agentic-orchestrator 0.1.28 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (836) hide show
  1. package/.claude/settings.local.json +46 -1
  2. package/.cortexrc +28 -0
  3. package/.github/agents/copilot-instructions.md +29 -0
  4. package/.github/copilot-instructions.md +93 -0
  5. package/.vscode/settings.json +13 -0
  6. package/.vscode/tms.code-snippets +223 -0
  7. package/AGENTS.md +72 -1
  8. package/Agentic-Orchestrator.iml +12 -11
  9. package/CLAUDE.md +72 -1
  10. package/CONSTITUTION.md +504 -0
  11. package/FUTURE-ENHANCEMENTS.md +85 -0
  12. package/NEXT-TASKS.md +25 -0
  13. package/PROMPTS.md +161 -0
  14. package/README.md +126 -29
  15. package/agentic/orchestrator/agents.yaml +4 -3
  16. package/agentic/orchestrator/defaults/policy.defaults.yaml +39 -3
  17. package/agentic/orchestrator/gates.yaml +15 -3
  18. package/agentic/orchestrator/policy.yaml +47 -3
  19. package/agentic/orchestrator/prompts/builder.system.md +69 -20
  20. package/agentic/orchestrator/prompts/planner-intake.system.md +149 -0
  21. package/agentic/orchestrator/prompts/planner.system.md +113 -40
  22. package/agentic/orchestrator/prompts/qa.system.md +73 -18
  23. package/agentic/orchestrator/prompts/reconciler.system.md +119 -0
  24. package/agentic/orchestrator/schemas/agents.schema.json +89 -1
  25. package/agentic/orchestrator/schemas/execution-control.schema.json +242 -0
  26. package/agentic/orchestrator/schemas/index.schema.json +234 -0
  27. package/agentic/orchestrator/schemas/intake.review.schema.json +82 -0
  28. package/agentic/orchestrator/schemas/organizer-ordering-artifact.schema.json +75 -0
  29. package/agentic/orchestrator/schemas/plan.schema.json +44 -0
  30. package/agentic/orchestrator/schemas/policy.schema.json +238 -9
  31. package/agentic/orchestrator/schemas/policy.user.schema.json +129 -1
  32. package/agentic/orchestrator/schemas/spec.manifest.bootstrap.schema.json +101 -0
  33. package/agentic/orchestrator/schemas/spec.manifest.verified.schema.json +80 -0
  34. package/agentic/orchestrator/schemas/state.schema.json +298 -3
  35. package/agentic/orchestrator/tools/catalog.json +145 -15
  36. package/agentic/orchestrator/tools/schemas/input/doctor.run.input.schema.json +18 -0
  37. package/agentic/orchestrator/tools/schemas/input/evidence.latest.input.schema.json +4 -0
  38. package/agentic/orchestrator/tools/schemas/input/evidence.verify_chain.input.schema.json +13 -0
  39. package/agentic/orchestrator/tools/schemas/input/feature.intake_submit.input.schema.json +11 -0
  40. package/agentic/orchestrator/tools/schemas/input/feature.question_answer.input.schema.json +15 -0
  41. package/agentic/orchestrator/tools/schemas/input/feature.question_create.input.schema.json +21 -0
  42. package/agentic/orchestrator/tools/schemas/input/feature.question_list.input.schema.json +13 -0
  43. package/agentic/orchestrator/tools/schemas/input/feature.ready_to_merge.input.schema.json +5 -0
  44. package/agentic/orchestrator/tools/schemas/input/feature.send_message.input.schema.json +1 -1
  45. package/agentic/orchestrator/tools/schemas/input/replay.timeline_get.input.schema.json +32 -0
  46. package/agentic/orchestrator/tools/schemas/input/repo.conflict_abort.input.schema.json +16 -0
  47. package/agentic/orchestrator/tools/schemas/input/repo.conflict_files.input.schema.json +16 -0
  48. package/agentic/orchestrator/tools/schemas/input/repo.reconcile_mainline.input.schema.json +37 -0
  49. package/agentic/orchestrator/tools/schemas/input/repo.resolve_conflict.input.schema.json +40 -0
  50. package/agentic/orchestrator/tools/schemas/input/runtime.execution_request_list.input.schema.json +7 -0
  51. package/agentic/orchestrator/tools/schemas/input/runtime.execution_request_submit.input.schema.json +25 -0
  52. package/agentic/orchestrator/tools/schemas/output/doctor.run.output.schema.json +34 -0
  53. package/agentic/orchestrator/tools/schemas/output/evidence.verify_chain.output.schema.json +23 -0
  54. package/agentic/orchestrator/tools/schemas/output/feature.get_context.output.schema.json +62 -2
  55. package/agentic/orchestrator/tools/schemas/output/feature.intake_submit.output.schema.json +24 -0
  56. package/agentic/orchestrator/tools/schemas/output/feature.question_answer.output.schema.json +21 -0
  57. package/agentic/orchestrator/tools/schemas/output/feature.question_create.output.schema.json +12 -0
  58. package/agentic/orchestrator/tools/schemas/output/feature.question_list.output.schema.json +14 -0
  59. package/agentic/orchestrator/tools/schemas/output/feature.ready_to_merge.output.schema.json +31 -0
  60. package/agentic/orchestrator/tools/schemas/output/feature.send_message.output.schema.json +8 -18
  61. package/agentic/orchestrator/tools/schemas/output/replay.timeline_get.output.schema.json +64 -0
  62. package/agentic/orchestrator/tools/schemas/output/repo.conflict_abort.output.schema.json +16 -0
  63. package/agentic/orchestrator/tools/schemas/output/repo.conflict_files.output.schema.json +22 -0
  64. package/agentic/orchestrator/tools/schemas/output/repo.reconcile_mainline.output.schema.json +61 -0
  65. package/agentic/orchestrator/tools/schemas/output/repo.resolve_conflict.output.schema.json +19 -0
  66. package/agentic/orchestrator/tools/schemas/output/report.dashboard.output.schema.json +26 -0
  67. package/agentic/orchestrator/tools/schemas/output/runtime.execution_request_list.output.schema.json +17 -0
  68. package/agentic/orchestrator/tools/schemas/output/runtime.execution_request_submit.output.schema.json +24 -0
  69. package/agentic/orchestrator/tools.md +13 -0
  70. package/apps/control-plane/scripts/validate-mcp-contracts.ts +1 -1
  71. package/apps/control-plane/src/application/kernel-tool-wiring.ts +140 -2
  72. package/apps/control-plane/src/application/services/activity-monitor-service.ts +44 -1
  73. package/apps/control-plane/src/application/services/bootstrap-manifest-generator-service.ts +251 -0
  74. package/apps/control-plane/src/application/services/checkpoint-service.ts +87 -27
  75. package/apps/control-plane/src/application/services/collision-override-service.ts +906 -0
  76. package/apps/control-plane/src/application/services/collision-queue-service.ts +129 -38
  77. package/apps/control-plane/src/application/services/cost-tracking-service.ts +94 -0
  78. package/apps/control-plane/src/application/services/execution-control-service.ts +599 -0
  79. package/apps/control-plane/src/application/services/feature-deletion-service.ts +37 -1
  80. package/apps/control-plane/src/application/services/feature-lifecycle-service.ts +182 -4
  81. package/apps/control-plane/src/application/services/feature-send-message-service.ts +17 -8
  82. package/apps/control-plane/src/application/services/feature-state-service.ts +191 -6
  83. package/apps/control-plane/src/application/services/gate-service.ts +121 -2
  84. package/apps/control-plane/src/application/services/git-reconciliation-service.ts +1591 -0
  85. package/apps/control-plane/src/application/services/intake-service.ts +1468 -0
  86. package/apps/control-plane/src/application/services/merge-service.ts +308 -17
  87. package/apps/control-plane/src/application/services/notifier-service.ts +3 -1
  88. package/apps/control-plane/src/application/services/performance-analytics-service.ts +75 -0
  89. package/apps/control-plane/src/application/services/plan-service.ts +336 -20
  90. package/apps/control-plane/src/application/services/question-service.ts +693 -0
  91. package/apps/control-plane/src/application/services/reactions-service.ts +73 -17
  92. package/apps/control-plane/src/application/services/replay-timeline-service.ts +295 -0
  93. package/apps/control-plane/src/application/services/reporting-service.ts +194 -10
  94. package/apps/control-plane/src/application/services/run-lease-service.ts +121 -5
  95. package/apps/control-plane/src/application/services/worktree-watchdog-service.ts +95 -8
  96. package/apps/control-plane/src/application/tools/tool-metadata.ts +7 -0
  97. package/apps/control-plane/src/application/usage-types.ts +138 -0
  98. package/apps/control-plane/src/cli/add-command-handler.ts +162 -0
  99. package/apps/control-plane/src/cli/answer-command-handler.ts +113 -0
  100. package/apps/control-plane/src/cli/attach-command-handler.ts +12 -3
  101. package/apps/control-plane/src/cli/cli-argument-parser.ts +133 -11
  102. package/apps/control-plane/src/cli/collision-command-handler.ts +113 -0
  103. package/apps/control-plane/src/cli/command-catalog.ts +479 -0
  104. package/apps/control-plane/src/cli/complete-command-handler.ts +23 -0
  105. package/apps/control-plane/src/cli/completion-command-handler.ts +25 -0
  106. package/apps/control-plane/src/cli/completion-resolver.ts +319 -0
  107. package/apps/control-plane/src/cli/completion-shell-renderer.ts +58 -0
  108. package/apps/control-plane/src/cli/dashboard-command-handler.ts +111 -1
  109. package/apps/control-plane/src/cli/dashboard-runtime-runner.ts +1036 -0
  110. package/apps/control-plane/src/cli/dashboard-runtime.ts +31 -0
  111. package/apps/control-plane/src/cli/help-command-handler.ts +17 -185
  112. package/apps/control-plane/src/cli/init-command-handler.ts +51 -6
  113. package/apps/control-plane/src/cli/merge-command-handler.ts +200 -0
  114. package/apps/control-plane/src/cli/questions-command-handler.ts +70 -0
  115. package/apps/control-plane/src/cli/replay-command-handler.ts +98 -0
  116. package/apps/control-plane/src/cli/resume-command-handler.ts +231 -16
  117. package/apps/control-plane/src/cli/retry-command-handler.ts +229 -17
  118. package/apps/control-plane/src/cli/retry-resume-decision.ts +75 -0
  119. package/apps/control-plane/src/cli/rollback-command-handler.ts +4 -2
  120. package/apps/control-plane/src/cli/run-command-handler.ts +35 -1
  121. package/apps/control-plane/src/cli/spec-ingestion-service.ts +45 -55
  122. package/apps/control-plane/src/cli/spec-preparation.ts +114 -0
  123. package/apps/control-plane/src/cli/spec-utils.ts +90 -11
  124. package/apps/control-plane/src/cli/status-command-handler.ts +122 -0
  125. package/apps/control-plane/src/cli/types.ts +41 -3
  126. package/apps/control-plane/src/core/collisions.ts +150 -31
  127. package/apps/control-plane/src/core/constants.ts +18 -1
  128. package/apps/control-plane/src/core/error-codes.ts +39 -0
  129. package/apps/control-plane/src/core/execution-control.ts +56 -0
  130. package/apps/control-plane/src/core/feature-resume-phase.ts +118 -0
  131. package/apps/control-plane/src/core/gate-freshness.ts +359 -0
  132. package/apps/control-plane/src/core/gate-log-extractor.ts +97 -0
  133. package/apps/control-plane/src/core/gates.ts +90 -1
  134. package/apps/control-plane/src/core/intake-artifacts.ts +295 -0
  135. package/apps/control-plane/src/core/kernel-types.ts +11 -0
  136. package/apps/control-plane/src/core/kernel.ts +604 -16
  137. package/apps/control-plane/src/core/mainline-conflict.ts +22 -0
  138. package/apps/control-plane/src/core/merge-repair.ts +149 -0
  139. package/apps/control-plane/src/core/path-layout.ts +46 -2
  140. package/apps/control-plane/src/core/path-rules.ts +11 -3
  141. package/apps/control-plane/src/core/plan-submit-recovery.ts +130 -0
  142. package/apps/control-plane/src/core/questions.ts +49 -0
  143. package/apps/control-plane/src/core/runtime-sessions.ts +4 -0
  144. package/apps/control-plane/src/core/schemas.ts +40 -1
  145. package/apps/control-plane/src/core/tool-caller.ts +25 -1
  146. package/apps/control-plane/src/core/utils/index-normalizer.ts +25 -4
  147. package/apps/control-plane/src/core/worktree-diff.ts +66 -0
  148. package/apps/control-plane/src/index.ts +29 -1
  149. package/apps/control-plane/src/interfaces/cli/bootstrap.ts +300 -6
  150. package/apps/control-plane/src/mcp/kernel-tool-executor.ts +17 -0
  151. package/apps/control-plane/src/mcp/tool-runtime.ts +63 -4
  152. package/apps/control-plane/src/providers/api-worker-provider.ts +62 -15
  153. package/apps/control-plane/src/providers/cli-worker-provider.ts +1037 -61
  154. package/apps/control-plane/src/providers/output-parsers/generic-output-parser.ts +99 -1
  155. package/apps/control-plane/src/providers/output-parsers/types.ts +2 -0
  156. package/apps/control-plane/src/providers/provider-defaults.ts +116 -7
  157. package/apps/control-plane/src/providers/providers.ts +225 -21
  158. package/apps/control-plane/src/providers/worker-provider-factory.ts +26 -2
  159. package/apps/control-plane/src/supervisor/artifact-stager.ts +52 -0
  160. package/apps/control-plane/src/supervisor/build-wave-executor.ts +477 -166
  161. package/apps/control-plane/src/supervisor/execution-enrollment-service.ts +408 -0
  162. package/apps/control-plane/src/supervisor/organizer-enrollment-scheduler.ts +117 -0
  163. package/apps/control-plane/src/supervisor/organizer-sidecar-service.ts +394 -0
  164. package/apps/control-plane/src/supervisor/plan-conformance-scorer.ts +2 -5
  165. package/apps/control-plane/src/supervisor/planner-phase.ts +85 -0
  166. package/apps/control-plane/src/supervisor/planning-wave-executor.ts +993 -64
  167. package/apps/control-plane/src/supervisor/prompt-bundle-loader.ts +20 -1
  168. package/apps/control-plane/src/supervisor/qa-wave-executor.ts +384 -177
  169. package/apps/control-plane/src/supervisor/run-coordinator.ts +723 -20
  170. package/apps/control-plane/src/supervisor/runtime.ts +485 -9
  171. package/apps/control-plane/src/supervisor/session-orchestrator.ts +220 -1
  172. package/apps/control-plane/src/supervisor/types.ts +152 -1
  173. package/apps/control-plane/src/supervisor/worker-decision-loop.ts +1030 -92
  174. package/apps/control-plane/test/activity-monitor.spec.ts +76 -0
  175. package/apps/control-plane/test/add-command-handler.spec.ts +189 -0
  176. package/apps/control-plane/test/application/services/feature-state-service.spec.ts +208 -0
  177. package/apps/control-plane/test/artifact-stager.spec.ts +93 -0
  178. package/apps/control-plane/test/batch-operations.spec.ts +58 -0
  179. package/apps/control-plane/test/bootstrap-edge-cases.spec.ts +50 -2
  180. package/apps/control-plane/test/bootstrap-manifest-generator-service.spec.ts +99 -0
  181. package/apps/control-plane/test/bootstrap.spec.ts +177 -4
  182. package/apps/control-plane/test/checkpoint-service.spec.ts +977 -29
  183. package/apps/control-plane/test/cli-argument-parser.spec.ts +119 -0
  184. package/apps/control-plane/test/cli-helpers.spec.ts +1202 -12
  185. package/apps/control-plane/test/cli.unit.spec.ts +797 -16
  186. package/apps/control-plane/test/collision-command-handler.spec.ts +182 -0
  187. package/apps/control-plane/test/collision-override-service.spec.ts +878 -0
  188. package/apps/control-plane/test/collision-queue.spec.ts +430 -2
  189. package/apps/control-plane/test/collisions.spec.ts +209 -1
  190. package/apps/control-plane/test/core-utils.spec.ts +61 -0
  191. package/apps/control-plane/test/cost-tracking.spec.ts +224 -0
  192. package/apps/control-plane/test/dashboard-api.integration.spec.ts +185 -5
  193. package/apps/control-plane/test/dashboard-client.spec.ts +948 -0
  194. package/apps/control-plane/test/dashboard-command.spec.ts +138 -6
  195. package/apps/control-plane/test/dashboard-runtime-runner.spec.ts +1550 -0
  196. package/apps/control-plane/test/dashboard-runtime.spec.ts +138 -0
  197. package/apps/control-plane/test/dashboard-ui-utils.spec.ts +56 -12
  198. package/apps/control-plane/test/dependency-scheduler.spec.ts +7 -1
  199. package/apps/control-plane/test/env-file.spec.ts +76 -0
  200. package/apps/control-plane/test/execution-control-service.spec.ts +535 -0
  201. package/apps/control-plane/test/execution-enrollment-service.spec.ts +648 -0
  202. package/apps/control-plane/test/feature-lifecycle.spec.ts +126 -0
  203. package/apps/control-plane/test/feature-resume-phase.spec.ts +164 -0
  204. package/apps/control-plane/test/feature-send-message-service.spec.ts +161 -0
  205. package/apps/control-plane/test/feature-state-service.spec.ts +295 -0
  206. package/apps/control-plane/test/fs.spec.ts +80 -0
  207. package/apps/control-plane/test/gate-freshness.spec.ts +590 -0
  208. package/apps/control-plane/test/gate-log-extractor.spec.ts +170 -0
  209. package/apps/control-plane/test/gates.spec.ts +108 -0
  210. package/apps/control-plane/test/git-reconciliation-service.spec.ts +2307 -0
  211. package/apps/control-plane/test/helpers.ts +65 -0
  212. package/apps/control-plane/test/incremental-gates.spec.ts +271 -0
  213. package/apps/control-plane/test/index-normalizer.spec.ts +98 -0
  214. package/apps/control-plane/test/init-wizard.spec.ts +17 -0
  215. package/apps/control-plane/test/intake-artifacts.spec.ts +203 -0
  216. package/apps/control-plane/test/intake-service.spec.ts +3176 -0
  217. package/apps/control-plane/test/kernel-collision-replay.spec.ts +3 -2
  218. package/apps/control-plane/test/kernel-tool-executor.spec.ts +77 -0
  219. package/apps/control-plane/test/kernel-tool-wiring.spec.ts +279 -0
  220. package/apps/control-plane/test/kernel.branches.spec.ts +15 -2
  221. package/apps/control-plane/test/kernel.coverage.spec.ts +7 -3
  222. package/apps/control-plane/test/kernel.coverage2.spec.ts +731 -2
  223. package/apps/control-plane/test/kernel.spec.ts +464 -2
  224. package/apps/control-plane/test/mainline-conflict.spec.ts +66 -0
  225. package/apps/control-plane/test/mcp-helpers.spec.ts +79 -0
  226. package/apps/control-plane/test/mcp.spec.ts +177 -13
  227. package/apps/control-plane/test/merge-command-handler.spec.ts +531 -0
  228. package/apps/control-plane/test/merge-service.spec.ts +570 -4
  229. package/apps/control-plane/test/notifier-service.spec.ts +26 -0
  230. package/apps/control-plane/test/organizer-enrollment-scheduler.spec.ts +340 -0
  231. package/apps/control-plane/test/organizer-ordering-artifact.spec.ts +95 -0
  232. package/apps/control-plane/test/organizer-sidecar-service.spec.ts +468 -0
  233. package/apps/control-plane/test/output-loop-detector.spec.ts +6 -0
  234. package/apps/control-plane/test/path-layout.spec.ts +70 -0
  235. package/apps/control-plane/test/performance-analytics.spec.ts +124 -0
  236. package/apps/control-plane/test/plan-conformance-scorer.spec.ts +53 -0
  237. package/apps/control-plane/test/plan-service.spec.ts +686 -4
  238. package/apps/control-plane/test/planning-wave-executor.spec.ts +3272 -86
  239. package/apps/control-plane/test/policy-loader-service.spec.ts +5 -0
  240. package/apps/control-plane/test/prompt-overlay.spec.ts +65 -0
  241. package/apps/control-plane/test/provider-command-runner-epipe.spec.ts +64 -0
  242. package/apps/control-plane/test/providers/api-worker-provider.spec.ts +129 -0
  243. package/apps/control-plane/test/providers/cli-worker-provider.spec.ts +148 -0
  244. package/apps/control-plane/test/providers/usage-types.spec.ts +98 -0
  245. package/apps/control-plane/test/providers.spec.ts +293 -16
  246. package/apps/control-plane/test/question-command-handlers.spec.ts +156 -0
  247. package/apps/control-plane/test/question-service.spec.ts +1119 -0
  248. package/apps/control-plane/test/reactions.spec.ts +114 -0
  249. package/apps/control-plane/test/replay-command-handler.spec.ts +144 -0
  250. package/apps/control-plane/test/replay-timeline-service.spec.ts +459 -0
  251. package/apps/control-plane/test/response.spec.ts +31 -0
  252. package/apps/control-plane/test/resume-command.spec.ts +757 -9
  253. package/apps/control-plane/test/retry-resume-decision.spec.ts +133 -0
  254. package/apps/control-plane/test/rollback-command-handler.spec.ts +334 -0
  255. package/apps/control-plane/test/rollback-command.spec.ts +120 -0
  256. package/apps/control-plane/test/run-coordinator.spec.ts +3062 -404
  257. package/apps/control-plane/test/schemas/state.schema.spec.ts +71 -0
  258. package/apps/control-plane/test/service-retry-paths.spec.ts +112 -0
  259. package/apps/control-plane/test/services.spec.ts +472 -2
  260. package/apps/control-plane/test/session-management.spec.ts +346 -1
  261. package/apps/control-plane/test/spec-ingestion.spec.ts +102 -28
  262. package/apps/control-plane/test/spec-preparation.spec.ts +182 -0
  263. package/apps/control-plane/test/supervisor-collaborators.spec.ts +191 -3
  264. package/apps/control-plane/test/supervisor.calltool.spec.ts +198 -0
  265. package/apps/control-plane/test/supervisor.spec.ts +95 -16
  266. package/apps/control-plane/test/supervisor.unit.spec.ts +385 -18
  267. package/apps/control-plane/test/tool-runtime.spec.ts +122 -0
  268. package/apps/control-plane/test/worker-decision-loop.spec.ts +3479 -476
  269. package/apps/control-plane/test/worker-execution-policy.spec.ts +1416 -6
  270. package/apps/control-plane/test/worker-provider-adapters.spec.ts +1894 -37
  271. package/apps/control-plane/test/worker-provider-factory.spec.ts +81 -0
  272. package/apps/control-plane/test/worktree-watchdog-service.spec.ts +125 -0
  273. package/apps/control-plane/vitest.config.ts +5 -0
  274. package/config/agentic/orchestrator/agents.yaml +22 -1
  275. package/config/agentic/orchestrator/gates.yaml +24 -7
  276. package/config/agentic/orchestrator/policy.yaml +23 -1
  277. package/config/agentic/orchestrator/prompts/builder.system.md +69 -20
  278. package/config/agentic/orchestrator/prompts/organizer.system.md +85 -0
  279. package/config/agentic/orchestrator/prompts/overrides/builder.claude.md +28 -0
  280. package/config/agentic/orchestrator/prompts/overrides/builder.codex.md +28 -0
  281. package/config/agentic/orchestrator/prompts/overrides/planner.claude.md +20 -0
  282. package/config/agentic/orchestrator/prompts/overrides/planner.codex.md +20 -0
  283. package/config/agentic/orchestrator/prompts/planner-intake.system.md +149 -0
  284. package/config/agentic/orchestrator/prompts/planner.system.md +113 -40
  285. package/config/agentic/orchestrator/prompts/qa.system.md +75 -18
  286. package/config/agentic/orchestrator/prompts/reconciler.system.md +119 -0
  287. package/dist/apps/control-plane/application/kernel-tool-wiring.d.ts +26 -2
  288. package/dist/apps/control-plane/application/kernel-tool-wiring.js +40 -2
  289. package/dist/apps/control-plane/application/kernel-tool-wiring.js.map +1 -1
  290. package/dist/apps/control-plane/application/services/activity-monitor-service.js +37 -1
  291. package/dist/apps/control-plane/application/services/activity-monitor-service.js.map +1 -1
  292. package/dist/apps/control-plane/application/services/bootstrap-manifest-generator-service.d.ts +4 -0
  293. package/dist/apps/control-plane/application/services/bootstrap-manifest-generator-service.js +188 -0
  294. package/dist/apps/control-plane/application/services/bootstrap-manifest-generator-service.js.map +1 -0
  295. package/dist/apps/control-plane/application/services/checkpoint-service.d.ts +5 -0
  296. package/dist/apps/control-plane/application/services/checkpoint-service.js +69 -24
  297. package/dist/apps/control-plane/application/services/checkpoint-service.js.map +1 -1
  298. package/dist/apps/control-plane/application/services/collision-override-service.d.ts +139 -0
  299. package/dist/apps/control-plane/application/services/collision-override-service.js +568 -0
  300. package/dist/apps/control-plane/application/services/collision-override-service.js.map +1 -0
  301. package/dist/apps/control-plane/application/services/collision-queue-service.d.ts +15 -0
  302. package/dist/apps/control-plane/application/services/collision-queue-service.js +92 -33
  303. package/dist/apps/control-plane/application/services/collision-queue-service.js.map +1 -1
  304. package/dist/apps/control-plane/application/services/cost-tracking-service.d.ts +11 -0
  305. package/dist/apps/control-plane/application/services/cost-tracking-service.js +75 -0
  306. package/dist/apps/control-plane/application/services/cost-tracking-service.js.map +1 -1
  307. package/dist/apps/control-plane/application/services/execution-control-service.d.ts +75 -0
  308. package/dist/apps/control-plane/application/services/execution-control-service.js +421 -0
  309. package/dist/apps/control-plane/application/services/execution-control-service.js.map +1 -0
  310. package/dist/apps/control-plane/application/services/feature-deletion-service.d.ts +1 -0
  311. package/dist/apps/control-plane/application/services/feature-deletion-service.js +23 -1
  312. package/dist/apps/control-plane/application/services/feature-deletion-service.js.map +1 -1
  313. package/dist/apps/control-plane/application/services/feature-lifecycle-service.d.ts +24 -1
  314. package/dist/apps/control-plane/application/services/feature-lifecycle-service.js +132 -3
  315. package/dist/apps/control-plane/application/services/feature-lifecycle-service.js.map +1 -1
  316. package/dist/apps/control-plane/application/services/feature-send-message-service.js +16 -8
  317. package/dist/apps/control-plane/application/services/feature-send-message-service.js.map +1 -1
  318. package/dist/apps/control-plane/application/services/feature-state-service.d.ts +36 -0
  319. package/dist/apps/control-plane/application/services/feature-state-service.js +163 -6
  320. package/dist/apps/control-plane/application/services/feature-state-service.js.map +1 -1
  321. package/dist/apps/control-plane/application/services/gate-service.d.ts +2 -1
  322. package/dist/apps/control-plane/application/services/gate-service.js +95 -5
  323. package/dist/apps/control-plane/application/services/gate-service.js.map +1 -1
  324. package/dist/apps/control-plane/application/services/git-reconciliation-service.d.ts +92 -0
  325. package/dist/apps/control-plane/application/services/git-reconciliation-service.js +1097 -0
  326. package/dist/apps/control-plane/application/services/git-reconciliation-service.js.map +1 -0
  327. package/dist/apps/control-plane/application/services/intake-service.d.ts +63 -0
  328. package/dist/apps/control-plane/application/services/intake-service.js +1050 -0
  329. package/dist/apps/control-plane/application/services/intake-service.js.map +1 -0
  330. package/dist/apps/control-plane/application/services/merge-service.d.ts +5 -1
  331. package/dist/apps/control-plane/application/services/merge-service.js +233 -18
  332. package/dist/apps/control-plane/application/services/merge-service.js.map +1 -1
  333. package/dist/apps/control-plane/application/services/notifier-service.d.ts +1 -1
  334. package/dist/apps/control-plane/application/services/notifier-service.js +1 -0
  335. package/dist/apps/control-plane/application/services/notifier-service.js.map +1 -1
  336. package/dist/apps/control-plane/application/services/performance-analytics-service.d.ts +11 -0
  337. package/dist/apps/control-plane/application/services/performance-analytics-service.js +59 -0
  338. package/dist/apps/control-plane/application/services/performance-analytics-service.js.map +1 -1
  339. package/dist/apps/control-plane/application/services/plan-service.d.ts +5 -0
  340. package/dist/apps/control-plane/application/services/plan-service.js +254 -15
  341. package/dist/apps/control-plane/application/services/plan-service.js.map +1 -1
  342. package/dist/apps/control-plane/application/services/question-service.d.ts +72 -0
  343. package/dist/apps/control-plane/application/services/question-service.js +507 -0
  344. package/dist/apps/control-plane/application/services/question-service.js.map +1 -0
  345. package/dist/apps/control-plane/application/services/reactions-service.d.ts +2 -0
  346. package/dist/apps/control-plane/application/services/reactions-service.js +60 -17
  347. package/dist/apps/control-plane/application/services/reactions-service.js.map +1 -1
  348. package/dist/apps/control-plane/application/services/replay-timeline-service.d.ts +39 -0
  349. package/dist/apps/control-plane/application/services/replay-timeline-service.js +205 -0
  350. package/dist/apps/control-plane/application/services/replay-timeline-service.js.map +1 -0
  351. package/dist/apps/control-plane/application/services/reporting-service.d.ts +59 -0
  352. package/dist/apps/control-plane/application/services/reporting-service.js +121 -9
  353. package/dist/apps/control-plane/application/services/reporting-service.js.map +1 -1
  354. package/dist/apps/control-plane/application/services/run-lease-service.d.ts +20 -0
  355. package/dist/apps/control-plane/application/services/run-lease-service.js +81 -4
  356. package/dist/apps/control-plane/application/services/run-lease-service.js.map +1 -1
  357. package/dist/apps/control-plane/application/services/worktree-watchdog-service.d.ts +10 -0
  358. package/dist/apps/control-plane/application/services/worktree-watchdog-service.js +65 -8
  359. package/dist/apps/control-plane/application/services/worktree-watchdog-service.js.map +1 -1
  360. package/dist/apps/control-plane/application/tools/tool-metadata.js +7 -0
  361. package/dist/apps/control-plane/application/tools/tool-metadata.js.map +1 -1
  362. package/dist/apps/control-plane/application/usage-types.d.ts +65 -0
  363. package/dist/apps/control-plane/application/usage-types.js +75 -0
  364. package/dist/apps/control-plane/application/usage-types.js.map +1 -0
  365. package/dist/apps/control-plane/cli/add-command-handler.d.ts +18 -0
  366. package/dist/apps/control-plane/cli/add-command-handler.js +110 -0
  367. package/dist/apps/control-plane/cli/add-command-handler.js.map +1 -0
  368. package/dist/apps/control-plane/cli/answer-command-handler.d.ts +8 -0
  369. package/dist/apps/control-plane/cli/answer-command-handler.js +96 -0
  370. package/dist/apps/control-plane/cli/answer-command-handler.js.map +1 -0
  371. package/dist/apps/control-plane/cli/attach-command-handler.js +8 -3
  372. package/dist/apps/control-plane/cli/attach-command-handler.js.map +1 -1
  373. package/dist/apps/control-plane/cli/cli-argument-parser.js +131 -11
  374. package/dist/apps/control-plane/cli/cli-argument-parser.js.map +1 -1
  375. package/dist/apps/control-plane/cli/collision-command-handler.d.ts +8 -0
  376. package/dist/apps/control-plane/cli/collision-command-handler.js +90 -0
  377. package/dist/apps/control-plane/cli/collision-command-handler.js.map +1 -0
  378. package/dist/apps/control-plane/cli/command-catalog.d.ts +21 -0
  379. package/dist/apps/control-plane/cli/command-catalog.js +416 -0
  380. package/dist/apps/control-plane/cli/command-catalog.js.map +1 -0
  381. package/dist/apps/control-plane/cli/complete-command-handler.d.ts +15 -0
  382. package/dist/apps/control-plane/cli/complete-command-handler.js +26 -0
  383. package/dist/apps/control-plane/cli/complete-command-handler.js.map +1 -0
  384. package/dist/apps/control-plane/cli/completion-command-handler.d.ts +8 -0
  385. package/dist/apps/control-plane/cli/completion-command-handler.js +20 -0
  386. package/dist/apps/control-plane/cli/completion-command-handler.js.map +1 -0
  387. package/dist/apps/control-plane/cli/completion-resolver.d.ts +1 -0
  388. package/dist/apps/control-plane/cli/completion-resolver.js +250 -0
  389. package/dist/apps/control-plane/cli/completion-resolver.js.map +1 -0
  390. package/dist/apps/control-plane/cli/completion-shell-renderer.d.ts +3 -0
  391. package/dist/apps/control-plane/cli/completion-shell-renderer.js +53 -0
  392. package/dist/apps/control-plane/cli/completion-shell-renderer.js.map +1 -0
  393. package/dist/apps/control-plane/cli/dashboard-command-handler.d.ts +1 -0
  394. package/dist/apps/control-plane/cli/dashboard-command-handler.js +84 -1
  395. package/dist/apps/control-plane/cli/dashboard-command-handler.js.map +1 -1
  396. package/dist/apps/control-plane/cli/dashboard-runtime-runner.d.ts +81 -0
  397. package/dist/apps/control-plane/cli/dashboard-runtime-runner.js +724 -0
  398. package/dist/apps/control-plane/cli/dashboard-runtime-runner.js.map +1 -0
  399. package/dist/apps/control-plane/cli/dashboard-runtime.d.ts +1 -0
  400. package/dist/apps/control-plane/cli/dashboard-runtime.js +26 -0
  401. package/dist/apps/control-plane/cli/dashboard-runtime.js.map +1 -0
  402. package/dist/apps/control-plane/cli/help-command-handler.js +13 -172
  403. package/dist/apps/control-plane/cli/help-command-handler.js.map +1 -1
  404. package/dist/apps/control-plane/cli/init-command-handler.js +51 -6
  405. package/dist/apps/control-plane/cli/init-command-handler.js.map +1 -1
  406. package/dist/apps/control-plane/cli/merge-command-handler.d.ts +8 -0
  407. package/dist/apps/control-plane/cli/merge-command-handler.js +139 -0
  408. package/dist/apps/control-plane/cli/merge-command-handler.js.map +1 -0
  409. package/dist/apps/control-plane/cli/questions-command-handler.d.ts +8 -0
  410. package/dist/apps/control-plane/cli/questions-command-handler.js +59 -0
  411. package/dist/apps/control-plane/cli/questions-command-handler.js.map +1 -0
  412. package/dist/apps/control-plane/cli/replay-command-handler.d.ts +15 -0
  413. package/dist/apps/control-plane/cli/replay-command-handler.js +55 -0
  414. package/dist/apps/control-plane/cli/replay-command-handler.js.map +1 -0
  415. package/dist/apps/control-plane/cli/resume-command-handler.d.ts +2 -0
  416. package/dist/apps/control-plane/cli/resume-command-handler.js +180 -17
  417. package/dist/apps/control-plane/cli/resume-command-handler.js.map +1 -1
  418. package/dist/apps/control-plane/cli/retry-command-handler.js +202 -16
  419. package/dist/apps/control-plane/cli/retry-command-handler.js.map +1 -1
  420. package/dist/apps/control-plane/cli/retry-resume-decision.d.ts +26 -0
  421. package/dist/apps/control-plane/cli/retry-resume-decision.js +61 -0
  422. package/dist/apps/control-plane/cli/retry-resume-decision.js.map +1 -0
  423. package/dist/apps/control-plane/cli/rollback-command-handler.js +3 -2
  424. package/dist/apps/control-plane/cli/rollback-command-handler.js.map +1 -1
  425. package/dist/apps/control-plane/cli/run-command-handler.js +26 -2
  426. package/dist/apps/control-plane/cli/run-command-handler.js.map +1 -1
  427. package/dist/apps/control-plane/cli/spec-ingestion-service.d.ts +2 -0
  428. package/dist/apps/control-plane/cli/spec-ingestion-service.js +37 -48
  429. package/dist/apps/control-plane/cli/spec-ingestion-service.js.map +1 -1
  430. package/dist/apps/control-plane/cli/spec-preparation.d.ts +14 -0
  431. package/dist/apps/control-plane/cli/spec-preparation.js +81 -0
  432. package/dist/apps/control-plane/cli/spec-preparation.js.map +1 -0
  433. package/dist/apps/control-plane/cli/spec-utils.d.ts +4 -0
  434. package/dist/apps/control-plane/cli/spec-utils.js +70 -11
  435. package/dist/apps/control-plane/cli/spec-utils.js.map +1 -1
  436. package/dist/apps/control-plane/cli/status-command-handler.js +69 -0
  437. package/dist/apps/control-plane/cli/status-command-handler.js.map +1 -1
  438. package/dist/apps/control-plane/cli/types.d.ts +41 -4
  439. package/dist/apps/control-plane/cli/types.js +9 -1
  440. package/dist/apps/control-plane/cli/types.js.map +1 -1
  441. package/dist/apps/control-plane/core/collisions.d.ts +37 -19
  442. package/dist/apps/control-plane/core/collisions.js +87 -12
  443. package/dist/apps/control-plane/core/collisions.js.map +1 -1
  444. package/dist/apps/control-plane/core/constants.d.ts +17 -1
  445. package/dist/apps/control-plane/core/constants.js +18 -1
  446. package/dist/apps/control-plane/core/constants.js.map +1 -1
  447. package/dist/apps/control-plane/core/error-codes.d.ts +39 -0
  448. package/dist/apps/control-plane/core/error-codes.js +39 -0
  449. package/dist/apps/control-plane/core/error-codes.js.map +1 -1
  450. package/dist/apps/control-plane/core/execution-control.d.ts +45 -0
  451. package/dist/apps/control-plane/core/execution-control.js +2 -0
  452. package/dist/apps/control-plane/core/execution-control.js.map +1 -0
  453. package/dist/apps/control-plane/core/feature-resume-phase.d.ts +3 -0
  454. package/dist/apps/control-plane/core/feature-resume-phase.js +88 -0
  455. package/dist/apps/control-plane/core/feature-resume-phase.js.map +1 -0
  456. package/dist/apps/control-plane/core/gate-freshness.d.ts +48 -0
  457. package/dist/apps/control-plane/core/gate-freshness.js +267 -0
  458. package/dist/apps/control-plane/core/gate-freshness.js.map +1 -0
  459. package/dist/apps/control-plane/core/gate-log-extractor.d.ts +22 -0
  460. package/dist/apps/control-plane/core/gate-log-extractor.js +66 -0
  461. package/dist/apps/control-plane/core/gate-log-extractor.js.map +1 -0
  462. package/dist/apps/control-plane/core/gates.d.ts +11 -2
  463. package/dist/apps/control-plane/core/gates.js +67 -3
  464. package/dist/apps/control-plane/core/gates.js.map +1 -1
  465. package/dist/apps/control-plane/core/intake-artifacts.d.ts +109 -0
  466. package/dist/apps/control-plane/core/intake-artifacts.js +143 -0
  467. package/dist/apps/control-plane/core/intake-artifacts.js.map +1 -0
  468. package/dist/apps/control-plane/core/kernel-types.d.ts +8 -0
  469. package/dist/apps/control-plane/core/kernel.d.ts +256 -8
  470. package/dist/apps/control-plane/core/kernel.js +400 -14
  471. package/dist/apps/control-plane/core/kernel.js.map +1 -1
  472. package/dist/apps/control-plane/core/mainline-conflict.d.ts +7 -0
  473. package/dist/apps/control-plane/core/mainline-conflict.js +20 -0
  474. package/dist/apps/control-plane/core/mainline-conflict.js.map +1 -0
  475. package/dist/apps/control-plane/core/merge-repair.d.ts +35 -0
  476. package/dist/apps/control-plane/core/merge-repair.js +99 -0
  477. package/dist/apps/control-plane/core/merge-repair.js.map +1 -0
  478. package/dist/apps/control-plane/core/path-layout.d.ts +10 -0
  479. package/dist/apps/control-plane/core/path-layout.js +32 -2
  480. package/dist/apps/control-plane/core/path-layout.js.map +1 -1
  481. package/dist/apps/control-plane/core/path-rules.js +9 -3
  482. package/dist/apps/control-plane/core/path-rules.js.map +1 -1
  483. package/dist/apps/control-plane/core/plan-submit-recovery.d.ts +22 -0
  484. package/dist/apps/control-plane/core/plan-submit-recovery.js +78 -0
  485. package/dist/apps/control-plane/core/plan-submit-recovery.js.map +1 -0
  486. package/dist/apps/control-plane/core/questions.d.ts +40 -0
  487. package/dist/apps/control-plane/core/questions.js +2 -0
  488. package/dist/apps/control-plane/core/questions.js.map +1 -0
  489. package/dist/apps/control-plane/core/runtime-sessions.d.ts +4 -0
  490. package/dist/apps/control-plane/core/schemas.d.ts +2 -0
  491. package/dist/apps/control-plane/core/schemas.js +31 -1
  492. package/dist/apps/control-plane/core/schemas.js.map +1 -1
  493. package/dist/apps/control-plane/core/tool-caller.d.ts +18 -1
  494. package/dist/apps/control-plane/core/utils/index-normalizer.js +17 -4
  495. package/dist/apps/control-plane/core/utils/index-normalizer.js.map +1 -1
  496. package/dist/apps/control-plane/core/worktree-diff.d.ts +4 -0
  497. package/dist/apps/control-plane/core/worktree-diff.js +52 -0
  498. package/dist/apps/control-plane/core/worktree-diff.js.map +1 -0
  499. package/dist/apps/control-plane/index.d.ts +10 -2
  500. package/dist/apps/control-plane/index.js +9 -2
  501. package/dist/apps/control-plane/index.js.map +1 -1
  502. package/dist/apps/control-plane/interfaces/cli/bootstrap.js +236 -6
  503. package/dist/apps/control-plane/interfaces/cli/bootstrap.js.map +1 -1
  504. package/dist/apps/control-plane/mcp/kernel-tool-executor.js +16 -0
  505. package/dist/apps/control-plane/mcp/kernel-tool-executor.js.map +1 -1
  506. package/dist/apps/control-plane/mcp/tool-runtime.d.ts +5 -0
  507. package/dist/apps/control-plane/mcp/tool-runtime.js +40 -5
  508. package/dist/apps/control-plane/mcp/tool-runtime.js.map +1 -1
  509. package/dist/apps/control-plane/providers/api-worker-provider.d.ts +2 -2
  510. package/dist/apps/control-plane/providers/api-worker-provider.js +40 -9
  511. package/dist/apps/control-plane/providers/api-worker-provider.js.map +1 -1
  512. package/dist/apps/control-plane/providers/cli-worker-provider.d.ts +59 -3
  513. package/dist/apps/control-plane/providers/cli-worker-provider.js +758 -46
  514. package/dist/apps/control-plane/providers/cli-worker-provider.js.map +1 -1
  515. package/dist/apps/control-plane/providers/output-parsers/generic-output-parser.js +91 -1
  516. package/dist/apps/control-plane/providers/output-parsers/generic-output-parser.js.map +1 -1
  517. package/dist/apps/control-plane/providers/output-parsers/types.d.ts +2 -0
  518. package/dist/apps/control-plane/providers/provider-defaults.d.ts +12 -0
  519. package/dist/apps/control-plane/providers/provider-defaults.js +103 -7
  520. package/dist/apps/control-plane/providers/provider-defaults.js.map +1 -1
  521. package/dist/apps/control-plane/providers/providers.d.ts +50 -4
  522. package/dist/apps/control-plane/providers/providers.js +145 -14
  523. package/dist/apps/control-plane/providers/providers.js.map +1 -1
  524. package/dist/apps/control-plane/providers/worker-provider-factory.d.ts +2 -0
  525. package/dist/apps/control-plane/providers/worker-provider-factory.js +8 -1
  526. package/dist/apps/control-plane/providers/worker-provider-factory.js.map +1 -1
  527. package/dist/apps/control-plane/supervisor/artifact-stager.d.ts +5 -0
  528. package/dist/apps/control-plane/supervisor/artifact-stager.js +45 -0
  529. package/dist/apps/control-plane/supervisor/artifact-stager.js.map +1 -0
  530. package/dist/apps/control-plane/supervisor/build-wave-executor.d.ts +24 -1
  531. package/dist/apps/control-plane/supervisor/build-wave-executor.js +362 -150
  532. package/dist/apps/control-plane/supervisor/build-wave-executor.js.map +1 -1
  533. package/dist/apps/control-plane/supervisor/execution-enrollment-service.d.ts +41 -0
  534. package/dist/apps/control-plane/supervisor/execution-enrollment-service.js +311 -0
  535. package/dist/apps/control-plane/supervisor/execution-enrollment-service.js.map +1 -0
  536. package/dist/apps/control-plane/supervisor/organizer-enrollment-scheduler.d.ts +15 -0
  537. package/dist/apps/control-plane/supervisor/organizer-enrollment-scheduler.js +93 -0
  538. package/dist/apps/control-plane/supervisor/organizer-enrollment-scheduler.js.map +1 -0
  539. package/dist/apps/control-plane/supervisor/organizer-sidecar-service.d.ts +44 -0
  540. package/dist/apps/control-plane/supervisor/organizer-sidecar-service.js +311 -0
  541. package/dist/apps/control-plane/supervisor/organizer-sidecar-service.js.map +1 -0
  542. package/dist/apps/control-plane/supervisor/plan-conformance-scorer.js +2 -5
  543. package/dist/apps/control-plane/supervisor/plan-conformance-scorer.js.map +1 -1
  544. package/dist/apps/control-plane/supervisor/planner-phase.d.ts +3 -0
  545. package/dist/apps/control-plane/supervisor/planner-phase.js +70 -0
  546. package/dist/apps/control-plane/supervisor/planner-phase.js.map +1 -0
  547. package/dist/apps/control-plane/supervisor/planning-wave-executor.d.ts +42 -0
  548. package/dist/apps/control-plane/supervisor/planning-wave-executor.js +753 -55
  549. package/dist/apps/control-plane/supervisor/planning-wave-executor.js.map +1 -1
  550. package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js +19 -1
  551. package/dist/apps/control-plane/supervisor/prompt-bundle-loader.js.map +1 -1
  552. package/dist/apps/control-plane/supervisor/qa-wave-executor.d.ts +21 -0
  553. package/dist/apps/control-plane/supervisor/qa-wave-executor.js +287 -156
  554. package/dist/apps/control-plane/supervisor/qa-wave-executor.js.map +1 -1
  555. package/dist/apps/control-plane/supervisor/run-coordinator.d.ts +30 -1
  556. package/dist/apps/control-plane/supervisor/run-coordinator.js +561 -17
  557. package/dist/apps/control-plane/supervisor/run-coordinator.js.map +1 -1
  558. package/dist/apps/control-plane/supervisor/runtime.d.ts +84 -0
  559. package/dist/apps/control-plane/supervisor/runtime.js +393 -3
  560. package/dist/apps/control-plane/supervisor/runtime.js.map +1 -1
  561. package/dist/apps/control-plane/supervisor/session-orchestrator.d.ts +54 -0
  562. package/dist/apps/control-plane/supervisor/session-orchestrator.js +176 -1
  563. package/dist/apps/control-plane/supervisor/session-orchestrator.js.map +1 -1
  564. package/dist/apps/control-plane/supervisor/types.d.ts +142 -1
  565. package/dist/apps/control-plane/supervisor/types.js.map +1 -1
  566. package/dist/apps/control-plane/supervisor/worker-decision-loop.d.ts +68 -2
  567. package/dist/apps/control-plane/supervisor/worker-decision-loop.js +723 -89
  568. package/dist/apps/control-plane/supervisor/worker-decision-loop.js.map +1 -1
  569. package/docs/core/ARCHITECTURE.md +227 -0
  570. package/docs/core/DECISIONS.md +94 -0
  571. package/docs/core/DOMAIN-LOGIC.md +60 -0
  572. package/docs/core/PATTERNS.md +201 -0
  573. package/docs/core/TROUBLESHOOTING.md +347 -0
  574. package/docs/core/intentgraph-dependencies.json +39860 -0
  575. package/docs/core/intentgraph.index.json +46580 -0
  576. package/docs/plans/2026-03-10-gate-failure-targeted-repair-design.md +224 -0
  577. package/docs/plans/2026-03-10-gate-failure-targeted-repair.md +1032 -0
  578. package/docs/superpowers/plans/2026-03-16-provider-cli-config.md +743 -0
  579. package/docs/superpowers/plans/2026-03-23-reconcile-divergence-fix.md +777 -0
  580. package/docs/superpowers/plans/2026-03-28-ordering-agent-implementation.md +1754 -0
  581. package/docs/superpowers/plans/2026-03-29-drop-zone-and-provider-optimization.md +1108 -0
  582. package/docs/superpowers/plans/2026-03-29-merge-target-feature-branch.md +685 -0
  583. package/docs/superpowers/plans/2026-03-29-organizer-sidecar-runtime-loop.md +1289 -0
  584. package/docs/superpowers/specs/2026-03-23-reconcile-divergence-fix-design.md +118 -0
  585. package/docs/superpowers/specs/2026-03-28-ordering-agent-spec-audit-design.md +50 -0
  586. package/docs/superpowers/specs/2026-03-29-drop-zone-and-provider-optimization-design.md +254 -0
  587. package/docs/superpowers/specs/2026-03-29-merge-target-feature-branch-design.md +152 -0
  588. package/docs/superpowers/specs/2026-03-29-organizer-sidecar-runtime-loop-design.md +225 -0
  589. package/package.json +3 -2
  590. package/packages/web-dashboard/package.json +2 -1
  591. package/packages/web-dashboard/src/app/analytics/page.tsx +36 -2
  592. package/packages/web-dashboard/src/app/api/actions/route.ts +274 -63
  593. package/packages/web-dashboard/src/app/api/actions/status/route.ts +35 -0
  594. package/packages/web-dashboard/src/app/api/analytics/provider/route.ts +18 -0
  595. package/packages/web-dashboard/src/app/api/collisions/approve/route.ts +58 -0
  596. package/packages/web-dashboard/src/app/api/features/[id]/checkpoint-diff/route.ts +36 -0
  597. package/packages/web-dashboard/src/app/api/features/[id]/checkpoints/route.ts +29 -0
  598. package/packages/web-dashboard/src/app/api/features/[id]/conflicts/abort/route.ts +29 -0
  599. package/packages/web-dashboard/src/app/api/features/[id]/conflicts/files/route.ts +30 -0
  600. package/packages/web-dashboard/src/app/api/features/[id]/conflicts/resolve/route.ts +51 -0
  601. package/packages/web-dashboard/src/app/api/features/[id]/conflicts/route.ts +75 -0
  602. package/packages/web-dashboard/src/app/api/features/[id]/diff/route.ts +16 -2
  603. package/packages/web-dashboard/src/app/api/features/[id]/files/route.ts +26 -0
  604. package/packages/web-dashboard/src/app/api/features/[id]/gate-history/route.ts +27 -0
  605. package/packages/web-dashboard/src/app/api/features/[id]/genealogy/route.ts +26 -0
  606. package/packages/web-dashboard/src/app/api/features/[id]/history/run/[runId]/route.ts +20 -0
  607. package/packages/web-dashboard/src/app/api/features/[id]/history/runs/route.ts +34 -0
  608. package/packages/web-dashboard/src/app/api/features/[id]/intake-workspace/route.ts +20 -0
  609. package/packages/web-dashboard/src/app/api/features/[id]/live-output/route.ts +74 -0
  610. package/packages/web-dashboard/src/app/api/features/[id]/plan/amend/route.ts +21 -0
  611. package/packages/web-dashboard/src/app/api/features/[id]/plan-progress/route.ts +20 -0
  612. package/packages/web-dashboard/src/app/api/features/[id]/planner-artifacts/[artifact]/route.ts +78 -0
  613. package/packages/web-dashboard/src/app/api/features/[id]/planner-lifecycle/route.ts +20 -0
  614. package/packages/web-dashboard/src/app/api/features/[id]/planning-workspace/route.ts +20 -0
  615. package/packages/web-dashboard/src/app/api/features/[id]/questions/[questionId]/answer/route.ts +27 -0
  616. package/packages/web-dashboard/src/app/api/features/[id]/questions/route.ts +18 -0
  617. package/packages/web-dashboard/src/app/api/features/[id]/review/route.ts +14 -7
  618. package/packages/web-dashboard/src/app/api/features/[id]/route.ts +57 -2
  619. package/packages/web-dashboard/src/app/api/features/[id]/spec/route.ts +30 -0
  620. package/packages/web-dashboard/src/app/api/features/[id]/triage/route.ts +83 -0
  621. package/packages/web-dashboard/src/app/api/features/[id]/worker-events/route.ts +40 -0
  622. package/packages/web-dashboard/src/app/api/launch/preview/route.ts +86 -0
  623. package/packages/web-dashboard/src/app/api/launch/submit/route.ts +180 -0
  624. package/packages/web-dashboard/src/app/api/mainline/status/route.ts +74 -0
  625. package/packages/web-dashboard/src/app/api/merge-queue/route.ts +13 -0
  626. package/packages/web-dashboard/src/app/api/policy/budget/route.ts +14 -0
  627. package/packages/web-dashboard/src/app/api/projects/route.ts +11 -7
  628. package/packages/web-dashboard/src/app/api/reconciler/queue/route.ts +47 -0
  629. package/packages/web-dashboard/src/app/api/run/route.ts +26 -2
  630. package/packages/web-dashboard/src/app/api/runtime/events/route.ts +227 -0
  631. package/packages/web-dashboard/src/app/api/runtime/operations/route.ts +269 -0
  632. package/packages/web-dashboard/src/app/api/runtime/questions/route.ts +11 -0
  633. package/packages/web-dashboard/src/app/api/runtime/runs/route.ts +80 -0
  634. package/packages/web-dashboard/src/app/api/status/route.ts +4 -2
  635. package/packages/web-dashboard/src/app/feature/[id]/page.tsx +32 -42
  636. package/packages/web-dashboard/src/app/globals.css +34 -3
  637. package/packages/web-dashboard/src/app/launch/page.tsx +362 -0
  638. package/packages/web-dashboard/src/app/layout.tsx +23 -1
  639. package/packages/web-dashboard/src/app/page.tsx +263 -272
  640. package/packages/web-dashboard/src/components/dashboard/attention-strip.tsx +52 -0
  641. package/packages/web-dashboard/src/components/dashboard/collision-approval-drawer.tsx +185 -0
  642. package/packages/web-dashboard/src/components/dashboard/command-center-header.tsx +102 -0
  643. package/packages/web-dashboard/src/components/dashboard/mainline-status-banner.tsx +84 -0
  644. package/packages/web-dashboard/src/components/dashboard/merged-archive.tsx +36 -0
  645. package/packages/web-dashboard/src/components/dashboard/prioritized-queues.tsx +98 -0
  646. package/packages/web-dashboard/src/components/dashboard/reconciler-queue-card.tsx +115 -0
  647. package/packages/web-dashboard/src/components/dashboard/secondary-diagnostics-rail.tsx +48 -0
  648. package/packages/web-dashboard/src/components/dashboard/task-filter-bar.tsx +74 -0
  649. package/packages/web-dashboard/src/components/dashboard/triage-drawer.tsx +455 -0
  650. package/packages/web-dashboard/src/components/diff-viewer.tsx +19 -3
  651. package/packages/web-dashboard/src/components/evidence-viewer.tsx +65 -51
  652. package/packages/web-dashboard/src/components/feature-card.tsx +90 -7
  653. package/packages/web-dashboard/src/components/feature-cost-panel.tsx +112 -11
  654. package/packages/web-dashboard/src/components/feature-list-view.tsx +25 -4
  655. package/packages/web-dashboard/src/components/features/runtime-inspector/EventsTimelineView.tsx +260 -0
  656. package/packages/web-dashboard/src/components/features/runtime-inspector/OperationsListView.tsx +172 -0
  657. package/packages/web-dashboard/src/components/features/runtime-inspector/RuntimeInspectorPanel.tsx +896 -0
  658. package/packages/web-dashboard/src/components/filter-bar.tsx +7 -39
  659. package/packages/web-dashboard/src/components/focus/ActionableRiskList.tsx +46 -0
  660. package/packages/web-dashboard/src/components/focus/AgentRolePerformanceCard.tsx +200 -0
  661. package/packages/web-dashboard/src/components/focus/BlockedGuidanceBanner.tsx +149 -0
  662. package/packages/web-dashboard/src/components/focus/CheckpointInspector.tsx +123 -0
  663. package/packages/web-dashboard/src/components/focus/CheckpointRail.tsx +118 -0
  664. package/packages/web-dashboard/src/components/focus/CheckpointScrubber.tsx +249 -0
  665. package/packages/web-dashboard/src/components/focus/CollisionApprovalBanner.tsx +192 -0
  666. package/packages/web-dashboard/src/components/focus/CollisionRadar.tsx +136 -0
  667. package/packages/web-dashboard/src/components/focus/ConflictStatusCard.tsx +52 -0
  668. package/packages/web-dashboard/src/components/focus/ContextSidebar.tsx +108 -0
  669. package/packages/web-dashboard/src/components/focus/DiagnosisPanel.tsx +68 -0
  670. package/packages/web-dashboard/src/components/focus/FeatureDecisionBanner.tsx +68 -0
  671. package/packages/web-dashboard/src/components/focus/FeatureQuestionAnswerPanel.tsx +167 -0
  672. package/packages/web-dashboard/src/components/focus/FocusHeader.tsx +54 -0
  673. package/packages/web-dashboard/src/components/focus/FocusLayout.tsx +283 -0
  674. package/packages/web-dashboard/src/components/focus/GateFlakinessSummary.tsx +144 -0
  675. package/packages/web-dashboard/src/components/focus/GenealogyTree.tsx +34 -0
  676. package/packages/web-dashboard/src/components/focus/HeroBlock.tsx +67 -0
  677. package/packages/web-dashboard/src/components/focus/LiveAgentConsole.tsx +277 -0
  678. package/packages/web-dashboard/src/components/focus/MergeQueueCard.tsx +78 -0
  679. package/packages/web-dashboard/src/components/focus/OperationalSummaryCard.tsx +227 -0
  680. package/packages/web-dashboard/src/components/focus/PinnedActions.tsx +96 -0
  681. package/packages/web-dashboard/src/components/focus/PlanAmendmentPanel.tsx +250 -0
  682. package/packages/web-dashboard/src/components/focus/PlanProgressPanel.tsx +133 -0
  683. package/packages/web-dashboard/src/components/focus/PlannerArtifactViewer.tsx +158 -0
  684. package/packages/web-dashboard/src/components/focus/PlannerLifecycleHeader.tsx +141 -0
  685. package/packages/web-dashboard/src/components/focus/ProgressSnapshotCard.tsx +113 -0
  686. package/packages/web-dashboard/src/components/focus/RecentMaterialChanges.tsx +69 -0
  687. package/packages/web-dashboard/src/components/focus/RoleLogViewer.tsx +436 -0
  688. package/packages/web-dashboard/src/components/focus/RunHistoryBrowser.tsx +62 -0
  689. package/packages/web-dashboard/src/components/focus/SpecViewer.tsx +172 -0
  690. package/packages/web-dashboard/src/components/focus/TabBar.tsx +33 -0
  691. package/packages/web-dashboard/src/components/focus/UsageBurnChart.tsx +212 -0
  692. package/packages/web-dashboard/src/components/focus/VerificationSummaryCard.tsx +122 -0
  693. package/packages/web-dashboard/src/components/focus/tabs/ChangesTab.tsx +325 -0
  694. package/packages/web-dashboard/src/components/focus/tabs/ConflictsTab.tsx +395 -0
  695. package/packages/web-dashboard/src/components/focus/tabs/GatesQaTab.tsx +38 -0
  696. package/packages/web-dashboard/src/components/focus/tabs/HistoryTab.tsx +213 -0
  697. package/packages/web-dashboard/src/components/focus/tabs/IntakeTab.tsx +429 -0
  698. package/packages/web-dashboard/src/components/focus/tabs/OverviewTab.tsx +217 -0
  699. package/packages/web-dashboard/src/components/focus/tabs/PlanningTab.tsx +390 -0
  700. package/packages/web-dashboard/src/components/focus/tabs/ReviewTab.tsx +497 -0
  701. package/packages/web-dashboard/src/components/focus/tabs/RuntimeTab.tsx +213 -0
  702. package/packages/web-dashboard/src/components/focus/tabs/TranscriptTab.tsx +315 -0
  703. package/packages/web-dashboard/src/components/gate-results.tsx +2 -2
  704. package/packages/web-dashboard/src/components/human-input-panel.tsx +33 -57
  705. package/packages/web-dashboard/src/components/kanban-board.tsx +4 -0
  706. package/packages/web-dashboard/src/components/launch/launch-draft-card.tsx +154 -0
  707. package/packages/web-dashboard/src/components/plan-viewer.tsx +147 -69
  708. package/packages/web-dashboard/src/components/quick-launch-panel.tsx +20 -47
  709. package/packages/web-dashboard/src/components/summary-bar.tsx +30 -76
  710. package/packages/web-dashboard/src/lib/aop-client.ts +2484 -36
  711. package/packages/web-dashboard/src/lib/blocked-state-guidance.ts +475 -0
  712. package/packages/web-dashboard/src/lib/collision-radar.ts +136 -0
  713. package/packages/web-dashboard/src/lib/dashboard-action-states.ts +204 -0
  714. package/packages/web-dashboard/src/lib/dashboard-runtime-client.ts +439 -0
  715. package/packages/web-dashboard/src/lib/dashboard-utils.ts +179 -18
  716. package/packages/web-dashboard/src/lib/drop-zone-utils.ts +92 -0
  717. package/packages/web-dashboard/src/lib/focus-detail-derivations.ts +958 -0
  718. package/packages/web-dashboard/src/lib/focus-view.ts +300 -0
  719. package/packages/web-dashboard/src/lib/health-diagnosis.ts +356 -0
  720. package/packages/web-dashboard/src/lib/launch-contracts.ts +77 -0
  721. package/packages/web-dashboard/src/lib/launch-markdown.ts +103 -0
  722. package/packages/web-dashboard/src/lib/launch-page-preview.ts +89 -0
  723. package/packages/web-dashboard/src/lib/live-feed.ts +1 -1
  724. package/packages/web-dashboard/src/lib/multi-project-config.ts +33 -0
  725. package/packages/web-dashboard/src/lib/orchestrator-tools.ts +881 -60
  726. package/packages/web-dashboard/src/lib/planner-workspace.ts +1285 -0
  727. package/packages/web-dashboard/src/lib/review-contracts.ts +5 -3
  728. package/packages/web-dashboard/src/lib/runtime-files.ts +285 -0
  729. package/packages/web-dashboard/src/lib/tool-catalog.ts +51 -0
  730. package/packages/web-dashboard/src/lib/types.ts +731 -3
  731. package/packages/web-dashboard/src/lib/usage-burn.ts +175 -0
  732. package/packages/web-dashboard/src/lib/worktree-diff.ts +128 -0
  733. package/packages/web-dashboard/src/styles/dashboard.module.css +1742 -459
  734. package/packages/web-dashboard/test/api/actions/route.spec.ts +675 -0
  735. package/packages/web-dashboard/test/api/features/diff.route.spec.ts +57 -0
  736. package/packages/web-dashboard/test/api/features/feature.route.spec.ts +99 -0
  737. package/packages/web-dashboard/test/api/features/live-output.route.spec.ts +123 -0
  738. package/packages/web-dashboard/test/api/features/plan-amend.route.spec.ts +95 -0
  739. package/packages/web-dashboard/test/api/features/planner-workspaces.route.spec.ts +162 -0
  740. package/packages/web-dashboard/test/api/features/question-answer.route.spec.ts +99 -0
  741. package/packages/web-dashboard/test/api/features/triage.route.spec.ts +195 -0
  742. package/packages/web-dashboard/test/api/launch/preview.route.spec.ts +149 -0
  743. package/packages/web-dashboard/test/api/launch/submit.route.spec.ts +382 -0
  744. package/packages/web-dashboard/test/api/runtime/events/route.spec.ts +164 -0
  745. package/packages/web-dashboard/test/api/runtime/operations/route.spec.ts +156 -0
  746. package/packages/web-dashboard/test/api/runtime/runs/route.spec.ts +112 -0
  747. package/packages/web-dashboard/test/components/changes-tab.spec.tsx +76 -0
  748. package/packages/web-dashboard/test/components/command-center-root.spec.tsx +87 -0
  749. package/packages/web-dashboard/test/components/diagnosis-panel.spec.tsx +59 -0
  750. package/packages/web-dashboard/test/components/feature-card.spec.tsx +45 -0
  751. package/packages/web-dashboard/test/components/focus-layout.spec.tsx +299 -0
  752. package/packages/web-dashboard/test/components/gate-results.spec.tsx +39 -0
  753. package/packages/web-dashboard/test/components/gates-qa-tab.spec.tsx +118 -0
  754. package/packages/web-dashboard/test/components/human-input-panel.spec.tsx +54 -0
  755. package/packages/web-dashboard/test/components/intake-tab.spec.tsx +210 -0
  756. package/packages/web-dashboard/test/components/kanban-board.spec.tsx +35 -0
  757. package/packages/web-dashboard/test/components/launch-draft-card.spec.tsx +114 -0
  758. package/packages/web-dashboard/test/components/launch-page.spec.tsx +79 -0
  759. package/packages/web-dashboard/test/components/overview-tab.spec.tsx +236 -0
  760. package/packages/web-dashboard/test/components/planning-tab.spec.tsx +202 -0
  761. package/packages/web-dashboard/test/components/review-tab.spec.tsx +169 -0
  762. package/packages/web-dashboard/test/components/role-log-viewer.spec.ts +42 -0
  763. package/packages/web-dashboard/test/components/runtime-inspector.spec.tsx +22 -0
  764. package/packages/web-dashboard/test/components/runtime-tab.spec.tsx +133 -0
  765. package/packages/web-dashboard/test/components/transcript-tab.spec.tsx +46 -0
  766. package/packages/web-dashboard/test/components/triage-drawer.spec.tsx +159 -0
  767. package/packages/web-dashboard/test/lib/aop-client.spec.ts +235 -0
  768. package/packages/web-dashboard/test/lib/dashboard-runtime-client.spec.ts +144 -0
  769. package/packages/web-dashboard/test/lib/focus-detail-derivations.spec.ts +314 -0
  770. package/packages/web-dashboard/test/lib/focus-view.spec.ts +248 -0
  771. package/packages/web-dashboard/test/lib/health-diagnosis.spec.ts +277 -0
  772. package/packages/web-dashboard/test/lib/launch-markdown.spec.ts +36 -0
  773. package/packages/web-dashboard/test/lib/multi-project-config.spec.ts +54 -0
  774. package/packages/web-dashboard/test/lib/orchestrator-tools.spec.ts +352 -0
  775. package/packages/web-dashboard/test/lib/planner-workspace.spec.ts +289 -0
  776. package/packages/web-dashboard/test/lib/worktree-diff.spec.ts +119 -0
  777. package/packages/web-dashboard/vitest.config.ts +2 -0
  778. package/spec-files/completed/agentic_orchestrator_add_feature_to_active_execution_spec.md +557 -0
  779. package/spec-files/completed/agentic_orchestrator_dashboard_command_center_redesign_spec.md +1147 -0
  780. package/spec-files/completed/agentic_orchestrator_execution_mode_spec.md +18 -16
  781. package/spec-files/completed/agentic_orchestrator_feature_focus_view_track_a_spec.md +672 -0
  782. package/spec-files/completed/agentic_orchestrator_feature_focus_view_track_b_spec.md +794 -0
  783. package/spec-files/completed/agentic_orchestrator_feature_focus_view_track_c_decision_centric_remediation_spec.md +1037 -0
  784. package/spec-files/completed/agentic_orchestrator_feature_focus_view_ux_redesign_spec.md +1432 -0
  785. package/spec-files/completed/agentic_orchestrator_focus_plan_tab_intake_planning_workspace_spec.md +921 -0
  786. package/spec-files/completed/agentic_orchestrator_intentional_collision_override_spec.md +584 -0
  787. package/spec-files/completed/agentic_orchestrator_interactive_planning_intake_and_requirements_verification_spec.md +1185 -0
  788. package/spec-files/completed/agentic_orchestrator_reactive_execution_enrollment_spec.md +864 -0
  789. package/spec-files/{outstanding → completed}/agentic_orchestrator_runtime_inspection_spec.md +92 -19
  790. package/spec-files/completed/agentic_orchestrator_scope_aware_run_lease_spec.md +408 -0
  791. package/spec-files/completed/git-reconciliation-engine.md +827 -0
  792. package/spec-files/outstanding/agentic_orchestrator_dashboard_quick_launch_and_control_surface_spec.md +331 -0
  793. package/spec-files/outstanding/agentic_orchestrator_enterprise_governance_dashboard_spec.md +16 -6
  794. package/spec-files/outstanding/agentic_orchestrator_evidence_integrity_doctor_spec.md +60 -9
  795. package/spec-files/outstanding/agentic_orchestrator_focus_plan_tab_execution_contract_workspace_spec.md +616 -0
  796. package/spec-files/outstanding/agentic_orchestrator_headless_standby_dashboard_runtime_spec.md +310 -0
  797. package/spec-files/outstanding/agentic_orchestrator_human_input_interaction_protocol_spec.md +175 -72
  798. package/spec-files/outstanding/agentic_orchestrator_interactive_rename_cleanup_spec.md +197 -0
  799. package/spec-files/outstanding/agentic_orchestrator_interactive_resume_and_reconciliation_disposition_spec.md +412 -0
  800. package/spec-files/outstanding/agentic_orchestrator_knowledge_canary_spec.md +166 -137
  801. package/spec-files/outstanding/agentic_orchestrator_observability_replay_spec.md +3 -3
  802. package/spec-files/outstanding/agentic_orchestrator_phase_specific_agent_profiles_and_token_telemetry_spec.md +303 -0
  803. package/spec-files/outstanding/agentic_orchestrator_planning_review_quality_spec.md +18 -5
  804. package/spec-files/outstanding/agentic_orchestrator_policy_stratification_spec.md +225 -0
  805. package/spec-files/outstanding/agentic_orchestrator_quality_adoption_execution_spec.md +77 -50
  806. package/spec-files/outstanding/agentic_orchestrator_ready_to_merge_branch_handoff_spec.md +724 -0
  807. package/spec-files/outstanding/agentic_orchestrator_remove_deterministic_mode_spec.md +263 -0
  808. package/spec-files/outstanding/agentic_orchestrator_request_more_context_and_dashboard_human_input_spec.md +456 -0
  809. package/spec-files/outstanding/agentic_orchestrator_spec_coverage_and_reconciliation_enforcement_spec.md +1411 -0
  810. package/spec-files/outstanding/agentic_orchestrator_spec_ordering_agent_spec.md +370 -0
  811. package/spec-files/outstanding/shadow_workspace_implementation_spec.md +1 -1
  812. package/spec-files/progress.md +2026 -120
  813. package/specs/001-runtime-inspection/checklists/requirements.md +35 -0
  814. package/specs/001-runtime-inspection/design.md +338 -0
  815. package/specs/001-runtime-inspection/spec.md +95 -0
  816. package/specs/002-scope-aware-lease/checklists/requirements.md +35 -0
  817. package/specs/002-scope-aware-lease/contracts/lease-registry.schema.json +101 -0
  818. package/specs/002-scope-aware-lease/data-model.md +236 -0
  819. package/specs/002-scope-aware-lease/plan.md +766 -0
  820. package/specs/002-scope-aware-lease/quickstart.md +150 -0
  821. package/specs/002-scope-aware-lease/research.md +135 -0
  822. package/specs/002-scope-aware-lease/spec.md +128 -0
  823. package/specs/002-scope-aware-lease/tasks.md +767 -0
  824. package/tsconfig.json +1 -1
  825. package/vitest.config.ts +28 -0
  826. package/ARCHITECTURE_ADHERENCE_ANALYSIS.md +0 -871
  827. package/packages/web-dashboard/next-env.d.ts +0 -6
  828. package/packages/web-dashboard/src/components/detail-panel.tsx +0 -1124
  829. package/packages/web-dashboard/src/components/review-workspace.tsx +0 -1162
  830. /package/spec-files/{outstanding → completed}/agentic_orchestrator_artifact_database_publishing_spec.md +0 -0
  831. /package/spec-files/{outstanding → completed}/agentic_orchestrator_cli_shell_tab_completion_spec.md +0 -0
  832. /package/spec-files/{outstanding → completed}/agentic_orchestrator_dashboard_diff_and_agent_console_spec.md +0 -0
  833. /package/spec-files/{outstanding → completed}/agentic_orchestrator_performance_improvements_spec.md +0 -0
  834. /package/spec-files/{outstanding → completed}/agentic_orchestrator_persistent_worker_runtime_spec.md +0 -0
  835. /package/spec-files/{outstanding → completed}/agentic_orchestrator_provider_auth_bootstrap_spec.md +0 -0
  836. /package/spec-files/{outstanding → completed}/agentic_orchestrator_real_worker_provider_execution_spec.md +0 -0
@@ -0,0 +1,3176 @@
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import type * as FsModule from '../src/core/fs.js';
6
+
7
+ vi.mock('../src/core/fs.js', async () => {
8
+ const actual = await vi.importActual<typeof FsModule>('../src/core/fs.js');
9
+ return {
10
+ ...actual,
11
+ nowIso: () => '2026-01-01T00:00:00.000Z',
12
+ };
13
+ });
14
+
15
+ import { IntakeService } from '../src/application/services/intake-service.js';
16
+ import { ERROR_CODES } from '../src/core/error-codes.js';
17
+ import { STATUS } from '../src/core/constants.js';
18
+
19
+ interface TestState {
20
+ frontMatter: Record<string, unknown>;
21
+ body: string;
22
+ }
23
+
24
+ function makePort(
25
+ repoRoot: string,
26
+ options: {
27
+ featureId?: string;
28
+ frontMatter?: Record<string, unknown>;
29
+ allowAutoPromotion?: boolean;
30
+ autoPromotionMinConfidence?: 'high' | 'medium' | 'low';
31
+ invalidSchemas?: string[];
32
+ validateSchemaImpl?: (
33
+ schemaName: string,
34
+ value: unknown,
35
+ ) => Promise<{ valid: boolean; errors?: unknown }>;
36
+ } = {},
37
+ ) {
38
+ const featureId = options.featureId ?? 'feature_intake';
39
+ const state: TestState = {
40
+ frontMatter: {
41
+ feature_id: featureId,
42
+ version: 1,
43
+ status: STATUS.INTAKE,
44
+ intake: {
45
+ status: 'not_started',
46
+ bootstrap_manifest_version: null,
47
+ verified_manifest_version: null,
48
+ open_ambiguity_count: 0,
49
+ last_verified_at: null,
50
+ promotion_basis: null,
51
+ },
52
+ ...options.frontMatter,
53
+ },
54
+ body: 'state body',
55
+ };
56
+ let updateCount = 0;
57
+
58
+ return {
59
+ state,
60
+ getUpdateCount: () => updateCount,
61
+ port: {
62
+ featurePath: (id: string) => path.join(repoRoot, '.aop', 'features', id),
63
+ specPath: (id: string) => path.join(repoRoot, '.aop', 'features', id, 'spec.md'),
64
+ withFeatureLock: async <T>(_featureId: string, operation: () => Promise<T>) =>
65
+ await operation(),
66
+ readState: async () => state,
67
+ updateState: async (
68
+ _featureId: string,
69
+ _expectedVersion: number | null,
70
+ updater: (
71
+ frontMatter: Record<string, unknown>,
72
+ body: string,
73
+ ) => Promise<{ frontMatter?: Record<string, unknown>; body?: string }>,
74
+ ) => {
75
+ updateCount += 1;
76
+ const updated = await updater(state.frontMatter, state.body);
77
+ state.frontMatter = updated.frontMatter ?? state.frontMatter;
78
+ state.body = updated.body ?? state.body;
79
+ return state.frontMatter;
80
+ },
81
+ validateSchema: async (schemaName: string, value: unknown) =>
82
+ options.validateSchemaImpl
83
+ ? await options.validateSchemaImpl(schemaName, value)
84
+ : {
85
+ valid: !(options.invalidSchemas ?? []).includes(schemaName),
86
+ errors: [{ schemaName }],
87
+ },
88
+ getPolicySnapshot: () => ({
89
+ planning: {
90
+ intake: {
91
+ allow_auto_promotion: options.allowAutoPromotion ?? false,
92
+ auto_promotion_min_confidence: options.autoPromotionMinConfidence ?? 'high',
93
+ },
94
+ },
95
+ }),
96
+ },
97
+ };
98
+ }
99
+
100
+ async function writeSpec(repoRoot: string, featureId: string, text: string): Promise<void> {
101
+ const specPath = path.join(repoRoot, '.aop', 'features', featureId, 'spec.md');
102
+ await fs.mkdir(path.dirname(specPath), { recursive: true });
103
+ await fs.writeFile(specPath, text, 'utf8');
104
+ }
105
+
106
+ async function writeQuestions(
107
+ repoRoot: string,
108
+ featureId: string,
109
+ items: Array<Record<string, unknown>>,
110
+ ): Promise<void> {
111
+ const questionsPath = path.join(repoRoot, '.aop', 'features', featureId, 'questions.json');
112
+ await fs.mkdir(path.dirname(questionsPath), { recursive: true });
113
+ await fs.writeFile(
114
+ questionsPath,
115
+ JSON.stringify(
116
+ {
117
+ version: 1,
118
+ feature_id: featureId,
119
+ items,
120
+ },
121
+ null,
122
+ 2,
123
+ ),
124
+ 'utf8',
125
+ );
126
+ }
127
+
128
+ async function writePlanArtifacts(
129
+ repoRoot: string,
130
+ featureId: string,
131
+ plan: Record<string, unknown>,
132
+ ): Promise<void> {
133
+ const featurePath = path.join(repoRoot, '.aop', 'features', featureId);
134
+ await fs.mkdir(featurePath, { recursive: true });
135
+ await fs.writeFile(path.join(featurePath, 'plan.json'), JSON.stringify(plan, null, 2), 'utf8');
136
+ await fs.writeFile(path.join(featurePath, 'plan.md'), '# stale plan\n', 'utf8');
137
+ }
138
+
139
+ describe('IntakeService', () => {
140
+ const tempDirs: string[] = [];
141
+
142
+ afterEach(async () => {
143
+ await Promise.all(
144
+ tempDirs.map(async (dir) => await fs.rm(dir, { recursive: true, force: true })),
145
+ );
146
+ });
147
+
148
+ it('persists a bootstrap manifest, creates the default review, and keeps awaiting-input state', async () => {
149
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
150
+ tempDirs.push(repoRoot);
151
+ await writeSpec(
152
+ repoRoot,
153
+ 'feature_intake',
154
+ [
155
+ '# Goals',
156
+ '- `UsageBurnChart` should render the usage trend.',
157
+ '- Maybe allow either manual or auto promotion.',
158
+ ].join('\n'),
159
+ );
160
+ const { state, port } = makePort(repoRoot, {
161
+ frontMatter: {
162
+ status: STATUS.AWAITING_INPUT,
163
+ },
164
+ });
165
+ const service = new IntakeService(port);
166
+
167
+ const manifest = await service.ensureBootstrapManifest('feature_intake');
168
+ const review = JSON.parse(
169
+ await fs.readFile(
170
+ path.join(repoRoot, '.aop', 'features', 'feature_intake', 'intake.review.json'),
171
+ 'utf8',
172
+ ),
173
+ ) as Record<string, unknown>;
174
+
175
+ expect(manifest.obligations).toHaveLength(2);
176
+ expect(manifest.ambiguities).toHaveLength(1);
177
+ expect(review).toMatchObject({
178
+ feature_id: 'feature_intake',
179
+ version: 1,
180
+ status: 'proposed',
181
+ bootstrap_manifest_version: 1,
182
+ verified_manifest_version: null,
183
+ });
184
+ expect(state.frontMatter.intake).toMatchObject({
185
+ status: 'awaiting_input',
186
+ bootstrap_manifest_version: 1,
187
+ verified_manifest_version: null,
188
+ open_ambiguity_count: 1,
189
+ });
190
+ });
191
+
192
+ it('preserves existing verified-intake metadata while refreshing the bootstrap manifest summary', async () => {
193
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
194
+ tempDirs.push(repoRoot);
195
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
196
+ const { state, port } = makePort(repoRoot, {
197
+ frontMatter: {
198
+ intake: {
199
+ status: 'in_progress',
200
+ bootstrap_manifest_version: null,
201
+ verified_manifest_version: 7,
202
+ open_ambiguity_count: 99,
203
+ last_verified_at: '2025-12-31T00:00:00.000Z',
204
+ promotion_basis: 'human_review_confirmed',
205
+ },
206
+ },
207
+ });
208
+ const service = new IntakeService(port);
209
+
210
+ await service.ensureBootstrapManifest('feature_intake');
211
+
212
+ expect(state.frontMatter.intake).toMatchObject({
213
+ status: 'in_progress',
214
+ bootstrap_manifest_version: 1,
215
+ verified_manifest_version: 7,
216
+ last_verified_at: '2025-12-31T00:00:00.000Z',
217
+ promotion_basis: 'human_review_confirmed',
218
+ });
219
+ });
220
+
221
+ it('returns an existing bootstrap manifest without mutating state again', async () => {
222
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
223
+ tempDirs.push(repoRoot);
224
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
225
+ const bootstrapPath = path.join(
226
+ repoRoot,
227
+ '.aop',
228
+ 'features',
229
+ 'feature_intake',
230
+ 'spec.manifest.bootstrap.json',
231
+ );
232
+ await fs.mkdir(path.dirname(bootstrapPath), { recursive: true });
233
+ await fs.writeFile(
234
+ bootstrapPath,
235
+ JSON.stringify(
236
+ {
237
+ feature_id: 'feature_intake',
238
+ manifest_version: 4,
239
+ artifact_type: 'bootstrap',
240
+ generation_mode: 'bootstrap',
241
+ generated_at: '2026-01-01T00:00:00.000Z',
242
+ source_hash: 'hash',
243
+ obligations: [],
244
+ ambiguities: [],
245
+ },
246
+ null,
247
+ 2,
248
+ ),
249
+ 'utf8',
250
+ );
251
+ const { getUpdateCount, port } = makePort(repoRoot);
252
+ const service = new IntakeService(port);
253
+
254
+ const manifest = await service.ensureBootstrapManifest('feature_intake');
255
+
256
+ expect(manifest.manifest_version).toBe(4);
257
+ expect(getUpdateCount()).toBe(0);
258
+ });
259
+
260
+ it('reuses a bootstrap manifest that appears while the feature lock is acquired', async () => {
261
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
262
+ tempDirs.push(repoRoot);
263
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
264
+ const bootstrapPath = path.join(
265
+ repoRoot,
266
+ '.aop',
267
+ 'features',
268
+ 'feature_intake',
269
+ 'spec.manifest.bootstrap.json',
270
+ );
271
+ const reviewPath = path.join(
272
+ repoRoot,
273
+ '.aop',
274
+ 'features',
275
+ 'feature_intake',
276
+ 'intake.review.json',
277
+ );
278
+ const { getUpdateCount, port } = makePort(repoRoot);
279
+ let injected = false;
280
+ port.withFeatureLock = async <T>(_featureId: string, operation: () => Promise<T>) => {
281
+ if (!injected) {
282
+ injected = true;
283
+ await fs.mkdir(path.dirname(bootstrapPath), { recursive: true });
284
+ await fs.writeFile(
285
+ bootstrapPath,
286
+ JSON.stringify(
287
+ {
288
+ feature_id: 'feature_intake',
289
+ manifest_version: 9,
290
+ artifact_type: 'bootstrap',
291
+ generation_mode: 'bootstrap',
292
+ generated_at: '2026-01-01T00:00:00.000Z',
293
+ source_hash: 'hash',
294
+ obligations: [],
295
+ ambiguities: [],
296
+ },
297
+ null,
298
+ 2,
299
+ ),
300
+ 'utf8',
301
+ );
302
+ await fs.writeFile(
303
+ reviewPath,
304
+ JSON.stringify(
305
+ {
306
+ feature_id: 'feature_intake',
307
+ version: 1,
308
+ status: 'proposed',
309
+ questions_open: 0,
310
+ questions_resolved: 0,
311
+ clarification_answers: [],
312
+ ambiguities: [],
313
+ bootstrap_manifest_version: 9,
314
+ verified_manifest_version: null,
315
+ promotion_basis: null,
316
+ last_updated_at: '2026-01-01T00:00:00.000Z',
317
+ },
318
+ null,
319
+ 2,
320
+ ),
321
+ 'utf8',
322
+ );
323
+ }
324
+ return await operation();
325
+ };
326
+ const service = new IntakeService(port);
327
+
328
+ const manifest = await service.ensureBootstrapManifest('feature_intake');
329
+
330
+ expect(manifest.manifest_version).toBe(9);
331
+ expect(getUpdateCount()).toBe(1);
332
+ });
333
+
334
+ it('creates a missing intake review when a bootstrap manifest already exists', async () => {
335
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
336
+ tempDirs.push(repoRoot);
337
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
338
+ const bootstrapPath = path.join(
339
+ repoRoot,
340
+ '.aop',
341
+ 'features',
342
+ 'feature_intake',
343
+ 'spec.manifest.bootstrap.json',
344
+ );
345
+ await fs.mkdir(path.dirname(bootstrapPath), { recursive: true });
346
+ await fs.writeFile(
347
+ bootstrapPath,
348
+ JSON.stringify(
349
+ {
350
+ feature_id: 'feature_intake',
351
+ manifest_version: 2,
352
+ artifact_type: 'bootstrap',
353
+ generation_mode: 'bootstrap',
354
+ generated_at: '2026-01-01T00:00:00.000Z',
355
+ source_hash: 'hash',
356
+ obligations: [],
357
+ ambiguities: [],
358
+ },
359
+ null,
360
+ 2,
361
+ ),
362
+ 'utf8',
363
+ );
364
+ const { port } = makePort(repoRoot, {
365
+ allowAutoPromotion: false,
366
+ });
367
+ const service = new IntakeService(port);
368
+
369
+ const result = await service.ensureIntakeArtifacts('feature_intake');
370
+ const review = JSON.parse(
371
+ await fs.readFile(
372
+ path.join(repoRoot, '.aop', 'features', 'feature_intake', 'intake.review.json'),
373
+ 'utf8',
374
+ ),
375
+ ) as Record<string, unknown>;
376
+
377
+ expect(result.review).toMatchObject({
378
+ feature_id: 'feature_intake',
379
+ bootstrap_manifest_version: 2,
380
+ status: 'proposed',
381
+ });
382
+ expect(review).toMatchObject({
383
+ version: 1,
384
+ bootstrap_manifest_version: 2,
385
+ status: 'proposed',
386
+ });
387
+ });
388
+
389
+ it('auto-promotes a clean bootstrap manifest into a verified manifest when policy allows it', async () => {
390
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
391
+ tempDirs.push(repoRoot);
392
+ await writeSpec(
393
+ repoRoot,
394
+ 'feature_intake',
395
+ '- `UsageBurnChart` must render an explicit intake summary before planning.',
396
+ );
397
+ const { state, port } = makePort(repoRoot, {
398
+ allowAutoPromotion: true,
399
+ });
400
+ const service = new IntakeService(port);
401
+
402
+ const result = await service.ensureIntakeArtifacts('feature_intake');
403
+ const verifiedManifest = JSON.parse(
404
+ await fs.readFile(
405
+ path.join(repoRoot, '.aop', 'features', 'feature_intake', 'spec.manifest.verified.json'),
406
+ 'utf8',
407
+ ),
408
+ ) as Record<string, unknown>;
409
+ const review = JSON.parse(
410
+ await fs.readFile(
411
+ path.join(repoRoot, '.aop', 'features', 'feature_intake', 'intake.review.json'),
412
+ 'utf8',
413
+ ),
414
+ ) as Record<string, unknown>;
415
+
416
+ expect(result.verifiedManifest).not.toBeNull();
417
+ expect(result.summary).toMatchObject({
418
+ status: 'verified',
419
+ bootstrap_manifest_version: 1,
420
+ verified_manifest_version: 1,
421
+ open_ambiguity_count: 0,
422
+ promotion_basis: 'policy_approved_auto_promotion',
423
+ });
424
+ expect(state.frontMatter.status).toBe(STATUS.PLANNING);
425
+ expect(state.frontMatter.intake).toMatchObject({
426
+ status: 'verified',
427
+ verified_manifest_version: 1,
428
+ promotion_basis: 'policy_approved_auto_promotion',
429
+ });
430
+ expect(verifiedManifest).toMatchObject({
431
+ artifact_type: 'verified',
432
+ verification_basis: 'policy_approved_auto_promotion',
433
+ source_bootstrap_version: 1,
434
+ });
435
+ expect(review).toMatchObject({
436
+ status: 'verified',
437
+ verified_manifest_version: 1,
438
+ promotion_basis: 'policy_approved_auto_promotion',
439
+ });
440
+ });
441
+
442
+ it('keeps intake in progress when auto-promotion is disabled', async () => {
443
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
444
+ tempDirs.push(repoRoot);
445
+ await writeSpec(
446
+ repoRoot,
447
+ 'feature_intake',
448
+ 'The system should normalize intake questions into a verified manifest before planning.',
449
+ );
450
+ const { state, port } = makePort(repoRoot, {
451
+ allowAutoPromotion: false,
452
+ });
453
+ const service = new IntakeService(port);
454
+
455
+ const result = await service.ensureIntakeArtifacts('feature_intake');
456
+
457
+ expect(result.verifiedManifest).toBeNull();
458
+ expect(result.summary).toMatchObject({
459
+ status: 'in_progress',
460
+ bootstrap_manifest_version: 1,
461
+ verified_manifest_version: null,
462
+ });
463
+ expect(state.frontMatter.status).toBe(STATUS.INTAKE);
464
+ });
465
+
466
+ it('keeps intake in progress when auto-promotion is allowed but obligations miss the confidence threshold', async () => {
467
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
468
+ tempDirs.push(repoRoot);
469
+ await writeSpec(
470
+ repoRoot,
471
+ 'feature_intake',
472
+ 'The system should normalize human input before planning begins.',
473
+ );
474
+ const { state, port } = makePort(repoRoot, {
475
+ allowAutoPromotion: true,
476
+ autoPromotionMinConfidence: 'high',
477
+ });
478
+ const service = new IntakeService(port);
479
+
480
+ const result = await service.ensureIntakeArtifacts('feature_intake');
481
+
482
+ expect(result.bootstrapManifest.obligations).toHaveLength(1);
483
+ expect(result.bootstrapManifest.obligations[0]?.confidence).toBe('low');
484
+ expect(result.verifiedManifest).toBeNull();
485
+ expect(result.summary.status).toBe('in_progress');
486
+ expect(state.frontMatter.status).toBe(STATUS.INTAKE);
487
+ });
488
+
489
+ it('supports cross-platform intake-to-planning fixtures for TypeScript, Python, Java, and CLI specs', async () => {
490
+ const fixtures = [
491
+ {
492
+ featureId: 'feature_typescript',
493
+ spec: [
494
+ '## `UsageBurnChart`',
495
+ '- `FocusView` should render the chart and spec summary.',
496
+ '- Maybe expose `GET /api/focus-view` for lazy data loading.',
497
+ ].join('\n'),
498
+ },
499
+ {
500
+ featureId: 'feature_python',
501
+ spec: [
502
+ '## `JobRunner`',
503
+ '- `POST /jobs` should enqueue work and persist the request payload.',
504
+ '- Maybe allow either sync execution or queue-backed execution.',
505
+ ].join('\n'),
506
+ },
507
+ {
508
+ featureId: 'feature_java',
509
+ spec: [
510
+ '## `MergeQueueController`',
511
+ '- `MergeQueueService` must publish queue updates to the audit stream.',
512
+ '- Maybe expose `/api/merge-queue` only when queue depth exceeds one.',
513
+ ].join('\n'),
514
+ },
515
+ {
516
+ featureId: 'feature_cli',
517
+ spec: [
518
+ '## `aop intake`',
519
+ '- `policy.yaml` should support `planning.intake` defaults.',
520
+ '- Maybe allow either `--answer` text or JSON object payloads.',
521
+ ].join('\n'),
522
+ },
523
+ ] as const;
524
+
525
+ for (const fixture of fixtures) {
526
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
527
+ tempDirs.push(repoRoot);
528
+ await writeSpec(repoRoot, fixture.featureId, fixture.spec);
529
+ const { state, port } = makePort(repoRoot, {
530
+ featureId: fixture.featureId,
531
+ allowAutoPromotion: false,
532
+ });
533
+ const service = new IntakeService(port);
534
+
535
+ const intake = await service.ensureIntakeArtifacts(fixture.featureId);
536
+ expect(intake.bootstrapManifest.obligations.length).toBeGreaterThan(0);
537
+ expect(intake.bootstrapManifest.ambiguities.length).toBeGreaterThan(0);
538
+ await writeQuestions(repoRoot, fixture.featureId, [
539
+ {
540
+ question_id: 'q_intake_resolved',
541
+ status: 'answered',
542
+ blocking: true,
543
+ question_type: 'clarification',
544
+ role: 'planner',
545
+ phase: 'intake',
546
+ request_action: 'ask_user_input',
547
+ session_id: 'session-planner-1',
548
+ prompt: 'Clarify grouped intake ambiguities',
549
+ details: {
550
+ ambiguity_ids: intake.bootstrapManifest.ambiguities.map((ambiguity) => ambiguity.id),
551
+ },
552
+ expected_answer: { kind: 'free_text' },
553
+ created_at: '2026-01-01T00:00:00.000Z',
554
+ expires_at: '2026-01-01T01:00:00.000Z',
555
+ answer: 'Operator confirmed the intended baseline scope.',
556
+ answered_at: '2026-01-01T00:05:00.000Z',
557
+ answered_by: 'operator:alice',
558
+ resume_status: 'intake',
559
+ resume_phase: 'intake',
560
+ },
561
+ ]);
562
+
563
+ const promoted = await service.intakeSubmit(fixture.featureId, {
564
+ verified_manifest: {
565
+ feature_id: fixture.featureId,
566
+ manifest_version: 1,
567
+ artifact_type: 'verified',
568
+ verification_basis: 'questions_resolved',
569
+ verified_at: '2026-01-01T00:00:00.000Z',
570
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
571
+ obligations: intake.bootstrapManifest.obligations,
572
+ },
573
+ open_ambiguities: [],
574
+ resolved_ambiguities: intake.bootstrapManifest.ambiguities.map((ambiguity) => ({
575
+ ...ambiguity,
576
+ status: 'resolved',
577
+ })),
578
+ requires_user_input: false,
579
+ });
580
+
581
+ expect(promoted.data.feature_status).toBe(STATUS.PLANNING);
582
+ expect(state.frontMatter.status).toBe(STATUS.PLANNING);
583
+ expect(state.frontMatter.intake).toMatchObject({
584
+ status: 'verified',
585
+ verified_manifest_version: 1,
586
+ open_ambiguity_count: 0,
587
+ promotion_basis: 'questions_resolved',
588
+ });
589
+ }
590
+ });
591
+
592
+ it('falls back to verified-manifest summary data when intake frontmatter is stale or invalid', async () => {
593
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
594
+ tempDirs.push(repoRoot);
595
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
596
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
597
+ await fs.mkdir(featureDir, { recursive: true });
598
+ await fs.writeFile(
599
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
600
+ JSON.stringify(
601
+ {
602
+ feature_id: 'feature_intake',
603
+ manifest_version: 2,
604
+ artifact_type: 'bootstrap',
605
+ generation_mode: 'bootstrap',
606
+ generated_at: '2026-01-01T00:00:00.000Z',
607
+ source_hash: 'hash',
608
+ obligations: [],
609
+ ambiguities: [{ id: 'amb-1', summary: 'open', status: 'open' }],
610
+ },
611
+ null,
612
+ 2,
613
+ ),
614
+ 'utf8',
615
+ );
616
+ await fs.writeFile(
617
+ path.join(featureDir, 'spec.manifest.verified.json'),
618
+ JSON.stringify(
619
+ {
620
+ feature_id: 'feature_intake',
621
+ manifest_version: 3,
622
+ artifact_type: 'verified',
623
+ verification_basis: 'human_review_confirmed',
624
+ verified_at: '2026-01-01T00:00:00.000Z',
625
+ source_bootstrap_version: 2,
626
+ obligations: [],
627
+ },
628
+ null,
629
+ 2,
630
+ ),
631
+ 'utf8',
632
+ );
633
+ await fs.writeFile(
634
+ path.join(featureDir, 'intake.review.json'),
635
+ JSON.stringify(
636
+ {
637
+ feature_id: 'feature_intake',
638
+ version: 2,
639
+ status: 'verified',
640
+ questions_open: 0,
641
+ questions_resolved: 1,
642
+ clarification_answers: [],
643
+ ambiguities: [{ id: 'amb-1', summary: 'open', status: 'open' }],
644
+ bootstrap_manifest_version: 2,
645
+ verified_manifest_version: 3,
646
+ promotion_basis: 'human_review_confirmed',
647
+ last_updated_at: '2026-01-01T00:00:00.000Z',
648
+ },
649
+ null,
650
+ 2,
651
+ ),
652
+ 'utf8',
653
+ );
654
+ const { port } = makePort(repoRoot, {
655
+ allowAutoPromotion: false,
656
+ frontMatter: {
657
+ status: STATUS.PLANNING,
658
+ intake: {
659
+ status: 'mystery',
660
+ },
661
+ },
662
+ });
663
+ const service = new IntakeService(port);
664
+
665
+ const result = await service.ensureIntakeArtifacts('feature_intake');
666
+
667
+ expect(result.summary).toMatchObject({
668
+ status: 'verified',
669
+ bootstrap_manifest_version: 2,
670
+ verified_manifest_version: 3,
671
+ open_ambiguity_count: 1,
672
+ last_verified_at: '2026-01-01T00:00:00.000Z',
673
+ promotion_basis: 'human_review_confirmed',
674
+ });
675
+ });
676
+
677
+ it('falls back to awaiting-input summary state when no verified manifest exists yet', async () => {
678
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
679
+ tempDirs.push(repoRoot);
680
+ await writeSpec(
681
+ repoRoot,
682
+ 'feature_intake',
683
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
684
+ );
685
+ const { port } = makePort(repoRoot, {
686
+ allowAutoPromotion: false,
687
+ frontMatter: {
688
+ status: STATUS.AWAITING_INPUT,
689
+ intake: {
690
+ status: 'mystery',
691
+ },
692
+ },
693
+ });
694
+ const service = new IntakeService(port);
695
+
696
+ const result = await service.ensureIntakeArtifacts('feature_intake');
697
+
698
+ expect(result.summary).toMatchObject({
699
+ status: 'awaiting_input',
700
+ bootstrap_manifest_version: 1,
701
+ verified_manifest_version: null,
702
+ open_ambiguity_count: 1,
703
+ promotion_basis: null,
704
+ });
705
+ });
706
+
707
+ it('prefers verified-manifest frontmatter provenance when the verified manifest is schema-valid', async () => {
708
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
709
+ tempDirs.push(repoRoot);
710
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
711
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
712
+ await fs.mkdir(featureDir, { recursive: true });
713
+ await fs.writeFile(
714
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
715
+ JSON.stringify(
716
+ {
717
+ feature_id: 'feature_intake',
718
+ manifest_version: 2,
719
+ artifact_type: 'bootstrap',
720
+ generation_mode: 'bootstrap',
721
+ generated_at: '2026-01-01T00:00:00.000Z',
722
+ source_hash: 'hash',
723
+ obligations: [],
724
+ ambiguities: [],
725
+ },
726
+ null,
727
+ 2,
728
+ ),
729
+ 'utf8',
730
+ );
731
+ await fs.writeFile(
732
+ path.join(featureDir, 'spec.manifest.verified.json'),
733
+ JSON.stringify(
734
+ {
735
+ feature_id: 'feature_intake',
736
+ manifest_version: 3,
737
+ artifact_type: 'verified',
738
+ verification_basis: 'human_review_confirmed',
739
+ verified_at: '2026-01-01T01:00:00.000Z',
740
+ source_bootstrap_version: 2,
741
+ obligations: [],
742
+ },
743
+ null,
744
+ 2,
745
+ ),
746
+ 'utf8',
747
+ );
748
+ await fs.writeFile(
749
+ path.join(featureDir, 'intake.review.json'),
750
+ JSON.stringify(
751
+ {
752
+ feature_id: 'feature_intake',
753
+ version: 2,
754
+ status: 'verified',
755
+ questions_open: 0,
756
+ questions_resolved: 0,
757
+ clarification_answers: [],
758
+ ambiguities: [],
759
+ bootstrap_manifest_version: 2,
760
+ verified_manifest_version: 3,
761
+ promotion_basis: 'questions_resolved',
762
+ last_updated_at: '2026-01-01T01:00:00.000Z',
763
+ },
764
+ null,
765
+ 2,
766
+ ),
767
+ 'utf8',
768
+ );
769
+ const { port } = makePort(repoRoot, {
770
+ allowAutoPromotion: false,
771
+ frontMatter: {
772
+ status: STATUS.PLANNING,
773
+ intake: {
774
+ status: 'verified',
775
+ verified_manifest_version: 3,
776
+ last_verified_at: '2026-01-01T02:00:00.000Z',
777
+ promotion_basis: 'human_review_confirmed',
778
+ },
779
+ },
780
+ validateSchemaImpl: async () => ({ valid: true }),
781
+ });
782
+ const service = new IntakeService(port);
783
+
784
+ const result = await service.ensureIntakeArtifacts('feature_intake');
785
+
786
+ expect(result.summary).toMatchObject({
787
+ status: 'verified',
788
+ verified_manifest_version: 3,
789
+ last_verified_at: '2026-01-01T02:00:00.000Z',
790
+ promotion_basis: 'human_review_confirmed',
791
+ });
792
+ });
793
+
794
+ it('ignores malformed verified manifests when ensuring intake artifacts', async () => {
795
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
796
+ tempDirs.push(repoRoot);
797
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
798
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
799
+ await fs.mkdir(featureDir, { recursive: true });
800
+ await fs.writeFile(
801
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
802
+ JSON.stringify(
803
+ {
804
+ feature_id: 'feature_intake',
805
+ manifest_version: 1,
806
+ artifact_type: 'bootstrap',
807
+ generation_mode: 'bootstrap',
808
+ generated_at: '2026-01-01T00:00:00.000Z',
809
+ source_hash: 'hash',
810
+ obligations: [
811
+ {
812
+ obligation_id: 'OBL-001',
813
+ kind: 'behavior',
814
+ name: 'Plan tab visibility',
815
+ description: 'Keep the plan tab visible.',
816
+ source_refs: [{ line_start: 1, line_end: 1, heading: 'Overview' }],
817
+ verification_hint: 'required',
818
+ confidence: 'high',
819
+ },
820
+ ],
821
+ ambiguities: [
822
+ {
823
+ id: 'AMB-021',
824
+ summary: 'Clarify plan tab visibility.',
825
+ status: 'open',
826
+ obligation_ids: ['OBL-001'],
827
+ },
828
+ ],
829
+ },
830
+ null,
831
+ 2,
832
+ ),
833
+ 'utf8',
834
+ );
835
+ await fs.writeFile(
836
+ path.join(featureDir, 'spec.manifest.verified.json'),
837
+ JSON.stringify(
838
+ {
839
+ feature_id: 'feature_intake',
840
+ manifest_version: 1,
841
+ artifact_type: 'verified',
842
+ verification_basis: 'pending_confirmation',
843
+ verified_at: null,
844
+ source_bootstrap_version: 1,
845
+ obligations: [
846
+ {
847
+ obligation_id: 'OBL-V01',
848
+ kind: 'behavior',
849
+ name: 'Draft plan tab visibility',
850
+ description: 'Draft verified manifest should not be treated as canonical.',
851
+ source_refs: [{ line_start: 1, line_end: 1, heading: 'Overview' }],
852
+ verification_hint: 'required',
853
+ confidence: 'high',
854
+ },
855
+ ],
856
+ },
857
+ null,
858
+ 2,
859
+ ),
860
+ 'utf8',
861
+ );
862
+ await fs.writeFile(
863
+ path.join(featureDir, 'intake.review.json'),
864
+ JSON.stringify(
865
+ {
866
+ feature_id: 'feature_intake',
867
+ version: 2,
868
+ status: 'verified',
869
+ questions_open: 0,
870
+ questions_resolved: 0,
871
+ clarification_answers: [],
872
+ ambiguities: [
873
+ {
874
+ id: 'AMB-021',
875
+ summary: 'Clarify plan tab visibility.',
876
+ status: 'open',
877
+ obligation_ids: ['OBL-001'],
878
+ },
879
+ ],
880
+ bootstrap_manifest_version: 1,
881
+ verified_manifest_version: 1,
882
+ promotion_basis: 'pending_confirmation',
883
+ last_updated_at: '2026-01-01T00:00:00.000Z',
884
+ },
885
+ null,
886
+ 2,
887
+ ),
888
+ 'utf8',
889
+ );
890
+ const { port } = makePort(repoRoot, {
891
+ allowAutoPromotion: false,
892
+ frontMatter: {
893
+ status: STATUS.PLANNING,
894
+ intake: {
895
+ status: 'verified',
896
+ promotion_basis: 'pending_confirmation',
897
+ },
898
+ },
899
+ validateSchemaImpl: async (schemaName, value) => {
900
+ if (schemaName !== 'spec.manifest.verified.schema.json') {
901
+ return { valid: true };
902
+ }
903
+ const record = value as Record<string, unknown>;
904
+ const verificationBasis = record.verification_basis;
905
+ const verifiedAt = record.verified_at;
906
+ const obligations = Array.isArray(record.obligations) ? record.obligations : [];
907
+ const obligationsValid = obligations.every((obligation) => {
908
+ const obligationRecord = obligation as Record<string, unknown>;
909
+ return (
910
+ typeof obligationRecord.obligation_id === 'string' &&
911
+ /^OBL-\d{3,}$/.test(obligationRecord.obligation_id)
912
+ );
913
+ });
914
+ const basisValid =
915
+ verificationBasis === 'structured_spec' ||
916
+ verificationBasis === 'questions_resolved' ||
917
+ verificationBasis === 'policy_approved_auto_promotion' ||
918
+ verificationBasis === 'human_review_confirmed';
919
+ return {
920
+ valid:
921
+ basisValid &&
922
+ typeof verifiedAt === 'string' &&
923
+ verifiedAt.length > 0 &&
924
+ obligationsValid,
925
+ };
926
+ },
927
+ });
928
+ const service = new IntakeService(port);
929
+
930
+ const result = await service.ensureIntakeArtifacts('feature_intake');
931
+
932
+ expect(result.verifiedManifest).toBeNull();
933
+ expect(result.summary).toMatchObject({
934
+ status: 'in_progress',
935
+ bootstrap_manifest_version: 1,
936
+ verified_manifest_version: null,
937
+ promotion_basis: null,
938
+ });
939
+ const review = JSON.parse(
940
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
941
+ ) as {
942
+ status: string;
943
+ promotion_basis: string | null;
944
+ verified_manifest_version: number | null;
945
+ };
946
+ expect(review.status).toBe('proposed');
947
+ expect(review.promotion_basis).toBeNull();
948
+ expect(review.verified_manifest_version).toBeNull();
949
+ });
950
+
951
+ it('syncs answered intake clarification questions into the intake review bridge', async () => {
952
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
953
+ tempDirs.push(repoRoot);
954
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
955
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
956
+ await fs.mkdir(featureDir, { recursive: true });
957
+ await fs.writeFile(
958
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
959
+ JSON.stringify(
960
+ {
961
+ feature_id: 'feature_intake',
962
+ manifest_version: 1,
963
+ artifact_type: 'bootstrap',
964
+ generation_mode: 'bootstrap',
965
+ generated_at: '2026-01-01T00:00:00.000Z',
966
+ source_hash: 'hash',
967
+ obligations: [
968
+ {
969
+ obligation_id: 'OBL-125',
970
+ kind: 'behavior',
971
+ name: 'usage status',
972
+ description: 'Track usage status labels',
973
+ source_refs: [{ line_start: 1, line_end: 1, heading: 'Overview' }],
974
+ verification_hint: 'required',
975
+ confidence: 'high',
976
+ },
977
+ ],
978
+ ambiguities: [
979
+ {
980
+ id: 'AMB-110',
981
+ summary: 'Derived USD remains optional and secondary.',
982
+ status: 'open',
983
+ },
984
+ {
985
+ id: 'AMB-303',
986
+ summary: 'Always label reported, estimated, or unavailable.',
987
+ status: 'open',
988
+ obligation_ids: ['OBL-125'],
989
+ },
990
+ ],
991
+ },
992
+ null,
993
+ 2,
994
+ ),
995
+ 'utf8',
996
+ );
997
+ await writeQuestions(repoRoot, 'feature_intake', [
998
+ {
999
+ question_id: 'q_answered',
1000
+ status: 'answered',
1001
+ question_type: 'clarification',
1002
+ phase: STATUS.INTAKE,
1003
+ resume_status: STATUS.INTAKE,
1004
+ resume_phase: STATUS.INTAKE,
1005
+ prompt: 'Clarify AMB-110 and AMB-303',
1006
+ answer: 'AMB-110 stays optional. AMB-303 always labels status.',
1007
+ answered_at: '2026-01-01T00:05:00.000Z',
1008
+ answered_by: 'dashboard:triage',
1009
+ details: {
1010
+ ambiguity_ids: ['AMB-110', 'AMB-303'],
1011
+ obligation_ids: ['OBL-125'],
1012
+ },
1013
+ },
1014
+ {
1015
+ question_id: 'q_open',
1016
+ status: 'open',
1017
+ question_type: 'clarification',
1018
+ phase: STATUS.INTAKE,
1019
+ resume_status: STATUS.INTAKE,
1020
+ resume_phase: STATUS.INTAKE,
1021
+ prompt: 'Follow-up on AMB-303',
1022
+ details: {
1023
+ ambiguity_ids: ['AMB-303'],
1024
+ obligation_ids: ['OBL-125'],
1025
+ },
1026
+ },
1027
+ ]);
1028
+ const { port } = makePort(repoRoot, {
1029
+ frontMatter: {
1030
+ status: STATUS.AWAITING_INPUT,
1031
+ intake: {
1032
+ status: 'awaiting_input',
1033
+ bootstrap_manifest_version: 1,
1034
+ verified_manifest_version: null,
1035
+ open_ambiguity_count: 2,
1036
+ last_verified_at: null,
1037
+ promotion_basis: null,
1038
+ },
1039
+ },
1040
+ });
1041
+ const service = new IntakeService(port);
1042
+
1043
+ const result = await service.ensureIntakeArtifacts('feature_intake');
1044
+ const review = JSON.parse(
1045
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1046
+ ) as Record<string, unknown>;
1047
+
1048
+ expect(result.review).toMatchObject({
1049
+ status: 'awaiting_input',
1050
+ questions_open: 1,
1051
+ questions_resolved: 1,
1052
+ });
1053
+ expect(review).toMatchObject({
1054
+ status: 'awaiting_input',
1055
+ questions_open: 1,
1056
+ questions_resolved: 1,
1057
+ clarification_answers: [
1058
+ expect.objectContaining({
1059
+ question_id: 'q_answered',
1060
+ ambiguity_ids: ['AMB-110', 'AMB-303'],
1061
+ obligation_ids: ['OBL-125'],
1062
+ answer: 'AMB-110 stays optional. AMB-303 always labels status.',
1063
+ resolution_status: 'candidate',
1064
+ }),
1065
+ ],
1066
+ });
1067
+ });
1068
+
1069
+ it('preserves existing clarification answers when no questions artifact exists', async () => {
1070
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1071
+ tempDirs.push(repoRoot);
1072
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1073
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1074
+ await fs.mkdir(featureDir, { recursive: true });
1075
+ await fs.writeFile(
1076
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1077
+ JSON.stringify(
1078
+ {
1079
+ feature_id: 'feature_intake',
1080
+ manifest_version: 1,
1081
+ artifact_type: 'bootstrap',
1082
+ generation_mode: 'bootstrap',
1083
+ generated_at: '2026-01-01T00:00:00.000Z',
1084
+ source_hash: 'hash',
1085
+ obligations: [],
1086
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1087
+ },
1088
+ null,
1089
+ 2,
1090
+ ),
1091
+ 'utf8',
1092
+ );
1093
+ await fs.writeFile(
1094
+ path.join(featureDir, 'intake.review.json'),
1095
+ JSON.stringify(
1096
+ {
1097
+ feature_id: 'feature_intake',
1098
+ version: 3,
1099
+ status: 'proposed',
1100
+ questions_open: 0,
1101
+ questions_resolved: 1,
1102
+ clarification_answers: [
1103
+ {
1104
+ question_id: 'q_preserved',
1105
+ ambiguity_ids: ['AMB-110'],
1106
+ obligation_ids: [],
1107
+ prompt: 'Clarify token units',
1108
+ answer: 'Use tokens only.',
1109
+ answered_at: '2026-01-01T00:05:00.000Z',
1110
+ answered_by: 'dashboard:triage',
1111
+ resolution_status: 'candidate',
1112
+ },
1113
+ ],
1114
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1115
+ bootstrap_manifest_version: 1,
1116
+ verified_manifest_version: null,
1117
+ promotion_basis: null,
1118
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1119
+ },
1120
+ null,
1121
+ 2,
1122
+ ),
1123
+ 'utf8',
1124
+ );
1125
+ const { port } = makePort(repoRoot);
1126
+ const service = new IntakeService(port);
1127
+
1128
+ await service.syncReviewFromQuestions('feature_intake');
1129
+
1130
+ const review = JSON.parse(
1131
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1132
+ ) as Record<string, unknown>;
1133
+ expect(review).toMatchObject({
1134
+ version: 3,
1135
+ questions_open: 0,
1136
+ questions_resolved: 1,
1137
+ clarification_answers: [
1138
+ expect.objectContaining({
1139
+ question_id: 'q_preserved',
1140
+ answer: 'Use tokens only.',
1141
+ resolution_status: 'candidate',
1142
+ }),
1143
+ ],
1144
+ });
1145
+ });
1146
+
1147
+ it('sorts preserved clarification answers from legacy intake review artifacts', async () => {
1148
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1149
+ tempDirs.push(repoRoot);
1150
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1151
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1152
+ await fs.mkdir(featureDir, { recursive: true });
1153
+ await fs.writeFile(
1154
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1155
+ JSON.stringify(
1156
+ {
1157
+ feature_id: 'feature_intake',
1158
+ manifest_version: 1,
1159
+ artifact_type: 'bootstrap',
1160
+ generation_mode: 'bootstrap',
1161
+ generated_at: '2026-01-01T00:00:00.000Z',
1162
+ source_hash: 'hash',
1163
+ obligations: [],
1164
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'resolved' }],
1165
+ },
1166
+ null,
1167
+ 2,
1168
+ ),
1169
+ 'utf8',
1170
+ );
1171
+ await fs.writeFile(
1172
+ path.join(featureDir, 'intake.review.json'),
1173
+ JSON.stringify(
1174
+ {
1175
+ feature_id: 'feature_intake',
1176
+ version: 1,
1177
+ status: 'proposed',
1178
+ questions_open: 0,
1179
+ questions_resolved: 2,
1180
+ clarification_answers: [
1181
+ {
1182
+ question_id: 'q_late',
1183
+ ambiguity_ids: ['AMB-110'],
1184
+ obligation_ids: [],
1185
+ prompt: 'Later clarification',
1186
+ answer: 'Use tokens only.',
1187
+ answered_at: '2026-01-01T00:06:00.000Z',
1188
+ answered_by: 'dashboard:triage',
1189
+ resolution_status: 'candidate',
1190
+ },
1191
+ {
1192
+ question_id: 'q_early',
1193
+ ambiguity_ids: ['AMB-110'],
1194
+ obligation_ids: [],
1195
+ prompt: 'Earlier clarification',
1196
+ answer: 'Start from tokens only.',
1197
+ answered_at: '2026-01-01T00:05:00.000Z',
1198
+ answered_by: 'dashboard:triage',
1199
+ resolution_status: 'candidate',
1200
+ },
1201
+ ],
1202
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'resolved' }],
1203
+ bootstrap_manifest_version: 1,
1204
+ verified_manifest_version: null,
1205
+ promotion_basis: null,
1206
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1207
+ },
1208
+ null,
1209
+ 2,
1210
+ ),
1211
+ 'utf8',
1212
+ );
1213
+ const { port } = makePort(repoRoot);
1214
+ const service = new IntakeService(port);
1215
+
1216
+ await service.syncReviewFromQuestions('feature_intake');
1217
+
1218
+ const review = JSON.parse(
1219
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1220
+ ) as { clarification_answers: Array<{ question_id: string }> };
1221
+ expect(review.clarification_answers.map((item) => item.question_id)).toEqual([
1222
+ 'q_early',
1223
+ 'q_late',
1224
+ ]);
1225
+ });
1226
+
1227
+ it('preserves explicit clarification resolution status values and sorts tied preserved answers by question id', async () => {
1228
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1229
+ tempDirs.push(repoRoot);
1230
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1231
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1232
+ await fs.mkdir(featureDir, { recursive: true });
1233
+ await fs.writeFile(
1234
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1235
+ JSON.stringify(
1236
+ {
1237
+ feature_id: 'feature_intake',
1238
+ manifest_version: 1,
1239
+ artifact_type: 'bootstrap',
1240
+ generation_mode: 'bootstrap',
1241
+ generated_at: '2026-01-01T00:00:00.000Z',
1242
+ source_hash: 'hash',
1243
+ obligations: [],
1244
+ ambiguities: [
1245
+ { id: 'AMB-110', summary: 'Clarify token units', status: 'open' },
1246
+ { id: 'AMB-303', summary: 'Clarify label policy', status: 'open' },
1247
+ ],
1248
+ },
1249
+ null,
1250
+ 2,
1251
+ ),
1252
+ 'utf8',
1253
+ );
1254
+ await fs.writeFile(
1255
+ path.join(featureDir, 'intake.review.json'),
1256
+ JSON.stringify(
1257
+ {
1258
+ feature_id: 'feature_intake',
1259
+ version: 1,
1260
+ status: 'proposed',
1261
+ questions_open: 0,
1262
+ questions_resolved: 2,
1263
+ clarification_answers: [
1264
+ {
1265
+ question_id: 'q_b',
1266
+ ambiguity_ids: ['AMB-110'],
1267
+ obligation_ids: [],
1268
+ prompt: 'Clarify token units',
1269
+ answer: 'Use tokens only.',
1270
+ answered_at: '2026-01-01T00:05:00.000Z',
1271
+ answered_by: 'dashboard:triage',
1272
+ resolution_status: 'candidate',
1273
+ },
1274
+ {
1275
+ question_id: 'q_a',
1276
+ ambiguity_ids: ['AMB-303'],
1277
+ obligation_ids: [],
1278
+ prompt: 'Clarify label policy',
1279
+ answer: 'Always label the metric.',
1280
+ answered_at: '2026-01-01T00:05:00.000Z',
1281
+ answered_by: 'dashboard:triage',
1282
+ resolution_status: 'applied',
1283
+ },
1284
+ ],
1285
+ ambiguities: [
1286
+ { id: 'AMB-110', summary: 'Clarify token units', status: 'open' },
1287
+ { id: 'AMB-303', summary: 'Clarify label policy', status: 'resolved' },
1288
+ ],
1289
+ bootstrap_manifest_version: 1,
1290
+ verified_manifest_version: null,
1291
+ promotion_basis: null,
1292
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1293
+ },
1294
+ null,
1295
+ 2,
1296
+ ),
1297
+ 'utf8',
1298
+ );
1299
+ const { port } = makePort(repoRoot);
1300
+ const service = new IntakeService(port);
1301
+
1302
+ await service.syncReviewFromQuestions('feature_intake');
1303
+
1304
+ const review = JSON.parse(
1305
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1306
+ ) as {
1307
+ clarification_answers: Array<{ question_id: string; resolution_status: string }>;
1308
+ };
1309
+ expect(review.clarification_answers).toEqual([
1310
+ expect.objectContaining({
1311
+ question_id: 'q_a',
1312
+ resolution_status: 'applied',
1313
+ }),
1314
+ expect.objectContaining({
1315
+ question_id: 'q_b',
1316
+ resolution_status: 'candidate',
1317
+ }),
1318
+ ]);
1319
+ });
1320
+
1321
+ it('drops malformed non-array preserved clarification answers during intake review sync', async () => {
1322
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1323
+ tempDirs.push(repoRoot);
1324
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1325
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1326
+ await fs.mkdir(featureDir, { recursive: true });
1327
+ await fs.writeFile(
1328
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1329
+ JSON.stringify(
1330
+ {
1331
+ feature_id: 'feature_intake',
1332
+ manifest_version: 1,
1333
+ artifact_type: 'bootstrap',
1334
+ generation_mode: 'bootstrap',
1335
+ generated_at: '2026-01-01T00:00:00.000Z',
1336
+ source_hash: 'hash',
1337
+ obligations: [],
1338
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1339
+ },
1340
+ null,
1341
+ 2,
1342
+ ),
1343
+ 'utf8',
1344
+ );
1345
+ await fs.writeFile(
1346
+ path.join(featureDir, 'intake.review.json'),
1347
+ JSON.stringify(
1348
+ {
1349
+ feature_id: 'feature_intake',
1350
+ version: 1,
1351
+ status: 'proposed',
1352
+ questions_open: 0,
1353
+ questions_resolved: 1,
1354
+ clarification_answers: {
1355
+ question_id: 'q_bad',
1356
+ },
1357
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1358
+ bootstrap_manifest_version: 1,
1359
+ verified_manifest_version: null,
1360
+ promotion_basis: null,
1361
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1362
+ },
1363
+ null,
1364
+ 2,
1365
+ ),
1366
+ 'utf8',
1367
+ );
1368
+ const { port } = makePort(repoRoot);
1369
+ const service = new IntakeService(port);
1370
+
1371
+ await service.syncReviewFromQuestions('feature_intake');
1372
+
1373
+ const review = JSON.parse(
1374
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1375
+ ) as { clarification_answers: unknown[] };
1376
+ expect(review.clarification_answers).toEqual([]);
1377
+ });
1378
+
1379
+ it('normalizes malformed legacy intake review ambiguities before rewriting the review', async () => {
1380
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1381
+ tempDirs.push(repoRoot);
1382
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1383
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1384
+ await fs.mkdir(featureDir, { recursive: true });
1385
+ await fs.writeFile(
1386
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1387
+ JSON.stringify(
1388
+ {
1389
+ feature_id: 'feature_intake',
1390
+ manifest_version: 1,
1391
+ artifact_type: 'bootstrap',
1392
+ generation_mode: 'bootstrap',
1393
+ generated_at: '2026-01-01T00:00:00.000Z',
1394
+ source_hash: 'hash',
1395
+ obligations: [],
1396
+ ambiguities: [
1397
+ {
1398
+ id: 'AMB-021',
1399
+ summary: 'Clarify phase-specific providers',
1400
+ status: 'open',
1401
+ obligation_ids: ['OBL-004'],
1402
+ },
1403
+ {
1404
+ id: 'AMB-110',
1405
+ summary: 'Clarify token units',
1406
+ status: 'open',
1407
+ obligation_ids: ['OBL-125'],
1408
+ },
1409
+ ],
1410
+ },
1411
+ null,
1412
+ 2,
1413
+ ),
1414
+ 'utf8',
1415
+ );
1416
+ await fs.writeFile(
1417
+ path.join(featureDir, 'intake.review.json'),
1418
+ JSON.stringify(
1419
+ {
1420
+ feature_id: 'feature_intake',
1421
+ version: 2,
1422
+ status: 'proposed',
1423
+ questions_open: 0,
1424
+ questions_resolved: 1,
1425
+ ambiguities: [
1426
+ {
1427
+ id: 'AMB-021',
1428
+ summary: 'Clarify phase-specific providers',
1429
+ status: 'resolved',
1430
+ obligation_ids: ['OBL-004 - planner/builder/qa model split'],
1431
+ resolution: 'Answered via dashboard',
1432
+ },
1433
+ {
1434
+ id: 'AMB-110',
1435
+ summary: 'Clarify token units',
1436
+ status: 'open',
1437
+ obligation_ids: ['bad OBL-125 / OBL-126'],
1438
+ resolution: { status: 'open' },
1439
+ },
1440
+ ],
1441
+ clarification_answers: [
1442
+ {
1443
+ question_id: 'q_legacy',
1444
+ ambiguity_ids: ['AMB-021 answered by operator'],
1445
+ obligation_ids: ['OBL-004 — provider split'],
1446
+ prompt: 'Clarify AMB-021',
1447
+ answer: 'Use role-specific providers.',
1448
+ answered_at: '2026-01-01T00:05:00.000Z',
1449
+ answered_by: 'dashboard:triage',
1450
+ resolution_status: 'candidate',
1451
+ },
1452
+ ],
1453
+ bootstrap_manifest_version: 1,
1454
+ verified_manifest_version: null,
1455
+ promotion_basis: 'questions_answered',
1456
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1457
+ },
1458
+ null,
1459
+ 2,
1460
+ ),
1461
+ 'utf8',
1462
+ );
1463
+ const { port } = makePort(repoRoot);
1464
+ const service = new IntakeService(port);
1465
+
1466
+ await service.syncReviewFromQuestions('feature_intake');
1467
+
1468
+ const review = JSON.parse(
1469
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1470
+ ) as {
1471
+ ambiguities: Array<Record<string, unknown>>;
1472
+ clarification_answers: Array<Record<string, unknown>>;
1473
+ promotion_basis: string | null;
1474
+ };
1475
+ expect(review.promotion_basis).toBeNull();
1476
+ expect(review.ambiguities).toEqual([
1477
+ {
1478
+ id: 'AMB-021',
1479
+ summary: 'Clarify phase-specific providers',
1480
+ status: 'resolved',
1481
+ obligation_ids: ['OBL-004'],
1482
+ },
1483
+ {
1484
+ id: 'AMB-110',
1485
+ summary: 'Clarify token units',
1486
+ status: 'open',
1487
+ obligation_ids: ['OBL-125', 'OBL-126'],
1488
+ },
1489
+ ]);
1490
+ expect(review.clarification_answers).toEqual([
1491
+ expect.objectContaining({
1492
+ question_id: 'q_legacy',
1493
+ ambiguity_ids: ['AMB-021'],
1494
+ obligation_ids: ['OBL-004'],
1495
+ }),
1496
+ ]);
1497
+ expect(review.ambiguities[0]).not.toHaveProperty('resolution');
1498
+ expect(review.ambiguities[1]).not.toHaveProperty('resolution');
1499
+ });
1500
+
1501
+ it('no-ops syncReviewFromQuestions when no bootstrap manifest exists yet', async () => {
1502
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1503
+ tempDirs.push(repoRoot);
1504
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1505
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1506
+ await fs.mkdir(featureDir, { recursive: true });
1507
+ const { port } = makePort(repoRoot);
1508
+ const service = new IntakeService(port);
1509
+
1510
+ await service.syncReviewFromQuestions('feature_intake');
1511
+
1512
+ await expect(fs.access(path.join(featureDir, 'intake.review.json'))).rejects.toBeDefined();
1513
+ });
1514
+
1515
+ it('marks synced clarification answers as applied and sorts ties by question id', async () => {
1516
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1517
+ tempDirs.push(repoRoot);
1518
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1519
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1520
+ await fs.mkdir(featureDir, { recursive: true });
1521
+ await fs.writeFile(
1522
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1523
+ JSON.stringify(
1524
+ {
1525
+ feature_id: 'feature_intake',
1526
+ manifest_version: 1,
1527
+ artifact_type: 'bootstrap',
1528
+ generation_mode: 'bootstrap',
1529
+ generated_at: '2026-01-01T00:00:00.000Z',
1530
+ source_hash: 'hash',
1531
+ obligations: [],
1532
+ ambiguities: [
1533
+ { id: 'AMB-110', summary: 'Clarify token units', status: 'open' },
1534
+ { id: 'AMB-303', summary: 'Clarify label policy', status: 'open' },
1535
+ ],
1536
+ },
1537
+ null,
1538
+ 2,
1539
+ ),
1540
+ 'utf8',
1541
+ );
1542
+ await fs.writeFile(
1543
+ path.join(featureDir, 'intake.review.json'),
1544
+ JSON.stringify(
1545
+ {
1546
+ feature_id: 'feature_intake',
1547
+ version: 1,
1548
+ status: 'proposed',
1549
+ questions_open: 0,
1550
+ questions_resolved: 0,
1551
+ clarification_answers: [],
1552
+ ambiguities: [
1553
+ { id: 'AMB-110', summary: 'Clarify token units', status: 'resolved' },
1554
+ { id: 'AMB-303', summary: 'Clarify label policy', status: 'resolved' },
1555
+ ],
1556
+ bootstrap_manifest_version: 1,
1557
+ verified_manifest_version: null,
1558
+ promotion_basis: null,
1559
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1560
+ },
1561
+ null,
1562
+ 2,
1563
+ ),
1564
+ 'utf8',
1565
+ );
1566
+ await writeQuestions(repoRoot, 'feature_intake', [
1567
+ {
1568
+ question_id: 'q_b',
1569
+ status: 'answered',
1570
+ question_type: 'clarification',
1571
+ phase: STATUS.INTAKE,
1572
+ prompt: 'Clarify AMB-303',
1573
+ answer: 'Always label the status.',
1574
+ answered_at: '2026-01-01T00:05:00.000Z',
1575
+ answered_by: 'dashboard:triage',
1576
+ details: {
1577
+ ambiguity_ids: ['AMB-303'],
1578
+ },
1579
+ },
1580
+ {
1581
+ question_id: 'q_a',
1582
+ status: 'answered',
1583
+ question_type: 'clarification',
1584
+ resume_status: STATUS.INTAKE,
1585
+ prompt: 'Clarify AMB-110',
1586
+ answer: 'Use tokens only.',
1587
+ answered_at: '2026-01-01T00:05:00.000Z',
1588
+ answered_by: 'dashboard:triage',
1589
+ details: {
1590
+ ambiguity_ids: ['AMB-110'],
1591
+ },
1592
+ },
1593
+ ]);
1594
+ const { port } = makePort(repoRoot);
1595
+ const service = new IntakeService(port);
1596
+
1597
+ await service.syncReviewFromQuestions('feature_intake');
1598
+
1599
+ const review = JSON.parse(
1600
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1601
+ ) as Record<string, unknown>;
1602
+ expect(review).toMatchObject({
1603
+ questions_resolved: 2,
1604
+ clarification_answers: [
1605
+ expect.objectContaining({
1606
+ question_id: 'q_a',
1607
+ resolution_status: 'applied',
1608
+ }),
1609
+ expect.objectContaining({
1610
+ question_id: 'q_b',
1611
+ resolution_status: 'applied',
1612
+ }),
1613
+ ],
1614
+ });
1615
+ });
1616
+
1617
+ it('drops malformed clarification answers that are missing required fields during review healing', async () => {
1618
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1619
+ tempDirs.push(repoRoot);
1620
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1621
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1622
+ await fs.mkdir(featureDir, { recursive: true });
1623
+ await fs.writeFile(
1624
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1625
+ JSON.stringify(
1626
+ {
1627
+ feature_id: 'feature_intake',
1628
+ manifest_version: 1,
1629
+ artifact_type: 'bootstrap',
1630
+ generation_mode: 'bootstrap',
1631
+ generated_at: '2026-01-01T00:00:00.000Z',
1632
+ source_hash: 'hash',
1633
+ obligations: [{ obligation_id: 'OBL-001', kind: 'behavior', name: 'one' }],
1634
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1635
+ },
1636
+ null,
1637
+ 2,
1638
+ ),
1639
+ 'utf8',
1640
+ );
1641
+ await fs.writeFile(
1642
+ path.join(featureDir, 'intake.review.json'),
1643
+ JSON.stringify(
1644
+ {
1645
+ feature_id: 'feature_intake',
1646
+ version: 1,
1647
+ status: 'proposed',
1648
+ questions_open: 0,
1649
+ questions_resolved: 0,
1650
+ clarification_answers: [
1651
+ {
1652
+ question_id: 'q_bad',
1653
+ ambiguity_ids: ['AMB-110'],
1654
+ answer: 'Missing prompt should drop this record.',
1655
+ answered_at: '2026-01-01T00:05:00.000Z',
1656
+ answered_by: 'dashboard:triage',
1657
+ },
1658
+ {
1659
+ question_id: 'q_good',
1660
+ ambiguity_ids: ['AMB-110'],
1661
+ obligation_ids: ['OBL-001'],
1662
+ prompt: 'Clarify token units',
1663
+ answer: 'Use tokens only.',
1664
+ answered_at: '2026-01-01T00:06:00.000Z',
1665
+ answered_by: 'dashboard:triage',
1666
+ },
1667
+ ],
1668
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1669
+ bootstrap_manifest_version: 1,
1670
+ verified_manifest_version: null,
1671
+ promotion_basis: null,
1672
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1673
+ },
1674
+ null,
1675
+ 2,
1676
+ ),
1677
+ 'utf8',
1678
+ );
1679
+ const { port } = makePort(repoRoot);
1680
+ const service = new IntakeService(port);
1681
+
1682
+ const result = await service.ensureIntakeArtifacts('feature_intake');
1683
+
1684
+ expect(result.review.clarification_answers).toEqual([
1685
+ expect.objectContaining({
1686
+ question_id: 'q_good',
1687
+ resolution_status: 'candidate',
1688
+ }),
1689
+ ]);
1690
+ });
1691
+
1692
+ it('sorts synced clarification answers by answered_at before question_id', async () => {
1693
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1694
+ tempDirs.push(repoRoot);
1695
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1696
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1697
+ await fs.mkdir(featureDir, { recursive: true });
1698
+ await fs.writeFile(
1699
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1700
+ JSON.stringify(
1701
+ {
1702
+ feature_id: 'feature_intake',
1703
+ manifest_version: 1,
1704
+ artifact_type: 'bootstrap',
1705
+ generation_mode: 'bootstrap',
1706
+ generated_at: '2026-01-01T00:00:00.000Z',
1707
+ source_hash: 'hash',
1708
+ obligations: [],
1709
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1710
+ },
1711
+ null,
1712
+ 2,
1713
+ ),
1714
+ 'utf8',
1715
+ );
1716
+ await writeQuestions(repoRoot, 'feature_intake', [
1717
+ {
1718
+ question_id: 'q_late',
1719
+ status: 'answered',
1720
+ question_type: 'clarification',
1721
+ phase: STATUS.INTAKE,
1722
+ prompt: 'Clarify token units later',
1723
+ answer: 'Use tokens only.',
1724
+ answered_at: '2026-01-01T00:06:00.000Z',
1725
+ answered_by: 'dashboard:triage',
1726
+ details: {
1727
+ ambiguity_ids: ['AMB-110'],
1728
+ },
1729
+ },
1730
+ {
1731
+ question_id: 'q_early',
1732
+ status: 'answered',
1733
+ question_type: 'clarification',
1734
+ resume_status: STATUS.INTAKE,
1735
+ prompt: 'Clarify token units first',
1736
+ answer: 'Start from tokens only.',
1737
+ answered_at: '2026-01-01T00:05:00.000Z',
1738
+ answered_by: 'dashboard:triage',
1739
+ details: {
1740
+ ambiguity_ids: ['AMB-110'],
1741
+ },
1742
+ },
1743
+ ]);
1744
+ const { port } = makePort(repoRoot);
1745
+ const service = new IntakeService(port);
1746
+
1747
+ await service.syncReviewFromQuestions('feature_intake');
1748
+
1749
+ const review = JSON.parse(
1750
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1751
+ ) as { clarification_answers: Array<{ question_id: string }> };
1752
+ expect(review.clarification_answers.map((item) => item.question_id)).toEqual([
1753
+ 'q_early',
1754
+ 'q_late',
1755
+ ]);
1756
+ });
1757
+
1758
+ it('keeps synced review status verified when a verified manifest already exists', async () => {
1759
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1760
+ tempDirs.push(repoRoot);
1761
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1762
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1763
+ await fs.mkdir(featureDir, { recursive: true });
1764
+ await fs.writeFile(
1765
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1766
+ JSON.stringify(
1767
+ {
1768
+ feature_id: 'feature_intake',
1769
+ manifest_version: 1,
1770
+ artifact_type: 'bootstrap',
1771
+ generation_mode: 'bootstrap',
1772
+ generated_at: '2026-01-01T00:00:00.000Z',
1773
+ source_hash: 'hash',
1774
+ obligations: [],
1775
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1776
+ },
1777
+ null,
1778
+ 2,
1779
+ ),
1780
+ 'utf8',
1781
+ );
1782
+ await fs.writeFile(
1783
+ path.join(featureDir, 'spec.manifest.verified.json'),
1784
+ JSON.stringify(
1785
+ {
1786
+ feature_id: 'feature_intake',
1787
+ manifest_version: 2,
1788
+ artifact_type: 'verified',
1789
+ verification_basis: 'human_review_confirmed',
1790
+ verified_at: '2026-01-01T00:10:00.000Z',
1791
+ source_bootstrap_version: 1,
1792
+ obligations: [],
1793
+ },
1794
+ null,
1795
+ 2,
1796
+ ),
1797
+ 'utf8',
1798
+ );
1799
+ await fs.writeFile(
1800
+ path.join(featureDir, 'intake.review.json'),
1801
+ JSON.stringify(
1802
+ {
1803
+ feature_id: 'feature_intake',
1804
+ version: 1,
1805
+ status: 'proposed',
1806
+ questions_open: 0,
1807
+ questions_resolved: 0,
1808
+ clarification_answers: [],
1809
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1810
+ bootstrap_manifest_version: 1,
1811
+ verified_manifest_version: 2,
1812
+ promotion_basis: 'human_review_confirmed',
1813
+ last_updated_at: '2026-01-01T00:00:00.000Z',
1814
+ },
1815
+ null,
1816
+ 2,
1817
+ ),
1818
+ 'utf8',
1819
+ );
1820
+ await writeQuestions(repoRoot, 'feature_intake', [
1821
+ {
1822
+ question_id: 'q_open',
1823
+ status: 'open',
1824
+ question_type: 'clarification',
1825
+ phase: STATUS.INTAKE,
1826
+ prompt: 'Clarify token units',
1827
+ details: {
1828
+ ambiguity_ids: ['AMB-110'],
1829
+ },
1830
+ },
1831
+ ]);
1832
+ const { port } = makePort(repoRoot);
1833
+ const service = new IntakeService(port);
1834
+
1835
+ await service.syncReviewFromQuestions('feature_intake');
1836
+
1837
+ const review = JSON.parse(
1838
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1839
+ ) as Record<string, unknown>;
1840
+ expect(review).toMatchObject({
1841
+ status: 'verified',
1842
+ verified_manifest_version: 2,
1843
+ promotion_basis: 'human_review_confirmed',
1844
+ questions_open: 1,
1845
+ });
1846
+ });
1847
+
1848
+ it('ignores malformed answered clarification fields while preserving valid clarification answers', async () => {
1849
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1850
+ tempDirs.push(repoRoot);
1851
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1852
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1853
+ await fs.mkdir(featureDir, { recursive: true });
1854
+ await fs.writeFile(
1855
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1856
+ JSON.stringify(
1857
+ {
1858
+ feature_id: 'feature_intake',
1859
+ manifest_version: 1,
1860
+ artifact_type: 'bootstrap',
1861
+ generation_mode: 'bootstrap',
1862
+ generated_at: '2026-01-01T00:00:00.000Z',
1863
+ source_hash: 'hash',
1864
+ obligations: [],
1865
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1866
+ },
1867
+ null,
1868
+ 2,
1869
+ ),
1870
+ 'utf8',
1871
+ );
1872
+ await writeQuestions(repoRoot, 'feature_intake', [
1873
+ {
1874
+ question_id: 'q_bad',
1875
+ status: 'answered',
1876
+ question_type: 'clarification',
1877
+ phase: STATUS.INTAKE,
1878
+ prompt: ' ',
1879
+ answer: { value: 'tokens only' },
1880
+ answered_at: '2026-01-01T00:05:00.000Z',
1881
+ answered_by: 'dashboard:triage',
1882
+ details: {
1883
+ ambiguity_ids: ['AMB-110', ' '],
1884
+ obligation_ids: [' '],
1885
+ },
1886
+ },
1887
+ {
1888
+ question_id: 'q_good',
1889
+ status: 'answered',
1890
+ question_type: 'clarification',
1891
+ phase: STATUS.INTAKE,
1892
+ prompt: 'Clarify token units',
1893
+ answer: 'Use tokens only.',
1894
+ answered_at: '2026-01-01T00:06:00.000Z',
1895
+ answered_by: 'dashboard:triage',
1896
+ details: {
1897
+ ambiguity_ids: ['AMB-110'],
1898
+ },
1899
+ },
1900
+ ]);
1901
+ const { port } = makePort(repoRoot);
1902
+ const service = new IntakeService(port);
1903
+
1904
+ await service.syncReviewFromQuestions('feature_intake');
1905
+
1906
+ const review = JSON.parse(
1907
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1908
+ ) as Record<string, unknown>;
1909
+ expect(review).toMatchObject({
1910
+ questions_resolved: 1,
1911
+ clarification_answers: [
1912
+ expect.objectContaining({
1913
+ question_id: 'q_good',
1914
+ }),
1915
+ ],
1916
+ });
1917
+ });
1918
+
1919
+ it('ignores malformed question entries that do not contain a usable status', async () => {
1920
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1921
+ tempDirs.push(repoRoot);
1922
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1923
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1924
+ await fs.mkdir(featureDir, { recursive: true });
1925
+ await fs.writeFile(
1926
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1927
+ JSON.stringify(
1928
+ {
1929
+ feature_id: 'feature_intake',
1930
+ manifest_version: 1,
1931
+ artifact_type: 'bootstrap',
1932
+ generation_mode: 'bootstrap',
1933
+ generated_at: '2026-01-01T00:00:00.000Z',
1934
+ source_hash: 'hash',
1935
+ obligations: [],
1936
+ ambiguities: [{ id: 'AMB-110', summary: 'Clarify token units', status: 'open' }],
1937
+ },
1938
+ null,
1939
+ 2,
1940
+ ),
1941
+ 'utf8',
1942
+ );
1943
+ await writeQuestions(repoRoot, 'feature_intake', [
1944
+ null as unknown as Record<string, unknown>,
1945
+ {
1946
+ question_id: 'q_missing_status',
1947
+ status: ' ',
1948
+ question_type: 'clarification',
1949
+ phase: STATUS.INTAKE,
1950
+ prompt: 'Ignored because the status is blank',
1951
+ details: {
1952
+ ambiguity_ids: ['AMB-110'],
1953
+ },
1954
+ },
1955
+ {
1956
+ question_id: 'q_good',
1957
+ status: 'answered',
1958
+ question_type: 'clarification',
1959
+ phase: STATUS.INTAKE,
1960
+ prompt: 'Clarify token units',
1961
+ answer: 'Use tokens only.',
1962
+ answered_at: '2026-01-01T00:06:00.000Z',
1963
+ answered_by: 'dashboard:triage',
1964
+ details: {
1965
+ ambiguity_ids: ['AMB-110'],
1966
+ },
1967
+ },
1968
+ ]);
1969
+ const { port } = makePort(repoRoot);
1970
+ const service = new IntakeService(port);
1971
+
1972
+ await service.syncReviewFromQuestions('feature_intake');
1973
+
1974
+ const review = JSON.parse(
1975
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
1976
+ ) as Record<string, unknown>;
1977
+ expect(review).toMatchObject({
1978
+ questions_resolved: 1,
1979
+ clarification_answers: [expect.objectContaining({ question_id: 'q_good' })],
1980
+ });
1981
+ });
1982
+
1983
+ it('normalizes non-array and duplicate submitted ambiguities before persisting intake review', async () => {
1984
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
1985
+ tempDirs.push(repoRoot);
1986
+ await writeSpec(repoRoot, 'feature_intake', '# Overview');
1987
+ const featureDir = path.join(repoRoot, '.aop', 'features', 'feature_intake');
1988
+ await fs.mkdir(featureDir, { recursive: true });
1989
+ await fs.writeFile(
1990
+ path.join(featureDir, 'spec.manifest.bootstrap.json'),
1991
+ JSON.stringify(
1992
+ {
1993
+ feature_id: 'feature_intake',
1994
+ manifest_version: 1,
1995
+ artifact_type: 'bootstrap',
1996
+ generation_mode: 'bootstrap',
1997
+ generated_at: '2026-01-01T00:00:00.000Z',
1998
+ source_hash: 'hash',
1999
+ obligations: [],
2000
+ ambiguities: [
2001
+ {
2002
+ id: 'AMB-110',
2003
+ summary: 'Clarify token units',
2004
+ status: 'open',
2005
+ obligation_ids: ['OBL-110'],
2006
+ },
2007
+ {
2008
+ id: 'AMB-303',
2009
+ summary: 'Clarify status labels',
2010
+ status: 'open',
2011
+ obligation_ids: ['OBL-303'],
2012
+ },
2013
+ ],
2014
+ },
2015
+ null,
2016
+ 2,
2017
+ ),
2018
+ 'utf8',
2019
+ );
2020
+ await writeQuestions(repoRoot, 'feature_intake', [
2021
+ {
2022
+ question_id: 'q_110',
2023
+ status: 'answered',
2024
+ question_type: 'clarification',
2025
+ phase: STATUS.INTAKE,
2026
+ prompt: 'Clarify AMB-110',
2027
+ answer: 'Use tokens only.',
2028
+ answered_at: '2026-01-01T00:05:00.000Z',
2029
+ answered_by: 'dashboard:triage',
2030
+ details: {
2031
+ ambiguity_ids: ['AMB-110'],
2032
+ },
2033
+ },
2034
+ {
2035
+ question_id: 'q_303',
2036
+ status: 'answered',
2037
+ question_type: 'clarification',
2038
+ phase: STATUS.INTAKE,
2039
+ prompt: 'Clarify AMB-303',
2040
+ answer: 'Always label the status.',
2041
+ answered_at: '2026-01-01T00:06:00.000Z',
2042
+ answered_by: 'dashboard:triage',
2043
+ details: {
2044
+ ambiguity_ids: ['AMB-303'],
2045
+ },
2046
+ },
2047
+ ]);
2048
+ const { port } = makePort(repoRoot);
2049
+ const service = new IntakeService(port);
2050
+
2051
+ await service.intakeSubmit('feature_intake', {
2052
+ verified_manifest: {
2053
+ feature_id: 'feature_intake',
2054
+ manifest_version: 1,
2055
+ artifact_type: 'verified',
2056
+ verification_basis: 'questions_resolved',
2057
+ verified_at: '2026-01-01T00:10:00.000Z',
2058
+ source_bootstrap_version: 1,
2059
+ obligations: [],
2060
+ },
2061
+ open_ambiguities: null,
2062
+ resolved_ambiguities: [
2063
+ {
2064
+ ambiguity_id: 'AMB-303',
2065
+ summary: 'Clarify status labels',
2066
+ obligation_ids: ['OBL-303 / labels'],
2067
+ resolution: 'Answered',
2068
+ },
2069
+ {
2070
+ ambiguity_id: 'AMB-110',
2071
+ summary: 'Clarify token units',
2072
+ obligation_ids: ['OBL-110 / telemetry'],
2073
+ },
2074
+ {
2075
+ ambiguity_id: 'AMB-303',
2076
+ summary: 'Duplicate ambiguity entry',
2077
+ obligation_ids: ['OBL-303 again'],
2078
+ },
2079
+ ],
2080
+ requires_user_input: false,
2081
+ } as unknown as Parameters<IntakeService['intakeSubmit']>[1]);
2082
+
2083
+ const review = JSON.parse(
2084
+ await fs.readFile(path.join(featureDir, 'intake.review.json'), 'utf8'),
2085
+ ) as { ambiguities: Array<Record<string, unknown>> };
2086
+ expect(review.ambiguities).toEqual([
2087
+ {
2088
+ id: 'AMB-110',
2089
+ summary: 'Clarify token units',
2090
+ status: 'resolved',
2091
+ obligation_ids: ['OBL-110'],
2092
+ },
2093
+ {
2094
+ id: 'AMB-303',
2095
+ summary: 'Clarify status labels',
2096
+ status: 'resolved',
2097
+ obligation_ids: ['OBL-303'],
2098
+ },
2099
+ ]);
2100
+ });
2101
+
2102
+ it('accepts questions_resolved when answered evidence uses a singular ambiguity_id field', async () => {
2103
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2104
+ tempDirs.push(repoRoot);
2105
+ await writeSpec(
2106
+ repoRoot,
2107
+ 'feature_intake',
2108
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2109
+ );
2110
+ const { state, port } = makePort(repoRoot);
2111
+ const service = new IntakeService(port);
2112
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2113
+ const ambiguity = intake.bootstrapManifest.ambiguities[0];
2114
+ expect(ambiguity).toBeDefined();
2115
+ await writeQuestions(repoRoot, 'feature_intake', [
2116
+ {
2117
+ question_id: 'q_intake_answered',
2118
+ status: 'answered',
2119
+ question_type: 'clarification',
2120
+ phase: STATUS.INTAKE,
2121
+ prompt: 'Clarify the ambiguity',
2122
+ details: { ambiguity_id: ambiguity?.id },
2123
+ answer: 'Confirmed.',
2124
+ answered_at: '2026-01-01T00:02:00.000Z',
2125
+ answered_by: 'operator:alice',
2126
+ },
2127
+ ]);
2128
+
2129
+ const promoted = await service.intakeSubmit('feature_intake', {
2130
+ verified_manifest: {
2131
+ feature_id: 'feature_intake',
2132
+ manifest_version: 1,
2133
+ artifact_type: 'verified',
2134
+ verification_basis: 'questions_resolved',
2135
+ verified_at: '2026-01-01T00:00:00.000Z',
2136
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2137
+ obligations: intake.bootstrapManifest.obligations,
2138
+ },
2139
+ open_ambiguities: [],
2140
+ resolved_ambiguities: [{ ...ambiguity, status: 'resolved' }],
2141
+ requires_user_input: false,
2142
+ });
2143
+
2144
+ expect(promoted.data.feature_status).toBe(STATUS.PLANNING);
2145
+ expect(state.frontMatter.intake).toMatchObject({
2146
+ status: 'verified',
2147
+ promotion_basis: 'questions_resolved',
2148
+ });
2149
+ });
2150
+
2151
+ it('rejects questions_resolved evidence when the answered intake question predates bootstrap generation', async () => {
2152
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2153
+ tempDirs.push(repoRoot);
2154
+ await writeSpec(
2155
+ repoRoot,
2156
+ 'feature_intake',
2157
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2158
+ );
2159
+ const { port } = makePort(repoRoot);
2160
+ const service = new IntakeService(port);
2161
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2162
+
2163
+ await writeQuestions(repoRoot, 'feature_intake', [
2164
+ {
2165
+ question_id: 'q_intake_answered',
2166
+ status: 'answered',
2167
+ question_type: 'clarification',
2168
+ phase: STATUS.INTAKE,
2169
+ prompt: 'Clarify the ambiguity',
2170
+ details: { ambiguity_ids: intake.bootstrapManifest.ambiguities.map((item) => item.id) },
2171
+ answer: 'Confirmed.',
2172
+ answered_at: '2025-12-31T23:59:59.000Z',
2173
+ answered_by: 'operator:alice',
2174
+ },
2175
+ ]);
2176
+
2177
+ await expect(
2178
+ service.intakeSubmit('feature_intake', {
2179
+ verified_manifest: {
2180
+ feature_id: 'feature_intake',
2181
+ manifest_version: 1,
2182
+ artifact_type: 'verified',
2183
+ verification_basis: 'questions_resolved',
2184
+ verified_at: '2026-01-01T00:00:00.000Z',
2185
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2186
+ obligations: intake.bootstrapManifest.obligations,
2187
+ },
2188
+ open_ambiguities: [],
2189
+ resolved_ambiguities: intake.bootstrapManifest.ambiguities.map((ambiguity) => ({
2190
+ ...ambiguity,
2191
+ status: 'resolved',
2192
+ })),
2193
+ requires_user_input: false,
2194
+ }),
2195
+ ).rejects.toMatchObject({
2196
+ normalizedResponse: {
2197
+ error: {
2198
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2199
+ message: 'verified manifest requires persisted answered intake-question evidence',
2200
+ },
2201
+ },
2202
+ });
2203
+ });
2204
+
2205
+ it('rejects intake promotion when open ambiguities remain even if requires_user_input is false', async () => {
2206
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2207
+ tempDirs.push(repoRoot);
2208
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2209
+ const { port } = makePort(repoRoot);
2210
+ const service = new IntakeService(port);
2211
+ await service.ensureIntakeArtifacts('feature_intake');
2212
+
2213
+ await expect(
2214
+ service.intakeSubmit('feature_intake', {
2215
+ verified_manifest: {
2216
+ feature_id: 'feature_intake',
2217
+ manifest_version: 1,
2218
+ artifact_type: 'verified',
2219
+ verification_basis: 'questions_resolved',
2220
+ verified_at: '2026-01-01T00:00:00.000Z',
2221
+ source_bootstrap_version: 1,
2222
+ obligations: [],
2223
+ },
2224
+ open_ambiguities: [{ id: 'AMB-001', summary: 'still open', status: 'open' }],
2225
+ resolved_ambiguities: [],
2226
+ requires_user_input: false,
2227
+ }),
2228
+ ).rejects.toMatchObject({
2229
+ normalizedResponse: {
2230
+ error: {
2231
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2232
+ message:
2233
+ 'verified manifest cannot be promoted while intake ambiguities remain unresolved',
2234
+ },
2235
+ },
2236
+ });
2237
+ });
2238
+
2239
+ it('rejects structured_spec verification when inferred ambiguities would be resolved by intake submission', async () => {
2240
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2241
+ tempDirs.push(repoRoot);
2242
+ await writeSpec(
2243
+ repoRoot,
2244
+ 'feature_intake',
2245
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2246
+ );
2247
+ const { port } = makePort(repoRoot);
2248
+ const service = new IntakeService(port);
2249
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2250
+
2251
+ await expect(
2252
+ service.intakeSubmit('feature_intake', {
2253
+ verified_manifest: {
2254
+ feature_id: 'feature_intake',
2255
+ manifest_version: 1,
2256
+ artifact_type: 'verified',
2257
+ verification_basis: 'structured_spec',
2258
+ verified_at: '2026-01-01T00:00:00.000Z',
2259
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2260
+ obligations: intake.bootstrapManifest.obligations,
2261
+ },
2262
+ open_ambiguities: [],
2263
+ resolved_ambiguities: intake.bootstrapManifest.ambiguities.map((ambiguity) => ({
2264
+ ...ambiguity,
2265
+ status: 'resolved',
2266
+ })),
2267
+ requires_user_input: false,
2268
+ }),
2269
+ ).rejects.toMatchObject({
2270
+ normalizedResponse: {
2271
+ error: {
2272
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2273
+ message: 'structured_spec verification cannot resolve inferred intake ambiguities',
2274
+ },
2275
+ },
2276
+ });
2277
+ });
2278
+
2279
+ it('accepts structured_spec verification when bootstrap intake has no inferred ambiguities', async () => {
2280
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2281
+ tempDirs.push(repoRoot);
2282
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2283
+ const { state, port } = makePort(repoRoot, {
2284
+ allowAutoPromotion: false,
2285
+ });
2286
+ const service = new IntakeService(port);
2287
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2288
+
2289
+ expect(intake.bootstrapManifest.ambiguities).toHaveLength(0);
2290
+
2291
+ const promoted = await service.intakeSubmit('feature_intake', {
2292
+ verified_manifest: {
2293
+ feature_id: 'feature_intake',
2294
+ manifest_version: 1,
2295
+ artifact_type: 'verified',
2296
+ verification_basis: 'structured_spec',
2297
+ verified_at: '2026-01-01T00:00:00.000Z',
2298
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2299
+ obligations: intake.bootstrapManifest.obligations,
2300
+ },
2301
+ open_ambiguities: [],
2302
+ resolved_ambiguities: [],
2303
+ requires_user_input: false,
2304
+ });
2305
+
2306
+ expect(promoted.data.feature_status).toBe(STATUS.PLANNING);
2307
+ expect(state.frontMatter.intake).toMatchObject({
2308
+ status: 'verified',
2309
+ promotion_basis: 'structured_spec',
2310
+ });
2311
+ });
2312
+
2313
+ it('rejects questions_resolved when answered evidence points at different ambiguity ids', async () => {
2314
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2315
+ tempDirs.push(repoRoot);
2316
+ await writeSpec(
2317
+ repoRoot,
2318
+ 'feature_intake',
2319
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2320
+ );
2321
+ const { port } = makePort(repoRoot);
2322
+ const service = new IntakeService(port);
2323
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2324
+ const resolvedAmbiguity = intake.bootstrapManifest.ambiguities[0];
2325
+ expect(resolvedAmbiguity).toBeDefined();
2326
+ await writeQuestions(repoRoot, 'feature_intake', [
2327
+ {
2328
+ question_id: 'q_mismatch',
2329
+ status: 'answered',
2330
+ question_type: 'clarification',
2331
+ phase: STATUS.INTAKE,
2332
+ prompt: 'Clarify a different ambiguity',
2333
+ details: {
2334
+ ambiguity_ids: ['AMB-999'],
2335
+ },
2336
+ answer: 'Confirmed.',
2337
+ answered_at: '2026-01-01T00:02:00.000Z',
2338
+ answered_by: 'operator:alice',
2339
+ },
2340
+ ]);
2341
+
2342
+ await expect(
2343
+ service.intakeSubmit('feature_intake', {
2344
+ verified_manifest: {
2345
+ feature_id: 'feature_intake',
2346
+ manifest_version: 1,
2347
+ artifact_type: 'verified',
2348
+ verification_basis: 'questions_resolved',
2349
+ verified_at: '2026-01-01T00:00:00.000Z',
2350
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2351
+ obligations: intake.bootstrapManifest.obligations,
2352
+ },
2353
+ open_ambiguities: [],
2354
+ resolved_ambiguities: [{ ...resolvedAmbiguity, status: 'resolved' }],
2355
+ requires_user_input: false,
2356
+ }),
2357
+ ).rejects.toMatchObject({
2358
+ normalizedResponse: {
2359
+ error: {
2360
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2361
+ message: 'resolved intake ambiguities must map to answered intake questions',
2362
+ },
2363
+ },
2364
+ });
2365
+ });
2366
+
2367
+ it('rejects intake promotion when verification still needs user input or open ambiguities remain', async () => {
2368
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2369
+ tempDirs.push(repoRoot);
2370
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2371
+ const reviewPath = path.join(
2372
+ repoRoot,
2373
+ '.aop',
2374
+ 'features',
2375
+ 'feature_intake',
2376
+ 'intake.review.json',
2377
+ );
2378
+ await fs.mkdir(path.dirname(reviewPath), { recursive: true });
2379
+ await fs.writeFile(
2380
+ reviewPath,
2381
+ JSON.stringify(
2382
+ {
2383
+ feature_id: 'feature_intake',
2384
+ version: 4,
2385
+ status: 'awaiting_input',
2386
+ questions_open: 1,
2387
+ questions_resolved: 0,
2388
+ clarification_answers: [],
2389
+ ambiguities: [],
2390
+ bootstrap_manifest_version: 1,
2391
+ verified_manifest_version: null,
2392
+ promotion_basis: null,
2393
+ last_updated_at: '2025-12-31T00:00:00.000Z',
2394
+ },
2395
+ null,
2396
+ 2,
2397
+ ),
2398
+ 'utf8',
2399
+ );
2400
+ const { state, port } = makePort(repoRoot);
2401
+ const service = new IntakeService(port);
2402
+
2403
+ await expect(
2404
+ service.intakeSubmit('feature_intake', {
2405
+ verified_manifest: {
2406
+ feature_id: 'feature_intake',
2407
+ manifest_version: 1,
2408
+ artifact_type: 'verified',
2409
+ verification_basis: 'questions_resolved',
2410
+ verified_at: '2026-01-01T00:00:00.000Z',
2411
+ source_bootstrap_version: 1,
2412
+ obligations: [],
2413
+ },
2414
+ open_ambiguities: [{ id: 'amb-1', summary: 'still open', status: 'open' }],
2415
+ resolved_ambiguities: [{ id: 'amb-2', summary: 'resolved', status: 'resolved' }],
2416
+ requires_user_input: true,
2417
+ }),
2418
+ ).rejects.toMatchObject({
2419
+ normalizedResponse: {
2420
+ error: {
2421
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2422
+ },
2423
+ },
2424
+ });
2425
+ const review = JSON.parse(await fs.readFile(reviewPath, 'utf8')) as Record<string, unknown>;
2426
+
2427
+ expect(review).toMatchObject({
2428
+ version: 4,
2429
+ status: 'awaiting_input',
2430
+ questions_open: 1,
2431
+ questions_resolved: 0,
2432
+ promotion_basis: null,
2433
+ });
2434
+ expect(state.frontMatter.intake).toMatchObject({
2435
+ status: 'in_progress',
2436
+ open_ambiguity_count: 0,
2437
+ promotion_basis: null,
2438
+ });
2439
+ });
2440
+
2441
+ it('rejects questions_resolved promotion without answered intake-question evidence', async () => {
2442
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2443
+ tempDirs.push(repoRoot);
2444
+ await writeSpec(
2445
+ repoRoot,
2446
+ 'feature_intake',
2447
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2448
+ );
2449
+ const { port } = makePort(repoRoot);
2450
+ const service = new IntakeService(port);
2451
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2452
+
2453
+ await expect(
2454
+ service.intakeSubmit('feature_intake', {
2455
+ verified_manifest: {
2456
+ feature_id: 'feature_intake',
2457
+ manifest_version: 1,
2458
+ artifact_type: 'verified',
2459
+ verification_basis: 'questions_resolved',
2460
+ verified_at: '2026-01-01T00:00:00.000Z',
2461
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2462
+ obligations: intake.bootstrapManifest.obligations,
2463
+ },
2464
+ open_ambiguities: [],
2465
+ resolved_ambiguities: intake.bootstrapManifest.ambiguities.map((ambiguity) => ({
2466
+ ...ambiguity,
2467
+ status: 'resolved',
2468
+ })),
2469
+ requires_user_input: false,
2470
+ }),
2471
+ ).rejects.toMatchObject({
2472
+ normalizedResponse: {
2473
+ error: {
2474
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2475
+ details: expect.objectContaining({
2476
+ verification_basis: 'questions_resolved',
2477
+ }),
2478
+ },
2479
+ },
2480
+ });
2481
+ });
2482
+
2483
+ it('rejects questions_resolved promotion when an answered intake question is missing actor metadata', async () => {
2484
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2485
+ tempDirs.push(repoRoot);
2486
+ await writeSpec(
2487
+ repoRoot,
2488
+ 'feature_intake',
2489
+ ['# Goals', '- Maybe allow either manual or auto promotion.'].join('\n'),
2490
+ );
2491
+ const { port } = makePort(repoRoot);
2492
+ const service = new IntakeService(port);
2493
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2494
+
2495
+ await writeQuestions(repoRoot, 'feature_intake', [
2496
+ {
2497
+ question_id: 'q_missing_actor',
2498
+ status: 'answered',
2499
+ question_type: 'clarification',
2500
+ phase: STATUS.INTAKE,
2501
+ prompt: 'Clarify the ambiguity',
2502
+ details: { ambiguity_ids: intake.bootstrapManifest.ambiguities.map((item) => item.id) },
2503
+ answer: 'Confirmed.',
2504
+ answered_at: '2026-01-01T00:02:00.000Z',
2505
+ answered_by: null,
2506
+ },
2507
+ ]);
2508
+
2509
+ await expect(
2510
+ service.intakeSubmit('feature_intake', {
2511
+ verified_manifest: {
2512
+ feature_id: 'feature_intake',
2513
+ manifest_version: 1,
2514
+ artifact_type: 'verified',
2515
+ verification_basis: 'questions_resolved',
2516
+ verified_at: '2026-01-01T00:00:00.000Z',
2517
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2518
+ obligations: intake.bootstrapManifest.obligations,
2519
+ },
2520
+ open_ambiguities: [],
2521
+ resolved_ambiguities: intake.bootstrapManifest.ambiguities.map((ambiguity) => ({
2522
+ ...ambiguity,
2523
+ status: 'resolved',
2524
+ })),
2525
+ requires_user_input: false,
2526
+ }),
2527
+ ).rejects.toMatchObject({
2528
+ normalizedResponse: {
2529
+ error: {
2530
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2531
+ message: 'verified manifest requires persisted answered intake-question evidence',
2532
+ },
2533
+ },
2534
+ });
2535
+ });
2536
+
2537
+ it('rejects human_review_confirmed without explicit manifest-review confirmation evidence', async () => {
2538
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2539
+ tempDirs.push(repoRoot);
2540
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2541
+ const { port } = makePort(repoRoot);
2542
+ const service = new IntakeService(port);
2543
+ await service.ensureIntakeArtifacts('feature_intake');
2544
+ await writeQuestions(repoRoot, 'feature_intake', [
2545
+ {
2546
+ question_id: 'q_intake_answered',
2547
+ status: 'answered',
2548
+ blocking: true,
2549
+ question_type: 'clarification',
2550
+ role: 'planner',
2551
+ phase: 'intake',
2552
+ request_action: 'ask_user_input',
2553
+ session_id: 'session-planner-1',
2554
+ prompt: 'Confirm the chart target',
2555
+ details: { ambiguity_id: 'AMB-001' },
2556
+ expected_answer: { kind: 'free_text' },
2557
+ created_at: '2026-01-01T00:00:00.000Z',
2558
+ expires_at: '2026-01-01T01:00:00.000Z',
2559
+ answer: 'Use the existing chart surface.',
2560
+ answered_at: '2026-01-01T00:02:00.000Z',
2561
+ answered_by: 'operator:alice',
2562
+ resume_status: 'intake',
2563
+ resume_phase: 'intake',
2564
+ },
2565
+ ]);
2566
+
2567
+ await expect(
2568
+ service.intakeSubmit('feature_intake', {
2569
+ verified_manifest: {
2570
+ feature_id: 'feature_intake',
2571
+ manifest_version: 1,
2572
+ artifact_type: 'verified',
2573
+ verification_basis: 'human_review_confirmed',
2574
+ verified_at: '2026-01-01T00:00:00.000Z',
2575
+ source_bootstrap_version: 1,
2576
+ obligations: [],
2577
+ },
2578
+ open_ambiguities: [],
2579
+ resolved_ambiguities: [],
2580
+ requires_user_input: false,
2581
+ }),
2582
+ ).rejects.toMatchObject({
2583
+ normalizedResponse: {
2584
+ error: {
2585
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2586
+ message:
2587
+ 'human_review_confirmed requires an explicit answered manifest-review confirmation question',
2588
+ },
2589
+ },
2590
+ });
2591
+ });
2592
+
2593
+ it('rejects verified-manifest promotion while an intake question is still open', async () => {
2594
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2595
+ tempDirs.push(repoRoot);
2596
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2597
+ const { port } = makePort(repoRoot);
2598
+ const service = new IntakeService(port);
2599
+ await service.ensureIntakeArtifacts('feature_intake');
2600
+ await writeQuestions(repoRoot, 'feature_intake', [
2601
+ {
2602
+ question_id: 'q_intake_open',
2603
+ status: 'open',
2604
+ blocking: true,
2605
+ question_type: 'clarification',
2606
+ role: 'planner',
2607
+ phase: 'intake',
2608
+ request_action: 'ask_user_input',
2609
+ session_id: 'session-planner-1',
2610
+ prompt: 'Need operator guidance',
2611
+ details: { ambiguity_id: 'AMB-001' },
2612
+ expected_answer: { kind: 'free_text' },
2613
+ created_at: '2026-01-01T00:00:00.000Z',
2614
+ expires_at: '2026-01-01T01:00:00.000Z',
2615
+ answer: null,
2616
+ answered_at: null,
2617
+ answered_by: null,
2618
+ resume_status: 'intake',
2619
+ resume_phase: 'intake',
2620
+ },
2621
+ ]);
2622
+
2623
+ await expect(
2624
+ service.intakeSubmit('feature_intake', {
2625
+ verified_manifest: {
2626
+ feature_id: 'feature_intake',
2627
+ manifest_version: 1,
2628
+ artifact_type: 'verified',
2629
+ verification_basis: 'questions_resolved',
2630
+ verified_at: '2026-01-01T00:00:00.000Z',
2631
+ source_bootstrap_version: 1,
2632
+ obligations: [],
2633
+ },
2634
+ open_ambiguities: [],
2635
+ resolved_ambiguities: [{ id: 'AMB-001', summary: 'resolved', status: 'resolved' }],
2636
+ requires_user_input: false,
2637
+ }),
2638
+ ).rejects.toMatchObject({
2639
+ normalizedResponse: {
2640
+ error: {
2641
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2642
+ message: 'verified manifest cannot be promoted while intake questions remain open',
2643
+ },
2644
+ },
2645
+ });
2646
+ });
2647
+
2648
+ it('rejects questions_resolved when no resolved ambiguities are supplied even with answered questions', async () => {
2649
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2650
+ tempDirs.push(repoRoot);
2651
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2652
+ const { port } = makePort(repoRoot);
2653
+ const service = new IntakeService(port);
2654
+ await service.ensureIntakeArtifacts('feature_intake');
2655
+ await writeQuestions(repoRoot, 'feature_intake', [
2656
+ {
2657
+ question_id: 'q_intake_answered',
2658
+ status: 'answered',
2659
+ blocking: true,
2660
+ question_type: 'clarification',
2661
+ role: 'planner',
2662
+ phase: 'intake',
2663
+ request_action: 'ask_user_input',
2664
+ session_id: 'session-planner-1',
2665
+ prompt: 'Need operator guidance',
2666
+ details: { ambiguity_id: 'AMB-001' },
2667
+ expected_answer: { kind: 'free_text' },
2668
+ created_at: '2026-01-01T00:00:00.000Z',
2669
+ expires_at: '2026-01-01T01:00:00.000Z',
2670
+ answer: 'Confirmed.',
2671
+ answered_at: '2026-01-01T00:02:00.000Z',
2672
+ answered_by: 'operator:alice',
2673
+ resume_status: 'intake',
2674
+ resume_phase: 'intake',
2675
+ },
2676
+ ]);
2677
+
2678
+ await expect(
2679
+ service.intakeSubmit('feature_intake', {
2680
+ verified_manifest: {
2681
+ feature_id: 'feature_intake',
2682
+ manifest_version: 1,
2683
+ artifact_type: 'verified',
2684
+ verification_basis: 'questions_resolved',
2685
+ verified_at: '2026-01-01T00:00:00.000Z',
2686
+ source_bootstrap_version: 1,
2687
+ obligations: [],
2688
+ },
2689
+ open_ambiguities: [],
2690
+ resolved_ambiguities: [],
2691
+ requires_user_input: false,
2692
+ }),
2693
+ ).rejects.toMatchObject({
2694
+ normalizedResponse: {
2695
+ error: {
2696
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
2697
+ message: 'questions_resolved verification requires at least one resolved ambiguity',
2698
+ },
2699
+ },
2700
+ });
2701
+ });
2702
+
2703
+ it('accepts human_review_confirmed when an explicit manifest-review confirmation answer exists', async () => {
2704
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2705
+ tempDirs.push(repoRoot);
2706
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2707
+ const { state, port } = makePort(repoRoot);
2708
+ const service = new IntakeService(port);
2709
+ await service.ensureIntakeArtifacts('feature_intake');
2710
+ await writeQuestions(repoRoot, 'feature_intake', [
2711
+ {
2712
+ question_id: 'q_manifest_confirm',
2713
+ status: 'answered',
2714
+ blocking: true,
2715
+ question_type: 'clarification',
2716
+ role: 'planner',
2717
+ phase: 'intake',
2718
+ request_action: 'ask_user_input',
2719
+ session_id: 'session-planner-1',
2720
+ prompt: 'Confirm the final verified manifest',
2721
+ details: {
2722
+ confirmation_kind: 'manifest_review',
2723
+ review_target: 'verified_manifest',
2724
+ },
2725
+ expected_answer: { kind: 'free_text' },
2726
+ created_at: '2026-01-01T00:00:00.000Z',
2727
+ expires_at: '2026-01-01T01:00:00.000Z',
2728
+ answer: 'Confirmed.',
2729
+ answered_at: '2026-01-01T00:03:00.000Z',
2730
+ answered_by: 'operator:alice',
2731
+ resume_status: 'intake',
2732
+ resume_phase: 'intake',
2733
+ },
2734
+ ]);
2735
+
2736
+ const promoted = await service.intakeSubmit('feature_intake', {
2737
+ verified_manifest: {
2738
+ feature_id: 'feature_intake',
2739
+ manifest_version: 1,
2740
+ artifact_type: 'verified',
2741
+ verification_basis: 'human_review_confirmed',
2742
+ verified_at: '2026-01-01T00:00:00.000Z',
2743
+ source_bootstrap_version: 1,
2744
+ obligations: [],
2745
+ },
2746
+ open_ambiguities: [],
2747
+ resolved_ambiguities: [],
2748
+ requires_user_input: false,
2749
+ });
2750
+
2751
+ expect(promoted.data.feature_status).toBe(STATUS.PLANNING);
2752
+ expect(state.frontMatter.intake).toMatchObject({
2753
+ status: 'verified',
2754
+ promotion_basis: 'human_review_confirmed',
2755
+ });
2756
+ });
2757
+
2758
+ it('normalizes draft reviewed manifests and legacy manifest-review confirmation questions', async () => {
2759
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2760
+ tempDirs.push(repoRoot);
2761
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2762
+ const { state, port } = makePort(repoRoot, {
2763
+ validateSchemaImpl: async (schemaName, value) => {
2764
+ if (schemaName !== 'spec.manifest.verified.schema.json') {
2765
+ return { valid: true };
2766
+ }
2767
+ const record = value as Record<string, unknown>;
2768
+ const obligations = Array.isArray(record.obligations) ? record.obligations : [];
2769
+ const sourceRefsValid = obligations.every((obligation) => {
2770
+ const obligationRecord = obligation as Record<string, unknown>;
2771
+ const sourceRefs = obligationRecord.source_refs;
2772
+ return (
2773
+ Array.isArray(sourceRefs) &&
2774
+ sourceRefs.every((sourceRef) => {
2775
+ const sourceRefRecord = sourceRef as Record<string, unknown>;
2776
+ return (
2777
+ typeof sourceRefRecord.line_start === 'number' &&
2778
+ typeof sourceRefRecord.line_end === 'number' &&
2779
+ (typeof sourceRefRecord.heading === 'string' || sourceRefRecord.heading === null)
2780
+ );
2781
+ })
2782
+ );
2783
+ });
2784
+ return {
2785
+ valid:
2786
+ record.artifact_type === 'verified' &&
2787
+ record.verification_basis === 'human_review_confirmed' &&
2788
+ typeof record.verified_at === 'string' &&
2789
+ obligations.every((obligation) => {
2790
+ const obligationRecord = obligation as Record<string, unknown>;
2791
+ return (
2792
+ typeof obligationRecord.obligation_id === 'string' &&
2793
+ /^OBL-\d{3,}$/.test(obligationRecord.obligation_id) &&
2794
+ [
2795
+ 'artifact',
2796
+ 'endpoint',
2797
+ 'workflow',
2798
+ 'behavior',
2799
+ 'integration',
2800
+ 'contract',
2801
+ 'verification',
2802
+ ].includes(String(obligationRecord.kind ?? '')) &&
2803
+ !Object.prototype.hasOwnProperty.call(obligationRecord, 'added_by')
2804
+ );
2805
+ }) &&
2806
+ sourceRefsValid,
2807
+ };
2808
+ },
2809
+ });
2810
+ const service = new IntakeService(port);
2811
+ const intake = await service.ensureIntakeArtifacts('feature_intake');
2812
+ await writeQuestions(repoRoot, 'feature_intake', [
2813
+ {
2814
+ question_id: 'q_manifest_review',
2815
+ status: 'answered',
2816
+ blocking: true,
2817
+ question_type: 'clarification',
2818
+ role: 'planner',
2819
+ phase: 'intake',
2820
+ request_action: 'ask_user_input',
2821
+ session_id: 'session-planner-1',
2822
+ prompt:
2823
+ 'Please review spec.manifest.verified.json and confirm whether the obligation set is complete.',
2824
+ details: {
2825
+ ambiguity_id: 'AMB-MANIFEST-REVIEW',
2826
+ obligation_ids: ['OBL-V01', 'OBL-V02', 'OBL-V03'],
2827
+ },
2828
+ expected_answer: { kind: 'free_text' },
2829
+ created_at: '2026-01-01T00:00:00.000Z',
2830
+ expires_at: '2026-01-01T01:00:00.000Z',
2831
+ answer: 'Confirmed. Add the operator follow-up obligation.',
2832
+ answered_at: '2026-01-01T00:03:00.000Z',
2833
+ answered_by: 'operator:alice',
2834
+ resume_status: 'intake',
2835
+ resume_phase: 'intake',
2836
+ },
2837
+ ]);
2838
+
2839
+ const promoted = await service.intakeSubmit('feature_intake', {
2840
+ verified_manifest: {
2841
+ feature_id: 'feature_intake',
2842
+ manifest_version: 1,
2843
+ artifact_type: 'verified',
2844
+ verification_basis: 'human_review_confirmed',
2845
+ verified_at: '2026-01-01T00:04:00.000Z',
2846
+ source_bootstrap_version: intake.bootstrapManifest.manifest_version,
2847
+ obligations: [
2848
+ {
2849
+ obligation_id: 'OBL-V01',
2850
+ kind: 'behavior',
2851
+ name: 'Primary plan workspace',
2852
+ description: 'Render the plan workspace.',
2853
+ source_refs: [{ line_start: 1, line_end: 1, heading: null }],
2854
+ verification_hint: 'required',
2855
+ confidence: 'high',
2856
+ },
2857
+ {
2858
+ obligation_id: 'OBL-V02',
2859
+ kind: 'constraint',
2860
+ name: 'Plan tab visibility during intake',
2861
+ description: 'The Plan tab must stay visible during intake.',
2862
+ source_refs: [{ line_start: 2, line_end: 2, heading: null }],
2863
+ verification_hint: 'required',
2864
+ confidence: 'high',
2865
+ },
2866
+ {
2867
+ obligation_id: 'OBL-V03',
2868
+ kind: 'behavior',
2869
+ name: 'Operator review follow-up',
2870
+ description: 'Add the operator-requested follow-up obligation.',
2871
+ source_refs: [],
2872
+ verification_hint: 'required',
2873
+ confidence: 'high',
2874
+ added_by: 'operator_review',
2875
+ },
2876
+ ],
2877
+ },
2878
+ open_ambiguities: [],
2879
+ resolved_ambiguities: [],
2880
+ requires_user_input: false,
2881
+ } as unknown as Parameters<IntakeService['intakeSubmit']>[1]);
2882
+
2883
+ const persisted = JSON.parse(
2884
+ await fs.readFile(
2885
+ path.join(repoRoot, '.aop', 'features', 'feature_intake', 'spec.manifest.verified.json'),
2886
+ 'utf8',
2887
+ ),
2888
+ ) as { obligations: Array<Record<string, unknown>> };
2889
+
2890
+ expect(promoted.data.feature_status).toBe(STATUS.PLANNING);
2891
+ expect(persisted.obligations).toEqual([
2892
+ {
2893
+ obligation_id: 'OBL-001',
2894
+ kind: 'behavior',
2895
+ name: 'Primary plan workspace',
2896
+ description: 'Render the plan workspace.',
2897
+ source_refs: [{ line_start: 1, line_end: 1, heading: null }],
2898
+ verification_hint: 'required',
2899
+ confidence: 'high',
2900
+ },
2901
+ {
2902
+ obligation_id: 'OBL-002',
2903
+ kind: 'contract',
2904
+ name: 'Plan tab visibility during intake',
2905
+ description: 'The Plan tab must stay visible during intake.',
2906
+ source_refs: [{ line_start: 2, line_end: 2, heading: null }],
2907
+ verification_hint: 'required',
2908
+ confidence: 'high',
2909
+ },
2910
+ {
2911
+ obligation_id: 'OBL-003',
2912
+ kind: 'behavior',
2913
+ name: 'Operator review follow-up',
2914
+ description: 'Add the operator-requested follow-up obligation.',
2915
+ source_refs: [],
2916
+ verification_hint: 'required',
2917
+ confidence: 'high',
2918
+ },
2919
+ ]);
2920
+ expect(state.frontMatter.intake).toMatchObject({
2921
+ status: 'verified',
2922
+ promotion_basis: 'human_review_confirmed',
2923
+ });
2924
+ });
2925
+
2926
+ it('clears stale accepted plan artifacts and resets the plan gate when intake is verified', async () => {
2927
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2928
+ tempDirs.push(repoRoot);
2929
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
2930
+ await writePlanArtifacts(repoRoot, 'feature_intake', {
2931
+ feature_id: 'feature_intake',
2932
+ plan_version: 1,
2933
+ summary: 'stale plan',
2934
+ files: {
2935
+ create: [],
2936
+ modify: ['apps/control-plane/src/stale.ts'],
2937
+ delete: [],
2938
+ },
2939
+ acceptance_criteria: [],
2940
+ gate_profile: 'default',
2941
+ plan_trace: [
2942
+ {
2943
+ obligation_id: 'OBL-STALE',
2944
+ disposition: 'in_scope',
2945
+ planned_paths: ['apps/control-plane/src/stale.ts'],
2946
+ notes: 'stale contract',
2947
+ },
2948
+ ],
2949
+ });
2950
+ const { state, port } = makePort(repoRoot, {
2951
+ allowAutoPromotion: true,
2952
+ frontMatter: {
2953
+ status: STATUS.INTAKE,
2954
+ gates: {
2955
+ plan: 'pass',
2956
+ fast: 'pass',
2957
+ full: 'pass',
2958
+ },
2959
+ },
2960
+ });
2961
+ const service = new IntakeService(port);
2962
+
2963
+ await service.intakeSubmit('feature_intake', {
2964
+ verified_manifest: {
2965
+ feature_id: 'feature_intake',
2966
+ manifest_version: 1,
2967
+ artifact_type: 'verified',
2968
+ verification_basis: 'policy_approved_auto_promotion',
2969
+ verified_at: '2026-01-01T00:00:00.000Z',
2970
+ source_bootstrap_version: 1,
2971
+ obligations: [],
2972
+ },
2973
+ open_ambiguities: [],
2974
+ resolved_ambiguities: [],
2975
+ requires_user_input: false,
2976
+ });
2977
+
2978
+ await expect(
2979
+ fs.access(path.join(repoRoot, '.aop', 'features', 'feature_intake', 'plan.json')),
2980
+ ).rejects.toThrow();
2981
+ await expect(
2982
+ fs.access(path.join(repoRoot, '.aop', 'features', 'feature_intake', 'plan.md')),
2983
+ ).rejects.toThrow();
2984
+ expect(state.frontMatter.status).toBe(STATUS.PLANNING);
2985
+ expect((state.frontMatter.gates as Record<string, unknown>).plan).toBe('na');
2986
+ });
2987
+
2988
+ it('rejects policy-approved auto-promotion when the bootstrap manifest does not satisfy promotion policy', async () => {
2989
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
2990
+ tempDirs.push(repoRoot);
2991
+ await writeSpec(
2992
+ repoRoot,
2993
+ 'feature_intake',
2994
+ 'The system should normalize human input before planning begins.',
2995
+ );
2996
+ const { port } = makePort(repoRoot, {
2997
+ allowAutoPromotion: true,
2998
+ autoPromotionMinConfidence: 'high',
2999
+ });
3000
+ const service = new IntakeService(port);
3001
+
3002
+ await expect(
3003
+ service.intakeSubmit('feature_intake', {
3004
+ verified_manifest: {
3005
+ feature_id: 'feature_intake',
3006
+ manifest_version: 1,
3007
+ artifact_type: 'verified',
3008
+ verification_basis: 'policy_approved_auto_promotion',
3009
+ verified_at: '2026-01-01T00:00:00.000Z',
3010
+ source_bootstrap_version: 1,
3011
+ obligations: [
3012
+ {
3013
+ obligation_id: 'OBL-001',
3014
+ kind: 'behavior',
3015
+ name: 'normalize human input before planning begins',
3016
+ description: 'The system should normalize human input before planning begins.',
3017
+ source_refs: [{ line_start: 1, line_end: 1, heading: null }],
3018
+ verification_hint: 'required',
3019
+ confidence: 'low',
3020
+ },
3021
+ ],
3022
+ },
3023
+ open_ambiguities: [],
3024
+ resolved_ambiguities: [],
3025
+ requires_user_input: false,
3026
+ }),
3027
+ ).rejects.toMatchObject({
3028
+ normalizedResponse: {
3029
+ error: {
3030
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
3031
+ },
3032
+ },
3033
+ });
3034
+ });
3035
+
3036
+ it('rejects intake submissions when the verified manifest points at a stale bootstrap manifest version', async () => {
3037
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
3038
+ tempDirs.push(repoRoot);
3039
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
3040
+ const { port } = makePort(repoRoot);
3041
+ const service = new IntakeService(port);
3042
+
3043
+ await expect(
3044
+ service.intakeSubmit('feature_intake', {
3045
+ verified_manifest: {
3046
+ feature_id: 'feature_intake',
3047
+ manifest_version: 1,
3048
+ artifact_type: 'verified',
3049
+ verification_basis: 'human_review_confirmed',
3050
+ verified_at: '2026-01-01T00:00:00.000Z',
3051
+ source_bootstrap_version: 99,
3052
+ obligations: [],
3053
+ },
3054
+ open_ambiguities: [],
3055
+ resolved_ambiguities: [],
3056
+ requires_user_input: false,
3057
+ }),
3058
+ ).rejects.toMatchObject({
3059
+ normalizedResponse: {
3060
+ error: {
3061
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
3062
+ },
3063
+ },
3064
+ });
3065
+ });
3066
+
3067
+ it('rejects intake submissions without a verified manifest payload', async () => {
3068
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
3069
+ tempDirs.push(repoRoot);
3070
+ const { port } = makePort(repoRoot);
3071
+ const service = new IntakeService(port);
3072
+
3073
+ await expect(
3074
+ service.intakeSubmit('feature_intake', {
3075
+ open_ambiguities: [],
3076
+ resolved_ambiguities: [],
3077
+ requires_user_input: false,
3078
+ } as unknown as Parameters<IntakeService['intakeSubmit']>[1]),
3079
+ ).rejects.toMatchObject({
3080
+ normalizedResponse: {
3081
+ error: {
3082
+ code: ERROR_CODES.INVALID_ARGUMENT,
3083
+ },
3084
+ },
3085
+ });
3086
+ });
3087
+
3088
+ it('rejects intake submissions when the verified manifest belongs to a different feature', async () => {
3089
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
3090
+ tempDirs.push(repoRoot);
3091
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
3092
+ const { port } = makePort(repoRoot);
3093
+ const service = new IntakeService(port);
3094
+
3095
+ await expect(
3096
+ service.intakeSubmit('feature_intake', {
3097
+ verified_manifest: {
3098
+ feature_id: 'other_feature',
3099
+ manifest_version: 1,
3100
+ artifact_type: 'verified',
3101
+ verification_basis: 'human_review_confirmed',
3102
+ verified_at: '2026-01-01T00:00:00.000Z',
3103
+ source_bootstrap_version: 1,
3104
+ obligations: [],
3105
+ },
3106
+ open_ambiguities: [],
3107
+ resolved_ambiguities: [],
3108
+ requires_user_input: false,
3109
+ }),
3110
+ ).rejects.toMatchObject({
3111
+ normalizedResponse: {
3112
+ error: {
3113
+ code: ERROR_CODES.INVALID_ARGUMENT,
3114
+ },
3115
+ },
3116
+ });
3117
+ });
3118
+
3119
+ it('surfaces verified-manifest schema failures as intake submission invalid', async () => {
3120
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
3121
+ tempDirs.push(repoRoot);
3122
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
3123
+ const { port } = makePort(repoRoot, {
3124
+ validateSchemaImpl: async (schemaName) =>
3125
+ schemaName === 'spec.manifest.verified.schema.json'
3126
+ ? {
3127
+ valid: false,
3128
+ errors: [{ keyword: 'pattern', instancePath: '/obligations/0/obligation_id' }],
3129
+ }
3130
+ : { valid: true },
3131
+ });
3132
+ const service = new IntakeService(port);
3133
+
3134
+ await expect(
3135
+ service.intakeSubmit('feature_intake', {
3136
+ verified_manifest: {
3137
+ feature_id: 'feature_intake',
3138
+ manifest_version: 1,
3139
+ artifact_type: 'verified',
3140
+ verification_basis: 'human_review_confirmed',
3141
+ verified_at: '2026-01-01T00:00:00.000Z',
3142
+ source_bootstrap_version: 1,
3143
+ obligations: [],
3144
+ },
3145
+ open_ambiguities: [],
3146
+ resolved_ambiguities: [],
3147
+ requires_user_input: false,
3148
+ }),
3149
+ ).rejects.toMatchObject({
3150
+ normalizedResponse: {
3151
+ error: {
3152
+ code: ERROR_CODES.INTAKE_SUBMISSION_INVALID,
3153
+ message: 'verified manifest failed schema validation',
3154
+ },
3155
+ },
3156
+ });
3157
+ });
3158
+
3159
+ it('fails with a structured validation error when bootstrap manifest validation fails', async () => {
3160
+ const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aop-intake-service-'));
3161
+ tempDirs.push(repoRoot);
3162
+ await writeSpec(repoRoot, 'feature_intake', '- `UsageBurnChart` should render.');
3163
+ const { port } = makePort(repoRoot, {
3164
+ invalidSchemas: ['spec.manifest.bootstrap.schema.json'],
3165
+ });
3166
+ const service = new IntakeService(port);
3167
+
3168
+ await expect(service.ensureBootstrapManifest('feature_intake')).rejects.toMatchObject({
3169
+ normalizedResponse: {
3170
+ error: {
3171
+ code: ERROR_CODES.STATE_VALIDATION_FAILED,
3172
+ },
3173
+ },
3174
+ });
3175
+ });
3176
+ });