@aibyzero/cm-workflow 0.16.7 → 0.16.8

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 (58) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/README.md +26 -1
  4. package/VERSION +1 -1
  5. package/assets/readme/workflow-recovery-detailed.png +0 -0
  6. package/assets/readme/workflow-stages-detailed.png +0 -0
  7. package/docs/installation.md +1 -1
  8. package/docs/js-workflow-control.md +36 -3
  9. package/docs/user-guide.md +104 -0
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/cm-ai-admission.mjs +3 -1
  12. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +27 -6
  13. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +82 -8
  14. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
  15. package/runtime/js/cm-ai/drive-core.mjs +17 -4
  16. package/runtime/js/cm-ai/execution-store.mjs +4 -2
  17. package/runtime/js/cm-ai/host-qa-executor.mjs +37 -13
  18. package/runtime/js/cm-ai/host-session.mjs +46 -6
  19. package/runtime/js/cm-ai/host-tool-bridge.mjs +15 -3
  20. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
  21. package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
  22. package/runtime/js/cm-fix/cause-package.mjs +37 -8
  23. package/runtime/js/cm-fix/diagnosis.mjs +43 -0
  24. package/runtime/js/cm-fix/execution.mjs +189 -148
  25. package/runtime/js/cm-fix/investigation.mjs +25 -9
  26. package/runtime/js/cm-fix/progress.mjs +3 -1
  27. package/runtime/js/notify-run.mjs +26 -0
  28. package/runtime/js/notify.mjs +388 -0
  29. package/runtime/model-efficiency.md +17 -0
  30. package/scripts/cm-ai-batch-run.mjs +5 -0
  31. package/scripts/cm-ai-batch-run.test.mjs +9 -1
  32. package/scripts/cm-ai-drive.mjs +4 -1
  33. package/scripts/cm-ai-drive.test.mjs +8 -0
  34. package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
  35. package/scripts/cm-ai-host.mjs +2 -2
  36. package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
  37. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +77 -4
  38. package/scripts/cm-fix-abandon.test.mjs +89 -3
  39. package/scripts/cm-fix-cause-package.test.mjs +33 -0
  40. package/scripts/cm-fix-drive.mjs +9 -1
  41. package/scripts/cm-fix-host.mjs +1 -1
  42. package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
  43. package/scripts/cm-host-qa-executor.test.mjs +121 -0
  44. package/scripts/cm-log-event.mjs +31 -5
  45. package/scripts/cm-notify.test.mjs +468 -0
  46. package/scripts/cm-patrol.mjs +83 -0
  47. package/scripts/cm-patrol.test.mjs +161 -0
  48. package/scripts/cm-token-report.mjs +497 -0
  49. package/scripts/cm-token-report.test.mjs +346 -0
  50. package/skills/cm-ai/SKILL.md +7 -3
  51. package/skills/cm-ai/references/N6-qa-eval.md +2 -2
  52. package/skills/cm-ai/references/js-host-modes.md +90 -0
  53. package/skills/cm-ai/references/js-host-qa-recovery.md +110 -0
  54. package/skills/cm-ai/references/js-host-recovery.md +199 -0
  55. package/skills/cm-ai/references/js-host.md +67 -329
  56. package/skills/cm-fix/SKILL.md +2 -0
  57. package/skills/cm-fix/references/js-host.md +16 -9
  58. package/skills/cm-prd/SKILL.md +2 -0
@@ -11,22 +11,38 @@ import {inspectVisualCarrier} from './visual.mjs';
11
11
  export const rediagnosisPackage=value=>({historyDigest:value.historyDigest,priorPackageDigest:value.priorPackageDigest,
12
12
  priorObservationDigest:value.priorObservationDigest,reason:value.reason,reviewFeedback:value.reviewFeedback});
13
13
 
14
- export function createFixCausePackage({codeProject,defect,status}){
14
+ // Round 2 shows the reviewer the round-1 review; every file that review examined
15
+ // or cited (outside the revised affectedPaths) is supplied as read-only context so
16
+ // the reviewer can examine and cite it. Old round-2 packages have no contextFiles.
17
+ const priorReviewPaths=feedback=>[...new Set([...(feedback?.examinedPaths??[]),...(feedback?.findings??[]).map(f=>f?.path)]
18
+ .filter(p=>typeof p==='string'&&!p.startsWith('specs:')))].sort();
19
+ function readContextFiles(codeProject,feedback,affectedPaths){
20
+ const files=[];
21
+ for(const p of priorReviewPaths(feedback).filter(p=>!affectedPaths.includes(p))){
22
+ // Only existing, ordinary source files inside the code root; anything else is omitted, never forged.
23
+ try{files.push(...readReviewSourceFiles(codeProject,[p]));}catch{}
24
+ }
25
+ return files;
26
+ }
27
+
28
+ export function createFixCausePackage({codeProject,defect,status,context=true}){
15
29
  need((status.stage==='cause_review_required'||status.stage==='observation_cause_review_correction_required'&&status.causeReviewCorrection)
16
30
  &&status.reproduction?.status==='reproduced'
17
31
  &&status.diagnosis!==null,'fix_cause_review_unavailable');
32
+ const contextFiles=context&&status.rediagnosis?readContextFiles(codeProject,status.rediagnosis.reviewFeedback,status.diagnosis.affectedPaths):[];
18
33
  const value=json({version:1,kind:'cm-fix-cause-review-package',identity:status.identity,defect,
19
34
  reproduction:status.reproduction,diagnosis:status.diagnosis,learning:status.learning,
20
35
  ...(status.rediagnosis?{rediagnosis:rediagnosisPackage(status.rediagnosis)}:{}),
21
36
  ...(status.causeReviewCorrection?{correction:status.causeReviewCorrection}:{}),
22
- files:readReviewSourceFiles(codeProject,status.diagnosis.affectedPaths)},4*1024*1024);
37
+ files:readReviewSourceFiles(codeProject,status.diagnosis.affectedPaths),...(contextFiles.length?{contextFiles}:{})},4*1024*1024);
23
38
  return json({...value,packageDigest:digest(value)},4*1024*1024);
24
39
  }
25
40
 
26
41
  export function readFixCausePackage(raw){
27
42
  const value=json(raw,4*1024*1024);
28
43
  shape(value,['version','kind','identity','defect','reproduction','diagnosis','learning','files','packageDigest',
29
- ...(Object.hasOwn(value,'correction')?['correction']:[]),...(Object.hasOwn(value,'rediagnosis')?['rediagnosis']:[])]);
44
+ ...(Object.hasOwn(value,'correction')?['correction']:[]),...(Object.hasOwn(value,'rediagnosis')?['rediagnosis']:[]),
45
+ ...(Object.hasOwn(value,'contextFiles')?['contextFiles']:[])]);
30
46
  if(value.rediagnosis){
31
47
  shape(value.rediagnosis,['historyDigest','priorPackageDigest','priorObservationDigest','reason','reviewFeedback']);
32
48
  need([value.rediagnosis.historyDigest,value.rediagnosis.priorPackageDigest,value.rediagnosis.priorObservationDigest].every(v=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v)), 'invalid_package');
@@ -62,6 +78,12 @@ export function readFixCausePackage(raw){
62
78
  text(d.rootCause);text(d.plan);need(Array.isArray(d.affectedModules)&&d.affectedModules.length>0,'invalid_package');
63
79
  d.affectedModules.forEach(text);
64
80
  need(Array.isArray(d.affectedPaths)&&digest([...d.affectedPaths].sort())===digest(files.map(file=>file.path)),'invalid_package');
81
+ if(Object.hasOwn(value,'contextFiles')){
82
+ need(value.rediagnosis&&Array.isArray(value.contextFiles)&&value.contextFiles.length>0,'invalid_package');
83
+ const context=readReviewSourceRecords(value.contextFiles).map(file=>file.path),allowed=priorReviewPaths(value.rediagnosis.reviewFeedback);
84
+ need(digest(context)===digest([...context].sort())&&new Set(context).size===context.length
85
+ &&context.every(p=>allowed.includes(p)&&!d.affectedPaths.includes(p)),'invalid_package');
86
+ }
65
87
  shape(r,['status','next','observation',...(Object.hasOwn(r,'attempts')?['attempts']:[])]);
66
88
  need(r.status==='reproduced'&&r.next==='diagnose','invalid_package');inspectFixReproductionAttempts(r);
67
89
  const o=r.observation;
@@ -78,23 +100,30 @@ export function readFixCausePackage(raw){
78
100
  return value;
79
101
  }
80
102
 
81
- export const causeReviewPaths=pkg=>pkg.files.map(file=>file.path);
103
+ export const causeReviewPaths=pkg=>[...pkg.files,...(pkg.contextFiles??[])].map(file=>file.path);
82
104
 
83
105
  // Validate the original package, then admit only the exact registered test transition.
84
106
  export function verifyFixCauseTransition(original,current,authorBaseline,authorResult){
85
107
  const reviewed=readFixCausePackage(original),now=readFixCausePackage(current);
86
108
  const expected=new Map(reviewed.files.map(file=>[file.path,file]));
109
+ // Round-2 context files (e.g. an existing regression test the narrowed
110
+ // diagnosis no longer covers) admit the same registered test transition;
111
+ // any other change to them is drift.
112
+ const expectedContext=new Map((reviewed.contextFiles??[]).map(file=>[file.path,file]));
87
113
  if(authorBaseline&&authorResult){
88
114
  const authored=inspectFixTestAuthor(authorResult,authorBaseline);
89
115
  need(authored.outcome==='authored','cause_review_drift');
90
116
  const before=new Map(authorBaseline.files.map(file=>[file.path,file]));
91
117
  for(const file of authored.testFiles){
92
- if(!expected.has(file.path))continue;
93
- need(digest(inventory([before.get(file.path)]))===digest(inventory([expected.get(file.path)])),'cause_review_drift');
94
- expected.set(file.path,file);
118
+ const target=expected.has(file.path)?expected:expectedContext.has(file.path)?expectedContext:null;
119
+ if(!target)continue;
120
+ need(digest(inventory([before.get(file.path)]))===digest(inventory([target.get(file.path)])),'cause_review_drift');
121
+ target.set(file.path,file);
95
122
  }
96
123
  }
97
124
  need(digest(inventory(now.files))===digest(inventory([...expected.values()])),'cause_review_drift');
125
+ need(Object.hasOwn(now,'contextFiles')===Object.hasOwn(reviewed,'contextFiles')
126
+ &&digest(inventory(now.contextFiles??[]))===digest(inventory([...expectedContext.values()])),'cause_review_drift');
98
127
  const {packageDigest,...body}=now;
99
- need(digest({...body,files:reviewed.files})===reviewed.packageDigest,'cause_review_drift');
128
+ need(digest({...body,files:reviewed.files,...(reviewed.contextFiles?{contextFiles:reviewed.contextFiles}:{})})===reviewed.packageDigest,'cause_review_drift');
100
129
  }
@@ -0,0 +1,43 @@
1
+ // One fix_diagnose validator for journal replay, live answers and the driver
2
+ // preflight. Replay keeps its historical error codes; a live answer that fails
3
+ // becomes invalid_diagnosis with the failing field, so the caller can resubmit.
4
+ import path from 'node:path';
5
+ import {json,need,shape,text} from '../cm-ai/effect-contract.mjs';
6
+ import {tagDiagnosticReason} from '../cm-ai/diagnostic-reason.mjs';
7
+ import {atField,inspectFixInvestigation} from './investigation.mjs';
8
+
9
+ export function inspectFixDiagnosis(raw){
10
+ const value=atField('(answer)',()=>json(raw,32*1024));
11
+ atField('(answer)',()=>shape(value,['status','rootCause','affectedPaths','plan','crossLayer','affectedModules',...(Object.hasOwn(value,'investigation')?['investigation']:[])]));
12
+ atField('status',()=>need(['diagnosed','needs_evidence','design_change'].includes(value.status),'invalid_diagnosis'));
13
+ for(const key of ['rootCause','plan'])atField(key,()=>text(value[key]));
14
+ atField('crossLayer',()=>need(typeof value.crossLayer==='boolean','invalid_diagnosis'));
15
+ if(Object.hasOwn(value,'investigation'))inspectFixInvestigation(value.investigation,value.crossLayer);
16
+ for(const key of ['affectedPaths','affectedModules']){
17
+ atField(key,()=>need(Array.isArray(value[key])&&value[key].length>0&&value[key].length<=32,'invalid_diagnosis'),32,
18
+ Array.isArray(value[key])?value[key].length:null);
19
+ value[key].forEach((item,index)=>atField(`${key}[${index}]`,()=>{
20
+ text(item);need(!path.isAbsolute(item)&&item===path.posix.normalize(item)
21
+ &&item!=='.'&&!item.startsWith('../')&&!/[\\\0]/.test(item),'invalid_diagnosis');
22
+ }));
23
+ atField(key,()=>need(new Set(value[key]).size===value[key].length,'invalid_diagnosis'));
24
+ }
25
+ return value;
26
+ }
27
+
28
+ export function describeFixDiagnosisError(error){
29
+ const field=typeof error?.field==='string'?error.field:'(answer)';
30
+ const limit=Number.isSafeInteger(error?.limit)?`:最多 ${error.limit} 项${Number.isSafeInteger(error.actual)?`,实际 ${error.actual} 项`:''}`:'';
31
+ return `诊断答案字段 ${field} 不合法${limit}(${error?.code??'invalid_input'})`;
32
+ }
33
+
34
+ // Live answer: never an interruption. The step stays pending and the same
35
+ // request may be answered again; nothing about the rejected answer is recorded.
36
+ export function fixDiagnosisAnswer(raw){
37
+ try{return inspectFixDiagnosis(raw);}
38
+ catch(error){
39
+ const failure=Object.assign(new Error('invalid_diagnosis'),{code:'invalid_diagnosis'});
40
+ throw tagDiagnosticReason(failure,describeFixDiagnosisError(error));
41
+ }
42
+ }
43
+ export const isInvalidFixDiagnosis=error=>error?.code==='invalid_diagnosis'&&typeof error.reason==='string';