From 424597d558c52726cf1e306c8a8aa21448be50a6 Mon Sep 17 00:00:00 2001 From: Fero Date: Mon, 12 Jan 2026 16:33:03 +0100 Subject: [PATCH] example: add desktop notification extension (OSC 777) (#658) --- .../examples/extensions/notify.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/coding-agent/examples/extensions/notify.ts diff --git a/packages/coding-agent/examples/extensions/notify.ts b/packages/coding-agent/examples/extensions/notify.ts new file mode 100644 index 00000000..f073c7a4 --- /dev/null +++ b/packages/coding-agent/examples/extensions/notify.ts @@ -0,0 +1,25 @@ +/** + * Desktop Notification Extension + * + * Sends a native desktop notification when the agent finishes and is waiting for input. + * Uses OSC 777 escape sequence - no external dependencies. + * + * Supported terminals: Ghostty, iTerm2, WezTerm, rxvt-unicode + * Not supported: Kitty (uses OSC 99), Terminal.app, Windows Terminal, Alacritty + */ + +import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; + +/** + * Send a desktop notification via OSC 777 escape sequence. + */ +function notify(title: string, body: string): void { + // OSC 777 format: ESC ] 777 ; notify ; title ; body BEL + process.stdout.write(`\x1b]777;notify;${title};${body}\x07`); +} + +export default function (pi: ExtensionAPI) { + pi.on("agent_end", async () => { + notify("Pi", "Ready for input"); + }); +}