@@ -3,7 +3,7 @@ import type { Hooks, Plugin } from "@opencode-ai/plugin";
33
44type OpenCodeEvent = Parameters < NonNullable < Hooks [ "event" ] > > [ 0 ] [ "event" ] ;
55
6- const REQUIRED_EVENTS = new Set ( [ "session.diff " ] ) ;
6+ const REQUIRED_EVENTS = new Set ( [ "message.updated " ] ) ;
77
88const ALL_CAPTURED_EVENTS = REQUIRED_EVENTS ;
99
@@ -15,13 +15,14 @@ type DiffTracePayload = {
1515 sessionID : string ;
1616 diff : string ;
1717 time : number ;
18+ model_id : string ;
1819} ;
1920
2021function extractDiffTracePayload (
2122 input : TraceInput ,
2223) : DiffTracePayload | undefined {
2324 const event = input . event ;
24- if ( event === undefined || event . type !== "session.diff " ) {
25+ if ( event === undefined || event . type !== "message.updated " ) {
2526 return undefined ;
2627 }
2728
@@ -30,15 +31,36 @@ function extractDiffTracePayload(
3031 return undefined ;
3132 }
3233
33- const propertiesObj = properties as Record < string , unknown > ;
34+ const propertiesObj = properties ;
35+
36+ // Access properties.info (the Message object)
37+ const info = propertiesObj . info ;
38+ if ( typeof info !== "object" || info === null ) {
39+ return undefined ;
40+ }
41+
42+ const infoObj = info ;
43+
44+ // Only capture user messages (filter out assistant, system, etc.)
45+ if ( infoObj . role !== "user" ) {
46+ return undefined ;
47+ }
3448
3549 const sessionID =
36- typeof propertiesObj . sessionID === "string" &&
37- propertiesObj . sessionID . trim ( ) . length > 0
38- ? propertiesObj . sessionID
50+ typeof infoObj . sessionID === "string" &&
51+ infoObj . sessionID . trim ( ) . length > 0
52+ ? infoObj . sessionID
3953 : "unknown" ;
4054
41- const diffEntries = propertiesObj . diff ;
55+ const model = infoObj . model ;
56+
57+ // Access info.summary?.diffs via explicit checks
58+ const summary = infoObj . summary ;
59+ const diffEntries =
60+ typeof summary === "object" && summary !== null
61+ ? ( summary ) . diffs
62+ : undefined ;
63+
4264 if ( ! Array . isArray ( diffEntries ) || diffEntries . length === 0 ) {
4365 return undefined ;
4466 }
@@ -48,16 +70,10 @@ function extractDiffTracePayload(
4870 if ( typeof entry !== "object" || entry === null ) {
4971 continue ;
5072 }
51- const entryObj = entry as Record < string , unknown > ;
52- const patch =
53- typeof entryObj . patch === "string"
54- ? entryObj . patch
55- : typeof entryObj . diff === "string"
56- ? entryObj . diff
57- : undefined ;
58- if ( patch !== undefined && patch . trim ( ) . length > 0 ) {
59- patches . push ( patch ) ;
60- }
73+ const entryObj = entry as { patch ?:string } ;
74+ const patch = entryObj . patch || "" ;
75+
76+ patches . push ( patch ) ;
6177 }
6278
6379 if ( patches . length === 0 ) {
@@ -68,6 +84,7 @@ function extractDiffTracePayload(
6884 sessionID,
6985 diff : patches . join ( "\n" ) ,
7086 time : Date . now ( ) ,
87+ model_id : `${ model . providerID } /${ model . modelID } ` ,
7188 } ;
7289}
7390
0 commit comments