@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,581 @@
1
+ // =============================================================================
2
+ // MEMBER SYNC -- the per-member git/dolt sync brackets
3
+ // (apra-fleet-3swo.6.10)
4
+ // =============================================================================
5
+ //
6
+ // Moved VERBATIM out of runner.js. This module owns the four bracket entry
7
+ // points the orchestrator wraps every dispatch (and every resume) in:
8
+ //
9
+ // 1. syncMemberBefore() -- G-pull: fetch + ff-only merge (or a reset to the
10
+ // remote tip on a mutating retry) before a member does any work.
11
+ // 2. syncMemberAfter() -- G-push: push, with ONE bounded pull-rebase retry
12
+ // and the Tier 2 conflict-resolution dispatch behind it.
13
+ // 3. syncMemberAfterOrdered() -- the ordered post-dispatch step: G-push
14
+ // (code) BEFORE D-push (beads), so a bead close can never be published
15
+ // ahead of the code that justifies it.
16
+ // 4. resyncReacquiredMember() -- the resume path's unconditional
17
+ // re-reconciliation of ONE member that was just re-acquired.
18
+ //
19
+ // These are the CALLERS of the git-topology layer (./git-topology.mjs), not
20
+ // part of it: every git command they issue goes through runGitStep, and every
21
+ // failure they classify goes through resolveGitProviderForClassification.
22
+ // git-topology.mjs's own header records that these four deliberately stayed in
23
+ // runner.js when it was extracted; they now live here, which is why this
24
+ // extraction had to run AFTER that one -- the other order would have forced a
25
+ // temporary back-import from runner.js into the new module.
26
+ //
27
+ // WHY resolveSettleShell did NOT move with them: syncMemberAfterOrdered calls
28
+ // it to resolve the member's registered shell before building the dolt-settle
29
+ // callback, but it stays DEFINED IN runner.js and is imported back from there
30
+ // (see the import below for the anchoring test and the call-site split). It was
31
+ // module-private before this extraction and is now merely exported so this
32
+ // module can reach it; it is not otherwise part of runner.js's moved surface.
33
+ //
34
+ // GUARD REGISTRATION: this module is registered in ./guarded-modules.mjs as
35
+ // part of this extraction (see that file's STANDING RULE). It carries
36
+ // syncMemberAfter's one member_name-bearing command() site -- the Tier 2
37
+ // post-resolution `git status --porcelain` read -- and, more importantly, it
38
+ // is where syncMemberAfterOrdered now lives, which is the sanctioned wrapper
39
+ // unbracketed-push-guard.mjs resolves BY NAME WITHIN A FILE: its bare
40
+ // syncMemberAfter()/DoltSync.syncAfter() calls stay sanctioned only because
41
+ // the wrapper that contains them travelled here with them.
42
+ //
43
+ // Dependency-injection stance is unchanged: nothing here does I/O of its own.
44
+ // Every git command is issued via an injected command() with an explicit
45
+ // `member_name`, and the resume path's git/dolt runners are injected too, so
46
+ // unit tests drive all of it with no live fleet.
47
+ // =============================================================================
48
+
49
+ import { GitDivergedError, GitSyncError } from './errors.mjs';
50
+ import { runGitStep, resolveGitProviderForClassification } from './git-topology.mjs';
51
+ import { parseUnmergedPaths, detectAndAbortRebaseConflict, dispatchConflictResolutionAgent } from './conflict-ladder.mjs';
52
+ import { DoltSync } from './dolt-sync.mjs';
53
+ import { buildSettleCallback } from './dolt-settle.mjs';
54
+ import { decideEnsureBranchAction } from './branch-ensure.mjs';
55
+ // resolveSettleShell stays in runner.js: test/sprint-state.test.mjs anchors it
56
+ // there by symbol ('resolveSettleShell must still exist in runner.js'), and six
57
+ // of its seven call sites are runner.js's own orchestrator-side settle brackets.
58
+ // This is the same runner.js back-import abort.mjs, prompts.mjs and worklists.mjs
59
+ // already use; nothing here touches it at module-evaluation time, so the cycle
60
+ // resolves through the hoisted function declaration at call time.
61
+ import { resolveSettleShell } from './runner.js';
62
+
63
+ // ---------------------------------------------------------------------------
64
+ // Orchestrator-bracketed git sync helpers
65
+ // ---------------------------------------------------------------------------
66
+ //
67
+ // Stance: SINGLE-WRITER TOKEN PASSING. The writer pushes, then the next reader
68
+ // pulls, so every intra-sprint git merge is fast-forward BY CONSTRUCTION. A
69
+ // non-FF result is therefore not a merge to resolve -- it is proof the
70
+ // invariant is already broken, so it is a HARD, TYPED error
71
+ // (GitDivergedError), never auto-resolved.
72
+ //
73
+ // Every bracket must fail-soft-with-retry in a way that DISTINGUISHES
74
+ // transient-retry (network unreachable, an index/ref lock) from diverged-abort
75
+ // (non-FF, unmerged/conflicted paths). A diverged state must NEVER be retried
76
+ // blindly. classifyGitFailure() is that classifier -- it moved to
77
+ // ./git-topology.mjs with runGitStep (apra-fleet-3swo.6.3); the two failure
78
+ // classes surface as two distinct WorkflowError subclasses (GitSyncError vs
79
+ // GitDivergedError) so callers and tests can assert them apart.
80
+ //
81
+ // Every git command is issued via the injected command() with an explicit
82
+ // `member_name` -- agents never run sync themselves; the orchestrator brackets
83
+ // each dispatch. `command` is dependency-injected so unit tests can drive these
84
+ // helpers with a mock command() and no live fleet.
85
+
86
+ /**
87
+ * True when `error` is git's exact "the named ref does not exist on the
88
+ * remote" message (`fatal: couldn't find remote ref <branch>`), as opposed to
89
+ * any other fetch/pull/rebase failure. This is the ONE place that text is
90
+ * matched (apra-fleet-ta3.3): syncMemberBefore's pre-dispatch fetch and
91
+ * syncMemberAfter's post-push pull-rebase both hit this exact message for the
92
+ * identical underlying reason -- a brand-new local branch that has never been
93
+ * pushed to `remote` yet, so there is nothing there to fetch/rebase against --
94
+ * and both treat it as a benign no-op / retry-directly signal via this shared
95
+ * predicate rather than each carrying its own copy of the regex.
96
+ * @param {string} error - the raw git stderr/stdout of a failed command
97
+ * @returns {boolean}
98
+ */
99
+ export function isMissingRemoteRefError(error) {
100
+ return /couldn't find remote ref/i.test(error || '');
101
+ }
102
+
103
+ /**
104
+ * G-pull: bring `member` up to the shared branch tip before it does any work --
105
+ * `git fetch` then `git merge --ff-only`. Because of single-writer token
106
+ * passing this merge is fast-forward by construction; a non-FF result is a
107
+ * distinct typed GitDivergedError (NOT a generic failure), never auto-merged.
108
+ * Transient (network/lock) failures are retried up to `maxTransientRetries`;
109
+ * divergence is never retried.
110
+ *
111
+ * Every git command is issued via the injected command() with an explicit
112
+ * member_name.
113
+ *
114
+ * An optional injected `onAuthFailure` is threaded through to runGitStep's
115
+ * bounded one-shot self-heal, since a stale token can break a pull as easily as
116
+ * a push.
117
+ *
118
+ * An optional `resetToRemoteTip` (default false) changes the pull half from
119
+ * `git merge --ff-only` to `git reset --hard <remote>/<branch>` so a RETRIED
120
+ * doer dispatch resumes on the published tip instead of failing on (or
121
+ * re-committing over) a divergence its own prior attempt left behind. It must
122
+ * only be set on a retry that may have mutated state (withGitSync's
123
+ * resumeOntoRemoteTip); omitting it keeps the ff-only-merge behaviour for every
124
+ * first attempt.
125
+ *
126
+ * apra-fleet-417.7: an optional injected `resolveMemberProvider` (see
127
+ * createMemberVcsProviderResolver) is resolved ONCE at the top of this call
128
+ * and threaded into every runGitStep call below, so a G-pull auth failure for
129
+ * a non-GitHub member classifies via that member's own provider chain.
130
+ *
131
+ * @param {string} member
132
+ * @param {{ command: Function, log?: Function, maxTransientRetries?: number, remote?: string, branch?: string, onAuthFailure?: Function, resetToRemoteTip?: boolean, resolveMemberProvider?: (member: string) => Promise<string|undefined> }} opts
133
+ * @returns {Promise<{ ok: true, member: string }>}
134
+ */
135
+ export async function syncMemberBefore(member, opts = {}) {
136
+ const { command, log = () => {}, maxTransientRetries = 1, remote = 'origin', branch, onAuthFailure, resetToRemoteTip = false, resolveMemberProvider } = opts;
137
+ if (typeof command !== 'function') {
138
+ throw new Error("syncMemberBefore requires an injected command() in opts");
139
+ }
140
+ const provider = await resolveGitProviderForClassification(resolveMemberProvider, member, log);
141
+
142
+ const fetchCmd = branch ? `git fetch ${remote} ${branch}` : `git fetch ${remote}`;
143
+ const fetch = await runGitStep({
144
+ command, member, cmd: fetchCmd,
145
+ label: `G-pull fetch for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
146
+ });
147
+ if (!fetch.ok) {
148
+ // A brand-new sprint branch created locally from base, before its
149
+ // first G-push, makes this fetch fail with "couldn't find remote ref
150
+ // <branch>". That is a benign, expected state: there is nothing on the
151
+ // remote to pull, so the bracket's pull half is a no-op, not an error.
152
+ // Only this precise git message may be treated as
153
+ // branch-doesn't-exist; anything else must still surface.
154
+ if (isMissingRemoteRefError(fetch.error)) {
155
+ log(`[Sync] G-pull for member '${member}': branch '${branch}' does not exist on '${remote}' yet (not pushed); skipping pull (nothing to sync down).`);
156
+ return { ok: true, member };
157
+ }
158
+ // A fetch cannot "diverge" -- any failure here is transient-exhausted
159
+ // or unknown; surface it as a (non-diverged) sync error.
160
+ throw new GitSyncError(
161
+ `[Sync] G-pull fetch failed for member '${member}': ${fetch.error}`,
162
+ { member, gitOutput: fetch.error },
163
+ );
164
+ }
165
+
166
+ // On a RETRIED dispatch whose prior attempt was not provably a no-mutation
167
+ // failure (it may have committed and/or pushed its streak), `git merge
168
+ // --ff-only` is the wrong recovery: if the prior attempt pushed and the
169
+ // local tip then diverged with a re-implemented duplicate commit, the
170
+ // ff-only merge raises GitDivergedError and the streak can NEVER resume,
171
+ // because every subsequent push/merge fails non-fast-forward. Hard-resetting
172
+ // onto the freshly fetched remote tip makes the retry resume ON TOP of
173
+ // already-published work instead of re-committing it. Only the code checkout
174
+ // is touched (beads live in a separate Dolt clone); a local commit that was
175
+ // never published is intentionally dropped and simply re-done by the retry,
176
+ // which is what prevents the divergent duplicate commit. A concrete branch
177
+ // is required to name a remote tip; without one this falls through to the
178
+ // ff-only merge below.
179
+ if (resetToRemoteTip && branch) {
180
+ const resetTarget = `${remote}/${branch}`;
181
+ const reset = await runGitStep({
182
+ command, member, cmd: `git reset --hard ${resetTarget}`,
183
+ label: `G-pull reset-to-remote-tip for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
184
+ });
185
+ if (!reset.ok) {
186
+ throw new GitSyncError(
187
+ `[Sync] G-pull reset-to-remote-tip failed for member '${member}': ${reset.error}`,
188
+ { member, gitOutput: reset.error },
189
+ );
190
+ }
191
+ log(`[Sync] G-pull for member '${member}': hard-reset local branch onto '${resetTarget}' so a retried dispatch resumes on the published tip instead of re-committing.`);
192
+ return { ok: true, member };
193
+ }
194
+
195
+ const mergeCmd = branch ? `git merge --ff-only ${remote}/${branch}` : 'git merge --ff-only';
196
+ const merge = await runGitStep({
197
+ command, member, cmd: mergeCmd,
198
+ label: `G-pull ff-only merge for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
199
+ });
200
+ if (!merge.ok) {
201
+ if (merge.kind === 'diverged') {
202
+ throw new GitDivergedError(
203
+ `[Sync] G-pull for member '${member}' could not fast-forward -- it has DIVERGED from the shared branch and must not be auto-merged: ${merge.error}`,
204
+ { member, gitOutput: merge.error, operation: 'pull' },
205
+ );
206
+ }
207
+ throw new GitSyncError(
208
+ `[Sync] G-pull ff-only merge failed for member '${member}': ${merge.error}`,
209
+ { member, gitOutput: merge.error },
210
+ );
211
+ }
212
+
213
+ return { ok: true, member };
214
+ }
215
+
216
+ /**
217
+ * G-push: publish `member`'s committed work to the shared branch after a
218
+ * dispatch -- `git push` with ONE bounded pull-rebase retry. If the
219
+ * push is rejected as non-FF (another writer got there first), do a single
220
+ * `git pull --rebase` and re-push exactly once; if it is STILL rejected, raise
221
+ * a typed GitDivergedError -- the single-writer invariant is violated and the
222
+ * push must never be retried further/blindly. Transient (network/lock)
223
+ * failures are retried up to `maxTransientRetries`; divergence is never
224
+ * retried beyond the one bounded rebase.
225
+ *
226
+ * `pushCode: false` makes this a no-op (a read-only bracket has nothing to
227
+ * publish). Every git command is issued via the injected command() with an
228
+ * explicit member_name.
229
+ *
230
+ * Tier 2 of the git conflict ladder: when the pull-rebase retry hits a REAL
231
+ * content conflict (unmerged paths, not just a plain non-FF race), an optional
232
+ * injected `agent()` gets exactly ONE bounded conflict-resolution-runbook
233
+ * dispatch before this function gives up and throws the typed
234
+ * GitDivergedError. The agent's own claim of success is never trusted: this
235
+ * function mechanically re-checks `git status --porcelain` for a clean tree and
236
+ * then attempts one real re-push; only that observed outcome decides whether
237
+ * Tier 2 resolved the conflict. Omitting `agent` leaves Tier 1 only.
238
+ *
239
+ * An optional injected `onAuthFailure` is threaded through to every runGitStep
240
+ * call below for a bounded one-shot self-heal (call it once, retry the same
241
+ * command once) whenever a step is classified 'auth'.
242
+ *
243
+ * apra-fleet-417.7: an optional injected `resolveMemberProvider` (see
244
+ * createMemberVcsProviderResolver) is resolved ONCE at the top of this call
245
+ * and threaded into every runGitStep call below, so a G-push auth failure for
246
+ * a non-GitHub member classifies via that member's own provider chain.
247
+ *
248
+ * @param {string} member
249
+ * @param {{
250
+ * command: Function, pushCode?: boolean, log?: Function,
251
+ * maxTransientRetries?: number, remote?: string, branch?: string,
252
+ * agent?: Function, resolveConflictModel?: string, onAuthFailure?: Function,
253
+ * resolveMemberProvider?: (member: string) => Promise<string|undefined>,
254
+ * }} opts
255
+ * @returns {Promise<{ ok: true, member: string, pushed: boolean, rebased: boolean, tier2Resolved?: boolean }>}
256
+ */
257
+ export async function syncMemberAfter(member, opts = {}) {
258
+ const {
259
+ command, pushCode = true, log = () => {}, maxTransientRetries = 1, remote = 'origin', branch,
260
+ agent, resolveConflictModel, onAuthFailure, resolveMemberProvider, setUpstream = false,
261
+ } = opts;
262
+ if (typeof command !== 'function') {
263
+ throw new Error("syncMemberAfter requires an injected command() in opts");
264
+ }
265
+
266
+ if (!pushCode) {
267
+ return { ok: true, member, pushed: false, rebased: false };
268
+ }
269
+ const provider = await resolveGitProviderForClassification(resolveMemberProvider, member, log);
270
+
271
+ // apra-fleet: `setUpstream` (opt-in, default false -- every existing
272
+ // caller's command text is byte-for-byte unchanged) is for Publish PR's
273
+ // push specifically: it needs `-u` to set the tracking branch on a brand
274
+ // new sprint branch's first push, AND that distinct spelling is what lets
275
+ // mock-sprint-publish-push-failure.test.mjs's `gitGhFailurePattern` (and
276
+ // any real-world log grep) target Publish's push in isolation from every
277
+ // OTHER per-dispatch G-push in the same sprint, which all share the plain
278
+ // `git push <remote> <branch>` spelling below.
279
+ const pushCmd = branch ? `git push${setUpstream ? ' -u' : ''} ${remote} ${branch}` : 'git push';
280
+
281
+ let push = await runGitStep({
282
+ command, member, cmd: pushCmd,
283
+ label: `G-push for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
284
+ });
285
+ if (push.ok) {
286
+ return { ok: true, member, pushed: true, rebased: false };
287
+ }
288
+
289
+ if (push.kind !== 'diverged') {
290
+ // Transient-exhausted or unknown non-FF failure -- not a divergence,
291
+ // so no rebase retry; surface the (non-diverged) sync error.
292
+ throw new GitSyncError(
293
+ `[Sync] G-push for member '${member}' failed: ${push.error}`,
294
+ { member, gitOutput: push.error },
295
+ );
296
+ }
297
+
298
+ // Non-FF push: attempt EXACTLY ONE pull --rebase then re-push.
299
+ log(`[Sync] G-push for member '${member}' was rejected as non-fast-forward; attempting a single pull --rebase then one re-push.`);
300
+ const rebaseCmd = branch ? `git pull --rebase ${remote} ${branch}` : 'git pull --rebase';
301
+ const rebase = await runGitStep({
302
+ command, member, cmd: rebaseCmd,
303
+ label: `G-push pull-rebase retry for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
304
+ });
305
+ if (!rebase.ok) {
306
+ // Missing-remote-ref guard (apra-fleet-ta3.3). ROOT CAUSE: the
307
+ // initial push above can be classified 'diverged' even when `remote`
308
+ // has NO such branch at all -- git's non-fast-forward rejection
309
+ // trailers ("failed to push some refs", "[rejected]") are GENERIC:
310
+ // they are also the trailer git prints for other push rejections,
311
+ // and nothing in that first push's own error text can distinguish
312
+ // "the remote branch exists and truly diverged" from "the remote
313
+ // branch does not exist yet". The only place that distinction
314
+ // becomes observable is here: `git pull --rebase` against a
315
+ // nonexistent remote branch fails with the SAME exact, unambiguous
316
+ // "couldn't find remote ref <branch>" message syncMemberBefore
317
+ // already treats as benign (see isMissingRemoteRefError() above) --
318
+ // so this is not a divergence to reconcile, it is a brand-new local
319
+ // branch that has simply never been pushed. Skip the doomed
320
+ // rebase/conflict machinery entirely and retry a plain push, which
321
+ // creates the branch on `remote`.
322
+ if (isMissingRemoteRefError(rebase.error)) {
323
+ log(`[Sync] G-push pull-rebase for member '${member}': branch '${branch}' does not exist on '${remote}' yet (never pushed) -- nothing to rebase against; retrying the push directly to create it.`);
324
+ const createPush = await runGitStep({
325
+ command, member, cmd: pushCmd,
326
+ label: `G-push retry (create missing remote branch) for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
327
+ });
328
+ if (createPush.ok) {
329
+ return { ok: true, member, pushed: true, rebased: false };
330
+ }
331
+ if (createPush.kind === 'diverged') {
332
+ // The branch now exists on the remote -- a concurrent writer
333
+ // must have published it between our rebase attempt and this
334
+ // retry. That IS a genuine divergence; the single-writer
335
+ // invariant is violated and this must not be retried further.
336
+ throw new GitDivergedError(
337
+ `[Sync] G-push for member '${member}' was rejected on retry after a missing-remote-ref rebase skip -- another writer published '${branch}' first; the single-writer token invariant is violated: ${createPush.error}`,
338
+ { member, gitOutput: createPush.error, operation: 'push' },
339
+ );
340
+ }
341
+ throw new GitSyncError(
342
+ `[Sync] G-push retry (create missing remote branch) for member '${member}' failed: ${createPush.error}`,
343
+ { member, gitOutput: createPush.error },
344
+ );
345
+ }
346
+
347
+ // Tier 1 scripted detection: confirm from git's own porcelain status --
348
+ // not from this failing command's exit code/message classification --
349
+ // whether the rebase actually left unmerged paths, and if so restore a
350
+ // clean tree via `git rebase --abort` BEFORE the typed divergence error
351
+ // below propagates. This is the single Tier 1 -> Tier 2 escalation
352
+ // point.
353
+ const unmergedPaths = await detectAndAbortRebaseConflict({ command, member, log, maxTransientRetries, runGitStep });
354
+
355
+ // Tier 2: unmergedPaths.length > 0 means a real content conflict, not
356
+ // just a non-FF race. Attempt exactly ONE bounded agent-with-runbook
357
+ // dispatch (when an agent() was injected) before falling back to the
358
+ // typed GitDivergedError below. Every outcome (agent throws, agent
359
+ // returns, or agent unavailable) is mechanically re-verified against
360
+ // real git state -- never the agent's own claim.
361
+ if (unmergedPaths.length > 0 && typeof agent === 'function') {
362
+ try {
363
+ await dispatchConflictResolutionAgent({
364
+ agent, member, branch, unmergedPaths, log, model: resolveConflictModel, remote,
365
+ });
366
+ } catch (tier2Err) {
367
+ log(`[Sync] Tier 2 conflict-resolution dispatch for member '${member}' threw and will not be retried (script-first: no further escalation): ${tier2Err.message}`);
368
+ }
369
+
370
+ const postTier2Status = await command('git status --porcelain', { member_name: member, silent: true, failSoft: true, label: `Tier 2 post-resolution clean-state check for '${member}'` });
371
+ const stillUnmerged = parseUnmergedPaths(postTier2Status && postTier2Status.output ? postTier2Status.output : '');
372
+ if (stillUnmerged.length === 0) {
373
+ const rePush = await runGitStep({
374
+ command, member, cmd: pushCmd,
375
+ label: `G-push after Tier 2 conflict resolution for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
376
+ });
377
+ if (rePush.ok) {
378
+ log(`[Sync] Tier 2 conflict resolution for member '${member}' succeeded -- working tree clean and the resolved code was pushed.`);
379
+ return { ok: true, member, pushed: true, rebased: true, tier2Resolved: true };
380
+ }
381
+ log(`[Sync] Tier 2 conflict resolution for member '${member}' left a clean tree but the re-push still failed: ${rePush.error}`);
382
+ } else {
383
+ log(`[Sync] Tier 2 conflict resolution for member '${member}' did not fully resolve -- porcelain still shows unmerged path(s): ${stillUnmerged.join(', ')}. Restoring a clean tree before failing this streak.`);
384
+ await detectAndAbortRebaseConflict({ command, member, log, maxTransientRetries, runGitStep });
385
+ }
386
+ }
387
+
388
+ if (rebase.kind === 'diverged' || unmergedPaths.length > 0) {
389
+ throw new GitDivergedError(
390
+ `[Sync] G-push pull-rebase for member '${member}' hit unmergeable divergence (conflict) -- must not be retried blindly: ${rebase.error}`,
391
+ { member, gitOutput: rebase.error, operation: 'push-rebase', details: { unmergedPaths } },
392
+ );
393
+ }
394
+ throw new GitSyncError(
395
+ `[Sync] G-push pull-rebase for member '${member}' failed: ${rebase.error}`,
396
+ { member, gitOutput: rebase.error },
397
+ );
398
+ }
399
+
400
+ push = await runGitStep({
401
+ command, member, cmd: pushCmd,
402
+ label: `G-push re-push after rebase for '${member}'`, log, maxTransientRetries, onAuthFailure, provider,
403
+ });
404
+ if (push.ok) {
405
+ return { ok: true, member, pushed: true, rebased: true };
406
+ }
407
+
408
+ // Still rejected after the one bounded rebase -- diverged, never retried further.
409
+ throw new GitDivergedError(
410
+ `[Sync] G-push for member '${member}' still rejected after one pull-rebase retry -- the single-writer token invariant is violated; refusing to retry further: ${push.error}`,
411
+ { member, gitOutput: push.error, operation: 'push' },
412
+ );
413
+ }
414
+
415
+ /**
416
+ * The ordered post-dispatch sync step every withGitSync() bracket's `finally`
417
+ * runs: G-push (code) BEFORE D-push (beads).
418
+ *
419
+ * For code-writing roles (pushCode:true), G-push MUST succeed before D-push is
420
+ * attempted. If G-push throws at all, D-push is skipped ENTIRELY and the error
421
+ * is rethrown, never swallowed -- closing a bead in dolt while the code that
422
+ * justifies the close never left this member's checkout would advertise an
423
+ * UNREACHABLE CLOSE: a reviewer, or the next streak's G-pull, would see the
424
+ * bead done and find no matching commit on the shared branch.
425
+ *
426
+ * With pushCode:false, syncMemberAfter never touches git and cannot throw, so
427
+ * D-push always still runs.
428
+ *
429
+ * `agent`/`resolveConflictModel` are threaded through to syncMemberAfter's
430
+ * conflict-resolution escalation; `onAuthFailure` is threaded through to BOTH
431
+ * syncMemberAfter and doltPushAfter for their bounded one-shot self-heal.
432
+ *
433
+ * @param {string} member
434
+ * @param {{
435
+ * command: Function, pushCode?: boolean, pushBeads?: boolean,
436
+ * log?: Function, mutex?: { acquire: Function, release: Function },
437
+ * sprintId?: string, branch?: string, maxTransientRetries?: number,
438
+ * remote?: string, agent?: Function, resolveConflictModel?: string,
439
+ * onAuthFailure?: Function,
440
+ * resolveMemberProvider?: (member: string) => Promise<string|undefined>,
441
+ * args?: { callTool?: Function },
442
+ * sprintState?: object,
443
+ * }} opts
444
+ * @returns {Promise<{ ok: true, member: string, gPush: object, dPush: object }>}
445
+ */
446
+ export async function syncMemberAfterOrdered(member, opts = {}) {
447
+ const {
448
+ command, pushCode = true, pushBeads = true, log = () => {},
449
+ mutex, sprintId, branch, maxTransientRetries = 1, remote = 'origin',
450
+ agent, resolveConflictModel, onAuthFailure, resolveMemberProvider, args, sprintState,
451
+ } = opts;
452
+
453
+ let gPush;
454
+ try {
455
+ gPush = await syncMemberAfter(member, { command, pushCode, log, branch, maxTransientRetries, remote, agent, resolveConflictModel, onAuthFailure, resolveMemberProvider });
456
+ } catch (gPushErr) {
457
+ log(`[Sync] G-push failed for member '${member}' -- skipping D-push and failing this streak rather than advertising an unreachable close (a beads close whose justifying code never reached the shared branch): ${gPushErr.message}`);
458
+ throw gPushErr;
459
+ }
460
+
461
+ // EXPLICITLY FATAL (apra-fleet-417.3.1): DoltSync.syncAfter is degraded by
462
+ // default, but this is the post-dispatch bracket -- the member's beads
463
+ // closes must reach the shared remote or the orchestrator's next read sees
464
+ // a bead this streak believes it closed. A silent degrade here would
465
+ // advertise an unreachable close, exactly what the G-push-before-D-push
466
+ // ordering above exists to prevent, and would erase the
467
+ // BEADS_SYNC_CONFLICT terminal reason the dashboard reports.
468
+ //
469
+ // Before that fatal divergence surfaces, run the deterministic settle
470
+ // (settleDoltConflicts, dolt-settle.mjs). It is TOTAL over row-level
471
+ // conflicts -- no gates, no allowlist, no LLM escalation -- and a resolved
472
+ // settle is a VERIFIED recovery, because settle republishes (bd dolt pull
473
+ // + push) and checks the push actually landed before returning. The streak
474
+ // only fails (DoltDivergedError -> BEADS_SYNC_CONFLICT) when settle itself
475
+ // hits an operational failure (no usable dolt binary, the ephemeral server
476
+ // would not start, a SQL statement errored).
477
+ //
478
+ // Notably, the data-loss hazard that forced the old ladder's Path B to be
479
+ // disabled at THIS call site does not exist for settle: it never discards
480
+ // and re-bootstraps a clone, so an arbitrary multi-command dispatch's bead
481
+ // mutations cannot be silently thrown away here. There is no pendingMutation
482
+ // to capture and replay because nothing is ever dropped.
483
+ // Thread this member's REGISTERED shell into dolt-settle the same way
484
+ // the pre-dispatch bracket does (apra-fleet-7dir.16/.24), guarded on
485
+ // `args.callTool` so a caller with no MCP client (mock-sprint scenarios)
486
+ // keeps the pre-shell-aware default.
487
+ const shell = await resolveSettleShell({ args, member, log, sprintState });
488
+ const settle = buildSettleCallback(member, { command, log, shell });
489
+ const dPush = await DoltSync.syncAfter(member, { command, pushBeads, log, mutex, sprintId, onAuthFailure, fatal: true, settle });
490
+ return { ok: true, member, gPush, dPush };
491
+ }
492
+
493
+ /**
494
+ * (apra-fleet-p2to.4.2) Re-sync ONE member that was just re-acquired on resume.
495
+ * Runs -- UNCONDITIONALLY, never gated on a "looks unchanged" heuristic -- the
496
+ * same three reconciliation steps a fresh dispatch would rely on, because while
497
+ * this sprint was paused both origin and the beads DB can have moved (another
498
+ * sprint, a human push) on top of the released member:
499
+ *
500
+ * 1. `git fetch` (base branch, then the sprint branch soft -- a brand-new
501
+ * branch legitimately has no remote ref yet).
502
+ * 2. The pure decideEnsureBranchAction() probe: fetch outcome + a local-branch
503
+ * existence probe + (when both tips exist) a two-way ancestor comparison,
504
+ * fed into the SAME decision helper the Ensure Sprint Branch phase uses.
505
+ * An 'abort' decision (fetch failed for a non-"missing ref" reason, or the
506
+ * tips diverged) THROWS rather than touch git -- resuming onto a diverged
507
+ * branch could silently discard real pushed work. A 'checkout' decision is
508
+ * executed so the member's working branch is reconciled to origin's new
509
+ * tip before work continues.
510
+ * 3. `bd dolt pull` -- re-sync the beads clone to whatever landed while paused.
511
+ *
512
+ * All I/O is injected so this stays transport-agnostic and unit-testable:
513
+ * - `runGit(cmd)` -> Promise<{ ok: boolean, stdout?: string, error?: string }>
514
+ * (a SOFT git runner: it never throws; this function decides which failures
515
+ * are fatal).
516
+ * - `doltPull(member)` -> Promise<any> (runs `bd dolt pull` on the member).
517
+ *
518
+ * @param {{ member: string, branch: string, baseBranch: string,
519
+ * runGit: (cmd: string) => Promise<{ ok: boolean, stdout?: string, error?: string }>,
520
+ * doltPull: (member: string) => Promise<any>, log?: Function }} opts
521
+ * @returns {Promise<void>}
522
+ */
523
+ export async function resyncReacquiredMember(opts = {}) {
524
+ const { member, branch, baseBranch, runGit, doltPull, log = () => {} } = opts;
525
+ if (typeof runGit !== 'function' || typeof doltPull !== 'function') {
526
+ throw new TypeError('resyncReacquiredMember requires runGit() and doltPull() to be injected');
527
+ }
528
+
529
+ async function gitStep(cmd, { failSoft = false } = {}) {
530
+ const res = await runGit(cmd);
531
+ if (!failSoft && !(res && res.ok)) {
532
+ throw new Error(
533
+ `[resume-resync] '${cmd}' failed on member '${member}': ${(res && (res.error || res.stdout)) || 'unknown error'}`
534
+ );
535
+ }
536
+ return res || { ok: false };
537
+ }
538
+
539
+ // 1. git fetch: base (hard -- a missing base is a real problem) then the
540
+ // sprint branch (soft -- a brand-new branch has no remote ref yet).
541
+ await gitStep(`git fetch origin ${baseBranch} --quiet`);
542
+ const branchFetch = await gitStep(`git fetch origin ${branch} --quiet`, { failSoft: true });
543
+
544
+ // 2. decideEnsureBranchAction probe: local-branch existence + tip comparison.
545
+ const localProbe = await gitStep(`git rev-parse --verify --quiet refs/heads/${branch}`, { failSoft: true });
546
+ const localBranchExists = localProbe.ok;
547
+ let localTipStatus;
548
+ if (branchFetch.ok && localBranchExists) {
549
+ const localIsAncestorOfRemote = await gitStep(
550
+ `git merge-base --is-ancestor ${branch} origin/${branch}`, { failSoft: true }
551
+ );
552
+ const remoteIsAncestorOfLocal = await gitStep(
553
+ `git merge-base --is-ancestor origin/${branch} ${branch}`, { failSoft: true }
554
+ );
555
+ if (localIsAncestorOfRemote.ok) {
556
+ localTipStatus = 'behind-or-equal';
557
+ } else if (remoteIsAncestorOfLocal.ok) {
558
+ localTipStatus = 'ahead';
559
+ } else {
560
+ localTipStatus = 'diverged';
561
+ }
562
+ }
563
+ const decision = decideEnsureBranchAction({
564
+ branch,
565
+ baseBranch,
566
+ branchFetchOk: branchFetch.ok,
567
+ branchFetchError: branchFetch.error,
568
+ localBranchExists,
569
+ localTipStatus,
570
+ });
571
+ if (decision.action === 'abort') {
572
+ throw new Error(`[resume-resync] ${decision.message} (member '${member}')`);
573
+ }
574
+ // Reconcile the member's working branch to origin's (possibly moved) tip.
575
+ await gitStep(decision.command);
576
+
577
+ // 3. bd dolt pull: re-sync the beads clone.
578
+ await doltPull(member);
579
+
580
+ log(`[resume-resync] member '${member}' re-synced (git fetch + branch reconcile + beads D-pull) before work resumed`);
581
+ }