@aibyzero/cm-workflow 0.21.5 → 0.21.7
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 +13 -0
- package/README.md +14 -3
- package/VERSION +1 -1
- package/docs/installation.md +7 -7
- package/docs/runtime-failover.md +5 -3
- package/docs/user-guide.md +5 -5
- package/install.ps1 +3 -0
- package/install.sh +2 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +9 -2
- package/runtime/js/cm-ai/tool-preview.mjs +6 -0
- package/runtime/js/cm-check/host.mjs +37 -8
- package/runtime/review.md +1 -0
- package/runtime/workflow-config.md +1 -1
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
- package/scripts/cm-check-doc-links.mjs +29 -0
- package/scripts/cm-check-host.test.mjs +46 -0
- package/scripts/cm-check-runtime.sh +15 -0
- package/scripts/cm-claude-install-layout.test.mjs +12 -0
- package/scripts/cm-codex-clean-env.test.mjs +40 -0
- package/scripts/cm-doc-links-shared.mjs +139 -0
- package/scripts/cm-doc-links.test.mjs +110 -0
- package/scripts/cm-rewrite-doc-links.mjs +34 -0
- package/scripts/cm-runtime-i18n.mjs +3 -3
- package/scripts/cm-runtime-install.mjs +19 -10
- package/scripts/cm-runtime.mjs +2 -4
- package/scripts/cm-runtime.test.mjs +55 -13
- package/scripts/cm-statusline.test.mjs +54 -0
- package/skills/cm-ai/references/N1-init.md +4 -3
- package/skills/cm-ai/references/N4-review.md +4 -1
- package/skills/cm-ai/references/js-host.md +12 -1
- package/skills/cm-check/SKILL.md +1 -1
- package/skills/cm-runtime/SKILL.md +6 -6
- package/templates/statusline/cm-statusline.sh +63 -1
|
@@ -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
|
+
}
|
|
@@ -9,8 +9,8 @@ export const messages={
|
|
|
9
9
|
menu:{zh:'运行时配置:[1] 保留当前配置(推荐,默认) [2] 修改运行时预设 [3] 查看高级模型配置说明 [1]: ',en:'Runtime configuration: [1] Keep current configuration (recommended, default) [2] Change runtime preset [3] Advanced model configuration [1]: '},
|
|
10
10
|
kept:{zh:'已保留当前配置,未写入文件。\n',en:'Kept current configuration; no files written.\n'},
|
|
11
11
|
builtin:{zh:'内置默认(未声明)',en:'Built-in defaults (undeclared)'},
|
|
12
|
-
tools:{zh:'你手上有哪个 AI 工具?[1] 只有 Codex [2] 只有 Claude [3] 两个都有: ',en:'Which AI tools do you have? [1] Codex only [2] Claude only [3] Both: '},
|
|
13
|
-
coder:{zh:'谁写代码?[1] Codex(Claude
|
|
12
|
+
tools:{zh:'你手上有哪个 AI 工具?[1] 只有 Codex [2] 只有 Claude(默认) [3] 两个都有: ',en:'Which AI tools do you have? [1] Codex only [2] Claude only (default) [3] Both: '},
|
|
13
|
+
coder:{zh:'谁写代码?[1] Codex(Claude 审) [2] Claude(Codex 审,默认): ',en:'Who writes code? [1] Codex (Claude reviews) [2] Claude (Codex reviews, default): '},
|
|
14
14
|
scope:{zh:'改哪一层?[1] 当前项目({project}) [2] 用户级默认({user}) [{default}]: ',en:'Which scope? [1] Current project ({project}) [2] User default ({user}) [{default}]: '},
|
|
15
15
|
create:{zh:'将从模板新建项目配置:{file}\n',en:'Will create project configuration from the template: {file}\n'},
|
|
16
16
|
current:{zh:'当前用户级默认: {available} / {preset}\n',en:'Current user default: {available} / {preset}\n'},
|
|
@@ -26,7 +26,7 @@ export const messages={
|
|
|
26
26
|
drift:{zh:'预览后的配置已改变: {file};未保存,请重新预览并确认。',en:'Configuration changed after preview: {file}; not saved. Generate a fresh preview and confirm again.'},
|
|
27
27
|
advanced:{zh:'高级模型配置说明:建议保留当前默认,仅在有明确需要时手工编辑项目 .cm-workflow.yml 的模型别名。\n合同说明: {doc}\n校验: node "{validator}" --project "<项目路径>" --print-effective\n校验不证明 provider 兼容或配额可用;预设切换保留模型别名。\nunset --user 只删除用户默认,项目声明仍优先,不是恢复所有默认值。\n',en:'Advanced model configuration: keep current defaults unless you have a specific need; edit model aliases manually in the project .cm-workflow.yml.\nContract: {doc}\nValidate: node "{validator}" --project "<project path>" --print-effective\nValidation does not prove provider compatibility or quota; preset changes preserve model aliases.\nunset --user removes only user defaults; project declarations still win. It is not a reset of all settings.\n'},
|
|
28
28
|
absent:{zh:'未声明',en:'Undeclared'},
|
|
29
|
-
confirm:{zh:'
|
|
29
|
+
confirm:{zh:'输入确认码 {code} 保存;其他输入或直接回车取消: ',en:'Type confirmation code {code} to save; anything else cancels: '},
|
|
30
30
|
cancelled:{zh:'已放弃,未修改运行时声明。\n',en:'Cancelled; runtime declaration unchanged.\n'},
|
|
31
31
|
installed:{zh:'✓ 用户级运行时默认已写入 {file} ({preset})\n',en:'✓ User runtime default saved to {file} ({preset})\n'},
|
|
32
32
|
comment:{zh:'用 cm-runtime set --user <preset> 修改用户级默认。',en:'Use cm-runtime set --user <preset> to change the user default.'},
|
|
@@ -4,6 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
6
|
import {createInterface} from 'node:readline';
|
|
7
|
+
import {randomBytes} from 'node:crypto';
|
|
7
8
|
import {userRuntimesPath,readConfigText,parseUserRuntimes} from './cm-workflow-config.mjs';
|
|
8
9
|
import {writeUserRuntime,prepareRuntimePreview,formatRuntimePreview} from './cm-runtime.mjs';
|
|
9
10
|
import {runtimeLanguage,runtimeText as t} from './cm-runtime-i18n.mjs';
|
|
@@ -12,32 +13,41 @@ export class PromptCancelled extends Error {}
|
|
|
12
13
|
// Queue lines so injected streams and pasted answers cannot lose later responses.
|
|
13
14
|
export function runtimeQuestions(input,output,lang=runtimeLanguage()){
|
|
14
15
|
const rl=createInterface({input,output,terminal:false});
|
|
15
|
-
const queue=[];let pending=null,closed=false,cancelled=false;
|
|
16
|
+
const queue=[];let pending=null,closed=false,cancelled=false,unterminated=false;
|
|
17
|
+
// 输入最后一行没回车就结束(EOF),那一行不算数:防止未提交的 y 被当成确认。
|
|
18
|
+
input.on('data',chunk=>{const text=String(chunk);if(text.length)unterminated=!text.endsWith('\n');});
|
|
16
19
|
rl.on('line',line=>{if(pending){const resolve=pending;pending=null;resolve(line);}else queue.push(line);});
|
|
17
20
|
const close=()=>{closed=true;if(pending){pending(null);pending=null;}};
|
|
18
21
|
rl.on('close',close);
|
|
19
22
|
const interrupt=()=>{cancelled=true;queue.length=0;rl.close();close();};
|
|
20
23
|
rl.on('SIGINT',interrupt);process.on('SIGINT',interrupt);
|
|
21
24
|
return {
|
|
22
|
-
|
|
25
|
+
// fresh=true(确认题):确认码是此刻才生成的,提问显示前已排队的行一律丢弃。
|
|
26
|
+
async ask(question,{fresh=false}={}){
|
|
27
|
+
if(fresh)queue.length=0;
|
|
23
28
|
if(cancelled||closed&&!queue.length)throw new PromptCancelled();
|
|
24
29
|
output.write(question);
|
|
25
30
|
const answer=queue.length?queue.shift():await new Promise(resolve=>{pending=resolve;});
|
|
26
31
|
if(answer===null||cancelled)throw new PromptCancelled();
|
|
32
|
+
if(closed&&!queue.length&&unterminated)throw new PromptCancelled();
|
|
27
33
|
return answer.trim();
|
|
28
34
|
},
|
|
29
35
|
close(){process.removeListener('SIGINT',interrupt);rl.close();},
|
|
30
36
|
};
|
|
31
37
|
}
|
|
38
|
+
// 保存确认:必须输入本次提问随机生成的 8 位确认码(每次提问重新生成,不由预览内容算出,
|
|
39
|
+
// 所以重复预览、提前粘贴都复用不了)。回车、n、y 等其他输入一律取消,不写。
|
|
40
|
+
export const newConfirmCode=()=>randomBytes(4).toString('hex'); // 8 位十六进制,碰撞概率约 1/43 亿
|
|
41
|
+
export async function askConfirm(ask,preview,lang=runtimeLanguage(),code=newConfirmCode()){
|
|
42
|
+
return (await ask(t('confirm',lang,{code}),{fresh:true})).toLowerCase()===code;
|
|
43
|
+
}
|
|
32
44
|
export async function askRuntimePreset(ask,lang=runtimeLanguage()){
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if(choice===''){if(++empty===3)throw new PromptCancelled();}else empty=0;
|
|
37
|
-
}while(!['1','2','3'].includes(choice));
|
|
45
|
+
// 空回车默认选 Claude(工具题=只有 Claude,写代码题=Claude 写)。
|
|
46
|
+
let choice;
|
|
47
|
+
do{choice=await ask(t('tools',lang));if(choice==='')choice='2';}while(!['1','2','3'].includes(choice));
|
|
38
48
|
if(choice!=='3')return choice==='1'?'codex-only':'claude-only';
|
|
39
49
|
let coder;
|
|
40
|
-
do{coder=await ask(t('coder',lang));}while(!['
|
|
50
|
+
do{coder=await ask(t('coder',lang));if(coder==='')coder='2';}while(!['1','2'].includes(coder));
|
|
41
51
|
return coder==='2'?'claude-codes':'codex-codes';
|
|
42
52
|
}
|
|
43
53
|
export async function promptRuntime(argv=process.argv.slice(2),input=process.stdin,output=process.stdout){
|
|
@@ -61,8 +71,7 @@ export async function promptRuntime(argv=process.argv.slice(2),input=process.std
|
|
|
61
71
|
const preset=await askRuntimePreset(ask,lang);
|
|
62
72
|
const preview=prepareRuntimePreview(null,preset,{user:true,lang});
|
|
63
73
|
output.write(formatRuntimePreview(preview,lang));
|
|
64
|
-
|
|
65
|
-
if(confirm!=='y')throw new PromptCancelled();
|
|
74
|
+
if(!await askConfirm(ask,preview,lang))throw new PromptCancelled();
|
|
66
75
|
output.write(t('installed',lang,{file:writeUserRuntime(preset,{lang,preview}),preset}));
|
|
67
76
|
}catch(error){if(error instanceof PromptCancelled)output.write(t('cancelled',lang));else throw error;}
|
|
68
77
|
finally{questions.close();}
|
package/scripts/cm-runtime.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {ConfigError,findConfig,loadConfig,readConfigText,parseUserRuntimes,
|
|
|
10
10
|
CONFIG_FILENAMES,previewUserRuntimeConfig} from './cm-workflow-config.mjs';
|
|
11
11
|
import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
|
|
12
12
|
import {runtimeLanguage,runtimeText as t} from './cm-runtime-i18n.mjs';
|
|
13
|
-
import {askRuntimePreset,runtimeQuestions,PromptCancelled} from './cm-runtime-install.mjs';
|
|
13
|
+
import {askRuntimePreset,askConfirm,runtimeQuestions,PromptCancelled} from './cm-runtime-install.mjs';
|
|
14
14
|
export {askRuntimePreset} from './cm-runtime-install.mjs';
|
|
15
15
|
import {probeRuntimes} from './cm-failover.mjs';
|
|
16
16
|
|
|
@@ -188,9 +188,7 @@ export async function interactiveRuntime(project,{input=process.stdin,output=pro
|
|
|
188
188
|
const preset=await askRuntimePreset(ask,lang);
|
|
189
189
|
const preview=prepareRuntimePreview(root,preset,{user,lang});
|
|
190
190
|
output.write(formatRuntimePreview(preview,lang));
|
|
191
|
-
|
|
192
|
-
do{confirm=(await ask(t('confirm',lang))).toLowerCase();}while(!['','y','n'].includes(confirm));
|
|
193
|
-
if(confirm!=='y')throw new PromptCancelled();
|
|
191
|
+
if(!await askConfirm(ask,preview,lang))throw new PromptCancelled();
|
|
194
192
|
saveRuntime(root,preset,user,lang,output,preview);
|
|
195
193
|
output.write(showRuntime(root,{lang})+'\n');return 0;
|
|
196
194
|
}catch(error){if(error instanceof PromptCancelled){output.write(t('cancelled',lang));return 0;}throw error;}
|
|
@@ -135,9 +135,22 @@ function tty(){
|
|
|
135
135
|
let text='';output.on('data',chunk=>{text+=chunk;});
|
|
136
136
|
return {input,output,text:()=>text};
|
|
137
137
|
}
|
|
138
|
+
// 逐行喂入:每个提问(不以换行结尾的输出)出现后才送下一行;{CODE} 换成提示里显示的确认码。
|
|
139
|
+
function feed(io,answers){
|
|
140
|
+
const lines=answers.split(/(?<=\n)/);let seen='';
|
|
141
|
+
io.output.on('data',chunk=>{
|
|
142
|
+
seen+=chunk;
|
|
143
|
+
if(String(chunk).endsWith('\n'))return;
|
|
144
|
+
let next=lines.shift();
|
|
145
|
+
if(next===undefined){io.input.end();return;}
|
|
146
|
+
if(next.includes('{CODE}')){const code=(/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk))??[])[1];next=next.replace('{CODE}',code??'????');}
|
|
147
|
+
if(lines.length===0)io.input.end(next);else io.input.write(next);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
138
150
|
async function wizard(root,answers,lang='en'){
|
|
139
|
-
const io=tty();
|
|
140
|
-
|
|
151
|
+
const io=tty();feed(io,answers);
|
|
152
|
+
const running=main(['--project',root],{...io,lang});
|
|
153
|
+
const code=await running;return {code,text:io.text()};
|
|
141
154
|
}
|
|
142
155
|
test('wizard and installer share the same preset question function',()=>assert.equal(wizardPreset,installerPreset));
|
|
143
156
|
test('entry keeps missing and existing configuration by default, without logs or run writes',()=>wizardFixture(async root=>{
|
|
@@ -156,7 +169,7 @@ test('advanced model information is read-only and has no model editing prompt',(
|
|
|
156
169
|
assert.deepEqual(fs.readdirSync(root),[]);
|
|
157
170
|
}));
|
|
158
171
|
test('Enter at the final confirmation declines the proposed change',()=>wizardFixture(async root=>{
|
|
159
|
-
const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/
|
|
172
|
+
const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/confirmation code/);
|
|
160
173
|
assert.match(result.text,/Cancelled/);assert.deepEqual(fs.readdirSync(root),[]);
|
|
161
174
|
}));
|
|
162
175
|
test('first-install declaration is optional and Enter skips it',()=>wizardFixture(async root=>{
|
|
@@ -180,7 +193,7 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
|
|
|
180
193
|
const before='\ufeff# keep\r\nversion: 1\r\nruntimes: {available: codex}\r\nroles:\r\n coder: {adapter: current-ai, source: local, model: default} # keep coder\r\n reviewer: {adapter: current-ai, source: local, model: default}\r\n';
|
|
181
194
|
const initial=before;
|
|
182
195
|
fs.writeFileSync(file,initial);
|
|
183
|
-
const result=await wizard(root,'2\n1\n3\n1\
|
|
196
|
+
const result=await wizard(root,'2\n1\n3\n1\n{CODE}\n');assert.equal(result.code,0,result.text);
|
|
184
197
|
assert.equal(fs.readFileSync(file,'utf8'),initial.replace('available: codex','available: both').replace('adapter: current-ai','adapter: codex-cli').replace('adapter: current-ai','adapter: claude-cli').replaceAll('source: local','source: subscription'));
|
|
185
198
|
assert.match(result.text,/Which AI tools do you have/);assert.match(result.text,/Who writes code/);
|
|
186
199
|
assert.match(result.text,/preset: codex-codes/);assert.match(result.text,/runtimes_source: project/);
|
|
@@ -189,12 +202,12 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
|
|
|
189
202
|
assert.equal(event.event,'decision');assert.equal(event.preset,'codex-codes');
|
|
190
203
|
}));
|
|
191
204
|
test('missing project defaults to user scope and Chinese preset/comment/output',()=>wizardFixture(async root=>{
|
|
192
|
-
const result=await wizard(root,'2\n\n2\
|
|
205
|
+
const result=await wizard(root,'2\n\n2\n{CODE}\n','zh');assert.equal(result.code,0);
|
|
193
206
|
assert(!fs.existsSync(path.join(root,'.cm-workflow.yml')));
|
|
194
207
|
assert.match(fs.readFileSync(path.join(root,'user','runtimes.yml'),'utf8'),/# 用 cm-runtime.*\npreset: claude-only/s);
|
|
195
|
-
assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text
|
|
208
|
+
assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text,/确认码/);assert.match(result.text,/runtimes_source: user/);
|
|
196
209
|
}));
|
|
197
|
-
test('
|
|
210
|
+
test('empty final confirmation, refusal, EOF and SIGINT do not write',()=>wizardFixture(async root=>{
|
|
198
211
|
for(const [lang,cancelled] of [['en',/Cancelled/],['zh',/已放弃/]]){
|
|
199
212
|
for(const answers of ['2\n2\n\n\n\n','2\n2\n1\nn\n','2\n2\n','2\n2\n1\n']){
|
|
200
213
|
const result=await wizard(root,answers,lang);assert.equal(result.code,0);
|
|
@@ -204,9 +217,38 @@ test('three empty mandatory answers, refusal, EOF and SIGINT do not write',()=>w
|
|
|
204
217
|
assert.equal(await running,0);assert.match(io.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
205
218
|
}
|
|
206
219
|
}));
|
|
220
|
+
test('empty answers default to Claude: tools question and coder question',async()=>{
|
|
221
|
+
const feed=list=>async()=>list.shift();
|
|
222
|
+
assert.equal(await installerPreset(feed([''])),'claude-only');
|
|
223
|
+
assert.equal(await installerPreset(feed(['3',''])),'claude-codes');
|
|
224
|
+
assert.equal(await installerPreset(feed(['3','1'])),'codex-codes');
|
|
225
|
+
assert.equal(await installerPreset(feed(['1'])),'codex-only');
|
|
226
|
+
});
|
|
227
|
+
test('saving needs the preview confirmation code: pasted y, n, Enter, wrong code and unterminated EOF code never write',()=>wizardFixture(async root=>{
|
|
228
|
+
const cancelled=/Cancelled/;
|
|
229
|
+
// 提前粘贴(含猜测 y):确认码预览前不可知 → 取消,不写。
|
|
230
|
+
const pasted=tty(),running=main(['--project',root],{...pasted,lang:'en'});
|
|
231
|
+
pasted.input.end('2\n2\n\ny\n');assert.equal(await running,0);
|
|
232
|
+
assert.match(pasted.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
233
|
+
// y、n、回车、错码:立即取消(不挂起、不吞输入),不写。
|
|
234
|
+
for(const answer of ['y\n','n\n','\n','zzzz\n']){
|
|
235
|
+
const r=await wizard(root,`2\n2\n\n${answer}`);assert.equal(r.code,0);
|
|
236
|
+
assert.match(r.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
237
|
+
}
|
|
238
|
+
// 确认码每次提问随机生成:同一预览两次提问的码不同,上一次的码复用不了。
|
|
239
|
+
const codes=[];for(let i=0;i<2;i++){const r=await wizard(root,'2\n2\n\nn\n');codes.push(/(?:confirmation code|确认码) (\w{8})/.exec(r.text)[1]);}
|
|
240
|
+
assert.notEqual(codes[0],codes[1]);
|
|
241
|
+
const reused=await wizard(root,`2\n2\n\n${codes[0]}\n`);assert.match(reused.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
242
|
+
// 正确确认码但没回车就 EOF:不算数,不写。
|
|
243
|
+
const tail=await wizard(root,'2\n2\n\n{CODE}');assert.equal(tail.code,0);
|
|
244
|
+
assert.match(tail.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
245
|
+
// 对照:输入显示的确认码并回车才写入,且确认码大小写不敏感。
|
|
246
|
+
const ok=await wizard(root,'2\n2\n\n{CODE}\n');assert.equal(ok.code,0);
|
|
247
|
+
assert.match(ok.text,/Saved|已保存|installed/i);assert(fs.existsSync(path.join(root,'user','runtimes.yml')));
|
|
248
|
+
}));
|
|
207
249
|
test('explicit project creation, existing-project scope default and invalid choice retry',()=>wizardFixture(async root=>{
|
|
208
|
-
const created=await wizard(root,'2\n1\nwrong\n1\
|
|
209
|
-
const changed=await wizard(root,'2\n\n3\n2\
|
|
250
|
+
const created=await wizard(root,'2\n1\nwrong\n1\n{CODE}\n');assert.equal(created.code,0);assert.match(created.text,/Will create project configuration/);
|
|
251
|
+
const changed=await wizard(root,'2\n\n3\n2\n{CODE}\n');assert.equal(changed.code,0);assert.match(changed.text,/preset: claude-codes/);
|
|
210
252
|
assert.equal(loadConfig({projectRoot:root}).roles.coder.adapter,'claude-cli');
|
|
211
253
|
}));
|
|
212
254
|
test('non-TTY no command exits 2 with usage and no writes',()=>fixture((root,run)=>{
|
|
@@ -234,8 +276,8 @@ test('installer culture reaches shared prompts and comments; explicit override w
|
|
|
234
276
|
for(const key of keys)delete process.env[key];
|
|
235
277
|
for(const [culture,override,expected] of [['zh-CN',undefined,'zh'],['en-US',undefined,'en'],['zh-CN','en','en']]){
|
|
236
278
|
if(override)process.env.CM_WORKFLOW_LANG=override;else delete process.env.CM_WORKFLOW_LANG;
|
|
237
|
-
const io=tty(),running=promptRuntime(['--lang',culture],io.input,io.output);
|
|
238
|
-
|
|
279
|
+
const io=tty();feed(io,'y\n3\n2\n{CODE}\n');const running=promptRuntime(['--lang',culture],io.input,io.output);
|
|
280
|
+
await running;
|
|
239
281
|
assert.match(io.text(),expected==='zh'?/你手上有哪个 AI 工具/:/Which AI tools do you have/);
|
|
240
282
|
const file=path.join(root,'user','runtimes.yml');assert.match(fs.readFileSync(file,'utf8'),expected==='zh'?/# 用 cm-runtime/:/# Use cm-runtime/);
|
|
241
283
|
fs.unlinkSync(file);
|
|
@@ -297,7 +339,7 @@ test('project preview save refuses target edits and preserves the external write
|
|
|
297
339
|
test('TTY confirmation cannot overwrite edits made after its preview',()=>wizardFixture(async root=>{
|
|
298
340
|
const file=path.join(root,'.cm-workflow.yml');fs.writeFileSync(file,'version: 1\n');
|
|
299
341
|
const io=tty(),external='version: 1\n# external edit\n';let changed=false;
|
|
300
|
-
io.output.on('data',chunk=>{
|
|
342
|
+
io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){fs.writeFileSync(file,external);changed=true;io.input.end(`${m[1]}\n`);}});
|
|
301
343
|
const running=main(['--project',root],{...io,lang:'en'});io.input.write('2\n1\n1\n');
|
|
302
344
|
assert.equal(await running,1);assert(changed);assert.equal(fs.readFileSync(file,'utf8'),external);
|
|
303
345
|
assert(!fs.existsSync(path.join(root,'logs')));
|
|
@@ -310,7 +352,7 @@ test('installer keeps existing defaults, defaults No at final confirmation and r
|
|
|
310
352
|
assert.deepEqual(fs.readFileSync(file),before);
|
|
311
353
|
}
|
|
312
354
|
const io=tty();let changed=false;
|
|
313
|
-
io.output.on('data',chunk=>{
|
|
355
|
+
io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){writeUserRuntime('claude-codes');changed=true;io.input.end(`${m[1]}\n`);}});
|
|
314
356
|
const running=promptRuntime([],io.input,io.output);io.input.write('n\n2\n');
|
|
315
357
|
await assert.rejects(running,/fresh preview|重新预览/);assert(changed);
|
|
316
358
|
assert.match(fs.readFileSync(file,'utf8'),/preset: claude-codes/);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// 状态条只显示属于当前会话项目的 CM 状态(按 stdin 的 cwd 判断)。
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
|
|
10
|
+
const script=fileURLToPath(new URL('../templates/statusline/cm-statusline.sh',import.meta.url));
|
|
11
|
+
function fixture(fn){
|
|
12
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-statusline-')));
|
|
13
|
+
try{
|
|
14
|
+
const home=path.join(root,'home'),project=path.join(root,'proj'),specs=path.join(project,'specs','feat');
|
|
15
|
+
fs.mkdirSync(path.join(home,'.claude'),{recursive:true});fs.mkdirSync(specs,{recursive:true});
|
|
16
|
+
fs.mkdirSync(path.join(root,'proj2'));fs.mkdirSync(path.join(root,'other'));
|
|
17
|
+
fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),specs);
|
|
18
|
+
fs.writeFileSync(path.join(specs,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
|
|
19
|
+
fn({root,home,project,specs});
|
|
20
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
21
|
+
}
|
|
22
|
+
const run=(home,input)=>spawnSync('/bin/bash',[script],{input:JSON.stringify(input),env:{...process.env,HOME:home},encoding:'utf8'}).stdout;
|
|
23
|
+
|
|
24
|
+
test('shows CM status when cwd is the project, inside specs, or via workspace.current_dir',()=>fixture(({home,project,specs})=>{
|
|
25
|
+
for(const input of [{cwd:project},{cwd:specs},{workspace:{current_dir:project}}])
|
|
26
|
+
assert.match(run(home,input),/正在开发接口/,JSON.stringify(input));
|
|
27
|
+
}));
|
|
28
|
+
test('hides another project\'s status, a prefix-lookalike dir, and a missing cwd',()=>fixture(({root,home})=>{
|
|
29
|
+
for(const input of [{cwd:path.join(root,'other')},{cwd:path.join(root,'proj2')},{model:{display_name:'M'}}]){
|
|
30
|
+
const out=run(home,input);
|
|
31
|
+
assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),JSON.stringify(input)+out);
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
test('inherited GIT_DIR / GIT_WORK_TREE cannot pull in another project\'s status',()=>fixture(({root,home,project})=>{
|
|
36
|
+
assert.equal(spawnSync('git',['init','-q',project]).status,0);
|
|
37
|
+
const env={...process.env,HOME:home,GIT_DIR:path.join(project,'.git'),GIT_WORK_TREE:project};
|
|
38
|
+
const out=spawnSync('/bin/bash',[script],{input:JSON.stringify({cwd:path.join(root,'other')}),env,encoding:'utf8'}).stdout;
|
|
39
|
+
assert(!out.includes('正在开发接口'),out);
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
test('a cwd that is "/", an ancestor of HOME, or a deleted directory never shows another project\'s status',()=>fixture(({root,home})=>{
|
|
43
|
+
const gone=path.join(root,'gone');fs.mkdirSync(gone);fs.rmSync(gone,{recursive:true});
|
|
44
|
+
for(const cwd of ['/',root,home,gone]){
|
|
45
|
+
const out=run(home,{cwd});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),cwd+out);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
test('a pointer to HOME with a stale status file never leaks into projects under HOME',()=>fixture(({home})=>{
|
|
50
|
+
const other=path.join(home,'work','other');fs.mkdirSync(other,{recursive:true});
|
|
51
|
+
fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),home);
|
|
52
|
+
fs.writeFileSync(path.join(home,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
|
|
53
|
+
const out=run(home,{cwd:other});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),out);
|
|
54
|
+
}));
|
|
@@ -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
|
-
- 机器条件与理由见
|
|
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
|
|
|
@@ -94,11 +94,12 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-spec-amend.mjs" inspect --specs-dir "{SPECS_
|
|
|
94
94
|
|
|
95
95
|
开工前按 `runtime/review.md` 探测能否建立**与实现者不同上下文**的审查通道,而不是检查当前进程是否叫 Codex:
|
|
96
96
|
|
|
97
|
-
-
|
|
97
|
+
- 项目声明审查者为 `claude-cli`(含 `claude-only`)→ 只探测全新 Claude CLI 审查进程,不探测 Codex;不可用即暂停
|
|
98
|
+
- 其余情况:可创建 fresh Codex 子代理/独立线程 → 作为主通道
|
|
98
99
|
- 子代理不可用,但可以安全启动隔离的 `codex` CLI 审查会话 → 作为备用通道
|
|
99
100
|
- 两者都不可用 → 暂停新开发,已有实现保持待审并说明通道失败原因;不论任务风险高低,都不能用 `self-degraded` 诊断代替独立审查或进入成功收尾
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
Codex 与 Claude 两条通道都由 protected host 实际启动并回收 V3 凭证;凭证标明实际审查端,不能把
|
|
102
103
|
Claude 结果标成 Codex 通过门禁。通道不可用不算代码 finding,不消耗实现审查轮次。
|
|
103
104
|
|
|
104
105
|
## Git 前置检查(字段优先,询问兜底)
|