@aibyzero/cm-workflow 0.16.8 → 0.17.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 (226) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +31 -0
  3. package/README.md +22 -3
  4. package/VERSION +1 -1
  5. package/compat/claude-commands/cm-notify.md +3 -0
  6. package/docs/cm-control-policy-v2.md +331 -0
  7. package/docs/execution-optimizations.md +1 -1
  8. package/docs/external-models.md +3 -3
  9. package/docs/human-correction.md +5 -5
  10. package/docs/installation.md +1 -1
  11. package/docs/js-workflow-control.md +119 -78
  12. package/docs/next-steps.md +19 -2
  13. package/docs/untested-branches.md +2 -3
  14. package/docs/user-guide.md +105 -5
  15. package/package.json +2 -1
  16. package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
  17. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
  18. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
  19. package/runtime/js/cm-ai/code-projects.mjs +4 -1
  20. package/runtime/js/cm-ai/control-policy.mjs +111 -0
  21. package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
  22. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  23. package/runtime/js/cm-ai/drive-core.mjs +9 -0
  24. package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
  25. package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
  26. package/runtime/js/cm-ai/effect-contract.mjs +6 -1
  27. package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
  28. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  29. package/runtime/js/cm-ai/host-check.mjs +4 -1
  30. package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
  31. package/runtime/js/cm-ai/host-documentation.mjs +53 -12
  32. package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
  33. package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
  34. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
  35. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  36. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  37. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  38. package/runtime/js/cm-ai/host-session.mjs +1 -1
  39. package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  41. package/runtime/js/cm-ai/host.mjs +1 -2
  42. package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
  43. package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
  44. package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
  45. package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
  46. package/runtime/js/cm-ai/review-package.mjs +26 -5
  47. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  48. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
  49. package/runtime/js/cm-ai/task-commit.mjs +39 -0
  50. package/runtime/js/cm-ai/task-runner.mjs +629 -121
  51. package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
  52. package/runtime/js/cm-ai/worker-claude.mjs +10 -3
  53. package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
  54. package/runtime/js/cm-fix/execution.mjs +176 -48
  55. package/runtime/js/cm-fix/host.mjs +2 -1
  56. package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
  57. package/runtime/js/cm-fix/progress.mjs +13 -3
  58. package/runtime/js/cm-fix/protected-edits.mjs +10 -3
  59. package/runtime/js/cm-fix/repair.mjs +11 -3
  60. package/runtime/js/cm-fix/test-author.mjs +10 -3
  61. package/runtime/js/cm-idea/session.mjs +67 -4
  62. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  63. package/runtime/js/cm-prd/review-correction.mjs +10 -4
  64. package/runtime/js/cm-prd/review-host.mjs +1 -1
  65. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  66. package/runtime/js/cm-prd/session.mjs +43 -0
  67. package/runtime/js/cm-refactor/records.mjs +98 -8
  68. package/runtime/js/cm-refactor/workflow.mjs +80 -10
  69. package/runtime/js/cm-test/host.mjs +10 -3
  70. package/runtime/js/cm-test/session.mjs +45 -6
  71. package/runtime/js/notify-safe-read.mjs +49 -0
  72. package/runtime/js/notify-send.mjs +313 -0
  73. package/runtime/js/notify.mjs +164 -37
  74. package/runtime/js/policy-binding-compat.mjs +55 -0
  75. package/runtime/review.md +52 -7
  76. package/runtime/task-gates.md +107 -9
  77. package/scripts/ci-test-shards.mjs +67 -0
  78. package/scripts/ci-test-shards.test.mjs +64 -0
  79. package/scripts/ci-test-weights.json +222 -0
  80. package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
  81. package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
  82. package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
  83. package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
  84. package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
  85. package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
  86. package/scripts/cm-ai-batch-drive.mjs +98 -34
  87. package/scripts/cm-ai-batch-drive.test.mjs +124 -16
  88. package/scripts/cm-ai-batch-host.mjs +167 -29
  89. package/scripts/cm-ai-batch-host.test.mjs +303 -31
  90. package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
  91. package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
  92. package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
  93. package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
  94. package/scripts/cm-ai-batch-run.mjs +213 -25
  95. package/scripts/cm-ai-batch-run.test.mjs +21 -341
  96. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  97. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  98. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  99. package/scripts/cm-ai-control-policy.test.mjs +124 -0
  100. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  101. package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
  102. package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
  103. package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
  104. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  105. package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
  106. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
  107. package/scripts/cm-ai-drive.mjs +142 -58
  108. package/scripts/cm-ai-drive.test.mjs +70 -84
  109. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  110. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  111. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
  113. package/scripts/cm-ai-host-fixture.mjs +296 -0
  114. package/scripts/cm-ai-host-protected.test.mjs +253 -0
  115. package/scripts/cm-ai-host.mjs +122 -100
  116. package/scripts/cm-ai-host.test.mjs +35 -776
  117. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  118. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  119. package/scripts/cm-ai-light-modules.test.mjs +54 -0
  120. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  121. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  122. package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
  123. package/scripts/cm-ai-progress.test.mjs +10 -8
  124. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  125. package/scripts/cm-ai-protected-scope.test.mjs +8 -5
  126. package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
  127. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  128. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  129. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
  130. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  131. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  132. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
  133. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  134. package/scripts/cm-ai-review-failure.test.mjs +137 -32
  135. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  136. package/scripts/cm-ai-review-timeout.test.mjs +132 -67
  137. package/scripts/cm-ai-run.mjs +91 -28
  138. package/scripts/cm-ai-run.test.mjs +11 -38
  139. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  140. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  141. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  142. package/scripts/cm-ai-supersede.test.mjs +489 -51
  143. package/scripts/cm-blocked-reason.test.mjs +2 -3
  144. package/scripts/cm-capability-gate.test.mjs +33 -1
  145. package/scripts/cm-check-drive-files.mjs +8 -0
  146. package/scripts/cm-check-drive.test.mjs +2 -5
  147. package/scripts/cm-check-runtime.sh +4 -2
  148. package/scripts/cm-claude-developer-worker.test.mjs +15 -0
  149. package/scripts/cm-claude-review-stream.test.mjs +21 -16
  150. package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
  151. package/scripts/cm-claude-worker.test.mjs +23 -5
  152. package/scripts/cm-controlled-correction.test.mjs +469 -0
  153. package/scripts/cm-external-batch-host.test.mjs +30 -11
  154. package/scripts/cm-external-model-host.test.mjs +1 -1
  155. package/scripts/cm-external-model-recovery.test.mjs +32 -12
  156. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  157. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  158. package/scripts/cm-fix-abandon.test.mjs +163 -10
  159. package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
  160. package/scripts/cm-fix-drive.mjs +25 -7
  161. package/scripts/cm-fix-host.mjs +8 -7
  162. package/scripts/cm-fix-review-budget.test.mjs +13 -0
  163. package/scripts/cm-fix-review-recovery.test.mjs +36 -1
  164. package/scripts/cm-host-answer-timeout.test.mjs +65 -0
  165. package/scripts/cm-host-call-kinds.test.mjs +28 -0
  166. package/scripts/cm-host-documentation.test.mjs +49 -0
  167. package/scripts/cm-host-qa-executor.test.mjs +23 -12
  168. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  169. package/scripts/cm-host-review-authority.test.mjs +0 -31
  170. package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
  171. package/scripts/cm-idea-drive.mjs +49 -11
  172. package/scripts/cm-idea-drive.test.mjs +66 -0
  173. package/scripts/cm-idea-host.mjs +106 -16
  174. package/scripts/cm-init-answer-gaps.test.mjs +258 -0
  175. package/scripts/cm-init-drive.mjs +41 -7
  176. package/scripts/cm-init-host.mjs +61 -12
  177. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  178. package/scripts/cm-log-event.mjs +21 -10
  179. package/scripts/cm-notify-command.test.mjs +936 -0
  180. package/scripts/cm-notify-read-drift.test.mjs +270 -0
  181. package/scripts/cm-notify.mjs +481 -0
  182. package/scripts/cm-notify.test.mjs +312 -23
  183. package/scripts/cm-patrol.test.mjs +3 -2
  184. package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
  185. package/scripts/cm-prd-drive.mjs +18 -5
  186. package/scripts/cm-prd-drive.test.mjs +15 -0
  187. package/scripts/cm-prd-host.mjs +37 -4
  188. package/scripts/cm-prd-review-disposition.test.mjs +6 -1
  189. package/scripts/cm-prd-review-gate.mjs +56 -0
  190. package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
  191. package/scripts/cm-refactor-drive.mjs +52 -8
  192. package/scripts/cm-refactor-drive.test.mjs +44 -0
  193. package/scripts/cm-refactor-host.test.mjs +10 -6
  194. package/scripts/cm-release-smoke.sh +2 -0
  195. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  196. package/scripts/cm-task-gate.mjs +368 -34
  197. package/scripts/cm-task-gate.py +2 -0
  198. package/scripts/cm-task-gate.test.mjs +252 -4
  199. package/scripts/cm-test-answer-gaps.test.mjs +151 -0
  200. package/scripts/cm-test-drive.mjs +21 -5
  201. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  202. package/scripts/fixtures/claude-review-process.mjs +1 -1
  203. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  204. package/scripts/policy-binding-compat.test.mjs +103 -0
  205. package/scripts/scan-public-safety.py +4 -0
  206. package/scripts/validate-public-repo.py +4 -0
  207. package/skills/cm-ai/SKILL.md +8 -6
  208. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  209. package/skills/cm-ai/references/N4-review.md +11 -21
  210. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  211. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  212. package/skills/cm-ai/references/js-host-modes.md +35 -14
  213. package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
  214. package/skills/cm-ai/references/js-host-recovery.md +181 -21
  215. package/skills/cm-ai/references/js-host.md +76 -32
  216. package/skills/cm-check/SKILL.md +3 -3
  217. package/skills/cm-fix/SKILL.md +12 -0
  218. package/skills/cm-fix/references/js-host.md +44 -5
  219. package/skills/cm-idea/references/js-host.md +27 -2
  220. package/skills/cm-init/references/js-host.md +17 -4
  221. package/skills/cm-notify/SKILL.md +34 -0
  222. package/skills/cm-prd/references/js-change-recovery.md +35 -1
  223. package/skills/cm-prd/references/js-host.md +1 -1
  224. package/skills/cm-refactor/SKILL.md +12 -0
  225. package/skills/cm-refactor/references/js-host.md +17 -0
  226. package/skills/cm-test/references/js-host.md +14 -1
@@ -19,8 +19,7 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
19
19
  execution:{kind:'cm-current-conversation-v1',hostContextId:'host',review:{model:'fixture'},
20
20
  workflow:{qa:{commands:[],environment:{}},documentationPaths:['README.md'],applicableAgentFiles:[]}},
21
21
  qaExecutor:{version:1,mode:'commands'},qaDecisionProvider:'host-v1',qaTimeoutMs:60000,
22
- applicableAgentFiles:[],documentationProvider:{version:1,timeoutMs:60000},documentationSync:{version:1,paths:['README.md']},
23
- hostDecisionProvider:{version:1,timeoutMs:60000},developmentAuthorization:'per-attempt-v1'};
22
+ applicableAgentFiles:[],documentationProvider:{version:1,timeoutMs:60000},documentationSync:{version:1,paths:['README.md']},developmentAuthorization:'per-attempt-v1'};
24
23
  const original=structuredClone(material),[withoutQa,withoutWorkflow]=preQaConfigurations(material);
25
24
  assert.deepEqual(material,original);
26
25
  assert.equal(withoutQa.execution.workflow.qa,null);
@@ -32,7 +31,6 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
32
31
  assert.deepEqual(projection.definition,material.definition);
33
32
  assert.deepEqual(projection.execution.review,material.execution.review);
34
33
  assert.equal(projection.execution.hostContextId,'host');
35
- assert.deepEqual(projection.hostDecisionProvider,material.hostDecisionProvider);
36
34
  assert.equal(projection.developmentAuthorization,material.developmentAuthorization);
37
35
  assert(!Object.hasOwn(projection,'qaExecutor'));
38
36
  }
@@ -53,19 +51,20 @@ test('fixed Codex assembly requires review preflight and denies developer dispat
53
51
  const {requestFor}=await import('../runtime/js/cm-ai/effect-contract.mjs');
54
52
  const config={codeProject:f.codeProject,developerModel:'fixture',reviewerModel:'fixture',hostContextId:'main',
55
53
  developerContextId:'author',checkCommands:[{id:'check',command:[process.execPath,'--version']}],timeoutMs:1000,reviewerPreflight:null};
56
- let decisions=0;const authority={authorizeDevelopment:()=>{decisions++;return {status:'denied'};},
57
- authorizeReview:()=>({status:'denied',code:'permission_denied'}),hostDecision:{status:'denied',code:'permission_denied'}};
54
+ let decisions=0;const authority={authorizeDevelopment:()=>{decisions++;return {status:'denied'};}};
58
55
  await assert.rejects(createCodexExecution(config,authority),{code:'tool_preflight_missing'});
59
56
  config.reviewerPreflight={passed:true,cli_model:'fixture',prompt_transport:'stdin',
60
57
  config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})};
61
58
  const execution=await createCodexExecution(config,authority);assert.equal(decisions,0);
62
59
  const request=requestFor({invocationId:'dev-1',identity,role:'developer',provider:'codex',requestedModel:'fixture',
63
60
  contextId:'author',payload:{scope:['a.js'],requirements:[],priorReview:null}});
64
- await assert.rejects(execution.developer.run(request,{signal:new AbortController().signal}),{code:'permission_denied'});
61
+ let workerEvents=0;
62
+ await assert.rejects(execution.developer.run(request,{signal:new AbortController().signal,onWorker:()=>workerEvents++}),{code:'invalid_development_attempt'});
63
+ assert.equal(workerEvents,0,'denied workflow scope must refuse before worker spawn');
65
64
  assert.equal(decisions,1);assert.equal(fs.readFileSync(path.join(f.codeProject,'a.js'),'utf8'),'old\n');
66
- assert.equal(execution.reviewInvocation.authorize,authority.authorizeReview);
65
+ assert.equal(Object.hasOwn(execution.reviewInvocation,'authorize'),false);
67
66
  }));
68
- for(const [mode,nested] of [...['manual','approved','denied','awaiting','blocked','repair','review_limit','spec_drift'].map(mode=>[mode,false]),['approved',true],['blocked',true]])
67
+ for(const [mode,nested] of [...['manual','approved','blocked','repair','review_limit','spec_drift'].map(mode=>[mode,false]),['approved',true],['blocked',true]])
69
68
  test(`trusted host execution uses the same entry and sole gate: ${mode} nested=${nested}`,
70
69
  {skip:!platform},()=>fixture(async f=>{
71
70
  const {main}=await import('./cm-ai-run.mjs');
@@ -105,34 +104,11 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
105
104
  examinedPaths:reviewPaths(request.payload.reviewPackage),findings:verdict==='changes_requested'
106
105
  ?[{id:'F1',severity:'P2',path:'a.js',message:'Synthetic repair required',evidence:'First implementation'}]:[],summary:'Synthetic review'}};
107
106
  }}],
108
- reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main'],
109
- authorize:(request,{authorizationAt})=>{
110
- assert(['approved','blocked','repair','review_limit','spec_drift'].includes(mode));
111
- const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.attempt}`,adapterId:'codex-review-adapter',
112
- invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
113
- reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
114
- hostContextId:'main',decisionId:`decision-${request.identity.attempt}`,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
115
- return {...body,grantDigest:digest(body)};
116
- }},
117
- hostDecision:mode==='awaiting'?null:['approved','blocked','repair','review_limit','spec_drift'].includes(mode)?{status:'approved'}:{status:'denied',code:'permission_denied'},
107
+ reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main']},
118
108
  check:createHostCheck({cwd:f.codeProject,commands:[{id:'content',command:[process.execPath,'-e',
119
109
  "require('node:assert/strict').match(require('node:fs').readFileSync('a.js','utf8'),/^new( 2)?\\n$/)"]}]})};
120
- let qaCalls=0,qaRuns=0,docInspections=0,docWrites=0,reviewDecisions=0;
110
+ let qaCalls=0,qaRuns=0,docInspections=0,docWrites=0;
121
111
  const dynamicQa=mode==='approved'&&!nested;
122
- const dynamicReview=dynamicQa||mode==='repair';
123
- if(dynamicReview){
124
- const {createHostReviewAuthority}=await import('../runtime/js/cm-ai/host-review-authority.mjs');
125
- const authority=createHostReviewAuthority({hostContextId:'main',reviewerId:'reviewer',adapterId:'codex-review-adapter',
126
- timeoutMs:1000,decide:async(binding,signal)=>{
127
- reviewDecisions++;await Promise.resolve();assert.equal(signal.aborted,false);
128
- assert.equal(binding.identity.attempt,reviewDecisions);
129
- const handoff=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews',`login-T-001-a${binding.identity.attempt}-handoff.json`),'utf8'));
130
- assert.equal(handoff.status,'ready_for_review');assert.match(binding.packageDigest,/^[a-f0-9]{64}$/);
131
- return {status:'approved'};
132
- }});
133
- execution.hostDecision=null;execution.hostDecisionProvider=authority.hostDecisionProvider;
134
- execution.reviewInvocation.authorize=authority.authorize;
135
- }
136
112
  if(dynamicQa){
137
113
  const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
138
114
  definition.scope.push('README.md');fs.writeFileSync(f.config,JSON.stringify(definition));
@@ -189,8 +165,6 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
189
165
  if(repaired)assert.equal(JSON.parse(stdout).result.identity.attempt,2);
190
166
  if(mode==='spec_drift')assert.equal(JSON.parse(stdout).result.code,'spec_drift');
191
167
  if(mode==='review_limit')assert.equal(JSON.parse(stdout).result.code,'review_limit');
192
- if(mode==='denied')assert.equal(JSON.parse(stdout).result.outcome,'denied');
193
- if(mode==='awaiting')assert.equal(JSON.parse(stdout).result.code,'decision_required');
194
168
  assert.equal(fs.readFileSync(path.join(f.specsDir,'1.login','tasks.md'),'utf8').includes('[x]'),completed);
195
169
  assert(fs.existsSync(path.join(f.specsDir,'.reviews','login-T-001-a1-handoff.json')));
196
170
  assert.equal(f.invoke('resume',[request('status')]).status,1);
@@ -201,7 +175,6 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
201
175
  {input:resumedInput,output:resumedOutput,error,execution}),0,stderr);
202
176
  assert.equal(JSON.parse(resumed).result.state,expected,resumed);
203
177
  assert.equal(calls,repaired?2:1);assert.equal(reviews,repaired?2:['approved','blocked','spec_drift'].includes(mode)?1:0);
204
- if(dynamicReview)assert.equal(reviewDecisions,repaired?2:1,'reopen must not reauthorize completed review');
205
178
  if(dynamicQa){
206
179
  assert.equal(qaCalls,1);assert.equal(qaRuns,1);assert.equal(docInspections,2);assert.equal(docWrites,1);
207
180
  assert.equal(JSON.parse(resumed).result.code,'run_done');
@@ -400,13 +373,13 @@ test('trusted parallel selection binds admission, Learning, start and resume fin
400
373
  const learning={specsDir:f.specsDir,codeProject:f.codeProject,feature:'1.login',identity:definition.identity,applicableAgentFiles:[]};
401
374
  assert.throws(()=>inspectCmAiTaskLearningInput(learning),{code:'learning_context_invalid'});
402
375
  assert.equal(inspectCmAiTaskLearningInput(learning,{parallelSelection}).identity.taskId,'T-002');
403
- const execution={configuration:{kind:'selection-fixture'},timeoutMs:2000,excludedContexts:['host'],hostDecision:null,
376
+ const execution={configuration:{kind:'selection-fixture'},timeoutMs:2000,excludedContexts:['host'],
404
377
  developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.js'),'selected implementation\n');return {status:'succeeded',value:{outcome:'implemented',
405
378
  application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
406
379
  check:async()=>[{id:'check',command:['fixture'],outcome:'passed',exitCode:0,evidence:'fixture'}],reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',
407
380
  requestedModel:'fixture',allowed:true,available:true,contexts:['review-1','review-2'],
408
381
  run:async()=>{throw new Error('no review');}}],
409
- reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host'],authorize:()=>{throw new Error('no review');}}};
382
+ reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']}};
410
383
  await assert.rejects(openControlRun(definition,'create',execution),{code:'task_selection_mismatch'});
411
384
  await assert.rejects(openControlRun(definition,'create',execution,{parallelSelection:{version:1,group:['T-001','T-003']}}),{code:'task_selection_mismatch'});
412
385
  const direct=createCmAiHost({runner:{root:f.codeProject,identity:definition.identity,scope:['a.js'],requirements:['requirements.md'],
@@ -21,12 +21,12 @@ function fixture(t){
21
21
  const definition=(runId,taskId='T-001',taskSelection)=>validateRunDefinition({version:1,specsDir,codeProject,feature,
22
22
  identity:{repositoryId:'guard-fixture',runId,taskId,attempt:1},scope:['a.mjs'],requirements:[],
23
23
  ...(taskSelection?{taskSelection}: {})});
24
- const execution={configuration:{kind:'guard-fixture'},timeoutMs:1000,excludedContexts:['host'],hostDecision:null,
24
+ const execution={configuration:{kind:'guard-fixture'},timeoutMs:1000,excludedContexts:['host'],
25
25
  qaLogHome:path.join(root,'logs'),
26
26
  developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:async()=>{throw Error('unexpected development');}},
27
27
  reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,
28
28
  available:true,contexts:['review-one','review-two'],run:async()=>{throw Error('unexpected review');}}],
29
- reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host'],authorize:()=>{throw Error('unexpected review');}},
29
+ reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']},
30
30
  check:async()=>{throw Error('unexpected check');}};
31
31
  return {root,specsDir,codeProject,feature,definition,execution};
32
32
  }
@@ -41,10 +41,10 @@ function fixture(t){
41
41
  return {root,definition,codeProject,specsDir,config,review,reviewFile,records,fake,
42
42
  env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
43
43
  }
44
- function launch(f,{host='session-A',original,mode='resume',operation='status',review=false}={}){
44
+ function launch(f,{host='session-A',original,mode='resume',operation='status',review=false,hold=false}={}){
45
45
  return new Promise((resolve,reject)=>{
46
46
  const args=['serve','--config',f.config,'--mode',mode,'--host-context',host,'--allow-development','--review-config',f.reviewFile,
47
- ...(original===undefined?[]:['--original-host-context',original]),...(review?['--allow-review-attempt',String(review===true?1:review)]:[])];
47
+ ...(original===undefined?[]:['--original-host-context',original]),...(hold?['--hold-revision']:[])];
48
48
  const child=spawn(process.execPath,[cli,...args],{env:f.env,stdio:['pipe','pipe','pipe']});
49
49
  let buffer='',stderr='';const rows=[];
50
50
  const timer=setTimeout(()=>{child.kill();reject(Error('session chain timeout'));},15000);
@@ -76,11 +76,13 @@ function launch(f,{host='session-A',original,mode='resume',operation='status',re
76
76
  }
77
77
  });
78
78
  child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,rows,result:rows.find(r=>r.requestId===operation)?.result});});
79
- send({version:1,operation,requestId:operation,identity});
79
+ const attempt=fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'))
80
+ ?runnerStatus(readRunnerHistory(f.records(),f.records()[0].payload.config,3).state,f.records()[0].payload.config).identity.attempt:1;
81
+ send({version:1,operation,requestId:operation,identity:{...identity,attempt}});
80
82
  });
81
83
  }
82
84
  const ok=run=>{assert.equal(run.code,0,run.stderr);return run.result;};
83
- async function created(t){const f=fixture(t);assert.equal(ok(await launch(f,{mode:'create',operation:'advance'})).code,'decision_required');return f;}
85
+ async function created(t){const f=fixture(t);assert.equal(ok(await launch(f,{mode:'create',operation:'start'})).state,'awaiting_review');return f;}
84
86
  async function reviewed(t,host='session-B'){
85
87
  const f=await created(t);f.before=f.records().map(row=>JSON.stringify(row));
86
88
  assert.equal(ok(await launch(f,{host,original:'session-A',operation:'advance',review:true})).state,'fixture_completed');return f;
@@ -102,7 +104,7 @@ test('original-host-context on create fails before opening store, including equa
102
104
  }
103
105
  });
104
106
 
105
- test('A creates, B signs review, C declaring only A replays the completed run',async t=>{
107
+ test('A creates, B runs review, C declaring only A replays the completed run',async t=>{
106
108
  const f=await reviewed(t),before=f.records();
107
109
  for(const host of ['session-C','session-B','session-A']){
108
110
  assert.equal(ok(await launch(f,{host,original:'session-A'})).state,'fixture_completed');
@@ -110,12 +112,12 @@ test('A creates, B signs review, C declaring only A replays the completed run',a
110
112
  }
111
113
  });
112
114
 
113
- test('joining host is journaled once immediately before its grant; old records keep exact bytes',async t=>{
115
+ test('joining host is journaled once immediately before its review binding; old records keep exact bytes',async t=>{
114
116
  const f=await reviewed(t),rows=f.records(),joins=rows.filter(r=>r.payload.type==='host-joined');
115
117
  assert.equal(joins.length,1);assert.equal(joins[0].kind,'result');
116
118
  assert.deepEqual(joins[0].payload,{version:3,protocol:'cm-task-runner',type:'host-joined',hostContextId:'session-B'});
117
119
  const index=rows.indexOf(joins[0]);assert.equal(rows[index+1].payload.type,'review-invocation-registered');
118
- assert.equal(rows[index+1].payload.grant.hostContextId,'session-B');
120
+ assert.equal(rows[index+1].payload.binding.hostContextId,'session-B');
119
121
  assert.deepEqual(rows.slice(0,f.before.length).map(row=>JSON.stringify(row)),f.before);
120
122
  for(const host of ['session-B','session-C'])ok(await launch(f,{host,original:'session-A'}));
121
123
  assert.deepEqual(f.records(),rows);
@@ -166,8 +168,9 @@ test('V3 joined-host grammar rejects misplaced, duplicate, durable and extra rec
166
168
 
167
169
  test('V3 joined-host grammar rejects an earlier reviewer joining before a later review registration',async t=>{
168
170
  const f=await created(t);reviewerResult(f,{thread:'earlier-reviewer',changes:true});
169
- const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
170
- assert.equal(revised.state,'awaiting_review');assert.equal(revised.code,'decision_required');
171
+ const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true,hold:true}));
172
+ assert.equal(revised.state,'changes_requested');assert.equal(revised.code,'revision_answer_required');
173
+ assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
171
174
  const rows=f.records(),config=rows[0].payload.config;
172
175
  const reviewerThread=rows.find(r=>r.payload.type==='review-invocation-started').payload.providerThreadId;
173
176
  const firstIntent=rows.find(r=>r.payload.type==='effect-intent'&&r.payload.effect.kind==='review');
@@ -188,7 +191,7 @@ test('V3 joined-host grammar rejects an earlier reviewer joining before a later
188
191
 
189
192
  test('development after cross-session reopen reports live provider thread without changing init',async t=>{
190
193
  const f=fixture(t);ok(await launch(f,{mode:'create'}));const before=f.records();
191
- assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance'})).code,'decision_required');
194
+ assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
192
195
  const rows=f.records();assert.deepEqual(rows.slice(0,before.length),before);
193
196
  assert.deepEqual(rows[0].payload.config.reviewInvocation,{developerThreadId:'cm-conversation-author',excludedThreadIds:['session-A']});
194
197
  const call=rows.filter(r=>r.payload.type==='effect-checkpoint').at(-1).payload.checkpoint.calls[0];
@@ -213,9 +216,9 @@ for(const thread of ['session-A','session-B'])test(`live reviewer cannot be dura
213
216
 
214
217
  test('second review excludes earlier joined host even when the current host is C',async t=>{
215
218
  const f=await created(t);reviewerResult(f,{changes:true});
216
- const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
217
- // advance also develops attempt 2, then waits for its separate review grant.
218
- assert.equal(revised.state,'awaiting_review');assert.equal(revised.code,'decision_required');
219
+ const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true,hold:true}));
220
+ assert.equal(revised.state,'changes_requested');assert.equal(revised.code,'revision_answer_required');
221
+ assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
219
222
  reviewerResult(f,{thread:'session-B'});
220
223
  const result=ok(await launch(f,{host:'session-C',original:'session-A',operation:'advance',review:2}));
221
224
  assert.equal(result.state,'unknown');
@@ -243,7 +246,7 @@ test('runner session chain without CLI reaches B grant and replays it in C',asyn
243
246
  }};
244
247
  const durable=createConversationExecution(f.definition,'session-A',bridge,f.review);
245
248
  const execution=(host,allow=false)=>{
246
- const live=createConversationExecution(f.definition,host,bridge,f.review,allow?1:null);
249
+ const live=createConversationExecution(f.definition,host,bridge,f.review,null);
247
250
  return {...live,configuration:durable.configuration,excludedContexts:durable.excludedContexts,
248
251
  reviewInvocation:{...live.reviewInvocation,excludedThreadIds:durable.reviewInvocation.excludedThreadIds},
249
252
  reviewers:live.reviewers.map(reviewer=>({...reviewer,run(request,{onEvent}){
@@ -258,7 +261,7 @@ test('runner session chain without CLI reaches B grant and replays it in C',asyn
258
261
  const run=await openControlRun(f.definition,mode,execution(host,allow));
259
262
  try{return await run.host.handle({version:1,operation,requestId:operation,identity});}finally{run.close();}
260
263
  }
261
- assert.equal((await session('session-A','create','advance')).code,'decision_required');
264
+ assert.equal((await session('session-A','create','start')).state,'awaiting_review');
262
265
  const reviewed=await session('session-B','resume','advance',true);
263
266
  assert.equal(reviewed.state,'fixture_completed',JSON.stringify(reviewed));
264
267
  assert.equal((await session('session-C','resume','status')).state,'fixture_completed');
@@ -15,6 +15,7 @@ import {writeSpecsStatus,readSpecsStatus} from '../runtime/js/specs-status.mjs';
15
15
  import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
16
16
  import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
17
17
  import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
18
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
18
19
  import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
19
20
  import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
20
21
 
@@ -62,15 +63,7 @@ function executionFor(f,{decision=null,onReview=()=>{},onDevelop=()=>{}}={}){
62
63
  requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'export const a=2;\n');onDevelop();
63
64
  return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
64
65
  retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
65
- reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
66
- authorize:(request,{authorizationAt})=>{
67
- const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.runId}`,
68
- adapterId:'codex-review-adapter',invocationId:request.invocationId,requestDigest:request.requestDigest,
69
- identity:request.identity,reviewerId:'reviewer',logicalContextId:request.contextId,
70
- packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'control',decisionId:'approved',
71
- decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
72
- return {...body,grantDigest:digest(body)};
73
- }},hostDecision:decision,check:createHostCheck({cwd:f.codeProject,
66
+ reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,
74
67
  commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]})};
75
68
  }
76
69
  async function withRun(f,mode,options,run,runId){
@@ -80,8 +73,8 @@ async function withRun(f,mode,options,run,runId){
80
73
  const ask=(host,identity,operation,extra={})=>host.handle({version:1,operation,requestId:operation,identity,...extra});
81
74
  async function awaitingReview(f){
82
75
  return withRun(f,'create',{},async(host,identity)=>{
83
- const result=await ask(host,identity,'advance');
84
- assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.code,'decision_required');
76
+ const result=await ask(host,identity,'start');
77
+ assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.code,null);
85
78
  return result.packageDigest;
86
79
  });
87
80
  }
@@ -96,8 +89,10 @@ test('another task changed and re-approved: status names spec_drift and the rebi
96
89
  assert.equal(status.state,'awaiting_review');assert.equal(status.code,'spec_drift');
97
90
  assert.equal(status.pendingAction,'spec_rebind');
98
91
  assert.match(status.reason,/1\.work\/tasks\.md/);assert.match(status.reason,/--rebind-spec-material/);
99
- const decision=await ask(host,identity,'decision',{packageDigest});
100
- assert.equal(decision.outcome,'rejected');assert.equal(decision.code,'spec_drift');
92
+ const beforeAction=fs.readFileSync(stateFile(f));
93
+ const decision=await ask(host,identity,'advance');
94
+ assert.deepEqual(fs.readFileSync(stateFile(f)),beforeAction,'spec drift dispatch refusal keeps exact journal bytes');
95
+ assert.equal(decision.outcome,'reported');assert.equal(decision.code,'spec_drift');
101
96
  assert.equal(decision.pendingAction,'spec_rebind');
102
97
  });
103
98
  const before=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records.length;
@@ -164,7 +159,7 @@ test('a rebind cannot carry changed content: a later content change still drifts
164
159
  // advertise an action the run would refuse.
165
160
  test('a spec change during review never leaves status advertising a refused action',async t=>{
166
161
  const f=fixture(t);
167
- await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'advance')).state,'awaiting_review'));
162
+ await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'start')).state,'awaiting_review'));
168
163
  const changeDuringReview=()=>{
169
164
  fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 审查期间改了\n\n- T-002 依赖 T-001\n');reapprove(f);};
170
165
  await withRun(f,'resume',{decision:{status:'approved'},onReview:changeDuringReview},async(host,identity)=>{
@@ -179,7 +174,8 @@ test('a spec change during review never leaves status advertising a refused acti
179
174
  test('host CLI accepts the rebind only on resume with a single-line reason',t=>{
180
175
  const f=fixture(t),config=path.join(f.root,'run.json'),review=path.join(f.root,'review.json');
181
176
  fs.writeFileSync(config,JSON.stringify(f.definition('rebind-cli-run')));
182
- fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{}}));
177
+ fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
178
+ config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})}}));
183
179
  const launch=(mode,extra)=>{
184
180
  const result=spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context','cli-host',
185
181
  '--allow-development','--review-config',review,...extra],{encoding:'utf8',timeout:20000,input:'',
@@ -209,7 +205,7 @@ test('a run rebound before its first delivery develops against the re-approved s
209
205
  assert.equal((await ask(host,identity,'advance')).code,'spec_drift');
210
206
  });
211
207
  await withRun(f,'resume',{specRebindReason:'只改了 T-002'},async(host,identity)=>{
212
- const result=await ask(host,identity,'advance');
208
+ const result=await ask(host,identity,'start');
213
209
  assert.equal(result.state,'awaiting_review',JSON.stringify(result));
214
210
  });
215
211
  });
@@ -470,9 +466,9 @@ test('a batch member never advertises spec_rebind and names the real exits',asyn
470
466
  const batch=()=>createCmAiBatch({configuration:{version:1,repositoryId:'rebind-fixture',batchId:'rebind-batch-1',
471
467
  specsDir:f.specsDir,codeProject:f.codeProject,tasks:['T-001','T-002'].map(taskId=>({feature:f.feature,taskId,
472
468
  scope:[taskId==='T-001'?'a.mjs':'b.mjs'],requirements:['requirements.md']}))},
473
- executionFor:async()=>executionFor(f),logHome:path.join(f.root,'batch-logs')});
469
+ executionFor:async()=>({...executionFor(f),check:createHostCheck({cwd:f.codeProject,commands:[{id:'hold',command:[process.execPath,'-e','process.exit(1)']}]})}),logHome:path.join(f.root,'batch-logs')});
474
470
  const first=await batch().handle({operation:'advance',requestId:'batch-advance'});
475
- assert.equal(first.state,'awaiting_review',JSON.stringify(first));
471
+ assert.equal(first.state,'blocked',JSON.stringify(first));assert.equal(first.code,'develop_checks_not_passed');
476
472
  fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
477
473
  const status=await batch().handle({operation:'status',requestId:'batch-status'});
478
474
  assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');