dsh-plugin-tool-management 0.22.1 → 0.22.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.
@@ -3,7 +3,7 @@
3
3
  // 这张表就是与宿主的契约本体 —— 纯字面量,判定逻辑在 probe.ts 的 inspectCapability,
4
4
  // 取数原语在 host-probe.ts。缺一个成员时界面给出的是这一行点名的降级,而不是删除序列
5
5
  // 中途抛出的一次异常。
6
- import { callableWithSentinel, isFn, PROBE_SENTINEL, resolvableFromHost } from './host-probe.js';
6
+ import { callableWithSentinel, isAsyncFn, isFn, PROBE_SENTINEL, resolvableFromHost } from './host-probe.js';
7
7
  /**
8
8
  * 能力表。它就是与宿主之间的契约:适配器伸手要的每一样都列在这里,并写清缺席时的后果,
9
9
  * 于是缺一个成员得到的是**有名有姓、界面上看得见**的降级,而不是删除序列跑到一半抛出的错。
@@ -171,6 +171,48 @@ export const CAPABILITY_SPECS = [
171
171
  // **enter 不真调**(官方实现对任意输入都会往 store 写入条目),它只有存在性 + 文本比对。
172
172
  probe: (t) => callableWithSentinel(t, 'announce', PROBE_SENTINEL),
173
173
  },
174
+ {
175
+ // 列表与删除都会碰实时会话:历史页读会话正文用 `get`,删除子会话级联用 `list`。
176
+ // 缺任何一个都不会在"进入删除主体之前"被发现 —— 路由必须把它们算进要求里。
177
+ id: 'sessions.live-access',
178
+ label: '实时会话读取(get / list)',
179
+ kind: 'read',
180
+ owner: 'sessions',
181
+ fallback: 'refuse-operation',
182
+ methods: ['get', 'list'],
183
+ },
184
+ // ---- 持久化后端:历史列表与删除的共同底座 ------------------------------
185
+ // 这两个成员此前完全不在能力表里:删除入口自己会在破坏性步骤前硬检查,
186
+ // 但兼容页 / 路由看不见它们 —— 页面说「删除可用」而点下去在链路中段才报错。
187
+ {
188
+ id: 'persistence.list',
189
+ label: '会话存储枚举',
190
+ kind: 'read',
191
+ owner: 'persistence',
192
+ fallback: 'refuse-operation',
193
+ methods: ['list'],
194
+ },
195
+ {
196
+ id: 'persistence.transcript-locate',
197
+ label: '会话转写工件定位',
198
+ kind: 'delete',
199
+ owner: 'persistence',
200
+ fallback: 'disable-destructive',
201
+ methods: ['locate'],
202
+ },
203
+ {
204
+ // 投影修复是可选路径:两代读取入口任一在场即可(新版 open 句柄 / 旧版 readFrom)。
205
+ // 都缺时只少「归档会话的投影补建」,不碰数据,所以只上报不拦路。
206
+ id: 'persistence.transcript-read',
207
+ label: '会话转写读取(投影修复)',
208
+ kind: 'read',
209
+ owner: 'persistence',
210
+ fallback: 'inform-only',
211
+ optional: true,
212
+ probe: (t) => (isFn(t?.readFrom) || isFn(t?.open))
213
+ ? undefined
214
+ : '持久化后端既没有 readFrom 也没有 open:归档会话的投影修复会静默跳过',
215
+ },
174
216
  // ---- projection cache ---------------------------------------------------
175
217
  {
176
218
  id: 'projection.write',
@@ -205,6 +247,43 @@ export const CAPABILITY_SPECS = [
205
247
  return undefined;
206
248
  },
207
249
  },
250
+ {
251
+ id: 'projection.cached-title',
252
+ label: '投影缓存标题读取(cachedSnapshot)',
253
+ kind: 'read',
254
+ owner: 'projectionCache',
255
+ fallback: 'inform-only',
256
+ methods: ['cachedSnapshot', 'cachedPredecessorTitle'],
257
+ // 两个入口都是同步、零 I/O 的列表提示面;用哨兵 header 真调一次,只验证「不抛错」
258
+ // 与「有值时带 values 对象」—— 真实标题取决于磁盘记录,交给人工核对。
259
+ probe: (t) => {
260
+ const snapshot = t.cachedSnapshot;
261
+ const predecessor = t.cachedPredecessorTitle;
262
+ if (typeof snapshot !== 'function')
263
+ return '宿主投影缓存缺少 cachedSnapshot():归档列表读不到标题';
264
+ if (typeof predecessor !== 'function')
265
+ return '宿主投影缓存缺少 cachedPredecessorTitle():旧格式代际的标题提示不可用';
266
+ try {
267
+ const value = snapshot.call(t, { id: PROBE_SENTINEL }, ['title']);
268
+ if (value !== undefined) {
269
+ const values = value === null ? null : value.values;
270
+ if (typeof value !== 'object' || values === null || typeof values !== 'object') {
271
+ return 'cachedSnapshot() 的返回值缺少 values 对象:标题读取形状变了';
272
+ }
273
+ }
274
+ }
275
+ catch (error) {
276
+ return `cachedSnapshot(哨兵 header) 抛错:${String(error?.message ?? error)}`;
277
+ }
278
+ try {
279
+ predecessor.call(t, { id: PROBE_SENTINEL });
280
+ }
281
+ catch (error) {
282
+ return `cachedPredecessorTitle(哨兵 header) 抛错:${String(error?.message ?? error)}`;
283
+ }
284
+ return undefined;
285
+ },
286
+ },
208
287
  {
209
288
  id: 'projection.delete-native',
210
289
  label: '投影缓存删除屏障',
@@ -373,4 +452,324 @@ export const CAPABILITY_SPECS = [
373
452
  // "只能对活的宿主查"),而不是编一个"缺失"。
374
453
  staticWhen: () => resolvableFromHost('@deepseek-ai/dsh-client-connection'),
375
454
  },
455
+ // ---- 不在 inject 清单里的宿主服务:缺席不阻止插件挂载,但会静默少一块功能 ----
456
+ // 这几条与上面那些契约面的区别:它们不是「宿主某个对象上的成员」,而是**整个服务**
457
+ // 换名 / 消失。插件在运行时用 `ctx.get(name)` 软取,取不到就各自降级 —— 没有全局信号,
458
+ // 所以逐条列出来,升级后第一眼能看见是哪一块没了。
459
+ {
460
+ id: 'subagents.runtime',
461
+ label: '子智能体运行时(startActivation)',
462
+ kind: 'write',
463
+ owner: 'subagents',
464
+ fallback: 'refuse-operation',
465
+ methods: ['startActivation', 'list'],
466
+ // list() 是只读的 provider 名册:既能证明运行时在,也能核对「名字数组」这个返回形状。
467
+ // startActivation 不能真调(会启动一个子代理),只核对它是异步方法。
468
+ probe: (t) => {
469
+ const list = t.list;
470
+ if (typeof list !== 'function')
471
+ return '宿主子智能体运行时缺少 list()';
472
+ let names;
473
+ try {
474
+ names = list.call(t);
475
+ }
476
+ catch (error) {
477
+ return `subagents.list() 抛错:${String(error?.message ?? error)}`;
478
+ }
479
+ if (!Array.isArray(names))
480
+ return 'subagents.list() 未返回数组:provider 名册读不出来';
481
+ const invalid = names.find((name) => typeof name !== 'string');
482
+ if (invalid !== undefined)
483
+ return 'subagents.list() 的元素不是字符串:provider 名册形状变了';
484
+ return isAsyncFn(t.startActivation)
485
+ ? undefined
486
+ : 'startActivation 不是异步方法:派活调用会同步失败或返回非 Promise';
487
+ },
488
+ describe: (t) => {
489
+ try {
490
+ const names = t.list?.();
491
+ return Array.isArray(names) && names.length > 0 ? `已注册 provider:${names.join('、')}` : undefined;
492
+ }
493
+ catch {
494
+ return undefined;
495
+ }
496
+ },
497
+ },
498
+ {
499
+ id: 'llm.model-catalog',
500
+ label: '模型目录(场景模型候选)',
501
+ kind: 'read',
502
+ owner: 'llm',
503
+ fallback: 'inform-only',
504
+ methods: ['listProviders', 'listModels', 'resolveModelInfo'],
505
+ // listProviders() 是同步且只读的:能直接核对 LlmProviderInfo[] 的 id / name 形状。
506
+ // listModels / resolveModelInfo 是异步(可能联网)的,只核对异步方法签名,不发起调用。
507
+ probe: (t) => {
508
+ const listProviders = t.listProviders;
509
+ if (typeof listProviders !== 'function')
510
+ return '宿主 llm 服务缺少 listProviders()';
511
+ let providers;
512
+ try {
513
+ providers = listProviders.call(t);
514
+ }
515
+ catch (error) {
516
+ return `listProviders() 抛错:${String(error?.message ?? error)}`;
517
+ }
518
+ if (!Array.isArray(providers))
519
+ return 'listProviders() 未返回数组:模型来源枚举失效';
520
+ const invalid = providers.find((item) => item === null || typeof item !== 'object'
521
+ || typeof item.id !== 'string'
522
+ || typeof item.name !== 'string');
523
+ if (invalid !== undefined)
524
+ return 'listProviders() 的元素缺少字符串 id / name:模型来源形状变了';
525
+ if (!isAsyncFn(t.listModels))
526
+ return 'listModels 不是异步方法:来源下的模型枚举会失效';
527
+ if (!isAsyncFn(t.resolveModelInfo))
528
+ return 'resolveModelInfo 不是异步方法:思考档位清单会失效';
529
+ return undefined;
530
+ },
531
+ describe: (t) => isFn(t.listModels) ? '支持 listModels(可枚举模型)' : '无 listModels(只列来源,模型需手填)',
532
+ },
533
+ {
534
+ id: 'approval.effective-policy',
535
+ label: '审批策略读取(完全权限判定)',
536
+ kind: 'read',
537
+ owner: 'approval',
538
+ fallback: 'inform-only',
539
+ methods: ['effectivePolicy'],
540
+ // 私有实现细节:只核对接收一个 session 参数,返回值取决于会话(可能是 never / ask);
541
+ // 用哨兵真调会把「没有会话」误报成契约漂移,所以不调用。
542
+ probe: (t) => t.effectivePolicy?.length === 1
543
+ ? undefined
544
+ : 'effectivePolicy 的签名不再是单参数(session):完全权限判定可能失真',
545
+ },
546
+ {
547
+ id: 'tools.schema-list',
548
+ label: '工具清单读取(schemas)',
549
+ kind: 'read',
550
+ owner: 'tools',
551
+ fallback: 'inform-only',
552
+ methods: ['schemas'],
553
+ // 工具名从 `schemas()` 的元素上读;元素形状一变,MCP 工具计数会恒为 0,
554
+ // 可见性摘除的名单也会跟着变空 —— 两处都静默。只查方法存在不够。
555
+ probe: (t) => {
556
+ const schemas = t.schemas;
557
+ if (typeof schemas !== 'function')
558
+ return '宿主工具服务缺少 schemas()';
559
+ let list;
560
+ try {
561
+ list = schemas.call(t);
562
+ }
563
+ catch (error) {
564
+ return `schemas() 抛错:${String(error?.message ?? error)}`;
565
+ }
566
+ if (!Array.isArray(list))
567
+ return 'schemas() 没有返回数组:工具计数与可见性名单无法生成';
568
+ const invalid = list.find((item) => item === null || typeof item !== 'object' || typeof item.name !== 'string');
569
+ return invalid === undefined ? undefined : 'schemas() 的元素缺少字符串 name:工具名读不出来';
570
+ },
571
+ },
572
+ // ---- 其余宿主服务的公开面:缺了不会让插件挂不上,但对应功能会静默少一块 ----
573
+ {
574
+ id: 'skills.register-provider',
575
+ label: '技能 provider 注册(registerProvider)',
576
+ kind: 'write',
577
+ owner: 'skills',
578
+ fallback: 'inform-only',
579
+ methods: ['registerProvider'],
580
+ // 真注册一个 provider 会进入技能目录并触发失效事件,所以只核对签名:
581
+ // 官方若改成两参 / 返回不可调用对象,下面的注册逻辑会静默失效。
582
+ probe: (t) => {
583
+ const register = t.registerProvider;
584
+ if (typeof register !== 'function')
585
+ return '宿主技能服务缺少 registerProvider():技能启停与官方内置技能接管失效';
586
+ return register.length === 1
587
+ ? undefined
588
+ : 'registerProvider 的签名不再是单参数(create):provider 注册可能静默失效';
589
+ },
590
+ },
591
+ {
592
+ id: 'agents.list',
593
+ label: '活动 agent 清单(agents.list)',
594
+ kind: 'read',
595
+ owner: 'agents',
596
+ fallback: 'inform-only',
597
+ methods: ['list'],
598
+ // 只读调用:返回活动 agent 数组。非空时核对 id / ctx;空数组时只能证明返回形状是数组。
599
+ probe: (t) => {
600
+ let agents;
601
+ try {
602
+ agents = t.list();
603
+ }
604
+ catch (error) {
605
+ return `agents.list() 抛错:${String(error?.message ?? error)}`;
606
+ }
607
+ if (!Array.isArray(agents))
608
+ return 'agents.list() 未返回数组:agent 作用域 provider 无法补装';
609
+ const invalid = agents.find((agent) => agent === null || typeof agent !== 'object'
610
+ || typeof agent.id !== 'string'
611
+ || agent.ctx === null || typeof agent.ctx !== 'object');
612
+ return invalid === undefined ? undefined : 'agents.list() 的元素缺少字符串 id 或 ctx:agent 作用域 provider 无法补装';
613
+ },
614
+ },
615
+ {
616
+ id: 'pluginInventory.list',
617
+ label: 'Loader 插件条目清单(pluginInventory.list)',
618
+ kind: 'read',
619
+ owner: 'pluginInventory',
620
+ fallback: 'inform-only',
621
+ methods: ['list'],
622
+ // 异步读取实时 Loader 树;探测不发起调用(会等宿主加载),只核对异步签名。
623
+ probe: (t) => {
624
+ const list = t.list;
625
+ if (!isAsyncFn(list))
626
+ return 'pluginInventory.list 不是异步方法:loader 条目清单读不出来';
627
+ return list.length === 0
628
+ ? undefined
629
+ : 'pluginInventory.list 的签名不再是零参数:条目清单可能读不出来';
630
+ },
631
+ },
632
+ {
633
+ id: 'webServer.register',
634
+ label: 'HTTP 路由注册(webServer.register)',
635
+ kind: 'write',
636
+ owner: 'webServer',
637
+ fallback: 'refuse-operation',
638
+ methods: ['register'],
639
+ // 真注册一条路由会占用宿主路由表;只核对单参数签名。
640
+ probe: (t) => {
641
+ const register = t.register;
642
+ if (typeof register !== 'function')
643
+ return '宿主 webServer 缺少 register():插件面板 API 无法挂载(整页 404)';
644
+ return register.length === 1
645
+ ? undefined
646
+ : 'webServer.register 的签名不再是单参数(route):面板 API 路由可能挂不上';
647
+ },
648
+ describe: (t) => isFn(t.registerUpgrade) ? '支持 registerUpgrade' : undefined,
649
+ },
650
+ {
651
+ id: 'sandboxPolicy.resolve',
652
+ label: '沙箱策略解析(sandboxPolicy.resolve)',
653
+ kind: 'read',
654
+ owner: 'sandboxPolicy',
655
+ fallback: 'refuse-operation',
656
+ methods: ['resolve'],
657
+ // 零副作用真调:read-only 请求不涉及会话与文件,返回的 mode / workspaceRoot 是纯计算。
658
+ probe: (t) => {
659
+ let policy;
660
+ try {
661
+ policy = t.resolve({ mode: 'read-only' });
662
+ }
663
+ catch (error) {
664
+ return `sandboxPolicy.resolve({ mode: "read-only" }) 抛错:${String(error?.message ?? error)}`;
665
+ }
666
+ if (policy === null || typeof policy !== 'object')
667
+ return 'sandboxPolicy.resolve() 未返回对象:补丁写入的授权策略读不出来';
668
+ const value = policy;
669
+ if (typeof value.mode !== 'string')
670
+ return 'sandboxPolicy.resolve() 的返回值缺少字符串 mode';
671
+ if (typeof value.workspaceRoot !== 'string' || value.workspaceRoot === '')
672
+ return 'sandboxPolicy.resolve() 的返回值缺少 workspaceRoot';
673
+ return undefined;
674
+ },
675
+ describe: (t) => {
676
+ try {
677
+ const policy = t.resolve({ mode: 'read-only' });
678
+ return typeof policy?.mode === 'string' ? `观测 read-only → ${policy.mode}` : undefined;
679
+ }
680
+ catch {
681
+ return undefined;
682
+ }
683
+ },
684
+ },
685
+ {
686
+ id: 'tools.get-method',
687
+ label: '按名读取工具定义(get)',
688
+ kind: 'read',
689
+ owner: 'tools',
690
+ fallback: 'inform-only',
691
+ methods: ['get'],
692
+ // `get` 是「这台服务器的共享资源工具此刻注册着没有」与装层前过滤未知名的唯一判据;
693
+ // 缺了它,逐会话资源工具摘除会整段跳过,别的对话的服务器资源重新可见。
694
+ probe: (t) => isFn(t?.get) ? undefined : '宿主工具服务缺少 get():共享资源工具的逐会话摘除与装层前过滤会静默跳过',
695
+ },
696
+ {
697
+ id: 'tools.guard-dispatch',
698
+ label: '工具执行守卫分发(guard / checkGuards)',
699
+ kind: 'write',
700
+ owner: 'tools',
701
+ fallback: 'inform-only',
702
+ methods: ['guard', 'checkGuards'],
703
+ // 只查 `guard` 不够:宿主可能保留注册入口、却不再在 pipeline 里调 checkGuards。
704
+ // 那种情况下注册成功、零报错,停用表与逐会话开关全部失效。
705
+ probe: (t) => isFn(t?.guard) && isFn(t?.checkGuards)
706
+ ? undefined
707
+ : '宿主工具服务缺少 guard() / checkGuards():停用工具与逐会话开关的执行侧拦截不会生效',
708
+ },
709
+ {
710
+ id: 'tools.mcp-resource-args',
711
+ label: 'MCP 共享资源工具参数(server / uri)',
712
+ kind: 'read',
713
+ owner: 'tools',
714
+ fallback: 'inform-only',
715
+ // 只查工具名不够:守卫读的是 `execution.arguments.server`,参数名一改就变成空串,
716
+ // 按「算不出来不拦」静默放行 —— 别的对话的服务器资源可被本对话列出 / 读取。
717
+ probe: (t) => {
718
+ const get = t.get;
719
+ if (typeof get !== 'function')
720
+ return '宿主工具服务缺少 get():无法核对共享资源工具的参数名';
721
+ const requiredByTool = {
722
+ list_mcp_resources: ['server'],
723
+ list_mcp_resource_templates: ['server'],
724
+ read_mcp_resource: ['server', 'uri'],
725
+ };
726
+ for (const [name, required] of Object.entries(requiredByTool)) {
727
+ let definition;
728
+ try {
729
+ definition = get.call(t, name);
730
+ }
731
+ catch {
732
+ definition = undefined;
733
+ }
734
+ // 没有 MCP 服务器时官方不注册这三个工具;一台都没有不是故障。
735
+ if (definition === undefined)
736
+ continue;
737
+ const parameters = definition.parameters;
738
+ const properties = parameters?.properties;
739
+ const list = Array.isArray(parameters?.required) ? parameters.required : [];
740
+ const missing = required.filter((param) => properties === null || typeof properties !== 'object'
741
+ || !(param in properties)
742
+ || !list.includes(param));
743
+ if (missing.length > 0) {
744
+ return `${name} 的参数 ${missing.join('、')} 不在 properties/required 里:逐会话守卫读不到服务器名,会静默放行`;
745
+ }
746
+ }
747
+ return undefined;
748
+ },
749
+ },
750
+ {
751
+ id: 'systemPrompt.mcp-section',
752
+ label: '系统提示词 MCP 段(MCP_SERVERS)',
753
+ kind: 'read',
754
+ owner: 'systemPrompt',
755
+ fallback: 'inform-only',
756
+ methods: ['section', 'getSectionOrder'],
757
+ // `MCP_SERVERS` 改名后 getSectionOrder 返回 undefined,prompt-shadow 直接放弃注册,
758
+ // 别的对话的服务器名与 instructions 会静默进入本对话。
759
+ probe: (t) => {
760
+ const orderOf = t.getSectionOrder;
761
+ if (typeof orderOf !== 'function')
762
+ return '宿主 systemPrompt 缺少 getSectionOrder()';
763
+ let order;
764
+ try {
765
+ order = orderOf.call(t, 'MCP_SERVERS');
766
+ }
767
+ catch (error) {
768
+ return `getSectionOrder("MCP_SERVERS") 抛错:${String(error?.message ?? error)}`;
769
+ }
770
+ return Number.isFinite(order)
771
+ ? undefined
772
+ : 'getSectionOrder("MCP_SERVERS") 没有返回数字:MCP 提示词段排序位变了,跨会话 prompt 隔离无法挂载';
773
+ },
774
+ },
376
775
  ];