dsh-model-switch 0.4.71 → 0.4.73
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/CHANGELOG.md +25 -0
- package/PRODUCT.md +1 -1
- package/README.md +2 -0
- package/lib/auto-review-0mh6NLlr.js +1817 -0
- package/lib/auto-review-B4L59yj4.js +1079 -0
- package/lib/auto-review.js +2 -2
- package/lib/automode-compat.js +1 -1
- package/lib/client.js +128 -4
- package/lib/index.js +12 -4
- package/lib/review-timeout-CAlD65wl.js +339 -0
- package/lib/review-timeout.js +1 -1
- package/lib/tool-allowlist-Ddb8jfNx.js +560 -0
- package/lib/types/auto-review-gate.d.ts +186 -0
- package/lib/types/auto-review.d.ts +31 -2
- package/lib/types/capabilities-rpc.d.ts +6 -0
- package/lib/types/client/ModelSwitchSettings.d.ts +2 -0
- package/lib/types/client/locales.d.ts +7 -0
- package/lib/types/client-contract.d.ts +8 -0
- package/lib/types/host-settings.d.ts +11 -0
- package/lib/types/tool-allowlist.d.ts +7 -2
- package/package.json +1 -1
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
/** Catalog lookup by id. */
|
|
2
|
+
const SOURCE_BY_ID = new Map([
|
|
3
|
+
{
|
|
4
|
+
id: "core",
|
|
5
|
+
kind: "core",
|
|
6
|
+
label: "DSH 核心",
|
|
7
|
+
repo: "https://github.com/deepseek-ai/deepseek-harness"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "dsh-ops",
|
|
11
|
+
kind: "plugin",
|
|
12
|
+
label: "插件 · dsh-ops",
|
|
13
|
+
repo: "https://github.com/T-Auto/dsh-ops"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "dsh-browser-cdp",
|
|
17
|
+
kind: "plugin",
|
|
18
|
+
label: "插件 · dsh-browser-cdp",
|
|
19
|
+
repo: "https://github.com/drscrewdriver/dsh-browser-cdp"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "dsh-auto-memory",
|
|
23
|
+
kind: "plugin",
|
|
24
|
+
label: "插件 · dsh-auto-memory",
|
|
25
|
+
repo: "https://github.com/AskTheWay/dsh-auto-memory"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "dsh-model-switch",
|
|
29
|
+
kind: "plugin",
|
|
30
|
+
label: "插件 · dsh-model-switch",
|
|
31
|
+
repo: "https://github.com/vandoor7-droid/dsh-model-switch"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "dsh-prime-memory",
|
|
35
|
+
kind: "plugin",
|
|
36
|
+
label: "插件 · dsh-prime-memory",
|
|
37
|
+
repo: "https://github.com/drscrewdriver/dsh-prime-memory"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "dsh-vision-router",
|
|
41
|
+
kind: "plugin",
|
|
42
|
+
label: "插件 · dsh-vision-router",
|
|
43
|
+
repo: "https://github.com/ysr666/dsh-vision-router"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "dsh-univer-office",
|
|
47
|
+
kind: "plugin",
|
|
48
|
+
label: "插件 · dsh-univer-office",
|
|
49
|
+
repo: "https://github.com/dream-num/dsh-univer-office"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "dsh-embedded-browser",
|
|
53
|
+
kind: "plugin",
|
|
54
|
+
label: "插件 · dsh-embedded-browser",
|
|
55
|
+
repo: "https://github.com/imroc/dsh-embedded-browser"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "dsh-bilibili-summary",
|
|
59
|
+
kind: "plugin",
|
|
60
|
+
label: "插件 · dsh-bilibili-summary",
|
|
61
|
+
repo: "https://github.com/Adamaik/dsh-zcode-plugins"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "dsh-media-lens",
|
|
65
|
+
kind: "plugin",
|
|
66
|
+
label: "插件 · dsh-media-lens",
|
|
67
|
+
repo: "https://github.com/drscrewdriver/dsh-media-lens"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "dsh-video-storyboard",
|
|
71
|
+
kind: "plugin",
|
|
72
|
+
label: "插件 · dsh-video-storyboard",
|
|
73
|
+
repo: "https://github.com/SAOS-3624/dsh-video-storyboard"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "dsh-video-studio",
|
|
77
|
+
kind: "plugin",
|
|
78
|
+
label: "插件 · dsh-video-studio",
|
|
79
|
+
repo: "https://github.com/vandoor7-droid/dsh-video-studio"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "dsh-meme-radar",
|
|
83
|
+
kind: "plugin",
|
|
84
|
+
label: "插件 · dsh-meme-radar",
|
|
85
|
+
repo: "https://github.com/vandoor7-droid/dsh-meme-radar"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "dsh-windows-mcp",
|
|
89
|
+
kind: "plugin",
|
|
90
|
+
label: "插件 · dsh-windows-mcp",
|
|
91
|
+
repo: "https://github.com/helloHub1212/dsh-windows-mcp"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "mcp:wincu",
|
|
95
|
+
kind: "mcp",
|
|
96
|
+
label: "MCP · wincu(dsh-computer-use-win)",
|
|
97
|
+
repo: "https://github.com/Yu-tao-Li/dsh-computer-use-win"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "mcp:mineru-mcp",
|
|
101
|
+
kind: "mcp",
|
|
102
|
+
label: "MCP · mineru-mcp(@vandoor2/mineru-mcp)",
|
|
103
|
+
repo: "https://gitee.com/vandoor2/mineru-mcp"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "qqbot-extension",
|
|
107
|
+
kind: "extension",
|
|
108
|
+
label: "QQ 机器人扩展(框架 @zaofan/dsh-qqbot)",
|
|
109
|
+
repo: "https://github.com/zaofan-make/dsh-qqbot"
|
|
110
|
+
}
|
|
111
|
+
].map((entry) => [entry.id, entry]));
|
|
112
|
+
/**
|
|
113
|
+
* Tool names the released Host owns, calibrated against dsh 0.2.1-rc.2.
|
|
114
|
+
*
|
|
115
|
+
* A name outside the catalog would otherwise be reported as core, which is the
|
|
116
|
+
* one guess a reader could act on wrongly; it resolves to `unknown` instead.
|
|
117
|
+
*/
|
|
118
|
+
const CORE_TOOLS = /* @__PURE__ */ new Set([
|
|
119
|
+
"ask_user_question",
|
|
120
|
+
"conversation_search",
|
|
121
|
+
"create_goal",
|
|
122
|
+
"create_skill",
|
|
123
|
+
"create_worktree",
|
|
124
|
+
"edit",
|
|
125
|
+
"exit_plan_mode",
|
|
126
|
+
"get_goal",
|
|
127
|
+
"glob",
|
|
128
|
+
"grep",
|
|
129
|
+
"interrupt_agent",
|
|
130
|
+
"job_kill",
|
|
131
|
+
"job_list",
|
|
132
|
+
"job_output",
|
|
133
|
+
"list_agents",
|
|
134
|
+
"list_mcp_resource_templates",
|
|
135
|
+
"list_subagent_models",
|
|
136
|
+
"list_mcp_resources",
|
|
137
|
+
"load_workspace_dependencies",
|
|
138
|
+
"present",
|
|
139
|
+
"pwsh",
|
|
140
|
+
"ralph",
|
|
141
|
+
"read",
|
|
142
|
+
"read_image",
|
|
143
|
+
"read_mcp_resource",
|
|
144
|
+
"run_code",
|
|
145
|
+
"schedule_create",
|
|
146
|
+
"schedule_delete",
|
|
147
|
+
"schedule_edit",
|
|
148
|
+
"schedule_list",
|
|
149
|
+
"schedule_update",
|
|
150
|
+
"schedule_view",
|
|
151
|
+
"send_message",
|
|
152
|
+
"session_event_read",
|
|
153
|
+
"session_event_search",
|
|
154
|
+
"session_event_trace",
|
|
155
|
+
"session_search",
|
|
156
|
+
"session_trace",
|
|
157
|
+
"sidebar_open",
|
|
158
|
+
"skill",
|
|
159
|
+
"spawn_teammate",
|
|
160
|
+
"subagent",
|
|
161
|
+
"subagent_fork",
|
|
162
|
+
"team_task_create",
|
|
163
|
+
"team_task_get",
|
|
164
|
+
"team_task_list",
|
|
165
|
+
"team_task_update",
|
|
166
|
+
"terminal_close",
|
|
167
|
+
"terminal_list",
|
|
168
|
+
"terminal_open",
|
|
169
|
+
"terminal_read",
|
|
170
|
+
"terminal_send",
|
|
171
|
+
"terminal_signal",
|
|
172
|
+
"todo_write",
|
|
173
|
+
"update_goal",
|
|
174
|
+
"user_terminal_list",
|
|
175
|
+
"user_terminal_read",
|
|
176
|
+
"wait_agent",
|
|
177
|
+
"web_fetch",
|
|
178
|
+
"web_search",
|
|
179
|
+
"web_search_pro",
|
|
180
|
+
"workflow",
|
|
181
|
+
"working_directory",
|
|
182
|
+
"write"
|
|
183
|
+
]);
|
|
184
|
+
/** MCP server name → catalog id, for the servers this allowlist knows. */
|
|
185
|
+
const MCP_SERVERS = /* @__PURE__ */ new Map([["wincu", "mcp:wincu"], ["mineru-mcp", "mcp:mineru-mcp"]]);
|
|
186
|
+
/** Plugin identity by tool-name prefix (checked before the core catalog). */
|
|
187
|
+
const PLUGIN_PREFIXES = [
|
|
188
|
+
["bcdp_", "dsh-browser-cdp"],
|
|
189
|
+
["browser_window_", "dsh-browser-cdp"],
|
|
190
|
+
["browser_embedded_", "dsh-embedded-browser"],
|
|
191
|
+
["ops_", "dsh-ops"],
|
|
192
|
+
["vision_", "dsh-vision-router"],
|
|
193
|
+
["univer_", "dsh-univer-office"],
|
|
194
|
+
["bilibili_", "dsh-bilibili-summary"],
|
|
195
|
+
["media_read_", "dsh-media-lens"],
|
|
196
|
+
["video_", "dsh-video-storyboard"],
|
|
197
|
+
["studio_", "dsh-video-studio"],
|
|
198
|
+
["meme_", "dsh-meme-radar"]
|
|
199
|
+
];
|
|
200
|
+
/**
|
|
201
|
+
* Single plugin tools that carry no usable prefix.
|
|
202
|
+
*
|
|
203
|
+
* `memory_` is shared by two installed plugins with disjoint names, so it cannot
|
|
204
|
+
* be a prefix rule: the calibration below names each tool explicitly.
|
|
205
|
+
*/
|
|
206
|
+
const PLUGIN_TOOLS = /* @__PURE__ */ new Map([
|
|
207
|
+
["generate_image", "dsh-model-switch"],
|
|
208
|
+
["memory_add", "dsh-prime-memory"],
|
|
209
|
+
["memory_conflicts", "dsh-prime-memory"],
|
|
210
|
+
["memory_conflicts_rejected", "dsh-prime-memory"],
|
|
211
|
+
["memory_delete", "dsh-prime-memory"],
|
|
212
|
+
["memory_expand_graph_node", "dsh-prime-memory"],
|
|
213
|
+
["memory_import", "dsh-prime-memory"],
|
|
214
|
+
["memory_migrate_relation", "dsh-prime-memory"],
|
|
215
|
+
["memory_read_scene", "dsh-prime-memory"],
|
|
216
|
+
["memory_receipts", "dsh-prime-memory"],
|
|
217
|
+
["memory_reproject", "dsh-prime-memory"],
|
|
218
|
+
["memory_resolve_conflict", "dsh-prime-memory"],
|
|
219
|
+
["memory_room_admin", "dsh-prime-memory"],
|
|
220
|
+
["memory_room_review", "dsh-prime-memory"],
|
|
221
|
+
["memory_ruminate", "dsh-prime-memory"],
|
|
222
|
+
["memory_ruminate_cancel", "dsh-prime-memory"],
|
|
223
|
+
["memory_ruminate_status", "dsh-prime-memory"],
|
|
224
|
+
["memory_search", "dsh-prime-memory"],
|
|
225
|
+
["memory_search_graph", "dsh-prime-memory"],
|
|
226
|
+
["memory_skill_archive", "dsh-prime-memory"],
|
|
227
|
+
["memory_skill_list", "dsh-prime-memory"],
|
|
228
|
+
["memory_skill_pin", "dsh-prime-memory"],
|
|
229
|
+
["memory_skill_read", "dsh-prime-memory"],
|
|
230
|
+
["memory_slot_close", "dsh-prime-memory"],
|
|
231
|
+
["memory_slot_list", "dsh-prime-memory"],
|
|
232
|
+
["memory_slot_write", "dsh-prime-memory"],
|
|
233
|
+
["memory_update", "dsh-prime-memory"],
|
|
234
|
+
["memory_context", "dsh-auto-memory"],
|
|
235
|
+
["memory_delete_all", "dsh-auto-memory"],
|
|
236
|
+
["memory_list", "dsh-auto-memory"],
|
|
237
|
+
["memory_prune", "dsh-auto-memory"],
|
|
238
|
+
["memory_read", "dsh-auto-memory"],
|
|
239
|
+
["memory_write", "dsh-auto-memory"],
|
|
240
|
+
["hotlist_scan", "dsh-meme-radar"],
|
|
241
|
+
["windows_mcp_doctor", "dsh-windows-mcp"]
|
|
242
|
+
]);
|
|
243
|
+
/** `<base>__<owner>` — the extension-tool naming the QQ bot framework uses. */
|
|
244
|
+
const EXTENSION_TOOL = /^([A-Za-z0-9_-]+)__(.+)$/;
|
|
245
|
+
/**
|
|
246
|
+
* Default allowlist: every pure-read tool this deployment exposes plus the
|
|
247
|
+
* no-side-effect and autonomy entries the user explicitly released, calibrated
|
|
248
|
+
* on a live desktop profile (105 tools) at dsh 0.2.1-rc.2.
|
|
249
|
+
*
|
|
250
|
+
* Grouped by origin so a reader can trace each entry through {@link SOURCE_CATALOG}.
|
|
251
|
+
* Entries ending in `*` are patterns: the QQ bot extension suffixes its tools with
|
|
252
|
+
* the bot's own name, so `sessions_list__*` keeps working when the persona is
|
|
253
|
+
* renamed.
|
|
254
|
+
*
|
|
255
|
+
* Everything here follows one rule: releasing it must not let a side effect escape
|
|
256
|
+
* the reviewer. Calls that merely dispatch, ask, present, wait or navigate qualify
|
|
257
|
+
* because the work they trigger still runs under the same auto preset. Delegation
|
|
258
|
+
* tools (`subagent`, `subagent_fork`, `spawn_teammate`) deliberately stay out: a
|
|
259
|
+
* child session seeds its preset from `permissionPresets.current(parent.session)`,
|
|
260
|
+
* and this bypass answers `'custom'` for an allowlisted call in flight — releasing
|
|
261
|
+
* them would hand the child no `auto` preset at all, i.e. no review.
|
|
262
|
+
* Beyond that rule sit the entries the user explicitly released (2026-10-24:
|
|
263
|
+
* goal/schedule/terminal creation; 2026-11-20: the vision model calls, the
|
|
264
|
+
* mineru document_parse task, todo/goal updates, and the prime-memory write
|
|
265
|
+
* tools; 2026-11-22: the media-lens file reads and the video storyboard
|
|
266
|
+
* search/decode tools). These do have side effects — vision calls spend the configured
|
|
267
|
+
* backend's quota and send image content to it, document_parse spawns a parse
|
|
268
|
+
* task, the memory tools mutate the memory store — but everything they enable
|
|
269
|
+
* stays inside the same session and auto preset. Releasing them only skips the
|
|
270
|
+
* reviewer; it grants no permission the preset did not already grant. The
|
|
271
|
+
* delegation spawns stay excluded regardless: a child session seeds its preset
|
|
272
|
+
* from the parent's in-flight bypass answer, so releasing them would strip the
|
|
273
|
+
* child of the auto preset entirely (see DELEGATION_SPAWNS in the tests).
|
|
274
|
+
* schedule_edit was reviewed on 2026-11-20 and deliberately kept OUT: it can
|
|
275
|
+
* modify or delete tasks other sessions created. bilibili_login (writes the
|
|
276
|
+
* stored sign-in session), bilibili_transcribe (its first run builds a private
|
|
277
|
+
* virtualenv, downloads a whisper model and the audio) and meme_add (writes
|
|
278
|
+
* the meme library) were reviewed on 2026-11-22 and stay OUT for the same
|
|
279
|
+
* reason.
|
|
280
|
+
*/
|
|
281
|
+
const DEFAULT_READ_ONLY_TOOLS = [
|
|
282
|
+
"read",
|
|
283
|
+
"grep",
|
|
284
|
+
"glob",
|
|
285
|
+
"read_image",
|
|
286
|
+
"skill",
|
|
287
|
+
"web_search",
|
|
288
|
+
"web_search_pro",
|
|
289
|
+
"web_fetch",
|
|
290
|
+
"load_workspace_dependencies",
|
|
291
|
+
"ask_user_question",
|
|
292
|
+
"present",
|
|
293
|
+
"sidebar_open",
|
|
294
|
+
"exit_plan_mode",
|
|
295
|
+
"job_list",
|
|
296
|
+
"job_output",
|
|
297
|
+
"terminal_list",
|
|
298
|
+
"terminal_read",
|
|
299
|
+
"list_agents",
|
|
300
|
+
"team_task_list",
|
|
301
|
+
"team_task_get",
|
|
302
|
+
"get_goal",
|
|
303
|
+
"schedule_list",
|
|
304
|
+
"wait_agent",
|
|
305
|
+
"send_message",
|
|
306
|
+
"team_task_create",
|
|
307
|
+
"list_mcp_resources",
|
|
308
|
+
"list_mcp_resource_templates",
|
|
309
|
+
"read_mcp_resource",
|
|
310
|
+
"session_search",
|
|
311
|
+
"session_event_search",
|
|
312
|
+
"session_event_read",
|
|
313
|
+
"session_event_trace",
|
|
314
|
+
"session_trace",
|
|
315
|
+
"create_goal",
|
|
316
|
+
"schedule_create",
|
|
317
|
+
"terminal_open",
|
|
318
|
+
"ops_read_files",
|
|
319
|
+
"ops_discover_tools",
|
|
320
|
+
"bcdp_status",
|
|
321
|
+
"bcdp_help",
|
|
322
|
+
"bcdp_doctor",
|
|
323
|
+
"bcdp_snapshot",
|
|
324
|
+
"browser_window_status",
|
|
325
|
+
"memory_list",
|
|
326
|
+
"memory_read",
|
|
327
|
+
"memory_search",
|
|
328
|
+
"memory_search_graph",
|
|
329
|
+
"memory_expand_graph_node",
|
|
330
|
+
"memory_read_scene",
|
|
331
|
+
"memory_skill_list",
|
|
332
|
+
"memory_skill_read",
|
|
333
|
+
"memory_slot_list",
|
|
334
|
+
"memory_receipts",
|
|
335
|
+
"memory_conflicts",
|
|
336
|
+
"memory_conflicts_rejected",
|
|
337
|
+
"memory_ruminate_status",
|
|
338
|
+
"ops_glob",
|
|
339
|
+
"ops_grep",
|
|
340
|
+
"ops_inspect_local_file",
|
|
341
|
+
"ops_read_docx",
|
|
342
|
+
"ops_diff",
|
|
343
|
+
"ops_result",
|
|
344
|
+
"bcdp_captcha",
|
|
345
|
+
"bcdp_page_info",
|
|
346
|
+
"bcdp_read_element",
|
|
347
|
+
"bcdp_screenshot",
|
|
348
|
+
"browser_embedded_status",
|
|
349
|
+
"browser_embedded_snapshot",
|
|
350
|
+
"browser_embedded_screenshot",
|
|
351
|
+
"browser_embedded_ask_human",
|
|
352
|
+
"conversation_search",
|
|
353
|
+
"mcp__wincu__windows_computer_use_accessibility_tree",
|
|
354
|
+
"mcp__wincu__windows_computer_use_element_info",
|
|
355
|
+
"mcp__wincu__windows_computer_use_find",
|
|
356
|
+
"mcp__wincu__windows_computer_use_health",
|
|
357
|
+
"mcp__wincu__windows_computer_use_list_windows",
|
|
358
|
+
"mcp__wincu__windows_computer_use_ocr",
|
|
359
|
+
"mcp__wincu__windows_computer_use_screenshot",
|
|
360
|
+
"mcp__wincu__windows_computer_use_snapshot",
|
|
361
|
+
"mcp__wincu__windows_computer_use_tools",
|
|
362
|
+
"mcp__wincu__windows_computer_use_wait",
|
|
363
|
+
"mcp__wincu__windows_computer_use_wait_for",
|
|
364
|
+
"schedule_view",
|
|
365
|
+
"vision_colors",
|
|
366
|
+
"vision_crop",
|
|
367
|
+
"vision_trace",
|
|
368
|
+
"vision_extract_foreground",
|
|
369
|
+
"vision_materialize",
|
|
370
|
+
"vision_pixel_diff",
|
|
371
|
+
"vision_html_screenshot",
|
|
372
|
+
"vision_present",
|
|
373
|
+
"univer_status",
|
|
374
|
+
"univer_inspect",
|
|
375
|
+
"univer_lint",
|
|
376
|
+
"univer_api",
|
|
377
|
+
"mcp__mineru-mcp__get_task_progress",
|
|
378
|
+
"mcp__mineru-mcp__get_recent_logs",
|
|
379
|
+
"mcp__mineru-mcp__wait_for_task",
|
|
380
|
+
"user_terminal_list",
|
|
381
|
+
"user_terminal_read",
|
|
382
|
+
"windows_mcp_doctor",
|
|
383
|
+
"meme_query",
|
|
384
|
+
"hotlist_scan",
|
|
385
|
+
"bilibili_video_info",
|
|
386
|
+
"bilibili_series",
|
|
387
|
+
"bilibili_subtitles",
|
|
388
|
+
"video_help",
|
|
389
|
+
"video_probe",
|
|
390
|
+
"video_storyboard_settings",
|
|
391
|
+
"studio_status",
|
|
392
|
+
"studio_open",
|
|
393
|
+
"vision_describe",
|
|
394
|
+
"vision_bootstrap",
|
|
395
|
+
"vision_ground",
|
|
396
|
+
"vision_detect",
|
|
397
|
+
"vision_ocr",
|
|
398
|
+
"vision_long_screenshot_ocr",
|
|
399
|
+
"mcp__mineru-mcp__document_parse",
|
|
400
|
+
"todo_write",
|
|
401
|
+
"update_goal",
|
|
402
|
+
"list_subagent_models",
|
|
403
|
+
"memory_write",
|
|
404
|
+
"memory_resolve_conflict",
|
|
405
|
+
"memory_room_admin",
|
|
406
|
+
"memory_room_review",
|
|
407
|
+
"memory_ruminate",
|
|
408
|
+
"memory_skill_archive",
|
|
409
|
+
"memory_skill_pin",
|
|
410
|
+
"memory_slot_close",
|
|
411
|
+
"memory_slot_write",
|
|
412
|
+
"memory_add",
|
|
413
|
+
"memory_update",
|
|
414
|
+
"memory_delete",
|
|
415
|
+
"memory_import",
|
|
416
|
+
"memory_migrate_relation",
|
|
417
|
+
"memory_reproject",
|
|
418
|
+
"memory_ruminate_cancel",
|
|
419
|
+
"media_read_image",
|
|
420
|
+
"media_read_audio",
|
|
421
|
+
"media_read_pdf",
|
|
422
|
+
"media_read_video",
|
|
423
|
+
"video_locate",
|
|
424
|
+
"video_storyboard",
|
|
425
|
+
"video_subtitles",
|
|
426
|
+
"video_zoom",
|
|
427
|
+
"sessions_list__*",
|
|
428
|
+
"bing_search__*"
|
|
429
|
+
];
|
|
430
|
+
/**
|
|
431
|
+
* Validate one allowlist entry.
|
|
432
|
+
*
|
|
433
|
+
* `*` is a suffix wildcard: the entry must keep at least one literal leading
|
|
434
|
+
* character, so a stray `*` can never turn the list into "allow everything".
|
|
435
|
+
*
|
|
436
|
+
* @param entry - the raw entry as typed in settings.
|
|
437
|
+
* @returns `ok`, or the specific problem.
|
|
438
|
+
*/
|
|
439
|
+
function validateAllowEntry(entry) {
|
|
440
|
+
const trimmed = entry.trim();
|
|
441
|
+
if (trimmed === "") return "empty";
|
|
442
|
+
if (/^\*+$/.test(trimmed)) return "bare-wildcard";
|
|
443
|
+
if (trimmed.startsWith("*")) return "leading-wildcard";
|
|
444
|
+
return "ok";
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Whether a tool name matches one allowlist entry.
|
|
448
|
+
*
|
|
449
|
+
* Exact names match exactly; an entry may end in `*`, which matches any
|
|
450
|
+
* remaining characters (including none). Invalid entries never match.
|
|
451
|
+
*
|
|
452
|
+
* @param name - the tool name from `exec.name`.
|
|
453
|
+
* @param entry - one allowlist entry.
|
|
454
|
+
* @returns true when the call may skip review.
|
|
455
|
+
*/
|
|
456
|
+
function matchesAllowPattern(name, entry) {
|
|
457
|
+
if (name === "" || validateAllowEntry(entry) !== "ok") return false;
|
|
458
|
+
const trimmed = entry.trim();
|
|
459
|
+
const star = trimmed.indexOf("*");
|
|
460
|
+
if (star === -1) return name === trimmed;
|
|
461
|
+
const prefix = trimmed.slice(0, star);
|
|
462
|
+
const suffix = trimmed.slice(star + 1);
|
|
463
|
+
if (!name.startsWith(prefix) || !name.endsWith(suffix)) return false;
|
|
464
|
+
return name.length >= prefix.length + suffix.length;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Whether a tool name is covered by an allowlist.
|
|
468
|
+
* @param name - the tool name under review.
|
|
469
|
+
* @param allowlist - configured entries, patterns included.
|
|
470
|
+
* @returns true when at least one entry matches.
|
|
471
|
+
*/
|
|
472
|
+
function isAllowedByList(name, allowlist) {
|
|
473
|
+
return allowlist.some((entry) => matchesAllowPattern(name, entry));
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Resolve the origin of one tool name for display.
|
|
477
|
+
*
|
|
478
|
+
* Resolution order: MCP bridge → `<tool>__<owner>` extension → plugin prefix →
|
|
479
|
+
* plugin table → core catalog → unknown. Only the first two are structural; the
|
|
480
|
+
* rest are calibrated names, so an unlisted tool is reported as unknown rather
|
|
481
|
+
* than guessed into a package.
|
|
482
|
+
*
|
|
483
|
+
* @param name - the tool name.
|
|
484
|
+
* @returns The origin, with its repository when known.
|
|
485
|
+
*/
|
|
486
|
+
function resolveToolSource(name) {
|
|
487
|
+
const trimmed = name.trim().replace(/\*+$/, "");
|
|
488
|
+
const mcp = /^mcp__([A-Za-z0-9_-]+)__/.exec(trimmed);
|
|
489
|
+
if (mcp !== null) {
|
|
490
|
+
const server = mcp[1];
|
|
491
|
+
const entry = SOURCE_BY_ID.get(MCP_SERVERS.get(server) ?? "");
|
|
492
|
+
if (entry !== void 0) return {
|
|
493
|
+
kind: "mcp",
|
|
494
|
+
label: entry.label,
|
|
495
|
+
repo: entry.repo,
|
|
496
|
+
owner: server
|
|
497
|
+
};
|
|
498
|
+
return {
|
|
499
|
+
kind: "mcp",
|
|
500
|
+
label: `MCP · ${server}`,
|
|
501
|
+
owner: server
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
const extension = EXTENSION_TOOL.exec(trimmed);
|
|
505
|
+
if (extension !== null && !trimmed.startsWith("mcp__")) {
|
|
506
|
+
const entry = SOURCE_BY_ID.get("qqbot-extension");
|
|
507
|
+
const base = extension[1];
|
|
508
|
+
const owner = extension[2];
|
|
509
|
+
return {
|
|
510
|
+
kind: "extension",
|
|
511
|
+
label: `扩展 · ${base}__${owner}`,
|
|
512
|
+
...entry === void 0 ? {} : { repo: entry.repo },
|
|
513
|
+
owner
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
if (trimmed.endsWith("__")) {
|
|
517
|
+
const entry = SOURCE_BY_ID.get("qqbot-extension");
|
|
518
|
+
return {
|
|
519
|
+
kind: "extension",
|
|
520
|
+
label: `扩展 · ${trimmed.slice(0, -2)}__*`,
|
|
521
|
+
...entry === void 0 ? {} : { repo: entry.repo },
|
|
522
|
+
owner: "*"
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
for (const [prefix, id] of PLUGIN_PREFIXES) {
|
|
526
|
+
if (!trimmed.startsWith(prefix)) continue;
|
|
527
|
+
const entry = SOURCE_BY_ID.get(id);
|
|
528
|
+
if (entry !== void 0) return {
|
|
529
|
+
kind: "plugin",
|
|
530
|
+
label: entry.label,
|
|
531
|
+
repo: entry.repo,
|
|
532
|
+
owner: id
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
const plugin = PLUGIN_TOOLS.get(trimmed);
|
|
536
|
+
if (plugin !== void 0) {
|
|
537
|
+
const entry = SOURCE_BY_ID.get(plugin);
|
|
538
|
+
if (entry !== void 0) return {
|
|
539
|
+
kind: "plugin",
|
|
540
|
+
label: entry.label,
|
|
541
|
+
repo: entry.repo,
|
|
542
|
+
owner: plugin
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (CORE_TOOLS.has(trimmed)) {
|
|
546
|
+
const entry = SOURCE_BY_ID.get("core");
|
|
547
|
+
return {
|
|
548
|
+
kind: "core",
|
|
549
|
+
label: entry?.label ?? "DSH 核心",
|
|
550
|
+
...entry === void 0 ? {} : { repo: entry.repo },
|
|
551
|
+
owner: "core"
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
kind: "unknown",
|
|
556
|
+
label: "未知来源"
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
export { isAllowedByList as n, resolveToolSource as r, DEFAULT_READ_ONLY_TOOLS as t };
|