carlos-flow 2.6.1 → 2.6.3
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/CHANGELOG.md +64 -0
- package/TRIGGER_GUIDE.md +5 -5
- package/ghost.json +77 -1
- package/package.json +7 -3
- package/plugins/carlos-flow-trigger.js +215 -204
- package/scripts/full-audit.mjs +242 -0
- package/scripts/lang-audit.mjs +164 -0
- package/scripts/mutation-check.mjs +1 -1
- package/scripts/sync-readme.mjs +10 -7
- package/scripts/verify-activation-e2e.sh +1 -1
- package/scripts/verify-install-e2e.sh +20 -7
- package/src/index.js +13 -1
- package/src/protocol.js +76 -76
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// full-audit.mjs — 对外产物全面体检(身份 / 版本 / 文档 / 产物 / 源码 / 死链 / 工具清单)
|
|
2
|
+
//
|
|
3
|
+
// 为什么需要:
|
|
4
|
+
// 2026-11-07 单包合并后,仓库里散落着大量**双仓时代**的遗留:
|
|
5
|
+
// 指向已删除仓库的链接、硬编码旧包名的插件路径、开发者本机路径、
|
|
6
|
+
// 死链、ghost.json 工具清单缺 3 个(导致 Cindy 用户看不到它们)。
|
|
7
|
+
// 这些问题**不会让任何测试变红**,但会直接让用户看到错误信息。
|
|
8
|
+
// 所以要有一道「产物面向用户是否正确」的独立体检。
|
|
9
|
+
//
|
|
10
|
+
// 检查项:
|
|
11
|
+
// 1. 旧仓库 / 旧包名残留引用(区分「迁移文档里的正当提及」与「真实残留」)
|
|
12
|
+
// 2. 个人路径 / 开发者机路径残留
|
|
13
|
+
// 3. 版本号一致性(package.json / lock / ghost.json / TRIGGER_GUIDE / CHANGELOG / 各文档)
|
|
14
|
+
// 4. 文档内部死链
|
|
15
|
+
// 5. npm 发布集合完整性与敏感文件
|
|
16
|
+
// 6. 模板占位符(__ROOT__)与合法性
|
|
17
|
+
// 7. package.json 关键字段(bin / exports / scripts / repository)
|
|
18
|
+
// 8. scripts 与 CI 不再残留双仓逻辑
|
|
19
|
+
// 9. ghost.json 工具清单 vs 服务端实际工具
|
|
20
|
+
//
|
|
21
|
+
// 退出码:0 = 全部通过;1 = 发现问题
|
|
22
|
+
import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
|
|
23
|
+
import { join, resolve, dirname } from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
|
|
26
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
27
|
+
|
|
28
|
+
const problems = [];
|
|
29
|
+
const notes = [];
|
|
30
|
+
const P = (cat, msg) => problems.push(`[${cat}] ${msg}`);
|
|
31
|
+
const N = (cat, msg) => notes.push(`[${cat}] ${msg}`);
|
|
32
|
+
|
|
33
|
+
const read = (p) => { try { return readFileSync(join(ROOT, p), "utf8"); } catch { return null; } };
|
|
34
|
+
const readJson = (p) => { const t = read(p); if (!t) return null; try { return JSON.parse(t); } catch (e) { return { __error: e.message }; } };
|
|
35
|
+
|
|
36
|
+
const pkg = readJson("package.json");
|
|
37
|
+
const VERSION = pkg?.version;
|
|
38
|
+
|
|
39
|
+
// ---- 个人路径模式:用「拼接」表达,避免本脚本自己被扫出来 ----
|
|
40
|
+
const PERSONAL_PATTERNS = [
|
|
41
|
+
// 描述文字里也不能出现完整字面量 —— 否则本脚本自己会被扫出来。
|
|
42
|
+
["D:" + "/cindy", "硬编码开发者机路径(盘符 + 项目目录)"],
|
|
43
|
+
["D:" + "/dev-env", "硬编码开发者机路径(盘符 + 工具链目录)"],
|
|
44
|
+
["C:" + "/Users/EDY", "硬编码开发者机路径(盘符 + 用户目录)"],
|
|
45
|
+
["/home/" + "edy", "硬编码开发者机路径(家目录 + 用户名)"],
|
|
46
|
+
["opencode-" + "backups", "硬编码开发者机目录(旧备份目录名)"],
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
// ---- 旧包名:迁移文档里提及是正当的 ----
|
|
50
|
+
const LEGACY_NAMES = ["carlos-flow-" + "cindy", "carlos-flow-" + "opencode"];
|
|
51
|
+
// 这些文件里出现旧包名是**正当的**(迁移指引 / 版本历史 / 弃用说明)
|
|
52
|
+
const LEGACY_ALLOWED_FILES = /^(MIGRATION\.md|CHANGELOG\.md|README(\.zh|\.en)?\.md|RELEASE_NOTES\.md)$/;
|
|
53
|
+
// 这些文件里出现旧包名是**正当的**(脚本在讲「旧包名已废弃」这件事本身)
|
|
54
|
+
const LEGACY_ALLOWED_SCRIPTS = /^(scripts\/check-repo-parity\.mjs|scripts\/full-audit\.mjs|scripts\/mutation-check\.mjs|plugins\/carlos-flow-trigger\.js)$/;
|
|
55
|
+
|
|
56
|
+
const scanFiles = [];
|
|
57
|
+
const walk = (dir, depth = 0) => {
|
|
58
|
+
if (depth > 3) return;
|
|
59
|
+
let entries = [];
|
|
60
|
+
try { entries = readdirSync(dir); } catch { return; }
|
|
61
|
+
for (const e of entries) {
|
|
62
|
+
if (e === "node_modules" || e === ".git" || e === "docs") continue;
|
|
63
|
+
const full = join(dir, e);
|
|
64
|
+
let st;
|
|
65
|
+
try { st = statSync(full); } catch { continue; }
|
|
66
|
+
if (st.isDirectory()) walk(full, depth + 1);
|
|
67
|
+
else if (/\.(md|json|js|mjs|cjs|sh|yml|yaml|html)$/.test(e)) scanFiles.push(full);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
walk(ROOT);
|
|
71
|
+
|
|
72
|
+
const relOf = (f) => f.slice(ROOT.length + 1).replace(/\\/g, "/");
|
|
73
|
+
|
|
74
|
+
// ========== 1 + 2. 旧引用 / 个人路径 ==========
|
|
75
|
+
console.log("▶ 1. 旧引用与个人路径");
|
|
76
|
+
for (const f of scanFiles) {
|
|
77
|
+
const rel = relOf(f);
|
|
78
|
+
const text = readFileSync(f, "utf8");
|
|
79
|
+
|
|
80
|
+
for (const name of LEGACY_NAMES) {
|
|
81
|
+
const hits = text.match(new RegExp(name.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"));
|
|
82
|
+
if (!hits || !hits.length) continue;
|
|
83
|
+
const legacyOk = LEGACY_ALLOWED_FILES.test(rel) || LEGACY_ALLOWED_SCRIPTS.test(rel);
|
|
84
|
+
// package.json 的 bin 兼容别名是**刻意保留**的
|
|
85
|
+
if (rel === "package.json" || rel === "package-lock.json") {
|
|
86
|
+
N("旧引用", `${rel} 含兼容别名 ${name}(刻意保留)`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (legacyOk) N("旧引用", `${rel} 提及旧包名 ${name}(迁移/弃用说明,正当)`);
|
|
90
|
+
else P("旧引用", `${rel} 含旧包名 ${name}(需改为 carlos-flow)`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const [pat, desc] of PERSONAL_PATTERNS) {
|
|
94
|
+
const hits = text.split(pat).length - 1;
|
|
95
|
+
if (!hits) continue;
|
|
96
|
+
// CHANGELOG 是版本历史,刻意保留被修复路径的原样描述以便追溯
|
|
97
|
+
if (rel === "CHANGELOG.md") { N("个人路径", `${rel} 含 ${hits} 处${desc}(版本历史,正当)`); continue; }
|
|
98
|
+
P("个人路径", `${rel} 含 ${hits} 处${desc}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ========== 3. 版本号一致性 ==========
|
|
103
|
+
console.log("▶ 2. 版本号一致性");
|
|
104
|
+
const compareVer = (a, b) => {
|
|
105
|
+
const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
|
|
106
|
+
for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) - (pb[i] || 0);
|
|
107
|
+
return 0;
|
|
108
|
+
};
|
|
109
|
+
const lock = readJson("package-lock.json");
|
|
110
|
+
const lockVersions = [lock?.version, lock?.packages?.[""]?.version].filter(Boolean);
|
|
111
|
+
for (const v of new Set(lockVersions)) {
|
|
112
|
+
if (v !== VERSION) P("版本", `package-lock.json 版本 = ${v},package.json = ${VERSION}`);
|
|
113
|
+
}
|
|
114
|
+
const ghostVer = readJson("ghost.json")?.version;
|
|
115
|
+
const checks = [
|
|
116
|
+
["ghost.json", ghostVer],
|
|
117
|
+
];
|
|
118
|
+
for (const [f, v] of checks) {
|
|
119
|
+
if (!v) P("版本", `${f} 读不到版本号`);
|
|
120
|
+
else if (v !== VERSION) P("版本", `${f} = ${v},package.json = ${VERSION}`);
|
|
121
|
+
}
|
|
122
|
+
// 版本号提取:冒号可能是半角 `:` 或全角 `:`(Markdown 里两种都常见)。
|
|
123
|
+
// 旧实现只认半角,于是「**版本**:v2.6.0」这种全角写法会被**漏检** ——
|
|
124
|
+
// 结果是升版本时只改了一半,文档里留下旧版本号。
|
|
125
|
+
const guideText = read("TRIGGER_GUIDE.md") || "";
|
|
126
|
+
const guideV = (guideText.match(/\*\*版本\*\*\s*[::]\s*v?(\d+\.\d+\.\d+)/) || [])[1];
|
|
127
|
+
const guideVs = [...guideText.matchAll(/\*\*版本\*\*\s*[::]\s*v?(\d+\.\d+\.\d+)/g)].map((m) => m[1]);
|
|
128
|
+
if (guideV !== VERSION) P("版本", `TRIGGER_GUIDE.md = ${guideV},package.json = ${VERSION}`);
|
|
129
|
+
if (new Set(guideVs).size > 1) {
|
|
130
|
+
P("版本", `TRIGGER_GUIDE.md 出现多个版本号:${[...new Set(guideVs)].join(", ")}(升版本时漏改)`);
|
|
131
|
+
}
|
|
132
|
+
const changelogV = ((read("CHANGELOG.md") || "").match(/^## \[(\d+\.\d+\.\d+)\]/m) || [])[1];
|
|
133
|
+
if (changelogV !== VERSION) P("版本", `CHANGELOG.md 顶部 = ${changelogV},package.json = ${VERSION}`);
|
|
134
|
+
for (const f of ["README.md", "README.zh.md", "README.en.md", "MIGRATION.md", "RELEASE_NOTES.md"]) {
|
|
135
|
+
const t = read(f);
|
|
136
|
+
if (!t) { P("版本", `${f} 缺失`); continue; }
|
|
137
|
+
const vers = [...new Set(t.match(/\b2\.\d+\.\d+\b/g) || [])];
|
|
138
|
+
const future = vers.filter((v) => v !== VERSION && compareVer(v, VERSION) > 0);
|
|
139
|
+
if (future.length) P("版本", `${f} 出现比当前版本更高的版本号:${future.join(", ")}`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ========== 4. 文档死链 ==========
|
|
143
|
+
console.log("▶ 3. 文档内部死链");
|
|
144
|
+
for (const f of ["README.md", "README.zh.md", "README.en.md", "MIGRATION.md", "TRIGGER_GUIDE.md", "CHANGELOG.md", "CONTRIBUTING.md", "SECURITY.md", "CODE_OF_CONDUCT.md"]) {
|
|
145
|
+
const t = read(f);
|
|
146
|
+
if (!t) continue;
|
|
147
|
+
const links = [...t.matchAll(/\]\((\.[^)#]+)(#[^)]*)?\)/g)].map((m) => m[1]);
|
|
148
|
+
for (const l of new Set(links)) {
|
|
149
|
+
const target = resolve(dirname(join(ROOT, f)), l);
|
|
150
|
+
if (!existsSync(target)) P("死链", `${f} → ${l}(目标不存在)`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ========== 5. npm 发布集合 ==========
|
|
155
|
+
console.log("▶ 4. npm 发布集合");
|
|
156
|
+
const published = [];
|
|
157
|
+
const add = (rel) => {
|
|
158
|
+
const full = join(ROOT, rel);
|
|
159
|
+
if (!existsSync(full)) return;
|
|
160
|
+
let st; try { st = statSync(full); } catch { return; }
|
|
161
|
+
if (st.isDirectory()) for (const e of readdirSync(full)) add(rel.replace(/\/$/, "") + "/" + e);
|
|
162
|
+
else published.push(rel.replace(/\\/g, "/"));
|
|
163
|
+
};
|
|
164
|
+
for (const f of pkg?.files || []) add(f);
|
|
165
|
+
const MUST_IN_PKG = [
|
|
166
|
+
"client/carlos.js", "src/index.js", "src/trigger.js", "src/state.js", "src/protocol.js",
|
|
167
|
+
"bridge/mcp-bridge.js", "plugins/carlos-flow-trigger.js", "ghost.json", "opencode.json",
|
|
168
|
+
"opencode.json.template", ".mcprc.template", "trigger-config.usable.json",
|
|
169
|
+
"templates/cursor/mcp.json", "templates/cline/mcp.json", "templates/vscode/mcp.json",
|
|
170
|
+
"templates/claude/claude_desktop_config.json",
|
|
171
|
+
"README.md", "README.zh.md", "README.en.md", "TRIGGER_GUIDE.md", "MIGRATION.md",
|
|
172
|
+
"CHANGELOG.md", "LICENSE",
|
|
173
|
+
];
|
|
174
|
+
for (const f of MUST_IN_PKG) if (!published.includes(f)) P("包内容", `发布集合缺 ${f}`);
|
|
175
|
+
const FORBIDDEN = [/(^|\/)\.npmrc$/, /secret\.json$/, /\.b64$/, /\.bak$/, /\.pid$/, /^fix_/, /^debug_/];
|
|
176
|
+
for (const f of published) if (FORBIDDEN.some((re) => re.test(f))) P("包内容", `发布集合含敏感/临时文件 ${f}`);
|
|
177
|
+
|
|
178
|
+
// ========== 6. 模板 ==========
|
|
179
|
+
console.log("▶ 5. 模板占位符与合法性");
|
|
180
|
+
for (const tpl of ["ghost.json", "opencode.json", "templates/cursor/mcp.json", "templates/cline/mcp.json", "templates/vscode/mcp.json", "templates/claude/claude_desktop_config.json", "trigger-config.usable.json"]) {
|
|
181
|
+
const j = readJson(tpl);
|
|
182
|
+
if (!j) P("模板", `${tpl} 缺失`);
|
|
183
|
+
else if (j.__error) P("模板", `${tpl} 不是合法 JSON:${j.__error}`);
|
|
184
|
+
}
|
|
185
|
+
// .mcprc.template 是 YAML(带注释),不能用 JSON 解析 —— 只检查关键字段存在
|
|
186
|
+
const mcprc = read(".mcprc.template") || "";
|
|
187
|
+
if (!mcprc.includes("carlos-flow")) P("模板", ".mcprc.template 未声明 carlos-flow");
|
|
188
|
+
if (!mcprc.includes("__ROOT__")) P("模板", ".mcprc.template 缺少 __ROOT__ 占位符");
|
|
189
|
+
for (const tpl of ["ghost.json", "opencode.json"]) {
|
|
190
|
+
const t = read(tpl) || "";
|
|
191
|
+
if (!t.includes("__ROOT__")) P("模板", `${tpl} 缺少 __ROOT__ 占位符(init 渲染不到实际路径)`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ========== 7. package.json 字段 ==========
|
|
195
|
+
console.log("▶ 6. package.json 字段");
|
|
196
|
+
if (pkg) {
|
|
197
|
+
const bins = Object.keys(pkg.bin || {});
|
|
198
|
+
for (const b of ["carlos-flow", "carlos-flow-cindy", "carlos-flow-opencode"]) {
|
|
199
|
+
if (!bins.includes(b)) P("package.json", `bin 缺 ${b}`);
|
|
200
|
+
}
|
|
201
|
+
if (!pkg.repository?.url?.includes("carlos-flow.git")) P("package.json", "repository.url 不指向新仓库");
|
|
202
|
+
if (!pkg.homepage?.includes("carlos-flow")) P("package.json", "homepage 不指向新仓库");
|
|
203
|
+
if (!pkg.exports?.["./cindy"]) P("package.json", "exports 缺 ./cindy");
|
|
204
|
+
if (!pkg.exports?.["./opencode"]) P("package.json", "exports 缺 ./opencode");
|
|
205
|
+
for (const s of ["check:lang", "test:lang", "check:identity", "check:anchors", "test:all"]) {
|
|
206
|
+
if (!pkg.scripts?.[s]) P("package.json", `scripts 缺 ${s}`);
|
|
207
|
+
}
|
|
208
|
+
if (!pkg.description || !/[一-鿿]/.test(pkg.description)) P("package.json", "description 非中文");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ========== 8. 脚本与 CI 不残留双仓逻辑 ==========
|
|
212
|
+
console.log("▶ 7. 脚本与 CI");
|
|
213
|
+
const relScript = read("scripts/release.mjs") || "";
|
|
214
|
+
if (!relScript.includes('"carlos-flow"')) P("脚本", "release.mjs 未识别单包身份 carlos-flow");
|
|
215
|
+
if (/PEER_ID|PEER_PATH|repoPathOf/.test(relScript)) P("脚本", "release.mjs 仍残留双仓逻辑");
|
|
216
|
+
const ci = read(".github/workflows/ci.yml") || "";
|
|
217
|
+
if (/^\s*parity:/m.test(ci)) P("CI", "ci.yml 仍残留双仓 parity job");
|
|
218
|
+
if (/carlos-flow-cindy|carlos-flow-opencode/.test(ci)) P("CI", "ci.yml 仍残留旧仓库名");
|
|
219
|
+
const relWf = read(".github/workflows/release.yml") || "";
|
|
220
|
+
if (/carlos-flow-cindy|carlos-flow-opencode/.test(relWf)) P("CI", "release.yml 仍残留旧仓库名");
|
|
221
|
+
|
|
222
|
+
// ========== 9. ghost.json 工具清单 ==========
|
|
223
|
+
console.log("▶ 8. ghost.json 工具清单");
|
|
224
|
+
const ghostJson = readJson("ghost.json");
|
|
225
|
+
const idx = read("src/index.js") || "";
|
|
226
|
+
const uniqueServer = [...new Set([...idx.matchAll(/name:\s*"(flow_[a-z_]+)"/g)].map((m) => m[1]))];
|
|
227
|
+
const ghostTools = (ghostJson?.tools || []).map((t) => t.name);
|
|
228
|
+
if (ghostTools.length !== uniqueServer.length) {
|
|
229
|
+
P("工具清单", `ghost.json 声明 ${ghostTools.length} 个,服务端实际 ${uniqueServer.length} 个`);
|
|
230
|
+
}
|
|
231
|
+
for (const t of uniqueServer) if (!ghostTools.includes(t)) P("工具清单", `ghost.json 缺工具 ${t}`);
|
|
232
|
+
for (const t of ghostTools) if (!uniqueServer.includes(t)) P("工具清单", `ghost.json 声明了服务端不存在的工具 ${t}`);
|
|
233
|
+
|
|
234
|
+
// ---- 输出 ----
|
|
235
|
+
console.log("\n" + "=".repeat(72));
|
|
236
|
+
console.log(problems.length === 0
|
|
237
|
+
? `✅ 产物全面体检通过(${notes.length} 条正当说明)`
|
|
238
|
+
: `❌ 发现 ${problems.length} 个问题,${notes.length} 条正当说明`);
|
|
239
|
+
console.log("=".repeat(72));
|
|
240
|
+
for (const p of problems) console.log("❌ " + p);
|
|
241
|
+
if (process.env.SHOW_NOTES === "1") for (const n of notes) console.log("ℹ️ " + n);
|
|
242
|
+
process.exit(problems.length ? 1 : 0);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// lang-audit.mjs — 产物语言体检(中文合规守卫)
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要这个守卫:
|
|
5
|
+
// 2026-11-07 发生过一次真实事故 —— 同一会话里对话回复全是中文,
|
|
6
|
+
// 但**连续 5 个 git 提交信息写成了完整英文段落**,用户当场指为「非常严重的技术事故」。
|
|
7
|
+
//
|
|
8
|
+
// 根因不是「没看到用户要求」(要求早已写入记忆),而是:
|
|
9
|
+
// · 对话语言是合规的,肉眼扫一遍「回复」完全看不出问题;
|
|
10
|
+
// · 漏检的全部是**产物**(提交信息、注释、脚本文案、文档正文),
|
|
11
|
+
// 而产物会持久化并对外分发(进 GitHub、进 npm 包),影响面远大于一次对话。
|
|
12
|
+
//
|
|
13
|
+
// 所以「我说的是中文的」不能作为合规判据 —— 必须**单独检查产物**。
|
|
14
|
+
// 本脚本把这件事自动化,让它不依赖临场自觉。
|
|
15
|
+
//
|
|
16
|
+
// 检查范围:
|
|
17
|
+
// 1) git 提交信息(标题 + 正文,排除代码块与含中文的行)
|
|
18
|
+
// 2) 源码注释(.js/.mjs/.cjs/.sh/.yml/.yaml)
|
|
19
|
+
//
|
|
20
|
+
// 允许英文的例外(外部接口约束,不算违反):
|
|
21
|
+
// 标识符、命令、路径、报错原文、API 字段名、日志原文、技术专有名词、
|
|
22
|
+
// 用户自己写的英文、以及被明确要求产出的英文材料(如 README.en.md)。
|
|
23
|
+
//
|
|
24
|
+
// 退出码:0 = 合规;1 = 发现英文叙述(逐条打印位置)
|
|
25
|
+
import { execFileSync } from "node:child_process";
|
|
26
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
27
|
+
import { join, resolve, dirname } from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
|
|
30
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
31
|
+
|
|
32
|
+
// 允许出现在中文语境里的英文词(标识符 / 专有名词 / 外部接口名)
|
|
33
|
+
// 读文件并按行拆分。
|
|
34
|
+
// ⚠️ 必须处理 CRLF:JavaScript 正则的 `.` **不匹配 `\r`**(它是行终止符),
|
|
35
|
+
// 所以「按 \n 拆分」在 Windows 上会留下一行尾的 `\r`,
|
|
36
|
+
// 导致 `(.+)$` 完全匹配不上 —— 注释扫描会**静默扫不到任何一行**,
|
|
37
|
+
// 体检结果就是假绿。
|
|
38
|
+
// 这正是 2026-11-07 实际发生的事:本地(CRLF)全部通过,CI(LF)却报出真问题。
|
|
39
|
+
const readLines = (file) => {
|
|
40
|
+
const raw = readFileSync(file, "utf8");
|
|
41
|
+
return raw.split(/\r?\n/);
|
|
42
|
+
};
|
|
43
|
+
// 注意:必须**按词排除**而不是整行排除 —— 否则
|
|
44
|
+
// 「fix(release): add missing shebang to bin entry」
|
|
45
|
+
// 里的 fix / release 会让整行被放行,英文叙述就漏检了。
|
|
46
|
+
const ALLOWED_WORDS = new Set([
|
|
47
|
+
"npm", "mcp", "node", "json", "yaml", "yml", "github", "gitlab", "ci", "carlos",
|
|
48
|
+
"readme", "changelog", "trigger", "guide", "migration", "error", "timeout",
|
|
49
|
+
"ok", "verify", "scope", "acceptance", "sessionid", "init", "target", "git",
|
|
50
|
+
"commit", "release", "docs", "fix", "feat", "chore", "test", "yarn", "npx",
|
|
51
|
+
"shell", "stdin", "stdout", "stderr", "http", "https", "api", "url", "repo",
|
|
52
|
+
"src", "lib", "bin", "tool", "tools", "service", "server", "client", "bridge",
|
|
53
|
+
"plugin", "template", "templates", "license", "mit", "apache", "bsd", "utf",
|
|
54
|
+
"linux", "windows", "macos", "opencode", "cursor", "cline", "claude", "copilot",
|
|
55
|
+
"version", "semver", "keep", "monorepo", "shim", "shebang", "validatecard",
|
|
56
|
+
"tier", "read", "goal", "quote", "cmd", "argv", "env", "pkg", "args",
|
|
57
|
+
"opts", "params", "config", "keywordweights", "readonly", "intentwords",
|
|
58
|
+
"mutatingactionwords", "flow", "user", "msgs", "state",
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const MIN_WORDS = 5; // 连续 5 个以上英文词才判定为「英文叙述」
|
|
62
|
+
const MIN_COMMIT_WORDS = 3; // 提交信息阈值低一点(正文段落更短)
|
|
63
|
+
|
|
64
|
+
// 判定规则:**一行里只要有中文字符就算合规**(标识符、报错原文、引用的英文术语
|
|
65
|
+
// 嵌在中文句子里是正常的);只有**整行没有中文**、且英文词达到阈值时才算违规。
|
|
66
|
+
// 之前的写法用「英文词数」直接判,会把
|
|
67
|
+
// 「exitCode=127(command not found),记 PASS 的前置证据永远拿不到」
|
|
68
|
+
// 这类「中文句子 + 引用的英文报错」误判 —— 那是合规的中文注释。
|
|
69
|
+
const isEnglishNarration = (text, minWords) => {
|
|
70
|
+
if (/[一-鿿]/.test(text)) return false; // 有中文 → 合规
|
|
71
|
+
|
|
72
|
+
// 剥离「引用的原文」:中文句子里的英文报错原文、代码块、标识符引用
|
|
73
|
+
let s = text
|
|
74
|
+
.replace(/[「」『』“”"'‘’`][^「」『』“”"'‘’`]*[「」『』“”"'‘’`]/g, " ")
|
|
75
|
+
.replace(/`[^`]*`/g, " ");
|
|
76
|
+
|
|
77
|
+
// 命令行 / 路径示例行:含 `--` 参数、以命令前缀开头、或形如 a/b/c
|
|
78
|
+
if (/^\s*(\$|>)?\s*(node|npm|npx|yarn|git|bash|sh|python3?|curl|cd|echo|export|carlos-flow|carlos)\b/i.test(s)) return false;
|
|
79
|
+
if (/\s--[a-z][\w-]*/i.test(s)) return false;
|
|
80
|
+
if (/^[A-Za-z0-9_.\-/]+\s*[=:]/i.test(s.trim()) && !/\s/.test(s.trim())) return false;
|
|
81
|
+
|
|
82
|
+
const words = (s.match(/[A-Za-z][A-Za-z'-]{2,}/g) || []).map((w) => w.toLowerCase());
|
|
83
|
+
if (words.length < minWords) return false;
|
|
84
|
+
// 去掉允许词后仍需达到足够密度,否则整句都是专有名词/标识符
|
|
85
|
+
const residual = words.filter((w) => !ALLOWED_WORDS.has(w));
|
|
86
|
+
if (residual.length < Math.max(3, Math.ceil(words.length * 0.4))) return false;
|
|
87
|
+
return true;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
let problems = 0;
|
|
91
|
+
const report = (where, text) => {
|
|
92
|
+
console.log(` ❌ ${where}`);
|
|
93
|
+
console.log(` ${text.slice(0, 110)}`);
|
|
94
|
+
problems++;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ---- 1. 提交信息 ----
|
|
98
|
+
console.log("▶ 提交信息");
|
|
99
|
+
try {
|
|
100
|
+
const raw = execFileSync("git", ["log", "--format=%H%x00%B%x00%x00", "-15"], {
|
|
101
|
+
cwd: ROOT,
|
|
102
|
+
encoding: "utf8",
|
|
103
|
+
});
|
|
104
|
+
const parts = raw.split("\u0000").filter((s) => s.trim());
|
|
105
|
+
let commitProblems = 0;
|
|
106
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
107
|
+
const sha = (parts[i] || "").trim();
|
|
108
|
+
const body = parts[i + 1] || "";
|
|
109
|
+
let inCode = false;
|
|
110
|
+
for (const line of body.split("\n")) {
|
|
111
|
+
if (/^\s*```/.test(line)) { inCode = !inCode; continue; }
|
|
112
|
+
if (inCode) continue;
|
|
113
|
+
const t = line.trim();
|
|
114
|
+
if (!t) continue;
|
|
115
|
+
if (!isEnglishNarration(t, MIN_COMMIT_WORDS)) continue;
|
|
116
|
+
report(`提交 ${sha.slice(0, 7)}`, t);
|
|
117
|
+
commitProblems++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (commitProblems === 0) console.log(" ✅ 提交信息均为中文");
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.log(" ⏭ 跳过(取不到 git 历史)");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---- 2. 源码注释 ----
|
|
126
|
+
console.log("\n▶ 源码注释");
|
|
127
|
+
const walk = (dir, depth = 0) => {
|
|
128
|
+
if (depth > 4) return [];
|
|
129
|
+
let out = [];
|
|
130
|
+
let entries = [];
|
|
131
|
+
try { entries = readdirSync(dir); } catch { return out; }
|
|
132
|
+
for (const e of entries) {
|
|
133
|
+
if (e === "node_modules" || e === ".git") continue;
|
|
134
|
+
const full = join(dir, e);
|
|
135
|
+
let st;
|
|
136
|
+
try { st = statSync(full); } catch { continue; }
|
|
137
|
+
if (st.isDirectory()) out = out.concat(walk(full, depth + 1));
|
|
138
|
+
else if (/\.(js|mjs|cjs|sh|yml|yaml)$/.test(e)) out.push(full);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
let codeProblems = 0;
|
|
144
|
+
for (const f of walk(ROOT)) {
|
|
145
|
+
const rel = f.slice(ROOT.length + 1).replace(/\\/g, "/");
|
|
146
|
+
const lines = readLines(f);
|
|
147
|
+
lines.forEach((line, i) => {
|
|
148
|
+
const m = line.match(/^\s*(?:\/\/|#)\s*(.+)$/);
|
|
149
|
+
if (!m) return;
|
|
150
|
+
const t = m[1].trim();
|
|
151
|
+
if (!isEnglishNarration(t, MIN_WORDS)) return;
|
|
152
|
+
report(`${rel}:${i + 1}`, t);
|
|
153
|
+
codeProblems++;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (codeProblems === 0) console.log(" ✅ 源码注释均为中文");
|
|
157
|
+
|
|
158
|
+
console.log("");
|
|
159
|
+
if (problems > 0) {
|
|
160
|
+
console.log(`❌ 产物语言体检失败:发现 ${problems} 处英文叙述`);
|
|
161
|
+
console.log(" 修复方式:把对应内容改写为中文(标识符、命令、报错原文可保留原样)");
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
console.log("✅ 产物语言体检通过");
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 用法: node scripts/mutation-check.mjs [源仓路径]
|
|
6
6
|
// 产物: <仓库>/.mutation-report.md(可用 MUTATION_REPORT 覆盖)
|
|
7
7
|
//
|
|
8
|
-
//
|
|
8
|
+
// 跨平台:原先硬编码了某台开发机的本机路径与 Git Bash 路径,CI(ubuntu)必失败。
|
|
9
9
|
// 现在:源仓默认取当前仓库根目录;工作副本/报告路径走临时目录或环境变量;
|
|
10
10
|
// shell 按平台选择(Windows 用 cmd,POSIX 用默认 sh)。
|
|
11
11
|
import { execSync } from "node:child_process";
|
package/scripts/sync-readme.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// sync-readme.mjs —
|
|
2
|
+
// sync-readme.mjs — 保持多语言 README 集合一致
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// 文件布局(方案 A —— 三份独立文件):
|
|
5
5
|
// README.md ← 中文主文档(GitHub 首页 / npm 渲染页默认展示)
|
|
6
6
|
// README.zh.md ← 中文副本(保证 /README.zh.md 直链可用,与主文档一致)
|
|
7
7
|
// README.en.md ← 英文完整版(顶部语言栏切换目标)
|
|
8
8
|
//
|
|
9
|
-
//
|
|
10
|
-
// node scripts/sync-readme.mjs #
|
|
11
|
-
// node scripts/sync-readme.mjs --check #
|
|
9
|
+
// 用法:
|
|
10
|
+
// node scripts/sync-readme.mjs # 同步并校验(发现漂移时退出码 1)
|
|
11
|
+
// node scripts/sync-readme.mjs --check # 只校验,绝不写文件
|
|
12
12
|
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import path from "node:path";
|
|
@@ -86,8 +86,11 @@ if (!existsSync(TRIGGER_GUIDE)) {
|
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
88
88
|
})();
|
|
89
|
-
// 尝试从末尾的 '**版本**:' 字段提取版本号,去掉可能的 'v'
|
|
90
|
-
|
|
89
|
+
// 尝试从末尾的 '**版本**:' 字段提取版本号,去掉可能的 'v' 前缀。
|
|
90
|
+
// 冒号可能是半角 `:` 或全角 `:`(Markdown 里两种都常见)—— 早先只认半角,
|
|
91
|
+
// 结果升版本时把 TRIGGER_GUIDE.md 里写成全角的那一处漏改,本检查直接报
|
|
92
|
+
// 「提取不到版本号」而看不出真实原因。
|
|
93
|
+
const versionMatch = guide.match(/\*\*版本\*\*\s*[::]\s*(v?\d+\.\d+\.\d+)/);
|
|
91
94
|
const versionInGuide = versionMatch ? versionMatch[1].replace(/^v/, '') : null;
|
|
92
95
|
if (pkgVersion && versionInGuide) {
|
|
93
96
|
log(versionInGuide === pkgVersion, `TRIGGER_GUIDE.md version is ${versionInGuide} vs package.json ${pkgVersion}`);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# 用法: bash scripts/verify-activation-e2e.sh [repo-root]
|
|
4
4
|
#
|
|
5
5
|
# 根目录默认从**脚本自身位置**推导(scripts/ → 仓库根),
|
|
6
|
-
# 不写死任何开发者的本机路径 ——
|
|
6
|
+
# 不写死任何开发者的本机路径 —— 旧实现写死了某台开发机的本机路径,
|
|
7
7
|
# 在别人机器上会 cd 到不存在的路径;且在 opencode 包里还指向 cindy 仓(跨仓串味)。
|
|
8
8
|
set -u
|
|
9
9
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
@@ -10,13 +10,15 @@
|
|
|
10
10
|
# 一律通过环境变量传给 node 进程。
|
|
11
11
|
#
|
|
12
12
|
# 用法: bash scripts/verify-install-e2e.sh
|
|
13
|
-
# 环境变量:CARLOS_FLOW_PKG(默认 carlos-flow
|
|
14
|
-
# CARLOS_FLOW_VERSION
|
|
13
|
+
# 环境变量:CARLOS_FLOW_PKG(默认 carlos-flow)
|
|
14
|
+
# CARLOS_FLOW_VERSION(默认取本仓 package.json 的版本)
|
|
15
15
|
set -u
|
|
16
16
|
|
|
17
17
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
18
|
-
PKG_NAME="${CARLOS_FLOW_PKG:-carlos-flow
|
|
19
|
-
|
|
18
|
+
PKG_NAME="${CARLOS_FLOW_PKG:-carlos-flow}"
|
|
19
|
+
# 版本默认取本仓 package.json —— 写死版本号会在每次发版后立刻过期
|
|
20
|
+
# (旧实现写死旧版本号,包名写死已废弃的旧包名 → 验证的是不存在的包)
|
|
21
|
+
PKG_VERSION="${CARLOS_FLOW_VERSION:-$(node -p "require('${SCRIPT_DIR}/../package.json').version")}"
|
|
20
22
|
|
|
21
23
|
echo "══ ① 从 npm 安装 $PKG_NAME@$PKG_VERSION ══"
|
|
22
24
|
# 用独立 prefix 模拟「干净环境」,不污染系统全局
|
|
@@ -92,9 +94,20 @@ child.kill(); process.exit(tp.activated ? 0 : 1);
|
|
|
92
94
|
|
|
93
95
|
echo ""
|
|
94
96
|
echo "══ ⑤ 审计:包内无个人私有路径 ══"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
# 模式用变量拼接写成 —— 否则这段脚本**自己就含字面量**,
|
|
98
|
+
# grep 会把它自己扫出来,审计永远失败(上一版就是这么坏的)。
|
|
99
|
+
# 拼���后的完整形态与下面的清单一致。
|
|
100
|
+
PERSONAL_A="D:"; PERSONAL_A="${PERSONAL_A}/cindy"
|
|
101
|
+
PERSONAL_B="C:"; PERSONAL_B="${PERSONAL_B}/Users/EDY"
|
|
102
|
+
PERSONAL_C="D:"; PERSONAL_C="${PERSONAL_C}/dev-env"
|
|
103
|
+
PERSONAL_D="/home/"; PERSONAL_D="${PERSONAL_D}edy"
|
|
104
|
+
# CHANGELOG.md 例外:它是**版本历史**,刻意保留被修复路径的原样描述以便追溯,
|
|
105
|
+
# 不是「仍在生效的配置」。除此之外,包内任何文件都不得出现个人路径。
|
|
106
|
+
HITS="$(grep -rl -e "${PERSONAL_A}" -e "${PERSONAL_B}" -e "${PERSONAL_C}" -e "${PERSONAL_D}" \
|
|
107
|
+
"$PKG_ROOT" 2>/dev/null | grep -v node_modules | grep -v 'CHANGELOG.md' | head -5)"
|
|
108
|
+
if [ -n "$HITS" ]; then
|
|
109
|
+
echo " ✗ 上列文件仍含个人私有路径:"
|
|
110
|
+
echo "$HITS" | sed 's/^/ /'
|
|
98
111
|
else
|
|
99
112
|
echo " ✓ 包内无个人私有路径"
|
|
100
113
|
fi
|
package/src/index.js
CHANGED
|
@@ -21,7 +21,19 @@ const log = (msg) => {
|
|
|
21
21
|
|
|
22
22
|
// ---- 通用工具函数 ----------------------------------------------------------
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// 成功响应:统一注入 ok:true。
|
|
25
|
+
//
|
|
26
|
+
// 之前各工具的 payload 有的显式写 \`ok: true\`、有的没写(如 flow_audit),
|
|
27
|
+
// 于是调用方拿到手的心智模型不一致 —— 想判断成败只能逐个工具记「这个有没有 ok」。
|
|
28
|
+
// 现在由 ok() 统一注入:
|
|
29
|
+
// · payload 里没有 ok 字段 → 补上 ok:true
|
|
30
|
+
// · payload 里已有 ok 字段 → 保留原值(不改 ok:false 的语义)
|
|
31
|
+
// 这是**增量兼容**:现有调用方读取 total / events / by_type 等字段不受影响。
|
|
32
|
+
const ok = (obj) => {
|
|
33
|
+
const payload = obj && typeof obj === "object" && !Array.isArray(obj) ? obj : { value: obj };
|
|
34
|
+
const withOk = "ok" in payload ? payload : { ok: true, ...payload };
|
|
35
|
+
return { content: [{ type: "text", text: JSON.stringify(withOk, null, 2) }] };
|
|
36
|
+
};
|
|
25
37
|
const fail = (message) => ({ content: [{ type: "text", text: "ERROR: " + String(message) }], isError: true });
|
|
26
38
|
|
|
27
39
|
const asStringArray = (v) => (Array.isArray(v) ? v.map((x) => String(x)) : []);
|