dsh-plugin-tool-management 0.21.2 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CHANGELOG.md +38 -1
  2. package/README.md +1 -1
  3. package/README_EN.md +1 -1
  4. package/docs/{update.md → UPDATE.md} +34 -33
  5. package/lib/approval-policy.js +2 -2
  6. package/lib/audit-log.js +1 -1
  7. package/lib/boot/reconcile.js +3 -3
  8. package/lib/client.js +12 -1
  9. package/lib/compat/capability-specs.js +13 -17
  10. package/lib/compat/host-contracts.js +2 -0
  11. package/lib/compat/host-probe.js +35 -38
  12. package/lib/compat/host-roots.js +86 -15
  13. package/lib/compat/preset-reach.js +75 -102
  14. package/lib/compat/probe.js +68 -117
  15. package/lib/compat/runtime-notes.js +1 -1
  16. package/lib/context-inject-contract.js +6 -5
  17. package/lib/context-inject-frame.js +113 -53
  18. package/lib/context-inject-select.js +13 -14
  19. package/lib/context-inject-surface.js +5 -3
  20. package/lib/context-inject.js +58 -44
  21. package/lib/desktop-cookie-prune.js +95 -0
  22. package/lib/diagnostics.js +3 -1
  23. package/lib/exports/transcript.js +4 -4
  24. package/lib/host-names.js +6 -6
  25. package/lib/http-api.js +35 -26
  26. package/lib/http-fence.js +6 -6
  27. package/lib/hub.js +12 -13
  28. package/lib/imports/parsers.js +25 -21
  29. package/lib/imports/upload.js +5 -1
  30. package/lib/index.js +238 -231
  31. package/lib/mcp/disabled-tools.js +1 -0
  32. package/lib/mcp/loader-token.js +4 -4
  33. package/lib/mcp/manager.js +93 -114
  34. package/lib/mcp/override-blocks.js +1 -1
  35. package/lib/mcp/patch-yaml.js +42 -31
  36. package/lib/mcp/restart-marker.js +1 -1
  37. package/lib/mcp/secret-guard.js +6 -6
  38. package/lib/mcp/state-section.js +110 -69
  39. package/lib/mcp/tool-visibility.js +21 -22
  40. package/lib/memories/archive-engine.js +29 -29
  41. package/lib/memories/archive.js +23 -3
  42. package/lib/memories/constants.js +40 -127
  43. package/lib/memories/discovery.js +11 -2
  44. package/lib/memories/index-io.js +26 -20
  45. package/lib/memories/projection.js +18 -19
  46. package/lib/memories/prompt-layer.js +3 -2
  47. package/lib/memories/service.js +41 -38
  48. package/lib/memories/snapshot.js +37 -29
  49. package/lib/op-registry.js +33 -17
  50. package/lib/ops/candidates.js +3 -2
  51. package/lib/ops/compat.js +10 -9
  52. package/lib/ops/ctx.js +1 -1
  53. package/lib/ops/memory.js +18 -18
  54. package/lib/ops/prompts.js +8 -8
  55. package/lib/ops/quick-prompts.js +1 -0
  56. package/lib/ops/scene-records.js +23 -24
  57. package/lib/ops/scene-sync.js +8 -7
  58. package/lib/ops/scope.js +31 -30
  59. package/lib/ops/sessions.js +10 -9
  60. package/lib/ops/snapshot.js +10 -9
  61. package/lib/ops/state-doctor.js +6 -6
  62. package/lib/ops/trash-retention.js +2 -1
  63. package/lib/ops/trash.js +6 -6
  64. package/lib/prompts/preset-id.js +1 -1
  65. package/lib/prompts/project-instructions.js +3 -3
  66. package/lib/prompts/quick-service.js +1 -0
  67. package/lib/prompts/service.js +13 -12
  68. package/lib/request-gate.js +26 -25
  69. package/lib/scene-linkage.js +6 -5
  70. package/lib/scene-prompt-sync.js +10 -9
  71. package/lib/scene-settings.js +1 -0
  72. package/lib/scenes/candidates.js +9 -10
  73. package/lib/scope/intent-store.js +1 -0
  74. package/lib/scope/intent.js +10 -10
  75. package/lib/scope/resolve.js +6 -6
  76. package/lib/scope/scope-overrides.js +17 -17
  77. package/lib/scope/store.js +1 -0
  78. package/lib/sessions/archive-schemas.js +9 -0
  79. package/lib/sessions/bridge.js +42 -56
  80. package/lib/sessions/history.js +6 -7
  81. package/lib/sessions/workspace.js +21 -23
  82. package/lib/settings-sidecars.js +1 -0
  83. package/lib/sidebar-settings.js +1 -0
  84. package/lib/skills/catalog.js +9 -10
  85. package/lib/skills/core-util.js +5 -0
  86. package/lib/skills/core.js +35 -22
  87. package/lib/skills/frontmatter.js +26 -14
  88. package/lib/skills/homes.js +2 -0
  89. package/lib/skills/import-pipeline.js +8 -1
  90. package/lib/skills/manager-state.js +30 -6
  91. package/lib/skills/official.js +14 -11
  92. package/lib/skills/readonly-discovery.js +1 -0
  93. package/lib/skills/service.js +19 -18
  94. package/lib/skills/skill-roots.js +25 -7
  95. package/lib/skills/skill-trash.js +14 -3
  96. package/lib/skills/system-trash.js +3 -1
  97. package/lib/skills/upload-pipeline.js +19 -3
  98. package/lib/slash-settings.js +1 -0
  99. package/lib/stale-write.js +9 -1
  100. package/lib/subagents/catalog.js +5 -5
  101. package/lib/subagents/child-preset.js +7 -10
  102. package/lib/subagents/persona-parse.js +9 -8
  103. package/lib/subagents/persona-write.js +1 -1
  104. package/lib/subagents/run-provider.js +13 -15
  105. package/lib/subagents/service.js +13 -12
  106. package/lib/subagents/tool-filter.js +1 -1
  107. package/lib/subagents/tools.js +41 -39
  108. package/lib/token-config.js +9 -9
  109. package/lib/tool-table-switch.js +3 -2
  110. package/lib/tools/deps.js +33 -13
  111. package/lib/tools/mcp.js +62 -35
  112. package/lib/tools/memory.js +51 -36
  113. package/lib/tools/prompt.js +32 -20
  114. package/lib/tools/remove.js +12 -11
  115. package/lib/tools/scene.js +39 -36
  116. package/lib/tools/skills.js +44 -45
  117. package/lib/tools/subagent.js +21 -22
  118. package/lib/tools/table.js +21 -20
  119. package/lib/trash-id.js +3 -2
  120. package/lib/trash-retention.js +4 -5
  121. package/lib/update-check.js +5 -1
  122. package/package.json +3 -2
@@ -9,9 +9,10 @@ import { createRequire } from 'node:module';
9
9
  import { readFileSync, realpathSync } from 'node:fs';
10
10
  import { dirname, join } from 'node:path';
11
11
  import { fileURLToPath } from 'node:url';
12
+ /** `typeof` 的函数判定,带上类型收窄 —— 探针里到处要用,别各写一遍。 */
12
13
  export const isFn = (value) => typeof value === 'function';
13
14
  /**
14
- * Resolve a package the way this plugin resolves it, without throwing.
15
+ * 按本插件自己的方式解析一个包;解析不到返回 null,不抛错。
15
16
  *
16
17
  * `import.meta.resolve` 给的是**URL**:目录里带空格的路径(桌面版装在
17
18
  * `D:\DeepSeek Harness\...`)会以 `%20` 形式回来,直接当路径用会得到一个
@@ -32,7 +33,7 @@ export function safeResolve(specifier) {
32
33
  }
33
34
  }
34
35
  /**
35
- * Whether a path lives inside an electron `app.asar` archive.
36
+ * 路径是否落在 electron 的 `app.asar` 归档里。
36
37
  *
37
38
  * 桌面版把整个 DSH 装进 `resources/app.asar`:宿主的 `@deepseek-ai/*` 物理上就在
38
39
  * 归档里,插件(装在 `$DSH_HOME/profiles/<name>/node_modules`)在外面的磁盘上。
@@ -46,13 +47,13 @@ export function isAsarPath(value) {
46
47
  return /[\\/][^\\/]+\.asar[\\/]/i.test(value);
47
48
  }
48
49
  /**
49
- * Resolve a path through every junction/symlink to its physical file.
50
- * Node loads modules by real path, so two different-looking paths that
51
- * realpath to one file ARE the same module — which is exactly the property
52
- * this plugin depends on, and the reason `@deepseek-ai/*` is junctioned into
53
- * the host installation instead of being copied.
50
+ * 把路径穿过所有 junction / symlink 解析成物理文件。
54
51
  *
55
- * 取不到真实形态时**不再拿输入去比**(issue #1 要求):那会把「路径不可解析」
52
+ * node 按真实路径加载模块,所以两个长得不一样的路径只要 realpath 到同一个文件就是同一个
53
+ * 模块 —— 这正是本插件依赖的性质,也是 `@deepseek-ai/*` 用 junction 接进宿主安装、
54
+ * 而不是复制一份的原因。
55
+ *
56
+ * 取不到真实形态时**不再拿输入去比**:那会把「路径不可解析」
56
57
  * 伪装成「两份不同拷贝」,给出一个编出来的结论。改由调用方把原因报成说明。
57
58
  */
58
59
  export function realPathWithReason(value) {
@@ -68,7 +69,7 @@ export function realPathWithReason(value) {
68
69
  return { reason: code === '' ? message : `${code} ${message}` };
69
70
  }
70
71
  }
71
- /** Read a package version from a resolvable manifest. */
72
+ /** 从可解析的包清单里读版本号。 */
72
73
  export function versionOf(specifier) {
73
74
  const entry = safeResolve(specifier);
74
75
  if (entry === null)
@@ -81,7 +82,7 @@ export function versionOf(specifier) {
81
82
  return parsed.version;
82
83
  }
83
84
  catch {
84
- /* keep walking up */
85
+ /* 这一层没有就继续往上找 */
85
86
  }
86
87
  const parent = dirname(dir);
87
88
  if (parent === dir)
@@ -91,8 +92,8 @@ export function versionOf(specifier) {
91
92
  return undefined;
92
93
  }
93
94
  /**
94
- * Version of the package a resolved entry path belongs to: walk up until a
95
- * `package.json` whose `name` matches the package directory we came from.
95
+ * 一个已解析入口路径所属包的版本:向上找 `package.json`,直到 `name` 与入口所在的
96
+ * 包目录对得上。
96
97
  *
97
98
  * 与 `versionOf` 的分工:那个从**说明符**出发(要能解析),这个从**已经拿到的路径**
98
99
  * 出发。归档宿主那种「路径不同但版本相同」的判断只能用后者 —— 前者在 `.asar` 里
@@ -131,9 +132,9 @@ function packageNameOfPath(entry) {
131
132
  return first;
132
133
  }
133
134
  /**
134
- * Compare a live member with this plugin's copy of the implementation.
135
- * `undefined` means "not comparable" — the member is absent on the live object
136
- * or the reference copy does not have it either.
135
+ * 把活成员与本插件那份同实现做文本比对。
136
+ *
137
+ * `undefined` = 比不了:活对象上没有这个成员,或参考副本里也没有。
137
138
  */
138
139
  export function textMatchOf(live, reference) {
139
140
  if (!isFn(live) || !isFn(reference))
@@ -148,9 +149,7 @@ export function textMatchOf(live, reference) {
148
149
  }
149
150
  }
150
151
  /**
151
- * The prototype that defines a live instance's members, following the prototype
152
- * chain so proxies, subclass instances and cross-realm objects all answer
153
- * honestly.
152
+ * 定义活实例成员的那个原型。沿原型链走,代理、子类实例、跨 realm 对象都能问出真话。
154
153
  */
155
154
  function prototypeOf(instance) {
156
155
  if (instance === null || typeof instance !== 'object')
@@ -160,27 +159,24 @@ function prototypeOf(instance) {
160
159
  const proto = Object.getPrototypeOf(instance);
161
160
  return proto !== null && typeof proto === 'object' ? proto : undefined;
162
161
  }
163
- // The official package + class each capability owner's members live on. This is
164
- // the single answer to "which class defines this owner" — both the live
165
- // reference-prototype lookup below and the exported static table read it, so a
166
- // host drift is described in exactly one place.
162
+ // 每个能力属主的成员落在哪个官方包 / 类上 —— 「谁定义了这个属主」只在这里回答一次:
163
+ // 下面的活原型查找与对外的静态表都读它,宿主漂移因此只有一个描述处。
167
164
  const WORKSPACE_CLASS = { pkg: '@deepseek-ai/dsh-workspace', target: 'WorkspaceRegistry' };
168
165
  const PROJECTION_CLASS = { pkg: '@deepseek-ai/dsh-session-projection-cache', target: 'SessionProjectionCache' };
169
- // `sessions.*` members are host-private members, but they are still declared on
170
- // an official class: `@deepseek-ai/dsh-session` is a peer this plugin declares,
171
- // and `SessionStore` is where `flush`/`liveEntryFor`/`detachEntered`/`enter`/
172
- // `announce` live. Without this entry the doctor could not see the two
173
- // capabilities the delete route depends on.
166
+ // `sessions.*` 的成员虽然是宿主私有的,但仍声明在官方类上:`@deepseek-ai/dsh-session`
167
+ // 是本插件声明的 peer,`SessionStore` 就是 `flush` / `liveEntryFor` / `detachEntered` /
168
+ // `enter` / `announce` 的所在。少了这一条,doctor 看不见删除路线依赖的那两项能力。
174
169
  const SESSIONS_CLASS = { pkg: '@deepseek-ai/dsh-session', target: 'SessionStore' };
175
- // 0.15.0 新增的两块契约面 —— 恰是 0.1.7 升级咬人的两处(prepareDocument 返回语义变了、
176
- // read 改名 readDocument),此前不在表里,故障只能靠用户实测发现。类名按官方安装源码核对
177
- // (dsh-settings 导出 SettingsForms;dsh-agent-preset-registry 导出 AgentPresetRegistry)。
170
+ // 设置与预设名册两块契约面:类名按官方安装源码核对(dsh-settings 导出 SettingsForms;
171
+ // dsh-agent-preset-registry 导出 AgentPresetRegistry)。不在表里时,这两处契约一变
172
+ // (prepareDocument 返回语义、read 改名 readDocument)只能靠用户实测才发现。
178
173
  const SETTINGS_CLASS = { pkg: '@deepseek-ai/dsh-settings', target: 'SettingsForms' };
179
174
  const ROSTER_CLASS = { pkg: '@deepseek-ai/dsh-agent-preset-registry', target: 'AgentPresetRegistry' };
180
- // 0.2.1 的两块契约面(tools.restrict / connection.admit)也都声明在官方类上,所以同样接入
181
- // 「参考副本 + 文本比对」:官方改了实现,比对的结论从"一致"变成"漂移",界面上看得见。
175
+ // tools.restrict / connection.admit 也声明在官方类上,所以同样接入「参考副本 + 文本比对」:
176
+ // 官方改了实现,结论就从"一致"变成"漂移",界面上看得见。
182
177
  const TOOLS_CLASS = { pkg: '@deepseek-ai/dsh-tools', target: 'ToolRuntime' };
183
178
  const CONNECTION_CLASS = { pkg: '@deepseek-ai/dsh-client-connection', target: 'HostConnectionService' };
179
+ /** 每类宿主服务由哪个包的哪个导出承载 —— 静态检查要据此拿到官方原型。 */
184
180
  export const OWNER_CLASSES = {
185
181
  workspace: WORKSPACE_CLASS,
186
182
  projectionCache: PROJECTION_CLASS,
@@ -190,7 +186,7 @@ export const OWNER_CLASSES = {
190
186
  tools: TOOLS_CLASS,
191
187
  connection: CONNECTION_CLASS,
192
188
  };
193
- /** The named export's prototype, or undefined when the package is absent/trimmed. */
189
+ /** 具名导出的原型;包缺席或被裁剪时为 undefined。 */
194
190
  function classPrototypeOf(ref) {
195
191
  try {
196
192
  const mod = createRequire(import.meta.url)(ref.pkg);
@@ -208,12 +204,12 @@ function classPrototypeOf(ref) {
208
204
  */
209
205
  export const PROBE_SENTINEL = '__dshm_probe_never_exists__';
210
206
  /**
211
- * 用哨兵实参**真调**一个宿主方法(2026-09-19 分层探针第二层),验证「存在且可调用」:
207
+ * 用哨兵实参**真调**一个宿主方法(分层探针第二层),验证「存在且可调用」:
212
208
  * - 同步抛 `TypeError` → 实现坏了/签名漂移,返回失败详情(shape-mismatch);
213
209
  * - 受控同步拒绝(普通 `Error`,如 not found)或返回值(含 rejected Promise)→ 通过。
214
210
  *
215
211
  * 只判同步段:探针框架是同步的(`assessHost` 不能 await),异步结果分类留待
216
- * 异步化改造(见审查 07 跟进项)。返回的 Promise 一律挂 `.catch` 吞掉,探针
212
+ * 异步化改造。返回的 Promise 一律挂 `.catch` 吞掉,探针
217
213
  * 不制造 unhandled rejection。调用必须以 `target` 为 receiver —— 私有方法全靠
218
214
  * `this.*` 拿内部状态,脱离 receiver 调用会把好实现误判成 TypeError。
219
215
  *
@@ -241,7 +237,7 @@ export function callableWithSentinel(target, name, ...args) {
241
237
  return undefined;
242
238
  }
243
239
  }
244
- /** Official prototypes this plugin's adapters mirror, when importable. */
240
+ /** 官方原型:本插件的适配器照着它写,能 import 到才给。 */
245
241
  export function referencePrototypes() {
246
242
  const out = {};
247
243
  const workspace = classPrototypeOf(WORKSPACE_CLASS);
@@ -282,7 +278,7 @@ export function referencePrototypes() {
282
278
  * `node_modules` 里就没有 —— `safeResolve`/`classPrototypeOf` 一律取不到。运行时探测不看
283
279
  * 插件侧(它看的是 ctx 上的活服务),所以只有 doctor 这种"没有活宿主"的静态视图会被误导:
284
280
  * 它从插件锚点解析,解析不到就把一条**运行时确实存在**的能力记成 `missing`
285
- * (2026-10-17 `connection.admit` 就这么误报过:`dsh-client-connection` 不在插件依赖图里,
281
+ * (`connection.admit` 就这么误报过:`dsh-client-connection` 不在插件依赖图里,
286
282
  * 而它承载的 `admit()` 在 0.2.1 的 Web 组合里一定有)。
287
283
  *
288
284
  * 判据必须是宿主侧:逐个宿主安装锚点试着解析(纯 `require.resolve`,不 import),只要有
@@ -296,7 +292,7 @@ export function resolvableFromHost(specifier) {
296
292
  return true;
297
293
  }
298
294
  catch {
299
- /* try the next anchor */
295
+ /* 换下一个锚点再试 */
300
296
  }
301
297
  }
302
298
  return false;
@@ -315,6 +311,7 @@ function hostResolveAnchors() {
315
311
  // `hostRootCandidates()` 的注入点:由 probe.ts 在模块加载时填进来。不反向 import 是为了
316
312
  // 不成环(probe.ts → host-probe.ts → probe.ts),而"宿主在哪"的口径仍然只有一份。
317
313
  let hostRootCandidatesFn = () => [];
314
+ /** 注入「宿主根候选」的实现。放在这里是为了让 host-probe 不反向依赖 host-roots(避免循环引用)。 */
318
315
  export function provideHostRootCandidates(fn) {
319
316
  hostRootCandidatesFn = fn;
320
317
  }
@@ -1,17 +1,21 @@
1
1
  // 宿主安装根的发现与「该走哪条恢复路」的判定。
2
2
  //
3
- // 声明从 compat/probe.ts 按行号区间搬来,正文一字未改(唯一的容差是 `--export-top-level`
4
- // 加的 `export ` 前缀,moved-verify 逐字对拍)。
5
- //
6
3
  // 为什么单独一层:这几件是「宿主装在哪、按什么形状找得到它」的**位置**知识,与 probe.ts 主体
7
4
  // 那份「宿主版本与能力对不对」的**判定**知识是两件事;混在一起时 probe.ts 里几百行读代码的
8
5
  // 视线都要先跨过一遍 asar / npx 缓存的路径拼接。
9
- // 搬走的这些行里没有任何一处读 `import.meta.url` / `createRequire` —— 那两处在 probe.ts 主体
10
- // 里(深度敏感,一挪就改语义),这一层不碰。
6
+ //
7
+ // 这一层不读 `import.meta.url` / `createRequire` —— 那两处在 probe.ts 主体里(深度敏感,
8
+ // 一挪就改语义),这里只吃已解析好的路径。
11
9
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
12
10
  import { dirname, join } from 'node:path';
13
11
  import { realPathWithReason, safeResolve, } from './host-probe.js';
14
12
  // 类型面照旧从 lib/compat/probe.js 对外可见(`ops/compat.ts` 等按这个路径引它们)。
13
+ /**
14
+ * 需要比对**物理模块身份**的官方包。
15
+ *
16
+ * 只收「插件与宿主会同时加载、且是否同一份实现会改变行为」的那几个:cordis 的 symbol、
17
+ * tools 的注册表、工作区的索引、投影缓存、存储域、spill。别的官方包只在能力表里按成员检查。
18
+ */
15
19
  export const IDENTITY_PACKAGES = [
16
20
  '@deepseek-ai/cordis',
17
21
  '@deepseek-ai/dsh-tools',
@@ -20,33 +24,60 @@ export const IDENTITY_PACKAGES = [
20
24
  '@deepseek-ai/dsh-storage-domain',
21
25
  '@deepseek-ai/dsh-spill-local',
22
26
  ];
27
+ /** 本插件适配器最后一次对着验证过的宿主版本 —— 改它等于宣布适配了新的一代。 */
23
28
  export const VERIFIED_HOST_VERSION = '0.2.1-rc.2';
29
+ /**
30
+ * 每个操作依赖的能力集合,按「缺成员时插件怎么达到同样结果」分组。
31
+ *
32
+ * 顺序即优先级:`native`(宿主自己就实现了整个操作)能走就不走 `adapter`(受检兼容层,
33
+ * 唯一会碰私有成员的路线)。两组都不可用才算该操作不可用。
34
+ */
24
35
  export const OPERATION_ROUTES = {
25
36
  archive: { native: ['workspace.archive-native'], adapter: ['workspace.enqueue', 'workspace.set-state'] },
26
37
  unarchive: { native: ['workspace.unarchive-native'], adapter: ['workspace.enqueue', 'workspace.set-state'] },
27
38
  batch: { native: ['workspace.batch-native'], adapter: ['workspace.enqueue', 'workspace.set-state'] },
28
39
  delete: {
29
40
  native: ['workspace.delete-native'],
30
- // NOTE: `projection.delete-native` is deliberately NOT a route requirement.
31
- // A host cache without its own delete barrier is expected on rc.2; the
32
- // bridge wraps it (`workspace.js` / `sessions/bridge.ts`) and reports a
33
- // refusal itself when even that is impossible. Requiring the native barrier
34
- // here would disable deletion on exactly the host this plugin was verified
35
- // against.
41
+ // `projection.delete-native` **刻意不作为**路线要求:宿主缓存没有自己的删除屏障是
42
+ // 常态,`sessions/bridge.ts` 会包一层顶上;连包都包不住时由它自己报拒绝。把它列为
43
+ // 要求,会让本插件适配的那一版宿主反而删不了东西。
36
44
  adapter: [
37
45
  'workspace.enqueue', 'workspace.set-state', 'workspace.index-header',
38
46
  'sessions.detach-live', 'sessions.cold-announce', 'projection.write',
39
- // B2:运行时硬前提(`table.delete`)也算一条路由要求 —— 不算进来的话,宿主表不可删时
40
- // 路由说可用、点下去必拒。batch 的 adapter 路由**有意**保持只有 enqueue/set-state:
47
+ // `projection.table-delete` 是运行时硬前提,也算一条路由要求 —— 不算进来的话,宿主表
48
+ // 不可删时路由说可用、点下去必拒。batch 的 adapter 路由**有意**只留 enqueue / set-state:
41
49
  // 它的逐条失败会在结果里按 sessionId 报出来,此处不放宽也不收紧。
42
50
  'projection.table-delete',
43
51
  ],
44
52
  },
45
53
  list: { native: [], adapter: ['workspace.read-state', 'workspace.read-table', 'workspace.index-shape'] },
46
54
  };
55
+ /**
56
+ * 一条能力失败时给用户看的补救说明。
57
+ *
58
+ * 所有能力目前共用同一句:可行动的路只有两条(更新插件 / 改用宿主原生入口),差异在
59
+ * `doctor` 的明细里。参数留着,将来要按能力分叉时不必改调用点。
60
+ *
61
+ * @param _finding 失败的那条能力结论
62
+ * @returns 可直接展示给用户的补救说明
63
+ */
47
64
  export function recoveryFor(_finding) {
48
65
  return `宿主 ${VERIFIED_HOST_VERSION} 的该项能力未通过探测;请更新本插件到与本机 DSH 匹配的版本,或改用宿主原生入口(先运行 node scripts/doctor.mjs 查看差异)。`;
49
66
  }
67
+ /**
68
+ * 宿主 `@deepseek-ai` 目录的候选序列,按优先级排 —— 全仓「宿主装在哪」的唯一口径。
69
+ *
70
+ * 四步,前一步找不到才看下一步:
71
+ * 1. 桌面版的 `resources/app.asar`(见 {@link asarHostPackageRoot});
72
+ * 2. `$DSH_HOME/profiles/node_modules/@deepseek-ai`;
73
+ * 3. 从 {@link IDENTITY_PACKAGES} 里每个能解析的锚点向上找 `node_modules/@deepseek-ai`;
74
+ * 4. npx 缓存里的安装(见 {@link npxCacheHostRoots})。
75
+ *
76
+ * 锚点那一步只认**真实形态**:取不到就跳过 —— 这里没有可比的对象,跳过是如实;而身份
77
+ * 比对那边取不到必须报出来(见 `assessHost` 的 realpath 说明)。
78
+ *
79
+ * @returns 候选目录(可能为空,调用方按顺序试)
80
+ */
50
81
  export function hostRootCandidates() {
51
82
  const home = process.env.DSH_HOME || join(process.env.USERPROFILE || process.env.HOME || '', '.dsh');
52
83
  const candidates = [];
@@ -77,6 +108,15 @@ export function hostRootCandidates() {
77
108
  candidates.push(...npxCacheHostRoots());
78
109
  return candidates;
79
110
  }
111
+ /**
112
+ * 桌面版 `app.asar` 里的宿主 `@deepseek-ai` 目录。
113
+ *
114
+ * 只认 electron 注入的 `process.resourcesPath`,不按包名或环境变量猜 —— 所以 `dsh web`
115
+ * (普通 node)下一律返回 null。归档内路径由 electron 自己的 fs 修补解析,归档外的普通
116
+ * node 读不到,因此这里失败是正常路径,不报错。
117
+ *
118
+ * @returns 归档内的目录;不是桌面版、或归档里没有 `dsh` 包时为 null
119
+ */
80
120
  export function asarHostPackageRoot() {
81
121
  const resources = process.resourcesPath;
82
122
  if (typeof resources !== 'string' || resources === '')
@@ -91,6 +131,14 @@ export function asarHostPackageRoot() {
91
131
  }
92
132
  return dir;
93
133
  }
134
+ /**
135
+ * npx 缓存里的宿主 `@deepseek-ai` 目录,按目录 mtime 新到旧排。
136
+ *
137
+ * 缓存位置依次看 `npm_config_cache`、`~/.npmrc` 的 `cache=`、`%LOCALAPPDATA%\npm-cache`。
138
+ * 全程同步、不起子进程;一个都读不到就当没有这批候选。
139
+ *
140
+ * @returns 按新旧排好的目录列表(可能为空)
141
+ */
94
142
  export function npxCacheHostRoots() {
95
143
  const home = process.env.USERPROFILE || process.env.HOME || '';
96
144
  let cache = process.env.npm_config_cache || '';
@@ -125,9 +173,24 @@ export function npxCacheHostRoots() {
125
173
  }
126
174
  return roots.sort((left, right) => right.mtime - left.mtime).map((root) => root.dir);
127
175
  }
176
+ /**
177
+ * 能力 id → 结论的索引,供路由判定反复按 id 查。
178
+ *
179
+ * @param assessment 任意带 `findings` 的评估结果
180
+ * @returns id 到结论的映射;同一个 id 重复出现时后者胜
181
+ */
128
182
  export function findingsById(assessment) {
129
183
  return new Map(assessment.findings.map((finding) => [finding.id, finding]));
130
184
  }
185
+ /**
186
+ * 把一组能力 id 里**没通过**的那些翻成拒绝说明,顺序与入参一致。
187
+ *
188
+ * id 在评估里不存在时**不算失败**:宿主根本没暴露这项能力,挡不住一条用不到它的路线。
189
+ *
190
+ * @param assessment 任意带 `findings` 的评估结果
191
+ * @param ids 要检查的能力 id
192
+ * @returns 拒绝说明列表;全部通过时为空数组
193
+ */
131
194
  export function refusalsFor(assessment, ids) {
132
195
  const index = findingsById(assessment);
133
196
  const out = [];
@@ -139,13 +202,21 @@ export function refusalsFor(assessment, ids) {
139
202
  }
140
203
  return out;
141
204
  }
205
+ /**
206
+ * 决定一个操作该走哪条路。
207
+ *
208
+ * 从不从「部分可用」悄悄退到破坏性路线:只有它需要的**每一项**能力都 `ok`,那条路才被选中。
209
+ *
210
+ * @param assessment 最新一次宿主评估
211
+ * @param operation 操作名(见 {@link OPERATION_ROUTES})
212
+ * @returns 选中的路线;`none` 时附上缺什么、为什么
213
+ */
142
214
  export function routeFor(assessment, operation) {
143
215
  const routes = OPERATION_ROUTES[operation];
144
216
  const index = findingsById(assessment);
145
217
  const allOk = (ids) => ids.every((id) => {
146
218
  const finding = index.get(id);
147
- // A capability that the host does not expose at all cannot block a route
148
- // it is not part of; absent ids are treated as satisfied.
219
+ // 宿主根本没暴露的能力,挡不住一条用不到它的路线;缺席的 id 按满足处理。
149
220
  return finding === undefined || finding.state === 'ok';
150
221
  });
151
222
  if (routes.native.length > 0 && allOk(routes.native))