processes
Background jobs, long-running processes, and task management
What this skill does
# Processes - Complete API Reference
Spawn and manage background processes, long-running jobs, and scheduled tasks.
---
## Chat Commands
### Spawn Jobs
```
/job spawn "npm run backtest" Start background job
/job spawn "python train.py" --name ml Named job
/job spawn "node bot.js" --restart Auto-restart on exit
```
### Manage Jobs
```
/jobs List all jobs
/job status <id> Check job status
/job output <id> View job output
/job output <id> --follow Stream output
/job stop <id> Stop job
/job restart <id> Restart job
```
### Logs
```
/job logs <id> View logs
/job logs <id> --tail 100 Last 100 lines
/job logs <id> --since 1h Last hour
```
---
## TypeScript API Reference
### Create Process Manager
```typescript
import { createProcessManager } from 'clodds/processes';
const processes = createProcessManager({
// Working directory
cwd: process.cwd(),
// Environment
env: process.env,
// Limits
maxProcesses: 10,
maxMemoryMB: 1024,
// Logging
logDir: './logs/jobs',
maxLogSizeMB: 100,
// Storage
storage: 'sqlite',
dbPath: './jobs.db',
});
```
### Spawn Process
```typescript
// Simple spawn
const job = await processes.spawn({
command: 'npm',
args: ['run', 'backtest'],
name: 'backtest-btc',
});
console.log(`Job ID: ${job.id}`);
console.log(`PID: ${job.pid}`);
// With options
const job = await processes.spawn({
command: 'python',
args: ['train.py', '--epochs', '100'],
name: 'ml-training',
// Environment
env: {
...process.env,
CUDA_VISIBLE_DEVICES: '0',
},
// Working directory
cwd: '/path/to/ml-project',
// Auto-restart
restart: true,
maxRestarts: 3,
restartDelayMs: 5000,
// Resource limits
maxMemoryMB: 4096,
timeoutMs: 3600000, // 1 hour
});
```
### List Jobs
```typescript
const jobs = await processes.list();
for (const job of jobs) {
console.log(`${job.id}: ${job.name}`);
console.log(` Status: ${job.status}`); // 'running' | 'stopped' | 'failed' | 'completed'
console.log(` PID: ${job.pid}`);
console.log(` Started: ${job.startedAt}`);
console.log(` Memory: ${job.memoryMB}MB`);
console.log(` CPU: ${job.cpuPercent}%`);
}
```
### Get Status
```typescript
const status = await processes.getStatus(jobId);
console.log(`Status: ${status.status}`);
console.log(`Exit code: ${status.exitCode}`);
console.log(`Runtime: ${status.runtimeMs}ms`);
console.log(`Restarts: ${status.restarts}`);
console.log(`Memory: ${status.memoryMB}MB`);
console.log(`CPU: ${status.cpuPercent}%`);
```
### Get Output
```typescript
// Get all output
const output = await processes.getOutput(jobId);
console.log(output.stdout);
console.log(output.stderr);
// Get last N lines
const output = await processes.getOutput(jobId, { tail: 100 });
// Stream output
const stream = processes.streamOutput(jobId);
stream.on('stdout', (data) => console.log(data));
stream.on('stderr', (data) => console.error(data));
stream.on('exit', (code) => console.log(`Exit: ${code}`));
```
### Stop Job
```typescript
// Graceful stop (SIGTERM)
await processes.stop(jobId);
// Force kill (SIGKILL)
await processes.stop(jobId, { force: true });
// Stop all
await processes.stopAll();
```
### Restart Job
```typescript
await processes.restart(jobId);
```
### Event Handlers
```typescript
processes.on('started', (job) => {
console.log(`Job started: ${job.name}`);
});
processes.on('stopped', (job) => {
console.log(`Job stopped: ${job.name} (code: ${job.exitCode})`);
});
processes.on('failed', (job, error) => {
console.error(`Job failed: ${job.name}`, error);
});
processes.on('output', (job, type, data) => {
console.log(`[${job.name}] ${type}: ${data}`);
});
```
---
## Job Status
| Status | Description |
|--------|-------------|
| `running` | Currently executing |
| `stopped` | Stopped by user |
| `completed` | Finished successfully |
| `failed` | Exited with error |
| `restarting` | Auto-restarting |
---
## Use Cases
### Run Backtest
```typescript
const job = await processes.spawn({
command: 'npm',
args: ['run', 'backtest', '--', '--strategy', 'momentum'],
name: 'backtest-momentum',
});
// Wait for completion
const result = await processes.wait(job.id);
console.log(`Backtest complete: ${result.exitCode === 0 ? 'success' : 'failed'}`);
```
### Train ML Model
```typescript
const job = await processes.spawn({
command: 'python',
args: ['train.py'],
name: 'ml-training',
cwd: './ml',
maxMemoryMB: 8192,
timeoutMs: 86400000, // 24 hours
});
// Monitor progress
processes.streamOutput(job.id).on('stdout', (line) => {
if (line.includes('Epoch')) {
console.log(line);
}
});
```
---
## Best Practices
1. **Name your jobs** — Easier to identify
2. **Set timeouts** — Prevent runaway processes
3. **Monitor memory** — Prevent OOM kills
4. **Use restart sparingly** — Debug failures first
5. **Check logs** — Always review output
Related in Productivity
gitea-workflow
IncludedOrchestrate agile development workflows for Gitea repositories using the tea CLI. Use when working with Gitea-hosted repos and asking to 'run the workflow', 'continue working', 'what's next', 'complete the task cycle', 'start my day', 'end the sprint', 'implement the next task', or wanting guided step-by-step development assistance. Keywords: workflow, orchestrate, agile, task cycle, sprint, daily, implement, review, PR, standup, retrospective, gitea, tea.
microsoft-graph-gateway
IncludedRoute Microsoft Graph work in this workspace. Use when users want to read or write Outlook mail, calendar events, contacts, OneDrive or SharePoint files, Teams, Planner, To Do, users, groups, directory data, or arbitrary Microsoft Graph endpoints from VS Code. Prefer WorkIQ for common read scenarios. Use Microsoft Graph for write actions and gap-read scenarios that need exact Graph properties, filters, permissions, or endpoints.
copilotkit
IncludedUse when building with CopilotKit — setup, development, integrations, debugging, upgrading, or contributing. Routes to the appropriate specialized skill based on the task.
wordly-wisdom
IncludedProvides calibrated decision analysis using Charlie Munger-style multiple mental models, inversion, incentive mapping, circle-of-competence checks, misjudgment audits, second-order effects, and forecast updates. Use when the user asks for an oracle take, a hard call, a decision memo, a premortem, an outside view, a red-team, a sanity-check, what am I missing, think this through, or wants a strategy, hire, investment, plan, product, partnership, or major life choice analysed. Avoid for simple factual lookups or time-sensitive legal, medical, or market questions without fresh evidence.
swain-session
IncludedSession management and project status dashboard. Owns the full session lifecycle (start/work/close/resume), focus lane, bookmarks, worktree detection, and tab naming. Also serves as the project status dashboard — shows active epics, progress, actionable next steps, blocked items, tasks, GitHub issues, and recommendations. Worktree creation is deferred to swain-do task dispatch (SPEC-195). Triggers on: 'session', 'status', 'what's next', 'dashboard', 'overview', 'where are we', 'what should I work on', 'show me priorities', 'bookmark', 'focus on', 'session info'.
gandi
IncludedComprehensive Gandi domain registrar integration for domain and DNS management. Register and manage domains, create/update/delete DNS records (A, AAAA, CNAME, MX, TXT, SRV, and more), configure email forwarding and aliases, check SSL certificate status, create DNS snapshots for safe rollback, bulk update zone files, and monitor domain expiration. Supports multi-domain management, zone file import/export, and automated DNS backups. Includes both read-only and destructive operations with safety controls.