@@ -113,20 +113,22 @@ func opencodeEndpointEvents(input map[string]interface{}, sessionID string) []op
113113 return opencodePartEvents (fields , part )
114114 case "session.created" :
115115 return one ("session.started" , "session" , "info" , "opencode session started" , fields )
116+ case "session.deleted" :
117+ return one ("session.ended" , "session" , "info" , "opencode session deleted" , fields )
116118 case "session.status" :
117119 status := opencodeMap (opencodeProperties (input ), "status" )
118120 statusType := getFirstStr (status , "type" )
119121 switch statusType {
120122 case "idle" :
121- return one ("session.ended " , "session" , "info" , "opencode session idle" , fields )
123+ return one ("session.status " , "session" , "info" , "opencode session idle" , fields )
122124 case "retry" :
123125 fields ["error" ] = map [string ]interface {}{"type" : "retry" }
124126 return one ("model.retry" , "session" , "medium" , "opencode model retry" , fields )
125127 default :
126128 return one ("session.status" , "session" , "info" , "opencode session " + firstNonEmpty (statusType , "status updated" ), fields )
127129 }
128130 case "session.idle" :
129- return one ("session.ended " , "session" , "info" , "opencode session ended " , fields )
131+ return one ("session.status " , "session" , "info" , "opencode session idle " , fields )
130132 case "session.error" :
131133 errorInfo := opencodeMap (opencodeProperties (input ), "error" )
132134 if len (errorInfo ) > 0 {
@@ -150,6 +152,15 @@ func opencodeEndpointEvents(input map[string]interface{}, sessionID string) []op
150152 "operation" : operation ,
151153 "language" : strings .TrimPrefix (filepath .Ext (path ), "." ),
152154 }
155+ if callID := getFirstStr (properties , "callID" , "call_id" ); callID != "" {
156+ fields ["gen_ai" ] = map [string ]interface {}{
157+ "operation" : map [string ]interface {}{"name" : "execute_tool" },
158+ "tool" : map [string ]interface {}{
159+ "name" : "file_watcher" ,
160+ "call" : map [string ]interface {}{"id" : callID },
161+ },
162+ }
163+ }
153164 return one ("file.modified" , "file" , "info" , "opencode file change observed" , fields )
154165 case "command.execute.before" :
155166 if command := opencodeCommand (input ); command != "" {
@@ -208,6 +219,7 @@ func supportedOpenCodeEventTypes() []string {
208219 "permission.v2.asked" ,
209220 "permission.v2.replied" ,
210221 "session.created" ,
222+ "session.deleted" ,
211223 "session.diff" ,
212224 "session.error" ,
213225 "session.idle" ,
@@ -319,17 +331,18 @@ func opencodeToolFields(input map[string]interface{}, completed bool) map[string
319331 if path := opencodeToolPath (toolInput ); path != "" {
320332 operation := fileOperation (toolName )
321333 if operation == "" {
322- lower := strings . ToLower ( toolName )
323- if strings . Contains ( lower , "glob" ) || strings . Contains ( lower , "grep" ) || strings . Contains ( lower , "search" ) {
324- operation = "read"
334+ delete ( fields , "file" )
335+ if tool , ok := fields [ "tool" ].( map [ string ] interface {}); ok {
336+ delete ( tool , "path" )
325337 }
338+ } else {
339+ fields ["file" ] = map [string ]interface {}{
340+ "path" : path ,
341+ "operation" : operation ,
342+ "language" : strings .TrimPrefix (filepath .Ext (path ), "." ),
343+ }
344+ fields ["tool" ] = mergeNested (fields ["tool" ], map [string ]interface {}{"name" : toolName , "path" : path })
326345 }
327- fields ["file" ] = map [string ]interface {}{
328- "path" : path ,
329- "operation" : operation ,
330- "language" : strings .TrimPrefix (filepath .Ext (path ), "." ),
331- }
332- fields ["tool" ] = mergeNested (fields ["tool" ], map [string ]interface {}{"name" : toolName , "path" : path })
333346 }
334347
335348 if completed {
@@ -355,7 +368,7 @@ func opencodeToolFields(input map[string]interface{}, completed bool) map[string
355368 commandFields ["duration_ms" ] = duration
356369 }
357370 if metadata := opencodeMap (toolResponse , "metadata" ); len (metadata ) > 0 {
358- if exitCode , ok := firstToolIntAcross ([]map [string ]interface {}{metadata }, "exit_code" , "exitCode" , "status" ); ok {
371+ if exitCode , ok := firstToolIntAcross ([]map [string ]interface {}{metadata }, "exit" , " exit_code" , "exitCode" , "status" ); ok {
359372 commandFields ["exit_code" ] = exitCode
360373 }
361374 }
@@ -405,14 +418,12 @@ func opencodeDecision(input map[string]interface{}) string {
405418
406419func opencodeToolAction (input map [string ]interface {}) (string , string ) {
407420 name := strings .ToLower (opencodeToolName (input ))
408- toolInput := opencodeMap (input , "tool_input" , "toolInput" )
409421 switch {
410422 case strings .Contains (name , "mcp" ) || strings .HasPrefix (name , "list_mcp_" ) || strings .HasPrefix (name , "read_mcp_" ):
411423 return "mcp.tool_invoked" , "mcp"
412424 case name == "bash" || strings .Contains (name , "shell" ) || strings .Contains (name , "terminal" ):
413425 return "command.executed" , "command"
414- case strings .Contains (name , "read" ) ||
415- ((strings .Contains (name , "glob" ) || strings .Contains (name , "grep" ) || strings .Contains (name , "search" )) && opencodeToolPath (toolInput ) != "" ):
426+ case strings .Contains (name , "read" ):
416427 return "file.read" , "file"
417428 case strings .Contains (name , "edit" ) || strings .Contains (name , "write" ) || strings .Contains (name , "patch" ):
418429 return "file.modified" , "file"
@@ -437,11 +448,7 @@ func opencodeToolMessage(action string) string {
437448}
438449
439450func opencodeToolPath (input map [string ]interface {}) string {
440- path := firstToolString (input , "file_path" , "filePath" , "path" , "target" , "destination" )
441- if path == "" {
442- path = firstToolString (input , "pattern" )
443- }
444- return hookdiff .NormalizePath (path )
451+ return hookdiff .NormalizePath (firstToolString (input , "file_path" , "filePath" , "path" , "target" , "destination" ))
445452}
446453
447454func opencodeAssistantFields (info map [string ]interface {}) map [string ]interface {} {
0 commit comments