buzz icon indicating copy to clipboard operation
buzz copied to clipboard

feat(acp): allow host policy to decide permission requests

Open Silentpartnercoding opened this issue 4 months ago • 1 comments

Follow-up to the permission-boundary analysis in #2931.

Buzz’s generic ACP client currently selects allow_once whenever that option is offered. This change adds an injectable asynchronous permission-decision callback so the host can choose among the exact options supplied by the agent.

The callback receives the permission request and offered options. A policy decision may select only an option that was actually offered. If the policy is unavailable, times out, is cancelled, returns an error, or selects an invalid option, the client fails closed through an offered rejection option.

The focused tests cover:

  • a deny decision emits a rejection response and never selects an allow option
  • option kinds and IDs are preserved exactly
  • string and numeric JSON-RPC request IDs
  • missing policy, timeout, cancellation, callback error, and invalid selection
  • response-write failure and cancellation cleanup

Trust boundary

This governs cooperative operations that cross session/request_permission. It does not provide general filesystem, subprocess, network, MCP, runtime, or operating-system containment. Runtimes that perform work without issuing a permission request remain outside this policy boundary.

Verification

  • cargo test -p buzz-acp
  • cargo build -p buzz-acp
  • cargo fmt --check
  • cargo clippy -p buzz-acp --all-targets -- -D warnings
  • focused deny-path JSON-RPC regression tests
  • git diff --check

Silentpartnercoding avatar Aug 01 '26 05:08 Silentpartnercoding

+1, this is a real problem when running multiple agent panes side by side — a click meant purely to shift focus landing on a Yes / No prompt is a dangerous failure mode precisely because it can't be undone. The fact that Orca already flips mouseEventsRequireAlt transiently for link clicks (terminal-link-pty-mouse-suppression.ts:45) makes this feel less like a new feature and more like surfacing an existing, already-tested mechanism as a persistent user preference.

On the open questions:

Agreed a single global setting is the right scope for v1 — per-pane/per-agent overrides can always come later if there's demand, no need to design for it now. The macOptionClickForcesSelection interaction on macOS is worth a line in the docs/tooltip so users aren't surprised when Option+click stops forcing a text selection and starts sending a mouse report instead. Worth double-checking the middle-click primary-selection paste path specifically, since it already conditionally backs off based on mouseTrackingMode — want to make sure this new state doesn't interact with that in a surprising way.

Happy to help test the PR against real TUIs (tmux, Claude Code prompts, etc.) if that's useful once it's up.

riyahref avatar Aug 01 '26 09:08 riyahref

Thanks — the PR is up as #11924, and two of your three points are already in it.

Middle-click primary-selection paste. You were right to single this out: it did break. getPrimarySelectionMiddleClickPane treated any mouseTrackingMode other than 'none' as proof the TUI would receive the click and deferred to it — but with the gate on, an unmodified middle click is suppressed by xterm, so neither the TUI nor Orca handled it and the paste was silently lost. The PR moves that decision into shouldClaimMiddleClickForPrimarySelection, so Orca defers only when the report actually reaches the TUI and pastes itself when the gate suppresses it. Covered by a 6-case table over mouseTrackingMode × gate × alt.

The same pass turned up one more surface: the dashboard popout's live preview terminal forwards its own onData straight to the PTY but never resolved the option, so a user who enabled the setting was still unguarded there. Fixed in the same PR.

macOS macOptionClickForcesSelection. Agreed, and the setting's own description now states the consequence rather than leaving it to be discovered:

Clicks and drags reach a program that tracks the mouse only while Option is held, so a stray click cannot answer its prompt. Plain clicks select text instead, replacing Option-click-to-select. Scrolling is unchanged.

Scope. Single global preference for v1, as you suggested — no per-pane or per-agent surface.

One thing I did not resolve, noted in the PR: terminal-link-pty-mouse-suppression.ts also writes this option, forcing it on for one Cmd/Ctrl link gesture and restoring the previous value on mouseup. applyTerminalAppearance now writes the same option from settings, so an unrelated settings write landing inside that gesture would restore the pre-gesture value. The window is a held mouse button, so I left the two writers uncoordinated rather than adding a guard between the modules — but I would rather be talked out of that than have it slip by.

Testing against real TUIs would genuinely help. tmux and Claude Code prompts are the two I would most want a second pair of eyes on, plus whether wheel scrolling stays intact for you — xterm documents wheel as unaffected and that matches what I measured, but I have only checked it on macOS.

giirrr avatar Aug 01 '26 10:08 giirrr

I'll pull #11924 and test it against tmux and Claude Code prompts today, and confirm wheel scrolling is untouched on my end too. Will report back with results (and screen recordings if anything looks off).

On the unresolved race between terminal-link-pty-mouse-suppression.ts and applyTerminalAppearance — I don't have a fix in mind off the top of my head, but I'll specifically try to trigger it while testing: holding a Cmd/Ctrl link click open and flipping the setting in the middle of that window, to see if it actually manifests in practice or stays theoretical. Will let you know either way.

riyahref avatar Aug 01 '26 10:08 riyahref

Thanks — one heads-up before you spend time on it.

The race is fixed as of 7f00642, pushed shortly before your comment, so holding a link click and flipping the setting will no longer reproduce anything. The suppressor stopped restoring a value snapshotted at mousedown; it now takes a getMouseEventsRequireAlt reader and restores what the setting says at mouseup, leaving applyTerminalAppearance as the only thing that decides the resting value. The PR body is updated to match.

The inverse is the case worth testing now: hold a Cmd/Ctrl link click, flip the setting mid-gesture, release, and check the pane ends up matching the setting rather than its pre-click value. That path is new and only has unit coverage.

Two things worth knowing while you test:

  • Wheel events are documented as unaffected by mouseEventsRequireAlt, and that matches what I measured. If TUI scrolling changes for you, that is a real finding.
  • On macOS the gate takes precedence over macOptionClickForcesSelection, so Option-drag stops forcing a selection and starts reaching the app. Expected, but it is the change most likely to feel wrong at first.

giirrr avatar Aug 01 '26 11:08 giirrr