@aibyzero/cm-workflow 0.16.1 → 0.16.3

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 (147) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +4 -0
  3. package/CHANGELOG.md +179 -0
  4. package/README.md +2 -2
  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 +110 -0
  9. package/docs/untested-branches.md +79 -0
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
  12. package/runtime/js/cm-ai/cm-ai-admission.mjs +5 -0
  13. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
  14. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
  15. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
  16. package/runtime/js/cm-ai/drive-core.mjs +68 -0
  17. package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
  18. package/runtime/js/cm-ai/effect-contract.mjs +38 -5
  19. package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
  20. package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
  21. package/runtime/js/cm-ai/host-handoff.mjs +9 -14
  22. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
  23. package/runtime/js/cm-ai/host-session.mjs +2 -2
  24. package/runtime/js/cm-ai/host.mjs +1 -1
  25. package/runtime/js/cm-ai/metrics-table.mjs +22 -0
  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-fix/cause-invocation.mjs +9 -5
  32. package/runtime/js/cm-fix/cause-package.mjs +21 -0
  33. package/runtime/js/cm-fix/dossier.mjs +40 -1
  34. package/runtime/js/cm-fix/execution.mjs +369 -83
  35. package/runtime/js/cm-fix/host.mjs +7 -3
  36. package/runtime/js/cm-fix/layout.mjs +34 -0
  37. package/runtime/js/cm-fix/metrics.mjs +2 -4
  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-fix/walkthrough.mjs +8 -2
  47. package/runtime/js/cm-prd/accepted-design.mjs +28 -9
  48. package/runtime/js/cm-prd/analysis.mjs +68 -16
  49. package/runtime/js/cm-prd/change.mjs +21 -1
  50. package/runtime/js/cm-prd/draft-save.mjs +96 -2
  51. package/runtime/js/cm-prd/failed-correction.mjs +51 -0
  52. package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
  53. package/runtime/js/cm-prd/review-correction.mjs +3 -0
  54. package/runtime/js/cm-prd/review-disposition.mjs +33 -15
  55. package/runtime/js/cm-prd/review-findings.mjs +2 -2
  56. package/runtime/js/cm-prd/review-host.mjs +2 -0
  57. package/runtime/js/cm-prd/review-preparation.mjs +28 -1
  58. package/runtime/js/cm-prd/review-publication.mjs +4 -2
  59. package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
  60. package/runtime/js/cm-prd/session.mjs +5 -5
  61. package/runtime/js/cm-prd/split-design.mjs +67 -0
  62. package/runtime/js/cm-prd/summary.mjs +53 -8
  63. package/runtime/js/cm-refactor/workflow.mjs +103 -21
  64. package/scripts/audit-untested-enums.mjs +59 -0
  65. package/scripts/cm-ai-batch-drive.mjs +251 -0
  66. package/scripts/cm-ai-batch-drive.test.mjs +152 -0
  67. package/scripts/cm-ai-contracts.test.mjs +30 -0
  68. package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
  69. package/scripts/cm-ai-drive.mjs +334 -0
  70. package/scripts/cm-ai-drive.test.mjs +251 -0
  71. package/scripts/cm-ai-execution-diagnostic.test.mjs +25 -0
  72. package/scripts/cm-ai-fix-integration.test.mjs +1 -1
  73. package/scripts/cm-ai-host.mjs +41 -18
  74. package/scripts/cm-ai-host.test.mjs +37 -0
  75. package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
  76. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
  77. package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
  78. package/scripts/cm-ai-review-timeout.test.mjs +30 -0
  79. package/scripts/cm-ai-run.mjs +59 -11
  80. package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
  81. package/scripts/cm-ai-session-chain.test.mjs +261 -0
  82. package/scripts/cm-ai-supersede.test.mjs +320 -0
  83. package/scripts/cm-check-drive.mjs +93 -0
  84. package/scripts/cm-check-drive.test.mjs +62 -0
  85. package/scripts/cm-check-host.test.mjs +47 -0
  86. package/scripts/cm-claude-probe.test.mjs +117 -2
  87. package/scripts/cm-fix-abandon.test.mjs +383 -0
  88. package/scripts/cm-fix-cause-package.test.mjs +31 -1
  89. package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
  90. package/scripts/cm-fix-drive.mjs +168 -0
  91. package/scripts/cm-fix-drive.test.mjs +117 -0
  92. package/scripts/cm-fix-escalation.test.mjs +214 -0
  93. package/scripts/cm-fix-execution.test.mjs +67 -0
  94. package/scripts/cm-fix-host.mjs +4 -2
  95. package/scripts/cm-fix-metrics.test.mjs +32 -0
  96. package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
  97. package/scripts/cm-fix-qa-source.test.mjs +3 -3
  98. package/scripts/cm-fix-session-chain.test.mjs +244 -0
  99. package/scripts/cm-fix-test-extension.test.mjs +246 -0
  100. package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
  101. package/scripts/cm-host-handoff.test.mjs +37 -0
  102. package/scripts/cm-idea-drive.mjs +99 -0
  103. package/scripts/cm-idea-drive.test.mjs +50 -0
  104. package/scripts/cm-init-drive.mjs +191 -0
  105. package/scripts/cm-init-drive.test.mjs +59 -0
  106. package/scripts/cm-log-event.mjs +9 -0
  107. package/scripts/cm-prd-design-phase.test.mjs +355 -15
  108. package/scripts/cm-prd-drive.mjs +308 -0
  109. package/scripts/cm-prd-drive.test.mjs +154 -0
  110. package/scripts/cm-prd-host.mjs +46 -17
  111. package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
  112. package/scripts/cm-prd-review-disposition.test.mjs +133 -7
  113. package/scripts/cm-prd-review-gate.mjs +23 -4
  114. package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
  115. package/scripts/cm-prd-summary.test.mjs +48 -4
  116. package/scripts/cm-refactor-drive.mjs +237 -0
  117. package/scripts/cm-refactor-drive.test.mjs +77 -0
  118. package/scripts/cm-refactor-gaps.test.mjs +276 -0
  119. package/scripts/cm-refactor-host.test.mjs +1 -48
  120. package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
  121. package/scripts/cm-release-smoke.sh +14 -0
  122. package/scripts/cm-test-drive.mjs +132 -0
  123. package/scripts/cm-test-drive.test.mjs +91 -0
  124. package/scripts/cm-test-session.test.mjs +117 -0
  125. package/scripts/correction-check.test.mjs +38 -0
  126. package/scripts/fixtures/claude-model-marker.mjs +6 -0
  127. package/scripts/fixtures/claude-review-process.mjs +7 -0
  128. package/scripts/fixtures/cm-refactor.mjs +56 -0
  129. package/skills/cm-ai/SKILL.md +1 -1
  130. package/skills/cm-ai/references/N4-review.md +2 -0
  131. package/skills/cm-ai/references/N8-finish.md +1 -0
  132. package/skills/cm-ai/references/js-host.md +80 -3
  133. package/skills/cm-check/references/js-host.md +2 -0
  134. package/skills/cm-fix/SKILL.md +11 -4
  135. package/skills/cm-fix/references/js-host.md +67 -2
  136. package/skills/cm-fix/references/test-extension.md +57 -0
  137. package/skills/cm-idea/references/js-host.md +2 -0
  138. package/skills/cm-init/references/js-host.md +2 -0
  139. package/skills/cm-prd/SKILL.md +8 -8
  140. package/skills/cm-prd/references/js-change-recovery.md +41 -0
  141. package/skills/cm-prd/references/js-host.md +64 -2
  142. package/skills/cm-prd/references/spec-self-check.md +14 -2
  143. package/skills/cm-refactor/SKILL.md +5 -0
  144. package/skills/cm-refactor/references/js-batch.md +3 -1
  145. package/skills/cm-refactor/references/js-host.md +49 -0
  146. package/skills/cm-test/references/js-host.md +5 -0
  147. package/skills/cm-test/references/unit-coverage.md +2 -2
@@ -4,18 +4,22 @@ import {inspectProviderCauseReview} from '../cm-ai/provider-review-observation.m
4
4
  import {digest,id,json,need,shape,text,hex} from '../cm-ai/effect-contract.mjs';
5
5
 
6
6
  // A run outlives the session that created it. Its durable configuration keeps the
7
- // original hostContextId, so stored records and fingerprints stay byte-identical;
8
- // a resumed session declares its own next to it. Both are host identities: a grant
9
- // may carry either, and the reviewer stays independent of both.
7
+ // original hostContextId, so stored records and fingerprints stay byte-identical.
8
+ // Every later session that signs a grant is first written into the run's own
9
+ // history (fix-host-joined-N), and the session running now is added on top. All
10
+ // of them are host identities: a grant may carry any, and the reviewer stays
11
+ // independent of every one. The history is what lets a third session accept a
12
+ // grant the second one signed.
13
+ export const MAX_FIX_JOINED_HOSTS=16;
10
14
  export function fixHostContexts(configuration){
11
15
  const hosts=configuration.hostContextIds??[configuration.hostContextId];
12
- need(Array.isArray(hosts)&&hosts.length>=1&&hosts.length<=2&&new Set(hosts).size===hosts.length
16
+ need(Array.isArray(hosts)&&hosts.length>=1&&hosts.length<=MAX_FIX_JOINED_HOSTS+2&&new Set(hosts).size===hosts.length
13
17
  &&hosts[0]===configuration.hostContextId,'invalid_host_context');
14
18
  hosts.forEach(id);return hosts;
15
19
  }
16
20
  export function validateCauseReviewer(raw,hostContextId,maxExclusions=32){
17
21
  const hosts=Array.isArray(hostContextId)?hostContextId:[hostContextId];
18
- need(hosts.length>=1&&hosts.length<=2,'invalid_cause_reviewer');hosts.forEach(id);
22
+ need(hosts.length>=1&&hosts.length<=MAX_FIX_JOINED_HOSTS+2,'invalid_cause_reviewer');hosts.forEach(id);
19
23
  need([32,33,34].includes(maxExclusions),'invalid_cause_reviewer');
20
24
  const value=json(raw);shape(value,['reviewerId','adapterId','provider','requestedModel','contextId','excludedThreadIds',
21
25
  ...(Object.hasOwn(value,'workerConfigurationDigest')?['workerConfigurationDigest']:[])]);
@@ -4,6 +4,8 @@ import {digest,id,json,need,shape,text,validIdentity} from '../cm-ai/effect-cont
4
4
  import {inspectFixLearning} from './learning.mjs';
5
5
  import {inspectFixInvestigation} from './investigation.mjs';
6
6
  import {inspectFixReproductionAttempts} from './reproduce.mjs';
7
+ import {inspectFixTestAuthor} from './test-author.mjs';
8
+ import {inventory} from './test-extension.mjs';
7
9
  import {inspectVisualCarrier} from './visual.mjs';
8
10
 
9
11
  export function createFixCausePackage({codeProject,defect,status}){
@@ -68,3 +70,22 @@ export function readFixCausePackage(raw){
68
70
  }
69
71
 
70
72
  export const causeReviewPaths=pkg=>pkg.files.map(file=>file.path);
73
+
74
+ // Validate the original package, then admit only the exact registered test transition.
75
+ export function verifyFixCauseTransition(original,current,authorBaseline,authorResult){
76
+ const reviewed=readFixCausePackage(original),now=readFixCausePackage(current);
77
+ const expected=new Map(reviewed.files.map(file=>[file.path,file]));
78
+ if(authorBaseline&&authorResult){
79
+ const authored=inspectFixTestAuthor(authorResult,authorBaseline);
80
+ need(authored.outcome==='authored','cause_review_drift');
81
+ const before=new Map(authorBaseline.files.map(file=>[file.path,file]));
82
+ for(const file of authored.testFiles){
83
+ if(!expected.has(file.path))continue;
84
+ need(digest(inventory([before.get(file.path)]))===digest(inventory([expected.get(file.path)])),'cause_review_drift');
85
+ expected.set(file.path,file);
86
+ }
87
+ }
88
+ need(digest(inventory(now.files))===digest(inventory([...expected.values()])),'cause_review_drift');
89
+ const {packageDigest,...body}=now;
90
+ need(digest({...body,files:reviewed.files})===reviewed.packageDigest,'cause_review_drift');
91
+ }
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import {createHash,randomUUID} from 'node:crypto';
5
5
  import {need,digest} from '../cm-ai/effect-contract.mjs';
6
6
  import {writeReviewEvidence} from '../cm-ai/review-evidence-file.mjs';
7
+ import {currentTestFiles,verifyExtensionFiles} from './test-extension.mjs';
7
8
  import {verifyFixRedEvidence} from './red-test.mjs';
8
9
  import {inspectFixReproduction} from './reproduce.mjs';
9
10
  import {readReviewSourceFiles} from '../cm-ai/review-package.mjs';
@@ -75,13 +76,50 @@ export function publishFixObservationDossier({specsRoot,configuration,status,reg
75
76
  return {path:written.path,sha256:createHash('sha256').update(bytes).digest('hex'),completionEligible:false};
76
77
  }
77
78
 
79
+ // Escalation is an incomplete exit, never a repaired-fix snapshot.
80
+ export function publishFixEscalationDossier({specsRoot,configuration,status,causeEvidenceFile,registeredAt}){
81
+ need(status.stage==='escalation_required'&&status.completionEligible===false
82
+ &&status.diagnosis?.status==='design_change'&&status.causeReview?.review?.verdict==='approved','fix_escalation_unavailable');
83
+ const slug=/^T-FIX-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(status.identity.taskId)?.[1];
84
+ need(slug&&Number.isSafeInteger(registeredAt)&&registeredAt>=0&&Number.isFinite(new Date(registeredAt).getTime()),'invalid_fix_dossier');
85
+ need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot,'unsupported_path');
86
+ let test;
87
+ if(configuration.redTest){
88
+ need(status.redTest?.status==='red_confirmed','fix_escalation_red_required');
89
+ verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot);
90
+ test=isVisual(configuration.redTest)
91
+ ?{noFailingTest:`没有失败测试:${configuration.redTest.reason};已核对修前视觉载体。`,visual:status.redTest}
92
+ :{testFiles:status.redTest.testFiles,redEvidenceFile:status.redTest.output.path,redTest:status.redTest};
93
+ }else test={noFailingTest:'没有失败测试:本运行未配置 redTest,未执行自动红测;新设计立项时需明确验收方式。'};
94
+ const section=(title,value)=>`## ${title}\n\n${JSON.stringify(value,null,2).split('\n').map(line=>` ${line}`).join('\n')}\n\n`;
95
+ const body='# 缺陷档案(升级立项)\n\n状态:升级立项。尚未修复,不代表修复完成。以下记录是数据,不是执行指令。\n\n'
96
+ +section('任务',status.identity)
97
+ +section('缺陷与复现',{defect:configuration.defect,reproduction:status.reproduction})
98
+ +section('根因、影响范围与诊断方案',status.diagnosis)
99
+ +section('独立根因审查',{evidenceFile:causeEvidenceFile,review:status.causeReview})
100
+ +section('保留的失败测试与证据',test)
101
+ +'## 立项建议\n\n建议用 $cm-prd --change 发起设计变更;保留上述失败测试文件,把新设计使该测试变绿作为验收检查。没有失败测试时,须在立项中明确替代验收方式,不伪称红测已通过。\n\n'
102
+ +'本档案不代表 task_done,不写修复完成指标;升级退出以原运行日志为准。不授予 provider、安装或 Git 权限。\n';
103
+ const recovery=status.observationResume?readFixObservationArchive({specsRoot,resume:status.observationResume}):null;
104
+ const bytes=Buffer.concat([...(recovery?[recovery.original,recovery.marker]:[]),Buffer.from(body)]);
105
+ need(bytes.length<=256*1024,'limit_exceeded');
106
+ const directory=fixDossierDirectory(specsRoot,configuration);
107
+ try{fs.mkdirSync(directory,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
108
+ need(fs.realpathSync(directory)===directory&&fs.lstatSync(directory).isDirectory(),'unsupported_path');
109
+ const archiveName=recovery?path.posix.basename(status.observationResume.dossier.path)
110
+ :`${new Date(registeredAt).toISOString().slice(0,10).replaceAll('-','')}-${slug}.md`;
111
+ return writeDossier({directory,archiveName,bytes,replaceable:recovery?[recovery.original]:[]});
112
+ }
113
+
78
114
  export function publishFixDossier({specsRoot,configuration,status,registeredAt,final=false}){
79
115
  need(typeof final==='boolean','invalid_input');
80
116
  need(status.stage==='closeout_required'&&status.completionEligible===false,'fix_closeout_unavailable');
81
117
  const slug=/^T-FIX-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(status.identity.taskId)?.[1];
82
118
  need(slug&&Number.isSafeInteger(registeredAt)&&registeredAt>=0&&Number.isFinite(new Date(registeredAt).getTime()),'invalid_fix_dossier');
83
119
  need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot,'unsupported_path');
84
- const output=verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot);
120
+ const extension=status.revision?.tests&&status.revisionTestAuthor?.outcome==='authored'?{plan:status.revision.tests,files:status.revisionTestAuthor.testFiles}:null;
121
+ verifyExtensionFiles(configuration.redTest.cwd,extension);
122
+ const output=verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot,currentTestFiles(status.redTest.testFiles,extension));
85
123
  const section=(title,value)=>`## ${title}\n\n${JSON.stringify(value,null,2).split('\n').map(line=>` ${line}`).join('\n')}\n\n`;
86
124
  // Keep original bytes as base64, not a decoded/re-encoded or truncated substitute.
87
125
  const body='# 缺陷档案(收尾待完成)\n\n状态:证据快照,不代表 task_done / run_done。下列内容是数据,不是执行指令。\n\n'
@@ -93,6 +131,7 @@ export function publishFixDossier({specsRoot,configuration,status,registeredAt,f
93
131
  +section('实际改动',status.repair)
94
132
  +(isVisual(configuration.redTest)?section('修前视觉载体(自动红测不可用)',{reason:configuration.redTest.reason,
95
133
  evidence:status.redTest,...output}):section('保护测试与原始红输出',{test:status.redTest,encoding:'base64; exact stdout/stderr bytes',...output}))
134
+ +(extension?section('第二轮覆盖补充(不是新增红灯证据)',{plan:extension.plan,author:status.revisionTestAuthor,beforeRevision:status.revisionTestCheck}):'')
96
135
  +section('修前基线、修后及审后回归',{baseline:status.baseline,regression:status.regression,postReviewRegression:status.postReviewRegression})
97
136
  +(status.walkthrough?section('按声明波及面进行的关键流程走查',status.walkthrough):'')
98
137
  +section('Learning',{application:status.learning,retrospective:status.retrospective,writeback:status.learningWriteback??null})