Files
HomeAgent/internal/plugins/remotedevice
JianFeeeee b27e6142e2 fix(remotedevice): 补 screensue/camerasue/speakeruse 专用工具,修「agent 被迫手拼命令字符串」
## 问题(生产日志实证,10-06 12:46~13:04)

三个能力只能走 device_ctl_cmdrun 的 **command 字符串**,agent 于是手拼:

    homeagent-screensue 0 <!DOCTYPE html><html><head><meta charset="utf-8">…

结果是工具调用**连执行都没执行**:

    13:00:38  stream tool_call device_ctl_cmdrun argument fragments invalid JSON:
              "{\"device_id\": \"gui-JianF\", \"command\": \"homeagent-screensue 0
               <!DOCTYPE html>…<meta charset=\\\"utf-8\\\">…
    13:00:38  args unparseable (982 bytes) — surfacing to model instead of calling

三个原因叠加:
  ① 引号要穿过两层 JSON 转义(HTML 必然含引号)
  ② 时长与内容共用一个字符串靠空格切分(内容里的空格有歧义)
  ③ 长度无上限(一屏看板几十 KB)

agent 的应对是反复试参数 —— 它在猜格式,不是在做事:

    screensue shown on display 0 for 15s / 25s / 30s / 40s / 60s / 180s

## 改动

新增三个结构化工具(与 screensee 同一层):

| 工具 | 参数 |
|---|---|
| `screensue` | device_id, content 或 content_path, duration_seconds |
| `camerasue` | device_id, duration_seconds(省略/0=拍照,N=录像 N 秒) |
| `speakeruse` | device_id, text 或 text_path |

- 命令字符串由**服务端**拼装,形状与 GUI `executeHomeagentCmd` 的解析一致
- 长内容走 `*_path`(服务端读文件,上限 2MB,与 clipboardsue 对齐)
- `duration_seconds=0` **显式下发 0**(常驻),与「省略=默认 5 秒」语义区分开
- device_ctl_cmdrun 描述改向:告明它只管 shell,屏幕/摄像头/语音请用专用工具;
  homeagent-* 旧前缀仍兼容(不破坏既有调用)

## 顺带修掉一个「只提交判据没提交实现」的缺口

clipboardsue 的实现读 `args["content"]`,但**工具 schema 里只有 text** ——
参数存在却不暴露,等于没有。已补进 schema。

## 判据

capability_tools_test.go,11 条。三个变异自证会红:

- 变异 A:把 content 与时长拼回一个字符串 → 红
  (`got="screensue 三点开会"` / 含引号内容被下划线替换)
- 变异 B:duration=0 时省略 → 红(与「默认5秒」混淆)
- 变异 C:超时错误退化成一句「失败」→ 红(丢掉 req_id 与复查提示)

★ 过程中两次遇到「无输出」,都不是被杀死而是**编译失败**
(未使用的 prefix / 类型不符)。本项目已记过这个坑:
编译失败 ≠ 被杀。加 `_ = prefix` 后确认是真的被杀。

另:一条判据自己假红了一次 —— `res["size"]` 经 JSON 回来是 float64
而非 int,断言写错。判据的红也要先分清「实现错了」与「断言错了」。

## 验证

- go build / go vet / go test ./internal/... 全绿
- go test -race remotedevice 无数据竞争
- 部署后 39 插件加载、0 panic/fatal、DB integrity ok
- 快照 /home/newqqagent/memory/pre-capability-tools-20261006-211446/

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-06 21:17:03 +08:00
..