37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
/**
|
|
* Pi Notify Extension (with audible bell)
|
|
*
|
|
* Fires a terminal bell + native desktop notification when Pi finishes.
|
|
* - Bell (\x07): tmux flags the window in the status bar + audible ding
|
|
* - OSC 777: Ghostty, iTerm2, WezTerm desktop notification popup
|
|
* - OSC 99: Kitty desktop notification popup
|
|
*
|
|
* Based on the official example from earendil-works/pi, with bell added.
|
|
*/
|
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
|
function notifyOSC777(title: string, body: string): void {
|
|
process.stdout.write(`\x1b]777;notify;${title};${body}\x07`);
|
|
}
|
|
|
|
function notifyOSC99(title: string, body: string): void {
|
|
process.stdout.write(`\x1b]99;i=1:d=0;${title}\x1b\\`);
|
|
process.stdout.write(`\x1b]99;i=1:p=body;${body}\x1b\\`);
|
|
}
|
|
|
|
function notify(title: string, body: string): void {
|
|
// Audible bell — tmux catches this, flags the window, terminal dings
|
|
process.stdout.write("\x07");
|
|
// Desktop notification popup (OSC 777 for Ghostty, OSC 99 for Kitty)
|
|
if (process.env.KITTY_WINDOW_ID) {
|
|
notifyOSC99(title, body);
|
|
} else {
|
|
notifyOSC777(title, body);
|
|
}
|
|
}
|
|
|
|
export default function (pi: ExtensionAPI) {
|
|
pi.on("agent_end", async () => {
|
|
notify("Pi", "Task complete — ready for input");
|
|
});
|
|
}
|