@dabuliu_wsy/dsh-im 0.0.0-stage → 0.2.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -3
  3. package/cordis.patch.yml +4 -0
  4. package/dist/core/agent-state.d.ts +38 -0
  5. package/dist/core/agent-state.js +59 -0
  6. package/dist/core/arbiter-bridge.d.ts +25 -0
  7. package/dist/core/arbiter-bridge.js +20 -0
  8. package/dist/core/arbiter.d.ts +29 -0
  9. package/dist/core/arbiter.js +59 -0
  10. package/dist/core/avatar-brands.d.ts +23 -0
  11. package/dist/core/avatar-brands.js +75 -0
  12. package/dist/core/avatar-presets.d.ts +21 -0
  13. package/dist/core/avatar-presets.js +38 -0
  14. package/dist/core/avatar.d.ts +1 -0
  15. package/dist/core/avatar.js +18 -0
  16. package/dist/core/blocked.d.ts +12 -0
  17. package/dist/core/blocked.js +23 -0
  18. package/dist/core/budget-plan.d.ts +41 -0
  19. package/dist/core/budget-plan.js +69 -0
  20. package/dist/core/calibration-samples.d.ts +77 -0
  21. package/dist/core/calibration-samples.js +168 -0
  22. package/dist/core/calibrator.d.ts +57 -0
  23. package/dist/core/calibrator.js +125 -0
  24. package/dist/core/chapter-tree.d.ts +128 -0
  25. package/dist/core/chapter-tree.js +400 -0
  26. package/dist/core/consensus.d.ts +135 -0
  27. package/dist/core/consensus.js +394 -0
  28. package/dist/core/context-budget.d.ts +153 -0
  29. package/dist/core/context-budget.js +183 -0
  30. package/dist/core/curator.d.ts +28 -0
  31. package/dist/core/curator.js +190 -0
  32. package/dist/core/dual-window.d.ts +86 -0
  33. package/dist/core/dual-window.js +175 -0
  34. package/dist/core/events.d.ts +110 -0
  35. package/dist/core/events.js +117 -0
  36. package/dist/core/facts.d.ts +114 -0
  37. package/dist/core/facts.js +400 -0
  38. package/dist/core/fence.d.ts +34 -0
  39. package/dist/core/fence.js +129 -0
  40. package/dist/core/floor.d.ts +18 -0
  41. package/dist/core/floor.js +80 -0
  42. package/dist/core/ids.d.ts +11 -0
  43. package/dist/core/ids.js +29 -0
  44. package/dist/core/im.d.ts +167 -0
  45. package/dist/core/im.js +1307 -0
  46. package/dist/core/index.d.ts +33 -0
  47. package/dist/core/index.js +33 -0
  48. package/dist/core/log.d.ts +21 -0
  49. package/dist/core/log.js +63 -0
  50. package/dist/core/memory-claims.d.ts +67 -0
  51. package/dist/core/memory-claims.js +164 -0
  52. package/dist/core/memory-context.d.ts +121 -0
  53. package/dist/core/memory-context.js +303 -0
  54. package/dist/core/memory-visibility.d.ts +58 -0
  55. package/dist/core/memory-visibility.js +36 -0
  56. package/dist/core/memory.d.ts +12 -0
  57. package/dist/core/memory.js +73 -0
  58. package/dist/core/metrics.d.ts +49 -0
  59. package/dist/core/metrics.js +89 -0
  60. package/dist/core/multi-hop.d.ts +116 -0
  61. package/dist/core/multi-hop.js +278 -0
  62. package/dist/core/persist.d.ts +21 -0
  63. package/dist/core/persist.js +94 -0
  64. package/dist/core/proactive.d.ts +54 -0
  65. package/dist/core/proactive.js +108 -0
  66. package/dist/core/prompt.d.ts +82 -0
  67. package/dist/core/prompt.js +164 -0
  68. package/dist/core/receipt.d.ts +107 -0
  69. package/dist/core/receipt.js +86 -0
  70. package/dist/core/retrieval.d.ts +69 -0
  71. package/dist/core/retrieval.js +260 -0
  72. package/dist/core/role-state.d.ts +16 -0
  73. package/dist/core/role-state.js +65 -0
  74. package/dist/core/runtime.d.ts +137 -0
  75. package/dist/core/runtime.js +574 -0
  76. package/dist/core/summary.d.ts +19 -0
  77. package/dist/core/summary.js +96 -0
  78. package/dist/core/text.d.ts +10 -0
  79. package/dist/core/text.js +45 -0
  80. package/dist/core/time.d.ts +22 -0
  81. package/dist/core/time.js +84 -0
  82. package/dist/core/tool-schema.d.ts +12 -0
  83. package/dist/core/tool-schema.js +92 -0
  84. package/dist/core/tools.d.ts +137 -0
  85. package/dist/core/tools.js +348 -0
  86. package/dist/core/types.d.ts +400 -0
  87. package/dist/core/types.js +1 -0
  88. package/dist/core/window.d.ts +6 -0
  89. package/dist/core/window.js +7 -0
  90. package/dist/core/workspace-node.d.ts +28 -0
  91. package/dist/core/workspace-node.js +232 -0
  92. package/dist/core/workspace.d.ts +9 -0
  93. package/dist/core/workspace.js +45 -0
  94. package/dist/host/agent-session.d.ts +279 -0
  95. package/dist/host/agent-session.js +935 -0
  96. package/dist/host/attachment-gc.d.ts +37 -0
  97. package/dist/host/attachment-gc.js +97 -0
  98. package/dist/host/calibration-samples-store.d.ts +5 -0
  99. package/dist/host/calibration-samples-store.js +67 -0
  100. package/dist/host/capabilities.d.ts +45 -0
  101. package/dist/host/capabilities.js +67 -0
  102. package/dist/host/derived-store.d.ts +36 -0
  103. package/dist/host/derived-store.js +199 -0
  104. package/dist/host/dsh-llm.d.ts +143 -0
  105. package/dist/host/dsh-llm.js +395 -0
  106. package/dist/host/event-store.d.ts +47 -0
  107. package/dist/host/event-store.js +154 -0
  108. package/dist/host/fs-atomic.d.ts +1 -0
  109. package/dist/host/fs-atomic.js +26 -0
  110. package/dist/host/im-api.d.ts +352 -0
  111. package/dist/host/im-api.js +1137 -0
  112. package/dist/host/index.d.ts +103 -0
  113. package/dist/host/index.js +453 -0
  114. package/dist/host/memory-index.d.ts +65 -0
  115. package/dist/host/memory-index.js +181 -0
  116. package/dist/host/metrics-store.d.ts +7 -0
  117. package/dist/host/metrics-store.js +104 -0
  118. package/dist/host/models.d.ts +39 -0
  119. package/dist/host/models.js +67 -0
  120. package/dist/host/persona-tools.d.ts +57 -0
  121. package/dist/host/persona-tools.js +226 -0
  122. package/dist/host/preflight.d.ts +31 -0
  123. package/dist/host/preflight.js +29 -0
  124. package/dist/host/receipt-store.d.ts +26 -0
  125. package/dist/host/receipt-store.js +68 -0
  126. package/dist/host/run-check.d.ts +51 -0
  127. package/dist/host/run-check.js +190 -0
  128. package/dist/host/state-roots.d.ts +50 -0
  129. package/dist/host/state-roots.js +163 -0
  130. package/dist/host/tool-cache.d.ts +25 -0
  131. package/dist/host/tool-cache.js +90 -0
  132. package/dist/host/tool-call-budget.d.ts +29 -0
  133. package/dist/host/tool-call-budget.js +38 -0
  134. package/dsh-plugin.json +25 -0
  135. package/lib/client.inner.cjs +3346 -0
  136. package/lib/client.js +3354 -0
  137. package/package.json +86 -6
@@ -0,0 +1,348 @@
1
+ /**
2
+ * 角色工具授权模型:来源组 + 单工具。
3
+ *
4
+ * 背景:DSH 的 tools.register 没有 owner/来源元数据,唯一可靠信号是命名约定
5
+ * (MCP 的 mcp__<server>__<tool>)。所以授权不看“内置还是自己装的”,只看
6
+ * “这个工具属于哪个来源组 / 是否被显式授予”。
7
+ *
8
+ * 授权条目(Persona.toolAllow: string[]):
9
+ * - read/search/write/check:产品内置插件工具能力(read_file/list_dir/search_files/write_file/run_check)
10
+ * - grp:<groupId>:整组授予(含以后新增的工具),例如 grp:mcp:aippt、grp:browser
11
+ * - tool:<toolName>:只授予单个宿主工具
12
+ * - 旧数据兼容:browser → grp:browser,image → grp:image
13
+ *
14
+ * 契约详见 docs/TOOL-GRANTS.md。
15
+ */
16
+ /** 主会话继承下来的能力标签。角色只能从这里减,不能往外加。没有“任意终端”。 */
17
+ export const INHERITED_TOOLS = [
18
+ { id: 'read', label: '读文件' },
19
+ { id: 'search', label: '搜索' },
20
+ { id: 'write', label: '写群目录' },
21
+ { id: 'check', label: '跑检查(测试)' },
22
+ { id: 'memory', label: '读历史(记忆检索)' },
23
+ { id: 'browser', label: '浏览器(bcdp)' },
24
+ { id: 'image', label: '画图(Magpie)' },
25
+ ];
26
+ /** 产品内置的 4 个能力(插件自己注册的工具,不依赖宿主工具层)。 */
27
+ export const CORE_CAPABILITIES = ['read', 'search', 'write', 'check', 'memory'];
28
+ /** 每个内置能力对应的插件工具(native 与 ctx.llm 两条路径共用同一目录)。 */
29
+ export const CORE_CAPABILITY_TOOLS = {
30
+ read: ['read_file'],
31
+ search: ['search_files'],
32
+ write: ['write_file'],
33
+ check: ['run_check'],
34
+ memory: ['memory_search', 'memory_expand'],
35
+ };
36
+ /** list_dir 由读或搜索任一能力覆盖。 */
37
+ export const LIST_DIR_TOOL = 'list_dir';
38
+ /** 新建角色默认勾上的能力。浏览器/画图/宿主扩展默认关闭。 */
39
+ export function defaultToolAllow() {
40
+ return [...CORE_CAPABILITIES];
41
+ }
42
+ export function inheritedToolIds() {
43
+ return INHERITED_TOOLS.map((t) => t.id);
44
+ }
45
+ export function toolLabel(id) {
46
+ return INHERITED_TOOLS.find((t) => t.id === id)?.label ?? id;
47
+ }
48
+ /** 插件注册进模型的工具名。 */
49
+ export const PLUGIN_TOOL_NAMES = [LIST_DIR_TOOL, 'read_file', 'search_files', 'write_file', 'run_check', 'memory_search', 'memory_expand'];
50
+ /** 画图工具(Magpie MCP server 产出)。 */
51
+ export const IMAGE_TOOL_NAMES = new Set([
52
+ 'mcp__magpie-image__generate_image',
53
+ 'mcp__magpie-image__generate_video',
54
+ 'mcp__magpie-image__generation_result',
55
+ ]);
56
+ /**
57
+ * 出厂声明。bcdp / magpie 不再享受代码特例,只是这里的两条声明,
58
+ * 用户配置的 toolGroups 会追加在后面(同 id 覆盖)。
59
+ */
60
+ export const BUILTIN_TOOL_GROUPS = [
61
+ { id: 'browser', label: '浏览器(bcdp)', match: { prefixes: ['bcdp_'] } },
62
+ { id: 'image', label: '画图(Magpie)', match: { mcpServers: ['magpie-image'] } },
63
+ ];
64
+ /** 未声明来源的宿主工具统一落到这个组,仍可单工具勾选。 */
65
+ export const OTHER_TOOL_GROUP = { id: 'ext:other', label: '其他宿主工具(未声明来源)' };
66
+ /** MCP 约定分组的 id 前缀。 */
67
+ export const MCP_GROUP_PREFIX = 'mcp:';
68
+ /**
69
+ * 永远不可授予的宿主工具前缀:连接器管理(配置/发布/导入)属于部署操作,
70
+ * 专家角色任何情况下都不能用。它们不进入工具目录(UI 不可见、不可勾),
71
+ * guard 里还有第二道无条件拒绝。
72
+ */
73
+ export const NEVER_GRANTABLE_PREFIXES = ['mcp_connector_'];
74
+ export function isNeverGrantableHostTool(name) {
75
+ return NEVER_GRANTABLE_PREFIXES.some((prefix) => name.startsWith(prefix));
76
+ }
77
+ /** 从 tools.schemas() 的返回值里取工具名(兼容 string / {name} 两种形状)。 */
78
+ export function schemaToolNames(listed) {
79
+ if (!Array.isArray(listed))
80
+ return [];
81
+ const names = [];
82
+ for (const item of listed) {
83
+ if (typeof item === 'string' && item)
84
+ names.push(item);
85
+ else if (item && typeof item === 'object' && typeof item.name === 'string')
86
+ names.push(item.name);
87
+ }
88
+ return names;
89
+ }
90
+ /** 解析 mcp__<server>__<tool>。 */
91
+ export function mcpServerOf(name) {
92
+ if (!name.startsWith('mcp__'))
93
+ return undefined;
94
+ const rest = name.slice('mcp__'.length);
95
+ const at = rest.indexOf('__');
96
+ if (at <= 0 || at + 2 >= rest.length)
97
+ return undefined;
98
+ return rest.slice(0, at);
99
+ }
100
+ function normalizeDecls(declared) {
101
+ const merged = new Map();
102
+ for (const decl of declared)
103
+ merged.set(decl.id, decl);
104
+ return [...merged.values()];
105
+ }
106
+ /** 一个工具落在哪个声明组(不看 MCP 约定)。 */
107
+ function declaredGroupOf(name, declares) {
108
+ const server = mcpServerOf(name);
109
+ for (const decl of declares) {
110
+ const match = decl.match;
111
+ if (!match)
112
+ continue;
113
+ if (match.names?.includes(name))
114
+ return decl;
115
+ if (match.prefixes?.some((prefix) => prefix.length > 0 && name.startsWith(prefix)))
116
+ return decl;
117
+ if (server !== undefined && match.mcpServers?.includes(server))
118
+ return decl;
119
+ }
120
+ return undefined;
121
+ }
122
+ /** 工具 → 来源组 id(声明优先 → MCP 约定 → 兜底组)。 */
123
+ export function groupIdForTool(name, declared = BUILTIN_TOOL_GROUPS) {
124
+ const decl = declaredGroupOf(name, normalizeDecls(declared));
125
+ if (decl)
126
+ return decl.id;
127
+ const server = mcpServerOf(name);
128
+ if (server !== undefined)
129
+ return `${MCP_GROUP_PREFIX}${server}`;
130
+ return OTHER_TOOL_GROUP.id;
131
+ }
132
+ export function groupLabelFor(groupId, declared = BUILTIN_TOOL_GROUPS) {
133
+ const decl = normalizeDecls(declared).find((item) => item.id === groupId);
134
+ if (decl)
135
+ return decl.label;
136
+ if (groupId.startsWith(MCP_GROUP_PREFIX))
137
+ return `MCP:${groupId.slice(MCP_GROUP_PREFIX.length)}`;
138
+ if (groupId === OTHER_TOOL_GROUP.id)
139
+ return OTHER_TOOL_GROUP.label;
140
+ return groupId;
141
+ }
142
+ /** 发现宿主工具来源组。names 是宿主 tools.schemas() 的全局视图。 */
143
+ export function discoverToolGroups(names, declared = BUILTIN_TOOL_GROUPS) {
144
+ const declares = normalizeDecls(declared);
145
+ const byId = new Map();
146
+ for (const name of [...new Set(names)].sort()) {
147
+ if (PLUGIN_TOOL_NAMES.includes(name))
148
+ continue;
149
+ // 连接器管理等永远不可授予的宿主工具不进目录:UI 不出现,也不参与授权计算。
150
+ if (isNeverGrantableHostTool(name))
151
+ continue;
152
+ const decl = declaredGroupOf(name, declares);
153
+ const server = mcpServerOf(name);
154
+ const builtin = decl !== undefined && BUILTIN_TOOL_GROUPS.some((item) => item.id === decl.id);
155
+ const id = decl?.id ?? (server !== undefined ? `${MCP_GROUP_PREFIX}${server}` : OTHER_TOOL_GROUP.id);
156
+ const group = byId.get(id) ?? {
157
+ id,
158
+ label: decl?.label ?? groupLabelFor(id, declares),
159
+ kind: decl === undefined ? (server !== undefined ? 'mcp' : 'other') : builtin ? 'builtin' : 'declared',
160
+ tools: [],
161
+ };
162
+ group.tools.push(name);
163
+ byId.set(id, group);
164
+ }
165
+ return [...byId.values()];
166
+ }
167
+ /** 产品内置能力 + 宿主来源组的完整目录(客户端角色编辑器 / 状态接口用)。 */
168
+ export function toolGroupCatalog(hostNames, declared = BUILTIN_TOOL_GROUPS) {
169
+ return {
170
+ capabilities: CORE_CAPABILITIES.map((id) => ({
171
+ id,
172
+ label: toolLabel(id),
173
+ tools: [...CORE_CAPABILITY_TOOLS[id]],
174
+ })),
175
+ groups: discoverToolGroups(hostNames, declared),
176
+ };
177
+ }
178
+ /** 解析一个授权条目;非法返回 null。 */
179
+ export function parseGrant(entry) {
180
+ if (typeof entry !== 'string')
181
+ return null;
182
+ const id = entry.trim();
183
+ if (!id)
184
+ return null;
185
+ if (id === 'browser' || id === 'image')
186
+ return { kind: 'group', value: id };
187
+ if (CORE_CAPABILITIES.includes(id))
188
+ return { kind: 'capability', value: id };
189
+ if (id.startsWith('grp:')) {
190
+ const value = id.slice(4).trim();
191
+ return value ? { kind: 'group', value } : null;
192
+ }
193
+ if (id.startsWith('tool:')) {
194
+ const value = id.slice(5).trim();
195
+ return /^[A-Za-z0-9_.:-]+$/.test(value) ? { kind: 'tool', value } : null;
196
+ }
197
+ return null;
198
+ }
199
+ /**
200
+ * 规整授权条目:旧 id 迁移(browser/image → grp:)、去重、丢掉非法/已下线 id。
201
+ * 传了 toolDeny(旧数据)时按“内置能力全集 − deny”换算成 toolAllow。
202
+ */
203
+ export function normalizeToolAllow(ids, deny) {
204
+ const source = Array.isArray(ids)
205
+ ? ids
206
+ : Array.isArray(deny)
207
+ ? inheritedToolIds().filter((id) => !deny.includes(id))
208
+ : undefined;
209
+ if (source === undefined)
210
+ return undefined;
211
+ const out = [];
212
+ const seen = new Set();
213
+ for (const raw of source) {
214
+ if (typeof raw !== 'string')
215
+ continue;
216
+ const parsed = parseGrant(raw);
217
+ if (!parsed)
218
+ continue;
219
+ const normalized = parsed.kind === 'group' ? `grp:${parsed.value}` : parsed.kind === 'tool' ? `tool:${parsed.value}` : parsed.value;
220
+ if (seen.has(normalized))
221
+ continue;
222
+ seen.add(normalized);
223
+ out.push(normalized);
224
+ }
225
+ return out;
226
+ }
227
+ /** 只保留当前存在的能力 id(老数据里的 `shell` 等会被静默丢弃)。 */
228
+ export function legacyKnownToolAllow(ids) {
229
+ if (!Array.isArray(ids))
230
+ return undefined;
231
+ const known = new Set(inheritedToolIds());
232
+ return [...new Set(ids.filter((id) => typeof id === 'string' && known.has(id)))];
233
+ }
234
+ /** 授权条目集合。 */
235
+ export function grantSet(toolAllow) {
236
+ const set = new Set();
237
+ for (const entry of toolAllow ?? []) {
238
+ const parsed = parseGrant(entry);
239
+ if (!parsed)
240
+ continue;
241
+ if (parsed.kind === 'capability')
242
+ set.add(`cap:${parsed.value}`);
243
+ else if (parsed.kind === 'group')
244
+ set.add(`grp:${parsed.value}`);
245
+ else
246
+ set.add(`tool:${parsed.value}`);
247
+ }
248
+ return set;
249
+ }
250
+ /** 插件工具是否被授予(read/search/write/check)。 */
251
+ export function pluginToolGranted(name, toolAllow) {
252
+ if (toolAllow === undefined)
253
+ return true;
254
+ if (name === LIST_DIR_TOOL)
255
+ return toolAllow.includes('read') || toolAllow.includes('search');
256
+ const capability = CORE_CAPABILITIES.find((id) => CORE_CAPABILITY_TOOLS[id].includes(name));
257
+ return capability !== undefined && toolAllow.includes(capability);
258
+ }
259
+ /** 宿主工具是否被授予(单工具或所属组)。 */
260
+ export function hostToolGranted(name, toolAllow, declared = BUILTIN_TOOL_GROUPS) {
261
+ if (toolAllow === undefined)
262
+ return false;
263
+ if (isNeverGrantableHostTool(name))
264
+ return false;
265
+ const grants = grantSet(toolAllow);
266
+ if (grants.has(`tool:${name}`))
267
+ return true;
268
+ return grants.has(`grp:${groupIdForTool(name, declared)}`);
269
+ }
270
+ /** 当前授权下真正生效的宿主工具(用于可见性收窄与会话重建判定)。 */
271
+ export function effectiveHostTools(hostNames, toolAllow, declared = BUILTIN_TOOL_GROUPS) {
272
+ if (toolAllow === undefined)
273
+ return [];
274
+ return [...new Set(hostNames)].filter((name) => hostToolGranted(name, toolAllow, declared)).sort();
275
+ }
276
+ /** 这个角色勾了、但这次没有注册进 agent 的能力(只统计 4 个插件能力)。 */
277
+ export function nativeCapabilityGap(toolAllow, covered = []) {
278
+ const caps = new Set(toolAllow ?? []);
279
+ const have = new Set(covered);
280
+ return CORE_CAPABILITIES.filter((id) => caps.has(id) && !have.has(id));
281
+ }
282
+ /** 勾选对应到要注册的插件工具。list_dir 属于读或搜索。undefined 表示继承全部能力。 */
283
+ export function pluginToolsForAllow(toolAllow) {
284
+ const allowed = new Set(toolAllow ?? inheritedToolIds());
285
+ const names = [];
286
+ if (allowed.has('read') || allowed.has('search'))
287
+ names.push(LIST_DIR_TOOL);
288
+ if (allowed.has('read'))
289
+ names.push('read_file');
290
+ if (allowed.has('search'))
291
+ names.push('search_files');
292
+ if (allowed.has('write'))
293
+ names.push('write_file');
294
+ if (allowed.has('check'))
295
+ names.push('run_check');
296
+ // memory 也是插件能力(两个插件工具),native 与 ctx.llm 两条传输必须同权;
297
+ // 之前漏了这里会让原生会话静默没有记忆工具(真机复验发现)。
298
+ if (allowed.has('memory'))
299
+ names.push(...CORE_CAPABILITY_TOOLS.memory);
300
+ return names;
301
+ }
302
+ /**
303
+ * 宿主工具执行前的硬拒绝。插件工具交给按能力收窄的那一层;宿主工具只认
304
+ * tool:/grp: 授权;另外永远拒绝连接器管理类工具。
305
+ */
306
+ export function personaHostToolDenial(name, toolAllow, declared = BUILTIN_TOOL_GROUPS) {
307
+ if (PLUGIN_TOOL_NAMES.includes(name))
308
+ return undefined;
309
+ if (!name)
310
+ return '专家角色不能使用宿主工具 (未命名)';
311
+ if (name.startsWith('mcp_connector_'))
312
+ return `专家角色不能使用连接器管理工具 ${name}`;
313
+ if (hostToolGranted(name, toolAllow, declared))
314
+ return undefined;
315
+ const group = groupLabelFor(groupIdForTool(name, declared), declared);
316
+ return `专家角色没有授予「${group}」里的工具 ${name}`;
317
+ }
318
+ /** 授权条目的可读标签(成员卡/兼容横幅用)。 */
319
+ export function labelForGrant(entry, catalog) {
320
+ const parsed = parseGrant(entry);
321
+ if (!parsed)
322
+ return entry;
323
+ if (parsed.kind === 'capability')
324
+ return toolLabel(parsed.value);
325
+ if (parsed.kind === 'group') {
326
+ const group = catalog?.groups.find((item) => item.id === parsed.value);
327
+ return group?.label ?? groupLabelFor(parsed.value);
328
+ }
329
+ return `工具 ${parsed.value}`;
330
+ }
331
+ /** 只校验形状,不校验“是否存在”:组/工具可能来自已卸载插件。 */
332
+ export function assertKnownTools(ids) {
333
+ const bad = ids.filter((id) => parseGrant(id) === null);
334
+ if (bad.length)
335
+ throw new Error(`不能新增工具:${bad.join('、')}(只支持 read/search/write/check 或 grp:/tool: 授权)`);
336
+ }
337
+ /** 旧接口:toolAllow/toolDeny → 规整后的 toolAllow。 */
338
+ export function resolveToolFilter(input) {
339
+ if (input.toolAllow) {
340
+ assertKnownTools(input.toolAllow);
341
+ return { toolAllow: normalizeToolAllow(input.toolAllow) };
342
+ }
343
+ if (input.toolDeny) {
344
+ assertKnownTools(input.toolDeny);
345
+ return { toolAllow: normalizeToolAllow(undefined, input.toolDeny) };
346
+ }
347
+ return {};
348
+ }