@@ -89,7 +89,8 @@ func opencodeEndpointEvents(input map[string]interface{}, sessionID string) []op
8989 action , category = "tool.completed" , "tool"
9090 }
9191 }
92- return one (action , category , "info" , opencodeToolMessage (action ), fields )
92+ events := one (action , category , "info" , opencodeToolMessage (action ), fields )
93+ return append (events , opencodeFileMutationEvents (input , fields )... )
9394 case "message.updated" :
9495 info := opencodeMap (input , "message_info" , "info" )
9596 if len (info ) == 0 {
@@ -622,6 +623,41 @@ func opencodeDiffEvents(input map[string]interface{}, base map[string]interface{
622623 return events
623624}
624625
626+ func opencodeFileMutationEvents (input map [string ]interface {}, base map [string ]interface {}) []opencodeNormalizedEvent {
627+ command , _ := base ["command" ].(map [string ]interface {})
628+ if exitCode , ok := opencodeInt (command ["exit_code" ]); ok && exitCode != 0 {
629+ return nil
630+ }
631+ items , _ := input ["file_mutations" ].([]interface {})
632+ if len (items ) == 0 {
633+ return nil
634+ }
635+ var events []opencodeNormalizedEvent
636+ for _ , item := range items {
637+ mutation , ok := item .(map [string ]interface {})
638+ if ! ok {
639+ continue
640+ }
641+ path := getFirstStr (mutation , "path" , "file" , "filePath" , "file_path" )
642+ operation := firstNonEmpty (getFirstStr (mutation , "operation" ), "modify" )
643+ if path == "" {
644+ continue
645+ }
646+ fields := cloneOpenCodeFields (base )
647+ delete (fields , "command" )
648+ fields ["file" ] = map [string ]interface {}{
649+ "path" : path ,
650+ "operation" : operation ,
651+ "language" : strings .TrimPrefix (filepath .Ext (path ), "." ),
652+ }
653+ events = append (events , opencodeNormalizedEvent {
654+ action : "file.modified" , category : "file" , severity : "info" ,
655+ message : "opencode file " + operation + " observed" , fields : fields ,
656+ })
657+ }
658+ return events
659+ }
660+
625661func opencodeApprovalAction (decision string ) string {
626662 switch strings .ToLower (strings .TrimSpace (decision )) {
627663 case "once" , "always" , "accepted" , "accept" , "allow" , "allowed" , "approve" , "approved" :
0 commit comments