From 7d855454a86521a29462f67f8ca9496bb546fe05 Mon Sep 17 00:00:00 2001 From: kicer Date: Thu, 19 Nov 2026 16:56:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(device):=20=E5=8E=BB=E6=8E=89=20caps?= =?UTF-8?q?=EF=BC=8Cshell=20=E6=94=B9=E6=8A=A5=E8=B7=AF=E5=BE=84=E4=B8=8E?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 能力清单会过期且探测不可靠(Store stub、非登录 shell 的 PATH 差异), 交给模型现场自查;shell 是命令入口,补 shell_path/shell_ver。 --- app/server/devices.js | 12 ++++++++---- app/server/tools/definitions.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/server/devices.js b/app/server/devices.js index b535f5e..f6c3dd1 100644 --- a/app/server/devices.js +++ b/app/server/devices.js @@ -84,7 +84,7 @@ function attach(server) { function onConnection(ws) { const dev = { - ws, name: null, os: '', arch: '', shell: '', root: '', caps: [], ver: '', + ws, name: null, os: '', arch: '', shell: '', shellPath: '', shellVer: '', root: '', ver: '', connectedAt: Date.now(), lastSeen: Date.now(), health: null, helloTimer: null, }; dev.helloTimer = setTimeout(() => { @@ -128,8 +128,9 @@ function onHello(dev, m) { dev.os = String(m.os || ''); dev.arch = String(m.arch || ''); dev.shell = String(m.shell || ''); + dev.shellPath = String(m.shell_path || ''); + dev.shellVer = String(m.shell_ver || ''); dev.root = String(m.root || ''); - dev.caps = Array.isArray(m.caps) ? m.caps : []; dev.ver = String(m.ver || ''); const old = state.byName.get(dev.name); @@ -138,7 +139,7 @@ function onHello(dev, m) { try { old.ws.close(4000, 'replaced'); } catch (_) {} } state.byName.set(dev.name, dev); - log.info('devices', `设备上线:${dev.name}(${dev.os}/${dev.arch} shell=${dev.shell} root=${dev.root})`); + log.info('devices', `设备上线:${dev.name}(${dev.os}/${dev.arch} shell=${dev.shellPath || dev.shell} ${dev.shellVer} root=${dev.root})`); // 上线即取一次健康快照,list 时能顺带看到负载;失败不影响接入 health(dev.name).catch(() => {}); @@ -156,9 +157,12 @@ function list() { device: d.name, os: d.os, arch: d.arch, + // shell 是模型的命令入口:kind 决定调用形式(sh -c / cmd /c),path 决定实际解释器 + //(/bin/sh 可能是 dash、bash 或 busybox),ver 拿得到就给。 shell: d.shell, + shell_path: d.shellPath, + shell_ver: d.shellVer, root: d.root, - caps: d.caps, ver: d.ver, connected_sec: Math.round((now - d.connectedAt) / 1000), idle_sec: Math.round((now - d.lastSeen) / 1000), diff --git a/app/server/tools/definitions.json b/app/server/tools/definitions.json index c992dc4..b3bcc4a 100644 --- a/app/server/tools/definitions.json +++ b/app/server/tools/definitions.json @@ -436,7 +436,7 @@ "type": "function", "function": { "name": "device", - "description": "Operate the remote devices (other machines) connected to this server. Devices dial out to this server, so they need no inbound port; they stay connected until closed.\n\n- action=list: no other params. Returns every online device with os/arch/shell/root/caps/health. Always call this first when you don't know device names.\n- action=health: requires device. Returns host uptime, load, memory, disk and temperature (fields the platform can't provide are -1).\n- action=exec: requires device and command. Runs the command through a shell on that device (sh -c on Unix, cmd /c on Windows) and returns stdout, stderr and the exit code. `cwd` must be inside that device's work root; omit it to use the root.\n\nUse it when the work has to happen on the user's own machine (laptop, box, Windows PC). For the machine running this server use `terminal` instead. If a device is offline, say so explicitly — do not silently run the command elsewhere.", + "description": "Operate the remote devices (other machines) connected to this server. Devices dial out to this server, so they need no inbound port; they stay connected until closed.\n\n- action=list: no other params. Returns every online device with os/arch/shell/root/health. Always call this first when you don't know device names.\n- action=health: requires device. Returns host uptime, load, memory, disk and temperature (fields the platform can't provide are -1).\n- action=exec: requires device and command. Runs the command through a shell on that device (sh -c on Unix, cmd /c on Windows) and returns stdout, stderr and the exit code. `cwd` must be inside that device's work root; omit it to use the root.\n\nUse it when the work has to happen on the user's own machine (laptop, box, Windows PC). For the machine running this server use `terminal` instead. If a device is offline, say so explicitly — do not silently run the command elsewhere.", "parameters": { "type": "object", "required": [