dsh-plugin-tool-management 0.21.2 → 0.21.4

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 +62 -1
  2. package/README.md +3 -5
  3. package/README_EN.md +3 -3
  4. package/docs/{update.md → UPDATE.md} +35 -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 +469 -171
  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 +274 -243
  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 +38 -18
  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 +144 -40
  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 +16 -15
  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 +63 -36
  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 +4 -3
@@ -31,7 +31,7 @@ function reportNativeDeleteAvailable(entry) {
31
31
  * 独立归档门面:消费当前宿主服务,不注册或替换 workspaceRegistry。
32
32
  * 外部服务有原生接口时优先委托;官方缺口由受检查的兼容层补齐。
33
33
  *
34
- * 实测边界(2026-09-14,对抗式审查):现装宿主**没有任何**原生归档扩展接口
34
+ * 实测边界:现装宿主**没有任何**原生归档扩展接口
35
35
  * ——全量 grep `archivedSessionDetails` / `deleteArchivedSessions` / `unarchiveSessions`
36
36
  * 均不存在,`@michengai/dsh-archive-manager` 也未安装。因此下面所有
37
37
  * `typeof this.registry.X === "function"` 的委托分支在当前环境**都是死代码**,
@@ -57,17 +57,18 @@ function reportNativeDeleteAvailable(entry) {
57
57
  * 兼容层不拦截官方的 indexHeader,因此不承诺修正外部后端返回陈旧列表的行为。
58
58
  */
59
59
  /**
60
- * Compatibility adapter for the official JSONL backend's session-owned layout.
61
- * A generic locate() path does NOT grant ownership of its parent directory.
62
- * Unknown backends/layouts keep artifact-only deletion. Do not prune ancestors.
60
+ * 官方 JSONL 后端「会话自有目录」布局的兼容适配。
61
+ *
62
+ * 通用 `locate()` 给出的路径**不**代表它的父目录也归本插件管;后端或布局不认识时只删
63
+ * transcript 产物,绝不去修剪上级目录。
63
64
  */
64
65
  function jsonlSessionDirectory(persistence, header, location) {
65
66
  if (persistence.name !== "session-persistence-jsonl" ||
66
67
  location.kind !== "jsonl")
67
68
  return;
68
- // Official JSONL stores its resolved root at construction. Re-resolving a
69
- // relative config.root after process.chdir() would point to a different store.
70
- // This backend-specific field is optional; only absolute config is a safe fallback.
69
+ // 官方 JSONL 在构造时就把解析好的根存下来。`process.chdir()` 之后再解析相对的
70
+ // config.root 会指到另一个存储。这个后端专属字段是可选的;只有**绝对路径**的
71
+ // config.root 才能当退路。
71
72
  const root = persistence.root ?? persistence.config?.root;
72
73
  if (typeof root !== "string" ||
73
74
  !isAbsolute(root) ||
@@ -78,7 +79,7 @@ function jsonlSessionDirectory(persistence, header, location) {
78
79
  return;
79
80
  if (typeof header.id !== "string" || header.id.length === 0)
80
81
  return;
81
- // Upstream encodes UTF-16 code units as ~XXXX (including lone surrogates).
82
+ // 上游把 UTF-16 码元写成 ~XXXX(孤立代理项也一样)。
82
83
  const encode = (text) => text.replace(/[^A-Za-z0-9._-]/g, (ch) => `~${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`);
83
84
  const segment = header.id === "."
84
85
  ? "~002E"
@@ -128,8 +129,8 @@ function defaultArchivedAtFile() {
128
129
  function defaultWorkspaceSnapshotFile() {
129
130
  return hubPath("history-workspaces.json");
130
131
  }
131
- // Standalone facade over the existing registry. Never instantiate/register a
132
- // second WorkspaceRegistry, and never open another copy of its storage domain.
132
+ // 套在既有 registry 外面的独立门面:绝不实例化 / 注册第二个 WorkspaceRegistry,
133
+ // 也绝不再打开一份它的存储域。
133
134
  var ArchiveWorkspaceRegistry = class {
134
135
  /** 宿主注入的上下文(服务读取按动态面处理,见 `HostContext`)。 */
135
136
  ctx;
@@ -232,8 +233,7 @@ var ArchiveWorkspaceRegistry = class {
232
233
  }
233
234
  }
234
235
  for (const id of ids) {
235
- // Existing entries without a timestamp must get a full retention window,
236
- // never be expired using their potentially much older creation time.
236
+ // 没有时间戳的存量条目要给满一个保留窗口,不能按它可能老得多的创建时间判过期。
237
237
  if (!this.archivedAtMap.has(id)) {
238
238
  this.archivedAtMap.set(id, this.registry.archivedAt?.(id) ?? Date.now());
239
239
  changed = true;
@@ -804,7 +804,7 @@ var ArchiveWorkspaceRegistry = class {
804
804
  * 后续目标并把成功、并发消失和失败分别返回给客户端。
805
805
  */
806
806
  async deleteArchivedSessions(target) {
807
- // 与单删同一条纪律(A3-1):宿主补上原生批量入口也**先不切换** —— 只上报。
807
+ // 与单删同一条纪律:宿主补上原生批量入口也**先不切换** —— 只上报。
808
808
  if (typeof this.registry.deleteArchivedSessions === "function")
809
809
  reportNativeDeleteAvailable("deleteArchivedSessions");
810
810
  // 适配路径(无宿主原生批量入口):在任何会话被删除之前确认整条链路可用。
@@ -908,7 +908,7 @@ var ArchiveWorkspaceRegistry = class {
908
908
  * 永久删除一个会话及其全部痕迹(转录目录、工作区记账、归档标记、
909
909
  * 投影缓存行)。
910
910
  *
911
- * 级联只删**已归档**的子代理会话(审查 F10);被保留的未归档子会话 id 通过
911
+ * 级联只删**已归档**的子代理会话;被保留的未归档子会话 id 通过
912
912
  * `keptUnarchivedDescendants` 回给调用方,界面据此如实呈现,不假装整支都没了。
913
913
  * @param sessionId - 要删除的会话。
914
914
  * @returns `{ deleted: true }`,有被保留的未归档子会话时附带其 id。
@@ -936,7 +936,7 @@ var ArchiveWorkspaceRegistry = class {
936
936
  return await this.deleteLocalSession(sessionId, storedIndex);
937
937
  }
938
938
  catch (error) {
939
- // Failed deletion must not permanently suppress a still-live session.
939
+ // 删除失败不能把还活着的会话永久压住(否则它再也不会被列出 / 归档)。
940
940
  // (`clearTombstone` 是**预留位**:宿主无此入口,实际命中的是本插件 bridge guard
941
941
  // 的墓碑 —— 说明见 `cleanupUnknownArchivedSession` 里那一处。)
942
942
  this.getProjectionCache()?.clearTombstone?.(sessionId);
@@ -974,7 +974,7 @@ var ArchiveWorkspaceRegistry = class {
974
974
  // 先记录被删生命周期的日志身份:目录删除后头部不可再读,
975
975
  // 冷复用探针(sessionKnown 墓碑分支)靠它区分同 id 的新生命周期。
976
976
  const deletedHeader = this.headers.get(sessionId) ?? live?.header;
977
- // Install the barrier BEFORE flush/detach can schedule a final cache put.
977
+ // 栅栏必须装在 flush / detach 可能排上最后一次缓存写之前。
978
978
  await this.bridge.beginDelete(sessionId, deletedHeader);
979
979
  if (live !== void 0) {
980
980
  // 持久化屏障先行:不能有未落盘的转录写入与目录删除竞争
@@ -999,7 +999,7 @@ var ArchiveWorkspaceRegistry = class {
999
999
  if (projCache !== void 0)
1000
1000
  await projCache.delete(sessionId);
1001
1001
  // 级联只吃已归档的子会话;被保留(未归档)的 id 一路带回 op 层,让界面/模型
1002
- // 知道「父会话已删,但这一支没有全没」(审查 F10)。
1002
+ // 知道「父会话已删,但这一支没有全没」。
1003
1003
  const keptDescendants = await this.deleteDescendants(sessionId, storedIndex);
1004
1004
  await this.cleanSpill(sessionId);
1005
1005
  await this.removeTranscriptDirectory(sessionId);
@@ -1068,7 +1068,7 @@ var ArchiveWorkspaceRegistry = class {
1068
1068
  }
1069
1069
  if (this.deletedSessionIds.has(id))
1070
1070
  return this.coldReuseKnown(id);
1071
- // Refresh from authoritative persistence, not the host's stale header cache.
1071
+ // 从权威持久化刷新,不用宿主那份可能过期的 header 缓存。
1072
1072
  // 批量删除会传入**批首快照**(同一批里 k 次全库 list() 是纯浪费);不传就是逐条取新鲜数据。
1073
1073
  const header = storedIndex !== void 0
1074
1074
  ? storedIndex.get(id)
@@ -1174,10 +1174,8 @@ var ArchiveWorkspaceRegistry = class {
1174
1174
  const directory = jsonlSessionDirectory(persistence, header, location);
1175
1175
  if (directory !== void 0) {
1176
1176
  target = { path: directory, kind: "session directory" };
1177
- // The configured storage root may itself be an intentional alias, but
1178
- // project/session links must not redirect recursive deletion elsewhere.
1179
- // These checks assume trusted, stable storage ancestors; lstat + rm
1180
- // is not an atomic defense against another process swapping directories.
1177
+ // 配置的存储根本身可能就是有意做的别名,但项目 / 会话链接不得把递归删除引到别处。
1178
+ // 这些检查假定存储祖先可信且稳定:lstat + rm 挡不住另一个进程在中间把目录换掉。
1181
1179
  for (const path of [dirname(directory), directory]) {
1182
1180
  let stat;
1183
1181
  try {
@@ -1256,7 +1254,7 @@ var ArchiveWorkspaceRegistry = class {
1256
1254
  * 仅头部标记 `origin: "subagent"` 的会话参与:单凭 `parentSession` 有歧义
1257
1255
  *(fork 分支也携带它),而 fork 分支是独立的用户会话,绝不能被级联删除。
1258
1256
  *
1259
- * **只级联「已归档」的子会话**(2026-09-30 审查 F10)。此前这里只按
1257
+ * **只级联「已归档」的子会话**。此前这里只按
1260
1258
  * `parentSession + origin: subagent` 收集就逐个 `deleteSessionCore`,**完全不查归档集合**,
1261
1259
  * 于是「只能删已归档」在**注册表层不成立** —— 删一个已归档父会话,会把它**未归档**的子代理
1262
1260
  * 会话一起永久删掉。op 入口那层的收敛(`history-delete` / `deleteArchivedSessions`)拦不住
@@ -11,6 +11,7 @@ import { DEFAULT_INJECT_SETTINGS, normalizeInjectSettings } from './context-inje
11
11
  import { normalizeSceneSettings } from './scene-settings.js';
12
12
  import { normalizeSlashSettings } from './slash-settings.js';
13
13
  import { normalizeSidebarSettings } from './sidebar-settings.js';
14
+ /** 设置类侧车(注入设置、工具表等)的读写门面:读宽松、写严格。 */
14
15
  export function createSettingsSidecars(deps) {
15
16
  /**
16
17
  * 写路径的 strict read:只有文件不存在才回默认值;读坏 / 解析不了一律拒绝保存。
@@ -5,6 +5,7 @@
5
5
  //
6
6
  // 为什么存服务端而不是 localStorage:与其余入口开关同一个家,换浏览器也在;存本地就
7
7
  // 只有那个浏览器认,而这条开关的用途正是"这台机器上我不想在侧栏看到它"。
8
+ /** 侧栏入口出厂值:默认显示。 */
8
9
  export const DEFAULT_SIDEBAR_SETTINGS = { enabled: true };
9
10
  /** 把任意输入夹成合法设置:读不到 / 形状不对一律按默认开启。 */
10
11
  export function normalizeSidebarSettings(raw) {
@@ -12,7 +12,6 @@
12
12
  // 与官方目录的两处有意差别:
13
13
  // - 只列**当前启用且可被模型调用**的(官方只过滤可调用性,不管用户在插件页关掉了谁)。
14
14
  // - 「本预设没有官方 `skill` 加载工具,要正文先用 `skill_manager_list` 取源文件路径」那句
15
- // 2026-09-18 起挪进注入框架的 `how` 行(context-inject.ts 的 DOMAIN_FRAME.skills)——
16
15
  // 本段只排版清单,标题与"怎么用"一处一个出处。
17
16
  //
18
17
  // 同步性:`text()` 必须同步返回(注入通道每个 step 同步取文本),而技能清单是异步读盘 →
@@ -59,7 +58,7 @@ layer) {
59
58
  continue;
60
59
  const rootKey = String(root.key ?? '');
61
60
  // 来源级停用是**上层闸**:里面的单条技能默认一条都加载不了。
62
- // 0.21.2 起这一格有会话层(skillSources):场景勾中的来源为开、没勾的为关;全局意图
61
+ // 这一格有会话层(skillSources):场景勾中的来源为开、没勾的为关;全局意图
63
62
  // off 的来源对**没认领的**会话也是关(租约只把它拉起来,不把它变成全局开着)。
64
63
  // 装配层给的 `source` 是有效可见性(含意图),undefined = 没有意图,落到运行态。
65
64
  const srcLayer = layer?.source !== undefined && rootKey !== '' ? layer.source(rootKey) : undefined;
@@ -78,7 +77,7 @@ layer) {
78
77
  // 来源闸**始终生效**:显式开一条技能时写侧会一并认领它的来源(见 ops/scope.ts 的
79
78
  // `upperOf`),所以这里不需要也不应该让技能级覆盖越过一个**明确关掉的**来源
80
79
  // —— 用户在本会话把来源关掉、界面已经把整组画成"关",注入却还列着里面某条技能,
81
- // 就是显示与上下文各说各话(0.21.2 复核)。来源开着时,显式覆盖才决定这一条。
80
+ // 就是显示与上下文各说各话。来源开着时,显式覆盖才决定这一条。
82
81
  const enabledNow = rootEnabled && (typeof over === 'boolean' ? over : isEnabled(row));
83
82
  if (!enabledNow || row.modelInvocable === false)
84
83
  continue;
@@ -98,7 +97,7 @@ layer) {
98
97
  const shown = sorted.slice(0, Math.max(0, maxEntries));
99
98
  const lines = shown.map((row) => (row.description ? '- `' + row.name + '`: ' + row.description : '- `' + row.name + '`'));
100
99
  // 只有清单:标题、工具名与"只给摘要、读完再用"的纪律由注入通道的框架承担
101
- // (2026-09-18 起,见 context-inject.ts 的 DOMAIN_FRAME 的 `how` 行)—— 一处内容一个出处。
100
+ // (见 context-inject.ts 的 DOMAIN_FRAME 的 `how` 行)—— 一处内容一个出处。
102
101
  const out = [...lines];
103
102
  const hidden = sorted.length - shown.length;
104
103
  // 查询工具被关掉(兼容页的模型工具表)时只说"还有几个":点名一个模型手里没有的工具,
@@ -114,7 +113,7 @@ layer) {
114
113
  * 本会话与**官方那份目录**的差异(纯函数)。`''` = 没有差异。
115
114
  *
116
115
  * 用途有两处:
117
- * 1. **接管判据**(0.21.2 第二轮):非空时注入侧拦下官方 `skill-catalog`(只限本会话),
116
+ * 1. **接管判据**:非空时注入侧拦下官方 `skill-catalog`(只限本会话)
118
117
  * 由 `renderSkillCatalog` 送会话版整份。用户真机发现「先注入官方清单、再补一行
119
118
  * not available here」等于让模型先看到错的再被告知不可用 —— 有差异就不能让官方那份
120
119
  * 继续到达模型。官方更早那条仍在历史里,由首份会话版的取代声明压过。
@@ -176,7 +175,7 @@ export function renderSkillCatalogDelta(data, layer) {
176
175
  return lines.join('\n');
177
176
  }
178
177
  /**
179
- * 本会话是否需要**整份接管**技能目录(0.21.2 第二轮):差异行非空就是需要。
178
+ * 本会话是否需要**整份接管**技能目录:差异行非空就是需要。
180
179
  *
181
180
  * 纯函数只为把"什么算有差异"钉在测试里:空串与纯空白都不算,其余一个字就算。
182
181
  * 判据只服务注入层(同步的 SWR 缓存),不进 `sessionMcpContextOf` 那套同步守卫路径。
@@ -188,7 +187,7 @@ export function skillCatalogNeedsTakeover(delta) {
188
187
  * 创建 SWR 的技能目录。计算失败时保留上一次的值(不把段清空),首次失败维持 `''`。
189
188
  * 并发调用共享同一次计算(inflight 折叠)。
190
189
  *
191
- * ⚠️ 缓存**按会话分桶**(0.21.2):`skill-state` 带 sessionId 时项目技能根只取该会话的
190
+ * ⚠️ 缓存**按会话分桶**:`skill-state` 带 sessionId 时项目技能根只取该会话的
192
191
  * cwd,两个会话能算出两份不同的清单。单槽缓存下 A 算完 B 直接用 —— 症状是「B 的对话里
193
192
  * 列出了 A 项目的技能」。键 = sessionId(全局口径用空串),上限 16 条 LRU。
194
193
  */
@@ -213,7 +212,7 @@ export function createSkillCatalog(deps, opts = {}) {
213
212
  dataByKey.delete(key);
214
213
  dataByKey.set(key, hit);
215
214
  };
216
- // `force`(0.21.2 第三轮):写操作后调用的那次**不许并到在飞的那一次上**。并过去的话,
215
+ // `force`:写操作后调用的那次**不许并到在飞的那一次上**。并过去的话
217
216
  // 拿回的是刷新前的旧任务 —— 它带着旧的 generation,结果会被作废,于是缓存停在旧数据,
218
217
  // 而调用方以为已经重算完了(症状:刚拨开的技能这一轮仍不出现)。
219
218
  const revalidate = (key, force = false) => {
@@ -299,10 +298,10 @@ export function createSkillCatalog(deps, opts = {}) {
299
298
  generation += 1;
300
299
  const keys = [...new Set([...dataByKey.keys(), ''])];
301
300
  inflight.clear();
302
- // **不先清空 `dataByKey`**(2026-10-22 用户实测修正):清空之后、新数据回来之前的那一拍,
301
+ // **不先清空 `dataByKey`**(用户实测修正):清空之后、新数据回来之前的那一拍,
303
302
  // `text()` / `delta()` 一律读到空 → 注入侧按"这一域没内容"发一条「已清空」,于是
304
303
  // 「对话中途拨开一条技能」的那一轮,模型收到的是「Cleared — 不再有效」,下一轮才看到
305
- // 真正的清单。留着上一份:最坏是这一拍仍是上一版(`ready()` 仍为真,不会误报清空)。
304
+ // 真正的清单。留着上一份:最坏是这一拍仍是上一份(`ready()` 仍为真,不会误报清空)。
306
305
  rendered = null;
307
306
  return Promise.all(keys.map((key) => revalidate(key, true))).then(() => { });
308
307
  },
@@ -10,7 +10,9 @@ import { basename, dirname, join, resolve } from "node:path";
10
10
  import { promises as fs } from "node:fs";
11
11
  import { randomUUID } from "node:crypto";
12
12
  import { isSameOrDescendant, isValidSegment } from "../paths.js";
13
+ /** 技能条目名长度上限 128:留足中文与后缀,又不至于撞上文件系统的 255 字节限。 */
13
14
  export const MAX_ENTRY_NAME_LENGTH = 128;
15
+ /** 可以重试的改名错误码 —— Windows 上杀毒 / 索引服务短暂占用文件就会报这三个。 */
14
16
  export const TRANSIENT_RENAME_CODES = new Set(["EACCES", "EBUSY", "EPERM"]);
15
17
  // ── 业务错误码 ────────────────────────────────────────────────────────────────
16
18
  /** 构造带 code/params 的业务 Error,供导入链路 throw 后透传到失败明细。 */
@@ -30,10 +32,12 @@ export function attachCode(item, error) {
30
32
  item.params = coded.params;
31
33
  return item;
32
34
  }
35
+ /** 用于比较的路径标识:绝对化,Windows 上再折成小写(文件系统不区分大小写)。 */
33
36
  export function pathIdentity(path) {
34
37
  const canonical = resolve(path);
35
38
  return process.platform === "win32" ? canonical.toLowerCase() : canonical;
36
39
  }
40
+ /** `lstat` 的 null 版:路径不存在返回 null,别的错误照抛。 */
37
41
  export async function lstatOrNull(path) {
38
42
  try {
39
43
  return await fs.lstat(path);
@@ -76,6 +80,7 @@ export async function renameWithRetry(source, destination, options = {}) {
76
80
  }
77
81
  }
78
82
  }
83
+ /** 目标同目录下的临时路径(同卷才能 rename),带 `kind` 便于辨认用途。 */
79
84
  export function temporaryPath(target, kind) {
80
85
  return join(dirname(target), `.${basename(target)}.dssm-${kind}-${randomUUID()}`);
81
86
  }
@@ -28,25 +28,25 @@ export { parseSkillDoc, toKebab, unquote, yamlScalar, yamlFieldLines, rewriteFro
28
28
  // 官方内置技能段与 home 解析拆到同目录的 official.ts / homes.ts 后,core.js 的公开面照旧
29
29
  // (hub.ts、memories/*、subagents/service.ts 都按 ../skills/core.js 引 resolveDshHome)。
30
30
  export { resolveAgentsHome, resolveDshHome } from "./homes.js";
31
- // 业务错误码 / 条目路径谓词 / 可恢复 rename 的重试这一层 2026-10-01 剥到 ./core-util.js:
31
+ // 业务错误码 / 条目路径谓词 / 可恢复 rename 的重试这一层 剥到 ./core-util.js:
32
32
  // 这几件被导入链路与技能读写**两侧同时**用到,留在本文件里就意味着任何搬出去的段都要反过来
33
33
  // 引 core —— 那是运行时环。搬到这里,两侧都只向下引这一层。公开面照旧:entryPath 与
34
34
  // renameWithRetry 仍有外部引方(index.ts 按 ./skills/core.js 引 renameWithRetry)。
35
35
  export { entryPath, renameWithRetry } from "./core-util.js";
36
- // 来源与路径底座(四来源 / 项目级来源 / root-state-trash 路径 / 路径比较口径)2026-10-01
36
+ // 来源与路径底座(四来源 / 项目级来源 / root-state-trash 路径 / 路径比较口径)
37
37
  // 剥到 ./skill-roots.js。那一层只向下引 ./official.js / ./homes.js / ./core-util.js,
38
38
  // 不回引本文件;userRoots / projectRoots / trashRootPath 有外部引方(service.ts、
39
39
  // system-trash.ts),而 core.js 的公开面里还挂着另外四件 —— 全部照旧从 core.js 出口走。
40
40
  export { customRootKey, isDefaultSkillSource, managerHomePath, managerStatePath, projectRoots, trashRootPath, userRoots, } from "./skill-roots.js";
41
- // 上传落盘链路(Base64 目录 / ZIP 校成来源、写进技能根目录)2026-10-01 剥到
41
+ // 上传落盘链路(Base64 目录 / ZIP 校成来源、写进技能根目录)剥到
42
42
  // ./upload-pipeline.js;它向下引 core-util / import-pipeline / skill-roots 三层,不回引本文件。
43
43
  // service.ts 按 ./core.js 引这两件,公开面照旧再出口一次。
44
44
  export { importSkill, importUploadedSkill } from "./upload-pipeline.js";
45
- // 技能回收站(可写根判定 / 移进移出 / 清单读写)2026-10-01 剥到 ./skill-trash.js。
45
+ // 技能回收站(可写根判定 / 移进移出 / 清单读写)剥到 ./skill-trash.js。
46
46
  // 四件本来在 core.js 的出口上(外部按 ./core.js 引),照旧再出口一次。
47
47
  export { listTrash, permanentlyDeleteTrash, readTrashMetadata, restoreTrash } from "./skill-trash.js";
48
48
  import { checkedWritableRootDefinition, movePathWithFallback, safeExistingEntryPaths, trashRootMetadata, } from "./skill-trash.js";
49
- // manager 状态层(状态文档与归一 / 启停策略 / 来源扫描去重)2026-10-01 剥到 ./manager-state.js:
49
+ // manager 状态层(状态文档与归一 / 启停策略 / 来源扫描去重)剥到 ./manager-state.js:
50
50
  // 那三件事共用一份进程内 singleton state,拆成两层就得让一层去引另一层的私有状态,等于没拆。
51
51
  // readManagerState / effectiveSkillPolicy / entryOf 等本来挂在 core.js 的出口上(兄弟模块按
52
52
  // ./core.js 引),照旧再出口一次。
@@ -68,7 +68,7 @@ const MAX_BROWSE_ENTRIES = 500;
68
68
  /**
69
69
  * 默认来源:插件自己的读写根 —— `dsh`(官方技能目录)与 `hub`(新建/导入落点)。
70
70
  *
71
- * 用户裁定的是**不对称**语义,两个方向必须成对记住,只改一半就是漏改:
71
+ * 用户要求的是**不对称**语义,两个方向必须成对记住,只改一半就是漏改:
72
72
  *
73
73
  * - 来源**路径**:必须读取。既不能「移除来源」(连目录都不扫),也不能「停用来源」
74
74
  * (仍然扫描但仍算不读取的策略位)—— 界面上没有来源开关,服务端也拒绝这两个写操作。
@@ -698,7 +698,7 @@ export async function setSkillEnabled(root, name, enabled, log) {
698
698
  return setPolicySkillEnabled(root, name, enabled, log);
699
699
  }
700
700
  /**
701
- * 批量显式停用技能(v0.8.5:新建 / 导入 / 回收站恢复默认不启动 —— 用户裁定)。
701
+ * 批量显式停用技能(新建 / 导入 / 回收站恢复默认不启动)。
702
702
  * 直接写 disabledSkills 名单(与 setSkillEnabled 同一张表),不做 frontmatter 等
703
703
  * 二次校验——调用方传入的必然是刚落盘/刚恢复的条目。
704
704
  * 必须在调用方的写锁(service 的 write())内执行。
@@ -723,7 +723,7 @@ export async function markSkillsDisabled(entries, log) {
723
723
  * 少了这一步,「显式启用过 → 删除 → 从回收站恢复」这条链会把同一个名字同时留在两份名单
724
724
  * 上(删除不清策略、恢复又要默认停用),整份状态随即被判非法 —— 插件 fail-closed 停用
725
725
  * **所有**技能,而且 `writable` 一并变 false,用户在界面上连一个开关都按不动,等于被锁死在
726
- * 一份自己造不出来的状态上(用户 2026-10-14 实测踩到)。
726
+ * 一份自己造不出来的状态上(用户 实测踩到)。
727
727
  *
728
728
  * 摘除要放在下面那个 `continue` **之前**:名字已经在 disabled 里、却还挂在 enabled 上
729
729
  * (就是被锁死的那份文件的形状)时,`continue` 会把清理一并跳过去。
@@ -894,7 +894,7 @@ export async function deleteSkill(root, name, log, options = {}) {
894
894
  params: { name },
895
895
  };
896
896
  const targets = await safeExistingEntryPaths(definition.path, name);
897
- // 回收站条目 id 走五个域共用的那个生成器(2026-10-15 smoke-test P1-7):此前这里另写了一套
897
+ // 回收站条目 id 走五个域共用的那个生成器:此前这里另写了一套
898
898
  // `${Date.now()}-${randomUUID()}`,于是同一次操作里记忆/人设/场景/提示词拿到 `mv8faxqe-…`
899
899
  // 这种形状、技能拿到 `1792001296466-62d3d393-…`。模型按 `action=list` 的 id 跨域 restore,
900
900
  // 两种长相只会让它多猜一层。读侧只校验单个合法路径段,旧条目照旧能列、能恢复。
@@ -969,7 +969,7 @@ export async function deleteSkill(root, name, log, options = {}) {
969
969
  /**
970
970
  * 一个上传路径段会不会被文件系统**改写**成别的东西。
971
971
  *
972
- * 为什么必须单判这一条(2026-09-30 审查 P2-17,实为路径逃逸而非口径分叉):
972
+ * 为什么必须单判这一条:
973
973
  * 下面的 `part === ".."` 只挡**恰好**是 `..` 的段,而 Windows 的路径归一化会把段尾的
974
974
  * **点与空格**静默裁掉 —— `.. `(`..` 加一个空格)在 `CreateFileW` / `CreateDirectoryW`
975
975
  * 眼里就是 `..`。于是 `join(contentRoot, ".. ", "x")` 看着在根内(`isSameOrDescendant`
@@ -996,9 +996,10 @@ export async function deleteSkill(root, name, log, options = {}) {
996
996
  function yamlString(value) {
997
997
  return JSON.stringify(String(value));
998
998
  }
999
+ /** 新建一条技能,按落点写到对应根下。 */
999
1000
  export async function createSkill(input, log, options = {}) {
1000
- // 默认落点是「DSH 技能目录」(用户裁定 2026-10-15 改回):v0.4-v0.20.0 期间这里是 hub。
1001
- // hub(`tool-management/skills/`)现在只服务「导入技能」功能 —— 那边走
1001
+ // 默认落点是「DSH 技能目录」。hub(`tool-management/skills/`)只服务
1002
+ // 「导入技能」功能 —— 那边走
1002
1003
  // `skillCreateRootPath()`,不经这里。调用方显式传 options.root(如项目根)时仍以调用方为准。
1003
1004
  const requestedRoot = Object.prototype.hasOwnProperty.call(options, "root")
1004
1005
  ? options.root
@@ -1205,7 +1206,7 @@ export async function updateSkill(input, log, options = {}) {
1205
1206
  log("update", `更新 ${existingDoc}`);
1206
1207
  return { name, path: existingDoc, root: definition.key };
1207
1208
  }
1208
- /** 详情弹窗列出的 bundle 附件上限:再多就不是给人看的清单了(2026-10-16)。 */
1209
+ /** 详情弹窗列出的 bundle 附件上限:再多就不是给人看的清单了。 */
1209
1210
  const MAX_DETAIL_ATTACHMENTS = 200;
1210
1211
  const MAX_DETAIL_ATTACHMENT_DEPTH = 6;
1211
1212
  /**
@@ -1258,6 +1259,14 @@ async function listBundleAttachments(dir) {
1258
1259
  files.sort((a, b) => a.path.localeCompare(b.path));
1259
1260
  return { files, truncated };
1260
1261
  }
1262
+ /**
1263
+ * 一条技能的详情:正文、元数据与随包附件清单。
1264
+ *
1265
+ * @param keyOrRoot 来源 key,或已解析好的来源定义(自定义来源由 service 层解析后传入)
1266
+ * @param name 技能名(frontmatter 里的声明名,不是文件夹名)
1267
+ * @param options.projectCwds 项目来源要在这些工作区里解析
1268
+ * @returns 成功时带正文与附件清单;来源未知 / 技能不存在 / 不可加载时返回带 `code` 的失败回执
1269
+ */
1261
1270
  export async function skillDetail(keyOrRoot, name, options = {}) {
1262
1271
  const scopedRoots = await projectRoots(options.projectCwds);
1263
1272
  // 支持传 key 或 definition(自定义来源由 service 层解析后传入)。
@@ -1318,7 +1327,7 @@ export async function skillDetail(keyOrRoot, name, options = {}) {
1318
1327
  /**
1319
1328
  * 生成 manager provider 候选:保留禁用候选以阻止低优先级重名副本意外激活。
1320
1329
  *
1321
- * **同名首选必须传进分组**(2026-09-30 审查 F8)。此前这里调
1330
+ * **同名首选必须传进分组**。此前这里调
1322
1331
  * `groupLoadableSkillsByName(items)` 时没带 `preferred`,而管理页(`markWinners`)带了 ——
1323
1332
  * 于是「同名首选」只在界面上生效:用户把 A 设为首选,界面把 A 标成「同名首选」、把 B 标成
1324
1333
  * 「被覆盖」,模型侧却仍按 rank 拿到 B。**界面说的和模型用的不是同一份**,且没有任何一处报错。
@@ -1406,6 +1415,17 @@ export async function listProviderCandidates(options = {}) {
1406
1415
  }
1407
1416
  return candidates;
1408
1417
  }
1418
+ /**
1419
+ * 按候选取回技能正文 —— 宿主 provider 的 `get()` 走这里。
1420
+ *
1421
+ * 候选里的 locator 是**上一次扫描时的快照**,取回时必须逐项复核(来源、声明名、真实路径、
1422
+ * 文档真实路径):任何一项对不上就返回 `undefined`,让宿主回落到别的 provider。返回 `undefined`
1423
+ * 与返回空正文是两件事 —— 前者表示「这条我不认」,后者会被模型当成一份空技能。
1424
+ *
1425
+ * @param candidate 扫描阶段产出的候选(含 locator)
1426
+ * @param options.cwd 项目来源要在哪个工作区里重新解析
1427
+ * @returns 技能正文与元数据;候选失效、路径对不上或读取失败时为 `undefined`
1428
+ */
1409
1429
  export async function getProviderSkill(candidate, options = {}) {
1410
1430
  const locator = candidate && candidate.locator;
1411
1431
  if (!locator ||
@@ -1424,7 +1444,7 @@ export async function getProviderSkill(candidate, options = {}) {
1424
1444
  // `rootByKey()` 恒取不到。少了这一支就是「列得出、调不动」:`state()` 扫的是
1425
1445
  // `userRoots() + customRootsFromState()`,官方 catalog 因此把目录里的技能列给模型,
1426
1446
  // 而模型真去 `skill` 工具取正文时这里返回 undefined —— 症状是
1427
- // `skill "brainstorming" is unknown or no longer available`(用户 2026-09-22 报的)。
1447
+ // `skill "brainstorming" is unknown or no longer available`(用户反馈的)。
1428
1448
  if (!root &&
1429
1449
  CUSTOM_ROOT_KEY_RE.test(locator.rootKey)) {
1430
1450
  root = customRootsFromState((await readManagerState()).state).find((item) => item.key === locator.rootKey);
@@ -1466,11 +1486,4 @@ export async function getProviderSkill(candidate, options = {}) {
1466
1486
  }
1467
1487
  }
1468
1488
  // ── 状态快照 ────────────────────────────────────────────────────────────────
1469
- /**
1470
- * 真实路径去重后按声明名分组;管理页与当前工作区 provider 共用来源优先级。
1471
- *
1472
- * `preferred`(技能名 → 来源 key)是用户对同名技能的显式选择:命中的来源排到同名前,
1473
- * 其余仍按来源 rank 排序;未命中(或键已失效)时退化为纯 rank 顺序。
1474
- */
1475
- /** DSH、常见 Agent、自定义目录与活动 Session 项目根的技能快照。 */
1476
1489
  export { KEBAB_RE };
@@ -25,10 +25,11 @@ export function parseSkillDoc(text) {
25
25
  const fields = [];
26
26
  let body = src;
27
27
  let hasFrontmatter = false;
28
- if (lines.length > 0 && lines[0].trim() === "---") {
28
+ // split 至少返回一个元素,所以只判首行在不在,不再重复判长度。
29
+ if (lines[0] != null && lines[0].trim() === "---") {
29
30
  let end = -1;
30
31
  for (let i = 1; i < lines.length; i++) {
31
- if (lines[i].trim() === "---") {
32
+ if (lines[i]?.trim() === "---") {
32
33
  end = i;
33
34
  break;
34
35
  }
@@ -36,30 +37,37 @@ export function parseSkillDoc(text) {
36
37
  if (end >= 0) {
37
38
  hasFrontmatter = true;
38
39
  for (let i = 1; i < end; i++) {
39
- const m = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(lines[i]);
40
+ // end 是 lines 的合法下标,循环体内 lines[i] 恒存在。
41
+ const line = lines[i];
42
+ const m = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(line);
40
43
  if (m) {
41
- fields.push({ key: m[1], raw: m[2] });
42
- const block = /^([>|])[-+]?\s*$/.exec(m[2]);
44
+ // 该正则两个捕获组都非可选,命中即恒为 string。
45
+ const key = m[1];
46
+ const raw = m[2];
47
+ fields.push({ key, raw });
48
+ const block = /^([>|])[-+]?\s*$/.exec(raw);
43
49
  if (block) {
44
50
  const content = [];
45
- while (i + 1 < end &&
46
- (/^\s/.test(lines[i + 1]) || lines[i + 1] === "")) {
51
+ while (i + 1 < end) {
52
+ const next = lines[i + 1];
53
+ if (!/^\s/.test(next) && next !== "")
54
+ break;
47
55
  i++;
48
- content.push(lines[i]);
56
+ content.push(next);
49
57
  }
50
58
  const indentation = content
51
59
  .filter((line) => line.trim() !== "")
52
- .reduce((min, line) => Math.min(min, (/^\s*/.exec(line) || [""])[0].length), Infinity);
60
+ .reduce((min, line) => Math.min(min, (/^\s*/.exec(line)?.[0] ?? "").length), Infinity);
53
61
  const normalized = content.map((line) => Number.isFinite(indentation)
54
62
  ? line.slice(Math.min(indentation, line.length))
55
63
  : line);
56
- map[m[1]] =
64
+ map[key] =
57
65
  block[1] === ">"
58
66
  ? normalized.join(" ").replace(/\s+/g, " ").trim()
59
67
  : normalized.join("\n").trim();
60
68
  }
61
69
  else {
62
- map[m[1]] = decodeYamlScalar(m[2]);
70
+ map[key] = decodeYamlScalar(raw);
63
71
  }
64
72
  }
65
73
  }
@@ -85,6 +93,7 @@ export function decodeYamlScalar(v) {
85
93
  return s.slice(1, -1).replace(/''/g, "'");
86
94
  return s;
87
95
  }
96
+ /** 去掉 frontmatter 值两侧的引号并 trim;不是字符串时按空串处理。 */
88
97
  export function unquote(v) {
89
98
  const s = String(v == null ? "" : v).trim();
90
99
  if (s.length >= 2 &&
@@ -152,7 +161,7 @@ export function rewriteFrontmatterFields(text, updates, body) {
152
161
  let end = -1;
153
162
  if (lines[0] != null && lines[0].trim() === "---") {
154
163
  for (let i = 1; i < lines.length; i++) {
155
- if (lines[i].trim() === "---") {
164
+ if (lines[i]?.trim() === "---") {
156
165
  end = i;
157
166
  break;
158
167
  }
@@ -176,12 +185,15 @@ export function rewriteFrontmatterFields(text, updates, body) {
176
185
  const seen = new Set();
177
186
  let i = 0;
178
187
  while (i < front.length) {
179
- const m = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(front[i]);
188
+ // i < front.length,所以这一行恒存在。
189
+ const line = front[i];
190
+ const m = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(line);
180
191
  if (!m) {
181
- out.push(front[i]);
192
+ out.push(line);
182
193
  i++;
183
194
  continue;
184
195
  }
196
+ // 该正则两个捕获组都非可选,命中即恒为 string。
185
197
  const key = m[1];
186
198
  const isBlock = /^[>|][-+]?\s*$/.test(m[2]);
187
199
  let spanEnd = i + 1;
@@ -6,9 +6,11 @@
6
6
  import { homedir } from "node:os";
7
7
  import { join } from "node:path";
8
8
  // ── 路径解析 ────────────────────────────────────────────────────────────────
9
+ /** DSH 主目录:`$DSH_HOME`,缺省 `~/.dsh`。 */
9
10
  export function resolveDshHome() {
10
11
  return process.env.DSH_HOME || join(homedir(), ".dsh");
11
12
  }
13
+ /** 共享 agents 根:`$DSH_AGENTS_HOME`,缺省 `~/.agents`。 */
12
14
  export function resolveAgentsHome() {
13
15
  return process.env.DSH_AGENTS_HOME || join(homedir(), ".agents");
14
16
  }
@@ -5,13 +5,15 @@
5
5
  //
6
6
  // 为什么这一层要独立:它是「导入」这条链的下半段,向下只引 ./core-util.js 与 node:* /
7
7
  // ../paths.js,**不回引 core.js** —— 所以 core.js 反过来引它是单向的,加载图无环。
8
- // 留在 core.ts 里时,任何想把上传/导入段搬出去的尝试都会撞到这个环上(0.18.0 试过一回,
8
+ // 留在 core.ts 里时,任何想把上传/导入段搬出去的尝试都会撞到这个环上(试过一回,
9
9
  // 判给不做就是这个原因)。
10
10
  import { basename, dirname, join } from "node:path";
11
11
  import { promises as fs } from "node:fs";
12
12
  import { attachCode, codedError, lstatOrNull, renameWithRetry, temporaryPath } from "./core-util.js";
13
13
  import { toKebab } from "./frontmatter.js";
14
+ /** 目录扫描的最大深度:防止链接环或病态目录树把导入拖死。 */
14
15
  export const MAX_SOURCE_DEPTH = 64;
16
+ /** 看一眼来源路径:是目录还是文件、是不是技能(有 `SKILL.md`)。 */
15
17
  export async function analyzeSource(source) {
16
18
  let st;
17
19
  try {
@@ -84,6 +86,7 @@ export async function analyzeSource(source) {
84
86
  params: { path: source },
85
87
  };
86
88
  }
89
+ /** 列出目录下的候选技能条目(一层,不下钻)。 */
87
90
  export async function collectCandidates(dir) {
88
91
  const items = await fs.readdir(dir, { withFileTypes: true });
89
92
  const out = [];
@@ -118,6 +121,7 @@ export async function collectCandidates(dir) {
118
121
  }
119
122
  return out;
120
123
  }
124
+ /** 来源树里不允许有符号链接(防止导入把链接目标一起复制出去)。 */
121
125
  export async function assertNoSymbolicLinks(source) {
122
126
  const pending = [
123
127
  { path: source, depth: 0 },
@@ -142,6 +146,7 @@ export async function assertNoSymbolicLinks(source) {
142
146
  }
143
147
  }
144
148
  }
149
+ /** 导入前的预检:逐条判定「可导入 / 重名冲突 / 不合格」,结果就地写回三个入参数组。 */
145
150
  export async function preflightCandidates(pending, conflicts, failed) {
146
151
  for (const group of [pending, conflicts]) {
147
152
  for (let i = group.length - 1; i >= 0; i--) {
@@ -160,6 +165,7 @@ export async function preflightCandidates(pending, conflicts, failed) {
160
165
  }
161
166
  }
162
167
  }
168
+ /** 先复制到目标同目录的临时路径,返回该临时路径(尚未替换目标)。 */
163
169
  export async function copyToTemporary(source, target, isDir) {
164
170
  const temp = temporaryPath(target, "stage");
165
171
  try {
@@ -176,6 +182,7 @@ export async function copyToTemporary(source, target, isDir) {
176
182
  throw error;
177
183
  }
178
184
  }
185
+ /** 用一份新复制替换目标:先备份旧内容,替换失败则回滚,成功后再删备份。 */
179
186
  export async function replaceWithCopy(source, dest, isDir, existing = []) {
180
187
  const stage = await copyToTemporary(source, dest, isDir);
181
188
  const backups = [];