@chankov/agent-fleet 0.0.11 → 1.0.0

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.
Files changed (494) hide show
  1. package/.pi/extensions/agent-fleet-update-check/README.md +4 -4
  2. package/.pi/extensions/btw/README.md +26 -25
  3. package/.pi/extensions/btw/index.ts +80 -83
  4. package/.pi/extensions/pi-voice-stt/README.md +4 -3
  5. package/.pi/extensions/pi-voice-stt/config.ts +1 -1
  6. package/.pi/harnesses/agent-hub/README.md +106 -54
  7. package/.pi/harnesses/agent-hub/backend-policy.js +25 -4
  8. package/.pi/harnesses/agent-hub/footer.ts +4 -0
  9. package/.pi/harnesses/agent-hub/helpers.ts +18 -0
  10. package/.pi/harnesses/agent-hub/index.ts +537 -369
  11. package/.pi/harnesses/agent-hub/monitor-session-bridge.ts +10 -1
  12. package/.pi/harnesses/agent-hub/package.json +1 -1
  13. package/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  14. package/.pi/harnesses/agent-hub/posture.ts +103 -0
  15. package/.pi/harnesses/ask-user-remote/README.md +37 -3
  16. package/.pi/harnesses/ask-user-remote/index.ts +173 -17
  17. package/.pi/harnesses/coms/package.json +1 -1
  18. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  19. package/.pi/harnesses/lib/fleet-dashboard-ops.ts +118 -0
  20. package/.pi/harnesses/lib/fleet-dashboard-view.ts +140 -0
  21. package/.pi/harnesses/lib/fleet-detail-view.ts +43 -0
  22. package/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  23. package/.pi/harnesses/lib/fleet-panel.ts +34 -0
  24. package/.pi/harnesses/lib/fleet-read-model.ts +131 -0
  25. package/.pi/harnesses/lib/fleet-selection.ts +24 -0
  26. package/.pi/harnesses/package-lock.json +2011 -0
  27. package/.pi/harnesses/package.json +1 -0
  28. package/.versions/0.0.11/.pi/extensions/agent-fleet-update-check/README.md +4 -4
  29. package/.versions/0.0.11/.pi/extensions/pi-voice-stt/README.md +4 -3
  30. package/.versions/0.0.11/.pi/extensions/pi-voice-stt/config.ts +1 -1
  31. package/.versions/0.0.11/.pi/harnesses/agent-hub/monitor-session-bridge.ts +10 -1
  32. package/.versions/0.0.11/.pi/harnesses/ask-user-remote/README.md +37 -3
  33. package/.versions/0.0.11/.pi/harnesses/ask-user-remote/index.ts +173 -17
  34. package/.versions/0.0.11/.pi/harnesses/package-lock.json +2011 -0
  35. package/.versions/0.0.11/.pi/harnesses/package.json +1 -0
  36. package/.versions/0.0.11/docs/ARCHITECTURE.md +6 -8
  37. package/.versions/0.0.11/docs/agent-fleet-setup.md +17 -43
  38. package/.versions/0.0.11/docs/claude-code-coms-bridge.md +20 -2
  39. package/.versions/0.0.11/docs/coms-hermes-bridge.md +1 -1
  40. package/.versions/0.0.11/docs/getting-started.md +26 -237
  41. package/.versions/0.0.11/docs/npm-install.md +60 -478
  42. package/.versions/0.0.11/docs/pi-extensions.md +4 -4
  43. package/.versions/0.0.11/docs/pi-setup.md +37 -551
  44. package/.versions/0.0.11/hermes/README.md +1 -1
  45. package/.versions/0.0.11/install-manifest.json +375 -1247
  46. package/.versions/0.0.11/justfile +13 -6
  47. package/.versions/0.0.11/manifest-meta.json +543 -134
  48. package/.versions/0.0.11/scripts/lib/fleet-command.ts +8 -0
  49. package/.versions/0.0.11/scripts/lib/monitor-env.ts +18 -6
  50. package/.versions/0.0.11/skills/designing-agents/SKILL.md +1 -1
  51. package/.versions/0.0.11/skills/designing-agents/pi-harness-authoring.md +1 -1
  52. package/.versions/1.0.0/.pi/agents/dispatch-policy.yaml +32 -0
  53. package/.versions/1.0.0/.pi/agents/model-profiles.yaml +27 -0
  54. package/.versions/1.0.0/.pi/agents/peers.yaml +142 -0
  55. package/.versions/1.0.0/.pi/agents/teams.yaml +41 -0
  56. package/.versions/1.0.0/.pi/damage-control-rules.yaml +297 -0
  57. package/.versions/1.0.0/.pi/extensions/agent-fleet-update-check/README.md +57 -0
  58. package/.versions/1.0.0/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
  59. package/.versions/1.0.0/.pi/extensions/agent-fleet-update-check/package.json +6 -0
  60. package/.versions/1.0.0/.pi/extensions/btw/README.md +120 -0
  61. package/.versions/1.0.0/.pi/extensions/btw/index.ts +914 -0
  62. package/.versions/1.0.0/.pi/extensions/btw/package.json +6 -0
  63. package/.versions/1.0.0/.pi/extensions/btw/state.js +179 -0
  64. package/.versions/1.0.0/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  65. package/.versions/1.0.0/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  66. package/.versions/1.0.0/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  67. package/.versions/1.0.0/.pi/extensions/compact-and-continue/README.md +42 -0
  68. package/.versions/1.0.0/.pi/extensions/compact-and-continue/index.ts +120 -0
  69. package/.versions/1.0.0/.pi/extensions/compact-and-continue/package.json +6 -0
  70. package/.versions/1.0.0/.pi/extensions/mcp-bridge/README.md +46 -0
  71. package/.versions/1.0.0/.pi/extensions/mcp-bridge/index.ts +206 -0
  72. package/.versions/1.0.0/.pi/extensions/mcp-bridge/package.json +6 -0
  73. package/.versions/1.0.0/.pi/extensions/package-lock.json +1143 -0
  74. package/.versions/1.0.0/.pi/extensions/package.json +9 -0
  75. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/README.md +205 -0
  76. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/config.ts +198 -0
  77. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  78. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/index.ts +248 -0
  79. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/package.json +6 -0
  80. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  81. package/.versions/1.0.0/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  82. package/.versions/1.0.0/.pi/harnesses/agent-hub/README.md +1056 -0
  83. package/.versions/1.0.0/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  84. package/.versions/1.0.0/.pi/harnesses/agent-hub/artifacts.js +146 -0
  85. package/.versions/1.0.0/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  86. package/.versions/1.0.0/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  87. package/.versions/1.0.0/.pi/harnesses/agent-hub/context-window.js +106 -0
  88. package/.versions/1.0.0/.pi/harnesses/agent-hub/delegate.ts +435 -0
  89. package/.versions/1.0.0/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  90. package/.versions/1.0.0/.pi/harnesses/agent-hub/drift-watchdog.js +211 -0
  91. package/.versions/1.0.0/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  92. package/.versions/1.0.0/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  93. package/.versions/1.0.0/.pi/harnesses/agent-hub/footer.ts +35 -0
  94. package/.versions/1.0.0/.pi/harnesses/agent-hub/helpers.ts +266 -0
  95. package/.versions/1.0.0/.pi/harnesses/agent-hub/index.ts +9279 -0
  96. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  97. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  98. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  99. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  100. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  101. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  102. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  103. package/.versions/1.0.0/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  104. package/.versions/1.0.0/.pi/harnesses/agent-hub/package.json +7 -0
  105. package/.versions/1.0.0/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  106. package/.versions/1.0.0/.pi/harnesses/agent-hub/posture.ts +103 -0
  107. package/.versions/1.0.0/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  108. package/.versions/1.0.0/.pi/harnesses/agent-hub/research-retention.js +34 -0
  109. package/.versions/1.0.0/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  110. package/.versions/1.0.0/.pi/harnesses/agent-hub/return-contract.js +293 -0
  111. package/.versions/1.0.0/.pi/harnesses/agent-hub/return-extract.js +75 -0
  112. package/.versions/1.0.0/.pi/harnesses/agent-hub/review-findings.js +102 -0
  113. package/.versions/1.0.0/.pi/harnesses/agent-hub/run-budget.js +479 -0
  114. package/.versions/1.0.0/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  115. package/.versions/1.0.0/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  116. package/.versions/1.0.0/.pi/harnesses/agent-hub/scope-gate.js +103 -0
  117. package/.versions/1.0.0/.pi/harnesses/agent-hub/session-health.js +110 -0
  118. package/.versions/1.0.0/.pi/harnesses/agent-hub/spawn.ts +354 -0
  119. package/.versions/1.0.0/.pi/harnesses/agent-hub/version.ts +42 -0
  120. package/.versions/1.0.0/.pi/harnesses/ask-user-remote/README.md +53 -0
  121. package/.versions/1.0.0/.pi/harnesses/ask-user-remote/index.ts +477 -0
  122. package/.versions/1.0.0/.pi/harnesses/ask-user-remote/race-core.js +106 -0
  123. package/.versions/1.0.0/.pi/harnesses/coms/README.md +100 -0
  124. package/.versions/1.0.0/.pi/harnesses/coms/index.ts +1767 -0
  125. package/.versions/1.0.0/.pi/harnesses/coms/package.json +7 -0
  126. package/.versions/1.0.0/.pi/harnesses/coms/version.ts +42 -0
  127. package/.versions/1.0.0/.pi/harnesses/damage-control-continue/README.md +124 -0
  128. package/.versions/1.0.0/.pi/harnesses/damage-control-continue/index.ts +536 -0
  129. package/.versions/1.0.0/.pi/harnesses/damage-control-continue/package.json +7 -0
  130. package/.versions/1.0.0/.pi/harnesses/damage-control-continue/version.ts +42 -0
  131. package/.versions/1.0.0/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  132. package/.versions/1.0.0/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  133. package/.versions/1.0.0/.pi/harnesses/lib/fleet-dashboard-ops.ts +118 -0
  134. package/.versions/1.0.0/.pi/harnesses/lib/fleet-dashboard-view.ts +140 -0
  135. package/.versions/1.0.0/.pi/harnesses/lib/fleet-detail-view.ts +43 -0
  136. package/.versions/1.0.0/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  137. package/.versions/1.0.0/.pi/harnesses/lib/fleet-panel.ts +34 -0
  138. package/.versions/1.0.0/.pi/harnesses/lib/fleet-read-model.ts +131 -0
  139. package/.versions/1.0.0/.pi/harnesses/lib/fleet-selection.ts +24 -0
  140. package/.versions/1.0.0/.pi/harnesses/lib/herdr-client.ts +472 -0
  141. package/.versions/1.0.0/.pi/harnesses/lib/herdr-presence.ts +399 -0
  142. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  143. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  144. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  145. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  146. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  147. package/.versions/1.0.0/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  148. package/.versions/1.0.0/.pi/harnesses/lib/spawned-peers.js +190 -0
  149. package/.versions/1.0.0/.pi/harnesses/package-lock.json +2046 -0
  150. package/.versions/1.0.0/.pi/harnesses/package.json +10 -0
  151. package/.versions/1.0.0/.pi/prompts/af-build.md +24 -0
  152. package/{.claude/commands/code-simplify.md → .versions/1.0.0/.pi/prompts/af-code-simplify.md} +3 -3
  153. package/{.claude/commands/plan.md → .versions/1.0.0/.pi/prompts/af-plan.md} +1 -1
  154. package/.versions/{0.0.11/.claude/commands/review.md → 1.0.0/.pi/prompts/af-review.md} +3 -3
  155. package/.versions/1.0.0/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  156. package/.versions/1.0.0/.pi/prompts/af-ship.md +17 -0
  157. package/.versions/{0.0.11/.claude/commands/spec.md → 1.0.0/.pi/prompts/af-spec.md} +1 -1
  158. package/.versions/{0.0.11/.claude/commands/test.md → 1.0.0/.pi/prompts/af-test.md} +2 -2
  159. package/.versions/1.0.0/.pi/skills/bowser/SKILL.md +145 -0
  160. package/.versions/1.0.0/.version +1 -0
  161. package/.versions/1.0.0/agents/architect.md +24 -0
  162. package/.versions/1.0.0/agents/bowser.md +27 -0
  163. package/.versions/1.0.0/agents/builder.md +54 -0
  164. package/.versions/1.0.0/agents/code-reviewer.md +208 -0
  165. package/.versions/1.0.0/agents/deep-researcher.md +32 -0
  166. package/.versions/1.0.0/agents/documenter.md +18 -0
  167. package/.versions/1.0.0/agents/orchestrator.md +72 -0
  168. package/.versions/1.0.0/agents/plan-reviewer.md +83 -0
  169. package/.versions/1.0.0/agents/planner.md +70 -0
  170. package/.versions/1.0.0/agents/releaser.md +24 -0
  171. package/.versions/1.0.0/agents/researcher.md +28 -0
  172. package/.versions/1.0.0/agents/security-auditor.md +167 -0
  173. package/.versions/1.0.0/agents/test-engineer.md +153 -0
  174. package/.versions/1.0.0/agents/web-debugger.md +43 -0
  175. package/.versions/1.0.0/agents/web-performance-auditor.md +193 -0
  176. package/.versions/1.0.0/codex/CONDUCTOR.md +148 -0
  177. package/.versions/1.0.0/docs/ARCHITECTURE.md +337 -0
  178. package/.versions/1.0.0/docs/agent-fleet-setup.md +437 -0
  179. package/.versions/1.0.0/docs/claude-code-coms-bridge.md +128 -0
  180. package/.versions/1.0.0/docs/codex-remote-conductor.md +170 -0
  181. package/.versions/1.0.0/docs/coms-hermes-bridge.md +189 -0
  182. package/.versions/1.0.0/docs/getting-started.md +98 -0
  183. package/.versions/1.0.0/docs/npm-install.md +292 -0
  184. package/.versions/1.0.0/docs/pi-extensions.md +412 -0
  185. package/.versions/1.0.0/docs/pi-setup.md +74 -0
  186. package/.versions/1.0.0/docs/skill-anatomy.md +150 -0
  187. package/.versions/1.0.0/hermes/README.md +347 -0
  188. package/.versions/1.0.0/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  189. package/.versions/1.0.0/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  190. package/.versions/1.0.0/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  191. package/.versions/1.0.0/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  192. package/.versions/1.0.0/hermes/gates/gate-o-capability.md +8 -0
  193. package/.versions/1.0.0/hermes/gates/gate-o-validator-fixtures.json +1 -0
  194. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
  195. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  196. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  197. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  198. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  199. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  200. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  201. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  202. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  203. package/.versions/1.0.0/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  204. package/.versions/1.0.0/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  205. package/.versions/1.0.0/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  206. package/.versions/1.0.0/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  207. package/.versions/1.0.0/hermes/skills/hub-conductor/SKILL.md +84 -0
  208. package/.versions/1.0.0/hermes/skills/hub-liaison/SKILL.md +84 -0
  209. package/.versions/1.0.0/hermes/skills/hub-watchdog/SKILL.md +76 -0
  210. package/.versions/1.0.0/hermes/skills/hub-watchdog/manifest.json +1 -0
  211. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  212. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  213. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  214. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  215. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  216. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  217. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  218. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  219. package/.versions/1.0.0/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  220. package/.versions/1.0.0/hermes/watchdog-tests/__init__.py +0 -0
  221. package/.versions/1.0.0/hooks/coms-stop-hook.mjs +84 -0
  222. package/.versions/1.0.0/install-manifest.json +2745 -0
  223. package/.versions/1.0.0/justfile +272 -0
  224. package/.versions/1.0.0/manifest-meta.json +882 -0
  225. package/.versions/1.0.0/references/accessibility-checklist.md +160 -0
  226. package/.versions/1.0.0/references/definition-of-done.md +67 -0
  227. package/.versions/1.0.0/references/fleet-coordination-patterns.md +151 -0
  228. package/.versions/1.0.0/references/observability-checklist.md +91 -0
  229. package/.versions/1.0.0/references/orchestration-patterns.md +370 -0
  230. package/.versions/1.0.0/references/performance-checklist.md +153 -0
  231. package/.versions/1.0.0/references/prompting-patterns.md +380 -0
  232. package/.versions/1.0.0/references/security-checklist.md +179 -0
  233. package/.versions/1.0.0/references/testing-patterns.md +236 -0
  234. package/.versions/1.0.0/scripts/codex-conductor.ts +41 -0
  235. package/.versions/1.0.0/scripts/codex-remote-control.ts +167 -0
  236. package/.versions/1.0.0/scripts/coms-claude-bridge.ts +411 -0
  237. package/.versions/1.0.0/scripts/coms-cli.ts +484 -0
  238. package/.versions/1.0.0/scripts/coms-hermes-bridge.ts +413 -0
  239. package/.versions/1.0.0/scripts/fleet.ts +185 -0
  240. package/.versions/1.0.0/scripts/hermes-monitor-capability-runner.ts +25 -0
  241. package/.versions/1.0.0/scripts/hermes-monitor-scenario.ts +474 -0
  242. package/.versions/1.0.0/scripts/hermes-watchdog-capability-probe.ts +45 -0
  243. package/.versions/1.0.0/scripts/install-hermes-plugin.sh +180 -0
  244. package/.versions/1.0.0/scripts/lib/claude-bridge-core.ts +210 -0
  245. package/.versions/1.0.0/scripts/lib/codex-conductor.ts +88 -0
  246. package/.versions/1.0.0/scripts/lib/codex-remote-control.ts +480 -0
  247. package/.versions/1.0.0/scripts/lib/coms-envelope.ts +582 -0
  248. package/.versions/1.0.0/scripts/lib/fake-herdr-server.ts +88 -0
  249. package/.versions/1.0.0/scripts/lib/fleet-command.ts +266 -0
  250. package/.versions/1.0.0/scripts/lib/herdr-layout.ts +281 -0
  251. package/.versions/1.0.0/scripts/lib/hermes-bridge-core.ts +241 -0
  252. package/.versions/1.0.0/scripts/lib/hermes-monitor-events.ts +1 -0
  253. package/.versions/1.0.0/scripts/lib/hermes-monitor-herdr.ts +2 -0
  254. package/.versions/1.0.0/scripts/lib/hermes-monitor-model.ts +3 -0
  255. package/.versions/1.0.0/scripts/lib/hermes-monitor-registry.ts +2 -0
  256. package/.versions/1.0.0/scripts/lib/hermes-monitor-socket.ts +2 -0
  257. package/.versions/1.0.0/scripts/lib/hermes-monitor-store.ts +2 -0
  258. package/.versions/1.0.0/scripts/lib/monitor-env.ts +146 -0
  259. package/.versions/1.0.0/scripts/lib/peer-launch.ts +318 -0
  260. package/.versions/1.0.0/scripts/lib/persona-banner.ts +62 -0
  261. package/.versions/1.0.0/scripts/lib/spawn-stagger.ts +101 -0
  262. package/.versions/1.0.0/scripts/lib/team-project.ts +213 -0
  263. package/.versions/1.0.0/scripts/lib/team-snapshot.ts +147 -0
  264. package/.versions/1.0.0/scripts/peer-banner.ts +40 -0
  265. package/.versions/1.0.0/scripts/peer-launch.ts +259 -0
  266. package/.versions/1.0.0/scripts/team-snapshot.ts +237 -0
  267. package/.versions/1.0.0/scripts/team-up.ts +406 -0
  268. package/.versions/1.0.0/skills/_internal/grilling.md +11 -0
  269. package/.versions/1.0.0/skills/browser-testing-with-devtools/SKILL.md +351 -0
  270. package/.versions/1.0.0/skills/code-review-and-quality/SKILL.md +381 -0
  271. package/.versions/1.0.0/skills/compound-learning/SKILL.md +137 -0
  272. package/.versions/1.0.0/skills/context-engineering/SKILL.md +291 -0
  273. package/.versions/1.0.0/skills/deprecation-and-migration/SKILL.md +206 -0
  274. package/.versions/1.0.0/skills/designing-agents/SKILL.md +394 -0
  275. package/.versions/1.0.0/skills/designing-agents/pi-harness-authoring.md +222 -0
  276. package/.versions/1.0.0/skills/frontend-ui-engineering/SKILL.md +328 -0
  277. package/.versions/1.0.0/skills/git-workflow-and-versioning/SKILL.md +316 -0
  278. package/.versions/1.0.0/skills/idea-refine/SKILL.md +182 -0
  279. package/.versions/1.0.0/skills/idea-refine/examples.md +238 -0
  280. package/.versions/1.0.0/skills/idea-refine/frameworks.md +99 -0
  281. package/.versions/1.0.0/skills/idea-refine/refinement-criteria.md +113 -0
  282. package/.versions/1.0.0/skills/idea-refine/scripts/idea-refine.sh +15 -0
  283. package/.versions/1.0.0/skills/incremental-implementation/SKILL.md +287 -0
  284. package/.versions/1.0.0/skills/interview-me/SKILL.md +226 -0
  285. package/.versions/1.0.0/skills/orchestration-verification/SKILL.md +181 -0
  286. package/.versions/1.0.0/skills/peer-coms/SKILL.md +90 -0
  287. package/.versions/1.0.0/skills/performance-optimization/SKILL.md +350 -0
  288. package/.versions/1.0.0/skills/planning-and-task-breakdown/SKILL.md +254 -0
  289. package/.versions/1.0.0/skills/security-and-hardening/SKILL.md +461 -0
  290. package/.versions/1.0.0/skills/spec-driven-development/SKILL.md +257 -0
  291. package/.versions/1.0.0/skills/using-agent-skills/SKILL.md +199 -0
  292. package/.versions/1.0.0/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
  293. package/.versions/1.0.0/vendor/agent-skills-upstream/LICENSE +21 -0
  294. package/.versions/1.0.0/vendor/agent-skills-upstream/README.md +11 -0
  295. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
  296. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  297. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  298. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  299. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  300. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
  301. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  302. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  303. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
  304. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  305. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  306. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  307. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  308. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  309. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  310. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  311. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  312. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  313. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  314. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
  315. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
  316. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
  317. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
  318. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
  319. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
  320. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
  321. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
  322. package/.versions/1.0.0/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
  323. package/CHANGELOG.md +142 -0
  324. package/README.md +117 -79
  325. package/agents/orchestrator.md +1 -1
  326. package/bin/cli.js +289 -359
  327. package/bin/force-patch-changesets.js +18 -2
  328. package/bin/lib/apply.js +86 -32
  329. package/bin/lib/desired.js +87 -0
  330. package/bin/lib/detect-agent.js +22 -38
  331. package/bin/lib/doctor.js +283 -33
  332. package/bin/lib/features.js +78 -0
  333. package/bin/lib/manifest.js +127 -48
  334. package/bin/lib/overrides.js +35 -0
  335. package/bin/lib/personas.js +37 -0
  336. package/bin/lib/plan.js +18 -9
  337. package/bin/lib/purge.js +11 -0
  338. package/bin/lib/reconcile.js +68 -0
  339. package/bin/lib/scan.js +24 -0
  340. package/bin/lib/state.js +25 -1
  341. package/bin/lib/stt-wizard.js +33 -0
  342. package/bin/lib/transaction.js +149 -0
  343. package/bin/lib/tui.js +71 -0
  344. package/bin/lib/verify.js +9 -26
  345. package/bin/snapshot-version.js +3 -6
  346. package/docs/ARCHITECTURE.md +55 -21
  347. package/docs/MIGRATION-agent-fleet.md +222 -0
  348. package/docs/agent-fleet-setup.md +124 -64
  349. package/docs/claude-code-coms-bridge.md +21 -2
  350. package/docs/coms-hermes-bridge.md +1 -1
  351. package/docs/getting-started.md +61 -217
  352. package/docs/npm-install.md +207 -429
  353. package/docs/pi-extensions.md +85 -41
  354. package/docs/pi-setup.md +48 -545
  355. package/hermes/README.md +1 -1
  356. package/install-manifest.json +385 -1255
  357. package/justfile +45 -27
  358. package/manifest-meta.json +544 -134
  359. package/node_modules/pi-ask-user/README.md +43 -5
  360. package/node_modules/pi-ask-user/index.ts +630 -75
  361. package/node_modules/pi-ask-user/package.json +1 -1
  362. package/package.json +5 -11
  363. package/scripts/coms-claude-bridge.ts +10 -0
  364. package/scripts/fleet.ts +107 -90
  365. package/scripts/lib/claude-bridge-core.ts +45 -0
  366. package/scripts/lib/fleet-command.ts +170 -15
  367. package/scripts/lib/monitor-env.ts +18 -6
  368. package/scripts/lib/peer-launch.ts +6 -2
  369. package/scripts/lib/team-project.ts +24 -4
  370. package/scripts/team-up.ts +57 -11
  371. package/skills/designing-agents/SKILL.md +1 -1
  372. package/skills/designing-agents/pi-harness-authoring.md +3 -3
  373. package/.claude/commands/build.md +0 -44
  374. package/.claude/commands/design-agent.md +0 -14
  375. package/.claude/commands/doctor-agent-fleet.md +0 -22
  376. package/.claude/commands/orchestrate.md +0 -112
  377. package/.claude/commands/prime.md +0 -22
  378. package/.claude/commands/review.md +0 -16
  379. package/.claude/commands/set-hermes-telegram.md +0 -15
  380. package/.claude/commands/set-hermes-watchdog.md +0 -6
  381. package/.claude/commands/setup-agent-fleet.md +0 -17
  382. package/.claude/commands/ship.md +0 -72
  383. package/.claude/commands/spec.md +0 -15
  384. package/.claude/commands/test.md +0 -19
  385. package/.claude/commands/webperf.md +0 -32
  386. package/.claude/orchestrate-teams.yaml +0 -24
  387. package/.opencode/commands/af-build.md +0 -17
  388. package/.opencode/commands/af-code-simplify.md +0 -16
  389. package/.opencode/commands/af-compound.md +0 -16
  390. package/.opencode/commands/af-design-agent.md +0 -15
  391. package/.opencode/commands/af-doctor-agent-fleet.md +0 -22
  392. package/.opencode/commands/af-orchestrate.md +0 -112
  393. package/.opencode/commands/af-plan.md +0 -16
  394. package/.opencode/commands/af-prime.md +0 -22
  395. package/.opencode/commands/af-review.md +0 -15
  396. package/.opencode/commands/af-set-hermes-watchdog.md +0 -6
  397. package/.opencode/commands/af-setup-agent-fleet.md +0 -17
  398. package/.opencode/commands/af-ship.md +0 -16
  399. package/.opencode/commands/af-spec.md +0 -16
  400. package/.opencode/commands/af-test.md +0 -21
  401. package/.opencode/commands/af-webperf.md +0 -32
  402. package/.opencode/orchestrate-teams.yaml +0 -24
  403. package/.pi/prompts/af-doctor-agent-fleet.md +0 -22
  404. package/.pi/prompts/af-setup-agent-fleet.md +0 -19
  405. package/.versions/0.0.1/.opencode/commands/af-doctor-agent-fleet.md +0 -15
  406. package/.versions/0.0.1/.opencode/commands/af-setup-agent-fleet.md +0 -15
  407. package/.versions/0.0.1/skills/guided-workspace-setup/SKILL.md +0 -506
  408. package/.versions/0.0.10/.opencode/commands/af-doctor-agent-fleet.md +0 -22
  409. package/.versions/0.0.10/.opencode/commands/af-setup-agent-fleet.md +0 -17
  410. package/.versions/0.0.10/.pi/prompts/af-doctor-agent-fleet.md +0 -22
  411. package/.versions/0.0.10/.pi/prompts/af-setup-agent-fleet.md +0 -19
  412. package/.versions/0.0.10/skills/guided-workspace-setup/SKILL.md +0 -226
  413. package/.versions/0.0.11/.claude/commands/build.md +0 -44
  414. package/.versions/0.0.11/.claude/commands/code-simplify.md +0 -22
  415. package/.versions/0.0.11/.claude/commands/design-agent.md +0 -14
  416. package/.versions/0.0.11/.claude/commands/doctor-agent-fleet.md +0 -22
  417. package/.versions/0.0.11/.claude/commands/orchestrate.md +0 -112
  418. package/.versions/0.0.11/.claude/commands/plan.md +0 -16
  419. package/.versions/0.0.11/.claude/commands/prime.md +0 -22
  420. package/.versions/0.0.11/.claude/commands/set-hermes-telegram.md +0 -15
  421. package/.versions/0.0.11/.claude/commands/set-hermes-watchdog.md +0 -6
  422. package/.versions/0.0.11/.claude/commands/setup-agent-fleet.md +0 -17
  423. package/.versions/0.0.11/.claude/commands/ship.md +0 -72
  424. package/.versions/0.0.11/.claude/commands/webperf.md +0 -32
  425. package/.versions/0.0.11/.claude/orchestrate-teams.yaml +0 -24
  426. package/.versions/0.0.11/.opencode/commands/af-build.md +0 -17
  427. package/.versions/0.0.11/.opencode/commands/af-code-simplify.md +0 -16
  428. package/.versions/0.0.11/.opencode/commands/af-compound.md +0 -16
  429. package/.versions/0.0.11/.opencode/commands/af-design-agent.md +0 -15
  430. package/.versions/0.0.11/.opencode/commands/af-doctor-agent-fleet.md +0 -22
  431. package/.versions/0.0.11/.opencode/commands/af-orchestrate.md +0 -112
  432. package/.versions/0.0.11/.opencode/commands/af-plan.md +0 -16
  433. package/.versions/0.0.11/.opencode/commands/af-prime.md +0 -22
  434. package/.versions/0.0.11/.opencode/commands/af-review.md +0 -15
  435. package/.versions/0.0.11/.opencode/commands/af-set-hermes-telegram.md +0 -15
  436. package/.versions/0.0.11/.opencode/commands/af-set-hermes-watchdog.md +0 -6
  437. package/.versions/0.0.11/.opencode/commands/af-setup-agent-fleet.md +0 -17
  438. package/.versions/0.0.11/.opencode/commands/af-ship.md +0 -16
  439. package/.versions/0.0.11/.opencode/commands/af-spec.md +0 -16
  440. package/.versions/0.0.11/.opencode/commands/af-test.md +0 -21
  441. package/.versions/0.0.11/.opencode/commands/af-webperf.md +0 -32
  442. package/.versions/0.0.11/.opencode/orchestrate-teams.yaml +0 -24
  443. package/.versions/0.0.11/.pi/prompts/af-doctor-agent-fleet.md +0 -22
  444. package/.versions/0.0.11/.pi/prompts/af-setup-agent-fleet.md +0 -19
  445. package/.versions/0.0.11/docs/opencode-setup.md +0 -281
  446. package/.versions/0.0.11/hooks/SIMPLIFY-IGNORE.md +0 -90
  447. package/.versions/0.0.11/hooks/hooks.json +0 -14
  448. package/.versions/0.0.11/hooks/session-start.sh +0 -74
  449. package/.versions/0.0.11/hooks/simplify-ignore.sh +0 -302
  450. package/.versions/0.0.11/skills/guided-workspace-setup/SKILL.md +0 -226
  451. package/.versions/0.0.4/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  452. package/.versions/0.0.4/.opencode/commands/af-setup-agent-fleet.md +0 -15
  453. package/.versions/0.0.4/skills/guided-workspace-setup/SKILL.md +0 -535
  454. package/.versions/0.0.4/skills/guided-workspace-setup/companion-manifest.json +0 -33
  455. package/.versions/0.0.5/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  456. package/.versions/0.0.5/.opencode/commands/af-setup-agent-fleet.md +0 -15
  457. package/.versions/0.0.5/skills/guided-workspace-setup/SKILL.md +0 -542
  458. package/.versions/0.0.5/skills/guided-workspace-setup/companion-manifest.json +0 -35
  459. package/.versions/0.0.6/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  460. package/.versions/0.0.6/.opencode/commands/af-setup-agent-fleet.md +0 -15
  461. package/.versions/0.0.6/.pi/prompts/af-doctor-agent-fleet.md +0 -15
  462. package/.versions/0.0.6/.pi/prompts/af-setup-agent-fleet.md +0 -27
  463. package/.versions/0.0.6/skills/guided-workspace-setup/SKILL.md +0 -544
  464. package/.versions/0.0.6/skills/guided-workspace-setup/companion-manifest.json +0 -35
  465. package/.versions/0.0.7/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  466. package/.versions/0.0.7/.opencode/commands/af-setup-agent-fleet.md +0 -15
  467. package/.versions/0.0.7/.pi/prompts/af-doctor-agent-fleet.md +0 -15
  468. package/.versions/0.0.7/.pi/prompts/af-setup-agent-fleet.md +0 -27
  469. package/.versions/0.0.7/skills/guided-workspace-setup/SKILL.md +0 -544
  470. package/.versions/0.0.7/skills/guided-workspace-setup/companion-manifest.json +0 -35
  471. package/.versions/0.0.8/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  472. package/.versions/0.0.8/.opencode/commands/af-setup-agent-fleet.md +0 -15
  473. package/.versions/0.0.8/.pi/prompts/af-doctor-agent-fleet.md +0 -15
  474. package/.versions/0.0.8/.pi/prompts/af-setup-agent-fleet.md +0 -27
  475. package/.versions/0.0.8/skills/guided-workspace-setup/SKILL.md +0 -544
  476. package/.versions/0.0.8/skills/guided-workspace-setup/companion-manifest.json +0 -36
  477. package/.versions/0.0.9/.opencode/commands/af-doctor-agent-fleet.md +0 -17
  478. package/.versions/0.0.9/.opencode/commands/af-setup-agent-fleet.md +0 -15
  479. package/.versions/0.0.9/.pi/prompts/af-doctor-agent-fleet.md +0 -15
  480. package/.versions/0.0.9/.pi/prompts/af-setup-agent-fleet.md +0 -27
  481. package/.versions/0.0.9/skills/guided-workspace-setup/SKILL.md +0 -544
  482. package/bin/lib/bootstrap.js +0 -323
  483. package/bin/lib/transform-persona.js +0 -180
  484. package/docs/opencode-setup.md +0 -281
  485. package/hooks/SIMPLIFY-IGNORE.md +0 -90
  486. package/hooks/hooks.json +0 -14
  487. package/hooks/session-start.sh +0 -74
  488. package/hooks/simplify-ignore.sh +0 -302
  489. package/skills/guided-workspace-setup/SKILL.md +0 -226
  490. /package/.versions/0.0.10/{skills/guided-workspace-setup/companion-manifest.json → bin/catalog/harness-runtime-closure.json} +0 -0
  491. /package/.versions/0.0.11/{skills/guided-workspace-setup/companion-manifest.json → bin/catalog/harness-runtime-closure.json} +0 -0
  492. /package/{.opencode/commands → .versions/1.0.0/.pi/prompts}/af-set-hermes-telegram.md +0 -0
  493. /package/.versions/{0.0.9/skills/guided-workspace-setup/companion-manifest.json → 1.0.0/bin/catalog/harness-runtime-closure.json} +0 -0
  494. /package/{skills/guided-workspace-setup/companion-manifest.json → bin/catalog/harness-runtime-closure.json} +0 -0
@@ -0,0 +1,536 @@
1
+ /**
2
+ * Damage-Control (continue) — fail-closed guardrails without aborting the agent turn
3
+ *
4
+ * On a blocked tool call:
5
+ * - The result is replaced with actionable feedback that
6
+ * distinguishes destructive vs non-destructive intent and tells the
7
+ * agent how to adapt.
8
+ * - We do NOT call ctx.abort(), so the agent's turn continues and can
9
+ * try an alternate path (e.g. assume a .env key exists instead of
10
+ * reading it to verify).
11
+ *
12
+ * On top of the rule engine this variant supports runtime EXEMPTIONS for the
13
+ * path categories (zeroAccessPaths / readOnlyPaths / noDeletePaths) — never
14
+ * for the destructive bashToolPatterns:
15
+ * - /af-allow <pattern> [turn|session] pre-authorizes a protected pattern
16
+ * (/af-allowed lists, /af-revoke removes). Session grants are mirrored into the
17
+ * shared exemptions file when agent-hub provides one, so spawned children
18
+ * inherit them.
19
+ * - In interactive sessions a path block opens a dialog (keep blocked /
20
+ * allow once / turn / session) — an approved call proceeds immediately.
21
+ * - In headless children spawned by agent-hub (ctx.hasUI is false and
22
+ * AGENT_HUB_ASK_ENDPOINT is set) a path block escalates to the hub
23
+ * dispatcher over its coms socket and waits for the user's decision;
24
+ * timeout or denial fails closed.
25
+ *
26
+ * In this repo it is the only supported safety harness: the agent-hub main
27
+ * session and every native specialist, research helper, and nested delegate
28
+ * use it. Missing safety plumbing makes Agent Hub refuse child dispatch.
29
+ *
30
+ * Usage: pi -e .pi/harnesses/damage-control-continue/index.ts
31
+ */
32
+
33
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
34
+ import { isToolCallEventType } from "@mariozechner/pi-coding-agent";
35
+ import { parse as yamlParse } from "yaml";
36
+ import * as crypto from "crypto";
37
+ import * as fs from "fs";
38
+ import * as path from "path";
39
+ import * as os from "os";
40
+ import {
41
+ AGENT_ID_ENV,
42
+ ASK_ENDPOINT_ENV,
43
+ EXEMPTIONS_FILE_ENV,
44
+ appendExemptionToFile,
45
+ fileExemptionsFor,
46
+ readExemptionsFile,
47
+ removeExemptionFromFile,
48
+ requestAccessFromHub,
49
+ type AccessRequest,
50
+ type Exemption,
51
+ type ExemptionScope,
52
+ type PathRuleCategory,
53
+ } from "../lib/damage-control-shared.ts";
54
+ import { registerVersionStatus } from "./version.ts";
55
+
56
+ interface Rule {
57
+ pattern: string;
58
+ reason: string;
59
+ ask?: boolean;
60
+ }
61
+
62
+ interface Rules {
63
+ bashToolPatterns: Rule[];
64
+ zeroAccessPaths: string[];
65
+ readOnlyPaths: string[];
66
+ noDeletePaths: string[];
67
+ }
68
+
69
+ // Cap on hub escalations per agent run, so a confused child cannot flood the
70
+ // dispatcher with approval dialogs. Denials are also cached per turn.
71
+ const MAX_ESCALATIONS_PER_TURN = 3;
72
+ const PROMPT_TIMEOUT_MS = 60_000;
73
+
74
+ function continueFeedback(toolName: string, violationReason: string, invocation: string, note?: string): string {
75
+ return [
76
+ `🛡️ Damage-Control: ${toolName} blocked — ${violationReason}`,
77
+ ``,
78
+ `Attempted: ${invocation}`,
79
+ ...(note ? [``, note] : []),
80
+ ``,
81
+ `Don't call ${toolName} directly like this. Decide which case you're in and continue:`,
82
+ ``,
83
+ `→ NON-DESTRUCTIVE (e.g. reading .env to verify a key, listing a protected dir, peeking at config):`,
84
+ ` Assume the data is present and correct. Skip the verification step and move on with the task.`,
85
+ ` Example: if you were reading .env to confirm a key exists, just assume it does — the user has`,
86
+ ` configured their environment. If you actually need a value, ask the user for it explicitly.`,
87
+ ``,
88
+ `→ DESTRUCTIVE (delete, overwrite, force-push, drop, rm, truncate, sudo, kill, etc.):`,
89
+ ` STOP. Tell the user exactly what you need to ship this task and ask how they want to proceed.`,
90
+ ` Do not invent a workaround that achieves the same destructive effect.`,
91
+ ``,
92
+ `Pick the right path above and continue working. Do not retry this exact call.`,
93
+ ].join("\n");
94
+ }
95
+
96
+ export default function (pi: ExtensionAPI) {
97
+ let rules: Rules = {
98
+ bashToolPatterns: [],
99
+ zeroAccessPaths: [],
100
+ readOnlyPaths: [],
101
+ noDeletePaths: [],
102
+ };
103
+
104
+ // Runtime exemptions. Turn-scoped entries (and per-turn denial memory) are
105
+ // cleared on agent_end; session-scoped entries live for the process. The
106
+ // shared exemptions file (agent-hub plumbing) is re-read on every block, so
107
+ // grants made mid-session in the hub apply to already-running children.
108
+ const turnExemptions: Exemption[] = [];
109
+ const sessionExemptions: Exemption[] = [];
110
+ const deniedThisTurn = new Set<string>();
111
+ let escalationsThisTurn = 0;
112
+
113
+ const agentId = () => process.env[AGENT_ID_ENV] || "unknown-agent";
114
+ const askEndpoint = () => process.env[ASK_ENDPOINT_ENV];
115
+ const sharedExemptionsFile = () => process.env[EXEMPTIONS_FILE_ENV];
116
+
117
+ function activeExemptions(): Exemption[] {
118
+ return [...turnExemptions, ...sessionExemptions, ...fileExemptionsFor(sharedExemptionsFile(), agentId())];
119
+ }
120
+
121
+ function grantExemption(pattern: string, scope: ExemptionScope, via: Exemption["grantedVia"]): Exemption {
122
+ const ex: Exemption = { pattern, scope, grantedVia: via, grantedAt: new Date().toISOString() };
123
+ (scope === "turn" ? turnExemptions : sessionExemptions).push(ex);
124
+ if (scope === "session") {
125
+ const file = sharedExemptionsFile();
126
+ if (file) {
127
+ try { appendExemptionToFile(file, ex); } catch { /* best-effort — memory copy still applies */ }
128
+ }
129
+ }
130
+ pi.appendEntry("damage-control-log", { action: "exemption_granted", pattern, scope, via });
131
+ return ex;
132
+ }
133
+
134
+ function resolvePath(p: string, cwd: string): string {
135
+ if (p.startsWith("~")) {
136
+ p = path.join(os.homedir(), p.slice(1));
137
+ }
138
+ return path.resolve(cwd, p);
139
+ }
140
+
141
+ function expandTilde(p: string): string {
142
+ return p.startsWith("~") ? path.join(os.homedir(), p.slice(1)) : p;
143
+ }
144
+
145
+ function commandReferencesPath(command: string, protectedPath: string): boolean {
146
+ if (!protectedPath) return false;
147
+ let idx = command.indexOf(protectedPath);
148
+ while (idx >= 0) {
149
+ const after = command[idx + protectedPath.length];
150
+ if (!after || !/[A-Za-z0-9_-]/.test(after)) return true;
151
+ idx = command.indexOf(protectedPath, idx + 1);
152
+ }
153
+ return false;
154
+ }
155
+
156
+ function isPathMatch(targetPath: string, pattern: string, cwd: string): boolean {
157
+ const resolvedPattern = pattern.startsWith("~") ? path.join(os.homedir(), pattern.slice(1)) : pattern;
158
+
159
+ if (resolvedPattern.endsWith("/")) {
160
+ const absolutePattern = path.isAbsolute(resolvedPattern) ? resolvedPattern : path.resolve(cwd, resolvedPattern);
161
+ return targetPath.startsWith(absolutePattern);
162
+ }
163
+
164
+ const regexPattern = resolvedPattern
165
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
166
+ .replace(/\*/g, ".*");
167
+
168
+ const regex = new RegExp(`^${regexPattern}$|^${regexPattern}/|/${regexPattern}$|/${regexPattern}/`);
169
+
170
+ const relativePath = path.relative(cwd, targetPath);
171
+
172
+ return regex.test(targetPath) || regex.test(relativePath) || targetPath.includes(resolvedPattern) || relativePath.includes(resolvedPattern);
173
+ }
174
+
175
+ // An exemption unlocks the exact protected pattern it names, or any target
176
+ // it would itself match under the same rules the block used.
177
+ function exemptionApplies(ex: Exemption, matchedPattern: string, inputPaths: string[], command: string | null, cwd: string): boolean {
178
+ if (ex.pattern === matchedPattern) return true;
179
+ if (command && command.includes(ex.pattern)) return true;
180
+ for (const p of inputPaths) {
181
+ if (isPathMatch(resolvePath(p, cwd), ex.pattern, cwd)) return true;
182
+ }
183
+ return false;
184
+ }
185
+
186
+ function statusText(): string {
187
+ const total = rules.bashToolPatterns.length + rules.zeroAccessPaths.length + rules.readOnlyPaths.length + rules.noDeletePaths.length;
188
+ const exemptions = turnExemptions.length + sessionExemptions.length + readExemptionsFile(sharedExemptionsFile()).length;
189
+ return exemptions > 0
190
+ ? `🛡️ Damage-Control (continue): ${total} Rules, ${exemptions} exemption${exemptions === 1 ? "" : "s"}`
191
+ : `🛡️ Damage-Control (continue): ${total} Rules`;
192
+ }
193
+
194
+ pi.registerCommand("af-allow", {
195
+ description: "Damage-control: exempt a protected path pattern — /af-allow <pattern> [turn|session]",
196
+ handler: async (args, ctx) => {
197
+ const parts = args.trim().split(/\s+/).filter(Boolean);
198
+ let scope: ExemptionScope = "session";
199
+ const last = parts[parts.length - 1];
200
+ if (last === "turn" || last === "session") {
201
+ scope = last;
202
+ parts.pop();
203
+ }
204
+ const pattern = parts.join(" ");
205
+ if (!pattern) {
206
+ ctx.ui.notify("Usage: /af-allow <pattern> [turn|session] — e.g. /af-allow .env turn", "warning");
207
+ return;
208
+ }
209
+ const already = activeExemptions().some((e) => e.pattern === pattern && (e.scope === scope || e.scope === "session"));
210
+ if (already) {
211
+ ctx.ui.notify(`🛡️ ${pattern} is already exempted`, "info");
212
+ return;
213
+ }
214
+ grantExemption(pattern, scope, "command");
215
+ ctx.ui.notify(`🛡️ Exemption granted: ${pattern} (${scope})`, "warning");
216
+ ctx.ui.setStatus("damage-control", statusText());
217
+ },
218
+ });
219
+
220
+ pi.registerCommand("af-allowed", {
221
+ description: "Damage-control: list active exemptions",
222
+ handler: async (_args, ctx) => {
223
+ const lines: string[] = [];
224
+ for (const e of turnExemptions) lines.push(`${e.pattern} (turn, via ${e.grantedVia})`);
225
+ for (const e of sessionExemptions) lines.push(`${e.pattern} (session, via ${e.grantedVia})`);
226
+ for (const e of readExemptionsFile(sharedExemptionsFile())) {
227
+ lines.push(`${e.pattern} (session${e.agent ? `, agent ${e.agent}` : ", all agents"}, via ${e.grantedVia})`);
228
+ }
229
+ ctx.ui.notify(lines.length ? `🛡️ Active exemptions:\n${lines.join("\n")}` : "🛡️ No active exemptions", "info");
230
+ },
231
+ });
232
+
233
+ pi.registerCommand("af-revoke", {
234
+ description: "Damage-control: revoke an exemption — /af-revoke <pattern>",
235
+ handler: async (args, ctx) => {
236
+ const pattern = args.trim();
237
+ if (!pattern) {
238
+ ctx.ui.notify("Usage: /af-revoke <pattern>", "warning");
239
+ return;
240
+ }
241
+ let removed = false;
242
+ for (const store of [turnExemptions, sessionExemptions]) {
243
+ for (let i = store.length - 1; i >= 0; i--) {
244
+ if (store[i].pattern === pattern) {
245
+ store.splice(i, 1);
246
+ removed = true;
247
+ }
248
+ }
249
+ }
250
+ if (removeExemptionFromFile(sharedExemptionsFile(), pattern)) removed = true;
251
+ if (removed) {
252
+ pi.appendEntry("damage-control-log", { action: "exemption_revoked", pattern });
253
+ ctx.ui.notify(`🛡️ Exemption revoked: ${pattern}`, "warning");
254
+ } else {
255
+ ctx.ui.notify(`🛡️ No exemption found for: ${pattern}`, "info");
256
+ }
257
+ ctx.ui.setStatus("damage-control", statusText());
258
+ },
259
+ });
260
+
261
+ pi.on("agent_end", async () => {
262
+ turnExemptions.length = 0;
263
+ deniedThisTurn.clear();
264
+ escalationsThisTurn = 0;
265
+ });
266
+
267
+ pi.on("session_start", async (_event, ctx) => {
268
+ registerVersionStatus(ctx);
269
+ const projectRulesPath = path.join(ctx.cwd, ".pi", "damage-control-rules.yaml");
270
+ const globalRulesPath = path.join(os.homedir(), ".pi", "damage-control-rules.yaml");
271
+ const rulesPath = fs.existsSync(projectRulesPath) ? projectRulesPath : fs.existsSync(globalRulesPath) ? globalRulesPath : null;
272
+ try {
273
+ if (rulesPath) {
274
+ const content = fs.readFileSync(rulesPath, "utf8");
275
+ const loaded = yamlParse(content) as Partial<Rules>;
276
+ rules = {
277
+ bashToolPatterns: loaded.bashToolPatterns || [],
278
+ zeroAccessPaths: loaded.zeroAccessPaths || [],
279
+ readOnlyPaths: loaded.readOnlyPaths || [],
280
+ noDeletePaths: loaded.noDeletePaths || [],
281
+ };
282
+ const source = rulesPath === projectRulesPath ? "project" : "global";
283
+ const total = rules.bashToolPatterns.length + rules.zeroAccessPaths.length + rules.readOnlyPaths.length + rules.noDeletePaths.length;
284
+ ctx.ui.notify(`🛡️ Damage-Control (continue): Loaded ${total} rules (${source}). Blocks deliver feedback so the agent can adapt and keep working.`);
285
+ } else {
286
+ ctx.ui.notify("🛡️ Damage-Control (continue): No rules found at .pi/damage-control-rules.yaml (project or global)");
287
+ }
288
+ } catch (err) {
289
+ ctx.ui.notify(`🛡️ Damage-Control (continue): Failed to load rules: ${err instanceof Error ? err.message : String(err)}`);
290
+ }
291
+
292
+ ctx.ui.setStatus("damage-control", statusText());
293
+ });
294
+
295
+ pi.on("tool_call", async (event, ctx) => {
296
+ let violationReason: string | null = null;
297
+ let shouldAsk = false;
298
+ // The protected pattern that matched, set only for the path categories —
299
+ // those are exemptible/escalatable. Destructive bashToolPatterns leave
300
+ // this null and can never be exempted.
301
+ let matchedPattern: string | null = null;
302
+ let matchedCategory: PathRuleCategory | null = null;
303
+
304
+ const checkPaths = (pathsToCheck: string[]) => {
305
+ for (const p of pathsToCheck) {
306
+ const resolved = resolvePath(p, ctx.cwd);
307
+ for (const zap of rules.zeroAccessPaths) {
308
+ if (isPathMatch(resolved, zap, ctx.cwd)) {
309
+ matchedPattern = zap;
310
+ matchedCategory = "zero_access";
311
+ return `Access to zero-access path restricted: ${zap}`;
312
+ }
313
+ }
314
+ }
315
+ return null;
316
+ };
317
+
318
+ const inputPaths: string[] = [];
319
+ if (isToolCallEventType("read", event) || isToolCallEventType("write", event) || isToolCallEventType("edit", event)) {
320
+ inputPaths.push(event.input.path);
321
+ } else if (isToolCallEventType("grep", event) || isToolCallEventType("find", event) || isToolCallEventType("ls", event)) {
322
+ inputPaths.push(event.input.path || ".");
323
+ }
324
+
325
+ if (isToolCallEventType("grep", event) && event.input.glob) {
326
+ for (const zap of rules.zeroAccessPaths) {
327
+ if (event.input.glob.includes(zap) || isPathMatch(event.input.glob, zap, ctx.cwd)) {
328
+ violationReason = `Glob matches zero-access path: ${zap}`;
329
+ matchedPattern = zap;
330
+ matchedCategory = "zero_access";
331
+ break;
332
+ }
333
+ }
334
+ }
335
+
336
+ // find's required `pattern` is a filename glob (e.g. "*.env") — the `path` check
337
+ // above only sees the search root ("."), so check the pattern too, mirroring grep's glob.
338
+ if (!violationReason && isToolCallEventType("find", event) && event.input.pattern) {
339
+ for (const zap of rules.zeroAccessPaths) {
340
+ if (event.input.pattern.includes(zap) || isPathMatch(event.input.pattern, zap, ctx.cwd)) {
341
+ violationReason = `Find pattern matches zero-access path: ${zap}`;
342
+ matchedPattern = zap;
343
+ matchedCategory = "zero_access";
344
+ break;
345
+ }
346
+ }
347
+ }
348
+
349
+ if (!violationReason) {
350
+ violationReason = checkPaths(inputPaths);
351
+ }
352
+
353
+ if (!violationReason) {
354
+ if (isToolCallEventType("bash", event)) {
355
+ const command = event.input.command;
356
+
357
+ for (const rule of rules.bashToolPatterns) {
358
+ const regex = new RegExp(rule.pattern);
359
+ if (regex.test(command)) {
360
+ violationReason = rule.reason;
361
+ shouldAsk = !!rule.ask;
362
+ break;
363
+ }
364
+ }
365
+
366
+ if (!violationReason) {
367
+ for (const zap of rules.zeroAccessPaths) {
368
+ if (command.includes(zap)) {
369
+ violationReason = `Bash command references zero-access path: ${zap}`;
370
+ matchedPattern = zap;
371
+ matchedCategory = "zero_access";
372
+ break;
373
+ }
374
+ }
375
+ }
376
+
377
+ if (!violationReason) {
378
+ for (const rop of rules.readOnlyPaths) {
379
+ if (command.includes(rop) && (/[\s>|]/.test(command) || command.includes("rm") || command.includes("mv") || command.includes("sed"))) {
380
+ violationReason = `Bash command may modify read-only path: ${rop}`;
381
+ matchedPattern = rop;
382
+ matchedCategory = "read_only";
383
+ break;
384
+ }
385
+ }
386
+ }
387
+
388
+ if (!violationReason) {
389
+ const hasDeleteOrMove = /\brm\b/.test(command) || /\bmv\b/.test(command);
390
+ if (hasDeleteOrMove) {
391
+ for (const ndp of rules.noDeletePaths) {
392
+ const expanded = expandTilde(ndp);
393
+ const matched = commandReferencesPath(command, ndp) || (expanded !== ndp && commandReferencesPath(command, expanded));
394
+ if (matched) {
395
+ violationReason = `Bash command attempts to delete/move protected path: ${ndp}`;
396
+ matchedPattern = ndp;
397
+ matchedCategory = "no_delete";
398
+ break;
399
+ }
400
+ }
401
+ }
402
+ }
403
+ } else if (isToolCallEventType("write", event) || isToolCallEventType("edit", event)) {
404
+ for (const p of inputPaths) {
405
+ const resolved = resolvePath(p, ctx.cwd);
406
+ for (const rop of rules.readOnlyPaths) {
407
+ if (isPathMatch(resolved, rop, ctx.cwd)) {
408
+ violationReason = `Modification of read-only path restricted: ${rop}`;
409
+ matchedPattern = rop;
410
+ matchedCategory = "read_only";
411
+ break;
412
+ }
413
+ }
414
+ }
415
+ }
416
+ }
417
+
418
+ if (!violationReason) {
419
+ return { block: false };
420
+ }
421
+
422
+ const command = isToolCallEventType("bash", event) ? event.input.command : null;
423
+ const invocation = command ?? JSON.stringify(event.input);
424
+
425
+ // ── exemption layer (path categories only) ──
426
+ if (matchedPattern) {
427
+ const exempted = activeExemptions().find((ex) => exemptionApplies(ex, matchedPattern!, inputPaths, command, ctx.cwd));
428
+ if (exempted) {
429
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "exempted", pattern: exempted.pattern, scope: exempted.scope });
430
+ ctx.ui.notify(`🛡️ Damage-Control: ${event.toolName} allowed by exemption ${exempted.pattern} (${exempted.scope})`, "warning");
431
+ return { block: false };
432
+ }
433
+
434
+ if (!deniedThisTurn.has(matchedPattern)) {
435
+ if (ctx.hasUI) {
436
+ // Interactive session: ask the user right now. An approved call
437
+ // proceeds immediately — the agent never sees the block.
438
+ const KEEP = "Keep blocked";
439
+ const ONCE = "Allow once";
440
+ const TURN = "Allow for this turn";
441
+ const SESSION = "Allow for this session";
442
+ const choices = matchedCategory === "no_delete"
443
+ ? [KEEP, ONCE]
444
+ : [KEEP, ONCE, TURN, SESSION];
445
+ const choice = await ctx.ui.select(
446
+ `🛡️ Blocked: ${event.toolName} — ${violationReason}`,
447
+ choices,
448
+ { timeout: PROMPT_TIMEOUT_MS },
449
+ );
450
+ if (choice === ONCE) {
451
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "allowed_once", pattern: matchedPattern });
452
+ return { block: false };
453
+ }
454
+ if (choice === TURN || choice === SESSION) {
455
+ grantExemption(matchedPattern, choice === TURN ? "turn" : "session", "prompt");
456
+ ctx.ui.setStatus("damage-control", statusText());
457
+ return { block: false };
458
+ }
459
+ const note = choice === KEEP
460
+ ? `The user reviewed this call and kept the block in place.`
461
+ : `The user did not answer the approval dialog in time (auto-kept blocked). They can pre-authorize with /af-allow ${matchedPattern} [turn|session].`;
462
+ if (choice === KEEP) deniedThisTurn.add(matchedPattern);
463
+ ctx.ui.setStatus("damage-control", `⚠️ Last Violation: ${violationReason.slice(0, 30)}...`);
464
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: choice === KEEP ? "blocked_by_user" : "blocked_prompt_timeout" });
465
+ return { block: true, reason: continueFeedback(event.toolName, violationReason, invocation, note) };
466
+ }
467
+
468
+ const endpoint = askEndpoint();
469
+ if (endpoint && escalationsThisTurn < MAX_ESCALATIONS_PER_TURN) {
470
+ // Headless child spawned by agent-hub: escalate to the dispatcher
471
+ // and wait for the user's decision (fail closed on timeout/error).
472
+ escalationsThisTurn++;
473
+ const req: AccessRequest = {
474
+ type: "access_request",
475
+ msg_id: crypto.randomUUID(),
476
+ sender_session: agentId(),
477
+ sender_endpoint: "",
478
+ hops: 0,
479
+ timestamp: new Date().toISOString(),
480
+ agent: agentId(),
481
+ tool: event.toolName,
482
+ rule: violationReason,
483
+ pattern: matchedPattern,
484
+ category: matchedCategory!,
485
+ invocation: invocation.slice(0, 500),
486
+ };
487
+ const decision = await requestAccessFromHub(endpoint, req);
488
+ if (decision === "allow_once") {
489
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "allowed_once", pattern: matchedPattern, via: "escalation" });
490
+ return { block: false };
491
+ }
492
+ if (decision === "allow_agent" || decision === "allow_all") {
493
+ // The hub persisted the grant to the shared file; keep a memory
494
+ // copy too so this run doesn't depend on re-reading it.
495
+ sessionExemptions.push({ pattern: matchedPattern, scope: "session", grantedVia: "escalation", grantedAt: new Date().toISOString() });
496
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: decision === "allow_all" ? "allowed_all_agents" : "allowed_this_agent", pattern: matchedPattern, via: "escalation" });
497
+ return { block: false };
498
+ }
499
+ deniedThisTurn.add(matchedPattern);
500
+ const note = decision === "deny"
501
+ ? `This block was escalated to the user via the dispatcher and the user DENIED access.`
502
+ : decision === "timeout"
503
+ ? `This block was escalated to the user via the dispatcher but the approval request timed out (auto-kept blocked). If access to this path is essential, say so explicitly in your final response so the user can grant it and re-dispatch you.`
504
+ : `Escalating this block to the dispatcher failed (hub unreachable).`;
505
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: `escalation_${decision}`, pattern: matchedPattern });
506
+ return { block: true, reason: continueFeedback(event.toolName, violationReason, invocation, note) };
507
+ }
508
+ }
509
+ }
510
+
511
+ if (shouldAsk) {
512
+ const confirmed = await ctx.ui.confirm(
513
+ "🛡️ Damage-Control Confirmation",
514
+ `Dangerous command detected: ${violationReason}\n\nCommand: ${invocation}\n\nDo you want to proceed?`,
515
+ { timeout: 30000 },
516
+ );
517
+
518
+ if (!confirmed) {
519
+ ctx.ui.setStatus("damage-control", `⚠️ Last Violation Blocked: ${violationReason.slice(0, 30)}...`);
520
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "blocked_by_user" });
521
+ return { block: true, reason: continueFeedback(event.toolName, `${violationReason} (user denied)`, invocation) };
522
+ } else {
523
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "confirmed_by_user" });
524
+ return { block: false };
525
+ }
526
+ } else {
527
+ const note = matchedPattern
528
+ ? `The user can pre-authorize this path with /af-allow ${matchedPattern} [turn|session] in a damage-control-continue session.`
529
+ : undefined;
530
+ ctx.ui.notify(`🛑 Damage-Control: Blocked ${event.toolName} (${violationReason}) — agent will adapt and continue.`);
531
+ ctx.ui.setStatus("damage-control", `⚠️ Last Violation: ${violationReason.slice(0, 30)}...`);
532
+ pi.appendEntry("damage-control-log", { tool: event.toolName, input: event.input, rule: violationReason, action: "blocked" });
533
+ return { block: true, reason: continueFeedback(event.toolName, violationReason, invocation, note) };
534
+ }
535
+ });
536
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "agent-fleet-pi-damage-control-continue",
3
+ "private": true,
4
+ "type": "module",
5
+ "main": "index.ts",
6
+ "version": "1.0.0"
7
+ }
@@ -0,0 +1,42 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ export const VERSION_STATUS_KEY = "00-agent-fleet-version";
4
+ export const VERSION_LABEL = "agent fleet";
5
+ export const VERSION_LABEL_URL = "https://github.com/chankov/agent-fleet";
6
+
7
+ /**
8
+ * Wrap `text` in an OSC 8 hyperlink. Terminals that support it make the label
9
+ * clickable and hand the URL to the OS opener; terminals that don't ignore the
10
+ * sequence and render `text` unchanged. pi's TUI strips OSC sequences before
11
+ * measuring (`visibleWidth`) and truncating, so a linked label costs no footer
12
+ * columns. Multiplexers that mangle unknown OSC (GNU screen, tmux before 3.4)
13
+ * are the reason for the AGENT_FLEET_NO_LINKS opt-out below.
14
+ */
15
+ export function linkify(text: string, url: string): string {
16
+ return `\x1b]8;;${url}\x07${text}\x1b]8;;\x07`;
17
+ }
18
+
19
+ function linksEnabled(): boolean {
20
+ const optOut = process.env.AGENT_FLEET_NO_LINKS;
21
+ return !optOut || optOut === "0" || optOut === "false";
22
+ }
23
+
24
+ export function formatVersionLabel(version: string): string {
25
+ const label = linksEnabled() ? linkify(VERSION_LABEL, VERSION_LABEL_URL) : VERSION_LABEL;
26
+ return `${label} v${version}`;
27
+ }
28
+
29
+ function readAdjacentVersion(): string | null {
30
+ try {
31
+ const manifest = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
32
+ return typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : null;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ export const HARNESS_VERSION = readAdjacentVersion();
39
+
40
+ export function registerVersionStatus(ctx: { ui?: { setStatus?: (key: string, text: string) => void } }): void {
41
+ if (HARNESS_VERSION) ctx.ui?.setStatus?.(VERSION_STATUS_KEY, formatVersionLabel(HARNESS_VERSION));
42
+ }
@@ -0,0 +1,94 @@
1
+ // .pi/harnesses/lib/coms-registry-entry.ts
2
+ //
3
+ // The shape written to ~/.pi/coms/projects/<project>/agents/<name>.json, and
4
+ // the one function that builds it for the 30-second heartbeat.
5
+ //
6
+ // It exists because both harnesses (the standalone coms harness and the copy
7
+ // embedded in agent-hub) had their own inline copy of the same object literal,
8
+ // and both copies wrote `started_at: nowIso()` on EVERY heartbeat. The field
9
+ // therefore never held the start of anything — it was always "about 30 seconds
10
+ // ago", and every reader that tried to show uptime showed noise. Registration
11
+ // sets `started_at`; the heartbeat carries it forward unchanged and moves
12
+ // `heartbeat_at` instead. That distinction is the whole point of this module,
13
+ // so it is stated once, here, and tested.
14
+ //
15
+ // Pure module: no pi imports, no fs, no clock of its own — `now` is passed in.
16
+ // Erasable-TS; testable under node --test.
17
+
18
+ export interface ComsRegistryEntry {
19
+ session_id: string;
20
+ name: string;
21
+ purpose: string;
22
+ model: string;
23
+ color: string;
24
+ pid: number;
25
+ endpoint: string;
26
+ cwd: string;
27
+ // When this session registered. NEVER refreshed — see the module note.
28
+ started_at: string;
29
+ explicit: boolean;
30
+ version: number;
31
+ // Live status snapshot — refreshed every keepalive tick. Optional so
32
+ // entries written before the heartbeat carried them still parse cleanly.
33
+ context_used_pct?: number;
34
+ queue_depth?: number;
35
+ heartbeat_at?: string;
36
+ }
37
+
38
+ // What the session knows about itself from registration onwards. This is the
39
+ // harness `identity` object; it is the source of every field the heartbeat is
40
+ // not allowed to invent.
41
+ export interface ComsIdentity {
42
+ session_id: string;
43
+ name: string;
44
+ purpose: string;
45
+ color: string;
46
+ cwd: string;
47
+ endpoint: string;
48
+ explicit: boolean;
49
+ model: string;
50
+ started_at: string;
51
+ }
52
+
53
+ // What is genuinely new at heartbeat time.
54
+ export interface LiveSnapshot {
55
+ now: string;
56
+ pid: number;
57
+ // The model can change mid-session (`/model`), so it is re-read rather than
58
+ // frozen at registration; falling back to the registered one when the ctx
59
+ // is not available.
60
+ model?: string | null;
61
+ contextUsedPct?: number | null;
62
+ queueDepth?: number | null;
63
+ }
64
+
65
+ // Percentages arrive from `ctx.getContextUsage()`, queue depths from a Map
66
+ // size. Both reach a human eye and a JSON file, so neither may be NaN,
67
+ // negative, or fractional.
68
+ function count(value: number | null | undefined): number {
69
+ if (typeof value !== "number" || !Number.isFinite(value)) return 0;
70
+ return Math.max(0, Math.round(value));
71
+ }
72
+
73
+ // The registry entry for a heartbeat write. Also the entry used for self-heal
74
+ // (the file was unlinked under us and is being re-created), which is why every
75
+ // field is present rather than patched onto whatever is on disk: there may be
76
+ // nothing on disk.
77
+ export function buildLiveRegistryEntry(identity: ComsIdentity, live: LiveSnapshot): ComsRegistryEntry {
78
+ return {
79
+ session_id: identity.session_id,
80
+ name: identity.name,
81
+ purpose: identity.purpose,
82
+ model: live.model || identity.model,
83
+ color: identity.color,
84
+ pid: live.pid,
85
+ endpoint: identity.endpoint,
86
+ cwd: identity.cwd,
87
+ started_at: identity.started_at,
88
+ explicit: identity.explicit,
89
+ version: 1,
90
+ context_used_pct: count(live.contextUsedPct),
91
+ queue_depth: count(live.queueDepth),
92
+ heartbeat_at: live.now,
93
+ };
94
+ }