dsh-plugin-tool-management 0.21.2 → 0.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/README.md +3 -5
  3. package/README_EN.md +3 -3
  4. package/docs/{update.md → UPDATE.md} +35 -33
  5. package/lib/approval-policy.js +2 -2
  6. package/lib/audit-log.js +1 -1
  7. package/lib/boot/reconcile.js +3 -3
  8. package/lib/client.js +469 -171
  9. package/lib/compat/capability-specs.js +13 -17
  10. package/lib/compat/host-contracts.js +2 -0
  11. package/lib/compat/host-probe.js +35 -38
  12. package/lib/compat/host-roots.js +86 -15
  13. package/lib/compat/preset-reach.js +75 -102
  14. package/lib/compat/probe.js +68 -117
  15. package/lib/compat/runtime-notes.js +1 -1
  16. package/lib/context-inject-contract.js +6 -5
  17. package/lib/context-inject-frame.js +113 -53
  18. package/lib/context-inject-select.js +13 -14
  19. package/lib/context-inject-surface.js +5 -3
  20. package/lib/context-inject.js +58 -44
  21. package/lib/desktop-cookie-prune.js +95 -0
  22. package/lib/diagnostics.js +3 -1
  23. package/lib/exports/transcript.js +4 -4
  24. package/lib/host-names.js +6 -6
  25. package/lib/http-api.js +35 -26
  26. package/lib/http-fence.js +6 -6
  27. package/lib/hub.js +12 -13
  28. package/lib/imports/parsers.js +25 -21
  29. package/lib/imports/upload.js +5 -1
  30. package/lib/index.js +274 -243
  31. package/lib/mcp/disabled-tools.js +1 -0
  32. package/lib/mcp/loader-token.js +4 -4
  33. package/lib/mcp/manager.js +93 -114
  34. package/lib/mcp/override-blocks.js +1 -1
  35. package/lib/mcp/patch-yaml.js +42 -31
  36. package/lib/mcp/restart-marker.js +1 -1
  37. package/lib/mcp/secret-guard.js +6 -6
  38. package/lib/mcp/state-section.js +110 -69
  39. package/lib/mcp/tool-visibility.js +21 -22
  40. package/lib/memories/archive-engine.js +29 -29
  41. package/lib/memories/archive.js +23 -3
  42. package/lib/memories/constants.js +40 -127
  43. package/lib/memories/discovery.js +11 -2
  44. package/lib/memories/index-io.js +26 -20
  45. package/lib/memories/projection.js +18 -19
  46. package/lib/memories/prompt-layer.js +3 -2
  47. package/lib/memories/service.js +41 -38
  48. package/lib/memories/snapshot.js +37 -29
  49. package/lib/op-registry.js +38 -18
  50. package/lib/ops/candidates.js +3 -2
  51. package/lib/ops/compat.js +10 -9
  52. package/lib/ops/ctx.js +1 -1
  53. package/lib/ops/memory.js +18 -18
  54. package/lib/ops/prompts.js +8 -8
  55. package/lib/ops/quick-prompts.js +1 -0
  56. package/lib/ops/scene-records.js +23 -24
  57. package/lib/ops/scene-sync.js +8 -7
  58. package/lib/ops/scope.js +144 -40
  59. package/lib/ops/sessions.js +10 -9
  60. package/lib/ops/snapshot.js +10 -9
  61. package/lib/ops/state-doctor.js +6 -6
  62. package/lib/ops/trash-retention.js +2 -1
  63. package/lib/ops/trash.js +6 -6
  64. package/lib/prompts/preset-id.js +1 -1
  65. package/lib/prompts/project-instructions.js +3 -3
  66. package/lib/prompts/quick-service.js +1 -0
  67. package/lib/prompts/service.js +13 -12
  68. package/lib/request-gate.js +26 -25
  69. package/lib/scene-linkage.js +6 -5
  70. package/lib/scene-prompt-sync.js +10 -9
  71. package/lib/scene-settings.js +1 -0
  72. package/lib/scenes/candidates.js +9 -10
  73. package/lib/scope/intent-store.js +1 -0
  74. package/lib/scope/intent.js +16 -15
  75. package/lib/scope/resolve.js +6 -6
  76. package/lib/scope/scope-overrides.js +17 -17
  77. package/lib/scope/store.js +1 -0
  78. package/lib/sessions/archive-schemas.js +9 -0
  79. package/lib/sessions/bridge.js +42 -56
  80. package/lib/sessions/history.js +6 -7
  81. package/lib/sessions/workspace.js +21 -23
  82. package/lib/settings-sidecars.js +1 -0
  83. package/lib/sidebar-settings.js +1 -0
  84. package/lib/skills/catalog.js +9 -10
  85. package/lib/skills/core-util.js +5 -0
  86. package/lib/skills/core.js +35 -22
  87. package/lib/skills/frontmatter.js +26 -14
  88. package/lib/skills/homes.js +2 -0
  89. package/lib/skills/import-pipeline.js +8 -1
  90. package/lib/skills/manager-state.js +30 -6
  91. package/lib/skills/official.js +14 -11
  92. package/lib/skills/readonly-discovery.js +1 -0
  93. package/lib/skills/service.js +19 -18
  94. package/lib/skills/skill-roots.js +25 -7
  95. package/lib/skills/skill-trash.js +14 -3
  96. package/lib/skills/system-trash.js +3 -1
  97. package/lib/skills/upload-pipeline.js +19 -3
  98. package/lib/slash-settings.js +1 -0
  99. package/lib/stale-write.js +9 -1
  100. package/lib/subagents/catalog.js +5 -5
  101. package/lib/subagents/child-preset.js +7 -10
  102. package/lib/subagents/persona-parse.js +9 -8
  103. package/lib/subagents/persona-write.js +1 -1
  104. package/lib/subagents/run-provider.js +13 -15
  105. package/lib/subagents/service.js +13 -12
  106. package/lib/subagents/tool-filter.js +1 -1
  107. package/lib/subagents/tools.js +41 -39
  108. package/lib/token-config.js +9 -9
  109. package/lib/tool-table-switch.js +3 -2
  110. package/lib/tools/deps.js +33 -13
  111. package/lib/tools/mcp.js +63 -36
  112. package/lib/tools/memory.js +51 -36
  113. package/lib/tools/prompt.js +32 -20
  114. package/lib/tools/remove.js +12 -11
  115. package/lib/tools/scene.js +39 -36
  116. package/lib/tools/skills.js +44 -45
  117. package/lib/tools/subagent.js +21 -22
  118. package/lib/tools/table.js +21 -20
  119. package/lib/trash-id.js +3 -2
  120. package/lib/trash-retention.js +4 -5
  121. package/lib/update-check.js +5 -1
  122. package/package.json +4 -3
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
@@ -238,13 +265,13 @@ export function buildMcpTools(deps) {
238
265
  // 调用方是否**以为**自己在改会话层(省略 scope 也算)。全局粒度下这个以为会落空,
239
266
  // 回执必须点出来 —— 否则 agent 会把"机器级改动"转述成"只影响这个对话"。
240
267
  const askedForSession = (args && args.scope) !== 'global';
241
- // restart 与 stop 都是机器级动作(重启要真停一次;彻底停止定义上就压过所有会话),
268
+ // restart 与 stop 都是机器级动作(重启要真停一次;blocked 定义上就压过所有会话),
242
269
  // 没有会话版本 —— 与 restart 同一条,忽略 scope 并如实点出来。
243
270
  const sessionOnly = scope !== 'global' && action !== 'restart' && action !== 'stop';
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 = '';
@@ -1,15 +1,14 @@
1
- // 记忆(rules)域的 model 工具(2026-09-19 从 index.ts 的注册区抽出;2026-09-23 改名合并、
2
- // 同日把场景能力分出去;0.21.2 加 _search):memory_manager_list / _read / _search / _switch / _save。
1
+ // 记忆(rules)域的 model 工具:memory_manager_list / _read / _search / _switch / _save。
3
2
  //
4
- // 为什么族名在 0.14.0 里绕了一圈回到 `memory_manager_`:中途改成 `scene_memory_manager_`
5
- // 是为了跟注入段名(`scene-memory-manager-catalog`)对齐,但那个名字描述的是**域**,
3
+ // 为什么族名是 `memory_manager_` 而不是 `scene_memory_manager_`:后者是为了跟注入段名
4
+ // (`scene-memory-manager-catalog`)对齐才改的,但那个名字描述的是**域**,
6
5
  // 而这个族操作的全是记忆。加场景能力时这个错配就现形了 —— 场景是另一个对象(容器,
7
6
  // 进入时切换 mcp / 技能 / 人设),硬塞进 `save` 会让 `description` 变成双义参数(给
8
7
  // `memory` 时是记忆描述、给 `scene` 时是场景描述),门禁也得按参数分叉(记忆写入有开关
9
8
  // 可放行,场景写入是改运行时环境、不该有那条路)。所以拆成两族:这里管记忆内容,
10
9
  // `scene_manager_*`(tools/scene.ts)管场景本身。
11
10
  //
12
- // 场景清单也不挂在这条 list 的尾巴上(同日第四轮裁定:「记忆就管记忆,场景就管场景」)——
11
+ // 场景清单也不挂在这条 list 的尾巴上(「记忆就管记忆,场景就管场景」)——
13
12
  // 它在 `scene_manager_list`,理由记在 tools/scene.ts 头部,别当"少写了一段"再加回来。
14
13
  //
15
14
  // 为什么 write + update 并成 save:两者的判定(同名 = 改、无同名 = 建)本来就只有
@@ -17,18 +16,20 @@
17
16
  // 模型必须自己先查一次再决定调哪条,而它手里的清单可能已经过期。合并后由工具侧兜住。
18
17
  //
19
18
  // 活动场景的记忆正文会自动注入上下文(无需调用工具读取);这里的工具用于查询/编辑规则
20
- // 本身。memory_manager_save 受 tools/pre-execute 审批门禁(D2)。
19
+ // 本身。memory_manager_save 受 tools/pre-execute 审批门禁。
21
20
  // 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
22
- import { effectiveScope, globalActionNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
21
+ import { GLOBAL_SCENE, SHARED_GROUP } from '../memories/constants.js';
22
+ import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
23
+ /** 注册记忆域的 model 工具(列表 / 读取 / 检索 / 切换 / 保存)。 */
23
24
  export function buildMemoryTools(deps) {
24
25
  const { defineTool, register } = deps;
25
26
  register(defineTool({
26
27
  name: 'memory_manager_list',
27
28
  // 末尾**不点名** `scene_manager_list`:场景一族在出厂默认里就是关着的,指向一条模型没有的
28
- // 工具只会让它去猜名字(用户 2026-09-23 把默认名单扩到十五条时去掉的这句)。
29
+ // 工具只会让它去猜名字(用户 把默认名单扩到十五条时去掉的这句)。
29
30
  description: 'List memories (id, scene, enabled, form flat|bundle, description) plus the scene the injection follows. What is injected each turn is in the "Current memories" reminder; use this for ids and for entries that are off. Pass `scene` to filter; all=true lists everything.',
30
31
  parameters: {
31
- // 参数名与其余五个域同词(2026-10-14 对抗性审查 P1-3):同一个概念在工具面只该有一个名字,
32
+ // 参数名与其余五个域同词:同一个概念在工具面只该有一个名字
32
33
  // 而 `scene` 是它在 `scene_manager_*`、`<scene>/<name>` 与注入段标题里的叫法。
33
34
  // op 的内部契约字段仍是 `group`(`rules-list` 与界面侧调用方都读它),所以 execute 里
34
35
  // 显式映射一次 —— 改 op 的字段名要动界面,那不是这一条能顺手做的事。
@@ -42,7 +43,7 @@ export function buildMemoryTools(deps) {
42
43
  const opArgs = {};
43
44
  if (args && args.scene !== undefined)
44
45
  opArgs.group = args.scene;
45
- // 会话层(0.21.2,计划 §8.2「memory_manager_list 只列本会话场景」):带上 sessionId,
46
+ // 会话层(`memory_manager_list` 只列本会话场景):带上 sessionId,
46
47
  // op 就按本会话钉住的场景与逐条开关投影 —— 「会注入」这一栏与模型真实看到的一致。
47
48
  // 取不到会话 = 不给,op 退回全局口径(不报错)。
48
49
  const scoped = sessionScopeOf(deps, exec && exec.agent);
@@ -53,8 +54,16 @@ export function buildMemoryTools(deps) {
53
54
  throw new Error((r && r.error) || 'failed to read memories');
54
55
  // 「会注入」的判定与记忆段同源(renderSceneMemory):global 场景恒常注入,其余场景要
55
56
  // 在 index.active 里,再叠加单条 enabled 与同名 bundle 的 shadowed。默认只列这些,
56
- // 全列一次会把没启用的条目也算进上下文(用户裁定 2026-09-16,与技能列表同口径)。
57
- const sceneOn = (group) => group === 'global' ||
57
+ // 全列一次会把没启用的条目也算进上下文(与技能列表同口径)。
58
+ //
59
+ // **两个**保留桶恒常注入,不是一个:`global`(界面「全局」)之外还有 `_shared`
60
+ // (公共基线)。注入侧 `resolveActiveScenes` 无条件把两者都放进 active
61
+ // (见 memories/projection.ts),这里只认 `global` 就会把 `_shared` 标成
62
+ // "scene off" 并默认藏起来 —— 而它每轮都在上下文里。模型照这份名单回答
63
+ // 「没有这条记忆」,实际它正躺在自己眼前。`activeScene` 永远报不到 `_shared`
64
+ // (`enabledSceneOf` 只回非保留场景),所以只能在这一层显式认。
65
+ const alwaysInjects = (group) => group === GLOBAL_SCENE || group === SHARED_GROUP;
66
+ const sceneOn = (group) => alwaysInjects(group) ||
58
67
  (group !== '' && (r.activeMode === 'all' || String(r.activeScene || '') === group));
59
68
  const stateOf = (x) => {
60
69
  if (x.shadowed === true)
@@ -68,7 +77,7 @@ export function buildMemoryTools(deps) {
68
77
  const rows = (r.rules || []).map((x) => ({ x, ...stateOf(x) }));
69
78
  const shown = showAll ? rows : rows.filter((row) => row.injects);
70
79
  const lines = shown.map(({ x, label }) => ('- ' + x.id + ' [' + (x.group || 'no scene') + '] ' + label +
71
- // 形态与附件(2026-10-15):此前不报,模型分不清哪条是 bundle、更不知道它带了几个附件
80
+ // 形态与附件:此前不报,模型分不清哪条是 bundle、更不知道它带了几个附件
72
81
  // (`rules-list` 早就把 `form` 与 bundle 的附件摘要给了出来,只是这里没渲染)。
73
82
  (x.form === 'bundle'
74
83
  ? ' · bundle' + (x.attach && x.attach.count ? ' (' + x.attach.count + ' attachment(s))' : '')
@@ -76,22 +85,26 @@ export function buildMemoryTools(deps) {
76
85
  (x.description ? ' — ' + x.description : '')));
77
86
  // 注入按哪个场景走 —— 上面那句「场景未启用」只有配上它才可解读:少了这一行,
78
87
  // 模型看到一片"未启用"会以为是条目自己的问题。(场景本身的清单在 `scene_manager_list`,
79
- // 2026-09-23 拆过去了;这里只留"记忆按哪一集注入",因为那是记忆域自己的现状。)
80
88
  const scope = r.activeMode === 'all'
81
89
  ? 'every scene (historical default, not narrowed)'
82
90
  : (r.activeScene ? '"' + String(r.activeScene) + '"' : 'no scene is on');
83
- // 会话层(0.21.2):本会话钉了场景 / 改了个别开关时,上面那行报的是**本会话**的投影,
91
+ // 会话层:本会话钉了场景 / 改了个别开关时,上面那行报的是**本会话**的投影
84
92
  // 与全局可能不同。不说清的话,模型会拿这份名单去回答"全局现在是什么" —— 那是错的答案。
93
+ // 粒度决定这句话的主语:工作区粒度下那一格是同工作区共享的,"本对话"是假话。
94
+ const viewNoun = deps.scopeMode?.() === 'workspace' ? 'this workspace' : 'this conversation';
85
95
  const sessionNote = scoped === null || scoped.scope === undefined
86
96
  ? ''
87
- : '\nthis is the view here (this conversation, or its whole workspace under per-workspace isolation)' +
97
+ : '\nthis is ' + viewNoun + "'s view" +
88
98
  (scoped.scope.scene !== undefined ? ' — scene pinned to "' + scoped.scope.scene + '"; the machine-wide scene may differ' : '') +
89
99
  (scoped.scope.memory !== undefined ? '; ' + Object.keys(scoped.scope.memory).length + ' switch(es) applied here' : '');
100
+ // `_shared` 只在真有这类条目时点名:没有就不付这几个字,而有了不说的话,
101
+ // 上面那句「只列会注入的」会让人以为名单里全是 global + 当前场景。
102
+ const sharedHere = rows.some(({ x }) => String(x.group || '') === SHARED_GROUP);
90
103
  const header = 'memories: ' + (showAll
91
104
  ? rows.length + ' total'
92
105
  : shown.length + ' injecting / ' + rows.length + ' total' +
93
106
  (shown.length === rows.length ? '' : ' (pass all=true for all)')) +
94
- '\ninjects from: ' + scope + ' + global (global always injects)' + sessionNote + '\n';
107
+ '\ninjects from: ' + scope + ' + global' + (sharedHere ? ' + _shared' : '') + ' (always on)' + sessionNote + '\n';
95
108
  // 注入边界:压制型预设(persona complete / 关闭运行时上下文)下本插件默认不注入,
96
109
  // 此时列出的记忆**不在**模型上下文里。必须说出来,否则模型会假设自己已经看到正文。
97
110
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
@@ -100,7 +113,7 @@ export function buildMemoryTools(deps) {
100
113
  }));
101
114
  register(defineTool({
102
115
  name: 'memory_manager_read',
103
- // "dropped by the byte budget" 改成"left out of it"(2026-10-15 注入文本审查):byte budget
116
+ // "dropped by the byte budget" 改成"left out of it":byte budget
104
117
  // 是本插件内部术语,模型没有这个概念 —— 它只知道"这条在不在我上下文里"。说内部机制
105
118
  // 等于让它去猜一个它观测不到的量。
106
119
  description: 'Read one memory\'s full body, its form (flat|bundle) and its attachment names. Only for ones not already in your context (disabled, in an inactive scene, or left out). Attachment contents are not returned — use your file tools.',
@@ -114,7 +127,7 @@ export function buildMemoryTools(deps) {
114
127
  if (!r || r.ok === false)
115
128
  throw new Error((r && r.error) || 'failed to read memories');
116
129
  const rule = r.rule || {};
117
- // 形态与附件名(2026-10-15):op 一直把 `attachments` 给了出来,这里此前**整个丢掉**,
130
+ // 形态与附件名:op 一直把 `attachments` 给了出来,这里此前**整个丢掉**,
118
131
  // 于是模型连"这条记忆是 bundle、带了 3 个附件"都看不到。只给名字不给内容 ——
119
132
  // 附件可能是图片或大 md,全文塞回来会吃光这一轮的上下文(与注入段附件行同口径)。
120
133
  const attach = Array.isArray(rule.attachments) ? rule.attachments : [];
@@ -122,7 +135,7 @@ export function buildMemoryTools(deps) {
122
135
  const attLine = attach.length
123
136
  ? '\nattachments (' + attach.length + '): ' + attach.map((a) => String((a && a.name) || a)).join(', ')
124
137
  : '';
125
- // 会话层(0.21.2):这条记忆在本会话是关着的(或不在本会话钉住的场景里)时,读得到
138
+ // 会话层:这条记忆在本会话是关着的(或不在本会话钉住的场景里)时,读得到
126
139
  // 正文 ≠ 它会进上下文。不说清的话,模型会以为自己已经掌握了它、下一轮却看不到。
127
140
  const scoped = sessionScopeOf(deps, exec && exec.agent);
128
141
  const over = scoped?.scope?.memory?.[String(rule.id)];
@@ -169,11 +182,11 @@ export function buildMemoryTools(deps) {
169
182
  }));
170
183
  register(defineTool({
171
184
  name: 'memory_manager_switch',
172
- // 为什么叫 `_switch` 而不是 `_set_enabled`(2026-09-23 用户裁定):六个域里"拨一个开关"
185
+ // 为什么叫 `_switch` 而不是 `_set_enabled`:六个域里"拨一个开关"
173
186
  // 是同一件事,名字该同形 —— `mcp_manager_switch` 早就是这个名字,`_set_enabled` 只剩
174
187
  // 记忆 / 技能 / 人设三族在叫。**参数保留 `enabled` 布尔**:这里没有 `restart` 那第三个
175
188
  // 动词,`action: 'on' | 'off'` 只会在 `true`/`false` 之上多一层映射、多付一段 schema。
176
- // 旧名不注册别名(同 0.14.0 的口径:注册就进工具表、就要付 token);用户的旧设置由
189
+ // 旧名不注册别名(同一口径:注册就进工具表、就要付 token);用户的旧设置由
177
190
  // `tools/table.ts` 的 `LEGACY_TOOL_NAME_MAP` 翻译。
178
191
  //
179
192
  // 为什么单独一个工具:注入实况里「这个域注入了几次 / 模型调了几次」都看得到,但模型此前
@@ -182,14 +195,14 @@ export function buildMemoryTools(deps) {
182
195
  // 三个写侧工具共用一句 consent(`Only when the user asks or approves.` / `Only on the
183
196
  // user's instruction.`):这些动的都是"以后每一轮都会带上"的东西,模型不该顺手做。
184
197
  // 描述同时按"省 token"重写了一遍 —— 这几段文字每次请求都要发出去,废话是常驻成本。
185
- // 后半句"freeing the byte budget"删掉(2026-10-15 注入文本审查):byte budget 是本插件
198
+ // 后半句"freeing the byte budget"删掉:byte budget 是本插件
186
199
  // 内部术语,模型据此做不了任何判断 —— "不再被注入"已经是它需要的全部因果。
187
200
  description: 'Enable or disable one memory. Disabled memories stop being injected. Reversible. Only when the user asks or approves.',
188
201
  parameters: {
189
202
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name>.' },
190
203
  enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable.' },
191
- // 决策 10(2026-10-19):默认只改**这个对话**。写全局要显式说明。
192
- scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('global = every conversation (the memory index).') },
204
+ // 默认只改**这个对话**。写全局要显式说明。
205
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('global = every conversation.') },
193
206
  },
194
207
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
195
208
  async execute(args, exec) {
@@ -198,7 +211,7 @@ export function buildMemoryTools(deps) {
198
211
  // 中文 op 错;这里先挡一句说清"这条工具要什么"。
199
212
  if (typeof (args && args.enabled) !== 'boolean')
200
213
  throw new Error('missing argument: enabled must be true or false');
201
- // 场景锁冻结的是**全局**写入(决策 11):会话覆盖写的是侧车,与锁无关 ——
214
+ // 场景锁冻结的是**全局**写入:会话覆盖写的是侧车,与锁无关 ——
202
215
  // 与面板的 `scopeWriteLocked()` 同一口径。只有全局那条路才过守卫。
203
216
  // 全局粒度下 `effectiveScope` 一律返回 global:那一档没有会话层,写的就是索引本身。
204
217
  const scope = effectiveScope(deps, args);
@@ -208,7 +221,7 @@ export function buildMemoryTools(deps) {
208
221
  if (blocked)
209
222
  throw new Error(blocked);
210
223
  }
211
- // 决策 10:默认写**本会话**(别的对话不受影响),`scope: "global"` 才改索引。
224
+ // 默认写**本会话**(别的对话不受影响),`scope: "global"` 才改索引。
212
225
  // 会话层只改"注入不注入",不碰索引里那条记录 —— 所以不需要场景档案同步。
213
226
  if (sessionOnly) {
214
227
  if (!deps.sessionScopeSet)
@@ -216,9 +229,9 @@ export function buildMemoryTools(deps) {
216
229
  const sc = await deps.sessionScopeSet(exec && exec.agent, 'memory', memory, args.enabled === true);
217
230
  if (!sc || sc.ok === false)
218
231
  throw new Error((sc && sc.error) || 'failed to switch this memory here');
219
- return 'OK: ' + memory + ' now ' + (args.enabled ? 'enabled' : 'disabled') + scopeOnlyNote() +
220
- (sc.cleared === true ? ' (that matches the global setting, so the per-conversation override was removed)' : '') +
221
- '. The global setting is unchanged; other conversations keep theirs. Pass scope="global" to change it for every conversation.';
232
+ return 'OK: ' + memory + ' now ' + (args.enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
233
+ (sc.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') +
234
+ '. ' + globalUnchangedNote(deps) + ' Pass scope="global" to change it for every conversation.';
222
235
  }
223
236
  const r = await deps.rulesOps['rules-toggle']({ id: memory, enabled: args.enabled });
224
237
  if (!r || r.ok === false)
@@ -244,7 +257,7 @@ export function buildMemoryTools(deps) {
244
257
  }));
245
258
  register(defineTool({
246
259
  name: 'memory_manager_save',
247
- // 「能推导的别记」「先查重」这两句是 0.13.0 加的:记忆是唯一直接吃注入预算的域
260
+ // 「能推导的别记」「先查重」这两句必须有:记忆是唯一直接吃注入预算的域
248
261
  // (场景段 128 KiB),而模型很乐意把「这个项目用 pnpm」记一条 —— 那看一眼 `package.json`
249
262
  // 就知道,记下来却永久占着每一轮请求。合并 write/update 后这两句更要留:upsert 降低了
250
263
  // "再记一条"的摩擦,而摩擦正是这里唯一拦得住它的东西。
@@ -253,7 +266,7 @@ export function buildMemoryTools(deps) {
253
266
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name> — copy it from the list. `global` is the always-on scene.' },
254
267
  description: { type: 'string', description: 'One-sentence description (<=500 chars). Required when creating. Empty string = drop it and re-derive from the body; omit = keep.' },
255
268
  body: { type: 'string', description: 'Markdown body (<=256 KiB). Required when creating. Omit to keep the current body.' },
256
- // 不再承诺「旧文件进回收站」(2026-10-14 对抗性审查 P0-3):bundle 记忆改名走的是
269
+ // 不再承诺「旧文件进回收站」:bundle 记忆改名走的是
257
270
  // 「只重写正文、目录不动」那条路,一个字都不进回收站 —— 对 bundle 说进回收站是假话。
258
271
  // 与上一轮 P1-1 同口径:**只说可逆,不说实现细节**。
259
272
  nextName: { type: 'string', description: 'New memory name (= file name); omit to keep it.' },
@@ -266,7 +279,7 @@ export function buildMemoryTools(deps) {
266
279
  const memory = String((args && args.memory) || '').trim();
267
280
  // 拆成 `<场景>/<名字>`:要求两段都非空。**不做"没有斜杠就落 global"的兜底** —— 那会把
268
281
  // 一次拼错的 id 变成一条"每轮都注入"的全局记忆,而清单上看起来完全正常。
269
- // 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准(§2 规则一)。
282
+ // 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准。
270
283
  const slash = memory.indexOf('/');
271
284
  if (slash <= 0 || slash === memory.length - 1) {
272
285
  throw new Error('memory must be <scene>/<name> (copy that from the listing; the always-on scene is written global/<name>): ' + (memory || '(empty)'));
@@ -338,11 +351,11 @@ export function buildMemoryTools(deps) {
338
351
  const warn = dup.length
339
352
  ? `\nnote: ${dup.length} existing memories have a similar name or description (${dup.join(', ')}) — if it is the same thing, update that one instead of keeping two.`
340
353
  : '';
341
- // 回执必须同时说清**两个**条件(2026-10-15 smoke-test P1-3):新建的记忆在 op 层是
354
+ // 回执必须同时说清**两个**条件:新建的记忆在 op 层是
342
355
  // `enabled: false`(ops/memory.ts 的 rulesCreate),而原先这句只提场景 —— 读起来像
343
356
  // "场景一开它就自动生效",模型据此以为已经生效,实际还差一次开关。与 skill_manager_save
344
357
  // 的 enableHint 同一形状:点名的工具在出厂默认名单里是关着的,关着就改说"用户开启后"。
345
- // 「会不会注入」按**本会话**的投影判(0.21.2):会话钉了别的场景时,这条记忆落进的
358
+ // 「会不会注入」按**本会话**的投影判:会话钉了别的场景时,这条记忆落进的
346
359
  // 那个场景在这个对话里根本没开着 —— 照全局口径回一句"打开就能用"是错的答案。
347
360
  const scoped = sessionScopeOf(deps, exec && exec.agent);
348
361
  const effScene = scoped?.scope?.scene;
@@ -351,7 +364,9 @@ export function buildMemoryTools(deps) {
351
364
  const sceneActive = group === 'global' ||
352
365
  (group !== '' && (activeMode === 'all' || String(activeNow || '') === group));
353
366
  const sceneTail = sceneActive ? '' : ', and turn scene "' + group + '" on';
354
- const enableHint = deps.toolVisible('memory_manager_switch')
367
+ // 判据按 **agent**:工具表是每个作用域一份,本作用域把它关掉(或人设 toolsDeny 砍掉)
368
+ // 之后,点名它就是让模型白跑一趟 —— 与 mcp/skill 的 listHint 同一条。
369
+ const enableHint = deps.toolVisibleFor('memory_manager_switch', exec && exec.agent)
355
370
  ? ' (created disabled — turn it on first with memory_manager_switch' + sceneTail + ')'
356
371
  : ' (created disabled — the user has to turn it on first' + sceneTail + ')';
357
372
  // 会话层:这条记忆写的是**磁盘上的那一份**(所有对话共用),本会话的开关只决定