sdd-agent-platform 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (722) hide show
  1. package/README.md +30 -28
  2. package/node_modules/@sdd-agent-platform/core/dist/ai-tools.js +67 -69
  3. package/node_modules/@sdd-agent-platform/core/dist/ai-tools.js.map +1 -1
  4. package/node_modules/@sdd-agent-platform/core/dist/artifacts/ingestion.js +64 -9
  5. package/node_modules/@sdd-agent-platform/core/dist/artifacts/ingestion.js.map +1 -1
  6. package/node_modules/@sdd-agent-platform/core/dist/artifacts/sdd-evidence.js +0 -1
  7. package/node_modules/@sdd-agent-platform/core/dist/artifacts/sdd-evidence.js.map +1 -1
  8. package/node_modules/@sdd-agent-platform/core/dist/artifacts/sdd-result.js +26 -17
  9. package/node_modules/@sdd-agent-platform/core/dist/artifacts/sdd-result.js.map +1 -1
  10. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.d.ts +3 -0
  11. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.js +12 -9
  12. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.js.map +1 -1
  13. package/node_modules/@sdd-agent-platform/core/dist/config/project-config.d.ts +3 -1
  14. package/node_modules/@sdd-agent-platform/core/dist/config/project-config.js +7 -3
  15. package/node_modules/@sdd-agent-platform/core/dist/config/project-config.js.map +1 -1
  16. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.d.ts +4 -4
  17. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.js +12 -25
  18. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.js.map +1 -1
  19. package/node_modules/@sdd-agent-platform/core/dist/context/build-package.d.ts +1 -1
  20. package/node_modules/@sdd-agent-platform/core/dist/context/build-package.js +1 -7
  21. package/node_modules/@sdd-agent-platform/core/dist/context/build-package.js.map +1 -1
  22. package/node_modules/@sdd-agent-platform/core/dist/context/evidence-summary.js +26 -8
  23. package/node_modules/@sdd-agent-platform/core/dist/context/evidence-summary.js.map +1 -1
  24. package/node_modules/@sdd-agent-platform/core/dist/context/log-worker.js +2 -2
  25. package/node_modules/@sdd-agent-platform/core/dist/context/log-worker.js.map +1 -1
  26. package/node_modules/@sdd-agent-platform/core/dist/context-offload/contracts.d.ts +1 -1
  27. package/node_modules/@sdd-agent-platform/core/dist/contracts.d.ts +2 -1
  28. package/node_modules/@sdd-agent-platform/core/dist/contracts.js +1 -0
  29. package/node_modules/@sdd-agent-platform/core/dist/contracts.js.map +1 -1
  30. package/node_modules/@sdd-agent-platform/core/dist/delegation/model.d.ts +3 -0
  31. package/node_modules/@sdd-agent-platform/core/dist/delegation/validation.d.ts +3 -0
  32. package/node_modules/@sdd-agent-platform/core/dist/delegation/validation.js +7 -4
  33. package/node_modules/@sdd-agent-platform/core/dist/delegation/validation.js.map +1 -1
  34. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/document-chain.js +1 -1
  35. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/document-chain.js.map +1 -1
  36. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/project.js +8 -8
  37. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/project.js.map +1 -1
  38. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/registries.js +0 -1
  39. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/registries.js.map +1 -1
  40. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-evidence.js +4 -4
  41. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-evidence.js.map +1 -1
  42. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-trust.js +0 -24
  43. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-trust.js.map +1 -1
  44. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/runtime-contracts.js +1 -1
  45. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/runtime-contracts.js.map +1 -1
  46. package/node_modules/@sdd-agent-platform/core/dist/doctor/doctor.js +178 -58
  47. package/node_modules/@sdd-agent-platform/core/dist/doctor/doctor.js.map +1 -1
  48. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js +14 -7
  49. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js.map +1 -1
  50. package/node_modules/@sdd-agent-platform/core/dist/evidence-runtime/contracts.d.ts +0 -1
  51. package/node_modules/@sdd-agent-platform/core/dist/execution/background-executor.js +4 -4
  52. package/node_modules/@sdd-agent-platform/core/dist/execution/background-executor.js.map +1 -1
  53. package/node_modules/@sdd-agent-platform/core/dist/execution/foreground-subagents.js +3 -3
  54. package/node_modules/@sdd-agent-platform/core/dist/execution/foreground-subagents.js.map +1 -1
  55. package/node_modules/@sdd-agent-platform/core/dist/execution/host-invocation.js +5 -4
  56. package/node_modules/@sdd-agent-platform/core/dist/execution/host-invocation.js.map +1 -1
  57. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js +3 -2
  58. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js.map +1 -1
  59. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js +2 -2
  60. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js.map +1 -1
  61. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.d.ts +1 -1
  62. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.js +1 -1
  63. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.js.map +1 -1
  64. package/node_modules/@sdd-agent-platform/core/dist/instructions.d.ts +1 -1
  65. package/node_modules/@sdd-agent-platform/core/dist/instructions.js +54 -61
  66. package/node_modules/@sdd-agent-platform/core/dist/instructions.js.map +1 -1
  67. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/decision-gate.js +1 -1
  68. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/decision-gate.js.map +1 -1
  69. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.d.ts +1 -0
  70. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js +24 -8
  71. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js.map +1 -1
  72. package/node_modules/@sdd-agent-platform/core/dist/orchestration/contracts.d.ts +1 -1
  73. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.d.ts +12 -2
  74. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.js +62 -21
  75. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.js.map +1 -1
  76. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.d.ts +5 -2
  77. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js +69 -27
  78. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js.map +1 -1
  79. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js +15 -15
  80. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js.map +1 -1
  81. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js +1 -1
  82. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js.map +1 -1
  83. package/node_modules/@sdd-agent-platform/core/dist/registries/capability-sources.js +1 -1
  84. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.d.ts +1 -1
  85. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.js +9 -9
  86. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.js.map +1 -1
  87. package/node_modules/@sdd-agent-platform/core/dist/registries/eval-learning-context.js +4 -4
  88. package/node_modules/@sdd-agent-platform/core/dist/registries/eval-learning-context.js.map +1 -1
  89. package/node_modules/@sdd-agent-platform/core/dist/registries/query-status.js +2 -2
  90. package/node_modules/@sdd-agent-platform/core/dist/registries/query-status.js.map +1 -1
  91. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-capabilities.js +3 -3
  92. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-capabilities.js.map +1 -1
  93. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-plugins.js +2 -2
  94. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-plugins.js.map +1 -1
  95. package/node_modules/@sdd-agent-platform/core/dist/registries/worker-adapters.js +11 -11
  96. package/node_modules/@sdd-agent-platform/core/dist/registries/worker-adapters.js.map +1 -1
  97. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js +12 -12
  98. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js.map +1 -1
  99. package/node_modules/@sdd-agent-platform/core/dist/risk/contracts.d.ts +2 -2
  100. package/node_modules/@sdd-agent-platform/core/dist/risk/kernel.js +4 -4
  101. package/node_modules/@sdd-agent-platform/core/dist/risk/kernel.js.map +1 -1
  102. package/node_modules/@sdd-agent-platform/core/dist/risk/legacy-adapters.js +4 -7
  103. package/node_modules/@sdd-agent-platform/core/dist/risk/legacy-adapters.js.map +1 -1
  104. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.d.ts +2 -2
  105. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.js +19 -17
  106. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.js.map +1 -1
  107. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime-config.js +1 -1
  108. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime-config.js.map +1 -1
  109. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime.d.ts +2 -0
  110. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js +1 -1
  111. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js.map +1 -1
  112. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js +45 -15
  113. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js.map +1 -1
  114. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-import.d.ts +28 -0
  115. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-import.js +373 -0
  116. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-import.js.map +1 -0
  117. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js +2 -2
  118. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js.map +1 -1
  119. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.d.ts +37 -0
  120. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.js +235 -0
  121. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.js.map +1 -0
  122. package/node_modules/@sdd-agent-platform/core/dist/router.d.ts +2 -0
  123. package/node_modules/@sdd-agent-platform/core/dist/router.js +2 -0
  124. package/node_modules/@sdd-agent-platform/core/dist/router.js.map +1 -1
  125. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.d.ts +16 -0
  126. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js +126 -9
  127. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js.map +1 -1
  128. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.d.ts +0 -2
  129. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js +7 -5
  130. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js.map +1 -1
  131. package/node_modules/@sdd-agent-platform/core/dist/run-state/model.d.ts +28 -8
  132. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.d.ts +0 -2
  133. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.js +1 -3
  134. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.js.map +1 -1
  135. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js +37 -27
  136. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js.map +1 -1
  137. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.d.ts +5 -2
  138. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js +53 -14
  139. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js.map +1 -1
  140. package/node_modules/@sdd-agent-platform/core/dist/run-state/timing.d.ts +8 -0
  141. package/node_modules/@sdd-agent-platform/core/dist/run-state/timing.js +131 -0
  142. package/node_modules/@sdd-agent-platform/core/dist/run-state/timing.js.map +1 -0
  143. package/node_modules/@sdd-agent-platform/core/dist/run-state.d.ts +1 -0
  144. package/node_modules/@sdd-agent-platform/core/dist/run-state.js +1 -0
  145. package/node_modules/@sdd-agent-platform/core/dist/run-state.js.map +1 -1
  146. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/build.js +0 -3
  147. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/build.js.map +1 -1
  148. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/findings.js +5 -44
  149. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/findings.js.map +1 -1
  150. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/model.d.ts +1 -17
  151. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.d.ts +10 -0
  152. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js +65 -0
  153. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js.map +1 -1
  154. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.d.ts +64 -0
  155. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.js +200 -0
  156. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.js.map +1 -0
  157. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.d.ts +2 -0
  158. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js +97 -10
  159. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js.map +1 -1
  160. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.d.ts +1 -1
  161. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js +8 -6
  162. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js.map +1 -1
  163. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.d.ts +1 -0
  164. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js +55 -34
  165. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js.map +1 -1
  166. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.d.ts +55 -0
  167. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.js +322 -0
  168. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.js.map +1 -0
  169. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.d.ts +55 -0
  170. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.js +241 -0
  171. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.js.map +1 -0
  172. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.d.ts +888 -0
  173. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.js +3870 -0
  174. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.js.map +1 -0
  175. package/node_modules/@sdd-agent-platform/core/dist/stage-runtime/runtime.js +8 -1
  176. package/node_modules/@sdd-agent-platform/core/dist/stage-runtime/runtime.js.map +1 -1
  177. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.d.ts +44 -1
  178. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js +170 -23
  179. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js.map +1 -1
  180. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.d.ts +170 -18
  181. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.js +544 -32
  182. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.js.map +1 -1
  183. package/node_modules/@sdd-agent-platform/core/dist/subagents/contracts.d.ts +1 -1
  184. package/node_modules/@sdd-agent-platform/core/dist/subagents/runtime.js +7 -7
  185. package/node_modules/@sdd-agent-platform/core/dist/subagents/runtime.js.map +1 -1
  186. package/node_modules/@sdd-agent-platform/core/dist/test-support/fixtures.js +1 -1
  187. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.d.ts +1 -1
  188. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js +8 -23
  189. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js.map +1 -1
  190. package/node_modules/@sdd-agent-platform/core/dist/truth-reconciliation.d.ts +44 -0
  191. package/node_modules/@sdd-agent-platform/core/dist/truth-reconciliation.js +138 -0
  192. package/node_modules/@sdd-agent-platform/core/dist/truth-reconciliation.js.map +1 -0
  193. package/node_modules/@sdd-agent-platform/core/dist/tsconfig.tsbuildinfo +1 -1
  194. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.d.ts +0 -1
  195. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js +28 -53
  196. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js.map +1 -1
  197. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.d.ts +0 -2
  198. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js +10 -50
  199. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js.map +1 -1
  200. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.d.ts +0 -1
  201. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js +159 -150
  202. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js.map +1 -1
  203. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.d.ts +12 -2
  204. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js +238 -103
  205. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js.map +1 -1
  206. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-cache.d.ts +26 -0
  207. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-cache.js +73 -0
  208. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-cache.js.map +1 -0
  209. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.d.ts +18 -0
  210. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js +27 -5
  211. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js.map +1 -1
  212. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.d.ts +1 -1
  213. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js +9 -32
  214. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js.map +1 -1
  215. package/node_modules/@sdd-agent-platform/core/dist/work-units/contracts.d.ts +1 -1
  216. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js +228 -15
  217. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js.map +1 -1
  218. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js +49 -15
  219. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js.map +1 -1
  220. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js +42 -6
  221. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js.map +1 -1
  222. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/types.d.ts +4 -5
  223. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.d.ts +0 -1
  224. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js +1 -2
  225. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  226. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/dependencies.js +1 -1
  227. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.d.ts +0 -1
  228. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js +72 -6
  229. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js.map +1 -1
  230. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/migration-recovery.d.ts +40 -0
  231. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/migration-recovery.js +110 -0
  232. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/migration-recovery.js.map +1 -0
  233. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/repair-contract.d.ts +12 -0
  234. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/repair-contract.js +63 -0
  235. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/repair-contract.js.map +1 -0
  236. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve-task-run.d.ts +21 -0
  237. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve-task-run.js +95 -0
  238. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve-task-run.js.map +1 -0
  239. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.d.ts +55 -5
  240. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js +538 -34
  241. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js.map +1 -1
  242. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/runtime-projections.d.ts +228 -0
  243. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/runtime-projections.js +452 -0
  244. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/runtime-projections.js.map +1 -0
  245. package/node_modules/@sdd-agent-platform/core/package.json +3 -3
  246. package/node_modules/@sdd-agent-platform/core/src/ai-tools.test.ts +49 -1
  247. package/node_modules/@sdd-agent-platform/core/src/ai-tools.ts +67 -69
  248. package/node_modules/@sdd-agent-platform/core/src/artifacts/ingestion.test.ts +38 -0
  249. package/node_modules/@sdd-agent-platform/core/src/artifacts/ingestion.ts +65 -9
  250. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-evidence.ts +0 -1
  251. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-result.test.ts +2 -2
  252. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-result.ts +26 -17
  253. package/node_modules/@sdd-agent-platform/core/src/config/init-project.test.ts +43 -31
  254. package/node_modules/@sdd-agent-platform/core/src/config/init-project.ts +14 -11
  255. package/node_modules/@sdd-agent-platform/core/src/config/project-config.ts +10 -4
  256. package/node_modules/@sdd-agent-platform/core/src/config/starter-documents.ts +12 -25
  257. package/node_modules/@sdd-agent-platform/core/src/context/build-package.ts +2 -8
  258. package/node_modules/@sdd-agent-platform/core/src/context/context-build.test.ts +3 -2
  259. package/node_modules/@sdd-agent-platform/core/src/context/evidence-summary.ts +27 -8
  260. package/node_modules/@sdd-agent-platform/core/src/context/log-worker.ts +2 -2
  261. package/node_modules/@sdd-agent-platform/core/src/context-offload/contracts.ts +1 -1
  262. package/node_modules/@sdd-agent-platform/core/src/contracts.ts +2 -1
  263. package/node_modules/@sdd-agent-platform/core/src/delegation/model.ts +3 -0
  264. package/node_modules/@sdd-agent-platform/core/src/delegation/validation.ts +8 -5
  265. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/document-chain.ts +1 -1
  266. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/project.ts +8 -8
  267. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/registries.ts +0 -1
  268. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-evidence.ts +4 -4
  269. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-trust.ts +0 -21
  270. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/runtime-contracts.ts +1 -1
  271. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.test.ts +143 -45
  272. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.ts +193 -58
  273. package/node_modules/@sdd-agent-platform/core/src/evidence/lookup.ts +15 -7
  274. package/node_modules/@sdd-agent-platform/core/src/evidence-runtime/contracts.ts +0 -1
  275. package/node_modules/@sdd-agent-platform/core/src/execution/background-executor.test.ts +50 -2
  276. package/node_modules/@sdd-agent-platform/core/src/execution/background-executor.ts +4 -4
  277. package/node_modules/@sdd-agent-platform/core/src/execution/foreground-subagents.test.ts +11 -2
  278. package/node_modules/@sdd-agent-platform/core/src/execution/foreground-subagents.ts +3 -3
  279. package/node_modules/@sdd-agent-platform/core/src/execution/host-invocation.ts +5 -4
  280. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.test.ts +12 -1
  281. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.ts +3 -2
  282. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.test.ts +1 -1
  283. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.ts +2 -2
  284. package/node_modules/@sdd-agent-platform/core/src/execution/wave-executor.test.ts +10 -0
  285. package/node_modules/@sdd-agent-platform/core/src/governance/policy.test.ts +8 -0
  286. package/node_modules/@sdd-agent-platform/core/src/governance/policy.ts +2 -2
  287. package/node_modules/@sdd-agent-platform/core/src/instructions.test.ts +33 -18
  288. package/node_modules/@sdd-agent-platform/core/src/instructions.ts +55 -62
  289. package/node_modules/@sdd-agent-platform/core/src/lifecycle/decision-gate.test.ts +1 -1
  290. package/node_modules/@sdd-agent-platform/core/src/lifecycle/decision-gate.ts +1 -1
  291. package/node_modules/@sdd-agent-platform/core/src/lifecycle/ship.test.ts +47 -0
  292. package/node_modules/@sdd-agent-platform/core/src/lifecycle/ship.ts +25 -8
  293. package/node_modules/@sdd-agent-platform/core/src/orchestration/contracts.ts +1 -1
  294. package/node_modules/@sdd-agent-platform/core/src/orchestration/runtime.ts +74 -22
  295. package/node_modules/@sdd-agent-platform/core/src/phase8-contracts.test.ts +2 -3
  296. package/node_modules/@sdd-agent-platform/core/src/phase8-risk-kernel.test.ts +3 -3
  297. package/node_modules/@sdd-agent-platform/core/src/registries/agent-capability-catalog.ts +82 -35
  298. package/node_modules/@sdd-agent-platform/core/src/registries/agent-registry.ts +15 -15
  299. package/node_modules/@sdd-agent-platform/core/src/registries/agent-runtime-static.ts +1 -1
  300. package/node_modules/@sdd-agent-platform/core/src/registries/capability-sources.ts +1 -1
  301. package/node_modules/@sdd-agent-platform/core/src/registries/command-team-runtime.ts +10 -10
  302. package/node_modules/@sdd-agent-platform/core/src/registries/eval-learning-context.ts +4 -4
  303. package/node_modules/@sdd-agent-platform/core/src/registries/query-status.ts +2 -2
  304. package/node_modules/@sdd-agent-platform/core/src/registries/registries.test.ts +18 -2
  305. package/node_modules/@sdd-agent-platform/core/src/registries/tool-capabilities.ts +3 -3
  306. package/node_modules/@sdd-agent-platform/core/src/registries/tool-plugins.ts +2 -2
  307. package/node_modules/@sdd-agent-platform/core/src/registries/worker-adapters.ts +11 -11
  308. package/node_modules/@sdd-agent-platform/core/src/registries/workflow-gates.ts +12 -12
  309. package/node_modules/@sdd-agent-platform/core/src/risk/contracts.ts +2 -2
  310. package/node_modules/@sdd-agent-platform/core/src/risk/kernel.ts +4 -4
  311. package/node_modules/@sdd-agent-platform/core/src/risk/legacy-adapters.ts +4 -7
  312. package/node_modules/@sdd-agent-platform/core/src/risk/workflow-gates.ts +20 -18
  313. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime-config.ts +1 -1
  314. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime.ts +2 -0
  315. package/node_modules/@sdd-agent-platform/core/src/router/route-projection.ts +1 -1
  316. package/node_modules/@sdd-agent-platform/core/src/router/route-sdd-task.test.ts +241 -4
  317. package/node_modules/@sdd-agent-platform/core/src/router/routing.ts +47 -15
  318. package/node_modules/@sdd-agent-platform/core/src/router/runtime-import.ts +453 -0
  319. package/node_modules/@sdd-agent-platform/core/src/router/runtime-validation.ts +2 -2
  320. package/node_modules/@sdd-agent-platform/core/src/router/stage-route-binding.ts +279 -0
  321. package/node_modules/@sdd-agent-platform/core/src/router.ts +2 -0
  322. package/node_modules/@sdd-agent-platform/core/src/run-state/artifacts.ts +132 -10
  323. package/node_modules/@sdd-agent-platform/core/src/run-state/inspect-run.ts +7 -7
  324. package/node_modules/@sdd-agent-platform/core/src/run-state/model.ts +31 -8
  325. package/node_modules/@sdd-agent-platform/core/src/run-state/run-index.ts +1 -5
  326. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.test.ts +50 -2
  327. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.ts +39 -29
  328. package/node_modules/@sdd-agent-platform/core/src/run-state/task-evidence.ts +62 -16
  329. package/node_modules/@sdd-agent-platform/core/src/run-state/timing.ts +146 -0
  330. package/node_modules/@sdd-agent-platform/core/src/run-state.ts +1 -0
  331. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/build.ts +0 -3
  332. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/findings.ts +6 -46
  333. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/model.ts +1 -13
  334. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis.test.ts +0 -2
  335. package/node_modules/@sdd-agent-platform/core/src/runtime-paths.ts +77 -0
  336. package/node_modules/@sdd-agent-platform/core/src/runtime-projection-p0.test.ts +96 -0
  337. package/node_modules/@sdd-agent-platform/core/src/runtime-projection-p0.ts +292 -0
  338. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/document-hashes.ts +109 -10
  339. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/run-binding.ts +8 -6
  340. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.test.ts +123 -1
  341. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.ts +58 -43
  342. package/node_modules/@sdd-agent-platform/core/src/stage-artifacts.ts +450 -0
  343. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration-contracts.ts +322 -0
  344. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration.test.ts +2903 -0
  345. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration.ts +5831 -0
  346. package/node_modules/@sdd-agent-platform/core/src/stage-runtime/runtime.test.ts +1 -1
  347. package/node_modules/@sdd-agent-platform/core/src/stage-runtime/runtime.ts +9 -1
  348. package/node_modules/@sdd-agent-platform/core/src/status/project-status.test.ts +239 -16
  349. package/node_modules/@sdd-agent-platform/core/src/status/project-status.ts +249 -23
  350. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.test.ts +196 -4
  351. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.ts +860 -54
  352. package/node_modules/@sdd-agent-platform/core/src/subagents/contracts.ts +1 -1
  353. package/node_modules/@sdd-agent-platform/core/src/subagents/runtime.test.ts +3 -3
  354. package/node_modules/@sdd-agent-platform/core/src/subagents/runtime.ts +7 -7
  355. package/node_modules/@sdd-agent-platform/core/src/test-support/fixtures.ts +1 -1
  356. package/node_modules/@sdd-agent-platform/core/src/test-support/run-state.ts +9 -23
  357. package/node_modules/@sdd-agent-platform/core/src/truth-reconciliation.test.ts +72 -0
  358. package/node_modules/@sdd-agent-platform/core/src/truth-reconciliation.ts +177 -0
  359. package/node_modules/@sdd-agent-platform/core/src/verification/goal-verify.test.ts +13 -87
  360. package/node_modules/@sdd-agent-platform/core/src/verification/goal-verify.ts +27 -56
  361. package/node_modules/@sdd-agent-platform/core/src/verification/rendering.ts +10 -54
  362. package/node_modules/@sdd-agent-platform/core/src/verification/review-gate.test.ts +8 -1
  363. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.test.ts +93 -79
  364. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.ts +166 -154
  365. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.test.ts +100 -47
  366. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.ts +265 -107
  367. package/node_modules/@sdd-agent-platform/core/src/verification/validation-cache.ts +106 -0
  368. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.test.ts +47 -5
  369. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.ts +48 -5
  370. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.test.ts +15 -31
  371. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.ts +9 -33
  372. package/node_modules/@sdd-agent-platform/core/src/work-units/contracts.ts +1 -1
  373. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/evidence-packet.ts +246 -17
  374. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.test.ts +339 -3
  375. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.ts +53 -14
  376. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.test.ts +45 -8
  377. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.ts +45 -6
  378. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/types.ts +6 -5
  379. package/node_modules/@sdd-agent-platform/core/src/workflow-state/affected-file-conflicts.ts +1 -3
  380. package/node_modules/@sdd-agent-platform/core/src/workflow-state/dependencies.ts +1 -1
  381. package/node_modules/@sdd-agent-platform/core/src/workflow-state/latest-eligible-run.ts +75 -7
  382. package/node_modules/@sdd-agent-platform/core/src/workflow-state/migration-recovery.ts +158 -0
  383. package/node_modules/@sdd-agent-platform/core/src/workflow-state/repair-contract.ts +77 -0
  384. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve-task-run.ts +114 -0
  385. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.test.ts +518 -25
  386. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.ts +670 -41
  387. package/node_modules/@sdd-agent-platform/core/src/workflow-state/runtime-projections.ts +712 -0
  388. package/package.json +1 -1
  389. package/packages/cli/dist/args.js +2 -2
  390. package/packages/cli/dist/args.js.map +1 -1
  391. package/packages/cli/dist/commands/ai-tools.js +13 -2
  392. package/packages/cli/dist/commands/ai-tools.js.map +1 -1
  393. package/packages/cli/dist/commands/context.js +1 -1
  394. package/packages/cli/dist/commands/context.js.map +1 -1
  395. package/packages/cli/dist/commands/execution.js +49 -1
  396. package/packages/cli/dist/commands/execution.js.map +1 -1
  397. package/packages/cli/dist/commands/governance.js +1 -1
  398. package/packages/cli/dist/commands/governance.js.map +1 -1
  399. package/packages/cli/dist/commands/init.js +6 -1
  400. package/packages/cli/dist/commands/init.js.map +1 -1
  401. package/packages/cli/dist/commands/lifecycle.js +15 -2
  402. package/packages/cli/dist/commands/lifecycle.js.map +1 -1
  403. package/packages/cli/dist/commands/registry/runtime.js +48 -2
  404. package/packages/cli/dist/commands/registry/runtime.js.map +1 -1
  405. package/packages/cli/dist/commands/run.js +52 -2
  406. package/packages/cli/dist/commands/run.js.map +1 -1
  407. package/packages/cli/dist/commands/stage-close.d.ts +6 -0
  408. package/packages/cli/dist/commands/stage-close.js +295 -0
  409. package/packages/cli/dist/commands/stage-close.js.map +1 -0
  410. package/packages/cli/dist/commands/status.js +68 -2
  411. package/packages/cli/dist/commands/status.js.map +1 -1
  412. package/packages/cli/dist/commands/test.js +180 -2
  413. package/packages/cli/dist/commands/test.js.map +1 -1
  414. package/packages/cli/dist/commands/verifies.js +7 -5
  415. package/packages/cli/dist/commands/verifies.js.map +1 -1
  416. package/packages/cli/dist/commands/verify.js +222 -26
  417. package/packages/cli/dist/commands/verify.js.map +1 -1
  418. package/packages/cli/dist/dispatch.js +4 -9
  419. package/packages/cli/dist/dispatch.js.map +1 -1
  420. package/packages/cli/dist/help.js +27 -26
  421. package/packages/cli/dist/help.js.map +1 -1
  422. package/packages/cli/dist/renderers/doctor.js +1 -1
  423. package/packages/cli/dist/renderers/doctor.js.map +1 -1
  424. package/packages/cli/dist/renderers/execution.js +1 -1
  425. package/packages/cli/dist/renderers/execution.js.map +1 -1
  426. package/packages/cli/dist/renderers/json.d.ts +1 -0
  427. package/packages/cli/dist/renderers/json.js +3 -0
  428. package/packages/cli/dist/renderers/json.js.map +1 -1
  429. package/packages/cli/dist/renderers/registry-runtime.d.ts +2 -1
  430. package/packages/cli/dist/renderers/registry-runtime.js +20 -0
  431. package/packages/cli/dist/renderers/registry-runtime.js.map +1 -1
  432. package/packages/cli/dist/renderers/router.js +1 -1
  433. package/packages/cli/dist/renderers/router.js.map +1 -1
  434. package/packages/cli/dist/renderers/workflow.d.ts +0 -4
  435. package/packages/cli/dist/renderers/workflow.js +30 -89
  436. package/packages/cli/dist/renderers/workflow.js.map +1 -1
  437. package/packages/cli/dist/skill-import-args.d.ts +10 -0
  438. package/packages/cli/dist/skill-import-args.js +47 -0
  439. package/packages/cli/dist/skill-import-args.js.map +1 -0
  440. package/packages/cli/dist/tsconfig.tsbuildinfo +1 -1
  441. package/packages/cli/package.json +2 -2
  442. package/packages/core/dist/ai-tools.js +67 -69
  443. package/packages/core/dist/ai-tools.js.map +1 -1
  444. package/packages/core/dist/artifacts/ingestion.js +64 -9
  445. package/packages/core/dist/artifacts/ingestion.js.map +1 -1
  446. package/packages/core/dist/artifacts/sdd-evidence.js +0 -1
  447. package/packages/core/dist/artifacts/sdd-evidence.js.map +1 -1
  448. package/packages/core/dist/artifacts/sdd-result.js +26 -17
  449. package/packages/core/dist/artifacts/sdd-result.js.map +1 -1
  450. package/packages/core/dist/config/init-project.d.ts +3 -0
  451. package/packages/core/dist/config/init-project.js +12 -9
  452. package/packages/core/dist/config/init-project.js.map +1 -1
  453. package/packages/core/dist/config/project-config.d.ts +3 -1
  454. package/packages/core/dist/config/project-config.js +7 -3
  455. package/packages/core/dist/config/project-config.js.map +1 -1
  456. package/packages/core/dist/config/starter-documents.d.ts +4 -4
  457. package/packages/core/dist/config/starter-documents.js +12 -25
  458. package/packages/core/dist/config/starter-documents.js.map +1 -1
  459. package/packages/core/dist/context/build-package.d.ts +1 -1
  460. package/packages/core/dist/context/build-package.js +1 -7
  461. package/packages/core/dist/context/build-package.js.map +1 -1
  462. package/packages/core/dist/context/evidence-summary.js +26 -8
  463. package/packages/core/dist/context/evidence-summary.js.map +1 -1
  464. package/packages/core/dist/context/log-worker.js +2 -2
  465. package/packages/core/dist/context/log-worker.js.map +1 -1
  466. package/packages/core/dist/context-offload/contracts.d.ts +1 -1
  467. package/packages/core/dist/contracts.d.ts +2 -1
  468. package/packages/core/dist/contracts.js +1 -0
  469. package/packages/core/dist/contracts.js.map +1 -1
  470. package/packages/core/dist/delegation/model.d.ts +3 -0
  471. package/packages/core/dist/delegation/validation.d.ts +3 -0
  472. package/packages/core/dist/delegation/validation.js +7 -4
  473. package/packages/core/dist/delegation/validation.js.map +1 -1
  474. package/packages/core/dist/doctor/checks/document-chain.js +1 -1
  475. package/packages/core/dist/doctor/checks/document-chain.js.map +1 -1
  476. package/packages/core/dist/doctor/checks/project.js +8 -8
  477. package/packages/core/dist/doctor/checks/project.js.map +1 -1
  478. package/packages/core/dist/doctor/checks/registries.js +0 -1
  479. package/packages/core/dist/doctor/checks/registries.js.map +1 -1
  480. package/packages/core/dist/doctor/checks/run-evidence.js +4 -4
  481. package/packages/core/dist/doctor/checks/run-evidence.js.map +1 -1
  482. package/packages/core/dist/doctor/checks/run-trust.js +0 -24
  483. package/packages/core/dist/doctor/checks/run-trust.js.map +1 -1
  484. package/packages/core/dist/doctor/checks/runtime-contracts.js +1 -1
  485. package/packages/core/dist/doctor/checks/runtime-contracts.js.map +1 -1
  486. package/packages/core/dist/doctor/doctor.js +178 -58
  487. package/packages/core/dist/doctor/doctor.js.map +1 -1
  488. package/packages/core/dist/evidence/lookup.js +14 -7
  489. package/packages/core/dist/evidence/lookup.js.map +1 -1
  490. package/packages/core/dist/evidence-runtime/contracts.d.ts +0 -1
  491. package/packages/core/dist/execution/background-executor.js +4 -4
  492. package/packages/core/dist/execution/background-executor.js.map +1 -1
  493. package/packages/core/dist/execution/foreground-subagents.js +3 -3
  494. package/packages/core/dist/execution/foreground-subagents.js.map +1 -1
  495. package/packages/core/dist/execution/host-invocation.js +5 -4
  496. package/packages/core/dist/execution/host-invocation.js.map +1 -1
  497. package/packages/core/dist/execution/resident-worker.js +3 -2
  498. package/packages/core/dist/execution/resident-worker.js.map +1 -1
  499. package/packages/core/dist/execution/stage-team-runtime.js +2 -2
  500. package/packages/core/dist/execution/stage-team-runtime.js.map +1 -1
  501. package/packages/core/dist/governance/policy.d.ts +1 -1
  502. package/packages/core/dist/governance/policy.js +1 -1
  503. package/packages/core/dist/governance/policy.js.map +1 -1
  504. package/packages/core/dist/instructions.d.ts +1 -1
  505. package/packages/core/dist/instructions.js +54 -61
  506. package/packages/core/dist/instructions.js.map +1 -1
  507. package/packages/core/dist/lifecycle/decision-gate.js +1 -1
  508. package/packages/core/dist/lifecycle/decision-gate.js.map +1 -1
  509. package/packages/core/dist/lifecycle/ship.d.ts +1 -0
  510. package/packages/core/dist/lifecycle/ship.js +24 -8
  511. package/packages/core/dist/lifecycle/ship.js.map +1 -1
  512. package/packages/core/dist/orchestration/contracts.d.ts +1 -1
  513. package/packages/core/dist/orchestration/runtime.d.ts +12 -2
  514. package/packages/core/dist/orchestration/runtime.js +62 -21
  515. package/packages/core/dist/orchestration/runtime.js.map +1 -1
  516. package/packages/core/dist/registries/agent-capability-catalog.d.ts +5 -2
  517. package/packages/core/dist/registries/agent-capability-catalog.js +69 -27
  518. package/packages/core/dist/registries/agent-capability-catalog.js.map +1 -1
  519. package/packages/core/dist/registries/agent-registry.js +15 -15
  520. package/packages/core/dist/registries/agent-registry.js.map +1 -1
  521. package/packages/core/dist/registries/agent-runtime-static.js +1 -1
  522. package/packages/core/dist/registries/agent-runtime-static.js.map +1 -1
  523. package/packages/core/dist/registries/capability-sources.js +1 -1
  524. package/packages/core/dist/registries/command-team-runtime.d.ts +1 -1
  525. package/packages/core/dist/registries/command-team-runtime.js +9 -9
  526. package/packages/core/dist/registries/command-team-runtime.js.map +1 -1
  527. package/packages/core/dist/registries/eval-learning-context.js +4 -4
  528. package/packages/core/dist/registries/eval-learning-context.js.map +1 -1
  529. package/packages/core/dist/registries/query-status.js +2 -2
  530. package/packages/core/dist/registries/query-status.js.map +1 -1
  531. package/packages/core/dist/registries/tool-capabilities.js +3 -3
  532. package/packages/core/dist/registries/tool-capabilities.js.map +1 -1
  533. package/packages/core/dist/registries/tool-plugins.js +2 -2
  534. package/packages/core/dist/registries/tool-plugins.js.map +1 -1
  535. package/packages/core/dist/registries/worker-adapters.js +11 -11
  536. package/packages/core/dist/registries/worker-adapters.js.map +1 -1
  537. package/packages/core/dist/registries/workflow-gates.js +12 -12
  538. package/packages/core/dist/registries/workflow-gates.js.map +1 -1
  539. package/packages/core/dist/risk/contracts.d.ts +2 -2
  540. package/packages/core/dist/risk/kernel.js +4 -4
  541. package/packages/core/dist/risk/kernel.js.map +1 -1
  542. package/packages/core/dist/risk/legacy-adapters.js +4 -7
  543. package/packages/core/dist/risk/legacy-adapters.js.map +1 -1
  544. package/packages/core/dist/risk/workflow-gates.d.ts +2 -2
  545. package/packages/core/dist/risk/workflow-gates.js +19 -17
  546. package/packages/core/dist/risk/workflow-gates.js.map +1 -1
  547. package/packages/core/dist/router/agent-runtime-config.js +1 -1
  548. package/packages/core/dist/router/agent-runtime-config.js.map +1 -1
  549. package/packages/core/dist/router/agent-runtime.d.ts +2 -0
  550. package/packages/core/dist/router/route-projection.js +1 -1
  551. package/packages/core/dist/router/route-projection.js.map +1 -1
  552. package/packages/core/dist/router/routing.js +45 -15
  553. package/packages/core/dist/router/routing.js.map +1 -1
  554. package/packages/core/dist/router/runtime-import.d.ts +28 -0
  555. package/packages/core/dist/router/runtime-import.js +373 -0
  556. package/packages/core/dist/router/runtime-import.js.map +1 -0
  557. package/packages/core/dist/router/runtime-validation.js +2 -2
  558. package/packages/core/dist/router/runtime-validation.js.map +1 -1
  559. package/packages/core/dist/router/stage-route-binding.d.ts +37 -0
  560. package/packages/core/dist/router/stage-route-binding.js +235 -0
  561. package/packages/core/dist/router/stage-route-binding.js.map +1 -0
  562. package/packages/core/dist/router.d.ts +2 -0
  563. package/packages/core/dist/router.js +2 -0
  564. package/packages/core/dist/router.js.map +1 -1
  565. package/packages/core/dist/run-state/artifacts.d.ts +16 -0
  566. package/packages/core/dist/run-state/artifacts.js +126 -9
  567. package/packages/core/dist/run-state/artifacts.js.map +1 -1
  568. package/packages/core/dist/run-state/inspect-run.d.ts +0 -2
  569. package/packages/core/dist/run-state/inspect-run.js +7 -5
  570. package/packages/core/dist/run-state/inspect-run.js.map +1 -1
  571. package/packages/core/dist/run-state/model.d.ts +28 -8
  572. package/packages/core/dist/run-state/run-index.d.ts +0 -2
  573. package/packages/core/dist/run-state/run-index.js +1 -3
  574. package/packages/core/dist/run-state/run-index.js.map +1 -1
  575. package/packages/core/dist/run-state/run-state.js +37 -27
  576. package/packages/core/dist/run-state/run-state.js.map +1 -1
  577. package/packages/core/dist/run-state/task-evidence.d.ts +5 -2
  578. package/packages/core/dist/run-state/task-evidence.js +53 -14
  579. package/packages/core/dist/run-state/task-evidence.js.map +1 -1
  580. package/packages/core/dist/run-state/timing.d.ts +8 -0
  581. package/packages/core/dist/run-state/timing.js +131 -0
  582. package/packages/core/dist/run-state/timing.js.map +1 -0
  583. package/packages/core/dist/run-state.d.ts +1 -0
  584. package/packages/core/dist/run-state.js +1 -0
  585. package/packages/core/dist/run-state.js.map +1 -1
  586. package/packages/core/dist/runtime-analysis/build.js +0 -3
  587. package/packages/core/dist/runtime-analysis/build.js.map +1 -1
  588. package/packages/core/dist/runtime-analysis/findings.js +5 -44
  589. package/packages/core/dist/runtime-analysis/findings.js.map +1 -1
  590. package/packages/core/dist/runtime-analysis/model.d.ts +1 -17
  591. package/packages/core/dist/runtime-paths.d.ts +10 -0
  592. package/packages/core/dist/runtime-paths.js +65 -0
  593. package/packages/core/dist/runtime-paths.js.map +1 -1
  594. package/packages/core/dist/runtime-projection-p0.d.ts +64 -0
  595. package/packages/core/dist/runtime-projection-p0.js +200 -0
  596. package/packages/core/dist/runtime-projection-p0.js.map +1 -0
  597. package/packages/core/dist/sdd-docs/document-hashes.d.ts +2 -0
  598. package/packages/core/dist/sdd-docs/document-hashes.js +97 -10
  599. package/packages/core/dist/sdd-docs/document-hashes.js.map +1 -1
  600. package/packages/core/dist/sdd-docs/run-binding.d.ts +1 -1
  601. package/packages/core/dist/sdd-docs/run-binding.js +8 -6
  602. package/packages/core/dist/sdd-docs/run-binding.js.map +1 -1
  603. package/packages/core/dist/sdd-docs/task-parser.d.ts +1 -0
  604. package/packages/core/dist/sdd-docs/task-parser.js +55 -34
  605. package/packages/core/dist/sdd-docs/task-parser.js.map +1 -1
  606. package/packages/core/dist/stage-artifacts.d.ts +55 -0
  607. package/packages/core/dist/stage-artifacts.js +322 -0
  608. package/packages/core/dist/stage-artifacts.js.map +1 -0
  609. package/packages/core/dist/stage-collaboration-contracts.d.ts +55 -0
  610. package/packages/core/dist/stage-collaboration-contracts.js +241 -0
  611. package/packages/core/dist/stage-collaboration-contracts.js.map +1 -0
  612. package/packages/core/dist/stage-collaboration.d.ts +888 -0
  613. package/packages/core/dist/stage-collaboration.js +3870 -0
  614. package/packages/core/dist/stage-collaboration.js.map +1 -0
  615. package/packages/core/dist/stage-runtime/runtime.js +8 -1
  616. package/packages/core/dist/stage-runtime/runtime.js.map +1 -1
  617. package/packages/core/dist/status/project-status.d.ts +44 -1
  618. package/packages/core/dist/status/project-status.js +170 -23
  619. package/packages/core/dist/status/project-status.js.map +1 -1
  620. package/packages/core/dist/storage/runtime-store.d.ts +170 -18
  621. package/packages/core/dist/storage/runtime-store.js +544 -32
  622. package/packages/core/dist/storage/runtime-store.js.map +1 -1
  623. package/packages/core/dist/subagents/contracts.d.ts +1 -1
  624. package/packages/core/dist/subagents/runtime.js +7 -7
  625. package/packages/core/dist/subagents/runtime.js.map +1 -1
  626. package/packages/core/dist/test-support/fixtures.js +1 -1
  627. package/packages/core/dist/test-support/run-state.d.ts +1 -1
  628. package/packages/core/dist/test-support/run-state.js +8 -23
  629. package/packages/core/dist/test-support/run-state.js.map +1 -1
  630. package/packages/core/dist/truth-reconciliation.d.ts +44 -0
  631. package/packages/core/dist/truth-reconciliation.js +138 -0
  632. package/packages/core/dist/truth-reconciliation.js.map +1 -0
  633. package/packages/core/dist/tsconfig.tsbuildinfo +1 -1
  634. package/packages/core/dist/verification/goal-verify.d.ts +0 -1
  635. package/packages/core/dist/verification/goal-verify.js +28 -53
  636. package/packages/core/dist/verification/goal-verify.js.map +1 -1
  637. package/packages/core/dist/verification/rendering.d.ts +0 -2
  638. package/packages/core/dist/verification/rendering.js +10 -50
  639. package/packages/core/dist/verification/rendering.js.map +1 -1
  640. package/packages/core/dist/verification/single-task-loop.d.ts +0 -1
  641. package/packages/core/dist/verification/single-task-loop.js +159 -150
  642. package/packages/core/dist/verification/single-task-loop.js.map +1 -1
  643. package/packages/core/dist/verification/test-runtime.d.ts +12 -2
  644. package/packages/core/dist/verification/test-runtime.js +238 -103
  645. package/packages/core/dist/verification/test-runtime.js.map +1 -1
  646. package/packages/core/dist/verification/validation-cache.d.ts +26 -0
  647. package/packages/core/dist/verification/validation-cache.js +73 -0
  648. package/packages/core/dist/verification/validation-cache.js.map +1 -0
  649. package/packages/core/dist/verification/validation-wave.d.ts +18 -0
  650. package/packages/core/dist/verification/validation-wave.js +27 -5
  651. package/packages/core/dist/verification/validation-wave.js.map +1 -1
  652. package/packages/core/dist/verification/verify-contract.d.ts +1 -1
  653. package/packages/core/dist/verification/verify-contract.js +9 -32
  654. package/packages/core/dist/verification/verify-contract.js.map +1 -1
  655. package/packages/core/dist/work-units/contracts.d.ts +1 -1
  656. package/packages/core/dist/workflow-gate/evidence-packet.js +228 -15
  657. package/packages/core/dist/workflow-gate/evidence-packet.js.map +1 -1
  658. package/packages/core/dist/workflow-gate/hard-checks.js +49 -15
  659. package/packages/core/dist/workflow-gate/hard-checks.js.map +1 -1
  660. package/packages/core/dist/workflow-gate/policy.js +42 -6
  661. package/packages/core/dist/workflow-gate/policy.js.map +1 -1
  662. package/packages/core/dist/workflow-gate/types.d.ts +4 -5
  663. package/packages/core/dist/workflow-state/affected-file-conflicts.d.ts +0 -1
  664. package/packages/core/dist/workflow-state/affected-file-conflicts.js +1 -2
  665. package/packages/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  666. package/packages/core/dist/workflow-state/dependencies.js +1 -1
  667. package/packages/core/dist/workflow-state/latest-eligible-run.d.ts +0 -1
  668. package/packages/core/dist/workflow-state/latest-eligible-run.js +72 -6
  669. package/packages/core/dist/workflow-state/latest-eligible-run.js.map +1 -1
  670. package/packages/core/dist/workflow-state/migration-recovery.d.ts +40 -0
  671. package/packages/core/dist/workflow-state/migration-recovery.js +110 -0
  672. package/packages/core/dist/workflow-state/migration-recovery.js.map +1 -0
  673. package/packages/core/dist/workflow-state/repair-contract.d.ts +12 -0
  674. package/packages/core/dist/workflow-state/repair-contract.js +63 -0
  675. package/packages/core/dist/workflow-state/repair-contract.js.map +1 -0
  676. package/packages/core/dist/workflow-state/resolve-task-run.d.ts +21 -0
  677. package/packages/core/dist/workflow-state/resolve-task-run.js +95 -0
  678. package/packages/core/dist/workflow-state/resolve-task-run.js.map +1 -0
  679. package/packages/core/dist/workflow-state/resolve.d.ts +55 -5
  680. package/packages/core/dist/workflow-state/resolve.js +538 -34
  681. package/packages/core/dist/workflow-state/resolve.js.map +1 -1
  682. package/packages/core/dist/workflow-state/runtime-projections.d.ts +228 -0
  683. package/packages/core/dist/workflow-state/runtime-projections.js +452 -0
  684. package/packages/core/dist/workflow-state/runtime-projections.js.map +1 -0
  685. package/packages/core/package.json +3 -3
  686. package/node_modules/@sdd-agent-platform/core/dist/doctor/render.d.ts +0 -2
  687. package/node_modules/@sdd-agent-platform/core/dist/doctor/render.js +0 -44
  688. package/node_modules/@sdd-agent-platform/core/dist/doctor/render.js.map +0 -1
  689. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.d.ts +0 -17
  690. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js +0 -243
  691. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js.map +0 -1
  692. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.d.ts +0 -110
  693. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js +0 -497
  694. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js.map +0 -1
  695. package/node_modules/@sdd-agent-platform/core/dist/sync-back.d.ts +0 -2
  696. package/node_modules/@sdd-agent-platform/core/dist/sync-back.js +0 -3
  697. package/node_modules/@sdd-agent-platform/core/dist/sync-back.js.map +0 -1
  698. package/node_modules/@sdd-agent-platform/core/src/sync-back/apply.ts +0 -270
  699. package/node_modules/@sdd-agent-platform/core/src/sync-back/inspect.ts +0 -655
  700. package/node_modules/@sdd-agent-platform/core/src/sync-back/sync-back.test.ts +0 -569
  701. package/node_modules/@sdd-agent-platform/core/src/sync-back.ts +0 -2
  702. package/packages/cli/dist/commands/artifact.d.ts +0 -6
  703. package/packages/cli/dist/commands/artifact.js +0 -168
  704. package/packages/cli/dist/commands/artifact.js.map +0 -1
  705. package/packages/cli/dist/commands/sync-back.d.ts +0 -6
  706. package/packages/cli/dist/commands/sync-back.js +0 -82
  707. package/packages/cli/dist/commands/sync-back.js.map +0 -1
  708. package/packages/cli/dist/renderers/artifacts.d.ts +0 -5
  709. package/packages/cli/dist/renderers/artifacts.js +0 -43
  710. package/packages/cli/dist/renderers/artifacts.js.map +0 -1
  711. package/packages/core/dist/doctor/render.d.ts +0 -2
  712. package/packages/core/dist/doctor/render.js +0 -44
  713. package/packages/core/dist/doctor/render.js.map +0 -1
  714. package/packages/core/dist/sync-back/apply.d.ts +0 -17
  715. package/packages/core/dist/sync-back/apply.js +0 -243
  716. package/packages/core/dist/sync-back/apply.js.map +0 -1
  717. package/packages/core/dist/sync-back/inspect.d.ts +0 -110
  718. package/packages/core/dist/sync-back/inspect.js +0 -497
  719. package/packages/core/dist/sync-back/inspect.js.map +0 -1
  720. package/packages/core/dist/sync-back.d.ts +0 -2
  721. package/packages/core/dist/sync-back.js +0 -3
  722. package/packages/core/dist/sync-back.js.map +0 -1
@@ -3,15 +3,17 @@ import { mkdir, readFile } from 'node:fs/promises';
3
3
  import { getRuntimeStorePath, getSddDir } from '../runtime-paths.js';
4
4
  import { exists } from './json-io.js';
5
5
  import type { InvocationLedgerEntry, RuntimeEvent, RunState } from '../run-state/model.js';
6
- import { RUNTIME_PROJECTION_ENVELOPE_CONTRACT_VERSION, type RuntimeProjectionEnvelope, type RuntimeProjectionStaleness } from '../contracts.js';
6
+ import { INVOCATION_LEDGER_CONTRACT_VERSION, RUNTIME_PROJECTION_ENVELOPE_CONTRACT_VERSION, type RuntimeProjectionEnvelope, type RuntimeProjectionStaleness } from '../contracts.js';
7
7
  import type { AgentExecutionRecord, TeamSessionRecord } from '../router/agent-runtime.js';
8
8
  import type { ResidentWorkerRuntimeRecord } from '../execution/resident-worker.js';
9
9
  import { assertAdvisoryAssessment, assertValidFanInEvidenceSet, assertValidStageRoleResult, type FanInEvidenceSetRecord, type LlmAdvisorAssessmentRecord, type StageRoleResultRecord, type StageTeamSessionRecord } from '../execution/stage-team-runtime.js';
10
10
  import type { WorkflowGateDecision, WorkflowGateDecisionKind } from '../workflow-gate/types.js';
11
+ import type { RegisteredStageArtifact } from '../stage-artifacts.js';
12
+ import type { RegisteredStageCollaborationContract } from '../stage-collaboration-contracts.js';
11
13
 
12
14
 
13
- export const RUNTIME_STORE_SCHEMA_VERSION = 6;
14
- export const RUNTIME_STORE_CONTRACT_VERSION = 'phase-8.17-validation-wave-runtime-v6';
15
+ export const RUNTIME_STORE_SCHEMA_VERSION = 12;
16
+ export const RUNTIME_STORE_CONTRACT_VERSION = 'phase-9.1-stage-collaboration-contracts-runtime-v12';
15
17
 
16
18
  export type RuntimeStoreIssueCode = 'STORE_UNAVAILABLE' | 'SCHEMA_MISMATCH' | 'LEGACY_IMPORT_FAILED';
17
19
 
@@ -47,7 +49,7 @@ export interface RuntimeStoreDoctorCheck {
47
49
  action?: string;
48
50
  }
49
51
 
50
- export type RuntimeArtifactPayloadStatus = 'active' | 'candidate' | 'rejected' | 'superseded';
52
+ export type RuntimeArtifactPayloadStatus = 'active' | 'candidate' | 'partial' | 'active_attempt' | 'rejected' | 'superseded' | 'quarantined' | 'stale';
51
53
 
52
54
  export interface RuntimeArtifactPayloadRecord {
53
55
  payloadId: string;
@@ -66,21 +68,50 @@ export interface RuntimeArtifactPayloadRecord {
66
68
  payload: unknown;
67
69
  }
68
70
 
69
- export interface RuntimeSyncBackDecisionRecord {
70
- decisionId: string;
71
- runId: string;
72
- branch: string;
73
- taskId: string | null;
74
- status: string;
75
- proposalPath: string | null;
76
- proposalDigest: string | null;
77
- proposalPayloadId: string | null;
78
- reasons: string[];
71
+ export type RuntimeEvidenceSetScopeKind = 'task' | 'batch' | 'wave' | 'ship';
72
+ export type RuntimeEvidenceSetStatus = 'candidate' | 'accepted' | 'partial' | 'rejected' | 'superseded' | 'quarantined' | 'stale';
73
+
74
+ export interface RuntimeEvidenceSetItemRecord {
75
+ evidenceSetId: string;
76
+ payloadId: string;
77
+ logicalRef: string;
78
+ role: string;
79
+ required: boolean;
80
+ digestAtSelection: string;
81
+ }
82
+
83
+ export interface RuntimeEvidenceSetRecord {
84
+ evidenceSetId: string;
85
+ branchSlug: string;
86
+ scopeKind: RuntimeEvidenceSetScopeKind;
87
+ scopeId: string;
88
+ sourceRunId: string | null;
89
+ documentContractHashes: Record<string, string | null>;
90
+ gateDecisionId: string | null;
91
+ status: RuntimeEvidenceSetStatus;
79
92
  createdAt: string;
80
- updatedAt: string;
93
+ items: RuntimeEvidenceSetItemRecord[];
81
94
  payload: unknown;
82
95
  }
83
96
 
97
+ export interface RuntimeSelectionPointerRecord {
98
+ branchSlug: string;
99
+ scopeKind: RuntimeEvidenceSetScopeKind;
100
+ scopeId: string;
101
+ selectedEvidenceSetId: string;
102
+ selectedAt: string;
103
+ selectedByGateDecisionId: string | null;
104
+ reason: string;
105
+ }
106
+
107
+ export interface RuntimeResolvedEvidenceSelection {
108
+ source: 'selection_pointer' | 'candidate_payloads' | 'legacy_active_payloads' | 'none';
109
+ evidenceSet: RuntimeEvidenceSetRecord | null;
110
+ pointer: RuntimeSelectionPointerRecord | null;
111
+ payloads: RuntimeArtifactPayloadRecord[];
112
+ }
113
+
114
+
84
115
  export type RuntimeDurableGapSeverity = 'info' | 'warning' | 'blocking';
85
116
  export type RuntimeDurableGapStatus = 'open' | 'acknowledged' | 'resolved' | 'waived' | 'superseded';
86
117
  export type RuntimeDurableGapSource = 'runtime' | 'gate_policy' | 'doctor' | 'validator' | 'agent' | 'team' | 'llm_advisor' | 'import';
@@ -149,6 +180,93 @@ export interface RuntimeAcceptanceEvidenceMapRecord {
149
180
  payload: unknown;
150
181
  }
151
182
 
183
+ export type RuntimeValidationCacheEntryStatus = 'valid' | 'stale' | 'superseded';
184
+
185
+ export interface RuntimeValidationCacheEntryRecord {
186
+ cacheKey: string;
187
+ branchSlug: string;
188
+ command: string;
189
+ status: RuntimeValidationCacheEntryStatus;
190
+ sourceTestRunId: string;
191
+ sourceRunId: string;
192
+ sourceEvidenceSetId: string | null;
193
+ outputArtifact: string | null;
194
+ stdoutDigest: string;
195
+ stderrDigest: string;
196
+ createdAt: string;
197
+ lastUsedAt: string;
198
+ payload: unknown;
199
+ }
200
+
201
+ export interface RuntimeValidationCacheUseRecord {
202
+ useId: string;
203
+ cacheKey: string;
204
+ branchSlug: string;
205
+ testRunId: string;
206
+ runId: string;
207
+ taskId: string;
208
+ sourceTestRunId: string;
209
+ sourceEvidenceSetId: string | null;
210
+ reusedAt: string;
211
+ mappedTaskIds: string[];
212
+ reason: string;
213
+ payload: unknown;
214
+ }
215
+
216
+ export type RuntimeRepairType = 'contract_repair' | 'implementation_repair' | 'validation_command_repair' | 'artifact_repair' | 'environment_repair' | 'gate_policy_repair' | 'migration_repair';
217
+ export type RuntimeRepairStatus = 'open' | 'in_progress' | 'resolved' | 'superseded';
218
+
219
+ export interface RuntimeRepairRecord {
220
+ repairId: string;
221
+ branchSlug: string;
222
+ taskId: string | null;
223
+ repairType: RuntimeRepairType;
224
+ repairOfRunId: string | null;
225
+ repairOfGateDecisionId: string | null;
226
+ status: RuntimeRepairStatus;
227
+ affectedTasks: string[];
228
+ blockers: string[];
229
+ recommendedCommands: string[];
230
+ requiredEvidence: string[];
231
+ createdAt: string;
232
+ resolvedAt: string | null;
233
+ payload: unknown;
234
+ }
235
+
236
+ export type RuntimeCapabilityAdoptionStage = 'spec' | 'plan' | 'tasks' | 'verifies' | 'do' | 'test' | 'goal-verify' | 'ship';
237
+ export type RuntimeCapabilityAdoptionStatus = 'adopted' | 'rejected' | 'unresolved';
238
+ export type RuntimeCapabilityAdoptionAuthority = 'sdd_contract' | 'sdd_gate';
239
+
240
+ export interface RuntimeCapabilityAdoptionRecord {
241
+ adoptionId: string;
242
+ branchSlug: string;
243
+ lifecycleStage: RuntimeCapabilityAdoptionStage;
244
+ capabilityDomain: string;
245
+ sourceId: string | null;
246
+ status: RuntimeCapabilityAdoptionStatus;
247
+ reason: string;
248
+ evidenceRefs: string[];
249
+ finalAuthority: RuntimeCapabilityAdoptionAuthority;
250
+ createdAt: string;
251
+ updatedAt: string;
252
+ payload: unknown;
253
+ }
254
+
255
+ export interface RuntimeStageArtifactFilter {
256
+ branchSlug?: string | null;
257
+ stage?: string | null;
258
+ artifactKind?: string | null;
259
+ producer?: string | null;
260
+ artifactRef?: string | null;
261
+ }
262
+
263
+ export interface RuntimeStageCollaborationContractFilter {
264
+ branchSlug?: string | null;
265
+ stage?: string | null;
266
+ status?: RegisteredStageCollaborationContract['status'] | null;
267
+ contractRef?: string | null;
268
+ }
269
+
152
270
 
153
271
  let runtimeStoreConstructorPromise: Promise<RuntimeStoreConstructor> | null = null;
154
272
 
@@ -214,6 +332,8 @@ function initializeRuntimeStoreSchema(db: RuntimeStoreDatabase): void {
214
332
  if (currentVersion > RUNTIME_STORE_SCHEMA_VERSION) {
215
333
  throw new RuntimeStoreError('SCHEMA_MISMATCH', `Runtime store schema ${currentVersion} is newer than supported schema ${RUNTIME_STORE_SCHEMA_VERSION}.`);
216
334
  }
335
+ migrateRuntimeStoreSchema(db, currentVersion);
336
+
217
337
  db.exec(`
218
338
  CREATE TABLE IF NOT EXISTS runtime_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_at TEXT NOT NULL);
219
339
  CREATE TABLE IF NOT EXISTS runs (run_id TEXT PRIMARY KEY, status TEXT NOT NULL, phase TEXT, current_task TEXT, partition TEXT, git_branch TEXT, task_id TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, state_json TEXT NOT NULL, state_hash TEXT NOT NULL);
@@ -231,12 +351,14 @@ CREATE TABLE IF NOT EXISTS source_snapshots (snapshot_id TEXT PRIMARY KEY, run_i
231
351
  CREATE TABLE IF NOT EXISTS projections (projection_id TEXT PRIMARY KEY, projection_type TEXT NOT NULL, scope_key TEXT NOT NULL, generated_at TEXT NOT NULL, payload_json TEXT NOT NULL, UNIQUE(projection_type, scope_key));
232
352
  CREATE TABLE IF NOT EXISTS legacy_imports (import_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, entity_type TEXT NOT NULL, content_hash TEXT NOT NULL, imported_at TEXT NOT NULL, status TEXT NOT NULL, issue TEXT, UNIQUE(run_id, entity_type));
233
353
  CREATE TABLE IF NOT EXISTS test_runs (test_run_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, partition TEXT, task_id TEXT NOT NULL, status TEXT NOT NULL, started_at TEXT NOT NULL, completed_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
234
- CREATE TABLE IF NOT EXISTS test_steps (test_step_id TEXT PRIMARY KEY, test_run_id TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, command TEXT NOT NULL, status TEXT NOT NULL, exit_code INTEGER, duration_ms INTEGER NOT NULL, output_artifact TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
354
+ CREATE TABLE IF NOT EXISTS test_steps (test_step_id TEXT PRIMARY KEY, test_run_id TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, command TEXT NOT NULL, status TEXT NOT NULL, exit_code INTEGER, duration_ms INTEGER NOT NULL, output_artifact TEXT, payload_json TEXT NOT NULL, FOREIGN KEY(test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
235
355
  CREATE TABLE IF NOT EXISTS agent_executions (execution_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, task_id TEXT NOT NULL, profile TEXT NOT NULL, status TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
236
356
  CREATE TABLE IF NOT EXISTS team_sessions (team_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, task_id TEXT, status TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
237
357
  CREATE TABLE IF NOT EXISTS worker_runtimes (runtime_id TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, status TEXT NOT NULL, claimed_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, PRIMARY KEY(run_id, runtime_id), FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
238
358
  CREATE TABLE IF NOT EXISTS artifact_payloads (payload_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, source_run_id TEXT NOT NULL, branch_slug TEXT NOT NULL, task_id TEXT, logical_ref TEXT NOT NULL, physical_payload_path TEXT NOT NULL, artifact_role TEXT NOT NULL, digest TEXT NOT NULL, sequence INTEGER NOT NULL, status TEXT NOT NULL, supersedes TEXT, created_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE, UNIQUE(branch_slug, physical_payload_path), UNIQUE(run_id, logical_ref, digest));
239
- CREATE TABLE IF NOT EXISTS sync_back_decisions (decision_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, branch TEXT NOT NULL, task_id TEXT, status TEXT NOT NULL, proposal_path TEXT, proposal_digest TEXT, proposal_payload_id TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
359
+ CREATE TABLE IF NOT EXISTS evidence_sets (evidence_set_id TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, scope_kind TEXT NOT NULL, scope_id TEXT NOT NULL, source_run_id TEXT, document_contract_hashes_json TEXT NOT NULL, gate_decision_id TEXT, status TEXT NOT NULL, created_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(source_run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
360
+ CREATE TABLE IF NOT EXISTS evidence_set_items (evidence_set_id TEXT NOT NULL, payload_id TEXT NOT NULL, logical_ref TEXT NOT NULL, role TEXT NOT NULL, required INTEGER NOT NULL, digest_at_selection TEXT NOT NULL, PRIMARY KEY(evidence_set_id, payload_id), FOREIGN KEY(evidence_set_id) REFERENCES evidence_sets(evidence_set_id) ON DELETE CASCADE, FOREIGN KEY(payload_id) REFERENCES artifact_payloads(payload_id) ON DELETE CASCADE);
361
+ CREATE TABLE IF NOT EXISTS selection_pointers (branch_slug TEXT NOT NULL, scope_kind TEXT NOT NULL, scope_id TEXT NOT NULL, selected_evidence_set_id TEXT NOT NULL, selected_at TEXT NOT NULL, selected_by_gate_decision_id TEXT, reason TEXT NOT NULL, PRIMARY KEY(branch_slug, scope_kind, scope_id), FOREIGN KEY(selected_evidence_set_id) REFERENCES evidence_sets(evidence_set_id) ON DELETE CASCADE);
240
362
  CREATE TABLE IF NOT EXISTS durable_gaps (gap_id TEXT PRIMARY KEY, partition TEXT NOT NULL, task_id TEXT, run_id TEXT, stage TEXT, gate_name TEXT, source TEXT NOT NULL, category TEXT NOT NULL, severity TEXT NOT NULL, status TEXT NOT NULL, message TEXT NOT NULL, recommendation TEXT, evidence_refs_json TEXT NOT NULL, proposal_refs_json TEXT NOT NULL, source_refs_json TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, closed_at TEXT, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
241
363
  CREATE TABLE IF NOT EXISTS stage_team_sessions (session_id TEXT PRIMARY KEY, partition TEXT NOT NULL, run_id TEXT, task_id TEXT, stage TEXT NOT NULL, lifecycle_profile TEXT NOT NULL, status TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
242
364
  CREATE TABLE IF NOT EXISTS stage_role_results (result_id TEXT PRIMARY KEY, session_id TEXT NOT NULL, partition TEXT NOT NULL, run_id TEXT, task_id TEXT, role_id TEXT NOT NULL, agent_id TEXT, output_kind TEXT NOT NULL, authority_ceiling TEXT NOT NULL, status TEXT NOT NULL, created_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
@@ -246,6 +368,12 @@ CREATE TABLE IF NOT EXISTS workflow_gate_decisions (decision_id TEXT PRIMARY KEY
246
368
  CREATE TABLE IF NOT EXISTS validation_environment_sessions (session_id TEXT PRIMARY KEY, partition TEXT NOT NULL, run_id TEXT, wave_run_id TEXT, status TEXT NOT NULL, reuse_key TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
247
369
  CREATE TABLE IF NOT EXISTS validation_wave_runs (wave_run_id TEXT PRIMARY KEY, partition TEXT NOT NULL, run_id TEXT, task_ids_json TEXT NOT NULL, status TEXT NOT NULL, environment_session_id TEXT NOT NULL, started_at TEXT NOT NULL, completed_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE SET NULL);
248
370
  CREATE TABLE IF NOT EXISTS acceptance_evidence_maps (map_id TEXT PRIMARY KEY, wave_run_id TEXT NOT NULL, test_run_id TEXT NOT NULL, partition TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, acceptance_ref TEXT NOT NULL, status TEXT NOT NULL, evidence_refs_json TEXT NOT NULL, gaps_json TEXT NOT NULL, created_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
371
+ CREATE TABLE IF NOT EXISTS validation_cache_entries (cache_key TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, command TEXT NOT NULL, status TEXT NOT NULL, source_test_run_id TEXT NOT NULL, source_run_id TEXT NOT NULL, source_evidence_set_id TEXT, output_artifact TEXT, stdout_digest TEXT NOT NULL, stderr_digest TEXT NOT NULL, created_at TEXT NOT NULL, last_used_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(source_test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(source_run_id) REFERENCES runs(run_id) ON DELETE CASCADE, FOREIGN KEY(source_evidence_set_id) REFERENCES evidence_sets(evidence_set_id) ON DELETE SET NULL);
372
+ CREATE TABLE IF NOT EXISTS validation_cache_uses (use_id TEXT PRIMARY KEY, cache_key TEXT NOT NULL, branch_slug TEXT NOT NULL, test_run_id TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, source_test_run_id TEXT NOT NULL, source_evidence_set_id TEXT, reused_at TEXT NOT NULL, mapped_task_ids_json TEXT NOT NULL, reason TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(cache_key) REFERENCES validation_cache_entries(cache_key) ON DELETE CASCADE, FOREIGN KEY(test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE);
373
+ CREATE TABLE IF NOT EXISTS repair_records (repair_id TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, task_id TEXT, repair_type TEXT NOT NULL, repair_of_run_id TEXT, repair_of_gate_decision_id TEXT, status TEXT NOT NULL, affected_tasks_json TEXT NOT NULL, blockers_json TEXT NOT NULL, recommended_commands_json TEXT NOT NULL, required_evidence_json TEXT NOT NULL, created_at TEXT NOT NULL, resolved_at TEXT, payload_json TEXT NOT NULL, FOREIGN KEY(repair_of_run_id) REFERENCES runs(run_id) ON DELETE SET NULL, FOREIGN KEY(repair_of_gate_decision_id) REFERENCES workflow_gate_decisions(decision_id) ON DELETE SET NULL);
374
+ CREATE TABLE IF NOT EXISTS capability_adoptions (adoption_id TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, lifecycle_stage TEXT NOT NULL, capability_domain TEXT NOT NULL, source_id TEXT, status TEXT NOT NULL, reason TEXT NOT NULL, evidence_refs_json TEXT NOT NULL, final_authority TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, payload_json TEXT NOT NULL, UNIQUE(branch_slug, lifecycle_stage, capability_domain, source_id));
375
+ CREATE TABLE IF NOT EXISTS stage_artifacts (artifact_id TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, stage TEXT NOT NULL, artifact_kind TEXT NOT NULL, producer TEXT NOT NULL, artifact_ref TEXT NOT NULL, content_hash TEXT NOT NULL, contract TEXT NOT NULL, target_ref TEXT, target_hash TEXT, review_ref TEXT, review_hash TEXT, verdict TEXT, finding_count INTEGER, blocking_count INTEGER, recommendation TEXT, frontmatter_json TEXT NOT NULL, registered_at TEXT NOT NULL, payload_json TEXT NOT NULL, UNIQUE(branch_slug, stage, artifact_ref, content_hash));
376
+ CREATE TABLE IF NOT EXISTS stage_collaboration_contracts (contract_id TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, stage TEXT NOT NULL, contract_ref TEXT NOT NULL, content_hash TEXT NOT NULL, contract_version TEXT NOT NULL, producer TEXT NOT NULL, work_order_id TEXT, status TEXT NOT NULL, validation_errors_json TEXT NOT NULL, selected_agents_json TEXT NOT NULL, selected_skills_json TEXT NOT NULL, selected_materials_json TEXT NOT NULL, evidence_contracts_json TEXT NOT NULL, checkpoint_plan_json TEXT NOT NULL, rework_plan_json TEXT NOT NULL, permission_projection_json TEXT NOT NULL, frontmatter_json TEXT NOT NULL, registered_at TEXT NOT NULL, payload_json TEXT NOT NULL, UNIQUE(branch_slug, stage, contract_ref, content_hash));
249
377
  CREATE INDEX IF NOT EXISTS idx_runs_partition_task_updated ON runs(partition, task_id, updated_at);
250
378
  CREATE INDEX IF NOT EXISTS idx_events_run_time ON events(run_id, event_time, event_id);
251
379
  CREATE INDEX IF NOT EXISTS idx_artifacts_run_path ON artifacts(run_id, path);
@@ -259,7 +387,8 @@ CREATE INDEX IF NOT EXISTS idx_team_sessions_run_task ON team_sessions(run_id, t
259
387
  CREATE INDEX IF NOT EXISTS idx_worker_runtimes_run_task ON worker_runtimes(run_id, task_id, updated_at);
260
388
  CREATE INDEX IF NOT EXISTS idx_artifact_payloads_logical ON artifact_payloads(branch_slug, logical_ref, status, sequence);
261
389
  CREATE INDEX IF NOT EXISTS idx_artifact_payloads_run_logical ON artifact_payloads(run_id, logical_ref, status, sequence);
262
- CREATE INDEX IF NOT EXISTS idx_sync_back_decisions_run_task ON sync_back_decisions(run_id, task_id, updated_at);
390
+ CREATE INDEX IF NOT EXISTS idx_evidence_sets_scope ON evidence_sets(branch_slug, scope_kind, scope_id, status, created_at);
391
+ CREATE INDEX IF NOT EXISTS idx_selection_pointers_scope ON selection_pointers(branch_slug, scope_kind, scope_id);
263
392
  CREATE INDEX IF NOT EXISTS idx_durable_gaps_partition_task ON durable_gaps(partition, task_id, status, severity, updated_at);
264
393
  CREATE INDEX IF NOT EXISTS idx_durable_gaps_run_task ON durable_gaps(run_id, task_id, status, severity, updated_at);
265
394
  CREATE INDEX IF NOT EXISTS idx_stage_team_sessions_partition_task ON stage_team_sessions(partition, task_id, updated_at);
@@ -270,6 +399,14 @@ CREATE INDEX IF NOT EXISTS idx_workflow_gate_decisions_partition_task ON workflo
270
399
  CREATE INDEX IF NOT EXISTS idx_validation_environment_sessions_partition ON validation_environment_sessions(partition, wave_run_id, updated_at);
271
400
  CREATE INDEX IF NOT EXISTS idx_validation_wave_runs_partition ON validation_wave_runs(partition, status, completed_at);
272
401
  CREATE INDEX IF NOT EXISTS idx_acceptance_evidence_maps_task ON acceptance_evidence_maps(partition, task_id, acceptance_ref, created_at);
402
+ CREATE INDEX IF NOT EXISTS idx_validation_cache_entries_branch_status ON validation_cache_entries(branch_slug, status, last_used_at);
403
+ CREATE INDEX IF NOT EXISTS idx_validation_cache_uses_run_task ON validation_cache_uses(run_id, task_id, reused_at);
404
+ CREATE INDEX IF NOT EXISTS idx_repair_records_branch_status ON repair_records(branch_slug, status, repair_type, created_at);
405
+ CREATE INDEX IF NOT EXISTS idx_capability_adoptions_branch_domain ON capability_adoptions(branch_slug, capability_domain, status, updated_at);
406
+ CREATE INDEX IF NOT EXISTS idx_stage_artifacts_branch_stage ON stage_artifacts(branch_slug, stage, registered_at);
407
+ CREATE INDEX IF NOT EXISTS idx_stage_artifacts_ref ON stage_artifacts(branch_slug, stage, artifact_ref, content_hash);
408
+ CREATE INDEX IF NOT EXISTS idx_stage_collaboration_contracts_branch_stage ON stage_collaboration_contracts(branch_slug, stage, registered_at);
409
+ CREATE INDEX IF NOT EXISTS idx_stage_collaboration_contracts_ref ON stage_collaboration_contracts(branch_slug, stage, contract_ref, content_hash);
273
410
  `);
274
411
  db.exec(`PRAGMA user_version = ${RUNTIME_STORE_SCHEMA_VERSION}`);
275
412
  const now = new Date().toISOString();
@@ -277,6 +414,43 @@ CREATE INDEX IF NOT EXISTS idx_acceptance_evidence_maps_task ON acceptance_evide
277
414
  db.prepare('INSERT OR REPLACE INTO runtime_meta (key, value, updated_at) VALUES (?, ?, ?)').run('schema_version', String(RUNTIME_STORE_SCHEMA_VERSION), now);
278
415
  }
279
416
 
417
+ function migrateRuntimeStoreSchema(db: RuntimeStoreDatabase, currentVersion: number): void {
418
+ if (currentVersion === 0 || currentVersion >= RUNTIME_STORE_SCHEMA_VERSION) {
419
+ return;
420
+ }
421
+ if (currentVersion < 12) {
422
+ migrateNullableOutputArtifactColumns(db);
423
+ }
424
+ }
425
+
426
+ function migrateNullableOutputArtifactColumns(db: RuntimeStoreDatabase): void {
427
+ migrateNullableOutputArtifactColumn(db, 'test_steps', 'test_step_id TEXT PRIMARY KEY, test_run_id TEXT NOT NULL, run_id TEXT NOT NULL, task_id TEXT NOT NULL, command TEXT NOT NULL, status TEXT NOT NULL, exit_code INTEGER, duration_ms INTEGER NOT NULL, output_artifact TEXT, payload_json TEXT NOT NULL, FOREIGN KEY(test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(run_id) REFERENCES runs(run_id) ON DELETE CASCADE', 'test_step_id, test_run_id, run_id, task_id, command, status, exit_code, duration_ms, output_artifact, payload_json');
428
+ migrateNullableOutputArtifactColumn(db, 'validation_cache_entries', 'cache_key TEXT PRIMARY KEY, branch_slug TEXT NOT NULL, command TEXT NOT NULL, status TEXT NOT NULL, source_test_run_id TEXT NOT NULL, source_run_id TEXT NOT NULL, source_evidence_set_id TEXT, output_artifact TEXT, stdout_digest TEXT NOT NULL, stderr_digest TEXT NOT NULL, created_at TEXT NOT NULL, last_used_at TEXT NOT NULL, payload_json TEXT NOT NULL, FOREIGN KEY(source_test_run_id) REFERENCES test_runs(test_run_id) ON DELETE CASCADE, FOREIGN KEY(source_run_id) REFERENCES runs(run_id) ON DELETE CASCADE, FOREIGN KEY(source_evidence_set_id) REFERENCES evidence_sets(evidence_set_id) ON DELETE SET NULL', 'cache_key, branch_slug, command, status, source_test_run_id, source_run_id, source_evidence_set_id, output_artifact, stdout_digest, stderr_digest, created_at, last_used_at, payload_json');
429
+ }
430
+
431
+ function migrateNullableOutputArtifactColumn(db: RuntimeStoreDatabase, tableName: string, columnDefinitionSql: string, columnsSql: string): void {
432
+ if (!runtimeStoreColumnIsNotNull(db, tableName, 'output_artifact')) {
433
+ return;
434
+ }
435
+ const tempTableName = `${tableName}_runtime_v12`;
436
+ db.exec('PRAGMA foreign_keys = OFF');
437
+ try {
438
+ db.exec(`DROP TABLE IF EXISTS ${tempTableName}`);
439
+ db.exec(`CREATE TABLE ${tempTableName} (${columnDefinitionSql})`);
440
+ db.exec(`INSERT INTO ${tempTableName} (${columnsSql}) SELECT ${columnsSql} FROM ${tableName}`);
441
+ db.exec(`DROP TABLE ${tableName}`);
442
+ db.exec(`ALTER TABLE ${tempTableName} RENAME TO ${tableName}`);
443
+ } finally {
444
+ db.exec('PRAGMA foreign_keys = ON');
445
+ }
446
+ }
447
+
448
+ function runtimeStoreColumnIsNotNull(db: RuntimeStoreDatabase, tableName: string, columnName: string): boolean {
449
+ const rows = db.prepare(`PRAGMA table_info(${tableName})`).all() as Array<{ name?: string; notnull?: number }>;
450
+ const column = rows.find((row) => row.name === columnName);
451
+ return (column?.notnull ?? 0) === 1;
452
+ }
453
+
280
454
  function readRuntimeStoreSchemaVersion(db: RuntimeStoreDatabase): number {
281
455
  const row = db.prepare('PRAGMA user_version').get() as { user_version?: unknown } | undefined;
282
456
  return typeof row?.user_version === 'number' ? row.user_version : 0;
@@ -523,6 +697,92 @@ export async function recordRuntimeEvidenceAttachment(projectRoot: string, input
523
697
  });
524
698
  }
525
699
 
700
+ export async function recordRuntimeStageArtifact(projectRoot: string, record: RegisteredStageArtifact): Promise<RegisteredStageArtifact> {
701
+ await withRuntimeStore(projectRoot, ({ db }) => {
702
+ db.prepare('INSERT OR REPLACE INTO stage_artifacts (artifact_id, branch_slug, stage, artifact_kind, producer, artifact_ref, content_hash, contract, target_ref, target_hash, review_ref, review_hash, verdict, finding_count, blocking_count, recommendation, frontmatter_json, registered_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
703
+ .run(record.artifactId, record.branch, record.stage, record.kind, record.producer, record.ref, record.hash, record.contract, record.targetRef?.ref ?? null, record.targetHash ?? null, record.reviewRef?.ref ?? null, record.reviewHash ?? null, record.verdict ?? null, record.findingCount ?? null, record.blockingCount ?? null, record.recommendation ?? null, JSON.stringify(record.frontmatter), record.registeredAt, JSON.stringify(record));
704
+ });
705
+ return record;
706
+ }
707
+
708
+ export async function listRuntimeStageArtifacts(projectRoot: string, filter: RuntimeStageArtifactFilter = {}): Promise<RegisteredStageArtifact[]> {
709
+ return withRuntimeStore(projectRoot, ({ db }) => {
710
+ const clauses: string[] = [];
711
+ const params: string[] = [];
712
+ if (filter.branchSlug) {
713
+ clauses.push('branch_slug = ?');
714
+ params.push(filter.branchSlug);
715
+ }
716
+ if (filter.stage) {
717
+ clauses.push('stage = ?');
718
+ params.push(filter.stage);
719
+ }
720
+ if (filter.artifactKind) {
721
+ clauses.push('artifact_kind = ?');
722
+ params.push(filter.artifactKind);
723
+ }
724
+ if (filter.producer) {
725
+ clauses.push('producer = ?');
726
+ params.push(filter.producer);
727
+ }
728
+ if (filter.artifactRef) {
729
+ clauses.push('artifact_ref = ?');
730
+ params.push(filter.artifactRef);
731
+ }
732
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
733
+ const rows = db.prepare(`SELECT * FROM stage_artifacts${where} ORDER BY registered_at DESC, artifact_id ASC`).all(...params) as RuntimeStageArtifactRow[];
734
+ return rows.map(runtimeStageArtifactFromRow);
735
+ });
736
+ }
737
+
738
+ export async function readRuntimeStageArtifact(projectRoot: string, artifactId: string): Promise<RegisteredStageArtifact | null> {
739
+ return withRuntimeStore(projectRoot, ({ db }) => {
740
+ const row = db.prepare('SELECT * FROM stage_artifacts WHERE artifact_id = ?').get(artifactId) as RuntimeStageArtifactRow | undefined;
741
+ return row ? runtimeStageArtifactFromRow(row) : null;
742
+ });
743
+ }
744
+
745
+ export async function recordRuntimeStageCollaborationContract(projectRoot: string, record: RegisteredStageCollaborationContract): Promise<RegisteredStageCollaborationContract> {
746
+ await withRuntimeStore(projectRoot, ({ db }) => {
747
+ db.prepare('INSERT OR REPLACE INTO stage_collaboration_contracts (contract_id, branch_slug, stage, contract_ref, content_hash, contract_version, producer, work_order_id, status, validation_errors_json, selected_agents_json, selected_skills_json, selected_materials_json, evidence_contracts_json, checkpoint_plan_json, rework_plan_json, permission_projection_json, frontmatter_json, registered_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
748
+ .run(record.contractId, record.branch, record.stage, record.ref, record.hash, record.contract, record.producer, record.workOrderId ?? null, record.status, JSON.stringify(record.validationErrors), JSON.stringify(record.selectedAgents), JSON.stringify(record.selectedSkills), JSON.stringify(record.selectedMaterialPacks), JSON.stringify(record.evidenceContracts), JSON.stringify(record.checkpointPlan), JSON.stringify(record.reworkPlan), JSON.stringify(record.permissionProjection), JSON.stringify(record.frontmatter), record.registeredAt, JSON.stringify(record));
749
+ });
750
+ return record;
751
+ }
752
+
753
+ export async function listRuntimeStageCollaborationContracts(projectRoot: string, filter: RuntimeStageCollaborationContractFilter = {}): Promise<RegisteredStageCollaborationContract[]> {
754
+ return withRuntimeStore(projectRoot, ({ db }) => {
755
+ const clauses: string[] = [];
756
+ const params: string[] = [];
757
+ if (filter.branchSlug) {
758
+ clauses.push('branch_slug = ?');
759
+ params.push(filter.branchSlug);
760
+ }
761
+ if (filter.stage) {
762
+ clauses.push('stage = ?');
763
+ params.push(filter.stage);
764
+ }
765
+ if (filter.status) {
766
+ clauses.push('status = ?');
767
+ params.push(filter.status);
768
+ }
769
+ if (filter.contractRef) {
770
+ clauses.push('contract_ref = ?');
771
+ params.push(filter.contractRef);
772
+ }
773
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
774
+ const rows = db.prepare(`SELECT * FROM stage_collaboration_contracts${where} ORDER BY registered_at DESC, contract_id ASC`).all(...params) as RuntimeStageCollaborationContractRow[];
775
+ return rows.map(runtimeStageCollaborationContractFromRow);
776
+ });
777
+ }
778
+
779
+ export async function readRuntimeStageCollaborationContract(projectRoot: string, contractId: string): Promise<RegisteredStageCollaborationContract | null> {
780
+ return withRuntimeStore(projectRoot, ({ db }) => {
781
+ const row = db.prepare('SELECT * FROM stage_collaboration_contracts WHERE contract_id = ?').get(contractId) as RuntimeStageCollaborationContractRow | undefined;
782
+ return row ? runtimeStageCollaborationContractFromRow(row) : null;
783
+ });
784
+ }
785
+
526
786
  export async function recordRuntimeArtifactPayload(projectRoot: string, input: Omit<RuntimeArtifactPayloadRecord, 'sequence' | 'supersedes' | 'createdAt'> & { sequence?: number; supersedes?: string | null; createdAt?: string }): Promise<RuntimeArtifactPayloadRecord> {
527
787
  const createdAt = input.createdAt ?? new Date().toISOString();
528
788
  return withRuntimeStore(projectRoot, ({ db }) => {
@@ -535,6 +795,7 @@ export async function recordRuntimeArtifactPayload(projectRoot: string, input: O
535
795
  db.prepare('UPDATE artifact_payloads SET status = ? WHERE branch_slug = ? AND ((task_id IS NULL AND ? IS NULL) OR task_id = ?) AND logical_ref = ? AND status = ?')
536
796
  .run('superseded', input.branchSlug, input.taskId, input.taskId, input.logicalRef, 'active');
537
797
  }
798
+
538
799
  const record: RuntimeArtifactPayloadRecord = {
539
800
  ...input,
540
801
  sequence,
@@ -584,30 +845,56 @@ export async function listRuntimeArtifactPayloads(projectRoot: string, input: {
584
845
  });
585
846
  }
586
847
 
587
- export async function recordRuntimeSyncBackDecision(projectRoot: string, record: RuntimeSyncBackDecisionRecord): Promise<void> {
588
- const payloadJson = JSON.stringify({ payload: record.payload, reasons: record.reasons });
848
+ export async function createRuntimeEvidenceSet(projectRoot: string, input: Omit<RuntimeEvidenceSetRecord, 'createdAt'> & { createdAt?: string }): Promise<RuntimeEvidenceSetRecord> {
849
+ const createdAt = input.createdAt ?? new Date().toISOString();
850
+ const record: RuntimeEvidenceSetRecord = { ...input, createdAt };
589
851
  await withRuntimeStore(projectRoot, ({ db }) => {
590
- db.prepare('INSERT OR REPLACE INTO sync_back_decisions (decision_id, run_id, branch, task_id, status, proposal_path, proposal_digest, proposal_payload_id, created_at, updated_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
591
- .run(record.decisionId, record.runId, record.branch, record.taskId, record.status, record.proposalPath, record.proposalDigest, record.proposalPayloadId, record.createdAt, record.updatedAt, payloadJson);
852
+ db.prepare('INSERT OR REPLACE INTO evidence_sets (evidence_set_id, branch_slug, scope_kind, scope_id, source_run_id, document_contract_hashes_json, gate_decision_id, status, created_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
853
+ .run(record.evidenceSetId, record.branchSlug, record.scopeKind, record.scopeId, record.sourceRunId, JSON.stringify(record.documentContractHashes), record.gateDecisionId, record.status, record.createdAt, JSON.stringify(record.payload));
854
+ for (const item of record.items) {
855
+ db.prepare('INSERT OR REPLACE INTO evidence_set_items (evidence_set_id, payload_id, logical_ref, role, required, digest_at_selection) VALUES (?, ?, ?, ?, ?, ?)')
856
+ .run(record.evidenceSetId, item.payloadId, item.logicalRef, item.role, item.required ? 1 : 0, item.digestAtSelection);
857
+ }
592
858
  });
859
+ return record;
593
860
  }
594
861
 
595
- export async function readRuntimeSyncBackDecision(projectRoot: string, runId: string, taskId?: string | null): Promise<RuntimeSyncBackDecisionRecord | null> {
596
- return withRuntimeStore(projectRoot, ({ db }) => {
597
- const row = taskId
598
- ? db.prepare('SELECT * FROM sync_back_decisions WHERE run_id = ? AND task_id = ? ORDER BY updated_at DESC LIMIT 1').get(runId, taskId)
599
- : db.prepare('SELECT * FROM sync_back_decisions WHERE run_id = ? ORDER BY updated_at DESC LIMIT 1').get(runId);
600
- return row ? runtimeSyncBackDecisionFromRow(row as RuntimeSyncBackDecisionRow) : null;
862
+ export async function updateRuntimeSelectionPointer(projectRoot: string, pointer: RuntimeSelectionPointerRecord): Promise<RuntimeSelectionPointerRecord> {
863
+ await withRuntimeStore(projectRoot, ({ db }) => {
864
+ const previous = db.prepare('SELECT selected_evidence_set_id FROM selection_pointers WHERE branch_slug = ? AND scope_kind = ? AND scope_id = ?')
865
+ .get(pointer.branchSlug, pointer.scopeKind, pointer.scopeId) as { selected_evidence_set_id?: string } | undefined;
866
+ db.prepare('INSERT OR REPLACE INTO selection_pointers (branch_slug, scope_kind, scope_id, selected_evidence_set_id, selected_at, selected_by_gate_decision_id, reason) VALUES (?, ?, ?, ?, ?, ?, ?)')
867
+ .run(pointer.branchSlug, pointer.scopeKind, pointer.scopeId, pointer.selectedEvidenceSetId, pointer.selectedAt, pointer.selectedByGateDecisionId, pointer.reason);
868
+ if (previous?.selected_evidence_set_id !== pointer.selectedEvidenceSetId) {
869
+ recordSelectionPointerActivity(db, pointer);
870
+ }
601
871
  });
872
+ return pointer;
602
873
  }
603
874
 
604
- export async function listRuntimeSyncBackDecisions(projectRoot: string, runId: string): Promise<RuntimeSyncBackDecisionRecord[]> {
875
+ export async function resolveRuntimeSelectedEvidence(projectRoot: string, input: { branchSlug: string; scopeKind: RuntimeEvidenceSetScopeKind; scopeId: string; fallbackRunIds?: string[]; fallbackTaskIds?: string[]; fallbackLogicalRefPrefixes?: string[]; allowCandidateFallback?: boolean }): Promise<RuntimeResolvedEvidenceSelection> {
605
876
  return withRuntimeStore(projectRoot, ({ db }) => {
606
- const rows = db.prepare('SELECT * FROM sync_back_decisions WHERE run_id = ? ORDER BY updated_at DESC, decision_id ASC').all(runId) as RuntimeSyncBackDecisionRow[];
607
- return rows.map(runtimeSyncBackDecisionFromRow);
877
+ const pointerRow = db.prepare('SELECT * FROM selection_pointers WHERE branch_slug = ? AND scope_kind = ? AND scope_id = ?').get(input.branchSlug, input.scopeKind, input.scopeId) as RuntimeSelectionPointerRow | undefined;
878
+ if (pointerRow) {
879
+ const evidenceSet = runtimeEvidenceSetFromDb(db, pointerRow.selected_evidence_set_id);
880
+ if (evidenceSet && evidenceSetMatchesFallbackRuns(evidenceSet, input.fallbackRunIds)) {
881
+ const payloads = payloadsForEvidenceSet(db, evidenceSet);
882
+ if (payloads.length > 0) {
883
+ return { source: 'selection_pointer', evidenceSet, pointer: runtimeSelectionPointerFromRow(pointerRow), payloads };
884
+ }
885
+ }
886
+ }
887
+ const fallbackPayloads = legacyFallbackPayloads(db, input);
888
+ if (fallbackPayloads.length === 0) {
889
+ return { source: 'none', evidenceSet: null, pointer: null, payloads: [] };
890
+ }
891
+ return input.allowCandidateFallback
892
+ ? { source: 'candidate_payloads', evidenceSet: null, pointer: null, payloads: fallbackPayloads }
893
+ : { source: 'legacy_active_payloads', evidenceSet: null, pointer: null, payloads: fallbackPayloads };
608
894
  });
609
895
  }
610
896
 
897
+
611
898
  export async function recordRuntimeDurableGap(projectRoot: string, input: Omit<RuntimeDurableGapRecord, 'createdAt' | 'updatedAt' | 'closedAt'> & { createdAt?: string; updatedAt?: string; closedAt?: string | null }): Promise<RuntimeDurableGapRecord> {
612
899
  const createdAt = input.createdAt ?? new Date().toISOString();
613
900
  const updatedAt = input.updatedAt ?? createdAt;
@@ -800,13 +1087,13 @@ export interface RuntimeTestStepRecord {
800
1087
  status: string;
801
1088
  exitCode: number | null;
802
1089
  durationMs: number;
803
- outputArtifact: string;
1090
+ outputArtifact: string | null;
804
1091
  payload: unknown;
805
1092
  }
806
1093
 
807
1094
  export async function recordRuntimeTestRun(projectRoot: string, record: RuntimeTestRunRecord): Promise<void> {
808
1095
  await withRuntimeStore(projectRoot, ({ db }) => {
809
- db.prepare('INSERT OR REPLACE INTO test_runs (test_run_id, run_id, partition, task_id, status, started_at, completed_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')
1096
+ db.prepare('INSERT INTO test_runs (test_run_id, run_id, partition, task_id, status, started_at, completed_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(test_run_id) DO UPDATE SET run_id = excluded.run_id, partition = excluded.partition, task_id = excluded.task_id, status = excluded.status, started_at = excluded.started_at, completed_at = excluded.completed_at, payload_json = excluded.payload_json')
810
1097
  .run(record.testRunId, record.runId, record.partition, record.taskId, record.status, record.startedAt, record.completedAt, JSON.stringify(record.payload));
811
1098
  });
812
1099
  }
@@ -818,6 +1105,24 @@ export async function recordRuntimeTestStep(projectRoot: string, record: Runtime
818
1105
  });
819
1106
  }
820
1107
 
1108
+ export async function listRuntimeTestSteps(projectRoot: string, input: { runId?: string | null; testRunId?: string | null } = {}): Promise<RuntimeTestStepRecord[]> {
1109
+ return withRuntimeStore(projectRoot, ({ db }) => {
1110
+ const clauses: string[] = [];
1111
+ const params: string[] = [];
1112
+ if (input.runId) {
1113
+ clauses.push('run_id = ?');
1114
+ params.push(input.runId);
1115
+ }
1116
+ if (input.testRunId) {
1117
+ clauses.push('test_run_id = ?');
1118
+ params.push(input.testRunId);
1119
+ }
1120
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
1121
+ const rows = db.prepare(`SELECT test_step_id, test_run_id, run_id, task_id, command, status, exit_code, duration_ms, output_artifact, payload_json FROM test_steps${where} ORDER BY test_step_id ASC`).all(...params) as RuntimeTestStepRow[];
1122
+ return rows.map(runtimeTestStepFromRow);
1123
+ });
1124
+ }
1125
+
821
1126
  export async function listRuntimeTestRuns(projectRoot: string, runId?: string | null): Promise<RuntimeTestRunRecord[]> {
822
1127
  return withRuntimeStore(projectRoot, ({ db }) => {
823
1128
  const rows = runId
@@ -836,6 +1141,131 @@ export async function listRuntimeTestRuns(projectRoot: string, runId?: string |
836
1141
  });
837
1142
  }
838
1143
 
1144
+ export async function recordRuntimeValidationCacheEntry(projectRoot: string, record: RuntimeValidationCacheEntryRecord): Promise<void> {
1145
+ await withRuntimeStore(projectRoot, ({ db }) => {
1146
+ db.prepare('INSERT INTO validation_cache_entries (cache_key, branch_slug, command, status, source_test_run_id, source_run_id, source_evidence_set_id, output_artifact, stdout_digest, stderr_digest, created_at, last_used_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(cache_key) DO UPDATE SET branch_slug = excluded.branch_slug, command = excluded.command, status = excluded.status, source_test_run_id = excluded.source_test_run_id, source_run_id = excluded.source_run_id, source_evidence_set_id = excluded.source_evidence_set_id, output_artifact = excluded.output_artifact, stdout_digest = excluded.stdout_digest, stderr_digest = excluded.stderr_digest, last_used_at = excluded.last_used_at, payload_json = excluded.payload_json')
1147
+ .run(record.cacheKey, record.branchSlug, record.command, record.status, record.sourceTestRunId, record.sourceRunId, record.sourceEvidenceSetId, record.outputArtifact, record.stdoutDigest, record.stderrDigest, record.createdAt, record.lastUsedAt, JSON.stringify(record.payload));
1148
+ });
1149
+ }
1150
+
1151
+ export async function readRuntimeValidationCacheEntry(projectRoot: string, input: { branchSlug: string; cacheKey: string }): Promise<RuntimeValidationCacheEntryRecord | null> {
1152
+ return withRuntimeStore(projectRoot, ({ db }) => {
1153
+ const row = db.prepare('SELECT cache_key, branch_slug, command, status, source_test_run_id, source_run_id, source_evidence_set_id, output_artifact, stdout_digest, stderr_digest, created_at, last_used_at, payload_json FROM validation_cache_entries WHERE branch_slug = ? AND cache_key = ? AND status = ?').get(input.branchSlug, input.cacheKey, 'valid') as RuntimeValidationCacheEntryRow | undefined;
1154
+ return row ? runtimeValidationCacheEntryFromRow(row) : null;
1155
+ });
1156
+ }
1157
+
1158
+ export async function listRuntimeValidationCacheEntries(projectRoot: string, input: { branchSlug?: string | null; status?: RuntimeValidationCacheEntryStatus | null } = {}): Promise<RuntimeValidationCacheEntryRecord[]> {
1159
+ return withRuntimeStore(projectRoot, ({ db }) => {
1160
+ const clauses: string[] = [];
1161
+ const params: string[] = [];
1162
+ if (input.branchSlug) {
1163
+ clauses.push('branch_slug = ?');
1164
+ params.push(input.branchSlug);
1165
+ }
1166
+ if (input.status) {
1167
+ clauses.push('status = ?');
1168
+ params.push(input.status);
1169
+ }
1170
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
1171
+ const rows = db.prepare(`SELECT cache_key, branch_slug, command, status, source_test_run_id, source_run_id, source_evidence_set_id, output_artifact, stdout_digest, stderr_digest, created_at, last_used_at, payload_json FROM validation_cache_entries${where} ORDER BY last_used_at DESC, cache_key ASC`).all(...params) as RuntimeValidationCacheEntryRow[];
1172
+ return rows.map(runtimeValidationCacheEntryFromRow);
1173
+ });
1174
+ }
1175
+
1176
+ export async function recordRuntimeValidationCacheUse(projectRoot: string, record: RuntimeValidationCacheUseRecord): Promise<void> {
1177
+ await withRuntimeStore(projectRoot, ({ db }) => {
1178
+ db.prepare('INSERT OR REPLACE INTO validation_cache_uses (use_id, cache_key, branch_slug, test_run_id, run_id, task_id, source_test_run_id, source_evidence_set_id, reused_at, mapped_task_ids_json, reason, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
1179
+ .run(record.useId, record.cacheKey, record.branchSlug, record.testRunId, record.runId, record.taskId, record.sourceTestRunId, record.sourceEvidenceSetId, record.reusedAt, JSON.stringify(record.mappedTaskIds), record.reason, JSON.stringify(record.payload));
1180
+ db.prepare('UPDATE validation_cache_entries SET last_used_at = ? WHERE cache_key = ?')
1181
+ .run(record.reusedAt, record.cacheKey);
1182
+ });
1183
+ }
1184
+
1185
+ export async function listRuntimeValidationCacheUses(projectRoot: string, input: { branchSlug?: string | null; runId?: string | null; taskId?: string | null } = {}): Promise<RuntimeValidationCacheUseRecord[]> {
1186
+ return withRuntimeStore(projectRoot, ({ db }) => {
1187
+ const clauses: string[] = [];
1188
+ const params: string[] = [];
1189
+ if (input.branchSlug) {
1190
+ clauses.push('branch_slug = ?');
1191
+ params.push(input.branchSlug);
1192
+ }
1193
+ if (input.runId) {
1194
+ clauses.push('run_id = ?');
1195
+ params.push(input.runId);
1196
+ }
1197
+ if (input.taskId) {
1198
+ clauses.push('task_id = ?');
1199
+ params.push(input.taskId);
1200
+ }
1201
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
1202
+ const rows = db.prepare(`SELECT use_id, cache_key, branch_slug, test_run_id, run_id, task_id, source_test_run_id, source_evidence_set_id, reused_at, mapped_task_ids_json, reason, payload_json FROM validation_cache_uses${where} ORDER BY reused_at DESC, use_id ASC`).all(...params) as RuntimeValidationCacheUseRow[];
1203
+ return rows.map(runtimeValidationCacheUseFromRow);
1204
+ });
1205
+ }
1206
+
1207
+ export async function recordRuntimeRepair(projectRoot: string, record: RuntimeRepairRecord): Promise<void> {
1208
+ await withRuntimeStore(projectRoot, ({ db }) => {
1209
+ db.prepare('INSERT INTO repair_records (repair_id, branch_slug, task_id, repair_type, repair_of_run_id, repair_of_gate_decision_id, status, affected_tasks_json, blockers_json, recommended_commands_json, required_evidence_json, created_at, resolved_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(repair_id) DO UPDATE SET status = excluded.status, blockers_json = excluded.blockers_json, recommended_commands_json = excluded.recommended_commands_json, required_evidence_json = excluded.required_evidence_json, resolved_at = excluded.resolved_at, payload_json = excluded.payload_json')
1210
+ .run(record.repairId, record.branchSlug, record.taskId, record.repairType, record.repairOfRunId, record.repairOfGateDecisionId, record.status, JSON.stringify(record.affectedTasks), JSON.stringify(record.blockers), JSON.stringify(record.recommendedCommands), JSON.stringify(record.requiredEvidence), record.createdAt, record.resolvedAt, JSON.stringify(record.payload));
1211
+ });
1212
+ }
1213
+
1214
+ export async function listRuntimeRepairs(projectRoot: string, input: { branchSlug?: string | null; taskId?: string | null; status?: RuntimeRepairStatus | null } = {}): Promise<RuntimeRepairRecord[]> {
1215
+ return withRuntimeStore(projectRoot, ({ db }) => {
1216
+ const clauses: string[] = [];
1217
+ const params: string[] = [];
1218
+ if (input.branchSlug) {
1219
+ clauses.push('branch_slug = ?');
1220
+ params.push(input.branchSlug);
1221
+ }
1222
+ if (input.taskId) {
1223
+ clauses.push('task_id = ?');
1224
+ params.push(input.taskId);
1225
+ }
1226
+ if (input.status) {
1227
+ clauses.push('status = ?');
1228
+ params.push(input.status);
1229
+ }
1230
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
1231
+ const rows = db.prepare(`SELECT repair_id, branch_slug, task_id, repair_type, repair_of_run_id, repair_of_gate_decision_id, status, affected_tasks_json, blockers_json, recommended_commands_json, required_evidence_json, created_at, resolved_at, payload_json FROM repair_records${where} ORDER BY created_at DESC, repair_id ASC`).all(...params) as RuntimeRepairRow[];
1232
+ return rows.map(runtimeRepairFromRow);
1233
+ });
1234
+ }
1235
+
1236
+ export async function recordRuntimeCapabilityAdoption(projectRoot: string, record: RuntimeCapabilityAdoptionRecord): Promise<void> {
1237
+ await withRuntimeStore(projectRoot, ({ db }) => {
1238
+ db.prepare('INSERT INTO capability_adoptions (adoption_id, branch_slug, lifecycle_stage, capability_domain, source_id, status, reason, evidence_refs_json, final_authority, created_at, updated_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(branch_slug, lifecycle_stage, capability_domain, source_id) DO UPDATE SET adoption_id = excluded.adoption_id, status = excluded.status, reason = excluded.reason, evidence_refs_json = excluded.evidence_refs_json, final_authority = excluded.final_authority, updated_at = excluded.updated_at, payload_json = excluded.payload_json')
1239
+ .run(record.adoptionId, record.branchSlug, record.lifecycleStage, record.capabilityDomain, record.sourceId, record.status, record.reason, JSON.stringify(record.evidenceRefs), record.finalAuthority, record.createdAt, record.updatedAt, JSON.stringify(record.payload));
1240
+ });
1241
+ }
1242
+
1243
+ export async function listRuntimeCapabilityAdoptions(projectRoot: string, input: { branchSlug?: string | null; lifecycleStage?: RuntimeCapabilityAdoptionStage | null; capabilityDomain?: string | null; status?: RuntimeCapabilityAdoptionStatus | null } = {}): Promise<RuntimeCapabilityAdoptionRecord[]> {
1244
+ return withRuntimeStore(projectRoot, ({ db }) => {
1245
+ const clauses: string[] = [];
1246
+ const params: string[] = [];
1247
+ if (input.branchSlug) {
1248
+ clauses.push('branch_slug = ?');
1249
+ params.push(input.branchSlug);
1250
+ }
1251
+ if (input.lifecycleStage) {
1252
+ clauses.push('lifecycle_stage = ?');
1253
+ params.push(input.lifecycleStage);
1254
+ }
1255
+ if (input.capabilityDomain) {
1256
+ clauses.push('capability_domain = ?');
1257
+ params.push(input.capabilityDomain);
1258
+ }
1259
+ if (input.status) {
1260
+ clauses.push('status = ?');
1261
+ params.push(input.status);
1262
+ }
1263
+ const where = clauses.length > 0 ? ` WHERE ${clauses.join(' AND ')}` : '';
1264
+ const rows = db.prepare(`SELECT adoption_id, branch_slug, lifecycle_stage, capability_domain, source_id, status, reason, evidence_refs_json, final_authority, created_at, updated_at, payload_json FROM capability_adoptions${where} ORDER BY updated_at DESC, adoption_id ASC`).all(...params) as RuntimeCapabilityAdoptionRow[];
1265
+ return rows.map(runtimeCapabilityAdoptionFromRow);
1266
+ });
1267
+ }
1268
+
839
1269
  export async function recordRuntimeValidationEnvironmentSession(projectRoot: string, record: RuntimeValidationEnvironmentSessionRecord): Promise<void> {
840
1270
  await withRuntimeStore(projectRoot, ({ db }) => {
841
1271
  db.prepare('INSERT OR REPLACE INTO validation_environment_sessions (session_id, partition, run_id, wave_run_id, status, reuse_key, created_at, updated_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)')
@@ -933,6 +1363,149 @@ export async function listRuntimeAcceptanceEvidenceMaps(projectRoot: string, inp
933
1363
  });
934
1364
  }
935
1365
 
1366
+ interface RuntimeEvidenceSetRow {
1367
+ evidence_set_id: string;
1368
+ branch_slug: string;
1369
+ scope_kind: RuntimeEvidenceSetScopeKind;
1370
+ scope_id: string;
1371
+ source_run_id: string | null;
1372
+ document_contract_hashes_json: string;
1373
+ gate_decision_id: string | null;
1374
+ status: RuntimeEvidenceSetStatus;
1375
+ created_at: string;
1376
+ payload_json: string;
1377
+ }
1378
+
1379
+ interface RuntimeEvidenceSetItemRow {
1380
+ evidence_set_id: string;
1381
+ payload_id: string;
1382
+ logical_ref: string;
1383
+ role: string;
1384
+ required: number;
1385
+ digest_at_selection: string;
1386
+ }
1387
+
1388
+ interface RuntimeSelectionPointerRow {
1389
+ branch_slug: string;
1390
+ scope_kind: RuntimeEvidenceSetScopeKind;
1391
+ scope_id: string;
1392
+ selected_evidence_set_id: string;
1393
+ selected_at: string;
1394
+ selected_by_gate_decision_id: string | null;
1395
+ reason: string;
1396
+ }
1397
+
1398
+ function runtimeEvidenceSetFromDb(db: RuntimeStoreDatabase, evidenceSetId: string): RuntimeEvidenceSetRecord | null {
1399
+ const row = db.prepare('SELECT * FROM evidence_sets WHERE evidence_set_id = ?').get(evidenceSetId) as RuntimeEvidenceSetRow | undefined;
1400
+ if (!row) {
1401
+ return null;
1402
+ }
1403
+ const items = db.prepare('SELECT * FROM evidence_set_items WHERE evidence_set_id = ? ORDER BY logical_ref ASC, payload_id ASC').all(evidenceSetId) as RuntimeEvidenceSetItemRow[];
1404
+ return {
1405
+ evidenceSetId: row.evidence_set_id,
1406
+ branchSlug: row.branch_slug,
1407
+ scopeKind: row.scope_kind,
1408
+ scopeId: row.scope_id,
1409
+ sourceRunId: row.source_run_id,
1410
+ documentContractHashes: JSON.parse(row.document_contract_hashes_json) as Record<string, string | null>,
1411
+ gateDecisionId: row.gate_decision_id,
1412
+ status: row.status,
1413
+ createdAt: row.created_at,
1414
+ items: items.map((item) => ({
1415
+ evidenceSetId: item.evidence_set_id,
1416
+ payloadId: item.payload_id,
1417
+ logicalRef: item.logical_ref,
1418
+ role: item.role,
1419
+ required: item.required === 1,
1420
+ digestAtSelection: item.digest_at_selection
1421
+ })),
1422
+ payload: JSON.parse(row.payload_json)
1423
+ };
1424
+ }
1425
+
1426
+ function payloadsForEvidenceSet(db: RuntimeStoreDatabase, evidenceSet: RuntimeEvidenceSetRecord): RuntimeArtifactPayloadRecord[] {
1427
+ const payloadIds = evidenceSet.items.map((item) => item.payloadId);
1428
+ if (payloadIds.length === 0) {
1429
+ return [];
1430
+ }
1431
+ const rows = db.prepare(`SELECT * FROM artifact_payloads WHERE payload_id IN (${payloadIds.map(() => '?').join(',')})`).all(...payloadIds) as RuntimeArtifactPayloadRow[];
1432
+ const byId = new Map(rows.map((row) => [row.payload_id, runtimeArtifactPayloadFromRow(row)]));
1433
+ return payloadIds.flatMap((payloadId) => byId.get(payloadId) ? [byId.get(payloadId)!] : []);
1434
+ }
1435
+
1436
+ function runtimeSelectionPointerFromRow(row: RuntimeSelectionPointerRow): RuntimeSelectionPointerRecord {
1437
+ return {
1438
+ branchSlug: row.branch_slug,
1439
+ scopeKind: row.scope_kind,
1440
+ scopeId: row.scope_id,
1441
+ selectedEvidenceSetId: row.selected_evidence_set_id,
1442
+ selectedAt: row.selected_at,
1443
+ selectedByGateDecisionId: row.selected_by_gate_decision_id,
1444
+ reason: row.reason
1445
+ };
1446
+ }
1447
+
1448
+ function recordSelectionPointerActivity(db: RuntimeStoreDatabase, pointer: RuntimeSelectionPointerRecord): void {
1449
+ const evidenceSet = db.prepare('SELECT source_run_id FROM evidence_sets WHERE evidence_set_id = ?').get(pointer.selectedEvidenceSetId) as { source_run_id?: string | null } | undefined;
1450
+ if (!evidenceSet?.source_run_id) {
1451
+ return;
1452
+ }
1453
+ const entry: InvocationLedgerEntry = {
1454
+ contract: 'sdd-invocation-ledger-v1',
1455
+ version: INVOCATION_LEDGER_CONTRACT_VERSION,
1456
+ entryId: runtimeScopedId('selection-pointer', pointer.branchSlug, pointer.scopeKind, pointer.scopeId, pointer.selectedEvidenceSetId, pointer.selectedAt),
1457
+ runId: evidenceSet.source_run_id,
1458
+ taskId: pointer.scopeKind === 'task' ? pointer.scopeId : null,
1459
+ branch: pointer.branchSlug,
1460
+ kind: 'policy_evaluation',
1461
+ ref: `selection:${pointer.scopeKind}:${pointer.scopeId}`,
1462
+ status: 'selected',
1463
+ timestamp: pointer.selectedAt,
1464
+ inputHash: pointer.selectedByGateDecisionId,
1465
+ outputHash: pointer.selectedEvidenceSetId,
1466
+ materialRefs: [pointer.selectedEvidenceSetId],
1467
+ metadata: {
1468
+ scopeKind: pointer.scopeKind,
1469
+ scopeId: pointer.scopeId,
1470
+ selectedEvidenceSetId: pointer.selectedEvidenceSetId
1471
+ }
1472
+ };
1473
+ db.prepare('INSERT OR REPLACE INTO activities (activity_id, run_id, task_id, branch, kind, ref, status, created_at, payload_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)')
1474
+ .run(entry.entryId, entry.runId, entry.taskId, entry.branch, entry.kind, entry.ref, entry.status, entry.timestamp, JSON.stringify(entry));
1475
+ }
1476
+
1477
+ function evidenceSetMatchesFallbackRuns(evidenceSet: RuntimeEvidenceSetRecord, fallbackRunIds?: string[]): boolean {
1478
+ if (!fallbackRunIds || fallbackRunIds.length === 0) {
1479
+ return true;
1480
+ }
1481
+ return Boolean(evidenceSet.sourceRunId && fallbackRunIds.includes(evidenceSet.sourceRunId));
1482
+ }
1483
+
1484
+ function legacyFallbackPayloads(db: RuntimeStoreDatabase, input: { branchSlug: string; fallbackRunIds?: string[]; fallbackTaskIds?: string[]; fallbackLogicalRefPrefixes?: string[] }): RuntimeArtifactPayloadRecord[] {
1485
+ const clauses = ['status = ?', 'branch_slug = ?'];
1486
+ const params: string[] = ['active', input.branchSlug];
1487
+ const scopeClauses: string[] = [];
1488
+ const scopeParams: string[] = [];
1489
+ if (input.fallbackRunIds && input.fallbackRunIds.length > 0) {
1490
+ scopeClauses.push(`run_id IN (${input.fallbackRunIds.map(() => '?').join(',')})`);
1491
+ scopeParams.push(...input.fallbackRunIds);
1492
+ }
1493
+ if (input.fallbackTaskIds && input.fallbackTaskIds.length > 0) {
1494
+ scopeClauses.push(`task_id IN (${input.fallbackTaskIds.map(() => '?').join(',')})`);
1495
+ scopeParams.push(...input.fallbackTaskIds);
1496
+ }
1497
+ if (input.fallbackLogicalRefPrefixes && input.fallbackLogicalRefPrefixes.length > 0) {
1498
+ scopeClauses.push(`(task_id IS NULL AND (${input.fallbackLogicalRefPrefixes.map(() => 'logical_ref LIKE ?').join(' OR ')}))`);
1499
+ scopeParams.push(...input.fallbackLogicalRefPrefixes.map((prefix) => `${prefix}%`));
1500
+ }
1501
+ if (scopeClauses.length > 0) {
1502
+ clauses.push(`(${scopeClauses.join(' OR ')})`);
1503
+ params.push(...scopeParams);
1504
+ }
1505
+ const rows = db.prepare(`SELECT * FROM artifact_payloads WHERE ${clauses.join(' AND ')} ORDER BY created_at DESC, sequence DESC`).all(...params) as RuntimeArtifactPayloadRow[];
1506
+ return rows.map(runtimeArtifactPayloadFromRow);
1507
+ }
1508
+
936
1509
  export async function recordLegacyImportFailure(projectRoot: string, runId: string, entityType: string, error: unknown): Promise<void> {
937
1510
  try {
938
1511
  await withRuntimeStore(projectRoot, ({ db }) => {
@@ -951,10 +1524,10 @@ export async function inspectRuntimeStoreEvidence(projectRoot: string): Promise<
951
1524
  const integrityRow = db.prepare('PRAGMA integrity_check').get() as { integrity_check?: string } | undefined;
952
1525
  const schemaVersion = versionRow?.user_version ?? 0;
953
1526
  if (schemaVersion !== RUNTIME_STORE_SCHEMA_VERSION) {
954
- return [{ level: 'FAIL', check: 'runtime_store', message: `Runtime store schema version ${schemaVersion} does not match expected ${RUNTIME_STORE_SCHEMA_VERSION}.`, action: 'Run a compatible sdd version or rebuild the runtime store from legacy .sdd/runs.' }];
1527
+ return [{ level: 'FAIL', check: 'runtime_store', message: `Runtime store schema version ${schemaVersion} does not match expected ${RUNTIME_STORE_SCHEMA_VERSION}.`, action: 'Run a compatible sdd version or rebuild runtime.sqlite projections from canonical docs and accepted stage evidence refs.' }];
955
1528
  }
956
1529
  if (integrityRow?.integrity_check !== 'ok') {
957
- return [{ level: 'FAIL', check: 'runtime_store', message: `Runtime store integrity check failed: ${integrityRow?.integrity_check ?? 'unknown'}.`, action: 'Rebuild runtime projections from legacy .sdd/runs after preserving the database for debugging.' }];
1530
+ return [{ level: 'FAIL', check: 'runtime_store', message: `Runtime store integrity check failed: ${integrityRow?.integrity_check ?? 'unknown'}.`, action: 'Preserve runtime.sqlite for debugging, then rebuild projections from canonical docs and accepted stage evidence refs.' }];
958
1531
  }
959
1532
  const checks: RuntimeStoreDoctorCheck[] = [{ level: 'PASS', check: 'runtime_store', message: `${RUNTIME_STORE_CONTRACT_VERSION} is available at ${storePath} with schema ${schemaVersion}.` }];
960
1533
  const scopeLeak = db.prepare('SELECT COUNT(*) AS count FROM evidence_claims c JOIN runs r ON r.run_id = c.run_id WHERE c.partition IS NOT NULL AND r.partition IS NOT NULL AND c.partition <> r.partition').get() as { count?: number } | undefined;
@@ -969,7 +1542,7 @@ export async function inspectRuntimeStoreEvidence(projectRoot: string): Promise<
969
1542
  const failedLegacy = legacy.find((row) => row.status === 'failed')?.count ?? 0;
970
1543
  const importedLegacy = legacy.find((row) => row.status === 'imported')?.count ?? 0;
971
1544
  checks.push(failedLegacy > 0
972
- ? { level: 'FAIL', check: 'runtime_legacy_import', message: `${failedLegacy} legacy import record(s) failed.`, action: 'Inspect legacy .sdd/runs files and repair malformed state/events/invocation evidence before test or sync-back.' }
1545
+ ? { level: 'FAIL', check: 'runtime_legacy_import', message: `${failedLegacy} legacy import record(s) failed.`, action: 'Inspect imported runtime records and repair malformed state/events/invocation metadata before continuing.' }
973
1546
  : importedLegacy > 0
974
1547
  ? { level: 'PASS', check: 'runtime_legacy_import', message: `${importedLegacy} legacy runtime record(s) imported non-destructively; trust debt was preserved, not upgraded.` }
975
1548
  : { level: 'PASS', check: 'runtime_legacy_import', message: 'No legacy runtime import debt detected.' });
@@ -1002,6 +1575,35 @@ function nextArtifactPayloadSequence(db: RuntimeStoreDatabase, branchSlug: strin
1002
1575
  return (row?.sequence ?? 0) + 1;
1003
1576
  }
1004
1577
 
1578
+ interface RuntimeTestStepRow {
1579
+ test_step_id: string;
1580
+ test_run_id: string;
1581
+ run_id: string;
1582
+ task_id: string;
1583
+ command: string;
1584
+ status: string;
1585
+ exit_code: number | null;
1586
+ duration_ms: number;
1587
+ output_artifact: string | null;
1588
+ payload_json: string;
1589
+ }
1590
+
1591
+ function runtimeTestStepFromRow(row: RuntimeTestStepRow): RuntimeTestStepRecord {
1592
+ return {
1593
+ stepId: row.test_step_id,
1594
+ testRunId: row.test_run_id,
1595
+ runId: row.run_id,
1596
+ taskId: row.task_id,
1597
+ command: row.command,
1598
+ status: row.status,
1599
+ exitCode: row.exit_code,
1600
+ durationMs: row.duration_ms,
1601
+ outputArtifact: row.output_artifact,
1602
+ payload: JSON.parse(row.payload_json)
1603
+ };
1604
+ }
1605
+
1606
+
1005
1607
  function runtimeArtifactPayloadFromRow(row: RuntimeArtifactPayloadRow): RuntimeArtifactPayloadRecord {
1006
1608
  return {
1007
1609
  payloadId: row.payload_id,
@@ -1021,38 +1623,242 @@ function runtimeArtifactPayloadFromRow(row: RuntimeArtifactPayloadRow): RuntimeA
1021
1623
  };
1022
1624
  }
1023
1625
 
1024
- interface RuntimeSyncBackDecisionRow {
1025
- decision_id: string;
1626
+
1627
+ interface RuntimeValidationCacheEntryRow {
1628
+ cache_key: string;
1629
+ branch_slug: string;
1630
+ command: string;
1631
+ status: RuntimeValidationCacheEntryStatus;
1632
+ source_test_run_id: string;
1633
+ source_run_id: string;
1634
+ source_evidence_set_id: string | null;
1635
+ output_artifact: string | null;
1636
+ stdout_digest: string;
1637
+ stderr_digest: string;
1638
+ created_at: string;
1639
+ last_used_at: string;
1640
+ payload_json: string;
1641
+ }
1642
+
1643
+ function runtimeValidationCacheEntryFromRow(row: RuntimeValidationCacheEntryRow): RuntimeValidationCacheEntryRecord {
1644
+ return {
1645
+ cacheKey: row.cache_key,
1646
+ branchSlug: row.branch_slug,
1647
+ command: row.command,
1648
+ status: row.status,
1649
+ sourceTestRunId: row.source_test_run_id,
1650
+ sourceRunId: row.source_run_id,
1651
+ sourceEvidenceSetId: row.source_evidence_set_id,
1652
+ outputArtifact: row.output_artifact,
1653
+ stdoutDigest: row.stdout_digest,
1654
+ stderrDigest: row.stderr_digest,
1655
+ createdAt: row.created_at,
1656
+ lastUsedAt: row.last_used_at,
1657
+ payload: JSON.parse(row.payload_json)
1658
+ };
1659
+ }
1660
+
1661
+ interface RuntimeValidationCacheUseRow {
1662
+ use_id: string;
1663
+ cache_key: string;
1664
+ branch_slug: string;
1665
+ test_run_id: string;
1026
1666
  run_id: string;
1027
- branch: string;
1667
+ task_id: string;
1668
+ source_test_run_id: string;
1669
+ source_evidence_set_id: string | null;
1670
+ reused_at: string;
1671
+ mapped_task_ids_json: string;
1672
+ reason: string;
1673
+ payload_json: string;
1674
+ }
1675
+
1676
+ function runtimeValidationCacheUseFromRow(row: RuntimeValidationCacheUseRow): RuntimeValidationCacheUseRecord {
1677
+ return {
1678
+ useId: row.use_id,
1679
+ cacheKey: row.cache_key,
1680
+ branchSlug: row.branch_slug,
1681
+ testRunId: row.test_run_id,
1682
+ runId: row.run_id,
1683
+ taskId: row.task_id,
1684
+ sourceTestRunId: row.source_test_run_id,
1685
+ sourceEvidenceSetId: row.source_evidence_set_id,
1686
+ reusedAt: row.reused_at,
1687
+ mappedTaskIds: parseStringList(row.mapped_task_ids_json),
1688
+ reason: row.reason,
1689
+ payload: JSON.parse(row.payload_json)
1690
+ };
1691
+ }
1692
+
1693
+ interface RuntimeRepairRow {
1694
+ repair_id: string;
1695
+ branch_slug: string;
1028
1696
  task_id: string | null;
1029
- status: string;
1030
- proposal_path: string | null;
1031
- proposal_digest: string | null;
1032
- proposal_payload_id: string | null;
1697
+ repair_type: RuntimeRepairType;
1698
+ repair_of_run_id: string | null;
1699
+ repair_of_gate_decision_id: string | null;
1700
+ status: RuntimeRepairStatus;
1701
+ affected_tasks_json: string;
1702
+ blockers_json: string;
1703
+ recommended_commands_json: string;
1704
+ required_evidence_json: string;
1033
1705
  created_at: string;
1034
- updated_at: string;
1706
+ resolved_at: string | null;
1035
1707
  payload_json: string;
1036
1708
  }
1037
1709
 
1038
- function runtimeSyncBackDecisionFromRow(row: RuntimeSyncBackDecisionRow): RuntimeSyncBackDecisionRecord {
1039
- const parsed = JSON.parse(row.payload_json) as { payload?: unknown; reasons?: unknown };
1710
+ function runtimeRepairFromRow(row: RuntimeRepairRow): RuntimeRepairRecord {
1040
1711
  return {
1041
- decisionId: row.decision_id,
1042
- runId: row.run_id,
1043
- branch: row.branch,
1712
+ repairId: row.repair_id,
1713
+ branchSlug: row.branch_slug,
1044
1714
  taskId: row.task_id,
1715
+ repairType: row.repair_type,
1716
+ repairOfRunId: row.repair_of_run_id,
1717
+ repairOfGateDecisionId: row.repair_of_gate_decision_id,
1045
1718
  status: row.status,
1046
- proposalPath: row.proposal_path,
1047
- proposalDigest: row.proposal_digest,
1048
- proposalPayloadId: row.proposal_payload_id,
1049
- reasons: Array.isArray(parsed.reasons) ? parsed.reasons.filter((reason): reason is string => typeof reason === 'string') : [],
1719
+ affectedTasks: parseStringList(row.affected_tasks_json),
1720
+ blockers: parseStringList(row.blockers_json),
1721
+ recommendedCommands: parseStringList(row.recommended_commands_json),
1722
+ requiredEvidence: parseStringList(row.required_evidence_json),
1723
+ createdAt: row.created_at,
1724
+ resolvedAt: row.resolved_at,
1725
+ payload: JSON.parse(row.payload_json)
1726
+ };
1727
+ }
1728
+
1729
+ interface RuntimeCapabilityAdoptionRow {
1730
+ adoption_id: string;
1731
+ branch_slug: string;
1732
+ lifecycle_stage: RuntimeCapabilityAdoptionStage;
1733
+ capability_domain: string;
1734
+ source_id: string | null;
1735
+ status: RuntimeCapabilityAdoptionStatus;
1736
+ reason: string;
1737
+ evidence_refs_json: string;
1738
+ final_authority: RuntimeCapabilityAdoptionAuthority;
1739
+ created_at: string;
1740
+ updated_at: string;
1741
+ payload_json: string;
1742
+ }
1743
+
1744
+ function runtimeCapabilityAdoptionFromRow(row: RuntimeCapabilityAdoptionRow): RuntimeCapabilityAdoptionRecord {
1745
+ return {
1746
+ adoptionId: row.adoption_id,
1747
+ branchSlug: row.branch_slug,
1748
+ lifecycleStage: row.lifecycle_stage,
1749
+ capabilityDomain: row.capability_domain,
1750
+ sourceId: row.source_id,
1751
+ status: row.status,
1752
+ reason: row.reason,
1753
+ evidenceRefs: parseStringList(row.evidence_refs_json),
1754
+ finalAuthority: row.final_authority,
1050
1755
  createdAt: row.created_at,
1051
1756
  updatedAt: row.updated_at,
1052
- payload: parsed.payload ?? null
1757
+ payload: JSON.parse(row.payload_json)
1758
+ };
1759
+ }
1760
+
1761
+ interface RuntimeStageArtifactRow {
1762
+ artifact_id: string;
1763
+ branch_slug: string;
1764
+ stage: RegisteredStageArtifact['stage'];
1765
+ artifact_kind: RegisteredStageArtifact['kind'];
1766
+ producer: RegisteredStageArtifact['producer'];
1767
+ artifact_ref: string;
1768
+ content_hash: string;
1769
+ contract: string;
1770
+ target_ref: string | null;
1771
+ target_hash: string | null;
1772
+ review_ref: string | null;
1773
+ review_hash: string | null;
1774
+ verdict: RegisteredStageArtifact['verdict'] | null;
1775
+ finding_count: number | null;
1776
+ blocking_count: number | null;
1777
+ recommendation: RegisteredStageArtifact['recommendation'] | null;
1778
+ frontmatter_json: string;
1779
+ registered_at: string;
1780
+ payload_json: string;
1781
+ }
1782
+
1783
+ function runtimeStageArtifactFromRow(row: RuntimeStageArtifactRow): RegisteredStageArtifact {
1784
+ const payload = JSON.parse(row.payload_json) as RegisteredStageArtifact;
1785
+ return {
1786
+ ...payload,
1787
+ artifactId: row.artifact_id,
1788
+ branch: row.branch_slug,
1789
+ stage: row.stage,
1790
+ kind: row.artifact_kind,
1791
+ producer: row.producer,
1792
+ ref: row.artifact_ref,
1793
+ hash: row.content_hash,
1794
+ contract: row.contract,
1795
+ targetRef: row.target_ref ? runtimeRefFromStoredRef(row.target_ref, row.target_hash ?? undefined) : undefined,
1796
+ targetHash: row.target_hash ?? undefined,
1797
+ reviewRef: row.review_ref ? runtimeRefFromStoredRef(row.review_ref, row.review_hash ?? undefined) : undefined,
1798
+ reviewHash: row.review_hash ?? undefined,
1799
+ verdict: row.verdict ?? undefined,
1800
+ findingCount: row.finding_count ?? undefined,
1801
+ blockingCount: row.blocking_count ?? undefined,
1802
+ recommendation: row.recommendation ?? undefined,
1803
+ frontmatter: JSON.parse(row.frontmatter_json) as Record<string, unknown>,
1804
+ registeredAt: row.registered_at
1805
+ };
1806
+ }
1807
+
1808
+ interface RuntimeStageCollaborationContractRow {
1809
+ contract_id: string;
1810
+ branch_slug: string;
1811
+ stage: RegisteredStageCollaborationContract['stage'];
1812
+ contract_ref: string;
1813
+ content_hash: string;
1814
+ contract_version: string;
1815
+ producer: RegisteredStageCollaborationContract['producer'];
1816
+ work_order_id: string | null;
1817
+ status: RegisteredStageCollaborationContract['status'];
1818
+ validation_errors_json: string;
1819
+ selected_agents_json: string;
1820
+ selected_skills_json: string;
1821
+ selected_materials_json: string;
1822
+ evidence_contracts_json: string;
1823
+ checkpoint_plan_json: string;
1824
+ rework_plan_json: string;
1825
+ permission_projection_json: string;
1826
+ frontmatter_json: string;
1827
+ registered_at: string;
1828
+ payload_json: string;
1829
+ }
1830
+
1831
+ function runtimeStageCollaborationContractFromRow(row: RuntimeStageCollaborationContractRow): RegisteredStageCollaborationContract {
1832
+ const payload = JSON.parse(row.payload_json) as RegisteredStageCollaborationContract;
1833
+ return {
1834
+ ...payload,
1835
+ contractId: row.contract_id,
1836
+ branch: row.branch_slug,
1837
+ stage: row.stage,
1838
+ ref: row.contract_ref,
1839
+ hash: row.content_hash,
1840
+ contract: row.contract_version,
1841
+ producer: row.producer,
1842
+ workOrderId: row.work_order_id,
1843
+ status: row.status,
1844
+ validationErrors: JSON.parse(row.validation_errors_json) as string[],
1845
+ selectedAgents: JSON.parse(row.selected_agents_json) as string[],
1846
+ selectedSkills: JSON.parse(row.selected_skills_json) as string[],
1847
+ selectedMaterialPacks: JSON.parse(row.selected_materials_json) as string[],
1848
+ evidenceContracts: JSON.parse(row.evidence_contracts_json) as string[],
1849
+ checkpointPlan: JSON.parse(row.checkpoint_plan_json) as string[],
1850
+ reworkPlan: JSON.parse(row.rework_plan_json) as RegisteredStageCollaborationContract['reworkPlan'],
1851
+ permissionProjection: JSON.parse(row.permission_projection_json) as RegisteredStageCollaborationContract['permissionProjection'],
1852
+ frontmatter: JSON.parse(row.frontmatter_json) as Record<string, unknown>,
1853
+ registeredAt: row.registered_at
1053
1854
  };
1054
1855
  }
1055
1856
 
1857
+ function runtimeRefFromStoredRef(ref: string, hash?: string): { kind: 'document' | 'artifact' | 'projection' | 'external'; ref: string; hash?: string } {
1858
+ const kind = ref.startsWith('specs/') ? 'document' : ref.startsWith('.sdd/runs/') ? 'artifact' : ref.startsWith('projection:') ? 'projection' : 'external';
1859
+ return hash ? { kind, ref, hash } : { kind, ref };
1860
+ }
1861
+
1056
1862
  interface RuntimeDurableGapRow {
1057
1863
  gap_id: string;
1058
1864
  partition: string;