dsh-plugin-tool-management 0.21.3 → 0.21.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,134 @@
1
+ // 按**这一次调用的参数**决定要不要弹确认卡。
2
+ //
3
+ // 与 `index.ts` 的 `CONFIRM_LABELS` 分工:那张表回答"这条工具要不要门",这里回答"这一次
4
+ // 要不要门"。必须分开,因为同一个工具不同 action 的危险度差得远:
5
+ //
6
+ // · `*_remove` 的 `list` 是读、`restore` 是恢复,只有 `trash` 是删除;
7
+ // · `mcp_manager_switch` 的 `restart` 是服务器挂掉时的恢复路径(场景锁都为它开口),
8
+ // `stop` 才是机器级停机;
9
+ // · `prompt_manager_apply` 的 `apply: false` 是撤销,不是改写。
10
+ //
11
+ // 一律按工具名挂卡会把恢复路径一起堵住 —— 出事时用户反而要多点一次确认。
12
+ //
13
+ // 另一半判据是**作用域**:几个 `_switch` 默认写本会话(爆炸半径小),只有显式
14
+ // `scope: "global"` 或在全局粒度下才变成机器级。给默认路径也挂卡是纯摩擦。
15
+ //
16
+ // 本模块保持纯函数:不读磁盘、不看会话、不抛错。参数不成立(缺 id / 不是布尔)时返回
17
+ // `null` 让工具自己报错 —— 给一次注定失败的调用弹卡只会产生无效审批。
18
+ /**
19
+ * 需要按参数判定的工具名。
20
+ *
21
+ * 不在这张表里的工具仍走 `CONFIRM_LABELS` 的既有分支(无条件问,或按设置开关问)。
22
+ */
23
+ export const ARG_CONDITIONAL_CONFIRM_TOOLS = new Set([
24
+ 'memory_manager_remove',
25
+ 'skill_manager_remove',
26
+ 'subagent_manager_remove',
27
+ 'scene_manager_remove',
28
+ 'prompt_manager_remove',
29
+ 'prompt_manager_apply',
30
+ 'mcp_manager_switch',
31
+ 'memory_manager_switch',
32
+ 'skill_manager_switch',
33
+ 'subagent_manager_switch',
34
+ ]);
35
+ /** 取一个必填字符串参数;不是非空字符串就返回空串。 */
36
+ function text(value) {
37
+ return typeof value === 'string' ? value.trim() : '';
38
+ }
39
+ /** 这次写入是不是落在机器级:显式 `scope: "global"`,或全局粒度下没有会话层。 */
40
+ function machineWide(args, mode) {
41
+ return mode === 'global' || args.scope === 'global';
42
+ }
43
+ /** 开关类回执里的目标名词,避免每个分支各拼一遍。 */
44
+ function removeSubject(name) {
45
+ if (name === 'memory_manager_remove')
46
+ return 'memory';
47
+ if (name === 'skill_manager_remove')
48
+ return 'skill';
49
+ if (name === 'subagent_manager_remove')
50
+ return 'persona';
51
+ if (name === 'scene_manager_remove')
52
+ return 'scene';
53
+ return 'AGENTS.md preset';
54
+ }
55
+ /**
56
+ * 这一次调用要不要问用户;要问就返回卡上那句理由,不问返回 `null`。
57
+ *
58
+ * @param name 工具名(大小写与注册名一致)。
59
+ * @param rawArgs 工具入参(模型给的那一份,未校验)。
60
+ * @param mode 当前隔离粒度;`global` 下所有开关写入都是机器级。
61
+ * @returns 确认卡的理由;`null` = 不拦,调用方直接 `next()`。
62
+ * @remarks
63
+ * 只有 `remove` 的 `trash`、`mcp_switch` 的 `stop` 与全局 `on`/`off`、`prompt_apply` 的
64
+ * 正向应用、以及三个 `_switch` 的机器级写入会返回理由。其余 action(`list`/`restore`/
65
+ * `restart`/`apply:false`/会话级开关)一律放行。
66
+ */
67
+ export function argConditionalConfirmReason(name, rawArgs, mode) {
68
+ const args = (rawArgs !== null && typeof rawArgs === 'object' ? rawArgs : {});
69
+ const action = text(args.action);
70
+ if (name.endsWith('_remove')) {
71
+ // 只有 trash 是删除。list 是读、restore 是恢复(与 mcp 的 restart 同一档,不该拦)。
72
+ if (action !== 'trash')
73
+ return null;
74
+ const id = text(args.id);
75
+ // 缺 id 时工具自己会拒;先弹一张卡等于让用户批准一次注定失败的删除。
76
+ if (id === '')
77
+ return null;
78
+ return `Delete ${removeSubject(name)}「${id}」 — moved to the trash, restorable from the panel.`;
79
+ }
80
+ if (name === 'prompt_manager_apply') {
81
+ // apply=false 是撤销(回到本轮应用之前),可逆,不问。
82
+ if (args.apply === false)
83
+ return null;
84
+ const id = text(args.id);
85
+ if (id === '')
86
+ return null;
87
+ return `Apply AGENTS.md preset「${id}」 — effective next turn, machine-wide. A scene-driven baseline is rebound, not overwritten.`;
88
+ }
89
+ if (name === 'mcp_manager_switch') {
90
+ const server = text(args.server);
91
+ if (server === '')
92
+ return null;
93
+ // restart 是恢复路径(服务器挂了只有它能救),场景锁都为它开口 —— 不拦。
94
+ if (action === 'restart')
95
+ return null;
96
+ if (action === 'stop') {
97
+ return `Stop MCP server「${server}」 machine-wide — every conversation still using it is disconnected.`;
98
+ }
99
+ if (action !== 'on' && action !== 'off')
100
+ return null;
101
+ if (!machineWide(args, mode))
102
+ return null;
103
+ return `Turn MCP server「${server}」 ${action} for every conversation (global switch).`;
104
+ }
105
+ if (name === 'memory_manager_switch' || name === 'subagent_manager_switch') {
106
+ if (typeof args.enabled !== 'boolean')
107
+ return null;
108
+ if (!machineWide(args, mode))
109
+ return null;
110
+ const key = name === 'memory_manager_switch' ? text(args.memory) : text(args.name);
111
+ if (key === '')
112
+ return null;
113
+ const subject = name === 'memory_manager_switch' ? 'memory' : 'persona';
114
+ return `Turn ${subject}「${key}」 ${args.enabled ? 'on' : 'off'} for every conversation (global switch).`;
115
+ }
116
+ if (name === 'skill_manager_switch') {
117
+ // prefer 也是一次机器级的持久选择,但 `enabled` 缺省时它是唯一动作。
118
+ const prefer = typeof args.prefer === 'boolean';
119
+ if (typeof args.enabled !== 'boolean' && !prefer)
120
+ return null;
121
+ if (!machineWide(args, mode))
122
+ return null;
123
+ const source = text(args.source);
124
+ const key = source !== '' ? text(args.source) : text(args.name);
125
+ const label = source !== '' ? 'source' : 'skill';
126
+ if (key === '')
127
+ return null;
128
+ if (typeof args.enabled === 'boolean') {
129
+ return `Turn ${label}「${key}」 ${args.enabled ? 'on' : 'off'} for every conversation (global switch).`;
130
+ }
131
+ return `${args.prefer ? 'Make' : 'Stop preferring'} the copy of ${label}「${key}」 win its name collision, machine-wide.`;
132
+ }
133
+ return null;
134
+ }
package/lib/index.js CHANGED
@@ -84,6 +84,7 @@ import { buildMemoryTools } from './tools/memory.js';
84
84
  import { buildRemoveTools } from './tools/remove.js';
85
85
  import { buildSceneTools } from './tools/scene.js';
86
86
  import { buildSubagentTools } from './tools/subagent.js';
87
+ import { ARG_CONDITIONAL_CONFIRM_TOOLS, argConditionalConfirmReason } from './confirm-gate.js';
87
88
  import { createScenePromptSync } from './scene-prompt-sync.js';
88
89
  import { extractExportTurns, serializeTranscript } from './exports/transcript.js';
89
90
  import { spawn } from 'node:child_process';
@@ -1252,9 +1253,9 @@ export default {
1252
1253
  }
1253
1254
  }
1254
1255
  /**
1255
- * 场景应用写全局意图:`blocked`(彻底停止)是比场景更强的用户要求,场景不得覆盖它
1256
+ * 场景应用写全局意图:`blocked`(统一关闭)是比场景更强的用户要求,场景不得覆盖它
1256
1257
  * —— 只有全局意图开关(`scope-intent-set`)能解除。不挡的话,进一次包含这台服务器 /
1257
- * 这条技能的场景,就会把「彻底停止」悄悄降级成 off,之后任何会话的租约都能把它拉起来。
1258
+ * 这条技能的场景,就会把「统一关闭」悄悄降级成 off,之后任何会话的租约都能把它拉起来。
1258
1259
  */
1259
1260
  function withSceneIntent(current, domain, key, state) {
1260
1261
  if (intentOf(current, domain, key) === 'blocked')
@@ -1341,7 +1342,7 @@ export default {
1341
1342
  // 场景模式进出一次就会改写 state.json。意图那一格同口径。
1342
1343
  const { states, shadowed, unloadable, entryNames } = await skillScan();
1343
1344
  const intentSnap = intentStore.snapshot();
1344
- /** 全局「彻底停止」的技能:场景不得覆盖(见 `withSceneIntent`),物理启停也一并跳过。 */
1345
+ /** 全局「统一关闭」的技能:场景不得覆盖(见 `withSceneIntent`),物理启停也一并跳过。 */
1345
1346
  const blocked = new Set();
1346
1347
  const planned = [];
1347
1348
  const skipped = [];
@@ -1361,13 +1362,13 @@ export default {
1361
1362
  skipped.push(`${key}(已不存在)`);
1362
1363
  continue;
1363
1364
  }
1364
- // 全局彻底停止压过场景(与 `scope-set` 拒写「开」同一条):既不改意图也不动策略表。
1365
- // 技能还要看所在来源:来源被彻底停止时,技能级开关开着也加载不到(来源闸恒生效)。
1365
+ // 全局统一关闭压过场景(与 `scope-set` 拒写「开」同一条):既不改意图也不动策略表。
1366
+ // 技能还要看所在来源:来源被统一关闭时,技能级开关开着也加载不到(来源闸恒生效)。
1366
1367
  if (intentOf(intentSnap, 'skills', key) === 'blocked' ||
1367
1368
  intentOf(intentSnap, 'skillSources', key.slice(0, i)) === 'blocked') {
1368
1369
  blocked.add(key);
1369
1370
  if (on)
1370
- skipped.push(`${key}(已在全局「彻底停止」)`);
1371
+ skipped.push(`${key}(已在全局「统一关闭」)`);
1371
1372
  continue;
1372
1373
  }
1373
1374
  const wanted = on ? 'on' : 'off';
@@ -1456,7 +1457,7 @@ export default {
1456
1457
  const prev = wanted.get(name);
1457
1458
  wanted.set(name, prev === undefined ? s.enabled : prev || s.enabled);
1458
1459
  }
1459
- // 全局「彻底停止」压过场景:不改意图、不动补丁(见 `withSceneIntent`)。
1460
+ // 全局「统一关闭」压过场景:不改意图、不动补丁(见 `withSceneIntent`)。
1460
1461
  const blocked = new Set();
1461
1462
  for (const [name, enabled] of [...wanted]) {
1462
1463
  if (intentOf(intentSnap, 'mcp', name) !== 'blocked')
@@ -1464,7 +1465,7 @@ export default {
1464
1465
  wanted.delete(name);
1465
1466
  blocked.add(name);
1466
1467
  if (enabled)
1467
- ctx.logger?.warn?.(`场景要启用 MCP 服务器「${name}」,但它已在全局「彻底停止」:已跳过`);
1468
+ ctx.logger?.warn?.(`场景要启用 MCP 服务器「${name}」,但它已在全局「统一关闭」:已跳过`);
1468
1469
  }
1469
1470
  if (wanted.size > 0) {
1470
1471
  await intentStore.mutate((current) => {
@@ -1547,14 +1548,14 @@ export default {
1547
1548
  // 与 MCP 同一条:场景引擎改的是全局定义 → 先写意图,再改来源状态(见
1548
1549
  // applyMcpServerSwitches 的注释;运行态 = 意图 ∪ 租约)。
1549
1550
  const intentSnap = intentStore.snapshot();
1550
- // 全局「彻底停止」压过场景:不改意图、不动来源状态(见 `withSceneIntent`)。
1551
+ // 全局「统一关闭」压过场景:不改意图、不动来源状态(见 `withSceneIntent`)。
1551
1552
  const blocked = new Set();
1552
1553
  for (const s of switches) {
1553
1554
  if (intentOf(intentSnap, 'skillSources', s.root) !== 'blocked')
1554
1555
  continue;
1555
1556
  blocked.add(s.root);
1556
1557
  if (s.enabled)
1557
- ctx.logger?.warn?.(`场景要启用技能来源「${s.root}」,但它已在全局「彻底停止」:已跳过`);
1558
+ ctx.logger?.warn?.(`场景要启用技能来源「${s.root}」,但它已在全局「统一关闭」:已跳过`);
1558
1559
  }
1559
1560
  if (switches.length > 0) {
1560
1561
  await intentStore.mutate((current) => {
@@ -2994,7 +2995,7 @@ export default {
2994
2995
  //
2995
2996
  // 只问**全局关着**的那些格:开着的那些本来就该显示成开着,数它没有意义,而记忆这类域
2996
2997
  // 可能有几百条键 —— 每次读面板都全扫一遍是不必要的成本。
2997
- // 键集合的口径:**意图域**只数「意图不是 on」的键(全局开着不是租约,彻底停止没有
2998
+ // 键集合的口径:**意图域**只数「意图不是 on」的键(全局开着不是租约,统一关闭没有
2998
2999
  // 租约这回事);**纯视图域**只数「全局关着」的键。两句话都只回答"这一格该不该挂徽章"。
2999
3000
  const leaseKeys = {};
3000
3001
  for (const domain of SCOPE_FLAG_DOMAINS) {
@@ -3016,12 +3017,34 @@ export default {
3016
3017
  out[key] = list.length;
3017
3018
  return out;
3018
3019
  };
3020
+ // 场景页的「全部关闭」:只数**会话层进入过场景**的未归档会话 / 工作区。全局正在用的
3021
+ // 那个场景是全局设置,不算临时运行;没有场景覆盖时连会话清单都不读。
3022
+ let sceneLeases = 0;
3023
+ const sceneLeaseCounts = Object.create(null);
3024
+ try {
3025
+ const overrides = await scopeStore.read();
3026
+ const sceneIds = Object.entries(overrides.sessions)
3027
+ .filter(([, scope]) => typeof scope.scene === 'string' && scope.scene !== '')
3028
+ .map(([id]) => id);
3029
+ if (sceneIds.length > 0) {
3030
+ const rows = await scopeSessionRows();
3031
+ const archived = new Set(rows.filter((row) => row.archived === true).map((row) => row.id));
3032
+ for (const id of sceneIds) {
3033
+ if (archived.has(id))
3034
+ continue;
3035
+ const name = String(overrides.sessions[id].scene);
3036
+ sceneLeaseCounts[name] = (sceneLeaseCounts[name] || 0) + 1;
3037
+ sceneLeases += 1;
3038
+ }
3039
+ }
3040
+ }
3041
+ catch { /* 读不到 = 没有临时场景 */ }
3019
3042
  return {
3020
3043
  scene,
3021
3044
  flags,
3022
3045
  unavailable,
3023
3046
  // 三态意图与租约计数(界面用):`flags` 把 blocked 投影成 false,分不出「关着」与
3024
- // 「彻底停止」;租约计数则是全局 off 却仍在跑的唯一解释。
3047
+ // 「统一关闭」;租约计数则是全局 off 却仍在跑的唯一解释。
3025
3048
  intent: { mcp: intentSnapshot.mcp, skillSources: intentSnapshot.skillSources, skills: intentSnapshot.skills },
3026
3049
  leases: {
3027
3050
  mcp: leaseCounts('mcp'),
@@ -3032,6 +3055,8 @@ export default {
3032
3055
  subagents: leaseCounts('subagents'),
3033
3056
  quickPrompts: leaseCounts('quickPrompts'),
3034
3057
  },
3058
+ sceneLeases,
3059
+ sceneLeaseCounts,
3035
3060
  };
3036
3061
  }
3037
3062
  /**
@@ -3425,7 +3450,7 @@ export default {
3425
3450
  const rows = rowsIn.map((row) => {
3426
3451
  const name = String((row && (row.serverName || row.id)) || '');
3427
3452
  const state = intentOf(intent, 'mcp', name);
3428
- // 全局开着(`on`)不是租约;彻底停止(`blocked`)压过一切会话层 —— 两种都不挂徽章。
3453
+ // 全局开着(`on`)不是租约;统一关闭(`blocked`)压过一切会话层 —— 两种都不挂徽章。
3429
3454
  const leaseCount = state === 'on' || state === 'blocked' || scan === null ? 0 : (scan.claims.mcp.get(name) || []).length;
3430
3455
  return {
3431
3456
  ...row,
@@ -4964,6 +4989,21 @@ export default {
4964
4989
  // —— 门禁挂在它上面即覆盖整个模型可达面。标签取中性的「保存」:改一台已有服务器
4965
4990
  // (含改 URL / 命令)与新增一台是同一档危险度,但"新增"在改分支上是句假话。
4966
4991
  mcp_manager_save: '「保存 MCP 服务器」',
4992
+ // 删除与「应用提示词」原先只有描述里的 consent 句。它们动的都是磁盘上那一份:
4993
+ // 删除进回收站可恢复,应用改写的是全局 AGENTS.md 基线 —— 与上面几条同一档,
4994
+ // 门禁不该比"往 hub 里写一个技能文件"更松。
4995
+ memory_manager_remove: '「删除记忆」',
4996
+ skill_manager_remove: '「删除技能」',
4997
+ subagent_manager_remove: '「删除人设」',
4998
+ scene_manager_remove: '「删除场景」',
4999
+ prompt_manager_remove: '「删除提示词预设」',
5000
+ prompt_manager_apply: '「应用提示词预设」',
5001
+ // 四条 switch 只在**机器级**写入时问一次(判据在 `confirm-gate.ts`)。
5002
+ // 默认写本会话,爆炸半径只有一个对话 —— 给默认路径挂卡是纯摩擦。
5003
+ mcp_manager_switch: '「MCP 服务器开关」',
5004
+ memory_manager_switch: '「记忆开关」',
5005
+ skill_manager_switch: '「技能开关」',
5006
+ subagent_manager_switch: '「人设开关」',
4967
5007
  };
4968
5008
  const bypassedByFullAccess = (exec) => {
4969
5009
  if (!isApprovalNever(ctx, exec))
@@ -4993,6 +5033,19 @@ export default {
4993
5033
  return next();
4994
5034
  if (exec.name === 'subagent_manager_run' && !(await subagentManagerRunTargetExists(exec)))
4995
5035
  return next();
5036
+ // 按参数判定的那批(删除的 trash、开关的机器级写入、提示词的正向应用):
5037
+ // 先算"这一次要不要问",不问就直接放行 —— 不能落到末尾那条 "Run a subagent" 的
5038
+ // 兜底分支上。bypass 放到判定之后:`remove list` 这类根本不问的调用不该在
5039
+ // 审计日志里留下一条"跳过了确认"。
5040
+ const confirmName = String(exec.name);
5041
+ if (ARG_CONDITIONAL_CONFIRM_TOOLS.has(confirmName)) {
5042
+ const reason = argConditionalConfirmReason(confirmName, exec.arguments, await scopeStore.mode());
5043
+ if (reason === null)
5044
+ return next();
5045
+ if (bypassedByFullAccess(exec))
5046
+ return next();
5047
+ return Promise.resolve({ kind: 'ask', reason });
5048
+ }
4996
5049
  if (bypassedByFullAccess(exec))
4997
5050
  return next();
4998
5051
  if (exec.name === 'skill_manager_save') {
@@ -81,7 +81,7 @@ export function createArchiveEngine(deps) {
81
81
  * 还原到快照(退出模式与失败回滚共用同一条路径):
82
82
  * MCP 停用表**按快照原文整体回写**——模式自己写进去的键(未勾服务器的 ['*'])必须随之消失,
83
83
  * 否则退出后用户环境仍被静默停用(比"多留一个键"严重得多);模式期间的手动改动不保留
84
- * (「退出 = 恢复 mode.snapshot」,手动改动只在「保存到场景」时回写)。
84
+ * (「退出 = 恢复 mode.snapshot」,手动改动只在「保存」时回写)。
85
85
  * 技能只写快照列出的键(这是既有批量通道的语义):模式期间新增的技能保持现状。
86
86
  * 上层两行(服务器级 / 来源级)按**全量**快照还原 —— 只回写与现状不同的行,见
87
87
  * mcpServerRowsToRestore / skillSourceRowsToRestore。
@@ -274,10 +274,14 @@ export const OP_REGISTRY = Object.freeze({
274
274
  'scope-clear': { write: true },
275
275
  // 锁开关自己不能被自己挡住,否则锁上了解不开(与 `rules-scene-lock` 同一条)。
276
276
  'scope-lock': { write: true },
277
- // 全局意图(`hub/scope-intent.json`):MCP 服务器 / 技能来源两格的**全局开关**。
277
+ // 全局意图(`hub/scope-intent.json`):MCP 服务器 / 技能 / 技能来源三格的**全局开关**。
278
278
  // 与 `mcpm-set-enabled` / `skill-source-enable` 同档:写全局定义、场景锁要冻结它。
279
279
  // 会话层的 scope-set 仍不冻结(它只写租约,不改全局)。
280
280
  'scope-intent-set': { write: true, frozen: true, syncsArchive: true },
281
+ // 「统一关闭」/「全部停止」:一次性动作(关会话 / 工作区的开关 + 写 off),不是持久意图。
282
+ // 写全局意图之外还改会话侧车,所以照全局写入口同一档冻结;不同步场景档案 ——
283
+ // 它是一次性的,不该把场景里的勾选永久改掉。
284
+ 'scope-stop-now': { write: true, frozen: true },
281
285
  // 清理 patch 备份:删磁盘文件(备份里含明文凭据副本),按写操作门禁。
282
286
  'backups-clean': { write: true },
283
287
  // ── 场景候选源(4)与内联(1)──────────────────────────────────────────────
package/lib/ops/scope.js CHANGED
@@ -31,7 +31,7 @@
31
31
  // 收进一条 op 就是第五份实现。面板改全局时照旧调各域自己的 op;模型工具要改全局也走
32
32
  // 各域自己的工具(`skill_manager_switch` 等),由那边按 `scope: "global"` 分派。
33
33
  import { PROMPT_CONTENT_MAX_BYTES, SCOPE_FLAG_DOMAINS, applyFlag, effectiveDiff, enterSceneInScope, exitSceneInScope, isFlagDomain, isEmptyScope, isKeepableScope, layerParentSnapshot, layeredFlag, normalizeSessionScope, overrideCountOf, promptOverrideOf, pruneScope, scopeForLayerSeed, withBaseline, } from '../scope/scope-overrides.js';
34
- import { isIntentDomain, normalizeIntentState } from '../scope/intent.js';
34
+ import { effectiveLayerOf, isIntentDomain, normalizeIntentState } from '../scope/intent.js';
35
35
  import { normalizePresetId } from '../prompts/preset-id.js';
36
36
  import { isWorkspaceScopeKey, scopeKeyLabel, scopeKeyOfRow, workspaceScopeKeyOf } from '../scope/workspace-key.js';
37
37
  import { workspaceBaseName } from '../sessions/path-key.js';
@@ -123,8 +123,8 @@ export function buildScopeOps(deps) {
123
123
  /**
124
124
  * 这一格落到哪些**意图**域/键上(逐工具 → 服务器;单条技能 → 自己 + 所在来源)。
125
125
  *
126
- * 用途只有两个:判断全局是不是「彻底停止」,以及回执里点名"仅为这个对话临时运行"的那一格。
127
- * 技能要**两个**都查:来源被彻底停止时,技能级策略表开着也加载不到 —— 只查自己会给出
126
+ * 用途只有两个:判断全局是不是「统一关闭」,以及回执里点名"仅为这个对话临时运行"的那一格。
127
+ * 技能要**两个**都查:来源被统一关闭时,技能级策略表开着也加载不到 —— 只查自己会给出
128
128
  * 一条"能开"的假承诺。
129
129
  */
130
130
  function intentTargetsOf(domain, key) {
@@ -420,10 +420,10 @@ export function buildScopeOps(deps) {
420
420
  entries.push({ domain: 'skillSources', key: root });
421
421
  }
422
422
  warnings = warnings.concat(reconcileWarnings(report, entries));
423
- // 全局「彻底停止」压过场景:勾中它也不会运行。不说的话用户会以为场景坏了。
423
+ // 全局「统一关闭」压过场景:勾中它也不会运行。不说的话用户会以为场景坏了。
424
424
  for (const entry of entries) {
425
425
  if (global.intent?.[entry.domain]?.[entry.key] === 'blocked') {
426
- warnings.unshift(`${intentLabel(entry.domain)}「${entry.key}」已在全局「彻底停止」:这个场景里它不会运行`);
426
+ warnings.unshift(`${intentLabel(entry.domain)}「${entry.key}」已在全局「统一关闭」:这个场景里它不会运行`);
427
427
  }
428
428
  }
429
429
  }
@@ -447,13 +447,13 @@ export function buildScopeOps(deps) {
447
447
  if (typeof (args && args.value) !== 'boolean')
448
448
  return { ok: false, error: 'value 必须是布尔值(只按传入值写入,不做"翻转"推断)' };
449
449
  const value = args.value === true;
450
- // 全局「彻底停止」压过一切会话层(显式拒绝的语义):写一条"开"只会看起来生效、
450
+ // 全局「统一关闭」压过一切会话层(显式拒绝的语义):写一条"开"只会看起来生效、
451
451
  // 实际调不到 —— 当场拒掉并给出出口(先把全局改成关闭或启用)。
452
452
  // 技能要连**所在来源**一起查:来源停了,技能级策略开着也加载不到。
453
453
  const blockedTarget = intentTargetsOf(domain, key)
454
454
  .find((target) => global.intent?.[target.domain]?.[target.key] === 'blocked');
455
455
  if (value && blockedTarget !== undefined) {
456
- return { ok: false, error: `「${blockedTarget.key}」已在全局「彻底停止」:先把全局改回关闭或启用,它才可能再运行` };
456
+ return { ok: false, error: `「${blockedTarget.key}」已在全局「统一关闭」:先把全局改回关闭或启用,它才可能再运行` };
457
457
  }
458
458
  // 下层值的**预检**(锁外、读缓存):只为快速拒绝,不是权威判定 —— 权威那一份在
459
459
  // `store.mutate` 的锁内按**重读出来的** `cur` 再算一次(见下面 `effectiveParent`)。
@@ -1028,13 +1028,14 @@ export function buildScopeOps(deps) {
1028
1028
  return { ok: false, error: '切换失败: ' + deps.message(e) };
1029
1029
  }
1030
1030
  },
1031
- // 全局意图:MCP 服务器 / 技能来源两格的**全局开关**写这里,不再直接改补丁 /
1032
- // 来源状态 —— 后者是运行态,由对账器维持成 `意图 ∪ 租约`。三态里只有 `blocked`(界面的
1033
- // 「彻底停止」)会连租约一起停;`off` 在有租约时保持连接运行,只是别的会话看不到。
1031
+ // 全局意图:MCP 服务器 / 技能(含来源)三格的**全局开关**写这里,不再直接改补丁 /
1032
+ // 来源状态 —— 后者是运行态,由对账器维持成 `意图 ∪ 租约`。
1033
+ // `blocked` 仍可读(旧版本留下的 MCP 值),新界面不再写它:「统一关闭」是一次性
1034
+ // 动作,走下面的 `scope-stop-now`。
1034
1035
  'scope-intent-set': async (args) => {
1035
1036
  const domain = String((args && args.domain) || '').trim();
1036
1037
  if (!isIntentDomain(domain))
1037
- return { ok: false, error: `未知 domain: ${domain}(可用:mcp / skillSources)` };
1038
+ return { ok: false, error: `未知 domain: ${domain}(可用:mcp / skillSources / skills)` };
1038
1039
  const raw = args && args.value;
1039
1040
  const state = normalizeIntentState(raw) ?? (raw === true ? 'on' : raw === false ? 'off' : undefined);
1040
1041
  if (state === undefined)
@@ -1064,6 +1065,108 @@ export function buildScopeOps(deps) {
1064
1065
  .map((item) => `「${item.key}」的全局意图已记下,但运行态没跟上(${item.error}):下一次对账会再试`);
1065
1066
  return { ok: true, domain, value: state, keys, ...(warnings.length > 0 ? { warnings } : {}) };
1066
1067
  },
1068
+ /**
1069
+ * 「统一关闭」/「全部关闭」:一次性停机,不留下持久的 `blocked`。
1070
+ *
1071
+ * 对布尔域:先把全局意图写成 `off`(只有 mcp / skills / skillSources 有意图),再把
1072
+ * **所有层里开着它的**会话 / 工作区写成显式关闭 —— 只写 off 不够:那些层里的 `true`
1073
+ * (或场景勾选)会在下一轮对账里成为租约,把它重新拉起来。显式 `false` 同时压过场景层,
1074
+ * 所以场景里的会话也会一起停下。memory / subagents / quickPrompts 没有运行态,清掉
1075
+ * 认领就够了。
1076
+ *
1077
+ * `scene` 没有布尔键:把每个进入过场景的会话 / 工作区退回基线(`exitSceneInScope`);
1078
+ * 带 `key` / `keys` 时只退这些场景,不带 = 页头「全部关闭」退全部。
1079
+ * 全局正在用的那个场景不动 —— 它是全局设置,不是"临时运行"。
1080
+ *
1081
+ * 归档会话不写:它已经不占资源,改它的设置只是噪音。被锁的层照写 —— 这是用户显式
1082
+ * 触发的全局停机,层锁保护的是误触,不是拒绝停机。
1083
+ */
1084
+ 'scope-stop-now': async (args) => {
1085
+ const domain = String((args && args.domain) || 'mcp').trim();
1086
+ const isFlagDomainArg = (value) => value === 'mcp' || value === 'skills' || value === 'skillSources' || value === 'memory' || value === 'subagents' || value === 'quickPrompts';
1087
+ if (domain !== 'scene' && !isFlagDomainArg(domain)) {
1088
+ return { ok: false, error: `不支持的 domain: ${domain}(可用:mcp / skills / skillSources / memory / subagents / quickPrompts / scene)` };
1089
+ }
1090
+ let archived = new Set();
1091
+ try {
1092
+ archived = new Set((await deps.sessions()).filter((row) => row.archived === true).map((row) => row.id));
1093
+ }
1094
+ catch { /* 清单读不到:不按归档过滤,宁可多关几格 */ }
1095
+ if (domain === 'scene') {
1096
+ // 不带 key = 页头的「全部关闭」;带 key = 某一张场景卡菜单里的「统一关闭」。
1097
+ const rawScenes = Array.isArray(args && args.keys)
1098
+ ? args.keys
1099
+ : (args && args.key !== undefined ? [args.key] : []);
1100
+ const sceneNames = new Set(rawScenes.map((key) => String(key)).filter((key) => key !== ''));
1101
+ for (const key of sceneNames) {
1102
+ if (key === '__proto__' || key.length > 256 || /[\u0000-\u001f\u007f]/.test(key))
1103
+ return { ok: false, error: '非法 key: ' + key };
1104
+ }
1105
+ const res = await deps.store.mutateAll((scope, sessionId) => {
1106
+ if (archived.has(sessionId) || typeof scope.scene !== 'string' || scope.scene === '')
1107
+ return scope;
1108
+ if (sceneNames.size > 0 && !sceneNames.has(scope.scene))
1109
+ return scope;
1110
+ return exitSceneInScope(scope).scope;
1111
+ });
1112
+ if (!res.ok)
1113
+ return { ok: false, error: '退出场景失败: ' + res.error };
1114
+ if (res.changed > 0)
1115
+ deps.onChanged?.('', 'scene');
1116
+ if (deps.reconcile !== undefined)
1117
+ await deps.reconcile().catch(() => undefined);
1118
+ return { ok: true, domain, cleared: res.changed, ...(sceneNames.size > 0 ? { keys: [...sceneNames] } : {}) };
1119
+ }
1120
+ const rawList = Array.isArray(args && args.keys)
1121
+ ? args.keys
1122
+ : (args && args.key !== undefined ? [args.key] : []);
1123
+ const keys = [...new Set(rawList.map((key) => String(key)).filter((key) => key !== ''))];
1124
+ if (keys.length === 0)
1125
+ return { ok: false, error: '缺少 key(或 keys)' };
1126
+ if (keys.length > 512)
1127
+ return { ok: false, error: '一次最多改 512 项' };
1128
+ for (const key of keys) {
1129
+ if (key === '__proto__' || key.length > 256 || /[\u0000-\u001f\u007f]/.test(key))
1130
+ return { ok: false, error: '非法 key: ' + key };
1131
+ }
1132
+ const runtime = domain === 'mcp' || domain === 'skills' || domain === 'skillSources';
1133
+ if (runtime) {
1134
+ if (deps.writeIntent === undefined)
1135
+ return { ok: false, error: '当前环境不支持全局意图写入' };
1136
+ const error = await deps.writeIntent(domain, keys, 'off');
1137
+ if (error !== null)
1138
+ return { ok: false, error: '写入失败: ' + error };
1139
+ }
1140
+ const cleared = Object.create(null);
1141
+ const res = await deps.store.mutateAll((scope, sessionId) => {
1142
+ if (archived.has(sessionId))
1143
+ return scope;
1144
+ const archive = scope.scene !== undefined ? deps.sceneArchiveOf?.(scope.scene) : undefined;
1145
+ const table = scope[domain];
1146
+ let next = table;
1147
+ for (const key of keys) {
1148
+ if (effectiveLayerOf(scope, archive, domain, key) !== true)
1149
+ continue;
1150
+ if (next === undefined)
1151
+ next = {};
1152
+ else if (next === table)
1153
+ next = Object.assign({}, next);
1154
+ next[key] = false;
1155
+ cleared[key] = (cleared[key] || 0) + 1;
1156
+ }
1157
+ return next === table ? scope : Object.assign({}, scope, { [domain]: next });
1158
+ });
1159
+ if (!res.ok)
1160
+ return { ok: false, error: '关闭会话开关失败: ' + res.error };
1161
+ if (res.changed > 0)
1162
+ deps.onChanged?.('', domain);
1163
+ const report = runtime && deps.reconcile !== undefined ? await deps.reconcile().catch(() => undefined) : undefined;
1164
+ const keySet = new Set(keys);
1165
+ const warnings = (report === undefined ? [] : report.failed)
1166
+ .filter((item) => item.domain === domain && keySet.has(item.key))
1167
+ .map((item) => `「${item.key}」已记录为关闭,但运行态没跟上(${item.error}):下一次对账会再试`);
1168
+ return { ok: true, domain, keys, cleared, ...(warnings.length > 0 ? { warnings } : {}) };
1169
+ },
1067
1170
  // 锁 / 解锁:与 `rules-scene-lock` 同一条 —— 它自己不能被锁挡住,否则锁上就解不开。
1068
1171
  'scope-lock': async (args) => {
1069
1172
  const rawId = String((args && args.sessionId) || '').trim();
@@ -16,8 +16,9 @@
16
16
  // 删除 / 归档 / 场景改档案这几条路径分叉。
17
17
  //
18
18
  // 用户要求「仍按租约运行」:全局 off + 有租约 → 连接保持运行,但只有认领的
19
- // 会话看得到它;未认领的会话(含新会话)一律按 off。`blocked`(界面上的「彻底停止」)是
20
- // 唯一的立即停机路径:显式拒绝,压过租约与一切会话层。
19
+ // 会话看得到它;未认领的会话(含新会话)一律按 off。`blocked` 是显式拒绝,压过租约与
20
+ // 一切会话层;新界面不再写它 —— MCP 的「统一关闭」已改为一次性动作(先写 off 再清掉
21
+ // 各层认领),读侧仍认这个值,保证升级前留下的记录照旧生效。
21
22
  //
22
23
  // ## 为什么只有这三格有意图
23
24
  //
@@ -95,9 +96,9 @@ export function withIntent(intent, domain, keys, state) {
95
96
  * 一台服务器 / 一个来源在某个会话里的可见性。`lower` 是会话的那三层
96
97
  * (覆盖 → 场景层 → 基线)的并值,`undefined` = 三层都没话说。
97
98
  *
98
- * 优先级:`blocked`(全局彻底停止)> 会话层 > `on` / `off` > 运行态。
99
- * blocked 压过会话层是"彻底停止"的定义:否则一个还留着 `mcp[x]=true` 的会话就能把它复活,
100
- * 用户点了「彻底停止」却还看得见工具,那一步就没有出口了。
99
+ * 优先级:`blocked`(显式拒绝)> 会话层 > `on` / `off` > 运行态。
100
+ * blocked 压过会话层是它的定义:否则一个还留着 `mcp[x]=true` 的会话就能把它复活,
101
+ * 那一步就没有出口了。
101
102
  */
102
103
  export function resolveResource(intent, lower) {
103
104
  if (intent === 'blocked')
@@ -80,7 +80,7 @@ export function defineSubagentManagerListTool(subagents) {
80
80
  name: 'subagent_manager_list',
81
81
  // `depth-filtered` 删掉:注入深度是**注入侧**的实现细节
82
82
  // 模型看到的是"目录里有哪些人设",`catalogDepth` 那个词对它没有任何可操作性。
83
- description: 'List personas (pre-configured subagent profiles) with their descriptions. The "Current subagents" reminder carries a view of the same catalog; call this for the always-current full list, or all=true to include disabled personas and ones outside the active scene.',
83
+ description: 'List personas (pre-configured subagent profiles) with descriptions and the file holding each body (read it with your file tools). The "Current subagents" reminder carries a view of the same catalog; call this for the always-current full list, or all=true to include disabled personas and ones outside the active scene.',
84
84
  parameters: {
85
85
  all: { type: 'boolean', description: 'Include disabled personas and ones outside the active scene (default false). Listed ≠ delegable: `run` still refuses those.' },
86
86
  },
@@ -109,9 +109,18 @@ export function defineSubagentManagerListTool(subagents) {
109
109
  // 而工具又不列全,结果是"明明能委派却查不到人设"。
110
110
  // `all=true` 时**标出哪些不可用**:只列名字的话,模型照样分不清哪个能直接委派
111
111
  // (与技能列表标 `shadowed-by:` 同一条理由 —— 列出来不等于能用)。
112
+ // 每行带**正文文件路径**。这个域刻意没有 `subagent_manager_read`(正文是文件,不是
113
+ // 另一份存储),但模型手里有通用文件工具 —— 不给路径,用户说「读一下这个人设的完整
114
+ // 定义」时它只能回「做不到」。清单本来只有 description,正文在 `PersonaDoc.path`
115
+ // (`service.ts` 扫目录时一起记下的绝对路径),这里原样带出去,零额外读取。
116
+ //
117
+ // 放在行尾而不是表头给一个目录模板:模型拼 `<dir>/<name>.md` 要多一步推理,路径里
118
+ // 有空格或非 ASCII 目录名时还可能拼错;每条一个完整路径是零歧义,代价只在调用时付
119
+ // (不是每轮的 schema 成本)。
112
120
  const lines = allowed.map((p) => '- ' + p.name + ' — ' + (p.description || '(no description)') +
113
121
  (p.continuable === true ? CONTINUABLE_MARK : '') +
114
- (includeUnavailable ? (!decideInSession(p, flag, boundSet) ? ' (disabled — turn it on first)' : '') : ''));
122
+ (includeUnavailable ? (!decideInSession(p, flag, boundSet) ? ' (disabled — turn it on first)' : '') : '') +
123
+ (p.path ? ' · ' + p.path : ''));
115
124
  // 默认口径下有多少个没列出来(停用的 + 不在启用场景里的):不报的话,模型看到一份短名单
116
125
  // 会当成"本机只有这些人设"。数量照报,与另外三个 list 的表头同一口径。
117
126
  const hiddenCount = includeUnavailable ? 0 : docs.length - allowed.length;