dsh-aurorix-agentbook 1.0.1 → 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aurorix Drakos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -62,15 +62,24 @@
62
62
  - **连续操作时偶尔提示"提示太频繁"**:App 对 toast 有每插件 2 秒一条的限制。写入成功的回执已改到面板的状态行里,不占 toast 配额。
63
63
  - `lib/` 改了要在 App 的「引擎」页重启引擎才生效。
64
64
 
65
- ## 安装与自查
65
+ ## 安装
66
+
67
+ 从 npm 装:
68
+
69
+ ```sh
70
+ dsh plugin --profile web add dsh-aurorix-agentbook
71
+ ```
72
+
73
+ 开发时想挂本地目录,把 `dsh-aurorix-agentbook` 换成该目录的绝对路径即可。
74
+
75
+ 自查:
66
76
 
67
77
  ```sh
68
- dsh plugin --profile web add /root/.dsh/dsh-go/plugins/dsh-aurorix-agentbook
69
78
  node ~/.dsh/skills/dsh-go-plugin/kit/bin/check.mjs . --load
70
79
  node --test test/*.test.js
71
80
  ```
72
81
 
73
- 装的是指向本目录的链接,**目录不能删**。测试会真的读写记忆库:每条临时记录自己写入、自己删除,跑完不留东西。
82
+ 测试会真的读写记忆库:每条临时记录自己写入、自己删除,跑完不留东西。
74
83
 
75
84
  ## 文件
76
85
 
@@ -85,7 +94,7 @@ node --test test/*.test.js
85
94
  | `lib/view.js` | 面板视图与数据模型 |
86
95
  | `lib/words.js` | 中英文案与平面名 |
87
96
  | `test/memory.test.js` | 界面层端到端(20 项) |
88
- | `test/host.test.js` | 宿主层端到端(14 项) |
97
+ | `test/host.test.js` | 宿主层端到端(22 项) |
89
98
 
90
99
  ## 不做什么
91
100
 
package/cordis.patch.yml CHANGED
@@ -2,7 +2,9 @@
2
2
  # (提示词注入 / aurorix_recall 与 aurorix_remember 工具 / /memory 系列命令)合一。
3
3
  #
4
4
  # 配置字段(改这里,重启宿主后生效):
5
- # abookPath abook 可执行文件绝对路径;留空则按 ~/AgentsBook/abook 与 PATH 自动找
5
+ # abookPath abook 可执行文件绝对路径;留空则用插件自带的,缺了自动下载
6
+ # home DSH 家目录;留空取 $DSH_HOME 或 ~/.dsh。程序放 <home>/cache/dsh-aurorix-agentbook/bin
7
+ # autoInstall 后端缺失时是否自动下载对应平台的 abook(不改 PATH、不装系统目录)
6
8
  # root 记忆库根;留空则不传 --root,由 abook 按程序所在目录推导
7
9
  # injectSection 是否注入记忆协议段落
8
10
  # injectSnapshot 是否把分层快照注入运行时上下文
@@ -21,8 +23,10 @@
21
23
  - id: dsh-aurorix-agentbook
22
24
  name: dsh-aurorix-agentbook
23
25
  config:
24
- abookPath: /root/AgentsBook/abook
26
+ abookPath: ''
25
27
  root: /root/AgentsBook
28
+ home: ''
29
+ autoInstall: true
26
30
  injectSection: true
27
31
  injectSnapshot: true
28
32
  residentLimit: 40
package/lib/abook.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { spawn } from 'node:child_process'
4
4
  import { existsSync } from 'node:fs'
5
5
  import { homedir } from 'node:os'
6
+ import { ensureBackend, installedPath } from './backend.js'
6
7
  import { join } from 'node:path'
7
8
 
8
9
  const TIMEOUT_MS = 20_000
@@ -121,16 +122,55 @@ function reasonOf(r) {
121
122
  const text = (value) => (typeof value === 'string' ? value : value === undefined || value === null ? '' : String(value))
122
123
 
123
124
  export function createBackend(options = {}) {
124
- const bin = typeof options === 'string' ? options : (options.bin ?? locate())
125
- if (bin === undefined) return undefined
125
+ const explicit = typeof options === 'string' ? options : (options.configured ?? options.bin ?? '')
126
126
  const root = typeof options === 'object' && typeof options.root === 'string' && options.root !== ''
127
127
  ? options.root
128
128
  : ''
129
+ const home = typeof options === 'object' ? options.home : undefined
130
+ const version = typeof options === 'object' ? options.version : undefined
131
+ const autoInstall = typeof options === 'object' ? options.autoInstall : undefined
132
+
133
+ // 二进制可能还没装:先认显式配置与老路径,都没有就等第一次调用时下载安装。
134
+ let bin = explicit !== '' ? explicit : undefined
135
+ let installing
136
+
137
+ // 优先级:显式配置 > 插件自己装的 > 老路径兼容 > 下载安装。
138
+ // 插件自己的排前面,这样升级插件不会被动用上一个不相干的 abook。
139
+ function ensureBin() {
140
+ if (typeof bin === 'string' && bin !== '' && existsSync(bin)) return Promise.resolve(bin)
141
+ if (installing !== undefined) return installing
142
+ installing = (async () => {
143
+ if (explicit !== '' && existsSync(explicit)) return (bin = explicit)
144
+ const own = installedPath(home)
145
+ if (existsSync(own)) return (bin = own)
146
+ const legacy = locate()
147
+ if (legacy !== undefined) return (bin = legacy)
148
+ const r = await ensureBackend({ configured: '', home, version, autoInstall })
149
+ return (bin = r.bin)
150
+ })().catch((err) => {
151
+ installing = undefined
152
+ throw err
153
+ })
154
+ return installing
155
+ }
129
156
 
130
157
  // 每次调用都带上 --root:库根显式固定,不依赖引擎进程的 cwd 或环境变量。
131
- const call = (args, input) => run(bin, root === '' ? args : [...args, '--root', root], input)
158
+ async function call(args, input) {
159
+ let b
160
+ try {
161
+ b = await ensureBin()
162
+ } catch (err) {
163
+ // 后端装不上不该让整个插件崩:返回一条可读的失败,界面层照常显示提示。
164
+ return { ok: false, code: err?.code ?? 'backend-unavailable', stdout: '', stderr: err?.message ?? String(err), json: undefined }
165
+ }
166
+ return run(b, root === '' ? args : [...args, '--root', root], input)
167
+ }
168
+
132
169
  return {
133
- bin,
170
+ get bin() {
171
+ return bin
172
+ },
173
+ ensure: ensureBin,
134
174
 
135
175
  /** 各平面条数与总数;credentials=vault 表示凭据平面由独立保险箱承载。 */
136
176
  async context() {
package/lib/backend.js ADDED
@@ -0,0 +1,164 @@
1
+ // 后端二进制自管理:插件装好就该能跑,用户不需要单独装 abook。
2
+ //
3
+ // 三条原则:
4
+ // 1. 不碰系统目录、不改 PATH、不写 shell 配置——二进制只放在插件自己的数据目录里。
5
+ // 2. 程序与数据分离:二进制在 cache,记忆库本体仍在 ~/AgentsBook。
6
+ // 3. 失败要能说清:网络断了、平台不支持、校验不过,各自给不同的错误。
7
+ import { createHash } from 'node:crypto'
8
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
9
+ import { homedir } from 'node:os'
10
+ import { join } from 'node:path'
11
+
12
+ const REPO = 'Sharl210/abook'
13
+ const DATA_DIR = 'dsh-aurorix-agentbook'
14
+ const BIN_NAME = process.platform === 'win32' ? 'abook.exe' : 'abook'
15
+
16
+ /** 平台 → release 资产名。找不到就是找不到,不猜一个差不多的。 */
17
+ export function assetName(platform = process.platform, arch = process.arch, isAndroid = detectAndroid()) {
18
+ if (platform === 'linux') {
19
+ if (arch === 'arm64') return isAndroid ? 'abook-aarch64-linux-android' : 'abook-aarch64-unknown-linux-musl'
20
+ if (arch === 'x64') return isAndroid ? 'abook-x86_64-linux-android' : 'abook-x86_64-unknown-linux-musl'
21
+ if (arch === 'arm') return isAndroid ? 'abook-armv7-linux-androideabi' : 'abook-armv7-unknown-linux-musleabihf'
22
+ if (arch === 'ia32') return isAndroid ? 'abook-i686-linux-android' : 'abook-i686-unknown-linux-musl'
23
+ if (arch === 'riscv64') return 'abook-riscv64gc-unknown-linux-gnu'
24
+ if (arch === 'loong64') return 'abook-loongarch64-unknown-linux-gnu'
25
+ }
26
+ if (platform === 'darwin') {
27
+ if (arch === 'arm64') return 'abook-aarch64-apple-darwin'
28
+ if (arch === 'x64') return 'abook-x86_64-apple-darwin'
29
+ }
30
+ if (platform === 'win32') {
31
+ if (arch === 'x64') return 'abook-x86_64-pc-windows-gnullvm.exe'
32
+ if (arch === 'arm64') return 'abook-aarch64-pc-windows-gnullvm.exe'
33
+ if (arch === 'ia32') return 'abook-i686-pc-windows-gnullvm.exe'
34
+ }
35
+ return undefined
36
+ }
37
+
38
+ /** proot / Termux 里 platform 仍是 linux,但要用 android 构建。 */
39
+ function detectAndroid() {
40
+ if (process.env.ANDROID_ROOT || process.env.ANDROID_DATA) return true
41
+ try {
42
+ return existsSync('/system/build.prop')
43
+ } catch {
44
+ return false
45
+ }
46
+ }
47
+
48
+ /** 程序放插件数据目录,和记忆库(~/AgentsBook)分开。 */
49
+ export function backendDir(home = process.env.DSH_HOME ?? join(homedir(), '.dsh')) {
50
+ return join(home, 'cache', DATA_DIR, 'bin')
51
+ }
52
+
53
+ export function installedPath(home) {
54
+ return join(backendDir(home), BIN_NAME)
55
+ }
56
+
57
+ function versionFile(home) {
58
+ return join(backendDir(home), 'VERSION')
59
+ }
60
+
61
+ function readInstalled(home) {
62
+ const bin = installedPath(home)
63
+ try {
64
+ if (!existsSync(bin)) return undefined
65
+ const st = statSync(bin)
66
+ if (st.size < 100_000) return undefined
67
+ const ver = existsSync(versionFile(home)) ? readFileSync(versionFile(home), 'utf8').trim() : ''
68
+ return { bin, version: ver, size: st.size }
69
+ } catch {
70
+ return undefined
71
+ }
72
+ }
73
+
74
+ /** 文件头是不是真二进制——防着拿到一个 HTML 错误页。 */
75
+ function looksExecutable(buf) {
76
+ if (buf.length < 4) return false
77
+ const m = buf.subarray(0, 4)
78
+ return (
79
+ (m[0] === 0x7f && m[1] === 0x45 && m[2] === 0x4c && m[3] === 0x46) || // ELF
80
+ (m[0] === 0x4d && m[1] === 0x5a) || // MZ
81
+ (m[0] === 0xcf && m[1] === 0xfa && m[2] === 0xed && m[3] === 0xfe) || // Mach-O 64 LE
82
+ (m[0] === 0xfe && m[1] === 0xed && m[2] === 0xfa && m[3] === 0xcf) || // Mach-O 64 BE
83
+ (m[0] === 0xca && m[1] === 0xfe && m[2] === 0xba && m[3] === 0xbe) // fat
84
+ )
85
+ }
86
+
87
+ /**
88
+ * 确保后端可用。返回 { bin, version, source } 或抛带 code 的错误。
89
+ * source: 'configured' | 'existing' | 'downloaded'
90
+ */
91
+ export async function ensureBackend(options = {}) {
92
+ // 1. 显式配置优先,且不做任何下载
93
+ if (typeof options.configured === 'string' && options.configured !== '') {
94
+ if (!existsSync(options.configured)) {
95
+ throw backendError('configured-missing', `配置里的 abookPath 不存在:${options.configured}`)
96
+ }
97
+ return { bin: options.configured, version: 'configured', source: 'configured' }
98
+ }
99
+
100
+ // 2. 已经装过且版本对得上,直接用
101
+ const home = options.home
102
+ const want = options.version // 期望版本;undefined 表示不挑
103
+ const have = readInstalled(home)
104
+ if (have !== undefined && (want === undefined || want === '' || have.version === want)) {
105
+ return { bin: have.bin, version: have.version, source: 'existing' }
106
+ }
107
+
108
+ // 3. 下载
109
+ if (options.autoInstall === false) {
110
+ throw backendError('missing', '后端未安装,且已关闭自动安装。')
111
+ }
112
+ const asset = assetName()
113
+ if (asset === undefined) {
114
+ throw backendError('unsupported-platform', `没有适配 ${process.platform}/${process.arch} 的 abook 构建。`)
115
+ }
116
+ const version = want !== undefined && want !== '' ? want : await latestVersion()
117
+ const url = `https://github.com/${REPO}/releases/download/${version}/${asset}`
118
+ const buf = await download(url)
119
+ if (!looksExecutable(buf)) {
120
+ throw backendError('bad-download', `${url} 返回的不是可执行文件(前 4 字节 ${[...buf.subarray(0, 4)].map((b) => b.toString(16)).join(' ')})。`)
121
+ }
122
+
123
+ const dir = backendDir(home)
124
+ mkdirSync(dir, { recursive: true })
125
+ const target = installedPath(home)
126
+ const tmp = `${target}.tmp-${process.pid}`
127
+ writeFileSync(tmp, buf)
128
+ if (process.platform !== 'win32') chmodSync(tmp, 0o755)
129
+ renameSync(tmp, target)
130
+ writeFileSync(versionFile(home), version)
131
+ try {
132
+ rmSync(tmp, { force: true })
133
+ } catch {}
134
+
135
+ return { bin: target, version, source: 'downloaded', bytes: buf.length, sha256: createHash('sha256').update(buf).digest('hex') }
136
+ }
137
+
138
+ async function latestVersion() {
139
+ const r = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, {
140
+ headers: { 'user-agent': 'dsh-aurorix-agentbook', accept: 'application/vnd.github+json' },
141
+ })
142
+ if (!r.ok) throw backendError('catalog-failed', `查 abook 最新版本失败:HTTP ${r.status}`)
143
+ const d = await r.json()
144
+ if (typeof d.tag_name !== 'string') throw backendError('catalog-failed', 'GitHub 返回里没有 tag_name')
145
+ return d.tag_name
146
+ }
147
+
148
+ async function download(url) {
149
+ let r
150
+ try {
151
+ r = await fetch(url, { redirect: 'follow', headers: { 'user-agent': 'dsh-aurorix-agentbook' } })
152
+ } catch (err) {
153
+ throw backendError('network', `下载 abook 失败:${err?.message ?? err}`)
154
+ }
155
+ if (!r.ok) throw backendError('download-failed', `下载 ${url} 失败:HTTP ${r.status}`)
156
+ const ab = await r.arrayBuffer()
157
+ return Buffer.from(ab)
158
+ }
159
+
160
+ export function backendError(code, message) {
161
+ const err = new Error(message)
162
+ err.code = code
163
+ return err
164
+ }
@@ -0,0 +1,105 @@
1
+ // 记忆整理范式:专门给「整理/瘦身/清理/合并记忆」这类作业用。
2
+ // 与日常写入分开——日常写入不做质检,整理才做。
3
+ export const CURATION_MANUAL = [
4
+ "# 记忆库整理手册",
5
+ "",
6
+ "这份手册面向**一次专门的整理作业**:把记忆库从「堆着」变成「能用」。不是日常写入,是定期维护。",
7
+ "",
8
+ "## 什么时候该整理",
9
+ "",
10
+ "命中任一再动手,否则别动——日常使用中看到的乱,多半是正常的:",
11
+ "",
12
+ "- 用户明确要求整理、瘦身、清理、合并记忆",
13
+ "- 常驻层(soul / profile / explicit)明显变大,每轮注入成本上升",
14
+ "- 发现同一条事实在多个平面重复,或两条互相矛盾",
15
+ "- 检索时明明有相关记录却排不上来(标题不准确)",
16
+ "- 明确知道某条记录已过时",
17
+ "",
18
+ "**不该整理的信号**:库里有重复、粗糙、互相矛盾的条目是正常状态,看到不等于要清。没有明确触发时,不要顺手整理。",
19
+ "",
20
+ "## 整理前必须先读完",
21
+ "",
22
+ "不做这一步就动手,等于把用户的资产按猜测重排。",
23
+ "",
24
+ "1. 看整体:`aurorix_abook` 跑 `state`,记下各平面条数与一致性状态",
25
+ "2. 通读常驻层:`soul` / `profile` / `explicit` 全量(快照里已有),逐条看内容与长度",
26
+ "3. 摸下三层:`rules` / `long_term` / `episodic` 用 `aurorix_abook` 跑 `memory list --plane <p> --limit 200 --json`,不要只凭标题判断",
27
+ "4. 标记候选:哪些超大、哪些放错平面、哪些内容重复、哪些过期",
28
+ "",
29
+ "读不完整理完,不算整理完。",
30
+ "",
31
+ "## 三阶段",
32
+ "",
33
+ "### 阶段一:常驻层减重",
34
+ "",
35
+ "常驻层每轮全量注入,它涨一点,每轮成本涨一点。",
36
+ "",
37
+ "- 找出 `explicit` 里超过 ~500 字的记录:多半是「用户说要记住」,结果把整段经过塞进来了",
38
+ "- 处理:短关键点留在 `explicit`,完整经过用 `aurorix_remember` 写进 `long_term` 或 `episodic`,然后删掉 `explicit` 里的长正文",
39
+ "- `soul` 里混进任务细节、`profile` 里混进一次性事件的,同样迁走",
40
+ "- 迁完确认:常驻层每条都该是「长期成立的短句」",
41
+ "",
42
+ "### 阶段二:下三层梳理",
43
+ "",
44
+ "- **重复**:同一件事多条。合并(`memory merge`),保留信息最全的那条,把其余的有用细节并进去",
45
+ "- **矛盾**:两条说法冲突。先判断哪条有更新的证据;能判就合并并写明「后来的判断是 X,早期记的是 Y」;判不了就保留两条并在正文里标明分歧,不要擅自选一个删掉另一个",
46
+ "- **过时**:明确知道已失效的。不要硬删,改写成历史记录(「曾用 A 方案,X 之后改成 B」),保留演进痕迹",
47
+ "- **放错平面**:工作原则在 `long_term` → 提到 `soul`;用户偏好散在 `long_term` → 提到 `profile`;单次事件在 `long_term` → 移到 `episodic`",
48
+ "- **标题不准**:标题只概括这条记录在讲什么,用白话。不写用途、不写适用场景、不写「何时该读」",
49
+ "",
50
+ "### 阶段三:提纯反哺",
51
+ "",
52
+ "只把**跨任务稳定**的结论提炼上去:",
53
+ "",
54
+ "- 反复验证过的 AI 行为原则 → `soul`",
55
+ "- 稳定的用户偏好、称呼、环境事实 → `profile`",
56
+ "- 一次性事件、未验证的推测 → 不上提",
57
+ "",
58
+ "上提时写短:一条原则一段话,超过 300 字说明提得太细,还在描述过程而非原则。",
59
+ "",
60
+ "## 具体命令",
61
+ "",
62
+ "全部通过 `aurorix_abook` 跑,或 `aurorix_remember` 写:",
63
+ "",
64
+ "```",
65
+ "list memory list --plane <平面> --limit 200 --json 看一圈(别只看标题)",
66
+ "read memory read <id> 读全文",
67
+ "update memory update <id> --expect-revision N 改标题/正文/字段",
68
+ "merge memory merge <主> <被并入> --expect-revision A --expect-into-revision B",
69
+ "move_plane memory move_plane <id> --to-plane <平面> --expect-revision N",
70
+ "split memory split <id> --separator <分隔符> --expect-revision N",
71
+ "delete memory delete <id> --expect-revision N 软删,可恢复",
72
+ "restore memory restore <id> --expect-revision N",
73
+ "state / reconcile / doctor 改完核对",
74
+ "```",
75
+ "",
76
+ "**先读后改,带 `--expect-revision`**:不带的话,两个动作之间别人改了库,你的写入会盖掉它。",
77
+ "",
78
+ "## 安全边界",
79
+ "",
80
+ "- 删除一律走软删(`memory delete`),**不做物理删除**。墓碑保留,能恢复",
81
+ "- 合并只在正文一致或能明确判断时才做;拿不准就保留两条并标注关系",
82
+ "- 一次只处理一个平面,改完立刻核对,别攒一大批最后一起改",
83
+ "- 动手前先跑一次 `state` 记下基线条数,整理完对照,数字对不上要查",
84
+ "- **不碰凭据平面**:`credentials` 走专用入口,不进普通整理",
85
+ "",
86
+ "## 验收",
87
+ "",
88
+ "整理完逐项核对,缺一项不算完成:",
89
+ "",
90
+ "1. `state` 的一致性通过,条数变化能解释(合并少了 N 条、软删 M 条、迁移没变数量)",
91
+ "2. 常驻层没有超长记录、没有混入整段经过",
92
+ "3. 被合并/移动的记录 ID 都还在(软删可恢复)",
93
+ "4. 抽查 5 条改过的记录,读全文确认内容没丢",
94
+ "5. 向用户报告:**结构变化**(哪些平面增减)、**处置明细**(合并/迁移/软删各多少)、**矛盾怎么裁决的**",
95
+ "",
96
+ "报告不能只报数量。用户要看的是「你动了什么、为什么」。",
97
+ "",
98
+ "## 常见错误",
99
+ "",
100
+ "- **只凭标题判断**:标题只有几十字,正文可能完全不同的事",
101
+ "- **顺手整理**:没有明确触发就动手,把用户熟悉的记录改得认不出来",
102
+ "- **硬删**:直接物理删除,用户想恢复时找不到",
103
+ "- **一次改太多**:出问题时无法定位是哪一步搞坏的",
104
+ "- **把摘要当正文**:列表给的是 preview,改之前必须 `read` 全文",
105
+ ].join('\n')
package/lib/guide.js CHANGED
@@ -30,6 +30,24 @@ export const GUIDE = {
30
30
  "`MEMORY_PLANE_RESIDENT_GATE`=常驻层(soul/profile/explicit)全量随快照每步到达,不需要另行读取;判断「库里有什麼」看快照的分层结构,需要正文再检索.完整原文见`aurorix_guide({\"topic\":\"preload\"})`.",
31
31
  "`MEMORY_CONTEXT_BUDGET_GATE`=快照给平面结构,不整库全读;单条正文≤8KB,超预算先分页/收窄/分段,禁以\"省token\"为由跳过记忆或截断abook输出;`ABOOK_OUTPUT_INTEGRITY_GATE`优先于任何篇幅理由.",
32
32
  "`LAZY_LOAD_GATE`=**不做前置检测,直接调用.**要记忆就直接调工具,不先探活.工具报不可用才按`MEMORY_FAILURE_GATE`处置;禁自行安装、禁手工拼命令、禁改PATH或shell配置,禁自行编译替代.完整原文:`aurorix_guide({\"topic\":\"root\"})`.",
33
+ "### 附件(文件域)",
34
+ "",
35
+ "记录 = 文字域 + 文件域。附件放在 `<记录名>-refs/` 里,图片、截图、原始日志、PDF、抓包、表格都算。",
36
+ "",
37
+ "```",
38
+ "attach list <记录> 列附件(名字 + 体积)",
39
+ "attach add <记录> <文件> [--name N] 复制进附件目录;--move 搬走,--force 超 50MB 时必带",
40
+ "attach get <记录> <附件名> 只打印绝对路径,不打印内容(大文件别塞进输出)",
41
+ "attach rm <记录> <附件名> 删一个",
42
+ "attach path <记录> 打印附件目录",
43
+ "attach sync <记录> | --all 清单与磁盘重新对齐",
44
+ "attach refs <记录> 检查正文里的附件引用有没有悬空",
45
+ "attach check 找孤立目录(记录改名/删除但附件还在)",
46
+ "```",
47
+ "",
48
+ "三条不变量:①附件变了记录就算改过,清单随写入刷新;②默认复制,只有用户明确说「搬过去」才 `--move`;③50MB 是控制库体积的硬线,没有免检通道,用户说过「你决定」就是授权,直接 `--force`。",
49
+ "",
50
+ "正文引用写法:`本条目附件1://文件名`,指向清单第 1 行。",
33
51
  ].join('\n\n'),
34
52
 
35
53
  // 预载、平面常驻与召回分层
package/lib/host.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  resolveStatePath,
14
14
  } from './snapshot.js'
15
15
  import { GUIDE, GUIDE_INDEX } from './guide.js'
16
+ import { CURATION_MANUAL } from './curation.js'
16
17
 
17
18
  /** 单次工具返回的正文上限:超了就拒收并给分页建议,不返回半截证据。 */
18
19
  const RAW_LIMIT = 200 * 1024
@@ -369,6 +370,25 @@ export function attachHost(ctx, deps) {
369
370
  },
370
371
  })
371
372
 
373
+ // 整理范式:只有真的要做「整理/瘦身/清理」这类作业时才用。
374
+ const curate = scope.tools.register({
375
+ name: 'aurorix_curate',
376
+ description: '取「记忆库整理手册」:什么时候该整理、整理前三步通读、三阶段(常驻层减重 / 下三层梳理 / 提纯反哺)、具体命令、安全边界与验收清单。用户要求整理、瘦身、清理、合并记忆,或你判断该做一次维护时先取这份,不要凭印象动手。',
377
+ parameters: { type: 'object', properties: {}, required: [] },
378
+ output: {
379
+ schema: {
380
+ type: 'object',
381
+ additionalProperties: false,
382
+ properties: { text: { type: 'string', description: '整理手册全文' } },
383
+ required: ['text'],
384
+ },
385
+ render: (_args, value) => [{ type: 'text', text: value.text }],
386
+ },
387
+ async execute() {
388
+ return { text: CURATION_MANUAL }
389
+ },
390
+ })
391
+
372
392
  // 完整操作手册:把系统提示词里搬出来的门按章取回。
373
393
  const guide = scope.tools.register({
374
394
  name: 'aurorix_guide',
@@ -404,7 +424,7 @@ export function attachHost(ctx, deps) {
404
424
  })
405
425
 
406
426
  scope.effect(() => () => {
407
- for (const dispose of [recall, remember, runCmd, spec, guide]) {
427
+ for (const dispose of [recall, remember, runCmd, spec, guide, curate]) {
408
428
  try {
409
429
  if (typeof dispose === 'function') dispose()
410
430
  } catch {
@@ -437,16 +457,32 @@ export function attachHost(ctx, deps) {
437
457
  const memory = scope.commands.register({
438
458
  definitionId: 'dsh-aurorix-agentbook/memory',
439
459
  name: 'memory',
440
- description: '查看记忆库分层状态,或强制刷新',
441
- input: { hint: 'refresh' },
460
+ description: '查看记忆库分层状态、强制刷新,或查看后端二进制信息',
461
+ input: { hint: 'refresh | backend' },
442
462
  async handler(invocation) {
443
463
  const raw = String(invocation.rawInput || '').trim()
464
+ if (raw === 'backend') {
465
+ // 架构判定装错、下载了错误平台、或者根本没装——都从这里一眼看出来。
466
+ let info
467
+ try {
468
+ await backend.ensure()
469
+ info = { bin: backend.bin }
470
+ } catch (err) {
471
+ return { kind: 'error', text: `后端不可用(${err?.code ?? 'unknown'}):${err?.message ?? err}` }
472
+ }
473
+ const r = await backend.raw(['version'])
474
+ const out = String(r.stdout ?? '').trim()
475
+ return {
476
+ kind: r.ok ? 'success' : 'error',
477
+ text: [`后端:${info.bin}`, out === '' ? `(version 无输出)${String(r.stderr ?? '').trim()}` : out].join('\n'),
478
+ }
479
+ }
444
480
  if (raw === 'refresh') {
445
481
  snapshot.fetchedAt = 0
446
482
  await refresh()
447
483
  return { kind: 'success', text: `已刷新。\n${statusText()}` }
448
484
  }
449
- if (raw.length > 0) return { kind: 'error', text: `用法:/memory [refresh]\n\n${statusText()}` }
485
+ if (raw.length > 0) return { kind: 'error', text: `用法:/memory [refresh|backend]\n\n${statusText()}` }
450
486
  return { kind: 'success', text: statusText() }
451
487
  },
452
488
  })
package/lib/index.js CHANGED
@@ -28,12 +28,19 @@ function readSettings(config) {
28
28
  return {
29
29
  abookPath: String(get('abookPath') || ''),
30
30
  root: String(get('root') || ''),
31
+ home: String(get('home') || ''),
32
+ autoInstall: get('autoInstall', true) !== false,
31
33
  }
32
34
  }
33
35
 
34
36
  export function apply(ctx, config) {
35
37
  const settings = readSettings(config)
36
- const backend = createBackend({ bin: settings.abookPath || undefined, root: settings.root || undefined })
38
+ const backend = createBackend({
39
+ configured: settings.abookPath || undefined,
40
+ root: settings.root || undefined,
41
+ home: settings.home || undefined,
42
+ autoInstall: settings.autoInstall,
43
+ })
37
44
  const w = (locale) => words(locale)
38
45
 
39
46
  // 宿主层(提示词注入、工具、斜杠命令)和界面层共用这一个 backend。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aurorix-agentbook",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -72,7 +72,8 @@
72
72
  },
73
73
  "scripts": {
74
74
  "test": "node --test --test-concurrency=1 --test-timeout=90000 test/*.test.js",
75
- "check": "node ~/.dsh/skills/dsh-go-plugin/kit/bin/check.mjs . --load"
75
+ "check": "node ~/.dsh/skills/dsh-go-plugin/kit/bin/check.mjs . --load",
76
+ "postinstall": "node scripts/postinstall.js"
76
77
  },
77
78
  "keywords": [
78
79
  "dsh",
@@ -90,6 +91,7 @@
90
91
  },
91
92
  "files": [
92
93
  "lib/",
94
+ "scripts/",
93
95
  "cordis.patch.yml",
94
96
  "README.md"
95
97
  ]
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ // 安装期就把对应架构的后端拉下来。
3
+ // 失败不阻塞安装:运行时还会再试一次,但那时已经在用了,用户会等。
4
+ import { ensureBackend } from '../lib/backend.js'
5
+
6
+ const label = '[dsh-aurorix-agentbook]'
7
+
8
+ try {
9
+ const r = await ensureBackend()
10
+ console.log(`${label} 后端就绪:${r.version}(${r.source})`)
11
+ if (r.sha256) console.log(`${label} sha256 ${r.sha256}`)
12
+ console.log(`${label} 位置 ${r.bin}`)
13
+ } catch (err) {
14
+ // 网络不通、平台没有构建、GitHub 限流——都不该让 npm install 失败。
15
+ console.warn(`${label} 后端暂未安装(${err?.code ?? 'unknown'}):${err?.message ?? err}`)
16
+ console.warn(`${label} 不影响安装;首次使用时会自动重试,也可以看 README 的离线安装说明。`)
17
+ process.exitCode = 0
18
+ }