@developerz.ai/ui-debugger-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 developerz-ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,295 @@
1
+ # UI Debugger MCP
2
+
3
+ > An MCP server that debugs UIs **autonomously** — so the AI that wrote your app can also test it, without a human clicking through every flow.
4
+
5
+ ## The problem
6
+
7
+ AI coding agents (Claude, etc.) are great at writing code. They're bad at
8
+ **knowing if the UI actually works**. For backend code there are unit and
9
+ integration tests. For UI, a human still has to open the app, log in, click
10
+ around, and report what's broken. That human-in-the-loop is slow, boring, and
11
+ the main bottleneck when an entire product is built by AI.
12
+
13
+ ## The idea
14
+
15
+ Eliminate the human from the UI-debug loop with an MCP server.
16
+
17
+ - A **smart agent** (Claude Code, Cursor, …) finishes a PR and wants to verify the UI.
18
+ - It hands a **story** to this server: *"on web, log in and do X, Y, Z — tell me if it breaks."*
19
+ - A **small fast agent runs inside this server** (via the Vercel AI SDK). It drives
20
+ the browser or desktop, watches console + network, takes screenshots.
21
+ - It reports **structured findings** back: pass/fail, what broke, evidence.
22
+ - The smart agent fixes the code and asks again. **Loop until the UI works.**
23
+
24
+ Unlike [playwright-mcp](https://github.com/microsoft/playwright-mcp) — where the
25
+ smart model issues every single click itself — here the smart model stays
26
+ high-level and delegates the whole clicking loop to the small agent.
27
+
28
+ ## How it's different from playwright-mcp
29
+
30
+ | | playwright-mcp | UI Debugger MCP |
31
+ |---|---|---|
32
+ | Who clicks | smart model, one action per call | small agent, on its own |
33
+ | Tools exposed | many (click, type, snapshot…) | few (give a story, get findings) |
34
+ | Smart model cost | high (chatty) | low (high-level) |
35
+ | Output | raw page state | structured findings + evidence |
36
+
37
+ ## Architecture — the three actors
38
+
39
+ Picture a **boss**, a **fast blind driver**, and a **describer with eyes**:
40
+
41
+ ```
42
+ ┌─────────────┐ MCP conversation ┌──────────────────────────────────────┐
43
+ │ smart agent │ start_debug ───────▶ │ UI Debugger MCP server │
44
+ │ (Claude) │ send_message (live) │ │
45
+ │ │ ◀─────── get_findings │ ┌────────────┐ ┌────────────┐ │
46
+ │ sets goals │ │ │ fast guy │ look│ vision guy │ │
47
+ │ fixes code │ │ │ (driver) │────▶│ (eyes) │ │
48
+ │ loops │ │ │ deepseek │◀────│ glm 5v │ │
49
+ └─────────────┘ │ │ text·blind │ desc│ image │ │
50
+ ▲ │ └─────┬──────┘ └────────────┘ │
51
+ │ "works + looks nice" │ observe / act (SQL-like) │
52
+ │ findings + screenshots │ │ shared adapter contract │
53
+ └──────────────────────────────│─────────┼─────────────────────────────│
54
+ └─────────┼─────────────────────────────┘
55
+ ▼
56
+ ┌──────────────┬──────────────┬──────────────┐
57
+ │ web (CDP) │ desktop │ android │
58
+ │ browser │ X11/Wayland │ ADB │
59
+ └──────────────┴──────────────┴──────────────┘
60
+ ```
61
+
62
+ - **smart agent** — the boss (Claude/caller). Sends a goal, reads findings, **fixes
63
+ the code**, loops. Stays high-level — never clicks.
64
+ - **fast guy** — the driver. Fast, cheap, **text-only and blind**. Runs the
65
+ click loop on structure (DOM / a11y tree / view hierarchy). Default: deepseek.
66
+ - **vision guy** — the eyes. **Multimodal**. The driver calls `look` to ask
67
+ *"does this look right? is the button centred?"* and gets a description back.
68
+ Default: glm. Spent only when visual judgment is needed.
69
+
70
+ One goal: **the UI works *and* looks nice.** Full design in [`docs/idea/`](docs/idea/).
71
+
72
+ Every run keeps its screenshots and stitches them into a short **captioned
73
+ replay video** — Claude attaches it to the PR so a reviewer sees the flow working
74
+ in ~10 seconds ([`docs/idea/workspace.md`](docs/idea/workspace.md#pr-replay-video)).
75
+
76
+ ## Targets
77
+
78
+ One project can expose several debug targets. A large app can have all three:
79
+
80
+ | Target | Protocol / how it's driven | Reads |
81
+ |---------|--------------------------------------------------|-------|
82
+ | web | **CDP** (Chrome DevTools Protocol), headless by default | DOM |
83
+ | desktop | **X11 / Wayland** input + AT-SPI | a11y tree / vision |
84
+ | mobile | **ADB** (uiautomator + screencap), Android | view hierarchy / vision |
85
+
86
+ Three adapters, one shared contract. Each runs **managed** (server launches the
87
+ target) or **attach** (connect to a running one via `cdpUrl` / `adbSerial`).
88
+ Linux first. iOS is out of scope on Linux (macOS-only tooling).
89
+
90
+ ## Setup
91
+
92
+ Install like any local MCP server — one entry in your `.mcp.json`:
93
+
94
+ ```jsonc
95
+ {
96
+ "mcpServers": {
97
+ "ui-debugger": {
98
+ "command": "npx",
99
+ "args": ["-y", "@developerz.ai/ui-debugger-mcp"],
100
+ "env": {
101
+ "OPENAI_API_KEY": "sk-...",
102
+ "OPENAI_BASE_URL": "https://openrouter.ai/api/v1"
103
+ }
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ Then add a per-project `.ui-debugger-mcp.json` describing the app to debug
110
+ (models, targets, urls). The fastest way is the `init` command:
111
+
112
+ ```bash
113
+ npx @developerz.ai/ui-debugger-mcp init # in your project root
114
+ ```
115
+
116
+ **`ui-debugger-mcp init`** scaffolds a project for debugging (described in
117
+ [`docs/idea/config.md`](docs/idea/config.md)):
118
+
119
+ - creates the workspace dir `./tmp/ui-debugger-mcp/`
120
+ - writes a starter `.ui-debugger-mcp.json` (default deepseek/glm models, a `web`
121
+ target stub) if one doesn't already exist
122
+ - adds `tmp/` to `.gitignore`
123
+ - prints the `.mcp.json` snippet to paste (it never writes your API key)
124
+
125
+ Config files:
126
+
127
+ - `.mcp.json` → **how to launch** the server (command + secret key). Gitignored.
128
+ - `.ui-debugger-mcp.json` → **how to debug this app** (models, targets). Committed.
129
+
130
+ The server reads the **current directory** to pick the project session — open it
131
+ in your repo and it debugs that repo.
132
+
133
+ ## Quickstart
134
+
135
+ ```bash
136
+ # 1. Scaffold the project (run once in your app's root)
137
+ npx @developerz.ai/ui-debugger-mcp init
138
+ ```
139
+
140
+ This creates `./tmp/ui-debugger-mcp/`, writes a starter `.ui-debugger-mcp.json`,
141
+ and prints the `.mcp.json` snippet to paste.
142
+
143
+ ```jsonc
144
+ // 2. Paste into your project's .mcp.json (add your API key)
145
+ {
146
+ "mcpServers": {
147
+ "ui-debugger": {
148
+ "command": "npx",
149
+ "args": ["-y", "@developerz.ai/ui-debugger-mcp"],
150
+ "env": {
151
+ "OPENAI_API_KEY": "sk-...",
152
+ "OPENAI_BASE_URL": "https://openrouter.ai/api/v1"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ ```jsonc
160
+ // 3. Edit .ui-debugger-mcp.json — set your app's URL
161
+ {
162
+ "targets": {
163
+ "web": { "adapter": "browser", "url": "http://localhost:3000" }
164
+ }
165
+ }
166
+ ```
167
+
168
+ ```text
169
+ // 4. In Claude Code (or any MCP client):
170
+ start_debug { target: "web", goal: "log in and add item 3 to the cart" }
171
+
172
+ // 5. Poll until done:
173
+ get_findings { session_id: "...", wait: true }
174
+
175
+ // 6. Read bugs[] + visual[] + summary. Fix code, repeat.
176
+ ```
177
+
178
+ ## Using it
179
+
180
+ It's a **conversation**, not a remote control — five fat tools, not one-per-click:
181
+
182
+ | Tool | What it does |
183
+ |------|--------------|
184
+ | `start_debug` | Open a run: `{ target, goal, criteria?, timeout? }`. The small agent drives autonomously. Returns `{ session_id }`. |
185
+ | `get_findings` | Poll status + structured findings (functional bugs + visual issues) + evidence. Long-poll with `wait`. |
186
+ | `send_message` | Talk to the running agent mid-flight — add work, redirect, or answer a question. |
187
+ | `describe` | List the configured targets + models for this project. |
188
+ | `end_session` | Close the run, free the browser/profile. |
189
+
190
+ A run is **always time-capped**: `start_debug`'s `timeout` (seconds) overrides the
191
+ default 300s, so a session can never hang forever — it auto-ends and frees the
192
+ profile lock when the cap fires.
193
+
194
+ Typical loop from a smart agent:
195
+
196
+ ```text
197
+ start_debug { target: "web", goal: "log in and add item 3 to the cart" }
198
+ → poll get_findings (wait) until status is passed | failed
199
+ → read bugs[] + visual[] + summary, fix the code, start_debug again
200
+ ```
201
+
202
+ You can also drive it **headless** from a script with `claude -p` — see
203
+ [`docs/claude/SKILL.md`](docs/claude/SKILL.md) for the CLI recipe (MCP config,
204
+ allowed tools, output formats).
205
+
206
+ ### CLI — check or stop a run
207
+
208
+ The `ui-debugger-mcp` binary doubles as a control CLI for the active run
209
+ (reads `state.json`, no API key needed):
210
+
211
+ ```bash
212
+ ui-debugger-mcp status # which run is active, server pid, verdict, finding counts
213
+ ui-debugger-mcp stop # gracefully end the run (frees the browser + profile)
214
+ ```
215
+
216
+ ## Troubleshooting
217
+
218
+ **Chrome not found**
219
+ The web adapter launches Chrome via the system PATH. Install Chrome/Chromium, or
220
+ set `executablePath` in `.ui-debugger-mcp.json`:
221
+ ```jsonc
222
+ "web": { "adapter": "browser", "url": "...", "executablePath": "/usr/bin/chromium-browser" }
223
+ ```
224
+
225
+ **Session locked — "another run is active"**
226
+ One Chrome profile = one run. If a previous run crashed without cleaning up:
227
+ ```bash
228
+ npx @developerz.ai/ui-debugger-mcp stop # graceful teardown
229
+ ```
230
+ Or delete `./tmp/ui-debugger-mcp/state.json` and restart the MCP server.
231
+
232
+ **Run times out with no findings**
233
+ Default cap is 300 s. Raise it per-call:
234
+ ```text
235
+ start_debug { target: "web", goal: "...", timeout: 600 }
236
+ ```
237
+ If the agent is stuck at login, add `?debug-ai=true` to your app's login route
238
+ (gated by `ALLOW_AI_DEBUG_LOGIN`) to skip captchas — see `CLAUDE.md` for the
239
+ pattern.
240
+
241
+ **`get_findings` returns empty `bugs[]` / `visual[]`**
242
+ The run may still be in progress — use `wait: true`:
243
+ ```text
244
+ get_findings { session_id: "...", wait: true }
245
+ ```
246
+ Check `./tmp/ui-debugger-mcp/<project>/logs/agent.log` for the agent's trace.
247
+
248
+ **`replay.mp4` not generated**
249
+ ffmpeg is optional. Install it and retry, or ignore — findings and screenshots
250
+ still land without it.
251
+
252
+ ## Stack
253
+
254
+ - **Bun** + **TypeScript** (ships as npm, runs via `npx`/`bunx`)
255
+ - **Vercel AI SDK** — the agent loop (fast driver + vision describer)
256
+ - **Any OpenAI-compatible router** (OpenRouter default) — swap models per role.
257
+ Defaults: **deepseek** (text) drives, **glm** (image) sees.
258
+ - **CDP** for web, **X11/Wayland** for desktop, **ADB** for Android
259
+ - stdio MCP transport
260
+
261
+ ## Status
262
+
263
+ All three adapters ship in v1:
264
+
265
+ | Target | State |
266
+ |---------|-------|
267
+ | web | ✅ shipped (CDP, headless + attach) |
268
+ | desktop | ✅ shipped (X11/Wayland, AT-SPI + xdotool) |
269
+ | android | ✅ shipped (ADB, uiautomator) |
270
+
271
+ Replay video (`replay.mp4`, captioned stills → mp4 via ffmpeg) ships with the web adapter.
272
+ ffmpeg is optional — absent gracefully, findings still land.
273
+
274
+ See [`docs/idea/`](docs/idea/) for design notes.
275
+
276
+ ## Docs
277
+
278
+ - [`docs/idea/overview.md`](docs/idea/overview.md) — problem + idea
279
+ - [`docs/idea/architecture.md`](docs/idea/architecture.md) — system design
280
+ - [`docs/idea/adapters.md`](docs/idea/adapters.md) — adapter contract + targets
281
+ - [`docs/idea/desktop-control.md`](docs/idea/desktop-control.md) — Linux control tooling (X11/Wayland/mobile)
282
+ - [`docs/idea/agent-loop.md`](docs/idea/agent-loop.md) — the story → findings loop
283
+ - [`docs/idea/mcp-tools.md`](docs/idea/mcp-tools.md) — two tool layers, SQL-like params, in-repo prompts
284
+ - [`docs/idea/models.md`](docs/idea/models.md) — the three actors (smart agent / fast guy / vision guy)
285
+ - [`docs/idea/config.md`](docs/idea/config.md) — config files
286
+ - [`docs/idea/workspace.md`](docs/idea/workspace.md) — per-project space + logs
287
+ - [`docs/claude/SKILL.md`](docs/claude/SKILL.md) — driving `claude` as a headless CLI tool (generic)
288
+ - [`CLAUDE.md`](CLAUDE.md) — instructions for AI agents working on this repo
289
+
290
+ ## Credits / influences
291
+
292
+ - [`ai-task-master`](../ai-task-master) — build template (orchestrator + subagents)
293
+ - [`gold-standards-in-ai`](../gold-standards-in-ai) — MCP & code conventions
294
+ - [`claude-code-bible`](../../sebyx07/claude-code-bible) — agent-first patterns
295
+ - [Model Context Protocol](https://modelcontextprotocol.io/docs/develop/connect-local-servers)
@@ -0,0 +1,38 @@
1
+ /**
2
+ * ADB (Android Debug Bridge) transport — the one I/O seam for the android adapter.
3
+ *
4
+ * Android is **fully framework-driven** (no vision needed): every read/act/capture
5
+ * is an `adb` subprocess (`idea/desktop-control.md`). This module is the thin runner
6
+ * that shells out; all command *shapes* (`input tap`, `uiautomator dump`, keycodes)
7
+ * live in the pure builders beside it (`commands.ts`, `uiautomator.ts`) so they stay
8
+ * unit-testable without spawning. {@link AdbCli} is injected as a seam in tests.
9
+ *
10
+ * Three channels, mirroring `adb`'s own surface:
11
+ * - {@link Adb.shell} — `adb shell <cmd>` → text (am/input/uiautomator/getprop/logcat).
12
+ * - {@link Adb.execOut} — `adb exec-out <cmd>` → **raw bytes** (binary-safe `screencap -p`).
13
+ * - {@link Adb.adb} — top-level `adb <args>` (`wait-for-device`, `emu kill`).
14
+ *
15
+ * Target selection is baked into the `flags` at construction: `['-s', serial]` for an
16
+ * attached device, `['-e']` for the single managed emulator. Fails loud — a non-zero
17
+ * exit or a missing binary rejects as an {@link AdbError}, never a silent fallback.
18
+ */
19
+ /** The ADB transport the adapter depends on — implemented by {@link AdbCli}, faked in tests. */
20
+ export interface Adb {
21
+ /** `adb <target> shell <command…>` → stdout text. */
22
+ shell(command: string[]): Promise<string>;
23
+ /** `adb <target> exec-out <command…>` → raw stdout bytes (binary-safe, e.g. `screencap -p`). */
24
+ execOut(command: string[]): Promise<Uint8Array>;
25
+ /** `adb <target> <args…>` → stdout text (top-level: `wait-for-device`, `emu kill`, …). */
26
+ adb(args: string[]): Promise<string>;
27
+ }
28
+ /**
29
+ * `execFile`-backed {@link Adb}. Construct with the device-selection `flags`
30
+ * (`['-s', serial]` to attach · `['-e']` for the managed emulator).
31
+ */
32
+ export declare class AdbCli implements Adb {
33
+ #private;
34
+ constructor(flags: string[]);
35
+ shell(command: string[]): Promise<string>;
36
+ adb(args: string[]): Promise<string>;
37
+ execOut(command: string[]): Promise<Uint8Array>;
38
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * ADB (Android Debug Bridge) transport — the one I/O seam for the android adapter.
3
+ *
4
+ * Android is **fully framework-driven** (no vision needed): every read/act/capture
5
+ * is an `adb` subprocess (`idea/desktop-control.md`). This module is the thin runner
6
+ * that shells out; all command *shapes* (`input tap`, `uiautomator dump`, keycodes)
7
+ * live in the pure builders beside it (`commands.ts`, `uiautomator.ts`) so they stay
8
+ * unit-testable without spawning. {@link AdbCli} is injected as a seam in tests.
9
+ *
10
+ * Three channels, mirroring `adb`'s own surface:
11
+ * - {@link Adb.shell} — `adb shell <cmd>` → text (am/input/uiautomator/getprop/logcat).
12
+ * - {@link Adb.execOut} — `adb exec-out <cmd>` → **raw bytes** (binary-safe `screencap -p`).
13
+ * - {@link Adb.adb} — top-level `adb <args>` (`wait-for-device`, `emu kill`).
14
+ *
15
+ * Target selection is baked into the `flags` at construction: `['-s', serial]` for an
16
+ * attached device, `['-e']` for the single managed emulator. Fails loud — a non-zero
17
+ * exit or a missing binary rejects as an {@link AdbError}, never a silent fallback.
18
+ */
19
+ import { execFile } from 'node:child_process';
20
+ import { promisify } from 'node:util';
21
+ import { AdbError } from '../../errors.js';
22
+ const pExecFile = promisify(execFile);
23
+ const ADB = 'adb';
24
+ /** 64 MiB stdout cap — `screencap -p` PNGs run a few MB on hi-dpi panels; text replies are tiny. */
25
+ const MAX_BUFFER = 64 * 1024 * 1024;
26
+ /**
27
+ * `execFile`-backed {@link Adb}. Construct with the device-selection `flags`
28
+ * (`['-s', serial]` to attach · `['-e']` for the managed emulator).
29
+ */
30
+ export class AdbCli {
31
+ #flags;
32
+ constructor(flags) {
33
+ this.#flags = flags;
34
+ }
35
+ shell(command) {
36
+ return this.#text(['shell', ...command]);
37
+ }
38
+ adb(args) {
39
+ return this.#text(args);
40
+ }
41
+ async execOut(command) {
42
+ const args = ['exec-out', ...command];
43
+ try {
44
+ const { stdout } = await pExecFile(ADB, [...this.#flags, ...args], {
45
+ encoding: 'buffer',
46
+ maxBuffer: MAX_BUFFER,
47
+ });
48
+ return Uint8Array.from(stdout);
49
+ }
50
+ catch (error) {
51
+ throw this.#wrap(args, error);
52
+ }
53
+ }
54
+ async #text(args) {
55
+ try {
56
+ const { stdout } = await pExecFile(ADB, [...this.#flags, ...args], { maxBuffer: MAX_BUFFER });
57
+ return stdout;
58
+ }
59
+ catch (error) {
60
+ throw this.#wrap(args, error);
61
+ }
62
+ }
63
+ /** Wrap any subprocess failure as a loud {@link AdbError} (ENOENT → a clear install hint). */
64
+ #wrap(args, error) {
65
+ if (error instanceof Error && error.code === 'ENOENT') {
66
+ return new AdbError('android: `adb` not found on PATH (install Android platform-tools)');
67
+ }
68
+ const message = error instanceof Error ? error.message : String(error);
69
+ return new AdbError(`adb ${args[0] ?? ''} failed: ${message}`);
70
+ }
71
+ }
72
+ //# sourceMappingURL=adb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adb.js","sourceRoot":"","sources":["../../../src/adapters/android/adb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEtC,MAAM,GAAG,GAAG,KAAK,CAAC;AAElB,oGAAoG;AACpG,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAYpC;;;GAGG;AACH,MAAM,OAAO,MAAM;IACR,MAAM,CAAW;IAE1B,YAAY,KAAe;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAiB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,GAAG,CAAC,IAAc;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAiB;QAC7B,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE;gBACjE,QAAQ,EAAE,QAAQ;gBAClB,SAAS,EAAE,UAAU;aACtB,CAAC,CAAC;YACH,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAc;QACxB,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9F,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,8FAA8F;IAC9F,KAAK,CAAC,IAAc,EAAE,KAAc;QAClC,IAAI,KAAK,YAAY,KAAK,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjF,OAAO,IAAI,QAAQ,CAAC,mEAAmE,CAAC,CAAC;QAC3F,CAAC;QACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;CACF"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Android adapter — drives an emulator/device over **ADB** behind the shared
3
+ * {@link Adapter} contract, so the agent loop stays adapter-blind.
4
+ *
5
+ * Composition (split per SRP — see siblings):
6
+ * - transport → {@link Adb} (`adb` subprocess seam, `adb.ts`)
7
+ * - read → {@link UiAutomatorSource} (`uiautomator dump` → view hierarchy, `uiautomator.ts`)
8
+ * - commands → pure argv builders (`input tap/text/swipe/keyevent`, `commands.ts`)
9
+ *
10
+ * **Managed or attach** (`idea/adapters.md`): with an `adbSerial` the adapter attaches
11
+ * to a running device and `close` is disconnect-only (never stops it); otherwise it
12
+ * boots the configured `emulator @avd`, waits for `sys.boot_completed`, and `close`
13
+ * stops it. Android is fully framework-driven — no vision needed for actions.
14
+ *
15
+ * `console` is logcat-backed (real crash/error signal); `network` has no ADB channel
16
+ * and throws loud ({@link AdapterError}). Every backend failure surfaces as an
17
+ * {@link AdapterError}; our own loud errors pass through un-rewrapped.
18
+ */
19
+ import type { AndroidTarget } from '../../config/schema.js';
20
+ import type { Adapter, ConsoleEntry, Filters, LogQuery, NetworkEntry, Node, NodeRef, Query, ScrollOptions, WaitOptions } from '../contract.js';
21
+ import { type Adb } from './adb.js';
22
+ import { type UiAutomatorSource } from './uiautomator.js';
23
+ /**
24
+ * Parse `logcat -v epoch` output into {@link ConsoleEntry}s (oldest first, as emitted).
25
+ * Line shape: `1546300800.000 1000 1000 I Tag: message` — unmatched lines are skipped.
26
+ */
27
+ export declare function parseLogcat(raw: string): ConsoleEntry[];
28
+ /** Apply the whitelisted console `filters` (logcat). Loud on an unknown key or wrong type. */
29
+ export declare function applyLogFilters(entries: ConsoleEntry[], filters?: Filters): ConsoleEntry[];
30
+ export interface AndroidAdapterInit {
31
+ /** Resolved android-target config (avd, emulatorPath, adbSerial). */
32
+ config: AndroidTarget;
33
+ /** Override the ADB transport (defaults to {@link AdbCli}); a seam for tests. */
34
+ adb?: Adb;
35
+ /** Override the read source (defaults to {@link AdbUiAutomator}); a seam for tests. */
36
+ ui?: UiAutomatorSource;
37
+ }
38
+ /**
39
+ * The android {@link Adapter}: an ADB + uiautomator pair behind one contract.
40
+ * Construct via {@link AndroidAdapter.create}.
41
+ */
42
+ export declare class AndroidAdapter implements Adapter {
43
+ #private;
44
+ private constructor();
45
+ /** Wire the adapter from config: `adbSerial` → attach (`-s serial`), else managed emulator (`-e`). */
46
+ static create(init: AndroidAdapterInit): AndroidAdapter;
47
+ /** Ensure the device is up (managed: boot the emulator), then start the activity/package. */
48
+ open(target: string): Promise<void>;
49
+ find(opts: Query): Promise<Node | null>;
50
+ readState(opts?: Query): Promise<Node[]>;
51
+ click(target: NodeRef): Promise<void>;
52
+ type(target: NodeRef, text: string): Promise<void>;
53
+ pressKey(key: string): Promise<void>;
54
+ scroll(opts: ScrollOptions): Promise<void>;
55
+ screenshot(): Promise<Uint8Array>;
56
+ waitFor(opts: WaitOptions): Promise<void>;
57
+ /** Drain recent logcat as normalized console entries (newest first), narrowed by {@link LogQuery}. */
58
+ console(opts?: LogQuery): Promise<ConsoleEntry[]>;
59
+ /** Android exposes no network channel over ADB — unsupported, surfaced loud. */
60
+ network(): Promise<NetworkEntry[]>;
61
+ /** Attach: disconnect-only (never stop the device). Managed: stop the emulator. */
62
+ close(): Promise<void>;
63
+ }