dsh-plugin-tool-management 0.21.0 → 0.21.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.
- package/CHANGELOG.md +108 -0
- package/README.md +47 -10
- package/README_EN.md +45 -10
- package/docs/images/1-EN.png +0 -0
- package/docs/images/1.png +0 -0
- package/docs/images/2-EN.png +0 -0
- package/docs/images/2.png +0 -0
- package/docs/images/3-EN.png +0 -0
- package/docs/images/3.png +0 -0
- package/docs/images/4-EN.png +0 -0
- package/docs/images/4.png +0 -0
- package/docs/images/5-EN.png +0 -0
- package/docs/images/5.png +0 -0
- package/docs/images/6-EN.png +0 -0
- package/docs/images/6.png +0 -0
- package/docs/images/7-EN.png +0 -0
- package/docs/images/7.png +0 -0
- package/docs/images/8-EN.png +0 -0
- package/docs/images/8.png +0 -0
- package/docs/images/icon.png +0 -0
- package/docs/images/icon.svg +1 -0
- package/docs/update.md +37 -35
- package/lib/boot/reconcile.js +157 -0
- package/lib/client.js +7166 -3084
- package/lib/compat/patch-dialect.js +14 -1
- package/lib/compat/probe.js +25 -21
- package/lib/context-inject-frame.js +62 -40
- package/lib/context-inject-select.js +59 -4
- package/lib/context-inject-surface.js +49 -3
- package/lib/context-inject.js +145 -22
- package/lib/diagnostics.js +77 -0
- package/lib/http-api.js +39 -23
- package/lib/http-fence.js +40 -5
- package/lib/imports/unzip.js +48 -0
- package/lib/imports/upload.js +8 -36
- package/lib/index.js +2933 -169
- package/lib/mcp/disabled-tools.js +96 -0
- package/lib/mcp/manager.js +559 -128
- package/lib/mcp/restart-marker.js +110 -0
- package/lib/mcp/state-section.js +132 -43
- package/lib/mcp/tool-visibility.js +348 -56
- package/lib/memories/archive-engine.js +39 -14
- package/lib/memories/discovery.js +30 -10
- package/lib/memories/index-io.js +217 -18
- package/lib/memories/projection.js +20 -3
- package/lib/memories/prompt-layer.js +37 -0
- package/lib/memories/search.js +86 -0
- package/lib/memories/service.js +327 -91
- package/lib/memories/snapshot.js +66 -19
- package/lib/op-registry.js +49 -4
- package/lib/ops/candidates.js +11 -3
- package/lib/ops/compat.js +46 -4
- package/lib/ops/memory.js +78 -9
- package/lib/ops/prompts.js +49 -5
- package/lib/ops/quick-prompts.js +24 -2
- package/lib/ops/scene-records.js +7 -0
- package/lib/ops/scene-sync.js +23 -4
- package/lib/ops/scope.js +1093 -0
- package/lib/ops/sessions.js +5 -2
- package/lib/ops/snapshot.js +55 -20
- package/lib/ops/state-doctor.js +39 -4
- package/lib/ops/trash.js +12 -1
- package/lib/paths.js +50 -3
- package/lib/prompts/preset-id.js +4 -0
- package/lib/prompts/project-instructions.js +162 -0
- package/lib/prompts/quick-service.js +5 -4
- package/lib/prompts/service.js +20 -9
- package/lib/request-gate.js +6 -4
- package/lib/scene-linkage.js +12 -0
- package/lib/scene-prompt-sync.js +1 -1
- package/lib/scenes/candidates.js +8 -1
- package/lib/scope/intent-store.js +105 -0
- package/lib/scope/intent.js +376 -0
- package/lib/scope/resolve.js +190 -0
- package/lib/scope/scope-overrides.js +894 -0
- package/lib/scope/store.js +262 -0
- package/lib/scope/workspace-key.js +64 -0
- package/lib/sessions/history.js +3 -2
- package/lib/settings-sidecars.js +82 -19
- package/lib/sidebar-settings.js +13 -0
- package/lib/skills/catalog.js +206 -33
- package/lib/skills/core.js +1 -1
- package/lib/skills/frontmatter.js +121 -0
- package/lib/skills/service.js +145 -20
- package/lib/stale-write.js +74 -0
- package/lib/subagents/catalog.js +47 -13
- package/lib/subagents/persona-parse.js +26 -5
- package/lib/subagents/persona-write.js +11 -7
- package/lib/subagents/service.js +3 -2
- package/lib/subagents/tools.js +78 -8
- package/lib/token-config.js +25 -5
- package/lib/tool-table-switch.js +141 -49
- package/lib/tools/deps.js +151 -5
- package/lib/tools/mcp.js +189 -39
- package/lib/tools/memory.js +103 -18
- package/lib/tools/prompt.js +61 -9
- package/lib/tools/remove.js +46 -21
- package/lib/tools/scene.js +120 -26
- package/lib/tools/skills.js +191 -30
- package/lib/tools/subagent.js +52 -20
- package/lib/tools/table.js +48 -11
- package/lib/trash-retention.js +3 -2
- package/lib/update-check.js +218 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +19 -14
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// MCP 停用表的读取结果与结构校验(纯函数,无 I/O)。
|
|
2
|
+
//
|
|
3
|
+
// 这张表是「关掉危险工具」的唯一依据,读失败不能退化成空表。四态里只有 missing(ENOENT)
|
|
4
|
+
// 可以当空表;corrupt / unreadable 都由调用方按 unknown 处理。
|
|
5
|
+
//
|
|
6
|
+
// 结构错误与「名字不认识」必须分开:前者是文件被改坏,后者可能只是宿主用了本插件正则不
|
|
7
|
+
// 认识的工具名。把后者升级成全表损坏,会让一个合法名字把全部 MCP 工具一起禁掉。
|
|
8
|
+
/** 这些键在普通对象上是原型槽,不是普通属性;出现在侧车里一律按结构错误处理。 */
|
|
9
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
10
|
+
/** 与写入口 / 界面同一套工具名格式;不匹配的名字保留并上报,不升级为整表损坏。 */
|
|
11
|
+
const TOOL_NAME_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
12
|
+
export function isUnsafeKey(key) {
|
|
13
|
+
return UNSAFE_KEYS.has(key);
|
|
14
|
+
}
|
|
15
|
+
/** 空的无原型表:写入、克隆与快照都用它,避免 `__proto__` 赋值改原型。 */
|
|
16
|
+
export function emptyDisabledTools() {
|
|
17
|
+
return Object.create(null);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 安全克隆:只保留字符串数组,丢弃保留键。用于所有写前“读-改-写”的合并点。
|
|
21
|
+
* 注意不能用 `Object.assign({}, map)` —— 目标若是普通对象,`__proto__` 会触发 setter。
|
|
22
|
+
*/
|
|
23
|
+
export function cloneDisabledTools(map) {
|
|
24
|
+
const out = emptyDisabledTools();
|
|
25
|
+
if (!map || typeof map !== 'object')
|
|
26
|
+
return out;
|
|
27
|
+
for (const [serverName, list] of Object.entries(map)) {
|
|
28
|
+
if (isUnsafeKey(serverName) || !Array.isArray(list))
|
|
29
|
+
continue;
|
|
30
|
+
out[serverName] = list.filter((name) => typeof name === 'string').slice();
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function serverKeyProblem(key) {
|
|
35
|
+
if (key === '')
|
|
36
|
+
return '存在空的服务器名';
|
|
37
|
+
if (key.length > 128)
|
|
38
|
+
return `服务器名过长:${key.slice(0, 16)}…`;
|
|
39
|
+
if (/[\u0000-\u001f\u007f]/.test(key))
|
|
40
|
+
return `服务器名含控制字符:${JSON.stringify(key)}`;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 合法 JSON 的结构校验。返回 `ok` 时 value 一定是无原型对象。
|
|
45
|
+
*
|
|
46
|
+
* 结构错误(顶层不是对象、值不是数组、元素不是字符串、空名字、proto 键)→ corrupt;
|
|
47
|
+
* 字符串但不符合本插件工具名格式(例如 `read.file`)→ 原样保留 + warnings。
|
|
48
|
+
*/
|
|
49
|
+
export function classifyDisabledTools(raw) {
|
|
50
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
51
|
+
return { status: 'corrupt', error: '顶层不是对象' };
|
|
52
|
+
}
|
|
53
|
+
const out = emptyDisabledTools();
|
|
54
|
+
const warnings = [];
|
|
55
|
+
const warned = new Set();
|
|
56
|
+
for (const [serverName, rawList] of Object.entries(raw)) {
|
|
57
|
+
if (isUnsafeKey(serverName)) {
|
|
58
|
+
return { status: 'corrupt', error: `服务器名是保留键:${serverName}` };
|
|
59
|
+
}
|
|
60
|
+
const keyProblem = serverKeyProblem(serverName);
|
|
61
|
+
if (keyProblem)
|
|
62
|
+
return { status: 'corrupt', error: keyProblem };
|
|
63
|
+
if (!Array.isArray(rawList)) {
|
|
64
|
+
return { status: 'corrupt', error: `服务器「${serverName}」的值不是数组` };
|
|
65
|
+
}
|
|
66
|
+
const names = [];
|
|
67
|
+
for (const item of rawList) {
|
|
68
|
+
if (typeof item !== 'string') {
|
|
69
|
+
return { status: 'corrupt', error: `服务器「${serverName}」的条目不是字符串` };
|
|
70
|
+
}
|
|
71
|
+
if (item === '') {
|
|
72
|
+
return { status: 'corrupt', error: `服务器「${serverName}」存在空工具名` };
|
|
73
|
+
}
|
|
74
|
+
if (item !== '*' && !TOOL_NAME_RE.test(item) && !warned.has(serverName + '/' + item)) {
|
|
75
|
+
warned.add(serverName + '/' + item);
|
|
76
|
+
warnings.push(serverName + '/' + item);
|
|
77
|
+
}
|
|
78
|
+
if (names.indexOf(item) < 0)
|
|
79
|
+
names.push(item);
|
|
80
|
+
}
|
|
81
|
+
if (names.length)
|
|
82
|
+
out[serverName] = names;
|
|
83
|
+
}
|
|
84
|
+
return { status: 'ok', value: out, warnings };
|
|
85
|
+
}
|
|
86
|
+
/** 停用表不可用时的具名错误:调用方可以据此返回结构化错误,而不是把空表当成事实。 */
|
|
87
|
+
export class DisabledToolsUnavailableError extends Error {
|
|
88
|
+
status;
|
|
89
|
+
detail;
|
|
90
|
+
constructor(status, detail) {
|
|
91
|
+
super(`MCP 停用表${status === 'corrupt' ? '损坏' : '不可读'}:${detail}`);
|
|
92
|
+
this.name = 'DisabledToolsUnavailableError';
|
|
93
|
+
this.status = status;
|
|
94
|
+
this.detail = detail;
|
|
95
|
+
}
|
|
96
|
+
}
|