@aibyzero/cm-workflow 0.16.0 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +61 -0
  3. package/README.md +2 -2
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +8 -2
  7. package/docs/untested-branches.md +73 -0
  8. package/package.json +1 -1
  9. package/runtime/js/cm-ai/checklist-coverage.mjs +70 -0
  10. package/runtime/js/cm-ai/effect-contract.mjs +37 -3
  11. package/runtime/js/cm-ai/host-conversation-execution.mjs +37 -1
  12. package/runtime/js/cm-ai/metrics-table.mjs +22 -0
  13. package/runtime/js/cm-ai/review-package.mjs +29 -3
  14. package/runtime/js/cm-ai/task-runner.mjs +10 -4
  15. package/runtime/js/cm-fix/cause-invocation.mjs +17 -4
  16. package/runtime/js/cm-fix/execution.mjs +41 -24
  17. package/runtime/js/cm-fix/final-review.mjs +18 -11
  18. package/runtime/js/cm-fix/finish.mjs +14 -1
  19. package/runtime/js/cm-fix/layout.mjs +26 -0
  20. package/runtime/js/cm-fix/metrics.mjs +2 -4
  21. package/runtime/js/cm-fix/walkthrough.mjs +8 -2
  22. package/runtime/js/cm-refactor/workflow.mjs +3 -2
  23. package/runtime/js/cm-security/scan.mjs +7 -1
  24. package/scripts/audit-untested-enums.mjs +59 -0
  25. package/scripts/cm-ai-checklist-coverage.test.mjs +116 -0
  26. package/scripts/cm-ai-execution-diagnostic.test.mjs +25 -0
  27. package/scripts/cm-ai-verification-gate.test.mjs +18 -0
  28. package/scripts/cm-fix-cross-session-host.test.mjs +100 -0
  29. package/scripts/cm-fix-execution.test.mjs +74 -0
  30. package/scripts/cm-fix-host.mjs +11 -5
  31. package/scripts/cm-fix-metrics.test.mjs +32 -0
  32. package/scripts/cm-fix-repair-owner.test.mjs +22 -18
  33. package/scripts/cm-release-smoke.sh +14 -0
  34. package/scripts/cm-review-dependency-snapshot.test.mjs +85 -0
  35. package/scripts/cm-review-inventory.test.mjs +42 -0
  36. package/scripts/cm-security.test.mjs +24 -0
  37. package/skills/cm-fix/references/js-host.md +18 -1
  38. package/templates/auto-update/cm-update.sh +51 -0
@@ -75,3 +75,88 @@ test('legacy baselines retain already-recorded dependency files and their drift
75
75
  fs.unlinkSync(path.join(root,'.venv','recorded.txt'));
76
76
  assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'});
77
77
  });
78
+
79
+ function installCocoaPods(root,prefix){
80
+ const pods=path.join(root,prefix);
81
+ fs.mkdirSync(path.join(pods,'Headers/Private/DoubleConversion/double-conversion'),{recursive:true});
82
+ fs.mkdirSync(path.join(pods,'Pods.xcodeproj'));
83
+ fs.writeFileSync(path.join(pods,'Manifest.lock'),'PODFILE CHECKSUM: synthetic');
84
+ fs.writeFileSync(path.join(path.dirname(pods),'Podfile.lock'),'PODFILE CHECKSUM: synthetic');
85
+ fs.writeFileSync(path.join(pods,'DoubleConversion.h'),'generated pod header');
86
+ fs.symlinkSync('../../../../DoubleConversion.h',path.join(pods,'Headers/Private/DoubleConversion/double-conversion/bignum-dtoa.h'));
87
+ return pods;
88
+ }
89
+
90
+ test('generated CocoaPods trees stay out of the snapshot instead of blocking it',t=>{
91
+ const {root,options}=fixture(t);
92
+ installCocoaPods(root,'mobile/ios/Pods');
93
+ const baseline=captureReviewBaseline(options);
94
+ // Podfile.lock is authored and checked in; only the generated tree disappears.
95
+ assert.deepEqual(baseline.files.map(f=>f.path),
96
+ ['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
97
+ fs.writeFileSync(path.join(root,'src/main.py'),'after');
98
+ const pkg=createReviewPackage({root,baseline,checks});
99
+ assert.equal(verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
100
+ for(const field of ['scope','requirements'])
101
+ assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),{code:'excluded_snapshot_path'});
102
+ });
103
+
104
+ test('an authored pods directory is still snapshotted and its symlinks still fail closed',t=>{
105
+ const {root,options}=fixture(t);
106
+ fs.mkdirSync(path.join(root,'src/pods'),{recursive:true});
107
+ fs.writeFileSync(path.join(root,'src/pods/scheduler.py'),'business code');
108
+ assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
109
+ ['requirements.md','src/main.py','src/pods/scheduler.py']);
110
+ fs.symlinkSync('../../requirements.md',path.join(root,'src/pods/linked.py'));
111
+ assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'});
112
+ });
113
+
114
+ test('a Pods directory missing any one CocoaPods artefact keeps the symlink guard',t=>{
115
+ for(const missing of ['Pods/Manifest.lock','Pods/Pods.xcodeproj','Podfile.lock']){
116
+ const {root,options}=fixture(t);
117
+ installCocoaPods(root,'mobile/ios/Pods');
118
+ fs.rmSync(path.join(root,'mobile/ios',missing),{recursive:true,force:true});
119
+ assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'},missing);
120
+ }
121
+ });
122
+
123
+ // The traversal and the scope guard must ask one predicate, not two that agree
124
+ // by coincidence. They once did not: the traversal probed every directory for
125
+ // the generated entries while the guard additionally required the name "pods".
126
+ // A directory called src/ holding an empty Manifest.lock and an empty
127
+ // Pods.xcodeproj/ was then skipped whole — taking a file explicitly declared in
128
+ // scope out of the review with no error raised anywhere.
129
+ test('a directory that is not named pods is never treated as a generated tree',t=>{
130
+ const {root,options}=fixture(t);
131
+ fs.writeFileSync(path.join(root,'src/Manifest.lock'),'');
132
+ fs.mkdirSync(path.join(root,'src/Pods.xcodeproj'));
133
+ fs.writeFileSync(path.join(root,'Podfile.lock'),'');
134
+ const baseline=captureReviewBaseline(options);
135
+ assert.ok(baseline.files.some(f=>f.path==='src/main.py'),
136
+ 'a declared scope file was silently dropped from the snapshot');
137
+ // A file added inside the disguise must stay visible: out_of_scope is the
138
+ // snapshot seeing it and refusing it, which is the opposite of vanishing.
139
+ fs.writeFileSync(path.join(root,'src/added.py'),'new');
140
+ fs.writeFileSync(path.join(root,'src/main.py'),'after');
141
+ assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'},
142
+ 'a file added after the baseline stayed invisible to the review package');
143
+ });
144
+
145
+ // Whatever the predicate accepts leaves the review silently, so the two callers
146
+ // must never diverge again. Assert they are the same predicate, not two rules.
147
+ test('the scope guard rejects exactly what the traversal skips',t=>{
148
+ const {root,options}=fixture(t);
149
+ installCocoaPods(root,'mobile/ios/Pods');
150
+ assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
151
+ ['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
152
+ for(const field of ['scope','requirements'])
153
+ assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),
154
+ {code:'excluded_snapshot_path'},field);
155
+ // Remove one artefact: the tree comes back into the snapshot, and the guard
156
+ // must stop rejecting it in the same step.
157
+ fs.rmSync(path.join(root,'mobile/ios/Podfile.lock'));
158
+ fs.rmSync(path.join(root,'mobile/ios/Pods/Headers'),{recursive:true,force:true});
159
+ assert.ok(captureReviewBaseline(options).files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'));
160
+ assert.deepEqual(captureReviewBaseline({...options,scope:['mobile/ios/Pods/DoubleConversion.h']})
161
+ .files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'),true);
162
+ });
@@ -296,3 +296,45 @@ test('new specification and legacy packages both retain receipt completion eligi
296
296
  assert.equal(verifyReviewPackage({root:f.code,baseline:pkg===current?baseline:legacyBaseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
297
297
  }
298
298
  });
299
+
300
+ // A repository that merely contains mobile/.env.example used to be impossible
301
+ // to review: walk() validates every discovered path, so the placeholder aborted
302
+ // the whole baseline capture rather than being skipped. Committed placeholders
303
+ // are ordinary source; the real secret files must still be refused.
304
+ test('committed environment placeholders are inventoried while real secret files stay refused',()=>fixture(root=>{
305
+ fs.mkdirSync(path.join(root,'mobile'));
306
+ write(root,'mobile/.env.example','API_URL=https://example.invalid\n');
307
+ write(root,'.env.sample','TOKEN=replace-me\n');
308
+ const baseline=capture(root);
309
+ const inventoried=baseline.files.map(f=>f.path);
310
+ assert.ok(inventoried.includes('mobile/.env.example'),'placeholder missing from the inventory');
311
+ assert.ok(inventoried.includes('.env.sample'),'placeholder missing from the inventory');
312
+ // Inventoried means hashed, not disclosed: only selected scope carries a body.
313
+ const placeholder=baseline.files.find(f=>f.path==='mobile/.env.example');
314
+ assert.equal(placeholder.contentBase64,undefined);
315
+ assert.equal(typeof placeholder.sha256,'string');
316
+
317
+ // Selecting a placeholder as ordinary source is allowed too.
318
+ const selected=captureReviewBaseline({root,identity,scope:['mobile/.env.example'],
319
+ requirements:['requirements.md']}).files.find(f=>f.path==='mobile/.env.example');
320
+ assert.equal(Buffer.from(selected.contentBase64,'base64').toString(),
321
+ 'API_URL=https://example.invalid\n');
322
+
323
+ for(const secret of ['.env','.env.local','.env.production','.env.example.bak']){
324
+ write(root,secret,'SECRET=1\n');
325
+ assert.throws(()=>capture(root),{code:'unsupported_path'},`${secret} was not refused`);
326
+ assert.throws(()=>captureReviewBaseline({root,identity,scope:[secret],
327
+ requirements:['requirements.md']}),{code:'unsupported_path'},`${secret} was selectable`);
328
+ fs.rmSync(path.join(root,secret));
329
+ }
330
+
331
+ // The placeholder name must not become a way to smuggle a real secret in.
332
+ fs.writeFileSync(path.join(root,'.env'),'SECRET=real\n');
333
+ fs.symlinkSync('.env',path.join(root,'.env.disguise'));
334
+ fs.renameSync(path.join(root,'.env.disguise'),path.join(root,'.env.template'));
335
+ assert.throws(()=>capture(root),{code:'unsupported_path'},'the .env sibling was not refused');
336
+ fs.rmSync(path.join(root,'.env'));
337
+ assert.throws(()=>capture(root),/unsupported_file|unsupported_path|read_failed/,
338
+ 'a symlink wearing a placeholder name was captured');
339
+ fs.rmSync(path.join(root,'.env.template'));
340
+ }));
@@ -58,6 +58,30 @@ test('no change is distinct from partial and missing tools do not pass',t=>{
58
58
  assert.ok(r.tools.every(v=>v.reason==='tool_missing'));assert.equal(r.aiReview,'pending');
59
59
  });
60
60
 
61
+ // .env.example and friends are committed placeholder files meant to be copied.
62
+ // Treating them as real secret files hid exactly the case worth scanning: a real
63
+ // key pasted into the example. Only these four explicit suffixes are readable.
64
+ test('committed env examples are scanned while real env files stay protected',t=>{
65
+ const f=fixture(t);
66
+ for(const name of ['.env.example','.env.sample','.env.template','.env.dist'])f.put(name,'API_KEY=replace-me\n');
67
+ f.put('nested/.env.example','TOKEN=replace-me\n');
68
+ for(const name of ['.env','.env.local','.env.production','.env.example.bak'])f.put(name,'API_KEY=real\n');
69
+ f.git('add','.');
70
+ const r=inventory(f.project,{all:true});
71
+ const gap=name=>r.gaps.some(v=>v.path===name&&v.reason==='protected_path_not_read');
72
+ const read=name=>r.files.some(v=>v.path===name);
73
+ for(const name of ['.env.example','.env.sample','.env.template','.env.dist','nested/.env.example']){
74
+ assert.equal(read(name),true,`${name} 应当被扫描`);
75
+ assert.equal(gap(name),false,`${name} 不应记为受保护跳过`);
76
+ }
77
+ // Real secret files keep their existing protection, including a suffix that
78
+ // merely contains "example" rather than ending with it.
79
+ for(const name of ['.env','.env.local','.env.production','.env.example.bak']){
80
+ assert.equal(gap(name),true,`${name} 应当仍被保护`);
81
+ assert.equal(read(name),false,`${name} 不应被读取`);
82
+ }
83
+ });
84
+
61
85
  test('symlink ancestor, protected files and scanner controls are visible gaps',t=>{
62
86
  const f=fixture(t);f.put('dir/file.py','ok');f.put('.env','private fixture');f.put('.gitleaks.toml','malicious rule');f.git('add','.');
63
87
  fs.renameSync(path.join(f.project,'dir'),path.join(f.base,'outside'));
@@ -11,6 +11,10 @@
11
11
  纯视觉替代、裸项目走下文原owner分支,不能伪造命令或specs跨过。
12
12
  2. 从当前真实宿主确定 `--runtime codex|claude`,不能让模型选择另一端规避失败。
13
13
  用真实会话身份作为 `--host-context`;恢复必须保留原身份、配置与 runtime,不冒用旧会话。
14
+ 换会话恢复时,`--host-context` 填当前真实会话,另加 `--original-host-context` 填创建这次运行的旧会话 ID
15
+ (取自 `specs/.reviews/.execution/<runId>/state.json` 首条 `fix-configuration` 记录的
16
+ `configuration.hostContextId`)。durable 配置与指纹保持原样、旧记录一字不改;填错只会 `fingerprint_mismatch`
17
+ 失败退出。两个会话身份都算宿主:授权凭据两者皆可,reviewer 必须同时独立于两者。同会话重开不带此参数。
14
18
  3. 配置是数据文件,不是脚本模块。读取 `../../../scripts/cm-fix-host.mjs` 的配置解析与
15
19
  `--help`,按已批准范围填写 `specsRoot`、`identity`、`defect`、`reproduction`;后者为
16
20
  `{cwd, command, expectedFailure:{exitCode,outputIncludes}, timeoutMs}`,命令使用 argv 数组。
@@ -46,6 +50,17 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-fix-host.mjs" serve \
46
50
  复现/红测/存量基线/修后及审后回归/命令走查使用同一原生specs只读沙箱;日志、证据和Learning仍由原owner负责。
47
51
  固定命令执行器使用本机Codex sandbox,不调用模型;Claude宿主的推理和Review仍属Claude,不借用Codex身份或诊断。
48
52
 
53
+ 沙箱里 `network={enabled=false}`,而这个开关同时管着 unix domain socket 的 listen。于是**凡是要开本地
54
+ IPC socket 的命令都会失败**,典型的是 `tsx` CLI(启动时在 TMPDIR 建 `<pid>.pipe`,报
55
+ `Error: listen EPERM`),`vitest` 等同理;写 TMPDIR 文件本身不受影响。这不是配置能绕开的:放开它就等于
56
+ 给测试命令放开整个外网。配 `baseline.commands` / `redTest` / `walkthrough` 时请避开这类命令,例如把
57
+ `npm test`(内部串联 12 个 `tsx xxx.test.ts`)换成逐文件的
58
+ `node --import ./node_modules/tsx/dist/loader.mjs <file>`,覆盖面不变而沙箱能跑。
59
+
60
+ 沙箱内失败只会留下 `outcome:"failed"` 和 `host check exited N`——原始输出**有意**不进证据(可能含密钥、
61
+ 且不稳定)。要看真实原因,手工重放 `specsPermissionArgs` 拼出的那条 `codex sandbox ... -- <命令>`。
62
+ 配置里留了跑不了的命令,代价是修复前后都失败、回归判 `unresolved_failure`,整轮卡在 `regression_blocked`。
63
+
49
64
  `fix_test_author`/`fix_repair`请求若有`editMode:"protected-text-v1"`,当前会话只读取和生成提案,**不直接修改文件**。
50
65
  按请求scope和expected返回`{outcome,edits:[{path,beforeSha256,content}]}`,content为完整UTF-8正文,null删除已有文件,
51
66
  beforeSha256严格复制expected中该路径的摘要(原不存在则null);不能改路径范围或先自行落盘。blocked须edits为空数组。
@@ -132,7 +147,9 @@ handoff → 最终独立 Review/发布 → 原 N5 → 审后回归/走查 →
132
147
  第二次修复仍需 fresh 独立 Review;不得重置 ≤2 轮上限。unknown 不重派。
133
148
 
134
149
  修复完成仅认原 `finish` 的当前结果与证据;待授权、失败、漂移、缺证据如实报告,
135
- 不手工补成功。当前 finish 仅支持 delivery:diff;Git/发布/安装不在这些开关的权限内。
150
+ 不手工补成功。finish 接受 `policies.delivery` 的任一取值,只要求它在收尾写记录期间不变;
151
+ 它写档案/METRICS/task_done,**不执行 Git**——branch/draft-mr 的提交、推送、开 MR 仍由执行者按
152
+ SKILL 第 7 步单独完成并记 `delivery` 事件。Git/发布/安装都不在这些开关的权限内。
136
153
  退出通道用 `host_close` 或 EOF;只有用户明确取消才发 `cancel`。
137
154
 
138
155
  本接线是源 Skill 指令,不证明安装副本已加载或真实双宿主验收。保持原输出格式,
@@ -12,6 +12,7 @@ MANIFEST="$ROOT/manifest.txt"
12
12
  LOG="$ROOT/update.log"
13
13
  STAMP="$ROOT/.last-check"
14
14
  LOCK="$ROOT/.lock"
15
+ DISCARDED="$ROOT/discarded" # reset 前抢救出来的本地改动补丁
15
16
  ANNOUNCE="$ROOT/pending-announce" # 下次 Claude Code 启动时播报,由 cm-announce.sh 消费
16
17
  REMOTE="${CM_UPDATE_REMOTE:-git@github.com:kingxiaozhe/cm-workflow.git}" # 团队 fork 用环境变量覆盖,别改文件(会被自愈还原)
17
18
  BRANCH="${CM_UPDATE_BRANCH:-main}"
@@ -23,6 +24,35 @@ export GIT_SSH_COMMAND="ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new
23
24
 
24
25
  mkdir -p "$ROOT"
25
26
 
27
+ # repo/ 是更新器的缓存,不是给人开发的克隆:每次更新都会 reset --hard + clean -fd。
28
+ # 说明文件放在缓存目录之外,否则会被 clean 掉。
29
+ if [ ! -f "$ROOT/README.md" ]; then
30
+ cat >"$ROOT/README.md" <<'CMREADME'
31
+ # ~/.cm-workflow 是 CM Workflow 的私有工作目录
32
+
33
+ ## repo/ 是缓存,不要在里面改代码
34
+
35
+ `repo/` 由自动更新器管理。每次更新都会执行:
36
+
37
+ git reset --hard origin/<分支>
38
+ git clean -qfd
39
+
40
+ **它里面任何未提交的改动和未跟踪的新文件都会被丢弃,不另行询问。**
41
+ 它看起来是个正常的 git 克隆(remote 指向真仓库、`git log` 正常),
42
+ 但不要拿它当开发目录——请另外 `git clone` 一份。
43
+
44
+ 更新器在丢弃前会做两件事:把改动存成补丁放到 `discarded/`,并在
45
+ `update.log` 里记一行、同时发一条系统通知。补丁可以用
46
+ `git apply` 打回你自己的克隆。
47
+
48
+ ## 其他内容
49
+
50
+ - `update.log`:更新日志
51
+ - `logs/`:各工作流的运行日志(本机私有,不外发)
52
+ - `discarded/`:被更新器丢弃的本地改动补丁
53
+ CMREADME
54
+ fi
55
+
26
56
  log() { printf '%s %s\n' "$(date '+%F %T')" "$*" >>"$LOG"; }
27
57
  notify() { osascript -e "display notification \"$2\" with title \"$1\"" >/dev/null 2>&1 || true; }
28
58
  die() { log "✗ $*"; exit 1; }
@@ -199,6 +229,27 @@ if [ "$local_sha" = "$remote_sha" ] && [ -f "$MANIFEST" ] && [ "$FORCE" = 0 ]; t
199
229
  fi
200
230
 
201
231
  new_commits="$(git log --oneline "HEAD..origin/$BRANCH" 2>/dev/null | head -5)"
232
+
233
+ # 缓存目录里不该有人工改动,但确实发生过。丢弃之前先存一份补丁并明确告警,
234
+ # 不要让它无声消失。抢救失败不阻塞更新——缓存与远端一致才是这里的第一要务。
235
+ dirty="$(git status --porcelain 2>/dev/null)"
236
+ if [ -n "$dirty" ]; then
237
+ dirty_n="$(printf '%s\n' "$dirty" | wc -l | tr -d ' ')"
238
+ mkdir -p "$DISCARDED"
239
+ patch="$DISCARDED/$(date '+%Y%m%dT%H%M%S').patch"
240
+ {
241
+ printf '# 更新器在 %s 丢弃的本地改动(%s 个条目)\n' "$(date '+%F %T')" "$dirty_n"
242
+ printf '# 已跟踪文件的改动可用 git apply 打回自己的克隆;未跟踪文件只列出路径。\n\n'
243
+ git diff HEAD 2>/dev/null
244
+ printf '\n# 未跟踪文件(内容未保存):\n'
245
+ git ls-files --others --exclude-standard 2>/dev/null | sed 's|^|# |'
246
+ } >"$patch" 2>/dev/null || patch=""
247
+ log "⚠ repo/ 有 $dirty_n 处本地改动,将被更新丢弃:"
248
+ log "$(printf '%s\n' "$dirty" | head -20 | sed 's|^| |')"
249
+ [ -n "$patch" ] && log " 已存补丁:$patch"
250
+ notify "CM Workflow 更新" "repo/ 的 $dirty_n 处本地改动已被丢弃,补丁见 discarded/"
251
+ fi
252
+
202
253
  git reset --hard --quiet "origin/$BRANCH" || die "reset 到 origin/$BRANCH 失败"
203
254
  git clean -qfd
204
255
  VERSION="$(cat "$REPO/VERSION" 2>/dev/null || echo 未知)"