feat(ui): run !/!! bang commands on the user's terminal via a PTY - #544
Merged
Conversation
added 2 commits
June 29, 2026 15:21
Previously !/!! captured stdout with stdin as /dev/null and forced noninteractive env vars (GIT_TERMINAL_PROMPT=0, GCM_INTERACTIVE=Never, DEBIAN_FRONTEND=noninteractive), so commands needing terminal input — `gh auth login`, editors, prompts — hung to a 120s timeout or failed silently. Reuse the /sandbox attach PTY-relay path: suspend the TUI, spawn the command attached to /dev/tty, relay I/O until exit, capture output, resume. Visible (`!`) feeds captured output to the agent as a turn; Invisible (`!!`) shows it live only. Falls back to the capture-only path when there's no controlling terminal, the backend is microvm, or on non-unix. Sandbox gains command_for_pty() (secret-scrubbed, no noninteractive env); the suspend/resume helpers move into terminal.rs so attach and the bang path share one verified sequence.
These helpers were moved into terminal.rs from the (unix-only) sandbox attach command, which lost the implicit cfg(unix) gating the module gave them. On windows-default they compiled and referenced unix-only callees (join_reader, drain_stdin_nonblocking, sync_and_drain_via_sentinel, Renderer::reset_tui/set_needs_repaint), breaking the windows CI build. All call sites are already unix-only (mod shell_interactive, mod sandbox).
Collaborator
|
janet, bang, microvm, computer use on the same PTY rails i'm wondering if there's an abstraction/interface unification story here potentially where/how commands go, when on host and when in sandbox, when via janet, etc @yogthos i haven't thought about it too deeply, just wanted to make note of it, bring to your attention tangentially related to: #536 security clamping |
yogthos
pushed a commit
that referenced
this pull request
Jun 30, 2026
PTY-backed !/!! bang commands (interactive gh/editors, vt100 in-place render), /prompt <name> <text> runs the text, write_todo_list backed by the issue board, clipboard copied tooltip, CI clippy gate, visible failed MCP servers, stream retry on mid-tool-call chunk timeouts, and bounded DB loads in agent construction. (#538, #539, #540, #541, #542, #544, #546, #547)
Collaborator
Author
|
Oh that's an interesting idea, it might be nice to unify these things. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
!cmd/!!cmdpreviously ran with stdin as/dev/nulland noninteractive env vars forced (GIT_TERMINAL_PROMPT=0,GCM_INTERACTIVE=Never,DEBIAN_FRONTEND=noninteractive), so anything needing terminal input —gh auth login, editors, password prompts — hung to a 120s timeout or failed silently.This reuses the
/sandbox attachPTY-relay path to run bang commands attached to the user's real terminal.Behavior
!(Visible): suspend the TUI, spawn the command on a PTY connected to/dev/tty, relay I/O until exit, capture output, resume the TUI; captured output is fed to the agent as a turn.!!(Invisible): same path, but output is shown live and not sent to the agent.microvm, or on non-unix.Implementation notes
Sandbox::command_for_pty()— omits the noninteractive env vars and scrubs secrets, since the child owns the terminal.suspend_tui_for_subprocess/resume_tui_after_subprocessextracted intoterminal.rsso/sandbox attachand the bang path share one verified sequence.shell_phasereduced to theShellKindenum; the off-thread spawn +shell_resultselect arm are removed (the command now runs synchronously while the TUI is suspended, so the channel hop is unnecessary).Test plan
cargo fmt --checkcargo clippy --bin dirge --all-targets— 0 warningscargo test --bin dirge— sandbox suite (41), pty_relay suite, plus two new testscommand_for_pty_omits_noninteractive_env,run_loop_captures_child_stdout