dsh-plugin-tool-management 0.22.4 → 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 -1395
- package/README.md +194 -177
- package/README_EN.md +194 -177
- package/docs/ARCHITECTURE.md +137 -0
- package/docs/COMPATIBILITY.md +112 -0
- package/docs/TROUBLESHOOTING.md +287 -0
- package/lib/client.js +14984 -12279
- package/lib/compat/capability-specs.js +66 -16
- package/lib/compat/host-contracts.js +14 -3
- 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 +74 -22
- package/lib/context-inject.js +107 -15
- 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/imports/unzip.js +144 -26
- package/lib/index.js +1371 -79
- package/lib/legacy-tool-names.js +19 -4
- package/lib/mcp/manager.js +1 -0
- package/lib/mcp/tool-visibility.js +204 -11
- 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 +252 -17
- 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 +30 -0
- package/lib/scope/workspace-key.js +39 -0
- package/lib/settings-sidecars.js +2 -2
- package/lib/skills/dir-watch.js +49 -22
- package/lib/skills/official.js +180 -36
- package/lib/skills/service.js +2 -2
- 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 -152
- package/docs/UPDATE.md +0 -49
package/lib/tool-table-switch.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { renameWithRetry } from './skills/core-util.js';
|
|
1
2
|
import { clearRuntimeNote, noteRuntime } from './compat/runtime-notes.js';
|
|
2
3
|
import { hubPath } from './hub.js';
|
|
3
|
-
import { addPreset, applyToolTableToggles, buildToolTableReport, classifyToolTableSettings, DEFAULT_HIDDEN_TOOLS, DEFAULT_TOOL_TABLE_SETTINGS, dropPreset, migrateLegacyToolNames, normalizeToolTableSettings, PRESET_MAX_COUNT, PRESET_NAME_MAX_LENGTH, summarizeToolDescription, } from './tools/table.js';
|
|
4
|
+
import { addPreset, applyToolTableToggles, buildToolTableReport, classifyToolTableSettings, DEFAULT_HIDDEN_TOOLS, DEFAULT_TOOL_TABLE_SETTINGS, dropPreset, migrateLegacyToolNames, normalizeToolTableSettings, PRESET_MAX_COUNT, PRESET_NAME_MAX_LENGTH, PROACTIVE_MEMORY_TOOL, stripProactiveToolHidden, summarizeToolDescription, } from './tools/table.js';
|
|
4
5
|
/** 模型工具表开关(侧车 `tool-table.json`):出厂默认名单、按会话 / 全局改可见集。 */
|
|
5
6
|
export function createToolTableSwitch(deps) {
|
|
6
7
|
// ---------- 模型工具表开关(侧车 `tool-table.json`,界面在「兼容」页)----------
|
|
7
8
|
// 工具表按**每个请求**付钱:整张表的定义合计 ≈6.1k tok 每轮都在。关掉某几个,
|
|
8
9
|
// 它们整份不进请求(实测口径与取舍见 src/tools/table.ts 的文件头)。**出厂就已经关了十八条**
|
|
9
|
-
// (
|
|
10
|
+
// (23 条里实发 5 条)—— 名单、判据与代价在 `DEFAULT_HIDDEN_TOOLS`,只在这个人从没记过
|
|
10
11
|
// 选择时铺(见下面的 `toolTableSettingsFrom`)。
|
|
11
12
|
//
|
|
12
13
|
// 为什么放在目录之前:两个目录的「用 `X` 查」提示要跟着这份设置变(工具关掉后那句话
|
|
@@ -98,6 +99,9 @@ export function createToolTableSwitch(deps) {
|
|
|
98
99
|
toolTableIssueValue = checked.status;
|
|
99
100
|
publishToolTableNote(checked.status, checked.error);
|
|
100
101
|
}
|
|
102
|
+
// 工具表数据里不保留自主记忆那条工具:旧文件里残留的名字读出来就摘掉。
|
|
103
|
+
// 运行时可见性由 `withProactiveTool` / `overlayWithProactiveTool` 按开关强制。
|
|
104
|
+
value = { ...value, hidden: stripProactiveToolHidden(value.hidden) };
|
|
101
105
|
const changed = toolTableCache === null || toolTableCache.value.hidden.join('\u0000') !== value.hidden.join('\u0000');
|
|
102
106
|
toolTableCache = { at: Date.now(), value, off: new Set(value.hidden) };
|
|
103
107
|
// 首读 / 文件被外部改过 ⇒ 可见性要跟着重排。同步快照的调用方(门禁、注入通道)不会
|
|
@@ -124,7 +128,10 @@ export function createToolTableSwitch(deps) {
|
|
|
124
128
|
}
|
|
125
129
|
return toolTableCache.off;
|
|
126
130
|
}
|
|
127
|
-
|
|
131
|
+
// 自主记忆那条工具不进报表:它不出现在面板里,也不该出现在分组计数 / 体积合计里。
|
|
132
|
+
const toolTableRows = () => [...toolTableSizes]
|
|
133
|
+
.filter(([name]) => name !== PROACTIVE_MEMORY_TOOL)
|
|
134
|
+
.map(([name, bytes]) => ({ name, bytes }));
|
|
128
135
|
const toolTableReport = (hidden = [...toolTableHidden()]) => buildToolTableReport(toolTableRows(), hidden, deps.carrierHiddenTools ? deps.carrierHiddenTools() : []);
|
|
129
136
|
/** 落盘 + 同步内存缓存;调用方必须已持有写锁。 */
|
|
130
137
|
async function writeToolTableSettingsLocked(next) {
|
|
@@ -136,13 +143,15 @@ export function createToolTableSwitch(deps) {
|
|
|
136
143
|
publishToolTableNote(checked.status, checked.error);
|
|
137
144
|
return { ok: false, error: toolTableRefuseMessage() };
|
|
138
145
|
}
|
|
146
|
+
// 落盘前再摘一次:旧文件 / 旧方案里残留的名字不能借这次写回磁盘。
|
|
147
|
+
const clean = { ...next, hidden: stripProactiveToolHidden(next.hidden) };
|
|
139
148
|
try {
|
|
140
|
-
await deps.writeJsonFile(hubPath(TOOL_TABLE_FILE),
|
|
149
|
+
await deps.writeJsonFile(hubPath(TOOL_TABLE_FILE), clean);
|
|
141
150
|
}
|
|
142
151
|
catch (e) {
|
|
143
152
|
return { ok: false, error: '设置保存失败: ' + deps.message(e) };
|
|
144
153
|
}
|
|
145
|
-
toolTableCache = { at: Date.now(), value:
|
|
154
|
+
toolTableCache = { at: Date.now(), value: clean, off: new Set(clean.hidden) };
|
|
146
155
|
toolTableStateValue = 'ok';
|
|
147
156
|
toolTableIssueValue = null;
|
|
148
157
|
clearRuntimeNote('tool-table-file');
|
|
@@ -159,6 +168,56 @@ export function createToolTableSwitch(deps) {
|
|
|
159
168
|
// 等待(锁可重入,但代价是重入方也一起变慢)。
|
|
160
169
|
return deps.withWriteLock(async () => await writeToolTableSettingsLocked(next));
|
|
161
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* 修复通道:把**损坏 / 不可读**的侧车改名留存,再按出厂名单继续。
|
|
173
|
+
*
|
|
174
|
+
* 为什么必须有:`unknown` 状态下所有写都被拒(`mutateToolTableSettings` 与
|
|
175
|
+
* `writeToolTableSettings` 两道),而唯一能改变状态的途径就是重写这个文件 ——
|
|
176
|
+
* 没有这条通道,侧车一坏,模型和用户都只能去手动删文件。
|
|
177
|
+
*
|
|
178
|
+
* 只在异常状态可用:健康的文件不做事(返回 `ok:false` 说明原因),免得把「恢复」
|
|
179
|
+
* 误用成「清空我的设置」。改名而不是删除:原文件留在 hub 里供事后排查。
|
|
180
|
+
*
|
|
181
|
+
* 改名后立刻写出厂名单,是因为 `unknown` 状态本身也要清 —— 只改名不写盘的话,
|
|
182
|
+
* 下一次读会把 missing 当默认,但缓存里的 unknown 与上报要等那次读才消。
|
|
183
|
+
*
|
|
184
|
+
* @returns `quarantined` = 留存文件的路径;`null` = 文件本来就不在(无可留存)。
|
|
185
|
+
*/
|
|
186
|
+
async function repairToolTable() {
|
|
187
|
+
await deps.ensurePaths();
|
|
188
|
+
return deps.withWriteLock(async () => {
|
|
189
|
+
const abs = hubPath(TOOL_TABLE_FILE);
|
|
190
|
+
const checked = checkToolTableRead(await deps.readJsonFileStrict(abs));
|
|
191
|
+
if (checked.status === 'ok' || checked.status === 'missing') {
|
|
192
|
+
return { ok: false, error: '工具表侧车当前可读(未损坏 / 未不可读),修复入口只在状态异常时可用;未改动任何东西' };
|
|
193
|
+
}
|
|
194
|
+
let quarantined = null;
|
|
195
|
+
try {
|
|
196
|
+
quarantined = abs + '.corrupt-' + new Date().toISOString().replace(/[:.]/g, '-');
|
|
197
|
+
await renameWithRetry(abs, quarantined);
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
// 改名失败(权限 / 占用)就**不**写:写下去等于把读不出来的原文件覆盖掉。
|
|
201
|
+
return { ok: false, error: '修复失败(未改动原文件):' + deps.message(e) };
|
|
202
|
+
}
|
|
203
|
+
const clean = normalizeHidden([...DEFAULT_HIDDEN_TOOLS]);
|
|
204
|
+
try {
|
|
205
|
+
await deps.writeJsonFile(abs, { hidden: clean, presets: [] });
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
return { ok: false, error: '原文件已留存为 ' + quarantined + ',但写回出厂名单失败:' + deps.message(e) };
|
|
209
|
+
}
|
|
210
|
+
toolTableCache = { at: Date.now(), value: { hidden: clean, presets: [] }, off: new Set(clean) };
|
|
211
|
+
toolTableStateValue = 'ok';
|
|
212
|
+
toolTableIssueValue = null;
|
|
213
|
+
clearRuntimeNote('tool-table-file');
|
|
214
|
+
try {
|
|
215
|
+
deps.mcp.scheduleToolRestrictions();
|
|
216
|
+
}
|
|
217
|
+
catch { /* 可见性会等下一次 tools/change */ }
|
|
218
|
+
return { ok: true, quarantined };
|
|
219
|
+
});
|
|
220
|
+
}
|
|
162
221
|
/**
|
|
163
222
|
* 锁内读-改-写:strict 读当前值 → 回调算新值 → 再确认一次并落盘。
|
|
164
223
|
* 回调返回 `{ok:false}` 时不写盘;读坏时直接返回拒绝,绝不拿缓存 / 默认值当基线。
|
|
@@ -186,6 +245,17 @@ export function createToolTableSwitch(deps) {
|
|
|
186
245
|
return { ok: true, settings: next };
|
|
187
246
|
});
|
|
188
247
|
}
|
|
248
|
+
/** 自主记忆总开关此刻开没开。没装配时按关算(藏起来是安全侧)。 */
|
|
249
|
+
const proactiveOn = () => deps.proactiveMemoryEnabled?.() === true;
|
|
250
|
+
/** 此刻不允许被关掉的工具(只认已注册的;开关没开时是空表)。 */
|
|
251
|
+
const forcedVisible = () => proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? [PROACTIVE_MEMORY_TOOL] : [];
|
|
252
|
+
/** 此刻不允许被打开的工具(对称的另一半)。 */
|
|
253
|
+
const forcedHidden = () => !proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? [PROACTIVE_MEMORY_TOOL] : [];
|
|
254
|
+
/**
|
|
255
|
+
* 工具表数据里永远不含自主记忆那条工具(展示与保存都不带它)。
|
|
256
|
+
* 运行时的「开 / 关」由 `withProactiveTool` 与 `overlayWithProactiveTool` 按开关强制。
|
|
257
|
+
*/
|
|
258
|
+
const normalizeHidden = (hidden) => stripProactiveToolHidden(hidden);
|
|
189
259
|
/**
|
|
190
260
|
* 回给界面的同一份形状:当前名单 + 已存方案 + 出厂默认名单 + 体积报告。
|
|
191
261
|
*
|
|
@@ -193,15 +263,23 @@ export function createToolTableSwitch(deps) {
|
|
|
193
263
|
* `DEFAULT_HIDDEN_TOOLS`),写进文件就会出现"用户删不掉的一条数据"。界面把它排在最前、
|
|
194
264
|
* 不给删除键,词典出它的名字。
|
|
195
265
|
*/
|
|
196
|
-
const toolTablePayload = (value) =>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
266
|
+
const toolTablePayload = (value) => {
|
|
267
|
+
const hidden = normalizeHidden(value.hidden);
|
|
268
|
+
return {
|
|
269
|
+
ok: true, hidden, presets: value.presets,
|
|
270
|
+
// 出厂名单同样不含自主记忆工具:它在界面上没有行,也不进「出厂默认关 N 条」的计数。
|
|
271
|
+
defaultHidden: stripProactiveToolHidden(DEFAULT_HIDDEN_TOOLS),
|
|
272
|
+
report: toolTableReport(hidden),
|
|
273
|
+
// 侧车状态随每次读回传:界面据此禁用开关并说明原因(unknown 时保存会被服务端拒绝)。
|
|
274
|
+
state: toolTableStateValue, issue: toolTableIssueValue,
|
|
275
|
+
};
|
|
276
|
+
};
|
|
202
277
|
/** 方案名:折叠空白 + 截到上限。空名由调用方报错(这里不猜"用户想叫什么")。 */
|
|
203
278
|
const presetNameOf = (raw) => String(raw ?? '').replaceAll(/\s+/g, ' ').trim().slice(0, PRESET_NAME_MAX_LENGTH);
|
|
204
279
|
async function toolTableOp(args) {
|
|
280
|
+
// 两个方向都锁:开着的不能关、关着的不能开,这条工具没有独立于总开关的状态。
|
|
281
|
+
const forced = new Set(forcedVisible());
|
|
282
|
+
const forcedOff = new Set(forcedHidden());
|
|
205
283
|
if (!args || args.set !== true) {
|
|
206
284
|
// 存 / 删方案都不动 `hidden`,所以这两条路**不**重排可见性、也不刷目录(那是 `set`
|
|
207
285
|
// 那一条才有的三处联动)。失败原因回 `code` 不回中文串 —— 英文界面会原样露出中文。
|
|
@@ -242,12 +320,21 @@ export function createToolTableSwitch(deps) {
|
|
|
242
320
|
.filter((t) => t && typeof t.name === 'string' && t.name !== '')
|
|
243
321
|
.map((t) => ({ name: String(t.name), hidden: t.hidden === true }))
|
|
244
322
|
// 只收**已注册**的名字:写进来的陌生名字在下一次 restrict 时会让官方抛错。
|
|
245
|
-
|
|
323
|
+
// 锁定的两条方向都不收:模型侧 `tool_manager_tools` 也改不动自主记忆工具。
|
|
324
|
+
.filter((t) => toolTableSizes.has(t.name) && !forced.has(t.name) && !forcedOff.has(t.name));
|
|
246
325
|
if (toggles.length === 0) {
|
|
247
|
-
|
|
326
|
+
const names = args.toggle.map((t) => String(t && t.name));
|
|
327
|
+
const blocked = names.filter((name) => forced.has(name) || forcedOff.has(name));
|
|
328
|
+
return {
|
|
329
|
+
ok: false,
|
|
330
|
+
error: blocked.length
|
|
331
|
+
? 'this tool follows the autonomous memory switch and cannot be toggled here: ' + blocked.join(', ')
|
|
332
|
+
: 'none of these are this plugin\'s tools: ' + names.join(', '),
|
|
333
|
+
};
|
|
248
334
|
}
|
|
249
335
|
const outcome = await mutateToolTableSettings((current) => ({
|
|
250
|
-
|
|
336
|
+
// 归一放在最后:不管盘上留的是上一版哪一边的值,这条工具都只跟总开关走。
|
|
337
|
+
hidden: normalizeHidden(applyToolTableToggles(current.hidden, toggles)),
|
|
251
338
|
presets: current.presets,
|
|
252
339
|
}));
|
|
253
340
|
if (!outcome.ok)
|
|
@@ -262,8 +349,8 @@ export function createToolTableSwitch(deps) {
|
|
|
262
349
|
// 只收**已注册**的名字:写进来的陌生名字在下一次 restrict 时会让官方抛错
|
|
263
350
|
// ("names unknown global tool")。注册失败的工具本来也不在表里。
|
|
264
351
|
const outcome = await mutateToolTableSettings((current) => {
|
|
265
|
-
|
|
266
|
-
|
|
352
|
+
// 先滤掉没注册的名字,再归一那条跟随开关的工具(顺序不能反:归一可能往里加名字)。
|
|
353
|
+
const hidden = normalizeHidden(normalizeToolTableSettings({ hidden: args.hidden }).hidden.filter((name) => toolTableSizes.has(name)));
|
|
267
354
|
return { hidden, presets: current.presets };
|
|
268
355
|
});
|
|
269
356
|
if (!outcome.ok)
|
|
@@ -289,5 +376,6 @@ export function createToolTableSwitch(deps) {
|
|
|
289
376
|
mutateToolTableSettings,
|
|
290
377
|
toolTableReport,
|
|
291
378
|
toolTableOp,
|
|
379
|
+
repairToolTable,
|
|
292
380
|
};
|
|
293
381
|
}
|
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) {
|