11import path from "node:path" ;
22import type { Plugin } from "@opencode-ai/plugin" ;
33import { createNotificationScheduler } from "@/notification-scheduler" ;
4+ import { loadConfig , ConfigError } from "@/config/loader" ;
5+ import { createResolvedConfig } from "@/config/resolver" ;
46
57export const SimpleNotificationPlugin : Plugin = async ( { client } ) => {
6- const scheduler = createNotificationScheduler ( ) ;
8+ const config = await loadConfig ( ) . catch ( async ( error ) => {
9+ const message =
10+ error instanceof ConfigError
11+ ? `Notification plugin config error: ${ error . message } `
12+ : `Notification plugin failed to load: ${ error instanceof Error ? error . message : String ( error ) } ` ;
13+
14+ await client . tui . showToast ( {
15+ body : { message, variant : "error" } ,
16+ } ) ;
17+
18+ throw error ;
19+ } ) ;
20+
21+ const resolvedConfig = createResolvedConfig ( config ) ;
22+ const scheduler = createNotificationScheduler ( resolvedConfig ) ;
723 // Tracks sessions where assistant has responded since last user message
824 const activeSessions = new Set < string > ( ) ;
925
@@ -22,7 +38,7 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
2238 . get ( { path : { id : sessionId } } )
2339 . then ( ( details ) => details . data ?. title )
2440 . catch ( ( ) => undefined ) ;
25- scheduler . schedule ( sessionId , "Response ready" , title ?? sessionId ) ;
41+ scheduler . schedule ( sessionId , "Response ready" , title ?? sessionId , "session.idle" ) ;
2642 }
2743 activeSessions . delete ( sessionId ) ;
2844 break ;
@@ -37,7 +53,7 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
3753 . catch ( ( ) => undefined )
3854 : ( event . properties . error ?. data . message as string ) ;
3955 if ( sessionId ) {
40- scheduler . schedule ( sessionId , "Session error" , message ?? sessionId ) ;
56+ scheduler . schedule ( sessionId , "Session error" , message ?? sessionId , "session.error" ) ;
4157 }
4258 break ;
4359 }
@@ -58,6 +74,7 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
5874 sessionId ,
5975 "Permission Asked" ,
6076 `${ session ?. title } in ${ projectName } needs permission` ,
77+ "permission.asked" ,
6178 ) ;
6279 break ;
6380 }
@@ -78,6 +95,7 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
7895 sessionId ,
7996 "Question" ,
8097 `${ session ?. title } in ${ projectName } has a question` ,
98+ "question.asked" ,
8199 ) ;
82100 break ;
83101 }
@@ -95,8 +113,6 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
95113 case "message.updated" : {
96114 const info = event . properties . info ;
97115 if ( info . role === "user" ) {
98- // Only cancel for real user messages, not automatic system messages
99- // System messages have 'agent' or 'model' fields
100116 const infoAny = info ;
101117 const isAutomaticMessage = infoAny . agent || infoAny . model ;
102118 if ( ! isAutomaticMessage ) {
@@ -119,7 +135,6 @@ export const SimpleNotificationPlugin: Plugin = async ({ client }) => {
119135
120136 case "tui.prompt.append" :
121137 case "tui.command.execute" :
122- // No sessionID in these events, can't cancel reliably
123138 break ;
124139 }
125140 } ,
0 commit comments