dsh-prime-memory 0.18.5 → 0.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -28
- package/dist/contract.d.ts +1 -109
- package/dist/hooks/recall.d.ts +1 -4
- package/dist/hooks/recall.js +1 -7
- package/dist/hooks/slot-recall.js +24 -1
- package/dist/index.js +4 -14
- package/dist/metadata-validators.d.ts +0 -5
- package/dist/metadata-validators.js +1 -11
- package/dist/pipeline/ruminate.d.ts +1 -11
- package/dist/pipeline/ruminate.js +1 -18
- package/dist/projection/slots.js +9 -14
- package/dist/stats.d.ts +2 -26
- package/dist/stats.js +13 -261
- package/dist/store/l1.d.ts +0 -34
- package/dist/store/l1.js +1 -68
- package/dist/store/sqlite.d.ts +0 -4
- package/dist/store/sqlite.js +0 -20
- package/dist/tools/index.d.ts +1 -4
- package/dist/tools/index.js +2 -224
- package/dist/types.d.ts +0 -4
- package/package.json +1 -1
- package/dist/client.js +0 -6274
- package/dist/config.d.ts +0 -1407
- package/dist/embedding-worker.cjs +0 -176
- package/dist/index.d.ts +0 -999
- package/dist/room-review.d.ts +0 -196
- package/dist/room-review.js +0 -281
- package/dist/runtime-package-lock.json +0 -982
- package/dist/store/recall-usage.d.ts +0 -43
- package/dist/store/recall-usage.js +0 -149
- package/dist/store/rooms-registry.d.ts +0 -66
- package/dist/store/rooms-registry.js +0 -250
package/dist/tools/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { RECEIPTS_QUERY_LIMIT_MAX, dimensionOf, toReceiptView } from '../store/r
|
|
|
3
3
|
import { listConflictPairs, renderConflictResolution, renderConflicts, resolveConflictPair } from '../conflict-service.js';
|
|
4
4
|
import { WING_CATALOG, WING_FALLBACK, normPersistence, normScope, resolveRecordScope } from '../types.js';
|
|
5
5
|
import { scopeFilterOf, workspaceIdOf } from '../workspace.js';
|
|
6
|
-
import { annotateOrphanCandidates, confirmReview, mergeRoom, nextReview, pendingReviewCount, renameRoom, skipReview, } from '../room-review.js';
|
|
7
6
|
import { GRAPH_STATUS_LABELS } from '../prompts/graph-projection.js';
|
|
8
7
|
import { redactSecrets } from '../util/redact.js';
|
|
9
8
|
const OFF_NOTICE = '本会话的记忆档位为"关闭":该会话对记忆系统完全隐身,不读取也不写入记忆。';
|
|
@@ -31,9 +30,7 @@ function applyManualRedaction(record, cfg, logger) {
|
|
|
31
30
|
}
|
|
32
31
|
export function registerMemoryTools(ctx, cfg, stores, logger, modes, live,
|
|
33
32
|
/** 反刍控制器(可选:未装配时 ruminate 工具返回未启用提示)。 */
|
|
34
|
-
ruminate
|
|
35
|
-
/** Room 注册表(分类管理 beta.4;缺省 = memory_room_admin 返回未装配提示)。 */
|
|
36
|
-
roomRegistry) {
|
|
33
|
+
ruminate) {
|
|
37
34
|
if (!cfg.tools)
|
|
38
35
|
return;
|
|
39
36
|
/**
|
|
@@ -133,6 +130,7 @@ roomRegistry) {
|
|
|
133
130
|
items: {
|
|
134
131
|
type: 'object',
|
|
135
132
|
properties: {
|
|
133
|
+
id: { type: 'string', description: 'L1 record_id:可写入槽位 refs 或喂给 memory_receipts' },
|
|
136
134
|
content: { type: 'string' },
|
|
137
135
|
type: { type: 'string' },
|
|
138
136
|
scene_name: { type: 'string' },
|
|
@@ -171,145 +169,6 @@ roomRegistry) {
|
|
|
171
169
|
};
|
|
172
170
|
},
|
|
173
171
|
}));
|
|
174
|
-
// ── memory_room_admin: Room 粒度目录治理(分类管理 beta.4;beta.5 起 merge/rename/retire 已注册) ──
|
|
175
|
-
// list 免预算零风险;merge/rename/retire 走 dryRun 预览→实跑,执行前自动备份,完成入队场景重算。
|
|
176
|
-
ctx.tools.register(defineTool({
|
|
177
|
-
name: 'memory_room_admin',
|
|
178
|
-
description: 'Room 分类管理(目录粒度)。action="list" 列出注册表条目与自生长 Room 计数;' +
|
|
179
|
-
'action="register" 预注册一个 Room(高权限;两级制——大类上限 200,小类用「大类/小类」细分不占额度,如 dsh-plugin/merge;' +
|
|
180
|
-
'action="merge" 合并两个 Room(高权限;dryRun 默认 true 只返预览,实跑改写全部匹配记录的 tags 并入队场景重算,执行前自动备份);' +
|
|
181
|
-
'action="rename" 改名(= merge 1:1 + 注册表改名);action="retire" 退役一个注册 Room(高权限;存量记录不动)。' +
|
|
182
|
-
'merge/rename 与反刍并发会相互覆盖,请在反刍空闲时执行。',
|
|
183
|
-
parameters: {
|
|
184
|
-
action: { type: 'string', required: true, description: 'list | register(高权限) | merge(高权限) | rename(高权限) | retire(高权限)' },
|
|
185
|
-
slug: { type: 'string', description: 'register 的 Room slug(小写字母数字连字符)' },
|
|
186
|
-
label: { type: 'string', description: 'register 的人类可读名(可选,可中文)' },
|
|
187
|
-
description: { type: 'string', description: 'register 的归类说明(可选;喂给标注器帮助归类)' },
|
|
188
|
-
from: { type: 'string', description: 'merge/rename 的源 Room slug' },
|
|
189
|
-
to: { type: 'string', description: 'merge/rename 的目标 Room slug' },
|
|
190
|
-
dryRun: { type: 'string', description: 'merge/rename:默认 true 只返预览;"false" 才实际执行' },
|
|
191
|
-
},
|
|
192
|
-
output: {
|
|
193
|
-
schema: {
|
|
194
|
-
type: 'object',
|
|
195
|
-
properties: {
|
|
196
|
-
notice: { type: 'string' },
|
|
197
|
-
rooms: { type: 'string' },
|
|
198
|
-
slug: { type: 'string' },
|
|
199
|
-
created: { type: 'boolean' },
|
|
200
|
-
},
|
|
201
|
-
additionalProperties: false,
|
|
202
|
-
},
|
|
203
|
-
render: (_args, value) => [{ type: 'text', text: value.notice ?? JSON.stringify(value) }],
|
|
204
|
-
},
|
|
205
|
-
execute: async (args) => {
|
|
206
|
-
const action = String(args.action ?? '');
|
|
207
|
-
if (action === 'list') {
|
|
208
|
-
if (!roomRegistry)
|
|
209
|
-
return { notice: 'Room 注册表未装配(需要插件重载以初始化)。' };
|
|
210
|
-
const registry = roomRegistry.list();
|
|
211
|
-
const counts = stores.l1.listRooms();
|
|
212
|
-
const countOf = (slug) => counts.find((r) => r.room === slug)?.count ?? 0;
|
|
213
|
-
const regLines = registry.map((e) => `- ${e.slug}${e.label ? `(${e.label})` : ''} [${e.source}/${e.status}] 现有 ${countOf(e.slug)} 条${e.description ? ` — ${e.description}` : ''}`);
|
|
214
|
-
const grownOnly = counts.filter((r) => !registry.some((e) => e.slug === r.room));
|
|
215
|
-
return {
|
|
216
|
-
notice: `注册表 ${registry.length} 条(上限 200),自生长未注册 ${grownOnly.length} 个。\n` +
|
|
217
|
-
(regLines.join('\n') || '(注册表为空——用 action=register 预注册)') +
|
|
218
|
-
`\n自生长未注册:${grownOnly.map((r) => `${r.room}(${r.count})`).join(", ") || "无"}`,
|
|
219
|
-
rooms: `${registry.length}+${grownOnly.length}`,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
if (action === 'register') {
|
|
223
|
-
if (!roomRegistry)
|
|
224
|
-
return { notice: 'Room 注册表未装配(需要插件重载以初始化)。' };
|
|
225
|
-
if (!live.get().memoryMutate)
|
|
226
|
-
return { notice: MUTATE_OFF_NOTICE };
|
|
227
|
-
const slug = String(args.slug ?? '').trim();
|
|
228
|
-
try {
|
|
229
|
-
const r = await roomRegistry.register({
|
|
230
|
-
slug,
|
|
231
|
-
label: typeof args.label === 'string' ? args.label : undefined,
|
|
232
|
-
description: typeof args.description === 'string' ? args.description : undefined,
|
|
233
|
-
});
|
|
234
|
-
return {
|
|
235
|
-
notice: r.created
|
|
236
|
-
? `已预注册 Room:${r.entry.slug}${r.entry.label ? `(${r.entry.label})` : ''}。候选标注器将优先把相关记忆挂到它上面。`
|
|
237
|
-
: `Room 已存在:${r.entry.slug}(本次只补全了缺失的 label/description)。`,
|
|
238
|
-
slug: r.entry.slug,
|
|
239
|
-
created: r.created,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
catch (err) {
|
|
243
|
-
return { notice: `注册失败: ${err instanceof Error ? err.message : String(err)}` };
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (action === 'update') {
|
|
247
|
-
if (!roomRegistry)
|
|
248
|
-
return { notice: 'Room 注册表未装配(需要插件重载以初始化)。' };
|
|
249
|
-
if (!live.get().memoryMutate)
|
|
250
|
-
return { notice: MUTATE_OFF_NOTICE };
|
|
251
|
-
const slug = String(args.slug ?? '').trim();
|
|
252
|
-
if (!slug)
|
|
253
|
-
return { notice: 'update 需要 slug。' };
|
|
254
|
-
try {
|
|
255
|
-
const ok = await roomRegistry.update(slug, {
|
|
256
|
-
label: typeof args.label === 'string' ? args.label : undefined,
|
|
257
|
-
description: typeof args.description === 'string' ? args.description : undefined,
|
|
258
|
-
});
|
|
259
|
-
return { notice: ok ? `已更新:${slug}(显示名/归类说明)。` : `无变化:${slug} 未找到或未提供非空字段。`, slug };
|
|
260
|
-
}
|
|
261
|
-
catch (err) {
|
|
262
|
-
return { notice: `更新失败: ${err instanceof Error ? err.message : String(err)}` };
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (action === 'merge' || action === 'rename') {
|
|
266
|
-
if (!roomRegistry)
|
|
267
|
-
return { notice: 'Room 注册表未装配(需要插件重载以初始化)。' };
|
|
268
|
-
if (!live.get().memoryMutate)
|
|
269
|
-
return { notice: MUTATE_OFF_NOTICE };
|
|
270
|
-
const from = String(args.from ?? '').trim();
|
|
271
|
-
const to = String(args.to ?? '').trim();
|
|
272
|
-
if (!from || !to)
|
|
273
|
-
return { notice: 'merge/rename 需要 from 与 to 两个 slug。' };
|
|
274
|
-
const dryRun = String(args.dryRun ?? 'true').toLowerCase() !== 'false';
|
|
275
|
-
try {
|
|
276
|
-
const fn = action === 'merge' ? mergeRoom : renameRoom;
|
|
277
|
-
const r = await fn({ l1: stores.l1, registry: roomRegistry, logger }, from, to, { dryRun });
|
|
278
|
-
if (r.dryRun) {
|
|
279
|
-
return {
|
|
280
|
-
notice: `[dryRun 预览] ${from} → ${to}:影响 ${r.affected} 条${r.hasMore ? '(超过单次上限,需续跑)' : ''}。` +
|
|
281
|
-
`样例:${r.preview.join(', ') || '无'}。确认无误后以 dryRun="false" 执行(执行前自动备份,重写含已退场行,完成后自动入队场景重算)。`,
|
|
282
|
-
affected: r.affected,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
notice: `${action === 'merge' ? '合并' : '改名'}完成:${from} → ${to},重写 ${r.applied} 条` +
|
|
287
|
-
`(备份:${r.backupFile ?? '无'})。`,
|
|
288
|
-
applied: r.applied,
|
|
289
|
-
id: to,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
catch (err) {
|
|
293
|
-
return { notice: `${action} 失败: ${err instanceof Error ? err.message : String(err)}` };
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
if (action === 'retire') {
|
|
297
|
-
if (!roomRegistry)
|
|
298
|
-
return { notice: 'Room 注册表未装配(需要插件重载以初始化)。' };
|
|
299
|
-
if (!live.get().memoryMutate)
|
|
300
|
-
return { notice: MUTATE_OFF_NOTICE };
|
|
301
|
-
const slug = String(args.slug ?? '').trim();
|
|
302
|
-
try {
|
|
303
|
-
const ok = await roomRegistry.setStatus(slug, 'retired');
|
|
304
|
-
return { notice: ok ? `已退役 Room:${slug}(存量记录的 tags 不动,仅词表不再推荐)。` : `未找到注册条目:${slug}(自生长 Room 无需退役,会随 tags 自然消失)。`, slug };
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
return { notice: `退役失败: ${err instanceof Error ? err.message : String(err)}` };
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return { notice: `非法 action:${action}(允许 list/register/merge/rename/retire)。` };
|
|
311
|
-
},
|
|
312
|
-
}));
|
|
313
172
|
// ── conversation_search: L0 原始对话 ──
|
|
314
173
|
ctx.tools.register(defineTool({
|
|
315
174
|
name: 'conversation_search',
|
|
@@ -906,87 +765,6 @@ roomRegistry) {
|
|
|
906
765
|
},
|
|
907
766
|
}));
|
|
908
767
|
// ── 反刍状态查询(查看当前反刍进度) ──
|
|
909
|
-
// ── memory_room_review:孤儿记忆的 Room 候选逐个复查(agent 长尾治理)──────
|
|
910
|
-
// next/annotate 只读或预算内标注(无需门);confirm/skip 改写 metadata,
|
|
911
|
-
// confirm 吃 live.memoryMutate 高权限门(与 memory_delete 同款)。
|
|
912
|
-
ctx.tools.register(defineTool({
|
|
913
|
-
name: 'memory_room_review',
|
|
914
|
-
description: '孤儿记忆(无 Room 绑定)的逐个复查:action="next" 取下一条待复查记录(带系统预标记的候选 Room 与现有词表,agent 依据记录内容判定);' +
|
|
915
|
-
'action="confirm" 按 id 把 1-3 个 Room slug 写入该记忆(高权限);action="skip" 跳过(不再进队列);' +
|
|
916
|
-
'action="annotate" 立即对一批孤儿做候选预标记(平时由反刍自动推进)。建议长会话空闲时逐个过,保持分类收敛——优先挂靠现有 Room。',
|
|
917
|
-
parameters: {
|
|
918
|
-
action: { type: 'string', required: true, description: 'next(取下一条)| confirm(确认写入)| skip(跳过)| annotate(批量预标记)' },
|
|
919
|
-
id: { type: 'string', description: 'confirm/skip 的目标记录 id(action=next 返回的 id)' },
|
|
920
|
-
rooms: { type: 'string', description: 'confirm 的 Room slug 列表(逗号分隔,1-3 个,小写字母数字连字符;可含词表外新 slug)' },
|
|
921
|
-
},
|
|
922
|
-
output: {
|
|
923
|
-
schema: {
|
|
924
|
-
type: 'object',
|
|
925
|
-
properties: {
|
|
926
|
-
notice: { type: 'string' },
|
|
927
|
-
id: { type: 'string' },
|
|
928
|
-
content: { type: 'string' },
|
|
929
|
-
candidates: { type: 'string' },
|
|
930
|
-
roomCatalog: { type: 'string' },
|
|
931
|
-
remaining: { type: 'number' },
|
|
932
|
-
confirmedTags: { type: 'string' },
|
|
933
|
-
annotated: { type: 'number' },
|
|
934
|
-
deferred: { type: 'number' },
|
|
935
|
-
},
|
|
936
|
-
additionalProperties: false,
|
|
937
|
-
},
|
|
938
|
-
render: (_args, value) => [{ type: 'text', text: value.notice ?? JSON.stringify(value) }],
|
|
939
|
-
},
|
|
940
|
-
execute: async (args) => {
|
|
941
|
-
const action = String(args.action ?? '');
|
|
942
|
-
const io = { l1: stores.l1, logger };
|
|
943
|
-
if (action === 'next') {
|
|
944
|
-
const item = nextReview(io.l1);
|
|
945
|
-
if (!item)
|
|
946
|
-
return { notice: '没有待复查的孤儿记忆(roomCandidates 队列为空)。可用 action=annotate 先做一轮候选预标记。' };
|
|
947
|
-
return {
|
|
948
|
-
id: item.id,
|
|
949
|
-
content: item.content,
|
|
950
|
-
candidates: item.candidates.join(', '),
|
|
951
|
-
roomCatalog: item.roomCatalog.map((r) => `${r.room}(${r.count})`).join(', '),
|
|
952
|
-
remaining: item.remaining,
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
if (action === 'annotate') {
|
|
956
|
-
const r = await annotateOrphanCandidates(ctx, cfg, { ...io, registry: roomRegistry }, 40);
|
|
957
|
-
return {
|
|
958
|
-
notice: `候选预标记完成:选中 ${r.selected} 条,产候选 ${r.candidates} 条,写 pending ${r.written} 条。用 action=next 逐个复查。`,
|
|
959
|
-
annotated: r.candidates,
|
|
960
|
-
deferred: r.selected - r.written,
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
if (action === 'confirm') {
|
|
964
|
-
if (!live.get().memoryMutate)
|
|
965
|
-
return { notice: MUTATE_OFF_NOTICE };
|
|
966
|
-
const id = String(args.id ?? '').trim();
|
|
967
|
-
if (!id)
|
|
968
|
-
return { notice: 'confirm 需要 id(action=next 返回的 id)。' };
|
|
969
|
-
const rooms = String(args.rooms ?? '')
|
|
970
|
-
.split(/[,,、]/)
|
|
971
|
-
.map((x) => x.trim())
|
|
972
|
-
.filter(Boolean);
|
|
973
|
-
if (rooms.length === 0)
|
|
974
|
-
return { notice: 'confirm 需要 rooms(逗号分隔的 1-3 个 Room slug)。' };
|
|
975
|
-
const r = confirmReview(io.l1, id, rooms);
|
|
976
|
-
if (!r)
|
|
977
|
-
return { notice: `确认失败:id=${id} 不存在、已被确认过、或 rooms 全部非法(需 1-3 个合法 slug)。` };
|
|
978
|
-
return { notice: `已挂到 Room:${r.tags.join(', ')}(面板下一次刷新即可见)。`, confirmedTags: r.tags.join(', '), id };
|
|
979
|
-
}
|
|
980
|
-
if (action === 'skip') {
|
|
981
|
-
const id = String(args.id ?? '').trim();
|
|
982
|
-
if (!id)
|
|
983
|
-
return { notice: 'skip 需要 id。' };
|
|
984
|
-
const ok = skipReview(io.l1, id);
|
|
985
|
-
return { notice: ok ? `已跳过 ${id}(不再进复查队列)。` : `跳过失败:id=${id} 不存在。`, id };
|
|
986
|
-
}
|
|
987
|
-
return { notice: `非法 action:${action}(允许 next/confirm/skip/annotate)。剩余待复查 ${pendingReviewCount(stores.l1)} 条。` };
|
|
988
|
-
},
|
|
989
|
-
}));
|
|
990
768
|
ctx.tools.register(defineTool({
|
|
991
769
|
name: 'memory_ruminate_status',
|
|
992
770
|
description: '查询当前记忆反刍的状态与进度(是否运行中、当前阶段、已完成/总会话数等)。\n\n注意:在 DSH Web GUI 的对话中无法直接调用此工具,因为模型可调用工具列表不包含 ruminate_status。如需查询进度,请在记忆库面板的蒸馏面板查看。',
|
package/dist/types.d.ts
CHANGED
|
@@ -41,10 +41,6 @@ export interface RoomCount {
|
|
|
41
41
|
room: string;
|
|
42
42
|
/** 该 Room 下的记录数(与 `wingL1Counts()` 同口径:含 retired 行)。 */
|
|
43
43
|
count: number;
|
|
44
|
-
/** 来源标示(rooms-get 端点层合并注册表后附带;'grown' = 自生长,可缺省)。 */
|
|
45
|
-
source?: 'pre-registered' | 'grown';
|
|
46
|
-
/** 人类可读名(注册表条目才有;面板 chip 可用 label 展示)。 */
|
|
47
|
-
label?: string;
|
|
48
44
|
}
|
|
49
45
|
/** 记录族标签推断:work_* 前缀 → work,其余(含 auto 档兜底)→ chat。 */
|
|
50
46
|
export declare function familyForType(type: string): MemoryFamily;
|