Skip to content

feat(tui): notify when GAIA needs you, and keep the PC awake - #5235

Closed
kovtcharov wants to merge 1 commit into
amd:feat/tui-minimal-claude-stylefrom
kovtcharov:claude/tui-notify-keepawake-71e83d
Closed

kovtcharov wants to merge 1 commit into
amd:feat/tui-minimal-claude-stylefrom
kovtcharov:claude/tui-notify-keepawake-71e83d

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Long local turns run for minutes, so people switch windows and miss approval prompts and questions. The turn then sits waiting, and a laptop can idle-sleep in the middle of it. Now the terminal UI sends a desktop notification through the terminal when a step needs approval, the agent asks a question, or a turn finishes, but only while the terminal is in the background. It also keeps the PC awake while GAIA works on a turn, and reports once in the chat if the OS refuses.

Builds on #5155 (base is its branch, so this diff is only this work) and lands after v0.25.0.

Closes #5231

🔍 Technical details
  • Hook point: a wrapper around the root model reads ChatModel.Attention() after every update and acts on edges. The chat view makes no calls; model.go gains 4 lines, so it can route a one-off notice past overlays.
  • Escape sequences: OSC 777 for Windows Terminal (plus BEL), Ghostty, WezTerm, foot and rxvt; OSC 9 for iTerm2; BEL everywhere else. Agent text is cleaned of control characters, C1 codes and ;. Approval notifications omit the command line, because the OS keeps notifications in its history and on the lock screen.
  • No torn frames: notifications share a mutex-wrapped stdout with Bubble Tea's renderer (tea.WithOutput), so one can never land inside a frame's escape sequence.
  • Focus: off Windows, focus reports (CSI ?1004h) arrive as FocusMsg/BlurMsg. Bubble Tea v1.3.10 drops console focus events on Windows, so there the foreground window is compared with the console's root owner. Another tab of the same Windows Terminal window counts as focused. A terminal that never reports focus never notifies (documented, including tmux focus-events).
  • Keep-awake: SetThreadExecutionState on a locked OS thread on Windows; caffeinate -i -w <pid> on macOS; systemd-inhibit --what=idle:sleep on Linux, released by closing a pipe. Linux therefore also holds off a manual suspend; the docs say so. The hold drops while a prompt waits on the user. A helper that fails at start or dies mid-turn is reported once.
  • Settings: notify_approval, notify_question, notify_finished, keep_awake in ~/.gaia/config.json, all on by default, declared in GaiaConfig so gaia config set accepts them as strict booleans.
  • Windows Terminal: it honours OSC 777 only from 1.26, with compatibility.allowOSC777 turned on; earlier versions get the bell.

Test plan

  • cd tui && go test ./... and go vet ./... pass; GOOS=linux and GOOS=darwin go vet pass for the new packages
  • Unit tests assert the exact bytes for BEL, OSC 9, OSC 777 and OSC 777+BEL, escape-injection cleaning, focus gating (reports and the Windows probe), each per-event setting, keep-awake hold/release order, and one-time failure reporting
  • python -m pytest tests/unit/test_cli_config.py passes; python util/lint.py --black --isort passes; util/check_doc_links.py --internal-only passes
  • Windows Terminal 1.24, live TUI with a scripted agent: with the TUI's window in front, a finished turn sent nothing; with another window in front, it sent OSC 777 + BEL; keep-awake held and released around each turn
  • Windows foreground probe in Windows Terminal resolves the console's root owner to the terminal window (known=true)
  • Permission prompt with the terminal in the background raises a notification in Windows Terminal. Needs the real agent and a model: the scripted agent's event format has no approval event, so this path is covered by unit tests only
  • Desktop popup in Windows Terminal 1.26 with compatibility.allowOSC777 on (this machine has 1.24, which only rings the bell)
  • Linux/macOS keep-awake helper tests pass in CI under -race (TUI Build & Test). The real caffeinate hold passes on macOS; on the Linux runner systemd-inhibit is refused (no login session), so that one platform test skips with the plain-words error

… turn

Long local turns made people switch windows and miss approval prompts and
questions, and a laptop could sleep mid-turn. The terminal UI now sends a
desktop notification through the terminal (OSC 777 or OSC 9, with the bell
as fallback) when a step needs approval, the agent asks a question, or a
turn finishes, and only while the terminal is in the background. Each event
has its own setting (notify_approval, notify_question, notify_finished in
~/.gaia/config.json).

While GAIA works on a turn the PC is kept from idle-sleeping
(SetThreadExecutionState, caffeinate, systemd-inhibit), released when the
turn ends or waits on the user; a failure is reported once in the chat.
keep_awake turns it off.

A wrapper around the root model watches ChatModel.Attention() and acts on
edges, so the chat view makes no calls. Notifications share a locked stdout
with the renderer so they never land inside a frame. Focus comes from focus
reports, except on Windows, where Bubble Tea drops console focus events and
the foreground window is compared instead.

Closes amd#5231
@github-actions github-actions Bot added documentation Documentation changes tests Test changes tui Go terminal UI (gaia-tui) labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

The terminal UI now sends a desktop notification when a step needs approval, the agent asks a question, or a turn finishes, and only while the terminal is in the background. It also keeps the PC from idle-sleeping during a turn. I found no correctness or safety problems. Agent text is cleaned before it goes into the terminal escape sequence, approval notifications never include the command line, sensitive questions stay out of the OS notification history, and the keep-awake hold is released whenever a prompt waits on the user. All four new settings are on by default and can each be turned off with gaia config set.

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR description reports a live Windows Terminal 1.24 run with a scripted agent. With the TUI in front, a finished turn sent nothing; with another window in front, it sent OSC 777 + BEL. Keep-awake held and released around each turn. Two paths still lack live proof: the approval notification (unit tests only, because the scripted agent can't raise an approval) and the real popup on Windows Terminal 1.26. Those are fair to leave until after merge. For everything outside the author's run, this verdict rests on reading the code.

🔍 Technical details

Issues found (minor only, none blocking)

  • 🟢 A note can be dropped if the user leaves the chat view before it's shown (tui/internal/ui/attention.go:1720). flushNotes checks that a conversation is on screen when it queues chat.NoticeMsg. The root model only routes that message to the chat when activeView == viewChat (root/model.go). If the user opens the gateway in between, the one-time keep-awake failure note never appears. Rare and harmless; to fix it, deliver the note straight to m.chat from the root regardless of the active view.
  • 🟢 A failed keep-awake is retried on every turn (tui/internal/attention/keepawake.go:727). Once acquire fails (for example, Linux with no logind), every later Hold(true) spawns systemd-inhibit again and waits the 300 ms startup grace on the keeper goroutine. The user is told only once, so this costs nothing they can see. Stopping after the first refusal would avoid a process per turn.
  • 🟢 Hold can block the UI goroutine in theory (keepawake.go:706). reqs holds 16 requests, and the keeper can stall for up to about 2.3 s on a slow helper. Holds only change on turn and prompt edges, so the buffer won't fill in practice. Mentioned only because Hold runs inside Update.

Strengths

  • Hooking in at the state edges (ChatModel.Attention() plus one wrapper around the root model) keeps notification logic out of the chat view. It also means "each prompt notifies once" falls out of AskKey comparison instead of needing flags at call sites.
  • The escape-sequence safety is tested at byte level: control characters and C1 codes are stripped, ; is replaced, ConEmu's 9;4; is avoided, and long bodies are truncated. Sharing one locked stdout with Bubble Tea's renderer prevents torn frames.
  • Failures are loud and actionable, as CLAUDE.md requires. A bad config key is named, the readable keys still apply, a helper that dies mid-turn is reported, and every message says how to turn the feature off. The GaiaConfig fields make gaia config set reject non-boolean values, and the docs in the guide, the CLI reference and the dev reference all agree.

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

Labels

documentation Documentation changes enhancement New feature or request tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants