@aibyzero/cm-workflow 0.21.7 → 0.25.1
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.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +64 -0
- package/README.md +15 -1
- package/VERSION +1 -1
- package/docs/architecture.md +9 -0
- package/docs/cm-acceptance-completion.md +3 -1
- package/docs/cm-control-policy-v2.md +35 -3
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +1 -0
- package/docs/human-correction.md +1 -1
- package/docs/installation.md +63 -19
- package/docs/js-workflow-control.md +67 -31
- package/docs/next-steps.md +10 -0
- package/docs/runtime-failover.md +2 -2
- package/docs/user-guide.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/batch-location.mjs +14 -0
- package/runtime/js/cm-ai/batch-plan.mjs +6 -2
- package/runtime/js/cm-ai/claude-probe-diagnosis.mjs +21 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +20 -7
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -2
- package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
- package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
- package/runtime/js/cm-ai/drive-core.mjs +50 -6
- package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
- package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
- package/runtime/js/cm-ai/execution-store.mjs +21 -3
- package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
- package/runtime/js/cm-ai/host-check.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +29 -2
- package/runtime/js/cm-ai/host-handoff.mjs +7 -0
- package/runtime/js/cm-ai/host-progress.mjs +18 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
- package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
- package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
- package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
- package/runtime/js/cm-ai/review-continuation.mjs +102 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
- package/runtime/js/cm-ai/review-package.mjs +25 -4
- package/runtime/js/cm-ai/review-presentation.mjs +31 -14
- package/runtime/js/cm-ai/review-runner.mjs +5 -4
- package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
- package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
- package/runtime/js/cm-ai/task-commit.mjs +7 -4
- package/runtime/js/cm-ai/task-owner.mjs +5 -2
- package/runtime/js/cm-ai/task-runner.mjs +343 -52
- package/runtime/js/cm-ai/worker-claude-developer.mjs +3 -1
- package/runtime/js/cm-ai/worker-claude.mjs +5 -1
- package/runtime/js/cm-check/host.mjs +13 -3
- package/runtime/js/cm-fix/diagnosis.mjs +16 -3
- package/runtime/js/cm-fix/execution.mjs +47 -9
- package/runtime/js/cm-fix/finish.mjs +9 -1
- package/runtime/js/cm-fix/step-timing.mjs +222 -0
- package/runtime/js/cm-idea/session.mjs +22 -3
- package/runtime/js/cm-init/review-evidence.mjs +20 -7
- package/runtime/js/cm-prd/ai-draft.mjs +260 -0
- package/runtime/js/cm-prd/analysis.mjs +27 -9
- package/runtime/js/cm-prd/change.mjs +29 -8
- package/runtime/js/cm-prd/failed-correction.mjs +24 -4
- package/runtime/js/cm-prd/narrow-review.mjs +63 -3
- package/runtime/js/cm-prd/review-channels.mjs +5 -0
- package/runtime/js/cm-prd/review-correction.mjs +65 -5
- package/runtime/js/cm-prd/review-disposition.mjs +10 -1
- package/runtime/js/cm-prd/review-publication.mjs +2 -1
- package/runtime/js/cm-prd/self-check.mjs +121 -9
- package/runtime/js/cm-prd/session.mjs +55 -13
- package/runtime/js/cm-prd/summary.mjs +34 -6
- package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
- package/runtime/js/cm-refactor/records.mjs +82 -11
- package/runtime/js/cm-refactor/workflow.mjs +3 -1
- package/runtime/js/executor-version.mjs +81 -0
- package/runtime/js/python-log-writer.mjs +15 -0
- package/runtime/js/run-analysis.mjs +136 -11
- package/runtime/logging.md +6 -0
- package/runtime/review.md +2 -1
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.mjs +27 -1
- package/scripts/cm-ai-admission.test.mjs +34 -2
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
- package/scripts/cm-ai-batch-drive.mjs +54 -17
- package/scripts/cm-ai-batch-drive.test.mjs +123 -6
- package/scripts/cm-ai-batch-host.mjs +64 -11
- package/scripts/cm-ai-batch-host.test.mjs +23 -3
- package/scripts/cm-ai-batch-location.test.mjs +22 -1
- package/scripts/cm-ai-batch-merge.mjs +102 -0
- package/scripts/cm-ai-batch-plan.mjs +55 -2
- package/scripts/cm-ai-batch-plan.test.mjs +228 -6
- package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
- package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
- package/scripts/cm-ai-batch-run.mjs +437 -34
- package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
- package/scripts/cm-ai-completion-summary.test.mjs +2 -1
- package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
- package/scripts/cm-ai-direct-review.test.mjs +1 -1
- package/scripts/cm-ai-disk-edits.test.mjs +229 -0
- package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
- package/scripts/cm-ai-drive.mjs +66 -14
- package/scripts/cm-ai-drive.test.mjs +13 -3
- package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
- package/scripts/cm-ai-host.mjs +20 -9
- package/scripts/cm-ai-host.test.mjs +12 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
- package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
- package/scripts/cm-ai-review-continuation.test.mjs +335 -0
- package/scripts/cm-ai-review-failure.test.mjs +13 -10
- package/scripts/cm-ai-review-timeout.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +42 -11
- package/scripts/cm-ai-run.test.mjs +26 -0
- package/scripts/cm-ai-supersede.test.mjs +10 -2
- package/scripts/cm-capability-gate.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +54 -0
- package/scripts/cm-check-runtime.sh +27 -15
- package/scripts/cm-check-update.mjs +83 -8
- package/scripts/cm-check-update.test.mjs +114 -1
- package/scripts/cm-claude-developer-worker.test.mjs +29 -1
- package/scripts/cm-claude-managed-preflight.test.mjs +126 -0
- package/scripts/cm-claude-probe.test.mjs +5 -0
- package/scripts/cm-claude-review-stream.test.mjs +4 -1
- package/scripts/cm-claude-worker.test.mjs +29 -0
- package/scripts/cm-codex-prompt-input.test.mjs +2 -1
- package/scripts/cm-developer-self-review.test.mjs +27 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
- package/scripts/cm-efficiency-response.test.mjs +2 -1
- package/scripts/cm-executor-version-draft.test.mjs +251 -0
- package/scripts/cm-executor-version-entries.test.mjs +93 -0
- package/scripts/cm-executor-version-prd.test.mjs +154 -0
- package/scripts/cm-executor-version-records.test.mjs +256 -0
- package/scripts/cm-executor-version.test.mjs +250 -0
- package/scripts/cm-external-model-host.test.mjs +6 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
- package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
- package/scripts/cm-fix-drive.mjs +7 -2
- package/scripts/cm-fix-drive.test.mjs +45 -0
- package/scripts/cm-fix-entry.mjs +5 -2
- package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
- package/scripts/cm-fix-host.mjs +9 -2
- package/scripts/cm-fix-review-preflight.mjs +2 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +19 -0
- package/scripts/cm-fix-test-extension.test.mjs +30 -2
- package/scripts/cm-host-check.test.mjs +12 -0
- package/scripts/cm-host-qa-executor.test.mjs +172 -1
- package/scripts/cm-host-qa-policy.test.mjs +55 -1
- package/scripts/cm-idea-drive.mjs +5 -2
- package/scripts/cm-idea-entry.mjs +5 -2
- package/scripts/cm-idea-host.mjs +3 -1
- package/scripts/cm-init-drive.mjs +8 -5
- package/scripts/cm-init-entry.mjs +5 -2
- package/scripts/cm-init-host.mjs +6 -2
- package/scripts/cm-log-event.mjs +10 -2
- package/scripts/cm-log-event.test.mjs +29 -0
- package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
- package/scripts/cm-prd-ai-draft.test.mjs +505 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
- package/scripts/cm-prd-completion.test.mjs +67 -4
- package/scripts/cm-prd-design-phase.test.mjs +48 -13
- package/scripts/cm-prd-drive.mjs +91 -21
- package/scripts/cm-prd-drive.test.mjs +126 -4
- package/scripts/cm-prd-entry.mjs +5 -2
- package/scripts/cm-prd-host.mjs +89 -20
- package/scripts/cm-prd-host.test.mjs +17 -8
- package/scripts/cm-prd-narrow-review.test.mjs +49 -1
- package/scripts/cm-prd-review-disposition.test.mjs +94 -1
- package/scripts/cm-prd-review-gate.mjs +13 -5
- package/scripts/cm-prd-review-publication.test.mjs +34 -0
- package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
- package/scripts/cm-prd-self-check.test.mjs +1 -1
- package/scripts/cm-refactor-drive.mjs +10 -4
- package/scripts/cm-refactor-entry.mjs +5 -2
- package/scripts/cm-refactor-host.mjs +3 -1
- package/scripts/cm-release-smoke.sh +3 -2
- package/scripts/cm-run-analysis.test.mjs +373 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
- package/scripts/cm-skill-hints-exam.mjs +3 -1
- package/scripts/cm-skill-hints-install.test.mjs +1 -1
- package/scripts/cm-skill-hints.mjs +106 -10
- package/scripts/cm-skill-hints.test.mjs +162 -6
- package/scripts/cm-skill-judge.mjs +2 -1
- package/scripts/cm-task-gate.mjs +88 -18
- package/scripts/cm-task-scope.test.mjs +1 -1
- package/scripts/cm-test-drive.mjs +13 -8
- package/scripts/cm-test-entry.mjs +5 -2
- package/scripts/cm-test-host.mjs +3 -1
- package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
- package/scripts/cm-workflow-config.test.mjs +8 -3
- package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +10 -1
- package/scripts/policy-binding-compat.test.mjs +3 -2
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/shell-pipe-early-exit.test.mjs +96 -0
- package/scripts/test-cm-prd-review-gate.py +55 -0
- package/scripts/test-shell-compat.sh +7 -5
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -2
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/js-host-recovery.md +5 -1
- package/skills/cm-ai/references/js-host.md +17 -8
- package/skills/cm-check/SKILL.md +3 -0
- package/skills/cm-fix/references/isolated-review.md +1 -1
- package/skills/cm-fix/references/js-host.md +20 -0
- package/skills/cm-fix/references/test-extension.md +1 -1
- package/skills/cm-prd/SKILL.md +8 -6
- package/skills/cm-prd/references/ai-draft.md +81 -0
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/greenfield.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -2
- package/skills/cm-prd/references/js-host.md +9 -6
- package/skills/cm-prd/references/light-mode.md +19 -0
- package/skills/cm-prd/references/requirement-grilling.md +2 -0
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-prd/references/summary-card.md +1 -0
- package/templates/auto-update/cm-update.sh +2 -2
|
@@ -23,8 +23,9 @@ import {readSourceFiles,snapshotSource,selectReportDirectory,checkSourceEvidence
|
|
|
23
23
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
24
24
|
import {inspectDeclaredTestCommand} from '../runtime/js/cm-test/declared-command.mjs';
|
|
25
25
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
26
|
-
import {effectDigest} from '../runtime/js/cm-refactor/records.mjs';
|
|
27
|
-
import {
|
|
26
|
+
import {effectDigest,journalCreatedBy} from '../runtime/js/cm-refactor/records.mjs';
|
|
27
|
+
import {assertResumable,executorRelease} from '../runtime/js/executor-version.mjs';
|
|
28
|
+
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,errorLine} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
28
29
|
|
|
29
30
|
import {driverLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
30
31
|
|
|
@@ -49,10 +50,10 @@ function main(){
|
|
|
49
50
|
valid(config.skillDir===path.join(root,'skills/cm-test'),'config.skillDir 必须指向当前 checkout');
|
|
50
51
|
let admission;
|
|
51
52
|
try{admission=inspectCmTestAdmission({...config.arguments,skillDir:config.skillDir,project:config.project});}
|
|
52
|
-
catch(error){stop(2,`宿主配置准入失败: ${error
|
|
53
|
+
catch(error){stop(2,`宿主配置准入失败: ${errorLine(error)}`);}
|
|
53
54
|
valid(admission.status==='ready','宿主配置准入');
|
|
54
55
|
try{createCmTestHost(config,{call:()=>{throw Error('preflight must not call host')}});}
|
|
55
|
-
catch(error){stop(2,`宿主配置无效: ${error
|
|
56
|
+
catch(error){stop(2,`宿主配置无效: ${errorLine(error)}`);}
|
|
56
57
|
valid(['codex','claude'].includes(config.runtime)&&Array.isArray(config.sources)&&Array.isArray(config.commands)
|
|
57
58
|
&&config.commands.length<=32&&path.isAbsolute(config.logHome),'config.runtime/sources/commands/logHome');
|
|
58
59
|
if(admission.operation==='impact')valid(config.commands.length===0&&config.environment===null,'impact 只读配置');
|
|
@@ -67,6 +68,9 @@ function main(){
|
|
|
67
68
|
const session=path.resolve(base,plan.sessionDir);
|
|
68
69
|
if(!safeFile(path.join(session,'execution.jsonl')))stop(2,`恢复记录不存在: ${path.join(session,'execution.jsonl')}`);
|
|
69
70
|
const rows=fs.readFileSync(path.join(session,'execution.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
71
|
+
// Same gate the host applies before writing: a newer journal is refused with its reason.
|
|
72
|
+
try{const createdBy=journalCreatedBy(rows);if(createdBy)assertResumable(createdBy);}
|
|
73
|
+
catch(error){stop(2,errorLine(error));}
|
|
70
74
|
const context=rows.find(row=>row.type==='context')?.value;
|
|
71
75
|
valid(context?.workflow==='cm-test'&&context.configDigest===digest(config),'resume 配置绑定不匹配');
|
|
72
76
|
const pending=new Map(),inputs=new Map();let last=null;
|
|
@@ -84,6 +88,7 @@ function main(){
|
|
|
84
88
|
}else if(operation==='start'&&plan.sessionDir){
|
|
85
89
|
const session=path.resolve(base,plan.sessionDir);
|
|
86
90
|
valid(!fs.existsSync(path.join(session,'execution.jsonl')),'start 的 sessionDir 已有记录,请用 resume');
|
|
91
|
+
try{executorRelease();}catch(error){stop(2,errorLine(error));}
|
|
87
92
|
}
|
|
88
93
|
const existingSession=plan.sessionDir&&safeFile(path.join(path.resolve(base,plan.sessionDir),'execution.jsonl'));
|
|
89
94
|
const answerRoot=plan.answers?path.resolve(base,plan.answers):null;
|
|
@@ -91,12 +96,12 @@ function main(){
|
|
|
91
96
|
if(['start','resume'].includes(operation)){
|
|
92
97
|
if(admission.operation==='impact'){
|
|
93
98
|
try{impact=collectBranchImpact(admission.project,admission.comparison,config.sources,config.mapPaths??[]);}
|
|
94
|
-
catch(error){stop(2,`impact 定义无效: ${error
|
|
99
|
+
catch(error){stop(2,`impact 定义无效: ${errorLine(error)}`);}
|
|
95
100
|
if(impact.changes.length)asks.push('change_impact');
|
|
96
101
|
}else{
|
|
97
102
|
const runId='test-drive-preflight';
|
|
98
103
|
let snapshot;try{snapshot=snapshotSource(admission.project,selectReportDirectory(admission,runId));
|
|
99
|
-
sources=readSourceFiles(admission.project,config.sources,snapshot);}catch(error){stop(2,`sources 定义无效: ${error
|
|
104
|
+
sources=readSourceFiles(admission.project,config.sources,snapshot);}catch(error){stop(2,`sources 定义无效: ${errorLine(error)}`);}
|
|
100
105
|
const caseFile=admission.cases??(admission.specs&&admission.feature?path.join(admission.specs,admission.feature,'test-cases.json'):null);
|
|
101
106
|
if(caseFile&&safeFile(caseFile)){
|
|
102
107
|
if(path.extname(caseFile)==='.json'){
|
|
@@ -107,7 +112,7 @@ function main(){
|
|
|
107
112
|
if(admission.operation==='generate_cases'||contract===null)asks.push('test_cases');
|
|
108
113
|
for(const item of config.commands){
|
|
109
114
|
try{inspectDeclaredTestCommand(item,sources);createHostCheck({cwd:admission.project,commands:[{id:item.id,command:item.command}]});}
|
|
110
|
-
catch(error){stop(2,`声明命令无效 ${item?.id??'?'}: ${error
|
|
115
|
+
catch(error){stop(2,`声明命令无效 ${item?.id??'?'}: ${errorLine(error)}`);}
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
}
|
|
@@ -131,7 +136,7 @@ function main(){
|
|
|
131
136
|
valid(value.contractDigest===digest(selected),'qa_logic.contractDigest');
|
|
132
137
|
checkSourceEvidence(value.results,sources);
|
|
133
138
|
}
|
|
134
|
-
}catch(error){stop(2,`答案格式错误:${kind}: ${error
|
|
139
|
+
}catch(error){stop(2,`答案格式错误:${kind}: ${errorLine(error)}`);}
|
|
135
140
|
return value;
|
|
136
141
|
};
|
|
137
142
|
const answers=preflightAnswers(asks,loadAnswer);
|
|
@@ -3,6 +3,8 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {fileURLToPath} from 'node:url';
|
|
5
5
|
import {inspectBranchComparison} from '../runtime/js/cm-test/branch-impact.mjs';
|
|
6
|
+
import {executorRelease} from '../runtime/js/executor-version.mjs';
|
|
7
|
+
import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
6
8
|
|
|
7
9
|
const FEATURE=/^(\d+)\.(.+)$/;
|
|
8
10
|
const OPTIONAL=new Set(['description','specs','feature','cases','reportDir','generateCases',
|
|
@@ -82,7 +84,8 @@ function workflowRoot(skillDir) {
|
|
|
82
84
|
ownedFile(root,'VERSION','skill_path_invalid');layout='plugin';
|
|
83
85
|
}else if(fs.existsSync(path.join(root,'templates','cm-VERSION'))){
|
|
84
86
|
ownedFile(root,'templates/cm-VERSION','skill_path_invalid');layout='claude-compat';
|
|
85
|
-
|
|
87
|
+
// No release marker at all: a broken install, reported with its reinstall hint.
|
|
88
|
+
}else{executorRelease(root);reject('skill_path_invalid');}
|
|
86
89
|
ownedFile(root,'skills/cm-test/SKILL.md','skill_path_invalid');
|
|
87
90
|
ownedFile(root,'runtime/test-contract.md','skill_path_invalid');
|
|
88
91
|
ownedFile(root,'scripts/cm-test-entry.mjs','skill_path_invalid');
|
|
@@ -230,7 +233,7 @@ if(isMainModule(process.argv[1])){
|
|
|
230
233
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
231
234
|
} catch(error) {
|
|
232
235
|
process.stderr.write(`${JSON.stringify({schemaVersion:1,workflow:'cm-test',status:'blocked',
|
|
233
|
-
reason:error?.code??'admission_failed'})}\n`);
|
|
236
|
+
reason:error?.code??'admission_failed',...(diagnosticReason(error)?{detail:diagnosticReason(error)}:{})})}\n`);
|
|
234
237
|
process.exitCode=2;
|
|
235
238
|
}
|
|
236
239
|
}
|
package/scripts/cm-test-host.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
|
10
10
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
11
11
|
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
12
|
import {openTestSession} from '../runtime/js/cm-test/session.mjs';
|
|
13
|
+
import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
13
14
|
|
|
14
15
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
15
16
|
let bridge,session;
|
|
@@ -34,7 +35,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
34
35
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
35
36
|
try{await serveCmAiHost({host,input,output,toolBridge:bridge});}finally{if(rawMode)input.setRawMode(false);}
|
|
36
37
|
return 0;
|
|
37
|
-
}catch(cause){
|
|
38
|
+
}catch(cause){const reason=cause instanceof Error?diagnosticReason(cause):null;
|
|
39
|
+
error.write(JSON.stringify({error:{code:cause?.code??'cm_test_host_failed',...(reason?{reason}:{})}})+'\n');return 1;}
|
|
38
40
|
finally{bridge?.close();session?.close();}
|
|
39
41
|
}
|
|
40
42
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -18,10 +18,11 @@ import os from 'node:os';
|
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import {createHash,randomUUID} from 'node:crypto';
|
|
20
20
|
import {spawnSync} from 'node:child_process';
|
|
21
|
-
import {fileURLToPath} from 'node:url';
|
|
21
|
+
import {fileURLToPath,pathToFileURL} from 'node:url';
|
|
22
22
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
23
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
24
24
|
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
25
|
+
import {executorRelease} from '../runtime/js/executor-version.mjs';
|
|
25
26
|
|
|
26
27
|
const repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
27
28
|
const LEGACY_COMMIT='f73402d';
|
|
@@ -57,8 +58,10 @@ function fixture(t){
|
|
|
57
58
|
workflows:{'1.work/T-001':workflow,'1.work/T-002':workflow}};
|
|
58
59
|
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(bundle));
|
|
59
60
|
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify(policy));
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
// Preflight receipt bound to a code version's reviewer arguments (default: the current code).
|
|
62
|
+
const writeReview=(fingerprint=configFingerprint)=>fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',
|
|
63
|
+
preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:fingerprint({cwd:codeProject,model:'fixture'})}}));
|
|
64
|
+
writeReview();
|
|
62
65
|
// Fixture Codex reviewer: approves, except T-002 while the reject marker exists.
|
|
63
66
|
fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
|
|
64
67
|
const fs=require('node:fs');let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
|
|
@@ -87,11 +90,19 @@ const fs=require('node:fs');let prompt='';process.stdin.on('data',part=>prompt+=
|
|
|
87
90
|
const drive=(workflowRoot=repo)=>spawnSync(process.execPath,[path.join(workflowRoot,'scripts/cm-ai-batch-drive.mjs'),'--plan',plan,'advance'],
|
|
88
91
|
{encoding:'utf8',timeout:120000,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
89
92
|
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
90
|
-
return {root,specsDir,codeProject,bundle,reject,writePlan,drive,log:path.join(specsDir,'运行日志.jsonl')};
|
|
93
|
+
return {root,specsDir,codeProject,bundle,reject,writePlan,writeReview,drive,log:path.join(specsDir,'运行日志.jsonl')};
|
|
91
94
|
}
|
|
92
95
|
// The plan digest and worktree segment exactly as f73402d computed them.
|
|
93
96
|
const legacyPlanDigest=bundle=>digest({...bundle.batch,controlPolicy:policy});
|
|
94
97
|
const legacySegment=id=>`${id.slice(0,8).replace(/\./g,'-')}-${createHash('sha256').update(id).digest('hex').slice(0,12)}`;
|
|
98
|
+
// The log is append-only: the pre-upgrade text must stay the exact prefix, byte for byte
|
|
99
|
+
// (comparing parsed rows would miss a rewrite that only changes spacing or key order).
|
|
100
|
+
// Raw bytes, not decoded text: decoding maps invalid UTF-8 and U+FFFD to the same character.
|
|
101
|
+
const assertLogPrefix=(f,before,message)=>{
|
|
102
|
+
const bytes=fs.readFileSync(f.log);
|
|
103
|
+
assert.ok(bytes.length>before.length,'the upgraded run appended rows');
|
|
104
|
+
assert.deepEqual(bytes.subarray(0,before.length),before,message);
|
|
105
|
+
};
|
|
95
106
|
const batchRows=f=>fs.readFileSync(f.log,'utf8').trim().split('\n').map(line=>JSON.parse(line))
|
|
96
107
|
.filter(row=>row.run_id===batchId&&row.event==='decision'&&row.phase.startsWith('batch_'));
|
|
97
108
|
const memberStates=f=>{
|
|
@@ -134,21 +145,27 @@ test('a batch whose pre-upgrade host wrote batch_start and stopped before its fi
|
|
|
134
145
|
const result=resumeToDone(f);
|
|
135
146
|
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
136
147
|
assertLegacyCompletion(f,planDigest);
|
|
137
|
-
|
|
148
|
+
assertLogPrefix(f,Buffer.from(JSON.stringify(row)+'\n'),'the original batch_start row is kept byte for byte, not rewritten');
|
|
149
|
+
// Review q1: members created after the upgrade keep the QA count the batch was approved by.
|
|
150
|
+
for(const [runId,state] of Object.entries(memberStates(f)))
|
|
151
|
+
assert.equal(Object.hasOwn(state.records[0].payload.config,'qaCadence'),false,`${runId} keeps the historical QA cadence`);
|
|
138
152
|
});
|
|
139
153
|
|
|
140
154
|
const legacyAvailable=spawnSync('git',['-C',repo,'cat-file','-e',`${LEGACY_COMMIT}^{commit}`]).status===0;
|
|
141
155
|
test('a batch the f73402d code really ran to mid-member resumes on the new code with unchanged fingerprints to run_done',
|
|
142
|
-
{skip:legacyAvailable?false:`${LEGACY_COMMIT} 不在本地历史(浅克隆),跳过真实旧代码运行`,timeout:300000},t=>{
|
|
156
|
+
{skip:legacyAvailable?false:`${LEGACY_COMMIT} 不在本地历史(浅克隆),跳过真实旧代码运行`,timeout:300000},async t=>{
|
|
143
157
|
const old=fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-old-'));t.after(()=>fs.rmSync(old,{recursive:true,force:true}));
|
|
144
158
|
const archive=spawnSync('sh',['-c',`git -C "$1" archive ${LEGACY_COMMIT} | tar -x -C "$2"`,'archive',repo,old],{encoding:'utf8'});
|
|
145
159
|
assert.equal(archive.status,0,archive.stderr);
|
|
146
160
|
const f=fixture(t);fs.writeFileSync(f.reject,'');
|
|
161
|
+
// The pre-upgrade host only accepts a receipt for its own reviewer arguments; 813b9d0 later
|
|
162
|
+
// changed them, so the receipt is the one f73402d's preflight would have written.
|
|
163
|
+
f.writeReview((await import(pathToFileURL(path.join(old,'runtime/js/cm-ai/codex-config.mjs')).href)).configFingerprint);
|
|
147
164
|
// Pre-upgrade run: T-001 done and handed off, T-002 stopped after a changes_requested review.
|
|
148
165
|
const first=f.drive(old);assert.equal(first.status,0,first.stderr);
|
|
149
166
|
const stopped=lastResult(first);
|
|
150
|
-
assert.deepEqual([stopped.state,stopped.code,stopped.identity
|
|
151
|
-
const before=batchRows(f),states=memberStates(f);
|
|
167
|
+
assert.deepEqual([stopped.state,stopped.code,stopped.identity?.taskId],['changes_requested','revision_answer_required','T-002']);
|
|
168
|
+
const before=batchRows(f),beforeLog=fs.readFileSync(f.log),states=memberStates(f);
|
|
152
169
|
assert.deepEqual(before.map(row=>row.phase),['batch_start','batch_task_committed','batch_handoff']);
|
|
153
170
|
// The hand-written archive above matches the real one: same row keys, same digest formula.
|
|
154
171
|
assert.deepEqual(Object.keys(before[0]).sort(),LEGACY_START_KEYS);
|
|
@@ -158,15 +175,51 @@ test('a batch the f73402d code really ran to mid-member resumes on the new code
|
|
|
158
175
|
for(const state of Object.values(states))assert.deepEqual(Object.keys(state.fingerprints).sort(),['config','inputs','workflow']);
|
|
159
176
|
// Upgrade: the T-002 author answers the review; the reviewer now approves.
|
|
160
177
|
fs.rmSync(f.reject);
|
|
178
|
+
// Documented upgrade step (CHANGELOG, 813b9d0): re-run the preflight with the same config.
|
|
179
|
+
f.writeReview();
|
|
161
180
|
const answers=path.join(f.root,'answers/1.work/T-002');
|
|
162
181
|
fs.writeFileSync(path.join(answers,'develop-a2.json'),JSON.stringify({...develop,edits:{'other.mjs':'second.txt'}}));
|
|
163
182
|
fs.writeFileSync(path.join(answers,'second.txt'),'export const other = 2;\n');
|
|
164
183
|
const result=resumeToDone(f);
|
|
165
184
|
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
166
185
|
assertLegacyCompletion(f,before[0].plan_digest);
|
|
167
|
-
|
|
186
|
+
assertLogPrefix(f,beforeLog,'the pre-upgrade log rows are kept byte for byte');
|
|
168
187
|
const after=memberStates(f);
|
|
169
188
|
for(const [runId,state] of Object.entries(states))
|
|
170
189
|
assert.deepEqual(after[runId].fingerprints,state.fingerprints,`${runId} keeps its pre-upgrade fingerprints`);
|
|
171
190
|
assert.equal(fs.readFileSync(path.join(f.codeProject,'other.mjs'),'utf8'),'export const other = 2;\n');
|
|
172
191
|
});
|
|
192
|
+
|
|
193
|
+
// Executor release (0.22.0): a batch started by this release folds its createdBy into
|
|
194
|
+
// the plan digest, so the real 0.21.7 code reads batch_plan_mismatch and writes nothing.
|
|
195
|
+
const RELEASE_0_21_7='034d460';
|
|
196
|
+
const release0217Available=spawnSync('git',['-C',repo,'cat-file','-e',`${RELEASE_0_21_7}^{commit}`]).status===0;
|
|
197
|
+
test('the real 0.21.7 code refuses a batch this release started before writing anything',
|
|
198
|
+
{skip:release0217Available?false:`${RELEASE_0_21_7} 不在本地历史(浅克隆),跳过真实旧代码运行`,timeout:300000},t=>{
|
|
199
|
+
const old=fs.mkdtempSync(path.join(os.tmpdir(),'cm-release-0217-'));t.after(()=>fs.rmSync(old,{recursive:true,force:true}));
|
|
200
|
+
const archive=spawnSync('sh',['-c',`git -C "$1" archive ${RELEASE_0_21_7} | tar -x -C "$2"`,'archive',repo,old],{encoding:'utf8'});
|
|
201
|
+
assert.equal(archive.status,0,archive.stderr);
|
|
202
|
+
const f=fixture(t);
|
|
203
|
+
const first=f.drive();assert.equal(first.status,0,first.stderr);
|
|
204
|
+
const start=batchRows(f)[0];
|
|
205
|
+
assert.equal(start.phase,'batch_start');assert.deepEqual(start.created_by,{version:1,release:executorRelease()});
|
|
206
|
+
assert.notEqual(start.plan_digest,legacyPlanDigest(f.bundle),'the release is part of the plan digest');
|
|
207
|
+
const before={log:fs.readFileSync(f.log),stores:memberStates(f)};
|
|
208
|
+
f.writePlan('resume');
|
|
209
|
+
// With a member store on disk 0.21.7 already stops at its read-only member check.
|
|
210
|
+
const downgraded=f.drive(old);
|
|
211
|
+
assert.notEqual(downgraded.status,0);assert.match(downgraded.stderr,/invalid_input/,downgraded.stderr);
|
|
212
|
+
assert.deepEqual({log:fs.readFileSync(f.log),stores:memberStates(f)},before,'0.21.7 wrote nothing');
|
|
213
|
+
// Only batch_start on disk (stopped before its first member): the plan digest stops it.
|
|
214
|
+
const execution=path.join(f.specsDir,'.reviews/.execution');
|
|
215
|
+
for(const name of Object.keys(memberStates(f)))fs.rmSync(path.join(execution,name),{recursive:true,force:true});
|
|
216
|
+
fs.writeFileSync(f.log,JSON.stringify(start)+'\n');
|
|
217
|
+
const onlyStart=fs.readFileSync(f.log),batchOnly=f.drive(old);
|
|
218
|
+
assert.match(batchOnly.stdout+batchOnly.stderr,/batch_plan_mismatch/,batchOnly.stdout+batchOnly.stderr);
|
|
219
|
+
assert.deepEqual(fs.readFileSync(f.log),onlyStart,'0.21.7 appended nothing');assert.deepEqual(memberStates(f),{});
|
|
220
|
+
// A row stripped of created_by is not read as a pre-0.22.0 batch either.
|
|
221
|
+
const rows=fs.readFileSync(f.log,'utf8').trim().split('\n').map(line=>JSON.parse(line));
|
|
222
|
+
fs.writeFileSync(f.log,rows.map(row=>JSON.stringify(row.phase==='batch_start'?(({created_by,...rest})=>rest)(row):row)).join('\n')+'\n');
|
|
223
|
+
const stripped=f.drive();
|
|
224
|
+
assert.match(stripped.stdout+stripped.stderr,/batch_plan_mismatch/,stripped.stdout+stripped.stderr);
|
|
225
|
+
});
|
|
@@ -10,6 +10,11 @@ const scriptsRoot=fileURLToPath(new URL('.',import.meta.url));
|
|
|
10
10
|
const entryPath=path.join(scriptsRoot,'cm-workflow-config.mjs');
|
|
11
11
|
const pythonPath=path.join(scriptsRoot,'cm_workflow_config.py');
|
|
12
12
|
const pythonExecutable=process.env.CM_PYTHON_BIN||'python3';
|
|
13
|
+
// Python 3.14 的 argparse 在 FORCE_COLOR=1(node --test 或终端注入)时给 usage/error 上色,
|
|
14
|
+
// 纯文本断言必失败,安装末尾自检随之回滚(2026-12 用户反馈:Python 3.14 装 0.25.0 回滚)。
|
|
15
|
+
// PYTHON_COLORS=0 优先于 FORCE_COLOR,只关 Python 的颜色。
|
|
16
|
+
// 每次调用时取环境:测试会在运行中把用户目录换成临时目录。
|
|
17
|
+
const plainPython=()=>({encoding:'utf8',env:{...process.env,PYTHON_COLORS:'0'}});
|
|
13
18
|
|
|
14
19
|
const validYaml=`version: 1
|
|
15
20
|
project:
|
|
@@ -139,17 +144,17 @@ test('JS CLI is authoritative and Python CLI is an output-compatible forwarder',
|
|
|
139
144
|
];
|
|
140
145
|
for(const args of cases){
|
|
141
146
|
const js=spawnSync(process.execPath,[entryPath,...args],{encoding:'utf8'});
|
|
142
|
-
const py=spawnSync(pythonExecutable,[pythonPath,...args],
|
|
147
|
+
const py=spawnSync(pythonExecutable,[pythonPath,...args],plainPython());
|
|
143
148
|
assert.equal(py.status,js.status,args.join(' '));
|
|
144
149
|
assert.equal(py.stdout,js.stdout,args.join(' '));
|
|
145
150
|
assert.equal(py.stderr.replaceAll('cm_workflow_config.py','cm-workflow-config.mjs'),js.stderr,args.join(' '));
|
|
146
151
|
}
|
|
147
|
-
const help=spawnSync(pythonExecutable,[pythonPath,'--help'],
|
|
152
|
+
const help=spawnSync(pythonExecutable,[pythonPath,'--help'],plainPython());
|
|
148
153
|
assert.equal(help.status,0);
|
|
149
154
|
assert.match(help.stdout,/^usage: cm_workflow_config\.py \[-h\]/);
|
|
150
155
|
assert.match(help.stdout,/Validate and print CM Workflow project configuration/);
|
|
151
156
|
assert.match(help.stdout,/--role \{analyst,browser_qa,coder,external_expert,planner,reviewer,tester\}/);
|
|
152
|
-
const invalidRole=spawnSync(pythonExecutable,[pythonPath,'--role','not-a-role','--print-role'],
|
|
157
|
+
const invalidRole=spawnSync(pythonExecutable,[pythonPath,'--role','not-a-role','--print-role'],plainPython());
|
|
153
158
|
assert.equal(invalidRole.status,2);
|
|
154
159
|
assert.match(invalidRole.stderr,/^usage: cm_workflow_config\.py \[-h\]/);
|
|
155
160
|
assert.match(invalidRole.stderr,/cm_workflow_config\.py: error: argument --role: invalid choice: 'not-a-role'/);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Test helper: create runs with the completion-check reuse escape hatch set
|
|
2
|
+
// (CM_AI_COMPLETION_CHECK_REUSE=off), so tests of the fresh completion re-check
|
|
3
|
+
// machinery (retries, limits, rework) keep exercising it. Restores the variable.
|
|
4
|
+
export async function withFreshCompletionChecks(run){
|
|
5
|
+
const old=process.env.CM_AI_COMPLETION_CHECK_REUSE;process.env.CM_AI_COMPLETION_CHECK_REUSE='off';
|
|
6
|
+
try{return await run();}
|
|
7
|
+
finally{if(old===undefined)delete process.env.CM_AI_COMPLETION_CHECK_REUSE;else process.env.CM_AI_COMPLETION_CHECK_REUSE=old;}
|
|
8
|
+
}
|
|
@@ -114,7 +114,7 @@ def validate_evidence(path: Path) -> None:
|
|
|
114
114
|
if field not in fields:
|
|
115
115
|
raise GateError(f"PRD review evidence is missing {field}")
|
|
116
116
|
reviewer = fields["reviewer"]
|
|
117
|
-
if reviewer not in {"codex-subagent", "codex-cli", "self-degraded"}:
|
|
117
|
+
if reviewer not in {"codex-subagent", "codex-cli", "claude-cli", "self-degraded"}:
|
|
118
118
|
raise GateError("PRD review evidence reviewer is not a supported channel")
|
|
119
119
|
if reviewer == "self-degraded":
|
|
120
120
|
if fields["independent"] != "false" or not fields.get("degraded_reason", ""):
|
|
@@ -155,8 +155,17 @@ def load_receipt(path: Path, *, stage: str, feature: str, evidence: Path) -> dic
|
|
|
155
155
|
"artifacts",
|
|
156
156
|
"at",
|
|
157
157
|
}
|
|
158
|
+
if isinstance(value, dict) and "narrow_user_decision_sha256" in value:
|
|
159
|
+
# Design only: the user's accept-risks decision this receipt released on (mirrors the JS gate).
|
|
160
|
+
required = required | {"narrow_user_decision_sha256"}
|
|
158
161
|
if not isinstance(value, dict) or set(value) != required:
|
|
159
162
|
raise GateError("PRD review receipt fields do not match the contract")
|
|
163
|
+
if "narrow_user_decision_sha256" in value and (
|
|
164
|
+
value["stage"] != "design"
|
|
165
|
+
or not isinstance(value["narrow_user_decision_sha256"], str)
|
|
166
|
+
or not re.fullmatch(r"[0-9a-f]{64}", value["narrow_user_decision_sha256"])
|
|
167
|
+
):
|
|
168
|
+
raise GateError("PRD review receipt narrow decision binding is invalid")
|
|
160
169
|
if (
|
|
161
170
|
value["schema_version"] != 1
|
|
162
171
|
or value["stage"] != stage
|
|
@@ -90,8 +90,9 @@ test('real cm-test host: a journal bound by 0b3040e opens and replays; another p
|
|
|
90
90
|
if(message.type==='host_request')child.kill('SIGKILL');});
|
|
91
91
|
await closed;
|
|
92
92
|
const journal=path.join(session,'execution.jsonl');
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// The first row keeps its own previous (a format-2 journal starts from its format seed).
|
|
94
|
+
const rebind=policy=>{let previous=null;const rows=fs.readFileSync(journal,'utf8').trimEnd().split('\n').map(line=>JSON.parse(line)).map(({hash,...row},index)=>{
|
|
95
|
+
const body={...row,...(row.type==='context'?{value:{...row.value,binding:{...row.value.binding,policy}}}:{}),previous:index===0?row.previous:previous};
|
|
95
96
|
previous=digest(body);return {...body,hash:previous};});
|
|
96
97
|
fs.writeFileSync(journal,rows.map(row=>JSON.stringify(row)).join('\n')+'\n',{mode:0o600});};
|
|
97
98
|
rebind(legacyTest.policy);
|
|
@@ -42,6 +42,7 @@ ALLOW_LOOPBACK_ENDPOINT_FILES = {
|
|
|
42
42
|
Path("scripts/cm-ai-host-cli-workflow.test.mjs"),
|
|
43
43
|
Path("scripts/cm-ai-multi-root.test.mjs"),
|
|
44
44
|
Path("scripts/cm-ai-nested-execution.test.mjs"),
|
|
45
|
+
Path("scripts/cm-claude-managed-preflight.test.mjs"),
|
|
45
46
|
Path("scripts/cm-claude-probe.test.mjs"),
|
|
46
47
|
Path("scripts/cm-fix-review-verification-command.test.mjs"),
|
|
47
48
|
Path("scripts/cm-fix-visual-bare.test.mjs"),
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Guard: under `set -o pipefail`, a reader that stops before EOF (`grep -q`,
|
|
2
|
+
// `grep -l`, `grep -m`, `head`, `awk ... exit`, `sed ... q`) can leave the
|
|
3
|
+
// writer with SIGPIPE, so the pipeline fails at random (CI flake on
|
|
4
|
+
// cm-check-runtime.sh: "cm-prd single-round reviews have no crash-safe
|
|
5
|
+
// disposition recovery gate" while the text was present).
|
|
6
|
+
import test from 'node:test';
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {fileURLToPath} from 'node:url';
|
|
11
|
+
|
|
12
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
13
|
+
const SKIP = new Set(['.git', 'node_modules']);
|
|
14
|
+
const READER = String.raw`(?:grep\b[^|;&)\]]*?(?:\s-[A-Za-z]*[qlLm][A-Za-z]*\b|\s--(?:quiet|silent|files-with(?:out)?-matches|max-count)\b)` +
|
|
15
|
+
String.raw`|head\b|awk\b[^|&]*?\bexit\b|sed\b[^|&]*?(?:^|[;{'\s\d$/])q\s*(?:[;}'\d]|$))`;
|
|
16
|
+
const EARLY_READER = new RegExp(String.raw`^\s*` + READER);
|
|
17
|
+
const PIPEFAIL = /^\s*set\s+[^#\n]*?-[A-Za-z]*o\s+pipefail\b/m;
|
|
18
|
+
|
|
19
|
+
// Scans one line of shell code: drops an unquoted comment and records pipes
|
|
20
|
+
// that sit in code (not in '...' or "..." text; `$(...)` inside "..." is code).
|
|
21
|
+
function scan(line) {
|
|
22
|
+
const stack = ['code'], pipes = [];
|
|
23
|
+
for (let i = 0; i < line.length; i++) {
|
|
24
|
+
const ch = line[i], top = stack.at(-1);
|
|
25
|
+
if (top === "'") { if (ch === "'") stack.pop(); continue; }
|
|
26
|
+
if (top === '"') {
|
|
27
|
+
if (ch === '\\') i++;
|
|
28
|
+
else if (ch === '"') stack.pop();
|
|
29
|
+
else if (ch === '$' && line[i + 1] === '(') { stack.push('subst'); i++; }
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === '\\') i++;
|
|
33
|
+
else if (ch === "'" || ch === '"') stack.push(ch);
|
|
34
|
+
else if (ch === '#' && (i === 0 || /[\s;]/.test(line[i - 1]))) return {code: line.slice(0, i), pipes};
|
|
35
|
+
else if (ch === '$' && line[i + 1] === '(') { stack.push('subst'); i++; }
|
|
36
|
+
else if (ch === ')' && top === 'subst') stack.pop();
|
|
37
|
+
else if (ch === '|' && line[i - 1] !== '|' && line[i + 1] !== '|') pipes.push(i);
|
|
38
|
+
}
|
|
39
|
+
return {code: line, pipes};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function shellFiles(dir) {
|
|
43
|
+
const found = [];
|
|
44
|
+
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
45
|
+
const full = path.join(dir, entry.name);
|
|
46
|
+
if (SKIP.has(entry.name) || path.relative(root, full) === path.join('.claude', 'worktrees')) continue;
|
|
47
|
+
if (entry.isDirectory()) found.push(...shellFiles(full));
|
|
48
|
+
else if (entry.isFile() && entry.name.endsWith('.sh')) found.push(full);
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Lines continued by a trailing `|` or `\` (after any comment) are joined so a
|
|
54
|
+
// reader on the next line is still seen. The reader text is tested raw, so
|
|
55
|
+
// `awk '{exit}'` and `sed '1q'` count.
|
|
56
|
+
export function earlyExitPipes(text) {
|
|
57
|
+
if (!PIPEFAIL.test(text)) return [];
|
|
58
|
+
const lines = text.split('\n'), offenders = [];
|
|
59
|
+
for (let i = 0; i < lines.length; i++) {
|
|
60
|
+
const start = i;
|
|
61
|
+
let command = scan(lines[i]).code;
|
|
62
|
+
while (/(?:\||\\)\s*$/.test(command) && i + 1 < lines.length)
|
|
63
|
+
command = command.replace(/\\\s*$/, ' ') + ' ' + scan(lines[++i]).code;
|
|
64
|
+
if (scan(command).pipes.some(at => EARLY_READER.test(command.slice(at + 1)))) offenders.push(start + 1);
|
|
65
|
+
}
|
|
66
|
+
return offenders;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test('the guard recognizes the early-exit readers it is meant to stop', () => {
|
|
70
|
+
const bad = [
|
|
71
|
+
`printf '%s' "$x" | grep -Fq a`, 'foo | grep -q b', 'bar | head -n 1', 'a | grep --quiet b',
|
|
72
|
+
'a | grep -l b', 'a | grep -m 1 b', "a | awk '/x/{print; exit}'", "a | sed -n '/x/{p;q;}'",
|
|
73
|
+
`x="$(a | head -1)"`, "yes | sed -n '1q'", 'b="$(c | grep -q d)"',
|
|
74
|
+
];
|
|
75
|
+
const good = [
|
|
76
|
+
'# baz | head', 'qux | grep -Fc c', 'a || head -n 1 file', "echo 'a | head'", 'a | grep -c b',
|
|
77
|
+
"a | sed -n '1,5p'", 'a | grep b >/dev/null', "x=1 # note: a | head", '[ "$(a | grep -c b)" -eq 1 ]',
|
|
78
|
+
'echo "yes | head"', 'a | grep -c x # not -q', "a | sed 's/q/x/'",
|
|
79
|
+
];
|
|
80
|
+
const tail = ['printf x |', ' grep -Eq y ||', ' fail', 'yes | # keep going', ' head -n 1'];
|
|
81
|
+
const script = ['set -euo pipefail', ...bad, ...good, ...tail].join('\n');
|
|
82
|
+
const after = bad.length + good.length + 2;
|
|
83
|
+
assert.deepEqual(earlyExitPipes(script), [...bad.map((_, i) => i + 2), after, after + 3]);
|
|
84
|
+
assert.deepEqual(earlyExitPipes(script.replace('set -euo pipefail', 'set -eu')), []);
|
|
85
|
+
assert.deepEqual(earlyExitPipes('# uses pipefail elsewhere\nfoo | head\n'), []);
|
|
86
|
+
assert.deepEqual(earlyExitPipes('set -- pipefail\nfoo | head\n'), []);
|
|
87
|
+
assert.deepEqual(earlyExitPipes('set -o errexit -o pipefail\nfoo | head\n'), [2]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('pipefail shell scripts do not pipe into readers that exit early', () => {
|
|
91
|
+
const offenders = shellFiles(root).flatMap(file =>
|
|
92
|
+
earlyExitPipes(fs.readFileSync(file, 'utf8')).map(line => `${path.relative(root, file)}:${line}`));
|
|
93
|
+
assert.deepEqual(offenders, [],
|
|
94
|
+
'Under pipefail, a pipe into a reader that stops early (grep -q/-l/-m, head, awk exit, sed q) can fail with SIGPIPE at random. ' +
|
|
95
|
+
'Match text with a shell `case` (`contains "$var" needle`), count with `grep -c`, or limit with a reader that consumes all input (`sed -n \'1,5p\'`).');
|
|
96
|
+
});
|
|
@@ -75,6 +75,30 @@ def runtime_mark_fixtures(root: Path) -> None:
|
|
|
75
75
|
assert "changed after disposition" in invoke("inspect", *flags, expected_exit=1)["stderr"]
|
|
76
76
|
(root / name).write_bytes(saved)
|
|
77
77
|
assert receipt.read_bytes() == receipt_bytes
|
|
78
|
+
# Review (todo r1): the user-decision binding is design-only; a split receipt carrying it is rejected by both.
|
|
79
|
+
narrow_decision_binding_fixtures(receipt, ["inspect", *flags], accept_valid=False)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def narrow_decision_binding_fixtures(receipt: Path, inspect_args: list[str], *, accept_valid: bool = True) -> None:
|
|
83
|
+
"""Both implementations read the optional design-only user-decision binding alike."""
|
|
84
|
+
saved = receipt.read_bytes()
|
|
85
|
+
base = json.loads(saved)
|
|
86
|
+
impls = [ROOT / "scripts" / "cm-prd-review-gate.mjs",
|
|
87
|
+
ROOT / "scripts" / "fixtures" / "prd-review-gate-python-oracle.py"]
|
|
88
|
+
cases = [("a" * 64, True), ("A" * 64, False), ("a" * 63, False), (7, False), (["a" * 64], False), (None, False)]
|
|
89
|
+
try:
|
|
90
|
+
for value, accepted in cases:
|
|
91
|
+
accepted = accepted and accept_valid
|
|
92
|
+
receipt.write_text(json.dumps({**base, "narrow_user_decision_sha256": value}) + "\n", encoding="utf-8")
|
|
93
|
+
for impl in impls:
|
|
94
|
+
runner = sys.executable if impl.suffix == ".py" else os.environ.get("CM_NODE_BIN", "node")
|
|
95
|
+
done = subprocess.run([runner, str(impl), *inspect_args], cwd=ROOT, text=True,
|
|
96
|
+
encoding="utf-8", capture_output=True, check=False)
|
|
97
|
+
ok = done.returncode == 0 and json.loads(done.stdout).get("outcome") == "completed"
|
|
98
|
+
if ok != accepted:
|
|
99
|
+
raise AssertionError(f"{impl.name} narrow binding {value!r}: expected accepted={accepted}\n{done.stderr}")
|
|
100
|
+
finally:
|
|
101
|
+
receipt.write_bytes(saved)
|
|
78
102
|
|
|
79
103
|
|
|
80
104
|
def main() -> int:
|
|
@@ -153,6 +177,36 @@ def main() -> int:
|
|
|
153
177
|
)
|
|
154
178
|
assert degraded["outcome"] == "resume_disposition"
|
|
155
179
|
|
|
180
|
+
# External report 2026-12 item 3: claude-only presets declare claude-cli; the gate,
|
|
181
|
+
# its CLI and the Python oracle all read it like the other independent channels.
|
|
182
|
+
oracle = ROOT / "scripts" / "fixtures" / "prd-review-gate-python-oracle.py"
|
|
183
|
+
for reviewer, expected_exit in (("claude-cli", 0), ("claude-api", 1)):
|
|
184
|
+
channel_evidence = reviews / f"prd-4.{reviewer}-design-r1.md"
|
|
185
|
+
channel_evidence.write_text(
|
|
186
|
+
"---\n"
|
|
187
|
+
"at: 2026-08-04T12:00:00-07:00\n"
|
|
188
|
+
f"reviewer: {reviewer}\n"
|
|
189
|
+
"independent: true\n"
|
|
190
|
+
"scope:\n"
|
|
191
|
+
" - design.md\n"
|
|
192
|
+
"---\n\n"
|
|
193
|
+
"独立审查零发现。\n",
|
|
194
|
+
encoding="utf-8",
|
|
195
|
+
)
|
|
196
|
+
channel_args = ["inspect", "--stage", "design", "--feature", f"4.{reviewer}",
|
|
197
|
+
"--evidence", str(channel_evidence),
|
|
198
|
+
"--receipt", str(reviews / f"prd-4.{reviewer}-design-disposition.json")]
|
|
199
|
+
channel = invoke(*channel_args, expected_exit=expected_exit)
|
|
200
|
+
if expected_exit == 0:
|
|
201
|
+
assert channel["outcome"] == "resume_disposition", channel
|
|
202
|
+
checked = subprocess.run([sys.executable, str(oracle), *channel_args], cwd=ROOT, text=True,
|
|
203
|
+
encoding="utf-8", capture_output=True, check=False)
|
|
204
|
+
assert checked.returncode == expected_exit, checked.stderr
|
|
205
|
+
if expected_exit == 0:
|
|
206
|
+
assert json.loads(checked.stdout)["outcome"] == "resume_disposition"
|
|
207
|
+
else:
|
|
208
|
+
assert "not a supported channel" in checked.stderr, checked.stderr
|
|
209
|
+
|
|
156
210
|
evidence_body = (
|
|
157
211
|
"---\n"
|
|
158
212
|
"at: 2026-08-04T12:00:00-07:00\n"
|
|
@@ -221,6 +275,7 @@ def main() -> int:
|
|
|
221
275
|
str(receipt),
|
|
222
276
|
)
|
|
223
277
|
assert completed["outcome"] == "completed"
|
|
278
|
+
narrow_decision_binding_fixtures(receipt, inspect_args)
|
|
224
279
|
|
|
225
280
|
artifact.write_text("# changed after disposition\n", encoding="utf-8")
|
|
226
281
|
artifact_mismatch = invoke(
|
|
@@ -409,17 +409,19 @@ roles:
|
|
|
409
409
|
source: subscription
|
|
410
410
|
ROUTE_YML
|
|
411
411
|
|
|
412
|
+
contains() { case "$1" in *"$2"*) return 0 ;; esac; return 1; }
|
|
413
|
+
|
|
412
414
|
route_line() {
|
|
413
415
|
grep "^runtime declaration \[both\] $2:" "$1" || true
|
|
414
416
|
}
|
|
415
417
|
|
|
416
418
|
env -u CM_RUNTIME "$ROOT/scripts/cm-check-runtime.sh" --project "$ROUTE_PROJECT" \
|
|
417
419
|
>"$TMP_ROOT/route-unset.out" 2>&1 || true
|
|
418
|
-
if ! route_line "$TMP_ROOT/route-unset.out" coder
|
|
420
|
+
if ! contains "$(route_line "$TMP_ROOT/route-unset.out" coder)" '未判定'; then
|
|
419
421
|
cat "$TMP_ROOT/route-unset.out" >&2
|
|
420
422
|
fail "an unnamed runtime must report 未判定 instead of guessing one"
|
|
421
423
|
fi
|
|
422
|
-
if route_line "$TMP_ROOT/route-unset.out" reviewer
|
|
424
|
+
if contains "$(route_line "$TMP_ROOT/route-unset.out" reviewer)" '已声明未派发'; then
|
|
423
425
|
cat "$TMP_ROOT/route-unset.out" >&2
|
|
424
426
|
fail "an unnamed runtime must not claim the reviewer was never dispatched"
|
|
425
427
|
fi
|
|
@@ -428,11 +430,11 @@ for rt in codex claude; do
|
|
|
428
430
|
env -u CM_RUNTIME "$ROOT/scripts/cm-check-runtime.sh" --project "$ROUTE_PROJECT" --runtime "$rt" \
|
|
429
431
|
>"$TMP_ROOT/route-$rt.out" 2>&1 || true
|
|
430
432
|
if [ "$rt" = codex ]; then own=coder; other=reviewer; else own=reviewer; other=coder; fi
|
|
431
|
-
if ! route_line "$TMP_ROOT/route-$rt.out" "$own"
|
|
433
|
+
if ! contains "$(route_line "$TMP_ROOT/route-$rt.out" "$own")" 'route_state=current-runtime'; then
|
|
432
434
|
cat "$TMP_ROOT/route-$rt.out" >&2
|
|
433
435
|
fail "--runtime $rt must label $own as the current runtime"
|
|
434
436
|
fi
|
|
435
|
-
if ! route_line "$TMP_ROOT/route-$rt.out" "$other"
|
|
437
|
+
if ! contains "$(route_line "$TMP_ROOT/route-$rt.out" "$other")" '已声明未派发'; then
|
|
436
438
|
cat "$TMP_ROOT/route-$rt.out" >&2
|
|
437
439
|
fail "--runtime $rt must label $other as declared but not dispatched"
|
|
438
440
|
fi
|
|
@@ -440,7 +442,7 @@ done
|
|
|
440
442
|
|
|
441
443
|
CM_RUNTIME=claude "$ROOT/scripts/cm-check-runtime.sh" --project "$ROUTE_PROJECT" \
|
|
442
444
|
>"$TMP_ROOT/route-env.out" 2>&1 || true
|
|
443
|
-
if ! route_line "$TMP_ROOT/route-env.out" reviewer
|
|
445
|
+
if ! contains "$(route_line "$TMP_ROOT/route-env.out" reviewer)" 'route_state=current-runtime'; then
|
|
444
446
|
cat "$TMP_ROOT/route-env.out" >&2
|
|
445
447
|
fail "CM_RUNTIME must still name the current runtime when no flag is passed"
|
|
446
448
|
fi
|
package/skills/cm-ai/SKILL.md
CHANGED
|
@@ -99,7 +99,7 @@ START
|
|
|
99
99
|
|
|
100
100
|
**暂停(仅灾难级):** 不可逆破坏(删数据、动线上、不可回滚迁移)、资金/密钥/合规风险、交付形态级架构错向、环境阻塞到无法继续。
|
|
101
101
|
**不暂停(多方案自主决策):** 执行中出现多个可选方案时——技术选型、实现路径、库/工具选择、审查意见分歧——**自己分析利弊选最优解直接执行,不询问**。代价是留痕义务:把「选了什么 / 为什么 / 放弃了什么」写进任务汇报,方向性取舍追记 LESSONS.md——人可以事后翻案,但流程不为选择题停车。业务逻辑歧义按需求文档最合理解释执行并显式记录所做假设,仅当触及灾难级清单才暂停。
|
|
102
|
-
**节点间不停车:** 除上述灾难级与各节点显式卡点(入口闸/降级知情/形态确认/涉合规走查)外,任何节点完成后**直接进入下一节点**——不得以"我将要…是否继续?"、"完成了 X,需要我继续吗?"
|
|
102
|
+
**节点间不停车:** 除上述灾难级与各节点显式卡点(入口闸/降级知情/形态确认/涉合规走查)外,任何节点完成后**直接进入下一节点**——不得以"我将要…是否继续?"、"完成了 X,需要我继续吗?"这类问句收尾等待。阶段性汇报写在输出里照常可见,但回合不能停在等确认上(实跑反馈:执行器习惯性在节点末尾问一句,用户被迫每阶段点头,自动化名存实亡)。驾驶员最后一行 `[drive] 下一步:` 为 `继续` 时不得结束本轮;后台驾驶员与 Monitor 的配合见 `references/js-host.md` 第 7 条。
|
|
103
103
|
**度量:** 每次暂停问人,恢复后在当前任务的 METRICS.md 记录里人工介入计 1 次并注明原因(见 N5)。
|
|
104
104
|
**状态落盘(供状态条/看板实时点亮节点):** 每进入一个节点(N1–N8),覆盖写入 `{SPECS_DIR}/.cm-status.json` 单行 JSON:
|
|
105
105
|
`{"node":"N4","feature":"1.xxx","task":"T-005","detail":"一句话当前动作","state":"running","at":"HH:MM:SS"}`
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
以 JS admission 的结果为准;模型不得自行拼写或修改 `.cm-specs-status`:
|
|
45
45
|
|
|
46
46
|
- `ready` / `complete` → 沿用现有准入结果;旧版无 `specFiles` 的文件仍可读取,不在本节点自行补造批准证据。
|
|
47
|
-
- `awaiting_spec_approval` → 展示规格摘要卡(无卡时可现场汇总,但不得据此生成或替换 `summaryDigest`),请用户明确回复“开始”。JS
|
|
47
|
+
- `awaiting_spec_approval` → 展示规格摘要卡(无卡时可现场汇总,但不得据此生成或替换 `summaryDigest`),请用户明确回复“开始”。JS 仅接受“开始”“开始吧”“可以开始”“确认开始”“开始执行”“现在开始”“可以,请开始开发”“开工”“开工吧”“批准开工”“同意开工”“批准开始”“同意开始”,可带尾部中英文句末标点和空白;泛化授权语(“继续”“可以”“好”“好的”“OK”“按最优解处理”“你看着办”“行”)仍不构成审批,未命中时明确提示回复“开始”(实跑失守:泛化授权曾被误视为审批通过)。
|
|
48
48
|
- 取得明确回复后运行以下写入口,`--approval-response` 传用户原话;多个代码项目全部传入:
|
|
49
49
|
|
|
50
50
|
```bash
|
|
@@ -32,9 +32,9 @@ N3 保留开发期 lint 与测试;这些正常检查不构成作者自审前
|
|
|
32
32
|
|
|
33
33
|
审查输入只包含**本 task 的 diff**,不得将整个未分类 working tree 当作任务 diff。审查者必须:
|
|
34
34
|
|
|
35
|
-
- 假设这个 diff
|
|
35
|
+
- 假设这个 diff 有害,优先寻找**可复现、可达的失败场景**
|
|
36
36
|
- 对照 requirements/design/task 验收,检查超范围变更
|
|
37
|
-
-
|
|
37
|
+
- 按严重度排序;每条阻断项(P0/P1/P2)必须说明「可达输入/状态 → 错误结果」;纯命名/措辞/文档润色、范围外重构建议或无可达触发路径的理论担忧一律归为 P3(只记录不阻断)
|
|
38
38
|
- 找不到真实问题时明确写「零发现」,不凑数
|
|
39
39
|
|
|
40
40
|
该 feature 存在 `test-cases.json` 时,把 `taskIds` 命中当前 task 的 logic cases
|