dsh-plugin-tool-management 0.21.8 → 0.22.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.
@@ -16,7 +16,7 @@
16
16
  // 刻意**不存**重启前的完整有效状态:那要求在阶段 1 之前把两张补丁全读一遍并存档,而恢复时
17
17
  // 一样要重新读一遍才敢写(磁盘上可能已经变了)。存快照只会多一处会过期的真相源 ——
18
18
  // 所以恢复走「重新算」(见 boot/reconcile.ts 的 reconcileMcpRestart)。
19
- import { readFileSync, renameSync } from 'node:fs';
19
+ import { readFileSync } from 'node:fs';
20
20
  import { mkdir, readFile, rm } from 'node:fs/promises';
21
21
  import { dirname } from 'node:path';
22
22
  import { writeFileAtomically } from '../memories/index-io.js';
@@ -82,13 +82,14 @@ export async function clearMcpRestartMarker() {
82
82
  await rm(mcpRestartMarkerPath(), { force: true }).catch(() => undefined);
83
83
  }
84
84
  /**
85
- * 进程是否还活着(同机)。
85
+ * 进程是否**可能**还活着(同机)。与 `hub-lock.ts` 里那把锁的判定方向相反(那边把非法
86
+ * pid 当没活,因为要允许抢锁),两处不能合并成一份实现。
86
87
  *
87
88
  * `pid <= 0`(老标记 / 读不出来)按**活着**处理 —— 那种情况下自动恢复才是最危险的分支
88
89
  * (可能在一次正常的重启中途插进去改补丁)。宁可漏一次自动恢复(用户手动重启即可),
89
90
  * 也不要在一个未知进程可能正持有写锁时动它的文件。
90
91
  */
91
- export function processAlive(pid) {
92
+ export function pidLikelyAlive(pid) {
92
93
  if (!Number.isInteger(pid) || pid <= 0)
93
94
  return true;
94
95
  try {
@@ -101,10 +102,3 @@ export function processAlive(pid) {
101
102
  return code === 'EPERM';
102
103
  }
103
104
  }
104
- /** 留一份坏标记便于事后核对(与索引隔离同思路)。 */
105
- export function quarantineMcpRestartMarker() {
106
- try {
107
- renameSync(mcpRestartMarkerPath(), `${mcpRestartMarkerPath()}.corrupt-${Date.now()}`);
108
- }
109
- catch { /* 没有就算了 */ }
110
- }
@@ -76,10 +76,6 @@ export function normalizeArchive(raw) {
76
76
  out.toolTablePreset = toolTablePreset;
77
77
  return out;
78
78
  }
79
- /** 档案里有没有写过这一段 —— 「没写过」与「写过但为空」语义不同。 */
80
- export function hasSection(archive, section) {
81
- return archive[section] !== undefined;
82
- }
83
79
  /**
84
80
  * MCP 段应用计划:段已定义 → 对并集里每台服务器产出**精确停用名单(勾选集的补集)**。
85
81
  * 服务器未勾(键缺失)→ ['*'] 整台停用(guard/restrict 原生支持通配,服务器后加载也会被拦);
@@ -18,7 +18,6 @@
18
18
  // 会话头里没有它。要拿得走 `ctx.workspaceRegistry` 线性查一遍(每个 step 一次)。
19
19
  // 「工作区隔离」因此以**会话头的 cwd** 为准(与下拉分组、工作区挂回同一口径),
20
20
  // 派生出的作用域键见 `scope/workspace-key.ts`;仍然不需要 workspaceId。
21
- import { nearestProjectRoot } from '../skills/skill-roots.js';
22
21
  import { isWorkspaceScopeKey, workspaceScopeKeyOf } from './workspace-key.js';
23
22
  /**
24
23
  * 见过的会话 cwd(工作区模式用)。
@@ -124,23 +123,6 @@ export function sessionScopeIdOf(agent) {
124
123
  current = up;
125
124
  }
126
125
  }
127
- /**
128
- * 会话的项目根(判据与官方一致:向上找最近的 `.git`,找不到就没有项目根)。
129
- *
130
- * 与 `skills/skill-roots.ts` 的 `nearestProjectRoot` 是**同一个函数**,不另写一份 ——
131
- * 项目技能根与项目 AGENTS.md 必须认同一个目录,否则"技能按 A 项目隔离、指令按 B 项目读"。
132
- */
133
- export async function projectRootOf(cwd) {
134
- if (cwd === undefined)
135
- return null;
136
- try {
137
- const found = await nearestProjectRoot(cwd);
138
- return found && found.root ? found.root : null;
139
- }
140
- catch {
141
- return null;
142
- }
143
- }
144
126
  // ── 工作区模式:把一个会话折叠到工作区作用域键 ──────────────────────
145
127
  /**
146
128
  * 一个**已知 cwd 的会话 id** → 当前模式下的作用域键(同步)。
@@ -69,8 +69,6 @@ export function clampPromptBaseline(text) {
69
69
  end -= 1;
70
70
  return bytes.subarray(0, end).toString('utf8');
71
71
  }
72
- /** 三种隔离粒度(界面与校验共用,顺序即界面顺序:从最粗到最细)。 */
73
- export const SCOPE_MODES = Object.freeze(['global', 'session', 'workspace']);
74
72
  /** 夹一个模式;不认识的按会话粒度。 */
75
73
  export function normalizeScopeMode(raw) {
76
74
  if (raw === 'global' || raw === 'workspace')
@@ -90,10 +88,6 @@ const MAX_RECORD_KEY_LENGTH = 1024;
90
88
  export function isFlagDomain(domain) {
91
89
  return typeof domain === 'string' && SCOPE_FLAG_DOMAINS.includes(domain);
92
90
  }
93
- /** 是不是覆盖域(含 `scene`)。 */
94
- export function isScopeDomain(domain) {
95
- return domain === 'scene' || isFlagDomain(domain);
96
- }
97
91
  /** 一个键能不能进覆盖表:非空、不超长、不含控制字符(键最终会进 JSON,不参与路径拼接)。 */
98
92
  function validKey(key) {
99
93
  // `__proto__` 会在普通对象上改原型而不是落一个自有属性 —— 侧车里出现它时按非法键丢弃。
@@ -20,7 +20,7 @@ import { isSameOrDescendant } from "../paths.js";
20
20
  // 回收站条目 id(与 hub / 记忆 / 人设 / 场景 / 提示词共用一个生成器)。不能引 `../hub.js` ——
21
21
  // 那边引了本文件的 resolveDshHome,引回去就是环;所以生成器放在 `../trash-id.js` 这一叶上。
22
22
  import { newTrashId } from "../trash-id.js";
23
- import { OFFICE_SKILL_NAMES, OFFICIAL_SOURCE_KEY, officialOfficeRuntimeSection, } from "./official.js";
23
+ import { OFFICIAL_SOURCE_KEY, officeKitApplies, officialOfficeRuntimeSection, } from "./official.js";
24
24
  import { parseSkillDoc, toKebab, unquote } from "./frontmatter.js";
25
25
  // 拆出去的公开函数照旧挂在 core.js 上(tools/skills.ts 引 toKebab,memories/* 与 ops/memory.ts
26
26
  // 引 parseSkillDoc / unquote,契约测试也按 lib/skills/core.js 取它们)。
@@ -1463,10 +1463,10 @@ export async function getProviderSkill(candidate, options = {}) {
1463
1463
  const summary = entryOf(locator.entryName, entry.kind, entry.docPath, doc);
1464
1464
  if (!summary.loadable || summary.declaredName !== candidate.name)
1465
1465
  return undefined;
1466
- // 官方 office 技能:补上官方 provider 在 get 时追加的 LibreOffice Kit 段
1467
- // (SKILL.md 明文引用这段的 node/cli 路径,见上方块注释)。
1468
- const officeRuntime = locator.rootKey === OFFICIAL_SOURCE_KEY &&
1469
- OFFICE_SKILL_NAMES.has(locator.entryName)
1466
+ // 官方 office 操作技能:补上官方 provider 在 get 时追加的 LibreOffice Kit 段
1467
+ // (SKILL.md 明文引用这段的 node/cli 路径,见上方块注释)。按正文判断而不是按技能名,
1468
+ // 官方增删 / 改名操作技能时不会漏挂。
1469
+ const officeRuntime = locator.rootKey === OFFICIAL_SOURCE_KEY && officeKitApplies(doc.body)
1470
1470
  ? officialOfficeRuntimeSection()
1471
1471
  : "";
1472
1472
  return {
@@ -1,5 +1,5 @@
1
1
  // 官方内置技能来源:把宿主随会话注入的内置技能物成本插件自有的真实目录(单技能可启停),
2
- // 并给出 Office 三件套那段「Installed LibreOffice Kit」运行时说明。
2
+ // 并给出 Office 操作技能那段「Installed LibreOffice Kit」运行时说明。
3
3
  //
4
4
  // 从 core.ts 整段搬来,一行未改。这一段是本插件里唯一直接摸宿主安装形态的代码
5
5
  // (resourcesDir / desktopPackageDir / resolvedPackageDir),单独成层后 core.ts 只管
@@ -9,15 +9,18 @@ import { createRequire } from "node:module";
9
9
  import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
10
10
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
11
11
  import { resolveDshHome } from "./homes.js";
12
+ import { clearRuntimeNote, noteRuntime } from "../compat/runtime-notes.js";
12
13
  // ── 官方内置技能来源(随宿主注入会话上下文的内置技能)──────────────────────
13
14
  //
14
15
  // 宿主按形态注入不同的官方技能(官方源码逐一核对):
15
- // - 桌面版 4 个:office-docx / office-pptx / office-xlsx(dsh-skill-office 只在桌面
16
- // 宿主装配,assetRoot 指到 `<resources>/runtime/office-skills`)+ diagnose-windows-
17
- // sandbox-acl(dsh-sandbox-local 的门控是 `process.platform === "win32"`,rank 600)。
16
+ // - 桌面版 8 个:office 路由 + office-docx / office-pptx / office-xlsx(创作)+
17
+ // office-render / office-recalculate / office-export-pdf(操作)(dsh-skill-office
18
+ // 只在桌面宿主装配,assetRoot 指到 `<resources>/runtime/office-skills`)+
19
+ // diagnose-windows-sandbox-acl(dsh-sandbox-local 的门控是
20
+ // `process.platform === "win32"`,rank 600)。
18
21
  // - web 版:沙盒诊断技能由宿主注入(门控只看 win32 —— 用户截图实锤,
19
22
  // 按「web 不注入」的误判把 web 挡在门外,会让页面不显示而宿主照注);office
20
- // 插件 web 宿主不装配、不注入,但用户要求技能页照样把这三个暴露出来
23
+ // 插件 web 宿主不装配、不注入,但用户要求技能页照样把这七个暴露出来
21
24
  // 统一管理(npm 包自带完整 assets,接管后可启停)。
22
25
  //
23
26
  // 它们或住在官方 asar 里、或由官方 provider 复制进临时目录自管,插件直接扫描/接管有两个
@@ -29,7 +32,7 @@ import { resolveDshHome } from "./homes.js";
29
32
  // 整目录覆盖拷贝(与官方 provider 的「私有资源副本」同一做法),扫描、启停、overlay、
30
33
  // 脚本执行全部落在真实文件上。599 压过宿主 provider 的 600,停用即不注入。分形态是竞态
31
34
  // 教训:原先共用一份目录,web 启动把它解析到的沙盒技能盖进去,桌面物化好的
32
- // 4 个只剩 1 个;改成各写各的子目录,互不清对方的账。共享布局的残留(旧条目
35
+ // 8 个只剩 1 个;改成各写各的子目录,互不清对方的账。共享布局的残留(旧条目
33
36
  // 直接躺在 official-skills/ 下)按已知名单清理。
34
37
  //
35
38
  // - 预设参考技能(dsh-agent-preset/skills)不注入会话上下文,不列入。
@@ -86,52 +89,82 @@ function resolvedPackageDir(packageName, subpath) {
86
89
  return null;
87
90
  }
88
91
  }
92
+ /**
93
+ * 目录里是否至少有一个带 SKILL.md 的技能子目录。
94
+ *
95
+ * 不点名校验 / 不比对固定清单:官方技能集合会变(新增 / 改名 / 重排),只要源还是
96
+ * 「子目录 + SKILL.md」这个形态就整目录接管;一个都没有说明这份源不完整,宁可返回
97
+ * false 让上层不列出,也不物化一份空壳。
98
+ */
99
+ function hasSkillDocs(dir) {
100
+ try {
101
+ return readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isDirectory() && existsSync(join(dir, entry.name, "SKILL.md")));
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
89
107
  /**
90
108
  * office 技能源头。桌面版由宿主挂载:运行时真实目录优先(官方 assetRoot),其次 asar
91
109
  * 包内 assets。web 宿主不装配 office 插件(不注入),但 npm 包自带完整 assets —— 用户
92
- * 要求技能页照样暴露这三个技能,走宿主进程解析链取包内一份。解析不到
110
+ * 要求技能页照样暴露这些技能,走宿主进程解析链取包内一份。解析不到
93
111
  * 一律 null —— 不把拿不到真实文件的技能凭空列出来。
94
112
  */
95
113
  function officialOfficeSource() {
114
+ // 桌面壳通过 DSH_BUNDLED_OFFICE_SKILLS 指定宿主实际使用的 assets 根,照抄最稳。
115
+ const bundled = process.env.DSH_BUNDLED_OFFICE_SKILLS;
116
+ if (bundled !== undefined && bundled !== "" && hasSkillDocs(bundled))
117
+ return bundled;
96
118
  const resources = resourcesDir();
97
119
  if (resources !== null) {
98
120
  const runtimeDir = join(resources, "runtime", "office-skills");
99
- if (existsSync(join(runtimeDir, "office-docx")))
121
+ if (hasSkillDocs(runtimeDir))
100
122
  return runtimeDir;
101
123
  const asarDir = desktopPackageDir("@deepseek-ai/dsh-skill-office", "assets");
102
- if (asarDir !== null && existsSync(join(asarDir, "office-docx")))
124
+ if (asarDir !== null && hasSkillDocs(asarDir))
103
125
  return asarDir;
104
126
  }
105
- return resolvedPackageDir("@deepseek-ai/dsh-skill-office", "assets");
127
+ const resolved = resolvedPackageDir("@deepseek-ai/dsh-skill-office", "assets");
128
+ return resolved !== null && hasSkillDocs(resolved) ? resolved : null;
106
129
  }
107
130
  /** 沙盒诊断技能源头(桌面 asar 直连优先,其次宿主进程解析链;宿主门控仅看 win32,web/桌面皆注入)。 */
108
131
  function officialSandboxSource() {
109
132
  if (process.platform !== "win32")
110
133
  return null;
111
- return (desktopPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl") ??
112
- resolvedPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl"));
134
+ const source = desktopPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl") ??
135
+ resolvedPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl");
136
+ return source !== null && existsSync(join(source, "SKILL.md")) ? source : null;
113
137
  }
114
138
  // ── office 技能的「Installed LibreOffice Kit」段 ────────────────────────────
115
139
  //
116
- // 官方 dsh-office provider 在 get 时给三个 office 技能的正文**追加**一段
117
- // 「Installed LibreOffice Kit」:SKILL.md 明文要求「使用这段提供的 libreofficeKit.node
118
- // 与 .cli 绝对路径,禁止自行搜索/猜测」。我们以 599 接管后官方 provider 不再被问到,
119
- // 这段必须由我们补上 —— 否则模型拿到的 office 技能缺执行 LibreOffice 命令所需的全部
120
- // 路径(这个缺口在桌面上本来就有)。文案与 JSON 形状逐字取自官方
140
+ // 官方 dsh-office provider 在 get 时只给三个**操作**技能(office-render /
141
+ // office-recalculate / office-export-pdf)的正文**追加**一段「Installed LibreOffice
142
+ // Kit」:SKILL.md 明文要求「使用这段提供的 libreofficeKit.node 与 .cli 绝对路径,
143
+ // 禁止自行搜索/猜测」。三个创作技能只产出 OOXML,不执行 LibreOffice 命令,官方不给它们
144
+ // 补段。我们以覆盖方式接管后官方 provider 不再被问到,这段必须由我们补上 ——
145
+ // 否则模型拿到的操作技能缺执行 LibreOffice 命令所需的全部路径。文案与 JSON 形状逐字取自官方
121
146
  // dsh-skill-office lib/index.js 的 officeRuntime();node/cli 的落点按宿主形态各自核实:
122
147
  // - 桌面:官方明确要求 packaged 应用必须给**独立 node**(electron 本体不行)。
123
- // 实测桌面把运行时装在 `<resources>/runtime/primary-runtime/`(DSH_PRIMARY_RUNTIME
124
- // 指向它,SDK 部署可被同名环境变量改写),node 在其 dependencies/node/bin 下;cli
125
- // 必须用 `app.asar.unpacked` 里的真实文件 —— 独立 node 读不了 asar 内部。
148
+ // 桌面壳通过 `DSH_BUNDLED_OFFICE_NODE` / `DSH_BUNDLED_OFFICE_CLI` 传真实路径
149
+ // (运行时装在 `<resources>/runtime/primary-runtime/`,node 在其 dependencies/node/bin
150
+ // 下;cli 在 `app.asar.unpacked` 里 —— 独立 node 读不了 asar 内部);变量缺席时才按
151
+ // 形态兜底。
126
152
  // - web:官方默认 process.execPath(宿主是普通 node 进程),cli 从宿主进程解析链取。
127
153
  // 任一路径不是真实文件 → 用官方口径的「已停用」文案(SKILL.md 自有降级分支,模型不会
128
154
  // 去猜路径),绝不给一个跑不起来的路径。
129
- /** 三个 office 技能的名字:get 时要为它们补官方 provider 追加的 LibreOffice Kit 段。 */
130
- export const OFFICE_SKILL_NAMES = new Set([
131
- "office-docx",
132
- "office-pptx",
133
- "office-xlsx",
134
- ]);
155
+ /**
156
+ * 一个官方技能是否需要补 LibreOffice Kit 段。
157
+ *
158
+ * 官方按写死的技能名单注入;照抄名单会在官方增删操作技能时静默漏挂或错挂。改看正文:
159
+ * 需要这段的技能自己会写明「使用下方提供的 Node / CLI 绝对路径」,正文里必然出现
160
+ * LibreOffice。三个创作技能不提它,操作技能都提 —— 官方换名字 / 加技能也照样命中。
161
+ *
162
+ * @param body SKILL.md 正文(frontmatter 之后)
163
+ * @returns 正文提到 LibreOffice 时为 true
164
+ */
165
+ export function officeKitApplies(body) {
166
+ return /\blibreoffice\b/iu.test(body);
167
+ }
135
168
  const OFFICE_RUNTIME_DISABLED = "\n\nLibreOffice Kit is disabled in this deployment.";
136
169
  let officeRuntimeSectionCache;
137
170
  /** 官方 provider 在 get 时追加的 LibreOffice Kit 段(每进程算一次,路径不随会话变)。 */
@@ -141,21 +174,38 @@ export function officialOfficeRuntimeSection() {
141
174
  return officeRuntimeSectionCache;
142
175
  }
143
176
  function computeOfficeRuntimeSection() {
177
+ const env = process.env;
144
178
  const resources = resourcesDir();
179
+ const runtimeRoot = env.DSH_PRIMARY_RUNTIME || env.DSH_BUNDLED_PRIMARY_RUNTIME || "";
180
+ const nodeBin = join("bin", process.platform === "win32" ? "node.exe" : "node");
145
181
  let node;
146
182
  let cli;
147
- const runtimeRoot = process.env.DSH_PRIMARY_RUNTIME || process.env.DSH_BUNDLED_PRIMARY_RUNTIME;
148
- if (runtimeRoot) {
149
- // SDK / 容器部署:官方配置从运行时根推导(cordis 装配逐字核对)。
150
- node = join(resolve(runtimeRoot), "dependencies", "node", "bin", process.platform === "win32" ? "node.exe" : "node");
151
- cli = resolvedPackageDir("@deepseek-ai/libreoffice-kit", "lib/cli.js");
183
+ // 官方 provider 的路径来源就是这几个环境变量(cordis 装配逐字核对):桌面壳会把独立
184
+ // node 与 unpacked 的 cli 直接传进来。优先照抄,免得按形态猜错 —— 桌面上
185
+ // DSH_BUNDLED_PRIMARY_RUNTIME 也在,若只看它会从解析链拿到 asar 内部的 cli,
186
+ // 独立 node 读不了。
187
+ if (env.DSH_BUNDLED_OFFICE_CLI === "")
188
+ return OFFICE_RUNTIME_DISABLED;
189
+ if (env.DSH_BUNDLED_OFFICE_CLI !== undefined) {
190
+ cli = env.DSH_BUNDLED_OFFICE_CLI;
191
+ node =
192
+ env.DSH_BUNDLED_OFFICE_NODE ??
193
+ (runtimeRoot !== ""
194
+ ? join(resolve(runtimeRoot), "dependencies", "node", nodeBin)
195
+ : process.execPath);
152
196
  }
153
197
  else if (resources !== null) {
154
- node = join(resources, "runtime", "primary-runtime", "dependencies", "node", "bin", process.platform === "win32" ? "node.exe" : "node");
198
+ // 桌面兜底(壳未给 OFFICE_* 环境变量时):运行时装在 runtime/primary-runtime 下;
155
199
  // 桌面的 cli 只认 unpacked 真实文件(独立 node 读不了 asar;electron 的 fs 补丁
156
200
  // 会让 existsSync 对 asar 内部也返回真,所以这里不用解析链兜底)。
201
+ node = join(resources, "runtime", "primary-runtime", "dependencies", "node", nodeBin);
157
202
  cli = join(resources, "app.asar.unpacked", "dsh", "node_modules", "@deepseek-ai", "libreoffice-kit", "lib", "cli.js");
158
203
  }
204
+ else if (runtimeRoot !== "") {
205
+ // SDK / 容器部署:官方配置从运行时根推导(cordis 装配逐字核对)。
206
+ node = join(resolve(runtimeRoot), "dependencies", "node", nodeBin);
207
+ cli = resolvedPackageDir("@deepseek-ai/libreoffice-kit", "lib/cli.js");
208
+ }
159
209
  else {
160
210
  node = process.execPath;
161
211
  cli = resolvedPackageDir("@deepseek-ai/libreoffice-kit", "lib/cli.js");
@@ -168,8 +218,21 @@ function computeOfficeRuntimeSection() {
168
218
  return false;
169
219
  }
170
220
  };
171
- if (!usable(node) || cli === null || !usable(cli))
221
+ if (!usable(node) || cli === null || !usable(cli)) {
222
+ // 可用的路径不存在时不把跑不起来的路径写进正文;同时留一条界面可见的降级,
223
+ // 否则用户只会看到技能「少了那段说明」,不知道该修哪。
224
+ noteRuntime({
225
+ id: "office-kit",
226
+ label: "LibreOffice Kit 路径",
227
+ kind: "read",
228
+ fallback: "inform-only",
229
+ detail: "未找到可用的独立 Node 或 LibreOffice CLI,office 操作技能本轮使用官方的「已停用」文案。请检查 DSH 安装的 runtime 是否完整。",
230
+ detailKey: "office-kit",
231
+ params: { node, cli: cli ?? "" },
232
+ });
172
233
  return OFFICE_RUNTIME_DISABLED;
234
+ }
235
+ clearRuntimeNote("office-kit");
173
236
  return `\n\n## Installed LibreOffice Kit\n\nUse these absolute paths for every LibreOffice Kit command. Pass the CLI entry as the first argument to Node.\n\n${JSON.stringify({ libreofficeKit: { node, cli } }, null, 2)}`;
174
237
  }
175
238
  function copyDirectorySync(from, to) {
@@ -254,15 +317,12 @@ export function officialSkillRoot() {
254
317
  localeKey: "official",
255
318
  mutable: false,
256
319
  deletable: false,
257
- // 来源层无开关(同默认来源),单个技能可启停;overlay 以 599 压过官方
258
- // provider 的 600,脚本从物化副本的真实路径执行。
320
+ // 来源层无开关(同默认来源),单个技能可启停;脚本从物化副本的真实路径执行。
259
321
  //
260
- // 残余风险:`599` 是个**数字契约** ——
261
- // 它只在"官方那个 provider 的 rank 恰好是 600"时成立。官方调档位(把内置技能提到
262
- // 599 以上、或降到 599 以下)会让接管失效:要么官方内置技能重新注入、与 599 层并存
263
- // (同名两份),要么本插件反向遮蔽掉本不该遮蔽的东西。rank 是纯数字、没有能力探测
264
- // 能提前发现,doctor 也查不了(要枚举官方 provider 的注册参数)。所以记为**已知
265
- // 假设**,列进 CHANGELOG 的宿主适配矩阵,官方更新时人工核对这一处。
322
+ // rank 只决定**本 provider 内部**同名候选的先后(官方 599 排在 hub / dsh / agents
323
+ // 之后,被用户自己的同名技能盖住)。对宿主官方 provider 的接管不靠数字:
324
+ // 全局层由宿主自己提供官方技能,我们只在每个 agent 的 scoped 层里注册同一份候选,
325
+ // 层优先级「最近一层胜出」直接压过全局层 —— 官方改 rank 常量不会让接管失效。
266
326
  toggleable: true,
267
327
  native: false,
268
328
  scope: "user",
@@ -4,10 +4,19 @@
4
4
  // 从 skills/service.ts 整段搬来,一行未改。invalidators 由调用方注入,本层不持有状态 ——
5
5
  // 它是官方 provider 通道的使用方,不改官方包、也不 monkey-patch。
6
6
  import { getProviderSkill, listProviderCandidates } from './core.js';
7
+ import { OFFICIAL_SOURCE_KEY } from './official.js';
8
+ import { noteRuntime } from '../compat/runtime-notes.js';
7
9
  const PROVIDER_NAME = 'dsh-plugin-tool-management-external';
8
10
  const message = (e) => String((e && e.message) || e);
9
- /** manager provider:以 core 的候选/正文接口接管四个来源(含启停策略)。 */
10
- export function externalSkillProvider(control, invalidators) {
11
+ /**
12
+ * manager provider:以 core 的候选/正文接口接管四个外部来源(含启停策略)。
13
+ *
14
+ * @param scope `global` 时**不**返回官方内置技能的候选。那一家由宿主自己的 provider 在
15
+ * 全局层提供;我们在每个 agent 的 scoped 层里再注册一份,靠「最近一层胜出」接管它,
16
+ * 不再依赖数字 rank 与宿主内部常量对齐。全局层若也放一份同名候选,等于把 rank 假设
17
+ * 重新引回来 —— 官方改档位时接管会静默失效。
18
+ */
19
+ export function externalSkillProvider(control, invalidators, scope = 'agent') {
11
20
  if (control && typeof control.invalidate === 'function')
12
21
  invalidators.add(control.invalidate);
13
22
  if (control && control.signal && typeof control.signal.addEventListener === 'function') {
@@ -15,7 +24,12 @@ export function externalSkillProvider(control, invalidators) {
15
24
  }
16
25
  return {
17
26
  name: PROVIDER_NAME,
18
- list: async (options) => listProviderCandidates(options),
27
+ list: async (options) => {
28
+ const candidates = await listProviderCandidates(options);
29
+ return scope === 'global'
30
+ ? candidates.filter((candidate) => candidate?.locator?.rootKey !== OFFICIAL_SOURCE_KEY)
31
+ : candidates;
32
+ },
19
33
  get: async (candidate, options) => getProviderSkill(candidate, options),
20
34
  };
21
35
  }
@@ -43,11 +57,22 @@ export function registerAgentSkillProviders(ctx, invalidators) {
43
57
  if (!skills)
44
58
  return;
45
59
  try {
46
- const dispose = skills.registerProvider((control) => externalSkillProvider(control, invalidators));
60
+ const dispose = skills.registerProvider((control) => externalSkillProvider(control, invalidators, 'agent'));
47
61
  registrations.set(agent.id, typeof dispose === 'function' ? dispose : () => { });
48
62
  }
49
63
  catch (e) {
50
- console.error('[dsh-plugin-tool-management] agent-scoped skills provider registration failed:', message(e));
64
+ console.error('[dsh-plugin-tool-management] agent-scoped skills provider setup failed:', message(e));
65
+ // 这一层没挂上时,官方内置技能仍由宿主注入,但我们的启停不再生效 ——
66
+ // 界面上看不出差别,留一条降级让兼容页说清。
67
+ noteRuntime({
68
+ id: 'skills-agent-provider',
69
+ label: '技能作用域接管',
70
+ kind: 'read',
71
+ fallback: 'inform-only',
72
+ detail: 'agent 作用域的技能 provider 未挂上(' + message(e) + '):官方内置技能这一轮由宿主直接注入,启停开关不生效。',
73
+ detailKey: 'skills-agent-provider',
74
+ params: { reason: message(e) },
75
+ });
51
76
  }
52
77
  };
53
78
  const uninstall = (agent) => {
@@ -136,8 +136,13 @@ export function pluginLog() {
136
136
  /** 技能域服务门面:来源枚举、清单扫描、启停与新建 / 更新。 */
137
137
  export function createSkillsService(ctx) {
138
138
  const log = pluginLog();
139
- const roots = userRoots();
140
- const rootByKey = Object.fromEntries(roots.map((root) => [root.key, root]));
139
+ // 根系**按需推导**:`userRoots()` 会物化官方内置技能(同步拷贝宿主安装里的文件)。
140
+ // 放在构造期等于让宿主启动路径去读宿主目录;首次取用(列技能、装 watcher、越界校验)
141
+ // 时再算,失败也不影响宿主启动。
142
+ let rootsCache = null;
143
+ const roots = () => (rootsCache ??= userRoots());
144
+ let rootByKeyCache = null;
145
+ const rootByKey = () => (rootByKeyCache ??= Object.fromEntries(roots().map((root) => [root.key, root])));
141
146
  /** op 入参里的 `sessionId`(空串 / 非字符串 → undefined = 全局口径)。 */
142
147
  const sessionIdOfArgs = (args) => {
143
148
  const raw = args && typeof args.sessionId === 'string' ? args.sessionId.trim() : '';
@@ -159,8 +164,9 @@ export function createSkillsService(ctx) {
159
164
  return { projectCwds: own === null ? activeSessionCwds(ctx) : own };
160
165
  };
161
166
  const requestRoot = async (key) => {
162
- if (rootByKey[key])
163
- return rootByKey[key];
167
+ const known = rootByKey();
168
+ if (known[key])
169
+ return known[key];
164
170
  // 自定义来源不在静态 root 表里:从状态文件的 customRoots 解析 definition。
165
171
  try {
166
172
  const policy = await readManagerState();
@@ -302,7 +308,7 @@ export function createSkillsService(ctx) {
302
308
  disposers.push(dispose);
303
309
  };
304
310
  try {
305
- const dispose = ctx.skills.registerProvider((control) => externalSkillProvider(control, providerInvalidators));
311
+ const dispose = ctx.skills.registerProvider((control) => externalSkillProvider(control, providerInvalidators, 'global'));
306
312
  if (typeof dispose === 'function')
307
313
  add(dispose);
308
314
  }
@@ -315,8 +321,13 @@ export function createSkillsService(ctx) {
315
321
  catch (e) {
316
322
  console.error('[dsh-plugin-tool-management] agent-scoped provider setup failed:', message(e));
317
323
  }
318
- try {
319
- const watchPaths = roots
324
+ // 静态来源的 watcher 与状态文件都**推迟到装配之后**:`roots()` 会物化官方内置技能
325
+ // (同步拷贝宿主安装里的文件),apply 里调用等于让宿主启动路径读宿主目录。
326
+ void Promise.resolve()
327
+ .then(() => {
328
+ if (disposed)
329
+ return null;
330
+ const watchPaths = roots()
320
331
  // 官方内置来源是宿主启动时物化的只读副本,不会中途变化,不起 watcher。
321
332
  .filter((root) => root.key !== 'official')
322
333
  .map((root) => String((root && root.path) || ''))
@@ -324,19 +335,20 @@ export function createSkillsService(ctx) {
324
335
  add(watchDirectories(watchPaths, invalidateSkills));
325
336
  // 自定义目录在状态文件里,注册时读取一次并一并监听(后添加的目录由
326
337
  // provider 首次 list 天然覆盖,等插件重载后才有 watcher)。
327
- readManagerState()
328
- .then((current) => {
329
- const customPaths = customRootsFromState(current.state)
330
- .map((root) => String((root && root.path) || ''))
331
- .filter(Boolean);
332
- if (customPaths.length)
333
- add(watchDirectories(customPaths, invalidateSkills));
334
- })
335
- .catch(() => { });
336
- }
337
- catch (e) {
338
+ return readManagerState();
339
+ })
340
+ .then((current) => {
341
+ if (current === null)
342
+ return;
343
+ const customPaths = customRootsFromState(current.state)
344
+ .map((root) => String((root && root.path) || ''))
345
+ .filter(Boolean);
346
+ if (customPaths.length)
347
+ add(watchDirectories(customPaths, invalidateSkills));
348
+ })
349
+ .catch((e) => {
338
350
  console.error('[dsh-plugin-tool-management] skill watcher setup failed:', message(e));
339
- }
351
+ });
340
352
  return () => {
341
353
  disposed = true;
342
354
  for (const dispose of disposers) {
@@ -560,7 +572,7 @@ export function createSkillsService(ctx) {
560
572
  * 静态根(`userRoots`)+ 状态文件里的自定义根 + 当前活动工作区的项目来源。
561
573
  */
562
574
  async function isInsideKnownSkillRoot(abs) {
563
- const dirs = roots.map((r) => String((r && r.path) || '')).filter(Boolean);
575
+ const dirs = roots().map((r) => String((r && r.path) || '')).filter(Boolean);
564
576
  try {
565
577
  for (const r of customRootsFromState((await readManagerState()).state)) {
566
578
  if (r && r.path)
@@ -9,6 +9,7 @@
9
9
  // 运行侧不碰人设清单的那份缓存(`cache` / `enabledCache` 都在 service.ts 那一层),
10
10
  // 所以它只需要 ctx / req / message 三件。
11
11
  import { randomUUID } from 'node:crypto';
12
+ import { EXPECTED_MIN_HOST_VERSION } from '../compat/probe.js';
12
13
  import { emptyResultNote, renderPersonaPrompt, RESULT_MAX, textOfBlocks, } from './persona-parse.js';
13
14
  import { childPresetDefinition } from './child-preset.js';
14
15
  // 拆出四层后 subagents/service.js 的公开面照旧(index.ts、ops/sessions.ts、scenes/candidates.ts、
@@ -37,7 +38,8 @@ export function createRunProvider(deps) {
37
38
  async function ensureProvider(kind) {
38
39
  const runtime = deps.ctx.get?.('subagents');
39
40
  if (!runtime || typeof runtime.startActivation !== 'function') {
40
- throw new Error('the subagent service is not mounted or lacks startActivation (ctx.subagents is missing; check that DSH is >= 0.2.1-rc.2)');
41
+ throw new Error('the subagent service is not mounted or lacks startActivation '
42
+ + `(ctx.subagents is missing; check that DSH is >= ${EXPECTED_MIN_HOST_VERSION})`);
41
43
  }
42
44
  if (hasProvider(runtime, kind))
43
45
  return runtime;
@@ -5,6 +5,7 @@
5
5
  // (先读一次 `skill-state`)。改的分支走新加的 `skill-update` op,它只认本插件可写的两个根
6
6
  // (hub = 导入落点 / dsh = 新建默认落点)里的胜出者。
7
7
  import { toKebab } from '../skills/core.js';
8
+ import { OFFICIAL_SOURCE_KEY, officeKitApplies, officialOfficeRuntimeSection } from '../skills/official.js';
8
9
  import { effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
9
10
  /** 注册技能域的 model 工具(列表 / 启停 / 新建或更新)。 */
10
11
  export function buildSkillTools(deps) {
@@ -242,7 +243,13 @@ export function buildSkillTools(deps) {
242
243
  // 注入边界:正文读进来就永久留在这一轮的 transcript 里,压制型预设下目录也可能不在 ——
243
244
  // 与 skill_manager_list 同一句说明,别让模型以为"读过就等于技能开着"。
244
245
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
245
- return header + String(detail.body || '').trim() + notice;
246
+ // 官方 office 操作技能:provider 的 get 会补 LibreOffice Kit 段,这里读到的正文
247
+ // 必须与真正注入的一致,否则模型按少了 node/cli 路径的正文去猜。判据同 get:看正文。
248
+ const body = String(detail.body || '');
249
+ const officeRuntime = picked.rootKey === OFFICIAL_SOURCE_KEY && officeKitApplies(body)
250
+ ? officialOfficeRuntimeSection()
251
+ : '';
252
+ return header + body.trim() + officeRuntime + notice;
246
253
  },
247
254
  }));
248
255
  register(defineTool({
@@ -24,8 +24,6 @@ export const UPDATE_CHECK_FILE = 'update-check.json';
24
24
  export const PACKAGE_NAME = 'dsh-plugin-tool-management';
25
25
  /** npm 官方 registry:没有宿主登记时的唯一来源,也是单源回退的默认值。 */
26
26
  const DEFAULT_REGISTRY = 'https://registry.npmjs.org/';
27
- /** npm registry 的元数据地址(单源回退时使用)。 */
28
- export const REGISTRY_URL = DEFAULT_REGISTRY + PACKAGE_NAME;
29
27
  /** 公网源集合:宿主测速只覆盖这两个,只有它们能被测速结果提到最前。 */
30
28
  const PUBLIC_REGISTRIES = new Set([DEFAULT_REGISTRY, 'https://registry.npmmirror.com/']);
31
29
  /**