dsh-plugin-tool-management 0.21.1 → 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 (143) hide show
  1. package/CHANGELOG.md +111 -1
  2. package/README.md +43 -7
  3. package/README_EN.md +41 -7
  4. package/docs/{update.md → UPDATE.md} +38 -36
  5. package/docs/images/1-EN.png +0 -0
  6. package/docs/images/1.png +0 -0
  7. package/docs/images/2-EN.png +0 -0
  8. package/docs/images/2.png +0 -0
  9. package/docs/images/3-EN.png +0 -0
  10. package/docs/images/3.png +0 -0
  11. package/docs/images/4-EN.png +0 -0
  12. package/docs/images/4.png +0 -0
  13. package/docs/images/5-EN.png +0 -0
  14. package/docs/images/5.png +0 -0
  15. package/docs/images/6-EN.png +0 -0
  16. package/docs/images/6.png +0 -0
  17. package/docs/images/7-EN.png +0 -0
  18. package/docs/images/7.png +0 -0
  19. package/docs/images/8-EN.png +0 -0
  20. package/docs/images/8.png +0 -0
  21. package/lib/approval-policy.js +2 -2
  22. package/lib/audit-log.js +1 -1
  23. package/lib/boot/reconcile.js +157 -0
  24. package/lib/client.js +6668 -3145
  25. package/lib/compat/capability-specs.js +13 -17
  26. package/lib/compat/host-contracts.js +2 -0
  27. package/lib/compat/host-probe.js +35 -38
  28. package/lib/compat/host-roots.js +86 -15
  29. package/lib/compat/patch-dialect.js +14 -1
  30. package/lib/compat/preset-reach.js +75 -102
  31. package/lib/compat/probe.js +86 -131
  32. package/lib/compat/runtime-notes.js +1 -1
  33. package/lib/context-inject-contract.js +6 -5
  34. package/lib/context-inject-frame.js +124 -73
  35. package/lib/context-inject-select.js +66 -12
  36. package/lib/context-inject-surface.js +52 -4
  37. package/lib/context-inject.js +176 -39
  38. package/lib/desktop-cookie-prune.js +95 -0
  39. package/lib/diagnostics.js +79 -0
  40. package/lib/exports/transcript.js +4 -4
  41. package/lib/host-names.js +6 -6
  42. package/lib/http-api.js +73 -48
  43. package/lib/http-fence.js +44 -9
  44. package/lib/hub.js +12 -13
  45. package/lib/imports/parsers.js +25 -21
  46. package/lib/imports/unzip.js +48 -0
  47. package/lib/imports/upload.js +13 -37
  48. package/lib/index.js +3026 -279
  49. package/lib/mcp/disabled-tools.js +97 -0
  50. package/lib/mcp/loader-token.js +4 -4
  51. package/lib/mcp/manager.js +636 -226
  52. package/lib/mcp/override-blocks.js +1 -1
  53. package/lib/mcp/patch-yaml.js +42 -31
  54. package/lib/mcp/restart-marker.js +110 -0
  55. package/lib/mcp/secret-guard.js +6 -6
  56. package/lib/mcp/state-section.js +190 -60
  57. package/lib/mcp/tool-visibility.js +364 -73
  58. package/lib/memories/archive-engine.js +67 -42
  59. package/lib/memories/archive.js +23 -3
  60. package/lib/memories/constants.js +40 -127
  61. package/lib/memories/discovery.js +41 -12
  62. package/lib/memories/index-io.js +238 -33
  63. package/lib/memories/projection.js +36 -20
  64. package/lib/memories/prompt-layer.js +38 -0
  65. package/lib/memories/search.js +86 -0
  66. package/lib/memories/service.js +350 -111
  67. package/lib/memories/snapshot.js +83 -36
  68. package/lib/op-registry.js +73 -15
  69. package/lib/ops/candidates.js +14 -5
  70. package/lib/ops/compat.js +56 -13
  71. package/lib/ops/ctx.js +1 -1
  72. package/lib/ops/memory.js +89 -20
  73. package/lib/ops/prompts.js +57 -13
  74. package/lib/ops/quick-prompts.js +25 -2
  75. package/lib/ops/scene-records.js +29 -23
  76. package/lib/ops/scene-sync.js +30 -10
  77. package/lib/ops/scope.js +1094 -0
  78. package/lib/ops/sessions.js +15 -11
  79. package/lib/ops/snapshot.js +65 -29
  80. package/lib/ops/state-doctor.js +40 -5
  81. package/lib/ops/trash-retention.js +2 -1
  82. package/lib/ops/trash.js +6 -6
  83. package/lib/paths.js +50 -3
  84. package/lib/prompts/preset-id.js +5 -1
  85. package/lib/prompts/project-instructions.js +162 -0
  86. package/lib/prompts/quick-service.js +6 -4
  87. package/lib/prompts/service.js +30 -18
  88. package/lib/request-gate.js +32 -29
  89. package/lib/scene-linkage.js +17 -4
  90. package/lib/scene-prompt-sync.js +11 -10
  91. package/lib/scene-settings.js +1 -0
  92. package/lib/scenes/candidates.js +17 -11
  93. package/lib/scope/intent-store.js +106 -0
  94. package/lib/scope/intent.js +376 -0
  95. package/lib/scope/resolve.js +190 -0
  96. package/lib/scope/scope-overrides.js +894 -0
  97. package/lib/scope/store.js +263 -0
  98. package/lib/scope/workspace-key.js +64 -0
  99. package/lib/sessions/archive-schemas.js +9 -0
  100. package/lib/sessions/bridge.js +42 -56
  101. package/lib/sessions/history.js +9 -9
  102. package/lib/sessions/workspace.js +21 -23
  103. package/lib/settings-sidecars.js +51 -24
  104. package/lib/sidebar-settings.js +1 -0
  105. package/lib/skills/catalog.js +207 -35
  106. package/lib/skills/core-util.js +5 -0
  107. package/lib/skills/core.js +36 -23
  108. package/lib/skills/frontmatter.js +144 -11
  109. package/lib/skills/homes.js +2 -0
  110. package/lib/skills/import-pipeline.js +8 -1
  111. package/lib/skills/manager-state.js +30 -6
  112. package/lib/skills/official.js +14 -11
  113. package/lib/skills/readonly-discovery.js +1 -0
  114. package/lib/skills/service.js +157 -31
  115. package/lib/skills/skill-roots.js +25 -7
  116. package/lib/skills/skill-trash.js +14 -3
  117. package/lib/skills/system-trash.js +3 -1
  118. package/lib/skills/upload-pipeline.js +19 -3
  119. package/lib/slash-settings.js +1 -0
  120. package/lib/stale-write.js +82 -0
  121. package/lib/subagents/catalog.js +52 -18
  122. package/lib/subagents/child-preset.js +7 -10
  123. package/lib/subagents/persona-parse.js +35 -13
  124. package/lib/subagents/persona-write.js +12 -8
  125. package/lib/subagents/run-provider.js +13 -15
  126. package/lib/subagents/service.js +16 -14
  127. package/lib/subagents/tool-filter.js +1 -1
  128. package/lib/subagents/tools.js +113 -41
  129. package/lib/token-config.js +34 -14
  130. package/lib/tool-table-switch.js +142 -49
  131. package/lib/tools/deps.js +172 -6
  132. package/lib/tools/mcp.js +231 -54
  133. package/lib/tools/memory.js +139 -39
  134. package/lib/tools/prompt.js +81 -17
  135. package/lib/tools/remove.js +52 -26
  136. package/lib/tools/scene.js +139 -42
  137. package/lib/tools/skills.js +211 -51
  138. package/lib/tools/subagent.js +63 -32
  139. package/lib/tools/table.js +63 -25
  140. package/lib/trash-id.js +3 -2
  141. package/lib/trash-retention.js +7 -7
  142. package/lib/update-check.js +222 -0
  143. package/package.json +18 -15
@@ -15,6 +15,7 @@ import { lstatOrNull, pathIdentity } from "./core-util.js";
15
15
  import { OFFICIAL_SOURCE_KEY, officialSkillRoot } from "./official.js";
16
16
  import { resolveAgentsHome, resolveDshHome } from "./homes.js";
17
17
  import { isSameOrDescendant } from "../paths.js";
18
+ /** 全部技能来源(官方 / 导入 / DSH 技能 / 人设 / codex / claude / 自定义),按优先级排。 */
18
19
  export function userRoots() {
19
20
  const official = officialSkillRoot();
20
21
  return [
@@ -31,16 +32,15 @@ export function userRoots() {
31
32
  native: true,
32
33
  rank: 400,
33
34
  },
34
- // 官方内置紧随 DSH 技能之后(用户裁定):同为一眼要看的来源,排在导入技能之前。
35
+ // 官方内置紧随 DSH 技能之后:同为一眼要看的来源,排在导入技能之前。
35
36
  ...(official === null ? [] : [official]),
36
37
  {
37
- // v0.4:插件**导入/上传**的技能落到 hub 内(用户要求:插件产生的文件收在
38
+ // 插件**导入/上传**的技能落到 hub 内(用户要求:插件产生的文件收在
38
39
  // $DSH_HOME/tool-management/)。rank 高于 DSH 技能,同名时 hub 版本遮蔽官方目录里的;
39
40
  // 官方 ~/.dsh/skills/ 仍作为可切换来源列出(不搬走、不删)。
40
41
  //
41
- // 界面名「导入技能」:它是插件**导入/上传**的落点 —— v0.20.0 及以前新建也落这里,
42
- // 2026-10-15 用户裁定「新增技能默认 DSH 技能,导入技能功能才用导入技能目录」后,
43
- // 新建改走 DSH 技能目录(见 core.ts 的 createSkill 默认值)。
42
+ // 界面名「导入技能」:它是插件**导入/上传**的落点 —— 新建不落这里,
43
+ // 新建走 DSH 技能目录(见 core.ts 的 createSkill 默认值)。
44
44
  // 与 dsh 同为默认来源:路径必须读取(不可移除、不可停用),里面的技能可删。
45
45
  key: "hub",
46
46
  path: join(resolveDshHome(), "tool-management", "skills"),
@@ -81,20 +81,25 @@ export function userRoots() {
81
81
  },
82
82
  ];
83
83
  }
84
+ /** 出厂就存在的三个来源 key(`dsh` / `hub` / `official`);其余来源由状态文件与项目根补上。 */
84
85
  export const DEFAULT_SOURCE_KEYS = Object.freeze(["dsh", "hub", OFFICIAL_SOURCE_KEY]);
86
+ /** 是不是内置来源(内置来源不可移除、不可停用,但里面的技能可删)。 */
85
87
  export function isDefaultSkillSource(rootOrKey) {
86
88
  const key = rootOrKey && typeof rootOrKey === "object"
87
89
  ? rootOrKey.key
88
90
  : rootOrKey;
89
91
  return DEFAULT_SOURCE_KEYS.includes(key);
90
92
  }
93
+ /** 项目根的稳定短标识(规范化路径的 sha256 前 16 位),用作来源 key 与缓存键。 */
91
94
  export function projectIdentity(path) {
92
95
  const canonical = pathIdentity(path);
93
96
  return createHash("sha256").update(canonical).digest("hex").slice(0, 16);
94
97
  }
98
+ /** 自定义来源的 key:`custom-<路径指纹>`,同一路径永远得到同一个 key。 */
95
99
  export function customRootKey(path) {
96
100
  return "custom-" + projectIdentity(path);
97
101
  }
102
+ /** 从 cwd 向上找最近的 `.git` 所在目录作为项目根;`cwd` 非绝对路径时返回 null。 */
98
103
  export async function nearestProjectRoot(cwd) {
99
104
  if (typeof cwd !== "string" || !isAbsolute(cwd))
100
105
  return null;
@@ -127,6 +132,7 @@ export async function nearestProjectRoot(cwd) {
127
132
  current = parent;
128
133
  }
129
134
  }
135
+ /** 项目来源是否可用:与用户技能根重叠的来源要剔掉,否则会绕过用户根的停用策略。 */
130
136
  export async function projectSourceSafe(definition) {
131
137
  // 只读来源允许目录链接,但重叠来源会绕过用户根的停用策略。
132
138
  if (definition.kind === "project-agents")
@@ -148,7 +154,7 @@ export async function projectSourceSafe(definition) {
148
154
  *
149
155
  * 目录缺失 / 是链接 / 读不了,以及点号开头的隐藏条目,一律按「没有」处理 —— 注册一个
150
156
  * 没有技能的来源只有噪音:占一个来源位,还会在场景切换时产生「停用 project-dsh:<路径
151
- * 哈希>」这类只有内部键的提示(用户 2026-10-15 报的)。
157
+ * 哈希>」这类只有内部键的提示(用户反馈的)。
152
158
  */
153
159
  async function hasSkillEntry(path, mutable) {
154
160
  const stat = await lstatOrNull(path);
@@ -179,6 +185,7 @@ async function hasSkillEntry(path, mutable) {
179
185
  }
180
186
  return false;
181
187
  }
188
+ /** 由一组会话 cwd 推出项目级技能来源(同一项目根只出一份),重叠 / 异常的记进 `diagnostics`。 */
182
189
  export async function projectRoots(projectCwds = [], diagnostics) {
183
190
  const projects = new Map();
184
191
  for (const cwd of Array.isArray(projectCwds) ? projectCwds : []) {
@@ -251,7 +258,7 @@ export async function projectRoots(projectCwds = [], diagnostics) {
251
258
  for (const candidate of candidates) {
252
259
  if (!(await projectSourceSafe(candidate)))
253
260
  continue;
254
- // 无技能的项目来源不注册(用户 2026-10-15 裁定):目录不存在、是链接或底下没有
261
+ // 无技能的项目来源不注册:目录不存在、是链接或底下没有
255
262
  // 一条技能条目时,这个来源对用户不可见也不可用 —— 硬注册出来只会平白占一个来源位、
256
263
  // 在场景切换时弹「停用 project-dsh:<路径哈希>」这类只有内部键的提示,而新建技能的
257
264
  // 落点也早已不含项目来源(createRoots 只收用户级)。本仓库就没有 .dsh/skills,
@@ -263,23 +270,29 @@ export async function projectRoots(projectCwds = [], diagnostics) {
263
270
  }
264
271
  return roots;
265
272
  }
273
+ /** 插件自己的数据根:`$DSH_HOME/tool-management`。 */
266
274
  export function managerHomePath() {
267
275
  return join(resolveDshHome(), "tool-management");
268
276
  }
277
+ /** 技能状态侧车路径(`skills-state.json`)。 */
269
278
  export function managerStatePath() {
270
279
  return join(managerHomePath(), "skills-state.json");
271
280
  }
281
+ /** 技能回收站根目录。 */
272
282
  export function trashRootPath() {
273
283
  return join(managerHomePath(), "trash", "skills-trash");
274
284
  }
285
+ /** 「DSH 技能」来源的目录(新建技能的默认落点)。 */
275
286
  export function dshRootPath() {
276
287
  // userRoots() 恒含 dsh 来源(见上方列表),断言只为让类型收敛。
277
288
  return userRoots().find((root) => root.key === "dsh").path;
278
289
  }
290
+ /** 新建技能的落点:有「导入技能」来源就落它,否则落 DSH 技能目录。 */
279
291
  export function skillCreateRootPath() {
280
292
  const hub = userRoots().find((root) => root.key === "hub");
281
293
  return hub && hub.path ? hub.path : dshRootPath();
282
294
  }
295
+ /** 只读来源上做写操作时统一的拒绝结果(带上被拒的动作名)。 */
283
296
  export function readonlyError(action) {
284
297
  return {
285
298
  ok: false,
@@ -290,6 +303,7 @@ export function readonlyError(action) {
290
303
  : "该技能来源不允许启用或停用",
291
304
  };
292
305
  }
306
+ /** 把来源的 key / 对象 / 路径三种入参归一成来源定义;认不出返回 null。 */
293
307
  export function rootDefinition(root) {
294
308
  if (root && typeof root === "object" && typeof root.key === "string")
295
309
  return root;
@@ -298,9 +312,11 @@ export function rootDefinition(root) {
298
312
  const resolved = resolve(root);
299
313
  return userRoots().find((item) => resolve(item.path) === resolved) || null;
300
314
  }
315
+ /** 按 key 查来源定义;不存在返回 null。 */
301
316
  export function rootByKey(key) {
302
317
  return userRoots().find((item) => item.key === key) || null;
303
318
  }
319
+ /** 取真实路径;路径不存在时退回原样(只做规范化,不造一个假结果)。 */
304
320
  export async function resolvedPath(path) {
305
321
  try {
306
322
  return await fs.realpath(path);
@@ -309,6 +325,7 @@ export async function resolvedPath(path) {
309
325
  return resolve(path);
310
326
  }
311
327
  }
328
+ /** 用于「两个路径是不是同一处」的比对路径:逐级解析已存在的祖先,保留尚不存在的尾段。 */
312
329
  export async function comparisonPath(path) {
313
330
  let current = resolve(path);
314
331
  const missing = [];
@@ -325,6 +342,7 @@ export async function comparisonPath(path) {
325
342
  }
326
343
  }
327
344
  }
345
+ /** 给定路径是否与任一用户技能根重叠(相同或互为祖先)。 */
328
346
  export async function overlapsUserSkillRoot(path) {
329
347
  const candidate = await comparisonPath(path);
330
348
  for (const root of userRoots()) {
@@ -14,6 +14,7 @@ import { rewriteDeclaredName } from "./frontmatter.js";
14
14
  import { dshRootPath, overlapsUserSkillRoot, projectIdentity, projectRoots, readonlyError, rootByKey, rootDefinition, skillCreateRootPath, trashRootPath, } from "./skill-roots.js";
15
15
  // `KEBAB_RE` 的单一真相源在 upload-pipeline(manager-state / core 也都从那里取)。
16
16
  import { KEBAB_RE } from "./upload-pipeline.js";
17
+ /** 来源定义里可写的那一份;只读或认不出的来源返回 null。 */
17
18
  export function writableRootDefinition(root) {
18
19
  const definition = rootDefinition(root);
19
20
  if (!definition || definition.mutable !== true)
@@ -38,6 +39,7 @@ export function writableRootDefinition(root) {
38
39
  return null;
39
40
  return definition;
40
41
  }
42
+ /** 同 {@link writableRootDefinition},但对项目来源额外核对目录边界后才算可写。 */
41
43
  export async function checkedWritableRootDefinition(root) {
42
44
  const definition = writableRootDefinition(root);
43
45
  if (!definition || definition.scope !== "project")
@@ -68,6 +70,7 @@ export async function checkedWritableRootDefinition(root) {
68
70
  }
69
71
  return definition;
70
72
  }
73
+ /** 删掉搬走后残留的旧路径;本来就不存在时静默返回。 */
71
74
  export async function removeMovedPath(path) {
72
75
  const st = await lstatOrNull(path);
73
76
  if (!st)
@@ -77,6 +80,7 @@ export async function removeMovedPath(path) {
77
80
  else
78
81
  await fs.unlink(path);
79
82
  }
83
+ /** rename 优先,跨卷失败时退回「复制 + 删除」。 */
80
84
  export async function movePathWithFallback(source, destination, options = {}) {
81
85
  try {
82
86
  await renameWithRetry(source, destination, options);
@@ -113,6 +117,7 @@ export async function movePathWithFallback(source, destination, options = {}) {
113
117
  }
114
118
  return { copied: true, cleanupError, quarantine };
115
119
  }
120
+ /** 一条技能在某个根下**实际存在**的所有路径(bundle 与 flat 两种形态都可能残留)。 */
116
121
  export async function safeExistingEntryPaths(root, name) {
117
122
  const paths = [];
118
123
  const bundle = entryPath(root, name);
@@ -127,6 +132,7 @@ export async function safeExistingEntryPaths(root, name) {
127
132
  paths.push({ path: flat, fileName: `${name}.md`, recursive: false });
128
133
  return paths;
129
134
  }
135
+ /** 读回收站条目的元数据;id 不合法或条目不存在返回 null。 */
130
136
  export async function readTrashMetadata(id) {
131
137
  if (entryPath(trashRootPath(), id) === null)
132
138
  return null;
@@ -143,6 +149,7 @@ export async function readTrashMetadata(id) {
143
149
  return null;
144
150
  }
145
151
  }
152
+ /** 来源在回收站元数据里的形状:项目来源记 `project`,其余一律记 `user`。 */
146
153
  export function trashRootMetadata(definition) {
147
154
  if (definition.scope !== "project")
148
155
  return { key: definition.key, scope: "user", label: definition.label };
@@ -155,8 +162,9 @@ export function trashRootMetadata(definition) {
155
162
  label: definition.label,
156
163
  };
157
164
  }
165
+ /** 由回收站元数据反推恢复目标来源;旧版条目一律归 `$DSH_HOME/skills`。 */
158
166
  export async function restoreRootDefinition(metadata, options = {}) {
159
- // version 1 entries predate scoped Trash and always belong to $DSH_HOME/skills.
167
+ // version 1 的条目早于分域回收站,一律属于 $DSH_HOME/skills。
160
168
  if (!metadata.root)
161
169
  return rootByKey("dsh");
162
170
  // 用户级来源按 key 重新解析:路径来自 userRoots(),不信元数据里记住的 path
@@ -189,6 +197,7 @@ export async function restoreRootDefinition(metadata, options = {}) {
189
197
  }
190
198
  return checkedWritableRootDefinition(root);
191
199
  }
200
+ /** 列出回收站里全部条目;目录读不到时返回空列表(不报错)。 */
192
201
  export async function listTrash() {
193
202
  let items;
194
203
  try {
@@ -227,7 +236,7 @@ async function nextFreeSkillName(root, name) {
227
236
  return null;
228
237
  }
229
238
  /**
230
- * 退号恢复时把技能**声明名**改成新的落盘名(用户 2026-10-14)。
239
+ * 退号恢复时把技能**声明名**改成新的落盘名(用户确认退号时)。
231
240
  *
232
241
  * 为什么必须改:`canonicalSkillName()` 取的是 frontmatter 里的 `name:`,**不是文件夹名** ——
233
242
  * 技能页的同名判定、`preferredSkills` 首选表、喂给宿主的 provider 候选名,全都以它为准。
@@ -276,6 +285,7 @@ async function retitleRestoredSkill(root, name, metadata) {
276
285
  }
277
286
  return true;
278
287
  }
288
+ /** 把一条技能从回收站恢复回它原来的来源根。 */
279
289
  export async function restoreTrash(id, log, options = {}) {
280
290
  const metadata = await readTrashMetadata(id);
281
291
  if (!metadata)
@@ -290,7 +300,7 @@ export async function restoreTrash(id, log, options = {}) {
290
300
  return definition || readonlyError("restore");
291
301
  const root = definition.path;
292
302
  /*
293
- * 同名先问一句(用户 2026-10-14):撞名时**默认仍拒绝**,但把候选名字一起回(`params.next`),
303
+ * 同名先问一句(用户要求):撞名时**默认仍拒绝**,但把候选名字一起回(`params.next`),
294
304
  * 界面弹窗才能如实写出"确认后会叫 `foo-1`";用户确认后带 `dedupe: true` 重来,这一次真的
295
305
  * 按退号的名字落盘。
296
306
  *
@@ -355,6 +365,7 @@ export async function restoreTrash(id, log, options = {}) {
355
365
  throw error;
356
366
  }
357
367
  }
368
+ /** 永久删除一条回收站条目(不可恢复,调用方必须先确认)。 */
358
369
  export async function permanentlyDeleteTrash(id, log) {
359
370
  const metadata = await readTrashMetadata(id);
360
371
  if (!metadata)
@@ -17,6 +17,7 @@ import { permanentlyDeleteTrash, trashRootPath } from './core.js';
17
17
  * 让调用方按既有的「回收站失败 → 硬删除」兜底走下去,队列得以继续。
18
18
  */
19
19
  export const EXTERNAL_CMD_TIMEOUT_MS = 30_000;
20
+ /** 跑一个外部命令,成功返回 true,失败 / 超时 / 命令不存在一律返回 false(不抛错)。 */
20
21
  export function runQuietly(command, args) {
21
22
  return new Promise((resolve) => {
22
23
  let settled = false;
@@ -50,6 +51,7 @@ export function runQuietly(command, args) {
50
51
  child.on('close', (code) => finish(code === 0));
51
52
  });
52
53
  }
54
+ /** PowerShell 单引号字面量转义(内部单引号翻倍)。 */
53
55
  export function psQuote(value) {
54
56
  return "'" + String(value).replace(/'/g, "''") + "'";
55
57
  }
@@ -80,7 +82,7 @@ export async function moveToSystemTrash(abs) {
80
82
  export async function permanentlyDeleteTrashSafely(id, log) {
81
83
  const clean = String(id || '').trim();
82
84
  const root = trashRootPath();
83
- // 走 `paths.ts` 的单段名校验,而不是自写白名单(审查 F1,0.17.0):
85
+ // 走 `paths.ts` 的单段名校验,而不是自写白名单:
84
86
  // 原判据 `/^[A-Za-z0-9._-]{1,128}$/` 放行 `.` 与 `..`,而 `root + sep + '..'` 解析后
85
87
  // 正是**回收站根目录**,末尾那句字符串前缀比对拦不住它 —— 于是「删掉某一条」变成
86
88
  // 「把整个 `trash/`(技能/场景/子智能体/提示词四类)送进系统回收站」,且返回 `ok:true`。
@@ -5,7 +5,7 @@
5
5
  //
6
6
  // 为什么这一段终于能搬:它向下要的东西分三层齐了 —— 路径与来源在 ./skill-roots.js、
7
7
  // 错误码与原子改名在 ./core-util.js、预检(读成候选 / 拒符号链 / 临时件 / 替换)在
8
- // ./import-pipeline.js。0.18.0 那次试切判给不做,缺的就是这三层:当时它们全在 core.ts 里,
8
+ // ./import-pipeline.js。想切出去就得先有这三层 —— 否则它们全在 core.ts 里,
9
9
  // 搬上传段必然反过来引 core,而 core 的 handlers 又引上传 ⇒ 运行时环。
10
10
  import { basename, dirname, join } from "node:path";
11
11
  import { promises as fs } from "node:fs";
@@ -16,13 +16,21 @@ import { parseSkillDoc, rewriteDeclaredName, toKebab } from "./frontmatter.js";
16
16
  import { attachCode, codedError, entryPath, lstatOrNull, MAX_ENTRY_NAME_LENGTH, renameWithRetry, temporaryPath, } from "./core-util.js";
17
17
  import { analyzeSource, collectCandidates, MAX_SOURCE_DEPTH, preflightCandidates, replaceWithCopy, } from "./import-pipeline.js";
18
18
  import { managerHomePath, resolvedPath, skillCreateRootPath } from "./skill-roots.js";
19
+ /** 技能目录名的合法形状(kebab-case):它同时是 frontmatter 里 `name` 的推荐写法。 */
19
20
  export const KEBAB_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
21
+ /** Windows 保留设备名(`con` / `nul` / `com1`…):同名目录在 Windows 上根本建不出来。 */
20
22
  export const WINDOWS_DEVICE_NAME_RE = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
23
+ /** 上传压缩包本身的上限 32 MiB(与传输层体限同档,先挡住再解压)。 */
21
24
  export const MAX_UPLOAD_ARCHIVE_BYTES = 32 << 20;
25
+ /** 解压后单个条目上限 32 MiB —— 防 zip 炸弹的第二道闸。 */
22
26
  export const MAX_UPLOAD_ENTRY_BYTES = 32 << 20;
27
+ /** 解压后累计上限 64 MiB:与记忆附件、导入器同层口径,超过就不是一份技能了。 */
23
28
  export const MAX_UPLOAD_TOTAL_BYTES = 64 << 20;
29
+ /** 压缩包内条目数上限 1000:正常技能包是几十个文件,上千基本是打包错了。 */
24
30
  export const MAX_UPLOAD_ENTRIES = 1000;
31
+ /** 包内路径长度上限 512:再长会撞上 Windows 的路径长度限制,解压必失败。 */
25
32
  export const MAX_UPLOAD_PATH_LENGTH = 512;
33
+ /** 两个路径是否相同或互为祖先(按真实形态比)。 */
26
34
  export async function pathsOverlap(a, b) {
27
35
  const left = await resolvedPath(a);
28
36
  const right = await resolvedPath(b);
@@ -59,6 +67,7 @@ async function nextFreeImportName(root, base, claimed) {
59
67
  }
60
68
  return null;
61
69
  }
70
+ /** 从磁盘上的一个目录导入技能(新建或按 options 覆盖)。 */
62
71
  export async function importSkill(source, log, options = {}) {
63
72
  const targetRoot = skillCreateRootPath();
64
73
  const conflict = options.conflict === "overwrite" ? "overwrite" : "skip";
@@ -159,7 +168,7 @@ export async function importSkill(source, log, options = {}) {
159
168
  const existing = await existingEntryPaths(targetRoot, c.kebab);
160
169
  let renamedFrom;
161
170
  if (existing.length) {
162
- // 上传导入撞名一律退号新增(用户 2026-10-15):旧行为是静默跳过,结果里只多
171
+ // 上传导入撞名一律退号新增(用户要求):静默跳过的话结果里只多
163
172
  // 一行"已跳过",用户想要的那份根本没进来。`skill-import`(目录导入)不带
164
173
  // dedupe,仍是 skip / overwrite 二选一。
165
174
  if (options.dedupe !== true) {
@@ -265,11 +274,13 @@ export async function importSkill(source, log, options = {}) {
265
274
  return failureResult();
266
275
  return { kind: analysis.kind, imported, skipped, failed };
267
276
  }
277
+ /** 这个路径段在上传时会被改写(含控制字符或结尾的点 / 空白)。 */
268
278
  export function pathSegmentRewritten(part) {
269
279
  if (/[\u0000-\u001f\u007f]/.test(part))
270
280
  return true;
271
281
  return part !== part.replace(/[.\s]+$/, "");
272
282
  }
283
+ /** 归一化上传条目里的相对路径:统一分隔符、拒掉绝对路径与 `..`。 */
273
284
  export function normalizeUploadPath(input) {
274
285
  const raw = String(input == null ? "" : input).replace(/\\/g, "/");
275
286
  if (!raw ||
@@ -300,6 +311,7 @@ export function normalizeUploadPath(input) {
300
311
  }
301
312
  return { path: parts.join("/"), directory };
302
313
  }
314
+ /** 解码上传的 Base64 内容,并按 `maxBytes` 卡上限(超限抛带 code 的错误)。 */
303
315
  export function decodeUploadBase64(value, maxBytes, code = "error.upload.tooLarge") {
304
316
  const raw = String(value == null ? "" : value);
305
317
  const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
@@ -328,6 +340,7 @@ export function decodeUploadBase64(value, maxBytes, code = "error.upload.tooLarg
328
340
  const bytes = Buffer.from(raw, "base64");
329
341
  return bytes;
330
342
  }
343
+ /** 把上传过程中的抛出值折成统一的失败结果(保留既有兜底文案)。 */
331
344
  export function uploadError(error) {
332
345
  // 按可选 message 读取抛出值,保持既有兜底文案。
333
346
  const cause = error;
@@ -336,6 +349,7 @@ export function uploadError(error) {
336
349
  error: String(cause && cause.message ? cause.message : error),
337
350
  }, error);
338
351
  }
352
+ /** 把上传的「文件条目数组」逐个落到 `contentRoot` 下。 */
339
353
  export async function writeUploadedEntries(contentRoot, entries) {
340
354
  if (!Array.isArray(entries) || entries.length === 0)
341
355
  throw codedError("上传内容为空", "error.upload.empty");
@@ -362,6 +376,7 @@ export async function writeUploadedEntries(contentRoot, entries) {
362
376
  await fs.writeFile(target, bytes);
363
377
  }
364
378
  }
379
+ /** 把上传的 ZIP 解开落到 `contentRoot` 下(解压前先卡大小与条目数)。 */
365
380
  export async function writeUploadedZip(contentRoot, encoded) {
366
381
  const archive = decodeUploadBase64(encoded, MAX_UPLOAD_ARCHIVE_BYTES, "error.upload.archiveTooLarge");
367
382
  let count = 0;
@@ -395,6 +410,7 @@ export async function writeUploadedZip(contentRoot, encoded) {
395
410
  }));
396
411
  await writeUploadedEntries(contentRoot, entries);
397
412
  }
413
+ /** 把一次上传落成磁盘上的一份源目录,返回它的路径。 */
398
414
  export async function prepareUploadedSource(sessionRoot, input) {
399
415
  const contentRoot = join(sessionRoot, "content");
400
416
  await fs.mkdir(contentRoot, { recursive: true });
@@ -408,7 +424,6 @@ export async function prepareUploadedSource(sessionRoot, input) {
408
424
  // 没有根级 SKILL.md:剩下的合法形态只有两种 —— 根级 .md(单文件技能)或子目录
409
425
  // 带 SKILL.md(批量),与 importSkill 的 collectCandidates 收录口径一一对应。
410
426
  // 两者都不占,这个包就打不开:此时说清缺的是 SKILL.md、以及是哪个包(用户
411
- // 2026-10-15:老报错是 importSkill 的空来源错误,带着 uuid 临时目录路径、落在
412
427
  // 通用「文件要求」段,认不出是谁、也看不出缺什么)。
413
428
  const items = await fs.readdir(contentRoot, { withFileTypes: true });
414
429
  for (const it of items) {
@@ -439,6 +454,7 @@ export async function prepareUploadedSource(sessionRoot, input) {
439
454
  await renameWithRetry(contentRoot, wrappedRoot);
440
455
  return batchRoot;
441
456
  }
457
+ /** 上传导入的完整流程:落盘 → 预检 → 复制进目标根 → 清理临时目录。 */
442
458
  export async function importUploadedSkill(input, log, options = {}) {
443
459
  const uploadHome = join(managerHomePath(), "uploads");
444
460
  const sessionRoot = join(uploadHome, `.upload-${randomUUID()}`);
@@ -10,6 +10,7 @@
10
10
  //
11
11
  // 为什么放在服务端而不是 localStorage:与其余设置同一个家(侧车 + op + 登记表),换浏览器也在;
12
12
  // 存本地就只有那个浏览器认,而这条开关的用途正是"这台机器上我不想看到它"。
13
+ /** `/` 菜单出厂值:模型工具与快捷提示词都露出来。 */
13
14
  export const DEFAULT_SLASH_SETTINGS = { tools: true, quickPrompts: true };
14
15
  /**
15
16
  * 把任意输入夹成合法设置:读不到 / 形状不对一律按默认开启。
@@ -0,0 +1,82 @@
1
+ // 并发编辑的「内容指纹」判据。
2
+ //
3
+ // 问题:两个窗口同时打开同一份记忆 / 提示词 / 补丁,后保存的那一份会把前一份的改动整份覆盖。
4
+ // 文件锁只能防同进程的两条路径,防不住外部编辑器 —— 所以判据必须是**内容**:读的时候给一份
5
+ // 指纹,写的时候核对指纹还在不在。
6
+ //
7
+ // 为什么不用 mtime:拷贝、同步盘回写、`touch` 都会改 mtime 而不改内容;反过来,某些工具
8
+ // 会保留 mtime 而改内容。内容 hash 没有这两种误判。
9
+ //
10
+ // `expectedStamp` 是**可选**参数:不带 = 回到旧行为(不校验)。这样旧客户端、脚本、
11
+ // 模型工具都不受影响,只有界面在编辑弹窗里主动带。
12
+ import { createHash } from 'node:crypto';
13
+ import { readFile } from 'node:fs/promises';
14
+ /** 「基于旧值写」被拒的统一错误码:界面按它弹「重新加载 / 覆盖保存」。 */
15
+ export const STALE_WRITE_CODE = 'stale-write';
16
+ /** 内容指纹:sha256 前 16 位。`null` / `undefined` 表示"文件不存在"。 */
17
+ export function stampOfText(text) {
18
+ if (text === null || text === undefined)
19
+ return null;
20
+ return createHash('sha256').update(text, 'utf8').digest('hex').slice(0, 16);
21
+ }
22
+ /** 文件指纹:不存在返回 `null`;其它读失败抛错(调用方按失败处理,不静默放行)。 */
23
+ export async function stampOf(abs) {
24
+ try {
25
+ return stampOfText(await readFile(abs, 'utf8'));
26
+ }
27
+ catch (e) {
28
+ if (e?.code === 'ENOENT')
29
+ return null;
30
+ throw e;
31
+ }
32
+ }
33
+ /** 规范化客户端传来的 `expectedStamp`:非字符串 / 空串 = 没带。 */
34
+ export function normalizeStamp(expected) {
35
+ if (typeof expected !== 'string')
36
+ return null;
37
+ const s = expected.trim();
38
+ return s === '' ? null : s;
39
+ }
40
+ /** 「基于旧值写」被拒时的统一结果,带上磁盘上现在的值。 */
41
+ export function staleWriteResult(current) {
42
+ return {
43
+ ok: false,
44
+ code: STALE_WRITE_CODE,
45
+ error: '文件已在别处被修改,本次保存没有写入。请重新加载后再改,或选择覆盖保存。',
46
+ current: { stamp: current },
47
+ };
48
+ }
49
+ /**
50
+ * 比对指纹:一致 / 没带 = `null`(继续写);不一致 = 冲突回执。
51
+ * 调用方直接 `return conflict` 即可,回执形状与其余 op 的失败一致。
52
+ */
53
+ export function stampConflict(current, expected) {
54
+ const want = normalizeStamp(expected);
55
+ if (want === null)
56
+ return null;
57
+ return want === current ? null : staleWriteResult(current);
58
+ }
59
+ /**
60
+ * 「基于旧值写」被拒时的异常形态,供没有结构化回执通道的写路径使用。
61
+ *
62
+ * 与 `staleWriteResult()` 是同一件事的两种出口:有回执通道的 op 返回结果,没有的抛这个。
63
+ * `current` 带上磁盘上现在的值,调用方才能让用户决定「重新加载」还是「覆盖保存」。
64
+ */
65
+ export class StaleWriteError extends Error {
66
+ code = STALE_WRITE_CODE;
67
+ current;
68
+ constructor(current) {
69
+ super('文件已在别处被修改,本次保存没有写入。');
70
+ this.name = 'StaleWriteError';
71
+ this.current = current;
72
+ }
73
+ }
74
+ /** 抛错版:给没有结构化回执通道的写路径用。 */
75
+ export async function assertStamp(abs, expected) {
76
+ const want = normalizeStamp(expected);
77
+ if (want === null)
78
+ return;
79
+ const current = await stampOf(abs);
80
+ if (current !== want)
81
+ throw new StaleWriteError(current);
82
+ }
@@ -34,12 +34,12 @@ export function catalogDescription(value, maxLength) {
34
34
  * 返回 `''` 表示不注入 —— `renderPrompt` 会删除空段,所以不用人设的用户零 token 成本。
35
35
  * 名字按字典序排序:即使底层目录枚举顺序变化,段文本也保持逐字节稳定(前缀缓存契约)。
36
36
  *
37
- * 文案纪律(2026-09-16 用户裁定):**只写模型能照做的事,不写实现说明**。原文两句里
37
+ * 文案纪律:**只写模型能照做的事,不写实现说明**。原文两句里
38
38
  * 「该人设的完整提示词会成为子代理的系统提示词」「子代理在独立上下文中执行」都是宿主内部
39
39
  * 机制,模型无法据此行动;而委派的调用语义与成本(自包含任务、只回最终结果、会开新会话)
40
40
  * 已经写在 `subagent_manager_run` 的描述里 —— 常驻层再重复一遍等于同一件事付两次 token。
41
41
  *
42
- * 第三版(2026-09-17 用户指出"还是那句套话"):**职责彻底切开** —— 本函数只排版清单
42
+ * **职责彻底切开**(用户指出"还是那句套话")—— 本函数只排版清单
43
43
  * (`- **名字** — 描述`),"这是什么 + 该拿它做什么"整句交给注入通道的引导语。于是这里
44
44
  * 既没有标题也没有"可委派给下列子智能体"那句:一处内容只有一个出处。
45
45
  */
@@ -50,13 +50,13 @@ export function renderSubagentCatalog(allowed, maxEntries = DEFAULT_CATALOG_MAX_
50
50
  const shown = sorted.slice(0, Math.max(0, maxEntries));
51
51
  const lines = shown.map((p) => '- **' + p.name + '** — ' + (catalogDescription(p.description, maxDescription) || NO_DESCRIPTION) + (p.continuable === true ? CONTINUABLE_MARK : ''));
52
52
  const hidden = sorted.length - shown.length;
53
- // 只给清单。"这是什么"与"该拿它做什么"由注入通道的框架交代 —— 2026-09-18 起是
53
+ // 只给清单。"这是什么"与"该拿它做什么"由注入通道的框架交代 —— 起是
54
54
  // context-inject.ts 的 `DOMAIN_FRAME.subagents`(标题 + 加粗的动作句 + 工具名行)。
55
55
  // 这里原本还有 `## 子智能体` 标题与一句加粗的「可委派给下列子智能体(调 `subagent_manager_run`)。」
56
- // —— 加上引导语,同一件事说了三遍(用户 2026-09-17 指出)。正文从此只管排版。
56
+ // —— 加上引导语,同一件事说了三遍(用户 指出)。正文从此只管排版。
57
57
  const out = [...lines];
58
58
  // 查询工具**只在真被 40 条上限截掉时**才出现:常态下不提,省常驻字符,也免得模型为了
59
- // 「确认一遍」去调它(用户裁定:没列出来的就是当前不想要的)。与 MCP 状态段的
59
+ // 「确认一遍」去调它(没列出来的就是当前不想要的)。与 MCP 状态段的
60
60
  // `(${N} more not listed.)` 同一句式,但这里多给一个出口——不给人设就真的找不回来了。
61
61
  if (hidden > 0) {
62
62
  // 与技能目录同一条纪律:点名一个被关掉的工具只会让模型去猜名字。数量照报。
@@ -77,22 +77,49 @@ export function createSubagentCatalog(deps, opts = {}) {
77
77
  const maxDescription = opts.maxDescription ?? DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH;
78
78
  const ttlMs = opts.ttlMs ?? 1000;
79
79
  const now = opts.now ?? (() => Date.now());
80
- let allowed = [];
80
+ let docs = [];
81
+ let globalSceneLists = [];
82
+ /** 全局口径的可见集合(正在用的场景绑定 ∩ 全局启停)—— 每次重算从 docs 推一次。 */
83
+ let globalAllowed = new Set();
81
84
  let loadedAt = Number.NEGATIVE_INFINITY;
82
85
  let inflight = null;
83
- // 渲染结果按**深度 + 尾句前提**缓存:过滤只依赖深度这一个整数(实际出现的深度就 0/1/2 三档),
84
- // 而尾句点不点名 `subagent_manager_list` 取决于**这个 agent 手里有没有它**(2026-10-14
85
- // 审查 P1-8:此前只按深度缓存,于是尾句用的是第一个来问的 agent 的答案)。
86
- // 两维都是小枚举,于是"每个 step 同步渲染"退化成一次查表。重算成功时清空。
86
+ // 渲染结果按**深度 + 尾句前提 + 会话层指纹**缓存:过滤只依赖这三样。
87
87
  const rendered = new Map();
88
88
  const recompute = async () => {
89
89
  try {
90
- allowed = (await filterBySceneBinding(await deps.list(), await deps.sceneLists())).allowed;
90
+ docs = await deps.list();
91
+ globalSceneLists = await deps.sceneLists();
92
+ globalAllowed = new Set(filterBySceneBinding(docs, globalSceneLists).allowed
93
+ .filter((p) => p.enabled !== false)
94
+ .map((p) => p.name));
91
95
  rendered.clear();
92
96
  }
93
97
  catch { /* 保留上一次的值;首次失败则维持 [] */ }
94
98
  loadedAt = now();
95
99
  };
100
+ /**
101
+ * 某个 agent 该列的人设:四层并值(`flagFor`)优先;这一层没话说就落到全局口径。
102
+ *
103
+ * 会话层**能救回**场景绑定的排除项("进入场景之后还想开什么就开什么")—— 所以这里不再
104
+ * 先按场景过滤再按覆盖过滤,而是逐条问一句"本会话怎么判",只有判不出来时才用全局集合。
105
+ */
106
+ const listedFor = (agent, depth) => {
107
+ let flag;
108
+ try {
109
+ flag = deps.flagFor ? deps.flagFor(agent) : undefined;
110
+ }
111
+ catch {
112
+ flag = undefined;
113
+ }
114
+ return docs.filter((p) => {
115
+ if (!catalogInjectedAt(p, depth))
116
+ return false;
117
+ const f = flag ? flag(p.name) : undefined;
118
+ if (typeof f === 'boolean')
119
+ return f;
120
+ return globalAllowed.has(p.name);
121
+ });
122
+ };
96
123
  const revalidate = () => {
97
124
  if (inflight)
98
125
  return inflight;
@@ -105,15 +132,22 @@ export function createSubagentCatalog(deps, opts = {}) {
105
132
  void revalidate();
106
133
  const depth = subagentDepthOf(agent);
107
134
  const visible = deps.listToolVisible ? deps.listToolVisible(agent) : true;
108
- const key = depth + '|' + (visible ? '1' : '0');
109
- const cached = rendered.get(key);
110
- if (cached !== undefined)
111
- return cached;
112
- const out = renderSubagentCatalog(allowed.filter((p) => catalogInjectedAt(p, depth)), maxEntries, maxDescription, visible);
113
- rendered.set(key, out);
135
+ const hasLayer = deps.flagFor !== undefined && deps.flagFor(agent) !== undefined;
136
+ // 有会话层但装配层没给指纹(老装配 / 测试)时不走渲染缓存:宁可多算一次。
137
+ const cacheable = !hasLayer || deps.layerKeyFor !== undefined;
138
+ const layerKey = deps.layerKeyFor ? deps.layerKeyFor(agent) : '';
139
+ const key = layerKey + '\u0000' + depth + '|' + (visible ? '1' : '0');
140
+ if (cacheable) {
141
+ const cached = rendered.get(key);
142
+ if (cached !== undefined)
143
+ return cached;
144
+ }
145
+ const out = renderSubagentCatalog(listedFor(agent, depth), maxEntries, maxDescription, visible);
146
+ if (cacheable)
147
+ rendered.set(key, out);
114
148
  return out;
115
149
  },
116
- catalogVisibleAt: (depth) => allowed.some((p) => catalogInjectedAt(p, depth)),
150
+ catalogVisibleAt: (depth, agent) => listedFor(agent, depth).length > 0,
117
151
  refresh: () => {
118
152
  loadedAt = Number.NEGATIVE_INFINITY;
119
153
  return revalidate();
@@ -1,10 +1,8 @@
1
- // Agent Preset helpers for persona-scoped child composition.
1
+ // 给「按人设隔离的子组合」用的 Agent Preset 辅助。
2
2
  //
3
- // DSH 0.2.1 removed persona/toolFilter from SubagentStartRequest. A spawn child
4
- // can still select an independent preset, so this module clones the parent's
5
- // declared preset, replaces its persona row, and registers a short-lived preset
6
- // id for that child. The clone is mounted by the official registry; nothing in
7
- // the official package is patched.
3
+ // 官方从 `SubagentStartRequest` 里拿掉了 persona / toolFilter,而 spawn 出来的子会话仍可以
4
+ // 选一份独立预设。所以这里复制父会话声明的那份预设、替换其中的人设行,为子会话注册一个
5
+ // 短命的预设 id。克隆体由官方 registry 挂载 —— 官方包里一个字节都不改。
8
6
  import { createHash } from 'node:crypto';
9
7
  import { JSON_SCHEMA, Type, load } from 'js-yaml';
10
8
  import { renderPersonaPrompt } from './persona-parse.js';
@@ -44,8 +42,7 @@ function cloneEntry(value) {
44
42
  function isPersonaOrPresetSwitch(row) {
45
43
  if (row.name === '@deepseek-ai/dsh-persona')
46
44
  return true;
47
- // A custom preset row would replace the whole composition; cloning it would
48
- // silently change the parent instead of merely overriding its persona.
45
+ // 自定义预设行会替换整个组合;复制它等于悄悄改掉父会话,而不只是覆盖人设。
49
46
  return row.name === '@deepseek-ai/dsh-agent-preset';
50
47
  }
51
48
  function removePersonaRows(rows) {
@@ -69,7 +66,7 @@ function removePersonaRows(rows) {
69
66
  }
70
67
  return kept;
71
68
  }
72
- /** Read the parent preset's declared rows and return a child definition. */
69
+ /** 读父预设声明的那几行,拼出一份子预设定义。 */
73
70
  export async function childPresetDefinition(parentAgent, persona) {
74
71
  const parentCtx = parentAgent?.ctx;
75
72
  const roster = presetRosterOf(parentCtx);
@@ -100,7 +97,7 @@ export async function childPresetDefinition(parentAgent, persona) {
100
97
  config: { prefix: renderPersonaPrompt(persona) },
101
98
  });
102
99
  // hash 必须覆盖**父预设的组合正文**:同一个 id 的内容可以被 profile 补丁改写,只按
103
- // id + 人设定哈希会让改过的内容继续复用旧定义(冷恢复/追问时加载的是上一版插件树)。
100
+ // id + 人设定哈希会让改过的内容继续复用旧定义(冷恢复/追问时加载的是上一次构建的插件树)。
104
101
  const hash = createHash('sha256')
105
102
  .update(parentPresetId)
106
103
  .update('\0')