From e3fcd2bc7517f96feef3bda8b4a92dc59a05ec6b Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2026 07:11:20 +0000 Subject: [PATCH] refactor(notifications): share default user notification preferences The all-enabled UserNotificationPreferences default was declared three times across the notifications service (twice as DEFAULT_PREFERENCES and once inlined). Consolidate on a single exported constant owned by cloud-agent-session-push.ts, which already owns the UserNotificationPreferences type. --- .../lib/agent-session-notification-push.ts | 18 ++++++---------- .../src/lib/cloud-agent-session-push.ts | 21 +++++++++++-------- .../src/lib/internal-dispatch-push.ts | 17 +++++---------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/services/notifications/src/lib/agent-session-notification-push.ts b/services/notifications/src/lib/agent-session-notification-push.ts index 034f46bd65..e74d600960 100644 --- a/services/notifications/src/lib/agent-session-notification-push.ts +++ b/services/notifications/src/lib/agent-session-notification-push.ts @@ -19,7 +19,11 @@ import { type SendAgentSessionNotificationResult, } from '@kilocode/notifications'; -import { sanitizeTitle, type UserNotificationPreferences } from './cloud-agent-session-push'; +import { + DEFAULT_USER_NOTIFICATION_PREFERENCES, + sanitizeTitle, + type UserNotificationPreferences, +} from './cloud-agent-session-push'; export type { SendAgentSessionNotificationParams } from '@kilocode/notifications'; @@ -47,16 +51,6 @@ export function buildAgentSessionNotificationContent( }; } -const DEFAULT_PREFERENCES: UserNotificationPreferences = { - agentPushEnabled: true, - chatMessagesEnabled: true, - agentAttentionEnabled: true, - sessionStatusEnabled: true, - kiloclawActivityEnabled: true, - balanceAlertsEnabled: true, - securityFindingsEnabled: true, -}; - export type DispatchAgentSessionNotificationPushDeps = { getSession: (userId: string, cliSessionId: string) => Promise; hasOrganizationAccess: (userId: string, organizationId: string) => Promise; @@ -145,7 +139,7 @@ export async function dispatchAgentSessionNotificationPush( let prefs: UserNotificationPreferences; try { const row = await deps.readPreferences(parsed.userId); - prefs = row ?? DEFAULT_PREFERENCES; + prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES; } catch { return { dispatched: false, reason: 'failed' }; } diff --git a/services/notifications/src/lib/cloud-agent-session-push.ts b/services/notifications/src/lib/cloud-agent-session-push.ts index e0da30cea2..6b770aecbc 100644 --- a/services/notifications/src/lib/cloud-agent-session-push.ts +++ b/services/notifications/src/lib/cloud-agent-session-push.ts @@ -28,6 +28,17 @@ export type UserNotificationPreferences = { securityFindingsEnabled: boolean; }; +/** Default-on value used when a preference read returns no row. */ +export const DEFAULT_USER_NOTIFICATION_PREFERENCES: UserNotificationPreferences = { + agentPushEnabled: true, + chatMessagesEnabled: true, + agentAttentionEnabled: true, + sessionStatusEnabled: true, + kiloclawActivityEnabled: true, + balanceAlertsEnabled: true, + securityFindingsEnabled: true, +}; + const TITLE_MAX_LENGTH = 80; export function sanitizeTitle(title: string | null | undefined): string | null { @@ -90,15 +101,7 @@ async function dispatchSessionPush( let prefs: UserNotificationPreferences; try { const row = await deps.readPreferences(userId); - prefs = row ?? { - agentPushEnabled: true, - chatMessagesEnabled: true, - agentAttentionEnabled: true, - sessionStatusEnabled: true, - kiloclawActivityEnabled: true, - balanceAlertsEnabled: true, - securityFindingsEnabled: true, - }; + prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES; } catch { return { dispatched: false, reason: 'dispatch_failed' }; } diff --git a/services/notifications/src/lib/internal-dispatch-push.ts b/services/notifications/src/lib/internal-dispatch-push.ts index d214b45bb4..10d5ed2482 100644 --- a/services/notifications/src/lib/internal-dispatch-push.ts +++ b/services/notifications/src/lib/internal-dispatch-push.ts @@ -11,7 +11,10 @@ import type { PerRecipientResult, } from '@kilocode/notifications'; -import type { UserNotificationPreferences } from './cloud-agent-session-push'; +import { + DEFAULT_USER_NOTIFICATION_PREFERENCES, + type UserNotificationPreferences, +} from './cloud-agent-session-push'; type RecipientDOStub = { dispatchPush: (input: DispatchPushInput) => Promise; @@ -27,16 +30,6 @@ export type InternalDispatchDeps = { readPreferences: (userId: string) => Promise; }; -const DEFAULT_PREFERENCES: UserNotificationPreferences = { - agentPushEnabled: true, - chatMessagesEnabled: true, - agentAttentionEnabled: true, - sessionStatusEnabled: true, - kiloclawActivityEnabled: true, - balanceAlertsEnabled: true, - securityFindingsEnabled: true, -}; - function securityFindingTitle( notificationKind: 'new_finding' | 'sla_warning' | 'sla_breach', severity: string @@ -195,7 +188,7 @@ export async function dispatchInternalPushCore( let prefs: UserNotificationPreferences; try { const row = await deps.readPreferences(userId); - prefs = row ?? DEFAULT_PREFERENCES; + prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES; } catch { return 'failed' as const; }