dsh-plugin-tool-management 0.21.3 → 0.21.5
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 +42 -0
- package/README.md +14 -14
- package/README_EN.md +5 -3
- package/docs/UPDATE.md +2 -0
- package/lib/client.js +465 -178
- package/lib/confirm-gate.js +134 -0
- package/lib/index.js +66 -13
- package/lib/memories/archive-engine.js +1 -1
- package/lib/op-registry.js +5 -1
- package/lib/ops/scope.js +114 -11
- package/lib/scope/intent.js +6 -5
- package/lib/subagents/tools.js +11 -2
- package/lib/tools/deps.js +61 -5
- package/lib/tools/mcp.js +29 -6
- package/lib/tools/memory.js +17 -4
- package/lib/tools/prompt.js +9 -3
- package/lib/tools/remove.js +101 -17
- package/lib/tools/scene.js +17 -3
- package/lib/tools/skills.js +12 -3
- package/lib/tools/table.js +4 -1
- package/package.json +2 -2
- package/docs/images/icon.png +0 -0
- package/docs/images/promo-cover-EN.png +0 -0
- package/docs/images/promo-cover.png +0 -0
package/lib/tools/deps.js
CHANGED
|
@@ -22,6 +22,57 @@ export function toolNameList(list) {
|
|
|
22
22
|
const head = list.slice(0, TOOL_NAME_LIST_CAP).join(', ');
|
|
23
23
|
return list.length > TOOL_NAME_LIST_CAP ? head + ' ...(' + list.length + ' total)' : head;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 同 `candidateNote`,候选已经在手上时用这个(同步、不读盘)。
|
|
27
|
+
*
|
|
28
|
+
* 多数错误路径上数据本来就扫到了(`rules-list` / `skill-state` / `rows` 都在作用域里),
|
|
29
|
+
* 再包一层 thunk 只是绕路。
|
|
30
|
+
*/
|
|
31
|
+
export function existingNote(names, label) {
|
|
32
|
+
const list = (names || []).map((v) => String(v ?? '').trim()).filter((v) => v !== '');
|
|
33
|
+
if (!list.length)
|
|
34
|
+
return '';
|
|
35
|
+
return ' Existing ' + label + ': ' + toolNameList(list) + '.';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 错误消息里的「现成候选」:只在出错时出现,不进 schema,所以不占每轮预算。
|
|
39
|
+
*
|
|
40
|
+
* 为什么不写进参数说明:候选随数据变,写进描述必然很快过期,而且每轮都要付一次 token。
|
|
41
|
+
* 模型缺参数、名字打错之后再告诉它「现成的是这几个」,正好是它需要的那一刻 —— 这也正是
|
|
42
|
+
* 口语请求最容易断的一环(用户说「删掉那条记忆」,模型手里只有一个叫法,没有 id)。
|
|
43
|
+
*
|
|
44
|
+
* `read` 失败一律返回空串:取候选失败绝不能改变错误结论 —— 原报错更接近真相。
|
|
45
|
+
*/
|
|
46
|
+
export async function candidateNote(read, label) {
|
|
47
|
+
let raw = [];
|
|
48
|
+
try {
|
|
49
|
+
raw = await read();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
return existingNote(raw, label);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 运行时点名一条工具:在它手里才点名,否则退回中性说法。
|
|
58
|
+
*
|
|
59
|
+
* 静态描述里不能这么做(契约测试会拦),而且指一条模型没有的工具本来就是把它往墙上推。
|
|
60
|
+
* 错误消息与回执是运行时分支、可以点名,但判据仍是 `toolVisibleFor` —— 「这是错误消息
|
|
61
|
+
* 所以随便写」是错的理解:那条约束的实质是「不让模型看见它手里没有的东西」,与字符串
|
|
62
|
+
* 写在哪一行无关。
|
|
63
|
+
*
|
|
64
|
+
* 判定本身抛错时按**不可见**处理:中性说法永远成立,点名可能落空。
|
|
65
|
+
*/
|
|
66
|
+
export function toolOrNeutral(deps, agent, tool, named, neutral) {
|
|
67
|
+
let visible = false;
|
|
68
|
+
try {
|
|
69
|
+
visible = deps.toolVisibleFor(tool, agent);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
visible = false;
|
|
73
|
+
}
|
|
74
|
+
return visible ? named : neutral;
|
|
75
|
+
}
|
|
25
76
|
/**
|
|
26
77
|
* 按名字找技能落在哪个来源(root)。
|
|
27
78
|
*
|
|
@@ -36,25 +87,30 @@ export function toolNameList(list) {
|
|
|
36
87
|
* `shadowedBy` 盖住的那一份(同名组里胜出的只有一个),都没有就取第一个。
|
|
37
88
|
*/
|
|
38
89
|
export async function locateSkillRoot(skillsOps, name) {
|
|
90
|
+
const empty = { ok: true, root: null, canonical: null, roots: [], matches: [], names: [] };
|
|
39
91
|
const wanted = String(name || '').trim();
|
|
40
92
|
if (wanted === '')
|
|
41
|
-
return
|
|
93
|
+
return empty;
|
|
42
94
|
let state;
|
|
43
95
|
try {
|
|
44
96
|
state = await skillsOps['skill-state']({});
|
|
45
97
|
}
|
|
46
98
|
catch {
|
|
47
|
-
return { ok: false, root: null, canonical: null, roots: [], matches: [] };
|
|
99
|
+
return { ok: false, root: null, canonical: null, roots: [], matches: [], names: [] };
|
|
48
100
|
}
|
|
49
101
|
if (!state || state.ok === false)
|
|
50
|
-
return { ok: false, root: null, canonical: null, roots: [], matches: [] };
|
|
102
|
+
return { ok: false, root: null, canonical: null, roots: [], matches: [], names: [] };
|
|
51
103
|
const roots = [];
|
|
104
|
+
const names = [];
|
|
52
105
|
const hits = [];
|
|
53
106
|
for (const root of (state.data && state.data.roots) || []) {
|
|
54
107
|
roots.push(String(root.key || ''));
|
|
55
108
|
for (const skill of root.skills || []) {
|
|
56
109
|
// 与 list / read / save 同一套名字口径:`declaredName || name`,再比目录名。
|
|
57
|
-
|
|
110
|
+
const canonical = String(skill.declaredName || skill.name || '');
|
|
111
|
+
if (canonical !== '' && names.indexOf(canonical) < 0)
|
|
112
|
+
names.push(canonical);
|
|
113
|
+
if (canonical !== wanted && String(skill.name || '') !== wanted)
|
|
58
114
|
continue;
|
|
59
115
|
hits.push({
|
|
60
116
|
root: String(root.key || ''),
|
|
@@ -64,7 +120,7 @@ export async function locateSkillRoot(skillsOps, name) {
|
|
|
64
120
|
}
|
|
65
121
|
}
|
|
66
122
|
const winner = hits.find((hit) => hit.shadowedBy === '') || hits[0];
|
|
67
|
-
return { ok: true, root: winner ? winner.root : null, canonical: winner ? winner.canonical : null, roots, matches: hits };
|
|
123
|
+
return { ok: true, root: winner ? winner.root : null, canonical: winner ? winner.canonical : null, roots, matches: hits, names };
|
|
68
124
|
}
|
|
69
125
|
/**
|
|
70
126
|
* 取本会话的身份与覆盖。宿主没接这条通道、或取不到会话 → `null`(= 按全局)。
|
package/lib/tools/mcp.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
// `mcpm-edit` 里那句 `if (row[field] === undefined) return` 就不会生效,于是
|
|
27
27
|
// `resolveMaskedKv({}, 旧值)` 把整份 headers / env 静默清空、连 warning 都不给。
|
|
28
28
|
import { DEFAULT_MCP_NOTE_MAX_LENGTH, normalizeMcpNote } from '../mcp/state-section.js';
|
|
29
|
-
import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
|
|
29
|
+
import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
|
|
30
30
|
/** 「去看清单」那句:`mcp_manager_list` 不在模型手里时不能点名它(调用方按 `toolVisibleFor` 决定给不给)。 */
|
|
31
31
|
const MCP_LIST_HINT = ' (see mcp_manager_list — all=true also lists disabled ones)';
|
|
32
32
|
/**
|
|
@@ -42,7 +42,11 @@ const MCP_NEUTRAL_HINT = ' (copy the server name from your own `mcp__<server>__<
|
|
|
42
42
|
function locate(rows, server, level, listHint = MCP_LIST_HINT) {
|
|
43
43
|
const hits = (rows || []).filter((r) => String(r.serverName) === server);
|
|
44
44
|
if (!hits.length) {
|
|
45
|
-
|
|
45
|
+
// 猜错 serverName 是这条族里最常见的一次失败(口语里说的是「github 那个」)。清单这一趟
|
|
46
|
+
// 已经读在手上,直接把现成名字列出来 —— 指路的那两句仍然留着:它们解释**名字从哪来**,
|
|
47
|
+
// 而候选只回答"现在有哪些"。
|
|
48
|
+
throw new Error('no such server: ' + server + (listHint || MCP_NEUTRAL_HINT)
|
|
49
|
+
+ existingNote((rows || []).map((r) => String(r.serverName)), 'MCP servers'));
|
|
46
50
|
}
|
|
47
51
|
if (level) {
|
|
48
52
|
const picked = hits.filter((r) => r.level === level);
|
|
@@ -222,7 +226,14 @@ export function buildMcpTools(deps) {
|
|
|
222
226
|
// 让它在三个动词里选一个,比让它猜两个布尔的组合省一次往返。
|
|
223
227
|
// `restart` 的含义只在 `action` 参数里说一次:描述里那句
|
|
224
228
|
// "(reconnects and re-syncs tools)" 与参数说明逐字重复,而模型读参数时两处都在手上。
|
|
225
|
-
|
|
229
|
+
//
|
|
230
|
+
// 场景锁那句必须**分开说清豁免的范围**。`restart` 在确认门里是放行的(`confirm-gate.ts`:
|
|
231
|
+
// 它是场景锁唯一的恢复出口,加确认卡会把恢复路径本身掐断),所以这句描述是 restart 面前
|
|
232
|
+
// **唯一**的约束。旧写法 "except restart (the recovery path)" 把括号当定语还是理由分不清,
|
|
233
|
+
// 紧挨着的 "Only when the user asks or approves" 就被读成对别的动作说的 —— 模型可能理解成
|
|
234
|
+
// 「restart 是我的自愈手段,不用问」。`the lock skips it, approval does not` 把两个主语
|
|
235
|
+
// 摆在一起,豁免只剥掉锁那一层。
|
|
236
|
+
description: 'Turn one MCP server on or off, restart it, or stop it machine-wide; pass `tool` to target named tools on it. `off` leaves a server running while any conversation still uses it, `stop` ends it for them too. Blocked while the active scene is locked, except restart (the recovery path; the lock skips it, approval does not). Only when the user asks or approves.',
|
|
226
237
|
parameters: {
|
|
227
238
|
// 出口必须指向**常驻**来源,不能指向 `mcp_manager_list`:
|
|
228
239
|
// 那条工具在出厂默认里就是关着的,`listHint()` 在它不可见时返回空串,于是猜错名字时的
|
|
@@ -247,6 +258,14 @@ export function buildMcpTools(deps) {
|
|
|
247
258
|
throw new Error('action must be on / off / restart / stop (got: ' + (action || '(empty)') + ')');
|
|
248
259
|
}
|
|
249
260
|
const server = String((args && args.server) || '').trim();
|
|
261
|
+
// 空名字单独报「缺参数」:落进 `locate` 会变成 `no such server: (空)`,读起来像
|
|
262
|
+
// 「这台服务器不存在」,而真实原因是它根本没传。
|
|
263
|
+
if (server === '') {
|
|
264
|
+
throw new Error('missing argument: server (the server name)' + await candidateNote(async () => {
|
|
265
|
+
const r = await deps.mcpmListView();
|
|
266
|
+
return r && r.ok !== false ? (r.rows || []).map((x) => String(x.serverName)) : [];
|
|
267
|
+
}, 'MCP servers'));
|
|
268
|
+
}
|
|
250
269
|
// 单值仍然接受(旧提示词 / 手写调用),数组是新增的批量形态。
|
|
251
270
|
const rawTool = args && args.tool !== undefined && args.tool !== null ? args.tool : undefined;
|
|
252
271
|
const tools = (Array.isArray(rawTool) ? rawTool : rawTool === undefined ? [] : [rawTool])
|
|
@@ -265,7 +284,7 @@ export function buildMcpTools(deps) {
|
|
|
265
284
|
// 调用方是否**以为**自己在改会话层(省略 scope 也算)。全局粒度下这个以为会落空,
|
|
266
285
|
// 回执必须点出来 —— 否则 agent 会把"机器级改动"转述成"只影响这个对话"。
|
|
267
286
|
const askedForSession = (args && args.scope) !== 'global';
|
|
268
|
-
// restart 与 stop
|
|
287
|
+
// restart 与 stop 都是机器级动作(重启要真停一次;blocked 定义上就压过所有会话),
|
|
269
288
|
// 没有会话版本 —— 与 restart 同一条,忽略 scope 并如实点出来。
|
|
270
289
|
const sessionOnly = scope !== 'global' && action !== 'restart' && action !== 'stop';
|
|
271
290
|
// on|off 会写补丁(`mcpm-set-enabled` / `mcpm-tool-enabled` 在登记表里是 frozen),
|
|
@@ -417,8 +436,12 @@ export function buildMcpTools(deps) {
|
|
|
417
436
|
throw new Error(blocked);
|
|
418
437
|
requireGlobalScope(args, 'MCP servers', !sessionLayerOn(deps));
|
|
419
438
|
const server = String((args && args.server) || '').trim();
|
|
420
|
-
if (!server)
|
|
421
|
-
throw new Error('missing argument: server (the server name)')
|
|
439
|
+
if (!server) {
|
|
440
|
+
throw new Error('missing argument: server (the server name)' + await candidateNote(async () => {
|
|
441
|
+
const r = await deps.mcpmListView();
|
|
442
|
+
return r && r.ok !== false ? (r.rows || []).map((x) => String(x.serverName)) : [];
|
|
443
|
+
}, 'MCP servers'));
|
|
444
|
+
}
|
|
422
445
|
const levelArg = args && args.level !== undefined ? String(args.level) : undefined;
|
|
423
446
|
// `hint` 的三态:省略 = 保持;`''` = **清空**;非空 = 设置。
|
|
424
447
|
// 此前用 `hintText.trim() !== ''` 判"要不要写备注",把"清空"与"省略"混成一件事 ——
|
package/lib/tools/memory.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// 本身。memory_manager_save 受 tools/pre-execute 审批门禁。
|
|
20
20
|
// 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
|
|
21
21
|
import { GLOBAL_SCENE, SHARED_GROUP } from '../memories/constants.js';
|
|
22
|
-
import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
|
|
22
|
+
import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
|
|
23
23
|
/** 注册记忆域的 model 工具(列表 / 读取 / 检索 / 切换 / 保存)。 */
|
|
24
24
|
export function buildMemoryTools(deps) {
|
|
25
25
|
const { defineTool, register } = deps;
|
|
@@ -282,7 +282,14 @@ export function buildMemoryTools(deps) {
|
|
|
282
282
|
// 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准。
|
|
283
283
|
const slash = memory.indexOf('/');
|
|
284
284
|
if (slash <= 0 || slash === memory.length - 1) {
|
|
285
|
-
|
|
285
|
+
// 这一条错得最有规律:用户口语里说的是「编程约定」,模型手里没有 id,就把那个名字
|
|
286
|
+
// 直接传进来了。给两条现成的 id 比再解释一遍格式有用;读失败就只报格式
|
|
287
|
+
// (`candidateNote` 自己吞掉失败,不改变错误结论)。
|
|
288
|
+
const note = await candidateNote(async () => {
|
|
289
|
+
const r = await deps.rulesOps['rules-list']({});
|
|
290
|
+
return r && r.ok !== false ? (r.rules || []).map((x) => String(x.id)) : [];
|
|
291
|
+
}, 'memory ids');
|
|
292
|
+
throw new Error('memory must be <scene>/<name> (copy that from the listing; the always-on scene is written global/<name>): ' + (memory || '(empty)') + note);
|
|
286
293
|
}
|
|
287
294
|
const group = memory.slice(0, slash);
|
|
288
295
|
const name = memory.slice(slash + 1);
|
|
@@ -323,8 +330,14 @@ export function buildMemoryTools(deps) {
|
|
|
323
330
|
body.trim() === '' ? 'body' : '',
|
|
324
331
|
description.trim() === '' ? 'description' : '',
|
|
325
332
|
].filter((x) => x !== '');
|
|
326
|
-
if (missing.length)
|
|
327
|
-
|
|
333
|
+
if (missing.length) {
|
|
334
|
+
// id 不存在 + 内容也不全:最可能是名字记差了一个字。先给**同一场景**里现成的 id
|
|
335
|
+
// (整个库列出来只会把这条错误变成噪音),一条都没有才退回全库。
|
|
336
|
+
const ids = (all.rules || []).map((x) => String(x.id));
|
|
337
|
+
const here = ids.filter((id) => id.indexOf(group + '/') === 0);
|
|
338
|
+
throw new Error('creating a memory needs ' + missing.join(' and ') + ' (' + memory + ' does not exist yet)'
|
|
339
|
+
+ existingNote(here.length ? here : ids, 'memory ids'));
|
|
340
|
+
}
|
|
328
341
|
// 查重只**说出来**,不拒绝 —— 猜错一次就把该记的东西记不下去,比多记一条代价大得多;
|
|
329
342
|
// 而且"像不像同一条"本来就是人判断的事。只在建的分支提示:改的分支没有"再记一条"的风险。
|
|
330
343
|
const norm = (value) => String(value ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
package/lib/tools/prompt.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { normalizePresetDescription } from '../prompts/service.js';
|
|
14
14
|
import { hasPromptOverride } from '../scope/scope-overrides.js';
|
|
15
|
-
import { sessionScopeOf, text } from './deps.js';
|
|
15
|
+
import { candidateNote, sessionScopeOf, text } from './deps.js';
|
|
16
16
|
/** 注册提示词域的 model 工具(列表 / 读取 / 应用)。 */
|
|
17
17
|
export function buildPromptTools(deps) {
|
|
18
18
|
const { defineTool, register } = deps;
|
|
@@ -115,8 +115,14 @@ export function buildPromptTools(deps) {
|
|
|
115
115
|
promptScopeTail(scoped?.scope);
|
|
116
116
|
}
|
|
117
117
|
const id = String((args && args.id) || '').trim();
|
|
118
|
-
if (id === '')
|
|
119
|
-
|
|
118
|
+
if (id === '') {
|
|
119
|
+
// 用户口语里很少同时说出预设 id(「换成简洁那版」)—— 缺 id 时就给现成的几个,
|
|
120
|
+
// 只在错误路径上读一次盘。
|
|
121
|
+
throw new Error('missing argument: id (only optional when apply=false cancels)' + await candidateNote(async () => {
|
|
122
|
+
const l = await deps.promptOps['agentsmd-list']({});
|
|
123
|
+
return l && l.ok !== false ? (l.presets || []).map((p) => String(p.id)) : [];
|
|
124
|
+
}, 'presets'));
|
|
125
|
+
}
|
|
120
126
|
const r = await deps.applyPresetGuarded(id);
|
|
121
127
|
if (!r.ok)
|
|
122
128
|
throw new Error(r.error);
|
package/lib/tools/remove.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
//
|
|
14
14
|
// 参数名统一 `id`:`trash` 时是资源标识(记忆 `<场景>/<名>`、技能名、人设名、预设 id、
|
|
15
15
|
// 场景名),`restore` 时是 `action=list` 给出的**回收站条目 id** —— 两种含义在描述里写清。
|
|
16
|
-
import { globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text } from './deps.js';
|
|
16
|
+
import { candidateNote, globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text, toolOrNeutral, } from './deps.js';
|
|
17
17
|
/** 三个动词共用的描述骨架。 */
|
|
18
18
|
function removeDescription(noun) {
|
|
19
19
|
return 'Delete one ' + noun + ' (to the trash), restore one, or list the trash. '
|
|
@@ -54,15 +54,7 @@ function restoredName(r) {
|
|
|
54
54
|
};
|
|
55
55
|
return pick(r) || pick(r && r.data);
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
* 一条删除工具的 execute:三个动词的分派与回执。
|
|
59
|
-
*
|
|
60
|
-
* 会话层:删除是**全局**动作 —— 技能正文、人设 `.md`、场景档案、MCP 补丁
|
|
61
|
-
* 提示词预设都只有一份,没有「本会话的副本」,所以这一格的口径就是「全局动作」。
|
|
62
|
-
* 所以这里不写会话层,只在**这个对话真有该域覆盖**时补一句尾注:
|
|
63
|
-
* 删完之后那条会话覆盖还在(读时忽略,对账才清),不说明的话用户会以为它跟着没了。
|
|
64
|
-
*/
|
|
65
|
-
async function runRemove(deps, cfg, args, agent) {
|
|
57
|
+
async function runRemove(deps, cfg, args, agent, isMemoryId) {
|
|
66
58
|
const action = String((args && args.action) || '');
|
|
67
59
|
if (action !== 'trash' && action !== 'restore' && action !== 'list') {
|
|
68
60
|
throw new Error('action must be trash / restore / list (got: ' + (action || '(empty)') + ')');
|
|
@@ -82,8 +74,30 @@ async function runRemove(deps, cfg, args, agent) {
|
|
|
82
74
|
// 连提示词那一族也一样(提示词根本不进会话域,更没有「本会话的预设」可删)。
|
|
83
75
|
requireGlobalScope(args, cfg.noun + 's', !sessionLayerOn(deps));
|
|
84
76
|
const id = String((args && args.id) || '').trim();
|
|
85
|
-
if (id === '')
|
|
86
|
-
|
|
77
|
+
if (id === '') {
|
|
78
|
+
// 恢复的 id 是**回收站条目 id**(与 trash 的资源标识不是一回事),指错地方最费时间 ——
|
|
79
|
+
// 这一条不用候选名单,一句 `action=list` 就是正解。
|
|
80
|
+
let note = '';
|
|
81
|
+
let hint = '';
|
|
82
|
+
if (action === 'restore') {
|
|
83
|
+
note = ' A restore id is a trash entry id — action=list prints them.';
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
note = await candidateNote(cfg.idHelp.list, cfg.idHelp.label);
|
|
87
|
+
// 有候选就不必再说去哪儿拿(两句叠在一起只是把错误读长一倍);一条都读不到时才指路。
|
|
88
|
+
if (note === '') {
|
|
89
|
+
hint = toolOrNeutral(deps, agent, cfg.idHelp.tool, ' Call `' + cfg.idHelp.tool + '` to get one.', cfg.idHelp.neutral);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
throw new Error('missing argument: id (required by action=' + action + ')' + note + hint);
|
|
93
|
+
}
|
|
94
|
+
// 跨族误用里唯一能**确认**的一种:带斜杠的 id 落到别的域,且这个 id 确实在记忆库里。
|
|
95
|
+
// 只按形状(`a/b`)判会误伤 —— 场景名与技能名都没有禁止斜杠的校验,用户起的名字里
|
|
96
|
+
// 完全可能出现。所以这里读一次记忆库确认存在;读不到就当不是,宁可少说一句。
|
|
97
|
+
if (action === 'trash' && cfg.domain !== 'memory' && id.indexOf('/') > 0 && await isMemoryId(id)) {
|
|
98
|
+
throw new Error('"' + id + '" is a memory id (memory ids are <scene>/<name>); this tool handles ' + cfg.noun + 's.'
|
|
99
|
+
+ toolOrNeutral(deps, agent, 'memory_manager_remove', ' Use `memory_manager_remove` with action=trash for it.', ' Pass it to the memory manager instead — this one only handles ' + cfg.noun + 's.'));
|
|
100
|
+
}
|
|
87
101
|
const r = action === 'trash' ? await cfg.trash(args) : await cfg.restore(args);
|
|
88
102
|
if (!r || r.ok === false)
|
|
89
103
|
throw new Error((r && r.error) || (action === 'trash' ? 'failed to move it to the trash' : 'restore failed'));
|
|
@@ -106,6 +120,23 @@ export function buildRemoveTools(deps) {
|
|
|
106
120
|
const sub = deps.subagentOps;
|
|
107
121
|
const pr = deps.promptOps;
|
|
108
122
|
const sc = deps.sceneOps;
|
|
123
|
+
/**
|
|
124
|
+
* 这个 id 是不是记忆库里一条真实存在的记忆。
|
|
125
|
+
*
|
|
126
|
+
* 只在「带斜杠的 id 传到别的域」那条错误路径上调用,正常删除不会碰它。
|
|
127
|
+
* 读失败一律 false:探不到就不说那句话,错误结论仍由原逻辑给出。
|
|
128
|
+
*/
|
|
129
|
+
const isMemoryId = async (id) => {
|
|
130
|
+
try {
|
|
131
|
+
const r = await mem['rules-list']({});
|
|
132
|
+
if (!r || r.ok === false)
|
|
133
|
+
return false;
|
|
134
|
+
return (r.rules || []).some((x) => String(x.id) === id);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
109
140
|
const memoryCfg = {
|
|
110
141
|
noun: 'memory', label: 'memory', domain: 'memory',
|
|
111
142
|
trash: (a) => mem['rules-remove']({ id: String(a.id || '') }),
|
|
@@ -116,6 +147,15 @@ export function buildRemoveTools(deps) {
|
|
|
116
147
|
throw new Error((r && r.error) || 'failed to read the trash');
|
|
117
148
|
return (r.entries || []).map((e) => ({ id: String(e.trashId), name: String(e.name), deletedAt: e.deletedAt }));
|
|
118
149
|
},
|
|
150
|
+
idHelp: {
|
|
151
|
+
tool: 'memory_manager_list',
|
|
152
|
+
neutral: ' — the ids are the lines in the "Current memories" reminder.',
|
|
153
|
+
label: 'memory ids',
|
|
154
|
+
list: async () => {
|
|
155
|
+
const r = await mem['rules-list']({});
|
|
156
|
+
return r && r.ok !== false ? (r.rules || []).map((x) => String(x.id)) : [];
|
|
157
|
+
},
|
|
158
|
+
},
|
|
119
159
|
};
|
|
120
160
|
const skillCfg = {
|
|
121
161
|
noun: 'skill', label: 'skill', domain: 'skills',
|
|
@@ -136,6 +176,23 @@ export function buildRemoveTools(deps) {
|
|
|
136
176
|
throw new Error((r && r.error) || 'skill-state failed');
|
|
137
177
|
return ((r.data && r.data.trash) || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
|
|
138
178
|
},
|
|
179
|
+
idHelp: {
|
|
180
|
+
tool: 'skill_manager_list',
|
|
181
|
+
neutral: ' — the names are in the "Current skills" reminder.',
|
|
182
|
+
label: 'skills',
|
|
183
|
+
list: async () => {
|
|
184
|
+
const r = await sk['skill-state']({});
|
|
185
|
+
const names = [];
|
|
186
|
+
for (const root of (r && r.ok !== false && r.data && r.data.roots) || []) {
|
|
187
|
+
for (const skill of root.skills || []) {
|
|
188
|
+
const n = String(skill.declaredName || skill.name || '');
|
|
189
|
+
if (n !== '' && names.indexOf(n) < 0)
|
|
190
|
+
names.push(n);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return names;
|
|
194
|
+
},
|
|
195
|
+
},
|
|
139
196
|
};
|
|
140
197
|
const subagentCfg = {
|
|
141
198
|
noun: 'persona', label: 'persona', domain: 'subagents',
|
|
@@ -147,6 +204,15 @@ export function buildRemoveTools(deps) {
|
|
|
147
204
|
throw new Error((r && r.error) || 'failed to read the trash');
|
|
148
205
|
return (r.trash || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
|
|
149
206
|
},
|
|
207
|
+
idHelp: {
|
|
208
|
+
tool: 'subagent_manager_list',
|
|
209
|
+
neutral: ' — the names are in the "Current subagents" reminder.',
|
|
210
|
+
label: 'personas',
|
|
211
|
+
list: async () => {
|
|
212
|
+
const r = await sub['subagent-list']({});
|
|
213
|
+
return r && r.ok !== false ? (r.subagents || []).map((p) => String(p.name)) : [];
|
|
214
|
+
},
|
|
215
|
+
},
|
|
150
216
|
};
|
|
151
217
|
const promptCfg = {
|
|
152
218
|
noun: 'preset', label: 'preset',
|
|
@@ -159,6 +225,15 @@ export function buildRemoveTools(deps) {
|
|
|
159
225
|
const arr = Array.isArray(r) ? r : (r.presets || r.trash || r.entries || []);
|
|
160
226
|
return arr.map((e) => ({ id: String(e.id), name: String(e.name || e.id), deletedAt: e.deletedAt }));
|
|
161
227
|
},
|
|
228
|
+
idHelp: {
|
|
229
|
+
tool: 'prompt_manager_list',
|
|
230
|
+
neutral: ' — the one in effect is named in the "Current prompt" reminder.',
|
|
231
|
+
label: 'presets',
|
|
232
|
+
list: async () => {
|
|
233
|
+
const r = await pr['agentsmd-list']({});
|
|
234
|
+
return r && r.ok !== false ? (r.presets || []).map((p) => String(p.id)) : [];
|
|
235
|
+
},
|
|
236
|
+
},
|
|
162
237
|
};
|
|
163
238
|
const sceneCfg = {
|
|
164
239
|
noun: 'scene', label: 'scene', domain: 'scene',
|
|
@@ -172,6 +247,15 @@ export function buildRemoveTools(deps) {
|
|
|
172
247
|
throw new Error((r && r.error) || 'failed to read the trash');
|
|
173
248
|
return (r.trash || []).map((e) => ({ id: String(e.id), name: String(e.name), deletedAt: e.deletedAt }));
|
|
174
249
|
},
|
|
250
|
+
idHelp: {
|
|
251
|
+
tool: 'scene_manager_list',
|
|
252
|
+
neutral: ' — the names are in the "Current scene" reminder.',
|
|
253
|
+
label: 'scenes',
|
|
254
|
+
list: async () => {
|
|
255
|
+
const r = await sc['rules-list']({});
|
|
256
|
+
return r && r.ok !== false ? (r.scenes || []).map((s) => String(s.name)) : [];
|
|
257
|
+
},
|
|
258
|
+
},
|
|
175
259
|
};
|
|
176
260
|
register(defineTool({
|
|
177
261
|
name: 'memory_manager_remove',
|
|
@@ -182,7 +266,7 @@ export function buildRemoveTools(deps) {
|
|
|
182
266
|
scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
|
|
183
267
|
},
|
|
184
268
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
185
|
-
async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent); },
|
|
269
|
+
async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent, isMemoryId); },
|
|
186
270
|
}));
|
|
187
271
|
register(defineTool({
|
|
188
272
|
name: 'skill_manager_remove',
|
|
@@ -194,7 +278,7 @@ export function buildRemoveTools(deps) {
|
|
|
194
278
|
root: { type: 'string', description: 'Source root the skill lives in. Default: whichever source holds that skill; only used by action=trash.' },
|
|
195
279
|
},
|
|
196
280
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
197
|
-
async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent); },
|
|
281
|
+
async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent, isMemoryId); },
|
|
198
282
|
}));
|
|
199
283
|
register(defineTool({
|
|
200
284
|
name: 'subagent_manager_remove',
|
|
@@ -205,7 +289,7 @@ export function buildRemoveTools(deps) {
|
|
|
205
289
|
scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
|
|
206
290
|
},
|
|
207
291
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
208
|
-
async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent); },
|
|
292
|
+
async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent, isMemoryId); },
|
|
209
293
|
}));
|
|
210
294
|
register(defineTool({
|
|
211
295
|
name: 'prompt_manager_remove',
|
|
@@ -216,7 +300,7 @@ export function buildRemoveTools(deps) {
|
|
|
216
300
|
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a preset writes the one global baseline', 'there is nothing per-conversation to delete') },
|
|
217
301
|
},
|
|
218
302
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
219
|
-
async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent); },
|
|
303
|
+
async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent, isMemoryId); },
|
|
220
304
|
}));
|
|
221
305
|
register(defineTool({
|
|
222
306
|
name: 'scene_manager_remove',
|
|
@@ -227,6 +311,6 @@ export function buildRemoveTools(deps) {
|
|
|
227
311
|
scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC_SCENE },
|
|
228
312
|
},
|
|
229
313
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
230
|
-
async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent); },
|
|
314
|
+
async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent, isMemoryId); },
|
|
231
315
|
}));
|
|
232
316
|
}
|
package/lib/tools/scene.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// 理由是"那是改运行时环境的动作";补上 `_switch` 的取舍记在 CHANGELOG 里 —— 要点是
|
|
25
25
|
// **场景段的动作句仍然不加回来**:「上下文注入只给现在是什么」是同一天定下的原则,
|
|
26
26
|
// 不因为多了一条工具就破例(工具描述本来就是写"什么时候该用它"的地方)。
|
|
27
|
-
import { effectiveScope, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
|
|
27
|
+
import { candidateNote, effectiveScope, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
|
|
28
28
|
import { FACTORY_TOOL_TABLE_PRESET } from './table.js';
|
|
29
29
|
/** 档案里由模型设置的段(`memories` 段在 P5 已废弃,不再是档案的一部分)。
|
|
30
30
|
* `mcpNotes`与其余三段同族:整段替换、段缺席 = 不碰这一域。 */
|
|
@@ -159,6 +159,20 @@ function agentsMdNote(sync, action) {
|
|
|
159
159
|
}
|
|
160
160
|
return notes.join('');
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* 「缺场景名」时的补救:现成的场景名读一次盘带出来。
|
|
164
|
+
*
|
|
165
|
+
* 只在错误路径上调用。场景名是用户口语里给出的那个词(「切到写作场景」),而 schema 里
|
|
166
|
+
* 要的是**确切名字**(单个路径段,界面显示名可能不同)—— 不给候选,模型只能猜第二次。
|
|
167
|
+
* 读不到(或一个场景都没有)时退回常驻来源,不点名任何工具。
|
|
168
|
+
*/
|
|
169
|
+
async function sceneCandidates(deps) {
|
|
170
|
+
const note = await candidateNote(async () => {
|
|
171
|
+
const r = await deps.rulesOps['rules-list']({});
|
|
172
|
+
return r && r.ok !== false ? (r.scenes || []).map((s) => String(s.name)) : [];
|
|
173
|
+
}, 'scenes');
|
|
174
|
+
return note !== '' ? note : ' — the names are in the "Current scene" reminder.';
|
|
175
|
+
}
|
|
162
176
|
/** 注册场景域的 model 工具(列表 / 进入 / 保存 / 删除)。 */
|
|
163
177
|
export function buildSceneTools(deps) {
|
|
164
178
|
const { defineTool, register } = deps;
|
|
@@ -277,7 +291,7 @@ export function buildSceneTools(deps) {
|
|
|
277
291
|
if (action === 'enter') {
|
|
278
292
|
wanted = String((args && args.scene) || '').trim();
|
|
279
293
|
if (wanted === '')
|
|
280
|
-
throw new Error('action=enter needs scene: the scene name
|
|
294
|
+
throw new Error('action=enter needs scene: the scene name' + await sceneCandidates(deps));
|
|
281
295
|
if (wanted.indexOf('/') >= 0 || wanted.indexOf('\\') >= 0)
|
|
282
296
|
throw new Error('a scene name is a single path segment (no / or \\): ' + wanted);
|
|
283
297
|
}
|
|
@@ -296,7 +310,7 @@ export function buildSceneTools(deps) {
|
|
|
296
310
|
if (action === 'enter') {
|
|
297
311
|
scene = String((args && args.scene) || '').trim();
|
|
298
312
|
if (scene === '')
|
|
299
|
-
throw new Error('action=enter needs scene: the scene name
|
|
313
|
+
throw new Error('action=enter needs scene: the scene name' + await sceneCandidates(deps));
|
|
300
314
|
// 场景名是**单个路径段**(与 scene_manager_save 同一条校验、同一句报错)。
|
|
301
315
|
if (scene.indexOf('/') >= 0 || scene.indexOf('\\') >= 0) {
|
|
302
316
|
throw new Error('a scene name is a single path segment (no / or \\): ' + scene);
|
package/lib/tools/skills.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// (先读一次 `skill-state`)。改的分支走新加的 `skill-update` op,它只认本插件可写的两个根
|
|
6
6
|
// (hub = 导入落点 / dsh = 新建默认落点)里的胜出者。
|
|
7
7
|
import { toKebab } from '../skills/core.js';
|
|
8
|
-
import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
|
|
8
|
+
import { effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
|
|
9
9
|
/** 注册技能域的 model 工具(列表 / 启停 / 新建或更新)。 */
|
|
10
10
|
export function buildSkillTools(deps) {
|
|
11
11
|
const { defineTool, register } = deps;
|
|
@@ -187,7 +187,15 @@ export function buildSkillTools(deps) {
|
|
|
187
187
|
const listHint = deps.toolVisibleFor('skill_manager_list', exec && exec.agent)
|
|
188
188
|
? ' — call skill_manager_list (pass all=true) to see what is installed'
|
|
189
189
|
: '';
|
|
190
|
-
|
|
190
|
+
// 名字打错是这条错误最常见的成因,而现成的名字这一次已经扫到了(`data.roots` 在手),
|
|
191
|
+
// 不必再读一次盘。条目多时只列前几个,见 `toolNameList`。
|
|
192
|
+
const names = [];
|
|
193
|
+
for (const root of data.roots || []) {
|
|
194
|
+
for (const skill of root.skills || [])
|
|
195
|
+
names.push(String(skill.declaredName || skill.name || ''));
|
|
196
|
+
}
|
|
197
|
+
throw new Error('no skill named "' + wanted + '"' + (rootWanted ? ' in source "' + rootWanted + '"' : '') + listHint
|
|
198
|
+
+ existingNote(names, 'skills'));
|
|
191
199
|
}
|
|
192
200
|
// 胜出者优先:同名的影子副本读得到,但那不是生效的一份,所以默认不选它。
|
|
193
201
|
const picked = hits.find((hit) => !hit.shadowedBy && hit.enabled)
|
|
@@ -380,7 +388,8 @@ export function buildSkillTools(deps) {
|
|
|
380
388
|
// 探得到、就是没这个技能:当场把"查过哪些来源"说清楚。否则模型收到 op 那句不带
|
|
381
389
|
// 来源信息的「技能不存在」后,只能猜该传哪个 root(smoke-test P1-4-old 同一处)。
|
|
382
390
|
if (found.ok) {
|
|
383
|
-
throw new Error('no such skill: ' + name + (found.roots.length ? ' (searched ' + found.roots.join(', ') + ')' : '')
|
|
391
|
+
throw new Error('no such skill: ' + name + (found.roots.length ? ' (searched ' + found.roots.join(', ') + ')' : '')
|
|
392
|
+
+ existingNote(found.names, 'skills'));
|
|
384
393
|
}
|
|
385
394
|
// 探不到(skill-state 失败)就别在这里编结论:退回旧默认,交给 op 报它自己的错。
|
|
386
395
|
return 'dsh';
|
package/lib/tools/table.js
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
// 实测数字(口径:宿主 `recordToolSize` 的 `ceil(JSON.stringify(header.tools).length / 4) + 4`,
|
|
11
11
|
// 即**字符数 / 4**;界面「模型工具表」那行合计与逐条 ≈tok 就是这份,逐条相加与整份数组
|
|
12
12
|
// 的算法差不到 1%):
|
|
13
|
-
// · 重测:二十条隐藏 ≈**5,213 tok**(≈20,852 字符),默认可见那六条 ≈**1,547 tok
|
|
13
|
+
// · 重测:二十条隐藏 ≈**5,213 tok**(≈20,852 字符),默认可见那六条 ≈**1,547 tok**
|
|
14
|
+
// (0.21.5 又动了默认可见的两条:`mcp_manager_switch` 补 38 字符的场景锁豁免说明(+10),
|
|
15
|
+
// `subagent_manager_list` 补正文文件路径的说明(+14),同一口径现为 **1,571**;
|
|
16
|
+
// 隐藏那二十条没动,仍是 5,213)。
|
|
14
17
|
// 比 10-18 那份(16,743 字符 ≈4,186)涨了两成 —— 会话作用域这轮给工具描述加了"写本对话
|
|
15
18
|
// 还是全局""`scope` 参数""租约"这些句子,名单一个字没变。
|
|
16
19
|
// 那次实测的名单里还没有 `memory_manager_search`(它自己 ≈70 tok 未计入)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-tool-management",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.5",
|
|
4
4
|
"description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
]
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
-
"icon": "./docs/images/
|
|
73
|
+
"icon": "./docs/images/logo.png",
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
76
76
|
"@deepseek-ai/dsh-agent-preset-registry": ">=0.2.1-rc.2 <0.2.2",
|
package/docs/images/icon.png
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|