dsh-aurorix-agentbook 1.7.2 → 1.8.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/CLI.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  ## 怎么直接用
6
6
 
7
- 插件安装后会在 PATH 里建一个软链,终端里直接敲 `abook` 就行,不用带路径:
7
+ 二进制随插件包一起发:`vendor/` 下按平台架构各一份,插件运行时挑对应那份复制到自己的数据目录,全程离线。系统 PATH 里没有它,也不该有。
8
+
9
+ 要用命令行,走插件的 shell 工具(`aurorix_sh`)——它只对那一条子进程前置 PATH,在那里可以直接敲 `abook`:
8
10
 
9
11
  ```sh
10
12
  abook version # 看版本与平台标记
@@ -12,7 +14,7 @@ abook state # 库状态:记录数、地图数、一致性
12
14
  abook help # 全部命令一览
13
15
  ```
14
16
 
15
- 软链指向插件自己的二进制(`<DSH_HOME>/cache/dsh-aurorix-agentbook/bin/abook`),不复制、不改 PATH 变量、不写 shell 配置。
17
+ 插件自己的二进制落在 `<DSH_HOME>/cache/dsh-aurorix-agentbook/bin/abook`;不改 PATH 变量、不写 shell 配置、不在系统目录留软链。
16
18
 
17
19
  ## 库根
18
20
 
package/README.md CHANGED
@@ -32,6 +32,17 @@
32
32
 
33
33
  当前库(约 560 条)的快照约 60 KB,默认上限 96 KB,不会被截断。
34
34
 
35
+ ## 后端二进制
36
+
37
+ `abook` 随包一起发:`vendor/` 下按平台架构各一份(共 15 个),插件运行时按 `process.platform`/`process.arch` 挑对应那份,复制到 `<DSH_HOME>/cache/dsh-aurorix-agentbook/bin/` 并加执行位。
38
+
39
+ - **不联网**:取二进制不走任何外部服务,不会因为网络或镜像限流失败。
40
+ - **不碰系统**:不装系统目录、不写 PATH 变量、不写 shell 配置、不在系统里留软链。系统 PATH 里本来就没有 `abook`,这是有意的。
41
+ - **要在命令行用**:走插件的 shell 工具(`aurorix_sh`),它只对那一条子进程前置 PATH。
42
+ - **版本对齐**:插件与二进制同仓库、同版本发布。升级就是升级插件,不存在单独升二进制这条路。
43
+
44
+ 包因此有 17 MB 左右。这是刻意的取舍:一次下载换掉运行时的所有网络失败。
45
+
35
46
  ## 怎么工作
36
47
 
37
48
  - 后端是 `abook` 子进程,不是读文件、不是猜格式。命令走 argv,正文走 stdin,避开引号与换行。
package/cordis.patch.yml CHANGED
@@ -2,9 +2,8 @@
2
2
  # (提示词注入 / aurorix_recall 与 aurorix_remember 工具 / /memory 系列命令)合一。
3
3
  #
4
4
  # 配置字段(改这里,重启宿主后生效):
5
- # abookPath abook 可执行文件绝对路径;留空则用插件自带的,缺了自动下载
5
+ # abookPath abook 可执行文件绝对路径;留空用插件包里自带的那份(按平台架构自动挑)
6
6
  # home DSH 家目录;留空取 $DSH_HOME 或 ~/.dsh。程序放 <home>/cache/dsh-aurorix-agentbook/bin
7
- # autoInstall 后端缺失时是否自动下载对应平台的 abook(不改 PATH、不装系统目录)
8
7
  # root 记忆库根;留空则不传 --root,由 abook 按程序所在目录推导
9
8
  # injectSection 是否注入记忆协议段落
10
9
  # injectSnapshot 是否把分层快照注入运行时上下文
@@ -26,7 +25,6 @@
26
25
  abookPath: ''
27
26
  root: ''
28
27
  home: ''
29
- autoInstall: true
30
28
  injectSection: true
31
29
  injectSnapshot: true
32
30
  residentLimit: 40
package/lib/abook.js CHANGED
@@ -3,33 +3,24 @@
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, ensureLibrary, installedPath } from './backend.js'
6
+ import { ensureBackend, ensureLibrary } from './backend.js'
7
7
  import { join } from 'node:path'
8
8
 
9
9
  const TIMEOUT_MS = 20_000
10
10
  const MAX_OUTPUT = 8 * 1024 * 1024
11
11
 
12
- /** 找 abook:先看环境变量(测试与自定路径),再按库根与 PATH 顺序找。 */
12
+ /**
13
+ * 测试与自定路径用的显式覆盖。生产路径不查 PATH、也不查系统里已有的 abook:
14
+ * 二进制只归插件所有,避免用到另一份版本对不上的二进制——那样传参契约会错位。
15
+ */
13
16
  export function locate() {
14
17
  const explicit = process.env.ABOOK_BIN
15
- if (typeof explicit === 'string' && explicit !== '') {
16
- // 显式指定时只认它:找不到就是没有,不悄悄回落到别的二进制。
17
- try {
18
- return existsSync(explicit) ? explicit : undefined
19
- } catch {
20
- return undefined
21
- }
22
- }
23
- const candidates = [join(homedir(), 'AgentsBook', 'abook')]
24
- for (const dir of (process.env.PATH ?? '').split(':')) {
25
- if (dir !== '') candidates.push(join(dir, 'abook'))
26
- }
27
- for (const path of candidates) {
28
- try {
29
- if (existsSync(path)) return path
30
- } catch {}
18
+ if (typeof explicit !== 'string' || explicit === '') return undefined
19
+ try {
20
+ return existsSync(explicit) ? explicit : undefined
21
+ } catch {
22
+ return undefined
31
23
  }
32
- return undefined
33
24
  }
34
25
 
35
26
  /**
@@ -151,7 +142,6 @@ export function createBackend(options = {}) {
151
142
  : join(homedir(), 'AgentsBook')
152
143
  const home = typeof options === 'object' ? options.home : undefined
153
144
  const version = typeof options === 'object' ? options.version : undefined
154
- const autoInstall = typeof options === 'object' ? options.autoInstall : undefined
155
145
 
156
146
  // 二进制可能还没装:先认显式配置与老路径,都没有就等第一次调用时下载安装。
157
147
  let bin = explicit !== '' ? explicit : undefined
@@ -164,11 +154,10 @@ export function createBackend(options = {}) {
164
154
  if (installing !== undefined) return installing
165
155
  installing = (async () => {
166
156
  if (explicit !== '') return (bin = (await ensureBackend({ configured: explicit })).bin)
167
- const own = installedPath(home)
168
- if (existsSync(own)) return (bin = own)
169
157
  const legacy = locate()
170
158
  if (legacy !== undefined) return (bin = legacy)
171
- const r = await ensureBackend({ configured: '', home, version, autoInstall })
159
+ // 其余全部交给 ensureBackend:它只从包内取,不联网、不碰系统。
160
+ const r = await ensureBackend({ configured: '', home, version })
172
161
  return (bin = r.bin)
173
162
  })().finally(() => { installing = undefined })
174
163
  return installing
package/lib/backend.js CHANGED
@@ -1,33 +1,41 @@
1
- // 后端二进制自管理:插件装好就该能跑,用户不需要单独装 abook。
1
+ // 后端二进制:跟着插件包一起发,按当前架构挑一份。
2
2
  //
3
- // 三条原则:
4
- // 1. 不碰系统目录、不改 PATH、不写 shell 配置——二进制只放在插件自己的数据目录里。
5
- // 2. 程序与数据分离:二进制在 cache,记忆库本体仍在 ~/AgentsBook。
6
- // 3. 失败要能说清:网络断了、平台不支持、校验不过,各自给不同的错误。
3
+ // 为什么这么设计(和上一版的关键区别):
4
+ // 1. **不联网**。以前要在运行时查 GitHub Release 再下载,网络一抖就整页报错,
5
+ // 遇到 GitHub API 限流还会给一个和用户无关的 HTTP 403。现在二进制就在包里,
6
+ // 首次使用只是把它复制到插件自己的数据目录并加执行位,不依赖任何外部服务。
7
+ // 2. **不碰系统**。以前会在 PATH 里找个可写目录建软链,等于往系统里插了一个 `abook`。
8
+ // 现在不建软链、不改 PATH、不写 shell 配置;要让 shell 里能敲到它,
9
+ // 只经由插件的 shell 工具在那一条子进程里临时前置 PATH。
10
+ // 3. **版本对齐**。插件和二进制同一个仓库一起维护、一起发版,命令行参数不会再出现
11
+ // "插件按新契约传参、二进制还是老版本"这种错位。
7
12
  import { createHash, randomBytes } from 'node:crypto'
8
13
  import {
9
- accessSync,
10
14
  chmodSync,
11
- constants as fsConstants,
15
+ copyFileSync,
12
16
  existsSync,
13
17
  mkdirSync,
14
18
  readFileSync,
15
- realpathSync,
16
19
  renameSync,
17
20
  rmSync,
18
21
  statSync,
19
- symlinkSync,
20
22
  writeFileSync,
21
23
  } from 'node:fs'
22
24
  import { homedir } from 'node:os'
23
- import { delimiter, join as joinPath } from 'node:path'
24
- import { join } from 'node:path'
25
+ import { join as joinPath, dirname } from 'node:path'
26
+ import { fileURLToPath } from 'node:url'
25
27
 
26
- const REPO = 'Sharl210/abook'
27
28
  const DATA_DIR = 'dsh-aurorix-agentbook'
28
29
  const BIN_NAME = process.platform === 'win32' ? 'abook.exe' : 'abook'
29
30
 
30
- /** 平台 → release 资产名。找不到就是找不到,不猜一个差不多的。 */
31
+ /** 包内二进制目录。源码运行时是 ../vendor,装成 npm 包后仍是同一层的 vendor/。 */
32
+ const PACKAGE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)))
33
+ export const VENDOR_DIR = joinPath(PACKAGE_ROOT, 'vendor')
34
+
35
+ /**
36
+ * 平台 + 架构 → 包内文件名。
37
+ * 找不到就是找不到:不猜一个"差不多能用"的,那种猜法只会在运行时报更难看懂的错误。
38
+ */
31
39
  export function assetName(platform = process.platform, arch = process.arch, isAndroid = detectAndroid()) {
32
40
  if (platform === 'linux') {
33
41
  if (arch === 'arm64') return isAndroid ? 'abook-aarch64-linux-android' : 'abook-aarch64-unknown-linux-musl'
@@ -49,7 +57,7 @@ export function assetName(platform = process.platform, arch = process.arch, isAn
49
57
  return undefined
50
58
  }
51
59
 
52
- /** proot / Termux 里 platform 仍是 linux,但要用 android 构建。 */
60
+ /** proot / Termux 里 platform 仍是 linux,但得用 android 构建。 */
53
61
  function detectAndroid() {
54
62
  if (process.env.ANDROID_ROOT || process.env.ANDROID_DATA) return true
55
63
  try {
@@ -59,33 +67,28 @@ function detectAndroid() {
59
67
  }
60
68
  }
61
69
 
62
- /** 程序放插件数据目录,和记忆库(~/AgentsBook)分开。 */
63
- export function backendDir(home = process.env.DSH_HOME ?? join(homedir(), '.dsh')) {
64
- return join(home, 'cache', DATA_DIR, 'bin')
70
+ /** 插件自己的数据目录:放已经加过执行位的二进制副本,和记忆库(~/AgentsBook)分开。 */
71
+ export function backendDir(home = process.env.DSH_HOME ?? joinPath(homedir(), '.dsh')) {
72
+ // home 为空串时 joinPath 会给出相对路径,那种路径会跟着 cwd 乱跑——当成没配处理。
73
+ const base = typeof home === 'string' && home !== '' ? home : joinPath(homedir(), '.dsh')
74
+ return joinPath(base, 'cache', DATA_DIR, 'bin')
65
75
  }
66
76
 
67
77
  export function installedPath(home) {
68
- return join(backendDir(home), BIN_NAME)
78
+ return joinPath(backendDir(home), BIN_NAME)
69
79
  }
70
80
 
71
81
  function versionFile(home) {
72
- return join(backendDir(home), 'VERSION')
82
+ return joinPath(backendDir(home), 'VERSION')
73
83
  }
74
84
 
75
- function readInstalled(home) {
76
- const bin = installedPath(home)
77
- try {
78
- if (!existsSync(bin)) return undefined
79
- const st = statSync(bin)
80
- if (st.size < 100_000) return undefined
81
- const ver = existsSync(versionFile(home)) ? readFileSync(versionFile(home), 'utf8').trim() : ''
82
- return { bin, version: ver, size: st.size }
83
- } catch {
84
- return undefined
85
- }
85
+ /** 包内那份候选文件的绝对路径。 */
86
+ export function vendoredPath(platform, arch, isAndroid) {
87
+ const name = assetName(platform, arch, isAndroid)
88
+ return name === undefined ? undefined : joinPath(VENDOR_DIR, name)
86
89
  }
87
90
 
88
- /** 文件头是不是真二进制——防着拿到一个 HTML 错误页。 */
91
+ /** 文件头是不是真二进制——防着包里混进 HTML 错误页或者被截断的下载。 */
89
92
  function looksExecutable(buf) {
90
93
  if (buf.length < 4) return false
91
94
  const m = buf.subarray(0, 4)
@@ -98,12 +101,37 @@ function looksExecutable(buf) {
98
101
  )
99
102
  }
100
103
 
104
+ /** 已经落地的副本还能不能用:存在、够大、文件头对、版本对得上。 */
105
+ function readInstalled(home, want) {
106
+ const bin = installedPath(home)
107
+ try {
108
+ if (!existsSync(bin)) return undefined
109
+ const st = statSync(bin)
110
+ if (st.size < 100_000) return undefined
111
+ if (!looksExecutable(readFileSync(bin).subarray(0, 4))) return undefined
112
+ const ver = existsSync(versionFile(home)) ? readFileSync(versionFile(home), 'utf8').trim() : ''
113
+ if (typeof want === 'string' && want !== '' && ver !== want) return undefined
114
+ return { bin, version: ver, size: st.size }
115
+ } catch {
116
+ return undefined
117
+ }
118
+ }
119
+
120
+ /** 包内二进制的版本号:包根 package.json 的 version 就是它,两者一起发版。 */
121
+ export function packageVersion() {
122
+ try {
123
+ return JSON.parse(readFileSync(joinPath(PACKAGE_ROOT, 'package.json'), 'utf8')).version ?? ''
124
+ } catch {
125
+ return ''
126
+ }
127
+ }
128
+
101
129
  /**
102
- * 确保后端可用。返回 { bin, version, source } 或抛带 code 的错误。
103
- * source: 'configured' | 'existing' | 'downloaded'
130
+ * 确保后端可用,全程离线。
131
+ * 返回 { bin, version, source },source 为 'configured' | 'cached' | 'vendored'。
104
132
  */
105
133
  export async function ensureBackend(options = {}) {
106
- // 1. 显式配置优先,且不做任何下载
134
+ // 1. 显式配置最优先:用户指了哪个就用哪个,不再自作主张
107
135
  if (typeof options.configured === 'string' && options.configured !== '') {
108
136
  if (!existsSync(options.configured)) {
109
137
  throw backendError('configured-missing', `配置里的 abookPath 不存在:${options.configured}`)
@@ -111,152 +139,50 @@ export async function ensureBackend(options = {}) {
111
139
  return { bin: options.configured, version: 'configured', source: 'configured' }
112
140
  }
113
141
 
114
- // 2. 已经装过且版本对得上,直接用
115
- const home = options.home
116
- const want = options.version // 期望版本;undefined 表示不挑
117
- const have = readInstalled(home)
118
- if (have !== undefined && (want === undefined || want === '' || have.version === want)) {
119
- linkCli(have.bin)
120
- return { bin: have.bin, version: have.version, source: 'existing' }
121
- }
142
+ // 2. 已经放好的副本,且版本与当前插件一致,直接用
143
+ const want = options.version ?? packageVersion()
144
+ const cached = readInstalled(options.home, want)
145
+ if (cached !== undefined) return { bin: cached.bin, version: cached.version, source: 'cached' }
122
146
 
123
- // 3. 下载
124
- if (options.autoInstall === false) {
125
- throw backendError('missing', '后端未安装,且已关闭自动安装。')
147
+ // 3. 从包内取对应架构那一份,复制到插件数据目录
148
+ const src = vendoredPath()
149
+ if (src === undefined) {
150
+ throw backendError(
151
+ 'unsupported-platform',
152
+ `这个包没有附带给 ${process.platform}/${process.arch} 的 abook,插件无法在这个平台上工作。`,
153
+ )
126
154
  }
127
- const asset = assetName()
128
- if (asset === undefined) {
129
- throw backendError('unsupported-platform', `没有适配 ${process.platform}/${process.arch} 的 abook 构建。`)
155
+ if (!existsSync(src)) {
156
+ throw backendError(
157
+ 'vendor-missing',
158
+ `安装包不完整:缺少 ${src.slice(PACKAGE_ROOT.length + 1)}。重装一次插件即可。`,
159
+ )
130
160
  }
131
- const release = await releaseInfo(want)
132
- const url = `https://github.com/${REPO}/releases/download/${encodeURIComponent(release.version)}/${asset}`
133
- const buf = await download(url)
161
+ const buf = readFileSync(src)
134
162
  if (!looksExecutable(buf)) {
135
- throw backendError('bad-download', `${url} 返回的不是可执行文件(前 4 字节 ${[...buf.subarray(0, 4)].map((b) => b.toString(16)).join(' ')})。`)
136
- }
137
- const digest = createHash('sha256').update(buf).digest('hex')
138
- if (digest !== release.digest) {
139
- throw backendError('checksum-mismatch', `${asset} 校验失败:期望 ${release.digest},实际 ${digest}。`)
163
+ throw backendError('bad-vendor', `包内的 ${src.split('/').pop()} 不是可执行文件,安装包可能损坏。`)
140
164
  }
141
165
 
142
- const dir = backendDir(home)
143
- mkdirSync(dir, { recursive: true })
144
- const target = installedPath(home)
166
+ const target = installedPath(options.home)
167
+ mkdirSync(dirname(target), { recursive: true })
145
168
  const suffix = `${process.pid}-${randomBytes(8).toString('hex')}`
146
169
  const tmp = `${target}.tmp-${suffix}`
147
- const versionTmp = `${versionFile(home)}.tmp-${suffix}`
148
170
  try {
149
- writeFileSync(tmp, buf, { mode: 0o755 })
171
+ copyFileSync(src, tmp)
150
172
  if (process.platform !== 'win32') chmodSync(tmp, 0o755)
151
- writeFileSync(versionTmp, `${release.version}\n`, { mode: 0o600 })
152
- renameSync(tmp, target)
153
- renameSync(versionTmp, versionFile(home))
173
+ renameSync(tmp, target) // 原子替换:中途失败不会留下半个文件
174
+ writeFileSync(versionFile(options.home), `${want}\n`, { mode: 0o600 })
154
175
  } finally {
155
176
  try { rmSync(tmp, { force: true }) } catch {}
156
- try { rmSync(versionTmp, { force: true }) } catch {}
157
- }
158
-
159
- linkCli(target)
160
- return { bin: target, version: release.version, source: 'downloaded', bytes: buf.length, sha256: digest }
161
- }
162
-
163
- async function releaseInfo(version) {
164
- const endpoint = version === undefined || version === ''
165
- ? `https://api.github.com/repos/${REPO}/releases/latest`
166
- : `https://api.github.com/repos/${REPO}/releases/tags/${encodeURIComponent(version)}`
167
- let r
168
- try {
169
- r = await fetch(endpoint, {
170
- headers: { 'user-agent': 'dsh-aurorix-agentbook', accept: 'application/vnd.github+json' },
171
- })
172
- } catch (err) {
173
- throw backendError('network', `查 abook 发布信息失败:${err?.message ?? err}`)
174
- }
175
- if (!r.ok) throw backendError('catalog-failed', `查 abook 发布信息失败:HTTP ${r.status}`)
176
- const d = await r.json()
177
- const tag = typeof d.tag_name === 'string' ? d.tag_name : ''
178
- if (!/^v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(tag)) {
179
- throw backendError('catalog-failed', 'GitHub 返回了无效的 abook 版本标识')
180
- }
181
- const asset = assetName()
182
- const entry = Array.isArray(d.assets) ? d.assets.find((x) => x?.name === asset) : undefined
183
- const digest = typeof entry?.digest === 'string' && /^sha256:[0-9a-f]{64}$/.test(entry.digest)
184
- ? entry.digest.slice('sha256:'.length)
185
- : ''
186
- if (digest === '') throw backendError('catalog-failed', `GitHub 没有提供 ${asset} 的 SHA-256 摘要`)
187
- return { version: tag, digest }
188
- }
189
-
190
- async function download(url) {
191
- let r
192
- try {
193
- r = await fetch(url, { redirect: 'follow', headers: { 'user-agent': 'dsh-aurorix-agentbook' } })
194
- } catch (err) {
195
- throw backendError('network', `下载 abook 失败:${err?.message ?? err}`)
196
177
  }
197
- if (!r.ok) throw backendError('download-failed', `下载 ${url} 失败:HTTP ${r.status}`)
198
- const ab = await r.arrayBuffer()
199
- return Buffer.from(ab)
200
- }
201
-
202
-
203
- /**
204
- * 让 `abook` 在 shell 里能直接调,不用带路径。
205
- *
206
- * 做法:往 PATH 里**已有**的目录放一个软链。改的是文件系统,不是环境变量——
207
- * 不写 shell 配置、不改 PATH 定义。找不到可写目录就安静跳过,调用方照旧用绝对路径。
208
- */
209
- export function linkCli(bin, options = {}) {
210
- if (process.platform === 'win32') return { ok: false, reason: 'windows 不做软链' }
211
- const pathEnv = options.pathEnv ?? process.env.PATH ?? ''
212
- const name = options.name ?? 'abook'
213
- try {
214
- // PATH 里已经有指向我们的,就不用动
215
- for (const dir of pathEnv.split(delimiter)) {
216
- if (dir === '') continue
217
- const candidate = joinPath(dir, name)
218
- try {
219
- if (existsSync(candidate) && realpathSync(candidate) === realpathSync(bin)) {
220
- return { ok: true, linked: candidate, reason: 'already' }
221
- }
222
- } catch {}
223
- }
224
- // 找第一个可写目录,优先用户级路径
225
- const dirs = pathEnv.split(delimiter).filter((d) => d !== '')
226
- const preferred = [
227
- ...dirs.filter((d) => d.includes('.local/bin')),
228
- ...dirs.filter((d) => !d.includes('.local/bin')),
229
- ]
230
- for (const dir of preferred) {
231
- try {
232
- if (!existsSync(dir)) continue
233
- accessSync(dir, fsConstants.W_OK)
234
- const target = joinPath(dir, name)
235
- // Never replace an existing PATH command: it may belong to the user or another package.
236
- try {
237
- symlinkSync(bin, target)
238
- return { ok: true, linked: target, reason: 'created' }
239
- } catch (err) {
240
- if (err?.code === 'EEXIST') {
241
- try {
242
- if (realpathSync(target) === realpathSync(bin)) {
243
- return { ok: true, linked: target, reason: 'already' }
244
- }
245
- } catch {}
246
- }
247
- continue
248
- }
249
- } catch {
250
- continue
251
- }
252
- }
253
- } catch (err) {
254
- return { ok: false, reason: String(err?.message ?? err) }
178
+ return {
179
+ bin: target,
180
+ version: want,
181
+ source: 'vendored',
182
+ sha256: createHash('sha256').update(buf).digest('hex'),
255
183
  }
256
- return { ok: false, reason: 'PATH 里没有可写目录' }
257
184
  }
258
185
 
259
-
260
186
  const LAYOUT_MARKER = 'abook.memory.layout.v1'
261
187
  const PLANES = ['soul', 'rules', 'profile', 'explicit', 'long_term', 'episodic']
262
188
 
package/lib/cli-manual.js CHANGED
@@ -7,7 +7,8 @@ export const CLI_MANUAL = [
7
7
  "",
8
8
  "## 怎么直接用",
9
9
  "",
10
- "插件安装后会在 PATH 里建一个软链,终端里直接敲 `abook` 就行,不用带路径:",
10
+ "二进制随插件包一起发,按当前平台架构挑对应那份,不装进系统、不写 PATH。",
11
+ "要在 shell 里用它,走插件的 shell 工具(`aurorix_sh`)——它只对那一条子进程前置 PATH,那里直接敲 `abook` 就行:",
11
12
  "",
12
13
  "```sh",
13
14
  "abook version # 看版本与平台标记",
package/lib/guide.js CHANGED
@@ -28,7 +28,7 @@ export const GUIDE = {
28
28
  // 工具面与命令口径(含命名、发行源、接入、命令参数)
29
29
  tools: [
30
30
  "`AURORIX_ABOOK_NAMING_GATE`=`Aurorix`是记忆机制的名称,不是可执行命令名、MCP `serverName`或工具名前缀;命令行工具固定叫`abook`;需要记忆能力时优先使用 abook MCP.相关 MCP 的`serverName`、服务标签和工具标识应显著包含`abook`(通常为`abook`或`abook-mcp`),不得把服务直接命名为`Aurorix memory`或只用该机制名充当服务标识.",
31
- "`ABOOK_RELEASE_SOURCE_GATE`=`abook`不是 npm 上同名书籍生成包,也不是`agentbook`等其他项目;权威发行源固定为 GitHub 仓库`https://github.com/Sharl210/abook`及其 Releases 页面`https://github.com/Sharl210/abook/releases`.Android ARM64 使用资产`abook-aarch64-linux-android`;下载后先核对 GitHub Release 资产摘要与 SHA-256,再原子安装到`~/AgentsBook/abook`并保留上一版备份.不得因 PATH、`~/AgentsBook`或当前工作目录暂时没有文件就改装 npm 同名包、猜测其他来源或声称记忆机制不存在.",
31
+ "`ABOOK_RELEASE_SOURCE_GATE`=`abook`不是 npm 上同名书籍生成包,也不是`agentbook`等其他项目;上游仓库是 GitHub 的`https://github.com/Sharl210/abook`.但**运行时不需要也不允许去那里下载**:二进制已按平台架构随插件包一起发(`vendor/` 下 15 份),插件按 `process.platform`/`process.arch` 挑对应那份复制到自己的数据目录并加执行位,全程离线、不装系统目录、不写 PATH、不写 shell 配置.因此:报「后端不可用」时先看是不是这台机器的平台没有对应构建(插件会明确说哪个 os/arch),不要去 GitHub 找、不要自己下载、不要改用 npm 同名包或别的来源;插件与二进制同仓库维护同版本发布,不存在「单独升级二进制」这条路,升级就是升插件.",
32
32
  "`MEMORY_MCP_FIRST_GATE`=**abook 的 MCP 工具优先于 abook 命令行,范围是全部任务与执行,不只是记忆.**这里的 MCP 专指 abook 自己的 MCP 服务(serverName 通常是 abook):别的 MCP 有自己的工具面,不得替代它,也不得因为别的 MCP 在场就认为 abook 已接入.①只要 abook 的 MCP 工具在工具清单里,凡涉及记忆库的读写检索维护就一律走工具调用;`abook` CLI 只在两种情形下允许:该能力确实没有对应工具,或明确属于历史库兼容与迁移;同一件事两者都能做时,工具是唯一默认路径,不是「建议优先」.②「实在用不了」不是感觉,要能被复核:先确认工具在清单里(`tools/list`),再用`memory_help`或`describe`取过参数面,把报错原文读明白并按`ERROR_FIRST_REPAIR_GATE`修过一轮,仍不通才允许退;只凭「调了一次失败」「我记得没这功能」「太麻烦」就敲命令,一律按违反本条处理,因为那多半是参数名写错或没查清单.退到 CLI 时须在同一轮说明是哪一条用不了、试过什么、错误原文是什么;说不出来就当没试过.③按要做的事找入口,不要按记忆里的旧清单:`memory_init`空库起步(幂等);总览`memory_context`/`memory_index`/`memory_paths`;找`memory_search`(可限定字段、`regex`走正则)、`memory_recall`(历史事实,回答\"以前记过什么\")、`memory_grep`(要行号或前后文;search 答哪条记录,grep 答哪一行);看`memory_read`单条、`memory_list`分页(可过滤`status`/`kind`,含软删)、`memory_trash`回收站、`memory_history`看一条怎么变成现在这样;写`memory_write`/`memory_update`(可改任意头部字段)/`memory_move_plane`换平面/`memory_merge`合并(被并入者软删)/`memory_split`按分隔符拆(原记录软删并记派生);删与恢复`memory_delete`/`memory_restore`;批量`memory_batch_preview`→`apply`/`status`/`rollback`,preview 优先用`records`数组按记录改(每项 id 与 expected_revision,工具算版本与正文),`path`+`body`按文件改只作兜底;先 preview 拿 token 再 apply,一批有一条不合法则整批不动;全量备份`memory_export`(凭据不出明文).两者共用同一内核与同一库,禁两套各写一份或各建一库.库维护与导航都在工具面上:state/stats/doctor/lint/audit/reconcile/repair/sync/refresh/normalize/refs/leftover/recount/tree/map/atlas/paths/budget/log/recent/get(前缀`abook_`),查状态、对账、看结构一律用它们,用途按`abook describe <命令>`现取,不逐个背;少数仍只在 CLI 且不必去试:`identity`/`path`/`related`/`diff`/`check`(依赖旧两库Global.md、Atlas 或旧记录结构)与`attach sync`/`commit`/`txn`/`vault import`(要外部文件或令牌).④工具 schema 用`tools/list`/`memory_help`现取,不凭记忆写参数名;工具面会随版本增加,每次动手前现取的清单才是准的.⑤工具不可用或调用失败时,先按`ERROR_FIRST_REPAIR_GATE`修因,禁把\"那就用命令行\"当作默认退路;确属工具面未覆盖才退回CLI.⑥\"工具里没有\"这个判断必须先`tools/list`核实:凭印象断言某个能力没有工具入口,是本条最容易失守的地方,也是退回CLI最常见的原因.",
33
33
  "`MCP_ATTACH_BOOTSTRAP_GATE`=**环境未接入 abook 的 MCP 时,接入本身就是当前第一优先任务,先配好再干活.**①判据:凡本轮任务要读写记忆库,开工第一个动作就是确认 abook 的 MCP 工具在不在清单里;不在即命中,此时立刻转入接入流程,不要先用 CLI 把活干完再回头配——那样接入会无限期搁置,后续每轮都同样退在 CLI 上.②动作顺序:取到可执行文件(库根下的`abook`本身可执行,`abook detect`说明该用哪个架构包) → 立刻为本环境完成 MCP 接入 → **在配置里把记忆库根一并固定** → `tools/list`确认真可见 → 再开始原任务.③库根必须写进配置:`mcp` 支持启动参数,配置时就把库根写进 `args`(形如 `mcp stdio --root <库根>`),此后所有调用都不必再传`root`.理由:`MCP_PLANE_ROOT_PRIORITY`=显式传参 > 配置期固定 > 运行时推导;配置期排在前因为写进客户端配置的路径唯一、可复核、不随环境漂移,而推导取决于二进制位置、环境变量与 cwd,任一处变动就指向另一个库,那时看到的是\"没有找到记录\"这类看着像数据问题的错误.库根用`detect`或`memory_paths`查一次即可.④配置方法按当前环境的实际机制决定:宿主文档、已有配置文件、环境变量、自己的探查都能给出答案;**不写任何具体宿主的分步手册**——写死一家会误导别家,而环境信息本就在手边.⑤接入失败:保留原目标,列已试步骤与原样错误,标`BLOCKED`并列解除条件,禁静默退回 CLI 充当已完成.⑥接入后按`MEMORY_MCP_FIRST_GATE`走工具面.",
34
34
  "`CAPABILITY_DISCLOSURE`=工具能力已知可用,按场景直接调用,禁\"可能有这个功能吧\"式试探.**命令清单不写进本文件**——`abook commands` 一条命令就给全量(条数随版本变,现取现用,禁凭记忆报数),单条契约用 `abook describe <命令>`.在这里抄一份清单,一是必然过期(已经出现过写 76 条而实际 78 条),二是占掉每轮额度;而门缺了没地方现取,命令会现取,所以该省的正是清单.高频易错只在`ABOOK_CLI_ENTRY_GATE`保留判据级规则,其余现取现用.",
@@ -114,7 +114,7 @@ export const GUIDE = {
114
114
  // 库根、启动与失败处置
115
115
  root: [
116
116
  "`MEMORY_ROOT_RESOLUTION_GATE`=**库根由`abook`自己决定,不由环境变量决定**:程序所在目录与记忆库同层(该目录含`Global.md`/`Index.md`/`planes`/`vault`时即为库根),所以`~/AgentsBook/abook`天然知道自己的库在哪,换shell、换会话、换调用方式答案都一样.解析优先级只有一条链:`--root`显式指定 → 程序所在目录 → `$ABOOK_ROOT`(仅老脚本兼容) → `~/AgentsBook`.",
117
- "`COLD_START_ENTRY_GATE`=只有命令不存在(`command not found`/`No such file`)才进本段;退码2/3/5/6是用法、数据或完整性问题,按`MEMORY_FAILURE_GATE`处置,不走安装.安装点只有一个:记忆库根(与`Global.md`/`Index.md`同层,默认`~/AgentsBook`);首次安装用发布包内`install.sh`或官方安装入口,升级用`abook upgrade`,下载、文件头校验、SHA-256、原子替换、`detect`与`selftest`都由工具完成.禁手拼多源下载、禁凭记忆写版本号、禁自行编译替代、禁装系统目录、禁改PATH或任何shell配置、禁chown系统文件.Android上自身路径不得用`current_exe`推断(指向linker64),升级工具已内置该判断,自写脚本禁绕开.工具报\"拿不到当前程序路径\"时加`--dir <库根>`;装完仍不可用→`BLOCKED`并列全部源与原样错误.",
117
+ "`COLD_START_ENTRY_GATE`=**命令不存在(`command not found`/`No such file`)不再是一个需要处理的场景**:二进制随插件包安装,已经在 PATH 之外就位,常驻在插件自己的数据目录里,由插件在每次调用时用绝对路径拉起.所以这个错误只可能来自「绕过插件自己敲命令」——那属于违规路径,不要顺着它去装东西.真的取不到二进制时(平台没有对应构建、安装包缺文件)插件会给出明确的 `error.code`:如实转述那个错误并列解除条件(通常是「这台机器的 os/arch 没有构建」或「重装插件」),禁自行下载、禁自行编译、禁装系统目录、禁改 PATH 或 shell 配置.`repo root 与程序所在目录`的关系不变:程序在插件数据目录,库根默认`~/AgentsBook`,两者分离.`UPDATE_VERIFY_GATE`/`UPDATE_CACHE_WINDOW_GATE` 两条依赖下载与镜像的规则已不适用,仅在讨论上游仓库本身时参考.",
118
118
  "`COLD_START_NOT_RETRY`=退码2/3/5/6是用法、数据或完整性问题,不走安装;只有命令不存在才算工具没装.",
119
119
  "`UPDATE_VERIFY_GATE`=替换后必须同时满足:文件头为`ELF`/`Mach-O`/`MZ`之一、SHA-256与发布清单一致、原命令重试成功、`abook detect`报就绪、`abook selftest`通过;任一不过即保留旧二进制并回滚.镜像与缓存差异以`abook help upgrade`现取为准,不在本文件维护镜像表.",
120
120
  "`BOOTSTRAP_USER_SCOPE_GATE`=整条链路只动当前用户:禁装系统/共享目录、禁改shell配置、禁chown系统文件.",
package/lib/host.js CHANGED
@@ -245,7 +245,19 @@ export function attachHost(ctx, deps) {
245
245
 
246
246
  const recall = scope.tools.register({
247
247
  name: 'aurorix_recall',
248
- description: '在记忆库按话题检索条目,返回平面、标题、记录 ID 与正文摘要。需要全文时再读。',
248
+ description:
249
+ '在记忆库按话题检索条目,返回平面、标题、记录 ID 与正文摘要。\n' +
250
+ '**查记忆是本会话的默认动作,不是可选项。** 检索一次几十毫秒,重复踩一次坑要花掉一整轮——' +
251
+ '成本差两个数量级,不确定时永远选查。\n' +
252
+ '下面任一条命中就直接调,不要先判断「值不值得查」:\n' +
253
+ '- 一开始动代码、改配置、跑构建、发版、写文件之前(上次踩过的坑就在库里)\n' +
254
+ '- 用户提到「以前 / 上次 / 之前 / 记得 / 记过 / 我是不是说过」\n' +
255
+ '- 遇到陌生的库、仓库、包、设备、接口、报错原文\n' +
256
+ '- 用户说的东西和你的印象不一致,或你正准备说「应该 / 大概 / 一般来说」\n' +
257
+ '- 上下文被压缩过,或这是跨会话续接\n' +
258
+ '- 准备写记忆之前(先查有没有同一条,避免重复开新条)\n' +
259
+ '禁把「这轮简单」「刚聊过」「我应该记得」当跳过理由:漏查的代价是重复踩坑,查一次的代价是一次工具调用。\n' +
260
+ '检索词用话题词,不要用整句;推荐先广后窄:先一个词看面上有什么,再收窄。',
249
261
  parameters: {
250
262
  type: 'object',
251
263
  properties: {
@@ -283,7 +295,20 @@ export function attachHost(ctx, deps) {
283
295
 
284
296
  const remember = scope.tools.register({
285
297
  name: 'aurorix_remember',
286
- description: '向记忆库写入一条记录。短小关键点写 explicit,完整经过与可复用结论写 long_term,单次事件写 episodic。',
298
+ description:
299
+ '向记忆库写入一条记录。**写入不需要批准,直接写**——宁多一条,不要让有用的经验随会话消失。\n' +
300
+ '平面选择:\n' +
301
+ '- `explicit` —— 用户明说「记住」的短关键点、约定、决策\n' +
302
+ '- `long_term` —— 完整经过、根因、可复用结论、踩过的坑(最常用)\n' +
303
+ '- `episodic` —— 单次事件、过程、证据\n' +
304
+ '- `profile` —— 用户稳定偏好、称呼、环境事实\n' +
305
+ '- `soul` —— 你自己的稳定行为原则\n' +
306
+ '- `rules` —— 硬性约束\n' +
307
+ '**这些时刻就该写,不要等用户提**:做了决定(尤其是排除了别的方案,把为什么排除也写进去)、' +
308
+ '被用户纠正、踩坑并查明根因、交付完一个单元、发现库里某条已经过时、' +
309
+ '发现平台或工具的隐蔽差异、用户表达了稳定偏好。\n' +
310
+ '不值得写的:寒暄、没有未来用途的过程日志、能从代码直接读到的内容。\n' +
311
+ '同一件事更新同一条(先 `aurorix_recall` 查有没有),不要重复开新条。',
287
312
  parameters: {
288
313
  type: 'object',
289
314
  properties: {
@@ -450,7 +475,8 @@ export function attachHost(ctx, deps) {
450
475
  name: 'aurorix_sh',
451
476
  description:
452
477
  '在本机 shell 里跑一条命令(bash -c)。能用管道、重定向、grep、sed、awk、jq、python 脚本——整理记忆时搜关键字、批量替换、统计都靠它。\n' +
453
- 'abook 已经在 PATH 里,直接打 `abook ...` 就行,不用带路径。\n' +
478
+ 'abook 二进制归插件所有,不在系统 PATH 里:本工具只对这一条子进程前置 PATH,' +
479
+ '所以在这里可以直接打 `abook ...`;系统别处(包括普通终端)没有它,也别去 PATH 里找或另装一份。\n' +
454
480
  '**唯一要记的坑**:abook 的输出不要接 head / tail / cut -c / sed -n 范围——它检测到截断会把整份结果丢弃。要控篇幅用 --limit / --page / --json;要加工就先重定向到文件,再用别的命令读那个文件。\n' +
455
481
  '输出超过 200KB 会被整份拒收并提示收窄,不会给你半截。\n' +
456
482
  `当前 shell:${SHELL.name}(${SHELL.kind})。` +
package/lib/index.js CHANGED
@@ -30,7 +30,6 @@ function readSettings(config) {
30
30
  abookPath: String(get('abookPath') || ''),
31
31
  root: String(get('root') || ''),
32
32
  home: String(get('home') || ''),
33
- autoInstall: get('autoInstall', true) !== false,
34
33
  }
35
34
  }
36
35
 
@@ -40,7 +39,6 @@ export function apply(ctx, config) {
40
39
  configured: settings.abookPath || undefined,
41
40
  root: settings.root || undefined,
42
41
  home: settings.home || undefined,
43
- autoInstall: settings.autoInstall,
44
42
  })
45
43
  const w = (locale) => words(locale)
46
44
 
package/lib/snapshot.js CHANGED
@@ -51,18 +51,30 @@ export const DEFAULT_MANUAL = [
51
51
  "- `episodic` —— 按时间记的事件、过程、证据与会话经过",
52
52
  "- `credentials` —— 凭据保险箱,独立存放,走专用入口,不混进普通检索",
53
53
  "",
54
- "### 什么时候主动查",
54
+ "### 什么时候主动查(默认动作,不是可选项)",
55
55
  "",
56
- "**记忆不是等用户问才查的东西。** 命中下面任一就查,别先判断「值不值得查」:",
56
+ "**查记忆是本会话的默认动作:命中下面任一就直接调 `aurorix_recall`,不要先判断「值不值得查」。**",
57
+ "检索一次几十毫秒,重复踩一次坑要花掉整轮;成本差着两个数量级,所以不确定时永远选查。",
57
58
  "",
58
- "1. 工程类动作(碰工件、写盘、跑命令、构建、发版)",
59
- "2. 用户提到「以前 / 上次 / 之前 / 记得 / 记忆」",
60
- "3. 对象陌生(不认识的库、仓库、包、设备、流程)",
61
- "4. 跨会话续接,或上下文被压缩过",
62
- "5. 要写记忆、归置平面或迁移之前",
59
+ "必查清单:",
60
+ "",
61
+ "1. 动手之前——写盘、改代码、改配置、跑命令、构建、发版、迁移",
62
+ "2. 用户提到「以前 / 上次 / 之前 / 记得 / 记过 / 我是不是说过」",
63
+ "3. 遇到陌生的库、仓库、包、设备、接口、报错原文、陌生路径",
64
+ "4. 上下文被压缩过,或这是跨会话/跨任务的续接",
65
+ "5. 你正准备说「应该 / 大概 / 一般来说 / 我记得」的时候(这类措辞出现,说明你在凭印象答)",
66
+ "6. 要写记忆之前(先查有没有同一条,避免重复开新条)",
63
67
  "",
64
68
  "路径固定三步:**看快照 → 按话题检索 → 读命中正文**。快照里只有标题的,原文在库里。",
65
- "禁把「这轮简单」「刚聊过」「应该没记过」当跳过理由——漏查的成本远高于查一次。",
69
+ "",
70
+ "禁把这几种说法当跳过理由——它们都不成立:",
71
+ "",
72
+ "- 「这轮很简单」:简单轮正是踩重复坑最多的地方",
73
+ "- 「刚聊过」:刚聊过的是当前上下文,不是历史结论",
74
+ "- 「我应该记得」:记得的是印象,库里的是原文,两者冲突时以库为准",
75
+ "- 「先做完再查」:查完再做,比做完再返工便宜",
76
+ "",
77
+ "**做完一件有结论的事就顺手写一条**:不是因为用户要求,是因为下轮可能用得上。",
66
78
  "",
67
79
  "### 四个工具",
68
80
  "",
package/lib/web.js CHANGED
@@ -371,59 +371,94 @@ refreshVault();
371
371
  }
372
372
 
373
373
  /** 往页面里塞一个侧边栏入口。等 SPA 把导航渲染出来再插,避免插到还没生成的容器里。 */
374
- export function sidebarScript(prefix, title) {
374
+ /**
375
+ * 网页端的入口:一个自绘的悬浮按钮 + 点开后的 iframe 弹层。
376
+ *
377
+ * 为什么不再往侧边栏塞一项:
378
+ * 侧边栏是靠克隆宿主导航项、再替换文字和图标做出来的,依赖的是宿主每次构建都会变
379
+ * 的类名和 DOM 结构——宿主一改版就错位,而且视觉上永远像"贴上去的"。改用自绘的
380
+ * 悬浮按钮后,只依赖 document.body 和一段内联样式,宿主怎么改版都不影响;
381
+ * 面板用 iframe 装,页面自己的样式和宿主的样式互不污染。
382
+ *
383
+ * 权限与宿主保持一致:页面本身仍然要求 Host/Origin 校验与已认证的身份,
384
+ * 换个展现形式不放宽任何访问条件。
385
+ */
386
+ export function floatButtonScript(prefix, title) {
375
387
  return `(function(){
376
388
  if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
377
389
  var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
378
390
 
379
- // 记忆库图标(书本 + 书签),24×24,跟宿主图标同规格
380
391
  var ICON = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5.5A1.5 1.5 0 0 1 5.5 4H10a2 2 0 0 1 2 2v14a1.5 1.5 0 0 0-1.5-1.5H5.5A1.5 1.5 0 0 1 4 17V5.5Z"/><path d="M20 5.5A1.5 1.5 0 0 0 18.5 4H14a2 2 0 0 0-2 2v14a1.5 1.5 0 0 1 1.5-1.5h5A1.5 1.5 0 0 0 20 17V5.5Z"/></svg>';
381
-
382
- function setText(el, text){
383
- var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
384
- var node, hit = false;
385
- while ((node = walker.nextNode())) {
386
- if (node.textContent.trim() === '') continue;
387
- node.textContent = text; hit = true; break;
392
+ var CLOSE = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>';
393
+
394
+ var CSS = ''
395
+ + '.ax-fab{position:fixed;right:18px;bottom:18px;z-index:2147483000;display:flex;align-items:center;gap:7px;'
396
+ + 'padding:9px 14px;border-radius:999px;border:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.28));'
397
+ + 'background:var(--dsl-alias-bg-l2,#1b1f1e);color:var(--dsl-alias-text-l1,#e9efee);'
398
+ + 'font:13px/1 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;cursor:pointer;'
399
+ + 'box-shadow:0 6px 24px rgba(0,0,0,.28);transition:transform .12s,box-shadow .12s}'
400
+ + '.ax-fab:hover{transform:translateY(-1px);box-shadow:0 10px 30px rgba(0,0,0,.34)}'
401
+ + '.ax-mask{position:fixed;inset:0;z-index:2147483001;background:rgba(0,0,0,.42);display:none}'
402
+ + '.ax-mask.ax-on{display:block}'
403
+ + '.ax-panel{position:fixed;right:18px;bottom:74px;z-index:2147483002;display:none;'
404
+ + 'width:min(560px,calc(100vw - 36px));height:min(760px,calc(100vh - 140px));'
405
+ + 'border-radius:14px;overflow:hidden;background:var(--dsl-alias-bg-l1,#0d1110);'
406
+ + 'border:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.28));box-shadow:0 24px 64px rgba(0,0,0,.45)}'
407
+ + '.ax-panel.ax-on{display:flex;flex-direction:column}'
408
+ + '.ax-head{display:flex;align-items:center;justify-content:space-between;gap:10px;'
409
+ + 'padding:9px 12px;border-bottom:1px solid var(--dsl-alias-border-l2,rgba(127,127,127,.22));flex:0 0 auto}'
410
+ + '.ax-title{font:600 13.5px/1.2 -apple-system,system-ui,"PingFang SC",sans-serif;color:var(--dsl-alias-text-l1,#e9efee)}'
411
+ + '.ax-x{display:flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:8px;'
412
+ + 'border:0;background:transparent;color:inherit;cursor:pointer;opacity:.7}'
413
+ + '.ax-x:hover{opacity:1;background:rgba(127,127,127,.14)}'
414
+ + '.ax-frame{flex:1 1 auto;width:100%;border:0;background:transparent}'
415
+ + '@media (max-width:700px){.ax-panel{right:8px;left:8px;bottom:66px;width:auto;height:calc(100vh - 120px)}}';
416
+
417
+ function boot(){
418
+ var style = document.createElement('style');
419
+ style.textContent = CSS;
420
+ document.head.appendChild(style);
421
+
422
+ var mask = document.createElement('div'); mask.className = 'ax-mask';
423
+ var panel = document.createElement('div'); panel.className = 'ax-panel';
424
+ panel.setAttribute('role','dialog'); panel.setAttribute('aria-label', NAME);
425
+
426
+ var head = document.createElement('div'); head.className = 'ax-head';
427
+ var ttl = document.createElement('div'); ttl.className = 'ax-title'; ttl.textContent = NAME;
428
+ var x = document.createElement('button'); x.className = 'ax-x'; x.type = 'button';
429
+ x.setAttribute('aria-label','关闭'); x.innerHTML = CLOSE;
430
+ head.appendChild(ttl); head.appendChild(x);
431
+ var frame = document.createElement('iframe'); frame.className = 'ax-frame'; frame.title = NAME;
432
+ panel.appendChild(head); panel.appendChild(frame);
433
+
434
+ var fab = document.createElement('button'); fab.className = 'ax-fab'; fab.type = 'button';
435
+ fab.innerHTML = ICON; fab.appendChild(document.createTextNode(NAME));
436
+
437
+ var loaded = false;
438
+ function open(){
439
+ // 首次打开才建 iframe:不打开就不发请求,也不占内存
440
+ if (!loaded) { frame.src = HREF; loaded = true; }
441
+ mask.classList.add('ax-on'); panel.classList.add('ax-on');
442
+ x.focus();
388
443
  }
389
- if (!hit) el.appendChild(document.createTextNode(text));
390
- }
391
-
392
- function insert(){
393
- if (document.querySelector('[data-aurorix-entry]')) return true;
394
- var nav = document.querySelector('nav[aria-label], aside nav, nav, [role="navigation"]');
395
- if (!nav) return false;
396
-
397
- // 拿一个真实的导航项当样板,克隆它的 class 和层级,样式就不会割裂。
398
- var sample = Array.prototype.find.call(nav.querySelectorAll('a,button'), function(el){
399
- var t = (el.textContent || '').trim();
400
- return t.length > 0 && t.length <= 8 && !el.querySelector('input');
444
+ function close(){
445
+ mask.classList.remove('ax-on'); panel.classList.remove('ax-on');
446
+ fab.focus();
447
+ }
448
+ fab.onclick = open;
449
+ x.onclick = close;
450
+ mask.onclick = close;
451
+ document.addEventListener('keydown', function(e){
452
+ if (e.key === 'Escape' && panel.classList.contains('ax-on')) close();
401
453
  });
402
454
 
403
- if (!sample) return false;
404
- var el = sample.cloneNode(true);
405
- el.setAttribute('data-aurorix-entry','');
406
- if (el.tagName === 'A') { el.href = HREF; el.target = '_blank'; el.rel = 'noopener'; }
407
- else { el.onclick = function(){ window.open(HREF, '_blank', 'noopener'); }; }
408
- el.removeAttribute('aria-current');
409
- el.removeAttribute('data-active');
410
- if (el.className && typeof el.className === 'string') el.className = el.className.replace(/\bactive\b/g, '').trim();
411
-
412
- // 换图标:保留宿主图标的容器与尺寸,只换内容。
413
- var svg = el.querySelector('svg');
414
- if (svg) { var box = document.createElementNS('http://www.w3.org/2000/svg','svg'); box.innerHTML = ICON; svg.replaceWith(box.firstChild); }
415
- setText(el, NAME);
416
-
417
- sample.parentNode.insertBefore(el, sample.nextSibling);
418
- return true;
455
+ document.body.appendChild(mask);
456
+ document.body.appendChild(panel);
457
+ document.body.appendChild(fab);
419
458
  }
420
459
 
421
- var tries = 0;
422
- var timer = setInterval(function(){
423
- var ok = false;
424
- try { ok = insert(); } catch (e) { ok = true; }
425
- if (ok || ++tries > 60) clearInterval(timer);
426
- }, 400);
460
+ if (document.body) boot();
461
+ else document.addEventListener('DOMContentLoaded', boot);
427
462
  })();`
428
463
  }
429
464
 
@@ -518,7 +553,7 @@ export function createWebHandler({ backend, connection }) {
518
553
 
519
554
  const lang = url.searchParams.get('lang') === 'en' ? 'en' : 'zh-CN'
520
555
  const cspNonce = randomBytes(18).toString('base64')
521
- const csp = `default-src 'none'; script-src 'nonce-${cspNonce}'; style-src 'nonce-${cspNonce}'; connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'`
556
+ const csp = `default-src 'none'; script-src 'nonce-${cspNonce}'; style-src 'nonce-${cspNonce}'; connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'self'`
522
557
  if (path === PREFIX) {
523
558
  res.writeHead(308, { location: `${PREFIX}/`, 'cache-control': 'no-store', 'referrer-policy': 'no-referrer' })
524
559
  res.end()
@@ -530,7 +565,7 @@ export function createWebHandler({ backend, connection }) {
530
565
  'cache-control': 'no-store',
531
566
  'x-content-type-options': 'nosniff',
532
567
  'referrer-policy': 'no-referrer',
533
- 'x-frame-options': 'DENY',
568
+ 'x-frame-options': 'SAMEORIGIN',
534
569
  'content-security-policy': csp,
535
570
  })
536
571
  res.end(pageHtml(lang, cspNonce))
@@ -707,7 +742,7 @@ export function attachWeb(ctx, { backend }) {
707
742
  handler: createWebHandler({ backend, connection: webCtx.connection }),
708
743
  }), 'dsh-aurorix-agentbook: web route')
709
744
  const off = webCtx.effect(() => ctx.on('webserver/index-inject', (table) => {
710
- table.push({ kind: 'script', placement: 'body-end', text: sidebarScript(PREFIX, PAGE_TITLE) })
745
+ table.push({ kind: 'script', placement: 'body-end', text: floatButtonScript(PREFIX, PAGE_TITLE) })
711
746
  }), 'dsh-aurorix-agentbook: sidebar injection')
712
747
  return () => {
713
748
  try { dispose() } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aurorix-agentbook",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "description": "dsh-aurorix-agentbook:给 dsh-go 接通 Aurorix 记忆库——原生界面(状态条/胶囊/菜单/面板/保险箱)加宿主侧提示词注入、分层快照与四个工具。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -89,6 +89,7 @@
89
89
  },
90
90
  "files": [
91
91
  "lib/",
92
+ "vendor/",
92
93
  "scripts/",
93
94
  "cordis.patch.yml",
94
95
  "README.md",
@@ -0,0 +1,15 @@
1
+ 11602ede9dbab6bbc8206c5b248b87cfe9430a5fc5335ab3b165c8f8c772012c abook-aarch64-apple-darwin
2
+ c57a607aa3828a1fdbe8baf7f675873dfe30a01bf67ced1dba86fae41ecf79bc abook-aarch64-linux-android
3
+ a0af94bed932e741d25d5cf9287c622839c84a6c5949a3a1a77c6557f4df9d02 abook-aarch64-pc-windows-gnullvm.exe
4
+ 6fb8752018a9baeeac9206735db61a95b19b22efae2dc5eb203c374d90d55877 abook-aarch64-unknown-linux-musl
5
+ 62614b3e93883dae4fe16459052cb7bfc9d5af70fcf9d4895e33d8a2beef7b46 abook-armv7-linux-androideabi
6
+ 387063071728e1a531d11dab181ec72bc845c4d17b2a69fa8f79b3c476c94e8a abook-armv7-unknown-linux-musleabihf
7
+ 7247523a0e64a1335e45ec6ddd406f6b27ec024bd7ed954f3eed6900dbb87438 abook-i686-linux-android
8
+ a38591e67e88a722a967ca8507b764afda446b614bb0e837fe40e6432d526f89 abook-i686-pc-windows-gnullvm.exe
9
+ 6fe669aa25b285d21e9732be0ad22fcee5ba75e11df89fb0536d7ce1f8e54d2a abook-i686-unknown-linux-musl
10
+ 9dec52adaf0abaa8d9d94bca2c7457fef2f019b118d12277795508089495b126 abook-loongarch64-unknown-linux-gnu
11
+ f1a85d17acbfb38568b65ce953d971a30e087424c4f87f49392ca4ae684135fa abook-riscv64gc-unknown-linux-gnu
12
+ b652bfb48c404667cc6daf6a6c5a33b083d9d330e059fd6146e44f854f27b5bc abook-x86_64-apple-darwin
13
+ f16b21d0b19ef2e376794799bec5ae703afb96b06c4c633509f5befce59fae3c abook-x86_64-linux-android
14
+ 4700ca9ca417c2caceaf4f45c801051730390d438fe1bd019a7f8f228f594ae6 abook-x86_64-pc-windows-gnullvm.exe
15
+ 482297d92dba4944b28deab9005fea6c95069cce222c2d6f1b3691e1ef4c9884 abook-x86_64-unknown-linux-musl
Binary file
Binary file