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
package/lib/tools/deps.js CHANGED
@@ -15,6 +15,7 @@ export function text(value) {
15
15
  * 截断则是因为这些文字都要进上下文,不能无上限。
16
16
  */
17
17
  export const TOOL_NAME_LIST_CAP = 6;
18
+ /** 把工具名列表折成一句可读文案(超长只报前几个与总数)。 */
18
19
  export function toolNameList(list) {
19
20
  if (!list.length)
20
21
  return 'none';
@@ -24,7 +25,7 @@ export function toolNameList(list) {
24
25
  /**
25
26
  * 按名字找技能落在哪个来源(root)。
26
27
  *
27
- * 为什么需要它(2026-10-15 smoke-test P0-1):`skill-create` 的默认落点是 **hub**
28
+ * 为什么需要它:`skill-create` 的默认落点是 **hub**
28
29
  * (`tool-management/skills/`,与界面「创建技能」一致),而 `skill-enable` / `skill-disable` /
29
30
  * `skill-prefer` / `skill-delete` 这些 op 的默认 root 是 **dsh**。于是「建完就启用」这条
30
31
  * 最自然的链路必然报「技能不存在」—— 同一个动作在工具侧落 hub、在开关侧查 dsh。
@@ -82,7 +83,7 @@ export function sessionScopeOf(deps, agent) {
82
83
  }
83
84
  }
84
85
  /**
85
- * 全局动作的回执尾注(0.21.2):**只在这个对话真有该域覆盖时**才出现。
86
+ * 全局动作的回执尾注:**只在这个对话真有该域覆盖时**才出现。
86
87
  *
87
88
  * 为什么需要:`*_save` / `*_remove` / `prompt_manager_*` 动的是磁盘上的那一份 —— 技能、
88
89
  * 人设、场景、MCP 服务器、提示词预设都是**机器级**对象,没有"本会话的一份"。模型据此
@@ -106,7 +107,7 @@ export function globalActionNote(deps, agent, domain, noun) {
106
107
  ' of its own ' + noun + ' switch(es), which still take precedence here — clear them if this change should apply to it too.';
107
108
  }
108
109
  /**
109
- * 一条工具这次的 `scope` 到底走哪条路(0.21.2+ 全局粒度)。
110
+ * 一条工具这次的 `scope` 到底走哪条路(含全局粒度)。
110
111
  *
111
112
  * 唯一的判定点。三种粒度下 `scope` 的**默认值**不同:
112
113
  *
@@ -129,13 +130,13 @@ export function sessionLayerOn(deps) {
129
130
  return deps.scopeMode?.() !== 'global';
130
131
  }
131
132
  /**
132
- * 全局动作的**歧义守卫**(0.21.2,计划 §8.2 的「会话层下拒绝并说明」)。
133
+ * 全局动作的**歧义守卫**(会话层下拒绝并说明)。
133
134
  *
134
135
  * 只加在**有会话层同胞**的那几条上:技能 / 人设 / 场景 / MCP 服务器各自都有一条
135
136
  * `*_manager_switch` 能按会话改「看不看得到」,于是「删掉它」在会话语境里天然有歧义 ——
136
137
  * 用户说的可能是「这个对话里别再用它」,而这条工具动的是磁盘上的那一份。
137
138
  *
138
- * **缺省不拒**(`scope` 省略 = 全局,与上一版逐字相同):这几条工具每个都要付 token,
139
+ * **缺省不拒**(`scope` 省略 = 全局,行为不变):这几条工具每个都要付 token,
139
140
  * 而"每次删除都先失败一次再重试"是纯摩擦 —— 模型并不知道用户此刻在面板里编辑哪一层。
140
141
  * 真正要挡的是**模型自己以为在改会话**:它显式写了 `scope: "session"` 时,这里当场纠回来,
141
142
  * 而不是静默地改掉全局。
@@ -146,7 +147,7 @@ export function sessionLayerOn(deps) {
146
147
  * 加在:技能 / 人设 / 场景 / MCP 四条 `*_save`、五条 `*_remove`。
147
148
  * 不加在:`memory_manager_save`(落 `<场景>/<名字>`,写哪儿由 id 自己说清)、
148
149
  * `*_manager_switch`(它们本来就按会话写,`scope` 是真的)。
149
- * `prompt_manager_apply` 也从清单里去掉了(2026-10-21 审查 P2-2):它的参数表里没有
150
+ * `prompt_manager_apply` 也从清单里去掉了:它的参数表里没有
150
151
  * `scope`,守卫读不到东西 —— 模型按 schema 不可能传,这条守卫等于永不触发,留着只会
151
152
  * 让人以为它被守住了。提示词只有全局一层,参数表已经说清。
152
153
  */
@@ -161,20 +162,20 @@ export function requireGlobalScope(args, what, isolationOff = false) {
161
162
  + 'To change what THIS conversation sees instead, use the matching *_manager_switch.');
162
163
  }
163
164
  /**
164
- * 模型面 `scope` 参数的共同措辞(0.21.2 描述瘦身)。
165
+ * 模型面 `scope` 参数的共同措辞。
165
166
  *
166
167
  * 为什么收成一处:同一件事(这一格只有全局一层)此前在 14 个参数上各写一套,最长的一条
167
168
  * 563 字符 —— 这些字节每个请求都跟着工具表发一遍。可写会话层的那几条各域还要补自己的
168
169
  * 存储名与租约语义,所以只收这一类。
169
170
  *
170
- * `unless isolation is off`(0.21.2+):全局粒度下没有会话层,`scope: "session"` 的所指
171
+ * `unless isolation is off`:全局粒度下没有会话层,`scope: "session"` 的所指
171
172
  * 就是全局,守卫也放行 —— 只说"被拒"会让模型在一个合法的调用前先自我否决。
172
173
  */
173
174
  export function scopeGlobalOnlyDesc(what, instead) {
174
175
  return 'Always global — ' + what + ' ("session" is refused unless isolation is off); ' + instead + '.';
175
176
  }
176
177
  /**
177
- * 模型面「会话层」`scope` 参数的共同措辞(2026-10-21 审查 P0-1)。
178
+ * 模型面「会话层」`scope` 参数的共同措辞。
178
179
  *
179
180
  * 为什么不能写死 "this conversation only":隔离粒度可切(`scope-mode-set`)。切到工作区后
180
181
  * `session` 这一档写的是 `ws:<cwd>` 那一格 —— **同工作区的每个对话都读它**;关掉隔离
@@ -190,10 +191,13 @@ export function scopeSessionDesc(tail) {
190
191
  return 'session (default) = this conversation; its whole workspace under workspace isolation; machine-wide once isolation is off. ' + tail;
191
192
  }
192
193
  /**
193
- * 会话层写入回执的统一后缀(2026-10-21 审查 P0-1 延伸)。
194
+ * 会话层写入回执的统一后缀:按**当前隔离粒度**说清影响范围。
194
195
  *
195
- * 与 `scopeSessionDesc` 同一件事,但用在**回执**上:原文五处都写 "**for this conversation
196
- * only**",在工作区粒度下是同一个问题 —— 写的是 `ws:<cwd>` 那一格,同工作区的每个对话都读它。
196
+ * 为什么必须带 `deps`:粒度是运行时事实(可切),而这句话会被 agent 原样转述给用户。
197
+ * 此前写成「this conversation, or every conversation in its workspace under workspace
198
+ * isolation」—— 三档同时成立,于是它什么都没说:用户问「是不是只影响这个对话」,
199
+ * agent 只能把这句话再念一遍。拿得到粒度就写死一档;拿不到(宿主没接这条通道)
200
+ * 才退回那句兜底。
197
201
  *
198
202
  * 只在会话层真的被写到时才用。全局粒度下 `effectiveScope` 会把所有写入导向全局,
199
203
  * 回执走各域原有的"机器级"措辞,不会到这里。
@@ -201,9 +205,25 @@ export function scopeSessionDesc(tail) {
201
205
  * 回执不是常驻成本(只在调用时出现一次),所以这里可以写全,不必像工具描述那样抠字:
202
206
  * agent 会把这句话原样转述给用户,含糊的措辞比长一点的措辞贵得多。
203
207
  */
204
- export function scopeOnlyNote() {
208
+ export function scopeOnlyNote(deps) {
209
+ const mode = deps.scopeMode?.();
210
+ if (mode === 'workspace')
211
+ return ' **for this whole workspace only** (every conversation in it; other workspaces are unaffected)';
212
+ if (mode === 'session')
213
+ return ' **for this conversation only**';
205
214
  return ' **for this scope only** (this conversation, or every conversation in its workspace under workspace isolation)';
206
215
  }
216
+ /**
217
+ * 「全局没动、别人不受影响」那句:谁算「别人」由粒度决定。
218
+ *
219
+ * 工作区粒度下同工作区的其它对话读的是**同一格**,照旧写 "other conversations keep
220
+ * theirs" 就是假话 —— 而且它与同一句回执里的 `scopeOnlyNote` 直接打架。
221
+ */
222
+ export function globalUnchangedNote(deps) {
223
+ return deps.scopeMode?.() === 'workspace'
224
+ ? 'The global setting is unchanged; other workspaces keep theirs.'
225
+ : 'The global setting is unchanged; other conversations keep theirs.';
226
+ }
207
227
  /** 全局粒度下写入回执的说明:让 agent 别把这句转述成"只影响这个对话"。 */
208
228
  export function isolationOffNote(deps) {
209
229
  return deps.scopeMode?.() === 'global'
package/lib/tools/mcp.js CHANGED
@@ -1,7 +1,7 @@
1
- // MCP 域的 model 工具(2026-09-19 从 index.ts 的注册区抽出;2026-09-23 合并):
1
+ // MCP 域的 model 工具(从 index.ts 的注册区抽出;合并):
2
2
  // mcp_manager_list / mcp_manager_switch / mcp_manager_save。
3
3
  //
4
- // 两条合并理由(0.14.0 用户裁定):
4
+ // 两条合并理由:
5
5
  // · set_enabled + restart → switch:两者都是"拨一下这台服务器",只是动词不同。合并后
6
6
  // 由 `action` 自报动词,工具名不再需要用长度去区分"启停"与"重启"。
7
7
  // · add + edit → save:改一台已配置的服务器(含 URL / 命令)与新增一台危险度同级
@@ -13,7 +13,7 @@
13
13
  // 所以 switch 里只有 on|off 过 `lockedSceneGuard()`,restart 不过;与面板侧
14
14
  // `guardLockedOps(frozenOps('all'))` 的口径逐字一致(两处口径不同才是真的"说假话")。
15
15
  //
16
- // restart 现在是**唯一**的重启入口:面板侧那颗重启键用户此前已删除(2026-10-12 复核,
16
+ // restart 现在是**唯一**的重启入口:面板侧那颗重启键用户此前已删除(复核,
17
17
  // 客户端已无任何 restart 调用方)。这不是要把它也删掉 —— 工具是模型按需调用的面,与面板
18
18
  // 按钮是两回事;面板删掉只说明"不想让人手点",而"服务器卡住、让模型重连一下"这条恢复路径
19
19
  // 仍然成立,且它正是上面那条"锁定期间唯一不冻结的写"的立足点。删掉它等于把场景锁定时的
@@ -26,14 +26,14 @@
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, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
29
+ import { effectiveScope, 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
  /**
33
33
  * 指不到 `mcp_manager_list` 时的**中性出口**:不点名任何工具,两条常驻来源都成立
34
34
  * —— 模型自己的 `mcp__<server>__<tool>` 工具名(就在它的 schema 里),以及注入段。
35
35
  *
36
- * 为什么必须有这一句(2026-10-14 对抗性审查 P0-1):`mcp_manager_switch` 是默认**唯一可见**
36
+ * 为什么必须有这一句:`mcp_manager_switch` 是默认**唯一可见**
37
37
  * 的 MCP 工具,猜错 serverName 时若报错里只有「没有这台服务器:X」,模型拿不到任何补救线索
38
38
  * —— 它只能猜第二次。出口要么指向工具(那条工具得在它手里),要么指向这两条常驻来源。
39
39
  */
@@ -71,24 +71,41 @@ function kvToText(map) {
71
71
  function argsToText(value) {
72
72
  return Array.isArray(value) ? value.join(' ') : String(value == null ? '' : value);
73
73
  }
74
+ /** 注册 MCP 域的 model 工具(列表 / 预览 / 启停 / 导入)。 */
74
75
  export function buildMcpTools(deps) {
75
76
  const { defineTool, register } = deps;
76
77
  /**
77
78
  * 那句"去看清单"要不要给:`mcp_manager_list` 在出厂默认里就是关着的,点名一条模型没有的工具
78
79
  * 只会让它白跑一趟(执行侧拦住它,而它看不出为什么)。
79
80
  *
80
- * 判据按 **agent** 而不是全局开关(2026-10-14 对抗性审查 P0-1):全局关着、但这个人设没砍掉
81
+ * 判据按 **agent** 而不是全局开关:全局关着、但这个人设没砍掉
81
82
  * 它时,那句话是对的;反过来,全局开着、而这个人设用 `toolsDeny` 砍掉了它时,只读全局开关
82
83
  * 就会让我们点名一条它手里没有的工具。与注入框架 `how` 行同一份判据(`toolVisibleFor`)。
83
84
  */
84
85
  const listHint = (agent) => (deps.toolVisibleFor('mcp_manager_list', agent) ? MCP_LIST_HINT : '');
86
+ /**
87
+ * 本作用域里某个工具那一格的生效值(四层并值)。`undefined` = 这一层没话说,落到全局。
88
+ *
89
+ * 必须问:`mcp_manager_switch` 的 `tool` 分支默认写的是**会话层** `mcpTools`,
90
+ * 而 `mcpm-tools` 报的是**全局**停用表 —— 不投影的话,本作用域刚关掉的工具在清单里
91
+ * 仍显示为开着,模型据此回答"它开着"就是错的(运行侧确实已经拒了它)。
92
+ */
93
+ const toolFlag = (agent, key) => {
94
+ if (deps.sessionFlagOf === undefined)
95
+ return undefined;
96
+ try {
97
+ return deps.sessionFlagOf(agent, 'mcpTools', key);
98
+ }
99
+ catch {
100
+ return undefined;
101
+ }
102
+ };
85
103
  register(defineTool({
86
104
  name: 'mcp_manager_list',
87
105
  // 注入段与本工具的关系要**如实说成筛过的视图**(而非"同一份清单"):注入段只列当前真有
88
106
  // 工具注册的服务器(停用与掉线的都不进),也不带 level / loader / 工具数。把这个盲区写出来
89
107
  // 是行动依据 —— 模型要知道"停用 / 掉线的那台去哪查"就得靠这句(all=true)。
90
108
  //
91
- // 2026-10-15 注入文本审查:删掉两处白付的 token ——
92
109
  // ① 括号里那句把 "Current MCP servers" reminder 的**内容**逐项列了一遍(可用 / 工具全停 /
93
110
  // 备注 / 停用不进),而那段 reminder 每轮就在模型上下文里,它自己看得到;
94
111
  // ② `where loader:on:<phase> is the loader's current phase` —— 用自己解释自己
@@ -110,11 +127,11 @@ export function buildMcpTools(deps) {
110
127
  if (!r.ok)
111
128
  throw new Error(r.error);
112
129
  const all = r.rows || [];
113
- // 默认只列「已启用」的(用户裁定 2026-09-16,与技能 / 记忆列表同口径):停用的服务器
130
+ // 默认只列「已启用」的(与技能 / 记忆列表同口径):停用的服务器
114
131
  // 模型调不到,列出来只是噪音。表头给出全量口径,所以不会变成盲区。
115
- // 会话层(0.21.2):本会话隐藏的服务器 —— 它们**此刻一条工具都调不到**,与全局停用同形。
132
+ // 会话层:本会话隐藏的服务器 —— 它们**此刻一条工具都调不到**,与全局停用同形。
116
133
  // 默认口径下按停用处理(不列);`all=true` 时列出来并标注,否则模型会以为这台服务器不存在。
117
- // 逐行问谓词(0.21.2):行数组就是全集,判据(覆盖 → 场景层 → 基线)在 index.ts 一份。
134
+ // 逐行问谓词:行数组就是全集,判据(覆盖 → 场景层 → 基线)在 index.ts 一份。
118
135
  const offHere = new Set();
119
136
  if (deps.sessionHiddenServer) {
120
137
  for (const x of all) {
@@ -131,7 +148,7 @@ export function buildMcpTools(deps) {
131
148
  // 自己 schema 里的 `mcp__*` 工具对得上;被场景收窄 / 手动关掉的工具不算。
132
149
  const usableTools = typeof x.enabledToolCount === 'number' ? x.enabledToolCount : x.toolCount;
133
150
  // 「本会话关掉」必须与「全局停用」分开说:前者换个对话就回来了,后者要改配置。
134
- // 0.21.2 起还有第三种:**全局意图 off、但本会话认领着它**(租约)—— 对这里调用
151
+ // 还有第三种:**全局意图 off、但本会话认领着它**(租约)—— 对这里调用
135
152
  // 模型的那个会话来说它是可用的,但别的对话看不到;不说清就会被读成"全局开着"。
136
153
  const serverName = String(x.serverName);
137
154
  const globalOn = x.intent === 'blocked' ? false : (typeof x.globalOn === 'boolean' ? x.globalOn : x.disabled !== true);
@@ -167,9 +184,19 @@ export function buildMcpTools(deps) {
167
184
  lines.push(' ' + (x.disabled ? '(tools not recorded: server is off)' : '(no tools recorded)'));
168
185
  continue;
169
186
  }
170
- lines.push(' tools: ' + items.map((it) => it.name + (it.enabled === false ? ' (off)' : '')).join(', '));
187
+ lines.push(' tools: ' + items.map((it) => {
188
+ // 服务器在这一层整个不可用时,逐工具不再重复标注:上面那行已经说了它不可用。
189
+ // 停用表读不出来时同理 —— 那一档执行侧全拒,(on here) 会与上面那句打架。
190
+ const here = offHere.has(String(x.serverName)) || (t && t.disabledState === 'unknown')
191
+ ? undefined
192
+ : toolFlag(exec && exec.agent, String(x.serverName) + '/' + String(it.name));
193
+ const off = here === undefined ? it.enabled === false : !here;
194
+ if (!off)
195
+ return String(it.name) + (it.enabled === false ? ' (on here)' : '');
196
+ return String(it.name) + (it.enabled === false ? ' (off)' : ' (off here)');
197
+ }).join(', '));
171
198
  }
172
- // 会话层(0.21.2,计划 §8.2「mcp_manager_list 标注本会话可见性」):本会话停用的服务器
199
+ // 会话层(`mcp_manager_list` 标注本会话可见性):本会话停用的服务器
173
200
  // 与全局停用**同形**(默认不列、all=true 标注),但两者的含义完全不同 —— 前者换个对话
174
201
  // 就回来,后者要改配置。表头点一句,模型才不会把这份清单当成"这台机器的配置"。
175
202
  const sessionLine = offHere.size === 0
@@ -193,11 +220,11 @@ export function buildMcpTools(deps) {
193
220
  name: 'mcp_manager_switch',
194
221
  // 为什么 action 是必填枚举而不是两个可选布尔:模型最容易犯的错是"想重启却只传了 server",
195
222
  // 让它在三个动词里选一个,比让它猜两个布尔的组合省一次往返。
196
- // `restart` 的含义只在 `action` 参数里说一次(2026-10-15 注入文本审查):描述里那句
223
+ // `restart` 的含义只在 `action` 参数里说一次:描述里那句
197
224
  // "(reconnects and re-syncs tools)" 与参数说明逐字重复,而模型读参数时两处都在手上。
198
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.',
199
226
  parameters: {
200
- // 出口必须指向**常驻**来源,不能指向 `mcp_manager_list`(2026-10-14 对抗性审查 P0-1):
227
+ // 出口必须指向**常驻**来源,不能指向 `mcp_manager_list`:
201
228
  // 那条工具在出厂默认里就是关着的,`listHint()` 在它不可见时返回空串,于是猜错名字时的
202
229
  // 报错退化成「没有这台服务器:<你猜的>」—— 一个字都不告诉它还能去哪看。
203
230
  // 指向模型自己的工具表(`mcp__<server>__<tool>` 就在它的 schema 里)与常驻注入段,
@@ -205,13 +232,13 @@ export function buildMcpTools(deps) {
205
232
  server: { type: 'string', required: true, description: 'Server name — the one in your own `mcp__<server>__<tool>` names.' },
206
233
  action: { type: 'string', required: true, enum: ['on', 'off', 'restart', 'stop'], description: 'on = enable, off = disable, restart = reconnect and re-sync tools, stop = disable and disconnect anything still using it.' },
207
234
  level: { type: 'string', description: 'project or global — only to disambiguate same-name servers.' },
208
- // 支持数组(2026-10-21 审查 P2-3):关 8 个工具原本要 8 次调用,每次都带着整份工具表
235
+ // 支持数组:关 8 个工具原本要 8 次调用,每次都带着整份工具表
209
236
  // 重新推理一遍 —— 那是这份工具集里最贵的开销,而工具描述本身只占百分之几。
210
237
  tool: { type: 'array', items: { type: 'string' }, description: 'Tool name(s) on that server (no mcp__ prefix) — one or several. Only for on/off.' },
211
- // 决策 10(2026-10-19):默认只改**这个对话**,别的对话不受影响。写全局要显式说明。
212
- // 0.21.2:开启一台机器级关着的服务器时,那一步在全局发生(连接是进程级的)—— 租约
238
+ // 默认只改**这个对话**,别的对话不受影响。写全局要显式说明。
239
+ // 开启一台机器级关着的服务器时,那一步在全局发生(连接是进程级的)—— 租约
213
240
  // 这个词一句带过就够,别的对话看不到它。
214
- scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('a server it turns on runs as a lease, invisible outside that scope (isolation on only). global = every conversation (off keeps leased connections running, stop cuts them). restart / stop are always global.') },
241
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('turning one on here starts it for this scope only (other scopes cannot see it). global = every conversation (off leaves it running while any conversation still uses it; stop cuts it). restart / stop are always global.') },
215
242
  },
216
243
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
217
244
  async execute(args, exec) {
@@ -228,7 +255,7 @@ export function buildMcpTools(deps) {
228
255
  if (tools.length > 0 && (action === 'restart' || action === 'stop')) {
229
256
  throw new Error('restart and stop are whole-server actions (' + (action === 'stop' ? 'stopping cuts off every conversation using it' : 'off, wait for it to drop, then back on at its previous state') + '); a single tool cannot be ' + action + 'ped');
230
257
  }
231
- // 决策 10:默认写**本会话**(别的对话不受影响),`scope: "global"` 才改补丁。
258
+ // 默认写**本会话**(别的对话不受影响),`scope: "global"` 才改补丁。
232
259
  // 两条边界决定了这里的分支:
233
260
  // · restart 是进程级动作(要真停一次再起),没有会话版本 —— 永远走全局;
234
261
  // · 会话层写不碰补丁、不进场景档案,所以不需要冻结守卫与 syncSwitchToScene
@@ -244,7 +271,7 @@ export function buildMcpTools(deps) {
244
271
  // on|off 会写补丁(`mcpm-set-enabled` / `mcpm-tool-enabled` 在登记表里是 frozen),
245
272
  // 所以过场景冻结守卫;restart 不过 —— 它是锁定期间唯一的恢复入口(见文件头)。
246
273
  // 会话层写入(`sessionOnly`)也不被场景锁挡住:它写的是侧车,与全局状态无关
247
- // (决策 11,与面板的 `scopeWriteLocked()` 同口径)。那个"租约跑起来"的例外
274
+ // (与面板的 `scopeWriteLocked()` 同口径)。那个"租约跑起来"的例外
248
275
  // 同样不受场景锁管:它是进入本会话的前置条件,不是一次独立的全局配置改动。
249
276
  if (action !== 'restart' && !sessionOnly) {
250
277
  const blocked = await deps.lockedSceneGuard();
@@ -262,7 +289,7 @@ export function buildMcpTools(deps) {
262
289
  if (setter === undefined)
263
290
  throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change the config for every conversation');
264
291
  // 开启一台全局关着的服务器时,op 侧把它作为本会话的租约跑起来(连接是进程级的,
265
- // 没有会话版本)—— 用户裁定「仍按租约运行」。那一步的影响由回执里的 `warnings`
292
+ // 没有会话版本)—— 用户要求「仍按租约运行」。那一步的影响由回执里的 `warnings`
266
293
  // 如实带出来(哪些临时跑起来了),这里不重写一份判定。
267
294
  const one = async (domain, key) => {
268
295
  const r = await setter(exec && exec.agent, domain, key, enabled);
@@ -272,13 +299,13 @@ export function buildMcpTools(deps) {
272
299
  };
273
300
  const globalNote = ' Pass scope="global" to change it for every conversation.';
274
301
  // 回执必须说清写的是哪一层:用户看到「已停用」而全局其实没变时,才不会以为别的对话也变了。
275
- // 措辞用 `scopeOnlyNote()`(不再写死「本对话」,见 2026-10-21 审查 P0-1)。
302
+ // 措辞用 `scopeOnlyNote()`(不再写死「本对话」)。
276
303
  if (tools.length === 0) {
277
304
  const r = await one('mcp', String(row.serverName));
278
305
  const warnings = r.warnings !== undefined && r.warnings.length > 0 ? '\n' + r.warnings.join('\n') : '';
279
- return 'OK: ' + String(row.serverName) + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote() +
306
+ return 'OK: ' + String(row.serverName) + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
280
307
  (r.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') + warnings +
281
- (warnings === '' ? '\nThe global setting is unchanged; conversations outside this scope keep theirs.' : '') + globalNote;
308
+ (warnings === '' ? '\n' + globalUnchangedNote(deps) : '') + globalNote;
282
309
  }
283
310
  let cleared = 0;
284
311
  const warningsAll = [];
@@ -293,9 +320,9 @@ export function buildMcpTools(deps) {
293
320
  ? 'tool ' + tools[0] + ' on ' + String(row.serverName)
294
321
  : tools.length + ' tools on ' + String(row.serverName) + ' (' + tools.join(', ') + ')';
295
322
  const warnings = warningsAll.length > 0 ? '\n' + warningsAll.join('\n') : '';
296
- return 'OK: ' + what + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote() +
323
+ return 'OK: ' + what + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
297
324
  (cleared === tools.length ? ' (that matches what this scope would see anyway, so the overrides were removed)' : '') + warnings +
298
- (warnings === '' ? '\nThe global setting is unchanged; conversations outside this scope keep theirs.' : '') + globalNote;
325
+ (warnings === '' ? '\n' + globalUnchangedNote(deps) : '') + globalNote;
299
326
  }
300
327
  // 走到这里说明这次是**全局**动作:显式 scope="global"、restart / stop(它们没有
301
328
  // 会话版本),或者隔离被关掉了(全局粒度)。默认值是 session,所以模型很可能以为
@@ -333,7 +360,7 @@ export function buildMcpTools(deps) {
333
360
  throw new Error((r && r.error) || 'restart failed');
334
361
  return 'OK: ' + String(row.serverName) + ' (' + row.level + ') restarted' + scopeIgnored;
335
362
  }
336
- // 全局开关 = **意图**(0.21.2):off 不再立刻停 —— 还在用它的会话会按租约继续跑,
363
+ // 全局开关 = **意图**:off 不再立刻停 —— 还在用它的会话会按租约继续跑
337
364
  // 只有 stop(blocked)会连它们一起切断。直接写补丁会让"谁也看不到"与"连接停不停"
338
365
  // 变成同一件事,那正是会话级开启串到新会话里的根源。
339
366
  if (deps.scopeIntentSet) {
@@ -374,12 +401,12 @@ export function buildMcpTools(deps) {
374
401
  headers: { type: 'string', description: 'Extra headers, key=value per line (streamable-http). Omitting it is what preserves the real secrets.' },
375
402
  env: { type: 'string', description: 'Extra env vars, key=value per line (stdio).' },
376
403
  level: { type: 'string', description: 'project or global (project when creating); only needed for same-name servers.' },
377
- // 名字与注入段对齐(2026-10-14 对抗性审查 P1-2):注入段与工具输出都写 `user-hint`
404
+ // 名字与注入段对齐:注入段与工具输出都写 `user-hint`
378
405
  // (对应注入行里那句 `user hint:`),参数名跟着叫 `hint`,一份数据三个面一个词。
379
406
  // 「写什么」那半句已经由注入框架的 `how` 行逐字说过("选服务器之前先看一眼"),
380
- // 这里只留参数独有的信息:长度上限与截断行为(2026-10-14 审查 P2-4)。
407
+ // 这里只留参数独有的信息:长度上限与截断行为。
381
408
  hint: { type: 'string', description: "Short hint for later (≤300 chars; longer is stored whole but truncated in listings). '' clears the existing hint." },
382
- // 0.21.2:MCP 服务器是**机器级**配置(cordis 补丁),没有「本会话的一份」。这个参数只为一件事:
409
+ // MCP 服务器是**机器级**配置(cordis 补丁),没有「本会话的一份」。这个参数只为一件事:
383
410
  // 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
384
411
  scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('the server config is machine-wide', 'hide a server here with mcp_manager_switch') },
385
412
  },
@@ -393,7 +420,7 @@ export function buildMcpTools(deps) {
393
420
  if (!server)
394
421
  throw new Error('missing argument: server (the server name)');
395
422
  const levelArg = args && args.level !== undefined ? String(args.level) : undefined;
396
- // `hint` 的三态(2026-10-15 修 P1-5):省略 = 保持;`''` = **清空**;非空 = 设置。
423
+ // `hint` 的三态:省略 = 保持;`''` = **清空**;非空 = 设置。
397
424
  // 此前用 `hintText.trim() !== ''` 判"要不要写备注",把"清空"与"省略"混成一件事 ——
398
425
  // 模型传 `hint: ""` 想清掉已有备注时收到「没有要改的东西」,而 op 侧 `mcpm-note`
399
426
  // 本来就支持空串清空(`manager.ts:431`)。判据改成"参数给没给",不是"值空不空"。
@@ -432,14 +459,14 @@ export function buildMcpTools(deps) {
432
459
  if (!r || r.ok === false)
433
460
  throw new Error((r && r.error) || 'failed to add the server');
434
461
  // 备注单独走 `mcpm-note`(`mcpm-add` 不认这个字段)。失败**不回滚**主写入:
435
- // 服务器已经建好了,"备注没写上"是 warning,不是失败(与 0.13.0 界面同规格)。
462
+ // 服务器已经建好了,"备注没写上"是 warning,不是失败(与界面同规格)。
436
463
  let warn = '';
437
464
  if (hintGiven && !clearsNote) {
438
465
  const n = await deps.mcpmNote({ id: String(r.row.id), note: hintText });
439
466
  if (!n || n.ok === false)
440
467
  warn = '\nWARN: the server was created, but the hint was not written (' + ((n && n.error) || 'unknown reason') + ')';
441
468
  }
442
- // 会话层(0.21.2):服务器是**机器级**配置(cordis 补丁),本会话只能把它藏起来。
469
+ // 会话层:服务器是**机器级**配置(cordis 补丁),本会话只能把它藏起来。
443
470
  return 'OK: created ' + r.row.id + ' at ' + r.row.level + warn +
444
471
  globalActionNote(deps, exec && exec.agent, 'mcp', 'MCP');
445
472
  }
@@ -523,7 +550,7 @@ export function buildMcpTools(deps) {
523
550
  const r = await deps.mcpmEdit(payload);
524
551
  if (!r || r.ok === false)
525
552
  throw new Error((r && r.error) || 'failed to update the server');
526
- // `hint` 进 `changed` 必须**等写成功之后**(2026-10-15 修 P1-6):此前按意图先算进去,
553
+ // `hint` 进 `changed` 必须**等写成功之后**:此前按意图先算进去,
527
554
  // mcpmNote 失败时回执一边说"改了 hint"、一边 WARN"备注没写进去",模型读不出到底改没改。
528
555
  const changed = touched.concat(levelChanged ? ['level'] : []);
529
556
  let warn = '';