feat(shell): 抽出执行后端,Windows 用 git-bash / busybox 跑命令
POSIX 上 spawn('/bin/sh') + kill(-pid) 是刻意选的最强约束:/bin/sh 固定
(不读 $SHELL,否则用户把 shell 设成 fish 后模型写的 POSIX 语法全废),
进程组让「停止」能一次带走孙进程。Windows 这三样都没有,同一个写法从
「有效」变成「静默失效」,detached 还会多弹一个控制台。
把三种能力收敛到 app/server/shell.js(resolve / spawnShell / killTree),
terminal、技能、engine 的取消都改走它,上层不再出现 process.platform 分支:
- POSIX 分支逐字节不变,Linux / macOS / OpenWrt 行为与拆分前一致
- Windows 依次探测 git-bash、busybox-w32,都没有就明确报错,不静默退到
cmd.exe——cmd 的语法与模型写的 POSIX 差太远,降级只会让它反复试错
- killTree 在 Windows 走 taskkill /T:child.kill() 只杀 shell 本身,
模型起的 node/python/ffmpeg 孙进程会留下来继续占端口
- detached 在 Windows 关闭(会新建控制台,且让子进程脱离 taskkill 的父子树)
- 三级覆盖:AGENT_SHELL > config.terminal.shell > 自动探测;
AGENT_SHELL_ARGS 可改参数模板(bash 想读 rc 时写 -lc)
新增 local/start-win.mjs:start.sh 那 1100 多行 bash 靠 lsof / pgrep /
readlink -f / nohup / setsid / 进程组信号,Windows 一个都没有。启动器这层
本来就只做进程管理,用 Node 重写更省事;业务代码一行都不分平台。首次运行
自动把 busybox-w32(单文件 600KB)下到 local/bin/,生成 local/config.win.yml,
之后不再覆盖。
验证(macOS 实跑):普通命令 / 超时 704ms / 取消 403ms 三条路径正常,进程组
3 个进程 kill 后归 0,procs 无残留;真实 core 启动 health 200,日志多一行
terminal=/bin/sh -c ← default。win32 分支只做了逻辑模拟(无 shell 的报错
文案、有 busybox 时解析为 busybox sh -c),真机待验。
未做:Windows 启动器未拉起四个同栈 MCP 与 office 预览网关,配置里
mcp_servers 暂为空,terminal / 文件工具 / 技能不受影响。
This commit is contained in:
@@ -8,6 +8,7 @@ const { executeTool, resolveInTask } = require('./tools/executor');
|
||||
const publicFiles = require('./public-files');
|
||||
const mcp = require('./mcp');
|
||||
const rexec = require('./remote-exec');
|
||||
const shell = require('./shell'); // 执行后端:killTree 的平台差异(进程组 / taskkill)不往引擎里渗
|
||||
const log = require('./log');
|
||||
const profile = require('./user-profile');
|
||||
const memory = require('./memory');
|
||||
@@ -568,9 +569,8 @@ function killRunProcs(run) {
|
||||
for (const proc of run.procs) {
|
||||
// 远端 executor 任务句柄(remote-exec.js):发 DELETE 取消,不能本地 kill。
|
||||
if (typeof proc.remoteKill === 'function') { try { proc.remoteKill(); } catch (_) {} continue; }
|
||||
try { process.kill(-proc.pid, 'SIGKILL'); } catch (_) {
|
||||
try { proc.kill('SIGKILL'); } catch (__) {}
|
||||
}
|
||||
// 平台差异交给执行后端:POSIX 杀进程组,Windows 走 taskkill /T。
|
||||
shell.killTree(proc);
|
||||
}
|
||||
run.procs.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user