import { 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; 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>(base: T, override: Record): T { const result = { ...base } as Record; 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, override[key] as Record, ); } else { result[key] = override[key]; } } return result as T; }