@@ -73,13 +73,27 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
7373 console . error ( "[opencode-warp] failed to emit init log:" , err )
7474 } )
7575
76+ async function isSubagentSession ( sessionId ?: string ) : Promise < boolean > {
77+ if ( ! sessionId ) return false
78+ try {
79+ const session = await client . session . get ( {
80+ path : { id : sessionId } ,
81+ } )
82+ return ! ! session . data ?. parentID
83+ } catch {
84+ // If we can't fetch the session, fall through and notify anyway
85+ return false
86+ }
87+ }
88+
7689 return {
7790 event : async ( { event } : { event : Event } ) => {
7891 const cwd = directory || ""
7992
8093 switch ( event . type ) {
8194 case "session.created" : {
8295 const sessionId = event . properties . info . id
96+ if ( await isSubagentSession ( sessionId ) ) return
8397 const body = buildPayload ( "session_start" , sessionId , cwd , {
8498 plugin_version : PLUGIN_VERSION ,
8599 } )
@@ -90,17 +104,10 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
90104 case "session.idle" : {
91105 const sessionId = event . properties . sessionID
92106
93- if ( sessionId ) {
94- try {
95- const session = await client . session . get ( {
96- path : { id : sessionId } ,
97- } )
98- if ( session . data ?. parentID ) return
99- } catch {
100- // If we can't fetch the session, fall through and notify anyway
101- }
102- }
107+ if ( await isSubagentSession ( sessionId ) ) return
103108
109+ // Fetch the conversation to extract last query and response
110+ // (port of on-stop.sh transcript parsing)
104111 let query = ""
105112 let response = ""
106113
@@ -143,13 +150,15 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
143150 }
144151
145152 case "permission.updated" : {
153+ if ( await isSubagentSession ( event . properties . sessionID ) ) return
146154 sendPermissionNotification ( event . properties , cwd )
147155 return
148156 }
149157
150158 case "permission.replied" : {
151159 const { sessionID, response } = event . properties
152160 if ( response === "reject" ) return
161+ if ( await isSubagentSession ( sessionID ) ) return
153162 const body = buildPayload ( "permission_replied" , sessionID , cwd )
154163 warpNotify ( NOTIFICATION_TITLE , body )
155164 return
@@ -159,6 +168,7 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
159168 // permission.asked is listed in the opencode docs but has no SDK type.
160169 // Handle it with the same logic as permission.updated.
161170 if ( ( event as any ) . type === "permission.asked" ) {
171+ if ( await isSubagentSession ( ( event as any ) . properties ?. sessionID ) ) return
162172 sendPermissionNotification ( ( event as any ) . properties , cwd )
163173 }
164174 }
@@ -171,6 +181,8 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
171181 // completion notification.)
172182 "chat.message" : async ( input , output ) => {
173183 const cwd = directory || ""
184+ if ( await isSubagentSession ( input . sessionID ) ) return
185+
174186 const queryText = extractTextFromParts ( output . parts )
175187 if ( ! queryText ) return
176188
@@ -184,6 +196,7 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
184196 // "question" tool so Warp can notify the user that input is needed.
185197 "tool.execute.before" : async ( input ) => {
186198 if ( input . tool !== "question" ) return
199+ if ( await isSubagentSession ( input . sessionID ) ) return
187200
188201 const cwd = directory || ""
189202 const body = buildPayload ( "question_asked" , input . sessionID , cwd , {
@@ -198,6 +211,8 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
198211 const sessionId = input . sessionID
199212 const cwd = directory || ""
200213
214+ if ( await isSubagentSession ( sessionId ) ) return
215+
201216 const body = buildPayload ( "tool_complete" , sessionId , cwd , {
202217 tool_name : toolName ,
203218 } )
0 commit comments