dsh-plugin-tool-management 0.21.0 → 0.21.2

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 (106) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +47 -10
  3. package/README_EN.md +45 -10
  4. package/docs/images/1-EN.png +0 -0
  5. package/docs/images/1.png +0 -0
  6. package/docs/images/2-EN.png +0 -0
  7. package/docs/images/2.png +0 -0
  8. package/docs/images/3-EN.png +0 -0
  9. package/docs/images/3.png +0 -0
  10. package/docs/images/4-EN.png +0 -0
  11. package/docs/images/4.png +0 -0
  12. package/docs/images/5-EN.png +0 -0
  13. package/docs/images/5.png +0 -0
  14. package/docs/images/6-EN.png +0 -0
  15. package/docs/images/6.png +0 -0
  16. package/docs/images/7-EN.png +0 -0
  17. package/docs/images/7.png +0 -0
  18. package/docs/images/8-EN.png +0 -0
  19. package/docs/images/8.png +0 -0
  20. package/docs/images/icon.png +0 -0
  21. package/docs/images/icon.svg +1 -0
  22. package/docs/update.md +37 -35
  23. package/lib/boot/reconcile.js +157 -0
  24. package/lib/client.js +7166 -3084
  25. package/lib/compat/patch-dialect.js +14 -1
  26. package/lib/compat/probe.js +25 -21
  27. package/lib/context-inject-frame.js +62 -40
  28. package/lib/context-inject-select.js +59 -4
  29. package/lib/context-inject-surface.js +49 -3
  30. package/lib/context-inject.js +145 -22
  31. package/lib/diagnostics.js +77 -0
  32. package/lib/http-api.js +39 -23
  33. package/lib/http-fence.js +40 -5
  34. package/lib/imports/unzip.js +48 -0
  35. package/lib/imports/upload.js +8 -36
  36. package/lib/index.js +2933 -169
  37. package/lib/mcp/disabled-tools.js +96 -0
  38. package/lib/mcp/manager.js +559 -128
  39. package/lib/mcp/restart-marker.js +110 -0
  40. package/lib/mcp/state-section.js +132 -43
  41. package/lib/mcp/tool-visibility.js +348 -56
  42. package/lib/memories/archive-engine.js +39 -14
  43. package/lib/memories/discovery.js +30 -10
  44. package/lib/memories/index-io.js +217 -18
  45. package/lib/memories/projection.js +20 -3
  46. package/lib/memories/prompt-layer.js +37 -0
  47. package/lib/memories/search.js +86 -0
  48. package/lib/memories/service.js +327 -91
  49. package/lib/memories/snapshot.js +66 -19
  50. package/lib/op-registry.js +49 -4
  51. package/lib/ops/candidates.js +11 -3
  52. package/lib/ops/compat.js +46 -4
  53. package/lib/ops/memory.js +78 -9
  54. package/lib/ops/prompts.js +49 -5
  55. package/lib/ops/quick-prompts.js +24 -2
  56. package/lib/ops/scene-records.js +7 -0
  57. package/lib/ops/scene-sync.js +23 -4
  58. package/lib/ops/scope.js +1093 -0
  59. package/lib/ops/sessions.js +5 -2
  60. package/lib/ops/snapshot.js +55 -20
  61. package/lib/ops/state-doctor.js +39 -4
  62. package/lib/ops/trash.js +12 -1
  63. package/lib/paths.js +50 -3
  64. package/lib/prompts/preset-id.js +4 -0
  65. package/lib/prompts/project-instructions.js +162 -0
  66. package/lib/prompts/quick-service.js +5 -4
  67. package/lib/prompts/service.js +20 -9
  68. package/lib/request-gate.js +6 -4
  69. package/lib/scene-linkage.js +12 -0
  70. package/lib/scene-prompt-sync.js +1 -1
  71. package/lib/scenes/candidates.js +8 -1
  72. package/lib/scope/intent-store.js +105 -0
  73. package/lib/scope/intent.js +376 -0
  74. package/lib/scope/resolve.js +190 -0
  75. package/lib/scope/scope-overrides.js +894 -0
  76. package/lib/scope/store.js +262 -0
  77. package/lib/scope/workspace-key.js +64 -0
  78. package/lib/sessions/history.js +3 -2
  79. package/lib/settings-sidecars.js +82 -19
  80. package/lib/sidebar-settings.js +13 -0
  81. package/lib/skills/catalog.js +206 -33
  82. package/lib/skills/core.js +1 -1
  83. package/lib/skills/frontmatter.js +121 -0
  84. package/lib/skills/service.js +145 -20
  85. package/lib/stale-write.js +74 -0
  86. package/lib/subagents/catalog.js +47 -13
  87. package/lib/subagents/persona-parse.js +26 -5
  88. package/lib/subagents/persona-write.js +11 -7
  89. package/lib/subagents/service.js +3 -2
  90. package/lib/subagents/tools.js +78 -8
  91. package/lib/token-config.js +25 -5
  92. package/lib/tool-table-switch.js +141 -49
  93. package/lib/tools/deps.js +151 -5
  94. package/lib/tools/mcp.js +189 -39
  95. package/lib/tools/memory.js +103 -18
  96. package/lib/tools/prompt.js +61 -9
  97. package/lib/tools/remove.js +46 -21
  98. package/lib/tools/scene.js +120 -26
  99. package/lib/tools/skills.js +191 -30
  100. package/lib/tools/subagent.js +52 -20
  101. package/lib/tools/table.js +48 -11
  102. package/lib/trash-retention.js +3 -2
  103. package/lib/update-check.js +218 -0
  104. package/locale/en.json +6 -0
  105. package/locale/zh.json +6 -0
  106. package/package.json +19 -14
@@ -1,5 +1,5 @@
1
1
  // 记忆(rules)域的 model 工具(2026-09-19 从 index.ts 的注册区抽出;2026-09-23 改名合并、
2
- // 同日把场景能力分出去):memory_manager_list / _read / _switch / _save。
2
+ // 同日把场景能力分出去;0.21.2 加 _search):memory_manager_list / _read / _search / _switch / _save。
3
3
  //
4
4
  // 为什么族名在 0.14.0 里绕了一圈回到 `memory_manager_`:中途改成 `scene_memory_manager_`
5
5
  // 是为了跟注入段名(`scene-memory-manager-catalog`)对齐,但那个名字描述的是**域**,
@@ -19,20 +19,20 @@
19
19
  // 活动场景的记忆正文会自动注入上下文(无需调用工具读取);这里的工具用于查询/编辑规则
20
20
  // 本身。memory_manager_save 受 tools/pre-execute 审批门禁(D2)。
21
21
  // 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
22
- import { text } from './deps.js';
22
+ import { effectiveScope, globalActionNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
23
23
  export function buildMemoryTools(deps) {
24
24
  const { defineTool, register } = deps;
25
25
  register(defineTool({
26
26
  name: 'memory_manager_list',
27
27
  // 末尾**不点名** `scene_manager_list`:场景一族在出厂默认里就是关着的,指向一条模型没有的
28
28
  // 工具只会让它去猜名字(用户 2026-09-23 把默认名单扩到十五条时去掉的这句)。
29
- description: 'List memories (id, scene, enabled, form flat|bundle, description) plus the scene injection currently follows. What is injected each turn is in the "Current memories" reminder; use this for ids and for entries that are off. Pass a `scene` to filter by scene; all=true lists everything.',
29
+ 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
30
  parameters: {
31
31
  // 参数名与其余五个域同词(2026-10-14 对抗性审查 P1-3):同一个概念在工具面只该有一个名字,
32
32
  // 而 `scene` 是它在 `scene_manager_*`、`<scene>/<name>` 与注入段标题里的叫法。
33
33
  // op 的内部契约字段仍是 `group`(`rules-list` 与界面侧调用方都读它),所以 execute 里
34
34
  // 显式映射一次 —— 改 op 的字段名要动界面,那不是这一条能顺手做的事。
35
- scene: { type: 'string', description: 'Optional scene filter.' },
35
+ scene: { type: 'string', description: 'Optional scene filter; `global` is the always-on scene.' },
36
36
  all: { type: 'boolean', description: 'Include memories that are off, in an inactive scene, or shadowed (default false).' },
37
37
  },
38
38
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
@@ -42,6 +42,12 @@ export function buildMemoryTools(deps) {
42
42
  const opArgs = {};
43
43
  if (args && args.scene !== undefined)
44
44
  opArgs.group = args.scene;
45
+ // 会话层(0.21.2,计划 §8.2「memory_manager_list 只列本会话场景」):带上 sessionId,
46
+ // op 就按本会话钉住的场景与逐条开关投影 —— 「会注入」这一栏与模型真实看到的一致。
47
+ // 取不到会话 = 不给,op 退回全局口径(不报错)。
48
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
49
+ if (scoped !== null)
50
+ opArgs.sessionId = scoped.sessionId;
45
51
  const r = await deps.rulesOps['rules-list'](opArgs);
46
52
  if (!r || r.ok === false)
47
53
  throw new Error((r && r.error) || 'failed to read memories');
@@ -74,11 +80,18 @@ export function buildMemoryTools(deps) {
74
80
  const scope = r.activeMode === 'all'
75
81
  ? 'every scene (historical default, not narrowed)'
76
82
  : (r.activeScene ? '"' + String(r.activeScene) + '"' : 'no scene is on');
83
+ // 会话层(0.21.2):本会话钉了场景 / 改了个别开关时,上面那行报的是**本会话**的投影,
84
+ // 与全局可能不同。不说清的话,模型会拿这份名单去回答"全局现在是什么" —— 那是错的答案。
85
+ const sessionNote = scoped === null || scoped.scope === undefined
86
+ ? ''
87
+ : '\nthis is the view here (this conversation, or its whole workspace under per-workspace isolation)' +
88
+ (scoped.scope.scene !== undefined ? ' — scene pinned to "' + scoped.scope.scene + '"; the machine-wide scene may differ' : '') +
89
+ (scoped.scope.memory !== undefined ? '; ' + Object.keys(scoped.scope.memory).length + ' switch(es) applied here' : '');
77
90
  const header = 'memories: ' + (showAll
78
91
  ? rows.length + ' total'
79
92
  : shown.length + ' injecting / ' + rows.length + ' total' +
80
93
  (shown.length === rows.length ? '' : ' (pass all=true for all)')) +
81
- '\ninjects from: ' + scope + ' + global (global always injects)\n';
94
+ '\ninjects from: ' + scope + ' + global (global always injects)' + sessionNote + '\n';
82
95
  // 注入边界:压制型预设(persona complete / 关闭运行时上下文)下本插件默认不注入,
83
96
  // 此时列出的记忆**不在**模型上下文里。必须说出来,否则模型会假设自己已经看到正文。
84
97
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
@@ -90,12 +103,12 @@ export function buildMemoryTools(deps) {
90
103
  // "dropped by the byte budget" 改成"left out of it"(2026-10-15 注入文本审查):byte budget
91
104
  // 是本插件内部术语,模型没有这个概念 —— 它只知道"这条在不在我上下文里"。说内部机制
92
105
  // 等于让它去猜一个它观测不到的量。
93
- description: 'Read the full body of one memory, plus its form (flat|bundle) and the names of its attachments. Only for ones not already in your context (disabled, in an inactive scene, or left out of it). Attachment contents are not returned — read those with your file tools.',
106
+ 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.',
94
107
  parameters: {
95
108
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name>.' },
96
109
  },
97
110
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
98
- async execute(args) {
111
+ async execute(args, exec) {
99
112
  // op 的字段名是 `id`,不改 op:这里显式转换(键名对模型是 `<场景>/<名字>`,对 op 是 `id`)。
100
113
  const r = await deps.rulesOps['rules-read']({ id: String((args && args.memory) || '') });
101
114
  if (!r || r.ok === false)
@@ -109,7 +122,49 @@ export function buildMemoryTools(deps) {
109
122
  const attLine = attach.length
110
123
  ? '\nattachments (' + attach.length + '): ' + attach.map((a) => String((a && a.name) || a)).join(', ')
111
124
  : '';
112
- return '# ' + rule.id + ' (' + form + ')' + attLine + '\n\n' + (rule.body || '');
125
+ // 会话层(0.21.2):这条记忆在本会话是关着的(或不在本会话钉住的场景里)时,读得到
126
+ // 正文 ≠ 它会进上下文。不说清的话,模型会以为自己已经掌握了它、下一轮却看不到。
127
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
128
+ const over = scoped?.scope?.memory?.[String(rule.id)];
129
+ const offHere = over === false
130
+ ? '\n(switched off here only — the body above is not injected here; the global setting is unchanged) '
131
+ : '';
132
+ return '# ' + rule.id + ' (' + form + ')' + attLine + '\n\n' + (rule.body || '') + offHere;
133
+ },
134
+ }));
135
+ register(defineTool({
136
+ name: 'memory_manager_search',
137
+ // 为什么单独一条而不是给 list 加 `query`:list 是"清单"(每条都要占一行输出),
138
+ // 搜索是"找一条"(片段 + 排序)。混在一起时,搜不到就等于清单为空 —— 模型分不清
139
+ // "没有这条记忆"和"这个词没匹配上"。默认在工具表里**关着**(见 tools/table.ts):
140
+ // 它是按需检索,不是每轮都该付 schema 成本的能力。
141
+ description: 'Search memories by words in id, scene, description, tags or body. Returns ids plus a short snippet; read the memory itself for the full body. All words must match (case-insensitive).',
142
+ parameters: {
143
+ query: { type: 'string', required: true, description: 'Words to look for; every word must match somewhere in the memory.' },
144
+ limit: { type: 'number', description: 'Max hits (default 20, max 100).' },
145
+ },
146
+ output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
147
+ async execute(args, exec) {
148
+ const query = String((args && args.query) || '').trim();
149
+ if (query === '')
150
+ throw new Error('missing argument: query');
151
+ const opArgs = { query };
152
+ if (args && args.limit !== undefined)
153
+ opArgs.limit = args.limit;
154
+ // 与 list 同一条会话投影:`enabled` 报的是**这里**的生效值,不是全局。
155
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
156
+ if (scoped !== null)
157
+ opArgs.sessionId = scoped.sessionId;
158
+ const r = await deps.rulesOps['rules-search'](opArgs);
159
+ if (!r || r.ok === false)
160
+ throw new Error((r && r.error) || 'failed to search memories');
161
+ const hits = Array.isArray(r.hits) ? r.hits : [];
162
+ if (!hits.length)
163
+ return 'no memories match "' + query + '"';
164
+ const lines = hits.map((h) => '- ' + h.id + ' [' + (h.scene || 'no scene') + ']' +
165
+ (h.enabled === false ? ' (off here)' : '') +
166
+ (h.snippet ? ' — ' + h.snippet : ''));
167
+ return 'memories matching "' + query + '": ' + hits.length + '\n' + lines.join('\n');
113
168
  },
114
169
  }));
115
170
  register(defineTool({
@@ -132,18 +187,39 @@ export function buildMemoryTools(deps) {
132
187
  description: 'Enable or disable one memory. Disabled memories stop being injected. Reversible. Only when the user asks or approves.',
133
188
  parameters: {
134
189
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name>.' },
135
- enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable; omission is refused.' },
190
+ 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).') },
136
193
  },
137
194
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
138
- async execute(args) {
139
- const blocked = await deps.lockedSceneGuard();
140
- if (blocked)
141
- throw new Error(blocked);
195
+ async execute(args, exec) {
142
196
  const memory = String((args && args.memory) || '');
143
197
  // `enabled` 必须是布尔:`rules-toggle` 缺了它直接拒(ops/memory.ts),但那是给用户看的
144
198
  // 中文 op 错;这里先挡一句说清"这条工具要什么"。
145
199
  if (typeof (args && args.enabled) !== 'boolean')
146
200
  throw new Error('missing argument: enabled must be true or false');
201
+ // 场景锁冻结的是**全局**写入(决策 11):会话覆盖写的是侧车,与锁无关 ——
202
+ // 与面板的 `scopeWriteLocked()` 同一口径。只有全局那条路才过守卫。
203
+ // 全局粒度下 `effectiveScope` 一律返回 global:那一档没有会话层,写的就是索引本身。
204
+ const scope = effectiveScope(deps, args);
205
+ const sessionOnly = scope === 'session';
206
+ if (!sessionOnly) {
207
+ const blocked = await deps.lockedSceneGuard();
208
+ if (blocked)
209
+ throw new Error(blocked);
210
+ }
211
+ // 决策 10:默认写**本会话**(别的对话不受影响),`scope: "global"` 才改索引。
212
+ // 会话层只改"注入不注入",不碰索引里那条记录 —— 所以不需要场景档案同步。
213
+ if (sessionOnly) {
214
+ if (!deps.sessionScopeSet)
215
+ throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change it for every conversation');
216
+ const sc = await deps.sessionScopeSet(exec && exec.agent, 'memory', memory, args.enabled === true);
217
+ if (!sc || sc.ok === false)
218
+ 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.';
222
+ }
147
223
  const r = await deps.rulesOps['rules-toggle']({ id: memory, enabled: args.enabled });
148
224
  if (!r || r.ok === false)
149
225
  throw new Error((r && r.error) || 'failed to switch this memory');
@@ -163,7 +239,7 @@ export function buildMemoryTools(deps) {
163
239
  catch {
164
240
  sceneNote = '';
165
241
  }
166
- return 'OK: memory ' + String(rule.id || memory) + ' ' + (rule.enabled === false ? 'disabled' : 'enabled') + sceneNote;
242
+ return 'OK: memory ' + String(rule.id || memory) + ' ' + (rule.enabled === false ? 'disabled' : 'enabled') + sceneNote + isolationOffNote(deps);
167
243
  },
168
244
  }));
169
245
  register(defineTool({
@@ -172,7 +248,7 @@ export function buildMemoryTools(deps) {
172
248
  // (场景段 128 KiB),而模型很乐意把「这个项目用 pnpm」记一条 —— 那看一眼 `package.json`
173
249
  // 就知道,记下来却永久占着每一轮请求。合并 write/update 后这两句更要留:upsert 降低了
174
250
  // "再记一条"的摩擦,而摩擦正是这里唯一拦得住它的东西。
175
- description: 'Create a memory, or update the one that already has this id — the receipt says which happened. Memories cost context on EVERY later request, so record only what cannot be re-derived from code, config or git, and check the list for one that already says this — update that instead of adding a near-duplicate. Blocked while the active scene is locked. Only on the user\'s instruction.',
251
+ description: 'Create a memory, or update the one with this id — the receipt says which. Memories cost context on every later request: record only what cannot be re-derived from code, config or git, and update an existing one rather than adding a near-duplicate. Blocked while the active scene is locked. Only on the user\'s instruction.',
176
252
  parameters: {
177
253
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name> — copy it from the list. `global` is the always-on scene.' },
178
254
  description: { type: 'string', description: 'One-sentence description (<=500 chars). Required when creating. Empty string = drop it and re-derive from the body; omit = keep.' },
@@ -183,7 +259,7 @@ export function buildMemoryTools(deps) {
183
259
  nextName: { type: 'string', description: 'New memory name (= file name); omit to keep it.' },
184
260
  },
185
261
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
186
- async execute(args) {
262
+ async execute(args, exec) {
187
263
  const blocked = await deps.lockedSceneGuard();
188
264
  if (blocked)
189
265
  throw new Error(blocked);
@@ -266,13 +342,22 @@ export function buildMemoryTools(deps) {
266
342
  // `enabled: false`(ops/memory.ts 的 rulesCreate),而原先这句只提场景 —— 读起来像
267
343
  // "场景一开它就自动生效",模型据此以为已经生效,实际还差一次开关。与 skill_manager_save
268
344
  // 的 enableHint 同一形状:点名的工具在出厂默认名单里是关着的,关着就改说"用户开启后"。
345
+ // 「会不会注入」按**本会话**的投影判(0.21.2):会话钉了别的场景时,这条记忆落进的
346
+ // 那个场景在这个对话里根本没开着 —— 照全局口径回一句"打开就能用"是错的答案。
347
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
348
+ const effScene = scoped?.scope?.scene;
349
+ const activeNow = effScene === undefined ? all.activeScene : effScene;
350
+ const activeMode = effScene === undefined ? all.activeMode : 'custom';
269
351
  const sceneActive = group === 'global' ||
270
- (group !== '' && (all.activeMode === 'all' || String(all.activeScene || '') === group));
352
+ (group !== '' && (activeMode === 'all' || String(activeNow || '') === group));
271
353
  const sceneTail = sceneActive ? '' : ', and turn scene "' + group + '" on';
272
354
  const enableHint = deps.toolVisible('memory_manager_switch')
273
355
  ? ' (created disabled — turn it on first with memory_manager_switch' + sceneTail + ')'
274
356
  : ' (created disabled — the user has to turn it on first' + sceneTail + ')';
275
- return 'OK: created ' + r.rule.id + enableHint + warn;
357
+ // 会话层:这条记忆写的是**磁盘上的那一份**(所有对话共用),本会话的开关只决定
358
+ // "这里看不看得到"。模型据此回一句"记下了"时,用户很容易读成"只在这个对话里"。
359
+ return 'OK: created ' + r.rule.id + enableHint + warn +
360
+ globalActionNote(deps, exec && exec.agent, 'memory', 'memory');
276
361
  },
277
362
  }));
278
363
  }
@@ -11,7 +11,8 @@
11
11
  // 换句话说:**能删的是可恢复的那一步,不可逆的那一步照旧不给模型。**
12
12
  import { join } from 'node:path';
13
13
  import { normalizePresetDescription } from '../prompts/service.js';
14
- import { text } from './deps.js';
14
+ import { hasPromptOverride } from '../scope/scope-overrides.js';
15
+ import { sessionScopeOf, text } from './deps.js';
15
16
  export function buildPromptTools(deps) {
16
17
  const { defineTool, register } = deps;
17
18
  register(defineTool({
@@ -19,7 +20,7 @@ export function buildPromptTools(deps) {
19
20
  // 那句 `(that reminder is absent when the preset carries the official instructions line)`
20
21
  // 删掉(2026-10-15 注入文本审查):模型**观测不到**"official instructions line"这个条件,
21
22
  // 拿它做不了任何决定 —— reminder 在不在,它抬头就能看见,不必由描述来预告。
22
- description: 'List AGENTS.md presets (id, description, active state, file path); read that file for a preset body. The one in effect is in the "Current prompt" reminder, whose "Instructions from:" line names the file. Defaults to the one in effect; all=true for the whole library.',
23
+ description: 'List AGENTS.md presets (id, description, active state, file path); read that file for a body. The one in effect is in the "Current prompt" reminder. Defaults to the one in effect; all=true for the whole library.',
23
24
  parameters: {
24
25
  all: { type: 'boolean', description: 'Include inactive presets (default false).' },
25
26
  },
@@ -54,12 +55,20 @@ export function buildPromptTools(deps) {
54
55
  const desc = normalizePresetDescription(p.description);
55
56
  return p.id + mark + ' | ' + (desc || '(no description)') + ' | ' + join(deps.promptsDir, p.id, 'AGENTS.md');
56
57
  });
58
+ // 会话层(0.21.2,决策 5):提示词**不进**会话域 —— 预设写的是全局基线 ~/.dsh/AGENTS.md,
59
+ // 宿主每轮只读一份。会话能改的是生效场景,而场景绑哪个预设是场景自己的事。
60
+ // 这句只在模型真会读错时才值钱:它会拿这份清单回答「本会话现在用哪份提示词」,
61
+ // 而本会话钉住场景时,答案来自那个场景的绑定,不是这份 active 标记。
62
+ const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
63
+ const sessionLine = pinned === undefined
64
+ ? '\n(prompts are global: this scope has no preset of its own)'
65
+ : '\n(prompts are global; this scope pins scene "' + pinned + '", so the preset in effect here is that scene\'s binding — not necessarily the [active] one below)';
57
66
  const header = 'AGENTS.md presets: ' + (showAll
58
67
  ? all.length + ' in the library'
59
68
  : fallback.length
60
69
  ? fallback.length + (active.length ? ' active' : ' last applied') + ' of ' + all.length +
61
70
  (fallback.length === all.length ? '' : ' (pass all=true for the whole library)')
62
- : '0 active of ' + all.length + ' (pass all=true for the whole library)') + '\n';
71
+ : '0 active of ' + all.length + ' (pass all=true for the whole library)') + sessionLine + '\n';
63
72
  // 同上:AGENTS.md 由官方 dsh-agent-instructions 行承载(极简没挂这一行),
64
73
  // 这一行不在时文件内容不会进上下文。
65
74
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
@@ -68,7 +77,7 @@ export function buildPromptTools(deps) {
68
77
  }));
69
78
  register(defineTool({
70
79
  name: 'prompt_manager_apply',
71
- description: 'Apply one AGENTS.md preset by id; effective next turn. If a scene drives the baseline this does NOT refuse — it rebinds that scene to the preset and re-syncs it, so tell the user which scene was rebound. A locked scene blocks the call. Pass apply=false to cancel instead — AGENTS.md goes back to what it was before the run of applies (the file is removed if there was none to begin with); a scene driving the baseline refuses that, rebind the scene instead. Only on the user\'s instruction.',
80
+ description: 'Apply one AGENTS.md preset by id; effective next turn. When a scene drives the baseline this does not refuse — it rebinds that scene, so tell the user which one. A locked scene blocks the call. apply=false cancels instead: AGENTS.md goes back to what it was before this run of applies (removed if there was none), which a scene-driven baseline refuses — rebind the scene instead. Only on the user\'s instruction.',
72
81
  parameters: {
73
82
  // `id` 从 required 摘掉(2026-10-15 smoke-test P1-5):描述一直写着 "Ignored when
74
83
  // apply=false",schema 却把它标成必填 —— 模型照描述「取消不用给 id」操作,先被 schema
@@ -78,10 +87,20 @@ export function buildPromptTools(deps) {
78
87
  apply: { type: 'boolean', description: 'Omit or true = apply the preset in `id`; false = cancel — undo the run of applies (no `id` needed).' },
79
88
  },
80
89
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
81
- async execute(args) {
90
+ async execute(args, exec) {
82
91
  const blocked = await deps.lockedSceneGuard();
83
92
  if (blocked)
84
93
  throw new Error(blocked);
94
+ // 会话层(0.21.2,决策 5):提示词永远全局。本会话钉了场景时,这里改的是**那个场景**
95
+ // 的绑定(`applyPresetGuarded` 的 viaScene 分支)—— 别的对话只要没钉同一个场景就不受影响,
96
+ // 但这不是「本会话的提示词」,回执必须按那条路说清。
97
+ // 提示词**不进**会话域(决策 5),所以这里没有 scope 参数,也**不做**
98
+ // `requireGlobalScope` 守卫(2026-10-21 审查 P2-2):守卫读 `args.scope`,而参数表里
99
+ // 没有这个字段 —— 模型按 schema 不可能传它,守卫只在「模型自己编了一个未声明参数」时
100
+ // 才触发,等于靠运气。留着这行还让 deps.ts 的清单以为这条被守住了。
101
+ // 提示词确实只有全局一层,参数表已经把这件事说完了。
102
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
103
+ const pinned = scoped?.scope?.scene;
85
104
  if (args.apply === false) {
86
105
  // 取消方向:`agentsmd-unapply` 自带两条护栏(场景驱动时拒绝、没有链起点时给确定
87
106
  // 错误码),原样透传。回执要说清恢复成哪种 —— 起点没有文件时是**删文件**,
@@ -89,9 +108,10 @@ export function buildPromptTools(deps) {
89
108
  const r = await deps.unapplyPreset();
90
109
  if (!r.ok)
91
110
  throw new Error(r.error || 'failed to cancel the application');
92
- return r.removed === true
111
+ return (r.removed === true
93
112
  ? 'OK: application cancelled — ~/.dsh/AGENTS.md did not exist before the run started, so the file was removed (effective next turn).'
94
- : 'OK: application cancelled — ~/.dsh/AGENTS.md is back to what it was before the run started (effective next turn).';
113
+ : 'OK: application cancelled — ~/.dsh/AGENTS.md is back to what it was before the run started (effective next turn).') +
114
+ promptScopeTail(scoped?.scope);
95
115
  }
96
116
  const id = String((args && args.id) || '').trim();
97
117
  if (id === '')
@@ -102,12 +122,44 @@ export function buildPromptTools(deps) {
102
122
  // 场景驱动时写的是「场景绑定」,回执必须说清改的是哪个场景 —— 只说「已应用到
103
123
  // AGENTS.md」会让模型对用户谎报(用户不知道自己的场景绑定被换掉了)。
104
124
  if (r.viaScene) {
105
- return 'OK: preset ' + id + ' is now the prompt binding of scene "' + (r.scene || '') + '" and the scene was re-synced (effective next turn; ~/.dsh/AGENTS.md now carries that scene\'s binding).';
125
+ return 'OK: preset ' + id + ' is now the prompt binding of scene "' + (r.scene || '') + '" and the scene was re-synced (effective next turn; ~/.dsh/AGENTS.md now carries that scene\'s binding).' +
126
+ // 会话层:这个场景可能只是**本会话**钉住的那个(别的对话钉别的场景),所以「绑到了场景」
127
+ // 与「所有对话都变成这份提示词」不是一回事。
128
+ (pinned === undefined || pinned !== String(r.scene || '')
129
+ ? ''
130
+ : '\nnote: that is this scope\'s pinned scene. Other conversations only pick this up if they pin the same scene; the machine-wide baseline is whatever the global scene binds.');
106
131
  }
107
132
  // 生效时机与宿主行为对齐(index.ts 提示词服务一节考证过):dsh-agent-instructions
108
133
  // 每个 pre-step 都 stat 比对版本,写文件即下一轮重读 —— 不是"下个会话"。说错了
109
134
  // 模型会劝用户重开会话,而其实下一句话就已经在新基线下跑。
110
- return 'OK: preset ' + id + ' applied to ~/.dsh/AGENTS.md — effective next turn' + (r.backedUp ? ' (previous backed up to __last-applied__)' : '');
135
+ return 'OK: preset ' + id + ' applied to ~/.dsh/AGENTS.md — effective next turn' + (r.backedUp ? ' (previous backed up to __last-applied__)' : '') +
136
+ // 成功分支也要带尾注(2026-10-21 审查 P0-2):`applyPresetGuarded` 走的是**全局**
137
+ // driver,本会话钉着的场景/会话级覆盖都不在其中 —— 不带的话,模型会照回执说
138
+ // 「提示词已换」,而用户在这个对话里看到的是原来那份。
139
+ promptScopeTail(scoped?.scope);
111
140
  },
112
141
  }));
113
142
  }
143
+ /**
144
+ * 提示词回执的会话尾注(0.21.2,决策 5;2026-10-21 审查 P0-2 由「钉场景」扩成三路)。
145
+ *
146
+ * 提示词**不进**会话域:预设写的是全局基线 `~/.dsh/AGENTS.md`,宿主每轮只读一份。
147
+ * 但**生效来源**按会话走 —— 本会话可能钉了场景(`scene-preset`),也可能带会话级
148
+ * 提示词覆盖(`session-preset` / `session-content`),两者都排在 `global-file` 之上。
149
+ * 不说清的话,模型会回一句「提示词已换」,而用户在自己的对话里看到的是别的。
150
+ *
151
+ * 为什么必须三路:`prompt_manager_apply` 走的是**全局** driver(`applyPresetGuarded`),
152
+ * 会话钉的场景不在其中。「全局没有场景 + 本会话钉了场景」是日常形态,而这条路此前
153
+ * 只在 `apply=false` 分支带了尾注,成功分支漏了 —— 用户按回执去验证,必然发现没变。
154
+ */
155
+ function promptScopeTail(scope) {
156
+ if (scope === undefined)
157
+ return '';
158
+ if (hasPromptOverride(scope)) {
159
+ return '\nnote: prompts are global — this changed the machine-wide baseline. This scope carries its own prompt override, so what it gets here stays the same until that override is cleared.';
160
+ }
161
+ const pinned = scope.scene;
162
+ if (pinned === undefined)
163
+ return '';
164
+ return '\nnote: prompts are global — this changed the machine-wide baseline. This scope pins scene "' + pinned + '", so what it actually gets is that scene\'s binding.';
165
+ }
@@ -13,15 +13,23 @@
13
13
  //
14
14
  // 参数名统一 `id`:`trash` 时是资源标识(记忆 `<场景>/<名>`、技能名、人设名、预设 id、
15
15
  // 场景名),`restore` 时是 `action=list` 给出的**回收站条目 id** —— 两种含义在描述里写清。
16
- import { locateSkillRoot, text } from './deps.js';
16
+ import { globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text } from './deps.js';
17
17
  /** 三个动词共用的描述骨架。 */
18
18
  function removeDescription(noun) {
19
- return 'Delete one ' + noun + ' (moves it to the trash), restore one from the trash, or list the trash. '
20
- + 'Nothing here is permanent — emptying the trash is a panel action. '
19
+ return 'Delete one ' + noun + ' (to the trash), restore one, or list the trash. '
20
+ + 'Deletes are recoverable; this tool never empties the trash. '
21
21
  + 'Blocked while the active scene is locked. Only on the user\'s instruction.';
22
22
  }
23
23
  /** `action` 参数:三个动词 + 每个动词要哪个 `id`。 */
24
- const ACTION_DESC = 'trash = delete the item named in `id` (moves it to the trash); restore = put back the trash entry `id` (get its id from action=list); list = list the trash (no `id`).';
24
+ const ACTION_DESC = 'trash = delete the item named by `id`; restore = put back a trash entry id (from list); list = list the trash (no `id`).';
25
+ /** 删除只有全局一份(会话层没有可删的东西),四个域同一句话。 */
26
+ const REMOVE_SCOPE_DESC = scopeGlobalOnlyDesc('one machine-wide copy', 'switch it off here instead');
27
+ /**
28
+ * 场景的变体(2026-10-21 审查 P2-1):`REMOVE_SCOPE_DESC` 让模型「在本会话里把它关掉」,
29
+ * 而场景根本没有「关掉」这个动作 —— `scene_manager_switch` 只有 enter / exit。照抄那一句
30
+ * 会让模型去找一个不存在的开关,或者干脆回一句「做不到」。
31
+ */
32
+ const REMOVE_SCOPE_DESC_SCENE = scopeGlobalOnlyDesc('the scene record and archive are machine-wide', 'exit it here with scene_manager_switch (action=exit)');
25
33
  /**
26
34
  * 恢复 op 回传的**最终落盘名**。五个域把名字放在不同字段上:
27
35
  * · 记忆 / 技能 / 人设 / 场景 → `name`(退号恢复时它是新名字,不是回收站里的原名)
@@ -46,8 +54,15 @@ function restoredName(r) {
46
54
  };
47
55
  return pick(r) || pick(r && r.data);
48
56
  }
49
- /** 一条删除工具的 execute:三个动词的分派与回执。 */
50
- async function runRemove(deps, cfg, args) {
57
+ /**
58
+ * 一条删除工具的 execute:三个动词的分派与回执。
59
+ *
60
+ * 会话层(0.21.2):删除是**全局**动作 —— 技能正文、人设 `.md`、场景档案、MCP 补丁、
61
+ * 提示词预设都只有一份,没有「本会话的副本」。计划 §8.2 对这一格的口径是「全局动作」,
62
+ * 所以这里不写会话层,只在**这个对话真有该域覆盖**时补一句尾注:
63
+ * 删完之后那条会话覆盖还在(读时忽略,对账才清),不说明的话用户会以为它跟着没了。
64
+ */
65
+ async function runRemove(deps, cfg, args, agent) {
51
66
  const action = String((args && args.action) || '');
52
67
  if (action !== 'trash' && action !== 'restore' && action !== 'list') {
53
68
  throw new Error('action must be trash / restore / list (got: ' + (action || '(empty)') + ')');
@@ -62,6 +77,10 @@ async function runRemove(deps, cfg, args) {
62
77
  const blocked = await deps.lockedSceneGuard();
63
78
  if (blocked)
64
79
  throw new Error(blocked);
80
+ // 会话层(0.21.2):`scope: "session"` 是模型**以为**自己能删本会话那一份时的错误,
81
+ // 当场纠回来。省略 / "global" 照旧(0.21.2 的行为不变)。五条删除都是全局动作 ——
82
+ // 连提示词那一族也一样(决策 5:提示词根本不进会话域,更没有「本会话的预设」可删)。
83
+ requireGlobalScope(args, cfg.noun + 's', !sessionLayerOn(deps));
65
84
  const id = String((args && args.id) || '').trim();
66
85
  if (id === '')
67
86
  throw new Error('missing argument: id (required by action=' + action + ')');
@@ -69,7 +88,8 @@ async function runRemove(deps, cfg, args) {
69
88
  if (!r || r.ok === false)
70
89
  throw new Error((r && r.error) || (action === 'trash' ? 'failed to move it to the trash' : 'restore failed'));
71
90
  if (action === 'trash') {
72
- return 'OK: ' + cfg.label + ' "' + id + '" moved to the trash (recoverable; permanent deletion lives in the panel trash)';
91
+ return 'OK: ' + cfg.label + ' "' + id + '" moved to the trash (recoverable; permanent deletion lives in the panel trash)' +
92
+ (cfg.domain === undefined ? '' : globalActionNote(deps, agent, cfg.domain, cfg.label));
73
93
  }
74
94
  // 恢复的回执要说**恢复成了什么**,而不是回收站条目 id(2026-10-15 smoke-test P1-6):
75
95
  // `id` 是 `action=list` 给的那一串(记忆 `mv…`、技能 `<时间戳>-<uuid>`),模型看到它
@@ -86,7 +106,7 @@ export function buildRemoveTools(deps) {
86
106
  const pr = deps.promptOps;
87
107
  const sc = deps.sceneOps;
88
108
  const memoryCfg = {
89
- noun: 'memory', label: 'memory',
109
+ noun: 'memory', label: 'memory', domain: 'memory',
90
110
  trash: (a) => mem['rules-remove']({ id: String(a.id || '') }),
91
111
  restore: (a) => mem['rules-restore']({ trashId: String(a.id || '') }),
92
112
  list: async () => {
@@ -97,7 +117,7 @@ export function buildRemoveTools(deps) {
97
117
  },
98
118
  };
99
119
  const skillCfg = {
100
- noun: 'skill', label: 'skill',
120
+ noun: 'skill', label: 'skill', domain: 'skills',
101
121
  // 与 `skill_manager_switch` 同一条(smoke-test P0-1):不给 root 就按名字在全部来源里
102
122
  // 找胜出的那一份。默认值原本是 dsh,而 `skill_manager_save` 落 hub —— 「建完就删」
103
123
  // 必然报「技能不存在」。删一个真的不存在的技能时退回 dsh,交给 op 报它自己的错。
@@ -117,7 +137,7 @@ export function buildRemoveTools(deps) {
117
137
  },
118
138
  };
119
139
  const subagentCfg = {
120
- noun: 'persona', label: 'persona',
140
+ noun: 'persona', label: 'persona', domain: 'subagents',
121
141
  trash: (a) => sub['subagent-delete']({ name: String(a.id || '') }),
122
142
  restore: (a) => sub['subagent-trash-restore']({ id: String(a.id || '') }),
123
143
  list: async () => {
@@ -140,7 +160,7 @@ export function buildRemoveTools(deps) {
140
160
  },
141
161
  };
142
162
  const sceneCfg = {
143
- noun: 'scene', label: 'scene',
163
+ noun: 'scene', label: 'scene', domain: 'scene',
144
164
  // 删场景走 handlers 里那份(`withAgentsMdSync` 包过):直调 `memoriesService.ops` 会漏掉
145
165
  // 「场景绑的预设曾写进 AGENTS.md,删了要跟着处理」那一步。
146
166
  trash: (a) => deps.sceneRemove({ name: String(a.id || '') }),
@@ -157,50 +177,55 @@ export function buildRemoveTools(deps) {
157
177
  description: removeDescription('memory'),
158
178
  parameters: {
159
179
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
160
- id: { type: 'string', description: 'For trash: the memory id `<scene>/<name>`. For restore: the trash entry id from action=list. Not needed for list.' },
180
+ id: { type: 'string', description: 'For trash: the memory id `<scene>/<name>`; for restore: a trash entry id; omit for list.' },
181
+ scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
161
182
  },
162
183
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
163
- async execute(args) { return runRemove(deps, memoryCfg, args); },
184
+ async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent); },
164
185
  }));
165
186
  register(defineTool({
166
187
  name: 'skill_manager_remove',
167
188
  description: removeDescription('skill'),
168
189
  parameters: {
169
190
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
170
- id: { type: 'string', description: 'For trash: the skill name. For restore: the trash entry id from action=list. Not needed for list.' },
191
+ id: { type: 'string', description: 'For trash: the skill name; for restore: a trash entry id; omit for list.' },
192
+ scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
171
193
  root: { type: 'string', description: 'Source root the skill lives in. Default: whichever source holds that skill; only used by action=trash.' },
172
194
  },
173
195
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
174
- async execute(args) { return runRemove(deps, skillCfg, args); },
196
+ async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent); },
175
197
  }));
176
198
  register(defineTool({
177
199
  name: 'subagent_manager_remove',
178
200
  description: removeDescription('persona'),
179
201
  parameters: {
180
202
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
181
- id: { type: 'string', description: 'For trash: the persona name. For restore: the trash entry id from action=list. Not needed for list.' },
203
+ id: { type: 'string', description: 'For trash: the persona name; for restore: a trash entry id; omit for list.' },
204
+ scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
182
205
  },
183
206
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
184
- async execute(args) { return runRemove(deps, subagentCfg, args); },
207
+ async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent); },
185
208
  }));
186
209
  register(defineTool({
187
210
  name: 'prompt_manager_remove',
188
211
  description: removeDescription('AGENTS.md preset'),
189
212
  parameters: {
190
213
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
191
- id: { type: 'string', description: 'For trash: the preset id. For restore: the trash entry id from action=list. Not needed for list.' },
214
+ id: { type: 'string', description: 'For trash: the preset id; for restore: a trash entry id; omit for list.' },
215
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a preset writes the one global baseline', 'there is nothing per-conversation to delete') },
192
216
  },
193
217
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
194
- async execute(args) { return runRemove(deps, promptCfg, args); },
218
+ async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent); },
195
219
  }));
196
220
  register(defineTool({
197
221
  name: 'scene_manager_remove',
198
222
  description: removeDescription('scene'),
199
223
  parameters: {
200
224
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
201
- id: { type: 'string', description: 'For trash: the scene name. For restore: the trash entry id from action=list. Not needed for list.' },
225
+ id: { type: 'string', description: 'For trash: the scene name; for restore: a trash entry id; omit for list.' },
226
+ scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC_SCENE },
202
227
  },
203
228
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
204
- async execute(args) { return runRemove(deps, sceneCfg, args); },
229
+ async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent); },
205
230
  }));
206
231
  }