Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
docs(desktop): design bounded foreground route (#2492)
Max2583ed3909ce
diff --git a/docs/plans/desktop-computer-use-route-b-design.md b/docs/plans/desktop-computer-use-route-b-design.mdnew file mode 100644index 000000000..e13a483ea--- /dev/null+++ b/docs/plans/desktop-computer-use-route-b-design.md@@ -0,0 +1,235 @@+# Route B: Bounded Foreground Delivery++Status: owner-facing decision record. This document defines a design boundary+only. It does not authorize implementation. Owner and source review are+required before any product change or merge.++[Route A](desktop-computer-use.md#route-a-raw-single-click-selector-2026-10-10)+remains the shipped background contract. Route B is a separate, explicit+foreground request for applications that do not produce an observable result+through the available background routes. It must never become a silent fallback+from Route A.++## Evidence++The background-input research found that the pinned driver can deliver an+exact-window `synthetic_events` click to a test-owned AppKit surface without+changing the frontmost application or hardware pointer. It also found that an+Accessibility success response is not proof that a custom surface handled a+real mouse event. The research records the limitation that some applications+require real HID origin or hardware pointer state:++[`desktop-computer-use-background-input/findings.md`](../research/desktop-computer-use-background-input/findings.md)++The research note is committed in this PR as the durable record of the+test-owned probe. Slice 2 provides the application evidence.++### Slice 2 QQ observation++The owner-approved QQ Route A observation used one background raw click with+`x=41`, `y=146`, `count=1`, `button=left`, `modifier=[]`,+`click_mode:"raw"`, and `delivery_mode:"background"`. The driver accepted the+dispatch and reported the `synthetic_events` route. Fresh before/after+observations showed no observable QQ view change.++The raw QQ responses, observations, and screenshots remain in the local Slice 2+evidence directory and are intentionally not committed because they contain+private third-party application content.++The evidence shows a gap between accepted driver dispatch and observable+application effect. It does not change Route A semantics or justify automatic+replay.++## Decision++### Granularity: per call++Foreground is allowed only for one explicit foreground input call. The call+must identify one exact application window observed in the same Avibe Agent+Session and must use the explicit `delivery_mode:"foreground"` value. The+foreground interval ends immediately after that call, followed by restoration+of the prior desktop state.++Consent does not make later calls foreground calls. There is no per-app+allowlist and no session-wide foreground mode. Per-app permission is too broad+for applications with multiple windows and can outlive the task that justified+it. A session-wide mode makes an accidental or stale request affect every later+input. Per-call admission keeps the target and the side effect bounded.++The first implementation decision should remain narrower than general HID+support: it should separately specify the exact click shape, target types,+platforms, and result contract it can verify. Typing, hotkeys, scrolling,+dragging, desktop targets, ambiguous windows, and unsupported operations remain+refused until they have their own contract.++### Consent: native session toggle++The recommended consent model is a per-Avibe-Agent-Session toggle owned by the+native desktop tray/menu:++`Allow foreground control for this conversation`++The owner turns it on from the native shell UI. It expires when the Session+ends or is archived, when native Computer Use stops, or when the owner switches+it off. It is ephemeral session consent, not a durable allowlist.++Consent can never be granted by the CLI, an IM message, or agent arguments.+Those paths may request a foreground call, but they cannot create or extend+the grant. The added rule is exactly that foreground consent is granted only+through the native shell UI.++Every-call confirmation is more interruptive and does not fit work initiated+from an IM or an unattended Session. A per-app allowlist is longer-lived and+broader than the task requires. The per-Session toggle is the selected+compromise: the owner makes one explicit native decision, while each input+still requires a separate foreground request and exact target admission.++Route B inherits the existing documented same-user local trust boundary. This+record does not introduce a second authority model for same-user processes.+Signed shell capabilities, secure-enclave or keychain keys, mutual-authenticated+minting, and a new daemon-level capability protocol are future hardening, not+part of this decision. Any stronger trust guarantee requires a separate owner+decision before implementation.++### Record, restore, and verify++Route B v1 has a finite restoration contract. Before the foreground call, the+implementation records exactly:++1. the prior frontmost application and its frontmost native window, including+ identities that distinguish the current process and native window;+2. the hardware pointer position; and+3. the active Space of the affected display.++The target must be one freshly observed application window in the same Session+and must satisfy the admission preconditions below. The implementation must+retain the target identity and coordinate context needed to confirm that it is+still the requested window before posting the foreground input. Numeric PID or+window identifiers must not be treated as proof of identity after reuse.++After the explicit input call, the implementation restores those three recorded+values and verifies them against a fresh observation: the prior frontmost+application and exact window, the hardware pointer position, and the affected+display's active Space. The previously frontmost window must still be present+on the current Space in that observation. A transport acknowledgement is not+effect confirmation; the result must preserve the existing click effect+vocabulary, including `confirmed` and `unverifiable`.++If restoration cannot be completed or cannot be verified, the operation stops+and reports a concrete restoration failure. It does not retry, choose another+window, silently fall back to Route A, or claim that the input was undone.+The implementation must preserve enough delivery and restoration detail for the+caller to distinguish an unattempted call, an attempted call with an+unverifiable effect, and a call whose effect occurred but whose restoration+failed.++Native Computer Use stop expires consent and cancels the current foreground+call. Restoration and reporting remain the terminal obligation before normal+daemon teardown; if the call cannot restore and verify, it stops and reports.+Stop cannot claim to undo an input that was already posted.++Any other window-system state is not restored in v1 and may differ after the+call. This includes the target's `z_index` and z-order relative to+non-frontmost windows, focus or selection inside windows, IME state, and+fullscreen or tiling arrangements. Because of the admission preconditions, the+target was already visible beforehand.++Owner-input quarantine, suppression, capture, and replay during the+focus-changing interval are explicitly out of scope for this record. The+implementation must not claim those stronger guarantees without a later owner+decision. The same applies to durable recovery markers across shell or daemon+restarts.++### User-visible indication++The owner must be able to see when foreground mode is active. The native shell+must show a visible indicator before the foreground call begins and keep it+visible until restoration has been verified. The indicator should identify the+active foreground operation and expose the existing native Computer Use stop+control. A successful restoration clears the active state; a failed or+unverifiable restoration remains visible as an attention state until the+owner resolves it.++The Workbench may mirror this state, but it cannot be the only indication+because the request may originate from an IM or another hidden surface.++## Admission and API shape++Today the Computer Use server refuses `delivery_mode:"foreground"`. That+remains the behavior until a separately approved implementation lands. A+future Route B admission branch must require the explicit foreground value,+the active native session toggle, a fresh exact target, the existing+observe-first and lease checks, and a supported operation/platform. Omitted+delivery mode remains background. An accepted background dispatch with an+unverifiable result never escalates by itself; a later foreground call must be+an explicit caller decision with its own admission.++Route B v1 admits a target only when a fresh `list_windows` call in the same+call's admission finds the exact pid and window with all of these conditions:+`is_on_screen=true`, `minimized=false`, and `on_current_space=true`. For v1,+the on-screen condition is also the no-hidden condition: Route B does not+un-hide, reveal, or un-minimize a target. Any false, null, missing, or+otherwise non-admissible value fails closed with a stable reason:+`target_off_active_space` for a missing or off-current-Space target, and+`target_not_admissible` for visibility, hidden, or minimized targets. Route B+never switches Spaces; cross-Space targets are future work.++The CLI should reuse the existing leaf command and argument shape rather than+add a new top-level foreground command or hidden retry flag. The planned+request shape is conceptually:++```text+vibe computer click --arg pid=97470 --arg window_id=6285 \+ --arg x=41 --arg y=146 --arg capture_id=capture_... \+ --arg action=click --arg button=left --arg count=1 \+ --arg modifier=[] --arg delivery_mode=foreground+```++This example documents the future contract; it does not add a product flag in+this design-only lane. The built-in `computer-use` Skill should teach callers+to use background delivery first, observe the exact target in the same Session,+carry the observation context, and verify both the application effect and+restoration. It must tell agents that they cannot grant consent, that+foreground is never an implicit fallback, and that an unverifiable background+result must not be blindly replayed.++## Windows and Q6++Route B has no Windows parity decision yet. Q6 still determines whether the+embedded daemon, proxy reachability, UIA worker, interactive-session boundary,+integrity-level behavior, and foreground-only targets can support the same+contract. Windows therefore remains refused for foreground delivery until the+Q6 machine run establishes exact process/window targeting, pointer restoration,+visible indication, effect verification, and restoration verification through+native Windows APIs.++Q6 changes Route B admission and safety evidence, not just packaging. A future+Windows implementation needs its own owner-reviewed platform contract; it+cannot infer parity from the macOS design.++## Out of scope and next decision++This record does not include:++- Route B implementation, product flags, persistent state files, schema+ changes, GUI/TCC changes, credentials, Runtime changes, or packaging work;+- a silent fallback or automatic replay from Route A;+- per-app allowlists, global permission, session-wide foreground mode, or+ agent-granted consent;+- signed shell capabilities, secure-enclave/keychain identity,+ mutual-authenticated minting, or a new process-authentication trust model;+- owner-input quarantine, suppression, capture, or replay, including restart+ persistence and recovery markers;+- cross-Space targets or Space switching;+- general foreground typing, hotkeys, scrolling, dragging, desktop-wide HID,+ login-screen or lock-screen control;+- QQ/WeChat acceptance, application-specific adapters, OCR, perception, or+ model changes; or+- Windows foreground delivery before the Q6 machine run.++Before implementation, owner and source must review and approve the first+supported click shape, native toggle lifecycle, exact restoration and failure+result, visible indicator behavior, admission/refusal rules, CLI/Skill wording,+and platform gates. That later implementation decision must also state whether+any future hardening listed above is required. This PR remains docs-only and+must not be merged without source review.diff --git a/docs/research/desktop-computer-use-background-input/findings.md b/docs/research/desktop-computer-use-background-input/findings.mdnew file mode 100644index 000000000..a2dfb3729--- /dev/null+++ b/docs/research/desktop-computer-use-background-input/findings.md@@ -0,0 +1,227 @@+# macOS Background Input Research++Date: 2026-10-10++This note records a read-only source review and one bounded, hermetic probe. It+does not change the installed Avibe application, TCC state, credentials, or+owner Runtime, and it does not automate QQ, WeChat, or any owner application.++## Finding++The pinned cua-driver 0.31.0 can deliver a background synthetic mouse click+that a test-owned AppKit surface accepts through normal `hitTest` and+`mouseDown` dispatch. The working route is the exact window-scoped pixel path+with background delivery, after the driver enters its raw synthetic-event+path.++This result is narrower than "all self-drawn macOS apps work in the+background." It does not establish that QQ or WeChat will accept the event.+The upstream macOS contract explicitly documents that some OpenGL, Metal, Qt,+wxWidgets, game, and pointer-reading surfaces require a real HID origin or+hardware pointer position and can discard PID-routed events.++There is also a current route-selection trap. For an ordinary background+left-click with `count=1`, the driver first performs a pixel hit-test and+attempts `AXPress` when an AX element is exposed at that point. In the probe,+the test view deliberately made AXPress a no-op for the real button behavior:+the AX counter increased, while the real `mouseDown` hit-test counter did not.+Using `count=2` bypassed that single-click AX hit-test branch and reached the+raw synthetic-event path. That is evidence that the transport works, but it is+not a correct general-purpose single-click API.++## macOS routes in 0.31.0++The pinned source tag is `cua-driver-rs-v0.31.0` at+`5272e492d61b96caf08e3bf434d91126c1f3dccc`. The repository records the+corresponding managed tool snapshot in+`desktop/cua-driver/tools-v0.31.0.json`.++The probe below used the exact earlier snapshot from source-worktree commit+`d40a5fda4c5d2be230e2a898528b25cda2cbe220`, whose SHA-256 is recorded below.+The current repository snapshot has SHA-256+`4257e598f5a6ad7e632b48e96c03257d7c5ed618a93b72820b2d4fef0f196acf` and+includes Avibe's later `click_mode:"raw"` patch. The probe therefore records+historical behavior of the earlier snapshot; it is not a conformance result+for the current snapshot or its raw-click selector.++The relevant routes are:++| Route | Mechanism | Background behavior |+| --- | --- | --- |+| Semantic AX actions | `AXUIElementPerformAction`, including `AXPress` | Calls the target's accessibility action without moving the hardware pointer. A successful AX return is not proof that a custom surface handled a real mouse event. |+| Pixel mouse, per PID | Private SkyLight `SLEventPostToPid`, with public `CGEvent::post_to_pid` fallback | Sends a synthetic mouse event to one process. The driver stamps screen/window routing metadata, including `CGEventSetWindowLocation` and the target PID/window fields. |+| Window-pointer pixel route | Window-local coordinates converted from the exact window snapshot, then routed as PID-targeted CGEvents | Provides precise window targeting. In the earlier snapshot used by the probe, a normal single left-click could be intercepted by the AX hit-test optimization before this route ran. The current Avibe snapshot exposes `click_mode:"raw"` for the exact background left-click case. |+| PID keyboard | `SLEventPostToPid` with an `SLSEventAuthenticationMessage` where needed, then public PID fallback | Background key transitions and text synthesis without a global HID post. The auth envelope is for Chromium-like targets; menu shortcuts have a no-auth path. |+| Foreground HID | Global `CGEvent` posts through the HID tap after explicit activation | Not a background route. It is the fallback for surfaces that require real HID origin or hardware pointer state. |+| Focus without raise | SkyLight event-record SPI used by the background pixel activation guard | Uses private records to make the target AppKit-active for routing while suppressing normal raise/Space-follow behavior. This is separate from the raw click transport. |++The source resolves private symbols at runtime with `dlopen`/`dlsym`. The+focus-without-raise implementation uses `_SLPSGetFrontProcess`,+`SLSGetWindowOwner`, `SLSGetConnectionPSN` or `GetProcessForPID`, and+`SLPSPostEventRecordTo`. `SLPSSetFrontProcessWithOptions` is resolved for the+broader SkyLight support surface, but the documented focus-without-raise+recipe deliberately does not call it. The raw event post uses+`SLEventPostToPid`; the public fallback is `CGEvent::post_to_pid`.++The 0.31.0 `serve` invocation used by this research and by the desktop+Runtime is:++```text+serve --embedded --parent-liveness-stdio --no-permissions-gate+ --no-overlay --socket <path> --host-bundle-id <id>+ --permission-mode standard+```++The 0.31.0 CLI also exposes `--grant existing-profile`, capability-manifest+and approval flags, cursor theme/reduced-motion flags, and experimental+history/PIP flags. None of those selects a different macOS background mouse+transport or disables the AX-first single-click optimization. There is no+`serve` flag that forces a raw single-click or enables foreground input.+`delivery_mode` is a per-tool argument; the Avibe admission layer currently+rejects `delivery_mode:"foreground"`.++## Bounded probe++The probe created two test-owned AppKit applications:++- `HitTestOnlyTarget`: a custom `NSView` whose real behavior only increments+ `hitTestClickCount` from `mouseDown` inside the button rectangle.+ `accessibilityPerformPress` increments a separate `axPressCount`.+- `ForegroundGuard`: an unrelated foreground window used to detect an+ unintended raise or focus change.++The probe evidence was retained in a temporary local evidence root.++The latest run used the installed rc4 helper solely as a process binary:++```text+driver version: cua-driver 0.31.0+driver path: installed Avibe app helper (`cua-driver`)+driver sha256: a72b09106ee1c962eef465a407b6e2f172d38944f6702e5f11e6ad85feb390d1+tool snapshot sha256: b03c3e48d1b00c8fe7c0e8b9813eb5ea104ad38313672fc4b68af203a827f43b+```++The `b03c3e48...` snapshot is the exact+`desktop/cua-driver/tools-v0.31.0.json` artifact at source-worktree commit+`d40a5fda...`; it predates the current repository snapshot and its+`click_mode:"raw"` selector. The observations below are consequently bounded+to the installed/pre-patch probe artifact and must not be read as validation+of the current checked-in snapshot.++The original post-merge acceptance helper under+`~/Applications/Avibe CUA Post-Merge Acceptance 20261009.app` was removed by+the later rc4 replacement, so its previous binary hash+`2a05d3e8...` is preserved only in the earlier acceptance evidence. The+source tag remains pinned to 0.31.0, but the probe and current repository+snapshot are distinct artifacts; this note keeps both hashes explicit rather+than treating them as identical.++Observed results from the latest run:++| Action | Result |+| --- | --- |+| AXPress through `element_token` | `axPressCount` 0 to 1, `hitTestClickCount` unchanged. The driver reported route `accessibility`. |+| PID-only pixel click | Refused as `ambiguous_window_target` because the test process exposed five eligible windows, including four off-screen windows. No event was sent. |+| Exact window pixel click, `count=1` | Routed to the driver's AX hit-test optimization. `axPressCount` increased again; the real hit-test count stayed unchanged. |+| Exact window pixel click, `count=2` | Routed as `synthetic_events`; `hitTestClickCount` increased by 2. |+| Same exact window click through `core.ComputerUseServer` | Passed after observing the window with a screenshot on the same session. `hitTestClickCount` increased by 2 more and the response retained route `synthetic_events`. |++The direct raw click and the core-forwarded raw click both returned the same+hardware cursor position before and after dispatch. The exact target never+became the frontmost application. In the latest run the frontmost app at the+raw dispatch point was an already-running user app and remained unchanged in+three follow-up samples. An earlier run kept the test guard frontmost across+the same samples. No test process remained after cleanup; the latest target,+guard, and driver PIDs were `84605`, `84610`, and `84613`.++The core forwarding result matters because it rules out a+`core/computer_server.py` event-posting defect. The server performs the+observe-first and exact-window admission checks, then forwards the pixel+arguments to the driver. The successful core run used a fresh+`get_window_state` screenshot on the same session; the earlier failed core+attempt was correctly refused with `screenshot_context_missing` because that+context had been omitted.++## Does `core/computer_server.py` need a change?++The current Avibe snapshot already exposes `click_mode:"raw"` for the exact+background left-click case, and the core server validates and forwards that+selector. The historical probe predates this selector, so its `count=2`+synthetic-event result does not validate the current raw-click contract.+Reusing `count=2` is not an acceptable product workaround because it changes+the click gesture. The next evidence question is whether the current raw+selector is accepted by target applications that reject background synthetic+events; that is separate from Route B foreground design.++## Options if a target still rejects the raw route++The existing private SkyLight focus-without-raise machinery is already the+closest background mechanism in the driver. A new private route would still+need to use undocumented SkyLight ABI and event-record layouts, preserve the+prior front process/window, make the target AppKit-active without a visible+raise, and restore the prior state. It would carry material risks:++- private symbol names, signatures, and event-record layouts can change across+ macOS releases;+- behavior can differ between AppKit, Catalyst, Electron, Metal/OpenGL, and+ other event loops;+- the target may inspect the real HID source or hardware pointer, which a+ PID-routed event cannot reproduce;+- Accessibility and Screen Recording remain separate TCC boundaries;+- private SPI use increases hardened-runtime, notarization, support, and+ rollback risk even when the binary is locally signed and the symbols are+ resolved dynamically.++The bounded foreground mode is the practical fallback for a surface that+requires true HID input:++1. Require an explicit user-authorized `delivery_mode:"foreground"` request.+2. Admit one exact PID/window observed in the same session; reject desktop-wide+ or ambiguous targets.+3. Record the current frontmost PID/window and the target geometry.+4. Briefly activate only the exact target, post the required HID event at the+ exact screen point, and restore the recorded frontmost app/window.+5. Verify restoration and the target effect from a fresh observation.+6. Refuse implicit escalation, global HID injection, and activation when the+ exact target cannot be restored safely.++That mode should remain a separate, visible product contract. It should not be+silently added as a fallback from a failed background click.++## Upstream check after 0.31.0++I compared the pinned macOS input and click sources at+`cua-driver-rs-v0.32.0`, `v0.33.0` through `v0.33.4`, `v0.34.0`, and+`v0.34.1`. The tags resolve to:++```text+v0.32.0 58aba84b5b83d77e7e2b0f006547699eb594e50d+v0.33.0 1553a3f360ea12155be3bc77e27c427ca62f967a+v0.33.1 a9baa8d107fba8b0aef5a4ed6233e498e88d14d0+v0.33.2 c82d32e3e1adbc6578a148962002ddf6e3e8a15a+v0.33.3 a46cd19cff980c9269425bb8aefa90588d5924d3+v0.33.4 ba0033a661101669c60ce05f1fe5753bf8bad748+v0.34.0 b0968e1b12834e485dda68789541a3cc57664a9f+v0.34.1 0c69d9a2c8abbb5051a2df4a23f0fa166d5385dc+```++The later releases change the surrounding SDK/tool contract, window+enumeration, coordinate and input timing behavior, modifier aliases, menu and+consent handling, cursor behavior, and refusal/verification paths. The+macOS-specific diffs do not add a new background click transport that replaces+the 0.31.0 `SLEventPostToPid`/public PID fallback or the existing+focus-without-raise recipe. The later source still documents the same+limitation for canvases and other surfaces that require real HID origin.++## Scope and follow-up++This is a research result, not an implementation recommendation to enable+foreground input. The current raw single-click selector is already part of the+checked-in Avibe contract. The next implementation question is validation of+that existing selector against target applications that reject synthetic+events; that requires a driver contract and consuming test before any further+change to `core/computer_server.py`.++The probe sources are not included in this PR; this note is the evidence+record. No commit, push, PR, TCC mutation, credential access, installed-Avibe+change, QQ/WeChat action, or owner Runtime restart was performed.