opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(tui): OSC 9 desktop notifications for toasts (#4454)

Open mcheviron opened this issue 1 month ago • 1 comments

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

mcheviron avatar Nov 21 '25 22:11 mcheviron

@rekram1-node do you think this could be added soon? I am not sure if it's the type of feature that needs architectural stuff or not

mcheviron avatar Dec 09 '25 22:12 mcheviron