feat: emit OSC terminal notifications on agent turn completion#1463
feat: emit OSC terminal notifications on agent turn completion#1463Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b872d4b9ce
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/kimi_cli/ui/shell/visualize.py
Outdated
| if not sys.stdout.isatty(): | ||
| return |
There was a problem hiding this comment.
Gate OSC notifications on the actual terminal stream
TurnEnd dispatch runs inside the Live(...) block in this module, and Rich redirects sys.stdout there by default; checking sys.stdout.isatty() in this helper can therefore evaluate the proxy stream instead of the real terminal and return early. In interactive shell sessions this suppresses both OSC writes, so the new completion notification path never fires even when the terminal supports OSC 9/777. Please gate on the console’s underlying output stream (or disable stdout redirection for Live) before deciding to skip notification emission.
Useful? React with 👍 / 👎.
b872d4b to
66bfe9c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66bfe9cf6a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/kimi_cli/ui/shell/visualize.py
Outdated
| case TurnEnd(): | ||
| pass | ||
| _emit_osc_notification("Kimi", "Task completed") |
There was a problem hiding this comment.
Restrict completion notifications to final user turn
TurnEnd is emitted for internal flow steps as well as the top-level user request (see _flow_turn in src/kimi_cli/soul/kimisoul.py, which sends TurnEnd() on each node iteration), so emitting "Task completed" on every TurnEnd produces repeated and incorrect desktop notifications while a flow is still running. In multi-node or retrying flows this can spam notifications and tell users the task is done before the command actually finishes.
Useful? React with 👍 / 👎.
Emit OSC 9 and OSC 777 escape sequences when the agent completes a turn, enabling desktop notifications in supported terminals (iTerm2, Windows Terminal, GNOME Terminal, rxvt-unicode, etc.). Write directly to stderr fd using os.write() to bypass Rich's stdout proxy in Live() mode. Check os.isatty(2) instead of sys.stdout.isatty() for reliable TTY detection. Fixes MoonshotAI#1342
66bfe9c to
94dd081
Compare
Feature
Emit OSC 9 and OSC 777 escape sequences when the agent completes a turn, enabling desktop notifications in supported terminals.
Supported terminals:
Only emits when stdout is a TTY to avoid noise in piped/redirected output.
Fixes #1342