@aibyzero/cm-workflow 0.21.5 → 0.21.6

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-workflow",
3
- "version": "0.21.5",
3
+ "version": "0.21.6",
4
4
  "description": "Spec-driven product development workflow for Codex: external research, PRD, implementation, read-only feature testing, review, QA, fixes, refactors, and documentation.",
5
5
  "author": {
6
6
  "name": "cm-workflow maintainers",
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
 
6
6
  ## 未发布
7
7
 
8
+ (暂无)
9
+
10
+ ## 0.21.6 — 2026-11-25
11
+
12
+ - **修复 Claude 兼容安装下技能的 docs 链接失效**:安装时把本包技能里的 `../docs/` 链接改写为 `../cm-workflow/docs/`,并随包写入范围清单,`cm-check` 机器检查链接可达且不误查用户自装技能;`cm-notify` 不属于读取运行时合同的核心技能,第 2 组口径与检查一并改正。
13
+ - **修复 `cm-check-drive` 被大文件误阻断**:快照不再让超过 1MB 的非 CM 文本触发 `init_draft_target_invalid`,超限文件按内容摘要或大小与时间核对漂移,阻断信息带出具体文件路径。
14
+
8
15
  ## 0.21.5 — 2026-11-25
9
16
 
10
17
  - **cm-prd 设计阶段支持修正后窄审,最多两轮**:设计审查返回问题、原修正保存后,同一份审查包下可用 `narrow_review` 记录窄审(审查方、会话、逐条分级、四个是否题、阻断触发场景),作者据此再修正,每轮修正必须有对应审查记录并逐项写处置;第三轮被拒,第二轮仍有阻断停在「待用户拍板」,不自动放行。有窄审记录时,原处置回执和旧入口 `record` 都要窄审通过。只对新写出的原修正存档生效,在途旧运行与 split 阶段不变。
package/README.md CHANGED
@@ -17,6 +17,11 @@
17
17
 
18
18
  ## 最近更新
19
19
 
20
+ **0.21.6**
21
+
22
+ - **修复 Claude 兼容安装下技能里的文档链接失效**:技能里指向 `docs/` 的链接装完后能打开;`cm-check` 新增链接可达检查,不会误查你自己装的技能。
23
+ - **修复 `cm-check` 被大文件误阻断**:技能目录里有超过 1MB 的文本(如其他技能自带的压缩脚本)时不再启动即报 `init_draft_target_invalid`,阻断信息会指出具体文件。详见[更新日志](CHANGELOG.md)。
24
+
20
25
  **0.21.5**
21
26
 
22
27
  - **cm-ai 新任务支持软链**:项目里有软链不再一建基线就报错;开发可以新建、改指向或删除软链,CM 会核对它不指出项目、不指进 `.git` 和规格目录。已有任务不受影响。
@@ -293,7 +298,7 @@ $cm-check
293
298
 
294
299
  仓库直接分发 Skills 和脚本,无需在仓库根目录运行 `npm install` 或构建。完整安装行为、覆盖范围和卸载说明见[安装指南](docs/installation.md)。
295
300
 
296
- 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.5 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
301
+ 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.6 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
297
302
 
298
303
  ## 升级旧版本
299
304
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.21.5
1
+ 0.21.6
@@ -76,7 +76,7 @@ Install or upgrade with the same command:
76
76
  npx @aibyzero/cm-workflow@latest install
77
77
  ```
78
78
 
79
- To pin a version, use `npx @aibyzero/cm-workflow@0.21.5 install` from outside
79
+ To pin a version, use `npx @aibyzero/cm-workflow@0.21.6 install` from outside
80
80
  the CM Workflow source checkout (for example, your home directory). Inside a
81
81
  checkout with the same package name and version, npm can select the local
82
82
  uninstalled package and report `cm-workflow: command not found`.
package/install.ps1 CHANGED
@@ -114,6 +114,9 @@ try {
114
114
  Stage-Tree (Join-Path $Src "docs") "cm-workflow\docs"
115
115
  Stage-Tree (Join-Path $Src "assets") "cm-workflow\assets"
116
116
  Stage-File (Join-Path $Src "README.md") "cm-workflow\README.md"
117
+ # docs 装在 cm-workflow\docs,技能里的 ../docs/ 相对链接要跟着改写。
118
+ node (Join-Path $Src "scripts\cm-rewrite-doc-links.mjs") $Stage | Out-Null
119
+ if ($LASTEXITCODE -ne 0) { throw "改写文档链接失败。" }
117
120
 
118
121
  foreach ($pair in @(
119
122
  @("dashboard", "dashboard"),
package/install.sh CHANGED
@@ -374,6 +374,8 @@ done
374
374
  stage_tree "$SRC_DIR/docs" "cm-workflow/docs"
375
375
  stage_tree "$SRC_DIR/assets" "cm-workflow/assets"
376
376
  stage_file "$SRC_DIR/README.md" "cm-workflow/README.md"
377
+ # docs 装在 cm-workflow/docs/,技能里的 ../docs/ 相对链接要跟着改写。
378
+ node "$SRC_DIR/scripts/cm-rewrite-doc-links.mjs" "$STAGE" >/dev/null || { echo "改写文档链接失败,安装已停止,未修改任何文件。" >&2; exit 1; }
377
379
 
378
380
  for wrapper in "$SRC_DIR"/compat/claude-commands/cm-*.md; do
379
381
  name="$(basename "$wrapper" .md)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.21.5",
3
+ "version": "0.21.6",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -6,8 +6,17 @@ import {createCmCheckInvocation} from '../../../scripts/cm-check-entry.mjs';
6
6
  import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
7
7
  import {need,shape,json,digest} from '../cm-ai/effect-contract.mjs';
8
8
 
9
- const directories=['skills','runtime','agents','compat/claude-commands','templates','scripts','.codex-plugin'];
10
- const topFiles=['VERSION','README.md','package.json','install.sh','install.ps1','install-codex.sh','install-codex.ps1'];
9
+ const directories=['skills','runtime','agents','compat/claude-commands','templates','scripts','.codex-plugin','docs','cm-workflow/docs'];
10
+ const topFiles=['cm-workflow/doc-links-scope.txt','VERSION','README.md','package.json','install.sh','install.ps1','install-codex.sh','install-codex.ps1'];
11
+ const READ_LIMIT=1048576; // 与 readCmInitSource 的单文件上限一致
12
+ const OVERSIZE_HASH_LIMIT=16*1024*1024;
13
+ function readOversize(file,size){
14
+ const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
15
+ try{
16
+ const opened=fs.fstatSync(fd);need(opened.isFile()&&opened.nlink===1&&opened.size===size,'check_source_changed');
17
+ const bytes=Buffer.alloc(size);need(fs.readSync(fd,bytes,0,size,0)===size,'check_source_changed');return bytes;
18
+ }finally{fs.closeSync(fd);}
19
+ }
11
20
  const optionalIds=['statusline','updater','subagents','isolated_review','external_browser'];
12
21
  // Groups 1 and 7 inspect the Codex plugin manifest, the root VERSION and the root README.
13
22
  // A Claude-compatible installation legitimately owns none of them, so only these two may be
@@ -24,14 +33,27 @@ function snapshot(root){
24
33
  if(stat.isDirectory()){
25
34
  need(fs.realpathSync(target)===target,'check_source_path_changed');
26
35
  files[relative]={directory:true};
27
- for(const name of fs.readdirSync(target).sort())visit(relative+'/'+name);
36
+ let names;
37
+ try{names=fs.readdirSync(target).sort();}catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
38
+ for(const name of names)visit(relative+'/'+name);
28
39
  }else{
29
40
  need(stat.isFile()&&stat.nlink===1,'check_source_file_invalid');
30
- if(/\.(?:md|mjs|js|json|ya?ml|py|sh|ps1|toml|txt|ts|css|html)$/.test(relative)||relative==='VERSION'){
41
+ // 超过 readCmInitSource 单文件上限(1MB)的文本(如非 CM 技能自带的 babel.min.js,约 3MB)不再走它,
42
+ // 否则整次检查会以 init_draft_target_invalid 阻断(2026-11 反馈:~/.claude/skills/huashu-design)。
43
+ // 仍要发现检查期间的改动:16MB 内的按内容算摘要,更大的只记大小与修改时间。
44
+ const text=/\.(?:md|mjs|js|json|ya?ml|py|sh|ps1|toml|txt|ts|css|html)$/.test(relative)||relative==='VERSION';
45
+ if(text&&stat.size<=READ_LIMIT){
31
46
  bytes+=stat.size;need(bytes<=64*1024*1024,'check_inventory_limit');
32
- const data=readCmInitSource(root,relative);need(data!==null,'check_source_changed');
47
+ let data;
48
+ try{data=readCmInitSource(root,relative);need(data!==null,'check_source_changed');}
49
+ catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
33
50
  files[relative]={digest:digest(data.toString('base64')),lines:data.toString('utf8').split('\n').length};
34
- }else files[relative]={size:stat.size,mode:stat.mode&0o777};
51
+ }else if(text&&stat.size<=OVERSIZE_HASH_LIMIT){
52
+ bytes+=stat.size;need(bytes<=64*1024*1024,'check_inventory_limit');
53
+ let data;
54
+ try{data=readOversize(target,stat.size);}catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
55
+ files[relative]={size:stat.size,mode:stat.mode&0o777,oversized:true,digest:digest(data.toString('base64')),lines:data.toString('utf8').split('\n').length};
56
+ }else files[relative]={size:stat.size,mode:stat.mode&0o777,...(text?{oversized:true,mtimeMs:stat.mtimeMs,ctimeMs:stat.ctimeMs}:{})};
35
57
  }
36
58
  }
37
59
  for(const relative of [...directories,...topFiles])visit(relative);
@@ -51,7 +73,14 @@ export function createCmCheckHost(raw,{call}){
51
73
  return {...source,digest:digest({source:source.digest,configs})};
52
74
  };
53
75
  const status=()=>json({stage,mechanical,result,completionAuthorized:false});
54
- const current=baseline=>need(capture().digest===baseline.digest,'check_source_changed');
76
+ const current=baseline=>{
77
+ const now=capture();
78
+ if(now.digest===baseline.digest)return;
79
+ const e=new Error('check_source_changed');e.code='check_source_changed';
80
+ const keys=[...new Set([...Object.keys(baseline.files),...Object.keys(now.files)])].sort();
81
+ const file=keys.find(k=>JSON.stringify(baseline.files[k])!==JSON.stringify(now.files[k]));
82
+ if(file)e.file=file;throw e;
83
+ };
55
84
  async function start(){
56
85
  need(stage==='ready','check_already_started');stage='mechanical';
57
86
  try{
@@ -110,7 +139,7 @@ export function createCmCheckHost(raw,{call}){
110
139
  findingsCount:assessment.checks.filter(row=>row.status==='failed').reduce((sum,row)=>sum+row.findings.length,0),
111
140
  semanticChecked:true,completionAuthorized:false};
112
141
  stage='reported';return status();
113
- }catch(error){stage=controller.signal.aborted?'cancelled':'blocked';result={overall:'BLOCKED',reason:error?.code??'check_failed',completionAuthorized:false};return status();}
142
+ }catch(error){stage=controller.signal.aborted?'cancelled':'blocked';result={overall:'BLOCKED',reason:error?.code??'check_failed',...(typeof error?.file==='string'?{file:error.file}:{}),completionAuthorized:false};return status();}
114
143
  }
115
144
  return Object.freeze({async handle(request){
116
145
  shape(request,['requestId','operation']);
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ // 校验本包技能 *.md 里指向 docs 的相对引用(Markdown 链接和反引号路径)在当前安装布局下可达。
3
+ // 插件/源码布局 docs 在根目录;Claude 兼容布局在 cm-workflow/docs(安装时已改写)。
4
+ import { existsSync } from 'node:fs';
5
+ import { dirname, relative, resolve } from 'node:path';
6
+ import { pathToFileURL } from 'node:url';
7
+ import { listDocRefs, makeBoundedReader, managedSkillMarkdown, mapOutsideFences } from './cm-doc-links-shared.mjs';
8
+
9
+ export function findBrokenDocLinks(root) {
10
+ const broken = [];
11
+ const read = makeBoundedReader();
12
+ for (const file of managedSkillMarkdown(root)) {
13
+ mapOutsideFences(read(file), (part) => {
14
+ for (const m of listDocRefs(part)) {
15
+ const target = m.up + (m.done || '') + m.rest;
16
+ if (!existsSync(resolve(dirname(file), target))) broken.push(`${relative(root, file)} -> ${target}`);
17
+ }
18
+ return part;
19
+ });
20
+ }
21
+ return broken;
22
+ }
23
+
24
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
25
+ let broken;
26
+ try { broken = findBrokenDocLinks(resolve(process.argv[2] || '.')); } catch (e) { console.error(`broken docs link: ${e.message}`); process.exit(1); }
27
+ for (const b of broken) console.error(`broken docs link: ${b}`);
28
+ process.exit(broken.length ? 1 : 0);
29
+ }
@@ -49,6 +49,52 @@ test('actual JSONL CLI runs fixture checker once then eight groups; optional deg
49
49
  assert.equal(result.mechanical.output,'original checker output\noriginal stderr\n');assert.equal(result.result.completionAuthorized,false);
50
50
  assert.deepEqual(fs.readdirSync(f.input.project),[]);
51
51
  });
52
+ test('snapshot 遇到超过 1MB 的非 CM 技能文本只记大小,不阻断检查',{timeout:5000},async t=>{
53
+ const f=fixture(t);const big=path.join(f.dir,'skills/other-skill/assets/vendor/babel.min.js');
54
+ fs.mkdirSync(path.dirname(big),{recursive:true});fs.writeFileSync(big,Buffer.alloc(1048576+1024,97));
55
+ const host=createCmCheckHost(f.input,{call:async(kind,payload)=>kind==='check_runtime'?mechanical(payload):assessment(payload)});
56
+ const value=await host.handle({requestId:'start',operation:'start'});
57
+ assert.equal(value.result.overall,'PASSED',JSON.stringify(value));
58
+ });
59
+ test('超过 1MB 的 CM 文本在检查期间被等长改一个字节仍判为源码漂移;读失败的阻断带文件路径',{timeout:8000},async t=>{
60
+ const f=fixture(t);const big=path.join(f.dir,'skills/cm-check/big.md');fs.writeFileSync(big,Buffer.alloc(1048576+1024,97));
61
+ const host=createCmCheckHost(f.input,{call:async(kind,payload)=>{
62
+ if(kind==='check_runtime')return mechanical(payload);
63
+ const bytes=fs.readFileSync(big);bytes[10]=98;fs.writeFileSync(big,bytes);return assessment(payload);}});
64
+ const drift=await host.handle({requestId:'start',operation:'start'});
65
+ assert.equal(drift.result.overall,'BLOCKED',JSON.stringify(drift));
66
+ const g=fixture(t);const locked=path.join(g.dir,'skills/cm-check/locked.md');fs.writeFileSync(locked,'x');fs.chmodSync(locked,0o000);
67
+ t.after(()=>{try{fs.chmodSync(locked,0o644);}catch{}});
68
+ if(process.getuid?.()!==0){
69
+ const blocked=await createCmCheckHost(g.input,{call:async()=>{throw Error('must not run');}}).handle({requestId:'start',operation:'start'});
70
+ assert.equal(blocked.result.overall,'BLOCKED');assert.equal(blocked.result.file,'skills/cm-check/locked.md');
71
+ }
72
+ });
73
+ test('大文件的读取计入 64MiB 预算;超 16MB 的文本等长改写(ctime 变)也判漂移;漂移与目录读失败的阻断带路径;大文件可作证据',{timeout:30000},async t=>{
74
+ const run=async(f,mutate)=>createCmCheckHost(f.input,{call:async(kind,payload)=>{if(kind==='check_runtime')return mechanical(payload);mutate?.(payload);return assessment(payload);}}).handle({requestId:'start',operation:'start'});
75
+ const f=fixture(t);for(let i=0;i<5;i++)fs.writeFileSync(path.join(f.dir,`skills/cm-check/b${i}.md`),Buffer.alloc(14*1024*1024,97));
76
+ assert.equal((await run(f)).result.reason,'check_inventory_limit');
77
+ const g=fixture(t);const huge=path.join(g.dir,'skills/cm-check/huge.md');fs.writeFileSync(huge,Buffer.alloc(17*1024*1024,97));
78
+ const d=await run(g,()=>{const b=fs.readFileSync(huge);b[5]=98;fs.writeFileSync(huge,b);});
79
+ assert.equal(d.result.reason,'check_source_changed');assert.equal(d.result.file,'skills/cm-check/huge.md');
80
+ const h=fixture(t);const mid=path.join(h.dir,'skills/cm-check/mid.md');fs.writeFileSync(mid,Buffer.alloc(1048576+10,97));
81
+ const ok=createCmCheckHost(h.input,{call:async(kind,payload)=>{if(kind==='check_runtime')return mechanical(payload);const v=assessment(payload);v.checks[0].evidence=[{path:'skills/cm-check/mid.md',line:1}];return v;}});
82
+ assert.equal((await ok.handle({requestId:'start',operation:'start'})).result.overall,'PASSED');
83
+ if(process.getuid?.()!==0){
84
+ const k=fixture(t);const dir=path.join(k.dir,'skills/cm-check/locked');fs.mkdirSync(dir);fs.chmodSync(dir,0o000);
85
+ try{assert.equal((await run(k)).result.file,'skills/cm-check/locked');}finally{fs.chmodSync(dir,0o755);}
86
+ }
87
+ });
88
+ test('docs 目录进入快照:检查期间删掉被技能链接指向的文档会被判漂移',{timeout:8000},async t=>{
89
+ const f=fixture(t);fs.mkdirSync(path.join(f.dir,'docs'));const doc=path.join(f.dir,'docs/user-guide.md');fs.writeFileSync(doc,'x');
90
+ const r=await createCmCheckHost(f.input,{call:async(kind,payload)=>{if(kind==='check_runtime')return mechanical(payload);fs.unlinkSync(doc);return assessment(payload);}}).handle({requestId:'start',operation:'start'});
91
+ assert.equal(r.result.reason,'check_source_changed');
92
+ });
93
+ test('范围清单进入快照:检查期间改它(改变受管范围)会被判漂移',{timeout:8000},async t=>{
94
+ const f=fixture(t);fs.mkdirSync(path.join(f.dir,'cm-workflow'));const scope=path.join(f.dir,'cm-workflow/doc-links-scope.txt');fs.writeFileSync(scope,'# cm-workflow doc-links scope v1 count=0\n');
95
+ const r=await createCmCheckHost(f.input,{call:async(kind,payload)=>{if(kind==='check_runtime')return mechanical(payload);fs.writeFileSync(scope,'# cm-workflow doc-links scope v1 count=1\nskills/x/SKILL.md\n');return assessment(payload);}}).handle({requestId:'start',operation:'start'});
96
+ assert.equal(r.result.reason,'check_source_changed');
97
+ });
52
98
  test('mechanical failure stops semantics, repeated start never retries',async t=>{
53
99
  const f=fixture(t,7);let calls=0;const host=createCmCheckHost(f.input,{call:async(kind,payload)=>{calls++;assert.equal(kind,'check_runtime');return mechanical(payload);}});
54
100
  const value=await host.handle({requestId:'start',operation:'start'});assert.equal(value.result.overall,'FAILED');assert.equal(value.result.semanticChecked,false);
@@ -360,6 +360,12 @@ for correction_command in prepare-human-correction publish-human-correction-revi
360
360
  grep -Fq "$correction_command" "$ROOT/$HUMAN_CORRECTION_DOC" ||
361
361
  fail "human correction command/document pair incomplete: $correction_command"
362
362
  done
363
+ # Skill docs links must resolve in this layout (0.21.5: claude-compat links pointed at a missing ~/.claude/docs).
364
+ if [ -n "$NODE_BIN" ] && [ -f "$ROOT/scripts/cm-check-doc-links.mjs" ]; then
365
+ "$NODE_BIN" "$ROOT/scripts/cm-check-doc-links.mjs" "$ROOT" || fail "skills docs links do not resolve in $MODE layout (see broken docs link lines above)"
366
+ else
367
+ fail "missing scripts/cm-check-doc-links.mjs or node for docs link check"
368
+ fi
363
369
  require_file "scripts/cm-workflow-config.mjs"
364
370
  require_file "scripts/cm-workflow-config.test.mjs"
365
371
  # Group 4: user runtimes.yml producers <-> authoritative consumer.
@@ -708,6 +714,15 @@ for name in cm-challenge cm-idea cm-init cm-prd cm-ai cm-test cm-security cm-fix
708
714
  fi
709
715
  done
710
716
 
717
+ # cm-check 第 2 组口径:除独立配置工具 cm-notify 外,核心 Skill 必须用链接或反引号路径引用真实存在的 runtime/ 合同。
718
+ for name in cm-idea cm-init cm-prd cm-ai cm-test cm-security cm-fix cm-refactor cm-check cm-runtime; do
719
+ runtime_ref_ok=0
720
+ for ref in $(grep -oE '(\]\(\.\./\.\./runtime/[A-Za-z0-9._/-]+\.(md|json|mjs)[)#]|`\.\./\.\./runtime/[A-Za-z0-9._/-]+\.(md|json|mjs)[`#])' "$ROOT/skills/$name/SKILL.md" | sed -E 's/^(\]\(|`)//; s/.$//'); do
721
+ [ -f "$ROOT/skills/$name/$ref" ] && runtime_ref_ok=1
722
+ done
723
+ [ "$runtime_ref_ok" -eq 1 ] || fail "core skill has no resolvable runtime/ contract reference: skills/$name/SKILL.md"
724
+ done
725
+
711
726
  for reference in \
712
727
  skills/cm-idea/references/idea-to-prd.md \
713
728
  skills/cm-idea/references/example-prd.md \
@@ -12,12 +12,24 @@ test('real isolated Claude install checks correction docs at its installed layou
12
12
  t.after(()=>fs.rmSync(home,{recursive:true,force:true}));
13
13
  const target=path.join(home,'.claude'),env={...process.env,HOME:home,CLAUDE_HOME:target,
14
14
  CM_WORKFLOW_HOME:path.join(home,'user'),CM_WORKFLOW_LOG_HOME:path.join(home,'logs'),CM_MATT_SKILLS_INSTALL:'off'};
15
+ // 用户自装、带断链的技能(首次安装时目标里已存在)不得让安装的自检失败或回滚。
16
+ fs.mkdirSync(path.join(target,'skills/cm-user-own'),{recursive:true});
17
+ fs.writeFileSync(path.join(target,'skills/cm-user-own/SKILL.md'),'---\nname: cm-user-own\ndescription: 用户自装技能\n---\n[x](../../docs/none.md)\n');
15
18
  const installed=spawnSync('/bin/bash',[path.join(source,'install.sh'),'--yes'],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
16
19
  assert.equal(installed.status,0,installed.stdout+installed.stderr);
17
20
  assert.match(installed.stdout,/cm runtime check: PASSED \(claude-compat v/);
18
21
  const doc=path.join(target,'cm-workflow/docs/human-correction.md');
19
22
  assert.equal(fs.readFileSync(doc,'utf8'),fs.readFileSync(path.join(source,'docs/human-correction.md'),'utf8'));
20
23
  assert.equal(fs.existsSync(path.join(target,'docs/human-correction.md')),false);
24
+ const notify=fs.readFileSync(path.join(target,'skills/cm-notify/SKILL.md'),'utf8');
25
+ assert.match(notify,/\.\.\/\.\.\/cm-workflow\/docs\/user-guide\.md/);
26
+ assert.equal(fs.readFileSync(path.join(source,'skills/cm-notify/SKILL.md'),'utf8').includes('../../cm-workflow/docs/'),false);
27
+ const scope=fs.readFileSync(path.join(target,'cm-workflow/doc-links-scope.txt'),'utf8');
28
+ assert.match(scope,/skills\/cm-notify\/SKILL\.md/);
29
+ assert.equal(scope.includes('cm-user-own'),false);
30
+ assert.equal(fs.readFileSync(path.join(target,'skills/cm-user-own/SKILL.md'),'utf8'),'---\nname: cm-user-own\ndescription: 用户自装技能\n---\n[x](../../docs/none.md)\n');
31
+ const links=spawnSync(process.execPath,[path.join(target,'scripts/cm-check-doc-links.mjs'),target],{encoding:'utf8'});
32
+ assert.equal(links.status,0,links.stderr);
21
33
  fs.unlinkSync(doc);
22
34
  const rejected=spawnSync('/bin/bash',[path.join(target,'scripts/cm-check-runtime.sh'),'--project',source],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
23
35
  assert.notEqual(rejected.status,0);
@@ -0,0 +1,139 @@
1
+ // 改写与检查共用同一套“哪些是指向本包 docs 的相对引用”的识别规则,避免两边漂移。
2
+ import { closeSync, existsSync, lstatSync, openSync, readSync, readdirSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+
5
+ // 范围清单:安装器在暂存目录生成、随包装入 <根>/cm-workflow/,列出本包自带的 skills/**/*.md。
6
+ // 检查只看清单里的文件,所以用户自装的技能(含同样以 cm- 开头的)不会被误判;
7
+ // 两个安装器(含不生成安装清单的 PowerShell)用同一份,不依赖安装清单的发布时机。
8
+ export const SCOPE_FILE = 'cm-workflow/doc-links-scope.txt';
9
+ const SCOPE_HEADER = '# cm-workflow doc-links scope v1';
10
+ // 单个技能文档读取上限;超过按错误处理,不整份读进内存(与快照的预算同口径)。
11
+ export const MAX_DOC_BYTES = 1024 * 1024;
12
+ export const MAX_TOTAL_BYTES = 64 * 1024 * 1024;
13
+
14
+ // 只认两种写法:Markdown 链接目标 ](…) 和整段反引号路径 `…`,且路径后必须紧跟收尾符:
15
+ // 链接:) 或 # 或 空白+标题;反引号:` 或 #。
16
+ // 外链(https://x/?next=../../docs/y)、普通文字、带命令行后缀的反引号(`../docs/g.md --dry-run`)都不算。
17
+ // 兼容安装已改写形态 ../cm-workflow/docs/ 也要认,检查才能发现它指向的文档被删。
18
+ const PATH = String.raw`((?:\.\.\/)+)(cm-workflow\/)?(docs\/[^\s)\`'"#>\]]*)`;
19
+ const DOC_REF = new RegExp(
20
+ String.raw`(?<=\]\()` + PATH + String.raw`(?=[)#]|\s+["'(])|(?<=\`)` + PATH + String.raw`(?=[\`#])`,
21
+ 'g',
22
+ );
23
+
24
+ // 统一成 (上级前缀, 已含 cm-workflow/ 否, docs 路径) 回调;返回值替换原匹配。
25
+ export function replaceDocRefs(text, fn) {
26
+ return text.replace(DOC_REF, (...a) => fn(a[1] ?? a[4], a[2] ?? a[5], a[3] ?? a[6], a[0]));
27
+ }
28
+ export function listDocRefs(text) {
29
+ const out = [];
30
+ replaceDocRefs(text, (up, done, rest, whole) => { out.push({ up, done, rest }); return whole; });
31
+ return out;
32
+ }
33
+
34
+ // 围栏代码块(``` 或 ~~~,可缩进 0–3 格、可在引用块 > 内,结束围栏可更长,未闭合则到文末)里的示例不改、不查。
35
+ // 逐行判断:引用块层数(> 的个数)比开围栏时少,说明引用块已结束,围栏随之结束,该行按正文处理;
36
+ // 结束围栏必须与开围栏同字符、不短于它、层数相同、后面只有空白。
37
+ // 缩进总共至多 3 格:无引用块时只认开头的缩进;有引用块时 > 之后允许再缩进至多 3 格。
38
+ const LINE_PREFIX = /^(?:[ ]{0,3}((?:>[ \t]?)+)[ ]{0,3}|[ ]{0,3})/; // 缩进只数空格:Tab 占 4 列,已超上限
39
+ export function mapOutsideFences(text, fn) {
40
+ let out = '';
41
+ let plain = '';
42
+ let fence = null; // {ch, len, depth}
43
+ for (const line of text.split(/(?<=\n)/)) {
44
+ const pm = line.match(LINE_PREFIX);
45
+ const depth = ((pm[1] || '').match(/>/g) || []).length;
46
+ const rest = line.slice(pm[0].length);
47
+ if (fence && depth < fence.depth) fence = null;
48
+ if (fence) {
49
+ const close = rest.match(/^(`{3,}|~{3,})[ \t]*\r?\n?$/);
50
+ if (depth === fence.depth && close && close[1][0] === fence.ch && close[1].length >= fence.len) fence = null;
51
+ out += line;
52
+ continue;
53
+ }
54
+ const open = rest.match(/^(`{3,}|~{3,})/);
55
+ if (open) {
56
+ out += fn(plain) + line;
57
+ plain = '';
58
+ fence = { ch: open[1][0], len: open[1].length, depth };
59
+ } else plain += line;
60
+ }
61
+ return out + fn(plain);
62
+ }
63
+
64
+ function walk(dir, out) {
65
+ for (const name of readdirSync(dir).sort()) {
66
+ const p = join(dir, name);
67
+ const st = lstatSync(p);
68
+ if (st.isSymbolicLink()) continue;
69
+ if (st.isDirectory()) walk(p, out);
70
+ else if (name.endsWith('.md')) out.push(p);
71
+ }
72
+ }
73
+
74
+ // 暂存目录里 skills/ 全是本包的:改写与生成范围清单用它。
75
+ export function stagedSkillMarkdown(stageRoot) {
76
+ const out = [];
77
+ walk(join(stageRoot, 'skills'), out);
78
+ return out;
79
+ }
80
+
81
+ export function scopeText(stageRoot) {
82
+ const rel = stagedSkillMarkdown(stageRoot).map((p) => p.slice(stageRoot.length + 1).split('\\').join('/'));
83
+ return `${SCOPE_HEADER} count=${rel.length}\n${rel.join('\n')}\n`;
84
+ }
85
+
86
+ // 本包管理的技能文档。
87
+ // - 有范围清单:只取清单里的文件;头部数量与实际行数不符(被截断)、清单为空、清单里的文件缺失,都抛错,不静默跳过。
88
+ // - 无清单且根下有 cm-workflow/docs(兼容安装布局;源码与插件根没有 cm-workflow/,与用户自己的 docs/ 无关):抛错,因为无法区分本包与用户自装技能。
89
+ // - 其余(源码、插件、安装暂存目录):skills/ 全是本包的。
90
+ export function managedSkillMarkdown(root) {
91
+ const scope = join(root, SCOPE_FILE);
92
+ if (existsSync(scope)) {
93
+ const lines = readBounded(scope, MAX_DOC_BYTES).split('\n').filter((l) => l !== '');
94
+ const head = lines[0] && lines[0].match(/^# cm-workflow doc-links scope v1 count=(\d+)$/);
95
+ const files = lines.slice(1);
96
+ if (!head || Number(head[1]) !== files.length || files.length === 0) {
97
+ throw new Error(`范围清单损坏或被截断: ${SCOPE_FILE}`);
98
+ }
99
+ return files.map((rel) => {
100
+ if (!/^skills\/.+\.md$/.test(rel) || rel.includes('\\') || rel.split('/').some((seg) => seg === '' || seg === '.' || seg === '..')) throw new Error(`范围清单含非法路径: ${rel}`);
101
+ const p = join(root, rel);
102
+ if (!existsSync(p)) throw new Error(`范围清单里的文件不存在: ${rel}`);
103
+ return p;
104
+ });
105
+ }
106
+ if (existsSync(join(root, 'cm-workflow', 'docs'))) {
107
+ throw new Error(`兼容安装缺少范围清单 ${SCOPE_FILE},无法区分本包技能与自装技能;请重新安装`);
108
+ }
109
+ const out = [];
110
+ walk(join(root, 'skills'), out);
111
+ return out;
112
+ }
113
+
114
+ // 限量读取:最多读 limit+1 字节,超过 limit 即抛错;不依赖先 stat 再读(文件可能在两步之间变大)。
115
+ function readBuffer(file, limit) {
116
+ const fd = openSync(file, 'r');
117
+ try {
118
+ const buf = Buffer.alloc(limit + 1);
119
+ let n = 0;
120
+ for (;;) {
121
+ const got = readSync(fd, buf, n, buf.length - n, null);
122
+ if (got === 0) break;
123
+ n += got;
124
+ if (n > limit) throw new Error(`文件超过 ${limit} 字节上限: ${file}`);
125
+ }
126
+ return buf.subarray(0, n);
127
+ } finally { closeSync(fd); }
128
+ }
129
+ export function readBounded(file, limit) { return readBuffer(file, limit).toString('utf8'); }
130
+
131
+ // 技能文档读取:单文件 MAX_DOC_BYTES,累计 MAX_TOTAL_BYTES,均按实际读到的字节算。
132
+ export function makeBoundedReader() {
133
+ let total = 0;
134
+ return (file) => {
135
+ const buf = readBuffer(file, Math.min(MAX_DOC_BYTES, MAX_TOTAL_BYTES - total));
136
+ total += buf.length; // 实际读到的字节数,不是解码后的字符数
137
+ return buf.toString('utf8');
138
+ };
139
+ }
@@ -0,0 +1,110 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import {spawnSync} from 'node:child_process';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {rewriteText,rewriteTree} from './cm-rewrite-doc-links.mjs';
9
+ import {findBrokenDocLinks} from './cm-check-doc-links.mjs';
10
+ import {SCOPE_FILE,scopeText,MAX_DOC_BYTES,readBounded} from './cm-doc-links-shared.mjs';
11
+ const source=fileURLToPath(new URL('..',import.meta.url));
12
+ const tmp=t=>{const d=fs.mkdtempSync(path.join(os.tmpdir(),'cm-doc-links-'));t.after(()=>fs.rmSync(d,{recursive:true,force:true}));return d;};
13
+ test('rewriteText 只改 ../ 开头的 docs 链接,不动项目自己的 docs/ 路径',()=>{
14
+ assert.equal(rewriteText('[a](../../docs/x.md) [b](../../../docs/y.md#z) `docs/architecture.md`'),
15
+ '[a](../../cm-workflow/docs/x.md) [b](../../../cm-workflow/docs/y.md#z) `docs/architecture.md`');
16
+ });
17
+ test('rewriteText 幂等',()=>{const once=rewriteText('[a](../../docs/x.md)');assert.equal(rewriteText(once),once);});
18
+ test('兼容布局:改写后链接可达,未改写时被检查拦下',t=>{
19
+ const root=tmp(t);
20
+ fs.mkdirSync(path.join(root,'skills/cm-s/references'),{recursive:true});
21
+ fs.mkdirSync(path.join(root,'cm-workflow/docs'),{recursive:true});
22
+ fs.writeFileSync(path.join(root,'cm-workflow/docs/g.md'),'x');
23
+ fs.writeFileSync(path.join(root,'skills/cm-s/SKILL.md'),'[g](../../docs/g.md)');
24
+ fs.writeFileSync(path.join(root,'skills/cm-s/references/r.md'),'[g](../../../docs/g.md#a) [w](https://e.com/docs/q.md)');
25
+ fs.writeFileSync(path.join(root,SCOPE_FILE),scopeText(root));
26
+ assert.equal(findBrokenDocLinks(root).length,2);
27
+ assert.equal(rewriteTree(root).length,2);
28
+ assert.deepEqual(findBrokenDocLinks(root),[]);
29
+ });
30
+ test('源码布局:所有技能 docs 链接可达',()=>{assert.deepEqual(findBrokenDocLinks(source),[]);});
31
+ test('命令行入口在含空格的路径下真的执行:改写后检查通过,缺文档时非 0 退出',t=>{
32
+ const root=path.join(tmp(t),'with space');
33
+ fs.mkdirSync(path.join(root,'skills/cm-x'),{recursive:true});fs.mkdirSync(path.join(root,'cm-workflow/docs'),{recursive:true});
34
+ fs.writeFileSync(path.join(root,'cm-workflow/docs/g.md'),'x');
35
+ fs.writeFileSync(path.join(root,'skills/cm-x/SKILL.md'),'[g](../../docs/g.md) `../../docs/g.md`\n```md\n[e](../../docs/none.md)\n```\n[ext](https://e.com/a/../docs/q.md)');
36
+ const run=(script,...args)=>spawnSync(process.execPath,[path.join(source,'scripts',script),...args],{encoding:'utf8'});
37
+ assert.equal(run('cm-check-doc-links.mjs',root).status,1);
38
+ const r=run('cm-rewrite-doc-links.mjs',root);assert.equal(r.status,0);assert.match(r.stdout,/已改写 1 个/);
39
+ const text=fs.readFileSync(path.join(root,'skills/cm-x/SKILL.md'),'utf8');
40
+ assert.match(text,/\]\(\.\.\/\.\.\/cm-workflow\/docs\/g\.md\)/);
41
+ assert.match(text,/\(\.\.\/\.\.\/docs\/none\.md\)/);
42
+ assert.match(text,/https:\/\/e\.com\/a\/\.\.\/docs\/q\.md/);
43
+ assert.equal(run('cm-check-doc-links.mjs',root).status,0);
44
+ fs.unlinkSync(path.join(root,'cm-workflow/docs/g.md'));
45
+ assert.equal(run('cm-check-doc-links.mjs',root).status,1);
46
+ assert.notEqual(run('cm-rewrite-doc-links.mjs',path.join(root,'nope')).status,0);
47
+ });
48
+ test('范围清单:用户自装技能(含 cm- 开头)不归本包检查,清单里的技能照查',t=>{
49
+ const root=tmp(t);fs.mkdirSync(path.join(root,'skills/cm-unrelated'),{recursive:true});fs.mkdirSync(path.join(root,'skills/cm-own'));fs.mkdirSync(path.join(root,'cm-workflow/docs'),{recursive:true});
50
+ fs.writeFileSync(path.join(root,'skills/cm-own/SKILL.md'),'[g](../../cm-workflow/docs/none.md)');
51
+ fs.writeFileSync(path.join(root,SCOPE_FILE),scopeText(root));// 此刻 cm-unrelated 还不存在
52
+ fs.writeFileSync(path.join(root,'skills/cm-unrelated/SKILL.md'),'[g](../../docs/none.md)');
53
+ assert.deepEqual(findBrokenDocLinks(root),['skills/cm-own/SKILL.md -> ../../cm-workflow/docs/none.md']);
54
+ });
55
+ test('范围清单被截断、为空、缺失、指向不存在文件时检查报错而不是静默通过',t=>{
56
+ const root=tmp(t);fs.mkdirSync(path.join(root,'skills/cm-a'),{recursive:true});fs.mkdirSync(path.join(root,'skills/cm-b'));fs.mkdirSync(path.join(root,'cm-workflow/docs'),{recursive:true});
57
+ fs.writeFileSync(path.join(root,'skills/cm-a/SKILL.md'),'x');fs.writeFileSync(path.join(root,'skills/cm-b/SKILL.md'),'x');
58
+ assert.throws(()=>findBrokenDocLinks(root),/缺少范围清单/);
59
+ const full=scopeText(root),scope=path.join(root,SCOPE_FILE);
60
+ fs.writeFileSync(scope,full);assert.deepEqual(findBrokenDocLinks(root),[]);
61
+ fs.writeFileSync(scope,full.split('\n').slice(0,2).join('\n')+'\n');assert.throws(()=>findBrokenDocLinks(root),/截断/);
62
+ fs.writeFileSync(scope,'');assert.throws(()=>findBrokenDocLinks(root),/截断/);
63
+ fs.writeFileSync(scope,full.replace('skills/cm-b/SKILL.md','skills/cm-gone/SKILL.md'));assert.throws(()=>findBrokenDocLinks(root),/不存在/);
64
+ fs.writeFileSync(scope,full.replace('skills/cm-b/SKILL.md','skills/../x.md'));assert.throws(()=>findBrokenDocLinks(root),/非法路径/);
65
+ });
66
+ test('技能文档超过读取上限时报错,不整份读入',t=>{
67
+ const root=tmp(t);fs.mkdirSync(path.join(root,'skills/cm-a'),{recursive:true});fs.mkdirSync(path.join(root,'docs'));
68
+ fs.writeFileSync(path.join(root,'skills/cm-a/SKILL.md'),'a'.repeat(MAX_DOC_BYTES+1));
69
+ assert.throws(()=>findBrokenDocLinks(root),/上限/);
70
+ assert.throws(()=>rewriteTree(root),/上限/);
71
+ });
72
+ test('带命令行后缀的反引号路径、引用块内的围栏都不被改写;收尾符正常的照改',()=>{
73
+ const keep=['`../../docs/g.md --dry-run`','> ```md\n> [a](../../docs/a.md)\n> ```','>> ~~~\n>> `../../docs/b.md`\n>> ~~~'];
74
+ for(const text of keep)assert.equal(rewriteText(text),text,text);
75
+ assert.equal(rewriteText('`../../docs/g.md` [x](../../docs/y.md "标题") [z](../../docs/y.md#h)'),
76
+ '`../../cm-workflow/docs/g.md` [x](../../cm-workflow/docs/y.md "标题") [z](../../cm-workflow/docs/y.md#h)');
77
+ });
78
+ test('外链查询参数、缩进围栏、四波浪号围栏、未闭合围栏都不被改写',()=>{
79
+ const keep=['[x](https://e.com/v?next=../../docs/g.md)',' ```md\n[a](../../docs/a.md)\n ```','~~~~\n[b](../../docs/b.md)\n~~~~','```\n[c](../../docs/c.md)'];
80
+ for(const text of keep)assert.equal(rewriteText(text),text,text);
81
+ });
82
+ test('围栏逐行判断:引用块结束后围栏随之结束;普通围栏里带 > 的标记不算结束',()=>{
83
+ assert.equal(rewriteText('> ```md\n> [a](../../docs/a.md)\n\n[b](../../docs/b.md)\n'),'> ```md\n> [a](../../docs/a.md)\n\n[b](../../cm-workflow/docs/b.md)\n');
84
+ assert.equal(rewriteText('> ```\n> [a](../../docs/a.md)\n[lazy](../../docs/l.md)\n'),'> ```\n> [a](../../docs/a.md)\n[lazy](../../cm-workflow/docs/l.md)\n');
85
+ const plain='```\n> ```\n[c](../../docs/c.md)\n```\n';assert.equal(rewriteText(plain),plain);
86
+ const longer='````\n```\n[d](../../docs/d.md)\n````\n[e](../../docs/e.md)';assert.equal(rewriteText(longer),'````\n```\n[d](../../docs/d.md)\n````\n[e](../../cm-workflow/docs/e.md)');
87
+ });
88
+ test('兼容布局下根有用户自己的 docs/ 也不退回全量扫描;清单路径含反斜杠或 . 段被拒;超大清单被拒',t=>{
89
+ const root=tmp(t);fs.mkdirSync(path.join(root,'skills/cm-a'),{recursive:true});fs.mkdirSync(path.join(root,'cm-workflow/docs'),{recursive:true});fs.mkdirSync(path.join(root,'docs'));
90
+ fs.writeFileSync(path.join(root,'skills/cm-a/SKILL.md'),'x');
91
+ assert.throws(()=>findBrokenDocLinks(root),/缺少范围清单/);
92
+ const scope=path.join(root,SCOPE_FILE),head='# cm-workflow doc-links scope v1 count=1\n';
93
+ for(const bad of ['skills\\..\\x.md','skills/./cm-a/SKILL.md','skills//cm-a/SKILL.md']){fs.writeFileSync(scope,head+bad+'\n');assert.throws(()=>findBrokenDocLinks(root),/非法路径/,bad);}
94
+ fs.writeFileSync(scope,head+'skills/cm-a/SKILL.md\n'+'\n'.repeat(MAX_DOC_BYTES));assert.throws(()=>findBrokenDocLinks(root),/上限/);
95
+ });
96
+ test('readBounded 按实际读到的字节限量,不信 stat',t=>{
97
+ const f=path.join(tmp(t),'a.md');fs.writeFileSync(f,'a'.repeat(100));
98
+ assert.equal(readBounded(f,100).length,100);assert.throws(()=>readBounded(f,99),/上限/);
99
+ });
100
+ test('缩进 4 格的三反引号不是结束围栏;累计预算按实际字节算',t=>{
101
+ const text='```\n ```\n[c](../../docs/c.md)\n```\n';assert.equal(rewriteText(text),text);
102
+ assert.equal(rewriteText(' ```\n[c](../../docs/c.md)\n ```\n[d](../../docs/d.md)'),' ```\n[c](../../docs/c.md)\n ```\n[d](../../cm-workflow/docs/d.md)');
103
+ const root=tmp(t);fs.mkdirSync(path.join(root,'skills/cm-a'),{recursive:true});fs.mkdirSync(path.join(root,'docs'));
104
+ const bad=Buffer.alloc(900*1024,0xff),n=Math.floor(64*1024*1024/bad.length)-1;// 非法 UTF-8 解码后字符数远大于字节数
105
+ for(let i=0;i<n;i++){fs.mkdirSync(path.join(root,'skills/cm-a/d'+i),{recursive:true});fs.writeFileSync(path.join(root,`skills/cm-a/d${i}/r.md`),bad);}
106
+ assert.deepEqual(findBrokenDocLinks(root),[]);
107
+ });
108
+ test('行首 Tab 加三反引号不是结束围栏',()=>{
109
+ const text='```\n\t```\n[c](../../docs/c.md)\n```\n';assert.equal(rewriteText(text),text);
110
+ });
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ // Claude 兼容安装把 docs/ 装到 <根>/cm-workflow/docs/,而源码与插件安装里 docs/ 在根目录。
3
+ // 暂存目录里本包技能 *.md 的 ../docs/… 相对引用,在此改写成 ../cm-workflow/docs/…
4
+ // (实跑教训:0.21.5 兼容安装下约 18 处链接解析到不存在的 ~/.claude/docs)。
5
+ // 遍历失败直接抛错、退出码非 0,由安装器停止安装,不当作“改写了 0 个”。
6
+ import { mkdirSync, writeFileSync } from 'node:fs';
7
+ import { dirname, join } from 'node:path';
8
+ import { pathToFileURL } from 'node:url';
9
+ import { SCOPE_FILE, makeBoundedReader, mapOutsideFences, replaceDocRefs, scopeText, stagedSkillMarkdown } from './cm-doc-links-shared.mjs';
10
+
11
+ export function rewriteText(text) {
12
+ return mapOutsideFences(text, (part) => replaceDocRefs(part, (up, done, rest, whole) => (done ? whole : `${up}cm-workflow/${rest}`)));
13
+ }
14
+
15
+ export function rewriteTree(stageRoot) {
16
+ const changed = [];
17
+ const read = makeBoundedReader();
18
+ for (const f of stagedSkillMarkdown(stageRoot)) {
19
+ const before = read(f);
20
+ const after = rewriteText(before);
21
+ if (after !== before) { writeFileSync(f, after); changed.push(f); }
22
+ }
23
+ // 暂存目录的 skills/ 全是本包的:把这份清单随包装入,检查只看清单里的文件。
24
+ const scope = join(stageRoot, SCOPE_FILE);
25
+ mkdirSync(dirname(scope), { recursive: true });
26
+ writeFileSync(scope, scopeText(stageRoot));
27
+ return changed;
28
+ }
29
+
30
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
31
+ const root = process.argv[2];
32
+ if (!root) { console.error('用法: cm-rewrite-doc-links.mjs <暂存目录>'); process.exit(2); }
33
+ console.log(`已改写 ${rewriteTree(root).length} 个文件的 docs 相对链接`);
34
+ }
@@ -84,7 +84,7 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-spec-amend.mjs" inspect --specs-dir "{SPECS_
84
84
  - 审查者不能是写补正的会话;宿主要求跨工具审查时按宿主规则选审查者。审查判 `changes_requested` 或摘要不符时 `apply` 拒绝,转 2 级。
85
85
  - `apply` 只换绑规格批准,保留原 `approval.response`;在途运行仍按 `js-host.md` 的 `spec_rebind` 规则换绑或重做。
86
86
  - 不得手改 `.cm-specs-approved.json` 和 `~/.cm-workflow/spec-approvals/` 下的批准台账;被改过即失效,退回 2 级。`apply` 报 `spec_approval_busy` 时等对方批准结束再试,不删锁文件;持续报错时把 `.cm-specs-approval.lock` 与 `.cm-specs-approval.lock.reclaim` 里的 pid 告诉用户,由用户确认没有批准或补正在运行后自行删除(崩溃遗留不自动清理)。
87
- - 机器条件与理由见 `docs/proposals/spec-amendment-tiers.md`。快照与回执只绑定内容,不证明是谁写的,保障级别同 `.cm-specs-status`(实跑教训:wue、aihot-dev 两个会话 17 次“开始”里 16 次是开发中补规格)。
87
+ - 机器条件与理由见 [spec-amendment-tiers](../../../docs/proposals/spec-amendment-tiers.md)。快照与回执只绑定内容,不证明是谁写的,保障级别同 `.cm-specs-status`(实跑教训:wue、aihot-dev 两个会话 17 次“开始”里 16 次是开发中补规格)。
88
88
 
89
89
  多任务批次的并行组提议规则见 `js-host.md` 第 3.1 条;本兼容流程不自行发明并行判定。
90
90
 
@@ -67,7 +67,7 @@ Claude Code 将 `--runtime` 改为 `claude`。这一项说明本次检查跑在
67
67
  ## 语义检查
68
68
 
69
69
  1. **Codex 入口**(按 `installMode` 分流):`cm-idea/cm-init/cm-prd/cm-ai/cm-test/cm-security/cm-fix/cm-refactor/cm-check/cm-runtime/cm-notify` 十一个核心 Skill 与独立 `external-expert` Skill 均有合法 frontmatter,两种模式都查。`plugin` 模式另查 `.codex-plugin/plugin.json` 的 `skills` 指向 `./skills/`;`claude-compat` 模式没有该清单文件(安装器不生成),这一半记 `not_applicable` 并说明,不记 blocked。
70
- 2. **共享真相**:十一个核心 Skill 引用 `runtime/` 合同;`external-expert` 引用共享外部专家合同;`compat/claude-commands/cm-*.md` 只是 macOS/Linux 旧入口薄包装,不再复制业务规则。
70
+ 2. **共享真相**:除独立配置工具 `cm-notify`(只管提醒设置,不读运行时合同)外,其余十个核心 Skill 引用 `runtime/` 合同;`external-expert` 引用共享外部专家合同;`compat/claude-commands/cm-*.md` 只是 macOS/Linux 旧入口薄包装,不再复制业务规则。
71
71
  3. **流程链路**:`cm-ai` 的 N1–N8 引用全部存在;`cm-prd` 的 greenfield/brownfield/change-mode 全部存在;`cm-idea` 引用 `idea-to-prd`;`cm-prd/cm-ai/cm-test/cm-qa-engineer` 共用 `runtime/test-contract.md`;`cm-prd/cm-ai/cm-test/cm-security/cm-fix/cm-refactor/external-expert` 共用 `runtime/logging.md` 与统一 writer;`cm-test --generate-cases` 生成校验后的 inferred 草稿并硬停止。
72
72
  4. **角色链路**:N3 引用的 `cm-*-engineer/manager/expert` Skill 存在;Claude `agents/` 中每个兼容角色能找到对应工种 Skill。Codex 不依赖这些 `.md` agent 文件;配套完整性核对用户级 `runtimes.yml` 的安装器/cm-runtime 生成方与 cm-workflow-config 消费方,cm-runtime 与 cm-notify 是独立工具、不配工种。
73
73
  5. **状态与审查**:`.cm-specs-status`、`.cm-status.json`、`.cm-run.json`、`tasks.md`、可选 `test-cases.json`、`METRICS.md`、`LESSONS.md`、`运行日志.jsonl` 及 `.reviews/` 的生成方与消费方配对;项目日志保持权威,全局日志只是私有可重建镜像;N4 凭证头包含 reviewer/independent/task/round/at/scope;`cm-fix` 收口前机械检查修后审查凭证;`.external/` 不得冒充 N4/N5 凭证。