Repository navigation
feat(android): P0 hardening, screen OCR, app browser and task routing - #230
Open
michaelatamuk wants to merge 59 commits into
Open
michaelatamuk wants to merge 59 commits into
michaelatamuk wants to merge 59 commits into
Conversation
When the accessibility tree carries less than a line of text, run bundled ML Kit OCR on-device and append the result to the observation with the same email/card/phone/OTP redaction as the tree. Normal screens pay nothing; a canvas or game becomes readable. The observation hash is recomputed after the merge.
Record what is done, what is partial and what has not started across deep links, OCR, typed actions and the eleven cross-app features. Each item has detailed checkboxes, a definition of done and a place in the recommended order; consent and audit rules are explicit.
Move the 80-character threshold, the OCR cap and the merge into SparseOcrPolicy so the JVM can prove them. The policy tests cover a blind tree, a normal tree, blank OCR, marking and the 6000-character cap; the cross-app checkboxes now mark the unit tests and the green build.
Inbound intents no longer start a turn or rewrite bridge/backend settings; automation extras are debug ACTION_MAIN only. Payments are classified before package trust, app.function is no longer trusted, and payment-like links (bit, paybox, market, sms, mailto, tel, uber, lyft) require approval. The typed-action helper sends base64 parameters through an argument list, validates the function id and reports the exit code instead of a blanket ok. OCR is opt-in and no longer changes the observation hash; the status page records the remaining state/screen gap.
Eleven cards, one per feature, with the general feature, the phone screens in order and a structured Under the hood block: app links, typed actions, capability registry, notification actions, scoped grants, BrowserPort, encrypted snapshots and usage memory. PNG exports are included; the scrollable index.html is the source.
startActivity now turns ActivityNotFoundException into UnsupportedOperationException, so the executor records UNSUPPORTED and the person sees that no app handles the link instead of a generic device failure.
A goal that names the task instead of the app (get a taxi, find a hotel, send a message) can now reach a catalogue entry whose purpose or actions match the task class. It is a heuristic with tests, not a model guess; a tie still asks.
All cards now use the same 900px layout with filled phone screens; captions that describe HOPA's own behaviour sit outside the app screen. Card 2 shows only what Uber displays and states that HOPA opened the screen and stopped. Cards 12-14 cover deep links, screen reading and typed actions, so the set matches the fourteen plan items.
A plain relay through HOPA adds a step and no value, so the share card now shows HOPA classifying the selection and offering a real action (Maps, chat, save). The plan records plain relay as a non-goal and adds the classify-and-act item to the share checklist.
AndroidBrowser implements BrowserPort with one WebView kept off screen, main-thread calls, a mutex, a load timeout and fail-closed certificate handling. BrowserUrl allows only https and refuses logins, control characters and other schemes. AppContainer passes the port to every executor and RunCoordinator marks webAvailable, so web.navigate/read/click/type no longer throw.
Card 4 is a sequence inside the Bank only: ask, version check, approval, receipt; the mail-to-bank scenario is orchestration, not a macro. Card 3 drops the fake Clipboard target, shows Messages, and explains HOPA's role as classify-and-act. The plan marks the Android BrowserPort as wired.
Card 4 is now a five-screen warranty-repair scenario: receipt, warranty check with three explained steps, service slots, booking approval, and a per-step result. Feature 4 is renamed from per-app macros to scenarios and macros, with a scenario record and per-step results added to the checklist.
The receipt alone is not a reason to act. Card 4 now opens with the person's problem (machine broken, error E4) and the receipt attached as evidence; HOPA checks the warranty term, explains the three steps, and only then offers a service slot.
Card 4 is now a real move: a lease in Files, a checklist of five providers, and forms or bookings in the Power Co, Fiber and bank apps, with a result per app. Card 9 compares Booking, Hotels and Airbnb screens instead of websites; card 15 books in the service app. The README and the plan state the rule: web is only a fallback when no app handles the task.
The card now runs in causal order: allow Delivery only, the notification arrives while the person is driving, the person asks HOPA to confirm, HOPA presses the notification's own button, and the app reports the result. Proof is the app cancelling or updating the notification.
Card 6 is now HOPA Today: one on-device list of today's notifications from chosen apps (Delivery, Bank, Calendar, Messages), with each row carrying the app's own action. Tapping Confirm fires the notification's PendingIntent; the app updates its own notification and the digest shows the result. The plan replaces content retention with a today-only digest that is cleared on demand and never sent to a model unless asked.
The first screen now says what the person may have missed: 3 need you, 1 changed, 8 updates. The next screen lists the three with the app's own actions; acting on the delivery removes it and leaves 2. The digest is grouped by need, not by time.
Card 8 now shows the missing middle: the person asks to book, HOPA asks for the two scopes, the booking runs with the grant, the app returns id 88213, and the grant is revoked. Card 9 states that Booking, Hotels and Airbnb screens are read through accessibility and Open in Booking opens the app on that hotel, with no API and no purchase inside HOPA.
Card 9 now shows Booking, Hotels and Airbnb with a 'HOPA is reading this screen' bar, then the table and the Booking screen the row opens. Card 8 no longer shows a revoked state after the booking: the last screen keeps the grant active and offers Revoke access, with a note that the grant stays until the person removes it.
Card 8 replaces the invented restaurant grant with Google OAuth calendar.events: the person asks for a dinner event, the Google consent shows only that scope, HOPA creates the event, Calendar returns it, and access can be revoked in HOPA or myaccount.google.com. The hood notes that ActionExecutor is HOPA's own action layer, not Android. Card 9 now starts and ends in HOPA: ask, read Booking, Hotels and Airbnb screens, compare, open the source app.
The memory screen now shows what is stored (4 of 5, last used today), that this request saved Taxi to Uber, and a clear action. The hood explains when a choice is recorded, how the count and recency rank, what happens to an uninstalled app, how clearing works, and that only explicit choices are used.
Card 0 shows the ladder of deciders, the action JSON, the checks, ActionExecutor and the ports, and the stop conditions, on a readable panel. Card 13 now starts with the HOPA bubble, shows the Ask-about-this-screen input, and marks the bank screen as a separate later run with a divider, so the refusal is not a sudden jump.
Card 0.1 follows one action through validate, approve, route, one port call, record and the four exits, with an example trace from ui.tap to the recorded step. Card 13 drops the extra Ask screen: the bubble, the answer in HOPA, then a separate later bank run that is refused, with a divider between the runs.
Card 0.1 now shows one action entering ActionExecutor and branching by kind: screen via DevicePort, web via BrowserPort, intents via SystemPort, app.function via a typed action, and ui.wait via the clock. The shared checks, the four returns and an example trace sit on the same panel as card 0. Card 13 shows the question typed over the app before any answer.
The ticket question is no longer 'what time is my train': the person asks to add the trip to Calendar 20 minutes before. HOPA reads the image-only ticket, turns the text into event parameters and creates the event, so the person retypes nothing. The protected bank screen remains a separate later run.
Card 13.1 is a payslip: the person asks what the deductions mean, HOPA reads the lines and explains each one in plain words, and changes nothing. The card states the limits (no tax advice, unknown lines marked), the privacy (on-device, not stored) and that every amount quoted is visible on the screen.
The middle screen of the payslip card now includes a small screenshot of the document it read: status bar, app title and the line labels, with every amount replaced by a grey mask and the caption 'Screenshot - amounts masked'. The privacy row says the preview masks amounts and logs are redacted.
The payslip preview now uses dark redaction bars for every amount, a red HIDDEN badge on the screenshot, and the caption 'Screenshot - sensitive values hidden'. A light grey placeholder no longer reads as an empty field.
The payslip preview drops the red HIDDEN badge: dark redaction bars and the caption 'amounts hidden' carry it without pulling focus from the explanation. Card 13 now shows a mini screenshot of the ticket inside HOPA's answer, captioned 'Screenshot - read by HOPA'.
Section 0.2 lists every way HOPA can operate another app: accessibility UI, Android intents with each system action, app-declared functions, notification actions, OAuth APIs and the web fallback. It states what each needs and its real status, and that deep links are system.openLink, not a separate channel.
Card 0 now shows only the six families, with AppFunctions instead of AppFunctions/MCP because MCP is a service, not an installed app. Card 0.1 lists all sixteen Android intent actions, including calendar, files, camera, pickers, timer, media, contact and settings, and is tall enough to show every row. The plan keeps the full table and notes that MCP is a service channel.
Card 0 lists the five target-app ways plus the service-level OAuth channel, in 740 px. Card 0.1 lists all sixteen Android intents in 1100 px so no row is cut, marks the four that return data, and says the rest only report started. The plan table keeps all 22 rows, uses target app throughout, and notes the intent results and the MCP service boundary.
AppLinks maps known hosts and schemes (wa.me, t.me, waze, uber, lyft, market) to their packages; AndroidSystemPort opens that package explicitly when it is installed and falls back to the implicit handler otherwise. The manifest declares queries for those packages and VIEW https, and the catalog tests cover the mapping and the chooser fallback.
hopa://callback?requestId=...&status=... is parsed by LinkCallback, stored in LinkCallbackStore for the process, and shown as a notice; it never starts a turn. The manifest accepts the callback host, and the catalog tests cover the valid and refused forms.
The 0.2 table keeps all 22 rows, but ACTION_INSERT, the document and camera intents, pickers, multi-share, timer, media, contact edit and settings are not implemented yet; only the original six system actions are shipped.
system.openLink now returns 'opened, not confirmed' after handing the URI to Android, so the model cannot read a deep link as a completed task. A callback result is shown separately; the executor test uses a fake SystemPort and checks the text and the opened URL.
LinkOpenTest calls AndroidSystemPort.openLink inside the app on the device: Maps, WhatsApp with prefilled text and Chrome pass, while the supplied Telegram name does not resolve (the same with am start without HOPA). The androidTest manifest declares the same queries as HOPA, and the callback notice is now neutral and names the request and the returned text.
Maps, WhatsApp with prefilled text, Telegram (AnnushkaSsadovoy), Chrome and the callback pass through AndroidSystemPort.openLink on the SM-S926B; the refused schemes are covered by unit tests. The checklist and the one-line index mark deep links as done.
system.setTimer takes text like '20m Tea' or '90s', parses it in TimerText, and calls the clock app through ACTION_SET_TIMER. The kind is in the action schema, asks for approval because it is a change, and the Windows port refuses honestly. Tests cover the parser and the executor call.
AppLinkCatalogue builds the Maps, WhatsApp, Telegram, Uber and OpenTable links with encoded parameters, and tests assert the exact URLs and the allowlist. RunNarrator now says 'Open ... (finish in the app)' for system.openLink, so a link is not read as a completed task.
…imits When the system refuses a screenshot on a sparse screen, the observation says 'screen capture blocked' and no black frame is sent. The OCR switch now states that only Latin script is recognised; Hebrew and Cyrillic are not claimed. VLM and pixel redaction move to their own 8.2.1 checklist.
ktlint rejects the joined ui.type and system.setTimer examples at 120 columns; the strings are split without changing the prompt.
A vision frame now goes through ML Kit: every block whose text the observation redactor would change is blacked out, and a failed recognition sends no image. DevicePort.screenshotForVision defaults to null, so a port that cannot redact never falls back to raw pixels; the hidden screen port redacts too. A nearly uniform black frame (some FLAG_SECURE windows) is refused, and the observation says 'blocked or unavailable' instead of showing an empty screen. The last frame is reused inside the system's one-per-second window. On the SM-S926B: PixelRedactionTest 4/4; a canvas turn reads TL 2048 / 14:32 / Platform 3; a payment page reaches the model as blacked-out bars; the secure debug window gives vision=null blocked=true.
Capabilities > Apps now lists every launcher entry with version and system flag, and each card shows the app's typed actions, the sixteen hand-off intents it answers, the links HOPA knows, and what opening it means. Hand-offs are one PackageManager query per action; links come from the link catalogue; typed actions come from the platform AppFunctions catalogue, then the hidden-screen helper. When neither is available the screen says so and invents nothing. MCP and OAuth are service-level and stay out of a per-app card. On the SM-S926B: 376 apps; WhatsApp shows SEND/SENDTO/SEND_MULTIPLE and three wa.me links; Calendar shows INSERT; a debug probe shows the system catalogue returns 0 without the assistant role.
The Apps screen now names the two channels plainly: App functions (AppFunctions, human labels plus the raw name) and Android actions (the ACTION_* probes, with share types inside the same card). Full intent filters are not readable on Android 17, so hosts and MIME types are real probes; the runtime probe that proved it is included. Exported screens, extras, component counts and build facts move into the collapsed Technical details; permissions show allowed/not allowed. The helper now survives the 900 KB catalogue: replies are compacted to one line, children get a clean CLASSPATH, output is read before waiting, and function ids with '#' are accepted. Device: 377 apps, 11 with app functions; Samsung Clock shows 18; WhatsApp shows SEND/SENDTO/SEND_MULTIPLE; installed over wireless debugging.
TaskClass maps a goal to a small task family, and a turn that used an app records task -> package with a count. The per-task app memory lives in its own preferences file; a different app replaces the choice, and the Apps screen shows the remembered choices with a per-row forget and Clear all. The turn prompt lists the choices and tells the model to prefer them when they fit. Only the app field of a run record is used; clipboard and notifications are never read for this. Tests: TaskClass 5, UsageMemory 3; green :app:assembleDebug with stores/catalog/capabilities tests and ktlint.
The repository keeps one public behaviour declaration per file, with contracts allowed to share a file. App functions, intents, surfaces, declared functions and the usage memory are split accordingly; humanAction becomes private. The usage prompt is a default method on the store, so it does not need a top-level function file. No behaviour changes.
The first taxi turn navigated to https://uber.com in the browser; a URL-to-package fallback would have stored com.ubercab as if the app had been used. Only a ui.launch with a package is recorded now. A second turn that explicitly opened the Uber app recorded taxi -> com.ubercab, and the usage file was created.
The Capabilities page gained the Apps tile in the capability registry work; the golden is re-recorded with Roborazzi so verifyRoborazziDebug compares against the current screen.
The turn prompt now lists AppFunctions from every package the helper can see, not only the foreground app, so a typed call does not need the app on screen. app.function validates app/ref and requires a JSON object, and the on-screen adapter states that functions need the hidden screen. TurnResult/TurnOutcome carry AppFunctionResult, and the receipt shows app id, function, status and the returned payload; a failure shows failed, not ok. Tests cover the parameter check. Device: the helper runs Clock/Calendar functions, but the instant-command/anchors layer answered 'use the Clock app function' with 'Opened Alarms.' at 0 tokens, so the model never reached app.function. The routing fix and the success/denial device turn remain open in 8.3.
An explicit app-function request now disables instant commands and graphs, so the model reaches app.function instead of an anchors step that only opens the app. A returned payload object without a decision key is read as text, not a schema error, and the prompt tells the model to answer in plain language rather than echo the JSON. Clock getAlarms executed on the S24 before the surface binding was lost; the final answer/result-card and refusal turns remain open in 8.3.
Routing now prefers a named app, then an installed app for the task, then a website, then the store page, and never silently picks between two launched apps that fit. A remembered per-task app breaks the tie and carries one factual reason line into the prompt. Preferences travel from UsageMemoryStore through TurnRequest/TurnContext to AppRouter. Also fixes ktlint spacing in AgentLoop.
The prompt keeps only a few functions per app. A function the goal names, or whose words it shares, is now first, so a truncated Clock list cannot hide getAlarms or startStopwatch. Ties keep the platform order.
A link, address, phone or date in the composer now offers at most two chips: Open link, Navigate, Call, Add event. A tap sends one normal turn, so approval and screen rules still apply; plain text stays in the Android share sheet and the clipboard is never read in the background.
A message with a file now offers Share file: the stored bytes go through the app FileProvider with a read grant and the file's MIME type, plus the message text. If the file is gone, the app says so instead of opening an empty chooser. The clipboard section records that copy is a menu tap and nothing reads the clip.
…imes The first settings emission was treated as the launch baseline and ignored. If a sign-in stored the identity before the collector started, onForeground had already failed with no credentials, so no socket opened. The first nonblank identity now connects when the app is in front; connect is idempotent behind the gate and the link check. The existing foreground test exposed this on loaded CI runners.
A known link whose app is not installed now fails with the package and its Play page, so the model can offer an install instead of retrying the link. The store card already opens only on an explicit tap; this closes the missing-app detection before a link fails.
system.share now uses its optional app field: with a package it sends ACTION_SEND to that app and checks resolveActivity; without one it keeps the system chooser. The run record carries the package, text and timestamp, and system.share already asks first as a sensitive kind.
The harness restored the global stdout/stderr as soon as the scope was cancelled. A late admission log line could land in the next test's capture, which made the no-link-on-stderr assertion intermittent. close now joins the cancelled scope with a short bound before restoring the streams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Android client: close the P0 gate, add opt-in screen OCR, give the agent a real browser, and route a task word to a known app.