@linxiraos/pi-messenger 1.1.0 → 1.3.0
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 +741 -676
- package/LICENSE +45 -0
- package/README.md +424 -424
- package/THIRD-PARTY-NOTICES.txt +22951 -0
- package/config-overlay.ts +175 -171
- package/config.ts +221 -209
- package/crew/agents/crew-plan-sync.md +66 -64
- package/crew/agents/crew-planner.md +173 -172
- package/crew/agents/crew-reviewer.md +58 -58
- package/crew/agents/crew-worker.md +130 -129
- package/crew/agents.ts +507 -434
- package/crew/handlers/coordination.ts +350 -332
- package/crew/handlers/plan.ts +988 -906
- package/crew/handlers/review.ts +354 -333
- package/crew/handlers/revise.ts +400 -376
- package/crew/handlers/status.ts +303 -295
- package/crew/handlers/sync.ts +237 -233
- package/crew/handlers/task.ts +820 -792
- package/crew/handlers/team.ts +294 -235
- package/crew/handlers/work.ts +467 -425
- package/crew/id-allocator.ts +30 -30
- package/crew/index.ts +297 -257
- package/crew/live-progress.ts +58 -58
- package/crew/lobby.ts +504 -473
- package/crew/prompt.ts +262 -252
- package/crew/registry.ts +114 -114
- package/crew/spawn.ts +135 -111
- package/crew/state-autonomous.ts +163 -164
- package/crew/state-planning.ts +264 -263
- package/crew/state.ts +20 -20
- package/crew/store.ts +646 -642
- package/crew/task-actions.ts +162 -131
- package/crew/team/store.ts +572 -479
- package/crew/team/subagent-roles.ts +105 -87
- package/crew/team/types.ts +50 -50
- package/crew/types.ts +194 -194
- package/crew/utils/artifacts.ts +57 -62
- package/crew/utils/config.ts +158 -156
- package/crew/utils/discover.ts +221 -219
- package/crew/utils/install.ts +94 -85
- package/crew/utils/migrations.ts +126 -0
- package/crew/utils/progress.ts +191 -187
- package/crew/utils/result.ts +16 -16
- package/crew/utils/risk-labels.ts +5 -7
- package/crew/utils/task-format.ts +14 -14
- package/crew/utils/team-roles.ts +44 -28
- package/crew/utils/truncate.ts +76 -79
- package/crew/utils/verdict.ts +55 -55
- package/editor-binary.ts +150 -0
- package/editor-command.ts +107 -0
- package/editor-target.ts +40 -0
- package/feed.ts +321 -268
- package/handlers.ts +1041 -1107
- package/index.ts +1314 -1206
- package/install.mjs +187 -189
- package/lib.ts +587 -467
- package/overlay-actions.ts +519 -511
- package/overlay-coordinator.ts +150 -150
- package/overlay-render.ts +770 -676
- package/overlay.ts +872 -830
- package/package.json +64 -60
- package/paths.ts +60 -0
- package/skills/pi-messenger-crew/SKILL.md +375 -347
- package/store.ts +1147 -1139
- package/teamagent-command.ts +321 -0
- package/vitest.config.ts +10 -10
package/crew/handlers/work.ts
CHANGED
|
@@ -1,425 +1,467 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Crew - Work Handler
|
|
3
|
-
*
|
|
4
|
-
* Spawns workers for ready tasks with concurrency control.
|
|
5
|
-
* Simplified: works on current plan's tasks
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ExtensionContext } from "@
|
|
9
|
-
import type { Dirs } from "../../lib.ts";
|
|
10
|
-
import type { CrewParams, AppendEntryFn } from "../types.ts";
|
|
11
|
-
import { result } from "../utils/result.ts";
|
|
12
|
-
import { resolveModel, spawnAgents } from "../agents.ts";
|
|
13
|
-
import { loadCrewConfig } from "../utils/config.ts";
|
|
14
|
-
import { discoverCrewAgents, discoverCrewSkills } from "../utils/discover.ts";
|
|
15
|
-
import { buildWorkerPrompt } from "../prompt.ts";
|
|
16
|
-
import * as teamStore from "../team/store.ts";
|
|
17
|
-
import { reviewImplementation } from "./review.ts";
|
|
18
|
-
import
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Work Handler
|
|
3
|
+
*
|
|
4
|
+
* Spawns workers for ready tasks with concurrency control.
|
|
5
|
+
* Simplified: works on current plan's tasks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionContext } from "@linxiraos/zeta";
|
|
9
|
+
import type { Dirs } from "../../lib.ts";
|
|
10
|
+
import type { CrewParams, AppendEntryFn } from "../types.ts";
|
|
11
|
+
import { result } from "../utils/result.ts";
|
|
12
|
+
import { resolveModel, spawnAgents } from "../agents.ts";
|
|
13
|
+
import { loadCrewConfig } from "../utils/config.ts";
|
|
14
|
+
import { discoverCrewAgents, discoverCrewSkills } from "../utils/discover.ts";
|
|
15
|
+
import { buildWorkerPrompt } from "../prompt.ts";
|
|
16
|
+
import * as teamStore from "../team/store.ts";
|
|
17
|
+
import { reviewImplementation } from "./review.ts";
|
|
18
|
+
import {
|
|
19
|
+
autonomousState,
|
|
20
|
+
isAutonomousForCwd,
|
|
21
|
+
startAutonomous,
|
|
22
|
+
stopAutonomous,
|
|
23
|
+
addWaveResult,
|
|
24
|
+
clampConcurrency,
|
|
25
|
+
} from "../state.ts";
|
|
26
|
+
import { getAvailableLobbyWorkers, assignTaskToLobbyWorker, cleanupUnassignedAliveFiles } from "../lobby.ts";
|
|
27
|
+
import { logFeedEvent } from "../../feed.ts";
|
|
28
|
+
import { approvalTaskSummaries } from "../utils/task-format.ts";
|
|
29
|
+
import * as store from "../store.ts";
|
|
30
|
+
import { getCrewDir } from "../store.ts";
|
|
31
|
+
|
|
32
|
+
function revisionHint(taskId: string): string {
|
|
33
|
+
return `pi_messenger({ action: "task.revise", id: "${taskId}", prompt: "Address approval feedback" })`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function rejectedTasksText(tasks: { id: string; title: string; approval?: { feedback?: string } }[]): string {
|
|
37
|
+
if (tasks.length === 0) return "";
|
|
38
|
+
return `\n\nRejected tasks need revision:\n${tasks.map(t => ` - ${t.id}: ${t.title}${t.approval?.feedback ? ` — ${t.approval.feedback}` : ""}\n Revise with: \`${revisionHint(t.id)}\``).join("\n")}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function execute(
|
|
42
|
+
params: CrewParams,
|
|
43
|
+
dirs: Dirs,
|
|
44
|
+
ctx: ExtensionContext,
|
|
45
|
+
appendEntry: AppendEntryFn,
|
|
46
|
+
signal?: AbortSignal,
|
|
47
|
+
sessionModel?: string,
|
|
48
|
+
) {
|
|
49
|
+
const cwd = ctx.cwd;
|
|
50
|
+
const config = loadCrewConfig(getCrewDir(cwd));
|
|
51
|
+
const { autonomous, concurrency: concurrencyOverride } = params;
|
|
52
|
+
|
|
53
|
+
// Verify plan exists
|
|
54
|
+
const plan = store.getPlan(cwd);
|
|
55
|
+
if (!plan) {
|
|
56
|
+
return result(
|
|
57
|
+
'No plan found. Create one first:\n\n pi_messenger({ action: "plan" })\n pi_messenger({ action: "plan", prd: "path/to/PRD.md" })',
|
|
58
|
+
{
|
|
59
|
+
mode: "work",
|
|
60
|
+
error: "no_plan",
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check for worker agent
|
|
66
|
+
const availableAgents = discoverCrewAgents(cwd);
|
|
67
|
+
const hasWorker = availableAgents.some(a => a.name === "crew-worker");
|
|
68
|
+
if (!hasWorker) {
|
|
69
|
+
return result("Error: crew-worker agent not found. Required for task execution.", {
|
|
70
|
+
mode: "work",
|
|
71
|
+
error: "no_worker",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
store.autoCompleteMilestones(cwd);
|
|
76
|
+
syncCompletedCount(cwd);
|
|
77
|
+
|
|
78
|
+
// Get ready tasks — auto-block any that exceeded max attempts
|
|
79
|
+
const allReady = store.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" });
|
|
80
|
+
const readyTasks: typeof allReady = [];
|
|
81
|
+
const needsApproval: typeof allReady = [];
|
|
82
|
+
const rejected: typeof allReady = [];
|
|
83
|
+
for (const task of allReady) {
|
|
84
|
+
if (teamStore.taskNeedsRevision(task)) {
|
|
85
|
+
rejected.push(task);
|
|
86
|
+
} else if (teamStore.taskPendingApproval(task)) {
|
|
87
|
+
needsApproval.push(task);
|
|
88
|
+
} else if (task.attempt_count >= config.work.maxAttemptsPerTask) {
|
|
89
|
+
store.updateTask(cwd, task.id, {
|
|
90
|
+
status: "blocked",
|
|
91
|
+
blocked_reason: `Max attempts (${config.work.maxAttemptsPerTask}) reached`,
|
|
92
|
+
});
|
|
93
|
+
store.appendTaskProgress(
|
|
94
|
+
cwd,
|
|
95
|
+
task.id,
|
|
96
|
+
"system",
|
|
97
|
+
`Auto-blocked after ${task.attempt_count} attempts (max: ${config.work.maxAttemptsPerTask})`,
|
|
98
|
+
);
|
|
99
|
+
logFeedEvent(cwd, "crew", "task.block", task.id, `Max attempts (${config.work.maxAttemptsPerTask}) reached`);
|
|
100
|
+
} else {
|
|
101
|
+
readyTasks.push(task);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (readyTasks.length === 0) {
|
|
106
|
+
const tasks = store.getTasks(cwd);
|
|
107
|
+
const inProgress = tasks.filter(t => t.status === "in_progress");
|
|
108
|
+
const blocked = tasks.filter(t => t.status === "blocked");
|
|
109
|
+
const done = tasks.filter(t => t.status === "done");
|
|
110
|
+
|
|
111
|
+
let reason = "";
|
|
112
|
+
if (done.length === tasks.length) {
|
|
113
|
+
reason = "🎉 All tasks are done! Plan is complete.";
|
|
114
|
+
} else if (inProgress.length > 0) {
|
|
115
|
+
reason = `${inProgress.length} task(s) in progress: ${inProgress.map(t => t.id).join(", ")}`;
|
|
116
|
+
} else if (rejected.length > 0) {
|
|
117
|
+
reason = "No startable tasks; rejected tasks need revision.";
|
|
118
|
+
} else if (needsApproval.length > 0) {
|
|
119
|
+
reason = "No startable tasks; ready tasks need lead approval.";
|
|
120
|
+
} else if (blocked.length > 0) {
|
|
121
|
+
reason = `${blocked.length} task(s) blocked: ${blocked.map(t => `${t.id} (${t.blocked_reason})`).join(", ")}`;
|
|
122
|
+
} else {
|
|
123
|
+
reason = "All remaining tasks have unmet dependencies.";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const approvalText =
|
|
127
|
+
needsApproval.length > 0
|
|
128
|
+
? `\n\nNeeds approval:\n${needsApproval.map(t => ` - ${t.id}: ${t.title}`).join("\n")}`
|
|
129
|
+
: "";
|
|
130
|
+
|
|
131
|
+
const revisionText = rejectedTasksText(rejected);
|
|
132
|
+
|
|
133
|
+
return result(`No ready tasks.\n\n${reason}${approvalText}${revisionText}`, {
|
|
134
|
+
mode: "work",
|
|
135
|
+
prd: plan.prd,
|
|
136
|
+
ready: [],
|
|
137
|
+
reason,
|
|
138
|
+
needsApproval: approvalTaskSummaries(needsApproval),
|
|
139
|
+
rejected: approvalTaskSummaries(rejected),
|
|
140
|
+
inProgress: inProgress.map(t => t.id),
|
|
141
|
+
blocked: blocked.map(t => t.id),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Determine concurrency
|
|
146
|
+
const requestedConcurrency =
|
|
147
|
+
concurrencyOverride ??
|
|
148
|
+
(autonomous && isAutonomousForCwd(cwd) ? autonomousState.concurrency : config.concurrency.workers);
|
|
149
|
+
autonomousState.concurrency = clampConcurrency(requestedConcurrency, config.concurrency.max);
|
|
150
|
+
|
|
151
|
+
// If autonomous mode, set up state and persist (only on first wave or cwd change)
|
|
152
|
+
if (autonomous && !isAutonomousForCwd(cwd)) {
|
|
153
|
+
startAutonomous(cwd, autonomousState.concurrency);
|
|
154
|
+
appendEntry("crew-state", autonomousState);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const skills = discoverCrewSkills(cwd);
|
|
158
|
+
|
|
159
|
+
// Assign tasks to lobby workers first (they're already running and warmed up)
|
|
160
|
+
const prdLabel = store.getPlanLabel(plan);
|
|
161
|
+
const lobbyAssigned = new Set<string>();
|
|
162
|
+
const lobbyWorkers = getAvailableLobbyWorkers(cwd);
|
|
163
|
+
for (const lobbyWorker of lobbyWorkers) {
|
|
164
|
+
const task = readyTasks.find(t => !lobbyAssigned.has(t.id));
|
|
165
|
+
if (!task) break;
|
|
166
|
+
|
|
167
|
+
const others = readyTasks.filter(t => t.id !== task.id);
|
|
168
|
+
const prompt = buildWorkerPrompt(
|
|
169
|
+
task,
|
|
170
|
+
prdLabel,
|
|
171
|
+
cwd,
|
|
172
|
+
config,
|
|
173
|
+
others,
|
|
174
|
+
skills,
|
|
175
|
+
teamStore.buildTeamPromptContext(cwd, task),
|
|
176
|
+
);
|
|
177
|
+
store.updateTask(cwd, task.id, {
|
|
178
|
+
status: "in_progress",
|
|
179
|
+
started_at: new Date().toISOString(),
|
|
180
|
+
base_commit: store.getBaseCommit(cwd),
|
|
181
|
+
assigned_to: lobbyWorker.name,
|
|
182
|
+
attempt_count: task.attempt_count + 1,
|
|
183
|
+
});
|
|
184
|
+
if (!assignTaskToLobbyWorker(lobbyWorker, task.id, prompt, dirs.inbox)) {
|
|
185
|
+
store.updateTask(cwd, task.id, { status: "todo", assigned_to: undefined });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
store.appendTaskProgress(
|
|
189
|
+
cwd,
|
|
190
|
+
task.id,
|
|
191
|
+
"system",
|
|
192
|
+
`Assigned to lobby worker ${lobbyWorker.name} (attempt ${task.attempt_count + 1})`,
|
|
193
|
+
);
|
|
194
|
+
logFeedEvent(cwd, lobbyWorker.name, "task.start", task.id, task.title);
|
|
195
|
+
lobbyAssigned.add(task.id);
|
|
196
|
+
}
|
|
197
|
+
cleanupUnassignedAliveFiles(cwd);
|
|
198
|
+
|
|
199
|
+
// Build prompts for remaining tasks — spawnAgents throttles via autonomousState.concurrency
|
|
200
|
+
const remainingTasks = readyTasks.filter(t => !lobbyAssigned.has(t.id));
|
|
201
|
+
const teamRoles = teamStore.resolveRoles(cwd);
|
|
202
|
+
const workerTasks = remainingTasks.map(task => {
|
|
203
|
+
const roleName = teamStore.resolveRoleName(cwd, task.role);
|
|
204
|
+
const roleModel = roleName ? teamRoles[roleName]?.model : undefined;
|
|
205
|
+
const taskModel = resolveModel(task.model, params.model, roleModel, config.models?.worker, sessionModel);
|
|
206
|
+
const others = readyTasks.filter(t => t.id !== task.id);
|
|
207
|
+
const prompt = buildWorkerPrompt(
|
|
208
|
+
task,
|
|
209
|
+
prdLabel,
|
|
210
|
+
cwd,
|
|
211
|
+
config,
|
|
212
|
+
others,
|
|
213
|
+
skills,
|
|
214
|
+
teamStore.buildTeamPromptContext(cwd, task),
|
|
215
|
+
);
|
|
216
|
+
store.appendTaskProgress(cwd, task.id, "system", `Assigned to crew-worker (attempt ${task.attempt_count + 1})`);
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
agent: "crew-worker",
|
|
220
|
+
task: prompt,
|
|
221
|
+
taskId: task.id,
|
|
222
|
+
modelOverride: taskModel,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const workerResults = await spawnAgents(workerTasks, cwd, {
|
|
227
|
+
signal,
|
|
228
|
+
messengerDirs: { registry: dirs.registry, inbox: dirs.inbox },
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Process results
|
|
232
|
+
const succeeded: string[] = [];
|
|
233
|
+
const failed: string[] = [];
|
|
234
|
+
const blocked: string[] = [];
|
|
235
|
+
|
|
236
|
+
for (let i = 0; i < workerResults.length; i++) {
|
|
237
|
+
const r = workerResults[i];
|
|
238
|
+
const taskId = r.taskId;
|
|
239
|
+
if (!taskId) {
|
|
240
|
+
failed.push(`unknown-result-${i}`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const task = store.getTask(cwd, taskId);
|
|
244
|
+
|
|
245
|
+
if (r.exitCode === 0) {
|
|
246
|
+
if (task?.status === "done") {
|
|
247
|
+
succeeded.push(taskId);
|
|
248
|
+
} else if (task?.status === "blocked") {
|
|
249
|
+
blocked.push(taskId);
|
|
250
|
+
} else if (task?.status === "in_progress") {
|
|
251
|
+
store.appendTaskProgress(
|
|
252
|
+
cwd,
|
|
253
|
+
taskId,
|
|
254
|
+
"system",
|
|
255
|
+
r.wasGracefullyShutdown
|
|
256
|
+
? "Task interrupted (shutdown), reset to todo"
|
|
257
|
+
: "Worker exited without completing task, reset to todo",
|
|
258
|
+
);
|
|
259
|
+
store.updateTask(cwd, taskId, { status: "todo", assigned_to: undefined });
|
|
260
|
+
failed.push(taskId);
|
|
261
|
+
} else {
|
|
262
|
+
failed.push(taskId);
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
if (r.wasGracefullyShutdown) {
|
|
266
|
+
if (task?.status === "done") {
|
|
267
|
+
succeeded.push(taskId);
|
|
268
|
+
} else if (task?.status === "blocked") {
|
|
269
|
+
blocked.push(taskId);
|
|
270
|
+
} else if (task?.status === "in_progress") {
|
|
271
|
+
store.appendTaskProgress(cwd, taskId, "system", "Task interrupted (shutdown), reset to todo");
|
|
272
|
+
store.updateTask(cwd, taskId, { status: "todo", assigned_to: undefined });
|
|
273
|
+
failed.push(taskId);
|
|
274
|
+
} else {
|
|
275
|
+
failed.push(taskId);
|
|
276
|
+
}
|
|
277
|
+
} else if (autonomous && task?.status === "in_progress") {
|
|
278
|
+
store.appendTaskProgress(cwd, taskId, "system", `Worker crashed: ${r.error ?? "Unknown error"}`);
|
|
279
|
+
store.blockTask(cwd, taskId, `Worker failed: ${r.error ?? "Unknown error"}`);
|
|
280
|
+
blocked.push(taskId);
|
|
281
|
+
} else {
|
|
282
|
+
if (task?.status === "in_progress") {
|
|
283
|
+
store.appendTaskProgress(cwd, taskId, "system", `Worker failed: ${r.error ?? "Unknown error"}`);
|
|
284
|
+
}
|
|
285
|
+
failed.push(taskId);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Auto-review succeeded tasks
|
|
291
|
+
if (config.review.enabled && succeeded.length > 0) {
|
|
292
|
+
const hasReviewer = availableAgents.some(a => a.name === "crew-reviewer");
|
|
293
|
+
if (hasReviewer) {
|
|
294
|
+
for (const taskId of [...succeeded]) {
|
|
295
|
+
if (signal?.aborted) break;
|
|
296
|
+
const task = store.getTask(cwd, taskId);
|
|
297
|
+
if (!task || !task.base_commit) continue;
|
|
298
|
+
if ((task.review_count ?? 0) >= config.review.maxIterations) continue;
|
|
299
|
+
|
|
300
|
+
if (task.status === "blocked" || /duplicate/i.test(task.blocked_reason ?? "")) {
|
|
301
|
+
if (task.status !== "blocked") {
|
|
302
|
+
store.blockTask(cwd, taskId, task.blocked_reason ?? "Duplicate task");
|
|
303
|
+
}
|
|
304
|
+
succeeded.splice(succeeded.indexOf(taskId), 1);
|
|
305
|
+
blocked.push(taskId);
|
|
306
|
+
logFeedEvent(
|
|
307
|
+
cwd,
|
|
308
|
+
"crew",
|
|
309
|
+
"task.review",
|
|
310
|
+
taskId,
|
|
311
|
+
`skipped — blocked: ${task.blocked_reason ?? task.status}`,
|
|
312
|
+
);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const rr = await reviewImplementation(cwd, taskId, config.models?.reviewer ?? sessionModel);
|
|
317
|
+
const verdict = rr.details?.verdict as string | undefined;
|
|
318
|
+
if (!verdict) {
|
|
319
|
+
store.appendTaskProgress(
|
|
320
|
+
cwd,
|
|
321
|
+
taskId,
|
|
322
|
+
"system",
|
|
323
|
+
`Auto-review skipped: ${rr.details?.error ?? "unknown"}`,
|
|
324
|
+
);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const reviewCount = (task.review_count ?? 0) + 1;
|
|
329
|
+
store.updateTask(cwd, taskId, { review_count: reviewCount });
|
|
330
|
+
|
|
331
|
+
if (verdict === "SHIP") {
|
|
332
|
+
logFeedEvent(cwd, "crew", "task.review", taskId, "SHIP");
|
|
333
|
+
} else if (verdict === "NEEDS_WORK") {
|
|
334
|
+
store.resetTask(cwd, taskId);
|
|
335
|
+
logFeedEvent(cwd, "crew", "task.review", taskId, "NEEDS_WORK — reset for retry");
|
|
336
|
+
succeeded.splice(succeeded.indexOf(taskId), 1);
|
|
337
|
+
failed.push(taskId);
|
|
338
|
+
} else {
|
|
339
|
+
const lastReview = store.getTask(cwd, taskId)?.last_review;
|
|
340
|
+
const summary = lastReview?.summary
|
|
341
|
+
? lastReview.summary.split("\n")[0].slice(0, 120)
|
|
342
|
+
: "Major issues found";
|
|
343
|
+
store.blockTask(cwd, taskId, `Reviewer: ${summary}`);
|
|
344
|
+
logFeedEvent(cwd, "crew", "task.review", taskId, "MAJOR_RETHINK — blocked");
|
|
345
|
+
succeeded.splice(succeeded.indexOf(taskId), 1);
|
|
346
|
+
blocked.push(taskId);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
syncCompletedCount(cwd);
|
|
353
|
+
|
|
354
|
+
// Save current wave number BEFORE addWaveResult increments it
|
|
355
|
+
const currentWave = autonomous ? autonomousState.waveNumber : 1;
|
|
356
|
+
|
|
357
|
+
if (autonomous) {
|
|
358
|
+
addWaveResult({
|
|
359
|
+
waveNumber: currentWave,
|
|
360
|
+
tasksAttempted: remainingTasks.map(t => t.id),
|
|
361
|
+
succeeded,
|
|
362
|
+
failed,
|
|
363
|
+
blocked,
|
|
364
|
+
timestamp: new Date().toISOString(),
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
if (signal?.aborted) {
|
|
368
|
+
stopAutonomous("manual");
|
|
369
|
+
appendEntry("crew-state", autonomousState);
|
|
370
|
+
} else {
|
|
371
|
+
const nextReady = store
|
|
372
|
+
.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" })
|
|
373
|
+
.filter(t => !teamStore.taskNeedsApproval(t));
|
|
374
|
+
const allTasks = store.getTasks(cwd);
|
|
375
|
+
const allDone = allTasks.every(t => t.status === "done");
|
|
376
|
+
const allBlockedOrDone = allTasks.every(t => t.status === "done" || t.status === "blocked");
|
|
377
|
+
|
|
378
|
+
if (allDone) {
|
|
379
|
+
stopAutonomous("completed");
|
|
380
|
+
appendEntry("crew-state", autonomousState);
|
|
381
|
+
appendEntry("crew_wave_complete", {
|
|
382
|
+
prd: plan.prd,
|
|
383
|
+
status: "completed",
|
|
384
|
+
totalWaves: currentWave,
|
|
385
|
+
totalTasks: allTasks.length,
|
|
386
|
+
});
|
|
387
|
+
} else if (allBlockedOrDone || nextReady.length === 0) {
|
|
388
|
+
stopAutonomous("blocked");
|
|
389
|
+
appendEntry("crew-state", autonomousState);
|
|
390
|
+
appendEntry("crew_wave_blocked", {
|
|
391
|
+
prd: plan.prd,
|
|
392
|
+
status: "blocked",
|
|
393
|
+
blockedTasks: allTasks.filter(t => t.status === "blocked").map(t => t.id),
|
|
394
|
+
});
|
|
395
|
+
} else {
|
|
396
|
+
appendEntry("crew-state", autonomousState);
|
|
397
|
+
appendEntry("crew_wave_continue", {
|
|
398
|
+
prd: plan.prd,
|
|
399
|
+
nextWave: autonomousState.waveNumber,
|
|
400
|
+
readyTasks: nextReady.map(t => t.id),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Build result
|
|
407
|
+
const updatedPlan = store.getPlan(cwd);
|
|
408
|
+
const progress = updatedPlan ? `${updatedPlan.completed_count}/${updatedPlan.task_count}` : "unknown";
|
|
409
|
+
|
|
410
|
+
const nextReady = store.getReadyTasks(cwd, { advisory: config.dependencies === "advisory" });
|
|
411
|
+
const actionableNextReady = nextReady.filter(t => !teamStore.taskNeedsApproval(t));
|
|
412
|
+
const finalNeedsApproval = nextReady.filter(teamStore.taskPendingApproval);
|
|
413
|
+
const finalRejected = nextReady.filter(teamStore.taskNeedsRevision);
|
|
414
|
+
|
|
415
|
+
let statusText = "";
|
|
416
|
+
if (succeeded.length > 0) statusText += `\n✅ Completed: ${succeeded.join(", ")}`;
|
|
417
|
+
if (failed.length > 0) statusText += `\n❌ Failed: ${failed.join(", ")}`;
|
|
418
|
+
if (blocked.length > 0) statusText += `\n🚫 Blocked: ${blocked.join(", ")}`;
|
|
419
|
+
if (finalNeedsApproval.length > 0)
|
|
420
|
+
statusText += `\n🛑 Needs approval: ${finalNeedsApproval.map(t => t.id).join(", ")}`;
|
|
421
|
+
if (finalRejected.length > 0) statusText += `\n↩️ Rejected: ${finalRejected.map(t => t.id).join(", ")}`;
|
|
422
|
+
const nextText =
|
|
423
|
+
actionableNextReady.length > 0
|
|
424
|
+
? `\n\n**Ready for next wave:** ${actionableNextReady.map(t => t.id).join(", ")}`
|
|
425
|
+
: "";
|
|
426
|
+
const continueText =
|
|
427
|
+
autonomous && !signal?.aborted && actionableNextReady.length > 0
|
|
428
|
+
? "Autonomous mode: Continuing to next wave..."
|
|
429
|
+
: signal?.aborted && autonomous
|
|
430
|
+
? "Autonomous mode stopped (cancelled)."
|
|
431
|
+
: "";
|
|
432
|
+
|
|
433
|
+
const lobbyText =
|
|
434
|
+
lobbyAssigned.size > 0 ? `\n🏢 Lobby workers assigned: ${Array.from(lobbyAssigned).join(", ")}` : "";
|
|
435
|
+
|
|
436
|
+
const text = `# Work Wave ${currentWave}
|
|
437
|
+
|
|
438
|
+
**PRD:** ${store.getPlanLabel(plan)}
|
|
439
|
+
**Tasks attempted:** ${remainingTasks.length}${lobbyAssigned.size > 0 ? ` (+${lobbyAssigned.size} lobby)` : ""}
|
|
440
|
+
**Progress:** ${progress}
|
|
441
|
+
${statusText}${lobbyText}${rejectedTasksText(finalRejected)}${nextText}
|
|
442
|
+
|
|
443
|
+
${continueText}`;
|
|
444
|
+
|
|
445
|
+
return result(text, {
|
|
446
|
+
mode: "work",
|
|
447
|
+
prd: plan.prd,
|
|
448
|
+
wave: currentWave,
|
|
449
|
+
attempted: remainingTasks.map(t => t.id),
|
|
450
|
+
succeeded,
|
|
451
|
+
failed,
|
|
452
|
+
blocked,
|
|
453
|
+
needsApproval: approvalTaskSummaries(finalNeedsApproval),
|
|
454
|
+
rejected: approvalTaskSummaries(finalRejected),
|
|
455
|
+
nextReady: actionableNextReady.map(t => t.id),
|
|
456
|
+
autonomous: !!autonomous,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function syncCompletedCount(cwd: string): void {
|
|
461
|
+
const plan = store.getPlan(cwd);
|
|
462
|
+
if (!plan) return;
|
|
463
|
+
const doneCount = store.getTasks(cwd).filter(t => t.status === "done").length;
|
|
464
|
+
if (plan.completed_count !== doneCount) {
|
|
465
|
+
store.updatePlan(cwd, { completed_count: doneCount });
|
|
466
|
+
}
|
|
467
|
+
}
|