Skip to content

feat(preview): follow the agent's desktop window and cursor - #1284

Merged
nixuuu merged 1 commit into
devfrom
feat/background-app-interaction
Nov 25, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/background-app-interaction

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Change

Desktop Mini follows the window where the agent is working, even when the user has another application in front. A Desktop tool that returns a screenshot supplies the image for Mini directly. PNG and JPEG images up to 2 MiB keep their original bytes, and larger supported images are resized from the same response. For accessibility actions, Mini shows the live window and the result of the action. Moving on to shell work or ending the turn dismisses the old view. Overlapping GUI calls keep their own lifetimes.

The worker verifies the window ID, PID and process instance before publishing live pixels. On supported Macs it captures a covered window with ScreenCaptureKit. Capture is paced by client frame acknowledgements, up to 12 fps. The read-only Mini and manually selected interactive Preview keep separate subscriptions. Additive protocol fields carry verified frames, model screenshots and ephemeral call completions.

A thread can enable an animated blue cursor for its verified Desktop actions. On macOS the marker is clipped to the visible part of its target window. Web, desktop and mobile Preview draw it over the corresponding image and respect reduced motion. Background input still uses the accessibility actions exposed by the target application. The existing physical-input setting governs operations that move the shared pointer.

Verification

  • Measured two animated, covered AppKit windows through Agent Desktop 1.3.1. Local worker output improved from 0.77 to 9.5–10.3 distinct frames/s. All four tool screenshots matched the Preview bytes exactly, and the test windows received zero activations.
  • Exercised the real gateway, WorkerLink, BFF SSE and Chromium canvas on a local connection. A controlled 10 fps source delivered 45/45 distinct frames at 9.96 fps, with a 34.6 ms p95 from WorkerLink send to paint acknowledgement.
  • Verified the production web thread view with post-click state changes, concurrent shell and GUI calls, stale-target rejection, narrow layouts and manual sidebar handoff. Checked the animated cursor in Chromium. On an iPhone 17e simulator after rebasing onto the new mobile gestures, the cursor hotspot stayed within 1.2 pt of a known landmark through zoom, pan, rotation and viewport resize. A tap mapped to (0.4001, 0.5002) for a target at (0.4, 0.5).
  • Ran focused worker MCP, capture, lifecycle and cursor tests, gateway integration tests with isolated PostgreSQL, affected package typechecks, scoped lint and formatting. After integrating the latest dev branch, regenerated the protocol bindings and reran the worker typecheck and connection-loss tests. GitHub CI covers the full gate.
  • Native desktop capture was exercised on Apple Silicon. Intel macOS received a syntax check. Windows, Linux and Android runtime verification remain open.
  • The branch-alias test failed in the first CI attempt. All eight tests in its unchanged suite passed locally on this commit with PostgreSQL. In a controlled run, holding the worker acknowledgement reproduced the same busy checkout after the fixture marked the turn failed. The switch succeeded once the command settled. First CI attempt

Copy audit

Passed the ten checks in docs/copy.md §8. The generic “Waiting for image…” becomes “Waiting for the agent’s view…” while Desktop resolves its source. “Last view” labels a completed screenshot. Narrow layouts truncate the window title while keeping the preview controls accessible.

@nixuuu
nixuuu enabled auto-merge (squash) November 25, 2026 21:08
@nixuuu
nixuuu merged commit c7aa7a1 into dev Nov 25, 2026
39 of 41 checks passed
@nixuuu
nixuuu deleted the feat/background-app-interaction branch November 25, 2026 21:27
nixuuu added a commit that referenced this pull request Nov 29, 2026
## Problem

During Desktop automation macOS kept showing "Canopy is requesting to
bypass the system private window picker…" although the user had allowed
it many times. The `replayd` approval for `app.canopy.desktop` stayed in
place (`kScreenCaptureApprovalLastAlerted` unchanged for weeks), so the
answers were never stored.

The `replayd` log shows why. macOS checks consent after each frame by
resolving the capturing process. Every alert came right after the window
preview's capture helper disconnected:

```
client disconnected, successfully stopped active session
approveOnStreamStart…
[ERROR] requireAlertWithCanonicalBundleID… Error resolving binary path and audit token
userAcknowledgementAlertWithBundleID → showAlert
```

The preview killed the helper with `SIGKILL` right after a frame when
the target changed or the preview stopped (`desktop-follow-preview.ts`).
`replayd` could no longer resolve the process, so it showed the alert
and had nothing to store the answer for.

## Fix

- Stopping the capture ends the helper's stdin instead of killing it.
The helper finishes the outstanding frame and exits one second after its
last one. `SIGKILL` stays as a fallback after 4 s (the helper bounds one
capture at 2.5 s).
- `next()` returns as soon as the capture stops and no longer waits for
an outstanding frame. The failure path in the follow preview no longer
waits for the helper to exit before falling back to Agent Desktop
screenshots; the preview's `close()` still awaits it.
- `docs/automation-tools.md` describes the behaviour.

Fixes: #1284

## Verification

- Locally: worker typecheck, oxlint and oxfmt on the changed files, `bun
run check:tmp ./apps/worker/src/agent-preview/desktop-follow.test.ts` (6
pass).
- A Bun simulation of the parent/helper protocol confirmed the
outstanding frame is still delivered after stdin ends and the helper
exits about 1 s after it.
- **Not verified on macOS**: this worker runs Linux. To confirm on a
nightly build, keep `log stream --info --predicate 'process ==
"replayd"'` running while the agent switches windows. `Error resolving
binary path and audit token` and the alert should no longer appear.
- No new test: the path needs ScreenCaptureKit and `replayd`, and the
existing follow tests cover the preview wiring on Linux.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant