carlos-flow 2.6.1 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/TRIGGER_GUIDE.md +5 -5
- package/ghost.json +77 -1
- package/package.json +6 -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 +5 -5
- package/scripts/verify-activation-e2e.sh +1 -1
- package/scripts/verify-install-e2e.sh +20 -7
- package/src/protocol.js +76 -76
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [2.6.2] - 2026-11-07 — 对外产物全面排查:修掉 2 个严重 bug 与 5 类遗留
|
|
9
|
+
|
|
10
|
+
### 🐛 修复 | Fixed
|
|
11
|
+
|
|
12
|
+
> 这一版的每一项**都不会让任何测试变红**,但会直接让用户看到错误信息。
|
|
13
|
+
> 单包合并后仓库里散落着大量双仓时代的遗留,为此新增 `scripts/full-audit.mjs`
|
|
14
|
+
> 做独立的「对外产物体检」,首轮报出 49 项,本次修完归零。
|
|
15
|
+
|
|
16
|
+
| # | 问题 | 影响 | 修复 |
|
|
17
|
+
|---|------|------|------|
|
|
18
|
+
| T-69 | `plugins/carlos-flow-trigger.js` 硬编码找 `node_modules/carlos-flow-opencode` | 单包化后该目录**根本不存在** → 除「插件就在包内」外的所有安装方式都找不到 MCP server → **OpenCode 的自动触发静默失效**(不报错,只是永远不触发) | 改为同时尝试 `carlos-flow` 与两个已弃用旧包名;实测真实 npm 安装下能定位到 `src/index.js` |
|
|
19
|
+
| T-70 | `ghost.json` 只声明 12 个工具,缺 `flow_run_verify` / `flow_check_scope` / `flow_trigger_check` | **Cindy 用户根本看不到这三个工具** —— 服务端有、清单没有 | 补齐到 15 个,与服务端 `src/index.js` 逐一对齐;并新增「ghost.json 工具清单 vs 服务端实际工具」的一致性检查 |
|
|
20
|
+
| T-71 | `scripts/verify-install-e2e.sh` 默认验证已废弃的旧包名 + 写死的旧版本号 | 该脚本验证的是一个**不存在的包** → 装包验收形同虚设 | 默认包名改为 `carlos-flow`,版本改为取自本仓 `package.json` |
|
|
21
|
+
| T-72 | 该脚本的「包内无个人路径」审计,grep 模式里含字面量 | **必然检出自己** → 这项审计从来没通过过 | 模式改为变量拼接;`CHANGELOG.md` 例外(版本历史刻意保留被修复路径的原样描述,便于追溯) |
|
|
22
|
+
| T-73 | `TRIGGER_GUIDE.md` 三处死链(`../README.md` 等,文件本身就在根目录) | 文档里的链接点不开 | 改为 `./` 相对路径 |
|
|
23
|
+
| T-74 | `CONTRIBUTING.md` / `SECURITY.md` / `CODE_OF_CONDUCT.md` 指向已删除的旧仓库、保留双仓表述 | 社区文档与 Security Advisories 入口全部失效 | 全部改为单一仓库 `carlos-flow` |
|
|
24
|
+
| T-75 | `settings.html` 示例路径用旧包名、`settings.js` 注释含开发者机路径 | Cindy 插件设置页给用户错误的安装路径示例 | 清理 |
|
|
25
|
+
| T-76 | `scripts/verify-activation-e2e.sh` 与 `scripts/mutation-check.mjs` 注释含开发者机路径 | 随包分发的文件里出现开发者机路径 | 改为泛化表述 |
|
|
26
|
+
| T-77 | `TRIGGER_GUIDE.md` 的版本号有两种写法(半角 `:` 与全角 `:`),升版本时只改了一半 | 文档里留下旧版本号;体检脚本因只认半角而**漏检** | 版本提取兼容两种冒号;并新增「同一文件出现多个版本号」检查 |
|
|
27
|
+
|
|
28
|
+
### ✨ 新增 | Added
|
|
29
|
+
|
|
30
|
+
- **`scripts/full-audit.mjs`(`npm run check:full`)** —— 「对外产物体检」:
|
|
31
|
+
旧引用 / 个人路径 / 版本一致性 / 文档死链 / npm 发布集合 / 模板占位符 /
|
|
32
|
+
package.json 关键字段 / 脚本与 CI 的双仓残留 / ghost.json 工具清单,9 类检查。
|
|
33
|
+
- **CI 与 Release workflow 接入 `npm run check:full`** —— 上述遗留一旦复发立即红。
|
|
34
|
+
|
|
35
|
+
### 🔬 验证 | Verification
|
|
36
|
+
|
|
37
|
+
- `check:full` 通过(首轮 49 项 → 0)
|
|
38
|
+
- `check:identity` / `check:lang` / `test:lang`(12/0)全部通过
|
|
39
|
+
- 主测试 **129/0** 通过(smoke 4 / e2e 62 / p0 22 / trigger 29 / concurrency 3 / acceptance 13)
|
|
40
|
+
- 插件路径修复用**真实 npm 安装**实测:能定位到 `node_modules/carlos-flow/src/index.js`
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
8
44
|
## [2.6.1] - 2026-11-07 — 修复全局命令不可用(bin 缺 shebang)
|
|
9
45
|
|
|
10
46
|
### 🐛 修复 | Fixed
|
package/TRIGGER_GUIDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Carlos Flow 智能触发引擎使用指南
|
|
2
2
|
|
|
3
|
-
> **版本**:v2.6.
|
|
3
|
+
> **版本**:v2.6.2
|
|
4
4
|
> **适用**:`carlos-flow` 单包架构(2.6.0+)
|
|
5
5
|
> **代码位置**:`src/trigger.js`(零外部依赖的纯 JavaScript 实现)
|
|
6
6
|
|
|
@@ -769,9 +769,9 @@ node client/carlos.js flow_status '{"sessionId":"my-task"}'
|
|
|
769
769
|
- [变异测试](scripts/mutation-check.mjs) - 注入退化验证测试套件真的能抓住(13 类变异)
|
|
770
770
|
- [核心代码](src/trigger.js) - 触发引擎实现
|
|
771
771
|
- [集成示例](client/carlos.js) - 客户端集成代码
|
|
772
|
-
- [完整 README](
|
|
773
|
-
- [迁移指南](
|
|
774
|
-
- [更新日志](
|
|
772
|
+
- [完整 README](./README.md) - 项目总览与能力矩阵
|
|
773
|
+
- [迁移指南](./MIGRATION.md) - 从旧包升级
|
|
774
|
+
- [更新日志](./CHANGELOG.md) - 版本历史
|
|
775
775
|
|
|
776
776
|
## 📄 许可证
|
|
777
777
|
|
|
@@ -779,5 +779,5 @@ MIT License
|
|
|
779
779
|
|
|
780
780
|
---
|
|
781
781
|
|
|
782
|
-
**版本**: v2.6.
|
|
782
|
+
**版本**: v2.6.2
|
|
783
783
|
**更新日期**: 2026-11-07
|
package/ghost.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "Carlos 工作流",
|
|
6
6
|
"description": "机械门禁 MCP:留痕/派发/裁定/审计/快照/免检/还原。自动管理 Bridge 后台常驻,首次调用 ~3-5s,后续 ~1s。",
|
|
7
7
|
"whenToUse": "需要走 Carlos 工作流门禁时使用:留痕/派发/裁定/审计/快照/免检/还原",
|
|
8
|
-
"version": "2.6.
|
|
8
|
+
"version": "2.6.2",
|
|
9
9
|
"kind": "mcp",
|
|
10
10
|
"entry": "client/carlos.js",
|
|
11
11
|
"command": "门禁",
|
|
@@ -400,6 +400,82 @@
|
|
|
400
400
|
"sessionId"
|
|
401
401
|
]
|
|
402
402
|
}
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"name": "flow_run_verify",
|
|
406
|
+
"description": "执行卡片中指定的验证命令,返回执行结果(退出码、stdout、stderr)。用于在派发 executor 后验证其工作成果,或手动触发验证。记 PASS 裁定前必须先跑通本工具。",
|
|
407
|
+
"parameters": {
|
|
408
|
+
"type": "object",
|
|
409
|
+
"properties": {
|
|
410
|
+
"sessionId": {
|
|
411
|
+
"type": "string",
|
|
412
|
+
"description": "会话 ID,默认 unknown"
|
|
413
|
+
},
|
|
414
|
+
"cwd": {
|
|
415
|
+
"type": "string",
|
|
416
|
+
"description": "工作目录,默认 process.cwd()"
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
"name": "flow_check_scope",
|
|
423
|
+
"description": "检查指定文件列表是否在卡片 scope 范围内。用于在提交裁定前自查越界改动。空 scope 判定为全部越界(fail-closed)。",
|
|
424
|
+
"parameters": {
|
|
425
|
+
"type": "object",
|
|
426
|
+
"properties": {
|
|
427
|
+
"sessionId": {
|
|
428
|
+
"type": "string",
|
|
429
|
+
"description": "会话 ID,默认 unknown"
|
|
430
|
+
},
|
|
431
|
+
"paths": {
|
|
432
|
+
"type": "array",
|
|
433
|
+
"items": {
|
|
434
|
+
"type": "string"
|
|
435
|
+
},
|
|
436
|
+
"description": "要检查的文件路径列表"
|
|
437
|
+
},
|
|
438
|
+
"cwd": {
|
|
439
|
+
"type": "string",
|
|
440
|
+
"description": "仓库工作目录,默认 process.cwd()"
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
"required": [
|
|
444
|
+
"sessionId"
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
"name": "flow_trigger_check",
|
|
450
|
+
"description": "智能触发检查:判断当前这条用户消息是否应该启动 Carlos 工作流,并在达标时实际完成激活(写入用户原话 + 开占位卡 → 会话进入门禁态)。宿主在收到用户消息时调用本工具,就能获得与命令行客户端完全一致的自动触发行为。未达阈值时只如实返回评分与决策,不做任何动作;被限流时也如实返回真实评分。中文流程词(工作流/门禁/派发/审计…)已内置,中文需求同样能触发。",
|
|
451
|
+
"parameters": {
|
|
452
|
+
"type": "object",
|
|
453
|
+
"properties": {
|
|
454
|
+
"sessionId": {
|
|
455
|
+
"type": "string",
|
|
456
|
+
"description": "会话 ID,默认 unknown"
|
|
457
|
+
},
|
|
458
|
+
"message": {
|
|
459
|
+
"type": "string",
|
|
460
|
+
"description": "用户本轮消息原文(必须是真实原话,用于 quote 锚点)"
|
|
461
|
+
},
|
|
462
|
+
"complexity": {
|
|
463
|
+
"type": "number",
|
|
464
|
+
"description": "任务复杂度系数,默认 1.0"
|
|
465
|
+
},
|
|
466
|
+
"execute": {
|
|
467
|
+
"type": "boolean",
|
|
468
|
+
"description": "true = 达标时实际执行激活步骤(默认 true);false = 只评分不动作"
|
|
469
|
+
},
|
|
470
|
+
"cwd": {
|
|
471
|
+
"type": "string",
|
|
472
|
+
"description": "工作目录,默认 process.cwd()"
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
"required": [
|
|
476
|
+
"message"
|
|
477
|
+
]
|
|
478
|
+
}
|
|
403
479
|
}
|
|
404
480
|
]
|
|
405
481
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carlos-flow",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Carlos 工作流 — AI 编码 Agent 的机械门禁。留痕/派发/验证/裁定/审计/还原,约束写在代码里而非提示词里。单一包支持 Cindy/OpenCode/Cursor/Cline/VS Code/Claude Desktop。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
"init:cursor": "node client/carlos.js init --target cursor",
|
|
39
39
|
"init:cline": "node client/carlos.js init --target cline",
|
|
40
40
|
"init:vscode": "node client/carlos.js init --target vscode",
|
|
41
|
-
"init:claude": "node client/carlos.js init --target claude"
|
|
41
|
+
"init:claude": "node client/carlos.js init --target claude",
|
|
42
|
+
"check:lang": "node scripts/lang-audit.mjs",
|
|
43
|
+
"test:lang": "node test/lang-audit.test.mjs",
|
|
44
|
+
"check:full": "node scripts/full-audit.mjs"
|
|
42
45
|
},
|
|
43
46
|
"keywords": [
|
|
44
47
|
"carlos",
|
|
@@ -87,4 +90,4 @@
|
|
|
87
90
|
"CHANGELOG.md",
|
|
88
91
|
"LICENSE"
|
|
89
92
|
]
|
|
90
|
-
}
|
|
93
|
+
}
|
|
@@ -1,204 +1,215 @@
|
|
|
1
|
-
// carlos-flow-trigger — OpenCode 插件:把智能触发引擎真正接到消息事件上
|
|
2
|
-
//
|
|
3
|
-
// 为什么需要这个插件:
|
|
4
|
-
// Carlos 工作流的「智能触发引擎」(src/trigger.js)原本只接在**命令行客户端**
|
|
5
|
-
// (client/carlos.js)上 —— MCP server 根本不接触发引擎。
|
|
6
|
-
// 而在 OpenCode 里,Agent 走的是 MCP 工具路径(直接调 flow_* 工具),
|
|
7
|
-
// 于是 README 里那张「工作流会自己认出该上场的时候」的流程图在**实际使用路径上是不成立的**。
|
|
8
|
-
//
|
|
9
|
-
// 本插件做的事:
|
|
10
|
-
// 监听 OpenCode 的 `chat.message` 钩子(用户每发一条消息都会触发),
|
|
11
|
-
// 把消息原文交给 MCP 的 flow_trigger_check 工具 —— 由它做评分与决策,
|
|
12
|
-
// 达标时**实际完成激活**(写入用户原话 + 开占位卡 → 会话进入门禁态)。
|
|
13
|
-
//
|
|
14
|
-
// 评分与决策逻辑与命令行路径**共用同一份实现**(src/trigger.js),
|
|
15
|
-
// 所以两条路径的行为完全一致,不会出现「命令行能触发、MCP 不能」。
|
|
16
|
-
//
|
|
17
|
-
// 安装:
|
|
18
|
-
// 方式 A(本地文件):把本文件放到 OpenCode 的插件目录
|
|
19
|
-
// ~/.config/opencode/plugins/carlos-flow-trigger.js
|
|
20
|
-
//
|
|
21
|
-
// 项目级则放 .opencode/plugins/carlos-flow-trigger.js
|
|
22
|
-
// 方式 B(npm 包):在 opencode.json 里加
|
|
23
|
-
// { "plugin": ["carlos-flow
|
|
24
|
-
// 然后重启 OpenCode。
|
|
25
|
-
//
|
|
26
|
-
// 可选环境变量:
|
|
27
|
-
// CARLOS_FLOW_TRIGGER=off 关闭插件(临时停用自动触发)
|
|
28
|
-
// CARLOS_FLOW_TRIGGER_DEBUG=1 打印触发决策日志
|
|
29
|
-
//
|
|
30
|
-
// 说明:
|
|
31
|
-
// · 插件只做「判断 + 激活」,**不代替 Agent 决定改哪些文件**;
|
|
32
|
-
// 激活后仍需补齐 scope / acceptance / verify.cmd 才能派发(闸门不放松);
|
|
33
|
-
// · 任何异常都只记日志、绝不阻断用户消息(插件出错不应该让 OpenCode 挂掉)。
|
|
34
|
-
|
|
35
|
-
import { spawn } from "node:child_process";
|
|
36
|
-
import { existsSync } from "node:fs";
|
|
37
|
-
import { homedir } from "node:os";
|
|
38
|
-
import { join, resolve } from "node:path";
|
|
39
|
-
|
|
40
|
-
const DEBUG = process.env.CARLOS_FLOW_TRIGGER_DEBUG === "1";
|
|
41
|
-
const ENABLED = process.env.CARLOS_FLOW_TRIGGER !== "off";
|
|
42
|
-
|
|
43
|
-
// 找到 MCP server 的 src/index.js。
|
|
44
|
-
// 插件可能位于:
|
|
45
|
-
// 1) <pkg>/plugins/carlos-flow-trigger.js(npm 包内,方式 B)
|
|
46
|
-
// 2) ~/.config/opencode/plugins/carlos-flow-trigger.js(本地文件,方式 A)
|
|
47
|
-
// 3) <repo>/plugins/carlos-flow-trigger.js(源码 checkout)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
console.error(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
// carlos-flow-trigger — OpenCode 插件:把智能触发引擎真正接到消息事件上
|
|
2
|
+
//
|
|
3
|
+
// 为什么需要这个插件:
|
|
4
|
+
// Carlos 工作流的「智能触发引擎」(src/trigger.js)原本只接在**命令行客户端**
|
|
5
|
+
// (client/carlos.js)上 —— MCP server 根本不接触发引擎。
|
|
6
|
+
// 而在 OpenCode 里,Agent 走的是 MCP 工具路径(直接调 flow_* 工具),
|
|
7
|
+
// 于是 README 里那张「工作流会自己认出该上场的时候」的流程图在**实际使用路径上是不成立的**。
|
|
8
|
+
//
|
|
9
|
+
// 本插件做的事:
|
|
10
|
+
// 监听 OpenCode 的 `chat.message` 钩子(用户每发一条消息都会触发),
|
|
11
|
+
// 把消息原文交给 MCP 的 flow_trigger_check 工具 —— 由它做评分与决策,
|
|
12
|
+
// 达标时**实际完成激活**(写入用户原话 + 开占位卡 → 会话进入门禁态)。
|
|
13
|
+
//
|
|
14
|
+
// 评分与决策逻辑与命令行路径**共用同一份实现**(src/trigger.js),
|
|
15
|
+
// 所以两条路径的行为完全一致,不会出现「命令行能触发、MCP 不能」。
|
|
16
|
+
//
|
|
17
|
+
// 安装:
|
|
18
|
+
// 方式 A(本地文件):把本文件放到 OpenCode 的插件目录
|
|
19
|
+
// ~/.config/opencode/plugins/carlos-flow-trigger.js
|
|
20
|
+
// Windows 下则是 %APPDATA%\opencode\plugins\carlos-flow-trigger.js
|
|
21
|
+
// 项目级则放 .opencode/plugins/carlos-flow-trigger.js
|
|
22
|
+
// 方式 B(npm 包):在 opencode.json 里加
|
|
23
|
+
// { "plugin": ["carlos-flow/plugins/carlos-flow-trigger.js"] }
|
|
24
|
+
// 然后重启 OpenCode。
|
|
25
|
+
//
|
|
26
|
+
// 可选环境变量:
|
|
27
|
+
// CARLOS_FLOW_TRIGGER=off 关闭插件(临时停用自动触发)
|
|
28
|
+
// CARLOS_FLOW_TRIGGER_DEBUG=1 打印触发决策日志
|
|
29
|
+
//
|
|
30
|
+
// 说明:
|
|
31
|
+
// · 插件只做「判断 + 激活」,**不代替 Agent 决定改哪些文件**;
|
|
32
|
+
// 激活后仍需补齐 scope / acceptance / verify.cmd 才能派发(闸门不放松);
|
|
33
|
+
// · 任何异常都只记日志、绝不阻断用户消息(插件出错不应该让 OpenCode 挂掉)。
|
|
34
|
+
|
|
35
|
+
import { spawn } from "node:child_process";
|
|
36
|
+
import { existsSync } from "node:fs";
|
|
37
|
+
import { homedir } from "node:os";
|
|
38
|
+
import { join, resolve } from "node:path";
|
|
39
|
+
|
|
40
|
+
const DEBUG = process.env.CARLOS_FLOW_TRIGGER_DEBUG === "1";
|
|
41
|
+
const ENABLED = process.env.CARLOS_FLOW_TRIGGER !== "off";
|
|
42
|
+
|
|
43
|
+
// 找到 MCP server 的 src/index.js。
|
|
44
|
+
// 插件可能位于:
|
|
45
|
+
// 1) <pkg>/plugins/carlos-flow-trigger.js(npm 包内,方式 B)
|
|
46
|
+
// 2) ~/.config/opencode/plugins/carlos-flow-trigger.js(本地文件,方式 A)
|
|
47
|
+
// 3) <repo>/plugins/carlos-flow-trigger.js(源码 checkout)
|
|
48
|
+
//
|
|
49
|
+
// ⚠️ 包名是 **carlos-flow**(v2.6.0 起统一单包)。
|
|
50
|
+
// 旧版这里硬编码的是 carlos-flow-opencode —— 单包化之后那个目录根本不存在,
|
|
51
|
+
// 于是除「方式 B」(插件就在包内)外的所有安装方式都**找不到 MCP server**,
|
|
52
|
+
// 自动触发**静默失效**。
|
|
53
|
+
// 现在同时接受新包名与两个已弃用的旧包名(兼容老用户尚未迁移的 node_modules)。
|
|
54
|
+
const PKG_NAMES = ["carlos-flow", "carlos-flow-opencode", "carlos-flow-cindy"];
|
|
55
|
+
function findMcpServer() {
|
|
56
|
+
const here = new URL(".", import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, "$1");
|
|
57
|
+
const dir = resolve(here);
|
|
58
|
+
const candidates = [
|
|
59
|
+
join(dir, "..", "src", "index.js"), // <pkg>/plugins/ → <pkg>/src/
|
|
60
|
+
];
|
|
61
|
+
for (const name of PKG_NAMES) {
|
|
62
|
+
candidates.push(
|
|
63
|
+
join(dir, "..", "..", "node_modules", name, "src", "index.js"),
|
|
64
|
+
join(dir, "..", "..", "..", "node_modules", name, "src", "index.js"),
|
|
65
|
+
join(homedir(), ".config", "opencode", "node_modules", name, "src", "index.js"),
|
|
66
|
+
join(homedir(), "AppData", "Roaming", "opencode", "node_modules", name, "src", "index.js"),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
for (const p of candidates) {
|
|
70
|
+
try {
|
|
71
|
+
if (existsSync(p)) return p;
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 以 MCP 的 stdio 协议调一个工具(一次性拉起,用完即退)
|
|
78
|
+
async function callMcpTool(serverPath, toolName, args, timeoutMs = 15000) {
|
|
79
|
+
return new Promise((resolvePromise) => {
|
|
80
|
+
const child = spawn(process.execPath, [serverPath], {
|
|
81
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
82
|
+
windowsHide: true,
|
|
83
|
+
});
|
|
84
|
+
let buf = "";
|
|
85
|
+
let stderr = "";
|
|
86
|
+
const pending = new Map();
|
|
87
|
+
let id = 1;
|
|
88
|
+
|
|
89
|
+
const timer = setTimeout(() => {
|
|
90
|
+
try { child.kill(); } catch {}
|
|
91
|
+
resolvePromise({ ok: false, error: "timeout" });
|
|
92
|
+
}, timeoutMs);
|
|
93
|
+
|
|
94
|
+
child.stdout.on("data", (d) => {
|
|
95
|
+
buf += d.toString();
|
|
96
|
+
let i;
|
|
97
|
+
while ((i = buf.indexOf("\n")) >= 0) {
|
|
98
|
+
const line = buf.slice(0, i);
|
|
99
|
+
buf = buf.slice(i + 1);
|
|
100
|
+
if (!line.trim()) continue;
|
|
101
|
+
try {
|
|
102
|
+
const msg = JSON.parse(line);
|
|
103
|
+
if (msg.id && pending.has(msg.id)) {
|
|
104
|
+
pending.get(msg.id)(msg);
|
|
105
|
+
pending.delete(msg.id);
|
|
106
|
+
}
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
child.stderr.on("data", (d) => { stderr += d.toString(); });
|
|
111
|
+
|
|
112
|
+
const req = (method, params) => new Promise((r) => {
|
|
113
|
+
const rid = id++;
|
|
114
|
+
pending.set(rid, r);
|
|
115
|
+
child.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: rid, method, params }) + "\n");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
child.on("error", (e) => {
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
try { child.kill(); } catch {}
|
|
121
|
+
resolvePromise({ ok: false, error: String(e && e.message ? e.message : e) });
|
|
122
|
+
});
|
|
123
|
+
child.on("exit", () => {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
resolvePromise({ ok: false, error: stderr.slice(-300) || "server exited" });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
(async () => {
|
|
129
|
+
try {
|
|
130
|
+
await req("initialize", {
|
|
131
|
+
protocolVersion: "2024-11-05",
|
|
132
|
+
capabilities: {},
|
|
133
|
+
clientInfo: { name: "carlos-flow-trigger", version: "1.0.0" },
|
|
134
|
+
});
|
|
135
|
+
const res = await req("tools/call", { name: toolName, arguments: args });
|
|
136
|
+
const text = res?.result?.content?.[0]?.text || "";
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
try { child.kill(); } catch {}
|
|
139
|
+
if (res?.result?.isError) {
|
|
140
|
+
resolvePromise({ ok: false, error: String(text).slice(0, 300) });
|
|
141
|
+
} else {
|
|
142
|
+
try {
|
|
143
|
+
resolvePromise({ ok: true, data: JSON.parse(text) });
|
|
144
|
+
} catch {
|
|
145
|
+
resolvePromise({ ok: false, error: "bad json: " + String(text).slice(0, 200) });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (e) {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
try { child.kill(); } catch {}
|
|
151
|
+
resolvePromise({ ok: false, error: String(e && e.message ? e.message : e) });
|
|
152
|
+
}
|
|
153
|
+
})();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 从 parts 里取出用户消息文本(只看 type==="text" 的部分)
|
|
158
|
+
function extractText(parts) {
|
|
159
|
+
if (!Array.isArray(parts)) return "";
|
|
160
|
+
return parts
|
|
161
|
+
.filter((p) => p && p.type === "text" && typeof p.text === "string")
|
|
162
|
+
.map((p) => p.text)
|
|
163
|
+
.join("\n")
|
|
164
|
+
.trim();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const CarlosFlowTriggerPlugin = async ({ client, $, worktree, directory }) => {
|
|
168
|
+
const serverPath = findMcpServer();
|
|
169
|
+
if (!serverPath) {
|
|
170
|
+
console.error("[carlos-flow-trigger] 未找到 MCP server(src/index.js),自动触发未启用");
|
|
171
|
+
console.error("[carlos-flow-trigger] 请确认已全局安装:npm install -g carlos-flow");
|
|
172
|
+
}
|
|
173
|
+
if (DEBUG) {
|
|
174
|
+
console.error("[carlos-flow-trigger] server:", serverPath, "cwd:", worktree || directory);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
"chat.message": async (input, output) => {
|
|
179
|
+
if (!ENABLED) return;
|
|
180
|
+
if (!serverPath) return;
|
|
181
|
+
|
|
182
|
+
const message = extractText(output && output.parts);
|
|
183
|
+
if (!message) return;
|
|
184
|
+
|
|
185
|
+
const sessionId = input.sessionID || "default";
|
|
186
|
+
try {
|
|
187
|
+
const res = await callMcpTool(serverPath, "flow_trigger_check", {
|
|
188
|
+
sessionId,
|
|
189
|
+
message,
|
|
190
|
+
cwd: worktree || directory || process.cwd(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (!res.ok) {
|
|
194
|
+
if (DEBUG) console.error("[carlos-flow-trigger] 调用失败:", res.error);
|
|
195
|
+
return; // 插件出错绝不阻断用户消息
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const d = res.data || {};
|
|
199
|
+
if (DEBUG) {
|
|
200
|
+
console.error(
|
|
201
|
+
`[carlos-flow-trigger] decision=${d.decision} score=${d.score} activated=${d.activated}`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (d.activated) {
|
|
205
|
+
console.error(
|
|
206
|
+
`[carlos-flow-trigger] 已自动激活 Carlos 工作流(评分 ${d.score})—— ` +
|
|
207
|
+
`请补齐 ${(d.pending_fields || []).join(" / ")} 后再派发`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
if (DEBUG) console.error("[carlos-flow-trigger] 异常:", e && e.message ? e.message : e);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
};
|
|
@@ -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";
|
|
@@ -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/protocol.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
// Carlos Flow
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
export const PROTOCOL = {
|
|
5
|
-
ROUTE_TABLE: `| 档 | 场景 | 动作 |
|
|
6
|
-
|---|---|---|
|
|
7
|
-
| T0 | 讨论 / 解释 / 概念澄清 | 直接答,不派发、不填卡,0 个子 Agent,无门禁 |
|
|
8
|
-
| T1 | 只读调研(摸清代码现状) | 派 explore,1 个子 Agent,免门禁 |
|
|
9
|
-
| T2 | 修改代码 / 配置 / 文档 | 留痕 → 派 executor → 派 auditor,2 个子 Agent,机械门禁 + 独立复核 |
|
|
10
|
-
|
|
11
|
-
判定口径:要写文件 = T2;要读文件但不写 = T1;两者都不需要 = T0`,
|
|
12
|
-
|
|
13
|
-
FOUR_CONTRACT: `四段合同(每段一行,主 Agent 必须在任务卡里写全):
|
|
14
|
-
1. objective:一句话目标。
|
|
15
|
-
2. output format:executor 报告 ≤300 字,四段式 —— 结论 / 改动(file:line 逐条)/ 验证结果 / 遗留风险。
|
|
16
|
-
3. tool guidance:验证命令由主 Agent 指定,executor 不得自选测试项。
|
|
17
|
-
4. task boundaries:只准改清单里的文件,一个不多;要改别的 → 停下来在报告里说明,不要自己扩大范围。`,
|
|
18
|
-
|
|
19
|
-
REPORT_SPEC: `executor 报告 ≤300 字,四段式:结论 / 改动 / 验证 / 遗留风险。
|
|
20
|
-
auditor 报告 ≤200 字,五段式:裁定 / 失败类型 / scope 标注 / 证据 / 附注。`,
|
|
21
|
-
|
|
22
|
-
ERROR_LAYERS: `| 层 | 触发 | 处置 |
|
|
23
|
-
|---|---|---|
|
|
24
|
-
| 基础设施故障 | 网络抖动、模型不可用、配额耗尽 | 静默降级或改用 Explore / 自读只读验证,不把原始错误喂回 |
|
|
25
|
-
| Agent 故障 | 工具名错、参数错 | 把错误喂回并附恢复指引 |
|
|
26
|
-
| 接管 | 同一子 Agent 连续 2 次失败 | 接管 = 只读验证,不写文件 |`,
|
|
27
|
-
|
|
28
|
-
STATE_FIELDS: `{"card":null,"card_ts":0,"tier":"read_only","task_id":null,"dispatch_count":0,"write_files":0,"last_user_ts":0,"bypass":false,"bypass_ts":0,"verdict":null,"completed_ok":false,"stale":false}`,
|
|
29
|
-
|
|
30
|
-
AUDIT_EVENTS: `["run","finding","decision","resolution"]`,
|
|
31
|
-
|
|
32
|
-
BYPASS_WORDS: `["直接干","跳过门禁","免检","别管流程","不用走流程"]`,
|
|
33
|
-
|
|
34
|
-
CARD_TEMPLATE: `FLOW_CARD:{"goal":"一句话目标","quote":"用户原话摘录","scope":["只准改的文件"],"acceptance":["可判定的验收标准"],"unknowns":[],"assumptions":[],"files":[{"path":"a/b.py","line":1}],"verify":{"cmd":"pytest -q tests/x.py"},"confirmed":false}`,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
const SENSITIVE_NAMES = new Set([
|
|
39
|
-
".env", ".env.local", ".env.development", ".env.production", ".env.test",
|
|
40
|
-
"settings.json", "settings.local.json",
|
|
41
|
-
"package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml",
|
|
42
|
-
"poetry.lock", "requirements.txt",
|
|
43
|
-
"dockerfile", "docker-compose.yml", "docker-compose.yaml", "makefile",
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
const SENSITIVE_SEGMENTS = new Set([
|
|
47
|
-
"migrations", "deploy", "deployment", "k8s", "kube",
|
|
48
|
-
".github", ".gitlab", "secrets", "certs", "terraform",
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
const SENSITIVE_EXTENSIONS = new Set([
|
|
52
|
-
".pem", ".key", ".p12", ".pfx", ".env",
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
export function isSensitive(rel) {
|
|
56
|
-
if (typeof rel !== "string" || rel.length === 0) return false;
|
|
57
|
-
const normalized = rel.replace(/\\/g, "/").toLowerCase();
|
|
58
|
-
const segments = normalized.split("/").filter((s) => s.length > 0);
|
|
59
|
-
const base = segments.length ? segments[segments.length - 1] : normalized;
|
|
60
|
-
|
|
61
|
-
if (SENSITIVE_NAMES.has(base)) return true;
|
|
62
|
-
// 只检查目录段(不含最后一段文件名):与 card.js 保持一致
|
|
63
|
-
for (const seg of segments.slice(0, -1)) {
|
|
64
|
-
if (SENSITIVE_SEGMENTS.has(seg)) return true;
|
|
65
|
-
}
|
|
66
|
-
for (const ext of SENSITIVE_EXTENSIONS) {
|
|
67
|
-
if (base.endsWith(ext)) return true;
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function riskTier(scope) {
|
|
73
|
-
if (!Array.isArray(scope) || scope.length === 0) return "read_only";
|
|
74
|
-
if (scope.some((p) => isSensitive(p))) return "sensitive";
|
|
75
|
-
if (scope.length === 1) return "single_file";
|
|
76
|
-
return "cross_module";
|
|
1
|
+
// Carlos Flow 协议 — 路由档位 / 四段合同 / 报告规格 / 错误分层 / 状态字段的唯一真源。
|
|
2
|
+
// 被协调器(coordinator)与各角色 Agent 共同引用。
|
|
3
|
+
|
|
4
|
+
export const PROTOCOL = {
|
|
5
|
+
ROUTE_TABLE: `| 档 | 场景 | 动作 |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| T0 | 讨论 / 解释 / 概念澄清 | 直接答,不派发、不填卡,0 个子 Agent,无门禁 |
|
|
8
|
+
| T1 | 只读调研(摸清代码现状) | 派 explore,1 个子 Agent,免门禁 |
|
|
9
|
+
| T2 | 修改代码 / 配置 / 文档 | 留痕 → 派 executor → 派 auditor,2 个子 Agent,机械门禁 + 独立复核 |
|
|
10
|
+
|
|
11
|
+
判定口径:要写文件 = T2;要读文件但不写 = T1;两者都不需要 = T0`,
|
|
12
|
+
|
|
13
|
+
FOUR_CONTRACT: `四段合同(每段一行,主 Agent 必须在任务卡里写全):
|
|
14
|
+
1. objective:一句话目标。
|
|
15
|
+
2. output format:executor 报告 ≤300 字,四段式 —— 结论 / 改动(file:line 逐条)/ 验证结果 / 遗留风险。
|
|
16
|
+
3. tool guidance:验证命令由主 Agent 指定,executor 不得自选测试项。
|
|
17
|
+
4. task boundaries:只准改清单里的文件,一个不多;要改别的 → 停下来在报告里说明,不要自己扩大范围。`,
|
|
18
|
+
|
|
19
|
+
REPORT_SPEC: `executor 报告 ≤300 字,四段式:结论 / 改动 / 验证 / 遗留风险。
|
|
20
|
+
auditor 报告 ≤200 字,五段式:裁定 / 失败类型 / scope 标注 / 证据 / 附注。`,
|
|
21
|
+
|
|
22
|
+
ERROR_LAYERS: `| 层 | 触发 | 处置 |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| 基础设施故障 | 网络抖动、模型不可用、配额耗尽 | 静默降级或改用 Explore / 自读只读验证,不把原始错误喂回 |
|
|
25
|
+
| Agent 故障 | 工具名错、参数错 | 把错误喂回并附恢复指引 |
|
|
26
|
+
| 接管 | 同一子 Agent 连续 2 次失败 | 接管 = 只读验证,不写文件 |`,
|
|
27
|
+
|
|
28
|
+
STATE_FIELDS: `{"card":null,"card_ts":0,"tier":"read_only","task_id":null,"dispatch_count":0,"write_files":0,"last_user_ts":0,"bypass":false,"bypass_ts":0,"verdict":null,"completed_ok":false,"stale":false}`,
|
|
29
|
+
|
|
30
|
+
AUDIT_EVENTS: `["run","finding","decision","resolution"]`,
|
|
31
|
+
|
|
32
|
+
BYPASS_WORDS: `["直接干","跳过门禁","免检","别管流程","不用走流程"]`,
|
|
33
|
+
|
|
34
|
+
CARD_TEMPLATE: `FLOW_CARD:{"goal":"一句话目标","quote":"用户原话摘录","scope":["只准改的文件"],"acceptance":["可判定的验收标准"],"unknowns":[],"assumptions":[],"files":[{"path":"a/b.py","line":1}],"verify":{"cmd":"pytest -q tests/x.py"},"confirmed":false}`,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 敏感文件名单(三种匹配方式:文件名命中 / 路径段命中 / 扩展名命中)
|
|
38
|
+
const SENSITIVE_NAMES = new Set([
|
|
39
|
+
".env", ".env.local", ".env.development", ".env.production", ".env.test",
|
|
40
|
+
"settings.json", "settings.local.json",
|
|
41
|
+
"package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml",
|
|
42
|
+
"poetry.lock", "requirements.txt",
|
|
43
|
+
"dockerfile", "docker-compose.yml", "docker-compose.yaml", "makefile",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
const SENSITIVE_SEGMENTS = new Set([
|
|
47
|
+
"migrations", "deploy", "deployment", "k8s", "kube",
|
|
48
|
+
".github", ".gitlab", "secrets", "certs", "terraform",
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const SENSITIVE_EXTENSIONS = new Set([
|
|
52
|
+
".pem", ".key", ".p12", ".pfx", ".env",
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
export function isSensitive(rel) {
|
|
56
|
+
if (typeof rel !== "string" || rel.length === 0) return false;
|
|
57
|
+
const normalized = rel.replace(/\\/g, "/").toLowerCase();
|
|
58
|
+
const segments = normalized.split("/").filter((s) => s.length > 0);
|
|
59
|
+
const base = segments.length ? segments[segments.length - 1] : normalized;
|
|
60
|
+
|
|
61
|
+
if (SENSITIVE_NAMES.has(base)) return true;
|
|
62
|
+
// 只检查目录段(不含最后一段文件名):与 card.js 保持一致
|
|
63
|
+
for (const seg of segments.slice(0, -1)) {
|
|
64
|
+
if (SENSITIVE_SEGMENTS.has(seg)) return true;
|
|
65
|
+
}
|
|
66
|
+
for (const ext of SENSITIVE_EXTENSIONS) {
|
|
67
|
+
if (base.endsWith(ext)) return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function riskTier(scope) {
|
|
73
|
+
if (!Array.isArray(scope) || scope.length === 0) return "read_only";
|
|
74
|
+
if (scope.some((p) => isSensitive(p))) return "sensitive";
|
|
75
|
+
if (scope.length === 1) return "single_file";
|
|
76
|
+
return "cross_module";
|
|
77
77
|
}
|