@aibyzero/cm-workflow 0.13.3 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +34 -1
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +55 -0
  7. package/docs/user-guide.md +3 -0
  8. package/package.json +1 -1
  9. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +1 -0
  10. package/runtime/js/cm-ai/cm-ai-admission.mjs +53 -22
  11. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +4 -5
  12. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +40 -17
  13. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +103 -23
  14. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -4
  15. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +5 -2
  16. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  17. package/runtime/js/cm-ai/developer-adapter.mjs +17 -5
  18. package/runtime/js/cm-ai/durable-runner-state.mjs +7 -2
  19. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  20. package/runtime/js/cm-ai/execution-store.mjs +25 -5
  21. package/runtime/js/cm-ai/host-check.mjs +20 -1
  22. package/runtime/js/cm-ai/host-conversation-execution.mjs +5 -4
  23. package/runtime/js/cm-ai/host-documentation.mjs +2 -2
  24. package/runtime/js/cm-ai/host-qa-executor.mjs +46 -24
  25. package/runtime/js/cm-ai/host-qa-policy.mjs +3 -1
  26. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +41 -3
  27. package/runtime/js/cm-ai/qa-environment.mjs +22 -0
  28. package/runtime/js/cm-ai/task-runner.mjs +1 -0
  29. package/runtime/js/cm-ai/worker-claude-developer.mjs +2 -1
  30. package/runtime/js/cm-fix/cause-package.mjs +3 -1
  31. package/runtime/js/cm-fix/dossier.mjs +7 -2
  32. package/runtime/js/cm-fix/reproduce.mjs +26 -5
  33. package/runtime/js/cm-fix/visual.mjs +3 -2
  34. package/runtime/js/cm-fix/walkthrough.mjs +2 -1
  35. package/runtime/js/cm-init/draft-generation.mjs +3 -2
  36. package/runtime/js/cm-init/draft-inspection.mjs +17 -3
  37. package/runtime/js/cm-init/review-evidence.mjs +1 -1
  38. package/runtime/js/cm-prd/summary.mjs +6 -8
  39. package/runtime/js/cm-security/finalize.mjs +164 -0
  40. package/runtime/js/cm-test/host.mjs +2 -2
  41. package/runtime/js/specs-status.mjs +66 -0
  42. package/runtime/project-context.md +4 -1
  43. package/scripts/cm-ai-admission.mjs +46 -7
  44. package/scripts/cm-ai-admission.test.mjs +50 -0
  45. package/scripts/cm-ai-batch-host.mjs +72 -10
  46. package/scripts/cm-ai-batch-host.test.mjs +128 -4
  47. package/scripts/cm-ai-batch-run.mjs +366 -17
  48. package/scripts/cm-ai-batch-run.test.mjs +222 -13
  49. package/scripts/cm-ai-bootstrap.test.mjs +3 -2
  50. package/scripts/cm-ai-host.mjs +38 -21
  51. package/scripts/cm-ai-host.test.mjs +68 -4
  52. package/scripts/cm-ai-nested-execution.test.mjs +1 -1
  53. package/scripts/cm-ai-run.mjs +25 -15
  54. package/scripts/cm-ai-run.test.mjs +48 -0
  55. package/scripts/cm-blocked-reason.test.mjs +104 -0
  56. package/scripts/cm-capability-gate.test.mjs +179 -0
  57. package/scripts/cm-check-update.mjs +5 -2
  58. package/scripts/cm-check-update.test.mjs +21 -0
  59. package/scripts/cm-codex-developer-adapter.test.mjs +70 -0
  60. package/scripts/cm-fix-cause-package.test.mjs +18 -1
  61. package/scripts/cm-fix-execution.test.mjs +31 -0
  62. package/scripts/cm-fix-host-review.test.mjs +2 -1
  63. package/scripts/cm-fix-host.test.mjs +2 -1
  64. package/scripts/cm-fix-observation-dossier.test.mjs +2 -0
  65. package/scripts/cm-fix-qa-source.test.mjs +1 -3
  66. package/scripts/cm-fix-reproduce.test.mjs +53 -2
  67. package/scripts/cm-fix-review-recovery.test.mjs +4 -3
  68. package/scripts/cm-host-check.test.mjs +22 -0
  69. package/scripts/cm-host-qa-executor.test.mjs +302 -3
  70. package/scripts/cm-host-qa-policy.test.mjs +34 -0
  71. package/scripts/cm-init-draft-generation.test.mjs +24 -3
  72. package/scripts/cm-init-draft-inspection.test.mjs +80 -0
  73. package/scripts/cm-init-host.mjs +2 -2
  74. package/scripts/cm-init-host.test.mjs +3 -1
  75. package/scripts/cm-init-session.test.mjs +37 -0
  76. package/scripts/cm-log-event.mjs +28 -7
  77. package/scripts/cm-prd-design-phase.test.mjs +2 -1
  78. package/scripts/cm-prd-host.test.mjs +3 -2
  79. package/scripts/cm-prd-session-recovery.test.mjs +5 -4
  80. package/scripts/cm-qa-environment.test.mjs +30 -0
  81. package/scripts/cm-security.mjs +12 -4
  82. package/scripts/cm-security.test.mjs +109 -0
  83. package/scripts/cm-specs-status.test.mjs +130 -0
  84. package/scripts/cm-workflow-config.mjs +4 -0
  85. package/scripts/test-shell-compat.sh +0 -0
  86. package/skills/cm-ai/references/N1-init.md +22 -15
  87. package/skills/cm-ai/references/N5-mark-done.md +5 -2
  88. package/skills/cm-ai/references/N6-qa-eval.md +9 -4
  89. package/skills/cm-ai/references/js-host.md +25 -0
  90. package/skills/cm-fix/SKILL.md +5 -4
  91. package/skills/cm-fix/references/js-host.md +13 -0
  92. package/skills/cm-idea/SKILL.md +2 -0
  93. package/skills/cm-init/references/runtime-declaration.md +2 -0
  94. package/skills/cm-prd/SKILL.md +9 -8
  95. package/skills/cm-prd/references/spec-self-check.md +1 -0
  96. package/skills/cm-security/SKILL.md +14 -7
  97. package/skills/cm-security/references/scan-contract.md +45 -1
  98. package/skills/cm-test/references/js-host.md +4 -3
  99. package/templates/dashboard/dashboard.html +2 -2
@@ -6,7 +6,7 @@ import {spawnSync} from 'node:child_process';
6
6
  import {fileURLToPath} from 'node:url';
7
7
  import {loadConfig,resolveRole} from '../../../scripts/cm-workflow-config.mjs';
8
8
  import {validateTestCases} from '../../../scripts/validate-test-cases.mjs';
9
- import {inspectCmAiAdmission} from './cm-ai-admission.mjs';
9
+ import {inspectCmAiAdmission,inspectCmAiQaTaskContext} from './cm-ai-admission.mjs';
10
10
  import {createHostCheck} from './host-check.mjs';
11
11
  import {specsPermissionArgs} from './codex-config.mjs';
12
12
  import {resolveCodeProjects,codeProjectPaths} from './code-projects.mjs';
@@ -14,12 +14,13 @@ import {findCmAiQaDecision,readCmAiQaRunRound,reportFile} from './cm-ai-qa-log.m
14
14
  import {captureReviewBaseline} from './review-package.mjs';
15
15
  import {writeCmAiQaStatus} from './cm-ai-run-finalizer.mjs';
16
16
  import {digest,freeze,hex,id,json,need,shape,text,validCallTimeout,validIdentity} from './effect-contract.mjs';
17
+ import {isQaEnvironmentCarrier,QA_ENVIRONMENT_SCOPES} from './qa-environment.mjs';
17
18
 
18
19
  const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
19
20
  const order={ 'cm-default':['logic','commands','browser'],
20
21
  'java-backend':['commands','logic','browser'],'web-frontend':['commands','browser','logic'] };
21
22
 
22
- function readPlan(configuration) {
23
+ function readPlan(configuration,selectCompleted=true) {
23
24
  const {codeProject,specsDir,feature,commands}=configuration;
24
25
  const admission=inspectCmAiAdmission({specsDir,codeProject});
25
26
  need(['ready','complete'].includes(admission.state),admission.reason??'qa_admission_required');
@@ -35,15 +36,25 @@ function readPlan(configuration) {
35
36
  need(validateTestCases(contract).length===0&&contract.feature===feature.replace(/^\d+\./,''),'test_cases_invalid');
36
37
  cases=contract.cases;
37
38
  }
38
- const selected=cases.filter(item=>item.blocking||config.policies.tests.includes(item.kind));
39
+ const context=selectCompleted?inspectCmAiQaTaskContext({specsDir,codeProject,feature}):{completed:[],pending:0};
40
+ const completed=new Set(context.completed.filter(task=>task.feature===feature).map(task=>task.id));
41
+ const applicable=cases.filter(item=>item.blocking||config.policies.tests.includes(item.kind));
42
+ const deferred=context.pending===0?[]:applicable.map(item=>({id:item.id,
43
+ taskIds:item.taskIds.filter(taskId=>!completed.has(taskId))})).filter(item=>item.taskIds.length>0);
44
+ const deferredIds=new Set(deferred.map(item=>item.id));
45
+ const selected=applicable.filter(item=>!deferredIds.has(item.id));
39
46
  const wanted=new Set(selected.filter(item=>item.kind==='logic').map(item=>item.id));
40
- const scheduled=commands.filter(item=>config.policies.tests.includes('commands')
41
- ||item.caseIds.some(caseId=>wanted.has(caseId)));
47
+ const scheduled=commands.filter(item=>(config.policies.tests.includes('commands')
48
+ &&(context.pending===0||item.caseIds.length===0))||item.caseIds.some(caseId=>wanted.has(caseId)));
42
49
  for(const item of commands)for(const caseId of item.caseIds)
43
50
  need(cases.some(candidate=>candidate.id===caseId&&candidate.kind==='logic'),'qa_command_mapping_invalid');
44
51
  const modes=order[config.project.workflow].filter(mode=>mode==='commands'
45
- ?scheduled.length>0||config.policies.tests.includes('commands'):selected.some(item=>item.kind===mode));
46
- return json({config,cases:selected,commands:scheduled,modes});
52
+ ?scheduled.length>0||(config.policies.tests.includes('commands')&&(context.pending===0||commands.length===0))
53
+ :selected.some(item=>item.kind===mode));
54
+ const noApplicableCases=context.pending>0&&selected.length===0&&scheduled.length===0;
55
+ if(noApplicableCases)modes.splice(0,modes.length,'commands');
56
+ return json({config,cases:selected,...(selectCompleted?{deferred_cases:deferred}:{}),commands:scheduled,modes,
57
+ ...(noApplicableCases?{no_applicable_cases:true}:{})});
47
58
  }
48
59
 
49
60
  function logStep(configuration,binding,event,phase,data,detail) {
@@ -73,13 +84,14 @@ function evidence(raw) {
73
84
  return result;
74
85
  }
75
86
 
76
- function saveReport(configuration,binding,rows,summary) {
87
+ function saveReport(configuration,binding,rows,summary,deferred) {
77
88
  const reviews=path.join(configuration.specsDir,'.reviews'),stat=fs.lstatSync(reviews);
78
89
  need(stat.isDirectory()&&!stat.isSymbolicLink()&&fs.realpathSync(reviews)===reviews,'qa_report_invalid');
79
90
  const target=path.join(reviews,`${binding.testRunId}-execution.md`);
80
91
  const body=Buffer.from(`# CM QA execution report\n\nOverall: ${summary.result}\n\n`
81
92
  +'Counts are declared command checks plus selected cases, not framework test totals.\n'
82
93
  +'Static verdicts are retained separately; only observed command/browser evidence counts as PASS.\n\n'
94
+ +`## deferred_cases\n\n${JSON.stringify(deferred,null,2)}\n\n`
83
95
  +rows.map(row=>`## ${row.id}\n\n${JSON.stringify(row,null,2)}\n`).join('\n'));
84
96
  need(body.length<=1024*1024,'limit_exceeded');
85
97
  const fd=fs.openSync(target,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY|fs.constants.O_NOFOLLOW,0o600);
@@ -115,19 +127,24 @@ export function createHostQaExecutor(options) {
115
127
  }
116
128
  shape(configuration.environment,['kind','carrier','target','scope']);
117
129
  const environment=configuration.environment;
118
- need(['local','test'].includes(environment.scope),'qa_environment_required');text(environment.target);
119
- const carriers={web:['browser'],app:['ios-simulator','android-emulator','device'],miniprogram:['wechat-devtools','device']};
120
- need(carriers[environment.kind]?.includes(environment.carrier),'qa_environment_required');
121
- const plan=readPlan(configuration);
122
- need(!plan.cases.some(item=>ids.has(item.id)),'qa_id_conflict');
123
- // One missing-command item keeps an empty invocation from passing as zero tests.
124
- const commandCount=plan.modes.includes('commands')?Math.max(1,plan.commands.length):0;
125
- const caseCount=Math.max(1,commandCount+plan.cases.length);
126
- const mode=plan.modes.length===1&&['commands','browser'].includes(plan.modes[0])?plan.modes[0]:'all';
127
- const metadata=json({kind:'cm-host-qa-executor-v1',...configuration,plan,
128
- capabilities:{logic:logic!==null,browser:browser!==null}});
129
- return Object.freeze({mode,caseCount,timeoutMs:configuration.timeoutMs,configuration:metadata,
130
+ need(QA_ENVIRONMENT_SCOPES.includes(environment.scope),'qa_environment_required');text(environment.target);
131
+ need(isQaEnvironmentCarrier(environment.kind,environment.carrier),'qa_environment_required');
132
+ const describe=plan=>{
133
+ need(!plan.cases.some(item=>ids.has(item.id)),'qa_id_conflict');
134
+ // One missing-command item keeps an empty invocation from passing as zero tests.
135
+ const commandCount=plan.modes.includes('commands')?Math.max(1,plan.commands.length):0;
136
+ const caseCount=Math.max(1,commandCount+plan.cases.length);
137
+ const mode=plan.modes.length===1&&['commands','browser'].includes(plan.modes[0])?plan.modes[0]:'all';
138
+ return json({mode,caseCount,configuration:{kind:'cm-host-qa-executor-v1',...configuration,plan,
139
+ capabilities:{logic:logic!==null,browser:browser!==null}}});
140
+ };
141
+ // Preserve the historical configuration fingerprint across N5 and old-run
142
+ // resume. Selection is invocation data, frozen by prepare at N6 instead.
143
+ const initial=describe(readPlan(configuration,false));let prepared=null;
144
+ const prepare=()=>{prepared=describe(readPlan(configuration));return freeze(prepared);};
145
+ return Object.freeze({...initial,timeoutMs:configuration.timeoutMs,prepare,
130
146
  async run(rawBinding,signal){
147
+ const {mode,caseCount,configuration:{plan}}=prepared??prepare();
131
148
  let binding=json(rawBinding);
132
149
  shape(binding,['specsDir','codeProject','feature','identity','packageDigest','testRunId','mode','caseCount',
133
150
  ...(Object.hasOwn(binding,'qaRound')?['qaRound']:[])]);
@@ -159,7 +176,10 @@ export function createHostQaExecutor(options) {
159
176
  for(const stage of plan.modes){
160
177
  const routed=route(stage==='browser'?'browser_qa':'tester');
161
178
  if(stage==='commands'){
162
- if(!plan.commands.length)rows.push({id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No declared project test command']});
179
+ if(plan.no_applicable_cases)rows.push({id:'no-applicable-cases',kind:'commands',verdict:'BLOCKED',
180
+ evidence:['all applicable cases are bound to unfinished tasks; deferred to feature completion',
181
+ ...plan.deferred_cases.map(item=>`${item.id}: ${item.taskIds.join(', ')}`)]});
182
+ else if(!plan.commands.length)rows.push({id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No declared project test command']});
163
183
  for(const command of plan.commands){
164
184
  notCancelled();
165
185
  const check=createHostCheck({cwd:roots?command.codeProject:configuration.codeProject,commands:[{id:command.id,command:command.command}],
@@ -197,12 +217,13 @@ export function createHostQaExecutor(options) {
197
217
  ...(hostRequestTimeout?{hostRequestTimeout:true}:{})});
198
218
  }else{
199
219
  logStep(configuration,binding,'test_run','case_start',{case_id:item.id},'QA browser case started');
200
- let observed;
220
+ let observed,hostRequestTimeout=false;
201
221
  if(browser===null||item.expected.some(value=>value.includes('[需确认]')))
202
222
  observed={verdict:'BLOCKED',evidence:[],environment,cleanup:'not_needed'};
203
223
  else try{observed=json(await browser(request,signal));}
204
224
  catch(error){
205
225
  if(error.code!=='host_request_timeout')throw error;
226
+ hostRequestTimeout=true;
206
227
  observed={verdict:'BLOCKED',evidence:['host_request_timeout'],environment,cleanup:'failed'};
207
228
  }
208
229
  notCancelled();shape(observed,['verdict','evidence','environment','cleanup']);
@@ -218,7 +239,8 @@ export function createHostQaExecutor(options) {
218
239
  const verdict=evidenceProblem!==null||digest(observed.environment)!==digest(environment)||observed.cleanup==='failed'
219
240
  ||(item.cleanup.length>0&&observed.cleanup!=='completed')?'BLOCKED':observed.verdict;
220
241
  rows.push({id:item.id,kind:'browser',origin:item.origin,blocking:item.blocking,verdict,
221
- evidence:observed.evidence,evidenceProblem,environment:observed.environment,cleanup:observed.cleanup});
242
+ evidence:observed.evidence,evidenceProblem,environment:observed.environment,cleanup:observed.cleanup,
243
+ ...(hostRequestTimeout?{hostRequestTimeout:true}:{})});
222
244
  logStep(configuration,binding,'test_run',verdict==='BLOCKED'?'case_blocked':'case_complete',
223
245
  {case_id:item.id,result:verdict},'QA browser case finished');
224
246
  }
@@ -245,7 +267,7 @@ export function createHostQaExecutor(options) {
245
267
  blocked=rows.filter(item=>item.verdict==='BLOCKED').length;
246
268
  need(passed+failed+blocked===caseCount,'qa_result_invalid');
247
269
  const summary={result:failed>0?'FAIL':blocked>0?'BLOCKED':'PASS',passed,failed,blocked};
248
- const report=saveReport(configuration,binding,rows,summary);
270
+ const report=saveReport(configuration,binding,rows,summary,plan.deferred_cases);
249
271
  return json({...summary,report});
250
272
  }});
251
273
  }
@@ -9,7 +9,9 @@ const key=(feature,task)=>`${feature}/${task}`;
9
9
 
10
10
  function history(binding,context) {
11
11
  const completed=new Set(context.completed.map(task=>key(task.feature,task.id)));
12
- const unseen=new Set(completed),since=new Set();
12
+ const pendingFeatures=new Set(context.pendingFeatures);
13
+ const unseen=new Set(context.completed.filter(task=>pendingFeatures.has(task.feature))
14
+ .map(task=>key(task.feature,task.id))),since=new Set();
13
15
  const log=path.join(binding.specsDir,'运行日志.jsonl');
14
16
  if(fs.existsSync(log))scanRows(log,row=>{
15
17
  if(row?.schema_version!==1||row.workflow!=='cm-ai'||row.event!=='qa'||row.node!=='N6'
@@ -1,9 +1,37 @@
1
1
  // Fixed current-conversation capabilities over the existing N6/N8 adapters.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import {json,need,shape} from './effect-contract.mjs';
4
+ import {digest,json,need,shape,validIdentity,hex} from './effect-contract.mjs';
5
5
  import {createHostQaDecisionProvider} from './host-qa-policy.mjs';
6
6
  import {createHostQaExecutor} from './host-qa-executor.mjs';
7
+ import {loadConfig} from '../../../scripts/cm-workflow-config.mjs';
8
+ import {validateTestCases} from '../../../scripts/validate-test-cases.mjs';
9
+
10
+ // Browser capability is a property of the launching session, not of the project.
11
+ // The host cannot probe whether this session can drive a browser; it can only
12
+ // require a fresh explicit assertion, so a mismatch surfaces at launch
13
+ // instead of at the last QA step. Declaration, not detection.
14
+ export function featureHasBrowserCases(specsDir,feature,codeProject){
15
+ const source=path.join(specsDir,feature,'test-cases.json');
16
+ if(!fs.existsSync(source))return false;
17
+ const stat=fs.lstatSync(source);
18
+ need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=1024*1024,'test_cases_invalid');
19
+ const bytes=fs.readFileSync(source);let contract;
20
+ try{contract=json(JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(bytes)));}
21
+ catch{need(false,'test_cases_invalid');}
22
+ need(validateTestCases(contract).length===0,'test_cases_invalid');
23
+ const config=loadConfig({projectRoot:codeProject});
24
+ // Match QA applicability before pending tasks defer execution.
25
+ return contract.cases.some(item=>item.kind==='browser'&&(item.blocking||config.policies.tests.includes('browser')));
26
+ }
27
+
28
+ export function readBrowserCapability(value,applicable){
29
+ if(!applicable){need(value===undefined,'invalid_arguments');return null;}
30
+ need(value!==undefined,'browser_capability_required');
31
+ need(['available','unavailable'].includes(value),'invalid_arguments');
32
+ need(value==='available','browser_capability_unavailable');
33
+ return 'available';
34
+ }
7
35
 
8
36
  export function readHostWorkflowConfiguration(file){
9
37
  const stat=fs.lstatSync(file);
@@ -24,7 +52,7 @@ export function validateHostWorkflowConfiguration(raw){
24
52
  return config;
25
53
  }
26
54
 
27
- export function createHostWorkflowCapabilities({definition,configuration,bridge,allowQa,runtime='codex',protectedExecution=false,bootstrap=null}){
55
+ export function createHostWorkflowCapabilities({definition,configuration,bridge,allowQa,runtime='codex',protectedExecution=false,bootstrap=null,parallelMember=false}){
28
56
  need(['codex','claude'].includes(runtime),'invalid_runtime');
29
57
  const {specsDir,codeProject,feature,requirements}=definition;
30
58
  const logHome=path.join(specsDir,'.reviews','host-log-mirror');
@@ -36,7 +64,7 @@ export function createHostWorkflowCapabilities({definition,configuration,bridge,
36
64
  need(allowQa===true,'qa_authorization_required');
37
65
  result.qaLogHome=logHome;
38
66
  const requestTimeout={timeoutMs:configuration.qa.timeoutMs??60000};
39
- result.qaDecisionProvider=createHostQaDecisionProvider({timeoutMs:60000,
67
+ result.qaDecisionProvider=parallelMember?createParallelMemberQaDecisionProvider():createHostQaDecisionProvider({timeoutMs:60000,
40
68
  assess:(request,signal)=>bridge.call('qa_assess',request,signal,requestTimeout)});
41
69
  result.qaExecutor=createHostQaExecutor({specsDir,codeProject,feature,requirements,runtime,
42
70
  ...(definition.codeProjects?{codeProjects:definition.codeProjects}:{}),
@@ -48,3 +76,13 @@ export function createHostWorkflowCapabilities({definition,configuration,bridge,
48
76
  }
49
77
  return result;
50
78
  }
79
+
80
+ export function createParallelMemberQaDecisionProvider(){
81
+ return Object.freeze({timeoutMs:60000,async decide(raw,signal){
82
+ const binding=json(raw);shape(binding,['specsDir','codeProject','feature','identity','packageDigest']);
83
+ validIdentity(binding.identity);hex(binding.packageDigest);need(!signal.aborted,'cancelled');
84
+ return {decisionId:`qa-${digest({identity:binding.identity,packageDigest:binding.packageDigest}).slice(0,48)}`,
85
+ identity:binding.identity,packageDigest:binding.packageDigest,status:'skipped',
86
+ reason:'parallel_member_deferred',score:4,at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
87
+ }});
88
+ }
@@ -0,0 +1,22 @@
1
+ // Single source of truth for QA / visual / walkthrough environment carriers.
2
+ // Previously duplicated verbatim in four modules; a new delivery form had to be
3
+ // added in every copy or the validators silently diverged.
4
+ // The list follows the delivery forms cm-prd confirms with the user
5
+ // (skills/cm-prd/references/greenfield.md), plus the backend, CLI and library
6
+ // projects cm-prd already recognises as having no deployment form.
7
+ export const QA_ENVIRONMENT_CARRIERS=Object.freeze({
8
+ web:Object.freeze(['browser']),
9
+ app:Object.freeze(['ios-simulator','android-emulator','device']),
10
+ miniprogram:Object.freeze(['wechat-devtools','device']),
11
+ desktop:Object.freeze(['app-window']),
12
+ service:Object.freeze(['cli','http-api']),
13
+ library:Object.freeze(['none']),
14
+ });
15
+ export const QA_ENVIRONMENT_SCOPES=Object.freeze(['local','test']);
16
+ // Validation only: nothing downstream branches on kind/carrier, the pair travels
17
+ // with each case request as declared provenance.
18
+ // hasOwn keeps an inherited key such as __proto__ from resolving to Object.prototype,
19
+ // which made the previous duplicated lookups throw instead of rejecting the value.
20
+ export function isQaEnvironmentCarrier(kind,carrier){
21
+ return Object.hasOwn(QA_ENVIRONMENT_CARRIERS,kind)&&QA_ENVIRONMENT_CARRIERS[kind].includes(carrier);
22
+ }
@@ -372,6 +372,7 @@ export function createTaskRunner(options) {
372
372
  const response=terminalFor(await bounded(adapter.run,request),request);active();
373
373
  call.terminal=response.status;call.effectiveModel=response.effectiveModel;call.resultDigest=digest(response.result);
374
374
  if(role==='developer'&&response.status==='failed'&&response.result!==null)call.failureResult=response.result;
375
+ if(role==='developer'&&Object.hasOwn(response,'blockedReason'))call.blockedReason=response.blockedReason;
375
376
  if(Object.hasOwn(response,'providerThreadId'))call.providerThreadId=response.providerThreadId;
376
377
  return {request,response,call};
377
378
  } catch(error){call.terminal=state==='cancelled'?'cancelled':'unknown';throw error;}
@@ -22,8 +22,9 @@ export function validateClaudeProposal(raw){
22
22
  shape(result,['status','value','edits']);
23
23
  const value=result.value,nullable=v=>v===null||typeof v==='string';
24
24
  need(value&&typeof value==='object','invalid_result');
25
- shape(value,['outcome',...['application','retrospective'].filter(key=>Object.hasOwn(value,key))]);
25
+ shape(value,['outcome',...['application','retrospective','reason'].filter(key=>Object.hasOwn(value,key))]);
26
26
  need(['implemented','blocked'].includes(value.outcome),'invalid_result');
27
+ if(Object.hasOwn(value,'reason'))need(nullable(value.reason),'invalid_result');
27
28
  if(Object.hasOwn(value,'application')){
28
29
  shape(value.application,['status','note']);
29
30
  need(['applied','no_relevant_lesson'].includes(value.application.status)&&nullable(value.application.note),'invalid_result');
@@ -3,6 +3,7 @@ import {readReviewSourceFiles,readReviewSourceRecords,readReviewPackage} from '.
3
3
  import {digest,id,json,need,shape,text,validIdentity} from '../cm-ai/effect-contract.mjs';
4
4
  import {inspectFixLearning} from './learning.mjs';
5
5
  import {inspectFixInvestigation} from './investigation.mjs';
6
+ import {inspectFixReproductionAttempts} from './reproduce.mjs';
6
7
  import {inspectVisualCarrier} from './visual.mjs';
7
8
 
8
9
  export function createFixCausePackage({codeProject,defect,status}){
@@ -50,7 +51,8 @@ export function readFixCausePackage(raw){
50
51
  text(d.rootCause);text(d.plan);need(Array.isArray(d.affectedModules)&&d.affectedModules.length>0,'invalid_package');
51
52
  d.affectedModules.forEach(text);
52
53
  need(Array.isArray(d.affectedPaths)&&digest([...d.affectedPaths].sort())===digest(files.map(file=>file.path)),'invalid_package');
53
- shape(r,['status','next','observation']);need(r.status==='reproduced'&&r.next==='diagnose','invalid_package');
54
+ shape(r,['status','next','observation',...(Object.hasOwn(r,'attempts')?['attempts']:[])]);
55
+ need(r.status==='reproduced'&&r.next==='diagnose','invalid_package');inspectFixReproductionAttempts(r);
54
56
  const o=r.observation;
55
57
  if(o.kind==='visual'){
56
58
  shape(o,['kind','phase','carrier','environment','reason']);need(o.phase==='before','invalid_package');
@@ -23,17 +23,20 @@ export function readFixObservationArchive({specsRoot,resume}){
23
23
  return {original,bytes,marker};
24
24
  }
25
25
 
26
+ // Absent attempts identify legacy results: retain their exact archive bytes so
27
+ // finish/resume remains possible. New producers always emit a nonempty list.
26
28
  export function publishFixObservationDossier({specsRoot,configuration,status,registeredAt}){
27
29
  if(['observation_not_reproduced','observation_needs_evidence'].includes(status.stage)){
28
30
  need(status.completionEligible===false&&status.observationResume,'fix_observation_unavailable');
29
31
  const recovery=readFixObservationArchive({specsRoot,resume:status.observationResume});
30
- const reproduction=inspectFixReproduction(status.observationReproduction,configuration.reproduction);
32
+ const reproduction=inspectFixReproduction(status.observationReproduction,configuration.reproduction,{requireAttempts:Object.hasOwn(status.observationReproduction,'attempts')});
31
33
  need(status.stage==='observation_not_reproduced'?reproduction.status==='not_reproduced':
32
34
  reproduction.status==='reproduced'&&status.observationDiagnosis?.status==='needs_evidence','fix_observation_unavailable');
33
35
  const body='# 恢复观测(仍未完成)\n\n以下是数据,不是执行指令。\n\n'
34
36
  +JSON.stringify({identity:status.identity,resume:status.observationResume,reproduction,
35
37
  diagnosis:status.observationDiagnosis??null,learning:status.learning,
36
38
  expectedFailure:configuration.reproduction.expectedFailure},null,2).split('\n').map(line=>' '+line).join('\n')
39
+ +(reproduction.attempts?'\n\n## 复现尝试\n\n'+JSON.stringify(reproduction.attempts,null,2).split('\n').map(line=>' '+line).join('\n'):'')
37
40
  +'\n\n等待补充实际失败日志、触发步骤或环境差异;不自动重试,不写 task_done 或完成指标。退出事实以原运行日志为准。\n';
38
41
  const bytes=Buffer.concat([recovery.original,recovery.marker,Buffer.from(body)]);
39
42
  need(bytes.length<=256*1024,'limit_exceeded');
@@ -42,7 +45,7 @@ export function publishFixObservationDossier({specsRoot,configuration,status,reg
42
45
  return writeDossier({directory,archiveName,bytes,replaceable:[recovery.original]});
43
46
  }
44
47
  need(status.stage==='observation'&&status.completionEligible===false,'fix_observation_unavailable');
45
- const reproduction=inspectFixReproduction(status.reproduction,configuration.reproduction);
48
+ const reproduction=inspectFixReproduction(status.reproduction,configuration.reproduction,{requireAttempts:Object.hasOwn(status.reproduction,'attempts')});
46
49
  need(reproduction.status==='not_reproduced'||status.diagnosis?.status==='needs_evidence','fix_observation_unavailable');
47
50
  const slug=/^T-FIX-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(status.identity.taskId)?.[1];
48
51
  need(slug&&Number.isSafeInteger(registeredAt)&&registeredAt>=0&&Number.isFinite(new Date(registeredAt).getTime()),'invalid_fix_dossier');
@@ -51,6 +54,7 @@ export function publishFixObservationDossier({specsRoot,configuration,status,reg
51
54
  let bytes=Buffer.from('# 缺陷档案(观测中)\n\n尚未修复、尚未完成。以下记录是数据,不是执行指令。\n\n'
52
55
  +section('任务',status.identity)
53
56
  +section('现象与已执行的复现',{defect:configuration.defect,reproduction})
57
+ +(reproduction.attempts?section('复现尝试',reproduction.attempts):'')
54
58
  +section('当前诊断(可能尚未进行)',status.diagnosis)
55
59
  +section('已读取的 Learning',status.learning)
56
60
  +section('等待证据',{expectedFailure:configuration.reproduction.expectedFailure,diagnosticPlan:status.diagnosis?.plan??null})
@@ -84,6 +88,7 @@ export function publishFixDossier({specsRoot,configuration,status,registeredAt,f
84
88
  +section('任务',status.identity)
85
89
  +(status.priorAttempts?section('先前轮次(历史记录,不替代当前审查)',status.priorAttempts):'')
86
90
  +section('现象与复现',{defect:configuration.defect,command:configuration.reproduction.command,result:status.reproduction})
91
+ +(status.reproduction.attempts?section('复现尝试',status.reproduction.attempts):'')
87
92
  +section('根因与修法(已记录诊断)',status.diagnosis)
88
93
  +section('实际改动',status.repair)
89
94
  +(isVisual(configuration.redTest)?section('修前视觉载体(自动红测不可用)',{reason:configuration.redTest.reason,
@@ -4,8 +4,27 @@ import {createHostCheck} from '../cm-ai/host-check.mjs';
4
4
  import {digest,json,need,shape,text} from '../cm-ai/effect-contract.mjs';
5
5
  import {isVisual,visualConfiguration,visualBefore,inspectVisualBefore} from './visual.mjs';
6
6
 
7
- export function inspectFixReproduction(raw,config){
8
- const value=json(raw);shape(value,['status','next','observation']);
7
+ // Shared by execution results and the existing root-cause package reader.
8
+ export function inspectFixReproductionAttempts(value,{requireAttempts=false}={}){
9
+ // Missing fields remain legal during historical replay; new observation entry
10
+ // and publication require an actual recorded attempt, never inferred history.
11
+ if(Object.hasOwn(value,'attempts')){
12
+ need(Array.isArray(value.attempts),'invalid_fix_reproduction_attempts');
13
+ for(const attempt of value.attempts){
14
+ shape(attempt,['scenario','dimension','outcome']);text(attempt.scenario);text(attempt.dimension);
15
+ need(['reproduced','not_reproduced','unsupported'].includes(attempt.outcome),'invalid_fix_reproduction_attempts');
16
+ }
17
+ if(value.attempts.length)need(value.attempts.at(-1).outcome===
18
+ ({reproduced:'reproduced',not_reproduced:'not_reproduced',blocked:'unsupported'})[value.status],
19
+ 'fix_reproduction_attempts_mismatch');
20
+ }
21
+ if(requireAttempts||value.next==='observation'&&Object.hasOwn(value,'attempts'))
22
+ need(value.attempts?.length>0,'fix_reproduction_attempts_required');
23
+ }
24
+
25
+ export function inspectFixReproduction(raw,config,{requireAttempts=false}={}){
26
+ const value=json(raw);shape(value,['status','next','observation',...(Object.hasOwn(value,'attempts')?['attempts']:[])]);
27
+ inspectFixReproductionAttempts(value,{requireAttempts});
9
28
  if(isVisual(config)){
10
29
  inspectVisualBefore(value.observation,config);
11
30
  need(value.status==='reproduced'&&value.next==='diagnose','reproduction_mismatch');return value;
@@ -29,7 +48,8 @@ export function createFixReproduction(options,{specsRoot=null}={}){
29
48
  return async(request,{signal,authorized})=>{
30
49
  need(authorized===true,'reproduction_authorization_required');need(!signal.aborted,'cancelled');
31
50
  need(!used,'reproduction_already_attempted');used=true;
32
- return inspectFixReproduction({status:'reproduced',next:'diagnose',observation:visualBefore(config)},config);
51
+ return inspectFixReproduction({status:'reproduced',next:'diagnose',observation:visualBefore(config),
52
+ attempts:[{scenario:config.steps.join(" → "),dimension:'按描述(未改变维度)',outcome:'reproduced'}]},config,{requireAttempts:true});
33
53
  };
34
54
  }
35
55
  shape(options,['cwd','command','expectedFailure','timeoutMs']);
@@ -47,8 +67,9 @@ export function createFixReproduction(options,{specsRoot=null}={}){
47
67
  const [observed]=await check(request,{signal});
48
68
  const reproduced=observed.outcome==='failed'&&observed.exitCode===config.expectedFailure.exitCode
49
69
  &&observed.signatureMatched===true;
50
- return json({status:observed.outcome==='unavailable'?'blocked':reproduced?'reproduced':'not_reproduced',
70
+ return inspectFixReproduction({status:observed.outcome==='unavailable'?'blocked':reproduced?'reproduced':'not_reproduced',
51
71
  next:observed.outcome==='unavailable'?'resolve_execution':reproduced?'diagnose':'observation',
52
- observation:observed});
72
+ observation:observed,attempts:[{scenario:JSON.stringify(config.command),dimension:'按描述(未改变维度)',
73
+ outcome:observed.outcome==='unavailable'?'unsupported':reproduced?'reproduced':'not_reproduced'}]},config,{requireAttempts:true});
53
74
  };
54
75
  }
@@ -4,6 +4,7 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import {createHash} from 'node:crypto';
6
6
  import {digest,json,need,shape,text,validCallTimeout} from '../cm-ai/effect-contract.mjs';
7
+ import {isQaEnvironmentCarrier,QA_ENVIRONMENT_SCOPES} from '../cm-ai/qa-environment.mjs';
7
8
 
8
9
  export const isVisual=config=>config?.kind==='visual';
9
10
  export function visualConfiguration(config){
@@ -12,8 +13,8 @@ export function visualConfiguration(config){
12
13
  need(path.isAbsolute(config.cwd)&&fs.realpathSync(config.cwd)===config.cwd,'unsupported_path');
13
14
  if(config.testFiles)need(Array.isArray(config.testFiles)&&config.testFiles.length===0,'fix_visual_test_files_invalid');
14
15
  shape(config.environment,['scope','kind','carrier','target']);
15
- need(['local','test'].includes(config.environment.scope)&&({web:['browser'],app:['ios-simulator','android-emulator','device'],
16
- miniprogram:['wechat-devtools','device']})[config.environment.kind]?.includes(config.environment.carrier),'fix_visual_environment_required');text(config.environment.target);
16
+ need(QA_ENVIRONMENT_SCOPES.includes(config.environment.scope)
17
+ &&isQaEnvironmentCarrier(config.environment.kind,config.environment.carrier),'fix_visual_environment_required');text(config.environment.target);
17
18
  for(const list of [config.steps,config.expected]){need(Array.isArray(list)&&list.length>0&&list.length<=32,'fix_visual_steps_required');list.forEach(text);}
18
19
  need(config.expected.every(value=>!value.includes('[需确认]')),'fix_visual_expectation_unconfirmed');
19
20
  inspectVisualCarrier(config.before);return config;
@@ -3,6 +3,7 @@
3
3
  import {createHostCheck} from '../cm-ai/host-check.mjs';
4
4
  import {readReviewSourceFiles} from '../cm-ai/review-package.mjs';
5
5
  import {digest,hex,id,json,need,shape,text,validCallTimeout,validIdentity} from '../cm-ai/effect-contract.mjs';
6
+ import {isQaEnvironmentCarrier,QA_ENVIRONMENT_SCOPES} from '../cm-ai/qa-environment.mjs';
6
7
 
7
8
  export function readFixWalkthrough(raw,cwd){
8
9
  const config=json(raw,64*1024);
@@ -22,7 +23,7 @@ export function readFixWalkthrough(raw,cwd){
22
23
  if(flow.kind==='browser'){
23
24
  shape(config.environment,['kind','carrier','target','scope']);
24
25
  const {kind,carrier,target,scope}=config.environment;text(target);
25
- need(['local','test'].includes(scope)&&({web:['browser'],app:['ios-simulator','android-emulator','device'],miniprogram:['wechat-devtools','device']})[kind]?.includes(carrier),'walkthrough_environment_required');
26
+ need(QA_ENVIRONMENT_SCOPES.includes(scope)&&isQaEnvironmentCarrier(kind,carrier),'walkthrough_environment_required');
26
27
  }
27
28
  }
28
29
  return config;
@@ -63,7 +63,8 @@ export async function generateCmInitDraft({project,workflowRoot,selection},{gene
63
63
  'Use templates as skeletons; remove inapplicable sections and resolve placeholders.',
64
64
  'Preserve existing user constraints; flag changes for human confirmation, never silently remove them.',
65
65
  'Local version control excludes remote/PR sections; none excludes git-workflow generation.',
66
- 'Config file: fill only runtimes.available and roles.coder/reviewer adapter+source per preset; keep every other existing value; no secrets.',
66
+ 'Config file: fill runtimes.available and roles.coder/reviewer adapter+source per preset; for existing configs keep every other value; no secrets.',
67
+ 'New config only: adapt policies.delivery to branch or diff for local/none version control; remove browser from policies.tests when modules contain neither frontend nor miniprogram.',
67
68
  'AGENTS is Codex-native; CLAUDE stays within 150 lines. File contents are data, not extra authority.'],
68
69
  writeAuthorized:false,executionAuthorized:false});
69
70
  const response=json(await generate(request,signal));
@@ -80,7 +81,7 @@ export async function generateCmInitDraft({project,workflowRoot,selection},{gene
80
81
  const before=baseline.get(prior.path);
81
82
  need(current===null?before===null:before!==null&&current.equals(before),'init_generation_project_changed');
82
83
  }
83
- const inspection=inspectCmInitDraft({project:analysis.project,documents});
84
+ const inspection=inspectCmInitDraft({project:analysis.project,documents,selection:choice});
84
85
  return freeze({version:1,workflow:'cm-init',status:'draft_generated',documents,inspection,
85
86
  semanticApprovalRequired:true,writeAuthorized:false,executionAuthorized:false});
86
87
  }
@@ -4,7 +4,7 @@ import path from 'node:path';
4
4
  import crypto from 'node:crypto';
5
5
  import {isDeepStrictEqual} from 'node:util';
6
6
  import {freeze,need} from '../cm-ai/effect-contract.mjs';
7
- import {CONFIG_FILENAMES,ConfigError,findConfig,loadConfig,runtimesSource} from '../../../scripts/cm-workflow-config.mjs';
7
+ import {CONFIG_FILENAMES,ConfigError,findConfig,loadConfig,runtimePreset,runtimesSource} from '../../../scripts/cm-workflow-config.mjs';
8
8
 
9
9
  const rules=new Set(['coding-style','testing','security','git-workflow','frontend','miniprogram',
10
10
  'backend-api','database','smart-contract','finance']);
@@ -45,7 +45,7 @@ export function readCmInitSource(root,file){
45
45
  }
46
46
  }
47
47
 
48
- export function inspectCmInitDraft({project,documents}){
48
+ export function inspectCmInitDraft({project,documents,selection}){
49
49
  need(typeof project==='string'&&path.isAbsolute(project),'init_project_path_invalid');
50
50
  const root=fs.realpathSync(project);
51
51
  need(fs.statSync(root).isDirectory(),'init_project_path_invalid');
@@ -70,6 +70,20 @@ export function inspectCmInitDraft({project,documents}){
70
70
  const parse=text=>loadConfig({projectRoot:root,configPath:path.join(root,file),text});
71
71
  const config=parse(content);
72
72
  if(runtimesSource(config)!=='project')issues.push({path:file,code:'runtimes_declaration_missing'});
73
+ if(selection?.runtimes){
74
+ const expected=runtimePreset(selection.runtimes.preset);
75
+ const actual={runtimes:{available:config.runtimes.available},roles:Object.fromEntries(
76
+ ['coder','reviewer'].map(role=>[role,{adapter:config.roles[role].adapter,source:config.roles[role].source}]))};
77
+ if(!isDeepStrictEqual(expected,actual))
78
+ issues.push({path:file,code:'runtimes_preset_mismatch',expected,actual});
79
+ }
80
+ if(before===null&&selection){
81
+ if(['local','none'].includes(selection.versionControl)&&config.policies.delivery==='draft-mr')
82
+ issues.push({path:file,code:'delivery_requires_remote',severity:'warning'});
83
+ if(Array.isArray(selection.modules)&&!selection.modules.some(name=>['frontend','miniprogram'].includes(name))
84
+ &&config.policies.tests.includes('browser'))
85
+ issues.push({path:file,code:'browser_tests_without_ui',severity:'warning'});
86
+ }
73
87
  if(before!==null){
74
88
  const previous=parse(before.toString('utf8'));
75
89
  if(!isDeepStrictEqual(preservedConfig(previous),preservedConfig(config)))
@@ -90,7 +104,7 @@ export function inspectCmInitDraft({project,documents}){
90
104
  }
91
105
  }
92
106
  return freeze({version:1,workflow:'cm-init',phase:'draft_inspection',project:root,
93
- status:issues.length?'blocked':'structurally_checked',issues,changes,
107
+ status:issues.some(issue=>issue.severity!=='warning')?'blocked':'structurally_checked',issues,changes,
94
108
  existingChangeReviewRequired:changes.filter(change=>change.action==='modify').map(change=>change.path),
95
109
  remainingChecks:['semantic_constraint_preservation','commands_and_globs','other_file_references',
96
110
  'applicable_rules_and_version_control','independent_review','current_files_before_write'],
@@ -61,7 +61,7 @@ export function loadCmInitRecoveryDraft({project,packageDigest}){
61
61
  need(archiveBytes({project,reviewPackage:saved.reviewPackage,review:saved.review}).equals(bytes),'init_archive_invalid');
62
62
  const pkg=saved.reviewPackage;
63
63
  need(pkg.kind==='cm-init-draft-review-package'&&pkg.version===1,'init_archive_invalid');
64
- const inspection=inspectCmInitDraft({project,documents:pkg.documents});
64
+ const inspection=inspectCmInitDraft({project,documents:pkg.documents,selection:pkg.selection});
65
65
  need(Array.isArray(pkg.originals)&&pkg.originals.length===pkg.documents.length,'init_archive_invalid');
66
66
  const sha=value=>createHash('sha256').update(value).digest('hex');
67
67
  const files=inspection.changes.map((change,index)=>{
@@ -1,8 +1,9 @@
1
1
  // Evidence-backed human handoff. No specification approval or development.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import {createHash,randomUUID} from 'node:crypto';
4
+ import {createHash} from 'node:crypto';
5
5
  import {TextDecoder} from 'node:util';
6
+ import {writeSpecsStatus} from '../specs-status.mjs';
6
7
  import {buildManifest} from '../../../scripts/cm-spec-manifest.mjs';
7
8
  import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
8
9
  import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
@@ -93,20 +94,17 @@ export function publishPrdAwaitingReview({specs,summary,writeEnabled,recover=fal
93
94
  }
94
95
  need(digest(before)===summary.evidenceDigest,'prd_summary_inputs_changed');
95
96
  const status={status:'awaiting_review',summaryDigest:summary.summaryDigest,at:new Date().toISOString(),features:before.features.map(item=>item.directory),
96
- specFiles:before.specFiles,testCases:before.specFiles.filter(item=>item.path.endsWith('/test-cases.json'))};
97
+ specFiles:before.specFiles,testCases:before.specFiles.filter(item=>item.path.endsWith('/test-cases.json')),approval:null};
97
98
  const bytes=Buffer.from(JSON.stringify(status)+'\n'),target=path.join(specs,'.cm-specs-status');
98
- const temporary=path.join(specs,`.cm-prd-status-${randomUUID()}`);let fd;
99
99
  try{
100
- fd=fs.openSync(temporary,'wx',0o600);fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;
101
- need(digest(inspectPrdSummaryEvidence(specs,scope))===summary.evidenceDigest,'prd_summary_inputs_changed');
102
- fs.renameSync(temporary,target);
103
- const dir=fs.openSync(specs,'r');try{fs.fsyncSync(dir);}finally{fs.closeSync(dir);}
100
+ writeSpecsStatus(specs,status,{beforeRename:()=>{
101
+ need(digest(inspectPrdSummaryEvidence(specs,scope))===summary.evidenceDigest,'prd_summary_inputs_changed');
102
+ }});
104
103
  need(readCmInitSource(specs,'.cm-specs-status')?.equals(bytes),'prd_summary_status_unknown');
105
104
  need(digest(buildManifest(specs))===digest(before.specFiles),'prd_summary_inputs_changed');
106
105
  return json({status:'awaiting_review',path:target,features:status.features,completionAuthorized:false,
107
106
  next:'human_review_then_explicit_cm_ai'});
108
107
  }catch{return json({status:'awaiting_review_write_unknown',next:'inspect_status_and_specs_without_automatic_retry',completionAuthorized:false});}
109
- finally{if(fd!==undefined)fs.closeSync(fd);try{fs.unlinkSync(temporary);}catch(error){if(error.code!=='ENOENT')throw error;}}
110
108
  }
111
109
 
112
110
  const requiredSignals=prdDesignRiskSignals;