@apralabs/apra-fleet 0.3.5 → 0.4.0

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 (571) hide show
  1. package/README.md +245 -257
  2. package/dist/agents/backlog-groomer.md +287 -0
  3. package/dist/agents/deployer.md +52 -11
  4. package/dist/agents/doer.md +32 -7
  5. package/dist/agents/integ-test-runner.md +151 -61
  6. package/dist/agents/plan-reviewer.md +74 -17
  7. package/dist/agents/planner.md +94 -14
  8. package/dist/agents/regression-test-runner.md +216 -0
  9. package/dist/agents/reviewer.md +21 -6
  10. package/dist/agents/schemas/backlog-groomer-input.json +35 -0
  11. package/dist/agents/schemas/backlog-groomer-output.json +164 -0
  12. package/dist/agents/schemas/integ-test-runner-output.json +34 -0
  13. package/dist/agents/schemas/regression-test-runner-input.json +15 -0
  14. package/dist/agents/schemas/regression-test-runner-output.json +50 -0
  15. package/dist/agents/schemas/reviewer-output.json +4 -0
  16. package/dist/cli/agent-transform.d.ts +1 -0
  17. package/dist/cli/agent-transform.d.ts.map +1 -1
  18. package/dist/cli/agent-transform.js +77 -0
  19. package/dist/cli/agent-transform.js.map +1 -1
  20. package/dist/cli/auth.d.ts +3 -0
  21. package/dist/cli/auth.d.ts.map +1 -1
  22. package/dist/cli/auth.js +181 -5
  23. package/dist/cli/auth.js.map +1 -1
  24. package/dist/cli/config.d.ts +5 -1
  25. package/dist/cli/config.d.ts.map +1 -1
  26. package/dist/cli/config.js +7 -1
  27. package/dist/cli/config.js.map +1 -1
  28. package/dist/cli/dolt-install.d.ts +91 -0
  29. package/dist/cli/dolt-install.d.ts.map +1 -0
  30. package/dist/cli/dolt-install.js +334 -0
  31. package/dist/cli/dolt-install.js.map +1 -0
  32. package/dist/cli/install-guard.d.ts +29 -0
  33. package/dist/cli/install-guard.d.ts.map +1 -0
  34. package/dist/cli/install-guard.js +153 -0
  35. package/dist/cli/install-guard.js.map +1 -0
  36. package/dist/cli/install.d.ts +44 -3
  37. package/dist/cli/install.d.ts.map +1 -1
  38. package/dist/cli/install.js +604 -108
  39. package/dist/cli/install.js.map +1 -1
  40. package/dist/cli/join.d.ts +12 -0
  41. package/dist/cli/join.d.ts.map +1 -0
  42. package/dist/cli/join.js +87 -0
  43. package/dist/cli/join.js.map +1 -0
  44. package/dist/cli/register-member.d.ts +2 -0
  45. package/dist/cli/register-member.d.ts.map +1 -0
  46. package/dist/cli/register-member.js +193 -0
  47. package/dist/cli/register-member.js.map +1 -0
  48. package/dist/cli/restart.d.ts +2 -0
  49. package/dist/cli/restart.d.ts.map +1 -0
  50. package/dist/cli/restart.js +7 -0
  51. package/dist/cli/restart.js.map +1 -0
  52. package/dist/cli/secret.js +8 -2
  53. package/dist/cli/secret.js.map +1 -1
  54. package/dist/cli/spoke.d.ts +35 -0
  55. package/dist/cli/spoke.d.ts.map +1 -0
  56. package/dist/cli/spoke.js +212 -0
  57. package/dist/cli/spoke.js.map +1 -0
  58. package/dist/cli/start.d.ts +2 -0
  59. package/dist/cli/start.d.ts.map +1 -0
  60. package/dist/cli/start.js +92 -0
  61. package/dist/cli/start.js.map +1 -0
  62. package/dist/cli/status.d.ts +2 -0
  63. package/dist/cli/status.d.ts.map +1 -0
  64. package/dist/cli/status.js +83 -0
  65. package/dist/cli/status.js.map +1 -0
  66. package/dist/cli/stop.d.ts +2 -0
  67. package/dist/cli/stop.d.ts.map +1 -0
  68. package/dist/cli/stop.js +51 -0
  69. package/dist/cli/stop.js.map +1 -0
  70. package/dist/cli/uninstall.d.ts.map +1 -1
  71. package/dist/cli/uninstall.js +109 -9
  72. package/dist/cli/uninstall.js.map +1 -1
  73. package/dist/cli/update.d.ts.map +1 -1
  74. package/dist/cli/update.js +10 -1
  75. package/dist/cli/update.js.map +1 -1
  76. package/dist/cli/workflow-assets.d.ts +37 -0
  77. package/dist/cli/workflow-assets.d.ts.map +1 -0
  78. package/dist/cli/workflow-assets.js +144 -0
  79. package/dist/cli/workflow-assets.js.map +1 -0
  80. package/dist/cli/workflow.d.ts +75 -0
  81. package/dist/cli/workflow.d.ts.map +1 -0
  82. package/dist/cli/workflow.js +397 -0
  83. package/dist/cli/workflow.js.map +1 -0
  84. package/dist/hub-service/activity.d.ts +30 -0
  85. package/dist/hub-service/activity.d.ts.map +1 -0
  86. package/dist/hub-service/activity.js +20 -0
  87. package/dist/hub-service/activity.js.map +1 -0
  88. package/dist/hub-service/audit-log.d.ts +19 -0
  89. package/dist/hub-service/audit-log.d.ts.map +1 -0
  90. package/dist/hub-service/audit-log.js +13 -0
  91. package/dist/hub-service/audit-log.js.map +1 -0
  92. package/dist/hub-service/db/pool.d.ts +19 -0
  93. package/dist/hub-service/db/pool.d.ts.map +1 -0
  94. package/dist/hub-service/db/pool.js +53 -0
  95. package/dist/hub-service/db/pool.js.map +1 -0
  96. package/dist/hub-service/enrollment.d.ts +29 -0
  97. package/dist/hub-service/enrollment.d.ts.map +1 -0
  98. package/dist/hub-service/enrollment.js +48 -0
  99. package/dist/hub-service/enrollment.js.map +1 -0
  100. package/dist/hub-service/envelope-routes.d.ts +46 -0
  101. package/dist/hub-service/envelope-routes.d.ts.map +1 -0
  102. package/dist/hub-service/envelope-routes.js +94 -0
  103. package/dist/hub-service/envelope-routes.js.map +1 -0
  104. package/dist/hub-service/handlers/installers.d.ts +14 -0
  105. package/dist/hub-service/handlers/installers.d.ts.map +1 -0
  106. package/dist/hub-service/handlers/installers.js +8 -0
  107. package/dist/hub-service/handlers/installers.js.map +1 -0
  108. package/dist/hub-service/http-server.d.ts +31 -0
  109. package/dist/hub-service/http-server.d.ts.map +1 -0
  110. package/dist/hub-service/http-server.js +711 -0
  111. package/dist/hub-service/http-server.js.map +1 -0
  112. package/dist/hub-service/hub-jwt.d.ts +30 -0
  113. package/dist/hub-service/hub-jwt.d.ts.map +1 -0
  114. package/dist/hub-service/hub-jwt.js +105 -0
  115. package/dist/hub-service/hub-jwt.js.map +1 -0
  116. package/dist/hub-service/jwt-revocation.d.ts +20 -0
  117. package/dist/hub-service/jwt-revocation.d.ts.map +1 -0
  118. package/dist/hub-service/jwt-revocation.js +18 -0
  119. package/dist/hub-service/jwt-revocation.js.map +1 -0
  120. package/dist/hub-service/machines.d.ts +16 -0
  121. package/dist/hub-service/machines.d.ts.map +1 -0
  122. package/dist/hub-service/machines.js +14 -0
  123. package/dist/hub-service/machines.js.map +1 -0
  124. package/dist/hub-service/main.d.ts +3 -0
  125. package/dist/hub-service/main.d.ts.map +1 -0
  126. package/dist/hub-service/main.js +64 -0
  127. package/dist/hub-service/main.js.map +1 -0
  128. package/dist/hub-service/member-tokens.d.ts +11 -0
  129. package/dist/hub-service/member-tokens.d.ts.map +1 -0
  130. package/dist/hub-service/member-tokens.js +49 -0
  131. package/dist/hub-service/member-tokens.js.map +1 -0
  132. package/dist/hub-service/member-view.d.ts +20 -0
  133. package/dist/hub-service/member-view.d.ts.map +1 -0
  134. package/dist/hub-service/member-view.js +76 -0
  135. package/dist/hub-service/member-view.js.map +1 -0
  136. package/dist/hub-service/members.d.ts +44 -0
  137. package/dist/hub-service/members.d.ts.map +1 -0
  138. package/dist/hub-service/members.js +25 -0
  139. package/dist/hub-service/members.js.map +1 -0
  140. package/dist/hub-service/presence.d.ts +40 -0
  141. package/dist/hub-service/presence.d.ts.map +1 -0
  142. package/dist/hub-service/presence.js +44 -0
  143. package/dist/hub-service/presence.js.map +1 -0
  144. package/dist/hub-service/project-view.d.ts +12 -0
  145. package/dist/hub-service/project-view.d.ts.map +1 -0
  146. package/dist/hub-service/project-view.js +34 -0
  147. package/dist/hub-service/project-view.js.map +1 -0
  148. package/dist/hub-service/projects.d.ts +48 -0
  149. package/dist/hub-service/projects.d.ts.map +1 -0
  150. package/dist/hub-service/projects.js +80 -0
  151. package/dist/hub-service/projects.js.map +1 -0
  152. package/dist/hub-service/relay-queue.d.ts +115 -0
  153. package/dist/hub-service/relay-queue.d.ts.map +1 -0
  154. package/dist/hub-service/relay-queue.js +148 -0
  155. package/dist/hub-service/relay-queue.js.map +1 -0
  156. package/dist/hub-service/session-jwt.d.ts +10 -0
  157. package/dist/hub-service/session-jwt.d.ts.map +1 -0
  158. package/dist/hub-service/session-jwt.js +69 -0
  159. package/dist/hub-service/session-jwt.js.map +1 -0
  160. package/dist/hub-service/usage.d.ts +40 -0
  161. package/dist/hub-service/usage.d.ts.map +1 -0
  162. package/dist/hub-service/usage.js +25 -0
  163. package/dist/hub-service/usage.js.map +1 -0
  164. package/dist/hub-service/users.d.ts +56 -0
  165. package/dist/hub-service/users.d.ts.map +1 -0
  166. package/dist/hub-service/users.js +72 -0
  167. package/dist/hub-service/users.js.map +1 -0
  168. package/dist/hub-service/workspaces.d.ts +20 -0
  169. package/dist/hub-service/workspaces.d.ts.map +1 -0
  170. package/dist/hub-service/workspaces.js +10 -0
  171. package/dist/hub-service/workspaces.js.map +1 -0
  172. package/dist/index.js +179 -132
  173. package/dist/index.js.map +1 -1
  174. package/dist/os/linux.d.ts +13 -0
  175. package/dist/os/linux.d.ts.map +1 -1
  176. package/dist/os/linux.js +62 -3
  177. package/dist/os/linux.js.map +1 -1
  178. package/dist/os/os-commands.d.ts +10 -0
  179. package/dist/os/os-commands.d.ts.map +1 -1
  180. package/dist/os/windows.d.ts +1 -0
  181. package/dist/os/windows.d.ts.map +1 -1
  182. package/dist/os/windows.js +21 -1
  183. package/dist/os/windows.js.map +1 -1
  184. package/dist/paths.d.ts +23 -0
  185. package/dist/paths.d.ts.map +1 -1
  186. package/dist/paths.js +29 -0
  187. package/dist/paths.js.map +1 -1
  188. package/dist/providers/agy.d.ts +9 -2
  189. package/dist/providers/agy.d.ts.map +1 -1
  190. package/dist/providers/agy.js +127 -14
  191. package/dist/providers/agy.js.map +1 -1
  192. package/dist/providers/claude.d.ts +6 -2
  193. package/dist/providers/claude.d.ts.map +1 -1
  194. package/dist/providers/claude.js +248 -9
  195. package/dist/providers/claude.js.map +1 -1
  196. package/dist/providers/codex.d.ts +3 -2
  197. package/dist/providers/codex.d.ts.map +1 -1
  198. package/dist/providers/codex.js +7 -0
  199. package/dist/providers/codex.js.map +1 -1
  200. package/dist/providers/copilot.d.ts +3 -2
  201. package/dist/providers/copilot.d.ts.map +1 -1
  202. package/dist/providers/copilot.js +8 -1
  203. package/dist/providers/copilot.js.map +1 -1
  204. package/dist/providers/gemini.d.ts +3 -2
  205. package/dist/providers/gemini.d.ts.map +1 -1
  206. package/dist/providers/gemini.js +11 -1
  207. package/dist/providers/gemini.js.map +1 -1
  208. package/dist/providers/index.d.ts +1 -0
  209. package/dist/providers/index.d.ts.map +1 -1
  210. package/dist/providers/index.js +3 -0
  211. package/dist/providers/index.js.map +1 -1
  212. package/dist/providers/none.d.ts +51 -0
  213. package/dist/providers/none.d.ts.map +1 -0
  214. package/dist/providers/none.js +103 -0
  215. package/dist/providers/none.js.map +1 -0
  216. package/dist/providers/opencode.d.ts +4 -2
  217. package/dist/providers/opencode.d.ts.map +1 -1
  218. package/dist/providers/opencode.js +49 -0
  219. package/dist/providers/opencode.js.map +1 -1
  220. package/dist/providers/provider.d.ts +79 -1
  221. package/dist/providers/provider.d.ts.map +1 -1
  222. package/dist/providers/provider.js +10 -0
  223. package/dist/providers/provider.js.map +1 -1
  224. package/dist/services/agent-provisioner.d.ts +3 -3
  225. package/dist/services/agent-provisioner.d.ts.map +1 -1
  226. package/dist/services/agent-provisioner.js +12 -5
  227. package/dist/services/agent-provisioner.js.map +1 -1
  228. package/dist/services/auth-socket.d.ts.map +1 -1
  229. package/dist/services/auth-socket.js +2 -0
  230. package/dist/services/auth-socket.js.map +1 -1
  231. package/dist/services/budget-awareness.d.ts +130 -0
  232. package/dist/services/budget-awareness.d.ts.map +1 -0
  233. package/dist/services/budget-awareness.js +129 -0
  234. package/dist/services/budget-awareness.js.map +1 -0
  235. package/dist/services/cloud-sync.d.ts +35 -0
  236. package/dist/services/cloud-sync.d.ts.map +1 -0
  237. package/dist/services/cloud-sync.js +90 -0
  238. package/dist/services/cloud-sync.js.map +1 -0
  239. package/dist/services/context-admission.d.ts +82 -0
  240. package/dist/services/context-admission.d.ts.map +1 -0
  241. package/dist/services/context-admission.js +136 -0
  242. package/dist/services/context-admission.js.map +1 -0
  243. package/dist/services/event-bus.d.ts +27 -0
  244. package/dist/services/event-bus.d.ts.map +1 -0
  245. package/dist/services/event-bus.js +20 -0
  246. package/dist/services/event-bus.js.map +1 -0
  247. package/dist/services/file-chunker.d.ts +38 -0
  248. package/dist/services/file-chunker.d.ts.map +1 -0
  249. package/dist/services/file-chunker.js +63 -0
  250. package/dist/services/file-chunker.js.map +1 -0
  251. package/dist/services/file-transfer-relay.d.ts +55 -0
  252. package/dist/services/file-transfer-relay.d.ts.map +1 -0
  253. package/dist/services/file-transfer-relay.js +115 -0
  254. package/dist/services/file-transfer-relay.js.map +1 -0
  255. package/dist/services/github-app.d.ts.map +1 -1
  256. package/dist/services/github-app.js +1 -0
  257. package/dist/services/github-app.js.map +1 -1
  258. package/dist/services/http-transport.d.ts +25 -0
  259. package/dist/services/http-transport.d.ts.map +1 -0
  260. package/dist/services/http-transport.js +371 -0
  261. package/dist/services/http-transport.js.map +1 -0
  262. package/dist/services/hub-client.d.ts +69 -0
  263. package/dist/services/hub-client.d.ts.map +1 -0
  264. package/dist/services/hub-client.js +217 -0
  265. package/dist/services/hub-client.js.map +1 -0
  266. package/dist/services/jwt.d.ts +17 -0
  267. package/dist/services/jwt.d.ts.map +1 -0
  268. package/dist/services/jwt.js +70 -0
  269. package/dist/services/jwt.js.map +1 -0
  270. package/dist/services/known-sessions.d.ts +8 -0
  271. package/dist/services/known-sessions.d.ts.map +1 -0
  272. package/dist/services/known-sessions.js +40 -0
  273. package/dist/services/known-sessions.js.map +1 -0
  274. package/dist/services/model-pricing.d.ts +36 -0
  275. package/dist/services/model-pricing.d.ts.map +1 -0
  276. package/dist/services/model-pricing.js +108 -0
  277. package/dist/services/model-pricing.js.map +1 -0
  278. package/dist/services/orphan-recovery.d.ts +56 -0
  279. package/dist/services/orphan-recovery.d.ts.map +1 -0
  280. package/dist/services/orphan-recovery.js +111 -0
  281. package/dist/services/orphan-recovery.js.map +1 -0
  282. package/dist/services/pending-responses.d.ts +23 -0
  283. package/dist/services/pending-responses.d.ts.map +1 -0
  284. package/dist/services/pending-responses.js +52 -0
  285. package/dist/services/pending-responses.js.map +1 -0
  286. package/dist/services/registry.d.ts +4 -1
  287. package/dist/services/registry.d.ts.map +1 -1
  288. package/dist/services/registry.js +3 -0
  289. package/dist/services/registry.js.map +1 -1
  290. package/dist/services/relay-context.d.ts +23 -0
  291. package/dist/services/relay-context.d.ts.map +1 -0
  292. package/dist/services/relay-context.js +8 -0
  293. package/dist/services/relay-context.js.map +1 -0
  294. package/dist/services/relay-executor.d.ts +68 -0
  295. package/dist/services/relay-executor.d.ts.map +1 -0
  296. package/dist/services/relay-executor.js +70 -0
  297. package/dist/services/relay-executor.js.map +1 -0
  298. package/dist/services/relay-request.d.ts +65 -0
  299. package/dist/services/relay-request.d.ts.map +1 -0
  300. package/dist/services/relay-request.js +129 -0
  301. package/dist/services/relay-request.js.map +1 -0
  302. package/dist/services/relay-strategy.d.ts +19 -0
  303. package/dist/services/relay-strategy.d.ts.map +1 -0
  304. package/dist/services/relay-strategy.js +111 -0
  305. package/dist/services/relay-strategy.js.map +1 -0
  306. package/dist/services/service-manager/index.d.ts +5 -0
  307. package/dist/services/service-manager/index.d.ts.map +1 -0
  308. package/dist/services/service-manager/index.js +66 -0
  309. package/dist/services/service-manager/index.js.map +1 -0
  310. package/dist/services/service-manager/linux.d.ts +10 -0
  311. package/dist/services/service-manager/linux.d.ts.map +1 -0
  312. package/dist/services/service-manager/linux.js +97 -0
  313. package/dist/services/service-manager/linux.js.map +1 -0
  314. package/dist/services/service-manager/macos.d.ts +10 -0
  315. package/dist/services/service-manager/macos.d.ts.map +1 -0
  316. package/dist/services/service-manager/macos.js +94 -0
  317. package/dist/services/service-manager/macos.js.map +1 -0
  318. package/dist/services/service-manager/types.d.ts +18 -0
  319. package/dist/services/service-manager/types.d.ts.map +1 -0
  320. package/dist/services/service-manager/types.js +5 -0
  321. package/dist/services/service-manager/types.js.map +1 -0
  322. package/dist/services/service-manager/windows.d.ts +10 -0
  323. package/dist/services/service-manager/windows.d.ts.map +1 -0
  324. package/dist/services/service-manager/windows.js +73 -0
  325. package/dist/services/service-manager/windows.js.map +1 -0
  326. package/dist/services/session-registry.d.ts +70 -0
  327. package/dist/services/session-registry.d.ts.map +1 -0
  328. package/dist/services/session-registry.js +91 -0
  329. package/dist/services/session-registry.js.map +1 -0
  330. package/dist/services/singleton.d.ts +15 -0
  331. package/dist/services/singleton.d.ts.map +1 -0
  332. package/dist/services/singleton.js +98 -0
  333. package/dist/services/singleton.js.map +1 -0
  334. package/dist/services/sprint-coordination.d.ts +168 -0
  335. package/dist/services/sprint-coordination.d.ts.map +1 -0
  336. package/dist/services/sprint-coordination.js +564 -0
  337. package/dist/services/sprint-coordination.js.map +1 -0
  338. package/dist/services/ssh.d.ts.map +1 -1
  339. package/dist/services/ssh.js +70 -3
  340. package/dist/services/ssh.js.map +1 -1
  341. package/dist/services/stall/log-path-resolver.d.ts.map +1 -1
  342. package/dist/services/stall/log-path-resolver.js +8 -1
  343. package/dist/services/stall/log-path-resolver.js.map +1 -1
  344. package/dist/services/stall/stall-detector.d.ts.map +1 -1
  345. package/dist/services/stall/stall-detector.js +39 -7
  346. package/dist/services/stall/stall-detector.js.map +1 -1
  347. package/dist/services/stall/stall-poller.d.ts +16 -0
  348. package/dist/services/stall/stall-poller.d.ts.map +1 -1
  349. package/dist/services/stall/stall-poller.js +136 -18
  350. package/dist/services/stall/stall-poller.js.map +1 -1
  351. package/dist/services/strategy.d.ts.map +1 -1
  352. package/dist/services/strategy.js +55 -5
  353. package/dist/services/strategy.js.map +1 -1
  354. package/dist/services/substitution-engine.d.ts +20 -0
  355. package/dist/services/substitution-engine.d.ts.map +1 -0
  356. package/dist/services/substitution-engine.js +92 -0
  357. package/dist/services/substitution-engine.js.map +1 -0
  358. package/dist/services/task-cleanup.d.ts.map +1 -1
  359. package/dist/services/task-cleanup.js +1 -9
  360. package/dist/services/task-cleanup.js.map +1 -1
  361. package/dist/services/token-issuer.d.ts +47 -0
  362. package/dist/services/token-issuer.d.ts.map +1 -0
  363. package/dist/services/token-issuer.js +63 -0
  364. package/dist/services/token-issuer.js.map +1 -0
  365. package/dist/services/tool-registry.d.ts +3 -0
  366. package/dist/services/tool-registry.d.ts.map +1 -0
  367. package/dist/services/tool-registry.js +139 -0
  368. package/dist/services/tool-registry.js.map +1 -0
  369. package/dist/services/user-config.d.ts +14 -0
  370. package/dist/services/user-config.d.ts.map +1 -1
  371. package/dist/services/user-config.js +55 -0
  372. package/dist/services/user-config.js.map +1 -1
  373. package/dist/services/vcs/types.d.ts +44 -0
  374. package/dist/services/vcs/types.d.ts.map +1 -1
  375. package/dist/skills/fleet-sprint-cli/SKILL.md +103 -0
  376. package/dist/skills/pm/cost.md +3 -0
  377. package/dist/skills/pm/doer-reviewer-loop.md +3 -0
  378. package/dist/tools/check-status.d.ts.map +1 -1
  379. package/dist/tools/check-status.js +8 -2
  380. package/dist/tools/check-status.js.map +1 -1
  381. package/dist/tools/child-id-allocator.d.ts +45 -0
  382. package/dist/tools/child-id-allocator.d.ts.map +1 -0
  383. package/dist/tools/child-id-allocator.js +62 -0
  384. package/dist/tools/child-id-allocator.js.map +1 -0
  385. package/dist/tools/cloud-control.d.ts +2 -2
  386. package/dist/tools/compose-permissions.d.ts +12 -4
  387. package/dist/tools/compose-permissions.d.ts.map +1 -1
  388. package/dist/tools/compose-permissions.js +55 -4
  389. package/dist/tools/compose-permissions.js.map +1 -1
  390. package/dist/tools/dolt-push-mutex.d.ts +44 -0
  391. package/dist/tools/dolt-push-mutex.d.ts.map +1 -0
  392. package/dist/tools/dolt-push-mutex.js +83 -0
  393. package/dist/tools/dolt-push-mutex.js.map +1 -0
  394. package/dist/tools/execute-command.d.ts +11 -1
  395. package/dist/tools/execute-command.d.ts.map +1 -1
  396. package/dist/tools/execute-command.js +22 -5
  397. package/dist/tools/execute-command.js.map +1 -1
  398. package/dist/tools/execute-prompt.d.ts +72 -12
  399. package/dist/tools/execute-prompt.d.ts.map +1 -1
  400. package/dist/tools/execute-prompt.js +962 -71
  401. package/dist/tools/execute-prompt.js.map +1 -1
  402. package/dist/tools/get-member-model-pricing.d.ts +21 -0
  403. package/dist/tools/get-member-model-pricing.d.ts.map +1 -0
  404. package/dist/tools/get-member-model-pricing.js +29 -0
  405. package/dist/tools/get-member-model-pricing.js.map +1 -0
  406. package/dist/tools/list-members.d.ts.map +1 -1
  407. package/dist/tools/list-members.js +39 -7
  408. package/dist/tools/list-members.js.map +1 -1
  409. package/dist/tools/member-detail.d.ts +1 -1
  410. package/dist/tools/member-detail.d.ts.map +1 -1
  411. package/dist/tools/member-detail.js +8 -2
  412. package/dist/tools/member-detail.js.map +1 -1
  413. package/dist/tools/member-reservation.d.ts +29 -0
  414. package/dist/tools/member-reservation.d.ts.map +1 -0
  415. package/dist/tools/member-reservation.js +71 -0
  416. package/dist/tools/member-reservation.js.map +1 -0
  417. package/dist/tools/provision-vcs-auth.d.ts +7 -7
  418. package/dist/tools/provision-vcs-auth.js +1 -1
  419. package/dist/tools/provision-vcs-auth.js.map +1 -1
  420. package/dist/tools/register-member.d.ts +17 -5
  421. package/dist/tools/register-member.d.ts.map +1 -1
  422. package/dist/tools/register-member.js +144 -5
  423. package/dist/tools/register-member.js.map +1 -1
  424. package/dist/tools/remove-member.d.ts +1 -1
  425. package/dist/tools/report-status.d.ts +33 -0
  426. package/dist/tools/report-status.d.ts.map +1 -0
  427. package/dist/tools/report-status.js +44 -0
  428. package/dist/tools/report-status.js.map +1 -0
  429. package/dist/tools/respond-to-message.d.ts +21 -0
  430. package/dist/tools/respond-to-message.d.ts.map +1 -0
  431. package/dist/tools/respond-to-message.js +23 -0
  432. package/dist/tools/respond-to-message.js.map +1 -0
  433. package/dist/tools/send-files.d.ts +3 -0
  434. package/dist/tools/send-files.d.ts.map +1 -1
  435. package/dist/tools/send-files.js +88 -8
  436. package/dist/tools/send-files.js.map +1 -1
  437. package/dist/tools/send-message.d.ts +27 -0
  438. package/dist/tools/send-message.d.ts.map +1 -0
  439. package/dist/tools/send-message.js +46 -0
  440. package/dist/tools/send-message.js.map +1 -0
  441. package/dist/tools/shutdown-server.d.ts +2 -0
  442. package/dist/tools/shutdown-server.d.ts.map +1 -1
  443. package/dist/tools/shutdown-server.js +19 -0
  444. package/dist/tools/shutdown-server.js.map +1 -1
  445. package/dist/tools/update-member.d.ts +8 -8
  446. package/dist/tools/update-member.d.ts.map +1 -1
  447. package/dist/tools/update-member.js +11 -1
  448. package/dist/tools/update-member.js.map +1 -1
  449. package/dist/types.d.ts +15 -3
  450. package/dist/types.d.ts.map +1 -1
  451. package/dist/utils/agent-helpers.d.ts +2 -1
  452. package/dist/utils/agent-helpers.d.ts.map +1 -1
  453. package/dist/utils/agent-helpers.js +7 -2
  454. package/dist/utils/agent-helpers.js.map +1 -1
  455. package/dist/utils/pid-helpers.d.ts +15 -0
  456. package/dist/utils/pid-helpers.d.ts.map +1 -1
  457. package/dist/utils/pid-helpers.js +23 -0
  458. package/dist/utils/pid-helpers.js.map +1 -1
  459. package/dist/utils/process-utils.d.ts +3 -0
  460. package/dist/utils/process-utils.d.ts.map +1 -0
  461. package/dist/utils/process-utils.js +42 -0
  462. package/dist/utils/process-utils.js.map +1 -0
  463. package/dist/utils/prompt-errors.d.ts +2 -1
  464. package/dist/utils/prompt-errors.d.ts.map +1 -1
  465. package/dist/utils/prompt-errors.js +13 -3
  466. package/dist/utils/prompt-errors.js.map +1 -1
  467. package/dist/utils/workspace-trust.d.ts +24 -0
  468. package/dist/utils/workspace-trust.d.ts.map +1 -0
  469. package/dist/utils/workspace-trust.js +35 -0
  470. package/dist/utils/workspace-trust.js.map +1 -0
  471. package/dist/workflows/auto-sprint.js +450 -87
  472. package/package.json +35 -7
  473. package/packages/apra-fleet-client/package.json +26 -0
  474. package/packages/apra-fleet-client/src/client/api.mjs +396 -0
  475. package/packages/apra-fleet-client/src/client/client.mjs +146 -0
  476. package/packages/apra-fleet-client/src/client/errors.mjs +71 -0
  477. package/packages/apra-fleet-client/src/client/factory.mjs +65 -0
  478. package/packages/apra-fleet-client/src/client/server-resolution.mjs +265 -0
  479. package/packages/apra-fleet-client/src/client/transport.mjs +327 -0
  480. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +287 -0
  481. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +89 -0
  482. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +139 -0
  483. package/packages/apra-fleet-se/apra-pm/agents/doer.md +225 -0
  484. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +169 -0
  485. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +316 -0
  486. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +188 -0
  487. package/packages/apra-fleet-se/apra-pm/agents/planner.md +239 -0
  488. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +216 -0
  489. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +174 -0
  490. package/packages/apra-fleet-se/apra-pm/agents/schemas/backlog-groomer-input.json +35 -0
  491. package/packages/apra-fleet-se/apra-pm/agents/schemas/backlog-groomer-output.json +164 -0
  492. package/packages/apra-fleet-se/apra-pm/agents/schemas/ci-watcher-input.json +26 -0
  493. package/packages/apra-fleet-se/apra-pm/agents/schemas/ci-watcher-output.json +18 -0
  494. package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-input.json +19 -0
  495. package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +17 -0
  496. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-input.json +25 -0
  497. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +22 -0
  498. package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-input.json +31 -0
  499. package/packages/apra-fleet-se/apra-pm/agents/schemas/harvester-output.json +18 -0
  500. package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-input.json +20 -0
  501. package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +61 -0
  502. package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-input.json +15 -0
  503. package/packages/apra-fleet-se/apra-pm/agents/schemas/plan-reviewer-output.json +30 -0
  504. package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-input.json +15 -0
  505. package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-output.json +50 -0
  506. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-input.json +25 -0
  507. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +38 -0
  508. package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +402 -0
  509. package/packages/apra-fleet-se/apra-pm/skills/pm/beads.md +142 -0
  510. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +157 -0
  511. package/packages/apra-fleet-se/apra-pm/skills/pm/doer-reviewer-loop.md +300 -0
  512. package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +121 -0
  513. package/packages/apra-fleet-se/apra-pm/skills/pm/simple-sprint.md +65 -0
  514. package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +327 -0
  515. package/packages/apra-fleet-se/apra-pm/skills/pm/worktrees.md +92 -0
  516. package/packages/apra-fleet-se/apra-pm/version.json +3 -0
  517. package/packages/apra-fleet-se/bin/cli.mjs +857 -0
  518. package/packages/apra-fleet-se/bin/serve.mjs +383 -0
  519. package/packages/apra-fleet-se/fleet-sprint/conflict-ladder.mjs +178 -0
  520. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +914 -0
  521. package/packages/apra-fleet-se/fleet-sprint/dispatch-safety-guard.mjs +177 -0
  522. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +191 -0
  523. package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +151 -0
  524. package/packages/apra-fleet-se/fleet-sprint/docs/dolt-tier2-runbook.md +127 -0
  525. package/packages/apra-fleet-se/fleet-sprint/docs/fleet-sprint-diagram.md +94 -0
  526. package/packages/apra-fleet-se/fleet-sprint/docs/stabilization-log.md +1125 -0
  527. package/packages/apra-fleet-se/fleet-sprint/dolt-literal-guard.mjs +72 -0
  528. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-path-b.mjs +339 -0
  529. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery-tier2.mjs +360 -0
  530. package/packages/apra-fleet-se/fleet-sprint/dolt-recovery.mjs +363 -0
  531. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +1244 -0
  532. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +572 -0
  533. package/packages/apra-fleet-se/fleet-sprint/full-db-fetch-guard.mjs +118 -0
  534. package/packages/apra-fleet-se/fleet-sprint/runner.js +9447 -0
  535. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +103 -0
  536. package/packages/apra-fleet-se/fleet-sprint/sprint-lock.mjs +140 -0
  537. package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +435 -0
  538. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +68 -0
  539. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +53 -0
  540. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/dolt.mjs +146 -0
  541. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/generic-git.mjs +176 -0
  542. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +222 -0
  543. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +218 -0
  544. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +882 -0
  545. package/packages/apra-fleet-se/package.json +28 -0
  546. package/packages/apra-fleet-se/workflow.json +1 -0
  547. package/packages/apra-fleet-workflow/package.json +30 -0
  548. package/packages/apra-fleet-workflow/src/viewer/command-output-cap.mjs +112 -0
  549. package/packages/apra-fleet-workflow/src/viewer/debounced-writer.mjs +153 -0
  550. package/packages/apra-fleet-workflow/src/viewer/html-utils.mjs +31 -0
  551. package/packages/apra-fleet-workflow/src/viewer/index.mjs +1325 -0
  552. package/packages/apra-fleet-workflow/src/viewer/lean-state.mjs +237 -0
  553. package/packages/apra-fleet-workflow/src/viewer/run-state-paths.mjs +130 -0
  554. package/packages/apra-fleet-workflow/src/viewer/sprint-state-paths.mjs +29 -0
  555. package/packages/apra-fleet-workflow/src/workflow/engine.mjs +200 -0
  556. package/packages/apra-fleet-workflow/src/workflow/errors.mjs +146 -0
  557. package/packages/apra-fleet-workflow/src/workflow/index.mjs +1723 -0
  558. package/packages/apra-fleet-workflow/src/workflow/journal.mjs +291 -0
  559. package/packages/apra-fleet-workflow/src/workflow/pricing.mjs +99 -0
  560. package/packages/apra-fleet-workflow/src/workflow/vetting.mjs +111 -0
  561. package/scripts/agy-transcript-reader.js +1 -0
  562. package/scripts/fleet-statusline.sh +17 -13
  563. package/skills/fleet/SKILL.md +37 -2
  564. package/skills/fleet/beads.md +14 -7
  565. package/skills/fleet/permissions.md +50 -0
  566. package/skills/fleet/profiles/base-dev.json +1 -0
  567. package/skills/fleet/profiles/base-reviewer.json +1 -0
  568. package/skills/fleet/profiles/node.json +2 -2
  569. package/version.json +1 -1
  570. package/scripts/agy-settings-merge.js +0 -27
  571. /package/{dist → packages/apra-fleet-se/apra-pm}/agents/_shared/GRAPH-SEMANTICS.md +0 -0
@@ -0,0 +1,237 @@
1
+ // apra-fleet-eft.27.1: lean list-state transform for the dashboard's GET
2
+ // /state endpoint.
3
+ //
4
+ // Problem (apra-fleet-eft.27): a live 449-activity sprint measured a 116 MB
5
+ // GET /state payload per poll (85 MB of it pure duplication -- the same bead
6
+ // descriptions and command outputs embedded again and again by every `bd`
7
+ // command activity). Parsing + rendering that on the main thread produced a
8
+ // 49634 ms long task and made the dashboard effectively unusable.
9
+ //
10
+ // This module is a pure, dependency-free transform: it never touches the
11
+ // live `state` object the viewer mutates in place (src/viewer/index.mjs),
12
+ // nor the full-fidelity snapshots persisted to the configured
13
+ // state-snapshot directory and running/<runId>.json (those stay complete,
14
+ // unchanged, for audit/resume/History-view purposes) -- it only shapes what
15
+ // GET /state sends over the wire for the LIVE polling view.
16
+ //
17
+ // Two independent passes, both fully generic (no extension-specific
18
+ // field/namespace knowledge, so this stays workflow-agnostic per the parent
19
+ // bug's fix direction):
20
+ //
21
+ // 1. leanifyState(): walks state.tree and state.extensions and
22
+ // (a) merges known "heavy" fields (description/output/error/input/
23
+ // transcript/stdout/stderr -- the exact fields the bug's payload
24
+ // anatomy pointed at) into a single short `summary` field, and
25
+ // (b) caps every OTHER remaining string (msg, label, command, ...) at
26
+ // a hard length regardless of field name, as a generic safety net.
27
+ // Descriptions and agent transcripts are therefore never embedded in
28
+ // list state -- only short summaries survive.
29
+ // 2. dedupeStrings(): a second, independent pass that replaces any string
30
+ // value repeated 2+ times anywhere in the (already-leaned) payload with
31
+ // a small `{ $ref: <index> }` marker into a shared `_strings` table
32
+ // sent once, so remaining repeats (e.g. the same short label/member/
33
+ // title appearing on many activities) are never sent twice. Fully
34
+ // reversible via resolveStringRefs() -- the client-side counterpart
35
+ // embedded into the served page (src/viewer/index.mjs HTML_TEMPLATE).
36
+
37
+ export const DEFAULT_SUMMARY_MAX_CHARS = 200;
38
+ export const DEFAULT_MAX_INLINE_STRING_CHARS = 400;
39
+ export const DEFAULT_DEDUP_MIN_LENGTH = 24;
40
+
41
+ // The exact fields the bug's payload anatomy identified as the source of
42
+ // duplication: full bead descriptions and full `bd`/agent command
43
+ // input/output/error text. Checked in this priority order when more than
44
+ // one is present on the same object (e.g. a failed activity carrying both
45
+ // `error` and `output`) -- the most diagnostically useful one wins the
46
+ // single `summary` field.
47
+ export const HEAVY_FIELD_NAMES = ['error', 'output', 'input', 'description', 'transcript', 'stdout', 'stderr'];
48
+
49
+ /** Truncates a string to `maxChars`, appending an ellipsis marker when cut. */
50
+ export function truncate(str, maxChars) {
51
+ if (typeof str !== 'string') return str;
52
+ if (str.length <= maxChars) return str;
53
+ return str.slice(0, maxChars) + '...';
54
+ }
55
+
56
+ // Merges any HEAVY_FIELD_NAMES present on a plain object into a single
57
+ // short `summary` field and deletes the originals. Non-object input, and
58
+ // objects with none of these fields, pass through unchanged (a fresh
59
+ // shallow copy is only made when there's actually something to remove, so
60
+ // this stays cheap on the common case).
61
+ //
62
+ // apra-fleet-eft.38 (reopened): a `command` activity's output/error already
63
+ // carries <field>Truncated + <field>ByteLength markers by the time it gets
64
+ // here (command-output-cap.mjs capped it BEFORE storage, at activity:end --
65
+ // see src/viewer/index.mjs). Every OTHER activity type (most notably `agent`,
66
+ // whose full LLM response text is never capped at storage time, only here at
67
+ // the wire-shaping stage) had no such markers, so the dashboard's 'more...'
68
+ // control had nothing to key off of and never rendered for them. This now
69
+ // stamps the same <field>Truncated/<field>ByteLength pair onto ANY heavy
70
+ // field this function strips down to `summary`, whenever that field's full
71
+ // text does not survive intact inline (either it's a secondary heavy field --
72
+ // e.g. `output` when `error` already claimed the one `summary` slot -- that
73
+ // gets dropped entirely, or it's the summary source itself but longer than
74
+ // the summary cap). GET /activities/:id/output (src/viewer/index.mjs) falls
75
+ // back to the live in-memory state.tree for any id not already in
76
+ // command-output-cap.mjs's own store, so these markers are always backed by
77
+ // a real fetchable full text. Markers a field already carries (the `command`
78
+ // case above) are left untouched, never overwritten with a lesser byte count.
79
+ function summarizeHeavyFields(obj, maxChars) {
80
+ if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return obj;
81
+ const present = HEAVY_FIELD_NAMES.filter((key) =>
82
+ Object.prototype.hasOwnProperty.call(obj, key) && typeof obj[key] === 'string' && obj[key].length > 0
83
+ );
84
+ if (present.length === 0) return obj;
85
+
86
+ const out = { ...obj };
87
+ const summaryKey = present[0];
88
+ const heavyValue = out[summaryKey];
89
+
90
+ for (const key of present) {
91
+ const full = out[key];
92
+ const survivesIntactAsSummary = key === summaryKey && full.length <= maxChars;
93
+ const truncatedKey = `${key}Truncated`;
94
+ const byteLengthKey = `${key}ByteLength`;
95
+ if (!survivesIntactAsSummary && !Object.prototype.hasOwnProperty.call(out, truncatedKey)) {
96
+ out[truncatedKey] = true;
97
+ out[byteLengthKey] = Buffer.byteLength(full, 'utf8');
98
+ }
99
+ delete out[key];
100
+ }
101
+
102
+ if (!Object.prototype.hasOwnProperty.call(out, 'summary')) {
103
+ out.summary = truncate(heavyValue, maxChars);
104
+ }
105
+ return out;
106
+ }
107
+
108
+ function leanifyDeep(value, opts) {
109
+ if (Array.isArray(value)) return value.map((v) => leanifyDeep(v, opts));
110
+ if (value && typeof value === 'object') {
111
+ const summarized = summarizeHeavyFields(value, opts.summaryMaxChars);
112
+ const out = {};
113
+ for (const [k, v] of Object.entries(summarized)) {
114
+ out[k] = leanifyDeep(v, opts);
115
+ }
116
+ return out;
117
+ }
118
+ // Generic safety net: ANY remaining string, under ANY field name
119
+ // (log messages, labels, commands, future extension fields we don't
120
+ // yet know the name of), is capped -- list state must never embed an
121
+ // unbounded blob regardless of what it's called.
122
+ if (typeof value === 'string') return truncate(value, opts.maxInlineStringChars);
123
+ return value;
124
+ }
125
+
126
+ /**
127
+ * Returns a new state object whose `tree` and `extensions` have been
128
+ * stripped of heavy/unbounded string content (see module doc). Every other
129
+ * top-level field (status, stats, runId, ...) is passed through
130
+ * unchanged -- those are already small and fixed-shape.
131
+ *
132
+ * @param {object} state
133
+ * @param {object} [opts]
134
+ * @param {number} [opts.summaryMaxChars]
135
+ * @param {number} [opts.maxInlineStringChars]
136
+ */
137
+ export function leanifyState(state, opts = {}) {
138
+ const summaryMaxChars = opts.summaryMaxChars ?? DEFAULT_SUMMARY_MAX_CHARS;
139
+ const maxInlineStringChars = opts.maxInlineStringChars ?? DEFAULT_MAX_INLINE_STRING_CHARS;
140
+ const walkOpts = { summaryMaxChars, maxInlineStringChars };
141
+ return {
142
+ ...state,
143
+ tree: leanifyDeep(state.tree ?? [], walkOpts),
144
+ extensions: leanifyDeep(state.extensions ?? {}, walkOpts)
145
+ };
146
+ }
147
+
148
+ /**
149
+ * Replaces every string value that occurs 2+ times anywhere within `value`
150
+ * (arrays/objects walked recursively) with a `{ $ref: <index> }` marker into
151
+ * a shared table of unique strings, sent once. Strings shorter than
152
+ * `minLength` are left inline (not worth a reference indirection). Returns
153
+ * `{ value, table }`; `table[$ref]` recovers the original string. Pure and
154
+ * side-effect-free -- safe to call on any JSON-compatible value.
155
+ *
156
+ * @param {any} value
157
+ * @param {object} [opts]
158
+ * @param {number} [opts.minLength]
159
+ */
160
+ export function dedupeStrings(value, opts = {}) {
161
+ const minLength = opts.minLength ?? DEFAULT_DEDUP_MIN_LENGTH;
162
+
163
+ const counts = new Map();
164
+ (function count(v) {
165
+ if (Array.isArray(v)) { v.forEach(count); return; }
166
+ if (v && typeof v === 'object') { Object.values(v).forEach(count); return; }
167
+ if (typeof v === 'string' && v.length >= minLength) {
168
+ counts.set(v, (counts.get(v) || 0) + 1);
169
+ }
170
+ })(value);
171
+
172
+ const table = [];
173
+ const indexOf = new Map();
174
+ function refFor(str) {
175
+ if (indexOf.has(str)) return indexOf.get(str);
176
+ const idx = table.length;
177
+ table.push(str);
178
+ indexOf.set(str, idx);
179
+ return idx;
180
+ }
181
+
182
+ function replace(v) {
183
+ if (Array.isArray(v)) return v.map(replace);
184
+ if (v && typeof v === 'object') {
185
+ const out = {};
186
+ for (const [k, val] of Object.entries(v)) out[k] = replace(val);
187
+ return out;
188
+ }
189
+ if (typeof v === 'string' && v.length >= minLength && (counts.get(v) || 0) >= 2) {
190
+ return { $ref: refFor(v) };
191
+ }
192
+ return v;
193
+ }
194
+
195
+ return { value: replace(value), table };
196
+ }
197
+
198
+ /**
199
+ * Inverse of dedupeStrings(): walks `value`, replacing every
200
+ * `{ $ref: <index> }` marker with `table[<index>]`. A plain object/array
201
+ * containing no such markers (e.g. a frozen History-view state that never
202
+ * went through dedupeStrings()) round-trips unchanged, so this is always
203
+ * safe to apply defensively. This exact source is embedded verbatim into
204
+ * the served page's client-side <script> (via .toString(), the same
205
+ * pattern html-utils.mjs's escapeHtml() uses) so the browser can undo the
206
+ * same transform.
207
+ *
208
+ * @param {any} value
209
+ * @param {Array<string>} table
210
+ */
211
+ export function resolveStringRefs(value, table) {
212
+ if (Array.isArray(value)) return value.map((v) => resolveStringRefs(v, table));
213
+ if (value && typeof value === 'object') {
214
+ const keys = Object.keys(value);
215
+ if (keys.length === 1 && keys[0] === '$ref' && typeof value.$ref === 'number') {
216
+ return table[value.$ref];
217
+ }
218
+ const out = {};
219
+ for (const [k, v] of Object.entries(value)) out[k] = resolveStringRefs(v, table);
220
+ return out;
221
+ }
222
+ return value;
223
+ }
224
+
225
+ /**
226
+ * Convenience one-shot: leanify then dedupe, returning a single
227
+ * JSON.stringify-ready object (the shared string table is embedded under
228
+ * `_strings`). This is what GET /state serves.
229
+ *
230
+ * @param {object} state
231
+ * @param {object} [opts] - forwarded to leanifyState()/dedupeStrings().
232
+ */
233
+ export function buildListStatePayload(state, opts = {}) {
234
+ const leaned = leanifyState(state, opts);
235
+ const { value, table } = dedupeStrings(leaned, opts);
236
+ return { ...value, _strings: table };
237
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * apra-fleet-eft.2.3 (renamed under eft.37.1): path resolution for the
3
+ * continuous per-run state file, keyed by run id (NOT the HHMMSS key used by
4
+ * the crash-safety snapshot net, which collides across days -- see
5
+ * src/viewer/index.mjs persistState()).
6
+ *
7
+ * This module is domain-neutral core: it knows about "workflow runs", not
8
+ * about the auto-sprint domain. auto-sprint is one workflow that happens to
9
+ * run on top of it.
10
+ *
11
+ * Layout, under the SERVICE data directory (never the repo checkout, so a
12
+ * `git status`/`git clean` in the working tree never touches it):
13
+ * <serviceDataDir>/running/<runId>.json - live run, in-place overwrite
14
+ * <serviceDataDir>/old_runs/<runId>.json - terminal run, moved (not copied) here
15
+ *
16
+ * `<serviceDataDir>` reuses the SAME ~/.apra-fleet/data convention (honoring
17
+ * APRA_FLEET_DATA_DIR) as the fleet client's server-resolution module, so
18
+ * there is exactly one "where does apra-fleet keep its runtime state" answer
19
+ * across the whole codebase rather than a second, viewer-local one.
20
+ */
21
+ import path from 'node:path';
22
+ import fs from 'node:fs';
23
+ import { getFleetDataDir } from '@apralabs/apra-fleet-client/server-resolution';
24
+
25
+ /** @returns {string} <serviceDataDir>/running -- live, in-place-overwritten run state files. */
26
+ export function getRunningRunsDir(env = process.env) {
27
+ return path.join(getFleetDataDir(env), 'running');
28
+ }
29
+
30
+ /** @returns {string} <serviceDataDir>/old_runs -- terminal run state files, moved (not copied) here. */
31
+ export function getOldRunsDir(env = process.env) {
32
+ return path.join(getFleetDataDir(env), 'old_runs');
33
+ }
34
+
35
+ /**
36
+ * apra-fleet-4ul / apra-fleet-cvb.3: sanitize a runId for use as a SINGLE
37
+ * flat filename component. A path separator in `runId` (e.g. a branch-name-
38
+ * shaped runId like 'fix/fleet-sprint-stabilization' -- the pre-k7b.1
39
+ * fallback for a launch with no supervisor-minted sprintId) previously
40
+ * nested straight through an unsanitized `path.join`, so
41
+ * `old_runs/<runId>.json` silently became a NESTED
42
+ * `old_runs/fix/fleet-sprint-stabilization.json` instead of a flat file at
43
+ * the path every reader (watchdog.mjs's hasTerminalState(), this module's
44
+ * own getTerminalRunStatePath() reader branch) actually checks -- causing a
45
+ * cleanly-finished sprint to misclassify as CRASHED (apra-fleet-4ul).
46
+ *
47
+ * This is a defense-in-depth BACKSTOP at the lowest layer that turns a runId
48
+ * into a filename: every current launch/relaunch path already keys off the
49
+ * ledger's own sprintId (apra-fleet-k7b.1, src/supervisor/api.mjs's
50
+ * launch()), never a branch name, but this guarantees NO caller -- current
51
+ * or future, this module or a caller three layers up -- can ever again
52
+ * write a nested old_runs//running file, regardless of what string it
53
+ * passes as runId.
54
+ * @param {string} runId
55
+ * @returns {string} `runId` with every '/' or '\' replaced by '_'.
56
+ */
57
+ export function sanitizeRunIdForFilename(runId) {
58
+ return String(runId).replace(/[\\/]+/g, '_');
59
+ }
60
+
61
+ /**
62
+ * @param {string} runId - stable per-run id (e.g. a caller-supplied runId or a
63
+ * generated UUID), NOT an HHMMSS-style clock key, which collides across two
64
+ * runs started in the same second on different days.
65
+ * @returns {string} path to the run's live state file: <serviceDataDir>/running/<runId>.json
66
+ * (runId is sanitized -- apra-fleet-4ul/cvb.3 -- so this is always a FLAT
67
+ * file directly under running/, never nested).
68
+ */
69
+ export function getRunningRunStatePath(runId, env = process.env) {
70
+ if (!runId) {
71
+ throw new TypeError('getRunningRunStatePath requires a runId');
72
+ }
73
+ return path.join(getRunningRunsDir(env), `${sanitizeRunIdForFilename(runId)}.json`);
74
+ }
75
+
76
+ /**
77
+ * Resolve the terminal-state file path for a run.
78
+ *
79
+ * As a READER: returns the existing file, checking old_runs/ first (by the
80
+ * SANITIZED, always-flat key -- every write this module itself performs
81
+ * lands there) and then falling back to the legacy directory (read-only) so
82
+ * history for runs that terminated before this rename still loads.
83
+ *
84
+ * apra-fleet-4ul / apra-fleet-cvb.3: as a FINAL read-only fallback, also
85
+ * checks the raw, UNSANITIZED path built directly from `runId` -- this is
86
+ * what makes a pre-existing, already-on-disk LEGACY terminal record (written
87
+ * before this sanitize existed, under a slash-nested branch-name key) still
88
+ * discoverable, so a sprint that actually finished cleanly under one of
89
+ * those legacy runIds keeps classifying FINISHED, not CRASHED. Only
90
+ * consulted when the raw runId actually differs from its sanitized form (a
91
+ * normal, separator-free runId has no legacy nested variant to check, so
92
+ * this adds no extra fs.existsSync for the common case).
93
+ *
94
+ * As a WRITE target: for a fresh runId neither location exists yet, so this
95
+ * returns the canonical, SANITIZED old_runs/<runId>.json destination -- new
96
+ * terminal writes always land in old_runs/ as a flat file, never nested and
97
+ * never in the legacy directory.
98
+ *
99
+ * @param {string} runId
100
+ * @returns {string} path to the run's terminal state file.
101
+ */
102
+ export function getTerminalRunStatePath(runId, env = process.env) {
103
+ if (!runId) {
104
+ throw new TypeError('getTerminalRunStatePath requires a runId');
105
+ }
106
+ const safeRunId = sanitizeRunIdForFilename(runId);
107
+ const oldRunsPath = path.join(getOldRunsDir(env), `${safeRunId}.json`);
108
+ if (fs.existsSync(oldRunsPath)) {
109
+ return oldRunsPath;
110
+ }
111
+ // BOUNDARY-COMPAT: terminal run state written by pre-runId releases lives
112
+ // under the legacy old_sprints/ directory. Resolve it read-only so history
113
+ // for runs that terminated before this rename still loads; this branch
114
+ // never creates or writes that directory -- fresh terminal writes always
115
+ // go to old_runs/ (returned below). Remove one release after the se
116
+ // consumers stop producing legacy files.
117
+ const legacyTerminalPath = path.join(getFleetDataDir(env), 'old_sprints', `${safeRunId}.json`);
118
+ if (fs.existsSync(legacyTerminalPath)) {
119
+ return legacyTerminalPath;
120
+ }
121
+ // apra-fleet-4ul / apra-fleet-cvb.3: legacy, pre-sanitize nested write --
122
+ // see this function's doc comment above.
123
+ if (safeRunId !== runId) {
124
+ const legacyNestedOldRunsPath = path.join(getOldRunsDir(env), `${runId}.json`);
125
+ if (fs.existsSync(legacyNestedOldRunsPath)) {
126
+ return legacyNestedOldRunsPath;
127
+ }
128
+ }
129
+ return oldRunsPath;
130
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * BOUNDARY-COMPAT (apra-fleet-eft.37.1 / M1a): thin re-export shim for the
3
+ * pre-runId subpath '@apralabs/apra-fleet-workflow/viewer/sprint-state-paths'.
4
+ *
5
+ * The domain-neutral implementation now lives in run-state-paths.mjs and speaks
6
+ * "runs" (getRunningRunStatePath/getTerminalRunStatePath) instead of "sprints".
7
+ * This module keeps the old subpath and the old sprint-named exports resolvable
8
+ * so the apra-fleet-se supervisor consumers (watchdog/proxy/history-view) keep
9
+ * working until M1b (eft.37.2) migrates them to the run-state-paths API. Delete
10
+ * this shim once eft.37.2 lands and no consumer imports the sprint-* names.
11
+ */
12
+ import {
13
+ getRunningRunsDir,
14
+ getOldRunsDir,
15
+ getRunningRunStatePath,
16
+ getTerminalRunStatePath,
17
+ } from './run-state-paths.mjs';
18
+
19
+ /** @deprecated use getRunningRunsDir from run-state-paths.mjs */
20
+ export const getRunningSprintsDir = getRunningRunsDir;
21
+
22
+ /** @deprecated use getOldRunsDir from run-state-paths.mjs */
23
+ export const getOldSprintsDir = getOldRunsDir;
24
+
25
+ /** @deprecated use getRunningRunStatePath from run-state-paths.mjs */
26
+ export const getRunningSprintStatePath = getRunningRunStatePath;
27
+
28
+ /** @deprecated use getTerminalRunStatePath from run-state-paths.mjs */
29
+ export const getOldSprintStatePath = getTerminalRunStatePath;
@@ -0,0 +1,200 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+ import { pathToFileURL } from 'url';
4
+ import { randomUUID } from 'crypto';
5
+ import { VettingEngine } from './vetting.mjs';
6
+ import { JournalWriter, loadJournal, resolveJournalWritePath } from './journal.mjs';
7
+
8
+ /**
9
+ * Loads and runs user-authored workflow scripts.
10
+ *
11
+ * TRUST MODEL: workflow scripts are TRUSTED code. They are loaded as real ES
12
+ * modules via dynamic `import()` and execute with full Node.js privileges
13
+ * (filesystem, network, child processes, `process.env`, dynamic `import()`,
14
+ * etc.) -- there is no sandbox. Only run scripts you trust, the same way you
15
+ * would trust any other Node.js module you `import`. See
16
+ * docs/apra-fleet-workflow-architecture.md section 3 for details.
17
+ * `VettingEngine` (vetting.mjs) is an advisory lint that surfaces
18
+ * risky-looking patterns as warnings; it is NOT a security boundary and does
19
+ * not block execution unless a caller explicitly opts into strict mode.
20
+ */
21
+ export class WorkflowEngine {
22
+ /**
23
+ * @param {import('./index.mjs').FleetWorkflow} workflowApi
24
+ */
25
+ constructor(workflowApi) {
26
+ this.wf = workflowApi;
27
+ this.vetting = new VettingEngine();
28
+ }
29
+
30
+ /**
31
+ * Load a workflow script as a real ES module and run it.
32
+ *
33
+ * The module must export an entry point function as one of `main`,
34
+ * `run`, or `default` (checked in that order) -- this is the
35
+ * standardized pattern all workflow scripts in this repo (examples/*,
36
+ * auto-sprint's runner.js, test fixtures) follow. The entry point is
37
+ * invoked with a single `context` argument (the object returned by
38
+ * `workflowApi.createContext()`), exposing `agent`, `command`,
39
+ * `parallel`, `sequential`, `pipeline`, `transform`, `log`, `phase`,
40
+ * `group`, `endGroup`, `publishState`, `args`, `budget`, etc. Scripts
41
+ * access these via the `context` parameter (e.g.
42
+ * `export async function main(context) { const { agent, log } = context; ... }`)
43
+ * rather than via injected bare globals -- there is no global injection
44
+ * anymore now that scripts are real ES modules.
45
+ *
46
+ * @param {string} scriptPath
47
+ * @param {any} args
48
+ * @param {boolean|{strictVetting?: boolean, journal?: boolean|string|{path:string}, resumeJournal?: string}} [vettingOpts] -
49
+ * Either a plain options object, or -- for backward compatibility with
50
+ * the old `forceOverrideRisk` boolean parameter -- a boolean, which is
51
+ * now a no-op (vetting never blocks by default, so there is nothing
52
+ * left to "force override"). Recognized object fields:
53
+ * - `strictVetting` (boolean): opts in to blocking execution of
54
+ * high-risk scripts.
55
+ * - `journal` (apra-fleet-unw.11, F6): opts in to persisting this run's
56
+ * `activity:start`/`activity:end`/`end` events as an append-only
57
+ * JSONL journal (see journal.mjs). `true` -> default path
58
+ * `.fleet-workflow/journal-<runId>.jsonl`; a string or
59
+ * `{ path: string }` -> explicit path. OFF BY DEFAULT: omitting this
60
+ * (and `resumeJournal`) produces zero journal-related I/O and zero
61
+ * change to emitted event shapes.
62
+ * - `resumeJournal` (string path): resumes a previous (possibly
63
+ * crashed) run from an existing journal file. For each
64
+ * `agent()`/`command()` call, a deterministic activity key (sequence
65
+ * index within the run + call type + a hash of the dispatched
66
+ * prompt/command text + member) is looked up in the journal; a
67
+ * matching COMPLETED (successful) record is returned directly
68
+ * without dispatching to the fleet. The FIRST mismatch or missing
69
+ * entry stops replay and switches to live execution from that point
70
+ * onward (partial replay, not all-or-nothing -- Claude-CLI style).
71
+ * Journal records that were started but never finished (a crash
72
+ * mid-dispatch) are surfaced via a `journal:ambiguous` event and a
73
+ * console warning as possibly-double-dispatched; they are never
74
+ * auto-resolved (true idempotency requires fleet-server-side keys,
75
+ * descoped -- see plan.md). Unless `journal` is also given, the
76
+ * resumed run continues writing to the SAME file it resumed from.
77
+ */
78
+ async executeFile(scriptPath, args = {}, vettingOpts = {}) {
79
+ const fullPath = path.resolve(scriptPath);
80
+ const opts = typeof vettingOpts === 'boolean' ? {} : (vettingOpts || {});
81
+ const strictVetting = typeof vettingOpts === 'boolean' ? false : !!opts.strictVetting;
82
+
83
+ const source = await fs.readFile(fullPath, 'utf-8');
84
+ const vettingResult = await this.vetting.assessRisk(source);
85
+ if (vettingResult.riskScore > 0) {
86
+ console.warn(`[VettingEngine] Script flagged with risk score ${vettingResult.riskScore}/100 (advisory only -- workflow scripts run with full Node privileges and must be trusted; see docs/apra-fleet-workflow-architecture.md).`);
87
+ vettingResult.warnings.forEach(w => console.warn(` - WARNING: ${w}`));
88
+
89
+ if (strictVetting && vettingResult.riskScore > 50) {
90
+ throw new Error(`Workflow script rejected by VettingEngine in strict mode (Risk: ${vettingResult.riskScore}). Vetting is advisory-only by default (not a security boundary); pass { strictVetting: true } only if you want this check to be enforced.`);
91
+ }
92
+ }
93
+
94
+ const moduleUrl = pathToFileURL(fullPath).href;
95
+ const mod = await import(moduleUrl);
96
+
97
+ const entry = mod.main || mod.run || mod.default;
98
+ if (typeof entry !== 'function') {
99
+ throw new Error(`[WorkflowEngine] ${fullPath} does not export a main(context)/run(context)/default(context) function. Workflow scripts must export one of these as their entry point.`);
100
+ }
101
+
102
+ // (apra-fleet-unw.9, F11) Each executeFile() call gets its own
103
+ // isolated per-run context -- args, phase, group, budget -- via
104
+ // FleetWorkflow.runWithContext(), instead of mutating shared
105
+ // `this.wf.args`/`this.wf.currentPhase` instance state. This is what
106
+ // makes two concurrent executeFile() calls against the same
107
+ // FleetWorkflow instance safe: they no longer stomp on each other's
108
+ // args or phase attribution. See the runStorage comment in
109
+ // src/workflow/index.mjs for the full mechanism.
110
+ //
111
+ // (apra-fleet-unw.10) A `runId` is generated here (rather than left
112
+ // to runWithContext()'s internal default) so it's known up front and
113
+ // can be attached to the `end` event emitted from the `finally`
114
+ // block below on BOTH the success and failure/throw paths -- this is
115
+ // what lets the dashboard viewer (src/viewer/index.mjs) finally
116
+ // leave its perpetual "LIVE" state and transition to DONE/FAILED,
117
+ // and is also the runId a script's own `requestStop()`-triggered
118
+ // CancelledError (errors.mjs) will carry.
119
+ const runId = randomUUID();
120
+
121
+ // (apra-fleet-unw.11, F6) Journal setup. `journalEnabled` gates
122
+ // EVERYTHING journal-related in FleetWorkflow (the per-run activity
123
+ // sequence counter, replay-key computation) so that a normal call
124
+ // with neither `journal` nor `resumeJournal` set is byte-for-byte
125
+ // identical, in behavior and in emitted event shape, to before this
126
+ // feature existed (acceptance criterion #4).
127
+ const journalEnabled = !!(opts.journal || opts.resumeJournal);
128
+ let replay = null;
129
+ if (opts.resumeJournal) {
130
+ const resumePath = path.resolve(opts.resumeJournal);
131
+ const loaded = await loadJournal(resumePath);
132
+ replay = { completedByKey: loaded.completedByKey, diverged: false };
133
+
134
+ // Ambiguity guard: surface (never auto-resolve) any activity
135
+ // that was dispatched but never recorded as finished in the
136
+ // journal being resumed from -- most likely because the prior
137
+ // run crashed mid-dispatch. True idempotency requires
138
+ // fleet-server-side keys and is explicitly descoped (plan.md).
139
+ for (const ambiguousRecord of loaded.ambiguous) {
140
+ console.warn(
141
+ `[Journal] Ambiguous activity from a previous run (started but never recorded as finished -- ` +
142
+ `possibly double-dispatched on resume): id=${ambiguousRecord.id} type=${ambiguousRecord.type} ` +
143
+ `member=${ambiguousRecord.member} label=${ambiguousRecord.label || 'none'}`
144
+ );
145
+ this.wf.emit('journal:ambiguous', { runId, resumedFrom: resumePath, activity: ambiguousRecord });
146
+ }
147
+ }
148
+
149
+ const journalWritePath = journalEnabled ? resolveJournalWritePath(opts, runId) : null;
150
+ let journalWriter = null;
151
+ if (journalWritePath) {
152
+ journalWriter = new JournalWriter(this.wf, { runId, filePath: journalWritePath });
153
+ await journalWriter.init();
154
+ await journalWriter.writeRunStart({ scriptPath: fullPath, args });
155
+ }
156
+
157
+ let status = 'success';
158
+ let result;
159
+ let error;
160
+ try {
161
+ result = await this.wf.runWithContext(args, entry, { runId, journalEnabled, replay });
162
+ return result;
163
+ } catch (err) {
164
+ console.error('[WorkflowEngine] Execution Failed:', err);
165
+ error = err;
166
+ status = err && err.code === 'CANCELLED' ? 'cancelled' : 'failed';
167
+ throw err;
168
+ } finally {
169
+ this.wf.emit('end', {
170
+ runId,
171
+ status,
172
+ result: status === 'success' ? result : undefined,
173
+ error: error
174
+ ? { message: error.message, code: error.code, name: error.name }
175
+ : undefined
176
+ });
177
+ if (journalWriter) {
178
+ await journalWriter.close();
179
+ }
180
+ }
181
+ }
182
+
183
+ /**
184
+ * REMOVED: inline-string execution. Workflow scripts are now loaded as
185
+ * real ES modules via `import()`, which requires an actual module (a
186
+ * file on disk, or a `data:`/`blob:` URL you construct yourself) rather
187
+ * than an arbitrary source string handed to an `AsyncFunction`
188
+ * constructor -- that constructor-based path (and the export-stripping
189
+ * regex it depended on) has been removed entirely. Write the script to a
190
+ * file and call `executeFile(path, args)` instead.
191
+ */
192
+ async executeSource() {
193
+ throw new Error(
194
+ '[WorkflowEngine] executeSource() has been removed: workflow scripts are now loaded as real ES ' +
195
+ 'modules via import(), which requires an actual module (a file, or a data:/blob: URL you construct ' +
196
+ 'yourself) rather than an inline source string. Write the script to a file and call ' +
197
+ 'executeFile(path, args) instead.'
198
+ );
199
+ }
200
+ }