feat(remote): add a host-allocated macos-app lease backend
Merged
JA
2mo ago+2899+2899+0123456789012345678901234567890123456789-110-110-012345678901234567890123456789
Summary
Implements the macos-app lease backend from #3229, which confines a proxy client to one macOS app:
- The host allocates the lease on the daemon's loopback listener with the daemon token:
PUT /admin/leases/<id>with{ tenantId, runId, clientId, leaseBackend: "macos-app", leaseProvider, deviceKey: "<bundleId>@<pid>", ttlMs }; renew by repeating it, revoke withDELETE. Tenantlease_allocateformacos-appis refused. - Requests under the lease (including
batchsteps) are limited to the commands whose registry descriptor declaresappLease: 'allowed', lease-admission-exempt ones included (onlylease_heartbeatandlease_releasedeclare it). Every request exceptopen, thebatchenvelope, heartbeat and release must run in an existing session of the leased app.open/closetake only the leased bundle, only theappsurface is allowed,--fullscreen, host-path or launch inputs (including a batch step'sruntime, checked before any step runs) and device selectors (--udid,--serial,--device,--target) are refused,openandbatchmust carry--platform macos,openrequiresAGENT_DEVICE_MACOS_APP_BACKEND=native, and a pid-pinned lease stops at process exit. Refusals areUNAUTHORIZEDwithreason: MACOS_APP_LEASE_DENIED. - A session under the lease takes no host device claim, so one daemon serves several leased apps.
- Daemon policy
leases.require: "macos-app"(its only value) refuses requests that name no lease./healthreportsleaseBackends, withmacos-apponly on darwin. A tenant heartbeat cannot renew a host-allocated lease past the host'sttlMs. - The native macOS backend's
press/focus/fillact only inside the app's own on-screen windows and never on its menu bar, whose Apple menu acts for the whole Mac. This applies to the native backend generally. - Responses under the lease name nothing about the host:
openomits the session paths and the device, failures omitlogPathanddiagnosticsRecordand redact host paths and the host name, a snapshot's fallback screenshot path is dropped, and the request diagnostics route is not served to a tenant that held the lease. - Client: a remote config naming a
macos-applease uses it as given and never allocates one.
47 files, over the 1,000-line budget (mostly tests and docs); happy to split.
Open questions: requiring the native backend, and multi-client proxies (the proxy token is shared, so the host pins tenant and lease per client).
Validation
At 7dfeb33, except the response-redaction item:
- Checks:
pnpm check:affected --run(format, lint, typecheck, layering, fallow, build, 715 vitest files, daemon wire compat) passed at 332c35f, except for timeouts in unrelated tests under heavy host load:daemon-registration-owner.test.tsand two provider-integration scenarios, which passed on rerun. 7dfeb33 only moves one helper; lint, typecheck, layering, fallow, the eager-closure budget and the touched tests passed again. The macOS helper builds with-warnings-as-errors, andpnpm test:macos-helperpasses. CI is green at 7dfeb33 (12 checks pass, 3 skipped). - Response redaction (937471b):
pnpm check:affected --runpassed (716 vitest files), and CI is green at 937471b. Tests coveropenand a refused request through the request handler under the lease (no state dir, host path or device name in the wire response; an unleased open is unchanged),open --foregroundfailures, the fallback screenshot path, the diagnostics route, and the client reading anopenwithout device or paths. Not re-run live. - New tests: lease-exempt
doctorandsession_listrefused throughcreateRequestExecutionScopeunderleases.require; sessionlesssnapshot/screenshot/wait/find/get/isrefused byassertRequestLeaseAdmission; abatch [snapshot, open]before open refused at step 1 through the request handler; the heartbeat cap;/healthper host platform. - Live, two Macs, at edf873e: a client Mac ran the PR build against
agent-device proxyon a host Mac running macOS 27, withAGENT_DEVICE_DAEMON_POLICY{"version":1,"leases":{"require":"macos-app"}},AGENT_DEVICE_MACOS_APP_BACKEND=native, and a fixture app leased throughPUT /admin/leases/<id>. The run refused sessionlesssnapshot/screenshot,doctor,session list,devices, another app,--fullscreen, off-window and menu-bar clicks, and every request after the adminDELETE.open,snapshot,click,fill,screenshotandcloseof the leased app worked. Transcript. - In practice: Stim (appandflow/stim) agents drive Stim Desktop hosted on another Mac through this backend (
stim macos --host), and stim-server allocates each lease over the admin route. - Not verified: multi-client proxies (the host pins tenant and lease per client); the menu-bar ancestor check in the helper, which did not fire live because the window check refused first; native-backend actions on windows on another Space or minimized, which are now refused.