feat(device): 文件通道 pull/push

core 与设备复用同一条 WS 搬文件:256KiB 分块、base64、50MiB 上限,
写盘先 .part 再校验 size/sha256 后 rename;device 工具新增 pull/push 两个动作。
This commit is contained in:
2026-11-19 19:01:34 +08:00
parent 4a36cc0266
commit 3c9f9d2bdb
7 changed files with 443 additions and 4 deletions
+14
View File
@@ -98,6 +98,7 @@ sh scripts/build.sh all
|---|---|
| 设备 → core | `{t:"hello", ver, name, os, arch, shell, shell_path, shell_ver, root}` |
| core → 设备 | `{t:"exec", id, cmd, cwd, timeout_ms}` · `{t:"kill", id}` · `{t:"ping"}` · `{t:"health", id}` |
| 文件通道 | `{t:"file", id, op:"read"\|"write", path, size?, sha256?}` · `{t:"file.chunk", id, data:<base64>}` ×N · `{t:"file.done", id, size?, sha256?, err?}` |
| 设备 → core | `{t:"chunk", id, out:"out"\|"err", chunk:<base64>}` · `{t:"exit", id, code, killed_by, ms, truncated}` · `{t:"pong"}` · `{t:"health", …}` |
- 保活:core 每 20 秒发 `ping`,设备回 `pong`;90 秒无任何消息即断开重连。
@@ -106,6 +107,19 @@ sh scripts/build.sh all
- 输出:单流超过上限截断并置 `truncated`。
- `shell` 报的是实际解释器(`/bin/sh` 可能是 dash / bash / busybox),连同版本,供模型决定命令语法。
## 文件通道
core 通过同一条连接搬文件,**设备不需要任何额外端口**:
| 方向 | 流程 |
|---|---|
| 拉取(设备 → 会话目录) | `file{op:read}` → 设备分块回 `file.chunk` → `file.done{size,sha256}` |
| 推送(会话目录 → 设备) | `file{op:write,size,sha256}` → 分块 `file.chunk` → `file.done` |
- 每块 256 KiB(base64 后约 341 KiB),单文件上限 50 MiB;
- 写盘先落 `<path>.part`,`size` 与 `sha256` 都对上才 `rename`;
- 设备侧路径必须在工作根内(与 `exec` 的 cwd 校验同一套)。
## 安全边界
- 设备主动出站,服务端不需要知道设备 IP;