diff --git a/src/hooks/session-notification-scheduler.ts b/src/hooks/session-notification-scheduler.ts index 6b8387d5f..afea12c7f 100644 --- a/src/hooks/session-notification-scheduler.ts +++ b/src/hooks/session-notification-scheduler.ts @@ -2,8 +2,6 @@ import type { PluginInput } from "@opencode-ai/plugin" import type { Platform } from "./session-notification-sender" type SessionNotificationConfig = { - title: string - message: string playSound: boolean soundPath: string idleConfirmationDelay: number @@ -18,7 +16,7 @@ export function createIdleNotificationScheduler(options: { platform: Platform config: SessionNotificationConfig hasIncompleteTodos: (ctx: PluginInput, sessionID: string) => Promise - send: (ctx: PluginInput, platform: Platform, title: string, message: string) => Promise + send: (ctx: PluginInput, platform: Platform, sessionID: string) => Promise playSound: (ctx: PluginInput, platform: Platform, soundPath: string) => Promise }) { const notifiedSessions = new Set() @@ -34,23 +32,33 @@ export function createIdleNotificationScheduler(options: { const maxSessions = options.config.maxTrackedSessions if (notifiedSessions.size > maxSessions) { const sessionsToRemove = Array.from(notifiedSessions).slice(0, notifiedSessions.size - maxSessions) - sessionsToRemove.forEach((id) => notifiedSessions.delete(id)) + sessionsToRemove.forEach((id) => { + notifiedSessions.delete(id) + }) } if (sessionActivitySinceIdle.size > maxSessions) { const sessionsToRemove = Array.from(sessionActivitySinceIdle).slice(0, sessionActivitySinceIdle.size - maxSessions) - sessionsToRemove.forEach((id) => sessionActivitySinceIdle.delete(id)) + sessionsToRemove.forEach((id) => { + sessionActivitySinceIdle.delete(id) + }) } if (notificationVersions.size > maxSessions) { const sessionsToRemove = Array.from(notificationVersions.keys()).slice(0, notificationVersions.size - maxSessions) - sessionsToRemove.forEach((id) => notificationVersions.delete(id)) + sessionsToRemove.forEach((id) => { + notificationVersions.delete(id) + }) } if (executingNotifications.size > maxSessions) { const sessionsToRemove = Array.from(executingNotifications).slice(0, executingNotifications.size - maxSessions) - sessionsToRemove.forEach((id) => executingNotifications.delete(id)) + sessionsToRemove.forEach((id) => { + executingNotifications.delete(id) + }) } if (scheduledAt.size > maxSessions) { const sessionsToRemove = Array.from(scheduledAt.keys()).slice(0, scheduledAt.size - maxSessions) - sessionsToRemove.forEach((id) => scheduledAt.delete(id)) + sessionsToRemove.forEach((id) => { + scheduledAt.delete(id) + }) } } @@ -128,7 +136,7 @@ export function createIdleNotificationScheduler(options: { notifiedSessions.add(sessionID) - await options.send(options.ctx, options.platform, options.config.title, options.config.message) + await options.send(options.ctx, options.platform, sessionID) if (options.config.playSound && options.config.soundPath) { await options.playSound(options.ctx, options.platform, options.config.soundPath) diff --git a/src/hooks/session-notification.ts b/src/hooks/session-notification.ts index 00e171b7b..d54d38c61 100644 --- a/src/hooks/session-notification.ts +++ b/src/hooks/session-notification.ts @@ -3,6 +3,7 @@ import { subagentSessions, getMainSessionID } from "../features/claude-code-sess import { startBackgroundCheck, } from "./session-notification-utils" +import { buildReadyNotificationContent } from "./session-notification-content" import { type Platform, } from "./session-notification-sender" @@ -55,7 +56,28 @@ export function createSessionNotification( platform: currentPlatform, config: mergedConfig, hasIncompleteTodos, - send: sessionNotificationSender.sendSessionNotification, + send: async (hookCtx, platform, sessionID) => { + if ( + typeof hookCtx.client.session.get !== "function" + && typeof hookCtx.client.session.messages !== "function" + ) { + await sessionNotificationSender.sendSessionNotification( + hookCtx, + platform, + mergedConfig.title, + mergedConfig.message, + ) + return + } + + const content = await buildReadyNotificationContent(hookCtx, { + sessionID, + baseTitle: mergedConfig.title, + baseMessage: mergedConfig.message, + }) + + await sessionNotificationSender.sendSessionNotification(hookCtx, platform, content.title, content.message) + }, playSound: sessionNotificationSender.playSessionNotificationSound, })