@shgroup/dsh-serenity-hooks 1.119.0 → 1.121.0

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/lib/invariant.js CHANGED
@@ -82,6 +82,33 @@ function assertManifestProse(manifestPath, readmePaths) {
82
82
  const absent = tools.filter((t) => !s.text.includes(t));
83
83
  if (absent.length) issues.push(`${s.where} 的名单缺 ${absent.length} 项:${absent.join(", ")}(防"数对了、名单漏了")`);
84
84
  }
85
+ const countCn = cnNumberOf(n);
86
+ const condCn = cnNumberOf(3);
87
+ for (const p of readmePaths) {
88
+ if (!existsSync(p)) {
89
+ issues.push(`README 不存在:${p}`);
90
+ continue;
91
+ }
92
+ const m = readFileSync(p, "utf-8").match(/^###\s*3\.1\s*(\S+?)个工具(?:(其中(\S+?)个按条件出现))?/m);
93
+ if (!m) {
94
+ issues.push(`${p} 里找不到 §3.1 的「…个工具」标题(形态已变 ⇒ 钉子也要跟着改)`);
95
+ continue;
96
+ }
97
+ if (m[1] !== countCn) issues.push(`${p} 的 §3.1 标题写「${m[1]}个工具」,应为「${countCn}个工具」(工具数已 ${n})`);
98
+ if (m[2] !== void 0 && m[2] !== condCn) issues.push(`${p} 的 §3.1 标题写「其中${m[2]}个按条件出现」,应为「其中${condCn}个按条件出现」(条件工具数已 3)`);
99
+ }
100
+ return issues;
101
+ }
102
+ /**
103
+ * 阿拉伯数字 → 中文数字(README §3.1 标题用;只覆盖到 29,够 README 用)。
104
+ *
105
+ * 🔴 抽成函数是**必须**的,不是洁癖:`CONDITIONAL_TOOL_COUNT` 是**字面量类型**,
106
+ * 就地写三元时 TS 会在第一个分支之后把类型缩窄成 `never` ⇒ `=== 20` 处报
107
+ * "types '3' and '20' have no overlap"(TS2367)。那**不是逻辑错**,是窄化造成的假报,
108
+ * 而"给假报让路"最简单的做法就是放宽类型 —— ⛔ 那会连带丢掉真正的越界保护。
109
+ * 走函数调用 ⇒ 入参类型是 `number`,窄化不发生,判据与顺序都不变。
110
+ */
111
+ function cnNumberOf(n) {
85
112
  const cn = [
86
113
  "零",
87
114
  "一",
@@ -95,20 +122,9 @@ function assertManifestProse(manifestPath, readmePaths) {
95
122
  "九",
96
123
  "十"
97
124
  ];
98
- const countCn = n <= 10 ? cn[n] : n < 20 ? `十${cn[n - 10]}` : `二十${n === 20 ? "" : cn[n - 20]}`;
99
- for (const p of readmePaths) {
100
- if (!existsSync(p)) {
101
- issues.push(`README 不存在:${p}`);
102
- continue;
103
- }
104
- const m = readFileSync(p, "utf-8").match(/^###\s*3\.1\s*(\S+?)个工具/m);
105
- if (!m) {
106
- issues.push(`${p} 里找不到 §3.1 的「…个工具」标题(形态已变 ⇒ 钉子也要跟着改)`);
107
- continue;
108
- }
109
- if (m[1] !== countCn) issues.push(`${p} 的 §3.1 标题写「${m[1]}个工具」,应为「${countCn}个工具」(工具数已 ${n})`);
110
- }
111
- return issues;
125
+ if (n <= 10) return cn[n] ?? String(n);
126
+ if (n < 20) return `十${cn[n - 10] ?? ""}`;
127
+ return `二十${n === 20 ? "" : cn[n - 20] ?? ""}`;
112
128
  }
113
129
  /**
114
130
  * 包级不变量:本插件注册的工具集合(与 dsh.plugin.json contributes.tools 一致)。
@@ -147,9 +163,10 @@ const REGISTERED_TOOLS = [
147
163
  "localstore",
148
164
  "container_admin",
149
165
  "im-bridge",
150
- "diagram"
166
+ "diagram",
167
+ "reconstruct"
151
168
  ];
152
169
  /** 条件出现的工具数(`REGISTERED_TOOLS` 的**末段**;`assertManifestProse` 用) */
153
- const CONDITIONAL_TOOL_COUNT = 2;
170
+ const CONDITIONAL_TOOL_COUNT = 3;
154
171
  //#endregion
155
172
  export { CONDITIONAL_TOOL_COUNT, REGISTERED_TOOLS, assertManifestProse, verifyToolConsistency };
@@ -58,6 +58,6 @@ export declare function assertManifestProse(manifestPath: string, readmePaths: r
58
58
  * `review`(C 档,调引擎 `compliance`)/`index`(调 P1 的生成器)/`status` ⇒ **14**。
59
59
  * 同规格:**条件可见与否不影响这里列它**(本常量 = "插件**具备**的工具面")。
60
60
  */
61
- export declare const REGISTERED_TOOLS: readonly ["container_fs", "cognitive_trajectory", "dashboard", "container_git", "msm", "praxis", "ontology", "serenity-skill-creator", "localstore", "container_admin", "im-bridge", "diagram"];
61
+ export declare const REGISTERED_TOOLS: readonly ["container_fs", "cognitive_trajectory", "dashboard", "container_git", "msm", "praxis", "ontology", "serenity-skill-creator", "localstore", "container_admin", "im-bridge", "diagram", "reconstruct"];
62
62
  /** 条件出现的工具数(`REGISTERED_TOOLS` 的**末段**;`assertManifestProse` 用) */
63
- export declare const CONDITIONAL_TOOL_COUNT = 2;
63
+ export declare const CONDITIONAL_TOOL_COUNT = 3;
@@ -1,7 +1,7 @@
1
1
  import { d as readCccName, i as findGitRoot, l as pathInside, s as loadSerenityConfig, t as DEFAULT_SERENITY_CONFIG_PATHS } from "./ccc-x94FCzOv.js";
2
2
  import { u as ACC_VERSION } from "./rules-DKlpuFN_.js";
3
- import { i as readDshVersion, t as hostContractReport, v as checkRegistryQuality } from "./contract-qqnsi8tc.js";
4
- import { i as wakeSchedulerState, v as listWakes } from "./scheduler-CUPz7geH.js";
3
+ import { n as readDshVersion, s as hostContractReport, y as checkRegistryQuality } from "./status-DU4k3Wqe.js";
4
+ import { a as wakeSchedulerState, y as listWakes } from "./scheduler-CMBAoYR8.js";
5
5
  import { resolve } from "node:path";
6
6
  import { existsSync, readFileSync, statSync } from "node:fs";
7
7
  //#region src/surface/observation.ts
@@ -23,7 +23,27 @@
23
23
  * 配额、二进制拒绝全部仍由宿主实现执行。
24
24
  */
25
25
  import type { Context } from 'cordis';
26
- import type { HttpFetchResolver } from '@deepseek-ai/dsh-web-fetch-http';
26
+ /**
27
+ * 🔴 **0.2.2-rc.1 适配(2026-11-05,S142)**:宿主导出的 `HttpFetchResolver` 类型被**删除**了。
28
+ *
29
+ * 不是改名,是**整层消失**:`0.2.1-rc.2` 的 `provider.d.ts:24` 有
30
+ * `export type HttpFetchResolver = (hostname, signal) => Promise<PublicAddress[]>`,
31
+ * 而 `0.2.2-rc.1` 的同名文件里**没有这个导出**(同时 `network.ts` / `isPublicIpAddress` /
32
+ * `createPinnedLookup` 也一起消失,构造器从 `(limits, resolveAddresses?)` 缩成 `(limits)`)。
33
+ * 上游 README 已明写新立场:「It does not restrict destination addresses」。
34
+ *
35
+ * ⇒ 本模块**在 0.2.2+ 上已无存在理由**(它当年唯一的作用就是放宽那条地址判据)。
36
+ * 但**旧宿主(0.1.7 / 0.2.0 / 0.2.1)仍在支持档里**,而它们真的会拦 fake-ip
37
+ * ⇒ 不能现在删。故此处**自带一份结构等价的契约**,⛔ 不再从宿主 import 那个已消失的类型。
38
+ *
39
+ * ⚠️ 退役条件(写给下一个我):当 `VERIFIED_HOST_BANDS` 的下界抬到 `0.2.2` 之上时,
40
+ * **本文件连同 `cordis.patch.yml` 的 `disabled: true` 一起整块删除** —— 留着的每一天都是
41
+ * 一份「没人需要、但将来会漂」的代码。
42
+ */
43
+ type FetchResolver = (hostname: string, signal: AbortSignal) => Promise<Array<{
44
+ address: string;
45
+ family: 4 | 6;
46
+ }>>;
27
47
  /** 公网单播 IPv4(拒绝全部保留/私网段——与宿主判定口径一致,只额外放行 fake-ip) */
28
48
  export declare function isPublicV4(address: string): boolean;
29
49
  /** fake-ip 段判定(198.18.0.0/15) */
@@ -36,17 +56,15 @@ export declare function isPublicV6(address: string): boolean;
36
56
  /** 该地址是否允许被抓取:公网单播 **或** fake-ip 段 */
37
57
  export declare function isAllowedFetchAddress(address: string): boolean;
38
58
  /**
39
- * 解析并校验地址集合(宿主 `HttpFetchResolver` 契约)。
59
+ * 解析并校验地址集合(本模块自带的 {@link FetchResolver} 契约)。
40
60
  *
41
- * 语义与宿主 `resolvePublicAddresses` 一致——**任一地址不合法即整体拒绝**(防 DNS 重绑定),
42
- * 仅判据从「公网单播」放宽为 `isAllowedFetchAddress`。
43
- */
44
- export declare const resolveAllowedAddresses: HttpFetchResolver;
45
- /**
46
- * 注册接管 `http` id 的 fetch provider(宿主内置 provider 由本包 bundle patch 禁用)。
61
+ * ⚠️ **前身是宿主的 `HttpFetchResolver`,但那个类型在 0.2.2-rc.1 已随地址解析层一起被删除**
62
+ * (见文件头)。这里的语义沿用它,⛔ 但别再说"这是宿主契约" —— 那会让下一个维护者
63
+ * 去宿主里找一个不存在的类型(D151:退役功能的残留引用是零信号熵)。
47
64
  *
48
- * 后端包 `@deepseek-ai/dsh-web-fetch-http` 用**动态 import**:宿主版本里若没有该包,
49
- * 只降级为一条告警(绝不因缺一个可选后端而让整机启动失败——apply 抛错 = dsh 启动失败)。
50
- * 失败一律响亮但不抛错。
65
+ * 语义:**任一地址不合法即整体拒绝**(防 DNS 重绑定),
66
+ * 仅判据从「公网单播」放宽为 `isAllowedFetchAddress`。
51
67
  */
68
+ export declare const resolveAllowedAddresses: FetchResolver;
52
69
  export declare function registerWebFetchProvider(ctx: Context): Promise<void>;
70
+ export {};
@@ -2871,6 +2871,7 @@ var scheduler_exports = /* @__PURE__ */ __exportAll({
2871
2871
  buildCroWakeText: () => buildCroWakeText,
2872
2872
  buildSendText: () => buildSendText,
2873
2873
  buildWakeText: () => buildWakeText,
2874
+ createAndBindTarget: () => createAndBindTarget,
2874
2875
  deliverWake: () => deliverWake,
2875
2876
  registerWakeScheduler: () => registerWakeScheduler,
2876
2877
  resolveWakeTarget: () => resolveWakeTarget,
@@ -3231,7 +3232,7 @@ async function sendToCognitiveTrajectory(ctx, root, target, message, sender) {
3231
3232
  *
3232
3233
  * @returns 命中返回 agent 与取得方式;任一步失败返回**带原因**的 error(不静默、不误报成功)
3233
3234
  */
3234
- async function createAndBindTarget(ctx, root, dirName) {
3235
+ async function createAndBindTarget(ctx, root, dirName, opts = {}) {
3235
3236
  const sc = hostService(ctx, "sessionController");
3236
3237
  const create = sc?.create;
3237
3238
  if (typeof create !== "function") return {
@@ -3268,7 +3269,9 @@ async function createAndBindTarget(ctx, root, dirName) {
3268
3269
  dirName,
3269
3270
  mdPath: join(root, "AGENT_SESSIONS", dirName, "SESSION.md"),
3270
3271
  note: "auto-created by send-now",
3271
- createdAsUser: true
3272
+ createdAsUser: true,
3273
+ ...opts.takeover === true ? { takeover: true } : {},
3274
+ alive: hostAliveProbe(ctx)
3272
3275
  });
3273
3276
  const openingNote = deliverCarrierOpening(agent, buildCarrierOpening(parseTrajectoryCode(dirName) ?? dirName, trajectoryDescOf(dirName))) ? ", opening-as-user" : ", ⚠️ 开场白未投递";
3274
3277
  const titleNote = renameCarrierTitle(ctx, agent, root, dirName);
@@ -3857,4 +3860,4 @@ function registerWakeScheduler(ctx) {
3857
3860
  registerDisposer(ctx, "认知轨迹唤醒调度器", () => clock.dispose());
3858
3861
  }
3859
3862
  //#endregion
3860
- export { addWake as _, DEFAULT_LOOKBACK_MS as a, projectDirNameForCwd as c, registerCroTurnTracking as d, registerDisposer as f, WAKE_CATCH_UP_MS as g, CARRIER_OPENING_MARK as h, wakeSchedulerState as i, scanInterruptedSessions as l, listCroCognitiveTrajectories as m, scheduler_exports as n, createResumeOne as o, buildCroSnapshot as p, sendToCognitiveTrajectory as r, formatPendingTools as s, registerWakeScheduler as t, listRunningSessionIds as u, listWakes as v };
3863
+ export { WAKE_CATCH_UP_MS as _, wakeSchedulerState as a, formatPendingTools as c, listRunningSessionIds as d, registerCroTurnTracking as f, CARRIER_OPENING_MARK as g, listCroCognitiveTrajectories as h, sendToCognitiveTrajectory as i, projectDirNameForCwd as l, buildCroSnapshot as m, registerWakeScheduler as n, DEFAULT_LOOKBACK_MS as o, registerDisposer as p, scheduler_exports as r, createResumeOne as s, createAndBindTarget as t, scanInterruptedSessions as u, addWake as v, listWakes as y };
@@ -1,10 +1,10 @@
1
1
  import { d as hostSessions, r as cccRootForCwd } from "./ccc-roots-CsSSQjSS.js";
2
2
  import { m as readTrajectorySubscriptions } from "./ccc-x94FCzOv.js";
3
3
  import { F as isoLocal, w as sessionEvents } from "./bind-file-B0TuOP89.js";
4
- import { g as WAKE_CATCH_UP_MS, m as listCroCognitiveTrajectories } from "./scheduler-CUPz7geH.js";
4
+ import { _ as WAKE_CATCH_UP_MS, h as listCroCognitiveTrajectories } from "./scheduler-CMBAoYR8.js";
5
5
  import { n as readSimpleSettings } from "./settings-DibHCfEU.js";
6
- import { i as subscriptionStats, r as subscriptionEval } from "./subscriptions-CGpxv6Z6.js";
7
- import { containerClocks, containerWakes } from "./observation-Ci2SBIX2.js";
6
+ import { i as subscriptionStats, r as subscriptionEval } from "./subscriptions-CV-7Yhqb.js";
7
+ import { containerClocks, containerWakes } from "./observation-D0RjHk0e.js";
8
8
  //#region src/trajectory/live.ts
9
9
  /**
10
10
  * trajectory/live.ts — 进程内 live 会话取数 + 精简诊断
@@ -1429,21 +1429,34 @@ function forgetImBridgeVisibility(_sessionId) {}
1429
1429
  /** 会话销毁清理(lifecycle 调用)——方案 C 后由统一清理撤销,这里保留语义占位。 */
1430
1430
  function forgetHostScheduleToolHiding(_sessionId) {}
1431
1431
  /**
1432
- * 宿主 `dsh-tool-schedule` 注册的 4 个模型可见工具名(**逐字**)。
1432
+ * 宿主 `dsh-tool-schedule` 注册的模型可见工具名(**逐字**)。
1433
1433
  *
1434
1434
  * 🔴 **为什么要在 CCC 内屏蔽**(owner 原话:「这和 CRO 冲突,要求在宁静号激活情况下屏蔽掉」):
1435
1435
  * 宁静号的唤醒/巡航走 `cognitive_trajectory send-later` → `AGENT_SESSIONS/wake-registry.json`
1436
1436
  * → 中心调度器 5min tick(D58)。宿主这套定时器是**另一个**真相源 ⇒ 两处记账、
1437
1437
  * CRO 判据失真、且模型可能顺手排一个"不在任何账本里"的唤醒。
1438
- * ⚠️ 本清单**合并发射时不做探活**。⚠️ 现状缺口(v1.87.1 如实登记):宿主**没装**
1439
- * `dsh-tool-schedule` 时,这 4 个名字会把整次 restrict 拒掉,而退档只保留 ACC 自己的名字
1440
- * ⇒ 这一格的屏蔽**不生效**(旧实现同样不生效,**未回归**;但"顺带修好了"这句是假的,已删)。
1438
+ *
1439
+ * 🔴🔴 **2026-11-06(S142):宿主 0.2.2-rc.1 把这套工具改了名,本表没跟上 ⇒ 屏蔽漏了一半**。
1440
+ * 实测(`msm sys node` 读本机装机包的 `lib/index.js`,⛔ 非推断):
1441
+ * | 宿主版本 | `dsh-tool-schedule` 真实注册名 |
1442
+ * |---|---|
1443
+ * | `0.2.1-rc.2` | `schedule_create` / `schedule_list` / `schedule_update` / `schedule_delete` |
1444
+ * | `0.2.2-rc.1` | `schedule_create` / `schedule_list` / **`schedule_view`** / **`schedule_edit`** |
1445
+ * ⇒ `schedule_update` / `schedule_delete` **已不存在**(写在本表里=永远剔不掉的无效名),
1446
+ * 而 `schedule_view` / `schedule_edit` **从未被屏蔽**(用户在会话里能直接看到并调用它们)。
1447
+ * **失效形态是静默的**:宿主 `restrict()` 对未知名只会**剔除**(我们那边的降级档还会打
1448
+ * 「跳过 N 个未注册名」),所以"旧名失效+新名漏网"在读数面上表现为**一切正常**。
1449
+ * ⇒ 判据:**这张表是宿主侧的名字,宿主改名必须同批改这里**;升级宿主后要**真机核一次工具面**
1450
+ * (会话里能不能看见 `schedule_*`),⛔ 不能只信单元测试——它测的是本表,本表错了它也绿。
1451
+ * ⚠️ 本清单**合并发射时不做探活**。⚠️ 现状缺口(v1.87.1 如实登记):宿主**没装**
1452
+ * `dsh-tool-schedule` 时,这些名字会把整次 restrict 拒掉,而退档只保留 ACC 自己的名字
1453
+ * ⇒ 这一格的屏蔽**不生效**(旧实现同样不生效,**未回归**;但"顺带修好了"这句是假的,已删)。
1441
1454
  */
1442
1455
  const HOST_SCHEDULE_TOOL_NAMES = [
1443
1456
  "schedule_create",
1444
1457
  "schedule_list",
1445
- "schedule_update",
1446
- "schedule_delete"
1458
+ "schedule_view",
1459
+ "schedule_edit"
1447
1460
  ];
1448
1461
  /** 会话销毁清理(lifecycle 调用)。
1449
1462
  * ⚠️ 方案 C 后撤销只在 `forgetToolVisibility` 做一次;本函数保留语义占位。
@@ -1552,201 +1565,6 @@ function registerGuards(ctx, opts = {}) {
1552
1565
  });
1553
1566
  }
1554
1567
  //#endregion
1555
- //#region src/skills/opencode-scan.ts
1556
- /**
1557
- * opencode-scan.ts — opencode skill 标准扫描(纯逻辑,零 DSH 依赖)
1558
- *
1559
- * 兼容 opencode 的 skill 标准:`.opencode/skills/<name>/SKILL.md`
1560
- * (frontmatter: name/description/whenToUse;结构含 references/、scripts/)。
1561
- */
1562
- /** 解析 --- 分隔的 YAML frontmatter(只需 name/description/whenToUse) */
1563
- function parseFrontmatter(raw) {
1564
- const text = raw.replace(/^\uFEFF/, "");
1565
- const m = /^---\s*\n([\s\S]*?)\n---\s*\n?/.exec(text);
1566
- if (!m) return {
1567
- meta: {
1568
- name: "",
1569
- description: ""
1570
- },
1571
- content: text
1572
- };
1573
- const fm = m[1];
1574
- const body = text.slice(m[0].length);
1575
- const grab = (key) => {
1576
- const line = fm.split("\n").find((l) => l.startsWith(`${key}:`));
1577
- if (!line) return void 0;
1578
- return line.slice(key.length + 1).trim().replace(/^['"]|['"]$/g, "");
1579
- };
1580
- const meta = {
1581
- name: grab("name") ?? "",
1582
- description: grab("description") ?? ""
1583
- };
1584
- const whenToUse = grab("whenToUse");
1585
- if (whenToUse) meta.whenToUse = whenToUse;
1586
- return {
1587
- meta,
1588
- content: body
1589
- };
1590
- }
1591
- /** 扫描 CCC 的 .opencode/skills(一级目录 + SKILL.md 存在性) */
1592
- function listOpencodeSkillDirs(root) {
1593
- const dir = join(root, ".opencode", "skills");
1594
- if (!existsSync(dir)) return [];
1595
- return readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join(dir, e.name)).filter((d) => existsSync(join(d, "SKILL.md")));
1596
- }
1597
- /** 加载一个 opencode skill(frontmatter 解析 + 正文);读失败(EPERM/占用等)返回 null,单目录容错 */
1598
- function loadOpencodeSkill(skillDir) {
1599
- let raw;
1600
- try {
1601
- raw = readFileSync(join(skillDir, "SKILL.md"), "utf-8");
1602
- } catch {
1603
- return null;
1604
- }
1605
- const { meta, content } = parseFrontmatter(raw);
1606
- return {
1607
- name: meta.name,
1608
- dir: skillDir,
1609
- meta,
1610
- content,
1611
- path: join(skillDir, "SKILL.md")
1612
- };
1613
- }
1614
- //#endregion
1615
- //#region src/surface/status.ts
1616
- /**
1617
- * surface/status.ts — 状态与安全模式操作(纯逻辑,零 DSH 依赖,可独立单测)
1618
- *
1619
- * WebUI 停靠栏的数据源:ACC 版本 / CCC 根 / safe-mode 状态 / 黑名单 / keeper 阈值。
1620
- * setSafeMode 直接读写 .serenity-safe-on 标记(守卫实时读取,写即生效)。
1621
- */
1622
- /** 宿主包名 —— 从运行入口反推包根时的**身份核对**用(见 {@link dshVersionFromEntry}) */
1623
- const HOST_PACKAGE_NAME = "@deepseek-ai/dsh";
1624
- /** 上溯层数上限:入口脚本在包内的深度是 `lib/`(1 层)或 `lib/x/y/`(≤3 层)⇒ 6 层足够,且**保证有界** */
1625
- const MAX_ENTRY_ASCENT = 6;
1626
- /**
1627
- * 🔴 **布局无关档**:从**正在跑的那个入口脚本**反推宿主包根,读它的 `version`。
1628
- *
1629
- * 为什么必须补这一档(R↓:一处**静默失效**的实际缺陷;2026-09-28 docker bench 实测):
1630
- * 下面那条静态候选链({@link readDshVersion} 的 ②)是**猜安装位置**——`npm_config_prefix` /
1631
- * `APPDATA\npm` / `~/.npm-global`。一旦宿主装在**别处**(典型 = 容器镜像里的
1632
- * `/usr/local/lib/node_modules/@deepseek-ai/dsh`),**三个候选全不中** ⇒ 返回 `null`
1633
- * ⇒ `checkHostVersion(null)` 只给一条 **`required: false`** 的 issue ⇒ 报告 `ok` 仍为 `true`
1634
- * ⇒ **版本门完全静默**(bench 逐字:`host contract degraded (1 optional): host version unknown`)。
1635
- * ⚠️ 这类坏法**比"偶尔报警"更危险**:一条**永远为假**的判据看起来像"没报警 = 没问题"。
1636
- *
1637
- * 而"我们正跑在哪个宿主里"**本来就有直接证据**:`process.argv[1]`(= 启动本进程的那个脚本)。
1638
- * 三条判据要点(每条都对应一个实测过的坑):
1639
- * ① **先 `realpath`** —— 全局安装的 `dsh` 是**符号链接**(`/usr/local/bin/dsh` → `…/@deepseek-ai/dsh/lib/bin.js`),
1640
- * 而 Node 的 `argv[1]` **保留调用路径、不解析符号链接** ⇒ 不 realpath 就永远上溯不到包根。
1641
- * ② **核对包名**(`name === '@deepseek-ai/dsh'`)—— 否则在 vitest / npx 等入口下会误取**别人的**
1642
- * `package.json`(这是本档**唯一**的假阳性来源)。
1643
- * ③ **上溯有界**({@link MAX_ENTRY_ASCENT})—— 不设界的话,一个不在任何 dsh 包内的入口会一路爬到文件系统根。
1644
- *
1645
- * @param entry `process.argv[1]`(单测直接注入,无需替身)
1646
- */
1647
- function dshVersionFromEntry(entry) {
1648
- if (typeof entry !== "string" || entry === "") return null;
1649
- let dir;
1650
- try {
1651
- const real = realpathSync(entry);
1652
- dir = statSync(real).isDirectory() ? real : dirname(real);
1653
- } catch {
1654
- return null;
1655
- }
1656
- for (let i = 0; i < MAX_ENTRY_ASCENT; i++) {
1657
- try {
1658
- const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
1659
- if (pkg.name === HOST_PACKAGE_NAME && typeof pkg.version === "string") return pkg.version;
1660
- } catch {}
1661
- const parent = dirname(dir);
1662
- if (parent === dir) break;
1663
- dir = parent;
1664
- }
1665
- return null;
1666
- }
1667
- /**
1668
- * 读取已安装 DSH CLI 版本;读不到返回 null。
1669
- *
1670
- * **两档,顺序有理由**:
1671
- * ① 🔴 **布局无关档**({@link dshVersionFromEntry})= **正在跑的就是它** —— 直接证据优先于"猜安装位置"。
1672
- * ② **静态候选链**(跨平台历史档,保留):`npm_config_prefix` / `APPDATA\npm` / `~/.npm-global`
1673
- * (Windows npm 全局装在 `%APPDATA%\npm`,见审计问题 13)。
1674
- * ⚠️ 保留它是因为**本进程不一定是 dsh CLI**(单测、嵌入式、将来别的宿主进程)——
1675
- * 那时"本机装了哪个版本"仍需一个答案,只是证据等级更低。
1676
- */
1677
- function readDshVersion() {
1678
- const fromEntry = dshVersionFromEntry(process.argv[1]);
1679
- if (fromEntry !== null) return fromEntry;
1680
- const candidates = [];
1681
- if (process.env.npm_config_prefix) candidates.push(join(process.env.npm_config_prefix, "lib", "node_modules", "@deepseek-ai", "dsh"));
1682
- if (process.env.APPDATA) candidates.push(join(process.env.APPDATA, "npm", "node_modules", "@deepseek-ai", "dsh"));
1683
- candidates.push(join(homedir(), ".npm-global", "lib", "node_modules", "@deepseek-ai", "dsh"));
1684
- for (const p of candidates) try {
1685
- const pkg = JSON.parse(readFileSync(join(p, "package.json"), "utf-8"));
1686
- if (typeof pkg.version === "string") return pkg.version;
1687
- } catch {}
1688
- return null;
1689
- }
1690
- function getStatus(cwd, configPaths = DEFAULT_SERENITY_CONFIG_PATHS) {
1691
- const root = cccRootForCwd(cwd);
1692
- const restrict = getRestrictDiagnostics();
1693
- const common = {
1694
- accVersion: ACC_VERSION,
1695
- dshVersion: readDshVersion(),
1696
- nodeVersion: process.version
1697
- };
1698
- if (!root) return {
1699
- root: null,
1700
- ...common,
1701
- safeModeOn: false,
1702
- blacklist: [],
1703
- threshold: null,
1704
- trajectories: [],
1705
- skills: [],
1706
- restrict
1707
- };
1708
- const cfg = loadSerenityConfig(root, configPaths);
1709
- return {
1710
- root,
1711
- ...common,
1712
- safeModeOn: isSafeModeOn(root),
1713
- blacklist: readBlacklist(root, configPaths),
1714
- threshold: cfg.sessionKeeper?.threshold ?? null,
1715
- trajectories: listActiveTrajectories(root),
1716
- skills: listSkillSummaries(root),
1717
- restrict
1718
- };
1719
- }
1720
- /**
1721
- * 技能清单(面板用;owner 2026-10-18 要求 skills 单独占一个 panel)。
1722
- *
1723
- * 只取**两个可文件系统验证的事实**:名字(目录名)+ 是否已建模(`skill.ttl` 存在)。
1724
- * 为什么"是否建模"值得进面板:它是 skill 形态的**唯一二值区别**(有 `skill.ttl` = 增强型,
1725
- * 无 = 普通 skill),而后者**完全正常** —— 所以面板把它呈现为**信息**,不是缺陷标记。
1726
- *
1727
- * ⚠️ 单目录读失败**不抛**(`loadOpencodeSkill` 返回 null 时照旧收入名字):
1728
- * 面板是只读状态面,一个坏目录不该让整块面板消失。
1729
- */
1730
- function listSkillSummaries(root) {
1731
- const out = [];
1732
- for (const dir of listOpencodeSkillDirs(root)) {
1733
- const name = basename(dir);
1734
- out.push({
1735
- name,
1736
- modeled: existsSync(join(dir, "skill.ttl"))
1737
- });
1738
- }
1739
- return out.sort((a, b) => a.name.localeCompare(b.name));
1740
- }
1741
- /** 切换安全模式(写/删标记文件);返回实际生效状态 */
1742
- function setSafeMode(root, on) {
1743
- const marker = resolve(root, SAFE_MODE_MARKER);
1744
- if (on) {
1745
- if (!existsSync(marker)) writeFileSync(marker, isoLocal() + "\n", "utf-8");
1746
- } else rmSync(marker, { force: true });
1747
- return { on: isSafeModeOn(root) };
1748
- }
1749
- //#endregion
1750
1568
  //#region src/host/contract.ts
1751
1569
  /** dsp 依赖的宿主服务与成员(对照 `_tmp/host-0.1.5-rc.1/`(`dsh-develop host-fetch` 产物)逐一核对) */
1752
1570
  const HOST_SERVICES = [
@@ -2216,4 +2034,199 @@ function summarizeHostContract(report) {
2216
2034
  return `${required.length > 0 ? `host contract BROKEN (${required.length} required)` : `host contract degraded (${optional.length} optional)`}: ${report.issues.map((i) => i.detail).join("; ")}`;
2217
2035
  }
2218
2036
  //#endregion
2219
- export { docsPointer as C, runMsmAsync as S, CCC_CONFIG_REFERENCE as _, setSafeMode as a, loadMsmEntries as b, forgetExclusiveToolsVisibility as c, forgetNonCccToolVisibility as d, forgetTrajectoryConstraintToolVisibility as f, ACC_CATALOG as g, forgetToolVisibility as h, readDshVersion as i, forgetHostScheduleToolHiding as l, syncToolVisibility as m, summarizeHostContract as n, listOpencodeSkillDirs as o, registerGuards as p, getStatus as r, loadOpencodeSkill as s, hostContractReport as t, forgetImBridgeVisibility as u, checkRegistryQuality as v, setWeixinSendEndpoint as w, runMsm as x, findEntry as y };
2037
+ //#region src/skills/opencode-scan.ts
2038
+ /**
2039
+ * opencode-scan.ts — opencode skill 标准扫描(纯逻辑,零 DSH 依赖)
2040
+ *
2041
+ * 兼容 opencode 的 skill 标准:`.opencode/skills/<name>/SKILL.md`
2042
+ * (frontmatter: name/description/whenToUse;结构含 references/、scripts/)。
2043
+ */
2044
+ /** 解析 --- 分隔的 YAML frontmatter(只需 name/description/whenToUse) */
2045
+ function parseFrontmatter(raw) {
2046
+ const text = raw.replace(/^\uFEFF/, "");
2047
+ const m = /^---\s*\n([\s\S]*?)\n---\s*\n?/.exec(text);
2048
+ if (!m) return {
2049
+ meta: {
2050
+ name: "",
2051
+ description: ""
2052
+ },
2053
+ content: text
2054
+ };
2055
+ const fm = m[1];
2056
+ const body = text.slice(m[0].length);
2057
+ const grab = (key) => {
2058
+ const line = fm.split("\n").find((l) => l.startsWith(`${key}:`));
2059
+ if (!line) return void 0;
2060
+ return line.slice(key.length + 1).trim().replace(/^['"]|['"]$/g, "");
2061
+ };
2062
+ const meta = {
2063
+ name: grab("name") ?? "",
2064
+ description: grab("description") ?? ""
2065
+ };
2066
+ const whenToUse = grab("whenToUse");
2067
+ if (whenToUse) meta.whenToUse = whenToUse;
2068
+ return {
2069
+ meta,
2070
+ content: body
2071
+ };
2072
+ }
2073
+ /** 扫描 CCC 的 .opencode/skills(一级目录 + SKILL.md 存在性) */
2074
+ function listOpencodeSkillDirs(root) {
2075
+ const dir = join(root, ".opencode", "skills");
2076
+ if (!existsSync(dir)) return [];
2077
+ return readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join(dir, e.name)).filter((d) => existsSync(join(d, "SKILL.md")));
2078
+ }
2079
+ /** 加载一个 opencode skill(frontmatter 解析 + 正文);读失败(EPERM/占用等)返回 null,单目录容错 */
2080
+ function loadOpencodeSkill(skillDir) {
2081
+ let raw;
2082
+ try {
2083
+ raw = readFileSync(join(skillDir, "SKILL.md"), "utf-8");
2084
+ } catch {
2085
+ return null;
2086
+ }
2087
+ const { meta, content } = parseFrontmatter(raw);
2088
+ return {
2089
+ name: meta.name,
2090
+ dir: skillDir,
2091
+ meta,
2092
+ content,
2093
+ path: join(skillDir, "SKILL.md")
2094
+ };
2095
+ }
2096
+ //#endregion
2097
+ //#region src/surface/status.ts
2098
+ /**
2099
+ * surface/status.ts — 状态与安全模式操作(纯逻辑,零 DSH 依赖,可独立单测)
2100
+ *
2101
+ * WebUI 停靠栏的数据源:ACC 版本 / CCC 根 / safe-mode 状态 / 黑名单 / keeper 阈值。
2102
+ * setSafeMode 直接读写 .serenity-safe-on 标记(守卫实时读取,写即生效)。
2103
+ */
2104
+ /** 宿主包名 —— 从运行入口反推包根时的**身份核对**用(见 {@link dshVersionFromEntry}) */
2105
+ const HOST_PACKAGE_NAME = "@deepseek-ai/dsh";
2106
+ /** 上溯层数上限:入口脚本在包内的深度是 `lib/`(1 层)或 `lib/x/y/`(≤3 层)⇒ 6 层足够,且**保证有界** */
2107
+ const MAX_ENTRY_ASCENT = 6;
2108
+ /**
2109
+ * 🔴 **布局无关档**:从**正在跑的那个入口脚本**反推宿主包根,读它的 `version`。
2110
+ *
2111
+ * 为什么必须补这一档(R↓:一处**静默失效**的实际缺陷;2026-09-28 docker bench 实测):
2112
+ * 下面那条静态候选链({@link readDshVersion} 的 ②)是**猜安装位置**——`npm_config_prefix` /
2113
+ * `APPDATA\npm` / `~/.npm-global`。一旦宿主装在**别处**(典型 = 容器镜像里的
2114
+ * `/usr/local/lib/node_modules/@deepseek-ai/dsh`),**三个候选全不中** ⇒ 返回 `null`
2115
+ * ⇒ `checkHostVersion(null)` 只给一条 **`required: false`** 的 issue ⇒ 报告 `ok` 仍为 `true`
2116
+ * ⇒ **版本门完全静默**(bench 逐字:`host contract degraded (1 optional): host version unknown`)。
2117
+ * ⚠️ 这类坏法**比"偶尔报警"更危险**:一条**永远为假**的判据看起来像"没报警 = 没问题"。
2118
+ *
2119
+ * 而"我们正跑在哪个宿主里"**本来就有直接证据**:`process.argv[1]`(= 启动本进程的那个脚本)。
2120
+ * 三条判据要点(每条都对应一个实测过的坑):
2121
+ * ① **先 `realpath`** —— 全局安装的 `dsh` 是**符号链接**(`/usr/local/bin/dsh` → `…/@deepseek-ai/dsh/lib/bin.js`),
2122
+ * 而 Node 的 `argv[1]` **保留调用路径、不解析符号链接** ⇒ 不 realpath 就永远上溯不到包根。
2123
+ * ② **核对包名**(`name === '@deepseek-ai/dsh'`)—— 否则在 vitest / npx 等入口下会误取**别人的**
2124
+ * `package.json`(这是本档**唯一**的假阳性来源)。
2125
+ * ③ **上溯有界**({@link MAX_ENTRY_ASCENT})—— 不设界的话,一个不在任何 dsh 包内的入口会一路爬到文件系统根。
2126
+ *
2127
+ * @param entry `process.argv[1]`(单测直接注入,无需替身)
2128
+ */
2129
+ function dshVersionFromEntry(entry) {
2130
+ if (typeof entry !== "string" || entry === "") return null;
2131
+ let dir;
2132
+ try {
2133
+ const real = realpathSync(entry);
2134
+ dir = statSync(real).isDirectory() ? real : dirname(real);
2135
+ } catch {
2136
+ return null;
2137
+ }
2138
+ for (let i = 0; i < MAX_ENTRY_ASCENT; i++) {
2139
+ try {
2140
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
2141
+ if (pkg.name === HOST_PACKAGE_NAME && typeof pkg.version === "string") return pkg.version;
2142
+ } catch {}
2143
+ const parent = dirname(dir);
2144
+ if (parent === dir) break;
2145
+ dir = parent;
2146
+ }
2147
+ return null;
2148
+ }
2149
+ /**
2150
+ * 读取已安装 DSH CLI 版本;读不到返回 null。
2151
+ *
2152
+ * **两档,顺序有理由**:
2153
+ * ① 🔴 **布局无关档**({@link dshVersionFromEntry})= **正在跑的就是它** —— 直接证据优先于"猜安装位置"。
2154
+ * ② **静态候选链**(跨平台历史档,保留):`npm_config_prefix` / `APPDATA\npm` / `~/.npm-global`
2155
+ * (Windows npm 全局装在 `%APPDATA%\npm`,见审计问题 13)。
2156
+ * ⚠️ 保留它是因为**本进程不一定是 dsh CLI**(单测、嵌入式、将来别的宿主进程)——
2157
+ * 那时"本机装了哪个版本"仍需一个答案,只是证据等级更低。
2158
+ */
2159
+ function readDshVersion() {
2160
+ const fromEntry = dshVersionFromEntry(process.argv[1]);
2161
+ if (fromEntry !== null) return fromEntry;
2162
+ const candidates = [];
2163
+ if (process.env.npm_config_prefix) candidates.push(join(process.env.npm_config_prefix, "lib", "node_modules", "@deepseek-ai", "dsh"));
2164
+ if (process.env.APPDATA) candidates.push(join(process.env.APPDATA, "npm", "node_modules", "@deepseek-ai", "dsh"));
2165
+ candidates.push(join(homedir(), ".npm-global", "lib", "node_modules", "@deepseek-ai", "dsh"));
2166
+ for (const p of candidates) try {
2167
+ const pkg = JSON.parse(readFileSync(join(p, "package.json"), "utf-8"));
2168
+ if (typeof pkg.version === "string") return pkg.version;
2169
+ } catch {}
2170
+ return null;
2171
+ }
2172
+ function getStatus(cwd, configPaths = DEFAULT_SERENITY_CONFIG_PATHS) {
2173
+ const root = cccRootForCwd(cwd);
2174
+ const restrict = getRestrictDiagnostics();
2175
+ const common = {
2176
+ accVersion: ACC_VERSION,
2177
+ dshVersion: readDshVersion(),
2178
+ nodeVersion: process.version
2179
+ };
2180
+ if (!root) return {
2181
+ root: null,
2182
+ ...common,
2183
+ safeModeOn: false,
2184
+ blacklist: [],
2185
+ threshold: null,
2186
+ trajectories: [],
2187
+ skills: [],
2188
+ restrict
2189
+ };
2190
+ const cfg = loadSerenityConfig(root, configPaths);
2191
+ return {
2192
+ root,
2193
+ ...common,
2194
+ safeModeOn: isSafeModeOn(root),
2195
+ blacklist: readBlacklist(root, configPaths),
2196
+ threshold: cfg.sessionKeeper?.threshold ?? null,
2197
+ trajectories: listActiveTrajectories(root),
2198
+ skills: listSkillSummaries(root),
2199
+ restrict
2200
+ };
2201
+ }
2202
+ /**
2203
+ * 技能清单(面板用;owner 2026-10-18 要求 skills 单独占一个 panel)。
2204
+ *
2205
+ * 只取**两个可文件系统验证的事实**:名字(目录名)+ 是否已建模(`skill.ttl` 存在)。
2206
+ * 为什么"是否建模"值得进面板:它是 skill 形态的**唯一二值区别**(有 `skill.ttl` = 增强型,
2207
+ * 无 = 普通 skill),而后者**完全正常** —— 所以面板把它呈现为**信息**,不是缺陷标记。
2208
+ *
2209
+ * ⚠️ 单目录读失败**不抛**(`loadOpencodeSkill` 返回 null 时照旧收入名字):
2210
+ * 面板是只读状态面,一个坏目录不该让整块面板消失。
2211
+ */
2212
+ function listSkillSummaries(root) {
2213
+ const out = [];
2214
+ for (const dir of listOpencodeSkillDirs(root)) {
2215
+ const name = basename(dir);
2216
+ out.push({
2217
+ name,
2218
+ modeled: existsSync(join(dir, "skill.ttl"))
2219
+ });
2220
+ }
2221
+ return out.sort((a, b) => a.name.localeCompare(b.name));
2222
+ }
2223
+ /** 切换安全模式(写/删标记文件);返回实际生效状态 */
2224
+ function setSafeMode(root, on) {
2225
+ const marker = resolve(root, SAFE_MODE_MARKER);
2226
+ if (on) {
2227
+ if (!existsSync(marker)) writeFileSync(marker, isoLocal() + "\n", "utf-8");
2228
+ } else rmSync(marker, { force: true });
2229
+ return { on: isSafeModeOn(root) };
2230
+ }
2231
+ //#endregion
2232
+ export { runMsmAsync as C, runMsm as S, setWeixinSendEndpoint as T, ACC_CATALOG as _, loadOpencodeSkill as a, findEntry as b, summarizeHostContract as c, forgetImBridgeVisibility as d, forgetNonCccToolVisibility as f, forgetToolVisibility as g, syncToolVisibility as h, listOpencodeSkillDirs as i, forgetExclusiveToolsVisibility as l, registerGuards as m, readDshVersion as n, compareSemver as o, forgetTrajectoryConstraintToolVisibility as p, setSafeMode as r, hostContractReport as s, getStatus as t, forgetHostScheduleToolHiding as u, CCC_CONFIG_REFERENCE as v, docsPointer as w, loadMsmEntries as x, checkRegistryQuality as y };
@@ -1,7 +1,7 @@
1
1
  import { r as cccRootForCwd } from "./ccc-roots-CsSSQjSS.js";
2
2
  import { m as readTrajectorySubscriptions } from "./ccc-x94FCzOv.js";
3
3
  import { L as localHuman, n as findTrajectoryHolding } from "./bind-file-B0TuOP89.js";
4
- import { f as registerDisposer } from "./scheduler-CUPz7geH.js";
4
+ import { p as registerDisposer } from "./scheduler-CMBAoYR8.js";
5
5
  //#region src/trajectory/subscriptions.ts
6
6
  /**
7
7
  * trajectory/subscriptions.ts — 轨迹消息订阅(v1.107.0,owner 2026-11-01 令)
@@ -306,7 +306,7 @@ function defaultSubscriptionDeps(ctx) {
306
306
  readSubs: (root) => readTrajectorySubscriptions(root),
307
307
  dirForSession: (root, sessionId) => findTrajectoryHolding(`${root}/AGENT_SESSIONS`, sessionId),
308
308
  deliver: async (root, target, message) => {
309
- const { sendToCognitiveTrajectory } = await import("./scheduler-CUPz7geH.js").then((n) => n.n);
309
+ const { sendToCognitiveTrajectory } = await import("./scheduler-CMBAoYR8.js").then((n) => n.r);
310
310
  const res = await sendToCognitiveTrajectory(ctx, root, target, message, "trajectory-subscription");
311
311
  return {
312
312
  ok: res.ok,