@aibyzero/cm-workflow 0.21.6 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +58 -0
  3. package/README.md +18 -3
  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 +42 -16
  12. package/docs/js-workflow-control.md +65 -30
  13. package/docs/next-steps.md +10 -0
  14. package/docs/runtime-failover.md +5 -3
  15. package/docs/user-guide.md +6 -6
  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/checkpoint-package-material.mjs +9 -2
  20. package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
  21. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
  22. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
  23. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
  24. package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
  25. package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
  26. package/runtime/js/cm-ai/drive-core.mjs +50 -6
  27. package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
  28. package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
  29. package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
  30. package/runtime/js/cm-ai/execution-store.mjs +21 -3
  31. package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
  32. package/runtime/js/cm-ai/host-check.mjs +4 -2
  33. package/runtime/js/cm-ai/host-conversation-execution.mjs +23 -2
  34. package/runtime/js/cm-ai/host-handoff.mjs +7 -0
  35. package/runtime/js/cm-ai/host-progress.mjs +18 -0
  36. package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
  37. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  38. package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
  39. package/runtime/js/cm-ai/host-session.mjs +1 -1
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
  41. package/runtime/js/cm-ai/host.mjs +1 -1
  42. package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
  43. package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
  44. package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
  45. package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
  46. package/runtime/js/cm-ai/review-continuation.mjs +102 -0
  47. package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
  48. package/runtime/js/cm-ai/review-package.mjs +25 -4
  49. package/runtime/js/cm-ai/review-presentation.mjs +31 -14
  50. package/runtime/js/cm-ai/review-runner.mjs +5 -4
  51. package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
  52. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
  53. package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
  54. package/runtime/js/cm-ai/task-commit.mjs +7 -4
  55. package/runtime/js/cm-ai/task-owner.mjs +5 -2
  56. package/runtime/js/cm-ai/task-runner.mjs +343 -52
  57. package/runtime/js/cm-ai/tool-preview.mjs +6 -0
  58. package/runtime/js/cm-fix/diagnosis.mjs +16 -3
  59. package/runtime/js/cm-fix/execution.mjs +47 -9
  60. package/runtime/js/cm-fix/finish.mjs +9 -1
  61. package/runtime/js/cm-fix/step-timing.mjs +222 -0
  62. package/runtime/js/cm-idea/session.mjs +22 -3
  63. package/runtime/js/cm-init/review-evidence.mjs +20 -7
  64. package/runtime/js/cm-prd/ai-draft.mjs +260 -0
  65. package/runtime/js/cm-prd/analysis.mjs +27 -9
  66. package/runtime/js/cm-prd/change.mjs +29 -8
  67. package/runtime/js/cm-prd/failed-correction.mjs +24 -4
  68. package/runtime/js/cm-prd/narrow-review.mjs +63 -3
  69. package/runtime/js/cm-prd/review-correction.mjs +65 -5
  70. package/runtime/js/cm-prd/review-disposition.mjs +10 -1
  71. package/runtime/js/cm-prd/self-check.mjs +121 -9
  72. package/runtime/js/cm-prd/session.mjs +55 -13
  73. package/runtime/js/cm-prd/summary.mjs +34 -6
  74. package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
  75. package/runtime/js/cm-refactor/records.mjs +82 -11
  76. package/runtime/js/cm-refactor/workflow.mjs +3 -1
  77. package/runtime/js/executor-version.mjs +81 -0
  78. package/runtime/js/python-log-writer.mjs +15 -0
  79. package/runtime/js/run-analysis.mjs +136 -11
  80. package/runtime/logging.md +6 -0
  81. package/runtime/review.md +3 -1
  82. package/runtime/workflow-config.md +1 -1
  83. package/scripts/ci-test-weights.json +1 -0
  84. package/scripts/cm-ai-admission.mjs +27 -1
  85. package/scripts/cm-ai-admission.test.mjs +34 -2
  86. package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
  87. package/scripts/cm-ai-batch-drive.mjs +54 -17
  88. package/scripts/cm-ai-batch-drive.test.mjs +123 -6
  89. package/scripts/cm-ai-batch-host.mjs +55 -9
  90. package/scripts/cm-ai-batch-host.test.mjs +22 -3
  91. package/scripts/cm-ai-batch-location.test.mjs +22 -1
  92. package/scripts/cm-ai-batch-merge.mjs +102 -0
  93. package/scripts/cm-ai-batch-plan.mjs +55 -2
  94. package/scripts/cm-ai-batch-plan.test.mjs +228 -6
  95. package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
  96. package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
  97. package/scripts/cm-ai-batch-run.mjs +435 -33
  98. package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
  99. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
  100. package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
  101. package/scripts/cm-ai-completion-summary.test.mjs +2 -1
  102. package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
  103. package/scripts/cm-ai-direct-review.test.mjs +1 -1
  104. package/scripts/cm-ai-disk-edits.test.mjs +229 -0
  105. package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
  106. package/scripts/cm-ai-drive.mjs +66 -14
  107. package/scripts/cm-ai-drive.test.mjs +13 -3
  108. package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
  109. package/scripts/cm-ai-host.mjs +16 -8
  110. package/scripts/cm-ai-host.test.mjs +12 -0
  111. package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
  112. package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
  113. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
  114. package/scripts/cm-ai-review-continuation.test.mjs +335 -0
  115. package/scripts/cm-ai-review-failure.test.mjs +13 -10
  116. package/scripts/cm-ai-review-timeout.test.mjs +1 -1
  117. package/scripts/cm-ai-run.mjs +42 -11
  118. package/scripts/cm-ai-run.test.mjs +26 -0
  119. package/scripts/cm-ai-supersede.test.mjs +10 -2
  120. package/scripts/cm-capability-gate.test.mjs +1 -1
  121. package/scripts/cm-check-runtime.sh +9 -0
  122. package/scripts/cm-codex-clean-env.test.mjs +40 -0
  123. package/scripts/cm-codex-prompt-input.test.mjs +2 -1
  124. package/scripts/cm-developer-self-review.test.mjs +27 -0
  125. package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
  126. package/scripts/cm-efficiency-response.test.mjs +2 -1
  127. package/scripts/cm-executor-version-draft.test.mjs +251 -0
  128. package/scripts/cm-executor-version-entries.test.mjs +93 -0
  129. package/scripts/cm-executor-version-prd.test.mjs +154 -0
  130. package/scripts/cm-executor-version-records.test.mjs +256 -0
  131. package/scripts/cm-executor-version.test.mjs +250 -0
  132. package/scripts/cm-external-model-host.test.mjs +6 -1
  133. package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
  134. package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
  135. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
  136. package/scripts/cm-fix-drive.mjs +7 -2
  137. package/scripts/cm-fix-drive.test.mjs +45 -0
  138. package/scripts/cm-fix-entry.mjs +5 -2
  139. package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
  140. package/scripts/cm-fix-host.mjs +9 -2
  141. package/scripts/cm-fix-test-extension.test.mjs +30 -2
  142. package/scripts/cm-host-check.test.mjs +12 -0
  143. package/scripts/cm-host-qa-executor.test.mjs +172 -1
  144. package/scripts/cm-host-qa-policy.test.mjs +55 -1
  145. package/scripts/cm-idea-drive.mjs +5 -2
  146. package/scripts/cm-idea-entry.mjs +5 -2
  147. package/scripts/cm-idea-host.mjs +3 -1
  148. package/scripts/cm-init-drive.mjs +8 -5
  149. package/scripts/cm-init-entry.mjs +5 -2
  150. package/scripts/cm-init-host.mjs +6 -2
  151. package/scripts/cm-log-event.mjs +10 -2
  152. package/scripts/cm-log-event.test.mjs +29 -0
  153. package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
  154. package/scripts/cm-prd-ai-draft.test.mjs +505 -0
  155. package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
  156. package/scripts/cm-prd-completion.test.mjs +67 -4
  157. package/scripts/cm-prd-design-phase.test.mjs +48 -13
  158. package/scripts/cm-prd-drive.mjs +89 -20
  159. package/scripts/cm-prd-drive.test.mjs +109 -4
  160. package/scripts/cm-prd-entry.mjs +5 -2
  161. package/scripts/cm-prd-host.mjs +89 -20
  162. package/scripts/cm-prd-host.test.mjs +17 -8
  163. package/scripts/cm-prd-narrow-review.test.mjs +49 -1
  164. package/scripts/cm-prd-review-disposition.test.mjs +94 -1
  165. package/scripts/cm-prd-review-gate.mjs +11 -4
  166. package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
  167. package/scripts/cm-prd-self-check.test.mjs +1 -1
  168. package/scripts/cm-refactor-drive.mjs +10 -4
  169. package/scripts/cm-refactor-entry.mjs +5 -2
  170. package/scripts/cm-refactor-host.mjs +3 -1
  171. package/scripts/cm-run-analysis.test.mjs +373 -1
  172. package/scripts/cm-runtime-i18n.mjs +3 -3
  173. package/scripts/cm-runtime-install.mjs +19 -10
  174. package/scripts/cm-runtime.mjs +2 -4
  175. package/scripts/cm-runtime.test.mjs +55 -13
  176. package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
  177. package/scripts/cm-skill-hints-exam.mjs +3 -1
  178. package/scripts/cm-skill-hints-install.test.mjs +1 -1
  179. package/scripts/cm-skill-hints.mjs +106 -10
  180. package/scripts/cm-skill-hints.test.mjs +162 -6
  181. package/scripts/cm-skill-judge.mjs +2 -1
  182. package/scripts/cm-statusline.test.mjs +54 -0
  183. package/scripts/cm-task-gate.mjs +88 -18
  184. package/scripts/cm-task-scope.test.mjs +1 -1
  185. package/scripts/cm-test-drive.mjs +13 -8
  186. package/scripts/cm-test-entry.mjs +5 -2
  187. package/scripts/cm-test-host.mjs +3 -1
  188. package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
  189. package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
  190. package/scripts/fixtures/prd-review-gate-python-oracle.py +9 -0
  191. package/scripts/policy-binding-compat.test.mjs +3 -2
  192. package/scripts/test-cm-prd-review-gate.py +25 -0
  193. package/skills/cm-ai/SKILL.md +1 -1
  194. package/skills/cm-ai/references/N1-init.md +4 -3
  195. package/skills/cm-ai/references/N4-review.md +6 -3
  196. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  197. package/skills/cm-ai/references/js-host-recovery.md +4 -1
  198. package/skills/cm-ai/references/js-host.md +25 -5
  199. package/skills/cm-fix/references/js-host.md +20 -0
  200. package/skills/cm-fix/references/test-extension.md +1 -1
  201. package/skills/cm-prd/SKILL.md +8 -6
  202. package/skills/cm-prd/references/ai-draft.md +81 -0
  203. package/skills/cm-prd/references/change-mode.md +2 -0
  204. package/skills/cm-prd/references/greenfield.md +2 -0
  205. package/skills/cm-prd/references/js-change-recovery.md +2 -2
  206. package/skills/cm-prd/references/js-host.md +9 -6
  207. package/skills/cm-prd/references/light-mode.md +19 -0
  208. package/skills/cm-prd/references/requirement-grilling.md +2 -0
  209. package/skills/cm-prd/references/spec-self-check.md +1 -0
  210. package/skills/cm-prd/references/summary-card.md +1 -0
  211. package/skills/cm-runtime/SKILL.md +6 -6
  212. package/templates/statusline/cm-statusline.sh +63 -1
@@ -24,6 +24,7 @@ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
24
24
  import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
25
25
  import {rateLimitRetryEligible} from '../runtime/js/cm-ai/drive-rate-limit.mjs';
26
26
  import {guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
27
+ import {withFreshCompletionChecks} from './fixtures/fresh-completion-checks.mjs';
27
28
  // An exported CM_NOTIFY_OFF silences every notice; these fixtures expect notices on
28
29
  // (review 2026-11-17). Tests of the switch itself set it explicitly.
29
30
  delete process.env.CM_NOTIFY_OFF;
@@ -591,13 +592,15 @@ async function runnerFixture(t,fn,{timeoutMs=1000,reviewTimeoutMs,reviewerProvid
591
592
  taskCompletion:{reviewsDir,handoffs:[path.join(reviewsDir,'a1.json'),path.join(reviewsDir,'a2.json')]},
592
593
  reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main'],
593
594
  ...(reviewTimeoutMs===undefined?{}:{timeoutMs:reviewTimeoutMs})}};
594
- const make=(mode,extra={})=>createTaskRunner({...options,reviewInvocation:{...options.reviewInvocation,...extra},persistence:{store,mode,version:3}});
595
+ // Mirrors the run entry's creation escape hatch (withFreshCompletionChecks).
596
+ const make=(mode,extra={})=>createTaskRunner({...options,reviewInvocation:{...options.reviewInvocation,...extra},persistence:{store,mode,version:3},
597
+ ...(process.env.CM_AI_COMPLETION_CHECK_REUSE==='off'?{completionCheckReuse:false}:{})});
595
598
  const reopen=(extra={})=>{store.close();store=openTaskExecutionStore({...owner,create:false});return make('resume',extra);};
596
599
  // Simulate a host that died right after the last record of this type.
597
600
  const resumePrefix=type=>{
598
601
  const current=store.snapshot(),at=current.records.findLastIndex(record=>record.payload.type===type);assert(at>=0);store.close();
599
602
  const statePath=path.join(specsRoot,'.reviews','.execution',runIdentity.runId,'state.json');
600
- const body={version:current.version,identity:current.identity,fingerprints:current.fingerprints,records:current.records.slice(0,at+1)};
603
+ const body={version:current.version,identity:current.identity,fingerprints:current.fingerprints,...(Object.hasOwn(current,"createdBy")?{createdBy:current.createdBy}:{}),records:current.records.slice(0,at+1)};
601
604
  fs.writeFileSync(statePath,JSON.stringify({...body,revision:digest(body)})+'\n',{mode:0o600});
602
605
  store=openTaskExecutionStore({...owner,create:false});return make('resume');
603
606
  };
@@ -1087,7 +1090,7 @@ function completionFixture(t){
1087
1090
  ...(packageDigest?{packageDigest}:{})}),operation);
1088
1091
  return {...f,pass,run};
1089
1092
  }
1090
- test('repeated completion re-check blocks stop at completion_retry_limit instead of an uncompletable approval (real host)',t=>{
1093
+ test('repeated completion re-check blocks stop at completion_retry_limit instead of an uncompletable approval (real host)',t=>withFreshCompletionChecks(()=>(t=>{
1091
1094
  const f=completionFixture(t);f.pass(true);
1092
1095
  const delivered=f.run('start',{mode:'create'});
1093
1096
  assert.equal(delivered.status,0,delivered.stderr);assert.equal(delivered.result.state,'awaiting_review');
@@ -1116,9 +1119,9 @@ test('repeated completion re-check blocks stop at completion_retry_limit instead
1116
1119
  assert.deepEqual(f.intents(),intents);
1117
1120
  assert.match(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8'),/\[ \] T-001/);
1118
1121
  assert.equal(f.replay().state.code,'completion_retry_limit');
1119
- });
1122
+ })(t)));
1120
1123
 
1121
- test('completion re-checks no longer eat the six effects: develop blocks plus re-checks still complete (real host)',t=>{
1124
+ test('completion re-checks no longer eat the six effects: develop blocks plus re-checks still complete (real host)',t=>withFreshCompletionChecks(()=>(t=>{
1122
1125
  const f=completionFixture(t);f.pass(false);
1123
1126
  for(const mode of ['create','resume'])assert.equal(f.run('advance',{mode}).result.code,'develop_checks_not_passed');
1124
1127
  f.pass(true);
@@ -1132,9 +1135,9 @@ test('completion re-checks no longer eat the six effects: develop blocks plus re
1132
1135
  const completed=f.run('complete',{packageDigest});
1133
1136
  assert.equal(completed.status,0,completed.stderr);assert.equal(completed.result.state,'fixture_completed',JSON.stringify(completed.result));
1134
1137
  assert.match(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8'),/\[x\] T-001/);
1135
- });
1138
+ })(t)));
1136
1139
 
1137
- test('#retry-limit replay accepts the completion limit only once the re-check bound is spent',t=>{
1140
+ test('#retry-limit replay accepts the completion limit only once the re-check bound is spent',t=>withFreshCompletionChecks(()=>(t=>{
1138
1141
  const f=completionFixture(t);f.pass(true);
1139
1142
  const packageDigest=f.run('start',{mode:'create'}).result.packageDigest;
1140
1143
  f.run('decision',{review:true,packageDigest});f.pass(false);
@@ -1158,9 +1161,9 @@ test('#retry-limit replay accepts the completion limit only once the re-check bo
1158
1161
  const extended=[...structuredClone(records),intent].map((row,index)=>({...row,seq:index+1,
1159
1162
  id:`runner.${String(index+1).padStart(6,'0')}`}));
1160
1163
  assert.throws(()=>readRunnerHistory(rechain(extended),configuration,3),{code:'runner_stage'});
1161
- });
1164
+ })(t)));
1162
1165
 
1163
- test('#retry-limit an older journal past the completion re-check bound converts on the next complete request',t=>runnerFixture(t,async f=>{
1166
+ test('#retry-limit an older journal past the completion re-check bound converts on the next complete request',t=>withFreshCompletionChecks(()=>(t=>runnerFixture(t,async f=>{
1164
1167
  let failing=false;f.setChecks(()=>failing?[{...checksPassed[0],outcome:'failed',exitCode:1}]:checksPassed);
1165
1168
  let runner=f.make();
1166
1169
  await runner.executeEffect(f.effect('develop'));
@@ -1177,7 +1180,7 @@ test('#retry-limit an older journal past the completion re-check bound converts
1177
1180
  assert.equal(f.records().at(-1).payload.type,'completion-retry-limit');
1178
1181
  assert.equal(f.records().filter(row=>row.payload.type==='effect-intent').length,intents,'no intent');
1179
1182
  assert.deepEqual(f.reopen().status(),converted);
1180
- }));
1183
+ }))(t)));
1181
1184
 
1182
1185
  // Claude boundary exits (the T-009 incident shape): a user-role text the CLI did
1183
1186
  // not mark synthetic stops the reviewer with a summary and stays unknown; the
@@ -60,7 +60,7 @@ async function fixture(fn,{reviewRun,times,timeoutMs=1000,provider='codex'}={})
60
60
  const current=store.snapshot(),at=last?current.records.findLastIndex(record=>record.payload.type===type)
61
61
  :current.records.findIndex(record=>record.payload.type===type);assert(at>=0);store.close();
62
62
  const statePath=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json');
63
- const body={version:current.version,identity:current.identity,fingerprints:current.fingerprints,records:current.records.slice(0,at+1)};
63
+ const body={version:current.version,identity:current.identity,fingerprints:current.fingerprints,...(Object.hasOwn(current,"createdBy")?{createdBy:current.createdBy}:{}),records:current.records.slice(0,at+1)};
64
64
  fs.writeFileSync(statePath,JSON.stringify({...body,revision:digest(body)})+'\n',{mode:0o600});
65
65
  store=openTaskExecutionStore({...owner,create:false});return make('resume');
66
66
  };
@@ -28,6 +28,7 @@ import {RUN_ID_RULE,validRunId} from './cm-log-event.mjs';
28
28
  import {JOURNAL_PAYLOAD_LIMIT,boundedReason,shape,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
29
29
  import {protectedScopePaths} from '../runtime/js/cm-ai/developer-adapter.mjs';
30
30
  import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
31
+ import {EXECUTOR_REASON_CODES,assertResumable} from '../runtime/js/executor-version.mjs';
31
32
 
32
33
  const usage='cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json (validated read-only history; no owner lock or provider dispatch)\ncm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
33
34
  const fail=code=>{throw Object.assign(new Error(code),{code});};
@@ -226,12 +227,21 @@ export function assertCreatableRunId(identity){
226
227
  if(!validRunId(identity?.runId))fail(`invalid_config: identity.runId must be ${RUN_ID_RULE} (run log requirement)`);
227
228
  }
228
229
 
230
+ // The runner's qaCadence creation choice. An older empty store finished on resume keeps
231
+ // the historical count; a batch member takes its batch's (batch-run open), empty store or not.
232
+ export function runnerQaCadence({runnerMode,mode,batchQaCadence=null}){
233
+ if(![null,'legacy','feature-v1'].includes(batchQaCadence))fail('invalid_config: batchQaCadence');
234
+ if(runnerMode!=='create')return {};
235
+ return (batchQaCadence===null?mode!=='create':batchQaCadence==='legacy')?{qaCadence:false}:{};
236
+ }
237
+
229
238
  // Definition is data, never an import path, command, grant or executable callback.
230
239
  // legacyQa rebuilds the historical QA executor form for stores created before
231
240
  // the built-in plan left the fingerprint; it is never used to create a store.
232
- export function runConfigMaterial(definition,execution,{parallelSelection=null,bootstrapConfig=null,legacyQa=false,knowledgeCloseout=null}={}){
241
+ export function runConfigMaterial(definition,execution,{parallelSelection=null,bootstrapConfig=null,legacyQa=false,knowledgeCloseout=null,batchCompletion=null}={}){
233
242
  if(execution===null)return parallelSelection===null?definition:{definition,parallelSelection};
234
243
  return {definition,...(parallelSelection===null?{}:{parallelSelection}),execution:execution.configuration,
244
+ ...(batchCompletion===null?{}:{batchCompletion}),
235
245
  ...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
236
246
  ...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
237
247
  ...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
@@ -251,7 +261,9 @@ export function inspectRunHistory(definition){
251
261
  // histories this runtime cannot project report null rather than a guess.
252
262
  let supersedeTarget=null;
253
263
  try{supersedeTarget=controlLaunchTarget(snapshot);}catch{supersedeTarget=null;}
264
+ // createdBy null: the run predates recorded executor releases (created before 0.22.0).
254
265
  return {identity:snapshot.identity,revision:snapshot.revision,fingerprints:snapshot.fingerprints,supersedeTarget,
266
+ createdBy:snapshot.createdBy??null,
255
267
  records:snapshot.records.map(record=>({seq:record.seq,id:record.id,kind:record.kind,type:record.payload.type??null,
256
268
  legacyReviewGrant:record.payload.type==='review-invocation-registered'
257
269
  &&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))}))};
@@ -261,6 +273,8 @@ export function assertSupportedResumeHistory(definition){
261
273
  try{snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
262
274
  identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});}
263
275
  catch(error){if(error.code==='ENOENT')return null;throw error;}
276
+ // Refuse a run a newer executor created before anything else is opened or written.
277
+ if(snapshot.version===2)assertResumable(snapshot.createdBy);
264
278
  if(snapshot.records.some(record=>record.payload.type==='review-invocation-registered'
265
279
  &&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))))
266
280
  throw Object.assign(new Error('runner_invocation'),{code:'runner_invocation',
@@ -292,11 +306,16 @@ export async function openControlRun(definition,mode,execution=null,options={}){
292
306
  return {...result,close:()=>{try{close();}finally{guard?.close();}}};
293
307
  }catch(error){releaseHolds();guard?.close();throw error;}
294
308
  }
295
- async function openControlRunOwned(definition,mode,execution=null,{supersedeHolds=null,supersedeTarget=null,rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null,expectedControl=null,scopeRevision=null,developmentReworkReason=null,reviewedIntegration=null}={},acquireGuard=async()=>{}){
309
+ async function openControlRunOwned(definition,mode,execution=null,{supersedeHolds=null,supersedeTarget=null,rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,diskEdits=false,specRebindReason=null,expectedControl=null,scopeRevision=null,developmentReworkReason=null,reviewContinuationReason=null,reviewedIntegration=null,batchCompletion=null,batchQaCadence=null}={},acquireGuard=async()=>{}){
296
310
  // Check before importing node:sqlite: legacy Node users get a useful error.
297
311
  if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
312
+ if(batchCompletion!==null&&(execution===null||parallelSelection?.group?.length<2||!parallelSelection
313
+ ||typeof batchCompletion.verify!=='function'))fail('invalid_input');
314
+ const batchCompletionBinding=batchCompletion?.binding??null;
315
+ if(batchCompletion!==null&&batchCompletionBinding===null)fail('invalid_input');
298
316
  const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
299
317
  if(!['create','resume'].includes(mode))fail('invalid_mode');
318
+ runnerQaCadence({runnerMode:mode,mode,batchQaCadence});
300
319
  if(mode==='create')assertCreatableRunId(definition?.identity);
301
320
  // The developer adapter refuses these paths on every dispatch. Refuse the
302
321
  // run here, before any journal, intent or execution directory exists, so it
@@ -309,6 +328,8 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
309
328
  if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
310
329
  if(allowDevelopRedo&&mode!=='resume')fail('develop_redo_unavailable');
311
330
  if(typeof holdRevision!=='boolean')fail('invalid_input');
331
+ if(typeof diskEdits!=='boolean')fail('invalid_input');
332
+ if(diskEdits&&(mode!=='resume'||execution===null||protectedExecutions.has(execution)||execution.configuration.providerDevelopment||conversationProtection(execution)!==null))fail('invalid_arguments');
312
333
  if(specRebindReason!==null&&(mode!=='resume'||execution===null||typeof specRebindReason!=='string'||!specRebindReason.trim()
313
334
  ||Buffer.byteLength(specRebindReason,'utf8')>500||/[\r\n\0]/.test(specRebindReason)))fail('spec_rebind_unavailable');
314
335
  if(typeof acceptSupersededCodeDrift!=='boolean'||acceptSupersededCodeDrift&&supersedeReason===null)
@@ -320,13 +341,13 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
320
341
  ||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
321
342
  const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
322
343
  const controlPolicy=execution?.configuration?.controlPolicy??null;
323
- const elevatedRecovery=scopeRevision!==null||developmentReworkReason!==null;
344
+ const elevatedRecovery=scopeRevision!==null||developmentReworkReason!==null||reviewContinuationReason!==null;
324
345
  const launchRecovery=qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||specRebindReason!==null||elevatedRecovery||reviewedIntegration!==null;
325
346
  if(elevatedRecovery){
326
347
  if(!controlPolicy||mode!=='resume'||parallelSelection!==null||conversationProtection(execution)!==null
327
348
  ||protectedExecutions.has(execution)||execution.configuration.providerDevelopment)fail('recovery_launch_unavailable');
328
- if([scopeRevision!==null,developmentReworkReason!==null,qaConfigRevision!==null,rerunUnknownQa,rerunBlockedQa,specRebindReason!==null].filter(Boolean).length!==1)fail('invalid_input');
329
- const reason=scopeRevision?.reason??developmentReworkReason;
349
+ if([scopeRevision!==null,developmentReworkReason!==null,reviewContinuationReason!==null,qaConfigRevision!==null,rerunUnknownQa,rerunBlockedQa,specRebindReason!==null].filter(Boolean).length!==1)fail('invalid_input');
350
+ const reason=scopeRevision?.reason??developmentReworkReason??reviewContinuationReason;
330
351
  if(typeof reason!=='string'||!reason.trim()||Buffer.byteLength(reason,'utf8')>500||/[\r\n\0]/.test(reason))fail('invalid_input');
331
352
  }
332
353
  if(reviewedIntegration!==null){
@@ -370,7 +391,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
370
391
  if(execution!==null){
371
392
  const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
372
393
  shape(execution,['configuration','developer','reviewers','reviewInvocation','check','excludedContexts','timeoutMs',
373
- ...['bootstrap','developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync','verificationGate'].filter(key=>Object.hasOwn(execution,key))]);
394
+ ...['bootstrap','developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync','verificationGate','onChecksReused'].filter(key=>Object.hasOwn(execution,key))]);
374
395
  json(execution.configuration);validCallTimeout(execution.timeoutMs);
375
396
  if(Object.hasOwn(execution.configuration,'codeProject'))
376
397
  if(execution.configuration.codeProject!==definition.codeProject)fail('execution_root_mismatch');
@@ -509,7 +530,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
509
530
  ?readExecutionSnapshot({specsRoot:specsDir,identity:storeIdentity}):null;
510
531
  let opened,lastMismatch;
511
532
  for(const knowledgeCloseout of closeoutPolicyCandidates(execution,mode,snapshot)){
512
- const materialOptions={parallelSelection,bootstrapConfig,knowledgeCloseout};
533
+ const materialOptions={parallelSelection,bootstrapConfig,knowledgeCloseout,batchCompletion:batchCompletionBinding};
513
534
  try{opened=openFor(runConfigMaterial(definition,execution,materialOptions));break;}
514
535
  catch(error){
515
536
  if(mode!=='resume'||error.code!=='fingerprint_mismatch')throw error;
@@ -529,7 +550,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
529
550
  if(!opened&&mode==='resume'&&isImplicitQaDecision(execution?.qaDecisionProvider)){
530
551
  const {qaDecisionProvider,...original}=execution;
531
552
  for(const knowledgeCloseout of closeoutPolicyCandidates(original,mode,snapshot)){
532
- try{opened=openFor(runConfigMaterial(definition,original,{parallelSelection,bootstrapConfig,knowledgeCloseout}));implicitQaSuppressed=true;break;}
553
+ try{opened=openFor(runConfigMaterial(definition,original,{parallelSelection,bootstrapConfig,knowledgeCloseout,batchCompletion:batchCompletionBinding}));implicitQaSuppressed=true;break;}
533
554
  catch(error){if(error.code!=='fingerprint_mismatch')throw error;}
534
555
  }
535
556
  }
@@ -565,16 +586,25 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
565
586
  ...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
566
587
  ...(controlPolicy?{controlPolicy:savedPolicy??controlPolicy}:{}),
567
588
  ...(parallelSelection===null?{}:{parallelSelection}),
589
+ ...(batchCompletion===null?{}:{batchCompletionGate:batchCompletion.verify}),
568
590
  developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
569
591
  reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
570
592
  persistence:{store,mode:runnerMode,version:execution===null?2:3},
571
593
  ...(execution===null?{}:{providerDevelopment:protectedExecutions.has(execution)
572
- ||Boolean(execution.configuration.providerDevelopment),protectedDevelopment:conversationProtection(execution)!==null}),
594
+ ||Boolean(execution.configuration.providerDevelopment),protectedDevelopment:conversationProtection(execution)!==null,
595
+ ...(diskEdits?{diskEdits:true}:{})}),
573
596
  ...(execution===null?{}:{developer,reviewers:execution.reviewers,
574
597
  ...(execution.bootstrap?{bootstrap:execution.bootstrap}:{}),
575
598
  reviewInvocation:execution.reviewInvocation,check:execution.check,
576
599
  excludedContexts:execution.excludedContexts,timeoutMs:execution.timeoutMs,
577
600
  ...(Object.hasOwn(execution,'verificationGate')?{verificationGate:execution.verificationGate}:{}),
601
+ ...(typeof execution.onChecksReused==='function'?{onChecksReused:execution.onChecksReused}:{}),
602
+ // Escape hatch for checks that read inputs outside the code (env files,
603
+ // services): a run created with this off always reruns checks at completion.
604
+ // An older empty store finished on resume keeps the old default (no reuse).
605
+ ...(runnerMode==='create'&&(mode!=='create'||process.env.CM_AI_COMPLETION_CHECK_REUSE==='off')?{completionCheckReuse:false}:{}),
606
+ // Same rule for the N6 cadence: an older empty store keeps the historical count.
607
+ ...runnerQaCadence({runnerMode,mode,batchQaCadence}),
578
608
  taskLearning:{feature,hostHandoff:true}})},
579
609
  // The entry validates the declaration (single line, with --rerun-blocked-qa) before any durable write.
580
610
  entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
@@ -588,6 +618,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
588
618
  if(elevatedRecovery||reviewedIntegration!==null){
589
619
  const result=reviewedIntegration!==null?host.acceptReviewedIntegration({allowed:true,...reviewedIntegration})
590
620
  :scopeRevision!==null?host.reviseScope({allowed:true,...scopeRevision})
621
+ :reviewContinuationReason!==null?host.authorizeReviewContinuation({allowed:true,reason:reviewContinuationReason})
591
622
  :host.reworkDevelopment({allowed:true,reason:developmentReworkReason});
592
623
  if(result.outcome==='rejected')fail(result.code);
593
624
  }
@@ -656,7 +687,7 @@ async function openControlRunOwned(definition,mode,execution=null,{supersedeHold
656
687
  return result;
657
688
  }};
658
689
  const controlHost=controlPolicy?withControlPolicyHost(legacyHost,{identity,snapshot:()=>store.snapshot(),launchTarget:controlLaunchTarget}):null;
659
- return {host:legacyHost,...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,acceptReviewedIntegration:host.acceptReviewedIntegration,
690
+ return {host:legacyHost,...(host.preflightBatchCompletion?{preflightBatchCompletion:host.preflightBatchCompletion}:{}),...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,acceptReviewedIntegration:host.acceptReviewedIntegration,
660
691
  checkpoint:()=>store.snapshot().revision,close:()=>store.close()};
661
692
  }catch(error){store.close();throw error;}
662
693
  }
@@ -678,7 +709,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
678
709
  // Config diagnostics contain field names/reasons, never field values or provider text.
679
710
  const code=typeof cause.code==='string'&&(/^[a-z_]+$/.test(cause.code)
680
711
  ||cause.code.startsWith('invalid_config: '))?cause.code:'control_failed';
681
- const reason=code==='runner_invocation'&&typeof cause.reason==='string'?cause.reason:null;
712
+ const reason=(code==='runner_invocation'||EXECUTOR_REASON_CODES.has(code))&&typeof cause.reason==='string'?cause.reason:null;
682
713
  error.write(JSON.stringify({error:{code,...(reason?{reason}:{})}})+'\n');return 1;
683
714
  }finally{run?.close();}
684
715
  }
@@ -178,6 +178,18 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
178
178
  if(repaired)assert.equal(JSON.parse(stdout).result.identity.attempt,2);
179
179
  if(mode==='spec_drift')assert.equal(JSON.parse(stdout).result.code,'spec_drift');
180
180
  if(mode==='review_limit')assert.equal(JSON.parse(stdout).result.code,'review_limit');
181
+ if(mode==='review_limit'){
182
+ // Decision card built from the replayed journal: both rounds, the real check
183
+ // run and the changed files; read-only and with no third round offered.
184
+ const card=JSON.parse(stdout).result.reviewLimitCard;
185
+ assert.equal(card.authorizationGranted,false);assert.equal(card.dispatchedCalls,0);assert.deepEqual(card.missing,[]);
186
+ assert.deepEqual(card.rounds.map(r=>[r.attempt,r.verdict,r.findings[0].path]),[[1,'changes_requested','a.js'],[2,'changes_requested','a.js']]);
187
+ assert.equal(card.rounds[1].findings[0].sameFileAsRound1,true);
188
+ assert.deepEqual(card.checks,{fromAttempt:2,fromReview:2,items:[{id:'content',outcome:'passed'}]});
189
+ assert(card.changes.items.some(c=>c.path==='a.js'&&c.kind==='modified'));
190
+ assert.deepEqual(card.exits.map(e=>[e.id,e.available]),[['supersede',true],['spec_change',true],['review_continuation',false],['human_correction',false]]);
191
+ assert.equal(JSON.parse(stdout).result.guidance.recoveryOperation,null);
192
+ }
181
193
  assert.equal(fs.readFileSync(path.join(f.specsDir,'1.login','tasks.md'),'utf8').includes('[x]'),completed);
182
194
  assert(fs.existsSync(path.join(f.specsDir,'.reviews','login-T-001-a1-handoff.json')));
183
195
  assert.equal(f.invoke('resume',[request('status')]).status,1);
@@ -342,6 +354,20 @@ test('duplicate paths reject before writes and a genuine empty initializer can r
342
354
  assert.equal(resumed.rows[0].result.state,'pending_review');
343
355
  }));
344
356
 
357
+ // Reviews q1/q2: the N6 cadence a created runner freezes. A new batch's member keeps
358
+ // feature-v1 even when it resumes an empty store; a pre-qa_cadence batch never gets it.
359
+ test('runner QA cadence choice for created, empty-store and batch member runs',async()=>{
360
+ const {runnerQaCadence}=await import('./cm-ai-run.mjs');
361
+ assert.deepEqual(runnerQaCadence({runnerMode:'create',mode:'create'}),{});
362
+ assert.deepEqual(runnerQaCadence({runnerMode:'create',mode:'resume'}),{qaCadence:false});
363
+ assert.deepEqual(runnerQaCadence({runnerMode:'resume',mode:'resume'}),{});
364
+ assert.deepEqual(runnerQaCadence({runnerMode:'create',mode:'resume',batchQaCadence:'feature-v1'}),{});
365
+ assert.deepEqual(runnerQaCadence({runnerMode:'create',mode:'create',batchQaCadence:'legacy'}),{qaCadence:false});
366
+ assert.deepEqual(runnerQaCadence({runnerMode:'create',mode:'resume',batchQaCadence:'legacy'}),{qaCadence:false});
367
+ assert.deepEqual(runnerQaCadence({runnerMode:'resume',mode:'resume',batchQaCadence:'legacy'}),{});
368
+ assert.throws(()=>runnerQaCadence({runnerMode:'create',mode:'create',batchQaCadence:'other'}),/batchQaCadence/);
369
+ });
370
+
345
371
  test('configuration object key order does not change durable identity', {skip:!platform},()=>fixture(async f=>{
346
372
  assert.equal(f.invoke('create',[request('status')]).status,0);
347
373
  const reordered=Object.fromEntries(Object.entries(f.definition).reverse());
@@ -24,6 +24,7 @@ import {abandonEffectPlanError,buildCmAiDriveRequest,buildCmAiDriveHostArgs} fro
24
24
  import {spawn as spawnChild,spawnSync} from 'node:child_process';
25
25
  import {createDeveloperRun} from '../runtime/js/cm-ai/developer-adapter.mjs';
26
26
  import {readProcessStartTime} from '../runtime/js/cm-ai/worker-process-identity.mjs';
27
+ import {withFreshCompletionChecks} from './fixtures/fresh-completion-checks.mjs';
27
28
 
28
29
  // Never write the real ~/.cm-workflow home or its global log from this suite.
29
30
  const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-supersede-home-'));
@@ -662,7 +663,7 @@ test('out-of-scope delivery names the paths and re-checks after they are removed
662
663
  // A42: a completion re-check answering with another check list than the reviewed
663
664
  // package is a retryable completion_checks_changed naming both lists; older
664
665
  // journals with the terminal package_mismatch shape replay the same way.
665
- test('completion check-list mismatch is retryable and legacy package_mismatch replays as completion_checks_changed',async()=>{
666
+ test('completion check-list mismatch is retryable and legacy package_mismatch replays as completion_checks_changed',t=>withFreshCompletionChecks(()=>(async()=>{
666
667
  const f=runFixture();
667
668
  try{
668
669
  const runId='completion-check-list',identity=identityFor(runId),content='written\n';
@@ -707,7 +708,7 @@ test('completion check-list mismatch is retryable and legacy package_mismatch re
707
708
  assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));
708
709
  }finally{run.close();}
709
710
  }finally{fs.rmSync(f.root,{recursive:true,force:true});}
710
- });
711
+ })(t)));
711
712
 
712
713
  test('effect-interrupted replay binds intent and last record; forged and duplicate records are refused',async()=>{
713
714
  const f=runFixture();
@@ -1083,6 +1084,13 @@ test('explicit restart archives reviewed bytes and records a new-run authorizati
1083
1084
  const events=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
1084
1085
  .filter(row=>row.event==='supersede'&&row.run_id==='run-three-0003');
1085
1086
  assert.equal(events.length,1);
1087
+ // How the replaced run ended is logged as a separate diagnostic row, so the
1088
+ // restart event keeps its historical content and id.
1089
+ assert.equal(Object.hasOwn(events[0],'predecessor_outcomes'),false);
1090
+ const causes=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
1091
+ .filter(row=>row.event==='supersede_cause'&&row.run_id==='run-three-0003');
1092
+ assert.equal(causes.length,1);assert.equal(causes[0].diagnostic,true);assert.equal(causes[0].record_digest,events[0].record_digest);
1093
+ assert.deepEqual(causes[0].causes,{[[first.state,first.code].filter(Boolean).join('/')]:1});
1086
1094
  }finally{fs.rmSync(f.root,{recursive:true,force:true});}
1087
1095
  });
1088
1096
 
@@ -66,7 +66,7 @@ function started(f,...extra){
66
66
  const runDir=path.join(f.specsDir,'.reviews','.execution',identity.runId);
67
67
  assert(fs.statSync(path.join(runDir,'writer.sqlite')).isFile());
68
68
  const state=JSON.parse(fs.readFileSync(path.join(runDir,'state.json'),'utf8'));
69
- assert.equal(state.version,1);assert.deepEqual(state.identity,{repositoryId:identity.repositoryId,runId:identity.runId});
69
+ assert.equal(state.version,2);assert.equal(state.createdBy.version,1);assert.deepEqual(state.identity,{repositoryId:identity.repositoryId,runId:identity.runId});
70
70
  return state;
71
71
  }
72
72
 
@@ -308,6 +308,15 @@ done
308
308
  for consumer in runtime/js/cm-ai/task-runner.mjs runtime/js/cm-ai/durable-runner-state.mjs scripts/cm-ai-development-rework.test.mjs; do
309
309
  grep -q 'development-rework-authorized' "$ROOT/$consumer" || fail "missing development rework journal pairing: $consumer"
310
310
  done
311
+ require_file "runtime/js/cm-ai/review-continuation.mjs"
312
+ require_file "scripts/cm-ai-review-continuation.test.mjs"
313
+ for consumer in scripts/cm-ai-host.mjs scripts/cm-ai-drive.mjs runtime/js/cm-ai/operator-guidance.mjs "$CONTROL_POLICY_DOC"; do
314
+ grep -q 'review-continuation-reason' "$ROOT/$consumer" || fail "missing review continuation launch consumer: $consumer"
315
+ done
316
+ for consumer in runtime/js/cm-ai/task-runner.mjs runtime/js/cm-ai/durable-runner-state.mjs scripts/cm-ai-review-continuation.test.mjs; do
317
+ grep -q 'review-continuation-authorized' "$ROOT/$consumer" || fail "missing review continuation journal pairing: $consumer"
318
+ done
319
+ grep -q 'REVIEW_CONTINUATION_MARKER_PROTOCOL' "$ROOT/scripts/cm-task-gate.mjs" || fail "missing runner-owned correction marker check"
311
320
  require_file "runtime/js/cm-ai/scope-revision.mjs"
312
321
  require_file "scripts/cm-ai-scope-revision.test.mjs"
313
322
  for consumer in runtime/js/cm-ai/control-policy.mjs runtime/js/cm-ai/host-session.mjs \
@@ -0,0 +1,40 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {previewTools} from '../runtime/js/cm-ai/tool-preview.mjs';
7
+ import {cleanEnvironment} from '../runtime/js/cm-ai/codex-config.mjs';
8
+
9
+ // 2026-11-25: on a macOS system proxy the Codex child of tool-preview sent its loopback
10
+ // probe through the proxy (502). The probe child alone gets a fixed loopback exemption;
11
+ // host proxy values (addresses or bypass lists) reach no CM child.
12
+ const PROXY_KEYS=['NO_PROXY','no_proxy','HTTP_PROXY','http_proxy','HTTPS_PROXY','https_proxy','ALL_PROXY','all_proxy'];
13
+ function withHostProxy(t){
14
+ const saved=Object.fromEntries(PROXY_KEYS.map(k=>[k,process.env[k]]));
15
+ t.after(()=>{for(const [k,v] of Object.entries(saved)){if(v===undefined)delete process.env[k];else process.env[k]=v;}});
16
+ process.env.NO_PROXY='internal.example.test,127.0.0.1';
17
+ process.env.no_proxy='internal.example.test';
18
+ for(const k of PROXY_KEYS.slice(2))process.env[k]='http://proxy.example.test:8080';
19
+ }
20
+
21
+ test('tool-preview probe child gets only the fixed loopback proxy exemption',async t=>{
22
+ withHostProxy(t);
23
+ const dir=fs.mkdtempSync(path.join(os.tmpdir(),'cm-js-b1-'));
24
+ t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
25
+ const dump=path.join(dir,'env.json'),cli=path.join(dir,'fake-codex.mjs');
26
+ fs.writeFileSync(cli,`#!/usr/bin/env node\nimport fs from 'node:fs';\nfs.writeFileSync(${JSON.stringify(dump)},JSON.stringify(process.env));\nprocess.exit(1);\n`,{mode:0o755});
27
+ const receipt=await previewTools({cwd:fs.realpathSync(dir),model:'gpt-6.2-sol',cli,promptTransport:'argument',allowCodeProject:true});
28
+ assert.equal(receipt.passed,false);
29
+ const env=JSON.parse(fs.readFileSync(dump,'utf8'));
30
+ assert.equal(env.NO_PROXY,'127.0.0.1');
31
+ assert.equal(env.no_proxy,'127.0.0.1');
32
+ for(const k of PROXY_KEYS.slice(2))assert.equal(k in env,false,k);
33
+ assert.equal(JSON.stringify(env).includes('internal.example.test'),false);
34
+ });
35
+
36
+ test('other CM children still get no host proxy values',t=>{
37
+ withHostProxy(t);
38
+ const env=cleanEnvironment();
39
+ for(const k of PROXY_KEYS)assert.equal(k in env,false,k);
40
+ });
@@ -19,7 +19,8 @@ const INPUT_LIMIT=1048576,marker='\n<cm-review-data-json>\n';
19
19
  // clause added after #223, so its digest differs from the #223-era value.
20
20
  // Re-pinned deliberately when the reviewer instructions gained the requirement-evidence rule,
21
21
  // and again when they gained the cm-host-replay-v1 rule (host-observed baseline/red record).
22
- const LEGACY_PREFIX_SHA='e84123f370deb7d48eeade10e6ebdae84950f569d52c4e81e5718e0a6ae837c3';
22
+ // Re-pinned deliberately when the verdict rules required a concrete reachable input for every P0-P2 finding (bd972a8).
23
+ const LEGACY_PREFIX_SHA='9cfb8912d9323c181e53982183804b4ba153fb6757298350135911556c0539f8';
23
24
  const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
24
25
  const checks=[{id:'unit',command:['node','synthetic-unit.mjs'],outcome:'passed',exitCode:0,evidence:'Synthetic unit evidence, not a command execution'},
25
26
  {id:'boundary',command:['node','synthetic-boundary.mjs'],outcome:'passed',exitCode:0,evidence:'Synthetic boundary evidence, not a provider call'}];
@@ -0,0 +1,27 @@
1
+ // The developer must see the reviewer's own rejection rules before it returns
2
+ // (2026-11-28: 169 of 172 second rounds across 5 projects came from first-review
3
+ // changes_requested, mostly defects a self-check finds). Guards that the prompt
4
+ // carries the shared VERDICT_RULES and the checklist, not a drifting copy.
5
+ import test from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ // Load the runner first: it reaches the developer adapter through an import cycle.
8
+ import '../runtime/js/cm-ai/task-runner.mjs';
9
+ import {SELF_REVIEW,buildDeveloperPrompt} from '../runtime/js/cm-ai/developer-adapter.mjs';
10
+ import {VERDICT_RULES} from '../runtime/js/cm-ai/review-verdict-rules.mjs';
11
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
12
+
13
+ function request(payload){
14
+ const body={version:1,invocationId:'inv-1',identity:{repositoryId:'repo',runId:'run-1',taskId:'T-001',attempt:2},
15
+ role:'developer',provider:'codex',requestedModel:'m',contextId:'ctx-1',payload};
16
+ return {...body,requestDigest:digest(body)};
17
+ }
18
+
19
+ test('developer prompt carries the reviewer verdict rules and the self-review checklist',()=>{
20
+ assert.ok(SELF_REVIEW.includes(VERDICT_RULES),'self-review must embed the exact reviewer rules');
21
+ const prompt=buildDeveloperPrompt(request({scope:['src/a.js'],requirements:[],priorReview:null}),'codex');
22
+ assert.ok(prompt.includes(SELF_REVIEW),'every developer prompt must include the self-review section');
23
+ for(const phrase of ['failure and cancellation branch','out-of-order responses','real entry point',
24
+ 'device, simulator or browser walkthrough','same defect class'])assert.ok(prompt.includes(phrase),phrase);
25
+ // The checklist sits before the data block, so task data cannot displace it.
26
+ assert.ok(prompt.indexOf(SELF_REVIEW)<prompt.indexOf('<cm-developer-data-json>'));
27
+ });
@@ -192,9 +192,10 @@ test('default and V1 prompts match the frozen pre-V2 bytes for both existing ada
192
192
  // wording. These exact hashes came from each adapter before this change; they were
193
193
  // re-pinned deliberately when the reviewer instructions gained the
194
194
  // requirement-evidence rule (cm-requirement-evidence-v1), and again when they
195
- // gained the host-replay rule (cm-host-replay-v1).
196
- const expected={full:new Set(['8cf6ae73bc414bd408b4756423a4748d708b9c559a6692aea585c903beaa35e7']),
197
- v1:new Set(['b59c4ca5c36fe14d3056dd252fdc31d3e9724bca12855fe88d2bd3a110bd8338'])};
195
+ // gained the host-replay rule (cm-host-replay-v1), and again when the verdict
196
+ // rules required a concrete reachable input for every P0-P2 finding (bd972a8).
197
+ const expected={full:new Set(['50ca577f390ddb6ebf0f336a4c60f68e1070f07df1edc70f567ac37542878003']),
198
+ v1:new Set(['9176e11b924230ca4003d4ed2b59f5e1404087a25dd6599762438ee2a64ba909'])};
198
199
  for(const provider of ['claude','codex']){
199
200
  const request=reviewRequest(provider),full=buildReviewPrompt(request,provider);
200
201
  assert.equal(full,buildReviewPrompt(request,provider,null));
@@ -83,7 +83,8 @@ test('unknown original call stays unknown and cannot be repaired or redispatched
83
83
  test('legacy session is byte-preserved and cannot acquire optimization policy',t=>{
84
84
  const f=fixture(t,{legacy:true});let s=f.open();s.checkpoint({original:true});s.close();const before=fs.readFileSync(f.stateFile);
85
85
  assert.throws(()=>f.open(true),/execution_policy_legacy_run/);assert.deepEqual(fs.readFileSync(f.stateFile),before);
86
- s=f.open(false);assert.equal(s.state.version,1);assert(!Object.hasOwn(s.state,'executionPolicy'));s.close();
86
+ // Created without a policy: format 3 since 0.22.0 (format 1 before), never gaining one.
87
+ s=f.open(false);assert.equal(s.state.version,3);assert(!Object.hasOwn(s.state,'executionPolicy'));s.close();
87
88
  });
88
89
  test('real host transport routes repair without invoking a review channel',async t=>{
89
90
  const f=fixture(t),s=f.open();s.begin({operation:'final_review',mode:'independent',stage:'split',feature:'1.guide'},null);