@chankov/agent-fleet 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/.pi/harnesses/agent-hub/README.md +25 -11
  2. package/.pi/harnesses/agent-hub/delegate.ts +14 -3
  3. package/.pi/harnesses/agent-hub/index.ts +212 -40
  4. package/.pi/harnesses/agent-hub/package.json +1 -1
  5. package/.pi/harnesses/agent-hub/spawn.ts +25 -3
  6. package/.pi/harnesses/coms/package.json +1 -1
  7. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  8. package/.pi/harnesses/lib/fleet-dashboard-ops.ts +2 -2
  9. package/.pi/harnesses/lib/fleet-detail-view.ts +95 -16
  10. package/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
  11. package/.pi/prompts/af-plan.md +6 -5
  12. package/.versions/1.0.4/.pi/agents/dispatch-policy.yaml +32 -0
  13. package/.versions/1.0.4/.pi/agents/model-profiles.yaml +27 -0
  14. package/.versions/1.0.4/.pi/agents/peers.yaml +142 -0
  15. package/.versions/1.0.4/.pi/agents/teams.yaml +41 -0
  16. package/.versions/1.0.4/.pi/damage-control-rules.yaml +297 -0
  17. package/.versions/1.0.4/.pi/extensions/agent-fleet-update-check/README.md +57 -0
  18. package/.versions/1.0.4/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
  19. package/.versions/1.0.4/.pi/extensions/agent-fleet-update-check/package.json +6 -0
  20. package/.versions/1.0.4/.pi/extensions/btw/README.md +120 -0
  21. package/.versions/1.0.4/.pi/extensions/btw/index.ts +914 -0
  22. package/.versions/1.0.4/.pi/extensions/btw/package.json +6 -0
  23. package/.versions/1.0.4/.pi/extensions/btw/state.js +179 -0
  24. package/.versions/1.0.4/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  25. package/.versions/1.0.4/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  26. package/.versions/1.0.4/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  27. package/.versions/1.0.4/.pi/extensions/compact-and-continue/README.md +42 -0
  28. package/.versions/1.0.4/.pi/extensions/compact-and-continue/index.ts +120 -0
  29. package/.versions/1.0.4/.pi/extensions/compact-and-continue/package.json +6 -0
  30. package/.versions/1.0.4/.pi/extensions/mcp-bridge/README.md +46 -0
  31. package/.versions/1.0.4/.pi/extensions/mcp-bridge/index.ts +206 -0
  32. package/.versions/1.0.4/.pi/extensions/mcp-bridge/package.json +6 -0
  33. package/.versions/1.0.4/.pi/extensions/package-lock.json +1175 -0
  34. package/.versions/1.0.4/.pi/extensions/package.json +9 -0
  35. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/README.md +205 -0
  36. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/config.ts +198 -0
  37. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  38. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/index.ts +248 -0
  39. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/package.json +6 -0
  40. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  41. package/.versions/1.0.4/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  42. package/.versions/1.0.4/.pi/harnesses/agent-hub/README.md +1170 -0
  43. package/.versions/1.0.4/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  44. package/.versions/1.0.4/.pi/harnesses/agent-hub/artifacts.js +146 -0
  45. package/.versions/1.0.4/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  46. package/.versions/1.0.4/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  47. package/.versions/1.0.4/.pi/harnesses/agent-hub/budget-continuation.ts +73 -0
  48. package/.versions/1.0.4/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  49. package/.versions/1.0.4/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
  50. package/.versions/1.0.4/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  51. package/.versions/1.0.4/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
  52. package/.versions/1.0.4/.pi/harnesses/agent-hub/context-window.js +106 -0
  53. package/.versions/1.0.4/.pi/harnesses/agent-hub/delegate.ts +446 -0
  54. package/.versions/1.0.4/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  55. package/.versions/1.0.4/.pi/harnesses/agent-hub/drift-watchdog.js +218 -0
  56. package/.versions/1.0.4/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  57. package/.versions/1.0.4/.pi/harnesses/agent-hub/execution-profile.ts +69 -0
  58. package/.versions/1.0.4/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  59. package/.versions/1.0.4/.pi/harnesses/agent-hub/footer.ts +36 -0
  60. package/.versions/1.0.4/.pi/harnesses/agent-hub/helpers.ts +266 -0
  61. package/.versions/1.0.4/.pi/harnesses/agent-hub/hub-state-audit.js +59 -0
  62. package/.versions/1.0.4/.pi/harnesses/agent-hub/index.ts +10171 -0
  63. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  64. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  65. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  66. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  67. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  68. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  69. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  70. package/.versions/1.0.4/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  71. package/.versions/1.0.4/.pi/harnesses/agent-hub/package.json +7 -0
  72. package/.versions/1.0.4/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  73. package/.versions/1.0.4/.pi/harnesses/agent-hub/posture.ts +158 -0
  74. package/.versions/1.0.4/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  75. package/.versions/1.0.4/.pi/harnesses/agent-hub/research-retention.js +34 -0
  76. package/.versions/1.0.4/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  77. package/.versions/1.0.4/.pi/harnesses/agent-hub/return-contract.js +293 -0
  78. package/.versions/1.0.4/.pi/harnesses/agent-hub/return-extract.js +75 -0
  79. package/.versions/1.0.4/.pi/harnesses/agent-hub/review-findings.js +102 -0
  80. package/.versions/1.0.4/.pi/harnesses/agent-hub/run-budget.js +537 -0
  81. package/.versions/1.0.4/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  82. package/.versions/1.0.4/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  83. package/.versions/1.0.4/.pi/harnesses/agent-hub/scope-gate.js +103 -0
  84. package/.versions/1.0.4/.pi/harnesses/agent-hub/session-health.js +110 -0
  85. package/.versions/1.0.4/.pi/harnesses/agent-hub/spawn.ts +388 -0
  86. package/.versions/1.0.4/.pi/harnesses/agent-hub/version.ts +42 -0
  87. package/.versions/1.0.4/.pi/harnesses/ask-user-remote/README.md +53 -0
  88. package/.versions/1.0.4/.pi/harnesses/ask-user-remote/index.ts +532 -0
  89. package/.versions/1.0.4/.pi/harnesses/ask-user-remote/race-core.js +106 -0
  90. package/.versions/1.0.4/.pi/harnesses/coms/README.md +100 -0
  91. package/.versions/1.0.4/.pi/harnesses/coms/index.ts +1767 -0
  92. package/.versions/1.0.4/.pi/harnesses/coms/package.json +7 -0
  93. package/.versions/1.0.4/.pi/harnesses/coms/version.ts +42 -0
  94. package/.versions/1.0.4/.pi/harnesses/damage-control-continue/README.md +124 -0
  95. package/.versions/1.0.4/.pi/harnesses/damage-control-continue/index.ts +536 -0
  96. package/.versions/1.0.4/.pi/harnesses/damage-control-continue/package.json +7 -0
  97. package/.versions/1.0.4/.pi/harnesses/damage-control-continue/version.ts +42 -0
  98. package/.versions/1.0.4/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  99. package/.versions/1.0.4/.pi/harnesses/lib/context-budget-child-prompt.ts +179 -0
  100. package/.versions/1.0.4/.pi/harnesses/lib/context-budget-hub-prompt.ts +116 -0
  101. package/.versions/1.0.4/.pi/harnesses/lib/context-budget-view.ts +107 -0
  102. package/.versions/1.0.4/.pi/harnesses/lib/context-budget.ts +114 -0
  103. package/.versions/1.0.4/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  104. package/.versions/1.0.4/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
  105. package/.versions/1.0.4/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
  106. package/.versions/1.0.4/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
  107. package/.versions/1.0.4/.pi/harnesses/lib/fleet-dashboard-ops.ts +155 -0
  108. package/.versions/1.0.4/.pi/harnesses/lib/fleet-dashboard-view.ts +142 -0
  109. package/.versions/1.0.4/.pi/harnesses/lib/fleet-detail-view.ts +247 -0
  110. package/.versions/1.0.4/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  111. package/.versions/1.0.4/.pi/harnesses/lib/fleet-panel.ts +34 -0
  112. package/.versions/1.0.4/.pi/harnesses/lib/fleet-read-model.ts +131 -0
  113. package/.versions/1.0.4/.pi/harnesses/lib/fleet-selection.ts +24 -0
  114. package/.versions/1.0.4/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
  115. package/.versions/1.0.4/.pi/harnesses/lib/herdr-client.ts +472 -0
  116. package/.versions/1.0.4/.pi/harnesses/lib/herdr-presence.ts +399 -0
  117. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  118. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  119. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  120. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  121. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  122. package/.versions/1.0.4/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  123. package/.versions/1.0.4/.pi/harnesses/lib/spawned-peers.js +190 -0
  124. package/.versions/1.0.4/.pi/harnesses/package-lock.json +2039 -0
  125. package/.versions/1.0.4/.pi/harnesses/package.json +10 -0
  126. package/.versions/1.0.4/.pi/prompts/af-build.md +24 -0
  127. package/.versions/1.0.4/.pi/prompts/af-code-simplify.md +22 -0
  128. package/.versions/1.0.4/.pi/prompts/af-plan.md +17 -0
  129. package/.versions/1.0.4/.pi/prompts/af-review.md +16 -0
  130. package/.versions/1.0.4/.pi/prompts/af-set-hermes-telegram.md +15 -0
  131. package/.versions/1.0.4/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  132. package/.versions/1.0.4/.pi/prompts/af-ship.md +17 -0
  133. package/.versions/1.0.4/.pi/prompts/af-spec.md +15 -0
  134. package/.versions/1.0.4/.pi/prompts/af-test.md +19 -0
  135. package/.versions/1.0.4/.pi/skills/bowser/SKILL.md +145 -0
  136. package/.versions/1.0.4/.version +1 -0
  137. package/.versions/1.0.4/agents/architect.md +25 -0
  138. package/.versions/1.0.4/agents/bowser.md +28 -0
  139. package/.versions/1.0.4/agents/builder.md +56 -0
  140. package/.versions/1.0.4/agents/code-reviewer.md +209 -0
  141. package/.versions/1.0.4/agents/deep-researcher.md +33 -0
  142. package/.versions/1.0.4/agents/documenter.md +19 -0
  143. package/.versions/1.0.4/agents/orchestrator.md +21 -0
  144. package/.versions/1.0.4/agents/plan-reviewer.md +84 -0
  145. package/.versions/1.0.4/agents/planner.md +71 -0
  146. package/.versions/1.0.4/agents/releaser.md +25 -0
  147. package/.versions/1.0.4/agents/researcher.md +29 -0
  148. package/.versions/1.0.4/agents/security-auditor.md +168 -0
  149. package/.versions/1.0.4/agents/test-engineer.md +154 -0
  150. package/.versions/1.0.4/agents/web-debugger.md +44 -0
  151. package/.versions/1.0.4/agents/web-performance-auditor.md +194 -0
  152. package/.versions/1.0.4/bin/catalog/harness-runtime-closure.json +38 -0
  153. package/.versions/1.0.4/codex/CONDUCTOR.md +148 -0
  154. package/.versions/1.0.4/docs/ARCHITECTURE.md +375 -0
  155. package/.versions/1.0.4/docs/agent-fleet-setup.md +468 -0
  156. package/.versions/1.0.4/docs/claude-code-coms-bridge.md +128 -0
  157. package/.versions/1.0.4/docs/codex-remote-conductor.md +170 -0
  158. package/.versions/1.0.4/docs/coms-hermes-bridge.md +189 -0
  159. package/.versions/1.0.4/docs/getting-started.md +98 -0
  160. package/.versions/1.0.4/docs/npm-install.md +292 -0
  161. package/.versions/1.0.4/docs/pi-extensions.md +441 -0
  162. package/.versions/1.0.4/docs/pi-setup.md +74 -0
  163. package/.versions/1.0.4/docs/skill-anatomy.md +150 -0
  164. package/.versions/1.0.4/hermes/README.md +347 -0
  165. package/.versions/1.0.4/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  166. package/.versions/1.0.4/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  167. package/.versions/1.0.4/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  168. package/.versions/1.0.4/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  169. package/.versions/1.0.4/hermes/gates/gate-o-capability.md +8 -0
  170. package/.versions/1.0.4/hermes/gates/gate-o-validator-fixtures.json +1 -0
  171. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
  172. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  173. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  174. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  175. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  176. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  177. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  178. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  179. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  180. package/.versions/1.0.4/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  181. package/.versions/1.0.4/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  182. package/.versions/1.0.4/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  183. package/.versions/1.0.4/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  184. package/.versions/1.0.4/hermes/skills/hub-conductor/SKILL.md +84 -0
  185. package/.versions/1.0.4/hermes/skills/hub-liaison/SKILL.md +84 -0
  186. package/.versions/1.0.4/hermes/skills/hub-watchdog/SKILL.md +76 -0
  187. package/.versions/1.0.4/hermes/skills/hub-watchdog/manifest.json +1 -0
  188. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  189. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  190. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  191. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  192. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  193. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  194. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  195. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  196. package/.versions/1.0.4/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  197. package/.versions/1.0.4/hermes/watchdog-tests/__init__.py +0 -0
  198. package/.versions/1.0.4/hooks/coms-stop-hook.mjs +84 -0
  199. package/.versions/1.0.4/install-manifest.json +2745 -0
  200. package/.versions/1.0.4/justfile +272 -0
  201. package/.versions/1.0.4/manifest-meta.json +882 -0
  202. package/.versions/1.0.4/references/accessibility-checklist.md +160 -0
  203. package/.versions/1.0.4/references/definition-of-done.md +67 -0
  204. package/.versions/1.0.4/references/fleet-coordination-patterns.md +151 -0
  205. package/.versions/1.0.4/references/observability-checklist.md +91 -0
  206. package/.versions/1.0.4/references/orchestration-patterns.md +370 -0
  207. package/.versions/1.0.4/references/performance-checklist.md +153 -0
  208. package/.versions/1.0.4/references/prompting-patterns.md +380 -0
  209. package/.versions/1.0.4/references/security-checklist.md +179 -0
  210. package/.versions/1.0.4/references/testing-patterns.md +236 -0
  211. package/.versions/1.0.4/scripts/codex-conductor.ts +41 -0
  212. package/.versions/1.0.4/scripts/codex-remote-control.ts +167 -0
  213. package/.versions/1.0.4/scripts/coms-claude-bridge.ts +411 -0
  214. package/.versions/1.0.4/scripts/coms-cli.ts +484 -0
  215. package/.versions/1.0.4/scripts/coms-hermes-bridge.ts +413 -0
  216. package/.versions/1.0.4/scripts/fleet.ts +185 -0
  217. package/.versions/1.0.4/scripts/hermes-monitor-capability-runner.ts +25 -0
  218. package/.versions/1.0.4/scripts/hermes-monitor-scenario.ts +474 -0
  219. package/.versions/1.0.4/scripts/hermes-watchdog-capability-probe.ts +45 -0
  220. package/.versions/1.0.4/scripts/install-hermes-plugin.sh +180 -0
  221. package/.versions/1.0.4/scripts/lib/claude-bridge-core.ts +210 -0
  222. package/.versions/1.0.4/scripts/lib/codex-conductor.ts +88 -0
  223. package/.versions/1.0.4/scripts/lib/codex-remote-control.ts +480 -0
  224. package/.versions/1.0.4/scripts/lib/coms-envelope.ts +582 -0
  225. package/.versions/1.0.4/scripts/lib/fake-herdr-server.ts +88 -0
  226. package/.versions/1.0.4/scripts/lib/fleet-command.ts +266 -0
  227. package/.versions/1.0.4/scripts/lib/herdr-layout.ts +281 -0
  228. package/.versions/1.0.4/scripts/lib/hermes-bridge-core.ts +241 -0
  229. package/.versions/1.0.4/scripts/lib/hermes-monitor-events.ts +1 -0
  230. package/.versions/1.0.4/scripts/lib/hermes-monitor-herdr.ts +2 -0
  231. package/.versions/1.0.4/scripts/lib/hermes-monitor-model.ts +3 -0
  232. package/.versions/1.0.4/scripts/lib/hermes-monitor-registry.ts +2 -0
  233. package/.versions/1.0.4/scripts/lib/hermes-monitor-socket.ts +2 -0
  234. package/.versions/1.0.4/scripts/lib/hermes-monitor-store.ts +2 -0
  235. package/.versions/1.0.4/scripts/lib/monitor-env.ts +146 -0
  236. package/.versions/1.0.4/scripts/lib/peer-launch.ts +318 -0
  237. package/.versions/1.0.4/scripts/lib/persona-banner.ts +62 -0
  238. package/.versions/1.0.4/scripts/lib/spawn-stagger.ts +101 -0
  239. package/.versions/1.0.4/scripts/lib/team-project.ts +213 -0
  240. package/.versions/1.0.4/scripts/lib/team-snapshot.ts +147 -0
  241. package/.versions/1.0.4/scripts/peer-banner.ts +40 -0
  242. package/.versions/1.0.4/scripts/peer-launch.ts +259 -0
  243. package/.versions/1.0.4/scripts/team-snapshot.ts +237 -0
  244. package/.versions/1.0.4/scripts/team-up.ts +406 -0
  245. package/.versions/1.0.4/skills/_internal/grilling.md +59 -0
  246. package/.versions/1.0.4/skills/browser-testing-with-devtools/SKILL.md +351 -0
  247. package/.versions/1.0.4/skills/code-review-and-quality/SKILL.md +381 -0
  248. package/.versions/1.0.4/skills/compound-learning/SKILL.md +137 -0
  249. package/.versions/1.0.4/skills/context-engineering/SKILL.md +291 -0
  250. package/.versions/1.0.4/skills/deprecation-and-migration/SKILL.md +206 -0
  251. package/.versions/1.0.4/skills/designing-agents/SKILL.md +394 -0
  252. package/.versions/1.0.4/skills/designing-agents/pi-harness-authoring.md +222 -0
  253. package/.versions/1.0.4/skills/frontend-ui-engineering/SKILL.md +328 -0
  254. package/.versions/1.0.4/skills/git-workflow-and-versioning/SKILL.md +316 -0
  255. package/.versions/1.0.4/skills/idea-refine/SKILL.md +182 -0
  256. package/.versions/1.0.4/skills/idea-refine/examples.md +238 -0
  257. package/.versions/1.0.4/skills/idea-refine/frameworks.md +99 -0
  258. package/.versions/1.0.4/skills/idea-refine/refinement-criteria.md +113 -0
  259. package/.versions/1.0.4/skills/idea-refine/scripts/idea-refine.sh +15 -0
  260. package/.versions/1.0.4/skills/incremental-implementation/SKILL.md +298 -0
  261. package/.versions/1.0.4/skills/interview-me/SKILL.md +226 -0
  262. package/.versions/1.0.4/skills/orchestration-verification/SKILL.md +181 -0
  263. package/.versions/1.0.4/skills/peer-coms/SKILL.md +90 -0
  264. package/.versions/1.0.4/skills/performance-optimization/SKILL.md +350 -0
  265. package/.versions/1.0.4/skills/planning-and-task-breakdown/SKILL.md +263 -0
  266. package/.versions/1.0.4/skills/security-and-hardening/SKILL.md +461 -0
  267. package/.versions/1.0.4/skills/spec-driven-development/SKILL.md +256 -0
  268. package/.versions/1.0.4/skills/using-agent-skills/SKILL.md +197 -0
  269. package/.versions/1.0.4/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
  270. package/.versions/1.0.4/vendor/agent-skills-upstream/LICENSE +21 -0
  271. package/.versions/1.0.4/vendor/agent-skills-upstream/README.md +11 -0
  272. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
  273. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  274. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  275. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  276. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  277. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
  278. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  279. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  280. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
  281. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  282. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  283. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  284. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  285. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  286. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  287. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  288. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  289. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  290. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  291. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
  292. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
  293. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
  294. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
  295. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
  296. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
  297. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
  298. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
  299. package/.versions/1.0.4/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
  300. package/CHANGELOG.md +7 -0
  301. package/agents/builder.md +1 -0
  302. package/agents/planner.md +1 -1
  303. package/install-manifest.json +3 -3
  304. package/package.json +2 -2
  305. package/skills/_internal/grilling.md +53 -5
  306. package/skills/idea-refine/SKILL.md +2 -2
  307. package/skills/incremental-implementation/SKILL.md +12 -1
  308. package/skills/planning-and-task-breakdown/SKILL.md +14 -5
  309. package/skills/spec-driven-development/SKILL.md +10 -11
  310. package/skills/using-agent-skills/SKILL.md +13 -15
@@ -0,0 +1,103 @@
1
+ import { execFileSync } from "node:child_process";
2
+
3
+ export function snapshotWorktree(cwd) {
4
+ const status = gitStatus(cwd);
5
+ if (status.skipped) return { skipped: true, reason: status.reason, paths: new Set() };
6
+ return { skipped: false, paths: new Set(status.paths) };
7
+ }
8
+
9
+ export function diffAgainst(snapshot, cwd) {
10
+ const current = snapshotWorktree(cwd);
11
+ if (snapshot?.skipped || current.skipped) {
12
+ return { skipped: true, reason: snapshot?.reason || current.reason || "scope gate skipped", paths: [] };
13
+ }
14
+ const before = snapshot?.paths instanceof Set ? snapshot.paths : new Set(snapshot?.paths || []);
15
+ const paths = [...current.paths].filter((p) => !before.has(p)).sort();
16
+ return { skipped: false, paths };
17
+ }
18
+
19
+ export function checkScope(changedPaths, scopeGlobs) {
20
+ const scopes = (scopeGlobs || []).map(normalizePath).filter(Boolean);
21
+ const inScope = [];
22
+ const outOfScope = [];
23
+ for (const rawPath of changedPaths || []) {
24
+ const changed = normalizePath(rawPath);
25
+ if (!changed) continue;
26
+ if (scopes.some((scope) => matchesScope(changed, scope))) inScope.push(changed);
27
+ else outOfScope.push(changed);
28
+ }
29
+ return { inScope: uniqueSorted(inScope), outOfScope: uniqueSorted(outOfScope) };
30
+ }
31
+
32
+ function gitStatus(cwd) {
33
+ try {
34
+ const output = execFileSync("git", ["-C", cwd, "status", "--porcelain", "--untracked-files=all"], {
35
+ encoding: "utf-8",
36
+ stdio: ["ignore", "pipe", "pipe"],
37
+ });
38
+ return { skipped: false, paths: parsePorcelain(output) };
39
+ } catch (err) {
40
+ return { skipped: true, reason: err?.message || "not a git worktree" };
41
+ }
42
+ }
43
+
44
+ function parsePorcelain(output) {
45
+ const paths = [];
46
+ for (const line of String(output || "").split(/\r?\n/)) {
47
+ if (!line.trim()) continue;
48
+ let file = line.slice(3).trim();
49
+ const rename = file.match(/ -> (.+)$/);
50
+ if (rename) file = rename[1];
51
+ paths.push(normalizePath(unquotePorcelainPath(file)));
52
+ }
53
+ return uniqueSorted(paths.filter(Boolean));
54
+ }
55
+
56
+ function matchesScope(changedPath, scope) {
57
+ if (hasGlob(scope)) return globToRegExp(scope).test(changedPath);
58
+ const dir = scope.endsWith("/") ? scope.slice(0, -1) : scope;
59
+ return changedPath === dir || changedPath.startsWith(`${dir}/`);
60
+ }
61
+
62
+ function hasGlob(scope) {
63
+ return /[*?]/.test(scope);
64
+ }
65
+
66
+ function globToRegExp(glob) {
67
+ let out = "^";
68
+ for (let i = 0; i < glob.length; i++) {
69
+ const c = glob[i];
70
+ if (c === "*") {
71
+ if (glob[i + 1] === "*") {
72
+ out += ".*";
73
+ i++;
74
+ } else {
75
+ out += "[^/]*";
76
+ }
77
+ } else {
78
+ out += escapeRegExp(c);
79
+ }
80
+ }
81
+ out += "$";
82
+ return new RegExp(out);
83
+ }
84
+
85
+ function normalizePath(value) {
86
+ return String(value || "").trim().replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+/g, "/");
87
+ }
88
+
89
+ function uniqueSorted(values) {
90
+ return [...new Set(values)].sort();
91
+ }
92
+
93
+ function unquotePorcelainPath(value) {
94
+ const trimmed = String(value || "").trim();
95
+ if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
96
+ try { return JSON.parse(trimmed); } catch { return trimmed.slice(1, -1); }
97
+ }
98
+ return trimmed;
99
+ }
100
+
101
+ function escapeRegExp(value) {
102
+ return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
103
+ }
@@ -0,0 +1,110 @@
1
+ // Session-file health — the pure policy behind never handing pi a session file
2
+ // it will refuse. `spawnPiAgent` passes `--session <file>` on every run, so one
3
+ // corrupt `<agentKey>.json` bricks a persona for the rest of the session: every
4
+ // dispatch dies in ~1s with an empty result, and drop + re-add does not help
5
+ // because the file survives the roster change.
6
+ //
7
+ // A pi session file is JSONL whose FIRST record is the header
8
+ // `{"type":"session","version":N,...}`. Both files that pi rejected in the
9
+ // field (`builder.json.corrupt-*`, `builder.json.invalid-gate-p`) start with a
10
+ // `{"type":"message",...}` record instead — they were truncated at the head, so
11
+ // the conversation begins mid-chain. That single check separates them from the
12
+ // session files that were healthy but retired for other reasons.
13
+
14
+ export const SESSION_HEADER_TYPE = "session";
15
+
16
+ /**
17
+ * Would pi accept this session file body? Returns `{ ok, reason }`; `reason` is
18
+ * null when ok, and a human-readable cause otherwise (it reaches the dispatcher
19
+ * verbatim, so it must explain what happened, not just that something did).
20
+ */
21
+ export function isUsablePiSession(text) {
22
+ const body = String(text ?? "");
23
+ if (!body.trim()) return { ok: false, reason: "session file is empty" };
24
+
25
+ const firstLine = body.split(/\r?\n/).find((line) => line.trim());
26
+ let header;
27
+ try {
28
+ header = JSON.parse(firstLine);
29
+ } catch {
30
+ return { ok: false, reason: "first record is not valid JSON — the file is truncated or not a pi session" };
31
+ }
32
+ if (!header || typeof header !== "object" || Array.isArray(header)) {
33
+ return { ok: false, reason: "first record is not a JSON object" };
34
+ }
35
+ if (header.type !== SESSION_HEADER_TYPE) {
36
+ return {
37
+ ok: false,
38
+ reason: `first record is "${header.type ?? "(no type)"}", not a "${SESSION_HEADER_TYPE}" header — ` +
39
+ "the file was truncated at the head and the conversation starts mid-chain",
40
+ };
41
+ }
42
+ return { ok: true, reason: null };
43
+ }
44
+
45
+ /** `builder.json` → `builder.json.corrupt-2026-07-25T09-14-02-123Z` (no colons: portable filename). */
46
+ export function quarantineName(file, now = new Date()) {
47
+ const stamp = new Date(now).toISOString().replace(/[:.]/g, "-");
48
+ return `${file}.corrupt-${stamp}`;
49
+ }
50
+
51
+ /**
52
+ * The observed post-hoc signature of a session file pi rejects: it exits
53
+ * non-zero having produced no output at all, and says so on stderr. Validation
54
+ * cannot catch every reason pi refuses a file, so this is the second net — and
55
+ * the run never started, which is what makes a retry safe.
56
+ */
57
+ export function isCorruptSessionExit({ code, output, stderr } = {}) {
58
+ if (code === 0 || code == null) return false;
59
+ if (String(output ?? "").trim()) return false;
60
+ return /not a valid pi session|invalid pi session/i.test(String(stderr ?? ""));
61
+ }
62
+
63
+ /**
64
+ * Unconditionally quarantine a file that pi itself rejected. This is distinct
65
+ * from `quarantineIfUnusable`: the local header check may consider the file
66
+ * healthy even though pi applies a stricter invariant. A clean retry is allowed
67
+ * only after the rejected path has actually been moved aside.
68
+ */
69
+ export function forceQuarantineSession(file, io) {
70
+ if (!io.existsSync(file)) return { ok: true, quarantined: null, error: null };
71
+ const target = quarantineName(file, io.now ? io.now() : new Date());
72
+ try {
73
+ io.renameSync(file, target);
74
+ return { ok: true, quarantined: target, error: null };
75
+ } catch (err) {
76
+ return {
77
+ ok: false,
78
+ quarantined: null,
79
+ error: `could not quarantine pi-rejected session: ${err instanceof Error ? err.message : String(err)}`,
80
+ };
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Check `file` and move it aside when pi would reject it. `io` supplies the fs
86
+ * calls (`existsSync`, `readFileSync`, `renameSync`) and an optional `now`.
87
+ * Returns `{ usable, quarantined, reason }` — `quarantined` is the path the bad
88
+ * file was moved to, so the caller can name it for the human.
89
+ */
90
+ export function quarantineIfUnusable(file, io) {
91
+ if (!io.existsSync(file)) return { usable: false, quarantined: null, reason: null };
92
+
93
+ let verdict;
94
+ try {
95
+ verdict = isUsablePiSession(io.readFileSync(file, "utf-8"));
96
+ } catch (err) {
97
+ verdict = { ok: false, reason: `session file unreadable: ${err instanceof Error ? err.message : String(err)}` };
98
+ }
99
+ if (verdict.ok) return { usable: true, quarantined: null, reason: null };
100
+
101
+ const target = quarantineName(file, io.now ? io.now() : new Date());
102
+ try {
103
+ io.renameSync(file, target);
104
+ return { usable: false, quarantined: target, reason: verdict.reason };
105
+ } catch {
106
+ // Could not move it aside — still refuse to resume it. Starting clean
107
+ // overwrites the bad file, which is the outcome we want anyway.
108
+ return { usable: false, quarantined: null, reason: verdict.reason };
109
+ }
110
+ }
@@ -0,0 +1,388 @@
1
+ /**
2
+ * spawnPiAgent — the ONE place agent-hub code spawns a headless `pi` child and
3
+ * parses its JSON event stream. Research helpers and read-only delegate children
4
+ * opt into the per-tool watchdog here, rather than trusting an agent-side timer.
5
+ */
6
+
7
+ import { spawn, type ChildProcess } from "child_process";
8
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
9
+
10
+ export interface PiUsage {
11
+ input?: number;
12
+ output?: number;
13
+ [k: string]: any;
14
+ }
15
+
16
+ export interface ToolTimeout {
17
+ toolCallId: string;
18
+ toolName: string;
19
+ args: string;
20
+ startedAt: number;
21
+ deadlineAt: number;
22
+ }
23
+
24
+ export interface Termination {
25
+ reason: "tool_timeout" | "turn_timeout" | "drift_stop" | "cancelled";
26
+ confirmed: boolean;
27
+ escalated: boolean;
28
+ tool?: ToolTimeout;
29
+ }
30
+
31
+ /** External run control handed to the caller via onControl (drift watchdog). */
32
+ export interface PiRunControl {
33
+ /** Terminate the child group with the given classification (default "drift_stop"). */
34
+ terminate(reason?: "drift_stop" | "cancelled"): void;
35
+ }
36
+
37
+ export interface ToolWatchdogOptions {
38
+ /** Per read-only tool call deadline. null disables the watchdog. */
39
+ timeoutMs: number | null;
40
+ /** Grace after SIGTERM, followed by SIGKILL. Kept injectable for focused tests. */
41
+ termGraceMs?: number;
42
+ /** Bound on final settlement; never wait forever for close or inherited pipes. */
43
+ settleGraceMs?: number;
44
+ /** Only these tool names are watched (research/delegate read-only surface). */
45
+ tools?: readonly string[];
46
+ }
47
+
48
+ export interface SpawnPiAgentOptions {
49
+ model: string;
50
+ tools: string;
51
+ thinking: string;
52
+ /** Replacement prompt; mutually exclusive with appendSystemPrompt when spawning. */
53
+ systemPrompt?: string;
54
+ /** Prompt appended to Pi's inherited prompt (legacy/default child policy). */
55
+ appendSystemPrompt?: string;
56
+ /** Disable automatic global skill discovery for a minimized child. */
57
+ noSkills?: boolean;
58
+ /** Disable AGENTS.md/CLAUDE.md and other automatic context-file discovery. */
59
+ noContextFiles?: boolean;
60
+ sessionFile: string;
61
+ resume?: boolean;
62
+ prompt: string;
63
+ extensions?: string[];
64
+ env?: Record<string, string>;
65
+ /** Own a process group. Required for a watchdog/cancellation kill cascade. */
66
+ detached?: boolean;
67
+ cwd?: string;
68
+ /** Parent tool cancellation; classified separately from a tool timeout. */
69
+ signal?: AbortSignal;
70
+ toolWatchdog?: ToolWatchdogOptions;
71
+ /**
72
+ * Whole-run deadline: one timer from spawn start; on expiry the child group is
73
+ * terminated with reason "turn_timeout" (same SIGTERM→SIGKILL→settle cascade as
74
+ * the per-tool watchdog). null/undefined disables it. Unlike the tool watchdog
75
+ * this bounds the ENTIRE run, thinking and non-watched tools included.
76
+ */
77
+ turnDeadlineMs?: number | null;
78
+ }
79
+
80
+ export interface ModelFallbackNotice {
81
+ from: string;
82
+ to: string;
83
+ reason: string;
84
+ }
85
+
86
+ export interface SpawnPiAgentCallbacks {
87
+ onProcess?(proc: ChildProcess): void;
88
+ onModelFallback?(notice: ModelFallbackNotice): void;
89
+ /** Receives a terminate handle for parent-side classified stops (drift watchdog). */
90
+ onControl?(control: PiRunControl): void;
91
+ onTextDelta?(delta: string): void;
92
+ onThinkingDelta?(delta: string): void;
93
+ onToolStart?(toolName: string, argStr: string, toolCallId?: string): void;
94
+ /** Result text is the complete textual tool payload; duration is measured in the parent process. */
95
+ onToolEnd?(toolName: string, toolCallId?: string, isError?: boolean, resultText?: string, durationMs?: number): void;
96
+ onUsage?(usage: PiUsage, source: "message_end" | "agent_end"): void;
97
+ }
98
+
99
+ export interface SpawnPiAgentResult {
100
+ output: string;
101
+ exitCode: number | null;
102
+ stderr: string;
103
+ spawnError?: string;
104
+ /** Assistant-level provider/model failure reported in Pi's JSON stream. */
105
+ assistantError?: string;
106
+ toolCallsStarted: number;
107
+ modelUsed: string;
108
+ modelFallback?: ModelFallbackNotice;
109
+ /** Present only when parent-side bounded termination was requested. */
110
+ termination?: Termination;
111
+ }
112
+
113
+ const DEFAULT_TERM_GRACE_MS = 1_000;
114
+ const DEFAULT_SETTLE_GRACE_MS = 1_000;
115
+ const WATCHED_TOOLS = new Set(["read", "grep", "find", "ls"]);
116
+
117
+ /** Signal an explicitly owned process group, falling back only for legacy callers. */
118
+ export function killPiTree(proc: ChildProcess, signal: NodeJS.Signals = "SIGTERM"): void {
119
+ const pid = proc.pid;
120
+ if (pid == null) return;
121
+ try {
122
+ process.kill(-pid, signal);
123
+ } catch {
124
+ try { proc.kill(signal); } catch {}
125
+ }
126
+ }
127
+
128
+ export function spawnPiAgent(
129
+ opts: SpawnPiAgentOptions,
130
+ cbs: SpawnPiAgentCallbacks = {},
131
+ ): Promise<SpawnPiAgentResult> {
132
+ const promptArg = opts.systemPrompt !== undefined
133
+ ? ["--system-prompt", opts.systemPrompt]
134
+ : ["--append-system-prompt", opts.appendSystemPrompt ?? ""];
135
+ const args = [
136
+ "--mode", "json", "-p", "--no-extensions",
137
+ ...(opts.noSkills ? ["--no-skills"] : []),
138
+ ...(opts.noContextFiles ? ["--no-context-files"] : []),
139
+ ...(opts.extensions || []).flatMap(e => ["-e", e]),
140
+ "--model", opts.model, "--tools", opts.tools, "--thinking", opts.thinking,
141
+ ...promptArg, "--session", opts.sessionFile,
142
+ ];
143
+ if (opts.resume) args.push("-c");
144
+
145
+ const watchdog = opts.toolWatchdog;
146
+ const turnDeadlineMs = opts.turnDeadlineMs ?? null;
147
+ // A watchdog or deadline must own its group: group signalling remains valid even
148
+ // after the pi leader exits while an inherited-stdio descendant is still alive.
149
+ const ownsGroup = opts.detached === true || watchdog !== undefined || opts.signal !== undefined || turnDeadlineMs != null || cbs.onControl !== undefined;
150
+ const watchedTools = new Set(watchdog?.tools ?? WATCHED_TOOLS);
151
+ const timeoutMs = watchdog?.timeoutMs ?? null;
152
+ const termGraceMs = watchdog?.termGraceMs ?? DEFAULT_TERM_GRACE_MS;
153
+ const settleGraceMs = watchdog?.settleGraceMs ?? DEFAULT_SETTLE_GRACE_MS;
154
+
155
+ const textChunks: string[] = [];
156
+ const stderrChunks: string[] = [];
157
+ return new Promise((resolve) => {
158
+ const proc = spawn("pi", args, {
159
+ stdio: ["pipe", "pipe", "pipe"],
160
+ env: { ...process.env, ...(opts.env || {}) },
161
+ ...(opts.cwd ? { cwd: opts.cwd } : {}),
162
+ ...(ownsGroup ? { detached: true } : {}),
163
+ });
164
+ cbs.onProcess?.(proc);
165
+ proc.stdin?.on("error", () => {});
166
+ proc.stdin?.end(opts.prompt);
167
+
168
+ let buffer = "";
169
+ let settled = false;
170
+ let closeSeen = false;
171
+ let termination: Termination | undefined;
172
+ let termTimer: ReturnType<typeof setTimeout> | undefined;
173
+ let settleTimer: ReturnType<typeof setTimeout> | undefined;
174
+ let deadlineTimer: ReturnType<typeof setTimeout> | undefined;
175
+ const calls = new Map<string, ToolTimeout & { timer: ReturnType<typeof setTimeout> }>();
176
+
177
+ const clearCalls = () => {
178
+ for (const call of calls.values()) clearTimeout(call.timer);
179
+ calls.clear();
180
+ };
181
+ const cleanup = () => {
182
+ clearCalls();
183
+ if (termTimer) clearTimeout(termTimer);
184
+ if (settleTimer) clearTimeout(settleTimer);
185
+ if (deadlineTimer) clearTimeout(deadlineTimer);
186
+ opts.signal?.removeEventListener("abort", onAbort);
187
+ };
188
+ let assistantError: string | undefined;
189
+ let toolCallsStarted = 0;
190
+ const settle = (code: number | null, spawnError?: string) => {
191
+ if (settled) return;
192
+ settled = true;
193
+ cleanup();
194
+ if (termination) termination.confirmed = closeSeen;
195
+ // A pipe held by a descendant must not hold the caller forever.
196
+ try { proc.stdin?.destroy(); } catch {}
197
+ try { proc.stdout?.destroy(); } catch {}
198
+ try { proc.stderr?.destroy(); } catch {}
199
+ resolve({
200
+ output: textChunks.join(""),
201
+ // Pi's headless process can exit 0 while the assistant message itself
202
+ // reports stopReason:error. Normalize that to a failed run so callers
203
+ // never mark a provider/model error as successful.
204
+ exitCode: assistantError && code === 0 ? 1 : code,
205
+ stderr: stderrChunks.join(""),
206
+ toolCallsStarted,
207
+ modelUsed: opts.model,
208
+ ...(spawnError ? { spawnError } : {}),
209
+ ...(assistantError ? { assistantError } : {}),
210
+ ...(termination ? { termination } : {}),
211
+ });
212
+ };
213
+ const terminate = (reason: Termination["reason"], tool?: ToolTimeout) => {
214
+ // The first classification wins; later cancellation/exit events keep it.
215
+ if (termination) return;
216
+ termination = { reason, confirmed: false, escalated: false, ...(tool ? { tool } : {}) };
217
+ clearCalls();
218
+ killPiTree(proc, "SIGTERM");
219
+ termTimer = setTimeout(() => {
220
+ if (settled) return;
221
+ termination!.escalated = true;
222
+ killPiTree(proc, "SIGKILL");
223
+ }, termGraceMs);
224
+ settleTimer = setTimeout(() => settle(null), termGraceMs + settleGraceMs);
225
+ };
226
+ const onAbort = () => terminate("cancelled");
227
+ if (opts.signal?.aborted) onAbort();
228
+ else opts.signal?.addEventListener("abort", onAbort, { once: true });
229
+ // External classified stop (drift watchdog): same first-classification-wins
230
+ // cascade as every other termination path; harmless after settle.
231
+ cbs.onControl?.({ terminate: (reason = "drift_stop") => { if (!settled) terminate(reason); } });
232
+ if (turnDeadlineMs != null) {
233
+ deadlineTimer = setTimeout(() => terminate("turn_timeout"), turnDeadlineMs);
234
+ }
235
+
236
+ const toolStarts = new Map<string, number>();
237
+ const toolId = (event: any) => String(event.toolCallId ?? event.tool_call_id ?? event.id ?? "");
238
+ const toolResultText = (result: any): string => {
239
+ const content = result?.content ?? result;
240
+ if (typeof content === "string") return content;
241
+ if (!Array.isArray(content)) {
242
+ try { return content == null ? "" : JSON.stringify(content); } catch { return String(content ?? ""); }
243
+ }
244
+ return content.map((item: any) => {
245
+ if (typeof item === "string") return item;
246
+ if (item?.type === "text" && typeof item.text === "string") return item.text;
247
+ try { return JSON.stringify(item); } catch { return String(item ?? ""); }
248
+ }).filter(Boolean).join("\n");
249
+ };
250
+ const handleEvent = (event: any) => {
251
+ if (event.type === "message_update") {
252
+ const delta = event.assistantMessageEvent;
253
+ if (delta?.type === "text_delta") { textChunks.push(delta.delta || ""); cbs.onTextDelta?.(delta.delta || ""); }
254
+ else if (delta?.type === "thinking_delta") cbs.onThinkingDelta?.(delta.delta || "");
255
+ } else if (event.type === "tool_execution_start") {
256
+ toolCallsStarted++;
257
+ let argStr = "";
258
+ try { argStr = event.args != null ? JSON.stringify(event.args) : ""; } catch {}
259
+ const id = toolId(event);
260
+ const name = event.toolName || "tool";
261
+ if (id && !toolStarts.has(id)) toolStarts.set(id, Date.now());
262
+ cbs.onToolStart?.(name, argStr, id || undefined);
263
+ if (timeoutMs != null && id && watchedTools.has(name) && !calls.has(id)) {
264
+ const startedAt = Date.now();
265
+ const call: ToolTimeout = { toolCallId: id, toolName: name, args: argStr, startedAt, deadlineAt: startedAt + timeoutMs };
266
+ calls.set(id, { ...call, timer: setTimeout(() => terminate("tool_timeout", call), timeoutMs) });
267
+ }
268
+ } else if (event.type === "tool_execution_end") {
269
+ const id = toolId(event);
270
+ if (id) {
271
+ const call = calls.get(id);
272
+ if (call) { clearTimeout(call.timer); calls.delete(id); }
273
+ }
274
+ const rawIsError = event.isError ?? event.is_error ?? event.result?.isError ?? event.result?.is_error;
275
+ const startedAt = id ? toolStarts.get(id) : undefined;
276
+ if (id) toolStarts.delete(id);
277
+ cbs.onToolEnd?.(
278
+ event.toolName || "tool",
279
+ id || undefined,
280
+ typeof rawIsError === "boolean" ? rawIsError : undefined,
281
+ toolResultText(event.result),
282
+ startedAt == null ? undefined : Math.max(0, Date.now() - startedAt),
283
+ );
284
+ } else if (event.type === "message_end") {
285
+ if (event.message?.role === "assistant"
286
+ && (event.message.stopReason === "error" || event.message.stopReason === "aborted")) {
287
+ assistantError = String(event.message.errorMessage
288
+ || (event.message.stopReason === "aborted" ? "assistant model request aborted" : "assistant model run failed"));
289
+ }
290
+ if (event.message?.usage) cbs.onUsage?.(event.message.usage, "message_end");
291
+ } else if (event.type === "agent_end") {
292
+ const last = [...(event.messages || [])].reverse().find((m: any) => m.role === "assistant");
293
+ if (last?.usage) cbs.onUsage?.(last.usage, "agent_end");
294
+ }
295
+ };
296
+
297
+ proc.stdout!.setEncoding("utf-8");
298
+ proc.stdout!.on("data", (chunk: string) => {
299
+ buffer += chunk;
300
+ const lines = buffer.split("\n");
301
+ buffer = lines.pop() || "";
302
+ for (const line of lines) { if (line.trim()) try { handleEvent(JSON.parse(line)); } catch {} }
303
+ });
304
+ proc.stderr!.setEncoding("utf-8");
305
+ proc.stderr!.on("data", (chunk: string) => stderrChunks.push(chunk));
306
+ proc.on("close", (code) => {
307
+ closeSeen = true;
308
+ if (buffer.trim()) try { handleEvent(JSON.parse(buffer)); } catch {}
309
+ settle(code);
310
+ });
311
+ proc.on("error", (err) => settle(1, err.message));
312
+ });
313
+ }
314
+
315
+ const PROVIDER_FAILURE_RE = /\b(provider unavailable|service unavailable|overloaded|rate limit|too many requests|out of memory|oom|memory limit|resource exhausted|econn(?:reset|refused)|connection (?:reset|refused)|fetch failed|network error|gateway timeout|http\s*5\d\d|\b429\b)\b/i;
316
+
317
+ function modelFallbackReason(result: SpawnPiAgentResult, midRun = false): string | null {
318
+ // A terminated run (watchdog, deadline, cancellation) is a verdict on the
319
+ // work, not a provider outage — never retry it. A spawn failure never
320
+ // reached a provider at all.
321
+ if (result.spawnError || result.termination) return null;
322
+ const workStarted = result.toolCallsStarted > 0 || Boolean(result.output.trim());
323
+ if (!midRun && workStarted) return null;
324
+ const reason = result.assistantError
325
+ ? result.assistantError.slice(-500)
326
+ : result.exitCode !== 0
327
+ ? (result.stderr.trim().slice(-500) || `pi exited with code ${result.exitCode ?? "unknown"}`)
328
+ : null;
329
+ if (!reason) return null;
330
+ // Once work began, only a recognizable provider/transport failure is safe to
331
+ // route to another model. Deterministic session/configuration/harness errors
332
+ // must remain visible instead of being masked by an expensive second run.
333
+ if (midRun && workStarted && !PROVIDER_FAILURE_RE.test(reason)) return null;
334
+ return reason;
335
+ }
336
+
337
+ export interface ModelFallbackOptions {
338
+ /**
339
+ * Retry even when the failed attempt had already started tools or emitted
340
+ * text. Only pass this for a run that holds NO write-capable tools: the
341
+ * retry re-executes whatever the first attempt did, which is harmless for a
342
+ * reader and duplicates edits for a writer. Use `isReadOnlyToolList` on the
343
+ * effective tool list rather than assuming.
344
+ */
345
+ midRun?: boolean;
346
+ }
347
+
348
+ /**
349
+ * Run an overridden model and retry once on the original persona model when the
350
+ * first attempt failed for a provider-level reason. By default that means
351
+ * "failed before producing text or starting a tool"; `midRun` extends it to
352
+ * read-only runs, where a provider dying halfway through would otherwise throw
353
+ * the whole run away — and those are exactly the children that exist to protect
354
+ * their parent's context. The session file is restored before the retry so the
355
+ * failed turn never enters the resumable conversation.
356
+ */
357
+ export async function spawnPiAgentWithModelFallback(
358
+ opts: SpawnPiAgentOptions,
359
+ fallbackModel?: string,
360
+ cbs: SpawnPiAgentCallbacks = {},
361
+ fallbackOptions: ModelFallbackOptions = {},
362
+ ): Promise<SpawnPiAgentResult> {
363
+ if (!fallbackModel || fallbackModel === opts.model) return spawnPiAgent(opts, cbs);
364
+
365
+ const sessionExisted = existsSync(opts.sessionFile);
366
+ let sessionSnapshot: Buffer | undefined;
367
+ if (sessionExisted) {
368
+ try { sessionSnapshot = readFileSync(opts.sessionFile); } catch {}
369
+ }
370
+
371
+ const primary = await spawnPiAgent(opts, cbs);
372
+ const reason = modelFallbackReason(primary, fallbackOptions.midRun === true);
373
+ // If an existing resumable session could not be snapshotted, fail closed:
374
+ // retrying would preserve the failed turn and could duplicate the prompt.
375
+ if (!reason || (sessionExisted && !sessionSnapshot)) return primary;
376
+
377
+ try {
378
+ if (sessionExisted && sessionSnapshot) writeFileSync(opts.sessionFile, sessionSnapshot);
379
+ else unlinkSync(opts.sessionFile);
380
+ } catch (error: any) {
381
+ if (error?.code !== "ENOENT") return primary;
382
+ }
383
+
384
+ const notice: ModelFallbackNotice = { from: opts.model, to: fallbackModel, reason };
385
+ cbs.onModelFallback?.(notice);
386
+ const fallback = await spawnPiAgent({ ...opts, model: fallbackModel }, cbs);
387
+ return { ...fallback, modelFallback: notice };
388
+ }
@@ -0,0 +1,42 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ export const VERSION_STATUS_KEY = "00-agent-fleet-version";
4
+ export const VERSION_LABEL = "agent fleet";
5
+ export const VERSION_LABEL_URL = "https://github.com/chankov/agent-fleet";
6
+
7
+ /**
8
+ * Wrap `text` in an OSC 8 hyperlink. Terminals that support it make the label
9
+ * clickable and hand the URL to the OS opener; terminals that don't ignore the
10
+ * sequence and render `text` unchanged. pi's TUI strips OSC sequences before
11
+ * measuring (`visibleWidth`) and truncating, so a linked label costs no footer
12
+ * columns. Multiplexers that mangle unknown OSC (GNU screen, tmux before 3.4)
13
+ * are the reason for the AGENT_FLEET_NO_LINKS opt-out below.
14
+ */
15
+ export function linkify(text: string, url: string): string {
16
+ return `\x1b]8;;${url}\x07${text}\x1b]8;;\x07`;
17
+ }
18
+
19
+ function linksEnabled(): boolean {
20
+ const optOut = process.env.AGENT_FLEET_NO_LINKS;
21
+ return !optOut || optOut === "0" || optOut === "false";
22
+ }
23
+
24
+ export function formatVersionLabel(version: string): string {
25
+ const label = linksEnabled() ? linkify(VERSION_LABEL, VERSION_LABEL_URL) : VERSION_LABEL;
26
+ return `${label} v${version}`;
27
+ }
28
+
29
+ function readAdjacentVersion(): string | null {
30
+ try {
31
+ const manifest = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
32
+ return typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : null;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ export const HARNESS_VERSION = readAdjacentVersion();
39
+
40
+ export function registerVersionStatus(ctx: { ui?: { setStatus?: (key: string, text: string) => void } }): void {
41
+ if (HARNESS_VERSION) ctx.ui?.setStatus?.(VERSION_STATUS_KEY, formatVersionLabel(HARNESS_VERSION));
42
+ }