@apralabs/apra-fleet 0.4.0 → 0.4.2

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 (548) hide show
  1. package/README.md +159 -13
  2. package/dist/agents/backlog-groomer.md +31 -19
  3. package/dist/agents/ci-watcher.md +16 -1
  4. package/dist/agents/deployer.md +37 -47
  5. package/dist/agents/doer.md +147 -114
  6. package/dist/agents/harvester.md +41 -34
  7. package/dist/agents/integ-test-runner.md +98 -114
  8. package/dist/agents/kb-reconciler.md +205 -0
  9. package/dist/agents/plan-reviewer.md +45 -44
  10. package/dist/agents/planner.md +121 -50
  11. package/dist/agents/regression-test-runner.md +84 -81
  12. package/dist/agents/reviewer.md +118 -44
  13. package/dist/agents/schemas/doer-output.json +63 -3
  14. package/dist/agents/schemas/harvester-output.json +59 -2
  15. package/dist/agents/schemas/integ-test-runner-output.json +3 -3
  16. package/dist/agents/schemas/kb-reconciler-output.json +87 -0
  17. package/dist/agents/schemas/planner-output.json +65 -0
  18. package/dist/agents/schemas/regression-test-runner-output.json +4 -17
  19. package/dist/agents/schemas/reviewer-output.json +105 -8
  20. package/dist/cli/auth.d.ts.map +1 -1
  21. package/dist/cli/auth.js +1 -2
  22. package/dist/cli/auth.js.map +1 -1
  23. package/dist/cli/config.d.ts +3 -3
  24. package/dist/cli/config.d.ts.map +1 -1
  25. package/dist/cli/config.js +4 -13
  26. package/dist/cli/config.js.map +1 -1
  27. package/dist/cli/install.d.ts +1 -0
  28. package/dist/cli/install.d.ts.map +1 -1
  29. package/dist/cli/install.js +141 -44
  30. package/dist/cli/install.js.map +1 -1
  31. package/dist/cli/join.js +1 -1
  32. package/dist/cli/join.js.map +1 -1
  33. package/dist/cli/kb-commit.d.ts +12 -0
  34. package/dist/cli/kb-commit.d.ts.map +1 -0
  35. package/dist/cli/kb-commit.js +53 -0
  36. package/dist/cli/kb-commit.js.map +1 -0
  37. package/dist/cli/kb-directives.d.ts +17 -0
  38. package/dist/cli/kb-directives.d.ts.map +1 -0
  39. package/dist/cli/kb-directives.js +146 -0
  40. package/dist/cli/kb-directives.js.map +1 -0
  41. package/dist/cli/kb-import.d.ts +13 -0
  42. package/dist/cli/kb-import.d.ts.map +1 -0
  43. package/dist/cli/kb-import.js +56 -0
  44. package/dist/cli/kb-import.js.map +1 -0
  45. package/dist/cli/register-member.js +1 -1
  46. package/dist/cli/start.d.ts.map +1 -1
  47. package/dist/cli/start.js +7 -0
  48. package/dist/cli/start.js.map +1 -1
  49. package/dist/cli/uninstall.d.ts.map +1 -1
  50. package/dist/cli/uninstall.js +16 -3
  51. package/dist/cli/uninstall.js.map +1 -1
  52. package/dist/cli/watch.d.ts +76 -4
  53. package/dist/cli/watch.d.ts.map +1 -1
  54. package/dist/cli/watch.js +150 -17
  55. package/dist/cli/watch.js.map +1 -1
  56. package/dist/commands/kb-server.d.ts +8 -0
  57. package/dist/commands/kb-server.d.ts.map +1 -0
  58. package/dist/commands/kb-server.js +221 -0
  59. package/dist/commands/kb-server.js.map +1 -0
  60. package/dist/index.js +77 -2
  61. package/dist/index.js.map +1 -1
  62. package/dist/os/git-bash-candidates.d.ts +35 -0
  63. package/dist/os/git-bash-candidates.d.ts.map +1 -0
  64. package/dist/os/git-bash-candidates.js +46 -0
  65. package/dist/os/git-bash-candidates.js.map +1 -0
  66. package/dist/os/index.d.ts +13 -4
  67. package/dist/os/index.d.ts.map +1 -1
  68. package/dist/os/index.js +17 -2
  69. package/dist/os/index.js.map +1 -1
  70. package/dist/os/linux.d.ts +1 -0
  71. package/dist/os/linux.d.ts.map +1 -1
  72. package/dist/os/linux.js +19 -2
  73. package/dist/os/linux.js.map +1 -1
  74. package/dist/os/os-commands.d.ts +12 -0
  75. package/dist/os/os-commands.d.ts.map +1 -1
  76. package/dist/os/os-commands.js.map +1 -1
  77. package/dist/os/windows-gitbash.d.ts +93 -0
  78. package/dist/os/windows-gitbash.d.ts.map +1 -0
  79. package/dist/os/windows-gitbash.js +244 -0
  80. package/dist/os/windows-gitbash.js.map +1 -0
  81. package/dist/os/windows.d.ts +35 -0
  82. package/dist/os/windows.d.ts.map +1 -1
  83. package/dist/os/windows.js +93 -35
  84. package/dist/os/windows.js.map +1 -1
  85. package/dist/providers/agy.d.ts +15 -3
  86. package/dist/providers/agy.d.ts.map +1 -1
  87. package/dist/providers/agy.js +145 -11
  88. package/dist/providers/agy.js.map +1 -1
  89. package/dist/providers/claude.d.ts +14 -3
  90. package/dist/providers/claude.d.ts.map +1 -1
  91. package/dist/providers/claude.js +69 -22
  92. package/dist/providers/claude.js.map +1 -1
  93. package/dist/providers/codex.d.ts +14 -3
  94. package/dist/providers/codex.d.ts.map +1 -1
  95. package/dist/providers/codex.js +34 -8
  96. package/dist/providers/codex.js.map +1 -1
  97. package/dist/providers/copilot.d.ts +14 -3
  98. package/dist/providers/copilot.d.ts.map +1 -1
  99. package/dist/providers/copilot.js +33 -8
  100. package/dist/providers/copilot.js.map +1 -1
  101. package/dist/providers/email/headers.d.ts +15 -0
  102. package/dist/providers/email/headers.d.ts.map +1 -0
  103. package/dist/providers/email/headers.js +42 -0
  104. package/dist/providers/email/headers.js.map +1 -0
  105. package/dist/providers/email/index.d.ts +18 -0
  106. package/dist/providers/email/index.d.ts.map +1 -0
  107. package/dist/providers/email/index.js +60 -0
  108. package/dist/providers/email/index.js.map +1 -0
  109. package/dist/providers/email/provider.d.ts +49 -0
  110. package/dist/providers/email/provider.d.ts.map +1 -0
  111. package/dist/providers/email/provider.js +2 -0
  112. package/dist/providers/email/provider.js.map +1 -0
  113. package/dist/providers/email/sendgrid.d.ts +12 -0
  114. package/dist/providers/email/sendgrid.d.ts.map +1 -0
  115. package/dist/providers/email/sendgrid.js +67 -0
  116. package/dist/providers/email/sendgrid.js.map +1 -0
  117. package/dist/providers/email/smtp.d.ts +65 -0
  118. package/dist/providers/email/smtp.d.ts.map +1 -0
  119. package/dist/providers/email/smtp.js +373 -0
  120. package/dist/providers/email/smtp.js.map +1 -0
  121. package/dist/providers/index.d.ts +0 -1
  122. package/dist/providers/index.d.ts.map +1 -1
  123. package/dist/providers/index.js +0 -3
  124. package/dist/providers/index.js.map +1 -1
  125. package/dist/providers/none.d.ts +14 -3
  126. package/dist/providers/none.d.ts.map +1 -1
  127. package/dist/providers/none.js +26 -2
  128. package/dist/providers/none.js.map +1 -1
  129. package/dist/providers/opencode.d.ts +14 -3
  130. package/dist/providers/opencode.d.ts.map +1 -1
  131. package/dist/providers/opencode.js +60 -6
  132. package/dist/providers/opencode.js.map +1 -1
  133. package/dist/providers/provider.d.ts +91 -5
  134. package/dist/providers/provider.d.ts.map +1 -1
  135. package/dist/providers/provider.js +45 -1
  136. package/dist/providers/provider.js.map +1 -1
  137. package/dist/services/agent-provisioner.d.ts.map +1 -1
  138. package/dist/services/agent-provisioner.js +5 -8
  139. package/dist/services/agent-provisioner.js.map +1 -1
  140. package/dist/services/cloud/activity.js +2 -2
  141. package/dist/services/cloud/activity.js.map +1 -1
  142. package/dist/services/cloud/lifecycle.d.ts.map +1 -1
  143. package/dist/services/cloud/lifecycle.js +3 -0
  144. package/dist/services/cloud/lifecycle.js.map +1 -1
  145. package/dist/services/cloud/task-wrapper.d.ts +18 -0
  146. package/dist/services/cloud/task-wrapper.d.ts.map +1 -1
  147. package/dist/services/cloud/task-wrapper.js +157 -0
  148. package/dist/services/cloud/task-wrapper.js.map +1 -1
  149. package/dist/services/context-admission.d.ts.map +1 -1
  150. package/dist/services/context-admission.js +9 -7
  151. package/dist/services/context-admission.js.map +1 -1
  152. package/dist/services/credential-cleanup.d.ts.map +1 -1
  153. package/dist/services/credential-cleanup.js +22 -3
  154. package/dist/services/credential-cleanup.js.map +1 -1
  155. package/dist/services/github-app.d.ts.map +1 -1
  156. package/dist/services/github-app.js +11 -2
  157. package/dist/services/github-app.js.map +1 -1
  158. package/dist/services/knowledge/audn.d.ts +37 -0
  159. package/dist/services/knowledge/audn.d.ts.map +1 -0
  160. package/dist/services/knowledge/audn.js +219 -0
  161. package/dist/services/knowledge/audn.js.map +1 -0
  162. package/dist/services/knowledge/file-hash.d.ts +11 -0
  163. package/dist/services/knowledge/file-hash.d.ts.map +1 -0
  164. package/dist/services/knowledge/file-hash.js +123 -0
  165. package/dist/services/knowledge/file-hash.js.map +1 -0
  166. package/dist/services/knowledge/http-provider.d.ts +46 -0
  167. package/dist/services/knowledge/http-provider.d.ts.map +1 -0
  168. package/dist/services/knowledge/http-provider.js +254 -0
  169. package/dist/services/knowledge/http-provider.js.map +1 -0
  170. package/dist/services/knowledge/kb-providers.d.ts +15 -0
  171. package/dist/services/knowledge/kb-providers.d.ts.map +1 -0
  172. package/dist/services/knowledge/kb-providers.js +92 -0
  173. package/dist/services/knowledge/kb-providers.js.map +1 -0
  174. package/dist/services/knowledge/kb-scope-input.d.ts +5 -0
  175. package/dist/services/knowledge/kb-scope-input.d.ts.map +1 -0
  176. package/dist/services/knowledge/kb-scope-input.js +11 -0
  177. package/dist/services/knowledge/kb-scope-input.js.map +1 -0
  178. package/dist/services/knowledge/kb-service.d.ts +3 -0
  179. package/dist/services/knowledge/kb-service.d.ts.map +1 -0
  180. package/dist/services/knowledge/kb-service.js +2 -0
  181. package/dist/services/knowledge/kb-service.js.map +1 -0
  182. package/dist/services/knowledge/path-validation.d.ts +2 -0
  183. package/dist/services/knowledge/path-validation.d.ts.map +1 -0
  184. package/dist/services/knowledge/path-validation.js +13 -0
  185. package/dist/services/knowledge/path-validation.js.map +1 -0
  186. package/dist/services/knowledge/pre-init.d.ts +14 -0
  187. package/dist/services/knowledge/pre-init.d.ts.map +1 -0
  188. package/dist/services/knowledge/pre-init.js +147 -0
  189. package/dist/services/knowledge/pre-init.js.map +1 -0
  190. package/dist/services/knowledge/project-slug.d.ts +2 -0
  191. package/dist/services/knowledge/project-slug.d.ts.map +1 -0
  192. package/dist/services/knowledge/project-slug.js +49 -0
  193. package/dist/services/knowledge/project-slug.js.map +1 -0
  194. package/dist/services/knowledge/sqlite-provider.d.ts +147 -0
  195. package/dist/services/knowledge/sqlite-provider.d.ts.map +1 -0
  196. package/dist/services/knowledge/sqlite-provider.js +1646 -0
  197. package/dist/services/knowledge/sqlite-provider.js.map +1 -0
  198. package/dist/services/knowledge/types.d.ts +163 -0
  199. package/dist/services/knowledge/types.d.ts.map +1 -0
  200. package/dist/services/knowledge/types.js +9 -0
  201. package/dist/services/knowledge/types.js.map +1 -0
  202. package/dist/services/member-home.d.ts +89 -0
  203. package/dist/services/member-home.d.ts.map +1 -0
  204. package/dist/services/member-home.js +259 -0
  205. package/dist/services/member-home.js.map +1 -0
  206. package/dist/services/member-remote-url.d.ts +34 -0
  207. package/dist/services/member-remote-url.d.ts.map +1 -0
  208. package/dist/services/member-remote-url.js +39 -0
  209. package/dist/services/member-remote-url.js.map +1 -0
  210. package/dist/services/model-pricing.d.ts.map +1 -1
  211. package/dist/services/model-pricing.js +0 -5
  212. package/dist/services/model-pricing.js.map +1 -1
  213. package/dist/services/orphan-recovery.d.ts +9 -3
  214. package/dist/services/orphan-recovery.d.ts.map +1 -1
  215. package/dist/services/orphan-recovery.js +22 -8
  216. package/dist/services/orphan-recovery.js.map +1 -1
  217. package/dist/services/preflight-check.d.ts +56 -0
  218. package/dist/services/preflight-check.d.ts.map +1 -0
  219. package/dist/services/preflight-check.js +277 -0
  220. package/dist/services/preflight-check.js.map +1 -0
  221. package/dist/services/shell-probe.d.ts +131 -0
  222. package/dist/services/shell-probe.d.ts.map +1 -0
  223. package/dist/services/shell-probe.js +210 -0
  224. package/dist/services/shell-probe.js.map +1 -0
  225. package/dist/services/singleton.d.ts +2 -0
  226. package/dist/services/singleton.d.ts.map +1 -1
  227. package/dist/services/singleton.js +1 -1
  228. package/dist/services/singleton.js.map +1 -1
  229. package/dist/services/ssh.js +2 -2
  230. package/dist/services/ssh.js.map +1 -1
  231. package/dist/services/stall/find-log-file.d.ts.map +1 -1
  232. package/dist/services/stall/find-log-file.js +22 -16
  233. package/dist/services/stall/find-log-file.js.map +1 -1
  234. package/dist/services/stall/log-path-resolver.d.ts +11 -8
  235. package/dist/services/stall/log-path-resolver.d.ts.map +1 -1
  236. package/dist/services/stall/log-path-resolver.js +17 -40
  237. package/dist/services/stall/log-path-resolver.js.map +1 -1
  238. package/dist/services/stall/read-log-tail.d.ts.map +1 -1
  239. package/dist/services/stall/read-log-tail.js +6 -5
  240. package/dist/services/stall/read-log-tail.js.map +1 -1
  241. package/dist/services/stall/stall-detector.d.ts +32 -0
  242. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  243. package/dist/services/stall/stall-detector.js +149 -6
  244. package/dist/services/stall/stall-detector.js.map +1 -1
  245. package/dist/services/stall/stall-poller.d.ts +34 -0
  246. package/dist/services/stall/stall-poller.d.ts.map +1 -1
  247. package/dist/services/stall/stall-poller.js +160 -35
  248. package/dist/services/stall/stall-poller.js.map +1 -1
  249. package/dist/services/strategy.d.ts +9 -0
  250. package/dist/services/strategy.d.ts.map +1 -1
  251. package/dist/services/strategy.js +41 -7
  252. package/dist/services/strategy.js.map +1 -1
  253. package/dist/services/tool-registry.d.ts.map +1 -1
  254. package/dist/services/tool-registry.js +87 -1
  255. package/dist/services/tool-registry.js.map +1 -1
  256. package/dist/services/user-config.js +1 -1
  257. package/dist/services/user-config.js.map +1 -1
  258. package/dist/services/vcs/azure-devops.d.ts +1 -1
  259. package/dist/services/vcs/azure-devops.d.ts.map +1 -1
  260. package/dist/services/vcs/azure-devops.js +105 -10
  261. package/dist/services/vcs/azure-devops.js.map +1 -1
  262. package/dist/services/vcs/bitbucket.d.ts.map +1 -1
  263. package/dist/services/vcs/bitbucket.js +16 -0
  264. package/dist/services/vcs/bitbucket.js.map +1 -1
  265. package/dist/services/vcs/github.d.ts.map +1 -1
  266. package/dist/services/vcs/github.js +56 -1
  267. package/dist/services/vcs/github.js.map +1 -1
  268. package/dist/services/vcs/types.d.ts +123 -2
  269. package/dist/services/vcs/types.d.ts.map +1 -1
  270. package/dist/services/version-check.d.ts +22 -0
  271. package/dist/services/version-check.d.ts.map +1 -0
  272. package/dist/services/version-check.js +103 -0
  273. package/dist/services/version-check.js.map +1 -0
  274. package/dist/skills/fleet-sprint-cli/SKILL.md +15 -3
  275. package/dist/skills/pm/SKILL.md +0 -1
  276. package/dist/skills/pm/beads.md +6 -0
  277. package/dist/skills/pm/cost.md +0 -1
  278. package/dist/skills/pm/fleet-addendum.md +6 -1
  279. package/dist/skills/pm/index.md +56 -0
  280. package/dist/skills/pm/kb-reconcile.md +132 -0
  281. package/dist/skills/pm/kb-review.md +109 -0
  282. package/dist/tools/check-status.d.ts +47 -0
  283. package/dist/tools/check-status.d.ts.map +1 -1
  284. package/dist/tools/check-status.js +245 -3
  285. package/dist/tools/check-status.js.map +1 -1
  286. package/dist/tools/child-id-allocator.d.ts +2 -2
  287. package/dist/tools/cloud-control.js +2 -2
  288. package/dist/tools/cloud-control.js.map +1 -1
  289. package/dist/tools/code-intelligence-codebase-memory.d.ts +11 -0
  290. package/dist/tools/code-intelligence-codebase-memory.d.ts.map +1 -0
  291. package/dist/tools/code-intelligence-codebase-memory.js +270 -0
  292. package/dist/tools/code-intelligence-codebase-memory.js.map +1 -0
  293. package/dist/tools/code-intelligence-freshness.d.ts +2 -0
  294. package/dist/tools/code-intelligence-freshness.d.ts.map +1 -0
  295. package/dist/tools/code-intelligence-freshness.js +26 -0
  296. package/dist/tools/code-intelligence-freshness.js.map +1 -0
  297. package/dist/tools/code-intelligence-gitnexus.d.ts +14 -0
  298. package/dist/tools/code-intelligence-gitnexus.d.ts.map +1 -0
  299. package/dist/tools/code-intelligence-gitnexus.js +475 -0
  300. package/dist/tools/code-intelligence-gitnexus.js.map +1 -0
  301. package/dist/tools/code-intelligence-kb-enrich.d.ts +2 -0
  302. package/dist/tools/code-intelligence-kb-enrich.d.ts.map +1 -0
  303. package/dist/tools/code-intelligence-kb-enrich.js +65 -0
  304. package/dist/tools/code-intelligence-kb-enrich.js.map +1 -0
  305. package/dist/tools/code-intelligence-reindex.d.ts +7 -0
  306. package/dist/tools/code-intelligence-reindex.d.ts.map +1 -0
  307. package/dist/tools/code-intelligence-reindex.js +106 -0
  308. package/dist/tools/code-intelligence-reindex.js.map +1 -0
  309. package/dist/tools/code-intelligence-telemetry.d.ts +5 -0
  310. package/dist/tools/code-intelligence-telemetry.d.ts.map +1 -0
  311. package/dist/tools/code-intelligence-telemetry.js +52 -0
  312. package/dist/tools/code-intelligence-telemetry.js.map +1 -0
  313. package/dist/tools/code-intelligence-tests.d.ts +2 -0
  314. package/dist/tools/code-intelligence-tests.d.ts.map +1 -0
  315. package/dist/tools/code-intelligence-tests.js +24 -0
  316. package/dist/tools/code-intelligence-tests.js.map +1 -0
  317. package/dist/tools/code-intelligence.d.ts +114 -0
  318. package/dist/tools/code-intelligence.d.ts.map +1 -0
  319. package/dist/tools/code-intelligence.js +124 -0
  320. package/dist/tools/code-intelligence.js.map +1 -0
  321. package/dist/tools/compose-permissions.d.ts +26 -0
  322. package/dist/tools/compose-permissions.d.ts.map +1 -1
  323. package/dist/tools/compose-permissions.js +257 -33
  324. package/dist/tools/compose-permissions.js.map +1 -1
  325. package/dist/tools/execute-command.d.ts +2 -0
  326. package/dist/tools/execute-command.d.ts.map +1 -1
  327. package/dist/tools/execute-command.js +114 -28
  328. package/dist/tools/execute-command.js.map +1 -1
  329. package/dist/tools/execute-prompt.d.ts +13 -1
  330. package/dist/tools/execute-prompt.d.ts.map +1 -1
  331. package/dist/tools/execute-prompt.js +310 -61
  332. package/dist/tools/execute-prompt.js.map +1 -1
  333. package/dist/tools/kb-capture.d.ts +53 -0
  334. package/dist/tools/kb-capture.d.ts.map +1 -0
  335. package/dist/tools/kb-capture.js +130 -0
  336. package/dist/tools/kb-capture.js.map +1 -0
  337. package/dist/tools/kb-context.d.ts +17 -0
  338. package/dist/tools/kb-context.d.ts.map +1 -0
  339. package/dist/tools/kb-context.js +29 -0
  340. package/dist/tools/kb-context.js.map +1 -0
  341. package/dist/tools/kb-export.d.ts +19 -0
  342. package/dist/tools/kb-export.d.ts.map +1 -0
  343. package/dist/tools/kb-export.js +344 -0
  344. package/dist/tools/kb-export.js.map +1 -0
  345. package/dist/tools/kb-feedback.d.ts +23 -0
  346. package/dist/tools/kb-feedback.d.ts.map +1 -0
  347. package/dist/tools/kb-feedback.js +43 -0
  348. package/dist/tools/kb-feedback.js.map +1 -0
  349. package/dist/tools/kb-freshness-sweep.d.ts +14 -0
  350. package/dist/tools/kb-freshness-sweep.d.ts.map +1 -0
  351. package/dist/tools/kb-freshness-sweep.js +29 -0
  352. package/dist/tools/kb-freshness-sweep.js.map +1 -0
  353. package/dist/tools/kb-harvest.d.ts +20 -0
  354. package/dist/tools/kb-harvest.d.ts.map +1 -0
  355. package/dist/tools/kb-harvest.js +143 -0
  356. package/dist/tools/kb-harvest.js.map +1 -0
  357. package/dist/tools/kb-import.d.ts +44 -0
  358. package/dist/tools/kb-import.d.ts.map +1 -0
  359. package/dist/tools/kb-import.js +239 -0
  360. package/dist/tools/kb-import.js.map +1 -0
  361. package/dist/tools/kb-invalidate.d.ts +19 -0
  362. package/dist/tools/kb-invalidate.d.ts.map +1 -0
  363. package/dist/tools/kb-invalidate.js +34 -0
  364. package/dist/tools/kb-invalidate.js.map +1 -0
  365. package/dist/tools/kb-list.d.ts +32 -0
  366. package/dist/tools/kb-list.d.ts.map +1 -0
  367. package/dist/tools/kb-list.js +43 -0
  368. package/dist/tools/kb-list.js.map +1 -0
  369. package/dist/tools/kb-promote.d.ts +20 -0
  370. package/dist/tools/kb-promote.d.ts.map +1 -0
  371. package/dist/tools/kb-promote.js +20 -0
  372. package/dist/tools/kb-promote.js.map +1 -0
  373. package/dist/tools/kb-query.d.ts +35 -0
  374. package/dist/tools/kb-query.d.ts.map +1 -0
  375. package/dist/tools/kb-query.js +111 -0
  376. package/dist/tools/kb-query.js.map +1 -0
  377. package/dist/tools/kb-reconcile-prefilter.d.ts +14 -0
  378. package/dist/tools/kb-reconcile-prefilter.d.ts.map +1 -0
  379. package/dist/tools/kb-reconcile-prefilter.js +26 -0
  380. package/dist/tools/kb-reconcile-prefilter.js.map +1 -0
  381. package/dist/tools/kb-resolve-contradiction.d.ts +23 -0
  382. package/dist/tools/kb-resolve-contradiction.d.ts.map +1 -0
  383. package/dist/tools/kb-resolve-contradiction.js +37 -0
  384. package/dist/tools/kb-resolve-contradiction.js.map +1 -0
  385. package/dist/tools/kb-session-prime.d.ts +26 -0
  386. package/dist/tools/kb-session-prime.d.ts.map +1 -0
  387. package/dist/tools/kb-session-prime.js +392 -0
  388. package/dist/tools/kb-session-prime.js.map +1 -0
  389. package/dist/tools/kb-setup.d.ts +20 -0
  390. package/dist/tools/kb-setup.d.ts.map +1 -0
  391. package/dist/tools/kb-setup.js +49 -0
  392. package/dist/tools/kb-setup.js.map +1 -0
  393. package/dist/tools/kb-stats.d.ts +20 -0
  394. package/dist/tools/kb-stats.d.ts.map +1 -0
  395. package/dist/tools/kb-stats.js +115 -0
  396. package/dist/tools/kb-stats.js.map +1 -0
  397. package/dist/tools/list-members.d.ts.map +1 -1
  398. package/dist/tools/list-members.js +6 -2
  399. package/dist/tools/list-members.js.map +1 -1
  400. package/dist/tools/member-detail.d.ts.map +1 -1
  401. package/dist/tools/member-detail.js +13 -3
  402. package/dist/tools/member-detail.js.map +1 -1
  403. package/dist/tools/member-reservation.d.ts.map +1 -1
  404. package/dist/tools/member-reservation.js +13 -1
  405. package/dist/tools/member-reservation.js.map +1 -1
  406. package/dist/tools/monitor-task.d.ts.map +1 -1
  407. package/dist/tools/monitor-task.js +38 -5
  408. package/dist/tools/monitor-task.js.map +1 -1
  409. package/dist/tools/provision-auth.d.ts.map +1 -1
  410. package/dist/tools/provision-auth.js +15 -8
  411. package/dist/tools/provision-auth.js.map +1 -1
  412. package/dist/tools/provision-vcs-auth.d.ts +5 -2
  413. package/dist/tools/provision-vcs-auth.d.ts.map +1 -1
  414. package/dist/tools/provision-vcs-auth.js +58 -52
  415. package/dist/tools/provision-vcs-auth.js.map +1 -1
  416. package/dist/tools/register-member.d.ts +21 -12
  417. package/dist/tools/register-member.d.ts.map +1 -1
  418. package/dist/tools/register-member.js +70 -3
  419. package/dist/tools/register-member.js.map +1 -1
  420. package/dist/tools/remove-member.d.ts.map +1 -1
  421. package/dist/tools/remove-member.js +19 -5
  422. package/dist/tools/remove-member.js.map +1 -1
  423. package/dist/tools/report-status.d.ts.map +1 -1
  424. package/dist/tools/report-status.js +2 -1
  425. package/dist/tools/report-status.js.map +1 -1
  426. package/dist/tools/revoke-vcs-auth.js +2 -2
  427. package/dist/tools/revoke-vcs-auth.js.map +1 -1
  428. package/dist/tools/send-email.d.ts +69 -0
  429. package/dist/tools/send-email.d.ts.map +1 -0
  430. package/dist/tools/send-email.js +177 -0
  431. package/dist/tools/send-email.js.map +1 -0
  432. package/dist/tools/setup-ssh-key.d.ts.map +1 -1
  433. package/dist/tools/setup-ssh-key.js +4 -1
  434. package/dist/tools/setup-ssh-key.js.map +1 -1
  435. package/dist/tools/stop-prompt.js +2 -2
  436. package/dist/tools/stop-prompt.js.map +1 -1
  437. package/dist/tools/update-agent-cli.js +2 -2
  438. package/dist/tools/update-agent-cli.js.map +1 -1
  439. package/dist/tools/update-member.d.ts +21 -12
  440. package/dist/tools/update-member.d.ts.map +1 -1
  441. package/dist/tools/update-member.js +43 -2
  442. package/dist/tools/update-member.js.map +1 -1
  443. package/dist/types.d.ts +12 -1
  444. package/dist/types.d.ts.map +1 -1
  445. package/dist/utils/agent-helpers.d.ts +36 -0
  446. package/dist/utils/agent-helpers.d.ts.map +1 -1
  447. package/dist/utils/agent-helpers.js +39 -1
  448. package/dist/utils/agent-helpers.js.map +1 -1
  449. package/dist/utils/platform.d.ts +7 -0
  450. package/dist/utils/platform.d.ts.map +1 -1
  451. package/dist/utils/platform.js +11 -1
  452. package/dist/utils/platform.js.map +1 -1
  453. package/dist/utils/prompt-errors.js +1 -1
  454. package/dist/utils/prompt-errors.js.map +1 -1
  455. package/dist/utils/session-caller.d.ts +28 -0
  456. package/dist/utils/session-caller.d.ts.map +1 -0
  457. package/dist/utils/session-caller.js +24 -0
  458. package/dist/utils/session-caller.js.map +1 -0
  459. package/dist/utils/work-folder-validation.d.ts +39 -0
  460. package/dist/utils/work-folder-validation.d.ts.map +1 -0
  461. package/dist/utils/work-folder-validation.js +60 -0
  462. package/dist/utils/work-folder-validation.js.map +1 -0
  463. package/dist/utils/workspace-trust.d.ts.map +1 -1
  464. package/dist/utils/workspace-trust.js +5 -1
  465. package/dist/utils/workspace-trust.js.map +1 -1
  466. package/dist/workflows/auto-sprint.js +550 -23
  467. package/package.json +7 -4
  468. package/packages/apra-fleet-client/src/client/api.mjs +210 -7
  469. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +31 -19
  470. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +16 -1
  471. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +37 -47
  472. package/packages/apra-fleet-se/apra-pm/agents/doer.md +147 -114
  473. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +41 -34
  474. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +98 -114
  475. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +205 -0
  476. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +45 -44
  477. package/packages/apra-fleet-se/apra-pm/agents/planner.md +121 -50
  478. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +84 -81
  479. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +118 -44
  480. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +63 -3
  481. package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-output.json +59 -2
  482. package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +3 -3
  483. package/packages/apra-fleet-se/apra-pm/agents/schemas/kb-reconciler-output.json +87 -0
  484. package/packages/apra-fleet-se/apra-pm/agents/schemas/planner-output.json +65 -0
  485. package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-output.json +4 -17
  486. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +105 -8
  487. package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +0 -1
  488. package/packages/apra-fleet-se/apra-pm/skills/pm/beads.md +6 -0
  489. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +0 -1
  490. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +6 -1
  491. package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +56 -0
  492. package/packages/apra-fleet-se/apra-pm/skills/pm/kb-reconcile.md +132 -0
  493. package/packages/apra-fleet-se/apra-pm/skills/pm/kb-review.md +109 -0
  494. package/packages/apra-fleet-se/bin/cli.mjs +139 -3
  495. package/packages/apra-fleet-se/bin/serve.mjs +49 -2
  496. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +182 -38
  497. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +23 -8
  498. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-manual-recovery-verified.md +258 -0
  499. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +1487 -0
  500. package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +908 -0
  501. package/packages/apra-fleet-se/fleet-sprint/docs/shared-orchestrator-reservation-design.md +399 -0
  502. package/packages/apra-fleet-se/fleet-sprint/docs/stabilization-log.md +14 -4
  503. package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +1148 -0
  504. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +229 -112
  505. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +91 -6
  506. package/packages/apra-fleet-se/fleet-sprint/runner.js +2469 -238
  507. package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +134 -0
  508. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +154 -0
  509. package/packages/apra-fleet-se/fleet-sprint/se-windows-gitbash.mjs +97 -0
  510. package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +143 -0
  511. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +15 -3
  512. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +350 -0
  513. package/packages/apra-fleet-se/fleet-sprint/sprint-progress.mjs +101 -0
  514. package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +51 -0
  515. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +657 -12
  516. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/dolt.mjs +33 -4
  517. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +60 -30
  518. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +205 -2
  519. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/shell-helpers.mjs +164 -0
  520. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +141 -26
  521. package/packages/apra-fleet-se/package.json +1 -0
  522. package/packages/apra-fleet-workflow/src/viewer/index.mjs +294 -14
  523. package/packages/apra-fleet-workflow/src/viewer/run-title.mjs +60 -0
  524. package/packages/apra-fleet-workflow/src/workflow/index.mjs +443 -35
  525. package/skills/fleet/SKILL.md +20 -9
  526. package/skills/fleet/auth-azdevops.md +44 -5
  527. package/skills/fleet/auth-bitbucket.md +3 -3
  528. package/skills/fleet/auth-github.md +2 -2
  529. package/skills/fleet/beads-conflict-resolution.md +141 -0
  530. package/skills/fleet/beads.md +16 -12
  531. package/skills/fleet/knowledge-agent.md +66 -0
  532. package/skills/fleet/onboarding.md +4 -4
  533. package/skills/fleet/permissions.md +32 -8
  534. package/skills/fleet/profiles/base-dev.json +10 -1
  535. package/skills/fleet/profiles/base-reviewer.json +8 -1
  536. package/skills/fleet/profiles/tag-kb-reconciler.json +20 -0
  537. package/skills/fleet/skill-matrix.md +1 -1
  538. package/skills/fleet/troubleshooting.md +2 -1
  539. package/version.json +1 -1
  540. package/dist/providers/gemini.d.ts +0 -42
  541. package/dist/providers/gemini.d.ts.map +0 -1
  542. package/dist/providers/gemini.js +0 -202
  543. package/dist/providers/gemini.js.map +0 -1
  544. package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +0 -151
  545. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-tier2-runbook.md +0 -127
  546. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-path-b.mjs +0 -339
  547. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-tier2.mjs +0 -360
  548. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery.mjs +0 -363
@@ -246,20 +246,48 @@ function summarizeExtractionAttempts(attempts) {
246
246
  }
247
247
 
248
248
  /**
249
- * Builds the lean repair re-ask prompt sent to the SAME member after an
250
- * invalid structured-output attempt. apra-fleet-02s.3: repair re-asks now
251
- * force `resume: true` (see the payload construction below), so the member's
252
- * session already has the original prompt/schema and its own invalid
253
- * output in context -- re-embedding all of that here would just re-spend
254
- * tokens re-sending what the resumed session already has. Only the
255
- * validation errors plus a short corrected-JSON instruction are needed.
256
- * @param {string} errorsText
249
+ * Builds the repair re-ask prompt sent to the SAME member after an invalid
250
+ * structured-output attempt.
251
+ *
252
+ * HISTORY -- this deliberately REVERSES apra-fleet-02s.3, which shrank this
253
+ * to a lean reminder (validation errors only) on the theory that the forced
254
+ * `resume: true` on repair (see the payload construction below) guarantees
255
+ * the member's session still holds the original prompt and schema.
256
+ * apra-fleet-dnri: that assumption does not always hold. Observed live on
257
+ * 2026-08-20, a reviewer dispatch that failed schema validation twice was
258
+ * re-asked with only the validator text; the resumed session did not carry
259
+ * the task inputs, so the agent had no base branch, no branch and no work
260
+ * ids, correctly refused to guess, and its refusal was read as a real
261
+ * verdict -- aborting the whole sprint. Resume is an optimization, not a
262
+ * guarantee, so the re-ask must be self-contained on its own.
263
+ *
264
+ * BOUNDED ON PURPOSE (the original token-cost decision still stands): only
265
+ * `initialPrompt` is reattached -- the caller's original prompt plus the same
266
+ * schema instruction the initial dispatch appended. The invalid response
267
+ * text, the session transcript and any per-attempt accumulated history are
268
+ * NOT re-embedded, and callers must always pass the ORIGINAL `initialPrompt`
269
+ * (never the previous round's repair prompt), so the reattached portion is
270
+ * byte-identical on every repair round and the prompt does not grow.
271
+ *
272
+ * The reattachment is framed as REFERENCE material, not as a fresh order:
273
+ * when the repair re-ask resumes the failed attempt's own session (see the
274
+ * resume disposition at the dispatch payload below) the member may have
275
+ * already done the underlying work, and a prompt that restates the task can
276
+ * read as an instruction to redo it.
277
+ *
278
+ * @param {string} errorsText - Summary of every failed extraction attempt.
279
+ * @param {string} initialPrompt - The fully-resolved original dispatch prompt
280
+ * (caller prompt + appended schema instruction), unchanged.
257
281
  */
258
- function buildRepairPrompt(errorsText) {
282
+ function buildRepairPrompt(errorsText, initialPrompt) {
259
283
  return `Your previous response could not be used.\n\n` +
260
284
  `Validation errors:\n${errorsText}\n\n` +
261
- `Please respond again with corrected JSON only, strictly conforming to the schema from your previous instructions. ` +
262
- `Do not include any commentary, explanation, or text outside the JSON.`;
285
+ `For reference, the original request and the required JSON schema were:\n` +
286
+ `--- BEGIN ORIGINAL REQUEST ---\n${initialPrompt}\n--- END ORIGINAL REQUEST ---\n\n` +
287
+ `Do NOT redo any work you have already completed for this request -- report the ` +
288
+ `result you already determined. Respond again with corrected JSON only, strictly ` +
289
+ `conforming to the schema above. Do not include any commentary, explanation, or ` +
290
+ `text outside the JSON.`;
263
291
  }
264
292
 
265
293
  /**
@@ -329,10 +357,13 @@ function buildRepairPrompt(errorsText) {
329
357
  * @property {number} [schemaRetries] - Only meaningful when `schema` is set. Bounded number
330
358
  * of repair re-asks to the SAME member after a parse/validation failure, before giving up
331
359
  * and throwing AgentOutputError. Defaults to 2 (so up to 3 total dispatches: 1 original +
332
- * 2 repairs). Each repair re-ask FORCES `resume: true` (apra-fleet-02s.3) so the member's
333
- * session already has the original prompt/schema and its own invalid output in context --
334
- * the re-ask itself is a lean reminder containing only the ajv validation/parse errors
335
- * plus a corrected-JSON instruction, not a re-embedding of the full original prompt/output.
360
+ * 2 repairs). Each repair re-ask FORCES `resume: true` (apra-fleet-02s.3) so any real work
361
+ * the member already performed for this request is preserved rather than redone -- but the
362
+ * re-ask is SELF-CONTAINED and does not depend on that resume carrying context
363
+ * (apra-fleet-dnri): it reattaches the original prompt plus the schema instruction as
364
+ * reference, alongside the ajv validation/parse errors and a corrected-JSON instruction.
365
+ * The reattached portion is identical on every repair round (the invalid output, the
366
+ * session transcript and per-attempt history are never embedded), so repairs do not grow.
336
367
  * Each attempt emits its own activity:start/activity:end pair and is cost-accounted
337
368
  * individually. (apra-fleet-unw.8)
338
369
  * @property {number} [busyWaitMs] - How long (ms) to keep waiting-and-retrying when the
@@ -386,10 +417,14 @@ export class FleetWorkflow extends EventEmitter {
386
417
  * @param {import('../fleet-client/api.mjs').ApraFleet} fleetApi
387
418
  * @param {any} args
388
419
  */
389
- constructor(fleetApi, args = {}) {
420
+ constructor(fleetApi, args = {}, logPrefix = '') {
390
421
  super();
391
422
  this.fleetApi = fleetApi;
392
423
  this.args = args;
424
+ // (apra-fleet-20i.1.1) Optional per-run scenario label prepended to
425
+ // the [Workflow Log]/[Dispatch]/[Command] console.log lines below.
426
+ // Defaults to '' so existing callers get byte-identical output.
427
+ this.logPrefix = logPrefix;
393
428
  this.currentPhase = null;
394
429
  this.budget = {
395
430
  total: null,
@@ -420,6 +455,50 @@ export class FleetWorkflow extends EventEmitter {
420
455
  // controller.signal (via _currentSignal()) when the caller doesn't
421
456
  // pass its own opts.signal. See runWithContext()/requestStop() below.
422
457
  this._activeControllers = new Map();
458
+
459
+ // (apra-fleet-p2to.1) Cooperative pause/resume gate. This is the
460
+ // GENERIC engine primitive -- a soft, deferred barrier at every
461
+ // agent()/command() entry -- NOT a journaled interrupt(). See
462
+ // requestPause()/requestResume()/setPauseGuard() and _pauseGate()
463
+ // below for the full semantics. All state is instance-level (like
464
+ // requestStop()'s _activeControllers), so a single pause quiesces
465
+ // every run sharing this FleetWorkflow instance.
466
+ //
467
+ // _pauseRequested : a pause has been asked for but has not yet
468
+ // "taken effect" (still draining in-flight work
469
+ // and/or waiting on the pause guard).
470
+ // _paused : the pause has taken effect at a clean-state
471
+ // boundary -- zero in-flight activities and the
472
+ // guard (if any) permitted it. New agent()/
473
+ // command() calls block at the gate while true.
474
+ // _pauseGuard : optional predicate (set via setPauseGuard) that
475
+ // defers a requested pause until it returns truthy
476
+ // -- i.e. lets the workflow script declare where a
477
+ // clean-state boundary actually is. Null means
478
+ // "any zero-in-flight point is a boundary".
479
+ // _inFlight : count of agent()/command() dispatches that have
480
+ // passed the gate and not yet completed. 'paused'
481
+ // is only declared when this reaches zero.
482
+ // _pauseWaiters : { resolve, reject } for every call currently
483
+ // blocked at the gate. requestResume() resolves
484
+ // them (they re-check and proceed); requestStop()
485
+ // rejects them with a CancelledError so a paused
486
+ // run tears down instead of hanging.
487
+ // _preResumeHook : optional async hook (set via setPreResumeHook)
488
+ // that requestResume() awaits as a HARD BARRIER
489
+ // before it clears pause state, releases any gate
490
+ // waiter, or emits 'resumed' -- so a caller's
491
+ // re-reserve/resync completes strictly ahead of the
492
+ // first post-resume dispatch. A hook rejection
493
+ // rejects requestResume() (the run stays paused)
494
+ // rather than being swallowed. Null means no
495
+ // barrier -- resume proceeds immediately.
496
+ this._pauseRequested = false;
497
+ this._paused = false;
498
+ this._pauseGuard = null;
499
+ this._preResumeHook = null;
500
+ this._inFlight = 0;
501
+ this._pauseWaiters = [];
423
502
  }
424
503
 
425
504
  // Returns the active per-run store (see runStorage above), or
@@ -497,13 +576,217 @@ export class FleetWorkflow extends EventEmitter {
497
576
  * @param {string} [reason]
498
577
  */
499
578
  requestStop(reason = 'Workflow run cancelled via requestStop()') {
579
+ // (apra-fleet-p2to.1) A stop supersedes any pause: reject every call
580
+ // blocked at the pause gate with a CancelledError so a paused run
581
+ // unwinds instead of hanging forever, and clear the pause state so a
582
+ // late-arriving activity doesn't re-block. The gate promise rejecting
583
+ // is what makes "requestStop() while paused tears down" work -- the
584
+ // blocked agent()/command() re-throws the CancelledError, which
585
+ // unwinds the run exactly like an aborted in-flight dispatch does.
586
+ this._pauseRequested = false;
587
+ this._paused = false;
588
+ const waiters = this._pauseWaiters;
589
+ this._pauseWaiters = [];
590
+ for (const waiter of waiters) {
591
+ waiter.reject(new CancelledError(`[Workflow Error] ${reason}`));
592
+ }
500
593
  for (const controller of this._activeControllers.values()) {
501
594
  controller.abort(new CancelledError(`[Workflow Error] ${reason}`));
502
595
  }
503
596
  }
504
597
 
598
+ /**
599
+ * (apra-fleet-p2to.1) Registers (or clears, with `null`) the pause guard:
600
+ * a predicate consulted whenever a requested-but-not-yet-engaged pause is
601
+ * about to take effect. A pause only engages -- transitions to `_paused`
602
+ * and fires 'paused' -- when in-flight work has drained to zero AND this
603
+ * guard returns truthy. That lets a workflow script defer a mid-run pause
604
+ * to a boundary IT considers clean (e.g. "between phases", "not inside a
605
+ * transaction") rather than the mere between-activities gaps the engine
606
+ * can see on its own. A null guard (the default) treats every
607
+ * zero-in-flight point as an acceptable boundary. The guard is called with
608
+ * no arguments; a throwing guard is treated as "not at a boundary yet"
609
+ * (fail-closed: keep deferring rather than pause at a point the script
610
+ * couldn't vouch for) and logged.
611
+ *
612
+ * Generic engine hook only -- it carries no fleet-sprint (or any other
613
+ * caller's) semantics; the meaning of "clean" is entirely the guard's.
614
+ *
615
+ * @param {(() => boolean) | null} fn
616
+ */
617
+ setPauseGuard(fn) {
618
+ if (fn !== null && typeof fn !== 'function') {
619
+ throw new TypeError('[Workflow Error] setPauseGuard() requires a function or null');
620
+ }
621
+ this._pauseGuard = fn;
622
+ // Setting the guard at what the script now considers a clean boundary
623
+ // may be exactly the moment a deferred pause can finally engage.
624
+ this._maybeEngagePause();
625
+ }
626
+
627
+ /**
628
+ * (apra-fleet-p2to.1.3) Registers (or clears, with null) an async
629
+ * pre-resume hook that requestResume() awaits as a HARD BARRIER before it
630
+ * clears pause state, releases any gate waiter, or emits 'resumed'. This is
631
+ * the point at which a caller re-grabs/re-syncs whatever it released at
632
+ * pause (fleet-sprint's member re-reserve/resync) with the guarantee that
633
+ * the work completes strictly BEFORE the first post-resume agent()/
634
+ * command() dispatch -- no race with the resumed sprint loop.
635
+ *
636
+ * The hook is awaited; if it rejects, requestResume() rejects too and the
637
+ * run stays paused (pause state is never cleared on the reject path), so a
638
+ * failure surfaces to the caller instead of being silently swallowed --
639
+ * consistent with reReserveOnResume()'s rethrow contract.
640
+ *
641
+ * Generic engine hook only -- it carries no caller-specific semantics.
642
+ *
643
+ * @param {((reason: string) => (void | Promise<void>)) | null} fn
644
+ */
645
+ setPreResumeHook(fn) {
646
+ if (fn !== null && typeof fn !== 'function') {
647
+ throw new TypeError('[Workflow Error] setPreResumeHook() requires a function or null');
648
+ }
649
+ this._preResumeHook = fn;
650
+ }
651
+
652
+ /**
653
+ * (apra-fleet-p2to.1) Requests a cooperative pause of every run sharing
654
+ * this instance. Fires 'pause:requested' immediately, but the pause is
655
+ * DEFERRED: it only takes effect ('paused' fires, new dispatches block) at
656
+ * a clean-state boundary -- zero in-flight activities and, if a pause
657
+ * guard is set, that guard returning truthy. Calling it while already
658
+ * paused or pause-requested is a no-op.
659
+ *
660
+ * @param {string} [reason]
661
+ */
662
+ requestPause(reason = 'Workflow run paused via requestPause()') {
663
+ if (this._paused || this._pauseRequested) return;
664
+ this._pauseRequested = true;
665
+ this.emit('pause:requested', this._pauseEventPayload({ reason }));
666
+ // If we're already quiescent (nothing in flight, guard permits), the
667
+ // pause engages right now; otherwise it engages later as in-flight
668
+ // work drains (_exitActivity) or the guard opens (setPauseGuard).
669
+ this._maybeEngagePause();
670
+ }
671
+
672
+ /**
673
+ * (apra-fleet-p2to.1) Resumes a paused (or merely pause-requested) run.
674
+ * Clears the pause state and releases every call blocked at the gate so
675
+ * they proceed. Fires 'resumed'. No-op if not paused/pause-requested.
676
+ *
677
+ * (apra-fleet-p2to.1.3) When a pre-resume hook is registered (see
678
+ * setPreResumeHook), it is awaited as a HARD BARRIER FIRST -- while the run
679
+ * is still paused, so no gate waiter is released and no new dispatch slips
680
+ * through -- and only once it resolves are the waiters released and
681
+ * 'resumed' emitted. This guarantees the caller's re-reserve/resync
682
+ * completes strictly ahead of the first post-resume dispatch. A hook
683
+ * rejection propagates out of requestResume() with the pause state left
684
+ * intact (run stays paused), rather than being swallowed.
685
+ *
686
+ * @param {string} [reason]
687
+ * @returns {Promise<void>}
688
+ */
689
+ async requestResume(reason = 'Workflow run resumed via requestResume()') {
690
+ if (!this._paused && !this._pauseRequested) return;
691
+ // Barrier: drain the pre-resume hook BEFORE touching pause state. The
692
+ // run is still paused here, so waiters remain blocked and any fresh
693
+ // agent()/command() dispatch blocks at the gate -- the hook's work
694
+ // (e.g. member re-reserve/resync) cannot race the resumed loop. A
695
+ // rejection here surfaces to the caller with pause state untouched, so
696
+ // the run stays parked instead of resuming on a half-restored state.
697
+ if (this._preResumeHook) {
698
+ await this._preResumeHook(reason);
699
+ }
700
+ this._paused = false;
701
+ this._pauseRequested = false;
702
+ const waiters = this._pauseWaiters;
703
+ this._pauseWaiters = [];
704
+ for (const waiter of waiters) {
705
+ waiter.resolve();
706
+ }
707
+ this.emit('resumed', this._pauseEventPayload({ reason }));
708
+ }
709
+
710
+ // (apra-fleet-p2to.1) Phase/group (and runId) labels for pause lifecycle
711
+ // events, read from the active run store when there is one (falling back
712
+ // to the legacy instance-level fields), so subscribers can attribute a
713
+ // pause to where the run actually was -- exactly like log()/phase() do.
714
+ _pauseEventPayload(extra = {}) {
715
+ return {
716
+ phase: this._currentPhase(),
717
+ group: this._currentGroup(),
718
+ runId: this._currentRunId(),
719
+ ...extra
720
+ };
721
+ }
722
+
723
+ // (apra-fleet-p2to.1) True when a requested pause is allowed to take
724
+ // effect right now: null guard means "any zero-in-flight point is clean";
725
+ // otherwise the script's guard decides. A throwing guard fails closed
726
+ // (keep deferring) rather than pausing at an unvouched-for point.
727
+ _guardPermitsPause() {
728
+ if (!this._pauseGuard) return true;
729
+ try {
730
+ return !!this._pauseGuard();
731
+ } catch (err) {
732
+ console.error(`[Workflow] pause guard threw (deferring pause): ${err && err.message ? err.message : err}`);
733
+ return false;
734
+ }
735
+ }
736
+
737
+ // (apra-fleet-p2to.1) Engage a requested pause iff we're at a clean-state
738
+ // boundary: pause requested, not already paused, zero in-flight activities
739
+ // and the guard permits. Idempotent and cheap -- called from every point
740
+ // that can move us toward quiescence (requestPause, _exitActivity when the
741
+ // last activity drains, setPauseGuard opening the boundary, and the gate
742
+ // itself). This is the ONLY place 'paused' is emitted, which guarantees
743
+ // 'paused' can never fire while activities are still in flight.
744
+ _maybeEngagePause() {
745
+ if (!this._pauseRequested || this._paused) return;
746
+ if (this._inFlight > 0) return;
747
+ if (!this._guardPermitsPause()) return;
748
+ this._paused = true;
749
+ this.emit('paused', this._pauseEventPayload());
750
+ }
751
+
752
+ // (apra-fleet-p2to.1) The pause gate, awaited at the very start of every
753
+ // agent()/command() call (before it becomes in-flight). If a pause is
754
+ // engaged the call blocks here until requestResume() releases it (the
755
+ // awaited promise resolves) or requestStop() tears it down (the promise
756
+ // rejects with a CancelledError, which propagates out of agent()/command()
757
+ // and unwinds the run). A requested-but-not-yet-engaged pause is given a
758
+ // chance to engage first (this arrival at a gate is itself a between-
759
+ // activities boundary), so a pause requested while the run is idle takes
760
+ // effect on the next dispatch rather than slipping one through.
761
+ async _pauseGate() {
762
+ this._maybeEngagePause();
763
+ while (this._paused) {
764
+ await new Promise((resolve, reject) => {
765
+ this._pauseWaiters.push({ resolve, reject });
766
+ });
767
+ // Released by requestResume(); re-check in case another pause was
768
+ // requested in the meantime before we fall through to dispatch.
769
+ this._maybeEngagePause();
770
+ }
771
+ }
772
+
773
+ // (apra-fleet-p2to.1) In-flight bookkeeping bracketing the actual dispatch
774
+ // in agent()/command(). A call is "in flight" from the moment it clears
775
+ // the gate until it fully settles; 'paused' is withheld until this count
776
+ // returns to zero (see _maybeEngagePause), which is what "paused only at
777
+ // zero in-flight activities" means.
778
+ _enterActivity() {
779
+ this._inFlight += 1;
780
+ }
781
+
782
+ _exitActivity() {
783
+ this._inFlight = Math.max(0, this._inFlight - 1);
784
+ // Draining the last in-flight activity may complete a deferred pause.
785
+ this._maybeEngagePause();
786
+ }
787
+
505
788
  log(msg) {
506
- console.log(`[Workflow Log] ${msg}`);
789
+ console.log(`${this.logPrefix}[Workflow Log] ${msg}`);
507
790
  this.emit('log', { phase: this._currentPhase(), msg, runId: this._currentRunId() });
508
791
  }
509
792
 
@@ -624,15 +907,29 @@ export class FleetWorkflow extends EventEmitter {
624
907
  * @param {string} prompt
625
908
  * @param {AgentOptions} [opts]
626
909
  */
910
+ // (apra-fleet-p2to.1) Public entry: passes through the cooperative pause
911
+ // gate, then brackets the real dispatch with in-flight bookkeeping so a
912
+ // pause only declares 'paused' once every such dispatch has settled. The
913
+ // try/finally guarantees the in-flight count is balanced on every exit
914
+ // path (success, throw, or a gate-rejecting requestStop()).
627
915
  async agent(prompt, opts = {}) {
628
916
  if (!opts.member_name && !opts.member_id) {
629
917
  throw new Error(`[Workflow Error] agent() requires either member_name or member_id`);
630
918
  }
919
+ await this._pauseGate();
920
+ this._enterActivity();
921
+ try {
922
+ return await this._agentDispatch(prompt, opts);
923
+ } finally {
924
+ this._exitActivity();
925
+ }
926
+ }
631
927
 
928
+ async _agentDispatch(prompt, opts = {}) {
632
929
  const effectivePhase = opts.phase || this._currentPhase();
633
930
  const runId = this._currentRunId();
634
931
  if (effectivePhase) {
635
- console.log(`[Dispatch] phase: ${effectivePhase} | member: ${opts.member_name || opts.member_id} | label: ${opts.label || 'none'}`);
932
+ console.log(`${this.logPrefix}[Dispatch] phase: ${effectivePhase} | member: ${opts.member_name || opts.member_id} | label: ${opts.label || 'none'}`);
636
933
  }
637
934
 
638
935
  let compiledSchema = null;
@@ -665,6 +962,14 @@ export class FleetWorkflow extends EventEmitter {
665
962
 
666
963
  let currentPrompt = initialPrompt;
667
964
  let lastActivityMeta = null;
965
+ // apra-fleet-dnri: the session id reported by the attempt that just
966
+ // failed, used as an EXPLICIT resume target by the repair dispatch of
967
+ // the NEXT iteration (see the resume disposition comment on the
968
+ // payload below). Declared outside the loop because the capture site
969
+ // sits after the payload is built within the same iteration. It is
970
+ // re-assigned (or cleared) on every turn, so a repair round never
971
+ // reuses an older round's id.
972
+ let failedAttemptSessionId = null;
668
973
  const budget = this._currentBudget();
669
974
 
670
975
  // (apra-fleet-unw.11, F6) Journal replay. `replayKey` is computed
@@ -781,6 +1086,47 @@ export class FleetWorkflow extends EventEmitter {
781
1086
  lastActivityMeta = activityMeta;
782
1087
  this.emit('activity:start', activityMeta);
783
1088
 
1089
+ // apra-fleet-dnri -- RESUME DISPOSITION for a schema-repair
1090
+ // re-ask, corrected after a live reproduction:
1091
+ //
1092
+ // A repair dispatch SHOULD continue the session that produced the
1093
+ // invalid output -- by repair time the member may already have
1094
+ // done real, side-effecting work for this request (files edited,
1095
+ // commits made, tracker items claimed), and a fresh session with
1096
+ // the task restated invites it to redo that work. But the naive
1097
+ // way of asking for that -- a bare boolean `true` -- does NOT
1098
+ // mean "the session that just failed". execute_prompt resolves
1099
+ // `resume: true` to `explicitResumeId ?? agent.sessionId`, i.e.
1100
+ // the member's single globally-stored LAST session, shared across
1101
+ // every role with no task scoping. Observed live: a doer's repair
1102
+ // retry landed in the immediately-prior plan-reviewer session and
1103
+ // came back with reviewer-shaped output carrying a field that is
1104
+ // not in the doer schema at all.
1105
+ //
1106
+ // So the repair dispatch names the session EXPLICITLY, by id
1107
+ // (execute_prompt's resume accepts a session-id string for
1108
+ // exactly this). When no id was reported for the failed attempt
1109
+ // (a provider without resume support, or a dispatch that returned
1110
+ // none), we degrade LOUDLY to a fresh, self-contained session and
1111
+ // pass the boolean `false` EXPLICITLY -- never `undefined`, since
1112
+ // execute_prompt's schema declares `.default(true)` on this field
1113
+ // and an omitted key would silently restore the exact
1114
+ // wrong-session bug above.
1115
+ //
1116
+ // Correctness does not depend on the resume landing: the repair
1117
+ // prompt reattaches the original prompt and schema itself (see
1118
+ // buildRepairPrompt), so the re-ask works whether or not the
1119
+ // resumed session still carries the original context.
1120
+ let repairResume = false;
1121
+ if (isRepair) {
1122
+ if (typeof failedAttemptSessionId === 'string' && failedAttemptSessionId) {
1123
+ repairResume = failedAttemptSessionId;
1124
+ } else {
1125
+ console.error(`[Agent Schema Repair] DEGRADED: no session id was reported for the attempt that just failed on member '${opts.member_name || opts.member_id}', so this repair re-ask CANNOT target that session and is being dispatched in a FRESH session (resume: false). Any side-effecting work the member already did for this request is not visible to it; the repair prompt is self-contained, so the re-ask is still answerable.`);
1126
+ repairResume = false;
1127
+ }
1128
+ }
1129
+
784
1130
  const payload = {
785
1131
  prompt: currentPrompt,
786
1132
  model: opts.model,
@@ -796,15 +1142,10 @@ export class FleetWorkflow extends EventEmitter {
796
1142
  sprint_id: opts.sprint_id,
797
1143
  // F10: default to a self-contained (non-resumed) session for
798
1144
  // the INITIAL dispatch of a workflow-authored prompt. See
799
- // AgentOptions.resume above and apra-fleet-unw.3.
800
- // apra-fleet-02s.3: a schema-repair re-ask (isRepair===true)
801
- // is a different case -- it now FORCES resume:true,
802
- // regardless of opts.resume, so the member's session already
803
- // has the original prompt/schema and its own invalid output
804
- // in context; buildRepairPrompt() was shrunk accordingly to a
805
- // lean reminder (validation errors only), since re-sending
806
- // that context fresh every repair round would waste tokens.
807
- resume: isRepair ? true : (opts.resume ?? false),
1145
+ // AgentOptions.resume above and apra-fleet-unw.3. The
1146
+ // non-repair value is unchanged; the repair value is resolved
1147
+ // above (apra-fleet-dnri).
1148
+ resume: isRepair ? repairResume : (opts.resume ?? false),
808
1149
  // apra-fleet-unw.5: opts pass-through only, no control-flow change here.
809
1150
  timeoutMs: opts.timeoutMs,
810
1151
  // apra-fleet-unw.10: defaults to the active run's cooperative
@@ -838,6 +1179,31 @@ export class FleetWorkflow extends EventEmitter {
838
1179
  }
839
1180
  }
840
1181
 
1182
+ // apra-fleet-dnri: naming the failed attempt's session id
1183
+ // explicitly (above) converts one previously self-healing
1184
+ // case into a hard failure. execute_prompt rejects an
1185
+ // unknown/expired EXPLICIT id up front with
1186
+ // {isError, reason: 'session_not_found'}, making no LLM call,
1187
+ // and its transparent retry-in-a-fresh-session recovery is
1188
+ // gated on `resume === true`, so it does not apply here. Left
1189
+ // alone, the dispatch-error branch below would turn that into
1190
+ // an AgentDispatchError and abort the whole step -- worse
1191
+ // than the boolean behaviour this replaced.
1192
+ // Scope is deliberately narrow: for REPAIR dispatches only,
1193
+ // for that ONE reason, re-dispatch exactly once with the SAME
1194
+ // repair prompt in a fresh self-contained session, inside the
1195
+ // existing maxRepairs budget. No new retry framework, no new
1196
+ // budget, no broader error taxonomy.
1197
+ if (
1198
+ isRepair
1199
+ && result && result.structuredContent && result.structuredContent.isError
1200
+ && result.structuredContent.reason === 'session_not_found'
1201
+ ) {
1202
+ console.error(`[Agent Schema Repair] the session targeted by this repair re-ask (${payload.resume}) is gone or expired on member '${opts.member_name || opts.member_id}'; re-dispatching the same repair prompt once in a fresh self-contained session (resume: false).`);
1203
+ payload.resume = false;
1204
+ result = await this.fleetApi.executePrompt(payload);
1205
+ }
1206
+
841
1207
  // execute_prompt's dispatch-level structuredContent (added
842
1208
  // alongside the display text -- see src/tools/execute-prompt.ts)
843
1209
  // reports real per-call token usage AND classifies dispatch
@@ -907,6 +1273,21 @@ export class FleetWorkflow extends EventEmitter {
907
1273
  // engine falls back to a fresh session (a capability signal, not
908
1274
  // a provider-name check). Best-effort: a throwing callback must
909
1275
  // never break the dispatch.
1276
+ // apra-fleet-dnri: record THIS attempt's session id so that,
1277
+ // if its output turns out to be schema-invalid, the repair
1278
+ // dispatch of the next iteration can resume exactly this
1279
+ // session by id rather than whatever session the member
1280
+ // happens to have stored last. Assigned unconditionally (to
1281
+ // null when the provider reported none) so a later round can
1282
+ // never silently reuse an earlier round's id -- a provider may
1283
+ // mint a new id per turn. Deliberately NOT nested inside the
1284
+ // opts.onSessionId gate below: most callers pass no callback,
1285
+ // and gating the capture on it would mean the explicit-id
1286
+ // path never runs for them.
1287
+ failedAttemptSessionId = (structured && typeof structured.sessionId === 'string' && structured.sessionId)
1288
+ ? structured.sessionId
1289
+ : null;
1290
+
910
1291
  if (
911
1292
  structured
912
1293
  && typeof structured.sessionId === 'string'
@@ -992,8 +1373,9 @@ export class FleetWorkflow extends EventEmitter {
992
1373
 
993
1374
  if (attempt < maxRepairs) {
994
1375
  // Bounded repair: re-dispatch to the SAME member with
995
- // a fresh, self-contained prompt (original prompt +
996
- // invalid output + ajv errors). This attempt is still
1376
+ // a self-contained prompt (ajv errors + the original
1377
+ // prompt/schema reattached as reference, but NOT the
1378
+ // invalid output). This attempt is still
997
1379
  // recorded as its own activity:end (success: false)
998
1380
  // so the journal/dashboard show it as a distinct step
999
1381
  // before the repair attempt that follows.
@@ -1011,7 +1393,11 @@ export class FleetWorkflow extends EventEmitter {
1011
1393
  // dashboard's structured activity data.
1012
1394
  console.error(`[Agent API Error]`, repairMsg);
1013
1395
  this.emit('activity:end', { ...activityMeta, error: repairMsg, output: text, duration, usage: result.usage, cost, success: false });
1014
- currentPrompt = buildRepairPrompt(errorsText);
1396
+ // apra-fleet-dnri: always re-derive from
1397
+ // `initialPrompt`, never from `currentPrompt` --
1398
+ // otherwise repair round 2 would nest round 1's
1399
+ // prompt and the re-ask would grow per attempt.
1400
+ currentPrompt = buildRepairPrompt(errorsText, initialPrompt);
1015
1401
  continue;
1016
1402
  }
1017
1403
 
@@ -1083,7 +1469,23 @@ export class FleetWorkflow extends EventEmitter {
1083
1469
  * @param {string} cmd
1084
1470
  * @param {CommandOptions} [opts]
1085
1471
  */
1472
+ // (apra-fleet-p2to.1) Public entry: same pause-gate + in-flight bracketing
1473
+ // as agent() above. The member-argument guard runs before the gate so a
1474
+ // malformed call fails fast rather than blocking on a pause.
1086
1475
  async command(cmd, opts = {}) {
1476
+ if (!opts.member_name && !opts.member_id) {
1477
+ throw new Error(`[Workflow Error] command() requires either member_name or member_id`);
1478
+ }
1479
+ await this._pauseGate();
1480
+ this._enterActivity();
1481
+ try {
1482
+ return await this._commandDispatch(cmd, opts);
1483
+ } finally {
1484
+ this._exitActivity();
1485
+ }
1486
+ }
1487
+
1488
+ async _commandDispatch(cmd, opts = {}) {
1087
1489
  // (apra-fleet-unw.17, A4) `opts.failSoft`: when set, a command
1088
1490
  // failure that would otherwise throw (a well-formed `isError`
1089
1491
  // result -> CommandError, a "Member not found" text sniff ->
@@ -1106,14 +1508,14 @@ export class FleetWorkflow extends EventEmitter {
1106
1508
  if (!failSoft) throw err;
1107
1509
  return { ok: false, output: '', error: err.message };
1108
1510
  };
1109
- if (!opts.member_name && !opts.member_id) {
1110
- throw new Error(`[Workflow Error] command() requires either member_name or member_id`);
1111
- }
1511
+ // (apra-fleet-p2to.2.3) The member-argument guard lives solely in the
1512
+ // public command() entrypoint above; _commandDispatch() is only ever
1513
+ // reached through it, so a second copy here was dead code. Removed.
1112
1514
 
1113
1515
  const effectivePhase = opts.phase || this._currentPhase();
1114
1516
  const runId = this._currentRunId();
1115
1517
  if (!opts.silent) {
1116
- console.log(`[Command] phase: ${effectivePhase} | member: ${opts.member_name || opts.member_id} | label: ${opts.label || 'none'}`);
1518
+ console.log(`${this.logPrefix}[Command] phase: ${effectivePhase} | member: ${opts.member_name || opts.member_id} | label: ${opts.label || 'none'}`);
1117
1519
  }
1118
1520
 
1119
1521
  let finalCmd = cmd;
@@ -1583,7 +1985,13 @@ export class FleetWorkflow extends EventEmitter {
1583
1985
  publishState: this.publishState.bind(this),
1584
1986
  workflow: this.workflow.bind(this),
1585
1987
  group: this.group.bind(this),
1586
- endGroup: this.endGroup.bind(this)
1988
+ endGroup: this.endGroup.bind(this),
1989
+ // (apra-fleet-p2to.1) Script-facing: lets the workflow declare
1990
+ // where a clean-state boundary is so a deferred pause engages
1991
+ // there. requestPause()/requestResume()/requestStop() stay
1992
+ // instance-only (driven by the viewer/orchestrator, like
1993
+ // requestStop() already is), not part of the script context.
1994
+ setPauseGuard: this.setPauseGuard.bind(this)
1587
1995
  };
1588
1996
  }
1589
1997