dsh-plugin-tool-management 0.22.6 → 0.22.8
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 +51 -0
- package/README.md +17 -19
- package/README_EN.md +16 -18
- package/docs/COMPATIBILITY.md +112 -112
- package/docs/TROUBLESHOOTING.md +5 -5
- package/lib/client.js +239 -164
- package/lib/compat/capability-specs.js +1 -1
- package/lib/compat/probe.js +19 -19
- package/lib/confirm-gate.js +13 -13
- package/lib/context-inject-contract.js +6 -9
- package/lib/context-inject-frame.js +10 -8
- package/lib/context-inject-surface.js +1 -1
- package/lib/context-inject.js +1 -1
- package/lib/evolution/cold.js +2 -2
- package/lib/evolution/config.js +6 -15
- package/lib/evolution/gates.js +11 -2
- package/lib/evolution/maintenance.js +40 -12
- package/lib/evolution/notes.js +47 -6
- package/lib/evolution/review.js +1 -1
- package/lib/evolution/runtime.js +0 -1
- package/lib/evolution/state.js +29 -3
- package/lib/evolution/write.js +228 -79
- package/lib/index.js +210 -95
- package/lib/legacy-tool-names.js +39 -28
- package/lib/mcp/state-section.js +2 -2
- package/lib/memories/catalog.js +11 -0
- package/lib/memories/constants.js +34 -13
- package/lib/memories/projection.js +1 -1
- package/lib/memories/render-auto.js +11 -10
- package/lib/memories/service.js +10 -3
- package/lib/memories/snapshot.js +6 -5
- package/lib/op-registry.js +3 -0
- package/lib/ops/compat.js +4 -2
- package/lib/ops/evolution.js +52 -32
- package/lib/ops/memory.js +1 -1
- package/lib/ops/trash.js +1 -1
- package/lib/scenes/candidates.js +5 -1
- package/lib/skills/catalog.js +2 -2
- package/lib/subagents/catalog.js +1 -1
- package/lib/subagents/persona-parse.js +22 -3
- package/lib/subagents/run-provider.js +4 -4
- package/lib/text-width.js +8 -2
- package/lib/tool-table-switch.js +21 -9
- package/lib/tools/control.js +3 -3
- package/lib/tools/deps.js +4 -4
- package/lib/tools/memory.js +95 -42
- package/lib/tools/prompt.js +1 -1
- package/lib/tools/remove.js +4 -4
- package/lib/tools/scene.js +1 -1
- package/lib/tools/table.js +40 -17
- package/lib/trash-id.js +1 -1
- package/package.json +24 -24
package/lib/tools/memory.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// 记忆(rules)域的 model 工具:
|
|
1
|
+
// 记忆(rules)域的 model 工具:memory_manager_get / memory_manager_switch / memory_manager_remember。
|
|
2
2
|
//
|
|
3
|
-
// 自主笔记(agent 学的一句话)是另一族 `
|
|
4
|
-
// `
|
|
3
|
+
// 自主笔记(agent 学的一句话)是另一族 `memory_manager_note`:两族按对象分开,读取统一走
|
|
4
|
+
// `memory_manager_get`,id 形状也不同(用户记忆 `<scene>/<name>`,笔记 `note:<layer>/<slug>`)。
|
|
5
5
|
//
|
|
6
|
-
// 为什么工具名是 `
|
|
6
|
+
// 为什么工具名是 `memory_manager_*` 而不是 `scene_memory_manager_*`:后者描述的是**域**,
|
|
7
7
|
// 而这些工具操作的全是记忆。加场景能力时这个错配就现形了 —— 场景是另一个对象(容器,
|
|
8
8
|
// 进入时切换 mcp / 技能 / 人设),硬塞进同一个写工具会让 `description` 变成双义参数、
|
|
9
9
|
// 门禁按参数分叉(记忆写入有开关可放行,场景写入是改运行时环境、不该有那条路)。
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// 模型必须自己先查一次再决定调哪条,而它手里的清单可能已经过期。合并后由工具侧兜住。
|
|
18
18
|
//
|
|
19
19
|
// 活动场景的记忆正文会自动注入上下文(无需调用工具读取);这里的工具用于查询/编辑规则
|
|
20
|
-
// 本身。
|
|
20
|
+
// 本身。memory_manager_remember 受 tools/pre-execute 审批门禁。
|
|
21
21
|
// 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
|
|
22
22
|
import { GLOBAL_SCENE, MAX_GROUP_SEGMENT_LENGTH, SHARED_GROUP } from '../memories/constants.js';
|
|
23
23
|
import { MAX_AUTO_TEXT_WIDTH, MAX_AUTO_TITLE_WIDTH } from '../evolution/write.js';
|
|
@@ -51,10 +51,37 @@ export function buildMemoryTools(deps) {
|
|
|
51
51
|
throw new Error('missing op: ' + name + ' (the plugin is only partly assembled)');
|
|
52
52
|
return fn;
|
|
53
53
|
};
|
|
54
|
+
// 开关决定能力面:关掉的层连 `layer` 参数都不该出现。省略依赖时按两层都开处理,
|
|
55
|
+
// 让旧装配 / 单元测试保持原行为。
|
|
56
|
+
const noteLayersOf = (agent) => {
|
|
57
|
+
const got = deps.autoNoteLayers ? deps.autoNoteLayers(agent) : undefined;
|
|
58
|
+
return got ?? { global: true, workspace: true };
|
|
59
|
+
};
|
|
60
|
+
const noteReadLayersOf = (agent) => {
|
|
61
|
+
const got = deps.autoNoteReadLayers
|
|
62
|
+
? deps.autoNoteReadLayers(agent)
|
|
63
|
+
: deps.autoNoteLayers ? deps.autoNoteLayers(agent) : undefined;
|
|
64
|
+
return got ?? { global: true, workspace: true };
|
|
65
|
+
};
|
|
66
|
+
// 只有两层都开时层才是模型要选的东西;只剩一层时强制那一层,schema 里不留 `layer`。
|
|
67
|
+
const noteLayerParameter = {
|
|
68
|
+
type: 'string',
|
|
69
|
+
enum: ['global', 'workspace'],
|
|
70
|
+
description: 'global = every project; workspace = this project. Omit when unsure: the user chooses the layer on the card, or its default applies.',
|
|
71
|
+
};
|
|
72
|
+
const applyNoteLayerSchema = (tool, layers) => {
|
|
73
|
+
const properties = tool && tool.parameters && tool.parameters.properties;
|
|
74
|
+
if (!properties)
|
|
75
|
+
return;
|
|
76
|
+
if (layers.global && layers.workspace)
|
|
77
|
+
properties.layer = noteLayerParameter;
|
|
78
|
+
else
|
|
79
|
+
delete properties.layer;
|
|
80
|
+
};
|
|
54
81
|
/**
|
|
55
82
|
* 这条规则是不是自主笔记而不是用户记忆。
|
|
56
83
|
*
|
|
57
|
-
* `
|
|
84
|
+
* `memory_manager_get` 把两族并成一份输出,用户记忆那一半必须把笔记摘掉 —— 否则同一句话
|
|
58
85
|
* 会在「user memories」与「agent notes」各出现一次。`origin` 是权威字段;旧数据
|
|
59
86
|
* 没有它时按目录判(`_ws` / `_session` 只由笔记后端写入,见 memories/catalog.ts)。
|
|
60
87
|
*/
|
|
@@ -206,15 +233,16 @@ export function buildMemoryTools(deps) {
|
|
|
206
233
|
}
|
|
207
234
|
return lines.join('\n');
|
|
208
235
|
};
|
|
209
|
-
const noteCatalogText = async (all, limit) => {
|
|
236
|
+
const noteCatalogText = async (all, limit, layers) => {
|
|
210
237
|
if (!evo)
|
|
211
238
|
return '';
|
|
212
239
|
const r = await opOf(evo, 'evolution-list')({ all });
|
|
213
240
|
if (!r || r.ok === false)
|
|
214
241
|
throw new Error(String((r && r.error) || 'failed to read agent notes'));
|
|
215
|
-
const rows = Array.isArray(r.entries) ? r.entries : []
|
|
242
|
+
const rows = (Array.isArray(r.entries) ? r.entries : [])
|
|
243
|
+
.filter((e) => e.layer === 'workspace' ? layers.workspace : layers.global);
|
|
216
244
|
const shown = rows.slice(0, limit);
|
|
217
|
-
const order = ['workspace', 'global'];
|
|
245
|
+
const order = ['workspace', 'global'].filter((l) => l === 'workspace' ? layers.workspace : layers.global);
|
|
218
246
|
const lines = [];
|
|
219
247
|
for (const layer of order) {
|
|
220
248
|
const group = shown.filter((e) => e.layer === layer);
|
|
@@ -228,7 +256,7 @@ export function buildMemoryTools(deps) {
|
|
|
228
256
|
(e.key && String(e.key) !== String(e.id).slice(String(e.id).lastIndexOf('/') + 1) ? ' · slot ' + String(e.key) : '') +
|
|
229
257
|
(e.title ? ' · ' + String(e.title) : '') +
|
|
230
258
|
// 类型决定保质期,也是「这条是做法还是偏好」的唯一机器可读标记:
|
|
231
|
-
// 模型要靠它决定该不该照着做、值不值得 `
|
|
259
|
+
// 模型要靠它决定该不该照着做、值不值得 `memory_manager_get` 读全文。
|
|
232
260
|
// `evolution-list` 一直在返回 `kind`,这里此前没读。
|
|
233
261
|
(e.kind ? ' · ' + String(e.kind) : '') +
|
|
234
262
|
' · ' + String(e.tier || 'inferred') +
|
|
@@ -238,12 +266,14 @@ export function buildMemoryTools(deps) {
|
|
|
238
266
|
(e.oneLine ? ' — ' + String(e.oneLine) : ''));
|
|
239
267
|
}
|
|
240
268
|
}
|
|
269
|
+
// 总数只在两层都开时可信:只剩一层时 `r.total` 含已关层的条目,报出来就是泄漏。
|
|
270
|
+
const both = layers.global && layers.workspace;
|
|
241
271
|
const head = 'agent notes: ' + rows.length + ' listed' +
|
|
242
|
-
(r.total !== undefined ? ' / ' + r.total + ' in catalog' : '') +
|
|
272
|
+
(both && r.total !== undefined ? ' / ' + r.total + ' in catalog' : '') +
|
|
243
273
|
(rows.length > shown.length ? ' (showing ' + shown.length + ', raise limit for more)' : '');
|
|
244
274
|
return head + '\n' + (lines.join('\n') || '(none)');
|
|
245
275
|
};
|
|
246
|
-
const noteSearchText = async (query, limit) => {
|
|
276
|
+
const noteSearchText = async (query, limit, layers) => {
|
|
247
277
|
if (!evo)
|
|
248
278
|
return '';
|
|
249
279
|
// 与用户记忆搜索同口径:搜索覆盖归档 / 未注入的条目,`all` 只影响清单。
|
|
@@ -252,7 +282,9 @@ export function buildMemoryTools(deps) {
|
|
|
252
282
|
if (!r || r.ok === false)
|
|
253
283
|
throw new Error(String((r && r.error) || 'failed to read agent notes'));
|
|
254
284
|
const words = query.toLowerCase().split(/\s+/).filter((w) => w !== '');
|
|
255
|
-
const rows = (Array.isArray(r.entries) ? r.entries : [])
|
|
285
|
+
const rows = (Array.isArray(r.entries) ? r.entries : [])
|
|
286
|
+
.filter((e) => e.layer === 'workspace' ? layers.workspace : layers.global)
|
|
287
|
+
.filter((e) => {
|
|
256
288
|
// `kind` 也要能搜:结果行里印着它(「列出所有做法类笔记」是很自然的请求),
|
|
257
289
|
// 只显示不索引等于「看得见、搜不到」。类型是四个固定词,不会污染正文匹配。
|
|
258
290
|
const hay = [e.id, e.key, e.title, e.oneLine, e.body, e.boundary, e.alias, e.kind]
|
|
@@ -373,7 +405,7 @@ export function buildMemoryTools(deps) {
|
|
|
373
405
|
throw new Error('no user memory with id "' + id + '"; ' + (e instanceof Error ? e.message : String(e)));
|
|
374
406
|
}
|
|
375
407
|
}
|
|
376
|
-
throw new Error('no user memory with id "' + id + '". Call
|
|
408
|
+
throw new Error('no user memory with id "' + id + '". Call memory_manager_get with no id to list what exists.');
|
|
377
409
|
};
|
|
378
410
|
/**
|
|
379
411
|
* 从标题或正文首行派生文件名:保留 Unicode,去掉路径分隔符与控制字符,空白压成 `-`。
|
|
@@ -415,7 +447,7 @@ export function buildMemoryTools(deps) {
|
|
|
415
447
|
return [...names];
|
|
416
448
|
};
|
|
417
449
|
register(defineTool({
|
|
418
|
-
name: '
|
|
450
|
+
name: 'memory_manager_get',
|
|
419
451
|
description: 'Look up user-written memories and agent notes. No id → catalog (what exists and what injects); `id` → full body; `query` → filtered catalog with snippets. Agent note ids start with `note:`. Use this for ids and for entries not already in your context. Does not modify any memory; reading an agent note does count as a use, which keeps a note that is actually needed from aging out.',
|
|
420
452
|
parameters: {
|
|
421
453
|
id: { type: 'string', description: 'Read one entry: a user memory id (<scene>/<name>) or an agent note id (note:...).' },
|
|
@@ -452,7 +484,8 @@ export function buildMemoryTools(deps) {
|
|
|
452
484
|
// 自主记忆关着时,笔记不在这份清单里出现:功能没开,模型不该看到「有笔记可读」
|
|
453
485
|
// 这种半开状态(直接给 note: id 仍然读得到 —— 那是显式请求)。
|
|
454
486
|
const readable = deps.autoNotesReadable ?? deps.autoLearnEnabled;
|
|
455
|
-
const
|
|
487
|
+
const readLayers = noteReadLayersOf(exec && exec.agent);
|
|
488
|
+
const notesOn = Boolean(evo && readable && readable(exec && exec.agent) && (readLayers.global || readLayers.workspace));
|
|
456
489
|
if (kind === 'note' && !notesOn) {
|
|
457
490
|
throw new Error('autonomous memory is off here, so agent notes are not available. The user can turn it on in Memory → Autonomous memory.');
|
|
458
491
|
}
|
|
@@ -463,13 +496,13 @@ export function buildMemoryTools(deps) {
|
|
|
463
496
|
: await userCatalogText(all, limit, scene, exec));
|
|
464
497
|
}
|
|
465
498
|
if (kind !== 'memory' && notesOn) {
|
|
466
|
-
sections.push(query !== '' ? await noteSearchText(query, limit) : await noteCatalogText(all, limit));
|
|
499
|
+
sections.push(query !== '' ? await noteSearchText(query, limit, readLayers) : await noteCatalogText(all, limit, readLayers));
|
|
467
500
|
}
|
|
468
501
|
return sections.filter((s) => s !== '').join('\n\n') || '(none)';
|
|
469
502
|
},
|
|
470
503
|
}));
|
|
471
504
|
register(defineTool({
|
|
472
|
-
name: '
|
|
505
|
+
name: 'memory_manager_switch',
|
|
473
506
|
// 为什么叫 `_switch` 而不是 `_set_enabled`:六个域里"拨一个开关"
|
|
474
507
|
// 是同一件事,名字该同形 —— `mcp_manager_switch` 早就是这个名字,`_set_enabled` 只剩
|
|
475
508
|
// 记忆 / 技能 / 人设三族在叫。**参数保留 `enabled` 布尔**:这里没有 `restart` 那第三个
|
|
@@ -502,7 +535,7 @@ export function buildMemoryTools(deps) {
|
|
|
502
535
|
throw new Error('missing argument: id — the memory id like <scene>/<name>.');
|
|
503
536
|
// 笔记不是用户记忆:这条工具拨的是索引里的开关,笔记的删除/停用走另一族。
|
|
504
537
|
if (isNoteRef(memory)) {
|
|
505
|
-
throw new Error('that is an agent note, not a user memory: use ' + noteTool(exec && exec.agent, '
|
|
538
|
+
throw new Error('that is an agent note, not a user memory: use ' + noteTool(exec && exec.agent, 'memory_manager_note action=forget', 'the agent-note tool') + '. User memory ids look like <scene>/<name>.');
|
|
506
539
|
}
|
|
507
540
|
// `enabled` 必须是布尔:`rules-toggle` 缺了它直接拒(ops/memory.ts),但那是给用户看的
|
|
508
541
|
// 中文 op 错;这里先挡一句说清"这条工具要什么"。
|
|
@@ -559,7 +592,7 @@ export function buildMemoryTools(deps) {
|
|
|
559
592
|
},
|
|
560
593
|
}));
|
|
561
594
|
register(defineTool({
|
|
562
|
-
name: '
|
|
595
|
+
name: 'memory_manager_remember',
|
|
563
596
|
// 写入口只按**范围**分叉,不再按内容长短分叉:用户说「记录 a」时,唯一要判断的是
|
|
564
597
|
// 「记到哪儿」,而那是用户的问题,不是模型能猜的。旧版按"一句话 → 笔记 / 多段 → 记忆"
|
|
565
598
|
// 重定向,模型于是要在两条工具、三种后端之间选,参数串用是必然的。
|
|
@@ -591,13 +624,13 @@ export function buildMemoryTools(deps) {
|
|
|
591
624
|
// 当成一次更新写回去 —— 真实会话里 `action=forget` + `content` 就把一条待删
|
|
592
625
|
// 记忆的正文改成了「删」,回执却说更新成功。
|
|
593
626
|
if (actionArg !== '' && actionArg !== 'forget') {
|
|
594
|
-
throw new Error('unknown action: ' + actionArg + ' —
|
|
627
|
+
throw new Error('unknown action: ' + actionArg + ' — memory_manager_remember creates or updates; use action=forget with id to delete a user memory.');
|
|
595
628
|
}
|
|
596
629
|
if (actionArg === 'forget') {
|
|
597
630
|
if (rawId === '')
|
|
598
|
-
throw new Error('missing argument: id — the user memory to delete (<scene>/<name>). Agent notes use
|
|
631
|
+
throw new Error('missing argument: id — the user memory to delete (<scene>/<name>). Agent notes use memory_manager_note action=forget.');
|
|
599
632
|
if (isNoteRef(rawId))
|
|
600
|
-
throw new Error('that is an agent note: delete it with
|
|
633
|
+
throw new Error('that is an agent note: delete it with memory_manager_note action=forget.');
|
|
601
634
|
// 与 update 路径同一条兜底:裸 id 也可能是笔记 id(`note:` 前缀可省)。
|
|
602
635
|
// 两条路不一致时,模型按 update 的习惯传裸 id 来删,会得到"这不是用户记忆"的
|
|
603
636
|
// 错误,而它其实只是忘了加前缀。
|
|
@@ -610,7 +643,7 @@ export function buildMemoryTools(deps) {
|
|
|
610
643
|
note = null;
|
|
611
644
|
}
|
|
612
645
|
if (note && note.ok !== false) {
|
|
613
|
-
throw new Error('"' + rawId + '" is an agent note, not a user memory: delete it with
|
|
646
|
+
throw new Error('"' + rawId + '" is an agent note, not a user memory: delete it with memory_manager_note action=forget (note=' + rawId + ').');
|
|
614
647
|
}
|
|
615
648
|
}
|
|
616
649
|
if (!rawId.includes('/'))
|
|
@@ -628,7 +661,7 @@ export function buildMemoryTools(deps) {
|
|
|
628
661
|
if (!hit)
|
|
629
662
|
throw new Error('no memory with id "' + rawId + '".' + existingNote((all.rules || []).map((x) => String(x.id)), 'memory ids'));
|
|
630
663
|
if (isAutoRule(hit))
|
|
631
|
-
throw new Error('that is an agent note: delete it with
|
|
664
|
+
throw new Error('that is an agent note: delete it with memory_manager_note action=forget.');
|
|
632
665
|
const r = await opOf(deps.rulesOps, 'rules-remove')({ id: rawId });
|
|
633
666
|
if (!r || r.ok === false)
|
|
634
667
|
throw new Error(String((r && r.error) || 'failed to delete the memory'));
|
|
@@ -640,7 +673,7 @@ export function buildMemoryTools(deps) {
|
|
|
640
673
|
throw new Error('nextName is for user memories; a note uses title.');
|
|
641
674
|
const layer = String(a.layer || '');
|
|
642
675
|
if (layer !== 'global' && layer !== 'workspace') {
|
|
643
|
-
throw new Error('that note is not a global or workspace note, so
|
|
676
|
+
throw new Error('that note is not a global or workspace note, so memory_manager_remember cannot update it: ' + ref);
|
|
644
677
|
}
|
|
645
678
|
const id = String(a.id || stripNoteRef(ref));
|
|
646
679
|
const text = content !== '' ? content.trim() : String(a.body || '').trim();
|
|
@@ -654,7 +687,7 @@ export function buildMemoryTools(deps) {
|
|
|
654
687
|
// 拿它做更新会把原文留在旧条目里,回执却说"updated"。
|
|
655
688
|
const updateOp = evo['evolution-update'];
|
|
656
689
|
if (typeof updateOp !== 'function') {
|
|
657
|
-
throw new Error('this host cannot edit an agent note in place. Forget it with
|
|
690
|
+
throw new Error('this host cannot edit an agent note in place. Forget it with memory_manager_note action=forget and learn a new one, or use memory_manager_note action=learn with the same slot.');
|
|
658
691
|
}
|
|
659
692
|
// 并发编辑保护:先读一次拿当前正文指纹,写回时带上。缺了它,模型与用户同时改
|
|
660
693
|
// 同一条笔记时后保存的会静默覆盖先保存的,且没有任何 `stale` 提示 —— 界面编辑
|
|
@@ -724,7 +757,7 @@ export function buildMemoryTools(deps) {
|
|
|
724
757
|
throw new Error((all && all.error) || 'failed to read memories');
|
|
725
758
|
const hit = (all.rules || []).find((x) => String(x.id) === rawId);
|
|
726
759
|
if (!hit) {
|
|
727
|
-
// 与
|
|
760
|
+
// 与 memory_manager_get 同一条回退:裸 id 也可能是笔记 id(`note:` 前缀可省)。
|
|
728
761
|
if (evo) {
|
|
729
762
|
let note = null;
|
|
730
763
|
try {
|
|
@@ -896,19 +929,19 @@ export function buildMemoryTools(deps) {
|
|
|
896
929
|
}));
|
|
897
930
|
// ── 自主笔记(只在开关打开时出现在工具表里)────────────────────────────────
|
|
898
931
|
//
|
|
899
|
-
// 为什么不复用 `
|
|
932
|
+
// 为什么不复用 `memory_manager_remember`:那条的契约是「Only on the user's instruction」并且
|
|
900
933
|
// 受确认门禁。自主笔记需要零摩擦:给 `save` 加一个 `auto` 参数会让同一个工具同时代表
|
|
901
934
|
// 两种授权,门禁只能按参数分叉;模型传错一次就是"该问的没问"。授权边界写在工具名上。
|
|
902
935
|
//
|
|
903
936
|
// 与用户记忆分开的另一点是**对象**:笔记是一句话、按层(global / workspace)走;
|
|
904
|
-
// 用户记忆是多段、按场景走。读取统一走 `
|
|
937
|
+
// 用户记忆是多段、按场景走。读取统一走 `memory_manager_get`,这里只保留写入与删除。
|
|
905
938
|
// 弹卡策略:自动确认关 → 每次都问;开 → 不弹卡,由 agent 决定。生效判断在 gates 的 `autoActive`。
|
|
906
939
|
if (!deps.evolutionOps || !deps.autoLearnEnabled)
|
|
907
|
-
return;
|
|
940
|
+
return { refreshNoteSchema() { } };
|
|
908
941
|
const noteOps = deps.evolutionOps;
|
|
909
|
-
|
|
942
|
+
const noteToolDef = defineTool({
|
|
910
943
|
name: PROACTIVE_MEMORY_TOOL,
|
|
911
|
-
description: 'Agent notes (autonomous memory) — one-line notes YOU decided are worth keeping across conversations: a preference, a fact, a correction of your behaviour, or a repeatable procedure. Use this for your own judgement; when the user explicitly asks you to remember something, use
|
|
944
|
+
description: 'Agent notes (autonomous memory) — one-line notes YOU decided are worth keeping across conversations: a preference, a fact, a correction of your behaviour, or a repeatable procedure. Use this for your own judgement; when the user explicitly asks you to remember something, use memory_manager_remember instead (that is their asset, this is your cache).\n\nWrite it in one call and move on. If a call is refused, the reply names every problem at once — fix them in one retry, or drop the note and get back to the task. Do not reword the same idea repeatedly: a note that keeps failing is one the user did not need.\n\nRecord what will still hold in a different conversation, and nothing else:\n- A one-off ("this time", "for now", "next step") is not a note.\n- Something re-derivable from the code or config (dependency versions, file lists, config values) is not a note — read the file instead.\n- Say the thing itself, in words. Fragments, markup, and pure punctuation are refused.\n\nlearn: `title` (2-8 words) + `text` (<=1200 Chinese chars / 2400 letters; 1-2 clear sentences, or follow the style line in the learned-notes section); `kind` — preference / fact / correction / procedure (it sets the review interval: fact and procedure are re-checked after 30 days, preference and correction never expire, so a procedure filed as a correction stays forever); pass `slot` (a stable name) when you may update or forget it later; pass `quote` (their exact words) when you are recording something the user actually said — it is checked verbatim against this conversation, and if it does not match the note is still saved but with weaker evidence, so quote exactly when you can.\n\nEvery note shows the user a card unless they turned auto-confirm on. Check for an existing note on the same thing first (the memory read tool with kind=note lists them) — two notes saying the same thing in different words are both injected into every later conversation, and the duplicate check compares wording, not meaning. forget: `note` = id (note:...), slot, title, or the first line as it was injected. Inspect notes with the memory read tool.',
|
|
912
945
|
parameters: {
|
|
913
946
|
action: { type: 'string', enum: ['learn', 'forget'], required: true, description: 'learn or forget.' },
|
|
914
947
|
// ── learn ──
|
|
@@ -917,7 +950,6 @@ export function buildMemoryTools(deps) {
|
|
|
917
950
|
quote: { type: 'string', description: 'learn: the user\'s exact words, copied verbatim, when you are recording something they said. Checked against this conversation; a quote that does not match does not fail the call — the note is kept with weaker evidence. Omit it for your own inferences.' },
|
|
918
951
|
slot: { type: 'string', description: 'learn: optional stable slot name; learning again with the same slot merges when it says the same thing, and replaces the old note when it conflicts.' },
|
|
919
952
|
boundary: { type: 'string', description: 'learn: optional; when it may not hold.' },
|
|
920
|
-
layer: { type: 'string', enum: ['global', 'workspace'], description: 'learn: global (every project) or workspace (this project). Omit only when unsure; the card asks, or auto-confirm uses the default.' },
|
|
921
953
|
ttlDays: { type: 'number', description: 'learn: optional; re-check after N days.' },
|
|
922
954
|
// `kind` 决定保质期(事实 / 做法 30 天后提醒复核,偏好 / 纠正不过期)。不给时由
|
|
923
955
|
// `inferKind` 按措辞猜,而它只能看字面 —— 「必须 / 不要」这类约束词会把做法误判成
|
|
@@ -957,7 +989,7 @@ export function buildMemoryTools(deps) {
|
|
|
957
989
|
if (!r || r.ok === false) {
|
|
958
990
|
// 带 `note:` 前缀的一定是笔记:它只是不存在了,别再说"这像是用户记忆"。
|
|
959
991
|
if (isNoteRef(ref)) {
|
|
960
|
-
throw new Error('no such agent note: ' + ref + ' (it may have been forgotten or archived). List the current notes with
|
|
992
|
+
throw new Error('no such agent note: ' + ref + ' (it may have been forgotten or archived). List the current notes with memory_manager_get kind=note.');
|
|
961
993
|
}
|
|
962
994
|
// 用户记忆 id 也是 `<scene>/<name>` 形状;零命中时明确说这不是笔记,别让模型再猜。
|
|
963
995
|
if (raw.includes('/')) {
|
|
@@ -965,22 +997,37 @@ export function buildMemoryTools(deps) {
|
|
|
965
997
|
}
|
|
966
998
|
// 走到这里说明 id / slot / title / 注入行都没命中。`evolution-forget` 的内部错
|
|
967
999
|
// (`not a memory id`)对模型没有任何可执行信息 —— 它要的是"下一步做什么"。
|
|
968
|
-
throw new Error('no such agent note: "' + ref + '". Pass its id (note:<layer>/<slug>), its slot, its title, or the first line exactly as it was injected; list the current notes with
|
|
1000
|
+
throw new Error('no such agent note: "' + ref + '". Pass its id (note:<layer>/<slug>), its slot, its title, or the first line exactly as it was injected; list the current notes with memory_manager_get kind=note to find one.');
|
|
969
1001
|
}
|
|
970
1002
|
return 'OK: forgot ' + noteRefOf(String(r.id || raw)) + '. It will not be learned again for 30 days.';
|
|
971
1003
|
}
|
|
972
1004
|
if (action !== 'learn')
|
|
973
1005
|
throw new Error('unknown action: ' + action + ' (expected learn / forget)');
|
|
1006
|
+
const layers = noteLayersOf(agent);
|
|
1007
|
+
const onlyLayer = layers.global && !layers.workspace ? 'global'
|
|
1008
|
+
: layers.workspace && !layers.global ? 'workspace' : undefined;
|
|
1009
|
+
const askedLayer = args && typeof args.layer === 'string' ? args.layer : '';
|
|
1010
|
+
if (askedLayer !== '') {
|
|
1011
|
+
if (askedLayer !== 'global' && askedLayer !== 'workspace') {
|
|
1012
|
+
throw new Error('unknown layer: ' + askedLayer + ' (expected global / workspace)');
|
|
1013
|
+
}
|
|
1014
|
+
// 关掉的层在模型眼里不该存在。显式点名它时拒绝而不是悄悄落到另一层 ——
|
|
1015
|
+
// 静默改层会让模型以为自己记到了它说的那一层。
|
|
1016
|
+
if (!(askedLayer === 'global' ? layers.global : layers.workspace)) {
|
|
1017
|
+
throw new Error('the ' + askedLayer + ' autonomous-memory layer is off here, so nothing was done. The user can turn it on in Memory → Autonomous memory' +
|
|
1018
|
+
(onlyLayer !== undefined ? ', or omit layer to use the enabled ' + onlyLayer + ' layer.' : '.'));
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
974
1021
|
// save 的参数串进来时(`body` / `memory`),直接指回用户记忆,
|
|
975
1022
|
// 别让一次完整记忆被当成一句话笔记丢掉。
|
|
976
1023
|
if (args && (args.body !== undefined || args.memory !== undefined)) {
|
|
977
|
-
throw new Error('those are user-memory parameters, not note parameters: for a full memory call
|
|
1024
|
+
throw new Error('those are user-memory parameters, not note parameters: for a full memory call memory_manager_remember with content and scope=scene/global. For a note pass title and text (the same slot merges the same meaning and replaces a conflicting note).');
|
|
978
1025
|
}
|
|
979
1026
|
// ── learn(默认)──
|
|
980
1027
|
//
|
|
981
1028
|
// 先查用户记忆里是不是已经有同一条:用户自己写过的(或让模型写过的)记忆**永久生效、
|
|
982
1029
|
// 不衰减、不进回收站**,而笔记是会被 TTL 提醒、被合并、被归档的缓存。模型不知道这件事,
|
|
983
|
-
// 于是常见症状是——用户说「记住这个仓库用 pnpm」,模型先用
|
|
1030
|
+
// 于是常见症状是——用户说「记住这个仓库用 pnpm」,模型先用 memory_manager_remember 存了一条,
|
|
984
1031
|
// 之后每次看到又顺手记一条笔记,页面上同一条规则出现两遍,其中一遍还会自己过期。
|
|
985
1032
|
//
|
|
986
1033
|
// 命中就**不写**,并把已有的那条 id 告诉模型:它可以去更新那条,而不是另立一条。
|
|
@@ -994,7 +1041,7 @@ export function buildMemoryTools(deps) {
|
|
|
994
1041
|
// 已经在用户记忆里说过的事不再记一条笔记:见 `userMemoryCovering` 的说明。
|
|
995
1042
|
const covered = await userMemoryCovering(text);
|
|
996
1043
|
if (covered !== null) {
|
|
997
|
-
return 'Already covered by the user memory ' + covered + ', so nothing was recorded. That memory is permanent and always injected — update it with
|
|
1044
|
+
return 'Already covered by the user memory ' + covered + ', so nothing was recorded. That memory is permanent and always injected — update it with memory_manager_remember (id=' + covered + ', content=...) if the wording needs to change. Do not keep a second copy as a note.';
|
|
998
1045
|
}
|
|
999
1046
|
// 非法 TTL 不能静默落默认值:调用方会以为"30 天后重查"生效了。
|
|
1000
1047
|
if (args && args.ttlDays !== undefined) {
|
|
@@ -1008,6 +1055,9 @@ export function buildMemoryTools(deps) {
|
|
|
1008
1055
|
if (args && args[key] !== undefined && args[key] !== '')
|
|
1009
1056
|
payload[key] = args[key];
|
|
1010
1057
|
}
|
|
1058
|
+
// 只剩一层时替模型定层:schema 里没有 `layer`,路由与卡片都需要一个确定值。
|
|
1059
|
+
if (onlyLayer !== undefined && (args.layer === undefined || args.layer === ''))
|
|
1060
|
+
payload.layer = onlyLayer;
|
|
1011
1061
|
// `slot` 是模型面的名字;op 的字段仍是 `key`(同 slot 合并)。`key` 作为旧名兼容一次。
|
|
1012
1062
|
const slot = String((args && (args.slot !== undefined ? args.slot : args.key)) || '');
|
|
1013
1063
|
if (slot !== '')
|
|
@@ -1032,7 +1082,7 @@ export function buildMemoryTools(deps) {
|
|
|
1032
1082
|
throw gateError(r);
|
|
1033
1083
|
return learnReceipt(r, 'none', payload);
|
|
1034
1084
|
}
|
|
1035
|
-
//
|
|
1085
|
+
// 先只读预演:拿到「弹卡后会发生什么」(层、是否合并 / 取代、会不会直接生效)。
|
|
1036
1086
|
const preview = await previewOp(payload);
|
|
1037
1087
|
if (!preview || preview.ok === false)
|
|
1038
1088
|
throw gateError(preview);
|
|
@@ -1085,7 +1135,7 @@ export function buildMemoryTools(deps) {
|
|
|
1085
1135
|
if (choice.choice === 'revise') {
|
|
1086
1136
|
return 'Not saved yet. The user wants this note worded differently:\n' +
|
|
1087
1137
|
String(choice.custom ?? '') + '\n\n' +
|
|
1088
|
-
'Rewrite the note to match their wording, then call
|
|
1138
|
+
'Rewrite the note to match their wording, then call memory_manager_note action=learn again with the revised text. The card will ask them to confirm the new version.';
|
|
1089
1139
|
}
|
|
1090
1140
|
if (choice.choice === 'skip') {
|
|
1091
1141
|
return 'Not saved: the user chose not to add it. Do not save it again unless they ask.';
|
|
@@ -1099,7 +1149,10 @@ export function buildMemoryTools(deps) {
|
|
|
1099
1149
|
throw new Error(String((r && r.error) || 'failed to record it'));
|
|
1100
1150
|
return learnReceipt(r, 'approved', payload);
|
|
1101
1151
|
},
|
|
1102
|
-
})
|
|
1152
|
+
});
|
|
1153
|
+
applyNoteLayerSchema(noteToolDef, noteLayersOf());
|
|
1154
|
+
register(noteToolDef);
|
|
1155
|
+
return { refreshNoteSchema() { applyNoteLayerSchema(noteToolDef, noteLayersOf()); } };
|
|
1103
1156
|
}
|
|
1104
1157
|
/**
|
|
1105
1158
|
* 门禁拒绝 → 一句给模型看的话。
|
package/lib/tools/prompt.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 模型可查、可切;**不能造** —— 预设正文是用户自己写的一份长文(`AGENTS.md`),
|
|
5
5
|
// 模型没有创建入口,要新建只能由用户在面板里写。
|
|
6
6
|
//
|
|
7
|
-
// 删除在 `tools/remove.ts` 的 `
|
|
7
|
+
// 删除在 `tools/remove.ts` 的 `plugin_manager_trash`(加)。此前这里写的是
|
|
8
8
|
// 「不能造 / **不能删** —— 避免模型乱删用户预设」,那条理由针对的是**不可恢复**的删除:
|
|
9
9
|
// 预设正文是用户手写的、删了就得重写。回收站把它的前提消掉了 —— 那条删除工具
|
|
10
10
|
// 「进回收站、可恢复、需用户指令、过场景冻结守卫」,永久删除仍只留在面板。
|
package/lib/tools/remove.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 删除 / 回收站族的 model 工具:**一条** `
|
|
1
|
+
// 删除 / 回收站族的 model 工具:**一条** `plugin_manager_trash`(五个域共用)。
|
|
2
2
|
//
|
|
3
3
|
// 为什么要有这一族:此前模型**只能停用、不能删除** —— "把这条过时的记忆删掉"这类要求手里
|
|
4
4
|
// 没有出口,模型会去调 `*_switch(enabled:false)` 然后回一句"已停用",用户以为删了。面板上
|
|
@@ -150,7 +150,7 @@ function sceneExitNote(deps, agent, domain) {
|
|
|
150
150
|
return '';
|
|
151
151
|
return ' ' + toolOrNeutral(deps, agent, 'scene_manager_switch', 'You are still in it — leave it with scene_manager_switch (action=exit).', 'You are still in it — leaving it is a separate action, and the scene tools are off here.');
|
|
152
152
|
}
|
|
153
|
-
/** 注册删除类工具:五个域共用一条 `
|
|
153
|
+
/** 注册删除类工具:五个域共用一条 `plugin_manager_trash`(按 `domain` 分派)。 */
|
|
154
154
|
export function buildRemoveTools(deps) {
|
|
155
155
|
const { defineTool, register } = deps;
|
|
156
156
|
const mem = deps.memoryOps;
|
|
@@ -186,7 +186,7 @@ export function buildRemoveTools(deps) {
|
|
|
186
186
|
return (r.entries || []).map((e) => ({ id: String(e.trashId), name: String(e.name), deletedAt: e.deletedAt }));
|
|
187
187
|
},
|
|
188
188
|
idHelp: {
|
|
189
|
-
tool: '
|
|
189
|
+
tool: 'memory_manager_get',
|
|
190
190
|
neutral: ' — the ids are the lines in the "Current memories" reminder.',
|
|
191
191
|
label: 'memory ids',
|
|
192
192
|
list: async () => {
|
|
@@ -304,7 +304,7 @@ export function buildRemoveTools(deps) {
|
|
|
304
304
|
scene: sceneCfg,
|
|
305
305
|
};
|
|
306
306
|
register(defineTool({
|
|
307
|
-
name: '
|
|
307
|
+
name: 'plugin_manager_trash',
|
|
308
308
|
description: removeDescription(),
|
|
309
309
|
parameters: {
|
|
310
310
|
action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
|
package/lib/tools/scene.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (`tools/table.ts` 刻意不定义第二份排序),这一族按其余四族同形的排法排:先查、再拨开关、
|
|
4
4
|
// 最后写定义 —— 场景族补上这两条时是照"先建后切"的语义顺序注册的,成了五族里唯一的例外。
|
|
5
5
|
//
|
|
6
|
-
// 为什么单独一族而不是塞进 `
|
|
6
|
+
// 为什么单独一族而不是塞进 `memory_manager_remember`:场景与记忆是两个对象 —— 场景是**容器**
|
|
7
7
|
// (进入时按档案切换 mcp / 技能 / 人设,其余全部关掉),记忆是**内容**(按场景组织、吃注入
|
|
8
8
|
// 预算)。合成一条工具会让 `description` 变成双义参数、门禁按参数分叉,而这两件事的失败
|
|
9
9
|
// 形状都是静默的。
|
package/lib/tools/table.js
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
// 根本用不上。关掉某几个工具,它们整份不进请求(不是"把描述写短点"那种省);面板
|
|
5
5
|
// (118 个 op)与注入通道完全不受影响。
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
7
|
+
// 出厂**默认就关着十八条**:其中十七条在可勾选的 22 条里(关掉后每轮实发 5 条),
|
|
8
|
+
// 第十八条是自主笔记,它不在行集里、跟随记忆页的总开关(开则实发 6 条)—— 名单、判据
|
|
9
|
+
// 与代价见下面 `DEFAULT_HIDDEN_TOOLS`;用户自己额外关的与出厂关的在合计那句里分开报。
|
|
9
10
|
//
|
|
10
11
|
// 实测数字(口径:宿主 `recordToolSize` 的 `ceil(JSON.stringify(header.tools).length / 4) + 4`,
|
|
11
12
|
// 即**字符数 / 4**;`header.tools` 里只有 name / description / parameters —— 官方的
|
|
12
13
|
// `projectToolSchema` 不投影 output / execute,那几个不进请求。界面「模型工具表」那行
|
|
13
14
|
// 合计与逐条 ≈tok 就是这份):
|
|
14
|
-
// · 上一次实测(`
|
|
15
|
+
// · 上一次实测(`memory_manager_get` 合并之前)是 18 条隐藏 ≈**4,524 tok**、默认可见 6 条
|
|
15
16
|
// ≈**1,536 tok**、全开 ≈**6,055 tok**。合并后少了一条工具、描述也换了,**没有重测** ——
|
|
16
17
|
// 引用时按"旧口径"说,别当成当前工具表的实测值。
|
|
17
18
|
// · 同一批 A/B 实测净少 **4,119 / 4,197 tok**(把当时那批隐藏工具逐个打开,前后各跑两轮),
|
|
@@ -50,7 +51,7 @@ import { CONTROL_TOOL_NAME } from './deps.js';
|
|
|
50
51
|
* learn / forget 两个行为靠 `action` 分叉;名字集中在这里,是因为
|
|
51
52
|
* 「出厂隐藏名单」「跟随总开关开合」「旧名迁移」「工具注册」四处都得认同一串字符。
|
|
52
53
|
*/
|
|
53
|
-
export const PROACTIVE_MEMORY_TOOL = '
|
|
54
|
+
export const PROACTIVE_MEMORY_TOOL = 'memory_manager_note';
|
|
54
55
|
/**
|
|
55
56
|
* 自主笔记那条工具**只跟总开关走**,工具表盘上存过的关停名单对它无效。
|
|
56
57
|
*
|
|
@@ -80,25 +81,26 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
80
81
|
return hidden.filter((name) => name !== PROACTIVE_MEMORY_TOOL);
|
|
81
82
|
}
|
|
82
83
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
84
|
+
* 出厂默认关掉的**十八条**:其中十七条在可勾选的 22 条里(关掉后**每轮实发 5 条**),
|
|
85
|
+
* 第十八条是自主笔记 —— 它不在行集里、跟随记忆页的总开关(开则实发 6 条)。下面五组列
|
|
86
|
+
* 16 条,人设清单(`subagent_manager_list`)单列在「人设域」那一段,自主笔记单列在末尾 ——
|
|
85
87
|
* 三条计数不要合并,否则又会对不上。
|
|
86
88
|
*
|
|
87
89
|
* 判据只有一条:**这些信息或动作常态下由注入段与面板承担,
|
|
88
90
|
* 平时也用不到模型自己伸手**。分五组:
|
|
89
91
|
* · **写侧五条** —— 三个 `*_save`(MCP / 技能 / 人设:配置本体在面板上改)+
|
|
90
92
|
* `prompt_manager_apply`(当前生效的那份本来就在 `Current prompt` 注入段里)+
|
|
91
|
-
* `
|
|
93
|
+
* `plugin_manager_trash`(删除进回收站可恢复,但常态下由面板承担)。
|
|
92
94
|
* · **读侧四条** —— `mcp_manager_list` / `skill_manager_list` / `prompt_manager_list` /
|
|
93
95
|
* `scene_manager_list`。会话开头注入的那几段目录已经写了当前有什么,模型不必每轮
|
|
94
96
|
* 再带一份查询工具。
|
|
95
|
-
* **`
|
|
96
|
-
* 藏掉它等于把被截断的条目、以及 `
|
|
97
|
+
* **`memory_manager_get` 刻意不在这份名单**:合并后的读取入口同时承担清单、搜索与正文,
|
|
98
|
+
* 藏掉它等于把被截断的条目、以及 `memory_manager_remember` 需要的 id 变成不可发现。
|
|
97
99
|
* · **切场一条** —— `scene_manager_switch`:进入 / 退出场景。
|
|
98
100
|
* · **开关四条** —— `skill` / `memory` / `subagent` 三个 `_switch`(用户:「平时使用也很少」)
|
|
99
101
|
* + `mcp_manager_switch`。启停在面板上都有同款,注入段也写着当前开着哪些。
|
|
100
102
|
* MCP 那条**也关**(用户指定的五条清单里没有它):代价是这个域出厂没有一条可见工具 ——
|
|
101
|
-
* 模型要停 / 启服务器,得先用 `
|
|
103
|
+
* 模型要停 / 启服务器,得先用 `tool_manager_switch` 把它打开,多一次往返。默认清单以
|
|
102
104
|
* 用户点名的五条为准,不为了"每域留一条腿"自行加回。
|
|
103
105
|
* · **建档两条** —— `scene_manager_save`(场景记录)+ `scene_manager_archive`(档案段:
|
|
104
106
|
* 进入时开哪些 MCP / 技能 / 人设)。配置本体在面板上改;档案的勾选集机器自己算得出来
|
|
@@ -114,7 +116,7 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
114
116
|
* 技能 / 人设"是常问的,但它**低频于"读现状 + 拨开关 + 建改定义"**那批,而且面板每个域都有
|
|
115
117
|
* 删除入口 —— 默认关、要用时在「兼容」页勾上(与其余默认关停的工具同一条纪律,不额外付 token)。
|
|
116
118
|
*
|
|
117
|
-
* 关掉的这些**模型自己也能打开**:`
|
|
119
|
+
* 关掉的这些**模型自己也能打开**:`tool_manager_switch`(每轮常驻的那一条)能按对话
|
|
118
120
|
* 打开任意一条被关掉的工具,列清单时给出名字、一句话用途与 ≈token。这条工具不在
|
|
119
121
|
* 这份名单里 —— 它是唯一的回头路,自己关掉自己的话就再也开不回来了。
|
|
120
122
|
*
|
|
@@ -124,7 +126,7 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
124
126
|
* 上下文的记忆正文"在会话里查不到;`*_switch` 关掉后模型也不能再替你拨启停。三处配套改动为
|
|
125
127
|
* 的就是不把模型往墙上推:目录被条数上限截断时那句「用 `X_manager_list` 查」自动退回「另有
|
|
126
128
|
* N more not listed.)」(`listToolVisible`);`mcp_manager_list` / `skill_manager_read` 里"没找到 →
|
|
127
|
-
* 去调 list"那两句先问 `deps.toolVisible`;`
|
|
129
|
+
* 去调 list"那两句先问 `deps.toolVisible`;`memory_manager_get` 的描述不再点名已关的工具。
|
|
128
130
|
*
|
|
129
131
|
* 只在**用户从没记过选择**时生效(见 index.ts 的 `toolTableSettingsFrom`:侧车文件读不出来
|
|
130
132
|
* 才用这份)。已经存过盘的一律照原样,包括显式的 `hidden: []` —— 那是"我全都要",
|
|
@@ -135,7 +137,7 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
|
|
|
135
137
|
'scene_manager_switch',
|
|
136
138
|
'scene_manager_save',
|
|
137
139
|
'scene_manager_archive',
|
|
138
|
-
'
|
|
140
|
+
'memory_manager_switch',
|
|
139
141
|
'mcp_manager_list',
|
|
140
142
|
'mcp_manager_save',
|
|
141
143
|
'mcp_manager_switch',
|
|
@@ -147,7 +149,7 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
|
|
|
147
149
|
'subagent_manager_save',
|
|
148
150
|
'prompt_manager_list',
|
|
149
151
|
'prompt_manager_apply',
|
|
150
|
-
'
|
|
152
|
+
'plugin_manager_trash',
|
|
151
153
|
// 自主笔记:默认藏着(它是权限,不是便利),此后**跟随总开关开合** —— 开着强制可见、
|
|
152
154
|
// 关着强制隐藏,两边都不能手动改(见 index.ts 的 proactiveMemoryGlobalOn 那条过滤链)。
|
|
153
155
|
// 放在这份名单而不是另建一张表:
|
|
@@ -155,7 +157,10 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
|
|
|
155
157
|
// 实际被藏着"的错位。
|
|
156
158
|
PROACTIVE_MEMORY_TOOL,
|
|
157
159
|
]);
|
|
158
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* 出厂默认那份设置:名单十八条(含跟随总开关的自主笔记;落盘 / 读侧都会把它摘掉,
|
|
162
|
+
* 所以用户看到的可恢复项是十七条),方案清单是空的。
|
|
163
|
+
*/
|
|
159
164
|
export const DEFAULT_TOOL_TABLE_SETTINGS = { hidden: [...DEFAULT_HIDDEN_TOOLS], presets: [] };
|
|
160
165
|
/** 方案名上限(与 MCP 备注那类输入同风格:短到能在一行里读,长了也没人看)。 */
|
|
161
166
|
export const PRESET_NAME_MAX_LENGTH = 40;
|
|
@@ -377,6 +382,10 @@ export function applyToolTableToggles(current, toggles) {
|
|
|
377
382
|
/**
|
|
378
383
|
* 纯函数:把注册时量到的体积按域分组,标出哪些被关掉,给出四档合计。
|
|
379
384
|
*
|
|
385
|
+
* `rows` 是**可勾选的那部分表**(22 条):只跟总开关走的那条不在里面 —— 它在界面上没有
|
|
386
|
+
* 行、不进名单、不进方案。它由 `derived` 参数单独交代(名字、开没开、体积),报告用
|
|
387
|
+
* `sentCount` 把它加回"实际发送",两个口径因此不会在接口层散掉。
|
|
388
|
+
*
|
|
380
389
|
* 顺序:域按 `INJECT_DOMAIN_KEYS`(界面与注入通道同一顺序),域内按**注册顺序**
|
|
381
390
|
* —— 改顺序等于改显示顺序,不额外定义"重要性",免得出现第二份排序真相。
|
|
382
391
|
*
|
|
@@ -385,7 +394,7 @@ export function applyToolTableToggles(current, toggles) {
|
|
|
385
394
|
* 全局的 —— 所以由调用方给一份口径明确的名单(`tool-table-switch.ts` 传的是"标准预设下会
|
|
386
395
|
* 让位"的保守估计),本函数只负责把它从**可见**里扣掉、单独计一档。
|
|
387
396
|
*/
|
|
388
|
-
export function buildToolTableReport(rows, hidden, carrierHidden = []) {
|
|
397
|
+
export function buildToolTableReport(rows, hidden, carrierHidden = [], derived) {
|
|
389
398
|
const off = new Set(hidden.map((name) => String(name)));
|
|
390
399
|
const carried = new Set(carrierHidden.map((name) => String(name)));
|
|
391
400
|
// 「控制」组排在最前:它是**管着这张表的那一条工具**,放在末尾的「其它」组里
|
|
@@ -406,7 +415,12 @@ export function buildToolTableReport(rows, hidden, carrierHidden = []) {
|
|
|
406
415
|
list = [];
|
|
407
416
|
buckets.set(key, list);
|
|
408
417
|
}
|
|
409
|
-
list.push({
|
|
418
|
+
list.push({
|
|
419
|
+
name,
|
|
420
|
+
tok: estimateTok(row.bytes),
|
|
421
|
+
hidden: off.has(name),
|
|
422
|
+
defaultHidden: DEFAULT_HIDDEN_SET.has(name),
|
|
423
|
+
});
|
|
410
424
|
}
|
|
411
425
|
const groups = [];
|
|
412
426
|
let visibleTok = 0;
|
|
@@ -445,9 +459,18 @@ export function buildToolTableReport(rows, hidden, carrierHidden = []) {
|
|
|
445
459
|
hiddenTok += offTok;
|
|
446
460
|
groups.push({ key, tools, tok, hiddenTok: offTok });
|
|
447
461
|
}
|
|
462
|
+
const derivedTool = derived === undefined
|
|
463
|
+
? undefined
|
|
464
|
+
: {
|
|
465
|
+
name: String(derived.name),
|
|
466
|
+
active: derived.active === true,
|
|
467
|
+
tok: estimateTok(derived.bytes),
|
|
468
|
+
};
|
|
448
469
|
return {
|
|
449
470
|
groups, visibleTok, hiddenTok, totalTok: visibleTok + hiddenTok + carrierHiddenTok,
|
|
450
471
|
visibleCount, hiddenCount: totalCount - visibleCount - carrierHiddenCount, totalCount,
|
|
451
472
|
defaultHiddenCount, defaultHiddenTok, carrierHiddenCount, carrierHiddenTok,
|
|
473
|
+
...(derivedTool === undefined ? {} : { derived: derivedTool }),
|
|
474
|
+
sentCount: visibleCount + (derivedTool !== undefined && derivedTool.active ? 1 : 0),
|
|
452
475
|
};
|
|
453
476
|
}
|
package/lib/trash-id.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 头部的层注释)。放到这一叶模块里,两边都只向下引,不产生环。
|
|
6
6
|
//
|
|
7
7
|
// 形状:时间戳 base36 + uuid 前 8 位。统一它不是为了审美 —— 五个域的删除都走同一条
|
|
8
|
-
// `
|
|
8
|
+
// `plugin_manager_trash`,都按 `action=list` 给出的 id 做 restore,模型跨域操作时
|
|
9
9
|
// 认得这一种形状就够。此前技能域另写了一套
|
|
10
10
|
// `${Date.now()}-${randomUUID()}`(十进制时间戳 + 完整 uuid),拿到的是另一种长相。
|
|
11
11
|
//
|