paean 0.4.2 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +114 -0
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/worker.d.ts +7 -0
- package/dist/commands/worker.d.ts.map +1 -0
- package/dist/commands/worker.js +321 -0
- package/dist/commands/worker.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/system.d.ts +30 -0
- package/dist/mcp/system.d.ts.map +1 -0
- package/dist/mcp/system.js +530 -0
- package/dist/mcp/system.js.map +1 -0
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +5 -1
- package/dist/mcp/tools.js.map +1 -1
- package/dist/ui/theme/branding.d.ts.map +1 -1
- package/dist/ui/theme/branding.js +2 -7
- package/dist/ui/theme/branding.js.map +1 -1
- package/dist/worker/executors/claude.d.ts +29 -0
- package/dist/worker/executors/claude.d.ts.map +1 -0
- package/dist/worker/executors/claude.js +114 -0
- package/dist/worker/executors/claude.js.map +1 -0
- package/dist/worker/executors/codex.d.ts +29 -0
- package/dist/worker/executors/codex.d.ts.map +1 -0
- package/dist/worker/executors/codex.js +126 -0
- package/dist/worker/executors/codex.js.map +1 -0
- package/dist/worker/executors/cursor.d.ts +29 -0
- package/dist/worker/executors/cursor.d.ts.map +1 -0
- package/dist/worker/executors/cursor.js +136 -0
- package/dist/worker/executors/cursor.js.map +1 -0
- package/dist/worker/executors/gemini.d.ts +29 -0
- package/dist/worker/executors/gemini.d.ts.map +1 -0
- package/dist/worker/executors/gemini.js +129 -0
- package/dist/worker/executors/gemini.js.map +1 -0
- package/dist/worker/executors/index.d.ts +56 -0
- package/dist/worker/executors/index.d.ts.map +1 -0
- package/dist/worker/executors/index.js +108 -0
- package/dist/worker/executors/index.js.map +1 -0
- package/dist/worker/executors/internal.d.ts +23 -0
- package/dist/worker/executors/internal.d.ts.map +1 -0
- package/dist/worker/executors/internal.js +77 -0
- package/dist/worker/executors/internal.js.map +1 -0
- package/dist/worker/executors/opencode.d.ts +31 -0
- package/dist/worker/executors/opencode.d.ts.map +1 -0
- package/dist/worker/executors/opencode.js +129 -0
- package/dist/worker/executors/opencode.js.map +1 -0
- package/dist/worker/index.d.ts +14 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +17 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/service.d.ts +72 -0
- package/dist/worker/service.d.ts.map +1 -0
- package/dist/worker/service.js +435 -0
- package/dist/worker/service.js.map +1 -0
- package/dist/worker/supervisor.d.ts +83 -0
- package/dist/worker/supervisor.d.ts.map +1 -0
- package/dist/worker/supervisor.js +412 -0
- package/dist/worker/supervisor.js.map +1 -0
- package/dist/worker/types.d.ts +278 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +71 -0
- package/dist/worker/types.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Service
|
|
3
|
+
* Core service for the Local Autonomous Worker
|
|
4
|
+
* Manages task polling, execution, and lifecycle
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
import { type WorkerConfig, type WorkerState, type WorkerEventHandler } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* WorkerService - Manages autonomous task execution loop
|
|
10
|
+
*/
|
|
11
|
+
export declare class WorkerService extends EventEmitter {
|
|
12
|
+
private config;
|
|
13
|
+
private state;
|
|
14
|
+
private pollTimer;
|
|
15
|
+
private abortController;
|
|
16
|
+
private mcpState;
|
|
17
|
+
private onMcpToolCall;
|
|
18
|
+
private mcpClient;
|
|
19
|
+
constructor(config?: Partial<WorkerConfig>);
|
|
20
|
+
/**
|
|
21
|
+
* Start the worker loop
|
|
22
|
+
*/
|
|
23
|
+
start(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Stop the worker gracefully
|
|
26
|
+
*/
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Pause the worker (finish current task, don't pick new ones)
|
|
30
|
+
*/
|
|
31
|
+
pause(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Resume the worker
|
|
34
|
+
*/
|
|
35
|
+
resume(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get current worker state
|
|
38
|
+
*/
|
|
39
|
+
getState(): WorkerState;
|
|
40
|
+
/**
|
|
41
|
+
* Add event handler
|
|
42
|
+
*/
|
|
43
|
+
onEvent(handler: WorkerEventHandler): void;
|
|
44
|
+
/**
|
|
45
|
+
* Main poll and execute cycle
|
|
46
|
+
*/
|
|
47
|
+
private pollAndExecute;
|
|
48
|
+
/**
|
|
49
|
+
* Fetch the next pending task
|
|
50
|
+
*/
|
|
51
|
+
private fetchNextTask;
|
|
52
|
+
/**
|
|
53
|
+
* Execute a task using the agent
|
|
54
|
+
*/
|
|
55
|
+
private executeTask;
|
|
56
|
+
/**
|
|
57
|
+
* Verify task completion
|
|
58
|
+
* Override this method for custom verification logic
|
|
59
|
+
*/
|
|
60
|
+
private verifyTask;
|
|
61
|
+
/**
|
|
62
|
+
* Sleep helper
|
|
63
|
+
*/
|
|
64
|
+
private sleep;
|
|
65
|
+
/**
|
|
66
|
+
* Log helper
|
|
67
|
+
*/
|
|
68
|
+
private log;
|
|
69
|
+
}
|
|
70
|
+
export declare function getWorker(config?: Partial<WorkerConfig>): WorkerService;
|
|
71
|
+
export declare function resetWorker(): void;
|
|
72
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/worker/service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAWtC,OAAO,EACH,KAAK,YAAY,EACjB,KAAK,WAAW,EAIhB,KAAK,kBAAkB,EAG1B,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC3C,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,SAAS,CAA+C;IAChE,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,SAAS,CAAiB;gBAEtB,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAU9C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkD3B;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,MAAM,IAAI,IAAI;IAQd;;OAEG;IACH,QAAQ,IAAI,WAAW;IAIvB;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAI1C;;OAEG;YACW,cAAc;IA8H5B;;OAEG;YACW,aAAa;IAyB3B;;OAEG;YACW,WAAW;IAuGzB;;;OAGG;YACW,UAAU;IAqBxB;;OAEG;IACH,OAAO,CAAC,KAAK;IAUb;;OAEG;IACH,OAAO,CAAC,GAAG;CAKd;AAKD,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,aAAa,CAKvE;AAED,wBAAgB,WAAW,IAAI,IAAI,CAKlC"}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Service
|
|
3
|
+
* Core service for the Local Autonomous Worker
|
|
4
|
+
* Manages task polling, execution, and lifecycle
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
import { agentService } from '../agent/service.js';
|
|
8
|
+
import { initializeAgent } from '../agent/utils.js';
|
|
9
|
+
import { getTodoList, updateTodoItem, completeTodoItem } from '../api/todo.js';
|
|
10
|
+
import { executeSystemTool } from '../mcp/system.js';
|
|
11
|
+
import { DEFAULT_WORKER_CONFIG, buildTaskPrompt, } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* WorkerService - Manages autonomous task execution loop
|
|
14
|
+
*/
|
|
15
|
+
export class WorkerService extends EventEmitter {
|
|
16
|
+
config;
|
|
17
|
+
state;
|
|
18
|
+
pollTimer = null;
|
|
19
|
+
abortController = null;
|
|
20
|
+
mcpState = null;
|
|
21
|
+
onMcpToolCall = null;
|
|
22
|
+
mcpClient = null;
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
super();
|
|
25
|
+
this.config = { ...DEFAULT_WORKER_CONFIG, ...config };
|
|
26
|
+
this.state = {
|
|
27
|
+
status: 'idle',
|
|
28
|
+
completedCount: 0,
|
|
29
|
+
failedCount: 0,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Start the worker loop
|
|
34
|
+
*/
|
|
35
|
+
async start() {
|
|
36
|
+
if (this.state.status === 'running') {
|
|
37
|
+
throw new Error('Worker is already running');
|
|
38
|
+
}
|
|
39
|
+
this.log('Starting worker...');
|
|
40
|
+
// Initialize MCP
|
|
41
|
+
try {
|
|
42
|
+
const result = await initializeAgent({
|
|
43
|
+
mcp: true,
|
|
44
|
+
debug: this.config.debug
|
|
45
|
+
});
|
|
46
|
+
this.mcpState = result.mcpState;
|
|
47
|
+
this.onMcpToolCall = result.onMcpToolCall;
|
|
48
|
+
this.mcpClient = result.mcpClient;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.log(`Failed to initialize MCP: ${error}`);
|
|
52
|
+
// Continue without MCP - agent will still work with cloud tools
|
|
53
|
+
}
|
|
54
|
+
this.state = {
|
|
55
|
+
...this.state,
|
|
56
|
+
status: 'running',
|
|
57
|
+
startedAt: new Date(),
|
|
58
|
+
lastError: undefined,
|
|
59
|
+
};
|
|
60
|
+
this.abortController = new AbortController();
|
|
61
|
+
this.emit('event', { type: 'started' });
|
|
62
|
+
// Start polling
|
|
63
|
+
this.pollAndExecute();
|
|
64
|
+
this.pollTimer = setInterval(() => {
|
|
65
|
+
if (this.state.status === 'running' && !this.state.currentTask) {
|
|
66
|
+
this.pollAndExecute();
|
|
67
|
+
}
|
|
68
|
+
}, this.config.pollInterval);
|
|
69
|
+
this.log('Worker started');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Stop the worker gracefully
|
|
73
|
+
*/
|
|
74
|
+
async stop() {
|
|
75
|
+
if (this.state.status === 'idle') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.log('Stopping worker...');
|
|
79
|
+
this.state.status = 'stopping';
|
|
80
|
+
// Clear polling timer
|
|
81
|
+
if (this.pollTimer) {
|
|
82
|
+
clearInterval(this.pollTimer);
|
|
83
|
+
this.pollTimer = null;
|
|
84
|
+
}
|
|
85
|
+
// Abort current operation
|
|
86
|
+
if (this.abortController) {
|
|
87
|
+
this.abortController.abort();
|
|
88
|
+
this.abortController = null;
|
|
89
|
+
}
|
|
90
|
+
// Disconnect MCP
|
|
91
|
+
if (this.mcpClient && typeof this.mcpClient.disconnectAll === 'function') {
|
|
92
|
+
try {
|
|
93
|
+
await this.mcpClient.disconnectAll();
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
// Ignore disconnect errors
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Release current task if any
|
|
100
|
+
if (this.state.currentTask) {
|
|
101
|
+
try {
|
|
102
|
+
await updateTodoItem(this.state.currentTask.task.id, {
|
|
103
|
+
status: 'pending',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
this.log(`Failed to release task: ${e}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.state = {
|
|
111
|
+
...this.state,
|
|
112
|
+
status: 'idle',
|
|
113
|
+
currentTask: undefined,
|
|
114
|
+
};
|
|
115
|
+
this.emit('event', { type: 'stopped' });
|
|
116
|
+
this.log('Worker stopped');
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Pause the worker (finish current task, don't pick new ones)
|
|
120
|
+
*/
|
|
121
|
+
pause() {
|
|
122
|
+
if (this.state.status === 'running') {
|
|
123
|
+
this.state.status = 'paused';
|
|
124
|
+
this.emit('event', { type: 'paused' });
|
|
125
|
+
this.log('Worker paused');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Resume the worker
|
|
130
|
+
*/
|
|
131
|
+
resume() {
|
|
132
|
+
if (this.state.status === 'paused') {
|
|
133
|
+
this.state.status = 'running';
|
|
134
|
+
this.emit('event', { type: 'resumed' });
|
|
135
|
+
this.log('Worker resumed');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get current worker state
|
|
140
|
+
*/
|
|
141
|
+
getState() {
|
|
142
|
+
return { ...this.state };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Add event handler
|
|
146
|
+
*/
|
|
147
|
+
onEvent(handler) {
|
|
148
|
+
this.on('event', handler);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Main poll and execute cycle
|
|
152
|
+
*/
|
|
153
|
+
async pollAndExecute() {
|
|
154
|
+
if (this.state.status !== 'running') {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.state.lastPollAt = new Date();
|
|
158
|
+
try {
|
|
159
|
+
const task = await this.fetchNextTask();
|
|
160
|
+
if (!task) {
|
|
161
|
+
this.emit('event', { type: 'poll_empty' });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Claim the task
|
|
165
|
+
this.emit('event', { type: 'task_claimed', task });
|
|
166
|
+
// Execute with retries
|
|
167
|
+
let attempt = 1;
|
|
168
|
+
let previousFailureSummary;
|
|
169
|
+
const maxRetries = this.config.maxRetries;
|
|
170
|
+
while (attempt <= maxRetries) {
|
|
171
|
+
const ctx = {
|
|
172
|
+
task,
|
|
173
|
+
attempt,
|
|
174
|
+
previousFailureSummary,
|
|
175
|
+
startedAt: new Date(),
|
|
176
|
+
};
|
|
177
|
+
this.state.currentTask = ctx;
|
|
178
|
+
this.emit('event', { type: 'task_started', task, attempt });
|
|
179
|
+
const result = await this.executeTask(ctx);
|
|
180
|
+
if (result.success) {
|
|
181
|
+
// Verify if enabled
|
|
182
|
+
if (this.config.verificationEnabled) {
|
|
183
|
+
const verified = await this.verifyTask(ctx);
|
|
184
|
+
if (!verified) {
|
|
185
|
+
this.emit('event', { type: 'task_verification_failed', task });
|
|
186
|
+
previousFailureSummary = 'Verification failed: task execution completed but verification step did not pass.';
|
|
187
|
+
attempt++;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Mark as completed
|
|
192
|
+
try {
|
|
193
|
+
await completeTodoItem(task.id, result.message);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
this.log(`Failed to mark task as complete: ${e}`);
|
|
197
|
+
}
|
|
198
|
+
this.state.completedCount++;
|
|
199
|
+
this.emit('event', {
|
|
200
|
+
type: 'task_completed',
|
|
201
|
+
task,
|
|
202
|
+
duration: Date.now() - ctx.startedAt.getTime()
|
|
203
|
+
});
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Task failed
|
|
208
|
+
const willRetry = attempt < maxRetries;
|
|
209
|
+
previousFailureSummary = result.error || 'Unknown error';
|
|
210
|
+
this.emit('event', {
|
|
211
|
+
type: 'task_failed',
|
|
212
|
+
task,
|
|
213
|
+
error: previousFailureSummary,
|
|
214
|
+
willRetry
|
|
215
|
+
});
|
|
216
|
+
if (willRetry) {
|
|
217
|
+
// Store failure summary for retry
|
|
218
|
+
try {
|
|
219
|
+
await updateTodoItem(task.id, {
|
|
220
|
+
metadata: {
|
|
221
|
+
...task.metadata,
|
|
222
|
+
lastFailureSummary: previousFailureSummary,
|
|
223
|
+
retryCount: attempt,
|
|
224
|
+
lastAttemptAt: new Date().toISOString(),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
this.log(`Failed to update task metadata: ${e}`);
|
|
230
|
+
}
|
|
231
|
+
attempt++;
|
|
232
|
+
// Small delay before retry
|
|
233
|
+
await this.sleep(5000);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// All retries exhausted
|
|
237
|
+
this.state.failedCount++;
|
|
238
|
+
// Release task back to pending
|
|
239
|
+
try {
|
|
240
|
+
await updateTodoItem(task.id, {
|
|
241
|
+
status: 'pending',
|
|
242
|
+
metadata: {
|
|
243
|
+
...task.metadata,
|
|
244
|
+
lastFailure: previousFailureSummary,
|
|
245
|
+
failedAt: new Date().toISOString(),
|
|
246
|
+
retriesExhausted: true,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
this.log(`Failed to release failed task: ${e}`);
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
this.state.currentTask = undefined;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
261
|
+
this.state.lastError = errorMsg;
|
|
262
|
+
this.emit('event', { type: 'error', error: errorMsg });
|
|
263
|
+
// Cooldown on error
|
|
264
|
+
this.log(`Error in poll cycle: ${errorMsg}. Cooling down...`);
|
|
265
|
+
await this.sleep(this.config.cooldownOnError);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Fetch the next pending task
|
|
270
|
+
*/
|
|
271
|
+
async fetchNextTask() {
|
|
272
|
+
try {
|
|
273
|
+
const response = await getTodoList({ status: 'pending' });
|
|
274
|
+
const tasks = response.data.items;
|
|
275
|
+
if (tasks.length === 0) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
// Sort by priority (high > medium > low) and pick first
|
|
279
|
+
const priorityOrder = { high: 0, medium: 1, low: 2 };
|
|
280
|
+
tasks.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
|
|
281
|
+
const task = tasks[0];
|
|
282
|
+
// Lock the task by setting status to in_progress
|
|
283
|
+
await updateTodoItem(task.id, { status: 'in_progress' });
|
|
284
|
+
return task;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
this.log(`Failed to fetch tasks: ${error}`);
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Execute a task using the agent
|
|
293
|
+
*/
|
|
294
|
+
async executeTask(ctx) {
|
|
295
|
+
const startTime = Date.now();
|
|
296
|
+
const prompt = buildTaskPrompt(ctx);
|
|
297
|
+
return new Promise((resolve) => {
|
|
298
|
+
let responseText = '';
|
|
299
|
+
let hasError = false;
|
|
300
|
+
let errorMessage = '';
|
|
301
|
+
const timeout = setTimeout(() => {
|
|
302
|
+
agentService.abort();
|
|
303
|
+
resolve({
|
|
304
|
+
success: false,
|
|
305
|
+
error: `Task timed out after ${this.config.taskTimeout}ms`,
|
|
306
|
+
durationMs: Date.now() - startTime,
|
|
307
|
+
});
|
|
308
|
+
}, this.config.taskTimeout);
|
|
309
|
+
const callbacks = {
|
|
310
|
+
onContent: (text, partial) => {
|
|
311
|
+
if (partial) {
|
|
312
|
+
responseText += text;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
responseText = text;
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
onMcpToolCall: async (callId, serverName, toolName, args) => {
|
|
319
|
+
if (typeof this.onMcpToolCall === 'function') {
|
|
320
|
+
try {
|
|
321
|
+
const result = await this.onMcpToolCall(callId, serverName, toolName, args);
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
return {
|
|
326
|
+
content: [{ type: 'text', text: `Error: ${error}` }],
|
|
327
|
+
isError: true,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// Handle system tools in autonomous mode
|
|
332
|
+
if (toolName.startsWith('paean_execute') || toolName.startsWith('paean_check') || toolName.startsWith('paean_kill')) {
|
|
333
|
+
const result = await executeSystemTool(toolName, args, {
|
|
334
|
+
autonomousMode: this.config.autonomousMode,
|
|
335
|
+
debug: this.config.debug,
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
339
|
+
isError: !result.success,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
content: [{ type: 'text', text: 'MCP not available' }],
|
|
344
|
+
isError: true,
|
|
345
|
+
};
|
|
346
|
+
},
|
|
347
|
+
onError: (error) => {
|
|
348
|
+
hasError = true;
|
|
349
|
+
errorMessage = error;
|
|
350
|
+
},
|
|
351
|
+
onDone: (convId) => {
|
|
352
|
+
clearTimeout(timeout);
|
|
353
|
+
if (ctx.conversationId === undefined) {
|
|
354
|
+
ctx.conversationId = convId;
|
|
355
|
+
}
|
|
356
|
+
if (hasError) {
|
|
357
|
+
resolve({
|
|
358
|
+
success: false,
|
|
359
|
+
error: errorMessage,
|
|
360
|
+
durationMs: Date.now() - startTime,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
resolve({
|
|
365
|
+
success: true,
|
|
366
|
+
message: responseText.slice(0, 500), // Truncate for summary
|
|
367
|
+
durationMs: Date.now() - startTime,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
agentService.streamMessage(prompt, callbacks, {
|
|
373
|
+
conversationId: ctx.conversationId,
|
|
374
|
+
mcpState: this.mcpState,
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Verify task completion
|
|
380
|
+
* Override this method for custom verification logic
|
|
381
|
+
*/
|
|
382
|
+
async verifyTask(ctx) {
|
|
383
|
+
// Default implementation: check if task has verification command in metadata
|
|
384
|
+
const verifyCmd = ctx.task.metadata?.verificationCommand;
|
|
385
|
+
if (!verifyCmd) {
|
|
386
|
+
// No verification command, assume success
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const result = await executeSystemTool('paean_execute_shell', {
|
|
391
|
+
command: verifyCmd,
|
|
392
|
+
timeout: 60000,
|
|
393
|
+
}, { autonomousMode: true });
|
|
394
|
+
return result.success;
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Sleep helper
|
|
402
|
+
*/
|
|
403
|
+
sleep(ms) {
|
|
404
|
+
return new Promise((resolve) => {
|
|
405
|
+
const timer = setTimeout(resolve, ms);
|
|
406
|
+
this.abortController?.signal.addEventListener('abort', () => {
|
|
407
|
+
clearTimeout(timer);
|
|
408
|
+
resolve();
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Log helper
|
|
414
|
+
*/
|
|
415
|
+
log(message) {
|
|
416
|
+
if (this.config.debug) {
|
|
417
|
+
console.error(`[Worker] ${message}`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Export singleton for convenience
|
|
422
|
+
let workerInstance = null;
|
|
423
|
+
export function getWorker(config) {
|
|
424
|
+
if (!workerInstance) {
|
|
425
|
+
workerInstance = new WorkerService(config);
|
|
426
|
+
}
|
|
427
|
+
return workerInstance;
|
|
428
|
+
}
|
|
429
|
+
export function resetWorker() {
|
|
430
|
+
if (workerInstance) {
|
|
431
|
+
workerInstance.stop().catch(() => { });
|
|
432
|
+
workerInstance = null;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/worker/service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACH,WAAW,EACX,cAAc,EACd,gBAAgB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAOH,qBAAqB,EACrB,eAAe,GAClB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IACnC,MAAM,CAAe;IACrB,KAAK,CAAc;IACnB,SAAS,GAA0C,IAAI,CAAC;IACxD,eAAe,GAA2B,IAAI,CAAC;IAC/C,QAAQ,GAAY,IAAI,CAAC;IACzB,aAAa,GAAY,IAAI,CAAC;IAC9B,SAAS,GAAY,IAAI,CAAC;IAElC,YAAY,SAAgC,EAAE;QAC1C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,qBAAqB,EAAE,GAAG,MAAM,EAAE,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG;YACT,MAAM,EAAE,MAAM;YACd,cAAc,EAAE,CAAC;YACjB,WAAW,EAAE,CAAC;SACjB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,CA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C,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEhD,MAAM,UAAU,SAAS,CAAC,MAA8B;IACpD,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,cAAc,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,IAAI,cAAc,EAAE,CAAC;QACjB,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACvC,cAAc,GAAG,IAAI,CAAC;IAC1B,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor Agent
|
|
3
|
+
* Responsible for task grooming, executor selection, and semantic verification
|
|
4
|
+
* Acts as the "brain" that coordinates between cloud and local execution
|
|
5
|
+
*/
|
|
6
|
+
import type { TodoItem } from '../api/todo.js';
|
|
7
|
+
import type { ExecutorType, SupervisorDecision, VerificationResult, RecoveryStrategy } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Supervisor Agent - Coordinates task analysis, routing, and verification
|
|
10
|
+
*/
|
|
11
|
+
export declare class SupervisorAgent {
|
|
12
|
+
private debug;
|
|
13
|
+
private cloudEnabled;
|
|
14
|
+
constructor(options?: {
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
cloudEnabled?: boolean;
|
|
17
|
+
model?: string;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Groom a natural language prompt into a structured task
|
|
21
|
+
* Uses cloud LLM to analyze and structure the request
|
|
22
|
+
*/
|
|
23
|
+
groomTask(prompt: string, context?: {
|
|
24
|
+
projectPath?: string;
|
|
25
|
+
existingTasks?: TodoItem[];
|
|
26
|
+
fileStructure?: string;
|
|
27
|
+
}): Promise<SupervisorDecision>;
|
|
28
|
+
/**
|
|
29
|
+
* Cloud-based task grooming via agent service
|
|
30
|
+
*/
|
|
31
|
+
private cloudGroomTask;
|
|
32
|
+
/**
|
|
33
|
+
* Build the grooming prompt for the cloud LLM
|
|
34
|
+
*/
|
|
35
|
+
private buildGroomingPrompt;
|
|
36
|
+
/**
|
|
37
|
+
* Parse the grooming response from LLM
|
|
38
|
+
*/
|
|
39
|
+
private parseGroomingResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Local fallback grooming using heuristics
|
|
42
|
+
*/
|
|
43
|
+
private localGroomTask;
|
|
44
|
+
/**
|
|
45
|
+
* Structure a raw prompt into a cleaner format
|
|
46
|
+
*/
|
|
47
|
+
private structurePrompt;
|
|
48
|
+
/**
|
|
49
|
+
* Select executor based on task characteristics
|
|
50
|
+
*/
|
|
51
|
+
selectExecutor(task: TodoItem, availableExecutors: ExecutorType[]): ExecutorType;
|
|
52
|
+
/**
|
|
53
|
+
* Verify task completion semantically
|
|
54
|
+
*/
|
|
55
|
+
verifyCompletion(task: TodoItem, diff: string, output?: string): Promise<VerificationResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Cloud-based semantic verification
|
|
58
|
+
*/
|
|
59
|
+
private cloudVerifyCompletion;
|
|
60
|
+
/**
|
|
61
|
+
* Local verification fallback
|
|
62
|
+
*/
|
|
63
|
+
private localVerifyCompletion;
|
|
64
|
+
/**
|
|
65
|
+
* Analyze failure and recommend recovery strategy
|
|
66
|
+
*/
|
|
67
|
+
analyzeFailure(_task: TodoItem, error: string, attempt: number, currentExecutor: ExecutorType): Promise<RecoveryStrategy>;
|
|
68
|
+
/**
|
|
69
|
+
* Validate executor type string
|
|
70
|
+
*/
|
|
71
|
+
private validateExecutorType;
|
|
72
|
+
/**
|
|
73
|
+
* Debug logging
|
|
74
|
+
*/
|
|
75
|
+
private log;
|
|
76
|
+
}
|
|
77
|
+
export declare function getSupervisor(options?: {
|
|
78
|
+
debug?: boolean;
|
|
79
|
+
cloudEnabled?: boolean;
|
|
80
|
+
model?: string;
|
|
81
|
+
}): SupervisorAgent;
|
|
82
|
+
export declare function resetSupervisor(): void;
|
|
83
|
+
//# sourceMappingURL=supervisor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/worker/supervisor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EACR,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACnB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,YAAY,CAAU;gBAElB,OAAO,GAAE;QACjB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;KACb;IAMN;;;OAGG;IACG,SAAS,CACX,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC;QAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;KAC1B,GACF,OAAO,CAAC,kBAAkB,CAAC;IAc9B;;OAEG;YACW,cAAc;IAoC5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAmC3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAwB7B;;OAEG;IACH,OAAO,CAAC,cAAc;IAmEtB;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,YAAY,EAAE,GAAG,YAAY;IA6BhF;;OAEG;IACG,gBAAgB,CAClB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC;IAa9B;;OAEG;YACW,qBAAqB;IAiEnC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