refactor: remove built-in serial hardware support

Remove serial tools and platform implementations.
Drop tool registration, defaults, and example settings.
Ignore legacy tools.serial settings and remove them on save.
Update documentation and config compatibility tests.
This commit is contained in:
loveuer committed 2026-11-13 10:17:09 +08:00
1 parent a8804df0ed
commit b11c2c31ad
24 files changed
+12 -1705

No files matched your search

@@ -1,58 +0,0 @@
# 串口 Tool 设计
当前 fork 保留 `serial` 串口工具,默认关闭,通过 `tools.serial.enabled` 启用。I²C、SPI、USB 热插拔监控和内置 hardware Skill 已移除。
## Serial Tool 设计
`serial` 采用无状态调用模型,每次请求都自行打开和关闭端口,避免在 agent 回合之间维护串口会话状态。
支持动作:
- `list`:枚举主机串口
- `read`:从串口读取指定长度字节
- `write`:向串口写入字节或文本
公共参数:
- `port`
- `baud`
- `data_bits`
- `parity`
- `stop_bits`
- `timeout_ms`
当前波特率实现边界:
- Windows 允许配置工具层接受的范围 `50-4000000`
- Linux / macOS 当前仅支持标准 termios 波特率,实际支持到 `230400`
- 因此 `baud` 的跨平台可移植取值应优先使用 `230400` 及以下的常见标准速率
安全约束:
- `write` 必须显式传 `confirm: true`
- 单次读写负载限制为 `4096` 字节
- `port` 只接受白名单串口名:
- Linux / macOS 仅允许 `/dev/tty*`、`/dev/cu.*` 及对应简写设备名
- Windows 仅允许 `COM\d+` 或 `\\.\COM\d+`
- 明确拒绝 `..`、普通文件绝对路径、盘符路径等非串口设备路径,避免路径穿越或误打开任意文件
## 跨平台实现边界
- Linux / macOS:
- 基于 `golang.org/x/sys/unix` 和 termios 配置串口参数。
- 当前仅接入标准 termios 波特率映射,最高到 `230400`,尚未扩展 `460800`、`921600`、`1000000`、`2000000` 等更高速率。
- 通过 `/dev/...` 枚举和访问设备。
- Windows:
- 基于 `kernel32` 串口 API 配置 `DCB` 和 `COMMTIMEOUTS`。
- 当前读写仍使用同步 `ReadFile` / `WriteFile`;一旦 syscall 已进入执行,turn context cancellation 不能立即打断,只能等待 `COMMTIMEOUTS` 触发后返回。
- 通过注册表 `HARDWARE\\DEVICEMAP\\SERIALCOMM` 枚举端口。
- 其他平台:
- `serial` Tool 显式返回 unsupported,不做静默降级。
## 后续建议
1. 如果需要持续交互式串口会话,建议再增加 session 型 Tool,而不是让 LLM 反复做短连接轮询。
2. 如果后续要支持 CAN、GPIO、PWM,建议抽出统一的硬件 capability 描述层,而不是继续只靠 Tool 名称区分。
3. 若需要生产级稳定性,建议补真实串口回环测试,至少覆盖 Linux PTY 和 Windows COM 模拟场景。