diff --git a/src/hooks/session-notification.ts b/src/hooks/session-notification.ts index eded5181e8..3abebbba19 100644 --- a/src/hooks/session-notification.ts +++ b/src/hooks/session-notification.ts @@ -29,6 +29,8 @@ interface SessionNotificationConfig { skipIfIncompleteTodos?: boolean /** Maximum number of sessions to track before cleanup (default: 100) */ maxTrackedSessions?: number + /** Callback to check if there are pending background tasks (default: undefined - no check) */ + hasPendingBackgroundTasks?: () => boolean } type Platform = "darwin" | "linux" | "win32" | "unsupported" @@ -156,6 +158,7 @@ export function createSessionNotification( idleConfirmationDelay: 1500, skipIfIncompleteTodos: true, maxTrackedSessions: 100, + hasPendingBackgroundTasks: undefined as (() => boolean) | undefined, ...config, } @@ -227,6 +230,10 @@ export function createSessionNotification( executingNotifications.add(sessionID) try { + if (mergedConfig.hasPendingBackgroundTasks?.()) { + return + } + if (mergedConfig.skipIfIncompleteTodos) { const hasPendingWork = await hasIncompleteTodos(ctx, sessionID) if (notificationVersions.get(sessionID) !== version) { diff --git a/src/index.ts b/src/index.ts index 240844d968..5349165910 100644 --- a/src/index.ts +++ b/src/index.ts @@ -111,6 +111,8 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { : null; // Check for conflicting notification plugins before creating session-notification + // backgroundManagerRef is set later after BackgroundManager is created + let backgroundManagerRef: BackgroundManager | null = null; let sessionNotification = null; if (isHookEnabled("session-notification")) { const forceEnable = pluginConfig.notification?.force_enable ?? false; @@ -124,7 +126,12 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { allPlugins: externalNotifier.allPlugins, }); } else { - sessionNotification = createSessionNotification(ctx); + sessionNotification = createSessionNotification(ctx, { + hasPendingBackgroundTasks: () => { + if (!backgroundManagerRef) return false; + return backgroundManagerRef.getRunningTasks().length > 0; + }, + }); } } @@ -271,6 +278,8 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { }, }); + backgroundManagerRef = backgroundManager; + const atlasHook = isHookEnabled("atlas") ? createAtlasHook(ctx, { directory: ctx.directory, backgroundManager }) : null;