Something went wrong. Try again.
Notifications for pi.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { readFileSync, existsSync } from "node:fs";import { join } from "node:path";import { homedir } from "node:os";
const CONFIG_PATH = join( homedir(), ".pi", "agent", "extensions", "notify", "config.json",);
export interface HookConfig { enabled: boolean; title?: string | null; message?: string | null;}
export interface NativeConfig { enabled: boolean; windowsAppId?: string | null;}
export interface NotifyConfig { hooks: Record<string, HookConfig>; native: NativeConfig;}
const DEFAULTS: NotifyConfig = { hooks: { agent_end: { enabled: true, title: null, message: null }, "permissions:prompt": { enabled: true, title: null, message: null }, }, native: { enabled: true, windowsAppId: null },};
export function loadConfig(): NotifyConfig { try { if (existsSync(CONFIG_PATH)) { const raw = JSON.parse(readFileSync(CONFIG_PATH, "utf-8")); return deepMerge(DEFAULTS, raw); } } catch { // Config load failure — using defaults silently. } return structuredClone(DEFAULTS);}
function deepMerge<T extends Record<string, unknown>>(base: T, override: Record<string, unknown>): T { const result = { ...base } as Record<string, unknown>; for (const key of Object.keys(override)) { if ( typeof base[key] === "object" && base[key] !== null && !Array.isArray(base[key]) && typeof override[key] === "object" && override[key] !== null && !Array.isArray(override[key]) ) { result[key] = deepMerge( base[key] as Record<string, unknown>, override[key] as Record<string, unknown>, ); } else { result[key] = override[key]; } } return result as T;}