Skip to content

feat(tui): notify when background work blocks or stops while away - #687

Merged
mohitranka merged 1 commit into
mainfrom
feat/background-strip-notify
Sep 14, 2026
Merged

mohitranka merged 1 commit into
mainfrom
feat/background-strip-notify

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Completes the background-activity work from #685 and #686. Those made work visible and made a block legible in the app; this makes it reach an operator who is looking at another window.

The gap

Forge had no out-of-band path at all — the only OSC escape in the codebase was OSC 52 for the clipboard, and dispatch_terminal_event swallowed FocusGained/FocusLost in its _ => {} arm, so the TUI could not even tell whether anyone was watching.

What changed

Two channels, and they are not equivalents:

  • OSC 9 (ESC ] 9 ; text BEL) asks the terminal for a desktop notification carrying the text. Ghostty, Kitty, iTerm2 and WezTerm forward it to the OS notification centre, several of them over SSH. Everywhere else it is ignored.
  • BEL rings the bell: universal, and says nothing.

Neither can be probed, so the mode and the terminal's identity decide — exactly what Claude Code does with its Ghostty/Kitty/iTerm2 allowlist.

[tui]
notify = "auto" | "bell" | "osc9" | "both" | "off"   # default: auto

auto is silent, not the bell, on an unrecognised terminal: an unexpected audible bell is worse than no notification. bell is the opt-in universal fallback, both is for tmux/SSH where one channel gets swallowed.

Also:

  • Focus now arrives via EnableFocusChange (newly requested), with FocusGained/FocusLost handled rather than ignored. Default focus is focused, so a terminal that never reports focus changes never notifies.
  • Notification text is sanitized rather than trusted: labels come from the model, and an embedded ESC or BEL would terminate the sequence early and leave the remainder to be read as terminal commands. There is a test with a hostile label.
  • The mode is installed into a thread-local rather than carried on TuiRuntimeConfig, following theme's precedent — a new field there would have touched every one of its 121 call sites to carry a value read in one place.

Notes for the reviewer

  • The in-app toast still fires when focused; the terminal notification and the in-app notice answer different questions.
  • Two existing TuiConfigFile test literals gained the new field; a_subagent_stopping_for_approval_names_itself now uses a shared helper instead of duplicating 30 lines of setup.

Verification

cargo fmt --all -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings clean. New tests cover channel resolution per mode and terminal, control-character stripping, truncation, sequence framing, both focus gates, and an app-level test that a blocking subagent notifies an away operator while staying silent when watched.

One test initially asserted that auto stays silent because the test environment has no allowlisted TERM_PROGRAM. That was wrong — the local TERM_PROGRAM is on the list — so it now tests the mode gate and leaves auto's resolution to the pure channels_for tests, which do not depend on the terminal they run in.

Forge had no way to reach an operator who is looking at another window.
`notify.rs` is that path: when a background task blocks on approval or
reaches a terminal state, and the terminal does not have focus, a notification
goes out naming the task.

Two channels, and they are not equivalents. OSC 9 (`ESC ] 9 ; text BEL`) asks
the terminal for a desktop notification carrying the text; Ghostty, Kitty,
iTerm2 and WezTerm forward it to the OS notification centre, several of them
over SSH. Everywhere else it is ignored. BEL rings the bell: universal, and
says nothing. Neither can be probed, so the mode and the terminal's identity
decide, exactly as Claude Code does with its Ghostty/Kitty/iTerm2 allowlist.

`[tui] notify = "auto" | "bell" | "osc9" | "both" | "off"`, default `auto`.
`auto` is silent — not the bell — on an unrecognised terminal, because an
unexpected audible bell is worse than no notification. The value is installed
into a thread-local rather than carried on `TuiRuntimeConfig`, following
theme's precedent: the config is read in one place, and a new field there
would have touched every one of its 121 call sites.

Focus arrives via `EnableFocusChange`, which the TUI did not previously
request; `dispatch_terminal_event` now handles `FocusGained`/`FocusLost`
instead of swallowing them. Default focus is *focused*, so a terminal that
never reports focus changes never notifies.

Notification text is sanitized rather than trusted: labels come from the
model, and an embedded ESC or BEL would terminate the sequence early and leave
the rest to be read as terminal commands.

Also drops the duplicated setup in the approval-naming test in favour of a
shared helper.

Tests: channel resolution per mode and terminal, control-character stripping,
truncation, sequence framing, both focus gates, and an app-level test that a
blocking subagent notifies an away operator while staying silent when
watched.
@mohitranka
mohitranka merged commit ef0bd79 into main Sep 14, 2026
3 checks passed
mohitranka added a commit that referenced this pull request Sep 14, 2026
…ions (#688)

The design system described the footer's counts-only chip and referred per-item
detail to "the task view", which did not exist as a named surface. The strip now
renders (#685, #686) and notifies (#687), so the rules that shipped — and the
reason each exists — belong in the design language rather than only in the code.

Adds §9.12 (the strip) and §9.13 (out-of-band notification), and points Row 1
of §9.3 at them. The rules recorded are the ones that are load-bearing and easy
to undo by accident: the derived height that keeps the transcript's floor,
the ordering that stops truncation hiding a failure, `cancelled` staying
distinct from `done`, the one-minute expiry, and the focus gate on the
notification.
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.

1 participant