refactor(device): 去掉 caps,shell 改报路径与版本

能力清单会过期且探测不可靠(Store stub、非登录 shell 的 PATH 差异),
交给模型现场自查;shell 是命令入口,补 shell_path/shell_ver。
This commit is contained in:
2026-11-19 16:56:51 +08:00
parent 1859fe0d5b
commit 7d855454a8
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -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),
+1 -1
View File
@@ -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": [