@aibyzero/cm-workflow 0.16.2 → 0.16.4

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 (155) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +4 -0
  3. package/CHANGELOG.md +147 -0
  4. package/README.md +44 -3
  5. package/VERSION +1 -1
  6. package/docs/installation.md +1 -1
  7. package/docs/js-workflow-control.md +46 -7
  8. package/docs/next-steps.md +100 -0
  9. package/docs/untested-branches.md +24 -18
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/claude-review-stream.mjs +18 -0
  12. package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
  13. package/runtime/js/cm-ai/cm-ai-admission.mjs +7 -1
  14. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
  15. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
  16. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
  17. package/runtime/js/cm-ai/drive-core.mjs +68 -0
  18. package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
  19. package/runtime/js/cm-ai/effect-contract.mjs +4 -3
  20. package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
  21. package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
  22. package/runtime/js/cm-ai/host-handoff.mjs +9 -14
  23. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
  24. package/runtime/js/cm-ai/host-session.mjs +10 -3
  25. package/runtime/js/cm-ai/host.mjs +1 -1
  26. package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
  27. package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
  28. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
  29. package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
  30. package/runtime/js/cm-ai/task-runner.mjs +41 -8
  31. package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
  32. package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
  33. package/runtime/js/cm-fix/cause-package.mjs +21 -0
  34. package/runtime/js/cm-fix/dossier.mjs +40 -1
  35. package/runtime/js/cm-fix/execution.mjs +360 -83
  36. package/runtime/js/cm-fix/host.mjs +7 -3
  37. package/runtime/js/cm-fix/layout.mjs +14 -6
  38. package/runtime/js/cm-fix/progress.mjs +14 -0
  39. package/runtime/js/cm-fix/protected-edits.mjs +1 -1
  40. package/runtime/js/cm-fix/red-test.mjs +7 -6
  41. package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
  42. package/runtime/js/cm-fix/regression.mjs +16 -10
  43. package/runtime/js/cm-fix/repair.mjs +16 -13
  44. package/runtime/js/cm-fix/test-author.mjs +2 -1
  45. package/runtime/js/cm-fix/test-extension.mjs +45 -0
  46. package/runtime/js/cm-prd/accepted-design.mjs +28 -9
  47. package/runtime/js/cm-prd/analysis.mjs +68 -16
  48. package/runtime/js/cm-prd/change.mjs +21 -1
  49. package/runtime/js/cm-prd/draft-save.mjs +96 -2
  50. package/runtime/js/cm-prd/failed-correction.mjs +51 -0
  51. package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
  52. package/runtime/js/cm-prd/review-correction.mjs +3 -0
  53. package/runtime/js/cm-prd/review-disposition.mjs +33 -15
  54. package/runtime/js/cm-prd/review-findings.mjs +2 -2
  55. package/runtime/js/cm-prd/review-host.mjs +2 -0
  56. package/runtime/js/cm-prd/review-preparation.mjs +28 -1
  57. package/runtime/js/cm-prd/review-publication.mjs +4 -2
  58. package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
  59. package/runtime/js/cm-prd/session.mjs +5 -5
  60. package/runtime/js/cm-prd/split-design.mjs +67 -0
  61. package/runtime/js/cm-prd/summary.mjs +57 -10
  62. package/runtime/js/cm-refactor/workflow.mjs +100 -19
  63. package/runtime/js/specs-status.mjs +6 -2
  64. package/scripts/cm-ai-admission.mjs +2 -0
  65. package/scripts/cm-ai-batch-drive.mjs +251 -0
  66. package/scripts/cm-ai-batch-drive.test.mjs +159 -0
  67. package/scripts/cm-ai-batch-host.mjs +13 -5
  68. package/scripts/cm-ai-batch-host.test.mjs +25 -0
  69. package/scripts/cm-ai-contracts.test.mjs +30 -0
  70. package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
  71. package/scripts/cm-ai-drive.mjs +335 -0
  72. package/scripts/cm-ai-drive.test.mjs +258 -0
  73. package/scripts/cm-ai-fix-integration.test.mjs +1 -1
  74. package/scripts/cm-ai-host.mjs +48 -20
  75. package/scripts/cm-ai-host.test.mjs +79 -0
  76. package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
  77. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
  78. package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
  79. package/scripts/cm-ai-review-timeout.test.mjs +30 -0
  80. package/scripts/cm-ai-run.mjs +59 -11
  81. package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
  82. package/scripts/cm-ai-session-chain.test.mjs +261 -0
  83. package/scripts/cm-ai-supersede.test.mjs +320 -0
  84. package/scripts/cm-check-drive.mjs +94 -0
  85. package/scripts/cm-check-drive.test.mjs +78 -0
  86. package/scripts/cm-check-entry.mjs +13 -2
  87. package/scripts/cm-check-host.mjs +2 -2
  88. package/scripts/cm-check-host.test.mjs +103 -0
  89. package/scripts/cm-check-runtime.sh +15 -6
  90. package/scripts/cm-claude-developer-worker.test.mjs +40 -1
  91. package/scripts/cm-claude-probe.test.mjs +117 -2
  92. package/scripts/cm-claude-review-stream.test.mjs +43 -0
  93. package/scripts/cm-fix-abandon.test.mjs +383 -0
  94. package/scripts/cm-fix-cause-package.test.mjs +31 -1
  95. package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
  96. package/scripts/cm-fix-drive.mjs +168 -0
  97. package/scripts/cm-fix-drive.test.mjs +117 -0
  98. package/scripts/cm-fix-escalation.test.mjs +214 -0
  99. package/scripts/cm-fix-execution.test.mjs +26 -0
  100. package/scripts/cm-fix-host.mjs +4 -2
  101. package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
  102. package/scripts/cm-fix-qa-source.test.mjs +3 -3
  103. package/scripts/cm-fix-session-chain.test.mjs +244 -0
  104. package/scripts/cm-fix-test-extension.test.mjs +246 -0
  105. package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
  106. package/scripts/cm-host-handoff.test.mjs +37 -0
  107. package/scripts/cm-idea-drive.mjs +99 -0
  108. package/scripts/cm-idea-drive.test.mjs +50 -0
  109. package/scripts/cm-init-drive.mjs +191 -0
  110. package/scripts/cm-init-drive.test.mjs +59 -0
  111. package/scripts/cm-log-event.mjs +9 -0
  112. package/scripts/cm-prd-completion.test.mjs +30 -2
  113. package/scripts/cm-prd-design-phase.test.mjs +355 -15
  114. package/scripts/cm-prd-drive.mjs +314 -0
  115. package/scripts/cm-prd-drive.test.mjs +164 -0
  116. package/scripts/cm-prd-host.mjs +46 -17
  117. package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
  118. package/scripts/cm-prd-review-disposition.test.mjs +133 -7
  119. package/scripts/cm-prd-review-gate.mjs +23 -4
  120. package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
  121. package/scripts/cm-prd-summary.test.mjs +79 -4
  122. package/scripts/cm-refactor-drive.mjs +237 -0
  123. package/scripts/cm-refactor-drive.test.mjs +77 -0
  124. package/scripts/cm-refactor-gaps.test.mjs +276 -0
  125. package/scripts/cm-refactor-host.test.mjs +1 -48
  126. package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
  127. package/scripts/cm-specs-status.test.mjs +19 -0
  128. package/scripts/cm-test-drive.mjs +132 -0
  129. package/scripts/cm-test-drive.test.mjs +91 -0
  130. package/scripts/cm-test-session.test.mjs +117 -0
  131. package/scripts/correction-check.test.mjs +38 -0
  132. package/scripts/fixtures/claude-model-marker.mjs +6 -0
  133. package/scripts/fixtures/claude-review-process.mjs +7 -0
  134. package/scripts/fixtures/cm-refactor.mjs +56 -0
  135. package/scripts/test-shell-compat.sh +67 -0
  136. package/skills/cm-ai/SKILL.md +1 -1
  137. package/skills/cm-ai/references/N4-review.md +2 -0
  138. package/skills/cm-ai/references/N8-finish.md +1 -0
  139. package/skills/cm-ai/references/js-host.md +85 -3
  140. package/skills/cm-check/SKILL.md +6 -1
  141. package/skills/cm-check/references/js-host.md +4 -2
  142. package/skills/cm-fix/SKILL.md +11 -4
  143. package/skills/cm-fix/references/js-host.md +67 -2
  144. package/skills/cm-fix/references/test-extension.md +57 -0
  145. package/skills/cm-idea/references/js-host.md +2 -0
  146. package/skills/cm-init/references/js-host.md +2 -0
  147. package/skills/cm-prd/SKILL.md +8 -8
  148. package/skills/cm-prd/references/js-change-recovery.md +71 -0
  149. package/skills/cm-prd/references/js-host.md +64 -2
  150. package/skills/cm-prd/references/spec-self-check.md +14 -2
  151. package/skills/cm-refactor/SKILL.md +5 -0
  152. package/skills/cm-refactor/references/js-batch.md +3 -1
  153. package/skills/cm-refactor/references/js-host.md +49 -0
  154. package/skills/cm-test/references/js-host.md +5 -0
  155. package/skills/cm-test/references/unit-coverage.md +2 -2
@@ -0,0 +1,159 @@
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 {spawnSync} from 'node:child_process';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {buildManifest} from './cm-spec-manifest.mjs';
9
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
10
+
11
+ const DRIVER=fileURLToPath(new URL('./cm-ai-batch-drive.mjs',import.meta.url));
12
+ const reviewer=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
13
+ const key='1.work/T-001';
14
+ const develop={status:'succeeded',value:{outcome:'implemented',
15
+ application:{status:'no_relevant_lesson',note:null},
16
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:{'target.mjs':'target.txt'}};
17
+
18
+ function fixture(t,count=1){
19
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-drive-')));
20
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
21
+ const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),bin=path.join(root,'bin');
22
+ fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
23
+ for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
24
+ fs.writeFileSync(path.join(specsDir,'1.work','tasks.md'),Array.from({length:count},(_,n)=>
25
+ `- [ ] T-00${n+1}: implement target ${n+1}\n`).join(''));
26
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir)}));
27
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
28
+ for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
29
+ const run=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(run.status,0,run.stderr);
30
+ }
31
+ const batch={version:1,repositoryId:'batch-drive',batchId:'batch-drive-run',specsDir,codeProject,
32
+ tasks:Array.from({length:count},(_,n)=>({feature:'1.work',taskId:`T-00${n+1}`,
33
+ scope:[n===0?'target.mjs':`target${n+1}.mjs`],requirements:['requirements.md']}))};
34
+ fs.writeFileSync(path.join(root,'batch.json'),JSON.stringify({batch,workflows:Object.fromEntries(batch.tasks.map(task=>
35
+ [`1.work/${task.taskId}`,{
36
+ documentationPaths:[],applicableAgentFiles:[],qa:{commands:[{id:'value',caseIds:[],
37
+ command:[process.execPath,'-e',"import('./target.mjs').then(m=>{if(m.value!==42)process.exit(1)})"]}],
38
+ environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}}}]))}));
39
+ fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,
40
+ cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
41
+ fs.copyFileSync(reviewer,path.join(bin,'codex'));fs.chmodSync(path.join(bin,'codex'),0o700);
42
+ const answers=path.join(root,'answers','1.work','T-001');fs.mkdirSync(answers,{recursive:true});
43
+ fs.writeFileSync(path.join(answers,'target.txt'),'export const value = 42;\n');
44
+ const write=(name,value)=>fs.writeFileSync(path.join(answers,name),JSON.stringify(value));
45
+ const plan=(extra={})=>{
46
+ const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
47
+ fs.writeFileSync(file,JSON.stringify({config:'batch.json',mode:'create',hostContext:'batch-host-a',
48
+ permissions:['--allow-qa'],answers:'answers',checks:Object.fromEntries(batch.tasks.map(task=>
49
+ [`1.work/${task.taskId}`,[{id:'syntax',command:[process.execPath,'--check',task.taskId==='T-001'?'target.mjs':'target2.mjs']}]])),...extra}));
50
+ return file;
51
+ };
52
+ const drive=(file,operation)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],{encoding:'utf8',timeout:60000,
53
+ env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),
54
+ CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
55
+ const store=path.join(specsDir,'.reviews','.execution');
56
+ return {root,answers,codeProject,specsDir,plan,drive,write,store};
57
+ }
58
+ function prepared(f){
59
+ f.write('develop.json',develop);
60
+ f.write('qa-assess.json',{scores:{scope:2,risk:2,accumulation:2,boundary:2},
61
+ changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
62
+ f.write('documentation-inspect.json',{status:'completed',reason:'README and task artifacts inspected'});
63
+ }
64
+ function noStore(f){assert.equal(fs.existsSync(f.store),false);assert.equal(fs.existsSync(path.join(f.specsDir,'运行日志.jsonl')),false);}
65
+
66
+ test('help names plan invocation',()=>{
67
+ const run=spawnSync(process.execPath,[DRIVER,'--help'],{encoding:'utf8'});
68
+ assert.equal(run.status,0);assert.match(run.stdout,/--plan PLAN\.json <operation>/);
69
+ });
70
+ test('batch driver accepts input limit as a value before host launch',t=>{
71
+ const f=fixture(t);
72
+ const run=f.drive(f.plan({permissions:['--allow-qa','--input-limit','1048576']}),'advance');
73
+ assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);
74
+ assert.doesNotMatch(run.stderr,/permissions 无效|--input-limit 文件不存在/);
75
+ noStore(f);
76
+ });
77
+ test('real batch host advances with authored edit and actual check, then resumes and reports status',t=>{
78
+ const f=fixture(t);prepared(f);
79
+ const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
80
+ assert.match(first.stderr,/应答 develop/);assert.match(first.stderr,/应答 check/);
81
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
82
+ const before=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'));
83
+ const state=path.join(f.store,fs.readdirSync(f.store).find(name=>name.startsWith('task-')),'state.json');
84
+ const stateBefore=fs.readFileSync(state);
85
+ const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a'}),'status');
86
+ assert.equal(resumed.status,0,resumed.stderr);
87
+ assert.equal(JSON.parse(resumed.stdout).result.batchId,'batch-drive-run');
88
+ assert.deepEqual(fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl')),before);
89
+ assert.deepEqual(fs.readFileSync(state),stateBefore);
90
+ const again=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a'}),'advance');
91
+ assert.equal(again.status,0,again.stderr);
92
+ });
93
+ test('real batch reaches completion with an independently dispatched fixture review',t=>{
94
+ const f=fixture(t);prepared(f);
95
+ const permissions=['--allow-qa','--review-config','review.json','--allow-review',`${key}:1`];
96
+ const first=f.drive(f.plan({permissions}),'advance');
97
+ assert.equal(first.status,0,first.stderr);assert.match(first.stderr,/应答 check/);
98
+ let result=JSON.parse(first.stdout).result;
99
+ for(let n=0;n<4&&result.state!=='run_done';n++){
100
+ const next=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a',permissions}),'advance');
101
+ assert.equal(next.status,0,next.stderr);result=JSON.parse(next.stdout).result;
102
+ }
103
+ assert.equal(result.state,'run_done',JSON.stringify(result));
104
+ });
105
+ test('missing answer leaves no batch store or session',t=>{
106
+ const f=fixture(t);const run=f.drive(f.plan(),'advance');
107
+ assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);noStore(f);
108
+ });
109
+ test('batch selection preflights the later task before launching the first',t=>{
110
+ const f=fixture(t,2);prepared(f);
111
+ const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);
112
+ assert.match(run.stderr,/任务 1\.work\/T-002 会反问 develop.*T-002\/develop\.json/s);
113
+ noStore(f);
114
+ });
115
+ test('invalid parallel selection is refused before the batch store',t=>{
116
+ const f=fixture(t,2);prepared(f);
117
+ const config=path.join(f.root,'batch.json'),bundle=JSON.parse(fs.readFileSync(config,'utf8'));
118
+ bundle.batch.parallel=[[key,'1.work/T-002']];fs.writeFileSync(config,JSON.stringify(bundle));
119
+ const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);
120
+ assert.match(run.stderr,/parallel_final_task_excluded|批次定义、scope 或 workflow 无效/);
121
+ noStore(f);
122
+ });
123
+ test('malformed authored answer is refused before launch',t=>{
124
+ const f=fixture(t);prepared(f);f.write('develop.json',{...develop,value:{outcome:'implemented'}});
125
+ const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);assert.match(run.stderr,/答案格式错误/);noStore(f);
126
+ });
127
+ test('static check cannot replace a real runner',t=>{
128
+ const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
129
+ const run=f.drive(f.plan({checks:undefined}),'advance');
130
+ assert.equal(run.status,2);assert.match(run.stderr,/PLAN\.checks/);noStore(f);
131
+ });
132
+ test('a static passed check cannot override a failed real command',t=>{
133
+ const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
134
+ const run=f.drive(f.plan({checks:{[key]:[{id:'actual',command:[process.execPath,'-e','process.exit(7)']}]}}),'advance');
135
+ assert.equal(run.status,0,run.stderr);
136
+ const files=fs.readdirSync(f.store),state=path.join(f.store,files.find(name=>name.startsWith('task-')),'state.json');
137
+ assert.match(fs.readFileSync(state,'utf8'),/host check exited 7/);
138
+ });
139
+ test('an out-of-scope edit is refused before launch',t=>{
140
+ const f=fixture(t);prepared(f);f.write('develop.json',{...develop,edits:{'outside.mjs':'target.txt'}});
141
+ const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);assert.match(run.stderr,/越过批准 scope: outside\.mjs/);noStore(f);
142
+ });
143
+ test('verification evidence kind requires a real runner',t=>{
144
+ const f=fixture(t);prepared(f);f.write('verification-precheck.json',{satisfied:true,evidence:'static'});
145
+ const run=f.drive(f.plan({permissions:['--allow-qa','--verification-precheck']}),'advance');
146
+ assert.equal(run.status,2);assert.match(run.stderr,/verification_precheck/);noStore(f);
147
+ });
148
+ test('QA logic evidence cannot be supplied as a static answer',t=>{
149
+ const f=fixture(t);prepared(f);
150
+ fs.writeFileSync(path.join(f.specsDir,'1.work','test-cases.json'),JSON.stringify({cases:[{kind:'logic',id:'CASE-1'}]}));
151
+ f.write('qa-logic.json',{verdict:'PASS',evidence:['static claim']});
152
+ const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);
153
+ assert.match(run.stderr,/qa_logic/);noStore(f);
154
+ });
155
+ test('resume binding is required before launch',t=>{
156
+ const f=fixture(t);prepared(f);
157
+ const run=f.drive(f.plan({mode:'resume'}),'advance');assert.equal(run.status,2);
158
+ assert.match(run.stderr,/originalHostContext/);noStore(f);
159
+ });
@@ -9,13 +9,17 @@ import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
9
9
  import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
10
10
  import {claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
11
11
  import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
12
- import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
12
+ import {serveCmAiHost,parseHostInputLimit} from '../runtime/js/cm-ai/host-session.mjs';
13
13
  import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
14
14
  import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
15
15
 
16
- const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development [--runtime codex|claude] [--review-config PATH] [--allow-review FEATURE/TASK:1|2]... [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa] [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]...';
16
+ const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development [--runtime codex|claude] [--input-limit BYTES] [--review-config PATH] [--allow-review FEATURE/TASK:1|2]... [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa] [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]...';
17
17
  const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
18
18
 
19
+ export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
20
+ return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
21
+ }
22
+
19
23
  async function memberReviewConfiguration(batch,definition,review,runtime){
20
24
  try{
21
25
  need(review!==null,'review_configuration_required');
@@ -44,7 +48,7 @@ async function memberReviewConfiguration(batch,definition,review,runtime){
44
48
  }
45
49
 
46
50
  export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
47
- if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nOptional --protected-conversation-config PATH uses the shared current-host scoped text proposals and native sandbox checks; {checkCommands,timeoutMs}. No extra model call, same Codex/Claude runtime and per-task Review permissions. Optional --protected-config PATH {model,checkCommands,timeoutMs} enables CLI development only for per-task --allow-provider-development FEATURE/TASK:1|2 grants; mutually exclusive with --protected-conversation-config. Optional bundle.bootstraps maps approved bootstrap task keys to {selection}; --allow-bootstrap-write grants only those fixed instruction/scaffold steps. Optional batch.codeProjects uses prefixed paths and checks with codeProject per command; one task remains one completion gate.\nOptional --review-config PATH is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000). It is independent of --protected-conversation-config/--protected-config and wins over their timeoutMs for the reviewer, so a review that exceeds the default can be raised without switching development mode. It is not part of the authorized configuration digest, so a resumed run may raise it after review_transport_timeout.\nOptional --rerun-unknown-qa / --rerun-blocked-qa carry the same single-task QA recovery into a batch and require --allow-qa; they are mutually exclusive. A batch has no --mode, so each task applies the flag only when it resumes an existing run and has a QA executor; a created run or a task without QA ignores it rather than failing the whole batch. Semantics, limits and the qaRound cap are the single-task ones, unchanged.\nOptional --verification-precheck sends the written verification of the task and the collected checks back as a verification_precheck request before any handoff or review package is built. It may only block: a requirement reported unsatisfied stops the task at blocked / verification_precheck_failed with pendingAction resume and spends no review round. Passing it is not an approval, writes no receipt and does not replace the independent review. A task with no written verification is unaffected.\nBatch entry requires a clean Git main checkout (including untracked files); batch_main_dirty lists dirty files before any task or worktree starts. Serial tasks are committed automatically before batch_handoff, with task_commit recording the SHA (null if unchanged). Terminal parallel members preserve WIP on their retained branches and fall back once to serial generation 2 after ready members merge.\n');return 0;}
51
+ if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nOptional --input-limit BYTES sets the host input transport limit to an integer from 65536 to 4194304 (default 65536); it may change on resume.\nOptional --protected-conversation-config PATH uses the shared current-host scoped text proposals and native sandbox checks; {checkCommands,timeoutMs}. No extra model call, same Codex/Claude runtime and per-task Review permissions. Optional --protected-config PATH {model,checkCommands,timeoutMs} enables CLI development only for per-task --allow-provider-development FEATURE/TASK:1|2 grants; mutually exclusive with --protected-conversation-config. Optional bundle.bootstraps maps approved bootstrap task keys to {selection}; --allow-bootstrap-write grants only those fixed instruction/scaffold steps. Optional batch.codeProjects uses prefixed paths and checks with codeProject per command; one task remains one completion gate.\nOptional --review-config PATH is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000). It is independent of --protected-conversation-config/--protected-config and wins over their timeoutMs for the reviewer, so a review that exceeds the default can be raised without switching development mode. It is not part of the authorized configuration digest, so a resumed run may raise it after review_transport_timeout.\nOptional --rerun-unknown-qa / --rerun-blocked-qa carry the same single-task QA recovery into a batch and require --allow-qa; they are mutually exclusive. A batch has no --mode, so each task applies the flag only when it resumes an existing run and has a QA executor; a created run or a task without QA ignores it rather than failing the whole batch. Semantics, limits and the qaRound cap are the single-task ones, unchanged.\nOptional --verification-precheck sends the written verification of the task and the collected checks back as a verification_precheck request before any handoff or review package is built. It may only block: a requirement reported unsatisfied stops the task at blocked / verification_precheck_failed with pendingAction resume and spends no review round. Passing it is not an approval, writes no receipt and does not replace the independent review. A task with no written verification is unaffected.\nBatch entry requires a clean Git main checkout (including untracked files); batch_main_dirty lists dirty files before any task or worktree starts. Serial tasks are committed automatically before batch_handoff, with task_commit recording the SHA (null if unchanged). Terminal parallel members preserve WIP on their retained branches and fall back once to serial generation 2 after ready members merge.\n');return 0;}
48
52
  let bridge;
49
53
  try{
50
54
  need(argv.length>=6&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--host-context'
@@ -62,7 +66,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
62
66
  }
63
67
  need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
64
68
  for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
65
- let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag;
69
+ let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
66
70
  let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map();
67
71
  for(let index=6;index<argv.length;index++){
68
72
  const name=argv[index];
@@ -92,6 +96,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
92
96
  else if(name==='--runtime'){
93
97
  need(runtime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');runtime=argv[++index];
94
98
  }
99
+ else if(name==='--input-limit'){
100
+ need(inputLimitRaw===undefined&&typeof argv[index+1]==='string','invalid_arguments');
101
+ inputLimitRaw=argv[++index];parseHostInputLimit(inputLimitRaw);
102
+ }
95
103
  else if(name==='--review-config'){need(review===null&&typeof argv[index+1]==='string','invalid_arguments');review=readConversationReviewConfiguration(argv[++index]);}
96
104
  else if(name==='--allow-review'){
97
105
  const approval=argv[++index];need(typeof approval==='string'&&!approvals.has(approval),'invalid_arguments');
@@ -142,7 +150,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
142
150
  try{return await driver.handle(request);}catch(cause){return {outcome:'blocked',code:safeCode(cause)};}
143
151
  }};
144
152
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
145
- try{await serveCmAiHost({host,input,output,toolBridge:bridge});}
153
+ try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
146
154
  finally{if(rawMode)input.setRawMode(false);}
147
155
  return 0;
148
156
  }catch(cause){error.write(JSON.stringify({error:{code:safeCode(cause)}})+'\n');return 1;}
@@ -11,6 +11,29 @@ import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
11
11
  import {buildManifest} from './cm-spec-manifest.mjs';
12
12
 
13
13
  const cli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
14
+ test('batch host input limit reaches transport without opening a host',async()=>{
15
+ const {serveHostTransport}=await import('./cm-ai-batch-host.mjs');
16
+ assert.equal(typeof serveHostTransport,'function');
17
+ let seen;
18
+ await serveHostTransport({host:{}},'1048576',async options=>{seen=options.inputLimit;});
19
+ assert.equal(seen,1048576);
20
+ for(const raw of ['65535','4194305','1.5'])
21
+ await assert.rejects(serveHostTransport({host:{}},raw,async()=>{}),/invalid_arguments/);
22
+ });
23
+ test('batch host help documents input limit',()=>{
24
+ const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
25
+ assert.equal(help.status,0);assert.match(help.stdout,/--input-limit BYTES/);
26
+ });
27
+ test('batch host CLI rejects out-of-range and non-integer input limits before opening a run',()=>{
28
+ const f=fixture();
29
+ try{
30
+ for(const raw of ['65535','4194305','1.5']){
31
+ const run=spawnSync(process.execPath,[cli,...f.args,'--input-limit',raw],{encoding:'utf8'});
32
+ assert.equal(run.status,1);assert.match(run.stderr,/invalid_arguments/);
33
+ assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews')),false);
34
+ }
35
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
36
+ });
14
37
  function fixture(runtime='codex'){
15
38
  const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-host-')));
16
39
  const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',bin=path.join(root,'bin');
@@ -233,10 +256,12 @@ test('provider development grants select worktree runtimes and keep the serial t
233
256
  const protectedFile=path.join(f.root,'protected.json');fs.writeFileSync(protectedFile,JSON.stringify(protection));
234
257
  const stub=path.join(f.root,'stub.mjs'),host=path.join(f.root,'batch-host.mjs');
235
258
  const hostModule=new URL('./cm-ai-host.mjs',import.meta.url).href;
259
+ const sessionModule=new URL('../runtime/js/cm-ai/host-session.mjs',import.meta.url).href;
236
260
  const workerModule=new URL('../runtime/js/cm-ai/codex-config.mjs',import.meta.url).href;
237
261
  fs.writeFileSync(stub,`
238
262
  import {configFingerprint} from ${JSON.stringify(workerModule)};
239
263
  export {readConversationReviewConfiguration,readConversationProtection} from ${JSON.stringify(hostModule)};
264
+ export {parseHostInputLimit} from ${JSON.stringify(sessionModule)};
240
265
  export const calls=[];export let scheduler;
241
266
  export function createConversationExecution(...args){calls.push(args);return {};}
242
267
  export async function runReviewPreflight(definition,{model}){return {model,disabledSkills:[],preflight:{passed:true,
@@ -0,0 +1,30 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {createRun,transition,restoreRun} from '../runtime/js/cm-ai/contracts.mjs';
4
+
5
+ const definition={runId:'state-fixture',fingerprint:'source-config',scope:'synthetic',
6
+ steps:[{id:'first',requiresApproval:true}]};
7
+ const identity={runId:definition.runId,fingerprint:definition.fingerprint,scope:definition.scope,
8
+ stepId:'first',attempt:1,requestHash:'request-first'};
9
+ const event=(id,type,extra={})=>({id,type,...identity,...extra});
10
+ const host={source:'host',now:10};
11
+
12
+ test('restoreRun accepts active, waiting_user, deny and revoked states but rejects an unknown decision',()=>{
13
+ const active=createRun(definition);
14
+ const waiting=transition(active,event('ask','request_decision',{requestId:'decision-1',expiresAt:20}),host).state;
15
+ const approved=transition(waiting,event('approve','decision',{requestId:'decision-1',decision:'approve'}),host).state;
16
+ const denied=transition(waiting,event('deny','decision',{requestId:'decision-1',decision:'deny'}),host).state;
17
+ const revoked=transition(approved,event('revoke','revoke'),host).state;
18
+ for(const [name,snapshot,runStatus,stepStatus,decision] of [
19
+ ['active',active,'active','pending',null],
20
+ ['waiting_user',waiting,'active','waiting_user','waiting'],
21
+ ['deny',denied,'blocked','blocked','deny'],
22
+ ['revoked',revoked,'blocked','blocked','revoked']]){
23
+ const restored=restoreRun(snapshot,definition);
24
+ assert.equal(restored.status,runStatus,name);
25
+ assert.equal(restored.steps[0].status,stepStatus,name);
26
+ assert.equal(restored.steps[0].approval?.decision??null,decision,name);
27
+ }
28
+ const invalid=structuredClone(denied);invalid.steps[0].approval.decision='not_a_decision';
29
+ assert.throws(()=>restoreRun(invalid,definition),/invalid_snapshot/);
30
+ });
@@ -0,0 +1,62 @@
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 {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
7
+ import {recordCmAiQaDecision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
8
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
9
+
10
+ const identity={repositoryId:'fixture',runId:'conversation-ops',taskId:'T-001',attempt:1};
11
+ const packageDigest='8'.repeat(64);
12
+ const operation=(name,requestId=name)=>({version:1,operation:name,requestId,identity,packageDigest,testRunId:null});
13
+
14
+ async function fixture(run){
15
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-conversation-ops-')));
16
+ const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.login';
17
+ fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
18
+ fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Requirements\n');
19
+ fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Design\n');
20
+ fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: finished\n');
21
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
22
+ fs.writeFileSync(path.join(codeProject,'README.md'),'existing project\n');
23
+ let current={state:'ready',code:null,identity,packageDigest},effects=0;
24
+ const runner={status:()=>current,executeEffect:async()=>{effects++;throw Error('unexpected runner effect');},
25
+ cancel:()=>current,run:async()=>current};
26
+ const entry=extra=>createCmAiConversationEntry({specsDir,codeProject,feature,identity,runner,
27
+ applicableAgentFiles:[],...extra});
28
+ const complete=()=>{current={...current,state:'fixture_completed'};};
29
+ const seedQa=()=>recordCmAiQaDecision({specsDir,codeProject,feature,identity,packageDigest,
30
+ logHome:path.join(root,'logs'),decision:{decisionId:'qa-skipped',identity,packageDigest,
31
+ status:'skipped',reason:'fixture',score:4,at:'2026-09-04T15:10:00-07:00'}});
32
+ try{return await run({root,specsDir,codeProject,entry,complete,seedQa,effects:()=>effects});}
33
+ finally{fs.rmSync(root,{recursive:true,force:true});}
34
+ }
35
+
36
+ test('context_refresh requires a completed task and returns its bound context summary',()=>fixture(async f=>{
37
+ const request=operation('context_refresh');
38
+ assert.equal((await f.entry().handle(request)).code,'context_not_ready');
39
+ f.complete();f.seedQa();
40
+ const result=await f.entry().handle(request);
41
+ assert.deepEqual(result,{version:1,workflow:'cm-ai',operation:'context_refresh',requestDigest:digest(request),
42
+ identity,outcome:'refreshed',state:'fixture_completed',code:'context_complete',packageDigest,
43
+ pendingAction:'finish',nextTask:null,contextDigest:result.contextDigest,contextFiles:result.contextFiles});
44
+ assert.match(result.contextDigest,/^[a-f0-9]{64}$/);
45
+ assert.deepEqual(result.contextFiles.map(file=>file.path),[
46
+ '1.login/design.md','1.login/requirements.md','1.login/tasks.md']);
47
+ assert.equal(f.effects(),0);
48
+ }));
49
+
50
+ test('run_finalize requires documentation sync and returns the final outcome without runner effects',()=>fixture(async f=>{
51
+ f.complete();f.seedQa();
52
+ const refresh=await f.entry().handle(operation('context_refresh'));
53
+ const request=operation('run_finalize');
54
+ assert.equal((await f.entry().handle(request)).code,'run_not_ready');
55
+ const documentationResult={syncId:'docs-completed',identity,packageDigest,contextDigest:refresh.contextDigest,
56
+ status:'completed',reason:'documentation synced',at:'2026-09-04T15:20:00-07:00'};
57
+ const result=await f.entry({documentationResult,qaLogHome:path.join(f.root,'logs')}).handle(request);
58
+ assert.deepEqual(result,{version:1,workflow:'cm-ai',operation:'run_finalize',requestDigest:digest(request),
59
+ identity,outcome:'finalized',state:'run_done',code:'run_done',packageDigest,pendingAction:'none',
60
+ contextDigest:refresh.contextDigest,deduplicated:false,degraded:false});
61
+ assert.equal(f.effects(),0);
62
+ }));