@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,118 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
import type { MonitorRegistration } from "./hermes-monitor-registry.ts";
|
|
7
|
+
|
|
8
|
+
export const MAX_SOCKET_FRAME_BYTES = 64 * 1024;
|
|
9
|
+
export const MAX_SNAPSHOT_BYTES = 256 * 1024;
|
|
10
|
+
export const MAX_CANCEL_RESPONSE_BYTES = 16 * 1024;
|
|
11
|
+
export const PARTIAL_FRAME_TIMEOUT_MS = 1000;
|
|
12
|
+
export const MAX_SOCKET_CONNECTIONS = 32;
|
|
13
|
+
export const MAX_TASK_ID_LENGTH = 128;
|
|
14
|
+
export const MAX_AFTER_SEQUENCE = 1_000_000_000;
|
|
15
|
+
/** 2 MiB covers the 256 KiB retained UTF-8 output after worst-case JSON escaping plus its envelope. */
|
|
16
|
+
export const MAX_OUTPUT_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
17
|
+
|
|
18
|
+
interface SnapshotRequest {
|
|
19
|
+
type: "snapshot";
|
|
20
|
+
token: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function authorized(actual: string, expected: string): boolean {
|
|
24
|
+
const actualBytes = Buffer.from(actual);
|
|
25
|
+
const expectedBytes = Buffer.from(expected);
|
|
26
|
+
return actualBytes.length === expectedBytes.length && crypto.timingSafeEqual(actualBytes, expectedBytes);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function validTaskRequest(taskId: unknown, generation: unknown, afterSequence?: unknown): boolean { return typeof taskId === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(taskId) && taskId.length <= MAX_TASK_ID_LENGTH && Number.isInteger(generation) && (generation as number) >= 1 && (afterSequence === undefined || (Number.isInteger(afterSequence) && (afterSequence as number) >= 0 && (afterSequence as number) <= MAX_AFTER_SEQUENCE)); }
|
|
30
|
+
|
|
31
|
+
function parseRequest(frame: string): SnapshotRequest | null {
|
|
32
|
+
try {
|
|
33
|
+
const value = JSON.parse(frame) as Partial<SnapshotRequest>;
|
|
34
|
+
if (value.type !== "snapshot" || typeof value.token !== "string") return null;
|
|
35
|
+
return { type: "snapshot", token: value.token };
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class MonitorSocketServer {
|
|
42
|
+
private readonly registration: MonitorRegistration;
|
|
43
|
+
private readonly server: net.Server;
|
|
44
|
+
private connections = 0;
|
|
45
|
+
|
|
46
|
+
constructor(registration: MonitorRegistration) {
|
|
47
|
+
this.registration = registration;
|
|
48
|
+
this.server = net.createServer((socket) => {
|
|
49
|
+
if (this.connections >= MAX_SOCKET_CONNECTIONS) { socket.destroy(); return; }
|
|
50
|
+
this.connections += 1;
|
|
51
|
+
socket.once("close", () => { this.connections -= 1; });
|
|
52
|
+
this.handle(socket);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private assertOwnedSocketPath(): void {
|
|
57
|
+
if (!this.registration.socketDir || path.resolve(this.registration.socketPath) !== path.join(path.resolve(this.registration.socketDir), "s")) throw new Error("monitor socket path is not registry-owned");
|
|
58
|
+
if (fs.lstatSync(this.registration.socketDir).isSymbolicLink() || (fs.statSync(this.registration.socketDir).mode & 0o777) !== 0o700) throw new Error("monitor socket directory is unsafe");
|
|
59
|
+
}
|
|
60
|
+
private async removeVerifiedStaleSocket(): Promise<void> {
|
|
61
|
+
this.assertOwnedSocketPath(); if (!fs.existsSync(this.registration.socketPath)) return;
|
|
62
|
+
const active=await new Promise<boolean>(resolve=>{const probe=net.createConnection(this.registration.socketPath);probe.once("connect",()=>{probe.destroy();resolve(true);});probe.once("error",()=>resolve(false));});
|
|
63
|
+
if (active) throw new Error("monitor socket is already active");
|
|
64
|
+
if (fs.lstatSync(this.registration.socketPath).isSymbolicLink()) throw new Error("monitor socket must not be a symlink"); fs.unlinkSync(this.registration.socketPath);
|
|
65
|
+
}
|
|
66
|
+
async listen(): Promise<void> {
|
|
67
|
+
await this.removeVerifiedStaleSocket(); return new Promise((resolve, reject) => { this.server.once("error", reject); this.server.listen(this.registration.socketPath, () => { this.server.off("error", reject); fs.chmodSync(this.registration.socketPath, 0o600); resolve(); }); });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async close(): Promise<void> {
|
|
71
|
+
await new Promise<void>((resolve, reject) => this.server.close((error) => error ? reject(error) : resolve()));
|
|
72
|
+
this.assertOwnedSocketPath(); try { fs.unlinkSync(this.registration.socketPath); } catch (error: any) { if (error?.code !== "ENOENT") throw error; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
mode(): number {
|
|
76
|
+
return fs.statSync(this.registration.socketPath).mode & 0o777;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private handle(socket: net.Socket): void {
|
|
80
|
+
let buffer = "";
|
|
81
|
+
let handled = false;
|
|
82
|
+
const deadline = setTimeout(() => { if (!handled) socket.destroy(); }, PARTIAL_FRAME_TIMEOUT_MS);
|
|
83
|
+
socket.on("data", (chunk) => {
|
|
84
|
+
if (handled) return;
|
|
85
|
+
buffer += chunk.toString("utf8");
|
|
86
|
+
if (Buffer.byteLength(buffer, "utf8") > MAX_SOCKET_FRAME_BYTES) {
|
|
87
|
+
socket.destroy();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const newline = buffer.indexOf("\n");
|
|
91
|
+
if (newline < 0) return;
|
|
92
|
+
handled = true;
|
|
93
|
+
const request = parseRequest(buffer.slice(0, newline));
|
|
94
|
+
clearTimeout(deadline);
|
|
95
|
+
let value: { type?: string; token?: string; taskId?: string; generation?: number };
|
|
96
|
+
try { value = JSON.parse(buffer.slice(0, newline)) as typeof value; } catch { socket.destroy(); return; }
|
|
97
|
+
if (value.type === "output") {
|
|
98
|
+
if (!authorized(String(value.token ?? ""), this.registration.token)) { socket.end(JSON.stringify({ ok: false, error: "unauthorized" }) + "\n"); return; }
|
|
99
|
+
if (!this.registration.output || (value as any).afterSequence === undefined || !validTaskRequest(value.taskId, value.generation, (value as any).afterSequence)) { socket.destroy(); return; }
|
|
100
|
+
Promise.resolve().then(()=>this.registration.output!({ taskId: value.taskId!, generation: value.generation!, afterSequence: (value as any).afterSequence })).then((output) => { const body=JSON.stringify({ ok:true, output }); if(Buffer.byteLength(body)>MAX_OUTPUT_RESPONSE_BYTES) socket.end(JSON.stringify({ok:false,error:"response_too_large"})+"\n"); else socket.end(body+"\n"); }).catch(()=>socket.end(JSON.stringify({ok:false,error:"monitor_unavailable"})+"\n")); return;
|
|
101
|
+
}
|
|
102
|
+
if (value.type === "cancel") {
|
|
103
|
+
if (!authorized(String(value.token ?? ""), this.registration.token)) { socket.end(JSON.stringify({ ok: false, error: "unauthorized" }) + "\n"); return; }
|
|
104
|
+
if (!this.registration.cancel || !validTaskRequest(value.taskId, value.generation)) { socket.destroy(); return; }
|
|
105
|
+
Promise.resolve().then(()=>this.registration.cancel!({ taskId: value.taskId!, generation: value.generation! })).then((result) => { const body=JSON.stringify({ ok: true, result }); if (Buffer.byteLength(body, "utf8") > MAX_CANCEL_RESPONSE_BYTES) socket.end(JSON.stringify({ok:false,error:"response_too_large"})+"\n"); else socket.end(body + "\n"); }).catch(()=>socket.end(JSON.stringify({ok:false,error:"monitor_unavailable"})+"\n")); return;
|
|
106
|
+
}
|
|
107
|
+
if (!request || !authorized(request.token, this.registration.token)) {
|
|
108
|
+
if (request) socket.end(JSON.stringify({ ok: false, error: "unauthorized" }) + "\n");
|
|
109
|
+
else socket.destroy();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try { const response = JSON.stringify({ ok: true, snapshot: this.registration.snapshot() }); if (Buffer.byteLength(response, "utf8") > MAX_SNAPSHOT_BYTES) socket.end(JSON.stringify({ok:false,error:"response_too_large"})+"\n"); else socket.end(response + "\n"); } catch { socket.end(JSON.stringify({ok:false,error:"monitor_unavailable"})+"\n"); }
|
|
113
|
+
});
|
|
114
|
+
socket.on("end", () => {
|
|
115
|
+
if (!handled) socket.destroy();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createChildTask, createParentTask, type CreateChildTaskInput, type CreateParentTaskInput, type MonitorTask } from "./hermes-monitor-model.ts";
|
|
2
|
+
export const MAX_OUTPUT_BYTES=256*1024;
|
|
3
|
+
export const MONITOR_RETENTION_MS=7*24*60*60*1000;
|
|
4
|
+
export const MONITOR_RETENTION_MAX=200;
|
|
5
|
+
const terminal=new Set(["completed","blocked","failed","cancelled","orphaned","done"]);
|
|
6
|
+
const active=(state:string)=>state==="starting"||state==="running"||state==="cancelling"||state==="recovering";
|
|
7
|
+
export function pruneMonitorTasks<T extends {state:string;updatedAt?:string}>(options:{now:Date;tasks:T[]}):T[]{const cutoff=options.now.getTime()-MONITOR_RETENTION_MS;const running=options.tasks.filter(t=>active(t.state));const terminalTasks=options.tasks.filter(t=>!active(t.state)&&(!t.updatedAt||new Date(t.updatedAt).getTime()>=cutoff)).sort((a,b)=>new Date(a.updatedAt??0).getTime()-new Date(b.updatedAt??0).getTime()).slice(-MONITOR_RETENTION_MAX);return [...running,...terminalTasks];}
|
|
8
|
+
export interface MonitorOutput{text:string;sequence:number;firstSequence:number;truncated:boolean}
|
|
9
|
+
interface StoredOutput{chunks:{sequence:number;text:string}[];sequence:number;truncated:boolean}
|
|
10
|
+
interface StoredTask{task:MonitorTask;output:StoredOutput;createdAt:string;updatedAt:string}
|
|
11
|
+
function suffix(text:string,limit:number){let bytes=0;const chars:string[]=[];for(const char of Array.from(text).reverse()){const size=Buffer.byteLength(char);if(bytes+size>limit)break;chars.push(char);bytes+=size;}return chars.reverse().join("");}
|
|
12
|
+
|
|
13
|
+
export class MonitorStore {
|
|
14
|
+
private readonly tasks=new Map<string,StoredTask>(); private readonly now:()=>Date;
|
|
15
|
+
constructor(options:{now?:()=>Date}={}){this.now=options.now??(()=>new Date());}
|
|
16
|
+
private key(id:string,generation:number){return `${id}:${generation}`;} private stamp(){return this.now().toISOString();}
|
|
17
|
+
createParent(input:CreateParentTaskInput){return this.add(createParentTask(input));}
|
|
18
|
+
createChild(input:CreateChildTaskInput){if(![...this.tasks.values()].some(s=>s.task.id===input.parentId&&s.task.generation===input.parentGeneration&&s.task.kind==="parent"))throw new Error(`parent task ${input.parentId} was not found`);return this.add(createChildTask(input));}
|
|
19
|
+
patch(id:string,generation:number,values:any){const stored=this.require(id,generation);Object.assign(stored.task,values);stored.updatedAt=this.stamp();return stored.task;}
|
|
20
|
+
transition(id:string,generation:number,state:any){const stored=this.require(id,generation);if(terminal.has(stored.task.state))throw new Error("terminal transition");stored.task.state=state;stored.updatedAt=this.stamp();return stored.task;}
|
|
21
|
+
get(id:string,generation?:number){return generation===undefined?[...this.tasks.values()].find(s=>s.task.id===id)?.task:this.tasks.get(this.key(id,generation))?.task;}
|
|
22
|
+
appendPublicOutput(id:string,generation:number,text:string){const stored=this.require(id,generation);if(terminal.has(stored.task.state))throw new Error("terminal output");const sequence=stored.output.sequence+1, chunk=suffix(text,MAX_OUTPUT_BYTES),chunks=[...stored.output.chunks,{sequence,text:chunk}];let bytes=chunks.reduce((n,c)=>n+Buffer.byteLength(c.text),0),truncated=stored.output.truncated||bytes<Buffer.byteLength(text);while(bytes>MAX_OUTPUT_BYTES&&chunks.length>1){bytes-=Buffer.byteLength(chunks.shift()!.text);truncated=true;}stored.output={chunks,sequence,truncated};stored.updatedAt=this.stamp();return this.outputAfter(stored.output,0);}
|
|
23
|
+
readOutput(id:string,generation:number,afterSequence:number){return this.outputAfter(this.require(id,generation).output,afterSequence);}
|
|
24
|
+
snapshot(){return {tasks:[...this.tasks.values()].map(s=>this.publicTask(s))};} durableSnapshot(){return{tasks:[...this.tasks.values()].map(s=>({...this.publicTask(s),outputChunks:s.output.chunks.map(c=>({...c}),),outputLatestSequence:s.output.sequence,outputFirstSequence:s.output.chunks[0]?.sequence??0,outputTruncated:s.output.truncated}))};} restore(rows:any[]){for(const row of rows){const key=this.key(row.id,row.generation);if(this.tasks.has(key))continue;const output=row.output??"";this.tasks.set(key,{task:{...row},output:{chunks:Array.isArray(row.outputChunks)?row.outputChunks.map((c:any)=>({sequence:c.sequence,text:c.text})):output?[{sequence:row.outputSequence??1,text:output}]:[],sequence:row.outputLatestSequence??row.outputSequence??0,truncated:row.outputTruncated??!!row.truncated},createdAt:row.createdAt??this.stamp(),updatedAt:row.updatedAt??this.stamp()});}}
|
|
25
|
+
prune(now=this.now()){const cutoff=now.getTime()-MONITOR_RETENTION_MS;const values=[...this.tasks.values()];const protectedIds=new Set<string>();for(const s of values)if(active(s.task.state)){protectedIds.add(this.key(s.task.id,s.task.generation));if(s.task.parentId)for(const p of values)if(p.task.id===s.task.parentId)protectedIds.add(this.key(p.task.id,p.task.generation));for(const c of values)if(c.task.parentId===s.task.id)protectedIds.add(this.key(c.task.id,c.task.generation));}const candidates=values.filter(s=>!active(s.task.state)&&!protectedIds.has(this.key(s.task.id,s.task.generation))).sort((a,b)=>Date.parse(a.updatedAt)-Date.parse(b.updatedAt));const expired=candidates.filter(s=>Date.parse(s.updatedAt)<cutoff);for(const s of expired)this.tasks.delete(this.key(s.task.id,s.task.generation));const remaining=[...this.tasks.values()].filter(s=>!active(s.task.state)&&!protectedIds.has(this.key(s.task.id,s.task.generation))).sort((a,b)=>Date.parse(a.updatedAt)-Date.parse(b.updatedAt));while(remaining.length>MONITOR_RETENTION_MAX){const oldest=remaining.shift()!;this.tasks.delete(this.key(oldest.task.id,oldest.task.generation));}return this.snapshot();}
|
|
26
|
+
private add(task:MonitorTask){const key=this.key(task.id,task.generation);if(this.tasks.has(key))throw new Error(`task ${task.id} generation ${task.generation} already exists`);const stamp=this.stamp();this.tasks.set(key,{task,output:{chunks:[],sequence:0,truncated:false},createdAt:stamp,updatedAt:stamp});return task;}
|
|
27
|
+
private publicTask(s:StoredTask){const output=this.outputAfter(s.output,0);return {...s.task,createdAt:s.createdAt,updatedAt:s.updatedAt,outputSequence:output.sequence,firstSequence:output.firstSequence,truncated:output.truncated};}
|
|
28
|
+
private outputAfter(output:StoredOutput,after:number):MonitorOutput{return{text:output.chunks.filter(c=>c.sequence>after).map(c=>c.text).join(""),sequence:output.sequence,firstSequence:output.chunks[0]?.sequence??0,truncated:output.truncated};}
|
|
29
|
+
private require(id:string,generation:number){const stored=this.tasks.get(this.key(id,generation));if(!stored)throw new Error(`task ${id} generation ${generation} was not found`);return stored;}
|
|
30
|
+
}
|
|
31
|
+
export function createMonitorStore(options:{now:()=>Date}){const store=new MonitorStore(options);const baseSnapshot=store.snapshot.bind(store);return Object.assign(store,{snapshot(){const all=(baseSnapshot() as any).tasks;return{tasks:all.filter((t:any)=>t.kind==='parent').map((parent:any)=>({id:parent.id,generation:parent.generation,children:all.filter((child:any)=>child.parentId===parent.id).map((child:any)=>({id:child.id,generation:child.generation,state:child.state,workspaceId:child.workspaceId,hubPaneId:child.hubPaneId,outputSequence:child.outputSequence,updatedAt:child.updatedAt}))}))};}});}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// scripts/lib/persona-banner.ts
|
|
2
|
+
//
|
|
3
|
+
// Pure logic for the per-pane identity banner (`just _peer`/`_peer-plus`
|
|
4
|
+
// print it before exec'ing pi): persona frontmatter → colored ANSI banner.
|
|
5
|
+
// Frontmatter parsing mirrors the coms harness convention (name /
|
|
6
|
+
// description / color, quoted values allowed). Backend-agnostic — works in
|
|
7
|
+
// any terminal, inside or outside herdr.
|
|
8
|
+
|
|
9
|
+
export interface PersonaMeta {
|
|
10
|
+
name?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
color?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parsePersonaFrontmatter(raw: string): PersonaMeta {
|
|
16
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n?/);
|
|
17
|
+
if (!match) return {};
|
|
18
|
+
const fm: Record<string, string> = {};
|
|
19
|
+
for (const line of match[1].split("\n")) {
|
|
20
|
+
const idx = line.indexOf(":");
|
|
21
|
+
if (idx > 0) {
|
|
22
|
+
const key = line.slice(0, idx).trim();
|
|
23
|
+
let val = line.slice(idx + 1).trim();
|
|
24
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
25
|
+
val = val.slice(1, -1);
|
|
26
|
+
}
|
|
27
|
+
fm[key] = val;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { name: fm.name, description: fm.description, color: fm.color };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isValidHex(hex: string): boolean {
|
|
34
|
+
return /^#[0-9a-fA-F]{6}$/.test(hex);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function hexFg(hex: string, s: string): string {
|
|
38
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
39
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
40
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
41
|
+
return `\x1b[38;2;${r};${g};${b}m${s}\x1b[0m`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_COLOR = "#36F9F6";
|
|
45
|
+
|
|
46
|
+
// Colored banner lines for a peer pane: name in the persona color, purpose
|
|
47
|
+
// dimmed below, framed by a rule in the same color. `width` caps the rule so
|
|
48
|
+
// narrow panes don't wrap.
|
|
49
|
+
export function renderBanner(
|
|
50
|
+
peerName: string,
|
|
51
|
+
meta: PersonaMeta,
|
|
52
|
+
width = 60,
|
|
53
|
+
): string[] {
|
|
54
|
+
const color = meta.color && isValidHex(meta.color) ? meta.color : DEFAULT_COLOR;
|
|
55
|
+
const purpose = (meta.description ?? "").trim();
|
|
56
|
+
const rule = hexFg(color, "━".repeat(Math.max(8, Math.min(width, 100))));
|
|
57
|
+
const title = hexFg(color, `● ${peerName}`);
|
|
58
|
+
const lines = [rule, title];
|
|
59
|
+
if (purpose) lines.push(`\x1b[2m${purpose}\x1b[0m`);
|
|
60
|
+
lines.push(rule);
|
|
61
|
+
return lines;
|
|
62
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// scripts/lib/spawn-stagger.ts
|
|
2
|
+
//
|
|
3
|
+
// Pre-warm/stagger for simultaneous pi pane spawns (team-up, hub-team,
|
|
4
|
+
// team-resume). pi's credential store (~/.pi/agent/auth.json) is loaded once
|
|
5
|
+
// at boot under a short-retry file lock; when a stale OAuth token forces one
|
|
6
|
+
// pane to refresh it over the network WHILE holding that lock, sibling panes
|
|
7
|
+
// booting in the same instant lose the lock race and come up with an empty
|
|
8
|
+
// credential store — every provider shows "unconfigured". The fix is local:
|
|
9
|
+
// when a stale OAuth credential is detected, one pi pane starts immediately
|
|
10
|
+
// (the warmer — it refreshes the token) and every other pi pane sleeps a few
|
|
11
|
+
// seconds before launching. Fresh tokens mean zero delay everywhere.
|
|
12
|
+
//
|
|
13
|
+
// Pure logic only — no fs, no sockets, no process.exit. Callers read
|
|
14
|
+
// auth.json themselves (lock-free, same as pi's readStoredCredential) and
|
|
15
|
+
// inject delays into pane env; the `_peer`/`_peer-plus` recipes honor
|
|
16
|
+
// AGENT_FLEET_SPAWN_DELAY with a plain `sleep`.
|
|
17
|
+
|
|
18
|
+
/** Env var the justfile peer recipes read: seconds to sleep before launching pi. */
|
|
19
|
+
export const STAGGER_ENV_VAR = "AGENT_FLEET_SPAWN_DELAY";
|
|
20
|
+
|
|
21
|
+
/** Delay for the first staggered pane — long enough for the warmer's token refresh round-trip. */
|
|
22
|
+
export const WARMUP_SECONDS = 4;
|
|
23
|
+
|
|
24
|
+
/** Extra spacing between subsequent staggered panes. */
|
|
25
|
+
export const STEP_SECONDS = 1;
|
|
26
|
+
|
|
27
|
+
/** Treat tokens expiring within this window as stale — pane boot takes seconds. */
|
|
28
|
+
export const EXPIRY_MARGIN_MS = 60_000;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Does auth.json hold an OAuth credential that a booting pi would refresh?
|
|
32
|
+
* `raw` is the file's contents (undefined when unreadable/absent). Missing or
|
|
33
|
+
* malformed files never stagger: with no stored credential there is nothing
|
|
34
|
+
* to refresh, so there is no long lock hold to dodge.
|
|
35
|
+
*/
|
|
36
|
+
export function oauthNeedsWarmup(raw: string | undefined, now = Date.now()): boolean {
|
|
37
|
+
if (!raw) return false;
|
|
38
|
+
let data: unknown;
|
|
39
|
+
try {
|
|
40
|
+
data = JSON.parse(raw);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (typeof data !== "object" || data === null) return false;
|
|
45
|
+
for (const credential of Object.values(data)) {
|
|
46
|
+
if (typeof credential !== "object" || credential === null) continue;
|
|
47
|
+
const { type, expires } = credential as { type?: unknown; expires?: unknown };
|
|
48
|
+
if (type !== "oauth" || typeof expires !== "number") continue;
|
|
49
|
+
if (expires <= now + EXPIRY_MARGIN_MS) return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface StaggerOptions {
|
|
55
|
+
/** Per-peer flag, in spawn order: does this pane boot a pi process? */
|
|
56
|
+
peerIsPi: boolean[];
|
|
57
|
+
/** Does the root pane (hub) boot a pi process? The hub warms when present. */
|
|
58
|
+
rootIsPi: boolean;
|
|
59
|
+
/** Result of oauthNeedsWarmup — false short-circuits to all-zero delays. */
|
|
60
|
+
needed: boolean;
|
|
61
|
+
warmupSeconds?: number;
|
|
62
|
+
stepSeconds?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Per-peer delay seconds (spawn order). Exactly one pi process — the hub when
|
|
67
|
+
* present, otherwise the first pi peer — starts at 0 and refreshes the stale
|
|
68
|
+
* token; every other pi peer starts after the warm-up window. Non-pi panes
|
|
69
|
+
* (runner: claude-code) never wait: they do not touch pi's credential store.
|
|
70
|
+
*/
|
|
71
|
+
export function staggerDelays(opts: StaggerOptions): number[] {
|
|
72
|
+
const { peerIsPi, rootIsPi, needed, warmupSeconds = WARMUP_SECONDS, stepSeconds = STEP_SECONDS } = opts;
|
|
73
|
+
if (!needed) return peerIsPi.map(() => 0);
|
|
74
|
+
let staggered = 0;
|
|
75
|
+
let warmerAssigned = rootIsPi;
|
|
76
|
+
return peerIsPi.map((isPi) => {
|
|
77
|
+
if (!isPi) return 0;
|
|
78
|
+
if (!warmerAssigned) {
|
|
79
|
+
warmerAssigned = true;
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
return warmupSeconds + staggered++ * stepSeconds;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Convenience for the team entrypoints: auth.json contents + peers → a
|
|
88
|
+
* `delayForPeer` hook for buildTeamLayout. Structural peer type avoids a
|
|
89
|
+
* circular import with herdr-layout.ts.
|
|
90
|
+
*/
|
|
91
|
+
export function planSpawnDelays<P extends { runner?: string }>(
|
|
92
|
+
peers: P[],
|
|
93
|
+
rootIsPi: boolean,
|
|
94
|
+
authJsonRaw: string | undefined,
|
|
95
|
+
now = Date.now(),
|
|
96
|
+
): { needed: boolean; delayForPeer: (peer: P) => number | undefined } {
|
|
97
|
+
const needed = oauthNeedsWarmup(authJsonRaw, now);
|
|
98
|
+
const delays = staggerDelays({ peerIsPi: peers.map((p) => p.runner !== "claude-code"), rootIsPi, needed });
|
|
99
|
+
const byPeer = new Map<P, number>(peers.map((p, i) => [p, delays[i]]));
|
|
100
|
+
return { needed, delayForPeer: (peer) => byPeer.get(peer) };
|
|
101
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// scripts/lib/team-project.ts
|
|
2
|
+
//
|
|
3
|
+
// Shared project scoping helpers for herdr team commands. The coms harness
|
|
4
|
+
// already isolates peers by --project; this file only keeps team workspace
|
|
5
|
+
// labels, snapshot files, and generated launch argv in sync with that scope.
|
|
6
|
+
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_PROJECT = "default";
|
|
11
|
+
|
|
12
|
+
// Conservative project names: no empty string, path separators, traversal,
|
|
13
|
+
// whitespace, shell metacharacters, or glob stars. Dots are allowed for names
|
|
14
|
+
// like "acme.prod", but ".." is not allowed anywhere.
|
|
15
|
+
export const PROJECT_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
16
|
+
export const TEAM_SAFE = /^[A-Za-z0-9_-]+$/;
|
|
17
|
+
export const CODEX_CONTRACT_IDENTITY = "agent-fleet-codex-conductor-pilot-v1";
|
|
18
|
+
export const DEFAULT_CODEX_TIMEOUT_MS = 300_000;
|
|
19
|
+
|
|
20
|
+
export type ConductorBackend = "hermes" | "codex";
|
|
21
|
+
export type WorkspaceMode = "peers" | "hub" | "conductor-hermes" | "conductor-codex";
|
|
22
|
+
|
|
23
|
+
export interface ConductorSpec {
|
|
24
|
+
backend: ConductorBackend;
|
|
25
|
+
workspaceMode: Extract<WorkspaceMode, `conductor-${string}`>;
|
|
26
|
+
paneLabel: string;
|
|
27
|
+
command: string[];
|
|
28
|
+
cwd: string;
|
|
29
|
+
env: Record<string, string>;
|
|
30
|
+
ratio: number;
|
|
31
|
+
displayText: string;
|
|
32
|
+
expectedServiceScope: "none" | "agent-fleet-codex-remote-control.service";
|
|
33
|
+
conductorName: string;
|
|
34
|
+
team: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function validateAbsoluteRepoRoot(repoRoot: string): string {
|
|
38
|
+
if (!path.isAbsolute(repoRoot) || path.resolve(repoRoot) !== repoRoot || repoRoot.includes("..")) {
|
|
39
|
+
throw new Error(`Invalid absolute repository root: ${JSON.stringify(repoRoot)}`);
|
|
40
|
+
}
|
|
41
|
+
return repoRoot;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function validateProject(project: string): string {
|
|
45
|
+
if (
|
|
46
|
+
project.length === 0 ||
|
|
47
|
+
project === "." ||
|
|
48
|
+
project.includes("..") ||
|
|
49
|
+
project.includes("/") ||
|
|
50
|
+
project.includes("\\") ||
|
|
51
|
+
!PROJECT_SAFE.test(project)
|
|
52
|
+
) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Invalid project name: ${JSON.stringify(project)} (use letters, numbers, dots, underscores, or hyphens; no '..')`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return project;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function validateTeamName(team: string): string {
|
|
61
|
+
if (!TEAM_SAFE.test(team)) throw new Error(`Invalid team name: ${JSON.stringify(team)}`);
|
|
62
|
+
return team;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The worktree/repo identity that scopes a workspace label so the same team
|
|
66
|
+
// launched from different checkouts never collides. It is the LAST dot-segment
|
|
67
|
+
// of the checkout directory's basename — the convention the fleet uses for
|
|
68
|
+
// git worktrees: `main.wt2` → `wt2`, `ringithub.end2` → `end2`, a plain
|
|
69
|
+
// `agent-fleet` checkout → `agent-fleet`. Sanitized to the label-safe charset;
|
|
70
|
+
// falls back to "repo" when nothing usable remains.
|
|
71
|
+
export function worktreeTag(repoRoot: string): string {
|
|
72
|
+
const base = path.basename(repoRoot);
|
|
73
|
+
const dot = base.lastIndexOf(".");
|
|
74
|
+
const seg = dot > 0 ? base.slice(dot + 1) : base;
|
|
75
|
+
const safe = seg.replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
76
|
+
return safe || "repo";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function parseProjectFlag(argv: string[]): string {
|
|
80
|
+
let project = DEFAULT_PROJECT;
|
|
81
|
+
let seen = false;
|
|
82
|
+
for (let i = 0; i < argv.length; i++) {
|
|
83
|
+
if (argv[i] !== "--project") continue;
|
|
84
|
+
if (seen) throw new Error("--project may only be provided once");
|
|
85
|
+
seen = true;
|
|
86
|
+
const value = argv[i + 1];
|
|
87
|
+
if (!value || value.startsWith("--")) throw new Error("--project requires a name");
|
|
88
|
+
project = value;
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
return validateProject(project);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Workspace label = <worktree-tag>-<mode>-<team>, with a `--project.<name>`
|
|
95
|
+
// suffix when the coms project is non-default. The worktree tag keys the label
|
|
96
|
+
// to the checkout, so `just hub-team <team>` from two repos/worktrees yields
|
|
97
|
+
// distinct labels (e.g. `wt2-hub-plan` vs `end2-hub-plan`) instead of colliding
|
|
98
|
+
// on a shared `pi-hub-<team>`. Pass `tag` from worktreeTag(REPO_ROOT); it
|
|
99
|
+
// defaults to "repo" only for callers that have no checkout in hand.
|
|
100
|
+
export function teamWorkspaceLabel(
|
|
101
|
+
kind: WorkspaceMode,
|
|
102
|
+
team: string,
|
|
103
|
+
project = DEFAULT_PROJECT,
|
|
104
|
+
tag = "repo",
|
|
105
|
+
): string {
|
|
106
|
+
validateTeamName(team);
|
|
107
|
+
validateProject(project);
|
|
108
|
+
const base = `${tag}-${kind}-${team}`;
|
|
109
|
+
return project === DEFAULT_PROJECT ? base : `${base}--project.${project}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function hubCommand(project = DEFAULT_PROJECT): string[] {
|
|
113
|
+
validateProject(project);
|
|
114
|
+
return project === DEFAULT_PROJECT ? ["just", "hub"] : ["just", "hub", "--project", project];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function conductorCommand(): string[] {
|
|
118
|
+
return ["hermes", "-p", "dev"];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function conductorSpec(
|
|
122
|
+
backend: ConductorBackend,
|
|
123
|
+
input: { repoRoot: string; runtimeDir?: string; team: string; project?: string; nodeBin?: string },
|
|
124
|
+
): ConductorSpec {
|
|
125
|
+
const repoRoot = validateAbsoluteRepoRoot(input.repoRoot);
|
|
126
|
+
const team = validateTeamName(input.team);
|
|
127
|
+
const project = validateProject(input.project ?? DEFAULT_PROJECT);
|
|
128
|
+
const conductorName = `${backend}-${team}-conductor`;
|
|
129
|
+
if (backend === "hermes") {
|
|
130
|
+
return {
|
|
131
|
+
backend,
|
|
132
|
+
workspaceMode: "conductor-hermes",
|
|
133
|
+
paneLabel: "conductor-hermes",
|
|
134
|
+
command: conductorCommand(),
|
|
135
|
+
cwd: repoRoot,
|
|
136
|
+
env: {},
|
|
137
|
+
ratio: 0.35,
|
|
138
|
+
displayText: "Hermes conductor; no herdr control",
|
|
139
|
+
expectedServiceScope: "none",
|
|
140
|
+
conductorName,
|
|
141
|
+
team,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const runtimeDir = input.runtimeDir ?? path.join(os.homedir(), ".local", "state", "agent-fleet", "codex-conductor");
|
|
145
|
+
if (!path.isAbsolute(runtimeDir) || path.resolve(runtimeDir) !== runtimeDir) {
|
|
146
|
+
throw new Error(`Codex conductor requires an absolute runtime directory: ${JSON.stringify(runtimeDir)}`);
|
|
147
|
+
}
|
|
148
|
+
const relativeRuntime = path.relative(repoRoot, runtimeDir);
|
|
149
|
+
if (relativeRuntime === "" || (!relativeRuntime.startsWith("..") && !path.isAbsolute(relativeRuntime))) {
|
|
150
|
+
throw new Error("Codex conductor requires a runtime directory outside repoRoot");
|
|
151
|
+
}
|
|
152
|
+
const workspaceDir = path.join(runtimeDir, "workspace");
|
|
153
|
+
const nodeBin = input.nodeBin ?? process.execPath;
|
|
154
|
+
if (!path.isAbsolute(nodeBin)) throw new Error(`Codex conductor requires an absolute Node binary path: ${JSON.stringify(nodeBin)}`);
|
|
155
|
+
return {
|
|
156
|
+
backend,
|
|
157
|
+
workspaceMode: "conductor-codex",
|
|
158
|
+
paneLabel: "conductor-codex-control",
|
|
159
|
+
command: [nodeBin, "--experimental-strip-types", path.join(repoRoot, "scripts", "codex-remote-control.ts"), "control-pane"],
|
|
160
|
+
cwd: workspaceDir,
|
|
161
|
+
env: {
|
|
162
|
+
AGENT_FLEET_REPO_ROOT: repoRoot,
|
|
163
|
+
COMS_CLI_PROJECT: project,
|
|
164
|
+
COMS_CLI_NAME: conductorName,
|
|
165
|
+
COMS_CLI_TIMEOUT_MS: String(DEFAULT_CODEX_TIMEOUT_MS),
|
|
166
|
+
AGENT_FLEET_CODEX_CONTRACT_PATH: path.join(workspaceDir, "AGENTS.md"),
|
|
167
|
+
AGENT_FLEET_CODEX_CONTRACT_IDENTITY: CODEX_CONTRACT_IDENTITY,
|
|
168
|
+
AGENT_FLEET_CONDUCTOR_BACKEND: "codex",
|
|
169
|
+
},
|
|
170
|
+
ratio: 0.35,
|
|
171
|
+
displayText: "Codex control pane; requested systemd state only",
|
|
172
|
+
expectedServiceScope: "agent-fleet-codex-remote-control.service",
|
|
173
|
+
conductorName,
|
|
174
|
+
team,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function teamSnapshotPath(snapshotDir: string, team: string, project = DEFAULT_PROJECT): string {
|
|
179
|
+
validateTeamName(team);
|
|
180
|
+
validateProject(project);
|
|
181
|
+
return project === DEFAULT_PROJECT
|
|
182
|
+
? path.join(snapshotDir, `${team}.json`)
|
|
183
|
+
: path.join(snapshotDir, "projects", project, `${team}.json`);
|
|
184
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// scripts/lib/team-snapshot.ts
|
|
2
|
+
//
|
|
3
|
+
// Pure logic for fleet resume (B5): snapshot a running team (peer manifest +
|
|
4
|
+
// per-peer session resume refs harvested from herdr) and rebuild it later.
|
|
5
|
+
// See docs/plans/herdr/b5-resume-notes.md for the decisions: pane exit closes
|
|
6
|
+
// the pane (nothing to re-attach), layout.export cannot target an unfocused
|
|
7
|
+
// workspace, so snapshots store peers + refs and the grid is regenerated with
|
|
8
|
+
// the same builder team-up uses.
|
|
9
|
+
//
|
|
10
|
+
// No sockets, no fs, no process.exit here — the wiring lives in
|
|
11
|
+
// scripts/team-snapshot.ts.
|
|
12
|
+
|
|
13
|
+
import type { Peer } from "./herdr-layout.ts";
|
|
14
|
+
import { DEFAULT_PROJECT, teamWorkspaceLabel, validateProject, validateTeamName } from "./team-project.ts";
|
|
15
|
+
|
|
16
|
+
// Shape of herdr's agent_session (agent.list): pi panes carry
|
|
17
|
+
// {kind:"path", value:<session .jsonl>}, claude panes {kind:"id", value:<uuid>}.
|
|
18
|
+
export interface ResumeRef {
|
|
19
|
+
kind: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PeerSnapshot extends Peer {
|
|
24
|
+
resume: ResumeRef | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TeamSnapshot {
|
|
28
|
+
version: 1;
|
|
29
|
+
team: string;
|
|
30
|
+
project: string;
|
|
31
|
+
hub: boolean;
|
|
32
|
+
workspace_label: string;
|
|
33
|
+
taken_at: string;
|
|
34
|
+
peers: PeerSnapshot[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Minimal shapes of the herdr responses the builder joins over.
|
|
38
|
+
export interface PaneLite {
|
|
39
|
+
pane_id: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
export interface AgentLite {
|
|
44
|
+
pane_id?: string;
|
|
45
|
+
agent?: string;
|
|
46
|
+
agent_session?: { kind?: string; value?: string };
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Join: peers.yaml manifest × pane labels (pane label = peer name, set by the
|
|
51
|
+
// layout) × agent sessions (keyed by pane_id). A peer whose pane or session
|
|
52
|
+
// is missing snapshots with resume: null — it will start fresh on resume.
|
|
53
|
+
export function buildSnapshot(opts: {
|
|
54
|
+
team: string;
|
|
55
|
+
hub: boolean;
|
|
56
|
+
peers: Peer[];
|
|
57
|
+
panes: PaneLite[];
|
|
58
|
+
agents: AgentLite[];
|
|
59
|
+
now?: Date;
|
|
60
|
+
project?: string;
|
|
61
|
+
tag?: string;
|
|
62
|
+
}): TeamSnapshot {
|
|
63
|
+
const { team, hub, peers, panes, agents, project = DEFAULT_PROJECT, tag } = opts;
|
|
64
|
+
validateTeamName(team);
|
|
65
|
+
validateProject(project);
|
|
66
|
+
const paneByLabel = new Map<string, string>();
|
|
67
|
+
for (const p of panes) {
|
|
68
|
+
if (p.label) paneByLabel.set(p.label, p.pane_id);
|
|
69
|
+
}
|
|
70
|
+
const sessionByPane = new Map<string, ResumeRef>();
|
|
71
|
+
for (const a of agents) {
|
|
72
|
+
const s = a.agent_session;
|
|
73
|
+
if (a.pane_id && s && typeof s.kind === "string" && typeof s.value === "string") {
|
|
74
|
+
sessionByPane.set(a.pane_id, { kind: s.kind, value: s.value });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
version: 1,
|
|
79
|
+
team,
|
|
80
|
+
project,
|
|
81
|
+
hub,
|
|
82
|
+
workspace_label: teamWorkspaceLabel(hub ? "hub" : "peers", team, project, tag),
|
|
83
|
+
taken_at: (opts.now ?? new Date()).toISOString(),
|
|
84
|
+
peers: peers.map((peer) => {
|
|
85
|
+
const paneId = peer.name ? paneByLabel.get(peer.name) : undefined;
|
|
86
|
+
const resume = paneId ? sessionByPane.get(paneId) ?? null : null;
|
|
87
|
+
return { ...peer, resume };
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The resume ref usable by this peer's launch recipe, or undefined to start
|
|
93
|
+
// fresh. `refUsable` is injected (fs check for pi paths); refs of kinds the
|
|
94
|
+
// recipes cannot consume yet (e.g. claude ids before the Phase-4 runner
|
|
95
|
+
// lands) resolve undefined with a reason via `onSkip`.
|
|
96
|
+
export function resumeRefForPeer(
|
|
97
|
+
peer: PeerSnapshot,
|
|
98
|
+
refUsable: (ref: ResumeRef) => boolean,
|
|
99
|
+
onSkip?: (peer: PeerSnapshot, reason: string) => void,
|
|
100
|
+
): string | undefined {
|
|
101
|
+
if (!peer.resume) {
|
|
102
|
+
onSkip?.(peer, "no session ref in snapshot — starting fresh");
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
// pi peers resume by session file path; claude-code peers by session id
|
|
106
|
+
// (herdr reports {kind:"id"} for claude — `claude --resume <id>`).
|
|
107
|
+
const wantKind = peer.runner === "claude-code" ? "id" : "path";
|
|
108
|
+
if (peer.resume.kind !== wantKind) {
|
|
109
|
+
onSkip?.(peer, `unsupported resume kind "${peer.resume.kind}" — starting fresh`);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (!refUsable(peer.resume)) {
|
|
113
|
+
onSkip?.(peer, `session file gone (${peer.resume.value}) — starting fresh`);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
return peer.resume.value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function parseSnapshot(raw: string): TeamSnapshot {
|
|
120
|
+
let parsed: unknown;
|
|
121
|
+
try {
|
|
122
|
+
parsed = JSON.parse(raw);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
throw new Error(`Snapshot is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
125
|
+
}
|
|
126
|
+
const s = parsed as TeamSnapshot;
|
|
127
|
+
if (!s || s.version !== 1 || typeof s.team !== "string" || !Array.isArray(s.peers)) {
|
|
128
|
+
throw new Error("Snapshot has an unexpected shape (want {version:1, team, peers[]}).");
|
|
129
|
+
}
|
|
130
|
+
validateTeamName(s.team);
|
|
131
|
+
if (!("project" in (s as Record<string, unknown>))) {
|
|
132
|
+
(s as { project: string }).project = DEFAULT_PROJECT;
|
|
133
|
+
} else if (typeof (s as { project?: unknown }).project !== "string") {
|
|
134
|
+
throw new Error("Snapshot has an unexpected shape (project must be a string when present).");
|
|
135
|
+
}
|
|
136
|
+
validateProject(s.project);
|
|
137
|
+
return s;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function assertSnapshotProject(snap: TeamSnapshot, requestedProject: string): void {
|
|
141
|
+
validateProject(requestedProject);
|
|
142
|
+
if (snap.project !== requestedProject) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Snapshot project mismatch: snapshot is ${JSON.stringify(snap.project)}, requested ${JSON.stringify(requestedProject)}.`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|