vgxness 1.20.4 → 1.20.6

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 (375) hide show
  1. package/dist/adapters/claude/agent-renderer.js +82 -0
  2. package/dist/{mcp → adapters/claude/install}/claude-code-agent-config.js +64 -9
  3. package/dist/{mcp → adapters/claude/install}/claude-code-config.js +28 -6
  4. package/dist/{mcp → adapters/claude/install}/claude-code-project-memory.js +35 -5
  5. package/dist/{mcp → adapters/claude/install}/claude-code-scope.js +12 -3
  6. package/dist/{mcp → adapters/claude/install}/claude-code-user-config.js +26 -5
  7. package/dist/{mcp → adapters/claude/install}/claude-code-user-memory.js +47 -7
  8. package/dist/{mcp → adapters/claude/install}/client-install-claude-code-contract.js +45 -8
  9. package/dist/{mcp → adapters/claude/install}/client-install-claude-code.js +98 -14
  10. package/dist/adapters/json/agent-renderer.js +104 -0
  11. package/dist/adapters/opencode/agent-renderer.js +113 -0
  12. package/dist/{mcp → adapters/opencode/install}/client-install-opencode-contract.js +2 -2
  13. package/dist/{mcp → adapters/opencode/install}/client-install-opencode.js +1 -1
  14. package/dist/{mcp → adapters/opencode/install}/opencode-default-agent-config.js +2 -2
  15. package/dist/{mcp → adapters/opencode/install}/opencode-handoff-preview.js +60 -7
  16. package/dist/{mcp → adapters/opencode/install}/opencode-visibility.js +1 -1
  17. package/dist/adapters/provider-renderer.js +6 -0
  18. package/dist/agents/agent-activation-service.js +1 -263
  19. package/dist/agents/agent-lookup-contexts.js +1 -28
  20. package/dist/agents/agent-registry-service.js +1 -81
  21. package/dist/agents/agent-resolver.js +1 -287
  22. package/dist/agents/agent-seed-service.js +1 -157
  23. package/dist/agents/agent-seed-upgrade-service.js +1 -231
  24. package/dist/agents/agent-selector-resolver.js +1 -28
  25. package/dist/agents/boot-upgrade.js +1 -59
  26. package/dist/agents/canonical-agent-manifest.js +1 -245
  27. package/dist/agents/canonical-agent-projection.js +1 -236
  28. package/dist/agents/manager-profile-overlay-service.js +1 -60
  29. package/dist/agents/profile-model-routing.js +1 -30
  30. package/dist/agents/renderers/claude-renderer.js +1 -82
  31. package/dist/agents/renderers/index.js +1 -14
  32. package/dist/agents/renderers/json-renderer.js +1 -104
  33. package/dist/agents/renderers/opencode-renderer.js +1 -113
  34. package/dist/agents/renderers/provider-adapter.js +1 -6
  35. package/dist/agents/repositories/agent-seed-history.js +1 -128
  36. package/dist/agents/repositories/agents.js +1 -200
  37. package/dist/agents/repositories/manager-profile-overlays.js +1 -90
  38. package/dist/agents/schema.js +1 -1
  39. package/dist/application/agents/agent-activation-service.js +261 -0
  40. package/dist/application/agents/agent-lookup-contexts.js +28 -0
  41. package/dist/application/agents/agent-registry-service.js +81 -0
  42. package/dist/application/agents/agent-resolver.js +287 -0
  43. package/dist/application/agents/agent-seed-service.js +157 -0
  44. package/dist/application/agents/agent-seed-upgrade-service.js +231 -0
  45. package/dist/application/agents/agent-selector-resolver.js +28 -0
  46. package/dist/application/agents/boot-upgrade.js +59 -0
  47. package/dist/application/agents/canonical-agent-projection.js +236 -0
  48. package/dist/application/agents/manager-profile-overlay-service.js +68 -0
  49. package/dist/application/agents/profile-model-routing.js +30 -0
  50. package/dist/application/agents/renderers/claude-renderer.js +1 -0
  51. package/dist/application/agents/renderers/index.js +14 -0
  52. package/dist/application/agents/renderers/json-renderer.js +1 -0
  53. package/dist/application/agents/renderers/opencode-renderer.js +1 -0
  54. package/dist/application/agents/renderers/provider-adapter.js +1 -0
  55. package/dist/application/memory/active-work-preview.js +75 -0
  56. package/dist/application/memory/agent-memory-capture-service.js +498 -0
  57. package/dist/application/memory/import/dry-run-planner.js +58 -0
  58. package/dist/application/memory/import/index.js +3 -0
  59. package/dist/application/memory/import/observation-writer.js +226 -0
  60. package/dist/application/memory/import/package.js +179 -0
  61. package/dist/application/memory/memory-service.js +202 -0
  62. package/dist/application/memory/search.js +11 -0
  63. package/dist/{mcp → application/provider-setup}/provider-change-plan.js +74 -13
  64. package/dist/{mcp → application/provider-setup}/provider-doctor.js +201 -31
  65. package/dist/{mcp → application/provider-setup}/provider-health-types.js +1 -1
  66. package/dist/{mcp → application/provider-setup}/provider-status.js +170 -33
  67. package/dist/application/runs/execution-planning.js +180 -0
  68. package/dist/application/runs/operation-execution.js +1 -0
  69. package/dist/application/runs/operation-retry.js +129 -0
  70. package/dist/application/runs/resume-after-approval-result.js +88 -0
  71. package/dist/application/runs/run-insights.js +270 -0
  72. package/dist/application/runs/run-service.js +1480 -0
  73. package/dist/application/runs/run-snapshot-export-service.js +31 -0
  74. package/dist/application/runs/sandbox-process-execution.js +244 -0
  75. package/dist/application/runs/sandbox-worktree-planning.js +59 -0
  76. package/dist/application/runs/task-scoped-command-grant-service.js +224 -0
  77. package/dist/application/sdd/artifact-portability-service.js +137 -0
  78. package/dist/application/sdd/cockpit-read-model.js +195 -0
  79. package/dist/application/sdd/sdd-continuation-plan.js +265 -0
  80. package/dist/application/sdd/sdd-workflow-service.js +892 -0
  81. package/dist/application/skills/boot-seed.js +42 -0
  82. package/dist/application/skills/personal-skills.js +41 -0
  83. package/dist/application/skills/skill-export-service.js +34 -0
  84. package/dist/application/skills/skill-index-service.js +126 -0
  85. package/dist/application/skills/skill-payload.js +186 -0
  86. package/dist/application/skills/skill-registry-service.js +648 -0
  87. package/dist/application/skills/skill-resolver.js +368 -0
  88. package/dist/application/skills/skill-seed-service.js +242 -0
  89. package/dist/application/skills/skill-status-service.js +147 -0
  90. package/dist/cli/bun-bin.js +0 -0
  91. package/dist/cli/cli-flags.js +1 -387
  92. package/dist/cli/cli-help.js +1 -173
  93. package/dist/cli/cli-helpers.js +1 -77
  94. package/dist/cli/cli-types.js +1 -1
  95. package/dist/cli/commands/agent-skill-dispatcher.js +1 -700
  96. package/dist/cli/commands/index.js +1 -9
  97. package/dist/cli/commands/interactive-entrypoint-dispatcher.js +1 -14
  98. package/dist/cli/commands/mcp-dispatcher.js +1 -232
  99. package/dist/cli/commands/memory-sdd-dispatcher.js +1 -367
  100. package/dist/cli/commands/run-permission-dispatcher.js +1 -455
  101. package/dist/cli/commands/setup-dispatcher.js +1 -496
  102. package/dist/cli/commands/status-dispatcher.js +1 -130
  103. package/dist/cli/commands/verification-dispatcher.js +1 -47
  104. package/dist/cli/commands/workflow-dispatcher.js +1 -566
  105. package/dist/cli/dispatcher.js +1 -247
  106. package/dist/cli/doctor-renderer.js +1 -26
  107. package/dist/cli/home-tui-app.js +1 -411
  108. package/dist/cli/home-tui-controller.js +1 -314
  109. package/dist/cli/mcp-start-path.js +1 -21
  110. package/dist/cli/product-resume-renderer.js +1 -32
  111. package/dist/cli/product-status-renderer.js +1 -81
  112. package/dist/cli/sdd-renderer.js +1 -247
  113. package/dist/cli/setup-plan-renderer.js +1 -79
  114. package/dist/cli/setup-status-renderer.js +1 -50
  115. package/dist/cli/setup-tui-app.js +1 -130
  116. package/dist/cli/setup-tui-controller.js +1 -89
  117. package/dist/cli/tui/focus-reducer.js +1 -0
  118. package/dist/cli/tui/focus-types.js +1 -0
  119. package/dist/cli/tui/ink/app-shell.js +1 -0
  120. package/dist/cli/tui/ink/components.js +1 -38
  121. package/dist/cli/tui/ink/help-overlay.js +1 -0
  122. package/dist/cli/tui/ink/state-components.js +1 -0
  123. package/dist/cli/tui/ink/theme.js +1 -36
  124. package/dist/cli/tui/key-intents.js +1 -0
  125. package/dist/cli/tui/keymap.js +1 -20
  126. package/dist/cli/tui/navigation.js +1 -10
  127. package/dist/cli/tui/screen-registry.js +1 -0
  128. package/dist/cli/tui/terminal-capabilities.js +1 -12
  129. package/dist/cli/tui/tui-types.js +1 -1
  130. package/dist/cli/tui/visual/badges.js +1 -19
  131. package/dist/cli/tui/visual/footer.js +1 -27
  132. package/dist/cli/tui/visual/index.js +1 -3
  133. package/dist/cli/tui/visual/viewport.js +1 -11
  134. package/dist/cli/tui-render-helpers.js +1 -200
  135. package/dist/cli/verification-plan-renderer.js +1 -25
  136. package/dist/cli/verification-report-renderer.js +1 -19
  137. package/dist/domain/agents/canonical-agent-manifest.js +355 -0
  138. package/dist/domain/agents/schema.js +1 -0
  139. package/dist/domain/memory/active-work-topics.js +64 -0
  140. package/dist/domain/memory/memory-capture-schema.js +1 -0
  141. package/dist/domain/memory/schema.js +1 -0
  142. package/dist/domain/runs/schema.js +5 -0
  143. package/dist/domain/sdd/cockpit-types.js +1 -0
  144. package/dist/domain/sdd/schema.js +111 -0
  145. package/dist/domain/skills/schema.js +1 -0
  146. package/dist/governance/risk-classifier.js +2 -0
  147. package/dist/interfaces/cli/bun-bin.js +46 -0
  148. package/dist/interfaces/cli/cli-flags.js +391 -0
  149. package/dist/interfaces/cli/cli-help.js +173 -0
  150. package/dist/interfaces/cli/cli-helpers.js +77 -0
  151. package/dist/interfaces/cli/cli-types.js +1 -0
  152. package/dist/interfaces/cli/commands/agent-skill-dispatcher.js +700 -0
  153. package/dist/interfaces/cli/commands/index.js +9 -0
  154. package/dist/interfaces/cli/commands/interactive-entrypoint-dispatcher.js +14 -0
  155. package/dist/interfaces/cli/commands/mcp-dispatcher.js +252 -0
  156. package/dist/interfaces/cli/commands/memory-sdd-dispatcher.js +367 -0
  157. package/dist/interfaces/cli/commands/run-permission-dispatcher.js +460 -0
  158. package/dist/interfaces/cli/commands/setup-dispatcher.js +496 -0
  159. package/dist/interfaces/cli/commands/status-dispatcher.js +130 -0
  160. package/dist/interfaces/cli/commands/verification-dispatcher.js +47 -0
  161. package/dist/interfaces/cli/commands/workflow-dispatcher.js +566 -0
  162. package/dist/interfaces/cli/dispatcher.js +247 -0
  163. package/dist/interfaces/cli/doctor-renderer.js +26 -0
  164. package/dist/interfaces/cli/home-tui-app.js +462 -0
  165. package/dist/interfaces/cli/home-tui-controller.js +341 -0
  166. package/dist/interfaces/cli/index.js +27 -0
  167. package/dist/interfaces/cli/mcp-start-path.js +21 -0
  168. package/dist/interfaces/cli/product-resume-renderer.js +32 -0
  169. package/dist/interfaces/cli/product-status-renderer.js +81 -0
  170. package/dist/interfaces/cli/sdd-renderer.js +247 -0
  171. package/dist/interfaces/cli/setup-plan-renderer.js +79 -0
  172. package/dist/interfaces/cli/setup-status-renderer.js +50 -0
  173. package/dist/interfaces/cli/setup-tui-app.js +135 -0
  174. package/dist/interfaces/cli/setup-tui-controller.js +89 -0
  175. package/dist/interfaces/cli/tui/focus-reducer.js +60 -0
  176. package/dist/interfaces/cli/tui/focus-types.js +10 -0
  177. package/dist/interfaces/cli/tui/ink/app-shell.js +16 -0
  178. package/dist/interfaces/cli/tui/ink/components.js +38 -0
  179. package/dist/interfaces/cli/tui/ink/help-overlay.js +6 -0
  180. package/dist/interfaces/cli/tui/ink/state-components.js +22 -0
  181. package/dist/interfaces/cli/tui/ink/theme.js +36 -0
  182. package/dist/interfaces/cli/tui/key-intents.js +33 -0
  183. package/dist/interfaces/cli/tui/keymap.js +20 -0
  184. package/dist/interfaces/cli/tui/navigation.js +10 -0
  185. package/dist/interfaces/cli/tui/screen-registry.js +43 -0
  186. package/dist/interfaces/cli/tui/terminal-capabilities.js +12 -0
  187. package/dist/interfaces/cli/tui/tui-types.js +1 -0
  188. package/dist/interfaces/cli/tui/visual/badges.js +19 -0
  189. package/dist/interfaces/cli/tui/visual/footer.js +27 -0
  190. package/dist/interfaces/cli/tui/visual/index.js +3 -0
  191. package/dist/interfaces/cli/tui/visual/viewport.js +11 -0
  192. package/dist/interfaces/cli/tui-render-helpers.js +200 -0
  193. package/dist/interfaces/cli/verification-plan-renderer.js +25 -0
  194. package/dist/interfaces/cli/verification-report-renderer.js +19 -0
  195. package/dist/interfaces/mcp/contracts/agents.js +1 -0
  196. package/dist/interfaces/mcp/contracts/context.js +1 -0
  197. package/dist/interfaces/mcp/contracts/governance.js +1 -0
  198. package/dist/interfaces/mcp/contracts/index.js +1 -0
  199. package/dist/interfaces/mcp/contracts/memory.js +1 -0
  200. package/dist/interfaces/mcp/contracts/providers.js +1 -0
  201. package/dist/interfaces/mcp/contracts/runs.js +1 -0
  202. package/dist/interfaces/mcp/contracts/sdd.js +1 -0
  203. package/dist/interfaces/mcp/contracts/sessions.js +1 -0
  204. package/dist/interfaces/mcp/contracts/skills.js +1 -0
  205. package/dist/interfaces/mcp/contracts/verification.js +1 -0
  206. package/dist/interfaces/mcp/control-plane/handlers/agents.js +38 -0
  207. package/dist/interfaces/mcp/control-plane/handlers/context.js +12 -0
  208. package/dist/interfaces/mcp/control-plane/handlers/memory.js +95 -0
  209. package/dist/interfaces/mcp/control-plane/handlers/providers.js +19 -0
  210. package/dist/interfaces/mcp/control-plane/handlers/runs.js +134 -0
  211. package/dist/interfaces/mcp/control-plane/handlers/sdd.js +225 -0
  212. package/dist/interfaces/mcp/control-plane/handlers/sessions.js +39 -0
  213. package/dist/interfaces/mcp/control-plane/handlers/skills.js +82 -0
  214. package/dist/interfaces/mcp/control-plane/handlers/verification.js +11 -0
  215. package/dist/interfaces/mcp/control-plane/types.js +1 -0
  216. package/dist/interfaces/mcp/control-plane.js +235 -0
  217. package/dist/interfaces/mcp/schema.js +174 -0
  218. package/dist/interfaces/mcp/schemas/common.js +121 -0
  219. package/dist/interfaces/mcp/schemas/inputs/agents.js +69 -0
  220. package/dist/interfaces/mcp/schemas/inputs/context.js +32 -0
  221. package/dist/interfaces/mcp/schemas/inputs/governance.js +23 -0
  222. package/dist/interfaces/mcp/schemas/inputs/index.js +10 -0
  223. package/dist/interfaces/mcp/schemas/inputs/memory.js +50 -0
  224. package/dist/interfaces/mcp/schemas/inputs/providers.js +35 -0
  225. package/dist/interfaces/mcp/schemas/inputs/runs.js +146 -0
  226. package/dist/interfaces/mcp/schemas/inputs/sdd.js +102 -0
  227. package/dist/interfaces/mcp/schemas/inputs/sessions.js +32 -0
  228. package/dist/interfaces/mcp/schemas/inputs/skills.js +231 -0
  229. package/dist/interfaces/mcp/schemas/inputs/verification.js +9 -0
  230. package/dist/interfaces/mcp/schemas/outputs/index.js +2 -0
  231. package/dist/interfaces/mcp/schemas/outputs/providers.js +28 -0
  232. package/dist/interfaces/mcp/schemas/outputs/sdd.js +166 -0
  233. package/dist/interfaces/mcp/stdio-server.js +116 -0
  234. package/dist/interfaces/mcp/validation/agents.js +189 -0
  235. package/dist/interfaces/mcp/validation/common.js +415 -0
  236. package/dist/interfaces/mcp/validation/governance.js +50 -0
  237. package/dist/interfaces/mcp/validation/memory.js +133 -0
  238. package/dist/interfaces/mcp/validation/providers.js +94 -0
  239. package/dist/interfaces/mcp/validation/runs.js +514 -0
  240. package/dist/interfaces/mcp/validation/sdd.js +247 -0
  241. package/dist/interfaces/mcp/validation/sessions.js +51 -0
  242. package/dist/interfaces/mcp/validation/skills.js +685 -0
  243. package/dist/interfaces/mcp/validation/verification.js +24 -0
  244. package/dist/interfaces/mcp/validation.js +149 -0
  245. package/dist/mcp/control-plane-snapshot-service.js +65 -2
  246. package/dist/mcp/control-plane.js +1 -646
  247. package/dist/mcp/doctor.js +1 -1
  248. package/dist/mcp/index.js +17 -17
  249. package/dist/mcp/schema.js +1 -1072
  250. package/dist/mcp/stdio-server.js +1 -116
  251. package/dist/mcp/validation.js +1 -2239
  252. package/dist/memory/active-work-preview.js +1 -75
  253. package/dist/memory/active-work-topics.js +1 -64
  254. package/dist/memory/agent-memory-capture-service.js +1 -497
  255. package/dist/memory/import/dry-run-planner.js +1 -58
  256. package/dist/memory/import/index.js +1 -3
  257. package/dist/memory/import/observation-writer.js +1 -226
  258. package/dist/memory/import/package.js +1 -179
  259. package/dist/memory/memory-capture-schema.js +1 -1
  260. package/dist/memory/memory-service.js +1 -201
  261. package/dist/memory/repositories/artifacts.js +1 -67
  262. package/dist/memory/repositories/observations.js +1 -217
  263. package/dist/memory/repositories/sessions.js +1 -125
  264. package/dist/memory/repositories/traces.js +1 -78
  265. package/dist/memory/schema.js +1 -1
  266. package/dist/memory/search.js +1 -11
  267. package/dist/memory/sqlite/database.js +1 -228
  268. package/dist/memory/storage-paths.js +1 -72
  269. package/dist/payload/context-budget-policy.js +10 -0
  270. package/dist/payload/context-budget-service.js +26 -0
  271. package/dist/payload/payload-diagnostics.js +50 -0
  272. package/dist/permissions/explicit-request-authorization.js +126 -0
  273. package/dist/permissions/policy-evaluator.js +54 -14
  274. package/dist/runs/execution-planning.js +1 -178
  275. package/dist/runs/operation-execution.js +1 -1
  276. package/dist/runs/operation-retry.js +1 -129
  277. package/dist/runs/repositories/runs.js +1 -676
  278. package/dist/runs/repositories/task-scoped-command-grants.js +1 -462
  279. package/dist/runs/resume-after-approval-result.js +1 -84
  280. package/dist/runs/run-insights.js +1 -270
  281. package/dist/runs/run-service.js +1 -1439
  282. package/dist/runs/run-snapshot-export-service.js +1 -31
  283. package/dist/runs/sandbox-process-execution.js +1 -240
  284. package/dist/runs/sandbox-worktree-planning.js +1 -59
  285. package/dist/runs/schema.js +1 -5
  286. package/dist/runs/task-scoped-command-grant-service.js +1 -216
  287. package/dist/sdd/artifact-portability-service.js +1 -137
  288. package/dist/sdd/cockpit-read-model.js +1 -195
  289. package/dist/sdd/cockpit-types.js +1 -1
  290. package/dist/sdd/schema.js +1 -111
  291. package/dist/sdd/sdd-continuation-plan.js +1 -265
  292. package/dist/sdd/sdd-workflow-service.js +1 -822
  293. package/dist/setup/providers/claude-setup-adapter.js +11 -4
  294. package/dist/setup/providers/opencode-setup-adapter.js +10 -7
  295. package/dist/setup/setup-plan.js +20 -7
  296. package/dist/skills/boot-seed.js +1 -42
  297. package/dist/skills/personal-skills.js +1 -41
  298. package/dist/skills/repositories/skill-evaluation-requests.js +1 -190
  299. package/dist/skills/repositories/skill-evaluation-scenarios.js +1 -305
  300. package/dist/skills/repositories/skill-improvement-proposals.js +1 -355
  301. package/dist/skills/repositories/skills.js +1 -1077
  302. package/dist/skills/schema.js +1 -1
  303. package/dist/skills/skill-export-service.js +1 -34
  304. package/dist/skills/skill-index-service.js +1 -126
  305. package/dist/skills/skill-payload.js +1 -186
  306. package/dist/skills/skill-registry-service.js +1 -644
  307. package/dist/skills/skill-resolver.js +1 -368
  308. package/dist/skills/skill-seed-service.js +1 -242
  309. package/dist/skills/skill-status-service.js +1 -147
  310. package/dist/storage/agents/repositories/agent-seed-history.js +128 -0
  311. package/dist/storage/agents/repositories/agents.js +200 -0
  312. package/dist/storage/agents/repositories/manager-profile-overlays.js +90 -0
  313. package/dist/storage/memory/repositories/artifacts.js +67 -0
  314. package/dist/storage/memory/repositories/observations.js +217 -0
  315. package/dist/storage/memory/repositories/sessions.js +125 -0
  316. package/dist/storage/memory/repositories/traces.js +78 -0
  317. package/dist/storage/memory/sqlite/database.js +228 -0
  318. package/dist/storage/memory/storage-paths.js +72 -0
  319. package/dist/storage/runs/repositories/runs.js +676 -0
  320. package/dist/storage/runs/repositories/task-scoped-command-grants.js +464 -0
  321. package/dist/storage/skills/repositories/skill-evaluation-requests.js +190 -0
  322. package/dist/storage/skills/repositories/skill-evaluation-scenarios.js +305 -0
  323. package/dist/storage/skills/repositories/skill-improvement-proposals.js +355 -0
  324. package/dist/storage/skills/repositories/skills.js +1084 -0
  325. package/docs/architecture.md +2 -2
  326. package/docs/glossary.md +1 -1
  327. package/docs/mcp.md +1 -1
  328. package/docs/module-boundaries.md +114 -0
  329. package/docs/prd.md +1 -1
  330. package/docs/project-health-audit-v1.10.x.md +1 -1
  331. package/docs/providers.md +2 -2
  332. package/docs/safety.md +3 -3
  333. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/apply-progress.md +122 -0
  334. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/archive-report.md +61 -0
  335. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/design.md +66 -0
  336. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/proposal.md +79 -0
  337. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/spec.md +67 -0
  338. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/tasks.md +63 -0
  339. package/docs/sdd/archive/2026-06-26-ambitious-structure-reorganization/verify-report.md +71 -0
  340. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/apply-progress.md +68 -0
  341. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/archive-report.md +61 -0
  342. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/design.md +43 -0
  343. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/proposal.md +61 -0
  344. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/spec.md +31 -0
  345. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/tasks.md +27 -0
  346. package/docs/sdd/archive/2026-06-26-legacy-facade-cleanup/verify-report.md +58 -0
  347. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/apply-progress.md +65 -0
  348. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/archive-report.md +53 -0
  349. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/design.md +64 -0
  350. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/proposal.md +62 -0
  351. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/spec.md +51 -0
  352. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/tasks.md +50 -0
  353. package/docs/sdd/archive/2026-06-26-provider-install-adapter-boundary/verify-report.md +66 -0
  354. package/docs/storage.md +2 -2
  355. package/package.json +2 -2
  356. /package/dist/{mcp → adapters/claude/install}/claude-code-cli.js +0 -0
  357. /package/dist/{memory → storage/memory}/sqlite/migrations/001_initial.sql +0 -0
  358. /package/dist/{memory → storage/memory}/sqlite/migrations/002_observation_revisions.sql +0 -0
  359. /package/dist/{memory → storage/memory}/sqlite/migrations/003_agent_registry.sql +0 -0
  360. /package/dist/{memory → storage/memory}/sqlite/migrations/004_run_runtime.sql +0 -0
  361. /package/dist/{memory → storage/memory}/sqlite/migrations/005_run_approvals.sql +0 -0
  362. /package/dist/{memory → storage/memory}/sqlite/migrations/006_run_operation_attempts.sql +0 -0
  363. /package/dist/{memory → storage/memory}/sqlite/migrations/007_abandoned_operation_attempts.sql +0 -0
  364. /package/dist/{memory → storage/memory}/sqlite/migrations/008_run_execution_plan_events.sql +0 -0
  365. /package/dist/{memory → storage/memory}/sqlite/migrations/009_multiple_operation_attempts.sql +0 -0
  366. /package/dist/{memory → storage/memory}/sqlite/migrations/010_skill_registry.sql +0 -0
  367. /package/dist/{memory → storage/memory}/sqlite/migrations/011_skill_usage_resolution_outcomes.sql +0 -0
  368. /package/dist/{memory → storage/memory}/sqlite/migrations/012_skill_improvement_proposals.sql +0 -0
  369. /package/dist/{memory → storage/memory}/sqlite/migrations/013_skill_evaluation_scenarios.sql +0 -0
  370. /package/dist/{memory → storage/memory}/sqlite/migrations/014_manager_profile_overlays.sql +0 -0
  371. /package/dist/{memory → storage/memory}/sqlite/migrations/015_artifact_metadata.sql +0 -0
  372. /package/dist/{memory → storage/memory}/sqlite/migrations/016_agent_seed_history.sql +0 -0
  373. /package/dist/{memory → storage/memory}/sqlite/migrations/017_intent_signal_skill_targets.sql +0 -0
  374. /package/dist/{memory → storage/memory}/sqlite/migrations/018_skill_system_v2.sql +0 -0
  375. /package/dist/{memory → storage/memory}/sqlite/migrations/019_task_scoped_command_grants.sql +0 -0
@@ -1,676 +1 @@
1
- import { randomUUID } from 'node:crypto';
2
- const finalStatuses = new Set(['completed', 'failed', 'blocked', 'cancelled']);
3
- const allowedOutcomes = {
4
- completed: ['success', 'partial'],
5
- failed: ['failure'],
6
- blocked: ['blocked'],
7
- cancelled: ['cancelled'],
8
- };
9
- export class RunRepository {
10
- db;
11
- constructor(db) {
12
- this.db = db;
13
- }
14
- create(input) {
15
- const validation = validateCreate(input);
16
- if (!validation.ok)
17
- return validation;
18
- const result = this.db.transaction(() => {
19
- const id = randomUUID();
20
- const now = new Date().toISOString();
21
- this.db.connection
22
- .prepare(`
23
- INSERT INTO runs(id, project, user_intent, workflow, phase, selected_agent_id, provider_adapter, model, status, created_at, updated_at)
24
- VALUES (@id, @project, @userIntent, @workflow, @phase, @selectedAgentId, @providerAdapter, @model, 'created', @now, @now)
25
- `)
26
- .run({ ...input, id, now });
27
- const run = this.getById(id);
28
- if (!run.ok)
29
- throw new Error(run.error.message);
30
- return run.value;
31
- });
32
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
33
- }
34
- getById(id) {
35
- try {
36
- const row = this.db.connection.prepare('SELECT * FROM runs WHERE id=?').get(id);
37
- return row ? ok(mapRun(row)) : missing(`Run not found: ${id}`);
38
- }
39
- catch (cause) {
40
- return fail('Failed to read run', cause);
41
- }
42
- }
43
- getDetails(id) {
44
- const run = this.getById(id);
45
- if (!run.ok)
46
- return run;
47
- const events = this.listEvents(id);
48
- if (!events.ok)
49
- return events;
50
- const checkpoints = this.listCheckpoints(id);
51
- if (!checkpoints.ok)
52
- return checkpoints;
53
- const approvals = this.listApprovals(id);
54
- if (!approvals.ok)
55
- return approvals;
56
- const operationAttempts = this.listOperationAttempts(id);
57
- if (!operationAttempts.ok)
58
- return operationAttempts;
59
- return ok({ ...run.value, events: events.value, checkpoints: checkpoints.value, approvals: approvals.value, operationAttempts: operationAttempts.value });
60
- }
61
- list(filters = {}) {
62
- try {
63
- const where = [];
64
- const parameters = {};
65
- if (filters.project !== undefined) {
66
- where.push('project=@project');
67
- parameters.project = filters.project;
68
- }
69
- if (filters.status !== undefined) {
70
- where.push('status=@status');
71
- parameters.status = filters.status;
72
- }
73
- if (filters.statuses !== undefined && filters.statuses.length > 0) {
74
- const statusPlaceholders = filters.statuses.map((_, index) => `@status${index}`);
75
- where.push(`status IN (${statusPlaceholders.join(', ')})`);
76
- for (const [index, status] of filters.statuses.entries())
77
- parameters[`status${index}`] = status;
78
- }
79
- const limitClause = filters.limit === undefined ? '' : 'LIMIT @limit';
80
- const queryParameters = { ...parameters };
81
- if (filters.limit !== undefined)
82
- queryParameters.limit = filters.limit;
83
- const rows = this.db.connection
84
- .prepare(`
85
- SELECT * FROM runs
86
- ${where.length ? `WHERE ${where.join(' AND ')}` : ''}
87
- ORDER BY created_at DESC
88
- ${limitClause}
89
- `)
90
- .all(queryParameters);
91
- return ok(rows.map(mapRun));
92
- }
93
- catch (cause) {
94
- return fail('Failed to list runs', cause);
95
- }
96
- }
97
- appendEvent(input) {
98
- const run = this.getById(input.runId);
99
- if (!run.ok)
100
- return run;
101
- if (!input.title.trim())
102
- return validationFailure('Run event title is required');
103
- const result = this.db.transaction(() => {
104
- const next = this.nextSequence('run_events', input.runId);
105
- const event = {
106
- id: randomUUID(),
107
- runId: input.runId,
108
- sequence: next,
109
- kind: input.kind,
110
- title: input.title,
111
- payloadJson: JSON.stringify(input.payload ?? {}),
112
- relatedType: input.relatedType ?? null,
113
- relatedId: input.relatedId ?? null,
114
- createdAt: new Date().toISOString(),
115
- };
116
- this.db.connection
117
- .prepare(`
118
- INSERT INTO run_events(id, run_id, sequence, kind, title, payload_json, related_type, related_id, created_at)
119
- VALUES (@id, @runId, @sequence, @kind, @title, @payloadJson, @relatedType, @relatedId, @createdAt)
120
- `)
121
- .run(event);
122
- return mapEventRow({
123
- ...event,
124
- run_id: event.runId,
125
- payload_json: event.payloadJson,
126
- related_type: event.relatedType,
127
- related_id: event.relatedId,
128
- created_at: event.createdAt,
129
- });
130
- });
131
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
132
- }
133
- appendCheckpoint(input) {
134
- const run = this.getById(input.runId);
135
- if (!run.ok)
136
- return run;
137
- if (finalStatuses.has(run.value.status))
138
- return validationFailure(`Cannot checkpoint terminal run: ${run.value.status}`);
139
- if (!input.label.trim())
140
- return validationFailure('Run checkpoint label is required');
141
- const result = this.db.transaction(() => {
142
- const next = this.nextSequence('run_checkpoints', input.runId);
143
- const checkpoint = {
144
- id: randomUUID(),
145
- runId: input.runId,
146
- sequence: next,
147
- label: input.label,
148
- stateJson: JSON.stringify(input.state),
149
- createdAt: new Date().toISOString(),
150
- };
151
- this.db.connection
152
- .prepare(`
153
- INSERT INTO run_checkpoints(id, run_id, sequence, label, state_json, created_at)
154
- VALUES (@id, @runId, @sequence, @label, @stateJson, @createdAt)
155
- `)
156
- .run(checkpoint);
157
- this.db.connection
158
- .prepare('UPDATE runs SET latest_checkpoint_id=@checkpointId, updated_at=@updatedAt WHERE id=@runId')
159
- .run({ checkpointId: checkpoint.id, updatedAt: checkpoint.createdAt, runId: input.runId });
160
- return mapCheckpointRow({ ...checkpoint, run_id: checkpoint.runId, state_json: checkpoint.stateJson, created_at: checkpoint.createdAt });
161
- });
162
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
163
- }
164
- createApproval(input) {
165
- const run = this.getById(input.runId);
166
- if (!run.ok)
167
- return run;
168
- const decisionEvent = this.getEventById(input.decisionEventId);
169
- if (!decisionEvent.ok)
170
- return decisionEvent;
171
- if (decisionEvent.value.runId !== input.runId)
172
- return validationFailure('Approval decision event must belong to the run');
173
- if (decisionEvent.value.kind !== 'permission-decision')
174
- return validationFailure('Approval decision event must be a permission-decision event');
175
- if (!isAskPermissionDecision(decisionEvent.value.payload))
176
- return validationFailure('Approval can only be created for ask permission decisions');
177
- const result = this.db.transaction(() => {
178
- const approval = {
179
- id: randomUUID(),
180
- runId: input.runId,
181
- decisionEventId: input.decisionEventId,
182
- status: 'pending',
183
- requestedAt: new Date().toISOString(),
184
- };
185
- this.db.connection
186
- .prepare(`
187
- INSERT INTO run_approvals(id, run_id, decision_event_id, status, requested_at)
188
- VALUES (@id, @runId, @decisionEventId, @status, @requestedAt)
189
- `)
190
- .run(approval);
191
- this.db.connection.prepare('UPDATE runs SET updated_at=@updatedAt WHERE id=@runId').run({ runId: input.runId, updatedAt: approval.requestedAt });
192
- return approval;
193
- });
194
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
195
- }
196
- getApproval(id) {
197
- try {
198
- const row = this.db.connection.prepare('SELECT * FROM run_approvals WHERE id=?').get(id);
199
- return row ? ok(mapApprovalRow(row)) : missing(`Approval not found: ${id}`);
200
- }
201
- catch (cause) {
202
- return fail('Failed to read run approval', cause);
203
- }
204
- }
205
- listApprovals(runId) {
206
- const run = this.getById(runId);
207
- if (!run.ok)
208
- return run;
209
- try {
210
- const rows = this.db.connection.prepare('SELECT * FROM run_approvals WHERE run_id=? ORDER BY requested_at ASC').all(runId);
211
- return ok(rows.map(mapApprovalRow));
212
- }
213
- catch (cause) {
214
- return fail('Failed to list run approvals', cause);
215
- }
216
- }
217
- listOperationAttempts(runId) {
218
- const run = this.getById(runId);
219
- if (!run.ok)
220
- return run;
221
- try {
222
- const rows = this.db.connection
223
- .prepare('SELECT * FROM run_operation_attempts WHERE run_id=? ORDER BY COALESCE(approval_id, id) ASC, attempt_sequence ASC, reserved_at ASC')
224
- .all(runId);
225
- return ok(rows.map(mapOperationAttemptRow));
226
- }
227
- catch (cause) {
228
- return fail('Failed to list run operation attempts', cause);
229
- }
230
- }
231
- getOperationAttempt(id) {
232
- try {
233
- const row = this.db.connection.prepare('SELECT * FROM run_operation_attempts WHERE id=?').get(id);
234
- return row ? ok(mapOperationAttemptRow(row)) : missing(`Run operation attempt not found: ${id}`);
235
- }
236
- catch (cause) {
237
- return fail('Failed to read run operation attempt', cause);
238
- }
239
- }
240
- reserveOperationAttempt(input) {
241
- const run = this.getById(input.runId);
242
- if (!run.ok)
243
- return run;
244
- const decisionEvent = this.getEventById(input.decisionEventId);
245
- if (!decisionEvent.ok)
246
- return decisionEvent;
247
- if (decisionEvent.value.runId !== input.runId)
248
- return validationFailure('Attempt decision event must belong to the run');
249
- if (input.pendingExecutionEventId !== undefined) {
250
- const pendingEvent = this.getEventById(input.pendingExecutionEventId);
251
- if (!pendingEvent.ok)
252
- return pendingEvent;
253
- if (pendingEvent.value.runId !== input.runId)
254
- return validationFailure('Attempt pending execution event must belong to the run');
255
- }
256
- const result = this.db.transaction(() => {
257
- const now = new Date().toISOString();
258
- const existingReserved = input.approvalId === undefined
259
- ? undefined
260
- : this.db.connection.prepare("SELECT * FROM run_operation_attempts WHERE approval_id=? AND status='reserved'").get(input.approvalId);
261
- if (existingReserved !== undefined) {
262
- return validationFailure(`Approval already has an active operation attempt reservation: ${mapOperationAttemptRow(existingReserved).id}`);
263
- }
264
- const attemptSequence = input.approvalId === undefined
265
- ? 1
266
- : this.db.connection
267
- .prepare('SELECT COALESCE(MAX(attempt_sequence), 0) + 1 AS nextSequence FROM run_operation_attempts WHERE approval_id=?')
268
- .get(input.approvalId).nextSequence;
269
- const attempt = {
270
- id: randomUUID(),
271
- runId: input.runId,
272
- approvalId: input.approvalId ?? null,
273
- attemptSequence,
274
- decisionEventId: input.decisionEventId,
275
- pendingExecutionEventId: input.pendingExecutionEventId ?? null,
276
- category: input.category,
277
- operation: input.operation,
278
- operationJson: JSON.stringify(input.operationMetadata),
279
- executorName: input.executorName,
280
- status: 'reserved',
281
- reservedAt: now,
282
- updatedAt: now,
283
- };
284
- const insert = this.db.connection
285
- .prepare(`
286
- INSERT OR IGNORE INTO run_operation_attempts(
287
- id, run_id, approval_id, attempt_sequence, decision_event_id, pending_execution_event_id,
288
- category, operation, operation_json, executor_name, status, reserved_at, updated_at
289
- ) VALUES (
290
- @id, @runId, @approvalId, @attemptSequence, @decisionEventId, @pendingExecutionEventId,
291
- @category, @operation, @operationJson, @executorName, @status, @reservedAt, @updatedAt
292
- )
293
- `)
294
- .run(attempt);
295
- if (insert.changes === 0) {
296
- const existing = input.approvalId === undefined
297
- ? undefined
298
- : this.db.connection
299
- .prepare('SELECT * FROM run_operation_attempts WHERE approval_id=? AND attempt_sequence=?')
300
- .get(input.approvalId, attemptSequence);
301
- const status = existing === undefined ? 'existing' : mapOperationAttemptRow(existing).status;
302
- return validationFailure(`Approval attempt sequence is already reserved: ${status}`);
303
- }
304
- this.db.connection.prepare('UPDATE runs SET updated_at=@updatedAt WHERE id=@runId').run({ runId: input.runId, updatedAt: now });
305
- return ok(mapOperationAttemptRow({
306
- ...attempt,
307
- run_id: attempt.runId,
308
- approval_id: attempt.approvalId,
309
- attempt_sequence: attempt.attemptSequence,
310
- decision_event_id: attempt.decisionEventId,
311
- pending_execution_event_id: attempt.pendingExecutionEventId,
312
- operation_json: attempt.operationJson,
313
- executor_name: attempt.executorName,
314
- result_event_id: null,
315
- output_json: null,
316
- error_json: null,
317
- reserved_at: attempt.reservedAt,
318
- updated_at: attempt.updatedAt,
319
- completed_at: null,
320
- }));
321
- });
322
- return result.ok ? result.value : fail(result.error.message, result.error.cause, result.error.code);
323
- }
324
- completeOperationAttempt(input) {
325
- const existing = this.getOperationAttempt(input.attemptId);
326
- if (!existing.ok)
327
- return existing;
328
- if (existing.value.status !== 'reserved')
329
- return validationFailure(`Operation attempt is already finalized: ${existing.value.status}`);
330
- const result = this.db.transaction(() => {
331
- const now = new Date().toISOString();
332
- this.db.connection
333
- .prepare(`
334
- UPDATE run_operation_attempts
335
- SET status=@status, output_json=@outputJson, error_json=@errorJson, updated_at=@now, completed_at=@now
336
- WHERE id=@attemptId AND status='reserved'
337
- `)
338
- .run({
339
- attemptId: input.attemptId,
340
- status: input.status,
341
- outputJson: input.output === undefined ? null : JSON.stringify(input.output),
342
- errorJson: input.error === undefined ? null : JSON.stringify(input.error),
343
- now,
344
- });
345
- this.db.connection.prepare('UPDATE runs SET updated_at=@updatedAt WHERE id=@runId').run({ runId: existing.value.runId, updatedAt: now });
346
- const updated = this.getOperationAttempt(input.attemptId);
347
- if (!updated.ok)
348
- throw new Error(updated.error.message);
349
- return updated.value;
350
- });
351
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
352
- }
353
- abandonOperationAttempt(input) {
354
- const existing = this.getOperationAttempt(input.attemptId);
355
- if (!existing.ok)
356
- return existing;
357
- if (existing.value.status !== 'reserved')
358
- return validationFailure(`Only reserved operation attempts can be abandoned: ${existing.value.status}`);
359
- if (!input.actor.trim())
360
- return validationFailure('Operation attempt abandonment actor is required');
361
- if (!input.reason.trim())
362
- return validationFailure('Operation attempt abandonment reason is required');
363
- const result = this.db.transaction(() => {
364
- const now = new Date().toISOString();
365
- const update = this.db.connection
366
- .prepare(`
367
- UPDATE run_operation_attempts
368
- SET status='abandoned', updated_at=@now, completed_at=@now
369
- WHERE id=@attemptId AND status='reserved'
370
- `)
371
- .run({ attemptId: input.attemptId, now });
372
- if (update.changes === 0)
373
- return validationFailure(`Operation attempt is already finalized: ${input.attemptId}`);
374
- const event = this.insertEvent({
375
- runId: existing.value.runId,
376
- kind: 'operation-execution',
377
- title: `Operation attempt abandoned: ${existing.value.category} ${existing.value.operation}`,
378
- payload: {
379
- status: 'abandoned',
380
- attemptId: existing.value.id,
381
- approvalId: existing.value.approvalId ?? null,
382
- decisionEventId: existing.value.decisionEventId,
383
- pendingExecutionEventId: existing.value.pendingExecutionEventId ?? null,
384
- actor: input.actor,
385
- reason: input.reason,
386
- timestamp: now,
387
- executorName: existing.value.executorName,
388
- executorInvoked: false,
389
- operationExecuted: false,
390
- retryAllowed: false,
391
- requestedOperation: existing.value.operationMetadata,
392
- },
393
- relatedType: 'operation-attempt',
394
- relatedId: existing.value.id,
395
- });
396
- this.db.connection
397
- .prepare('UPDATE run_operation_attempts SET result_event_id=@eventId, updated_at=@now WHERE id=@attemptId')
398
- .run({ attemptId: input.attemptId, eventId: event.id, now });
399
- this.db.connection.prepare('UPDATE runs SET updated_at=@updatedAt WHERE id=@runId').run({ runId: existing.value.runId, updatedAt: now });
400
- const updated = this.getOperationAttempt(input.attemptId);
401
- if (!updated.ok)
402
- throw new Error(updated.error.message);
403
- return ok({ attempt: updated.value, event });
404
- });
405
- return result.ok ? result.value : fail(result.error.message, result.error.cause, result.error.code);
406
- }
407
- attachAttemptResultEvent(attemptId, eventId) {
408
- const attempt = this.getOperationAttempt(attemptId);
409
- if (!attempt.ok)
410
- return attempt;
411
- const event = this.getEventById(eventId);
412
- if (!event.ok)
413
- return event;
414
- if (event.value.runId !== attempt.value.runId)
415
- return validationFailure('Attempt result event must belong to the run');
416
- const result = this.db.transaction(() => {
417
- const now = new Date().toISOString();
418
- this.db.connection
419
- .prepare('UPDATE run_operation_attempts SET result_event_id=@eventId, updated_at=@now WHERE id=@attemptId')
420
- .run({ attemptId, eventId, now });
421
- const updated = this.getOperationAttempt(attemptId);
422
- if (!updated.ok)
423
- throw new Error(updated.error.message);
424
- return updated.value;
425
- });
426
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
427
- }
428
- resolveApproval(input) {
429
- const approval = this.getApproval(input.approvalId);
430
- if (!approval.ok)
431
- return approval;
432
- if (approval.value.status !== 'pending')
433
- return validationFailure(`Approval is already resolved: ${approval.value.status}`);
434
- if (!input.actor.trim())
435
- return validationFailure('Approval resolution actor is required');
436
- const result = this.db.transaction(() => {
437
- const resolvedAt = new Date().toISOString();
438
- const update = this.db.connection
439
- .prepare(`
440
- UPDATE run_approvals
441
- SET status=@status, resolved_at=@resolvedAt, resolved_by=@actor, resolution_reason=@reason
442
- WHERE id=@approvalId AND status='pending'
443
- `)
444
- .run({ approvalId: input.approvalId, status: input.status, resolvedAt, actor: input.actor, reason: input.reason ?? null });
445
- if (update.changes === 0)
446
- return validationFailure(`Approval is already resolved or changed by another resolver: ${input.approvalId}`);
447
- const event = this.insertEvent({
448
- runId: approval.value.runId,
449
- kind: 'approval',
450
- title: `Approval ${input.status}`,
451
- payload: {
452
- approvalId: input.approvalId,
453
- decisionEventId: approval.value.decisionEventId,
454
- status: input.status,
455
- actor: input.actor,
456
- reason: input.reason ?? null,
457
- resolvedAt,
458
- operationExecuted: false,
459
- },
460
- relatedType: 'approval',
461
- relatedId: input.approvalId,
462
- });
463
- this.db.connection.prepare('UPDATE runs SET updated_at=@updatedAt WHERE id=@runId').run({ runId: approval.value.runId, updatedAt: resolvedAt });
464
- const resolved = this.getApproval(input.approvalId);
465
- if (!resolved.ok)
466
- throw new Error(resolved.error.message);
467
- return ok({ approval: resolved.value, event });
468
- });
469
- return result.ok ? result.value : fail(result.error.message, result.error.cause, result.error.code);
470
- }
471
- updateFinalStatus(input) {
472
- const run = this.getById(input.runId);
473
- if (!run.ok)
474
- return run;
475
- if (finalStatuses.has(run.value.status))
476
- return validationFailure(`Run is already terminal: ${run.value.status}`);
477
- if (!allowedOutcomes[input.status].includes(input.outcome))
478
- return validationFailure(`Outcome ${input.outcome} is not valid for status ${input.status}`);
479
- const result = this.db.transaction(() => {
480
- const now = new Date().toISOString();
481
- this.db.connection
482
- .prepare(`
483
- UPDATE runs
484
- SET status=@status, outcome=@outcome, outcome_reason=@outcomeReason, completed_at=@now, updated_at=@now
485
- WHERE id=@runId
486
- `)
487
- .run({ ...input, outcomeReason: input.outcomeReason ?? null, now });
488
- const updated = this.getById(input.runId);
489
- if (!updated.ok)
490
- throw new Error(updated.error.message);
491
- return updated.value;
492
- });
493
- return result.ok ? result : fail(result.error.message, result.error.cause, result.error.code);
494
- }
495
- listEvents(runId) {
496
- try {
497
- const rows = this.db.connection.prepare('SELECT * FROM run_events WHERE run_id=? ORDER BY sequence ASC').all(runId);
498
- return ok(rows.map(mapEventRow));
499
- }
500
- catch (cause) {
501
- return fail('Failed to list run events', cause);
502
- }
503
- }
504
- getEventById(id) {
505
- try {
506
- const row = this.db.connection.prepare('SELECT * FROM run_events WHERE id=?').get(id);
507
- return row ? ok(mapEventRow(row)) : missing(`Run event not found: ${id}`);
508
- }
509
- catch (cause) {
510
- return fail('Failed to read run event', cause);
511
- }
512
- }
513
- listCheckpoints(runId) {
514
- try {
515
- const rows = this.db.connection.prepare('SELECT * FROM run_checkpoints WHERE run_id=? ORDER BY sequence ASC').all(runId);
516
- return ok(rows.map(mapCheckpointRow));
517
- }
518
- catch (cause) {
519
- return fail('Failed to list run checkpoints', cause);
520
- }
521
- }
522
- nextSequence(table, runId) {
523
- const row = this.db.connection.prepare(`SELECT COALESCE(MAX(sequence), 0) + 1 AS sequence FROM ${table} WHERE run_id=?`).get(runId);
524
- return row.sequence;
525
- }
526
- insertEvent(input) {
527
- const next = this.nextSequence('run_events', input.runId);
528
- const event = {
529
- id: randomUUID(),
530
- runId: input.runId,
531
- sequence: next,
532
- kind: input.kind,
533
- title: input.title,
534
- payloadJson: JSON.stringify(input.payload ?? {}),
535
- relatedType: input.relatedType ?? null,
536
- relatedId: input.relatedId ?? null,
537
- createdAt: new Date().toISOString(),
538
- };
539
- this.db.connection
540
- .prepare(`
541
- INSERT INTO run_events(id, run_id, sequence, kind, title, payload_json, related_type, related_id, created_at)
542
- VALUES (@id, @runId, @sequence, @kind, @title, @payloadJson, @relatedType, @relatedId, @createdAt)
543
- `)
544
- .run(event);
545
- return mapEventRow({
546
- ...event,
547
- run_id: event.runId,
548
- payload_json: event.payloadJson,
549
- related_type: event.relatedType,
550
- related_id: event.relatedId,
551
- created_at: event.createdAt,
552
- });
553
- }
554
- }
555
- function validateCreate(input) {
556
- if (!input.project.trim())
557
- return validationFailure('Run project is required');
558
- if (!input.userIntent.trim())
559
- return validationFailure('Run user intent is required');
560
- if (!input.workflow.trim())
561
- return validationFailure('Run workflow is required');
562
- if (!input.phase.trim())
563
- return validationFailure('Run phase is required');
564
- if (!input.selectedAgentId.trim())
565
- return validationFailure('Run selectedAgentId is required');
566
- if (!input.providerAdapter.trim())
567
- return validationFailure('Run providerAdapter is required');
568
- if (!input.model.trim())
569
- return validationFailure('Run model is required');
570
- return ok(undefined);
571
- }
572
- function mapRun(row) {
573
- const run = {
574
- id: row.id,
575
- project: row.project,
576
- userIntent: row.user_intent,
577
- workflow: row.workflow,
578
- phase: row.phase,
579
- selectedAgentId: row.selected_agent_id,
580
- providerAdapter: row.provider_adapter,
581
- model: row.model,
582
- status: row.status,
583
- createdAt: row.created_at,
584
- updatedAt: row.updated_at,
585
- };
586
- if (row.outcome !== null)
587
- run.outcome = row.outcome;
588
- if (row.outcome_reason !== null)
589
- run.outcomeReason = row.outcome_reason;
590
- if (row.latest_checkpoint_id !== null)
591
- run.latestCheckpointId = row.latest_checkpoint_id;
592
- if (row.completed_at !== null)
593
- run.completedAt = row.completed_at;
594
- return run;
595
- }
596
- function mapEventRow(row) {
597
- const event = {
598
- id: row.id,
599
- runId: row.run_id,
600
- sequence: row.sequence,
601
- kind: row.kind,
602
- title: row.title,
603
- payload: JSON.parse(row.payload_json),
604
- createdAt: row.created_at,
605
- };
606
- if (row.related_type !== null)
607
- event.relatedType = row.related_type;
608
- if (row.related_id !== null)
609
- event.relatedId = row.related_id;
610
- return event;
611
- }
612
- function mapCheckpointRow(row) {
613
- return { id: row.id, runId: row.run_id, sequence: row.sequence, label: row.label, state: JSON.parse(row.state_json), createdAt: row.created_at };
614
- }
615
- function mapApprovalRow(row) {
616
- const approval = {
617
- id: row.id,
618
- runId: row.run_id,
619
- decisionEventId: row.decision_event_id,
620
- status: row.status,
621
- requestedAt: row.requested_at,
622
- };
623
- if (row.resolved_at !== null)
624
- approval.resolvedAt = row.resolved_at;
625
- if (row.resolved_by !== null)
626
- approval.resolvedBy = row.resolved_by;
627
- if (row.resolution_reason !== null)
628
- approval.resolutionReason = row.resolution_reason;
629
- return approval;
630
- }
631
- function mapOperationAttemptRow(row) {
632
- const attempt = {
633
- id: row.id,
634
- runId: row.run_id,
635
- attemptSequence: row.attempt_sequence ?? 1,
636
- decisionEventId: row.decision_event_id,
637
- category: row.category,
638
- operation: row.operation,
639
- operationMetadata: JSON.parse(row.operation_json),
640
- executorName: row.executor_name,
641
- status: row.status,
642
- reservedAt: row.reserved_at,
643
- updatedAt: row.updated_at,
644
- };
645
- if (row.approval_id !== null)
646
- attempt.approvalId = row.approval_id;
647
- if (row.pending_execution_event_id !== null)
648
- attempt.pendingExecutionEventId = row.pending_execution_event_id;
649
- if (row.result_event_id !== null)
650
- attempt.resultEventId = row.result_event_id;
651
- if (row.output_json !== null)
652
- attempt.output = JSON.parse(row.output_json);
653
- if (row.error_json !== null)
654
- attempt.error = JSON.parse(row.error_json);
655
- if (row.completed_at !== null)
656
- attempt.completedAt = row.completed_at;
657
- return attempt;
658
- }
659
- function isAskPermissionDecision(payload) {
660
- return typeof payload === 'object' && payload !== null && !Array.isArray(payload) && payload.decision === 'ask';
661
- }
662
- function ok(value) {
663
- return { ok: true, value };
664
- }
665
- function missing(message) {
666
- return { ok: false, error: { code: 'not_found', message } };
667
- }
668
- function validationFailure(message) {
669
- return { ok: false, error: { code: 'validation_failed', message } };
670
- }
671
- function fail(message, cause, code = 'validation_failed') {
672
- const error = { code, message };
673
- if (cause !== undefined)
674
- error.cause = cause;
675
- return { ok: false, error };
676
- }
1
+ export * from '../../storage/runs/repositories/runs.js';