Files
dots/common/.pi/agent/extensions/notify.ts
T
coja 1e39e0cb4b [Sync] replace the flat layout with the unified stow tree
Supersedes the old flat .config/ layout (last published 2026-06-28) with the
private repo's structure: one shared base plus per-host overlays.

- packages: common/ gui/ lw/ fl/ wm/ plus install.sh and bin/ tooling
  (dotsync, reconcile-hyde.sh)
- new README covering the layout, deploy order and the HyDE dependency
- current HyDE waybar rig (layouts/, cava), pi agent extensions, claude/
  config, tmux, presenterm, aichat roles
- fish: kp (keepassxc-cli + fzf picker, db path from $KP_DB) and
  bind_M_n_history (alt+1..9 recalls the nth history entry)
- drops cruft that should never have been tracked: the duplicate top-level
  .pi/ copy, btop.log, zellij config.kdl.bak, fish_variables
- .pi/agent/auth.json is gitignored; auth.json.example ships instead

Host-specific work sessions and the personal backlog stay in the private
tree. Endpoint locators in the llamacpp/whisper guides are placeholders
($SERVER, <own-domain>) — the guides themselves stay, since they are the
useful part.
2026-08-13 02:53:06 +02:00

56 lines
1.9 KiB
TypeScript

/**
* Pi Notify Extension
*
* Sends a native terminal notification when Pi agent is done and waiting for input.
* Supports multiple terminal protocols:
* - OSC 777: Ghostty, iTerm2, WezTerm, rxvt-unicode
* - OSC 99: Kitty
* - Windows toast: Windows Terminal (WSL)
*/
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
function windowsToastScript(title: string, body: string): string {
const type = "Windows.UI.Notifications";
const mgr = `[${type}.ToastNotificationManager, ${type}, ContentType = WindowsRuntime]`;
const template = `[${type}.ToastTemplateType]::ToastText01`;
const toast = `[${type}.ToastNotification]::new($xml)`;
return [
`${mgr} > $null`,
`$xml = [${type}.ToastNotificationManager]::GetTemplateContent(${template})`,
`$xml.GetElementsByTagName('text')[0].AppendChild($xml.CreateTextNode('${body}')) > $null`,
`[${type}.ToastNotificationManager]::CreateToastNotifier('${title}').Show(${toast})`,
].join("; ");
}
function notifyOSC777(title: string, body: string): void {
process.stdout.write(`\x1b]777;notify;${title};${body}\x07`);
}
function notifyOSC99(title: string, body: string): void {
// Kitty OSC 99: i=notification id, d=0 means not done yet, p=body for second part
process.stdout.write(`\x1b]99;i=1:d=0;${title}\x1b\\`);
process.stdout.write(`\x1b]99;i=1:p=body;${body}\x1b\\`);
}
function notifyWindows(title: string, body: string): void {
const { execFile } = require("child_process");
execFile("powershell.exe", ["-NoProfile", "-Command", windowsToastScript(title, body)]);
}
function notify(title: string, body: string): void {
if (process.env.WT_SESSION) {
notifyWindows(title, body);
} else 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", "Ready for input");
});
}