dsh-aurorix-agentbook 1.12.0 → 1.12.1

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/README.md CHANGED
@@ -38,14 +38,7 @@ Harness Web 上,顶部右侧那组操作按钮里会多一个记忆库按钮
38
38
  `abook memory themes` 聚成主题簇,同一主题的若干条折成一个标签加条数;
39
39
  - 没折进簇的条目逐条列标题,一条都不会消失。
40
40
 
41
- 主题簇的标签后面带簇 id,例如 `环境变量·库根·程序×3#theme-3f9a1c07d2b4`。
42
- 想看这一簇到底有哪几条:
43
-
44
- ```json
45
- ["theme-members", "--algorithm", "aplusplus", "--input", "title", "--cluster", "theme-3f9a1c07d2b4", "--json"]
46
- ```
47
-
48
- 这条走的是簇 id,不是关键词检索,所以不受召回率影响:簇里有几条就展开几条。
41
+ 快照里每个主题带短编号,展开命令也印在同一份快照里。把其中的「编号」替换成 `#` 后的数字,交给 `aurorix_abook`。它精确返回该簇的成员,不走关键词召回;若快照已变更,旧编号会明确报失效。
49
42
 
50
43
  在默认配置下,主题簇直接替换模型快照里的一组标题,不需要另开面板。跨平面的主题放在共同的句云区;未折叠的记录仍在各自平面逐条列出。主题过时或使用不带该能力的自定义后端时,可用普通召回找原文。
51
44
 
package/lib/host.js CHANGED
@@ -56,7 +56,7 @@ import {
56
56
  resolveStatePath,
57
57
  librarySignature,
58
58
  } from './snapshot.js'
59
- import { createThemeClient } from './theme.js'
59
+ import { createThemeClient, SNAPSHOT_THEME_ARGS } from './theme.js'
60
60
  import { GUIDE, GUIDE_INDEX } from './guide.js'
61
61
  import { CURATION_MANUAL } from './curation.js'
62
62
  import { COMMAND_GROUPS, capabilityText, describeAll, driftOf } from './capability.js'
@@ -168,6 +168,7 @@ export function attachHost(ctx, deps) {
168
168
  })
169
169
  snapshot.text = built.text
170
170
  snapshot.stats = built.stats
171
+ snapshot.themeRefs = built.themeRefs
171
172
  snapshot.error = ''
172
173
  snapshot.fetchedAt = Date.now()
173
174
  // 记下这份文本对应的库指纹:下次库没变就不用重建。
@@ -451,7 +452,16 @@ export function attachHost(ctx, deps) {
451
452
  }
452
453
  // `capability` 不是 abook 的子命令,是插件的内置能力地图:
453
454
  // 直接调用会被 abook 判成未知命令,所以在这里先拦下来。
454
- const argv = Array.isArray(args.argv) ? args.argv.map((x) => String(x)) : []
455
+ let argv = Array.isArray(args.argv) ? args.argv.map((x) => String(x)) : []
456
+ if (argv[0] === 'theme-open') {
457
+ const refs = snapshot.themeRefs
458
+ if (argv.length !== 3 || !/^[1-9][0-9]*$/.test(argv[2])) {
459
+ return { code: 2, text: '用法:theme-open <快照标识> <主题编号>' }
460
+ }
461
+ const id = refs?.stamp === argv[1] ? refs.ids[Number(argv[2]) - 1] : undefined
462
+ if (id === undefined) return { code: 3, text: '主题编号已失效或不存在。请用当前快照的编号,或调用 memory themes 获取最新主题。' }
463
+ argv = ['theme-members', ...SNAPSHOT_THEME_ARGS, '--cluster', id, '--json']
464
+ }
455
465
  if (argv[0] === 'capability' || argv[0] === 'capabilities' || argv[0] === '地图') {
456
466
  return { code: 0, text: capabilityFor(args.group) }
457
467
  }
@@ -470,7 +480,7 @@ export function attachHost(ctx, deps) {
470
480
  ]
471
481
  return { code: drift.ok ? 0 : 3, text: lines.join('\n') }
472
482
  }
473
- const result = await backend.raw(args.argv, { stdin: args.stdin })
483
+ const result = await backend.raw(argv, { stdin: args.stdin })
474
484
  if (result.ok === false && result.reason !== undefined) {
475
485
  return { code: 2, text: `拒绝执行:${result.reason}` }
476
486
  }
package/lib/snapshot.js CHANGED
@@ -8,6 +8,7 @@
8
8
  //
9
9
  // 折叠的前提是可验证:只有当锚点词检索确实覆盖该簇全部条目(召回 >= 80%)时
10
10
  // 才折叠;否则原样列出。宁可多占几百字节,也不让模型以为「库里没有这条」。
11
+ import { createHash } from 'node:crypto'
11
12
  import { mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from 'node:fs'
12
13
  import { dirname, join } from 'node:path'
13
14
 
@@ -373,8 +374,10 @@ export async function buildSnapshot(listPlane, options = {}) {
373
374
  }
374
375
 
375
376
  // 独立的主题行容纳跨平面簇;每个成员仍可从展开结果查到原平面。
376
- const labels = selected.folds.map((f) => `${f.phrase}×${f.count}#${f.id}`).join(' ')
377
- const instructions = '用 aurorix_abook ["theme-members","--algorithm","aplusplus","--input","title","--cluster","<簇ID>","--json"] 展开(# 后是簇 ID)。若已变化,重新取句云或检索。'
377
+ const ids = selected.folds.map((f) => f.id)
378
+ const stamp = createHash('sha256').update(JSON.stringify(ids)).digest('hex').slice(0, 12)
379
+ const labels = selected.folds.map((f, i) => `${f.phrase}#${i+1}`).join(' ')
380
+ const instructions = `用 aurorix_abook ["theme-open","${stamp}","编号"] 展开。`
378
381
  const plainIndex = titleLines(new Map()).join('\n')
379
382
  const foldedIndex = labels ? [`**句云(长期事实与事件)**:${labels}`, instructions, ...titleLines(selected.ownerOf)].join('\n') : ''
380
383
  const useFolded = foldedIndex !== '' && Buffer.byteLength(foldedIndex) < Buffer.byteLength(plainIndex)
@@ -392,6 +395,7 @@ export async function buildSnapshot(listPlane, options = {}) {
392
395
  ].filter((part) => part && part.length > 0)
393
396
 
394
397
  return {
398
+ themeRefs: useFolded ? { stamp, ids } : null,
395
399
  text: clampBytes(parts.join('\n\n'), options.maxContextBytes ?? 96000),
396
400
  stats: {
397
401
  total: records.length,
package/lib/theme.js CHANGED
@@ -11,6 +11,11 @@
11
11
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
12
12
  import { dirname } from 'node:path'
13
13
 
14
+ // 只用于插件注入;abook 自己的 CLI 默认值不变。展开时必须用同一组参数。
15
+ export const SNAPSHOT_THEME_ARGS = Object.freeze([
16
+ '--algorithm', 'aplusplus', '--input', 'title', '--rank', '48', '--neighbors', '10', '--similarity', '0.40',
17
+ ])
18
+
14
19
  /** abook 自己的诊断噪声:linker 警告与截断提示都不是判断依据。 */
15
20
  const NOISE = [/^linker: Warning:/, /^WARNING: linker:/, /^\[abook\] 检测到输出/]
16
21
 
@@ -43,8 +48,7 @@ function reasonOf(result) {
43
48
  */
44
49
  export function createThemeClient(backend, options = {}) {
45
50
  const timeoutMs = Math.max(1000, Number(options.timeoutMs) || 30_000)
46
- const algorithm = String(options.algorithm || 'aplusplus')
47
- const input = String(options.input || 'title')
51
+ const args = SNAPSHOT_THEME_ARGS
48
52
 
49
53
  let identityPromise
50
54
  let capabilityPromise
@@ -108,7 +112,7 @@ export function createThemeClient(backend, options = {}) {
108
112
  if (cap.ok !== true) return { ok: false, unavailable: cap.unavailable === true, reason: cap.reason }
109
113
 
110
114
  const result = await backend.raw(
111
- ['memory', 'themes', '--algorithm', algorithm, '--input', input, '--json'],
115
+ ['memory', 'themes', ...args, '--json'],
112
116
  { timeoutMs },
113
117
  )
114
118
  if (result?.ok !== true || result?.json === null || typeof result?.json !== 'object') {
@@ -148,7 +152,7 @@ export function createThemeClient(backend, options = {}) {
148
152
  if (selector === null) return { ok: false, reason: '要么给 --cluster,要么给 --id' }
149
153
 
150
154
  const result = await backend.raw(
151
- ['theme-members', '--algorithm', algorithm, '--input', input, ...selector, '--json'],
155
+ ['theme-members', ...args, ...selector, '--json'],
152
156
  { timeoutMs },
153
157
  )
154
158
  if (result?.ok !== true || result?.json === null || typeof result?.json !== 'object') {
@@ -162,7 +166,7 @@ export function createThemeClient(backend, options = {}) {
162
166
  }
163
167
  }
164
168
 
165
- return { themes, members, capability, identity, algorithm, input }
169
+ return { themes, members, capability, identity }
166
170
  }
167
171
 
168
172
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aurorix-agentbook",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 与 Harness Web 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)与 Web 顶栏槽位面板,加宿主侧提示词注入、分层快照与八个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",