Skip to content

feat(ui): run !/!! bang commands on the user's terminal via a PTY - #544

Merged
yogthos merged 2 commits into
mainfrom
interactive-shell
Jun 29, 2026
Merged

feat(ui): run !/!! bang commands on the user's terminal via a PTY#544
yogthos merged 2 commits into
mainfrom
interactive-shell

Conversation

@yogthos

@yogthos yogthos commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

!cmd / !!cmd previously ran with stdin as /dev/null and 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 attach PTY-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.
  • Falls back to the capture-only path when there is no controlling terminal, the sandbox backend is microvm, or on non-unix.

Implementation notes

  • New 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_subprocess extracted into terminal.rs so /sandbox attach and the bang path share one verified sequence.
  • shell_phase reduced to the ShellKind enum; the off-thread spawn + shell_result select arm are removed (the command now runs synchronously while the TUI is suspended, so the channel hop is unnecessary).

Test plan

  • cargo fmt --check
  • cargo clippy --bin dirge --all-targets — 0 warnings
  • cargo test --bin dirge — sandbox suite (41), pty_relay suite, plus two new tests
  • New: command_for_pty_omits_noninteractive_env, run_loop_captures_child_stdout

Yogthos 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).
@yogthos
yogthos merged commit bf64bcc into main Jun 29, 2026
13 checks passed
@allen-munsch

Copy link
Copy Markdown
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)
@yogthos

yogthos commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Oh that's an interesting idea, it might be nice to unify these things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants