@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/revise.ts
CHANGED
|
@@ -1,376 +1,400 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { MessengerState } from "../../lib.ts";
|
|
4
|
-
import type { CrewParams, Task } from "../types.ts";
|
|
5
|
-
import { result } from "../utils/result.ts";
|
|
6
|
-
import * as store from "../store.ts";
|
|
7
|
-
import { logFeedEvent } from "../../feed.ts";
|
|
8
|
-
import { spawnAgents } from "../agents.ts";
|
|
9
|
-
import { getLiveWorkers } from "../live-progress.ts";
|
|
10
|
-
import { isAutonomousForCwd, isPlanningForCwd } from "../state.ts";
|
|
11
|
-
import { loadCrewConfig } from "../utils/config.ts";
|
|
12
|
-
|
|
13
|
-
export interface ReviseResult {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// =============================================================================
|
|
19
|
-
// Single task revision
|
|
20
|
-
// =============================================================================
|
|
21
|
-
|
|
22
|
-
export async function executeRevise(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
): Promise<ReviseResult> {
|
|
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
|
-
id
|
|
351
|
-
title
|
|
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
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { MessengerState } from "../../lib.ts";
|
|
4
|
+
import type { CrewParams, Task } from "../types.ts";
|
|
5
|
+
import { result } from "../utils/result.ts";
|
|
6
|
+
import * as store from "../store.ts";
|
|
7
|
+
import { logFeedEvent } from "../../feed.ts";
|
|
8
|
+
import { spawnAgents } from "../agents.ts";
|
|
9
|
+
import { getLiveWorkers } from "../live-progress.ts";
|
|
10
|
+
import { isAutonomousForCwd, isPlanningForCwd } from "../state.ts";
|
|
11
|
+
import { loadCrewConfig } from "../utils/config.ts";
|
|
12
|
+
|
|
13
|
+
export interface ReviseResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Single task revision
|
|
20
|
+
// =============================================================================
|
|
21
|
+
|
|
22
|
+
export async function executeRevise(
|
|
23
|
+
cwd: string,
|
|
24
|
+
taskId: string,
|
|
25
|
+
prompt: string | undefined,
|
|
26
|
+
agentName: string,
|
|
27
|
+
sessionModel?: string,
|
|
28
|
+
): Promise<ReviseResult> {
|
|
29
|
+
const task = store.getTask(cwd, taskId);
|
|
30
|
+
if (!task) return { success: false, message: `Task ${taskId} not found` };
|
|
31
|
+
if (task.status === "in_progress") return { success: false, message: `Task ${taskId} is in_progress` };
|
|
32
|
+
if (getLiveWorkers(cwd).has("__reviser__")) return { success: false, message: "A revision is already running" };
|
|
33
|
+
if (isPlanningForCwd(cwd)) return { success: false, message: "Cannot revise during planning" };
|
|
34
|
+
if (isAutonomousForCwd(cwd)) return { success: false, message: "Cannot revise during autonomous work" };
|
|
35
|
+
|
|
36
|
+
if (prompt) {
|
|
37
|
+
store.appendTaskProgress(cwd, taskId, agentName, `Revision requested: "${prompt}"`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const spec = store.getTaskSpec(cwd, taskId) ?? "";
|
|
41
|
+
const progress = store.getTaskProgress(cwd, taskId) ?? "";
|
|
42
|
+
const blockContext = store.getBlockContext(cwd, taskId) ?? "";
|
|
43
|
+
const prdContent = readPrd(cwd);
|
|
44
|
+
|
|
45
|
+
const revisePrompt = buildRevisePrompt(task, spec, progress, blockContext, prdContent, prompt);
|
|
46
|
+
const config = loadCrewConfig(store.getCrewDir(cwd));
|
|
47
|
+
|
|
48
|
+
let output: string;
|
|
49
|
+
try {
|
|
50
|
+
const [agentResult] = await spawnAgents(
|
|
51
|
+
[
|
|
52
|
+
{
|
|
53
|
+
agent: "crew-planner",
|
|
54
|
+
task: revisePrompt,
|
|
55
|
+
taskId: "__reviser__",
|
|
56
|
+
modelOverride: config.models?.planner ?? sessionModel,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
cwd,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (agentResult.exitCode !== 0) {
|
|
63
|
+
const msg = `Revision failed: ${agentResult.error ?? "planner exited with error"}`;
|
|
64
|
+
logFeedEvent(cwd, agentName, "task.revise", taskId, msg);
|
|
65
|
+
return { success: false, message: msg };
|
|
66
|
+
}
|
|
67
|
+
output = agentResult.output;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
const msg = `Revision failed: ${err instanceof Error ? err.message : "unknown error"}`;
|
|
70
|
+
logFeedEvent(cwd, agentName, "task.revise", taskId, msg);
|
|
71
|
+
return { success: false, message: msg };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const parsed = parseRevisedTask(output);
|
|
75
|
+
if (!parsed) {
|
|
76
|
+
const msg = "Revision failed: could not parse revised-task block from planner output";
|
|
77
|
+
logFeedEvent(cwd, agentName, "task.revise", taskId, msg);
|
|
78
|
+
return { success: false, message: msg };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (parsed.title) store.updateTask(cwd, taskId, { title: parsed.title });
|
|
82
|
+
store.setTaskSpec(cwd, taskId, parsed.spec);
|
|
83
|
+
|
|
84
|
+
const preview = prompt ? prompt.slice(0, 60) : "revised";
|
|
85
|
+
logFeedEvent(cwd, agentName, "task.revise", taskId, preview);
|
|
86
|
+
return { success: true, message: `Revised ${taskId}${parsed.title ? `: ${parsed.title}` : ""}` };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function taskRevise(cwd: string, params: CrewParams, state: MessengerState) {
|
|
90
|
+
const { id, prompt } = params;
|
|
91
|
+
if (!id) return result("Error: id required for task.revise", { mode: "task.revise", error: "missing_id" });
|
|
92
|
+
|
|
93
|
+
const r = await executeRevise(cwd, id, prompt ?? undefined, state.agentName || "unknown", state.model || undefined);
|
|
94
|
+
if (!r.success) {
|
|
95
|
+
return result(`Error: ${r.message}`, { mode: "task.revise", error: "revision_failed", id });
|
|
96
|
+
}
|
|
97
|
+
return result(r.message, { mode: "task.revise", id });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// =============================================================================
|
|
101
|
+
// Subtree revision
|
|
102
|
+
// =============================================================================
|
|
103
|
+
|
|
104
|
+
export async function executeReviseTree(
|
|
105
|
+
cwd: string,
|
|
106
|
+
taskId: string,
|
|
107
|
+
prompt: string | undefined,
|
|
108
|
+
agentName: string,
|
|
109
|
+
sessionModel?: string,
|
|
110
|
+
): Promise<ReviseResult> {
|
|
111
|
+
const target = store.getTask(cwd, taskId);
|
|
112
|
+
if (!target) return { success: false, message: `Task ${taskId} not found` };
|
|
113
|
+
if (getLiveWorkers(cwd).has("__reviser__")) return { success: false, message: "A revision is already running" };
|
|
114
|
+
if (isPlanningForCwd(cwd)) return { success: false, message: "Cannot revise during planning" };
|
|
115
|
+
if (isAutonomousForCwd(cwd)) return { success: false, message: "Cannot revise during autonomous work" };
|
|
116
|
+
|
|
117
|
+
const dependents = store.getTransitiveDependents(cwd, taskId);
|
|
118
|
+
const subtreeAll = [target, ...dependents];
|
|
119
|
+
const subtreeIds = new Set(subtreeAll.map(t => t.id));
|
|
120
|
+
|
|
121
|
+
const liveWorkers = getLiveWorkers(cwd);
|
|
122
|
+
const liveTasks = subtreeAll.filter(t => liveWorkers.has(t.id));
|
|
123
|
+
if (liveTasks.length > 0) {
|
|
124
|
+
return { success: false, message: `Cannot revise: ${liveTasks.map(t => t.id).join(", ")} have live workers` };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const doneTasks = subtreeAll.filter(t => t.status === "done");
|
|
128
|
+
const revisable = subtreeAll.filter(t => t.status !== "done");
|
|
129
|
+
|
|
130
|
+
if (prompt) {
|
|
131
|
+
store.appendTaskProgress(cwd, taskId, agentName, `Tree revision requested: "${prompt}"`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const prdContent = readPrd(cwd);
|
|
135
|
+
const revisePrompt = buildReviseTreePrompt(subtreeAll, doneTasks, prdContent, prompt, cwd);
|
|
136
|
+
const config = loadCrewConfig(store.getCrewDir(cwd));
|
|
137
|
+
|
|
138
|
+
let output: string;
|
|
139
|
+
try {
|
|
140
|
+
const [agentResult] = await spawnAgents(
|
|
141
|
+
[
|
|
142
|
+
{
|
|
143
|
+
agent: "crew-planner",
|
|
144
|
+
task: revisePrompt,
|
|
145
|
+
taskId: "__reviser__",
|
|
146
|
+
modelOverride: config.models?.planner ?? sessionModel,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
cwd,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (agentResult.exitCode !== 0) {
|
|
153
|
+
const msg = `Tree revision failed: ${agentResult.error ?? "planner exited with error"}`;
|
|
154
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, msg);
|
|
155
|
+
return { success: false, message: msg };
|
|
156
|
+
}
|
|
157
|
+
output = agentResult.output;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
const msg = `Tree revision failed: ${err instanceof Error ? err.message : "unknown error"}`;
|
|
160
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, msg);
|
|
161
|
+
return { success: false, message: msg };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const parsed = parseRevisionTaskBlock(output);
|
|
165
|
+
if (!parsed || parsed.length === 0) {
|
|
166
|
+
const msg = "Tree revision failed: could not parse tasks-json block from planner output";
|
|
167
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, msg);
|
|
168
|
+
return { success: false, message: msg };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const existingEntries = parsed.filter(e => e.id);
|
|
172
|
+
const newEntries = parsed.filter(e => !e.id && e.title);
|
|
173
|
+
|
|
174
|
+
for (const entry of existingEntries) {
|
|
175
|
+
if (!subtreeIds.has(entry.id!)) {
|
|
176
|
+
const msg = `Tree revision failed: returned ID ${entry.id} is outside the subtree`;
|
|
177
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, msg);
|
|
178
|
+
return { success: false, message: msg };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const maxNew = Math.max(5, subtreeAll.length * 2);
|
|
183
|
+
if (newEntries.length > maxNew) {
|
|
184
|
+
const msg = `Tree revision failed: too many new tasks (${newEntries.length}, max ${maxNew})`;
|
|
185
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, msg);
|
|
186
|
+
return { success: false, message: msg };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (const entry of existingEntries) {
|
|
190
|
+
if (entry.title) store.updateTask(cwd, entry.id!, { title: entry.title });
|
|
191
|
+
store.setTaskSpec(cwd, entry.id!, entry.spec);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const titleToId = new Map<string, string>();
|
|
195
|
+
for (const t of store.getTasks(cwd)) {
|
|
196
|
+
titleToId.set(t.title.toLowerCase(), t.id);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
for (const entry of newEntries) {
|
|
200
|
+
const created = store.createTask(cwd, entry.title!, entry.spec, []);
|
|
201
|
+
titleToId.set(entry.title!.toLowerCase(), created.id);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for (const entry of [...existingEntries, ...newEntries]) {
|
|
205
|
+
if (!entry.dependsOn || entry.dependsOn.length === 0) continue;
|
|
206
|
+
const entryId = entry.id ?? titleToId.get(entry.title!.toLowerCase());
|
|
207
|
+
if (!entryId) continue;
|
|
208
|
+
|
|
209
|
+
const resolvedDeps: string[] = [];
|
|
210
|
+
for (const dep of entry.dependsOn) {
|
|
211
|
+
const resolved = titleToId.get(dep.toLowerCase()) ?? (dep.startsWith("task-") ? dep : undefined);
|
|
212
|
+
if (resolved && resolved !== entryId) resolvedDeps.push(resolved);
|
|
213
|
+
}
|
|
214
|
+
if (resolvedDeps.length > 0) {
|
|
215
|
+
store.updateTask(cwd, entryId, { depends_on: resolvedDeps });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
for (const task of revisable) {
|
|
220
|
+
store.updateTask(cwd, task.id, {
|
|
221
|
+
status: "todo",
|
|
222
|
+
started_at: undefined,
|
|
223
|
+
completed_at: undefined,
|
|
224
|
+
base_commit: undefined,
|
|
225
|
+
assigned_to: undefined,
|
|
226
|
+
summary: undefined,
|
|
227
|
+
evidence: undefined,
|
|
228
|
+
blocked_reason: undefined,
|
|
229
|
+
});
|
|
230
|
+
store.cleanupBlockFiles(cwd, task.id);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const preview = prompt ? prompt.slice(0, 60) : "revised tree";
|
|
234
|
+
logFeedEvent(cwd, agentName, "task.revise-tree", taskId, `${taskId} + ${dependents.length} dependents — ${preview}`);
|
|
235
|
+
return { success: true, message: `Revised ${taskId} + ${dependents.length} dependents` };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export async function taskReviseTree(cwd: string, params: CrewParams, state: MessengerState) {
|
|
239
|
+
const { id, prompt } = params;
|
|
240
|
+
if (!id) return result("Error: id required for task.revise-tree", { mode: "task.revise-tree", error: "missing_id" });
|
|
241
|
+
|
|
242
|
+
const r = await executeReviseTree(
|
|
243
|
+
cwd,
|
|
244
|
+
id,
|
|
245
|
+
prompt ?? undefined,
|
|
246
|
+
state.agentName || "unknown",
|
|
247
|
+
state.model || undefined,
|
|
248
|
+
);
|
|
249
|
+
if (!r.success) {
|
|
250
|
+
return result(`Error: ${r.message}`, { mode: "task.revise-tree", error: "revision_failed", id });
|
|
251
|
+
}
|
|
252
|
+
return result(r.message, { mode: "task.revise-tree", id });
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// =============================================================================
|
|
256
|
+
// Helpers
|
|
257
|
+
// =============================================================================
|
|
258
|
+
|
|
259
|
+
function readPrd(cwd: string): string {
|
|
260
|
+
const plan = store.getPlan(cwd);
|
|
261
|
+
if (!plan) return "";
|
|
262
|
+
if (plan.prompt) return plan.prompt;
|
|
263
|
+
const prdPath = path.isAbsolute(plan.prd) ? plan.prd : path.join(cwd, plan.prd);
|
|
264
|
+
try {
|
|
265
|
+
return fs.readFileSync(prdPath, "utf-8");
|
|
266
|
+
} catch {
|
|
267
|
+
return "";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function buildRevisePrompt(
|
|
272
|
+
task: Task,
|
|
273
|
+
spec: string,
|
|
274
|
+
progress: string,
|
|
275
|
+
blockContext: string,
|
|
276
|
+
prdContent: string,
|
|
277
|
+
prompt: string | undefined,
|
|
278
|
+
): string {
|
|
279
|
+
const parts: string[] = [
|
|
280
|
+
`Revise the spec for task ${task.id}: "${task.title}"`,
|
|
281
|
+
"",
|
|
282
|
+
"## Current Spec",
|
|
283
|
+
spec || "(no spec)",
|
|
284
|
+
];
|
|
285
|
+
|
|
286
|
+
if (progress) parts.push("", "## Progress", progress);
|
|
287
|
+
if (blockContext) parts.push("", "## Block Context", blockContext);
|
|
288
|
+
if (prdContent) {
|
|
289
|
+
const truncated = prdContent.length > 20000 ? prdContent.slice(0, 20000) + "\n[truncated]" : prdContent;
|
|
290
|
+
parts.push("", "## PRD", truncated);
|
|
291
|
+
}
|
|
292
|
+
if (prompt) parts.push("", "## Revision Instructions", prompt);
|
|
293
|
+
|
|
294
|
+
parts.push(
|
|
295
|
+
"",
|
|
296
|
+
"## Output Format",
|
|
297
|
+
`Return a single \`revised-task\` fenced block:
|
|
298
|
+
|
|
299
|
+
\`\`\`revised-task
|
|
300
|
+
{
|
|
301
|
+
"title": "Updated title (or omit to keep current)",
|
|
302
|
+
"spec": "Full revised spec content..."
|
|
303
|
+
}
|
|
304
|
+
\`\`\`
|
|
305
|
+
|
|
306
|
+
The spec should be complete (not a diff). Include all sections the task needs.`,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
return parts.join("\n");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function buildReviseTreePrompt(
|
|
313
|
+
subtree: Task[],
|
|
314
|
+
doneTasks: Task[],
|
|
315
|
+
prdContent: string,
|
|
316
|
+
prompt: string | undefined,
|
|
317
|
+
cwd: string,
|
|
318
|
+
): string {
|
|
319
|
+
const parts: string[] = [
|
|
320
|
+
`Revise the following task subtree. Done tasks are context (preserve them), non-done tasks are revisable.`,
|
|
321
|
+
"",
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
for (const task of subtree) {
|
|
325
|
+
const isDone = doneTasks.some(d => d.id === task.id);
|
|
326
|
+
const spec = store.getTaskSpec(cwd, task.id) ?? "(no spec)";
|
|
327
|
+
const deps = task.depends_on.length > 0 ? `\nDependencies: ${task.depends_on.join(", ")}` : "";
|
|
328
|
+
parts.push(`### ${task.id}: ${task.title} [${isDone ? "DONE - context only" : "REVISABLE"}]${deps}\n${spec}\n`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (prdContent) {
|
|
332
|
+
const truncated = prdContent.length > 20000 ? prdContent.slice(0, 20000) + "\n[truncated]" : prdContent;
|
|
333
|
+
parts.push("## PRD", truncated, "");
|
|
334
|
+
}
|
|
335
|
+
if (prompt) parts.push("## Revision Instructions", prompt, "");
|
|
336
|
+
|
|
337
|
+
parts.push(`## Output Format
|
|
338
|
+
|
|
339
|
+
Return a single \`tasks-json\` fenced block. Each task object must have:
|
|
340
|
+
- \`id\`: the existing task ID (e.g. "task-3") for existing tasks, or OMIT for new tasks
|
|
341
|
+
- \`title\`: task title
|
|
342
|
+
- \`spec\`: full revised spec content
|
|
343
|
+
- \`dependsOn\`: array of task IDs or titles this depends on
|
|
344
|
+
|
|
345
|
+
Existing tasks that you don't include will be left unchanged.
|
|
346
|
+
Do NOT include done tasks unless you need to reference them in dependencies.
|
|
347
|
+
|
|
348
|
+
\`\`\`tasks-json
|
|
349
|
+
[
|
|
350
|
+
{ "id": "task-3", "title": "...", "spec": "...", "dependsOn": [] },
|
|
351
|
+
{ "title": "New task", "spec": "...", "dependsOn": ["task-3"] }
|
|
352
|
+
]
|
|
353
|
+
\`\`\``);
|
|
354
|
+
|
|
355
|
+
return parts.join("\n");
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function parseRevisedTask(output: string): { title?: string; spec: string } | null {
|
|
359
|
+
const match = output.match(/```revised-task\s*\n([\s\S]*?)\n```/);
|
|
360
|
+
if (!match) return null;
|
|
361
|
+
try {
|
|
362
|
+
const parsed = JSON.parse(match[1]);
|
|
363
|
+
if (typeof parsed.spec !== "string" || !parsed.spec.trim()) return null;
|
|
364
|
+
return {
|
|
365
|
+
title: typeof parsed.title === "string" && parsed.title.trim() ? parsed.title.trim() : undefined,
|
|
366
|
+
spec: parsed.spec,
|
|
367
|
+
};
|
|
368
|
+
} catch {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface RevisionEntry {
|
|
374
|
+
id?: string;
|
|
375
|
+
title?: string;
|
|
376
|
+
spec: string;
|
|
377
|
+
dependsOn?: string[];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function parseRevisionTaskBlock(output: string): RevisionEntry[] | null {
|
|
381
|
+
const match = output.match(/```tasks-json\s*\n([\s\S]*?)\n```/);
|
|
382
|
+
if (!match) return null;
|
|
383
|
+
try {
|
|
384
|
+
const parsed = JSON.parse(match[1]);
|
|
385
|
+
if (!Array.isArray(parsed)) return null;
|
|
386
|
+
const entries: RevisionEntry[] = [];
|
|
387
|
+
for (const raw of parsed) {
|
|
388
|
+
if (typeof raw.spec !== "string" || !raw.spec.trim()) continue;
|
|
389
|
+
entries.push({
|
|
390
|
+
id: typeof raw.id === "string" && raw.id.trim() ? raw.id.trim() : undefined,
|
|
391
|
+
title: typeof raw.title === "string" && raw.title.trim() ? raw.title.trim() : undefined,
|
|
392
|
+
spec: raw.spec,
|
|
393
|
+
dependsOn: Array.isArray(raw.dependsOn) ? raw.dependsOn.filter((d: unknown) => typeof d === "string") : [],
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return entries.length > 0 ? entries : null;
|
|
397
|
+
} catch {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
}
|