@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,106 @@
1
+ // merge-forms.js — the two artifact forms that share a file with the user.
2
+ //
3
+ // Every other strategy owns its target outright: the file is a copy, a link, or
4
+ // generated output, and comparing it is comparing bytes. These two are not.
5
+ //
6
+ // • a managed region is a sentinel-bounded block inside a file whose other
7
+ // lines belong to the user (the `justfile` harness recipes);
8
+ // • a JSON merge sets named key paths inside a file whose other keys belong
9
+ // to the user (`.claude/settings.json`).
10
+ //
11
+ // Both need the same three operations — locate our part, compare our part,
12
+ // rewrite our part — and both `verify` and `apply` need them. They live here
13
+ // so the reader and the writer cannot disagree about where our part ends;
14
+ // putting them in either module would make the two import each other.
15
+
16
+ // `[ \t]*$` rather than `\s*$` on purpose: `\s` matches newlines, and a greedy
17
+ // trailing `\s*` swallows the line break after the closing sentinel whenever
18
+ // one is there to swallow. The same region then hashes differently depending on
19
+ // whether it sits mid-file or at EOF, which reads as drift on every re-run.
20
+ const REGION_OPEN = /^#[ \t]*>>>[ \t]*agent-fleet:(\S+).*>>>[ \t]*$/m;
21
+
22
+ const regionClose = (name) =>
23
+ new RegExp(`^#[ \\t]*<<<[ \\t]*agent-fleet:${escapeRe(name)}[ \\t]*<<<[ \\t]*$`, "m");
24
+
25
+ /**
26
+ * Find the agent-fleet region in a file's text.
27
+ *
28
+ * @returns {{name: string, block: string, start: number, end: number}|null}
29
+ * null when there is no region, or the opening sentinel has no match — an
30
+ * unterminated region is not a region we may rewrite.
31
+ */
32
+ export function extractRegion(text) {
33
+ if (typeof text !== "string") return null;
34
+ const open = text.match(REGION_OPEN);
35
+ if (!open) return null;
36
+ const close = text.match(regionClose(open[1]));
37
+ if (!close || close.index < open.index) return null;
38
+ const end = close.index + close[0].length;
39
+ return { name: open[1], block: text.slice(open.index, end), start: open.index, end };
40
+ }
41
+
42
+ /**
43
+ * Put `block` into `existing`, replacing a region already there or appending
44
+ * one if not. Everything outside the sentinels is preserved verbatim — this is
45
+ * what lets a workspace keep its own recipes across an upgrade that prunes
46
+ * retired ones.
47
+ */
48
+ export function replaceRegion(existing, block) {
49
+ const found = extractRegion(existing);
50
+ if (found) return existing.slice(0, found.start) + block + existing.slice(found.end);
51
+ const head = (existing ?? "").trimEnd();
52
+ return head.length > 0 ? `${head}\n\n${block}\n` : `${block}\n`;
53
+ }
54
+
55
+ /**
56
+ * Take our region out of `existing`, leaving the user's lines. Used when the
57
+ * last item that owned the region is removed: leaving the block behind is worse
58
+ * than deleting the file, because `just --list` keeps offering recipes for
59
+ * harness directories that are no longer installed.
60
+ *
61
+ * @returns {string|null} the remaining text, or null when nothing is left of it
62
+ */
63
+ export function stripRegion(existing) {
64
+ const found = extractRegion(existing);
65
+ if (!found) return existing ?? null;
66
+ const rest = (existing.slice(0, found.start) + existing.slice(found.end)).trim();
67
+ return rest.length > 0 ? `${rest}\n` : null;
68
+ }
69
+
70
+ /**
71
+ * `[[path, value], …]` for every leaf of an object — arrays and primitives are
72
+ * leaves, plain objects are walked. These paths are exactly what a merge sets
73
+ * and what the state file records, so setting a whole subtree is impossible by
74
+ * construction.
75
+ */
76
+ export function leafPaths(value, trail = []) {
77
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return [[trail, value]];
78
+ return Object.entries(value).flatMap(([k, v]) => leafPaths(v, [...trail, k]));
79
+ }
80
+
81
+ export function getPath(obj, path) {
82
+ let node = obj;
83
+ for (const key of path) {
84
+ if (node === null || typeof node !== "object") return undefined;
85
+ node = node[key];
86
+ }
87
+ return node;
88
+ }
89
+
90
+ export function setPath(obj, path, value) {
91
+ let node = obj;
92
+ for (const key of path.slice(0, -1)) {
93
+ if (node[key] === null || typeof node[key] !== "object" || Array.isArray(node[key])) node[key] = {};
94
+ node = node[key];
95
+ }
96
+ node[path[path.length - 1]] = value;
97
+ }
98
+
99
+ /** Stable serialisation for hashing a JSON value. */
100
+ export function canonicalJson(value) {
101
+ return JSON.stringify(value ?? null);
102
+ }
103
+
104
+ function escapeRe(s) {
105
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
106
+ }
@@ -0,0 +1,569 @@
1
+ // plan.js — turn (manifest × recorded state × disk) into an ordered action list.
2
+ //
3
+ // This is the deterministic core the whole installer rests on. `install`,
4
+ // `upgrade`, and later `doctor --fix` and `uninstall` are the same computation
5
+ // with different policies about what each item state means; `apply()` (Phase 4)
6
+ // is this plan executed. Because every verb shares the planner, repair and
7
+ // setup cannot drift apart in behaviour — that drift is what the prose skill
8
+ // could not prevent.
9
+ //
10
+ // The planner is pure in the sense that matters: it reads the filesystem, and
11
+ // writes nothing. Two runs against an unchanged workspace produce identical
12
+ // output.
13
+ //
14
+ // See plans/deterministic-installer-manifest-spec.md §4 for the state and merge
15
+ // tables this implements, and plans/deterministic-installer.md phases 3 and 5.
16
+
17
+ import { itemsForAgent, resolveSelection } from "./manifest.js";
18
+ import { evaluateWorkspace, resolveBaseRoot } from "./verify.js";
19
+ import { readState, readLegacyRecord, isAgentFleetCheckout } from "./state.js";
20
+
21
+ export const PLAN_SCHEMA_VERSION = 1;
22
+
23
+ // What an action does. Ordered by how much it disturbs the workspace, which is
24
+ // also the order they are summarised in.
25
+ export const ACTION_KINDS = [
26
+ "create", // nothing there; write it
27
+ "refresh", // present but behind, or deliberately overwritten
28
+ "repair", // recorded but missing/broken on disk
29
+ "remove", // retired upstream, and we own it
30
+ "conflict", // three-way conflict — needs a human decision, never guessed
31
+ "keep", // already correct, or a local edit we are preserving
32
+ "exec", // runs a command; gated on --allow-exec
33
+ "external", // a package the user installs; reported, never performed
34
+ "operator", // systemd/pairing/credentials; printed as next steps only
35
+ "skip", // deliberately not acted on, with a reason
36
+ ];
37
+
38
+ // Actions that change the workspace. `changes === 0` is what idempotency means.
39
+ const MUTATING = new Set(["create", "refresh", "repair", "remove"]);
40
+
41
+ // The states that mean "we installed this and it is broken now" — the only
42
+ // ones `repair` acts on, and the ones every other verb repairs unconditionally.
43
+ const BREAKAGE = {
44
+ "missing": "recorded as installed but absent on disk",
45
+ "broken-link": "symlink target no longer exists",
46
+ "foreign-link": "symlink resolves outside the source root",
47
+ };
48
+
49
+ /**
50
+ * Build an action plan.
51
+ *
52
+ * @param {object} opts
53
+ * @param {string} opts.workspace absolute target workspace
54
+ * @param {string} opts.sourceRoot absolute agent-fleet package root
55
+ * @param {string} opts.packageVersion the running package's version
56
+ * @param {object} opts.manifest loaded install manifest
57
+ * @param {"install"|"upgrade"|"repair"|"uninstall"} [opts.verb]
58
+ * @param {string} [opts.agent] overrides the recorded agent
59
+ * @param {"copy"|"symlink"} [opts.method]
60
+ * @param {string[]} [opts.profiles] profile names (install only)
61
+ * @param {string[]} [opts.items] explicit item ids (install, uninstall)
62
+ * @param {boolean} [opts.allowExec] permit `exec` items to be planned
63
+ * @param {"theirs"|"ours"|null} [opts.accept] non-interactive conflict policy
64
+ * @param {string} [opts.platform]
65
+ * @returns {object} plan
66
+ */
67
+ export function buildPlan({
68
+ workspace,
69
+ sourceRoot,
70
+ packageVersion,
71
+ manifest,
72
+ verb = "install",
73
+ agent = null,
74
+ method = null,
75
+ profiles = [],
76
+ items = [],
77
+ all = false,
78
+ allowExec = false,
79
+ accept = null,
80
+ platform = process.platform,
81
+ }) {
82
+ const state = readState(workspace);
83
+ const legacy = readLegacyRecord(workspace);
84
+ const resolvedAgent = agent ?? state?.agent ?? legacy?.agent ?? null;
85
+ if (!resolvedAgent) {
86
+ throw new Error(
87
+ "cannot plan without a coding agent — pass --agent <claude-code|opencode|pi>",
88
+ );
89
+ }
90
+
91
+ const recordedVersion = state?.packageVersion ?? legacy?.version ?? null;
92
+ const stateSource = state ? "state-file" : legacy ? "legacy-record" : "none";
93
+ const baseRoot = resolveBaseRoot(sourceRoot, recordedVersion);
94
+
95
+ // Symlink installs survive only inside an agent-fleet checkout (see
96
+ // isAgentFleetCheckout). A workspace that recorded `symlink` before the
97
+ // restriction is not left half-supported: the method resolves to `copy`, and
98
+ // the decision table's method-change rule then re-materialises every linked
99
+ // item as a real file on this pass. The CLI refuses an *explicit*
100
+ // `--method symlink` outright rather than downgrading it silently — that one
101
+ // the user typed on purpose.
102
+ const requestedMethod = method ?? state?.method ?? "copy";
103
+ const symlinkSupported = isAgentFleetCheckout(workspace);
104
+ const resolvedMethod = requestedMethod === "symlink" && !symlinkSupported ? "copy" : requestedMethod;
105
+
106
+ const evaluations = evaluateWorkspace({
107
+ workspace, sourceRoot, manifest, agent: resolvedAgent, platform, state, baseRoot,
108
+ fileLimit: Infinity,
109
+ });
110
+ const byId = new Map(evaluations.map((e) => [e.id, e]));
111
+
112
+ // What are we acting on?
113
+ //
114
+ // install — the selection the caller asked for (profiles ∪ items), closed
115
+ // over `requires` and `companions`.
116
+ // upgrade — whatever this workspace already has. An upgrade never widens
117
+ // the install; new artifacts are reported as available, and the
118
+ // user adds them with an explicit `install`.
119
+ // repair — the same recorded set, but only breakage is actionable.
120
+ // uninstall — the named recorded items (or all of them), closed downwards
121
+ // over companions nobody else still needs.
122
+ const recordedIds = Object.keys(state?.items ?? {}).sort();
123
+ const notes = [];
124
+
125
+ if (["upgrade", "repair", "uninstall"].includes(verb) && stateSource === "none") {
126
+ throw new Error(
127
+ `nothing to ${verb} — this workspace has no agent-fleet install record. Run \`install\` first.`,
128
+ );
129
+ }
130
+
131
+ const selection = verb === "install"
132
+ ? resolveSelection(manifest, resolvedAgent, { profiles, items })
133
+ : verb === "uninstall"
134
+ ? resolveRemoval({ manifest, agent: resolvedAgent, recordedIds, requested: items, all, notes })
135
+ : { selected: recordedIds, unknown: [] };
136
+
137
+ const selected = new Set(selection.selected);
138
+
139
+ if (resolvedMethod !== requestedMethod) {
140
+ notes.push({
141
+ type: "symlink-retired",
142
+ detail:
143
+ "this workspace was installed with symlinks, which are now supported only inside " +
144
+ "an agent-fleet checkout — linked items are being re-materialised as copies",
145
+ });
146
+ }
147
+
148
+ if (["upgrade", "repair"].includes(verb) && stateSource === "legacy-record") {
149
+ notes.push({
150
+ type: "pre-engine-workspace",
151
+ detail:
152
+ "install record predates the state file, so ownership cannot be read back; " +
153
+ "run `install` once to reconstruct it before upgrading",
154
+ });
155
+ }
156
+ if (verb === "upgrade") {
157
+ if (recordedVersion && recordedVersion === packageVersion) {
158
+ notes.push({
159
+ type: "no-version-delta",
160
+ detail: `already at v${packageVersion} — only content drift is actionable`,
161
+ });
162
+ }
163
+ if (!baseRoot && recordedVersion) {
164
+ notes.push({
165
+ type: "base-snapshot-missing",
166
+ detail:
167
+ `no .versions/${recordedVersion} snapshot — merges degrade to two-way ` +
168
+ "and local edits are preserved rather than merged",
169
+ });
170
+ }
171
+ }
172
+
173
+ const actions = [];
174
+ for (const evaluation of evaluations) {
175
+ const action = decide({
176
+ evaluation,
177
+ verb,
178
+ selected: selected.has(evaluation.id),
179
+ allowExec,
180
+ accept,
181
+ method: resolvedMethod,
182
+ });
183
+ if (action) actions.push({ ...action, ...describe(evaluation) });
184
+ }
185
+
186
+ // Recorded ids the current manifest no longer lists — retired upstream, or
187
+ // catalogued for a different agent — never reach the loop above, because it
188
+ // walks the catalogue. Both verbs that remove things still have to reach them:
189
+ // otherwise a retired artifact could never be cleaned up at all.
190
+ if (["upgrade", "uninstall"].includes(verb)) {
191
+ for (const id of selection.selected) {
192
+ if (byId.has(id)) continue;
193
+ actions.push({
194
+ kind: "remove",
195
+ id,
196
+ itemKind: state?.items?.[id]?.kind ?? "unknown",
197
+ consent: "file",
198
+ state: "gone",
199
+ owned: true,
200
+ target: state?.items?.[id]?.files?.[0]?.path ?? null,
201
+ reason: verb === "uninstall"
202
+ ? "recorded as installed but no longer in the catalogue"
203
+ : "no longer in the catalogue for this agent — retired upstream",
204
+ });
205
+ }
206
+ }
207
+
208
+ const ordered = orderActions(actions, manifest, resolvedAgent);
209
+ const conflicts = ordered.filter((a) => a.kind === "conflict");
210
+
211
+ return {
212
+ schemaVersion: PLAN_SCHEMA_VERSION,
213
+ verb,
214
+ workspace,
215
+ sourceRoot,
216
+ agent: resolvedAgent,
217
+ method: resolvedMethod,
218
+ packageVersion,
219
+ recordedVersion,
220
+ stateSource,
221
+ baseAvailable: Boolean(baseRoot),
222
+ selection: {
223
+ profiles: [...profiles].sort(),
224
+ requested: [...items].sort(),
225
+ resolved: selection.selected,
226
+ unknown: selection.unknown,
227
+ },
228
+ actions: ordered,
229
+ conflicts,
230
+ notes,
231
+ summary: summarise(ordered, evaluations, selected, verb),
232
+ };
233
+ }
234
+
235
+ /**
236
+ * Which recorded items an `uninstall` should take down.
237
+ *
238
+ * Selection closes *downwards* only. Removing an item takes its companions —
239
+ * but a companion shared with something that stays installed is kept, or
240
+ * removing `pi-extension:btw` would delete the `package.json` five other
241
+ * extensions run from. The mirror rule guards the other direction: an item
242
+ * another installed item `pinnedBy` is refused, not silently orphaned.
243
+ *
244
+ * @returns {{ selected: string[], unknown: string[], refused: object[] }}
245
+ */
246
+ function resolveRemoval({ manifest, agent, recordedIds, requested, all, notes }) {
247
+ const recorded = new Set(recordedIds);
248
+ const catalogue = new Map(itemsForAgent(manifest, agent).map((i) => [i.id, i]));
249
+ const unknown = [];
250
+
251
+ const roots = [];
252
+ if (all) {
253
+ roots.push(...recorded);
254
+ } else {
255
+ for (const id of requested) {
256
+ if (recorded.has(id)) roots.push(id);
257
+ else unknown.push(id);
258
+ }
259
+ }
260
+
261
+ // A fixpoint, not two passes: refusing a pinned item can orphan a companion
262
+ // that was only selected because of it, and expanding companions can surface
263
+ // a newly pinned one. Iterate until neither step changes anything.
264
+ const refused = new Map();
265
+ let selected = new Set();
266
+ for (;;) {
267
+ selected = new Set(roots.filter((id) => !refused.has(id)));
268
+
269
+ // Downward closure: a companion travels with its parent.
270
+ let grew = true;
271
+ while (grew) {
272
+ grew = false;
273
+ for (const id of [...selected]) {
274
+ for (const cid of catalogue.get(id)?.companions ?? []) {
275
+ if (!recorded.has(cid) || selected.has(cid) || refused.has(cid)) continue;
276
+ selected.add(cid);
277
+ grew = true;
278
+ }
279
+ }
280
+ }
281
+
282
+ // Upward guard: refuse rather than break something that stays. One rule
283
+ // covers both shapes — an explicit `pinnedBy` edge, and a companion whose
284
+ // parent survives (removing `.pi/extensions/package.json` under five
285
+ // extensions is the same mistake as removing a pinned harness).
286
+ const newlyRefused = [...selected]
287
+ .map((id) => ({
288
+ id,
289
+ pinnedBy: [
290
+ ...(catalogue.get(id)?.pinnedBy ?? []),
291
+ ...(catalogue.get(id)?.parents ?? []),
292
+ ].filter((p) => recorded.has(p) && !selected.has(p)),
293
+ }))
294
+ .filter((entry) => entry.pinnedBy.length > 0);
295
+
296
+ if (newlyRefused.length === 0) break;
297
+ for (const entry of newlyRefused) refused.set(entry.id, entry);
298
+ }
299
+
300
+ for (const entry of [...refused.values()].sort((a, b) => (a.id < b.id ? -1 : 1))) {
301
+ notes.push({
302
+ type: "pinned",
303
+ detail: `${entry.id} is kept — still required by ${entry.pinnedBy.sort().join(", ")}`,
304
+ });
305
+ }
306
+
307
+ return {
308
+ selected: [...selected].sort(),
309
+ unknown: uniqSorted(unknown),
310
+ refused: [...refused.values()],
311
+ };
312
+ }
313
+
314
+ function uniqSorted(list) {
315
+ return [...new Set(list)].sort();
316
+ }
317
+
318
+ /** True when the plan needs a human decision before it can be applied. */
319
+ export function hasConflicts(plan) {
320
+ return plan.conflicts.length > 0;
321
+ }
322
+
323
+ /** True when applying the plan would change the workspace. */
324
+ export function isNoop(plan) {
325
+ return plan.summary.changes === 0 && plan.conflicts.length === 0;
326
+ }
327
+
328
+ // ── the decision table ──────────────────────────────────────────────────────
329
+
330
+ /**
331
+ * One item's state → one action. This is §4.1 of the spec, plus the one place
332
+ * the two verbs genuinely differ:
333
+ *
334
+ * `modified` (the user edited an installed file)
335
+ * • install — refresh. The user named this item, and SKILL.md step 10's
336
+ * rule applies: selection is consent, so no mid-flight question. The
337
+ * action carries `overwrites: true` so the confirmation screen can say so.
338
+ * • upgrade — keep. Nobody asked for this file specifically; a bulk version
339
+ * bump must never eat a deliberate local edit.
340
+ *
341
+ * The two Phase 6 verbs are narrowings of the same table rather than new ones:
342
+ *
343
+ * repair — admits only the three breakage states. Content that is merely
344
+ * behind or edited is not breakage, and a doctor that quietly
345
+ * refreshed it would be an upgrade wearing a repair's name.
346
+ * uninstall — admits only removal, and only of what the state file records.
347
+ */
348
+ function decide({ evaluation, verb, selected, allowExec, accept, method }) {
349
+ const { id, state, consent } = evaluation;
350
+
351
+ if (verb === "uninstall") {
352
+ if (!selected) return null;
353
+ // The ownership rule, at plan time: `apply()` enforces it again before it
354
+ // deletes anything, but a plan that lists a file we never installed would
355
+ // already have told the user a lie.
356
+ if (!evaluation.owned) {
357
+ return { kind: "skip", id, reason: "not recorded as installed by agent-fleet — never removed" };
358
+ }
359
+ return { kind: "remove", id, reason: "selected for removal" };
360
+ }
361
+
362
+ if (verb === "repair") {
363
+ // Only breakage, and only ours. An unowned broken link (a pre-engine
364
+ // workspace, a hand-made link) is still reported — by the doctor scan,
365
+ // which has the rename heuristics the manifest cannot express.
366
+ if (!evaluation.owned || !BREAKAGE[state]) return null;
367
+ return { kind: "repair", id, reason: BREAKAGE[state] };
368
+ }
369
+
370
+ // Consent classes the engine never applies itself, regardless of state.
371
+ if (state === "not-applicable") {
372
+ if (!selected) return null;
373
+ if (consent === "exec") {
374
+ return allowExec
375
+ ? { kind: "exec", id, reason: "declared command, permitted by --allow-exec" }
376
+ : { kind: "skip", id, reason: "runs a command — re-run with --allow-exec to include it" };
377
+ }
378
+ if (consent === "external") {
379
+ return {
380
+ kind: "external",
381
+ id,
382
+ reason: `external package — install ${evaluation.packageSpec ?? "it"} yourself; never done for you`,
383
+ };
384
+ }
385
+ if (consent === "operator") {
386
+ return {
387
+ kind: "operator",
388
+ id,
389
+ reason: `${(evaluation.operatorSteps ?? []).length} operator step(s) — printed, never performed`,
390
+ };
391
+ }
392
+ return { kind: "skip", id, reason: "no workspace target" };
393
+ }
394
+
395
+ // Owned but retired, or the source vanished: propose the cleanup on upgrade,
396
+ // leave it alone on install.
397
+ if (state === "gone") {
398
+ if (!evaluation.owned) return null;
399
+ return verb === "upgrade"
400
+ ? { kind: "remove", id, reason: "retired upstream — no source in this version" }
401
+ : { kind: "keep", id, reason: "retired upstream; `upgrade` proposes the cleanup" };
402
+ }
403
+
404
+ // Recorded as installed but missing or mis-linked on disk. Repair regardless
405
+ // of selection — this is breakage we caused, and leaving it is not an option.
406
+ if (BREAKAGE[state]) {
407
+ if (!evaluation.owned && !selected) return null;
408
+ return { kind: "repair", id, reason: BREAKAGE[state] };
409
+ }
410
+
411
+ if (!selected) {
412
+ // Never touched: a narrower profile does not uninstall anything (§2.3).
413
+ return evaluation.owned
414
+ ? { kind: "keep", id, reason: "installed but not in this selection — selection never removes" }
415
+ : null;
416
+ }
417
+
418
+ // Install form, not content: a copy whose bytes match the source is still the
419
+ // wrong thing when the workspace asked for symlinks (and vice versa), so a
420
+ // changed --method has to re-materialise even a byte-identical item.
421
+ if (
422
+ ["linked", "up-to-date", "outdated"].includes(state) &&
423
+ ["copy", "symlink"].includes(evaluation.recordedMethod) &&
424
+ evaluation.recordedMethod !== method
425
+ ) {
426
+ return {
427
+ kind: "refresh",
428
+ id,
429
+ reason: `installed as ${evaluation.recordedMethod}; this run asks for ${method}`,
430
+ };
431
+ }
432
+
433
+ switch (state) {
434
+ case "absent":
435
+ return { kind: "create", id, reason: "not installed" };
436
+
437
+ case "linked":
438
+ return { kind: "keep", id, reason: "symlinked to source — content follows the package" };
439
+
440
+ case "up-to-date":
441
+ return { kind: "keep", id, reason: "matches the current source" };
442
+
443
+ case "outdated":
444
+ return { kind: "refresh", id, reason: "source is newer; the local copy is unmodified" };
445
+
446
+ case "modified":
447
+ return verb === "upgrade"
448
+ ? { kind: "keep", id, reason: "locally modified — preserved by upgrade", preserved: true }
449
+ : { kind: "refresh", id, reason: "locally modified — selecting it overwrites your edits", overwrites: true };
450
+
451
+ case "conflict":
452
+ if (accept === "theirs") {
453
+ return { kind: "refresh", id, reason: "conflict resolved by --accept-theirs", overwrites: true };
454
+ }
455
+ if (accept === "ours") {
456
+ return { kind: "keep", id, reason: "conflict resolved by --accept-ours", preserved: true };
457
+ }
458
+ return {
459
+ kind: "conflict",
460
+ id,
461
+ reason: "changed both locally and upstream — resolve with --accept-theirs / --accept-ours",
462
+ };
463
+
464
+ case "partial":
465
+ return { kind: "create", id, reason: "partially present — completing the install" };
466
+
467
+ case "unchecked":
468
+ // managed-region / json-merge: their real comparison needs the merge
469
+ // logic that lands with apply(). Planning them as a refresh is the safe
470
+ // reading — both strategies are idempotent rewrites of a bounded region.
471
+ return { kind: "refresh", id, reason: "managed region — rewritten from source on every apply" };
472
+
473
+ default:
474
+ return { kind: "skip", id, reason: `unhandled state: ${state}` };
475
+ }
476
+ }
477
+
478
+ // ── ordering ────────────────────────────────────────────────────────────────
479
+
480
+ // Phases apply() walks in order. A command must see the finished file tree —
481
+ // `npm ci --prefix .pi/extensions` needs the manifests already written — so no
482
+ // amount of dependency ordering inside phase 1 can put an exec early enough to
483
+ // be wrong. Reporting-only kinds come last because they change nothing.
484
+ const PHASE = { exec: 1, external: 2, operator: 2, skip: 2 };
485
+ const phaseOf = (kind) => PHASE[kind] ?? 0;
486
+
487
+ /**
488
+ * Order actions so apply() can walk them straight through: file work first
489
+ * (requirements before the items that need them, then by id), then commands,
490
+ * then the reporting-only kinds.
491
+ *
492
+ * Two edge sets feed the topological pass — `requires`, which is a hard
493
+ * dependency, and a companion's `parents`, so a companion never lands before
494
+ * the artifact it belongs to. Cycles are legal (the two Fleet Core harnesses
495
+ * require each other, because either one alone cannot boot `just fleet`); the
496
+ * trail guard makes such a pair fall back to id order instead of looping.
497
+ */
498
+ function orderActions(actions, manifest, agent) {
499
+ const catalogue = itemsForAgent(manifest, agent);
500
+ const edges = new Map(
501
+ catalogue.map((i) => [i.id, [...(i.requires ?? []), ...(i.parents ?? [])]]),
502
+ );
503
+ const present = new Map(actions.map((a) => [a.id, a]));
504
+ const out = [];
505
+ const seen = new Set();
506
+
507
+ const visit = (id, trail) => {
508
+ if (seen.has(id) || trail.has(id)) return;
509
+ trail.add(id);
510
+ for (const dep of [...(edges.get(id) ?? [])].sort()) {
511
+ if (present.has(dep)) visit(dep, trail);
512
+ }
513
+ trail.delete(id);
514
+ seen.add(id);
515
+ out.push(present.get(id));
516
+ };
517
+
518
+ for (const id of [...present.keys()].sort()) visit(id, new Set());
519
+
520
+ // Stable partition — the topological order survives inside each phase.
521
+ return out
522
+ .map((action, index) => ({ action, index }))
523
+ .sort((a, b) => phaseOf(a.action.kind) - phaseOf(b.action.kind) || a.index - b.index)
524
+ .map((entry) => entry.action);
525
+ }
526
+
527
+ // ── reporting ───────────────────────────────────────────────────────────────
528
+
529
+ function describe(evaluation) {
530
+ const out = {
531
+ itemKind: evaluation.kind,
532
+ consent: evaluation.consent,
533
+ state: evaluation.state,
534
+ owned: evaluation.owned,
535
+ target: evaluation.target ?? null,
536
+ };
537
+ if (evaluation.changedCount) out.changedCount = evaluation.changedCount;
538
+ // What the human does instead, for the two classes the engine won't do itself.
539
+ if (evaluation.operatorSteps) out.operatorSteps = evaluation.operatorSteps;
540
+ if (evaluation.packageSpec) out.packageSpec = evaluation.packageSpec;
541
+ // Only the paths a human has to act on travel with the action; the rest is
542
+ // noise in a plan that may list a hundred items.
543
+ const notable = (evaluation.files ?? []).filter(
544
+ (f) => f.state === "conflict" || f.state === "modified",
545
+ );
546
+ if (notable.length > 0) out.files = notable.map((f) => ({ path: f.path, state: f.state }));
547
+ return out;
548
+ }
549
+
550
+ function summarise(actions, evaluations, selected, verb) {
551
+ const byKind = Object.fromEntries(ACTION_KINDS.map((k) => [k, 0]));
552
+ for (const a of actions) byKind[a.kind] = (byKind[a.kind] ?? 0) + 1;
553
+
554
+ // Catalogued for this agent, not installed, not selected: what an `install`
555
+ // with a wider profile would add. Upgrade reports it instead of doing it.
556
+ const newAvailable = evaluations.filter(
557
+ (e) => !e.owned && e.state === "absent" && !selected.has(e.id),
558
+ ).length;
559
+
560
+ return {
561
+ ...byKind,
562
+ total: actions.length,
563
+ changes: actions.filter((a) => MUTATING.has(a.kind)).length,
564
+ overwrites: actions.filter((a) => a.overwrites).length,
565
+ preserved: actions.filter((a) => a.preserved).length,
566
+ newAvailable,
567
+ verb,
568
+ };
569
+ }