dsh-plugin-tool-management 0.22.5 → 0.22.7
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 +1652 -1415
- package/README.md +192 -177
- package/README_EN.md +192 -177
- package/docs/ARCHITECTURE.md +137 -134
- package/docs/COMPATIBILITY.md +112 -107
- package/docs/TROUBLESHOOTING.md +287 -285
- package/lib/client.js +15176 -12341
- 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 +107 -22
- 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 +41 -20
- 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 +498 -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 +883 -0
- package/lib/evolution/limits.js +21 -0
- package/lib/evolution/maintenance.js +544 -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 +178 -0
- package/lib/evolution/scope-card.js +144 -0
- package/lib/evolution/state.js +540 -0
- package/lib/evolution/write.js +1855 -0
- package/lib/index.js +1437 -57
- package/lib/legacy-tool-names.js +19 -4
- package/lib/mcp/tool-visibility.js +127 -10
- package/lib/memories/catalog.js +226 -0
- package/lib/memories/constants.js +137 -8
- package/lib/memories/discovery.js +59 -25
- package/lib/memories/projection.js +116 -31
- package/lib/memories/render-auto.js +199 -0
- package/lib/memories/search.js +3 -5
- package/lib/memories/service.js +168 -17
- package/lib/memories/snapshot.js +176 -24
- package/lib/op-registry.js +59 -0
- package/lib/ops/compat.js +6 -2
- package/lib/ops/evolution.js +896 -0
- package/lib/ops/memory.js +95 -72
- package/lib/ops/trash.js +14 -2
- package/lib/prompts/service.js +4 -1
- package/lib/scenes/candidates.js +5 -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 +65 -0
- package/lib/tool-table-switch.js +119 -19
- 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 +1098 -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 +103 -24
- package/package.json +155 -156
- package/docs/UPDATE.md +0 -50
package/lib/tool-table-switch.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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
|
-
// 它们整份不进请求(实测口径与取舍见 src/tools/table.ts
|
|
9
|
-
//
|
|
9
|
+
// 它们整份不进请求(实测口径与取舍见 src/tools/table.ts 的文件头)。**出厂就已经关了十八条**:
|
|
10
|
+
// 可勾选的 22 条里藏 17 条(实发 5 条),第十八条是自主笔记、跟随记忆页的总开关(开则实发 6 条)
|
|
11
|
+
// —— 名单、判据与代价在 `DEFAULT_HIDDEN_TOOLS`,只在这个人从没记过
|
|
10
12
|
// 选择时铺(见下面的 `toolTableSettingsFrom`)。
|
|
11
13
|
//
|
|
12
14
|
// 为什么放在目录之前:两个目录的「用 `X` 查」提示要跟着这份设置变(工具关掉后那句话
|
|
@@ -98,6 +100,9 @@ export function createToolTableSwitch(deps) {
|
|
|
98
100
|
toolTableIssueValue = checked.status;
|
|
99
101
|
publishToolTableNote(checked.status, checked.error);
|
|
100
102
|
}
|
|
103
|
+
// 工具表数据里不保留自主记忆那条工具:旧文件里残留的名字读出来就摘掉。
|
|
104
|
+
// 运行时可见性由 `withProactiveTool` / `overlayWithProactiveTool` 按开关强制。
|
|
105
|
+
value = { ...value, hidden: stripProactiveToolHidden(value.hidden) };
|
|
101
106
|
const changed = toolTableCache === null || toolTableCache.value.hidden.join('\u0000') !== value.hidden.join('\u0000');
|
|
102
107
|
toolTableCache = { at: Date.now(), value, off: new Set(value.hidden) };
|
|
103
108
|
// 首读 / 文件被外部改过 ⇒ 可见性要跟着重排。同步快照的调用方(门禁、注入通道)不会
|
|
@@ -113,7 +118,7 @@ export function createToolTableSwitch(deps) {
|
|
|
113
118
|
}
|
|
114
119
|
/**
|
|
115
120
|
* 同步快照(热路径用:工具门禁每次调用、注入通道每个 step 都要问一句)。还没加载时先给
|
|
116
|
-
* **空集**并异步预热 ——
|
|
121
|
+
* **空集**并异步预热 —— 空集不是出厂默认(出厂在 22 条里关着十七条),是刻意的:预热前的这一瞬与
|
|
117
122
|
* 用户的选择可能不一致,但方向必须是安全的那一侧(不隐藏任何东西,绝不因为读盘慢而让
|
|
118
123
|
* 工具凭空消失)。
|
|
119
124
|
*/
|
|
@@ -124,8 +129,22 @@ export function createToolTableSwitch(deps) {
|
|
|
124
129
|
}
|
|
125
130
|
return toolTableCache.off;
|
|
126
131
|
}
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
// 行集是可勾选的那 22 条:自主笔记那条**故意不在里面**(它没有手动开关,开关在记忆页)。
|
|
133
|
+
// 把它塞进来会让界面多画一行改不动的勾选,而"这条在不在表里"与"它发不发"是两件事。
|
|
134
|
+
// 实际发送由 `withProactiveTool` 在总开关开着时补上,报告用 `derived` / `sentCount` 交代。
|
|
135
|
+
const toolTableRows = () => [...toolTableSizes].filter(([name]) => name !== PROACTIVE_MEMORY_TOOL).map(([name, bytes]) => ({ name, bytes }));
|
|
136
|
+
/**
|
|
137
|
+
* 当前生效的关停名单(只含用户手动关的)。
|
|
138
|
+
*
|
|
139
|
+
* 报表与真实发送必须同一口径:自主笔记那条不在这份名单里(用户改不了),报告通过
|
|
140
|
+
* `derived` 单独说它开没开。顺手摘掉旧文件残留的名字 —— 读侧已经摘过一次,这里是第二道。
|
|
141
|
+
*/
|
|
142
|
+
const effectiveHidden = (hidden = [...toolTableHidden()]) => stripProactiveToolHidden(hidden);
|
|
143
|
+
const toolTableReport = (hidden) => buildToolTableReport(toolTableRows(), effectiveHidden(hidden), deps.carrierHiddenTools ? deps.carrierHiddenTools() : [], {
|
|
144
|
+
name: PROACTIVE_MEMORY_TOOL,
|
|
145
|
+
active: proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL),
|
|
146
|
+
bytes: toolTableSizes.get(PROACTIVE_MEMORY_TOOL) ?? 0,
|
|
147
|
+
});
|
|
129
148
|
/** 落盘 + 同步内存缓存;调用方必须已持有写锁。 */
|
|
130
149
|
async function writeToolTableSettingsLocked(next) {
|
|
131
150
|
// 锁内再确认一次:外部编辑器可能在这几毫秒里把文件写坏。此时覆盖同样会毁掉原内容。
|
|
@@ -136,13 +155,15 @@ export function createToolTableSwitch(deps) {
|
|
|
136
155
|
publishToolTableNote(checked.status, checked.error);
|
|
137
156
|
return { ok: false, error: toolTableRefuseMessage() };
|
|
138
157
|
}
|
|
158
|
+
// 落盘前再摘一次:旧文件 / 旧方案里残留的名字不能借这次写回磁盘。
|
|
159
|
+
const clean = { ...next, hidden: stripProactiveToolHidden(next.hidden) };
|
|
139
160
|
try {
|
|
140
|
-
await deps.writeJsonFile(hubPath(TOOL_TABLE_FILE),
|
|
161
|
+
await deps.writeJsonFile(hubPath(TOOL_TABLE_FILE), clean);
|
|
141
162
|
}
|
|
142
163
|
catch (e) {
|
|
143
164
|
return { ok: false, error: '设置保存失败: ' + deps.message(e) };
|
|
144
165
|
}
|
|
145
|
-
toolTableCache = { at: Date.now(), value:
|
|
166
|
+
toolTableCache = { at: Date.now(), value: clean, off: new Set(clean.hidden) };
|
|
146
167
|
toolTableStateValue = 'ok';
|
|
147
168
|
toolTableIssueValue = null;
|
|
148
169
|
clearRuntimeNote('tool-table-file');
|
|
@@ -159,6 +180,56 @@ export function createToolTableSwitch(deps) {
|
|
|
159
180
|
// 等待(锁可重入,但代价是重入方也一起变慢)。
|
|
160
181
|
return deps.withWriteLock(async () => await writeToolTableSettingsLocked(next));
|
|
161
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* 修复通道:把**损坏 / 不可读**的侧车改名留存,再按出厂名单继续。
|
|
185
|
+
*
|
|
186
|
+
* 为什么必须有:`unknown` 状态下所有写都被拒(`mutateToolTableSettings` 与
|
|
187
|
+
* `writeToolTableSettings` 两道),而唯一能改变状态的途径就是重写这个文件 ——
|
|
188
|
+
* 没有这条通道,侧车一坏,模型和用户都只能去手动删文件。
|
|
189
|
+
*
|
|
190
|
+
* 只在异常状态可用:健康的文件不做事(返回 `ok:false` 说明原因),免得把「恢复」
|
|
191
|
+
* 误用成「清空我的设置」。改名而不是删除:原文件留在 hub 里供事后排查。
|
|
192
|
+
*
|
|
193
|
+
* 改名后立刻写出厂名单,是因为 `unknown` 状态本身也要清 —— 只改名不写盘的话,
|
|
194
|
+
* 下一次读会把 missing 当默认,但缓存里的 unknown 与上报要等那次读才消。
|
|
195
|
+
*
|
|
196
|
+
* @returns `quarantined` = 留存文件的路径;`null` = 文件本来就不在(无可留存)。
|
|
197
|
+
*/
|
|
198
|
+
async function repairToolTable() {
|
|
199
|
+
await deps.ensurePaths();
|
|
200
|
+
return deps.withWriteLock(async () => {
|
|
201
|
+
const abs = hubPath(TOOL_TABLE_FILE);
|
|
202
|
+
const checked = checkToolTableRead(await deps.readJsonFileStrict(abs));
|
|
203
|
+
if (checked.status === 'ok' || checked.status === 'missing') {
|
|
204
|
+
return { ok: false, error: '工具表侧车当前可读(未损坏 / 未不可读),修复入口只在状态异常时可用;未改动任何东西' };
|
|
205
|
+
}
|
|
206
|
+
let quarantined = null;
|
|
207
|
+
try {
|
|
208
|
+
quarantined = abs + '.corrupt-' + new Date().toISOString().replace(/[:.]/g, '-');
|
|
209
|
+
await renameWithRetry(abs, quarantined);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
// 改名失败(权限 / 占用)就**不**写:写下去等于把读不出来的原文件覆盖掉。
|
|
213
|
+
return { ok: false, error: '修复失败(未改动原文件):' + deps.message(e) };
|
|
214
|
+
}
|
|
215
|
+
const clean = normalizeHidden([...DEFAULT_HIDDEN_TOOLS]);
|
|
216
|
+
try {
|
|
217
|
+
await deps.writeJsonFile(abs, { hidden: clean, presets: [] });
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
return { ok: false, error: '原文件已留存为 ' + quarantined + ',但写回出厂名单失败:' + deps.message(e) };
|
|
221
|
+
}
|
|
222
|
+
toolTableCache = { at: Date.now(), value: { hidden: clean, presets: [] }, off: new Set(clean) };
|
|
223
|
+
toolTableStateValue = 'ok';
|
|
224
|
+
toolTableIssueValue = null;
|
|
225
|
+
clearRuntimeNote('tool-table-file');
|
|
226
|
+
try {
|
|
227
|
+
deps.mcp.scheduleToolRestrictions();
|
|
228
|
+
}
|
|
229
|
+
catch { /* 可见性会等下一次 tools/change */ }
|
|
230
|
+
return { ok: true, quarantined };
|
|
231
|
+
});
|
|
232
|
+
}
|
|
162
233
|
/**
|
|
163
234
|
* 锁内读-改-写:strict 读当前值 → 回调算新值 → 再确认一次并落盘。
|
|
164
235
|
* 回调返回 `{ok:false}` 时不写盘;读坏时直接返回拒绝,绝不拿缓存 / 默认值当基线。
|
|
@@ -186,6 +257,17 @@ export function createToolTableSwitch(deps) {
|
|
|
186
257
|
return { ok: true, settings: next };
|
|
187
258
|
});
|
|
188
259
|
}
|
|
260
|
+
/** 自主记忆总开关此刻开没开。没装配时按关算(藏起来是安全侧)。 */
|
|
261
|
+
const proactiveOn = () => deps.proactiveMemoryEnabled?.() === true;
|
|
262
|
+
/** 此刻不允许被关掉的工具(只认已注册的;开关没开时是空表)。 */
|
|
263
|
+
const forcedVisible = () => proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? [PROACTIVE_MEMORY_TOOL] : [];
|
|
264
|
+
/** 此刻不允许被打开的工具(对称的另一半)。 */
|
|
265
|
+
const forcedHidden = () => !proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL) ? [PROACTIVE_MEMORY_TOOL] : [];
|
|
266
|
+
/**
|
|
267
|
+
* 工具表数据里永远不含自主记忆那条工具(展示与保存都不带它)。
|
|
268
|
+
* 运行时的「开 / 关」由 `withProactiveTool` 与 `overlayWithProactiveTool` 按开关强制。
|
|
269
|
+
*/
|
|
270
|
+
const normalizeHidden = (hidden) => stripProactiveToolHidden(hidden);
|
|
189
271
|
/**
|
|
190
272
|
* 回给界面的同一份形状:当前名单 + 已存方案 + 出厂默认名单 + 体积报告。
|
|
191
273
|
*
|
|
@@ -193,15 +275,23 @@ export function createToolTableSwitch(deps) {
|
|
|
193
275
|
* `DEFAULT_HIDDEN_TOOLS`),写进文件就会出现"用户删不掉的一条数据"。界面把它排在最前、
|
|
194
276
|
* 不给删除键,词典出它的名字。
|
|
195
277
|
*/
|
|
196
|
-
const toolTablePayload = (value) =>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
278
|
+
const toolTablePayload = (value) => {
|
|
279
|
+
const hidden = normalizeHidden(value.hidden);
|
|
280
|
+
return {
|
|
281
|
+
ok: true, hidden, presets: value.presets,
|
|
282
|
+
// 出厂名单同样不含自主记忆工具:它在界面上没有行,也不进「出厂默认关 N 条」的计数。
|
|
283
|
+
defaultHidden: stripProactiveToolHidden(DEFAULT_HIDDEN_TOOLS),
|
|
284
|
+
report: toolTableReport(hidden),
|
|
285
|
+
// 侧车状态随每次读回传:界面据此禁用开关并说明原因(unknown 时保存会被服务端拒绝)。
|
|
286
|
+
state: toolTableStateValue, issue: toolTableIssueValue,
|
|
287
|
+
};
|
|
288
|
+
};
|
|
202
289
|
/** 方案名:折叠空白 + 截到上限。空名由调用方报错(这里不猜"用户想叫什么")。 */
|
|
203
290
|
const presetNameOf = (raw) => String(raw ?? '').replaceAll(/\s+/g, ' ').trim().slice(0, PRESET_NAME_MAX_LENGTH);
|
|
204
291
|
async function toolTableOp(args) {
|
|
292
|
+
// 两个方向都锁:开着的不能关、关着的不能开,这条工具没有独立于总开关的状态。
|
|
293
|
+
const forced = new Set(forcedVisible());
|
|
294
|
+
const forcedOff = new Set(forcedHidden());
|
|
205
295
|
if (!args || args.set !== true) {
|
|
206
296
|
// 存 / 删方案都不动 `hidden`,所以这两条路**不**重排可见性、也不刷目录(那是 `set`
|
|
207
297
|
// 那一条才有的三处联动)。失败原因回 `code` 不回中文串 —— 英文界面会原样露出中文。
|
|
@@ -242,12 +332,21 @@ export function createToolTableSwitch(deps) {
|
|
|
242
332
|
.filter((t) => t && typeof t.name === 'string' && t.name !== '')
|
|
243
333
|
.map((t) => ({ name: String(t.name), hidden: t.hidden === true }))
|
|
244
334
|
// 只收**已注册**的名字:写进来的陌生名字在下一次 restrict 时会让官方抛错。
|
|
245
|
-
|
|
335
|
+
// 锁定的两条方向都不收:模型侧 `tool_manager_tools` 也改不动自主记忆工具。
|
|
336
|
+
.filter((t) => toolTableSizes.has(t.name) && !forced.has(t.name) && !forcedOff.has(t.name));
|
|
246
337
|
if (toggles.length === 0) {
|
|
247
|
-
|
|
338
|
+
const names = args.toggle.map((t) => String(t && t.name));
|
|
339
|
+
const blocked = names.filter((name) => forced.has(name) || forcedOff.has(name));
|
|
340
|
+
return {
|
|
341
|
+
ok: false,
|
|
342
|
+
error: blocked.length
|
|
343
|
+
? 'this tool follows the autonomous memory switch and cannot be toggled here: ' + blocked.join(', ')
|
|
344
|
+
: 'none of these are this plugin\'s tools: ' + names.join(', '),
|
|
345
|
+
};
|
|
248
346
|
}
|
|
249
347
|
const outcome = await mutateToolTableSettings((current) => ({
|
|
250
|
-
|
|
348
|
+
// 归一放在最后:不管盘上留的是上一版哪一边的值,这条工具都只跟总开关走。
|
|
349
|
+
hidden: normalizeHidden(applyToolTableToggles(current.hidden, toggles)),
|
|
251
350
|
presets: current.presets,
|
|
252
351
|
}));
|
|
253
352
|
if (!outcome.ok)
|
|
@@ -262,8 +361,8 @@ export function createToolTableSwitch(deps) {
|
|
|
262
361
|
// 只收**已注册**的名字:写进来的陌生名字在下一次 restrict 时会让官方抛错
|
|
263
362
|
// ("names unknown global tool")。注册失败的工具本来也不在表里。
|
|
264
363
|
const outcome = await mutateToolTableSettings((current) => {
|
|
265
|
-
|
|
266
|
-
|
|
364
|
+
// 先滤掉没注册的名字,再归一那条跟随开关的工具(顺序不能反:归一可能往里加名字)。
|
|
365
|
+
const hidden = normalizeHidden(normalizeToolTableSettings({ hidden: args.hidden }).hidden.filter((name) => toolTableSizes.has(name)));
|
|
267
366
|
return { hidden, presets: current.presets };
|
|
268
367
|
});
|
|
269
368
|
if (!outcome.ok)
|
|
@@ -289,5 +388,6 @@ export function createToolTableSwitch(deps) {
|
|
|
289
388
|
mutateToolTableSettings,
|
|
290
389
|
toolTableReport,
|
|
291
390
|
toolTableOp,
|
|
391
|
+
repairToolTable,
|
|
292
392
|
};
|
|
293
393
|
}
|
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) {
|