dsh-plugin-tool-management 0.22.0 → 0.22.1

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.
@@ -2,8 +2,9 @@
2
2
  // `scripts/doctor.mjs` 都要读它们,所以只有这一份。
3
3
  //
4
4
  // 为什么单独一层:这些包**不在**本插件的 `peerDependencies` 里 —— 宿主不要求插件依赖它们,
5
- // 但插件在运行时按**裸模块名**直接 require(MCP 客户端、人设、全局指令、技能目录)。它们有
6
- // 两个共同点让它们必须被看见:
5
+ // 但插件要么在运行时按**裸模块名**直接 require(MCP 客户端、人设、全局指令、技能目录),
6
+ // 要么把它们的**标识符**写死在自己代码里(共享资源工具的三个名字)。它们有两个共同点让
7
+ // 它们必须被看见:
7
8
  // (1) 官方改名或撤掉其中一个,对应功能**静默降级**(不抛错,只是少一半);
8
9
  // (2) 它们不参与模块身份比对(不是硬依赖),所以"两份不同拷贝"那一栏根本看不到它们。
9
10
  //
@@ -26,10 +27,13 @@ export const AGENTS_MD_REFRESH_MARKERS = [
26
27
  { needle: 'sameInstructionChange', why: '按 {action, scope, path, digest} 判「有没有变化」' },
27
28
  ];
28
29
  /**
29
- * 运行时按**裸模块名** require 的宿主包,以及每个包守着的契约。
30
+ * 运行时依赖的宿主包,以及每个包守着的契约。
30
31
  *
31
32
  * 与 `AGENTS_MD_REFRESH_MARKERS` 的分工:那一份是"同一个包内的若干标识符",这一份是
32
33
  * "若干不同的包各要求什么"。合起来才是"官方撤掉了什么"的完整清单。
34
+ *
35
+ * 条目有两种:插件**按裸模块名 require** 的那几个(`markers` 多半为空),以及插件把它的
36
+ * **标识符写死在自己代码里**的那几个 —— 后者靠 `markers` 里的 canary 盯住名字漂移。
33
37
  */
34
38
  export const BARE_HOST_MODULE_CONTRACTS = [
35
39
  {
@@ -37,6 +41,15 @@ export const BARE_HOST_MODULE_CONTRACTS = [
37
41
  feature: 'MCP 客户端(MCP 服务器装配的宿主出口)',
38
42
  markers: [],
39
43
  },
44
+ {
45
+ package: '@deepseek-ai/dsh-mcp-resources',
46
+ feature: 'MCP 共享资源工具(官方那三个资源工具的宿主出口)',
47
+ markers: [
48
+ { needle: 'list_mcp_resources', why: '共享资源工具的名字(插件的逐会话可见性摘除与执行侧守卫按这三个名字认它)' },
49
+ { needle: 'list_mcp_resource_templates', why: '同上(三个共享资源工具之一)' },
50
+ { needle: 'read_mcp_resource', why: '同上(三个共享资源工具之一)' },
51
+ ],
52
+ },
40
53
  {
41
54
  package: '@deepseek-ai/dsh-persona',
42
55
  feature: '人设(子代理人格的读取与解析)',
package/lib/host-names.js CHANGED
@@ -22,6 +22,24 @@ export const MCP_CLIENT_MODULE = '@deepseek-ai/dsh-mcp-client';
22
22
  * 只能靠宿主升级清单人工核对。真要靠探测兜住,得先有官方暴露工具归属的接口。
23
23
  */
24
24
  export const MCP_TOOL_PREFIX = 'mcp__';
25
+ /**
26
+ * 官方**共享资源工具**的三个名字(`@deepseek-ai/dsh-mcp-resources` 注册)。
27
+ *
28
+ * 这三个工具是所有已配置 MCP 服务器**共享的一套**:作用域里第一个 provider 注册时整体
29
+ * 注册,最后一个移除才整体注销 —— 没有「一台服务器一个工具」的粒度。
30
+ *
31
+ * 它们注册在**全局** tools 层:补丁里的 mcp-client 实例挂在根作用域 ⇒ provider 进全局层
32
+ * ⇒ 工具注册到全局 tools 层。于是:
33
+ * · 每个 agent 作用域都看得见 —— 别的会话开了 MCP,这台机器上每个会话都会多出这三个工具;
34
+ * · 它们在官方 `tools.restrict()` 的 `restrictableNames` 里(全局工具可被摘),插件能逐会话摘掉;
35
+ * · 官方 `mcpResources.request()` 按「全局层 + 作用域链」解析服务器 ⇒ 按 server 分的粒度
36
+ * 官方管不了,只能由插件的执行侧守卫守。
37
+ */
38
+ export const MCP_RESOURCE_TOOL_NAMES = ['list_mcp_resources', 'list_mcp_resource_templates', 'read_mcp_resource'];
39
+ /** 是不是官方那三个共享资源工具。 */
40
+ export function isMcpResourceTool(name) {
41
+ return MCP_RESOURCE_TOOL_NAMES.includes(String(name == null ? '' : name));
42
+ }
25
43
  /**
26
44
  * 一个工具名算不算「MCP 前缀漂移」的**证据**:以 `mcp` 开头,但词根后面**不是** `_`。
27
45
  *
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ import { renameWithRetry, resolveDshHome, trashRootPath } from './skills/core.js
17
17
  import { createPromptsService } from './prompts/service.js';
18
18
  import { createQuickPromptsService } from './prompts/quick-service.js';
19
19
  import { isInsideRootResolved } from './paths.js';
20
- import { DEFAULT_PROFILE_NAME, MCP_TOOL_PREFIX, PROFILE_CANDIDATES, serverNameCandidates, splitMcpToolName } from './host-names.js';
20
+ import { DEFAULT_PROFILE_NAME, MCP_RESOURCE_TOOL_NAMES, MCP_TOOL_PREFIX, PROFILE_CANDIDATES, isMcpResourceTool, serverNameCandidates, splitMcpToolName } from './host-names.js';
21
21
  import { createMemoriesService } from './memories/service.js';
22
22
  import { createArchiveEngine } from './memories/archive-engine.js';
23
23
  import { createSnapshotOps } from './ops/snapshot.js';
@@ -64,9 +64,9 @@ import { buildTrashRetentionOps } from './ops/trash-retention.js';
64
64
  // 会话作用域:侧车 scope-overrides.json / scope-intent.json + 作用域 op + 启动对账。
65
65
  import { rememberSessionCwd, scopeKeyOfAgent, scopeKeyOfIdSync, sessionIdentityOf, sessionIdOf, sessionScopeIdOf } from './scope/resolve.js';
66
66
  import { createScopeStore } from './scope/store.js';
67
- import { isWorkspaceScopeKey, scopeKeyLabel } from './scope/workspace-key.js';
67
+ import { isWorkspaceScopeKey, scopeKeyLabel, workspaceCwdOfScopeKey } from './scope/workspace-key.js';
68
68
  import { createIntentStore } from './scope/intent-store.js';
69
- import { effectiveLayerOf, intentOf, isIntentDomain, planReconcile, pruneIntentKeys, resolveResource, scanSessionClaims, withIntent, } from './scope/intent.js';
69
+ import { effectiveLayerOf, intentOf, isIntentDomain, leaseSessionDetails, leaseSourceDetails, planReconcile, pruneIntentKeys, resolveResource, scanSessionClaims, withIntent, } from './scope/intent.js';
70
70
  import { SCOPE_FLAG_DOMAINS, clampPromptBaseline, hasPromptOverride, mcpToolServerSegments, promptBaselineOf, promptOverrideOf, removeSceneInScope, renameSceneInScope, sessionScenePinOf, sessionToolTableHidden, setSceneToolTableInScope, withBaseline, } from './scope/scope-overrides.js';
71
71
  import { promptBaselineDiffers } from './memories/prompt-layer.js';
72
72
  // 回收站保留期:侧车 `hub/trash-retention.json` + 六类回收站的到期清扫。
@@ -867,6 +867,134 @@ export default {
867
867
  return undefined;
868
868
  return mcpVerdictOf(ctx, parts);
869
869
  }
870
+ /**
871
+ * MCP 服务器名册的短 TTL 快照(**与 agent 无关** —— 只有「可见性过滤」才逐 agent)。
872
+ *
873
+ * 为什么缓存:名册 = 两份补丁读盘 + 一次 loader 清单,而可见性那一层每个 agent 每个
874
+ * 重排轮次都要算一遍 —— 不缓存就是「agent 数 × 轮次」次读盘。
875
+ *
876
+ * TTL 取 3 秒,与侧车 TTL 同量级(服务器增删是罕见事件)。**陈旧的后果要说明白**:
877
+ * 刚加的服务器晚 3 秒才进名册,这段时间名册缺它 —— 若名册里别的服务器在本会话都看不见,
878
+ * 就会走到「一台都看不见」那一支;判据⑤会在新服务器**有工具**时拦下(全局工具表里已经有
879
+ * 它的 `mcp__*`),只有无工具的服务器才会真被摘掉。恢复要等「TTL 到期后的下一次重排」
880
+ * —— 重排本身会触发,但 TTL 没到期时它重算的还是陈旧名册。
881
+ */
882
+ let configuredServerStatesCache = null;
883
+ const CONFIGURED_SERVER_STATES_TTL_MS = 3000;
884
+ async function configuredServerStatesCached() {
885
+ const now = Date.now();
886
+ const cached = configuredServerStatesCache;
887
+ if (cached !== null && now - cached.at < CONFIGURED_SERVER_STATES_TTL_MS)
888
+ return cached.value;
889
+ const value = await mcp.configuredServerStatesDetailed();
890
+ configuredServerStatesCache = { at: now, value };
891
+ return value;
892
+ }
893
+ /**
894
+ * 本作用域**看得见的** MCP 服务器名,名册里的全部名字,以及「名册读全了没有」。
895
+ *
896
+ * `visible` = 看得见的那些(与状态段 / `mcp_manager_list` 同一份判据)。
897
+ * `names` = 名册里的全部名字(看得见 + 看不见)。
898
+ * `complete` = 名册读全了没有:任一层读不动它就只少几条,返回值上与「名册本来就短」
899
+ * 同形(读错误在 `configuredServerStates` 内部被吞成「跳过这一层」)。
900
+ *
901
+ * 可见性为 undefined(意图还没落盘、会话层也没话说)时按运行态兜底 —— 当它看得见。
902
+ */
903
+ async function visibleMcpServerNames(agent) {
904
+ let roster;
905
+ try {
906
+ roster = await configuredServerStatesCached();
907
+ }
908
+ catch {
909
+ return null;
910
+ }
911
+ if (!roster || !Array.isArray(roster.states))
912
+ return null;
913
+ const names = new Set();
914
+ const visible = [];
915
+ for (const row of roster.states) {
916
+ const name = String((row && row.serverName) || '');
917
+ if (!name)
918
+ continue;
919
+ names.add(name);
920
+ if (sessionServerHiddenOf(agent, name))
921
+ continue;
922
+ visible.push(name);
923
+ }
924
+ return { visible, names, complete: roster.complete };
925
+ }
926
+ /**
927
+ * 名册是不是**漏了**某台正在跑的服务器。
928
+ *
929
+ * 名册来自补丁与 loader 清单,任何一层出问题它都会少几条:读错误被吞成「跳过这一层」,
930
+ * 手写补丁也可能被插件那个容错行解析器整条丢掉(它只认自己写出的缩进,见 patch-yaml.ts)。
931
+ * 名册缺项的后果是「明明在跑的服务器被当成不存在」⇒ 把还能用的资源工具摘掉。
932
+ *
933
+ * 判据:全局工具表里有 `mcp__<server>__<tool>`,而 `<server>` 既不在名册里、名册里也没有
934
+ * `mcp-<server>` 这条(插件自己写的补丁条目 id 就是 `mcp-<serverName>`)—— 那这台服务器
935
+ * 确实在跑,却没进名册。切分取**第一个** `__`(宿主解析 MCP 工具名的口径;展示侧取最后
936
+ * 一个,这里要的是宿主那个)。
937
+ *
938
+ * 读不到工具表时当成缺项:判错方向要选「不摘」那一侧。
939
+ */
940
+ async function rosterMissesRunningServer(names) {
941
+ try {
942
+ const schemas = await tools.schemas();
943
+ for (const s of schemas) {
944
+ const full = String((s && s.name) || '');
945
+ if (!full.startsWith(MCP_TOOL_PREFIX))
946
+ continue;
947
+ const rest = full.slice(MCP_TOOL_PREFIX.length);
948
+ const i = rest.indexOf('__');
949
+ if (i <= 0)
950
+ continue;
951
+ const server = rest.slice(0, i);
952
+ if (names.has(server) || names.has('mcp-' + server))
953
+ continue;
954
+ return true;
955
+ }
956
+ return false;
957
+ }
958
+ catch {
959
+ return true;
960
+ }
961
+ }
962
+ /**
963
+ * 本作用域要不要摘掉官方那三个共享资源工具。
964
+ *
965
+ * 判据(一条都不许反):
966
+ * · 这三个名字**此刻注册着** —— 官方只在作用域里出现第一个 provider 时才注册它们。
967
+ * 把没注册的名字塞进 `tools.restrict({ deny })` 会让官方抛 "unknown global tool",
968
+ * **整份 deny 名单一起失效**(停用工具会静默复活)。
969
+ * · 名册**读全了**且**没漏掉正在跑的服务器** —— 名册缺项时按它下判断,会把明明在跑的
970
+ * 服务器当成不存在,于是摘掉模型还在用的能力。
971
+ * · 本作用域**一台服务器都看不见** —— 此时这三个工具在本作用域没有任何正当用途:
972
+ * 官方 `mcpResources.request()` 按「全局层 + 作用域链」解析服务器,别的会话租约起来
973
+ * 的服务器在这里照样能列能读 —— 这正是要堵的串味通道,不是「反正调不通」。
974
+ *
975
+ * 注册与否问**全局视图**(`tools.get(name)` 不给 scope):插件自己装在 agent scope 上的
976
+ * 限制会让 `get(name, agent)` 读成「不在」—— 拿它当判据会与摘除动作自激。
977
+ */
978
+ async function resourceToolDenyFor(agent) {
979
+ try {
980
+ const registered = MCP_RESOURCE_TOOL_NAMES.filter((name) => tools.get(name) !== undefined);
981
+ if (registered.length === 0)
982
+ return [];
983
+ const roster = await visibleMcpServerNames(agent);
984
+ if (roster === null)
985
+ return [];
986
+ if (!roster.complete)
987
+ return [];
988
+ if (roster.visible.length > 0)
989
+ return [];
990
+ if (await rosterMissesRunningServer(roster.names))
991
+ return [];
992
+ return registered;
993
+ }
994
+ catch {
995
+ return [];
996
+ }
997
+ }
870
998
  /**
871
999
  * 本会话的 MCP 可见性覆盖(restrict 层用):在**此刻注册着的**工具全名上算
872
1000
  * `{ allow, deny }`(名单语义见 mcp/manager.ts 的 deps 注释)。
@@ -879,25 +1007,30 @@ export default {
879
1007
  * 全部工具(比"本会话没藏住"难看得多),而且下一轮 `tools/change` 会重算回来。
880
1008
  * 守卫那边同一条:算不出来就不拦,全局停用表 / 工具表照旧。两处同向,才不会出现
881
1009
  * 「看不见却调得动」。
1010
+ *
1011
+ * 官方那三个共享资源工具也进这一份名单(见 `resourceToolDenyFor`):它们不在
1012
+ * `mcp__` 前缀里,上面的切分认不出,但它们同样要服从「这个作用域看不看得见服务器」。
882
1013
  */
883
1014
  async function sessionMcpOverlayOf(agent) {
884
- const empty = { allow: [], deny: [] };
885
1015
  const ctx = sessionMcpContextOf(agent);
886
1016
  const intentSnapshot = intentStore.snapshot();
887
1017
  const hasGlobalFilter = Object.values(intentSnapshot.mcp).some((state) => state === 'off' || state === 'blocked');
888
1018
  const hasSessionLayer = ctx.scope !== undefined &&
889
1019
  (ctx.scope.scene !== undefined || ctx.scope.detached === true || ctx.scope.mcp !== undefined || ctx.scope.mcpTools !== undefined);
1020
+ // 官方共享资源工具的摘除**不受下面那条早退影响**:它判的是「这个作用域有没有服务器」,
1021
+ // 与会话层有没有覆盖记录无关(全局开着的一台服务器在任何会话都看得见)。
1022
+ const resourceDeny = await resourceToolDenyFor(agent);
890
1023
  if (!hasGlobalFilter && !hasSessionLayer)
891
- return empty;
1024
+ return { allow: [], deny: resourceDeny };
892
1025
  let schemas = [];
893
1026
  try {
894
1027
  schemas = await tools.schemas();
895
1028
  }
896
1029
  catch {
897
- return empty;
1030
+ return { allow: [], deny: resourceDeny };
898
1031
  }
899
1032
  if (schemas.length === 0)
900
- return empty;
1033
+ return { allow: [], deny: resourceDeny };
901
1034
  const allow = [];
902
1035
  const deny = [];
903
1036
  for (const s of schemas) {
@@ -911,7 +1044,7 @@ export default {
911
1044
  else if (verdict === 'allow')
912
1045
  allow.push(name);
913
1046
  }
914
- return { allow, deny };
1047
+ return { allow, deny: [...deny, ...resourceDeny] };
915
1048
  }
916
1049
  /**
917
1050
  * 读一次侧车 + 会话清单,按给定键集合扫一遍七域认领(`scanSessionClaims`)。
@@ -921,6 +1054,7 @@ export default {
921
1054
  * @param strict 用**严格读**取侧车(`readStrict`:文件在却读不动 / 解析不了就抛)。
922
1055
  * `readable === false` 表示没读出来,而空侧车在痕迹闸门眼里等于"这一格从没被会话动过"
923
1056
  * —— 与"宁可少采纳,不误提升"正好相反,所以调用方必须把读失败当成**处处有痕迹**处理。
1057
+ * @returns `rows` 是这一趟读到的会话清单(认领者的标题 / 工作区就从这里取)。
924
1058
  */
925
1059
  async function scanClaimsOnce(targets, strict = false) {
926
1060
  let sessions = {};
@@ -938,12 +1072,12 @@ export default {
938
1072
  rows = [];
939
1073
  }
940
1074
  try {
941
- return { scan: scanSessionClaims({ sessions, rows, mode: scopeMode(), archiveOf: sceneArchiveOfSession, targets }), readable };
1075
+ return { scan: scanSessionClaims({ sessions, rows, mode: scopeMode(), archiveOf: sceneArchiveOfSession, targets }), readable, rows };
942
1076
  }
943
1077
  catch {
944
1078
  // 装饰性读数:算不出来不该让列表 op / 面板整份失败(下一轮再算)。
945
1079
  // `readable: false` 让它与"侧车读不出来"同档 —— 对账那边必须保守(不采纳运行态)。
946
- return { scan: scanSessionClaims({ sessions: {}, rows: [], mode: scopeMode(), archiveOf: () => undefined, targets }), readable: false };
1080
+ return { scan: scanSessionClaims({ sessions: {}, rows: [], mode: scopeMode(), archiveOf: () => undefined, targets }), readable: false, rows: [] };
947
1081
  }
948
1082
  }
949
1083
  /**
@@ -3019,17 +3153,40 @@ export default {
3019
3153
  if (keys.length > 0)
3020
3154
  leaseKeys[domain] = keys;
3021
3155
  }
3022
- const { scan: leaseScan } = await scanClaimsOnce(leaseKeys);
3156
+ const { scan: leaseScan, rows: leaseRows } = await scanClaimsOnce(leaseKeys);
3023
3157
  const leaseCounts = (domain) => {
3024
3158
  const out = {};
3025
3159
  for (const [key, list] of leaseScan.claims[domain])
3026
3160
  out[key] = list.length;
3027
3161
  return out;
3028
3162
  };
3163
+ // 认领者的名单(徽章浮窗逐行显示"是哪几个对话"):与 `leaseCounts` 同一趟扫描的结果,
3164
+ // 标题 / 工作区从这一趟读到的会话清单里取 —— 清单里没有的会话(孤儿 / 作用域键占位)
3165
+ // 只留一个短 id,不编工作区名。
3166
+ const leaseRowById = new Map();
3167
+ for (const row of leaseRows)
3168
+ leaseRowById.set(row.id, row);
3169
+ const leaseDetails = {};
3170
+ for (const domain of SCOPE_FLAG_DOMAINS) {
3171
+ if (domain === 'skillSources')
3172
+ continue;
3173
+ const claims = leaseScan.claims[domain];
3174
+ if (claims.size === 0)
3175
+ continue;
3176
+ leaseDetails[domain] = leaseSessionDetails(domain, claims, leaseRowById);
3177
+ }
3178
+ // 来源格:**并集**(来源自己 + 它底下那些技能各自认领的对话)。默认来源(官方内置 /
3179
+ // DSH 技能)全局开着、租约只落在底下的技能上 —— 组头不标的话,用户只会在某一行技能
3180
+ // 上看到徽章(用户 2026-11-05 报障)。
3181
+ const sourceDetails = leaseSourceDetails(leaseScan.claims.skillSources, leaseScan.claims.skills, leaseRowById);
3182
+ if (Object.keys(sourceDetails).length > 0)
3183
+ leaseDetails.skillSources = sourceDetails;
3029
3184
  // 场景页的「全部关闭」:只数**会话层进入过场景**的未归档会话 / 工作区。全局正在用的
3030
3185
  // 那个场景是全局设置,不算临时运行;没有场景覆盖时连会话清单都不读。
3031
3186
  let sceneLeases = 0;
3032
3187
  const sceneLeaseCounts = Object.create(null);
3188
+ /** 按场景拆开的**进入者**(徽章浮窗逐行列出是哪些对话 / 工作区在这个场景里)。 */
3189
+ const sceneLeaseDetails = Object.create(null);
3033
3190
  try {
3034
3191
  const overrides = await scopeStore.read();
3035
3192
  const sceneIds = Object.entries(overrides.sessions)
@@ -3038,12 +3195,24 @@ export default {
3038
3195
  if (sceneIds.length > 0) {
3039
3196
  const rows = await scopeSessionRows();
3040
3197
  const archived = new Set(rows.filter((row) => row.archived === true).map((row) => row.id));
3198
+ const rowById = new Map(rows.map((row) => [row.id, row]));
3041
3199
  for (const id of sceneIds) {
3042
3200
  if (archived.has(id))
3043
3201
  continue;
3044
3202
  const name = String(overrides.sessions[id].scene);
3045
3203
  sceneLeaseCounts[name] = (sceneLeaseCounts[name] || 0) + 1;
3046
3204
  sceneLeases += 1;
3205
+ // 谁在这个场景里(徽章浮窗逐行列出):会话键取清单里的标题与工作区;工作区键
3206
+ // 取目录名 —— 这一层记的是**作用域**,工作区粒度下一格就是整个工作区。
3207
+ const row = rowById.get(id);
3208
+ const cwd = isWorkspaceScopeKey(id)
3209
+ ? String(workspaceCwdOfScopeKey(id) || '')
3210
+ : (row !== undefined && typeof row.cwd === 'string' ? row.cwd : '');
3211
+ const title = row !== undefined && row.title !== ''
3212
+ ? row.title
3213
+ : (cwd !== '' ? basename(cwd) : id.slice(0, 8));
3214
+ const list = sceneLeaseDetails[name] || (sceneLeaseDetails[name] = []);
3215
+ list.push({ id, title, cwd, keys: [{ domain: 'scene', key: name }] });
3047
3216
  }
3048
3217
  }
3049
3218
  }
@@ -3064,8 +3233,10 @@ export default {
3064
3233
  subagents: leaseCounts('subagents'),
3065
3234
  quickPrompts: leaseCounts('quickPrompts'),
3066
3235
  },
3236
+ leaseDetails,
3067
3237
  sceneLeases,
3068
3238
  sceneLeaseCounts,
3239
+ sceneLeaseDetails,
3069
3240
  };
3070
3241
  }
3071
3242
  /**
@@ -5340,6 +5511,27 @@ export default {
5340
5511
  ctx.effect(() => tools.guard((exec) => {
5341
5512
  const name = String((exec && exec.name) || '');
5342
5513
  const isMcpTool = name.startsWith(MCP_TOOL_PREFIX);
5514
+ // 官方那三个共享资源工具:按 `server` 参数判这台服务器在本作用域看不看得见。
5515
+ //
5516
+ // 为什么必须单独守:官方 `mcpResources.request()` 按「全局层 + 作用域链」解析服务器,
5517
+ // 而 provider 注册在**全局层** —— 所以别的会话租约起来的服务器,本会话照样能
5518
+ // 列出/读到它的资源。可见性层(restrict)管不到这个粒度(三个工具是共享的一套,
5519
+ // 摘掉就连自己看得见的服务器也读不到了)。
5520
+ //
5521
+ // 失败方向:算不出来**不拦**。与同文件里 `sessionMcpVerdictSync` 同一档:会话层是叠在
5522
+ // 全局规则之上的**视图**,读一次失手不该让模型在对话中途丢掉工具(`sessionServerHiddenOf`
5523
+ // 是纯内存读,几乎不会抛)。这与下面「停用表读不出来 ⇒ MCP 工具 fail-closed」不矛盾:
5524
+ // 那条守的是**停用表**(磁盘上的权威),这条守的是**会话层视图**(读不到就当没有覆盖)。
5525
+ if (isMcpResourceTool(name)) {
5526
+ try {
5527
+ const args = (exec && exec.arguments);
5528
+ const server = String((args && args.server) || '');
5529
+ if (server !== '' && sessionServerHiddenOf(exec && exec.agent, server)) {
5530
+ return 'MCP 服务器「' + server + '」在本对话中不可用';
5531
+ }
5532
+ }
5533
+ catch (e) { /* 算不出来 = 不拦 */ }
5534
+ }
5343
5535
  try {
5344
5536
  // unknown 必须先于会话 verdict:本会话显式开着也不能越过“停用表读不出来”。
5345
5537
  if (isMcpTool && mcp.disabledToolsState() === 'unknown') {
@@ -781,9 +781,24 @@ export function createMcpManager(deps) {
781
781
  * 全局就按「开着」算(会话层关掉它才有意义);两份都关着才是「全局关着」。
782
782
  */
783
783
  async function configuredServerStates() {
784
+ return (await configuredServerStatesDetailed()).states;
785
+ }
786
+ /**
787
+ * 同 `configuredServerStates()`,但**带一份「这次读全了没有」**。
788
+ *
789
+ * 为什么要有这个:那份名册是**按层**读的,任一层读不动,它就只少几条(读错误在内部被吞成
790
+ * 「跳过这一层」),返回值上与「名册本来就短」同形。调用方要据此回答「这台机器上还有没有
791
+ * MCP 服务器」时必须能分辨这两种 —— 按一份缺项的名册下判断,会把明明在跑的服务器当成不存在。
792
+ *
793
+ * `complete === false` = 有一层没读全(补丁某层读不动,或 loader 清单读不到)。
794
+ * 文件**不存在**不算没读全(那是常态:多数部署没有某一层的补丁;`readPatch` 对
795
+ * FS_NOT_FOUND 返回空串而不抛)。
796
+ */
797
+ async function configuredServerStatesDetailed() {
784
798
  const p = await ensurePaths();
785
799
  const merged = new Map();
786
800
  const patchIds = new Set();
801
+ let complete = true;
787
802
  for (const level of ['project', 'global']) {
788
803
  const abs = level === 'project' ? p.projectPatch : p.globalPatch;
789
804
  let content = '';
@@ -791,6 +806,7 @@ export function createMcpManager(deps) {
791
806
  content = await readPatch(abs);
792
807
  }
793
808
  catch {
809
+ complete = false;
794
810
  continue;
795
811
  }
796
812
  for (const r of parseRows(content).rows) {
@@ -819,9 +835,11 @@ export function createMcpManager(deps) {
819
835
  merged.set(name, prev === undefined ? e.enabled !== true : prev && e.enabled !== true);
820
836
  }
821
837
  }
822
- catch { /* loader 清单读不到 → 只按补丁那几台算 */ }
838
+ catch {
839
+ complete = false; /* loader 清单读不到 → 名册可能缺 loader 上挂着的那几台 */
840
+ }
823
841
  }
824
- return [...merged].map(([serverName, disabled]) => ({ serverName, disabled }));
842
+ return { states: [...merged].map(([serverName, disabled]) => ({ serverName, disabled })), complete };
825
843
  }
826
844
  /** 补丁行(只读补丁,不枚举 schema)—— 对账与场景联动的 id → serverName 映射。 */
827
845
  async function patchServerRows() {
@@ -2229,6 +2247,7 @@ export function createMcpManager(deps) {
2229
2247
  mcpmListView,
2230
2248
  configuredServerNames,
2231
2249
  configuredServerStates,
2250
+ configuredServerStatesDetailed,
2232
2251
  patchServerRows,
2233
2252
  mcpmRowsWithNotes,
2234
2253
  readPluginSettings,
@@ -104,7 +104,9 @@ export function createCandidates(deps) {
104
104
  const rows = [];
105
105
  try {
106
106
  const r = await skillsService.ops['skill-state']({});
107
- for (const root of ((r && r.data && r.data.roots) || [])) {
107
+ const roots = (r && r.data && r.data.roots) || [];
108
+ for (let rootIndex = 0; rootIndex < roots.length; rootIndex++) {
109
+ const root = roots[rootIndex];
108
110
  const rootKey = String((root && root.key) || '');
109
111
  if (!rootKey)
110
112
  continue;
@@ -122,6 +124,7 @@ export function createCandidates(deps) {
122
124
  rootLabel: String((root && root.label) || rootKey),
123
125
  ...(root && root.localeKey ? { rootLocaleKey: String(root.localeKey) } : {}),
124
126
  ...(root && root.kind ? { rootKind: String(root.kind) } : {}),
127
+ rootIndex,
125
128
  });
126
129
  }
127
130
  }
@@ -326,6 +326,82 @@ export function scanSessionClaims(input) {
326
326
  }
327
327
  return { claims, explicit, traced };
328
328
  }
329
+ /**
330
+ * 认领者名单(徽章浮窗用):键 → 那些对话(标题 + 工作区 + 落在哪几格)。
331
+ *
332
+ * 徽章只说"临时运行 · N 个对话",用户要问的是"是哪几个"—— 这一份就是答案。
333
+ * 与 `claims` 同源:个数与名单永远一致(同一批会话 id)。
334
+ *
335
+ * 清单里没有的会话(孤儿 / 清单读不到时用来占位的作用域键)只留一个短 id:
336
+ * 编不出标题与工作区时如实留空,不猜。
337
+ *
338
+ * @param claims 键 → 认领会话 id(`scanSessionClaims` 的 `claims`)。
339
+ * @param rows 会话 id → 那一行的标题与工作区目录。
340
+ * @param domain 这一格的域(写进 `keys`,界面照着它写会话层的覆盖)。
341
+ */
342
+ export function leaseSessionDetails(domain, claims, rows) {
343
+ const out = {};
344
+ for (const [key, ids] of claims) {
345
+ out[key] = ids.map((id) => ({
346
+ id,
347
+ title: leaseTitleOf(id, rows),
348
+ cwd: leaseCwdOf(id, rows),
349
+ keys: [{ domain, key }],
350
+ }));
351
+ }
352
+ return out;
353
+ }
354
+ /**
355
+ * **来源格**的认领者名单:来源自己 + 它底下那些技能各自认领的对话(**并集**)。
356
+ *
357
+ * 为什么是并集:官方内置 / DSH 技能这类**默认来源没有来源级开关**,租约只落在底下的
358
+ * 技能上;而技能要加载就得让来源开着 —— 所以"这个来源里还有几个对话在临时运行"正是
359
+ * 这个并集。少了它,默认来源的组头永远是干净的(用户 2026-11-05 报障)。
360
+ *
361
+ * `keys` 记下这一条认领**具体落在哪几格**:来源那一格 + 底下那些技能各自的键。界面那颗
362
+ * 「×」照着它写会话层的覆盖,不必自己再猜一遍。
363
+ *
364
+ * @param sourceClaims 来源 → 认领会话 id。
365
+ * @param skillClaims 技能键(`<来源>/<技能名>`)→ 认领会话 id。
366
+ * @param rows 会话 id → 那一行的标题与工作区目录。
367
+ */
368
+ export function leaseSourceDetails(sourceClaims, skillClaims, rows) {
369
+ const out = {};
370
+ for (const [root, ids] of sourceClaims) {
371
+ out[root] = ids.map((id) => ({
372
+ id,
373
+ title: leaseTitleOf(id, rows),
374
+ cwd: leaseCwdOf(id, rows),
375
+ keys: [{ domain: 'skillSources', key: root }],
376
+ }));
377
+ }
378
+ for (const [skillKey, ids] of skillClaims) {
379
+ const slash = skillKey.indexOf('/');
380
+ if (slash <= 0)
381
+ continue;
382
+ const root = skillKey.slice(0, slash);
383
+ const list = out[root] ?? (out[root] = []);
384
+ for (const id of ids) {
385
+ let row = list.find((item) => item.id === id);
386
+ if (row === undefined) {
387
+ row = { id, title: leaseTitleOf(id, rows), cwd: leaseCwdOf(id, rows), keys: [] };
388
+ list.push(row);
389
+ }
390
+ row.keys.push({ domain: 'skills', key: skillKey });
391
+ }
392
+ }
393
+ return out;
394
+ }
395
+ /** 认领者的标题:清单里有就用它,没有就回落到短 id(不编)。 */
396
+ function leaseTitleOf(id, rows) {
397
+ const row = rows.get(id);
398
+ return row !== undefined && typeof row.title === 'string' && row.title !== '' ? row.title : id.slice(0, 8);
399
+ }
400
+ /** 认领者的工作区目录:清单里没有就是空串(它不属于任何工作区)。 */
401
+ function leaseCwdOf(id, rows) {
402
+ const row = rows.get(id);
403
+ return row !== undefined && typeof row.cwd === 'string' ? row.cwd : '';
404
+ }
329
405
  /**
330
406
  * 意图 / 运行态对账(纯函数)。运行态的目标恒为 `intent ∪ 租约`:
331
407
  *
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 官方 `tools.restrict()` 的**保留名**:名单里出现它时,官方不是"当它不存在",而是**直接抛错**
3
- * (`dsh-tools/lib/index.js:2800`:cannot name reserved PTC mode presentation transport),
3
+ * (`dsh-tools/lib/index.js:463`:cannot name reserved PTC mode presentation transport),
4
4
  * 子代理当场起不来。
5
5
  *
6
6
  * 为什么必须在这里显式剔除:`run_code` 在宿主面上是**合法可见**的工具名(非 native 模式下
@@ -21,7 +21,7 @@ export function stripReserved(names) {
21
21
  *
22
22
  * 为什么必须按预设分:子代理跑在父会话的预设里(官方 `composeFrom(childCtx, parent.ctx)`),
23
23
  * 而各预设的工具集合差别极大(极简模式只有持久 shell)。官方 `tools.restrict()` 实有
24
- * **四个**抛错点(`dsh-tools/lib/index.js:2790-2803`),抛了子代理就起不来:
24
+ * **四个**抛错点(`dsh-tools/lib/index.js:455-466`),抛了子代理就起不来:
25
25
  *
26
26
  * ① 非 scoped context 调用(宿主 `childCtx` 已满足,无风险);
27
27
  * ② `allow` 与 `deny` 同时缺省 ⇒ `restrict({})` 抛 —— 本函数用 `filter: null`(不下发)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-tool-management",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
5
5
  "repository": {
6
6
  "type": "git",