Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/hooks/session-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -156,6 +158,7 @@ export function createSessionNotification(
idleConfirmationDelay: 1500,
skipIfIncompleteTodos: true,
maxTrackedSessions: 100,
hasPendingBackgroundTasks: undefined as (() => boolean) | undefined,
...config,
}

Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
},
});
}
}

Expand Down Expand Up @@ -271,6 +278,8 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
},
});

backgroundManagerRef = backgroundManager;

const atlasHook = isHookEnabled("atlas")
? createAtlasHook(ctx, { directory: ctx.directory, backgroundManager })
: null;
Expand Down
Loading