⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
fix: add debouncing to prevent duplicate SessionStart voice notifications
Daniel Miessler7e04e510df65
diff --git a/.claude/hooks/initialize-pai-session.ts b/.claude/hooks/initialize-pai-session.tsindex 706ae174..b03d768f 100755--- a/.claude/hooks/initialize-pai-session.ts+++ b/.claude/hooks/initialize-pai-session.ts@@ -21,10 +21,15 @@* 3. Add both hooks to SessionStart in settings.json*/-import { existsSync, statSync } from 'fs';+import { existsSync, statSync, readFileSync, writeFileSync, unlinkSync } from 'fs';import { join } from 'path';+import { tmpdir } from 'os';import { PAI_DIR } from './lib/pai-paths';+// Debounce duration in milliseconds (prevents duplicate SessionStart events)+const DEBOUNCE_MS = 2000;+const LOCKFILE = join(tmpdir(), 'pai-session-start.lock');+async function sendNotification(title: string, message: string, priority: string = 'normal') {try {// Get voice ID from environment variable (customize in settings.json)@@ -53,6 +58,35 @@ async function sendNotification(title: string, message: string, priority: string}}+/**+ * Check if we're within the debounce window to prevent duplicate notifications+ * from the IDE firing multiple SessionStart events+ */+function shouldDebounce(): boolean {+ try {+ if (existsSync(LOCKFILE)) {+ const lockContent = readFileSync(LOCKFILE, 'utf-8');+ const lockTime = parseInt(lockContent, 10);+ const now = Date.now();++ if (now - lockTime < DEBOUNCE_MS) {+ // Within debounce window, skip this notification+ return true;+ }+ }++ // Update lockfile with current timestamp+ writeFileSync(LOCKFILE, Date.now().toString());+ return false;+ } catch (error) {+ // If any error, just proceed (don't break session start)+ try {+ writeFileSync(LOCKFILE, Date.now().toString());+ } catch {}+ return false;+ }+}+async function testStopHook() {const stopHookPath = join(PAI_DIR, 'hooks/stop-hook.ts');@@ -105,6 +139,13 @@ async function main() {process.exit(0);}+ // Check debounce to prevent duplicate voice notifications+ // (IDE extension can fire multiple SessionStart events)+ if (shouldDebounce()) {+ console.error('🔇 Debouncing duplicate SessionStart event');+ process.exit(0);+ }+// Test stop-hook first (only for main sessions)const stopHookOk = await testStopHook();