dsh-aurorix-agentbook 1.9.4 → 1.9.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/lib/host.js +15 -13
- package/lib/snapshot.js +13 -63
- package/package.json +1 -1
package/lib/host.js
CHANGED
|
@@ -73,18 +73,19 @@ function readConfig(config) {
|
|
|
73
73
|
enabled: get('enabled', true),
|
|
74
74
|
injectSection: get('injectSection', false),
|
|
75
75
|
injectSnapshot: get('injectSnapshot', true),
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
indexCount: Number(get('indexCount', 30)) || 0,
|
|
76
|
+
// 常驻层(soul / profile / explicit)给全量正文,下三层只给标题索引。
|
|
77
|
+
//
|
|
78
|
+
// 体积不从这里省:标题索引是「知道库里有什么」的入口,正文一律走检索。
|
|
79
|
+
// 曾经为了省字节把下三层压成摘要档甚至只留标题,前者等于把同一件事说半遍、
|
|
80
|
+
// 真正要正文时还得 recall;后者在 rules 上会删掉执行必需的标识符。现在
|
|
81
|
+
// 结构上就没有摘要档——要么常驻层全量,要么标题。
|
|
83
82
|
residentLimit: Number(get('residentLimit', 40)) || 40,
|
|
84
|
-
|
|
83
|
+
// 0 = 全部标题。下三层 538 条标题共约 37KB,全给也就这么多;截断反而让
|
|
84
|
+
// 模型以为「库里没有这条」而漏检索。
|
|
85
|
+
indexCount: Number(get('indexCount', 0)),
|
|
85
86
|
decayHalfLifeDays: Number(get('decayHalfLifeDays', 30)),
|
|
86
87
|
accessBoost: Number(get('accessBoost', 80)),
|
|
87
|
-
maxContextBytes: Number(get('maxContextBytes',
|
|
88
|
+
maxContextBytes: Number(get('maxContextBytes', 96000)) || 96000,
|
|
88
89
|
refreshMs: Number(get('refreshMs', 15000)) || 15000,
|
|
89
90
|
toolEnabled: get('toolEnabled', true) !== false,
|
|
90
91
|
commandEnabled: get('commandEnabled', true) !== false,
|
|
@@ -150,11 +151,8 @@ export function attachHost(ctx, deps) {
|
|
|
150
151
|
const doRefresh = async (current) => {
|
|
151
152
|
try {
|
|
152
153
|
const built = await buildSnapshot((plane) => backend.list(plane, { limit: 2000, full: true }), {
|
|
153
|
-
fullCount: current.fullCount,
|
|
154
|
-
briefCount: current.briefCount,
|
|
155
154
|
indexCount: current.indexCount,
|
|
156
155
|
residentLimit: current.residentLimit,
|
|
157
|
-
briefChars: current.briefChars,
|
|
158
156
|
decayHalfLifeDays: current.decayHalfLifeDays,
|
|
159
157
|
accessBoost: current.accessBoost,
|
|
160
158
|
maxContextBytes: current.maxContextBytes,
|
|
@@ -301,7 +299,11 @@ export function attachHost(ctx, deps) {
|
|
|
301
299
|
'- 上下文被压缩过,或这是跨会话续接\n' +
|
|
302
300
|
'- 准备写记忆之前(先查有没有同一条,避免重复开新条)\n' +
|
|
303
301
|
'禁把「这轮简单」「刚聊过」「我应该记得」当跳过理由:漏查的代价是重复踩坑,查一次的代价是一次工具调用。\n' +
|
|
304
|
-
'
|
|
302
|
+
'检索词用话题词,不要用整句;推荐先广后窄:先一个词看面上有什么,再收窄。\n' +
|
|
303
|
+
'\n' +
|
|
304
|
+
'注入的快照里下三层(rules / long_term / episodic)只有标题,正文不注入。\n' +
|
|
305
|
+
'看到相关标题后要正文,用 `aurorix_abook` 按 ID 取:`["memory","read","--id","<id>","--json"]`。\n' +
|
|
306
|
+
'本工具返回的 preview 只截前 220 字,够判断是不是这条,不够当正文用。',
|
|
305
307
|
parameters: {
|
|
306
308
|
type: 'object',
|
|
307
309
|
properties: {
|
package/lib/snapshot.js
CHANGED
|
@@ -21,11 +21,6 @@ const PLANE_LABEL = {
|
|
|
21
21
|
// 排序基准:身份/规则/偏好在最前,经验其次,过程记录最轻。
|
|
22
22
|
const PLANE_BASE = { soul: 1000, rules: 900, profile: 800, explicit: 700, long_term: 300, episodic: 120 }
|
|
23
23
|
|
|
24
|
-
// 约束类永不完全淡出:最低保到摘要档,避免规则被排到只剩标题。
|
|
25
|
-
const PLANE_FLOOR = { rules: 'brief' }
|
|
26
|
-
|
|
27
|
-
const TIER_ORDER = { index: 0, brief: 1, full: 2 }
|
|
28
|
-
|
|
29
24
|
// 每步注入的记忆说明:只在装了本插件的环境里出现。
|
|
30
25
|
// 系统提示词里不再提记忆——没装插件的环境本就没有这个能力,不该被暗示。
|
|
31
26
|
//
|
|
@@ -146,27 +141,6 @@ function scoreOf(record, access, now, halfLifeDays, accessBoost) {
|
|
|
146
141
|
return base + boost - decay
|
|
147
142
|
}
|
|
148
143
|
|
|
149
|
-
// 规则条数多、密度高,摘要短一点就够认出是哪条;其余平面给足上下文。
|
|
150
|
-
// rules 用 0 表示「摘要档只列标题」:规则标题平均 40 字节,本身已经把规则说清楚了,
|
|
151
|
-
// 再附一段正文摘要等于同一条信息说两遍,白占 19KB/轮。
|
|
152
|
-
const BRIEF_CHARS_BY_PLANE = { rules: 0 }
|
|
153
|
-
|
|
154
|
-
function renderTier(record, tier, briefChars) {
|
|
155
|
-
const limit = BRIEF_CHARS_BY_PLANE[record.plane] ?? briefChars
|
|
156
|
-
const title = record.title || '(无标题)'
|
|
157
|
-
const content = String(record.content || '').trim()
|
|
158
|
-
if (tier === 'full') return `- 【${title}】${content}`
|
|
159
|
-
if (tier === 'brief') {
|
|
160
|
-
// 限额为 0:标题即摘要。不附正文,也不附结构目录(同一个道理,标题已经说明是什么)。
|
|
161
|
-
if (limit <= 0) return `- ${title}`
|
|
162
|
-
const gist = gistOf(content, limit)
|
|
163
|
-
const heads = headingsOf(content)
|
|
164
|
-
const structure = heads.length > 1 ? `\n └ ${heads.slice(0, 5).join(' / ')}` : ''
|
|
165
|
-
return `- 【${title}】${gist}${structure}`
|
|
166
|
-
}
|
|
167
|
-
return title
|
|
168
|
-
}
|
|
169
|
-
|
|
170
144
|
/** 热度状态:记录哪个 ID 被真正用过。只影响排序,不影响库。 */
|
|
171
145
|
export function createAccessStore(statePath) {
|
|
172
146
|
let store = { version: 1, records: {} }
|
|
@@ -275,11 +249,8 @@ export function librarySignature(root) {
|
|
|
275
249
|
*/
|
|
276
250
|
export async function buildSnapshot(listPlane, options = {}) {
|
|
277
251
|
const {
|
|
278
|
-
|
|
279
|
-
briefCount = 12,
|
|
280
|
-
indexCount = 120,
|
|
252
|
+
indexCount = 0, // 0 = 全部标题,不截断
|
|
281
253
|
residentLimit = 40,
|
|
282
|
-
briefChars = 140,
|
|
283
254
|
decayHalfLifeDays = 30,
|
|
284
255
|
accessBoost = 80,
|
|
285
256
|
access = { records: () => ({}) },
|
|
@@ -306,6 +277,7 @@ export async function buildSnapshot(listPlane, options = {}) {
|
|
|
306
277
|
const accessMap = access.records()
|
|
307
278
|
const now = Math.floor(Date.now() / 1000)
|
|
308
279
|
|
|
280
|
+
// 常驻层:全量正文。这几层是身份、画像和用户明确交代的短要点,每轮都该看得见全文。
|
|
309
281
|
const resident = RESIDENT_PLANES.map((plane) => {
|
|
310
282
|
const rows = records.filter((r) => r.plane === plane).slice(0, residentLimit)
|
|
311
283
|
if (rows.length === 0) return ''
|
|
@@ -313,6 +285,12 @@ export async function buildSnapshot(listPlane, options = {}) {
|
|
|
313
285
|
return `**${PLANE_LABEL[plane]}**(${rows.length} 条)\n${body}`
|
|
314
286
|
}).filter(Boolean).join('\n\n')
|
|
315
287
|
|
|
288
|
+
// 下三层:只给标题索引,一条正文都不注入。
|
|
289
|
+
//
|
|
290
|
+
// 之前把这里做成「前几条全量 + 一批摘要 + 其余标题」的三档,摘要档吃掉 26.9KB,
|
|
291
|
+
// 而摘要的价值很低——标题本来就说清了「这条讲什么」,摘要只是把同一件事再说半遍;
|
|
292
|
+
// 真正要正文的时候一定会去 recall,注入的摘要在那一刻也用不上。
|
|
293
|
+
// 只留标题后:体积降下来,语义也干净——注入负责「知道有什么」,检索负责「读什么」。
|
|
316
294
|
const decay = records
|
|
317
295
|
.filter((r) => DECAY_PLANES.includes(r.plane))
|
|
318
296
|
.map((r) => ({ record: r, score: scoreOf(r, accessMap[r.id], now, decayHalfLifeDays, accessBoost) }))
|
|
@@ -320,40 +298,18 @@ export async function buildSnapshot(listPlane, options = {}) {
|
|
|
320
298
|
// 而输入顺序一变快照就变、又会让上下文多一份副本。ID 是稳定的。
|
|
321
299
|
.sort((a, b) => b.score - a.score || String(a.record.id).localeCompare(String(b.record.id)))
|
|
322
300
|
|
|
323
|
-
const tiers = new Map()
|
|
324
|
-
decay.forEach((entry, index) => {
|
|
325
|
-
let tier = index < fullCount ? 'full' : index < fullCount + briefCount ? 'brief' : 'index'
|
|
326
|
-
const floor = PLANE_FLOOR[entry.record.plane]
|
|
327
|
-
if (floor && TIER_ORDER[tier] < TIER_ORDER[floor]) tier = floor
|
|
328
|
-
tiers.set(entry.record.id, tier)
|
|
329
|
-
})
|
|
330
|
-
|
|
331
|
-
const fullRows = []
|
|
332
|
-
const briefByPlane = new Map()
|
|
333
301
|
const indexByPlane = new Map()
|
|
334
302
|
for (const entry of decay) {
|
|
335
|
-
const tier = tiers.get(entry.record.id)
|
|
336
303
|
const record = entry.record
|
|
337
|
-
if (
|
|
338
|
-
|
|
339
|
-
if (!briefByPlane.has(record.plane)) briefByPlane.set(record.plane, [])
|
|
340
|
-
briefByPlane.get(record.plane).push(renderTier(record, 'brief', briefChars))
|
|
341
|
-
} else {
|
|
342
|
-
if (!indexByPlane.has(record.plane)) indexByPlane.set(record.plane, [])
|
|
343
|
-
indexByPlane.get(record.plane).push(record.title || '(无标题)')
|
|
344
|
-
}
|
|
304
|
+
if (!indexByPlane.has(record.plane)) indexByPlane.set(record.plane, [])
|
|
305
|
+
indexByPlane.get(record.plane).push(record.title || '(无标题)')
|
|
345
306
|
}
|
|
346
307
|
|
|
347
|
-
const briefBlock = DECAY_PLANES
|
|
348
|
-
.filter((plane) => briefByPlane.has(plane))
|
|
349
|
-
.map((plane) => `**${PLANE_LABEL[plane]}**\n${briefByPlane.get(plane).join('\n')}`)
|
|
350
|
-
.join('\n\n')
|
|
351
|
-
|
|
352
308
|
const indexBlock = DECAY_PLANES
|
|
353
309
|
.filter((plane) => indexByPlane.has(plane))
|
|
354
310
|
.map((plane) => {
|
|
355
311
|
const titles = indexByPlane.get(plane)
|
|
356
|
-
const shown = titles.slice(0, indexCount)
|
|
312
|
+
const shown = indexCount > 0 ? titles.slice(0, indexCount) : titles
|
|
357
313
|
const rest = titles.length - shown.length
|
|
358
314
|
return `**${PLANE_LABEL[plane]}**(${titles.length} 条):${shown.join(' | ')}${rest > 0 ? ` …另有 ${rest} 条` : ''}`
|
|
359
315
|
})
|
|
@@ -362,11 +318,7 @@ export async function buildSnapshot(listPlane, options = {}) {
|
|
|
362
318
|
const parts = [
|
|
363
319
|
'### 常驻层(永久全量:soul / profile / explicit)',
|
|
364
320
|
resident,
|
|
365
|
-
|
|
366
|
-
fullRows.join('\n'),
|
|
367
|
-
briefBlock ? '### 摘要(原文在库里,需要细节就检索)' : '',
|
|
368
|
-
briefBlock,
|
|
369
|
-
indexBlock ? '### 可召回索引(仅标题,用 aurorix_recall 取正文)' : '',
|
|
321
|
+
indexBlock ? '### 可召回索引(仅标题;正文用 aurorix_abook ["memory","read","--id","<id>","--json"] 取)' : '',
|
|
370
322
|
indexBlock,
|
|
371
323
|
].filter((part) => part && part.length > 0)
|
|
372
324
|
|
|
@@ -375,9 +327,7 @@ export async function buildSnapshot(listPlane, options = {}) {
|
|
|
375
327
|
stats: {
|
|
376
328
|
total: records.length,
|
|
377
329
|
resident: records.filter((r) => RESIDENT_PLANES.includes(r.plane)).length,
|
|
378
|
-
|
|
379
|
-
brief: [...tiers.values()].filter((t) => t === 'brief').length,
|
|
380
|
-
index: [...tiers.values()].filter((t) => t === 'index').length,
|
|
330
|
+
index: records.filter((r) => DECAY_PLANES.includes(r.plane)).length,
|
|
381
331
|
},
|
|
382
332
|
}
|
|
383
333
|
}
|
package/package.json
CHANGED