example: add desktop notification extension (OSC 777) (#658)

This commit is contained in:
Fero 2026-01-12 16:33:03 +01:00 committed by GitHub
parent 175a137d00
commit 424597d558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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");
});
}