远控场景下,手机 App(KMP)的日志通过已配对的 relay 连接传到桌面,用于排查问题。分两种能力:
mobile-log 帧,桌面按设备和会话分文件落盘。mobile-log-pull-request,手机按 cursor 分片回 mobile-log-pull-response,桌面导出成一个 JSONL 文件。所有报文都是普通远控 app payload(zcode_type 区分),走现有 relay 加密通道,不新增连接。schema 定义在 packages/shared/src/web-remote-relay/mobileLog.ts,桌面收到后用 parseWebRemoteControlAppPayload 校验,非法报文直接丢弃。schema 不是 strict:多出来的字段会被忽略,方便手机新版本往前扩展。
MobileLogEntry(推送帧和拉取分片共用):
| 字段 | 类型 | 说明 |
|---|---|---|
ts |
int > 0 | 手机侧事件时间,epoch 毫秒 |
level |
"debug" \| "info" \| "warn" \| "error" |
其它值整帧拒绝 |
name |
string ≤ 200,可选 | 结构化事件名 |
tag |
string ≤ 100,可选 | 模块 / tag |
message |
string ≤ 4000,可选 | 正文,手机侧先截断。手机必须先脱敏(token、手机号等) |
mobile-log(手机 → 桌面){
"zcode_type": "mobile-log",
"device": {
"id": "install-uuid",
"name": "Pixel 8",
"platform": "android",
"appVersion": "1.2.0"
},
"sessionId": "app-launch-uuid",
"events": [{ "ts": 1761184800000, "level": "info", "tag": "rc", "message": "paired" }]
}
events 每帧 1..100 条。手机自己攒批(建议 1s 或 50 条触发一次),桌面不回 ack。device.id(1..128)作为设备目录名;不带时用配对时 mobile-view-state 里的设备名和平台。sessionId(1..128)表示一次 App 启动。同一会话写同一组文件;不带时用桌面的远控会话 sid。~/.zcode/v2/logs/mobile/<设备>/<YYYY-MM-DD>_<会话>.jsonl
<YYYY-MM-DD>_<会话>.1.jsonl # 滚动分片
[A-Za-z0-9._-],最长 64 个字符。{"kind":"mobile-log-file","openedAt",...,"device","mobileSessionId","desktopSession","windowId"}。之后每行一条:{"time":ISO,"ts","level","tag","name","message"}。logs/ 下,所以 Help →「导出日志」打的 zip 会自动带上最近 3 天的手机日志。mobile-log-pull-request(桌面 → 手机){
"zcode_type": "mobile-log-pull-request",
"requestId": "mobile-log-pull-<uuid>",
"sinceTs": 1761098400000,
"untilTs": 1761184800000,
"minLevel": "info",
"keyword": "relay",
"maxEntries": 200000,
"cursor": "opaque",
"acceptEncodings": ["gzip"]
}
| 字段 | 说明 |
|---|---|
requestId |
1..128,同一次拉取的所有分片共用 |
sinceTs / untilTs |
事件时间闭区间,可选 |
minLevel |
级别下限 debug < info < warn < error,可选 |
keyword |
≤ 200,对 name/tag/message 做大小写不敏感的子串匹配,可选 |
maxEntries |
1..1,000,000。超出时保留最新的条目,并在应答里标 truncated |
cursor |
≤ 256。首片不带;续拉时原样带回上一片的 cursor |
acceptEncodings |
桌面能解的压缩格式,目前只有 gzip。手机可以忽略,回明文 |
桌面菜单的默认请求是:最近 24 小时、全部级别、maxEntries=200000。
mobile-log-pull-response(手机 → 桌面)公共字段:
| 字段 | 说明 |
|---|---|
requestId |
与请求一致 |
success |
true |
totalMatched |
过滤后、截断前的匹配总数 |
returnedCount |
含本片在内,累计已返回的条数 |
hasMore |
是否还有下一片 |
cursor |
hasMore=true 时必带,≤ 256 |
truncated |
可选,结果被 maxEntries 截断时为 true |
sources |
≤ 8 个,每个 ≤ 64,例如 ["memory-ring","log-files"] |
分片体二选一:
"entries": MobileLogEntry[],最多 100 条。"encoding": "gzip"、"data"、"entryCount"。
data 是 base64(gzip(UTF-8 JSON 数组 MobileLogEntry[])),最多 700,000 个字符。entryCount 是解压后的条数(≤ 2000),桌面会校验。acceptEncodings 里有 gzip 时才允许用。单个 relay 物理帧上限是 1 MiB。gzip 分片的 base64 上限定在 700k,就是给外壳留出余量。
{
"zcode_type": "mobile-log-pull-response",
"requestId": "…",
"success": false,
"reason": "busy",
"error": "…"
}
reason ≤ 64,error ≤ 2000。reason 为 unsupported-action 时桌面提示升级 App,其它值统一提示「手机端返回错误」。
hasMore=false 时结束。文件末行写 summary:{"kind":"mobile-log-pull-summary","entryCount","totalMatched","shardCount",...}。防御措施:
手机不支持拉取时,按优先级从高到低:
app-error:{"zcode_type":"app-error","requestId":"<请求的 requestId>","reason":"unsupported-action","error":"…"}。推荐,桌面会立即提示「手机端版本不支持日志拉取」。success:false,并带 reason:"unsupported-action",效果同上。DesktopCommandIds.PullMobileLogs。2026-10-28 起这是唯一用户入口,帮助菜单(macOS 原生菜单栏、Windows/Linux 工作区帮助按钮)里的同名项已移除。~/.zcode/export-log/mobile-logs-<设备>-<YYYYMMDD-HHmmss>.jsonl。完成后弹框给出文件路径和实时日志目录,可「打开所在文件夹」。拉取统一打 [web-remote-control] 前缀、关键字 zcode_rc_log_pull:
[web-remote-control] zcode_rc_log_pull_start:开始拉取,带 window、since_ts、until_ts、max_entries。[web-remote-control] zcode_rc_log_pull_result:结束,成功 info、失败 warn。字段:request_id(成功时)、outcome(ok / error)、error_code、error_msg、duration_ms、bytes(写入文件的字节数,含 header 和 summary)、entries、shards、compressed_shards、truncated、file(只有文件名)。| 内容 | 文件 |
|---|---|
| schema / 上限 | packages/shared/src/web-remote-relay/mobileLog.ts |
| 实时落盘 | packages/desktop/src/main/web-remote-relay/mobileLogSink.ts |
| 拉取编排 | packages/desktop/src/main/web-remote-relay/mobileLogPull.ts |
| 导出与弹框 | packages/desktop/src/main/web-remote-relay/mobileLogPullExport.ts |
| 路由接入 | packages/desktop/src/main/webRemoteControlManager.ts:routePayload、pullMobileLogs |
| 面板入口 | packages/ui/src/web-remote-control/WebRemoteControlDialog.tsx |