@chankov/agent-fleet 0.0.9 → 0.0.10

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 (354) hide show
  1. package/.claude/commands/doctor-agent-fleet.md +12 -7
  2. package/.claude/commands/setup-agent-fleet.md +7 -15
  3. package/.opencode/commands/af-doctor-agent-fleet.md +12 -7
  4. package/.opencode/commands/af-setup-agent-fleet.md +8 -6
  5. package/.pi/extensions/agent-fleet-update-check/README.md +2 -3
  6. package/.pi/extensions/btw/README.md +2 -2
  7. package/.pi/extensions/chrome-devtools-mcp/README.md +3 -6
  8. package/.pi/extensions/compact-and-continue/README.md +3 -3
  9. package/.pi/extensions/mcp-bridge/README.md +1 -1
  10. package/.pi/harnesses/agent-hub/README.md +139 -10
  11. package/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  12. package/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  13. package/.pi/harnesses/agent-hub/index.ts +448 -39
  14. package/.pi/harnesses/agent-hub/package.json +1 -1
  15. package/.pi/harnesses/agent-hub/review-findings.js +102 -0
  16. package/.pi/harnesses/agent-hub/run-budget.js +302 -4
  17. package/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  18. package/.pi/harnesses/coms/package.json +1 -1
  19. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  20. package/.pi/prompts/af-doctor-agent-fleet.md +13 -6
  21. package/.pi/prompts/af-setup-agent-fleet.md +7 -15
  22. package/.versions/0.0.10/.claude/commands/build.md +44 -0
  23. package/.versions/0.0.10/.claude/commands/code-simplify.md +22 -0
  24. package/.versions/0.0.10/.claude/commands/design-agent.md +14 -0
  25. package/.versions/0.0.10/.claude/commands/doctor-agent-fleet.md +22 -0
  26. package/.versions/0.0.10/.claude/commands/orchestrate.md +112 -0
  27. package/.versions/0.0.10/.claude/commands/plan.md +16 -0
  28. package/.versions/0.0.10/.claude/commands/prime.md +22 -0
  29. package/.versions/0.0.10/.claude/commands/review.md +16 -0
  30. package/.versions/0.0.10/.claude/commands/set-hermes-telegram.md +15 -0
  31. package/.versions/0.0.10/.claude/commands/set-hermes-watchdog.md +6 -0
  32. package/.versions/0.0.10/.claude/commands/setup-agent-fleet.md +17 -0
  33. package/.versions/0.0.10/.claude/commands/ship.md +72 -0
  34. package/.versions/0.0.10/.claude/commands/spec.md +15 -0
  35. package/.versions/0.0.10/.claude/commands/test.md +19 -0
  36. package/.versions/0.0.10/.claude/commands/webperf.md +32 -0
  37. package/.versions/0.0.10/.claude/orchestrate-teams.yaml +24 -0
  38. package/.versions/0.0.10/.opencode/commands/af-build.md +17 -0
  39. package/.versions/0.0.10/.opencode/commands/af-code-simplify.md +16 -0
  40. package/.versions/0.0.10/.opencode/commands/af-compound.md +16 -0
  41. package/.versions/0.0.10/.opencode/commands/af-design-agent.md +15 -0
  42. package/.versions/0.0.10/.opencode/commands/af-doctor-agent-fleet.md +22 -0
  43. package/.versions/0.0.10/.opencode/commands/af-orchestrate.md +112 -0
  44. package/.versions/0.0.10/.opencode/commands/af-plan.md +16 -0
  45. package/.versions/0.0.10/.opencode/commands/af-prime.md +22 -0
  46. package/.versions/0.0.10/.opencode/commands/af-review.md +15 -0
  47. package/.versions/0.0.10/.opencode/commands/af-set-hermes-telegram.md +15 -0
  48. package/.versions/0.0.10/.opencode/commands/af-set-hermes-watchdog.md +6 -0
  49. package/.versions/0.0.10/.opencode/commands/af-setup-agent-fleet.md +17 -0
  50. package/.versions/0.0.10/.opencode/commands/af-ship.md +16 -0
  51. package/.versions/0.0.10/.opencode/commands/af-spec.md +16 -0
  52. package/.versions/0.0.10/.opencode/commands/af-test.md +21 -0
  53. package/.versions/0.0.10/.opencode/commands/af-webperf.md +32 -0
  54. package/.versions/0.0.10/.opencode/orchestrate-teams.yaml +24 -0
  55. package/.versions/0.0.10/.pi/agents/dispatch-policy.yaml +32 -0
  56. package/.versions/0.0.10/.pi/agents/model-profiles.yaml +27 -0
  57. package/.versions/0.0.10/.pi/agents/peers.yaml +142 -0
  58. package/.versions/0.0.10/.pi/agents/teams.yaml +41 -0
  59. package/.versions/0.0.10/.pi/damage-control-rules.yaml +297 -0
  60. package/.versions/0.0.10/.pi/extensions/agent-fleet-update-check/README.md +57 -0
  61. package/.versions/0.0.10/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
  62. package/.versions/0.0.10/.pi/extensions/agent-fleet-update-check/package.json +6 -0
  63. package/.versions/0.0.10/.pi/extensions/btw/README.md +118 -0
  64. package/.versions/0.0.10/.pi/extensions/btw/index.ts +917 -0
  65. package/.versions/0.0.10/.pi/extensions/btw/package.json +6 -0
  66. package/.versions/0.0.10/.pi/extensions/btw/state.js +179 -0
  67. package/.versions/0.0.10/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  68. package/.versions/0.0.10/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  69. package/.versions/0.0.10/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  70. package/.versions/0.0.10/.pi/extensions/compact-and-continue/README.md +42 -0
  71. package/.versions/0.0.10/.pi/extensions/compact-and-continue/index.ts +120 -0
  72. package/.versions/0.0.10/.pi/extensions/compact-and-continue/package.json +6 -0
  73. package/.versions/0.0.10/.pi/extensions/mcp-bridge/README.md +46 -0
  74. package/.versions/0.0.10/.pi/extensions/mcp-bridge/index.ts +206 -0
  75. package/.versions/0.0.10/.pi/extensions/mcp-bridge/package.json +6 -0
  76. package/.versions/0.0.10/.pi/extensions/package-lock.json +1143 -0
  77. package/.versions/0.0.10/.pi/extensions/package.json +9 -0
  78. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/README.md +201 -0
  79. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/config.ts +198 -0
  80. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  81. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/index.ts +248 -0
  82. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/package.json +6 -0
  83. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  84. package/.versions/0.0.10/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  85. package/.versions/0.0.10/.pi/harnesses/agent-hub/README.md +1001 -0
  86. package/.versions/0.0.10/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  87. package/.versions/0.0.10/.pi/harnesses/agent-hub/artifacts.js +146 -0
  88. package/.versions/0.0.10/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  89. package/.versions/0.0.10/.pi/harnesses/agent-hub/backend-policy.js +153 -0
  90. package/.versions/0.0.10/.pi/harnesses/agent-hub/context-window.js +106 -0
  91. package/.versions/0.0.10/.pi/harnesses/agent-hub/delegate.ts +435 -0
  92. package/.versions/0.0.10/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  93. package/.versions/0.0.10/.pi/harnesses/agent-hub/drift-watchdog.js +211 -0
  94. package/.versions/0.0.10/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  95. package/.versions/0.0.10/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  96. package/.versions/0.0.10/.pi/harnesses/agent-hub/footer.ts +31 -0
  97. package/.versions/0.0.10/.pi/harnesses/agent-hub/helpers.ts +248 -0
  98. package/.versions/0.0.10/.pi/harnesses/agent-hub/index.ts +9111 -0
  99. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  100. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  101. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  102. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  103. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  104. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  105. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  106. package/.versions/0.0.10/.pi/harnesses/agent-hub/monitor-session-bridge.ts +257 -0
  107. package/.versions/0.0.10/.pi/harnesses/agent-hub/package.json +7 -0
  108. package/.versions/0.0.10/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  109. package/.versions/0.0.10/.pi/harnesses/agent-hub/research-retention.js +34 -0
  110. package/.versions/0.0.10/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  111. package/.versions/0.0.10/.pi/harnesses/agent-hub/return-contract.js +293 -0
  112. package/.versions/0.0.10/.pi/harnesses/agent-hub/return-extract.js +75 -0
  113. package/.versions/0.0.10/.pi/harnesses/agent-hub/review-findings.js +102 -0
  114. package/.versions/0.0.10/.pi/harnesses/agent-hub/run-budget.js +479 -0
  115. package/.versions/0.0.10/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  116. package/.versions/0.0.10/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  117. package/.versions/0.0.10/.pi/harnesses/agent-hub/scope-gate.js +103 -0
  118. package/.versions/0.0.10/.pi/harnesses/agent-hub/session-health.js +110 -0
  119. package/.versions/0.0.10/.pi/harnesses/agent-hub/spawn.ts +354 -0
  120. package/.versions/0.0.10/.pi/harnesses/agent-hub/version.ts +42 -0
  121. package/.versions/0.0.10/.pi/harnesses/ask-user-remote/README.md +19 -0
  122. package/.versions/0.0.10/.pi/harnesses/ask-user-remote/index.ts +321 -0
  123. package/.versions/0.0.10/.pi/harnesses/ask-user-remote/race-core.js +106 -0
  124. package/.versions/0.0.10/.pi/harnesses/coms/README.md +100 -0
  125. package/.versions/0.0.10/.pi/harnesses/coms/index.ts +1767 -0
  126. package/.versions/0.0.10/.pi/harnesses/coms/package.json +7 -0
  127. package/.versions/0.0.10/.pi/harnesses/coms/version.ts +42 -0
  128. package/.versions/0.0.10/.pi/harnesses/damage-control-continue/README.md +124 -0
  129. package/.versions/0.0.10/.pi/harnesses/damage-control-continue/index.ts +536 -0
  130. package/.versions/0.0.10/.pi/harnesses/damage-control-continue/package.json +7 -0
  131. package/.versions/0.0.10/.pi/harnesses/damage-control-continue/version.ts +42 -0
  132. package/.versions/0.0.10/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  133. package/.versions/0.0.10/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  134. package/.versions/0.0.10/.pi/harnesses/lib/herdr-client.ts +472 -0
  135. package/.versions/0.0.10/.pi/harnesses/lib/herdr-presence.ts +399 -0
  136. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  137. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  138. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  139. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  140. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  141. package/.versions/0.0.10/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  142. package/.versions/0.0.10/.pi/harnesses/lib/spawned-peers.js +190 -0
  143. package/.versions/0.0.10/.pi/harnesses/package-lock.json +35 -0
  144. package/.versions/0.0.10/.pi/harnesses/package.json +9 -0
  145. package/.versions/0.0.10/.pi/prompts/af-build.md +24 -0
  146. package/.versions/0.0.10/.pi/prompts/af-code-simplify.md +22 -0
  147. package/.versions/0.0.10/.pi/prompts/af-doctor-agent-fleet.md +22 -0
  148. package/.versions/0.0.10/.pi/prompts/af-plan.md +16 -0
  149. package/.versions/0.0.10/.pi/prompts/af-review.md +16 -0
  150. package/.versions/0.0.10/.pi/prompts/af-set-hermes-telegram.md +15 -0
  151. package/.versions/0.0.10/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  152. package/.versions/0.0.10/.pi/prompts/af-setup-agent-fleet.md +19 -0
  153. package/.versions/0.0.10/.pi/prompts/af-ship.md +17 -0
  154. package/.versions/0.0.10/.pi/prompts/af-spec.md +15 -0
  155. package/.versions/0.0.10/.pi/prompts/af-test.md +19 -0
  156. package/.versions/0.0.10/.pi/skills/bowser/SKILL.md +145 -0
  157. package/.versions/0.0.10/.version +1 -0
  158. package/.versions/0.0.10/agents/architect.md +24 -0
  159. package/.versions/0.0.10/agents/bowser.md +27 -0
  160. package/.versions/0.0.10/agents/builder.md +54 -0
  161. package/.versions/0.0.10/agents/code-reviewer.md +208 -0
  162. package/.versions/0.0.10/agents/deep-researcher.md +32 -0
  163. package/.versions/0.0.10/agents/documenter.md +18 -0
  164. package/.versions/0.0.10/agents/orchestrator.md +72 -0
  165. package/.versions/0.0.10/agents/plan-reviewer.md +83 -0
  166. package/.versions/0.0.10/agents/planner.md +70 -0
  167. package/.versions/0.0.10/agents/releaser.md +24 -0
  168. package/.versions/0.0.10/agents/researcher.md +28 -0
  169. package/.versions/0.0.10/agents/security-auditor.md +167 -0
  170. package/.versions/0.0.10/agents/test-engineer.md +153 -0
  171. package/.versions/0.0.10/agents/web-debugger.md +43 -0
  172. package/.versions/0.0.10/agents/web-performance-auditor.md +193 -0
  173. package/.versions/0.0.10/codex/CONDUCTOR.md +148 -0
  174. package/.versions/0.0.10/docs/ARCHITECTURE.md +303 -0
  175. package/.versions/0.0.10/docs/agent-fleet-setup.md +377 -0
  176. package/.versions/0.0.10/docs/claude-code-coms-bridge.md +109 -0
  177. package/.versions/0.0.10/docs/codex-remote-conductor.md +170 -0
  178. package/.versions/0.0.10/docs/coms-hermes-bridge.md +189 -0
  179. package/.versions/0.0.10/docs/getting-started.md +254 -0
  180. package/.versions/0.0.10/docs/npm-install.md +514 -0
  181. package/.versions/0.0.10/docs/opencode-setup.md +281 -0
  182. package/.versions/0.0.10/docs/pi-extensions.md +363 -0
  183. package/.versions/0.0.10/docs/pi-setup.md +571 -0
  184. package/.versions/0.0.10/docs/skill-anatomy.md +150 -0
  185. package/.versions/0.0.10/hermes/README.md +347 -0
  186. package/.versions/0.0.10/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  187. package/.versions/0.0.10/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  188. package/.versions/0.0.10/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  189. package/.versions/0.0.10/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  190. package/.versions/0.0.10/hermes/gates/gate-o-capability.md +8 -0
  191. package/.versions/0.0.10/hermes/gates/gate-o-validator-fixtures.json +1 -0
  192. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
  193. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  194. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  195. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  196. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  197. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  198. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  199. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  200. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  201. package/.versions/0.0.10/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  202. package/.versions/0.0.10/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  203. package/.versions/0.0.10/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  204. package/.versions/0.0.10/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  205. package/.versions/0.0.10/hermes/skills/hub-conductor/SKILL.md +84 -0
  206. package/.versions/0.0.10/hermes/skills/hub-liaison/SKILL.md +84 -0
  207. package/.versions/0.0.10/hermes/skills/hub-watchdog/SKILL.md +76 -0
  208. package/.versions/0.0.10/hermes/skills/hub-watchdog/manifest.json +1 -0
  209. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  210. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  211. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  212. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  213. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  214. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  215. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  216. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  217. package/.versions/0.0.10/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  218. package/.versions/0.0.10/hermes/watchdog-tests/__init__.py +0 -0
  219. package/.versions/0.0.10/hooks/SIMPLIFY-IGNORE.md +90 -0
  220. package/.versions/0.0.10/hooks/coms-stop-hook.mjs +84 -0
  221. package/.versions/0.0.10/hooks/hooks.json +14 -0
  222. package/.versions/0.0.10/hooks/session-start.sh +74 -0
  223. package/.versions/0.0.10/hooks/simplify-ignore.sh +302 -0
  224. package/.versions/0.0.10/install-manifest.json +3615 -0
  225. package/.versions/0.0.10/justfile +254 -0
  226. package/.versions/0.0.10/manifest-meta.json +472 -0
  227. package/.versions/0.0.10/references/accessibility-checklist.md +160 -0
  228. package/.versions/0.0.10/references/definition-of-done.md +67 -0
  229. package/.versions/0.0.10/references/fleet-coordination-patterns.md +151 -0
  230. package/.versions/0.0.10/references/observability-checklist.md +91 -0
  231. package/.versions/0.0.10/references/orchestration-patterns.md +370 -0
  232. package/.versions/0.0.10/references/performance-checklist.md +153 -0
  233. package/.versions/0.0.10/references/prompting-patterns.md +380 -0
  234. package/.versions/0.0.10/references/security-checklist.md +179 -0
  235. package/.versions/0.0.10/references/testing-patterns.md +236 -0
  236. package/.versions/0.0.10/scripts/codex-conductor.ts +41 -0
  237. package/.versions/0.0.10/scripts/codex-remote-control.ts +167 -0
  238. package/.versions/0.0.10/scripts/coms-claude-bridge.ts +401 -0
  239. package/.versions/0.0.10/scripts/coms-cli.ts +484 -0
  240. package/.versions/0.0.10/scripts/coms-hermes-bridge.ts +413 -0
  241. package/.versions/0.0.10/scripts/fleet.ts +168 -0
  242. package/.versions/0.0.10/scripts/hermes-monitor-capability-runner.ts +25 -0
  243. package/.versions/0.0.10/scripts/hermes-monitor-scenario.ts +474 -0
  244. package/.versions/0.0.10/scripts/hermes-watchdog-capability-probe.ts +45 -0
  245. package/.versions/0.0.10/scripts/install-hermes-plugin.sh +180 -0
  246. package/.versions/0.0.10/scripts/lib/claude-bridge-core.ts +165 -0
  247. package/.versions/0.0.10/scripts/lib/codex-conductor.ts +88 -0
  248. package/.versions/0.0.10/scripts/lib/codex-remote-control.ts +480 -0
  249. package/.versions/0.0.10/scripts/lib/coms-envelope.ts +582 -0
  250. package/.versions/0.0.10/scripts/lib/fake-herdr-server.ts +88 -0
  251. package/.versions/0.0.10/scripts/lib/fleet-command.ts +111 -0
  252. package/.versions/0.0.10/scripts/lib/herdr-layout.ts +281 -0
  253. package/.versions/0.0.10/scripts/lib/hermes-bridge-core.ts +241 -0
  254. package/.versions/0.0.10/scripts/lib/hermes-monitor-events.ts +1 -0
  255. package/.versions/0.0.10/scripts/lib/hermes-monitor-herdr.ts +2 -0
  256. package/.versions/0.0.10/scripts/lib/hermes-monitor-model.ts +3 -0
  257. package/.versions/0.0.10/scripts/lib/hermes-monitor-registry.ts +2 -0
  258. package/.versions/0.0.10/scripts/lib/hermes-monitor-socket.ts +2 -0
  259. package/.versions/0.0.10/scripts/lib/hermes-monitor-store.ts +2 -0
  260. package/.versions/0.0.10/scripts/lib/monitor-env.ts +120 -0
  261. package/.versions/0.0.10/scripts/lib/peer-launch.ts +314 -0
  262. package/.versions/0.0.10/scripts/lib/persona-banner.ts +62 -0
  263. package/.versions/0.0.10/scripts/lib/spawn-stagger.ts +101 -0
  264. package/.versions/0.0.10/scripts/lib/team-project.ts +193 -0
  265. package/.versions/0.0.10/scripts/lib/team-snapshot.ts +147 -0
  266. package/.versions/0.0.10/scripts/peer-banner.ts +40 -0
  267. package/.versions/0.0.10/scripts/peer-launch.ts +259 -0
  268. package/.versions/0.0.10/scripts/team-snapshot.ts +237 -0
  269. package/.versions/0.0.10/scripts/team-up.ts +360 -0
  270. package/.versions/0.0.10/skills/_internal/grilling.md +11 -0
  271. package/.versions/0.0.10/skills/browser-testing-with-devtools/SKILL.md +351 -0
  272. package/.versions/0.0.10/skills/code-review-and-quality/SKILL.md +381 -0
  273. package/.versions/0.0.10/skills/compound-learning/SKILL.md +137 -0
  274. package/.versions/0.0.10/skills/context-engineering/SKILL.md +291 -0
  275. package/.versions/0.0.10/skills/deprecation-and-migration/SKILL.md +206 -0
  276. package/.versions/0.0.10/skills/designing-agents/SKILL.md +394 -0
  277. package/.versions/0.0.10/skills/designing-agents/pi-harness-authoring.md +222 -0
  278. package/.versions/0.0.10/skills/frontend-ui-engineering/SKILL.md +328 -0
  279. package/.versions/0.0.10/skills/git-workflow-and-versioning/SKILL.md +316 -0
  280. package/.versions/0.0.10/skills/guided-workspace-setup/SKILL.md +226 -0
  281. package/.versions/0.0.10/skills/guided-workspace-setup/companion-manifest.json +38 -0
  282. package/.versions/0.0.10/skills/idea-refine/SKILL.md +182 -0
  283. package/.versions/0.0.10/skills/idea-refine/examples.md +238 -0
  284. package/.versions/0.0.10/skills/idea-refine/frameworks.md +99 -0
  285. package/.versions/0.0.10/skills/idea-refine/refinement-criteria.md +113 -0
  286. package/.versions/0.0.10/skills/idea-refine/scripts/idea-refine.sh +15 -0
  287. package/.versions/0.0.10/skills/incremental-implementation/SKILL.md +287 -0
  288. package/.versions/0.0.10/skills/interview-me/SKILL.md +226 -0
  289. package/.versions/0.0.10/skills/orchestration-verification/SKILL.md +181 -0
  290. package/.versions/0.0.10/skills/peer-coms/SKILL.md +90 -0
  291. package/.versions/0.0.10/skills/performance-optimization/SKILL.md +350 -0
  292. package/.versions/0.0.10/skills/planning-and-task-breakdown/SKILL.md +254 -0
  293. package/.versions/0.0.10/skills/security-and-hardening/SKILL.md +461 -0
  294. package/.versions/0.0.10/skills/spec-driven-development/SKILL.md +257 -0
  295. package/.versions/0.0.10/skills/using-agent-skills/SKILL.md +199 -0
  296. package/.versions/0.0.10/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
  297. package/.versions/0.0.10/vendor/agent-skills-upstream/LICENSE +21 -0
  298. package/.versions/0.0.10/vendor/agent-skills-upstream/README.md +11 -0
  299. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
  300. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  301. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  302. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  303. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  304. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
  305. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  306. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  307. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
  308. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  309. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  310. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  311. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  312. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  313. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  314. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  315. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  316. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  317. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  318. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
  319. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
  320. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
  321. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
  322. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
  323. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
  324. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
  325. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
  326. package/.versions/0.0.10/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
  327. package/CHANGELOG.md +103 -0
  328. package/README.md +22 -5
  329. package/agents/code-reviewer.md +4 -0
  330. package/agents/orchestrator.md +7 -1
  331. package/agents/plan-reviewer.md +22 -1
  332. package/bin/build-manifest.js +68 -0
  333. package/bin/cli.js +679 -49
  334. package/bin/lib/apply.js +641 -0
  335. package/bin/lib/manifest.js +731 -0
  336. package/bin/lib/merge-forms.js +106 -0
  337. package/bin/lib/plan.js +569 -0
  338. package/bin/lib/state.js +213 -0
  339. package/bin/lib/verify.js +576 -0
  340. package/bin/snapshot-version.js +5 -0
  341. package/docs/ARCHITECTURE.md +52 -11
  342. package/docs/agent-fleet-setup.md +59 -48
  343. package/docs/getting-started.md +29 -6
  344. package/docs/npm-install.md +208 -31
  345. package/docs/opencode-setup.md +32 -0
  346. package/docs/pi-extensions.md +17 -10
  347. package/docs/pi-setup.md +164 -69
  348. package/install-manifest.json +3615 -0
  349. package/manifest-meta.json +472 -0
  350. package/package.json +8 -3
  351. package/skills/browser-testing-with-devtools/SKILL.md +3 -4
  352. package/skills/guided-workspace-setup/SKILL.md +172 -490
  353. package/skills/planning-and-task-breakdown/SKILL.md +18 -0
  354. package/skills/spec-driven-development/SKILL.md +12 -0
@@ -0,0 +1,641 @@
1
+ // apply.js — execute a plan.
2
+ //
3
+ // The only module in the installer that writes to a target workspace. Every
4
+ // verb reaches the filesystem through here, so the safety rules live in one
5
+ // place instead of being restated in prose per verb:
6
+ //
7
+ // • nothing is written outside the workspace — asserted per path, not assumed;
8
+ // • nothing is deleted that the state file does not record as ours, and
9
+ // nothing the user has since edited is deleted at all;
10
+ // • a conflict writes `<file>.new` beside the file and leaves the original
11
+ // alone — the engine never picks a side;
12
+ // • `exec` items run only when the plan admitted them (--allow-exec), and
13
+ // `external` / `operator` items are never performed.
14
+ //
15
+ // The state file is written even when the pass fails partway: a workspace with
16
+ // files but no record of them is worse than one that admits what it has.
17
+ //
18
+ // See plans/deterministic-installer.md phase 4.
19
+
20
+ import {
21
+ existsSync, mkdirSync, copyFileSync, writeFileSync, readFileSync,
22
+ symlinkSync, rmSync, rmdirSync, lstatSync, unlinkSync,
23
+ } from "node:fs";
24
+ import { spawnSync } from "node:child_process";
25
+ import { dirname, join, resolve } from "node:path";
26
+
27
+ import { itemsForAgent } from "./manifest.js";
28
+ import { expandBinding } from "./verify.js";
29
+ import { extractRegion, replaceRegion, stripRegion, leafPaths, setPath, canonicalJson } from "./merge-forms.js";
30
+ import { transformPersona } from "./transform-persona.js";
31
+ import {
32
+ readState, writeState, emptyState, hashFile, hashText, walkTree,
33
+ inspectPath, isInside, STATE_REL_PATH, LEGACY_RECORD_REL_PATH,
34
+ } from "./state.js";
35
+
36
+ export const APPLY_SCHEMA_VERSION = 1;
37
+
38
+ /**
39
+ * Execute a plan against its workspace.
40
+ *
41
+ * @param {object} opts
42
+ * @param {object} opts.plan a plan from buildPlan()
43
+ * @param {object} opts.manifest the manifest the plan was built from
44
+ * @param {boolean} [opts.allowExec]
45
+ * @param {() => string} [opts.now] injectable clock, for deterministic tests
46
+ * @returns {object} result
47
+ */
48
+ export function applyPlan({ plan, manifest, allowExec = false, now = () => new Date().toISOString() }) {
49
+ const { workspace, sourceRoot, agent, method, packageVersion } = plan;
50
+ const catalogue = new Map(itemsForAgent(manifest, agent).map((i) => [i.id, i]));
51
+ const previous = readState(workspace);
52
+
53
+ const state = previous ?? emptyState({
54
+ agent, method, packageVersion, sourceRoot, profiles: plan.selection.profiles,
55
+ });
56
+ // The pass re-stamps identity: an install can change agent, method, or the
57
+ // package doing the writing, and a stale header would misdirect every later
58
+ // comparison.
59
+ state.agent = agent;
60
+ state.method = method;
61
+ state.sourceRoot = sourceRoot;
62
+ state.profiles = [...new Set([...(state.profiles ?? []), ...plan.selection.profiles])].sort();
63
+
64
+ const results = [];
65
+ const conflictFiles = [];
66
+ let failed = null;
67
+
68
+ for (const action of plan.actions) {
69
+ if (failed) {
70
+ results.push({ id: action.id, action: action.kind, status: "not-reached" });
71
+ continue;
72
+ }
73
+ try {
74
+ const outcome = perform({
75
+ action, item: catalogue.get(action.id), state, workspace, sourceRoot,
76
+ method, agent, allowExec, now,
77
+ });
78
+ results.push({ id: action.id, action: action.kind, ...outcome });
79
+ if (outcome.conflicts) conflictFiles.push(...outcome.conflicts);
80
+ } catch (err) {
81
+ failed = { id: action.id, action: action.kind, status: "failed", detail: err.message };
82
+ results.push(failed);
83
+ }
84
+ }
85
+
86
+ // Record the pass even on failure — see the header note.
87
+ state.packageVersion = failed ? (previous?.packageVersion ?? packageVersion) : packageVersion;
88
+ state.updatedAt = now();
89
+ state.installedAt ??= state.updatedAt;
90
+ state.events = [...(state.events ?? []), {
91
+ at: state.updatedAt,
92
+ verb: plan.verb,
93
+ packageVersion,
94
+ actions: results.filter((r) => r.status === "applied").length,
95
+ conflicts: conflictFiles.length,
96
+ failed: failed ? 1 : 0,
97
+ }];
98
+
99
+ const statePath = writeState(workspace, state);
100
+ const recordPath = writeLegacyRecord({ workspace, state, plan });
101
+
102
+ const count = (status) => results.filter((r) => r.status === status).length;
103
+ return {
104
+ schemaVersion: APPLY_SCHEMA_VERSION,
105
+ verb: plan.verb,
106
+ workspace,
107
+ agent,
108
+ method,
109
+ packageVersion,
110
+ results,
111
+ conflictFiles,
112
+ statePath,
113
+ recordPath,
114
+ failure: failed,
115
+ summary: {
116
+ applied: count("applied"),
117
+ adopted: count("adopted"),
118
+ unchanged: count("unchanged"),
119
+ removed: count("removed"),
120
+ conflicts: conflictFiles.length,
121
+ skipped: count("skipped"),
122
+ failed: failed ? 1 : 0,
123
+ notReached: count("not-reached"),
124
+ },
125
+ };
126
+ }
127
+
128
+ // ── one action ──────────────────────────────────────────────────────────────
129
+
130
+ function perform({ action, item, state, workspace, sourceRoot, method, agent, allowExec, now }) {
131
+ switch (action.kind) {
132
+ case "create":
133
+ case "refresh":
134
+ case "repair": {
135
+ requireItem(item, action.id);
136
+ const files = materialize({ item, workspace, sourceRoot, method, agent });
137
+ const retired = retireLegacyTargets({ item, workspace, sourceRoot, agent });
138
+ state.items[action.id] = {
139
+ kind: item.kind,
140
+ strategy: item.binding.strategy,
141
+ method: methodFor(item, method),
142
+ version: state.packageVersion,
143
+ sourceRoot: item.binding.source?.[0] ?? null,
144
+ ...files,
145
+ };
146
+ return {
147
+ status: "applied",
148
+ detail: describeFiles(files) + (retired.length ? `; retired ${retired.join(", ")}` : ""),
149
+ };
150
+ }
151
+
152
+ case "keep": {
153
+ // A selected item that already matches the source but is not recorded is
154
+ // adopted: we were asked to install it, and it is byte-identical to what
155
+ // we would have written. Anything else is left exactly as it is.
156
+ if (item && !state.items[action.id] && ["up-to-date", "linked"].includes(action.state)) {
157
+ state.items[action.id] = {
158
+ kind: item.kind,
159
+ strategy: item.binding.strategy,
160
+ method: methodFor(item, method),
161
+ version: state.packageVersion,
162
+ sourceRoot: item.binding.source?.[0] ?? null,
163
+ ...inventory({ item, workspace, sourceRoot }),
164
+ };
165
+ return { status: "adopted", detail: "already matched the source; now recorded" };
166
+ }
167
+ return { status: "unchanged" };
168
+ }
169
+
170
+ case "conflict": {
171
+ requireItem(item, action.id);
172
+ const written = writeConflictCopies({ item, action, workspace, sourceRoot, agent });
173
+ return {
174
+ status: "skipped",
175
+ detail: `left untouched; ${written.length} .new file(s) written for review`,
176
+ conflicts: written,
177
+ };
178
+ }
179
+
180
+ case "remove":
181
+ return removeItem({ id: action.id, state, workspace, sourceRoot });
182
+
183
+ case "exec": {
184
+ if (!allowExec) return { status: "skipped", detail: "exec not permitted" };
185
+ const spec = item?.exec;
186
+ if (!spec) return { status: "skipped", detail: "no exec specification" };
187
+ const cwd = insideWorkspace(workspace, spec.cwd ?? ".");
188
+ const run = spawnSync(spec.command, spec.args ?? [], { cwd, stdio: "pipe", encoding: "utf8" });
189
+ if (run.status !== 0) {
190
+ throw new Error(
191
+ `${spec.command} ${(spec.args ?? []).join(" ")} exited ${run.status ?? "on signal"}: ` +
192
+ `${(run.stderr ?? "").trim().split("\n").slice(-3).join(" ") || "no output"}`,
193
+ );
194
+ }
195
+ state.items[action.id] = {
196
+ kind: item.kind, strategy: "exec", method: "exec",
197
+ version: state.packageVersion, files: [],
198
+ lastRun: { at: now(), command: `${spec.command} ${(spec.args ?? []).join(" ")}`.trim() },
199
+ };
200
+ return { status: "applied", detail: "command ran" };
201
+ }
202
+
203
+ case "external": {
204
+ const spec = item?.package;
205
+ recordExternal(state, spec, now);
206
+ return { status: "skipped", detail: `install it yourself: ${spec?.spec ?? "unknown package"}` };
207
+ }
208
+
209
+ case "operator":
210
+ return { status: "skipped", detail: "operator step — printed, never performed" };
211
+
212
+ case "skip":
213
+ return { status: "skipped", detail: action.reason };
214
+
215
+ default:
216
+ return { status: "skipped", detail: `unhandled action: ${action.kind}` };
217
+ }
218
+ }
219
+
220
+ // ── materialisation ─────────────────────────────────────────────────────────
221
+
222
+ /**
223
+ * Write an item's files and return the state records for them. Dispatches on
224
+ * strategy; `method: "symlink"` turns the two copy strategies into links, but
225
+ * never the generated or merged ones — a persona is transform output and a
226
+ * managed region shares its file with the user, so neither can be a link into
227
+ * the source.
228
+ */
229
+ function materialize({ item, workspace, sourceRoot, method, agent }) {
230
+ const binding = item.binding;
231
+
232
+ if (binding.strategy === "managed-region") return writeManagedRegion({ binding, workspace, sourceRoot });
233
+ if (binding.strategy === "json-merge") return mergeJson({ binding, workspace, sourceRoot });
234
+
235
+ const pairs = expandBinding(binding, sourceRoot);
236
+ if (pairs.length === 0) throw new Error(`no source available for ${item.id}`);
237
+
238
+ const link = method === "symlink" && binding.strategy !== "transform-persona";
239
+ const files = [];
240
+
241
+ for (const pair of pairs) {
242
+ const targetAbs = insideWorkspace(workspace, pair.targetRel);
243
+ clearTarget(targetAbs);
244
+
245
+ if (link) {
246
+ mkdirSync(dirname(targetAbs), { recursive: true });
247
+ symlinkSync(pair.sourceAbs, targetAbs);
248
+ files.push({ path: pair.targetRel, mode: "symlink", linkTarget: pair.sourceAbs });
249
+ continue;
250
+ }
251
+
252
+ if (binding.strategy === "transform-persona") {
253
+ const { content } = transformPersona(readFileSync(pair.sourceAbs, "utf8"), { agent });
254
+ writeFileSyncDeep(targetAbs, content);
255
+ files.push({ path: pair.targetRel, mode: "generated", sha256: hashText(content) });
256
+ continue;
257
+ }
258
+
259
+ if (pair.isDir) {
260
+ for (const rel of walkTree(pair.sourceAbs)) {
261
+ const dest = insideWorkspace(workspace, `${pair.targetRel}/${rel}`);
262
+ mkdirSync(dirname(dest), { recursive: true });
263
+ copyFileSync(join(pair.sourceAbs, rel), dest);
264
+ files.push({ path: `${pair.targetRel}/${rel}`, mode: "copy", sha256: hashFile(dest) });
265
+ }
266
+ continue;
267
+ }
268
+
269
+ mkdirSync(dirname(targetAbs), { recursive: true });
270
+ copyFileSync(pair.sourceAbs, targetAbs);
271
+ files.push({ path: pair.targetRel, mode: "copy", sha256: hashFile(targetAbs) });
272
+ }
273
+
274
+ return { files };
275
+ }
276
+
277
+ /**
278
+ * Retire a path this item used to install to.
279
+ *
280
+ * The only case today is the `af-` namespace: a workspace set up before it has
281
+ * `.pi/prompts/spec.md` alongside the new `af-spec.md`, and pi keeps offering
282
+ * the stale `/spec` from it. Deleting it is subject to the same ownership rule
283
+ * as everything else — it goes only when it is a link into the source, or its
284
+ * bytes still match what we would have written. A same-named prompt the user
285
+ * wrote themselves stays, and is reported.
286
+ */
287
+ function retireLegacyTargets({ item, workspace, sourceRoot, agent }) {
288
+ const legacy = item.binding.legacyTargets ?? [];
289
+ if (legacy.length === 0) return [];
290
+
291
+ const sourceRel = (item.binding.source ?? [])[0];
292
+ const sourceAbs = sourceRel ? join(sourceRoot, sourceRel) : null;
293
+ const ours = sourceAbs && existsSync(sourceAbs)
294
+ ? (item.binding.strategy === "transform-persona"
295
+ ? hashText(transformPersona(readFileSync(sourceAbs, "utf8"), { agent }).content)
296
+ : hashFile(sourceAbs))
297
+ : null;
298
+
299
+ const retired = [];
300
+ for (const rel of legacy) {
301
+ const abs = insideWorkspace(workspace, rel);
302
+ const found = inspectPath(abs);
303
+ if (found.kind === "absent") continue;
304
+ if (found.kind === "symlink") {
305
+ if (!found.dangling && !isInside(sourceRoot, found.linkTarget)) continue;
306
+ unlinkSync(abs);
307
+ retired.push(rel);
308
+ continue;
309
+ }
310
+ if (!ours || hashFile(abs) !== ours) continue; // user-authored or edited — keep
311
+ rmSync(abs, { force: true });
312
+ retired.push(rel);
313
+ }
314
+ return retired;
315
+ }
316
+
317
+ /** The same record, computed without writing — used when adopting a match. */
318
+ function inventory({ item, workspace, sourceRoot }) {
319
+ const binding = item.binding;
320
+
321
+ // Shared-file forms record our part, not the whole file. Hashing the file
322
+ // here would record the user's lines as ours and report drift the moment
323
+ // they edit them.
324
+ if (binding.strategy === "managed-region") {
325
+ const region = extractRegion(readFileSync(join(sourceRoot, binding.source[0]), "utf8"));
326
+ return {
327
+ files: [{
328
+ path: binding.target, mode: "managed-region",
329
+ region: region?.name ?? null, sha256: region ? hashText(region.block) : null,
330
+ }],
331
+ };
332
+ }
333
+ if (binding.strategy === "json-merge") {
334
+ const fragment = JSON.parse(readFileSync(join(sourceRoot, binding.source[0]), "utf8"));
335
+ return {
336
+ files: [],
337
+ jsonKeys: leafPaths(fragment).map(([path, value]) => ({
338
+ path: binding.target, keyPath: path.join("."), sha256: hashText(canonicalJson(value)),
339
+ })),
340
+ };
341
+ }
342
+
343
+ const files = [];
344
+ for (const pair of expandBinding(item.binding, sourceRoot)) {
345
+ const targetAbs = join(workspace, pair.targetRel);
346
+ const found = inspectPath(targetAbs);
347
+ if (found.kind === "symlink") {
348
+ files.push({ path: pair.targetRel, mode: "symlink", linkTarget: found.linkTarget });
349
+ continue;
350
+ }
351
+ if (pair.isDir) {
352
+ for (const rel of walkTree(pair.sourceAbs)) {
353
+ const p = `${pair.targetRel}/${rel}`;
354
+ files.push({ path: p, mode: "copy", sha256: hashFile(join(workspace, p)) });
355
+ }
356
+ continue;
357
+ }
358
+ files.push({
359
+ path: pair.targetRel,
360
+ mode: item.binding.strategy === "transform-persona" ? "generated" : "copy",
361
+ sha256: hashFile(targetAbs),
362
+ });
363
+ }
364
+ return { files };
365
+ }
366
+
367
+ /**
368
+ * Replace the agent-fleet region of a shared file, preserving everything
369
+ * outside the sentinels. This is what lets a workspace keep its own justfile
370
+ * recipes across an upgrade that prunes retired harness recipes.
371
+ */
372
+ function writeManagedRegion({ binding, workspace, sourceRoot }) {
373
+ const sourceAbs = join(sourceRoot, binding.source[0]);
374
+ if (!existsSync(sourceAbs)) throw new Error(`managed-region source missing: ${binding.source[0]}`);
375
+
376
+ const region = extractRegion(readFileSync(sourceAbs, "utf8"));
377
+ if (!region) throw new Error(`no complete agent-fleet region in ${binding.source[0]}`);
378
+
379
+ const targetAbs = insideWorkspace(workspace, binding.target);
380
+ const existing = existsSync(targetAbs) ? readFileSync(targetAbs, "utf8") : "";
381
+ writeFileSyncDeep(targetAbs, replaceRegion(existing, region.block));
382
+
383
+ return {
384
+ files: [{
385
+ path: binding.target, mode: "managed-region",
386
+ region: region.name, sha256: hashText(region.block),
387
+ }],
388
+ };
389
+ }
390
+
391
+ /**
392
+ * Set only the leaf paths the source declares, leaving every other key in the
393
+ * target file alone — user permissions, env vars, third-party MCP servers and
394
+ * custom hooks all survive.
395
+ */
396
+ function mergeJson({ binding, workspace, sourceRoot }) {
397
+ const sourceAbs = join(sourceRoot, binding.source[0]);
398
+ if (!existsSync(sourceAbs)) throw new Error(`json-merge source missing: ${binding.source[0]}`);
399
+
400
+ const fragment = JSON.parse(readFileSync(sourceAbs, "utf8"));
401
+ const targetAbs = insideWorkspace(workspace, binding.target);
402
+ let target = {};
403
+ if (existsSync(targetAbs)) {
404
+ try { target = JSON.parse(readFileSync(targetAbs, "utf8")); }
405
+ catch (err) { throw new Error(`${binding.target} is not valid JSON: ${err.message}`); }
406
+ }
407
+
408
+ const jsonKeys = [];
409
+ for (const [keyPath, value] of leafPaths(fragment)) {
410
+ setPath(target, keyPath, value);
411
+ jsonKeys.push({
412
+ path: binding.target,
413
+ keyPath: keyPath.join("."),
414
+ sha256: hashText(canonicalJson(value)),
415
+ });
416
+ }
417
+ writeFileSyncDeep(targetAbs, JSON.stringify(target, null, 2) + "\n");
418
+
419
+ return { files: [], jsonKeys };
420
+ }
421
+
422
+ /**
423
+ * A conflicting file gets its incoming version written beside it as `.new`.
424
+ * The original is untouched; resolution is the human's, and `--accept-theirs`
425
+ * / `--accept-ours` exist for when it is not worth their time.
426
+ */
427
+ function writeConflictCopies({ item, action, workspace, sourceRoot, agent }) {
428
+ const written = [];
429
+ const conflicted = new Set((action.files ?? []).filter((f) => f.state === "conflict").map((f) => f.path));
430
+
431
+ for (const pair of expandBinding(item.binding, sourceRoot)) {
432
+ const emit = (targetRel, contents) => {
433
+ if (!conflicted.has(targetRel)) return;
434
+ const dest = insideWorkspace(workspace, `${targetRel}.new`);
435
+ writeFileSyncDeep(dest, contents);
436
+ written.push(`${targetRel}.new`);
437
+ };
438
+
439
+ if (pair.isDir) {
440
+ for (const rel of walkTree(pair.sourceAbs)) {
441
+ emit(`${pair.targetRel}/${rel}`, readFileSync(join(pair.sourceAbs, rel)));
442
+ }
443
+ continue;
444
+ }
445
+ emit(
446
+ pair.targetRel,
447
+ item.binding.strategy === "transform-persona"
448
+ ? transformPersona(readFileSync(pair.sourceAbs, "utf8"), { agent }).content
449
+ : readFileSync(pair.sourceAbs),
450
+ );
451
+ }
452
+ return written;
453
+ }
454
+
455
+ // ── removal ─────────────────────────────────────────────────────────────────
456
+
457
+ /**
458
+ * Delete only what the state file records, and only where the workspace copy
459
+ * is still what we wrote. A path the user has since edited is kept and
460
+ * reported — an upgrade that silently eats an edited file is the failure mode
461
+ * this whole design exists to prevent.
462
+ */
463
+ function removeItem({ id, state, workspace, sourceRoot }) {
464
+ const recorded = state.items[id];
465
+ if (!recorded) return { status: "skipped", detail: "not recorded as ours — nothing removed" };
466
+
467
+ const kept = [];
468
+ let removed = 0;
469
+
470
+ for (const file of recorded.files ?? []) {
471
+ const abs = insideWorkspace(workspace, file.path);
472
+ const found = inspectPath(abs);
473
+ if (found.kind === "absent") continue;
474
+
475
+ if (found.kind === "symlink") {
476
+ if (!isInside(sourceRoot, found.linkTarget) && !found.dangling) { kept.push(file.path); continue; }
477
+ unlinkSync(abs); // not rmSync — see clearTarget() on dangling links
478
+ removed++;
479
+ continue;
480
+ }
481
+ // A managed region shares its file with the user: take our block out and
482
+ // leave their lines, rather than deleting a file that is half theirs. If
483
+ // the block was edited, it is theirs now — keep the whole thing.
484
+ if (file.mode === "managed-region") {
485
+ const text = readFileSync(abs, "utf8");
486
+ const region = extractRegion(text);
487
+ if (!region || (file.sha256 && hashText(region.block) !== file.sha256)) {
488
+ kept.push(file.path);
489
+ continue;
490
+ }
491
+ const rest = stripRegion(text);
492
+ if (rest === null) rmSync(abs, { force: true });
493
+ else writeFileSync(abs, rest);
494
+ removed++;
495
+ continue;
496
+ }
497
+ if (!file.sha256) { kept.push(file.path); continue; }
498
+ if (hashFile(abs) !== file.sha256) { kept.push(file.path); continue; }
499
+ rmSync(abs, { recursive: true, force: true });
500
+ removed++;
501
+ }
502
+
503
+ pruneEmptyDirs(workspace, (recorded.files ?? []).map((f) => f.path));
504
+ delete state.items[id];
505
+
506
+ return {
507
+ status: "removed",
508
+ detail: kept.length > 0
509
+ ? `${removed} removed; kept ${kept.length} user-modified path(s): ${kept.slice(0, 3).join(", ")}`
510
+ : `${removed} path(s) removed`,
511
+ };
512
+ }
513
+
514
+ // ── the human-readable record ───────────────────────────────────────────────
515
+
516
+ /**
517
+ * `.ai/agent-fleet-setup.md` is rendered from the state file and never parsed
518
+ * back, so the two cannot disagree. It keeps the pre-engine section names so
519
+ * an older reader still finds `version:` and `agent:`.
520
+ */
521
+ function writeLegacyRecord({ workspace, state, plan }) {
522
+ const byKind = {};
523
+ for (const [id, entry] of Object.entries(state.items)) {
524
+ (byKind[entry.kind] ??= []).push(id.split(":").slice(1).join(":"));
525
+ }
526
+ const line = (label, kind) =>
527
+ `${(label + ":").padEnd(12)}[${(byKind[kind] ?? []).sort().join(", ")}]`;
528
+
529
+ const text = `# Agent Fleet — Workspace Setup
530
+ #
531
+ # Generated from ${STATE_REL_PATH} by \`agent-fleet ${plan.verb}\`.
532
+ # Edit the workspace, not this file: it is rewritten on every apply.
533
+
534
+ ## workspace-summary
535
+ agent: ${state.agent}
536
+ method: ${state.method}
537
+ version: ${state.packageVersion}
538
+ source: ${state.sourceRoot}
539
+
540
+ ## install-status
541
+ ${line("skills", "skill")}
542
+ ${line("commands", "command")}
543
+ ${line("personas", "persona")}
544
+ ${line("references", "reference")}
545
+ ${line("hooks", "hook")}
546
+ ${line("extensions", "pi-extension")}
547
+ ${line("harnesses", "pi-harness")}
548
+ ${line("runtime-skills", "pi-runtime-skill")}
549
+ ${line("companions", "companion")}
550
+ external: [${(state.externalPackages ?? []).map((p) => p.spec).sort().join(", ")}]
551
+ updated: ${state.updatedAt.slice(0, 10)}
552
+
553
+ ## verification
554
+ - ${Object.keys(state.items).length} item(s) recorded; run \`agent-fleet verify\` to check them against disk.
555
+ - No secrets are stored in this file or in ${STATE_REL_PATH}.
556
+ `;
557
+ const path = join(workspace, LEGACY_RECORD_REL_PATH);
558
+ writeFileSyncDeep(path, text);
559
+ return path;
560
+ }
561
+
562
+ // ── helpers ─────────────────────────────────────────────────────────────────
563
+
564
+ /**
565
+ * Resolve a workspace-relative path and refuse anything that escapes. A
566
+ * manifest is data; a `../` in a target must not be able to write outside the
567
+ * directory the user named.
568
+ */
569
+ function insideWorkspace(workspace, rel) {
570
+ const abs = resolve(workspace, rel);
571
+ if (!isInside(workspace, abs)) {
572
+ throw new Error(`refusing to write outside the workspace: ${rel}`);
573
+ }
574
+ return abs;
575
+ }
576
+
577
+ function writeFileSyncDeep(abs, contents) {
578
+ mkdirSync(dirname(abs), { recursive: true });
579
+ writeFileSync(abs, contents);
580
+ }
581
+
582
+ /**
583
+ * Remove whatever occupies a target so the new form lands cleanly.
584
+ *
585
+ * A symlink is unlinked, never rmSync'd: `rmSync(path, { force: true })` stats
586
+ * through the link, sees ENOENT for a *dangling* one, and returns as if the
587
+ * path were already gone — leaving the broken link in place for the next
588
+ * symlinkSync to fail on with EEXIST. Repairing a broken link is exactly the
589
+ * case that hits this.
590
+ */
591
+ function clearTarget(abs) {
592
+ let st;
593
+ try { st = lstatSync(abs); } catch { return; }
594
+ if (st.isSymbolicLink()) { unlinkSync(abs); return; }
595
+ rmSync(abs, { recursive: true, force: true });
596
+ }
597
+
598
+ /**
599
+ * Drop directories emptied by a removal, never one that still holds anything.
600
+ *
601
+ * `rmdirSync` and not `rmSync`: the non-recursive rmSync throws EISDIR on any
602
+ * directory at all, so the whole walk used to abort on its first step and leave
603
+ * empty skill directories behind. rmdirSync is the call that means "remove this
604
+ * only if it is empty", which is exactly the rule wanted here — ENOTEMPTY stops
605
+ * the walk and the user's files stay.
606
+ */
607
+ function pruneEmptyDirs(workspace, relPaths) {
608
+ const dirs = [...new Set(relPaths.map((p) => dirname(p)))].sort((a, b) => b.length - a.length);
609
+ for (const rel of dirs) {
610
+ let dir = resolve(workspace, rel);
611
+ while (isInside(workspace, dir) && dir !== resolve(workspace)) {
612
+ try { rmdirSync(dir); } catch { break; }
613
+ dir = dirname(dir);
614
+ }
615
+ }
616
+ }
617
+
618
+ function methodFor(item, method) {
619
+ const strategy = item.binding.strategy;
620
+ if (strategy === "transform-persona") return "generated";
621
+ if (strategy === "managed-region" || strategy === "json-merge") return strategy;
622
+ return method;
623
+ }
624
+
625
+ function recordExternal(state, spec, now) {
626
+ if (!spec?.spec) return;
627
+ state.externalPackages ??= [];
628
+ if (state.externalPackages.some((p) => p.spec === spec.spec)) return;
629
+ state.externalPackages.push({ spec: spec.spec, scope: spec.scope ?? "project", recordedAt: now() });
630
+ }
631
+
632
+ function describeFiles({ files = [], jsonKeys = [] }) {
633
+ const parts = [];
634
+ if (files.length) parts.push(`${files.length} file(s)`);
635
+ if (jsonKeys.length) parts.push(`${jsonKeys.length} json key(s)`);
636
+ return parts.join(", ") || "nothing to write";
637
+ }
638
+
639
+ function requireItem(item, id) {
640
+ if (!item) throw new Error(`${id} is not in the catalogue for this agent`);
641
+ }