dsh-aurorix-agentbook 1.2.0 → 1.4.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/cordis.patch.yml +1 -1
- package/lib/abook.js +10 -2
- package/lib/backend.js +31 -0
- package/lib/host.js +85 -1
- package/package.json +1 -1
package/cordis.patch.yml
CHANGED
package/lib/abook.js
CHANGED
|
@@ -3,7 +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
|
+
import { ensureBackend, ensureLibrary, installedPath } from './backend.js'
|
|
7
7
|
import { join } from 'node:path'
|
|
8
8
|
|
|
9
9
|
const TIMEOUT_MS = 20_000
|
|
@@ -125,7 +125,7 @@ export function createBackend(options = {}) {
|
|
|
125
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
|
+
: join(homedir(), 'AgentsBook')
|
|
129
129
|
const home = typeof options === 'object' ? options.home : undefined
|
|
130
130
|
const version = typeof options === 'object' ? options.version : undefined
|
|
131
131
|
const autoInstall = typeof options === 'object' ? options.autoInstall : undefined
|
|
@@ -155,10 +155,18 @@ export function createBackend(options = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// 每次调用都带上 --root:库根显式固定,不依赖引擎进程的 cwd 或环境变量。
|
|
158
|
+
// 库骨架只检查一次:装了插件但本机没有库时,这里把它建出来。
|
|
159
|
+
let libReady
|
|
160
|
+
function ensureLib() {
|
|
161
|
+
if (libReady === undefined) libReady = Promise.resolve(ensureLibrary(root))
|
|
162
|
+
return libReady
|
|
163
|
+
}
|
|
164
|
+
|
|
158
165
|
async function call(args, input) {
|
|
159
166
|
let b
|
|
160
167
|
try {
|
|
161
168
|
b = await ensureBin()
|
|
169
|
+
await ensureLib()
|
|
162
170
|
} catch (err) {
|
|
163
171
|
// 后端装不上不该让整个插件崩:返回一条可读的失败,界面层照常显示提示。
|
|
164
172
|
return { ok: false, code: err?.code ?? 'backend-unavailable', stdout: '', stderr: err?.message ?? String(err), json: undefined }
|
package/lib/backend.js
CHANGED
|
@@ -221,6 +221,37 @@ export function linkCli(bin, options = {}) {
|
|
|
221
221
|
return { ok: false, reason: 'PATH 里没有可写目录' }
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
|
|
225
|
+
const LAYOUT_MARKER = 'abook.memory.layout.v1'
|
|
226
|
+
const PLANES = ['soul', 'rules', 'profile', 'explicit', 'long_term', 'episodic']
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 六平面库的最小骨架。用户第一次装插件时本机什么都没有,得能自己建出来。
|
|
230
|
+
*
|
|
231
|
+
* 注意不要用 `abook init`:那条命令建的是老的两层结构(canonical/candidate),
|
|
232
|
+
* 和六平面互斥——先 init 再放 marker 会报「混入旧模型标记」。
|
|
233
|
+
*
|
|
234
|
+
* 返回:'ready' | 'created' | 'legacy' | 'blocked'
|
|
235
|
+
*/
|
|
236
|
+
export function ensureLibrary(root) {
|
|
237
|
+
if (typeof root !== 'string' || root === '') return 'blocked'
|
|
238
|
+
const marker = joinPath(root, LAYOUT_MARKER)
|
|
239
|
+
const soulDir = joinPath(root, 'planes', 'soul')
|
|
240
|
+
try {
|
|
241
|
+
if (existsSync(marker) && existsSync(soulDir)) return 'ready'
|
|
242
|
+
// 老库在场:不碰用户已有的东西,交给显式迁移
|
|
243
|
+
if (existsSync(joinPath(root, 'canonical')) || existsSync(joinPath(root, 'Global.md'))) return 'legacy'
|
|
244
|
+
|
|
245
|
+
mkdirSync(joinPath(root, 'planes', 'tombstones'), { recursive: true })
|
|
246
|
+
mkdirSync(joinPath(root, 'vault'), { recursive: true })
|
|
247
|
+
for (const plane of PLANES) mkdirSync(joinPath(root, 'planes', plane, 'records'), { recursive: true })
|
|
248
|
+
writeFileSync(marker, `${LAYOUT_MARKER}\n`)
|
|
249
|
+
return 'created'
|
|
250
|
+
} catch {
|
|
251
|
+
return 'blocked'
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
224
255
|
export function backendError(code, message) {
|
|
225
256
|
const err = new Error(message)
|
|
226
257
|
err.code = code
|
package/lib/host.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
// 每个服务都用 ctx.inject 软依赖:宿主没有 systemPrompt(或 tools、commands)
|
|
7
7
|
// 时,那一块就不装,其余部分照常工作,整个插件不会因此起不来。
|
|
8
|
+
import { spawn } from 'node:child_process'
|
|
8
9
|
import {
|
|
9
10
|
buildSnapshot,
|
|
10
11
|
createAccessStore,
|
|
@@ -370,6 +371,89 @@ export function attachHost(ctx, deps) {
|
|
|
370
371
|
},
|
|
371
372
|
})
|
|
372
373
|
|
|
374
|
+
// Shell:整理记忆时得能跑 grep、管道、脚本,只给单个命令不够用。
|
|
375
|
+
const RAW_LIMIT = 200 * 1024
|
|
376
|
+
const sh = scope.tools.register({
|
|
377
|
+
name: 'aurorix_sh',
|
|
378
|
+
description:
|
|
379
|
+
'在本机 shell 里跑一条命令(bash -c)。能用管道、重定向、grep、sed、awk、jq、python 脚本——整理记忆时搜关键字、批量替换、统计都靠它。\n' +
|
|
380
|
+
'abook 已经在 PATH 里,直接打 `abook ...` 就行,不用带路径。\n' +
|
|
381
|
+
'**唯一要记的坑**:abook 的输出不要接 head / tail / cut -c / sed -n 范围——它检测到截断会把整份结果丢弃。要控篇幅用 --limit / --page / --json;要加工就先重定向到文件,再用别的命令读那个文件。\n' +
|
|
382
|
+
'输出超过 200KB 会被整份拒收并提示收窄,不会给你半截。',
|
|
383
|
+
parameters: {
|
|
384
|
+
type: 'object',
|
|
385
|
+
properties: {
|
|
386
|
+
command: { type: 'string', description: '完整 shell 命令,原样交给 bash -c' },
|
|
387
|
+
cwd: { type: 'string', description: '工作目录;省略则用进程当前目录' },
|
|
388
|
+
timeout_ms: { type: 'integer', description: '超时毫秒,默认 30000,上限 300000' },
|
|
389
|
+
},
|
|
390
|
+
required: ['command'],
|
|
391
|
+
},
|
|
392
|
+
output: {
|
|
393
|
+
schema: {
|
|
394
|
+
type: 'object',
|
|
395
|
+
additionalProperties: false,
|
|
396
|
+
properties: {
|
|
397
|
+
code: { type: 'integer', description: '退出码;超时是 -1' },
|
|
398
|
+
stdout: { type: 'string' },
|
|
399
|
+
stderr: { type: 'string' },
|
|
400
|
+
},
|
|
401
|
+
required: ['code', 'stdout', 'stderr'],
|
|
402
|
+
},
|
|
403
|
+
render: (_args, value) => {
|
|
404
|
+
const parts = []
|
|
405
|
+
if (value.stdout !== '') parts.push(value.stdout)
|
|
406
|
+
if (value.stderr !== '') parts.push(`[stderr]\n${value.stderr}`)
|
|
407
|
+
if (parts.length === 0) parts.push(`(无输出,退出码 ${value.code})`)
|
|
408
|
+
if (value.code !== 0) parts.push(`[exit code: ${value.code}]`)
|
|
409
|
+
return [{ type: 'text', text: parts.join('\n') }]
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
async execute(args) {
|
|
413
|
+
const command = typeof args.command === 'string' ? args.command.trim() : ''
|
|
414
|
+
if (command === '') return { code: 2, stdout: '', stderr: 'command 不能为空' }
|
|
415
|
+
const timeout = Math.min(Math.max(Number(args.timeout_ms) || 30_000, 1_000), 300_000)
|
|
416
|
+
const cwd = typeof args.cwd === 'string' && args.cwd !== '' ? args.cwd : undefined
|
|
417
|
+
|
|
418
|
+
return await new Promise((resolve) => {
|
|
419
|
+
const child = spawn('bash', ['-c', command], {
|
|
420
|
+
cwd,
|
|
421
|
+
// 让 shell 里的 abook 认定同一个库:程序在 cache,靠位置推导会错。
|
|
422
|
+
env: { ...process.env, ...(typeof root === 'string' && root !== '' ? { ABOOK_ROOT: root } : {}) },
|
|
423
|
+
})
|
|
424
|
+
const out = []
|
|
425
|
+
const err = []
|
|
426
|
+
let bytes = 0
|
|
427
|
+
let settled = false
|
|
428
|
+
const finish = (result) => {
|
|
429
|
+
if (settled) return
|
|
430
|
+
settled = true
|
|
431
|
+
clearTimeout(timer)
|
|
432
|
+
resolve(result)
|
|
433
|
+
}
|
|
434
|
+
const timer = setTimeout(() => {
|
|
435
|
+
try { child.kill('SIGKILL') } catch {}
|
|
436
|
+
finish({ code: -1, stdout: out.join(''), stderr: `${Math.round(timeout / 1000)} 秒超时,已终止` })
|
|
437
|
+
}, timeout)
|
|
438
|
+
|
|
439
|
+
child.stdout.on('data', (c) => {
|
|
440
|
+
bytes += c.length
|
|
441
|
+
if (bytes > RAW_LIMIT) {
|
|
442
|
+
try { child.kill('SIGKILL') } catch {}
|
|
443
|
+
finish({ code: -1, stdout: '', stderr: `输出超过 200KB,整份拒收。收窄一下:加 --limit/--page,或者把结果重定向到文件再用 grep/read 分页看。` })
|
|
444
|
+
return
|
|
445
|
+
}
|
|
446
|
+
out.push(c)
|
|
447
|
+
})
|
|
448
|
+
child.stderr.on('data', (c) => {
|
|
449
|
+
if (err.length < 500) err.push(c)
|
|
450
|
+
})
|
|
451
|
+
child.on('error', (e) => finish({ code: -1, stdout: out.join(''), stderr: String(e?.message ?? e) }))
|
|
452
|
+
child.on('close', (code) => finish({ code: code ?? -1, stdout: out.join(''), stderr: err.join('') }))
|
|
453
|
+
})
|
|
454
|
+
},
|
|
455
|
+
})
|
|
456
|
+
|
|
373
457
|
// 附件:记忆条目 = 文字域 + 文件域,这是文件域那一半。
|
|
374
458
|
const attach = scope.tools.register({
|
|
375
459
|
name: 'aurorix_attach',
|
|
@@ -481,7 +565,7 @@ export function attachHost(ctx, deps) {
|
|
|
481
565
|
})
|
|
482
566
|
|
|
483
567
|
scope.effect(() => () => {
|
|
484
|
-
for (const dispose of [recall, remember, runCmd, spec, guide, curate, attach]) {
|
|
568
|
+
for (const dispose of [recall, remember, runCmd, spec, guide, curate, attach, sh]) {
|
|
485
569
|
try {
|
|
486
570
|
if (typeof dispose === 'function') dispose()
|
|
487
571
|
} catch {
|