dsh-mcp-skills-controller 0.1.2 → 0.4.0

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.
package/icon.svg CHANGED
@@ -1,6 +1,8 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
2
- <!-- 滑杆组:上轨表示 MCP 服务器注入,下轨表示 skills 注入,圆点即开关位置 -->
3
- <path d="M3 7h18M3 17h18" />
4
- <circle cx="9" cy="7" r="2.6" />
5
- <circle cx="15" cy="17" r="2.6" />
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36" fill="none">
2
+ <!-- 滑杆组:上轨表示 MCP 服务器注入,下轨表示 skills 注入,圆点即开关位置。
3
+ DSH 以 <img> 加载插件图标,不继承页面 currentColor;用固定蓝色系保证
4
+ 在深色与浅色面板上都可辨认,不依赖主题反色。 -->
5
+ <path d="M5 12h26M5 24h26" stroke="#4C8DF6" stroke-width="2.2" stroke-linecap="round" />
6
+ <circle cx="14" cy="12" r="4.2" fill="#4C8DF6" stroke="#2F6BD8" stroke-width="1.4" />
7
+ <circle cx="23" cy="24" r="4.2" fill="#F4F8FF" stroke="#2F6BD8" stroke-width="1.4" />
6
8
  </svg>
package/index.js CHANGED
@@ -5,7 +5,9 @@
5
5
  * - 状态文件 `$DSH_HOME/dsh-mcp-skills-controller/state.json` 单写者维护(tmp + rename
6
6
  * 原子替换,损坏回退「全默认开启」),重启不丢;
7
7
  * - MCP:`agent/created` 时按冻结决策把 `tools.restrict({ deny })` 装到会话作用域
8
- * (serial 事件保证首批 prompt 组装前就位);deny 是展开后的精确工具名;
8
+ * (serial 事件保证首批 prompt 组装前就位);deny 是展开后的精确工具名。
9
+ * 决策分服务器级与工具级两层:工具级显式值压过服务器级(覆盖式),因此
10
+ * 「服务器关 + 单工具开」也成立;工具级同样创建时定型;
9
11
  * - skills:`agent/created` 时经 `ctx.get('skills')` 注册同名 runtime 遮蔽
10
12
  * (invocation 双 false),最近作用域层无条件胜出,模型 catalog 与 `/`
11
13
  * 命令同时消失;
@@ -22,19 +24,28 @@ import { randomBytes } from 'node:crypto'
22
24
  import { existsSync } from 'node:fs'
23
25
  import { dirname } from 'node:path'
24
26
  import {
25
- setSessionAll,
26
- setSessionMode,
27
+ clearAllMcpToolsGlobal,
28
+ clearAllMcpToolsSession,
29
+ clearMcpToolsGlobal,
30
+ clearMcpToolsSession,
27
31
  setGlobalAll,
28
32
  setGlobalEnabled,
33
+ setMcpToolGlobal,
34
+ setMcpToolSession,
35
+ setSessionAll,
36
+ setSessionMode,
29
37
  } from './src/merge.js'
30
38
  import { loadStateReport, saveState } from './src/state.js'
31
39
  import { createCatalogs } from './src/catalogs.js'
32
- import { isProjectSource } from './src/skill-catalog.js'
40
+ import { isProjectSource, skillGroupOf, skillOrigin } from './src/skill-origin.js'
41
+ import { isPackedPath } from './src/skill-path.js'
33
42
  import { createMcpMaskEngine } from './src/masks.js'
43
+ import { globalServerOn, globalToolOn, resolveServer, resolveTool } from './src/mcp-effective.js'
34
44
  import { createSkillShadowEngine } from './src/shadows.js'
35
45
  import * as views from './src/views.js'
36
46
  import { openDirectory } from './src/reveal.js'
37
- import { injectTokenMeta, registerRpc } from './src/rpc.js'
47
+ import { collectOrphans, pruneSessions } from './src/session-gc.js'
48
+ import { InvalidArgument, injectTokenMeta, registerRpc } from './src/rpc.js'
38
49
  import { handleAgentCreated } from './src/agent-hooks.js'
39
50
 
40
51
  export const name = 'mcp-skills-controller'
@@ -97,9 +108,157 @@ export function apply(ctx, rawConfig = {}) {
97
108
  const findAgent = (sessionId) => (ctx.get('agents')?.list?.() ?? [])
98
109
  .find((agent) => String(agent.id) === sessionId)
99
110
 
111
+ /**
112
+ * 汇总「仍然存在」的会话 id:在线会话、持久化存储、工作区归档集合。
113
+ * 任何只读来源不可用都抛错——存储故障不能被当成会话消失,否则清理会误删。
114
+ */
115
+ const knownSessionIds = async () => {
116
+ const ids = new Set()
117
+ for (const session of ctx.get('sessions')?.list?.() ?? []) {
118
+ const id = session?.header?.id ?? session?.id
119
+ if (typeof id === 'string' && id.length > 0) ids.add(id)
120
+ }
121
+ const persistence = ctx.get('sessionPersistence')
122
+ if (persistence === undefined || typeof persistence.list !== 'function') {
123
+ throw new Error('sessionPersistence 不可用,无法确认会话是否存在')
124
+ }
125
+ for (const snapshot of await persistence.list()) {
126
+ const id = snapshot?.header?.id
127
+ if (typeof id === 'string' && id.length > 0) ids.add(id)
128
+ }
129
+ const registry = ctx.get('workspaceRegistry')
130
+ if (registry !== undefined) {
131
+ const archived = registry.archivedSessionIds
132
+ if (!Array.isArray(archived)) {
133
+ throw new Error('workspaceRegistry.archivedSessionIds 不可用,无法确认归档会话')
134
+ }
135
+ for (const id of archived) {
136
+ if (typeof id === 'string' && id.length > 0) ids.add(id)
137
+ }
138
+ }
139
+ return ids
140
+ }
141
+
100
142
  /** 会话级技能目录:只读全局层 + 本会话 preset 层,项目 skill 随 cwd 发现。 */
101
143
  const readSessionSkills = (sessionId) => catalogs.skillsFor(findAgent(sessionId))
102
144
 
145
+ /**
146
+ * 在 MCP 目录里按公开全名(`mcp__<server>__<tool>`)找工具归属。
147
+ * 状态里工具键是裸名,所以同时返回 rawName;归属由宿主判定,客户端只传名字。
148
+ */
149
+ const findMcpTool = (catalog, name) => {
150
+ for (const server of catalog) {
151
+ const detail = Array.isArray(server.toolDetails)
152
+ ? server.toolDetails.find((tool) => tool.name === name)
153
+ : undefined
154
+ if (detail !== undefined) return { server: server.name, raw: detail.rawName }
155
+ if (Array.isArray(server.tools) && server.tools.includes(name)) {
156
+ const prefix = `mcp__${server.name}__`
157
+ return { server: server.name, raw: name.startsWith(prefix) ? name.slice(prefix.length) : name }
158
+ }
159
+ }
160
+ return undefined
161
+ }
162
+
163
+ /** 目录里的工具 → { fullName, rawName },供批量写工具层使用。 */
164
+ const mcpToolTargets = (server) => {
165
+ if (Array.isArray(server.toolDetails)) {
166
+ return server.toolDetails.map((tool) => ({ fullName: tool.name, rawName: tool.rawName }))
167
+ }
168
+ return (server.tools ?? []).map((fullName) => {
169
+ const prefix = `mcp__${server.name}__`
170
+ return {
171
+ fullName,
172
+ rawName: fullName.startsWith(prefix) ? fullName.slice(prefix.length) : fullName,
173
+ }
174
+ })
175
+ }
176
+
177
+ /**
178
+ * 工具写完后归一:某服务器的全部工具都生效为开、而服务器本身是关的,就提升为
179
+ * 「服务器开 + 清空全部工具例外」——避免「服务器关着逐个打开工具」留下一堆
180
+ * 冗余记录与 ↺。部分工具开仍然是例外,不动。
181
+ * @param scope 'global' | 'session'
182
+ * @returns 是否发生了归一。
183
+ */
184
+ const promoteServerIfAllOn = (scope, sessionId, catalog, serverName) => {
185
+ const server = catalog.find((entry) => entry.name === serverName)
186
+ if (server === undefined) return false
187
+ const targets = mcpToolTargets(server)
188
+ if (targets.length === 0) return false
189
+ const isGlobal = scope === 'global'
190
+ const serverOn = isGlobal
191
+ ? globalServerOn(state, serverName)
192
+ : resolveServer(state, sessionId, serverName)
193
+ if (serverOn) return false
194
+ const allOn = targets.every((tool) => (isGlobal
195
+ ? globalToolOn(state, serverName, tool.rawName)
196
+ : resolveTool(state, sessionId, serverName, tool.rawName, false)))
197
+ if (!allOn) return false
198
+ if (isGlobal) {
199
+ setGlobalEnabled(state, 'mcp', serverName, true)
200
+ clearMcpToolsGlobal(state, serverName)
201
+ } else {
202
+ setSessionMode(state, 'mcp', sessionId, serverName, 'on')
203
+ clearMcpToolsSession(state, sessionId, serverName)
204
+ }
205
+ return true
206
+ }
207
+
208
+ /**
209
+ * 工具写完后归一(关闭方向):某服务器的全部工具都生效为关、而服务器本身是开的,
210
+ * 就收敛为「服务器关 + 清空全部工具例外」。与 promote 对称,避免逐个关闭后留下
211
+ * 一堆 `false` 记录与 ↺。部分工具关仍然是例外,不动。
212
+ * @param scope 'global' | 'session'
213
+ * @returns 是否发生了归一。
214
+ */
215
+ const demoteServerIfAllOff = (scope, sessionId, catalog, serverName) => {
216
+ const server = catalog.find((entry) => entry.name === serverName)
217
+ if (server === undefined) return false
218
+ const targets = mcpToolTargets(server)
219
+ if (targets.length === 0) return false
220
+ const isGlobal = scope === 'global'
221
+ const serverOn = isGlobal
222
+ ? globalServerOn(state, serverName)
223
+ : resolveServer(state, sessionId, serverName)
224
+ if (!serverOn) return false
225
+ const allOff = targets.every((tool) => (isGlobal
226
+ ? !globalToolOn(state, serverName, tool.rawName)
227
+ : !resolveTool(state, sessionId, serverName, tool.rawName, true)))
228
+ if (!allOff) return false
229
+ if (isGlobal) {
230
+ setGlobalEnabled(state, 'mcp', serverName, false)
231
+ clearMcpToolsGlobal(state, serverName)
232
+ } else {
233
+ setSessionMode(state, 'mcp', sessionId, serverName, 'off')
234
+ clearMcpToolsSession(state, sessionId, serverName)
235
+ }
236
+ return true
237
+ }
238
+
239
+ /**
240
+ * 加载时归一历史数据:旧状态可能留下「服务器关 + 全部工具开」或
241
+ * 「服务器开 + 全部工具关」。目录为空(服务未就绪)时自然跳过。
242
+ */
243
+ const normalizeAllMcpServers = () => {
244
+ const catalog = catalogs.mcp()
245
+ let changed = false
246
+ const normalizeScope = (scope, sessionId) => {
247
+ for (const server of catalog) {
248
+ if (promoteServerIfAllOn(scope, sessionId, catalog, server.name)) changed = true
249
+ if (demoteServerIfAllOff(scope, sessionId, catalog, server.name)) changed = true
250
+ }
251
+ }
252
+ normalizeScope('global', undefined)
253
+ for (const sessionId of Object.keys(state.mcp.sessions ?? {})) {
254
+ normalizeScope('session', sessionId)
255
+ }
256
+ if (changed) persist()
257
+ }
258
+
259
+ // 目录可用时立刻归一一次;不可用(服务未就绪)时留到后续写操作再收敛。
260
+ normalizeAllMcpServers()
261
+
103
262
  /** MCP 会话快照:目录 + 生效值 + 三态模式。 */
104
263
  const mcpSessionPayload = (sessionId) => {
105
264
  const agent = findAgent(sessionId)
@@ -194,10 +353,72 @@ export function apply(ctx, rawConfig = {}) {
194
353
  const handlers = {
195
354
  sessionSnapshot,
196
355
 
197
- /** 单项三态切换。项目级技能忽略全局默认,'on' 即回到默认开。 */
356
+ /**
357
+ * 单项三态切换。MCP 的 item 可以是服务器名,也可以是工具公开全名
358
+ * (宿主按目录判定归属);项目级技能忽略全局默认,'on' 即回到默认开。
359
+ */
198
360
  sessionSet: async ({ session, kind, item, mode }) => {
361
+ if (kind === 'mcp') {
362
+ const catalog = catalogs.mcp()
363
+ const tool = findMcpTool(catalog, item)
364
+ if (tool !== undefined) {
365
+ // 工具层:状态里按「服务器 → 裸工具名」存,覆盖式语义下压过服务器开关。
366
+ const server = catalog.find((entry) => entry.name === tool.server)
367
+ const targets = server === undefined ? [] : mcpToolTargets(server)
368
+ const serverOn = resolveServer(state, session, tool.server)
369
+ // 这是最后一个未开的工具时,写完后会归一为「服务器开」。
370
+ const willAllOn = mode === 'on' && !serverOn && targets.length > 0
371
+ && targets.every((entry) => (entry.fullName === item
372
+ ? true
373
+ : resolveTool(state, session, tool.server, entry.rawName, serverOn)))
374
+ // 这是最后一个还开着的工具时,写完后会归一为「服务器关」。
375
+ const willAllOff = mode === 'off' && serverOn && targets.length > 0
376
+ && targets.every((entry) => (entry.fullName === item
377
+ ? true
378
+ : !resolveTool(state, session, tool.server, entry.rawName, serverOn)))
379
+ const changes = willAllOn
380
+ ? new Map([
381
+ ...targets.map((entry) => [entry.fullName, 'follow']),
382
+ [tool.server, 'on'],
383
+ ])
384
+ : willAllOff
385
+ ? new Map([
386
+ ...targets.map((entry) => [entry.fullName, 'follow']),
387
+ [tool.server, 'off'],
388
+ ])
389
+ : new Map([[item, mode]])
390
+ return commitSession({
391
+ kind,
392
+ session,
393
+ changes,
394
+ mutate: () => {
395
+ setMcpToolSession(state, session, tool.server, tool.raw, mode)
396
+ promoteServerIfAllOn('session', session, catalog, tool.server)
397
+ demoteServerIfAllOff('session', session, catalog, tool.server)
398
+ },
399
+ })
400
+ }
401
+ const server = catalog.find((entry) => entry.name === item)
402
+ if (server === undefined) {
403
+ throw new InvalidArgument('invalid-item', `未知的 MCP 服务器或工具:${item}`)
404
+ }
405
+ const targets = mcpToolTargets(server)
406
+ // 服务器开关是整组总开关:同时清掉该服务器的工具级例外,点开就是全开。
407
+ return commitSession({
408
+ kind,
409
+ session,
410
+ changes: new Map([
411
+ [item, mode],
412
+ ...targets.map((target) => [target.fullName, 'follow']),
413
+ ]),
414
+ mutate: () => {
415
+ setSessionMode(state, 'mcp', session, item, mode)
416
+ clearMcpToolsSession(state, session, item)
417
+ },
418
+ })
419
+ }
199
420
  // skills 写路径只读一次目录:来源判断、立即重算与返回快照共用同一份读数。
200
- const skillsCatalog = kind === 'skills' ? await readSessionSkills(session) : undefined
421
+ const skillsCatalog = await readSessionSkills(session)
201
422
  const row = skillsCatalog?.skills.find((entry) => entry.name === item)
202
423
  const project = row !== undefined && isProjectSource(row.source)
203
424
  return commitSession({
@@ -205,7 +426,7 @@ export function apply(ctx, rawConfig = {}) {
205
426
  session,
206
427
  changes: new Map([[item, mode]]),
207
428
  skillsCatalog,
208
- mutate: () => setSessionMode(state, kind, session, item, mode, { project }),
429
+ mutate: () => setSessionMode(state, 'skills', session, item, mode, { project }),
209
430
  })
210
431
  },
211
432
 
@@ -213,13 +434,63 @@ export function apply(ctx, rawConfig = {}) {
213
434
  * 整组操作。'follow' = 删除该 kind 该会话全部覆盖并按当下全局重算全部项;
214
435
  * 'on'/'off' = 对目录全集逐项写显式覆盖。会话全集包含项目级技能,批量
215
436
  * 操作一并包含;项目级技能按自己的默认值(开)做覆盖抑制。
437
+ *
438
+ * MCP 带 `server` 时只作用于该服务器的工具组(写工具层),不碰服务器开关;
439
+ * 省略则是服务器全集,保持原有整组语义。
216
440
  */
217
- sessionAll: async ({ session, kind, mode }) => {
441
+ sessionAll: async ({ session, kind, mode, server }) => {
218
442
  let items
219
443
  let projectItems = []
220
444
  let skillsCatalog
221
445
  if (kind === 'mcp') {
222
- items = catalogs.mcp().map((server) => server.name)
446
+ const catalog = catalogs.mcp()
447
+ if (server !== undefined) {
448
+ const target = catalog.find((entry) => entry.name === server)
449
+ if (target === undefined) {
450
+ throw new InvalidArgument('invalid-server', `未知的 MCP 服务器:${server}`)
451
+ }
452
+ const targets = mcpToolTargets(target)
453
+ const serverOn = resolveServer(state, session, target.name)
454
+ const willAllOn = mode === 'on' && !serverOn && targets.length > 0
455
+ const willAllOff = mode === 'off' && serverOn && targets.length > 0
456
+ return commitSession({
457
+ kind,
458
+ session,
459
+ changes: willAllOn
460
+ ? new Map([
461
+ ...targets.map((tool) => [tool.fullName, 'follow']),
462
+ [target.name, 'on'],
463
+ ])
464
+ : willAllOff
465
+ ? new Map([
466
+ ...targets.map((tool) => [tool.fullName, 'follow']),
467
+ [target.name, 'off'],
468
+ ])
469
+ : new Map(targets.map((tool) => [tool.fullName, mode])),
470
+ mutate: () => {
471
+ for (const tool of targets) {
472
+ setMcpToolSession(state, session, target.name, tool.rawName, mode)
473
+ }
474
+ promoteServerIfAllOn('session', session, catalog, target.name)
475
+ demoteServerIfAllOff('session', session, catalog, target.name)
476
+ },
477
+ })
478
+ }
479
+ items = catalog.map((entry) => entry.name)
480
+ const toolNames = catalog.flatMap((entry) => mcpToolTargets(entry).map((tool) => tool.fullName))
481
+ // 服务器全集批量也是整组重置:清掉全部工具级例外,冻结表里的工具项一起跟随。
482
+ return commitSession({
483
+ kind,
484
+ session,
485
+ changes: new Map([
486
+ ...items.map((name) => [name, mode]),
487
+ ...toolNames.map((name) => [name, 'follow']),
488
+ ]),
489
+ mutate: () => {
490
+ setSessionAll(state, 'mcp', session, mode, items)
491
+ clearAllMcpToolsSession(state, session)
492
+ },
493
+ })
223
494
  } else {
224
495
  skillsCatalog = await readSessionSkills(session)
225
496
  items = skillsCatalog.skills.map((row) => row.name)
@@ -239,24 +510,117 @@ export function apply(ctx, rawConfig = {}) {
239
510
  globalSnapshot,
240
511
 
241
512
  /**
242
- * 全局单项开关。「开」= 删除显式记录回到未记录态(默认开),不写 true;
513
+ * 全局单项开关。服务器层「开」= 删除显式记录回到未记录态(默认开);
514
+ * 工具层用三态(mode:on / off / follow),因为它的默认值取决于服务器。
243
515
  * 随后重算全部在线会话:已开始会话因冻结决策表不动(不追溯),空白会话
244
516
  * (新会话页背后的提前创建 agent)实时跟随新默认。
245
517
  */
246
- globalSet: async ({ kind, item, enabled }) => commitGlobal(
247
- () => setGlobalEnabled(state, kind, item, enabled),
248
- ),
249
-
250
- /** 全局整组开关;重算语义同 globalSet。项目级技能不在全局目录里。 */
251
- globalAll: async ({ kind, enabled }) => {
252
- const items = kind === 'mcp'
253
- ? catalogs.mcp().map((server) => server.name)
254
- : (await catalogs.skillsGlobal()).skills
518
+ globalSet: async ({ kind, item, enabled, mode }) => {
519
+ if (kind === 'mcp') {
520
+ const catalog = catalogs.mcp()
521
+ const tool = findMcpTool(catalog, item)
522
+ if (tool !== undefined) {
523
+ const nextMode = mode ?? (enabled === true ? 'on' : 'off')
524
+ return commitGlobal(() => {
525
+ setMcpToolGlobal(state, tool.server, tool.raw, nextMode)
526
+ promoteServerIfAllOn('global', undefined, catalog, tool.server)
527
+ demoteServerIfAllOff('global', undefined, catalog, tool.server)
528
+ })
529
+ }
530
+ const server = catalog.find((entry) => entry.name === item)
531
+ if (server === undefined) {
532
+ throw new InvalidArgument('invalid-item', `未知的 MCP 服务器或工具:${item}`)
533
+ }
534
+ // 服务器开关是整组总开关:同时清掉该服务器的工具级例外,点开就是全开。
535
+ return commitGlobal(() => {
536
+ setGlobalEnabled(state, 'mcp', item, enabled)
537
+ clearMcpToolsGlobal(state, item)
538
+ })
539
+ }
540
+ return commitGlobal(() => setGlobalEnabled(state, kind, item, enabled))
541
+ },
542
+
543
+ /**
544
+ * 全局整组开关;重算语义同 globalSet。项目级技能不在全局目录里。
545
+ * group 省略 = 全部 skills;指定时只作用于该展示分组(user / plugin /
546
+ * preset / other),由宿主按 source 分类挑选,客户端不传名字列表。
547
+ * MCP 带 `server` 时只作用于该服务器的工具组(写工具层)。
548
+ */
549
+ globalAll: async ({ kind, enabled, group, server, mode }) => {
550
+ let items
551
+ if (kind === 'mcp') {
552
+ const catalog = catalogs.mcp()
553
+ if (server !== undefined) {
554
+ const target = catalog.find((entry) => entry.name === server)
555
+ if (target === undefined) {
556
+ throw new InvalidArgument('invalid-server', `未知的 MCP 服务器:${server}`)
557
+ }
558
+ const targets = mcpToolTargets(target)
559
+ const nextMode = mode ?? (enabled === true ? 'on' : 'off')
560
+ // 工具组「全部开」写成显式 true:覆盖式语义下它要能突破服务器关。
561
+ return commitGlobal(() => {
562
+ for (const tool of targets) {
563
+ setMcpToolGlobal(state, target.name, tool.rawName, nextMode)
564
+ }
565
+ promoteServerIfAllOn('global', undefined, catalog, target.name)
566
+ demoteServerIfAllOff('global', undefined, catalog, target.name)
567
+ })
568
+ }
569
+ items = catalog.map((entry) => entry.name)
570
+ // 服务器全集批量同样清掉工具例外,避免「全部关」后仍有工具可见。
571
+ return commitGlobal(() => {
572
+ setGlobalAll(state, 'mcp', enabled, items)
573
+ clearAllMcpToolsGlobal(state)
574
+ })
575
+ } else {
576
+ const catalog = await catalogs.skillsGlobal()
577
+ items = catalog.skills
255
578
  .filter((row) => !isProjectSource(row.source))
579
+ .filter((row) => group === undefined
580
+ || skillGroupOf(skillOrigin(row.source).origin) === group)
256
581
  .map((row) => row.name)
582
+ }
257
583
  return commitGlobal(() => setGlobalAll(state, kind, enabled, items))
258
584
  },
259
585
 
586
+ /**
587
+ * 只读诊断:定位「界面显示开启、模型却看不到工具」这类问题。
588
+ * 返回在线 agent、目录、该会话实际可见的 MCP 工具名与已装掩码信息。
589
+ */
590
+ diagnose: async ({ session }) => {
591
+ const agent = findAgent(session)
592
+ const catalog = catalogs.mcp()
593
+ return {
594
+ session,
595
+ liveAgents: (ctx.get('agents')?.list?.() ?? []).map((entry) => String(entry.id)),
596
+ servers: catalog.map((server) => ({ name: server.name, tools: server.tools.length })),
597
+ ...masks.debugFor(agent, session, catalog),
598
+ }
599
+ },
600
+
601
+ /**
602
+ * 只读预览:列出状态里已经不存在于任何会话来源的会话覆盖。
603
+ * 只返回摘要,不返回会话内容;确认后走 cleanOrphanSessions。
604
+ */
605
+ orphanSessions: async () => {
606
+ const known = await knownSessionIds()
607
+ return { orphans: collectOrphans(state, known) }
608
+ },
609
+
610
+ /**
611
+ * 清理孤立会话覆盖:重新确认存在性后删除两层会话行并落盘。
612
+ * 删除的都不是在线/归档/存档中的会话;返回删除清单与最新全局快照。
613
+ */
614
+ cleanOrphanSessions: async () => {
615
+ const known = await knownSessionIds()
616
+ const orphans = collectOrphans(state, known)
617
+ const removed = orphans.length === 0
618
+ ? []
619
+ : pruneSessions(state, orphans.map((row) => row.session))
620
+ const persisted = removed.length === 0 ? true : persist()
621
+ return { removed, persisted, payload: await globalSnapshot() }
622
+ },
623
+
260
624
  /**
261
625
  * 「查看所在目录」:只接收技能名,指令文件位置由宿主目录解析——浏览器半
262
626
  * 不能把任意路径交给系统打开,否则 RPC 会变成一条任意路径启动器。
@@ -269,6 +633,8 @@ export function apply(ctx, rawConfig = {}) {
269
633
  if (typeof row.path !== 'string' || row.path.length === 0) {
270
634
  return { revealed: false, reason: 'no-path' }
271
635
  }
636
+ // 打包在 app.asar 内的技能:ctx.fs 能读,但文件管理器进不去归档。
637
+ if (isPackedPath(row.path)) return { revealed: false, reason: 'packed' }
272
638
  const directory = dirname(row.path)
273
639
  if (!existsSync(directory)) return { revealed: false, reason: 'missing-directory' }
274
640
  await openDirectory(directory)
@@ -297,9 +663,12 @@ export function apply(ctx, rawConfig = {}) {
297
663
  shadows.clearSession(String(agent.id))
298
664
  })
299
665
 
300
- // 工具集合变化(服务器重连、工具列表更新):按冻结决策重算 deny 展开,
301
- // 指纹挡住自激。
302
- ctx.on('tools/change', () => { masks.reconcile() })
666
+ // 工具集合变化(服务器重连、工具列表更新):先归一历史数据,再按冻结决策
667
+ // 重算 deny 展开,指纹挡住自激。
668
+ ctx.on('tools/change', () => {
669
+ normalizeAllMcpServers()
670
+ masks.reconcile()
671
+ })
303
672
 
304
673
  // 技能目录变化(provider 注册/注销、preset 装载):重算遮蔽差量,指纹挡住自激。
305
674
  ctx.on('skills/change', () => { shadows.reconcile() })
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "MCP & Skills Controller",
4
- "description": "Unified visibility control for MCP servers and skills with persistent global defaults plus per-session tri-state overrides, covering subagents; zero intrusion, no config rewrites."
4
+ "description": "Unified visibility control for MCP servers, tools and skills with persistent global defaults plus per-session tri-state overrides, covering subagents; zero intrusion, no config rewrites."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "MCP & Skills 控制器",
4
- "description": "以全局持久化默认 + 会话级三态覆盖统一管理 MCP 服务器与 skills 的注入可见性,支持子代理;零侵入,不改配置文件。"
4
+ "description": "以全局持久化默认 + 会话级三态覆盖统一管理 MCP 服务器、工具与 skills 的注入可见性,支持子代理;零侵入,不改配置文件。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-mcp-skills-controller",
3
- "version": "0.1.2",
4
- "description": "以「全局持久化默认 + 会话级三态覆盖」统一管理 MCP 服务器与 skills 的注入可见性;零侵入,不改任何配置文件。",
3
+ "version": "0.4.0",
4
+ "description": "以「全局持久化默认 + 会话级三态覆盖」统一管理 MCP 服务器、工具与 skills 的注入可见性;零侵入,不改任何配置文件。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "exports": {
@@ -50,8 +50,8 @@
50
50
  "skills"
51
51
  ],
52
52
  "scripts": {
53
- "check": "node --check index.js && node --check client.js && node --check src/merge.js && node --check src/state.js && node --check src/mcp-catalog.js && node --check src/skill-catalog.js && node --check src/session.js && node --check src/frozen-registry.js && node --check src/catalogs.js && node --check src/views.js && node --check src/agent-hooks.js && node --check src/masks.js && node --check src/shadows.js && node --check src/reveal.js && node --check src/rpc.js",
54
- "test": "node tests/merge-test.mjs && node tests/state-test.mjs && node tests/mcp-catalog-test.mjs && node tests/skill-catalog-test.mjs && node tests/masks-test.mjs && node tests/shadows-test.mjs && node tests/frozen-registry-test.mjs && node tests/views-test.mjs && node tests/agent-hooks-test.mjs && node tests/reveal-test.mjs && node tests/rpc-test.mjs && node tests/contract-test.mjs",
53
+ "check": "node --check index.js && node --check client.js && node --check src/merge.js && node --check src/state.js && node --check src/mcp-catalog.js && node --check src/mcp-effective.js && node --check src/skill-catalog.js && node --check src/skill-origin.js && node --check src/skill-path.js && node --check src/session.js && node --check src/frozen-registry.js && node --check src/catalogs.js && node --check src/views.js && node --check src/agent-hooks.js && node --check src/masks.js && node --check src/shadows.js && node --check src/session-gc.js && node --check src/reveal.js && node --check src/rpc.js",
54
+ "test": "node tests/merge-test.mjs && node tests/session-gc-test.mjs && node tests/state-test.mjs && node tests/mcp-catalog-test.mjs && node tests/mcp-effective-test.mjs && node tests/skill-catalog-test.mjs && node tests/skill-origin-test.mjs && node tests/masks-test.mjs && node tests/shadows-test.mjs && node tests/frozen-registry-test.mjs && node tests/views-test.mjs && node tests/agent-hooks-test.mjs && node tests/reveal-test.mjs && node tests/rpc-test.mjs && node tests/contract-test.mjs && node tests/integration-test.mjs && node tests/client-render-test.mjs",
55
55
  "prepack": "npm run check",
56
56
  "prepublishOnly": "npm run check"
57
57
  }