@phi-code-admin/phi-code 0.64.2 → 0.65.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.
@@ -467,7 +467,6 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
467
467
 
468
468
  let phaseQueue: OrchestratorPhase[] = [];
469
469
  let orchestrationActive = false;
470
- let idlePollTimer: ReturnType<typeof setInterval> | null = null;
471
470
  let activeAgentPrompt: string | null = null;
472
471
  let activeAgentTools: string[] | null = null;
473
472
  let savedTools: string[] | null = null;
@@ -629,34 +628,11 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
629
628
  activateAgent(phase, ctx);
630
629
  const agentName = phase.agent?.name || phase.key;
631
630
  ctx.ui.notify(`\n${phase.label} → \`${modelId}\` (agent: ${agentName})`, "info");
632
- // Wait for agent to be idle, then send the phase instruction
633
- waitForIdleThenSend(phase.instruction, ctx);
631
+ // Small delay to let the model switch settle, then send instruction
632
+ setTimeout(() => pi.sendUserMessage(phase.instruction), 500);
634
633
  });
635
634
  }
636
635
 
637
- /**
638
- * Reliable phase sending: poll isIdle() then sendUserMessage.
639
- * Retries up to 240 attempts (120 seconds).
640
- */
641
- function waitForIdleThenSend(message: string, ctx: any) {
642
- let attempts = 0;
643
- const timer = setInterval(() => {
644
- attempts++;
645
- if (attempts > 240) {
646
- clearInterval(timer);
647
- ctx.ui.notify("⚠️ Orchestrator timeout — agent never became idle.", "warning");
648
- setOrchestrationActive(false);
649
- phasePending = false;
650
- deactivateAgent();
651
- return;
652
- }
653
- if (ctx.isIdle()) {
654
- clearInterval(timer);
655
- setTimeout(() => pi.sendUserMessage(message), 300);
656
- }
657
- }, 500);
658
- }
659
-
660
636
  // ─── System Prompt Injection — Agent personas ────────────────────
661
637
 
662
638
  pi.on("before_agent_start", async (event, _ctx) => {
@@ -667,42 +643,20 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
667
643
  return { systemPrompt: activeAgentPrompt };
668
644
  });
669
645
 
670
- // ─── Output Event — Phase Chaining ───────────────────────────────
671
- // Fires on each output chunk. We use it to detect when a phase completes.
672
- // The key fix: only start ONE idle-check timer per phase, not one per chunk.
646
+ // ─── Agent End Event — Phase Chaining ────────────────────────────
647
+ // "agent_end" fires when the full agent loop completes (all tool calls
648
+ // resolved, response fully generated). This is the ONLY reliable signal
649
+ // that a phase has finished.
650
+ //
651
+ // Previous approach used "output" event which DOES NOT EXIST in Pi.
652
+ // That's why phases 2-5 never executed.
673
653
 
674
- pi.on("output", async (_event, ctx) => {
654
+ pi.on("agent_end", async (_event, ctx) => {
675
655
  if (!orchestrationActive || !phasePending) return;
676
- if (phaseQueue.length === 0 && phasePending) {
677
- // Last phase in progress — wait for it to finish, then complete
678
- }
679
-
680
- // Debounce: clear any existing timer, start fresh
681
- if (idlePollTimer) {
682
- clearInterval(idlePollTimer);
683
- idlePollTimer = null;
684
- }
685
656
 
686
- // After output, wait a bit then check if the agent is truly idle
687
- // Use a longer initial delay (2 seconds) to let tool calls complete
688
- idlePollTimer = setTimeout(() => {
689
- let attempts = 0;
690
- idlePollTimer = setInterval(() => {
691
- attempts++;
692
- if (attempts > 60) { // 30 seconds after last output
693
- clearInterval(idlePollTimer!);
694
- idlePollTimer = null;
695
- // Don't timeout — the phase might still have tool calls
696
- return;
697
- }
698
- if (ctx.isIdle()) {
699
- clearInterval(idlePollTimer!);
700
- idlePollTimer = null;
701
- phasePending = false;
702
- sendNextPhase(ctx);
703
- }
704
- }, 500) as any;
705
- }, 2000) as any;
657
+ // Phase complete chain to next
658
+ phasePending = false;
659
+ sendNextPhase(ctx);
706
660
  });
707
661
 
708
662
  // ─── /plan Command — Full workflow ───────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.64.2",
3
+ "version": "0.65.0",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {