@apralabs/apra-fleet 0.4.0 → 0.4.1

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 (427) hide show
  1. package/README.md +145 -7
  2. package/dist/agents/backlog-groomer.md +17 -1
  3. package/dist/agents/ci-watcher.md +13 -1
  4. package/dist/agents/deployer.md +15 -3
  5. package/dist/agents/doer.md +35 -1
  6. package/dist/agents/harvester.md +22 -3
  7. package/dist/agents/integ-test-runner.md +18 -2
  8. package/dist/agents/kb-reconciler.md +216 -0
  9. package/dist/agents/plan-reviewer.md +14 -1
  10. package/dist/agents/planner.md +88 -5
  11. package/dist/agents/regression-test-runner.md +19 -1
  12. package/dist/agents/reviewer.md +104 -3
  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 +2 -2
  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/reviewer-output.json +105 -8
  19. package/dist/cli/install.d.ts +1 -0
  20. package/dist/cli/install.d.ts.map +1 -1
  21. package/dist/cli/install.js +136 -5
  22. package/dist/cli/install.js.map +1 -1
  23. package/dist/cli/join.js +1 -1
  24. package/dist/cli/join.js.map +1 -1
  25. package/dist/cli/kb-commit.d.ts +12 -0
  26. package/dist/cli/kb-commit.d.ts.map +1 -0
  27. package/dist/cli/kb-commit.js +53 -0
  28. package/dist/cli/kb-commit.js.map +1 -0
  29. package/dist/cli/kb-directives.d.ts +17 -0
  30. package/dist/cli/kb-directives.d.ts.map +1 -0
  31. package/dist/cli/kb-directives.js +146 -0
  32. package/dist/cli/kb-directives.js.map +1 -0
  33. package/dist/cli/kb-import.d.ts +13 -0
  34. package/dist/cli/kb-import.d.ts.map +1 -0
  35. package/dist/cli/kb-import.js +56 -0
  36. package/dist/cli/kb-import.js.map +1 -0
  37. package/dist/cli/uninstall.d.ts.map +1 -1
  38. package/dist/cli/uninstall.js +11 -0
  39. package/dist/cli/uninstall.js.map +1 -1
  40. package/dist/cli/watch.d.ts +53 -4
  41. package/dist/cli/watch.d.ts.map +1 -1
  42. package/dist/cli/watch.js +118 -17
  43. package/dist/cli/watch.js.map +1 -1
  44. package/dist/commands/kb-server.d.ts +8 -0
  45. package/dist/commands/kb-server.d.ts.map +1 -0
  46. package/dist/commands/kb-server.js +221 -0
  47. package/dist/commands/kb-server.js.map +1 -0
  48. package/dist/index.js +77 -2
  49. package/dist/index.js.map +1 -1
  50. package/dist/os/linux.d.ts +1 -0
  51. package/dist/os/linux.d.ts.map +1 -1
  52. package/dist/os/linux.js +18 -1
  53. package/dist/os/linux.js.map +1 -1
  54. package/dist/os/os-commands.d.ts +5 -0
  55. package/dist/os/os-commands.d.ts.map +1 -1
  56. package/dist/os/windows.d.ts +35 -0
  57. package/dist/os/windows.d.ts.map +1 -1
  58. package/dist/os/windows.js +67 -31
  59. package/dist/os/windows.js.map +1 -1
  60. package/dist/providers/agy.d.ts +12 -1
  61. package/dist/providers/agy.d.ts.map +1 -1
  62. package/dist/providers/agy.js +134 -9
  63. package/dist/providers/agy.js.map +1 -1
  64. package/dist/providers/claude.d.ts +11 -1
  65. package/dist/providers/claude.d.ts.map +1 -1
  66. package/dist/providers/claude.js +47 -19
  67. package/dist/providers/claude.js.map +1 -1
  68. package/dist/providers/codex.d.ts +11 -1
  69. package/dist/providers/codex.d.ts.map +1 -1
  70. package/dist/providers/codex.js +29 -6
  71. package/dist/providers/codex.js.map +1 -1
  72. package/dist/providers/copilot.d.ts +11 -1
  73. package/dist/providers/copilot.d.ts.map +1 -1
  74. package/dist/providers/copilot.js +26 -6
  75. package/dist/providers/copilot.js.map +1 -1
  76. package/dist/providers/email/headers.d.ts +15 -0
  77. package/dist/providers/email/headers.d.ts.map +1 -0
  78. package/dist/providers/email/headers.js +42 -0
  79. package/dist/providers/email/headers.js.map +1 -0
  80. package/dist/providers/email/index.d.ts +18 -0
  81. package/dist/providers/email/index.d.ts.map +1 -0
  82. package/dist/providers/email/index.js +60 -0
  83. package/dist/providers/email/index.js.map +1 -0
  84. package/dist/providers/email/provider.d.ts +49 -0
  85. package/dist/providers/email/provider.d.ts.map +1 -0
  86. package/dist/providers/email/provider.js +2 -0
  87. package/dist/providers/email/provider.js.map +1 -0
  88. package/dist/providers/email/sendgrid.d.ts +12 -0
  89. package/dist/providers/email/sendgrid.d.ts.map +1 -0
  90. package/dist/providers/email/sendgrid.js +67 -0
  91. package/dist/providers/email/sendgrid.js.map +1 -0
  92. package/dist/providers/email/smtp.d.ts +65 -0
  93. package/dist/providers/email/smtp.d.ts.map +1 -0
  94. package/dist/providers/email/smtp.js +373 -0
  95. package/dist/providers/email/smtp.js.map +1 -0
  96. package/dist/providers/gemini.d.ts +11 -1
  97. package/dist/providers/gemini.d.ts.map +1 -1
  98. package/dist/providers/gemini.js +38 -4
  99. package/dist/providers/gemini.js.map +1 -1
  100. package/dist/providers/none.d.ts +11 -1
  101. package/dist/providers/none.d.ts.map +1 -1
  102. package/dist/providers/none.js +21 -0
  103. package/dist/providers/none.js.map +1 -1
  104. package/dist/providers/opencode.d.ts +11 -1
  105. package/dist/providers/opencode.d.ts.map +1 -1
  106. package/dist/providers/opencode.js +55 -4
  107. package/dist/providers/opencode.js.map +1 -1
  108. package/dist/providers/provider.d.ts +77 -0
  109. package/dist/providers/provider.d.ts.map +1 -1
  110. package/dist/providers/provider.js +44 -0
  111. package/dist/providers/provider.js.map +1 -1
  112. package/dist/services/agent-provisioner.d.ts.map +1 -1
  113. package/dist/services/agent-provisioner.js +3 -6
  114. package/dist/services/agent-provisioner.js.map +1 -1
  115. package/dist/services/cloud/lifecycle.d.ts.map +1 -1
  116. package/dist/services/cloud/lifecycle.js +3 -0
  117. package/dist/services/cloud/lifecycle.js.map +1 -1
  118. package/dist/services/cloud/task-wrapper.d.ts +18 -0
  119. package/dist/services/cloud/task-wrapper.d.ts.map +1 -1
  120. package/dist/services/cloud/task-wrapper.js +157 -0
  121. package/dist/services/cloud/task-wrapper.js.map +1 -1
  122. package/dist/services/github-app.d.ts.map +1 -1
  123. package/dist/services/github-app.js +11 -2
  124. package/dist/services/github-app.js.map +1 -1
  125. package/dist/services/knowledge/audn.d.ts +37 -0
  126. package/dist/services/knowledge/audn.d.ts.map +1 -0
  127. package/dist/services/knowledge/audn.js +219 -0
  128. package/dist/services/knowledge/audn.js.map +1 -0
  129. package/dist/services/knowledge/file-hash.d.ts +11 -0
  130. package/dist/services/knowledge/file-hash.d.ts.map +1 -0
  131. package/dist/services/knowledge/file-hash.js +123 -0
  132. package/dist/services/knowledge/file-hash.js.map +1 -0
  133. package/dist/services/knowledge/http-provider.d.ts +46 -0
  134. package/dist/services/knowledge/http-provider.d.ts.map +1 -0
  135. package/dist/services/knowledge/http-provider.js +254 -0
  136. package/dist/services/knowledge/http-provider.js.map +1 -0
  137. package/dist/services/knowledge/kb-providers.d.ts +15 -0
  138. package/dist/services/knowledge/kb-providers.d.ts.map +1 -0
  139. package/dist/services/knowledge/kb-providers.js +92 -0
  140. package/dist/services/knowledge/kb-providers.js.map +1 -0
  141. package/dist/services/knowledge/kb-scope-input.d.ts +5 -0
  142. package/dist/services/knowledge/kb-scope-input.d.ts.map +1 -0
  143. package/dist/services/knowledge/kb-scope-input.js +11 -0
  144. package/dist/services/knowledge/kb-scope-input.js.map +1 -0
  145. package/dist/services/knowledge/kb-service.d.ts +3 -0
  146. package/dist/services/knowledge/kb-service.d.ts.map +1 -0
  147. package/dist/services/knowledge/kb-service.js +2 -0
  148. package/dist/services/knowledge/kb-service.js.map +1 -0
  149. package/dist/services/knowledge/path-validation.d.ts +2 -0
  150. package/dist/services/knowledge/path-validation.d.ts.map +1 -0
  151. package/dist/services/knowledge/path-validation.js +13 -0
  152. package/dist/services/knowledge/path-validation.js.map +1 -0
  153. package/dist/services/knowledge/pre-init.d.ts +14 -0
  154. package/dist/services/knowledge/pre-init.d.ts.map +1 -0
  155. package/dist/services/knowledge/pre-init.js +147 -0
  156. package/dist/services/knowledge/pre-init.js.map +1 -0
  157. package/dist/services/knowledge/project-slug.d.ts +2 -0
  158. package/dist/services/knowledge/project-slug.d.ts.map +1 -0
  159. package/dist/services/knowledge/project-slug.js +49 -0
  160. package/dist/services/knowledge/project-slug.js.map +1 -0
  161. package/dist/services/knowledge/sqlite-provider.d.ts +147 -0
  162. package/dist/services/knowledge/sqlite-provider.d.ts.map +1 -0
  163. package/dist/services/knowledge/sqlite-provider.js +1646 -0
  164. package/dist/services/knowledge/sqlite-provider.js.map +1 -0
  165. package/dist/services/knowledge/types.d.ts +163 -0
  166. package/dist/services/knowledge/types.d.ts.map +1 -0
  167. package/dist/services/knowledge/types.js +9 -0
  168. package/dist/services/knowledge/types.js.map +1 -0
  169. package/dist/services/member-home.d.ts +89 -0
  170. package/dist/services/member-home.d.ts.map +1 -0
  171. package/dist/services/member-home.js +256 -0
  172. package/dist/services/member-home.js.map +1 -0
  173. package/dist/services/member-remote-url.d.ts +34 -0
  174. package/dist/services/member-remote-url.d.ts.map +1 -0
  175. package/dist/services/member-remote-url.js +39 -0
  176. package/dist/services/member-remote-url.js.map +1 -0
  177. package/dist/services/orphan-recovery.d.ts +5 -2
  178. package/dist/services/orphan-recovery.d.ts.map +1 -1
  179. package/dist/services/orphan-recovery.js +19 -8
  180. package/dist/services/orphan-recovery.js.map +1 -1
  181. package/dist/services/preflight-check.d.ts +56 -0
  182. package/dist/services/preflight-check.d.ts.map +1 -0
  183. package/dist/services/preflight-check.js +277 -0
  184. package/dist/services/preflight-check.js.map +1 -0
  185. package/dist/services/stall/log-path-resolver.d.ts +11 -8
  186. package/dist/services/stall/log-path-resolver.d.ts.map +1 -1
  187. package/dist/services/stall/log-path-resolver.js +17 -40
  188. package/dist/services/stall/log-path-resolver.js.map +1 -1
  189. package/dist/services/stall/stall-detector.d.ts +32 -0
  190. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  191. package/dist/services/stall/stall-detector.js +149 -6
  192. package/dist/services/stall/stall-detector.js.map +1 -1
  193. package/dist/services/stall/stall-poller.d.ts +34 -0
  194. package/dist/services/stall/stall-poller.d.ts.map +1 -1
  195. package/dist/services/stall/stall-poller.js +134 -2
  196. package/dist/services/stall/stall-poller.js.map +1 -1
  197. package/dist/services/strategy.d.ts.map +1 -1
  198. package/dist/services/strategy.js +2 -2
  199. package/dist/services/strategy.js.map +1 -1
  200. package/dist/services/tool-registry.d.ts.map +1 -1
  201. package/dist/services/tool-registry.js +87 -1
  202. package/dist/services/tool-registry.js.map +1 -1
  203. package/dist/services/vcs/github.d.ts.map +1 -1
  204. package/dist/services/vcs/github.js +32 -1
  205. package/dist/services/vcs/github.js.map +1 -1
  206. package/dist/services/version-check.d.ts +22 -0
  207. package/dist/services/version-check.d.ts.map +1 -0
  208. package/dist/services/version-check.js +103 -0
  209. package/dist/services/version-check.js.map +1 -0
  210. package/dist/skills/fleet-sprint-cli/SKILL.md +13 -2
  211. package/dist/skills/pm/beads.md +6 -0
  212. package/dist/skills/pm/fleet-addendum.md +6 -0
  213. package/dist/skills/pm/index.md +56 -0
  214. package/dist/skills/pm/kb-reconcile.md +132 -0
  215. package/dist/skills/pm/kb-review.md +109 -0
  216. package/dist/tools/check-status.d.ts +47 -0
  217. package/dist/tools/check-status.d.ts.map +1 -1
  218. package/dist/tools/check-status.js +242 -0
  219. package/dist/tools/check-status.js.map +1 -1
  220. package/dist/tools/child-id-allocator.d.ts +2 -2
  221. package/dist/tools/code-intelligence-codebase-memory.d.ts +11 -0
  222. package/dist/tools/code-intelligence-codebase-memory.d.ts.map +1 -0
  223. package/dist/tools/code-intelligence-codebase-memory.js +270 -0
  224. package/dist/tools/code-intelligence-codebase-memory.js.map +1 -0
  225. package/dist/tools/code-intelligence-freshness.d.ts +2 -0
  226. package/dist/tools/code-intelligence-freshness.d.ts.map +1 -0
  227. package/dist/tools/code-intelligence-freshness.js +26 -0
  228. package/dist/tools/code-intelligence-freshness.js.map +1 -0
  229. package/dist/tools/code-intelligence-gitnexus.d.ts +14 -0
  230. package/dist/tools/code-intelligence-gitnexus.d.ts.map +1 -0
  231. package/dist/tools/code-intelligence-gitnexus.js +475 -0
  232. package/dist/tools/code-intelligence-gitnexus.js.map +1 -0
  233. package/dist/tools/code-intelligence-kb-enrich.d.ts +2 -0
  234. package/dist/tools/code-intelligence-kb-enrich.d.ts.map +1 -0
  235. package/dist/tools/code-intelligence-kb-enrich.js +65 -0
  236. package/dist/tools/code-intelligence-kb-enrich.js.map +1 -0
  237. package/dist/tools/code-intelligence-reindex.d.ts +7 -0
  238. package/dist/tools/code-intelligence-reindex.d.ts.map +1 -0
  239. package/dist/tools/code-intelligence-reindex.js +106 -0
  240. package/dist/tools/code-intelligence-reindex.js.map +1 -0
  241. package/dist/tools/code-intelligence-telemetry.d.ts +5 -0
  242. package/dist/tools/code-intelligence-telemetry.d.ts.map +1 -0
  243. package/dist/tools/code-intelligence-telemetry.js +52 -0
  244. package/dist/tools/code-intelligence-telemetry.js.map +1 -0
  245. package/dist/tools/code-intelligence-tests.d.ts +2 -0
  246. package/dist/tools/code-intelligence-tests.d.ts.map +1 -0
  247. package/dist/tools/code-intelligence-tests.js +24 -0
  248. package/dist/tools/code-intelligence-tests.js.map +1 -0
  249. package/dist/tools/code-intelligence.d.ts +114 -0
  250. package/dist/tools/code-intelligence.d.ts.map +1 -0
  251. package/dist/tools/code-intelligence.js +124 -0
  252. package/dist/tools/code-intelligence.js.map +1 -0
  253. package/dist/tools/compose-permissions.d.ts +26 -0
  254. package/dist/tools/compose-permissions.d.ts.map +1 -1
  255. package/dist/tools/compose-permissions.js +244 -33
  256. package/dist/tools/compose-permissions.js.map +1 -1
  257. package/dist/tools/execute-command.d.ts +2 -0
  258. package/dist/tools/execute-command.d.ts.map +1 -1
  259. package/dist/tools/execute-command.js +86 -16
  260. package/dist/tools/execute-command.js.map +1 -1
  261. package/dist/tools/execute-prompt.d.ts +13 -1
  262. package/dist/tools/execute-prompt.d.ts.map +1 -1
  263. package/dist/tools/execute-prompt.js +257 -45
  264. package/dist/tools/execute-prompt.js.map +1 -1
  265. package/dist/tools/kb-capture.d.ts +53 -0
  266. package/dist/tools/kb-capture.d.ts.map +1 -0
  267. package/dist/tools/kb-capture.js +130 -0
  268. package/dist/tools/kb-capture.js.map +1 -0
  269. package/dist/tools/kb-context.d.ts +17 -0
  270. package/dist/tools/kb-context.d.ts.map +1 -0
  271. package/dist/tools/kb-context.js +29 -0
  272. package/dist/tools/kb-context.js.map +1 -0
  273. package/dist/tools/kb-export.d.ts +19 -0
  274. package/dist/tools/kb-export.d.ts.map +1 -0
  275. package/dist/tools/kb-export.js +344 -0
  276. package/dist/tools/kb-export.js.map +1 -0
  277. package/dist/tools/kb-feedback.d.ts +23 -0
  278. package/dist/tools/kb-feedback.d.ts.map +1 -0
  279. package/dist/tools/kb-feedback.js +43 -0
  280. package/dist/tools/kb-feedback.js.map +1 -0
  281. package/dist/tools/kb-freshness-sweep.d.ts +14 -0
  282. package/dist/tools/kb-freshness-sweep.d.ts.map +1 -0
  283. package/dist/tools/kb-freshness-sweep.js +29 -0
  284. package/dist/tools/kb-freshness-sweep.js.map +1 -0
  285. package/dist/tools/kb-harvest.d.ts +20 -0
  286. package/dist/tools/kb-harvest.d.ts.map +1 -0
  287. package/dist/tools/kb-harvest.js +143 -0
  288. package/dist/tools/kb-harvest.js.map +1 -0
  289. package/dist/tools/kb-import.d.ts +44 -0
  290. package/dist/tools/kb-import.d.ts.map +1 -0
  291. package/dist/tools/kb-import.js +239 -0
  292. package/dist/tools/kb-import.js.map +1 -0
  293. package/dist/tools/kb-invalidate.d.ts +19 -0
  294. package/dist/tools/kb-invalidate.d.ts.map +1 -0
  295. package/dist/tools/kb-invalidate.js +34 -0
  296. package/dist/tools/kb-invalidate.js.map +1 -0
  297. package/dist/tools/kb-list.d.ts +32 -0
  298. package/dist/tools/kb-list.d.ts.map +1 -0
  299. package/dist/tools/kb-list.js +43 -0
  300. package/dist/tools/kb-list.js.map +1 -0
  301. package/dist/tools/kb-promote.d.ts +20 -0
  302. package/dist/tools/kb-promote.d.ts.map +1 -0
  303. package/dist/tools/kb-promote.js +20 -0
  304. package/dist/tools/kb-promote.js.map +1 -0
  305. package/dist/tools/kb-query.d.ts +35 -0
  306. package/dist/tools/kb-query.d.ts.map +1 -0
  307. package/dist/tools/kb-query.js +111 -0
  308. package/dist/tools/kb-query.js.map +1 -0
  309. package/dist/tools/kb-reconcile-prefilter.d.ts +14 -0
  310. package/dist/tools/kb-reconcile-prefilter.d.ts.map +1 -0
  311. package/dist/tools/kb-reconcile-prefilter.js +26 -0
  312. package/dist/tools/kb-reconcile-prefilter.js.map +1 -0
  313. package/dist/tools/kb-resolve-contradiction.d.ts +23 -0
  314. package/dist/tools/kb-resolve-contradiction.d.ts.map +1 -0
  315. package/dist/tools/kb-resolve-contradiction.js +37 -0
  316. package/dist/tools/kb-resolve-contradiction.js.map +1 -0
  317. package/dist/tools/kb-session-prime.d.ts +26 -0
  318. package/dist/tools/kb-session-prime.d.ts.map +1 -0
  319. package/dist/tools/kb-session-prime.js +392 -0
  320. package/dist/tools/kb-session-prime.js.map +1 -0
  321. package/dist/tools/kb-setup.d.ts +20 -0
  322. package/dist/tools/kb-setup.d.ts.map +1 -0
  323. package/dist/tools/kb-setup.js +49 -0
  324. package/dist/tools/kb-setup.js.map +1 -0
  325. package/dist/tools/kb-stats.d.ts +20 -0
  326. package/dist/tools/kb-stats.d.ts.map +1 -0
  327. package/dist/tools/kb-stats.js +115 -0
  328. package/dist/tools/kb-stats.js.map +1 -0
  329. package/dist/tools/member-detail.d.ts.map +1 -1
  330. package/dist/tools/member-detail.js +8 -0
  331. package/dist/tools/member-detail.js.map +1 -1
  332. package/dist/tools/monitor-task.d.ts.map +1 -1
  333. package/dist/tools/monitor-task.js +21 -3
  334. package/dist/tools/monitor-task.js.map +1 -1
  335. package/dist/tools/provision-auth.d.ts.map +1 -1
  336. package/dist/tools/provision-auth.js +10 -3
  337. package/dist/tools/provision-auth.js.map +1 -1
  338. package/dist/tools/register-member.d.ts +3 -0
  339. package/dist/tools/register-member.d.ts.map +1 -1
  340. package/dist/tools/register-member.js +30 -1
  341. package/dist/tools/register-member.js.map +1 -1
  342. package/dist/tools/remove-member.d.ts.map +1 -1
  343. package/dist/tools/remove-member.js +17 -3
  344. package/dist/tools/remove-member.js.map +1 -1
  345. package/dist/tools/report-status.d.ts.map +1 -1
  346. package/dist/tools/report-status.js +2 -1
  347. package/dist/tools/report-status.js.map +1 -1
  348. package/dist/tools/send-email.d.ts +69 -0
  349. package/dist/tools/send-email.d.ts.map +1 -0
  350. package/dist/tools/send-email.js +177 -0
  351. package/dist/tools/send-email.js.map +1 -0
  352. package/dist/tools/setup-ssh-key.d.ts.map +1 -1
  353. package/dist/tools/setup-ssh-key.js +2 -0
  354. package/dist/tools/setup-ssh-key.js.map +1 -1
  355. package/dist/tools/update-member.d.ts +3 -0
  356. package/dist/tools/update-member.d.ts.map +1 -1
  357. package/dist/tools/update-member.js +25 -1
  358. package/dist/tools/update-member.js.map +1 -1
  359. package/dist/types.d.ts +1 -0
  360. package/dist/types.d.ts.map +1 -1
  361. package/dist/utils/prompt-errors.js +1 -1
  362. package/dist/utils/prompt-errors.js.map +1 -1
  363. package/dist/utils/session-caller.d.ts +28 -0
  364. package/dist/utils/session-caller.d.ts.map +1 -0
  365. package/dist/utils/session-caller.js +24 -0
  366. package/dist/utils/session-caller.js.map +1 -0
  367. package/dist/utils/work-folder-validation.d.ts +39 -0
  368. package/dist/utils/work-folder-validation.d.ts.map +1 -0
  369. package/dist/utils/work-folder-validation.js +60 -0
  370. package/dist/utils/work-folder-validation.js.map +1 -0
  371. package/dist/workflows/auto-sprint.js +546 -6
  372. package/package.json +7 -4
  373. package/packages/apra-fleet-client/src/client/api.mjs +118 -4
  374. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +17 -1
  375. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +13 -1
  376. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +15 -3
  377. package/packages/apra-fleet-se/apra-pm/agents/doer.md +35 -1
  378. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +22 -3
  379. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +18 -2
  380. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +216 -0
  381. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +14 -1
  382. package/packages/apra-fleet-se/apra-pm/agents/planner.md +88 -5
  383. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +19 -1
  384. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +104 -3
  385. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +63 -3
  386. package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-output.json +59 -2
  387. package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +2 -2
  388. package/packages/apra-fleet-se/apra-pm/agents/schemas/kb-reconciler-output.json +87 -0
  389. package/packages/apra-fleet-se/apra-pm/agents/schemas/planner-output.json +65 -0
  390. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +105 -8
  391. package/packages/apra-fleet-se/apra-pm/skills/pm/beads.md +6 -0
  392. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +6 -0
  393. package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +56 -0
  394. package/packages/apra-fleet-se/apra-pm/skills/pm/kb-reconcile.md +132 -0
  395. package/packages/apra-fleet-se/apra-pm/skills/pm/kb-review.md +109 -0
  396. package/packages/apra-fleet-se/bin/cli.mjs +7 -0
  397. package/packages/apra-fleet-se/bin/serve.mjs +14 -2
  398. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +31 -5
  399. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +1 -1
  400. package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +23 -151
  401. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-manual-recovery-verified.md +256 -0
  402. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +1482 -0
  403. package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +908 -0
  404. package/packages/apra-fleet-se/fleet-sprint/docs/shared-orchestrator-reservation-design.md +399 -0
  405. package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +972 -0
  406. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +167 -101
  407. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +50 -6
  408. package/packages/apra-fleet-se/fleet-sprint/runner.js +1416 -116
  409. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +13 -2
  410. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +350 -0
  411. package/packages/apra-fleet-se/fleet-sprint/sprint-progress.mjs +101 -0
  412. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +30 -17
  413. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +62 -2
  414. package/packages/apra-fleet-se/package.json +1 -0
  415. package/packages/apra-fleet-workflow/src/viewer/index.mjs +127 -13
  416. package/packages/apra-fleet-workflow/src/viewer/run-title.mjs +60 -0
  417. package/packages/apra-fleet-workflow/src/workflow/index.mjs +8 -4
  418. package/skills/fleet/knowledge-agent.md +66 -0
  419. package/skills/fleet/permissions.md +28 -4
  420. package/skills/fleet/profiles/base-dev.json +10 -1
  421. package/skills/fleet/profiles/base-reviewer.json +8 -1
  422. package/skills/fleet/profiles/tag-kb-reconciler.json +20 -0
  423. package/version.json +1 -1
  424. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-tier2-runbook.md +0 -127
  425. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-path-b.mjs +0 -339
  426. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-tier2.mjs +0 -360
  427. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery.mjs +0 -363
@@ -1339,7 +1339,8 @@ const REVIEW_SCHEMA = {
1339
1339
  ],
1340
1340
  "properties": {
1341
1341
  "title": {
1342
- "type": "string"
1342
+ "type": "string",
1343
+ "description": "Plain text only: letters, digits, space, and . , : ; ! ? ( ) ' _ / [ ] - -- nothing else. No backticks, double quotes, $, or backslash (the title is interpolated into a shell command downstream). Do NOT wrap a command/flag/filename in backticks here -- write it plain (e.g. \"Surface the Windows service registration mode in apra-fleet status\") or move the formatted detail into description instead, which has no such restriction. NOT enforced as a hard schema constraint here (deliberately no \"pattern\"): a single out-of-allowlist newTask title must never make ajv reject/retry the WHOLE structured verdict (verdict, notes, reopenIds, and the other newTasks) -- see validateNewTask() in fleet-sprint/runner.js, the actual (per-item, non-fatal) enforcement point, applied after parsing."
1343
1344
  },
1344
1345
  "description": {
1345
1346
  "type": "string"
@@ -1349,6 +1350,80 @@ const REVIEW_SCHEMA = {
1349
1350
  }
1350
1351
  }
1351
1352
  }
1353
+ },
1354
+ "kb_promotions": {
1355
+ "type": "array",
1356
+ "description": "Entries this reviewer VERIFIED against the tree and is promoting to CONFIRMED. Reviewer-only: promotion is the sole path that mints CONFIRMED, and widening capture does not widen promotion. The engine makes the kb_promote calls.",
1357
+ "items": {
1358
+ "type": "object",
1359
+ "required": [
1360
+ "id",
1361
+ "reason"
1362
+ ],
1363
+ "properties": {
1364
+ "id": {
1365
+ "type": "string",
1366
+ "description": "The entry id, copied verbatim from the 'KNOWLEDGE BANK -- promotion candidates' block in your dispatch prompt. That block is the ONLY source of promotable ids -- do not call a kb_* tool to find one, and never invent one.",
1367
+ "minLength": 1
1368
+ },
1369
+ "reason": {
1370
+ "type": "string",
1371
+ "description": "The evidence for this promotion -- what you actually checked. kb_promote refuses a trivial reason.",
1372
+ "minLength": 20
1373
+ }
1374
+ }
1375
+ }
1376
+ },
1377
+ "kb_captures": {
1378
+ "type": "array",
1379
+ "description": "Durable knowledge this role verified during its run. The engine makes the kb_capture calls; the role only decides. Optional -- omit or send [] to capture nothing.",
1380
+ "items": {
1381
+ "type": "object",
1382
+ "required": [
1383
+ "type",
1384
+ "title",
1385
+ "summary",
1386
+ "content",
1387
+ "source_files"
1388
+ ],
1389
+ "properties": {
1390
+ "type": {
1391
+ "type": "string",
1392
+ "enum": [
1393
+ "knowledge",
1394
+ "learning",
1395
+ "runbook"
1396
+ ]
1397
+ },
1398
+ "title": {
1399
+ "type": "string",
1400
+ "minLength": 8
1401
+ },
1402
+ "summary": {
1403
+ "type": "string",
1404
+ "minLength": 20
1405
+ },
1406
+ "content": {
1407
+ "type": "string",
1408
+ "description": "Full detail of the entry. REQUIRED -- kbCaptureSchema declares content as z.string().min(1), so a capture without it is rejected at the MCP boundary and persists nothing (apra-fleet-23c).",
1409
+ "minLength": 40
1410
+ },
1411
+ "source_files": {
1412
+ "type": "array",
1413
+ "description": "Files that make this claim checkable. At least one is REQUIRED -- SqliteProvider.capture() rejects an entry with no basis, because the freshness sweep can never stale it.",
1414
+ "items": {
1415
+ "type": "string"
1416
+ },
1417
+ "minItems": 1
1418
+ },
1419
+ "symbols": {
1420
+ "type": "array",
1421
+ "items": {
1422
+ "type": "string"
1423
+ }
1424
+ }
1425
+ }
1426
+ }
1352
1427
  }
1353
1428
  }
1354
1429
  };
@@ -1430,6 +1505,57 @@ const DOER_STATUS_SCHEMA = {
1430
1505
  },
1431
1506
  "notes": {
1432
1507
  "type": "string"
1508
+ },
1509
+ "kb_captures": {
1510
+ "type": "array",
1511
+ "description": "Durable knowledge this role verified during its run. The engine makes the kb_capture calls; the role only decides. Optional -- omit or send [] to capture nothing.",
1512
+ "items": {
1513
+ "type": "object",
1514
+ "required": [
1515
+ "type",
1516
+ "title",
1517
+ "summary",
1518
+ "content",
1519
+ "source_files"
1520
+ ],
1521
+ "properties": {
1522
+ "type": {
1523
+ "type": "string",
1524
+ "enum": [
1525
+ "knowledge",
1526
+ "learning",
1527
+ "runbook"
1528
+ ]
1529
+ },
1530
+ "title": {
1531
+ "type": "string",
1532
+ "minLength": 8
1533
+ },
1534
+ "summary": {
1535
+ "type": "string",
1536
+ "minLength": 20
1537
+ },
1538
+ "content": {
1539
+ "type": "string",
1540
+ "description": "Full detail of the entry. REQUIRED -- kbCaptureSchema declares content as z.string().min(1), so a capture without it is rejected at the MCP boundary and persists nothing (apra-fleet-23c).",
1541
+ "minLength": 40
1542
+ },
1543
+ "source_files": {
1544
+ "type": "array",
1545
+ "description": "Files that make this claim checkable. At least one is REQUIRED -- SqliteProvider.capture() rejects an entry with no basis, because the freshness sweep can never stale it.",
1546
+ "items": {
1547
+ "type": "string"
1548
+ },
1549
+ "minItems": 1
1550
+ },
1551
+ "symbols": {
1552
+ "type": "array",
1553
+ "items": {
1554
+ "type": "string"
1555
+ }
1556
+ }
1557
+ }
1558
+ }
1433
1559
  }
1434
1560
  }
1435
1561
  };
@@ -1493,7 +1619,7 @@ const INTEG_RUN_SCHEMA = {
1493
1619
  "items": {
1494
1620
  "type": "string"
1495
1621
  },
1496
- "description": "apra-fleet-jfo: verify-set bead ids (any issue_type, Step 1b) closed this run. Optional for backward compatibility -- absent/omitted on a dispatch that named no verify-set ids."
1622
+ "description": "Verify-set bead ids (any issue_type, Step 1b) closed this run. Optional for backward compatibility -- absent/omitted on a dispatch that named no verify-set ids."
1497
1623
  },
1498
1624
  "verifySetLeftOpen": {
1499
1625
  "type": "array",
@@ -1512,7 +1638,7 @@ const INTEG_RUN_SCHEMA = {
1512
1638
  }
1513
1639
  }
1514
1640
  },
1515
- "description": "apra-fleet-jfo: verify-set bead ids (Step 1b) left open this run, with why (gap bug filed, or inconclusive). Optional for backward compatibility."
1641
+ "description": "Verify-set bead ids (Step 1b) left open this run, with why (gap bug filed, or inconclusive). Optional for backward compatibility."
1516
1642
  },
1517
1643
  "observedFailures": {
1518
1644
  "type": "array",
@@ -1641,6 +1767,145 @@ const HARVEST_SCHEMA = {
1641
1767
  },
1642
1768
  "notes": {
1643
1769
  "type": "string"
1770
+ },
1771
+ "kb_captures": {
1772
+ "type": "array",
1773
+ "description": "Durable knowledge this role verified during its run. The engine makes the kb_capture calls; the role only decides. Optional -- omit or send [] to capture nothing.",
1774
+ "items": {
1775
+ "type": "object",
1776
+ "required": [
1777
+ "type",
1778
+ "title",
1779
+ "summary",
1780
+ "content",
1781
+ "source_files"
1782
+ ],
1783
+ "properties": {
1784
+ "type": {
1785
+ "type": "string",
1786
+ "enum": [
1787
+ "knowledge",
1788
+ "learning",
1789
+ "runbook"
1790
+ ]
1791
+ },
1792
+ "title": {
1793
+ "type": "string",
1794
+ "minLength": 8
1795
+ },
1796
+ "summary": {
1797
+ "type": "string",
1798
+ "minLength": 20
1799
+ },
1800
+ "content": {
1801
+ "type": "string",
1802
+ "description": "Full detail of the entry. REQUIRED -- kbCaptureSchema declares content as z.string().min(1), so a capture without it is rejected at the MCP boundary and persists nothing (apra-fleet-23c).",
1803
+ "minLength": 40
1804
+ },
1805
+ "source_files": {
1806
+ "type": "array",
1807
+ "description": "Files that make this claim checkable. At least one is REQUIRED -- SqliteProvider.capture() rejects an entry with no basis, because the freshness sweep can never stale it.",
1808
+ "items": {
1809
+ "type": "string"
1810
+ },
1811
+ "minItems": 1
1812
+ },
1813
+ "symbols": {
1814
+ "type": "array",
1815
+ "items": {
1816
+ "type": "string"
1817
+ }
1818
+ }
1819
+ }
1820
+ }
1821
+ }
1822
+ }
1823
+ };
1824
+ const PLANNER_SCHEMA = {
1825
+ "$schema": "http://json-schema.org/draft-07/schema#",
1826
+ "$id": "apra-pm/planner-output@1",
1827
+ "title": "planner output",
1828
+ "description": "Canonical machine-readable output contract for the planner role. See agents/planner.md Step 4 (Validate your own DAG) and Step 0 (Knowledge Bank) for the prose contract this mirrors. The planner previously had no schema at all -- its dispatch ended 'Confirm with any text when done' -- so this is the contract that makes its output routable rather than free prose.",
1829
+ "type": "object",
1830
+ "required": [
1831
+ "status",
1832
+ "notes"
1833
+ ],
1834
+ "properties": {
1835
+ "status": {
1836
+ "type": "string",
1837
+ "enum": [
1838
+ "OK",
1839
+ "BLOCKED"
1840
+ ]
1841
+ },
1842
+ "notes": {
1843
+ "type": "string"
1844
+ },
1845
+ "featureIds": {
1846
+ "type": "array",
1847
+ "description": "Feature-level bead ids created or updated this round.",
1848
+ "items": {
1849
+ "type": "string"
1850
+ }
1851
+ },
1852
+ "taskIds": {
1853
+ "type": "array",
1854
+ "description": "Task-level bead ids created or updated this round.",
1855
+ "items": {
1856
+ "type": "string"
1857
+ }
1858
+ },
1859
+ "kb_captures": {
1860
+ "type": "array",
1861
+ "description": "Durable knowledge this role verified during its run. The engine makes the kb_capture calls; the role only decides. Optional -- omit or send [] to capture nothing.",
1862
+ "items": {
1863
+ "type": "object",
1864
+ "required": [
1865
+ "type",
1866
+ "title",
1867
+ "summary",
1868
+ "content",
1869
+ "source_files"
1870
+ ],
1871
+ "properties": {
1872
+ "type": {
1873
+ "type": "string",
1874
+ "enum": [
1875
+ "knowledge",
1876
+ "learning",
1877
+ "runbook"
1878
+ ]
1879
+ },
1880
+ "title": {
1881
+ "type": "string",
1882
+ "minLength": 8
1883
+ },
1884
+ "summary": {
1885
+ "type": "string",
1886
+ "minLength": 20
1887
+ },
1888
+ "content": {
1889
+ "type": "string",
1890
+ "description": "Full detail of the entry. REQUIRED -- kbCaptureSchema declares content as z.string().min(1), so a capture without it is rejected at the MCP boundary and persists nothing (apra-fleet-23c).",
1891
+ "minLength": 40
1892
+ },
1893
+ "source_files": {
1894
+ "type": "array",
1895
+ "description": "Files that make this claim checkable. At least one is REQUIRED -- SqliteProvider.capture() rejects an entry with no basis, because the freshness sweep can never stale it.",
1896
+ "items": {
1897
+ "type": "string"
1898
+ },
1899
+ "minItems": 1
1900
+ },
1901
+ "symbols": {
1902
+ "type": "array",
1903
+ "items": {
1904
+ "type": "string"
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1644
1909
  }
1645
1910
  }
1646
1911
  };
@@ -1739,6 +2004,244 @@ async function parallel(tasks) {
1739
2004
  return Promise.all(tasks);
1740
2005
  }
1741
2006
 
2007
+ // -------------------------------------------------------- KB priming
2008
+ //
2009
+ // Dispatches a cheap agent to call kb_session_prime (and kb_import on first
2010
+ // call) and returns the top entries. The workflow injects these entries
2011
+ // directly into agent prompts -- agents never need to call KB tools themselves.
2012
+
2013
+ const KB_PRIMER_SCHEMA = {
2014
+ type: 'object',
2015
+ required: ['entries', 'sessionWarm', 'imported'],
2016
+ properties: {
2017
+ sessionWarm: { type: 'boolean' },
2018
+ imported: { type: 'boolean' },
2019
+ entries: {
2020
+ type: 'array',
2021
+ items: {
2022
+ type: 'object',
2023
+ required: ['title', 'summary'],
2024
+ properties: {
2025
+ title: { type: 'string' },
2026
+ summary: { type: 'string' },
2027
+ confidence: { type: 'string' },
2028
+ symbols: { type: 'array', items: { type: 'string' } },
2029
+ source_files: { type: 'array', items: { type: 'string' } },
2030
+ type: { type: 'string' },
2031
+ },
2032
+ },
2033
+ },
2034
+ },
2035
+ };
2036
+
2037
+ let _kbImported = false;
2038
+
2039
+ async function primeKB(repoPath) {
2040
+ const importStep = _kbImported ? '' :
2041
+ `Step 2: Import the bible into the KB database.\n` +
2042
+ ` a. First check if "${repoPath}/.fleet/kb-canonical.json" exists (use Bash: test -f).\n` +
2043
+ ` b. If it does NOT exist, run: echo $APRA_FLEET_DATA_DIR (using Bash) to get the data dir.\n` +
2044
+ ` Then check if "$APRA_FLEET_DATA_DIR/kb-canonical.json" exists.\n` +
2045
+ ` c. Call mcp__apra-fleet__kb_import with repo set to "${repoPath}".\n` +
2046
+ ` If the bible was found at the data dir path (step b), also pass\n` +
2047
+ ` path set to that full path (e.g. "/tmp/sprint-test/data-b/kb-canonical.json").\n` +
2048
+ ` d. If neither path has the bible, or the tool is unavailable, set imported=false and continue.\n`;
2049
+ const stepNum = _kbImported ? 2 : 3;
2050
+ try {
2051
+ const result = await dispatch(
2052
+ `You are a knowledge-base primer. Your ONLY job is to load KB tools, ` +
2053
+ `optionally import the bible, call kb_session_prime, and return the results.\n\n` +
2054
+ `Step 1: Call ToolSearch with query "select:mcp__apra-fleet__kb_session_prime` +
2055
+ (_kbImported ? `"` : `,mcp__apra-fleet__kb_import"`) +
2056
+ ` to load the tool schema(s).\n` +
2057
+ importStep +
2058
+ `Step ${stepNum}: Call mcp__apra-fleet__kb_session_prime with:\n` +
2059
+ ` repo_path: "${repoPath}"\n` +
2060
+ `Step ${stepNum + 1}: Parse the JSON string result. Extract the top_entries array.\n` +
2061
+ ` For each entry return: title, summary, confidence, symbols, source_files, type.\n` +
2062
+ ` Do NOT return the content field.\n` +
2063
+ ` Set sessionWarm from the result. Set imported to true if you ran kb_import successfully.\n\n` +
2064
+ `If ToolSearch returns no KB tools, return {entries:[], sessionWarm:false, imported:false}.\n` +
2065
+ `Return the structured result. Do not summarize or interpret.`,
2066
+ {
2067
+ model: MODEL_HAIKU,
2068
+ label: 'kb-primer',
2069
+ phase: 'Plan',
2070
+ schema: KB_PRIMER_SCHEMA,
2071
+ maxTurns: 10,
2072
+ }
2073
+ );
2074
+ if (result && result.imported) _kbImported = true;
2075
+ return result;
2076
+ } catch (e) {
2077
+ log(`KB primer failed: ${String(e).slice(0, 120)} -- proceeding without KB`);
2078
+ return null;
2079
+ }
2080
+ }
2081
+
2082
+ // --- Engine-executed KB capture and promote (KB trust pipeline, Phase 2) ---
2083
+ //
2084
+ // Judgment stays with the role agent; EXECUTION moves to the engine. A role
2085
+ // returns kb_captures / kb_promotions in its structured output and never calls
2086
+ // a KB tool itself. Three consequences the old prose-only contract could not
2087
+ // give: promotion no longer depends on an agent remembering Step 5, every
2088
+ // promotion is logged with its stated evidence, and the engine can refuse a
2089
+ // promotion BEFORE it is attempted.
2090
+ //
2091
+ // RUNTIME CONSTRAINT: this workflow is executed by Claude's Workflow tool in a
2092
+ // VM with no filesystem, no require(), and no MCP tool access -- only dispatched
2093
+ // subagents can call tools (see scripts/gen-auto-sprint-schemas.mjs's header for
2094
+ // the same constraint biting a previous revision). fleet-sprint/runner.js runs
2095
+ // under a different engine and DOES get an injected callTool, so it calls the KB
2096
+ // tools directly. Here the engine validates and logs, then hands the vetted
2097
+ // payload to one cheap executor agent whose only job is to make the calls.
2098
+
2099
+ // Promotion is the only path that mints CONFIRMED. Widening capture to four
2100
+ // roles deliberately does NOT widen promotion.
2101
+ const KB_PROMOTER_ROLES = new Set(['reviewer']);
2102
+
2103
+ const KB_MIN_PROMOTE_REASON = 20;
2104
+
2105
+ const KB_EXEC_SCHEMA = {
2106
+ type: 'object',
2107
+ required: ['captured', 'promoted'],
2108
+ properties: {
2109
+ captured: { type: 'number' },
2110
+ promoted: { type: 'number' },
2111
+ failed: { type: 'number' },
2112
+ notes: { type: 'string' },
2113
+ },
2114
+ };
2115
+
2116
+ /**
2117
+ * Validate what a role returned. Anything that would be refused downstream is
2118
+ * dropped HERE, with a reason logged, so a bad payload never becomes a tool call.
2119
+ * Returns { captures, promotions, rejected } -- all plain data.
2120
+ */
2121
+ function vetKbWork(role, result) {
2122
+ const captures = [];
2123
+ const promotions = [];
2124
+ const rejected = [];
2125
+
2126
+ const rawCaptures = (result && Array.isArray(result.kb_captures)) ? result.kb_captures : [];
2127
+ for (const c of rawCaptures) {
2128
+ if (!c || typeof c.title !== 'string' || typeof c.summary !== 'string') {
2129
+ rejected.push(`${role}: capture missing title/summary`);
2130
+ continue;
2131
+ }
2132
+ // Mirrors the Phase 1 provider invariant: an entry with no basis can never
2133
+ // be staled by the freshness sweep, so nothing could ever falsify it.
2134
+ if (!Array.isArray(c.source_files) || c.source_files.length === 0) {
2135
+ rejected.push(`${role}: capture "${c.title}" cites no source files`);
2136
+ continue;
2137
+ }
2138
+ if (!['knowledge', 'learning', 'runbook'].includes(c.type)) {
2139
+ rejected.push(`${role}: capture "${c.title}" has unsupported type ${String(c.type)}`);
2140
+ continue;
2141
+ }
2142
+ // apra-fleet-23c: kbCaptureSchema requires content (z.string().min(1)).
2143
+ // Omitting it meant every kb_capture failed zod validation at the MCP
2144
+ // boundary and persisted nothing. (This block had drifted out of sync with
2145
+ // the canonical copy in lib/vet-kb-work.mjs -- restored to match exactly.)
2146
+ if (typeof c.content !== 'string' || c.content.trim().length === 0) {
2147
+ rejected.push(`${role}: capture "${c.title}" has no content`);
2148
+ continue;
2149
+ }
2150
+ captures.push({
2151
+ type: c.type,
2152
+ title: c.title,
2153
+ summary: c.summary,
2154
+ content: c.content,
2155
+ source_files: c.source_files,
2156
+ symbols: Array.isArray(c.symbols) ? c.symbols : [],
2157
+ });
2158
+ }
2159
+
2160
+ const rawPromotions = (result && Array.isArray(result.kb_promotions)) ? result.kb_promotions : [];
2161
+ if (rawPromotions.length > 0 && !KB_PROMOTER_ROLES.has(role)) {
2162
+ rejected.push(`${role}: kb_promotions refused -- promotion is reviewer-only`);
2163
+ } else {
2164
+ for (const p of rawPromotions) {
2165
+ if (!p || typeof p.id !== 'string' || p.id.length === 0) {
2166
+ rejected.push(`${role}: promotion missing id`);
2167
+ continue;
2168
+ }
2169
+ if (typeof p.reason !== 'string' || p.reason.trim().length < KB_MIN_PROMOTE_REASON) {
2170
+ rejected.push(`${role}: promotion ${p.id} has no recorded evidence`);
2171
+ continue;
2172
+ }
2173
+ promotions.push({ id: p.id, reason: p.reason.trim() });
2174
+ }
2175
+ }
2176
+
2177
+ return { captures, promotions, rejected };
2178
+ }
2179
+
2180
+ /**
2181
+ * Execute vetted KB work. Returns null when there is nothing to do, so the
2182
+ * common case costs no dispatch at all.
2183
+ */
2184
+ async function runKbWork(repoPath, role, result) {
2185
+ const { captures, promotions, rejected } = vetKbWork(role, result);
2186
+
2187
+ for (const r of rejected) log(`KB refused -- ${r}`);
2188
+ // Every promotion is logged with its stated evidence, whether or not the call
2189
+ // later succeeds. This log IS the audit trail the bible never had.
2190
+ for (const p of promotions) log(`KB promote ${p.id} (${role}): ${p.reason}`);
2191
+
2192
+ if (captures.length === 0 && promotions.length === 0) return null;
2193
+
2194
+ try {
2195
+ return await dispatch(
2196
+ `You are a knowledge-base executor. Your ONLY job is to make the KB tool ` +
2197
+ `calls listed below and report counts. Make NO judgment about whether an ` +
2198
+ `entry is correct -- that decision has already been made and validated.\n\n` +
2199
+ `Step 1: Call ToolSearch with query ` +
2200
+ `"select:mcp__apra-fleet__kb_capture,mcp__apra-fleet__kb_promote".\n` +
2201
+ `Step 2: For EACH object in captures below, call mcp__apra-fleet__kb_capture ` +
2202
+ `with repo_path "${repoPath}" and that object's fields verbatim. Do not ` +
2203
+ `reword, merge, split or invent entries.\n` +
2204
+ `Step 3: For EACH object in promotions below, call mcp__apra-fleet__kb_promote ` +
2205
+ `with repo_path "${repoPath}" and that object's id and reason verbatim.\n` +
2206
+ `Step 4: Return the counts. A call refused by the tool counts in failed, ` +
2207
+ `not captured/promoted -- report it, do not retry it with altered fields.\n\n` +
2208
+ `captures: ${JSON.stringify(captures)}\n` +
2209
+ `promotions: ${JSON.stringify(promotions)}\n\n` +
2210
+ `If ToolSearch returns no KB tools, return {captured:0, promoted:0, failed:0}.`,
2211
+ {
2212
+ model: MODEL_HAIKU,
2213
+ label: `kb-exec-${role}`,
2214
+ phase: 'Develop',
2215
+ schema: KB_EXEC_SCHEMA,
2216
+ maxTurns: 20,
2217
+ }
2218
+ );
2219
+ } catch (e) {
2220
+ log(`KB executor failed for ${role}: ${String(e).slice(0, 120)} -- continuing`);
2221
+ return null;
2222
+ }
2223
+ }
2224
+
2225
+ const KB_CHAR_BUDGET = 4000;
2226
+
2227
+ function buildKBContext(kbResult) {
2228
+ if (!kbResult || !Array.isArray(kbResult.entries) || kbResult.entries.length === 0) {
2229
+ return '';
2230
+ }
2231
+ let block = `\n--- Project Knowledge Bank (${kbResult.entries.length} entries) ---\n` +
2232
+ `Trust CONFIRMED entries fully. Use INFERRED entries as hints, not facts.\n\n`;
2233
+ let len = block.length;
2234
+ for (const e of kbResult.entries) {
2235
+ const line = `- [${(e.confidence || 'CONFIRMED').toUpperCase()}] ${e.title}: ${e.summary}` +
2236
+ (e.symbols && e.symbols.length ? ` (symbols: ${e.symbols.join(', ')})` : '') + '\n';
2237
+ if (len + line.length > KB_CHAR_BUDGET) break;
2238
+ block += line;
2239
+ len += line.length;
2240
+ }
2241
+ block += `--- End Project Knowledge ---\n\n`;
2242
+ return block;
2243
+ }
2244
+
1742
2245
  // bd may prepend a `warning: ...` line to its --json stdout (notably bd 1.1.0's
1743
2246
  // "warning: beads.role not configured (GH#2950)"). In a normal terminal that goes to
1744
2247
  // stderr, but inside the workflow's sandboxed shell-dispatch subagents stderr merges
@@ -2260,11 +2763,32 @@ const stamp = async (name) => {
2260
2763
  };
2261
2764
  await stamp('setup');
2262
2765
 
2766
+ // ---- KB PRIMING (once at sprint start; refreshed per cycle) ----
2767
+ let kbContext = '';
2768
+ {
2769
+ const kbResult = await primeKB(repo);
2770
+ if (kbResult) {
2771
+ kbContext = buildKBContext(kbResult);
2772
+ log(`KB primed: ${(kbResult.entries || []).length} entries, imported=${kbResult.imported}`);
2773
+ } else {
2774
+ log('KB priming unavailable -- proceeding without KB context');
2775
+ }
2776
+ }
2777
+
2263
2778
  while (cycleCount < maxCycles) {
2264
2779
  cycleCount++;
2265
2780
  cycleCostUsd = 0;
2266
2781
  log(`\n=== Cycle ${cycleCount}/${maxCycles} | goal: ${goal} ===`);
2267
2782
 
2783
+ // ---- KB REFRESH (per cycle -- picks up entries captured in previous cycles) ----
2784
+ if (cycleCount > 1) {
2785
+ const kbRefresh = await primeKB(repo);
2786
+ if (kbRefresh) {
2787
+ kbContext = buildKBContext(kbRefresh);
2788
+ log(`KB refreshed: ${(kbRefresh.entries || []).length} entries`);
2789
+ }
2790
+ }
2791
+
2268
2792
  // ---------------------------------------------------------------- RESUME CHECK + CYCLE CHECKPOINT
2269
2793
 
2270
2794
  phase('Plan');
@@ -2327,6 +2851,7 @@ while (cycleCount < maxCycles) {
2327
2851
  let plannerResult = null;
2328
2852
  if (!skipPlanner) {
2329
2853
  plannerResult = await dispatch(
2854
+ kbContext +
2330
2855
  `Repo: ${repo}\nBranch: ${branch}\nBase branch: ${base_branch}\n` +
2331
2856
  `Sprint goals: ${rootSummary}\n` +
2332
2857
  (requirementsFile ? `Additional context: ${requirementsFile}\n` : '') +
@@ -2389,8 +2914,10 @@ while (cycleCount < maxCycles) {
2389
2914
  `Do NOT add new scope beyond the original sprint goals and open bugs/enhancements.\n` +
2390
2915
  `Do NOT re-create tasks that are already closed.\n`
2391
2916
  : '') +
2392
- `Confirm with any text when done.`,
2393
- { model: MODEL_OPUS, label: plannerLabel, phase: 'Plan', agentType: 'planner',
2917
+ `Return status "OK" when the DAG is in place, or "BLOCKED" with notes if you\n` +
2918
+ `could not create it. List the feature and task ids you created in featureIds\n` +
2919
+ `and taskIds.`,
2920
+ { model: MODEL_OPUS, label: plannerLabel, phase: 'Plan', schema: PLANNER_SCHEMA, agentType: 'planner',
2394
2921
  context: `planning sprint goals ${rootSummary}` }
2395
2922
  );
2396
2923
 
@@ -2398,6 +2925,7 @@ while (cycleCount < maxCycles) {
2398
2925
  log(`Planner returned null on cycle ${cycleCount} round ${pi} -- retrying`);
2399
2926
  continue;
2400
2927
  }
2928
+ await runKbWork(repo, 'planner', plannerResult);
2401
2929
  }
2402
2930
 
2403
2931
  const planReviewerLabel = `plan-reviewer-c${cycleCount}-r${pi}`;
@@ -2637,6 +3165,7 @@ while (cycleCount < maxCycles) {
2637
3165
 
2638
3166
  const doerOutcomes = await parallel(okWt.map(w =>
2639
3167
  dispatch(
3168
+ kbContext +
2640
3169
  `You are working in an ISOLATED git worktree -- other doers run concurrently in their own worktrees.\n` +
2641
3170
  `Worktree path: ${repo}/${w.path} (cd into it first; you are on temp branch ${w.branch})\n` +
2642
3171
  `Work ONLY task ${w.id}. Do NOT work any other task.\n\n` +
@@ -2651,7 +3180,10 @@ while (cycleCount < maxCycles) {
2651
3180
  `Return status "VERIFY" when done. Return status "BLOCKED" only for your runbook's blocked cases (missing secret) -- never any other status.`,
2652
3181
  { model: w.model, label: `doer-c${cycleCount}-i${devIter}-${w.id}`, phase: 'Develop', schema: DOER_STATUS_SCHEMA,
2653
3182
  agentType: 'doer', context: `task ${w.id} (worktree)` }
2654
- ).then(r => ({ w, ok: !!r && r.status === 'VERIFY' })).catch(() => ({ w, ok: false }))
3183
+ ).then(async r => {
3184
+ await runKbWork(repo, 'doer', r);
3185
+ return { w, ok: !!r && r.status === 'VERIFY' };
3186
+ }).catch(() => ({ w, ok: false }))
2655
3187
  ));
2656
3188
 
2657
3189
  // Merge sequentially into the sprint branch (deterministic id order from computeDoerBatch).
@@ -2726,6 +3258,7 @@ while (cycleCount < maxCycles) {
2726
3258
  log(`Doer c${cycleCount}-i${devIter}: ${labelTaskIds(fittedIds)} [model=${streak.model}${streakEstUsd != null ? ` est=$${streakEstUsd.toFixed(4)}` : ''}]`);
2727
3259
 
2728
3260
  const doerResult = await dispatch(
3261
+ kbContext +
2729
3262
  `Repo: ${repo}\nBranch: ${branch}\n\n` +
2730
3263
  (devFeedback
2731
3264
  ? `Reviewer feedback from the previous iteration (read feedback.md in ${repo} for full details):\n${devFeedback}\nAddress every finding before closing tasks.\n\n`
@@ -2744,6 +3277,7 @@ while (cycleCount < maxCycles) {
2744
3277
  { model: streak.model, label: doerLabel, phase: 'Develop', schema: DOER_STATUS_SCHEMA, agentType: 'doer',
2745
3278
  context: `tasks ${fittedIds.join(', ')}` }
2746
3279
  );
3280
+ await runKbWork(repo, 'doer', doerResult);
2747
3281
 
2748
3282
  if (!doerResult) {
2749
3283
  log(`Doer returned null (streak ${streak.model}) -- resetting orphaned in_progress tasks and retrying`);
@@ -2799,6 +3333,7 @@ while (cycleCount < maxCycles) {
2799
3333
  // One reviewer pass covering all streaks worked this iteration.
2800
3334
  const reviewerLabel = `reviewer-c${cycleCount}-i${devIter}: ${labelTaskIds(workedIds)}`;
2801
3335
  const review = await dispatch(
3336
+ kbContext +
2802
3337
  `Repo: ${repo}\nBranch: ${branch}\nBase branch: ${base_branch}\n` +
2803
3338
  `Sprint goals: ${rootSummary}\nTasks worked this iteration: ${workedIds.join(', ')}\n\n` +
2804
3339
  `Review ONLY the work done for the tasks listed above.\n` +
@@ -2815,6 +3350,7 @@ while (cycleCount < maxCycles) {
2815
3350
  context: `reviewing tasks ${workedIds.join(', ')}` }
2816
3351
  );
2817
3352
  log(`Reviewer c${cycleCount}-i${devIter}: ${(review && review.verdict) || 'null'} -- ${labelTaskIds(workedIds)}`);
3353
+ await runKbWork(repo, 'reviewer', review);
2818
3354
 
2819
3355
  if (!approved(review)) {
2820
3356
  devFeedback = (review && review.notes) || '';
@@ -3049,6 +3585,7 @@ await dispatchShell(
3049
3585
 
3050
3586
  const finalReviewLabel = 'final-reviewer';
3051
3587
  const finalReview = await dispatch(
3588
+ kbContext +
3052
3589
  `Repo: ${repo}\nBranch: ${branch}\nBase branch: ${base_branch}\n` +
3053
3590
  `Sprint goals: ${rootSummary}\nGoal: ${goal}\n` +
3054
3591
  (abortReason ? `Sprint ended early: ${abortReason}. Review what was completed.\n` : '') +
@@ -3062,6 +3599,7 @@ const finalReview = await dispatch(
3062
3599
  { model: MODEL_OPUS, label: finalReviewLabel, phase: 'Harvest', schema: REVIEW_SCHEMA, agentType: 'reviewer' }
3063
3600
  );
3064
3601
  log(`Final review: ${finalReview && finalReview.verdict || 'null'}`);
3602
+ await runKbWork(repo, 'reviewer', finalReview);
3065
3603
 
3066
3604
  if (!approved(finalReview)) {
3067
3605
  const notes = (finalReview && finalReview.notes) || '';
@@ -3159,6 +3697,7 @@ const analysisArtifactFile = `sprint-logs/${sprintLogBranch}-${effectiveStartedA
3159
3697
 
3160
3698
  const harvestLabel = 'harvester';
3161
3699
  const harvestResult = await dispatch(
3700
+ kbContext +
3162
3701
  `Repo: ${repo}\nBranch: ${branch}\nBase branch: ${base_branch}\n` +
3163
3702
  `Sprint goals: ${rootSummary}\nCycles completed: ${cycleCount}\nGoal met: ${goalMet}\n` +
3164
3703
  `sprintLogFile: ${sprintLogFile}\n` +
@@ -3178,6 +3717,7 @@ const harvestResult = await dispatch(
3178
3717
  `Return status "OK" if successful, "FAILED" with notes otherwise.`,
3179
3718
  { model: MODEL_SONNET, label: harvestLabel, phase: 'Harvest', schema: HARVEST_SCHEMA, agentType: 'harvester' }
3180
3719
  );
3720
+ await runKbWork(repo, 'harvester', harvestResult);
3181
3721
 
3182
3722
  if (!harvestResult || harvestResult.status !== 'OK') {
3183
3723
  log(`Harvest failed: ${(harvestResult && harvestResult.notes) || 'null'} -- writing analysis fallback`);