Skip to content

Commit b872d4b

Browse files
committed
feat: emit OSC terminal notifications on agent turn completion
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.). Only emits when stdout is a TTY to avoid noise in piped/redirected output. Fixes #1342
1 parent 94212ea commit b872d4b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/kimi_cli/ui/shell/visualize.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import sys
45
from collections import deque
56
from collections.abc import Awaitable, Callable
67
from contextlib import asynccontextmanager, suppress
@@ -444,6 +445,17 @@ async def _keyboard():
444445
await listener.stop()
445446

446447

448+
def _emit_osc_notification(title: str, body: str) -> None:
449+
"""Emit terminal notification via OSC 9 and OSC 777."""
450+
if not sys.stdout.isatty():
451+
return
452+
# OSC 9: used by ConEmu, Windows Terminal, iTerm2
453+
sys.stdout.write(f"\x1b]9;{body}\x07")
454+
# OSC 777: used by rxvt-unicode, VTE-based terminals (GNOME Terminal, etc.)
455+
sys.stdout.write(f"\x1b]777;notify;{title};{body}\x07")
456+
sys.stdout.flush()
457+
458+
447459
class _LiveView:
448460
def __init__(self, initial_status: StatusUpdate, cancel_event: asyncio.Event | None = None):
449461
self._cancel_event = cancel_event
@@ -568,7 +580,7 @@ def dispatch_wire_message(self, msg: WireMessage) -> None:
568580
)
569581
)
570582
case TurnEnd():
571-
pass
583+
_emit_osc_notification("Kimi", "Task completed")
572584
case CompactionBegin():
573585
self._compacting_spinner = Spinner("balloon", "Compacting...")
574586
self.refresh_soon()

0 commit comments

Comments
 (0)