dsh-plugin-tool-management 0.22.5 → 0.22.6
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 +1624 -1415
- package/README.md +194 -177
- package/README_EN.md +194 -177
- package/docs/ARCHITECTURE.md +137 -134
- package/docs/COMPATIBILITY.md +12 -7
- package/docs/TROUBLESHOOTING.md +287 -285
- package/lib/client.js +14975 -12277
- package/lib/compat/capability-specs.js +66 -16
- package/lib/compat/host-contracts.js +11 -2
- package/lib/compat/host-roots.js +1 -1
- package/lib/compat/manual-review.js +1 -1
- package/lib/compat/preset-reach.js +1 -1
- package/lib/compat/probe.js +96 -11
- package/lib/confirm-gate.js +40 -6
- package/lib/context-inject-contract.js +31 -14
- package/lib/context-inject-delta.js +146 -0
- package/lib/context-inject-frame.js +38 -19
- package/lib/context-inject-select.js +33 -4
- package/lib/context-inject-surface.js +30 -10
- package/lib/context-inject.js +106 -14
- package/lib/evolution/cold.js +389 -0
- package/lib/evolution/config.js +507 -0
- package/lib/evolution/digest.js +48 -0
- package/lib/evolution/episodes.js +287 -0
- package/lib/evolution/evidence.js +167 -0
- package/lib/evolution/gates.js +874 -0
- package/lib/evolution/limits.js +21 -0
- package/lib/evolution/maintenance.js +516 -0
- package/lib/evolution/notes.js +328 -0
- package/lib/evolution/organize.js +118 -0
- package/lib/evolution/review.js +524 -0
- package/lib/evolution/route.js +91 -0
- package/lib/evolution/runtime.js +179 -0
- package/lib/evolution/scope-card.js +144 -0
- package/lib/evolution/state.js +514 -0
- package/lib/evolution/write.js +1773 -0
- package/lib/index.js +1328 -58
- package/lib/legacy-tool-names.js +19 -4
- package/lib/mcp/tool-visibility.js +127 -10
- package/lib/memories/catalog.js +215 -0
- package/lib/memories/constants.js +115 -7
- package/lib/memories/discovery.js +59 -25
- package/lib/memories/projection.js +116 -31
- package/lib/memories/render-auto.js +198 -0
- package/lib/memories/search.js +3 -5
- package/lib/memories/service.js +158 -14
- package/lib/memories/snapshot.js +174 -23
- package/lib/op-registry.js +59 -0
- package/lib/ops/compat.js +2 -0
- package/lib/ops/evolution.js +887 -0
- package/lib/ops/memory.js +95 -72
- package/lib/ops/trash.js +14 -2
- package/lib/prompts/service.js +4 -1
- package/lib/scope/workspace-key.js +39 -0
- package/lib/settings-sidecars.js +2 -2
- package/lib/skills/official.js +180 -36
- package/lib/subagents/run-provider.js +35 -22
- package/lib/text-width.js +59 -0
- package/lib/tool-table-switch.js +104 -16
- package/lib/tools/control.js +45 -12
- package/lib/tools/deps.js +2 -2
- package/lib/tools/mcp.js +6 -4
- package/lib/tools/memory.js +1045 -267
- package/lib/tools/note-ref.js +20 -0
- package/lib/tools/remove.js +1 -1
- package/lib/tools/scene.js +3 -3
- package/lib/tools/table.js +76 -20
- package/package.json +155 -156
- package/docs/UPDATE.md +0 -50
package/lib/tools/control.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// · 自己不可被关:唯一的回头路不能被自己关掉(面板仍然可以关)。
|
|
18
18
|
import { text } from './deps.js';
|
|
19
19
|
import { governingScopeNote } from './deps.js';
|
|
20
|
-
import { applyToolTableToggles, estimateTok } from './table.js';
|
|
20
|
+
import { applyToolTableToggles, estimateTok, PROACTIVE_MEMORY_TOOL } from './table.js';
|
|
21
21
|
/** 一行清单:名字 · 用途 · ≈token。 */
|
|
22
22
|
function toolLine(name, summary, bytes) {
|
|
23
23
|
const purpose = summary === '' ? '' : ' — ' + summary;
|
|
@@ -57,8 +57,8 @@ export function buildControlTools(deps) {
|
|
|
57
57
|
},
|
|
58
58
|
target: {
|
|
59
59
|
type: 'string',
|
|
60
|
-
enum: ['memory-index', 'scope', 'mcp-disabled'],
|
|
61
|
-
description: 'For repair: memory-index | scope | mcp-disabled.',
|
|
60
|
+
enum: ['memory-index', 'scope', 'mcp-disabled', 'tool-table'],
|
|
61
|
+
description: 'For repair: memory-index | scope | mcp-disabled | tool-table.',
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
64
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
@@ -67,8 +67,16 @@ export function buildControlTools(deps) {
|
|
|
67
67
|
const agent = exec && exec.agent;
|
|
68
68
|
if (action === 'list')
|
|
69
69
|
return listTools(deps, agent);
|
|
70
|
-
|
|
70
|
+
// `repair` 也受子代理限制:它改的是**共享**侧车(记忆索引 / 作用域 / 工具表),
|
|
71
|
+
// 不是本会话的名单。早先它在 `subagentDepth` 判断之前就 return 了,于是子代理能调
|
|
72
|
+
// 一个破坏性的修复动作去动父会话与所有会话共用的状态 —— 与「子代理不改工具表」
|
|
73
|
+
// 的承诺正好相反。`list` 仍然放行:读一眼不改变任何状态。
|
|
74
|
+
if (action === 'repair') {
|
|
75
|
+
if ((deps.subagentDepth?.(agent) ?? 0) >= 1) {
|
|
76
|
+
throw new Error('this runs in a subagent, which shares its parent conversation\'s state: repairing a sidecar here would change every conversation. Ask the parent agent (or the user) to run it.');
|
|
77
|
+
}
|
|
71
78
|
return repairState(deps, args);
|
|
79
|
+
}
|
|
72
80
|
if (action !== 'enable' && action !== 'disable') {
|
|
73
81
|
throw new Error('unknown action: ' + (action === '' ? '(missing)' : action) + ' — use list, enable, disable or repair');
|
|
74
82
|
}
|
|
@@ -77,6 +85,11 @@ export function buildControlTools(deps) {
|
|
|
77
85
|
.filter((n) => n !== '');
|
|
78
86
|
if (requested.length === 0)
|
|
79
87
|
throw new Error('missing argument: tools — the names of the tools to ' + action);
|
|
88
|
+
// 自主记忆那条工具没有独立状态:它只跟总开关走,模型不能自己把它开出来或关掉。
|
|
89
|
+
// 提前在这里说清,而不是等写路径返回一句笼统的 "cannot be toggled"。
|
|
90
|
+
if (requested.includes(PROACTIVE_MEMORY_TOOL)) {
|
|
91
|
+
throw new Error(PROACTIVE_MEMORY_TOOL + ' follows the autonomous memory switch and cannot be turned on or off here — the user changes it on the Memory page.');
|
|
92
|
+
}
|
|
80
93
|
// 只认本插件注册过的名字:陌生名字写进关停名单会让官方的 restrict 抛错。
|
|
81
94
|
const known = requested.filter((n) => deps.toolTableSizes.has(n));
|
|
82
95
|
const unknown = requested.filter((n) => !deps.toolTableSizes.has(n));
|
|
@@ -89,6 +102,11 @@ export function buildControlTools(deps) {
|
|
|
89
102
|
if (action === 'disable' && known.includes(CONTROL_TOOL_NAME)) {
|
|
90
103
|
throw new Error('this tool cannot switch itself off — it is the only way back to the others. Only the user can disable it (in the panel).');
|
|
91
104
|
}
|
|
105
|
+
// 子代理不改工具表:它和父会话共用同一份名单,改完会留到父会话之后的每一轮。
|
|
106
|
+
// `list` 仍放行 —— 读一眼不改变任何状态。
|
|
107
|
+
if ((deps.subagentDepth?.(agent) ?? 0) >= 1) {
|
|
108
|
+
throw new Error('this runs in a subagent, which shares its parent conversation\'s tool table: switching tools here would change the parent conversation. Ask the parent agent (or the user) to make the change.');
|
|
109
|
+
}
|
|
92
110
|
const hidden = deps.hiddenForSession(agent);
|
|
93
111
|
// 逐条改:每一处改动是一个「关掉 / 打开某一条」,写侧在锁里现读现改。
|
|
94
112
|
const changes = known.map((name) => ({ name, hidden: action === 'disable' }));
|
|
@@ -104,9 +122,14 @@ export function buildControlTools(deps) {
|
|
|
104
122
|
];
|
|
105
123
|
if (unknown.length > 0)
|
|
106
124
|
lines.push('not this plugin\'s tools (ignored): ' + unknown.join(', '));
|
|
125
|
+
// 进入 / 退出场景会把场景工具表整份抄进本对话的名单。模型把"开了一条、别的没了"
|
|
126
|
+
// 误读成 enable 替换整份时,这一句是唯一能解释它的话。
|
|
127
|
+
lines.push('Entering or leaving a scene re-applies that scene\'s tool-table scheme here.');
|
|
107
128
|
// 说清「这一层看得见的条数」:模型据此判断自己还有没有别的路。
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
// 总数同样不含自主记忆那条工具:它不在工具表里,也不该出现在「N 条工具」的分母里。
|
|
130
|
+
const total = deps.toolTableSizes.size - (deps.toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? 1 : 0);
|
|
131
|
+
const offHere = next.filter((name) => name !== PROACTIVE_MEMORY_TOOL).length;
|
|
132
|
+
lines.push((total - offHere) + ' of ' + total + ' tools are available here now.');
|
|
110
133
|
return lines.join('\n');
|
|
111
134
|
},
|
|
112
135
|
}));
|
|
@@ -123,8 +146,8 @@ export function buildControlTools(deps) {
|
|
|
123
146
|
*/
|
|
124
147
|
async function repairState(deps, args) {
|
|
125
148
|
const target = String((args && args.target) || '').trim();
|
|
126
|
-
if (target !== 'memory-index' && target !== 'scope' && target !== 'mcp-disabled') {
|
|
127
|
-
throw new Error('missing argument: target — memory-index, scope or
|
|
149
|
+
if (target !== 'memory-index' && target !== 'scope' && target !== 'mcp-disabled' && target !== 'tool-table') {
|
|
150
|
+
throw new Error('missing argument: target — memory-index, scope, mcp-disabled or tool-table');
|
|
128
151
|
}
|
|
129
152
|
const r = await deps.repair(target);
|
|
130
153
|
if (!r || r.ok === false)
|
|
@@ -132,7 +155,10 @@ async function repairState(deps, args) {
|
|
|
132
155
|
const lines = ['OK: repaired ' + target + '.'];
|
|
133
156
|
if (r.message)
|
|
134
157
|
lines.push(String(r.message));
|
|
135
|
-
|
|
158
|
+
// 工具表的恢复值不是空表而是**出厂名单**:说"空表"会让模型以为所有工具现在都开着。
|
|
159
|
+
lines.push(target === 'tool-table'
|
|
160
|
+
? 'The damaged file was renamed aside, not deleted; the tool table is back to the factory list (the same one a fresh install starts with).'
|
|
161
|
+
: 'The damaged file was renamed aside, not deleted; the plugin now continues with an empty table, so whatever it held no longer applies.');
|
|
136
162
|
return lines.join('\n');
|
|
137
163
|
}
|
|
138
164
|
/**
|
|
@@ -146,13 +172,20 @@ function listTools(deps, agent) {
|
|
|
146
172
|
for (const [name, bytes] of deps.toolTableSizes) {
|
|
147
173
|
if (!hidden.has(name))
|
|
148
174
|
continue;
|
|
175
|
+
// 自主记忆那条工具不进「可以打开」的清单:列出来只会让模型去 enable,而那条路是封死的。
|
|
176
|
+
if (name === PROACTIVE_MEMORY_TOOL)
|
|
177
|
+
continue;
|
|
149
178
|
rows.push(toolLine(name, deps.toolTableSummaries.get(name) ?? '', bytes));
|
|
150
179
|
}
|
|
151
|
-
|
|
180
|
+
// 总数同样不含自主记忆那条工具:它不在工具表里,也不该出现在「N 条工具」的分母里。
|
|
181
|
+
const total = deps.toolTableSizes.size - (deps.toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? 1 : 0);
|
|
182
|
+
// 层级必须说清:模型要知道自己刚读的是「这个对话关着的」还是「整台机器关着的」——
|
|
183
|
+
// 它决定该不该去调 enable(全局粒度下那一改动的是所有对话)。与 `enable` / `disable`
|
|
184
|
+
// 的回执用同一句(`governingScopeNote`),两处不会各说一套。
|
|
152
185
|
if (rows.length === 0) {
|
|
153
|
-
return 'every tool of this plugin is already on here (' + total + ' tools); nothing to enable.';
|
|
186
|
+
return 'every tool of this plugin is already on here (' + total + ' tools)' + governingScopeNote(deps) + '; nothing to enable.';
|
|
154
187
|
}
|
|
155
|
-
return 'tools switched off here (' + rows.length + ' of ' + total + '):\n' +
|
|
188
|
+
return 'tools switched off here (' + rows.length + ' of ' + total + ')' + governingScopeNote(deps) + ':\n' +
|
|
156
189
|
rows.join('\n') +
|
|
157
190
|
'\ncall this tool with action="enable" and the names you need (one or more).';
|
|
158
191
|
}
|
package/lib/tools/deps.js
CHANGED
|
@@ -125,7 +125,7 @@ export const LIST_LIMIT_MAX = 100;
|
|
|
125
125
|
*
|
|
126
126
|
* 为什么要有上限:返回值进上下文,而**工具表管不着这一笔**(工具表只管 schema)。
|
|
127
127
|
* 模型爱「先全列出来看看」,一次就是几千 token —— 而它省下的那点(不用再调一次)
|
|
128
|
-
* 远不抵。`
|
|
128
|
+
* 远不抵。`memory_get` 的搜索与清单都带这个上限,别的 list 那几条没有 —— 同一族里
|
|
129
129
|
* 只有一条有限,不一致。
|
|
130
130
|
*/
|
|
131
131
|
export function listLimit(raw) {
|
|
@@ -270,7 +270,7 @@ export function sessionLayerOn(deps) {
|
|
|
270
270
|
* 全局,拒绝它只会让模型白跑一趟。
|
|
271
271
|
*
|
|
272
272
|
* 加在:技能 / 人设 / 场景 / MCP 四条 `*_save`、五条 `*_remove`。
|
|
273
|
-
* 不加在:`
|
|
273
|
+
* 不加在:`memory_remember`(它的 `scope` 指场景 / 工作区,不是会话层)、
|
|
274
274
|
* `*_manager_switch`(它们本来就按会话写,`scope` 是真的)。
|
|
275
275
|
* `prompt_manager_apply` 也从清单里去掉了:它的参数表里没有
|
|
276
276
|
* `scope`,守卫读不到东西 —— 模型按 schema 不可能传,这条守卫等于永不触发,留着只会
|
package/lib/tools/mcp.js
CHANGED
|
@@ -40,9 +40,9 @@ const MCP_LIST_HINT = ' (see mcp_manager_list — all=true also lists disabled o
|
|
|
40
40
|
* 指不到 `mcp_manager_list` 时的**中性出口**:不点名任何工具,两条常驻来源都成立
|
|
41
41
|
* —— 模型自己的 `mcp__<server>__<tool>` 工具名(就在它的 schema 里),以及注入段。
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* 为什么必须有这一句:MCP 域出厂没有一条可见工具(`mcp_manager_switch` 也在默认关停名单里),
|
|
44
|
+
* 猜错 serverName 时若报错里只有「没有这台服务器:X」,模型拿不到任何补救线索 —— 它只能猜
|
|
45
|
+
* 第二次。出口要么指向工具(那条工具得在它手里),要么指向这两条常驻来源。
|
|
46
46
|
*/
|
|
47
47
|
const MCP_NEUTRAL_HINT = ' (copy the server name from your own `mcp__<server>__<tool>` tool names, or take one listed in the "Current MCP servers" reminder)';
|
|
48
48
|
/** 按 serverName 定位条目;同名(project + global 各一台)时要求 level 明确指定。 */
|
|
@@ -452,7 +452,9 @@ export function buildMcpTools(deps) {
|
|
|
452
452
|
hint: { type: 'string', description: "Short hint for later (≤300 chars; longer is stored whole but truncated in listings). '' clears the existing hint." },
|
|
453
453
|
// MCP 服务器是**机器级**配置(cordis 补丁),没有「本会话的一份」。这个参数只为一件事:
|
|
454
454
|
// 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
|
|
455
|
-
|
|
455
|
+
// 不点名开关工具:它出厂默认关着(静态描述里点名一条模型可能没有的工具,
|
|
456
|
+
// 就是把它往墙上推 —— 契约测试也拦这一条)。运行时那条回执按可见性分叉。
|
|
457
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('the server config is machine-wide', 'switch the server on or off instead') },
|
|
456
458
|
},
|
|
457
459
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
458
460
|
async execute(args, exec) {
|