@apralabs/apra-fleet 0.4.2 → 0.4.3

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 (370) hide show
  1. package/README.md +38 -5
  2. package/dist/agents/backlog-groomer.md +25 -0
  3. package/dist/agents/ci-watcher.md +11 -0
  4. package/dist/agents/deployer.md +37 -2
  5. package/dist/agents/doer.md +36 -12
  6. package/dist/agents/harvester.md +11 -0
  7. package/dist/agents/integ-test-runner.md +11 -0
  8. package/dist/agents/kb-reconciler.md +9 -0
  9. package/dist/agents/plan-reviewer.md +110 -22
  10. package/dist/agents/planner.md +125 -37
  11. package/dist/agents/regression-test-runner.md +11 -0
  12. package/dist/agents/reviewer.md +13 -2
  13. package/dist/agents/schemas/plan-reviewer-output.json +37 -0
  14. package/dist/cli/agent-transform.d.ts +83 -2
  15. package/dist/cli/agent-transform.d.ts.map +1 -1
  16. package/dist/cli/agent-transform.js +266 -21
  17. package/dist/cli/agent-transform.js.map +1 -1
  18. package/dist/cli/auth.d.ts.map +1 -1
  19. package/dist/cli/auth.js +28 -9
  20. package/dist/cli/auth.js.map +1 -1
  21. package/dist/cli/config.d.ts +7 -5
  22. package/dist/cli/config.d.ts.map +1 -1
  23. package/dist/cli/config.js +44 -34
  24. package/dist/cli/config.js.map +1 -1
  25. package/dist/cli/install.d.ts +33 -0
  26. package/dist/cli/install.d.ts.map +1 -1
  27. package/dist/cli/install.js +290 -23
  28. package/dist/cli/install.js.map +1 -1
  29. package/dist/cli/kb-directives.d.ts.map +1 -1
  30. package/dist/cli/kb-directives.js +2 -1
  31. package/dist/cli/kb-directives.js.map +1 -1
  32. package/dist/cli/register-member.d.ts.map +1 -1
  33. package/dist/cli/register-member.js +6 -2
  34. package/dist/cli/register-member.js.map +1 -1
  35. package/dist/commands/kb-server.d.ts +3 -0
  36. package/dist/commands/kb-server.d.ts.map +1 -1
  37. package/dist/commands/kb-server.js +43 -3
  38. package/dist/commands/kb-server.js.map +1 -1
  39. package/dist/index.js +3 -3
  40. package/dist/os/linux.d.ts +6 -0
  41. package/dist/os/linux.d.ts.map +1 -1
  42. package/dist/os/linux.js +35 -2
  43. package/dist/os/linux.js.map +1 -1
  44. package/dist/os/os-commands.d.ts +61 -2
  45. package/dist/os/os-commands.d.ts.map +1 -1
  46. package/dist/os/windows-gitbash.d.ts +5 -0
  47. package/dist/os/windows-gitbash.d.ts.map +1 -1
  48. package/dist/os/windows-gitbash.js +15 -0
  49. package/dist/os/windows-gitbash.js.map +1 -1
  50. package/dist/os/windows.d.ts +6 -0
  51. package/dist/os/windows.d.ts.map +1 -1
  52. package/dist/os/windows.js +46 -3
  53. package/dist/os/windows.js.map +1 -1
  54. package/dist/providers/agy.d.ts +115 -6
  55. package/dist/providers/agy.d.ts.map +1 -1
  56. package/dist/providers/agy.js +569 -53
  57. package/dist/providers/agy.js.map +1 -1
  58. package/dist/providers/claude.d.ts +81 -3
  59. package/dist/providers/claude.d.ts.map +1 -1
  60. package/dist/providers/claude.js +344 -10
  61. package/dist/providers/claude.js.map +1 -1
  62. package/dist/providers/codex.d.ts +4 -2
  63. package/dist/providers/codex.d.ts.map +1 -1
  64. package/dist/providers/codex.js +19 -2
  65. package/dist/providers/codex.js.map +1 -1
  66. package/dist/providers/copilot.d.ts +4 -2
  67. package/dist/providers/copilot.d.ts.map +1 -1
  68. package/dist/providers/copilot.js +20 -2
  69. package/dist/providers/copilot.js.map +1 -1
  70. package/dist/providers/none.d.ts +4 -2
  71. package/dist/providers/none.d.ts.map +1 -1
  72. package/dist/providers/none.js +17 -2
  73. package/dist/providers/none.js.map +1 -1
  74. package/dist/providers/opencode.d.ts +3 -1
  75. package/dist/providers/opencode.d.ts.map +1 -1
  76. package/dist/providers/opencode.js +22 -2
  77. package/dist/providers/opencode.js.map +1 -1
  78. package/dist/providers/provider.d.ts +201 -6
  79. package/dist/providers/provider.d.ts.map +1 -1
  80. package/dist/providers/provider.js +56 -0
  81. package/dist/providers/provider.js.map +1 -1
  82. package/dist/services/agy-project.d.ts +102 -0
  83. package/dist/services/agy-project.d.ts.map +1 -0
  84. package/dist/services/agy-project.js +356 -0
  85. package/dist/services/agy-project.js.map +1 -0
  86. package/dist/services/auth-socket.js +4 -4
  87. package/dist/services/auth-web.js +1 -1
  88. package/dist/services/cloud/lifecycle.d.ts.map +1 -1
  89. package/dist/services/cloud/lifecycle.js +33 -4
  90. package/dist/services/cloud/lifecycle.js.map +1 -1
  91. package/dist/services/credential-cleanup.d.ts.map +1 -1
  92. package/dist/services/credential-cleanup.js +35 -17
  93. package/dist/services/credential-cleanup.js.map +1 -1
  94. package/dist/services/exit-drain.d.ts +44 -0
  95. package/dist/services/exit-drain.d.ts.map +1 -0
  96. package/dist/services/exit-drain.js +52 -0
  97. package/dist/services/exit-drain.js.map +1 -0
  98. package/dist/services/github-app.d.ts.map +1 -1
  99. package/dist/services/github-app.js +32 -4
  100. package/dist/services/github-app.js.map +1 -1
  101. package/dist/services/http-transport.d.ts +1 -0
  102. package/dist/services/http-transport.d.ts.map +1 -1
  103. package/dist/services/http-transport.js +48 -1
  104. package/dist/services/http-transport.js.map +1 -1
  105. package/dist/services/knowledge/kb-config.d.ts +42 -0
  106. package/dist/services/knowledge/kb-config.d.ts.map +1 -0
  107. package/dist/services/knowledge/kb-config.js +54 -0
  108. package/dist/services/knowledge/kb-config.js.map +1 -0
  109. package/dist/services/knowledge/kb-providers.d.ts +7 -1
  110. package/dist/services/knowledge/kb-providers.d.ts.map +1 -1
  111. package/dist/services/knowledge/kb-providers.js +191 -17
  112. package/dist/services/knowledge/kb-providers.js.map +1 -1
  113. package/dist/services/knowledge/require-sqlite-project.d.ts +32 -0
  114. package/dist/services/knowledge/require-sqlite-project.d.ts.map +1 -0
  115. package/dist/services/knowledge/require-sqlite-project.js +38 -0
  116. package/dist/services/knowledge/require-sqlite-project.js.map +1 -0
  117. package/dist/services/model-pricing.d.ts.map +1 -1
  118. package/dist/services/model-pricing.js +7 -3
  119. package/dist/services/model-pricing.js.map +1 -1
  120. package/dist/services/secret-token.d.ts +38 -0
  121. package/dist/services/secret-token.d.ts.map +1 -0
  122. package/dist/services/secret-token.js +51 -0
  123. package/dist/services/secret-token.js.map +1 -0
  124. package/dist/services/service-manager/types.d.ts +3 -1
  125. package/dist/services/service-manager/types.d.ts.map +1 -1
  126. package/dist/services/service-manager/windows.d.ts +14 -2
  127. package/dist/services/service-manager/windows.d.ts.map +1 -1
  128. package/dist/services/service-manager/windows.js +65 -7
  129. package/dist/services/service-manager/windows.js.map +1 -1
  130. package/dist/services/ssh.d.ts.map +1 -1
  131. package/dist/services/ssh.js +58 -2
  132. package/dist/services/ssh.js.map +1 -1
  133. package/dist/services/stall/read-log-tail.d.ts.map +1 -1
  134. package/dist/services/stall/read-log-tail.js +20 -10
  135. package/dist/services/stall/read-log-tail.js.map +1 -1
  136. package/dist/services/stall/stall-detector.d.ts +53 -4
  137. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  138. package/dist/services/stall/stall-detector.js +212 -34
  139. package/dist/services/stall/stall-detector.js.map +1 -1
  140. package/dist/services/strategy.d.ts.map +1 -1
  141. package/dist/services/strategy.js +79 -2
  142. package/dist/services/strategy.js.map +1 -1
  143. package/dist/services/substitution-engine.js +2 -2
  144. package/dist/services/substitution-engine.js.map +1 -1
  145. package/dist/services/tool-registry.d.ts.map +1 -1
  146. package/dist/services/tool-registry.js +5 -3
  147. package/dist/services/tool-registry.js.map +1 -1
  148. package/dist/services/vcs/azure-devops.d.ts +66 -1
  149. package/dist/services/vcs/azure-devops.d.ts.map +1 -1
  150. package/dist/services/vcs/azure-devops.js +192 -21
  151. package/dist/services/vcs/azure-devops.js.map +1 -1
  152. package/dist/services/vcs/types.d.ts +1 -1
  153. package/dist/skills/fleet-sprint-cli/SKILL.md +18 -0
  154. package/dist/skills/pm/SKILL.md +1 -1
  155. package/dist/skills/pm/cost.md +0 -3
  156. package/dist/skills/pm/fleet-addendum.md +2 -2
  157. package/dist/tools/check-status.d.ts +7 -4
  158. package/dist/tools/check-status.d.ts.map +1 -1
  159. package/dist/tools/check-status.js +2 -0
  160. package/dist/tools/check-status.js.map +1 -1
  161. package/dist/tools/compose-permissions.d.ts +6 -0
  162. package/dist/tools/compose-permissions.d.ts.map +1 -1
  163. package/dist/tools/compose-permissions.js +182 -34
  164. package/dist/tools/compose-permissions.js.map +1 -1
  165. package/dist/tools/credential-store-set.js +1 -1
  166. package/dist/tools/execute-command.d.ts.map +1 -1
  167. package/dist/tools/execute-command.js +31 -20
  168. package/dist/tools/execute-command.js.map +1 -1
  169. package/dist/tools/execute-prompt.d.ts +15 -2
  170. package/dist/tools/execute-prompt.d.ts.map +1 -1
  171. package/dist/tools/execute-prompt.js +1196 -892
  172. package/dist/tools/execute-prompt.js.map +1 -1
  173. package/dist/tools/kb-capture.d.ts +2 -2
  174. package/dist/tools/kb-capture.d.ts.map +1 -1
  175. package/dist/tools/kb-capture.js +29 -5
  176. package/dist/tools/kb-capture.js.map +1 -1
  177. package/dist/tools/kb-export.d.ts +2 -2
  178. package/dist/tools/kb-export.d.ts.map +1 -1
  179. package/dist/tools/kb-export.js +3 -28
  180. package/dist/tools/kb-export.js.map +1 -1
  181. package/dist/tools/kb-feedback.d.ts.map +1 -1
  182. package/dist/tools/kb-feedback.js +3 -1
  183. package/dist/tools/kb-feedback.js.map +1 -1
  184. package/dist/tools/kb-freshness-sweep.d.ts.map +1 -1
  185. package/dist/tools/kb-freshness-sweep.js +3 -1
  186. package/dist/tools/kb-freshness-sweep.js.map +1 -1
  187. package/dist/tools/kb-import.d.ts.map +1 -1
  188. package/dist/tools/kb-import.js +2 -1
  189. package/dist/tools/kb-import.js.map +1 -1
  190. package/dist/tools/kb-list.d.ts.map +1 -1
  191. package/dist/tools/kb-list.js +3 -1
  192. package/dist/tools/kb-list.js.map +1 -1
  193. package/dist/tools/kb-query.d.ts +2 -2
  194. package/dist/tools/kb-reconcile-prefilter.d.ts.map +1 -1
  195. package/dist/tools/kb-reconcile-prefilter.js +3 -1
  196. package/dist/tools/kb-reconcile-prefilter.js.map +1 -1
  197. package/dist/tools/kb-resolve-contradiction.d.ts.map +1 -1
  198. package/dist/tools/kb-resolve-contradiction.js +3 -1
  199. package/dist/tools/kb-resolve-contradiction.js.map +1 -1
  200. package/dist/tools/kb-setup.d.ts.map +1 -1
  201. package/dist/tools/kb-setup.js +125 -20
  202. package/dist/tools/kb-setup.js.map +1 -1
  203. package/dist/tools/kb-stats.d.ts.map +1 -1
  204. package/dist/tools/kb-stats.js +64 -43
  205. package/dist/tools/kb-stats.js.map +1 -1
  206. package/dist/tools/list-members.d.ts +2 -2
  207. package/dist/tools/list-members.d.ts.map +1 -1
  208. package/dist/tools/list-members.js +1 -0
  209. package/dist/tools/list-members.js.map +1 -1
  210. package/dist/tools/member-detail.d.ts +2 -2
  211. package/dist/tools/member-detail.d.ts.map +1 -1
  212. package/dist/tools/member-detail.js +17 -0
  213. package/dist/tools/member-detail.js.map +1 -1
  214. package/dist/tools/member-reservation.d.ts +58 -1
  215. package/dist/tools/member-reservation.d.ts.map +1 -1
  216. package/dist/tools/member-reservation.js +61 -20
  217. package/dist/tools/member-reservation.js.map +1 -1
  218. package/dist/tools/provision-auth.d.ts +80 -1
  219. package/dist/tools/provision-auth.d.ts.map +1 -1
  220. package/dist/tools/provision-auth.js +142 -54
  221. package/dist/tools/provision-auth.js.map +1 -1
  222. package/dist/tools/provision-vcs-auth.d.ts +91 -1
  223. package/dist/tools/provision-vcs-auth.d.ts.map +1 -1
  224. package/dist/tools/provision-vcs-auth.js +209 -49
  225. package/dist/tools/provision-vcs-auth.js.map +1 -1
  226. package/dist/tools/register-member.d.ts +12 -9
  227. package/dist/tools/register-member.d.ts.map +1 -1
  228. package/dist/tools/register-member.js +99 -12
  229. package/dist/tools/register-member.js.map +1 -1
  230. package/dist/tools/remove-member.d.ts.map +1 -1
  231. package/dist/tools/remove-member.js +27 -2
  232. package/dist/tools/remove-member.js.map +1 -1
  233. package/dist/tools/send-email.d.ts +2 -2
  234. package/dist/tools/setup-git-app.d.ts.map +1 -1
  235. package/dist/tools/setup-git-app.js +11 -7
  236. package/dist/tools/setup-git-app.js.map +1 -1
  237. package/dist/tools/shutdown-server.d.ts +2 -0
  238. package/dist/tools/shutdown-server.d.ts.map +1 -1
  239. package/dist/tools/shutdown-server.js +23 -1
  240. package/dist/tools/shutdown-server.js.map +1 -1
  241. package/dist/tools/update-member.d.ts +12 -9
  242. package/dist/tools/update-member.d.ts.map +1 -1
  243. package/dist/tools/update-member.js +43 -11
  244. package/dist/tools/update-member.js.map +1 -1
  245. package/dist/tools/vcs-credential-exec.d.ts +127 -0
  246. package/dist/tools/vcs-credential-exec.d.ts.map +1 -0
  247. package/dist/tools/vcs-credential-exec.js +197 -0
  248. package/dist/tools/vcs-credential-exec.js.map +1 -0
  249. package/dist/types.d.ts +13 -0
  250. package/dist/types.d.ts.map +1 -1
  251. package/dist/utils/log-helpers.d.ts.map +1 -1
  252. package/dist/utils/log-helpers.js +2 -2
  253. package/dist/utils/log-helpers.js.map +1 -1
  254. package/dist/utils/prompt-errors.d.ts.map +1 -1
  255. package/dist/utils/prompt-errors.js +7 -1
  256. package/dist/utils/prompt-errors.js.map +1 -1
  257. package/dist/utils/shell-escape.d.ts +16 -0
  258. package/dist/utils/shell-escape.d.ts.map +1 -1
  259. package/dist/utils/shell-escape.js +22 -2
  260. package/dist/utils/shell-escape.js.map +1 -1
  261. package/dist/utils/vcs-provider-detect.d.ts +65 -0
  262. package/dist/utils/vcs-provider-detect.d.ts.map +1 -0
  263. package/dist/utils/vcs-provider-detect.js +109 -0
  264. package/dist/utils/vcs-provider-detect.js.map +1 -0
  265. package/dist/utils/workspace-trust.d.ts +20 -17
  266. package/dist/utils/workspace-trust.d.ts.map +1 -1
  267. package/dist/utils/workspace-trust.js +87 -1
  268. package/dist/utils/workspace-trust.js.map +1 -1
  269. package/dist/workflows/auto-sprint.js +176 -15
  270. package/package.json +6 -4
  271. package/packages/apra-fleet-client/src/client/api.mjs +319 -17
  272. package/packages/apra-fleet-client/src/client/errors.mjs +6 -2
  273. package/packages/apra-fleet-se/apra-pm/agents/_shared/GRAPH-SEMANTICS.md +10 -2
  274. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +25 -0
  275. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +11 -0
  276. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +37 -2
  277. package/packages/apra-fleet-se/apra-pm/agents/doer.md +36 -12
  278. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +11 -0
  279. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +11 -0
  280. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +9 -0
  281. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +110 -22
  282. package/packages/apra-fleet-se/apra-pm/agents/planner.md +125 -37
  283. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +11 -0
  284. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +13 -2
  285. package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-output.json +37 -0
  286. package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +1 -1
  287. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +0 -3
  288. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +2 -2
  289. package/packages/apra-fleet-se/bin/cli.mjs +149 -1
  290. package/packages/apra-fleet-se/bin/serve.mjs +78 -4
  291. package/packages/apra-fleet-se/fleet-sprint/abort.mjs +481 -0
  292. package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +491 -0
  293. package/packages/apra-fleet-se/fleet-sprint/beads-identity-check.mjs +282 -0
  294. package/packages/apra-fleet-se/fleet-sprint/beads-identity.mjs +208 -0
  295. package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +638 -0
  296. package/packages/apra-fleet-se/fleet-sprint/beads-transitions.mjs +301 -0
  297. package/packages/apra-fleet-se/fleet-sprint/branch-ensure.mjs +96 -0
  298. package/packages/apra-fleet-se/fleet-sprint/conflict-ladder.mjs +8 -0
  299. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +61 -14
  300. package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +516 -0
  301. package/packages/apra-fleet-se/fleet-sprint/dispatch-failure.mjs +184 -0
  302. package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +1121 -0
  303. package/packages/apra-fleet-se/fleet-sprint/dispatch-safety-guard.mjs +216 -4
  304. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +1 -1
  305. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +276 -0
  306. package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +1 -1
  307. package/packages/apra-fleet-se/fleet-sprint/docs/run-sprint-cycle-prelude-decision.md +215 -0
  308. package/packages/apra-fleet-se/fleet-sprint/dolt-literal-guard.mjs +56 -1
  309. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +996 -32
  310. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +267 -0
  311. package/packages/apra-fleet-se/fleet-sprint/explicit-id-create-guard.mjs +501 -0
  312. package/packages/apra-fleet-se/fleet-sprint/fatal-diagnostics.mjs +134 -0
  313. package/packages/apra-fleet-se/fleet-sprint/full-db-fetch-guard.mjs +102 -0
  314. package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +556 -0
  315. package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +495 -0
  316. package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +564 -0
  317. package/packages/apra-fleet-se/fleet-sprint/inline-ladder-guard.mjs +216 -0
  318. package/packages/apra-fleet-se/fleet-sprint/kb.mjs +728 -0
  319. package/packages/apra-fleet-se/fleet-sprint/mcp-result.mjs +75 -0
  320. package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +252 -0
  321. package/packages/apra-fleet-se/fleet-sprint/member-sync.mjs +581 -0
  322. package/packages/apra-fleet-se/fleet-sprint/member-target.mjs +93 -0
  323. package/packages/apra-fleet-se/fleet-sprint/newtask-text.mjs +266 -0
  324. package/packages/apra-fleet-se/fleet-sprint/parent-notes-staleness.mjs +201 -0
  325. package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +136 -0
  326. package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +822 -0
  327. package/packages/apra-fleet-se/fleet-sprint/phases/ensure-sprint-branch.mjs +294 -0
  328. package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +403 -0
  329. package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +180 -0
  330. package/packages/apra-fleet-se/fleet-sprint/phases/integ-test.mjs +358 -0
  331. package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +390 -0
  332. package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +323 -0
  333. package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +232 -0
  334. package/packages/apra-fleet-se/fleet-sprint/phases/regression-test.mjs +174 -0
  335. package/packages/apra-fleet-se/fleet-sprint/phases/replan.mjs +197 -0
  336. package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +305 -0
  337. package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +559 -0
  338. package/packages/apra-fleet-se/fleet-sprint/role-policies.mjs +1416 -0
  339. package/packages/apra-fleet-se/fleet-sprint/round-session.mjs +100 -0
  340. package/packages/apra-fleet-se/fleet-sprint/runner.js +1467 -9798
  341. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +17 -12
  342. package/packages/apra-fleet-se/fleet-sprint/shell-command-guard.mjs +304 -0
  343. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +18 -0
  344. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +21 -2
  345. package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +454 -0
  346. package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +239 -0
  347. package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +163 -0
  348. package/packages/apra-fleet-se/fleet-sprint/unbracketed-push-guard.mjs +234 -0
  349. package/packages/apra-fleet-se/fleet-sprint/usage-limit-controller.mjs +211 -0
  350. package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +1279 -0
  351. package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +153 -19
  352. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +71 -21
  353. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +28 -0
  354. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +131 -0
  355. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +140 -16
  356. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/shell-helpers.mjs +1 -0
  357. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +77 -2
  358. package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +559 -0
  359. package/packages/apra-fleet-se/package.json +1 -1
  360. package/packages/apra-fleet-workflow/src/viewer/index.mjs +17 -6
  361. package/packages/apra-fleet-workflow/src/workflow/index.mjs +49 -7
  362. package/skills/fleet/SKILL.md +8 -8
  363. package/skills/fleet/auth-azdevops.md +14 -3
  364. package/skills/fleet/auth-bitbucket.md +2 -2
  365. package/skills/fleet/auth-github.md +5 -4
  366. package/skills/fleet/onboarding.md +3 -3
  367. package/skills/fleet/permissions.md +5 -1
  368. package/skills/fleet/profiles/node.json +1 -1
  369. package/skills/fleet/troubleshooting.md +3 -3
  370. package/version.json +1 -1
@@ -0,0 +1,516 @@
1
+ // Coordination clients for fleet-sprint: the supervisor-owned global dolt
2
+ // push mutex, the global child-id allocator, and the fleet server's own
3
+ // per-member reservation ledger (apra-fleet-3swo.4.3). Moved verbatim out of
4
+ // runner.js -- runner.js re-exports every symbol it previously exported from
5
+ // this region, so existing importers of fleet-sprint/runner.js resolve
6
+ // unchanged.
7
+ //
8
+ // Every client here speaks a coordination surface that is EXTERNAL to this
9
+ // process (a supervisor HTTP route, the fleet MCP server's own tools, or
10
+ // both) and is implemented INLINE rather than imported from its
11
+ // server-side counterpart, because runner.js (and this module alongside it)
12
+ // is copied verbatim next to the shipped bundle and loaded via
13
+ // engine.executeFile(), never bundled -- a cross-package relative import
14
+ // would not resolve in the shipped layout.
15
+ //
16
+ // `sprintId`/`sprint_id` on every client here is the SAME opaque sprint-
17
+ // identity token (derived in runner.js from the sprint's branch name, see
18
+ // sprintMutexId) -- it is passed through verbatim by every client below,
19
+ // never re-derived, reformatted, prefixed or namespaced, so a dispatch and
20
+ // the reservation/mutex/allocator calls that gate it always agree on who
21
+ // "this sprint" is.
22
+
23
+ import { resultText } from './mcp-result.mjs';
24
+ import { MemberReservationResumeError } from './errors.mjs';
25
+
26
+ /**
27
+ * Child-side HTTP client for the supervisor-owned global dolt push mutex
28
+ * (src/supervisor/dolt-mutex.mjs). The mutex object lives in the always-on
29
+ * supervisor process, but each detached sprint child runs in its OWN process
30
+ * and can only reach it over HTTP. Speaks the routes
31
+ * registerDoltMutexRoutes() exposes:
32
+ *
33
+ * POST {serviceUrl}/api/dolt-push-mutex/{sprintId}/acquire body { pid }
34
+ * POST {serviceUrl}/api/dolt-push-mutex/{sprintId}/release body { token }
35
+ *
36
+ * The acquire route long-polls -- it does not answer until this sprint
37
+ * genuinely owns the mutex (FIFO after every earlier waiter) -- so a resolved
38
+ * acquire() means this child holds it and no sibling sprint is pushing.
39
+ *
40
+ * Implemented INLINE rather than imported from src/supervisor/dolt-mutex.mjs
41
+ * because runner.js is copied verbatim next to the bundle and loaded via
42
+ * engine.executeFile(), never bundled -- a cross-package relative import would
43
+ * not resolve in the shipped layout. The { acquire, release } surface is
44
+ * exactly what doltPushAfter() calls.
45
+ *
46
+ * @param {{ serviceUrl: string, sprintId: string, fetch?: typeof fetch, log?: Function }} opts
47
+ * @returns {{ acquire: (sprintId: string, o?: { pid?: number|null }) => Promise<{ token: string|null }>, release: (token: string|null) => Promise<boolean> }}
48
+ */
49
+ export function createHttpDoltPushMutexClient(opts = {}) {
50
+ const base = String(opts.serviceUrl || '').replace(/\/+$/, '');
51
+ if (!base) throw new Error('createHttpDoltPushMutexClient requires a serviceUrl');
52
+ const boundSprintId = opts.sprintId;
53
+ const fetchImpl = opts.fetch ?? globalThis.fetch;
54
+ if (typeof fetchImpl !== 'function') {
55
+ throw new Error('createHttpDoltPushMutexClient requires a fetch implementation (Node >=18 global fetch or an injected one)');
56
+ }
57
+ const log = opts.log ?? (() => {});
58
+ const routeFor = (sprintId, action) =>
59
+ `${base}/api/dolt-push-mutex/${encodeURIComponent(sprintId)}/${action}`;
60
+
61
+ async function postJson(url, body) {
62
+ const res = await fetchImpl(url, {
63
+ method: 'POST',
64
+ headers: { 'content-type': 'application/json' },
65
+ body: JSON.stringify(body ?? {}),
66
+ });
67
+ if (!res || !res.ok) {
68
+ const status = res ? res.status : 'no-response';
69
+ throw new Error(`[dolt-mutex] ${url} returned HTTP ${status}`);
70
+ }
71
+ return res.json();
72
+ }
73
+
74
+ return {
75
+ async acquire(sprintId, o = {}) {
76
+ const id = sprintId || boundSprintId;
77
+ if (!id) throw new Error('[dolt-mutex] acquire requires a sprintId');
78
+ const payload = await postJson(routeFor(id, 'acquire'), { pid: o.pid ?? null });
79
+ return { token: payload.token ?? null, sprintId: payload.sprintId, expiresAt: payload.expiresAt };
80
+ },
81
+ async release(token) {
82
+ if (token == null) return true;
83
+ const id = boundSprintId;
84
+ if (!id) throw new Error('[dolt-mutex] release requires a bound sprintId');
85
+ try {
86
+ const payload = await postJson(routeFor(id, 'release'), { token });
87
+ return Boolean(payload.released);
88
+ } catch (err) {
89
+ // Non-fatal: the holder's lease expiry will reclaim the mutex
90
+ // even if this release never lands. Surface it for diagnostics.
91
+ log(`[dolt-mutex] release failed (non-fatal; lease will expire): ${err.message}`);
92
+ return false;
93
+ }
94
+ },
95
+ // Lease renewal (docs/dolt-sync-redesign.md Part 3.4): doltPushAfter()
96
+ // renews on an interval while it holds the mutex, so a legitimately
97
+ // long hold (push + reconcile + settle) is never force-evicted by the
98
+ // supervisor's 60s lease expiry while this sprint is still pushing.
99
+ async renew(token) {
100
+ if (token == null) return false;
101
+ const id = boundSprintId;
102
+ if (!id) throw new Error('[dolt-mutex] renew requires a bound sprintId');
103
+ try {
104
+ const payload = await postJson(routeFor(id, 'renew'), { token });
105
+ return Boolean(payload.renewed);
106
+ } catch (err) {
107
+ log(`[dolt-mutex] renew failed (non-fatal; the lease may expire): ${err.message}`);
108
+ return false;
109
+ }
110
+ },
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Child-side HTTP client for the supervisor-owned global child-id allocator
116
+ * (src/supervisor/id-allocator.mjs), used by the orchestrator's bead-creation
117
+ * path. Without a single minting authority, two sprints that each `bd create
118
+ * --parent X` in their own dolt clone independently derive the SAME next child
119
+ * id and their D-pushes hard-conflict; with it, each creator gets an EXPLICIT
120
+ * distinct id passed to `bd create --id <childId>`, so the creates target
121
+ * different rows. Speaks the routes registerIdAllocatorRoutes() exposes:
122
+ *
123
+ * POST {serviceUrl}/api/child-id-allocator/{parentId}/allocate body { pid, sprintId, floor }
124
+ * POST {serviceUrl}/api/child-id-allocator/confirm body { token }
125
+ * POST {serviceUrl}/api/child-id-allocator/release body { token }
126
+ *
127
+ * Implemented INLINE for the same shipped-layout reason as the dolt push mutex
128
+ * client above. The { allocate, confirm, release } surface is exactly what the
129
+ * bead-creation path calls.
130
+ *
131
+ * @param {{ serviceUrl: string, sprintId?: string, fetch?: typeof fetch, log?: Function }} opts
132
+ * @returns {{ allocate: Function, confirm: Function, release: Function }}
133
+ */
134
+ export function createHttpChildIdAllocatorClient(opts = {}) {
135
+ const base = String(opts.serviceUrl || '').replace(/\/+$/, '');
136
+ if (!base) throw new Error('createHttpChildIdAllocatorClient requires a serviceUrl');
137
+ const boundSprintId = opts.sprintId;
138
+ const fetchImpl = opts.fetch ?? globalThis.fetch;
139
+ if (typeof fetchImpl !== 'function') {
140
+ throw new Error('createHttpChildIdAllocatorClient requires a fetch implementation (Node >=18 global fetch or an injected one)');
141
+ }
142
+ const log = opts.log ?? (() => {});
143
+
144
+ async function postJson(url, body) {
145
+ const res = await fetchImpl(url, {
146
+ method: 'POST',
147
+ headers: { 'content-type': 'application/json' },
148
+ body: JSON.stringify(body ?? {}),
149
+ });
150
+ if (!res || !res.ok) {
151
+ const status = res ? res.status : 'no-response';
152
+ throw new Error(`[id-allocator] ${url} returned HTTP ${status}`);
153
+ }
154
+ return res.json();
155
+ }
156
+
157
+ return {
158
+ async allocate(parentId, o = {}) {
159
+ if (!parentId) throw new Error('[id-allocator] allocate requires a parentId');
160
+ const url = `${base}/api/child-id-allocator/${encodeURIComponent(parentId)}/allocate`;
161
+ const payload = await postJson(url, {
162
+ pid: o.pid ?? null,
163
+ sprintId: o.sprintId ?? boundSprintId ?? null,
164
+ floor: o.floor,
165
+ });
166
+ return { childId: payload.childId ?? null, seq: payload.seq, token: payload.token ?? null, expiresAt: payload.expiresAt };
167
+ },
168
+ async confirm(token) {
169
+ if (token == null) return true;
170
+ try {
171
+ const payload = await postJson(`${base}/api/child-id-allocator/confirm`, { token });
172
+ return Boolean(payload.confirmed);
173
+ } catch (err) {
174
+ // Non-fatal: the reservation's lease expiry reclaims it even if
175
+ // this confirm never lands. Surface it for diagnostics.
176
+ log(`[id-allocator] confirm failed (non-fatal; lease will expire): ${err.message}`);
177
+ return false;
178
+ }
179
+ },
180
+ async release(token) {
181
+ if (token == null) return true;
182
+ try {
183
+ const payload = await postJson(`${base}/api/child-id-allocator/release`, { token });
184
+ return Boolean(payload.released);
185
+ } catch (err) {
186
+ log(`[id-allocator] release failed (non-fatal; lease will expire): ${err.message}`);
187
+ return false;
188
+ }
189
+ },
190
+ };
191
+ }
192
+
193
+ /**
194
+ * Shared MCP tool-result-to-JSON parser for the two fleet-MCP-hosted
195
+ * coordination clients below. Tool handlers return a JSON STRING wrapped in
196
+ * the standard content[] envelope, so both clients need the same
197
+ * extract-then-parse step.
198
+ * @param {any} result
199
+ * @param {string} label
200
+ * @returns {object}
201
+ */
202
+ function parseCoordinationToolResult(result, label) {
203
+ let text = result;
204
+ if (typeof text !== 'string') {
205
+ text = (result && Array.isArray(result.content) && result.content[0] && typeof result.content[0].text === 'string')
206
+ ? result.content[0].text
207
+ : '';
208
+ }
209
+ let payload;
210
+ try {
211
+ payload = JSON.parse(text);
212
+ } catch {
213
+ throw new Error(`${label} returned a non-JSON response: ${String(text).slice(0, 200) || '(empty)'}`);
214
+ }
215
+ if (payload && payload.error) throw new Error(`${label} error: ${payload.error}`);
216
+ return payload ?? {};
217
+ }
218
+
219
+ /**
220
+ * MCP-transport counterpart to createHttpDoltPushMutexClient above, for the
221
+ * SUPERVISOR-LESS topology: a standalone/detached-binary CLI launch has no
222
+ * supervisor to reach, so `--service-url` is absent and the HTTP client cannot
223
+ * be built, but the launcher always holds a connected MCP client to the shared
224
+ * fleet HTTP singleton, making the fleet server's own `dolt_push_mutex` tool
225
+ * (src/tools/dolt-push-mutex.ts) the reachable coordination point.
226
+ *
227
+ * Ticketed acquire, not long-poll: an MCP tool call cannot block indefinitely,
228
+ * so `acquire` waits a bounded slice per call and then RE-POLLS the same
229
+ * ticket. The server keeps the waiter enqueued across polls, preserving FIFO
230
+ * order (a cancel-and-retry loop would send every timed-out waiter to the back
231
+ * of the queue). The caller's real pid is threaded through so a crashed holder
232
+ * is reclaimed by the server's dead-pid probe rather than wedging the mutex.
233
+ *
234
+ * Implemented INLINE for the same shipped-layout reason as the HTTP clients
235
+ * above.
236
+ *
237
+ * @param {{ callTool: (name: string, args: object) => Promise<any>, sprintId?: string, waitMs?: number, timeoutMs?: number, log?: Function }} opts
238
+ * @returns {{ acquire: Function, release: Function }}
239
+ */
240
+ export function createMcpDoltPushMutexClient(opts = {}) {
241
+ const { callTool, sprintId: boundSprintId, log = () => {} } = opts;
242
+ if (typeof callTool !== 'function') throw new Error('createMcpDoltPushMutexClient requires a callTool function');
243
+ const waitMs = Number.isFinite(opts.waitMs) && opts.waitMs > 0 ? opts.waitMs : 5000;
244
+ // Overall ceiling on how long a single acquire may keep re-polling before
245
+ // giving up (a wedged peer is bounded by the server-side lease anyway).
246
+ const timeoutMs = Number.isFinite(opts.timeoutMs) && opts.timeoutMs > 0 ? opts.timeoutMs : 15 * 60 * 1000;
247
+
248
+ async function call(args) {
249
+ return parseCoordinationToolResult(await callTool('dolt_push_mutex', args), '[dolt-mutex/mcp]');
250
+ }
251
+
252
+ return {
253
+ async acquire(sprintId, o = {}) {
254
+ const id = sprintId || boundSprintId;
255
+ if (!id) throw new Error('[dolt-mutex/mcp] acquire requires a sprintId');
256
+ const deadline = Date.now() + timeoutMs;
257
+ let payload = await call({ action: 'acquire', sprint_id: id, pid: o.pid ?? undefined, wait_ms: waitMs });
258
+ while (!payload.granted) {
259
+ if (Date.now() >= deadline) {
260
+ try { await call({ action: 'cancel', ticket: payload.ticket }); } catch { /* best effort */ }
261
+ throw new Error(`[dolt-mutex/mcp] timed out after ${timeoutMs} ms waiting for the push mutex (sprint '${id}')`);
262
+ }
263
+ log(`[dolt-mutex/mcp] waiting for the global push mutex (sprint '${id}', ticket ${payload.ticket})`);
264
+ payload = await call({ action: 'poll', ticket: payload.ticket, wait_ms: waitMs });
265
+ }
266
+ return { token: payload.token ?? null, sprintId: id, expiresAt: payload.expiresAt };
267
+ },
268
+ async release(token) {
269
+ if (token == null) return true;
270
+ try {
271
+ const payload = await call({ action: 'release', token });
272
+ return Boolean(payload.released);
273
+ } catch (err) {
274
+ // Non-fatal: the holder's lease expiry reclaims the mutex even
275
+ // if this release never lands (same posture as the HTTP client).
276
+ log(`[dolt-mutex/mcp] release failed (non-fatal; lease will expire): ${err.message}`);
277
+ return false;
278
+ }
279
+ },
280
+ // Same lease-renewal contract as the HTTP client above (design doc
281
+ // Part 3.4); the fleet tool exposes action 'renew'.
282
+ async renew(token) {
283
+ if (token == null) return false;
284
+ try {
285
+ const payload = await call({ action: 'renew', token });
286
+ return Boolean(payload.renewed);
287
+ } catch (err) {
288
+ log(`[dolt-mutex/mcp] renew failed (non-fatal; the lease may expire): ${err.message}`);
289
+ return false;
290
+ }
291
+ },
292
+ };
293
+ }
294
+
295
+ /**
296
+ * MCP-transport counterpart to createHttpChildIdAllocatorClient above, for the
297
+ * SUPERVISOR-LESS topology. Speaks the fleet server's own
298
+ * `child_id_allocator` tool (src/tools/child-id-allocator.ts); same rationale,
299
+ * same inline-implementation constraint, and the same { allocate, confirm,
300
+ * release } surface the bead-creation path already calls.
301
+ *
302
+ * @param {{ callTool: (name: string, args: object) => Promise<any>, sprintId?: string, log?: Function }} opts
303
+ * @returns {{ allocate: Function, confirm: Function, release: Function }}
304
+ */
305
+ export function createMcpChildIdAllocatorClient(opts = {}) {
306
+ const { callTool, sprintId: boundSprintId, log = () => {} } = opts;
307
+ if (typeof callTool !== 'function') throw new Error('createMcpChildIdAllocatorClient requires a callTool function');
308
+
309
+ async function call(args) {
310
+ return parseCoordinationToolResult(await callTool('child_id_allocator', args), '[id-allocator/mcp]');
311
+ }
312
+
313
+ return {
314
+ async allocate(parentId, o = {}) {
315
+ if (!parentId) throw new Error('[id-allocator/mcp] allocate requires a parentId');
316
+ const payload = await call({
317
+ action: 'allocate',
318
+ parent_id: parentId,
319
+ pid: o.pid ?? undefined,
320
+ sprint_id: o.sprintId ?? boundSprintId ?? undefined,
321
+ floor: o.floor,
322
+ });
323
+ return { childId: payload.childId ?? null, seq: payload.seq, token: payload.token ?? null, expiresAt: payload.expiresAt };
324
+ },
325
+ async confirm(token) {
326
+ if (token == null) return true;
327
+ try {
328
+ const payload = await call({ action: 'confirm', token });
329
+ return Boolean(payload.confirmed);
330
+ } catch (err) {
331
+ log(`[id-allocator/mcp] confirm failed (non-fatal; lease will expire): ${err.message}`);
332
+ return false;
333
+ }
334
+ },
335
+ async release(token) {
336
+ if (token == null) return true;
337
+ try {
338
+ const payload = await call({ action: 'release', token });
339
+ return Boolean(payload.released);
340
+ } catch (err) {
341
+ log(`[id-allocator/mcp] release failed (non-fatal; lease will expire): ${err.message}`);
342
+ return false;
343
+ }
344
+ },
345
+ };
346
+ }
347
+
348
+ /**
349
+ * Reserves and releases every sprint member against the fleet server's OWN
350
+ * per-member reservation record (the `member_reservation` tool), so that a
351
+ * sprint launched directly from the CLI -- never routed through the
352
+ * supervisor, and so absent from its ledger -- is still visible to
353
+ * execute_prompt's dispatch-time reservedBy check and to the supervisor's
354
+ * overlap guard.
355
+ *
356
+ * `callTool` is injected (the caller's MCP client) so this stays
357
+ * transport-agnostic and unit-testable without a live fleet server.
358
+ * Deliberately NOT built on the supervisor's HTTP routes, unlike the
359
+ * dolt-mutex/id-allocator clients above: `member_reservation` lives on the
360
+ * fleet MCP server every launch path already connects to, whereas the
361
+ * supervisor is optional and unwired for direct CLI launches.
362
+ *
363
+ * `sprintId` should be the SAME opaque identity used for the dolt push mutex
364
+ * and child-id allocator -- opaque and target-agnostic, with no assumption
365
+ * about which repo the sprint develops.
366
+ *
367
+ * Reserve/release are BEST-EFFORT per member: a failure (transport error, or
368
+ * the tool's own "already reserved by X" rejection) is logged and does NOT
369
+ * throw. That is safe because execute_prompt independently rejects any
370
+ * dispatch to a member this sprint failed to reserve, so an unreserved member
371
+ * fails loudly at its first dispatch rather than silently interleaving with
372
+ * another sprint.
373
+ *
374
+ * @param {{ callTool: (name: string, args: object) => Promise<any>, members?: string[], sprintId?: string, log?: Function }} opts
375
+ * @returns {{ reserveAll: () => Promise<void>, releaseAll: () => Promise<void> }}
376
+ */
377
+ // (apra-fleet-3swo.7.5) Classify a `member_reservation` result from its
378
+ // STRUCTURED half, not from its prose.
379
+ //
380
+ // The tool used to be readable only as text, and callFor() below discriminated
381
+ // a rejection by the leading '[-]' marker src/tools/member-reservation.ts
382
+ // prefixes onto its failure summaries. That coupled a load-bearing control-flow
383
+ // decision -- "did this sprint actually get the member?", which reReserveForResume
384
+ // turns into a hard resume failure -- to a human-facing wording detail, exactly
385
+ // the class of dependency that silently inverted once the provisioning tools
386
+ // retired their own status prefixes.
387
+ //
388
+ // member_reservation now returns `structuredContent.{ ok, outcome }`
389
+ // (MemberReservationFields / MemberReservationOutcome in
390
+ // src/tools/member-reservation.ts, mirrored by MemberReservationStructured in
391
+ // packages/apra-fleet-client/src/client/api.mjs), where `ok` already folds in
392
+ // the server's own authoritative list of failing outcomes
393
+ // (already_reserved_by_other, invalid_input, member_not_found, failed). Read
394
+ // THAT when present.
395
+ //
396
+ // The legacy prose/isError heuristic is kept ONLY for a result that carries no
397
+ // structuredContent at all -- a test double that mocks the bare string or
398
+ // `{ content }` shape. This mirrors provisionOutcome() in vcs-auth.mjs
399
+ // field-for-field so the two coordination surfaces cannot drift on what
400
+ // "the server said no" means. `outcome` is null on that fallback path,
401
+ // because there is no structured discriminator to report.
402
+ /**
403
+ * @param {unknown} result an MCP tool result from member_reservation
404
+ * @param {string} text the same result rendered as text, for the fallback only
405
+ * @returns {{ ok: boolean, outcome: string|null }}
406
+ */
407
+ function reservationOutcome(result, text) {
408
+ const structured = result && result.structuredContent;
409
+ if (structured && typeof structured.ok === 'boolean') {
410
+ return { ok: structured.ok, outcome: typeof structured.outcome === 'string' ? structured.outcome : null };
411
+ }
412
+ return {
413
+ ok: !((result && result.isError) || String(text == null ? '' : text).startsWith('[-]')),
414
+ outcome: null,
415
+ };
416
+ }
417
+
418
+ export function createMemberReservationClient(opts = {}) {
419
+ const { callTool, members = [], sprintId, log = () => {} } = opts;
420
+ const active = typeof callTool === 'function' && typeof sprintId === 'string' && sprintId.length > 0 && members.length > 0;
421
+
422
+ // Returns { ok, text } rather than throwing so BOTH the best-effort callers
423
+ // (reserveAll/releaseAll, which ignore the outcome) and the owner-checked
424
+ // resume caller (reReserveForResume, which MUST know per-member whether the
425
+ // reserve was granted or rejected) can share one call path. `ok` is false
426
+ // on a tool rejection ("already reserved by X") OR a transport throw; the
427
+ // caller decides what a failure means for its own contract.
428
+ async function callFor(action, member) {
429
+ try {
430
+ const result = await callTool('member_reservation', { member_name: member, action, sprint_id: sprintId });
431
+ const text = resultText(result);
432
+ const { ok, outcome } = reservationOutcome(result, text);
433
+ if (!ok) {
434
+ log(`[member-reservation] ${action} rejected for member '${member}'${outcome ? ` (${outcome})` : ''}: ${text || '(no detail)'}`);
435
+ return { ok: false, text };
436
+ }
437
+ return { ok: true, text };
438
+ } catch (err) {
439
+ log(`[member-reservation] ${action} failed for member '${member}' (non-fatal; execute_prompt's dispatch-time reservedBy check still applies): ${err.message}`);
440
+ return { ok: false, text: err.message };
441
+ }
442
+ }
443
+
444
+ async function releaseAll() {
445
+ if (!active) return;
446
+ for (const member of members) await callFor('release', member);
447
+ }
448
+
449
+ return {
450
+ async reserveAll() {
451
+ if (!active) return;
452
+ for (const member of members) await callFor('reserve', member);
453
+ },
454
+ releaseAll,
455
+
456
+ // (apra-fleet-p2to.4.2) Pause hand-back: release EVERY member so a
457
+ // different sprint may claim it while this one is parked at a
458
+ // cooperative pause. Best-effort per member, exactly like releaseAll()
459
+ // -- a pause must never fail on a release hiccup, and execute_prompt's
460
+ // dispatch-time reservedBy check still fails loudly on any member this
461
+ // sprint later dispatches to without holding.
462
+ //
463
+ // (apra-fleet-p2to.4.4.1) releaseForPause() is intentionally the SAME
464
+ // operation as releaseAll() -- both release every member,
465
+ // best-effort, with no distinct behavior of their own -- so this
466
+ // calls straight through to releaseAll() rather than keeping a
467
+ // byte-identical second copy of the loop to drift out of sync. The
468
+ // two names stay separate call sites (not aliased) because they mean
469
+ // different things to a caller even though today they do the same
470
+ // work: this is intended to change independently if a pause hand-back
471
+ // ever needs behavior releaseAll() should not have (e.g. skipping a
472
+ // member expected back imminently).
473
+ releaseForPause: releaseAll,
474
+
475
+ // (apra-fleet-p2to.4.2) Resume re-acquire, OWNER-CHECKED: re-reserve
476
+ // every member released at pause. A member is "unavailable" when its
477
+ // reserve is rejected -- another sprint claimed it while we were paused,
478
+ // so it is no longer ours. We refuse to silently continue on top of a
479
+ // member some other sprint now owns: collect every unavailable member
480
+ // and, if any, fail the resume with a single clean error that NAMES
481
+ // them (MemberReservationResumeError) so the operator knows exactly what
482
+ // to free before retrying the resume.
483
+ //
484
+ // Every successfully re-acquired member then runs `resyncMember` (git
485
+ // fetch + decideEnsureBranchAction probe + bd dolt pull) UNCONDITIONALLY
486
+ // before any work continues -- while paused, origin and the beads DB can
487
+ // have moved (another sprint, a human push), so the re-sync is never
488
+ // gated on a "looks unchanged" heuristic.
489
+ //
490
+ // @param {{ resyncMember?: (member: string) => Promise<void> }} [opts]
491
+ // @returns {Promise<{ reacquired: string[] }>}
492
+ async reReserveForResume({ resyncMember } = {}) {
493
+ if (!active) return { reacquired: [] };
494
+ const reacquired = [];
495
+ const unavailable = [];
496
+ for (const member of members) {
497
+ const res = await callFor('reserve', member);
498
+ if (res.ok) reacquired.push(member);
499
+ else unavailable.push(member);
500
+ }
501
+ if (unavailable.length > 0) {
502
+ // Hand back the ones we DID re-grab so a failed resume does not
503
+ // leave this sprint holding a partial, unusable reservation set
504
+ // that blocks the very members another operator may need to free
505
+ // up the unavailable ones. Best-effort -- the resume is failing
506
+ // regardless.
507
+ for (const member of reacquired) await callFor('release', member);
508
+ throw new MemberReservationResumeError(unavailable);
509
+ }
510
+ if (typeof resyncMember === 'function') {
511
+ for (const member of reacquired) await resyncMember(member);
512
+ }
513
+ return { reacquired };
514
+ },
515
+ };
516
+ }