@chankov/agent-fleet 1.0.1 → 1.0.2

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 (316) hide show
  1. package/.pi/extensions/package-lock.json +77 -45
  2. package/.pi/harnesses/agent-hub/README.md +109 -18
  3. package/.pi/harnesses/agent-hub/budget-continuation.ts +73 -0
  4. package/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  5. package/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
  6. package/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  7. package/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
  8. package/.pi/harnesses/agent-hub/hub-state-audit.js +18 -0
  9. package/.pi/harnesses/agent-hub/index.ts +988 -422
  10. package/.pi/harnesses/agent-hub/package.json +1 -1
  11. package/.pi/harnesses/agent-hub/posture.ts +72 -17
  12. package/.pi/harnesses/agent-hub/run-budget.js +12 -13
  13. package/.pi/harnesses/agent-hub/spawn.ts +14 -2
  14. package/.pi/harnesses/ask-user-remote/index.ts +59 -4
  15. package/.pi/harnesses/coms/package.json +1 -1
  16. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  17. package/.pi/harnesses/lib/context-budget-child-prompt.ts +179 -0
  18. package/.pi/harnesses/lib/context-budget-hub-prompt.ts +116 -0
  19. package/.pi/harnesses/lib/context-budget-view.ts +107 -0
  20. package/.pi/harnesses/lib/context-budget.ts +114 -0
  21. package/.pi/harnesses/lib/fleet-detail-view.ts +92 -2
  22. package/.pi/harnesses/package-lock.json +73 -80
  23. package/.versions/1.0.2/.pi/agents/dispatch-policy.yaml +32 -0
  24. package/.versions/1.0.2/.pi/agents/model-profiles.yaml +27 -0
  25. package/.versions/1.0.2/.pi/agents/peers.yaml +142 -0
  26. package/.versions/1.0.2/.pi/agents/teams.yaml +41 -0
  27. package/.versions/1.0.2/.pi/damage-control-rules.yaml +297 -0
  28. package/.versions/1.0.2/.pi/extensions/agent-fleet-update-check/README.md +57 -0
  29. package/.versions/1.0.2/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
  30. package/.versions/1.0.2/.pi/extensions/agent-fleet-update-check/package.json +6 -0
  31. package/.versions/1.0.2/.pi/extensions/btw/README.md +120 -0
  32. package/.versions/1.0.2/.pi/extensions/btw/index.ts +914 -0
  33. package/.versions/1.0.2/.pi/extensions/btw/package.json +6 -0
  34. package/.versions/1.0.2/.pi/extensions/btw/state.js +179 -0
  35. package/.versions/1.0.2/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  36. package/.versions/1.0.2/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  37. package/.versions/1.0.2/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  38. package/.versions/1.0.2/.pi/extensions/compact-and-continue/README.md +42 -0
  39. package/.versions/1.0.2/.pi/extensions/compact-and-continue/index.ts +120 -0
  40. package/.versions/1.0.2/.pi/extensions/compact-and-continue/package.json +6 -0
  41. package/.versions/1.0.2/.pi/extensions/mcp-bridge/README.md +46 -0
  42. package/.versions/1.0.2/.pi/extensions/mcp-bridge/index.ts +206 -0
  43. package/.versions/1.0.2/.pi/extensions/mcp-bridge/package.json +6 -0
  44. package/.versions/1.0.2/.pi/extensions/package-lock.json +1175 -0
  45. package/.versions/1.0.2/.pi/extensions/package.json +9 -0
  46. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/README.md +205 -0
  47. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/config.ts +198 -0
  48. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  49. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/index.ts +248 -0
  50. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/package.json +6 -0
  51. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  52. package/.versions/1.0.2/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  53. package/.versions/1.0.2/.pi/harnesses/agent-hub/README.md +1156 -0
  54. package/.versions/1.0.2/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  55. package/.versions/1.0.2/.pi/harnesses/agent-hub/artifacts.js +146 -0
  56. package/.versions/1.0.2/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  57. package/.versions/1.0.2/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  58. package/.versions/1.0.2/.pi/harnesses/agent-hub/budget-continuation.ts +73 -0
  59. package/.versions/1.0.2/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  60. package/.versions/1.0.2/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
  61. package/.versions/1.0.2/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  62. package/.versions/1.0.2/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
  63. package/.versions/1.0.2/.pi/harnesses/agent-hub/context-window.js +106 -0
  64. package/.versions/1.0.2/.pi/harnesses/agent-hub/delegate.ts +435 -0
  65. package/.versions/1.0.2/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  66. package/.versions/1.0.2/.pi/harnesses/agent-hub/drift-watchdog.js +211 -0
  67. package/.versions/1.0.2/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  68. package/.versions/1.0.2/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  69. package/.versions/1.0.2/.pi/harnesses/agent-hub/footer.ts +35 -0
  70. package/.versions/1.0.2/.pi/harnesses/agent-hub/helpers.ts +266 -0
  71. package/.versions/1.0.2/.pi/harnesses/agent-hub/hub-state-audit.js +73 -0
  72. package/.versions/1.0.2/.pi/harnesses/agent-hub/index.ts +9909 -0
  73. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  74. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  75. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  76. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  77. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  78. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  79. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  80. package/.versions/1.0.2/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  81. package/.versions/1.0.2/.pi/harnesses/agent-hub/package.json +7 -0
  82. package/.versions/1.0.2/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  83. package/.versions/1.0.2/.pi/harnesses/agent-hub/posture.ts +158 -0
  84. package/.versions/1.0.2/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  85. package/.versions/1.0.2/.pi/harnesses/agent-hub/research-retention.js +34 -0
  86. package/.versions/1.0.2/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  87. package/.versions/1.0.2/.pi/harnesses/agent-hub/return-contract.js +293 -0
  88. package/.versions/1.0.2/.pi/harnesses/agent-hub/return-extract.js +75 -0
  89. package/.versions/1.0.2/.pi/harnesses/agent-hub/review-findings.js +102 -0
  90. package/.versions/1.0.2/.pi/harnesses/agent-hub/run-budget.js +539 -0
  91. package/.versions/1.0.2/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  92. package/.versions/1.0.2/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  93. package/.versions/1.0.2/.pi/harnesses/agent-hub/scope-gate.js +103 -0
  94. package/.versions/1.0.2/.pi/harnesses/agent-hub/session-health.js +110 -0
  95. package/.versions/1.0.2/.pi/harnesses/agent-hub/spawn.ts +366 -0
  96. package/.versions/1.0.2/.pi/harnesses/agent-hub/version.ts +42 -0
  97. package/.versions/1.0.2/.pi/harnesses/ask-user-remote/README.md +53 -0
  98. package/.versions/1.0.2/.pi/harnesses/ask-user-remote/index.ts +532 -0
  99. package/.versions/1.0.2/.pi/harnesses/ask-user-remote/race-core.js +106 -0
  100. package/.versions/1.0.2/.pi/harnesses/coms/README.md +100 -0
  101. package/.versions/1.0.2/.pi/harnesses/coms/index.ts +1767 -0
  102. package/.versions/1.0.2/.pi/harnesses/coms/package.json +7 -0
  103. package/.versions/1.0.2/.pi/harnesses/coms/version.ts +42 -0
  104. package/.versions/1.0.2/.pi/harnesses/damage-control-continue/README.md +124 -0
  105. package/.versions/1.0.2/.pi/harnesses/damage-control-continue/index.ts +536 -0
  106. package/.versions/1.0.2/.pi/harnesses/damage-control-continue/package.json +7 -0
  107. package/.versions/1.0.2/.pi/harnesses/damage-control-continue/version.ts +42 -0
  108. package/.versions/1.0.2/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  109. package/.versions/1.0.2/.pi/harnesses/lib/context-budget-child-prompt.ts +179 -0
  110. package/.versions/1.0.2/.pi/harnesses/lib/context-budget-hub-prompt.ts +116 -0
  111. package/.versions/1.0.2/.pi/harnesses/lib/context-budget-view.ts +107 -0
  112. package/.versions/1.0.2/.pi/harnesses/lib/context-budget.ts +114 -0
  113. package/.versions/1.0.2/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  114. package/.versions/1.0.2/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
  115. package/.versions/1.0.2/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
  116. package/.versions/1.0.2/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
  117. package/.versions/1.0.2/.pi/harnesses/lib/fleet-dashboard-ops.ts +155 -0
  118. package/.versions/1.0.2/.pi/harnesses/lib/fleet-dashboard-view.ts +140 -0
  119. package/.versions/1.0.2/.pi/harnesses/lib/fleet-detail-view.ts +133 -0
  120. package/.versions/1.0.2/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  121. package/.versions/1.0.2/.pi/harnesses/lib/fleet-panel.ts +34 -0
  122. package/.versions/1.0.2/.pi/harnesses/lib/fleet-read-model.ts +131 -0
  123. package/.versions/1.0.2/.pi/harnesses/lib/fleet-selection.ts +24 -0
  124. package/.versions/1.0.2/.pi/harnesses/lib/herdr-client.ts +472 -0
  125. package/.versions/1.0.2/.pi/harnesses/lib/herdr-presence.ts +399 -0
  126. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  127. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  128. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  129. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  130. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  131. package/.versions/1.0.2/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  132. package/.versions/1.0.2/.pi/harnesses/lib/spawned-peers.js +190 -0
  133. package/.versions/1.0.2/.pi/harnesses/package-lock.json +2039 -0
  134. package/.versions/1.0.2/.pi/harnesses/package.json +10 -0
  135. package/.versions/1.0.2/.pi/prompts/af-build.md +24 -0
  136. package/.versions/1.0.2/.pi/prompts/af-code-simplify.md +22 -0
  137. package/.versions/1.0.2/.pi/prompts/af-plan.md +16 -0
  138. package/.versions/1.0.2/.pi/prompts/af-review.md +16 -0
  139. package/.versions/1.0.2/.pi/prompts/af-set-hermes-telegram.md +15 -0
  140. package/.versions/1.0.2/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  141. package/.versions/1.0.2/.pi/prompts/af-ship.md +17 -0
  142. package/.versions/1.0.2/.pi/prompts/af-spec.md +15 -0
  143. package/.versions/1.0.2/.pi/prompts/af-test.md +19 -0
  144. package/.versions/1.0.2/.pi/skills/bowser/SKILL.md +145 -0
  145. package/.versions/1.0.2/.version +1 -0
  146. package/.versions/1.0.2/agents/architect.md +24 -0
  147. package/.versions/1.0.2/agents/bowser.md +27 -0
  148. package/.versions/1.0.2/agents/builder.md +54 -0
  149. package/.versions/1.0.2/agents/code-reviewer.md +208 -0
  150. package/.versions/1.0.2/agents/deep-researcher.md +32 -0
  151. package/.versions/1.0.2/agents/documenter.md +18 -0
  152. package/.versions/1.0.2/agents/orchestrator.md +20 -0
  153. package/.versions/1.0.2/agents/plan-reviewer.md +83 -0
  154. package/.versions/1.0.2/agents/planner.md +70 -0
  155. package/.versions/1.0.2/agents/releaser.md +24 -0
  156. package/.versions/1.0.2/agents/researcher.md +28 -0
  157. package/.versions/1.0.2/agents/security-auditor.md +167 -0
  158. package/.versions/1.0.2/agents/test-engineer.md +153 -0
  159. package/.versions/1.0.2/agents/web-debugger.md +43 -0
  160. package/.versions/1.0.2/agents/web-performance-auditor.md +193 -0
  161. package/.versions/1.0.2/bin/catalog/harness-runtime-closure.json +38 -0
  162. package/.versions/1.0.2/codex/CONDUCTOR.md +148 -0
  163. package/.versions/1.0.2/docs/ARCHITECTURE.md +369 -0
  164. package/.versions/1.0.2/docs/agent-fleet-setup.md +468 -0
  165. package/.versions/1.0.2/docs/claude-code-coms-bridge.md +128 -0
  166. package/.versions/1.0.2/docs/codex-remote-conductor.md +170 -0
  167. package/.versions/1.0.2/docs/coms-hermes-bridge.md +189 -0
  168. package/.versions/1.0.2/docs/getting-started.md +98 -0
  169. package/.versions/1.0.2/docs/npm-install.md +292 -0
  170. package/.versions/1.0.2/docs/pi-extensions.md +439 -0
  171. package/.versions/1.0.2/docs/pi-setup.md +74 -0
  172. package/.versions/1.0.2/docs/skill-anatomy.md +150 -0
  173. package/.versions/1.0.2/hermes/README.md +347 -0
  174. package/.versions/1.0.2/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  175. package/.versions/1.0.2/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  176. package/.versions/1.0.2/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  177. package/.versions/1.0.2/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  178. package/.versions/1.0.2/hermes/gates/gate-o-capability.md +8 -0
  179. package/.versions/1.0.2/hermes/gates/gate-o-validator-fixtures.json +1 -0
  180. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
  181. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  182. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  183. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  184. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  185. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  186. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  187. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  188. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  189. package/.versions/1.0.2/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  190. package/.versions/1.0.2/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  191. package/.versions/1.0.2/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  192. package/.versions/1.0.2/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  193. package/.versions/1.0.2/hermes/skills/hub-conductor/SKILL.md +84 -0
  194. package/.versions/1.0.2/hermes/skills/hub-liaison/SKILL.md +84 -0
  195. package/.versions/1.0.2/hermes/skills/hub-watchdog/SKILL.md +76 -0
  196. package/.versions/1.0.2/hermes/skills/hub-watchdog/manifest.json +1 -0
  197. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  198. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  199. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  200. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  201. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  202. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  203. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  204. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  205. package/.versions/1.0.2/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  206. package/.versions/1.0.2/hermes/watchdog-tests/__init__.py +0 -0
  207. package/.versions/1.0.2/hooks/coms-stop-hook.mjs +84 -0
  208. package/.versions/1.0.2/install-manifest.json +2745 -0
  209. package/.versions/1.0.2/justfile +272 -0
  210. package/.versions/1.0.2/manifest-meta.json +882 -0
  211. package/.versions/1.0.2/references/accessibility-checklist.md +160 -0
  212. package/.versions/1.0.2/references/definition-of-done.md +67 -0
  213. package/.versions/1.0.2/references/fleet-coordination-patterns.md +151 -0
  214. package/.versions/1.0.2/references/observability-checklist.md +91 -0
  215. package/.versions/1.0.2/references/orchestration-patterns.md +370 -0
  216. package/.versions/1.0.2/references/performance-checklist.md +153 -0
  217. package/.versions/1.0.2/references/prompting-patterns.md +380 -0
  218. package/.versions/1.0.2/references/security-checklist.md +179 -0
  219. package/.versions/1.0.2/references/testing-patterns.md +236 -0
  220. package/.versions/1.0.2/scripts/codex-conductor.ts +41 -0
  221. package/.versions/1.0.2/scripts/codex-remote-control.ts +167 -0
  222. package/.versions/1.0.2/scripts/coms-claude-bridge.ts +411 -0
  223. package/.versions/1.0.2/scripts/coms-cli.ts +484 -0
  224. package/.versions/1.0.2/scripts/coms-hermes-bridge.ts +413 -0
  225. package/.versions/1.0.2/scripts/fleet.ts +185 -0
  226. package/.versions/1.0.2/scripts/hermes-monitor-capability-runner.ts +25 -0
  227. package/.versions/1.0.2/scripts/hermes-monitor-scenario.ts +474 -0
  228. package/.versions/1.0.2/scripts/hermes-watchdog-capability-probe.ts +45 -0
  229. package/.versions/1.0.2/scripts/install-hermes-plugin.sh +180 -0
  230. package/.versions/1.0.2/scripts/lib/claude-bridge-core.ts +210 -0
  231. package/.versions/1.0.2/scripts/lib/codex-conductor.ts +88 -0
  232. package/.versions/1.0.2/scripts/lib/codex-remote-control.ts +480 -0
  233. package/.versions/1.0.2/scripts/lib/coms-envelope.ts +582 -0
  234. package/.versions/1.0.2/scripts/lib/fake-herdr-server.ts +88 -0
  235. package/.versions/1.0.2/scripts/lib/fleet-command.ts +266 -0
  236. package/.versions/1.0.2/scripts/lib/herdr-layout.ts +281 -0
  237. package/.versions/1.0.2/scripts/lib/hermes-bridge-core.ts +241 -0
  238. package/.versions/1.0.2/scripts/lib/hermes-monitor-events.ts +1 -0
  239. package/.versions/1.0.2/scripts/lib/hermes-monitor-herdr.ts +2 -0
  240. package/.versions/1.0.2/scripts/lib/hermes-monitor-model.ts +3 -0
  241. package/.versions/1.0.2/scripts/lib/hermes-monitor-registry.ts +2 -0
  242. package/.versions/1.0.2/scripts/lib/hermes-monitor-socket.ts +2 -0
  243. package/.versions/1.0.2/scripts/lib/hermes-monitor-store.ts +2 -0
  244. package/.versions/1.0.2/scripts/lib/monitor-env.ts +146 -0
  245. package/.versions/1.0.2/scripts/lib/peer-launch.ts +318 -0
  246. package/.versions/1.0.2/scripts/lib/persona-banner.ts +62 -0
  247. package/.versions/1.0.2/scripts/lib/spawn-stagger.ts +101 -0
  248. package/.versions/1.0.2/scripts/lib/team-project.ts +213 -0
  249. package/.versions/1.0.2/scripts/lib/team-snapshot.ts +147 -0
  250. package/.versions/1.0.2/scripts/peer-banner.ts +40 -0
  251. package/.versions/1.0.2/scripts/peer-launch.ts +259 -0
  252. package/.versions/1.0.2/scripts/team-snapshot.ts +237 -0
  253. package/.versions/1.0.2/scripts/team-up.ts +406 -0
  254. package/.versions/1.0.2/skills/_internal/grilling.md +11 -0
  255. package/.versions/1.0.2/skills/browser-testing-with-devtools/SKILL.md +351 -0
  256. package/.versions/1.0.2/skills/code-review-and-quality/SKILL.md +381 -0
  257. package/.versions/1.0.2/skills/compound-learning/SKILL.md +137 -0
  258. package/.versions/1.0.2/skills/context-engineering/SKILL.md +291 -0
  259. package/.versions/1.0.2/skills/deprecation-and-migration/SKILL.md +206 -0
  260. package/.versions/1.0.2/skills/designing-agents/SKILL.md +394 -0
  261. package/.versions/1.0.2/skills/designing-agents/pi-harness-authoring.md +222 -0
  262. package/.versions/1.0.2/skills/frontend-ui-engineering/SKILL.md +328 -0
  263. package/.versions/1.0.2/skills/git-workflow-and-versioning/SKILL.md +316 -0
  264. package/.versions/1.0.2/skills/idea-refine/SKILL.md +182 -0
  265. package/.versions/1.0.2/skills/idea-refine/examples.md +238 -0
  266. package/.versions/1.0.2/skills/idea-refine/frameworks.md +99 -0
  267. package/.versions/1.0.2/skills/idea-refine/refinement-criteria.md +113 -0
  268. package/.versions/1.0.2/skills/idea-refine/scripts/idea-refine.sh +15 -0
  269. package/.versions/1.0.2/skills/incremental-implementation/SKILL.md +287 -0
  270. package/.versions/1.0.2/skills/interview-me/SKILL.md +226 -0
  271. package/.versions/1.0.2/skills/orchestration-verification/SKILL.md +181 -0
  272. package/.versions/1.0.2/skills/peer-coms/SKILL.md +90 -0
  273. package/.versions/1.0.2/skills/performance-optimization/SKILL.md +350 -0
  274. package/.versions/1.0.2/skills/planning-and-task-breakdown/SKILL.md +254 -0
  275. package/.versions/1.0.2/skills/security-and-hardening/SKILL.md +461 -0
  276. package/.versions/1.0.2/skills/spec-driven-development/SKILL.md +257 -0
  277. package/.versions/1.0.2/skills/using-agent-skills/SKILL.md +199 -0
  278. package/.versions/1.0.2/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
  279. package/.versions/1.0.2/vendor/agent-skills-upstream/LICENSE +21 -0
  280. package/.versions/1.0.2/vendor/agent-skills-upstream/README.md +11 -0
  281. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
  282. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  283. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  284. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  285. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  286. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
  287. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  288. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  289. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
  290. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  291. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  292. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  293. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  294. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  295. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  296. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  297. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  298. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  299. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  300. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
  301. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
  302. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
  303. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
  304. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
  305. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
  306. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
  307. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
  308. package/.versions/1.0.2/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
  309. package/CHANGELOG.md +9 -0
  310. package/README.md +4 -2
  311. package/agents/orchestrator.md +4 -56
  312. package/docs/ARCHITECTURE.md +48 -16
  313. package/docs/agent-fleet-setup.md +33 -2
  314. package/docs/pi-extensions.md +29 -2
  315. package/install-manifest.json +2 -2
  316. package/package.json +2 -2
@@ -0,0 +1,435 @@
1
+ /**
2
+ * delegate — the injected extension that gives an agent-hub specialist a
3
+ * mid-turn `delegate(role, instruction, context?, allow_write?)` tool.
4
+ *
5
+ * The hub adds `-e delegate.ts` (plus `delegate` in the child's `--tools`
6
+ * allowlist — pi's allowlist applies to extension tools too) when a dispatched
7
+ * persona declares `subagents:` in its frontmatter. Everything this extension
8
+ * may spawn comes from AGENT_HUB_DELEGATE_CONFIG (JSON, serialized by the
9
+ * hub): the declared sub-roles and their models, the remaining depth budget,
10
+ * the tree-wide remaining spawn budget, and the event directory. The child
11
+ * process NEVER re-parses persona files — model choice is configuration, not
12
+ * the LLM's whim.
13
+ *
14
+ * Budgets (readable refusals, never silent):
15
+ * - tree-wide spawn budget: at most 4 delegate children per dispatch
16
+ * - depth budget: each child receives `depth − 1`; the hub normally omits
17
+ * delegate tooling from children at remaining depth 0, so a persona with
18
+ * `delegate_depth: 1` (the default and max) can spawn terminal children
19
+ *
20
+ * Write safety: a child is read-only (read,grep,find,ls) unless it is the ONLY
21
+ * live child and the parent passed `allow_write: true` — then it inherits the
22
+ * parent's tools, intersected with the role's declared `tools:` cap when one
23
+ * exists. Concurrent children are always forced read-only (two agents editing
24
+ * the same files is not solvable with guardrails).
25
+ *
26
+ * Observability: every spawn/timeline/usage/exit is appended as JSONL to
27
+ * `<eventDir>/events.jsonl`. The hub watches that file and renders children as
28
+ * nested rows under the parent's grid card (openable via /af-zoom). Kill cascade:
29
+ * children are spawned in THIS process's group (the hub spawns specialists
30
+ * detached), so `/af-agents-kill` on the parent SIGTERMs the whole tree; a
31
+ * SIGTERM trap forwards to live children as a fallback.
32
+ */
33
+
34
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
35
+ import { Type } from "@sinclair/typebox";
36
+ import { appendFileSync, mkdirSync, writeFileSync } from "fs";
37
+ import type { ChildProcess } from "child_process";
38
+ import { spawnPiAgentWithModelFallback, killPiTree } from "./spawn.ts";
39
+ import { DEFAULT_PROVIDER_LIMITS, createProviderSemaphore, parseProviderLimits } from "./provider-semaphore.js";
40
+ import {
41
+ delegateBudgetRefusal,
42
+ DELEGATE_TREE_SPAWN_BUDGET,
43
+ isReadOnlyToolList,
44
+ normalizeDelegateRuntimeBudgets,
45
+ planDelegateSpawn,
46
+ resolveDelegateTools,
47
+ safeAgentKey,
48
+ safePathWithin,
49
+ } from "./helpers.ts";
50
+
51
+ const DEFAULT_CALL_BUDGET = DELEGATE_TREE_SPAWN_BUDGET;
52
+ const RESULT_CAP = 2000;
53
+ const DIGEST_MAX_LINES = 30;
54
+ // How often buffered text/thinking deltas are flushed into the event file.
55
+ const TIMELINE_FLUSH_MS = 700;
56
+
57
+ // Serialized by the hub into AGENT_HUB_DELEGATE_CONFIG. `tag` is this
58
+ // process's node id in the delegation tree ("root" for the specialist itself);
59
+ // nested delegate.ts instances get their child id as tag, so every event line
60
+ // carries an unambiguous parent chain.
61
+ export interface DelegateConfig {
62
+ persona: string;
63
+ tag: string;
64
+ roles: Record<string, { model: string; tools?: string; fallbackModel?: string }>;
65
+ depth: number;
66
+ callBudget: number;
67
+ remainingSpawns?: number;
68
+ parentTools: string;
69
+ personaPrompt: string;
70
+ eventDir: string;
71
+ damageControl?: string;
72
+ delegateExt: string;
73
+ /** Parent-side per-tool deadline inherited by every terminal child. */
74
+ reconSearchTimeoutMs?: number | null;
75
+ /** Whole-run deadline per delegate child (hub mode budget); null/absent = off. */
76
+ turnDeadlineMs?: number | null;
77
+ cwd: string;
78
+ }
79
+
80
+ // Appended to every child's system prompt so it knows its place in the tree
81
+ // and reports tersely (its full report returns through the tool result, which
82
+ // lands in the parent's context).
83
+ function subagentProtocol(persona: string, role: string, canDelegate: boolean): string {
84
+ return `
85
+
86
+ ## You are the "${role}" sub-agent of a ${persona} specialist
87
+ Your parent delegated ONE specific task to you. Do exactly that task — do not
88
+ widen scope, do not start unrelated work. Your full output is written to a result
89
+ file, but your parent receives only a compact digest. End your final message with
90
+ a \`DIGEST:\` section of no more than 30 lines, self-contained, with path:line
91
+ citations where relevant. Put the most important findings and next actions there.${canDelegate ? `
92
+ You may delegate narrow sub-tasks further via your own delegate tool, within
93
+ its declared roles and remaining tree budget.` : `
94
+ You CANNOT delegate further — your remaining depth is 0, so this child has no
95
+ delegate tooling. Do the work yourself with the tools you have.`}`;
96
+ }
97
+
98
+ function childResultDigest(output: string, resultPath: string): { text: string; hasDigest: boolean } {
99
+ const lines = String(output || "").split(/\r?\n/);
100
+ const marker = lines.map(l => l.trim()).findIndex(l => /^DIGEST:\s*$/i.test(l));
101
+ if (marker >= 0) {
102
+ const digestLines = lines.slice(marker, marker + DIGEST_MAX_LINES);
103
+ return {
104
+ text: capInline(`${digestLines.join("\n")}\n\nFull output: ${resultPath}\nRead the result file only if this digest is insufficient.`),
105
+ hasDigest: true,
106
+ };
107
+ }
108
+ const fallback = lines.slice(0, DIGEST_MAX_LINES).join("\n");
109
+ return {
110
+ text: capInline(`${fallback}\n\n[no DIGEST section — full output at ${resultPath}]`),
111
+ hasDigest: false,
112
+ };
113
+ }
114
+
115
+ function capInline(text: string): string {
116
+ return text.length > RESULT_CAP ? text.slice(0, RESULT_CAP) + "\n... [digest truncated]" : text;
117
+ }
118
+
119
+ export default function (pi: ExtensionAPI) {
120
+ let cfg: DelegateConfig | null = null;
121
+ try {
122
+ cfg = JSON.parse(process.env.AGENT_HUB_DELEGATE_CONFIG || "");
123
+ } catch {
124
+ cfg = null;
125
+ }
126
+ // Misconfigured (or launched outside the hub): register nothing — the
127
+ // parent simply has no delegate tool.
128
+ if (!cfg || !cfg.roles || !cfg.eventDir) return;
129
+ const config = cfg;
130
+ const budgets = normalizeDelegateRuntimeBudgets(config, DEFAULT_CALL_BUDGET);
131
+ config.depth = budgets.depth;
132
+ config.callBudget = budgets.callBudget;
133
+ config.remainingSpawns = budgets.remainingSpawns;
134
+
135
+ let callCount = 0;
136
+ let childSeq = 0;
137
+ // Synchronous reservation counter for the write-safety gate. Incremented at
138
+ // the gate (before any await), so two parallel delegate calls can never both
139
+ // observe "I am the only child" — do NOT replace this with liveChildren.size,
140
+ // which only grows once the child process actually spawns.
141
+ let liveCount = 0;
142
+ const liveChildren = new Set<ChildProcess>();
143
+
144
+ // Per-provider concurrency. Four read-only children fanning out at once is a
145
+ // feature against a hosted provider and a mid-run OOM against the local one,
146
+ // so `custom/*` queues past 2 in flight. Queued children still run — they
147
+ // just wait for a permit instead of racing for the same GPU.
148
+ const providerSemaphore = createProviderSemaphore({
149
+ ...DEFAULT_PROVIDER_LIMITS,
150
+ ...parseProviderLimits(process.env.AGENT_HUB_PROVIDER_LIMITS),
151
+ });
152
+
153
+ // Fallback cascade: the primary kill path is the process group (the hub
154
+ // signals the specialist's negative PID), but if only this process is
155
+ // terminated, forward the signal to any live children.
156
+ process.on("SIGTERM", () => {
157
+ for (const child of liveChildren) killPiTree(child, "SIGTERM");
158
+ });
159
+
160
+ const emit = (event: Record<string, unknown>) => {
161
+ try {
162
+ appendFileSync(safePathWithin(config.eventDir, "events.jsonl"), JSON.stringify(event) + "\n", "utf-8");
163
+ } catch {}
164
+ };
165
+
166
+ const roleNames = Object.keys(config.roles).filter((name) => {
167
+ try { safeAgentKey(name); return true; } catch { return false; }
168
+ });
169
+ if (roleNames.length === 0) return;
170
+
171
+ pi.registerTool({
172
+ name: "delegate",
173
+ label: "Delegate",
174
+ description:
175
+ `Spawn one of your declared sub-agents on its pre-configured model and wait for its report. ` +
176
+ `Declared roles: ${roleNames.join(", ")}. Use it to fan out scoped sub-tasks (reviews, scans, ` +
177
+ `doc checks) instead of doing everything yourself; at most ${DELEGATE_TREE_SPAWN_BUDGET} ` +
178
+ `children may be spawned per dispatch, and parallel children are forced read-only. The child ` +
179
+ `does not share your context — pass everything it needs in \`instruction\`/\`context\`.`,
180
+ parameters: Type.Object({
181
+ role: Type.String({ description: `Declared sub-role to spawn. One of: ${roleNames.join(", ")}` }),
182
+ instruction: Type.String({ description: "The specific, self-contained task for the sub-agent." }),
183
+ context: Type.Optional(Type.String({
184
+ description: "Optional background brief pasted above the instruction (the child shares none of " +
185
+ "your context). The keyword 'fork' (full context fork) is accepted but treated as a summary " +
186
+ "brief in v1 — write the brief out.",
187
+ })),
188
+ allow_write: Type.Optional(Type.Boolean({
189
+ description: "Let the child inherit your tools (including write access). Honored only while it " +
190
+ "is your ONLY live child; concurrent children are always read-only. A role-level tools cap " +
191
+ "still wins and refuses delegation if it leaves no tools.",
192
+ })),
193
+ }),
194
+
195
+ async execute(_toolCallId, params, _signal, onUpdate) {
196
+ const { role, instruction, context, allow_write } = params as {
197
+ role: string; instruction: string; context?: string; allow_write?: boolean;
198
+ };
199
+
200
+ // Readable refusals — budget exhaustion is an answer, not a mystery.
201
+ const budgetRefusal = delegateBudgetRefusal({
202
+ depth: config.depth,
203
+ callBudget: config.callBudget,
204
+ remainingSpawns: config.remainingSpawns ?? 0,
205
+ callCount,
206
+ });
207
+ if (budgetRefusal) {
208
+ return { content: [{ type: "text" as const, text: budgetRefusal }] };
209
+ }
210
+ const roleKey = roleNames.find(r => r.toLowerCase() === role.toLowerCase());
211
+ if (!roleKey) {
212
+ return {
213
+ content: [{ type: "text" as const, text:
214
+ `Delegation refused: "${role}" is not a declared sub-role. Declared roles: ` +
215
+ `${roleNames.join(", ")}.` }],
216
+ };
217
+ }
218
+ const roleDef = config.roles[roleKey];
219
+
220
+ // Write safety: read-only unless this is the only live child AND the
221
+ // parent explicitly granted write. The role's tools cap always wins.
222
+ const tools = resolveDelegateTools({
223
+ parentTools: config.parentTools,
224
+ roleTools: roleDef.tools,
225
+ allowWrite: allow_write === true,
226
+ concurrent: liveCount > 0,
227
+ });
228
+ if (tools.refused) {
229
+ return {
230
+ content: [{ type: "text" as const, text:
231
+ `Delegation refused: role "${roleKey}" declares tools "${roleDef.tools}" but none are ` +
232
+ `available under the current parent/concurrency tool policy.` }],
233
+ };
234
+ }
235
+ const effectiveTools = tools.effectiveTools;
236
+ const writeDowngraded = tools.writeDowngraded;
237
+
238
+ callCount++;
239
+ childSeq++;
240
+ const plan = planDelegateSpawn({
241
+ tag: config.tag,
242
+ roleKey,
243
+ childSeq,
244
+ depth: config.depth,
245
+ remainingSpawns: config.remainingSpawns ?? 0,
246
+ effectiveTools,
247
+ damageControl: config.damageControl,
248
+ delegateExt: config.delegateExt,
249
+ });
250
+ config.remainingSpawns = plan.nextRemainingSpawns;
251
+ const childId = plan.childId;
252
+ const childDepth = plan.childDepth;
253
+ const childRemainingSpawns = plan.childRemainingSpawns;
254
+ const childCanDelegate = plan.childCanDelegate;
255
+ const childExtensions = plan.childExtensions;
256
+ const childTools = plan.childTools;
257
+ const childConfig: DelegateConfig | null = plan.includeDelegateConfig ? {
258
+ ...config,
259
+ tag: childId,
260
+ depth: childDepth,
261
+ remainingSpawns: childRemainingSpawns,
262
+ parentTools: effectiveTools,
263
+ } : null;
264
+
265
+ const sessionsDir = safePathWithin(config.eventDir, "sessions");
266
+ const resultsDir = safePathWithin(config.eventDir, "results");
267
+ const childSessionFile = safePathWithin(sessionsDir, `${childId}.jsonl`);
268
+ const childResultFile = safePathWithin(resultsDir, `${childId}.md`);
269
+ try { mkdirSync(sessionsDir, { recursive: true }); } catch {}
270
+ try { mkdirSync(resultsDir, { recursive: true }); } catch {}
271
+
272
+ emit({
273
+ t: "spawn", id: childId, parent: config.tag, role: roleKey,
274
+ model: roleDef.model, tools: effectiveTools, remainingSpawns: childRemainingSpawns, ts: Date.now(),
275
+ });
276
+ onUpdate?.({
277
+ content: [{ type: "text", text: `Delegating to ${roleKey} (${roleDef.model})...` }],
278
+ details: { id: childId, role: roleKey, model: roleDef.model, status: "running" },
279
+ });
280
+
281
+ // Buffered timeline streaming: coalesce text/thinking deltas and flush
282
+ // them into the event file on an interval (and on tool/exit), so the
283
+ // hub can render a live /af-zoom timeline without an event per token.
284
+ let pendingKind: "text" | "thinking" | null = null;
285
+ let pendingDelta = "";
286
+ const flushTimeline = () => {
287
+ if (!pendingKind || !pendingDelta) return;
288
+ emit({ t: "timeline", id: childId, kind: pendingKind, delta: pendingDelta });
289
+ pendingDelta = "";
290
+ };
291
+ const queueDelta = (kind: "text" | "thinking", delta: string) => {
292
+ if (pendingKind !== kind) flushTimeline();
293
+ pendingKind = kind;
294
+ pendingDelta += delta;
295
+ };
296
+ const flushTimer = setInterval(flushTimeline, TIMELINE_FLUSH_MS);
297
+
298
+ const startTime = Date.now();
299
+ // Time spent waiting for a provider permit, reported alongside `elapsed`
300
+ // so a queued child is never mistaken for a slow one (the run deadline is
301
+ // measured from the spawn, not from here).
302
+ let queuedMs = 0;
303
+ let childProc: ChildProcess | null = null;
304
+ const mode = context?.trim().toLowerCase();
305
+ const brief = context && mode !== "summary" && mode !== "fork" ? context : undefined;
306
+ const prompt = brief
307
+ ? `## Context from your parent\n${brief}\n\n## Your task\n${instruction}`
308
+ : instruction;
309
+
310
+ let res;
311
+ liveCount++;
312
+ try {
313
+ const providerCap = providerSemaphore.limitFor(roleDef.model);
314
+ if (providerCap != null && providerSemaphore.inFlight(roleDef.model) >= providerCap) {
315
+ const ahead = providerSemaphore.queued(roleDef.model) + 1;
316
+ emit({ t: "queued", id: childId, model: roleDef.model, ahead, ts: Date.now() });
317
+ onUpdate?.({
318
+ content: [{ type: "text", text: `${roleKey} queued — ${providerCap} requests already in flight on this provider (${ahead} waiting)...` }],
319
+ details: { id: childId, role: roleKey, model: roleDef.model, status: "queued" },
320
+ });
321
+ }
322
+ res = await providerSemaphore.run(roleDef.model, () => {
323
+ queuedMs = Date.now() - startTime;
324
+ return spawnPiAgentWithModelFallback({
325
+ model: roleDef.model,
326
+ tools: childTools,
327
+ thinking: "off",
328
+ appendSystemPrompt: subagentProtocol(config.persona, roleKey, childCanDelegate),
329
+ sessionFile: childSessionFile,
330
+ prompt,
331
+ extensions: childExtensions,
332
+ env: childConfig ? { AGENT_HUB_DELEGATE_CONFIG: JSON.stringify(childConfig) } : undefined,
333
+ cwd: config.cwd,
334
+ // Each nested child owns its group. The SIGTERM trap above forwards
335
+ // parent cancellation so detached children cannot become orphans.
336
+ detached: true,
337
+ signal: _signal,
338
+ // `null` is the explicit `off` override; preserve it rather than
339
+ // silently restoring the default for terminal children.
340
+ toolWatchdog: { timeoutMs: config.reconSearchTimeoutMs === undefined ? 120_000 : config.reconSearchTimeoutMs },
341
+ // Whole-run bound from the hub's mode budget: a hung delegate (the
342
+ // 92-minute conventions scout) must not hold its parent hostage.
343
+ turnDeadlineMs: config.turnDeadlineMs === undefined ? null : config.turnDeadlineMs,
344
+ }, roleDef.fallbackModel, {
345
+ onProcess: (p) => {
346
+ if (childProc) liveChildren.delete(childProc);
347
+ childProc = p;
348
+ liveChildren.add(p);
349
+ },
350
+ onModelFallback: (notice) => {
351
+ emit({ t: "model_fallback", id: childId, ...notice, ts: Date.now() });
352
+ onUpdate?.({
353
+ content: [{ type: "text", text: `Override ${notice.from} failed before work began; retrying ${roleKey} with ${notice.to}...` }],
354
+ details: { id: childId, role: roleKey, model: notice.to, fallback: notice, status: "running" },
355
+ });
356
+ },
357
+ onTextDelta: (delta) => queueDelta("text", delta),
358
+ onThinkingDelta: (delta) => queueDelta("thinking", delta),
359
+ onToolStart: (toolName, argStr) => {
360
+ flushTimeline();
361
+ emit({ t: "tool", id: childId, name: toolName, args: argStr.slice(0, 500) });
362
+ },
363
+ onUsage: (usage, source) => {
364
+ if (source === "message_end") {
365
+ emit({ t: "usage", id: childId, input: usage.input || 0, output: usage.output || 0 });
366
+ }
367
+ },
368
+ }, {
369
+ // A child holding only read tools can be re-run safely, so a
370
+ // provider dying halfway through is recoverable rather than a
371
+ // discarded run. A write-capable child keeps the strict rule:
372
+ // a retry there could duplicate edits. A child that can delegate
373
+ // carries `delegate` in its tool list and so reads as non-read-only
374
+ // here — deliberately: retrying it would re-spawn its grandchildren.
375
+ midRun: isReadOnlyToolList(childTools),
376
+ });
377
+ });
378
+ } finally {
379
+ liveCount--;
380
+ clearInterval(flushTimer);
381
+ if (childProc) liveChildren.delete(childProc);
382
+ }
383
+
384
+ flushTimeline();
385
+ const elapsed = Date.now() - startTime;
386
+ const code = res.spawnError ? 1 : (res.termination ? (res.termination.reason === "cancelled" ? 130 : res.termination.reason === "drift_stop" ? 125 : 124) : (res.exitCode ?? 1));
387
+ emit({ t: "exit", id: childId, code, elapsed, ...(queuedMs > 0 ? { queuedMs } : {}), termination: res.termination, ts: Date.now() });
388
+
389
+ if (res.spawnError) {
390
+ const spawnFailure = `Delegate ${childId} failed to spawn: ${res.spawnError}`;
391
+ try { writeFileSync(childResultFile, spawnFailure + "\n", "utf-8"); } catch {}
392
+ return {
393
+ content: [{ type: "text" as const, text: `${spawnFailure}\n\nFull output: ${childResultFile}` }],
394
+ details: { id: childId, role: roleKey, status: "error", resultPath: childResultFile },
395
+ };
396
+ }
397
+
398
+ let output = res.output;
399
+ if (res.termination) {
400
+ const reason = res.termination.reason;
401
+ const tool = res.termination.tool;
402
+ const explanation = reason === "tool_timeout"
403
+ ? `exceeded its per-tool watchdog on ${tool?.toolName || "tool"} (${tool?.toolCallId || "unknown"})`
404
+ : reason === "turn_timeout"
405
+ ? "exceeded the per-run deadline (mode budget / agent-turn-timeout-s)"
406
+ : reason === "drift_stop"
407
+ ? "was stopped by the drift watchdog"
408
+ : "was cancelled by its caller";
409
+ output = `${reason}: delegate ${childId} ${explanation}; terminationConfirmed=${res.termination.confirmed}.`;
410
+ } else if (code !== 0) {
411
+ const errTail = res.stderr.trim().slice(-1000);
412
+ output = output
413
+ ? `${output}\n\n[stderr]\n${errTail}`
414
+ : `Delegate ${childId} exited with code ${code} and produced no output.\n\n[stderr]\n${errTail}`;
415
+ }
416
+ try { writeFileSync(childResultFile, output, "utf-8"); } catch {}
417
+ const digest = childResultDigest(output, childResultFile);
418
+
419
+ const notes: string[] = [];
420
+ if (writeDowngraded) notes.push("allow_write ignored — other children were live, so it ran read-only");
421
+ if (mode === "fork") notes.push("context: fork is not supported in v1 — the child started fresh from your instruction");
422
+ const noteBlock = notes.length > 0 ? `\n[note: ${notes.join("; ")}]` : "";
423
+
424
+ const fallbackNote = res.modelFallback
425
+ ? `\n[note: overridden model ${res.modelFallback.from} failed before work; retried once with original ${res.modelFallback.to}]`
426
+ : "";
427
+ return {
428
+ content: [{ type: "text" as const, text:
429
+ `[delegate ${childId} · ${res.modelUsed} · ${effectiveTools}] ${res.termination ? res.termination.reason : code === 0 ? "done" : "error"} ` +
430
+ `in ${Math.round(elapsed / 1000)}s${noteBlock}${fallbackNote}\n\n${digest.text}` }],
431
+ details: { id: childId, role: roleKey, model: res.modelUsed, fallback: res.modelFallback, status: res.termination ? res.termination.reason : code === 0 ? "done" : "error", elapsed, resultPath: childResultFile, digestFound: digest.hasDigest, termination: res.termination },
432
+ };
433
+ },
434
+ });
435
+ }
@@ -0,0 +1,122 @@
1
+ // Docs-only lane — the pure policy core behind "a documentation change is not a
2
+ // code change". A closeout that touched only markdown was routed through a full
3
+ // code-review gate, which produced a reviewer cycle, a stop, and an objection
4
+ // from the human; the review had no code to review. This module decides, from a
5
+ // dispatch's declared `scope` globs alone, whether the change is documentation.
6
+ //
7
+ // Everything here is data + pure functions so the policy is unit-testable away
8
+ // from the harness.
9
+
10
+ import { REVIEW_PERSONAS } from "./run-budget.js";
11
+
12
+ // Extensions that are documentation by nature.
13
+ const DOC_EXTENSIONS = new Set(["md", "mdx", "markdown", "rst", "adoc", "txt"]);
14
+
15
+ // Path prefixes whose entire subtree is documentation/evidence. Matched on the
16
+ // first segment, case-insensitively.
17
+ const DOC_DIRS = new Set(["docs", "doc", "artifacts", "adr", "adrs", "changelog", ".changeset"]);
18
+
19
+ // Extensionless files that are documentation when they sit at a scope root.
20
+ const DOC_BASENAMES = new Set(["readme", "license", "licence", "changelog", "contributing", "notice", "authors", "codeowners"]);
21
+
22
+ // Personas whose dispatch is a review GATE. test-engineer is included: asking
23
+ // for tests on a markdown change is the same category error as asking for a
24
+ // code review of it.
25
+ export const DOCS_BLOCKED_PERSONAS = [...REVIEW_PERSONAS, "test-engineer"];
26
+
27
+ /** Strip glob magic so a pattern can be judged by its literal shape. */
28
+ function literalize(glob) {
29
+ return String(glob || "")
30
+ .trim()
31
+ .replace(/\\/g, "/")
32
+ .replace(/^\.\//, "")
33
+ .replace(/^\/+/, "");
34
+ }
35
+
36
+ /**
37
+ * Is ONE glob confined to documentation?
38
+ * `Docs/**`, `**\/*.md`, `CHANGELOG.md`, `artifacts/evidence/*.png` → true.
39
+ * `**`, `src/**`, `**\/*.{md,ts}`, `RIN.Live/**\/*.md` → the last one is true
40
+ * (it can only ever match markdown), the first three are false.
41
+ */
42
+ export function isDocsGlob(glob) {
43
+ const pattern = literalize(glob);
44
+ if (!pattern) return false;
45
+
46
+ const segments = pattern.split("/").filter(Boolean);
47
+ if (segments.length === 0) return false;
48
+
49
+ // A leading documentation directory confines everything beneath it, whatever
50
+ // the tail looks like — `Docs/**`, `artifacts/evidence/*.png`.
51
+ const first = segments[0].toLowerCase();
52
+ if (DOC_DIRS.has(first) && !first.includes("*")) return true;
53
+
54
+ // Otherwise the FINAL segment has to confine the match to a doc file: any
55
+ // wildcard directory in between is fine, since the leaf still decides.
56
+ const leaf = segments[segments.length - 1];
57
+ if (!leaf || leaf === "**" || leaf === "*") return false;
58
+
59
+ // Brace alternation is only docs when EVERY alternative is.
60
+ const braces = leaf.match(/\{([^}]*)\}/);
61
+ if (braces) {
62
+ const alternatives = braces[1].split(",").map((a) => a.trim()).filter(Boolean);
63
+ if (alternatives.length === 0) return false;
64
+ return alternatives.every((alt) => isDocsGlob(leaf.replace(/\{[^}]*\}/, alt)));
65
+ }
66
+
67
+ const dot = leaf.lastIndexOf(".");
68
+ if (dot === -1) {
69
+ // No extension: only a known documentation basename counts, and only when
70
+ // it carries no wildcard (`README` yes, `REA*` no).
71
+ if (/[*?[\]]/.test(leaf)) return false;
72
+ return DOC_BASENAMES.has(leaf.toLowerCase());
73
+ }
74
+ const ext = leaf.slice(dot + 1).toLowerCase();
75
+ if (/[*?[\]]/.test(ext)) return false;
76
+ return DOC_EXTENSIONS.has(ext);
77
+ }
78
+
79
+ /**
80
+ * Is the whole declared scope documentation-only? An empty/absent scope is NOT
81
+ * docs-only — an undeclared scope means "unknown", and unknown is never the
82
+ * lighter lane.
83
+ */
84
+ export function isDocsOnlyScope(globs) {
85
+ const list = (globs || []).map(literalize).filter(Boolean);
86
+ if (list.length === 0) return false;
87
+ return list.every((glob) => isDocsGlob(glob));
88
+ }
89
+
90
+ /**
91
+ * Gate a review-persona dispatch whose scope is documentation only.
92
+ * Returns null when allowed, else { reason, message }. `reviewReason` is the
93
+ * dispatcher's explicit justification and always opens the gate — a docs change
94
+ * CAN warrant review (a published credential, a contractual API doc), it just
95
+ * must not be the default.
96
+ */
97
+ export function checkDocsLane(agent, scopeGlobs, reviewReason = "") {
98
+ const name = String(agent || "").trim().toLowerCase();
99
+ if (!DOCS_BLOCKED_PERSONAS.includes(name)) return null;
100
+ if (!isDocsOnlyScope(scopeGlobs)) return null;
101
+ if (String(reviewReason || "").trim()) return null;
102
+ return {
103
+ reason: "docs_only_lane",
104
+ message: `⚠ ${name} refused for a documentation-only scope — and this dispatch was NOT counted ` +
105
+ `against any budget.\nScope: ${(scopeGlobs || []).join(", ")}\n` +
106
+ `Documentation changes run in the single-worker docs lane: the writer verifies its own change ` +
107
+ `(links resolve, statements match the code it describes) and the work is done. A review gate here ` +
108
+ `produces a round trip with no code to review.\n` +
109
+ `If this docs change genuinely needs a gate — it publishes a credential or secret, it states a ` +
110
+ `contract other systems rely on, or the human asked for a review — re-dispatch with ` +
111
+ `\`review_reason: "<why>"\`. If the change also touches code, put those paths in \`scope\` too.`,
112
+ };
113
+ }
114
+
115
+ /** Note appended to a non-review dispatch that runs in the docs lane. */
116
+ export function docsLaneNotice(agent, scopeGlobs) {
117
+ if (!isDocsOnlyScope(scopeGlobs)) return null;
118
+ const name = String(agent || "").trim().toLowerCase();
119
+ if (DOCS_BLOCKED_PERSONAS.includes(name)) return null;
120
+ return `📝 Docs lane: this dispatch's scope is documentation only, so it needs no review gate. ` +
121
+ `Take ${name}'s own verification as sufficient and close the item — do not dispatch a reviewer for it.`;
122
+ }