dsh-memorytree-rule 0.0.0-stage → 1.0.2
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 +36 -0
- package/LICENSE +21 -0
- package/README.md +144 -3
- package/bin/mt.mjs +589 -0
- package/client.js +227 -0
- package/cordis.patch.yml +14 -0
- package/docs/DETAIL.md +69 -0
- package/docs/DETAIL.svg +85 -0
- package/docs/EMOTION.md +99 -0
- package/examples/AGENTS.demo.md +22 -0
- package/examples/AGENTS.template.md +212 -0
- package/icon.svg +17 -0
- package/index.js +418 -0
- package/lib/board.mjs +1113 -0
- package/lib/cards.mjs +56 -0
- package/lib/daily.mjs +140 -0
- package/lib/db.mjs +84 -0
- package/lib/demo.mjs +161 -0
- package/lib/diary.mjs +92 -0
- package/lib/emotion.mjs +474 -0
- package/lib/import-legacy.mjs +167 -0
- package/lib/ingest.mjs +279 -0
- package/lib/levels.mjs +40 -0
- package/lib/paths.mjs +85 -0
- package/lib/report.mjs +2130 -0
- package/lib/rules.mjs +635 -0
- package/lib/runtime.mjs +232 -0
- package/lib/schema.mjs +363 -0
- package/lib/search.mjs +264 -0
- package/lib/store.mjs +1334 -0
- package/lib/text.mjs +161 -0
- package/lib/tools.mjs +962 -0
- package/lib/vector.mjs +51 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +81 -6
- package/tests/emotion.test.mjs +215 -0
- package/tests/memory-tree.test.mjs +620 -0
- package/tests/regressions.test.mjs +834 -0
- package/tests/renumber.test.mjs +276 -0
- package/tests/trunk-bucket.test.mjs +225 -0
package/lib/tools.mjs
ADDED
|
@@ -0,0 +1,962 @@
|
|
|
1
|
+
// lib/tools.mjs — 9 个 memory_* 工具:按需召回、显式写入、日结分拣、维护。
|
|
2
|
+
//
|
|
3
|
+
// 约定(写给模型看的契约):
|
|
4
|
+
// - 检索默认覆盖全库(user + 各 workspace);不用传 scope 也能跨工作区找到任务卡。
|
|
5
|
+
// - 写入必须显式调用;插件不会偷偷记东西(AGENTS.md 的「单一注入源」约束)。
|
|
6
|
+
// - 主干(§1 判据)的正本是 AGENTS.md,这里写 trunk 只会产生「候选」,等主人点头再并入文件。
|
|
7
|
+
// - 遗忘默认归档,hard=true 才物理删除;工具层拒绝无理由的 hard 删除。
|
|
8
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
9
|
+
import { searchMemory } from "./search.mjs";
|
|
10
|
+
import { syncTrunk } from "./ingest.mjs";
|
|
11
|
+
import { importLegacy } from "./import-legacy.mjs";
|
|
12
|
+
import { buildDailyReport, applyDailyDecisions } from "./daily.mjs";
|
|
13
|
+
import { buildReportHtml } from "./report.mjs";
|
|
14
|
+
import { localDate } from "./diary.mjs";
|
|
15
|
+
import { LAYERS } from "./schema.mjs";
|
|
16
|
+
import { contentBlocks, estimateTokens, truncate } from "./text.mjs";
|
|
17
|
+
import { budgetFor, candidateStats, listCandidates, markCandidates, recordReview, sessionIdOf } from "./emotion.mjs";
|
|
18
|
+
|
|
19
|
+
const LAYER_LABEL = { trunk: "主干", emotion: "情感枝", task: "任务枝", leaf: "判断叶" };
|
|
20
|
+
const LAYER_ORDER = ["trunk", "emotion", "task", "leaf"];
|
|
21
|
+
|
|
22
|
+
function layerLabel(l) {
|
|
23
|
+
return LAYER_LABEL[l] ?? l;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseList(v) {
|
|
27
|
+
if (Array.isArray(v)) return v.map((x) => String(x).trim()).filter(Boolean);
|
|
28
|
+
return String(v ?? "")
|
|
29
|
+
.split(/[,,\s]+/)
|
|
30
|
+
.map((x) => x.trim())
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function refOf(n) {
|
|
35
|
+
return "#" + n.id;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function oneLine(s, max = 160) {
|
|
39
|
+
return truncate(String(s ?? "").replace(/\s+/g, " ").trim(), max);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 先写临时文件再替换,避免进程中断时把已有备份/报告写成半截。 */
|
|
43
|
+
async function writeFileAtomic(file, text) {
|
|
44
|
+
const fs = await import("node:fs");
|
|
45
|
+
const pathMod = await import("node:path");
|
|
46
|
+
const tmp = pathMod.join(
|
|
47
|
+
pathMod.dirname(file),
|
|
48
|
+
"." + pathMod.basename(file) + ".tmp-" + process.pid + "-" + Date.now(),
|
|
49
|
+
);
|
|
50
|
+
try {
|
|
51
|
+
fs.writeFileSync(tmp, text, "utf8");
|
|
52
|
+
try {
|
|
53
|
+
fs.renameSync(tmp, file);
|
|
54
|
+
} catch {
|
|
55
|
+
// Windows 上目标被占用时 rename 会 EPERM,退化为覆盖复制。
|
|
56
|
+
fs.copyFileSync(tmp, file);
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
try {
|
|
60
|
+
if (fs.existsSync(tmp)) fs.unlinkSync(tmp);
|
|
61
|
+
} catch {
|
|
62
|
+
/* 临时文件清理失败不影响主结果 */
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function fmtScore(x) {
|
|
68
|
+
return Number(x).toFixed(2).replace(/^0/, "");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
72
|
+
// memory_search
|
|
73
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
74
|
+
const searchTool = {
|
|
75
|
+
name: "memory_search",
|
|
76
|
+
description:
|
|
77
|
+
"按需召回记忆树里的条目(主干规则、情感枝、任务枝卡、判断叶)。混合检索:BM25 关键词 + 字符 n-gram 近似向量,按重要性/信任/衰减加权。任务开始前查一次相关背景;查不到会返回「没有命中」和原因,不会编造。默认搜全库(user + 各 workspace)。",
|
|
78
|
+
parameters: {
|
|
79
|
+
query: { type: "string", required: true, description: "检索词,3-12 个词:主体 + 动作/参数,如「pet-bridge 语音 tts」" },
|
|
80
|
+
scope: { type: "string", enum: ["all", "user", "workspace"], description: "作用域:all=全库(默认),user=只查全局,workspace=只查当前工作区" },
|
|
81
|
+
layers: { type: "string", description: "只查某些枝条,逗号分隔:trunk,emotion,task,leaf;默认全部" },
|
|
82
|
+
limit: { type: "integer", description: "返回条数 1-30,默认 6" },
|
|
83
|
+
mode: { type: "string", enum: ["hybrid", "keyword", "vector"], description: "检索方式,默认 hybrid(关键词+近似向量)" },
|
|
84
|
+
minScore: { type: "number", description: "相关度阈值 0-1,默认按模式自动定;调高更严格" },
|
|
85
|
+
includeArchived: { type: "boolean", description: "连已归档/已取代的旧条目一起看(排查历史口径时用)" },
|
|
86
|
+
},
|
|
87
|
+
output: {
|
|
88
|
+
schema: { type: "json" },
|
|
89
|
+
render(args, v) {
|
|
90
|
+
if (!v || v.ok === false) return "记忆检索失败:" + (v?.error ?? "未知错误");
|
|
91
|
+
const lines = [];
|
|
92
|
+
lines.push(
|
|
93
|
+
"记忆检索「" + v.query + "」:命中 " + v.total + " 条" + (v.returned ? ",显示 " + v.returned : "") +
|
|
94
|
+
"(" + v.mode + ";作用域 " + (v.scope ? v.scope.join("+") : "all") + ";候选 " + v.candidateCount + ")",
|
|
95
|
+
);
|
|
96
|
+
if (v.empty) {
|
|
97
|
+
lines.push(v.reason);
|
|
98
|
+
if (v.topRejected && v.topRejected.length) {
|
|
99
|
+
lines.push("最接近但未过阈值的:" + v.topRejected.map((t) => "#" + t.id + "(" + layerLabel(t.layer) + " " + fmtScore(t.score) + ")").join("、"));
|
|
100
|
+
}
|
|
101
|
+
lines.push("建议:换同义说法再查一次,或直接 memory_write 记下新信息;不要凭猜测补全。");
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
let n = 0;
|
|
105
|
+
for (const h of v.hits) {
|
|
106
|
+
const flags = [];
|
|
107
|
+
if (h.status !== "active") flags.push(h.status);
|
|
108
|
+
if (h.expired) flags.push("已过期");
|
|
109
|
+
if (h.match.phrase) flags.push("整串命中");
|
|
110
|
+
lines.push(
|
|
111
|
+
++n + ". [" + layerLabel(h.layer) + "] " + refOf(h) + " " + (h.subject ? h.subject + " · " : "") +
|
|
112
|
+
fmtScore(h.relevance) + (flags.length ? " (" + flags.join(",") + ")" : "") + " — " + oneLine(h.title || h.text, 60),
|
|
113
|
+
);
|
|
114
|
+
lines.push(" " + oneLine(h.snippet, 200));
|
|
115
|
+
if (h.validUntil) lines.push(" 有效期至:" + new Date(h.validUntil).toISOString().slice(0, 10));
|
|
116
|
+
}
|
|
117
|
+
if (v.honest) lines.push("(" + v.honest + ")");
|
|
118
|
+
return lines.join("\n");
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
timeoutMs: 20000,
|
|
122
|
+
async execute(args, exec) {
|
|
123
|
+
const rt = args.__rt;
|
|
124
|
+
const store = rt.open();
|
|
125
|
+
rt.ensureTrunk(exec);
|
|
126
|
+
const { scopes } = rt.scopesFor(exec, args.scope ?? "all");
|
|
127
|
+
const layers = parseList(args.layers).filter((l) => LAYERS.includes(l));
|
|
128
|
+
const res = searchMemory(store, {
|
|
129
|
+
query: args.query,
|
|
130
|
+
scopes,
|
|
131
|
+
layers: layers.length ? layers : undefined,
|
|
132
|
+
limit: args.limit,
|
|
133
|
+
mode: args.mode,
|
|
134
|
+
threshold: args.minScore,
|
|
135
|
+
status: args.includeArchived === true ? ["active", "candidate", "superseded", "archived"] : ["active", "candidate"],
|
|
136
|
+
});
|
|
137
|
+
return { ok: true, scope: scopes, ...res };
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
142
|
+
// memory_write
|
|
143
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
144
|
+
const writeTool = {
|
|
145
|
+
name: "memory_write",
|
|
146
|
+
description:
|
|
147
|
+
"往记忆树写一条记忆(唯一正确的新增方式)。layer 选枝条:task=做法/路径/坑的卡片(一个 subject 一张卡,自动替换旧卡),leaf=还没分类的观察(等每日分拣),emotion=相处与关系,trunk=主干规则候选(正本是 AGENTS.md,这里只产生候选)。默认自动脱敏(密钥/邮箱/长数字);确实要保留原文时传 redact:false。用户说「制定新规则:…」时,按约定写 layer=leaf、tags=新规则、source=chat:rule,进入判断叶等待分拣。",
|
|
148
|
+
parameters: {
|
|
149
|
+
layer: { type: "string", enum: ["trunk", "emotion", "task", "leaf"], required: true, description: "写到哪根枝条" },
|
|
150
|
+
text: { type: "string", required: true, description: "记忆正文(写清楚对象、条件、路径、结论)" },
|
|
151
|
+
subject: { type: "string", description: "主题键:task 卡用插件/脚本名(如 pet-bridge),emotion 可写对象,trunk 可留空" },
|
|
152
|
+
title: { type: "string", description: "一句话标题,便于列表里认出来" },
|
|
153
|
+
tags: { type: "string", description: "标签,逗号分隔,如「语音,踩坑」" },
|
|
154
|
+
scope: { type: "string", enum: ["auto", "user", "workspace"], description: "默认 auto:四枝都进全局(user);项目私有内容传 workspace" },
|
|
155
|
+
evidence: { type: "string", description: "逐字证据:原话/命令输出/文件行号片段,便于核实" },
|
|
156
|
+
importance: { type: "number", description: "重要性 0-1,默认按枝条给" },
|
|
157
|
+
halfLifeDays: { type: "number", description: "半衰期天数;0=不衰减(长期事实),短期信息填 30/90" },
|
|
158
|
+
validUntil: { type: "string", description: "有效期,ISO 日期(2026-12-31)或毫秒时间戳;过期条目检索会降权" },
|
|
159
|
+
supersedes: { type: "string", description: "要合并/取代的旧条目 id,逗号分隔;旧条目不会被删,只标 superseded" },
|
|
160
|
+
source: { type: "string", description: "来源标记(可选,默认 manual);自动采集或日结写入时用来回溯,只存短标记,不存正文" },
|
|
161
|
+
redact: { type: "boolean", description: "默认 true,自动脱敏密钥/邮箱/长数字;传 false 保留原文(敏感信息自行负责)" },
|
|
162
|
+
},
|
|
163
|
+
output: {
|
|
164
|
+
schema: { type: "json" },
|
|
165
|
+
render(args, v) {
|
|
166
|
+
if (!v || v.ok === false) return "写入失败:" + (v?.error ?? "未知错误");
|
|
167
|
+
const n = v.node;
|
|
168
|
+
const lines = [];
|
|
169
|
+
lines.push(
|
|
170
|
+
(v.duplicate ? "已存在(未重复写入):" : "已写入:") + "[" + layerLabel(n.layer) + "] " + refOf(n) +
|
|
171
|
+
(n.subject ? " " + n.subject : "") + " · " + oneLine(n.title || n.text, 60),
|
|
172
|
+
);
|
|
173
|
+
if (n.status === "candidate") {
|
|
174
|
+
lines.push("状态是 candidate:主干正本是 AGENTS.md,这条要等主人点头才能并入 §1(可用 memory_admin action=report 查看候选)。");
|
|
175
|
+
}
|
|
176
|
+
if (v.redactions && v.redactions.length) lines.push("已自动脱敏:" + v.redactions.join(";") + "(原文未落库)");
|
|
177
|
+
if (v.superseded && v.superseded.length) lines.push("已取代旧条目:" + v.superseded.map((i) => "#" + i).join("、") + "(旧条目保留可追溯)");
|
|
178
|
+
if (v.hint) lines.push(v.hint);
|
|
179
|
+
return lines.join("\n");
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
timeoutMs: 20000,
|
|
183
|
+
async execute(args, exec) {
|
|
184
|
+
const rt = args.__rt;
|
|
185
|
+
const store = rt.open();
|
|
186
|
+
rt.ensureTrunk(exec);
|
|
187
|
+
const layer = String(args.layer);
|
|
188
|
+
if (!LAYERS.includes(layer)) return { ok: false, error: "layer 只能是 " + LAYERS.join("/") };
|
|
189
|
+
const requestedScope = args.scope && String(args.scope) !== "auto" ? String(args.scope) : "auto";
|
|
190
|
+
if (!["auto", "user", "workspace"].includes(requestedScope)) {
|
|
191
|
+
return { ok: false, error: "scope 只能是 auto / user / workspace" };
|
|
192
|
+
}
|
|
193
|
+
const scope =
|
|
194
|
+
requestedScope === "auto"
|
|
195
|
+
? rt.defaultScope(layer, exec)
|
|
196
|
+
: requestedScope === "user"
|
|
197
|
+
? "user"
|
|
198
|
+
: rt.workspaceOf(exec).scope;
|
|
199
|
+
if (layer === "trunk" && scope !== "user") {
|
|
200
|
+
return { ok: false, error: "主干规则只属于 user 作用域;请用 scope=user 或 auto 写入主干候选。" };
|
|
201
|
+
}
|
|
202
|
+
const tags = parseList(args.tags);
|
|
203
|
+
const source = String(args.source ?? "manual").trim().slice(0, 200) || "manual";
|
|
204
|
+
const input = {
|
|
205
|
+
layer,
|
|
206
|
+
scope,
|
|
207
|
+
text: args.text,
|
|
208
|
+
subject: args.subject,
|
|
209
|
+
title: args.title,
|
|
210
|
+
tags,
|
|
211
|
+
evidence: args.evidence,
|
|
212
|
+
importance: args.importance,
|
|
213
|
+
halfLifeDays: args.halfLifeDays,
|
|
214
|
+
validUntil: args.validUntil,
|
|
215
|
+
source,
|
|
216
|
+
skipRedact: args.redact === false,
|
|
217
|
+
};
|
|
218
|
+
let hint;
|
|
219
|
+
if (layer === "trunk") hint = "主干候选已入队;并入 AGENTS.md 前不会影响每轮注入(单一注入源不变)。";
|
|
220
|
+
|
|
221
|
+
const supersedes = parseList(args.supersedes);
|
|
222
|
+
const tail = { duplicate: false, superseded: [], redactions: [], hint: hint ?? "" };
|
|
223
|
+
let res;
|
|
224
|
+
if (supersedes.length > 0) {
|
|
225
|
+
res = store.supersede(supersedes, { ...input, source: source + ":merge" }, { scopes: rt.scopesFor(exec, "all").scopes });
|
|
226
|
+
if (layer === "task") {
|
|
227
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响写入 */ }
|
|
228
|
+
}
|
|
229
|
+
return { ok: true, node: res.node, ...tail, superseded: res.superseded ?? [] };
|
|
230
|
+
}
|
|
231
|
+
if (layer === "task" && input.subject) {
|
|
232
|
+
const r = store.replaceCard(input.subject, input);
|
|
233
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响写入 */ }
|
|
234
|
+
return { ok: true, node: r.node, ...tail, superseded: r.superseded ?? [] };
|
|
235
|
+
}
|
|
236
|
+
const r = store.add(input);
|
|
237
|
+
if (layer === "task") {
|
|
238
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响写入 */ }
|
|
239
|
+
}
|
|
240
|
+
return { ok: true, node: r.node, ...tail, duplicate: !!r.duplicate, redactions: r.redactions ?? [] };
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
245
|
+
// memory_forget
|
|
246
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
247
|
+
const forgetTool = {
|
|
248
|
+
name: "memory_forget",
|
|
249
|
+
description:
|
|
250
|
+
"遗忘记忆条目。默认归档(archived,可恢复、不算删除);只有主人明确要求彻底删除时才传 hard=true,且必须写 reason。分类错误/内容重复优先用 memory_write 的 supersedes 合并,而不是删除。",
|
|
251
|
+
parameters: {
|
|
252
|
+
ids: { type: "string", required: true, description: "条目 id 或 uid,逗号分隔,如「12,13」或「leaf:ab12cd」" },
|
|
253
|
+
hard: { type: "boolean", description: "true=物理删除(不可恢复)。只有主人明确要求时才用" },
|
|
254
|
+
reason: { type: "string", description: "为什么要遗忘/删除,写进审计" },
|
|
255
|
+
},
|
|
256
|
+
output: {
|
|
257
|
+
schema: { type: "json" },
|
|
258
|
+
render(args, v) {
|
|
259
|
+
if (!v || v.ok === false) return "遗忘失败:" + (v?.error ?? "未知错误");
|
|
260
|
+
const parts = v.results.map((r) => (r.ok ? refOf(r) + (r.hard ? " 已物理删除" : " 已归档") : refOf(r) + " 失败:" + r.error));
|
|
261
|
+
return (v.hard ? "已删除:" : "已遗忘(归档):") + parts.join(";") + (v.hard ? "\n注意:物理删除不可恢复。" : "\n归档条目仍可被 includeArchived 检索到,需要时可恢复。");
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
timeoutMs: 20000,
|
|
265
|
+
async execute(args, exec) {
|
|
266
|
+
const rt = args.__rt;
|
|
267
|
+
const store = rt.open();
|
|
268
|
+
const ids = parseList(args.ids);
|
|
269
|
+
if (ids.length === 0) return { ok: false, error: "ids 不能为空" };
|
|
270
|
+
const hard = args.hard === true;
|
|
271
|
+
if (hard && String(args.reason ?? "").trim() === "") {
|
|
272
|
+
return { ok: false, error: "hard=true 必须给出 reason(不可恢复的操作要留痕)" };
|
|
273
|
+
}
|
|
274
|
+
const { scopes } = rt.scopesFor(exec, "all");
|
|
275
|
+
const results = [];
|
|
276
|
+
for (const ref of ids) {
|
|
277
|
+
const n = store.get(ref, { scope: scopes });
|
|
278
|
+
if (!n) {
|
|
279
|
+
results.push({ id: ref, ok: false, error: "找不到这条记忆,或它不在当前作用域" });
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
store.forget(n.id, { hard, reason: args.reason ?? "" });
|
|
284
|
+
results.push({ id: n.id, uid: n.uid, ok: true, hard });
|
|
285
|
+
} catch (err) {
|
|
286
|
+
results.push({ id: n.id, ok: false, error: err && err.message ? err.message : String(err) });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响遗忘 */ }
|
|
290
|
+
return { ok: true, hard, results };
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
295
|
+
// memory_tree
|
|
296
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
297
|
+
const treeTool = {
|
|
298
|
+
name: "memory_tree",
|
|
299
|
+
description: "看记忆树的整体结构:四枝各自多少条、任务枝有哪些卡、主干候选、过期与待分拣。找东西先 memory_search,想看全貌/盘点再用它。",
|
|
300
|
+
parameters: {
|
|
301
|
+
scope: { type: "string", enum: ["all", "user", "workspace"], description: "默认 all=全库" },
|
|
302
|
+
layer: { type: "string", enum: ["trunk", "emotion", "task", "leaf"], description: "只看一根枝条" },
|
|
303
|
+
limit: { type: "integer", description: "每枝最多列几条,默认 12" },
|
|
304
|
+
},
|
|
305
|
+
output: {
|
|
306
|
+
schema: { type: "json" },
|
|
307
|
+
render(args, v) {
|
|
308
|
+
if (!v || v.ok === false) return "读取失败:" + (v?.error ?? "未知错误");
|
|
309
|
+
const t = v.tree;
|
|
310
|
+
const lines = [];
|
|
311
|
+
const s = t.stats;
|
|
312
|
+
lines.push("记忆树:" + s.total + " 条(active " + (s.byStatus.active ?? 0) + " / candidate " + (s.byStatus.candidate ?? 0) + " / archived " + (s.byStatus.archived ?? 0) + ")|待分拣叶 " + s.pendingLeaves + "|主干候选 " + s.candidates + "|任务卡 " + s.taskCards + "|过期 " + s.expired);
|
|
313
|
+
lines.push("库:" + v.dbFile + "(" + (s.dbBytes / 1024).toFixed(0) + " KB);主干文件:" + v.agentsPath + (s.lastSyncAt ? "(上次同步 " + new Date(s.lastSyncAt).toISOString().slice(0, 16).replace("T", " ") + ")" : "(还没同步)"));
|
|
314
|
+
for (const l of t.layers) {
|
|
315
|
+
if (!v.layerFilter || l.layer === v.layerFilter) {
|
|
316
|
+
lines.push("");
|
|
317
|
+
lines.push("§ " + layerLabel(l.layer) + "(" + (l.activeTotal ?? l.active) + " 条 active)");
|
|
318
|
+
if (l.items.length === 0) lines.push(" (空)");
|
|
319
|
+
for (const it of l.items.slice(0, v.limit)) {
|
|
320
|
+
lines.push(" " + refOf(it) + " " + (it.subject ? it.subject + " · " : "") + oneLine(it.title || it.preview, 78) + (it.expired ? " ×过期" : ""));
|
|
321
|
+
}
|
|
322
|
+
const more = Math.max((l.activeTotal ?? l.items.length) - Math.min(v.limit, l.items.length), 0);
|
|
323
|
+
if (more > 0) lines.push(" …还有 " + more + " 条(用 memory_search 或加大 limit 查看)");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (t.candidates.length) {
|
|
327
|
+
lines.push("");
|
|
328
|
+
lines.push("主干候选(等主人点头才并入 AGENTS.md):");
|
|
329
|
+
for (const c of t.candidates.slice(0, 10)) lines.push(" " + refOf(c) + " " + oneLine(c.title || c.text, 90));
|
|
330
|
+
}
|
|
331
|
+
return lines.join("\n");
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
timeoutMs: 20000,
|
|
335
|
+
async execute(args, exec) {
|
|
336
|
+
const rt = args.__rt;
|
|
337
|
+
const store = rt.open();
|
|
338
|
+
rt.ensureTrunk(exec);
|
|
339
|
+
const { scopes } = rt.scopesFor(exec, args.scope ?? "all");
|
|
340
|
+
const layer = args.layer && LAYERS.includes(String(args.layer)) ? String(args.layer) : undefined;
|
|
341
|
+
const limit = Math.min(Math.max(Number(args.limit) || 12, 1), 100);
|
|
342
|
+
const tree = store.tree({ scopes });
|
|
343
|
+
return {
|
|
344
|
+
ok: true,
|
|
345
|
+
layerFilter: layer ?? null,
|
|
346
|
+
limit,
|
|
347
|
+
dbFile: rt.paths.dbFile,
|
|
348
|
+
agentsPath: rt.paths.agentsPath,
|
|
349
|
+
tree: layer ? { ...tree, layers: tree.layers.filter((l) => l.layer === layer) } : tree,
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
355
|
+
// memory_card
|
|
356
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
357
|
+
const cardTool = {
|
|
358
|
+
name: "memory_card",
|
|
359
|
+
description:
|
|
360
|
+
"读一张任务枝卡的完整内容(按 subject 找,或按 id 直接取),可一并看到同主题的相关条目。动手做某个插件/脚本之前先读它的卡,比全文检索更直接。",
|
|
361
|
+
parameters: {
|
|
362
|
+
subject: { type: "string", description: "卡的主题键,如 pet-bridge、restart-dsh" },
|
|
363
|
+
id: { type: "string", description: "也可以直接给条目 id/uid" },
|
|
364
|
+
includeRelated: { type: "boolean", description: "是否附上同 subject 的其他条目(默认 true)" },
|
|
365
|
+
scope: { type: "string", enum: ["all", "user", "workspace"], description: "默认 all=全库" },
|
|
366
|
+
},
|
|
367
|
+
output: {
|
|
368
|
+
schema: { type: "json" },
|
|
369
|
+
render(args, v) {
|
|
370
|
+
if (!v || v.ok === false) return "读取卡片失败:" + (v?.error ?? "未知错误");
|
|
371
|
+
if (!v.card) return "没有找到" + (v.subject ? "「" + v.subject + "」的卡" : "这张卡") + "。" + (v.hint ?? "");
|
|
372
|
+
const c = v.card;
|
|
373
|
+
const lines = [];
|
|
374
|
+
lines.push("[" + layerLabel(c.layer) + "] " + refOf(c) + (c.subject ? " " + c.subject : "") + " · " + (c.title || "(无标题)"));
|
|
375
|
+
lines.push("更新时间:" + new Date(c.updatedAt).toISOString().slice(0, 16).replace("T", " ") + "|信任 " + c.trust + "|重要性 " + c.importance + "|来源 " + c.source);
|
|
376
|
+
if (c.tags.length) lines.push("标签:" + c.tags.join("、"));
|
|
377
|
+
lines.push("");
|
|
378
|
+
lines.push(c.text);
|
|
379
|
+
if (c.evidence) lines.push("", "证据:" + oneLine(c.evidence, 300));
|
|
380
|
+
if (v.related && v.related.length) {
|
|
381
|
+
lines.push("");
|
|
382
|
+
lines.push("同主题的其他条目:");
|
|
383
|
+
for (const r of v.related) lines.push(" " + refOf(r) + " [" + layerLabel(r.layer) + "] " + oneLine(r.title || r.text, 80) + (r.status !== "active" ? " (" + r.status + ")" : ""));
|
|
384
|
+
}
|
|
385
|
+
return lines.join("\n");
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
timeoutMs: 20000,
|
|
389
|
+
async execute(args, exec) {
|
|
390
|
+
const rt = args.__rt;
|
|
391
|
+
const store = rt.open();
|
|
392
|
+
rt.ensureTrunk(exec);
|
|
393
|
+
const { scopes } = rt.scopesFor(exec, args.scope ?? "all");
|
|
394
|
+
let card = null;
|
|
395
|
+
if (args.id !== undefined && String(args.id).trim() !== "") {
|
|
396
|
+
card = store.get(String(args.id).trim(), { scope: scopes });
|
|
397
|
+
}
|
|
398
|
+
const subject = String(args.subject ?? "").trim();
|
|
399
|
+
if (!card && subject !== "") {
|
|
400
|
+
const rows = store.list({ scope: scopes, layers: ["task"], status: "active", subject, limit: 2, order: "created" });
|
|
401
|
+
if (rows.length) card = rows[0];
|
|
402
|
+
if (!card) {
|
|
403
|
+
const any = store.list({ scope: scopes, subject, limit: 5, order: "importance" });
|
|
404
|
+
if (any.length) card = any[0];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (!card) {
|
|
408
|
+
const subjects = store.list({ scope: scopes, layers: ["task"], status: "active", limit: 200, order: "created" })
|
|
409
|
+
.map((n) => n.subject)
|
|
410
|
+
.filter(Boolean);
|
|
411
|
+
const hint = subjects.length
|
|
412
|
+
? "任务枝现有的主题键:" + Array.from(new Set(subjects)).slice(0, 40).join("、")
|
|
413
|
+
: "任务枝还没有卡;可用 memory_write layer=task 新建一张,或先用 memory_search 找找。";
|
|
414
|
+
return { ok: true, card: null, subject, hint };
|
|
415
|
+
}
|
|
416
|
+
let related = [];
|
|
417
|
+
if (args.includeRelated !== false) {
|
|
418
|
+
const subj = card.subject;
|
|
419
|
+
related = store.list({ scope: scopes, status: ["active", "candidate", "superseded"], limit: 20, order: "updated" })
|
|
420
|
+
.filter((n) => n.id !== card.id && (subj !== "" ? n.subject === subj : false))
|
|
421
|
+
.slice(0, 8);
|
|
422
|
+
}
|
|
423
|
+
return { ok: true, card, related };
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
428
|
+
// memory_ingest
|
|
429
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
430
|
+
const ingestTool = {
|
|
431
|
+
name: "memory_ingest",
|
|
432
|
+
description:
|
|
433
|
+
"把外部正本导入成可检索的副本:sync=解析 AGENTS.md 的 §1 主干规则(默认,文件变了才写);migrate=从旧 Python 版 memories.db 迁记忆条目(幂等);status=看路径与可迁移状态。不改变 AGENTS.md 本身。",
|
|
434
|
+
parameters: {
|
|
435
|
+
action: { type: "string", enum: ["sync", "migrate", "status"], description: "默认 sync" },
|
|
436
|
+
path: { type: "string", description: "migrate 时可指定旧库路径;默认读 <DSH_HOME>/remembers-data/memories.db" },
|
|
437
|
+
force: { type: "boolean", description: "sync 时强制重建全部主干条目(默认只处理变化的)" },
|
|
438
|
+
dryRun: { type: "boolean", description: "migrate 时默认只预览不落库(true);主人确认后再传 false 写入" },
|
|
439
|
+
},
|
|
440
|
+
output: {
|
|
441
|
+
schema: { type: "json" },
|
|
442
|
+
render(args, v) {
|
|
443
|
+
if (!v || v.ok === false) return "导入失败:" + (v?.error ?? v?.reason ?? "未知错误");
|
|
444
|
+
if (v.action === "status") {
|
|
445
|
+
return [
|
|
446
|
+
"库:" + v.paths.dbFile,
|
|
447
|
+
"主干正本:" + v.paths.agentsPath + (v.agentsExists ? "" : "(不存在)"),
|
|
448
|
+
"旧库:" + v.paths.legacyDb + (v.legacyExists ? "" : "(不存在,无需迁移)"),
|
|
449
|
+
"条目:" + v.stats.total + "|索引版本 " + v.stats.indexVersion + "|上次主干同步 " + (v.stats.lastSyncAt ? new Date(v.stats.lastSyncAt).toISOString().slice(0, 16).replace("T", " ") : "从未"),
|
|
450
|
+
].join("\n");
|
|
451
|
+
}
|
|
452
|
+
if (v.action === "migrate") {
|
|
453
|
+
return (v.dryRun ? "【预览,未写入】" : "【已写入】") + "迁移 " + v.source + ":读 " + v.total + " 条,新增 " + v.added + ",已存在跳过 " + v.duplicate + ",跳过 " + v.skipped.length +
|
|
454
|
+
";分布 " + Object.entries(v.byLayer).map(([k, n]) => layerLabel(k) + " " + n).join(" / ") + "。" +
|
|
455
|
+
(v.note ? "\n" + v.note : "");
|
|
456
|
+
}
|
|
457
|
+
if (v.skipped) return "主干未变化,跳过同步(" + v.rules + " 条规则已在库)。";
|
|
458
|
+
return "主干同步:" + v.path + " → " + v.rules + " 条规则(新增 " + v.added + "、更新 " + v.updated + "、未变 " + v.unchanged + "、归档 " + v.archived + ")。";
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
timeoutMs: 120000,
|
|
462
|
+
async execute(args, exec) {
|
|
463
|
+
const rt = args.__rt;
|
|
464
|
+
const action = String(args.action ?? "sync");
|
|
465
|
+
if (action === "status") return { ok: true, action, ...rt.info() };
|
|
466
|
+
if (action === "migrate") {
|
|
467
|
+
const store = rt.open();
|
|
468
|
+
const file = args.path && String(args.path).trim() !== "" ? String(args.path) : rt.paths.legacyDb;
|
|
469
|
+
const dryRun = args.dryRun !== false;
|
|
470
|
+
const res = importLegacy(store, file, { scope: "user", dryRun });
|
|
471
|
+
if (!res.ok) return { ok: false, error: res.reason };
|
|
472
|
+
if (!dryRun) {
|
|
473
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响迁移结果 */ }
|
|
474
|
+
}
|
|
475
|
+
return { ok: true, action, dryRun, ...res };
|
|
476
|
+
}
|
|
477
|
+
rt.open();
|
|
478
|
+
const res = rt.ensureTrunk(exec, { force: args.force === true });
|
|
479
|
+
if (!res.ok) return { ok: false, error: res.reason ?? "主干同步失败" };
|
|
480
|
+
return { ok: true, action: "sync", ...res };
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
485
|
+
// memory_daily
|
|
486
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
487
|
+
const dailyTool = {
|
|
488
|
+
name: "memory_daily",
|
|
489
|
+
description:
|
|
490
|
+
"每日分拣:action=report 生成待分拣判断叶的报告(含聚类、候选主干、过期与陈旧卡提醒),你读完报告后逐条调用 memory_write/memory_forget;action=apply 可一次性提交分拣决定(trunk 只会成为候选)。插件本身不调 LLM、不存 key。",
|
|
491
|
+
parameters: {
|
|
492
|
+
action: { type: "string", enum: ["report", "apply"], description: "默认 report" },
|
|
493
|
+
scope: { type: "string", enum: ["all", "user", "workspace"], description: "默认 all" },
|
|
494
|
+
hours: { type: "integer", description: "回看多少小时内的判断叶,默认 24" },
|
|
495
|
+
limit: { type: "integer", description: "报告里最多列多少条,默认 30" },
|
|
496
|
+
decisions: { type: "string", description: "apply 用:JSON 数组,如 [{\"id\":12,\"to\":\"task\",\"subject\":\"pet-bridge\"},{\"id\":13,\"to\":\"forget\"}]" },
|
|
497
|
+
},
|
|
498
|
+
output: {
|
|
499
|
+
schema: { type: "json" },
|
|
500
|
+
render(args, v) {
|
|
501
|
+
if (!v || v.ok === false) return "分拣失败:" + (v?.error ?? "未知错误");
|
|
502
|
+
if (v.action === "apply") {
|
|
503
|
+
const parts = v.results.map((r) => "#" + r.id + (r.ok ? " → " + (r.to === "forget" ? "遗忘" : layerLabel(r.to)) : " 失败:" + r.error));
|
|
504
|
+
return "分拣完成:" + parts.join(";") + (v.candidates ? "(主干候选 " + v.candidates + " 条等主人点头)" : "");
|
|
505
|
+
}
|
|
506
|
+
const r = v.report;
|
|
507
|
+
const lines = [];
|
|
508
|
+
lines.push("待分拣判断叶:" + r.pendingCount + " 条(回看 " + r.hours + " 小时;作用域 " + r.scopes.join("+") + ")");
|
|
509
|
+
if (r.pendingTruncated) lines.push("另有 " + r.pendingTruncated + " 条在回看窗口内,超过单次展示上限,未列出。");
|
|
510
|
+
if (r.pendingOlderThanWindow) lines.push("更早有 " + r.pendingOlderThanWindow + " 条判断叶不在回看窗口内,可加大 hours 再看。");
|
|
511
|
+
if (r.pendingCount === 0) {
|
|
512
|
+
lines.push("没有新的判断叶。");
|
|
513
|
+
} else {
|
|
514
|
+
for (const it of r.items) {
|
|
515
|
+
lines.push("#" + it.id + " " + new Date(it.updatedAt).toISOString().slice(5, 16).replace("T", " ") + " " + oneLine(it.text, 150) + (it.tags.length ? " [" + it.tags.join(",") + "]" : ""));
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (r.clusters.length) {
|
|
519
|
+
lines.push("");
|
|
520
|
+
lines.push("可能的聚类(同主题多条,考虑合并成一张卡):");
|
|
521
|
+
for (const c of r.clusters) lines.push(" " + c.key + ":" + c.ids.map((i) => "#" + i).join("、"));
|
|
522
|
+
}
|
|
523
|
+
if (r.staleCards.length) {
|
|
524
|
+
lines.push("");
|
|
525
|
+
lines.push("超过 " + r.staleDays + " 天没更新的任务卡(确认是否还准确):" + r.staleCards.map((c) => c.subject + "#" + c.id).join("、"));
|
|
526
|
+
}
|
|
527
|
+
if (r.expired.length) {
|
|
528
|
+
lines.push("");
|
|
529
|
+
lines.push("已过期条目(该续期或归档):" + r.expired.map((x) => "#" + x.id + " " + oneLine(x.title, 40)).join("、"));
|
|
530
|
+
}
|
|
531
|
+
lines.push("");
|
|
532
|
+
lines.push("分拣做法:逐条判断 → 值得长期保留的用 memory_write(to=task/emotion/trunk)→ 没用的 memory_forget → 也可以把决定写成 decisions 交给 action=apply。trunk 只会成为候选,不动 AGENTS.md。");
|
|
533
|
+
return lines.join("\n");
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
timeoutMs: 60000,
|
|
537
|
+
async execute(args, exec) {
|
|
538
|
+
const rt = args.__rt;
|
|
539
|
+
const store = rt.open();
|
|
540
|
+
rt.ensureTrunk(exec);
|
|
541
|
+
const action = String(args.action ?? "report");
|
|
542
|
+
const { scopes } = rt.scopesFor(exec, args.scope ?? "all");
|
|
543
|
+
if (action === "apply") {
|
|
544
|
+
let decisions = [];
|
|
545
|
+
try {
|
|
546
|
+
decisions = typeof args.decisions === "string" ? JSON.parse(args.decisions) : args.decisions;
|
|
547
|
+
} catch (err) {
|
|
548
|
+
return { ok: false, error: "decisions 不是合法 JSON:" + (err && err.message ? err.message : String(err)) };
|
|
549
|
+
}
|
|
550
|
+
if (!Array.isArray(decisions) || decisions.length === 0) return { ok: false, error: "decisions 为空" };
|
|
551
|
+
const res = applyDailyDecisions(store, decisions, { scopes });
|
|
552
|
+
if (res.results.some((r) => r.ok && r.to === "task")) {
|
|
553
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响分拣 */ }
|
|
554
|
+
}
|
|
555
|
+
return { ok: true, action, ...res };
|
|
556
|
+
}
|
|
557
|
+
const report = buildDailyReport(store, {
|
|
558
|
+
scopes,
|
|
559
|
+
hours: Math.min(Math.max(Number(args.hours) || 24, 1), 24 * 30),
|
|
560
|
+
limit: Math.min(Math.max(Number(args.limit) || 30, 1), 100),
|
|
561
|
+
});
|
|
562
|
+
return { ok: true, action: "report", report };
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
567
|
+
// memory_admin
|
|
568
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
569
|
+
const adminTool = {
|
|
570
|
+
name: "memory_admin",
|
|
571
|
+
description:
|
|
572
|
+
"记忆树维护:doctor=体检(完整性/索引/主干同步/旧库状态),stats=统计,reindex=重建派生索引,export/import=JSONL 备份与恢复(merge=只加新条目,update=同 uid 覆盖),audit=看检索与写入审计,report=生成自包含交互星图看板(四主题/检索/详情抽屉/打印),diary=每日日记索引(op=auto 自动拼装当天库内变动,op=write 手写,op=get/list 读取;自动模式不调 LLM、不覆盖手写),placement=看板“待写入哪条枝”请求(op=get 查看、op=list 列表、op=recommend 回写 DSH 建议、op=cancel 取消)。破坏性操作只有 import 的 update 模式,需要 owner 明确同意。",
|
|
573
|
+
parameters: {
|
|
574
|
+
action: { type: "string", enum: ["doctor", "stats", "reindex", "export", "import", "audit", "report", "diary", "placement"], required: true, description: "维护动作" },
|
|
575
|
+
path: { type: "string", description: "export 的落盘路径 / import 的文件路径" },
|
|
576
|
+
mode: { type: "string", enum: ["merge", "update"], description: "import 模式:merge=只加新条目(默认),update=同 uid 覆盖内容" },
|
|
577
|
+
overwrite: { type: "boolean", description: "export/report 目标文件已存在时是否覆盖,默认 false(防误删旧备份)" },
|
|
578
|
+
limit: { type: "integer", description: "audit/diary list 返回条数,默认 20" },
|
|
579
|
+
op: { type: "string", enum: ["auto", "write", "get", "list"], description: "diary 子动作,默认 auto" },
|
|
580
|
+
date: { type: "string", description: "diary 日期 YYYY-MM-DD,默认今天" },
|
|
581
|
+
text: { type: "string", description: "diary op=write 的正文;按 §2-4 只写索引(做了什么、路径),情感叙事放 emotion 枝" },
|
|
582
|
+
mood: { type: "string", description: "diary 可选标记,默认自动模式为 auto、手写为 manual" },
|
|
583
|
+
force: { type: "boolean", description: "diary op=auto 时覆盖当天手写日记" },
|
|
584
|
+
requestId: { type: "string", description: "placement 请求 id(看板提示里给出的编号)" },
|
|
585
|
+
subject: { type: "string", description: "placement op=recommend 时建议写入的任务卡 subject" },
|
|
586
|
+
title: { type: "string", description: "placement op=recommend 时建议的任务卡标题" },
|
|
587
|
+
reason: { type: "string", description: "placement op=recommend 时的一句话理由" },
|
|
588
|
+
},
|
|
589
|
+
output: {
|
|
590
|
+
schema: { type: "json" },
|
|
591
|
+
render(args, v) {
|
|
592
|
+
if (!v || v.ok === false) return "维护操作失败:" + (v?.error ?? "未知错误");
|
|
593
|
+
switch (v.action) {
|
|
594
|
+
case "doctor":
|
|
595
|
+
return [
|
|
596
|
+
"体检:" + (v.healthy ? "通过" : "有问题"),
|
|
597
|
+
"库:" + v.dbFile + "(" + (v.dbBytes / 1024).toFixed(0) + " KB,完整性 " + v.integrity + ")",
|
|
598
|
+
"条目 " + v.stats.total + "|索引版本 " + v.stats.indexVersion + "|缺词项索引 " + v.missingIndex + "|缺向量 " + v.missingVec,
|
|
599
|
+
"主干:" + (v.agents.ok ? v.agents.rules + " 条规则" + (v.agents.changed ? "(本次已更新)" : "(已是最新)") : "同步失败:" + v.agents.reason),
|
|
600
|
+
v.legacy.exists ? "旧库:" + v.legacy.path + (v.legacy.imported ? "(已迁移)" : "(尚未迁移,可 memory_ingest action=migrate)") : "旧库:不存在",
|
|
601
|
+
v.warnings.length ? "提醒:" + v.warnings.join(";") : "无告警",
|
|
602
|
+
].join("\n");
|
|
603
|
+
case "stats": {
|
|
604
|
+
const s = v.stats;
|
|
605
|
+
return "共 " + s.total + " 条:" + LAYER_ORDER.map((l) => layerLabel(l) + " " + (s.byLayer[l] ?? 0)).join(" / ") +
|
|
606
|
+
"|active " + (s.byStatus.active ?? 0) + " / candidate " + (s.byStatus.candidate ?? 0) + " / archived " + (s.byStatus.archived ?? 0) +
|
|
607
|
+
"|作用域 " + Object.entries(s.byScope).map(([k, n]) => k + ":" + n).join("、") + "|过期 " + s.expired;
|
|
608
|
+
}
|
|
609
|
+
case "reindex":
|
|
610
|
+
return "已重建派生索引:" + v.nodes + " 条(term/vec 全部重算,索引版本 " + v.indexVersion + ")。";
|
|
611
|
+
case "export":
|
|
612
|
+
return "已导出 " + v.count + " 条记忆" + (v.extras ? ",另含 " + v.extras + " 条日记/大标题记录" : "") + "到 " + v.path + "(" + v.bytes + " 字节;JSONL,可直接用 import 恢复)。";
|
|
613
|
+
case "import":
|
|
614
|
+
return "已从 " + v.path + " 导入:新增 " + v.added + ",更新 " + v.updated + ",跳过 " + v.skipped +
|
|
615
|
+
(v.diary ? ";日记 " + v.diary : "") + (v.buckets ? ";大标题 " + v.buckets : "") + "。";
|
|
616
|
+
case "audit":
|
|
617
|
+
if (v.rows.length === 0) return "还没有审计记录。";
|
|
618
|
+
return v.rows.map((r) => new Date(r.ts).toISOString().slice(5, 16).replace("T", " ") + " " + r.kind + (r.query ? "「" + r.query + "」" : "") + (r.hits === null ? "" : " → " + r.hits + " 条")).join("\n");
|
|
619
|
+
case "report":
|
|
620
|
+
return "已生成星图看板:" + v.path + "(" + (v.bytes / 1024).toFixed(0) + " KB;四枝星座、四主题、检索、详情抽屉、打印)。用浏览器打开即可;数据是生成时的快照。";
|
|
621
|
+
case "diary": {
|
|
622
|
+
if (v.op === "list") {
|
|
623
|
+
if (!v.rows.length) return "还没有日记。";
|
|
624
|
+
return v.rows.map((r) => r.date + "(" + (r.mood === "manual" ? "手写" : "自动") + "):" + oneLine(r.text, 120)).join("\n");
|
|
625
|
+
}
|
|
626
|
+
if (v.op === "get" && !v.record) return (v.date ?? "该日期") + " 还没有日记。";
|
|
627
|
+
if (v.skipped) return "未覆盖:" + v.reason;
|
|
628
|
+
const r = v.record;
|
|
629
|
+
return "日记 " + r.date + "(" + (r.mood === "manual" ? "手写" : "自动索引") + "," + r.text.length + " 字):\n" + r.text;
|
|
630
|
+
}
|
|
631
|
+
case "placement": {
|
|
632
|
+
if (v.op === "list") {
|
|
633
|
+
if (!v.rows.length) return "没有待写入请求。";
|
|
634
|
+
return v.rows.map((p) => p.id + "|" + (p.status === "pending" ? "待判断" : p.status === "recommended" ? "已推荐 " + p.recommendedSubject : p.status) + "|" + oneLine(p.text, 80)).join("\n");
|
|
635
|
+
}
|
|
636
|
+
if (v.op === "recommend") return "已回写建议:" + v.placement.recommendedSubject + "(" + (v.placement.reason || "无理由") + ");等用户在看板确认。";
|
|
637
|
+
if (v.op === "cancel") return "已取消待写入请求 " + v.placement.id + "。";
|
|
638
|
+
if (!v.placement) return "找不到这条待写入请求。";
|
|
639
|
+
return "待写入请求 " + v.placement.id + ":" + v.placement.status + (v.placement.recommendedSubject ? "|建议 " + v.placement.recommendedSubject : "");
|
|
640
|
+
}
|
|
641
|
+
default:
|
|
642
|
+
return "完成:" + v.action;
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
timeoutMs: 60000,
|
|
647
|
+
async execute(args, exec) {
|
|
648
|
+
const rt = args.__rt;
|
|
649
|
+
const store = rt.open();
|
|
650
|
+
const action = String(args.action);
|
|
651
|
+
if (action === "placement") {
|
|
652
|
+
const op = String(args.op ?? "get");
|
|
653
|
+
if (op === "recommend") {
|
|
654
|
+
const requestId = String(args.requestId ?? "").trim();
|
|
655
|
+
if (!requestId) return { ok: false, error: "placement op=recommend 需要 requestId" };
|
|
656
|
+
if (!args.subject || String(args.subject).trim() === "") return { ok: false, error: "placement op=recommend 需要 subject" };
|
|
657
|
+
const placement = store.placementRecommend(requestId, {
|
|
658
|
+
subject: args.subject,
|
|
659
|
+
title: args.title,
|
|
660
|
+
reason: args.reason,
|
|
661
|
+
});
|
|
662
|
+
return { ok: true, action, op, placement };
|
|
663
|
+
}
|
|
664
|
+
if (op === "cancel") {
|
|
665
|
+
const requestId = String(args.requestId ?? "").trim();
|
|
666
|
+
if (!requestId) return { ok: false, error: "placement op=cancel 需要 requestId" };
|
|
667
|
+
return { ok: true, action, op, placement: store.placementSetStatus(requestId, "cancelled") };
|
|
668
|
+
}
|
|
669
|
+
if (op === "list") {
|
|
670
|
+
return { ok: true, action, op, rows: store.placementList({ limit: args.limit }) };
|
|
671
|
+
}
|
|
672
|
+
const requestId = String(args.requestId ?? "").trim();
|
|
673
|
+
if (!requestId) return { ok: false, error: "placement op=get 需要 requestId" };
|
|
674
|
+
return { ok: true, action, op: "get", placement: store.placementGet(requestId) };
|
|
675
|
+
}
|
|
676
|
+
if (action === "diary") {
|
|
677
|
+
const op = String(args.op ?? "auto");
|
|
678
|
+
const date = args.date && String(args.date).trim() !== "" ? String(args.date).trim() : localDate(store.now());
|
|
679
|
+
const paths = rt.paths ?? {};
|
|
680
|
+
if (op === "auto") {
|
|
681
|
+
const res = store.diaryAuto(date, { force: args.force === true, dbFile: paths.dbFile, agentsPath: paths.agentsPath, scopes: rt.scopesFor(exec, "all").scopes });
|
|
682
|
+
return { ok: true, action, op, date, ...res };
|
|
683
|
+
}
|
|
684
|
+
if (op === "write") {
|
|
685
|
+
if (!args.text || String(args.text).trim() === "") return { ok: false, error: "diary op=write 需要 text" };
|
|
686
|
+
const record = store.diaryAdd(date, String(args.text), String(args.mood ?? "manual"));
|
|
687
|
+
return { ok: true, action, op, date, record };
|
|
688
|
+
}
|
|
689
|
+
if (op === "get") {
|
|
690
|
+
return { ok: true, action, op, date, record: store.diaryGet(date) };
|
|
691
|
+
}
|
|
692
|
+
if (op === "list") {
|
|
693
|
+
const limit = Math.min(Math.max(Number(args.limit) || 20, 1), 366);
|
|
694
|
+
return { ok: true, action, op, rows: store.diaryList(limit) };
|
|
695
|
+
}
|
|
696
|
+
return { ok: false, error: "未知 diary op:" + op };
|
|
697
|
+
}
|
|
698
|
+
if (action === "doctor") {
|
|
699
|
+
const integrity = store.db.prepare("PRAGMA integrity_check").get();
|
|
700
|
+
const integrityText = integrity ? String(Object.values(integrity)[0]) : "unknown";
|
|
701
|
+
let agents;
|
|
702
|
+
try {
|
|
703
|
+
agents = rt.ensureTrunk(exec, { force: true });
|
|
704
|
+
} catch (err) {
|
|
705
|
+
agents = { ok: false, reason: err && err.message ? err.message : String(err) };
|
|
706
|
+
}
|
|
707
|
+
const total = store.count({});
|
|
708
|
+
const missingIndex = Number(
|
|
709
|
+
store.db.prepare("SELECT COUNT(*) c FROM node n WHERE NOT EXISTS (SELECT 1 FROM term t WHERE t.node_id=n.id)").get().c,
|
|
710
|
+
);
|
|
711
|
+
const missingVec = Number(
|
|
712
|
+
store.db.prepare("SELECT COUNT(*) c FROM node n WHERE NOT EXISTS (SELECT 1 FROM vec v WHERE v.node_id=n.id)").get().c,
|
|
713
|
+
);
|
|
714
|
+
const warnings = [];
|
|
715
|
+
if (integrityText !== "ok") warnings.push("SQLite 完整性检查返回 " + integrityText);
|
|
716
|
+
if (missingIndex > 0) warnings.push(missingIndex + " 条缺词项索引,可 reindex");
|
|
717
|
+
if (missingVec > 0) warnings.push(missingVec + " 条缺向量,可 reindex");
|
|
718
|
+
if (!agents.ok) warnings.push("主干同步失败:" + (agents.reason || "未知原因"));
|
|
719
|
+
if (total === 0) warnings.push("库里还没有记忆;可先运行 node bin/mt.mjs demo 看四枝示例,或复制 examples/AGENTS.template.md 后 sync");
|
|
720
|
+
const legacyImported = Boolean(
|
|
721
|
+
store.db.prepare("SELECT 1 AS hit FROM node WHERE uid LIKE 'legacy:%' LIMIT 1").get(),
|
|
722
|
+
);
|
|
723
|
+
const agentsOptional = String(agents.reason || "").includes("主干文件不存在");
|
|
724
|
+
return {
|
|
725
|
+
ok: true,
|
|
726
|
+
action,
|
|
727
|
+
healthy: integrityText === "ok" && missingIndex === 0 && missingVec === 0 && (agents.ok || agentsOptional),
|
|
728
|
+
dbFile: rt.paths.dbFile,
|
|
729
|
+
dbBytes: store.stats().dbBytes,
|
|
730
|
+
integrity: integrityText,
|
|
731
|
+
stats: store.stats(),
|
|
732
|
+
missingIndex,
|
|
733
|
+
missingVec,
|
|
734
|
+
agents: agents.ok ? { ok: true, rules: agents.rules, changed: agents.changed === true } : { ok: false, reason: agents.reason, optional: agentsOptional },
|
|
735
|
+
legacy: { exists: rt.info().legacyExists, path: rt.paths.legacyDb, imported: legacyImported },
|
|
736
|
+
warnings,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
if (action === "stats") return { ok: true, action, stats: store.stats() };
|
|
740
|
+
if (action === "reindex") {
|
|
741
|
+
const nodes = store.reindexAll();
|
|
742
|
+
return { ok: true, action, nodes, indexVersion: store.stats().indexVersion };
|
|
743
|
+
}
|
|
744
|
+
if (action === "export") {
|
|
745
|
+
const text = store.exportJsonl();
|
|
746
|
+
const fs = await import("node:fs");
|
|
747
|
+
const pathMod = await import("node:path");
|
|
748
|
+
const dir = rt.paths.exportDir;
|
|
749
|
+
try {
|
|
750
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
751
|
+
} catch (err) {
|
|
752
|
+
return { ok: false, error: "创建导出目录失败:" + (err && err.message ? err.message : String(err)) };
|
|
753
|
+
}
|
|
754
|
+
const file = args.path && String(args.path).trim() !== ""
|
|
755
|
+
? pathMod.resolve(String(args.path))
|
|
756
|
+
: pathMod.join(dir, "memory-tree-" + new Date().toISOString().replace(/[:.]/g, "-") + ".jsonl");
|
|
757
|
+
if (fs.existsSync(file) && args.overwrite !== true) {
|
|
758
|
+
return { ok: false, error: "目标文件已存在,未覆盖:" + file + "。确需覆盖请传 overwrite:true。" };
|
|
759
|
+
}
|
|
760
|
+
try {
|
|
761
|
+
fs.mkdirSync(pathMod.dirname(file), { recursive: true });
|
|
762
|
+
await writeFileAtomic(file, text);
|
|
763
|
+
} catch (err) {
|
|
764
|
+
return { ok: false, error: "导出写入失败:" + (err && err.message ? err.message : String(err)) };
|
|
765
|
+
}
|
|
766
|
+
const lines = text === "" ? [] : text.trimEnd().split("\n");
|
|
767
|
+
let count = 0;
|
|
768
|
+
let extras = 0;
|
|
769
|
+
for (const line of lines) {
|
|
770
|
+
if (line.trim() === "") continue;
|
|
771
|
+
try {
|
|
772
|
+
const obj = JSON.parse(line);
|
|
773
|
+
if (obj && obj._kind) extras += 1;
|
|
774
|
+
else count += 1;
|
|
775
|
+
} catch {
|
|
776
|
+
count += 1;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return { ok: true, action, path: file, count, extras, bytes: Buffer.byteLength(text, "utf8") };
|
|
780
|
+
}
|
|
781
|
+
if (action === "import") {
|
|
782
|
+
if (!args.path) return { ok: false, error: "import 需要 path(JSONL 文件)" };
|
|
783
|
+
const fs = await import("node:fs");
|
|
784
|
+
const file = String(args.path);
|
|
785
|
+
if (!fs.existsSync(file)) return { ok: false, error: "文件不存在:" + file };
|
|
786
|
+
let stat;
|
|
787
|
+
let text;
|
|
788
|
+
try {
|
|
789
|
+
stat = fs.statSync(file);
|
|
790
|
+
if (stat.size > 50 * 1024 * 1024) return { ok: false, error: "导入文件超过 50 MB,请拆分后再导入。" };
|
|
791
|
+
text = fs.readFileSync(file, "utf8");
|
|
792
|
+
} catch (err) {
|
|
793
|
+
return { ok: false, error: "读取导入文件失败:" + (err && err.message ? err.message : String(err)) };
|
|
794
|
+
}
|
|
795
|
+
try {
|
|
796
|
+
const res = store.importJsonl(text, { mode: args.mode === "update" ? "update" : "merge" });
|
|
797
|
+
try { rt.exportCards(); } catch { /* 快照失败不影响导入结果 */ }
|
|
798
|
+
return { ok: true, action, path: file, ...res };
|
|
799
|
+
} catch (err) {
|
|
800
|
+
return { ok: false, error: "导入失败:" + (err && err.message ? err.message : String(err)) };
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (action === "audit") {
|
|
804
|
+
const limit = Math.min(Math.max(Number(args.limit) || 20, 1), 100);
|
|
805
|
+
return { ok: true, action, rows: store.recentAudit(limit), revisions: store.recentRevisions(Math.min(limit, 20)) };
|
|
806
|
+
}
|
|
807
|
+
if (action === "report") {
|
|
808
|
+
// 离线报告不写入看板令牌:HTML 一旦被分享,令牌不能跟着走。
|
|
809
|
+
const html = buildReportHtml(rt, store, exec, {
|
|
810
|
+
board: { base: "", token: "", sessionId: null },
|
|
811
|
+
});
|
|
812
|
+
const fs = await import("node:fs");
|
|
813
|
+
const pathMod = await import("node:path");
|
|
814
|
+
const file = args.path && String(args.path).trim() !== "" ? pathMod.resolve(String(args.path)) : rt.paths.reportFile;
|
|
815
|
+
if (fs.existsSync(file) && args.overwrite !== true) {
|
|
816
|
+
return { ok: false, error: "目标文件已存在,未覆盖:" + file + "。确需覆盖请传 overwrite:true。" };
|
|
817
|
+
}
|
|
818
|
+
try {
|
|
819
|
+
fs.mkdirSync(pathMod.dirname(file), { recursive: true });
|
|
820
|
+
await writeFileAtomic(file, html);
|
|
821
|
+
} catch (err) {
|
|
822
|
+
return { ok: false, error: "报告写入失败:" + (err && err.message ? err.message : String(err)) };
|
|
823
|
+
}
|
|
824
|
+
return { ok: true, action, path: file, bytes: Buffer.byteLength(html, "utf8"), tokens: estimateTokens(html) };
|
|
825
|
+
}
|
|
826
|
+
return { ok: false, error: "未知 action:" + action };
|
|
827
|
+
},
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
831
|
+
// memory_emotion
|
|
832
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
833
|
+
const emotionTool = {
|
|
834
|
+
name: "memory_emotion",
|
|
835
|
+
description:
|
|
836
|
+
"情感枝日结工具(可选):查看/标记本地采集的候选、看候选统计与日结预算、记录一次日结。候选由插件在会话里按本地规则打分生成(0 token,正文只留节选,默认 30 天清;需先在配置里开启 emotionCapture:true);真正的记忆仍用 memory_write 写,本工具只动候选表与 review 表。日结流程:list 读候选 → memory_write 写 0–6 条 → mark 标记 accepted/dismissed → report 记账。候选不足就少写;写不出第一人称感受的候选宁可不写。",
|
|
837
|
+
parameters: {
|
|
838
|
+
action: { type: "string", enum: ["list", "mark", "stats", "budget", "report"], required: true, description: "list=读候选;mark=标记;stats=统计;budget=看日结预算;report=记录本次日结" },
|
|
839
|
+
day: { type: "string", description: "YYYY-MM-DD,默认今天" },
|
|
840
|
+
status: { type: "string", enum: ["pending", "accepted", "dismissed", "all"], description: "list 用;mark 只接受 accepted/dismissed" },
|
|
841
|
+
limit: { type: "integer", description: "list 返回条数,默认 20,最多 50" },
|
|
842
|
+
ids: { type: "string", description: "mark 用:候选 id,逗号分隔,如「12,13」" },
|
|
843
|
+
nodeIds: { type: "string", description: "mark 用:写入后的 node id,逗号分隔,与 ids 对齐" },
|
|
844
|
+
candidates: { type: "integer", description: "report 用:本次候选数" },
|
|
845
|
+
written: { type: "integer", description: "report 用:写入条数" },
|
|
846
|
+
dismissed: { type: "integer", description: "report 用:丢弃条数" },
|
|
847
|
+
costCny: { type: "number", description: "report 用:本次花费;省略时从账本取本会话花费" },
|
|
848
|
+
tokens: { type: "integer", description: "report 用:本次 token(估算)" },
|
|
849
|
+
note: { type: "string", description: "report 用:一句话备注" },
|
|
850
|
+
},
|
|
851
|
+
output: {
|
|
852
|
+
schema: { type: "json" },
|
|
853
|
+
render(args, v) {
|
|
854
|
+
if (!v || v.ok === false) return "情感日结操作失败:" + (v?.error ?? "未知错误");
|
|
855
|
+
if (v.action === "list") {
|
|
856
|
+
const lines = ["情感候选 " + v.day + ":" + v.count + " 条"];
|
|
857
|
+
for (const r of v.rows) {
|
|
858
|
+
lines.push("#" + r.id + " [" + r.category + " " + r.score + "] " + r.role + ":" + oneLine(r.text, 240));
|
|
859
|
+
if (r.context) lines.push(" 上下文:" + oneLine(r.context, 120));
|
|
860
|
+
if (r.reasons && r.reasons.length) lines.push(" 理由:" + r.reasons.join(";"));
|
|
861
|
+
}
|
|
862
|
+
if (!v.rows.length) lines.push("今天没有候选;可以直接 report 记 0 后结束。");
|
|
863
|
+
return lines.join("\n");
|
|
864
|
+
}
|
|
865
|
+
if (v.action === "mark") {
|
|
866
|
+
return "已标记 " + v.updated + " 条为 " + v.status +
|
|
867
|
+
(v.missing && v.missing.length ? ";未找到 #" + v.missing.join("、#") : "");
|
|
868
|
+
}
|
|
869
|
+
if (v.action === "stats") {
|
|
870
|
+
const cats = Object.entries(v.byCategory || {}).map(([k, n]) => k + " " + n).join("、") || "无";
|
|
871
|
+
const sts = Object.entries(v.byStatus || {}).map(([k, n]) => k + " " + n).join("、") || "无";
|
|
872
|
+
return "候选统计 " + v.day + ":共 " + v.total + " 条(" + cats + ";" + sts + ");近 7 天 " + v.week + " 条。";
|
|
873
|
+
}
|
|
874
|
+
if (v.action === "budget") {
|
|
875
|
+
return "日结预算:" + (v.over ? "已超" : "未超") + ";上限 " + v.capCny + " 元;今日总花费 " +
|
|
876
|
+
v.todayTotalCny + ";本会话 " + v.sessionCostCny + ";今日日结累计 " + v.reviewSpentCny +
|
|
877
|
+
(v.ledger ? "" : "(账本未读到)");
|
|
878
|
+
}
|
|
879
|
+
if (v.action === "report") {
|
|
880
|
+
return "已记录日结 #" + v.review.id + "(" + v.review.day + ");花费 " + v.budget.sessionCostCny + " 元。";
|
|
881
|
+
}
|
|
882
|
+
return "未知 action:" + v.action;
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
timeoutMs: 15000,
|
|
886
|
+
async execute(args, exec) {
|
|
887
|
+
const rt = args.__rt;
|
|
888
|
+
const store = rt.open();
|
|
889
|
+
const action = String(args.action ?? "");
|
|
890
|
+
const day = String(args.day || localDate());
|
|
891
|
+
if (action === "list") {
|
|
892
|
+
const rows = listCandidates(store.db, { day, status: args.status || "pending", limit: args.limit });
|
|
893
|
+
return { ok: true, action, day, rows, count: rows.length };
|
|
894
|
+
}
|
|
895
|
+
if (action === "mark") {
|
|
896
|
+
const ids = parseList(args.ids).map(Number).filter(Number.isFinite);
|
|
897
|
+
const nodeIds = parseList(args.nodeIds).map(Number).filter(Number.isFinite);
|
|
898
|
+
const status = String(args.status || "");
|
|
899
|
+
if (!ids.length) return { ok: false, error: "ids 不能为空" };
|
|
900
|
+
if (status !== "accepted" && status !== "dismissed") {
|
|
901
|
+
return { ok: false, error: "mark 的 status 只能是 accepted / dismissed" };
|
|
902
|
+
}
|
|
903
|
+
const res = markCandidates(store.db, ids, status, nodeIds);
|
|
904
|
+
return { ok: true, action, day, ...res };
|
|
905
|
+
}
|
|
906
|
+
if (action === "stats") {
|
|
907
|
+
return { ok: true, action, ...candidateStats(store.db, day) };
|
|
908
|
+
}
|
|
909
|
+
if (action === "budget") {
|
|
910
|
+
return { ok: true, action, ...budgetFor(rt, exec) };
|
|
911
|
+
}
|
|
912
|
+
if (action === "report") {
|
|
913
|
+
const budget = budgetFor(rt, exec);
|
|
914
|
+
const cost =
|
|
915
|
+
args.costCny === undefined || args.costCny === null || args.costCny === ""
|
|
916
|
+
? budget.sessionCostCny
|
|
917
|
+
: Number(args.costCny);
|
|
918
|
+
const review = recordReview(store.db, {
|
|
919
|
+
day,
|
|
920
|
+
sessionId: sessionIdOf(exec),
|
|
921
|
+
candidates: args.candidates,
|
|
922
|
+
written: args.written,
|
|
923
|
+
dismissed: args.dismissed,
|
|
924
|
+
costCny: cost,
|
|
925
|
+
tokens: args.tokens,
|
|
926
|
+
note: args.note,
|
|
927
|
+
});
|
|
928
|
+
return { ok: true, action, review, budget };
|
|
929
|
+
}
|
|
930
|
+
return { ok: false, error: "未知 action:" + action };
|
|
931
|
+
},
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
export function buildTools(runtime) {
|
|
935
|
+
const specs = [searchTool, writeTool, forgetTool, treeTool, cardTool, ingestTool, dailyTool, adminTool, emotionTool];
|
|
936
|
+
return specs.map((spec) => {
|
|
937
|
+
const rawRender = spec.output.render;
|
|
938
|
+
const wrapped = {
|
|
939
|
+
name: spec.name,
|
|
940
|
+
description: spec.description,
|
|
941
|
+
parameters: spec.parameters,
|
|
942
|
+
output: {
|
|
943
|
+
schema: spec.output.schema,
|
|
944
|
+
// 宿主要求 render 返回内容块数组;内部各 render 仍返回便于阅读的字符串。
|
|
945
|
+
render(args, value) {
|
|
946
|
+
return contentBlocks(rawRender(args, value));
|
|
947
|
+
},
|
|
948
|
+
...(spec.output.presentationMeta ? { presentationMeta: spec.output.presentationMeta } : {}),
|
|
949
|
+
},
|
|
950
|
+
timeoutMs: spec.timeoutMs,
|
|
951
|
+
async execute(args = {}, exec = {}) {
|
|
952
|
+
// 宿主传进来的 args 可能是冻结对象,不能往上挂字段;复制一份再注入运行时。
|
|
953
|
+
runtime.noteExec(exec);
|
|
954
|
+
const call = { ...args, __rt: runtime };
|
|
955
|
+
return spec.execute(call, exec);
|
|
956
|
+
},
|
|
957
|
+
};
|
|
958
|
+
return defineTool(wrapped);
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
export { syncTrunk };
|