dsh-aurorix-agentbook 1.4.0 → 1.4.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/lib/host.js +32 -6
- package/package.json +1 -1
package/lib/host.js
CHANGED
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
// 每个服务都用 ctx.inject 软依赖:宿主没有 systemPrompt(或 tools、commands)
|
|
7
7
|
// 时,那一块就不装,其余部分照常工作,整个插件不会因此起不来。
|
|
8
8
|
import { spawn } from 'node:child_process'
|
|
9
|
+
import { delimiter, dirname } from 'node:path'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 当前能用的 shell。不同平台差得远,命令语法完全不同,所以要让模型知道自己在哪套里。
|
|
13
|
+
* Windows 上没有 bash:有 PowerShell 就用它,再不行退回 cmd。
|
|
14
|
+
*/
|
|
15
|
+
function detectShell() {
|
|
16
|
+
if (process.platform !== 'win32') {
|
|
17
|
+
return { kind: 'posix', name: 'bash', build: (c) => ['-c', c] }
|
|
18
|
+
}
|
|
19
|
+
if (typeof process.env.PSModulePath === 'string' && process.env.PSModulePath !== '') {
|
|
20
|
+
return { kind: 'powershell', name: 'powershell', build: (c) => ['-NoProfile', '-NonInteractive', '-Command', c] }
|
|
21
|
+
}
|
|
22
|
+
const comspec = typeof process.env.ComSpec === 'string' ? process.env.ComSpec : 'cmd.exe'
|
|
23
|
+
return { kind: 'cmd', name: comspec, build: (c) => ['/d', '/s', '/c', c] }
|
|
24
|
+
}
|
|
9
25
|
import {
|
|
10
26
|
buildSnapshot,
|
|
11
27
|
createAccessStore,
|
|
@@ -372,6 +388,7 @@ export function attachHost(ctx, deps) {
|
|
|
372
388
|
})
|
|
373
389
|
|
|
374
390
|
// Shell:整理记忆时得能跑 grep、管道、脚本,只给单个命令不够用。
|
|
391
|
+
const SHELL = detectShell()
|
|
375
392
|
const RAW_LIMIT = 200 * 1024
|
|
376
393
|
const sh = scope.tools.register({
|
|
377
394
|
name: 'aurorix_sh',
|
|
@@ -379,7 +396,13 @@ export function attachHost(ctx, deps) {
|
|
|
379
396
|
'在本机 shell 里跑一条命令(bash -c)。能用管道、重定向、grep、sed、awk、jq、python 脚本——整理记忆时搜关键字、批量替换、统计都靠它。\n' +
|
|
380
397
|
'abook 已经在 PATH 里,直接打 `abook ...` 就行,不用带路径。\n' +
|
|
381
398
|
'**唯一要记的坑**:abook 的输出不要接 head / tail / cut -c / sed -n 范围——它检测到截断会把整份结果丢弃。要控篇幅用 --limit / --page / --json;要加工就先重定向到文件,再用别的命令读那个文件。\n' +
|
|
382
|
-
'输出超过 200KB
|
|
399
|
+
'输出超过 200KB 会被整份拒收并提示收窄,不会给你半截。\n' +
|
|
400
|
+
`当前 shell:${SHELL.name}(${SHELL.kind})。` +
|
|
401
|
+
(SHELL.kind === 'posix'
|
|
402
|
+
? '按 bash 语法写:管道 |、重定向 >、grep/sed/awk 都能用。'
|
|
403
|
+
: SHELL.kind === 'powershell'
|
|
404
|
+
? '按 PowerShell 语法写:管道传对象而不是文本,取字段用 Select-Object / Where-Object,没有 grep;路径用反斜杠或正斜杠都行。'
|
|
405
|
+
: '按 cmd 语法写:可用 | 与 >,但没有 grep;复杂处理建议改用 node 或 python 脚本。'),
|
|
383
406
|
parameters: {
|
|
384
407
|
type: 'object',
|
|
385
408
|
properties: {
|
|
@@ -416,11 +439,14 @@ export function attachHost(ctx, deps) {
|
|
|
416
439
|
const cwd = typeof args.cwd === 'string' && args.cwd !== '' ? args.cwd : undefined
|
|
417
440
|
|
|
418
441
|
return await new Promise((resolve) => {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
442
|
+
// PATH 只对这个子进程前置,不动系统环境;这样无论哪个平台,`abook` 都能直接打。
|
|
443
|
+
const binDir = typeof backend?.bin === 'string' && backend.bin !== '' ? dirname(backend.bin) : ''
|
|
444
|
+
const env = {
|
|
445
|
+
...process.env,
|
|
446
|
+
...(binDir !== '' ? { PATH: `${binDir}${delimiter}${process.env.PATH ?? ''}` } : {}),
|
|
447
|
+
...(typeof root === 'string' && root !== '' ? { ABOOK_ROOT: root } : {}),
|
|
448
|
+
}
|
|
449
|
+
const child = spawn(SHELL.name, SHELL.build(command), { cwd, env })
|
|
424
450
|
const out = []
|
|
425
451
|
const err = []
|
|
426
452
|
let bytes = 0
|