Skip to content

Commit 2c97f0c

Browse files
committed
docs: plan android emulator support
1 parent 0fe3339 commit 2c97f0c

3 files changed

Lines changed: 238 additions & 0 deletions

File tree

docs-linhay/memory/2026-06-05.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@
6262
- 决策:外部用户默认安装整个 `TritonKit.skills/` 文件夹到对应 agent skills 目录下,不再把三个 public skills 作为顶层目录分别复制进去。
6363
- 处理:`tritonkit-skills.tar.gz` 包结构改为顶层 `TritonKit.skills/``BUILD_INFO.json` 放在 `TritonKit.skills/BUILD_INFO.json`;README / release 文档说明旧安装升级时先删除 `tritonkit-dev-feedback``tritonkit-emulator-cli-takeover``tritonkit-real-project-regression` 三个旧顶层目录。
6464
- 脚本:新增 `docs-linhay/scripts/install-public-skills.sh <agent-skills-dir> [--from-tar tritonkit-skills.tar.gz]`,自动删除旧三个独立目录并安装整个 `TritonKit.skills/` bundle。
65+
# Android Emulator 支持规划
66+
67+
- 新建 `docs-linhay/spaces/20260605-android-emulator-support/`,定义 Android Emulator 支持的 feature space。
68+
- 范围收敛为本机 CLI + 本机 Android Emulator,底层通过 `adb` / `emulator` / `uiautomator`,不做真机、远端 agent、设备云、Web/Wails UI 或内置 VLM loop。
69+
- P0 先把 Android 接进统一 `triton device --platform android`:doctor/list/use/wait-ready/screenshot;P1 再补 `triton app --platform android` 的 APK install、launch、terminate、open-url;P1.5/P2 再做 UIAutomator layout、host input、smoke、evidence 和 replay。
70+
- 计划要求 fake adb 测试先红后绿,真实 emulator smoke 覆盖 list、wait-ready、screenshot、install、open-url、wait/assert/evidence,并同步 README、`ai-cli-readable-control.md`、public emulator skill 与 memory。
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# 20260605 Android Emulator Support
2+
3+
## 背景
4+
5+
TritonKit 当前 emulator takeover 的产品边界是本机 CLI + 本机模拟器/仿真器。iOS Simulator 与 HarmonyOS / DevEco Emulator 已经有统一 `triton device` 入口,Android Emulator 仍只停留在规划 slot。
6+
7+
本 space 用于定义 Android Emulator 支持计划,目标是把 Android 接入同一套 agent-facing CLI 契约,而不是新增 Web/Wails UI、远端 agent、设备云或真机控制链路。
8+
9+
## 目标
10+
11+
1. 通过 `triton device --platform android` 发现、选择、等待和截图本机 Android Emulator。
12+
2. 通过 `triton app --platform android` 覆盖 Debug APK 的安装、卸载、启动、终止、deep link / intent 打开。
13+
3. 通过 host-side Android adapter 输出机器可读 JSON / JSONL、稳定 error code、source command、artifact path 和 recovery nextAction。
14+
4. 在 evidence / smoke / replay 中保留 Android artifact 与 command ledger,且明确区分 host 命令成功和业务状态通过。
15+
5. 为后续 Android embedded runtime 预留 Debug-only 接入边界,但首期不依赖 embedded runtime 才能完成 host-side smoke。
16+
17+
## 非目标
18+
19+
1. 不支持 Android 真机、USB 授权、设备农场、远端 adb server 或多机 agent。
20+
2. 不做 Web/Wails UI、设备大盘、队列、权限系统、多租户或中心服务。
21+
3. 不内置 VLM loop,不把截图理解能力放进 TritonKit core。
22+
4. 不承诺系统安全绕过、root-only 能力、Play Protect 绕过或生产环境采集。
23+
5. 不在 P0 引入 Android embedded SDK;如需 Android App 内 runtime,另行拆分 Debug-only runtime space。
24+
25+
## 产品边界
26+
27+
Android 首期只接本机 Android Emulator,底层工具是 Android SDK / platform-tools:
28+
29+
| 能力域 | 底层工具 | Triton 入口 |
30+
| --- | --- | --- |
31+
| 工具诊断 | `adb version`, `emulator -version` | `triton device doctor --platform android --json` |
32+
| target 发现 | `adb devices -l` | `triton device list --platform android --json` |
33+
| ready 等待 | `adb shell getprop sys.boot_completed`, `pm path android` | `triton device wait-ready --platform android --jsonl` |
34+
| 截图 | `adb exec-out screencap -p` | `triton device screenshot --platform android --output <path.png> --json` |
35+
| app 生命周期 | `adb install`, `pm list packages`, `am start`, `am force-stop`, `pm uninstall` | `triton app ... --platform android --json` |
36+
| UI tree / text | `uiautomator dump`, `adb pull/cat` | `triton ax/wait/tap --platform android --json` |
37+
| 日志 | bounded `adb logcat` | P2 `triton logs/capture --platform android --json` |
38+
39+
## BDD 验收
40+
41+
### 场景一:agent 可以发现 Android Emulator
42+
43+
- Given 本机安装 Android SDK platform-tools
44+
- And 至少一个 Android Emulator 通过 `adb devices -l` 可见
45+
- When 执行 `triton device list --platform android --json`
46+
- Then 输出 `ok=true`
47+
- And `targets[]` 使用统一 `HostDeviceTarget` envelope
48+
- And target id 使用 `android:<adb-serial>`
49+
- And 每个 target 至少包含 `platform/id/target/state/ready/source`
50+
51+
### 场景二:没有 emulator 时返回可恢复诊断
52+
53+
- Given 本机可执行 `adb`
54+
- And `adb devices -l` 没有 emulator target
55+
- When 执行 `triton device list --platform android --json`
56+
- Then 输出合法 JSON
57+
- And `targets=[]`
58+
- And `defaultTarget=null`
59+
- And `nextAction` 指向 `triton device doctor --platform android --json` 或启动 emulator 的文档化恢复步骤
60+
61+
### 场景三:agent 可以等待 Android ready
62+
63+
- Given 一个 Android Emulator 已启动但可能仍在 booting
64+
- When 执行 `triton device wait-ready --platform android --target <adb-serial> --timeout 60 --jsonl`
65+
- Then JSONL 事件持续报告 boot 状态
66+
- And ready 判定至少要求 `sys.boot_completed=1`
67+
- And timeout 时返回 `device_not_ready`,不吞掉底层 adb 错误
68+
69+
### 场景四:agent 可以采集截图证据
70+
71+
- Given Android Emulator 已 ready
72+
- When 执行 `triton device screenshot --platform android --target <adb-serial> --output <path.png> --json`
73+
- Then 写出 PNG artifact
74+
- And 输出包含 `target/sourceCommands/artifact/path/format`
75+
- And artifact 失败时返回 `artifact_write_failed``android_screenshot_failed`
76+
77+
### 场景五:agent 可以安装并启动 Debug APK
78+
79+
- Given 一个本地 Debug APK
80+
- And Android Emulator 已 ready
81+
- When 执行 `triton app install --platform android --apk <path.apk> --json`
82+
- Then Triton 调用 `adb install -r`
83+
- And 输出不把安装成功误判为业务状态成功
84+
85+
- When 执行 `triton app open-url --platform android <url> --bundle <package> --json`
86+
- Then Triton 调用 `adb shell am start -a android.intent.action.VIEW -d <url> <package>`
87+
- And 后续必须通过 `wait/assert/screenshot/evidence` 验证业务状态
88+
89+
### 场景六:平台能力差异稳定表达
90+
91+
- Given Android 首期不支持某个 iOS/Harmony 专属能力
92+
- When agent 调用对应 CLI
93+
- Then 返回 `unsupported_capability`
94+
- And `nextAction.category=plan`
95+
- And 不回退到裸 `adb` 人读输出
96+
97+
## 分期
98+
99+
详细实施计划见 [20260605-android-emulator-support-plan-v01.md](plans/20260605-android-emulator-support-plan-v01.md)
100+
101+
## 交付物
102+
103+
1. Android host adapter runtime / model / command 分层。
104+
2. `device``app``ax/wait/tap/screenshot` 的 schema、capabilities 和 failure code 更新。
105+
3. fake adb fixture 与单元测试。
106+
4. 至少一轮真实 Android Emulator smoke 证据。
107+
5. README、`docs-linhay/dev/ai-cli-readable-control.md`、public skill 与 memory 写回。
108+
109+
## 风险
110+
111+
1. Android SDK 安装路径差异较大,P0 必须支持显式 `--adb <path>`,同时在 doctor 中暴露 PATH 探测结果。
112+
2. `adb devices -l` 对 offline / unauthorized / booting 的表达不一致,parser 要先用 fake fixture 锁住。
113+
3. `uiautomator dump` 可能无法覆盖 Compose 语义或 WebView DOM,P1/P2 必须把 host layout 与 app 业务语义区分清楚。
114+
4. Android action 的坐标、密度、导航栏和软键盘会影响 replay 稳定性,首期只承诺明确 selector 或坐标,不承诺智能重定位。
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# 20260605 Android Emulator Support Plan v01
2+
3+
## 成功标准
4+
5+
1. Android Emulator 进入 `triton device --platform android` 的统一 host device contract。
6+
2. Android Debug APK 可通过 `triton app --platform android` 完成安装、启动、终止和 deep link smoke。
7+
3. 所有新能力都可被 `triton schema --json``triton capabilities --json``triton doctor --json` 发现。
8+
4. fake adb 测试先红后绿,真实 emulator smoke 至少覆盖 list、wait-ready、screenshot、install、open-url、evidence。
9+
5. 不新增 Web/Wails UI,不支持真机或远端 agent。
10+
11+
## M0. 契约设计和红灯测试
12+
13+
- 定义 `HostDevicePlatform.android``android:<serial>` target id、Android 附加字段和统一 error code。
14+
- 新增 fake adb fixture,覆盖 `adb devices -l``getprop sys.boot_completed``screencap``install``am start``uiautomator dump`
15+
- 先补测试:
16+
- `DeviceCrossPlatformTests` 覆盖 `doctor/list/use/wait-ready/screenshot --platform android` schema。
17+
- `TKHostAdapterModelsTests` 覆盖 adb devices parser、boot completed parser、package / activity parser。
18+
- `AppOpenURLFlowTests` 覆盖 Android deep link source command 与 unverified warning。
19+
- 红灯预期:schema 不认识 android、platform enum 不接受 android、fake adb parser 不存在。
20+
21+
## M1. Device P0
22+
23+
- 实现 `AndroidHostDeviceAdapter`
24+
- `doctor`: 探测 `adb`、可选 `emulator`、Android SDK 路径提示。
25+
- `list`: 解析 `adb devices -l`,过滤/表达 `device/offline/unauthorized`
26+
- `use/current/resolve`: 复用统一 selector resolver,支持 alias、`android:<serial>`、raw serial、`current`
27+
- `wait-ready`: 轮询 `sys.boot_completed=1`,必要时验证 package manager 可响应。
28+
- `screenshot`: `adb exec-out screencap -p` 写本地 PNG。
29+
- 输出统一 `HostDeviceTarget` / `HostDeviceArtifactOutput`,平台差异放进 Android-specific metadata。
30+
- 错误码:`android_adb_not_found``android_target_offline``android_target_unauthorized``device_not_ready``android_screenshot_failed``host_command_timeout`
31+
32+
## M2. App P1
33+
34+
- `triton app list/info/install/uninstall/launch/terminate/open-url --platform android`
35+
- install: `adb install -r <apk>`
36+
- uninstall: `adb uninstall <package>`
37+
- launch: `monkey -p <package> 1` 或 schema 明确要求 package/activity 时用 `am start`
38+
- terminate: `am force-stop <package>`
39+
- open-url: `am start -a android.intent.action.VIEW -d <url> <package>`
40+
- info/list: `pm list packages``dumpsys package <package>` 的 bounded summary
41+
- app action 返回 host action envelope,不能把 adb 成功当作业务 pass。
42+
-`triton plan open-url --platform android` 或在现有 open-url plan 中支持 `--device <android-alias>` 的推荐链路。
43+
44+
## M3. Observe / Action P1.5
45+
46+
- `triton ax --platform android --output <path.json>`
47+
- 执行 `uiautomator dump /sdcard/window.xml`
48+
- `adb exec-out cat /sdcard/window.xml``adb pull`
49+
- 转为轻量 JSON artifact,不内联敏感完整 UI 到 stdout
50+
- `triton wait --platform android --text <text>` 轮询 UIAutomator tree。
51+
- `triton tap --platform android <text>` 从 bounds 取中心点后 `adb shell input tap x y`
52+
- `triton type/paste/press/swipe --platform android` 只接稳定 host input,所有输入动作标记 `runtimeScope=host-android`
53+
54+
## M4. Smoke / Evidence P2
55+
56+
- 新增 `triton smoke android`
57+
- device wait-ready
58+
- app install 可选
59+
- app open-url 或 launch
60+
- wait text
61+
- 可选 tap text
62+
- screenshot
63+
- evidence manifest
64+
- evidence artifact taxonomy 新增或复用:
65+
- `android.screenshot`
66+
- `android.layout`
67+
- `android.logcat`
68+
- `host.android-action`
69+
- `host.android-device-list`
70+
- `triton capture/evidence/replay` 读取 Android command ledger,保留 source command、elapsed、target、artifact path、redaction hint。
71+
72+
## M5. 真实 Emulator 验收
73+
74+
- 准备一个最小 Android Debug APK fixture 或使用现有可公开示例 APK。
75+
- 真实命令链:
76+
77+
```bash
78+
triton device doctor --platform android --json
79+
triton device list --platform android --json
80+
triton device alias set android-a --platform android --target <adb-serial> --json
81+
triton device wait-ready --device android-a --timeout 60 --jsonl
82+
triton device screenshot --device android-a --output /tmp/triton-android-smoke.png --json
83+
triton app install --platform android --device android-a --apk <path.apk> --json
84+
triton app open-url --platform android --device android-a "example://smoke" --bundle <package> --json
85+
triton wait --platform android --device android-a --text "<expected-text>" --timeout 20 --json
86+
triton smoke android --device android-a --bundle <package> --open-url "example://smoke" --wait-text "<expected-text>" --screenshot /tmp/triton-android-smoke.png --evidence /tmp/triton-android.tritonevidence --json
87+
```
88+
89+
- 截图按规范归档到 `docs-linhay/spaces/20260605-android-emulator-support/screenshots/<YYYYMMDD>/android/`
90+
91+
## M6. 文档、public skill 和门禁
92+
93+
- 更新:
94+
- `README.md`
95+
- `docs-linhay/dev/ai-cli-readable-control.md`
96+
- `docs-linhay/dev/20260520-simulator-takeover-architecture.md`
97+
- `TritonKit.skills/tritonkit-emulator-cli-takeover/SKILL.md`
98+
- `docs-linhay/memory/YYYY-MM-DD.md`
99+
- 门禁:
100+
101+
```bash
102+
swift test --package-path CLI --scratch-path .build/cli --filter DeviceCrossPlatformTests
103+
swift test --package-path CLI --scratch-path .build/cli --filter TKHostAdapterModelsTests
104+
swift test --package-path CLI --scratch-path .build/cli --filter AppOpenURLFlowTests
105+
docs-linhay/scripts/check-docs.sh
106+
docs-linhay/scripts/verify.sh --local
107+
```
108+
109+
## 拆分建议
110+
111+
1. 第一 PR:M0 + M1,只做 device P0 和 fake adb。
112+
2. 第二 PR:M2,app lifecycle 与 deep link。
113+
3. 第三 PR:M3 + M4,UIAutomator observe/action、smoke、evidence。
114+
4. 第四 PR:真实 emulator fixture、README / public skill 对外使用口径、release 门禁补齐。
115+
116+
## 暂不沉淀为 AGENTS 规则
117+
118+
本计划是 Android adapter 的 feature-level 规划,不新增 repo-wide 长期规则。当前 AGENTS 已包含 emulator takeover 边界和 Android Emulator 范围,暂不需要修改。

0 commit comments

Comments
 (0)