sdd-agent-platform 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (826) hide show
  1. package/README.md +33 -39
  2. package/node_modules/@sdd-agent-platform/core/dist/ai-tools.js +56 -73
  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 +9 -64
  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 +1 -0
  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 +17 -26
  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 +8 -7
  11. package/node_modules/@sdd-agent-platform/core/dist/config/init-project.js +8 -12
  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 +1 -1
  14. package/node_modules/@sdd-agent-platform/core/dist/config/project-config.js +1 -1
  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 +3 -4
  17. package/node_modules/@sdd-agent-platform/core/dist/config/starter-documents.js +377 -411
  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 +7 -13
  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 +8 -26
  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 +6 -1
  28. package/node_modules/@sdd-agent-platform/core/dist/contracts.js +5 -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 +0 -3
  31. package/node_modules/@sdd-agent-platform/core/dist/delegation/validation.d.ts +0 -3
  32. package/node_modules/@sdd-agent-platform/core/dist/delegation/validation.js +4 -7
  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 +3 -13
  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 +1 -0
  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 +24 -0
  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 +43 -180
  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.d.ts +1 -1
  49. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js +7 -14
  50. package/node_modules/@sdd-agent-platform/core/dist/evidence/lookup.js.map +1 -1
  51. package/node_modules/@sdd-agent-platform/core/dist/evidence-runtime/coordination.js +110 -0
  52. package/node_modules/@sdd-agent-platform/core/dist/evidence-runtime/coordination.js.map +1 -0
  53. package/node_modules/@sdd-agent-platform/core/dist/execution/background-executor.js +4 -4
  54. package/node_modules/@sdd-agent-platform/core/dist/execution/background-executor.js.map +1 -1
  55. package/node_modules/@sdd-agent-platform/core/dist/execution/foreground-subagents.js +3 -3
  56. package/node_modules/@sdd-agent-platform/core/dist/execution/foreground-subagents.js.map +1 -1
  57. package/node_modules/@sdd-agent-platform/core/dist/execution/host-invocation.js +85 -86
  58. package/node_modules/@sdd-agent-platform/core/dist/execution/host-invocation.js.map +1 -1
  59. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js +2 -3
  60. package/node_modules/@sdd-agent-platform/core/dist/execution/resident-worker.js.map +1 -1
  61. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js +2 -2
  62. package/node_modules/@sdd-agent-platform/core/dist/execution/stage-team-runtime.js.map +1 -1
  63. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.d.ts +1 -1
  64. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.js +1 -1
  65. package/node_modules/@sdd-agent-platform/core/dist/governance/policy.js.map +1 -1
  66. package/node_modules/@sdd-agent-platform/core/dist/instructions.d.ts +1 -1
  67. package/node_modules/@sdd-agent-platform/core/dist/instructions.js +31 -67
  68. package/node_modules/@sdd-agent-platform/core/dist/instructions.js.map +1 -1
  69. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/decision-gate.js +1 -1
  70. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/decision-gate.js.map +1 -1
  71. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.d.ts +0 -1
  72. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js +59 -85
  73. package/node_modules/@sdd-agent-platform/core/dist/lifecycle/ship.js.map +1 -1
  74. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/contracts.d.ts +159 -0
  75. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/contracts.js +7 -0
  76. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/contracts.js.map +1 -0
  77. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/kernel.d.ts +16 -0
  78. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/kernel.js +461 -0
  79. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph/kernel.js.map +1 -0
  80. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph.d.ts +2 -0
  81. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph.js +3 -0
  82. package/node_modules/@sdd-agent-platform/core/dist/lifecycle-graph.js.map +1 -0
  83. package/node_modules/@sdd-agent-platform/core/dist/orchestration/contracts.d.ts +1 -1
  84. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.d.ts +2 -12
  85. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.js +32 -80
  86. package/node_modules/@sdd-agent-platform/core/dist/orchestration/runtime.js.map +1 -1
  87. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.d.ts +2 -5
  88. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js +27 -69
  89. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-capability-catalog.js.map +1 -1
  90. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js +118 -34
  91. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-registry.js.map +1 -1
  92. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js +1 -1
  93. package/node_modules/@sdd-agent-platform/core/dist/registries/agent-runtime-static.js.map +1 -1
  94. package/node_modules/@sdd-agent-platform/core/dist/registries/capability-sources.js +1 -1
  95. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.d.ts +1 -1
  96. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.js +8 -15
  97. package/node_modules/@sdd-agent-platform/core/dist/registries/command-team-runtime.js.map +1 -1
  98. package/node_modules/@sdd-agent-platform/core/dist/registries/eval-learning-context.js +4 -4
  99. package/node_modules/@sdd-agent-platform/core/dist/registries/eval-learning-context.js.map +1 -1
  100. package/node_modules/@sdd-agent-platform/core/dist/registries/plan-scout-domains.d.ts +13 -0
  101. package/node_modules/@sdd-agent-platform/core/dist/registries/plan-scout-domains.js +76 -0
  102. package/node_modules/@sdd-agent-platform/core/dist/registries/plan-scout-domains.js.map +1 -0
  103. package/node_modules/@sdd-agent-platform/core/dist/registries/query-status.js +2 -2
  104. package/node_modules/@sdd-agent-platform/core/dist/registries/query-status.js.map +1 -1
  105. package/node_modules/@sdd-agent-platform/core/dist/registries/skill-capabilities.js +7 -7
  106. package/node_modules/@sdd-agent-platform/core/dist/registries/skill-capabilities.js.map +1 -1
  107. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-capabilities.js +4 -4
  108. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-capabilities.js.map +1 -1
  109. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-plugins.js +2 -2
  110. package/node_modules/@sdd-agent-platform/core/dist/registries/tool-plugins.js.map +1 -1
  111. package/node_modules/@sdd-agent-platform/core/dist/registries/worker-adapters.js +11 -11
  112. package/node_modules/@sdd-agent-platform/core/dist/registries/worker-adapters.js.map +1 -1
  113. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.d.ts +1 -1
  114. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js +21 -21
  115. package/node_modules/@sdd-agent-platform/core/dist/registries/workflow-gates.js.map +1 -1
  116. package/node_modules/@sdd-agent-platform/core/dist/risk/consumer-diagnostics.js +2 -1
  117. package/node_modules/@sdd-agent-platform/core/dist/risk/consumer-diagnostics.js.map +1 -1
  118. package/node_modules/@sdd-agent-platform/core/dist/risk/kernel.js +6 -6
  119. package/node_modules/@sdd-agent-platform/core/dist/risk/kernel.js.map +1 -1
  120. package/node_modules/@sdd-agent-platform/core/dist/risk/legacy-adapters.js +11 -23
  121. package/node_modules/@sdd-agent-platform/core/dist/risk/legacy-adapters.js.map +1 -1
  122. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.d.ts +2 -2
  123. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.js +18 -20
  124. package/node_modules/@sdd-agent-platform/core/dist/risk/workflow-gates.js.map +1 -1
  125. package/node_modules/@sdd-agent-platform/core/dist/router/agent-runtime.d.ts +0 -2
  126. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js +1 -1
  127. package/node_modules/@sdd-agent-platform/core/dist/router/route-projection.js.map +1 -1
  128. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js +16 -48
  129. package/node_modules/@sdd-agent-platform/core/dist/router/routing.js.map +1 -1
  130. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-import.js +11 -1
  131. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-import.js.map +1 -1
  132. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js +2 -2
  133. package/node_modules/@sdd-agent-platform/core/dist/router/runtime-validation.js.map +1 -1
  134. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.d.ts +2 -2
  135. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.js +20 -28
  136. package/node_modules/@sdd-agent-platform/core/dist/router/stage-route-binding.js.map +1 -1
  137. package/node_modules/@sdd-agent-platform/core/dist/router.d.ts +0 -1
  138. package/node_modules/@sdd-agent-platform/core/dist/router.js +0 -1
  139. package/node_modules/@sdd-agent-platform/core/dist/router.js.map +1 -1
  140. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.d.ts +6 -6
  141. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js +13 -124
  142. package/node_modules/@sdd-agent-platform/core/dist/run-state/artifacts.js.map +1 -1
  143. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.d.ts +2 -0
  144. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js +5 -7
  145. package/node_modules/@sdd-agent-platform/core/dist/run-state/inspect-run.js.map +1 -1
  146. package/node_modules/@sdd-agent-platform/core/dist/run-state/model.d.ts +28 -28
  147. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.d.ts +2 -0
  148. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.js +3 -1
  149. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-index.js.map +1 -1
  150. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js +26 -36
  151. package/node_modules/@sdd-agent-platform/core/dist/run-state/run-state.js.map +1 -1
  152. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.d.ts +0 -4
  153. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js +5 -51
  154. package/node_modules/@sdd-agent-platform/core/dist/run-state/task-evidence.js.map +1 -1
  155. package/node_modules/@sdd-agent-platform/core/dist/run-state.d.ts +0 -1
  156. package/node_modules/@sdd-agent-platform/core/dist/run-state.js +0 -1
  157. package/node_modules/@sdd-agent-platform/core/dist/run-state.js.map +1 -1
  158. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/build.js +1 -1
  159. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/build.js.map +1 -1
  160. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/findings.js +5 -5
  161. package/node_modules/@sdd-agent-platform/core/dist/runtime-analysis/findings.js.map +1 -1
  162. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js +1 -1
  163. package/node_modules/@sdd-agent-platform/core/dist/runtime-paths.js.map +1 -1
  164. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.d.ts +2 -2
  165. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.js +11 -0
  166. package/node_modules/@sdd-agent-platform/core/dist/runtime-projection-p0.js.map +1 -1
  167. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/artifact-depth.d.ts +14 -0
  168. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/artifact-depth.js +179 -0
  169. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/artifact-depth.js.map +1 -0
  170. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.d.ts +0 -2
  171. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js +10 -97
  172. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/document-hashes.js.map +1 -1
  173. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.d.ts +1 -1
  174. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js +6 -8
  175. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/run-binding.js.map +1 -1
  176. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.d.ts +5 -2
  177. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js +85 -68
  178. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-parser.js.map +1 -1
  179. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-rendering.js +2 -2
  180. package/node_modules/@sdd-agent-platform/core/dist/sdd-docs/task-rendering.js.map +1 -1
  181. package/node_modules/@sdd-agent-platform/core/dist/spec-entry.js +40 -0
  182. package/node_modules/@sdd-agent-platform/core/dist/spec-entry.js.map +1 -0
  183. package/node_modules/@sdd-agent-platform/core/dist/spec-manager-contracts.d.ts +12 -0
  184. package/node_modules/@sdd-agent-platform/core/dist/spec-manager-contracts.js +2 -0
  185. package/node_modules/@sdd-agent-platform/core/dist/spec-manager-contracts.js.map +1 -0
  186. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.d.ts +2 -2
  187. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.js +19 -26
  188. package/node_modules/@sdd-agent-platform/core/dist/stage-artifacts.js.map +1 -1
  189. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.d.ts +1 -1
  190. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.js +3 -6
  191. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration-contracts.js.map +1 -1
  192. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.d.ts +111 -263
  193. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.js +1272 -1124
  194. package/node_modules/@sdd-agent-platform/core/dist/stage-collaboration.js.map +1 -1
  195. package/node_modules/@sdd-agent-platform/core/dist/stage-runtime/runtime.js +5 -5
  196. package/node_modules/@sdd-agent-platform/core/dist/stage-runtime/runtime.js.map +1 -1
  197. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.d.ts +1 -44
  198. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js +47 -170
  199. package/node_modules/@sdd-agent-platform/core/dist/status/project-status.js.map +1 -1
  200. package/node_modules/@sdd-agent-platform/core/dist/storage/runtime-store.js +73 -73
  201. package/node_modules/@sdd-agent-platform/core/dist/subagents/contracts.d.ts +1 -1
  202. package/node_modules/@sdd-agent-platform/core/dist/subagents/runtime.js +7 -7
  203. package/node_modules/@sdd-agent-platform/core/dist/subagents/runtime.js.map +1 -1
  204. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.d.ts +1 -0
  205. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js +2 -0
  206. package/node_modules/@sdd-agent-platform/core/dist/sync-back/apply.js.map +1 -0
  207. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.d.ts +1 -0
  208. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js +2 -0
  209. package/node_modules/@sdd-agent-platform/core/dist/sync-back/inspect.js.map +1 -0
  210. package/node_modules/@sdd-agent-platform/core/dist/sync-back.d.ts +1 -0
  211. package/node_modules/@sdd-agent-platform/core/dist/sync-back.js +2 -0
  212. package/node_modules/@sdd-agent-platform/core/dist/sync-back.js.map +1 -0
  213. package/node_modules/@sdd-agent-platform/core/dist/task-execution-contract.d.ts +167 -0
  214. package/node_modules/@sdd-agent-platform/core/dist/task-execution-contract.js +377 -0
  215. package/node_modules/@sdd-agent-platform/core/dist/task-execution-contract.js.map +1 -0
  216. package/node_modules/@sdd-agent-platform/core/dist/test-support/fixtures.js +329 -314
  217. package/node_modules/@sdd-agent-platform/core/dist/test-support/fixtures.js.map +1 -1
  218. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.d.ts +1 -0
  219. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js +53 -7
  220. package/node_modules/@sdd-agent-platform/core/dist/test-support/run-state.js.map +1 -1
  221. package/node_modules/@sdd-agent-platform/core/dist/truth-reconciliation.js +9 -12
  222. package/node_modules/@sdd-agent-platform/core/dist/truth-reconciliation.js.map +1 -1
  223. package/node_modules/@sdd-agent-platform/core/dist/tsconfig.tsbuildinfo +1 -1
  224. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.d.ts +0 -48
  225. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js +1 -520
  226. package/node_modules/@sdd-agent-platform/core/dist/verification/goal-verify.js.map +1 -1
  227. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.d.ts +5 -5
  228. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js +14 -14
  229. package/node_modules/@sdd-agent-platform/core/dist/verification/rendering.js.map +1 -1
  230. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.d.ts +1 -0
  231. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js +111 -159
  232. package/node_modules/@sdd-agent-platform/core/dist/verification/single-task-loop.js.map +1 -1
  233. package/node_modules/@sdd-agent-platform/core/dist/verification/task-evidence-judgment.d.ts +49 -0
  234. package/node_modules/@sdd-agent-platform/core/dist/verification/task-evidence-judgment.js +521 -0
  235. package/node_modules/@sdd-agent-platform/core/dist/verification/task-evidence-judgment.js.map +1 -0
  236. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js +21 -21
  237. package/node_modules/@sdd-agent-platform/core/dist/verification/test-runtime.js.map +1 -1
  238. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.d.ts +0 -18
  239. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js +5 -27
  240. package/node_modules/@sdd-agent-platform/core/dist/verification/validation-wave.js.map +1 -1
  241. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js +45 -45
  242. package/node_modules/@sdd-agent-platform/core/dist/verification/verify-contract.js.map +1 -1
  243. package/node_modules/@sdd-agent-platform/core/dist/verification.d.ts +3 -3
  244. package/node_modules/@sdd-agent-platform/core/dist/verification.js +2 -2
  245. package/node_modules/@sdd-agent-platform/core/dist/verification.js.map +1 -1
  246. package/node_modules/@sdd-agent-platform/core/dist/work-units/contracts.d.ts +1 -1
  247. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js +9 -227
  248. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/evidence-packet.js.map +1 -1
  249. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js +9 -50
  250. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/hard-checks.js.map +1 -1
  251. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js +4 -42
  252. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/policy.js.map +1 -1
  253. package/node_modules/@sdd-agent-platform/core/dist/workflow-gate/types.d.ts +2 -3
  254. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.d.ts +1 -0
  255. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js +2 -1
  256. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  257. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/dependencies.js +1 -1
  258. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.d.ts +1 -0
  259. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js +23 -63
  260. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/latest-eligible-run.js.map +1 -1
  261. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.d.ts +2 -2
  262. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js +43 -65
  263. package/node_modules/@sdd-agent-platform/core/dist/workflow-state/resolve.js.map +1 -1
  264. package/node_modules/@sdd-agent-platform/core/package.json +5 -2
  265. package/node_modules/@sdd-agent-platform/core/src/ai-tools.test.ts +238 -185
  266. package/node_modules/@sdd-agent-platform/core/src/ai-tools.ts +56 -73
  267. package/node_modules/@sdd-agent-platform/core/src/artifacts/ingestion.test.ts +189 -227
  268. package/node_modules/@sdd-agent-platform/core/src/artifacts/ingestion.ts +222 -278
  269. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-evidence.test.ts +28 -28
  270. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-evidence.ts +302 -301
  271. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-result.test.ts +181 -181
  272. package/node_modules/@sdd-agent-platform/core/src/artifacts/sdd-result.ts +231 -240
  273. package/node_modules/@sdd-agent-platform/core/src/artifacts/templates.ts +99 -99
  274. package/node_modules/@sdd-agent-platform/core/src/artifacts.ts +4 -4
  275. package/node_modules/@sdd-agent-platform/core/src/coding-facts/contracts.ts +79 -79
  276. package/node_modules/@sdd-agent-platform/core/src/coding-facts.ts +1 -1
  277. package/node_modules/@sdd-agent-platform/core/src/config/init-project.test.ts +314 -318
  278. package/node_modules/@sdd-agent-platform/core/src/config/init-project.ts +128 -123
  279. package/node_modules/@sdd-agent-platform/core/src/config/project-config.ts +265 -265
  280. package/node_modules/@sdd-agent-platform/core/src/config/project-detection.ts +147 -147
  281. package/node_modules/@sdd-agent-platform/core/src/config/starter-documents.ts +400 -432
  282. package/node_modules/@sdd-agent-platform/core/src/context/budget.ts +30 -30
  283. package/node_modules/@sdd-agent-platform/core/src/context/build-package.ts +305 -311
  284. package/node_modules/@sdd-agent-platform/core/src/context/command-summary.ts +45 -45
  285. package/node_modules/@sdd-agent-platform/core/src/context/context-build.test.ts +188 -189
  286. package/node_modules/@sdd-agent-platform/core/src/context/evidence-summary.ts +144 -163
  287. package/node_modules/@sdd-agent-platform/core/src/context/log-worker.ts +48 -48
  288. package/node_modules/@sdd-agent-platform/core/src/context/source-refs.ts +41 -41
  289. package/node_modules/@sdd-agent-platform/core/src/context-offload/contracts.ts +47 -47
  290. package/node_modules/@sdd-agent-platform/core/src/context-offload/runtime.test.ts +71 -71
  291. package/node_modules/@sdd-agent-platform/core/src/context-offload/runtime.ts +178 -178
  292. package/node_modules/@sdd-agent-platform/core/src/context-offload.ts +2 -2
  293. package/node_modules/@sdd-agent-platform/core/src/context.ts +6 -6
  294. package/node_modules/@sdd-agent-platform/core/src/contracts/issues.ts +13 -13
  295. package/node_modules/@sdd-agent-platform/core/src/contracts.test.ts +9 -9
  296. package/node_modules/@sdd-agent-platform/core/src/contracts.ts +121 -116
  297. package/node_modules/@sdd-agent-platform/core/src/delegation/delegation.test.ts +183 -183
  298. package/node_modules/@sdd-agent-platform/core/src/delegation/model.ts +23 -26
  299. package/node_modules/@sdd-agent-platform/core/src/delegation/queue.ts +58 -58
  300. package/node_modules/@sdd-agent-platform/core/src/delegation/run-state.ts +14 -14
  301. package/node_modules/@sdd-agent-platform/core/src/delegation/state-machine.ts +90 -90
  302. package/node_modules/@sdd-agent-platform/core/src/delegation/validation.ts +124 -127
  303. package/node_modules/@sdd-agent-platform/core/src/delegation.ts +26 -26
  304. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/ai-entries.ts +28 -28
  305. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/document-chain.ts +104 -112
  306. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/local-run-index.ts +27 -27
  307. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/project.ts +84 -84
  308. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/registries.ts +252 -251
  309. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-evidence.ts +330 -330
  310. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-records.ts +79 -79
  311. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/run-trust.ts +128 -107
  312. package/node_modules/@sdd-agent-platform/core/src/doctor/checks/runtime-contracts.ts +300 -300
  313. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.test.ts +627 -755
  314. package/node_modules/@sdd-agent-platform/core/src/doctor/doctor.ts +301 -453
  315. package/node_modules/@sdd-agent-platform/core/src/doctor/model.ts +13 -13
  316. package/node_modules/@sdd-agent-platform/core/src/doctor/summary.ts +11 -11
  317. package/node_modules/@sdd-agent-platform/core/src/doctor.ts +2 -2
  318. package/node_modules/@sdd-agent-platform/core/src/evidence/lookup.ts +80 -88
  319. package/node_modules/@sdd-agent-platform/core/src/evidence-runtime/contracts.ts +48 -48
  320. package/node_modules/@sdd-agent-platform/core/src/evidence-runtime.ts +1 -1
  321. package/node_modules/@sdd-agent-platform/core/src/execution/agent-execution-records.ts +195 -195
  322. package/node_modules/@sdd-agent-platform/core/src/execution/background-executor.test.ts +187 -235
  323. package/node_modules/@sdd-agent-platform/core/src/execution/background-executor.ts +305 -305
  324. package/node_modules/@sdd-agent-platform/core/src/execution/foreground-subagents.test.ts +97 -106
  325. package/node_modules/@sdd-agent-platform/core/src/execution/foreground-subagents.ts +453 -453
  326. package/node_modules/@sdd-agent-platform/core/src/execution/host-invocation.ts +225 -226
  327. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.test.ts +132 -143
  328. package/node_modules/@sdd-agent-platform/core/src/execution/resident-worker.ts +436 -437
  329. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.test.ts +102 -102
  330. package/node_modules/@sdd-agent-platform/core/src/execution/stage-team-runtime.ts +271 -271
  331. package/node_modules/@sdd-agent-platform/core/src/execution/wave-executor.test.ts +111 -121
  332. package/node_modules/@sdd-agent-platform/core/src/execution/wave-executor.ts +231 -231
  333. package/node_modules/@sdd-agent-platform/core/src/execution.ts +5 -5
  334. package/node_modules/@sdd-agent-platform/core/src/governance/policy.test.ts +57 -65
  335. package/node_modules/@sdd-agent-platform/core/src/governance/policy.ts +175 -175
  336. package/node_modules/@sdd-agent-platform/core/src/governance.ts +1 -1
  337. package/node_modules/@sdd-agent-platform/core/src/instructions.test.ts +80 -64
  338. package/node_modules/@sdd-agent-platform/core/src/instructions.ts +32 -68
  339. package/node_modules/@sdd-agent-platform/core/src/lifecycle/decision-gate.test.ts +174 -174
  340. package/node_modules/@sdd-agent-platform/core/src/lifecycle/decision-gate.ts +373 -373
  341. package/node_modules/@sdd-agent-platform/core/src/lifecycle/rendering.ts +29 -29
  342. package/node_modules/@sdd-agent-platform/core/src/lifecycle/risk-signals.ts +146 -146
  343. package/node_modules/@sdd-agent-platform/core/src/lifecycle/ship.test.ts +47 -47
  344. package/node_modules/@sdd-agent-platform/core/src/lifecycle/ship.ts +255 -280
  345. package/node_modules/@sdd-agent-platform/core/src/lifecycle-graph/contracts.ts +179 -0
  346. package/node_modules/@sdd-agent-platform/core/src/lifecycle-graph/kernel.ts +522 -0
  347. package/node_modules/@sdd-agent-platform/core/src/lifecycle-graph.ts +2 -0
  348. package/node_modules/@sdd-agent-platform/core/src/lifecycle.ts +4 -4
  349. package/node_modules/@sdd-agent-platform/core/src/orchestration/contracts.ts +50 -50
  350. package/node_modules/@sdd-agent-platform/core/src/orchestration/index.ts +2 -2
  351. package/node_modules/@sdd-agent-platform/core/src/orchestration/runtime.ts +331 -394
  352. package/node_modules/@sdd-agent-platform/core/src/path-safety.test.ts +22 -22
  353. package/node_modules/@sdd-agent-platform/core/src/phase8-contracts.test.ts +243 -242
  354. package/node_modules/@sdd-agent-platform/core/src/phase8-projection-compat.test.ts +152 -153
  355. package/node_modules/@sdd-agent-platform/core/src/phase8-risk-kernel.test.ts +277 -277
  356. package/node_modules/@sdd-agent-platform/core/src/phase9-lifecycle-graph.test.ts +103 -0
  357. package/node_modules/@sdd-agent-platform/core/src/planning/task-graph.test.ts +88 -88
  358. package/node_modules/@sdd-agent-platform/core/src/planning/task-graph.ts +222 -222
  359. package/node_modules/@sdd-agent-platform/core/src/planning/wave-plan.test.ts +79 -79
  360. package/node_modules/@sdd-agent-platform/core/src/planning/wave-plan.ts +160 -160
  361. package/node_modules/@sdd-agent-platform/core/src/planning.ts +2 -2
  362. package/node_modules/@sdd-agent-platform/core/src/registries/agent-capability-catalog.ts +426 -473
  363. package/node_modules/@sdd-agent-platform/core/src/registries/agent-registry.ts +230 -146
  364. package/node_modules/@sdd-agent-platform/core/src/registries/agent-runtime-static.ts +142 -142
  365. package/node_modules/@sdd-agent-platform/core/src/registries/capability-sources.ts +253 -253
  366. package/node_modules/@sdd-agent-platform/core/src/registries/command-team-runtime.ts +302 -309
  367. package/node_modules/@sdd-agent-platform/core/src/registries/eval-learning-context.ts +246 -246
  368. package/node_modules/@sdd-agent-platform/core/src/registries/plan-scout-domains.ts +89 -0
  369. package/node_modules/@sdd-agent-platform/core/src/registries/query-status.ts +119 -119
  370. package/node_modules/@sdd-agent-platform/core/src/registries/registries.test.ts +454 -445
  371. package/node_modules/@sdd-agent-platform/core/src/registries/skill-capabilities.ts +37 -37
  372. package/node_modules/@sdd-agent-platform/core/src/registries/tool-capabilities.ts +135 -135
  373. package/node_modules/@sdd-agent-platform/core/src/registries/tool-plugins.ts +132 -132
  374. package/node_modules/@sdd-agent-platform/core/src/registries/worker-adapters.ts +144 -144
  375. package/node_modules/@sdd-agent-platform/core/src/registries/workflow-gates.ts +111 -111
  376. package/node_modules/@sdd-agent-platform/core/src/registries.ts +42 -42
  377. package/node_modules/@sdd-agent-platform/core/src/risk/consumer-diagnostics.ts +98 -97
  378. package/node_modules/@sdd-agent-platform/core/src/risk/contracts.ts +63 -63
  379. package/node_modules/@sdd-agent-platform/core/src/risk/kernel.ts +233 -233
  380. package/node_modules/@sdd-agent-platform/core/src/risk/legacy-adapters.ts +251 -263
  381. package/node_modules/@sdd-agent-platform/core/src/risk/workflow-gates.ts +203 -205
  382. package/node_modules/@sdd-agent-platform/core/src/risk.ts +5 -5
  383. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime-config.ts +327 -327
  384. package/node_modules/@sdd-agent-platform/core/src/router/agent-runtime.ts +388 -390
  385. package/node_modules/@sdd-agent-platform/core/src/router/profile-resolution.ts +154 -154
  386. package/node_modules/@sdd-agent-platform/core/src/router/risk-policy.ts +33 -33
  387. package/node_modules/@sdd-agent-platform/core/src/router/route-cache.ts +100 -100
  388. package/node_modules/@sdd-agent-platform/core/src/router/route-projection.ts +356 -356
  389. package/node_modules/@sdd-agent-platform/core/src/router/route-sdd-task.test.ts +428 -665
  390. package/node_modules/@sdd-agent-platform/core/src/router/route-sdd-task.ts +2 -2
  391. package/node_modules/@sdd-agent-platform/core/src/router/routing-rules.ts +73 -73
  392. package/node_modules/@sdd-agent-platform/core/src/router/routing.ts +189 -223
  393. package/node_modules/@sdd-agent-platform/core/src/router/runtime-import.ts +464 -453
  394. package/node_modules/@sdd-agent-platform/core/src/router/runtime-inspection.ts +124 -124
  395. package/node_modules/@sdd-agent-platform/core/src/router/runtime-registry.ts +123 -123
  396. package/node_modules/@sdd-agent-platform/core/src/router/runtime-validation.ts +277 -277
  397. package/node_modules/@sdd-agent-platform/core/src/router/stage-route-binding.ts +273 -279
  398. package/node_modules/@sdd-agent-platform/core/src/router/team-mode.ts +170 -170
  399. package/node_modules/@sdd-agent-platform/core/src/router.ts +5 -6
  400. package/node_modules/@sdd-agent-platform/core/src/run-state/artifacts.ts +126 -240
  401. package/node_modules/@sdd-agent-platform/core/src/run-state/events.ts +27 -27
  402. package/node_modules/@sdd-agent-platform/core/src/run-state/inspect-run.ts +172 -172
  403. package/node_modules/@sdd-agent-platform/core/src/run-state/invocation-ledger.ts +109 -109
  404. package/node_modules/@sdd-agent-platform/core/src/run-state/model.ts +252 -253
  405. package/node_modules/@sdd-agent-platform/core/src/run-state/run-index.test.ts +52 -52
  406. package/node_modules/@sdd-agent-platform/core/src/run-state/run-index.ts +356 -352
  407. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.test.ts +70 -118
  408. package/node_modules/@sdd-agent-platform/core/src/run-state/run-state.ts +406 -416
  409. package/node_modules/@sdd-agent-platform/core/src/run-state/task-evidence.ts +198 -252
  410. package/node_modules/@sdd-agent-platform/core/src/run-state/timing.ts +146 -146
  411. package/node_modules/@sdd-agent-platform/core/src/run-state.ts +8 -9
  412. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/build.ts +60 -60
  413. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/findings.ts +257 -256
  414. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis/model.ts +140 -140
  415. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis.test.ts +66 -66
  416. package/node_modules/@sdd-agent-platform/core/src/runtime-analysis.ts +2 -2
  417. package/node_modules/@sdd-agent-platform/core/src/runtime-paths.ts +253 -253
  418. package/node_modules/@sdd-agent-platform/core/src/runtime-projection-p0.test.ts +101 -96
  419. package/node_modules/@sdd-agent-platform/core/src/runtime-projection-p0.ts +314 -292
  420. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/artifact-depth.test.ts +380 -0
  421. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/artifact-depth.ts +207 -0
  422. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/context.ts +111 -111
  423. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/document-hashes.ts +207 -306
  424. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/run-binding.ts +95 -97
  425. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-inspection.ts +39 -39
  426. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.test.ts +467 -523
  427. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-parser.ts +738 -709
  428. package/node_modules/@sdd-agent-platform/core/src/sdd-docs/task-rendering.ts +81 -81
  429. package/node_modules/@sdd-agent-platform/core/src/sdd-docs.ts +5 -5
  430. package/node_modules/@sdd-agent-platform/core/src/spec-manager-contracts.ts +13 -0
  431. package/node_modules/@sdd-agent-platform/core/src/stage-artifacts.ts +435 -450
  432. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration-contracts.ts +316 -322
  433. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration.test.ts +2963 -2902
  434. package/node_modules/@sdd-agent-platform/core/src/stage-collaboration.ts +5856 -5831
  435. package/node_modules/@sdd-agent-platform/core/src/stage-runtime/contracts.ts +40 -40
  436. package/node_modules/@sdd-agent-platform/core/src/stage-runtime/runtime.test.ts +209 -209
  437. package/node_modules/@sdd-agent-platform/core/src/stage-runtime/runtime.ts +360 -360
  438. package/node_modules/@sdd-agent-platform/core/src/stage-runtime.ts +2 -2
  439. package/node_modules/@sdd-agent-platform/core/src/status/project-status.test.ts +288 -511
  440. package/node_modules/@sdd-agent-platform/core/src/status/project-status.ts +651 -851
  441. package/node_modules/@sdd-agent-platform/core/src/status.ts +2 -2
  442. package/node_modules/@sdd-agent-platform/core/src/storage/json-io.ts +10 -10
  443. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.test.ts +489 -681
  444. package/node_modules/@sdd-agent-platform/core/src/storage/runtime-store.ts +1981 -1981
  445. package/node_modules/@sdd-agent-platform/core/src/subagents/contracts.ts +45 -45
  446. package/node_modules/@sdd-agent-platform/core/src/subagents/runtime.test.ts +232 -232
  447. package/node_modules/@sdd-agent-platform/core/src/subagents/runtime.ts +307 -307
  448. package/node_modules/@sdd-agent-platform/core/src/subagents.ts +2 -2
  449. package/node_modules/@sdd-agent-platform/core/src/task-execution-contract.test.ts +141 -0
  450. package/node_modules/@sdd-agent-platform/core/src/task-execution-contract.ts +566 -0
  451. package/node_modules/@sdd-agent-platform/core/src/task-risk-profile.ts +193 -193
  452. package/node_modules/@sdd-agent-platform/core/src/test-support/fixtures.ts +413 -398
  453. package/node_modules/@sdd-agent-platform/core/src/test-support/run-state.ts +102 -56
  454. package/node_modules/@sdd-agent-platform/core/src/test-support.ts +2 -2
  455. package/node_modules/@sdd-agent-platform/core/src/truth-reconciliation.test.ts +72 -72
  456. package/node_modules/@sdd-agent-platform/core/src/truth-reconciliation.ts +9 -12
  457. package/node_modules/@sdd-agent-platform/core/src/verification/rendering.ts +137 -137
  458. package/node_modules/@sdd-agent-platform/core/src/verification/review-gate.test.ts +77 -84
  459. package/node_modules/@sdd-agent-platform/core/src/verification/review-gate.ts +77 -77
  460. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.ts +455 -506
  461. package/node_modules/@sdd-agent-platform/core/src/verification/{goal-verify.test.ts → task-evidence-judgment.test.ts} +261 -261
  462. package/node_modules/@sdd-agent-platform/core/src/verification/{goal-verify.ts → task-evidence-judgment.ts} +619 -619
  463. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.ts +1190 -1190
  464. package/node_modules/@sdd-agent-platform/core/src/verification/validation-cache.ts +106 -106
  465. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.ts +513 -556
  466. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.ts +334 -334
  467. package/node_modules/@sdd-agent-platform/core/src/verification.ts +8 -8
  468. package/node_modules/@sdd-agent-platform/core/src/work-units/contracts.ts +26 -26
  469. package/node_modules/@sdd-agent-platform/core/src/work-units/runtime.test.ts +88 -88
  470. package/node_modules/@sdd-agent-platform/core/src/work-units/runtime.ts +112 -112
  471. package/node_modules/@sdd-agent-platform/core/src/work-units.ts +2 -2
  472. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/evidence-packet.ts +190 -425
  473. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.test.ts +169 -507
  474. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/hard-checks.ts +136 -182
  475. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.test.ts +135 -174
  476. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/policy.ts +153 -194
  477. package/node_modules/@sdd-agent-platform/core/src/workflow-gate/types.ts +111 -115
  478. package/node_modules/@sdd-agent-platform/core/src/workflow-state/affected-file-conflicts.ts +95 -93
  479. package/node_modules/@sdd-agent-platform/core/src/workflow-state/dependencies.test.ts +32 -32
  480. package/node_modules/@sdd-agent-platform/core/src/workflow-state/dependencies.ts +114 -114
  481. package/node_modules/@sdd-agent-platform/core/src/workflow-state/latest-eligible-run.ts +184 -224
  482. package/node_modules/@sdd-agent-platform/core/src/workflow-state/migration-recovery.ts +158 -158
  483. package/node_modules/@sdd-agent-platform/core/src/workflow-state/repair-contract.ts +77 -77
  484. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve-task-run.ts +114 -114
  485. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.test.ts +969 -956
  486. package/node_modules/@sdd-agent-platform/core/src/workflow-state/resolve.ts +967 -992
  487. package/node_modules/@sdd-agent-platform/core/src/workflow-state/runtime-projections.ts +712 -712
  488. package/node_modules/@sdd-agent-platform/core/src/workflow-state.ts +2 -2
  489. package/node_modules/@sdd-agent-platform/core/src/worktree/isolation.ts +130 -130
  490. package/node_modules/@sdd-agent-platform/core/src/worktree/lifecycle.ts +269 -269
  491. package/node_modules/@sdd-agent-platform/core/src/worktree/worktree.test.ts +150 -150
  492. package/node_modules/@sdd-agent-platform/core/src/worktree.ts +2 -2
  493. package/node_modules/@sdd-agent-platform/core/tsconfig.json +15 -15
  494. package/package.json +2 -2
  495. package/packages/cli/dist/args.js +2 -2
  496. package/packages/cli/dist/args.js.map +1 -1
  497. package/packages/cli/dist/commands/ai-tools.js +2 -13
  498. package/packages/cli/dist/commands/ai-tools.js.map +1 -1
  499. package/packages/cli/dist/commands/{verifies.d.ts → artifact.d.ts} +1 -1
  500. package/packages/cli/dist/commands/artifact.js +168 -0
  501. package/packages/cli/dist/commands/artifact.js.map +1 -0
  502. package/packages/cli/dist/commands/context.js +1 -1
  503. package/packages/cli/dist/commands/context.js.map +1 -1
  504. package/packages/cli/dist/commands/evidence.js.map +1 -0
  505. package/packages/cli/dist/commands/execution.js +127 -49
  506. package/packages/cli/dist/commands/execution.js.map +1 -1
  507. package/packages/cli/dist/commands/governance.js +1 -1
  508. package/packages/cli/dist/commands/governance.js.map +1 -1
  509. package/packages/cli/dist/commands/init.js +1 -6
  510. package/packages/cli/dist/commands/init.js.map +1 -1
  511. package/packages/cli/dist/commands/instructions.d.ts +1 -1
  512. package/packages/cli/dist/commands/instructions.js +15 -1
  513. package/packages/cli/dist/commands/instructions.js.map +1 -1
  514. package/packages/cli/dist/commands/registry/runtime.js +63 -40
  515. package/packages/cli/dist/commands/registry/runtime.js.map +1 -1
  516. package/packages/cli/dist/commands/run.js +13 -52
  517. package/packages/cli/dist/commands/run.js.map +1 -1
  518. package/packages/cli/dist/commands/stage-close.d.ts +60 -0
  519. package/packages/cli/dist/commands/stage-close.js +270 -41
  520. package/packages/cli/dist/commands/stage-close.js.map +1 -1
  521. package/packages/cli/dist/commands/status.js +9 -68
  522. package/packages/cli/dist/commands/status.js.map +1 -1
  523. package/packages/cli/dist/commands/tasks.js.map +1 -1
  524. package/packages/cli/dist/dispatch.js +6 -26
  525. package/packages/cli/dist/dispatch.js.map +1 -1
  526. package/packages/cli/dist/help.js +153 -159
  527. package/packages/cli/dist/help.js.map +1 -1
  528. package/packages/cli/dist/renderers/artifacts.d.ts +5 -0
  529. package/packages/cli/dist/renderers/artifacts.js +43 -0
  530. package/packages/cli/dist/renderers/artifacts.js.map +1 -0
  531. package/packages/cli/dist/renderers/doctor.js +1 -1
  532. package/packages/cli/dist/renderers/doctor.js.map +1 -1
  533. package/packages/cli/dist/renderers/execution.js +1 -1
  534. package/packages/cli/dist/renderers/execution.js.map +1 -1
  535. package/packages/cli/dist/renderers/json.d.ts +0 -1
  536. package/packages/cli/dist/renderers/json.js +0 -3
  537. package/packages/cli/dist/renderers/json.js.map +1 -1
  538. package/packages/cli/dist/renderers/registry-runtime.d.ts +1 -2
  539. package/packages/cli/dist/renderers/registry-runtime.js +0 -20
  540. package/packages/cli/dist/renderers/registry-runtime.js.map +1 -1
  541. package/packages/cli/dist/renderers/router.js +1 -1
  542. package/packages/cli/dist/renderers/router.js.map +1 -1
  543. package/packages/cli/dist/renderers/workflow.d.ts +53 -0
  544. package/packages/cli/dist/renderers/workflow.js +89 -30
  545. package/packages/cli/dist/renderers/workflow.js.map +1 -1
  546. package/packages/cli/dist/tsconfig.tsbuildinfo +1 -1
  547. package/packages/cli/package.json +2 -2
  548. package/packages/core/dist/ai-tools.js +56 -73
  549. package/packages/core/dist/ai-tools.js.map +1 -1
  550. package/packages/core/dist/artifacts/ingestion.js +9 -64
  551. package/packages/core/dist/artifacts/ingestion.js.map +1 -1
  552. package/packages/core/dist/artifacts/sdd-evidence.js +1 -0
  553. package/packages/core/dist/artifacts/sdd-evidence.js.map +1 -1
  554. package/packages/core/dist/artifacts/sdd-result.js +17 -26
  555. package/packages/core/dist/artifacts/sdd-result.js.map +1 -1
  556. package/packages/core/dist/config/init-project.d.ts +8 -7
  557. package/packages/core/dist/config/init-project.js +8 -12
  558. package/packages/core/dist/config/init-project.js.map +1 -1
  559. package/packages/core/dist/config/project-config.d.ts +1 -1
  560. package/packages/core/dist/config/project-config.js +1 -1
  561. package/packages/core/dist/config/project-config.js.map +1 -1
  562. package/packages/core/dist/config/starter-documents.d.ts +3 -4
  563. package/packages/core/dist/config/starter-documents.js +377 -411
  564. package/packages/core/dist/config/starter-documents.js.map +1 -1
  565. package/packages/core/dist/context/build-package.d.ts +1 -1
  566. package/packages/core/dist/context/build-package.js +7 -13
  567. package/packages/core/dist/context/build-package.js.map +1 -1
  568. package/packages/core/dist/context/evidence-summary.js +8 -26
  569. package/packages/core/dist/context/evidence-summary.js.map +1 -1
  570. package/packages/core/dist/context/log-worker.js +2 -2
  571. package/packages/core/dist/context/log-worker.js.map +1 -1
  572. package/packages/core/dist/context-offload/contracts.d.ts +1 -1
  573. package/packages/core/dist/contracts.d.ts +6 -1
  574. package/packages/core/dist/contracts.js +5 -0
  575. package/packages/core/dist/contracts.js.map +1 -1
  576. package/packages/core/dist/delegation/model.d.ts +0 -3
  577. package/packages/core/dist/delegation/validation.d.ts +0 -3
  578. package/packages/core/dist/delegation/validation.js +4 -7
  579. package/packages/core/dist/delegation/validation.js.map +1 -1
  580. package/packages/core/dist/doctor/checks/document-chain.js +3 -13
  581. package/packages/core/dist/doctor/checks/document-chain.js.map +1 -1
  582. package/packages/core/dist/doctor/checks/project.js +8 -8
  583. package/packages/core/dist/doctor/checks/project.js.map +1 -1
  584. package/packages/core/dist/doctor/checks/registries.js +1 -0
  585. package/packages/core/dist/doctor/checks/registries.js.map +1 -1
  586. package/packages/core/dist/doctor/checks/run-evidence.js +4 -4
  587. package/packages/core/dist/doctor/checks/run-evidence.js.map +1 -1
  588. package/packages/core/dist/doctor/checks/run-trust.js +24 -0
  589. package/packages/core/dist/doctor/checks/run-trust.js.map +1 -1
  590. package/packages/core/dist/doctor/checks/runtime-contracts.js +1 -1
  591. package/packages/core/dist/doctor/checks/runtime-contracts.js.map +1 -1
  592. package/packages/core/dist/doctor/doctor.js +43 -180
  593. package/packages/core/dist/doctor/doctor.js.map +1 -1
  594. package/packages/core/dist/evidence/lookup.d.ts +1 -1
  595. package/packages/core/dist/evidence/lookup.js +7 -14
  596. package/packages/core/dist/evidence/lookup.js.map +1 -1
  597. package/packages/core/dist/evidence-runtime/coordination.js +110 -0
  598. package/packages/core/dist/evidence-runtime/coordination.js.map +1 -0
  599. package/packages/core/dist/execution/background-executor.js +4 -4
  600. package/packages/core/dist/execution/background-executor.js.map +1 -1
  601. package/packages/core/dist/execution/foreground-subagents.js +3 -3
  602. package/packages/core/dist/execution/foreground-subagents.js.map +1 -1
  603. package/packages/core/dist/execution/host-invocation.js +85 -86
  604. package/packages/core/dist/execution/host-invocation.js.map +1 -1
  605. package/packages/core/dist/execution/resident-worker.js +2 -3
  606. package/packages/core/dist/execution/resident-worker.js.map +1 -1
  607. package/packages/core/dist/execution/stage-team-runtime.js +2 -2
  608. package/packages/core/dist/execution/stage-team-runtime.js.map +1 -1
  609. package/packages/core/dist/governance/policy.d.ts +1 -1
  610. package/packages/core/dist/governance/policy.js +1 -1
  611. package/packages/core/dist/governance/policy.js.map +1 -1
  612. package/packages/core/dist/instructions.d.ts +1 -1
  613. package/packages/core/dist/instructions.js +31 -67
  614. package/packages/core/dist/instructions.js.map +1 -1
  615. package/packages/core/dist/lifecycle/decision-gate.js +1 -1
  616. package/packages/core/dist/lifecycle/decision-gate.js.map +1 -1
  617. package/packages/core/dist/lifecycle/ship.d.ts +0 -1
  618. package/packages/core/dist/lifecycle/ship.js +59 -85
  619. package/packages/core/dist/lifecycle/ship.js.map +1 -1
  620. package/packages/core/dist/lifecycle-graph/contracts.d.ts +159 -0
  621. package/packages/core/dist/lifecycle-graph/contracts.js +7 -0
  622. package/packages/core/dist/lifecycle-graph/contracts.js.map +1 -0
  623. package/packages/core/dist/lifecycle-graph/kernel.d.ts +16 -0
  624. package/packages/core/dist/lifecycle-graph/kernel.js +461 -0
  625. package/packages/core/dist/lifecycle-graph/kernel.js.map +1 -0
  626. package/packages/core/dist/lifecycle-graph.d.ts +2 -0
  627. package/packages/core/dist/lifecycle-graph.js +3 -0
  628. package/packages/core/dist/lifecycle-graph.js.map +1 -0
  629. package/packages/core/dist/orchestration/contracts.d.ts +1 -1
  630. package/packages/core/dist/orchestration/runtime.d.ts +2 -12
  631. package/packages/core/dist/orchestration/runtime.js +32 -80
  632. package/packages/core/dist/orchestration/runtime.js.map +1 -1
  633. package/packages/core/dist/registries/agent-capability-catalog.d.ts +2 -5
  634. package/packages/core/dist/registries/agent-capability-catalog.js +27 -69
  635. package/packages/core/dist/registries/agent-capability-catalog.js.map +1 -1
  636. package/packages/core/dist/registries/agent-registry.js +118 -34
  637. package/packages/core/dist/registries/agent-registry.js.map +1 -1
  638. package/packages/core/dist/registries/agent-runtime-static.js +1 -1
  639. package/packages/core/dist/registries/agent-runtime-static.js.map +1 -1
  640. package/packages/core/dist/registries/capability-sources.js +1 -1
  641. package/packages/core/dist/registries/command-team-runtime.d.ts +1 -1
  642. package/packages/core/dist/registries/command-team-runtime.js +8 -15
  643. package/packages/core/dist/registries/command-team-runtime.js.map +1 -1
  644. package/packages/core/dist/registries/eval-learning-context.js +4 -4
  645. package/packages/core/dist/registries/eval-learning-context.js.map +1 -1
  646. package/packages/core/dist/registries/plan-scout-domains.d.ts +13 -0
  647. package/packages/core/dist/registries/plan-scout-domains.js +76 -0
  648. package/packages/core/dist/registries/plan-scout-domains.js.map +1 -0
  649. package/packages/core/dist/registries/query-status.js +2 -2
  650. package/packages/core/dist/registries/query-status.js.map +1 -1
  651. package/packages/core/dist/registries/skill-capabilities.js +7 -7
  652. package/packages/core/dist/registries/skill-capabilities.js.map +1 -1
  653. package/packages/core/dist/registries/tool-capabilities.js +4 -4
  654. package/packages/core/dist/registries/tool-capabilities.js.map +1 -1
  655. package/packages/core/dist/registries/tool-plugins.js +2 -2
  656. package/packages/core/dist/registries/tool-plugins.js.map +1 -1
  657. package/packages/core/dist/registries/worker-adapters.js +11 -11
  658. package/packages/core/dist/registries/worker-adapters.js.map +1 -1
  659. package/packages/core/dist/registries/workflow-gates.d.ts +1 -1
  660. package/packages/core/dist/registries/workflow-gates.js +21 -21
  661. package/packages/core/dist/registries/workflow-gates.js.map +1 -1
  662. package/packages/core/dist/risk/consumer-diagnostics.js +2 -1
  663. package/packages/core/dist/risk/consumer-diagnostics.js.map +1 -1
  664. package/packages/core/dist/risk/kernel.js +6 -6
  665. package/packages/core/dist/risk/kernel.js.map +1 -1
  666. package/packages/core/dist/risk/legacy-adapters.js +11 -23
  667. package/packages/core/dist/risk/legacy-adapters.js.map +1 -1
  668. package/packages/core/dist/risk/workflow-gates.d.ts +2 -2
  669. package/packages/core/dist/risk/workflow-gates.js +18 -20
  670. package/packages/core/dist/risk/workflow-gates.js.map +1 -1
  671. package/packages/core/dist/router/agent-runtime.d.ts +0 -2
  672. package/packages/core/dist/router/route-projection.js +1 -1
  673. package/packages/core/dist/router/route-projection.js.map +1 -1
  674. package/packages/core/dist/router/routing.js +16 -48
  675. package/packages/core/dist/router/routing.js.map +1 -1
  676. package/packages/core/dist/router/runtime-import.js +11 -1
  677. package/packages/core/dist/router/runtime-import.js.map +1 -1
  678. package/packages/core/dist/router/runtime-validation.js +2 -2
  679. package/packages/core/dist/router/runtime-validation.js.map +1 -1
  680. package/packages/core/dist/router/stage-route-binding.d.ts +2 -2
  681. package/packages/core/dist/router/stage-route-binding.js +20 -28
  682. package/packages/core/dist/router/stage-route-binding.js.map +1 -1
  683. package/packages/core/dist/router.d.ts +0 -1
  684. package/packages/core/dist/router.js +0 -1
  685. package/packages/core/dist/router.js.map +1 -1
  686. package/packages/core/dist/run-state/artifacts.d.ts +6 -6
  687. package/packages/core/dist/run-state/artifacts.js +13 -124
  688. package/packages/core/dist/run-state/artifacts.js.map +1 -1
  689. package/packages/core/dist/run-state/inspect-run.d.ts +2 -0
  690. package/packages/core/dist/run-state/inspect-run.js +5 -7
  691. package/packages/core/dist/run-state/inspect-run.js.map +1 -1
  692. package/packages/core/dist/run-state/model.d.ts +28 -28
  693. package/packages/core/dist/run-state/run-index.d.ts +2 -0
  694. package/packages/core/dist/run-state/run-index.js +3 -1
  695. package/packages/core/dist/run-state/run-index.js.map +1 -1
  696. package/packages/core/dist/run-state/run-state.js +26 -36
  697. package/packages/core/dist/run-state/run-state.js.map +1 -1
  698. package/packages/core/dist/run-state/task-evidence.d.ts +0 -4
  699. package/packages/core/dist/run-state/task-evidence.js +5 -51
  700. package/packages/core/dist/run-state/task-evidence.js.map +1 -1
  701. package/packages/core/dist/run-state.d.ts +0 -1
  702. package/packages/core/dist/run-state.js +0 -1
  703. package/packages/core/dist/run-state.js.map +1 -1
  704. package/packages/core/dist/runtime-analysis/build.js +1 -1
  705. package/packages/core/dist/runtime-analysis/build.js.map +1 -1
  706. package/packages/core/dist/runtime-analysis/findings.js +5 -5
  707. package/packages/core/dist/runtime-analysis/findings.js.map +1 -1
  708. package/packages/core/dist/runtime-paths.js +1 -1
  709. package/packages/core/dist/runtime-paths.js.map +1 -1
  710. package/packages/core/dist/runtime-projection-p0.d.ts +2 -2
  711. package/packages/core/dist/runtime-projection-p0.js +11 -0
  712. package/packages/core/dist/runtime-projection-p0.js.map +1 -1
  713. package/packages/core/dist/sdd-docs/artifact-depth.d.ts +14 -0
  714. package/packages/core/dist/sdd-docs/artifact-depth.js +179 -0
  715. package/packages/core/dist/sdd-docs/artifact-depth.js.map +1 -0
  716. package/packages/core/dist/sdd-docs/document-hashes.d.ts +0 -2
  717. package/packages/core/dist/sdd-docs/document-hashes.js +10 -97
  718. package/packages/core/dist/sdd-docs/document-hashes.js.map +1 -1
  719. package/packages/core/dist/sdd-docs/run-binding.d.ts +1 -1
  720. package/packages/core/dist/sdd-docs/run-binding.js +6 -8
  721. package/packages/core/dist/sdd-docs/run-binding.js.map +1 -1
  722. package/packages/core/dist/sdd-docs/task-parser.d.ts +5 -2
  723. package/packages/core/dist/sdd-docs/task-parser.js +85 -68
  724. package/packages/core/dist/sdd-docs/task-parser.js.map +1 -1
  725. package/packages/core/dist/sdd-docs/task-rendering.js +2 -2
  726. package/packages/core/dist/sdd-docs/task-rendering.js.map +1 -1
  727. package/packages/core/dist/spec-entry.js +40 -0
  728. package/packages/core/dist/spec-entry.js.map +1 -0
  729. package/packages/core/dist/spec-manager-contracts.d.ts +12 -0
  730. package/packages/core/dist/spec-manager-contracts.js +2 -0
  731. package/packages/core/dist/spec-manager-contracts.js.map +1 -0
  732. package/packages/core/dist/stage-artifacts.d.ts +2 -2
  733. package/packages/core/dist/stage-artifacts.js +19 -26
  734. package/packages/core/dist/stage-artifacts.js.map +1 -1
  735. package/packages/core/dist/stage-collaboration-contracts.d.ts +1 -1
  736. package/packages/core/dist/stage-collaboration-contracts.js +3 -6
  737. package/packages/core/dist/stage-collaboration-contracts.js.map +1 -1
  738. package/packages/core/dist/stage-collaboration.d.ts +111 -263
  739. package/packages/core/dist/stage-collaboration.js +1272 -1124
  740. package/packages/core/dist/stage-collaboration.js.map +1 -1
  741. package/packages/core/dist/stage-runtime/runtime.js +5 -5
  742. package/packages/core/dist/stage-runtime/runtime.js.map +1 -1
  743. package/packages/core/dist/status/project-status.d.ts +1 -44
  744. package/packages/core/dist/status/project-status.js +47 -170
  745. package/packages/core/dist/status/project-status.js.map +1 -1
  746. package/packages/core/dist/storage/runtime-store.js +73 -73
  747. package/packages/core/dist/subagents/contracts.d.ts +1 -1
  748. package/packages/core/dist/subagents/runtime.js +7 -7
  749. package/packages/core/dist/subagents/runtime.js.map +1 -1
  750. package/packages/core/dist/sync-back/apply.d.ts +1 -0
  751. package/packages/core/dist/sync-back/apply.js +2 -0
  752. package/packages/core/dist/sync-back/apply.js.map +1 -0
  753. package/packages/core/dist/sync-back/inspect.d.ts +1 -0
  754. package/packages/core/dist/sync-back/inspect.js +2 -0
  755. package/packages/core/dist/sync-back/inspect.js.map +1 -0
  756. package/packages/core/dist/sync-back.d.ts +1 -0
  757. package/packages/core/dist/sync-back.js +2 -0
  758. package/packages/core/dist/sync-back.js.map +1 -0
  759. package/packages/core/dist/task-execution-contract.d.ts +167 -0
  760. package/packages/core/dist/task-execution-contract.js +377 -0
  761. package/packages/core/dist/task-execution-contract.js.map +1 -0
  762. package/packages/core/dist/test-support/fixtures.js +329 -314
  763. package/packages/core/dist/test-support/fixtures.js.map +1 -1
  764. package/packages/core/dist/test-support/run-state.d.ts +1 -0
  765. package/packages/core/dist/test-support/run-state.js +53 -7
  766. package/packages/core/dist/test-support/run-state.js.map +1 -1
  767. package/packages/core/dist/truth-reconciliation.js +9 -12
  768. package/packages/core/dist/truth-reconciliation.js.map +1 -1
  769. package/packages/core/dist/tsconfig.tsbuildinfo +1 -1
  770. package/packages/core/dist/verification/goal-verify.d.ts +0 -48
  771. package/packages/core/dist/verification/goal-verify.js +1 -520
  772. package/packages/core/dist/verification/goal-verify.js.map +1 -1
  773. package/packages/core/dist/verification/rendering.d.ts +5 -5
  774. package/packages/core/dist/verification/rendering.js +14 -14
  775. package/packages/core/dist/verification/rendering.js.map +1 -1
  776. package/packages/core/dist/verification/single-task-loop.d.ts +1 -0
  777. package/packages/core/dist/verification/single-task-loop.js +111 -159
  778. package/packages/core/dist/verification/single-task-loop.js.map +1 -1
  779. package/packages/core/dist/verification/task-evidence-judgment.d.ts +49 -0
  780. package/packages/core/dist/verification/task-evidence-judgment.js +521 -0
  781. package/packages/core/dist/verification/task-evidence-judgment.js.map +1 -0
  782. package/packages/core/dist/verification/test-runtime.js +21 -21
  783. package/packages/core/dist/verification/test-runtime.js.map +1 -1
  784. package/packages/core/dist/verification/validation-wave.d.ts +0 -18
  785. package/packages/core/dist/verification/validation-wave.js +5 -27
  786. package/packages/core/dist/verification/validation-wave.js.map +1 -1
  787. package/packages/core/dist/verification/verify-contract.js +45 -45
  788. package/packages/core/dist/verification/verify-contract.js.map +1 -1
  789. package/packages/core/dist/verification.d.ts +3 -3
  790. package/packages/core/dist/verification.js +2 -2
  791. package/packages/core/dist/verification.js.map +1 -1
  792. package/packages/core/dist/work-units/contracts.d.ts +1 -1
  793. package/packages/core/dist/workflow-gate/evidence-packet.js +9 -227
  794. package/packages/core/dist/workflow-gate/evidence-packet.js.map +1 -1
  795. package/packages/core/dist/workflow-gate/hard-checks.js +9 -50
  796. package/packages/core/dist/workflow-gate/hard-checks.js.map +1 -1
  797. package/packages/core/dist/workflow-gate/policy.js +4 -42
  798. package/packages/core/dist/workflow-gate/policy.js.map +1 -1
  799. package/packages/core/dist/workflow-gate/types.d.ts +2 -3
  800. package/packages/core/dist/workflow-state/affected-file-conflicts.d.ts +1 -0
  801. package/packages/core/dist/workflow-state/affected-file-conflicts.js +2 -1
  802. package/packages/core/dist/workflow-state/affected-file-conflicts.js.map +1 -1
  803. package/packages/core/dist/workflow-state/dependencies.js +1 -1
  804. package/packages/core/dist/workflow-state/latest-eligible-run.d.ts +1 -0
  805. package/packages/core/dist/workflow-state/latest-eligible-run.js +23 -63
  806. package/packages/core/dist/workflow-state/latest-eligible-run.js.map +1 -1
  807. package/packages/core/dist/workflow-state/resolve.d.ts +2 -2
  808. package/packages/core/dist/workflow-state/resolve.js +43 -65
  809. package/packages/core/dist/workflow-state/resolve.js.map +1 -1
  810. package/packages/core/package.json +5 -2
  811. package/tsconfig.build.json +6 -7
  812. package/node_modules/@sdd-agent-platform/core/src/verification/single-task-loop.test.ts +0 -269
  813. package/node_modules/@sdd-agent-platform/core/src/verification/test-runtime.test.ts +0 -492
  814. package/node_modules/@sdd-agent-platform/core/src/verification/validation-wave.test.ts +0 -383
  815. package/node_modules/@sdd-agent-platform/core/src/verification/verify-contract.test.ts +0 -188
  816. package/packages/cli/dist/commands/lifecycle.d.ts +0 -6
  817. package/packages/cli/dist/commands/lifecycle.js +0 -125
  818. package/packages/cli/dist/commands/lifecycle.js.map +0 -1
  819. package/packages/cli/dist/commands/test.d.ts +0 -6
  820. package/packages/cli/dist/commands/test.js +0 -373
  821. package/packages/cli/dist/commands/test.js.map +0 -1
  822. package/packages/cli/dist/commands/verifies.js +0 -87
  823. package/packages/cli/dist/commands/verifies.js.map +0 -1
  824. package/packages/cli/dist/commands/verify.d.ts +0 -6
  825. package/packages/cli/dist/commands/verify.js +0 -330
  826. package/packages/cli/dist/commands/verify.js.map +0 -1
@@ -1,851 +1,651 @@
1
- import { execFile } from 'node:child_process';
2
- import { stat } from 'node:fs/promises';
3
- import { promisify } from 'node:util';
4
- import type { ContextBranchSource, ContextResolverContract } from '../sdd-docs/context.js';
5
- import type { SddTaskGap, SddTaskModel } from '../sdd-docs/task-parser.js';
6
- import type { RunSummary } from '../run-state/model.js';
7
- import { readRunEvents } from '../run-state/events.js';
8
- import { readRunState } from '../run-state/run-state.js';
9
- import { listAgentExecutionRecords, listTeamSessionRecords } from '../execution/agent-execution-records.js';
10
- import { listResidentWorkerRuntimes } from '../execution/resident-worker.js';
11
- import { runDocumentStaleReasons } from '../workflow-state/resolve-task-run.js';
12
- import { resolveWorkflowState, workflowNextIntent, type WorkflowLatestTaskRun, type WorkflowNextIntent } from '../workflow-state/resolve.js';
13
- import type { WorkflowAffectedFileConflict } from '../workflow-state/affected-file-conflicts.js';
14
- import type { WorkflowDependencyBlocker } from '../workflow-state/dependencies.js';
15
- import type { LatestEligibleRunSelection } from '../workflow-state/latest-eligible-run.js';
16
- import { buildTaskRiskProfile } from '../task-risk-profile.js';
17
- import { listRuntimeProjections } from '../storage/runtime-store.js';
18
- import { inspectLifecycleRiskDecisionForModel, type LifecycleRiskConsumerDiagnostic } from '../risk.js';
19
- import { inspectWorkflowStageHandoff, type WorkflowStageHandoffDiagnostic } from '../stage-runtime.js';
20
- import { inspectContextOffloadRuntime, type ContextRuntimeDiagnostic } from '../context-offload.js';
21
- import { inspectFullStageChain, inspectSpecCollaborationHealth, type FullStageChainDiagnostic, type SpecCollaborationHealthDiagnostic } from '../stage-collaboration.js';
22
- import { inspectRuntimeProjectionP0, type RuntimeProjectionP0Diagnostic } from '../runtime-projection-p0.js';
23
- import { inspectSubagentDispatches, type SubagentDispatchDiagnostic } from '../subagents.js';
24
- import { inspectAgentCapabilityCatalog, REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS, type AgentCapabilityDomain, type ProfessionalCapabilityDomain } from '../registries/agent-capability-catalog.js';
25
- import { validateAgentSkillTeamRuntime } from '../router/runtime-validation.js';
26
- import {
27
- listRuntimeArtifactPayloads,
28
- listRuntimeCapabilityAdoptions,
29
- listRuntimeDurableGaps,
30
- listRuntimeFanInEvidenceSets,
31
- listRuntimeLlmAdvisorAssessments,
32
- listRuntimeStageRoleResults,
33
- listRuntimeStageTeamSessions,
34
- listRuntimeTestRuns,
35
- listRuntimeWorkflowGateDecisions,
36
- type RuntimeArtifactPayloadRecord,
37
- type RuntimeArtifactPayloadStatus,
38
- type RuntimeCapabilityAdoptionRecord,
39
- type RuntimeDurableGapRecord
40
- } from '../storage/runtime-store.js';
41
- import type { CapabilityEvidenceClassification } from '../evidence-runtime.js';
42
- import type { WorkflowGateDecision, WorkflowGateDecisionKind } from '../workflow-gate/types.js';
43
- import type { TruthReconciliationDecision } from '../truth-reconciliation.js';
44
-
45
- const execFileAsync = promisify(execFile);
46
-
47
- export interface RunEvidenceSummary {
48
- agentExecutions: number;
49
- teamSessions: number;
50
- artifactIngestions: number;
51
- workerRuntimes: number;
52
- staleWorkerRuntimes: number;
53
- routePreflight: boolean;
54
- tasksChangedAfterRun: boolean;
55
- tasksUpdatedAt: string | null;
56
- runUpdatedAt: string | null;
57
- }
58
-
59
- export interface TaskRiskSummary {
60
- highRiskTasks: string[];
61
- mediumRiskTasks: string[];
62
- sourceBoundaryTasks: string[];
63
- contextRiskTasks: string[];
64
- tokenRiskTasks: string[];
65
- performanceRiskTasks: string[];
66
- }
67
-
68
- export interface TokenRuntimeProjection {
69
- health: 'unknown' | 'nominal' | 'pressure';
70
- estimatedTokens: number | null;
71
- contextPackages: number;
72
- teamRuntimeDecisions: number;
73
- pressureReasons: string[];
74
- }
75
-
76
- export type CapabilityHealthStatus = 'absent' | 'pass' | 'warn' | 'blocked';
77
-
78
- export interface CapabilityHealthProjection {
79
- status: CapabilityHealthStatus;
80
- requiredProfessionalDomains: ProfessionalCapabilityDomain[];
81
- baselineDomains: ProfessionalCapabilityDomain[];
82
- missingBaselineDomains: ProfessionalCapabilityDomain[];
83
- materialPacks: number;
84
- activeDomains: AgentCapabilityDomain[];
85
- activePacks: string[];
86
- sources: {
87
- total: number;
88
- quarantined: number;
89
- denied: number;
90
- futureAdapters: number;
91
- };
92
- evidence: {
93
- accepted: number;
94
- candidate: number;
95
- quarantined: number;
96
- diagnostic: number;
97
- blocked: number;
98
- };
99
- adoptions: {
100
- adopted: number;
101
- rejected: number;
102
- unresolved: number;
103
- acceptedAuthority: number;
104
- releaseCriticalClosures: ProfessionalCapabilityDomain[];
105
- };
106
- warnings: string[];
107
- releaseCriticalGaps: ProfessionalCapabilityDomain[];
108
- reasons: string[];
109
- }
110
-
111
- export interface StageTeamHealthProjection {
112
- sessions: number;
113
- roleResults: number;
114
- advisorAssessments: number;
115
- fanInEvidenceSets: number;
116
- highConcernAdvisors: number;
117
- lifecycleProfiles: string[];
118
- directProfileRequiresNoTeam: boolean;
119
- }
120
-
121
- export interface WorkflowGateHealthProjection {
122
- decisions: number;
123
- blocked: number;
124
- warnings: number;
125
- humanRequired: number;
126
- latestDecision: WorkflowGateDecision | null;
127
- statusesByKind: Partial<Record<WorkflowGateDecisionKind, WorkflowGateDecision['status']>>;
128
- evidenceSelection: WorkflowGateEvidenceSelectionProjection;
129
- }
130
-
131
- export type WorkflowGateEvidenceSelectionSource = 'selection_pointer' | 'candidate_payloads' | 'legacy_active_payloads' | 'none' | 'unknown';
132
-
133
- export interface WorkflowGateEvidenceSelectionRef {
134
- payloadId: string | null;
135
- logicalRef: string;
136
- digest: string | null;
137
- status: string | null;
138
- }
139
-
140
- export interface WorkflowGateEvidenceSelectionProjection {
141
- source: WorkflowGateEvidenceSelectionSource;
142
- selectionPointerRef: string | null;
143
- acceptedEvidenceSetRef: string | null;
144
- selectedRefs: WorkflowGateEvidenceSelectionRef[];
145
- blockedRefs: string[];
146
- ignoredRefs: WorkflowGateEvidenceSelectionRef[];
147
- ignoredCounts: Record<Exclude<RuntimeArtifactPayloadStatus, 'active' | 'candidate'>, number>;
148
- selectionReasons: string[];
149
- reasons: string[];
150
- }
151
-
152
- export interface SpecCollaborationHealthProjection {
153
- status: SpecCollaborationHealthDiagnostic['status'];
154
- projectionCount: number;
155
- latestClarificationGateId: string | null;
156
- latestHandoffId: string | null;
157
- latestRejectionReason: string | null;
158
- reasons: string[];
159
- }
160
-
161
- export interface ProjectStatus {
162
- branch: string;
163
- workflowStatus: 'active' | 'not_started';
164
- context: ContextResolverContract;
165
- gitRoot: string | null;
166
- documents: SddTaskModel['documents'];
167
- tasks: {
168
- total: number;
169
- pending: number;
170
- inProgress: number;
171
- completed: number;
172
- blocked: number;
173
- deferred: number;
174
- unknown: number;
175
- gaps: number;
176
- };
177
- taskRisk: TaskRiskSummary;
178
- latestRun: RunSummary | null;
179
- latestRunsByTask: WorkflowLatestTaskRun[];
180
- latestEligibleRunsByTask: LatestEligibleRunSelection[];
181
- latestRunEvidence: RunEvidenceSummary | null;
182
- latestRunStaleReasons: string[];
183
- affectedFileConflicts: WorkflowAffectedFileConflict[];
184
- dependencyBlockers: WorkflowDependencyBlocker[];
185
- recommendedNextCommand: string;
186
- nextIntent: WorkflowNextIntent;
187
- tokenProjection: TokenRuntimeProjection;
188
- contextRuntime: ContextRuntimeDiagnostic;
189
- subagentDispatches: SubagentDispatchDiagnostic;
190
- lifecycleRisk: LifecycleRiskConsumerDiagnostic;
191
- capabilityHealth: CapabilityHealthProjection;
192
- workflowHandoff: WorkflowStageHandoffDiagnostic;
193
- specCollaborationHealth: SpecCollaborationHealthProjection;
194
- fullStageChain: FullStageChainDiagnostic;
195
- gaps: SddTaskGap[];
196
- durableGaps: RuntimeDurableGapRecord[];
197
- stageTeamHealth: StageTeamHealthProjection;
198
- workflowGateHealth: WorkflowGateHealthProjection;
199
- runtimeProjectionP0: RuntimeProjectionP0Diagnostic;
200
- truthReconciliation: TruthReconciliationDecision | null;
201
- }
202
-
203
- export interface StatuslineProjection {
204
- contract: 'sdd-statusline-projection-v1';
205
- branch: string;
206
- workflow: ProjectStatus['workflowStatus'];
207
- taskHealth: 'empty' | 'active' | 'blocked' | 'complete';
208
- runtimeHealth: 'none' | 'pass' | 'warn' | 'blocked';
209
- testHealth: 'none' | 'pass' | 'warn' | 'blocked';
210
- teamHealth: 'none' | 'active';
211
- tokenHealth: 'unknown' | 'nominal' | 'pressure';
212
- contextLoad: ProjectStatus['contextRuntime']['level'];
213
- contextAction: ProjectStatus['contextRuntime']['action'];
214
- subagentHealth: ProjectStatus['subagentDispatches']['status'];
215
- evidenceHealth: 'none' | 'pass' | 'warn' | 'blocked';
216
- capabilityHealth: ProjectStatus['capabilityHealth']['status'];
217
- latestRunId: string | null;
218
- counts: {
219
- tasks: ProjectStatus['tasks'];
220
- agentExecutions: number;
221
- teamSessions: number;
222
- workerRuntimes: number;
223
- staleWorkerRuntimes: number;
224
- artifactIngestions: number;
225
- staleReasons: number;
226
- affectedFileConflicts: number;
227
- subagentDispatches: number;
228
- blockingSubagents: number;
229
- capabilityWarnings: number;
230
- durableGaps: number;
231
- stageTeamSessions: number;
232
- stageRoleResults: number;
233
- advisorAssessments: number;
234
- fanInEvidenceSets: number;
235
- workflowGateDecisions: number;
236
- specCollaborationProjections: number;
237
- };
238
- taskRisk: TaskRiskSummary;
239
- next: string;
240
- }
241
-
242
- export async function getProjectStatus(projectRoot: string, options: { branch?: string | null; branchSource?: ContextBranchSource } = {}): Promise<ProjectStatus> {
243
- const [workflow, gitRoot] = await Promise.all([resolveWorkflowState(projectRoot, options), getGitRoot(projectRoot)]);
244
- const latestRun = workflow.latestRun;
245
- const latestRunState = workflow.latestRunState;
246
- const latestRunEvidence = latestRun ? await inspectRunEvidenceSummary(projectRoot, latestRun.runId) : null;
247
- const enrichedLatestRunEvidence = latestRun && latestRunEvidence
248
- ? await addTaskDocumentStalenessToRunEvidence(workflow.model.tasksPath, latestRun, latestRunEvidence)
249
- : latestRunEvidence;
250
- const latestRunStaleReasons = latestRunState ? runDocumentStaleReasons(latestRunState, workflow.model) : [];
251
- const taskRisk = summarizeTaskRisk(workflow.model.tasks);
252
- const tokenProjection = await inspectTokenRuntimeProjection(projectRoot);
253
- const lifecycleRisk = await inspectLifecycleRiskDecisionForModel(projectRoot, workflow.branch, workflow.model);
254
- const workflowHandoff = await inspectWorkflowStageHandoff(projectRoot, workflow.branch);
255
- const contextRuntime = await inspectContextOffloadRuntime(projectRoot, workflow.branch);
256
- const subagentDispatches = await inspectSubagentDispatches(projectRoot, workflow.branch);
257
- const capabilityHealth = await inspectCapabilityHealth(projectRoot, workflow.branch, latestRun?.runId ?? null, workflow.model.tasks);
258
- const durableGaps = await listRuntimeDurableGaps(projectRoot, { partition: workflow.branch, status: 'open_terminal' });
259
- const stageTeamHealth = await inspectStageTeamHealth(projectRoot, workflow.branch, latestRun?.runId ?? null);
260
- const workflowGateHealth = await inspectWorkflowGateHealth(projectRoot, workflow.branch, latestRun?.runId ?? null);
261
- const specCollaborationHealth = await inspectSpecCollaborationHealth(projectRoot, workflow.branch);
262
- const fullStageChain = await inspectFullStageChain(projectRoot, workflow.branch);
263
- const runtimeProjectionP0 = await inspectRuntimeProjectionP0(projectRoot, workflow.branch);
264
- const nextIntent = resolveProjectStatusNextIntent(workflow.branch, workflow.nextIntent, fullStageChain, workflowHandoff, workflow.truthReconciliation);
265
-
266
- return {
267
- branch: workflow.branch,
268
- workflowStatus: workflow.workflowStatus,
269
- context: workflow.context,
270
- gitRoot,
271
- documents: workflow.documents,
272
- tasks: workflow.taskCounts,
273
- taskRisk,
274
- latestRun,
275
- latestRunsByTask: workflow.latestRunsByTask,
276
- latestEligibleRunsByTask: workflow.latestEligibleRunsByTask,
277
- latestRunEvidence: enrichedLatestRunEvidence,
278
- latestRunStaleReasons,
279
- affectedFileConflicts: workflow.affectedFileConflicts,
280
- dependencyBlockers: workflow.dependencyBlockers,
281
- recommendedNextCommand: nextIntent.canonicalCommand,
282
- nextIntent,
283
- tokenProjection,
284
- contextRuntime,
285
- subagentDispatches,
286
- lifecycleRisk,
287
- workflowHandoff,
288
- capabilityHealth,
289
- gaps: workflow.visibleGaps,
290
- durableGaps,
291
- stageTeamHealth,
292
- workflowGateHealth,
293
- specCollaborationHealth,
294
- fullStageChain,
295
- runtimeProjectionP0,
296
- truthReconciliation: workflow.truthReconciliation
297
- };
298
- }
299
-
300
- export function resolveProjectStatusNextIntent(
301
- branch: string,
302
- workflowIntent: WorkflowNextIntent,
303
- fullStageChain: Pick<FullStageChainDiagnostic, 'finalHealth'>,
304
- workflowHandoff?: Pick<WorkflowStageHandoffDiagnostic, 'status' | 'latestHandoff' | 'latestStageRun'>,
305
- truthReconciliation?: TruthReconciliationDecision | null
306
- ): WorkflowNextIntent {
307
- if (truthReconciliation) {
308
- return truthReconciliation.nextIntent;
309
- }
310
- if (fullStageChain.finalHealth === 'ship_ready') {
311
- return workflowNextIntent('ship', 'workflow_complete', `sdd status --branch ${branch} --json`, 'Active Phase 9 stage chain is closed through ship_ready; inspect status only after accepted evidence changes.', null, {
312
- targetRuntimeStage: 'ship',
313
- displayCommand: `/sdd status --branch ${branch} --json`,
314
- evidenceSurface: ['specs/<branch>/*.md', '.sdd/runs/<branch>/<stage>/*.md', 'truthAlignment projection']
315
- });
316
- }
317
- if (fullStageChain.finalHealth === 'ready_for_ship') {
318
- return workflowNextIntent('ship', 'ship_readiness', `sdd ship close --branch ${branch} --compact-json`, 'Goal verification and truthAlignment are ready; close ship readiness with ship-stage evidence.', null);
319
- }
320
- return intraBundleHandoffNextIntent(branch, workflowHandoff) ?? workflowIntent;
321
- }
322
-
323
- function intraBundleHandoffNextIntent(branch: string, workflowHandoff?: Pick<WorkflowStageHandoffDiagnostic, 'status' | 'latestHandoff' | 'latestStageRun'>): WorkflowNextIntent | null {
324
- const handoff = workflowHandoff?.latestHandoff;
325
- const latestStageRun = workflowHandoff?.latestStageRun;
326
- if (workflowHandoff?.status !== 'fresh' || !handoff || !['proposed', 'accepted'].includes(handoff.status)) {
327
- return null;
328
- }
329
- if (latestStageRun?.stage === handoff.toStage && latestStageRun.status === 'completed') {
330
- return null;
331
- }
332
- if (handoff.fromStage === 'tasks' && handoff.toStage === 'verifies') {
333
- return workflowNextIntent('tasks', 'run_verifies', `sdd tasks close --branch ${branch} --target verifies --compact-json`, 'Close verifies inside the /sdd:tasks bundle using agent-authored verify evidence.', null, {
334
- targetRuntimeStage: 'verifies',
335
- resumeMode: 'resume',
336
- canAutoAdvanceWithinBundle: true,
337
- evidenceSurface: ['specs/<branch>/verify.md', '.sdd/runs/<branch>/verifies/*.md']
338
- });
339
- }
340
- if (handoff.fromStage === 'test' && handoff.toStage === 'goal-verify') {
341
- return workflowNextIntent('test', 'run_goal_verify', `sdd test close --branch ${branch} --target goal-verify --compact-json`, 'Close goal verification inside the /sdd:test bundle and compute truthAlignment before ship readiness.', null, {
342
- targetRuntimeStage: 'goal-verify',
343
- resumeMode: 'resume',
344
- canAutoAdvanceWithinBundle: true,
345
- evidenceSurface: ['.sdd/runs/<branch>/goal-verify/*.md', 'truthAlignment projection']
346
- });
347
- }
348
- return null;
349
- }
350
-
351
- export async function getStatuslineProjection(projectRoot: string, options: { branch?: string | null; branchSource?: ContextBranchSource } = {}): Promise<StatuslineProjection> {
352
- return statuslineProjectionFromStatus(await getProjectStatus(projectRoot, options));
353
- }
354
-
355
- export function statuslineProjectionFromStatus(status: ProjectStatus): StatuslineProjection {
356
- const evidence = status.latestRunEvidence;
357
- const runtimeHealth = status.latestRun
358
- ? status.latestRun.status === 'completed' && status.latestRun.validationStatus === 'pass' ? 'pass' : 'blocked'
359
- : 'none';
360
- const staleReasons = status.latestRunStaleReasons.length;
361
- const affectedFileConflicts = status.affectedFileConflicts.length;
362
- return {
363
- contract: 'sdd-statusline-projection-v1',
364
- branch: status.branch,
365
- workflow: status.workflowStatus,
366
- taskHealth: taskHealth(status),
367
- runtimeHealth,
368
- testHealth: testHealth(status),
369
- teamHealth: (evidence?.teamSessions ?? 0) > 0 || status.stageTeamHealth.sessions > 0 || status.stageTeamHealth.roleResults > 0 ? 'active' : 'none',
370
- tokenHealth: status.tokenProjection.health,
371
- contextLoad: status.contextRuntime.level,
372
- contextAction: status.contextRuntime.action,
373
- subagentHealth: status.subagentDispatches.status,
374
- evidenceHealth: evidenceHealth(status, runtimeHealth),
375
- capabilityHealth: status.capabilityHealth.status,
376
- latestRunId: status.latestRun?.runId ?? null,
377
- counts: {
378
- tasks: status.tasks,
379
- agentExecutions: evidence?.agentExecutions ?? 0,
380
- teamSessions: evidence?.teamSessions ?? 0,
381
- workerRuntimes: evidence?.workerRuntimes ?? 0,
382
- staleWorkerRuntimes: evidence?.staleWorkerRuntimes ?? 0,
383
- artifactIngestions: evidence?.artifactIngestions ?? 0,
384
- staleReasons,
385
- affectedFileConflicts,
386
- subagentDispatches: status.subagentDispatches.dispatches,
387
- blockingSubagents: status.subagentDispatches.blockingOpen,
388
- capabilityWarnings: status.capabilityHealth.warnings.length,
389
- durableGaps: status.durableGaps.length,
390
- stageTeamSessions: status.stageTeamHealth.sessions,
391
- stageRoleResults: status.stageTeamHealth.roleResults,
392
- advisorAssessments: status.stageTeamHealth.advisorAssessments,
393
- fanInEvidenceSets: status.stageTeamHealth.fanInEvidenceSets,
394
- workflowGateDecisions: status.workflowGateHealth.decisions,
395
- specCollaborationProjections: status.specCollaborationHealth.projectionCount
396
- },
397
- taskRisk: status.taskRisk,
398
- next: status.recommendedNextCommand
399
- };
400
- }
401
-
402
- async function inspectStageTeamHealth(projectRoot: string, partition: string, runId: string | null): Promise<StageTeamHealthProjection> {
403
- const query = runId ? { partition, runId } : { partition };
404
- const [sessions, roleResults, advisorAssessments, fanInEvidenceSets] = await Promise.all([
405
- listRuntimeStageTeamSessions(projectRoot, query),
406
- listRuntimeStageRoleResults(projectRoot, query),
407
- listRuntimeLlmAdvisorAssessments(projectRoot, query),
408
- listRuntimeFanInEvidenceSets(projectRoot, query)
409
- ]);
410
- return {
411
- sessions: sessions.length,
412
- roleResults: roleResults.length,
413
- advisorAssessments: advisorAssessments.length,
414
- fanInEvidenceSets: fanInEvidenceSets.length,
415
- highConcernAdvisors: advisorAssessments.filter((assessment) => assessment.concern === 'high').length,
416
- lifecycleProfiles: [...new Set(sessions.map((session) => session.lifecycleProfile))].sort(),
417
- directProfileRequiresNoTeam: !sessions.some((session) => session.lifecycleProfile === 'direct' && session.assignments.some((assignment) => assignment.required))
418
- };
419
- }
420
-
421
- async function inspectWorkflowGateHealth(projectRoot: string, partition: string, runId: string | null): Promise<WorkflowGateHealthProjection> {
422
- const query = runId ? { partition, runId } : { partition };
423
- const decisions = await listRuntimeWorkflowGateDecisions(projectRoot, query);
424
- const latestDecision = decisions[0] ?? null;
425
- const artifactPayloads = await listRuntimeArtifactPayloads(projectRoot, {
426
- branchSlug: partition,
427
- runId: runId ?? latestDecision?.runId ?? null,
428
- taskId: latestDecision?.taskId ?? null
429
- });
430
- const statusesByKind = Object.fromEntries(decisions.map((decision) => [decision.decisionKind, decision.status])) as WorkflowGateHealthProjection['statusesByKind'];
431
- return {
432
- decisions: decisions.length,
433
- blocked: decisions.filter((decision) => decision.status === 'BLOCKED').length,
434
- warnings: decisions.filter((decision) => decision.status === 'WARN').length,
435
- humanRequired: decisions.filter((decision) => decision.humanRequired).length,
436
- latestDecision,
437
- statusesByKind,
438
- evidenceSelection: workflowGateEvidenceSelection(latestDecision, artifactPayloads)
439
- };
440
- }
441
-
442
- const NON_CONSUMABLE_EVIDENCE_STATUSES = ['partial', 'active_attempt', 'rejected', 'superseded', 'quarantined', 'stale'] as const;
443
-
444
- function workflowGateEvidenceSelection(latestDecision: WorkflowGateDecision | null, payloads: RuntimeArtifactPayloadRecord[]): WorkflowGateEvidenceSelectionProjection {
445
- const binding = gateEvidenceBindingPayload(latestDecision);
446
- const ignoredRefs = payloads.filter((payload) => NON_CONSUMABLE_EVIDENCE_STATUSES.includes(payload.status as (typeof NON_CONSUMABLE_EVIDENCE_STATUSES)[number])).map(payloadSelectionRef);
447
- return {
448
- source: gateEvidenceSelectionSource(binding?.source),
449
- selectionPointerRef: readNullableString(binding?.selectionPointerRef),
450
- acceptedEvidenceSetRef: readNullableString(binding?.acceptedEvidenceSetRef),
451
- selectedRefs: readSelectionRefs(binding?.selectedRefs),
452
- blockedRefs: readStringArray(binding?.blockedRefs),
453
- ignoredRefs,
454
- ignoredCounts: ignoredEvidenceCounts(payloads),
455
- selectionReasons: readStringArray(binding?.selectionReasons),
456
- reasons: readStringArray(binding?.reasons)
457
- };
458
- }
459
-
460
- function ignoredEvidenceCounts(payloads: RuntimeArtifactPayloadRecord[]): WorkflowGateEvidenceSelectionProjection['ignoredCounts'] {
461
- return {
462
- partial: payloads.filter((payload) => payload.status === 'partial').length,
463
- active_attempt: payloads.filter((payload) => payload.status === 'active_attempt').length,
464
- rejected: payloads.filter((payload) => payload.status === 'rejected').length,
465
- superseded: payloads.filter((payload) => payload.status === 'superseded').length,
466
- quarantined: payloads.filter((payload) => payload.status === 'quarantined').length,
467
- stale: payloads.filter((payload) => payload.status === 'stale').length
468
- };
469
- }
470
-
471
- function gateEvidenceBindingPayload(latestDecision: WorkflowGateDecision | null): Record<string, unknown> | null {
472
- if (!latestDecision || !isRecord(latestDecision.payload)) {
473
- return null;
474
- }
475
- const binding = latestDecision.payload.evidenceBinding;
476
- return isRecord(binding) ? binding : null;
477
- }
478
-
479
- function gateEvidenceSelectionSource(value: unknown): WorkflowGateEvidenceSelectionSource {
480
- return value === 'selection_pointer' || value === 'candidate_payloads' || value === 'legacy_active_payloads' || value === 'none' ? value : 'unknown';
481
- }
482
-
483
- function readSelectionRefs(value: unknown): WorkflowGateEvidenceSelectionRef[] {
484
- if (!Array.isArray(value)) {
485
- return [];
486
- }
487
- return value.filter(isRecord).map((item) => ({
488
- payloadId: readNullableString(item.payloadId),
489
- logicalRef: readNullableString(item.logicalRef) ?? 'unknown',
490
- digest: readNullableString(item.digest),
491
- status: readNullableString(item.status)
492
- }));
493
- }
494
-
495
- function readStringArray(value: unknown): string[] {
496
- return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
497
- }
498
-
499
- function readNullableString(value: unknown): string | null {
500
- return typeof value === 'string' && value.length > 0 ? value : null;
501
- }
502
-
503
- function payloadSelectionRef(payload: RuntimeArtifactPayloadRecord): WorkflowGateEvidenceSelectionRef {
504
- return {
505
- payloadId: payload.payloadId,
506
- logicalRef: payload.logicalRef,
507
- digest: payload.digest,
508
- status: payload.status
509
- };
510
- }
511
-
512
- function summarizeTaskRisk(tasks: Array<Parameters<typeof buildTaskRiskProfile>[0]>): TaskRiskSummary {
513
- const entries = tasks.map((task) => ({ taskId: task?.id ?? null, profile: buildTaskRiskProfile(task) }));
514
- return {
515
- highRiskTasks: entries.filter(({ profile }) => profile.riskLevel === 'high').map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
516
- mediumRiskTasks: entries.filter(({ profile }) => profile.riskLevel === 'medium').map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
517
- sourceBoundaryTasks: entries.filter(({ profile }) => profile.sourceBoundary).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
518
- contextRiskTasks: entries.filter(({ profile }) => profile.contextRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
519
- tokenRiskTasks: entries.filter(({ profile }) => profile.tokenRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
520
- performanceRiskTasks: entries.filter(({ profile }) => profile.performanceRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort()
521
- };
522
- }
523
-
524
- function taskHealth(status: ProjectStatus): StatuslineProjection['taskHealth'] {
525
- if (status.tasks.total === 0) {
526
- return 'empty';
527
- }
528
- if (status.tasks.blocked > 0 || status.gaps.some((gap) => gap.severity === 'blocking') || status.durableGaps.some((gap) => gap.severity === 'blocking') || status.dependencyBlockers.length > 0) {
529
- return 'blocked';
530
- }
531
- if (status.tasks.completed === status.tasks.total) {
532
- return 'complete';
533
- }
534
- return 'active';
535
- }
536
-
537
- function testHealth(status: ProjectStatus): StatuslineProjection['testHealth'] {
538
- if (!status.latestRun) {
539
- return 'none';
540
- }
541
- if (status.latestRun.validationStatus === 'pass') {
542
- return 'pass';
543
- }
544
- if (status.latestRun.validationStatus === 'pass_with_gaps') {
545
- return 'warn';
546
- }
547
- return 'blocked';
548
- }
549
-
550
- function evidenceHealth(status: ProjectStatus, runtimeHealth: StatuslineProjection['runtimeHealth']): StatuslineProjection['evidenceHealth'] {
551
- if (!status.latestRunEvidence) {
552
- return 'none';
553
- }
554
- if (status.latestRunStaleReasons.length > 0 || status.affectedFileConflicts.length > 0 || status.latestRunEvidence.staleWorkerRuntimes > 0) {
555
- return 'blocked';
556
- }
557
- if (runtimeHealth === 'blocked' || status.latestRunEvidence.tasksChangedAfterRun) {
558
- return 'warn';
559
- }
560
- return 'pass';
561
- }
562
-
563
- async function inspectCapabilityHealth(projectRoot: string, branch: string, latestRunId: string | null, tasks: SddTaskModel['tasks']): Promise<CapabilityHealthProjection> {
564
- try {
565
- const [catalog, runtimeValidation, testRuns, adoptionRecords] = await Promise.all([
566
- inspectAgentCapabilityCatalog(projectRoot),
567
- validateAgentSkillTeamRuntime(projectRoot),
568
- latestRunId ? listRuntimeTestRuns(projectRoot, latestRunId) : Promise.resolve([]),
569
- listRuntimeCapabilityAdoptions(projectRoot, { branchSlug: branch })
570
- ]);
571
- const baselineDomains = uniqueSorted(catalog.capabilities
572
- .filter((capability) => capability.domainGroup === 'professional' && capability.provenance.sourceId === 'sdd_professional_baseline')
573
- .map((capability) => capability.domain)) as ProfessionalCapabilityDomain[];
574
- const missingBaselineDomains = REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS.filter((domain) => !baselineDomains.includes(domain));
575
- const latestEvidence = capabilityEvidenceFromTestRuns(testRuns.map((run) => run.payload));
576
- const acceptedProfessionalEvidence = latestEvidence.filter((item) => item.source === 'professional_capability' && item.class === 'accepted');
577
- const releaseCriticalAdoptions = releaseCriticalCapabilityAdoptions(adoptionRecords);
578
- const activeDomains = uniqueSorted([
579
- ...acceptedProfessionalEvidence.map((item) => item.domainOrSourceId),
580
- ...releaseCriticalAdoptions.map((record) => record.capabilityDomain)
581
- ]) as AgentCapabilityDomain[];
582
- const activePacks = uniqueSorted(catalog.materialPacks
583
- .filter((pack) => pack.domains.some((domain) => activeDomains.includes(domain)))
584
- .map((pack) => pack.id));
585
- const sources = runtimeValidation.inspection.capabilitySources;
586
- const releaseCriticalGaps = releaseCriticalCapabilityGaps(tasks, acceptedProfessionalEvidence, releaseCriticalAdoptions);
587
- const blocked = missingBaselineDomains.length > 0 || !runtimeValidation.valid || releaseCriticalGaps.length > 0;
588
- const noEvidence = latestRunId !== null && latestEvidence.length === 0;
589
- const warnings = [
590
- ...missingBaselineDomains.map((domain) => `missing baseline professional domain ${domain}`),
591
- ...runtimeValidation.issues.map((issue) => issue.message),
592
- ...noCapabilityEvidenceWarnings(noEvidence),
593
- ...releaseCriticalGaps.map((domain) => `release-critical capability gap ${domain}`)
594
- ];
595
- return {
596
- status: blocked ? 'blocked' : warnings.length > 0 ? 'warn' : 'pass',
597
- requiredProfessionalDomains: [...REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS],
598
- baselineDomains,
599
- missingBaselineDomains,
600
- materialPacks: catalog.materialPacks.length,
601
- activeDomains,
602
- activePacks,
603
- sources: {
604
- total: sources.length,
605
- quarantined: sources.filter((source) => source.quarantineRequired || source.quarantineStatus === 'quarantined').length,
606
- denied: sources.filter((source) => source.quarantineStatus === 'denied').length,
607
- futureAdapters: sources.filter((source) => source.hostCompatibility.some((item) => item.includes('future_adapter'))).length
608
- },
609
- evidence: capabilityEvidenceCounts(latestEvidence),
610
- adoptions: capabilityAdoptionCounts(adoptionRecords, releaseCriticalAdoptions),
611
- releaseCriticalGaps,
612
- warnings: uniqueSorted(warnings),
613
- reasons: capabilityHealthReasons(latestRunId, latestEvidence.length, blocked, warnings.length)
614
- };
615
- } catch (error) {
616
- return {
617
- status: 'absent',
618
- requiredProfessionalDomains: [...REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS],
619
- baselineDomains: [],
620
- missingBaselineDomains: [],
621
- materialPacks: 0,
622
- activeDomains: [],
623
- activePacks: [],
624
- sources: { total: 0, quarantined: 0, denied: 0, futureAdapters: 0 },
625
- evidence: { accepted: 0, candidate: 0, quarantined: 0, diagnostic: 0, blocked: 0 },
626
- adoptions: { adopted: 0, rejected: 0, unresolved: 0, acceptedAuthority: 0, releaseCriticalClosures: [] },
627
- warnings: [],
628
- releaseCriticalGaps: [],
629
- reasons: [`capability health unavailable: ${error instanceof Error ? error.message : String(error)}`]
630
- };
631
- }
632
- }
633
-
634
- function capabilityEvidenceFromTestRuns(payloads: unknown[]): CapabilityEvidenceClassification[] {
635
- return payloads.flatMap((payload) => isRecord(payload) && Array.isArray(payload.capabilityEvidence)
636
- ? payload.capabilityEvidence.filter(isCapabilityEvidenceClassification)
637
- : []);
638
- }
639
-
640
- function isCapabilityEvidenceClassification(value: unknown): value is CapabilityEvidenceClassification {
641
- return isRecord(value)
642
- && (value.class === 'accepted' || value.class === 'candidate' || value.class === 'quarantined' || value.class === 'diagnostic' || value.class === 'blocked')
643
- && (value.source === 'professional_capability' || value.source === 'external_source' || value.source === 'runtime_diagnostic')
644
- && typeof value.domainOrSourceId === 'string';
645
- }
646
-
647
- function capabilityEvidenceCounts(evidence: CapabilityEvidenceClassification[]): CapabilityHealthProjection['evidence'] {
648
- return {
649
- accepted: evidence.filter((item) => item.class === 'accepted').length,
650
- candidate: evidence.filter((item) => item.class === 'candidate').length,
651
- quarantined: evidence.filter((item) => item.class === 'quarantined').length,
652
- diagnostic: evidence.filter((item) => item.class === 'diagnostic').length,
653
- blocked: evidence.filter((item) => item.class === 'blocked').length
654
- };
655
- }
656
-
657
- function releaseCriticalCapabilityGaps(tasks: SddTaskModel['tasks'], acceptedProfessionalEvidence: CapabilityEvidenceClassification[], releaseCriticalAdoptions: RuntimeCapabilityAdoptionRecord[]): ProfessionalCapabilityDomain[] {
658
- const required = releaseCriticalDomainsForTasks(tasks);
659
- const acceptedEvidenceDomains = new Set(acceptedProfessionalEvidence.map((item) => item.domainOrSourceId));
660
- const adoptedDomains = new Set(releaseCriticalAdoptions.map((record) => record.capabilityDomain));
661
- return required.filter((domain) => !acceptedEvidenceDomains.has(domain) && !adoptedDomains.has(domain));
662
- }
663
-
664
- function releaseCriticalCapabilityAdoptions(records: RuntimeCapabilityAdoptionRecord[]): RuntimeCapabilityAdoptionRecord[] {
665
- return records.filter((record) => (record.status === 'adopted' || record.status === 'rejected')
666
- && record.reason.trim().length > 0
667
- && (record.finalAuthority === 'sdd_contract' || record.finalAuthority === 'sdd_gate')
668
- && isRequiredProfessionalDomain(record.capabilityDomain));
669
- }
670
-
671
- function capabilityAdoptionCounts(records: RuntimeCapabilityAdoptionRecord[], releaseCriticalAdoptions: RuntimeCapabilityAdoptionRecord[]): CapabilityHealthProjection['adoptions'] {
672
- return {
673
- adopted: records.filter((record) => record.status === 'adopted').length,
674
- rejected: records.filter((record) => record.status === 'rejected').length,
675
- unresolved: records.filter((record) => record.status === 'unresolved').length,
676
- acceptedAuthority: records.filter((record) => record.finalAuthority === 'sdd_contract' || record.finalAuthority === 'sdd_gate').length,
677
- releaseCriticalClosures: uniqueSorted(releaseCriticalAdoptions.map((record) => record.capabilityDomain).filter(isRequiredProfessionalDomain))
678
- };
679
- }
680
-
681
-
682
- function releaseCriticalDomainsForTasks(tasks: SddTaskModel['tasks']): ProfessionalCapabilityDomain[] {
683
- const domains = new Set<ProfessionalCapabilityDomain>();
684
- for (const task of tasks) {
685
- const text = [task.title ?? '', ...task.risk, ...task.affectedFiles, ...task.validation, ...task.acceptance, task.boundary ?? ''].join('\n').toLowerCase();
686
- if (/security|auth|permission|secret|token|安全/.test(text)) {
687
- domains.add('security-engineering');
688
- }
689
- if (/performance|latency|throughput|benchmark|capacity|性能/.test(text)) {
690
- domains.add('performance-engineering');
691
- }
692
- if (/observability|logging|metrics|tracing|diagnostic|可观测/.test(text)) {
693
- domains.add('observability-engineering');
694
- }
695
- if (/release|deploy|rollback|ci|ship|发布/.test(text)) {
696
- domains.add('release-engineering');
697
- }
698
- if (/database|schema|migration|query|data|db|数据/.test(text)) {
699
- domains.add('db-data-engineering');
700
- }
701
- if (/ui|ux|frontend|browser|figma|accessibility|交互|前端/.test(text)) {
702
- domains.add(text.includes('frontend') || text.includes('browser') || text.includes('前端') ? 'frontend-engineering' : 'ui-ux-product-design');
703
- }
704
- }
705
- return [...domains].sort((left, right) => left.localeCompare(right));
706
- }
707
-
708
- function isRequiredProfessionalDomain(domain: string): domain is ProfessionalCapabilityDomain {
709
- return REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS.includes(domain as ProfessionalCapabilityDomain);
710
- }
711
-
712
- function noCapabilityEvidenceWarnings(noEvidence: boolean): string[] {
713
- return noEvidence ? ['latest run has no capability evidence classification'] : [];
714
- }
715
-
716
- function capabilityHealthReasons(latestRunId: string | null, evidenceCount: number, blocked: boolean, warnings: number): string[] {
717
- if (blocked) {
718
- return ['Capability catalog, runtime source validation, or release-critical adoption has blocking issues.'];
719
- }
720
- if (latestRunId !== null && evidenceCount === 0) {
721
- return ['Latest run has no recorded capability evidence classification.'];
722
- }
723
- if (warnings > 0) {
724
- return ['Capability health has warnings; inspect status JSON for exact missing evidence or release-critical adoption state.'];
725
- }
726
- return ['Professional capability baseline, source policy, and release-critical adoption are visible.'];
727
- }
728
-
729
- function isRecord(value: unknown): value is Record<string, unknown> {
730
- return Boolean(value) && typeof value === 'object';
731
- }
732
-
733
- function uniqueSorted<T extends string>(values: T[]): T[] {
734
- return [...new Set(values)].sort((left, right) => left.localeCompare(right));
735
- }
736
-
737
- async function inspectTokenRuntimeProjection(projectRoot: string): Promise<TokenRuntimeProjection> {
738
- const projections = await listRuntimeProjections(projectRoot, ['context_build', 'team_runtime_decision']);
739
- const contextPackages = projections.filter((projection) => projection.projectionType === 'context_build');
740
- const teamRuntimeDecisions = projections.filter((projection) => projection.projectionType === 'team_runtime_decision');
741
- const contextTokenEstimates = contextPackages.map((projection) => tokenEstimateFromContextBuildPayload(projection.payload)).filter((value): value is number => value !== null);
742
- const teamTokenEstimates = teamRuntimeDecisions.map((projection) => tokenEstimateFromTeamRuntimePayload(projection.payload)).filter((value): value is number => value !== null);
743
- const estimatedTokens = [...contextTokenEstimates, ...teamTokenEstimates].reduce((total, value) => total + value, 0);
744
- const pressureReasons = [
745
- ...contextPackages.map((projection) => contextPressureReason(projection.payload)).filter((value): value is string => value !== null),
746
- ...teamRuntimeDecisions.map((projection) => teamPressureReason(projection.payload)).filter((value): value is string => value !== null)
747
- ];
748
-
749
- return {
750
- health: projections.length === 0 ? 'unknown' : pressureReasons.length > 0 ? 'pressure' : 'nominal',
751
- estimatedTokens: projections.length === 0 ? null : estimatedTokens,
752
- contextPackages: contextPackages.length,
753
- teamRuntimeDecisions: teamRuntimeDecisions.length,
754
- pressureReasons
755
- };
756
- }
757
-
758
- function tokenEstimateFromContextBuildPayload(payload: unknown): number | null {
759
- if (!payload || typeof payload !== 'object') {
760
- return null;
761
- }
762
- const budget = (payload as { budget?: { estimatedTokens?: unknown } }).budget;
763
- return typeof budget?.estimatedTokens === 'number' ? budget.estimatedTokens : null;
764
- }
765
-
766
- function tokenEstimateFromTeamRuntimePayload(payload: unknown): number | null {
767
- if (!payload || typeof payload !== 'object') {
768
- return null;
769
- }
770
- const decision = payload as { roleIds?: unknown; telemetryPolicy?: { contextBudget?: unknown } | null };
771
- const roleCount = Array.isArray(decision.roleIds) ? decision.roleIds.length : 0;
772
- const contextBudget = decision.telemetryPolicy?.contextBudget;
773
- const perRole = contextBudget === 'medium' ? 3000 : contextBudget === 'small' ? 1200 : 600;
774
- return roleCount * perRole;
775
- }
776
-
777
- function contextPressureReason(payload: unknown): string | null {
778
- if (!payload || typeof payload !== 'object') {
779
- return null;
780
- }
781
- const contextPackage = payload as { taskId?: unknown; profile?: unknown; budget?: { estimatedBytes?: unknown; maxBytes?: unknown } };
782
- const estimatedBytes = contextPackage.budget?.estimatedBytes;
783
- const maxBytes = contextPackage.budget?.maxBytes;
784
- if (contextPackage.profile === 'brief') {
785
- return null;
786
- }
787
- if (typeof estimatedBytes === 'number' && typeof maxBytes === 'number' && estimatedBytes >= maxBytes * 0.85) {
788
- return `context_budget_pressure:${String(contextPackage.taskId ?? 'unknown')}`;
789
- }
790
- return null;
791
- }
792
-
793
- function teamPressureReason(payload: unknown): string | null {
794
- if (!payload || typeof payload !== 'object') {
795
- return null;
796
- }
797
- const decision = payload as { command?: unknown; mode?: unknown; roleIds?: unknown };
798
- const roleCount = Array.isArray(decision.roleIds) ? decision.roleIds.length : 0;
799
- if (decision.mode === 'team-required' || roleCount > 2) {
800
- return `team_runtime_pressure:${String(decision.command ?? 'unknown')}`;
801
- }
802
- return null;
803
- }
804
-
805
- async function inspectRunEvidenceSummary(projectRoot: string, runId: string): Promise<RunEvidenceSummary> {
806
- const [state, events, agentExecutions, teamSessions, workerRuntimeList] = await Promise.all([
807
- readRunState(projectRoot, runId),
808
- readRunEvents(projectRoot, runId),
809
- listAgentExecutionRecords(projectRoot, runId),
810
- listTeamSessionRecords(projectRoot, runId),
811
- listResidentWorkerRuntimes(projectRoot, { runId })
812
- ]);
813
- return {
814
- agentExecutions: agentExecutions.length,
815
- teamSessions: teamSessions.length,
816
- artifactIngestions: Object.keys(state.artifactIngestions ?? {}).length,
817
- workerRuntimes: workerRuntimeList.runtimes.length,
818
- staleWorkerRuntimes: workerRuntimeList.staleRuntimes,
819
- routePreflight: events.some((event) => event.event === 'agent_router_preflight'),
820
- tasksChangedAfterRun: false,
821
- tasksUpdatedAt: null,
822
- runUpdatedAt: state.updatedAt ?? null
823
- };
824
- }
825
-
826
- async function addTaskDocumentStalenessToRunEvidence(tasksPath: string, latestRun: RunSummary, evidence: RunEvidenceSummary): Promise<RunEvidenceSummary> {
827
- try {
828
- const tasksStat = await stat(tasksPath);
829
- const runUpdatedAtMs = Date.parse(latestRun.updatedAt);
830
- if (Number.isNaN(runUpdatedAtMs)) {
831
- return { ...evidence, runUpdatedAt: latestRun.updatedAt };
832
- }
833
- return {
834
- ...evidence,
835
- tasksChangedAfterRun: tasksStat.mtimeMs > runUpdatedAtMs,
836
- tasksUpdatedAt: tasksStat.mtime.toISOString(),
837
- runUpdatedAt: latestRun.updatedAt
838
- };
839
- } catch {
840
- return { ...evidence, runUpdatedAt: latestRun.updatedAt };
841
- }
842
- }
843
-
844
- async function getGitRoot(projectRoot: string): Promise<string | null> {
845
- try {
846
- const result = await execFileAsync('git', ['-C', projectRoot, 'rev-parse', '--show-toplevel']);
847
- return result.stdout.trim();
848
- } catch {
849
- return null;
850
- }
851
- }
1
+ import { execFile } from 'node:child_process';
2
+ import { stat } from 'node:fs/promises';
3
+ import { promisify } from 'node:util';
4
+ import type { ContextBranchSource, ContextResolverContract } from '../sdd-docs/context.js';
5
+ import type { SddTaskGap, SddTaskModel } from '../sdd-docs/task-parser.js';
6
+ import type { RunState, RunSummary } from '../run-state/model.js';
7
+ import { readRunEvents } from '../run-state/events.js';
8
+ import { readRunState } from '../run-state/run-state.js';
9
+ import { listAgentExecutionRecords, listTeamSessionRecords } from '../execution/agent-execution-records.js';
10
+ import { listResidentWorkerRuntimes } from '../execution/resident-worker.js';
11
+ import { resolveWorkflowState, type WorkflowLatestTaskRun, type WorkflowNextIntent } from '../workflow-state/resolve.js';
12
+ import type { WorkflowAffectedFileConflict } from '../workflow-state/affected-file-conflicts.js';
13
+ import type { WorkflowDependencyBlocker } from '../workflow-state/dependencies.js';
14
+ import type { LatestEligibleRunSelection } from '../workflow-state/latest-eligible-run.js';
15
+ import { buildTaskRiskProfile } from '../task-risk-profile.js';
16
+ import { listRuntimeProjections } from '../storage/runtime-store.js';
17
+ import { inspectLifecycleRiskDecisionForModel, type LifecycleRiskConsumerDiagnostic } from '../risk.js';
18
+ import { inspectWorkflowStageHandoff, type WorkflowStageHandoffDiagnostic } from '../stage-runtime.js';
19
+ import { inspectContextOffloadRuntime, type ContextRuntimeDiagnostic } from '../context-offload.js';
20
+ import { inspectSubagentDispatches, type SubagentDispatchDiagnostic } from '../subagents.js';
21
+ import { inspectAgentCapabilityCatalog, REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS, type AgentCapabilityDomain, type ProfessionalCapabilityDomain } from '../registries/agent-capability-catalog.js';
22
+ import { validateAgentSkillTeamRuntime } from '../router/runtime-validation.js';
23
+ import { listRuntimeDurableGaps, listRuntimeFanInEvidenceSets, listRuntimeLlmAdvisorAssessments, listRuntimeStageRoleResults, listRuntimeStageTeamSessions, listRuntimeTestRuns, listRuntimeWorkflowGateDecisions, type RuntimeDurableGapRecord } from '../storage/runtime-store.js';
24
+ import type { CapabilityEvidenceClassification } from '../evidence-runtime.js';
25
+ import type { WorkflowGateDecision, WorkflowGateDecisionKind } from '../workflow-gate/types.js';
26
+
27
+ const execFileAsync = promisify(execFile);
28
+
29
+ export interface RunEvidenceSummary {
30
+ agentExecutions: number;
31
+ teamSessions: number;
32
+ artifactIngestions: number;
33
+ workerRuntimes: number;
34
+ staleWorkerRuntimes: number;
35
+ routePreflight: boolean;
36
+ tasksChangedAfterRun: boolean;
37
+ tasksUpdatedAt: string | null;
38
+ runUpdatedAt: string | null;
39
+ }
40
+
41
+ export interface TaskRiskSummary {
42
+ highRiskTasks: string[];
43
+ mediumRiskTasks: string[];
44
+ sourceBoundaryTasks: string[];
45
+ contextRiskTasks: string[];
46
+ tokenRiskTasks: string[];
47
+ performanceRiskTasks: string[];
48
+ }
49
+
50
+ export interface TokenRuntimeProjection {
51
+ health: 'unknown' | 'nominal' | 'pressure';
52
+ estimatedTokens: number | null;
53
+ contextPackages: number;
54
+ teamRuntimeDecisions: number;
55
+ pressureReasons: string[];
56
+ }
57
+
58
+ export type CapabilityHealthStatus = 'absent' | 'pass' | 'warn' | 'blocked';
59
+
60
+ export interface CapabilityHealthProjection {
61
+ status: CapabilityHealthStatus;
62
+ requiredProfessionalDomains: ProfessionalCapabilityDomain[];
63
+ baselineDomains: ProfessionalCapabilityDomain[];
64
+ missingBaselineDomains: ProfessionalCapabilityDomain[];
65
+ materialPacks: number;
66
+ activeDomains: AgentCapabilityDomain[];
67
+ activePacks: string[];
68
+ sources: {
69
+ total: number;
70
+ quarantined: number;
71
+ denied: number;
72
+ futureAdapters: number;
73
+ };
74
+ evidence: {
75
+ accepted: number;
76
+ candidate: number;
77
+ quarantined: number;
78
+ diagnostic: number;
79
+ blocked: number;
80
+ };
81
+ warnings: string[];
82
+ releaseCriticalGaps: ProfessionalCapabilityDomain[];
83
+ reasons: string[];
84
+ }
85
+
86
+ export interface StageTeamHealthProjection {
87
+ sessions: number;
88
+ roleResults: number;
89
+ advisorAssessments: number;
90
+ fanInEvidenceSets: number;
91
+ highConcernAdvisors: number;
92
+ lifecycleProfiles: string[];
93
+ directProfileRequiresNoTeam: boolean;
94
+ }
95
+
96
+ export interface WorkflowGateHealthProjection {
97
+ decisions: number;
98
+ blocked: number;
99
+ warnings: number;
100
+ humanRequired: number;
101
+ latestDecision: WorkflowGateDecision | null;
102
+ statusesByKind: Partial<Record<WorkflowGateDecisionKind, WorkflowGateDecision['status']>>;
103
+ }
104
+
105
+ export interface ProjectStatus {
106
+ branch: string;
107
+ workflowStatus: 'active' | 'not_started';
108
+ context: ContextResolverContract;
109
+ gitRoot: string | null;
110
+ documents: SddTaskModel['documents'];
111
+ tasks: {
112
+ total: number;
113
+ pending: number;
114
+ inProgress: number;
115
+ completed: number;
116
+ blocked: number;
117
+ deferred: number;
118
+ unknown: number;
119
+ gaps: number;
120
+ };
121
+ taskRisk: TaskRiskSummary;
122
+ latestRun: RunSummary | null;
123
+ latestRunsByTask: WorkflowLatestTaskRun[];
124
+ latestEligibleRunsByTask: LatestEligibleRunSelection[];
125
+ latestRunEvidence: RunEvidenceSummary | null;
126
+ latestRunStaleReasons: string[];
127
+ affectedFileConflicts: WorkflowAffectedFileConflict[];
128
+ dependencyBlockers: WorkflowDependencyBlocker[];
129
+ recommendedNextCommand: string;
130
+ nextIntent: WorkflowNextIntent;
131
+ tokenProjection: TokenRuntimeProjection;
132
+ contextRuntime: ContextRuntimeDiagnostic;
133
+ subagentDispatches: SubagentDispatchDiagnostic;
134
+ lifecycleRisk: LifecycleRiskConsumerDiagnostic;
135
+ capabilityHealth: CapabilityHealthProjection;
136
+ workflowHandoff: WorkflowStageHandoffDiagnostic;
137
+ gaps: SddTaskGap[];
138
+ durableGaps: RuntimeDurableGapRecord[];
139
+ stageTeamHealth: StageTeamHealthProjection;
140
+ workflowGateHealth: WorkflowGateHealthProjection;
141
+ }
142
+
143
+ export interface StatuslineProjection {
144
+ contract: 'sdd-statusline-projection-v1';
145
+ branch: string;
146
+ workflow: ProjectStatus['workflowStatus'];
147
+ taskHealth: 'empty' | 'active' | 'blocked' | 'complete';
148
+ runtimeHealth: 'none' | 'pass' | 'warn' | 'blocked';
149
+ testHealth: 'none' | 'pass' | 'warn' | 'blocked';
150
+ teamHealth: 'none' | 'active';
151
+ tokenHealth: 'unknown' | 'nominal' | 'pressure';
152
+ contextLoad: ProjectStatus['contextRuntime']['level'];
153
+ contextAction: ProjectStatus['contextRuntime']['action'];
154
+ subagentHealth: ProjectStatus['subagentDispatches']['status'];
155
+ evidenceHealth: 'none' | 'pass' | 'warn' | 'blocked';
156
+ capabilityHealth: ProjectStatus['capabilityHealth']['status'];
157
+ latestRunId: string | null;
158
+ counts: {
159
+ tasks: ProjectStatus['tasks'];
160
+ agentExecutions: number;
161
+ teamSessions: number;
162
+ workerRuntimes: number;
163
+ staleWorkerRuntimes: number;
164
+ artifactIngestions: number;
165
+ staleReasons: number;
166
+ affectedFileConflicts: number;
167
+ subagentDispatches: number;
168
+ blockingSubagents: number;
169
+ capabilityWarnings: number;
170
+ durableGaps: number;
171
+ stageTeamSessions: number;
172
+ stageRoleResults: number;
173
+ advisorAssessments: number;
174
+ fanInEvidenceSets: number;
175
+ workflowGateDecisions: number;
176
+ };
177
+ taskRisk: TaskRiskSummary;
178
+ next: string;
179
+ }
180
+
181
+ export async function getProjectStatus(projectRoot: string, options: { branch?: string | null; branchSource?: ContextBranchSource } = {}): Promise<ProjectStatus> {
182
+ const [workflow, gitRoot] = await Promise.all([resolveWorkflowState(projectRoot, options), getGitRoot(projectRoot)]);
183
+ const latestRun = workflow.latestRun;
184
+ const latestRunState = workflow.latestRunState;
185
+ const latestRunEvidence = latestRun ? await inspectRunEvidenceSummary(projectRoot, latestRun.runId) : null;
186
+ const enrichedLatestRunEvidence = latestRun && latestRunEvidence
187
+ ? await addTaskDocumentStalenessToRunEvidence(workflow.model.tasksPath, latestRun, latestRunEvidence)
188
+ : latestRunEvidence;
189
+ const latestRunStaleReasons = latestRunState ? await runDocumentStaleReasons(projectRoot, latestRunState, workflow.model) : [];
190
+ const taskRisk = summarizeTaskRisk(workflow.model.tasks);
191
+ const tokenProjection = await inspectTokenRuntimeProjection(projectRoot);
192
+ const lifecycleRisk = await inspectLifecycleRiskDecisionForModel(projectRoot, workflow.branch, workflow.model);
193
+ const workflowHandoff = await inspectWorkflowStageHandoff(projectRoot, workflow.branch);
194
+ const contextRuntime = await inspectContextOffloadRuntime(projectRoot, workflow.branch);
195
+ const subagentDispatches = await inspectSubagentDispatches(projectRoot, workflow.branch);
196
+ const capabilityHealth = await inspectCapabilityHealth(projectRoot, latestRun?.runId ?? null, workflow.model.tasks);
197
+ const durableGaps = await listRuntimeDurableGaps(projectRoot, { partition: workflow.branch, status: 'open_terminal' });
198
+ const stageTeamHealth = await inspectStageTeamHealth(projectRoot, workflow.branch, latestRun?.runId ?? null);
199
+ const workflowGateHealth = await inspectWorkflowGateHealth(projectRoot, workflow.branch, latestRun?.runId ?? null);
200
+
201
+ return {
202
+ branch: workflow.branch,
203
+ workflowStatus: workflow.workflowStatus,
204
+ context: workflow.context,
205
+ gitRoot,
206
+ documents: workflow.documents,
207
+ tasks: workflow.taskCounts,
208
+ taskRisk,
209
+ latestRun,
210
+ latestRunsByTask: workflow.latestRunsByTask,
211
+ latestEligibleRunsByTask: workflow.latestEligibleRunsByTask,
212
+ latestRunEvidence: enrichedLatestRunEvidence,
213
+ latestRunStaleReasons,
214
+ affectedFileConflicts: workflow.affectedFileConflicts,
215
+ dependencyBlockers: workflow.dependencyBlockers,
216
+ recommendedNextCommand: workflow.recommendedNextCommand,
217
+ nextIntent: workflow.nextIntent,
218
+ tokenProjection,
219
+ contextRuntime,
220
+ subagentDispatches,
221
+ lifecycleRisk,
222
+ workflowHandoff,
223
+ capabilityHealth,
224
+ gaps: workflow.visibleGaps,
225
+ durableGaps,
226
+ stageTeamHealth,
227
+ workflowGateHealth
228
+ };
229
+ }
230
+
231
+ export async function getStatuslineProjection(projectRoot: string, options: { branch?: string | null; branchSource?: ContextBranchSource } = {}): Promise<StatuslineProjection> {
232
+ return statuslineProjectionFromStatus(await getProjectStatus(projectRoot, options));
233
+ }
234
+
235
+ export function statuslineProjectionFromStatus(status: ProjectStatus): StatuslineProjection {
236
+ const evidence = status.latestRunEvidence;
237
+ const runtimeHealth = status.latestRun
238
+ ? status.latestRun.status === 'completed' && status.latestRun.validationStatus === 'pass' ? 'pass' : 'blocked'
239
+ : 'none';
240
+ const staleReasons = status.latestRunStaleReasons.length;
241
+ const affectedFileConflicts = status.affectedFileConflicts.length;
242
+ return {
243
+ contract: 'sdd-statusline-projection-v1',
244
+ branch: status.branch,
245
+ workflow: status.workflowStatus,
246
+ taskHealth: taskHealth(status),
247
+ runtimeHealth,
248
+ testHealth: testHealth(status),
249
+ teamHealth: (evidence?.teamSessions ?? 0) > 0 || status.stageTeamHealth.sessions > 0 || status.stageTeamHealth.roleResults > 0 ? 'active' : 'none',
250
+ tokenHealth: status.tokenProjection.health,
251
+ contextLoad: status.contextRuntime.level,
252
+ contextAction: status.contextRuntime.action,
253
+ subagentHealth: status.subagentDispatches.status,
254
+ evidenceHealth: evidenceHealth(status, runtimeHealth),
255
+ capabilityHealth: status.capabilityHealth.status,
256
+ latestRunId: status.latestRun?.runId ?? null,
257
+ counts: {
258
+ tasks: status.tasks,
259
+ agentExecutions: evidence?.agentExecutions ?? 0,
260
+ teamSessions: evidence?.teamSessions ?? 0,
261
+ workerRuntimes: evidence?.workerRuntimes ?? 0,
262
+ staleWorkerRuntimes: evidence?.staleWorkerRuntimes ?? 0,
263
+ artifactIngestions: evidence?.artifactIngestions ?? 0,
264
+ staleReasons,
265
+ affectedFileConflicts,
266
+ subagentDispatches: status.subagentDispatches.dispatches,
267
+ blockingSubagents: status.subagentDispatches.blockingOpen,
268
+ capabilityWarnings: status.capabilityHealth.warnings.length,
269
+ durableGaps: status.durableGaps.length,
270
+ stageTeamSessions: status.stageTeamHealth.sessions,
271
+ stageRoleResults: status.stageTeamHealth.roleResults,
272
+ advisorAssessments: status.stageTeamHealth.advisorAssessments,
273
+ fanInEvidenceSets: status.stageTeamHealth.fanInEvidenceSets,
274
+ workflowGateDecisions: status.workflowGateHealth.decisions
275
+ },
276
+ taskRisk: status.taskRisk,
277
+ next: status.recommendedNextCommand
278
+ };
279
+ }
280
+
281
+ async function inspectStageTeamHealth(projectRoot: string, partition: string, runId: string | null): Promise<StageTeamHealthProjection> {
282
+ const query = runId ? { partition, runId } : { partition };
283
+ const [sessions, roleResults, advisorAssessments, fanInEvidenceSets] = await Promise.all([
284
+ listRuntimeStageTeamSessions(projectRoot, query),
285
+ listRuntimeStageRoleResults(projectRoot, query),
286
+ listRuntimeLlmAdvisorAssessments(projectRoot, query),
287
+ listRuntimeFanInEvidenceSets(projectRoot, query)
288
+ ]);
289
+ return {
290
+ sessions: sessions.length,
291
+ roleResults: roleResults.length,
292
+ advisorAssessments: advisorAssessments.length,
293
+ fanInEvidenceSets: fanInEvidenceSets.length,
294
+ highConcernAdvisors: advisorAssessments.filter((assessment) => assessment.concern === 'high').length,
295
+ lifecycleProfiles: [...new Set(sessions.map((session) => session.lifecycleProfile))].sort(),
296
+ directProfileRequiresNoTeam: !sessions.some((session) => session.lifecycleProfile === 'direct' && session.assignments.some((assignment) => assignment.required))
297
+ };
298
+ }
299
+
300
+ async function inspectWorkflowGateHealth(projectRoot: string, partition: string, runId: string | null): Promise<WorkflowGateHealthProjection> {
301
+ const query = runId ? { partition, runId } : { partition };
302
+ const decisions = await listRuntimeWorkflowGateDecisions(projectRoot, query);
303
+ const statusesByKind = Object.fromEntries(decisions.map((decision) => [decision.decisionKind, decision.status])) as WorkflowGateHealthProjection['statusesByKind'];
304
+ return {
305
+ decisions: decisions.length,
306
+ blocked: decisions.filter((decision) => decision.status === 'BLOCKED').length,
307
+ warnings: decisions.filter((decision) => decision.status === 'WARN').length,
308
+ humanRequired: decisions.filter((decision) => decision.humanRequired).length,
309
+ latestDecision: decisions[0] ?? null,
310
+ statusesByKind
311
+ };
312
+ }
313
+
314
+ function summarizeTaskRisk(tasks: Array<Parameters<typeof buildTaskRiskProfile>[0]>): TaskRiskSummary {
315
+ const entries = tasks.map((task) => ({ taskId: task?.id ?? null, profile: buildTaskRiskProfile(task) }));
316
+ return {
317
+ highRiskTasks: entries.filter(({ profile }) => profile.riskLevel === 'high').map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
318
+ mediumRiskTasks: entries.filter(({ profile }) => profile.riskLevel === 'medium').map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
319
+ sourceBoundaryTasks: entries.filter(({ profile }) => profile.sourceBoundary).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
320
+ contextRiskTasks: entries.filter(({ profile }) => profile.contextRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
321
+ tokenRiskTasks: entries.filter(({ profile }) => profile.tokenRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort(),
322
+ performanceRiskTasks: entries.filter(({ profile }) => profile.performanceRisk).map(({ taskId }) => taskId).filter((taskId): taskId is string => Boolean(taskId)).sort()
323
+ };
324
+ }
325
+
326
+ function taskHealth(status: ProjectStatus): StatuslineProjection['taskHealth'] {
327
+ if (status.tasks.total === 0) {
328
+ return 'empty';
329
+ }
330
+ if (status.tasks.blocked > 0 || status.gaps.some((gap) => gap.severity === 'blocking') || status.durableGaps.some((gap) => gap.severity === 'blocking') || status.dependencyBlockers.length > 0) {
331
+ return 'blocked';
332
+ }
333
+ if (status.tasks.completed === status.tasks.total) {
334
+ return 'complete';
335
+ }
336
+ return 'active';
337
+ }
338
+
339
+ function testHealth(status: ProjectStatus): StatuslineProjection['testHealth'] {
340
+ if (!status.latestRun) {
341
+ return 'none';
342
+ }
343
+ if (status.latestRun.validationStatus === 'pass') {
344
+ return 'pass';
345
+ }
346
+ if (status.latestRun.validationStatus === 'pass_with_gaps') {
347
+ return 'warn';
348
+ }
349
+ return 'blocked';
350
+ }
351
+
352
+ function evidenceHealth(status: ProjectStatus, runtimeHealth: StatuslineProjection['runtimeHealth']): StatuslineProjection['evidenceHealth'] {
353
+ if (!status.latestRunEvidence) {
354
+ return 'none';
355
+ }
356
+ if (status.latestRunStaleReasons.length > 0 || status.affectedFileConflicts.length > 0 || status.latestRunEvidence.staleWorkerRuntimes > 0) {
357
+ return 'blocked';
358
+ }
359
+ if (runtimeHealth === 'blocked' || status.latestRunEvidence.tasksChangedAfterRun) {
360
+ return 'warn';
361
+ }
362
+ return 'pass';
363
+ }
364
+
365
+ async function inspectCapabilityHealth(projectRoot: string, latestRunId: string | null, tasks: SddTaskModel['tasks']): Promise<CapabilityHealthProjection> {
366
+ try {
367
+ const [catalog, runtimeValidation, testRuns] = await Promise.all([
368
+ inspectAgentCapabilityCatalog(projectRoot),
369
+ validateAgentSkillTeamRuntime(projectRoot),
370
+ latestRunId ? listRuntimeTestRuns(projectRoot, latestRunId) : Promise.resolve([])
371
+ ]);
372
+ const baselineDomains = uniqueSorted(catalog.capabilities
373
+ .filter((capability) => capability.domainGroup === 'professional' && capability.provenance.sourceId === 'sdd_professional_baseline')
374
+ .map((capability) => capability.domain)) as ProfessionalCapabilityDomain[];
375
+ const missingBaselineDomains = REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS.filter((domain) => !baselineDomains.includes(domain));
376
+ const latestEvidence = capabilityEvidenceFromTestRuns(testRuns.map((run) => run.payload));
377
+ const acceptedProfessionalEvidence = latestEvidence.filter((item) => item.source === 'professional_capability' && item.class === 'accepted');
378
+ const activeDomains = uniqueSorted(acceptedProfessionalEvidence
379
+ .map((item) => item.domainOrSourceId)) as AgentCapabilityDomain[];
380
+ const activePacks = uniqueSorted(catalog.materialPacks
381
+ .filter((pack) => pack.domains.some((domain) => activeDomains.includes(domain)))
382
+ .map((pack) => pack.id));
383
+ const sources = runtimeValidation.inspection.capabilitySources;
384
+ const blocked = missingBaselineDomains.length > 0 || !runtimeValidation.valid;
385
+ const noEvidence = latestRunId !== null && latestEvidence.length === 0;
386
+ const releaseCriticalGaps = releaseCriticalCapabilityGaps(tasks, acceptedProfessionalEvidence);
387
+ const warnings = [
388
+ ...missingBaselineDomains.map((domain) => `missing baseline professional domain ${domain}`),
389
+ ...runtimeValidation.issues.map((issue) => issue.message),
390
+ ...noCapabilityEvidenceWarnings(noEvidence),
391
+ ...releaseCriticalGaps.map((domain) => `release-critical capability gap ${domain}`)
392
+ ];
393
+ return {
394
+ status: blocked ? 'blocked' : warnings.length > 0 ? 'warn' : 'pass',
395
+ requiredProfessionalDomains: [...REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS],
396
+ baselineDomains,
397
+ missingBaselineDomains,
398
+ materialPacks: catalog.materialPacks.length,
399
+ activeDomains,
400
+ activePacks,
401
+ sources: {
402
+ total: sources.length,
403
+ quarantined: sources.filter((source) => source.quarantineRequired || source.quarantineStatus === 'quarantined').length,
404
+ denied: sources.filter((source) => source.quarantineStatus === 'denied').length,
405
+ futureAdapters: sources.filter((source) => source.hostCompatibility.some((item) => item.includes('future_adapter'))).length
406
+ },
407
+ evidence: capabilityEvidenceCounts(latestEvidence),
408
+ releaseCriticalGaps,
409
+ warnings: uniqueSorted(warnings),
410
+ reasons: capabilityHealthReasons(latestRunId, latestEvidence.length, blocked, warnings.length)
411
+ };
412
+ } catch (error) {
413
+ return {
414
+ status: 'absent',
415
+ requiredProfessionalDomains: [...REQUIRED_PROFESSIONAL_CAPABILITY_DOMAINS],
416
+ baselineDomains: [],
417
+ missingBaselineDomains: [],
418
+ materialPacks: 0,
419
+ activeDomains: [],
420
+ activePacks: [],
421
+ sources: { total: 0, quarantined: 0, denied: 0, futureAdapters: 0 },
422
+ evidence: { accepted: 0, candidate: 0, quarantined: 0, diagnostic: 0, blocked: 0 },
423
+ warnings: [],
424
+ releaseCriticalGaps: [],
425
+ reasons: [`capability health unavailable: ${error instanceof Error ? error.message : String(error)}`]
426
+ };
427
+ }
428
+ }
429
+
430
+ function capabilityEvidenceFromTestRuns(payloads: unknown[]): CapabilityEvidenceClassification[] {
431
+ return payloads.flatMap((payload) => isRecord(payload) && Array.isArray(payload.capabilityEvidence)
432
+ ? payload.capabilityEvidence.filter(isCapabilityEvidenceClassification)
433
+ : []);
434
+ }
435
+
436
+ function isCapabilityEvidenceClassification(value: unknown): value is CapabilityEvidenceClassification {
437
+ return isRecord(value)
438
+ && (value.class === 'accepted' || value.class === 'candidate' || value.class === 'quarantined' || value.class === 'diagnostic' || value.class === 'blocked')
439
+ && (value.source === 'professional_capability' || value.source === 'external_source' || value.source === 'runtime_diagnostic')
440
+ && typeof value.domainOrSourceId === 'string';
441
+ }
442
+
443
+ function capabilityEvidenceCounts(evidence: CapabilityEvidenceClassification[]): CapabilityHealthProjection['evidence'] {
444
+ return {
445
+ accepted: evidence.filter((item) => item.class === 'accepted').length,
446
+ candidate: evidence.filter((item) => item.class === 'candidate').length,
447
+ quarantined: evidence.filter((item) => item.class === 'quarantined').length,
448
+ diagnostic: evidence.filter((item) => item.class === 'diagnostic').length,
449
+ blocked: evidence.filter((item) => item.class === 'blocked').length
450
+ };
451
+ }
452
+
453
+ function releaseCriticalCapabilityGaps(tasks: SddTaskModel['tasks'], acceptedProfessionalEvidence: CapabilityEvidenceClassification[]): ProfessionalCapabilityDomain[] {
454
+ const required = releaseCriticalDomainsForTasks(tasks);
455
+ const acceptedEvidenceDomains = new Set(acceptedProfessionalEvidence.map((item) => item.domainOrSourceId));
456
+ return required.filter((domain) => !acceptedEvidenceDomains.has(domain));
457
+ }
458
+
459
+ function releaseCriticalDomainsForTasks(tasks: SddTaskModel['tasks']): ProfessionalCapabilityDomain[] {
460
+ const domains = new Set<ProfessionalCapabilityDomain>();
461
+ for (const task of tasks) {
462
+ const text = [task.title ?? '', ...task.risk, ...task.affectedFiles, ...task.validation, ...task.acceptance, task.boundary ?? ''].join('\n').toLowerCase();
463
+ if (/security|auth|permission|secret|token|安全/.test(text)) {
464
+ domains.add('security-engineering');
465
+ }
466
+ if (/performance|latency|throughput|benchmark|capacity|性能/.test(text)) {
467
+ domains.add('performance-engineering');
468
+ }
469
+ if (/observability|logging|metrics|tracing|diagnostic|可观测/.test(text)) {
470
+ domains.add('observability-engineering');
471
+ }
472
+ if (/release|deploy|rollback|ci|ship|发布/.test(text)) {
473
+ domains.add('release-engineering');
474
+ }
475
+ if (/database|schema|migration|query|data|db|数据/.test(text)) {
476
+ domains.add('db-data-engineering');
477
+ }
478
+ if (/ui|ux|frontend|browser|figma|accessibility|交互|前端/.test(text)) {
479
+ domains.add(text.includes('frontend') || text.includes('browser') || text.includes('前端') ? 'frontend-engineering' : 'ui-ux-product-design');
480
+ }
481
+ }
482
+ return [...domains].sort((left, right) => left.localeCompare(right));
483
+ }
484
+
485
+ function noCapabilityEvidenceWarnings(noEvidence: boolean): string[] {
486
+ return noEvidence ? ['latest run has no capability evidence classification'] : [];
487
+ }
488
+
489
+ function capabilityHealthReasons(latestRunId: string | null, evidenceCount: number, blocked: boolean, warnings: number): string[] {
490
+ if (blocked) {
491
+ return ['Capability catalog or runtime source validation has blocking issues.'];
492
+ }
493
+ if (latestRunId !== null && evidenceCount === 0) {
494
+ return ['Latest run has no recorded capability evidence classification.'];
495
+ }
496
+ if (warnings > 0) {
497
+ return ['Capability health has warnings; inspect status JSON for exact missing evidence or release-critical gaps.'];
498
+ }
499
+ return ['Professional capability baseline and source policy are visible.'];
500
+ }
501
+
502
+ function isRecord(value: unknown): value is Record<string, unknown> {
503
+ return Boolean(value) && typeof value === 'object';
504
+ }
505
+
506
+ function uniqueSorted<T extends string>(values: T[]): T[] {
507
+ return [...new Set(values)].sort((left, right) => left.localeCompare(right));
508
+ }
509
+
510
+ async function inspectTokenRuntimeProjection(projectRoot: string): Promise<TokenRuntimeProjection> {
511
+ const projections = await listRuntimeProjections(projectRoot, ['context_build', 'team_runtime_decision']);
512
+ const contextPackages = projections.filter((projection) => projection.projectionType === 'context_build');
513
+ const teamRuntimeDecisions = projections.filter((projection) => projection.projectionType === 'team_runtime_decision');
514
+ const contextTokenEstimates = contextPackages.map((projection) => tokenEstimateFromContextBuildPayload(projection.payload)).filter((value): value is number => value !== null);
515
+ const teamTokenEstimates = teamRuntimeDecisions.map((projection) => tokenEstimateFromTeamRuntimePayload(projection.payload)).filter((value): value is number => value !== null);
516
+ const estimatedTokens = [...contextTokenEstimates, ...teamTokenEstimates].reduce((total, value) => total + value, 0);
517
+ const pressureReasons = [
518
+ ...contextPackages.map((projection) => contextPressureReason(projection.payload)).filter((value): value is string => value !== null),
519
+ ...teamRuntimeDecisions.map((projection) => teamPressureReason(projection.payload)).filter((value): value is string => value !== null)
520
+ ];
521
+
522
+ return {
523
+ health: projections.length === 0 ? 'unknown' : pressureReasons.length > 0 ? 'pressure' : 'nominal',
524
+ estimatedTokens: projections.length === 0 ? null : estimatedTokens,
525
+ contextPackages: contextPackages.length,
526
+ teamRuntimeDecisions: teamRuntimeDecisions.length,
527
+ pressureReasons
528
+ };
529
+ }
530
+
531
+ function tokenEstimateFromContextBuildPayload(payload: unknown): number | null {
532
+ if (!payload || typeof payload !== 'object') {
533
+ return null;
534
+ }
535
+ const budget = (payload as { budget?: { estimatedTokens?: unknown } }).budget;
536
+ return typeof budget?.estimatedTokens === 'number' ? budget.estimatedTokens : null;
537
+ }
538
+
539
+ function tokenEstimateFromTeamRuntimePayload(payload: unknown): number | null {
540
+ if (!payload || typeof payload !== 'object') {
541
+ return null;
542
+ }
543
+ const decision = payload as { roleIds?: unknown; telemetryPolicy?: { contextBudget?: unknown } | null };
544
+ const roleCount = Array.isArray(decision.roleIds) ? decision.roleIds.length : 0;
545
+ const contextBudget = decision.telemetryPolicy?.contextBudget;
546
+ const perRole = contextBudget === 'medium' ? 3000 : contextBudget === 'small' ? 1200 : 600;
547
+ return roleCount * perRole;
548
+ }
549
+
550
+ function contextPressureReason(payload: unknown): string | null {
551
+ if (!payload || typeof payload !== 'object') {
552
+ return null;
553
+ }
554
+ const contextPackage = payload as { taskId?: unknown; profile?: unknown; budget?: { estimatedBytes?: unknown; maxBytes?: unknown } };
555
+ const estimatedBytes = contextPackage.budget?.estimatedBytes;
556
+ const maxBytes = contextPackage.budget?.maxBytes;
557
+ if (contextPackage.profile === 'brief') {
558
+ return null;
559
+ }
560
+ if (typeof estimatedBytes === 'number' && typeof maxBytes === 'number' && estimatedBytes >= maxBytes * 0.85) {
561
+ return `context_budget_pressure:${String(contextPackage.taskId ?? 'unknown')}`;
562
+ }
563
+ return null;
564
+ }
565
+
566
+ function teamPressureReason(payload: unknown): string | null {
567
+ if (!payload || typeof payload !== 'object') {
568
+ return null;
569
+ }
570
+ const decision = payload as { command?: unknown; mode?: unknown; roleIds?: unknown };
571
+ const roleCount = Array.isArray(decision.roleIds) ? decision.roleIds.length : 0;
572
+ if (decision.mode === 'team-required' || roleCount > 2) {
573
+ return `team_runtime_pressure:${String(decision.command ?? 'unknown')}`;
574
+ }
575
+ return null;
576
+ }
577
+
578
+ async function inspectRunEvidenceSummary(projectRoot: string, runId: string): Promise<RunEvidenceSummary> {
579
+ const [state, events, agentExecutions, teamSessions, workerRuntimeList] = await Promise.all([
580
+ readRunState(projectRoot, runId),
581
+ readRunEvents(projectRoot, runId),
582
+ listAgentExecutionRecords(projectRoot, runId),
583
+ listTeamSessionRecords(projectRoot, runId),
584
+ listResidentWorkerRuntimes(projectRoot, { runId })
585
+ ]);
586
+ return {
587
+ agentExecutions: agentExecutions.length,
588
+ teamSessions: teamSessions.length,
589
+ artifactIngestions: Object.keys(state.artifactIngestions ?? {}).length,
590
+ workerRuntimes: workerRuntimeList.runtimes.length,
591
+ staleWorkerRuntimes: workerRuntimeList.staleRuntimes,
592
+ routePreflight: events.some((event) => event.event === 'agent_router_preflight'),
593
+ tasksChangedAfterRun: false,
594
+ tasksUpdatedAt: null,
595
+ runUpdatedAt: state.updatedAt ?? null
596
+ };
597
+ }
598
+
599
+ async function addTaskDocumentStalenessToRunEvidence(tasksPath: string, latestRun: RunSummary, evidence: RunEvidenceSummary): Promise<RunEvidenceSummary> {
600
+ try {
601
+ const tasksStat = await stat(tasksPath);
602
+ const runUpdatedAtMs = Date.parse(latestRun.updatedAt);
603
+ if (Number.isNaN(runUpdatedAtMs)) {
604
+ return { ...evidence, runUpdatedAt: latestRun.updatedAt };
605
+ }
606
+ return {
607
+ ...evidence,
608
+ tasksChangedAfterRun: tasksStat.mtimeMs > runUpdatedAtMs,
609
+ tasksUpdatedAt: tasksStat.mtime.toISOString(),
610
+ runUpdatedAt: latestRun.updatedAt
611
+ };
612
+ } catch {
613
+ return { ...evidence, runUpdatedAt: latestRun.updatedAt };
614
+ }
615
+ }
616
+
617
+ async function getGitRoot(projectRoot: string): Promise<string | null> {
618
+ try {
619
+ const result = await execFileAsync('git', ['-C', projectRoot, 'rev-parse', '--show-toplevel']);
620
+ return result.stdout.trim();
621
+ } catch {
622
+ return null;
623
+ }
624
+ }
625
+
626
+ async function runDocumentStaleReasons(_projectRoot: string, state: RunState, model: SddTaskModel): Promise<string[]> {
627
+ const reasons: string[] = [];
628
+ const snapshot = state.documentSnapshot;
629
+ if (!snapshot.specHash && !snapshot.planHash && !snapshot.tasksHash) {
630
+ reasons.push('Run has no document snapshot hashes; rerun execute before validation.');
631
+ }
632
+ appendDocumentHashMismatch(reasons, 'spec.md', snapshot.specHash, model.documents.specHash ?? null);
633
+ appendDocumentHashMismatch(reasons, 'plan.md', snapshot.planHash, model.documents.planHash ?? null);
634
+ appendDocumentHashMismatch(reasons, 'tasks.md', snapshot.tasksHash, model.documents.tasksHash ?? null);
635
+ if (model.documents.planStale) {
636
+ reasons.push('Current plan.md is stale against spec.md.');
637
+ }
638
+ if (model.documents.tasksStale) {
639
+ reasons.push('Current tasks.md is stale against plan.md or spec.md.');
640
+ }
641
+ return reasons;
642
+ }
643
+
644
+ function appendDocumentHashMismatch(reasons: string[], documentName: string, expected: string | null, actual: string | null): void {
645
+ if (!expected && !actual) {
646
+ return;
647
+ }
648
+ if (!expected || !actual || expected.replace(/^sha256:/, '') !== actual) {
649
+ reasons.push(`Run snapshot for ${documentName} is ${expected ?? 'missing'}, current hash is ${actual ?? 'missing'}.`);
650
+ }
651
+ }