@apralabs/apra-fleet 0.4.1 → 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 (476) hide show
  1. package/README.md +53 -12
  2. package/dist/agents/backlog-groomer.md +42 -21
  3. package/dist/agents/ci-watcher.md +14 -0
  4. package/dist/agents/deployer.md +59 -46
  5. package/dist/agents/doer.md +157 -134
  6. package/dist/agents/harvester.md +31 -32
  7. package/dist/agents/integ-test-runner.md +92 -113
  8. package/dist/agents/kb-reconciler.md +40 -42
  9. package/dist/agents/plan-reviewer.md +139 -63
  10. package/dist/agents/planner.md +176 -100
  11. package/dist/agents/regression-test-runner.md +77 -81
  12. package/dist/agents/reviewer.md +69 -85
  13. package/dist/agents/schemas/integ-test-runner-output.json +1 -1
  14. package/dist/agents/schemas/plan-reviewer-output.json +37 -0
  15. package/dist/agents/schemas/regression-test-runner-output.json +4 -17
  16. package/dist/cli/agent-transform.d.ts +83 -2
  17. package/dist/cli/agent-transform.d.ts.map +1 -1
  18. package/dist/cli/agent-transform.js +266 -21
  19. package/dist/cli/agent-transform.js.map +1 -1
  20. package/dist/cli/auth.d.ts.map +1 -1
  21. package/dist/cli/auth.js +29 -11
  22. package/dist/cli/auth.js.map +1 -1
  23. package/dist/cli/config.d.ts +7 -5
  24. package/dist/cli/config.d.ts.map +1 -1
  25. package/dist/cli/config.js +44 -43
  26. package/dist/cli/config.js.map +1 -1
  27. package/dist/cli/install.d.ts +33 -0
  28. package/dist/cli/install.d.ts.map +1 -1
  29. package/dist/cli/install.js +294 -61
  30. package/dist/cli/install.js.map +1 -1
  31. package/dist/cli/kb-directives.d.ts.map +1 -1
  32. package/dist/cli/kb-directives.js +2 -1
  33. package/dist/cli/kb-directives.js.map +1 -1
  34. package/dist/cli/register-member.d.ts.map +1 -1
  35. package/dist/cli/register-member.js +7 -3
  36. package/dist/cli/register-member.js.map +1 -1
  37. package/dist/cli/start.d.ts.map +1 -1
  38. package/dist/cli/start.js +7 -0
  39. package/dist/cli/start.js.map +1 -1
  40. package/dist/cli/uninstall.d.ts.map +1 -1
  41. package/dist/cli/uninstall.js +5 -3
  42. package/dist/cli/uninstall.js.map +1 -1
  43. package/dist/cli/watch.d.ts +26 -3
  44. package/dist/cli/watch.d.ts.map +1 -1
  45. package/dist/cli/watch.js +41 -9
  46. package/dist/cli/watch.js.map +1 -1
  47. package/dist/commands/kb-server.d.ts +3 -0
  48. package/dist/commands/kb-server.d.ts.map +1 -1
  49. package/dist/commands/kb-server.js +43 -3
  50. package/dist/commands/kb-server.js.map +1 -1
  51. package/dist/index.js +3 -3
  52. package/dist/os/git-bash-candidates.d.ts +35 -0
  53. package/dist/os/git-bash-candidates.d.ts.map +1 -0
  54. package/dist/os/git-bash-candidates.js +46 -0
  55. package/dist/os/git-bash-candidates.js.map +1 -0
  56. package/dist/os/index.d.ts +13 -4
  57. package/dist/os/index.d.ts.map +1 -1
  58. package/dist/os/index.js +17 -2
  59. package/dist/os/index.js.map +1 -1
  60. package/dist/os/linux.d.ts +6 -0
  61. package/dist/os/linux.d.ts.map +1 -1
  62. package/dist/os/linux.js +36 -3
  63. package/dist/os/linux.js.map +1 -1
  64. package/dist/os/os-commands.d.ts +68 -2
  65. package/dist/os/os-commands.d.ts.map +1 -1
  66. package/dist/os/os-commands.js.map +1 -1
  67. package/dist/os/windows-gitbash.d.ts +98 -0
  68. package/dist/os/windows-gitbash.d.ts.map +1 -0
  69. package/dist/os/windows-gitbash.js +259 -0
  70. package/dist/os/windows-gitbash.js.map +1 -0
  71. package/dist/os/windows.d.ts +6 -0
  72. package/dist/os/windows.d.ts.map +1 -1
  73. package/dist/os/windows.js +73 -8
  74. package/dist/os/windows.js.map +1 -1
  75. package/dist/providers/agy.d.ts +118 -8
  76. package/dist/providers/agy.d.ts.map +1 -1
  77. package/dist/providers/agy.js +580 -55
  78. package/dist/providers/agy.js.map +1 -1
  79. package/dist/providers/claude.d.ts +83 -4
  80. package/dist/providers/claude.d.ts.map +1 -1
  81. package/dist/providers/claude.js +365 -12
  82. package/dist/providers/claude.js.map +1 -1
  83. package/dist/providers/codex.d.ts +7 -4
  84. package/dist/providers/codex.d.ts.map +1 -1
  85. package/dist/providers/codex.js +24 -4
  86. package/dist/providers/codex.js.map +1 -1
  87. package/dist/providers/copilot.d.ts +7 -4
  88. package/dist/providers/copilot.d.ts.map +1 -1
  89. package/dist/providers/copilot.js +27 -4
  90. package/dist/providers/copilot.js.map +1 -1
  91. package/dist/providers/index.d.ts +0 -1
  92. package/dist/providers/index.d.ts.map +1 -1
  93. package/dist/providers/index.js +0 -3
  94. package/dist/providers/index.js.map +1 -1
  95. package/dist/providers/none.d.ts +7 -4
  96. package/dist/providers/none.d.ts.map +1 -1
  97. package/dist/providers/none.js +22 -4
  98. package/dist/providers/none.js.map +1 -1
  99. package/dist/providers/opencode.d.ts +6 -3
  100. package/dist/providers/opencode.d.ts.map +1 -1
  101. package/dist/providers/opencode.js +27 -4
  102. package/dist/providers/opencode.js.map +1 -1
  103. package/dist/providers/provider.d.ts +215 -11
  104. package/dist/providers/provider.d.ts.map +1 -1
  105. package/dist/providers/provider.js +58 -2
  106. package/dist/providers/provider.js.map +1 -1
  107. package/dist/services/agent-provisioner.js +2 -2
  108. package/dist/services/agent-provisioner.js.map +1 -1
  109. package/dist/services/agy-project.d.ts +102 -0
  110. package/dist/services/agy-project.d.ts.map +1 -0
  111. package/dist/services/agy-project.js +356 -0
  112. package/dist/services/agy-project.js.map +1 -0
  113. package/dist/services/auth-socket.js +4 -4
  114. package/dist/services/auth-web.js +1 -1
  115. package/dist/services/cloud/activity.js +2 -2
  116. package/dist/services/cloud/activity.js.map +1 -1
  117. package/dist/services/cloud/lifecycle.d.ts.map +1 -1
  118. package/dist/services/cloud/lifecycle.js +33 -4
  119. package/dist/services/cloud/lifecycle.js.map +1 -1
  120. package/dist/services/context-admission.d.ts.map +1 -1
  121. package/dist/services/context-admission.js +9 -7
  122. package/dist/services/context-admission.js.map +1 -1
  123. package/dist/services/credential-cleanup.d.ts.map +1 -1
  124. package/dist/services/credential-cleanup.js +47 -10
  125. package/dist/services/credential-cleanup.js.map +1 -1
  126. package/dist/services/exit-drain.d.ts +44 -0
  127. package/dist/services/exit-drain.d.ts.map +1 -0
  128. package/dist/services/exit-drain.js +52 -0
  129. package/dist/services/exit-drain.js.map +1 -0
  130. package/dist/services/github-app.d.ts.map +1 -1
  131. package/dist/services/github-app.js +32 -4
  132. package/dist/services/github-app.js.map +1 -1
  133. package/dist/services/http-transport.d.ts +1 -0
  134. package/dist/services/http-transport.d.ts.map +1 -1
  135. package/dist/services/http-transport.js +48 -1
  136. package/dist/services/http-transport.js.map +1 -1
  137. package/dist/services/knowledge/kb-config.d.ts +42 -0
  138. package/dist/services/knowledge/kb-config.d.ts.map +1 -0
  139. package/dist/services/knowledge/kb-config.js +54 -0
  140. package/dist/services/knowledge/kb-config.js.map +1 -0
  141. package/dist/services/knowledge/kb-providers.d.ts +7 -1
  142. package/dist/services/knowledge/kb-providers.d.ts.map +1 -1
  143. package/dist/services/knowledge/kb-providers.js +191 -17
  144. package/dist/services/knowledge/kb-providers.js.map +1 -1
  145. package/dist/services/knowledge/require-sqlite-project.d.ts +32 -0
  146. package/dist/services/knowledge/require-sqlite-project.d.ts.map +1 -0
  147. package/dist/services/knowledge/require-sqlite-project.js +38 -0
  148. package/dist/services/knowledge/require-sqlite-project.js.map +1 -0
  149. package/dist/services/member-home.d.ts +1 -1
  150. package/dist/services/member-home.d.ts.map +1 -1
  151. package/dist/services/member-home.js +15 -12
  152. package/dist/services/member-home.js.map +1 -1
  153. package/dist/services/model-pricing.d.ts.map +1 -1
  154. package/dist/services/model-pricing.js +7 -8
  155. package/dist/services/model-pricing.js.map +1 -1
  156. package/dist/services/orphan-recovery.d.ts +6 -3
  157. package/dist/services/orphan-recovery.d.ts.map +1 -1
  158. package/dist/services/orphan-recovery.js +17 -14
  159. package/dist/services/orphan-recovery.js.map +1 -1
  160. package/dist/services/preflight-check.js +2 -2
  161. package/dist/services/preflight-check.js.map +1 -1
  162. package/dist/services/secret-token.d.ts +38 -0
  163. package/dist/services/secret-token.d.ts.map +1 -0
  164. package/dist/services/secret-token.js +51 -0
  165. package/dist/services/secret-token.js.map +1 -0
  166. package/dist/services/service-manager/types.d.ts +3 -1
  167. package/dist/services/service-manager/types.d.ts.map +1 -1
  168. package/dist/services/service-manager/windows.d.ts +14 -2
  169. package/dist/services/service-manager/windows.d.ts.map +1 -1
  170. package/dist/services/service-manager/windows.js +65 -7
  171. package/dist/services/service-manager/windows.js.map +1 -1
  172. package/dist/services/shell-probe.d.ts +131 -0
  173. package/dist/services/shell-probe.d.ts.map +1 -0
  174. package/dist/services/shell-probe.js +210 -0
  175. package/dist/services/shell-probe.js.map +1 -0
  176. package/dist/services/singleton.d.ts +2 -0
  177. package/dist/services/singleton.d.ts.map +1 -1
  178. package/dist/services/singleton.js +1 -1
  179. package/dist/services/singleton.js.map +1 -1
  180. package/dist/services/ssh.d.ts.map +1 -1
  181. package/dist/services/ssh.js +60 -4
  182. package/dist/services/ssh.js.map +1 -1
  183. package/dist/services/stall/find-log-file.d.ts.map +1 -1
  184. package/dist/services/stall/find-log-file.js +22 -16
  185. package/dist/services/stall/find-log-file.js.map +1 -1
  186. package/dist/services/stall/read-log-tail.d.ts.map +1 -1
  187. package/dist/services/stall/read-log-tail.js +26 -15
  188. package/dist/services/stall/read-log-tail.js.map +1 -1
  189. package/dist/services/stall/stall-detector.d.ts +53 -4
  190. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  191. package/dist/services/stall/stall-detector.js +212 -34
  192. package/dist/services/stall/stall-detector.js.map +1 -1
  193. package/dist/services/stall/stall-poller.d.ts.map +1 -1
  194. package/dist/services/stall/stall-poller.js +35 -42
  195. package/dist/services/stall/stall-poller.js.map +1 -1
  196. package/dist/services/strategy.d.ts +9 -0
  197. package/dist/services/strategy.d.ts.map +1 -1
  198. package/dist/services/strategy.js +119 -8
  199. package/dist/services/strategy.js.map +1 -1
  200. package/dist/services/substitution-engine.js +2 -2
  201. package/dist/services/substitution-engine.js.map +1 -1
  202. package/dist/services/tool-registry.d.ts.map +1 -1
  203. package/dist/services/tool-registry.js +5 -3
  204. package/dist/services/tool-registry.js.map +1 -1
  205. package/dist/services/user-config.js +1 -1
  206. package/dist/services/user-config.js.map +1 -1
  207. package/dist/services/vcs/azure-devops.d.ts +67 -2
  208. package/dist/services/vcs/azure-devops.d.ts.map +1 -1
  209. package/dist/services/vcs/azure-devops.js +281 -15
  210. package/dist/services/vcs/azure-devops.js.map +1 -1
  211. package/dist/services/vcs/bitbucket.d.ts.map +1 -1
  212. package/dist/services/vcs/bitbucket.js +16 -0
  213. package/dist/services/vcs/bitbucket.js.map +1 -1
  214. package/dist/services/vcs/github.d.ts.map +1 -1
  215. package/dist/services/vcs/github.js +24 -0
  216. package/dist/services/vcs/github.js.map +1 -1
  217. package/dist/services/vcs/types.d.ts +123 -2
  218. package/dist/services/vcs/types.d.ts.map +1 -1
  219. package/dist/skills/fleet-sprint-cli/SKILL.md +20 -1
  220. package/dist/skills/pm/SKILL.md +1 -2
  221. package/dist/skills/pm/cost.md +0 -4
  222. package/dist/skills/pm/fleet-addendum.md +2 -3
  223. package/dist/tools/check-status.d.ts +7 -4
  224. package/dist/tools/check-status.d.ts.map +1 -1
  225. package/dist/tools/check-status.js +5 -3
  226. package/dist/tools/check-status.js.map +1 -1
  227. package/dist/tools/cloud-control.js +2 -2
  228. package/dist/tools/cloud-control.js.map +1 -1
  229. package/dist/tools/compose-permissions.d.ts +6 -0
  230. package/dist/tools/compose-permissions.d.ts.map +1 -1
  231. package/dist/tools/compose-permissions.js +211 -50
  232. package/dist/tools/compose-permissions.js.map +1 -1
  233. package/dist/tools/credential-store-set.js +1 -1
  234. package/dist/tools/execute-command.d.ts.map +1 -1
  235. package/dist/tools/execute-command.js +56 -29
  236. package/dist/tools/execute-command.js.map +1 -1
  237. package/dist/tools/execute-prompt.d.ts +15 -2
  238. package/dist/tools/execute-prompt.d.ts.map +1 -1
  239. package/dist/tools/execute-prompt.js +1214 -873
  240. package/dist/tools/execute-prompt.js.map +1 -1
  241. package/dist/tools/kb-capture.d.ts +2 -2
  242. package/dist/tools/kb-capture.d.ts.map +1 -1
  243. package/dist/tools/kb-capture.js +29 -5
  244. package/dist/tools/kb-capture.js.map +1 -1
  245. package/dist/tools/kb-export.d.ts +2 -2
  246. package/dist/tools/kb-export.d.ts.map +1 -1
  247. package/dist/tools/kb-export.js +3 -28
  248. package/dist/tools/kb-export.js.map +1 -1
  249. package/dist/tools/kb-feedback.d.ts.map +1 -1
  250. package/dist/tools/kb-feedback.js +3 -1
  251. package/dist/tools/kb-feedback.js.map +1 -1
  252. package/dist/tools/kb-freshness-sweep.d.ts.map +1 -1
  253. package/dist/tools/kb-freshness-sweep.js +3 -1
  254. package/dist/tools/kb-freshness-sweep.js.map +1 -1
  255. package/dist/tools/kb-import.d.ts.map +1 -1
  256. package/dist/tools/kb-import.js +2 -1
  257. package/dist/tools/kb-import.js.map +1 -1
  258. package/dist/tools/kb-list.d.ts.map +1 -1
  259. package/dist/tools/kb-list.js +3 -1
  260. package/dist/tools/kb-list.js.map +1 -1
  261. package/dist/tools/kb-query.d.ts +2 -2
  262. package/dist/tools/kb-reconcile-prefilter.d.ts.map +1 -1
  263. package/dist/tools/kb-reconcile-prefilter.js +3 -1
  264. package/dist/tools/kb-reconcile-prefilter.js.map +1 -1
  265. package/dist/tools/kb-resolve-contradiction.d.ts.map +1 -1
  266. package/dist/tools/kb-resolve-contradiction.js +3 -1
  267. package/dist/tools/kb-resolve-contradiction.js.map +1 -1
  268. package/dist/tools/kb-setup.d.ts.map +1 -1
  269. package/dist/tools/kb-setup.js +125 -20
  270. package/dist/tools/kb-setup.js.map +1 -1
  271. package/dist/tools/kb-stats.d.ts.map +1 -1
  272. package/dist/tools/kb-stats.js +64 -43
  273. package/dist/tools/kb-stats.js.map +1 -1
  274. package/dist/tools/list-members.d.ts +2 -2
  275. package/dist/tools/list-members.d.ts.map +1 -1
  276. package/dist/tools/list-members.js +7 -2
  277. package/dist/tools/list-members.js.map +1 -1
  278. package/dist/tools/member-detail.d.ts +2 -2
  279. package/dist/tools/member-detail.d.ts.map +1 -1
  280. package/dist/tools/member-detail.js +22 -3
  281. package/dist/tools/member-detail.js.map +1 -1
  282. package/dist/tools/member-reservation.d.ts +58 -1
  283. package/dist/tools/member-reservation.d.ts.map +1 -1
  284. package/dist/tools/member-reservation.js +71 -18
  285. package/dist/tools/member-reservation.js.map +1 -1
  286. package/dist/tools/monitor-task.d.ts.map +1 -1
  287. package/dist/tools/monitor-task.js +17 -2
  288. package/dist/tools/monitor-task.js.map +1 -1
  289. package/dist/tools/provision-auth.d.ts +80 -1
  290. package/dist/tools/provision-auth.d.ts.map +1 -1
  291. package/dist/tools/provision-auth.js +147 -59
  292. package/dist/tools/provision-auth.js.map +1 -1
  293. package/dist/tools/provision-vcs-auth.d.ts +96 -3
  294. package/dist/tools/provision-vcs-auth.d.ts.map +1 -1
  295. package/dist/tools/provision-vcs-auth.js +254 -88
  296. package/dist/tools/provision-vcs-auth.js.map +1 -1
  297. package/dist/tools/register-member.d.ts +21 -12
  298. package/dist/tools/register-member.d.ts.map +1 -1
  299. package/dist/tools/register-member.js +141 -16
  300. package/dist/tools/register-member.js.map +1 -1
  301. package/dist/tools/remove-member.d.ts.map +1 -1
  302. package/dist/tools/remove-member.js +29 -4
  303. package/dist/tools/remove-member.js.map +1 -1
  304. package/dist/tools/revoke-vcs-auth.js +2 -2
  305. package/dist/tools/revoke-vcs-auth.js.map +1 -1
  306. package/dist/tools/send-email.d.ts +2 -2
  307. package/dist/tools/setup-git-app.d.ts.map +1 -1
  308. package/dist/tools/setup-git-app.js +11 -7
  309. package/dist/tools/setup-git-app.js.map +1 -1
  310. package/dist/tools/setup-ssh-key.d.ts.map +1 -1
  311. package/dist/tools/setup-ssh-key.js +2 -1
  312. package/dist/tools/setup-ssh-key.js.map +1 -1
  313. package/dist/tools/shutdown-server.d.ts +2 -0
  314. package/dist/tools/shutdown-server.d.ts.map +1 -1
  315. package/dist/tools/shutdown-server.js +23 -1
  316. package/dist/tools/shutdown-server.js.map +1 -1
  317. package/dist/tools/stop-prompt.js +2 -2
  318. package/dist/tools/stop-prompt.js.map +1 -1
  319. package/dist/tools/update-agent-cli.js +2 -2
  320. package/dist/tools/update-agent-cli.js.map +1 -1
  321. package/dist/tools/update-member.d.ts +21 -12
  322. package/dist/tools/update-member.d.ts.map +1 -1
  323. package/dist/tools/update-member.js +61 -12
  324. package/dist/tools/update-member.js.map +1 -1
  325. package/dist/tools/vcs-credential-exec.d.ts +127 -0
  326. package/dist/tools/vcs-credential-exec.d.ts.map +1 -0
  327. package/dist/tools/vcs-credential-exec.js +197 -0
  328. package/dist/tools/vcs-credential-exec.js.map +1 -0
  329. package/dist/types.d.ts +24 -1
  330. package/dist/types.d.ts.map +1 -1
  331. package/dist/utils/agent-helpers.d.ts +36 -0
  332. package/dist/utils/agent-helpers.d.ts.map +1 -1
  333. package/dist/utils/agent-helpers.js +39 -1
  334. package/dist/utils/agent-helpers.js.map +1 -1
  335. package/dist/utils/log-helpers.d.ts.map +1 -1
  336. package/dist/utils/log-helpers.js +2 -2
  337. package/dist/utils/log-helpers.js.map +1 -1
  338. package/dist/utils/platform.d.ts +7 -0
  339. package/dist/utils/platform.d.ts.map +1 -1
  340. package/dist/utils/platform.js +11 -1
  341. package/dist/utils/platform.js.map +1 -1
  342. package/dist/utils/prompt-errors.d.ts.map +1 -1
  343. package/dist/utils/prompt-errors.js +7 -1
  344. package/dist/utils/prompt-errors.js.map +1 -1
  345. package/dist/utils/shell-escape.d.ts +16 -0
  346. package/dist/utils/shell-escape.d.ts.map +1 -1
  347. package/dist/utils/shell-escape.js +22 -2
  348. package/dist/utils/shell-escape.js.map +1 -1
  349. package/dist/utils/vcs-provider-detect.d.ts +65 -0
  350. package/dist/utils/vcs-provider-detect.d.ts.map +1 -0
  351. package/dist/utils/vcs-provider-detect.js +109 -0
  352. package/dist/utils/vcs-provider-detect.js.map +1 -0
  353. package/dist/utils/workspace-trust.d.ts +20 -17
  354. package/dist/utils/workspace-trust.d.ts.map +1 -1
  355. package/dist/utils/workspace-trust.js +91 -1
  356. package/dist/utils/workspace-trust.js.map +1 -1
  357. package/dist/workflows/auto-sprint.js +180 -32
  358. package/package.json +7 -5
  359. package/packages/apra-fleet-client/src/client/api.mjs +403 -12
  360. package/packages/apra-fleet-client/src/client/errors.mjs +6 -2
  361. package/packages/apra-fleet-se/apra-pm/agents/_shared/GRAPH-SEMANTICS.md +10 -2
  362. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +42 -21
  363. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +14 -0
  364. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +59 -46
  365. package/packages/apra-fleet-se/apra-pm/agents/doer.md +157 -134
  366. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +31 -32
  367. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +92 -113
  368. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +40 -42
  369. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +139 -63
  370. package/packages/apra-fleet-se/apra-pm/agents/planner.md +176 -100
  371. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +77 -81
  372. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +69 -85
  373. package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +1 -1
  374. package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-output.json +37 -0
  375. package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-output.json +4 -17
  376. package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +1 -2
  377. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +0 -4
  378. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +2 -3
  379. package/packages/apra-fleet-se/bin/cli.mjs +280 -3
  380. package/packages/apra-fleet-se/bin/serve.mjs +114 -5
  381. package/packages/apra-fleet-se/fleet-sprint/abort.mjs +481 -0
  382. package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +491 -0
  383. package/packages/apra-fleet-se/fleet-sprint/beads-identity-check.mjs +282 -0
  384. package/packages/apra-fleet-se/fleet-sprint/beads-identity.mjs +208 -0
  385. package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +638 -0
  386. package/packages/apra-fleet-se/fleet-sprint/beads-transitions.mjs +301 -0
  387. package/packages/apra-fleet-se/fleet-sprint/branch-ensure.mjs +96 -0
  388. package/packages/apra-fleet-se/fleet-sprint/conflict-ladder.mjs +8 -0
  389. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +199 -34
  390. package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +516 -0
  391. package/packages/apra-fleet-se/fleet-sprint/dispatch-failure.mjs +184 -0
  392. package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +1121 -0
  393. package/packages/apra-fleet-se/fleet-sprint/dispatch-safety-guard.mjs +216 -4
  394. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +23 -8
  395. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-manual-recovery-verified.md +10 -8
  396. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +285 -4
  397. package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +3 -3
  398. package/packages/apra-fleet-se/fleet-sprint/docs/run-sprint-cycle-prelude-decision.md +215 -0
  399. package/packages/apra-fleet-se/fleet-sprint/docs/shared-orchestrator-reservation-design.md +12 -12
  400. package/packages/apra-fleet-se/fleet-sprint/docs/stabilization-log.md +14 -4
  401. package/packages/apra-fleet-se/fleet-sprint/dolt-literal-guard.mjs +56 -1
  402. package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +275 -99
  403. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +1054 -39
  404. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +308 -0
  405. package/packages/apra-fleet-se/fleet-sprint/explicit-id-create-guard.mjs +501 -0
  406. package/packages/apra-fleet-se/fleet-sprint/fatal-diagnostics.mjs +134 -0
  407. package/packages/apra-fleet-se/fleet-sprint/full-db-fetch-guard.mjs +102 -0
  408. package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +556 -0
  409. package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +495 -0
  410. package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +564 -0
  411. package/packages/apra-fleet-se/fleet-sprint/inline-ladder-guard.mjs +216 -0
  412. package/packages/apra-fleet-se/fleet-sprint/kb.mjs +728 -0
  413. package/packages/apra-fleet-se/fleet-sprint/mcp-result.mjs +75 -0
  414. package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +252 -0
  415. package/packages/apra-fleet-se/fleet-sprint/member-sync.mjs +581 -0
  416. package/packages/apra-fleet-se/fleet-sprint/member-target.mjs +93 -0
  417. package/packages/apra-fleet-se/fleet-sprint/newtask-text.mjs +266 -0
  418. package/packages/apra-fleet-se/fleet-sprint/parent-notes-staleness.mjs +201 -0
  419. package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +136 -0
  420. package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +822 -0
  421. package/packages/apra-fleet-se/fleet-sprint/phases/ensure-sprint-branch.mjs +294 -0
  422. package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +403 -0
  423. package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +180 -0
  424. package/packages/apra-fleet-se/fleet-sprint/phases/integ-test.mjs +358 -0
  425. package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +390 -0
  426. package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +323 -0
  427. package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +232 -0
  428. package/packages/apra-fleet-se/fleet-sprint/phases/regression-test.mjs +174 -0
  429. package/packages/apra-fleet-se/fleet-sprint/phases/replan.mjs +197 -0
  430. package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +305 -0
  431. package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +559 -0
  432. package/packages/apra-fleet-se/fleet-sprint/role-policies.mjs +1416 -0
  433. package/packages/apra-fleet-se/fleet-sprint/round-session.mjs +100 -0
  434. package/packages/apra-fleet-se/fleet-sprint/runner.js +1672 -9072
  435. package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +134 -0
  436. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +159 -0
  437. package/packages/apra-fleet-se/fleet-sprint/se-windows-gitbash.mjs +97 -0
  438. package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +143 -0
  439. package/packages/apra-fleet-se/fleet-sprint/shell-command-guard.mjs +304 -0
  440. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +20 -1
  441. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +21 -2
  442. package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +454 -0
  443. package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +239 -0
  444. package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +163 -0
  445. package/packages/apra-fleet-se/fleet-sprint/unbracketed-push-guard.mjs +234 -0
  446. package/packages/apra-fleet-se/fleet-sprint/usage-limit-controller.mjs +211 -0
  447. package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +1279 -0
  448. package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +204 -19
  449. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +707 -12
  450. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +28 -0
  451. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/dolt.mjs +33 -4
  452. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +191 -43
  453. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +333 -6
  454. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/shell-helpers.mjs +165 -0
  455. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +167 -37
  456. package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +559 -0
  457. package/packages/apra-fleet-se/package.json +1 -1
  458. package/packages/apra-fleet-workflow/src/viewer/index.mjs +178 -1
  459. package/packages/apra-fleet-workflow/src/workflow/index.mjs +478 -32
  460. package/skills/fleet/SKILL.md +27 -16
  461. package/skills/fleet/auth-azdevops.md +57 -7
  462. package/skills/fleet/auth-bitbucket.md +5 -5
  463. package/skills/fleet/auth-github.md +7 -6
  464. package/skills/fleet/beads-conflict-resolution.md +141 -0
  465. package/skills/fleet/beads.md +16 -12
  466. package/skills/fleet/onboarding.md +6 -6
  467. package/skills/fleet/permissions.md +11 -7
  468. package/skills/fleet/profiles/node.json +1 -1
  469. package/skills/fleet/skill-matrix.md +1 -1
  470. package/skills/fleet/troubleshooting.md +4 -3
  471. package/version.json +1 -1
  472. package/dist/providers/gemini.d.ts +0 -52
  473. package/dist/providers/gemini.d.ts.map +0 -1
  474. package/dist/providers/gemini.js +0 -236
  475. package/dist/providers/gemini.js.map +0 -1
  476. package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +0 -23
@@ -0,0 +1,323 @@
1
+ // =============================================================================
2
+ // PHASE MODULE: Publish PR (apra-fleet-3swo.6.9).
3
+ //
4
+ // The TWELFTH and LAST of runSprintCycle's twelve phase() boundaries: push the
5
+ // sprint branch and raise (but never merge) a pull request for it. Per the pm
6
+ // skill's R12 rule a human -- or a later, explicitly-scoped issue -- must
7
+ // review and merge; nothing here merges anything. Moved verbatim out of
8
+ // runner.js: every log line, PR title/body string and command() option is
9
+ // byte-identical to the inline version, so the golden transcript is unchanged.
10
+ // Move-only, no behaviour change.
11
+ //
12
+ // WHERE THIS PHASE STARTS AND STOPS. It starts at its own phase() call and
13
+ // ends where the inline version's final `endGroup()` used to sit. The
14
+ // `// 7. Publish` section banner above it, BOTH endGroup() calls and the two
15
+ // return objects stay in runner.js -- group('Finalization')/endGroup() wrap all
16
+ // four Finalization phases, not this one, and runSprintCycle's return value is
17
+ // the function's own contract. This phase returns `{ pushed }` and runner.js
18
+ // builds both return objects from it; that is the ONLY structural change, and
19
+ // it is behaviour-preserving in both directions:
20
+ // - push failed: this phase logs [Publish Push Failed] and returns
21
+ // pushed:false WITHOUT doing any PR/target-issue work, exactly as the
22
+ // inline early return did; runner.js then endGroup()s and returns the
23
+ // COMPUTED verdict with pushed:false.
24
+ // - push succeeded: this phase runs the PR/target-issue work and returns
25
+ // pushed:true; runner.js endGroup()s and returns the computed verdict.
26
+ // A genuine PR-creation failure still throws a typed CommandError from inside
27
+ // this phase, so it propagates out BEFORE runner.js's endGroup() -- same
28
+ // ordering the inline version had.
29
+ //
30
+ // THE BRANCH PUSH STAYS INSIDE A SYNC BRACKET (apra-fleet-3swo.4.1). The push
31
+ // goes through gitSync.pushGitAfter(), the bracketed syncMemberAfter() entry
32
+ // point -- never a raw `git push` and never the bare primitive -- so the pause
33
+ // guard reads "not clean" for its whole duration and a pause can never land
34
+ // mid-push of the sprint branch. Registering this module in
35
+ // ../guarded-modules.mjs is what keeps unbracketed-push-guard covering that
36
+ // site instead of silently losing it now that it has left runner.js. The
37
+ // non-hosted-remote target-issue closure's D-push likewise goes through
38
+ // gitSync.syncBeadsAfter(..., { pushBeads: true }).
39
+ //
40
+ // WHICH MEMBER DOES WHAT, AND WHY IT MATTERS. The branch push and the
41
+ // `git remote get-url origin` read run on publishGitMember -- the role-resolved
42
+ // 'harvester' member, a real dispatch member with an actual git checkout --
43
+ // NEVER orchestratorMember, which may be a shared/unreservable, git-less member
44
+ // (docs/design-orchestrator-worktree-model-v2.md section 4.3/4.5).
45
+ // raiseVcsPrForMember() and the direct `bd close` calls stay on
46
+ // orchestratorMember: a credential-file read plus a REST call, and beads
47
+ // mutations, neither of which needs a git checkout (section 4.6).
48
+ //
49
+ // WHY ITS HELPERS ARE INJECTED RATHER THAN IMPORTED. sanitizePrText is defined
50
+ // in ../runner.js, so importing it would be a circular import back into the
51
+ // file this module was sliced out of -- it is injected exactly as
52
+ // ./final-review.mjs injects it. command, gitSync, getMemberForRole and args
53
+ // are runSprintCycle-scoped, so there is nothing to import; vcsCapabilities,
54
+ // raiseVcsPrForMember, ApraFleet and CommandError live in real modules and are
55
+ // imported directly.
56
+ //
57
+ // GUARD COVERAGE: registered as 'phases/publish-pr.mjs' in
58
+ // ../guarded-modules.mjs. It took TWO member_name-bearing command() call sites
59
+ // out of runner.js -- the `git remote get-url origin` capability probe on
60
+ // publishGitMember and the per-target-issue `bd close` on orchestratorMember --
61
+ // plus the branch push and the beads D-push described above, and NO
62
+ // dispatchRole() site (it dispatches no agent; raiseVcsPrForMember is a REST
63
+ // call). That is exactly what dispatch-safety-guard, unbracketed-push-guard
64
+ // and the phase 3 dispatch census read, so all three baselines are pinned
65
+ // rather than assumed. It also owns the ONLY remaining vcsCapabilities() call
66
+ // site outside abort.mjs, which test/vcs-capabilities-table.test.mjs counts.
67
+ // =============================================================================
68
+
69
+ import { CommandError } from '@apralabs/apra-fleet-workflow';
70
+ import { ApraFleet } from '@apralabs/apra-fleet-client';
71
+ import { capabilities as vcsCapabilities } from '../vcs-module.mjs';
72
+ import { raiseVcsPrForMember } from '../vcs-auth.mjs';
73
+
74
+ /**
75
+ * Runs the Publish PR phase: push the sprint branch, then either raise a PR on
76
+ * a hosted remote or (on a remote that can never open one) close the target
77
+ * issue(s) directly when the verdict passed.
78
+ *
79
+ * @param {object} state Explicit phase state; see this file's header.
80
+ * @returns {Promise<{ pushed: boolean }>} Whether the sprint branch actually
81
+ * reached the remote. runner.js folds this straight into runSprintCycle's
82
+ * return value -- it never overrides the sprint's own computed verdict.
83
+ */
84
+ export async function runPublishPrPhase({
85
+ // Presentation + command seams.
86
+ phase,
87
+ log,
88
+ command,
89
+ // Sprint identity/config.
90
+ args,
91
+ validated,
92
+ targetIssues,
93
+ orchestratorMember,
94
+ finalCycleLabel,
95
+ // The sync brackets this phase's branch push and beads D-push go through.
96
+ gitSync,
97
+ // Role resolution for the git-capable publishing member (see header).
98
+ getMemberForRole,
99
+ // The verdict this phase publishes but must never change.
100
+ finalVerdictResult,
101
+ // Exported BY runner.js; injected to avoid a circular import (see header).
102
+ sanitizePrText,
103
+ }) {
104
+ phase(`Publish PR C${finalCycleLabel}`);
105
+ // The branch push is the LAST step of a sprint that has already done all of
106
+ // its work and computed a final verdict. A transient push failure (a racing
107
+ // writer, a momentarily unreachable remote, a credential refresh in flight)
108
+ // used to throw a CommandError from here, which converted a computed PASS
109
+ // into `verdict: 'ABORTED'` and discarded the whole run's conclusion over a
110
+ // network hiccup at the very end. So: failSoft plus the same short, bounded
111
+ // sync backoff every other push round trip uses, and -- if it STILL will not
112
+ // go through -- log loudly and return the COMPUTED verdict with
113
+ // `pushed: false` rather than destroying it.
114
+ //
115
+ // A persistent failure also skips everything downstream of the push (PR
116
+ // creation on a hosted remote; direct target-issue closure + D-push on a
117
+ // non-hosted one). None of that may run against a branch whose commits
118
+ // never reached the remote: a PR cannot be raised for unpushed work, and
119
+ // closing the sprint's target issue would advertise a completion nobody can
120
+ // see. This is the deliberately MINIMAL hardening -- the pluggable-publish
121
+ // restructure is apra-fleet-647.2, which supersedes it.
122
+ // apra-fleet: this push and the origin-remote read just below it run on
123
+ // publishGitMember -- a real dispatch member with an actual git checkout
124
+ // (harvester, falling back to the fallback pool like every other role
125
+ // resolution in ../runner.js) -- NEVER orchestratorMember, which may be a
126
+ // shared/unreservable, git-less member (docs/design-orchestrator-
127
+ // worktree-model-v2.md section 4.3/4.5). raiseVcsPrForMember() below
128
+ // stays on orchestratorMember: it is a credential-file read + REST call,
129
+ // not git, and is explicitly designed to stay there (section 4.6).
130
+ const publishGitMember = getMemberForRole('harvester');
131
+ let pushed = false;
132
+ let lastPushError = '';
133
+ // apra-fleet-9wdh-adjacent (Publish-PR push self-heal): this used to retry
134
+ // the byte-identical `git push` up to 3 times with no fetch/rebase step in
135
+ // between -- fine for a transient/busy-remote failure, but a genuine
136
+ // non-fast-forward rejection ("fetch first") is deterministic, so all 3
137
+ // attempts failed identically and the branch's work was stranded local-
138
+ // only. syncMemberAfter() (../git-sync.mjs) already implements the
139
+ // correct self-heal for exactly this failure shape -- bounded transient
140
+ // retry, then one pull-rebase-then-re-push on a genuine non-fast-forward
141
+ // divergence, never a blind force-push -- and every OTHER post-dispatch
142
+ // G-push in fleet-sprint already routes through it. Publish PR is the one
143
+ // push site that bypassed it. Route through it here too instead of the
144
+ // raw retry loop. NOTE: no `agent` is passed here, so a real content
145
+ // conflict during the rebase (not just a plain non-FF race) throws
146
+ // GitDivergedError directly rather than getting syncMemberAfter's
147
+ // optional Tier 2 conflict-resolution-agent dispatch -- same as the old
148
+ // loop, which had no Tier 2 either; not a regression.
149
+ // (apra-fleet-3swo.4.1) ... and this G-push, unlike the Publish-PR D-push
150
+ // just below, was never inside a sync bracket either -- a pause could land
151
+ // mid-`git push` of the sprint branch. pushGitAfter() is the bracketed
152
+ // syncMemberAfter() entry point; it threads the same command/log/branch/
153
+ // onAuthFailure/provider-resolver state the bare call passed by hand.
154
+ try {
155
+ await gitSync.pushGitAfter(publishGitMember, { remote: 'origin', setUpstream: true });
156
+ pushed = true;
157
+ } catch (pushErr) {
158
+ lastPushError = pushErr.message;
159
+ }
160
+ if (!pushed) {
161
+ log(`[Publish Push Failed] Could not push sprint branch '${validated.branch}' to origin (bounded transient retry, and a rebase-then-re-push if diverged, both exhausted) -- the sprint's work is COMMITTED LOCALLY ONLY and is NOT on the remote. Skipping PR creation and target-issue closure (neither is meaningful for an unpushed branch); the sprint's own computed verdict (${finalVerdictResult.verdict}) is preserved and returned with pushed:false. Push the branch by hand and raise the PR, or re-run finalization once the remote is reachable. Last error: ${lastPushError}`);
162
+ return { pushed: false };
163
+ }
164
+ // The final verdict is surfaced directly in the PR title and body -- a
165
+ // human reviewer must never have to dig through sprint logs to learn
166
+ // whether the run's own review gate passed. A FAIL verdict still publishes
167
+ // the PR (never suppressed), with the verdict stated plainly so the
168
+ // reviewer can weigh it before merging.
169
+ const finalVerdictLabel = finalVerdictResult.verdict === 'PASS' ? 'PASS' : 'FAIL';
170
+
171
+ // Resolve the sprint's own git 'origin' remote and classify it via
172
+ // VCSModule.capabilities() BEFORE ever attempting the VCSModule REST
173
+ // create-pull-request call. A remote whose provider cannot open a PR (a
174
+ // file:// bare mirror, or any other host with no hosting API support)
175
+ // means PR creation can never succeed, and attempting it anyway throws a
176
+ // hard 'gh auth login required'-shaped CommandError that would fail the
177
+ // whole sprint. Resolving the remote is itself failSoft -- an
178
+ // unresolvable remote fails closed to canOpenPullRequest:false, per
179
+ // capabilities()'s own contract -- so a probe hiccup here can never kill
180
+ // the sprint.
181
+ const originUrlRes = await command('git remote get-url origin', {
182
+ member_name: publishGitMember,
183
+ silent: true,
184
+ failSoft: true,
185
+ label: 'Resolve origin remote URL',
186
+ });
187
+ const originUrl = originUrlRes.ok ? originUrlRes.output.trim() : '';
188
+ // (apra-fleet-3swo.4.10) capabilities() is already the provider-agnostic
189
+ // hook -- it dispatches to WHICHEVER registered provider's matchesHost()
190
+ // claims this remote's host (github, azure-devops, bitbucket, ... see
191
+ // vcs-module.mjs's capabilities()), never a hardcoded GitHub check. The
192
+ // log line below used to say "not a gh-hostable GitHub remote" even
193
+ // though the gate itself was already provider-neutral -- that wording
194
+ // was pure residue, not control flow, but a broken/misconfigured
195
+ // Azure DevOps or Bitbucket remote hitting this same branch would have
196
+ // been told (wrongly) that it looked like a GitHub problem. `host` is
197
+ // carried through so the log names what was actually resolved, matching
198
+ // finalizeAbort's identical gate (abort.mjs) which never had the stale
199
+ // GitHub wording in the first place.
200
+ const publishPrCapabilities = vcsCapabilities(originUrl);
201
+ const hostedRemote = publishPrCapabilities.canOpenPullRequest;
202
+
203
+ if (!hostedRemote) {
204
+ log(`Publish PR: origin remote '${originUrl || '(unresolved)'}' cannot open a pull request (host: ${publishPrCapabilities.host || 'unknown'}) -- ` +
205
+ 'skipping PR creation entirely (no dependency on any VCS provider\'s auth for this path).');
206
+ // A non-hosted remote can never complete PR creation, so target-issue
207
+ // closure cannot be gated on it -- close the target issue(s) directly,
208
+ // but only when the sprint's own final verdict actually passed. A FAIL
209
+ // verdict must never be masked by closing the issue anyway; it still
210
+ // ends the sprint 'failed' via the return value below, same as the
211
+ // hosted-remote path.
212
+ if (finalVerdictResult.verdict === 'PASS') {
213
+ for (const id of targetIssues) {
214
+ const closeRes = await command(`bd close ${id}`, {
215
+ member_name: orchestratorMember,
216
+ silent: true,
217
+ failSoft: true,
218
+ label: `Close target issue '${id}' directly (non-hosted remote, no PR gate)`,
219
+ });
220
+ if (closeRes.ok) {
221
+ log(`Publish PR: closed target issue '${id}' directly (non-hosted remote, PASS verdict).`);
222
+ } else {
223
+ log(`Publish PR: failed to close target issue '${id}' directly (non-fatal, continuing): ${closeRes.error}`);
224
+ }
225
+ }
226
+ await gitSync.syncBeadsAfter(orchestratorMember, { pushBeads: true });
227
+ } else {
228
+ log('Publish PR: final verdict is FAIL -- leaving target issue(s) open (not closing on a non-PASS verdict).');
229
+ }
230
+ } else {
231
+ // finalVerdictResult.notes is LLM-authored free text -- sanitize with
232
+ // sanitizePrText() (see the comment above its definition) BEFORE it is
233
+ // ever embedded in the VCSModule-built create-pull-request command()
234
+ // string below. validated.goal/validated.branch need no sanitization
235
+ // here: both are already validated against shell-injection-safe patterns
236
+ // (GOAL_PATTERN/BRANCH_NAME_PATTERN) at arg-validation time.
237
+ const prTitle = `Auto-sprint [${finalVerdictLabel}]: ${validated.branch}`;
238
+ const safeNotes = sanitizePrText(finalVerdictResult.notes);
239
+ const prBody = [
240
+ `Automated apra-fleet-se sprint (goal: ${validated.goal}).`,
241
+ '',
242
+ `Final Verdict: ${finalVerdictLabel}`,
243
+ safeNotes ? `Notes: ${safeNotes}` : null,
244
+ '',
245
+ 'Do NOT auto-merge -- see pm skill R12; a human must review and merge this PR.',
246
+ ].filter((line) => line !== null).join('\n');
247
+
248
+ // Idempotent PR creation via VCSModule (apra-fleet-tfx.8: the reverted
249
+ // gh-based path is gone). A push+pr credential is minted just-in-time immediately
250
+ // before this one call (never at sprint setup, never for any other
251
+ // phase), VCSModule builds the orchestrator-side curl command, and
252
+ // `orchestratorMember` dispatches it via execute_command -- no gh, no
253
+ // server-side fallback. A re-run of finalization against a branch
254
+ // that ALREADY has an open PR from a prior, otherwise-successful run
255
+ // can be told apart from a genuine failure: the REST create-PR call
256
+ // returns 422 "already exists" in that case -- that specific outcome
257
+ // is swallowed (logged, not thrown) because it means the desired end
258
+ // state (a PR is open for this branch) already holds. Any OTHER
259
+ // failure (auth, network, a real API error, the injectable mock
260
+ // failure below) is NOT swallowed -- it is re-raised as a typed
261
+ // CommandError so it surfaces clearly rather than being silently
262
+ // invisible.
263
+ const fleetApiForPr = (args && typeof args.callTool === 'function') ? new ApraFleet({ callTool: args.callTool }) : null;
264
+ if (!fleetApiForPr) {
265
+ // Graceful degradation (apra-fleet-tfx.8.1): minting the push+pr
266
+ // credential VCSModule needs to raise this PR requires an MCP
267
+ // client. When no callTool is wired (e.g. a mock-sprint scenario
268
+ // that never opted into an MCP client), the sprint branch is
269
+ // already pushed by the withGitSync bracket -- so rather than an
270
+ // unconditional hard-throw that would fail every such pre-existing
271
+ // scenario at the very last step, this degrades to a clear,
272
+ // skipped-PR log and lets the sprint report its real verdict. In
273
+ // production callTool is always wired (bin/cli.mjs), so this branch
274
+ // never runs there; it exists purely so PR creation is not a hard
275
+ // MCP dependency for callers that legitimately have none. A genuine
276
+ // PR-creation FAILURE (auth, network, a real API error) still
277
+ // throws below -- only the callTool-absent case is degraded.
278
+ log(`[Publish PR Skipped] no MCP callTool available to mint a push+pr credential for member '${orchestratorMember}' -- branch '${validated.branch}' is pushed but the PR was not raised.`);
279
+ } else {
280
+ const prResult = await raiseVcsPrForMember({
281
+ fleetApi: fleetApiForPr,
282
+ command,
283
+ member: orchestratorMember,
284
+ base: validated.baseBranch,
285
+ head: validated.branch,
286
+ title: prTitle,
287
+ body: prBody,
288
+ log,
289
+ logPrefix: '[Publish PR]',
290
+ // Already resolved above via publishGitMember (a real
291
+ // git-capable member) for the PR-capability gate -- skip
292
+ // re-deriving it a second time by shelling out to
293
+ // orchestratorMember, which may have no git checkout of its
294
+ // own to read a remote from (docs/design-orchestrator-
295
+ // worktree-model-v2.md section 4.6: this call stays workspace-
296
+ // independent by design, credential-file-read + REST only).
297
+ remoteUrlOverride: originUrl,
298
+ });
299
+ if (!prResult.ok) {
300
+ if (prResult.authFailure) {
301
+ // apra-fleet-5co8.15: an auth failure raiseVcsPrForMember
302
+ // could not clear -- including one that never got past
303
+ // credential provisioning, e.g. a missing Azure DevOps PAT
304
+ // credential-store entry -- degrades the publish phase
305
+ // instead of aborting the sprint, same policy
306
+ // finalizeAbort() already applies to its own authFailure
307
+ // outcome (see ../abort.mjs). The branch is already pushed; only
308
+ // the PR itself is skipped.
309
+ log(`[Publish PR Skipped] could not raise a PR for branch '${validated.branch}' -> '${validated.baseBranch}' (branch is pushed) due to an unrecoverable VCS auth failure: ${prResult.error}`);
310
+ } else {
311
+ throw new CommandError(
312
+ `[Publish PR Failed] VCSModule create-pull-request failed for branch '${validated.branch}' -> '${validated.baseBranch}': ${prResult.error}`,
313
+ { details: { branch: validated.branch, baseBranch: validated.baseBranch, error: prResult.error } }
314
+ );
315
+ }
316
+ } else if (prResult.alreadyExists) {
317
+ log(`Publish PR: a PR for branch '${validated.branch}' already exists -- treating as idempotent success.`);
318
+ }
319
+ }
320
+ }
321
+
322
+ return { pushed: true };
323
+ }
@@ -0,0 +1,232 @@
1
+ // =============================================================================
2
+ // PHASE MODULE: Re-Review (apra-fleet-3swo.6.8).
3
+ //
4
+ // The EIGHTH of runSprintCycle's twelve phase() boundaries -- the ONE fresh
5
+ // review Cycle Evaluation dispatches when the goal-priority bead count already
6
+ // reads 0 but no review ran THIS cycle (the Develop/Review loop was skipped
7
+ // because there were no ready beads). Without it the exit decision would rest
8
+ // on a verdict from an earlier cycle, or the loop would spin with no way to
9
+ // confirm completion. Like ./review.mjs it then has the ORCHESTRATOR -- never
10
+ // the LLM -- apply every structured transition the verdict asks for (guarded
11
+ // reopens, validated newTask creation) before D-pushing the beads it just
12
+ // mutated. Moved verbatim out of runner.js: every prompt, log line, dispatch
13
+ // option, validation branch and sync call is byte-identical to the inline
14
+ // version, so the golden transcript is unchanged. Move-only, no behaviour
15
+ // change.
16
+ //
17
+ // WHERE THIS PHASE STARTS AND STOPS. It is the body of Cycle Evaluation's
18
+ // `if (openAtGoal.length === 0 && !reviewedThisCycle)` branch, and nothing
19
+ // else -- from its own phase() call to the post-mutation
20
+ // `gitSync.syncBeadsAfter(...)` that closes it. The `if` itself stays in
21
+ // runner.js because it is built out of Cycle Evaluation's own freshly-read
22
+ // counts, exactly as ./deploy.mjs's `if (hasDeploy)` probe and ./replan.mjs's
23
+ // `if (eligibleReplan.length > 0)` filter stayed behind; the
24
+ // stillOpenVerifyIds exit gate that follows it belongs to Cycle Evaluation,
25
+ // not to this phase.
26
+ //
27
+ // THE GUARDED VERDICT PATH IS NOT OPTIONAL. apra-fleet-3swo.4.7 brought this
28
+ // site's reopenIds under the SHARED applyGuardedReopens() path from
29
+ // ../beads-transitions.mjs -- it was previously the only one of the three
30
+ // verdict sites applying reopens with NO goal-scope guard, so a below-goal
31
+ // DEFERRED bead named here was pulled back into a sprint that no longer
32
+ // targeted it. That import, and the Re-review reopenIds site it wraps, moved
33
+ // here INTACT: this module must never grow a private reopen loop or a private
34
+ // allowlist of its own (pinned by
35
+ // test/beads-transitions-extraction.test.mjs, which now scans runner.js,
36
+ // phases/review.mjs and this file as separate sources and asserts which one
37
+ // owns which of the three sites).
38
+ //
39
+ // EXPLICIT STATE, NOT A CLOSURE -- AND WHY THREE VALUES COME BACK. Same shape
40
+ // as ./review.mjs, whose newTasks half this phase mirrors line for line.
41
+ // `rejectedNewTasks` is an array this phase PUSHES to, so passing the array
42
+ // itself is exactly equivalent to the closure it replaces. The three genuinely
43
+ // REASSIGNED values -- `lastReviewVerdict` and `reviewedThisCycle` (which the
44
+ // exit decision immediately below this phase's call site reads) and
45
+ // `pendingRejectedNewTasks` (which trackRejectedNewTaskForResurfacing()/
46
+ // clearResubmittedNewTask() return a NEW list from every time) -- are passed
47
+ // in and returned instead.
48
+ //
49
+ // WHY SOME HELPERS ARE INJECTED RATHER THAN IMPORTED. dispatchReview,
50
+ // bdListScoped, goalMax, recordReopen, childIdAllocator and sprintMutexId are
51
+ // runSprintCycle-scoped locals, so there is nothing to import. computeChildFloor,
52
+ // createChildBeadWithAllocatedId, trackRejectedNewTaskForResurfacing and
53
+ // clearResubmittedNewTask are exported BY runner.js; importing them here would
54
+ // make phases/re-review.mjs <-> runner.js a circular pair for the sake of four
55
+ // helpers, so they come through the state argument instead -- the same rule
56
+ // ./review.mjs's header states. The dependencies that live in real sibling
57
+ // modules (applyGuardedReopens from ../beads-transitions.mjs, validateNewTask/
58
+ // appendRejectedFindingToParentNotes/persistNewTaskBestEffort from ../abort.mjs)
59
+ // are imported directly.
60
+ //
61
+ // GUARD COVERAGE: registered as 'phases/re-review.mjs' in
62
+ // ../guarded-modules.mjs. It took NO command() call site out of runner.js --
63
+ // its reopen and newTask writes reach bd through injected helpers that issue
64
+ // their own command() calls in the modules that already own them, exactly as
65
+ // ./review.mjs's do -- and NO dispatchRole() site either: the reviewer ladder
66
+ // runs through runner.js's shared dispatchReview() helper, which the per-round
67
+ // Review and Final Review phases call too. Its only repo-side effect is the
68
+ // shared gitSync bracket at the end. Both zero baselines are pinned rather
69
+ // than assumed, so a future edit that reaches for a raw command() here turns
70
+ // red instead of landing on an unguarded site.
71
+ // =============================================================================
72
+
73
+ import { applyGuardedReopens } from '../beads-transitions.mjs';
74
+ import {
75
+ validateNewTask, appendRejectedFindingToParentNotes, persistNewTaskBestEffort,
76
+ } from '../abort.mjs';
77
+
78
+ /**
79
+ * Runs the Re-Review phase: one fresh review of the CURRENT state, plus the
80
+ * orchestrator-applied transitions its verdict asks for.
81
+ *
82
+ * @param {object} state Explicit phase state; see this file's header.
83
+ * @returns {Promise<{
84
+ * lastReviewVerdict: string|undefined,
85
+ * reviewedThisCycle: boolean,
86
+ * pendingRejectedNewTasks: object[],
87
+ * }>} The three REASSIGNED values described in the header. Every other output
88
+ * of this phase is an in-place mutation of an array the caller still holds.
89
+ */
90
+ export async function runReReviewPhase({
91
+ // Presentation + dispatch seams.
92
+ phase,
93
+ log,
94
+ command,
95
+ // Sprint identity/config.
96
+ cycle,
97
+ validated,
98
+ targetIssues,
99
+ orchestratorMember,
100
+ // The git/beads sync bracket this phase's post-mutation D-push goes
101
+ // through.
102
+ gitSync,
103
+ // Mutated in place; never reassigned by this phase (see header).
104
+ rejectedNewTasks,
105
+ // Reassigned, so passed in and returned (see header).
106
+ lastReviewVerdict,
107
+ reviewedThisCycle,
108
+ pendingRejectedNewTasks,
109
+ // runSprintCycle-scoped locals and runner.js-exported helpers, injected
110
+ // rather than imported (see header).
111
+ dispatchReview,
112
+ bdListScoped,
113
+ goalMax,
114
+ recordReopen,
115
+ childIdAllocator,
116
+ sprintMutexId,
117
+ computeChildFloor,
118
+ createChildBeadWithAllocatedId,
119
+ trackRejectedNewTaskForResurfacing,
120
+ clearResubmittedNewTask,
121
+ }) {
122
+ phase(`Re-Review C${cycle}`);
123
+ log(
124
+ `Cycle ${cycle}: 0 open goal-priority bead(s) but no review ran THIS cycle (Develop/Review ` +
125
+ `loop was skipped) -- dispatching a fresh re-review of the current state before deciding ` +
126
+ `whether to exit, rather than trusting a verdict from an earlier cycle.`
127
+ );
128
+ const reReviewScope = await bdListScoped('--json');
129
+ // apra-fleet-jfo.3: this call passed beadIds: [] unconditionally,
130
+ // which buildReviewerPrompt renders as "Review the work just done
131
+ // for the following bead id(s): ." -- no ids to review. The
132
+ // reviewer correctly treats that as missing required input and
133
+ // refuses (a CHANGES_NEEDED-shaped response with empty
134
+ // reopenIds/newTasks), which after one retry throws
135
+ // ReviewerContractViolationError and aborts the WHOLE sprint --
136
+ // hit live 2026-08-02 on apra-fleet-l7n-style sprints (Deploy
137
+ // fails on cycle 1 -> IntegTest skipped -> openAtGoal reads 0 ->
138
+ // this branch -> crash, before the sprint ever gets a real
139
+ // chance). The sprint's own root issue id(s) are always a valid,
140
+ // in-scope target for "review the current state" -- pass them as
141
+ // beadIds so the reviewer has something concrete to ground its
142
+ // verdict in; acceptanceCriteriaJson still carries the full scope
143
+ // for context.
144
+ const reReviewVerdict = await dispatchReview({ beadIds: targetIssues, acceptanceCriteriaJson: JSON.stringify(reReviewScope) });
145
+ lastReviewVerdict = reReviewVerdict.verdict;
146
+ reviewedThisCycle = true;
147
+
148
+ // Same orchestrator-applies-the-transition contract as the
149
+ // regular Develop/Review dispatch above: a re-review that
150
+ // reopens beads or proposes follow-up work must have those
151
+ // effects actually applied, not silently discarded just because
152
+ // this dispatch happened outside the normal Develop loop.
153
+ //
154
+ // apra-fleet-3swo.4.7: this site used to apply reopenIds with NO
155
+ // goal-scope guard -- the only one of the three verdict sites that
156
+ // did. It now goes through the same applyGuardedReopens() path as
157
+ // the per-round reviewer and Final Review, so a below-goal
158
+ // DEFERRED bead named here is skipped with the identical
159
+ // "deferred scope, not reopened" outcome instead of being pulled
160
+ // back into a sprint that no longer targets it.
161
+ await applyGuardedReopens({
162
+ entries: reReviewVerdict.reopenIds,
163
+ bdListScoped, goalMax, goal: validated.goal, log, command,
164
+ member: orchestratorMember,
165
+ logPrefix: 'Re-review reopenIds',
166
+ buildReopenCommand: ({ id }) => ({
167
+ cmd: `bd update ${id} --status=open`,
168
+ label: `Reopen ${id} per re-review verdict`,
169
+ }),
170
+ // Track per-bead reopen counts for reopen-thrash detection.
171
+ onReopened: ({ id }) => recordReopen(id),
172
+ });
173
+ for (const newTask of reReviewVerdict.newTasks) {
174
+ const validation = validateNewTask(newTask);
175
+ if (!validation.ok) {
176
+ log(`Re-review newTasks: REJECTED (not sent to bd create) -- ${validation.reason}`);
177
+ rejectedNewTasks.push({ cycle, reason: validation.reason, raw: newTask });
178
+ // Track it for resurfacing into the NEXT planning-phase
179
+ // dispatch too -- see trackRejectedNewTaskForResurfacing()'s
180
+ // doc comment.
181
+ pendingRejectedNewTasks = trackRejectedNewTaskForResurfacing(pendingRejectedNewTasks, {
182
+ title: newTask && newTask.title, description: newTask && newTask.description,
183
+ reason: validation.reason, cycle,
184
+ });
185
+ // Never let a rejected finding vanish -- persist it verbatim
186
+ // to the parent bead's notes as a fallback (non-fatal;
187
+ // degrades to the run log).
188
+ try {
189
+ await appendRejectedFindingToParentNotes({
190
+ command, member: orchestratorMember, parentId: targetIssues[0],
191
+ newTask, reason: validation.reason, cycle, log,
192
+ });
193
+ } catch (noteErr) {
194
+ log(`[fleet-sprint] rejected-finding notes fallback FAILED (non-fatal): ${noteErr.message}; finding preserved VERBATIM in this run log: ${JSON.stringify(newTask)}`);
195
+ }
196
+ continue;
197
+ }
198
+ const { title, description, priority } = validation;
199
+ // A bead can only have one parent -- when multiple sprint-root
200
+ // target issues are given, file follow-up work under the first
201
+ // one. `--parent` never accepts a comma-joined list; passing one
202
+ // silently creates an unparented/misparented bead.
203
+ //
204
+ // Same allocator-minted id path as the Develop/Review newTasks
205
+ // site above -- concurrent sprints must never mint the same child
206
+ // id under a shared parent.
207
+ const persisted = await persistNewTaskBestEffort({
208
+ command, member: orchestratorMember, parentId: targetIssues[0],
209
+ newTask, cycle, log, stage: 're-review',
210
+ createFn: async () => {
211
+ const floor = await computeChildFloor({ command, member: orchestratorMember, parentId: targetIssues[0], log });
212
+ await createChildBeadWithAllocatedId({
213
+ command, allocator: childIdAllocator, member: orchestratorMember,
214
+ title, description, priority, parentId: targetIssues[0],
215
+ sprintId: sprintMutexId, floor, log,
216
+ label: `Create follow-up task from re-review newTasks: ${title}`,
217
+ });
218
+ },
219
+ });
220
+ // Same resurface-list bookkeeping (title+description) as the
221
+ // Develop/Review newTasks site above.
222
+ if (persisted) {
223
+ pendingRejectedNewTasks = clearResubmittedNewTask(pendingRejectedNewTasks, { title, description });
224
+ }
225
+ }
226
+
227
+ // D-push the orchestrator's applied re-review reopens/newTask
228
+ // creates, same as the Develop/Review transition site above.
229
+ await gitSync.syncBeadsAfter(orchestratorMember, { pushBeads: true });
230
+
231
+ return { lastReviewVerdict, reviewedThisCycle, pendingRejectedNewTasks };
232
+ }