dsh-plugin-tool-management 0.22.7 → 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 +23 -0
- package/README.md +7 -7
- package/README_EN.md +6 -6
- package/docs/TROUBLESHOOTING.md +1 -1
- package/lib/client.js +80 -142
- package/lib/compat/capability-specs.js +1 -1
- package/lib/confirm-gate.js +13 -13
- package/lib/context-inject-contract.js +6 -9
- package/lib/context-inject-frame.js +7 -7
- package/lib/evolution/cold.js +2 -2
- package/lib/evolution/config.js +1 -1
- package/lib/evolution/notes.js +47 -6
- package/lib/evolution/review.js +1 -1
- package/lib/evolution/write.js +102 -35
- package/lib/index.js +38 -33
- package/lib/legacy-tool-names.js +39 -28
- package/lib/mcp/state-section.js +2 -2
- package/lib/memories/constants.js +3 -3
- package/lib/memories/projection.js +1 -1
- package/lib/memories/render-auto.js +7 -7
- package/lib/memories/snapshot.js +1 -1
- package/lib/op-registry.js +3 -0
- package/lib/ops/evolution.js +27 -16
- package/lib/ops/memory.js +1 -1
- package/lib/ops/trash.js +1 -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/tool-table-switch.js +1 -1
- package/lib/tools/control.js +3 -3
- package/lib/tools/deps.js +4 -4
- package/lib/tools/memory.js +29 -29
- 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 +10 -10
- package/lib/trash-id.js +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
// 从 subagents/service.ts 整段搬来,一行未改。这一层不认识宿主也不写文件:进来一段文本,
|
|
5
5
|
// 出去一个 PersonaDoc;创建与更新走的解析口径与扫描时同一份,两处不能各写一套。
|
|
6
|
+
import { translateLegacyToolName } from '../legacy-tool-names.js';
|
|
6
7
|
import { decodeYamlScalar } from '../skills/frontmatter.js';
|
|
7
8
|
/**
|
|
8
9
|
* 按逗号/顿号切名单,引号内的逗号不切 —— 与写侧 `listEntry`(persona-write.ts)配对:
|
|
@@ -48,6 +49,24 @@ export function listOf(value) {
|
|
|
48
49
|
const list = splitNameList(text).map((s) => decodeYamlScalar(s).trim()).filter(Boolean);
|
|
49
50
|
return list.length ? list : undefined;
|
|
50
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 工具名名单按旧名表翻译并按新名去重。
|
|
54
|
+
*
|
|
55
|
+
* 人设文件存的是工具名,但不走 `tool-table.json` 那条迁移路(三处旧名翻译都不覆盖它)。
|
|
56
|
+
* 不翻译的话,旧的 `toolsDeny` 条目对新名字**静默失配** —— deny 失效是 fail-open,
|
|
57
|
+
* 比 allow 少一条更危险。幂等:全是现行名时原样返回。
|
|
58
|
+
*/
|
|
59
|
+
function translateToolNameList(names) {
|
|
60
|
+
if (names === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const name of names) {
|
|
64
|
+
const next = translateLegacyToolName(name);
|
|
65
|
+
if (out.indexOf(next) < 0)
|
|
66
|
+
out.push(next);
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
51
70
|
/**
|
|
52
71
|
* frontmatter 里真值标志的写法(`continuable: true` / `yes` / `on` / `1`)。
|
|
53
72
|
*
|
|
@@ -87,7 +106,7 @@ export function parsePresetToolRules(frontmatter) {
|
|
|
87
106
|
const m = /^\s*([A-Za-z0-9._-]+)\s*:\s*(allow|deny)\s*:\s*(.*)$/i.exec(line);
|
|
88
107
|
if (!m)
|
|
89
108
|
continue;
|
|
90
|
-
const names = listOf(m[3]);
|
|
109
|
+
const names = translateToolNameList(listOf(m[3]));
|
|
91
110
|
// 空名单 = 不限制 = 不落盘,读到时也直接忽略,免得把"没开"读成"开了但空"。
|
|
92
111
|
if (!names)
|
|
93
112
|
continue;
|
|
@@ -154,9 +173,9 @@ export function parsePersona(raw, fallbackName) {
|
|
|
154
173
|
toolsByPreset = parsePresetToolRules(m[1]);
|
|
155
174
|
body = raw.slice(m[0].length);
|
|
156
175
|
}
|
|
157
|
-
const tools = listOf(data.tools);
|
|
176
|
+
const tools = translateToolNameList(listOf(data.tools));
|
|
158
177
|
// 兼容两种写法:`toolsdeny: a, b`(线上格式)与 `toolsDeny: a, b`(键名统一小写后同形)。
|
|
159
|
-
const toolsDeny = listOf(data.toolsdeny);
|
|
178
|
+
const toolsDeny = translateToolNameList(listOf(data.toolsdeny));
|
|
160
179
|
const firstLine = body.split(/\r?\n/).find((l) => l.trim())?.trim() ?? '';
|
|
161
180
|
const catalogDepth = parseCatalogDepth(data);
|
|
162
181
|
return {
|
package/lib/tool-table-switch.js
CHANGED
|
@@ -332,7 +332,7 @@ export function createToolTableSwitch(deps) {
|
|
|
332
332
|
.filter((t) => t && typeof t.name === 'string' && t.name !== '')
|
|
333
333
|
.map((t) => ({ name: String(t.name), hidden: t.hidden === true }))
|
|
334
334
|
// 只收**已注册**的名字:写进来的陌生名字在下一次 restrict 时会让官方抛错。
|
|
335
|
-
// 锁定的两条方向都不收:模型侧 `
|
|
335
|
+
// 锁定的两条方向都不收:模型侧 `tool_manager_switch` 也改不动自主记忆工具。
|
|
336
336
|
.filter((t) => toolTableSizes.has(t.name) && !forced.has(t.name) && !forcedOff.has(t.name));
|
|
337
337
|
if (toggles.length === 0) {
|
|
338
338
|
const names = args.toggle.map((t) => String(t && t.name));
|
package/lib/tools/control.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 控制面工具 `
|
|
1
|
+
// 控制面工具 `tool_manager_switch`:模型自己看得到哪些工具、能不能自己打开。
|
|
2
2
|
//
|
|
3
3
|
// 为什么要有它:插件出厂只发 6 条工具(`src/tools/table.ts` 的 `DEFAULT_HIDDEN_TOOLS`
|
|
4
4
|
// 关掉 18 条)。场景那一族**四条全关**,而场景目录注入只列**当前已启用的**场景 ——
|
|
@@ -24,9 +24,9 @@ function toolLine(name, summary, bytes) {
|
|
|
24
24
|
return '- ' + name + purpose + ' (≈' + estimateTok(bytes) + ' tok/turn)';
|
|
25
25
|
}
|
|
26
26
|
/** 这条工具自己的名字(自己不可被关的那条判据用)。 */
|
|
27
|
-
const CONTROL_TOOL_NAME = '
|
|
27
|
+
const CONTROL_TOOL_NAME = 'tool_manager_switch';
|
|
28
28
|
/**
|
|
29
|
-
* 注册控制面工具(`
|
|
29
|
+
* 注册控制面工具(`tool_manager_switch`)。
|
|
30
30
|
*
|
|
31
31
|
* 只做三件事:列清单、开工具、关工具。**没有第四件** ——
|
|
32
32
|
* 「打开之后立刻用那条工具」的动作没有做:它要么绕过宿主的工具执行管线
|
package/lib/tools/deps.js
CHANGED
|
@@ -79,7 +79,7 @@ export function toolOrNeutral(deps, agent, tool, named, neutral) {
|
|
|
79
79
|
* 定义在这一层而不是 `tools/control.ts`:回执与报错常要问「模型能不能自己打开某条工具」,
|
|
80
80
|
* 那问的就是这条的名字 —— 两处各写一个字面量,改名时就分叉了。
|
|
81
81
|
*/
|
|
82
|
-
export const CONTROL_TOOL_NAME = '
|
|
82
|
+
export const CONTROL_TOOL_NAME = 'tool_manager_switch';
|
|
83
83
|
/**
|
|
84
84
|
* 判定模型自己能不能弄到 `fixer`(那条能修好问题的工具)。
|
|
85
85
|
*
|
|
@@ -112,7 +112,7 @@ export function toolAccessSentence(deps, fixer, agent, fallback) {
|
|
|
112
112
|
if (route === 'direct')
|
|
113
113
|
return 'use ' + fixer;
|
|
114
114
|
if (route === 'via-control') {
|
|
115
|
-
return 'enable ' + fixer + ' with
|
|
115
|
+
return 'enable ' + fixer + ' with tool_manager_switch (action="enable", tools:["' + fixer + '"]), then use it';
|
|
116
116
|
}
|
|
117
117
|
return fallback;
|
|
118
118
|
}
|
|
@@ -125,7 +125,7 @@ export const LIST_LIMIT_MAX = 100;
|
|
|
125
125
|
*
|
|
126
126
|
* 为什么要有上限:返回值进上下文,而**工具表管不着这一笔**(工具表只管 schema)。
|
|
127
127
|
* 模型爱「先全列出来看看」,一次就是几千 token —— 而它省下的那点(不用再调一次)
|
|
128
|
-
* 远不抵。`
|
|
128
|
+
* 远不抵。`memory_manager_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_manager_remember`(它的 `scope` 指场景 / 工作区,不是会话层)、
|
|
274
274
|
* `*_manager_switch`(它们本来就按会话写,`scope` 是真的)。
|
|
275
275
|
* `prompt_manager_apply` 也从清单里去掉了:它的参数表里没有
|
|
276
276
|
* `scope`,守卫读不到东西 —— 模型按 schema 不可能传,这条守卫等于永不触发,留着只会
|
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';
|
|
@@ -81,7 +81,7 @@ export function buildMemoryTools(deps) {
|
|
|
81
81
|
/**
|
|
82
82
|
* 这条规则是不是自主笔记而不是用户记忆。
|
|
83
83
|
*
|
|
84
|
-
* `
|
|
84
|
+
* `memory_manager_get` 把两族并成一份输出,用户记忆那一半必须把笔记摘掉 —— 否则同一句话
|
|
85
85
|
* 会在「user memories」与「agent notes」各出现一次。`origin` 是权威字段;旧数据
|
|
86
86
|
* 没有它时按目录判(`_ws` / `_session` 只由笔记后端写入,见 memories/catalog.ts)。
|
|
87
87
|
*/
|
|
@@ -256,7 +256,7 @@ export function buildMemoryTools(deps) {
|
|
|
256
256
|
(e.key && String(e.key) !== String(e.id).slice(String(e.id).lastIndexOf('/') + 1) ? ' · slot ' + String(e.key) : '') +
|
|
257
257
|
(e.title ? ' · ' + String(e.title) : '') +
|
|
258
258
|
// 类型决定保质期,也是「这条是做法还是偏好」的唯一机器可读标记:
|
|
259
|
-
// 模型要靠它决定该不该照着做、值不值得 `
|
|
259
|
+
// 模型要靠它决定该不该照着做、值不值得 `memory_manager_get` 读全文。
|
|
260
260
|
// `evolution-list` 一直在返回 `kind`,这里此前没读。
|
|
261
261
|
(e.kind ? ' · ' + String(e.kind) : '') +
|
|
262
262
|
' · ' + String(e.tier || 'inferred') +
|
|
@@ -405,7 +405,7 @@ export function buildMemoryTools(deps) {
|
|
|
405
405
|
throw new Error('no user memory with id "' + id + '"; ' + (e instanceof Error ? e.message : String(e)));
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
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.');
|
|
409
409
|
};
|
|
410
410
|
/**
|
|
411
411
|
* 从标题或正文首行派生文件名:保留 Unicode,去掉路径分隔符与控制字符,空白压成 `-`。
|
|
@@ -447,7 +447,7 @@ export function buildMemoryTools(deps) {
|
|
|
447
447
|
return [...names];
|
|
448
448
|
};
|
|
449
449
|
register(defineTool({
|
|
450
|
-
name: '
|
|
450
|
+
name: 'memory_manager_get',
|
|
451
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.',
|
|
452
452
|
parameters: {
|
|
453
453
|
id: { type: 'string', description: 'Read one entry: a user memory id (<scene>/<name>) or an agent note id (note:...).' },
|
|
@@ -502,7 +502,7 @@ export function buildMemoryTools(deps) {
|
|
|
502
502
|
},
|
|
503
503
|
}));
|
|
504
504
|
register(defineTool({
|
|
505
|
-
name: '
|
|
505
|
+
name: 'memory_manager_switch',
|
|
506
506
|
// 为什么叫 `_switch` 而不是 `_set_enabled`:六个域里"拨一个开关"
|
|
507
507
|
// 是同一件事,名字该同形 —— `mcp_manager_switch` 早就是这个名字,`_set_enabled` 只剩
|
|
508
508
|
// 记忆 / 技能 / 人设三族在叫。**参数保留 `enabled` 布尔**:这里没有 `restart` 那第三个
|
|
@@ -535,7 +535,7 @@ export function buildMemoryTools(deps) {
|
|
|
535
535
|
throw new Error('missing argument: id — the memory id like <scene>/<name>.');
|
|
536
536
|
// 笔记不是用户记忆:这条工具拨的是索引里的开关,笔记的删除/停用走另一族。
|
|
537
537
|
if (isNoteRef(memory)) {
|
|
538
|
-
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>.');
|
|
539
539
|
}
|
|
540
540
|
// `enabled` 必须是布尔:`rules-toggle` 缺了它直接拒(ops/memory.ts),但那是给用户看的
|
|
541
541
|
// 中文 op 错;这里先挡一句说清"这条工具要什么"。
|
|
@@ -592,7 +592,7 @@ export function buildMemoryTools(deps) {
|
|
|
592
592
|
},
|
|
593
593
|
}));
|
|
594
594
|
register(defineTool({
|
|
595
|
-
name: '
|
|
595
|
+
name: 'memory_manager_remember',
|
|
596
596
|
// 写入口只按**范围**分叉,不再按内容长短分叉:用户说「记录 a」时,唯一要判断的是
|
|
597
597
|
// 「记到哪儿」,而那是用户的问题,不是模型能猜的。旧版按"一句话 → 笔记 / 多段 → 记忆"
|
|
598
598
|
// 重定向,模型于是要在两条工具、三种后端之间选,参数串用是必然的。
|
|
@@ -624,13 +624,13 @@ export function buildMemoryTools(deps) {
|
|
|
624
624
|
// 当成一次更新写回去 —— 真实会话里 `action=forget` + `content` 就把一条待删
|
|
625
625
|
// 记忆的正文改成了「删」,回执却说更新成功。
|
|
626
626
|
if (actionArg !== '' && actionArg !== 'forget') {
|
|
627
|
-
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.');
|
|
628
628
|
}
|
|
629
629
|
if (actionArg === 'forget') {
|
|
630
630
|
if (rawId === '')
|
|
631
|
-
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.');
|
|
632
632
|
if (isNoteRef(rawId))
|
|
633
|
-
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.');
|
|
634
634
|
// 与 update 路径同一条兜底:裸 id 也可能是笔记 id(`note:` 前缀可省)。
|
|
635
635
|
// 两条路不一致时,模型按 update 的习惯传裸 id 来删,会得到"这不是用户记忆"的
|
|
636
636
|
// 错误,而它其实只是忘了加前缀。
|
|
@@ -643,7 +643,7 @@ export function buildMemoryTools(deps) {
|
|
|
643
643
|
note = null;
|
|
644
644
|
}
|
|
645
645
|
if (note && note.ok !== false) {
|
|
646
|
-
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 + ').');
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
if (!rawId.includes('/'))
|
|
@@ -661,7 +661,7 @@ export function buildMemoryTools(deps) {
|
|
|
661
661
|
if (!hit)
|
|
662
662
|
throw new Error('no memory with id "' + rawId + '".' + existingNote((all.rules || []).map((x) => String(x.id)), 'memory ids'));
|
|
663
663
|
if (isAutoRule(hit))
|
|
664
|
-
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.');
|
|
665
665
|
const r = await opOf(deps.rulesOps, 'rules-remove')({ id: rawId });
|
|
666
666
|
if (!r || r.ok === false)
|
|
667
667
|
throw new Error(String((r && r.error) || 'failed to delete the memory'));
|
|
@@ -673,7 +673,7 @@ export function buildMemoryTools(deps) {
|
|
|
673
673
|
throw new Error('nextName is for user memories; a note uses title.');
|
|
674
674
|
const layer = String(a.layer || '');
|
|
675
675
|
if (layer !== 'global' && layer !== 'workspace') {
|
|
676
|
-
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);
|
|
677
677
|
}
|
|
678
678
|
const id = String(a.id || stripNoteRef(ref));
|
|
679
679
|
const text = content !== '' ? content.trim() : String(a.body || '').trim();
|
|
@@ -687,7 +687,7 @@ export function buildMemoryTools(deps) {
|
|
|
687
687
|
// 拿它做更新会把原文留在旧条目里,回执却说"updated"。
|
|
688
688
|
const updateOp = evo['evolution-update'];
|
|
689
689
|
if (typeof updateOp !== 'function') {
|
|
690
|
-
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.');
|
|
691
691
|
}
|
|
692
692
|
// 并发编辑保护:先读一次拿当前正文指纹,写回时带上。缺了它,模型与用户同时改
|
|
693
693
|
// 同一条笔记时后保存的会静默覆盖先保存的,且没有任何 `stale` 提示 —— 界面编辑
|
|
@@ -757,7 +757,7 @@ export function buildMemoryTools(deps) {
|
|
|
757
757
|
throw new Error((all && all.error) || 'failed to read memories');
|
|
758
758
|
const hit = (all.rules || []).find((x) => String(x.id) === rawId);
|
|
759
759
|
if (!hit) {
|
|
760
|
-
// 与
|
|
760
|
+
// 与 memory_manager_get 同一条回退:裸 id 也可能是笔记 id(`note:` 前缀可省)。
|
|
761
761
|
if (evo) {
|
|
762
762
|
let note = null;
|
|
763
763
|
try {
|
|
@@ -929,19 +929,19 @@ export function buildMemoryTools(deps) {
|
|
|
929
929
|
}));
|
|
930
930
|
// ── 自主笔记(只在开关打开时出现在工具表里)────────────────────────────────
|
|
931
931
|
//
|
|
932
|
-
// 为什么不复用 `
|
|
932
|
+
// 为什么不复用 `memory_manager_remember`:那条的契约是「Only on the user's instruction」并且
|
|
933
933
|
// 受确认门禁。自主笔记需要零摩擦:给 `save` 加一个 `auto` 参数会让同一个工具同时代表
|
|
934
934
|
// 两种授权,门禁只能按参数分叉;模型传错一次就是"该问的没问"。授权边界写在工具名上。
|
|
935
935
|
//
|
|
936
936
|
// 与用户记忆分开的另一点是**对象**:笔记是一句话、按层(global / workspace)走;
|
|
937
|
-
// 用户记忆是多段、按场景走。读取统一走 `
|
|
937
|
+
// 用户记忆是多段、按场景走。读取统一走 `memory_manager_get`,这里只保留写入与删除。
|
|
938
938
|
// 弹卡策略:自动确认关 → 每次都问;开 → 不弹卡,由 agent 决定。生效判断在 gates 的 `autoActive`。
|
|
939
939
|
if (!deps.evolutionOps || !deps.autoLearnEnabled)
|
|
940
940
|
return { refreshNoteSchema() { } };
|
|
941
941
|
const noteOps = deps.evolutionOps;
|
|
942
942
|
const noteToolDef = defineTool({
|
|
943
943
|
name: PROACTIVE_MEMORY_TOOL,
|
|
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
|
|
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.',
|
|
945
945
|
parameters: {
|
|
946
946
|
action: { type: 'string', enum: ['learn', 'forget'], required: true, description: 'learn or forget.' },
|
|
947
947
|
// ── learn ──
|
|
@@ -989,7 +989,7 @@ export function buildMemoryTools(deps) {
|
|
|
989
989
|
if (!r || r.ok === false) {
|
|
990
990
|
// 带 `note:` 前缀的一定是笔记:它只是不存在了,别再说"这像是用户记忆"。
|
|
991
991
|
if (isNoteRef(ref)) {
|
|
992
|
-
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.');
|
|
993
993
|
}
|
|
994
994
|
// 用户记忆 id 也是 `<scene>/<name>` 形状;零命中时明确说这不是笔记,别让模型再猜。
|
|
995
995
|
if (raw.includes('/')) {
|
|
@@ -997,7 +997,7 @@ export function buildMemoryTools(deps) {
|
|
|
997
997
|
}
|
|
998
998
|
// 走到这里说明 id / slot / title / 注入行都没命中。`evolution-forget` 的内部错
|
|
999
999
|
// (`not a memory id`)对模型没有任何可执行信息 —— 它要的是"下一步做什么"。
|
|
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
|
|
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.');
|
|
1001
1001
|
}
|
|
1002
1002
|
return 'OK: forgot ' + noteRefOf(String(r.id || raw)) + '. It will not be learned again for 30 days.';
|
|
1003
1003
|
}
|
|
@@ -1021,13 +1021,13 @@ export function buildMemoryTools(deps) {
|
|
|
1021
1021
|
// save 的参数串进来时(`body` / `memory`),直接指回用户记忆,
|
|
1022
1022
|
// 别让一次完整记忆被当成一句话笔记丢掉。
|
|
1023
1023
|
if (args && (args.body !== undefined || args.memory !== undefined)) {
|
|
1024
|
-
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).');
|
|
1025
1025
|
}
|
|
1026
1026
|
// ── learn(默认)──
|
|
1027
1027
|
//
|
|
1028
1028
|
// 先查用户记忆里是不是已经有同一条:用户自己写过的(或让模型写过的)记忆**永久生效、
|
|
1029
1029
|
// 不衰减、不进回收站**,而笔记是会被 TTL 提醒、被合并、被归档的缓存。模型不知道这件事,
|
|
1030
|
-
// 于是常见症状是——用户说「记住这个仓库用 pnpm」,模型先用
|
|
1030
|
+
// 于是常见症状是——用户说「记住这个仓库用 pnpm」,模型先用 memory_manager_remember 存了一条,
|
|
1031
1031
|
// 之后每次看到又顺手记一条笔记,页面上同一条规则出现两遍,其中一遍还会自己过期。
|
|
1032
1032
|
//
|
|
1033
1033
|
// 命中就**不写**,并把已有的那条 id 告诉模型:它可以去更新那条,而不是另立一条。
|
|
@@ -1041,7 +1041,7 @@ export function buildMemoryTools(deps) {
|
|
|
1041
1041
|
// 已经在用户记忆里说过的事不再记一条笔记:见 `userMemoryCovering` 的说明。
|
|
1042
1042
|
const covered = await userMemoryCovering(text);
|
|
1043
1043
|
if (covered !== null) {
|
|
1044
|
-
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.';
|
|
1045
1045
|
}
|
|
1046
1046
|
// 非法 TTL 不能静默落默认值:调用方会以为"30 天后重查"生效了。
|
|
1047
1047
|
if (args && args.ttlDays !== undefined) {
|
|
@@ -1135,7 +1135,7 @@ export function buildMemoryTools(deps) {
|
|
|
1135
1135
|
if (choice.choice === 'revise') {
|
|
1136
1136
|
return 'Not saved yet. The user wants this note worded differently:\n' +
|
|
1137
1137
|
String(choice.custom ?? '') + '\n\n' +
|
|
1138
|
-
'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.';
|
|
1139
1139
|
}
|
|
1140
1140
|
if (choice.choice === 'skip') {
|
|
1141
1141
|
return 'Not saved: the user chose not to add it. Do not save it again unless they ask.';
|
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
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// 即**字符数 / 4**;`header.tools` 里只有 name / description / parameters —— 官方的
|
|
13
13
|
// `projectToolSchema` 不投影 output / execute,那几个不进请求。界面「模型工具表」那行
|
|
14
14
|
// 合计与逐条 ≈tok 就是这份):
|
|
15
|
-
// · 上一次实测(`
|
|
15
|
+
// · 上一次实测(`memory_manager_get` 合并之前)是 18 条隐藏 ≈**4,524 tok**、默认可见 6 条
|
|
16
16
|
// ≈**1,536 tok**、全开 ≈**6,055 tok**。合并后少了一条工具、描述也换了,**没有重测** ——
|
|
17
17
|
// 引用时按"旧口径"说,别当成当前工具表的实测值。
|
|
18
18
|
// · 同一批 A/B 实测净少 **4,119 / 4,197 tok**(把当时那批隐藏工具逐个打开,前后各跑两轮),
|
|
@@ -51,7 +51,7 @@ import { CONTROL_TOOL_NAME } from './deps.js';
|
|
|
51
51
|
* learn / forget 两个行为靠 `action` 分叉;名字集中在这里,是因为
|
|
52
52
|
* 「出厂隐藏名单」「跟随总开关开合」「旧名迁移」「工具注册」四处都得认同一串字符。
|
|
53
53
|
*/
|
|
54
|
-
export const PROACTIVE_MEMORY_TOOL = '
|
|
54
|
+
export const PROACTIVE_MEMORY_TOOL = 'memory_manager_note';
|
|
55
55
|
/**
|
|
56
56
|
* 自主笔记那条工具**只跟总开关走**,工具表盘上存过的关停名单对它无效。
|
|
57
57
|
*
|
|
@@ -90,17 +90,17 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
90
90
|
* 平时也用不到模型自己伸手**。分五组:
|
|
91
91
|
* · **写侧五条** —— 三个 `*_save`(MCP / 技能 / 人设:配置本体在面板上改)+
|
|
92
92
|
* `prompt_manager_apply`(当前生效的那份本来就在 `Current prompt` 注入段里)+
|
|
93
|
-
* `
|
|
93
|
+
* `plugin_manager_trash`(删除进回收站可恢复,但常态下由面板承担)。
|
|
94
94
|
* · **读侧四条** —— `mcp_manager_list` / `skill_manager_list` / `prompt_manager_list` /
|
|
95
95
|
* `scene_manager_list`。会话开头注入的那几段目录已经写了当前有什么,模型不必每轮
|
|
96
96
|
* 再带一份查询工具。
|
|
97
|
-
* **`
|
|
98
|
-
* 藏掉它等于把被截断的条目、以及 `
|
|
97
|
+
* **`memory_manager_get` 刻意不在这份名单**:合并后的读取入口同时承担清单、搜索与正文,
|
|
98
|
+
* 藏掉它等于把被截断的条目、以及 `memory_manager_remember` 需要的 id 变成不可发现。
|
|
99
99
|
* · **切场一条** —— `scene_manager_switch`:进入 / 退出场景。
|
|
100
100
|
* · **开关四条** —— `skill` / `memory` / `subagent` 三个 `_switch`(用户:「平时使用也很少」)
|
|
101
101
|
* + `mcp_manager_switch`。启停在面板上都有同款,注入段也写着当前开着哪些。
|
|
102
102
|
* MCP 那条**也关**(用户指定的五条清单里没有它):代价是这个域出厂没有一条可见工具 ——
|
|
103
|
-
* 模型要停 / 启服务器,得先用 `
|
|
103
|
+
* 模型要停 / 启服务器,得先用 `tool_manager_switch` 把它打开,多一次往返。默认清单以
|
|
104
104
|
* 用户点名的五条为准,不为了"每域留一条腿"自行加回。
|
|
105
105
|
* · **建档两条** —— `scene_manager_save`(场景记录)+ `scene_manager_archive`(档案段:
|
|
106
106
|
* 进入时开哪些 MCP / 技能 / 人设)。配置本体在面板上改;档案的勾选集机器自己算得出来
|
|
@@ -116,7 +116,7 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
116
116
|
* 技能 / 人设"是常问的,但它**低频于"读现状 + 拨开关 + 建改定义"**那批,而且面板每个域都有
|
|
117
117
|
* 删除入口 —— 默认关、要用时在「兼容」页勾上(与其余默认关停的工具同一条纪律,不额外付 token)。
|
|
118
118
|
*
|
|
119
|
-
* 关掉的这些**模型自己也能打开**:`
|
|
119
|
+
* 关掉的这些**模型自己也能打开**:`tool_manager_switch`(每轮常驻的那一条)能按对话
|
|
120
120
|
* 打开任意一条被关掉的工具,列清单时给出名字、一句话用途与 ≈token。这条工具不在
|
|
121
121
|
* 这份名单里 —— 它是唯一的回头路,自己关掉自己的话就再也开不回来了。
|
|
122
122
|
*
|
|
@@ -126,7 +126,7 @@ export function stripProactiveToolHidden(hidden) {
|
|
|
126
126
|
* 上下文的记忆正文"在会话里查不到;`*_switch` 关掉后模型也不能再替你拨启停。三处配套改动为
|
|
127
127
|
* 的就是不把模型往墙上推:目录被条数上限截断时那句「用 `X_manager_list` 查」自动退回「另有
|
|
128
128
|
* N more not listed.)」(`listToolVisible`);`mcp_manager_list` / `skill_manager_read` 里"没找到 →
|
|
129
|
-
* 去调 list"那两句先问 `deps.toolVisible`;`
|
|
129
|
+
* 去调 list"那两句先问 `deps.toolVisible`;`memory_manager_get` 的描述不再点名已关的工具。
|
|
130
130
|
*
|
|
131
131
|
* 只在**用户从没记过选择**时生效(见 index.ts 的 `toolTableSettingsFrom`:侧车文件读不出来
|
|
132
132
|
* 才用这份)。已经存过盘的一律照原样,包括显式的 `hidden: []` —— 那是"我全都要",
|
|
@@ -137,7 +137,7 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
|
|
|
137
137
|
'scene_manager_switch',
|
|
138
138
|
'scene_manager_save',
|
|
139
139
|
'scene_manager_archive',
|
|
140
|
-
'
|
|
140
|
+
'memory_manager_switch',
|
|
141
141
|
'mcp_manager_list',
|
|
142
142
|
'mcp_manager_save',
|
|
143
143
|
'mcp_manager_switch',
|
|
@@ -149,7 +149,7 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
|
|
|
149
149
|
'subagent_manager_save',
|
|
150
150
|
'prompt_manager_list',
|
|
151
151
|
'prompt_manager_apply',
|
|
152
|
-
'
|
|
152
|
+
'plugin_manager_trash',
|
|
153
153
|
// 自主笔记:默认藏着(它是权限,不是便利),此后**跟随总开关开合** —— 开着强制可见、
|
|
154
154
|
// 关着强制隐藏,两边都不能手动改(见 index.ts 的 proactiveMemoryGlobalOn 那条过滤链)。
|
|
155
155
|
// 放在这份名单而不是另建一张表:
|
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
|
//
|