-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground-cli.ts
More file actions
84 lines (79 loc) · 2.93 KB
/
Copy pathbackground-cli.ts
File metadata and controls
84 lines (79 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* Background Task CLI
* node dist/lib/background/cli.js --action=<action> [args]
*/
import './provider-init.js';
import { BackgroundManager } from './manager.js';
const action = process.argv.find(a => a.startsWith('--action='))?.split('=')[1];
function arg(name: string): string {
return process.argv.find(a => a.startsWith(`--${name}=`))?.split('=').slice(1).join('=') || '';
}
function main(): void {
switch (action) {
case 'launch': {
const task = BackgroundManager.launch({
agent: arg('agent') || 'default',
prompt: arg('prompt') || '',
model: arg('model') || undefined,
description: arg('description') || undefined,
priority: (arg('priority') as 'high' | 'normal' | 'low') || 'normal',
maxRetries: parseInt(arg('max-retries')) || 3,
category: arg('category') || undefined,
});
console.log(JSON.stringify(task));
break;
}
case 'stats': {
console.log(JSON.stringify(BackgroundManager.getStats()));
break;
}
case 'parent-tasks': {
const parentId = arg('parent') || '';
const tasks = BackgroundManager.getTasksByParentSession(parentId);
console.log(JSON.stringify(tasks));
break;
}
case 'schedule-retry': {
const taskId = arg('task-id');
if (!taskId) { console.log(JSON.stringify({ error: 'missing --task-id' })); process.exit(1); }
console.log(JSON.stringify(BackgroundManager.scheduleRetry(taskId) || { error: 'not found' }));
break;
}
case 'update-status': {
const taskId = arg('task-id');
const status = arg('status') as any;
if (!taskId) { console.log(JSON.stringify({ error: 'missing --task-id' })); process.exit(1); }
console.log(JSON.stringify(BackgroundManager.updateStatus(taskId, status, {
lastError: arg('error') || undefined,
resultSummary: arg('summary') || undefined,
}) || { error: 'not found' }));
break;
}
case 'cancel': {
const taskId = arg('task-id');
if (!taskId) { console.log(JSON.stringify({ error: 'missing --task-id' })); process.exit(1); }
console.log(JSON.stringify(BackgroundManager.cancelTask(taskId) || { error: 'not found' }));
break;
}
case 'cleanup': {
const maxAge = parseInt(arg('max-age')) || 3600000;
const cleaned = BackgroundManager.cleanupStale(maxAge);
console.log(JSON.stringify({ cleaned }));
break;
}
case 'read': {
const taskId = arg('task-id');
if (!taskId) { console.log(JSON.stringify({ error: 'missing --task-id' })); process.exit(1); }
console.log(JSON.stringify(BackgroundManager.readTask(taskId) || { error: 'not found' }));
break;
}
default:
console.log(JSON.stringify({
error: 'unknown action',
validActions: ['launch', 'stats', 'parent-tasks', 'schedule-retry', 'update-status', 'cancel', 'cleanup', 'read'],
}));
process.exit(1);
}
}
main();