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
@@ -24,7 +24,7 @@
24
24
  // 理由是"那是改运行时环境的动作";补上 `_switch` 的取舍记在 CHANGELOG 里 —— 要点是
25
25
  // **场景段的动作句仍然不加回来**:「上下文注入只给现在是什么」是同一天定下的原则,
26
26
  // 不因为多了一条工具就破例(工具描述本来就是写"什么时候该用它"的地方)。
27
- import { text, toolNameList } from './deps.js';
27
+ import { effectiveScope, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
28
28
  import { FACTORY_TOOL_TABLE_PRESET } from './table.js';
29
29
  /** 档案里由模型设置的段(`memories` 段在 P5 已废弃,不再是档案的一部分)。
30
30
  * `mcpNotes`(0.20.0)与其余三段同族:整段替换、段缺席 = 不碰这一域。 */
@@ -128,17 +128,36 @@ function segmentDiff(key, beforeValue, afterValue) {
128
128
  *
129
129
  * 探测不到 / 什么都没做(`unchanged`)就不占行:那两种情况下文件确实没变,
130
130
  * 说一句"没变"只是噪音。
131
+ *
132
+ * `baselineError`(0.21.2 补齐):切进去了**但退不回来** —— 场景提示词已写进 AGENTS.md,
133
+ * 而"进场景之前那份基线"没能落盘。此前这一支在客户端有(45-scenes.js 的
134
+ * `scenes.agents.note.baselineLost`)、工具回执里没有,于是模型侧唯一能看到的版本是
135
+ * "切成功了"。它比 `error` 更该说:文件已经改了,只是没有退路。
136
+ *
137
+ * `snapshotMissing`(0.21.2 补齐):**模式快照丢了**,退出场景只能落盘模式位、运行时
138
+ * (MCP / 技能 / 人设 / 工具表)回不来。客户端有计划卡上的同款文案
139
+ * (`scenes.exit.noSnapshot`),工具回执此前同样没有 —— 模型只能看到"已退出"。
131
140
  */
132
- function agentsMdNote(sync) {
141
+ function agentsMdNote(sync, action) {
133
142
  if (!sync || typeof sync !== 'object')
134
143
  return '';
144
+ const notes = [];
135
145
  if (sync.error)
136
- return '\nWARN: the global baseline (AGENTS.md) was not synced: ' + String(sync.error);
146
+ notes.push('\nWARN: the global baseline (AGENTS.md) was not synced: ' + String(sync.error));
137
147
  if (sync.applied)
138
- return '\nAGENTS.md <- the scene-bound preset "' + String(sync.applied) + '"';
148
+ notes.push('\nAGENTS.md <- the scene-bound preset "' + String(sync.applied) + '"');
139
149
  if (sync.restored === true)
140
- return '\nAGENTS.md <- restored the pre-scene baseline';
141
- return '';
150
+ notes.push('\nAGENTS.md <- restored the pre-scene baseline');
151
+ if (sync.baselineError) {
152
+ notes.push('\nWARN: AGENTS.md was switched, but the pre-scene baseline could not be saved ('
153
+ + String(sync.baselineError) + ') — leaving this scene will NOT restore your previous global prompt.'
154
+ + ' The multi-generation backups under __last-applied__/AGENTS.md.bak-* still hold earlier copies.');
155
+ }
156
+ if (action === 'exit' && sync.snapshotMissing === true) {
157
+ notes.push('\nWARN: no mode snapshot was recorded for the scene that was left — the runtime'
158
+ + ' (MCP servers / skills / personas / tool table) was NOT rolled back; only the mode bit was cleared.');
159
+ }
160
+ return notes.join('');
142
161
  }
143
162
  export function buildSceneTools(deps) {
144
163
  const { defineTool, register } = deps;
@@ -150,10 +169,16 @@ export function buildSceneTools(deps) {
150
169
  // 默认的隐藏名单里):静态文本没法按 toolVisible 改写,点名一条模型没有的工具只会让它
151
170
  // 白跑一趟。要说"去哪看"就用中性说法(the scene listing / the "Current scene" reminder
152
171
  // —— 后者是常驻源,只要场景域开着就在)。点名只留在**运行时回执**里、按可见性分叉。
153
- description: 'List every scene with its archive (what entering it switches on: MCP servers, skills, personas, quick prompts, and the bound model tool-table scheme when there is one), bound prompt preset, memory count and enabled / entered / locked state. The scene currently entered is also shown in the "Current scene" reminder.',
172
+ description: 'List every scene with its archive (what entering it switches on: MCP servers, skills, personas, quick prompts, and the bound tool-table scheme), bound prompt preset, memory count and enabled / entered / locked state. The scene currently entered is also shown in the "Current scene" reminder.',
154
173
  parameters: {},
155
174
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
156
- async execute() {
175
+ async execute(_args, exec) {
176
+ // 会话层(0.21.2,计划 §8.2「scene_manager_list 标注本会话与全局默认」):
177
+ // 列表里的 on/off 是**全局**的启用集合;本会话进入的场景是另一件事(只改这个对话
178
+ // 看到什么)。两者都不说清,模型会把「全局进入的是 A」读成「这个对话看到的也是 A」。
179
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
180
+ const pinned = scoped?.scope?.scene;
181
+ const detachedHere = scoped?.scope?.detached === true;
157
182
  const r = await deps.rulesOps['rules-list']({});
158
183
  if (!r || r.ok === false)
159
184
  throw new Error((r && r.error) || 'failed to read scenes');
@@ -185,6 +210,10 @@ export function buildSceneTools(deps) {
185
210
  // 模型会把"启用着"读成"现在就是它" —— 而记忆与提示词只按**进入**的那一个注入。
186
211
  if (entered !== null && name === entered)
187
212
  state.push('entered');
213
+ // 本会话进入的那个场景(0.21.2):与 `entered` 是两个不同的东西 —— 前者只改
214
+ // 这个对话看到什么,后者真的切了运行时。同一个名字两个标,不冲突。
215
+ if (pinned !== undefined && name === pinned)
216
+ state.push('entered-in-this-conversation');
188
217
  if (s.locked === true)
189
218
  state.push('locked');
190
219
  // 打**场景名**而不是 label:`scene_manager_save` / `_switch` 要的都是名字(单个
@@ -198,10 +227,17 @@ export function buildSceneTools(deps) {
198
227
  bits.push('archive: ' + (archives === null ? 'unreadable (does not mean absent)' : archiveText(archives[name])));
199
228
  return bits.join(' · ');
200
229
  });
230
+ // 会话层(0.21.2):这一层进入的场景只改这一层的视图,不切运行时 —— 这一行必须与
231
+ // `entered` 分开报。(0.21.2:退出场景之后这一层不回全局,而是回到创建时的样子。)
232
+ const sessionLine = pinned !== undefined
233
+ ? '\nthe view here is scene "' + pinned + '" (its own view: the machine-wide runtime was not switched and AGENTS.md was not written).'
234
+ : (detachedHere
235
+ ? '\nthe scene was left here: this scope shows what it looked like when it was created (its own view; the machine-wide runtime was not touched).'
236
+ : '');
201
237
  return 'scenes (' + scenes.length + ' · ' +
202
238
  (r.activeMode === 'all' ? 'the enabled set is the historical default (all enabled)' : 'the enabled set is narrowed to a single scene') +
203
239
  (entered === null ? '; no scene is entered right now' : '; currently entered: "' + entered + '"') + '):\n' +
204
- (lines.join('\n') || '(no scenes)');
240
+ (lines.join('\n') || '(no scenes)') + sessionLine;
205
241
  },
206
242
  }));
207
243
  register(defineTool({
@@ -212,10 +248,14 @@ export function buildSceneTools(deps) {
212
248
  description: 'Enter a scene, or leave the one currently entered. Entering switches on its archive and everything else off, narrows injection to its memories, and applies its bound prompt preset to AGENTS.md. Leaving restores the runtime snapshot taken on entry. Only when the user asks or approves.',
213
249
  parameters: {
214
250
  action: { type: 'string', required: true, enum: ['enter', 'exit'], description: 'enter = switch to the scene named in `scene`; exit = leave the current one (no scene needed).' },
215
- scene: { type: 'string', description: 'Scene name (one path segment), required for enter. Use the exact name, not the display label — the scene listing and the "Current scene" reminder both print names.' },
251
+ scene: { type: 'string', description: 'Scene name (one path segment), required for enter — the exact name, not the display label.' },
252
+ // 决策 10 / 14(2026-10-19):默认只改**这个对话看到什么**,不切运行时、不写 AGENTS.md。
253
+ // 0.21.2:进入时可能让场景勾中的 MCP 服务器 / 技能来源按租约临时运行(连接与来源启用是
254
+ // 进程级的);那一步只在回执里出现,别在参数里长篇解释。
255
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('the scene is entered for that scope only: no runtime switch, AGENTS.md untouched (a scene entered here may keep its MCP servers running as a lease). global = the machine-wide current scene: switches the runtime and applies the bound prompt to AGENTS.md.') },
216
256
  },
217
257
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
218
- async execute(args) {
258
+ async execute(args, exec) {
219
259
  const action = String((args && args.action) || '');
220
260
  if (action !== 'enter' && action !== 'exit') {
221
261
  throw new Error('action must be enter / exit (got: ' + (action || '(empty)') + ')');
@@ -223,6 +263,34 @@ export function buildSceneTools(deps) {
223
263
  // 刻意**不过** `lockedSceneGuard()`:场景**自身**的启停不在冻结清单里(冻结的是五个
224
264
  // 域的内容)。锁定中的场景正被进入时不能退出 —— 那条守卫在 `scene-mode-set` 的包装里
225
265
  // (index.ts),它以 ok:false 返回,下面如实抛出去。
266
+ // 决策 14(0.21.2 起为"本会话的场景模式"):会话层进出场景**不切全局运行时** ——
267
+ // 不调 `scene-mode-set`、不调 `rules-set-active`、不写 AGENTS.md。它把场景作为本会话的
268
+ // 一层记下来:档案里勾了的在其生效集合内、没勾的在本会话关掉,记忆 / 场景段 / 目录按那个
269
+ // 场景投影。两个例外要如实说:进入时会把场景勾中的 MCP 服务器 / 技能来源在**全局**拉起
270
+ // (连接与来源启用是进程级的,没有会话版本),那一步的影响由回执里的 `warnings` 带出来。
271
+ // 全局粒度下没有"本会话的场景"这回事 —— 进 / 出就是切机器级运行时,走下面那条路。
272
+ if (effectiveScope(deps, args) === 'session') {
273
+ if (!deps.sessionScopeSet)
274
+ throw new Error('per-conversation scenes are unavailable in this host: pass scope="global" to switch the machine-wide scene');
275
+ let wanted = null;
276
+ if (action === 'enter') {
277
+ wanted = String((args && args.scene) || '').trim();
278
+ if (wanted === '')
279
+ throw new Error('action=enter needs scene: the scene name (copy it from the scene_manager_list line)');
280
+ if (wanted.indexOf('/') >= 0 || wanted.indexOf('\\') >= 0)
281
+ throw new Error('a scene name is a single path segment (no / or \\): ' + wanted);
282
+ }
283
+ // `scope-set` 的 scene 分支读的是 `value`:场景名 = 进入,null = 退出(下层换成基线)。
284
+ const sc = await deps.sessionScopeSet(exec && exec.agent, 'scene', '', wanted);
285
+ if (!sc || sc.ok === false)
286
+ throw new Error((sc && sc.error) || 'failed to switch the scene here');
287
+ const warnings = sc.warnings !== undefined && sc.warnings.length > 0 ? '\n' + sc.warnings.join('\n') : '';
288
+ return action === 'enter'
289
+ ? 'OK: scene "' + wanted + '" is now entered for this scope (its own view)' +
290
+ '. The machine-wide runtime did not switch and AGENTS.md was not written; conversations outside this scope keep theirs.' + warnings +
291
+ ' Pass scope="global" to enter it for real.'
292
+ : 'OK: this scope left the scene — back to how it looked when it was created (its own view). The runtime was not touched; conversations outside this scope keep theirs.';
293
+ }
226
294
  let scene = '';
227
295
  if (action === 'enter') {
228
296
  scene = String((args && args.scene) || '').trim();
@@ -288,8 +356,23 @@ export function buildSceneTools(deps) {
288
356
  if (Array.isArray(mode.stale) && mode.stale.length) {
289
357
  parts.push('dropped keys this machine does not have: ' + mode.stale.join(', '));
290
358
  }
291
- return head + (parts.length ? ' · ' + parts.join(' · ') : '') + agentsMdNote(act.agentsMd) +
292
- (noop ? '\n(' + (action === 'enter' ? 'already in the target scene' : 'already outside every scene') + ' — runtime unchanged)' : '');
359
+ // `snapshotMissing` 从模式侧带过来:`act` 是启用集合那次调用的产物,本身没有它,
360
+ // 而"退出时快照丢了"这件事只有模式引擎知道(见 archive-engine.ts 的 scene-mode-set)。
361
+ // 进 / 退两个方向都报 —— 进场景时它说的是"你即将进入一个退不出来的场景"。
362
+ const snapshotMissing = mode && mode.exit && mode.exit.snapshotMissing === true;
363
+ // 会话层(0.21.2):全局切了场景,但**本会话**若钉着别的场景,这里看到的东西不会变。
364
+ // 不点这一句,模型会以为「切了场景 = 我这边也切了」,然后拿错误的场景解释上下文。
365
+ const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
366
+ const pinnedNote = pinned === undefined
367
+ ? ''
368
+ : '\nnote: this scope pins scene "' + pinned + '" for its own view, so what it sees did not change. Clear that pin (scene_manager_switch with scope="session", action="exit") to follow this one.';
369
+ // 全局分支。全局粒度下 askedForSession 也走这里 —— 点明"隔离关着,所以这就是全局"。
370
+ const askedForSession = (args && args.scope) !== 'global';
371
+ return head + (parts.length ? ' · ' + parts.join(' · ') : '')
372
+ + agentsMdNote(act.agentsMd, snapshotMissing ? action : undefined) +
373
+ (noop ? '\n(' + (action === 'enter' ? 'already in the target scene' : 'already outside every scene') + ' — runtime unchanged)' : '') +
374
+ pinnedNote +
375
+ (askedForSession ? isolationOffNote(deps) : '');
293
376
  },
294
377
  }));
295
378
  register(defineTool({
@@ -297,34 +380,34 @@ export function buildSceneTools(deps) {
297
380
  // 「写入指引」保留("写成指令而不是备注"—— 这是场景说明质量的杠杆),但不再声称
298
381
  // "注入后模型会被要求照办":2026-09-23 定稿把场景段的授权语删了(注入只陈述现状),
299
382
  // 参数说明与注入侧各说各话时,模型信的那份是错的。改为如实说明去向。
300
- description: 'Save a scene — a named bundle the user enters: entering it switches on exactly what its archive lists (MCP servers, scene-level MCP note overrides, skills, personas, quick prompts, and the model tool table when a scheme is bound) and everything else off. Creates it if absent, else updates it. An archive section you give replaces that section whole — include what should stay; the receipt reports what got displaced. Saving does not enter it; entering is a separate action. Only on the user\'s instruction.',
383
+ description: 'Save a scene — a named bundle the user enters: entering switches on exactly what its archive lists (MCP servers, scene-level MCP note overrides, skills, personas, quick prompts, and the bound tool-table scheme) and everything else off. Creates it if absent. Omitted fields keep their values. An archive section you give replaces that section whole — include what should stay; the receipt reports what got displaced. Saving does not enter it. Only on the user\'s instruction.',
301
384
  parameters: {
302
385
  scene: { type: 'string', required: true, description: 'Scene name (one path segment, ≤64 chars, no / \\ or < > : " | ? *, not `_shared`). Created if absent.' },
303
- label: { type: 'string', description: 'Display name for this scene. Omit = keep.' },
304
- description: { type: 'string', description: 'What this scene is for; shown beside the scene name in the "Current scene" reminder while the scene is on — write an instruction, not a note. Omit = keep.' },
305
- // 与下面 `mcp` / `skills` / `subagents` 同一句式("Omit = keep; X = 一个都不"):
386
+ label: { type: 'string', description: 'Display name for this scene.' },
387
+ description: { type: 'string', description: 'What this scene is for — write an instruction, not a note; it shows beside the scene name while the scene is on.' },
388
+ // 与下面 `mcp` / `skills` / `subagents` 同一句式("X = 一个都不"):
306
389
  // 界面 2026-10-10 补了「无」这个选项,工具侧的空串语义要跟着说清,否则模型只知道
307
390
  // 「省略 = 保持」,不知道还有一条「解绑」的路。
308
- prompt: { type: 'string', description: 'Prompt preset id to bind; while this scene is on it is the global baseline. Omit = keep; \'\' = bind none (this scene leaves AGENTS.md alone).' },
391
+ prompt: { type: 'string', description: 'Prompt preset id to bind; while this scene is on it is the global baseline. \'\' = bind none (this scene leaves AGENTS.md alone).' },
309
392
  // 模型工具表方案绑定(0.20.0 补上模型侧入口:0.15.0 起界面可绑、档案里一直有这一栏,
310
393
  // `_list` / `_switch` 也读它,唯独 `_save` 写不了)。'' = 解绑只能走
311
394
  // `rules-update-scene` —— `scene-archive-save` 对载荷里**不带的栏**一律保留现值
312
395
  // (archive-engine 的「不带 ≠ 解绑」),所以解绑与设置分成两条路,见 execute 的 ②。
313
396
  // 哨兵 `factory-default` 与界面下拉同值(tools/table.ts 的 FACTORY_TOOL_TABLE_PRESET);
314
397
  // 不存在的方案名由引擎按 stale 丢弃并在进入时报告,op 不硬拒(与悬空绑定同口径)。
315
- toolTablePreset: { type: 'string', description: "Model tool-table scheme to bind while this scene is on. Omit = keep; '' = unbind (the scene leaves the tool table alone); 'factory-default' = the factory default; otherwise the name of a scheme saved in the panel. An unknown name is dropped and reported." },
398
+ toolTablePreset: { type: 'string', description: "Model tool-table scheme to bind while this scene is on. '' = unbind; 'factory-default' = the factory default; otherwise a saved scheme name. An unknown name is dropped and reported." },
316
399
  // 快捷提示词绑定(0.20.0)。段语义与上面三个档案段相反:**空数组是合法值**
317
400
  // (进入后全部停用),不是"清除这一段"。本工具不提供解绑(界面可解)—— 与
318
401
  // mcp / skills / subagents 三段没有解绑参数同一条口径。id 从场景清单里别的场景的
319
402
  // 绑定、或用户口述里来;不存在的 id 被引擎丢弃并在回执报出来。
320
- quickPrompts: { type: 'array', items: { type: 'string' }, description: 'Quick-prompt ids to switch on when this scene is entered; every other one is switched off, and the pre-entry state is restored on exit. Omit = keep; [] = switch all off on entry. Unknown ids are dropped and reported — copy them from a scene binding in the listing, or ask the user.' },
403
+ quickPrompts: { type: 'array', items: { type: 'string' }, description: 'Quick-prompt ids to switch on when this scene is entered; every other one goes off, and the pre-entry state is restored on exit. [] = all off on entry. Unknown ids are dropped and reported — copy them from the listing.' },
321
404
  mcp: {
322
405
  type: 'object',
323
406
  // 官方要求对象类型**显式声明开放性**(`additionalProperties` 是必需字段,且只能是
324
407
  // boolean)—— 嵌套对象不允许带 schema,所以值的形状(`'*'` 还是工具名数组)只能在
325
408
  // 描述里说清。这不是偷懒:键是服务器名,本身是动态的。
326
409
  additionalProperties: true,
327
- description: "Archive: serverName -> '*' (whole server) or a list of tool names to leave on. Omit = keep; {} = switch none on.",
410
+ description: "Archive: serverName -> '*' (whole server) or a list of tool names to leave on. {} = switch none on.",
328
411
  },
329
412
  // 场景级 MCP 备注覆盖(0.20.0):进入这个场景时用这份盖掉全局备注,退出时还原。
330
413
  // 与 mcp 段同一句式(省略 = 保持;{} = 一个都不覆盖)—— 界面存档编辑器早就能改,
@@ -332,16 +415,20 @@ export function buildSceneTools(deps) {
332
415
  mcpNotes: {
333
416
  type: 'object',
334
417
  additionalProperties: true,
335
- description: "Archive: serverName -> note that overrides that server's global note while this scene is on (the global note comes back on exit). Omit = keep; {} = drop every scene-level override.",
418
+ description: "Archive: serverName -> note overriding that server's global note while this scene is on (back on exit). {} = drop all scene-level overrides.",
336
419
  },
337
- skills: { type: 'array', items: { type: 'string' }, description: 'Archive: skill keys `<root>/<name>` to switch on. Omit = keep; [] = switch none on.' },
338
- subagents: { type: 'array', items: { type: 'string' }, description: 'Archive: persona names to switch on. Omit = keep; [] = switch none on.' },
420
+ skills: { type: 'array', items: { type: 'string' }, description: 'Archive: skill keys `<root>/<name>` to switch on. [] = switch none on.' },
421
+ subagents: { type: 'array', items: { type: 'string' }, description: 'Archive: persona names to switch on. [] = switch none on.' },
422
+ // 0.21.2:场景记录与档案是**机器级**的,没有「本会话的一份」。这个参数只为一件事:
423
+ // 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
424
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('the scene record and archive are machine-wide', 'entering a scene for one conversation is a switch action') },
339
425
  },
340
426
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
341
- async execute(args) {
427
+ async execute(args, exec) {
342
428
  const blocked = await deps.lockedSceneGuard();
343
429
  if (blocked)
344
430
  throw new Error(blocked);
431
+ requireGlobalScope(args, 'scenes', !sessionLayerOn(deps));
345
432
  const scene = String((args && args.scene) || '').trim();
346
433
  if (scene === '')
347
434
  throw new Error('missing argument: scene (the scene name)');
@@ -498,7 +585,14 @@ export function buildSceneTools(deps) {
498
585
  const enterHint = deps.toolVisible('scene_manager_switch')
499
586
  ? 'To take effect, enter it with scene_manager_switch.'
500
587
  : 'To take effect, the user has to enter this scene manually (scene_manager_switch is not available in this session).';
501
- return 'OK: scene "' + scene + '"' + parts.join('; ') + warnTail + clearWarn +
588
+ // 会话层(0.21.2):场景记录与档案是**机器级**的(一份索引 + 一份档案),本会话能改的
589
+ // 只有「这个对话用哪个场景」。不说清的话,模型会把「存好了」读成「只在这个对话里生效」。
590
+ const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
591
+ const globalNote = pinned === undefined
592
+ ? ''
593
+ : '\nnote: scenes are global (one record and one archive for the whole machine). This conversation only pins which scene it uses' +
594
+ ' (currently "' + pinned + '"); other conversations keep theirs.';
595
+ return 'OK: scene "' + scene + '"' + parts.join('; ') + warnTail + clearWarn + globalNote +
502
596
  (collapsed
503
597
  ? '\nnote: every scene was enabled until now (the historical all-enabled default); this call narrowed the enabled set to one scene, and the new one is not it — the user should confirm the enabled state.'
504
598
  : '') +