dsh-subagent-library 0.2.6 → 0.2.8

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.
package/README.en.md CHANGED
@@ -72,7 +72,7 @@ Entry fields:
72
72
  | `subagentProvider` | no | **Subagent transport** (a `ctx.subagents` provider such as `spawn`); defaults to the plugin-level default `spawn` |
73
73
  | `maxTokens` | no | Subagent output cap |
74
74
  | `persona` | no | Subagent system prompt. Personas go through strict `{{…}}` template interpolation (same semantics as deployment personas) — an unregistered variable (e.g. `{{user}}`) fails child activation |
75
- | `toolFilter` | no | `allow`/`deny` tool-name lists (deny write-class tools for read-only roles). **Read-only/restricted roles should also deny `list_subagents`/`delegate`** so children are not taught by the global prompt to re-delegate in a chain. Names are checked against the **actual parent session's** tool composition at delegation: a name missing there fails that delegation with a clear error listing the known tools — surfaced at the delegate call for foreground/continuable runs, and in the task result for background one-shots; saves are not pre-validated |
75
+ | `toolFilter` | no | `allow`/`deny` tool-name lists (deny write-class tools for read-only roles). **Read-only/restricted roles should also deny `list_subagents`/`delegate`** so children are not taught by the global prompt to re-delegate in a chain. Names are resolved against the **calling session's restrictable set** at delegation (not "visibility"): names that session cannot apply are ignored and annotated with the reason (`本会话不存在` / `本会话专属工具`) in the delegate result and the `list_subagents` catalog — one shared entry never fails a whole delegation because a session lacks a tool. **An `allow` list that no name applies to refuses the delegation** (otherwise "keep only these" would silently become "keep nothing"). Registries without `view()` fall back to visibility, where scope-local names still make delegation fail loudly. Saves are not pre-validated |
76
76
  | `maxDepth` | no | Delegation depth cap; **when unset, defaults to 3 when the transport supports depthLimit** (aligned with the official subagent tool to prevent chained recursive delegation; the harness itself has no global depth cap). Transports without depthLimit stay uncapped |
77
77
  | `backgroundMode` | no | `one-shot` (default) / `continuable` (resumable) |
78
78
 
package/README.md CHANGED
@@ -79,7 +79,7 @@ subagent-library:
79
79
  | `subagentProvider` | 否 | **子代理传输层**(`spawn` 等 `ctx.subagents` provider);默认取插件级默认 `spawn` |
80
80
  | `maxTokens` | 否 | 子代理输出上限 |
81
81
  | `persona` | 否 | 子代理角色提示词。注意 persona 走严格的 `{{…}}` 模板插值(与部署 persona 同语义)——出现未注册的变量(如 `{{user}}`)会让子代理激活失败 |
82
- | `toolFilter` | 否 | `allow`/`deny` 工具名单(只读角色用 deny 禁写类工具)。**只读/受限角色建议把 `list_subagents`/`delegate` 也列入 deny**,防止子代理被全局提示词教去链式再派活。名单按**委派时实际父会话**的工具组合校验:名字不在该组合时委派会明确报错(并列出可用工具名)——前台与可续聊在委派当场报出,后台 one-shot 的失败显示在任务结果中;保存阶段不做校验 |
82
+ | `toolFilter` | 否 | `allow`/`deny` 工具名单(只读角色用 deny 禁写类工具)。**只读/受限角色建议把 `list_subagents`/`delegate` 也列入 deny**,防止子代理被全局提示词教去链式再派活。名单在**委派时按调用方会话的可限制集合**解析(不是"可见"):不可应用的名字被忽略,并在派活结果与 `list_subagents` 目录里标注原因(`本会话不存在` / `本会话专属工具`)——共享条目不会因为某个会话缺该工具而整次派活失败。**`allow` 名单若在本会话全部不可应用则拒绝委派**(否则"只留这些"会变成"什么都不留")。旧注册表无 `view()` 时退回可见性判定,此时 scope-local 名仍会让委派明确报错。保存阶段不做校验 |
83
83
  | `maxDepth` | 否 | 委派深度上限;**缺省 = 传输层支持 depthLimit 时默认 3**(与官方 subagent 工具对齐,防链式递归派活;harness 自身无全局深度上限),不支持 depthLimit 的传输层则不设上限 |
84
84
  | `backgroundMode` | 否 | `one-shot`(默认)/ `continuable`(可续聊) |
85
85
 
package/lib/client.js CHANGED
@@ -917,6 +917,46 @@ function LibrarySettings(props) {
917
917
  });
918
918
  }
919
919
 
920
+ //#endregion
921
+ //#region src/client/nav-icon.ts
922
+ /**
923
+ * Settings-nav icon decoration for this plugin's own row (子代理库).
924
+ *
925
+ * The official settings shell's navIcon(id) table is closed — official ids
926
+ * get drawn icons and everything else falls back to a generic gear. This
927
+ * replaces that fallback <svg> inside OUR nav button (matched by our own
928
+ * registered label text) with the drawn robot-head icon. A MutationObserver
929
+ * re-applies the icon when the panel re-renders; gated on the settings
930
+ * dialog being present so idle chat streams never pay the query cost.
931
+ */
932
+ const NAV_ICON_INNER = "<path d=\"M8 6.5V3.9\"/><circle cx=\"8\" cy=\"2.6\" r=\"0.85\"/><rect x=\"3.25\" y=\"6.5\" width=\"9.5\" height=\"6.5\" rx=\"1.5\"/><path d=\"M5.75 9.25v1.25\"/><path d=\"M10.25 9.25v1.25\"/><path d=\"M1.75 9.25h1.5\"/><path d=\"M12.75 9.25h1.5\"/>";
933
+ const NAV_LABELS = new Set(["子代理库"]);
934
+ function decorateSettingsNavIcon(ctx) {
935
+ ctx.effect(() => {
936
+ const decorate = () => {
937
+ if (document.querySelector("[role=\"dialog\"]") === null) return;
938
+ for (const button of Array.from(document.querySelectorAll("button"))) {
939
+ const label = button.querySelector(":scope > span");
940
+ if (label === null || !NAV_LABELS.has(label.textContent ?? "")) continue;
941
+ const existing = button.firstElementChild;
942
+ if (existing instanceof SVGElement) {
943
+ if (existing.dataset.navIcon === "1") continue;
944
+ const template = document.createElement("template");
945
+ template.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-nav-icon="1">${NAV_ICON_INNER}</svg>`;
946
+ existing.replaceWith(template.content.firstElementChild);
947
+ }
948
+ }
949
+ };
950
+ const observer = new MutationObserver(() => decorate());
951
+ observer.observe(document.body, {
952
+ childList: true,
953
+ subtree: true
954
+ });
955
+ decorate();
956
+ return () => observer.disconnect();
957
+ }, "subagent-library: nav icon decoration");
958
+ }
959
+
920
960
  //#endregion
921
961
  //#region src/client/locales.ts
922
962
  const zh = {
@@ -1068,6 +1108,7 @@ function apply(ctx) {
1068
1108
  subscribeRefresh
1069
1109
  })
1070
1110
  }, LibrarySettings));
1111
+ decorateSettingsNavIcon(ctx);
1071
1112
  }
1072
1113
 
1073
1114
  //#endregion
package/lib/index.js CHANGED
@@ -9108,6 +9108,53 @@ async function settleForegroundRun(run) {
9108
9108
  output: result.output
9109
9109
  };
9110
9110
  }
9111
+ /**
9112
+ * Drop toolFilter names the CALLING session cannot restrict.
9113
+ *
9114
+ * `ctx.tools.restrict` validates against the child's inherited surface (global
9115
+ * layer + ancestors) and fails the WHOLE filter on one name it cannot admit —
9116
+ * unknown names and scope-local names included. A roster entry is shared by
9117
+ * every session, so a fixed deny list breaks delegation in any session whose
9118
+ * composition lacks one of the names (real case: deny lists carrying
9119
+ * `subagent` — a per-agent scope-local tool in DSH 0.1.2-rc.1 — or tools a
9120
+ * preset never mounts). Names outside the caller's restrictable set are dropped
9121
+ * (restrict could not have removed them anyway, and the child never inherits
9122
+ * the parent's own registrations) and reported in the delegate result instead
9123
+ * of failing the whole delegation.
9124
+ *
9125
+ * Dropping a DENY name can only widen the child (the name was unrestrictable,
9126
+ * so the child could never have it removed); dropping every ALLOW name would
9127
+ * leave the child with no global tools at all, which is reported separately as
9128
+ * `allowEmptied` so the caller can fail loudly instead of starting a crippled
9129
+ * child.
9130
+ * @param scope - the CALLING AGENT (dsh-tools' scope key), not its Context.
9131
+ */
9132
+ function sanitizeToolFilter(ctx, filter, scope) {
9133
+ if (filter === void 0) return {
9134
+ filter: void 0,
9135
+ dropped: [],
9136
+ allowEmptied: false
9137
+ };
9138
+ const tools = ctx.tools;
9139
+ const restrictable = tools.view?.(scope)?.restrictableNames;
9140
+ const restrictableName = (name$1) => restrictable !== void 0 ? restrictable.has(name$1) : tools.get(name$1, scope) !== void 0;
9141
+ const keep = (list) => list?.filter(restrictableName);
9142
+ const allow = keep(filter.allow);
9143
+ const deny = keep(filter.deny);
9144
+ const dropped = [...filter.allow ?? [], ...filter.deny ?? []].filter((name$1) => !restrictableName(name$1)).map((name$1) => ({
9145
+ name: name$1,
9146
+ reason: restrictable !== void 0 && tools.get(name$1, scope) !== void 0 ? "session-local" : "unknown"
9147
+ }));
9148
+ const next = {
9149
+ ...allow !== void 0 ? { allow } : {},
9150
+ ...deny !== void 0 && deny.length > 0 ? { deny } : {}
9151
+ };
9152
+ return {
9153
+ filter: next.allow === void 0 && next.deny === void 0 ? void 0 : next,
9154
+ dropped,
9155
+ allowEmptied: filter.allow !== void 0 && filter.allow.length > 0 && allow !== void 0 && allow.length === 0
9156
+ };
9157
+ }
9111
9158
  function apply(ctx, config$1) {
9112
9159
  let source;
9113
9160
  let settingsService;
@@ -9404,17 +9451,32 @@ function apply(ctx, config$1) {
9404
9451
  }]
9405
9452
  },
9406
9453
  isConcurrencySafe: () => true,
9407
- async execute() {
9454
+ async execute(_args, exec) {
9408
9455
  if (settingsFailure !== void 0) throw new Error(settingsFailure);
9409
9456
  const lib = resolveConfig();
9410
- return Object.entries(lib.entries).map(([id, entry]) => ({
9411
- id,
9412
- description: entry.description,
9413
- provider: entry.provider ?? "(session default)",
9414
- model: entry.model ?? "(session default)",
9415
- backgroundMode: entry.backgroundMode ?? "one-shot",
9416
- ...entry.toolFilter !== void 0 ? { toolFilter: [entry.toolFilter.allow !== void 0 ? `allow:[${entry.toolFilter.allow.join(", ")}]` : "", entry.toolFilter.deny !== void 0 ? `deny:[${entry.toolFilter.deny.join(", ")}]` : ""].filter(Boolean).join(" ") } : {}
9417
- }));
9457
+ const agent = exec.agent;
9458
+ /** The catalog must not advertise a filter this session cannot apply:
9459
+ * summarize the SANITIZED filter and list what was ignored, so the model
9460
+ * sees the same tool scope delegation will actually produce. */
9461
+ const filterSummary = (entry) => {
9462
+ if (entry.toolFilter === void 0) return void 0;
9463
+ const declared = [entry.toolFilter.allow !== void 0 ? `allow:[${entry.toolFilter.allow.join(", ")}]` : "", entry.toolFilter.deny !== void 0 ? `deny:[${entry.toolFilter.deny.join(", ")}]` : ""].filter(Boolean).join(" ");
9464
+ if (agent === void 0) return declared;
9465
+ const { filter, dropped } = sanitizeToolFilter(ctx, entry.toolFilter, agent);
9466
+ const effective = filter === void 0 ? "(本会话无可应用的名单项)" : [filter.allow !== void 0 ? `allow:[${filter.allow.join(", ")}]` : "", filter.deny !== void 0 ? `deny:[${filter.deny.join(", ")}]` : ""].filter(Boolean).join(" ");
9467
+ return dropped.length > 0 ? `${effective} 忽略:[${dropped.map((item) => item.name).join(", ")}]` : effective;
9468
+ };
9469
+ return Object.entries(lib.entries).map(([id, entry]) => {
9470
+ const summary = filterSummary(entry);
9471
+ return {
9472
+ id,
9473
+ description: entry.description,
9474
+ provider: entry.provider ?? "(session default)",
9475
+ model: entry.model ?? "(session default)",
9476
+ backgroundMode: entry.backgroundMode ?? "one-shot",
9477
+ ...summary !== void 0 ? { toolFilter: summary } : {}
9478
+ };
9479
+ });
9418
9480
  }
9419
9481
  }));
9420
9482
  ctx.tools.register(defineTool({
@@ -9456,10 +9518,13 @@ function apply(ctx, config$1) {
9456
9518
  },
9457
9519
  additionalProperties: true
9458
9520
  },
9459
- render: (_args, value) => [{
9460
- type: "text",
9461
- text: value.kind === "background" ? `started background subagent task ${value.jobId}` : value.kind === "continuable" ? `started subagent ${value.subagentId}` : value.kind === "foreground" ? outputValueText(value.output ?? []) : JSON.stringify(value)
9462
- }]
9521
+ render: (_args, value) => {
9522
+ const dropped = Array.isArray(value.droppedTools) ? value.droppedTools.filter((name$1) => typeof name$1 === "string") : [];
9523
+ return [{
9524
+ type: "text",
9525
+ text: (value.kind === "background" ? `started background subagent task ${value.jobId}` : value.kind === "continuable" ? `started subagent ${value.subagentId}` : value.kind === "foreground" ? outputValueText(value.output ?? []) : JSON.stringify(value)) + (dropped.length > 0 ? `\n(已忽略本会话不可用的工具名:${dropped.join(";")})` : "")
9526
+ }];
9527
+ }
9463
9528
  },
9464
9529
  isConcurrencySafe: () => true,
9465
9530
  async execute(args, exec) {
@@ -9480,6 +9545,9 @@ function apply(ctx, config$1) {
9480
9545
  if (continuable && transport.prepareContinuable === void 0) throw new Error(`delegate: transport "${subagentProviderName}" does not support continuable children`);
9481
9546
  const maxDepth = entry.maxDepth ?? (transport.capabilities.depthLimit ? DEFAULT_MAX_DEPTH : void 0);
9482
9547
  if (maxDepth !== void 0) assertSubagentMaxDepth(maxDepth);
9548
+ const { filter: toolFilter, dropped, allowEmptied } = sanitizeToolFilter(ctx, entry.toolFilter, parent);
9549
+ const droppedTools = dropped.map((item) => item.reason === "session-local" ? `${item.name}(本会话专属工具,子代本就继承不到)` : `${item.name}(本会话不存在)`);
9550
+ if (allowEmptied) throw new Error(`delegate: entry "${args.library_id}" allow list names no tool this session can apply (${droppedTools.join("; ")}) — refusing to start a child with no tools at all`);
9483
9551
  if (!continuable) {
9484
9552
  if (maxDepth !== void 0 && !transport.capabilities.depthLimit) throw new Error(`delegate: transport "${subagentProviderName}" cannot enforce maxDepth (no depthLimit capability)`);
9485
9553
  if (entry.persona !== void 0 && !transport.capabilities.persona) throw new Error(`delegate: transport "${subagentProviderName}" cannot apply a persona (no persona capability)`);
@@ -9500,9 +9568,10 @@ function apply(ctx, config$1) {
9500
9568
  parent,
9501
9569
  ...agentOptions !== void 0 ? { agentOptions } : {},
9502
9570
  ...entry.persona !== void 0 ? { persona: entry.persona } : {},
9503
- ...entry.toolFilter !== void 0 ? { toolFilter: entry.toolFilter } : {},
9571
+ ...toolFilter !== void 0 ? { toolFilter } : {},
9504
9572
  ...maxDepth !== void 0 ? { maxDepth } : {}
9505
9573
  };
9574
+ const droppedNote = droppedTools.length > 0 ? { droppedTools } : {};
9506
9575
  if (args.run_in_background === true || continuable) {
9507
9576
  if (continuable) return {
9508
9577
  kind: "continuable",
@@ -9511,7 +9580,8 @@ function apply(ctx, config$1) {
9511
9580
  label: args.description ?? args.library_id,
9512
9581
  request,
9513
9582
  signal: exec.signal
9514
- })).childId
9583
+ })).childId,
9584
+ ...droppedNote
9515
9585
  };
9516
9586
  const jobs = ctx.get("jobs");
9517
9587
  if (jobs === void 0) throw new Error("background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs");
@@ -9533,13 +9603,17 @@ function apply(ctx, config$1) {
9533
9603
  }), controller.signal)
9534
9604
  };
9535
9605
  }
9536
- })
9606
+ }),
9607
+ ...droppedNote
9537
9608
  };
9538
9609
  }
9539
- return settleForegroundRun(await ctx.subagents.start(subagentProviderName, {
9540
- ...request,
9541
- signal: exec.signal
9542
- }));
9610
+ return {
9611
+ ...await settleForegroundRun(await ctx.subagents.start(subagentProviderName, {
9612
+ ...request,
9613
+ signal: exec.signal
9614
+ })),
9615
+ ...droppedNote
9616
+ };
9543
9617
  }
9544
9618
  }));
9545
9619
  ctx.systemPrompt.section({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-subagent-library",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Named subagent library for DeepSeek Harness: a settings-driven roster of role subagents (model + persona + tool filter), exposed to every session through the list_subagents and delegate tools, a /subagent command, and a Settings page.",
5
5
  "keywords": [
6
6
  "deepseek-harness",