@phi-code-admin/phi-code 0.61.4 → 0.61.6
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/extensions/phi/orchestrator.ts +24 -100
- package/package.json +1 -1
|
@@ -226,12 +226,8 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
|
|
|
226
226
|
): Promise<{ results: TaskResult[]; progressFile: string }> {
|
|
227
227
|
const progressFile = todoFile.replace("todo-", "progress-");
|
|
228
228
|
const progressPath = join(plansDir, progressFile);
|
|
229
|
-
|
|
230
|
-
progress += `**Started:** ${new Date().toLocaleString()}\n`;
|
|
231
|
-
progress += `**Tasks:** ${tasks.length}\n**Mode:** in-session (single turn)\n\n`;
|
|
232
|
-
await writeFile(progressPath, progress, "utf-8");
|
|
229
|
+
const totalTasks = tasks.length;
|
|
233
230
|
|
|
234
|
-
// Shared context for sub-agents
|
|
235
231
|
const sharedContext = {
|
|
236
232
|
projectTitle: projectContext?.title || "Project",
|
|
237
233
|
projectDescription: projectContext?.description || "",
|
|
@@ -239,102 +235,47 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
|
|
|
239
235
|
completedTasks: [] as Array<{ index: number; title: string; agent: string; output: string }>,
|
|
240
236
|
};
|
|
241
237
|
|
|
242
|
-
|
|
243
|
-
const completed = new Set<number>();
|
|
244
|
-
const failed = new Set<number>();
|
|
245
|
-
const results: TaskResult[] = [];
|
|
246
|
-
|
|
247
|
-
// Check which tasks can run (all dependencies completed successfully)
|
|
248
|
-
function getReadyTasks(): number[] {
|
|
249
|
-
const ready: number[] = [];
|
|
250
|
-
for (let i = 0; i < tasks.length; i++) {
|
|
251
|
-
const taskNum = i + 1;
|
|
252
|
-
if (completed.has(taskNum) || failed.has(taskNum)) continue;
|
|
253
|
-
|
|
254
|
-
const deps = tasks[i].dependencies || [];
|
|
255
|
-
const allDepsMet = deps.every(d => completed.has(d));
|
|
256
|
-
const anyDepFailed = deps.some(d => failed.has(d));
|
|
257
|
-
|
|
258
|
-
if (anyDepFailed) {
|
|
259
|
-
// Skip tasks whose dependencies failed
|
|
260
|
-
failed.add(taskNum);
|
|
261
|
-
results.push({
|
|
262
|
-
taskIndex: taskNum,
|
|
263
|
-
title: tasks[i].title,
|
|
264
|
-
agent: tasks[i].agent || "code",
|
|
265
|
-
status: "skipped",
|
|
266
|
-
output: `Skipped: dependency #${deps.find(d => failed.has(d))} failed`,
|
|
267
|
-
durationMs: 0,
|
|
268
|
-
});
|
|
269
|
-
notify(`⏭️ Task ${taskNum}: **${tasks[i].title}** — skipped (dependency failed)`, "warning");
|
|
270
|
-
} else if (allDepsMet) {
|
|
271
|
-
ready.push(i);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return ready;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const totalTasks = tasks.length;
|
|
278
|
-
|
|
279
|
-
notify(`🚀 Executing ${totalTasks} tasks in-session (no subprocess overhead)...`, "info");
|
|
238
|
+
notify(`🚀 Executing ${totalTasks} tasks in-session...`, "info");
|
|
280
239
|
|
|
281
240
|
// Build a single comprehensive prompt with ALL tasks
|
|
282
|
-
|
|
283
|
-
let megaPrompt = `# 📋 Project Plan: ${sharedContext.projectTitle}\n\n`;
|
|
241
|
+
let megaPrompt = `# 📋 Project: ${sharedContext.projectTitle}\n\n`;
|
|
284
242
|
megaPrompt += `${sharedContext.projectDescription}\n\n`;
|
|
285
243
|
if (sharedContext.specSummary) {
|
|
286
244
|
megaPrompt += `## Spec\n${sharedContext.specSummary}\n\n`;
|
|
287
245
|
}
|
|
288
246
|
megaPrompt += `## Tasks (execute ALL in order)\n\n`;
|
|
289
247
|
|
|
248
|
+
const results: TaskResult[] = [];
|
|
249
|
+
|
|
290
250
|
for (let i = 0; i < tasks.length; i++) {
|
|
291
251
|
const task = tasks[i];
|
|
292
252
|
const { taskPrompt } = executeTaskInSession(task, sharedContext);
|
|
293
253
|
megaPrompt += `---\n\n${taskPrompt}\n\n`;
|
|
294
|
-
|
|
295
|
-
// Mark all tasks as completed for the progress file
|
|
296
254
|
results.push({
|
|
297
|
-
taskIndex: i + 1,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
status: "success",
|
|
301
|
-
output: "(executed in-session)",
|
|
302
|
-
durationMs: 0,
|
|
255
|
+
taskIndex: i + 1, title: task.title,
|
|
256
|
+
agent: task.agent || "code", status: "success",
|
|
257
|
+
output: "(in-session)", durationMs: 0,
|
|
303
258
|
});
|
|
304
259
|
}
|
|
305
260
|
|
|
306
261
|
megaPrompt += `---\n\n## ⚠️ Instructions\n\n`;
|
|
307
262
|
megaPrompt += `Execute ALL ${totalTasks} tasks above **sequentially**. For each task:\n`;
|
|
308
263
|
megaPrompt += `1. Create/edit the required files using your tools\n`;
|
|
309
|
-
megaPrompt += `2. Report what you did
|
|
264
|
+
megaPrompt += `2. Report what you did briefly\n`;
|
|
310
265
|
megaPrompt += `3. Move to the next task\n\n`;
|
|
311
|
-
megaPrompt += `Do NOT skip any task. Complete the entire project
|
|
266
|
+
megaPrompt += `Do NOT skip any task. Complete the entire project.\n`;
|
|
312
267
|
|
|
313
|
-
// Write progress
|
|
314
|
-
progress
|
|
315
|
-
progress +=
|
|
268
|
+
// Write progress file
|
|
269
|
+
let progress = `# Progress: ${todoFile}\n\n`;
|
|
270
|
+
progress += `**Started:** ${new Date().toLocaleString()}\n`;
|
|
271
|
+
progress += `**Tasks:** ${totalTasks} | **Mode:** in-session\n\n`;
|
|
316
272
|
for (const r of results) {
|
|
317
273
|
progress += `- Task ${r.taskIndex}: ${r.title} [${r.agent}]\n`;
|
|
318
274
|
}
|
|
319
|
-
progress += `\n---\n\n## Summary\n\n`;
|
|
320
|
-
progress += `- **Mode:** in-session (single turn)\n`;
|
|
321
|
-
progress += `- **Tasks:** ${totalTasks}\n`;
|
|
322
|
-
progress += `- **Status:** sent to LLM\n`;
|
|
323
275
|
await writeFile(progressPath, progress, "utf-8");
|
|
324
276
|
|
|
325
|
-
//
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const statusParts = [`📋 ${totalTasks} tasks sent`];
|
|
329
|
-
|
|
330
|
-
notify(
|
|
331
|
-
`\n🏁 **Execution complete!** (${wave - 1} waves)\n` +
|
|
332
|
-
statusParts.join(" | ") + ` | ⏱️ ${(totalTime / 1000).toFixed(1)}s\n` +
|
|
333
|
-
`Progress: \`${progressFile}\``,
|
|
334
|
-
failedCount === 0 ? "info" : "warning"
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
return { results, progressFile };
|
|
277
|
+
// Return the mega-prompt as tool result — LLM sees it and executes
|
|
278
|
+
return { results, progressFile, megaPrompt };
|
|
338
279
|
}
|
|
339
280
|
|
|
340
281
|
// ─── Generate Plan Files ─────────────────────────────────────────
|
|
@@ -467,39 +408,22 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
|
|
|
467
408
|
p.constraints?.length ? `Constraints: ${p.constraints.join("; ")}` : "",
|
|
468
409
|
].filter(Boolean).join("\n");
|
|
469
410
|
|
|
470
|
-
const { results, progressFile } = await executePlan(
|
|
411
|
+
const { results, progressFile, megaPrompt } = await executePlan(
|
|
471
412
|
p.tasks, todoFile, notify,
|
|
472
413
|
{ title: p.title, description: p.description, specSummary },
|
|
473
414
|
);
|
|
474
415
|
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const summary = `**🏁 Project "${p.title}" — Complete!**
|
|
480
|
-
|
|
481
|
-
**Plan files:** \`${specFile}\`, \`${todoFile}\`
|
|
482
|
-
**Progress:** \`${progressFile}\`
|
|
483
|
-
|
|
484
|
-
**Results:**
|
|
485
|
-
- ✅ Succeeded: ${succeeded}/${results.length}
|
|
486
|
-
- ❌ Failed: ${failed}
|
|
487
|
-
- ⏱️ Total time: ${(totalTime / 1000).toFixed(1)}s
|
|
488
|
-
|
|
489
|
-
**Task details:**
|
|
490
|
-
${results.map(r => {
|
|
491
|
-
const icon = r.status === "success" ? "✅" : "❌";
|
|
492
|
-
return `${icon} Task ${r.taskIndex}: ${r.title} [${r.agent}] (${(r.durationMs / 1000).toFixed(1)}s)`;
|
|
493
|
-
}).join("\n")}
|
|
494
|
-
|
|
495
|
-
All files in \`.phi/plans/\``;
|
|
416
|
+
const header = `**📋 Project "${p.title}" — ${p.tasks.length} tasks planned!**\n` +
|
|
417
|
+
`Plan: \`${specFile}\`, \`${todoFile}\` | Progress: \`${progressFile}\`\n\n` +
|
|
418
|
+
`---\n\n`;
|
|
496
419
|
|
|
420
|
+
// Return the mega-prompt as tool result
|
|
421
|
+
// The LLM sees this and executes all tasks in its current turn
|
|
497
422
|
return {
|
|
498
|
-
content: [{ type: "text", text:
|
|
423
|
+
content: [{ type: "text", text: header + megaPrompt }],
|
|
499
424
|
details: {
|
|
500
425
|
specFile, todoFile, progressFile,
|
|
501
|
-
taskCount: p.tasks.length,
|
|
502
|
-
totalTimeMs: totalTime, title: p.title,
|
|
426
|
+
taskCount: p.tasks.length,
|
|
503
427
|
},
|
|
504
428
|
};
|
|
505
429
|
} catch (error) {
|