@apralabs/apra-fleet 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/README.md +38 -5
  2. package/dist/agents/backlog-groomer.md +25 -0
  3. package/dist/agents/ci-watcher.md +11 -0
  4. package/dist/agents/deployer.md +37 -2
  5. package/dist/agents/doer.md +36 -12
  6. package/dist/agents/harvester.md +11 -0
  7. package/dist/agents/integ-test-runner.md +11 -0
  8. package/dist/agents/kb-reconciler.md +9 -0
  9. package/dist/agents/plan-reviewer.md +110 -22
  10. package/dist/agents/planner.md +125 -37
  11. package/dist/agents/regression-test-runner.md +11 -0
  12. package/dist/agents/reviewer.md +13 -2
  13. package/dist/agents/schemas/plan-reviewer-output.json +37 -0
  14. package/dist/cli/agent-transform.d.ts +83 -2
  15. package/dist/cli/agent-transform.d.ts.map +1 -1
  16. package/dist/cli/agent-transform.js +266 -21
  17. package/dist/cli/agent-transform.js.map +1 -1
  18. package/dist/cli/auth.d.ts.map +1 -1
  19. package/dist/cli/auth.js +28 -9
  20. package/dist/cli/auth.js.map +1 -1
  21. package/dist/cli/config.d.ts +7 -5
  22. package/dist/cli/config.d.ts.map +1 -1
  23. package/dist/cli/config.js +44 -34
  24. package/dist/cli/config.js.map +1 -1
  25. package/dist/cli/install.d.ts +33 -0
  26. package/dist/cli/install.d.ts.map +1 -1
  27. package/dist/cli/install.js +290 -23
  28. package/dist/cli/install.js.map +1 -1
  29. package/dist/cli/kb-directives.d.ts.map +1 -1
  30. package/dist/cli/kb-directives.js +2 -1
  31. package/dist/cli/kb-directives.js.map +1 -1
  32. package/dist/cli/register-member.d.ts.map +1 -1
  33. package/dist/cli/register-member.js +6 -2
  34. package/dist/cli/register-member.js.map +1 -1
  35. package/dist/commands/kb-server.d.ts +3 -0
  36. package/dist/commands/kb-server.d.ts.map +1 -1
  37. package/dist/commands/kb-server.js +43 -3
  38. package/dist/commands/kb-server.js.map +1 -1
  39. package/dist/index.js +3 -3
  40. package/dist/os/linux.d.ts +6 -0
  41. package/dist/os/linux.d.ts.map +1 -1
  42. package/dist/os/linux.js +35 -2
  43. package/dist/os/linux.js.map +1 -1
  44. package/dist/os/os-commands.d.ts +61 -2
  45. package/dist/os/os-commands.d.ts.map +1 -1
  46. package/dist/os/windows-gitbash.d.ts +5 -0
  47. package/dist/os/windows-gitbash.d.ts.map +1 -1
  48. package/dist/os/windows-gitbash.js +15 -0
  49. package/dist/os/windows-gitbash.js.map +1 -1
  50. package/dist/os/windows.d.ts +6 -0
  51. package/dist/os/windows.d.ts.map +1 -1
  52. package/dist/os/windows.js +46 -3
  53. package/dist/os/windows.js.map +1 -1
  54. package/dist/providers/agy.d.ts +115 -6
  55. package/dist/providers/agy.d.ts.map +1 -1
  56. package/dist/providers/agy.js +569 -53
  57. package/dist/providers/agy.js.map +1 -1
  58. package/dist/providers/claude.d.ts +81 -3
  59. package/dist/providers/claude.d.ts.map +1 -1
  60. package/dist/providers/claude.js +344 -10
  61. package/dist/providers/claude.js.map +1 -1
  62. package/dist/providers/codex.d.ts +4 -2
  63. package/dist/providers/codex.d.ts.map +1 -1
  64. package/dist/providers/codex.js +19 -2
  65. package/dist/providers/codex.js.map +1 -1
  66. package/dist/providers/copilot.d.ts +4 -2
  67. package/dist/providers/copilot.d.ts.map +1 -1
  68. package/dist/providers/copilot.js +20 -2
  69. package/dist/providers/copilot.js.map +1 -1
  70. package/dist/providers/none.d.ts +4 -2
  71. package/dist/providers/none.d.ts.map +1 -1
  72. package/dist/providers/none.js +17 -2
  73. package/dist/providers/none.js.map +1 -1
  74. package/dist/providers/opencode.d.ts +3 -1
  75. package/dist/providers/opencode.d.ts.map +1 -1
  76. package/dist/providers/opencode.js +22 -2
  77. package/dist/providers/opencode.js.map +1 -1
  78. package/dist/providers/provider.d.ts +201 -6
  79. package/dist/providers/provider.d.ts.map +1 -1
  80. package/dist/providers/provider.js +56 -0
  81. package/dist/providers/provider.js.map +1 -1
  82. package/dist/services/agy-project.d.ts +102 -0
  83. package/dist/services/agy-project.d.ts.map +1 -0
  84. package/dist/services/agy-project.js +356 -0
  85. package/dist/services/agy-project.js.map +1 -0
  86. package/dist/services/auth-socket.js +4 -4
  87. package/dist/services/auth-web.js +1 -1
  88. package/dist/services/cloud/lifecycle.d.ts.map +1 -1
  89. package/dist/services/cloud/lifecycle.js +33 -4
  90. package/dist/services/cloud/lifecycle.js.map +1 -1
  91. package/dist/services/credential-cleanup.d.ts.map +1 -1
  92. package/dist/services/credential-cleanup.js +35 -17
  93. package/dist/services/credential-cleanup.js.map +1 -1
  94. package/dist/services/exit-drain.d.ts +44 -0
  95. package/dist/services/exit-drain.d.ts.map +1 -0
  96. package/dist/services/exit-drain.js +52 -0
  97. package/dist/services/exit-drain.js.map +1 -0
  98. package/dist/services/github-app.d.ts.map +1 -1
  99. package/dist/services/github-app.js +32 -4
  100. package/dist/services/github-app.js.map +1 -1
  101. package/dist/services/http-transport.d.ts +1 -0
  102. package/dist/services/http-transport.d.ts.map +1 -1
  103. package/dist/services/http-transport.js +48 -1
  104. package/dist/services/http-transport.js.map +1 -1
  105. package/dist/services/knowledge/kb-config.d.ts +42 -0
  106. package/dist/services/knowledge/kb-config.d.ts.map +1 -0
  107. package/dist/services/knowledge/kb-config.js +54 -0
  108. package/dist/services/knowledge/kb-config.js.map +1 -0
  109. package/dist/services/knowledge/kb-providers.d.ts +7 -1
  110. package/dist/services/knowledge/kb-providers.d.ts.map +1 -1
  111. package/dist/services/knowledge/kb-providers.js +191 -17
  112. package/dist/services/knowledge/kb-providers.js.map +1 -1
  113. package/dist/services/knowledge/require-sqlite-project.d.ts +32 -0
  114. package/dist/services/knowledge/require-sqlite-project.d.ts.map +1 -0
  115. package/dist/services/knowledge/require-sqlite-project.js +38 -0
  116. package/dist/services/knowledge/require-sqlite-project.js.map +1 -0
  117. package/dist/services/model-pricing.d.ts.map +1 -1
  118. package/dist/services/model-pricing.js +7 -3
  119. package/dist/services/model-pricing.js.map +1 -1
  120. package/dist/services/secret-token.d.ts +38 -0
  121. package/dist/services/secret-token.d.ts.map +1 -0
  122. package/dist/services/secret-token.js +51 -0
  123. package/dist/services/secret-token.js.map +1 -0
  124. package/dist/services/service-manager/types.d.ts +3 -1
  125. package/dist/services/service-manager/types.d.ts.map +1 -1
  126. package/dist/services/service-manager/windows.d.ts +14 -2
  127. package/dist/services/service-manager/windows.d.ts.map +1 -1
  128. package/dist/services/service-manager/windows.js +65 -7
  129. package/dist/services/service-manager/windows.js.map +1 -1
  130. package/dist/services/ssh.d.ts.map +1 -1
  131. package/dist/services/ssh.js +58 -2
  132. package/dist/services/ssh.js.map +1 -1
  133. package/dist/services/stall/read-log-tail.d.ts.map +1 -1
  134. package/dist/services/stall/read-log-tail.js +20 -10
  135. package/dist/services/stall/read-log-tail.js.map +1 -1
  136. package/dist/services/stall/stall-detector.d.ts +53 -4
  137. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  138. package/dist/services/stall/stall-detector.js +212 -34
  139. package/dist/services/stall/stall-detector.js.map +1 -1
  140. package/dist/services/strategy.d.ts.map +1 -1
  141. package/dist/services/strategy.js +79 -2
  142. package/dist/services/strategy.js.map +1 -1
  143. package/dist/services/substitution-engine.js +2 -2
  144. package/dist/services/substitution-engine.js.map +1 -1
  145. package/dist/services/tool-registry.d.ts.map +1 -1
  146. package/dist/services/tool-registry.js +5 -3
  147. package/dist/services/tool-registry.js.map +1 -1
  148. package/dist/services/vcs/azure-devops.d.ts +66 -1
  149. package/dist/services/vcs/azure-devops.d.ts.map +1 -1
  150. package/dist/services/vcs/azure-devops.js +192 -21
  151. package/dist/services/vcs/azure-devops.js.map +1 -1
  152. package/dist/services/vcs/types.d.ts +1 -1
  153. package/dist/skills/fleet-sprint-cli/SKILL.md +18 -0
  154. package/dist/skills/pm/SKILL.md +1 -1
  155. package/dist/skills/pm/cost.md +0 -3
  156. package/dist/skills/pm/fleet-addendum.md +2 -2
  157. package/dist/tools/check-status.d.ts +7 -4
  158. package/dist/tools/check-status.d.ts.map +1 -1
  159. package/dist/tools/check-status.js +2 -0
  160. package/dist/tools/check-status.js.map +1 -1
  161. package/dist/tools/compose-permissions.d.ts +6 -0
  162. package/dist/tools/compose-permissions.d.ts.map +1 -1
  163. package/dist/tools/compose-permissions.js +182 -34
  164. package/dist/tools/compose-permissions.js.map +1 -1
  165. package/dist/tools/credential-store-set.js +1 -1
  166. package/dist/tools/execute-command.d.ts.map +1 -1
  167. package/dist/tools/execute-command.js +31 -20
  168. package/dist/tools/execute-command.js.map +1 -1
  169. package/dist/tools/execute-prompt.d.ts +15 -2
  170. package/dist/tools/execute-prompt.d.ts.map +1 -1
  171. package/dist/tools/execute-prompt.js +1196 -892
  172. package/dist/tools/execute-prompt.js.map +1 -1
  173. package/dist/tools/kb-capture.d.ts +2 -2
  174. package/dist/tools/kb-capture.d.ts.map +1 -1
  175. package/dist/tools/kb-capture.js +29 -5
  176. package/dist/tools/kb-capture.js.map +1 -1
  177. package/dist/tools/kb-export.d.ts +2 -2
  178. package/dist/tools/kb-export.d.ts.map +1 -1
  179. package/dist/tools/kb-export.js +3 -28
  180. package/dist/tools/kb-export.js.map +1 -1
  181. package/dist/tools/kb-feedback.d.ts.map +1 -1
  182. package/dist/tools/kb-feedback.js +3 -1
  183. package/dist/tools/kb-feedback.js.map +1 -1
  184. package/dist/tools/kb-freshness-sweep.d.ts.map +1 -1
  185. package/dist/tools/kb-freshness-sweep.js +3 -1
  186. package/dist/tools/kb-freshness-sweep.js.map +1 -1
  187. package/dist/tools/kb-import.d.ts.map +1 -1
  188. package/dist/tools/kb-import.js +2 -1
  189. package/dist/tools/kb-import.js.map +1 -1
  190. package/dist/tools/kb-list.d.ts.map +1 -1
  191. package/dist/tools/kb-list.js +3 -1
  192. package/dist/tools/kb-list.js.map +1 -1
  193. package/dist/tools/kb-query.d.ts +2 -2
  194. package/dist/tools/kb-reconcile-prefilter.d.ts.map +1 -1
  195. package/dist/tools/kb-reconcile-prefilter.js +3 -1
  196. package/dist/tools/kb-reconcile-prefilter.js.map +1 -1
  197. package/dist/tools/kb-resolve-contradiction.d.ts.map +1 -1
  198. package/dist/tools/kb-resolve-contradiction.js +3 -1
  199. package/dist/tools/kb-resolve-contradiction.js.map +1 -1
  200. package/dist/tools/kb-setup.d.ts.map +1 -1
  201. package/dist/tools/kb-setup.js +125 -20
  202. package/dist/tools/kb-setup.js.map +1 -1
  203. package/dist/tools/kb-stats.d.ts.map +1 -1
  204. package/dist/tools/kb-stats.js +64 -43
  205. package/dist/tools/kb-stats.js.map +1 -1
  206. package/dist/tools/list-members.d.ts +2 -2
  207. package/dist/tools/list-members.d.ts.map +1 -1
  208. package/dist/tools/list-members.js +1 -0
  209. package/dist/tools/list-members.js.map +1 -1
  210. package/dist/tools/member-detail.d.ts +2 -2
  211. package/dist/tools/member-detail.d.ts.map +1 -1
  212. package/dist/tools/member-detail.js +17 -0
  213. package/dist/tools/member-detail.js.map +1 -1
  214. package/dist/tools/member-reservation.d.ts +58 -1
  215. package/dist/tools/member-reservation.d.ts.map +1 -1
  216. package/dist/tools/member-reservation.js +61 -20
  217. package/dist/tools/member-reservation.js.map +1 -1
  218. package/dist/tools/provision-auth.d.ts +80 -1
  219. package/dist/tools/provision-auth.d.ts.map +1 -1
  220. package/dist/tools/provision-auth.js +142 -54
  221. package/dist/tools/provision-auth.js.map +1 -1
  222. package/dist/tools/provision-vcs-auth.d.ts +91 -1
  223. package/dist/tools/provision-vcs-auth.d.ts.map +1 -1
  224. package/dist/tools/provision-vcs-auth.js +209 -49
  225. package/dist/tools/provision-vcs-auth.js.map +1 -1
  226. package/dist/tools/register-member.d.ts +12 -9
  227. package/dist/tools/register-member.d.ts.map +1 -1
  228. package/dist/tools/register-member.js +99 -12
  229. package/dist/tools/register-member.js.map +1 -1
  230. package/dist/tools/remove-member.d.ts.map +1 -1
  231. package/dist/tools/remove-member.js +27 -2
  232. package/dist/tools/remove-member.js.map +1 -1
  233. package/dist/tools/send-email.d.ts +2 -2
  234. package/dist/tools/setup-git-app.d.ts.map +1 -1
  235. package/dist/tools/setup-git-app.js +11 -7
  236. package/dist/tools/setup-git-app.js.map +1 -1
  237. package/dist/tools/shutdown-server.d.ts +2 -0
  238. package/dist/tools/shutdown-server.d.ts.map +1 -1
  239. package/dist/tools/shutdown-server.js +23 -1
  240. package/dist/tools/shutdown-server.js.map +1 -1
  241. package/dist/tools/update-member.d.ts +12 -9
  242. package/dist/tools/update-member.d.ts.map +1 -1
  243. package/dist/tools/update-member.js +43 -11
  244. package/dist/tools/update-member.js.map +1 -1
  245. package/dist/tools/vcs-credential-exec.d.ts +127 -0
  246. package/dist/tools/vcs-credential-exec.d.ts.map +1 -0
  247. package/dist/tools/vcs-credential-exec.js +197 -0
  248. package/dist/tools/vcs-credential-exec.js.map +1 -0
  249. package/dist/types.d.ts +13 -0
  250. package/dist/types.d.ts.map +1 -1
  251. package/dist/utils/log-helpers.d.ts.map +1 -1
  252. package/dist/utils/log-helpers.js +2 -2
  253. package/dist/utils/log-helpers.js.map +1 -1
  254. package/dist/utils/prompt-errors.d.ts.map +1 -1
  255. package/dist/utils/prompt-errors.js +7 -1
  256. package/dist/utils/prompt-errors.js.map +1 -1
  257. package/dist/utils/shell-escape.d.ts +16 -0
  258. package/dist/utils/shell-escape.d.ts.map +1 -1
  259. package/dist/utils/shell-escape.js +22 -2
  260. package/dist/utils/shell-escape.js.map +1 -1
  261. package/dist/utils/vcs-provider-detect.d.ts +65 -0
  262. package/dist/utils/vcs-provider-detect.d.ts.map +1 -0
  263. package/dist/utils/vcs-provider-detect.js +109 -0
  264. package/dist/utils/vcs-provider-detect.js.map +1 -0
  265. package/dist/utils/workspace-trust.d.ts +20 -17
  266. package/dist/utils/workspace-trust.d.ts.map +1 -1
  267. package/dist/utils/workspace-trust.js +87 -1
  268. package/dist/utils/workspace-trust.js.map +1 -1
  269. package/dist/workflows/auto-sprint.js +176 -15
  270. package/package.json +6 -4
  271. package/packages/apra-fleet-client/src/client/api.mjs +319 -17
  272. package/packages/apra-fleet-client/src/client/errors.mjs +6 -2
  273. package/packages/apra-fleet-se/apra-pm/agents/_shared/GRAPH-SEMANTICS.md +10 -2
  274. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +25 -0
  275. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +11 -0
  276. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +37 -2
  277. package/packages/apra-fleet-se/apra-pm/agents/doer.md +36 -12
  278. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +11 -0
  279. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +11 -0
  280. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +9 -0
  281. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +110 -22
  282. package/packages/apra-fleet-se/apra-pm/agents/planner.md +125 -37
  283. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +11 -0
  284. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +13 -2
  285. package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-output.json +37 -0
  286. package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +1 -1
  287. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +0 -3
  288. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +2 -2
  289. package/packages/apra-fleet-se/bin/cli.mjs +149 -1
  290. package/packages/apra-fleet-se/bin/serve.mjs +78 -4
  291. package/packages/apra-fleet-se/fleet-sprint/abort.mjs +481 -0
  292. package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +491 -0
  293. package/packages/apra-fleet-se/fleet-sprint/beads-identity-check.mjs +282 -0
  294. package/packages/apra-fleet-se/fleet-sprint/beads-identity.mjs +208 -0
  295. package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +638 -0
  296. package/packages/apra-fleet-se/fleet-sprint/beads-transitions.mjs +301 -0
  297. package/packages/apra-fleet-se/fleet-sprint/branch-ensure.mjs +96 -0
  298. package/packages/apra-fleet-se/fleet-sprint/conflict-ladder.mjs +8 -0
  299. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +61 -14
  300. package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +516 -0
  301. package/packages/apra-fleet-se/fleet-sprint/dispatch-failure.mjs +184 -0
  302. package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +1121 -0
  303. package/packages/apra-fleet-se/fleet-sprint/dispatch-safety-guard.mjs +216 -4
  304. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +1 -1
  305. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +276 -0
  306. package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +1 -1
  307. package/packages/apra-fleet-se/fleet-sprint/docs/run-sprint-cycle-prelude-decision.md +215 -0
  308. package/packages/apra-fleet-se/fleet-sprint/dolt-literal-guard.mjs +56 -1
  309. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +996 -32
  310. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +267 -0
  311. package/packages/apra-fleet-se/fleet-sprint/explicit-id-create-guard.mjs +501 -0
  312. package/packages/apra-fleet-se/fleet-sprint/fatal-diagnostics.mjs +134 -0
  313. package/packages/apra-fleet-se/fleet-sprint/full-db-fetch-guard.mjs +102 -0
  314. package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +556 -0
  315. package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +495 -0
  316. package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +564 -0
  317. package/packages/apra-fleet-se/fleet-sprint/inline-ladder-guard.mjs +216 -0
  318. package/packages/apra-fleet-se/fleet-sprint/kb.mjs +728 -0
  319. package/packages/apra-fleet-se/fleet-sprint/mcp-result.mjs +75 -0
  320. package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +252 -0
  321. package/packages/apra-fleet-se/fleet-sprint/member-sync.mjs +581 -0
  322. package/packages/apra-fleet-se/fleet-sprint/member-target.mjs +93 -0
  323. package/packages/apra-fleet-se/fleet-sprint/newtask-text.mjs +266 -0
  324. package/packages/apra-fleet-se/fleet-sprint/parent-notes-staleness.mjs +201 -0
  325. package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +136 -0
  326. package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +822 -0
  327. package/packages/apra-fleet-se/fleet-sprint/phases/ensure-sprint-branch.mjs +294 -0
  328. package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +403 -0
  329. package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +180 -0
  330. package/packages/apra-fleet-se/fleet-sprint/phases/integ-test.mjs +358 -0
  331. package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +390 -0
  332. package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +323 -0
  333. package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +232 -0
  334. package/packages/apra-fleet-se/fleet-sprint/phases/regression-test.mjs +174 -0
  335. package/packages/apra-fleet-se/fleet-sprint/phases/replan.mjs +197 -0
  336. package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +305 -0
  337. package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +559 -0
  338. package/packages/apra-fleet-se/fleet-sprint/role-policies.mjs +1416 -0
  339. package/packages/apra-fleet-se/fleet-sprint/round-session.mjs +100 -0
  340. package/packages/apra-fleet-se/fleet-sprint/runner.js +1467 -9798
  341. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +17 -12
  342. package/packages/apra-fleet-se/fleet-sprint/shell-command-guard.mjs +304 -0
  343. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +18 -0
  344. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +21 -2
  345. package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +454 -0
  346. package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +239 -0
  347. package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +163 -0
  348. package/packages/apra-fleet-se/fleet-sprint/unbracketed-push-guard.mjs +234 -0
  349. package/packages/apra-fleet-se/fleet-sprint/usage-limit-controller.mjs +211 -0
  350. package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +1279 -0
  351. package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +153 -19
  352. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +71 -21
  353. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +28 -0
  354. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +131 -0
  355. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +140 -16
  356. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/shell-helpers.mjs +1 -0
  357. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +77 -2
  358. package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +559 -0
  359. package/packages/apra-fleet-se/package.json +1 -1
  360. package/packages/apra-fleet-workflow/src/viewer/index.mjs +17 -6
  361. package/packages/apra-fleet-workflow/src/workflow/index.mjs +49 -7
  362. package/skills/fleet/SKILL.md +8 -8
  363. package/skills/fleet/auth-azdevops.md +14 -3
  364. package/skills/fleet/auth-bitbucket.md +2 -2
  365. package/skills/fleet/auth-github.md +5 -4
  366. package/skills/fleet/onboarding.md +3 -3
  367. package/skills/fleet/permissions.md +5 -1
  368. package/skills/fleet/profiles/node.json +1 -1
  369. package/skills/fleet/troubleshooting.md +3 -3
  370. package/version.json +1 -1
@@ -0,0 +1,559 @@
1
+ // Worklist tier policy, effort-budget packing and the pure streak-assignment
2
+ // validation helpers for fleet-sprint's Develop/Review loop
3
+ // (apra-fleet-3swo.3.5). Moved verbatim out of runner.js -- runner.js
4
+ // re-exports every symbol this region previously exported (selectStreaks was
5
+ // module-private and is imported, not re-exported, for its own in-runner call
6
+ // sites), so behaviour is unchanged either way. This is a move-only
7
+ // extraction: no logic, ordering or tier-homogeneity rule changed.
8
+ //
9
+ // normalizeTierToken and DEFAULT_CONTEXT_CEILING stay in runner.js (out of
10
+ // this bead's scope -- normalizeTierToken is part of the newTask validation
11
+ // cluster, DEFAULT_CONTEXT_CEILING is shared with createRoundSessionRegistry's
12
+ // round-resume tracking) and are imported back here; the resulting runner.js
13
+ // <-> worklists.mjs cycle is safe because every use is inside a function
14
+ // body, never at module-evaluation time.
15
+ import { normalizeTierToken, DEFAULT_CONTEXT_CEILING } from './runner.js';
16
+
17
+ /**
18
+ * Validates a streak-assignment agent() result against the set of currently
19
+ * ready bead objects and returns the resolved streaks (arrays of the original
20
+ * bead objects, not just ids). Falls back to one-bead-per-streak -- which is
21
+ * correct by construction -- whenever the candidate does not cover every ready
22
+ * bead id EXACTLY once, so a malformed result can never drop or duplicate a
23
+ * bead's assignment.
24
+ *
25
+ * Pure: no I/O, no agent() calls.
26
+ * @param {{streaks: string[][]}|null|undefined} candidate
27
+ * @param {Array<{id: string}>} currentReady
28
+ * @returns {{ streaks: Array<Array<{id: string}>>, usedFallback: boolean, reason: string|null }}
29
+ */
30
+ export function selectStreaks(candidate, currentReady) {
31
+ const fallback = () => ({
32
+ streaks: currentReady.map((b) => [b]),
33
+ usedFallback: true,
34
+ });
35
+
36
+ if (!candidate || !Array.isArray(candidate.streaks)) {
37
+ return { ...fallback(), reason: 'no candidate or candidate.streaks was not an array' };
38
+ }
39
+
40
+ const byId = new Map(currentReady.map((b) => [b.id, b]));
41
+ const readyIds = currentReady.map((b) => b.id);
42
+ const seen = new Set();
43
+ const resolvedStreaks = [];
44
+
45
+ for (const streakIds of candidate.streaks) {
46
+ if (!Array.isArray(streakIds) || streakIds.length === 0) {
47
+ return { ...fallback(), reason: 'a streak entry was not a non-empty array' };
48
+ }
49
+ const resolvedStreak = [];
50
+ for (const id of streakIds) {
51
+ if (!byId.has(id)) {
52
+ return { ...fallback(), reason: `streak referenced unknown/non-ready bead id '${id}'` };
53
+ }
54
+ if (seen.has(id)) {
55
+ return { ...fallback(), reason: `bead id '${id}' appeared in more than one streak` };
56
+ }
57
+ seen.add(id);
58
+ resolvedStreak.push(byId.get(id));
59
+ }
60
+ resolvedStreaks.push(resolvedStreak);
61
+ }
62
+
63
+ if (seen.size !== readyIds.length) {
64
+ return { ...fallback(), reason: `candidate covered ${seen.size} of ${readyIds.length} ready bead id(s)` };
65
+ }
66
+
67
+ return { streaks: resolvedStreaks, usedFallback: false, reason: null };
68
+ }
69
+
70
+ /**
71
+ * Deterministic streak grouping from planner-emitted lane metadata (`streak` /
72
+ * `streakOrder`, recorded by planner.md through the same beads `--metadata`
73
+ * channel as `model`), intersected with the CURRENT ready set. When every ready
74
+ * bead is laned the grouping is fully determined by the plan and no agent()
75
+ * call is needed.
76
+ *
77
+ * Contract (mirrors selectStreaks' return shape, so the two are interchangeable
78
+ * at the call site):
79
+ * - Returns `null` when ANY ready bead is missing a non-empty
80
+ * `metadata.streak`. A partly-laned plan counts as "no lane metadata" so the
81
+ * caller falls back to the LLM assignment path; a plan must never be grouped
82
+ * by a mix of the two mechanisms.
83
+ * - Otherwise returns `{ streaks, reason: null }`, arrays of the ORIGINAL bead
84
+ * objects grouped by `streak` id.
85
+ *
86
+ * Ordering is total and stable: within a lane by numeric `streakOrder`
87
+ * ascending (missing/non-numeric last), then `title`, then `id`; lanes by their
88
+ * minimum `streakOrder`, then `streak` id. Members of a ready set are mutually
89
+ * unblocked by definition (a `blocks` edge would keep the blocked side out of
90
+ * the set), so `streakOrder` alone cannot violate a blocks edge and the
91
+ * title/id tiebreak only separates otherwise-equal peers.
92
+ *
93
+ * Pure: no I/O, no agent() calls.
94
+ * @param {Array<{id: string, title?: string, metadata?: {streak?: string, streakOrder?: number|string}}>} currentReady
95
+ * @returns {{ streaks: Array<Array<object>>, reason: null } | null}
96
+ */
97
+ export function groupStreaksFromLaneMetadata(currentReady) {
98
+ if (!Array.isArray(currentReady) || currentReady.length === 0) {
99
+ return null;
100
+ }
101
+ // A single un-laned bead disqualifies the whole deterministic path.
102
+ for (const b of currentReady) {
103
+ const streakId = b && b.metadata && b.metadata.streak;
104
+ if (typeof streakId !== 'string' || streakId.trim() === '') {
105
+ return null;
106
+ }
107
+ }
108
+
109
+ const orderOf = (b) => {
110
+ const raw = b.metadata.streakOrder;
111
+ const n = typeof raw === 'number' ? raw : Number.parseInt(raw, 10);
112
+ return Number.isFinite(n) ? n : Number.POSITIVE_INFINITY;
113
+ };
114
+ const withinLane = (a, b) =>
115
+ orderOf(a) - orderOf(b)
116
+ || String(a.title || '').localeCompare(String(b.title || ''))
117
+ || String(a.id).localeCompare(String(b.id));
118
+
119
+ const lanes = new Map();
120
+ for (const b of currentReady) {
121
+ const streakId = b.metadata.streak;
122
+ if (!lanes.has(streakId)) lanes.set(streakId, []);
123
+ lanes.get(streakId).push(b);
124
+ }
125
+
126
+ const laneEntries = [...lanes.entries()].map(([streakId, beads]) => {
127
+ const sorted = beads.slice().sort(withinLane);
128
+ const minOrder = Math.min(...sorted.map(orderOf));
129
+ return { streakId, sorted, minOrder };
130
+ });
131
+ laneEntries.sort((x, y) =>
132
+ x.minOrder - y.minOrder
133
+ || String(x.streakId).localeCompare(String(y.streakId)));
134
+
135
+ return { streaks: laneEntries.map((e) => e.sorted), reason: null };
136
+ }
137
+
138
+ export const SIZE_POINTS = Object.freeze({ S: 1, M: 2, L: 4 });
139
+ export const MODEL_WEIGHT = Object.freeze({ cheap: 1, standard: 10, premium: 20 });
140
+ export const DEFAULT_EFFORT_THRESHOLD = 200;
141
+
142
+ /**
143
+ * Effort formula shared with planner.md: `effort = (sum of per-task size
144
+ * points) x (max model weight across the lane)`. planner.md documents the
145
+ * same formula as design-time math the planner applies when authoring lane
146
+ * metadata; this is the executable reference the runtime effort budget and
147
+ * the unit tests use.
148
+ * @param {Array<{size: 'S'|'M'|'L', model: 'cheap'|'standard'|'premium'}>} tasks
149
+ * @returns {number}
150
+ */
151
+ export function computeLaneEffort(tasks) {
152
+ const sizeSum = tasks.reduce((acc, t) => acc + (SIZE_POINTS[t.size] || 0), 0);
153
+ const maxWeight = tasks.reduce((acc, t) => Math.max(acc, MODEL_WEIGHT[t.model] || 0), 0);
154
+ return sizeSum * maxWeight;
155
+ }
156
+
157
+ // ---------------------------------------------------------------------------
158
+ // Multi-streak assignment per doer (ordered worklists)
159
+ // ---------------------------------------------------------------------------
160
+ //
161
+ // When a develop round has more ready streaks than doers, these functions pack
162
+ // them into PER-DOER ORDERED WORKLISTS so one doer can work several streaks
163
+ // back to back -- resuming its own session between them (mode ii, default) or
164
+ // carrying the whole worklist in a single batched dispatch (mode i,
165
+ // config-gated) -- instead of re-paying the fixed dispatch overhead per streak.
166
+ //
167
+ // The assignment/ordering decision is deterministic and makes no LLM call.
168
+
169
+ // Tier-grouping key for a streak with no model metadata at all. Such a streak
170
+ // gets its own group rather than being folded into a real tier, which would
171
+ // either under-run required work or silently upgrade cheap work.
172
+ const UNSPECIFIED_TIER_KEY = 'unspecified';
173
+
174
+ /**
175
+ * A streak's REQUIRED model tier: the maximum (most-capable) tier across its
176
+ * member beads' `metadata.model`, per planner.md's "max model weight in the
177
+ * lane" formula. A streak must never execute on a tier below this. Beads whose
178
+ * model metadata is missing or is not one of the three tier names contribute
179
+ * nothing; a streak where no bead names a tier returns `null`, and the
180
+ * dispatch runs untiered.
181
+ * @param {Array<{metadata?: {model?: unknown}}>} streak
182
+ * @returns {'cheap'|'standard'|'premium'|null}
183
+ */
184
+ export function streakRequiredTier(streak) {
185
+ let best = null;
186
+ for (const bead of streak || []) {
187
+ const tier = normalizeTierToken(bead && bead.metadata && bead.metadata.model);
188
+ if (typeof tier === 'string' && MODEL_WEIGHT[tier] && (!best || MODEL_WEIGHT[tier] > MODEL_WEIGHT[best])) {
189
+ best = tier;
190
+ }
191
+ }
192
+ return best;
193
+ }
194
+
195
+ /**
196
+ * A streak's priority: the MINIMUM (i.e. most urgent) numeric priority among
197
+ * its member beads (bd's `priority` field, where 0 = P0). Beads without a
198
+ * numeric priority contribute nothing; a streak with none at all returns
199
+ * POSITIVE_INFINITY so it sorts after every priority-carrying streak and falls
200
+ * through to the deterministic tie-break.
201
+ * @param {Array<{priority?: unknown}>} streak
202
+ * @returns {number}
203
+ */
204
+ export function streakMinPriority(streak) {
205
+ let min = Number.POSITIVE_INFINITY;
206
+ for (const bead of streak || []) {
207
+ const p = bead ? bead.priority : undefined;
208
+ if (typeof p === 'number' && Number.isFinite(p) && p < min) {
209
+ min = p;
210
+ }
211
+ }
212
+ return min;
213
+ }
214
+
215
+ /**
216
+ * A streak's effort-point total, computed with the shared planner.md formula
217
+ * (computeLaneEffort: sum of size points x max model weight). planner.md
218
+ * mandates `size` alongside `model`/`streak`/`streakOrder`, but the defaults
219
+ * below still cover beads created outside a planner pass (e.g. reviewer
220
+ * `newTasks`, `[integ]` bugs, adopted carry-over beads): a bead without a
221
+ * usable `metadata.size` (S/M/L) defaults to 'M', the middle of the scale,
222
+ * and a bead without a tier-shaped model defaults to 'standard' for the
223
+ * WEIGHT term only. The defaults feed budget arithmetic and never affect
224
+ * which model a dispatch runs on -- streakRequiredTier decides that.
225
+ * @param {Array<{metadata?: {size?: unknown, model?: unknown}}>} streak
226
+ * @returns {number}
227
+ */
228
+ export function streakEffortPoints(streak) {
229
+ const tasks = (streak || []).map((bead) => {
230
+ const rawSize = bead && bead.metadata ? bead.metadata.size : undefined;
231
+ const size = typeof rawSize === 'string' && SIZE_POINTS[rawSize.trim().toUpperCase()]
232
+ ? rawSize.trim().toUpperCase()
233
+ : 'M';
234
+ const tier = normalizeTierToken(bead && bead.metadata && bead.metadata.model);
235
+ const model = typeof tier === 'string' && MODEL_WEIGHT[tier] ? tier : 'standard';
236
+ return { size, model };
237
+ });
238
+ return computeLaneEffort(tasks);
239
+ }
240
+
241
+ /**
242
+ * The ids a bead declares a `blocks`-type dependency on, i.e. beads that must
243
+ * finish BEFORE it. Accepts either shape a dependency entry can take: a full
244
+ * object carrying `dependency_type` (as `bd show --json` emits) or a plain id
245
+ * string. Entries of any other dependency type are not ordering constraints
246
+ * and are ignored.
247
+ * @param {{dependencies?: Array<string|{id?: string, depends_on_id?: string, dependency_type?: string}>}} bead
248
+ * @returns {string[]}
249
+ */
250
+ export function beadBlocksDependencyIds(bead) {
251
+ const out = [];
252
+ const deps = bead && Array.isArray(bead.dependencies) ? bead.dependencies : [];
253
+ for (const dep of deps) {
254
+ if (typeof dep === 'string' && dep) {
255
+ out.push(dep);
256
+ } else if (dep && typeof dep === 'object') {
257
+ if (dep.dependency_type && dep.dependency_type !== 'blocks') continue;
258
+ const id = dep.depends_on_id || dep.id;
259
+ if (typeof id === 'string' && id) out.push(id);
260
+ }
261
+ }
262
+ return out;
263
+ }
264
+
265
+ /**
266
+ * The tier policy for this round's worklist assignment, and the single place
267
+ * the "provider supports model-switch-on-resume" capability check is made.
268
+ * Mode (i) BATCH is one dispatch and therefore one model, so it ALWAYS
269
+ * requires a tier-homogeneous worklist; a mixed batch is rejected at
270
+ * assignment time rather than resolved by running everything at max tier. Mode
271
+ * (ii) RESUMED SEQUENCE may carry mixed tiers only when the provider can
272
+ * change model on a resumed session, signalled by `resumeModelSwitch`, whose
273
+ * default of false is the safe fallback to tier-homogeneous grouping.
274
+ *
275
+ * PRODUCTIZE-OR-PRUNE AUDIT (apra-fleet-3swo.7.13): `doer_worklist_mode`
276
+ * 'batch' and `resume_model_switch` (the two sprint-args.mjs keys this
277
+ * function consumes) have no CLI flag and no caller in this repo, but both
278
+ * were audited and PRODUCTIZED -- see sprint-args.mjs's KNOWN_ARG_KEYS
279
+ * comments and docs/fleet-sprint-cli-contract.md's "Dormant argument audit"
280
+ * for the caller-search evidence and the tests that exercise each end-to-end.
281
+ * @param {{ mode: 'resume'|'batch', resumeModelSwitch?: boolean }} opts
282
+ * @returns {{ tierHomogeneous: boolean }}
283
+ */
284
+ export function resolveWorklistTierPolicy({ mode, resumeModelSwitch = false }) {
285
+ if (mode === 'batch') return { tierHomogeneous: true };
286
+ return { tierHomogeneous: !resumeModelSwitch };
287
+ }
288
+
289
+ /**
290
+ * Whether the last dispatch's reported usage leaves enough context headroom to
291
+ * RESUME that session for the next streak. Mirrors createRoundSessionRegistry's
292
+ * near-ceiling rule: admission fails when the reported total_tokens is at or
293
+ * above `ceilingFraction` of `contextCeiling`. Unknown usage admits, the same
294
+ * stance the registry takes. On refusal the caller must fall back to a FRESH
295
+ * session carrying the FULL prompt -- never a delta prompt into a fresh
296
+ * session, since a delta only makes sense against a resumed session id.
297
+ * @param {{total_tokens?: number}|null|undefined} usage
298
+ * @param {{ contextCeiling?: number, ceilingFraction?: number }} [opts]
299
+ * @returns {boolean}
300
+ */
301
+ export function hasContextHeadroomForResume(usage, opts = {}) {
302
+ const contextCeiling = typeof opts.contextCeiling === 'number' && opts.contextCeiling > 0
303
+ ? opts.contextCeiling
304
+ : DEFAULT_CONTEXT_CEILING;
305
+ const ceilingFraction = typeof opts.ceilingFraction === 'number' && opts.ceilingFraction > 0
306
+ ? opts.ceilingFraction
307
+ : 0.9;
308
+ const totalTokens = usage && typeof usage.total_tokens === 'number' ? usage.total_tokens : null;
309
+ if (totalTokens === null) return true;
310
+ return totalTokens < contextCeiling * ceilingFraction;
311
+ }
312
+
313
+ /**
314
+ * Packs this round's streaks (as produced by groupStreaksFromLaneMetadata or
315
+ * selectStreaks) into per-doer ORDERED worklists.
316
+ *
317
+ * Pass-through: when `streaks.length <= doerCount` there is nothing to pack --
318
+ * every doer gets exactly one streak in the exact input order, with no
319
+ * re-sorting, no budget, and no tier logic.
320
+ *
321
+ * Packing path (`streaks.length > doerCount`) orders streaks by, in strict
322
+ * precedence:
323
+ * 1. `blocks`-edge constraints between streaks, which are HARD: a streak
324
+ * depending on beads in another streak of this round is placed in the SAME
325
+ * worklist AFTER that streak, co-location being the only arrangement that
326
+ * guarantees order under the global FIFO dispatch gate, or overflows if
327
+ * that is impossible. A streak whose in-round dependency overflowed
328
+ * overflows too. Lane formation normally prevents such edges between ready
329
+ * streaks, but one that exists is never violated.
330
+ * 2. Priority: among streaks with no dependency relationship,
331
+ * streakMinPriority ascending, so a P3 streak never occupies a doer ahead
332
+ * of an equally-ready P0 streak.
333
+ * 3. Input index, which is itself already a deterministic order (lane
334
+ * minOrder, then streakId/title/id on the lane-metadata path), so the
335
+ * tie-break adds no nondeterminism.
336
+ *
337
+ * Grouping rules:
338
+ * - TIER-OUTLIER ISOLATION: streaks are PARTITIONED BY TIER FIRST, before any
339
+ * priority/effort-budget packing, and each partition packs independently
340
+ * into its own slot(s). A minority-tier outlier is never folded into a
341
+ * majority-tier worklist just because effort-budget headroom allows it,
342
+ * which is what keeps tier homogeneity from silently escalating cheaper
343
+ * work to a costlier tier. Slots round-robin over the doer pool at the
344
+ * dispatch site, so under a homogeneous tier policy more partitions than
345
+ * doers still dispatch this round, each as its own tier-pure worklist on a
346
+ * shared doer; a mixed worklist is never built. When mixed tiers are
347
+ * allowed, whole partitions merge into at most doerCount worklists, each
348
+ * appended as its own CONTIGUOUS run, never interleaved with another tier's
349
+ * streaks.
350
+ * - Effort budget (opts.effortBudget, default DEFAULT_EFFORT_THRESHOLD, in
351
+ * the planner.md effort points): a streak joins a non-empty worklist only
352
+ * if the running total stays within budget, otherwise it queues to the next
353
+ * round via `overflow`. An EMPTY worklist always accepts, so a single
354
+ * over-budget streak still dispatches rather than starving forever.
355
+ *
356
+ * @param {Array<Array<object>>} streaks - arrays of ORIGINAL bead objects
357
+ * @param {number} doerCount
358
+ * @param {{ effortBudget?: number, tierHomogeneous?: boolean }} [opts]
359
+ * @returns {{
360
+ * worklists: Array<Array<Array<object>>>, // worklists[doerIndex] = ordered streak list
361
+ * overflow: Array<Array<object>>, // streaks queued to the next round
362
+ * packed: boolean, // false = pass-through (no packing needed)
363
+ * }}
364
+ */
365
+ export function assignDoerWorklists(streaks, doerCount, opts = {}) {
366
+ if (!Array.isArray(streaks) || streaks.length === 0
367
+ || !Number.isInteger(doerCount) || doerCount < 1) {
368
+ return { worklists: [], overflow: [], packed: false };
369
+ }
370
+ if (streaks.length <= doerCount) {
371
+ return { worklists: streaks.map((s) => [s]), overflow: [], packed: false };
372
+ }
373
+
374
+ const effortBudget = typeof opts.effortBudget === 'number' && opts.effortBudget > 0
375
+ ? opts.effortBudget
376
+ : DEFAULT_EFFORT_THRESHOLD;
377
+ const tierHomogeneous = opts.tierHomogeneous === true;
378
+
379
+ // --- Descriptors -------------------------------------------------------
380
+ const descs = streaks.map((streak, index) => ({
381
+ streak,
382
+ index,
383
+ priority: streakMinPriority(streak),
384
+ tierKey: streakRequiredTier(streak) || UNSPECIFIED_TIER_KEY,
385
+ effort: streakEffortPoints(streak),
386
+ beadIds: new Set(streak.map((b) => String(b && b.id))),
387
+ depIndexes: new Set(),
388
+ }));
389
+ const descByBeadId = new Map();
390
+ for (const d of descs) {
391
+ for (const id of d.beadIds) descByBeadId.set(id, d);
392
+ }
393
+ for (const d of descs) {
394
+ for (const bead of d.streak) {
395
+ for (const depId of beadBlocksDependencyIds(bead)) {
396
+ const other = descByBeadId.get(String(depId));
397
+ if (other && other !== d) d.depIndexes.add(other.index);
398
+ }
399
+ }
400
+ }
401
+
402
+ // --- Global order: dependency (hard) -> priority -> input index --------
403
+ // Kahn-style topological pass that, among the currently-unblocked streaks,
404
+ // always picks the (priority, index)-minimal one, so dependency order wins
405
+ // over priority and priority only orders mutually-independent streaks.
406
+ const order = [];
407
+ const remaining = new Set(descs.map((d) => d.index));
408
+ while (remaining.size > 0) {
409
+ let ready = [...remaining]
410
+ .map((i) => descs[i])
411
+ .filter((d) => [...d.depIndexes].every((di) => !remaining.has(di)));
412
+ if (ready.length === 0) {
413
+ // Dependency cycle between streaks (cannot happen for genuinely
414
+ // ready beads; defensive) -- fall back to (priority, index) order
415
+ // for the remainder rather than looping forever.
416
+ ready = [...remaining].map((i) => descs[i]);
417
+ }
418
+ ready.sort((a, b) => a.priority - b.priority || a.index - b.index);
419
+ const next = ready[0];
420
+ order.push(next);
421
+ remaining.delete(next.index);
422
+ }
423
+
424
+ // --- Packing: TIER-OUTLIER ISOLATION (partition-first) ------------------
425
+ // Streaks are partitioned by tier before any priority/effort-budget
426
+ // packing, and each partition's slot(s) pack independently, so a
427
+ // minority-tier outlier is never folded into a majority-tier worklist and
428
+ // silently escalated to that tier's cost. The global topo+priority order
429
+ // applies WITHIN a partition; partitions are claimed in order of their
430
+ // first appearance in that order, so the highest-priority work claims
431
+ // slots first.
432
+ //
433
+ // A SLOT is not a doer: the returned worklists round-robin over the doer
434
+ // pool at the dispatch site (worklists[i] -> doerPool[i % N]), so more
435
+ // partitions than doers still all dispatch this round, sequentially on a
436
+ // shared doer via the global FIFO gate. Sessions never carry across
437
+ // worklists, so a shared doer's second worklist is tier-pure by
438
+ // construction.
439
+ const overflow = [];
440
+ const overflowed = new Set();
441
+ const slots = []; // { items: desc[], effort: number }
442
+ const slotOfDesc = new Map(); // desc.index -> slot object
443
+
444
+ const newSlot = () => {
445
+ const slot = { items: [], effort: 0 };
446
+ slots.push(slot);
447
+ return slot;
448
+ };
449
+ const fits = (slot, d) => slot.items.length === 0 || slot.effort + d.effort <= effortBudget;
450
+ const place = (slot, d) => {
451
+ slot.items.push(d);
452
+ slot.effort += d.effort;
453
+ slotOfDesc.set(d.index, slot);
454
+ };
455
+ const spill = (d) => {
456
+ overflow.push(d.streak);
457
+ overflowed.add(d.index);
458
+ };
459
+
460
+ // Tier partitions, in order of each tier's first appearance in the global
461
+ // order; members stay in global (topo -> priority -> tie-break) order.
462
+ const partitions = [];
463
+ const partitionByTier = new Map();
464
+ for (const d of order) {
465
+ if (!partitionByTier.has(d.tierKey)) {
466
+ const p = { tierKey: d.tierKey, members: [], slots: [] };
467
+ partitionByTier.set(d.tierKey, p);
468
+ partitions.push(p);
469
+ }
470
+ partitionByTier.get(d.tierKey).members.push(d);
471
+ }
472
+
473
+ // Slot allocation. Every partition gets AT LEAST one dedicated slot
474
+ // (outlier isolation: a 1-streak minority partition gets a whole slot of
475
+ // its own before any majority partition gets a second one) -- EXCEPT in
476
+ // the mixed-tiers-allowed case below when partitions outnumber doers.
477
+ // When there are FEWER partitions than doers, the spare doer capacity is
478
+ // handed out one slot at a time to the partition with the highest
479
+ // per-slot load (ties: earliest partition), so e.g. 4 same-tier streaks
480
+ // over 2 doers still split 2/2. Deterministic throughout.
481
+ if (!tierHomogeneous && partitions.length > doerCount) {
482
+ // Mixed tiers allowed and more partitions than doers: merge WHOLE
483
+ // partitions into doerCount slots, each appended as its own contiguous
484
+ // run so no tier's streaks interleave with another's. Each partition
485
+ // joins the slot with the fewest streaks claimed so far, ties broken by
486
+ // creation order. Claims are whole partitions, so balance on claimed
487
+ // member counts rather than on items already placed.
488
+ for (let i = 0; i < doerCount; i++) newSlot();
489
+ const claimedCount = new Map(slots.map((s) => [s, 0]));
490
+ for (const p of partitions) {
491
+ const host = slots
492
+ .map((slot, si) => ({ slot, si }))
493
+ .sort((a, b) => claimedCount.get(a.slot) - claimedCount.get(b.slot) || a.si - b.si)[0].slot;
494
+ p.slots = [host];
495
+ claimedCount.set(host, claimedCount.get(host) + p.members.length);
496
+ }
497
+ } else {
498
+ for (const p of partitions) {
499
+ p.slots = [newSlot()];
500
+ }
501
+ let spare = doerCount - partitions.length;
502
+ while (spare > 0) {
503
+ let target = null;
504
+ for (const p of partitions) {
505
+ const load = p.members.length / p.slots.length;
506
+ if (!target || load > target.members.length / target.slots.length) target = p;
507
+ }
508
+ if (!target) break;
509
+ target.slots.push(newSlot());
510
+ spare--;
511
+ }
512
+ }
513
+
514
+ // Dependency gate: a streak whose in-round `blocks` dependency
515
+ // overflowed, is not placed yet (cross-partition edges are placed in
516
+ // partition order, and slots interleave at dispatch time, so order across
517
+ // slots is never guaranteed), or whose placed dependencies span slots the
518
+ // candidate set cannot honor, overflows to the next round (its dependency
519
+ // closes first). Returns the single slot all placed deps share, `null`
520
+ // for "no in-round dependency constraint", or `false` for "cannot place".
521
+ const depSlotFor = (d) => {
522
+ if (d.depIndexes.size === 0) return null;
523
+ const depSlots = new Set();
524
+ for (const di of d.depIndexes) {
525
+ if (overflowed.has(di)) return false;
526
+ if (!slotOfDesc.has(di)) return false; // not placed (yet) -> no order guarantee
527
+ depSlots.add(slotOfDesc.get(di));
528
+ }
529
+ return depSlots.size === 1 ? [...depSlots][0] : false;
530
+ };
531
+
532
+ for (const p of partitions) {
533
+ for (const d of p.members) {
534
+ const depSlot = depSlotFor(d);
535
+ if (depSlot === false) { spill(d); continue; }
536
+ // Dependency co-location: the dependent must land in the SAME
537
+ // slot AFTER its dependency -- but only if that slot is one this
538
+ // partition may use (tier purity is never sacrificed for a
539
+ // dependency; a cross-tier in-round edge overflows instead).
540
+ const candidates = (depSlot !== null ? [depSlot] : p.slots)
541
+ .filter((slot) => (depSlot === null || p.slots.includes(slot)) && fits(slot, d))
542
+ .sort((a, b) => a.items.length - b.items.length || slots.indexOf(a) - slots.indexOf(b));
543
+ if (candidates.length === 0) spill(d);
544
+ else place(candidates[0], d);
545
+ }
546
+ }
547
+
548
+ // Drop slots that ended up empty (a mixed-merge pre-created slot no
549
+ // partition landed on, or a partition slot whose members all spilled).
550
+ const worklists = slots
551
+ .filter((slot) => slot.items.length > 0)
552
+ // Worklist order within each slot = insertion order: contiguous tier
553
+ // blocks (partition-by-partition placement), and inside each block
554
+ // the global topo -> priority -> tie-break order (partition members
555
+ // were placed in that order).
556
+ .map((slot) => slot.items.map((d) => d.streak));
557
+
558
+ return { worklists, overflow, packed: true };
559
+ }
@@ -13,7 +13,7 @@
13
13
  "fleet-se-serve": "./bin/serve.mjs"
14
14
  },
15
15
  "scripts": {
16
- "test": "node --test --test-reporter=./test/helpers/timestamped-reporter.mjs --test-reporter-destination=stdout --test-concurrency=8 test/*.test.mjs",
16
+ "test": "node scripts/run-tests.mjs mock",
17
17
  "test:slow": "node --test --test-reporter=./test/helpers/timestamped-reporter.mjs --test-reporter-destination=stdout test/slow/*.test.mjs",
18
18
  "test:unit": "node scripts/run-tests.mjs mock",
19
19
  "test:integration": "node scripts/run-tests.mjs real",
@@ -843,7 +843,12 @@ const HTML_TEMPLATE = (dashboardExtensions, opts = {}) => {
843
843
  const sinceStr = pause.since ? new Date(pause.since).toLocaleTimeString([], { hour12: false }) : '-';
844
844
  const reasonHtml = pause.reason ? \`<span>Reason: <strong>\${escapeHtml(pause.reason)}</strong></span>\` : '';
845
845
  const phaseHtml = pause.phase ? \`<span>Phase: <strong>\${escapeHtml(pause.phase)}</strong></span>\` : '';
846
- pauseBanner.innerHTML = \`<span>Paused since <strong>\${sinceStr}</strong></span>\${phaseHtml}\${reasonHtml}\`;
846
+ // (apra-fleet-hzeb.3) Only present for a script-initiated pause
847
+ // that supplied resumeAt (e.g. a provider usage-limit reset
848
+ // time via ctx.requestPause(reason, { resumeAt })) -- an
849
+ // operator-initiated /pause never sets it, so this stays absent.
850
+ const resumeAtHtml = pause.resumeAt ? \`<span>Expected resume: <strong>\${escapeHtml(pause.resumeAt)}</strong></span>\` : '';
851
+ pauseBanner.innerHTML = \`<span>Paused since <strong>\${sinceStr}</strong></span>\${phaseHtml}\${reasonHtml}\${resumeAtHtml}\`;
847
852
  pauseBanner.style.display = 'flex';
848
853
  } else {
849
854
  pauseBanner.innerHTML = '';
@@ -1078,7 +1083,7 @@ export function createDashboardViewer(workflow, opts = {}) {
1078
1083
  // timestamp). `phase`/`group` mirror wherever the run was when the
1079
1084
  // pause was requested, for the dashboard's reason card. Generic to
1080
1085
  // any workflow -- no fleet-sprint-specific fields.
1081
- pause: { status: 'none', reason: null, since: null, phase: null, group: null },
1086
+ pause: { status: 'none', reason: null, since: null, phase: null, group: null, resumeAt: null },
1082
1087
  tree: [],
1083
1088
  extensions: {}
1084
1089
  };
@@ -1338,13 +1343,18 @@ export function createDashboardViewer(workflow, opts = {}) {
1338
1343
  reason: payload.reason ?? null,
1339
1344
  since: null,
1340
1345
  phase: payload.phase ?? null,
1341
- group: payload.group ?? null
1346
+ group: payload.group ?? null,
1347
+ // (apra-fleet-hzeb.3) Set by a script-initiated pause (e.g. a
1348
+ // detected provider usage-limit signal) via ctx.requestPause(reason,
1349
+ // { resumeAt }) -- an operator-initiated pause via the dashboard's
1350
+ // /pause route never sets this, so it stays null there.
1351
+ resumeAt: payload.resumeAt ?? null
1342
1352
  };
1343
1353
  broadcast({ type: 'update' });
1344
1354
  });
1345
1355
 
1346
1356
  workflow.on('paused', (payload) => {
1347
- // The 'paused' event itself carries no reason (see
1357
+ // The 'paused' event itself carries no reason/resumeAt (see
1348
1358
  // FleetWorkflow._maybeEngagePause) -- preserve whatever
1349
1359
  // 'pause:requested' set, and only stamp `since` now, at the moment
1350
1360
  // the pause actually engaged.
@@ -1353,13 +1363,14 @@ export function createDashboardViewer(workflow, opts = {}) {
1353
1363
  reason: state.pause.reason,
1354
1364
  since: nowIso(),
1355
1365
  phase: payload.phase ?? state.pause.phase,
1356
- group: payload.group ?? state.pause.group
1366
+ group: payload.group ?? state.pause.group,
1367
+ resumeAt: state.pause.resumeAt
1357
1368
  };
1358
1369
  broadcast({ type: 'update' });
1359
1370
  });
1360
1371
 
1361
1372
  workflow.on('resumed', () => {
1362
- state.pause = { status: 'none', reason: null, since: null, phase: null, group: null };
1373
+ state.pause = { status: 'none', reason: null, since: null, phase: null, group: null, resumeAt: null };
1363
1374
  broadcast({ type: 'update' });
1364
1375
  });
1365
1376