[PR #4612] feat(tui): OSC 9 desktop notifications for toasts (#4454) #11036

Closed
opened 2026-02-16 18:15:49 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4612

State: closed
Merged: No


Summary

Implements OSC 9 desktop notifications for important TUI events, as proposed in #4454.

  • Add a small OSC 9 helper for emitting terminal notifications from the TUI.
  • Wire desktop notifications through the existing toast system so any toast.show(...) can surface a desktop notification.
  • Gate notifications behind config.tui.notifications.desktop (defaulting to enabled when unset).

Implementation Details

OSC 9 helper

  • New file packages/opencode/src/cli/cmd/tui/util/osc.ts exposes:
    • osc9(text: string) which writes ESC ] 9;{text} BEL to stdout, wrapped for tmux when $TMUX is set.
  • This keeps OSC 9 usage encapsulated and aligned with how Codex/Claude use terminal notifications.

Toast integration

  • packages/opencode/src/cli/cmd/tui/ui/toast.tsx:
    • ToastProvider now reads sync.data.config.tui.notifications.desktop via useSync.
    • toast.show(...) calls sendDesktopNotification(summary) once per toast (using the toast title or a default "Notification").
    • If config.tui.notifications.desktop === false, desktop notifications are suppressed but visual toasts still render.
  • This keeps OSC 9 as a purely TUI concern and avoids sprinkling notification calls around the codebase.

Session toasts as first OSC 9 triggers

  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx:
    • Track status and permissions per route.sessionID and detect transitions:
      • non-idle -> idle → show "Agent finished / Session is now idle" toast.
      • permissions.length: 0 -> >0 → show "Permission required / Review and approve requested actions" toast.
    • Because these go through toast.show(...), they also trigger OSC 9 notifications (when enabled), matching the behavior described in #4454.
image
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4612 **State:** closed **Merged:** No --- ## Summary Implements OSC 9 desktop notifications for important TUI events, as proposed in [#4454](https://github.com/sst/opencode/issues/4454). - Add a small OSC 9 helper for emitting terminal notifications from the TUI. - Wire desktop notifications through the existing toast system so any `toast.show(...)` can surface a desktop notification. - Gate notifications behind `config.tui.notifications.desktop` (defaulting to enabled when unset). ## Implementation Details **OSC 9 helper** - New file `packages/opencode/src/cli/cmd/tui/util/osc.ts` exposes: - `osc9(text: string)` which writes `ESC ] 9;{text} BEL` to stdout, wrapped for tmux when `$TMUX` is set. - This keeps OSC 9 usage encapsulated and aligned with how Codex/Claude use terminal notifications. **Toast integration** - `packages/opencode/src/cli/cmd/tui/ui/toast.tsx`: - `ToastProvider` now reads `sync.data.config.tui.notifications.desktop` via `useSync`. - `toast.show(...)` calls `sendDesktopNotification(summary)` once per toast (using the toast `title` or a default `"Notification"`). - If `config.tui.notifications.desktop === false`, desktop notifications are suppressed but visual toasts still render. - This keeps OSC 9 as a purely TUI concern and avoids sprinkling notification calls around the codebase. **Session toasts as first OSC 9 triggers** - `packages/opencode/src/cli/cmd/tui/routes/session/index.tsx`: - Track `status` and `permissions` per `route.sessionID` and detect transitions: - `non-idle -> idle` → show "Agent finished / Session is now idle" toast. - `permissions.length: 0 -> >0` → show "Permission required / Review and approve requested actions" toast. - Because these go through `toast.show(...)`, they also trigger OSC 9 notifications (when enabled), matching the behavior described in #4454. <img width="740" height="196" alt="image" src="https://github.com/user-attachments/assets/cc1ee3ee-dee0-4a1c-a3f5-0f96e2fc4f88" />
yindo added the pull-request label 2026-02-16 18:15:49 -05:00
yindo closed this issue 2026-02-16 18:15:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11036