@chankov/agent-fleet 2.0.0 → 2.0.1
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/package.json +1 -1
- package/.pi/harnesses/coms/package.json +1 -1
- package/.pi/harnesses/damage-control-continue/package.json +1 -1
- package/.versions/2.0.1/.pi/agents/dispatch-policy.yaml +32 -0
- package/.versions/2.0.1/.pi/agents/model-profiles.yaml +27 -0
- package/.versions/2.0.1/.pi/agents/peers.yaml +142 -0
- package/.versions/2.0.1/.pi/agents/teams.yaml +41 -0
- package/.versions/2.0.1/.pi/damage-control-rules.yaml +297 -0
- package/.versions/2.0.1/.pi/extensions/agent-fleet-update-check/README.md +57 -0
- package/.versions/2.0.1/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
- package/.versions/2.0.1/.pi/extensions/agent-fleet-update-check/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/btw/README.md +120 -0
- package/.versions/2.0.1/.pi/extensions/btw/index.ts +914 -0
- package/.versions/2.0.1/.pi/extensions/btw/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/btw/state.js +179 -0
- package/.versions/2.0.1/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
- package/.versions/2.0.1/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
- package/.versions/2.0.1/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/compact-and-continue/README.md +42 -0
- package/.versions/2.0.1/.pi/extensions/compact-and-continue/index.ts +120 -0
- package/.versions/2.0.1/.pi/extensions/compact-and-continue/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/mcp-bridge/README.md +46 -0
- package/.versions/2.0.1/.pi/extensions/mcp-bridge/index.ts +206 -0
- package/.versions/2.0.1/.pi/extensions/mcp-bridge/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/package-lock.json +1175 -0
- package/.versions/2.0.1/.pi/extensions/package.json +9 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/README.md +205 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/config.ts +198 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/index.ts +248 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/package.json +6 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/providers.ts +214 -0
- package/.versions/2.0.1/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/README.md +1161 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/access-approval.ts +135 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/artifacts.js +146 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/backend-policy.js +174 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/budget-continuation.ts +73 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/context.ts +39 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/models.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/work-mode.ts +29 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/config/agents.ts +171 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/config/overrides.ts +118 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +211 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context/budgets.ts +208 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/context-window.js +106 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/delegate.ts +446 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-coms.ts +232 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-native-complete.ts +135 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +153 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +191 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-native-types.ts +207 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-native.ts +184 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/dispatch-observability.ts +220 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/docs-lane.js +122 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/drift-watchdog.js +218 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/external-blocker.js +85 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/fixtures/registration-surface.json +53 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/footer.ts +30 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/helpers.ts +266 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/hub-state-audit.js +59 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/index.ts +1850 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/input/completions.ts +76 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/input/shortcuts.ts +47 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +123 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +139 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +95 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/package.json +7 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/policy/models.ts +126 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/policy/roster.ts +79 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/policy/work-mode.ts +118 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/presentation.ts +48 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/prompts/context.ts +46 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/prompts/fragments.ts +115 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/prompts/session-start.ts +88 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/prompts/system-prompt.ts +110 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/research/controls.ts +75 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/research/runtime.ts +184 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/research/spawn-run.ts +146 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/research-retention.js +34 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/return-contract.js +293 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/return-extract.js +75 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/review-findings.js +102 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/run-budget.js +537 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/run-namespace.js +87 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/scope-gate.js +103 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/session-health.js +110 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/session-start.ts +42 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/spawn.ts +388 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/timeline.ts +54 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/action-executors.ts +146 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/context.ts +132 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +79 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +200 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/fleet-tools.ts +202 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/herdr-executors.ts +82 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/set-task-tier.ts +29 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/spawn-research.ts +62 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/tools/verification-contract.ts +77 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/types.ts +60 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/context-budget.ts +86 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/detail-panel.ts +175 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +130 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/grid.ts +306 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/history.ts +234 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/ui/zoom.ts +204 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/version.ts +42 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/work-mode-controls.ts +56 -0
- package/.versions/2.0.1/.pi/harnesses/agent-hub/work-mode.ts +167 -0
- package/.versions/2.0.1/.pi/harnesses/ask-user-remote/README.md +53 -0
- package/.versions/2.0.1/.pi/harnesses/ask-user-remote/index.ts +532 -0
- package/.versions/2.0.1/.pi/harnesses/ask-user-remote/race-core.js +106 -0
- package/.versions/2.0.1/.pi/harnesses/coms/README.md +100 -0
- package/.versions/2.0.1/.pi/harnesses/coms/index.ts +276 -0
- package/.versions/2.0.1/.pi/harnesses/coms/package.json +7 -0
- package/.versions/2.0.1/.pi/harnesses/coms/version.ts +42 -0
- package/.versions/2.0.1/.pi/harnesses/damage-control-continue/README.md +124 -0
- package/.versions/2.0.1/.pi/harnesses/damage-control-continue/index.ts +536 -0
- package/.versions/2.0.1/.pi/harnesses/damage-control-continue/package.json +7 -0
- package/.versions/2.0.1/.pi/harnesses/damage-control-continue/version.ts +42 -0
- package/.versions/2.0.1/.pi/harnesses/lib/coms-core-io.ts +385 -0
- package/.versions/2.0.1/.pi/harnesses/lib/coms-core.ts +577 -0
- package/.versions/2.0.1/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
- package/.versions/2.0.1/.pi/harnesses/lib/context-budget-child-prompt.ts +179 -0
- package/.versions/2.0.1/.pi/harnesses/lib/context-budget-hub-prompt.ts +114 -0
- package/.versions/2.0.1/.pi/harnesses/lib/context-budget-view.ts +107 -0
- package/.versions/2.0.1/.pi/harnesses/lib/context-budget.ts +114 -0
- package/.versions/2.0.1/.pi/harnesses/lib/damage-control-shared.ts +197 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-dashboard-ops.ts +155 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-dashboard-view.ts +142 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-detail-view.ts +247 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-overlay.ts +26 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-panel.ts +34 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-read-model.ts +131 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-selection.ts +24 -0
- package/.versions/2.0.1/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
- package/.versions/2.0.1/.pi/harnesses/lib/herdr-client.ts +472 -0
- package/.versions/2.0.1/.pi/harnesses/lib/herdr-presence.ts +399 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
- package/.versions/2.0.1/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
- package/.versions/2.0.1/.pi/harnesses/lib/spawned-peers.js +190 -0
- package/.versions/2.0.1/.pi/harnesses/package-lock.json +2039 -0
- package/.versions/2.0.1/.pi/harnesses/package.json +10 -0
- package/.versions/2.0.1/.pi/prompts/af-build.md +24 -0
- package/.versions/2.0.1/.pi/prompts/af-code-simplify.md +22 -0
- package/.versions/2.0.1/.pi/prompts/af-plan.md +17 -0
- package/.versions/2.0.1/.pi/prompts/af-review.md +16 -0
- package/.versions/2.0.1/.pi/prompts/af-set-hermes-telegram.md +15 -0
- package/.versions/2.0.1/.pi/prompts/af-set-hermes-watchdog.md +6 -0
- package/.versions/2.0.1/.pi/prompts/af-ship.md +17 -0
- package/.versions/2.0.1/.pi/prompts/af-spec.md +15 -0
- package/.versions/2.0.1/.pi/prompts/af-test.md +19 -0
- package/.versions/2.0.1/.pi/skills/bowser/SKILL.md +145 -0
- package/.versions/2.0.1/.version +1 -0
- package/.versions/2.0.1/agents/architect.md +25 -0
- package/.versions/2.0.1/agents/bowser.md +28 -0
- package/.versions/2.0.1/agents/builder.md +56 -0
- package/.versions/2.0.1/agents/code-reviewer.md +210 -0
- package/.versions/2.0.1/agents/deep-researcher.md +33 -0
- package/.versions/2.0.1/agents/documenter.md +22 -0
- package/.versions/2.0.1/agents/orchestrator.md +23 -0
- package/.versions/2.0.1/agents/plan-reviewer.md +84 -0
- package/.versions/2.0.1/agents/planner.md +73 -0
- package/.versions/2.0.1/agents/releaser.md +25 -0
- package/.versions/2.0.1/agents/researcher.md +31 -0
- package/.versions/2.0.1/agents/security-auditor.md +168 -0
- package/.versions/2.0.1/agents/test-engineer.md +154 -0
- package/.versions/2.0.1/agents/web-debugger.md +44 -0
- package/.versions/2.0.1/agents/web-performance-auditor.md +194 -0
- package/.versions/2.0.1/bin/catalog/harness-runtime-closure.json +38 -0
- package/.versions/2.0.1/codex/CONDUCTOR.md +148 -0
- package/.versions/2.0.1/docs/ARCHITECTURE.md +407 -0
- package/.versions/2.0.1/docs/agent-fleet-setup.md +468 -0
- package/.versions/2.0.1/docs/claude-code-coms-bridge.md +128 -0
- package/.versions/2.0.1/docs/codex-remote-conductor.md +170 -0
- package/.versions/2.0.1/docs/coms-hermes-bridge.md +189 -0
- package/.versions/2.0.1/docs/getting-started.md +119 -0
- package/.versions/2.0.1/docs/npm-install.md +292 -0
- package/.versions/2.0.1/docs/pi-extensions.md +439 -0
- package/.versions/2.0.1/docs/pi-setup.md +74 -0
- package/.versions/2.0.1/docs/skill-anatomy.md +150 -0
- package/.versions/2.0.1/hermes/README.md +347 -0
- package/.versions/2.0.1/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
- package/.versions/2.0.1/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
- package/.versions/2.0.1/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
- package/.versions/2.0.1/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
- package/.versions/2.0.1/hermes/gates/gate-o-capability.md +8 -0
- package/.versions/2.0.1/hermes/gates/gate-o-validator-fixtures.json +1 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
- package/.versions/2.0.1/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
- package/.versions/2.0.1/hermes/skills/hub-conductor/SKILL.md +84 -0
- package/.versions/2.0.1/hermes/skills/hub-liaison/SKILL.md +84 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/SKILL.md +76 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/manifest.json +1 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
- package/.versions/2.0.1/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
- package/.versions/2.0.1/hermes/watchdog-tests/__init__.py +0 -0
- package/.versions/2.0.1/hooks/coms-stop-hook.mjs +84 -0
- package/.versions/2.0.1/install-manifest.json +2830 -0
- package/.versions/2.0.1/justfile +286 -0
- package/.versions/2.0.1/manifest-meta.json +913 -0
- package/.versions/2.0.1/references/accessibility-checklist.md +160 -0
- package/.versions/2.0.1/references/definition-of-done.md +67 -0
- package/.versions/2.0.1/references/fleet-coordination-patterns.md +151 -0
- package/.versions/2.0.1/references/observability-checklist.md +91 -0
- package/.versions/2.0.1/references/orchestration-patterns.md +370 -0
- package/.versions/2.0.1/references/performance-checklist.md +153 -0
- package/.versions/2.0.1/references/prompting-patterns.md +380 -0
- package/.versions/2.0.1/references/security-checklist.md +179 -0
- package/.versions/2.0.1/references/testing-patterns.md +236 -0
- package/.versions/2.0.1/references/workflow-authoring.md +304 -0
- package/.versions/2.0.1/scripts/codex-conductor.ts +41 -0
- package/.versions/2.0.1/scripts/codex-remote-control.ts +167 -0
- package/.versions/2.0.1/scripts/coms-claude-bridge.ts +411 -0
- package/.versions/2.0.1/scripts/coms-cli.ts +484 -0
- package/.versions/2.0.1/scripts/coms-hermes-bridge.ts +413 -0
- package/.versions/2.0.1/scripts/fleet.ts +198 -0
- package/.versions/2.0.1/scripts/flow.ts +121 -0
- package/.versions/2.0.1/scripts/hermes-monitor-capability-runner.ts +25 -0
- package/.versions/2.0.1/scripts/hermes-monitor-scenario.ts +474 -0
- package/.versions/2.0.1/scripts/hermes-watchdog-capability-probe.ts +45 -0
- package/.versions/2.0.1/scripts/install-hermes-plugin.sh +180 -0
- package/.versions/2.0.1/scripts/lib/claude-bridge-core.ts +210 -0
- package/.versions/2.0.1/scripts/lib/codex-conductor.ts +88 -0
- package/.versions/2.0.1/scripts/lib/codex-remote-control.ts +480 -0
- package/.versions/2.0.1/scripts/lib/coms-envelope.ts +582 -0
- package/.versions/2.0.1/scripts/lib/fake-herdr-server.ts +88 -0
- package/.versions/2.0.1/scripts/lib/fleet-command.ts +270 -0
- package/.versions/2.0.1/scripts/lib/flow-command.ts +77 -0
- package/.versions/2.0.1/scripts/lib/flow-maintenance.ts +230 -0
- package/.versions/2.0.1/scripts/lib/herdr-layout.ts +281 -0
- package/.versions/2.0.1/scripts/lib/hermes-bridge-core.ts +241 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-events.ts +1 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-herdr.ts +2 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-model.ts +3 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-registry.ts +2 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-socket.ts +2 -0
- package/.versions/2.0.1/scripts/lib/hermes-monitor-store.ts +2 -0
- package/.versions/2.0.1/scripts/lib/monitor-env.ts +146 -0
- package/.versions/2.0.1/scripts/lib/peer-launch.ts +318 -0
- package/.versions/2.0.1/scripts/lib/persona-banner.ts +62 -0
- package/.versions/2.0.1/scripts/lib/spawn-stagger.ts +101 -0
- package/.versions/2.0.1/scripts/lib/team-project.ts +213 -0
- package/.versions/2.0.1/scripts/lib/team-snapshot.ts +147 -0
- package/.versions/2.0.1/scripts/peer-banner.ts +40 -0
- package/.versions/2.0.1/scripts/peer-launch.ts +259 -0
- package/.versions/2.0.1/scripts/team-snapshot.ts +237 -0
- package/.versions/2.0.1/scripts/team-up.ts +406 -0
- package/.versions/2.0.1/scripts/workflows/lib/agent-phase.ts +118 -0
- package/.versions/2.0.1/scripts/workflows/lib/changes.ts +61 -0
- package/.versions/2.0.1/scripts/workflows/lib/env.ts +34 -0
- package/.versions/2.0.1/scripts/workflows/lib/envelopes.ts +141 -0
- package/.versions/2.0.1/scripts/workflows/lib/gates.ts +81 -0
- package/.versions/2.0.1/scripts/workflows/lib/git.ts +96 -0
- package/.versions/2.0.1/scripts/workflows/lib/permissions.ts +130 -0
- package/.versions/2.0.1/scripts/workflows/lib/personas.ts +44 -0
- package/.versions/2.0.1/scripts/workflows/lib/quality.ts +64 -0
- package/.versions/2.0.1/scripts/workflows/lib/run.ts +106 -0
- package/.versions/2.0.1/scripts/workflows/lib/trace.ts +34 -0
- package/.versions/2.0.1/scripts/workflows/tsconfig.json +22 -0
- package/.versions/2.0.1/scripts/workflows/wf-build-test.ts +61 -0
- package/.versions/2.0.1/scripts/workflows/wf-document.ts +50 -0
- package/.versions/2.0.1/scripts/workflows/wf-quality.ts +20 -0
- package/.versions/2.0.1/scripts/workflows/wf-scout.ts +38 -0
- package/.versions/2.0.1/skills/_internal/grilling.md +59 -0
- package/.versions/2.0.1/skills/browser-testing-with-devtools/SKILL.md +351 -0
- package/.versions/2.0.1/skills/code-review-and-quality/SKILL.md +381 -0
- package/.versions/2.0.1/skills/compound-learning/SKILL.md +137 -0
- package/.versions/2.0.1/skills/context-engineering/SKILL.md +291 -0
- package/.versions/2.0.1/skills/deprecation-and-migration/SKILL.md +206 -0
- package/.versions/2.0.1/skills/designing-agents/SKILL.md +394 -0
- package/.versions/2.0.1/skills/designing-agents/pi-harness-authoring.md +222 -0
- package/.versions/2.0.1/skills/drafting-workflows/SKILL.md +143 -0
- package/.versions/2.0.1/skills/drafting-workflows/scripts/make-workflow.ts +177 -0
- package/.versions/2.0.1/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/2.0.1/skills/git-workflow-and-versioning/SKILL.md +316 -0
- package/.versions/2.0.1/skills/idea-refine/SKILL.md +182 -0
- package/.versions/2.0.1/skills/idea-refine/examples.md +238 -0
- package/.versions/2.0.1/skills/idea-refine/frameworks.md +99 -0
- package/.versions/2.0.1/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/2.0.1/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/2.0.1/skills/incremental-implementation/SKILL.md +298 -0
- package/.versions/2.0.1/skills/interview-me/SKILL.md +226 -0
- package/.versions/2.0.1/skills/orchestration-verification/SKILL.md +181 -0
- package/.versions/2.0.1/skills/peer-coms/SKILL.md +90 -0
- package/.versions/2.0.1/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/2.0.1/skills/planning-and-task-breakdown/SKILL.md +263 -0
- package/.versions/2.0.1/skills/security-and-hardening/SKILL.md +461 -0
- package/.versions/2.0.1/skills/spec-driven-development/SKILL.md +256 -0
- package/.versions/2.0.1/skills/using-agent-skills/SKILL.md +197 -0
- package/.versions/2.0.1/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/LICENSE +21 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/README.md +11 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
- package/.versions/2.0.1/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
- package/CHANGELOG.md +7 -0
- package/README.md +21 -0
- package/agents/code-reviewer.md +1 -0
- package/agents/documenter.md +3 -0
- package/agents/planner.md +2 -0
- package/agents/researcher.md +2 -0
- package/docs/ARCHITECTURE.md +3 -0
- package/docs/getting-started.md +21 -0
- package/docs/workflows.md +136 -0
- package/install-manifest.json +86 -1
- package/justfile +14 -0
- package/manifest-meta.json +32 -1
- package/package.json +10 -3
- package/references/workflow-authoring.md +304 -0
- package/scripts/fleet.ts +13 -0
- package/scripts/flow.ts +121 -0
- package/scripts/lib/flow-command.ts +77 -0
- package/scripts/lib/flow-maintenance.ts +230 -0
- package/scripts/workflows/lib/agent-phase.ts +118 -0
- package/scripts/workflows/lib/changes.ts +61 -0
- package/scripts/workflows/lib/env.ts +34 -0
- package/scripts/workflows/lib/envelopes.ts +141 -0
- package/scripts/workflows/lib/gates.ts +81 -0
- package/scripts/workflows/lib/git.ts +96 -0
- package/scripts/workflows/lib/permissions.ts +130 -0
- package/scripts/workflows/lib/personas.ts +44 -0
- package/scripts/workflows/lib/quality.ts +64 -0
- package/scripts/workflows/lib/run.ts +106 -0
- package/scripts/workflows/lib/trace.ts +34 -0
- package/scripts/workflows/tsconfig.json +22 -0
- package/scripts/workflows/wf-build-test.ts +61 -0
- package/scripts/workflows/wf-document.ts +50 -0
- package/scripts/workflows/wf-quality.ts +20 -0
- package/scripts/workflows/wf-scout.ts +38 -0
- package/skills/drafting-workflows/SKILL.md +143 -0
- package/skills/drafting-workflows/scripts/make-workflow.ts +177 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { statSync, readFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import type { Run } from "./run.ts";
|
|
4
|
+
import { executeQuality } from "./quality.ts";
|
|
5
|
+
|
|
6
|
+
export interface GateCheck { item: string; ok: boolean; note: string }
|
|
7
|
+
export class GateReport {
|
|
8
|
+
readonly gate: string;
|
|
9
|
+
readonly checks: GateCheck[] = [];
|
|
10
|
+
constructor(gate: string) { this.gate = gate; }
|
|
11
|
+
check(item: string, ok: boolean, note: string): this { this.checks.push({ item, ok, note }); return this; }
|
|
12
|
+
get ok(): boolean { return this.checks.length > 0 && this.checks.every(check => check.ok); }
|
|
13
|
+
failures(): GateCheck[] { return this.checks.filter(check => !check.ok); }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type Gate<T = any> = (envelope: T, run: Run) => GateReport | Promise<GateReport>;
|
|
17
|
+
|
|
18
|
+
function artifactPath(path: string, run: Run): string { return isAbsolute(path) ? path : resolve(run.trace.cwd, path); }
|
|
19
|
+
|
|
20
|
+
export const artifactsExist: Gate<{ artifacts?: string[] }> = (envelope, run) => {
|
|
21
|
+
const report = new GateReport("artifactsExist");
|
|
22
|
+
for (const item of envelope.artifacts ?? []) {
|
|
23
|
+
try { const stat = statSync(artifactPath(item, run)); report.check(item, true, `${stat.size} bytes`); }
|
|
24
|
+
catch { report.check(item, false, "declared artifact does not exist"); }
|
|
25
|
+
}
|
|
26
|
+
return envelope.artifacts?.length ? report : report.check("artifacts", true, "no artifacts declared");
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const filesNonEmpty: Gate<{ artifacts?: string[] }> = (envelope, run) => {
|
|
30
|
+
const report = new GateReport("filesNonEmpty");
|
|
31
|
+
for (const item of envelope.artifacts ?? []) {
|
|
32
|
+
try { const size = statSync(artifactPath(item, run)).size; report.check(item, size > 0, `${size} bytes`); }
|
|
33
|
+
catch { report.check(item, false, "file cannot be read"); }
|
|
34
|
+
}
|
|
35
|
+
return envelope.artifacts?.length ? report : report.check("artifacts", true, "no artifacts declared");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const jsonParses: Gate<{ artifacts?: string[] }> = (envelope, run) => {
|
|
39
|
+
const report = new GateReport("jsonParses");
|
|
40
|
+
const items = (envelope.artifacts ?? []).filter(item => item.toLowerCase().endsWith(".json"));
|
|
41
|
+
for (const item of items) {
|
|
42
|
+
try { JSON.parse(readFileSync(artifactPath(item, run), "utf8")); report.check(item, true, "JSON.parse succeeded"); }
|
|
43
|
+
catch (error) { report.check(item, false, error instanceof Error ? error.message : String(error)); }
|
|
44
|
+
}
|
|
45
|
+
return items.length ? report : report.check("json artifacts", true, "no JSON artifacts declared");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const diffMatchesClaims: Gate<{ changed_files?: string[] }> = (envelope, run) => {
|
|
49
|
+
const report = new GateReport("diffMatchesClaims");
|
|
50
|
+
for (const item of envelope.changed_files ?? []) {
|
|
51
|
+
try { const stat = statSync(artifactPath(item, run)); report.check(item, true, `${stat.size} bytes on disk`); }
|
|
52
|
+
catch { report.check(item, false, "claimed changed file does not exist"); }
|
|
53
|
+
}
|
|
54
|
+
return envelope.changed_files?.length ? report : report.check("changed_files", true, "no changed files claimed");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function testsPass(argv: string[], options: { cwd?: string; timeoutSeconds?: number } = {}): Gate {
|
|
58
|
+
return async (_envelope, run) => {
|
|
59
|
+
const logPath = resolve(run.trace.directory, `gate-tests-${Date.now()}.log`);
|
|
60
|
+
const result = await executeQuality(argv, { cwd: options.cwd ?? run.trace.cwd, logPath, timeoutSeconds: options.timeoutSeconds, signal: run.signal });
|
|
61
|
+
const evidence = result.passed ? `exit 0; ${logPath}` : `${(result.stderr || result.stdout).slice(-4000)}\n${logPath}`;
|
|
62
|
+
return new GateReport("testsPass").check(argv.join(" "), result.passed, evidence);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const verdictConsistent: Gate<{ approved?: boolean; assertions_failed?: unknown[]; assertions_unproven?: unknown[]; open_risks?: unknown[]; requires_user_decision?: unknown[] }> = envelope => {
|
|
67
|
+
const report = new GateReport("verdictConsistent");
|
|
68
|
+
const failed = envelope.assertions_failed ?? [];
|
|
69
|
+
const unproven = envelope.assertions_unproven ?? [];
|
|
70
|
+
const decisions = envelope.requires_user_decision ?? [];
|
|
71
|
+
const problems = [...failed, ...unproven, ...(envelope.open_risks ?? []), ...decisions];
|
|
72
|
+
report.check("approved vs failed assertions", !envelope.approved || failed.length === 0, envelope.approved && failed.length ? "approved verdict has blocking failed assertions" : "consistent");
|
|
73
|
+
report.check("approved vs unresolved work", !envelope.approved || (unproven.length === 0 && decisions.length === 0), envelope.approved && (unproven.length || decisions.length) ? "approved verdict has unresolved assertions or decisions" : "consistent");
|
|
74
|
+
report.check("rejection names a problem", envelope.approved !== false || problems.length > 0, envelope.approved === false && problems.length === 0 ? "rejected verdict names no problem" : "consistent");
|
|
75
|
+
return report;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export function gateCorrectionPrompt(reports: GateReport[]): string {
|
|
79
|
+
const failures = reports.flatMap(report => report.failures().map(check => `- ${report.gate} / ${check.item}: ${check.note}`));
|
|
80
|
+
return `Your previous work failed executable gates:\n${failures.join("\n")}\nCorrect the work in this same session, then re-emit ONLY your Report JSON.`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { changedPaths, permitted, rollBack, snapshot, type PermissionPolicy, type PermissionSnapshot } from "./permissions.ts";
|
|
3
|
+
|
|
4
|
+
export class StartRefusedError extends Error {
|
|
5
|
+
readonly exitCode = 3;
|
|
6
|
+
}
|
|
7
|
+
export class GitOperationError extends Error {}
|
|
8
|
+
|
|
9
|
+
export interface FlowBranchMetadata {
|
|
10
|
+
branch: string;
|
|
11
|
+
flowName?: string;
|
|
12
|
+
runId?: string;
|
|
13
|
+
baseBranch?: string;
|
|
14
|
+
baseCommit?: string;
|
|
15
|
+
result?: "accepted" | "rejected";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function git(cwd: string, args: string[]): string {
|
|
19
|
+
const result = spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
20
|
+
if (result.status !== 0) throw new GitOperationError((result.stderr || result.stdout || `git ${args.join(" ")} failed`).trim());
|
|
21
|
+
return result.stdout.trim();
|
|
22
|
+
}
|
|
23
|
+
function asStartRefusal(action: () => string): string {
|
|
24
|
+
try { return action(); }
|
|
25
|
+
catch (error) { throw new StartRefusedError(error instanceof Error ? error.message : String(error)); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isClean(cwd = process.cwd()): boolean {
|
|
29
|
+
return asStartRefusal(() => git(cwd, ["status", "--porcelain", "--untracked-files=all"])) === "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function requireCleanTree(cwd = process.cwd(), allowDirty = false): void {
|
|
33
|
+
if (!allowDirty && !isClean(cwd)) throw new StartRefusedError("Flow start refused: working tree is dirty; commit/stash it or pass --allow-dirty.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function flowBranchName(name: string, runId: string): string {
|
|
37
|
+
return `flow/${name}-${runId}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function configKey(branch: string, name: string): string { return `branch.${branch}.agentFleet${name}`; }
|
|
41
|
+
function optionalGit(cwd: string, args: string[]): string | undefined {
|
|
42
|
+
try { return git(cwd, args); } catch { return undefined; }
|
|
43
|
+
}
|
|
44
|
+
function writeBranchConfig(cwd: string, branch: string, name: string, value: string): void {
|
|
45
|
+
git(cwd, ["config", "--local", "--replace-all", configKey(branch, name), value]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function readFlowBranchMetadata(branch: string, cwd = process.cwd()): FlowBranchMetadata {
|
|
49
|
+
const value = (name: string) => optionalGit(cwd, ["config", "--local", "--get", configKey(branch, name)]);
|
|
50
|
+
const flowName = value("FlowName"), runId = value("RunId"), baseBranch = value("BaseBranch"), baseCommit = value("BaseCommit"), result = value("Result");
|
|
51
|
+
return {
|
|
52
|
+
branch,
|
|
53
|
+
...(flowName ? { flowName } : {}), ...(runId ? { runId } : {}), ...(baseBranch ? { baseBranch } : {}), ...(baseCommit ? { baseCommit } : {}),
|
|
54
|
+
...(result === "accepted" || result === "rejected" ? { result } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function recordFlowResult(branch: string, result: "accepted" | "rejected", cwd = process.cwd()): void {
|
|
59
|
+
writeBranchConfig(cwd, branch, "Result", result);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function createFlowBranch(name: string, runId: string, cwd = process.cwd()): string {
|
|
63
|
+
const branch = flowBranchName(name, runId);
|
|
64
|
+
const baseBranch = optionalGit(cwd, ["branch", "--show-current"]);
|
|
65
|
+
const baseCommit = asStartRefusal(() => git(cwd, ["rev-parse", "HEAD"]));
|
|
66
|
+
asStartRefusal(() => git(cwd, ["switch", "-c", branch]));
|
|
67
|
+
try {
|
|
68
|
+
writeBranchConfig(cwd, branch, "FlowName", name);
|
|
69
|
+
writeBranchConfig(cwd, branch, "RunId", runId);
|
|
70
|
+
writeBranchConfig(cwd, branch, "BaseCommit", baseCommit);
|
|
71
|
+
if (baseBranch) writeBranchConfig(cwd, branch, "BaseBranch", baseBranch);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new GitOperationError(`Flow branch was created but its metadata could not be recorded: ${error instanceof Error ? error.message : String(error)}`);
|
|
74
|
+
}
|
|
75
|
+
return branch;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function commitAll(message: string, cwd: string, baseline: PermissionSnapshot, policy: PermissionPolicy = {}): string | null {
|
|
79
|
+
let after = snapshot(cwd);
|
|
80
|
+
const changed = changedPaths(baseline, after);
|
|
81
|
+
const preDirtyChanged = changed.filter(path => baseline.paths.has(path));
|
|
82
|
+
if (preDirtyChanged.length) {
|
|
83
|
+
rollBack(baseline, preDirtyChanged);
|
|
84
|
+
after = snapshot(cwd);
|
|
85
|
+
}
|
|
86
|
+
const introduced = changedPaths(baseline, after).filter(path => !baseline.paths.has(path));
|
|
87
|
+
const violations = introduced.filter(path => !permitted(path, policy, cwd));
|
|
88
|
+
if (violations.length) {
|
|
89
|
+
rollBack(baseline, violations);
|
|
90
|
+
throw new GitOperationError(`Flow introduced paths outside the commit policy: ${violations.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
if (!introduced.length) return null;
|
|
93
|
+
git(cwd, ["add", "--", ...introduced]);
|
|
94
|
+
git(cwd, ["commit", "--only", "-m", message, "--", ...introduced]);
|
|
95
|
+
return git(cwd, ["rev-parse", "HEAD"]);
|
|
96
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
interface PathState {
|
|
7
|
+
path: string;
|
|
8
|
+
numstat: string;
|
|
9
|
+
index?: { mode: string; object: string; stage: string };
|
|
10
|
+
worktree?: { kind: "file" | "symlink"; data: string; hash: string };
|
|
11
|
+
headTracked: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PermissionSnapshot { cwd: string; paths: Map<string, PathState> }
|
|
14
|
+
export interface PermissionPolicy { writes?: string[]; protectedGlobs?: string[]; alwaysWritable?: string[] }
|
|
15
|
+
export interface PermissionEnforcement { changed: string[]; violations: string[]; preDirtyPreserved: string[] }
|
|
16
|
+
|
|
17
|
+
export class PermissionBreach extends Error {
|
|
18
|
+
readonly paths: string[];
|
|
19
|
+
readonly exitCode = 1;
|
|
20
|
+
readonly terminal = true;
|
|
21
|
+
constructor(paths: string[], preserved: string[] = []) {
|
|
22
|
+
super(`PermissionBreach: unauthorized repository changes: ${paths.join(", ")}${preserved.length ? `; restored pre-dirty state for: ${preserved.join(", ")}` : ""}`);
|
|
23
|
+
this.name = "PermissionBreach";
|
|
24
|
+
this.paths = paths;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function git(cwd: string, args: string[]): string {
|
|
29
|
+
return execFileSync("git", args, { cwd, encoding: "utf8" });
|
|
30
|
+
}
|
|
31
|
+
function zlist(value: string): string[] { return value.split("\0").filter(Boolean); }
|
|
32
|
+
function worktreeState(cwd: string, path: string): PathState["worktree"] {
|
|
33
|
+
const full = resolve(cwd, path);
|
|
34
|
+
if (!existsSync(full)) return undefined;
|
|
35
|
+
const stat = lstatSync(full);
|
|
36
|
+
if (stat.isDirectory()) return undefined;
|
|
37
|
+
const kind = stat.isSymbolicLink() ? "symlink" : "file";
|
|
38
|
+
const data = kind === "symlink" ? Buffer.from(readlinkSync(full)).toString("base64") : readFileSync(full).toString("base64");
|
|
39
|
+
return { kind, data, hash: createHash("sha256").update(data).digest("hex") };
|
|
40
|
+
}
|
|
41
|
+
function indexState(cwd: string, path: string): PathState["index"] {
|
|
42
|
+
const raw = git(cwd, ["ls-files", "-s", "-z", "--", path]);
|
|
43
|
+
const match = raw.match(/^(\d+) ([0-9a-f]+) (\d+)\t/);
|
|
44
|
+
return match ? { mode: match[1], object: match[2], stage: match[3] } : undefined;
|
|
45
|
+
}
|
|
46
|
+
function headTracked(cwd: string, path: string): boolean {
|
|
47
|
+
try { execFileSync("git", ["cat-file", "-e", `HEAD:${path}`], { cwd, stdio: "ignore" }); return true; } catch { return false; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function snapshot(cwd = process.cwd()): PermissionSnapshot {
|
|
51
|
+
const numstat = git(cwd, ["diff", "HEAD", "--no-renames", "--numstat", "-z"]);
|
|
52
|
+
const rows = zlist(numstat);
|
|
53
|
+
const stats = new Map<string, string>();
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const match = row.match(/^([^\t]+)\t([^\t]+)\t([\s\S]+)$/);
|
|
56
|
+
if (match) stats.set(match[3], `${match[1]}\t${match[2]}`);
|
|
57
|
+
}
|
|
58
|
+
const trackedChanges = zlist(git(cwd, ["diff", "HEAD", "--no-renames", "--name-only", "-z"]));
|
|
59
|
+
const untracked = zlist(git(cwd, ["ls-files", "--others", "--exclude-standard", "-z"]));
|
|
60
|
+
const paths = new Map<string, PathState>();
|
|
61
|
+
for (const path of new Set([...trackedChanges, ...untracked])) {
|
|
62
|
+
paths.set(path, { path, numstat: stats.get(path) ?? "untracked", index: indexState(cwd, path), worktree: worktreeState(cwd, path), headTracked: headTracked(cwd, path) });
|
|
63
|
+
}
|
|
64
|
+
return { cwd: resolve(cwd), paths };
|
|
65
|
+
}
|
|
66
|
+
function signature(state?: PathState): string { return state ? JSON.stringify(state) : "clean"; }
|
|
67
|
+
export function changedPaths(before: PermissionSnapshot, after: PermissionSnapshot): string[] {
|
|
68
|
+
const paths = new Set([...before.paths.keys(), ...after.paths.keys()]);
|
|
69
|
+
return [...paths].filter(path => signature(before.paths.get(path)) !== signature(after.paths.get(path))).sort();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function globRegex(pattern: string): RegExp {
|
|
73
|
+
let input = pattern.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
74
|
+
if (input.endsWith("/")) input += "**";
|
|
75
|
+
let source = "^";
|
|
76
|
+
for (let i = 0; i < input.length; i++) {
|
|
77
|
+
const char = input[i];
|
|
78
|
+
if (char === "*" && input[i + 1] === "*") {
|
|
79
|
+
i++;
|
|
80
|
+
if (input[i + 1] === "/") { i++; source += "(?:.*/)?"; } else source += ".*";
|
|
81
|
+
} else if (char === "*") source += "[^/]*";
|
|
82
|
+
else if (char === "?") source += "[^/]";
|
|
83
|
+
else source += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
84
|
+
}
|
|
85
|
+
return new RegExp(`${source}$`);
|
|
86
|
+
}
|
|
87
|
+
export function matchesWriteGlob(path: string, pattern: string): boolean { return globRegex(pattern).test(path.replaceAll("\\", "/")); }
|
|
88
|
+
export function permitted(path: string, policy: PermissionPolicy, cwd = process.cwd()): boolean {
|
|
89
|
+
const normalized = path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
90
|
+
for (const always of policy.alwaysWritable ?? []) {
|
|
91
|
+
const rel = relative(resolve(cwd), resolve(always)).split(sep).join("/");
|
|
92
|
+
if (normalized === rel || normalized.startsWith(`${rel}/`)) return true;
|
|
93
|
+
}
|
|
94
|
+
const explicitlyAllowed = policy.writes?.some(glob => matchesWriteGlob(normalized, glob)) ?? false;
|
|
95
|
+
if ((policy.protectedGlobs ?? []).some(glob => matchesWriteGlob(normalized, glob)) && !explicitlyAllowed) return false;
|
|
96
|
+
return policy.writes === undefined || explicitlyAllowed;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function restoreState(cwd: string, path: string, state?: PathState): void {
|
|
100
|
+
const full = resolve(cwd, path);
|
|
101
|
+
if (!state) {
|
|
102
|
+
if (headTracked(cwd, path)) execFileSync("git", ["restore", "--source=HEAD", "--staged", "--worktree", "--", path], { cwd });
|
|
103
|
+
else { rmSync(full, { recursive: true, force: true }); try { execFileSync("git", ["update-index", "--force-remove", "--", path], { cwd, stdio: "ignore" }); } catch {} }
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (state.index) execFileSync("git", ["update-index", "--add", "--cacheinfo", `${state.index.mode},${state.index.object},${path}`], { cwd });
|
|
107
|
+
else { try { execFileSync("git", ["update-index", "--force-remove", "--", path], { cwd, stdio: "ignore" }); } catch {} }
|
|
108
|
+
rmSync(full, { recursive: true, force: true });
|
|
109
|
+
if (state.worktree) {
|
|
110
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
111
|
+
const data = Buffer.from(state.worktree.data, "base64");
|
|
112
|
+
if (state.worktree.kind === "symlink") symlinkSync(data.toString(), full);
|
|
113
|
+
else writeFileSync(full, data);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function rollBack(before: PermissionSnapshot, paths: string[]): string[] {
|
|
117
|
+
const preserved: string[] = [];
|
|
118
|
+
for (const path of paths) {
|
|
119
|
+
if (before.paths.has(path)) preserved.push(path);
|
|
120
|
+
restoreState(before.cwd, path, before.paths.get(path));
|
|
121
|
+
}
|
|
122
|
+
return preserved;
|
|
123
|
+
}
|
|
124
|
+
export function enforce(before: PermissionSnapshot, after: PermissionSnapshot, policy: PermissionPolicy): PermissionEnforcement {
|
|
125
|
+
const changed = changedPaths(before, after);
|
|
126
|
+
const violations = changed.filter(path => !permitted(path, policy, before.cwd));
|
|
127
|
+
const preDirtyPreserved = violations.length ? rollBack(before, violations) : [];
|
|
128
|
+
if (violations.length) throw new PermissionBreach(violations, preDirtyPreserved);
|
|
129
|
+
return { changed, violations, preDirtyPreserved };
|
|
130
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { StartRefusedError } from "./git.ts";
|
|
3
|
+
|
|
4
|
+
interface ScannedPersona {
|
|
5
|
+
name: string; description: string; tools: string; model?: string; models?: string[];
|
|
6
|
+
thinking?: string; systemPrompt: string; file: string;
|
|
7
|
+
}
|
|
8
|
+
const agentsModulePath: string = "../../../.pi/harnesses/agent-hub/config/agents.ts";
|
|
9
|
+
const { scanAgentDirs } = await import(agentsModulePath) as { scanAgentDirs(cwd: string): ScannedPersona[] };
|
|
10
|
+
export type PersonaDefinition = ScannedPersona & { fallbackModel?: string; writes?: string[] };
|
|
11
|
+
|
|
12
|
+
function declaredWrites(file: string): string[] | undefined {
|
|
13
|
+
const frontmatter = readFileSync(file, "utf8").match(/^---\n([\s\S]*?)\n---/)?.[1] ?? "";
|
|
14
|
+
const lines = frontmatter.split("\n");
|
|
15
|
+
const index = lines.findIndex(line => /^writes\s*:/.test(line));
|
|
16
|
+
if (index < 0) return undefined;
|
|
17
|
+
const inline = lines[index].replace(/^writes\s*:\s*/, "").trim();
|
|
18
|
+
if (inline === "[]") return [];
|
|
19
|
+
if (inline) return inline.replace(/^\[|\]$/g, "").split(",").map(value => value.trim().replace(/^['\"]|['\"]$/g, "")).filter(Boolean);
|
|
20
|
+
const values: string[] = [];
|
|
21
|
+
for (let i = index + 1; i < lines.length; i++) {
|
|
22
|
+
const match = lines[i].match(/^\s+-\s+(.+)$/);
|
|
23
|
+
if (!match) break;
|
|
24
|
+
values.push(match[1].trim().replace(/^['\"]|['\"]$/g, ""));
|
|
25
|
+
}
|
|
26
|
+
return values;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listPersonas(cwd = process.cwd()): PersonaDefinition[] {
|
|
30
|
+
return scanAgentDirs(cwd).map(def => {
|
|
31
|
+
const override = process.env[`AGENT_FLEET_MODEL_${def.name.toUpperCase().replace(/-/g, "_")}`];
|
|
32
|
+
const model = override || def.model || def.models?.[0];
|
|
33
|
+
const fallbackModel = [def.model, ...(def.models ?? [])].find(candidate => candidate && candidate !== model);
|
|
34
|
+
const writes = declaredWrites(def.file);
|
|
35
|
+
return { ...def, model, fallbackModel, ...(writes === undefined ? {} : { writes }) };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function resolvePersona(name: string, cwd = process.cwd()): PersonaDefinition {
|
|
40
|
+
const persona = listPersonas(cwd).find(def => def.name.toLowerCase() === name.toLowerCase());
|
|
41
|
+
if (!persona) throw new StartRefusedError(`Flow start refused: persona "${name}" was not found in agents/, .claude/agents/, or .pi/agents/.`);
|
|
42
|
+
if (!persona.model) throw new StartRefusedError(`Flow start refused: persona "${name}" declares no model.`);
|
|
43
|
+
return persona;
|
|
44
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import type { Run } from "./run.ts";
|
|
5
|
+
|
|
6
|
+
export interface QualityResult { argv: string[]; exitCode: number; stdout: string; stderr: string; logPath: string; passed: boolean }
|
|
7
|
+
export interface VerifyEnvelope { status: "success" | "fail"; summary: string; artifacts: string[]; notes_for_next_agent: string; tests_run: string[] }
|
|
8
|
+
|
|
9
|
+
function splitArgv(value: string): string[] {
|
|
10
|
+
const matches = value.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) ?? [];
|
|
11
|
+
return matches.map(part => part.replace(/^("|')|("|')$/g, ""));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function qualityCommand(cwd = process.cwd()): string[] {
|
|
15
|
+
const override = resolve(cwd, ".ai", "agent-fleet-overrides.md");
|
|
16
|
+
if (!existsSync(override)) throw Object.assign(new Error("Flow start refused: configure `quality:` under `## workflows` in .ai/agent-fleet-overrides.md."), { exitCode: 3 });
|
|
17
|
+
const text = readFileSync(override, "utf8");
|
|
18
|
+
const heading = text.match(/^## workflows\s*$/m);
|
|
19
|
+
const sectionStart = heading == null ? -1 : heading.index! + heading[0].length;
|
|
20
|
+
const tail = sectionStart < 0 ? "" : text.slice(sectionStart);
|
|
21
|
+
const nextHeading = tail.search(/^##\s/m);
|
|
22
|
+
const section = nextHeading < 0 ? tail : tail.slice(0, nextHeading);
|
|
23
|
+
const configured = section.match(/^quality\s*:\s*(.+)$/m)?.[1]?.trim();
|
|
24
|
+
const argv = configured ? splitArgv(configured) : [];
|
|
25
|
+
if (!argv.length) throw Object.assign(new Error("Flow start refused: configure a non-empty `quality:` argv under `## workflows` in .ai/agent-fleet-overrides.md."), { exitCode: 3 });
|
|
26
|
+
return argv;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function executeQuality(argv: string[], options: { cwd?: string; logPath: string; timeoutSeconds?: number; signal?: AbortSignal }): Promise<QualityResult> {
|
|
30
|
+
const cwd = options.cwd ?? process.cwd();
|
|
31
|
+
const timeoutMs = (options.timeoutSeconds ?? 1800) * 1000;
|
|
32
|
+
if (!argv.length || !argv[0]) throw new Error("Quality command requires a non-empty argv list");
|
|
33
|
+
const result = await new Promise<{ code: number; stdout: string; stderr: string }>(resolveResult => {
|
|
34
|
+
const child = spawn(argv[0], argv.slice(1), { cwd, env: process.env, shell: false, stdio: ["ignore", "pipe", "pipe"] });
|
|
35
|
+
let stdout = "", stderr = "", settled = false;
|
|
36
|
+
let timer: NodeJS.Timeout;
|
|
37
|
+
const onAbort = () => { stderr += "\nCancelled by flow signal"; child.kill("SIGTERM"); };
|
|
38
|
+
const finish = (code: number) => { if (!settled) { settled = true; clearTimeout(timer); options.signal?.removeEventListener("abort", onAbort); resolveResult({ code, stdout, stderr }); } };
|
|
39
|
+
if (options.signal?.aborted) onAbort(); else options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
40
|
+
child.stdout?.on("data", chunk => { stdout += chunk; });
|
|
41
|
+
child.stderr?.on("data", chunk => { stderr += chunk; });
|
|
42
|
+
child.on("error", error => { stderr += error.message; finish((error as NodeJS.ErrnoException).code === "ENOENT" ? 127 : 1); });
|
|
43
|
+
child.on("close", code => finish(code ?? 1));
|
|
44
|
+
timer = setTimeout(() => { stderr += `\nTimed out after ${timeoutMs}ms`; child.kill("SIGTERM"); finish(1); }, timeoutMs);
|
|
45
|
+
});
|
|
46
|
+
const body = [`$ ${argv.join(" ")}`, result.stdout, result.stderr, `exit ${result.code}`].filter(Boolean).join("\n");
|
|
47
|
+
writeFileSync(options.logPath, body, "utf8");
|
|
48
|
+
return { argv, exitCode: result.code, stdout: result.stdout, stderr: result.stderr, logPath: options.logPath, passed: result.code === 0 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function runTests(run: Run, options: { cwd?: string; argv?: string[]; timeoutSeconds?: number } = {}): Promise<QualityResult> {
|
|
52
|
+
const cwd = options.cwd ?? process.cwd();
|
|
53
|
+
return executeQuality(options.argv ?? qualityCommand(cwd), { cwd, timeoutSeconds: options.timeoutSeconds, signal: run.signal, logPath: resolve(run.trace.directory, "command.log") });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function asEnvelope(result: QualityResult, what: string): VerifyEnvelope {
|
|
57
|
+
return {
|
|
58
|
+
status: result.passed ? "success" : "fail",
|
|
59
|
+
summary: result.passed ? `${what} passed` : `${what} failed with exit ${result.exitCode}`,
|
|
60
|
+
artifacts: [result.logPath],
|
|
61
|
+
notes_for_next_agent: result.passed ? "" : (result.stderr || result.stdout).slice(-4000),
|
|
62
|
+
tests_run: [`${result.argv.join(" ")} → ${result.exitCode}`],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import type { PermissionSnapshot } from "./permissions.ts";
|
|
3
|
+
import { FlowTrace } from "./trace.ts";
|
|
4
|
+
|
|
5
|
+
export type PhaseKind = "engineer" | "agent" | "code";
|
|
6
|
+
export interface PhaseParams { name: string; kind: PhaseKind; owner: string; description: string; retries?: number }
|
|
7
|
+
export interface FinishResult { accepted: boolean; reason?: string; exitCode: number; status: "accepted" | "rejected"; banner: string; signal?: NodeJS.Signals }
|
|
8
|
+
|
|
9
|
+
function words(value: string): string[] {
|
|
10
|
+
return value.toLowerCase().replace(/[_-]+/g, " ").replace(/[^a-z0-9 ]/g, "").split(/\s+/).filter(Boolean);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateDescription(name: string, description: string): void {
|
|
14
|
+
if (!description.trim()) throw new Error("Phase description must explain why the phase exists");
|
|
15
|
+
const nameWords = words(name);
|
|
16
|
+
const descriptionWords = words(description).filter(word => !["a", "an", "the", "to", "of"].includes(word));
|
|
17
|
+
if (nameWords.length > 0 && descriptionWords.join(" ") === nameWords.join(" ")) {
|
|
18
|
+
throw new Error("Phase description must explain why, not merely repeat its name");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class PhaseContext {
|
|
23
|
+
status: "fail" | "success" = "fail";
|
|
24
|
+
readonly params: PhaseParams;
|
|
25
|
+
private readonly trace: FlowTrace;
|
|
26
|
+
constructor(params: PhaseParams, trace: FlowTrace) { this.params = params; this.trace = trace; }
|
|
27
|
+
log(message: string, data: Record<string, unknown> = {}): void { this.trace.write("log", { phase: this.params.name, message, ...data }); }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Run {
|
|
31
|
+
readonly trace: FlowTrace;
|
|
32
|
+
readonly repositoryBaseline?: PermissionSnapshot;
|
|
33
|
+
private finished = false;
|
|
34
|
+
private phaseFailed = false;
|
|
35
|
+
private lastResult?: FinishResult;
|
|
36
|
+
private readonly cancellation = new AbortController();
|
|
37
|
+
readonly signal = this.cancellation.signal;
|
|
38
|
+
|
|
39
|
+
constructor(options: { cwd?: string; runId?: string; command?: string[]; trace?: FlowTrace; repositoryBaseline?: PermissionSnapshot } = {}) {
|
|
40
|
+
this.trace = options.trace ?? new FlowTrace(options);
|
|
41
|
+
this.repositoryBaseline = options.repositoryBaseline;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async phase<T>(params: PhaseParams, body: (phase: PhaseContext) => Promise<T> | T): Promise<T> {
|
|
45
|
+
if (this.finished) throw new Error("Cannot start a phase after finish()");
|
|
46
|
+
validateDescription(params.name, params.description);
|
|
47
|
+
const retries = params.retries ?? 0;
|
|
48
|
+
if (!Number.isInteger(retries) || retries < 0) throw new Error("Phase retries must be a non-negative integer");
|
|
49
|
+
const phase = new PhaseContext(params, this.trace);
|
|
50
|
+
this.trace.write("phase_start", { phase: params.name, kind: params.kind, owner: params.owner, description: params.description, retries, status: phase.status });
|
|
51
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
52
|
+
try {
|
|
53
|
+
const value = await body(phase);
|
|
54
|
+
if (this.finished) throw new Error("Run ended while phase was active");
|
|
55
|
+
phase.status = "success";
|
|
56
|
+
this.trace.write("phase_end", { phase: params.name, status: phase.status, attempt: attempt + 1 });
|
|
57
|
+
return value;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (this.finished) throw error;
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
this.trace.write("error", { phase: params.name, message, attempt: attempt + 1 });
|
|
62
|
+
const terminal = typeof error === "object" && error !== null && (error as { terminal?: boolean }).terminal === true;
|
|
63
|
+
if (attempt < retries && !terminal) {
|
|
64
|
+
this.trace.write("log", { phase: params.name, message: "retrying failed phase", nextAttempt: attempt + 2 });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
this.phaseFailed = true;
|
|
68
|
+
this.trace.write("phase_end", { phase: params.name, status: phase.status, attempt: attempt + 1, error: message });
|
|
69
|
+
if (!this.finished) this.finalize(false, message);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw new Error("unreachable phase retry state");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
registerProcess(process: ChildProcess, phase: string): void {
|
|
77
|
+
this.trace.write("agent_process", { phase, pid: process.pid ?? null, processGroup: process.pid == null ? null : -process.pid });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
finish(input: { accepted: boolean; reason?: string }): FinishResult {
|
|
81
|
+
if (this.finished) throw new Error("finish() may be called exactly once");
|
|
82
|
+
return this.finalize(input.accepted && !this.phaseFailed, input.reason);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
abort(reason: string, exitCode = 1): FinishResult {
|
|
86
|
+
this.cancellation.abort(reason);
|
|
87
|
+
if (this.finished) return this.lastResult!;
|
|
88
|
+
return this.finalize(false, reason, exitCode);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interrupt(signal: NodeJS.Signals): FinishResult {
|
|
92
|
+
const exitCode = 128 + (signal === "SIGINT" ? 2 : 15);
|
|
93
|
+
this.cancellation.abort(signal);
|
|
94
|
+
if (this.finished) return this.lastResult!;
|
|
95
|
+
return this.finalize(false, `interrupted by ${signal}`, exitCode, signal);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private finalize(accepted: boolean, reason?: string, exitCode = accepted ? 0 : 1, signal?: NodeJS.Signals): FinishResult {
|
|
99
|
+
this.finished = true;
|
|
100
|
+
const status = accepted ? "accepted" : "rejected";
|
|
101
|
+
const banner = accepted ? `FLOW ACCEPTED (${this.trace.runId})` : `FLOW REJECTED (${this.trace.runId})${reason ? `: ${reason}` : ""}`;
|
|
102
|
+
this.lastResult = { accepted, reason, exitCode, status, banner, ...(signal ? { signal } : {}) };
|
|
103
|
+
this.trace.write("run_end", { accepted, status, exitCode, reason: reason ?? "", banner, ...(signal ? { signal } : {}) });
|
|
104
|
+
return this.lastResult;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
const runNamespacePath: string = "../../../.pi/harnesses/agent-hub/run-namespace.js";
|
|
4
|
+
const { makeRunId } = await import(runNamespacePath) as { makeRunId(): string };
|
|
5
|
+
|
|
6
|
+
export type TraceEvent = Record<string, unknown> & { type: string; at: string; runId: string };
|
|
7
|
+
|
|
8
|
+
export class FlowTrace {
|
|
9
|
+
readonly runId: string;
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
readonly directory: string;
|
|
12
|
+
readonly file: string;
|
|
13
|
+
private ended = false;
|
|
14
|
+
|
|
15
|
+
constructor(options: { cwd?: string; runId?: string; command?: string[]; pid?: number } = {}) {
|
|
16
|
+
this.runId = options.runId ?? makeRunId();
|
|
17
|
+
this.cwd = resolve(options.cwd ?? process.cwd());
|
|
18
|
+
this.directory = resolve(this.cwd, ".pi", "flow-sessions", this.runId);
|
|
19
|
+
this.file = resolve(this.directory, "trace.jsonl");
|
|
20
|
+
mkdirSync(this.directory, { recursive: true });
|
|
21
|
+
this.write("run_start", { pid: options.pid ?? process.pid, command: options.command ?? process.argv });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
write(type: string, data: Record<string, unknown> = {}): void {
|
|
25
|
+
if (this.ended) return;
|
|
26
|
+
const event: TraceEvent = { type, at: new Date().toISOString(), runId: this.runId, ...data };
|
|
27
|
+
appendFileSync(this.file, `${JSON.stringify(event)}\n`, "utf8");
|
|
28
|
+
if (type === "run_end") this.ended = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
events(): TraceEvent[] {
|
|
32
|
+
return readFileSync(this.file, "utf8").trim().split("\n").filter(Boolean).map(line => JSON.parse(line));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowImportingTsExtensions": true,
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"checkJs": false,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"module": "NodeNext",
|
|
8
|
+
"moduleResolution": "NodeNext",
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"target": "ES2022",
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"./*.ts",
|
|
17
|
+
"./lib/*.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"./**/*.test.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { runAgentPhase } from "./lib/agent-phase.ts";
|
|
2
|
+
import { ENVELOPE_EXAMPLES, validateEnvelope, type BuildEnvelope as BuildEnvelopeSchema } from "./lib/envelopes.ts";
|
|
3
|
+
import { artifactsExist, diffMatchesClaims } from "./lib/gates.ts";
|
|
4
|
+
import { commitAll } from "./lib/git.ts";
|
|
5
|
+
import { snapshot, type PermissionSnapshot } from "./lib/permissions.ts";
|
|
6
|
+
import { resolvePersona, type PersonaDefinition } from "./lib/personas.ts";
|
|
7
|
+
import { qualityCommand, runTests, type QualityResult } from "./lib/quality.ts";
|
|
8
|
+
import type { FinishResult, Run } from "./lib/run.ts";
|
|
9
|
+
import type { Static } from "@sinclair/typebox";
|
|
10
|
+
|
|
11
|
+
export type BuildReport = Static<typeof BuildEnvelopeSchema>;
|
|
12
|
+
export const MAX_BUILD_FIX_ATTEMPTS = 2;
|
|
13
|
+
const BUILDER_PERMISSION_POLICY = { writes: ["**"] };
|
|
14
|
+
export interface BuildTestDeps {
|
|
15
|
+
agent?: (options: Parameters<typeof runAgentPhase<BuildReport>>[0]) => Promise<BuildReport>;
|
|
16
|
+
tests?: (run: Run, options: { cwd: string }) => Promise<QualityResult>;
|
|
17
|
+
commit?: (message: string, cwd: string, baseline: PermissionSnapshot, policy: { writes?: string[] }) => string | null;
|
|
18
|
+
persona?: PersonaDefinition;
|
|
19
|
+
baseline?: PermissionSnapshot;
|
|
20
|
+
maxFixAttempts?: number;
|
|
21
|
+
}
|
|
22
|
+
export function buildTestWorkflowPreflight(cwd: string): void { resolvePersona("builder", cwd); qualityCommand(cwd); }
|
|
23
|
+
function dryBuild(): BuildReport {
|
|
24
|
+
const parsed = validateEnvelope<BuildReport>("build", JSON.stringify(ENVELOPE_EXAMPLES.build));
|
|
25
|
+
if (!parsed.ok) throw new Error(parsed.errors.join("; "));
|
|
26
|
+
return parsed.value!;
|
|
27
|
+
}
|
|
28
|
+
function redOutput(result: QualityResult): string { return `${result.stdout}${result.stderr}`; }
|
|
29
|
+
|
|
30
|
+
/** Phases: engineer(request) → agent(builder) → code(test) → agent(builder-fix, bounded) → code(commit) */
|
|
31
|
+
export async function buildTestWorkflow(run: Run, input: { args: string[]; dryRun: boolean; cwd: string }, deps: BuildTestDeps = {}): Promise<FinishResult> {
|
|
32
|
+
const request = input.args.join(" ").trim();
|
|
33
|
+
if (!request) throw Object.assign(new Error("build-test flow requires an implementation request"), { exitCode: 2 });
|
|
34
|
+
const persona = deps.persona ?? resolvePersona("builder", input.cwd);
|
|
35
|
+
const baseline = deps.baseline ?? run.repositoryBaseline ?? snapshot(input.cwd);
|
|
36
|
+
const agent = deps.agent ?? runAgentPhase<BuildReport>;
|
|
37
|
+
const tests = deps.tests ?? ((activeRun, options) => runTests(activeRun, options));
|
|
38
|
+
const commit = deps.commit ?? commitAll;
|
|
39
|
+
await run.phase({ name: "request", kind: "engineer", owner: "operator", description: "Preserve the exact implementation outcome the operator asked for" }, phase => phase.log(request));
|
|
40
|
+
let report = await run.phase({ name: "build", kind: "agent", owner: "builder", description: "Implement the requested change before deterministic verification" }, () => input.dryRun ? dryBuild() : agent({ run, persona, task: request, envelope: "build", cwd: input.cwd, gates: [artifactsExist, diffMatchesClaims], gateRetries: 1, permissionPolicy: BUILDER_PERMISSION_POLICY }));
|
|
41
|
+
let quality = await run.phase({ name: "test", kind: "code", owner: "quality", description: "Measure the implementation with the configured suite before any commit" }, async phase => {
|
|
42
|
+
if (input.dryRun) { phase.log("dry-run: green quality result stubbed"); return { argv: ["dry-run"], exitCode: 0, stdout: "", stderr: "", logPath: run.trace.file, passed: true }; }
|
|
43
|
+
const result = await tests(run, { cwd: input.cwd }); phase.log(result.passed ? "suite passed" : "suite failed", { exitCode: result.exitCode, logPath: result.logPath }); return result;
|
|
44
|
+
});
|
|
45
|
+
for (let attempt = 1; !quality.passed && attempt <= (deps.maxFixAttempts ?? MAX_BUILD_FIX_ATTEMPTS); attempt++) {
|
|
46
|
+
const output = redOutput(quality);
|
|
47
|
+
report = await run.phase({ name: `builder-fix-${attempt}`, kind: "agent", owner: "builder", description: "Correct the implementation using verbatim evidence from the red suite" }, () => input.dryRun ? dryBuild() : agent({
|
|
48
|
+
run, persona, envelope: "build", cwd: input.cwd, gates: [artifactsExist, diffMatchesClaims], gateRetries: 1, permissionPolicy: BUILDER_PERMISSION_POLICY,
|
|
49
|
+
task: `The deterministic test suite is red. Correct the implementation. The suite output below is forwarded verbatim:\n--- BEGIN VERBATIM TEST OUTPUT ---\n${output}\n--- END VERBATIM TEST OUTPUT ---`,
|
|
50
|
+
}));
|
|
51
|
+
quality = await run.phase({ name: `test-after-fix-${attempt}`, kind: "code", owner: "quality", description: "Re-run the same configured suite to decide whether repair succeeded" }, async () => tests(run, { cwd: input.cwd }));
|
|
52
|
+
}
|
|
53
|
+
if (!quality.passed) return run.finish({ accepted: false, reason: `the suite remained red after ${deps.maxFixAttempts ?? MAX_BUILD_FIX_ATTEMPTS} builder fix attempts` });
|
|
54
|
+
await run.phase({ name: "commit", kind: "code", owner: "git", description: "Create one commit only after deterministic verification is green" }, phase => {
|
|
55
|
+
if (input.dryRun) return phase.log("dry-run: commit skipped");
|
|
56
|
+
const hash = commit(report.commit_message, input.cwd, baseline, { writes: persona.writes });
|
|
57
|
+
if (hash) phase.log("verified work committed", { hash });
|
|
58
|
+
else phase.log("no flow-introduced changes to commit");
|
|
59
|
+
});
|
|
60
|
+
return run.finish({ accepted: true });
|
|
61
|
+
}
|