Skip to content

fix(agent-isolation): show the touch overlay on macOS and for ssh-signed commits - #1288

Merged
potiuk merged 5 commits into
apache:mainfrom
potiuk:fix/gpg-touch-overlay-macos
Sep 19, 2026
Merged

potiuk merged 5 commits into
apache:mainfrom
potiuk:fix/gpg-touch-overlay-macos

Conversation

@potiuk

@potiuk potiuk commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Summary

  • gpg-touch-overlay.sh only watched for gpg, and its window was GTK with a zenity fallback. A Mac has neither, and a gpg.format=ssh commit signs via ssh-keygen -Y sign over gpg-agent's socket without ever starting gpg — so on macOS, and for ssh-signed commits anywhere, the key waited for a touch with nothing on screen.
  • The watcher now matches ssh-keygen alongside gpg/gpg2 (exact-name match kept), and macOS gets its own Tk window (gpg-touch-overlay-window-macos.py): main display only, borderless rather than native fullscreen so macOS does not switch Spaces out from under the terminal.
  • macOS has no setsid(1); the watcher falls back to perl's POSIX::setsid so it still leads its own session and disarm's single group kill closes the window.
  • arm/disarm always exit 0: a PreToolUse verdict must never block a commit over missing plumbing. The internal probes keep their real status for the tests.

Dogfooding this on the branch itself surfaced three more things that kept the window off the screen at the moment the key was actually waiting (second commit):

  • Interpreter choice. Tcl finds init.tcl relative to the executable it was started as and does not follow symlinks, so the python3 symlink uv or pyenv puts on PATH fails with "Tcl wasn't installed properly" while the interpreter behind it works. The probe then fell through to the Command Line Tools python, whose Apple Tk 8.5 starts and draws nothing for a borderless translucent window (or hangs setting it up). _tk_python now probes and reports each candidate by its resolved path and insists on Tk ≥ 8.6.
  • Watcher lifetime. The watcher took the first signing process ending as the end of the watch. A pre-commit hook that runs this tool's own test suite starts a process named ssh-keygen for half a second, so the watcher was gone before git signed; a rebase signing several commits lost all but the first the same way. It now lives until disarm, hiding the window between signatures — and actually exits on disarm's SIGTERM, which the old trap swallowed (it ran hide_overlay and kept looping).
  • Keyboard focus. A touch that lands before the key asks for one fires the YubiKey's OTP slot and types a burst of characters plus Return into whatever is in front — a browser, in practice. The window now gives its process an activation policy and activates it through the Objective-C runtime (ctypes, no PyObjC), then takes the keyboard while it is up, so those keystrokes land in the overlay instead. This is also what makes Esc-to-dismiss actually work on macOS: without focus the binding never saw the key.

Dogfooding the sandboxed path (third and fourth commits) turned up what the isolated setup got wrong for gpg.format=ssh, now covered at every layer:

  • sandbox-troubleshooting.md: a catalog entry for the signing-key read deny (symptom verbatim from a sandboxed run, one-file allowRead fix); the SSH-agent entry claimed a read grant on the socket was enough on both platforms — on macOS connect(2) needs sandbox.network.allowUnixSockets too, symptom and fix added; and a note that ssh transport (git push) cannot run from the sandbox at all (no DNS/TCP through the HTTP proxy).
  • setup-isolated-setup-verify check 10 (overlay hooks wired, scripts matching the framework copies, toolkit probe run outside the sandbox by the user, signing key readable from sandboxed Bash); setup-isolated-setup-doctor probe 5 (signing-key readability) and probe 1 naming the macOS socket case; setup-isolated-setup-update lists the overlay scripts for drift.
  • Evals: both suites were extracting a heading the skills no longer had (## The 3 probes vs ## The 4 probes); brought in line, one new case each.
  • Overlay script: the Tk probe lists interpreter homes by absolute path (the hook runs with the harness's environment, not the shell's PATH); the command matcher accepts a shell separator after the subcommand (git commit;); a marker file (touch /tmp/magpie-gpg-touch/debug) turns the watcher's log on where no variable can be set — the hook's environment — with a trace, the window's own output and the environment it drew from.
  • The overlay tests skip instead of erroring where the sandbox hides ps, so the pre-commit run passes inside it.

Verified end to end: both commits were signed from inside the sandbox with the hook-armed overlay providing the touch cue.

Migration path for existing adopters

Re-copy the hook scripts (cp tools/agent-isolation/gpg-touch-overlay* ~/.claude/scripts/) — there is one new file. No config change. Linux behaviour changes only in that the watcher now outlives the first signature (until disarm), which is what a multi-commit rebase needed anyway.

Test plan

  • prek run on all touched files — every hook passes. pytest (workspace) has to run outside the isolated sandbox: it denies ps/pgrep ("Operation not permitted"), which the session-leader and ssh-keygen-detection tests need.
  • tools/agent-isolation/tests/test_gpg_touch_overlay.py — 22 passed, 1 skipped (the gi probe, expected on macOS). New tests: ssh-keygen detection (whole-name match, so ssh-keygenx does not trip it), the session-leader guarantee of the spawn path, _tk_python returning a resolved path whose Tk is ≥ 8.6, and the watcher outliving a signature that ends.
  • End-to-end on macOS through the real hook path (arm → fake ssh-keygen → disarm): window up 1.7 s after the signature started, gone 0.2 s after it ended, watcher gone after disarm, no leftover process.
  • Both commits on this branch were signed with gpg.format=ssh on a YubiKey with the overlay up through the real arm path — including the ~45 s of pre-commit hooks (with the look-alike ssh-keygen from the test suite) before git signed. Esc dismisses the focused window.

Notes for reviewers

The watcher still gives no cue for the auth touch on git push over ssh — that goes through ssh, not ssh-keygen, and push only made it into the command matcher for --signed pushes. Same key, same silent block; matching ssh by name would also fire during any long transfer, so it needs a better signal than a process name. Out of scope here, worth a follow-up.

🤖 Generated with Claude Code

…ned commits

The watcher only knew gpg, and its window was GTK or zenity — a Mac has
neither, and a `gpg.format=ssh` commit signs via `ssh-keygen -Y sign`
over gpg-agent's socket without starting gpg at all. Either way the key
waited for a touch with nothing on screen.

- watch `ssh-keygen` alongside `gpg`/`gpg2` (exact-name match kept)
- add a Tk overlay window for macOS: main display, borderless rather
  than native fullscreen so the terminal is not pulled to another Space
- probe for a python that can actually start Tk, not just import
  tkinter (uv/pyenv/Homebrew pythons commonly lack the Tcl/Tk framework)
- fall back to perl's POSIX::setsid where setsid(1) is missing, keeping
  the watcher a session leader so disarm's group kill still closes the
  window
- arm/disarm always exit 0: a hook verdict must never block a commit
  over missing plumbing

Generated-by: Claude Fable 5.1
…ront of the keyboard

Three things kept the window off the screen at the moment the key was
actually waiting:

- Tcl finds init.tcl relative to the executable it was started as and
  does not follow symlinks, so the `python3` symlink uv or pyenv puts on
  PATH fails "Tcl wasn't installed properly" while the interpreter behind
  it works. The probe then fell through to the Command Line Tools python,
  whose Apple Tk 8.5 starts and draws nothing for the borderless window.
  Probe and report each candidate by its resolved path, and insist on
  Tk 8.6.
- The watcher took the first signing process ending as the end of the
  watch. A pre-commit hook that runs this tool's own test suite starts a
  process named ssh-keygen for half a second, so the watcher was gone
  before git signed; a rebase signing several commits lost all but the
  first the same way. The watcher now lives until disarm, hiding the
  window between signatures — and actually exits on disarm's SIGTERM,
  which the old trap swallowed.
- A touch that lands before the key asks for one fires the OTP slot and
  types into whatever is in front. The window now activates its process
  and takes the keyboard while it is up, so those keystrokes land in the
  overlay instead.

Generated-by: Claude Fable 5.1
@potiuk potiuk added family:tools tools/* capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) labels Sep 19, 2026
…h overlay and the ssh signing key

With gpg.format=ssh the sandbox's ~/.ssh read deny stops git before
the key is ever asked for a touch, and nothing in the isolated setup
said so. Now it does, at every layer:

- sandbox-troubleshooting.md gains a catalog entry for the failure
  (symptom verbatim from a sandboxed run, one-file allowRead fix), and
  the settings template carries the entry
- the SSH-agent entry claimed a read grant on the socket was enough on
  both platforms; on macOS connect(2) needs
  sandbox.network.allowUnixSockets as well — symptom, fix and template
  entry added
- setup-isolated-setup-verify: check 10 — overlay hooks wired, scripts
  matching the framework copies, toolkit probe run outside the sandbox
  by the user, signing key readable from sandboxed Bash
- setup-isolated-setup-doctor: probe 5 — signing-key readability, in
  the catalog's lock-step shape; probe 1 names the macOS socket case
- setup-isolated-setup-update: the overlay scripts join the drift list
- evals: both suites were extracting a heading the skills no longer
  had; headings and output specs brought in line, one new case each
- the overlay tests skip instead of erroring where the sandbox hides
  ps, so the pre-commit run passes inside it
- the Tk probe lists the usual interpreter homes by absolute path: the
  hook runs with the harness's environment, not the shell's PATH
- the command matcher accepts a shell separator after the subcommand
  (`git commit;` signs just as much as `git commit -m`)
- a marker file turns the watcher's log on where no variable can be
  set — the hook's environment — and the log then carries a trace,
  the window's own output, and the environment it drew from

Generated-by: Claude Fable 5.1
…ndbox

The agent-socket grant makes signing work; a push over ssh still gets
no DNS and no TCP from the sandbox, whose network is its HTTP proxy
alone. Say so next to the socket fix, with the symptom and the two
ways out (push from the terminal, or an https remote).

Generated-by: Claude Fable 5.1
arm opened the log with a truncating, non-append redirection for the
watcher while the window and its spawner appended to the same file, so
the watcher's trace overwrote their lines at its own offset — the
environment line the log exists to capture never survived. Truncate
once, then have everyone append.

Generated-by: Claude Fable 5.1
@potiuk
potiuk merged commit 223b9fd into apache:main Sep 19, 2026
10 checks passed
@potiuk potiuk added substrate:framework-dev Tool substrate: build / validate / eval the framework itself substrate:sandbox Tool substrate: agent isolation, egress control, settings audit labels Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) family:tools tools/* substrate:framework-dev Tool substrate: build / validate / eval the framework itself substrate:sandbox Tool substrate: agent isolation, egress control, settings audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants