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
@@ -3,19 +3,16 @@ import { workspaceDomainSpec } from "@deepseek-ai/dsh-workspace";
3
3
  import { assessHost, routeFor, refusalsFor, CapabilityRefusalError } from "../compat/probe.js";
4
4
  import { noteRuntime } from "../compat/runtime-notes.js";
5
5
  export { CapabilityRefusalError };
6
- // No Service subclass, no ctx.provide(), no second storage-domain owner.
7
- // The official API lacks unarchive and a cache deletion barrier, so this file
8
- // adapts the gaps. WHICH parts of the host it may touch is decided by
9
- // ../compat/probe.ts from live, observable facts (module identity, member
10
- // presence, shapes, read-only behaviour), never from comparing source text:
11
- // text equality only ever proved "same release", and it turned every harmless
12
- // upstream refactor into a total feature outage.
6
+ // 不继承 Service、不 ctx.provide()、不当第二个存储域的主人。官方 API 缺 unarchive
7
+ // 与缓存删除屏障,本文件只补这两个缺口。「能碰宿主哪些部分」由 ../compat/probe.ts 按活的、
8
+ // 可观察的事实判定(模块身份、成员存在、形状、只读行为),绝不比对源码文本:文本相等只
9
+ // 证明过「同一版发布」,而它把每一次无害的上游重构都变成整片功能失效。
13
10
  //
14
- // 纪律边界(对工作区「官方包与宿主机制只读」一条的解释,2026-09-18 复核确认):
11
+ // 纪律边界(对工作区「官方包与宿主机制只读」一条的解释,复核确认):
15
12
  // 这里的包装是**运行时实例**上的临时、可恢复、能力门控的适配(仅当宿主自己缺
16
13
  // delete/whenIdle 时才装;按原 descriptor 恢复;serial 队列防复活),不修改任何
17
14
  // 官方包文件、不持久化改动、不改变宿主机制的对外行为 —— 与「不 patch 官方代码」
18
- // 禁令针对的对象(包文件与宿主机制的永久改写)不同层。若用户裁定该解释不成立,
15
+ // 禁令针对的对象(包文件与宿主机制的永久改写)不同层。若用户要求该解释不成立,
19
16
  // 撤掉 acquire/releaseCacheGuard 即可整体退回「无删除屏障」的降级形态。
20
17
  const cacheGuards = new WeakMap();
21
18
  const raw = (value) => {
@@ -25,16 +22,14 @@ const raw = (value) => {
25
22
  };
26
23
  const sameLifecycle = (a, b) => a && b && a.createdAt === b.createdAt && (a.cwd ?? null) === (b.cwd ?? null);
27
24
  /**
28
- * Install the write barrier around the host's projection cache when (and only
29
- * when) the host cannot safely delete a cache row on its own.
25
+ * 给宿主的投影缓存装写屏障 —— 只在宿主自己删不干净缓存行时装。
30
26
  *
31
- * Guarded on capability, not on implementation text: the cache is wrapped only
32
- * when the write path and a deletable table are both present, and a host that
33
- * ships its own `delete`/`whenIdle` barrier never gets wrapped at all.
27
+ * 按**能力**设门,不看实现文本:写路径与可删的表都在才装;宿主自带
28
+ * `delete`/`whenIdle` 屏障时一律不装。
34
29
  *
35
- * @param cache - host projection cache instance.
36
- * @returns the barrier handle.
37
- * @throws {CapabilityRefusalError} when the cache cannot support a safe delete.
30
+ * @param cache 宿主的投影缓存实例
31
+ * @returns 屏障句柄
32
+ * @throws {CapabilityRefusalError} 缓存支撑不了安全删除时
38
33
  */
39
34
  function acquireCacheGuard(cache) {
40
35
  const existing = cacheGuards.get(cache);
@@ -101,7 +96,7 @@ function acquireCacheGuard(cache) {
101
96
  }
102
97
  const wrappers = {
103
98
  put(id, identity, rows) {
104
- // Preserve the upstream snapshot-at-call boundary even while queued.
99
+ // 即使排队,也要保住上游「调用瞬间快照」的边界:identity 先拷一份再入队。
105
100
  if (isBlocked(id, identity))
106
101
  return Promise.resolve();
107
102
  const expected = { ...identity };
@@ -112,7 +107,7 @@ function acquireCacheGuard(cache) {
112
107
  catch (error) {
113
108
  return Promise.reject(error);
114
109
  }
115
- // Serialize puts with deletion; never erase a new lifecycle reusing id.
110
+ // 让 put 与删除串行;同一个 id 被新生命周期复用时,绝不清掉新的那条。
116
111
  return serial(id, async () => {
117
112
  if (isBlocked(id, expected))
118
113
  return;
@@ -134,8 +129,8 @@ function acquireCacheGuard(cache) {
134
129
  });
135
130
  },
136
131
  write(session) {
137
- // Track the flush await before put as well as put itself. Otherwise a
138
- // delayed write could outlive disposal and bypass the restored method.
132
+ // put 之前的 flush 与 put 本身都要记在账上:否则一次延迟的写可能活过 dispose,
133
+ // 绕过已恢复的原方法。
139
134
  let task;
140
135
  try {
141
136
  task = track(Promise.resolve(originals.write.call(cache, session)));
@@ -184,7 +179,7 @@ function acquireCacheGuard(cache) {
184
179
  function restoreWrappers() {
185
180
  let clean = true;
186
181
  for (const name of ["put", "write"]) {
187
- // Never overwrite a later third-party wrapper.
182
+ // 后来装上的第三方包装绝不覆盖。
188
183
  if (cache[name] !== wrappers[name]) {
189
184
  clean = false;
190
185
  continue;
@@ -229,27 +224,24 @@ function acquireCacheGuard(cache) {
229
224
  return self;
230
225
  }
231
226
  /**
232
- * Live-session members the delete sequence needs, split by branch.
227
+ * 删除序列需要的能力 id,按分支给。
233
228
  *
234
- * `liveEntryFor`/`detachEntered` are private in the official declarations
235
- * (dsh-session lib/types/index.d.ts), so they are consumed through the same
236
- * capability gate as everything else. The point of checking BEFORE any
237
- * destructive step is unchanged: otherwise the failure lands mid-sequence
238
- * (after flush, before ledger cleanup) and leaves "transcript gone, archive
239
- * flag still set" behind.
229
+ * `liveEntryFor`/`detachEntered` 在官方声明里是私有的(dsh-session 的
230
+ * `lib/types/index.d.ts`),所以与其余能力一样走能力闸门。**动手之前**先查这一点不变:
231
+ * 否则失败会落在序列中段(已 flush、尚未清账),留下「transcript 没了、归档标记还在」。
240
232
  *
241
- * @param sessions - ctx.sessions; the cold branch tolerates it being absent.
242
- * @param hasLiveSession - whether this session is currently live.
243
- * @returns the capability ids that must be `ok`, in evaluation order.
233
+ * @param hasLiveSession 这个会话此刻是否活着
234
+ * @returns 必须为 `ok` 的能力 id,按求值顺序
244
235
  */
245
236
  export function requiredSessionCapabilities(hasLiveSession) {
246
237
  return hasLiveSession
247
238
  ? ["sessions.detach-live"]
248
239
  : ["sessions.cold-announce"];
249
240
  }
241
+ /** 归档会话的宿主桥:按能力选路、装缓存删除屏障、监听官方归档事件。 */
250
242
  export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
251
- // Cordis returns a fresh traceable method proxy on access. Compare and adapt
252
- // the original object, not proxies; calls retain the service owner's context.
243
+ // cordis 每次取成员都返回一个新的可追踪方法代理:要比对、要适配都落在原始对象上,
244
+ // 不碰代理;调用时仍保留服务属主的上下文。
253
245
  const registry = raw(suppliedRegistry);
254
246
  // 官方声明把 put/requireTable 标为 private(运行时存在,见文件头「纪律边界」),
255
247
  // 因此按本文件实际调用面收窄,不改动宿主对象本身。
@@ -258,12 +250,11 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
258
250
  let stopObserving;
259
251
  let assessment;
260
252
  let assessmentAt = 0;
261
- /** Re-probe at most every 5s: probing is cheap but not free on hot paths. */
253
+ /** 最多每 5s 重探一次:探测不贵,但在热路径上不是免费。 */
262
254
  const ASSESS_TTL_MS = 5000;
263
255
  /**
264
- * The current host assessment. Refreshed lazily so a host that gains or
265
- * loses a service is noticed without a plugin reload.
266
- * @param force - re-probe even when a cached value is still fresh.
256
+ * 当前宿主评估。懒刷新 —— 宿主多一个或少一个服务不必重载插件就能被发现。
257
+ * @param force 缓存还新鲜也重探一次
267
258
  */
268
259
  function hostAssessment(force = false) {
269
260
  const now = Date.now();
@@ -272,8 +263,7 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
272
263
  assessment = assessHost(ctx);
273
264
  }
274
265
  catch (error) {
275
- // A probe that throws is itself a finding: report it rather than
276
- // letting it escape into a delete sequence.
266
+ // 探测自己抛错也是一条 finding:记下来,不让它漏进删除序列。
277
267
  ctx.logger?.warn?.(`host capability probe failed: ${String(error)}`);
278
268
  assessment = undefined;
279
269
  }
@@ -281,14 +271,14 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
281
271
  }
282
272
  return assessment;
283
273
  }
284
- /** Capability ids not `ok` from the given list. */
274
+ /** 给定清单里状态不是 `ok` 的能力 id。 */
285
275
  function unavailable(ids) {
286
276
  const current = hostAssessment();
287
277
  if (current === undefined)
288
278
  return ids.map((id) => ({ id, label: id, detail: "宿主能力探测不可用", recovery: "请查看插件日志 dsh-plugin-tool-management.log" }));
289
279
  return refusalsFor(current, ids);
290
280
  }
291
- /** Throw when any listed capability is not usable; nothing is written before this runs. */
281
+ /** 名单里任一能力不可用就抛错 —— 它跑在任何写入之前,所以拒绝时一个字都没落盘。 */
292
282
  function requireCapabilities(operation, ids) {
293
283
  const refusals = unavailable(ids);
294
284
  if (refusals.length > 0)
@@ -302,11 +292,8 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
302
292
  return registry[name].call(registry, ...args);
303
293
  };
304
294
  /**
305
- * The adapter route needs the registry's read/write/delegate members. This is
306
- * a presence-and-shape check on the live object — the previous implementation
307
- * compared these methods' source text against this plugin's own copy of the
308
- * official prototype, which failed on any upstream refactor and, worse,
309
- * depended on the plugin loading a second copy of the package.
295
+ * 适配器路线需要 registry 的读 / 写 / 委派成员。这是对**活对象**的存在与形状检查 ——
296
+ * 比对这几个方法的源码文本会在任何上游重构时失败,更糟的是它默认了插件加载了第二份包。
310
297
  */
311
298
  function checkWorkspace(operation = "archive") {
312
299
  const current = hostAssessment();
@@ -319,7 +306,7 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
319
306
  requireCapabilities(operation, ["workspace.read-state", "workspace.enqueue"]);
320
307
  return { via: "adapter", refusals: [] };
321
308
  }
322
- /** Structural check of the workspace index shape. */
309
+ /** 工作区索引的形状检查。 */
323
310
  function checkIndexShape() {
324
311
  for (const name of ["headers", "sessionPaths", "invalidSessionPaths", "entities"]) {
325
312
  if (!(registry[name] instanceof Map))
@@ -328,16 +315,16 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
328
315
  }
329
316
  return {
330
317
  registry,
331
- /** Latest assessment, for the compatibility surface and the HTTP status op. */
318
+ /** 最新评估,给兼容页与 HTTP 状态 op 用。 */
332
319
  capabilities(force = false) { return hostAssessment(force); },
333
- /** Capability ids an operation still needs, without throwing. */
334
- refusalsFor(operation, ids) { return unavailable(ids); }, observe() {
320
+ /** 某个操作还缺哪些能力 id;不抛错。 */
321
+ refusalsFor(operation, ids) { return unavailable(ids); },
322
+ observe() {
335
323
  if (stopObserving)
336
324
  return;
337
325
  let previous = new Set(registry.archivedSessionIds);
338
- // Official durable domain notifications also cover archive operations
339
- // from the official sidebar or an external archive manager. No monkey
340
- // patch of archiveSession and no competing writer of its ledger.
326
+ // 官方的持久域通知也覆盖从官方侧栏或外部归档工具发起的归档操作。所以不 monkey patch
327
+ // `archiveSession`,也不去当它那本账的第二个写者。
341
328
  stopObserving = ctx.on("domain/changed", (change) => {
342
329
  // 官方事件类型把 value 声明为 unknown(载荷形状由 workspace 域规范决定)。
343
330
  const payload = change.value;
@@ -362,8 +349,7 @@ export function createSessionsBridge(ctx, suppliedRegistry, onArchive) {
362
349
  setState: (state) => method("setState", state),
363
350
  readHeader: (id) => method("readSessionHeader", id),
364
351
  /**
365
- * Install the cache delete barrier for one session, before anything is
366
- * flushed or detached. Prefers a host-native barrier when it exists.
352
+ * 在 flush / detach 之前给一个会话装上缓存删除屏障。宿主自带屏障时优先用它。
367
353
  */
368
354
  async beginDelete(id, header) {
369
355
  checkWorkspace("delete");
@@ -1,4 +1,4 @@
1
- // 归档会话域(原 index.ts apply() 闭包内六段,2026-09-19 抽出)。
1
+ // 归档会话域(原 index.ts apply() 闭包内六段,抽出)。
2
2
  //
3
3
  // 这一域管的是「归档会话的外围」:侧车账本的落点与搬迁、保留期设置、到期清扫、
4
4
  // 批量操作目标的校验、归档列表的分组视图。会话本身的归档 / 恢复 / 删除走宿主
@@ -23,11 +23,10 @@ import { ArchiveWorkspaceRegistry as SessionsService, workspaceBaseName, workspa
23
23
  */
24
24
  export function createHistoryDomain(deps) {
25
25
  const { ctx, config, pluginRoot, message } = deps;
26
- // ---------- independent history facade ----------
27
- // Keep the active workspaceRegistry/sessionProjectionCache instances intact.
28
- // Native archive extensions are delegated by capability, not package name.
29
- // Official gaps use a checked adapter (sessions/bridge.ts); no service or
30
- // storage-domain replacement. Retention uses the existing sidecar ledger.
26
+ // ---------- 独立的历史门面 ----------
27
+ // 现有的 workspaceRegistry / sessionProjectionCache 实例原样不动。原生归档扩展按**能力**
28
+ // 委派,不看包名。官方缺口由受检适配器补(`sessions/bridge.ts`)—— 不替换服务、不替换
29
+ // 存储域。保留期沿用现有的侧车账本。
31
30
  // 历史侧车三件套(归档时刻账本 / 保留期设置 / 工作区登记快照)统一放 hub 根
32
31
  // (`$DSH_HOME/tool-management/`),**不放插件目录**:npm 安装下插件目录会被
33
32
  // `dsh plugin update` 整体替换,放那里等于"升级即丢账本"——账本一丢,保留期基线
@@ -244,7 +243,7 @@ export function createHistoryDomain(deps) {
244
243
  liveRecords.push({ id: String(wid), path, title });
245
244
  }
246
245
  // 活登记也要探一次盘:登记还在、但磁盘上的工作区文件夹被删掉时,界面必须能及时
247
- // 标出来(用户 2026-10-12:「要怎么及时知道这个工作区实际文件夹已经被删除了」)。
246
+ // 标出来(用户 :「要怎么及时知道这个工作区实际文件夹已经被删除了」)。
248
247
  const liveDirMissing = path !== undefined && !(await directoryExists(path));
249
248
  const view = {
250
249
  id: 'ws:' + wid, title, kind: 'live', registered: true,
@@ -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
  }