sdd-agent-platform 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. package/README.md +18 -23
  2. package/node_modules/@sdd-agent-platform/core/dist/ai-tools.js +31 -28
  3. package/node_modules/@sdd-agent-platform/core/dist/ai-tools.js.map +1 -1
  4. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.js +3 -2
  5. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.js.map +1 -1
  6. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.d.ts +1 -1
  7. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.js +14 -5
  8. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.js.map +1 -1
  9. package/node_modules/@sdd-agent-platform/core/dist/contracts.d.ts +2 -0
  10. package/node_modules/@sdd-agent-platform/core/dist/contracts.js +2 -0
  11. package/node_modules/@sdd-agent-platform/core/dist/contracts.js.map +1 -1
  12. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-evidence.js +3 -3
  13. package/node_modules/@sdd-agent-platform/core/dist/doctor/checks/run-evidence.js.map +1 -1
  14. package/node_modules/@sdd-agent-platform/core/dist/doctor/doctor.js +155 -1
  15. package/node_modules/@sdd-agent-platform/core/dist/doctor/doctor.js.map +1 -1
  16. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.d.ts +23 -0
  17. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js +54 -0
  18. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js.map +1 -0
  19. package/node_modules/@sdd-agent-platform/core/dist/evidence-runtime/contracts.d.ts +11 -0
  20. package/node_modules/@sdd-agent-platform/core/dist/execution/agent-execution-records.js +15 -8
  21. package/node_modules/@sdd-agent-platform/core/dist/execution/agent-execution-records.js.map +1 -1
  22. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js +14 -6
  23. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js.map +1 -1
  24. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.d.ts +112 -0
  25. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js +145 -0
  26. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js.map +1 -0
  27. package/node_modules/@sdd-agent-platform/core/dist/instructions.js +36 -36
  28. package/node_modules/@sdd-agent-platform/core/dist/instructions.js.map +1 -1
  29. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.d.ts +2 -0
  30. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js +37 -17
  31. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js.map +1 -1
  32. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.d.ts +16 -1
  33. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js +174 -16
  34. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js.map +1 -1
  35. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js +2 -2
  36. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js.map +1 -1
  37. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.d.ts +10 -0
  38. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js +31 -1
  39. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js.map +1 -1
  40. package/node_modules/@sdd-agent-platform/core/dist/registries/capability-sources.d.ts +2 -17
  41. package/node_modules/@sdd-agent-platform/core/dist/registries/capability-sources.js +222 -10
  42. package/node_modules/@sdd-agent-platform/core/dist/registries/capability-sources.js.map +1 -1
  43. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js +5 -5
  44. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js.map +1 -1
  45. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime-config.js +27 -12
  46. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime-config.js.map +1 -1
  47. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime.d.ts +59 -1
  48. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.d.ts +3 -1
  49. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js +191 -0
  50. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js.map +1 -1
  51. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js +32 -6
  52. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js.map +1 -1
  53. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-inspection.js +11 -4
  54. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-inspection.js.map +1 -1
  55. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js +31 -3
  56. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js.map +1 -1
  57. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js +48 -15
  58. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js.map +1 -1
  59. package/node_modules/@sdd-agent-platform/core/dist/run-state/events.js +2 -2
  60. package/node_modules/@sdd-agent-platform/core/dist/run-state/events.js.map +1 -1
  61. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.d.ts +3 -1
  62. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js +15 -49
  63. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js.map +1 -1
  64. package/node_modules/@sdd-agent-platform/core/dist/run-state/invocation-ledger.js +2 -2
  65. package/node_modules/@sdd-agent-platform/core/dist/run-state/invocation-ledger.js.map +1 -1
  66. package/node_modules/@sdd-agent-platform/core/dist/run-state/model.d.ts +25 -1
  67. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js +21 -14
  68. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js.map +1 -1
  69. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.d.ts +62 -0
  70. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js +130 -0
  71. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js.map +1 -0
  72. package/node_modules/@sdd-agent-platform/core/dist/run-state.d.ts +1 -0
  73. package/node_modules/@sdd-agent-platform/core/dist/run-state.js +1 -0
  74. package/node_modules/@sdd-agent-platform/core/dist/run-state.js.map +1 -1
  75. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.d.ts +10 -0
  76. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js +44 -14
  77. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js.map +1 -1
  78. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/context.js +1 -1
  79. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/context.js.map +1 -1
  80. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.d.ts +4 -0
  81. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js +189 -0
  82. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js.map +1 -0
  83. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js +12 -3
  84. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js.map +1 -1
  85. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.d.ts +20 -0
  86. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js +101 -21
  87. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js.map +1 -1
  88. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.d.ts +62 -1
  89. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js +192 -4
  90. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js.map +1 -1
  91. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.d.ts +195 -2
  92. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.js +499 -2
  93. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.js.map +1 -1
  94. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js +23 -1
  95. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js.map +1 -1
  96. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.d.ts +19 -0
  97. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js +114 -12
  98. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js.map +1 -1
  99. package/node_modules/@sdd-agent-platform/core/dist/test-support/fixtures.js +21 -0
  100. package/node_modules/@sdd-agent-platform/core/dist/test-support/fixtures.js.map +1 -1
  101. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js +16 -2
  102. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js.map +1 -1
  103. package/node_modules/@sdd-agent-platform/core/dist/tsconfig.tsbuildinfo +1 -1
  104. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js +34 -2
  105. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js.map +1 -1
  106. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js +15 -5
  107. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js.map +1 -1
  108. package/node_modules/@sdd-agent-platform/core/dist/verification/review-gate.d.ts +22 -0
  109. package/node_modules/@sdd-agent-platform/core/dist/verification/review-gate.js +53 -0
  110. package/node_modules/@sdd-agent-platform/core/dist/verification/review-gate.js.map +1 -0
  111. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js +102 -9
  112. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js.map +1 -1
  113. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.d.ts +16 -1
  114. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js +355 -69
  115. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js.map +1 -1
  116. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.d.ts +58 -0
  117. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js +428 -0
  118. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js.map +1 -0
  119. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.d.ts +2 -0
  120. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js +116 -18
  121. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js.map +1 -1
  122. package/node_modules/@sdd-agent-platform/core/dist/verification.d.ts +2 -0
  123. package/node_modules/@sdd-agent-platform/core/dist/verification.js +2 -0
  124. package/node_modules/@sdd-agent-platform/core/dist/verification.js.map +1 -1
  125. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.d.ts +24 -0
  126. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js +182 -0
  127. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js.map +1 -0
  128. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.d.ts +4 -0
  129. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js +130 -0
  130. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js.map +1 -0
  131. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.d.ts +4 -0
  132. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js +146 -0
  133. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js.map +1 -0
  134. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/types.d.ts +89 -0
  135. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/types.js +2 -0
  136. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/types.js.map +1 -0
  137. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.d.ts +1 -0
  138. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js +16 -1
  139. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  140. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/dependencies.d.ts +8 -4
  141. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/dependencies.js +25 -11
  142. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/dependencies.js.map +1 -1
  143. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.d.ts +38 -0
  144. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js +122 -0
  145. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js.map +1 -0
  146. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.d.ts +27 -0
  147. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js +166 -37
  148. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js.map +1 -1
  149. package/node_modules/@sdd-agent-platform/core/dist/workflow-state.d.ts +1 -0
  150. package/node_modules/@sdd-agent-platform/core/dist/workflow-state.js +1 -0
  151. package/node_modules/@sdd-agent-platform/core/dist/workflow-state.js.map +1 -1
  152. package/node_modules/@sdd-agent-platform/core/package.json +1 -1
  153. package/node_modules/@sdd-agent-platform/core/src/ai-tools.ts +31 -28
  154. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-result.test.ts +50 -4
  155. package/node_modules/@sdd-agent-platform/core/src/config/init-project.test.ts +13 -10
  156. package/node_modules/@sdd-agent-platform/core/src/config/init-project.ts +3 -2
  157. package/node_modules/@sdd-agent-platform/core/src/config/starter-documents.ts +15 -5
  158. package/node_modules/@sdd-agent-platform/core/src/contracts.ts +2 -0
  159. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-evidence.ts +3 -3
  160. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.test.ts +117 -5
  161. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.ts +164 -1
  162. package/node_modules/@sdd-agent-platform/core/src/evidence/lookup.ts +80 -0
  163. package/node_modules/@sdd-agent-platform/core/src/evidence-runtime/contracts.ts +12 -0
  164. package/node_modules/@sdd-agent-platform/core/src/execution/agent-execution-records.ts +16 -11
  165. package/node_modules/@sdd-agent-platform/core/src/execution/background-executor.test.ts +7 -0
  166. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.test.ts +5 -0
  167. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.ts +14 -6
  168. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.test.ts +102 -0
  169. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.ts +271 -0
  170. package/node_modules/@sdd-agent-platform/core/src/execution/wave-executor.test.ts +4 -0
  171. package/node_modules/@sdd-agent-platform/core/src/governance/policy.test.ts +2 -0
  172. package/node_modules/@sdd-agent-platform/core/src/instructions.test.ts +11 -5
  173. package/node_modules/@sdd-agent-platform/core/src/instructions.ts +36 -36
  174. package/node_modules/@sdd-agent-platform/core/src/lifecycle/ship.ts +39 -17
  175. package/node_modules/@sdd-agent-platform/core/src/phase8-contracts.test.ts +3 -2
  176. package/node_modules/@sdd-agent-platform/core/src/phase8-risk-kernel.test.ts +5 -0
  177. package/node_modules/@sdd-agent-platform/core/src/planning/task-graph.test.ts +2 -0
  178. package/node_modules/@sdd-agent-platform/core/src/planning/wave-plan.test.ts +3 -0
  179. package/node_modules/@sdd-agent-platform/core/src/registries/agent-capability-catalog.ts +269 -17
  180. package/node_modules/@sdd-agent-platform/core/src/registries/agent-registry.ts +2 -2
  181. package/node_modules/@sdd-agent-platform/core/src/registries/agent-runtime-static.ts +41 -1
  182. package/node_modules/@sdd-agent-platform/core/src/registries/capability-sources.ts +238 -15
  183. package/node_modules/@sdd-agent-platform/core/src/registries/registries.test.ts +27 -2
  184. package/node_modules/@sdd-agent-platform/core/src/registries/workflow-gates.ts +5 -5
  185. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime-config.ts +31 -12
  186. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime.ts +66 -1
  187. package/node_modules/@sdd-agent-platform/core/src/router/route-projection.ts +211 -0
  188. package/node_modules/@sdd-agent-platform/core/src/router/route-sdd-task.test.ts +151 -3
  189. package/node_modules/@sdd-agent-platform/core/src/router/routing.ts +35 -6
  190. package/node_modules/@sdd-agent-platform/core/src/router/runtime-inspection.ts +11 -4
  191. package/node_modules/@sdd-agent-platform/core/src/router/runtime-validation.ts +32 -3
  192. package/node_modules/@sdd-agent-platform/core/src/run-state/artifacts.ts +48 -15
  193. package/node_modules/@sdd-agent-platform/core/src/run-state/events.ts +2 -2
  194. package/node_modules/@sdd-agent-platform/core/src/run-state/inspect-run.ts +17 -52
  195. package/node_modules/@sdd-agent-platform/core/src/run-state/invocation-ledger.ts +2 -2
  196. package/node_modules/@sdd-agent-platform/core/src/run-state/model.ts +28 -1
  197. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.test.ts +3 -0
  198. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.ts +22 -18
  199. package/node_modules/@sdd-agent-platform/core/src/run-state/task-evidence.ts +206 -0
  200. package/node_modules/@sdd-agent-platform/core/src/run-state.ts +1 -0
  201. package/node_modules/@sdd-agent-platform/core/src/runtime-paths.ts +54 -14
  202. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/context.ts +1 -1
  203. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/document-hashes.ts +207 -0
  204. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/run-binding.ts +12 -3
  205. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.test.ts +139 -0
  206. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.ts +137 -24
  207. package/node_modules/@sdd-agent-platform/core/src/status/project-status.ts +268 -5
  208. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.test.ts +368 -4
  209. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.ts +697 -2
  210. package/node_modules/@sdd-agent-platform/core/src/sync-back/apply.ts +23 -1
  211. package/node_modules/@sdd-agent-platform/core/src/sync-back/inspect.ts +145 -12
  212. package/node_modules/@sdd-agent-platform/core/src/sync-back/sync-back.test.ts +132 -9
  213. package/node_modules/@sdd-agent-platform/core/src/test-support/fixtures.ts +21 -0
  214. package/node_modules/@sdd-agent-platform/core/src/test-support/run-state.ts +16 -2
  215. package/node_modules/@sdd-agent-platform/core/src/verification/goal-verify.test.ts +1 -1
  216. package/node_modules/@sdd-agent-platform/core/src/verification/goal-verify.ts +38 -5
  217. package/node_modules/@sdd-agent-platform/core/src/verification/rendering.ts +15 -5
  218. package/node_modules/@sdd-agent-platform/core/src/verification/review-gate.test.ts +77 -0
  219. package/node_modules/@sdd-agent-platform/core/src/verification/review-gate.ts +77 -0
  220. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.test.ts +64 -4
  221. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.ts +110 -12
  222. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.test.ts +72 -25
  223. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.ts +402 -77
  224. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.test.ts +341 -0
  225. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.ts +513 -0
  226. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.test.ts +144 -5
  227. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.ts +129 -18
  228. package/node_modules/@sdd-agent-platform/core/src/verification.ts +2 -0
  229. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/evidence-packet.ts +196 -0
  230. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.test.ts +171 -0
  231. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.ts +143 -0
  232. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.test.ts +137 -0
  233. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.ts +155 -0
  234. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/types.ts +114 -0
  235. package/node_modules/@sdd-agent-platform/core/src/workflow-state/affected-file-conflicts.ts +18 -1
  236. package/node_modules/@sdd-agent-platform/core/src/workflow-state/dependencies.test.ts +1 -1
  237. package/node_modules/@sdd-agent-platform/core/src/workflow-state/dependencies.ts +33 -11
  238. package/node_modules/@sdd-agent-platform/core/src/workflow-state/latest-eligible-run.ts +156 -0
  239. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.test.ts +351 -2
  240. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.ts +227 -39
  241. package/node_modules/@sdd-agent-platform/core/src/workflow-state.ts +1 -0
  242. package/package.json +1 -1
  243. package/packages/cli/dist/commands/status.js +2 -2
  244. package/packages/cli/dist/commands/status.js.map +1 -1
  245. package/packages/cli/dist/commands/sync-back.js +1 -1
  246. package/packages/cli/dist/commands/sync-back.js.map +1 -1
  247. package/packages/cli/dist/commands/tasks.js +4 -4
  248. package/packages/cli/dist/commands/tasks.js.map +1 -1
  249. package/packages/cli/dist/commands/test.js +94 -5
  250. package/packages/cli/dist/commands/test.js.map +1 -1
  251. package/packages/cli/dist/commands/verifies.js +5 -3
  252. package/packages/cli/dist/commands/verifies.js.map +1 -1
  253. package/packages/cli/dist/commands/verify.js +48 -7
  254. package/packages/cli/dist/commands/verify.js.map +1 -1
  255. package/packages/cli/dist/help.js +32 -18
  256. package/packages/cli/dist/help.js.map +1 -1
  257. package/packages/cli/dist/renderers/artifacts.js +1 -1
  258. package/packages/cli/dist/renderers/artifacts.js.map +1 -1
  259. package/packages/cli/dist/renderers/registry-runtime.js +7 -2
  260. package/packages/cli/dist/renderers/registry-runtime.js.map +1 -1
  261. package/packages/cli/dist/renderers/router.js +4 -2
  262. package/packages/cli/dist/renderers/router.js.map +1 -1
  263. package/packages/cli/dist/renderers/workflow.js +33 -12
  264. package/packages/cli/dist/renderers/workflow.js.map +1 -1
  265. package/packages/cli/dist/tsconfig.tsbuildinfo +1 -1
  266. package/packages/cli/package.json +2 -2
  267. package/packages/core/dist/ai-tools.js +31 -28
  268. package/packages/core/dist/ai-tools.js.map +1 -1
  269. package/packages/core/dist/config/init-project.js +3 -2
  270. package/packages/core/dist/config/init-project.js.map +1 -1
  271. package/packages/core/dist/config/starter-documents.d.ts +1 -1
  272. package/packages/core/dist/config/starter-documents.js +14 -5
  273. package/packages/core/dist/config/starter-documents.js.map +1 -1
  274. package/packages/core/dist/contracts.d.ts +2 -0
  275. package/packages/core/dist/contracts.js +2 -0
  276. package/packages/core/dist/contracts.js.map +1 -1
  277. package/packages/core/dist/doctor/checks/run-evidence.js +3 -3
  278. package/packages/core/dist/doctor/checks/run-evidence.js.map +1 -1
  279. package/packages/core/dist/doctor/doctor.js +155 -1
  280. package/packages/core/dist/doctor/doctor.js.map +1 -1
  281. package/packages/core/dist/evidence/lookup.d.ts +23 -0
  282. package/packages/core/dist/evidence/lookup.js +54 -0
  283. package/packages/core/dist/evidence/lookup.js.map +1 -0
  284. package/packages/core/dist/evidence-runtime/contracts.d.ts +11 -0
  285. package/packages/core/dist/execution/agent-execution-records.js +15 -8
  286. package/packages/core/dist/execution/agent-execution-records.js.map +1 -1
  287. package/packages/core/dist/execution/resident-worker.js +14 -6
  288. package/packages/core/dist/execution/resident-worker.js.map +1 -1
  289. package/packages/core/dist/execution/stage-team-runtime.d.ts +112 -0
  290. package/packages/core/dist/execution/stage-team-runtime.js +145 -0
  291. package/packages/core/dist/execution/stage-team-runtime.js.map +1 -0
  292. package/packages/core/dist/instructions.js +36 -36
  293. package/packages/core/dist/instructions.js.map +1 -1
  294. package/packages/core/dist/lifecycle/ship.d.ts +2 -0
  295. package/packages/core/dist/lifecycle/ship.js +37 -17
  296. package/packages/core/dist/lifecycle/ship.js.map +1 -1
  297. package/packages/core/dist/registries/agent-capability-catalog.d.ts +16 -1
  298. package/packages/core/dist/registries/agent-capability-catalog.js +174 -16
  299. package/packages/core/dist/registries/agent-capability-catalog.js.map +1 -1
  300. package/packages/core/dist/registries/agent-registry.js +2 -2
  301. package/packages/core/dist/registries/agent-registry.js.map +1 -1
  302. package/packages/core/dist/registries/agent-runtime-static.d.ts +10 -0
  303. package/packages/core/dist/registries/agent-runtime-static.js +31 -1
  304. package/packages/core/dist/registries/agent-runtime-static.js.map +1 -1
  305. package/packages/core/dist/registries/capability-sources.d.ts +2 -17
  306. package/packages/core/dist/registries/capability-sources.js +222 -10
  307. package/packages/core/dist/registries/capability-sources.js.map +1 -1
  308. package/packages/core/dist/registries/workflow-gates.js +5 -5
  309. package/packages/core/dist/registries/workflow-gates.js.map +1 -1
  310. package/packages/core/dist/router/agent-runtime-config.js +27 -12
  311. package/packages/core/dist/router/agent-runtime-config.js.map +1 -1
  312. package/packages/core/dist/router/agent-runtime.d.ts +59 -1
  313. package/packages/core/dist/router/route-projection.d.ts +3 -1
  314. package/packages/core/dist/router/route-projection.js +191 -0
  315. package/packages/core/dist/router/route-projection.js.map +1 -1
  316. package/packages/core/dist/router/routing.js +32 -6
  317. package/packages/core/dist/router/routing.js.map +1 -1
  318. package/packages/core/dist/router/runtime-inspection.js +11 -4
  319. package/packages/core/dist/router/runtime-inspection.js.map +1 -1
  320. package/packages/core/dist/router/runtime-validation.js +31 -3
  321. package/packages/core/dist/router/runtime-validation.js.map +1 -1
  322. package/packages/core/dist/run-state/artifacts.js +48 -15
  323. package/packages/core/dist/run-state/artifacts.js.map +1 -1
  324. package/packages/core/dist/run-state/events.js +2 -2
  325. package/packages/core/dist/run-state/events.js.map +1 -1
  326. package/packages/core/dist/run-state/inspect-run.d.ts +3 -1
  327. package/packages/core/dist/run-state/inspect-run.js +15 -49
  328. package/packages/core/dist/run-state/inspect-run.js.map +1 -1
  329. package/packages/core/dist/run-state/invocation-ledger.js +2 -2
  330. package/packages/core/dist/run-state/invocation-ledger.js.map +1 -1
  331. package/packages/core/dist/run-state/model.d.ts +25 -1
  332. package/packages/core/dist/run-state/run-state.js +21 -14
  333. package/packages/core/dist/run-state/run-state.js.map +1 -1
  334. package/packages/core/dist/run-state/task-evidence.d.ts +62 -0
  335. package/packages/core/dist/run-state/task-evidence.js +130 -0
  336. package/packages/core/dist/run-state/task-evidence.js.map +1 -0
  337. package/packages/core/dist/run-state.d.ts +1 -0
  338. package/packages/core/dist/run-state.js +1 -0
  339. package/packages/core/dist/run-state.js.map +1 -1
  340. package/packages/core/dist/runtime-paths.d.ts +10 -0
  341. package/packages/core/dist/runtime-paths.js +44 -14
  342. package/packages/core/dist/runtime-paths.js.map +1 -1
  343. package/packages/core/dist/sdd-docs/context.js +1 -1
  344. package/packages/core/dist/sdd-docs/context.js.map +1 -1
  345. package/packages/core/dist/sdd-docs/document-hashes.d.ts +4 -0
  346. package/packages/core/dist/sdd-docs/document-hashes.js +189 -0
  347. package/packages/core/dist/sdd-docs/document-hashes.js.map +1 -0
  348. package/packages/core/dist/sdd-docs/run-binding.js +12 -3
  349. package/packages/core/dist/sdd-docs/run-binding.js.map +1 -1
  350. package/packages/core/dist/sdd-docs/task-parser.d.ts +20 -0
  351. package/packages/core/dist/sdd-docs/task-parser.js +101 -21
  352. package/packages/core/dist/sdd-docs/task-parser.js.map +1 -1
  353. package/packages/core/dist/status/project-status.d.ts +62 -1
  354. package/packages/core/dist/status/project-status.js +192 -4
  355. package/packages/core/dist/status/project-status.js.map +1 -1
  356. package/packages/core/dist/storage/runtime-store.d.ts +195 -2
  357. package/packages/core/dist/storage/runtime-store.js +499 -2
  358. package/packages/core/dist/storage/runtime-store.js.map +1 -1
  359. package/packages/core/dist/sync-back/apply.js +23 -1
  360. package/packages/core/dist/sync-back/apply.js.map +1 -1
  361. package/packages/core/dist/sync-back/inspect.d.ts +19 -0
  362. package/packages/core/dist/sync-back/inspect.js +114 -12
  363. package/packages/core/dist/sync-back/inspect.js.map +1 -1
  364. package/packages/core/dist/test-support/fixtures.js +21 -0
  365. package/packages/core/dist/test-support/fixtures.js.map +1 -1
  366. package/packages/core/dist/test-support/run-state.js +16 -2
  367. package/packages/core/dist/test-support/run-state.js.map +1 -1
  368. package/packages/core/dist/tsconfig.tsbuildinfo +1 -1
  369. package/packages/core/dist/verification/goal-verify.js +34 -2
  370. package/packages/core/dist/verification/goal-verify.js.map +1 -1
  371. package/packages/core/dist/verification/rendering.js +15 -5
  372. package/packages/core/dist/verification/rendering.js.map +1 -1
  373. package/packages/core/dist/verification/review-gate.d.ts +22 -0
  374. package/packages/core/dist/verification/review-gate.js +53 -0
  375. package/packages/core/dist/verification/review-gate.js.map +1 -0
  376. package/packages/core/dist/verification/single-task-loop.js +102 -9
  377. package/packages/core/dist/verification/single-task-loop.js.map +1 -1
  378. package/packages/core/dist/verification/test-runtime.d.ts +16 -1
  379. package/packages/core/dist/verification/test-runtime.js +355 -69
  380. package/packages/core/dist/verification/test-runtime.js.map +1 -1
  381. package/packages/core/dist/verification/validation-wave.d.ts +58 -0
  382. package/packages/core/dist/verification/validation-wave.js +428 -0
  383. package/packages/core/dist/verification/validation-wave.js.map +1 -0
  384. package/packages/core/dist/verification/verify-contract.d.ts +2 -0
  385. package/packages/core/dist/verification/verify-contract.js +116 -18
  386. package/packages/core/dist/verification/verify-contract.js.map +1 -1
  387. package/packages/core/dist/verification.d.ts +2 -0
  388. package/packages/core/dist/verification.js +2 -0
  389. package/packages/core/dist/verification.js.map +1 -1
  390. package/packages/core/dist/workflow-gate/evidence-packet.d.ts +24 -0
  391. package/packages/core/dist/workflow-gate/evidence-packet.js +182 -0
  392. package/packages/core/dist/workflow-gate/evidence-packet.js.map +1 -0
  393. package/packages/core/dist/workflow-gate/hard-checks.d.ts +4 -0
  394. package/packages/core/dist/workflow-gate/hard-checks.js +130 -0
  395. package/packages/core/dist/workflow-gate/hard-checks.js.map +1 -0
  396. package/packages/core/dist/workflow-gate/policy.d.ts +4 -0
  397. package/packages/core/dist/workflow-gate/policy.js +146 -0
  398. package/packages/core/dist/workflow-gate/policy.js.map +1 -0
  399. package/packages/core/dist/workflow-gate/types.d.ts +89 -0
  400. package/packages/core/dist/workflow-gate/types.js +2 -0
  401. package/packages/core/dist/workflow-gate/types.js.map +1 -0
  402. package/packages/core/dist/workflow-state/affected-file-conflicts.d.ts +1 -0
  403. package/packages/core/dist/workflow-state/affected-file-conflicts.js +16 -1
  404. package/packages/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  405. package/packages/core/dist/workflow-state/dependencies.d.ts +8 -4
  406. package/packages/core/dist/workflow-state/dependencies.js +25 -11
  407. package/packages/core/dist/workflow-state/dependencies.js.map +1 -1
  408. package/packages/core/dist/workflow-state/latest-eligible-run.d.ts +38 -0
  409. package/packages/core/dist/workflow-state/latest-eligible-run.js +122 -0
  410. package/packages/core/dist/workflow-state/latest-eligible-run.js.map +1 -0
  411. package/packages/core/dist/workflow-state/resolve.d.ts +27 -0
  412. package/packages/core/dist/workflow-state/resolve.js +166 -37
  413. package/packages/core/dist/workflow-state/resolve.js.map +1 -1
  414. package/packages/core/dist/workflow-state.d.ts +1 -0
  415. package/packages/core/dist/workflow-state.js +1 -0
  416. package/packages/core/dist/workflow-state.js.map +1 -1
  417. package/packages/core/package.json +1 -1
@@ -0,0 +1,171 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+
4
+ import { STAGE_TEAM_RUNTIME_CONTRACT_VERSION } from '../contracts.js';
5
+ import { evaluateWorkflowGateHardChecks } from './hard-checks.js';
6
+ import type { WorkflowGateEvidencePacket } from './types.js';
7
+
8
+ const generatedAt = '2026-01-01T00:00:00.000Z';
9
+
10
+ test('workflow gate hard checks block deterministic workflow violations', () => {
11
+ const checks = evaluateWorkflowGateHardChecks(packetInput({
12
+ durableGaps: [{
13
+ gapId: 'gap-001',
14
+ partition: 'feature',
15
+ taskId: 'T1',
16
+ runId: 'run-001',
17
+ stage: 'test',
18
+ gate: 'ship',
19
+ source: 'runtime',
20
+ category: 'validation',
21
+ severity: 'blocking',
22
+ status: 'open',
23
+ message: 'Validation evidence is missing.',
24
+ recommendation: null,
25
+ evidenceRefs: ['artifacts/validation-T1.md'],
26
+ proposalRefs: [],
27
+ sourceRefs: [],
28
+ createdAt: generatedAt,
29
+ updatedAt: generatedAt,
30
+ closedAt: null,
31
+ payload: {}
32
+ }],
33
+ fanInEvidenceSets: [{
34
+ contract: STAGE_TEAM_RUNTIME_CONTRACT_VERSION,
35
+ fanInId: 'fanin-001',
36
+ partition: 'feature',
37
+ runId: 'run-001',
38
+ taskId: 'T1',
39
+ stage: 'test',
40
+ roleResultIds: [],
41
+ durableGapIds: [],
42
+ proposalRefs: [],
43
+ advisorAssessmentIds: [],
44
+ evidenceRefs: ['artifacts/validation-T1.md'],
45
+ canonicalEvidenceRefs: [],
46
+ gateInputOnly: false,
47
+ createdAt: generatedAt,
48
+ payload: {}
49
+ } as unknown as WorkflowGateEvidencePacket['fanInEvidenceSets'][number]],
50
+ requiredArtifactRefs: ['artifacts/required-T1.md']
51
+ }));
52
+
53
+ assert.deepEqual(checks.filter((check) => check.severity === 'blocked').map((check) => check.code).sort(), [
54
+ 'authority_violation',
55
+ 'durable_gap_blocking',
56
+ 'missing_required_artifact'
57
+ ]);
58
+ });
59
+
60
+ test('workflow gate hard checks warn when no latest eligible run exists', () => {
61
+ const checks = evaluateWorkflowGateHardChecks(packetInput({ latestEligibleSelection: null }));
62
+
63
+ assert.equal(checks.some((check) => check.code === 'latest_eligible_missing' && check.severity === 'warning'), true);
64
+ });
65
+
66
+ test('workflow gate hard checks block missing and drifted artifact payloads', () => {
67
+ const checks = evaluateWorkflowGateHardChecks(packetInput({
68
+ artifactPayloadHealth: [
69
+ {
70
+ payloadId: 'payload-missing',
71
+ logicalRef: 'artifacts/validation-T1.md',
72
+ physicalPayloadPath: 'artifacts/validation-T1-run-old.md',
73
+ expectedDigest: 'expected',
74
+ actualDigest: null,
75
+ status: 'missing'
76
+ },
77
+ {
78
+ payloadId: 'payload-drift',
79
+ logicalRef: 'artifacts/review-T1.md',
80
+ physicalPayloadPath: 'artifacts/review-T1-run-old.md',
81
+ expectedDigest: 'expected',
82
+ actualDigest: 'actual',
83
+ status: 'digest_drift'
84
+ }
85
+ ]
86
+ }));
87
+
88
+ assert.deepEqual(checks.filter((check) => check.severity === 'blocked').map((check) => check.code).sort(), ['digest_drift', 'missing_payload']);
89
+ });
90
+
91
+ test('workflow gate hard checks block missing verify contract and runtime health failures', () => {
92
+ const checks = evaluateWorkflowGateHardChecks(packetInput({
93
+ runtimeHealth: { status: 'unavailable', issues: ['schema mismatch'] },
94
+ documents: {
95
+ ...packetInput().documents,
96
+ verifyExists: false,
97
+ verifyBasedOnTasksContractHash: null
98
+ } as WorkflowGateEvidencePacket['documents']
99
+ }));
100
+
101
+ assert.equal(checks.some((check) => check.code === 'schema_health_unavailable' && check.severity === 'blocked'), true);
102
+ assert.equal(checks.some((check) => check.code === 'missing_documents' && check.refs.includes('verify.md')), true);
103
+ });
104
+
105
+ function packetInput(overrides: Partial<Omit<WorkflowGateEvidencePacket, 'hardChecks'>> = {}): Omit<WorkflowGateEvidencePacket, 'hardChecks'> {
106
+ return {
107
+ packetId: 'packet-001',
108
+ generatedAt,
109
+ decisionKind: 'ship',
110
+ partition: 'feature',
111
+ taskId: 'T1',
112
+ runId: 'run-001',
113
+ documents: {
114
+ specExists: true,
115
+ planExists: true,
116
+ tasksExists: true,
117
+ verifyExists: true,
118
+ planStale: false,
119
+ tasksStale: false,
120
+ verifyStale: false,
121
+ specHash: 'spec-doc',
122
+ planHash: 'plan-doc',
123
+ tasksHash: 'tasks-doc',
124
+ verifyHash: 'verify-doc',
125
+ specContractHash: 'spec-contract',
126
+ planContractHash: 'plan-contract',
127
+ tasksContractHash: 'tasks-contract',
128
+ verifyContractHash: 'verify-contract',
129
+ planBasedOnSpecHash: 'spec-doc',
130
+ tasksBasedOnPlanHash: 'plan-doc',
131
+ verifyBasedOnTasksHash: 'tasks-doc',
132
+ planBasedOnSpecContractHash: 'spec-contract',
133
+ tasksBasedOnPlanContractHash: 'plan-contract',
134
+ verifyBasedOnTasksContractHash: 'tasks-contract'
135
+ } as WorkflowGateEvidencePacket['documents'],
136
+ latestEligibleSelection: {
137
+ partition: 'feature',
138
+ taskId: 'T1',
139
+ selected: {
140
+ partition: 'feature',
141
+ gitBranch: 'feature',
142
+ taskId: 'T1',
143
+ runId: 'run-001',
144
+ runStatus: 'completed',
145
+ validationStatus: 'pass',
146
+ syncBackStatus: 'not_created',
147
+ affectedFiles: [],
148
+ updatedAt: generatedAt,
149
+ compatibility: 'compatible',
150
+ eligibleForDefaultApply: true,
151
+ reasons: []
152
+ },
153
+ candidates: [],
154
+ rejected: []
155
+ },
156
+ latestEligibleSelections: [],
157
+ workflowScope: { waveRunId: null, taskIds: ['T1'], runIds: ['run-001'], evidenceRefs: [] },
158
+ runtimeHealth: { status: 'ok', issues: [] },
159
+ durableGaps: [],
160
+ dependencyBlockers: [],
161
+ affectedFileConflicts: [],
162
+ syncBackDecision: null,
163
+ syncBackDecisions: [],
164
+ fanInEvidenceSets: [],
165
+ advisorAssessments: [],
166
+ canonicalEvidenceRefs: [],
167
+ requiredArtifactRefs: [],
168
+ artifactPayloadHealth: [],
169
+ ...overrides
170
+ };
171
+ }
@@ -0,0 +1,143 @@
1
+ import type { WorkflowGateEvidencePacket, WorkflowGateHardCheck } from './types.js';
2
+
3
+ type WorkflowGateHardCheckInput = Omit<WorkflowGateEvidencePacket, 'hardChecks'>;
4
+
5
+ export function evaluateWorkflowGateHardChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
6
+ return [
7
+ ...runtimeHealthChecks(packet),
8
+ ...documentChecks(packet),
9
+ ...latestEligibleChecks(packet),
10
+ ...dependencyChecks(packet),
11
+ ...affectedFileChecks(packet),
12
+ ...durableGapChecks(packet),
13
+ ...artifactChecks(packet),
14
+ ...syncBackChecks(packet),
15
+ ...authorityChecks(packet)
16
+ ];
17
+ }
18
+
19
+ function runtimeHealthChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
20
+ if (packet.runtimeHealth.status === 'ok') {
21
+ return [];
22
+ }
23
+ return [blocked('schema_health_unavailable', packet.partition, `Runtime store health is unavailable: ${packet.runtimeHealth.issues.join('; ') || 'unknown issue'}.`, 'Repair runtime.sqlite schema or rerun after runtime storage is available.', packet.runtimeHealth.issues)];
24
+ }
25
+
26
+ function documentChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
27
+ const checks: WorkflowGateHardCheck[] = [];
28
+ const docs = packet.documents;
29
+ const missing = [
30
+ ['spec.md', docs.specExists],
31
+ ['plan.md', docs.planExists],
32
+ ['tasks.md', docs.tasksExists],
33
+ ['verify.md', docs.verifyExists]
34
+ ].filter(([, exists]) => !exists).map(([name]) => String(name));
35
+ if (missing.length > 0) {
36
+ checks.push(blocked('missing_documents', packet.partition, `Missing workflow documents: ${missing.join(', ')}.`, 'Run the missing SDD document stages before gate evaluation.', missing));
37
+ }
38
+ const stale = [
39
+ ['plan.md', docs.planStale],
40
+ ['tasks.md', docs.tasksStale],
41
+ ['verify.md', docs.verifyStale]
42
+ ].filter(([, value]) => value === true).map(([name]) => String(name));
43
+ if (stale.length > 0) {
44
+ checks.push(blocked('stale_documents', packet.partition, `Stale workflow documents: ${stale.join(', ')}.`, 'Refresh the stale stage contract before continuing.', stale));
45
+ }
46
+ if (docs.verifyExists && !docs.verifyBasedOnTasksContractHash) {
47
+ checks.push(blocked('contract_hash_mismatch', packet.partition, 'verify.md is missing based_on_tasks_contract_hash.', 'Regenerate verify.md from the frozen current tasks contract.', ['verify.md', 'tasks.md']));
48
+ } else if (docs.verifyBasedOnTasksContractHash && docs.tasksContractHash && docs.verifyBasedOnTasksContractHash !== docs.tasksContractHash) {
49
+ checks.push(blocked('contract_hash_mismatch', packet.partition, 'verify.md is bound to an older tasks contract hash.', 'Regenerate verify.md from the frozen current tasks contract.', ['verify.md', 'tasks.md']));
50
+ }
51
+ return checks;
52
+ }
53
+
54
+ function latestEligibleChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
55
+ const scopedSelections = packet.latestEligibleSelections ?? [];
56
+ const selections = scopedSelections.length > 0 ? scopedSelections : (packet.latestEligibleSelection ? [packet.latestEligibleSelection] : []);
57
+ if (selections.length === 0) {
58
+ return [warning('latest_eligible_missing', packet.partition, 'No latest eligible selection is available.', 'Create a run or inspect task evidence before applying gate decisions.', [])];
59
+ }
60
+ return selections.flatMap((selection) => {
61
+ if (!selection.selected && selection.candidates.length > 0) {
62
+ return [blocked('run_rejected', packet.partition, `No default-eligible run for ${selection.taskId}; rejected candidates=${selection.rejected.length}.`, 'Inspect rejected latest-eligible candidates and resolve their reasons.', selection.rejected.map((candidate) => candidate.runId))];
63
+ }
64
+ if (!selection.selected) {
65
+ return [warning('latest_eligible_missing', packet.partition, `No run candidates found for ${selection.taskId}.`, 'Run implementation or validation before expecting gate PASS.', [])];
66
+ }
67
+ const selected = selection.selected;
68
+ if (selected.runStatus === 'blocked' || selected.runStatus === 'failed' || selected.runStatus === 'archived') {
69
+ return [blocked('blocked_failed_or_archived_run', packet.partition, `Selected run ${selected.runId} is ${selected.runStatus}.`, 'Use a non-blocked completed run before continuing.', [selected.runId])];
70
+ }
71
+ if (!selected.eligibleForDefaultApply || selected.compatibility === 'strict_stale' || selected.compatibility === 'incompatible') {
72
+ return [blocked('run_rejected', packet.partition, `Selected run ${selected.runId} is not eligible: ${selected.reasons.join('; ') || selected.compatibility}.`, 'Resolve run eligibility before continuing.', [selected.runId])];
73
+ }
74
+ if (selected.validationStatus === 'fail' || selected.validationStatus === 'blocked') {
75
+ return [blocked('validation_failure', packet.partition, `Selected run validation is ${selected.validationStatus}.`, 'Rerun validation and collect passing evidence.', [selected.runId])];
76
+ }
77
+ return [];
78
+ });
79
+ }
80
+
81
+ function dependencyChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
82
+ return packet.dependencyBlockers.map((blocker) => blocked('dependency_blocker', packet.partition, blocker.reason, `Inspect dependency ${blocker.dependencyId} before continuing.`, [blocker.taskId, blocker.dependencyId]));
83
+ }
84
+
85
+ function affectedFileChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
86
+ return packet.affectedFileConflicts.map((conflict) => blocked('affected_file_conflict', packet.partition, `Affected file ${conflict.file} is active in run ${conflict.runId}.`, 'Resolve active run conflict before applying changes.', [conflict.file, conflict.runId]));
87
+ }
88
+
89
+ function durableGapChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
90
+ return packet.durableGaps
91
+ .filter((gap) => gap.status === 'open' || gap.status === 'acknowledged')
92
+ .filter((gap) => gap.severity === 'blocking')
93
+ .map((gap) => blocked('durable_gap_blocking', packet.partition, gap.message, gap.recommendation ?? 'Resolve the blocking durable gap before continuing.', [gap.gapId, ...gap.evidenceRefs]));
94
+ }
95
+
96
+ function artifactChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
97
+ const available = new Set([...packet.canonicalEvidenceRefs, ...packet.fanInEvidenceSets.flatMap((set) => [...set.canonicalEvidenceRefs, ...set.evidenceRefs])]);
98
+ const checks = packet.requiredArtifactRefs
99
+ .filter((ref) => !available.has(ref))
100
+ .map((ref) => blocked('missing_required_artifact', packet.partition, `Required artifact ${ref} is missing from gate evidence.`, 'Collect required artifacts before gate PASS.', [ref]));
101
+ for (const payload of packet.artifactPayloadHealth) {
102
+ if (payload.status === 'missing') {
103
+ checks.push(blocked('missing_payload', packet.partition, `Artifact payload ${payload.logicalRef} is missing at ${payload.physicalPayloadPath}.`, 'Restore the immutable payload or regenerate current evidence before gate PASS.', [payload.payloadId, payload.logicalRef, payload.physicalPayloadPath]));
104
+ } else if (payload.status === 'digest_drift') {
105
+ checks.push(blocked('digest_drift', packet.partition, `Artifact payload ${payload.logicalRef} digest drifted: expected ${payload.expectedDigest} actual ${payload.actualDigest}.`, 'Treat the payload as tampered or stale; regenerate accepted evidence before gate PASS.', [payload.payloadId, payload.logicalRef, payload.physicalPayloadPath]));
106
+ }
107
+ }
108
+ return checks;
109
+ }
110
+
111
+ function syncBackChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
112
+ const decisions = packet.syncBackDecisions.length > 0 ? packet.syncBackDecisions : (packet.syncBackDecision ? [packet.syncBackDecision] : []);
113
+ return decisions
114
+ .filter((decision) => decision.status === 'blocked' || decision.status === 'divergent')
115
+ .map((decision) => blocked('sync_back_divergence', packet.partition, `Sync-back decision ${decision.decisionId} is ${decision.status}.`, 'Inspect sync-back decision divergence before continuing.', [decision.decisionId]));
116
+ }
117
+
118
+ function authorityChecks(packet: WorkflowGateHardCheckInput): WorkflowGateHardCheck[] {
119
+ const checks: WorkflowGateHardCheck[] = [];
120
+ for (const fanIn of packet.fanInEvidenceSets) {
121
+ if (fanIn.gateInputOnly !== true) {
122
+ checks.push(blocked('authority_violation', packet.partition, `Fan-in evidence set ${fanIn.fanInId} is not gate-input-only.`, 'Regenerate fan-in evidence as non-final gate input.', [fanIn.fanInId]));
123
+ }
124
+ }
125
+ for (const advisor of packet.advisorAssessments) {
126
+ if (advisor.advisoryOnly !== true) {
127
+ checks.push(blocked('authority_violation', packet.partition, `Advisor assessment ${advisor.assessmentId} is not advisory-only.`, 'Discard or regenerate advisor assessment as advisory-only.', [advisor.assessmentId]));
128
+ }
129
+ }
130
+ return checks;
131
+ }
132
+
133
+ function blocked(code: WorkflowGateHardCheck['code'], scope: string, message: string, recovery: string, refs: string[]): WorkflowGateHardCheck {
134
+ return { code, severity: 'blocked', scope, message, recovery, refs: sortedUnique(refs) };
135
+ }
136
+
137
+ function warning(code: WorkflowGateHardCheck['code'], scope: string, message: string, recovery: string, refs: string[]): WorkflowGateHardCheck {
138
+ return { code, severity: 'warning', scope, message, recovery, refs: sortedUnique(refs) };
139
+ }
140
+
141
+ function sortedUnique(values: string[]): string[] {
142
+ return [...new Set(values.filter(Boolean))].sort();
143
+ }
@@ -0,0 +1,137 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+
4
+ import { WORKFLOW_GATE_RUNTIME_CONTRACT_VERSION, STAGE_TEAM_RUNTIME_CONTRACT_VERSION } from '../contracts.js';
5
+ import { synthesizeWorkflowGateDecision } from './policy.js';
6
+ import type { WorkflowGateEvidencePacket } from './types.js';
7
+
8
+ const generatedAt = '2026-01-01T00:00:00.000Z';
9
+
10
+ test('workflow gate policy keeps hard blocks monotonic over advisor concerns', () => {
11
+ const decision = synthesizeWorkflowGateDecision(packet({
12
+ hardChecks: [{
13
+ code: 'validation_failure',
14
+ severity: 'blocked',
15
+ scope: 'feature',
16
+ message: 'Selected run validation failed.',
17
+ recovery: 'Rerun validation.',
18
+ refs: ['run-001']
19
+ }],
20
+ advisorAssessments: [advisor('none')]
21
+ }));
22
+
23
+ assert.equal(decision.status, 'BLOCKED');
24
+ assert.equal(decision.decidedBy, 'runtime_policy');
25
+ assert.deepEqual(decision.forbiddenNextActions, ['ship', 'sync-back-apply', 'mark-task-complete', 'stage-pass']);
26
+ });
27
+
28
+ test('workflow gate policy requires a human for high-concern ship advisors', () => {
29
+ const decision = synthesizeWorkflowGateDecision(packet({ advisorAssessments: [advisor('high')] }));
30
+
31
+ assert.equal(decision.status, 'HUMAN_REQUIRED');
32
+ assert.equal(decision.humanRequired, true);
33
+ assert.deepEqual(decision.allowedNextActions, ['create-decision-card', 'inspect-evidence']);
34
+ assert.equal(decision.forbiddenNextActions.includes('satisfy-with-subagent-output'), true);
35
+ });
36
+
37
+ test('workflow gate policy treats advisor-only stage transitions without canonical evidence as advisory only', () => {
38
+ const decision = synthesizeWorkflowGateDecision(packet({
39
+ decisionKind: 'stage_transition',
40
+ advisorAssessments: [advisor('low')],
41
+ canonicalEvidenceRefs: []
42
+ }));
43
+
44
+ assert.equal(decision.status, 'ADVISORY_ONLY');
45
+ assert.deepEqual(decision.allowedNextActions, ['inspect-advisor-assessments']);
46
+ });
47
+
48
+ test('workflow gate policy escalates invalid advisors and warns on low confidence', () => {
49
+ const invalid = synthesizeWorkflowGateDecision(packet({ advisorAssessments: [advisor('low', { validity: 'invalid' })] }));
50
+ const lowConfidence = synthesizeWorkflowGateDecision(packet({ advisorAssessments: [advisor('low', { confidence: 'low' })] }));
51
+
52
+ assert.equal(invalid.status, 'HUMAN_REQUIRED');
53
+ assert.equal(invalid.advisorSummary.invalidCount, 1);
54
+ assert.equal(lowConfidence.status, 'WARN');
55
+ assert.equal(lowConfidence.advisorSummary.lowConfidenceCount, 1);
56
+ assert.deepEqual(lowConfidence.allowedNextActions, ['inspect-evidence']);
57
+ assert.deepEqual(lowConfidence.forbiddenNextActions, ['ship', 'sync-back-apply', 'mark-task-complete', 'stage-pass']);
58
+ });
59
+
60
+ test('workflow gate policy hashes stable gate inputs and carries evidence refs', () => {
61
+ const decision = synthesizeWorkflowGateDecision(packet({
62
+ canonicalEvidenceRefs: ['artifacts/validation-T1.md'],
63
+ fanInEvidenceSets: [{
64
+ contract: STAGE_TEAM_RUNTIME_CONTRACT_VERSION,
65
+ fanInId: 'fanin-001',
66
+ partition: 'feature',
67
+ runId: 'run-001',
68
+ taskId: 'T1',
69
+ stage: 'test',
70
+ roleResultIds: [],
71
+ durableGapIds: [],
72
+ proposalRefs: [],
73
+ advisorAssessmentIds: [],
74
+ evidenceRefs: ['artifacts/review-T1.md'],
75
+ canonicalEvidenceRefs: ['artifacts/validation-T1.md'],
76
+ gateInputOnly: true,
77
+ createdAt: generatedAt,
78
+ payload: {}
79
+ }]
80
+ }));
81
+
82
+ assert.match(decision.decisionId, /^gate-[a-f0-9]{16}$/);
83
+ assert.equal(decision.status, 'PASS');
84
+ assert.deepEqual(decision.evidenceRefs, ['artifacts/review-T1.md', 'artifacts/validation-T1.md']);
85
+ assert.deepEqual(decision.payload, { contract: WORKFLOW_GATE_RUNTIME_CONTRACT_VERSION, packetId: 'packet-001', workflowScope: { waveRunId: null, taskIds: ['T1'], runIds: ['run-001'], evidenceRefs: [] } });
86
+ });
87
+
88
+ function packet(overrides: Partial<WorkflowGateEvidencePacket> = {}): WorkflowGateEvidencePacket {
89
+ return {
90
+ packetId: 'packet-001',
91
+ generatedAt,
92
+ decisionKind: 'ship',
93
+ partition: 'feature',
94
+ taskId: 'T1',
95
+ runId: 'run-001',
96
+ documents: {} as WorkflowGateEvidencePacket['documents'],
97
+ latestEligibleSelection: null,
98
+ latestEligibleSelections: [],
99
+ workflowScope: { waveRunId: null, taskIds: ['T1'], runIds: ['run-001'], evidenceRefs: [] },
100
+ runtimeHealth: { status: 'ok', issues: [] },
101
+ durableGaps: [],
102
+ dependencyBlockers: [],
103
+ affectedFileConflicts: [],
104
+ syncBackDecision: null,
105
+ syncBackDecisions: [],
106
+ fanInEvidenceSets: [],
107
+ advisorAssessments: [],
108
+ canonicalEvidenceRefs: [],
109
+ requiredArtifactRefs: [],
110
+ artifactPayloadHealth: [],
111
+ hardChecks: [],
112
+ ...overrides
113
+ };
114
+ }
115
+
116
+ function advisor(concern: WorkflowGateEvidencePacket['advisorAssessments'][number]['concern'], overrides: Partial<WorkflowGateEvidencePacket['advisorAssessments'][number]> = {}): WorkflowGateEvidencePacket['advisorAssessments'][number] {
117
+ return {
118
+ contract: STAGE_TEAM_RUNTIME_CONTRACT_VERSION,
119
+ assessmentId: `advisor-${concern}`,
120
+ sessionId: null,
121
+ partition: 'feature',
122
+ runId: 'run-001',
123
+ taskId: 'T1',
124
+ kind: 'evidence_sufficiency',
125
+ concern,
126
+ validity: 'valid',
127
+ confidence: 'high',
128
+ advisoryOnly: true,
129
+ summary: `${concern} concern`,
130
+ evidenceRefs: [],
131
+ durableGapIds: [],
132
+ proposalRefs: [],
133
+ createdAt: generatedAt,
134
+ ...overrides,
135
+ payload: {}
136
+ };
137
+ }
@@ -0,0 +1,155 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { WORKFLOW_GATE_RUNTIME_CONTRACT_VERSION } from '../contracts.js';
3
+ import type { WorkflowGateAdvisorSummary, WorkflowGateDecision, WorkflowGateEvidencePacket, WorkflowGateHardCheck, WorkflowGateStatus } from './types.js';
4
+
5
+ export function synthesizeWorkflowGateDecision(packet: WorkflowGateEvidencePacket): WorkflowGateDecision {
6
+ const hardBlocks = packet.hardChecks.filter((check) => check.severity === 'blocked');
7
+ const warnings = packet.hardChecks.filter((check) => check.severity === 'warning');
8
+ const advisorSummary = summarizeAdvisors(packet);
9
+ const status = decideStatus(hardBlocks, warnings, advisorSummary, packet);
10
+ const humanRequired = status === 'HUMAN_REQUIRED';
11
+ const allowedNextActions = allowedActions(status, packet);
12
+ const forbiddenNextActions = forbiddenActions(status, packet);
13
+ return {
14
+ decisionId: `gate-${inputHash(packet).slice(0, 16)}`,
15
+ inputHash: inputHash(packet),
16
+ generatedAt: new Date().toISOString(),
17
+ partition: packet.partition,
18
+ taskId: packet.taskId,
19
+ runId: packet.runId,
20
+ decisionKind: packet.decisionKind,
21
+ status,
22
+ decidedBy: 'runtime_policy',
23
+ hardBlocks,
24
+ warnings,
25
+ advisorSummary,
26
+ allowedNextActions,
27
+ forbiddenNextActions,
28
+ humanRequired,
29
+ reasons: decisionReasons(status, hardBlocks, warnings, advisorSummary),
30
+ evidenceRefs: sortedUnique([...packet.canonicalEvidenceRefs, ...packet.fanInEvidenceSets.flatMap((set) => [...set.evidenceRefs, ...set.canonicalEvidenceRefs])]),
31
+ payload: {
32
+ contract: WORKFLOW_GATE_RUNTIME_CONTRACT_VERSION,
33
+ packetId: packet.packetId,
34
+ workflowScope: packet.workflowScope
35
+ }
36
+ };
37
+ }
38
+
39
+ export function summarizeAdvisors(packet: WorkflowGateEvidencePacket): WorkflowGateAdvisorSummary {
40
+ const highConcernCount = packet.advisorAssessments.filter((assessment) => assessment.concern === 'high').length;
41
+ const mediumConcernCount = packet.advisorAssessments.filter((assessment) => assessment.concern === 'medium').length;
42
+ const invalidCount = packet.advisorAssessments.filter((assessment) => assessment.advisoryOnly !== true || assessment.validity === 'invalid').length;
43
+ const lowConfidenceCount = packet.advisorAssessments.filter((assessment) => assessment.confidence === 'low').length;
44
+ return {
45
+ status: invalidCount > 0 ? 'invalid' : highConcernCount > 0 ? 'high_concern' : mediumConcernCount > 0 || lowConfidenceCount > 0 ? 'medium_concern' : packet.advisorAssessments.length > 0 ? 'low_concern' : 'none',
46
+ highConcernCount,
47
+ mediumConcernCount,
48
+ invalidCount,
49
+ lowConfidenceCount,
50
+ summaries: packet.advisorAssessments.map((assessment) => assessment.summary).filter(Boolean).sort()
51
+ };
52
+ }
53
+
54
+ export function inputHash(packet: WorkflowGateEvidencePacket): string {
55
+ return createHash('sha256').update(stableJson({
56
+ decisionKind: packet.decisionKind,
57
+ partition: packet.partition,
58
+ taskId: packet.taskId,
59
+ runId: packet.runId,
60
+ documents: packet.documents,
61
+ selection: packet.latestEligibleSelection,
62
+ selections: packet.latestEligibleSelections,
63
+ workflowScope: packet.workflowScope,
64
+ runtimeHealth: packet.runtimeHealth,
65
+ durableGaps: packet.durableGaps,
66
+ dependencyBlockers: packet.dependencyBlockers,
67
+ affectedFileConflicts: packet.affectedFileConflicts,
68
+ syncBackDecision: packet.syncBackDecision,
69
+ syncBackDecisions: packet.syncBackDecisions,
70
+ fanInEvidenceSets: packet.fanInEvidenceSets,
71
+ advisorAssessments: packet.advisorAssessments,
72
+ canonicalEvidenceRefs: packet.canonicalEvidenceRefs,
73
+ requiredArtifactRefs: packet.requiredArtifactRefs,
74
+ artifactPayloadHealth: packet.artifactPayloadHealth,
75
+ hardChecks: packet.hardChecks
76
+ }), 'utf8').digest('hex');
77
+ }
78
+
79
+ function decideStatus(hardBlocks: WorkflowGateHardCheck[], warnings: WorkflowGateHardCheck[], advisorSummary: WorkflowGateAdvisorSummary, packet: WorkflowGateEvidencePacket): WorkflowGateStatus {
80
+ if (hardBlocks.length > 0) {
81
+ return 'BLOCKED';
82
+ }
83
+ if (advisorSummary.status === 'invalid') {
84
+ return 'HUMAN_REQUIRED';
85
+ }
86
+ if (advisorSummary.status === 'high_concern') {
87
+ return 'HUMAN_REQUIRED';
88
+ }
89
+ if (warnings.length > 0 || advisorSummary.status === 'medium_concern') {
90
+ return 'WARN';
91
+ }
92
+ if (packet.decisionKind === 'stage_transition' && packet.advisorAssessments.length > 0 && packet.canonicalEvidenceRefs.length === 0) {
93
+ return 'ADVISORY_ONLY';
94
+ }
95
+ return 'PASS';
96
+ }
97
+
98
+ function allowedActions(status: WorkflowGateStatus, packet: WorkflowGateEvidencePacket): string[] {
99
+ if (status === 'PASS') {
100
+ return packet.decisionKind === 'ship' ? ['ship'] : ['continue'];
101
+ }
102
+ if (status === 'WARN') {
103
+ return ['inspect-evidence'];
104
+ }
105
+ if (status === 'HUMAN_REQUIRED') {
106
+ return ['create-decision-card', 'inspect-evidence'];
107
+ }
108
+ if (status === 'ADVISORY_ONLY') {
109
+ return ['inspect-advisor-assessments'];
110
+ }
111
+ return ['inspect-blockers', 'recover'];
112
+ }
113
+
114
+ function forbiddenActions(status: WorkflowGateStatus, packet: WorkflowGateEvidencePacket): string[] {
115
+ if (status === 'BLOCKED') {
116
+ return ['ship', 'sync-back-apply', 'mark-task-complete', 'stage-pass'];
117
+ }
118
+ if (status === 'HUMAN_REQUIRED') {
119
+ return ['satisfy-with-role-result', 'satisfy-with-subagent-output'];
120
+ }
121
+ if (status === 'ADVISORY_ONLY') {
122
+ return ['treat-advisor-as-pass'];
123
+ }
124
+ return status === 'WARN' ? ['ship', 'sync-back-apply', 'mark-task-complete', 'stage-pass'] : packet.decisionKind === 'ship' ? [] : ['skip-evidence-recording'];
125
+ }
126
+
127
+ function decisionReasons(status: WorkflowGateStatus, hardBlocks: WorkflowGateHardCheck[], warnings: WorkflowGateHardCheck[], advisorSummary: WorkflowGateAdvisorSummary): string[] {
128
+ if (hardBlocks.length > 0) {
129
+ return hardBlocks.map((check) => `${check.code}: ${check.message}`);
130
+ }
131
+ if (status === 'HUMAN_REQUIRED') {
132
+ return [`advisor=${advisorSummary.status}; human decision required because role/subagent outputs cannot satisfy this gate.`];
133
+ }
134
+ if (warnings.length > 0) {
135
+ return warnings.map((check) => `${check.code}: ${check.message}`);
136
+ }
137
+ if (advisorSummary.status === 'medium_concern' || advisorSummary.status === 'high_concern') {
138
+ return [`advisor=${advisorSummary.status}`];
139
+ }
140
+ return [`runtime_policy produced ${status}`];
141
+ }
142
+
143
+ function sortedUnique(values: string[]): string[] {
144
+ return [...new Set(values.filter(Boolean))].sort();
145
+ }
146
+
147
+ function stableJson(value: unknown): string {
148
+ if (Array.isArray(value)) {
149
+ return `[${value.map(stableJson).join(',')}]`;
150
+ }
151
+ if (value && typeof value === 'object') {
152
+ return `{${Object.entries(value as Record<string, unknown>).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stableJson(item)}`).join(',')}}`;
153
+ }
154
+ return JSON.stringify(value);
155
+ }