feat(desktop): add secure Co-Agent snapshot handoff
Summary
Adds a macOS-only, confirmation-gated handoff from Co-Agent into Buzz's existing agent-snapshot preview flow.
Co-Agent stages a narrowly scoped snapshot, then opens:
buzz://import-agent-snapshot?handoff=<canonical-lowercase-UUID>
Buzz resolves that identifier only inside:
~/Library/Application Support/Co-Agent/buzz-handoffs
No snapshot bytes or filesystem path are placed in the URL. Buzz never confirms or imports the snapshot automatically.
Security and lifecycle boundary
Before accepting a staged handoff, Buzz requires:
- A bounded URL containing one canonical lowercase UUID and no extra authority, path, fragment, or query parameters.
- An owner-owned, owner-only, real staging directory opened with
O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC. - An owner-owned, owner-only, single-link regular file opened with
openat(..., O_RDWR | O_NOFOLLOW | O_CLOEXEC)relative to that directory descriptor. - A payload within the existing snapshot-size limit and no older than 10 minutes.
- A
buzz-agent-snapshotv1 payload containing only the required envelope, name, optional system prompt,runtime: "hermes", display name, andmemory.level: "none".
The handoff rejects memory entries, audience settings, allowlists, model/provider selection, parallelism, timing controls, name pools, avatars, unknown fields, non-Hermes runtimes, symlinks, hard links, wrong ownership, permissive modes, oversized files, expired files, and files changed during read.
Buzz permits one pending handoff, bounded by the existing 5 MiB snapshot limit. The queue retains the validated file descriptor while the renderer opens the existing preview flow. After preview creation succeeds, Buzz rereads the exact accepted inode through that descriptor, compares the bytes, truncates it to zero, calls sync_all, and verifies zero length before releasing the queue item. It never unlinks a pathname. A concurrent replacement path is untouched, and a hardlink added after validation is zeroed with the accepted inode. Preview rejection drops the descriptor without altering the staged source, leaving it available for diagnosis and a clean retry.
Warm and cold launch
- Warm launch: the registered deep-link listener validates and queues the handoff, activates Buzz, and notifies the renderer.
- Cold launch:
get_current()feeds the startup URL through the same validator. - The renderer peeks the single pending item, navigates to Agents, opens the existing preview, and acknowledges only after preview creation succeeds.
- Import still requires the user's explicit confirmation. Cancellation does not import an agent.
Upstream compatibility audit
This branch is based directly on Buzz origin/main at 6300a6b1, including #3420's per-runtime ACP environment isolation.
Current Buzz main already provides the hermes preset, startup registry warming, Unix sidecar permissions, and Hermes ACP environment handling. Earlier private runtime-registration, command-resolution, and sidecar changes were removed from this PR. The separate Hermes launcher correction remains owned by #3334; this PR does not duplicate it.
Verification
Exact candidate: 0dd552d366ec79f308c0a4c7a498c3f9c84e7d57
- Nested-workspace
cargo fmt --all -- --check: passed - Focused secure handoff suite: 18 passed, 0 failed
- Full
just desktop-tauri-test: 1,867 passed, 14 ignored, 0 failed, plus 3 diagnostics passed pnpm test: 3,773 passed, 0 failedpnpm typecheck: passed- Biome on all changed TypeScript files: passed
pnpm check:file-sizes: passedgit diff --check origin/main...HEAD: passed
Co-Agent producer verification on matching commit e41dde124e825748e969852c3dce2d9499ed0650:
- Exact snapshot schema, canonical UUID URL,
0700directory,0600file, atomic sibling rename, and forbidden-field tests pass. - Full Swift suite: 62 tests, 1 skipped, 0 failures.
- Co-Agent opens the handoff with the exact detected Buzz application rather than relying on the global URL-scheme handler.
Scope and rollout
This implementation is intentionally macOS-only because its fixed staging path and ownership/mode checks are macOS-specific. Windows and Linux fail closed for this route.
No release or appcast is changed by this PR. Final customer-flow verification still requires a Block-signed build so Buzz identity and keychain continuity match production. The required installed-app test is: warm and cold Add to Buzz, visible preview, explicit confirmation and cancellation, imported Co-Agent start, structured mention, and visible response with only one Buzz process running.