WebDroid Agent logo

# WebDroid Agent

中文 | English

WebDroid Agent is a browser-first Android phone agent experiment. In static deployments, it runs entirely on the frontend. It connects to an Android device from the browser through WebUSB/WebADB, captures the device screen, sends it to an OpenAI-compatible vision model, then parses, validates, and executes the model's constrained action through ADB. Docker deployments add a local Node API proxy so model requests go through the container instead of directly from the browser. The goal is not to replace long-running human supervision. It is a local browser environment for quickly validating the vision-model-plus-phone-control loop. [Live site](https://webdroid-agent.pages.dev/) · [中文](./README.md) · [Tango / WebADB](https://github.com/yume-chan/ya-webadb) ```text Chromium WebUSB -> Tango/WebADB -> Android ADB Static deployment: Official OpenAI: browser fetch -> /v1/responses -> vision model Other providers: browser fetch -> /v1/chat/completions or Gemini generateContent Docker: browser fetch -> same-origin local proxy (/chat/completions or /responses) -> model API ``` ## Contents - [What It Can Do](#what-it-can-do) - [Good Fits](#good-fits) - [Project Status](#project-status) - [Flow](#flow) - [Requirements](#requirements) - [Quick Start](#quick-start) - [Configuration](#configuration) - [Docker Deployment](#docker-deployment) - [Action Protocol](#action-protocol) - [Device Control Details](#device-control-details) - [Screen Observation and Self-Checks](#screen-observation-and-self-checks) - [Safety Boundaries](#safety-boundaries) - [Project Structure](#project-structure) - [Verification](#verification) - [Roadmap](#roadmap) - [Contributing](#contributing) - [Deploying to Cloudflare Pages](#deploying-to-cloudflare-pages) - [License](#license) - [Related Projects and Community](#related-projects-and-community) ## What It Can Do - Run entirely on the frontend for static deployments such as Cloudflare Pages. - Use the built-in same-origin local API proxy in Docker deployments to avoid model-provider browser CORS limits. - Connect to an Android device with USB debugging enabled through WebADB in the browser. - Capture the phone screen and send the screenshot, current app, device state, full installed-app list, and step history to the model. - Use WebDroid JSON-family action protocols and canonical JSON action format: `webdroid_json` uses screenshot pixels, while `webdroid_normalized_json` uses Vision-Pointer-style 0-1000 normalized coordinates. - Parse, normalize, and validate the next action returned by the model. - Execute app launches, taps, swipes, text input, Back, Home, long press, double tap, and wait actions through ADB, including model-controlled wait duration. - Support clear-before-type input, waiting for the screen to settle after an action, transient model API and empty-model-response retries, and automatic recovery for a fixed whitelist (`action_stale` plus the transient device errors `device_io` / `device_timeout`, three attempts before `awaiting_review`); every other failure class stops after one attempt. - Support editable App Cards, local Custom Tools, and safe Secret typing that exposes only IDs/labels to the model. - Support continuous auto-execution as well as step-by-step human confirmation. - Send chat messages to run automatically, with one-step planning kept in advanced debug controls. - Support sensitive-action confirmation, unrestricted mode, max-step limits, true pause/resume from the current checkpoint, stop controls, and advanced reset/run-log export. - Persist page settings in the local browser `localStorage`, and persist agent thread/turn history in IndexedDB. - Judge every action by diffing the UI tree before and after it (`done` / `small_change` / `no_effect` / `place_changed`), and give each element a ref that survives re-dumps: `tap_ref` taps by ref, and an expired ref is reported instead of tapping the wrong place. - Name why a screen is unusable (still loading, blank, capture-blocked, unreadable, needs a human) and pick the takeover kind from the screen itself rather than from the model's wording. - Memory (when enabled): facts the model records are not dumped back into every prompt; the few most relevant items are retrieved per task, and anything containing a password, verification code, ID number, card number, or API key is refused at write time. - Skills: a run that finishes is drafted into a procedure and offered as a suggestion the next time a similar task comes up; the skill text is treated as untrusted data too. - Answer grounding: quotes, unit-bearing numbers, and dates in the final answer are checked by plain code against what the run actually read; a mismatch is logged, never silently rewritten. - Operate the console from the keyboard: `Cmd/Ctrl+K` focuses the composer, `Cmd/Ctrl+B` toggles the configuration panel, `Cmd/Ctrl+J` toggles the run log. `Esc` closes only the top-most dialog and never stops a run by itself; use the Stop button instead. The divider between the phone preview and the chat pane can be dragged (double-click resets it). ## Good Fits This project is a good fit for: - Testing whether an OpenAI-compatible vision model can understand real Android UI. - Debugging the phone-agent JSON action format, coordinate mapping, and auto-execution loops. - Building Android UI automation prototypes in a local and controlled environment. It is not a good fit for: - Payments, checkout flows, deletions, authorization, or account settings. - Login, captcha, password, or verification-code flows that need explicit human intervention. - Production use cases that require a backend, long-running reliability, or multi-device orchestration. ## Project Status The project is at an experimentally usable stage; the core loop already works: - Connect to an Android device from the browser and capture its screen. - Ask an OpenAI-compatible vision model for the next action. - Parse the canonical JSON action. - Execute the common ADB control commands and record a run log. - Support chat-driven auto-execution, human confirmation, stop, context restoration, and automatic recovery for `action_stale` plus transient device errors. - Screen diagnosis, action-effect verdicts, stable element refs, memory retrieval, skill reuse, and answer grounding sit on the same loop. It is still best treated as a local experiment. Real devices, model quality, browser permissions, CORS configuration, and Android ROM differences all affect the result. ## Flow 1. Open the app in a Chromium-based browser. 2. Connect an Android device with USB debugging enabled and authorize ADB on the phone. 3. Fill in the OpenAI-compatible `Base URL`, `API Key`, and `Model`; use **Test connection** to verify them first (Docker routes the check through the same-origin proxy). 4. Type a natural-language instruction in the chat, such as "Open Settings and go to Wi-Fi". 5. Sending the message captures the screen and asks the model for one action. 6. The frontend parses and validates the action, then executes safe actions automatically while sensitive actions ask for confirmation by default. 7. Only whitelisted failures (`action_stale` plus the transient device errors `device_io` / `device_timeout`) are retried automatically: the failure feedback is added to the next model context and the run moves to `awaiting_review` after three attempts. Every other failure class stops after one attempt. An expired element ref belongs to this bucket: re-read the screen and continue. 8. The loop continues until the model returns `done`, requests `take_over`, the max step count is reached, or the user stops execution; unrestricted mode does not stop on `take_over`. ## Requirements - A Chromium-based browser with WebUSB support, such as Chrome or Edge. - An Android device with USB debugging enabled. - A USB data cable. - A vision model API: **Official OpenAI** (`/v1/responses`, default model `gpt-5.6`), **OpenAI-compatible** `/v1/chat/completions`, **Qwen** compatible endpoint, or **Gemini** native `generateContent`. - A vision model that accepts screenshot/image input. - For static deployments, an API service configured to allow browser cross-origin requests. Docker deployments can avoid this for OpenAI official and compatible providers through the same-origin local proxy (Gemini still calls Google directly). - A `localhost` or HTTPS environment so WebUSB can work. ## Quick Start ```bash npm install npm run dev ``` Then open the local URL printed by Vite in Chrome or Edge. Common commands: ```bash npm test npm run lint npm run build npm run build:server # required for Docker / npm start proxy npm run preview ``` ## Configuration The app stores these values in the current browser's `localStorage`: - `Provider`: provider preset. `OpenAI` uses the Responses API; `OpenAI Compatible` / `Qwen` use chat completions; `Gemini` uses native generateContent. - `Base URL`: model API endpoint. Official OpenAI defaults to `https://api.openai.com/v1`; Qwen/Gemini have their own presets. - `API Key`: model API key. - `Model`: model name. Official OpenAI defaults to `gpt-5.6`; the compatible fallback default remains `gpt-5.5`. - `Thinking depth` / reasoning options: `reasoning_effort` for compatible endpoints; official OpenAI also supports reasoning mode (standard/pro) and reasoning summary; Qwen/Gemini use their own thinking budget or thinking level. - `Action protocol`: model action protocol. `webdroid_json` uses screenshot pixel coordinates; `webdroid_normalized_json` uses 0-1000 normalized coordinates. - `Max steps`: maximum auto-execution steps, default `150`. - `Confirm sensitive actions`: whether sensitive taps require human confirmation, default on. - `Safety strictness`: `Relaxed` / `Standard` (default) / `Strict`. It only moves verdicts inside each category's own floor and ceiling: relaxing never runs a payment or an account deletion, and tightening never turns a human step into a dead end. - `Unrestricted mode`: bypass local safety policy and sensitive confirmations, and prompt the model not to request human takeover. - `Stream responses`: whether to use streaming responses, default off. Streaming sends `stream_options.include_usage` so usage can be counted while the run is in flight; if a compatible gateway rejects that field the request is retried once without it, the run continues, and the log notes that the token count will be incomplete. - `Use ADB Keyboard for text`: whether to prefer ADB Keyboard input, default off. - `Memory`: whether the model may record durable facts with `note`, default off. When enabled, a run retrieves the most relevant items per task (at most 6 items / 1800 characters); anything containing a password, verification code, ID number, card number, or API key is never written. - `Task notifications`: send a system notification when a run ends; requires browser permission, default off. - `Darken screen during auto control`: dim the phone screen while the agent runs and restore the original brightness when it ends or fails, default off. - `Action tool toggles`: disable individual action tools; a disabled tool never appears in the model's tool list. - `Theme` / `Language`: UI theme (follow system / light / dark) and UI language (follow system / Chinese / English). They only affect the local interface. - `Action settle`, `Double tap interval`, `Keyboard step`: `Action settle` is the minimum wait after an action; the app then polls the screenshot until the screen settles, up to three times that value. The other two control the double-tap interval and per-character input pacing. - `App Cards`: package-name keyed editable app context cards; Chrome, Gmail, and Settings are built in by default. - `Secrets`: local secret records; the model sees only `id` and `label`, and `type_secret` resolves the value locally at execution time. - `Custom Tools`: local tool definitions; the model sees only tool names/descriptions, and local results are returned into later context. The API key stays in the browser only for static deployments. Docker deployments send model requests to the same-origin local proxy first, then the container's Node service forwards them to the configured model API so the browser does not need CORS access to the model provider. ## Docker Deployment The Docker image builds the same frontend app and enables a small local Node service (TypeScript compiled to `dist-server/`): - WebUSB/WebADB still runs in the browser. - The frontend posts through the same-origin `/api/openai/chat/completions` proxy envelope. Official OpenAI sets the upstream path to `/responses` inside that envelope; compatible providers use `/chat/completions`. - The Node service reads the request `Base URL`, `API Key`, and payload, then forwards them to the model API. - The Gemini preset bypasses this proxy and calls Google directly from the browser. - Cloudflare Pages does not use this Node service and does not set the proxy build variable, so the hosted static app still calls the configured model API directly from the browser. Build and run: ```bash npm run docker:build docker run --rm -p 8080:8080 webdroid-agent ``` Then open this URL in Chrome or Edge: ```text http://localhost:8080/ ``` If you use the repository Docker Compose config: ```bash docker compose up -d --build ``` Then open: ```text http://localhost:8083/ ``` You do not need to pass the API key as an environment variable. Continue entering it in the model settings panel. Do not expose this container proxy directly to an untrusted public network because it forwards arbitrary OpenAI-compatible `Base URL` values submitted by the browser. ### Proxy hardening (optional) The defaults are deliberately conservative: the published port binds to `127.0.0.1` on the host, the process inside the container listens on `0.0.0.0` so the port mapping works, and the server itself defaults to a loopback bind. For shared networks or stricter setups: | Variable | Effect | | --- | --- | | `PROXY_TOKEN` | When set, proxy requests must carry `x-proxy-token: ` or `Authorization: Bearer `; otherwise the proxy answers 401. The UI reads it at runtime from same-origin `GET /api/proxy-token` (`Cache-Control: no-store`, same-origin only), so no frontend rebuild is needed. | | `PROXY_ALLOW_HOSTS` | Comma-separated upstream host allowlist (e.g. `api.openai.com,dashscope.aliyuncs.com`; supports `host:port` and `*.example.com`). Non-matching `Base URL` hosts receive 403. | | `CSP_CONNECT_SRC` | Extra space-separated origins appended to the frontend `Content-Security-Policy` `connect-src`, for custom OpenAI-compatible provider endpoints. | | `HOST` | Server listen address, default `127.0.0.1`; the Docker image sets `0.0.0.0`. | The proxy also rejects cross-site browser requests (`Origin` / `Sec-Fetch-Site` mismatch) and non-`application/json` bodies, so another web page cannot turn a loopback proxy into a blind SSRF/open relay. `PROXY_TOKEN` complements these checks rather than replacing them. Example: ```bash docker run --rm -p 127.0.0.1:8080:8080 \ -e PROXY_TOKEN=change-me \ -e PROXY_ALLOW_HOSTS=api.openai.com,dashscope.aliyuncs.com \ webdroid-agent ``` It is still recommended not to expose the proxy to an untrusted public network. ## Action Protocol The model should return a single JSON object and avoid Markdown or explanatory prose: ```json { "action": "tap", "x": 540, "y": 1280, "reason": "Click the search box" } ``` Only WebDroid JSON-family protocols are currently available: - `webdroid_json`: touch coordinates are pixels in the attached screenshot. - `webdroid_normalized_json`: touch coordinates are Vision-Pointer-style 0-1000 normalized coordinates with the top-left origin. They are mapped back to model screenshot pixels, then to native device pixels before execution. Recommended canonical JSON actions: | Action | Meaning | | --- | --- | | `launch` | Launch an app by common app name or package name | | `tap` | Tap a screen coordinate | | `tap_ref` | Tap the element with a stable ref from the screen tree (such as `e12`), converted to coordinates before execution; an expired ref is reported as `stale` instead of tapping the wrong place | | `swipe` | Swipe from one point to another | | `input_text` | Type text; `clear:true` clears the currently focused field first | | `type_secret` | Type a local secret; the model sends only `secretId` and never sees the value | | `open_url` | Open a web URL or app deep link with Android `ACTION_VIEW` | | `set_clipboard` | Set WebDroid clipboard text and best-effort sync it to the device clipboard | | `paste` | Paste/type WebDroid clipboard text into the current focus | | `custom_tool` | Run a locally configured Custom Tool | | `key` | Send an Android key such as `BACK`, `HOME`, or `ENTER` | | `back` | Navigate back | | `home` | Return to the home screen | | `long_press` | Long-press a coordinate | | `double_tap` | Double-tap a coordinate | | `wait` | Wait for a duration, preferably with `duration` in seconds | | `take_over` | Request human takeover; `kind` may be `login`, `captcha`, `payment`, or `other` | | `note` | Record an observation without touching the device | | `view_screenshot` | Recall an earlier step's screenshot and attach it to the next model request | | `sequence` | Run a bounded list of actions in order, stopping on the first failure | | `repeat` | Repeat one action a given number of times, optionally with a delay | | `done` | Mark the task as complete | Examples: ```json { "action": "launch", "app": "Settings", "reason": "Open system settings" } ``` ```json { "action": "swipe", "fromX": 540, "fromY": 1700, "toX": 540, "toY": 500, "durationMs": 400, "reason": "Scroll the list down" } ``` ```json { "action": "take_over", "kind": "captcha", "message": "The user needs to enter a verification code" } ``` ```json { "action": "type_secret", "secretId": "gmail_password", "clear": true, "reason": "Type the configured local password" } ``` ```json { "action": "open_url", "url": "https://example.com/search?q=webdroid", "reason": "Open the target page directly" } ``` ```json { "action": "tap_ref", "ref": "e12", "reason": "The Wi-Fi switch in the screen tree" } ``` The legacy compatibility layer still accepts `interact` and `call_api`, but they are not recommended real execution actions. `interact` is converted to `take_over`; `call_api` is converted to `take_over` with an unsupported-second-API-call message. ## Device Control Details - Launching apps: prefer the device's installed-app list, and also support built-in common app-name mappings or direct Android package names. - Tap and swipe: coordinates are validated against the screen bounds before execution. - Screen tree: each step best-effort reads `uiautomator dump --compressed` and injects visible text, descriptions, resource ids, clickable state, bounds, and a stable element ref into the model context; the whole block is wrapped in `` and sized according to how much of the screen the tree describes. - Opening URLs: uses Android `am start -a android.intent.action.VIEW -d ` for web URLs and registered deep links. - Long press: simulated with Android `input swipe x y x y duration`. - Double tap: two taps with a configurable delay in between. - Text input: simple ASCII text uses Android `input text`. - Clear-before-type, Chinese, and complex text: use ADB Keyboard or AutoGLM Keyboard broadcast input. - Clipboard: `set_clipboard` stores a local WebDroid clipboard and tries `cmd clipboard set`; `paste` prefers the local clipboard through the current text-input channel. - ADB Keyboard mode requires `com.android.adbkeyboard/.AdbIME` to be installed and enabled on the device; the device panel provides install and enable controls. - After every device action, the app waits for the screen to settle: it waits out `Action settle`, then polls the screenshot and continues once two reads agree, up to three times that budget. ## Screen Observation and Self-Checks Every step rests on what is actually on the screen, so as much of that as possible is decided by code instead of by the model's own guesswork: - **Action effect**: once the next screen arrives, the UI tree before and after the action is diffed structurally (added, removed, moved, edited, toggled, focus). The verdict — `done`, `small_change`, `no_effect`, `place_changed` — goes into the next context as `` and shows up as a chip on the step card. "The tap did nothing" becomes evidence rather than a feeling. - **Stable element refs**: node indexes are reassigned on every dump, so each element also gets a ref (`e12`) that survives re-dumps. `tap_ref` taps by ref and is converted back to coordinates before execution; an expired ref reports `stale`, classifies as the auto-recoverable `action_stale`, and the model simply re-reads the screen instead of tapping the wrong place. - **Screen diagnosis**: a password field, captcha and payment phrase lists, readability, and consecutive black frames decide between `normal`, `loading`, `blank`, `protected`, `capture_unavailable`, and `needs_human`. A capture-blocked app, a black screen, and a page that is still loading each get their own explanation, and the takeover card's kind now comes from the screen rather than from the model's wording. - **Tree quality**: when the tree clearly describes the screen it costs fewer tokens; when most controls are unlabeled or a large region is unreadable, the model gets more nodes plus an explicit warning not to treat a missing node as proof that something is absent. - **Waiting for the screen to settle**: an action no longer sleeps for `Action settle` and hopes. The app polls the screenshot and continues once two reads agree — one poll on a static list, up to three times the budget on a slow page. - **Limit notices**: a short line that appears only after an action ("attempts used up", "too many requests") ends the turn immediately with a "Quota used up" card, so the model cannot burn the remaining steps against the same refusal. - **Screen text is data**: the whole tree reaches the model inside ``, the prompt explains the rule once, and a closing tag inside the payload is escaped — so a screen that prints "ignore your previous instructions" stays data. - **Answer grounding**: screen text and tool results read during the run go into a ledger, and the final answer's quotes, unit-bearing numbers, and dates are checked against it by plain code. A mismatch is logged; the answer is not rewritten and no extra model call is made. Declining to judge is the shared premise: with fewer than two meaningful nodes on either side the effect is not judged at all, a single black frame only counts as loading, and a task that matches no skill simply gets no suggestion. Saying nothing is better than handing the model a conclusion that sends it the wrong way. ## Safety Boundaries The frontend tries to constrain and confirm actions before execution: - Model output must parse into a supported action. - Coordinates are checked against the screen bounds. - Text input is length-limited and control characters are rejected. - `type_secret` receives only a local secret ID from the model; real secret values are not sent to model requests or result summaries. - Auto-execution has a maximum step count. - The user can stop the run at any time. - Sensitive taps can require human confirmation; unrestricted mode skips those confirmations. - `type_secret` is the sanctioned password/verification-code path and is not mistaken for a login takeover just because its reason mentions "password"; irreversible payment/account-deletion actions are still blocked. - Every safety category carries a risk level (`medium` / `high` / `critical`) and sits on a verdict ladder (`allow < confirm < take_over < block`). The strictness setting only moves a verdict between that category's own floor and ceiling; the irreversible guard is outside its reach, and an imported settings file can never relax it. - A blocked action ends the turn as `reviewKind: blocked` and gets a "Blocked by safety policy" card with no Continue button; a payment instead ends as `takeoverKind: payment`, so the card asks the user to pay and then continue. - `take_over`, `note`, and `done` do not directly control the device; legacy `interact` and `call_api` are converted to human takeover unless unrestricted mode is enabled. - In Docker/Node deployments the server binds to loopback by default and can be further restricted with `PROXY_TOKEN` and `PROXY_ALLOW_HOSTS` (see "Docker Deployment · Proxy hardening"). The proxy also rejects cross-site requests and non-JSON bodies. - The ADB Keyboard APK is pinned to a specific commit and its SHA-256 is verified before installation, so upstream changes cannot silently reach the device. The APK comes from a third-party GPL-2.0 repository and is downloaded only on demand. - Model requests have a 180-second overall timeout; a stalled upstream fails as `model_transport` instead of hanging forever. - Server responses carry CSP, `X-Frame-Options: DENY`, and `X-Content-Type-Options: nosniff`; the CSP `connect-src` list can be extended with `CSP_CONNECT_SRC`. - The screen tree and tool results always reach the model wrapped in ``, the prompt states once that this is data and not instructions, and a closing tag inside the payload is escaped. - Memory refuses passwords, verification codes, ID numbers, card numbers, and API keys at write time; when injected, items are retrieved per task instead of the whole store being pasted in. - The final answer is checked by plain code: quotes, unit-bearing numbers, and dates must appear in something the run actually read. A mismatch is logged, never silently rewritten. - Action effects, screen diagnosis, and limit notices only change prompting and stop decisions; they run after the safety verdict and do not move any capability boundary. It is still strongly recommended to avoid letting the agent handle account login, payments, checkout, deletions, authorization, verification codes, or privacy-sensitive pages. By default, when the model returns `take_over`, auto-execution stops and waits for a human; unrestricted mode does not stop on takeover requests. ## Project Structure ```text src/ adapters/ adbKeyboard.ts # ADB Keyboard install, detection, and encoding helpers appPackages.ts # common app-name to package-name mappings deviceParsers.ts # dumpsys and screenshot byte parsing deviceRetry.ts # device-read retry and delay helpers deviceTiming.ts # device execution timing defaults deviceTypes.ts # shared device backend types and errors inputCommands.ts # ADB input command building (with shell escaping) installedApps.ts # installed-app parsing, search, and display names lazyWebAdbBackend.ts # on-demand WebADB backend loading screenBlackoutCommands.ts # screen blackout commands for automatic control sensitiveActions.ts # sensitive action confirmation screenshotPreprocess.ts # screenshot preprocessing shellEscape.ts # shell argument escaping helper stayAwakeCommands.ts # stay-awake commands while ADB is connected uiAutomator.ts # uiautomator dump parsing and UI hierarchy formatting webAdbBackend.ts # WebADB/WebUSB implementation webUsbSupport.ts # WebUSB availability detection components/ AgentCursor.tsx # agent cursor animation AgentStepCard.tsx # agent step card AppContext.tsx # copy and locale context AppErrorBoundary.tsx # render error boundary AppTopbar.tsx # brand and status topbar ChatHistorySidebar.tsx # chat-history sidebar ChatPanel.tsx # chat transcript and composer shell ConfigSidebar.tsx # device and model configuration sidebar composition ConfirmDialog.tsx # shared confirmation dialog ConversationPanel.tsx # chat, history, and pending action view DeviceHomeOptionsSection.tsx # device input, confirmation, and timing options DevicePanel.tsx # device connection and execution settings panel DeviceQuickControls.tsx # direct action strip under the phone preview DeviceToolsSection.tsx # device tools (app list, keyboard, and more) InstalledAppsSection.tsx # installed-app search and launch controls LazyDetails.tsx # lazily rendered collapsible sections LazyMarkdownContent.tsx # lazily loaded Markdown rendering MarkdownContent.tsx # chat message Markdown rendering ModelPanel.tsx # model configuration panel NeedsYouCard.tsx # "needs you" card PendingActionCard.tsx # pending action confirmation card PhoneStage.tsx # phone screenshot and action overlay RunLog.tsx # run log view RunProgressBlock.tsx # run progress block ScreenshotLightbox.tsx # screenshot preview modal SensitiveActionDialog.tsx # sensitive action confirmation dialog (with focus trap) SettingsDialog.tsx # app settings, repository info, and editable resources SetupHome.tsx # first-run device/model setup onboarding ToastViewport.tsx # transient toast container TutorialPanel.tsx # quick-start tutorial expanded from the topbar UnrestrictedModeConfirmDialog.tsx # unrestricted-mode confirmation dialog actionDisplay.ts # action display text helpers configTargets.ts # configuration panel scroll targets deviceDisplay.ts # device display text helpers primitives/ # button and icon-button primitives hooks/ useAgentRunController.ts # auto-run and pending-action control useAgentSessionHistory.ts # session restore, persistence, and history state useBodyOverflow.ts # shared body scroll lock for dialogs and fullscreen useBusyTask.ts # busy-task and error state management useBusyTaskDocumentTitle.ts # busy task reflected in the document title useConfigTargetScroll.ts # config sidebar target scrolling useDeviceBackendPreferences.ts # device backend preference sync useDeviceController.ts # device connection, screenshot, and direct action state useDialogFocusTrap.ts # dialog focus trap useDisplayImageUrl.ts # screenshot blob URL lifecycle useDocumentPreferences.ts # document theme and language attribute sync useHotkeys.ts # global keyboard shortcut registration useLatestValue.ts # ref for reading latest values inside async callbacks useLocalResourcesState.ts # app cards / custom tools / secrets state useOverlayLayer.ts # overlay layer management usePersistedSettings.ts # settings persistence on changes useRepositoryStats.ts # GitHub repository stats loading for settings useRunLog.ts # run-log state management useSplitPane.ts # workspace split dragging and persistence useStorageEstimate.ts # local storage quota estimate useToasts.ts # toast state management useVirtualWindow.ts # virtual window for long lists lib/ abortSignal.ts # abort-signal helpers actionAliases.ts # action alias normalization actionCoordinates.ts # action coordinate conversion helpers actionDefaults.ts # common screenshot action defaults actionEffect.ts # screen-diff verdict for the previous action actionFormats.ts # action format definitions actionParser.ts # action parsing and normalization actionPreview.ts # action preview text formatting actionProtocol.ts # explicit action protocol enum actionRisk.ts # risk levels, verdict ladder, and safety strictness actionSafetyPolicy.ts # local action safety policy actionSecrets.ts # whether an action carries a resolved secret value actionTypes.ts # action types and validation error definitions actionValidation.ts # action field validation (package names, URIs, control chars) agentResources.ts # local Secret and Custom Tool resources agent.ts # agent loop orchestration agentThread.ts # persistent agent thread/turn/event model appCards.ts # editable app context cards appCopy.ts # localized copy aggregation and locale resolution appCopy.en-US.ts # English UI copy appCopy.zh-CN.ts # Chinese UI copy auditLog.ts # local audit log busyTask.ts # in-page busy task identifiers chatComposer.ts # chat composer focus helper chatRun.ts # chat-driven run state helpers contextBuilder.ts # model context building and compaction coordinateSystems.ts # screenshot and device pixel coordinate systems cursorMotion.ts # agent cursor motion path calculation deviceControlTypes.ts # shared device control types deviceDoctor.ts # device and model configuration diagnostics deviceErrors.ts # device error codes mapped onto UI copy deviceState.ts # device state display formatting elementRefs.ts # element refs that survive re-dumps evidenceLedger.ts # ledger of everything the run has read failureTaxonomy.ts # failure classes (FailureClass) and auto-recoverable kinds fileExport.ts # local JSON import/export helpers geminiClient.ts # native Gemini generateContent client geminiTypes.ts # Gemini request/response types grounding.ts # answer grounding checks (quotes, numbers, dates) httpRetry.ts # HTTP retry helpers interactionStream.ts # combined chat message and agent step display stream lazyWithRetry.ts # lazy import that reloads after a stale chunk limitNotice.ts # quota and rate-limit notice detection memory.ts # local agent memory items memoryIndex.ts # memory tokenizer and BM25 retrieval modelConnectionTest.ts # model connection test modelRequestTimeout.ts # model request timeout wrapper needsYou.ts # "needs you" card kind resolution openAiClient.ts # OpenAI-compatible chat completions client openAiErrors.ts # OpenAI client error types openAiPayload.ts # OpenAI-compatible request payload building openAiResponse.ts # OpenAI-compatible response reading and error formatting openAiResponsesClient.ts # official OpenAI Responses API client openAiResponsesTypes.ts # Responses API request/response types openAiRuntimeConfig.ts # OpenAI request runtime configuration openAiTypes.ts # OpenAI client and message types modelProviders.ts # provider presets (OpenAI / Qwen / Gemini) overlayStack.ts # overlay layer stack promptContextFormatting.ts # model context formatting helpers prompts.ts # prompts and action rules proxyToken.ts # same-origin proxy token fetch repository.ts # repository links and GitHub stats parsing runLogEntries.ts # run-log entry and screenshot-view formatting screenshot/ # screenshot coordinates, context, and retention policy coordinates.ts index.ts retention.ts screenDiagnosis.ts # screen state diagnosis (blank, secure, needs human) screenSettle.ts # waits for the screen to stop changing screenshotBlank.ts # decides whether a screenshot is entirely black secretVault.ts # encrypted local secret storage (AES-GCM) sensitiveFilter.ts # sensitive-content gate for memory and skills settings.ts # local settings persistence skillDraft.ts # drafts a skill from a run that finished skillStore.ts # local skill storage and matching taskNotifications.ts # task completion system notifications textRetention.ts # long-text retention policy threadStore.ts # agent thread persistent storage toolRegistry.ts # agent action tool registration and execution trajectory.ts # versioned, sanitised projection of one run trajectoryFixture.ts # trajectory-to-fixture projection (authoritative fixture shape) treeQuality.ts # how much of the screen the tree describes untrusted.ts # wraps device data as untrusted styles/ # styles split by page area agent-step-card.css # agent step-card styles chat-composer.css # chat composer styles chat-history.css # chat-history sidebar styles chat-panel.css # chat panel styles compact-section.css # collapsible tool-section styles config-panel.css # device and model configuration panel styles controls.css # forms, buttons, and shared control styles conversation-panel.css # conversation-panel shell and pending-action styles device-doctor.css # device doctor result styles device-options.css # device execution option styles device-panel.css # device connection section styles direct-commands.css # direct command panel styles index.css # global style entrypoint installed-apps.css # installed-app list styles layout.css # page layout and panel frames markdown-content.css # Markdown content styles model-panel.css # model configuration section styles phone-stage.css # phone preview and action-overlay styles primitives.css # primitive controls and typography styles responsive.css # responsive layout adjustments run-log.css # run-log styles screenshot-lightbox.css # screenshot preview modal styles sensitive-action-dialog.css # sensitive action dialog styles settings-dialog.css # settings dialog styles setup-home.css # setup onboarding styles theme.css # theme tokens and base reset tutorial-panel.css # tutorial panel styles App.tsx # page state, workflow logic, and component composition main.tsx # React entrypoint and global style loading scripts/ bundle-budget.mjs # enforces build output size budgets (runs inside build) css-audit.mjs # reports CSS selectors no longer referenced (heuristic) trajectory-to-fixture.mjs # derives sanitised replay fixtures from a trajectory (bare Node, no build step) server/ index.ts # static-file and API proxy server for Docker (builds to dist-server/) openAiProxy.ts # local OpenAI-compatible / Responses proxy handler test/ fixtures/ actions/ # action-parsing fixtures commands/ # device command argv fixtures coordinates/ # coordinate conversion fixtures runs/ # run-level fixtures (device loop: timeout retry, abort keeps executed steps) fixtureReplay/ # replays those fixtures with no device and no network helpers/ # test doubles such as a fake DeviceBackend repo-hardening.test.ts # repository-level security, build, and fixture guards ``` > Unit tests live next to the modules they cover (`*.test.ts` / `*.test.tsx`). ## Verification ```bash npm test npm run lint npm run build npm run build:server npm run css:audit # reports CSS selectors no longer referenced (heuristic; confirm by hand) npm run build:budget # check the budgets of an existing dist (build runs it too) ``` > `npm run build` finishes with `scripts/bundle-budget.mjs`: 400 KiB for the entry chunk, 500 KiB for any single chunk, 1100 KiB for everything emitted. Exceeding one fails the build. Override a budget for a one-off look with e.g. `BUNDLE_BUDGET_ENTRY_KB=500`. > > React and `@yume-chan/adb` are split into their own chunks (see `vite.config.ts`), which currently leaves the entry chunk at about 348 KiB and everything emitted at about 941 KiB (budget 1100 KiB). The Markdown stack is deliberately not chunked by hand: doing so makes Vite preload it from the entry and undoes the lazy import. Derive replay fixtures from an exported trajectory: ```bash npm run trajectory:fixture -- ``` The default destination is git-ignored staging, so a fixture only reaches `test/fixtures/` once a human has confirmed it (`--out ` writes to a directory you name instead). Existing fixtures are never overwritten by default: the generator prints the `expected` diff and leaves the file alone, and only `--force` replaces it. It refuses the whole run on inline image data, a missing field, an unsafe file name, or a projection that is not reproducible. The current tests mainly cover: - Action parsing and action safety validation. - OpenAI-compatible and Responses API request payload construction, response parsing, and network client errors. - Docker local proxy forwarding constraints for `/chat/completions` and `/responses`. - Single-step and continuous agent execution. - Failure feedback and automatic recovery for the whitelisted failures (`action_stale` plus the transient device errors `device_io` / `device_timeout`: three attempts before `awaiting_review`; every other failure class stops after one attempt), plus transient model API and empty-model-response retries. - Failure classification, trajectory projection and sanitisation, and offline replay of action, coordinate, and command fixtures plus the device loop (three `device_timeout` attempts before `awaiting_review`; an abort keeps the steps already executed). - Settings persistence and compatibility migration. - Agent thread/turn persistence. - Installed-app parsing, matching, and full context injection. - Screenshot coordinate mapping. - The run-log, screenshot preview, and main layout components. - Global hotkeys, split-pane dragging, dialog focus traps, and body scroll locking. - Action-effect diffing, the `no_effect` / `place_changed` distinction, and the refusal to judge from a poor tree. - Stable element refs across re-dumps (carry, retire, relocate, stale causes), `tap_ref` resolution, and continuing as `action_stale` after an expired ref. - All six screen-diagnosis states (including capture-blocked and "one black frame is only loading") and limit notices counting only when new. - Tree-quality grading, the untrusted wrapper, and closing-tag escaping. - Memory BM25 retrieval and the sensitive-content filter (passwords, codes, ID numbers, card numbers, API keys). - Skill drafting thresholds and matching, plus the untrusted wrapper around skill text. - Grounding's treatment of quotes, unit-bearing numbers, dates, and ordinals. - Safety-policy risk levels, the verdict ladder, the strictness setting, and the dedicated card for a blocked action. Real-device control still needs manual verification with an Android device. Work through [`docs/device-verification-matrix.md`](docs/device-verification-matrix.md): pause timing, resume without a new user message, resuming after a reload, streaming tokens per provider, and the safety strictness all live there. ## Roadmap - [x] Connect to Android devices over WebADB in the browser. - [x] Screenshot capture sent to OpenAI-compatible vision models. - [x] Canonical JSON action protocol. - [x] Editable App Cards, local Custom Tools, and secure Secret input. - [x] Automatic execution, single-step execution, and sensitive-action confirmation. - [x] Run log and screenshot viewing. - [x] Installed-app list, text-clearing input, configurable waits, and basic failure recovery. - [x] Official OpenAI Responses API, native Gemini API, and Qwen presets. - [x] First-run Setup onboarding (connect device → configure model → enter the workspace). - [x] Real-device verification matrix (`docs/device-verification-matrix.md`); still has to be walked through on hardware, with the results filled in. - [x] More systematic failure classification, with per-class action retry (delivered in this milestone). - [x] Task pause and resume. - [x] More systematic safety policy and risk grading (risk levels + verdict ladder + configurable strictness, see `src/lib/actionRisk.ts`). - [x] Screen observation and self-checks: action effects, stable element refs (`tap_ref`), screen diagnosis, tree-quality grading, adaptive settling, limit-notice detection. - [x] Memory retrieval with sensitive-content filtering, skill drafting and reuse, and answer grounding. ## Contributing Issues and pull requests are welcome around: - Compatibility reports for new devices, browsers, or models. - Action parsing, coordinate mapping, and ADB execution stability. - Documentation, example tasks, troubleshooting, and safety notes. - UI usability, log readability, and the local experimentation experience. Before submitting a change, please run: ```bash npm test npm run lint npm run build ``` ## Deploying to Cloudflare Pages The project is already set up on Cloudflare Pages: - Live site: https://webdroid-agent.pages.dev/ - Old URL: https://webadb-autoglm.pages.dev/ (pre-rename project, still reachable but deprecated) - Deployment method: automatic deployment from GitHub Redeploy: ```bash git push origin main ``` You can also verify the build locally first: ```bash npm run build ``` Cloudflare Pages should keep using plain `npm run build` without `VITE_OPENAI_PROXY_URL`. That keeps the hosted static app on browser-direct model API requests and avoids depending on the Docker-only local Node proxy. ## License This project is open source under the [MIT License](./LICENSE). You may use, copy, modify, distribute, and build on the code, provided that the original copyright notice and license text are retained. Third-party dependencies remain subject to their own licenses. Please review dependency license terms before redistribution or commercial use. ## Related Projects and Community - [Tango / WebADB](https://github.com/yume-chan/ya-webadb): the browser-side ADB/WebUSB foundation. - Linux.do: an active Chinese tech community centered on AI, software development, resource sharing, and current industry discussion.