dsh-plugin-tool-management 0.21.4 → 0.21.5

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/CHANGELOG.md CHANGED
@@ -10,6 +10,24 @@
10
10
 
11
11
  ---
12
12
 
13
+ ## [0.21.5] - 2026-10-23
14
+
15
+ ### 新增
16
+
17
+ - **错误消息附带现成候选**:缺 id、缺场景名、缺服务器名、名字打错时,列出当前存在的记忆 id、技能名、人设名、场景名、预设 id、MCP 服务器名。
18
+
19
+ ### 修复
20
+
21
+ - **人设清单带正文路径**:`list` 每条末尾给出人设文件路径,要读完整定义时用文件工具打开。
22
+ - **MCP 重启的豁免范围写清**:只豁免场景锁,不豁免用户同意。
23
+ - **十处写操作补上确认卡**:MCP 停机、提示词正向应用、五域删除进回收站、记忆 / 技能 / 人设的开关落到机器级时;恢复路径(MCP 重启、回收站还原、提示词撤销)不拦。
24
+ - **回收站还原缺 id 时说明那是回收站条目 id**,并指向 `action=list`。
25
+ - **记忆 id 传到其它域时说明那是记忆 id**。
26
+
27
+ ### 变更
28
+
29
+ - 错误消息里点名其它工具时按可见性分叉:模型手里没有那条工具就只指向注入段。
30
+
13
31
  ## [0.21.4] - 2026-10-23
14
32
 
15
33
  ### 新增
package/README.md CHANGED
@@ -29,7 +29,9 @@ dsh plugin --profile desktop add dsh-plugin-tool-management@latest # 桌面版
29
29
 
30
30
  ## 演示视频
31
31
 
32
- <video controls src="https://github.com/user-attachments/assets/8f785896-891a-4a91-9845-768a1d0bc829"></video>
32
+ <video controls src="https://github.com/user-attachments/assets/ff3111c3-4228-45b7-9e28-b85dc60fb6b3"></video>
33
+
34
+ 播放器起不来(登录态偶发被浏览器 CSP 拦)?[点此直接看同一个文件](https://github.com/user-attachments/assets/ff3111c3-4228-45b7-9e28-b85dc60fb6b3)。
33
35
 
34
36
  画面里每一个界面都是真机截图,没有重画的 UI,也没有伪造控件。
35
37
 
@@ -69,7 +71,7 @@ dsh plugin --profile desktop add dsh-plugin-tool-management@latest # 桌面版
69
71
  | 锁住就不怕手滑 | 场景可以上锁:五个域的增删改整体只读 |
70
72
  | 删了能找回 | 技能 / 记忆 / 人设 / 提示词 / 场景的删除都进回收站(会话永久删除除外);可勾选批量永久删除,也可设保留期让它自动清(默认永久保留) |
71
73
  | 安全、不添乱 | 只写自己的文件;密钥默认打码、看明文要令牌 |
72
- | 对话 / 工作区各管各的 | 面板顶部先选层,各域开关只影响那一层(全部全局 / 按对话 / 按工作区);其他层原样不动 |
74
+ | 对话 / 工作区各管各的 | 面板顶部先选层,各域开关只影响那一层(全部全局 / 按对话 / 按工作区);其他层原样不动 |
73
75
 
74
76
  ## 快速开始
75
77
 
@@ -85,7 +87,7 @@ dsh plugin --profile desktop remove dsh-plugin-tool-management # 桌面
85
87
  装不到最新版先看这两条:npm 镜像 / 代理有同步延迟;pnpm 若开了 `minimumReleaseAge`(发布冷却),新版本在冷却期内会被直接跳过。两种都不报错,只是安静地装成旧版 —— 用确切版本号安装可以绕开 `@latest` 的解析:
86
88
 
87
89
  ```sh
88
- dsh plugin --profile web add dsh-plugin-tool-management@0.21.2
90
+ dsh plugin --profile web add dsh-plugin-tool-management@0.X.X
89
91
  ```
90
92
 
91
93
  核对装上的到底是哪一版:设置 → 工具管理 → **兼容** 页的「本插件适配版本」是**这一轮实际加载的代码**里的版本号(不是 `package.json` 里写的),应与 `~/.dsh/tool-management/mount.json` 的 `version` 一致。
@@ -236,9 +238,9 @@ dsh plugin --profile web add dsh-plugin-tool-management@latest
236
238
  | 装完没有页面 | 硬刷新;不行重启 DSH。 |
237
239
  | 重复 MCP 页签 | 删 `cordis.patch.yml` 里的旧 loader 行后重启。 |
238
240
  | 改坏配置 DSH 起不来 | 从 `~/.dsh/tool-management/backups/` 取最近的 `cordis.patch.yml.<层级>.bak-<时间戳>` 覆盖回去(每份 patch 各留 5 份)。 |
239
- | 升级 DSH 后动作不可用 | 设置 → 工具管理 → **兼容** 看原因;`doctor.mjs` → `host-deps.mjs --fix`。 |
240
- | 升级 DSH 后装不上 / 提示 peer 不符 | 本插件只适配 DSH **0.2.1**(`>=0.2.1-rc.2 <0.2.2`):别的宿主代次请装对应版本的插件,跨代升级要等插件同步适配。 |
241
- | 模型调不到某条工具 | 「兼容」页的**模型工具表**看它是不是被关了(顶部先选到那个对话 / 工作区;出厂默认关着 20 条);面板和脚本不受影响。 |
241
+ | 升级 DSH 后动作不可用 | 设置 → 工具管理 → **兼容** 看原因;`doctor.mjs` → `host-deps.mjs --fix`。 |
242
+ | 升级 DSH 后装不上 / 提示 peer 不符 | 本插件只适配 DSH **0.2.1**(`>=0.2.1-rc.2 <0.2.2`):别的宿主代次请装对应版本的插件,跨代升级要等插件同步适配。 |
243
+ | 模型调不到某条工具 | 「兼容」页的**模型工具表**看它是不是被关了(顶部先选到那个对话 / 工作区;出厂默认关着 20 条);面板和脚本不受影响。 |
242
244
  | `approval=never` 还要确认吗 | 不弹卡,直接放行并记日志;想问回来切回「工作区内修改」。 |
243
245
  | `subagent_manager_run` 报 provider 不可用 | 对应 provider 没注册:`spawn`(默认)/ `fork`(`inherit`)分别挂 `@deepseek-ai/dsh-subagent-spawn-in-process` / `-fork-in-process` 后重启。 |
244
246
  | 场景绑了 A 人设,官方 `subagent` 还在跑别的 | 官方那两个是宿主的工具,本插件管不到;贴合人设的走 `subagent_manager_run`,官方只在没有人设贴合或要后台跑时用。 |
@@ -247,12 +249,12 @@ dsh plugin --profile web add dsh-plugin-tool-management@latest
247
249
 
248
250
  ## 文档
249
251
 
250
- | 文档 | 什么时候看 |
251
- | --- | --- |
252
- | [故障排查](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/TROUBLESHOOTING.md) | 装完没页面、重复页签、升级后动作不可用、停用表坏了、侧车损坏 |
253
- | [架构](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/ARCHITECTURE.md) | 想知道内容怎么进模型、同一个开关为什么两个对话不一样、改完落到哪个文件 |
254
- | [兼容矩阵](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/COMPATIBILITY.md) | 各 DSH 版本的能力矩阵(已验证 / 未实测 / 不可用) |
255
- | [CHANGELOG](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/CHANGELOG.md) | 每一版改了什么 |
252
+ | 文档 | 什么时候看 |
253
+ | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
254
+ | [故障排查](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/TROUBLESHOOTING.md) | 装完没页面、重复页签、升级后动作不可用、停用表坏了、侧车损坏 |
255
+ | [架构](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/ARCHITECTURE.md) | 想知道内容怎么进模型、同一个开关为什么两个对话不一样、改完落到哪个文件 |
256
+ | [兼容矩阵](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/docs/COMPATIBILITY.md) | 各 DSH 版本的能力矩阵(已验证 / 未实测 / 不可用) |
257
+ | [CHANGELOG](https://github.com/ouli-1242/dsh-plugin-tool-management/blob/main/CHANGELOG.md) | 每一版改了什么 |
256
258
 
257
259
  ---
258
260
 
package/README_EN.md CHANGED
@@ -29,7 +29,9 @@ Hard-refresh the browser after installing for web (Cmd/Ctrl+Shift+R), or restart
29
29
 
30
30
  ## Demo
31
31
 
32
- <video controls src="https://github.com/user-attachments/assets/8f785896-891a-4a91-9845-768a1d0bc829"></video>
32
+ <video controls src="https://github.com/user-attachments/assets/ff3111c3-4228-45b7-9e28-b85dc60fb6b3"></video>
33
+
34
+ Player refuses to start (browsers with a stricter CSP sometimes block the inline embed)? [Watch the same file directly](https://github.com/user-attachments/assets/ff3111c3-4228-45b7-9e28-b85dc60fb6b3).
33
35
 
34
36
  Every interface shown is a real screenshot of the running product — no redrawn UI, no fabricated controls.
35
37
 
@@ -85,7 +87,7 @@ dsh plugin --profile desktop remove dsh-plugin-tool-management # desktop
85
87
  Two reasons you might not get the newest release, and neither one errors out: npm mirrors / proxies lag behind, and pnpm's `minimumReleaseAge` (release cooldown) skips anything published inside the window. You just quietly end up on an older version. Pinning an exact version bypasses `@latest` resolution:
86
88
 
87
89
  ```sh
88
- dsh plugin --profile web add dsh-plugin-tool-management@0.21.2
90
+ dsh plugin --profile web add dsh-plugin-tool-management@0.21.4
89
91
  ```
90
92
 
91
93
  To check what you actually got: the "plugin adapter version" on the **Host** tab is the version baked into the code **loaded this session** (not what `package.json` says), and it should match `version` in `~/.dsh/tool-management/mount.json`.
package/docs/UPDATE.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  | 版本 | 发布 | 主题 |
6
6
  | ------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7
+ | [0.21.5](../CHANGELOG.md#0215---2026-10-23) | 2026-10-23 | 十处写操作补上确认卡(MCP 停机、提示词正向应用、五域删除、开关落到机器级),恢复路径不拦;错误消息附现成候选(记忆 id、技能名、场景名、预设 id、MCP 服务器名) |
7
8
  | [0.21.4](../CHANGELOG.md#0214---2026-10-23) | 2026-10-23 | 「彻底停止」改为一次性的「统一关闭」;场景 / MCP / 技能 / 子智能体 / 提示词 / 记忆六页页头新增「全部关闭」(有临时运行时才出现,位于回收站右侧,执行后立即消失);技能行可编辑(官方内置只读),场景 / 子智能体 / 记忆 / 快捷提示词补齐逐条「统一关闭」;统一关闭后徽章即时消失、不再触发列表重排;兼容页移除更新检查行,「保存到场景」「创建技能」文案收短 |
8
9
  | [0.21.3](../CHANGELOG.md#0213---2026-10-22) | 2026-10-22 | 修好三处注入:插件升级后旧框架文案不刷新、旧版本留下的注入消息不补发、MCP 启动 / 重连时先发「已清空」再发内容(两次注入);另修好同步脚本,只改大小写的改名不再把文件弄丢;新增启动时修剪桌面壳鉴权 cookie(堆多了会导致应用起不来);另加严格索引检查门禁与 op 登记表缺声明对账;请求栅栏改为按请求查找 `connection`,不再因挂载顺序永久降级;本地版本领先 registry 时不再显示指向旧版的「复制安装命令」 |
9
10
  | [0.21.2](../CHANGELOG.md#0212---2026-10-22) | 2026-10-22 | **本次重点 · 生效层级(全局 / 工作区 / 会话)**:默认每个对话各一份设置,兼容页可切全局或按工作区,六个域(含逐工具开关与模型工具表)都跟着层走,全局关着的服务器 / 来源能按对话临时运行;另加并发编辑指纹、插件更新检查、诊断信息、记忆搜索与三份文档;兼容范围收窄到 DSH 0.2.1。 |
@@ -0,0 +1,134 @@
1
+ // 按**这一次调用的参数**决定要不要弹确认卡。
2
+ //
3
+ // 与 `index.ts` 的 `CONFIRM_LABELS` 分工:那张表回答"这条工具要不要门",这里回答"这一次
4
+ // 要不要门"。必须分开,因为同一个工具不同 action 的危险度差得远:
5
+ //
6
+ // · `*_remove` 的 `list` 是读、`restore` 是恢复,只有 `trash` 是删除;
7
+ // · `mcp_manager_switch` 的 `restart` 是服务器挂掉时的恢复路径(场景锁都为它开口),
8
+ // `stop` 才是机器级停机;
9
+ // · `prompt_manager_apply` 的 `apply: false` 是撤销,不是改写。
10
+ //
11
+ // 一律按工具名挂卡会把恢复路径一起堵住 —— 出事时用户反而要多点一次确认。
12
+ //
13
+ // 另一半判据是**作用域**:几个 `_switch` 默认写本会话(爆炸半径小),只有显式
14
+ // `scope: "global"` 或在全局粒度下才变成机器级。给默认路径也挂卡是纯摩擦。
15
+ //
16
+ // 本模块保持纯函数:不读磁盘、不看会话、不抛错。参数不成立(缺 id / 不是布尔)时返回
17
+ // `null` 让工具自己报错 —— 给一次注定失败的调用弹卡只会产生无效审批。
18
+ /**
19
+ * 需要按参数判定的工具名。
20
+ *
21
+ * 不在这张表里的工具仍走 `CONFIRM_LABELS` 的既有分支(无条件问,或按设置开关问)。
22
+ */
23
+ export const ARG_CONDITIONAL_CONFIRM_TOOLS = new Set([
24
+ 'memory_manager_remove',
25
+ 'skill_manager_remove',
26
+ 'subagent_manager_remove',
27
+ 'scene_manager_remove',
28
+ 'prompt_manager_remove',
29
+ 'prompt_manager_apply',
30
+ 'mcp_manager_switch',
31
+ 'memory_manager_switch',
32
+ 'skill_manager_switch',
33
+ 'subagent_manager_switch',
34
+ ]);
35
+ /** 取一个必填字符串参数;不是非空字符串就返回空串。 */
36
+ function text(value) {
37
+ return typeof value === 'string' ? value.trim() : '';
38
+ }
39
+ /** 这次写入是不是落在机器级:显式 `scope: "global"`,或全局粒度下没有会话层。 */
40
+ function machineWide(args, mode) {
41
+ return mode === 'global' || args.scope === 'global';
42
+ }
43
+ /** 开关类回执里的目标名词,避免每个分支各拼一遍。 */
44
+ function removeSubject(name) {
45
+ if (name === 'memory_manager_remove')
46
+ return 'memory';
47
+ if (name === 'skill_manager_remove')
48
+ return 'skill';
49
+ if (name === 'subagent_manager_remove')
50
+ return 'persona';
51
+ if (name === 'scene_manager_remove')
52
+ return 'scene';
53
+ return 'AGENTS.md preset';
54
+ }
55
+ /**
56
+ * 这一次调用要不要问用户;要问就返回卡上那句理由,不问返回 `null`。
57
+ *
58
+ * @param name 工具名(大小写与注册名一致)。
59
+ * @param rawArgs 工具入参(模型给的那一份,未校验)。
60
+ * @param mode 当前隔离粒度;`global` 下所有开关写入都是机器级。
61
+ * @returns 确认卡的理由;`null` = 不拦,调用方直接 `next()`。
62
+ * @remarks
63
+ * 只有 `remove` 的 `trash`、`mcp_switch` 的 `stop` 与全局 `on`/`off`、`prompt_apply` 的
64
+ * 正向应用、以及三个 `_switch` 的机器级写入会返回理由。其余 action(`list`/`restore`/
65
+ * `restart`/`apply:false`/会话级开关)一律放行。
66
+ */
67
+ export function argConditionalConfirmReason(name, rawArgs, mode) {
68
+ const args = (rawArgs !== null && typeof rawArgs === 'object' ? rawArgs : {});
69
+ const action = text(args.action);
70
+ if (name.endsWith('_remove')) {
71
+ // 只有 trash 是删除。list 是读、restore 是恢复(与 mcp 的 restart 同一档,不该拦)。
72
+ if (action !== 'trash')
73
+ return null;
74
+ const id = text(args.id);
75
+ // 缺 id 时工具自己会拒;先弹一张卡等于让用户批准一次注定失败的删除。
76
+ if (id === '')
77
+ return null;
78
+ return `Delete ${removeSubject(name)}「${id}」 — moved to the trash, restorable from the panel.`;
79
+ }
80
+ if (name === 'prompt_manager_apply') {
81
+ // apply=false 是撤销(回到本轮应用之前),可逆,不问。
82
+ if (args.apply === false)
83
+ return null;
84
+ const id = text(args.id);
85
+ if (id === '')
86
+ return null;
87
+ return `Apply AGENTS.md preset「${id}」 — effective next turn, machine-wide. A scene-driven baseline is rebound, not overwritten.`;
88
+ }
89
+ if (name === 'mcp_manager_switch') {
90
+ const server = text(args.server);
91
+ if (server === '')
92
+ return null;
93
+ // restart 是恢复路径(服务器挂了只有它能救),场景锁都为它开口 —— 不拦。
94
+ if (action === 'restart')
95
+ return null;
96
+ if (action === 'stop') {
97
+ return `Stop MCP server「${server}」 machine-wide — every conversation still using it is disconnected.`;
98
+ }
99
+ if (action !== 'on' && action !== 'off')
100
+ return null;
101
+ if (!machineWide(args, mode))
102
+ return null;
103
+ return `Turn MCP server「${server}」 ${action} for every conversation (global switch).`;
104
+ }
105
+ if (name === 'memory_manager_switch' || name === 'subagent_manager_switch') {
106
+ if (typeof args.enabled !== 'boolean')
107
+ return null;
108
+ if (!machineWide(args, mode))
109
+ return null;
110
+ const key = name === 'memory_manager_switch' ? text(args.memory) : text(args.name);
111
+ if (key === '')
112
+ return null;
113
+ const subject = name === 'memory_manager_switch' ? 'memory' : 'persona';
114
+ return `Turn ${subject}「${key}」 ${args.enabled ? 'on' : 'off'} for every conversation (global switch).`;
115
+ }
116
+ if (name === 'skill_manager_switch') {
117
+ // prefer 也是一次机器级的持久选择,但 `enabled` 缺省时它是唯一动作。
118
+ const prefer = typeof args.prefer === 'boolean';
119
+ if (typeof args.enabled !== 'boolean' && !prefer)
120
+ return null;
121
+ if (!machineWide(args, mode))
122
+ return null;
123
+ const source = text(args.source);
124
+ const key = source !== '' ? text(args.source) : text(args.name);
125
+ const label = source !== '' ? 'source' : 'skill';
126
+ if (key === '')
127
+ return null;
128
+ if (typeof args.enabled === 'boolean') {
129
+ return `Turn ${label}「${key}」 ${args.enabled ? 'on' : 'off'} for every conversation (global switch).`;
130
+ }
131
+ return `${args.prefer ? 'Make' : 'Stop preferring'} the copy of ${label}「${key}」 win its name collision, machine-wide.`;
132
+ }
133
+ return null;
134
+ }
package/lib/index.js CHANGED
@@ -84,6 +84,7 @@ import { buildMemoryTools } from './tools/memory.js';
84
84
  import { buildRemoveTools } from './tools/remove.js';
85
85
  import { buildSceneTools } from './tools/scene.js';
86
86
  import { buildSubagentTools } from './tools/subagent.js';
87
+ import { ARG_CONDITIONAL_CONFIRM_TOOLS, argConditionalConfirmReason } from './confirm-gate.js';
87
88
  import { createScenePromptSync } from './scene-prompt-sync.js';
88
89
  import { extractExportTurns, serializeTranscript } from './exports/transcript.js';
89
90
  import { spawn } from 'node:child_process';
@@ -4988,6 +4989,21 @@ export default {
4988
4989
  // —— 门禁挂在它上面即覆盖整个模型可达面。标签取中性的「保存」:改一台已有服务器
4989
4990
  // (含改 URL / 命令)与新增一台是同一档危险度,但"新增"在改分支上是句假话。
4990
4991
  mcp_manager_save: '「保存 MCP 服务器」',
4992
+ // 删除与「应用提示词」原先只有描述里的 consent 句。它们动的都是磁盘上那一份:
4993
+ // 删除进回收站可恢复,应用改写的是全局 AGENTS.md 基线 —— 与上面几条同一档,
4994
+ // 门禁不该比"往 hub 里写一个技能文件"更松。
4995
+ memory_manager_remove: '「删除记忆」',
4996
+ skill_manager_remove: '「删除技能」',
4997
+ subagent_manager_remove: '「删除人设」',
4998
+ scene_manager_remove: '「删除场景」',
4999
+ prompt_manager_remove: '「删除提示词预设」',
5000
+ prompt_manager_apply: '「应用提示词预设」',
5001
+ // 四条 switch 只在**机器级**写入时问一次(判据在 `confirm-gate.ts`)。
5002
+ // 默认写本会话,爆炸半径只有一个对话 —— 给默认路径挂卡是纯摩擦。
5003
+ mcp_manager_switch: '「MCP 服务器开关」',
5004
+ memory_manager_switch: '「记忆开关」',
5005
+ skill_manager_switch: '「技能开关」',
5006
+ subagent_manager_switch: '「人设开关」',
4991
5007
  };
4992
5008
  const bypassedByFullAccess = (exec) => {
4993
5009
  if (!isApprovalNever(ctx, exec))
@@ -5017,6 +5033,19 @@ export default {
5017
5033
  return next();
5018
5034
  if (exec.name === 'subagent_manager_run' && !(await subagentManagerRunTargetExists(exec)))
5019
5035
  return next();
5036
+ // 按参数判定的那批(删除的 trash、开关的机器级写入、提示词的正向应用):
5037
+ // 先算"这一次要不要问",不问就直接放行 —— 不能落到末尾那条 "Run a subagent" 的
5038
+ // 兜底分支上。bypass 放到判定之后:`remove list` 这类根本不问的调用不该在
5039
+ // 审计日志里留下一条"跳过了确认"。
5040
+ const confirmName = String(exec.name);
5041
+ if (ARG_CONDITIONAL_CONFIRM_TOOLS.has(confirmName)) {
5042
+ const reason = argConditionalConfirmReason(confirmName, exec.arguments, await scopeStore.mode());
5043
+ if (reason === null)
5044
+ return next();
5045
+ if (bypassedByFullAccess(exec))
5046
+ return next();
5047
+ return Promise.resolve({ kind: 'ask', reason });
5048
+ }
5020
5049
  if (bypassedByFullAccess(exec))
5021
5050
  return next();
5022
5051
  if (exec.name === 'skill_manager_save') {
@@ -80,7 +80,7 @@ export function defineSubagentManagerListTool(subagents) {
80
80
  name: 'subagent_manager_list',
81
81
  // `depth-filtered` 删掉:注入深度是**注入侧**的实现细节
82
82
  // 模型看到的是"目录里有哪些人设",`catalogDepth` 那个词对它没有任何可操作性。
83
- description: 'List personas (pre-configured subagent profiles) with their descriptions. The "Current subagents" reminder carries a view of the same catalog; call this for the always-current full list, or all=true to include disabled personas and ones outside the active scene.',
83
+ description: 'List personas (pre-configured subagent profiles) with descriptions and the file holding each body (read it with your file tools). The "Current subagents" reminder carries a view of the same catalog; call this for the always-current full list, or all=true to include disabled personas and ones outside the active scene.',
84
84
  parameters: {
85
85
  all: { type: 'boolean', description: 'Include disabled personas and ones outside the active scene (default false). Listed ≠ delegable: `run` still refuses those.' },
86
86
  },
@@ -109,9 +109,18 @@ export function defineSubagentManagerListTool(subagents) {
109
109
  // 而工具又不列全,结果是"明明能委派却查不到人设"。
110
110
  // `all=true` 时**标出哪些不可用**:只列名字的话,模型照样分不清哪个能直接委派
111
111
  // (与技能列表标 `shadowed-by:` 同一条理由 —— 列出来不等于能用)。
112
+ // 每行带**正文文件路径**。这个域刻意没有 `subagent_manager_read`(正文是文件,不是
113
+ // 另一份存储),但模型手里有通用文件工具 —— 不给路径,用户说「读一下这个人设的完整
114
+ // 定义」时它只能回「做不到」。清单本来只有 description,正文在 `PersonaDoc.path`
115
+ // (`service.ts` 扫目录时一起记下的绝对路径),这里原样带出去,零额外读取。
116
+ //
117
+ // 放在行尾而不是表头给一个目录模板:模型拼 `<dir>/<name>.md` 要多一步推理,路径里
118
+ // 有空格或非 ASCII 目录名时还可能拼错;每条一个完整路径是零歧义,代价只在调用时付
119
+ // (不是每轮的 schema 成本)。
112
120
  const lines = allowed.map((p) => '- ' + p.name + ' — ' + (p.description || '(no description)') +
113
121
  (p.continuable === true ? CONTINUABLE_MARK : '') +
114
- (includeUnavailable ? (!decideInSession(p, flag, boundSet) ? ' (disabled — turn it on first)' : '') : ''));
122
+ (includeUnavailable ? (!decideInSession(p, flag, boundSet) ? ' (disabled — turn it on first)' : '') : '') +
123
+ (p.path ? ' · ' + p.path : ''));
115
124
  // 默认口径下有多少个没列出来(停用的 + 不在启用场景里的):不报的话,模型看到一份短名单
116
125
  // 会当成"本机只有这些人设"。数量照报,与另外三个 list 的表头同一口径。
117
126
  const hiddenCount = includeUnavailable ? 0 : docs.length - allowed.length;
package/lib/tools/deps.js CHANGED
@@ -22,6 +22,57 @@ export function toolNameList(list) {
22
22
  const head = list.slice(0, TOOL_NAME_LIST_CAP).join(', ');
23
23
  return list.length > TOOL_NAME_LIST_CAP ? head + ' ...(' + list.length + ' total)' : head;
24
24
  }
25
+ /**
26
+ * 同 `candidateNote`,候选已经在手上时用这个(同步、不读盘)。
27
+ *
28
+ * 多数错误路径上数据本来就扫到了(`rules-list` / `skill-state` / `rows` 都在作用域里),
29
+ * 再包一层 thunk 只是绕路。
30
+ */
31
+ export function existingNote(names, label) {
32
+ const list = (names || []).map((v) => String(v ?? '').trim()).filter((v) => v !== '');
33
+ if (!list.length)
34
+ return '';
35
+ return ' Existing ' + label + ': ' + toolNameList(list) + '.';
36
+ }
37
+ /**
38
+ * 错误消息里的「现成候选」:只在出错时出现,不进 schema,所以不占每轮预算。
39
+ *
40
+ * 为什么不写进参数说明:候选随数据变,写进描述必然很快过期,而且每轮都要付一次 token。
41
+ * 模型缺参数、名字打错之后再告诉它「现成的是这几个」,正好是它需要的那一刻 —— 这也正是
42
+ * 口语请求最容易断的一环(用户说「删掉那条记忆」,模型手里只有一个叫法,没有 id)。
43
+ *
44
+ * `read` 失败一律返回空串:取候选失败绝不能改变错误结论 —— 原报错更接近真相。
45
+ */
46
+ export async function candidateNote(read, label) {
47
+ let raw = [];
48
+ try {
49
+ raw = await read();
50
+ }
51
+ catch {
52
+ return '';
53
+ }
54
+ return existingNote(raw, label);
55
+ }
56
+ /**
57
+ * 运行时点名一条工具:在它手里才点名,否则退回中性说法。
58
+ *
59
+ * 静态描述里不能这么做(契约测试会拦),而且指一条模型没有的工具本来就是把它往墙上推。
60
+ * 错误消息与回执是运行时分支、可以点名,但判据仍是 `toolVisibleFor` —— 「这是错误消息
61
+ * 所以随便写」是错的理解:那条约束的实质是「不让模型看见它手里没有的东西」,与字符串
62
+ * 写在哪一行无关。
63
+ *
64
+ * 判定本身抛错时按**不可见**处理:中性说法永远成立,点名可能落空。
65
+ */
66
+ export function toolOrNeutral(deps, agent, tool, named, neutral) {
67
+ let visible = false;
68
+ try {
69
+ visible = deps.toolVisibleFor(tool, agent);
70
+ }
71
+ catch {
72
+ visible = false;
73
+ }
74
+ return visible ? named : neutral;
75
+ }
25
76
  /**
26
77
  * 按名字找技能落在哪个来源(root)。
27
78
  *
@@ -36,25 +87,30 @@ export function toolNameList(list) {
36
87
  * `shadowedBy` 盖住的那一份(同名组里胜出的只有一个),都没有就取第一个。
37
88
  */
38
89
  export async function locateSkillRoot(skillsOps, name) {
90
+ const empty = { ok: true, root: null, canonical: null, roots: [], matches: [], names: [] };
39
91
  const wanted = String(name || '').trim();
40
92
  if (wanted === '')
41
- return { ok: true, root: null, canonical: null, roots: [], matches: [] };
93
+ return empty;
42
94
  let state;
43
95
  try {
44
96
  state = await skillsOps['skill-state']({});
45
97
  }
46
98
  catch {
47
- return { ok: false, root: null, canonical: null, roots: [], matches: [] };
99
+ return { ok: false, root: null, canonical: null, roots: [], matches: [], names: [] };
48
100
  }
49
101
  if (!state || state.ok === false)
50
- return { ok: false, root: null, canonical: null, roots: [], matches: [] };
102
+ return { ok: false, root: null, canonical: null, roots: [], matches: [], names: [] };
51
103
  const roots = [];
104
+ const names = [];
52
105
  const hits = [];
53
106
  for (const root of (state.data && state.data.roots) || []) {
54
107
  roots.push(String(root.key || ''));
55
108
  for (const skill of root.skills || []) {
56
109
  // 与 list / read / save 同一套名字口径:`declaredName || name`,再比目录名。
57
- if (String(skill.declaredName || skill.name || '') !== wanted && String(skill.name || '') !== wanted)
110
+ const canonical = String(skill.declaredName || skill.name || '');
111
+ if (canonical !== '' && names.indexOf(canonical) < 0)
112
+ names.push(canonical);
113
+ if (canonical !== wanted && String(skill.name || '') !== wanted)
58
114
  continue;
59
115
  hits.push({
60
116
  root: String(root.key || ''),
@@ -64,7 +120,7 @@ export async function locateSkillRoot(skillsOps, name) {
64
120
  }
65
121
  }
66
122
  const winner = hits.find((hit) => hit.shadowedBy === '') || hits[0];
67
- return { ok: true, root: winner ? winner.root : null, canonical: winner ? winner.canonical : null, roots, matches: hits };
123
+ return { ok: true, root: winner ? winner.root : null, canonical: winner ? winner.canonical : null, roots, matches: hits, names };
68
124
  }
69
125
  /**
70
126
  * 取本会话的身份与覆盖。宿主没接这条通道、或取不到会话 → `null`(= 按全局)。
package/lib/tools/mcp.js CHANGED
@@ -26,7 +26,7 @@
26
26
  // `mcpm-edit` 里那句 `if (row[field] === undefined) return` 就不会生效,于是
27
27
  // `resolveMaskedKv({}, 旧值)` 把整份 headers / env 静默清空、连 warning 都不给。
28
28
  import { DEFAULT_MCP_NOTE_MAX_LENGTH, normalizeMcpNote } from '../mcp/state-section.js';
29
- import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
29
+ import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
30
30
  /** 「去看清单」那句:`mcp_manager_list` 不在模型手里时不能点名它(调用方按 `toolVisibleFor` 决定给不给)。 */
31
31
  const MCP_LIST_HINT = ' (see mcp_manager_list — all=true also lists disabled ones)';
32
32
  /**
@@ -42,7 +42,11 @@ const MCP_NEUTRAL_HINT = ' (copy the server name from your own `mcp__<server>__<
42
42
  function locate(rows, server, level, listHint = MCP_LIST_HINT) {
43
43
  const hits = (rows || []).filter((r) => String(r.serverName) === server);
44
44
  if (!hits.length) {
45
- throw new Error('no such server: ' + server + (listHint || MCP_NEUTRAL_HINT));
45
+ // 猜错 serverName 是这条族里最常见的一次失败(口语里说的是「github 那个」)。清单这一趟
46
+ // 已经读在手上,直接把现成名字列出来 —— 指路的那两句仍然留着:它们解释**名字从哪来**,
47
+ // 而候选只回答"现在有哪些"。
48
+ throw new Error('no such server: ' + server + (listHint || MCP_NEUTRAL_HINT)
49
+ + existingNote((rows || []).map((r) => String(r.serverName)), 'MCP servers'));
46
50
  }
47
51
  if (level) {
48
52
  const picked = hits.filter((r) => r.level === level);
@@ -222,7 +226,14 @@ export function buildMcpTools(deps) {
222
226
  // 让它在三个动词里选一个,比让它猜两个布尔的组合省一次往返。
223
227
  // `restart` 的含义只在 `action` 参数里说一次:描述里那句
224
228
  // "(reconnects and re-syncs tools)" 与参数说明逐字重复,而模型读参数时两处都在手上。
225
- description: 'Turn one MCP server on or off, restart it, or stop it machine-wide; pass `tool` to target named tools on it. `off` leaves a server running while any conversation still uses it, `stop` ends it for them too. Blocked while the active scene is locked, except restart (the recovery path). Only when the user asks or approves.',
229
+ //
230
+ // 场景锁那句必须**分开说清豁免的范围**。`restart` 在确认门里是放行的(`confirm-gate.ts`:
231
+ // 它是场景锁唯一的恢复出口,加确认卡会把恢复路径本身掐断),所以这句描述是 restart 面前
232
+ // **唯一**的约束。旧写法 "except restart (the recovery path)" 把括号当定语还是理由分不清,
233
+ // 紧挨着的 "Only when the user asks or approves" 就被读成对别的动作说的 —— 模型可能理解成
234
+ // 「restart 是我的自愈手段,不用问」。`the lock skips it, approval does not` 把两个主语
235
+ // 摆在一起,豁免只剥掉锁那一层。
236
+ description: 'Turn one MCP server on or off, restart it, or stop it machine-wide; pass `tool` to target named tools on it. `off` leaves a server running while any conversation still uses it, `stop` ends it for them too. Blocked while the active scene is locked, except restart (the recovery path; the lock skips it, approval does not). Only when the user asks or approves.',
226
237
  parameters: {
227
238
  // 出口必须指向**常驻**来源,不能指向 `mcp_manager_list`:
228
239
  // 那条工具在出厂默认里就是关着的,`listHint()` 在它不可见时返回空串,于是猜错名字时的
@@ -247,6 +258,14 @@ export function buildMcpTools(deps) {
247
258
  throw new Error('action must be on / off / restart / stop (got: ' + (action || '(empty)') + ')');
248
259
  }
249
260
  const server = String((args && args.server) || '').trim();
261
+ // 空名字单独报「缺参数」:落进 `locate` 会变成 `no such server: (空)`,读起来像
262
+ // 「这台服务器不存在」,而真实原因是它根本没传。
263
+ if (server === '') {
264
+ throw new Error('missing argument: server (the server name)' + await candidateNote(async () => {
265
+ const r = await deps.mcpmListView();
266
+ return r && r.ok !== false ? (r.rows || []).map((x) => String(x.serverName)) : [];
267
+ }, 'MCP servers'));
268
+ }
250
269
  // 单值仍然接受(旧提示词 / 手写调用),数组是新增的批量形态。
251
270
  const rawTool = args && args.tool !== undefined && args.tool !== null ? args.tool : undefined;
252
271
  const tools = (Array.isArray(rawTool) ? rawTool : rawTool === undefined ? [] : [rawTool])
@@ -417,8 +436,12 @@ export function buildMcpTools(deps) {
417
436
  throw new Error(blocked);
418
437
  requireGlobalScope(args, 'MCP servers', !sessionLayerOn(deps));
419
438
  const server = String((args && args.server) || '').trim();
420
- if (!server)
421
- throw new Error('missing argument: server (the server name)');
439
+ if (!server) {
440
+ throw new Error('missing argument: server (the server name)' + await candidateNote(async () => {
441
+ const r = await deps.mcpmListView();
442
+ return r && r.ok !== false ? (r.rows || []).map((x) => String(x.serverName)) : [];
443
+ }, 'MCP servers'));
444
+ }
422
445
  const levelArg = args && args.level !== undefined ? String(args.level) : undefined;
423
446
  // `hint` 的三态:省略 = 保持;`''` = **清空**;非空 = 设置。
424
447
  // 此前用 `hintText.trim() !== ''` 判"要不要写备注",把"清空"与"省略"混成一件事 ——
@@ -19,7 +19,7 @@
19
19
  // 本身。memory_manager_save 受 tools/pre-execute 审批门禁。
20
20
  // 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
21
21
  import { GLOBAL_SCENE, SHARED_GROUP } from '../memories/constants.js';
22
- import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
22
+ import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
23
23
  /** 注册记忆域的 model 工具(列表 / 读取 / 检索 / 切换 / 保存)。 */
24
24
  export function buildMemoryTools(deps) {
25
25
  const { defineTool, register } = deps;
@@ -282,7 +282,14 @@ export function buildMemoryTools(deps) {
282
282
  // 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准。
283
283
  const slash = memory.indexOf('/');
284
284
  if (slash <= 0 || slash === memory.length - 1) {
285
- throw new Error('memory must be <scene>/<name> (copy that from the listing; the always-on scene is written global/<name>): ' + (memory || '(empty)'));
285
+ // 这一条错得最有规律:用户口语里说的是「编程约定」,模型手里没有 id,就把那个名字
286
+ // 直接传进来了。给两条现成的 id 比再解释一遍格式有用;读失败就只报格式
287
+ // (`candidateNote` 自己吞掉失败,不改变错误结论)。
288
+ const note = await candidateNote(async () => {
289
+ const r = await deps.rulesOps['rules-list']({});
290
+ return r && r.ok !== false ? (r.rules || []).map((x) => String(x.id)) : [];
291
+ }, 'memory ids');
292
+ throw new Error('memory must be <scene>/<name> (copy that from the listing; the always-on scene is written global/<name>): ' + (memory || '(empty)') + note);
286
293
  }
287
294
  const group = memory.slice(0, slash);
288
295
  const name = memory.slice(slash + 1);
@@ -323,8 +330,14 @@ export function buildMemoryTools(deps) {
323
330
  body.trim() === '' ? 'body' : '',
324
331
  description.trim() === '' ? 'description' : '',
325
332
  ].filter((x) => x !== '');
326
- if (missing.length)
327
- throw new Error('creating a memory needs ' + missing.join(' and ') + ' (' + memory + ' does not exist yet)');
333
+ if (missing.length) {
334
+ // id 不存在 + 内容也不全:最可能是名字记差了一个字。先给**同一场景**里现成的 id
335
+ // (整个库列出来只会把这条错误变成噪音),一条都没有才退回全库。
336
+ const ids = (all.rules || []).map((x) => String(x.id));
337
+ const here = ids.filter((id) => id.indexOf(group + '/') === 0);
338
+ throw new Error('creating a memory needs ' + missing.join(' and ') + ' (' + memory + ' does not exist yet)'
339
+ + existingNote(here.length ? here : ids, 'memory ids'));
340
+ }
328
341
  // 查重只**说出来**,不拒绝 —— 猜错一次就把该记的东西记不下去,比多记一条代价大得多;
329
342
  // 而且"像不像同一条"本来就是人判断的事。只在建的分支提示:改的分支没有"再记一条"的风险。
330
343
  const norm = (value) => String(value ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
@@ -12,7 +12,7 @@
12
12
  import { join } from 'node:path';
13
13
  import { normalizePresetDescription } from '../prompts/service.js';
14
14
  import { hasPromptOverride } from '../scope/scope-overrides.js';
15
- import { sessionScopeOf, text } from './deps.js';
15
+ import { candidateNote, sessionScopeOf, text } from './deps.js';
16
16
  /** 注册提示词域的 model 工具(列表 / 读取 / 应用)。 */
17
17
  export function buildPromptTools(deps) {
18
18
  const { defineTool, register } = deps;
@@ -115,8 +115,14 @@ export function buildPromptTools(deps) {
115
115
  promptScopeTail(scoped?.scope);
116
116
  }
117
117
  const id = String((args && args.id) || '').trim();
118
- if (id === '')
119
- throw new Error('missing argument: id (only optional when apply=false cancels)');
118
+ if (id === '') {
119
+ // 用户口语里很少同时说出预设 id(「换成简洁那版」)—— 缺 id 时就给现成的几个,
120
+ // 只在错误路径上读一次盘。
121
+ throw new Error('missing argument: id (only optional when apply=false cancels)' + await candidateNote(async () => {
122
+ const l = await deps.promptOps['agentsmd-list']({});
123
+ return l && l.ok !== false ? (l.presets || []).map((p) => String(p.id)) : [];
124
+ }, 'presets'));
125
+ }
120
126
  const r = await deps.applyPresetGuarded(id);
121
127
  if (!r.ok)
122
128
  throw new Error(r.error);
@@ -13,7 +13,7 @@
13
13
  //
14
14
  // 参数名统一 `id`:`trash` 时是资源标识(记忆 `<场景>/<名>`、技能名、人设名、预设 id、
15
15
  // 场景名),`restore` 时是 `action=list` 给出的**回收站条目 id** —— 两种含义在描述里写清。
16
- import { globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text } from './deps.js';
16
+ import { candidateNote, globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text, toolOrNeutral, } from './deps.js';
17
17
  /** 三个动词共用的描述骨架。 */
18
18
  function removeDescription(noun) {
19
19
  return 'Delete one ' + noun + ' (to the trash), restore one, or list the trash. '
@@ -54,15 +54,7 @@ function restoredName(r) {
54
54
  };
55
55
  return pick(r) || pick(r && r.data);
56
56
  }
57
- /**
58
- * 一条删除工具的 execute:三个动词的分派与回执。
59
- *
60
- * 会话层:删除是**全局**动作 —— 技能正文、人设 `.md`、场景档案、MCP 补丁
61
- * 提示词预设都只有一份,没有「本会话的副本」,所以这一格的口径就是「全局动作」。
62
- * 所以这里不写会话层,只在**这个对话真有该域覆盖**时补一句尾注:
63
- * 删完之后那条会话覆盖还在(读时忽略,对账才清),不说明的话用户会以为它跟着没了。
64
- */
65
- async function runRemove(deps, cfg, args, agent) {
57
+ async function runRemove(deps, cfg, args, agent, isMemoryId) {
66
58
  const action = String((args && args.action) || '');
67
59
  if (action !== 'trash' && action !== 'restore' && action !== 'list') {
68
60
  throw new Error('action must be trash / restore / list (got: ' + (action || '(empty)') + ')');
@@ -82,8 +74,30 @@ async function runRemove(deps, cfg, args, agent) {
82
74
  // 连提示词那一族也一样(提示词根本不进会话域,更没有「本会话的预设」可删)。
83
75
  requireGlobalScope(args, cfg.noun + 's', !sessionLayerOn(deps));
84
76
  const id = String((args && args.id) || '').trim();
85
- if (id === '')
86
- throw new Error('missing argument: id (required by action=' + action + ')');
77
+ if (id === '') {
78
+ // 恢复的 id 是**回收站条目 id**(与 trash 的资源标识不是一回事),指错地方最费时间 ——
79
+ // 这一条不用候选名单,一句 `action=list` 就是正解。
80
+ let note = '';
81
+ let hint = '';
82
+ if (action === 'restore') {
83
+ note = ' A restore id is a trash entry id — action=list prints them.';
84
+ }
85
+ else {
86
+ note = await candidateNote(cfg.idHelp.list, cfg.idHelp.label);
87
+ // 有候选就不必再说去哪儿拿(两句叠在一起只是把错误读长一倍);一条都读不到时才指路。
88
+ if (note === '') {
89
+ hint = toolOrNeutral(deps, agent, cfg.idHelp.tool, ' Call `' + cfg.idHelp.tool + '` to get one.', cfg.idHelp.neutral);
90
+ }
91
+ }
92
+ throw new Error('missing argument: id (required by action=' + action + ')' + note + hint);
93
+ }
94
+ // 跨族误用里唯一能**确认**的一种:带斜杠的 id 落到别的域,且这个 id 确实在记忆库里。
95
+ // 只按形状(`a/b`)判会误伤 —— 场景名与技能名都没有禁止斜杠的校验,用户起的名字里
96
+ // 完全可能出现。所以这里读一次记忆库确认存在;读不到就当不是,宁可少说一句。
97
+ if (action === 'trash' && cfg.domain !== 'memory' && id.indexOf('/') > 0 && await isMemoryId(id)) {
98
+ throw new Error('"' + id + '" is a memory id (memory ids are <scene>/<name>); this tool handles ' + cfg.noun + 's.'
99
+ + toolOrNeutral(deps, agent, 'memory_manager_remove', ' Use `memory_manager_remove` with action=trash for it.', ' Pass it to the memory manager instead — this one only handles ' + cfg.noun + 's.'));
100
+ }
87
101
  const r = action === 'trash' ? await cfg.trash(args) : await cfg.restore(args);
88
102
  if (!r || r.ok === false)
89
103
  throw new Error((r && r.error) || (action === 'trash' ? 'failed to move it to the trash' : 'restore failed'));
@@ -106,6 +120,23 @@ export function buildRemoveTools(deps) {
106
120
  const sub = deps.subagentOps;
107
121
  const pr = deps.promptOps;
108
122
  const sc = deps.sceneOps;
123
+ /**
124
+ * 这个 id 是不是记忆库里一条真实存在的记忆。
125
+ *
126
+ * 只在「带斜杠的 id 传到别的域」那条错误路径上调用,正常删除不会碰它。
127
+ * 读失败一律 false:探不到就不说那句话,错误结论仍由原逻辑给出。
128
+ */
129
+ const isMemoryId = async (id) => {
130
+ try {
131
+ const r = await mem['rules-list']({});
132
+ if (!r || r.ok === false)
133
+ return false;
134
+ return (r.rules || []).some((x) => String(x.id) === id);
135
+ }
136
+ catch {
137
+ return false;
138
+ }
139
+ };
109
140
  const memoryCfg = {
110
141
  noun: 'memory', label: 'memory', domain: 'memory',
111
142
  trash: (a) => mem['rules-remove']({ id: String(a.id || '') }),
@@ -116,6 +147,15 @@ export function buildRemoveTools(deps) {
116
147
  throw new Error((r && r.error) || 'failed to read the trash');
117
148
  return (r.entries || []).map((e) => ({ id: String(e.trashId), name: String(e.name), deletedAt: e.deletedAt }));
118
149
  },
150
+ idHelp: {
151
+ tool: 'memory_manager_list',
152
+ neutral: ' — the ids are the lines in the "Current memories" reminder.',
153
+ label: 'memory ids',
154
+ list: async () => {
155
+ const r = await mem['rules-list']({});
156
+ return r && r.ok !== false ? (r.rules || []).map((x) => String(x.id)) : [];
157
+ },
158
+ },
119
159
  };
120
160
  const skillCfg = {
121
161
  noun: 'skill', label: 'skill', domain: 'skills',
@@ -136,6 +176,23 @@ export function buildRemoveTools(deps) {
136
176
  throw new Error((r && r.error) || 'skill-state failed');
137
177
  return ((r.data && r.data.trash) || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
138
178
  },
179
+ idHelp: {
180
+ tool: 'skill_manager_list',
181
+ neutral: ' — the names are in the "Current skills" reminder.',
182
+ label: 'skills',
183
+ list: async () => {
184
+ const r = await sk['skill-state']({});
185
+ const names = [];
186
+ for (const root of (r && r.ok !== false && r.data && r.data.roots) || []) {
187
+ for (const skill of root.skills || []) {
188
+ const n = String(skill.declaredName || skill.name || '');
189
+ if (n !== '' && names.indexOf(n) < 0)
190
+ names.push(n);
191
+ }
192
+ }
193
+ return names;
194
+ },
195
+ },
139
196
  };
140
197
  const subagentCfg = {
141
198
  noun: 'persona', label: 'persona', domain: 'subagents',
@@ -147,6 +204,15 @@ export function buildRemoveTools(deps) {
147
204
  throw new Error((r && r.error) || 'failed to read the trash');
148
205
  return (r.trash || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
149
206
  },
207
+ idHelp: {
208
+ tool: 'subagent_manager_list',
209
+ neutral: ' — the names are in the "Current subagents" reminder.',
210
+ label: 'personas',
211
+ list: async () => {
212
+ const r = await sub['subagent-list']({});
213
+ return r && r.ok !== false ? (r.subagents || []).map((p) => String(p.name)) : [];
214
+ },
215
+ },
150
216
  };
151
217
  const promptCfg = {
152
218
  noun: 'preset', label: 'preset',
@@ -159,6 +225,15 @@ export function buildRemoveTools(deps) {
159
225
  const arr = Array.isArray(r) ? r : (r.presets || r.trash || r.entries || []);
160
226
  return arr.map((e) => ({ id: String(e.id), name: String(e.name || e.id), deletedAt: e.deletedAt }));
161
227
  },
228
+ idHelp: {
229
+ tool: 'prompt_manager_list',
230
+ neutral: ' — the one in effect is named in the "Current prompt" reminder.',
231
+ label: 'presets',
232
+ list: async () => {
233
+ const r = await pr['agentsmd-list']({});
234
+ return r && r.ok !== false ? (r.presets || []).map((p) => String(p.id)) : [];
235
+ },
236
+ },
162
237
  };
163
238
  const sceneCfg = {
164
239
  noun: 'scene', label: 'scene', domain: 'scene',
@@ -172,6 +247,15 @@ export function buildRemoveTools(deps) {
172
247
  throw new Error((r && r.error) || 'failed to read the trash');
173
248
  return (r.trash || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
174
249
  },
250
+ idHelp: {
251
+ tool: 'scene_manager_list',
252
+ neutral: ' — the names are in the "Current scene" reminder.',
253
+ label: 'scenes',
254
+ list: async () => {
255
+ const r = await sc['rules-list']({});
256
+ return r && r.ok !== false ? (r.scenes || []).map((s) => String(s.name)) : [];
257
+ },
258
+ },
175
259
  };
176
260
  register(defineTool({
177
261
  name: 'memory_manager_remove',
@@ -182,7 +266,7 @@ export function buildRemoveTools(deps) {
182
266
  scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
183
267
  },
184
268
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
185
- async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent); },
269
+ async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent, isMemoryId); },
186
270
  }));
187
271
  register(defineTool({
188
272
  name: 'skill_manager_remove',
@@ -194,7 +278,7 @@ export function buildRemoveTools(deps) {
194
278
  root: { type: 'string', description: 'Source root the skill lives in. Default: whichever source holds that skill; only used by action=trash.' },
195
279
  },
196
280
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
197
- async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent); },
281
+ async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent, isMemoryId); },
198
282
  }));
199
283
  register(defineTool({
200
284
  name: 'subagent_manager_remove',
@@ -205,7 +289,7 @@ export function buildRemoveTools(deps) {
205
289
  scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
206
290
  },
207
291
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
208
- async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent); },
292
+ async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent, isMemoryId); },
209
293
  }));
210
294
  register(defineTool({
211
295
  name: 'prompt_manager_remove',
@@ -216,7 +300,7 @@ export function buildRemoveTools(deps) {
216
300
  scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a preset writes the one global baseline', 'there is nothing per-conversation to delete') },
217
301
  },
218
302
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
219
- async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent); },
303
+ async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent, isMemoryId); },
220
304
  }));
221
305
  register(defineTool({
222
306
  name: 'scene_manager_remove',
@@ -227,6 +311,6 @@ export function buildRemoveTools(deps) {
227
311
  scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC_SCENE },
228
312
  },
229
313
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
230
- async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent); },
314
+ async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent, isMemoryId); },
231
315
  }));
232
316
  }
@@ -24,7 +24,7 @@
24
24
  // 理由是"那是改运行时环境的动作";补上 `_switch` 的取舍记在 CHANGELOG 里 —— 要点是
25
25
  // **场景段的动作句仍然不加回来**:「上下文注入只给现在是什么」是同一天定下的原则,
26
26
  // 不因为多了一条工具就破例(工具描述本来就是写"什么时候该用它"的地方)。
27
- import { effectiveScope, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
27
+ import { candidateNote, effectiveScope, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
28
28
  import { FACTORY_TOOL_TABLE_PRESET } from './table.js';
29
29
  /** 档案里由模型设置的段(`memories` 段在 P5 已废弃,不再是档案的一部分)。
30
30
  * `mcpNotes`与其余三段同族:整段替换、段缺席 = 不碰这一域。 */
@@ -159,6 +159,20 @@ function agentsMdNote(sync, action) {
159
159
  }
160
160
  return notes.join('');
161
161
  }
162
+ /**
163
+ * 「缺场景名」时的补救:现成的场景名读一次盘带出来。
164
+ *
165
+ * 只在错误路径上调用。场景名是用户口语里给出的那个词(「切到写作场景」),而 schema 里
166
+ * 要的是**确切名字**(单个路径段,界面显示名可能不同)—— 不给候选,模型只能猜第二次。
167
+ * 读不到(或一个场景都没有)时退回常驻来源,不点名任何工具。
168
+ */
169
+ async function sceneCandidates(deps) {
170
+ const note = await candidateNote(async () => {
171
+ const r = await deps.rulesOps['rules-list']({});
172
+ return r && r.ok !== false ? (r.scenes || []).map((s) => String(s.name)) : [];
173
+ }, 'scenes');
174
+ return note !== '' ? note : ' — the names are in the "Current scene" reminder.';
175
+ }
162
176
  /** 注册场景域的 model 工具(列表 / 进入 / 保存 / 删除)。 */
163
177
  export function buildSceneTools(deps) {
164
178
  const { defineTool, register } = deps;
@@ -277,7 +291,7 @@ export function buildSceneTools(deps) {
277
291
  if (action === 'enter') {
278
292
  wanted = String((args && args.scene) || '').trim();
279
293
  if (wanted === '')
280
- throw new Error('action=enter needs scene: the scene name (copy it from the scene_manager_list line)');
294
+ throw new Error('action=enter needs scene: the scene name' + await sceneCandidates(deps));
281
295
  if (wanted.indexOf('/') >= 0 || wanted.indexOf('\\') >= 0)
282
296
  throw new Error('a scene name is a single path segment (no / or \\): ' + wanted);
283
297
  }
@@ -296,7 +310,7 @@ export function buildSceneTools(deps) {
296
310
  if (action === 'enter') {
297
311
  scene = String((args && args.scene) || '').trim();
298
312
  if (scene === '')
299
- throw new Error('action=enter needs scene: the scene name (copy it from the scene_manager_list line)');
313
+ throw new Error('action=enter needs scene: the scene name' + await sceneCandidates(deps));
300
314
  // 场景名是**单个路径段**(与 scene_manager_save 同一条校验、同一句报错)。
301
315
  if (scene.indexOf('/') >= 0 || scene.indexOf('\\') >= 0) {
302
316
  throw new Error('a scene name is a single path segment (no / or \\): ' + scene);
@@ -5,7 +5,7 @@
5
5
  // (先读一次 `skill-state`)。改的分支走新加的 `skill-update` op,它只认本插件可写的两个根
6
6
  // (hub = 导入落点 / dsh = 新建默认落点)里的胜出者。
7
7
  import { toKebab } from '../skills/core.js';
8
- import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
8
+ import { effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
9
9
  /** 注册技能域的 model 工具(列表 / 启停 / 新建或更新)。 */
10
10
  export function buildSkillTools(deps) {
11
11
  const { defineTool, register } = deps;
@@ -187,7 +187,15 @@ export function buildSkillTools(deps) {
187
187
  const listHint = deps.toolVisibleFor('skill_manager_list', exec && exec.agent)
188
188
  ? ' — call skill_manager_list (pass all=true) to see what is installed'
189
189
  : '';
190
- throw new Error('no skill named "' + wanted + '"' + (rootWanted ? ' in source "' + rootWanted + '"' : '') + listHint);
190
+ // 名字打错是这条错误最常见的成因,而现成的名字这一次已经扫到了(`data.roots` 在手),
191
+ // 不必再读一次盘。条目多时只列前几个,见 `toolNameList`。
192
+ const names = [];
193
+ for (const root of data.roots || []) {
194
+ for (const skill of root.skills || [])
195
+ names.push(String(skill.declaredName || skill.name || ''));
196
+ }
197
+ throw new Error('no skill named "' + wanted + '"' + (rootWanted ? ' in source "' + rootWanted + '"' : '') + listHint
198
+ + existingNote(names, 'skills'));
191
199
  }
192
200
  // 胜出者优先:同名的影子副本读得到,但那不是生效的一份,所以默认不选它。
193
201
  const picked = hits.find((hit) => !hit.shadowedBy && hit.enabled)
@@ -380,7 +388,8 @@ export function buildSkillTools(deps) {
380
388
  // 探得到、就是没这个技能:当场把"查过哪些来源"说清楚。否则模型收到 op 那句不带
381
389
  // 来源信息的「技能不存在」后,只能猜该传哪个 root(smoke-test P1-4-old 同一处)。
382
390
  if (found.ok) {
383
- throw new Error('no such skill: ' + name + (found.roots.length ? ' (searched ' + found.roots.join(', ') + ')' : ''));
391
+ throw new Error('no such skill: ' + name + (found.roots.length ? ' (searched ' + found.roots.join(', ') + ')' : '')
392
+ + existingNote(found.names, 'skills'));
384
393
  }
385
394
  // 探不到(skill-state 失败)就别在这里编结论:退回旧默认,交给 op 报它自己的错。
386
395
  return 'dsh';
@@ -10,7 +10,10 @@
10
10
  // 实测数字(口径:宿主 `recordToolSize` 的 `ceil(JSON.stringify(header.tools).length / 4) + 4`,
11
11
  // 即**字符数 / 4**;界面「模型工具表」那行合计与逐条 ≈tok 就是这份,逐条相加与整份数组
12
12
  // 的算法差不到 1%):
13
- // · 重测:二十条隐藏 ≈**5,213 tok**(≈20,852 字符),默认可见那六条 ≈**1,547 tok**。
13
+ // · 重测:二十条隐藏 ≈**5,213 tok**(≈20,852 字符),默认可见那六条 ≈**1,547 tok**
14
+ // (0.21.5 又动了默认可见的两条:`mcp_manager_switch` 补 38 字符的场景锁豁免说明(+10),
15
+ // `subagent_manager_list` 补正文文件路径的说明(+14),同一口径现为 **1,571**;
16
+ // 隐藏那二十条没动,仍是 5,213)。
14
17
  // 比 10-18 那份(16,743 字符 ≈4,186)涨了两成 —— 会话作用域这轮给工具描述加了"写本对话
15
18
  // 还是全局""`scope` 参数""租约"这些句子,名单一个字没变。
16
19
  // 那次实测的名单里还没有 `memory_manager_search`(它自己 ≈70 tok 未计入)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-tool-management",
3
- "version": "0.21.4",
3
+ "version": "0.21.5",
4
4
  "description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
5
5
  "repository": {
6
6
  "type": "git",
Binary file
Binary file
Binary file