@shgroup/dsh-serenity-hooks 1.137.11 → 1.137.13
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/README.md +7 -3
- package/dsh.plugin.json +3 -4
- package/lib/contract-B0uRA4S2.js +2307 -0
- package/lib/index.js +335 -226
- package/lib/invariant.js +5 -6
- package/lib/kernel/invariant.d.ts +2 -2
- package/lib/{observation-DiD_yJjS.js → observation-L-KQr5RL.js} +1 -2
- package/lib/{rebuild-Di1ITL-N.js → rebuild-CNFvXPby.js} +1 -1
- package/lib/seams/session-md-full-read.d.ts +47 -0
- package/lib/{service-mYmQXFFT.js → service-BZwjW8JL.js} +1 -1
- package/lib/{session-CA4rNuiV.js → session-BMaTNjK1.js} +4 -1
- package/lib/trajectory/reconstruct.d.ts +17 -23
- package/package.json +2 -2
- package/lib/service-DF23HvHY.js +0 -1003
- package/lib/status-BwfDsakn.js +0 -1309
- package/lib/tools/reconstruct.d.ts +0 -31
package/lib/service-DF23HvHY.js
DELETED
|
@@ -1,1003 +0,0 @@
|
|
|
1
|
-
import { d as readCccName$1, r as classifyPath } from "./ccc-DSMqTrRU.js";
|
|
2
|
-
import { u as ACC_VERSION } from "./rules-BYeykzys.js";
|
|
3
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { execFile, execFileSync, spawnSync } from "node:child_process";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { platform } from "node:process";
|
|
8
|
-
//#region src/im/endpoint.ts
|
|
9
|
-
/**
|
|
10
|
-
* im/endpoint.ts — 主动发送入口地址的**零依赖叶模块**(v1.30.9,S142)
|
|
11
|
-
*
|
|
12
|
-
* 为什么单独一个模块(R↓):地址的读者是 `msm-ops.buildMsmEnv`(把地址注入 MSM 子进程 env),
|
|
13
|
-
* 写者才是 `weixin-send-api`(监听器启停)。若 msm-ops 直接 import weixin-send-api,
|
|
14
|
-
* 静态依赖链会拖进整条微信桥栈(weixin-bridge → trajectory-session → `@deepseek-ai/dsh-llm`)——
|
|
15
|
-
* 后果实测:`acc-extras` / `ops` / `trajectory-constraint-admin` 三个测试套件因解析不到宿主包而**整文件加载失败**
|
|
16
|
-
* (它们只用到 MSM 注册表逻辑)。叶模块把「读」与「写」解耦:读者零依赖,写者自己承担重量。
|
|
17
|
-
*
|
|
18
|
-
* 同款先例:`host/effect.ts`(拆卸登记)、`trajectory/carrier.ts`(等待结算)。
|
|
19
|
-
*/
|
|
20
|
-
let endpoint = null;
|
|
21
|
-
/** 设置当前入口地址(weixin-send-api 启停时调用;null = 未启动) */
|
|
22
|
-
function setWeixinSendEndpoint(value) {
|
|
23
|
-
endpoint = value;
|
|
24
|
-
}
|
|
25
|
-
/** 当前入口地址(形如 http://127.0.0.1:3082;未启动 → null) */
|
|
26
|
-
function weixinSendEndpoint() {
|
|
27
|
-
return endpoint;
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/tools/config-docs.ts
|
|
31
|
-
/**
|
|
32
|
-
* **指针文案**(v1.75.0,owner 裁 Q3「指针」)——被降级的旧入口共用这一份。
|
|
33
|
-
*
|
|
34
|
-
* ## 为什么要有"指针"这个形态(而不是直接删掉旧入口)
|
|
35
|
-
*
|
|
36
|
-
* 旧入口的名字(`msm catalog` / `msm ccc-config` / `config guide`)**已经写在 CCC 侧的
|
|
37
|
-
* 文档与提示词里**,硬删会让它们全部变成"未知动作",而且**没有任何机械信号**告诉我们
|
|
38
|
-
* 哪份文档已经说谎了(本仓 D151 同族)。
|
|
39
|
-
*
|
|
40
|
-
* ⇒ 保留名字、只换返回内容:调用方能**自己顺着指针找到正文**,而正文仍然只有一份。
|
|
41
|
-
*
|
|
42
|
-
* 🔴 **必须只有一处实现**:`container-admin.ts`(config 域)与 `msm/service.ts`(msm 域)
|
|
43
|
-
* 都要用它。两处各写一份文案 ⇒ 措辞漂移(本仓反复踩过的形态)。
|
|
44
|
-
*
|
|
45
|
-
* @param chapter 正文所在的章 id
|
|
46
|
-
* @param what 这个入口原来叫什么(进标题,让调用方一眼确认自己找对了)
|
|
47
|
-
*/
|
|
48
|
-
function docsPointer(chapter, what) {
|
|
49
|
-
return [
|
|
50
|
-
`═══ ${what} — 正文已统一 ═══`,
|
|
51
|
-
"",
|
|
52
|
-
`正文在:container_admin config docs ${chapter}`,
|
|
53
|
-
"",
|
|
54
|
-
"为什么改(v1.75.0,owner 裁「指针」):这个内容此前有**两个**正文入口,",
|
|
55
|
-
"而它们返回同一份常量 ⇒ 两个真相源。现在「一个内容一个正文入口」,本入口只指路。",
|
|
56
|
-
"",
|
|
57
|
-
"索引(不知道还有哪些章):container_admin config docs"
|
|
58
|
-
].join("\n");
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/tools/msm/service.ts
|
|
62
|
-
/**
|
|
63
|
-
* tools/msm/service.ts — msm 纯操作层(acc_msm → msm 执行 + container_admin 管理面,v1.30;零 DSH 依赖)
|
|
64
|
-
*
|
|
65
|
-
* MSM(Mech & Semi-Mech)框架:exec 执行 / register|deregister|check 管理。
|
|
66
|
-
* 复用 CCC 的 mech-registry.json(v1 或数组格式)。cwd 钉在 CCC 根。
|
|
67
|
-
*/
|
|
68
|
-
const execFileAsync = promisify(execFile);
|
|
69
|
-
const MSM_TIMEOUT_MS = 6e5;
|
|
70
|
-
const BUN_EXE_CANDIDATES = [
|
|
71
|
-
() => join(process.env["USERPROFILE"] ?? process.env["HOME"] ?? "", ".bun", "bin", "bun.exe"),
|
|
72
|
-
() => join(process.env["APPDATA"] ?? "", "npm", "node_modules", "bun", "bin", "bun.exe"),
|
|
73
|
-
() => join(process.env["LOCALAPPDATA"] ?? "", "npm", "node_modules", "bun", "bin", "bun.exe")
|
|
74
|
-
];
|
|
75
|
-
let bunExeCache;
|
|
76
|
-
function bunExecutablePath() {
|
|
77
|
-
if (bunExeCache !== void 0) return bunExeCache;
|
|
78
|
-
if (platform !== "win32") {
|
|
79
|
-
bunExeCache = "bun";
|
|
80
|
-
return bunExeCache;
|
|
81
|
-
}
|
|
82
|
-
for (const cand of BUN_EXE_CANDIDATES) try {
|
|
83
|
-
if (existsSync(cand())) {
|
|
84
|
-
bunExeCache = cand();
|
|
85
|
-
return bunExeCache;
|
|
86
|
-
}
|
|
87
|
-
} catch {}
|
|
88
|
-
bunExeCache = null;
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
/** CCC 名:从 .serenity 解析(review P2-2 统一收口到 kernel/ccc.ts readCccName——跳 # 注释/空行首非空行;此处保留导出名兼容内部调用) */
|
|
92
|
-
function readCccName(root) {
|
|
93
|
-
return readCccName$1(root);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* path-arg 逃逸校验:根内 + symlink 防御(对齐 osp validatePathArgsFromTokens)。
|
|
97
|
-
* symlink 指向根外 → 拒绝(realpath 解析后与根前缀比对)。
|
|
98
|
-
*/
|
|
99
|
-
function assertPathInsideRoot(root, value, flagName) {
|
|
100
|
-
const abs = resolve(root, value);
|
|
101
|
-
if (classifyPath(abs, root) === "outside") throw new Error(`Path escape blocked: --${flagName}=${value} escapes the CCC root`);
|
|
102
|
-
if (existsSync(abs)) try {
|
|
103
|
-
const real = realpathSync(abs);
|
|
104
|
-
if (classifyPath(real, root) === "outside") throw new Error(`Path escape blocked: --${flagName}=${value} resolves via symlink outside the root (${real})`);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
if (e instanceof Error && e.message.includes("symlink")) throw e;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 业务子进程 env:注入 SERENITY_ROOT / SERENITY_CCC / SERENITY_VERSION(对齐 osp)
|
|
111
|
-
* + SERENITY_WEIXIN_API(v1.30.9:微信主动发送入口地址——MSM 脚本零硬编码端口;
|
|
112
|
-
* 未启动则不注入,脚本回退默认值)。
|
|
113
|
-
*/
|
|
114
|
-
function buildMsmEnv(root) {
|
|
115
|
-
const env = {
|
|
116
|
-
...process.env,
|
|
117
|
-
SERENITY_ROOT: root,
|
|
118
|
-
SERENITY_CCC: readCccName(root) ?? "",
|
|
119
|
-
SERENITY_VERSION: ACC_VERSION
|
|
120
|
-
};
|
|
121
|
-
const weixinApi = weixinSendEndpoint();
|
|
122
|
-
if (weixinApi) env.SERENITY_WEIXIN_API = weixinApi;
|
|
123
|
-
return env;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Windows 兼容(审计观察点 A):`.cmd` 不能直接被 CreateProcess 解析——
|
|
127
|
-
* `execFile('npx')` / `spawnSync('npx')` 在 Windows 必 ENOENT(需 shell 或显式 .cmd)。
|
|
128
|
-
* bun 无扩展名(bun.exe 可被 libuv 按 PATHEXT 解析),保持 'bun'。
|
|
129
|
-
*/
|
|
130
|
-
const NPX_BIN = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
131
|
-
/**
|
|
132
|
-
* ACC 能力目录(需求④ S142 用户拍板:"acc 配置各自做 guide 越来越多,整合成目录式使用指南")。
|
|
133
|
-
* 目录在前、详情各归各——**单一真相源**:本目录只索引"去哪个工具/子命令看详情",不复制详情
|
|
134
|
-
* (避免 container_admin/weixin-doctor 等 guide 全文重复 → 多真相源 → 失同步)。
|
|
135
|
-
* 后续新增功能只需在此加一行(低熵可演进)。
|
|
136
|
-
*
|
|
137
|
-
* 🔴 **2026-10-19 v1.75.0 起导出**:它是 `container_admin config docs catalog` 那一章的正文。
|
|
138
|
-
* `msm catalog` 动作**降为指针**(只指路,不再返回本常量)—— 否则同一份正文会有两个入口,
|
|
139
|
-
* 而"两个入口返回同一份内容"正是本目录自己反对的形态。
|
|
140
|
-
*/
|
|
141
|
-
const ACC_CATALOG = `═══ ACC Usage Catalog ═══
|
|
142
|
-
Directory of ACC capabilities — each area lists where to go for details (guides live with their feature; this catalog only points).
|
|
143
|
-
|
|
144
|
-
① 轨迹本体 → cognitive_trajectory(list/show/create/use + rebuild 超限重建 + send-now 即时投递 + send-later 未来一次性唤醒
|
|
145
|
-
+ cro-guide CRO 编写指南)
|
|
146
|
-
原 logbook 已并入(v1.33 用户裁决:废除 logbook 词);close/archive 删(归档走 container_fs mv),
|
|
147
|
-
health/qa/summary 分别并入 use / list,hook-develop-guide 并进 container_admin msm guide
|
|
148
|
-
② 认知质量框架 → praxis(eap/neat/cce/ontology 四合一——可实践理论注入,section 渐进披露,无参即目录)
|
|
149
|
-
ontology(v1.52 D121:本体工程**引擎**——init/check/explain/verify/review/compliance;
|
|
150
|
-
与 praxis ontology 的分工 = 那个是**方法文本**、这个是**能跑的那个**)
|
|
151
|
-
③ 工具与执行 → container_fs(容器文件系统 15 子命令)/ container_git(git)/ dashboard(health 含注册表检查/time/diag)
|
|
152
|
-
acc_msm 已并入 msm(执行+发现)与 container_admin(管理)——msm("<name>", ["<args>"]);inspect=true 查用法
|
|
153
|
-
(v1.106.0 已删 exclusiveTools 机制:原专属工具 acc-diag **已并入 dashboard diag**)
|
|
154
|
-
④ 轨迹约束与对外面 → container_admin config(轨迹约束四动作 guide/validate/apply/list——**原 role 域已并入 config**,旧名作过渡别名仍可用;说明类配置走**两层菜单** config docs 目录 / config docs <章节> 详情)
|
|
155
|
-
(2026-11-15 owner 令:**ACP 面已整条下架** —— 代码 / 端口 / 配置校验 / 会话前缀全部清除。
|
|
156
|
-
本插件**不提供**任何 ACP 接入面;外部程序化接入口径由宿主侧自行决定,与本插件无关。)
|
|
157
|
-
⑤ 自主与接入 → cognitive_trajectory send-now(跨轨迹的**即时**递送,**不排队**:live 目标在跑就当场注入当前轮、空闲则立即起轮;非 live 冷载入——等效于直接 wake;**有同步回执**)
|
|
158
|
-
cognitive_trajectory send-later(跨轨迹的"未来时刻 + 一条 message";fire-and-forget,无回执无回收)
|
|
159
|
-
weixin 微信桥(配置/扫码/路由/消息 hook——CCC 侧 weixin-doctor MSM:msm("weixin-doctor", ["guide"]))
|
|
160
|
-
⑥ CCC 配置总览 → container_admin config docs config(按章详情——8 段全表)
|
|
161
|
-
或 container_admin msm ccc-config(同一份正文的旧入口,保留)
|
|
162
|
-
⑦ 注册表与安全 → mech-registry.json 由 container_admin msm register/deregister 管理(写保护——不可直接编辑)
|
|
163
|
-
dashboard health 输出 registry 完整性检查;损坏恢复指引见 health registry.issues
|
|
164
|
-
CCC 级开关:safeMode.blacklist(写路径黑名单)
|
|
165
|
-
/ safeMode.hiddenTools(**已退役**,v1.123.0:安全模式只藏 bash;「CCC 内一律关」那批由 ACC 的 ALWAYS_DENY_TOOLS 恒隐,不再随开关变化)
|
|
166
|
-
CCC 级 skill 供给:cognitiveTrajectory.skills(v1.44.0——**本 CCC 每条轨迹都带**,含 轨迹约束会话;与轨迹自己的 frontmatter 声明取并集)
|
|
167
|
-
|
|
168
|
-
每区:一句话定位 + 详细入口(工具名 / guide 子命令)。详情永远以对应工具的 guide/ccc-config 为单一真相源。
|
|
169
|
-
`;
|
|
170
|
-
const MSM_GUIDE = `MSM Development Manual (Mech & Semi-Mech framework)
|
|
171
|
-
|
|
172
|
-
## What it is
|
|
173
|
-
MSM = the executable-unit layer. Mech is pure TS with zero LLM reasoning; Semi-Mech is a TS framework + LLM decision points.
|
|
174
|
-
MSM is ACC's deterministic executable-unit layer — all shell/exec operations go through MSM and cannot be bypassed.
|
|
175
|
-
|
|
176
|
-
## Registering a new MSM (container_admin msm register)
|
|
177
|
-
1. Write the script under <skill>/scripts/ (runnable via tsx; must include a main() CLI guard with an import.meta.url check)
|
|
178
|
-
2. container_admin msm register --domain msm --action register <name> --skill <s> --path <script path relative to root> --category <mech|semi-mech> --description <desc>
|
|
179
|
-
3. Auto-writes mech-registry.json (preserving the original format) + git commit (commits only the registry file)
|
|
180
|
-
4. Validation: path must be inside root, script must exist, name must be globally unique
|
|
181
|
-
|
|
182
|
-
## flag schema (v1)
|
|
183
|
-
flags is a new-style object array for parameter validation and path-escape guarding:
|
|
184
|
-
[{"name":"output","type":"string","description":"output path"},
|
|
185
|
-
{"name":"target","type":"path","description":"operation target (type:path enables in-root validation + symlink defense)"},
|
|
186
|
-
{"name":"force","type":"boolean","description":"force mode","default":false}]
|
|
187
|
-
- {name, type} format — new style, type:"path" enables the path-escape guard
|
|
188
|
-
- {flag, description} format — old style, CLI flag description string
|
|
189
|
-
- On registration, flags are passed via container_admin msm register --flags '<json>'
|
|
190
|
-
|
|
191
|
-
## Script conventions
|
|
192
|
-
- Top-of-file documentation: purpose / usage / exit codes
|
|
193
|
-
- Exit codes: 0 success / 1 user / 2 system / 3 operator (per ACC protocol classification)
|
|
194
|
-
- main() CLI guard (DC-M2): the script must start with
|
|
195
|
-
if (import.meta.url === \`file://\${process.argv[1]}\`) { main() }
|
|
196
|
-
or an equivalent isMain / require.main === check — so vitest imports never trigger top-level code
|
|
197
|
-
- A paired .test.ts or .spec.ts (DC-M1, vitest)
|
|
198
|
-
- Business subprocess environment: SERENITY_ROOT / SERENITY_CCC / SERENITY_VERSION injected
|
|
199
|
-
|
|
200
|
-
## Interaction & confirmation conventions (no blocking confirmation)
|
|
201
|
-
- MSMs run in **user-less subprocesses** (spawn/execFile, 600s timeout) — **never** use
|
|
202
|
-
readline / prompt / process.stdin etc. to block waiting for user input (it would hang until killed by the timeout)
|
|
203
|
-
- When a second confirmation is needed: **directly return the confirmation request** (list the operation to perform and its impact + how to retry with the confirmation flag),
|
|
204
|
-
returning a non-zero exit code (or an explicit hint)
|
|
205
|
-
- After the agent confirms, **re-invoke the MSM with the confirmation flag** (e.g. --confirm / --yes / --force) to retry
|
|
206
|
-
- Standard mode (two-phase):
|
|
207
|
-
1. First call: destructive/confirmation-requiring operation detected and no confirmation flag present → output the confirmation request (list operation/impact/rollback),
|
|
208
|
-
exit non-zero (e.g. 1 user), **perform no changes**
|
|
209
|
-
2. After the agent evaluates, re-invoke: with the confirmation flag → execute and output the result
|
|
210
|
-
- Applies to: delete/overwrite/push/batch operations and other irreversible or wide-impact operations
|
|
211
|
-
- Anti-example (forbidden): readline waiting for user input, process.stdin.on('data') blocking waits
|
|
212
|
-
(MSMs have no stdin interaction channel — they hang until the 600s timeout)
|
|
213
|
-
|
|
214
|
-
## Quality checks (container_admin msm check, DC-M1~M4)
|
|
215
|
-
DC-M1 has .test.ts/.spec.ts; DC-M2 has a main() guard (function main( / isMain / require.main === / import.meta.url);
|
|
216
|
-
DC-M3 bidirectional: scripts unregistered + registry references missing scripts; DC-M4 path-type flags marked type:"path"
|
|
217
|
-
|
|
218
|
-
## Self-description (protocol flags, first argument only)
|
|
219
|
-
msm("<name>", ["--list"]) — list all MSMs
|
|
220
|
-
msm("<name>", ["--schema", "<n>"]) — view a specific MSM's parameter schema
|
|
221
|
-
msm("<name>", ["--format=json"]) — JSON output mode (remaining args passed through losslessly)
|
|
222
|
-
`;
|
|
223
|
-
/**
|
|
224
|
-
* CCC 配置参考(对齐 osp ccc-config action)。
|
|
225
|
-
*
|
|
226
|
-
* 🔴 **2026-10-19 起导出**:`container_admin config docs config` 的两层菜单把它作为
|
|
227
|
-
* 「config」章正文返回。**不另写一份**——同一段说明有第二份副本就会漂(本轨反复踩过)。
|
|
228
|
-
*/
|
|
229
|
-
const CCC_CONFIG_REFERENCE = `═══ CCC Configuration Reference ═══
|
|
230
|
-
|
|
231
|
-
CCC-level features are configured in .opencode/serenity.json.
|
|
232
|
-
Below are all available configuration sections.
|
|
233
|
-
|
|
234
|
-
── 1. sessionKeeper.threshold / sessionKeeper.sessionMdMaxKB ──
|
|
235
|
-
cognitive-trajectory-assistant(COGNITIVE-TRAJECTORY-ASSISTANT · CHECKPOINT)提醒机制的积分阈值(非 headless 主 agent)。
|
|
236
|
-
按工具调用加权 + 耗时计分;达到阈值注入提醒,要求模型回复 ACK 码。
|
|
237
|
-
|
|
238
|
-
Config:
|
|
239
|
-
{ "sessionKeeper": { "threshold": 150, "sessionMdMaxKB": 100 } }
|
|
240
|
-
|
|
241
|
-
计分:write/edit = 3,task = 10,read/grep/glob/msm 等 = 1,时间 = 1/分钟
|
|
242
|
-
默认:150
|
|
243
|
-
|
|
244
|
-
▸ sessionMdMaxKB(v1.31.1 新增;v1.31.2 100→200;🔴 v1.84.0 200→100):
|
|
245
|
-
**活跃 SESSION.md 体积上限(KB,缺省 100;0 = 关闭)**。
|
|
246
|
-
超过 → 注入 [COGNITIVE-TRAJECTORY-ASSISTANT · LOGBOOK COMPACTION] 提醒:暂停当前工作 →
|
|
247
|
-
加载 eap(praxis eap)→ **按 EAP 重构整个 SESSION.md**(v1.84.0 起;旧版是四条重写原则)。
|
|
248
|
-
判据 = EAP 三个变量:E↑ 变量/边界/有向关系全显式 | R↓ 带理由与被否项,长证据链外移到
|
|
249
|
-
references/*.md(SESSION.md 留链接)| S↑ 结构每次同样重建,不是时间流水账。
|
|
250
|
-
两条硬约束随提醒给出:保留固定段落的**顺序与标题**(与系统提示词对齐)+ 保留顶部 frontmatter。
|
|
251
|
-
超限后每次工具调用都提醒;连续 3 次未重写 → 升级强制语气;
|
|
252
|
-
文件回到限内 → 自动停止(自愈)。轨迹提醒**不机械阻断工作**(与 rebuild 提醒同族)。
|
|
253
|
-
|
|
254
|
-
── 2. localstore.gitTrack ──
|
|
255
|
-
localstore.json 的 git 策略:allow 可提交 / deny 禁提交(默认 deny)。
|
|
256
|
-
deny 时写入自动确保 .gitignore 含该文件(物理保证),container_git commit 会检查拒绝。
|
|
257
|
-
|
|
258
|
-
Config:
|
|
259
|
-
{ "localstore": { "gitTrack": "allow" } }
|
|
260
|
-
|
|
261
|
-
── 3. hooks.autoRestoreSession ──
|
|
262
|
-
会话自动恢复(默认 true;受 events 门控——仅根会话 + 已有对话历史才恢复)。
|
|
263
|
-
|
|
264
|
-
Config:
|
|
265
|
-
{ "hooks": { "autoRestoreSession": false } }
|
|
266
|
-
|
|
267
|
-
── 4. safeMode(黑名单 + bash 开关)──
|
|
268
|
-
safe-mode 由 WebUI 开关控制(写 .serenity-safe-on 标记);黑名单路径受 guards seam 拦截。
|
|
269
|
-
|
|
270
|
-
▸ blacklist:写路径黑名单(同下 Config)。
|
|
271
|
-
▸ 工具屏蔽的**三张表**(owner 2026-11-06 令:「subagent 一套 tool 常开,安全模式开关只影响
|
|
272
|
-
bash 开关,剩余的都是只要在 CCC 目录就关」):
|
|
273
|
-
· subagent 一族(subagent / subagent_fork / send_message / list_agents / interrupt_agent /
|
|
274
|
-
list_subagent_models)——**不入任何表,常开**
|
|
275
|
-
· bash —— 只随 safe-mode 开关(ACC 基础表)
|
|
276
|
-
· 其余(宿主作业 / 编排 / 计划出口 / 插件管理 / 工作目录 / 阻塞提问 / 宿主定时器)
|
|
277
|
-
—— **在 CCC 内一律关**,与本开关无关
|
|
278
|
-
▸ 🔴 hiddenTools **已退役**(v1.123.0,本键不再被任何代码读取)——见上:那批工具不是
|
|
279
|
-
"安全模式下额外藏",而是**任何时候都该关**;跟着文件开关忽隐忽现反而是缺陷。
|
|
280
|
-
存量 CCC 里若仍写着它 ⇒ 静默忽略(schemastery 非 strict)。诊断读
|
|
281
|
-
\`AGENT_SESSIONS/.restrict-diag.json\` 的 \`denyByKey\`(每会话实际生效的 deny 清单)。
|
|
282
|
-
|
|
283
|
-
Config:
|
|
284
|
-
{ "safeMode": { "blacklist": [".secrets/"] } }
|
|
285
|
-
|
|
286
|
-
── 5. 轨迹约束.roles(F4 认知子集角色)──
|
|
287
|
-
轨迹约束角色 = 全知全能 cognitive trajectory 的任意子集(CCC 定义)。每角色独立模型 + 双白名单
|
|
288
|
-
(MSM 白名单 msms[] 与非 MSM 工具白名单 tools[],白名单外全隐藏;skill 加载恒可用)。
|
|
289
|
-
cognitive trajectory 纪律子集(session/keeper/rebuild 参与项)默认全关 = 完全独立。
|
|
290
|
-
systemPrompt 内联 或 systemPromptFile(.md 引用,推荐)——角色会话的完整人格/边界提示词。
|
|
291
|
-
validate 校验 / apply 生效 / list 查看:container_admin config <guide|validate|apply|list>(原 role 域已并入 config,旧名作过渡别名仍可用)。
|
|
292
|
-
|
|
293
|
-
Config:
|
|
294
|
-
{ "轨迹约束": { "roles": {
|
|
295
|
-
"qa": {
|
|
296
|
-
"model": "provider/model",
|
|
297
|
-
"msms": ["web-search", "vlm-describe"],
|
|
298
|
-
"tools": ["read", "grep", "glob"],
|
|
299
|
-
"systemPromptFile": ".opencode/skiff/qa.md"
|
|
300
|
-
} } } }
|
|
301
|
-
|
|
302
|
-
── 6. cognitive_trajectory(轨迹 + 唤醒注册表,D58)──
|
|
303
|
-
CCC 的一条 cognitive trajectory = 持久身体(SESSION.md)+ 时间轴(AGENT_SESSIONS/ 目录 + 唤醒注册表)。
|
|
304
|
-
一个 CCC 内可多条并行;条目全部由人类/agent 显式登记。
|
|
305
|
-
⚠️ ACC 不再提供**周期自唤醒**(原 autopilot,2026-09-15 整段退场:机制/时钟/container_admin autopilot
|
|
306
|
-
域/面板区块一并删除)。自主巡航改由 CCC 自己驱动(home-serenity 侧 msm autopilot-round 每轮自排下一轮,
|
|
307
|
-
真相源 = S151 SESSION.md §1/§1b/§1c)。**本轮的 cognitiveTrajectory.autopilot 配置段保留**(见下表)——
|
|
308
|
-
它现由 **CCC 侧脚本**读取,ACC 不再消费该段。
|
|
309
|
-
唤醒注册表(cognitive_trajectory send-later):唤醒 = 未来时刻 + 一条 message,可唤醒自己或别的 cognitive trajectory;
|
|
310
|
-
落点 AGENT_SESSIONS/wake-registry.json,中心调度器到点投递(fire-and-forget;无回执、无回收)。
|
|
311
|
-
运行态诊断(ACC 负责人专用):acc-diag(① live 运行态 / ①b 唤醒时钟 / ③ 唤醒注册表)。
|
|
312
|
-
|
|
313
|
-
▸ cognitiveTrajectory.skills(v1.44.0,**CCC 级 skill 供给**;owner 令 2026-09-20「要求实现我的诉求……
|
|
314
|
-
注入是动态注入就行;create 先不触发吧;**轨迹约束也支持**」):
|
|
315
|
-
**本 CCC 的每条轨迹都带这些 skill**——声明的 skill 全文在该轨迹**被绑定期间**注入系统提示词
|
|
316
|
-
(**动态注入**:每请求重新求值、不缓存 ⇒ 改配置或改 frontmatter **即时生效**,无需重新 use、无需重启)。
|
|
317
|
-
两条声明来源**并集**(不是二选一):本键 **cognitiveTrajectory.skills**(容器给的底座,**在前**)
|
|
318
|
-
+ 轨迹自己 SESSION.md 顶部 frontmatter 的 skills:(这条轨迹额外的,**追加**;同名去重)。
|
|
319
|
-
✅ **含 轨迹约束角色会话**(旁路的是 ACC 身份与纪律;skill 是"工作资料",照给)。
|
|
320
|
-
守卫:名字先过安全校验才用于拼路径(防穿越)|**合并后**统一 32 KB 上限截断|找不到响亮写 [缺失]。
|
|
321
|
-
⚠️ 与 create **无关**(create 刻意不夺绑定,U6)⇒ 注入的门是"**存在绑定**"(cognitive_trajectory use)。
|
|
322
|
-
失败语义:未配置 / 字段缺失 / 配置损坏 ⇒ **空数组**(= 无 CCC 级供给;轨迹级声明照旧生效)。
|
|
323
|
-
归属(D23):**机制在 ACC**(读取 + 合并 + 注入 + 守卫),**声明在 CCC**(本键)。
|
|
324
|
-
|
|
325
|
-
Config:
|
|
326
|
-
{ "cognitiveTrajectory": {
|
|
327
|
-
"skills": ["acc-session", "cce"], // v1.44.0:本 CCC 的每条轨迹都带(含 轨迹约束会话)
|
|
328
|
-
"autopilot": { // 原 autopilotTrajectory 段,字段不变(旧键仍回退读)
|
|
329
|
-
"enabled": true,
|
|
330
|
-
"intervalHours": 2,
|
|
331
|
-
"session": "S151",
|
|
332
|
-
"biasProvider": "autopilot-bias.ts",
|
|
333
|
-
"topPrompt": "本轨迹核心目标/纪律/质量要求(CCC 自填,防漂移)",
|
|
334
|
-
"avoidWakeHours": { "start": 8, "end": 18 }
|
|
335
|
-
} } }
|
|
336
|
-
|
|
337
|
-
── 7. weixin(微信桥 F4c-3,含消息记录 hook)──
|
|
338
|
-
CCC 级微信个人号接入(iLink 协议):dsh 一进程多 CCC,每 CCC 独立对接微信桥。
|
|
339
|
-
账号/路由/开关在此文件;**bot_token 凭据在 CCC localstore credential scope**
|
|
340
|
-
(扫码绑定后自动写入,永不进 git 明文面)。
|
|
341
|
-
路由 user → role:exact 优先,* 通配兜底;role 必须 ∈ 该 CCC 轨迹约束.roles。
|
|
342
|
-
面板(WebUI 设置 → 微信桥)可扫码绑定/移除账号/编辑路由;msm("weixin-doctor", ["status"|"diag"|"verify"|"guide"]) 排查 + 大而全指南。凭据主动查看:localstore get WEIXIN_<ACCOUNT>_TOKEN。
|
|
343
|
-
▸ 主动发送(v1.31.0:**ACC 工具 im-bridge**):调
|
|
344
|
-
im-bridge({channel:"weixin", action:"send", user:"<别名|id>", text:"<文本>"}) 给用户发消息——
|
|
345
|
-
**工具只能操作本会话 CCC**(无 ccc 参数,防误发他容器)→ weixin-bridge.sendProactiveText →
|
|
346
|
-
成功后触发 outgoing hook(source="proactive")。文件用 action:"send-file" + file:"<CCC 内路径>"
|
|
347
|
-
(逃逸/缺失/超 20MB 拒绝)+ 可选 caption。**可见性**:本 CCC 配置了 IM 通道
|
|
348
|
-
(weixin.enabled=true)才出现在模型工具清单里;未配置 → 由 guards 逐 agent
|
|
349
|
-
tools.restrict({deny:['im-bridge']}) 移除(不是"看得到但被拒")。轨迹约束角色另需在
|
|
350
|
-
roles.<role>.tools 白名单列出 im-bridge。
|
|
351
|
-
历史(v1.30.9~v1.30.x):CCC 侧 MSM weixin-send(走 loopback HTTP 入口 3082)——
|
|
352
|
-
v1.31.0 已退役(脚本删除 + 注册表注销);3082 入口保留给**非 agent 调用者**。
|
|
353
|
-
|
|
354
|
-
▸ 🔴🔴 **出站只有一条路:agent 自己调 im-bridge**(2026-10-24 起,owner 令)。
|
|
355
|
-
桥**永不**替你回发最终文本 —— 你说什么、说几条、什么时候说、要不要不说,全由你决定。
|
|
356
|
-
⛔ 不要指望"我把话写进回答里就会自动发出去":**不会**。必须真的调工具。
|
|
357
|
-
⇒ 每轮用户消息末尾都会附一行**已填好参数**的 im-bridge 调用模板(机制标记
|
|
358
|
-
[serenity:weixin-manual-output]),照它改 text 即可。
|
|
359
|
-
⇒ 本轮结束仍未成功调用(send / send-file)→ 你会被打回(≤2 次,提示 = 标记 + 事实);
|
|
360
|
-
达上限后**用户将收不到任何消息**(没有任何兜底转发)。
|
|
361
|
-
⇒ 成功调用才算送达;失败调用不算(不会被当成本轮已发送)。
|
|
362
|
-
⚠️ **前提**:本轨迹必须在 \`.opencode/serenity.json\` 的 \`im.routes\` 里被点名,否则 \`im-bridge\`
|
|
363
|
-
对你不**可见**——那种情况下闸门不会打回你(改成一条响亮告警,指明"该轨迹无发送权"),
|
|
364
|
-
因为打回一个你根本满足不了的要求只会空转。
|
|
365
|
-
|
|
366
|
-
▸ **已退役(不要再配,配了也不生效)**:
|
|
367
|
-
· \`weixin.autoReplyWithLastMessage\`(v1.30.10~2026-10-24)= 桥替 agent 回发最终文本。
|
|
368
|
-
**被否理由**(owner 原话):「autoReply 并不合适,主动性的 imBridge 仍然是更好的」——
|
|
369
|
-
它让 agent 失去"说几条/何时说/要不要不说"的决定权,而那正是主动发送的价值。
|
|
370
|
-
· \`weixin.fallbackOnNoSend\`(v1.30.17~2026-10-24)= 手动模式下 agent 没发成功时桥兜底转发。
|
|
371
|
-
它只在上面那个开关 =false 时才有意义 ⇒ 一起退役。
|
|
372
|
-
⚠️ 旧配置里残留这两个键**静默忽略**(不会报错,也不会生效)。
|
|
373
|
-
|
|
374
|
-
Config:
|
|
375
|
-
{ "weixin": {
|
|
376
|
-
"enabled": true,
|
|
377
|
-
"hook": "scripts/weixin-message-hook.ts",
|
|
378
|
-
"accounts": [{ "accountId": "wechat-1", "name": "家庭助手", "enabled": true }],
|
|
379
|
-
"routes": [{ "user": "*", "role": "my-role" }]
|
|
380
|
-
} }
|
|
381
|
-
|
|
382
|
-
▸ weixin.hook(消息记录 hook,v1.27.13):
|
|
383
|
-
微信桥每收/发一条消息触发一次 CCC 自写脚本,由 CCC 自行持久化保存(存哪/存成什么
|
|
384
|
-
/是否入库全归 CCC——ACC 不绑定存储)。未配置 hook → 零变化(不触发)。
|
|
385
|
-
|
|
386
|
-
触发(双向):
|
|
387
|
-
incoming = 用户 → bot:路由命中后、媒体落盘后触发(文本含语音转写;媒体带落盘 relPath)
|
|
388
|
-
outgoing = bot → 用户:发送成功后触发(reply = 用户实际收到的纯文本,已剥离 think)
|
|
389
|
-
· source="proactive" = agent 经 im-bridge 主动发起(**2026-10-24 起这是唯一值**)
|
|
390
|
-
· 历史值 reply / reply-fallback(桥自动回发 / 桥兜底转发)已随两个开关一起退役;
|
|
391
|
-
存量日志里仍能看到它们,那是历史事实,不是当前行为
|
|
392
|
-
· file(仅 send-file 补记):{ "name": "报告.pdf", "size": 12345, "caption": "可选" }
|
|
393
|
-
|
|
394
|
-
脚本约定(事件 JSON 单行经 stdin 传入;bun 优先 node 兜底):
|
|
395
|
-
#!/usr/bin/env bun 或 node script.js —— 读 process.stdin 整段 JSON.parse
|
|
396
|
-
const ev = JSON.parse(await new Response(process.stdin).text())
|
|
397
|
-
ev.event === 'incoming' | 'outgoing'
|
|
398
|
-
|
|
399
|
-
事件 schema(**不含任何会话凭据**——context_token/bot_token/token/aes_key 均不出现):
|
|
400
|
-
{ "event": "incoming", "ts": 1788359941488, "cccRoot": "/path/ccc",
|
|
401
|
-
"accountId": "wechat-1", "userId": "u1@im.wechat",
|
|
402
|
-
"sessionId": "skiff-weixin-xxx", "role": "my-role",
|
|
403
|
-
"message": { "text": "你好", "media": [{ "kind": "image", "relPath": "_tmp/weixin-inbound/<hash>/img_x.jpg" }] } }
|
|
404
|
-
{ "event": "outgoing", "ts": ..., "cccRoot": ..., "accountId": ...,
|
|
405
|
-
"userId": ..., "sessionId": ..., "role": ...,
|
|
406
|
-
"reply": "已记录(纯文本)", "source": "proactive" }
|
|
407
|
-
|
|
408
|
-
示例脚本(追加到按日文件——持久化归 CCC 自选:文件/DB/远端均可):
|
|
409
|
-
const fs = require('node:fs'); const p = '/path/ccc/AGENT_SESSIONS/_weixin-log.jsonl';
|
|
410
|
-
fs.appendFileSync(p, JSON.stringify(ev) + '\\n');
|
|
411
|
-
|
|
412
|
-
执行语义(旁路容忍):异步 fire-and-forget + 15s 超时 kill + 失败仅日志——
|
|
413
|
-
微信桥消息处理/回复不受 hook 影响;脚本须在 CCC 根内(路径逃逸拒绝)。
|
|
414
|
-
媒体 relPath 指向 _tmp/weixin-inbound/(临时目录)——需持久保存媒体文件请自行 copy。
|
|
415
|
-
|
|
416
|
-
── 8. (已删除)exclusiveTools(专属工具声明,v1.33 → v1.106.0 删除)──
|
|
417
|
-
🔴 **本键已不存在**(owner 2026-11-01 裁「机制整体删」)。
|
|
418
|
-
原语义:ACC 注册但默认对所有 CCC 隐藏的工具,只有在 CCC 配置里点名才可见(fail-closed)。
|
|
419
|
-
**删除理由**:那张表永远只有一个成员 acc-diag,而它已并入**常驻**的 dashboard 的 diag 动作。
|
|
420
|
-
表空之后那个 filter 恒回空数组 ⇒ 机制**静默空转、且任何测试都证伪不了它**
|
|
421
|
-
(一个验不出死活的机制比没有它更坏:它提供"这里还有一层保护"的错觉)。
|
|
422
|
-
|
|
423
|
-
▸ 要运行态诊断 ⇒ 直接用 dashboard 的 diag 动作(**无需任何声明,所有轨迹可见**)。
|
|
424
|
-
▸ 旧配置里残留 exclusiveTools ⇒ **静默忽略**(schemastery 非 strict),不影响加载。
|
|
425
|
-
▸ ⚠️ 连带后果(owner 已知并确认):dashboard 是常驻工具 ⇒ diag 段对**所有轨迹**可见,
|
|
426
|
-
而它的 live 会话清单是**全部 CCC** 的(跨容器)。这是「方案 C」的既定代价,不是缺陷。
|
|
427
|
-
|
|
428
|
-
── 9. userQuotes.enabled(用户语录台账,v1.113.0)──
|
|
429
|
-
**把用户直接说的话按天、按轨迹存下来**,供之后反向分析用户。owner 原话:
|
|
430
|
-
「我需要一个可开启关闭的功能,就是记录用户直接对谁说过什么,对谁是指对具体的某个轨迹……
|
|
431
|
-
这个功能如果开启,则默认写到一个指定目录内,按天进行记录。这个功能是用于具体的宁静号CCC反向来分析用户的」。
|
|
432
|
-
|
|
433
|
-
Config:
|
|
434
|
-
{ "userQuotes": { "enabled": true } }
|
|
435
|
-
|
|
436
|
-
默认:**关**。🔴 判据是 \`enabled === true\`,⛔ 不是"键存在"——
|
|
437
|
-
写成 "true" / 1 / 只写 userQuotes: {} 一律当**关**。理由:这是把用户原话原文**长期留存**,
|
|
438
|
-
含糊的配置必须落到"不写"那一侧(fail-closed;与订阅表的 fail-open 方向相反,
|
|
439
|
-
因为这里的危险方向是**多写**)。
|
|
440
|
-
|
|
441
|
-
落点:\`AGENT_SESSIONS/_user-quotes/<YYYY-MM-DD>.jsonl\`(按天,一行一条):
|
|
442
|
-
{"ts":"…+08:00","trajectory":"<轨迹目录名 或 null>","sessionId":"…","messageId":"…","text":"(原话,一字不改)","chars":88}
|
|
443
|
-
|
|
444
|
-
▸ **采集点** = \`agent/pre-step\` 的 \`payload.messages\`(本 step 从 inbox 取出、即将进本步的消息)。
|
|
445
|
-
▸ **判别面 = \`source.kind === 'user'\`**(结构性,⛔ 不靠措辞黑名单)。
|
|
446
|
-
▸ **"对谁" = 按轨迹**(Q1),取绑定真相源(\`current.dsh_session_bind\`);未绑定 ⇒ \`null\` 但**照常记**。
|
|
447
|
-
▸ **全文**(Q3):一字不改,不做摘要;\`chars\` 是**码点数**不是 UTF-16 单元数。
|
|
448
|
-
▸ 两个**冒充 \`kind:'user'\`** 的生产者(载体开场白/rebuild 锚点)按各自标记排除。
|
|
449
|
-
▸ IM 入站(**微信与飞书都算**)**不会混进来**:两者共用一个投递出口 \`deliverToTrajectory\`,
|
|
450
|
-
kind 是 \`plugin:dsh-serenity-hooks\`(已取证,非推演)。⇒ 台账 = **界面直话**。
|
|
451
|
-
⚠️ 两条边界:① 这是当前实现的属性、**不是协议保证**(IM 若改回 kind:'user' 就会开始收录,
|
|
452
|
-
那时要重新裁决);② \`_im-logs/<channel>/\` 仍是 IM 原话的唯一真相源 —— 不收录 ≠ 丢了。
|
|
453
|
-
▸ 采集失败只 warn、**不阻断 step**(台账是旁路观测,不是被观测对象的组成部分)。
|
|
454
|
-
判据全文(含取证与变异检验设计)⇒ \`src/trajectory/user-quotes.ts\` 头注释。
|
|
455
|
-
`;
|
|
456
|
-
function parseRegistry(raw) {
|
|
457
|
-
const data = JSON.parse(raw.replace(/^\uFEFF/, ""));
|
|
458
|
-
if (Array.isArray(data)) return data;
|
|
459
|
-
const entries = data.entries;
|
|
460
|
-
if (!Array.isArray(entries)) throw new Error("invalid registry: missing entries[]");
|
|
461
|
-
return entries;
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* 注册表单级化(需求⑤a S142 用户拍板:注册表只有一级——对齐 osp cccName 单聚合档):
|
|
465
|
-
* 所有 entry 集中写入 `.opencode/skills/<cccName>/references/mech-registry.json`
|
|
466
|
-
* (cccName = .serenity 首行,即顶层入口 skill 目录),skill 只作 entry 字段。
|
|
467
|
-
* 不再扫描/写入各 skill 目录的分散注册表(历史形态 v1.14~v1.27,register --skill
|
|
468
|
-
* 曾写入各自 skill 目录 —— 多真相源,废弃)。
|
|
469
|
-
*/
|
|
470
|
-
function findRegistries(root) {
|
|
471
|
-
const cccName = readCccName(root);
|
|
472
|
-
if (!cccName) return [];
|
|
473
|
-
const aggregate = join(root, ".opencode", "skills", cccName, "references", "mech-registry.json");
|
|
474
|
-
return existsSync(aggregate) ? [aggregate] : [];
|
|
475
|
-
}
|
|
476
|
-
function loadMsmEntries(root) {
|
|
477
|
-
const byName = /* @__PURE__ */ new Map();
|
|
478
|
-
for (const regPath of findRegistries(root)) for (const entry of parseRegistry(readFileSync(regPath, "utf-8"))) if (!byName.has(entry.name)) byName.set(entry.name, entry);
|
|
479
|
-
return [...byName.values()];
|
|
480
|
-
}
|
|
481
|
-
function findEntry(root, name) {
|
|
482
|
-
return loadMsmEntries(root).find((e) => e.name === name) ?? null;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* 扫描各 skill `scripts/` 下的**未注册候选**(DC-M3 正向基准,对齐 osp)。
|
|
486
|
-
*
|
|
487
|
-
* 🔴 **入口判据**(S151 轮 112 跨轨迹信号 → S142 实测精化,2026-09-17;取证见 S142 §0q):
|
|
488
|
-
* · **入口 ⟺ 有 shebang(`^#!`) ∨ 声明了 `function main(`** —— **`process.argv` 单独不算**。
|
|
489
|
-
* 反例(实测):`home-desk/scripts/lib/desk-dispatch.ts` 含 **5** 处 `process.argv`,
|
|
490
|
-
* 但无 shebang / 无 `main()`,且被 `desk-window.ts`、`desk-vision.ts` **import** ⇒ **它是库**。
|
|
491
|
-
* · **库 ⟺ 无 shebang ∧ 无 `main()` ∧ 被其它脚本 import** ⇒ **不是 MSM 候选,不上报**。
|
|
492
|
-
* ⚠️ **"有 `.test.ts`" 不是入口证据** —— 库**同样**有测试
|
|
493
|
-
* (`home-serenity/scripts/dev-kit/dev-kit.test.ts` 开头自述"**共享库单测**")。
|
|
494
|
-
* 📌 实现只测**前两条**(shebang / `main()`):第三条"被 import"是**描述性**的,不作判据 ——
|
|
495
|
-
* 因为**无 CLI 入口的文件本来就不可能被 `msm()` 调用**,上报它只会得到一条无法处置的欠账。
|
|
496
|
-
* 🔗 **与 DC-M2 自洽**:DC-M2 本就要求**已注册**脚本必须有 main() 守卫 ⇒ 把"无入口"的文件
|
|
497
|
-
* 排除出候选,与注册表的契约**同向**(两条判据不会互相打架)。
|
|
498
|
-
*
|
|
499
|
-
* 🔴 **本函数只扫 `scripts/` 一层(非递归),这是当前刻意的语义**(嵌套子域对容器不可见;
|
|
500
|
-
* 见 CCC `docs/t024-msm-skill-inventory.md` §3b)。**若将来改为递归,上面的判据就是护栏**:
|
|
501
|
-
* 嵌套候选实测 **8 个**(`dev-kit/` 5 + `home-desk/scripts/lib/` 3)**全部是库**——
|
|
502
|
-
* 不按判据过滤,一次递归就会制造 8 条假欠账,并可能诱使后续轮次把库注册成**假 MSM**。
|
|
503
|
-
* ⇒ **改递归前先读本条注释。**
|
|
504
|
-
*/
|
|
505
|
-
function scanSkillScripts(root) {
|
|
506
|
-
const out = [];
|
|
507
|
-
const skillsDir = join(root, ".opencode", "skills");
|
|
508
|
-
if (!existsSync(skillsDir)) return out;
|
|
509
|
-
for (const skill of readdirSync(skillsDir)) {
|
|
510
|
-
const scriptsDir = join(skillsDir, skill, "scripts");
|
|
511
|
-
if (!existsSync(scriptsDir)) continue;
|
|
512
|
-
for (const f of readdirSync(scriptsDir)) {
|
|
513
|
-
const abs = join(scriptsDir, f);
|
|
514
|
-
let isFile = false;
|
|
515
|
-
try {
|
|
516
|
-
isFile = statSync(abs).isFile();
|
|
517
|
-
} catch {
|
|
518
|
-
continue;
|
|
519
|
-
}
|
|
520
|
-
if (!isFile) continue;
|
|
521
|
-
if (!/\.(ts|js|mjs)$/.test(f)) continue;
|
|
522
|
-
if (/\.(test|spec)\./.test(f)) continue;
|
|
523
|
-
if (!hasCliEntry(abs)) continue;
|
|
524
|
-
out.push(join(".opencode", "skills", skill, "scripts", f));
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return out.sort();
|
|
528
|
-
}
|
|
529
|
-
/** 入口判据的机械实现(判据、反例与递归化护栏见 `scanSkillScripts` 注释) */
|
|
530
|
-
function hasCliEntry(absPath) {
|
|
531
|
-
let text;
|
|
532
|
-
try {
|
|
533
|
-
text = readFileSync(absPath, "utf-8");
|
|
534
|
-
} catch {
|
|
535
|
-
return true;
|
|
536
|
-
}
|
|
537
|
-
if (/^#!/.test(text)) return true;
|
|
538
|
-
return /\b(?:async\s+)?function\s+main\s*\(/.test(text);
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* **把 issue 列表压成「按检查码分组的一行摘要」**(D237:成功/失败类调用的返回精简)。
|
|
542
|
-
*
|
|
543
|
-
* ## 为什么需要它(owner 2026-10-24 令)
|
|
544
|
-
*
|
|
545
|
-
* > 「tool 的返回内容会影响 Agent 注意力……对于返回成功失败类的调用,如果成功要大幅精简;
|
|
546
|
-
* > 对于其它的调用,简练其结构,在确保信息有效的情况下降低大小」
|
|
547
|
-
*
|
|
548
|
-
* 实测症状(本仓真读数):`container_admin msm check` 返回 **36 条 issue,每条一个三字段对象**,
|
|
549
|
-
* 而其中 **M1 有 20 条、detail 逐字相同**(`no .test.ts / .spec.ts`)、**M3 有 16 条**(同样同 detail)。
|
|
550
|
-
* ⇒ 同一句话重复 20 遍**不携带额外信息**,只吃掉注意力。
|
|
551
|
-
*
|
|
552
|
-
* ## 判据(照 D237 分档)
|
|
553
|
-
*
|
|
554
|
-
* - **有 issue(失败面)⇒ 不省略任何一条**:失败条目是唯一能改变下一步的东西(D186「出声必须指名哪一半」)。
|
|
555
|
-
* 但可以**折叠结构**:同 `(check, detail)` 的条目合并成「一组 + 名字列表」,逐条信息一个字不丢。
|
|
556
|
-
* - **零 issue(成功面)⇒ 只留一行结论 + 计数**:通过的条目对下一步零信息量。
|
|
557
|
-
*
|
|
558
|
-
* @param report 原始报告(逐条 issue)
|
|
559
|
-
* @returns 压缩后的**面向 agent 的**结构(键名短、重复消除;entries 全保留只做分组)
|
|
560
|
-
*/
|
|
561
|
-
function compactRegistryQuality(report) {
|
|
562
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
563
|
-
for (const it of report.issues) {
|
|
564
|
-
const key = `${it.check}\u0000${it.detail}`;
|
|
565
|
-
const hit = byKey.get(key);
|
|
566
|
-
if (hit) hit.names.push(it.name);
|
|
567
|
-
else byKey.set(key, {
|
|
568
|
-
check: it.check,
|
|
569
|
-
detail: it.detail,
|
|
570
|
-
names: [it.name]
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
const groups = [...byKey.values()].sort((a, b) => a.check === b.check ? b.names.length - a.names.length : a.check < b.check ? -1 : 1).map((g) => ({
|
|
574
|
-
check: g.check,
|
|
575
|
-
detail: g.detail,
|
|
576
|
-
count: g.names.length,
|
|
577
|
-
names: g.names
|
|
578
|
-
}));
|
|
579
|
-
return {
|
|
580
|
-
checked: report.checked,
|
|
581
|
-
issueCount: report.issues.length,
|
|
582
|
-
groups
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* **注册表「质量契约」判据(DC-M1~M4)** —— 具名出口(C5 观察面归一,2026-09-15)。
|
|
587
|
-
*
|
|
588
|
-
* 此前这段判据**只存在于 `runMsm` 的 `case 'check'` 分支体内**(没有名字、无法从别处取用),
|
|
589
|
-
* 于是 `dashboard health` 只能另写一份 **不同判据** 的结构检查(`checkRegistryHealth`)。
|
|
590
|
-
* 抽成具名函数后,两条判据**各自有名字、各自可被取用、且仍然完全独立**——合并它们是错的:
|
|
591
|
-
* 本判据的主语是**条目契约**(有没有测试 / main() 守卫 / 双向注册 / path 型 flag),
|
|
592
|
-
* 结构判据的主语是**文件能否安全解析**。同一份注册表在两条判据下可以给出相反结论。
|
|
593
|
-
*
|
|
594
|
-
* 行为与抽取前**逐字一致**(`runMsm` 的 `check` 分支现只做 `return checkRegistryQuality(root)`)。
|
|
595
|
-
*/
|
|
596
|
-
function checkRegistryQuality(root) {
|
|
597
|
-
const entries = loadMsmEntries(root);
|
|
598
|
-
const issues = [];
|
|
599
|
-
const norm = (p) => p.split("\\").join("/").toLowerCase();
|
|
600
|
-
const registeredPaths = new Set(entries.map((e) => norm(e.path)));
|
|
601
|
-
for (const scriptPath of scanSkillScripts(root)) if (!registeredPaths.has(norm(scriptPath))) issues.push({
|
|
602
|
-
name: scriptPath,
|
|
603
|
-
check: "M3",
|
|
604
|
-
detail: "script not registered in mech-registry"
|
|
605
|
-
});
|
|
606
|
-
for (const e of entries) {
|
|
607
|
-
const script = join(root, e.path);
|
|
608
|
-
const scriptExists = existsSync(script);
|
|
609
|
-
if (!scriptExists) issues.push({
|
|
610
|
-
name: e.name,
|
|
611
|
-
check: "M3",
|
|
612
|
-
detail: `script missing (${e.path})`
|
|
613
|
-
});
|
|
614
|
-
const testFileTs = script.replace(/\.ts$/, ".test.ts");
|
|
615
|
-
const testFileSpec = script.replace(/\.ts$/, ".spec.ts");
|
|
616
|
-
if (!existsSync(testFileTs) && !existsSync(testFileSpec)) issues.push({
|
|
617
|
-
name: e.name,
|
|
618
|
-
check: "M1",
|
|
619
|
-
detail: "no .test.ts / .spec.ts"
|
|
620
|
-
});
|
|
621
|
-
if (scriptExists) {
|
|
622
|
-
const src = readFileSync(script, "utf-8");
|
|
623
|
-
if (!(/function main\(/.test(src) || /\bisMain\b/.test(src) || /require\.main\s*===/.test(src) || /import\.meta\.url/.test(src))) issues.push({
|
|
624
|
-
name: e.name,
|
|
625
|
-
check: "M2",
|
|
626
|
-
detail: "no main() guard"
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
const isPathLikeFlagName = (name) => {
|
|
630
|
-
if (name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().split(/[-_.]+/).filter(Boolean).some((s) => PATH_LIKE_SEGMENTS.has(s))) return true;
|
|
631
|
-
if (EXEMPT_FROM_PATH_SUFFIX.has(name.toLowerCase())) return false;
|
|
632
|
-
return PATH_LIKE_SUFFIXES.some((suf) => name.toLowerCase().endsWith(suf));
|
|
633
|
-
};
|
|
634
|
-
for (const f of e.flags ?? []) if ("name" in f && isPathLikeFlagName(String(f.name)) && f.type !== "path") issues.push({
|
|
635
|
-
name: e.name,
|
|
636
|
-
check: "M4",
|
|
637
|
-
detail: `flag --${f.name} should be type:"path"`
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
return {
|
|
641
|
-
checked: entries.length,
|
|
642
|
-
issues
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* 构成"路径型"的**整段**词。
|
|
647
|
-
* ⛔ 不要往里加 `profile` / `file` 之外的模糊词 —— 这份集合的每一次扩写都必须能说出
|
|
648
|
-
* "哪个 flag 因为它被正确识别了",否则它就只是在制造假阳。
|
|
649
|
-
*/
|
|
650
|
-
const PATH_LIKE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
651
|
-
"path",
|
|
652
|
-
"file",
|
|
653
|
-
"dir",
|
|
654
|
-
"folder",
|
|
655
|
-
"directory"
|
|
656
|
-
]);
|
|
657
|
-
/**
|
|
658
|
-
* 连写形式(`outfile` / `indir` / `outpath`)的判据 = **词尾**。
|
|
659
|
-
* ⛔ 不加 `profile`:它以 `file` 结尾,但那个 flag 是**名字**不是路径。
|
|
660
|
-
* ⇒ 这一条正是本判据此前的假阳来源;把它排除在此,而不是把 profile 硬标成 path。
|
|
661
|
-
*/
|
|
662
|
-
const PATH_LIKE_SUFFIXES = [
|
|
663
|
-
"file",
|
|
664
|
-
"path",
|
|
665
|
-
"dir"
|
|
666
|
-
];
|
|
667
|
-
/**
|
|
668
|
-
* 名字以路径词结尾、但**语义上不是路径**的 flag(点名例外)。
|
|
669
|
-
* 每加一项都要能说出"为什么它不是路径",否则就是拿例外掩盖假阳。
|
|
670
|
-
*/
|
|
671
|
-
const EXEMPT_FROM_PATH_SUFFIX = /* @__PURE__ */ new Set(["profile"]);
|
|
672
|
-
function registryPathFor(root, _skill) {
|
|
673
|
-
const cccName = readCccName(root) ?? "unknown";
|
|
674
|
-
return join(root, ".opencode", "skills", cccName, "references", "mech-registry.json");
|
|
675
|
-
}
|
|
676
|
-
function writeRegistry(path, entries, isV1Wrapped = true) {
|
|
677
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
678
|
-
const payload = isV1Wrapped ? JSON.stringify({
|
|
679
|
-
version: 1,
|
|
680
|
-
description: "MSM registry (managed by acc-msm / dsh-serenity-hooks)",
|
|
681
|
-
entries
|
|
682
|
-
}, null, 2) + "\n" : JSON.stringify(entries, null, 2) + "\n";
|
|
683
|
-
writeFileSync(path, payload, "utf-8");
|
|
684
|
-
}
|
|
685
|
-
function runMsm(root, args) {
|
|
686
|
-
switch (args.action) {
|
|
687
|
-
case "list": {
|
|
688
|
-
const entries = loadMsmEntries(root);
|
|
689
|
-
const cccName = readCccName(root) ?? "unknown";
|
|
690
|
-
const header = `(serenity-plugin v${ACC_VERSION}) CCC:${cccName} Root:${root}`;
|
|
691
|
-
if (entries.length === 0) return `${header}\n(no MSM registered)`;
|
|
692
|
-
const lines = entries.map((e) => {
|
|
693
|
-
const base = `${e.name} | ${e.skill ?? "-"} | ${e.category ?? "-"} | ${e.description ?? ""}`;
|
|
694
|
-
if (e.flags && e.flags.length > 0) return `${base} [flags: ${e.flags.map((f) => `--${f.name} <${f.type ?? "string"}>`).join(", ")}]`;
|
|
695
|
-
return base;
|
|
696
|
-
});
|
|
697
|
-
return `${header}\n` + lines.join("\n");
|
|
698
|
-
}
|
|
699
|
-
case "guide": return { guide: MSM_GUIDE };
|
|
700
|
-
case "catalog": return { catalog: docsPointer("catalog", "ACC 能力目录") };
|
|
701
|
-
case "exec": {
|
|
702
|
-
const { entry, businessArgs, fmtJson, hasHelp, protocol } = prepareExec(root, args);
|
|
703
|
-
const p = protocolResult(protocol);
|
|
704
|
-
if (p !== void 0) return p;
|
|
705
|
-
const baseOpts = {
|
|
706
|
-
cwd: root,
|
|
707
|
-
encoding: "utf-8",
|
|
708
|
-
timeout: MSM_TIMEOUT_MS,
|
|
709
|
-
stdio: [
|
|
710
|
-
"pipe",
|
|
711
|
-
"pipe",
|
|
712
|
-
"pipe"
|
|
713
|
-
],
|
|
714
|
-
env: buildMsmEnv(root)
|
|
715
|
-
};
|
|
716
|
-
const bunBin = bunExecutablePath();
|
|
717
|
-
let r = bunBin ? spawnSync(bunBin, [entry.path, ...businessArgs], baseOpts) : {
|
|
718
|
-
error: { code: "ENOENT" },
|
|
719
|
-
status: null,
|
|
720
|
-
stdout: "",
|
|
721
|
-
stderr: "",
|
|
722
|
-
pid: 0,
|
|
723
|
-
signal: null
|
|
724
|
-
};
|
|
725
|
-
if (r.error && isBunMissing(r.error)) r = spawnSync(NPX_BIN, [
|
|
726
|
-
"tsx",
|
|
727
|
-
entry.path,
|
|
728
|
-
...businessArgs
|
|
729
|
-
], {
|
|
730
|
-
...baseOpts,
|
|
731
|
-
shell: platform === "win32"
|
|
732
|
-
});
|
|
733
|
-
return msmExecResult(entry.name, r.status ?? 2, r.stdout ?? "", r.stderr ?? "", fmtJson, hasHelp);
|
|
734
|
-
}
|
|
735
|
-
case "register": {
|
|
736
|
-
const name = args.name ?? "";
|
|
737
|
-
const { skill, path, category, description } = args;
|
|
738
|
-
if (!name) throw new Error("register requires name");
|
|
739
|
-
if (!path || !category || !description) throw new Error("register requires path/category/description");
|
|
740
|
-
const scriptAbs = resolve(root, path);
|
|
741
|
-
if (classifyPath(scriptAbs, root) === "outside") throw new Error(`MSM register: path "${path}" escapes CCC root "${root}"`);
|
|
742
|
-
if (!existsSync(scriptAbs)) throw new Error(`MSM script not found: "${path}"`);
|
|
743
|
-
if (loadMsmEntries(root).some((e) => e.name === name)) throw new Error(`MSM already registered: "${name}"`);
|
|
744
|
-
const regPath = registryPathFor(root, skill);
|
|
745
|
-
const raw = existsSync(regPath) ? readFileSync(regPath, "utf-8").replace(/^\uFEFF/, "") : "";
|
|
746
|
-
const isV1Wrapped = raw === "" ? true : !Array.isArray(JSON.parse(raw));
|
|
747
|
-
const entries = existsSync(regPath) ? parseRegistry(readFileSync(regPath, "utf-8")) : [];
|
|
748
|
-
let flags;
|
|
749
|
-
if (args.flags) try {
|
|
750
|
-
const parsed = JSON.parse(args.flags);
|
|
751
|
-
if (!Array.isArray(parsed)) throw new Error("flags must be a JSON array");
|
|
752
|
-
flags = parsed;
|
|
753
|
-
} catch (e) {
|
|
754
|
-
throw new Error(`register flags parse failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
755
|
-
}
|
|
756
|
-
entries.push({
|
|
757
|
-
name,
|
|
758
|
-
path,
|
|
759
|
-
skill,
|
|
760
|
-
category,
|
|
761
|
-
description,
|
|
762
|
-
usage: args.usage ?? `msm ${name} [args...]`,
|
|
763
|
-
flags: flags ?? []
|
|
764
|
-
});
|
|
765
|
-
writeRegistry(regPath, entries, isV1Wrapped);
|
|
766
|
-
try {
|
|
767
|
-
const relRegistry = relative(root, regPath);
|
|
768
|
-
execFileSync("git", [
|
|
769
|
-
"add",
|
|
770
|
-
"--",
|
|
771
|
-
relRegistry
|
|
772
|
-
], {
|
|
773
|
-
cwd: root,
|
|
774
|
-
stdio: "pipe"
|
|
775
|
-
});
|
|
776
|
-
execFileSync("git", [
|
|
777
|
-
"commit",
|
|
778
|
-
"-m",
|
|
779
|
-
`chore(msm): register ${name}`
|
|
780
|
-
], {
|
|
781
|
-
cwd: root,
|
|
782
|
-
stdio: "pipe"
|
|
783
|
-
});
|
|
784
|
-
} catch {}
|
|
785
|
-
return {
|
|
786
|
-
registered: name,
|
|
787
|
-
registry: relative(root, regPath)
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
case "deregister": {
|
|
791
|
-
const name = args.name ?? "";
|
|
792
|
-
for (const regPath of findRegistries(root)) {
|
|
793
|
-
const dRaw = readFileSync(regPath, "utf-8").replace(/^\uFEFF/, "");
|
|
794
|
-
const isV1Wrapped = !Array.isArray(JSON.parse(dRaw));
|
|
795
|
-
const entries = parseRegistry(readFileSync(regPath, "utf-8"));
|
|
796
|
-
const idx = entries.findIndex((e) => e.name === name);
|
|
797
|
-
if (idx >= 0) {
|
|
798
|
-
entries.splice(idx, 1);
|
|
799
|
-
writeRegistry(regPath, entries, isV1Wrapped);
|
|
800
|
-
try {
|
|
801
|
-
const relRegistry = relative(root, regPath);
|
|
802
|
-
execFileSync("git", [
|
|
803
|
-
"add",
|
|
804
|
-
"--",
|
|
805
|
-
relRegistry
|
|
806
|
-
], {
|
|
807
|
-
cwd: root,
|
|
808
|
-
stdio: "pipe"
|
|
809
|
-
});
|
|
810
|
-
execFileSync("git", [
|
|
811
|
-
"commit",
|
|
812
|
-
"-m",
|
|
813
|
-
`chore(msm): deregister ${name}`
|
|
814
|
-
], {
|
|
815
|
-
cwd: root,
|
|
816
|
-
stdio: "pipe"
|
|
817
|
-
});
|
|
818
|
-
} catch {}
|
|
819
|
-
return { deregistered: name };
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
throw new Error(`MSM not registered: "${name}"`);
|
|
823
|
-
}
|
|
824
|
-
case "ccc-config": return docsPointer("config", "CCC 配置参考");
|
|
825
|
-
case "check": return compactRegistryQuality(checkRegistryQuality(root));
|
|
826
|
-
default: throw new Error(`Unknown action: ${args.action}`);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
function prepareExec(root, args) {
|
|
830
|
-
const name = args.name ?? "";
|
|
831
|
-
const entry = findEntry(root, name);
|
|
832
|
-
if (!entry) throw new Error(`MSM not registered: "${name}"`);
|
|
833
|
-
const business = args.args ?? [];
|
|
834
|
-
if (business[0] === "--list") return {
|
|
835
|
-
entry,
|
|
836
|
-
businessArgs: [],
|
|
837
|
-
fmtJson: false,
|
|
838
|
-
hasHelp: false,
|
|
839
|
-
protocol: { list: loadMsmEntries(root).map((e) => ({
|
|
840
|
-
name: e.name,
|
|
841
|
-
category: e.category ?? null
|
|
842
|
-
})) }
|
|
843
|
-
};
|
|
844
|
-
if (business[0] === "--schema") {
|
|
845
|
-
const target = business[1];
|
|
846
|
-
const found = target ? loadMsmEntries(root).find((e) => e.name === target) : null;
|
|
847
|
-
if (!found) throw new Error(`MSM not registered: "${target}"`);
|
|
848
|
-
return {
|
|
849
|
-
entry,
|
|
850
|
-
businessArgs: [],
|
|
851
|
-
fmtJson: false,
|
|
852
|
-
hasHelp: false,
|
|
853
|
-
protocol: { schema: {
|
|
854
|
-
name: found.name,
|
|
855
|
-
path: found.path,
|
|
856
|
-
flags: (found.flags ?? []).map((f) => ({
|
|
857
|
-
name: f.name,
|
|
858
|
-
type: f.type ?? null,
|
|
859
|
-
description: f.description ?? null
|
|
860
|
-
}))
|
|
861
|
-
} }
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
const fmtJson = business[0] === "--format=json";
|
|
865
|
-
const businessArgs = fmtJson ? business.slice(1) : business;
|
|
866
|
-
const hasHelp = businessArgs.includes("--help") || businessArgs.includes("-h");
|
|
867
|
-
for (const flag of entry.flags ?? []) {
|
|
868
|
-
if (flag.type !== "path") continue;
|
|
869
|
-
const eq = businessArgs.find((a) => a.startsWith(`--${flag.name}=`));
|
|
870
|
-
if (eq) assertPathInsideRoot(root, eq.slice(flag.name.length + 3), flag.name);
|
|
871
|
-
else {
|
|
872
|
-
const idx = businessArgs.indexOf(`--${flag.name}`);
|
|
873
|
-
if (idx >= 0 && businessArgs[idx + 1]) assertPathInsideRoot(root, businessArgs[idx + 1], flag.name);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
const script = resolve(root, entry.path);
|
|
877
|
-
if (classifyPath(script, root) === "outside") throw new Error(`MSM script escapes CCC root: "${entry.path}"`);
|
|
878
|
-
if (!existsSync(script)) throw new Error(`MSM script not found: "${entry.path}"`);
|
|
879
|
-
return {
|
|
880
|
-
entry: {
|
|
881
|
-
...entry,
|
|
882
|
-
path: script
|
|
883
|
-
},
|
|
884
|
-
businessArgs,
|
|
885
|
-
fmtJson,
|
|
886
|
-
hasHelp
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
/** 协议结果扁平化:{list|schema} 包装 → 顶层值(兼容旧契约);非协议返回 undefined */
|
|
890
|
-
function protocolResult(protocol) {
|
|
891
|
-
if (!protocol) return void 0;
|
|
892
|
-
if ("list" in protocol) return protocol.list;
|
|
893
|
-
if ("schema" in protocol) return protocol.schema;
|
|
894
|
-
}
|
|
895
|
-
/** 失败 TIP(对齐 osp:业务 exit≠0 且未传 --help 时追加提示) */
|
|
896
|
-
function helpTip() {
|
|
897
|
-
return "\n[TIP] Pass \"--help\" as the first arg to see this MSM's usage and required flags.";
|
|
898
|
-
}
|
|
899
|
-
function msmExecResult(name, status, stdout, stderr, fmtJson, hasHelp = false) {
|
|
900
|
-
const tip = status !== 0 && !hasHelp ? helpTip() : "";
|
|
901
|
-
if (fmtJson) return status === 0 ? {
|
|
902
|
-
name,
|
|
903
|
-
exit: 0,
|
|
904
|
-
ok: true,
|
|
905
|
-
data: stdout.trim()
|
|
906
|
-
} : {
|
|
907
|
-
name,
|
|
908
|
-
exit: status,
|
|
909
|
-
ok: false,
|
|
910
|
-
error: (stderr.trim() || stdout.trim()) + tip
|
|
911
|
-
};
|
|
912
|
-
/**
|
|
913
|
-
* 🔴🔴 **2026-11-04 owner 令:成功就吐原文,⛔ 不套信封。**
|
|
914
|
-
*
|
|
915
|
-
* owner 原话(看 `msm(carrier-log, [status, --trajectory …])` 的调用卡时):
|
|
916
|
-
* 「我想简化这个调用,输出不要套结构 直接 stdout 的内容给出来」,
|
|
917
|
-
* 并对「失败怎么办」补答:**「失败还是完整结构,成功简化,成功是大概率事件」**。
|
|
918
|
-
*
|
|
919
|
-
* ## 为什么这是对的(不是审美偏好)
|
|
920
|
-
* 修前每一次成功调用都返回 `{name, exit, stdout, stderr}` ——
|
|
921
|
-
* 一整块**中文排版正文**(`═══` 表头、多行缩进)被塞进 JSON 字符串,
|
|
922
|
-
* 于是**每一个换行都变成字面量 `\n`**,读者(模型)要先在脑子里做一次反转义。
|
|
923
|
-
* 那是纯粹的**传输损耗**:`name` 是调用方自己传的(零信息),
|
|
924
|
-
* `exit:0` 与 `stderr:""` 在成功路径上是常量(零信息)。
|
|
925
|
-
*
|
|
926
|
-
* ## 为什么失败路径**保持结构**(owner 明确要求,且理由更硬)
|
|
927
|
-
* `exit` 与 `stderr` 是**失败信号本身**。若把失败也抖成裸文本,
|
|
928
|
-
* 「工具挂了」会与「成功了但没输出」在阅读面上**长得一样** ——
|
|
929
|
-
* 那是本轨迹反复付代价的形态(D252 同族:读数器在跑,但答的不是那个问题;
|
|
930
|
-
* D253 同族:恒空的读数器会让「我没藏」与「藏了但读不到」publish 成同一输出)。
|
|
931
|
-
* ⇒ **失败必须能被机械判别**,所以保留 `exit` + 原文。
|
|
932
|
-
*
|
|
933
|
-
* ⚠️ **`--format=json` 那一路(上面 `fmtJson` 分支)一字不改**:它是**机器协议**,
|
|
934
|
-
* 调用方已经声明"我要结构化",简化它等于破坏契约。
|
|
935
|
-
*/
|
|
936
|
-
if (status === 0) return stdout.trimEnd();
|
|
937
|
-
return {
|
|
938
|
-
name,
|
|
939
|
-
exit: status,
|
|
940
|
-
stdout,
|
|
941
|
-
stderr: stderr + tip
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
/**
|
|
945
|
-
* 异步执行 MSM(msm 工具主路径):
|
|
946
|
-
* 用 execFile + promisify + timeout(超时自动 kill),**不阻塞 Node 事件循环**。
|
|
947
|
-
* (同步 spawnSync 版会阻塞 web 事件循环 → MSM 脚本自请求 3080 时死锁,见 postmortem。)
|
|
948
|
-
*/
|
|
949
|
-
/** bun 缺失的错误码集(Windows 兼容:无 bun 时 execFile('bun') 抛 EINVAL 而非 ENOENT,见 Windows 审计问题 5) */
|
|
950
|
-
const BUN_MISSING_CODES = /* @__PURE__ */ new Set([
|
|
951
|
-
"ENOENT",
|
|
952
|
-
"EINVAL",
|
|
953
|
-
"EPERM"
|
|
954
|
-
]);
|
|
955
|
-
function isBunMissing(err) {
|
|
956
|
-
return typeof err.code === "string" && BUN_MISSING_CODES.has(err.code);
|
|
957
|
-
}
|
|
958
|
-
async function runMsmAsync(root, args) {
|
|
959
|
-
if (args.action !== "exec") return runMsm(root, args);
|
|
960
|
-
const { entry, businessArgs, fmtJson, hasHelp, protocol } = prepareExec(root, args);
|
|
961
|
-
const p = protocolResult(protocol);
|
|
962
|
-
if (p !== void 0) return p;
|
|
963
|
-
const bunBin = bunExecutablePath();
|
|
964
|
-
const baseOpts = {
|
|
965
|
-
cwd: root,
|
|
966
|
-
encoding: "utf-8",
|
|
967
|
-
timeout: MSM_TIMEOUT_MS,
|
|
968
|
-
maxBuffer: 67108864,
|
|
969
|
-
env: buildMsmEnv(root)
|
|
970
|
-
};
|
|
971
|
-
try {
|
|
972
|
-
if (bunBin) {
|
|
973
|
-
const r = await execFileAsync(bunBin, [entry.path, ...businessArgs], baseOpts);
|
|
974
|
-
return msmExecResult(entry.name, 0, r.stdout, r.stderr, fmtJson, hasHelp);
|
|
975
|
-
}
|
|
976
|
-
throw { code: "ENOENT" };
|
|
977
|
-
} catch (e) {
|
|
978
|
-
const err = e;
|
|
979
|
-
if (isBunMissing(err)) try {
|
|
980
|
-
const r = await execFileAsync(NPX_BIN, [
|
|
981
|
-
"tsx",
|
|
982
|
-
entry.path,
|
|
983
|
-
...businessArgs
|
|
984
|
-
], {
|
|
985
|
-
...baseOpts,
|
|
986
|
-
shell: platform === "win32"
|
|
987
|
-
});
|
|
988
|
-
return msmExecResult(entry.name, 0, r.stdout, r.stderr, fmtJson, hasHelp);
|
|
989
|
-
} catch (e2) {
|
|
990
|
-
const err2 = e2;
|
|
991
|
-
const status = err2.killed ? 124 : typeof err2.code === "number" ? err2.code : 2;
|
|
992
|
-
const stdout = err2.stdout ?? "";
|
|
993
|
-
const stderr = err2.killed ? `MSM timed out after ${MSM_TIMEOUT_MS}ms` : err2.stderr ?? err2.message ?? "";
|
|
994
|
-
return msmExecResult(entry.name, status, stdout, stderr, fmtJson, hasHelp);
|
|
995
|
-
}
|
|
996
|
-
const status = err.killed ? 124 : typeof err.code === "number" ? err.code : 2;
|
|
997
|
-
const stdout = err.stdout ?? "";
|
|
998
|
-
const stderr = err.killed ? `MSM timed out after ${MSM_TIMEOUT_MS}ms` : err.stderr ?? err.message ?? "";
|
|
999
|
-
return msmExecResult(entry.name, status, stdout, stderr, fmtJson, hasHelp);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
//#endregion
|
|
1003
|
-
export { loadMsmEntries as a, docsPointer as c, findEntry as i, setWeixinSendEndpoint as l, CCC_CONFIG_REFERENCE as n, runMsm as o, checkRegistryQuality as r, runMsmAsync as s, ACC_CATALOG as t };
|