@chankov/agent-fleet 0.0.2 → 0.0.4
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/.claude/commands/doctor-agent-fleet.md +1 -1
- package/.claude/commands/setup-agent-fleet.md +5 -5
- package/.opencode/commands/af-doctor-agent-fleet.md +2 -0
- package/.opencode/commands/af-setup-agent-fleet.md +1 -1
- package/.pi/agents/peers.yaml +4 -0
- package/.pi/agents/teams.yaml +2 -2
- package/.pi/harnesses/agent-hub/README.md +254 -18
- package/.pi/harnesses/agent-hub/access-approval.ts +135 -0
- package/.pi/harnesses/agent-hub/delegate.ts +32 -9
- package/.pi/harnesses/agent-hub/drift-watchdog.js +165 -0
- package/.pi/harnesses/agent-hub/footer.ts +29 -0
- package/.pi/harnesses/agent-hub/helpers.ts +49 -0
- package/.pi/harnesses/agent-hub/index.ts +1269 -322
- package/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
- package/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
- package/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
- package/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
- package/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
- package/.pi/harnesses/agent-hub/monitor-session-bridge.ts +11 -0
- package/.pi/harnesses/agent-hub/package.json +5 -4
- package/.pi/harnesses/agent-hub/research-retention.js +34 -0
- package/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
- package/.pi/harnesses/agent-hub/run-budget.js +155 -0
- package/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
- package/.pi/harnesses/agent-hub/spawn.ts +161 -94
- package/.pi/harnesses/agent-hub/version.ts +18 -0
- package/.pi/harnesses/ask-user-remote/README.md +2 -0
- package/.pi/harnesses/coms/README.md +21 -0
- package/.pi/harnesses/coms/index.ts +2 -0
- package/.pi/harnesses/coms/package.json +5 -4
- package/.pi/harnesses/coms/version.ts +18 -0
- package/.pi/harnesses/damage-control-continue/README.md +32 -31
- package/.pi/harnesses/damage-control-continue/index.ts +23 -9
- package/.pi/harnesses/damage-control-continue/package.json +5 -4
- package/.pi/harnesses/damage-control-continue/version.ts +18 -0
- package/.pi/harnesses/{damage-control/shared.ts → lib/damage-control-shared.ts} +20 -6
- package/.pi/prompts/doctor-agent-fleet.md +1 -1
- package/.pi/prompts/setup-agent-fleet.md +5 -5
- package/.versions/0.0.4/.claude/commands/build.md +44 -0
- package/.versions/0.0.4/.claude/commands/code-simplify.md +22 -0
- package/.versions/0.0.4/.claude/commands/design-agent.md +14 -0
- package/.versions/0.0.4/.claude/commands/doctor-agent-fleet.md +17 -0
- package/.versions/0.0.4/.claude/commands/orchestrate.md +112 -0
- package/.versions/0.0.4/.claude/commands/plan.md +16 -0
- package/.versions/0.0.4/.claude/commands/prime.md +22 -0
- package/.versions/0.0.4/.claude/commands/review.md +16 -0
- package/.versions/0.0.4/.claude/commands/setup-agent-fleet.md +25 -0
- package/.versions/0.0.4/.claude/commands/ship.md +72 -0
- package/.versions/0.0.4/.claude/commands/spec.md +15 -0
- package/.versions/0.0.4/.claude/commands/test.md +19 -0
- package/.versions/0.0.4/.claude/commands/webperf.md +32 -0
- package/.versions/0.0.4/.claude/orchestrate-teams.yaml +24 -0
- package/.versions/0.0.4/.opencode/commands/af-build.md +17 -0
- package/.versions/0.0.4/.opencode/commands/af-code-simplify.md +16 -0
- package/.versions/0.0.4/.opencode/commands/af-compound.md +16 -0
- package/.versions/0.0.4/.opencode/commands/af-design-agent.md +15 -0
- package/.versions/0.0.4/.opencode/commands/af-doctor-agent-fleet.md +17 -0
- package/.versions/0.0.4/.opencode/commands/af-orchestrate.md +112 -0
- package/.versions/0.0.4/.opencode/commands/af-plan.md +16 -0
- package/.versions/0.0.4/.opencode/commands/af-prime.md +22 -0
- package/.versions/0.0.4/.opencode/commands/af-review.md +15 -0
- package/.versions/0.0.4/.opencode/commands/af-setup-agent-fleet.md +15 -0
- package/.versions/0.0.4/.opencode/commands/af-ship.md +16 -0
- package/.versions/0.0.4/.opencode/commands/af-spec.md +16 -0
- package/.versions/0.0.4/.opencode/commands/af-test.md +21 -0
- package/.versions/0.0.4/.opencode/commands/af-webperf.md +32 -0
- package/.versions/0.0.4/.opencode/orchestrate-teams.yaml +24 -0
- package/.versions/0.0.4/.pi/agents/dispatch-policy.yaml +32 -0
- package/.versions/0.0.4/.pi/agents/model-profiles.yaml +20 -0
- package/.versions/0.0.4/.pi/agents/peers.yaml +146 -0
- package/.versions/0.0.4/.pi/agents/teams.yaml +39 -0
- package/.versions/0.0.4/.pi/damage-control-rules.yaml +297 -0
- package/.versions/0.0.4/.pi/extensions/agent-fleet-update-check/README.md +58 -0
- package/.versions/0.0.4/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
- package/{.pi/harnesses/damage-control → .versions/0.0.4/.pi/extensions/agent-fleet-update-check}/package.json +1 -1
- package/.versions/0.0.4/.pi/extensions/btw/README.md +118 -0
- package/.versions/0.0.4/.pi/extensions/btw/index.ts +917 -0
- package/.versions/0.0.4/.pi/extensions/btw/package.json +6 -0
- package/.versions/0.0.4/.pi/extensions/btw/state.js +179 -0
- package/.versions/0.0.4/.pi/extensions/chrome-devtools-mcp/README.md +58 -0
- package/.versions/0.0.4/.pi/extensions/chrome-devtools-mcp/index.ts +92 -0
- package/.versions/0.0.4/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
- package/.versions/0.0.4/.pi/extensions/compact-and-continue/README.md +42 -0
- package/.versions/0.0.4/.pi/extensions/compact-and-continue/index.ts +120 -0
- package/.versions/0.0.4/.pi/extensions/compact-and-continue/package.json +6 -0
- package/.versions/0.0.4/.pi/extensions/mcp-bridge/README.md +46 -0
- package/.versions/0.0.4/.pi/extensions/mcp-bridge/index.ts +206 -0
- package/.versions/0.0.4/.pi/extensions/mcp-bridge/package.json +6 -0
- package/.versions/0.0.4/.pi/extensions/package-lock.json +1143 -0
- package/.versions/0.0.4/.pi/extensions/package.json +9 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/README.md +201 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/config.ts +198 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/index.ts +248 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/package.json +6 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/providers.ts +214 -0
- package/.versions/0.0.4/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/README.md +798 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/access-approval.ts +135 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/artifacts.js +92 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/backend-policy.js +153 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/delegate.ts +386 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/drift-watchdog.js +165 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/footer.ts +29 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/helpers.ts +214 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/index.ts +8045 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/monitor-session-bridge.ts +11 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/package.json +7 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/research-retention.js +34 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/return-contract.js +215 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/run-budget.js +155 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/scope-gate.js +103 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/spawn.ts +246 -0
- package/.versions/0.0.4/.pi/harnesses/agent-hub/version.ts +18 -0
- package/.versions/0.0.4/.pi/harnesses/ask-user-remote/README.md +18 -0
- package/.versions/0.0.4/.pi/harnesses/ask-user-remote/index.ts +293 -0
- package/.versions/0.0.4/.pi/harnesses/ask-user-remote/race-core.js +106 -0
- package/.versions/0.0.4/.pi/harnesses/coms/README.md +92 -0
- package/.versions/0.0.4/.pi/harnesses/coms/index.ts +1745 -0
- package/.versions/0.0.4/.pi/harnesses/coms/package.json +7 -0
- package/.versions/0.0.4/.pi/harnesses/coms/version.ts +18 -0
- package/.versions/0.0.4/.pi/harnesses/damage-control-continue/README.md +117 -0
- package/.versions/0.0.4/.pi/harnesses/damage-control-continue/index.ts +536 -0
- package/.versions/0.0.4/.pi/harnesses/damage-control-continue/package.json +7 -0
- package/.versions/0.0.4/.pi/harnesses/damage-control-continue/version.ts +18 -0
- package/.versions/0.0.4/.pi/harnesses/lib/damage-control-shared.ts +197 -0
- package/.versions/0.0.4/.pi/harnesses/lib/herdr-client.ts +458 -0
- package/.versions/0.0.4/.pi/harnesses/lib/herdr-presence.ts +288 -0
- package/.versions/0.0.4/.pi/harnesses/package-lock.json +35 -0
- package/.versions/0.0.4/.pi/harnesses/package.json +9 -0
- package/.versions/0.0.4/.pi/prompts/build.md +24 -0
- package/.versions/0.0.4/.pi/prompts/code-simplify.md +22 -0
- package/.versions/0.0.4/.pi/prompts/doctor-agent-fleet.md +15 -0
- package/.versions/0.0.4/.pi/prompts/plan.md +16 -0
- package/.versions/0.0.4/.pi/prompts/review.md +16 -0
- package/.versions/0.0.4/.pi/prompts/setup-agent-fleet.md +27 -0
- package/.versions/0.0.4/.pi/prompts/ship.md +17 -0
- package/.versions/0.0.4/.pi/prompts/spec.md +15 -0
- package/.versions/0.0.4/.pi/prompts/test.md +19 -0
- package/.versions/0.0.4/.pi/skills/bowser/SKILL.md +145 -0
- package/.versions/0.0.4/.version +1 -0
- package/.versions/0.0.4/agents/architect.md +23 -0
- package/.versions/0.0.4/agents/bowser.md +26 -0
- package/.versions/0.0.4/agents/builder.md +53 -0
- package/.versions/0.0.4/agents/code-reviewer.md +205 -0
- package/.versions/0.0.4/agents/deep-researcher.md +31 -0
- package/.versions/0.0.4/agents/documenter.md +18 -0
- package/.versions/0.0.4/agents/orchestrator.md +54 -0
- package/.versions/0.0.4/agents/plan-reviewer.md +60 -0
- package/.versions/0.0.4/agents/planner.md +69 -0
- package/.versions/0.0.4/agents/releaser.md +24 -0
- package/.versions/0.0.4/agents/researcher.md +28 -0
- package/.versions/0.0.4/agents/security-auditor.md +166 -0
- package/.versions/0.0.4/agents/test-engineer.md +151 -0
- package/.versions/0.0.4/agents/web-debugger.md +42 -0
- package/.versions/0.0.4/agents/web-performance-auditor.md +192 -0
- package/.versions/0.0.4/codex/CONDUCTOR.md +148 -0
- package/.versions/0.0.4/docs/ARCHITECTURE.md +210 -0
- package/.versions/0.0.4/docs/agent-fleet-setup.md +366 -0
- package/.versions/0.0.4/docs/claude-code-coms-bridge.md +103 -0
- package/.versions/0.0.4/docs/codex-remote-conductor.md +170 -0
- package/.versions/0.0.4/docs/coms-hermes-bridge.md +121 -0
- package/.versions/0.0.4/docs/getting-started.md +183 -0
- package/.versions/0.0.4/docs/npm-install.md +337 -0
- package/.versions/0.0.4/docs/opencode-setup.md +248 -0
- package/.versions/0.0.4/docs/pi-extensions.md +288 -0
- package/.versions/0.0.4/docs/pi-setup.md +463 -0
- package/.versions/0.0.4/docs/skill-anatomy.md +150 -0
- package/.versions/0.0.4/hermes/README.md +228 -0
- package/.versions/0.0.4/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
- package/.versions/0.0.4/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-cap.test.py +15 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-discovery.test.py +19 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-envelope.test.py +13 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-forged-owner.test.py +11 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-lease-list.test.py +9 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-multihub.test.py +17 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter-output.test.py +34 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +151 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter.test.py +39 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/plugin-api-validation.test.py +12 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
- package/.versions/0.0.4/hermes/plugins/agent-fleet-monitor/dashboard/review-live-wiring.red.test.py +22 -0
- package/.versions/0.0.4/hermes/skills/hub-conductor/SKILL.md +84 -0
- package/.versions/0.0.4/hermes/skills/hub-liaison/SKILL.md +84 -0
- package/.versions/0.0.4/hooks/SIMPLIFY-IGNORE.md +90 -0
- package/.versions/0.0.4/hooks/coms-stop-hook.mjs +73 -0
- package/.versions/0.0.4/hooks/hooks.json +14 -0
- package/.versions/0.0.4/hooks/session-start.sh +74 -0
- package/.versions/0.0.4/hooks/simplify-ignore.sh +302 -0
- package/.versions/0.0.4/justfile +256 -0
- package/.versions/0.0.4/references/accessibility-checklist.md +160 -0
- package/.versions/0.0.4/references/definition-of-done.md +67 -0
- package/.versions/0.0.4/references/fleet-coordination-patterns.md +151 -0
- package/.versions/0.0.4/references/observability-checklist.md +91 -0
- package/.versions/0.0.4/references/orchestration-patterns.md +370 -0
- package/.versions/0.0.4/references/performance-checklist.md +153 -0
- package/.versions/0.0.4/references/prompting-patterns.md +380 -0
- package/.versions/0.0.4/references/security-checklist.md +179 -0
- package/.versions/0.0.4/references/testing-patterns.md +236 -0
- package/.versions/0.0.4/scripts/codex-conductor.ts +41 -0
- package/.versions/0.0.4/scripts/codex-remote-control.ts +167 -0
- package/.versions/0.0.4/scripts/coms-claude-bridge.ts +286 -0
- package/.versions/0.0.4/scripts/coms-cli.ts +484 -0
- package/.versions/0.0.4/scripts/coms-hermes-bridge.ts +403 -0
- package/.versions/0.0.4/scripts/hermes-monitor-capability-runner.ts +25 -0
- package/.versions/0.0.4/scripts/hermes-monitor-scenario.ts +7 -0
- package/.versions/0.0.4/scripts/lib/claude-bridge-core.ts +100 -0
- package/.versions/0.0.4/scripts/lib/codex-conductor.ts +88 -0
- package/.versions/0.0.4/scripts/lib/codex-remote-control.ts +480 -0
- package/.versions/0.0.4/scripts/lib/coms-envelope.ts +539 -0
- package/.versions/0.0.4/scripts/lib/fake-herdr-server.ts +88 -0
- package/.versions/0.0.4/scripts/lib/herdr-layout.ts +263 -0
- package/.versions/0.0.4/scripts/lib/hermes-bridge-core.ts +238 -0
- package/.versions/0.0.4/scripts/lib/hermes-monitor-herdr.ts +28 -0
- package/.versions/0.0.4/scripts/lib/hermes-monitor-model.ts +9 -0
- package/.versions/0.0.4/scripts/lib/hermes-monitor-registry.ts +6 -0
- package/.versions/0.0.4/scripts/lib/hermes-monitor-socket.ts +118 -0
- package/.versions/0.0.4/scripts/lib/hermes-monitor-store.ts +31 -0
- package/.versions/0.0.4/scripts/lib/persona-banner.ts +62 -0
- package/.versions/0.0.4/scripts/lib/spawn-stagger.ts +101 -0
- package/.versions/0.0.4/scripts/lib/team-project.ts +184 -0
- package/.versions/0.0.4/scripts/lib/team-snapshot.ts +147 -0
- package/.versions/0.0.4/scripts/peer-banner.ts +40 -0
- package/.versions/0.0.4/scripts/team-snapshot.ts +238 -0
- package/.versions/0.0.4/scripts/team-up.ts +333 -0
- package/.versions/0.0.4/skills/_internal/grilling.md +11 -0
- package/.versions/0.0.4/skills/browser-testing-with-devtools/SKILL.md +352 -0
- package/.versions/0.0.4/skills/code-review-and-quality/SKILL.md +381 -0
- package/.versions/0.0.4/skills/compound-learning/SKILL.md +137 -0
- package/.versions/0.0.4/skills/context-engineering/SKILL.md +291 -0
- package/.versions/0.0.4/skills/deprecation-and-migration/SKILL.md +206 -0
- package/.versions/0.0.4/skills/designing-agents/SKILL.md +394 -0
- package/.versions/0.0.4/skills/designing-agents/pi-harness-authoring.md +222 -0
- package/.versions/0.0.4/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/0.0.4/skills/git-workflow-and-versioning/SKILL.md +316 -0
- package/.versions/0.0.4/skills/guided-workspace-setup/SKILL.md +535 -0
- package/.versions/0.0.4/skills/guided-workspace-setup/companion-manifest.json +33 -0
- package/.versions/0.0.4/skills/idea-refine/SKILL.md +182 -0
- package/.versions/0.0.4/skills/idea-refine/examples.md +238 -0
- package/.versions/0.0.4/skills/idea-refine/frameworks.md +99 -0
- package/.versions/0.0.4/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/0.0.4/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/0.0.4/skills/incremental-implementation/SKILL.md +287 -0
- package/.versions/0.0.4/skills/interview-me/SKILL.md +226 -0
- package/.versions/0.0.4/skills/orchestration-verification/SKILL.md +181 -0
- package/.versions/0.0.4/skills/peer-coms/SKILL.md +90 -0
- package/.versions/0.0.4/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/0.0.4/skills/planning-and-task-breakdown/SKILL.md +236 -0
- package/.versions/0.0.4/skills/security-and-hardening/SKILL.md +461 -0
- package/.versions/0.0.4/skills/spec-driven-development/SKILL.md +245 -0
- package/.versions/0.0.4/skills/using-agent-skills/SKILL.md +199 -0
- package/.versions/0.0.4/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/LICENSE +21 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/README.md +11 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
- package/.versions/0.0.4/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
- package/CHANGELOG.md +53 -0
- package/README.md +103 -541
- package/agents/architect.md +1 -1
- package/agents/builder.md +1 -1
- package/agents/code-reviewer.md +1 -1
- package/agents/deep-researcher.md +3 -3
- package/agents/orchestrator.md +20 -11
- package/agents/plan-reviewer.md +3 -3
- package/agents/planner.md +1 -1
- package/agents/security-auditor.md +1 -1
- package/agents/test-engineer.md +11 -4
- package/bin/lib/validate-overrides.js +19 -0
- package/bin/snapshot-version.js +17 -1
- package/bin/sync-harness-versions.js +94 -0
- package/codex/CONDUCTOR.md +148 -0
- package/docs/ARCHITECTURE.md +210 -0
- package/docs/agent-fleet-setup.md +11 -0
- package/docs/claude-code-coms-bridge.md +10 -0
- package/docs/codex-remote-conductor.md +170 -0
- package/docs/coms-hermes-bridge.md +121 -0
- package/docs/getting-started.md +14 -0
- package/docs/npm-install.md +2 -0
- package/docs/pi-extensions.md +49 -14
- package/docs/pi-setup.md +12 -4
- package/hermes/README.md +228 -0
- package/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
- package/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-cap.test.py +15 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-discovery.test.py +19 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-envelope.test.py +13 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-forged-owner.test.py +11 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-lease-list.test.py +9 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-multihub.test.py +17 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter-output.test.py +34 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +151 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/adapter.test.py +39 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/dist/index.js +10 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/plugin-api-validation.test.py +12 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
- package/hermes/plugins/agent-fleet-monitor/dashboard/review-live-wiring.red.test.py +22 -0
- package/hermes/skills/hub-conductor/SKILL.md +84 -0
- package/hermes/skills/hub-liaison/SKILL.md +84 -0
- package/justfile +106 -23
- package/package.json +17 -5
- package/scripts/codex-conductor.ts +41 -0
- package/scripts/codex-remote-control.ts +167 -0
- package/scripts/coms-cli.ts +311 -199
- package/scripts/coms-hermes-bridge.ts +2 -2
- package/scripts/lib/codex-conductor.ts +88 -0
- package/scripts/lib/codex-remote-control.ts +480 -0
- package/scripts/lib/coms-envelope.ts +51 -6
- package/scripts/lib/fake-herdr-server.ts +88 -0
- package/scripts/lib/herdr-layout.ts +18 -3
- package/scripts/lib/hermes-bridge-core.ts +4 -4
- package/scripts/lib/hermes-monitor-herdr.ts +28 -0
- package/scripts/lib/hermes-monitor-model.ts +9 -0
- package/scripts/lib/hermes-monitor-registry.ts +6 -0
- package/scripts/lib/hermes-monitor-socket.ts +118 -0
- package/scripts/lib/hermes-monitor-store.ts +31 -0
- package/scripts/lib/team-project.ts +85 -1
- package/scripts/team-up.ts +77 -18
- package/skills/designing-agents/SKILL.md +2 -2
- package/skills/designing-agents/pi-harness-authoring.md +26 -13
- package/skills/guided-workspace-setup/SKILL.md +131 -102
- package/skills/guided-workspace-setup/companion-manifest.json +33 -0
- package/skills/peer-coms/SKILL.md +9 -0
- package/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
- package/.pi/harnesses/damage-control/README.md +0 -65
- package/.pi/harnesses/damage-control/index.ts +0 -250
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { safeAgentKey } from "./helpers.ts";
|
|
3
|
+
|
|
4
|
+
export function monitorKeyForAgent(name:string,runCount:number){return`${safeAgentKey(name)}:${runCount}`;}
|
|
5
|
+
export function cancelLocalOwnedProcess(input:any){try{void Promise.resolve(input.monitorBridge?.markCancelling(input.monitorKey)).catch(()=>{});}catch{}input.treeKill(input.process);}
|
|
6
|
+
export async function cancelLocalWaitOnly(input:any){input.abort?.();try{await input.monitorBridge?.cancelWaitOnly(input.monitorKey,input.event);}catch{}}
|
|
7
|
+
export function linuxProcessIdentity(proc:any){try{if(!Number.isInteger(proc?.pid)||proc.pid<=0)return null;const stat=fs.readFileSync(`/proc/${proc.pid}/stat`,"utf8");const close=stat.lastIndexOf(")");const fields=stat.slice(close+2).trim().split(/\s+/);const starttime=fields[19];return starttime?{pid:proc.pid,starttime}:null;}catch{return null;}}
|
|
8
|
+
export function createOwnedHandleRegistry(deps:any={}) { const handles=new Map<string,any>(); const treeKill=deps.treeKill??((proc:any,signal:string)=>deps.signal?.(proc.pid,signal)), wait=deps.wait??(async()=>false), identity=deps.identity??linuxProcessIdentity; const graceMs=deps.graceMs??5000,setTimer=deps.setTimeout??setTimeout,clearTimer=deps.clearTimeout??clearTimeout;const observe=(p:any,exit:any)=>new Promise<boolean>(resolve=>{let done=false;let timer:any;const finish=(value:boolean)=>{if(done)return;done=true;if(timer!==undefined)clearTimer(timer);resolve(value);};timer=setTimer(()=>finish(false),graceMs);Promise.resolve(wait(p,exit)).then(value=>finish(!!value)).catch(()=>finish(false));});const same=(p:any,expected:any)=>{const current=identity(p);return !!current&¤t.pid===expected.pid&¤t.starttime===expected.starttime;}; return {register(v:any){const processIdentity=identity(v.process);const handle=`${v.profileKey}:${v.taskId}:${v.generation}`;handles.set(handle,{...v,processIdentity,cancelPromise:null});return handle},cancel(r:any){const v=handles.get(r.handle);if(!v)return Promise.resolve({cancelled:false,reason:"unauthorized"});if(v.profileKey!==r.profileKey||v.token!==r.token||v.taskId!==r.taskId)return Promise.resolve({cancelled:false,reason:"unauthorized"});if(v.generation!==r.generation)return Promise.resolve({cancelled:false,reason:"stale_generation"});if(v.cancelPromise)return v.cancelPromise;v.cancelPromise=(async()=>{const proc=v.process;if(!v.processIdentity||!same(proc,v.processIdentity))return{cancelled:false,reason:"stale_identity"};treeKill(proc,"SIGTERM");if(await observe(proc,v.exitPromise)){handles.delete(r.handle);return{cancelled:true,state:"cancelled"};}if(!same(proc,v.processIdentity))return{cancelled:false,reason:"stale_identity"};treeKill(proc,"SIGKILL");if(!(await observe(proc,v.exitPromise)))return{cancelled:false,reason:"exit_not_observed"};handles.delete(r.handle);return{cancelled:true,state:"cancelled"};})();return v.cancelPromise;}} }
|
|
9
|
+
export function recordWaitOnlyCancellation(r:any){return{state:"cancelled",history:r.lateEvent?[r.lateEvent]:[]}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { MonitorSocketServer } from "../../../scripts/lib/hermes-monitor-socket.ts";
|
|
3
|
+
import { createOwnedHandleRegistry, recordWaitOnlyCancellation } from "./monitor-control.ts";
|
|
4
|
+
export interface MonitorLifecycleConfig { runtimeDir:string; profileId:string; profilePath:string; }
|
|
5
|
+
export function monitorLifecycleConfig(env:NodeJS.ProcessEnv):MonitorLifecycleConfig|null{const profileId=env.AGENT_FLEET_PROFILE_ID,runtimeDir=env.AGENT_FLEET_MONITOR_RUNTIME_DIR;if(!profileId||!runtimeDir||!path.isAbsolute(runtimeDir)||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(profileId)||profileId.includes(".."))return null;return{runtimeDir,profileId,profilePath:path.join(runtimeDir,"profiles",profileId)};}
|
|
6
|
+
export function createMonitorLifecycle(deps:any){const control=createOwnedHandleRegistry(deps),handles=new Map<string,string>(),completedCancels=new Map<string,any>(),setTimer=deps.setInterval??setInterval,clearTimer=deps.clearInterval??clearInterval;let socket:MonitorSocketServer|null=null,registration:any=null,renewTimer:any=null,reconcileTimer:any=null,retryTimer:any=null,unavailable=false,bridgeRef:any=null,bridgeInput:any=null,epoch=0;const clearRenew=()=>{if(renewTimer!==null){clearTimer(renewTimer);renewTimer=null;}if(reconcileTimer!==null){clearTimer(reconcileTimer);reconcileTimer=null;}if(retryTimer!==null){(deps.clearTimeout??clearTimeout)(retryTimer);retryTimer=null;}};const cleanup=()=>{clearRenew();registration?.cleanup?.();registration=null;};const api:any={
|
|
7
|
+
async startBridge(bridge:any,input:any){const startEpoch=epoch;bridgeRef=bridge;bridgeInput=input;const value=await api.start({...input,snapshot:()=>{bridge.prune();return bridge.snapshot();},output:(request:any)=>bridge.readOutput(request)});if(!value||startEpoch!==epoch||bridgeRef!==bridge){if(value){try{await socket?.close();}catch{}value.cleanup?.();}return null;}bridge.setCurrentOwner?.({ownerSessionId:value.ownerId,ownerLeaseExpiresAt:value.leaseExpiresAt,updateActive:true});reconcileTimer=setTimer(()=>{const probeEpoch=epoch;const reconcile=(task:any,e:any)=>{if(probeEpoch!==epoch||bridgeRef!==bridge)return;bridge.reconcile({...e,taskId:`${task.id}:${task.generation}`});};try{for(const task of bridge.snapshot?.().tasks??[]){if(probeEpoch!==epoch||bridgeRef!==bridge)break;Promise.resolve(deps.getRecoveryEvidence?.(task)??deps.reconcileEvidence?.()??{}).then(e=>reconcile(task,e)).catch(()=>reconcile(task,{transient:true}));}}catch{if(probeEpoch===epoch&&bridgeRef===bridge)bridge.reconcile({transient:true});}},30_000);value.cancel=(request:any)=>bridge.cancelTask(request);return value;},
|
|
8
|
+
lowLevelCancelOwnedGeneration(request:any){return api.cancelOwnedGeneration(request);},
|
|
9
|
+
async start(input:any){const startEpoch=epoch;try{registration=deps.registry.register(input);registration.output=input.output;registration.cancel=(request:any)=>api.cancelOwnedGeneration(request);socket=(deps.createSocketServer??((r:any)=>new MonitorSocketServer(r)))(registration);await socket.listen();if(startEpoch!==epoch){try{await socket.close();}catch{}registration?.cleanup?.();registration=null;socket=null;return null;}if(registration.renew&®istration.leaseMs){renewTimer=setTimer(()=>{try{Promise.resolve(registration?.renew()).then((renewed:any)=>{if(renewed?.leaseExpiresAt){registration.leaseExpiresAt=renewed.leaseExpiresAt;bridgeRef?.setCurrentOwner?.({ownerSessionId:registration.ownerId,ownerLeaseExpiresAt:renewed.leaseExpiresAt,updateActive:true});}}).catch(()=>api.disable());}catch{void api.disable();}},Math.max(1,Math.floor(registration.leaseMs/2)));}return registration;}catch(error:any){try{await socket?.close();}catch{}socket=null;cleanup();if(error?.leaseExpiresAt){const delay=Math.max(0,new Date(error.leaseExpiresAt).getTime()-(deps.now?.()??Date.now()));const retryEpoch=epoch;retryTimer=(deps.setTimeout??setTimeout)(()=>{retryTimer=null;if(retryEpoch!==epoch)return;void (bridgeRef?api.startBridge(bridgeRef,bridgeInput):api.start(input)).catch(()=>{});},delay);return null;}throw error;}},
|
|
10
|
+
cancelOwnedGeneration(request:any){const key=`${request.taskId}:${request.generation}`;if(completedCancels.has(key))return Promise.resolve(completedCancels.get(key));const handle=handles.get(key);if(!handle)return Promise.resolve({cancelled:false,reason:"unsupported"});return control.cancel({...request,profileKey:registration?.profileKey,token:registration?.token,handle}).then((result:any)=>{completedCancels.set(key,result);return result;});},
|
|
11
|
+
registerOwnedGeneration(value:any){const proc:any=value.process;const exitPromise=value.exitPromise??(proc?.exitCode!==null&&proc?.exitCode!==undefined?Promise.resolve(true):new Promise(resolve=>proc?.once?.("close",()=>resolve(true))));const owned={...value,exitPromise,profileKey:registration?.profileKey??value.profileKey,token:registration?.token??value.token};const handle=control.register(owned);handles.set(`${owned.taskId}:${owned.generation}`,handle);return handle;},async disable(){unavailable=true;await api.stop();},isUnavailable(){return unavailable;},isAlive(){return !!socket&&!unavailable;},recordWaitOnlyCancellation,
|
|
12
|
+
async stop(){epoch++;bridgeRef=null;bridgeInput=null;clearRenew();try{await socket?.close();}finally{socket=null;registration?.cleanup?.();registration=null;}}
|
|
13
|
+
};return api;}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateChildTaskInput,
|
|
3
|
+
type CreateParentTaskInput,
|
|
4
|
+
type MonitorTask,
|
|
5
|
+
} from "../../../scripts/lib/hermes-monitor-model.ts";
|
|
6
|
+
import { MonitorStore, type MonitorOutput } from "../../../scripts/lib/hermes-monitor-store.ts";
|
|
7
|
+
import { correlateHubPane } from "../../../scripts/lib/hermes-monitor-herdr.ts";
|
|
8
|
+
|
|
9
|
+
export interface ViewerGatedMonitor {
|
|
10
|
+
setViewers(count: number): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createViewerGatedMonitor(options: {
|
|
15
|
+
pollMetadata: () => Promise<Array<{ id: string; generation: number; outputSequence: number }>>;
|
|
16
|
+
fetchOutput: (id: string, generation: number, afterSequence: number) => Promise<{ sequence: number }>;
|
|
17
|
+
intervalMs?: number;
|
|
18
|
+
}): ViewerGatedMonitor {
|
|
19
|
+
const cursors = new Map<string, number>();
|
|
20
|
+
let viewers = 0;
|
|
21
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
22
|
+
const poll = async () => {
|
|
23
|
+
if (viewers === 0) return;
|
|
24
|
+
for (const row of await options.pollMetadata()) {
|
|
25
|
+
const key = `${row.id}:${row.generation}`;
|
|
26
|
+
const cursor = cursors.get(key) ?? 0;
|
|
27
|
+
if (row.outputSequence > cursor) cursors.set(key, (await options.fetchOutput(row.id, row.generation, cursor)).sequence);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return { setViewers(count) { viewers = Math.max(0, count); if (viewers > 0 && !timer) timer = setInterval(() => void poll(), options.intervalMs ?? 1000); if (viewers === 0 && timer) { clearInterval(timer); timer = null; } }, stop() { viewers = 0; if (timer) clearInterval(timer); timer = null; } };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Agent Fleet-owned publishing seam. Hub lifecycle wiring is added in later slices.
|
|
34
|
+
export class MonitorPublisher {
|
|
35
|
+
private readonly store: MonitorStore;
|
|
36
|
+
|
|
37
|
+
constructor(store: MonitorStore) {
|
|
38
|
+
this.store = store;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
publishParent(input: CreateParentTaskInput): MonitorTask {
|
|
42
|
+
return this.store.createParent(input);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
publishChild(input: CreateChildTaskInput): MonitorTask {
|
|
46
|
+
return this.store.createChild(input);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async publishChildForHub(input: CreateChildTaskInput, env: NodeJS.ProcessEnv = process.env): Promise<MonitorTask> {
|
|
50
|
+
const correlation = await correlateHubPane(env);
|
|
51
|
+
return this.publishChild({ ...input, workspaceId: correlation.workspaceId ?? input.workspaceId, hubPaneId: correlation.hubPaneId ?? input.hubPaneId });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
transition(id: string, generation: number, state: any): MonitorTask { return this.store.transition(id, generation, state); }
|
|
55
|
+
|
|
56
|
+
publishPublicOutput(id: string, generation: number, text: string): MonitorOutput {
|
|
57
|
+
return this.store.appendPublicOutput(id, generation, text);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
export function stableMonitorHubId(input:{profileId:string;checkout:string;workspaceId?:string;paneId?:string}){if(!input.workspaceId||!input.paneId)throw new Error("monitor recovery requires Herdr workspace and pane identity");return crypto.createHash("sha256").update(`${input.profileId}\0${input.checkout}\0${input.workspaceId}\0${input.paneId}`).digest("hex");}
|
|
3
|
+
export async function monitorReconcileEvidence(input:any){try{const owner=input.owner??!!input.registry?.owns?.(input.hubId);const socket=input.socket??!!input.socketServer?.alive?.();const session=input.session??input.currentHubId===input.hubId;const pane=await input.herdr?.pane?.get?.(input.paneId);const workspace=await input.herdr?.workspace?.get?.(input.workspaceId);return{owner:!!owner,socket:!!socket,session:!!session,herdr:!!pane&&!!workspace};}catch{return{owner:!!input.owner,socket:!!input.socket,session:!!input.session,herdr:true,transient:true};}}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";import * as fs from "node:fs";import * as path from "node:path";
|
|
2
|
+
const key=(v:string)=>crypto.createHash("sha256").update(v).digest("hex");const ownedDir=(p:string)=>{const s=fs.lstatSync(p);if(s.isSymbolicLink()||!s.isDirectory()||(s.mode&0o777)!==0o700)throw Error("unsafe monitor runtime");};const safe=(v:string)=>/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(v)&&!v.includes("..");
|
|
3
|
+
export class MonitorRuntime {path:string;private now:()=>Date;constructor(o:any){if(!path.isAbsolute(o.runtimeDir)||!safe(o.profileId)||!safe(o.hubInstanceId))throw Error("unsafe monitor runtime");this.now=o.now??(()=>new Date());fs.mkdirSync(o.runtimeDir,{recursive:true,mode:0o700});ownedDir(o.runtimeDir);const journal=path.join(o.runtimeDir,"journal");fs.mkdirSync(journal,{recursive:true,mode:0o700});ownedDir(journal);const dir=path.join(journal,key(o.profileId));fs.mkdirSync(dir,{recursive:true,mode:0o700});ownedDir(dir);this.path=path.join(dir,`${key(o.hubInstanceId)}.json`);}save(state:any){const clean={tasks:(state.tasks??[]).map((t:any)=>({...t,output:String(t.output??"").slice(-8192),lateHistory:(t.lateHistory??[]).slice(-200)}))};const dir=path.dirname(this.path);ownedDir(dir);const tmp=path.join(dir,`.${path.basename(this.path)}.${crypto.randomUUID()}.tmp`);let fd:number|undefined;try{fd=fs.openSync(tmp,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_NOFOLLOW,0o600);fs.writeFileSync(fd,JSON.stringify(clean));fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;fs.renameSync(tmp,this.path);try{const dfd=fs.openSync(dir,fs.constants.O_RDONLY);fs.fsyncSync(dfd);fs.closeSync(dfd);}catch{}}finally{if(fd!==undefined)try{fs.closeSync(fd)}catch{};try{fs.unlinkSync(tmp)}catch{}}}load(){if(!fs.existsSync(this.path))return{tasks:[]};const st=fs.lstatSync(this.path);if(st.isSymbolicLink()||!st.isFile()||(st.mode&0o777)!==0o600)throw Error("unsafe monitor journal");try{const v=JSON.parse(fs.readFileSync(this.path,"utf8"));if(!Array.isArray(v.tasks))throw Error();return v;}catch{throw Error("unsafe monitor journal");}}reconcile(state:any,e:any){return{...state,tasks:(state.tasks??[]).map((t:any)=>{const lease=Date.parse(t.ownerLeaseExpiresAt??"");const expiry=Number.isFinite(lease)?lease:Date.parse(t.updatedAt??"")+30_000;const expired=this.now().getTime()>=expiry;return expired&&["starting","running","cancelling"].includes(t.state)&&!e.owner&&!e.socket&&!e.session&&!e.herdr?{...t,state:"orphaned"}:t;})};}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MonitorStore } from '../../../scripts/lib/hermes-monitor-store.ts'; import { MonitorPublisher } from './monitor-publisher.ts';
|
|
2
|
+
const terminal=(state:any)=>["completed","blocked","failed","cancelled","orphaned","done"].includes(state);
|
|
3
|
+
export function createMonitorSessionBridge(deps:any={}){const store=deps.store??new MonitorStore({now:deps.now}),pub=deps.publisher??new MonitorPublisher(store),keys=new Map(),ready=new Map(),late=new Map(),finalized=new Map(),cancellable=new Set(),waitAborts=new Map(),recovering=new Map(),monitorKeyByTask=new Map(),lateByGeneration=new Map();let currentOwner:any=deps.currentOwner??{};const runtime=deps.runtime;try{if(runtime){const restored=runtime.load().tasks??[];store.restore(restored);for(const task of restored){if(task.monitorKey){const id=`${task.id}:${task.generation}`;monitorKeyByTask.set(id,task.monitorKey);if(task.lateHistory)lateByGeneration.set(`${task.monitorKey}:${task.generation}`,task.lateHistory);const prior=keys.get(task.monitorKey);if(!prior||prior.generation<task.generation){keys.set(task.monitorKey,{id:task.id,generation:task.generation});ready.set(task.monitorKey,Promise.resolve(task));}}}}}catch(error){throw error}const persist=()=>runtime?.save({tasks:(store.durableSnapshot?.().tasks??records()).map((task:any)=>({...task,monitorKey:monitorKeyByTask.get(`${task.id}:${task.generation}`),lateHistory:lateByGeneration.get(`${monitorKeyByTask.get(`${task.id}:${task.generation}`)}:${task.generation}`)??[]}))});const records=()=>store.snapshot().tasks as any[];const lateEvent=(key:string,event:any,generation?:number)=>{generation??=keys.get(key)?.generation;const lateKey=generation===undefined?key:`${key}:${generation}`;const h=lateByGeneration.get(lateKey)??[];h.push(event);if(h.length>200)h.splice(0,h.length-200);lateByGeneration.set(lateKey,h);late.set(key,h);persist();return{state:'cancelled',history:h};};const after=(key:string,work:(v:any)=>any)=>{const pending=ready.get(key);if(!pending)return Promise.reject(new Error(`child ${key} is not registered`));const chained=pending.then(()=>{const v:any=keys.get(key);return work(v);}).then(value=>{persist();return value;});ready.set(key,chained.catch(()=>undefined));return chained;};return{
|
|
4
|
+
setCurrentOwner(owner:any){currentOwner={...owner};if(owner.updateActive){for(const task of records())if(!terminal(task.state)){if(!task.ownerSessionId)store.patch(task.id,task.generation,{ownerSessionId:owner.ownerSessionId,ownerLeaseExpiresAt:owner.ownerLeaseExpiresAt});else if(task.ownerSessionId===owner.ownerSessionId)store.patch(task.id,task.generation,{ownerLeaseExpiresAt:owner.ownerLeaseExpiresAt});}persist();}}, startParent(v:any){const task=pub.publishParent({...v,...currentOwner,generation:v.generation??1});keys.set(`parent:${task.id}`,{id:task.id,generation:task.generation});monitorKeyByTask.set(`${task.id}:${task.generation}`,`parent:${task.id}`);persist();return task},
|
|
5
|
+
startChild(v:any,env:any){const existing=ready.get(v.key);if(existing){const prior:any=keys.get(v.key),task=prior&&store.get(prior.id,prior.generation);if(!task||!["completed","blocked","failed","cancelled","orphaned","recovering"].includes(task.state))return existing;v={...v,generation:prior.generation+1};ready.delete(v.key);}const pending=Promise.resolve().then(()=>pub.publishChildForHub({...v,...currentOwner,parentGeneration:v.parentGeneration??1},env)).then((task:any)=>{keys.set(v.key,{id:task.id,generation:task.generation});monitorKeyByTask.set(`${task.id}:${task.generation}`,v.key);persist();return {...task,monitorKey:v.key};});ready.set(v.key,pending);pending.catch(()=>ready.delete(v.key));return pending;},
|
|
6
|
+
appendOutputFor(v:any,text:string){const task=store.get(v.id,v.generation);if(!task||terminal(task.state))return lateEvent(monitorKeyByTask.get(`${v.id}:${v.generation}`)??v.monitorKey,{kind:'late_output',text},v.generation);const result=pub.publishPublicOutput(v.id,v.generation,text);persist();return result;},finalizeChildFor(v:any,output:string,state:any){const id=`${v.id}:${v.generation}`,prior=finalized.get(id);if(prior)return prior;const task=store.get(v.id,v.generation),key=monitorKeyByTask.get(id)??v.monitorKey;if(!task||terminal(task.state))return lateEvent(key,{kind:'late_final',output,state},v.generation);const result=Promise.resolve().then(()=>{if(output)pub.publishPublicOutput(v.id,v.generation,output);const done=pub.transition(v.id,v.generation,state);persist();return done;});finalized.set(id,result);return result;},registerOwnedProcessFor(v:any,p:unknown){const key=v.monitorKey??monitorKeyByTask.get(`${v.id}:${v.generation}`);cancellable.add(key);return deps.registerOwnedProcess?.(key,p,v);},cancelFor(v:any){return this.cancelTask({taskId:v.id,generation:v.generation});},registerOwnedProcess(key:string,p:unknown){return after(key,(v:any)=>{cancellable.add(key);return deps.registerOwnedProcess?.(key,p,v);});},registerWaitOnly(key:string,abort?:()=>unknown){return after(key,()=>{cancellable.add(key);if(abort)waitAborts.set(key,abort);});},
|
|
7
|
+
appendOutput(key:string,text:string){return after(key,(v:any)=>{const task=store.get(v.id,v.generation);if(terminal(task?.state))return lateEvent(key,{kind:'late_output',text});return pub.publishPublicOutput(v.id,v.generation,text);});},
|
|
8
|
+
finishChild(key:string,state:any){return after(key,(v:any)=>{const task=store.get(v.id,v.generation);if(terminal(task?.state))return task?.state==='cancelled'||task?.state==='orphaned'?lateEvent(key,{kind:'late_finish',state}):task;return pub.transition(v.id,v.generation,state);});},
|
|
9
|
+
finalizeChild(key:string,output:string,state:any){const prior=finalized.get(key);if(prior)return prior;const result=after(key,async(v:any)=>{const task=store.get(v.id,v.generation);if(terminal(task?.state))return task?.state==='cancelled'||task?.state==='orphaned'?lateEvent(key,{kind:'late_final',output,state}):task;if(output)pub.publishPublicOutput(v.id,v.generation,output);return pub.transition(v.id,v.generation,state);});finalized.set(key,result);return result;},recordComsFinal(key:string,text:string){return this.appendOutput(key,text);},
|
|
10
|
+
markCancelling(key:string){return after(key,(v:any)=>{const task=store.get(v.id,v.generation);return terminal(task?.state)?task:pub.transition(v.id,v.generation,'cancelling');});},markCancelled(key:string){return after(key,(v:any)=>{const task=store.get(v.id,v.generation);return task?.state==='cancelled'?task:pub.transition(v.id,v.generation,'cancelled');});},async cancelOwnedProcess(key:string){return after(key,async(v:any)=>{const task=store.get(v.id,v.generation);if(task?.state==='cancelled')return{cancelled:true,state:'cancelled'};if(!terminal(task?.state))pub.transition(v.id,v.generation,'cancelling');const result=await deps.cancelOwnedProcess?.({taskId:v.id,generation:v.generation});if(result?.cancelled&&!terminal(store.get(v.id,v.generation)?.state))pub.transition(v.id,v.generation,'cancelled');if(result?.cancelled)cancellable.delete(key);return result??{cancelled:false,reason:'unsupported'};});},
|
|
11
|
+
cancelAllWaitOnly(){return Promise.all([...waitAborts.keys()].map(key=>this.cancelWaitOnly(key,{kind:'session_reset'})));},cancelWaitOnly(key:string,event:unknown){return after(key,async(v:any)=>{await waitAborts.get(key)?.();const task=store.get(v.id,v.generation);if(!terminal(task?.state))pub.transition(v.id,v.generation,'cancelled');cancellable.delete(key);waitAborts.delete(key);return lateEvent(key,event);});},cancelTask(request:any){const entry=[...keys.entries()].find(([,v]:any)=>v.id===request.taskId&&v.generation===request.generation);if(!entry)return Promise.resolve({cancelled:false,reason:'unsupported'});const [key]=entry;return waitAborts.has(key)?this.cancelWaitOnly(key,{kind:'operator_cancel'}).then(()=>({cancelled:true,state:'cancelled'})):this.cancelOwnedProcess(key);},recordComsLateEvent(key:string,event:unknown){return lateEvent(key,event);},readOutput(r:any){return store.readOutput(r.taskId,r.generation,r.afterSequence)},prune(){const value=store.prune();persist();return value},reconcile(e:any){for(const task of records()){if(e?.taskId&&`${task.id}:${task.generation}`!==e.taskId)continue;const old=task.ownerSessionId&&task.ownerSessionId!==currentOwner.ownerSessionId;if(["completed","blocked","failed","cancelled","orphaned"].includes(task.state))continue;if(old&&(deps.now?.().getTime?.()??Date.now())<Date.parse(task.ownerLeaseExpiresAt??"")){if(task.state!=="recovering"){recovering.set(`${task.id}:${task.generation}`,task.state);pub.transition(task.id,task.generation,"recovering");}continue;}if(old&&e?.oldOwner===false&&e?.oldSocket===false&&e?.oldSession===false&&e?.oldHerdr===false){pub.transition(task.id,task.generation,"orphaned");continue;}if(old)continue;if(["starting","running","cancelling","recovering"].includes(task.state)&&!e?.owner&&!e?.socket&&!e?.session&&!e?.herdr&&task.ownerLeaseExpiresAt&&(deps.now?.().getTime?.()??Date.now())<Date.parse(task.ownerLeaseExpiresAt)){if(task.state!=="recovering")recovering.set(`${task.id}:${task.generation}`,task.state);if(task.state!=="recovering")pub.transition(task.id,task.generation,"recovering");continue;}if(["starting","running","cancelling"].includes(task.state)&&e?.transient){recovering.set(`${task.id}:${task.generation}`,task.state);pub.transition(task.id,task.generation,"recovering");}else if(task.state==="recovering"&&e?.owner&&e?.socket&&e?.session&&e?.herdr)pub.transition(task.id,task.generation,recovering.get(`${task.id}:${task.generation}`)??"running");else if(["starting","running","cancelling","recovering"].includes(task.state)&&!e?.owner&&!e?.socket&&!e?.session&&!e?.herdr)pub.transition(task.id,task.generation,"orphaned");}persist();return this.snapshot();},snapshot(){persist();return{tasks:records().map((task:any)=>{const key=[...keys.entries()].find(([,v]:any)=>v.id===task.id&&v.generation===task.generation)?.[0];return{id:task.id,generation:task.generation,kind:task.kind,parentId:task.parentId,parentGeneration:task.parentGeneration,specialist:task.specialist,state:task.state,workspaceId:task.workspaceId,hubPaneId:task.hubPaneId,hubInstanceId:task.hubInstanceId,ownerSessionId:task.ownerSessionId,ownerLeaseExpiresAt:task.ownerLeaseExpiresAt,outputSequence:task.outputSequence,firstSequence:task.firstSequence,truncated:task.truncated,canCancel:!!key&&cancellable.has(key)&&!terminal(task.state)};})}},reset(){keys.clear();ready.clear();late.clear();finalized.clear();cancellable.clear();monitorKeyByTask.clear();lateByGeneration.clear();persist()},stop(){keys.clear();ready.clear();late.clear();finalized.clear();cancellable.clear();monitorKeyByTask.clear();lateByGeneration.clear()}}}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Retention policy for finished research helpers. The hub keeps every helper's
|
|
2
|
+
// card (and resumable session) in memory until something removes it; this module
|
|
3
|
+
// decides which finished helpers to drop so the research row doesn't grow without
|
|
4
|
+
// bound over a long session. Pure — the hub owns the actual state map, session
|
|
5
|
+
// files, and widget refresh.
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_RESEARCH_KEEP = 4;
|
|
8
|
+
|
|
9
|
+
// Parse the `research-keep` override value: "all" disables pruning of durable
|
|
10
|
+
// helpers, a non-negative integer keeps that many most-recently-finished ones.
|
|
11
|
+
// Returns null for anything else (caller warns and keeps the default).
|
|
12
|
+
export function parseResearchKeep(value) {
|
|
13
|
+
const v = String(value ?? "").trim().toLowerCase();
|
|
14
|
+
if (v === "all") return Infinity;
|
|
15
|
+
if (/^\d+$/.test(v)) return Number(v);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Decide which helper ids to drop. `states`: [{ id, status, finishedAt, ephemeral }].
|
|
20
|
+
// Running helpers are never dropped. Finished ephemeral helpers (auto-research
|
|
21
|
+
// pipe spawns — their findings persist as files under findings/ and their handles
|
|
22
|
+
// are never resumed) are always dropped. Finished durable helpers beyond the
|
|
23
|
+
// `keep` most recently finished are dropped, oldest first.
|
|
24
|
+
export function selectResearchPrunable(states, keep) {
|
|
25
|
+
const capped = keep >= 0 ? keep : DEFAULT_RESEARCH_KEEP;
|
|
26
|
+
const finished = (states || []).filter((s) => s.status !== "running");
|
|
27
|
+
const ephemeral = finished.filter((s) => s.ephemeral).map((s) => s.id);
|
|
28
|
+
const durable = finished
|
|
29
|
+
.filter((s) => !s.ephemeral)
|
|
30
|
+
.sort((a, b) => (b.finishedAt ?? 0) - (a.finishedAt ?? 0));
|
|
31
|
+
// slice(Infinity) → [] — "all" keeps every durable helper.
|
|
32
|
+
const overflow = durable.slice(capped).map((s) => s.id);
|
|
33
|
+
return [...ephemeral, ...overflow];
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Termination } from "./spawn.ts";
|
|
2
|
+
|
|
3
|
+
/** Spawn policy shared by every native read-only research-helper path. */
|
|
4
|
+
export function researchWatchdogSpawnOptions(timeoutMs: number | null, signal?: AbortSignal) {
|
|
5
|
+
return {
|
|
6
|
+
detached: true,
|
|
7
|
+
signal,
|
|
8
|
+
toolWatchdog: { timeoutMs },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Stable terminal result used by research lifecycle code after parent cleanup. */
|
|
13
|
+
export function researchTerminationOutcome(id: number, termination: Termination) {
|
|
14
|
+
const reason = termination.reason;
|
|
15
|
+
const tool = termination.tool;
|
|
16
|
+
const status = reason; // "tool_timeout" | "turn_timeout" | "drift_stop" | "cancelled"
|
|
17
|
+
const lastWork = reason === "tool_timeout"
|
|
18
|
+
? `tool_timeout: ${tool?.toolName || "tool"} (${tool?.toolCallId || "unknown"})`
|
|
19
|
+
: reason === "turn_timeout"
|
|
20
|
+
? "turn_timeout: per-run deadline exceeded"
|
|
21
|
+
: reason === "drift_stop"
|
|
22
|
+
? "drift_stop: stopped by the drift watchdog"
|
|
23
|
+
: "cancelled by caller";
|
|
24
|
+
const metadata = reason === "tool_timeout"
|
|
25
|
+
? `toolCallId=${tool?.toolCallId || "unknown"}, tool=${tool?.toolName || "unknown"}, deadline=${tool?.deadlineAt || "unknown"}, terminationConfirmed=${termination.confirmed}`
|
|
26
|
+
: `terminationConfirmed=${termination.confirmed}`;
|
|
27
|
+
const explanation = reason === "tool_timeout"
|
|
28
|
+
? "exceeded its per-tool watchdog"
|
|
29
|
+
: reason === "turn_timeout"
|
|
30
|
+
? "exceeded the per-run deadline (agent-turn-timeout-s / mode budget) — narrow the question or raise the deadline"
|
|
31
|
+
: reason === "drift_stop"
|
|
32
|
+
? "was stopped by the drift watchdog"
|
|
33
|
+
: "was cancelled by its caller";
|
|
34
|
+
return {
|
|
35
|
+
status,
|
|
36
|
+
lastWork,
|
|
37
|
+
output: `${status}: research helper r${id} ${explanation} (${metadata}).`,
|
|
38
|
+
exitCode: reason === "cancelled" ? 130 : reason === "drift_stop" ? 125 : 124,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const STRUCTURED_KEYS = [
|
|
2
|
+
"changed_files",
|
|
3
|
+
"assertions_proven",
|
|
4
|
+
"assertions_unproven",
|
|
5
|
+
"assertions_failed",
|
|
6
|
+
"tests_run",
|
|
7
|
+
"open_risks",
|
|
8
|
+
"requires_user_decision",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const ASSERTION_KEYS = new Set(["assertions_proven", "assertions_unproven", "assertions_failed"]);
|
|
12
|
+
|
|
13
|
+
export function extractAssertionIds(taskText) {
|
|
14
|
+
const ids = [];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
for (const match of String(taskText || "").matchAll(/\bA\d+\b/g)) {
|
|
17
|
+
const id = match[0];
|
|
18
|
+
if (!seen.has(id)) {
|
|
19
|
+
seen.add(id);
|
|
20
|
+
ids.push(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ids;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function parseStructuredReturn(finalText) {
|
|
27
|
+
const text = String(finalText || "");
|
|
28
|
+
const candidates = fencedBlocks(text);
|
|
29
|
+
candidates.push(text);
|
|
30
|
+
|
|
31
|
+
let best = null;
|
|
32
|
+
for (const candidate of candidates) {
|
|
33
|
+
const parsed = parseCandidate(candidate);
|
|
34
|
+
if (parsed && (!best || parsed.__score > best.__score)) best = parsed;
|
|
35
|
+
}
|
|
36
|
+
if (!best) return null;
|
|
37
|
+
delete best.__score;
|
|
38
|
+
return best;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function crossCheck(parsed, dispatchedIds) {
|
|
42
|
+
const ids = Array.from(new Set(dispatchedIds || []));
|
|
43
|
+
if (!parsed) {
|
|
44
|
+
return ids.length > 0 ? [{ type: "no_structured_return", ids }] : [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const notices = [];
|
|
48
|
+
const present = new Set();
|
|
49
|
+
for (const key of ["assertions_proven", "assertions_unproven", "assertions_failed"]) {
|
|
50
|
+
for (const entry of parsed[key] || []) {
|
|
51
|
+
if (entry && entry.id) present.add(entry.id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const id of ids) {
|
|
55
|
+
if (!present.has(id)) notices.push({ type: "missing", id });
|
|
56
|
+
}
|
|
57
|
+
for (const entry of parsed.assertions_proven || []) {
|
|
58
|
+
if (entry && entry.id && !entry.evidence) {
|
|
59
|
+
notices.push({ type: "proven_without_evidence", id: entry.id, note: entry.note || "" });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return notices;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function fencedBlocks(text) {
|
|
66
|
+
const blocks = [];
|
|
67
|
+
const re = /```[^\n]*\n([\s\S]*?)```/g;
|
|
68
|
+
let match;
|
|
69
|
+
while ((match = re.exec(text))) blocks.push(match[1]);
|
|
70
|
+
return blocks;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function parseCandidate(text) {
|
|
74
|
+
const result = Object.fromEntries(STRUCTURED_KEYS.map((key) => [key, []]));
|
|
75
|
+
let score = 0;
|
|
76
|
+
|
|
77
|
+
const keyBlocks = collectKeyBlocks(text);
|
|
78
|
+
for (const [key, block] of keyBlocks) {
|
|
79
|
+
result[key] = parseEntries(key, block);
|
|
80
|
+
score += 2 + result[key].length;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sectionBlocks = collectMarkdownSections(text);
|
|
84
|
+
for (const [key, block] of sectionBlocks) {
|
|
85
|
+
if (!keyBlocks.has(key)) {
|
|
86
|
+
result[key] = parseEntries(key, block);
|
|
87
|
+
score += 1 + result[key].length;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (score === 0) return null;
|
|
92
|
+
result.__score = score;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function collectKeyBlocks(text) {
|
|
97
|
+
const found = new Map();
|
|
98
|
+
const lines = text.split(/\r?\n/);
|
|
99
|
+
for (let i = 0; i < lines.length; i++) {
|
|
100
|
+
const match = lines[i].match(/^\s*([A-Za-z][A-Za-z0-9_ -]*)\s*:\s*(.*)$/);
|
|
101
|
+
if (!match) continue;
|
|
102
|
+
const key = normalizeKey(match[1]);
|
|
103
|
+
if (!STRUCTURED_KEYS.includes(key)) continue;
|
|
104
|
+
|
|
105
|
+
const block = [match[2] || ""];
|
|
106
|
+
let bracketBalance = balanceBrackets(match[2] || "");
|
|
107
|
+
let j = i + 1;
|
|
108
|
+
for (; j < lines.length; j++) {
|
|
109
|
+
const next = lines[j];
|
|
110
|
+
const nextKey = next.match(/^\s*([A-Za-z][A-Za-z0-9_ -]*)\s*:\s*/);
|
|
111
|
+
const isKnownNextKey = nextKey && STRUCTURED_KEYS.includes(normalizeKey(nextKey[1]));
|
|
112
|
+
const isHeading = /^\s*#{1,6}\s+/.test(next);
|
|
113
|
+
if (bracketBalance <= 0 && (isKnownNextKey || isHeading)) break;
|
|
114
|
+
if (next.trim() === "" && bracketBalance <= 0) break;
|
|
115
|
+
block.push(next);
|
|
116
|
+
bracketBalance += balanceBrackets(next);
|
|
117
|
+
}
|
|
118
|
+
found.set(key, block.join("\n"));
|
|
119
|
+
}
|
|
120
|
+
return found;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function collectMarkdownSections(text) {
|
|
124
|
+
const found = new Map();
|
|
125
|
+
const lines = text.split(/\r?\n/);
|
|
126
|
+
for (let i = 0; i < lines.length; i++) {
|
|
127
|
+
const match = lines[i].match(/^\s*#{1,6}\s+(.+?)\s*#*\s*$/);
|
|
128
|
+
if (!match) continue;
|
|
129
|
+
const key = normalizeKey(match[1]);
|
|
130
|
+
if (!STRUCTURED_KEYS.includes(key)) continue;
|
|
131
|
+
const block = [];
|
|
132
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
133
|
+
if (/^\s*#{1,6}\s+/.test(lines[j])) break;
|
|
134
|
+
block.push(lines[j]);
|
|
135
|
+
}
|
|
136
|
+
found.set(key, block.join("\n"));
|
|
137
|
+
}
|
|
138
|
+
return found;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function parseEntries(key, rawBlock) {
|
|
142
|
+
if (ASSERTION_KEYS.has(key)) {
|
|
143
|
+
return splitAssertionEntries(rawBlock).map(parseAssertionEntry).filter(Boolean);
|
|
144
|
+
}
|
|
145
|
+
return splitListEntries(rawBlock);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function normalizeListBlock(rawBlock) {
|
|
149
|
+
let block = String(rawBlock || "").trim();
|
|
150
|
+
if (!block || block === "[]") return "";
|
|
151
|
+
if (block.startsWith("[") && block.endsWith("]")) block = block.slice(1, -1);
|
|
152
|
+
return block;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function strippedLines(block) {
|
|
156
|
+
return block.split(/\r?\n/)
|
|
157
|
+
.map((line) => line.trim())
|
|
158
|
+
.filter(Boolean)
|
|
159
|
+
.map((line) => line.replace(/^[-*]\s+/, "").replace(/^\d+[.)]\s+/, "").replace(/,$/, "").trim())
|
|
160
|
+
.filter(Boolean);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function splitListEntries(rawBlock) {
|
|
164
|
+
const block = normalizeListBlock(rawBlock);
|
|
165
|
+
if (!block) return [];
|
|
166
|
+
const rawLines = block.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
167
|
+
const hasBulletLines = rawLines.some((line) => /^([-*]|\d+[.)])\s+/.test(line));
|
|
168
|
+
if (hasBulletLines) return strippedLines(block);
|
|
169
|
+
return [block.trim()];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function splitAssertionEntries(rawBlock) {
|
|
173
|
+
const block = normalizeListBlock(rawBlock);
|
|
174
|
+
if (!block) return [];
|
|
175
|
+
const rawLines = block.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
176
|
+
const hasBoundaryLines = rawLines.some((line) => /^([-*]|\d+[.)])\s+\bA\d+\b/.test(line));
|
|
177
|
+
if (hasBoundaryLines) return strippedLines(block).filter((line) => /^\bA\d+\b/.test(line));
|
|
178
|
+
return block
|
|
179
|
+
.split(/,(?=\s*A\d+\s*[:\-–—])/g)
|
|
180
|
+
.map((part) => part.trim().replace(/^,+\s*/, "").replace(/,+\s*$/, ""))
|
|
181
|
+
.filter(Boolean);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function parseAssertionEntry(entry) {
|
|
185
|
+
const text = String(entry || "").trim();
|
|
186
|
+
const idMatch = text.match(/\bA\d+\b/);
|
|
187
|
+
if (!idMatch) return null;
|
|
188
|
+
const id = idMatch[0];
|
|
189
|
+
let rest = text.slice((idMatch.index || 0) + id.length).trim();
|
|
190
|
+
rest = rest.replace(/^[:\-–—]\s*/, "");
|
|
191
|
+
|
|
192
|
+
let evidence = null;
|
|
193
|
+
const evidenceMatch = rest.match(/(?:^|\s+[—–-]\s*|\s+)evidence\s*:\s*([\s\S]*)$/i);
|
|
194
|
+
if (evidenceMatch) {
|
|
195
|
+
evidence = evidenceMatch[1].trim() || null;
|
|
196
|
+
rest = rest.slice(0, evidenceMatch.index).trim();
|
|
197
|
+
}
|
|
198
|
+
const note = rest.replace(/[✓✔]\s*$/u, "").trim();
|
|
199
|
+
return { id, note, evidence };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function normalizeKey(value) {
|
|
203
|
+
return String(value || "")
|
|
204
|
+
.trim()
|
|
205
|
+
.toLowerCase()
|
|
206
|
+
.replace(/[`*]/g, "")
|
|
207
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
208
|
+
.replace(/^_+|_+$/g, "");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function balanceBrackets(value) {
|
|
212
|
+
const opens = (String(value).match(/\[/g) || []).length;
|
|
213
|
+
const closes = (String(value).match(/\]/g) || []).length;
|
|
214
|
+
return opens - closes;
|
|
215
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Execution modes & per-turn budgets — the pure policy core behind the hub's
|
|
2
|
+
// runaway-orchestration guardrails. Budgets are PER USER TURN: a new user
|
|
3
|
+
// message opens a fresh window, so "budget exhausted" naturally means "stop,
|
|
4
|
+
// summarize, ask the user". Everything here is data + pure functions so the
|
|
5
|
+
// policy is unit-testable away from the 7k-line harness.
|
|
6
|
+
//
|
|
7
|
+
// A budget value of `null` means "off"/unlimited for that axis.
|
|
8
|
+
|
|
9
|
+
export const HUB_MODES = ["fast", "standard", "strict"];
|
|
10
|
+
export const DEFAULT_HUB_MODE = "standard";
|
|
11
|
+
|
|
12
|
+
// Task tiers — the dispatcher's per-turn complexity triage. Tier caps only
|
|
13
|
+
// lower the dispatch/research axes (min with the mode budget): a trivial ask
|
|
14
|
+
// must not burn a standard-mode budget on ceremony, while `project` defers
|
|
15
|
+
// entirely to the mode. Unset tier is treated as "feature".
|
|
16
|
+
export const TASK_TIERS = ["trivial", "small", "feature", "project"];
|
|
17
|
+
export const DEFAULT_TASK_TIER = "feature";
|
|
18
|
+
|
|
19
|
+
export const TIER_CAPS = {
|
|
20
|
+
trivial: { maxDispatches: 1, maxResearch: 1 },
|
|
21
|
+
small: { maxDispatches: 2, maxResearch: 2 },
|
|
22
|
+
feature: { maxDispatches: 6, maxResearch: 4 },
|
|
23
|
+
project: { maxDispatches: null, maxResearch: null },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** "Small", " TRIVIAL " → canonical tier name, or null when unrecognized. */
|
|
27
|
+
export function normalizeTaskTier(value) {
|
|
28
|
+
const v = String(value ?? "").trim().toLowerCase();
|
|
29
|
+
return TASK_TIERS.includes(v) ? v : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Session-recycle context threshold (percent, measured over input+cacheRead+
|
|
33
|
+
// cacheWrite): beyond this, resuming the specialist session mostly re-bills
|
|
34
|
+
// stale context, so a fresh session is cheaper than the memory is worth.
|
|
35
|
+
export const RECYCLE_CONTEXT_PCT = 60;
|
|
36
|
+
|
|
37
|
+
export const MODE_BUDGETS = {
|
|
38
|
+
fast: {
|
|
39
|
+
maxDispatches: 2,
|
|
40
|
+
maxResearch: 1,
|
|
41
|
+
wallMs: 15 * 60_000,
|
|
42
|
+
agentTurnMs: 10 * 60_000,
|
|
43
|
+
recycleRuns: 3,
|
|
44
|
+
delegation: false,
|
|
45
|
+
},
|
|
46
|
+
standard: {
|
|
47
|
+
maxDispatches: 8,
|
|
48
|
+
maxResearch: 4,
|
|
49
|
+
wallMs: 60 * 60_000,
|
|
50
|
+
agentTurnMs: 30 * 60_000,
|
|
51
|
+
recycleRuns: 5,
|
|
52
|
+
delegation: true,
|
|
53
|
+
},
|
|
54
|
+
strict: {
|
|
55
|
+
maxDispatches: 24,
|
|
56
|
+
maxResearch: 12,
|
|
57
|
+
wallMs: 240 * 60_000,
|
|
58
|
+
agentTurnMs: null,
|
|
59
|
+
recycleRuns: 5,
|
|
60
|
+
delegation: true,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** "Fast", " STRICT " → canonical mode name, or null when unrecognized. */
|
|
65
|
+
export function normalizeHubMode(value) {
|
|
66
|
+
const v = String(value ?? "").trim().toLowerCase();
|
|
67
|
+
return HUB_MODES.includes(v) ? v : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Effective budget for a mode with per-project overrides applied.
|
|
72
|
+
* Override fields (all optional): maxDispatches, maxResearch, wallMs,
|
|
73
|
+
* agentTurnMs, recycleRuns — a number replaces the mode default, `null` turns
|
|
74
|
+
* the axis off, `undefined` keeps the default. `delegation` is mode-owned.
|
|
75
|
+
* A declared `tier` (task tier) then LOWERS the dispatch and research caps to
|
|
76
|
+
* the tier cap — overrides raise/disable the mode side, but the tier keeps a
|
|
77
|
+
* simple ask from spending the whole envelope. No tier (null/undefined) means
|
|
78
|
+
* no tier caps: the caller decides when to assume DEFAULT_TASK_TIER.
|
|
79
|
+
*/
|
|
80
|
+
export function resolveTurnBudget(mode, overrides = {}, tier = undefined) {
|
|
81
|
+
const base = MODE_BUDGETS[normalizeHubMode(mode) ?? DEFAULT_HUB_MODE];
|
|
82
|
+
const pick = (key) => (overrides[key] === undefined ? base[key] : overrides[key]);
|
|
83
|
+
const caps = TIER_CAPS[normalizeTaskTier(tier)] ?? { maxDispatches: null, maxResearch: null };
|
|
84
|
+
const lower = (value, cap) => {
|
|
85
|
+
if (cap == null) return value;
|
|
86
|
+
if (value == null) return cap;
|
|
87
|
+
return Math.min(value, cap);
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
maxDispatches: lower(pick("maxDispatches"), caps.maxDispatches),
|
|
91
|
+
maxResearch: lower(pick("maxResearch"), caps.maxResearch),
|
|
92
|
+
wallMs: pick("wallMs"),
|
|
93
|
+
agentTurnMs: pick("agentTurnMs"),
|
|
94
|
+
recycleRuns: pick("recycleRuns"),
|
|
95
|
+
delegation: base.delegation,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function refusalTail(mode) {
|
|
100
|
+
return "Do NOT retry this call in this turn. Summarize progress so far (including " +
|
|
101
|
+
"unproven assertions and artifact paths), then ask the user whether to continue — " +
|
|
102
|
+
"the next user message starts a fresh budget window. The user can widen budgets " +
|
|
103
|
+
`with /hub-mode (current: ${mode}) or the max-*-per-turn / turn-wall-time-s keys ` +
|
|
104
|
+
"in .ai/agent-fleet-overrides.md.";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gate one dispatcher tool call against the turn budget.
|
|
109
|
+
* kind: "dispatch" | "research"; counters: { dispatches, research } — calls
|
|
110
|
+
* already made this turn. Returns null when allowed, else { reason, message }.
|
|
111
|
+
*/
|
|
112
|
+
export function checkTurnBudget(kind, counters, budget, elapsedWallMs, mode = DEFAULT_HUB_MODE) {
|
|
113
|
+
if (budget.wallMs != null && elapsedWallMs >= budget.wallMs) {
|
|
114
|
+
return {
|
|
115
|
+
reason: "wall",
|
|
116
|
+
message: `⚠ Turn budget exhausted: wall clock at ${Math.round(elapsedWallMs / 60_000)} min ` +
|
|
117
|
+
`(limit ${Math.round(budget.wallMs / 60_000)} min in ${mode} mode). ${refusalTail(mode)}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (kind === "dispatch" && budget.maxDispatches != null && counters.dispatches >= budget.maxDispatches) {
|
|
121
|
+
return {
|
|
122
|
+
reason: "dispatches",
|
|
123
|
+
message: `⚠ Turn budget exhausted: ${counters.dispatches} of ${budget.maxDispatches} ` +
|
|
124
|
+
`dispatch_agent calls used in ${mode} mode. ${refusalTail(mode)}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (kind === "research" && budget.maxResearch != null && counters.research >= budget.maxResearch) {
|
|
128
|
+
return {
|
|
129
|
+
reason: "research",
|
|
130
|
+
message: `⚠ Turn budget exhausted: ${counters.research} of ${budget.maxResearch} ` +
|
|
131
|
+
`spawn_research calls used in ${mode} mode. ${refusalTail(mode)}`,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Recycle the specialist's accumulated session before this run? True when the
|
|
139
|
+
* session already served `recycleRuns` runs, or its (correctly measured)
|
|
140
|
+
* context passed RECYCLE_CONTEXT_PCT — resuming past either point mostly
|
|
141
|
+
* re-bills stale context on every subsequent model call.
|
|
142
|
+
*/
|
|
143
|
+
export function shouldRecycleSession(runsSinceFresh, contextPct, budget, thresholdPct = RECYCLE_CONTEXT_PCT) {
|
|
144
|
+
if (runsSinceFresh <= 0) return false;
|
|
145
|
+
if (budget.recycleRuns != null && runsSinceFresh >= budget.recycleRuns) return true;
|
|
146
|
+
return contextPct >= thresholdPct;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** One-line status chip: "Mode: standard·small · 1/2 disp · 0/2 res". */
|
|
150
|
+
export function budgetStatusLine(mode, counters, budget, tier = null) {
|
|
151
|
+
const cap = (n) => (n == null ? "∞" : String(n));
|
|
152
|
+
const tierSuffix = tier ? `·${tier}` : "";
|
|
153
|
+
return `Mode: ${mode}${tierSuffix} · ${counters.dispatches}/${cap(budget.maxDispatches)} disp · ` +
|
|
154
|
+
`${counters.research}/${cap(budget.maxResearch)} res`;
|
|
155
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
const CONTINUE_ENTRY = /damage-control-continue[/\\]index\.ts$/;
|
|
5
|
+
const MISSING_SAFETY_ERROR = "damage-control-continue harness not found — guarded child dispatch refused";
|
|
6
|
+
|
|
7
|
+
/** Resolve only the surviving continue harness; never downgrade to an unguarded or hard-stop child. */
|
|
8
|
+
export function resolveSafetyHarness(cwd: string, argv: string[] = process.argv): string | null {
|
|
9
|
+
for (let i = 0; i < argv.length - 1; i++) {
|
|
10
|
+
if (argv[i] !== "-e" && argv[i] !== "--extension") continue;
|
|
11
|
+
const candidate = resolve(argv[i + 1]);
|
|
12
|
+
if (CONTINUE_ENTRY.test(candidate) && existsSync(candidate)) return candidate;
|
|
13
|
+
}
|
|
14
|
+
const local = join(cwd, ".pi", "harnesses", "damage-control-continue", "index.ts");
|
|
15
|
+
return existsSync(local) ? local : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function requireSafetyHarness(path: string | null):
|
|
19
|
+
| { ok: true; extensions: string[] }
|
|
20
|
+
| { ok: false; error: string } {
|
|
21
|
+
return path ? { ok: true, extensions: [path] } : { ok: false, error: MISSING_SAFETY_ERROR };
|
|
22
|
+
}
|