@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
|
@@ -19,6 +19,35 @@ export const COMS_DIR = process.env.PI_COMS_DIR || path.join(os.homedir(), ".pi"
|
|
|
19
19
|
export const MAX_HOPS = Number(process.env.PI_COMS_MAX_HOPS) || 5;
|
|
20
20
|
export const DEFAULT_TIMEOUT_MS = Number(process.env.PI_COMS_TIMEOUT_MS) || 1_800_000;
|
|
21
21
|
const LINE_CAP_BYTES = 64 * 1024;
|
|
22
|
+
// Pi peers refresh heartbeat_at every 30 seconds. A fresh heartbeat is the
|
|
23
|
+
// portable liveness signal for callers inside a sandbox/PID namespace, where
|
|
24
|
+
// process.kill(pid, 0) can incorrectly report a live host peer as ESRCH.
|
|
25
|
+
const REGISTRY_HEARTBEAT_FRESH_MS = 90_000;
|
|
26
|
+
|
|
27
|
+
// Registry paths are shared by every coms participant. Keep their components
|
|
28
|
+
// conservative so callers cannot escape the project/name directory structure.
|
|
29
|
+
export const COMS_PROJECT_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
30
|
+
export const COMS_NAME_SAFE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
31
|
+
|
|
32
|
+
export function validateComsProject(project: string): string {
|
|
33
|
+
if (
|
|
34
|
+
project.length === 0 ||
|
|
35
|
+
project === "." ||
|
|
36
|
+
project.includes("..") ||
|
|
37
|
+
project.includes("/") ||
|
|
38
|
+
project.includes("\\") ||
|
|
39
|
+
!COMS_PROJECT_SAFE.test(project)
|
|
40
|
+
) {
|
|
41
|
+
throw new Error(`Invalid project name: ${JSON.stringify(project)}`);
|
|
42
|
+
}
|
|
43
|
+
return project;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function validateComsName(name: string): string {
|
|
47
|
+
if (!COMS_NAME_SAFE.test(name)) throw new Error(`Invalid coms name: ${JSON.stringify(name)}`);
|
|
48
|
+
if (name === "projects") throw new Error(`Invalid reserved coms name: ${JSON.stringify(name)}`);
|
|
49
|
+
return name;
|
|
50
|
+
}
|
|
22
51
|
|
|
23
52
|
// ━━ Envelope shapes (mirror coms/index.ts) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
24
53
|
|
|
@@ -221,11 +250,11 @@ export function isCancelEnvelope(obj: unknown): obj is CancelEnvelope {
|
|
|
221
250
|
// ━━ Registry I/O (mirrors coms/index.ts semantics) ━━━━━━━━━━━━━━━━━━━━━━━━
|
|
222
251
|
|
|
223
252
|
export function projectAgentsDir(project: string): string {
|
|
224
|
-
return path.join(COMS_DIR, "projects", project, "agents");
|
|
253
|
+
return path.join(COMS_DIR, "projects", validateComsProject(project), "agents");
|
|
225
254
|
}
|
|
226
255
|
|
|
227
256
|
export function registryFilePath(project: string, name: string): string {
|
|
228
|
-
return path.join(projectAgentsDir(project), `${name}.json`);
|
|
257
|
+
return path.join(projectAgentsDir(project), `${validateComsName(name)}.json`);
|
|
229
258
|
}
|
|
230
259
|
|
|
231
260
|
export function ensureComsDirs(project: string): void {
|
|
@@ -241,6 +270,7 @@ export function ensureComsDirs(project: string): void {
|
|
|
241
270
|
}
|
|
242
271
|
|
|
243
272
|
export function writeRegistryAtomic(entry: RegistryEntry, project: string): string {
|
|
273
|
+
validateComsName(entry.name);
|
|
244
274
|
const file = registryFilePath(project, entry.name);
|
|
245
275
|
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
246
276
|
fs.writeFileSync(tmp, JSON.stringify(entry, null, 2));
|
|
@@ -261,8 +291,9 @@ export function readAllRegistryEntries(project: string): RegistryEntry[] {
|
|
|
261
291
|
let files: string[];
|
|
262
292
|
try {
|
|
263
293
|
files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
264
|
-
} catch {
|
|
265
|
-
return [];
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
|
|
296
|
+
throw new Error(`Unable to read coms registry ${dir}: ${(error as NodeJS.ErrnoException).code ?? "unknown error"}`);
|
|
266
297
|
}
|
|
267
298
|
const out: RegistryEntry[] = [];
|
|
268
299
|
for (const f of files) {
|
|
@@ -276,11 +307,24 @@ export function readAllRegistryEntries(project: string): RegistryEntry[] {
|
|
|
276
307
|
return out;
|
|
277
308
|
}
|
|
278
309
|
|
|
279
|
-
|
|
280
|
-
|
|
310
|
+
export function registryHeartbeatIsFresh(entry: RegistryEntry, now = Date.now()): boolean {
|
|
311
|
+
if (!entry.heartbeat_at) return false;
|
|
312
|
+
const heartbeat = Date.parse(entry.heartbeat_at);
|
|
313
|
+
if (!Number.isFinite(heartbeat)) return false;
|
|
314
|
+
const age = now - heartbeat;
|
|
315
|
+
return age >= -5_000 && age <= REGISTRY_HEARTBEAT_FRESH_MS;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// A fresh heartbeat wins before the PID probe because Codex remote commands
|
|
319
|
+
// can execute in a distinct PID namespace. For entries without a fresh
|
|
320
|
+
// heartbeat, preserve the harness rule: ESRCH removes; EPERM counts as live.
|
|
281
321
|
export function pruneDeadEntries(project: string): RegistryEntry[] {
|
|
282
322
|
const live: RegistryEntry[] = [];
|
|
283
323
|
for (const entry of readAllRegistryEntries(project)) {
|
|
324
|
+
if (registryHeartbeatIsFresh(entry)) {
|
|
325
|
+
live.push(entry);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
284
328
|
try {
|
|
285
329
|
process.kill(entry.pid, 0);
|
|
286
330
|
live.push(entry);
|
|
@@ -296,6 +340,7 @@ export function pruneDeadEntries(project: string): RegistryEntry[] {
|
|
|
296
340
|
}
|
|
297
341
|
|
|
298
342
|
export function resolveUniqueName(project: string, desiredName: string): string {
|
|
343
|
+
validateComsName(desiredName);
|
|
299
344
|
const liveNames = new Set(pruneDeadEntries(project).map((e) => e.name));
|
|
300
345
|
if (!liveNames.has(desiredName)) return desiredName;
|
|
301
346
|
let n = 2;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as net from "node:net";
|
|
3
|
+
import { mkdtempSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
export interface FakeHerdrRequest {
|
|
8
|
+
id: string;
|
|
9
|
+
method: string;
|
|
10
|
+
params: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class FakeHerdrServer {
|
|
14
|
+
public readonly requests: FakeHerdrRequest[] = [];
|
|
15
|
+
public readonly socketPath: string;
|
|
16
|
+
private readonly subscribers = new Set<net.Socket>();
|
|
17
|
+
private readonly server: net.Server;
|
|
18
|
+
private readonly root: string;
|
|
19
|
+
private workspaceId: string;
|
|
20
|
+
private readonly paneId: string;
|
|
21
|
+
private readonly resyncOutput: { sequence: number; text: string };
|
|
22
|
+
|
|
23
|
+
private constructor(socketPath: string, server: net.Server, root: string, paneId: string, workspaceId: string, resyncOutput: { sequence: number; text: string }) {
|
|
24
|
+
this.socketPath = socketPath;
|
|
25
|
+
this.server = server;
|
|
26
|
+
this.root = root;
|
|
27
|
+
this.paneId = paneId;
|
|
28
|
+
this.workspaceId = workspaceId;
|
|
29
|
+
this.resyncOutput = resyncOutput;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static async start(values: { paneId: string; workspaceId: string; resyncOutput?: { sequence: number; text: string } }): Promise<FakeHerdrServer> {
|
|
33
|
+
const root = mkdtempSync(join(tmpdir(), "fake-herdr-"));
|
|
34
|
+
const socketPath = join(root, "s");
|
|
35
|
+
let fake: FakeHerdrServer;
|
|
36
|
+
const server = net.createServer((socket) => {
|
|
37
|
+
let buffer = "";
|
|
38
|
+
socket.on("data", (chunk) => {
|
|
39
|
+
buffer += chunk.toString("utf8");
|
|
40
|
+
let newline: number;
|
|
41
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
42
|
+
const line = buffer.slice(0, newline);
|
|
43
|
+
buffer = buffer.slice(newline + 1);
|
|
44
|
+
if (!line) continue;
|
|
45
|
+
const request = JSON.parse(line) as FakeHerdrRequest;
|
|
46
|
+
fake.requests.push(request);
|
|
47
|
+
if (request.method === "events.subscribe") {
|
|
48
|
+
fake.subscribers.add(socket);
|
|
49
|
+
socket.write(JSON.stringify({ id: request.id, result: { type: "subscription_started" } }) + "\n");
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const result = request.method === "pane.get"
|
|
53
|
+
? { pane: { pane_id: fake.paneId, workspace_id: fake.workspaceId, monitor_resync_output: fake.resyncOutput } }
|
|
54
|
+
: request.method === "ping"
|
|
55
|
+
? { type: "pong", version: "fake", protocol: 14 }
|
|
56
|
+
: {};
|
|
57
|
+
socket.end(JSON.stringify({ id: request.id, result }) + "\n");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
socket.on("close", () => fake.subscribers.delete(socket));
|
|
61
|
+
});
|
|
62
|
+
fake = new FakeHerdrServer(socketPath, server, root, values.paneId, values.workspaceId, values.resyncOutput ?? { sequence: 0, text: "" });
|
|
63
|
+
await new Promise<void>((resolve, reject) => server.listen(socketPath, resolve).once("error", reject));
|
|
64
|
+
return fake;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setWorkspaceId(workspaceId: string): void {
|
|
68
|
+
this.workspaceId = workspaceId;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
emitStatus(): void {
|
|
72
|
+
for (const socket of this.subscribers) socket.write(JSON.stringify({ event: "pane.agent_status_changed", data: { pane_id: this.paneId } }) + "\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
disconnectSubscribers(): void {
|
|
76
|
+
for (const socket of this.subscribers) socket.destroy();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
subscriptionCount(): number {
|
|
80
|
+
return this.requests.filter((request) => request.method === "events.subscribe").length;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async close(): Promise<void> {
|
|
84
|
+
this.disconnectSubscribers();
|
|
85
|
+
await new Promise<void>((resolve) => this.server.close(() => resolve()));
|
|
86
|
+
fs.rmSync(this.root, { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -186,7 +186,7 @@ export interface TeamLayoutOptions {
|
|
|
186
186
|
// existing argv shapes; non-default projects are appended to hidden recipe
|
|
187
187
|
// positional args after model/session.
|
|
188
188
|
project?: string;
|
|
189
|
-
hub?: { command: string[]; label: string; ratio?: number };
|
|
189
|
+
hub?: { command: string[]; label: string; ratio?: number; cwd?: string; env?: Record<string, string> };
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
function paneNode(
|
|
@@ -234,7 +234,16 @@ function bsp(nodes: LayoutNode[], depth: number): LayoutNode {
|
|
|
234
234
|
export function buildTeamLayout(opts: TeamLayoutOptions): LayoutNode {
|
|
235
235
|
const { team, peers, repoRoot, envForPeer, resumeForPeer, delayForPeer, hub, project = DEFAULT_PROJECT } = opts;
|
|
236
236
|
validateProject(project);
|
|
237
|
-
if (peers.length === 0)
|
|
237
|
+
if (peers.length === 0) {
|
|
238
|
+
if (!hub) throw new Error(`Team "${team}" has no peers.`);
|
|
239
|
+
return {
|
|
240
|
+
type: "pane",
|
|
241
|
+
command: hub.command,
|
|
242
|
+
cwd: hub.cwd ?? repoRoot,
|
|
243
|
+
label: hub.label,
|
|
244
|
+
...(hub.env && Object.keys(hub.env).length > 0 ? { env: hub.env } : {}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
238
247
|
const panes = peers.map((p) => paneNode(p, team, repoRoot, envForPeer, resumeForPeer, project, delayForPeer));
|
|
239
248
|
const grid = bsp(panes, hub ? 1 : 0);
|
|
240
249
|
if (!hub) return grid;
|
|
@@ -242,7 +251,13 @@ export function buildTeamLayout(opts: TeamLayoutOptions): LayoutNode {
|
|
|
242
251
|
type: "split",
|
|
243
252
|
direction: "right",
|
|
244
253
|
ratio: hub.ratio ?? 0.4,
|
|
245
|
-
first: {
|
|
254
|
+
first: {
|
|
255
|
+
type: "pane",
|
|
256
|
+
command: hub.command,
|
|
257
|
+
cwd: hub.cwd ?? repoRoot,
|
|
258
|
+
label: hub.label,
|
|
259
|
+
...(hub.env && Object.keys(hub.env).length > 0 ? { env: hub.env } : {}),
|
|
260
|
+
},
|
|
246
261
|
second: grid,
|
|
247
262
|
};
|
|
248
263
|
}
|
|
@@ -117,9 +117,9 @@ export function formatTelegramQuestion(input: HermesBridgeQuestion, limit = TELE
|
|
|
117
117
|
if (!isValidQid(input.qid)) throw new Error("qid must be a 26-character Crockford ULID");
|
|
118
118
|
const options = input.options ?? [];
|
|
119
119
|
const header = `❓ [${HUB_Q_PREFIX}:${input.qid}] ${input.question}`;
|
|
120
|
-
const optionsBlock = options.length > 0 ? `\n\n
|
|
121
|
-
const instruction = `\n\n↩
|
|
122
|
-
const contextPrefix = input.context ? "\n\
|
|
120
|
+
const optionsBlock = options.length > 0 ? `\n\nOptions:\n${formatOptions(options)}` : "";
|
|
121
|
+
const instruction = `\n\n↩ Reply to this message, or type: ${HUB_Q_PREFIX}:${input.qid}: <answer>`;
|
|
122
|
+
const contextPrefix = input.context ? "\n\nContext: " : "";
|
|
123
123
|
const fixedLength = header.length + contextPrefix.length + optionsBlock.length + instruction.length;
|
|
124
124
|
const contextBudget = Math.max(0, limit - fixedLength);
|
|
125
125
|
const context = input.context ? truncateUtf16(input.context, contextBudget) : "";
|
|
@@ -199,7 +199,7 @@ export function timeoutErrorMessage(timeoutMs: number): string {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export function timeoutTelegramNote(qid: string, timeoutMs: number): string {
|
|
202
|
-
return `⌛ [${HUB_Q_PREFIX}:${qid}]
|
|
202
|
+
return `⌛ [${HUB_Q_PREFIX}:${qid}] The question timed out after ${timeoutMs}ms.`;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
export function timeoutOutcome(qid: string, timeoutMs = timeoutMsFromEnv()): {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { herdr, subscribe, type HerdrClientOptions, type SubscribeHandle } from "../../.pi/harnesses/lib/herdr-client.ts";
|
|
2
|
+
|
|
3
|
+
export interface HubCorrelation { workspaceId?: string; hubPaneId?: string; status: "correlated" | "uncorrelated" | "reconnecting"; }
|
|
4
|
+
|
|
5
|
+
export async function correlateHubPane(env: NodeJS.ProcessEnv = process.env, opts: HerdrClientOptions = {}): Promise<HubCorrelation> {
|
|
6
|
+
const hubPaneId = env.HERDR_PANE_ID;
|
|
7
|
+
if (env.HERDR_ENV !== "1" || !hubPaneId) return { status: "uncorrelated" };
|
|
8
|
+
try { const { pane } = await herdr.paneGet(hubPaneId, { socketPath: env.HERDR_SOCKET_PATH, ...opts }); return { workspaceId: pane.workspace_id, hubPaneId, status: "correlated" }; }
|
|
9
|
+
catch { return { hubPaneId, status: "reconnecting" }; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function watchHubMonitor(options: { env?: NodeJS.ProcessEnv; onStatus: (value: HubCorrelation) => void; onOutput?: (output: { sequence: number; text: string }) => void; initialCursor?: number; reconnectDelayMs?: number }): SubscribeHandle | null {
|
|
13
|
+
const env = options.env ?? process.env;
|
|
14
|
+
const paneId = env.HERDR_PANE_ID;
|
|
15
|
+
if (env.HERDR_ENV !== "1" || !paneId) { options.onStatus({ status: "uncorrelated" }); return null; }
|
|
16
|
+
let cursor = options.initialCursor ?? 0;
|
|
17
|
+
const refresh = async () => {
|
|
18
|
+
try {
|
|
19
|
+
const { pane } = await herdr.paneGet(paneId, { socketPath: env.HERDR_SOCKET_PATH });
|
|
20
|
+
options.onStatus({ workspaceId: pane.workspace_id, hubPaneId: paneId, status: "correlated" });
|
|
21
|
+
const output = (pane as { monitor_resync_output?: { sequence?: number; text?: string } }).monitor_resync_output;
|
|
22
|
+
if (output && typeof output.sequence === "number" && output.sequence > cursor && typeof output.text === "string") { cursor = output.sequence; options.onOutput?.({ sequence: output.sequence, text: output.text }); }
|
|
23
|
+
} catch { options.onStatus({ hubPaneId: paneId, status: "reconnecting" }); }
|
|
24
|
+
};
|
|
25
|
+
void refresh();
|
|
26
|
+
let connected = false;
|
|
27
|
+
return subscribe([{ type: "pane.agent_status_changed", pane_id: paneId }], () => void refresh(), { socketPath: env.HERDR_SOCKET_PATH, reconnectDelayMs: options.reconnectDelayMs, onConnect: () => { if (connected) options.onStatus({ hubPaneId: paneId, status: "reconnecting" }); connected = true; void refresh(); }, onError: () => options.onStatus({ hubPaneId: paneId, status: "reconnecting" }) });
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type MonitorTaskState = "starting" | "running" | "cancelling" | "completed" | "blocked" | "failed" | "cancelled" | "orphaned" | "recovering";
|
|
2
|
+
export const TERMINAL_TASK_STATES = new Set<MonitorTaskState>(["completed","blocked","failed","cancelled","orphaned"]);export type MonitorTaskKind="parent"|"child";
|
|
3
|
+
export interface MonitorTask{id:string;generation:number;kind:MonitorTaskKind;state:MonitorTaskState;parentId?:string;parentGeneration?:number;hubInstanceId?:string;checkoutId?:string;specialist?:string;workspaceId?:string;hubPaneId?:string;ownerSessionId?:string;ownerLeaseExpiresAt?:string;}
|
|
4
|
+
export interface CreateParentTaskInput{id:string;generation:number;hubInstanceId:string;checkoutId:string;ownerSessionId?:string;ownerLeaseExpiresAt?:string;}
|
|
5
|
+
export interface CreateChildTaskInput{id:string;generation:number;parentId:string;parentGeneration:number;specialist:string;workspaceId?:string;hubPaneId?:string;ownerSessionId?:string;ownerLeaseExpiresAt?:string;}
|
|
6
|
+
function requireStableIdentity(id:string,generation:number){if(!id)throw Error("task id is required");if(!Number.isInteger(generation)||generation<1)throw Error("task generation must be a positive integer");}const owner=(i:any)=>({...((i.ownerSessionId)?{ownerSessionId:i.ownerSessionId}:{}),...((i.ownerLeaseExpiresAt)?{ownerLeaseExpiresAt:i.ownerLeaseExpiresAt}:{})});
|
|
7
|
+
export function createParentTask(input:CreateParentTaskInput):MonitorTask{requireStableIdentity(input.id,input.generation);if(!input.hubInstanceId||!input.checkoutId)throw Error("parent correlation is required");return{id:input.id,generation:input.generation,kind:"parent",state:"starting",hubInstanceId:input.hubInstanceId,checkoutId:input.checkoutId,...owner(input)};}
|
|
8
|
+
export function createChildTask(input:CreateChildTaskInput):MonitorTask{requireStableIdentity(input.id,input.generation);if(!input.parentId||!Number.isInteger(input.parentGeneration)||input.parentGeneration<1||!input.specialist)throw Error("child hierarchy is required");return{id:input.id,generation:input.generation,kind:"child",state:"starting",parentId:input.parentId,parentGeneration:input.parentGeneration,specialist:input.specialist,...(input.workspaceId?{workspaceId:input.workspaceId}:{}),...(input.hubPaneId?{hubPaneId:input.hubPaneId}:{}),...owner(input)};}
|
|
9
|
+
export function transitionTask(task:MonitorTask,state:MonitorTaskState):MonitorTask{if(TERMINAL_TASK_STATES.has(task.state))throw Error(`terminal task ${task.id} cannot mutate`);if(state==="starting")throw Error("tasks cannot transition back to starting");return{...task,state};}export function continueTask(task:MonitorTask):MonitorTask{if(task.state!=="blocked")throw Error(`only blocked task ${task.id} can continue`);return{...task,generation:task.generation+1,state:"starting"};}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as crypto from "node:crypto"; import * as fs from "node:fs"; import * as path from "node:path";
|
|
2
|
+
export interface MonitorRegistration {profileKey:string;namespacePath:string;socketPath:string;socketDir:string;token:string;namespaceMode:number;tokenMode:number;discoveryPath:string;snapshot():unknown;cancel?(r:{taskId:string;generation:number}):unknown|Promise<unknown>;output?(r:{taskId:string;generation:number;afterSequence:number}):unknown|Promise<unknown>;cleanup():void;renew():void;leaseMs:number;ownerId?:string;leaseExpiresAt?:string;}
|
|
3
|
+
export interface MonitorRegistryOptions {runtimeDir:string;now?:()=>Date;pid?:number;leaseMs?:number;beforeRenewPublish?:()=>void;} export interface RegisterMonitorInput {profilePath:string;profileId?:string;hubInstanceId:string;snapshot:()=>unknown;}
|
|
4
|
+
const D=0o700,F=0o600;const validDiscovery=(d:any)=>typeof d?.owner==="string"&&/^[0-9a-f-]{36}$/i.test(d.owner)&&typeof d.token==="string"&&/^token-[0-9a-f-]{36}$/i.test(d.token)&&typeof d.socket==="string"&&/^@runtime\/s\/[a-f0-9]+\/s$/.test(d.socket)&&typeof d.lease?.hub==="string"&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(d.lease.hub)&&Number.isInteger(d.lease?.pid)&&d.lease.pid>0&&typeof d.lease?.startedAt==="string"&&!Number.isNaN(Date.parse(d.lease.startedAt))&&typeof d.lease?.expiresAt==="string"&&!Number.isNaN(Date.parse(d.lease.expiresAt));const mode=(p:string)=>fs.statSync(p).mode&0o777;function dir(p:string){if(!path.isAbsolute(p))throw Error("monitor runtime directory must be absolute");fs.mkdirSync(p,{recursive:true,mode:D});if(fs.lstatSync(p).isSymbolicLink())throw Error("monitor runtime directory must not be a symlink");fs.chmodSync(p,D);}export function canonicalMonitorProfileId(id:string){if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(id)||id.includes(".."))throw Error("monitor profile id is unsafe");return crypto.createHash("sha256").update(id).digest("hex");}function profile(p:string,id?:string){if(id)return canonicalMonitorProfileId(id);const real=fs.realpathSync(p);if(!fs.statSync(real).isDirectory())throw Error("monitor profile path must be a directory");return crypto.createHash("sha256").update(real).digest("hex");}function hub(id:string){if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(id)||id.includes(".."))throw Error("hub instance id is unsafe");return crypto.createHash("sha256").update(id).digest("hex");}function atomic(p:string,s:string){const t=`${p}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;fs.writeFileSync(t,s,{mode:F,flag:"wx"});fs.chmodSync(t,F);fs.renameSync(t,p);}
|
|
5
|
+
export class MonitorRegistry {private runtimeDir:string;private now:()=>Date;private pid:number;private leaseMs:number;private beforeRenewPublish?:()=>void;constructor(o:MonitorRegistryOptions){this.runtimeDir=o.runtimeDir;this.now=o.now??(()=>new Date());this.pid=o.pid??process.pid;this.leaseMs=o.leaseMs??30_000;this.beforeRenewPublish=o.beforeRenewPublish;dir(this.runtimeDir);}register(input:RegisterMonitorInput):MonitorRegistration{const key=profile(input.profilePath,input.profileId),h=hub(input.hubInstanceId),ns=path.join(this.runtimeDir,key,h);dir(path.join(this.runtimeDir,key));dir(ns);for(const file of fs.readdirSync(ns).filter(x=>x.startsWith("discovery-"))){const discoveryPath=path.join(ns,file);try{const d=JSON.parse(fs.readFileSync(discoveryPath,"utf8"));if(!validDiscovery(d)||d.token!==`token-${d.owner}`||d.socket!==`@runtime/s/${crypto.createHash("sha256").update(`${key}:${h}:${d.owner}`).digest("hex").slice(0,32)}/s`)throw new Error("monitor discovery metadata is malformed");if(new Date(d.lease?.expiresAt).getTime()>this.now().getTime()){const error:any=Error("monitor namespace is owned by an active lease");error.leaseExpiresAt=d.lease.expiresAt;throw error;}const tokenName=d.token;if(typeof tokenName==="string"&&/^token-[0-9a-f-]+$/.test(tokenName))try{fs.unlinkSync(path.join(ns,tokenName))}catch(e:any){if(e?.code!=="ENOENT")throw e;}fs.unlinkSync(discoveryPath);const socket=typeof d.socket==="string"?d.socket:"";if(socket.startsWith("@runtime/s/")&&socket.endsWith("/s")){const socketDir=path.join(this.runtimeDir,socket.slice("@runtime/".length,-2));if(socketDir.startsWith(path.join(this.runtimeDir,"s")+path.sep))try{fs.rmSync(socketDir,{recursive:true,force:true})}catch{}}}catch(e:any){if(/active lease|malformed/.test(String(e)))throw e;if(e instanceof SyntaxError||e instanceof TypeError||e instanceof RangeError)throw new Error("monitor discovery metadata is malformed");}}
|
|
6
|
+
const owner=crypto.randomUUID(),socketDir=path.join(this.runtimeDir,"s",crypto.createHash("sha256").update(`${key}:${h}:${owner}`).digest("hex").slice(0,32));dir(socketDir);const tokenPath=path.join(ns,`token-${owner}`),discoveryPath=path.join(ns,`discovery-${owner}.json`),socketPath=path.join(socketDir,"s"),token=crypto.randomBytes(32).toString("hex"),started=this.now();atomic(tokenPath,token);const tokenFd=fs.openSync(tokenPath,"r");const write=(issued:Date)=>atomic(discoveryPath,JSON.stringify({owner,socket:`@runtime/s/${path.basename(socketDir)}/s`,token:path.basename(tokenPath),lease:{hub:input.hubInstanceId,pid:this.pid,startedAt:started.toISOString(),expiresAt:new Date(issued.getTime()+this.leaseMs).toISOString()}}));write(started);const owns=()=>{try{return fs.fstatSync(tokenFd).nlink===1&&fs.readFileSync(tokenPath,"utf8")===token&&JSON.parse(fs.readFileSync(discoveryPath,"utf8")).owner===owner;}catch{return false;}};const cleanup=()=>{if(!owns())return;for(const p of [tokenPath,discoveryPath])try{fs.unlinkSync(p)}catch(e:any){if(e?.code!=="ENOENT")throw e;}finally{try{fs.closeSync(tokenFd)}catch{}}};return{profileKey:key,ownerId:owner,leaseExpiresAt:new Date(started.getTime()+this.leaseMs).toISOString(),namespacePath:ns,socketPath,socketDir,token,namespaceMode:mode(ns),tokenMode:mode(tokenPath),discoveryPath,snapshot:input.snapshot,cleanup,renew:()=>{if(!owns())throw Error("monitor ownership lost");this.beforeRenewPublish?.();if(!owns())throw Error("monitor ownership lost");const renewedAt=this.now();write(renewedAt);if(!owns()){try{if(JSON.parse(fs.readFileSync(discoveryPath,"utf8")).owner===owner)fs.unlinkSync(discoveryPath)}catch{}throw Error("monitor ownership lost");}return{leaseExpiresAt:new Date(renewedAt.getTime()+this.leaseMs).toISOString()};},leaseMs:this.leaseMs};} evidenceForOwner(ownerId:string,hubInstanceId:string){try{if(!/^[0-9a-f-]{36}$/i.test(ownerId))throw Error("malformed");const h=hub(hubInstanceId);for(const profileKey of fs.readdirSync(this.runtimeDir)){const p=path.join(this.runtimeDir,profileKey,h,`discovery-${ownerId}.json`);if(!fs.existsSync(p))continue;const d=JSON.parse(fs.readFileSync(p,"utf8"));if(!validDiscovery(d)||d.owner!==ownerId||d.token!==`token-${ownerId}`)throw Error("malformed");const token=path.join(path.dirname(p),d.token),socket=path.join(this.runtimeDir,d.socket.slice("@runtime/".length));return{owner:fs.existsSync(token),socket:fs.existsSync(socket),session:fs.existsSync(token),expired:new Date(d.lease.expiresAt).getTime()<=this.now().getTime()};}return{owner:false,socket:false,session:false,expired:true};}catch(error){return{transient:true,error};}}}
|
|
@@ -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}))}))};}});}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// already isolates peers by --project; this file only keeps team workspace
|
|
5
5
|
// labels, snapshot files, and generated launch argv in sync with that scope.
|
|
6
6
|
|
|
7
|
+
import * as os from "node:os";
|
|
7
8
|
import * as path from "node:path";
|
|
8
9
|
|
|
9
10
|
export const DEFAULT_PROJECT = "default";
|
|
@@ -13,6 +14,32 @@ export const DEFAULT_PROJECT = "default";
|
|
|
13
14
|
// like "acme.prod", but ".." is not allowed anywhere.
|
|
14
15
|
export const PROJECT_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
15
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
|
+
}
|
|
16
43
|
|
|
17
44
|
export function validateProject(project: string): string {
|
|
18
45
|
if (
|
|
@@ -71,7 +98,7 @@ export function parseProjectFlag(argv: string[]): string {
|
|
|
71
98
|
// on a shared `pi-hub-<team>`. Pass `tag` from worktreeTag(REPO_ROOT); it
|
|
72
99
|
// defaults to "repo" only for callers that have no checkout in hand.
|
|
73
100
|
export function teamWorkspaceLabel(
|
|
74
|
-
kind:
|
|
101
|
+
kind: WorkspaceMode,
|
|
75
102
|
team: string,
|
|
76
103
|
project = DEFAULT_PROJECT,
|
|
77
104
|
tag = "repo",
|
|
@@ -91,6 +118,63 @@ export function conductorCommand(): string[] {
|
|
|
91
118
|
return ["hermes", "-p", "dev"];
|
|
92
119
|
}
|
|
93
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
|
+
|
|
94
178
|
export function teamSnapshotPath(snapshotDir: string, team: string, project = DEFAULT_PROJECT): string {
|
|
95
179
|
validateTeamName(team);
|
|
96
180
|
validateProject(project);
|