@aibyzero/cm-workflow 0.25.0 → 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 +12 -0
- package/README.md +6 -1
- package/VERSION +1 -1
- package/docs/installation.md +28 -10
- package/docs/js-workflow-control.md +2 -1
- package/package.json +1 -1
- 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/host-conversation-execution.mjs +7 -1
- 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-prd/review-channels.mjs +5 -0
- package/runtime/js/cm-prd/review-publication.mjs +2 -1
- package/scripts/cm-ai-batch-host.mjs +10 -3
- package/scripts/cm-ai-batch-host.test.mjs +1 -0
- package/scripts/cm-ai-batch-run.mjs +2 -1
- package/scripts/cm-ai-host.mjs +4 -1
- package/scripts/cm-check-host.test.mjs +54 -0
- package/scripts/cm-check-runtime.sh +18 -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-fix-review-preflight.mjs +2 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +19 -0
- package/scripts/cm-prd-drive.mjs +2 -1
- package/scripts/cm-prd-drive.test.mjs +17 -0
- package/scripts/cm-prd-review-gate.mjs +2 -1
- package/scripts/cm-prd-review-publication.test.mjs +34 -0
- package/scripts/cm-release-smoke.sh +3 -2
- package/scripts/cm-workflow-config.test.mjs +8 -3
- package/scripts/fixtures/prd-review-gate-python-oracle.py +1 -1
- 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 +30 -0
- package/scripts/test-shell-compat.sh +7 -5
- package/skills/cm-ai/references/js-host-recovery.md +1 -0
- package/skills/cm-check/SKILL.md +3 -0
- package/skills/cm-fix/references/isolated-review.md +1 -1
- package/templates/auto-update/cm-update.sh +2 -2
|
@@ -79,3 +79,22 @@ test('one snapshot refuses a second MCP server before it can reset evidence',{sk
|
|
|
79
79
|
assert.equal(second.status,1);assert.match(second.stderr,/review_verification_server_already_started/);assert.equal(second.stdout,'');
|
|
80
80
|
}finally{await s.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
81
81
|
});
|
|
82
|
+
|
|
83
|
+
// External report 2026-12 item 6: when the Claude CLI starts but no message request reaches the loopback
|
|
84
|
+
// probe (an organisation-pinned endpoint), the cm-fix preflight still fails and explains why on stderr.
|
|
85
|
+
// Its exits stay inside cm-fix: the isolated review is Claude-only, so it never suggests Codex.
|
|
86
|
+
test('cm-fix preflight explains an unreached probe with Claude-only exits',{skip:process.platform!=='darwin'||!fs.existsSync('/usr/bin/sandbox-exec'),timeout:30000},()=>{
|
|
87
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-tools-managed-')));
|
|
88
|
+
try{
|
|
89
|
+
const cwd=path.join(root,'code'),bin=path.join(root,'bin');fs.mkdirSync(cwd);fs.mkdirSync(bin);
|
|
90
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');fs.writeFileSync(path.join(cwd,'value.test.mjs'),'');
|
|
91
|
+
fs.writeFileSync(path.join(bin,'claude'),`#!${process.execPath}\nprocess.stdin.resume();process.stdin.on('end',()=>{console.log(JSON.stringify({type:'system',subtype:'init',session_id:'probe-managed'}));process.exit(3);});\n`,{mode:0o700});
|
|
92
|
+
const config=path.join(root,'run.json');fs.writeFileSync(config,JSON.stringify({reproduction:{cwd},reviewVerification:verification}));
|
|
93
|
+
const run=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-fix-review-preflight.mjs',import.meta.url)),'--config',config,'--model','synthetic'],
|
|
94
|
+
{encoding:'utf8',env:{...process.env,PATH:bin+path.delimiter+process.env.PATH},timeout:25000});
|
|
95
|
+
assert.equal(run.status,1,run.stderr);
|
|
96
|
+
const receipt=JSON.parse(run.stdout);assert.equal(receipt.preflight.passed,false);assert.equal(receipt.preflight.cli_started,true);
|
|
97
|
+
assert.match(run.stderr,/工具预检没有收到用于核对工具的消息请求/);assert.match(run.stderr,/只支持 Claude,不能改由 Codex/);
|
|
98
|
+
assert.doesNotMatch(run.stderr,/cm-runtime/);
|
|
99
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
100
|
+
});
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import fs from 'node:fs';
|
|
27
27
|
import {readPrdRepairBinding,recoverPrdResponse} from '../runtime/js/cm-prd/response-recovery.mjs';
|
|
28
28
|
import {inspectPrdReviewResponse} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
29
|
+
import {PRD_REVIEWER_SOURCES} from '../runtime/js/cm-prd/review-channels.mjs';
|
|
29
30
|
import path from 'node:path';
|
|
30
31
|
import {fileURLToPath} from 'node:url';
|
|
31
32
|
import {createHash} from 'node:crypto';
|
|
@@ -312,7 +313,7 @@ function validate(kind,value,ctx){
|
|
|
312
313
|
}
|
|
313
314
|
}else if(kind==='prd_review'){
|
|
314
315
|
exact(value,['reviewer','contextId','independent','at','result','degradedReason'],'review.json');
|
|
315
|
-
check(
|
|
316
|
+
check(PRD_REVIEWER_SOURCES.includes(value.reviewer)&&nonempty(value.contextId)
|
|
316
317
|
&&typeof value.independent==='boolean'&&Number.isFinite(Date.parse(value.at))&&object(value.result),'review.json');
|
|
317
318
|
check(ctx.request.mode==='self-degraded'?value.reviewer==='self-degraded'&&value.independent===false
|
|
318
319
|
&&value.contextId===ctx.hostContext&&nonempty(value.degradedReason):
|
|
@@ -341,3 +341,20 @@ test('an old change_design session with an accepted requirement lacking a versio
|
|
|
341
341
|
testCasesReason:'no_observable_behavior',documents:[{path:'tasks.md',content:`${docs['tasks.md']}${row}`}]}]});
|
|
342
342
|
const tasked=f.drive('advance');assert.equal(tasked.status,0,tasked.stderr);assert.equal(tasked.json.result.stage,'change_check');
|
|
343
343
|
});
|
|
344
|
+
|
|
345
|
+
// External report 2026-12 item 3: the claude-only preset declares reviewer claude-cli. The driver's
|
|
346
|
+
// review.json preflight accepts it as a channel (it then stops on the package check, not the format),
|
|
347
|
+
// while an unknown channel still stops on the format check before the host starts.
|
|
348
|
+
test('final_review preflight accepts the claude-cli channel and still refuses unknown channels',t=>{
|
|
349
|
+
const f=fixture(t);f.write('analyze.json',analyzed);
|
|
350
|
+
const start=f.drive('start');assert.equal(start.status,0,start.stderr);f.plan.session=start.json.result.runId;
|
|
351
|
+
const attempt=reviewer=>{
|
|
352
|
+
f.write('review.json',{reviewer,contextId:'reviewer',independent:true,at:'2026-09-08T00:00:00.000Z',
|
|
353
|
+
result:{verdict:'approved',packageDigest:'a'.repeat(64),examinedPaths:[],findings:[],summary:'Synthetic'}});
|
|
354
|
+
return f.drive('final_review',{hostContext:'author',permissions:['--allow-review-write'],
|
|
355
|
+
request:{stage:'split',feature:'1.guide',mode:'independent'}});
|
|
356
|
+
};
|
|
357
|
+
const accepted=attempt('claude-cli');assert.equal(accepted.status,2);
|
|
358
|
+
assert.doesNotMatch(accepted.stderr,/答案格式错误/);assert.match(accepted.stderr,/review\.json 与当前原审查包不匹配/);
|
|
359
|
+
const refused=attempt('claude-api');assert.equal(refused.status,2);assert.match(refused.stderr,/答案格式错误: review\.json/);
|
|
360
|
+
});
|
|
@@ -12,6 +12,7 @@ import {assertNarrowReceiptAllowed} from '../runtime/js/cm-prd/review-correction
|
|
|
12
12
|
import {normalizeRuntimeMarks,normalizeRuntimeMarkBytes} from './cm-spec-manifest.mjs';
|
|
13
13
|
import {APPROVED_SPEC_FILES} from '../runtime/js/cm-ai/spec-amendment.mjs';
|
|
14
14
|
import {tagDiagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
15
|
+
import {PRD_REVIEWER_SOURCES} from '../runtime/js/cm-prd/review-channels.mjs';
|
|
15
16
|
|
|
16
17
|
// Messages stay byte-identical for the CLI and its Python oracle. Hosts get a stable
|
|
17
18
|
// code, plus an operator reason made of named fields only: review file names and
|
|
@@ -118,7 +119,7 @@ function evidenceHeader(file){
|
|
|
118
119
|
}
|
|
119
120
|
for(const key of ['at','reviewer','independent','scope'])need(fields.has(key),`PRD review evidence is missing ${key}`,'prd_review_evidence_invalid',where(key));
|
|
120
121
|
const reviewer=fields.get('reviewer');
|
|
121
|
-
need(
|
|
122
|
+
need(PRD_REVIEWER_SOURCES.includes(reviewer),'PRD review evidence reviewer is not a supported channel','prd_review_evidence_invalid',where('reviewer'));
|
|
122
123
|
need(reviewer==='self-degraded'?fields.get('independent')==='false'&&Boolean(fields.get('degraded_reason'))
|
|
123
124
|
:fields.get('independent')==='true','PRD review independence evidence invalid','prd_review_evidence_invalid',where('independent'));
|
|
124
125
|
need(!fields.get('scope')&&scope.length>0&&scope.every(Boolean),'PRD review evidence scope must be a non-empty list','prd_review_evidence_invalid',where('scope'));
|
|
@@ -3,10 +3,13 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
6
7
|
import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
|
|
7
8
|
import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
8
9
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
9
10
|
import {claimPrdReview,inspectPrdReview} from './cm-prd-review-gate.mjs';
|
|
11
|
+
import {REVIEWER_SOURCES} from '../runtime/js/review-findings.mjs';
|
|
12
|
+
import {PRD_REVIEWER_SOURCES,PRD_INDEPENDENT_REVIEWERS} from '../runtime/js/cm-prd/review-channels.mjs';
|
|
10
13
|
function fixture(t){
|
|
11
14
|
const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-r1-')));
|
|
12
15
|
t.after(()=>fs.rmSync(specs,{recursive:true,force:true}));fs.mkdirSync(path.join(specs,'.reviews'));
|
|
@@ -64,6 +67,37 @@ test('invalid identities and canonical IDs from other channels cannot publish',t
|
|
|
64
67
|
response.independent=true;response.reviewer='codex-cli';assert.throws(publish,/invalid_input/);
|
|
65
68
|
assert.equal(inspectPrdReview(prepared.paths).outcome,'dispatch_unknown');
|
|
66
69
|
});
|
|
70
|
+
// External report 2026-12 item 3: the claude-only preset declares reviewer claude-cli, and cm-prd
|
|
71
|
+
// refused it while task review accepted it. Every independent channel in the shared list publishes.
|
|
72
|
+
for(const reviewer of PRD_INDEPENDENT_REVIEWERS)
|
|
73
|
+
test(`independent ${reviewer} declaration publishes r1 under the same checks`,t=>{
|
|
74
|
+
const {prepared,response,claim,publish}=fixture(t);claim();response.reviewer=reviewer;
|
|
75
|
+
const result=publish();assert.equal(result.independent,true);assert.equal(result.completionAuthorized,false);
|
|
76
|
+
assert.match(fs.readFileSync(prepared.paths.evidence,'utf8'),new RegExp(`reviewer: ${reviewer}\\n`));
|
|
77
|
+
});
|
|
78
|
+
// Guard: cm-prd validators read one cm-prd list instead of their own copies. That list must equal the
|
|
79
|
+
// task review channels and the Python oracle, so adding or removing a channel anywhere fails here
|
|
80
|
+
// until a maintainer decides whether cm-prd accepts it (review r1: no silent widening).
|
|
81
|
+
test('cm-prd reviewer channels are one list, matched to task review and the Python oracle',()=>{
|
|
82
|
+
const repo=fileURLToPath(new URL('..',import.meta.url));
|
|
83
|
+
assert.deepEqual([...PRD_REVIEWER_SOURCES],[...REVIEWER_SOURCES],
|
|
84
|
+
'reviewer channels changed: decide whether cm-prd accepts it, then update runtime/js/cm-prd/review-channels.mjs and the Python oracle');
|
|
85
|
+
const oracle=fs.readFileSync(path.join(repo,'scripts/fixtures/prd-review-gate-python-oracle.py'),'utf8');
|
|
86
|
+
const literal=/if reviewer not in \{([^}]*)\}:/.exec(oracle);assert.ok(literal,'oracle reviewer check not found');
|
|
87
|
+
assert.deepEqual(literal[1].split(',').map(item=>item.trim().replace(/^"|"$/g,'')).sort(),[...PRD_REVIEWER_SOURCES].sort());
|
|
88
|
+
for(const file of ['runtime/js/cm-prd/review-publication.mjs','scripts/cm-prd-drive.mjs','scripts/cm-prd-review-gate.mjs']){
|
|
89
|
+
const source=fs.readFileSync(path.join(repo,file),'utf8');
|
|
90
|
+
assert.doesNotMatch(source,/\[\s*(['"`])(?:codex-subagent|codex-cli|claude-cli|self-degraded)\1\s*,/,`${file}: use runtime/js/cm-prd/review-channels.mjs`);
|
|
91
|
+
assert.match(source,/PRD_(?:INDEPENDENT_)?REVIEWER/,file);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
test('claude-cli keeps the independence rules and unknown channels stay refused',t=>{
|
|
95
|
+
const {prepared,response,claim,publish}=fixture(t);claim();response.reviewer='claude-cli';
|
|
96
|
+
response.contextId='author-context';assert.throws(publish,/prd_review_independence_invalid/);
|
|
97
|
+
response.contextId='reviewer-context';response.independent=false;assert.throws(publish,/prd_review_independence_invalid/);
|
|
98
|
+
response.independent=true;response.reviewer='claude-api';assert.throws(publish,/prd_review_independence_invalid/);
|
|
99
|
+
assert.equal(fs.existsSync(prepared.paths.evidence),false);
|
|
100
|
+
});
|
|
67
101
|
test('changes and explicit self-degradation stay findings, not completion or independent approval',t=>{
|
|
68
102
|
const {prepared,response,claim,publish}=fixture(t);claim();
|
|
69
103
|
response.reviewer='self-degraded';response.contextId='author-context';response.independent=false;
|
|
@@ -69,8 +69,9 @@ HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
|
|
|
69
69
|
|
|
70
70
|
PLUGIN_LIST="$(HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" codex plugin list)"
|
|
71
71
|
printf '%s\n' "$PLUGIN_LIST"
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
# grep -c reads all input; grep -q could close the pipe early and fail under pipefail.
|
|
73
|
+
plugin_enabled="$(printf '%s\n' "$PLUGIN_LIST" | grep -Ec '^cm-workflow@personal[[:space:]]+installed, enabled' || true)"
|
|
74
|
+
[ "$plugin_enabled" -gt 0 ] ||
|
|
74
75
|
fail "Codex did not report cm-workflow@personal as installed and enabled"
|
|
75
76
|
|
|
76
77
|
HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
|
|
@@ -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'/);
|
|
@@ -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", ""):
|
|
@@ -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
|
+
});
|
|
@@ -177,6 +177,36 @@ def main() -> int:
|
|
|
177
177
|
)
|
|
178
178
|
assert degraded["outcome"] == "resume_disposition"
|
|
179
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
|
+
|
|
180
210
|
evidence_body = (
|
|
181
211
|
"---\n"
|
|
182
212
|
"at: 2026-08-04T12:00:00-07:00\n"
|
|
@@ -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
|
|
@@ -149,6 +149,7 @@ QA-fix 新建子运行的配置 hostContextId 只能是当前会话或父运行
|
|
|
149
149
|
**v2:**诊断及缓存安全检查与下文相同,只修真实模型配置/环境;preflight 不是独立 Review 或授权。沿原诊断文件和策略恢复,不能手造 passed、修改指纹或添加 legacy 审查旗标。
|
|
150
150
|
|
|
151
151
|
Claude CLI 报 `unrecognized_model` 时 preflight 会失败并在 stderr 指明被拒 id、可用的家族别名示例(如 CLI 2.1.x 的 `claude-opus-5`),可快速取得时也打印 CLI 版本;示例不是完整模型清单。
|
|
152
|
+
Claude 命令行已启动、但预检没收到用于核对工具的消息请求时(例如托管设置固定接口地址、不许改 `ANTHROPIC_BASE_URL`),stderr 与 `tool_preflight_missing`、批次 `review_preflight_failed` 的 reason 会说明可能原因和出路:在不受托管限制的机器上对同一代码根预检和审查,或新建运行时按角色声明改由 Codex 审查。预检照旧拦住,不加跳过开关。
|
|
152
153
|
Claude 诊断只做回环请求捕获,`stopped_by_probe` 表示诊断自身终止,不发送工作流 cancel。
|
|
153
154
|
执行策略批次(未开外部模型)的并行成员预检缓存现在放在 `.reviews/external-preflight/<batchId>/`。旧版本放在运行目录 `.reviews/.execution/<batchId>/`,外部运行守卫会把它当成无法核实的运行,成员一律打不开。批次宿主打开成员前会核对这个旧目录:只含本批次并行成员的 `preflight-<task>.json`(0700 目录、0600 单链接文件),且每份仍绑定本次 `--review-config` 的模型、禁用技能和该成员 worktree 的指纹时,逐个移到新位置复用(新位置已有相同内容就删旧副本),不再重做回环。动任何文件之前先核对新位置 `.reviews/external-preflight/` 及 `<batchId>` 目录(存在时须为 0700 普通目录、不是链接,全是重复副本时也一样),新位置的副本也须是 0600 单链接普通文件;每个文件只按不跟随链接的方式读一次并核对这份字节;移动用不覆盖的硬链接再删旧名,新位置在迁移时出现或任一侧内容被改就拒绝;中途停下时同一文件会留在新旧两处,下次启动会补完。其他情况返回 `legacy_preflight_cache_invalid`,`reason` 写明目录和不符合的地方,宿主不移动任何文件;只读核对、确认没有进程在写后把该目录移出 `.reviews/.execution`,再用同一配置重启批次宿主并 `advance`,成员会重新预检。
|
|
154
155
|
|
package/skills/cm-check/SKILL.md
CHANGED
|
@@ -34,6 +34,9 @@ Claude Code 将 `--runtime` 改为 `claude`。默认发现 npm `latest` 稳定
|
|
|
34
34
|
- `unmanaged`:源码仓库、Pi/BYZ 或其他管理器安装仅报告本地/远程版本,不改其源码或
|
|
35
35
|
改换安装方式;明确说明自动升级未执行,沿用当前根检查。
|
|
36
36
|
- `blocked` / 非零退出 / 无有效结果:停止并报告原因,不绕过失败继续宣布通过。
|
|
37
|
+
- `blocked` 且带 `localEdits` / `localEditsDigest`:逐个转述 `localEdits` 列出的文件,安装器输出里的路径异常或
|
|
38
|
+
未完成的回滚先按输出处理。问用户是否丢弃这些文件的改动;用户在本轮明确同意后,才在同一更新命令末尾加
|
|
39
|
+
`--overwrite-local-edits {localEditsDigest}` 重跑一次。没有明确同意就按 `blocked` 收口;重跑返回新清单时重新问;报告清单缺失时,先请用户备份改过的文件,不直接重跑。
|
|
37
40
|
|
|
38
41
|
当前自动安装支持 macOS Codex 的个人本地市场安装,以及 macOS/Linux Claude 安装。
|
|
39
42
|
Windows 或其他安装方式有新版时,明确提示使用原平台安装器;不伪称已更新。
|
|
@@ -47,7 +47,7 @@ Claude 原生 Bash、Edit 等工具仍关闭。仅允许 `cm_review.read_file`
|
|
|
47
47
|
|
|
48
48
|
- 没有 `reviewVerification` 的旧运行继续原无工具 worker、预检和回放。不能在已有运行上补、删或改此字段;原指纹拒绝该变更,不迁移 journal,不重置轮次。
|
|
49
49
|
- 新模式缺少有效证据时不得接受成功审查;原 V3 失败/unknown 恢复规则仍适用。不把旧无工具 reconciliation 回执用于补齐新模式执行证据,不重新解释历史 approved。
|
|
50
|
-
- `review_verification_provider`:所选 reviewer 不是 Claude。`tool_preflight_missing`:配置与诊断不匹配。`review_verification_isolation_unavailable`:当前平台无受支持隔离。先修正新运行输入或环境,不改历史来绕过。
|
|
50
|
+
- `review_verification_provider`:所选 reviewer 不是 Claude。`tool_preflight_missing`:配置与诊断不匹配。`review_verification_isolation_unavailable`:当前平台无受支持隔离。先修正新运行输入或环境,不改历史来绕过。Claude 命令行已启动、但预检没收到用于核对工具的消息请求时(例如托管设置固定接口地址),`cm-fix-review-preflight.mjs` 在 stderr 说明可能原因;隔离审查只支持 Claude,出路是在不受托管限制的机器上对同一代码根和运行配置预检并审查。照旧不通过。
|
|
51
51
|
- `review_verification_package_binding`、`*_source_drift`、`*_copy_drift`:包与材料不一致。`*_baseline_failed`、`*_evidence`:实际检查或恢复没有满足合同。保留原结果,按原审查恢复入口处理,不能人工填成功。
|
|
52
52
|
- 当前只验证了 macOS 上的自包含命令。Linux/Windows 不降为直接执行。副本禁止 node_modules 和凭证目录;依赖下载、Xcode/模拟器服务、数据库或外部网络测试不在已验证支持范围。所需工具链/依赖不可访问会真实失败,不能据此声称 Wue 真机或 iOS 验收通过。
|
|
53
53
|
- 有界清理覆盖所拥有的进程组与登记中的命令组;不声称能找回任意敌对代码自行创建新 session、关闭全部管道的后代。**已知限制**:这样的后代在命令返回后可能仍然存活,命令结果照常返回,不会因此报失败。它仍受同一沙箱约束:不能读取未获允许的副本外文件,不能经上述接口读其他进程的环境,也写不到副本外;但它可以继续改动副本,登记文件被改会在下一次检查前后以副本漂移拒绝,未登记产物每条命令前后清除。命令组清理未知时拒绝本会话后续工具调用与成功证据,保留原进程登记,不允许新命令覆盖。清理未知不会记作成功;保留私有副本并输出 `review_verification_cleanup_unknown` 与保留路径,使用日志仍记录失败收尾。一个派发只允许一个 MCP 服务实例;重启或并行实例明确拒绝,不能清空或混用证据。
|
|
@@ -228,7 +228,7 @@ if [ "$local_sha" = "$remote_sha" ] && [ -f "$MANIFEST" ] && [ "$FORCE" = 0 ]; t
|
|
|
228
228
|
log "$(echo "$drift" | sed 's|^| |')"
|
|
229
229
|
fi
|
|
230
230
|
|
|
231
|
-
new_commits="$(git log --oneline "HEAD..origin/$BRANCH" 2>/dev/null |
|
|
231
|
+
new_commits="$(git log --oneline "HEAD..origin/$BRANCH" 2>/dev/null | sed -n '1,5p')"
|
|
232
232
|
|
|
233
233
|
# 缓存目录里不该有人工改动,但确实发生过。丢弃之前先存一份补丁并明确告警,
|
|
234
234
|
# 不要让它无声消失。抢救失败不阻塞更新——缓存与远端一致才是这里的第一要务。
|
|
@@ -245,7 +245,7 @@ if [ -n "$dirty" ]; then
|
|
|
245
245
|
git ls-files --others --exclude-standard 2>/dev/null | sed 's|^|# |'
|
|
246
246
|
} >"$patch" 2>/dev/null || patch=""
|
|
247
247
|
log "⚠ repo/ 有 $dirty_n 处本地改动,将被更新丢弃:"
|
|
248
|
-
log "$(printf '%s\n' "$dirty" |
|
|
248
|
+
log "$(printf '%s\n' "$dirty" | sed -n '1,20s|^| |p')"
|
|
249
249
|
[ -n "$patch" ] && log " 已存补丁:$patch"
|
|
250
250
|
notify "CM Workflow 更新" "repo/ 的 $dirty_n 处本地改动已被丢弃,补丁见 discarded/"
|
|
251
251
|
fi
|