@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,479 @@
1
+ // Execution modes & per-turn budgets — the pure policy core behind the hub's
2
+ // runaway-orchestration guardrails. Budgets are PER USER TURN: a new user
3
+ // message opens a fresh window, so "budget exhausted" naturally means "stop,
4
+ // summarize, ask the user". Everything here is data + pure functions so the
5
+ // policy is unit-testable away from the 7k-line harness.
6
+ //
7
+ // A budget value of `null` means "off"/unlimited for that axis.
8
+
9
+ export const HUB_MODES = ["fast", "standard", "strict"];
10
+ export const DEFAULT_HUB_MODE = "standard";
11
+
12
+ // Task tiers — the dispatcher's per-turn complexity triage. Tier caps only
13
+ // lower the dispatch/research axes (min with the mode budget): a trivial ask
14
+ // must not burn a standard-mode budget on ceremony, while `project` defers
15
+ // entirely to the mode. Unset tier is treated as "feature".
16
+ export const TASK_TIERS = ["trivial", "small", "feature", "project"];
17
+ // The tier ASSUMED when the dispatcher never called set_task_tier. It is
18
+ // deliberately not the middle of the range: the tier is task-scoped, so a skipped
19
+ // triage latches for the whole task, and skipped triage is exactly the case where
20
+ // the dispatcher was not thinking about proportionality. Assuming `feature` there
21
+ // unlocked planner/plan-reviewer/security-auditor, loosened the review cap, and
22
+ // handed out the full feature envelope — the over-apparatus failure mode, granted
23
+ // by forgetting a tool call. Assuming `small` costs an explicit escalation (with a
24
+ // reason) when the work really is bigger, which is the cheap direction to be wrong in.
25
+ export const DEFAULT_TASK_TIER = "small";
26
+
27
+ export const TIER_CAPS = {
28
+ trivial: { maxDispatches: 1, maxResearch: 1 },
29
+ small: { maxDispatches: 2, maxResearch: 2 },
30
+ feature: { maxDispatches: 6, maxResearch: 4 },
31
+ project: { maxDispatches: null, maxResearch: null },
32
+ };
33
+
34
+ /** "Small", " TRIVIAL " → canonical tier name, or null when unrecognized. */
35
+ export function normalizeTaskTier(value) {
36
+ const v = String(value ?? "").trim().toLowerCase();
37
+ return TASK_TIERS.includes(v) ? v : null;
38
+ }
39
+
40
+ // Session-recycle context threshold (percent, measured over input+cacheRead+
41
+ // cacheWrite): beyond this, resuming the specialist session mostly re-bills
42
+ // stale context, so a fresh session is cheaper than the memory is worth.
43
+ export const RECYCLE_CONTEXT_PCT = 60;
44
+
45
+ // Hard ceiling: at or past a full window the accumulated session no longer
46
+ // fits, so no threshold override may keep it alive. Session 1 of the
47
+ // post-mortem logged 315% → 176% → 100% while the configured threshold was
48
+ // still being consulted as if it were advisory.
49
+ export const HARD_RECYCLE_CONTEXT_PCT = 100;
50
+
51
+ export const MODE_BUDGETS = {
52
+ fast: {
53
+ maxDispatches: 2,
54
+ maxResearch: 1,
55
+ wallMs: 15 * 60_000,
56
+ agentTurnMs: 10 * 60_000,
57
+ recycleRuns: 3,
58
+ delegation: false,
59
+ },
60
+ standard: {
61
+ maxDispatches: 8,
62
+ maxResearch: 4,
63
+ wallMs: 60 * 60_000,
64
+ agentTurnMs: 30 * 60_000,
65
+ recycleRuns: 5,
66
+ delegation: true,
67
+ },
68
+ strict: {
69
+ maxDispatches: 24,
70
+ maxResearch: 12,
71
+ wallMs: 240 * 60_000,
72
+ agentTurnMs: null,
73
+ recycleRuns: 5,
74
+ delegation: true,
75
+ },
76
+ };
77
+
78
+ /** "Fast", " STRICT " → canonical mode name, or null when unrecognized. */
79
+ export function normalizeHubMode(value) {
80
+ const v = String(value ?? "").trim().toLowerCase();
81
+ return HUB_MODES.includes(v) ? v : null;
82
+ }
83
+
84
+ /**
85
+ * Effective budget for a mode with per-project overrides applied.
86
+ * Override fields (all optional): maxDispatches, maxResearch, wallMs,
87
+ * agentTurnMs, recycleRuns — a number replaces the mode default, `null` turns
88
+ * the axis off, `undefined` keeps the default. `delegation` is mode-owned.
89
+ * A declared `tier` (task tier) then LOWERS the dispatch and research caps to
90
+ * the tier cap — overrides raise/disable the mode side, but the tier keeps a
91
+ * simple ask from spending the whole envelope. No tier (null/undefined) means
92
+ * no tier caps: the caller decides when to assume DEFAULT_TASK_TIER.
93
+ */
94
+ export function resolveTurnBudget(mode, overrides = {}, tier = undefined) {
95
+ const base = MODE_BUDGETS[normalizeHubMode(mode) ?? DEFAULT_HUB_MODE];
96
+ const pick = (key) => (overrides[key] === undefined ? base[key] : overrides[key]);
97
+ const caps = TIER_CAPS[normalizeTaskTier(tier)] ?? { maxDispatches: null, maxResearch: null };
98
+ const lower = (value, cap) => {
99
+ if (cap == null) return value;
100
+ if (value == null) return cap;
101
+ return Math.min(value, cap);
102
+ };
103
+ return {
104
+ maxDispatches: lower(pick("maxDispatches"), caps.maxDispatches),
105
+ maxResearch: lower(pick("maxResearch"), caps.maxResearch),
106
+ wallMs: pick("wallMs"),
107
+ agentTurnMs: pick("agentTurnMs"),
108
+ recycleRuns: pick("recycleRuns"),
109
+ delegation: base.delegation,
110
+ };
111
+ }
112
+
113
+ function refusalTail(mode) {
114
+ return "Do NOT retry this call in this turn. Summarize progress so far (including " +
115
+ "unproven assertions and artifact paths), then ask the user whether to continue — " +
116
+ "the next user message starts a fresh budget window. The user can widen budgets " +
117
+ `with /af-hub-mode (current: ${mode}) or the max-*-per-turn / turn-wall-time-s keys ` +
118
+ "in .ai/agent-fleet-overrides.md.";
119
+ }
120
+
121
+ /**
122
+ * Gate one dispatcher tool call against the turn budget.
123
+ * kind: "dispatch" | "research"; counters: { dispatches, research } — calls
124
+ * already made this turn. Returns null when allowed, else { reason, message }.
125
+ */
126
+ export function checkTurnBudget(kind, counters, budget, elapsedWallMs, mode = DEFAULT_HUB_MODE) {
127
+ if (budget.wallMs != null && elapsedWallMs >= budget.wallMs) {
128
+ return {
129
+ reason: "wall",
130
+ message: `⚠ Turn budget exhausted: wall clock at ${Math.round(elapsedWallMs / 60_000)} min ` +
131
+ `(limit ${Math.round(budget.wallMs / 60_000)} min in ${mode} mode). ${refusalTail(mode)}`,
132
+ };
133
+ }
134
+ if (kind === "dispatch" && budget.maxDispatches != null && counters.dispatches >= budget.maxDispatches) {
135
+ return {
136
+ reason: "dispatches",
137
+ message: `⚠ Turn budget exhausted: ${counters.dispatches} of ${budget.maxDispatches} ` +
138
+ `dispatch_agent calls used in ${mode} mode. ${refusalTail(mode)}`,
139
+ };
140
+ }
141
+ if (kind === "research" && budget.maxResearch != null && counters.research >= budget.maxResearch) {
142
+ return {
143
+ reason: "research",
144
+ message: `⚠ Turn budget exhausted: ${counters.research} of ${budget.maxResearch} ` +
145
+ `spawn_research calls used in ${mode} mode. ${refusalTail(mode)}`,
146
+ };
147
+ }
148
+ return null;
149
+ }
150
+
151
+ /**
152
+ * Recycle the specialist's accumulated session before this run? True when the
153
+ * session already served `recycleRuns` runs, its context reached a full window
154
+ * (HARD_RECYCLE_CONTEXT_PCT, not overridable), or it passed the configured
155
+ * RECYCLE_CONTEXT_PCT — resuming past any of those mostly re-bills stale
156
+ * context on every subsequent model call.
157
+ */
158
+ export function shouldRecycleSession(runsSinceFresh, contextPct, budget, thresholdPct = RECYCLE_CONTEXT_PCT) {
159
+ if (runsSinceFresh <= 0) return false;
160
+ if (contextPct >= HARD_RECYCLE_CONTEXT_PCT) return true;
161
+ if (budget.recycleRuns != null && runsSinceFresh >= budget.recycleRuns) return true;
162
+ return contextPct >= thresholdPct;
163
+ }
164
+
165
+ /**
166
+ * The one case recycling cannot fix: a *fresh* session already measured over a
167
+ * full window means a single run overflowed on its own, so there is no
168
+ * accumulated history to drop. Either `contextWindow` is wrong for that
169
+ * provider or the run genuinely ran over — both need a human, not a retry.
170
+ * Returns the diagnostic line, or null when recycling covers the situation.
171
+ */
172
+ export function contextOverflowDiagnostic(runsSinceFresh, contextPct, { agent = "agent", model = "unknown model" } = {}) {
173
+ if (runsSinceFresh > 0) return null;
174
+ if (!(contextPct >= HARD_RECYCLE_CONTEXT_PCT)) return null;
175
+ return (
176
+ `⚠ ${agent} measured ${Math.round(contextPct)}% context on a fresh session (${model}) — ` +
177
+ "recycling cannot help, one run overflowed the window on its own. Either the resolved " +
178
+ "contextWindow is wrong for this provider or the run genuinely ran over: check the model's " +
179
+ "declared window and narrow the task's inputs."
180
+ );
181
+ }
182
+
183
+ /** One-line status chip: "Mode: standard·small · 1/2 disp · 0/2 res · task 4/6". */
184
+ export function budgetStatusLine(mode, counters, budget, tier = null, task = null) {
185
+ const cap = (n) => (n == null ? "∞" : String(n));
186
+ const tierSuffix = tier ? `·${tier}` : "";
187
+ const taskSuffix = task
188
+ ? ` · task ${task.counters.dispatches}/${cap(task.budget.maxDispatches)}`
189
+ : "";
190
+ return `Mode: ${mode}${tierSuffix} · ${counters.dispatches}/${cap(budget.maxDispatches)} disp · ` +
191
+ `${counters.research}/${cap(budget.maxResearch)} res${taskSuffix}`;
192
+ }
193
+
194
+ // ─────────────────────────────────────────────────────────────────────────────
195
+ // Tier ratchet (the tier is TASK-scoped, not turn-scoped)
196
+ // ─────────────────────────────────────────────────────────────────────────────
197
+ //
198
+ // Turn-scoped tiers cannot bind on a steered run: every follow-up message reset
199
+ // the tier to null, the next dispatch re-assumed `feature`, and a two-word
200
+ // correction ("no, only the one line") bought six fresh dispatches. Worse, the
201
+ // reset direction was always upward — nobody re-declares `trivial` after a
202
+ // steering message, so the effective tier drifted to the ceiling.
203
+ //
204
+ // The tier now survives the turn and moves by ratchet: DOWN is free (cheap and
205
+ // self-limiting), UP costs an explicit reason that is recorded and shown. Only
206
+ // an explicit new task (set_task_tier `new_task: true`, or /af-new-task) clears
207
+ // it.
208
+
209
+ export const TIER_RANK = { trivial: 0, small: 1, feature: 2, project: 3 };
210
+
211
+ /**
212
+ * Move the task tier from `current` to `next`.
213
+ * Returns { ok, tier, escalated, reason, message }: `tier` is always the tier
214
+ * that should be in force afterwards, so a refused escalation keeps the old one.
215
+ */
216
+ export function applyTierChange(current, next, reason = "") {
217
+ const target = normalizeTaskTier(next);
218
+ if (!target) {
219
+ return {
220
+ ok: false,
221
+ tier: current ?? null,
222
+ escalated: false,
223
+ reason: "unknown_tier",
224
+ message: `Unknown tier "${next}" — expected one of: ${TASK_TIERS.join(", ")}. ` +
225
+ `Tier unchanged (${current ?? "unset"}).`,
226
+ };
227
+ }
228
+ const from = normalizeTaskTier(current);
229
+ if (!from) {
230
+ return { ok: true, tier: target, escalated: false, reason: "initial", message: `Task tier: ${target}.` };
231
+ }
232
+ if (TIER_RANK[target] <= TIER_RANK[from]) {
233
+ return {
234
+ ok: true,
235
+ tier: target,
236
+ escalated: false,
237
+ reason: TIER_RANK[target] === TIER_RANK[from] ? "unchanged" : "lowered",
238
+ message: `Task tier: ${from} → ${target}.`,
239
+ };
240
+ }
241
+ if (!String(reason || "").trim()) {
242
+ return {
243
+ ok: false,
244
+ tier: from,
245
+ escalated: false,
246
+ reason: "raise_without_reason",
247
+ message: `⚠ Tier escalation ${from} → ${target} refused: raising the tier needs an explicit ` +
248
+ "`reason` naming what the ask turned out to contain that the lower tier does not cover. " +
249
+ `Tier stays ${from}. Lowering the tier never needs a reason.`,
250
+ };
251
+ }
252
+ return {
253
+ ok: true,
254
+ tier: target,
255
+ escalated: true,
256
+ reason: "raised",
257
+ message: `⚠ Task tier ESCALATED ${from} → ${target}: ${String(reason).trim()}`,
258
+ };
259
+ }
260
+
261
+ // ─────────────────────────────────────────────────────────────────────────────
262
+ // Task-scoped budget (the outer bound the turn budget never provided)
263
+ // ─────────────────────────────────────────────────────────────────────────────
264
+ //
265
+ // Turn budgets are a per-message allowance, and a per-message allowance cannot
266
+ // bound a task: the observed 47-hour run never hit one, because every steering
267
+ // message opened a fresh window of 8 dispatches and 60 minutes. The task budget
268
+ // is the same envelope multiplied once and NOT reset by a user message — only
269
+ // by an explicit new task. Exhaustion is a hard stop, not a "summarize and ask":
270
+ // continuing requires the human to open a new task window.
271
+
272
+ export const TASK_BUDGET_MULTIPLIER = 3;
273
+
274
+ /** Task envelope = turn envelope × multiplier; `null` (off) axes stay off. */
275
+ export function resolveTaskBudget(turnBudget, multiplier = TASK_BUDGET_MULTIPLIER) {
276
+ const scale = (value) => (value == null ? null : Math.max(1, Math.round(value * multiplier)));
277
+ return {
278
+ maxDispatches: scale(turnBudget.maxDispatches),
279
+ maxResearch: scale(turnBudget.maxResearch),
280
+ wallMs: scale(turnBudget.wallMs),
281
+ };
282
+ }
283
+
284
+ function taskRefusalTail() {
285
+ return "This is a HARD STOP for the current task, not a turn refusal — another user message does " +
286
+ "NOT reopen it. Summarize what is proven (with evidence and artifact paths), what is unproven, " +
287
+ "and what remains, then ask the human to either narrow the remaining work or open a fresh task " +
288
+ "window with `/af-new-task`. If the task genuinely grew, say what it grew INTO — a task that " +
289
+ "outgrew its envelope three times over is a re-scoping decision, not a budget problem.";
290
+ }
291
+
292
+ /**
293
+ * ACTIVE milliseconds in one turn: wall clock minus the time the human was away.
294
+ *
295
+ * The task clock must never charge for human time. A task's wall clock spans
296
+ * every message on it, so a lunch break, an overnight pause, or a long `ask_user`
297
+ * answer would all count as budget — and at `fast` mode's 45-minute task wall a
298
+ * single coffee break would hard-stop a task with two dispatches spent. That is a
299
+ * false positive that teaches people to reset the task window reflexively, which
300
+ * costs more than the guardrail buys. Dispatch/research counts stay the honest
301
+ * hard stops; the clock only bounds time the fleet actually spent working.
302
+ */
303
+ export function turnActiveMs(turnStartedAt, now, askUserWaitMs = 0) {
304
+ if (!turnStartedAt) return 0;
305
+ return Math.max(0, now - turnStartedAt - Math.max(0, askUserWaitMs || 0));
306
+ }
307
+
308
+ /**
309
+ * Gate one dispatcher tool call against the TASK budget (checked before the
310
+ * turn budget: it is the more severe stop).
311
+ * `activeTaskMs` is ACTIVE time (see turnActiveMs), never raw wall clock.
312
+ * kind: "dispatch" | "research". Returns null when allowed, else { reason, message }.
313
+ */
314
+ export function checkTaskBudget(kind, counters, taskBudget, activeTaskMs, tier = null) {
315
+ const label = tier ? `tier ${tier}` : "current tier";
316
+ if (taskBudget.wallMs != null && activeTaskMs >= taskBudget.wallMs) {
317
+ return {
318
+ reason: "task_wall",
319
+ message: `⛔ TASK budget exhausted: ${Math.round(activeTaskMs / 60_000)} min of ACTIVE time on this task ` +
320
+ `(limit ${Math.round(taskBudget.wallMs / 60_000)} min = ${TASK_BUDGET_MULTIPLIER}× the ${label} turn envelope; ` +
321
+ `time the human was away is not charged). ` +
322
+ taskRefusalTail(),
323
+ };
324
+ }
325
+ if (kind === "dispatch" && taskBudget.maxDispatches != null && counters.dispatches >= taskBudget.maxDispatches) {
326
+ return {
327
+ reason: "task_dispatches",
328
+ message: `⛔ TASK budget exhausted: ${counters.dispatches} of ${taskBudget.maxDispatches} ` +
329
+ `dispatch_agent calls used on this task (${TASK_BUDGET_MULTIPLIER}× the ${label} turn envelope). ` +
330
+ taskRefusalTail(),
331
+ };
332
+ }
333
+ if (kind === "research" && taskBudget.maxResearch != null && counters.research >= taskBudget.maxResearch) {
334
+ return {
335
+ reason: "task_research",
336
+ message: `⛔ TASK budget exhausted: ${counters.research} of ${taskBudget.maxResearch} ` +
337
+ `spawn_research calls used on this task (${TASK_BUDGET_MULTIPLIER}× the ${label} turn envelope). ` +
338
+ taskRefusalTail(),
339
+ };
340
+ }
341
+ return null;
342
+ }
343
+
344
+ /**
345
+ * How many research runs the TASK envelope still allows; null = unlimited.
346
+ * The auto-research pipe (specialist emits NEEDS_RESEARCH, the hub fans out
347
+ * read-only helpers in code) is exempt from the TURN budget on purpose — it is
348
+ * hub mechanics, not a dispatcher decision, and it must not steal the
349
+ * dispatcher's slots. It is NOT exempt from the TASK envelope: at 2 rounds × 4
350
+ * questions per dispatch and 18 dispatches per task, an uncounted pipe is 144
351
+ * research runs inside the bound that is supposed to be the outer one.
352
+ */
353
+ export function remainingTaskResearch(taskBudget, counters) {
354
+ if (taskBudget.maxResearch == null) return null;
355
+ return Math.max(0, taskBudget.maxResearch - (counters?.research ?? 0));
356
+ }
357
+
358
+ // ─────────────────────────────────────────────────────────────────────────────
359
+ // Tier persona gate (B3) — heavy apparatus is not available at low tiers
360
+ // ─────────────────────────────────────────────────────────────────────────────
361
+ //
362
+ // "A trivial ask gets one specialist" was prose in the system prompt, and prose
363
+ // lost: a one-line Azure permission change was routed through planner →
364
+ // plan-reviewer → security-auditor and grew a 1216-line plan. These personas
365
+ // each open a pipeline (plans, reviews, findings that ratchet back into the
366
+ // plan), so at trivial/small tiers they are refused in code. The escape hatch is
367
+ // the honest one: raise the tier with a reason.
368
+
369
+ export const HEAVY_PERSONAS = ["planner", "plan-reviewer", "architect", "security-auditor", "deep-researcher"];
370
+ export const REVIEW_PERSONAS = ["code-reviewer", "plan-reviewer", "security-auditor"];
371
+ const GATED_TIERS = new Set(["trivial", "small"]);
372
+
373
+ /**
374
+ * Refuse a heavy persona at a low tier. Returns null when allowed, else
375
+ * { reason, message }. Unknown/absent tier never gates (strict mode leaves the
376
+ * tier unset on purpose).
377
+ */
378
+ export function checkTierPersonaGate(tier, persona) {
379
+ const t = normalizeTaskTier(tier);
380
+ if (!t || !GATED_TIERS.has(t)) return null;
381
+ const name = String(persona || "").trim().toLowerCase();
382
+ if (!HEAVY_PERSONAS.includes(name)) return null;
383
+ return {
384
+ reason: "tier_persona_gate",
385
+ message: `⚠ ${name} is not available at tier "${t}" — and this dispatch was NOT counted against any budget.\n` +
386
+ `At trivial/small tiers the apparatus is one specialist plus its own evidence: no planning pipeline, ` +
387
+ `no plan review, no separate audit pass. Each of those personas opens a document/finding loop whose ` +
388
+ `output then has to be executed and re-reviewed.\n` +
389
+ `Either dispatch the specialist that does the actual work (builder, test-engineer, code-reviewer, ` +
390
+ `documenter), or — if the ask really is bigger than "${t}" — call set_task_tier with a higher tier ` +
391
+ `AND a reason naming what it turned out to contain. Do not raise the tier merely to unlock a persona.`,
392
+ };
393
+ }
394
+
395
+ // ─────────────────────────────────────────────────────────────────────────────
396
+ // Review finding budget (B6) — a review is a gate, and a gate has a size
397
+ // ─────────────────────────────────────────────────────────────────────────────
398
+ //
399
+ // Unbounded review authority is a ratchet: every round produced new blocking
400
+ // findings, each finding added an invariant to the plan, and the enlarged plan
401
+ // justified another round. PLAN37 recorded P37-001…011, R37-IMM-001 and six
402
+ // script-review remediations — none of which the user asked for. The cap is on
403
+ // BLOCKING findings only; everything else still gets reported, just not as a gate.
404
+
405
+ export const BLOCKING_FINDING_CAPS = { trivial: 1, small: 2, feature: 5, project: null };
406
+
407
+ // Review ROUNDS per task. The finding cap is an instruction to the reviewer, and
408
+ // an instruction is exactly what this whole change exists to stop relying on —
409
+ // but the finding cap is also the wrong thing to enforce mechanically: no rule
410
+ // the hub can evaluate distinguishes "invents a new manifest" from "this leaks a
411
+ // credential", and silently demoting the second is worse than tolerating the
412
+ // first. What the hub CAN own is its own action. The ratchet needs a second
413
+ // round to close, so the round count is where it is cut — deterministically,
414
+ // with no judgement about finding content.
415
+ export const REVIEW_ROUND_CAPS = { trivial: 1, small: 1, feature: 2, project: null };
416
+
417
+ /** Review rounds allowed on one task at this tier; null = uncapped. */
418
+ export function reviewRoundCap(tier) {
419
+ const t = normalizeTaskTier(tier);
420
+ if (!t) return null;
421
+ return REVIEW_ROUND_CAPS[t] ?? null;
422
+ }
423
+
424
+ /**
425
+ * Refuse an (N+1)-th review dispatch on the same task.
426
+ * Returns null when allowed, else { reason, message }.
427
+ */
428
+ export function checkReviewRoundCap(tier, persona, roundsSoFar) {
429
+ if (!isReviewPersona(persona)) return null;
430
+ const cap = reviewRoundCap(tier);
431
+ if (cap == null || roundsSoFar < cap) return null;
432
+ const t = normalizeTaskTier(tier);
433
+ return {
434
+ reason: "review_round_cap",
435
+ message: `⚠ Review round cap reached: ${roundsSoFar} of ${cap} review dispatch${cap === 1 ? "" : "es"} ` +
436
+ `already spent on this task at tier "${t}" — and this dispatch was NOT counted against any budget.\n` +
437
+ `A review is a GATE, not a loop. The findings from the round you already have are the gate: fix them, ` +
438
+ `re-verify only the assertions the fix touched, and close. Re-reviewing the same work to see whether ` +
439
+ `the fix produced new findings is the ratchet — each round's findings become requirements, and the ` +
440
+ `enlarged requirement set justifies the next round.\n` +
441
+ `If this genuinely is a different review (a different subsystem, or work the earlier round never saw), ` +
442
+ `raise the tier with a reason via set_task_tier, or open a new task window with /af-new-task.`,
443
+ };
444
+ }
445
+
446
+ /** Blocking-finding cap for a tier; null = uncapped (project / unset tier). */
447
+ export function blockingFindingCap(tier) {
448
+ const t = normalizeTaskTier(tier);
449
+ if (!t) return null;
450
+ return BLOCKING_FINDING_CAPS[t] ?? null;
451
+ }
452
+
453
+ /** Is this a review persona (gets the finding-budget clause)? */
454
+ export function isReviewPersona(persona) {
455
+ return REVIEW_PERSONAS.includes(String(persona || "").trim().toLowerCase());
456
+ }
457
+
458
+ /**
459
+ * The finding-budget clause appended to a review persona's task text.
460
+ * Returns null when the persona is not a reviewer or the tier is uncapped.
461
+ */
462
+ export function reviewBudgetClause(tier, persona) {
463
+ if (!isReviewPersona(persona)) return null;
464
+ const cap = blockingFindingCap(tier);
465
+ if (cap == null) return null;
466
+ return [
467
+ `## Finding budget (task tier: ${normalizeTaskTier(tier)})`,
468
+ ``,
469
+ `Report at most ${cap} BLOCKING finding${cap === 1 ? "" : "s"}. Rank by severity and put everything`,
470
+ `else under a "## Non-blocking (optional)" heading — non-blocking findings are advice, and must not`,
471
+ `gate the change or be re-raised as blockers in a later round.`,
472
+ ``,
473
+ `A blocking finding may only enforce an invariant the task, the plan, or the project rules ALREADY`,
474
+ `state. It may NOT introduce a new invariant, a new evidence artifact, a new script/manifest/fixture,`,
475
+ `or a new process requirement — that is scope growth wearing a reviewer's hat. If you believe a new`,
476
+ `invariant is genuinely needed, write it under "## Non-blocking (optional)" as a recommendation for`,
477
+ `the human to decide, and do not block on it.`,
478
+ ].join("\n");
479
+ }
@@ -0,0 +1,87 @@
1
+ // Immutable per-run artifact namespaces — the pure policy core behind "a run's
2
+ // artifacts are never overwritten by the next run".
3
+ //
4
+ // The observed failure: `.pi/agent-sessions/artifacts/` was deleted at session
5
+ // start, and specialist returns were named by a per-session counter
6
+ // (`returns/builder-run1.md`). Two consequences, both hit at once: a later
7
+ // session's `builder-run1.md` occupied the same path as an earlier one, and the
8
+ // start-of-session wipe removed eleven implementation returns and two review
9
+ // artifacts that a post-mortem then had to record as NOT RECOVERABLE.
10
+ //
11
+ // The fix is not retention-by-luck: each session archives the previous session's
12
+ // artifacts into `runs/<runId>/`, a namespace that is written once and never
13
+ // reused, and records it in `runs/index.json`. Pruning is explicit and bounded,
14
+ // so the directory cannot grow without limit either.
15
+
16
+ export const DEFAULT_RUN_HISTORY_KEEP = 10;
17
+ export const RUNS_DIRNAME = "runs";
18
+ export const RUN_INDEX_FILENAME = "index.json";
19
+
20
+ /**
21
+ * Run id: sortable UTC timestamp + a short random suffix, so two sessions
22
+ * starting in the same second still get distinct namespaces.
23
+ * `2026-08-03T09-10-42-a3f9`
24
+ */
25
+ export function makeRunId(date = new Date(), suffix = null) {
26
+ const iso = new Date(date).toISOString().replace(/\.\d+Z$/, "").replace(/:/g, "-");
27
+ const tail = suffix ?? Math.random().toString(36).slice(2, 6);
28
+ return `${iso}-${tail}`;
29
+ }
30
+
31
+ /** A run id we generated (used to filter stray directories out of `runs/`). */
32
+ export function isRunId(name) {
33
+ return /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-[a-z0-9]{2,8}$/.test(String(name || ""));
34
+ }
35
+
36
+ /**
37
+ * Which run directories to delete so at most `keep` survive.
38
+ * Run ids sort lexicographically by time, so newest = last. `keep: null`
39
+ * ("off") prunes nothing; non-run-id entries are never touched.
40
+ */
41
+ export function pruneRunDirs(names, keep = DEFAULT_RUN_HISTORY_KEEP) {
42
+ if (keep == null) return [];
43
+ const runs = (names || []).filter(isRunId).sort();
44
+ const limit = Math.max(0, keep);
45
+ if (runs.length <= limit) return [];
46
+ return runs.slice(0, runs.length - limit);
47
+ }
48
+
49
+ /**
50
+ * The metadata written once into `runs/<runId>/meta.json`. Carries the
51
+ * identifiers a post-mortem needs and could not previously recover: which
52
+ * workspace/project/repo the run belonged to, and when it started and ended.
53
+ */
54
+ export function buildRunMeta({ runId, startedAt = null, archivedAt = Date.now(), cwd = null, project = null, workspace = null, artifactCounts = null }) {
55
+ return {
56
+ runId,
57
+ startedAt: startedAt == null ? null : new Date(startedAt).toISOString(),
58
+ archivedAt: new Date(archivedAt).toISOString(),
59
+ cwd,
60
+ project,
61
+ workspace,
62
+ artifactCounts,
63
+ note: "Immutable archive of one agent-hub session's artifacts. Written once; never rewritten.",
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Fold a run entry into `runs/index.json`, newest last, capped at `keep`.
69
+ * Re-indexing the same runId replaces its entry rather than duplicating it.
70
+ */
71
+ export function appendRunIndex(existing, entry, keep = DEFAULT_RUN_HISTORY_KEEP) {
72
+ const runs = Array.isArray(existing?.runs) ? existing.runs.filter((r) => r && r.runId !== entry.runId) : [];
73
+ runs.push(entry);
74
+ runs.sort((a, b) => String(a.runId).localeCompare(String(b.runId)));
75
+ const trimmed = keep == null ? runs : runs.slice(Math.max(0, runs.length - Math.max(0, keep)));
76
+ return { version: 1, updatedAt: new Date().toISOString(), runs: trimmed };
77
+ }
78
+
79
+ /** Parse the `run-history-keep:` overrides value → number, null ("off"), or undefined. */
80
+ export function normalizeRunHistoryKeep(value) {
81
+ const raw = String(value ?? "").trim().toLowerCase();
82
+ if (!raw) return undefined;
83
+ if (raw === "off" || raw === "none" || raw === "0") return null;
84
+ const n = Number(raw);
85
+ if (!Number.isFinite(n) || n < 1) return undefined;
86
+ return Math.floor(n);
87
+ }
@@ -0,0 +1,22 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+
4
+ const CONTINUE_ENTRY = /damage-control-continue[/\\]index\.ts$/;
5
+ const MISSING_SAFETY_ERROR = "damage-control-continue harness not found — guarded child dispatch refused";
6
+
7
+ /** Resolve only the surviving continue harness; never downgrade to an unguarded or hard-stop child. */
8
+ export function resolveSafetyHarness(cwd: string, argv: string[] = process.argv): string | null {
9
+ for (let i = 0; i < argv.length - 1; i++) {
10
+ if (argv[i] !== "-e" && argv[i] !== "--extension") continue;
11
+ const candidate = resolve(argv[i + 1]);
12
+ if (CONTINUE_ENTRY.test(candidate) && existsSync(candidate)) return candidate;
13
+ }
14
+ const local = join(cwd, ".pi", "harnesses", "damage-control-continue", "index.ts");
15
+ return existsSync(local) ? local : null;
16
+ }
17
+
18
+ export function requireSafetyHarness(path: string | null):
19
+ | { ok: true; extensions: string[] }
20
+ | { ok: false; error: string } {
21
+ return path ? { ok: true, extensions: [path] } : { ok: false, error: MISSING_SAFETY_ERROR };
22
+ }