@aibyzero/cm-workflow 0.21.7 → 0.25.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 (227) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +64 -0
  3. package/README.md +15 -1
  4. package/VERSION +1 -1
  5. package/docs/architecture.md +9 -0
  6. package/docs/cm-acceptance-completion.md +3 -1
  7. package/docs/cm-control-policy-v2.md +35 -3
  8. package/docs/execution-optimizations.md +1 -1
  9. package/docs/external-models.md +1 -0
  10. package/docs/human-correction.md +1 -1
  11. package/docs/installation.md +63 -19
  12. package/docs/js-workflow-control.md +67 -31
  13. package/docs/next-steps.md +10 -0
  14. package/docs/runtime-failover.md +2 -2
  15. package/docs/user-guide.md +1 -1
  16. package/package.json +1 -1
  17. package/runtime/js/cm-ai/batch-location.mjs +14 -0
  18. package/runtime/js/cm-ai/batch-plan.mjs +6 -2
  19. package/runtime/js/cm-ai/claude-probe-diagnosis.mjs +21 -0
  20. package/runtime/js/cm-ai/claude-review-stream.mjs +20 -7
  21. package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -2
  22. package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
  23. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
  24. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
  25. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
  26. package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
  27. package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
  28. package/runtime/js/cm-ai/drive-core.mjs +50 -6
  29. package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
  30. package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
  31. package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
  32. package/runtime/js/cm-ai/execution-store.mjs +21 -3
  33. package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
  34. package/runtime/js/cm-ai/host-check.mjs +4 -2
  35. package/runtime/js/cm-ai/host-conversation-execution.mjs +29 -2
  36. package/runtime/js/cm-ai/host-handoff.mjs +7 -0
  37. package/runtime/js/cm-ai/host-progress.mjs +18 -0
  38. package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
  39. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  40. package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
  41. package/runtime/js/cm-ai/host-session.mjs +1 -1
  42. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
  43. package/runtime/js/cm-ai/host.mjs +1 -1
  44. package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
  45. package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
  46. package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
  47. package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
  48. package/runtime/js/cm-ai/review-continuation.mjs +102 -0
  49. package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
  50. package/runtime/js/cm-ai/review-package.mjs +25 -4
  51. package/runtime/js/cm-ai/review-presentation.mjs +31 -14
  52. package/runtime/js/cm-ai/review-runner.mjs +5 -4
  53. package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
  54. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
  55. package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
  56. package/runtime/js/cm-ai/task-commit.mjs +7 -4
  57. package/runtime/js/cm-ai/task-owner.mjs +5 -2
  58. package/runtime/js/cm-ai/task-runner.mjs +343 -52
  59. package/runtime/js/cm-ai/worker-claude-developer.mjs +3 -1
  60. package/runtime/js/cm-ai/worker-claude.mjs +5 -1
  61. package/runtime/js/cm-check/host.mjs +13 -3
  62. package/runtime/js/cm-fix/diagnosis.mjs +16 -3
  63. package/runtime/js/cm-fix/execution.mjs +47 -9
  64. package/runtime/js/cm-fix/finish.mjs +9 -1
  65. package/runtime/js/cm-fix/step-timing.mjs +222 -0
  66. package/runtime/js/cm-idea/session.mjs +22 -3
  67. package/runtime/js/cm-init/review-evidence.mjs +20 -7
  68. package/runtime/js/cm-prd/ai-draft.mjs +260 -0
  69. package/runtime/js/cm-prd/analysis.mjs +27 -9
  70. package/runtime/js/cm-prd/change.mjs +29 -8
  71. package/runtime/js/cm-prd/failed-correction.mjs +24 -4
  72. package/runtime/js/cm-prd/narrow-review.mjs +63 -3
  73. package/runtime/js/cm-prd/review-channels.mjs +5 -0
  74. package/runtime/js/cm-prd/review-correction.mjs +65 -5
  75. package/runtime/js/cm-prd/review-disposition.mjs +10 -1
  76. package/runtime/js/cm-prd/review-publication.mjs +2 -1
  77. package/runtime/js/cm-prd/self-check.mjs +121 -9
  78. package/runtime/js/cm-prd/session.mjs +55 -13
  79. package/runtime/js/cm-prd/summary.mjs +34 -6
  80. package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
  81. package/runtime/js/cm-refactor/records.mjs +82 -11
  82. package/runtime/js/cm-refactor/workflow.mjs +3 -1
  83. package/runtime/js/executor-version.mjs +81 -0
  84. package/runtime/js/python-log-writer.mjs +15 -0
  85. package/runtime/js/run-analysis.mjs +136 -11
  86. package/runtime/logging.md +6 -0
  87. package/runtime/review.md +2 -1
  88. package/scripts/ci-test-weights.json +1 -0
  89. package/scripts/cm-ai-admission.mjs +27 -1
  90. package/scripts/cm-ai-admission.test.mjs +34 -2
  91. package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
  92. package/scripts/cm-ai-batch-drive.mjs +54 -17
  93. package/scripts/cm-ai-batch-drive.test.mjs +123 -6
  94. package/scripts/cm-ai-batch-host.mjs +64 -11
  95. package/scripts/cm-ai-batch-host.test.mjs +23 -3
  96. package/scripts/cm-ai-batch-location.test.mjs +22 -1
  97. package/scripts/cm-ai-batch-merge.mjs +102 -0
  98. package/scripts/cm-ai-batch-plan.mjs +55 -2
  99. package/scripts/cm-ai-batch-plan.test.mjs +228 -6
  100. package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
  101. package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
  102. package/scripts/cm-ai-batch-run.mjs +437 -34
  103. package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
  104. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
  105. package/scripts/cm-ai-completion-summary.test.mjs +2 -1
  106. package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
  107. package/scripts/cm-ai-direct-review.test.mjs +1 -1
  108. package/scripts/cm-ai-disk-edits.test.mjs +229 -0
  109. package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
  110. package/scripts/cm-ai-drive.mjs +66 -14
  111. package/scripts/cm-ai-drive.test.mjs +13 -3
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
  113. package/scripts/cm-ai-host.mjs +20 -9
  114. package/scripts/cm-ai-host.test.mjs +12 -0
  115. package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
  116. package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
  117. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
  118. package/scripts/cm-ai-review-continuation.test.mjs +335 -0
  119. package/scripts/cm-ai-review-failure.test.mjs +13 -10
  120. package/scripts/cm-ai-review-timeout.test.mjs +1 -1
  121. package/scripts/cm-ai-run.mjs +42 -11
  122. package/scripts/cm-ai-run.test.mjs +26 -0
  123. package/scripts/cm-ai-supersede.test.mjs +10 -2
  124. package/scripts/cm-capability-gate.test.mjs +1 -1
  125. package/scripts/cm-check-host.test.mjs +54 -0
  126. package/scripts/cm-check-runtime.sh +27 -15
  127. package/scripts/cm-check-update.mjs +83 -8
  128. package/scripts/cm-check-update.test.mjs +114 -1
  129. package/scripts/cm-claude-developer-worker.test.mjs +29 -1
  130. package/scripts/cm-claude-managed-preflight.test.mjs +126 -0
  131. package/scripts/cm-claude-probe.test.mjs +5 -0
  132. package/scripts/cm-claude-review-stream.test.mjs +4 -1
  133. package/scripts/cm-claude-worker.test.mjs +29 -0
  134. package/scripts/cm-codex-prompt-input.test.mjs +2 -1
  135. package/scripts/cm-developer-self-review.test.mjs +27 -0
  136. package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
  137. package/scripts/cm-efficiency-response.test.mjs +2 -1
  138. package/scripts/cm-executor-version-draft.test.mjs +251 -0
  139. package/scripts/cm-executor-version-entries.test.mjs +93 -0
  140. package/scripts/cm-executor-version-prd.test.mjs +154 -0
  141. package/scripts/cm-executor-version-records.test.mjs +256 -0
  142. package/scripts/cm-executor-version.test.mjs +250 -0
  143. package/scripts/cm-external-model-host.test.mjs +6 -1
  144. package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
  145. package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
  146. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
  147. package/scripts/cm-fix-drive.mjs +7 -2
  148. package/scripts/cm-fix-drive.test.mjs +45 -0
  149. package/scripts/cm-fix-entry.mjs +5 -2
  150. package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
  151. package/scripts/cm-fix-host.mjs +9 -2
  152. package/scripts/cm-fix-review-preflight.mjs +2 -0
  153. package/scripts/cm-fix-review-verification-integration.test.mjs +19 -0
  154. package/scripts/cm-fix-test-extension.test.mjs +30 -2
  155. package/scripts/cm-host-check.test.mjs +12 -0
  156. package/scripts/cm-host-qa-executor.test.mjs +172 -1
  157. package/scripts/cm-host-qa-policy.test.mjs +55 -1
  158. package/scripts/cm-idea-drive.mjs +5 -2
  159. package/scripts/cm-idea-entry.mjs +5 -2
  160. package/scripts/cm-idea-host.mjs +3 -1
  161. package/scripts/cm-init-drive.mjs +8 -5
  162. package/scripts/cm-init-entry.mjs +5 -2
  163. package/scripts/cm-init-host.mjs +6 -2
  164. package/scripts/cm-log-event.mjs +10 -2
  165. package/scripts/cm-log-event.test.mjs +29 -0
  166. package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
  167. package/scripts/cm-prd-ai-draft.test.mjs +505 -0
  168. package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
  169. package/scripts/cm-prd-completion.test.mjs +67 -4
  170. package/scripts/cm-prd-design-phase.test.mjs +48 -13
  171. package/scripts/cm-prd-drive.mjs +91 -21
  172. package/scripts/cm-prd-drive.test.mjs +126 -4
  173. package/scripts/cm-prd-entry.mjs +5 -2
  174. package/scripts/cm-prd-host.mjs +89 -20
  175. package/scripts/cm-prd-host.test.mjs +17 -8
  176. package/scripts/cm-prd-narrow-review.test.mjs +49 -1
  177. package/scripts/cm-prd-review-disposition.test.mjs +94 -1
  178. package/scripts/cm-prd-review-gate.mjs +13 -5
  179. package/scripts/cm-prd-review-publication.test.mjs +34 -0
  180. package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
  181. package/scripts/cm-prd-self-check.test.mjs +1 -1
  182. package/scripts/cm-refactor-drive.mjs +10 -4
  183. package/scripts/cm-refactor-entry.mjs +5 -2
  184. package/scripts/cm-refactor-host.mjs +3 -1
  185. package/scripts/cm-release-smoke.sh +3 -2
  186. package/scripts/cm-run-analysis.test.mjs +373 -1
  187. package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
  188. package/scripts/cm-skill-hints-exam.mjs +3 -1
  189. package/scripts/cm-skill-hints-install.test.mjs +1 -1
  190. package/scripts/cm-skill-hints.mjs +106 -10
  191. package/scripts/cm-skill-hints.test.mjs +162 -6
  192. package/scripts/cm-skill-judge.mjs +2 -1
  193. package/scripts/cm-task-gate.mjs +88 -18
  194. package/scripts/cm-task-scope.test.mjs +1 -1
  195. package/scripts/cm-test-drive.mjs +13 -8
  196. package/scripts/cm-test-entry.mjs +5 -2
  197. package/scripts/cm-test-host.mjs +3 -1
  198. package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
  199. package/scripts/cm-workflow-config.test.mjs +8 -3
  200. package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
  201. package/scripts/fixtures/prd-review-gate-python-oracle.py +10 -1
  202. package/scripts/policy-binding-compat.test.mjs +3 -2
  203. package/scripts/scan-public-safety.py +1 -0
  204. package/scripts/shell-pipe-early-exit.test.mjs +96 -0
  205. package/scripts/test-cm-prd-review-gate.py +55 -0
  206. package/scripts/test-shell-compat.sh +7 -5
  207. package/skills/cm-ai/SKILL.md +1 -1
  208. package/skills/cm-ai/references/N1-init.md +1 -1
  209. package/skills/cm-ai/references/N4-review.md +2 -2
  210. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  211. package/skills/cm-ai/references/js-host-recovery.md +5 -1
  212. package/skills/cm-ai/references/js-host.md +17 -8
  213. package/skills/cm-check/SKILL.md +3 -0
  214. package/skills/cm-fix/references/isolated-review.md +1 -1
  215. package/skills/cm-fix/references/js-host.md +20 -0
  216. package/skills/cm-fix/references/test-extension.md +1 -1
  217. package/skills/cm-prd/SKILL.md +8 -6
  218. package/skills/cm-prd/references/ai-draft.md +81 -0
  219. package/skills/cm-prd/references/change-mode.md +2 -0
  220. package/skills/cm-prd/references/greenfield.md +2 -0
  221. package/skills/cm-prd/references/js-change-recovery.md +2 -2
  222. package/skills/cm-prd/references/js-host.md +9 -6
  223. package/skills/cm-prd/references/light-mode.md +19 -0
  224. package/skills/cm-prd/references/requirement-grilling.md +2 -0
  225. package/skills/cm-prd/references/spec-self-check.md +1 -0
  226. package/skills/cm-prd/references/summary-card.md +1 -0
  227. package/templates/auto-update/cm-update.sh +2 -2
@@ -16,6 +16,7 @@ import {createInterface} from 'node:readline';
16
16
  import {fileURLToPath} from 'node:url';
17
17
  import {inspectPrdReview} from './cm-prd-review-gate.mjs';
18
18
  import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
19
+ import {aiDraftAnalyzed,withAiDraftSections} from './cm-prd-ai-draft-fixture.mjs';
19
20
 
20
21
  const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-home-'));
21
22
  process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
@@ -99,8 +100,8 @@ test('O02: a recorded prd_generate answer the host refused is discarded and aske
99
100
  test('O05/O06: an unpublishable recorded split review is abandoned with --allow-review-abandon, then reviewed afresh',{timeout:40000},async t=>{
100
101
  const dir=fixture(t);let reviews=0,degraded=true,conflict=false;
101
102
  const respond=({kind,payload})=>{
102
- if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
103
- if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
103
+ if(kind==='prd_analyze')return aiDraftAnalyzed({status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]});
104
+ if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:withAiDraftSections(docs()).map(doc=>({
104
105
  ...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
105
106
  if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
106
107
  checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
@@ -146,8 +147,8 @@ test('O05/O06: an unpublishable recorded split review is abandoned with --allow-
146
147
  test('O05/O06: a recorded review that would publish is never abandoned',{timeout:40000},async t=>{
147
148
  const dir=fixture(t);let conflicted=false;
148
149
  const respond=({kind,payload})=>{
149
- if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
150
- if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
150
+ if(kind==='prd_analyze')return aiDraftAnalyzed({status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]});
151
+ if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:withAiDraftSections(docs()).map(doc=>({
151
152
  ...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
152
153
  if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
153
154
  checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
@@ -170,7 +171,7 @@ test('O05/O06: a recorded review that would publish is never abandoned',{timeout
170
171
  await c.close();
171
172
  });
172
173
 
173
- test('O02: at most two discards per call kind in a session; prd_review and prd_correct are never discarded',async t=>{
174
+ test('O02: at most two discards per call kind in a session; prd_review is never discarded (prd_correct: 问题7 tests)',async t=>{
174
175
  const dir=fixture(t),session=openPrdSession({specs:dir,sessionId:'prd-discard-cap',identity:{entry:{fixture:true},runtime:'codex'}});
175
176
  try{
176
177
  session.begin({requestId:'one',operation:'advance',text:'x'},null);
@@ -214,3 +215,107 @@ test('O05/O06: the gate finishes a release interrupted after the abandoned recor
214
215
  claimPrdReview({...args,package_sha256:'3'.repeat(64)});
215
216
  assert.throws(()=>abandonPrdReviewAttempt({...args,call_id:'call-3',reason:'x'}),{code:'prd_review_abandon_limit'});
216
217
  });
218
+
219
+ // dogfood 2026-12-01(问题 7):单轮 prd_correct 被机械检查拒收后,会话没有合法下一步——
220
+ // resume 重放同一份被拒答复,discard 又一律拒绝 prd_correct。新会话里,存档未写(磁盘未改)
221
+ // 且原答复仍过不了同一机械检查时,可以作废这份答复并重问;检查本身和次数上限不变,旧会话照旧。
222
+ function refusedCorrectionResponder(){
223
+ const flags={bad:true,corrections:0};
224
+ const respond=({kind,payload})=>{
225
+ if(kind==='prd_analyze')return aiDraftAnalyzed({status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]});
226
+ if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:withAiDraftSections(docs()).map(doc=>({
227
+ ...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
228
+ if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
229
+ checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
230
+ if(kind==='prd_review')return {reviewer:'codex-subagent',contextId:'synthetic-independent',independent:true,at:'2026-09-08T00:00:00.000Z',
231
+ result:{verdict:'changes_requested',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,
232
+ findings:[{id:'R1',severity:'P2',path:'2.new-guide/design.md',message:'Clarify design',evidence:'Synthetic finding'}],summary:'Synthetic review'}};
233
+ assert.equal(kind,'prd_correct');flags.corrections++;
234
+ // The refused shape: tasks.md loses its recorded task scopes (task_scope_missing).
235
+ return {documents:payload.documents.map(doc=>({path:doc.path,content:doc.path.endsWith('/design.md')?doc.content+'\nClarified design'
236
+ :flags.bad&&doc.path.endsWith('/tasks.md')?doc.content.replace(/\n {2}- 范围: `README.md`/g,''):doc.content})),
237
+ decisions:[{id:'R1',status:'applied',evidence:['Clarified'],changedPaths:['2.new-guide/design.md',...(flags.bad?['2.new-guide/tasks.md']:[])]}]};
238
+ };
239
+ return {flags,respond};
240
+ }
241
+ async function refusedCorrection(t){
242
+ const dir=fixture(t),{flags,respond}=refusedCorrectionResponder();
243
+ const c=await client(t,dir,respond,{change:false,review:true});
244
+ await c.request('start',{text:'New guide'});await c.request('advance',{text:'Draft'});await c.request('advance',{text:'Check'});
245
+ await c.request('save_draft');
246
+ const runId=(await c.request('status')).result.runId;
247
+ assert.equal((await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'})).result.reviewState.status,'review_recorded');
248
+ const tasksBefore=fs.readFileSync(path.join(dir,'2.new-guide/tasks.md'),'utf8');
249
+ const refused=await c.request('correct_findings',{stage:'split',feature:'2.new-guide'});
250
+ const recorded=stateOf(dir,runId).active.calls.at(-1);assert.equal(recorded.kind,'prd_correct');
251
+ return {dir,c,runId,flags,refused,recorded,tasksBefore,
252
+ resolution:{callId:recorded.callId,requestDigest:recorded.requestDigest,discard:true,evidence:'修正稿删掉了任务范围,被机械检查拒收'}};
253
+ }
254
+
255
+ test('问题7: 机械检查拒收的 prd_correct 可作废重问,不再卡死会话(仅新会话,存档未写)',{timeout:60000},async t=>{
256
+ const {dir,c,runId,flags,refused,recorded,tasksBefore,resolution}=await refusedCorrection(t);
257
+ assert.equal(refused.result?.reason,'prd_correction_mechanics_failed',JSON.stringify(refused));
258
+ // Field and file names with the rule code only, never the proposed content.
259
+ assert.deepEqual(refused.result.failedChecks,[{feature:'2.new-guide',code:'task_scope_missing',field:'2.new-guide/tasks.md'}]);
260
+ assert.doesNotMatch(JSON.stringify(refused.result),/Clarified design/);
261
+ assert.equal(fs.readFileSync(path.join(dir,'2.new-guide/tasks.md'),'utf8'),tasksBefore);
262
+ assert.equal(fs.existsSync(path.join(dir,'.reviews/prd-new-guide-split-correction.md')),false);
263
+ assert.match(refused.result.guidance.nextStep,/discard:true/);
264
+ // A plain resume still replays the same refused answer; the discard is the explicit exit.
265
+ assert.equal((await c.request('resume',{resolution:null})).result?.reason,'prd_correction_mechanics_failed');
266
+ assert.equal(flags.corrections,1);
267
+ flags.bad=false;
268
+ const again=await c.request('resume',{resolution});
269
+ assert.equal(again.result?.status,'correction_saved',JSON.stringify(again)+c.stderr());
270
+ assert.equal(flags.corrections,2,'asked again under the same pending correct_findings');
271
+ const state=stateOf(dir,runId);
272
+ assert.equal(state.active,null);
273
+ assert.deepEqual(state.discardedAnswers.map(item=>[item.kind,item.callId,item.operation]),[['prd_correct',recorded.callId,'correct_findings']]);
274
+ assert.match(fs.readFileSync(path.join(dir,'2.new-guide/design.md'),'utf8'),/Clarified design/);
275
+ assert.equal(fs.readFileSync(path.join(dir,'2.new-guide/tasks.md'),'utf8'),tasksBefore);
276
+ await c.close();
277
+ });
278
+
279
+ test('问题7: 旧会话(无 correctionDiscard)照旧不作废 prd_correct,状态不变',{timeout:60000},async t=>{
280
+ const {dir,c,runId,resolution}=await refusedCorrection(t);await c.close();
281
+ const file=path.join(dir,'.reviews/prd-sessions',runId,'state.json'),state=JSON.parse(fs.readFileSync(file,'utf8'));
282
+ delete state.correctionDiscard;fs.writeFileSync(file,JSON.stringify(state),{mode:0o600});
283
+ const before=fs.readFileSync(file,'utf8');
284
+ const legacy=await client(t,dir,refusedCorrectionResponder().respond,{session:runId,change:false,review:true});
285
+ const refused=await legacy.request('resume',{resolution});
286
+ assert.equal(refused.result?.reason,'prd_correction_recovery_required',JSON.stringify(refused));
287
+ assert.equal(fs.readFileSync(file,'utf8'),before);
288
+ await legacy.close();
289
+ });
290
+
291
+ // Review r1 A3: a host reopened without the correction permissions must refuse before the discard is
292
+ // written, and keep the pending operation (no discard spent, nothing cleared).
293
+ test('问题7 r1-A3: 缺修正权限时先拒绝,作废不落盘、待恢复操作保留',{timeout:60000},async t=>{
294
+ const {dir,c,runId,resolution}=await refusedCorrection(t);await c.close();
295
+ const file=path.join(dir,'.reviews/prd-sessions',runId,'state.json'),before=fs.readFileSync(file,'utf8');
296
+ const limited=await client(t,dir,refusedCorrectionResponder().respond,{session:runId,change:false});
297
+ const refused=await limited.request('resume',{resolution});
298
+ assert.equal(refused.result?.reason,'prd_correction_not_enabled',JSON.stringify(refused));
299
+ assert.equal(fs.readFileSync(file,'utf8'),before);
300
+ assert.equal(JSON.parse(before).active.request.operation,'correct_findings');
301
+ await limited.close();
302
+ });
303
+
304
+ // Review r1 A4: once the discards for prd_correct are spent the guidance stops offering one.
305
+ test('问题7 r1-A4: 作废次数用完后,指引改为说明已达上限并给出 cancel 出路',{timeout:90000},async t=>{
306
+ const {c,runId,refused,resolution,dir}=await refusedCorrection(t);
307
+ assert.match(refused.result.guidance.nextStep,/discard:true/);
308
+ let last=resolution;
309
+ for(let index=0;index<2;index++){
310
+ const again=await c.request('resume',{resolution:last});
311
+ assert.equal(again.result?.reason,'prd_correction_mechanics_failed',JSON.stringify(again));
312
+ const call=stateOf(dir,runId).active.calls.at(-1);last={...resolution,callId:call.callId,requestDigest:call.requestDigest};
313
+ if(index===0)assert.match(again.result.guidance.nextStep,/discard:true/);
314
+ else{
315
+ assert.doesNotMatch(again.result.guidance.nextStep,/discard:true/);
316
+ assert.match(again.result.guidance.summary,/上限/);assert.match(again.result.guidance.nextStep,/cancel/);
317
+ }
318
+ }
319
+ assert.equal((await c.request('resume',{resolution:last})).result?.reason,'prd_answer_discard_limit');
320
+ await c.close();
321
+ });
@@ -12,6 +12,7 @@ import {inspectPrdChangeSnapshot,inspectPrdChangeProposal,applyPrdChange,assertP
12
12
  import {loadConfig} from './cm-workflow-config.mjs';
13
13
  import {recordPrdReview} from './cm-prd-review-gate.mjs';
14
14
  import {parseFeatureTaskText} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
15
+ import {aiDraftAnalyzed,withAiDraftSections} from './cm-prd-ai-draft-fixture.mjs';
15
16
 
16
17
  // Keep runtime declarations and log mirrors independent of the invoking user's home.
17
18
  const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-completion-home-'));
@@ -35,7 +36,7 @@ async function client(t,dir,respond,{session,change=true,review=false}={}){
35
36
  '--project',dir,'--specs',dir,'--runtime','codex','--allow-log-write','--allow-spec-write',
36
37
  ...(change?['--change','1.guide']:[]),...(session?['--session',session]:[]),
37
38
  ...(review?['--allow-review-write','--allow-disposition-write','--host-context','synthetic-author']:[])],
38
- {env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
39
+ {env:{...process.env,TZ:'America/Los_Angeles',CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
39
40
  t.after(()=>{if(child.exitCode===null)child.kill();});let error='',sessionId,seq=0;
40
41
  child.stderr.on('data',bytes=>error+=bytes);const pending=new Map();let readyResolve,readyReject;
41
42
  const ready=new Promise((yes,no)=>{readyResolve=yes;readyReject=no;});
@@ -50,7 +51,7 @@ async function client(t,dir,respond,{session,change=true,review=false}={}){
50
51
  });
51
52
  child.on('close',code=>{if(!sessionId)readyReject(Error(error));for(const resolve of pending.values())resolve({closed:code,error});pending.clear();});
52
53
  await ready;
53
- return {child,request:async(operation,fields={})=>{const requestId=`test-${++seq}`;return new Promise(resolve=>{
54
+ return {child,stderr:()=>error,request:async(operation,fields={})=>{const requestId=`test-${++seq}`;return new Promise(resolve=>{
54
55
  pending.set(requestId,resolve);send({requestId,operation,...fields});});},
55
56
  close:async()=>{send({type:'host_close',sessionId});const [code]=await once(child,'close');assert.equal(code,0,error);}};
56
57
  }
@@ -92,6 +93,10 @@ test('actual change CLI resumes unsaved phase across processes and stops at huma
92
93
  assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'))).specFiles.length,3);await c.close();
93
94
  const rows=fs.readFileSync(path.join(dir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
94
95
  const progress=rows.filter(row=>row.event==='progress');assert.ok(progress.length>0);
96
+ // dogfood 2026-12-01(问题 21):awaiting_review 行用规格状态的发布时间,审批写入才能按同一秒找到它记下等待时长。
97
+ const published=JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'))).at;
98
+ const publishedRows=rows.filter(row=>row.event==='spec_lifecycle'&&row.phase==='awaiting_review');
99
+ assert.equal(publishedRows.length,1);assert.equal(publishedRows[0].at,`${published.slice(0,19)}+00:00`);
95
100
  for(const row of progress.filter(row=>row.phase==='start'))assert.equal(progress.filter(other=>other.phase==='complete'
96
101
  &&other.operation_id===row.operation_id&&other.segment===row.segment).length,1);
97
102
  c=await client(t,dir,()=>assert.fail('completed recovery must not call host'),{session:runId});
@@ -306,8 +311,8 @@ for(const recoveryMode of ['process-loss','mode-mismatch','publication-conflict'
306
311
  result:{verdict:'approved',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic no findings'}});
307
312
  const respond=message=>{
308
313
  calls++;const {kind,payload}=message;
309
- if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
310
- if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
314
+ if(kind==='prd_analyze')return aiDraftAnalyzed({status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]});
315
+ if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:withAiDraftSections(docs()).map(doc=>({
311
316
  ...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
312
317
  if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
313
318
  checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
@@ -389,3 +394,61 @@ test('change_tasks may omit unchanged documents of an existing feature; the 64 K
389
394
  documents:[{path:'tasks.md',content:'## 任务版本'+'\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08 | v1 | new |\n- [ ] T-001: [NEW] Extra\n'}]}]};
390
395
  assert.throws(()=>inspectPrdChangeProposal(before,fresh,['1.guide'],config),/prd_draft_triad_missing|prd_change/);
391
396
  });
397
+
398
+ // dogfood 2026-12-01:需求阶段漏写版本行时宿主照收,到任务阶段才报 prd_change_version_history_missing,前两阶段已无法回退,只能取消会话重来。
399
+ test('change requirements and design phases reject a changed document without a new version row on the spot', {timeout:25000},async t=>{
400
+ const dir=fixture(t);let omit=null;
401
+ const respond=message=>{const value=changeResponse(message);
402
+ const target=omit==='change_requirements'?'requirements.md':'design.md';
403
+ if(message.kind==='prd_generate'&&omit===message.payload.phase)for(const doc of value.features[0].documents)
404
+ if(doc.path===target)doc.content=doc.content.replace('\n| 2026-09-08 | v2 | change |','');
405
+ return value;};
406
+ const c=await client(t,dir,respond);
407
+ assert.equal((await c.request('start',{text:'Add example'})).result.stage,'change_requirements');
408
+ // 拒收后按现有 V1 恢复:丢弃被拒的那份答复(discard),同一阶段重新索要,不必取消会话。
409
+ const rejectedThenRetried=async(text,next)=>{const before=c.stderr().length;
410
+ assert.equal((await c.request('advance',{text})).error?.code,'host_request_failed');
411
+ assert.match(c.stderr().slice(before),/prd_change_version_history_missing/);
412
+ const blocked=(await c.request('status')).result;
413
+ assert.equal(blocked.stage,`change_${text.toLowerCase()}`,'rejected phase does not advance');
414
+ const call=blocked.recovery?.calls?.at(-1)??(await c.request('advance',{text})).result.recovery.calls.at(-1);omit=null;
415
+ const again=await c.request('resume',{resolution:{callId:call.callId,requestDigest:call.requestDigest,discard:true,evidence:'reply lacked version row'}});
416
+ assert.equal(again.result?.stage,next,JSON.stringify(again).slice(0,400)+c.stderr().slice(-400));};
417
+ omit='change_requirements';await rejectedThenRetried('Requirements','change_design');
418
+ omit='change_design';await rejectedThenRetried('Design','change_tasks');
419
+ await c.close();
420
+ });
421
+ // 审查 r1:代码围栏里的示例行、重复已有行都不算新增版本行。
422
+ test('version history ignores fenced example rows and duplicated old rows',async()=>{
423
+ const {inspectPrdChangeVersionHistory}=await import('../runtime/js/cm-prd/change.mjs');
424
+ const old='## 需求版本\n| 日期 | 版本 | 说明 |\n| 2026-09-08 | v1 | original |\n\nBody\n';
425
+ const before={files:{'1.guide/requirements.md':old}};
426
+ const check=content=>()=>inspectPrdChangeVersionHistory(before,[{directory:'1.guide',documents:[{path:'requirements.md',content}]}]);
427
+ assert.throws(check(`${old}Changed\n\`\`\`\n| 示例 | v2 | 非版本表 |\n\`\`\`\n`),/prd_change_version_history_missing/);
428
+ assert.throws(check(`${old}Changed\n| 2026-09-08 | v1 | original |\n`),/prd_change_version_history_missing/);
429
+ assert.doesNotThrow(check(old.replace('| original |','| original |\n| 2026-12-01 | v2 | change |')+'Changed\n'));
430
+ assert.doesNotThrow(check(old),'unchanged document needs no new row');
431
+ // 审查 r2:四反引号里的三反引号不提前结束围栏;三反引号里的 ~~~ 也不结束它。
432
+ assert.throws(check(`${old}Changed\n\`\`\`\`\n\`\`\`\n| 示例 | v2 | 非版本表 |\n\`\`\`\n\`\`\`\`\n`),/prd_change_version_history_missing/);
433
+ assert.doesNotThrow(check(`${old}Changed\n\`\`\`\n~~~\n\`\`\`\n| 2026-12-01 | v2 | change |\n`));
434
+ // 审查 r3:块内「三反引号加 ~」混合字符行不关闭围栏。
435
+ assert.throws(check(`${old}Changed\n\`\`\`\n\`\`\`~\n| 示例 | v2 | 非版本表 |\n\`\`\`\n`),/prd_change_version_history_missing/);
436
+ });
437
+ // dogfood 2026-12-01(问题 5、19):请求多带或少带字段时,错误输出要说清是哪个字段,不能只有 invalid_input。
438
+ test('a request with an extra or missing field names the field in the diagnostic', {timeout:25000},async t=>{
439
+ const dir=fixture(t);const c=await client(t,dir,changeResponse);
440
+ // stderr is a separate pipe: wait for the diagnostic line instead of racing the stdout reply.
441
+ // Wait for the whole diagnostic line (up to its newline), so a later chunk cannot hide part of it.
442
+ const seen=async pattern=>{const line=new RegExp(pattern.source+'[^\\n]*\\n');
443
+ for(let i=0;i<100&&!line.test(c.stderr());i++)await new Promise(r=>setTimeout(r,20));return c.stderr();};
444
+ const extra=await c.request('cancel',{reason:'leftover-value'});
445
+ assert.equal(extra.error?.code,'host_request_failed');
446
+ assert.match(await seen(/多余字段:reason/),/"code":"invalid_input"/);
447
+ const missing=await c.request('decision',{approved:true,allowUserCaseChanges:false});
448
+ assert.equal(missing.error?.code,'host_request_failed');assert.match(await seen(/缺少字段:proposalDigest/),/缺少字段:proposalDigest/);
449
+ // Review r1: an unknown key may be misplaced secret text, so only its count is reported; values never appear.
450
+ await c.request('cancel',{'sk-secret-token-AAAA':'v'});
451
+ const text=await seen(/另有 1 个非本宿主字段/);
452
+ assert.match(text,/另有 1 个非本宿主字段/);assert.doesNotMatch(text,/sk-secret|leftover-value/);
453
+ await c.close();
454
+ });
@@ -24,13 +24,14 @@ import {writeApprovalSnapshot} from '../runtime/js/cm-ai/spec-amendment.mjs';
24
24
  import {writeSpecsStatus} from '../runtime/js/specs-status.mjs';
25
25
  import {buildManifest} from './cm-spec-manifest.mjs';
26
26
  import {recordPrdHostDisposition,createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition.mjs';
27
+ import {aiDraftAnalyzed,aiDraftSummaryFields,AI_DRAFT_REQUIREMENTS_NOTE,AI_DRAFT_DESIGN_BASIS} from './cm-prd-ai-draft-fixture.mjs';
27
28
  const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
28
29
  const riskSignals=high=>({greenfieldAdr:false,architectureOrDataFlow:high,newRuntimeDependencyOrToolchain:false,
29
30
  publicContractDataOrSecurity:false,fiveOrMoreFunctions:false});
30
31
  const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
31
32
  const design=()=>({status:'design',summary:'Synthetic design before tasks',features:[{name:'guide',documents:[
32
- {path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
33
- {path:'design.md',content:'## 方案摘要\nSynthetic new architecture'}]}]});
33
+ {path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'+AI_DRAFT_REQUIREMENTS_NOTE},
34
+ {path:'design.md',content:'## 方案摘要\nSynthetic new architecture'+AI_DRAFT_DESIGN_BASIS}]}]});
34
35
  function fixture(t){
35
36
  const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-design-phase-')));
36
37
  t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));fs.mkdirSync(path.join(dir,'docs'));
@@ -127,10 +128,10 @@ test('late design response cannot erase an existing draft or reset self-check ro
127
128
  assert.equal(host.status().selfCheckRound,1);assert.deepEqual(host.status().draft,original);
128
129
  assert.equal(host.status().designDraft,null);
129
130
  });
130
- for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','promote','saved-promote','split-correct','split-manual','split-requirements','split-failed-design','split-failed-requirements','design-narrow','split-correct-narrow'])test(`actual CLI disposed design to tasks: ${mode}`, {timeout:FIXTURE_TIMEOUT_MS},async t=>{
131
- const promotes=['promote','saved-promote'].includes(mode),succeeds=['design-narrow','split-correct-narrow','self-check-revision','saved','late-risk','promote','saved-promote','split-correct','split-manual','split-requirements','split-failed-design','split-failed-requirements'].includes(mode);
131
+ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','promote','saved-promote','split-correct','split-manual','split-requirements','split-failed-design','split-failed-requirements','design-narrow','split-correct-narrow','design-narrow-accept'])test(`actual CLI disposed design to tasks: ${mode}`, {timeout:FIXTURE_TIMEOUT_MS},async t=>{
132
+ const promotes=['promote','saved-promote'].includes(mode),succeeds=['design-narrow','split-correct-narrow','design-narrow-accept','self-check-revision','saved','late-risk','promote','saved-promote','split-correct','split-manual','split-requirements','split-failed-design','split-failed-requirements'].includes(mode);
132
133
  const revisesSplit=mode.startsWith('split-');let splitPackage,pendingSplit,checks=0;
133
- let originalDigest,originalDecisions,narrowArtifacts;
134
+ let originalDigest,originalDecisions,narrowArtifacts,narrowDecisionProbe;
134
135
  const dir=fixture(t);fs.mkdirSync(path.join(dir,'mirror'));
135
136
  const child=spawn(process.execPath,[path.join(root,'scripts/cm-prd-host.mjs'),'serve',
136
137
  '--skill-dir',path.join(root,'skills/cm-prd'),'--project',dir,'--specs',dir,'--runtime','codex',
@@ -149,13 +150,16 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
149
150
  assert.ok(message.error,JSON.stringify(message));
150
151
  send({requestId:'narrow2',operation:'narrow_review',stage:'design',feature:'1.guide',packageDigest:originalDigest,round:2,
151
152
  designSha256:sha(fs.readFileSync(path.join(dir,'1.guide/design.md'),'utf8')),reviewer:'codex-gpt-6.2-sol',
152
- sessionId:'narrow-reviewer-2',independent:true,at:'2026-11-24T02:00:00.000Z',verdict:'approved',summary:'Narrow review 2',findings:[]});continue;
153
+ sessionId:'narrow-reviewer-2',independent:true,at:'2026-11-24T02:00:00.000Z',summary:'Narrow review 2',
154
+ ...(mode==='design-narrow-accept'?{verdict:'changes_requested',findings:[{id:'N2',severity:'major',security:false,dataLoss:false,
155
+ silentFailure:false,violatesWrittenRule:false,scenario:'Concurrent edit loses the merge',message:'Merge race stays open'}]}
156
+ :{verdict:'approved',findings:[]})});continue;
153
157
  }
154
- assert.equal(message.error,undefined,JSON.stringify(message));
158
+ if(message.requestId!=='summary-missing-decision')assert.equal(message.error,undefined,JSON.stringify(message));
155
159
  if(message.type==='host_ready'){sessionId=message.sessionId;send({requestId:'start',operation:'start',text:'Analyze'});}
156
160
  else if(message.type==='host_request'){
157
161
  let result;
158
- if(message.kind==='prd_analyze')result={status:'analyzed',summary:'Architecture',sourcePaths:['docs/input.md'],openQuestions:[]};
162
+ if(message.kind==='prd_analyze')result=aiDraftAnalyzed({status:'analyzed',summary:'Architecture',sourcePaths:['docs/input.md'],openQuestions:[]});
159
163
  else if(message.kind==='prd_generate'){
160
164
  if(message.payload.phase==='design'||message.payload.phase==='full_draft'){
161
165
  assert.equal(message.payload.phase,mode==='late-risk'||promotes?'full_draft':'design');
@@ -187,20 +191,20 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
187
191
  assert.deepEqual(message.payload.review.findings.map(item=>item.id),['N1']);
188
192
  result={decisions:[{id:'N1',status:'applied',evidence:['Narrow fix'],changedPaths:['1.guide/design.md']}],
189
193
  documents:message.payload.documents.map(item=>({path:item.path,content:item.path==='1.guide/design.md'?
190
- '## 方案摘要\nCorrected architecture boundary after narrow review':item.content}))};
194
+ '## 方案摘要\nCorrected architecture boundary after narrow review'+AI_DRAFT_DESIGN_BASIS:item.content}))};
191
195
  }
192
196
  else if(message.kind==='prd_correct'){
193
197
  const correctionPath=['split-requirements','split-failed-requirements'].includes(mode)&&message.payload.review.stage==='split'?'1.guide/requirements.md':'1.guide/design.md';
194
198
  result={decisions:[{id:'R1',status:'applied',evidence:['Clarified boundary'],changedPaths:[correctionPath]}],
195
199
  documents:message.payload.documents.map(item=>({path:item.path,content:item.path===correctionPath?
196
- (correctionPath.endsWith('/requirements.md')?item.content+'\nFailure scenario: explain invalid setup.':`## 方案摘要\nCorrected architecture boundary${message.payload.review.stage==='split'?' after split':''}`):item.content}))};
200
+ (correctionPath.endsWith('/requirements.md')?item.content+'\nFailure scenario: explain invalid setup.':`## 方案摘要\nCorrected architecture boundary${message.payload.review.stage==='split'?' after split':''}${AI_DRAFT_DESIGN_BASIS}`):item.content}))};
197
201
  }else if(message.kind==='prd_summary'){
198
202
  result={evidenceDigest:message.payload.evidenceDigest,deliveryForm:'Synthetic architecture documentation',
199
203
  estimatedTime:'Needs human review',openQuestions:'None in fixture',risks:'Synthetic host responses only',
200
204
  contextScope:'One feature',platformReadiness:'Not live verified',uiBaseline:'Not applicable',
201
205
  designRisk:[{feature:'1.guide',signals:{greenfieldAdr:false,architectureOrDataFlow:true,
202
206
  newRuntimeDependencyOrToolchain:false,publicContractDataOrSecurity:false,fiveOrMoreFunctions:false},
203
- evidence:['Synthetic new architecture requirement']}]};
207
+ evidence:['Synthetic new architecture requirement']}],...aiDraftSummaryFields()};
204
208
  }else{
205
209
  assert.equal(message.kind,'prd_review');reviews++;
206
210
  const isDesign=message.payload.package.stage==='design';
@@ -242,7 +246,7 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
242
246
  send({requestId:'correct',operation:'correct_findings',stage:'design',feature:'1.guide'});
243
247
  }else if(message.requestId==='correct'){
244
248
  assert.equal(message.result.status,'correction_saved');
245
- if(['design-narrow','split-correct-narrow'].includes(mode)){
249
+ if(['design-narrow','split-correct-narrow','design-narrow-accept'].includes(mode)){
246
250
  originalDecisions=message.result.decisions;originalDigest=message.result.packageDigest;
247
251
  send({requestId:'narrow1',operation:'narrow_review',stage:'design',feature:'1.guide',packageDigest:originalDigest,round:1,
248
252
  designSha256:sha(fs.readFileSync(path.join(dir,'1.guide/design.md'),'utf8')),reviewer:'codex-gpt-6.2-sol',
@@ -259,6 +263,16 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
259
263
  assert.equal(message.result.status,'correction_saved');assert.equal(message.result.narrow,true);narrowArtifacts=message.result.artifacts;
260
264
  send({requestId:'dispose-too-early',operation:'review_disposition',stage:'design',feature:'1.guide',
261
265
  packageDigest:originalDigest,decisions:originalDecisions,artifacts:narrowArtifacts});
266
+ }else if(message.requestId==='narrow2'&&mode==='design-narrow-accept'){
267
+ // dogfood 2026-11-30: the second-round stop had no way forward but cancel.
268
+ assert.equal(message.result.phase.status,'awaiting_user_decision');
269
+ send({requestId:'accept',operation:'narrow_user_decision',stage:'design',feature:'1.guide',packageDigest:originalDigest,round:2,
270
+ designSha256:sha(fs.readFileSync(path.join(dir,'1.guide/design.md'),'utf8')),decision:'accept_risks',
271
+ userWords:'带风险继续',acceptedFindingIds:['N2'],at:'2026-11-24T03:00:00.000Z'});
272
+ }else if(message.requestId==='accept'){
273
+ assert.equal(message.result.phase.status,'user_accepted');
274
+ send({requestId:'dispose',operation:'review_disposition',stage:'design',feature:'1.guide',
275
+ packageDigest:originalDigest,decisions:originalDecisions,artifacts:narrowArtifacts});
262
276
  }else if(message.requestId==='narrow2'){
263
277
  assert.equal(message.result.phase.status,'approved');
264
278
  send({requestId:'dispose',operation:'review_disposition',stage:'design',feature:'1.guide',
@@ -282,7 +296,7 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
282
296
  }else if(message.requestId==='split'){
283
297
  assert.equal(message.result.reviewState.status,'review_recorded');
284
298
  if(mode==='split-manual'){
285
- const content='## 方案摘要\nManual split architecture correction';fs.writeFileSync(path.join(dir,'1.guide/design.md'),content);
299
+ const content='## 方案摘要\nManual split architecture correction'+AI_DRAFT_DESIGN_BASIS;fs.writeFileSync(path.join(dir,'1.guide/design.md'),content);
286
300
  pendingSplit={packageDigest:splitPackage.packageDigest,decisions:[{id:'R1',status:'applied',evidence:['Manual saved correction'],changedPaths:['1.guide/design.md']}],
287
301
  artifacts:splitPackage.artifacts.map(a=>a.path==='1.guide/design.md'?{...a,sha256:sha(content)}:a)};
288
302
  }
@@ -303,13 +317,34 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
303
317
  }else if(message.requestId==='split-dispose'){
304
318
  assert.equal(message.result.gate.outcome,'completed');
305
319
  if(mode.startsWith('split-failed'))assert.equal(message.result.gate.disposition,'self_check_failed');
320
+ if(mode==='design-narrow-accept'){
321
+ // Review r1: a decision lost or rewritten after the receipt must block, never drop the accepted risks.
322
+ const file=path.join(dir,'.reviews/prd-guide-design-narrow-decision.json'),original=fs.readFileSync(file);
323
+ narrowDecisionProbe={file,original};fs.renameSync(file,file+'.aside');
324
+ send({requestId:'summary-missing-decision',operation:'prepare_summary'});continue;
325
+ }
306
326
  send(revisesSplit?{requestId:'split-resaved',operation:'save_draft'}:{requestId:'summary',operation:'prepare_summary'});
327
+ }else if(message.requestId==='summary-missing-decision'){
328
+ // The narrow chain then reads as an open user stop, so the host refuses outright; either way nothing publishes.
329
+ assert.ok(message.error||message.result.blockers.includes('1.guide: narrow_user_decision_binding_mismatch'),JSON.stringify(message));
330
+ const {file,original}=narrowDecisionProbe;fs.renameSync(file+'.aside',file);
331
+ const value=JSON.parse(original.toString('utf8'));value.userWords='改写后的话';
332
+ fs.chmodSync(file,0o600);fs.writeFileSync(file,JSON.stringify(value)+'\n');
333
+ send({requestId:'summary-rewritten-decision',operation:'prepare_summary'});
334
+ }else if(message.requestId==='summary-rewritten-decision'){
335
+ assert.ok(message.result.blockers.includes('1.guide: narrow_user_decision_binding_mismatch'),JSON.stringify(message.result.blockers));
336
+ fs.writeFileSync(narrowDecisionProbe.file,narrowDecisionProbe.original);
337
+ send({requestId:'summary',operation:'prepare_summary'});
307
338
  }else if(message.requestId==='split-resaved'){
308
339
  assert.equal(message.result.status,'draft_saved');assert.equal(checks,2);
309
340
  send({requestId:'summary',operation:'prepare_summary'});
310
341
  }else if(message.requestId==='summary'){
311
342
  assert.equal(message.result.readyForAwaitingReview,true);
312
343
  if(mode==='self-check-revision')assert.match(message.result.details.risks,/整稿自检失败.*未另做设计审查/);
344
+ if(mode==='design-narrow-accept'){
345
+ assert.match(message.result.details.risks,/设计窄审第 2 轮仍有阻断,用户决定带风险继续(原话:"带风险继续");未解决:N2(major)Merge race stays open/);
346
+ assert.ok(message.result.publicationInput.some(item=>item.path==='.reviews/prd-guide-design-narrow-decision.json'));
347
+ }
313
348
  assert.deepEqual(message.result.blockers,[]);
314
349
  if(mode.startsWith('split-failed')){
315
350
  assert.equal(message.result.features[0].reviews.split.correctionSelfCheck.status,'failed');