@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,93 @@
1
+ // =============================================================================
2
+ // Unified member OS/shell registry (apra-fleet-3swo.2.5).
3
+ //
4
+ // Extracted move-only from fleet-sprint/runner.js, which owned
5
+ // `resolveMemberTarget`, its per-member cache and the `resolveMemberOs`
6
+ // back-compat wrapper as private/local state. This module is now the single
7
+ // owner; runner.js imports and re-exports all three so its existing facade
8
+ // (dolt-settle.mjs's doc comments, vcs-providers/azure-devops.mjs's doc
9
+ // comments, vcs-providers/shell-helpers.mjs's doc comments, and the two test
10
+ // files that import resolveMemberOs/clearMemberOsCache by name from
11
+ // runner.js) stays intact.
12
+ //
13
+ // CONTRACT (do not change without checking every reference above): the
14
+ // resolved shape is { os, shell }, where os is a lowercase string like
15
+ // 'windows' | 'linux' | 'darwin' and shell is one of '' | 'gitbash' |
16
+ // 'pwsh7' | 'powershell5'.
17
+ // =============================================================================
18
+
19
+ // memberName -> resolved { os, shell } ('windows' | 'linux' | 'darwin' | ...
20
+ // and '' | 'gitbash' | ... respectively), cached for the lifetime of the
21
+ // runner process: a member's OS/shell never changes mid-sprint, and
22
+ // member_detail performs a live connectivity check, so this must not be
23
+ // re-dispatched per credential read (raiseVcsPrForMember can call it twice
24
+ // on the auth-retry path alone).
25
+ const memberOsCache = new Map();
26
+
27
+ // Test seam: the OS cache is process-lifetime state, so a test exercising two
28
+ // different member OSes for the same member name must be able to clear it.
29
+ export function clearMemberOsCache() {
30
+ memberOsCache.clear();
31
+ }
32
+
33
+ // Resolves `member`'s { os, shell } from the fleet member registry via
34
+ // fleetApi.memberDetail() ('member_detail' is the only MCP surface exposing
35
+ // Agent.os/Agent's registered shell -- src/tools/member-detail.ts; it does
36
+ // NOT expose a homeDir). Mirrors VCSModule.resolveProvider()'s member_detail
37
+ // JSON-parsing shape.
38
+ //
39
+ // Unlike resolveProvider, an unresolvable OS is NOT a hard error here: the
40
+ // ONLY behavioral difference it drives is which shell string the credential
41
+ // read is built as, and the historical (POSIX) string must stay byte-identical
42
+ // for every non-Windows member and for any caller that has no memberDetail
43
+ // wired. So a missing/unparseable/absent-`os` response degrades to 'linux'
44
+ // (the pre-existing behavior) and is logged, never thrown. A windows member
45
+ // whose record carries no `shell` (or an unrecognized one) resolves to '' --
46
+ // getSeCommands() treats that as the PowerShell implementation, matching what
47
+ // every Windows member was assumed to be before shells were recorded.
48
+ // @param {{ fleetApi?: object, member: string, log?: Function }} opts
49
+ // @returns {Promise<{ os: string, shell: string }>}
50
+ export async function resolveMemberTarget({ fleetApi, member, log = () => {} }) {
51
+ if (memberOsCache.has(member)) return memberOsCache.get(member);
52
+ try {
53
+ if (!fleetApi || typeof fleetApi.memberDetail !== 'function') {
54
+ throw new Error('no fleetApi.memberDetail() injected');
55
+ }
56
+ const res = await fleetApi.memberDetail({ member_name: member, format: 'json' });
57
+ const text = typeof res === 'string'
58
+ ? res
59
+ : (res && Array.isArray(res.content) && res.content[0] && typeof res.content[0].text === 'string')
60
+ ? res.content[0].text
61
+ : '';
62
+ const parsed = JSON.parse(text);
63
+ if (parsed && typeof parsed.os === 'string' && parsed.os.trim()) {
64
+ const os = parsed.os.trim().toLowerCase();
65
+ const shell = (parsed && typeof parsed.shell === 'string') ? parsed.shell.trim().toLowerCase() : '';
66
+ const target = { os, shell };
67
+ // Only a genuine member_detail-derived OS/shell is cached. Caching
68
+ // the 'linux' fallback below would permanently pin a member that
69
+ // hit a transient failure (asleep, flaky SSH, MCP hiccup) to
70
+ // POSIX command construction for the rest of the runner process
71
+ // -- including the auth-retry credential read at
72
+ // raiseVcsPrForMember, whose entire purpose is to recover from
73
+ // exactly this kind of transient failure. See apra-fleet-ot2z.13.
74
+ memberOsCache.set(member, target);
75
+ return target;
76
+ }
77
+ throw new Error('member_detail response carried no "os" field');
78
+ } catch (err) {
79
+ log(`Could not resolve OS for member '${member}' from member_detail (${err && err.message ? err.message : err}); assuming POSIX ('linux') for member-bound command construction.`);
80
+ return { os: 'linux', shell: '' };
81
+ }
82
+ }
83
+
84
+ // Back-compat wrapper: existing callers (and tests) that only need the OS
85
+ // string keep working unchanged. Resolves and caches both os and shell (see
86
+ // resolveMemberTarget above); callers that also need the shell (e.g. the VCS
87
+ // credential-read path) should call resolveMemberTarget directly.
88
+ // @param {{ fleetApi?: object, member: string, log?: Function }} opts
89
+ // @returns {Promise<string>}
90
+ export async function resolveMemberOs(opts) {
91
+ const { os } = await resolveMemberTarget(opts);
92
+ return os;
93
+ }
@@ -0,0 +1,266 @@
1
+ // Verdict/newTask text surface for fleet-sprint (apra-fleet-3swo.6.14).
2
+ // Extracted out of runner.js; runner.js re-exports every symbol it previously
3
+ // exported from this region, so existing importers of fleet-sprint/runner.js
4
+ // resolve unchanged.
5
+ //
6
+ // This module owns:
7
+ // - extractContestedBeadIds: reads the beads a plan-reviewer verdict calls
8
+ // out from its structured `findings` array, so a CHANGES_NEEDED verdict
9
+ // confined to specific beads can be told apart from a plan-wide one. Falls
10
+ // back to the deprecated free-text `notes` scan only for a verdict that
11
+ // carries no `findings` key at all.
12
+ // - SAFE_TEXT_RE: the newTask-title shell-injection allowlist (still
13
+ // exported, unchanged shape -- see its own header comment below for why).
14
+ // - normalizeTierToken: bead-metadata model-value tier normalization by
15
+ // containment ('cheap'/'standard'/'premium').
16
+ // - trackRejectedNewTaskForResurfacing / clearResubmittedNewTask /
17
+ // reconcilePendingRejectedNewTasks / buildRejectedNewTaskResurfaceLines:
18
+ // the pending-rejected-newTask resurfacing pipeline that feeds the
19
+ // planner prompt (see prompts.mjs's buildPlannerPrompt, which imports
20
+ // buildRejectedNewTaskResurfaceLines back from runner.js's facade).
21
+ //
22
+ // CROSS-FEATURE HANDOFF, now PARTLY LANDED: the Phase 5 bead that replaces
23
+ // plan-reviewer prose scraping with a structured findings field has run --
24
+ // extractContestedBeadIds reads `findings` first and keeps the notes scan only
25
+ // as a deprecated, absent-`findings` fallback (see its own comment for the
26
+ // removal release). What remains outstanding is the LATER Phase 5 bead that
27
+ // deletes the retired prose-scraper fallback outright and updates the facade
28
+ // symbol pins; until it runs, the fallback and the facade enumeration entry
29
+ // both stay exactly where they are.
30
+
31
+ /**
32
+ * Determines whether a plan-reviewer verdict is CONFINED to specific beads
33
+ * rather than spanning the whole plan.
34
+ *
35
+ * PRIMARY CHANNEL (structured): the plan-reviewer contract carries an optional
36
+ * per-bead `findings` array of `{ id, kind, detail }`. When it is PRESENT the
37
+ * contested set is read from it directly -- no text scanning at all. Per the
38
+ * contract, an EMPTY findings array is the explicit "the objection is
39
+ * plan-wide and names no individual bead" signal, so an empty array yields an
40
+ * empty contested set, which the caller already treats as whole-plan
41
+ * contested. `findings` ids are still intersected with `taskAssignments`, so
42
+ * this function keeps returning a SUBSET of the in-scope task ids in
43
+ * taskAssignments order -- exactly what the notes scan returned.
44
+ *
45
+ * FALLBACK CHANNEL (deprecated prose scan): a verdict produced against the
46
+ * previous contract has NO `findings` key at all. For that case only, `notes`
47
+ * is scanned for literal occurrences of each id already known to be in scope
48
+ * via `taskAssignments`. Absence of the key -- not its emptiness -- is what
49
+ * selects the fallback, which is why the two cases cannot be conflated.
50
+ *
51
+ * @param {{ notes?: string, findings?: Array<{ id?: string }>, taskAssignments?: Array<{ id?: string }> }} verdict
52
+ * @returns {string[]} the subset of taskAssignments ids the verdict calls out
53
+ */
54
+ export function extractContestedBeadIds(verdict) {
55
+ if (!verdict || !Array.isArray(verdict.taskAssignments)) {
56
+ return [];
57
+ }
58
+ const allIds = verdict.taskAssignments
59
+ .map((a) => a && a.id)
60
+ .filter((id) => typeof id === 'string' && id.length > 0);
61
+
62
+ if (Array.isArray(verdict.findings)) {
63
+ const namedIds = new Set(
64
+ verdict.findings
65
+ .map((f) => f && f.id)
66
+ .filter((id) => typeof id === 'string' && id.length > 0)
67
+ );
68
+ return allIds.filter((id) => namedIds.has(id));
69
+ }
70
+
71
+ return contestedBeadIdsFromNotesProse(verdict.notes, allIds);
72
+ }
73
+
74
+ // DEPRECATED prose-scraping fallback for extractContestedBeadIds.
75
+ //
76
+ // This is the pre-`findings` channel: before the plan-reviewer contract grew a
77
+ // structured per-bead findings array, `notes` was free text that named the
78
+ // offending bead ids, so the only way to tell a confined CHANGES_NEEDED from a
79
+ // plan-wide one was to scan that text. It survives for exactly one release so
80
+ // a verdict produced against the previous contract still routes correctly.
81
+ //
82
+ // An id matches only at a non-identifier-character boundary (or the string
83
+ // start/end), so a shorter id cannot false-positive inside a longer one that
84
+ // merely extends it. That boundary rule is preserved verbatim -- a verdict
85
+ // routed through this fallback must produce the same contested set it did
86
+ // before the structured field existed.
87
+ //
88
+ // Do not add a new caller: read `verdict.findings`.
89
+ //
90
+ // @deprecated since the structured plan-reviewer findings field; removal
91
+ // release: v0.5.0
92
+ /**
93
+ * @param {unknown} notes the verdict's free-text notes field
94
+ * @param {string[]} allIds the in-scope task ids, in taskAssignments order
95
+ * @returns {string[]} the subset of allIds that notes calls out by name
96
+ */
97
+ function contestedBeadIdsFromNotesProse(notes, allIds) {
98
+ if (typeof notes !== 'string') {
99
+ return [];
100
+ }
101
+ return allIds.filter((id) => {
102
+ const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
103
+ const boundary = '(?:^|[^A-Za-z0-9_-])';
104
+ const endBoundary = '(?:$|[^A-Za-z0-9_-])';
105
+ const re = new RegExp(`${boundary}${escaped}${endBoundary}`);
106
+ return re.test(notes);
107
+ });
108
+ }
109
+
110
+ // ---------------------------------------------------------------------------
111
+ // newTasks validation. Reviewer-authored newTasks are LLM output, and the
112
+ // reviewer's context includes the diff under review, so an adversarial
113
+ // diff/commit could try to steer it into emitting text crafted to break out of
114
+ // a shell command.
115
+ //
116
+ // SAFE_TEXT_RE (title only) deliberately excludes: backtick, `$`,
117
+ // double-quote (the command's own quoting delimiter -- allowing it back in
118
+ // would let a title close the quote early regardless of any other
119
+ // restriction), and backslash (blocks a trailing-backslash "escape the
120
+ // closing quote" trick as well as any other backslash-based escape
121
+ // sequence). The allowed punctuation (`.,:;!?()'-_/+[]` plus space) covers
122
+ // realistic task titles while remaining inert as shell syntax in both POSIX
123
+ // and Windows member shells.
124
+ //
125
+ // apra-fleet-v75: `[`, `]` and `+` are allowed. The title is interpolated as
126
+ // `bd create "${title}"` -- inside double quotes, brackets never glob and `+`
127
+ // has no meaning, in POSIX shells or PowerShell. Excluding them rejected this
128
+ // project's own bead-title convention ([bug]/[epic]/[test] prefixes), which
129
+ // `bd create` itself accepts; a real reviewer follow-up was dropped mid-sprint
130
+ // on exactly that. The characters that ARE live inside double quotes --
131
+ // `"`, `\`, backtick, `$` -- remain excluded, which is what this guard is for.
132
+ //
133
+ // `description` no longer reaches this shell-interpolation risk at all
134
+ // (apra-fleet-eft.56.1, transport hardened in eft.73.1):
135
+ // createChildBeadWithAllocatedId() stages it to a member-local temp file
136
+ // (base64-carried, member-side) and hands that path to `bd create
137
+ // --body-file`, never interpolating it into a command string. That removed
138
+ // the injection
139
+ // surface SAFE_TEXT_RE existed to close for descriptions, so
140
+ // SAFE_DESCRIPTION_RE only enforces the repo's own ASCII-only convention
141
+ // (plus non-empty) -- legitimate technical characters ('=', '&', '+', '"',
142
+ // backticks-as-text, '%', '#', '[', ']', etc.) are allowed again.
143
+ export const SAFE_TEXT_RE = /^[A-Za-z0-9 .,:;!?()'_/+[\]-]+$/;
144
+
145
+ /**
146
+ * Normalizes a bead-metadata model value by CONTAINMENT: a value that
147
+ * (case-insensitively) contains exactly ONE of the three tier names --
148
+ * 'cheap', 'standard', 'premium' -- becomes that bare tier name, so
149
+ * 'standard-tier', 'tier-standard' and 'Standard (default)' all resolve to
150
+ * 'standard'. A value containing zero tier names (an explicit provider model
151
+ * id) or more than one (ambiguous) passes through unchanged. This is the
152
+ * single read site for that metadata: an un-normalized alias would reach the
153
+ * dispatch as a literal provider model name and fail it outright.
154
+ * @param {unknown} raw
155
+ * @returns {unknown}
156
+ */
157
+ export function normalizeTierToken(raw) {
158
+ if (typeof raw !== 'string') return raw;
159
+ const lowered = raw.toLowerCase();
160
+ const matches = ['cheap', 'standard', 'premium'].filter((tier) => lowered.includes(tier));
161
+ return matches.length === 1 ? matches[0] : raw;
162
+ }
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // Resurfacing rejected newTasks into the next planning dispatch
166
+ // ---------------------------------------------------------------------------
167
+ //
168
+ // A note appended by appendRejectedFindingToParentNotes() is readable by a
169
+ // human but invisible to the planner, which is dispatched without resume and
170
+ // never reads bead notes. These helpers instead track the current set of
171
+ // not-yet-resubmitted rejected newTasks in run state so the planner prompt can
172
+ // carry them as explicit "previously rejected, fix and resubmit" items, and
173
+ // drop each one once resubmitted so the list cannot grow without bound. All
174
+ // are pure: the caller owns the array and none of these mutate it in place.
175
+
176
+ /**
177
+ * Records a newly-rejected newTask into the pending resurface list, keyed by
178
+ * title -- a newTask rejected twice under the same title keeps only the
179
+ * LATEST rejection reason/cycle (dedup by title), so a repeatedly-resubmitted-
180
+ * and-repeatedly-rejected item cannot grow the list unboundedly.
181
+ * @param {Array<{title: string, description: string, reason: string, cycle: number|string}>} pending
182
+ * @param {{title: unknown, description: unknown, reason: string, cycle: number|string}} rejected
183
+ * @returns {Array<{title: string, description: string, reason: string, cycle: number|string}>} a NEW array
184
+ */
185
+ export function trackRejectedNewTaskForResurfacing(pending, rejected) {
186
+ const title = String((rejected && rejected.title) || '(untitled)');
187
+ const description = String((rejected && rejected.description) || '');
188
+ const entry = { title, description, reason: String(rejected && rejected.reason), cycle: rejected && rejected.cycle };
189
+ const withoutDup = (Array.isArray(pending) ? pending : []).filter((p) => p.title !== title);
190
+ return [...withoutDup, entry];
191
+ }
192
+
193
+ /**
194
+ * Drops any pending rejected-newTask entries matching a newTask that has now
195
+ * been successfully created.
196
+ *
197
+ * `resubmitted` may be a bare title string (title-only match) or a
198
+ * `{title, description}` object, in which case a match on EITHER the title OR
199
+ * a non-empty description clears the entry. Description matching is what
200
+ * clears a resubmission whose title was corrected in response to the
201
+ * rejection reason -- title-only matching would leave such an item pending
202
+ * forever.
203
+ * @param {Array<{title: string, description?: string}>} pending
204
+ * @param {string|{title?: string, description?: string}} resubmitted
205
+ * @returns {Array<{title: string}>} a NEW array
206
+ */
207
+ export function clearResubmittedNewTask(pending, resubmitted) {
208
+ const list = Array.isArray(pending) ? pending : [];
209
+ const title = typeof resubmitted === 'string' ? resubmitted : String((resubmitted && resubmitted.title) || '');
210
+ const description = (resubmitted && typeof resubmitted === 'object' && resubmitted.description)
211
+ ? String(resubmitted.description) : '';
212
+ return list.filter((p) => {
213
+ const titleMatches = p.title === title;
214
+ const descriptionMatches = description.length > 0 && String((p && p.description) || '') === description;
215
+ return !(titleMatches || descriptionMatches);
216
+ });
217
+ }
218
+
219
+ /**
220
+ * Reconciles the pending resurface list against the parent bead's CURRENT
221
+ * children, matching purely on description and ignoring titles. The planner
222
+ * resubmits a corrected finding directly via `bd create` and never calls
223
+ * clearResubmittedNewTask(), so without this pass a planner resubmission would
224
+ * stay pending and reappear in every later planning prompt of the run. Call it
225
+ * after any phase that may have created children under the parent (chiefly the
226
+ * Plan phase), passing the live child list.
227
+ * @param {Array<{title: string, description?: string}>} pending
228
+ * @param {Array<{description?: string}>} currentChildren
229
+ * @returns {Array<{title: string, description?: string}>} a NEW array
230
+ */
231
+ export function reconcilePendingRejectedNewTasks(pending, currentChildren) {
232
+ const list = Array.isArray(pending) ? pending : [];
233
+ if (list.length === 0) return list;
234
+ const children = Array.isArray(currentChildren) ? currentChildren : [];
235
+ const childDescriptions = new Set(
236
+ children
237
+ .map((c) => String((c && c.description) || '').trim())
238
+ .filter((d) => d.length > 0)
239
+ );
240
+ if (childDescriptions.size === 0) return list;
241
+ return list.filter((p) => {
242
+ const description = String((p && p.description) || '').trim();
243
+ return description.length === 0 || !childDescriptions.has(description);
244
+ });
245
+ }
246
+
247
+ /**
248
+ * Formats the pending rejected-newTask items as explicit "previously rejected,
249
+ * fix and resubmit" prompt lines for the planner prompt. Returns `[]` when
250
+ * nothing is pending, so the prompt is unchanged in that case.
251
+ * @param {Array<{title: string, description: string, reason: string, cycle: number|string}>} pending
252
+ * @returns {string[]}
253
+ */
254
+ export function buildRejectedNewTaskResurfaceLines(pending) {
255
+ if (!Array.isArray(pending) || pending.length === 0) return [];
256
+ const lines = [
257
+ `${pending.length} previously REJECTED newTask(s) from an earlier round must be fixed and ` +
258
+ 're-submitted this planning pass. Verbatim title/description below, plus why each was ' +
259
+ 'rejected -- correct the stated defect (do not just resend the item unchanged), then create ' +
260
+ 'it via bd create as normal:',
261
+ ];
262
+ pending.forEach((r, i) => {
263
+ lines.push(`${i + 1}. Title: "${r.title}"\nDescription: ${r.description}\nRejected because: ${r.reason} (cycle ${r.cycle})`);
264
+ });
265
+ return lines;
266
+ }
@@ -0,0 +1,201 @@
1
+ // =============================================================================
2
+ // PARENT-NOTES STALENESS SIGNAL (apra-fleet-fsxg).
3
+ //
4
+ // A structural, tooling-computed advisory that does NOT depend on the model
5
+ // remembering to look: when a bead in the dispatch scope had its NOTES updated
6
+ // AFTER its most recently created child, its existing decomposition may predate
7
+ // the latest NOTES corrections. The planner/plan-reviewer role prompts already
8
+ // TELL the agent to read a bead's NOTES before decomposing/reviewing (see the
9
+ // companion role-prompt fixes), but a prompt instruction is the weakest layer:
10
+ // it fires only if the model chooses to perform the check, which is exactly the
11
+ // failure mode that motivated this -- an original decomposition simply never
12
+ // looked at NOTES. This module turns "remember to check for a stale
13
+ // decomposition" into "here is a specific bead the tooling already flagged --
14
+ // go look", closer to a linter finding than a style-guide reminder.
15
+ //
16
+ // STRICTLY ADVISORY: nothing here ever blocks a dispatch or fails a plan. A
17
+ // fired signal only ADDS a note to the planner/plan-reviewer dispatch context;
18
+ // an absent or errored signal changes nothing. A false negative (the bd calls
19
+ // fail, or beads exposes no notes-change timestamp) simply falls back to the
20
+ // pre-existing prompt-only behaviour.
21
+ //
22
+ // GENERIC: every string this module emits is product-generic. It names no
23
+ // target repo, build command, env var, or bead id -- the only ids that appear
24
+ // in its output are interpolated at RUNTIME from the live sprint scope (exactly
25
+ // as buildPlannerPrompt already interpolates targetIssues), never written as
26
+ // literals. Registered in guarded-modules.mjs; its two command() call sites
27
+ // each name member_name explicitly.
28
+ //
29
+ // WHY `bd history` AND NOT `updated_at`. beads stores `notes` as a single text
30
+ // field with no notes-specific timestamp; the bead-level `updated_at` moves on
31
+ // ANY mutation (status, priority, claim, close), so using it as a proxy for
32
+ // "notes last changed" would false-positive constantly and violate this
33
+ // feature's "no false positives on the common case" requirement. `bd history
34
+ // <id> --json` returns a per-commit snapshot of the whole issue (including its
35
+ // notes text), so walking it oldest-first isolates the exact commit at which
36
+ // the notes text last actually changed.
37
+ // =============================================================================
38
+
39
+ /**
40
+ * Derives the timestamp at which a bead's NOTES text last actually changed,
41
+ * from `bd history <id> --json` output. The history is an array of per-commit
42
+ * snapshots, NEWEST first, each shaped `{ CommitDate, Issue: { notes } }`.
43
+ *
44
+ * Walks the snapshots oldest-first, tracking the commit at which the notes
45
+ * text last transitioned to a new value. Returns that commit's date string, or
46
+ * `null` when the bead never carried notes, when the notes text never changed
47
+ * from empty, or when the CURRENT (newest) notes are empty -- an empty final
48
+ * notes field describes no correction, so it is never a staleness signal.
49
+ *
50
+ * @param {Array<{ CommitDate?: string, Issue?: { notes?: unknown } }>} history
51
+ * @returns {string|null} the ISO-ish date string of the last notes change, or null
52
+ */
53
+ export function notesLastUpdatedAtFromHistory(history) {
54
+ if (!Array.isArray(history) || history.length === 0) return null;
55
+ // History arrives newest-first; walk it oldest-first so a change is
56
+ // recorded at the commit that INTRODUCED it, not the latest commit that
57
+ // merely carried it forward unchanged.
58
+ const oldestFirst = [...history].reverse();
59
+ let prevNotes = '';
60
+ let lastChangeDate = null;
61
+ for (const entry of oldestFirst) {
62
+ const rawNotes = entry && entry.Issue && typeof entry.Issue.notes === 'string'
63
+ ? entry.Issue.notes
64
+ : '';
65
+ const notes = rawNotes.trim();
66
+ if (notes !== prevNotes) {
67
+ lastChangeDate = entry && typeof entry.CommitDate === 'string' ? entry.CommitDate : lastChangeDate;
68
+ prevNotes = notes;
69
+ }
70
+ }
71
+ // Final notes empty (never set, or explicitly cleared): no correction to be
72
+ // stale against.
73
+ if (prevNotes.length === 0) return null;
74
+ return lastChangeDate;
75
+ }
76
+
77
+ /**
78
+ * Picks the child with the most recent valid `created_at`, or null if none of
79
+ * the children carry a parseable creation timestamp.
80
+ * @param {Array<{ id?: string, created_at?: string }>} children
81
+ * @returns {{ id?: string, created_at: string }|null}
82
+ */
83
+ function mostRecentlyCreatedChild(children) {
84
+ if (!Array.isArray(children)) return null;
85
+ let best = null;
86
+ let bestTime = -Infinity;
87
+ for (const child of children) {
88
+ const createdAt = child && typeof child.created_at === 'string' ? child.created_at : null;
89
+ if (!createdAt) continue;
90
+ const time = Date.parse(createdAt);
91
+ if (Number.isNaN(time)) continue;
92
+ if (time > bestTime) {
93
+ bestTime = time;
94
+ best = { id: child && child.id, created_at: createdAt };
95
+ }
96
+ }
97
+ return best;
98
+ }
99
+
100
+ /**
101
+ * Decides whether a single bead's NOTES are newer than its most recently
102
+ * created child and, if so, returns a generic, advisory staleness note naming
103
+ * the bead; otherwise returns null.
104
+ *
105
+ * Returns null (NO false positive) when the bead has no children, when no child
106
+ * carries a parseable creation timestamp, when the notes-updated timestamp is
107
+ * absent/unparseable, or when the notes are NOT strictly newer than the most
108
+ * recently created child (the common case: notes predate the decomposition).
109
+ *
110
+ * @param {{ id: string, notesUpdatedAt: string|null, children: Array<{ id?: string, created_at?: string }> }} args
111
+ * @returns {string|null}
112
+ */
113
+ export function computeParentNotesStalenessNote({ id, notesUpdatedAt, children }) {
114
+ if (typeof notesUpdatedAt !== 'string' || notesUpdatedAt.length === 0) return null;
115
+ const notesTime = Date.parse(notesUpdatedAt);
116
+ if (Number.isNaN(notesTime)) return null;
117
+
118
+ const child = mostRecentlyCreatedChild(children);
119
+ if (!child) return null;
120
+ const childTime = Date.parse(child.created_at);
121
+ if (Number.isNaN(childTime)) return null;
122
+
123
+ // Strictly newer: notes exactly co-timed with the last child are not stale.
124
+ if (notesTime <= childTime) return null;
125
+
126
+ const childLabel = child.id ? `${child.id}, created ${child.created_at}` : `created ${child.created_at}`;
127
+ return (
128
+ `Bead ${id}: its NOTES were last updated (${notesUpdatedAt}) AFTER its most recently ` +
129
+ `created child (${childLabel}). Its existing decomposition may predate the latest NOTES ` +
130
+ `entries -- read this bead's full NOTES and verify its existing children are still consistent ` +
131
+ `with them before proceeding, treating any later correction/amendment recorded in NOTES as ` +
132
+ `authoritative over stale DESCRIPTION text or any child that contradicts it.`
133
+ );
134
+ }
135
+
136
+ /**
137
+ * Formats a set of per-bead staleness notes into one prominent, advisory block
138
+ * for injection into a planner/plan-reviewer dispatch prompt. Returns null when
139
+ * there is nothing to surface, so the prompt is unchanged in the common case.
140
+ * @param {string[]} notes
141
+ * @returns {string|null}
142
+ */
143
+ export function formatStalenessBlock(notes) {
144
+ if (!Array.isArray(notes) || notes.length === 0) return null;
145
+ const header =
146
+ 'TOOLING-COMPUTED STALENESS SIGNAL -- the dispatch tooling detected, without relying on you ' +
147
+ 'to remember to check, that the following in-scope bead(s) had their NOTES updated AFTER their ' +
148
+ 'most recently created child. Their existing decomposition may therefore predate the latest ' +
149
+ 'NOTES corrections. This is ADVISORY ONLY: it never blocks planning and is not itself a defect, ' +
150
+ 'but treat each as a specific bead to inspect first:';
151
+ return [header, ...notes.map((n, i) => `${i + 1}. ${n}`)].join('\n\n');
152
+ }
153
+
154
+ /**
155
+ * Computes the parent-NOTES staleness notes for a set of scope bead ids by
156
+ * reading each bead's children (`bd list --parent <id> --json`) and, when it
157
+ * has children, its notes-change history (`bd history <id> --json`). Pure
158
+ * fetch-and-compute: never mutates beads, never blocks, and swallows per-bead
159
+ * bd failures (advisory feature -- a failed probe simply yields no note).
160
+ *
161
+ * @param {{
162
+ * command: (label: string, opts: object) => Promise<unknown>,
163
+ * member: string,
164
+ * rootIds: string[],
165
+ * parseBdJson: (raw: unknown, label: string) => unknown,
166
+ * log?: (msg: string) => void,
167
+ * }} args
168
+ * @returns {Promise<string[]>} one note per stale bead, in rootIds order
169
+ */
170
+ export async function collectParentNotesStalenessNotes({ command, member, rootIds, parseBdJson, log }) {
171
+ const notes = [];
172
+ const ids = Array.isArray(rootIds) ? rootIds : [];
173
+ for (const id of ids) {
174
+ if (!id) continue;
175
+ let children;
176
+ try {
177
+ const label = `bd list --parent ${id} --json`;
178
+ const raw = await command(label, { member_name: member, silent: true });
179
+ children = parseBdJson(raw, label);
180
+ } catch (err) {
181
+ if (log) log(`[fleet-sprint] parent-NOTES staleness: child listing for '${id}' FAILED (non-fatal, skipped): ${err.message}`);
182
+ continue;
183
+ }
184
+ if (!Array.isArray(children) || children.length === 0) continue;
185
+
186
+ let notesUpdatedAt = null;
187
+ try {
188
+ const hLabel = `bd history ${id} --json`;
189
+ const hRaw = await command(hLabel, { member_name: member, silent: true });
190
+ const history = parseBdJson(hRaw, hLabel);
191
+ notesUpdatedAt = notesLastUpdatedAtFromHistory(history);
192
+ } catch (err) {
193
+ if (log) log(`[fleet-sprint] parent-NOTES staleness: history read for '${id}' FAILED (non-fatal, skipped): ${err.message}`);
194
+ continue;
195
+ }
196
+
197
+ const note = computeParentNotesStalenessNote({ id, notesUpdatedAt, children });
198
+ if (note) notes.push(note);
199
+ }
200
+ return notes;
201
+ }