@aibyzero/cm-workflow 0.13.3 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +34 -1
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +55 -0
  7. package/docs/user-guide.md +3 -0
  8. package/package.json +1 -1
  9. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +1 -0
  10. package/runtime/js/cm-ai/cm-ai-admission.mjs +53 -22
  11. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +4 -5
  12. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +40 -17
  13. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +103 -23
  14. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -4
  15. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +5 -2
  16. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  17. package/runtime/js/cm-ai/developer-adapter.mjs +17 -5
  18. package/runtime/js/cm-ai/durable-runner-state.mjs +7 -2
  19. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  20. package/runtime/js/cm-ai/execution-store.mjs +25 -5
  21. package/runtime/js/cm-ai/host-check.mjs +20 -1
  22. package/runtime/js/cm-ai/host-conversation-execution.mjs +5 -4
  23. package/runtime/js/cm-ai/host-documentation.mjs +2 -2
  24. package/runtime/js/cm-ai/host-qa-executor.mjs +46 -24
  25. package/runtime/js/cm-ai/host-qa-policy.mjs +3 -1
  26. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +41 -3
  27. package/runtime/js/cm-ai/qa-environment.mjs +22 -0
  28. package/runtime/js/cm-ai/task-runner.mjs +1 -0
  29. package/runtime/js/cm-ai/worker-claude-developer.mjs +2 -1
  30. package/runtime/js/cm-fix/cause-package.mjs +3 -1
  31. package/runtime/js/cm-fix/dossier.mjs +7 -2
  32. package/runtime/js/cm-fix/reproduce.mjs +26 -5
  33. package/runtime/js/cm-fix/visual.mjs +3 -2
  34. package/runtime/js/cm-fix/walkthrough.mjs +2 -1
  35. package/runtime/js/cm-init/draft-generation.mjs +3 -2
  36. package/runtime/js/cm-init/draft-inspection.mjs +17 -3
  37. package/runtime/js/cm-init/review-evidence.mjs +1 -1
  38. package/runtime/js/cm-prd/summary.mjs +6 -8
  39. package/runtime/js/cm-security/finalize.mjs +164 -0
  40. package/runtime/js/cm-test/host.mjs +2 -2
  41. package/runtime/js/specs-status.mjs +66 -0
  42. package/runtime/project-context.md +4 -1
  43. package/scripts/cm-ai-admission.mjs +46 -7
  44. package/scripts/cm-ai-admission.test.mjs +50 -0
  45. package/scripts/cm-ai-batch-host.mjs +72 -10
  46. package/scripts/cm-ai-batch-host.test.mjs +128 -4
  47. package/scripts/cm-ai-batch-run.mjs +366 -17
  48. package/scripts/cm-ai-batch-run.test.mjs +222 -13
  49. package/scripts/cm-ai-bootstrap.test.mjs +3 -2
  50. package/scripts/cm-ai-host.mjs +38 -21
  51. package/scripts/cm-ai-host.test.mjs +68 -4
  52. package/scripts/cm-ai-nested-execution.test.mjs +1 -1
  53. package/scripts/cm-ai-run.mjs +25 -15
  54. package/scripts/cm-ai-run.test.mjs +48 -0
  55. package/scripts/cm-blocked-reason.test.mjs +104 -0
  56. package/scripts/cm-capability-gate.test.mjs +179 -0
  57. package/scripts/cm-check-update.mjs +5 -2
  58. package/scripts/cm-check-update.test.mjs +21 -0
  59. package/scripts/cm-codex-developer-adapter.test.mjs +70 -0
  60. package/scripts/cm-fix-cause-package.test.mjs +18 -1
  61. package/scripts/cm-fix-execution.test.mjs +31 -0
  62. package/scripts/cm-fix-host-review.test.mjs +2 -1
  63. package/scripts/cm-fix-host.test.mjs +2 -1
  64. package/scripts/cm-fix-observation-dossier.test.mjs +2 -0
  65. package/scripts/cm-fix-qa-source.test.mjs +1 -3
  66. package/scripts/cm-fix-reproduce.test.mjs +53 -2
  67. package/scripts/cm-fix-review-recovery.test.mjs +4 -3
  68. package/scripts/cm-host-check.test.mjs +22 -0
  69. package/scripts/cm-host-qa-executor.test.mjs +302 -3
  70. package/scripts/cm-host-qa-policy.test.mjs +34 -0
  71. package/scripts/cm-init-draft-generation.test.mjs +24 -3
  72. package/scripts/cm-init-draft-inspection.test.mjs +80 -0
  73. package/scripts/cm-init-host.mjs +2 -2
  74. package/scripts/cm-init-host.test.mjs +3 -1
  75. package/scripts/cm-init-session.test.mjs +37 -0
  76. package/scripts/cm-log-event.mjs +28 -7
  77. package/scripts/cm-prd-design-phase.test.mjs +2 -1
  78. package/scripts/cm-prd-host.test.mjs +3 -2
  79. package/scripts/cm-prd-session-recovery.test.mjs +5 -4
  80. package/scripts/cm-qa-environment.test.mjs +30 -0
  81. package/scripts/cm-security.mjs +12 -4
  82. package/scripts/cm-security.test.mjs +109 -0
  83. package/scripts/cm-specs-status.test.mjs +130 -0
  84. package/scripts/cm-workflow-config.mjs +4 -0
  85. package/scripts/test-shell-compat.sh +0 -0
  86. package/skills/cm-ai/references/N1-init.md +22 -15
  87. package/skills/cm-ai/references/N5-mark-done.md +5 -2
  88. package/skills/cm-ai/references/N6-qa-eval.md +9 -4
  89. package/skills/cm-ai/references/js-host.md +25 -0
  90. package/skills/cm-fix/SKILL.md +5 -4
  91. package/skills/cm-fix/references/js-host.md +13 -0
  92. package/skills/cm-idea/SKILL.md +2 -0
  93. package/skills/cm-init/references/runtime-declaration.md +2 -0
  94. package/skills/cm-prd/SKILL.md +9 -8
  95. package/skills/cm-prd/references/spec-self-check.md +1 -0
  96. package/skills/cm-security/SKILL.md +14 -7
  97. package/skills/cm-security/references/scan-contract.md +45 -1
  98. package/skills/cm-test/references/js-host.md +4 -3
  99. package/templates/dashboard/dashboard.html +2 -2
@@ -4,7 +4,8 @@ import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import {spawn,spawnSync} from 'node:child_process';
7
- import {fileURLToPath} from 'node:url';
7
+ import {fileURLToPath,pathToFileURL} from 'node:url';
8
+ import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
8
9
  import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
9
10
  import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
10
11
  import {buildManifest} from './cm-spec-manifest.mjs';
@@ -18,6 +19,9 @@ function fixture(runtime='codex'){
18
19
  fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n');
19
20
  fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
20
21
  fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Two synthetic exports and README\n');
22
+ for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','fixture baseline']]){
23
+ const result=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(result.status,0,result.stderr);
24
+ }
21
25
  const batch={version:1,repositoryId:'batch-host',batchId:'batch-host-run',specsDir,codeProject,
22
26
  tasks:[1,2].map(n=>({feature,taskId:`T-00${n}`,scope:[`task${n}.mjs`,...(n===2?['README.md']:[])],requirements:['requirements.md']}))};
23
27
  const workflows=Object.fromEntries(batch.tasks.map((task,index)=>[`${feature}/${task.taskId}`,{
@@ -41,7 +45,7 @@ function execute(f,approvals,{cancel=false}={}){
41
45
  const child=spawn(process.execPath,[cli,...f.args,...approvals.flatMap(value=>['--allow-review',value])],
42
46
  {env:f.env,stdio:['pipe','pipe','pipe']});
43
47
  let buffer='',stderr='',sessionId;const calls=[],rows=[];
44
- const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('batch host timeout'));},15000);
48
+ const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('batch host timeout'));},Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
45
49
  child.stderr.on('data',part=>{stderr+=part;});child.once('error',reject);
46
50
  const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
47
51
  const respond=(row,result)=>send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
@@ -54,6 +58,8 @@ function execute(f,approvals,{cancel=false}={}){
54
58
  if(row.type==='host_ready')sessionId=row.sessionId;
55
59
  if(row.type==='host_request'){
56
60
  const payload=row.payload,identity=payload.identity??payload.request.identity;
61
+ const cwd=f.parallel&&identity.taskId!=='T-003'
62
+ ?path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),identity.taskId):f.codeProject;
57
63
  calls.push(`${identity.taskId}:${row.kind}`);
58
64
  if(cancel){send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
59
65
  if(row.kind==='develop'){
@@ -63,14 +69,14 @@ function execute(f,approvals,{cancel=false}={}){
63
69
  assert.equal(payload.request.payload.specification.task.id,identity.taskId);
64
70
  assert.deepEqual(payload.request.payload.specification.sources,buildManifest(f.specsDir));
65
71
  const content=`export const value = ${40+n};\n`;
66
- if(!f.protected)fs.writeFileSync(path.join(f.codeProject,`task${n}.mjs`),content);
72
+ if(!f.protected)fs.writeFileSync(path.join(cwd,`task${n}.mjs`),content);
67
73
  respond(row,{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
68
74
  retrospective:{status:'no_new_lesson',candidates:[],reason:null}},...(f.protected?{edits:
69
75
  payload.request.payload.scope.map(file=>({path:file,beforeSha256:payload.expected[file],
70
76
  content:file==='README.md'?'# Exports 41 and 42\n':content}))}:{})});
71
77
  }else if(row.kind==='check'){
72
78
  const checks=payload.scope.filter(file=>file.endsWith('.mjs')).map(file=>{
73
- const command=[process.execPath,'--check',path.join(f.codeProject,file)];
79
+ const command=[process.execPath,'--check',path.join(cwd,file)];
74
80
  const result=spawnSync(command[0],command.slice(1));assert.equal(result.status,0);
75
81
  return {id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Actual Node syntax check exited 0'};
76
82
  });respond(row,checks);
@@ -100,6 +106,10 @@ test('protected Claude batch uses actual sandbox edits/checks and original two-t
100
106
  const f=fixture('claude');f.protected=true;
101
107
  try{
102
108
  const nested=path.join(f.codeProject,'specs');fs.renameSync(f.specsDir,nested);f.specsDir=nested;f.batch.specsDir=nested;
109
+ fs.writeFileSync(path.join(f.codeProject,'.gitignore'),'specs/\n');
110
+ for(const args of [['add','.gitignore'],['commit','-m','ignore nested runtime specs']]){
111
+ const result=spawnSync('git',['-C',f.codeProject,...args],{encoding:'utf8'});assert.equal(result.status,0,result.stderr);
112
+ }
103
113
  const bundle=JSON.parse(fs.readFileSync(f.config,'utf8'));bundle.batch=f.batch;fs.writeFileSync(f.config,JSON.stringify(bundle));
104
114
  const protection=path.join(f.root,'protection.json');
105
115
  fs.writeFileSync(protection,JSON.stringify({timeoutMs:5000,checkCommands:[{id:'syntax',command:[process.execPath,'-e',
@@ -156,3 +166,117 @@ for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation
156
166
  const reopened=await execute(f,[]);assert.equal(reopened.result.code,'cancelled');assert.deepEqual(reopened.calls,[]);
157
167
  }finally{fs.rmSync(f.root,{recursive:true,force:true});}
158
168
  });
169
+
170
+
171
+ test('parallel member loopback preflights bind worktree cwd, stop before start and reuse on resume',async()=>{
172
+ const f=fixture();f.parallel=true;
173
+ try{
174
+ f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
175
+ f.batch.parallel=[['1.work/T-001','1.work/T-002']];
176
+ fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
177
+ fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
178
+ const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
179
+ fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
180
+ const git=args=>{const result=spawnSync('git',['-C',f.codeProject,...args],{encoding:'utf8'});assert.equal(result.status,0,result.stderr);};
181
+ git(['init','-b','main']);git(['config','user.name','Fixture']);git(['config','user.email','fixture@example.invalid']);
182
+ git(['add','-A']);git(['commit','--allow-empty','-m','synthetic baseline']);
183
+ const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
184
+ fs.writeFileSync(fail,'fail second member');
185
+ const processFixture=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
186
+ fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
187
+ const fs=require('node:fs'),cp=require('node:child_process');
188
+ const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
189
+ fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
190
+ if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
191
+ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
192
+ const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
193
+ process.stdout.write(result.stdout??'');process.stderr.write(result.stderr??'');process.exit(result.status??1);
194
+ });
195
+ `,{mode:0o700});
196
+ const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
197
+ const failed=await execute(f,['1.work/T-001:1','1.work/T-002:1']);
198
+ assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
199
+ assert.equal(failed.result.currentTask,'1.work/T-002');assert.deepEqual(failed.calls,[]);
200
+ assert.equal(probes().length,2);
201
+ fs.unlinkSync(fail);
202
+ const first=await execute(f,[]);assert.equal(first.result.code,'decision_required',JSON.stringify(first));
203
+ assert.equal(first.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(first));
204
+ const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
205
+ const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
206
+ for(const [index,bytes] of receipts.entries()){
207
+ const config=JSON.parse(bytes),cwd=path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),`T-00${index+1}`);
208
+ assert(preflightMatches(config.preflight,{cwd,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
209
+ assert(!preflightMatches(config.preflight,{cwd:f.codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
210
+ assert.equal(config.preflight.real_model_requests,0);assert.equal(config.preflight.listener_closed,true);
211
+ assert(probes().includes(cwd));
212
+ }
213
+ assert.equal(probes().length,3);
214
+ const resumed=await execute(f,[]);assert.equal(resumed.result.code,'decision_required');assert.deepEqual(resumed.calls,[]);
215
+ assert.equal(probes().length,3);
216
+ assert.deepEqual([1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8')),receipts);
217
+ const stale=JSON.parse(receipts[1]);stale.preflight.config_fingerprint='0'.repeat(64);
218
+ fs.writeFileSync(path.join(directory,'preflight-T-002.json'),JSON.stringify(stale));
219
+ const refreshed=await execute(f,[]);assert.equal(refreshed.result.code,'decision_required');assert.deepEqual(refreshed.calls,[]);
220
+ assert.equal(probes().length,4);
221
+ assert.equal(fs.readFileSync(path.join(directory,'preflight-T-002.json'),'utf8'),receipts[1]);
222
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
223
+ });
224
+
225
+ test('provider development grants select worktree runtimes and keep the serial task on protected conversation transport',async()=>{
226
+ const f=fixture();
227
+ try{
228
+ const worktree=path.join(f.root,'member');fs.mkdirSync(worktree);
229
+ fs.writeFileSync(path.join(worktree,'.cm-workflow.yml'),
230
+ 'version: 1\nruntimes:\n available: both\nroles:\n coder:\n adapter: claude-cli\n reviewer:\n adapter: codex-cli\n');
231
+ fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),'version: 1\nruntimes:\n available: codex\n');
232
+ const protection={model:'fixture-coder',checkCommands:[{id:'syntax',command:[process.execPath,'--check','task1.mjs']}],timeoutMs:12345};
233
+ const protectedFile=path.join(f.root,'protected.json');fs.writeFileSync(protectedFile,JSON.stringify(protection));
234
+ const stub=path.join(f.root,'stub.mjs'),host=path.join(f.root,'batch-host.mjs');
235
+ const hostModule=new URL('./cm-ai-host.mjs',import.meta.url).href;
236
+ const workerModule=new URL('../runtime/js/cm-ai/codex-config.mjs',import.meta.url).href;
237
+ fs.writeFileSync(stub,`
238
+ import {configFingerprint} from ${JSON.stringify(workerModule)};
239
+ export {readConversationReviewConfiguration,readConversationProtection} from ${JSON.stringify(hostModule)};
240
+ export const calls=[];export let scheduler;
241
+ export function createConversationExecution(...args){calls.push(args);return {};}
242
+ export async function runReviewPreflight(definition,{model}){return {model,disabledSkills:[],preflight:{passed:true,
243
+ cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:definition.codeProject,model})}};}
244
+ export function createCmAiBatch(options){scheduler=options;return {async handle(){
245
+ for(const [index,task] of options.configuration.tasks.entries())await options.executionFor({feature:task.feature,
246
+ identity:{taskId:task.taskId},codeProject:index===0?${JSON.stringify(worktree)}:options.configuration.codeProject},
247
+ {parallelMember:index===0});return {};}};}
248
+ export async function serveCmAiHost({host}){await host.handle({});}
249
+ `);
250
+ // Keep production parsing and executionFor intact; capture the factory boundary without launching a CLI.
251
+ const stubUrl=pathToFileURL(stub).href;
252
+ const source=fs.readFileSync(cli,'utf8').replace(/from '([^']+)'/g,(match,specifier)=>{
253
+ if(['./cm-ai-batch-run.mjs','./cm-ai-host.mjs','../runtime/js/cm-ai/host-session.mjs'].includes(specifier))return `from '${stubUrl}'`;
254
+ return specifier.startsWith('.')?`from '${new URL(specifier,new URL('./cm-ai-batch-host.mjs',import.meta.url)).href}'`:match;
255
+ });
256
+ fs.writeFileSync(host,source);
257
+ const {main}=await import(pathToFileURL(host).href),capture=await import(stubUrl);
258
+ let stderr='';const io={input:{},output:{write(){}},error:{write(value){stderr+=value;}}};
259
+ const args=[...f.args,'--protected-config',protectedFile,'--allow-provider-development','1.work/T-001:2'];
260
+ assert.equal(await main(args,io),0,stderr);
261
+ assert.equal(capture.calls.length,2);
262
+ const member=capture.calls[0][8],serial=capture.calls[1][8];
263
+ assert.equal(member.parallelMember,true);
264
+ assert.deepEqual(member.protection,{checkCommands:protection.checkCommands,timeoutMs:12345});
265
+ assert.deepEqual(member.providerDevelopment,{model:'fixture-coder',attempt:2,coderRuntime:'claude',reviewerRuntime:'codex'});
266
+ assert.equal(serial.parallelMember,false);
267
+ assert.deepEqual(serial.protection,{checkCommands:protection.checkCommands,timeoutMs:12345});
268
+ assert.equal(Object.hasOwn(serial,'providerDevelopment'),false);
269
+ assert.deepEqual(capture.scheduler.checkCommands,protection.checkCommands);
270
+ assert.equal(capture.scheduler.checkTimeoutMs,12345);
271
+ for(const extra of [
272
+ ['--allow-provider-development','1.work/T-001:1'],
273
+ ['--allow-provider-development','1.work/T-999:1'],
274
+ ['--allow-provider-development','1.work/T-002:3'],
275
+ ['--protected-conversation-config',protectedFile],
276
+ ]){
277
+ stderr='';assert.equal(await main([...args,...extra],io),1);
278
+ assert.equal(JSON.parse(stderr).error.code,'invalid_arguments');
279
+ assert.equal(capture.calls.length,2);
280
+ }
281
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
282
+ });