@chankov/agent-fleet 2.0.5 → 2.0.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/.pi/harnesses/agent-hub/README.md +74 -10
- package/.pi/harnesses/agent-hub/acceptance.ts +62 -0
- package/.pi/harnesses/agent-hub/artifacts.js +1 -1
- package/.pi/harnesses/agent-hub/budget-continuation.ts +0 -60
- package/.pi/harnesses/agent-hub/budget-recovery.ts +97 -0
- package/.pi/harnesses/agent-hub/commands/budget-continue.ts +10 -0
- package/.pi/harnesses/agent-hub/commands/context.ts +2 -0
- package/.pi/harnesses/agent-hub/commands/retry.ts +10 -0
- package/.pi/harnesses/agent-hub/config/agents.ts +3 -9
- package/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +7 -5
- package/.pi/harnesses/agent-hub/context/budgets.ts +8 -14
- package/.pi/harnesses/agent-hub/debate-command.ts +2 -2
- package/.pi/harnesses/agent-hub/dispatch-coms.ts +4 -1
- package/.pi/harnesses/agent-hub/dispatch-native-complete.ts +37 -18
- package/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +5 -5
- package/.pi/harnesses/agent-hub/dispatch-native-types.ts +22 -0
- package/.pi/harnesses/agent-hub/dispatch-native.ts +25 -11
- package/.pi/harnesses/agent-hub/execution-evidence.ts +80 -0
- package/.pi/harnesses/agent-hub/hub-state-audit.js +5 -0
- package/.pi/harnesses/agent-hub/index.ts +79 -43
- package/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +2 -0
- package/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +9 -30
- package/.pi/harnesses/agent-hub/monitor-control.ts +1 -1
- package/.pi/harnesses/agent-hub/no-progress.ts +76 -0
- package/.pi/harnesses/agent-hub/package.json +1 -1
- package/.pi/harnesses/agent-hub/policy/roster.ts +16 -1
- package/.pi/harnesses/agent-hub/policy/work-mode.ts +3 -2
- package/.pi/harnesses/agent-hub/poll-command.ts +2 -2
- package/.pi/harnesses/agent-hub/prompts/context.ts +1 -0
- package/.pi/harnesses/agent-hub/prompts/system-prompt.ts +3 -1
- package/.pi/harnesses/agent-hub/research/runtime.ts +17 -2
- package/.pi/harnesses/agent-hub/research/spawn-run.ts +14 -6
- package/.pi/harnesses/agent-hub/scope-gate.js +50 -30
- package/.pi/harnesses/agent-hub/tools/context.ts +2 -0
- package/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +6 -3
- package/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +65 -24
- package/.pi/harnesses/agent-hub/types.ts +1 -0
- package/.pi/harnesses/agent-hub/ui/pool.ts +6 -1
- package/.pi/harnesses/agent-hub/work-mode-controls.ts +1 -1
- package/.pi/harnesses/ask-user-remote/README.md +8 -2
- package/.pi/harnesses/ask-user-remote/index.ts +40 -14
- package/.pi/harnesses/ask-user-remote/questions.ts +161 -0
- package/.pi/harnesses/ask-user-remote/race-core.js +23 -5
- package/.pi/harnesses/ask-user-remote/runtime-ask.ts +43 -0
- package/.pi/harnesses/coms/README.md +1 -1
- package/.pi/harnesses/coms/index.ts +7 -1
- package/.pi/harnesses/coms/package.json +1 -1
- package/.pi/harnesses/damage-control-continue/package.json +1 -1
- package/.pi/harnesses/lib/context-budget-child-prompt.ts +5 -4
- package/.pi/harnesses/lib/fleet-dashboard-view.ts +1 -1
- package/.versions/2.0.6/.pi/agents/dispatch-policy.yaml +32 -0
- package/.versions/2.0.6/.pi/agents/model-profiles.yaml +83 -0
- package/.versions/2.0.6/.pi/agents/peers.yaml +145 -0
- package/.versions/2.0.6/.pi/agents/teams.yaml +41 -0
- package/.versions/2.0.6/.pi/agents/voices.yaml +13 -0
- package/.versions/2.0.6/.pi/damage-control-rules.yaml +297 -0
- package/.versions/2.0.6/.pi/extensions/agent-fleet-update-check/README.md +57 -0
- package/.versions/2.0.6/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
- package/.versions/2.0.6/.pi/extensions/agent-fleet-update-check/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/btw/README.md +120 -0
- package/.versions/2.0.6/.pi/extensions/btw/index.ts +914 -0
- package/.versions/2.0.6/.pi/extensions/btw/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/btw/state.js +179 -0
- package/.versions/2.0.6/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
- package/.versions/2.0.6/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
- package/.versions/2.0.6/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/compact-and-continue/README.md +42 -0
- package/.versions/2.0.6/.pi/extensions/compact-and-continue/index.ts +120 -0
- package/.versions/2.0.6/.pi/extensions/compact-and-continue/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/mcp-bridge/README.md +46 -0
- package/.versions/2.0.6/.pi/extensions/mcp-bridge/index.ts +206 -0
- package/.versions/2.0.6/.pi/extensions/mcp-bridge/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/package-lock.json +1175 -0
- package/.versions/2.0.6/.pi/extensions/package.json +9 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/README.md +205 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/config.ts +198 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/index.ts +248 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/package.json +6 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/providers.ts +214 -0
- package/.versions/2.0.6/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/README.md +1203 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/acceptance.ts +62 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/access-approval.ts +135 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/artifacts.js +146 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/backend-policy.js +174 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/budget-continuation.ts +13 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/budget-recovery.ts +97 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/budget-continue.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/context.ts +43 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/debate.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/models.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/poll.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/retry.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/work-mode.ts +29 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/config/agents.ts +173 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/config/model-profiles.ts +216 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/config/overrides.ts +153 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +213 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context/budgets.ts +202 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/context-window.js +106 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/debate-command.ts +176 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/delegate.ts +446 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-coms.ts +237 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-native-complete.ts +154 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +156 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +193 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-native-types.ts +230 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-native.ts +213 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/dispatch-observability.ts +225 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/docs-lane.js +122 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/drift-watchdog.js +218 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/execution-evidence.ts +80 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/external-blocker.js +85 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/fixtures/registration-surface.json +57 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/footer.ts +30 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/helpers.ts +266 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/hub-state-audit.js +64 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/index.ts +2151 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/input/completions.ts +76 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/input/shortcuts.ts +18 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +123 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +143 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +74 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/no-progress.ts +76 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/package.json +7 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/policy/models.ts +153 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/policy/profile-activation.ts +62 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/policy/profile-runtime.ts +120 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/policy/roster.ts +94 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/policy/work-mode.ts +119 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/poll-command.ts +176 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/presentation.ts +48 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/prompts/context.ts +47 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/prompts/fragments.ts +115 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/prompts/session-start.ts +90 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/prompts/system-prompt.ts +112 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/research/controls.ts +74 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/research/runtime.ts +192 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/research/spawn-run.ts +156 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/return-contract.js +293 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/return-extract.js +75 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/review-findings.js +102 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/run-budget.js +537 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/run-namespace.js +87 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/scope-gate.js +123 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/session-health.js +110 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/session-start.ts +42 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/spawn.ts +404 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/timeline.ts +54 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/action-executors.ts +149 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/context.ts +134 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +82 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +273 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/fleet-tools.ts +202 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/herdr-executors.ts +86 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/set-task-tier.ts +29 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/spawn-research.ts +62 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/tools/verification-contract.ts +77 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/types.ts +63 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/activity-dots.ts +16 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/context-budget.ts +86 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/detail-panel.ts +178 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +125 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/grid.ts +42 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/history.ts +234 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/running-strip.ts +139 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/ui/zoom.ts +204 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/version.ts +42 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/work-mode-controls.ts +56 -0
- package/.versions/2.0.6/.pi/harnesses/agent-hub/work-mode.ts +167 -0
- package/.versions/2.0.6/.pi/harnesses/ask-user-remote/README.md +59 -0
- package/.versions/2.0.6/.pi/harnesses/ask-user-remote/index.ts +558 -0
- package/.versions/2.0.6/.pi/harnesses/ask-user-remote/questions.ts +161 -0
- package/.versions/2.0.6/.pi/harnesses/ask-user-remote/race-core.js +124 -0
- package/.versions/2.0.6/.pi/harnesses/ask-user-remote/runtime-ask.ts +43 -0
- package/.versions/2.0.6/.pi/harnesses/coms/README.md +100 -0
- package/.versions/2.0.6/.pi/harnesses/coms/index.ts +282 -0
- package/.versions/2.0.6/.pi/harnesses/coms/package.json +7 -0
- package/.versions/2.0.6/.pi/harnesses/coms/version.ts +42 -0
- package/.versions/2.0.6/.pi/harnesses/damage-control-continue/README.md +124 -0
- package/.versions/2.0.6/.pi/harnesses/damage-control-continue/index.ts +536 -0
- package/.versions/2.0.6/.pi/harnesses/damage-control-continue/package.json +7 -0
- package/.versions/2.0.6/.pi/harnesses/damage-control-continue/version.ts +42 -0
- package/.versions/2.0.6/.pi/harnesses/lib/coms-core-io.ts +385 -0
- package/.versions/2.0.6/.pi/harnesses/lib/coms-core.ts +577 -0
- package/.versions/2.0.6/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
- package/.versions/2.0.6/.pi/harnesses/lib/context-budget-child-prompt.ts +180 -0
- package/.versions/2.0.6/.pi/harnesses/lib/context-budget-hub-prompt.ts +114 -0
- package/.versions/2.0.6/.pi/harnesses/lib/context-budget-view.ts +107 -0
- package/.versions/2.0.6/.pi/harnesses/lib/context-budget.ts +114 -0
- package/.versions/2.0.6/.pi/harnesses/lib/damage-control-shared.ts +197 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-dashboard-ops.ts +161 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-dashboard-view.ts +148 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-detail-view.ts +247 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-overlay.ts +26 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-panel.ts +34 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-read-model.ts +131 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-selection.ts +24 -0
- package/.versions/2.0.6/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
- package/.versions/2.0.6/.pi/harnesses/lib/herdr-client.ts +472 -0
- package/.versions/2.0.6/.pi/harnesses/lib/herdr-presence.ts +399 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
- package/.versions/2.0.6/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
- package/.versions/2.0.6/.pi/harnesses/lib/spawned-peers.js +190 -0
- package/.versions/2.0.6/.pi/harnesses/package-lock.json +2039 -0
- package/.versions/2.0.6/.pi/harnesses/package.json +10 -0
- package/.versions/2.0.6/.pi/prompts/af-build.md +24 -0
- package/.versions/2.0.6/.pi/prompts/af-code-simplify.md +22 -0
- package/.versions/2.0.6/.pi/prompts/af-plan.md +17 -0
- package/.versions/2.0.6/.pi/prompts/af-review.md +16 -0
- package/.versions/2.0.6/.pi/prompts/af-set-hermes-telegram.md +15 -0
- package/.versions/2.0.6/.pi/prompts/af-set-hermes-watchdog.md +6 -0
- package/.versions/2.0.6/.pi/prompts/af-ship.md +17 -0
- package/.versions/2.0.6/.pi/prompts/af-spec.md +15 -0
- package/.versions/2.0.6/.pi/prompts/af-test.md +19 -0
- package/.versions/2.0.6/.pi/skills/bowser/SKILL.md +145 -0
- package/.versions/2.0.6/.version +1 -0
- package/.versions/2.0.6/agents/architect.md +25 -0
- package/.versions/2.0.6/agents/bowser.md +28 -0
- package/.versions/2.0.6/agents/builder.md +56 -0
- package/.versions/2.0.6/agents/code-reviewer.md +210 -0
- package/.versions/2.0.6/agents/deep-researcher.md +33 -0
- package/.versions/2.0.6/agents/documenter.md +23 -0
- package/.versions/2.0.6/agents/orchestrator.md +23 -0
- package/.versions/2.0.6/agents/plan-reviewer.md +84 -0
- package/.versions/2.0.6/agents/planner.md +106 -0
- package/.versions/2.0.6/agents/releaser.md +25 -0
- package/.versions/2.0.6/agents/researcher.md +31 -0
- package/.versions/2.0.6/agents/security-auditor.md +168 -0
- package/.versions/2.0.6/agents/test-engineer.md +154 -0
- package/.versions/2.0.6/agents/web-debugger.md +44 -0
- package/.versions/2.0.6/agents/web-performance-auditor.md +194 -0
- package/.versions/2.0.6/bin/catalog/harness-runtime-closure.json +31 -0
- package/.versions/2.0.6/codex/fleet-session-client/SKILL.md +34 -0
- package/.versions/2.0.6/codex/fleet-session-client.zip +0 -0
- package/.versions/2.0.6/docs/ARCHITECTURE.md +407 -0
- package/.versions/2.0.6/docs/agent-fleet-setup.md +561 -0
- package/.versions/2.0.6/docs/claude-code-coms-bridge.md +133 -0
- package/.versions/2.0.6/docs/codex-session-bridge.md +219 -0
- package/.versions/2.0.6/docs/coms-hermes-bridge.md +188 -0
- package/.versions/2.0.6/docs/getting-started.md +126 -0
- package/.versions/2.0.6/docs/npm-install.md +301 -0
- package/.versions/2.0.6/docs/pi-extensions.md +446 -0
- package/.versions/2.0.6/docs/pi-setup.md +76 -0
- package/.versions/2.0.6/docs/skill-anatomy.md +150 -0
- package/.versions/2.0.6/hermes/README.md +347 -0
- package/.versions/2.0.6/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
- package/.versions/2.0.6/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
- package/.versions/2.0.6/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
- package/.versions/2.0.6/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
- package/.versions/2.0.6/hermes/gates/gate-o-capability.md +8 -0
- package/.versions/2.0.6/hermes/gates/gate-o-validator-fixtures.json +1 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +773 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
- package/.versions/2.0.6/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
- package/.versions/2.0.6/hermes/skills/hub-conductor/SKILL.md +84 -0
- package/.versions/2.0.6/hermes/skills/hub-liaison/SKILL.md +84 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/SKILL.md +76 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/manifest.json +1 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
- package/.versions/2.0.6/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
- package/.versions/2.0.6/hermes/watchdog-tests/__init__.py +0 -0
- package/.versions/2.0.6/hooks/coms-stop-hook.mjs +84 -0
- package/.versions/2.0.6/install-manifest.json +2924 -0
- package/.versions/2.0.6/justfile +247 -0
- package/.versions/2.0.6/manifest-meta.json +976 -0
- package/.versions/2.0.6/references/accessibility-checklist.md +160 -0
- package/.versions/2.0.6/references/communication-contract.md +26 -0
- package/.versions/2.0.6/references/definition-of-done.md +67 -0
- package/.versions/2.0.6/references/fleet-coordination-patterns.md +171 -0
- package/.versions/2.0.6/references/observability-checklist.md +91 -0
- package/.versions/2.0.6/references/orchestration-patterns.md +370 -0
- package/.versions/2.0.6/references/performance-checklist.md +153 -0
- package/.versions/2.0.6/references/prompting-patterns.md +380 -0
- package/.versions/2.0.6/references/security-checklist.md +179 -0
- package/.versions/2.0.6/references/testing-patterns.md +236 -0
- package/.versions/2.0.6/references/workflow-authoring.md +304 -0
- package/.versions/2.0.6/scripts/claude-code-preflight.ts +70 -0
- package/.versions/2.0.6/scripts/coms-claude-bridge.ts +411 -0
- package/.versions/2.0.6/scripts/coms-cli.ts +425 -0
- package/.versions/2.0.6/scripts/coms-hermes-bridge.ts +413 -0
- package/.versions/2.0.6/scripts/fleet-codex-client.ts +69 -0
- package/.versions/2.0.6/scripts/fleet-codex-read.py +146 -0
- package/.versions/2.0.6/scripts/fleet.ts +216 -0
- package/.versions/2.0.6/scripts/flow.ts +137 -0
- package/.versions/2.0.6/scripts/hermes-monitor-capability-runner.ts +25 -0
- package/.versions/2.0.6/scripts/hermes-monitor-scenario.ts +474 -0
- package/.versions/2.0.6/scripts/hermes-watchdog-capability-probe.ts +45 -0
- package/.versions/2.0.6/scripts/install-hermes-plugin.sh +180 -0
- package/.versions/2.0.6/scripts/lib/claude-bridge-core.ts +210 -0
- package/.versions/2.0.6/scripts/lib/coms-envelope.ts +582 -0
- package/.versions/2.0.6/scripts/lib/fake-herdr-server.ts +88 -0
- package/.versions/2.0.6/scripts/lib/fleet-codex-catalog.ts +63 -0
- package/.versions/2.0.6/scripts/lib/fleet-codex-operations.ts +190 -0
- package/.versions/2.0.6/scripts/lib/fleet-codex-session.ts +166 -0
- package/.versions/2.0.6/scripts/lib/fleet-codex-transport.ts +124 -0
- package/.versions/2.0.6/scripts/lib/fleet-command.ts +252 -0
- package/.versions/2.0.6/scripts/lib/flow-command.ts +93 -0
- package/.versions/2.0.6/scripts/lib/flow-maintenance.ts +230 -0
- package/.versions/2.0.6/scripts/lib/herdr-layout.ts +281 -0
- package/.versions/2.0.6/scripts/lib/hermes-bridge-core.ts +241 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-events.ts +1 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-herdr.ts +2 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-model.ts +3 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-registry.ts +2 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-socket.ts +2 -0
- package/.versions/2.0.6/scripts/lib/hermes-monitor-store.ts +2 -0
- package/.versions/2.0.6/scripts/lib/monitor-env.ts +146 -0
- package/.versions/2.0.6/scripts/lib/peer-launch.ts +318 -0
- package/.versions/2.0.6/scripts/lib/persona-banner.ts +62 -0
- package/.versions/2.0.6/scripts/lib/runtime-dependencies.js +124 -0
- package/.versions/2.0.6/scripts/lib/spawn-stagger.ts +101 -0
- package/.versions/2.0.6/scripts/lib/team-project.ts +178 -0
- package/.versions/2.0.6/scripts/lib/team-snapshot.ts +147 -0
- package/.versions/2.0.6/scripts/package-lock.json +35 -0
- package/.versions/2.0.6/scripts/package.json +9 -0
- package/.versions/2.0.6/scripts/peer-banner.ts +40 -0
- package/.versions/2.0.6/scripts/peer-launch.ts +285 -0
- package/.versions/2.0.6/scripts/team-snapshot.ts +237 -0
- package/.versions/2.0.6/scripts/team-up.ts +378 -0
- package/.versions/2.0.6/scripts/workflows/lib/agent-phase.ts +133 -0
- package/.versions/2.0.6/scripts/workflows/lib/changes.ts +61 -0
- package/.versions/2.0.6/scripts/workflows/lib/debate.ts +149 -0
- package/.versions/2.0.6/scripts/workflows/lib/env.ts +34 -0
- package/.versions/2.0.6/scripts/workflows/lib/envelopes.ts +169 -0
- package/.versions/2.0.6/scripts/workflows/lib/gates.ts +81 -0
- package/.versions/2.0.6/scripts/workflows/lib/git.ts +96 -0
- package/.versions/2.0.6/scripts/workflows/lib/merge.ts +95 -0
- package/.versions/2.0.6/scripts/workflows/lib/model-profile.ts +22 -0
- package/.versions/2.0.6/scripts/workflows/lib/model-visibility.ts +92 -0
- package/.versions/2.0.6/scripts/workflows/lib/permissions.ts +130 -0
- package/.versions/2.0.6/scripts/workflows/lib/personas.ts +57 -0
- package/.versions/2.0.6/scripts/workflows/lib/poll.ts +86 -0
- package/.versions/2.0.6/scripts/workflows/lib/quality.ts +64 -0
- package/.versions/2.0.6/scripts/workflows/lib/run.ts +108 -0
- package/.versions/2.0.6/scripts/workflows/lib/trace.ts +34 -0
- package/.versions/2.0.6/scripts/workflows/lib/voices.ts +128 -0
- package/.versions/2.0.6/scripts/workflows/lib/writer-lease.ts +112 -0
- package/.versions/2.0.6/scripts/workflows/tsconfig.json +22 -0
- package/.versions/2.0.6/scripts/workflows/wf-build-test.ts +61 -0
- package/.versions/2.0.6/scripts/workflows/wf-debate.ts +87 -0
- package/.versions/2.0.6/scripts/workflows/wf-document.ts +50 -0
- package/.versions/2.0.6/scripts/workflows/wf-poll.ts +95 -0
- package/.versions/2.0.6/scripts/workflows/wf-quality.ts +20 -0
- package/.versions/2.0.6/scripts/workflows/wf-scout.ts +38 -0
- package/.versions/2.0.6/skills/_internal/grilling.md +59 -0
- package/.versions/2.0.6/skills/browser-testing-with-devtools/SKILL.md +351 -0
- package/.versions/2.0.6/skills/code-review-and-quality/SKILL.md +381 -0
- package/.versions/2.0.6/skills/compound-learning/SKILL.md +137 -0
- package/.versions/2.0.6/skills/context-engineering/SKILL.md +291 -0
- package/.versions/2.0.6/skills/deprecation-and-migration/SKILL.md +206 -0
- package/.versions/2.0.6/skills/designing-agents/SKILL.md +394 -0
- package/.versions/2.0.6/skills/designing-agents/pi-harness-authoring.md +222 -0
- package/.versions/2.0.6/skills/drafting-workflows/SKILL.md +143 -0
- package/.versions/2.0.6/skills/drafting-workflows/scripts/make-workflow.ts +177 -0
- package/.versions/2.0.6/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/2.0.6/skills/git-workflow-and-versioning/SKILL.md +316 -0
- package/.versions/2.0.6/skills/idea-refine/SKILL.md +182 -0
- package/.versions/2.0.6/skills/idea-refine/examples.md +238 -0
- package/.versions/2.0.6/skills/idea-refine/frameworks.md +99 -0
- package/.versions/2.0.6/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/2.0.6/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/2.0.6/skills/incremental-implementation/SKILL.md +298 -0
- package/.versions/2.0.6/skills/interview-me/SKILL.md +226 -0
- package/.versions/2.0.6/skills/orchestration-verification/SKILL.md +181 -0
- package/.versions/2.0.6/skills/peer-coms/SKILL.md +90 -0
- package/.versions/2.0.6/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/2.0.6/skills/planning-and-task-breakdown/SKILL.md +265 -0
- package/.versions/2.0.6/skills/security-and-hardening/SKILL.md +461 -0
- package/.versions/2.0.6/skills/spec-driven-development/SKILL.md +256 -0
- package/.versions/2.0.6/skills/using-agent-skills/SKILL.md +197 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/LICENSE +21 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/README.md +11 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
- package/.versions/2.0.6/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
- package/CHANGELOG.md +23 -0
- package/README.md +12 -14
- package/bin/catalog/harness-runtime-closure.json +1 -6
- package/bin/lib/desired.js +2 -2
- package/bin/lib/features.js +8 -1
- package/bin/snapshot-version.js +1 -2
- package/codex/fleet-session-client/SKILL.md +34 -0
- package/codex/fleet-session-client.zip +0 -0
- package/docs/ARCHITECTURE.md +4 -4
- package/docs/MIGRATION-agent-fleet.md +2 -2
- package/docs/assets/branding/README.md +33 -0
- package/docs/assets/branding/agent-fleet-logo-v1.png +0 -0
- package/docs/assets/branding/agent-fleet-logo-white-v1.png +0 -0
- package/docs/codex-session-bridge.md +219 -0
- package/docs/coms-hermes-bridge.md +4 -5
- package/docs/getting-started.md +2 -0
- package/docs/npm-install.md +3 -1
- package/docs/pi-setup.md +2 -0
- package/hermes/README.md +1 -1
- package/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +19 -16
- package/install-manifest.json +54 -72
- package/justfile +0 -42
- package/manifest-meta.json +50 -43
- package/package.json +10 -7
- package/scripts/coms-cli.ts +2 -61
- package/scripts/fleet-codex-client.ts +69 -0
- package/scripts/fleet-codex-read.py +146 -0
- package/scripts/fleet.ts +0 -6
- package/scripts/lib/fleet-codex-catalog.ts +63 -0
- package/scripts/lib/fleet-codex-operations.ts +190 -0
- package/scripts/lib/fleet-codex-session.ts +166 -0
- package/scripts/lib/fleet-codex-transport.ts +124 -0
- package/scripts/lib/fleet-command.ts +5 -23
- package/scripts/lib/team-project.ts +15 -50
- package/scripts/team-up.ts +6 -34
- package/codex/CONDUCTOR.md +0 -148
- package/docs/codex-remote-conductor.md +0 -170
- package/scripts/codex-conductor.ts +0 -41
- package/scripts/codex-remote-control.ts +0 -167
- package/scripts/lib/codex-conductor.ts +0 -88
- package/scripts/lib/codex-remote-control.ts +0 -482
- package/systemd/user/agent-fleet-codex-remote-control.service.in +0 -23
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { lstatSync, readFileSync, readlinkSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
export function snapshotWorktree(cwd) {
|
|
7
|
+
const status = gitStatus(cwd);
|
|
8
|
+
if (status.skipped) return { skipped: true, reason: status.reason, paths: new Set() };
|
|
9
|
+
try {
|
|
10
|
+
const fingerprints = new Map(status.paths.map(path => [path, fileFingerprint(cwd, path)]));
|
|
11
|
+
let head = "";
|
|
12
|
+
try { head = execFileSync("git", ["-C", cwd, "rev-parse", "HEAD"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim(); } catch {}
|
|
13
|
+
return { skipped: false, paths: new Set(status.paths), fingerprints, head };
|
|
14
|
+
} catch (error) { return { skipped: true, reason: String(error), paths: new Set() }; }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function fileFingerprint(cwd, path) {
|
|
18
|
+
try {
|
|
19
|
+
const file = join(cwd, path), stat = lstatSync(file);
|
|
20
|
+
if (!stat.isFile() && !stat.isSymbolicLink()) throw new Error(`Cannot prove file-content delta for ${path}`);
|
|
21
|
+
return createHash("sha256").update(String(stat.mode)).update("\0").update(stat.isSymbolicLink() ? readlinkSync(file) : readFileSync(file)).digest("hex");
|
|
22
|
+
} catch (error) { if (error.code === "ENOENT") return "missing"; throw error; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function diffAgainst(snapshot, cwd) {
|
|
26
|
+
const current = snapshotWorktree(cwd);
|
|
27
|
+
if (snapshot?.skipped || current.skipped || snapshot?.head !== current.head) {
|
|
28
|
+
return { skipped: true, reason: snapshot?.reason || current.reason || "HEAD changed during observation; content attribution is incomplete", paths: [] };
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const paths = [...new Set([...snapshot.paths, ...current.paths])].filter(path => {
|
|
32
|
+
const before = snapshot.fingerprints.get(path);
|
|
33
|
+
return before === undefined || before !== (current.fingerprints.get(path) ?? fileFingerprint(cwd, path));
|
|
34
|
+
}).sort();
|
|
35
|
+
return { skipped: false, paths };
|
|
36
|
+
} catch (error) { return { skipped: true, reason: String(error), paths: [] }; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Runtime outputs are not input progress. Callers add explicitly supplied evidence separately. */
|
|
40
|
+
export function worktreeRevision(cwd, scopes = []) {
|
|
41
|
+
const snapshot = snapshotWorktree(cwd);
|
|
42
|
+
if (snapshot.skipped) return "unavailable";
|
|
43
|
+
const entries = [...snapshot.fingerprints].filter(([path]) => !path.startsWith(".pi/agent-sessions/") && (!scopes.length || checkScope([path], scopes).inScope.length)).sort(([a], [b]) => a.localeCompare(b));
|
|
44
|
+
return createHash("sha256").update(JSON.stringify([snapshot.head, entries])).digest("hex");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function checkScope(changedPaths, scopeGlobs) {
|
|
48
|
+
const scopes = (scopeGlobs || []).map(normalizePath).filter(Boolean);
|
|
49
|
+
const inScope = [];
|
|
50
|
+
const outOfScope = [];
|
|
51
|
+
for (const rawPath of changedPaths || []) {
|
|
52
|
+
const changed = normalizePath(rawPath);
|
|
53
|
+
if (!changed) continue;
|
|
54
|
+
if (scopes.some((scope) => matchesScope(changed, scope))) inScope.push(changed);
|
|
55
|
+
else outOfScope.push(changed);
|
|
56
|
+
}
|
|
57
|
+
return { inScope: uniqueSorted(inScope), outOfScope: uniqueSorted(outOfScope) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function gitStatus(cwd) {
|
|
61
|
+
try {
|
|
62
|
+
const output = execFileSync("git", ["-C", cwd, "status", "--porcelain", "-z", "--untracked-files=all"], {
|
|
63
|
+
encoding: "utf-8",
|
|
64
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
65
|
+
});
|
|
66
|
+
return { skipped: false, paths: parsePorcelain(output) };
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return { skipped: true, reason: err?.message || "not a git worktree" };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parsePorcelain(output) {
|
|
73
|
+
const entries = String(output || "").split("\0"), paths = [];
|
|
74
|
+
for (let i = 0; i < entries.length; i++) {
|
|
75
|
+
const entry = entries[i]; if (!entry) continue;
|
|
76
|
+
paths.push(entry.slice(3));
|
|
77
|
+
if (/[RC]/.test(entry.slice(0, 2)) && entries[i + 1]) paths.push(entries[++i]);
|
|
78
|
+
}
|
|
79
|
+
return uniqueSorted(paths);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function matchesScope(changedPath, scope) {
|
|
83
|
+
if (hasGlob(scope)) return globToRegExp(scope).test(changedPath);
|
|
84
|
+
const dir = scope.endsWith("/") ? scope.slice(0, -1) : scope;
|
|
85
|
+
return changedPath === dir || changedPath.startsWith(`${dir}/`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function hasGlob(scope) {
|
|
89
|
+
return /[*?]/.test(scope);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function globToRegExp(glob) {
|
|
93
|
+
let out = "^";
|
|
94
|
+
for (let i = 0; i < glob.length; i++) {
|
|
95
|
+
const c = glob[i];
|
|
96
|
+
if (c === "*") {
|
|
97
|
+
if (glob[i + 1] === "*") {
|
|
98
|
+
if (glob[i + 2] === "/") { out += "(?:.*/)?"; i += 2; }
|
|
99
|
+
else { out += ".*"; i++; }
|
|
100
|
+
} else {
|
|
101
|
+
out += "[^/]*";
|
|
102
|
+
}
|
|
103
|
+
} else if (c === "?") {
|
|
104
|
+
out += "[^/]";
|
|
105
|
+
} else {
|
|
106
|
+
out += escapeRegExp(c);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
out += "$";
|
|
110
|
+
return new RegExp(out);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function normalizePath(value) {
|
|
114
|
+
return String(value || "").trim().replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+/g, "/");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function uniqueSorted(values) {
|
|
118
|
+
return [...new Set(values)].sort();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function escapeRegExp(value) {
|
|
122
|
+
return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
123
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Session-file health — the pure policy behind never handing pi a session file
|
|
2
|
+
// it will refuse. `spawnPiAgent` passes `--session <file>` on every run, so one
|
|
3
|
+
// corrupt `<agentKey>.json` bricks a persona for the rest of the session: every
|
|
4
|
+
// dispatch dies in ~1s with an empty result, and drop + re-add does not help
|
|
5
|
+
// because the file survives the roster change.
|
|
6
|
+
//
|
|
7
|
+
// A pi session file is JSONL whose FIRST record is the header
|
|
8
|
+
// `{"type":"session","version":N,...}`. Both files that pi rejected in the
|
|
9
|
+
// field (`builder.json.corrupt-*`, `builder.json.invalid-gate-p`) start with a
|
|
10
|
+
// `{"type":"message",...}` record instead — they were truncated at the head, so
|
|
11
|
+
// the conversation begins mid-chain. That single check separates them from the
|
|
12
|
+
// session files that were healthy but retired for other reasons.
|
|
13
|
+
|
|
14
|
+
export const SESSION_HEADER_TYPE = "session";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Would pi accept this session file body? Returns `{ ok, reason }`; `reason` is
|
|
18
|
+
* null when ok, and a human-readable cause otherwise (it reaches the dispatcher
|
|
19
|
+
* verbatim, so it must explain what happened, not just that something did).
|
|
20
|
+
*/
|
|
21
|
+
export function isUsablePiSession(text) {
|
|
22
|
+
const body = String(text ?? "");
|
|
23
|
+
if (!body.trim()) return { ok: false, reason: "session file is empty" };
|
|
24
|
+
|
|
25
|
+
const firstLine = body.split(/\r?\n/).find((line) => line.trim());
|
|
26
|
+
let header;
|
|
27
|
+
try {
|
|
28
|
+
header = JSON.parse(firstLine);
|
|
29
|
+
} catch {
|
|
30
|
+
return { ok: false, reason: "first record is not valid JSON — the file is truncated or not a pi session" };
|
|
31
|
+
}
|
|
32
|
+
if (!header || typeof header !== "object" || Array.isArray(header)) {
|
|
33
|
+
return { ok: false, reason: "first record is not a JSON object" };
|
|
34
|
+
}
|
|
35
|
+
if (header.type !== SESSION_HEADER_TYPE) {
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
reason: `first record is "${header.type ?? "(no type)"}", not a "${SESSION_HEADER_TYPE}" header — ` +
|
|
39
|
+
"the file was truncated at the head and the conversation starts mid-chain",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return { ok: true, reason: null };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `builder.json` → `builder.json.corrupt-2026-07-25T09-14-02-123Z` (no colons: portable filename). */
|
|
46
|
+
export function quarantineName(file, now = new Date()) {
|
|
47
|
+
const stamp = new Date(now).toISOString().replace(/[:.]/g, "-");
|
|
48
|
+
return `${file}.corrupt-${stamp}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The observed post-hoc signature of a session file pi rejects: it exits
|
|
53
|
+
* non-zero having produced no output at all, and says so on stderr. Validation
|
|
54
|
+
* cannot catch every reason pi refuses a file, so this is the second net — and
|
|
55
|
+
* the run never started, which is what makes a retry safe.
|
|
56
|
+
*/
|
|
57
|
+
export function isCorruptSessionExit({ code, output, stderr } = {}) {
|
|
58
|
+
if (code === 0 || code == null) return false;
|
|
59
|
+
if (String(output ?? "").trim()) return false;
|
|
60
|
+
return /not a valid pi session|invalid pi session/i.test(String(stderr ?? ""));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Unconditionally quarantine a file that pi itself rejected. This is distinct
|
|
65
|
+
* from `quarantineIfUnusable`: the local header check may consider the file
|
|
66
|
+
* healthy even though pi applies a stricter invariant. A clean retry is allowed
|
|
67
|
+
* only after the rejected path has actually been moved aside.
|
|
68
|
+
*/
|
|
69
|
+
export function forceQuarantineSession(file, io) {
|
|
70
|
+
if (!io.existsSync(file)) return { ok: true, quarantined: null, error: null };
|
|
71
|
+
const target = quarantineName(file, io.now ? io.now() : new Date());
|
|
72
|
+
try {
|
|
73
|
+
io.renameSync(file, target);
|
|
74
|
+
return { ok: true, quarantined: target, error: null };
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
quarantined: null,
|
|
79
|
+
error: `could not quarantine pi-rejected session: ${err instanceof Error ? err.message : String(err)}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check `file` and move it aside when pi would reject it. `io` supplies the fs
|
|
86
|
+
* calls (`existsSync`, `readFileSync`, `renameSync`) and an optional `now`.
|
|
87
|
+
* Returns `{ usable, quarantined, reason }` — `quarantined` is the path the bad
|
|
88
|
+
* file was moved to, so the caller can name it for the human.
|
|
89
|
+
*/
|
|
90
|
+
export function quarantineIfUnusable(file, io) {
|
|
91
|
+
if (!io.existsSync(file)) return { usable: false, quarantined: null, reason: null };
|
|
92
|
+
|
|
93
|
+
let verdict;
|
|
94
|
+
try {
|
|
95
|
+
verdict = isUsablePiSession(io.readFileSync(file, "utf-8"));
|
|
96
|
+
} catch (err) {
|
|
97
|
+
verdict = { ok: false, reason: `session file unreadable: ${err instanceof Error ? err.message : String(err)}` };
|
|
98
|
+
}
|
|
99
|
+
if (verdict.ok) return { usable: true, quarantined: null, reason: null };
|
|
100
|
+
|
|
101
|
+
const target = quarantineName(file, io.now ? io.now() : new Date());
|
|
102
|
+
try {
|
|
103
|
+
io.renameSync(file, target);
|
|
104
|
+
return { usable: false, quarantined: target, reason: verdict.reason };
|
|
105
|
+
} catch {
|
|
106
|
+
// Could not move it aside — still refuse to resume it. Starting clean
|
|
107
|
+
// overwrites the bad file, which is the outcome we want anyway.
|
|
108
|
+
return { usable: false, quarantined: null, reason: verdict.reason };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export const SESSION_START_STEP_ORDER = [
|
|
4
|
+
"resetSession",
|
|
5
|
+
"restartMonitor",
|
|
6
|
+
"initializeComs",
|
|
7
|
+
"initializeExemptions",
|
|
8
|
+
"loadAgents",
|
|
9
|
+
"applyOverrides",
|
|
10
|
+
"restoreRoster",
|
|
11
|
+
"resolveCapabilities",
|
|
12
|
+
"notifyStartup",
|
|
13
|
+
"updateWidget",
|
|
14
|
+
"installFooter",
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export type SessionStartStep = (typeof SESSION_START_STEP_ORDER)[number];
|
|
18
|
+
|
|
19
|
+
export type SessionStartContext = ExtensionContext;
|
|
20
|
+
|
|
21
|
+
export type SessionStartDependencies = {
|
|
22
|
+
[K in SessionStartStep]: (ctx: SessionStartContext) => void | Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function assertSessionStartDependencies(deps: SessionStartDependencies): void {
|
|
26
|
+
for (const name of SESSION_START_STEP_ORDER) {
|
|
27
|
+
if (typeof deps[name] !== "function") {
|
|
28
|
+
throw new TypeError(`session_start dependency "${name}" must be a function`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function runSessionStart(ctx: SessionStartContext, deps: SessionStartDependencies): Promise<void> {
|
|
34
|
+
assertSessionStartDependencies(deps);
|
|
35
|
+
for (const name of SESSION_START_STEP_ORDER) await deps[name](ctx);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Register the lifecycle hook while keeping all mutable Hub state composition-owned. */
|
|
39
|
+
export function registerSessionStart(pi: ExtensionAPI, deps: SessionStartDependencies): void {
|
|
40
|
+
assertSessionStartDependencies(deps);
|
|
41
|
+
pi.on("session_start", async (_event, ctx) => runSessionStart(ctx, deps));
|
|
42
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { readActiveProfile, assertProfileModel, profileFallback, withProfileWork, PROFILE_ENV } from './policy/profile-runtime.ts';
|
|
2
|
+
/**
|
|
3
|
+
* spawnPiAgent — the ONE place agent-hub code spawns a headless `pi` child and
|
|
4
|
+
* parses its JSON event stream. Research helpers and read-only delegate children
|
|
5
|
+
* opt into the per-tool watchdog here, rather than trusting an agent-side timer.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn, type ChildProcess } from "child_process";
|
|
9
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
|
+
|
|
11
|
+
export interface PiUsage {
|
|
12
|
+
input?: number;
|
|
13
|
+
output?: number;
|
|
14
|
+
[k: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ToolTimeout {
|
|
18
|
+
toolCallId: string;
|
|
19
|
+
toolName: string;
|
|
20
|
+
args: string;
|
|
21
|
+
startedAt: number;
|
|
22
|
+
deadlineAt: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Termination {
|
|
26
|
+
reason: "tool_timeout" | "turn_timeout" | "drift_stop" | "cancelled";
|
|
27
|
+
confirmed: boolean;
|
|
28
|
+
escalated: boolean;
|
|
29
|
+
tool?: ToolTimeout;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** External run control handed to the caller via onControl (drift watchdog). */
|
|
33
|
+
export interface PiRunControl {
|
|
34
|
+
/** Terminate the child group with the given classification (default "drift_stop"). */
|
|
35
|
+
terminate(reason?: "drift_stop" | "cancelled"): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ToolWatchdogOptions {
|
|
39
|
+
/** Per read-only tool call deadline. null disables the watchdog. */
|
|
40
|
+
timeoutMs: number | null;
|
|
41
|
+
/** Grace after SIGTERM, followed by SIGKILL. Kept injectable for focused tests. */
|
|
42
|
+
termGraceMs?: number;
|
|
43
|
+
/** Bound on final settlement; never wait forever for close or inherited pipes. */
|
|
44
|
+
settleGraceMs?: number;
|
|
45
|
+
/** Only these tool names are watched (research/delegate read-only surface). */
|
|
46
|
+
tools?: readonly string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface SpawnPiAgentOptions {
|
|
50
|
+
model: string;
|
|
51
|
+
tools: string;
|
|
52
|
+
thinking: string;
|
|
53
|
+
/** Replacement prompt; mutually exclusive with appendSystemPrompt when spawning. */
|
|
54
|
+
systemPrompt?: string;
|
|
55
|
+
/** Prompt appended to Pi's inherited prompt (legacy/default child policy). */
|
|
56
|
+
appendSystemPrompt?: string;
|
|
57
|
+
/** Disable automatic global skill discovery for a minimized child. */
|
|
58
|
+
noSkills?: boolean;
|
|
59
|
+
/** Disable AGENTS.md/CLAUDE.md and other automatic context-file discovery. */
|
|
60
|
+
noContextFiles?: boolean;
|
|
61
|
+
sessionFile: string;
|
|
62
|
+
resume?: boolean;
|
|
63
|
+
prompt: string;
|
|
64
|
+
extensions?: string[];
|
|
65
|
+
env?: Record<string, string>;
|
|
66
|
+
/** Own a process group. Required for a watchdog/cancellation kill cascade. */
|
|
67
|
+
detached?: boolean;
|
|
68
|
+
cwd?: string;
|
|
69
|
+
/** Parent tool cancellation; classified separately from a tool timeout. */
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
toolWatchdog?: ToolWatchdogOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Whole-run deadline: one timer from spawn start; on expiry the child group is
|
|
74
|
+
* terminated with reason "turn_timeout" (same SIGTERM→SIGKILL→settle cascade as
|
|
75
|
+
* the per-tool watchdog). null/undefined disables it. Unlike the tool watchdog
|
|
76
|
+
* this bounds the ENTIRE run, thinking and non-watched tools included.
|
|
77
|
+
*/
|
|
78
|
+
turnDeadlineMs?: number | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ModelFallbackNotice {
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
reason: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface SpawnPiAgentCallbacks {
|
|
88
|
+
onProcess?(proc: ChildProcess): void;
|
|
89
|
+
onModelFallback?(notice: ModelFallbackNotice): void;
|
|
90
|
+
/** Receives a terminate handle for parent-side classified stops (drift watchdog). */
|
|
91
|
+
onControl?(control: PiRunControl): void;
|
|
92
|
+
onTextDelta?(delta: string): void;
|
|
93
|
+
onThinkingDelta?(delta: string): void;
|
|
94
|
+
onToolStart?(toolName: string, argStr: string, toolCallId?: string): void;
|
|
95
|
+
/** Result text is the complete textual tool payload; duration is measured in the parent process. */
|
|
96
|
+
onToolEnd?(toolName: string, toolCallId?: string, isError?: boolean, resultText?: string, durationMs?: number): void;
|
|
97
|
+
onUsage?(usage: PiUsage, source: "message_end" | "agent_end"): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface SpawnPiAgentResult {
|
|
101
|
+
output: string;
|
|
102
|
+
exitCode: number | null;
|
|
103
|
+
stderr: string;
|
|
104
|
+
spawnError?: string;
|
|
105
|
+
/** Assistant-level provider/model failure reported in Pi's JSON stream. */
|
|
106
|
+
assistantError?: string;
|
|
107
|
+
toolCallsStarted: number;
|
|
108
|
+
modelUsed: string;
|
|
109
|
+
modelFallback?: ModelFallbackNotice;
|
|
110
|
+
/** Present only when parent-side bounded termination was requested. */
|
|
111
|
+
termination?: Termination;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const DEFAULT_TERM_GRACE_MS = 1_000;
|
|
115
|
+
const DEFAULT_SETTLE_GRACE_MS = 1_000;
|
|
116
|
+
const WATCHED_TOOLS = new Set(["read", "grep", "find", "ls"]);
|
|
117
|
+
|
|
118
|
+
/** Signal an explicitly owned process group, falling back only for legacy callers. */
|
|
119
|
+
export function killPiTree(proc: ChildProcess, signal: NodeJS.Signals = "SIGTERM"): void {
|
|
120
|
+
const pid = proc.pid;
|
|
121
|
+
if (pid == null) return;
|
|
122
|
+
try {
|
|
123
|
+
process.kill(-pid, signal);
|
|
124
|
+
} catch {
|
|
125
|
+
try { proc.kill(signal); } catch {}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function spawnPiAgent(opts: SpawnPiAgentOptions, cbs: SpawnPiAgentCallbacks = {}): Promise<SpawnPiAgentResult> {
|
|
130
|
+
return withProfileWork(async () => {
|
|
131
|
+
try {
|
|
132
|
+
const active=readActiveProfile()??readActiveProfile(opts.env);
|
|
133
|
+
assertProfileModel(opts.model,active);
|
|
134
|
+
if(active) opts={...opts,env:{...opts.env,[PROFILE_ENV]:JSON.stringify(active)}};
|
|
135
|
+
return await spawnPiAgentUnchecked(opts,cbs);
|
|
136
|
+
} catch(error) {
|
|
137
|
+
return {output:'',stderr:String(error),exitCode:1,spawnError:String(error),modelUsed:opts.model,toolCallsStarted:0};
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function spawnPiAgentUnchecked(
|
|
143
|
+
opts: SpawnPiAgentOptions,
|
|
144
|
+
cbs: SpawnPiAgentCallbacks = {},
|
|
145
|
+
): Promise<SpawnPiAgentResult> {
|
|
146
|
+
const promptArg = opts.systemPrompt !== undefined
|
|
147
|
+
? ["--system-prompt", opts.systemPrompt]
|
|
148
|
+
: ["--append-system-prompt", opts.appendSystemPrompt ?? ""];
|
|
149
|
+
const args = [
|
|
150
|
+
"--mode", "json", "-p", "--no-extensions",
|
|
151
|
+
...(opts.noSkills ? ["--no-skills"] : []),
|
|
152
|
+
...(opts.noContextFiles ? ["--no-context-files"] : []),
|
|
153
|
+
...(opts.extensions || []).flatMap(e => ["-e", e]),
|
|
154
|
+
"--model", opts.model, "--tools", opts.tools, "--thinking", opts.thinking,
|
|
155
|
+
...promptArg, "--session", opts.sessionFile,
|
|
156
|
+
];
|
|
157
|
+
if (opts.resume) args.push("-c");
|
|
158
|
+
|
|
159
|
+
const watchdog = opts.toolWatchdog;
|
|
160
|
+
const turnDeadlineMs = opts.turnDeadlineMs ?? null;
|
|
161
|
+
// A watchdog or deadline must own its group: group signalling remains valid even
|
|
162
|
+
// after the pi leader exits while an inherited-stdio descendant is still alive.
|
|
163
|
+
const ownsGroup = opts.detached === true || watchdog !== undefined || opts.signal !== undefined || turnDeadlineMs != null || cbs.onControl !== undefined;
|
|
164
|
+
const watchedTools = new Set(watchdog?.tools ?? WATCHED_TOOLS);
|
|
165
|
+
const timeoutMs = watchdog?.timeoutMs ?? null;
|
|
166
|
+
const termGraceMs = watchdog?.termGraceMs ?? DEFAULT_TERM_GRACE_MS;
|
|
167
|
+
const settleGraceMs = watchdog?.settleGraceMs ?? DEFAULT_SETTLE_GRACE_MS;
|
|
168
|
+
|
|
169
|
+
const textChunks: string[] = [];
|
|
170
|
+
const stderrChunks: string[] = [];
|
|
171
|
+
return new Promise((resolve) => {
|
|
172
|
+
const proc = spawn("pi", args, {
|
|
173
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
174
|
+
env: { ...process.env, ...(opts.env || {}) },
|
|
175
|
+
...(opts.cwd ? { cwd: opts.cwd } : {}),
|
|
176
|
+
...(ownsGroup ? { detached: true } : {}),
|
|
177
|
+
});
|
|
178
|
+
cbs.onProcess?.(proc);
|
|
179
|
+
proc.stdin?.on("error", () => {});
|
|
180
|
+
proc.stdin?.end(opts.prompt);
|
|
181
|
+
|
|
182
|
+
let buffer = "";
|
|
183
|
+
let settled = false;
|
|
184
|
+
let closeSeen = false;
|
|
185
|
+
let termination: Termination | undefined;
|
|
186
|
+
let termTimer: ReturnType<typeof setTimeout> | undefined;
|
|
187
|
+
let settleTimer: ReturnType<typeof setTimeout> | undefined;
|
|
188
|
+
let deadlineTimer: ReturnType<typeof setTimeout> | undefined;
|
|
189
|
+
const calls = new Map<string, ToolTimeout & { timer: ReturnType<typeof setTimeout> }>();
|
|
190
|
+
|
|
191
|
+
const clearCalls = () => {
|
|
192
|
+
for (const call of calls.values()) clearTimeout(call.timer);
|
|
193
|
+
calls.clear();
|
|
194
|
+
};
|
|
195
|
+
const cleanup = () => {
|
|
196
|
+
clearCalls();
|
|
197
|
+
if (termTimer) clearTimeout(termTimer);
|
|
198
|
+
if (settleTimer) clearTimeout(settleTimer);
|
|
199
|
+
if (deadlineTimer) clearTimeout(deadlineTimer);
|
|
200
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
201
|
+
};
|
|
202
|
+
let assistantError: string | undefined;
|
|
203
|
+
let toolCallsStarted = 0;
|
|
204
|
+
const settle = (code: number | null, spawnError?: string) => {
|
|
205
|
+
if (settled) return;
|
|
206
|
+
settled = true;
|
|
207
|
+
cleanup();
|
|
208
|
+
if (termination) termination.confirmed = closeSeen;
|
|
209
|
+
// A pipe held by a descendant must not hold the caller forever.
|
|
210
|
+
try { proc.stdin?.destroy(); } catch {}
|
|
211
|
+
try { proc.stdout?.destroy(); } catch {}
|
|
212
|
+
try { proc.stderr?.destroy(); } catch {}
|
|
213
|
+
resolve({
|
|
214
|
+
output: textChunks.join(""),
|
|
215
|
+
// Pi's headless process can exit 0 while the assistant message itself
|
|
216
|
+
// reports stopReason:error. Normalize that to a failed run so callers
|
|
217
|
+
// never mark a provider/model error as successful.
|
|
218
|
+
exitCode: assistantError && code === 0 ? 1 : code,
|
|
219
|
+
stderr: stderrChunks.join(""),
|
|
220
|
+
toolCallsStarted,
|
|
221
|
+
modelUsed: opts.model,
|
|
222
|
+
...(spawnError ? { spawnError } : {}),
|
|
223
|
+
...(assistantError ? { assistantError } : {}),
|
|
224
|
+
...(termination ? { termination } : {}),
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
const terminate = (reason: Termination["reason"], tool?: ToolTimeout) => {
|
|
228
|
+
// The first classification wins; later cancellation/exit events keep it.
|
|
229
|
+
if (termination) return;
|
|
230
|
+
termination = { reason, confirmed: false, escalated: false, ...(tool ? { tool } : {}) };
|
|
231
|
+
clearCalls();
|
|
232
|
+
killPiTree(proc, "SIGTERM");
|
|
233
|
+
termTimer = setTimeout(() => {
|
|
234
|
+
if (settled) return;
|
|
235
|
+
termination!.escalated = true;
|
|
236
|
+
killPiTree(proc, "SIGKILL");
|
|
237
|
+
}, termGraceMs);
|
|
238
|
+
settleTimer = setTimeout(() => settle(null), termGraceMs + settleGraceMs);
|
|
239
|
+
};
|
|
240
|
+
const onAbort = () => terminate("cancelled");
|
|
241
|
+
if (opts.signal?.aborted) onAbort();
|
|
242
|
+
else opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
243
|
+
// External classified stop (drift watchdog): same first-classification-wins
|
|
244
|
+
// cascade as every other termination path; harmless after settle.
|
|
245
|
+
cbs.onControl?.({ terminate: (reason = "drift_stop") => { if (!settled) terminate(reason); } });
|
|
246
|
+
if (turnDeadlineMs != null) {
|
|
247
|
+
deadlineTimer = setTimeout(() => terminate("turn_timeout"), turnDeadlineMs);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const toolStarts = new Map<string, number>();
|
|
251
|
+
const toolId = (event: any) => String(event.toolCallId ?? event.tool_call_id ?? event.id ?? "");
|
|
252
|
+
const toolResultText = (result: any): string => {
|
|
253
|
+
const content = result?.content ?? result;
|
|
254
|
+
if (typeof content === "string") return content;
|
|
255
|
+
if (!Array.isArray(content)) {
|
|
256
|
+
try { return content == null ? "" : JSON.stringify(content); } catch { return String(content ?? ""); }
|
|
257
|
+
}
|
|
258
|
+
return content.map((item: any) => {
|
|
259
|
+
if (typeof item === "string") return item;
|
|
260
|
+
if (item?.type === "text" && typeof item.text === "string") return item.text;
|
|
261
|
+
try { return JSON.stringify(item); } catch { return String(item ?? ""); }
|
|
262
|
+
}).filter(Boolean).join("\n");
|
|
263
|
+
};
|
|
264
|
+
const handleEvent = (event: any) => {
|
|
265
|
+
if (event.type === "message_update") {
|
|
266
|
+
const delta = event.assistantMessageEvent;
|
|
267
|
+
if (delta?.type === "text_delta") { textChunks.push(delta.delta || ""); cbs.onTextDelta?.(delta.delta || ""); }
|
|
268
|
+
else if (delta?.type === "thinking_delta") cbs.onThinkingDelta?.(delta.delta || "");
|
|
269
|
+
} else if (event.type === "tool_execution_start") {
|
|
270
|
+
toolCallsStarted++;
|
|
271
|
+
let argStr = "";
|
|
272
|
+
try { argStr = event.args != null ? JSON.stringify(event.args) : ""; } catch {}
|
|
273
|
+
const id = toolId(event);
|
|
274
|
+
const name = event.toolName || "tool";
|
|
275
|
+
if (id && !toolStarts.has(id)) toolStarts.set(id, Date.now());
|
|
276
|
+
cbs.onToolStart?.(name, argStr, id || undefined);
|
|
277
|
+
if (timeoutMs != null && id && watchedTools.has(name) && !calls.has(id)) {
|
|
278
|
+
const startedAt = Date.now();
|
|
279
|
+
const call: ToolTimeout = { toolCallId: id, toolName: name, args: argStr, startedAt, deadlineAt: startedAt + timeoutMs };
|
|
280
|
+
calls.set(id, { ...call, timer: setTimeout(() => terminate("tool_timeout", call), timeoutMs) });
|
|
281
|
+
}
|
|
282
|
+
} else if (event.type === "tool_execution_end") {
|
|
283
|
+
const id = toolId(event);
|
|
284
|
+
if (id) {
|
|
285
|
+
const call = calls.get(id);
|
|
286
|
+
if (call) { clearTimeout(call.timer); calls.delete(id); }
|
|
287
|
+
}
|
|
288
|
+
const rawIsError = event.isError ?? event.is_error ?? event.result?.isError ?? event.result?.is_error;
|
|
289
|
+
const startedAt = id ? toolStarts.get(id) : undefined;
|
|
290
|
+
if (id) toolStarts.delete(id);
|
|
291
|
+
cbs.onToolEnd?.(
|
|
292
|
+
event.toolName || "tool",
|
|
293
|
+
id || undefined,
|
|
294
|
+
typeof rawIsError === "boolean" ? rawIsError : undefined,
|
|
295
|
+
toolResultText(event.result),
|
|
296
|
+
startedAt == null ? undefined : Math.max(0, Date.now() - startedAt),
|
|
297
|
+
);
|
|
298
|
+
} else if (event.type === "message_end") {
|
|
299
|
+
if (event.message?.role === "assistant"
|
|
300
|
+
&& (event.message.stopReason === "error" || event.message.stopReason === "aborted")) {
|
|
301
|
+
assistantError = String(event.message.errorMessage
|
|
302
|
+
|| (event.message.stopReason === "aborted" ? "assistant model request aborted" : "assistant model run failed"));
|
|
303
|
+
}
|
|
304
|
+
if (event.message?.usage) cbs.onUsage?.(event.message.usage, "message_end");
|
|
305
|
+
} else if (event.type === "agent_end") {
|
|
306
|
+
const last = [...(event.messages || [])].reverse().find((m: any) => m.role === "assistant");
|
|
307
|
+
if (last?.usage) cbs.onUsage?.(last.usage, "agent_end");
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
proc.stdout!.setEncoding("utf-8");
|
|
312
|
+
proc.stdout!.on("data", (chunk: string) => {
|
|
313
|
+
buffer += chunk;
|
|
314
|
+
const lines = buffer.split("\n");
|
|
315
|
+
buffer = lines.pop() || "";
|
|
316
|
+
for (const line of lines) { if (line.trim()) try { handleEvent(JSON.parse(line)); } catch {} }
|
|
317
|
+
});
|
|
318
|
+
proc.stderr!.setEncoding("utf-8");
|
|
319
|
+
proc.stderr!.on("data", (chunk: string) => stderrChunks.push(chunk));
|
|
320
|
+
proc.on("close", (code) => {
|
|
321
|
+
closeSeen = true;
|
|
322
|
+
if (buffer.trim()) try { handleEvent(JSON.parse(buffer)); } catch {}
|
|
323
|
+
settle(code);
|
|
324
|
+
});
|
|
325
|
+
proc.on("error", (err) => settle(1, err.message));
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const PROVIDER_FAILURE_RE = /\b(provider unavailable|service unavailable|overloaded|rate limit|too many requests|out of memory|oom|memory limit|resource exhausted|econn(?:reset|refused)|connection (?:reset|refused)|fetch failed|network error|gateway timeout|http\s*5\d\d|\b429\b)\b/i;
|
|
330
|
+
|
|
331
|
+
function modelFallbackReason(result: SpawnPiAgentResult, midRun = false): string | null {
|
|
332
|
+
// A terminated run (watchdog, deadline, cancellation) is a verdict on the
|
|
333
|
+
// work, not a provider outage — never retry it. A spawn failure never
|
|
334
|
+
// reached a provider at all.
|
|
335
|
+
if (result.spawnError || result.termination) return null;
|
|
336
|
+
const workStarted = result.toolCallsStarted > 0 || Boolean(result.output.trim());
|
|
337
|
+
if (!midRun && workStarted) return null;
|
|
338
|
+
const reason = result.assistantError
|
|
339
|
+
? result.assistantError.slice(-500)
|
|
340
|
+
: result.exitCode !== 0
|
|
341
|
+
? (result.stderr.trim().slice(-500) || `pi exited with code ${result.exitCode ?? "unknown"}`)
|
|
342
|
+
: null;
|
|
343
|
+
if (!reason) return null;
|
|
344
|
+
// Once work began, only a recognizable provider/transport failure is safe to
|
|
345
|
+
// route to another model. Deterministic session/configuration/harness errors
|
|
346
|
+
// must remain visible instead of being masked by an expensive second run.
|
|
347
|
+
if (midRun && workStarted && !PROVIDER_FAILURE_RE.test(reason)) return null;
|
|
348
|
+
return reason;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface ModelFallbackOptions {
|
|
352
|
+
/**
|
|
353
|
+
* Retry even when the failed attempt had already started tools or emitted
|
|
354
|
+
* text. Only pass this for a run that holds NO write-capable tools: the
|
|
355
|
+
* retry re-executes whatever the first attempt did, which is harmless for a
|
|
356
|
+
* reader and duplicates edits for a writer. Use `isReadOnlyToolList` on the
|
|
357
|
+
* effective tool list rather than assuming.
|
|
358
|
+
*/
|
|
359
|
+
midRun?: boolean;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Run an overridden model and retry once on the original persona model when the
|
|
364
|
+
* first attempt failed for a provider-level reason. By default that means
|
|
365
|
+
* "failed before producing text or starting a tool"; `midRun` extends it to
|
|
366
|
+
* read-only runs, where a provider dying halfway through would otherwise throw
|
|
367
|
+
* the whole run away — and those are exactly the children that exist to protect
|
|
368
|
+
* their parent's context. The session file is restored before the retry so the
|
|
369
|
+
* failed turn never enters the resumable conversation.
|
|
370
|
+
*/
|
|
371
|
+
export async function spawnPiAgentWithModelFallback(
|
|
372
|
+
opts: SpawnPiAgentOptions,
|
|
373
|
+
fallbackModel?: string,
|
|
374
|
+
cbs: SpawnPiAgentCallbacks = {},
|
|
375
|
+
fallbackOptions: ModelFallbackOptions = {},
|
|
376
|
+
): Promise<SpawnPiAgentResult> {
|
|
377
|
+
try { fallbackModel=profileFallback(fallbackModel,readActiveProfile()??readActiveProfile(opts.env)); }
|
|
378
|
+
catch(error) { return {output:'',stderr:String(error),exitCode:1,spawnError:String(error),modelUsed:opts.model,toolCallsStarted:0}; }
|
|
379
|
+
if (!fallbackModel || fallbackModel === opts.model) return spawnPiAgent(opts, cbs);
|
|
380
|
+
|
|
381
|
+
const sessionExisted = existsSync(opts.sessionFile);
|
|
382
|
+
let sessionSnapshot: Buffer | undefined;
|
|
383
|
+
if (sessionExisted) {
|
|
384
|
+
try { sessionSnapshot = readFileSync(opts.sessionFile); } catch {}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const primary = await spawnPiAgent(opts, cbs);
|
|
388
|
+
const reason = modelFallbackReason(primary, fallbackOptions.midRun === true);
|
|
389
|
+
// If an existing resumable session could not be snapshotted, fail closed:
|
|
390
|
+
// retrying would preserve the failed turn and could duplicate the prompt.
|
|
391
|
+
if (!reason || (sessionExisted && !sessionSnapshot)) return primary;
|
|
392
|
+
|
|
393
|
+
try {
|
|
394
|
+
if (sessionExisted && sessionSnapshot) writeFileSync(opts.sessionFile, sessionSnapshot);
|
|
395
|
+
else unlinkSync(opts.sessionFile);
|
|
396
|
+
} catch (error: any) {
|
|
397
|
+
if (error?.code !== "ENOENT") return primary;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const notice: ModelFallbackNotice = { from: opts.model, to: fallbackModel, reason };
|
|
401
|
+
cbs.onModelFallback?.(notice);
|
|
402
|
+
const fallback = await spawnPiAgent({ ...opts, model: fallbackModel }, cbs);
|
|
403
|
+
return { ...fallback, modelFallback: notice };
|
|
404
|
+
}
|