Skip to content

Commit 08f109e

Browse files
fix: classify OpenCode search tools as reads
Co-authored-by: Shukan Shah <shukanshah14@gmail.com>
1 parent 18c0b08 commit 08f109e

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

cli/beacon-hooks/cmd/opencode_event.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,16 @@ func opencodeToolFields(input map[string]interface{}, completed bool) map[string
317317
}
318318

319319
if path := opencodeToolPath(toolInput); path != "" {
320+
operation := fileOperation(toolName)
321+
if operation == "" {
322+
lower := strings.ToLower(toolName)
323+
if strings.Contains(lower, "glob") || strings.Contains(lower, "grep") || strings.Contains(lower, "search") {
324+
operation = "read"
325+
}
326+
}
320327
fields["file"] = map[string]interface{}{
321328
"path": path,
322-
"operation": fileOperation(toolName),
329+
"operation": operation,
323330
"language": strings.TrimPrefix(filepath.Ext(path), "."),
324331
}
325332
fields["tool"] = mergeNested(fields["tool"], map[string]interface{}{"name": toolName, "path": path})
@@ -398,12 +405,14 @@ func opencodeDecision(input map[string]interface{}) string {
398405

399406
func opencodeToolAction(input map[string]interface{}) (string, string) {
400407
name := strings.ToLower(opencodeToolName(input))
408+
toolInput := opencodeMap(input, "tool_input", "toolInput")
401409
switch {
402410
case strings.Contains(name, "mcp") || strings.HasPrefix(name, "list_mcp_") || strings.HasPrefix(name, "read_mcp_"):
403411
return "mcp.tool_invoked", "mcp"
404412
case name == "bash" || strings.Contains(name, "shell") || strings.Contains(name, "terminal"):
405413
return "command.executed", "command"
406-
case strings.Contains(name, "read"):
414+
case strings.Contains(name, "read") ||
415+
((strings.Contains(name, "glob") || strings.Contains(name, "grep") || strings.Contains(name, "search")) && opencodeToolPath(toolInput) != ""):
407416
return "file.read", "file"
408417
case strings.Contains(name, "edit") || strings.Contains(name, "write") || strings.Contains(name, "patch"):
409418
return "file.modified", "file"

cli/beacon-hooks/cmd/opencode_event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func TestOpenCodeTidyPlanetTraceReplay(t *testing.T) {
377377
want := []string{
378378
"prompt.submitted", "prompt.submitted",
379379
"tool.invoked", "file.read",
380-
"tool.invoked", "tool.completed",
380+
"tool.invoked", "file.read",
381381
"prompt.submitted", "tool.invoked", "tool.completed",
382382
"prompt.submitted", "tool.invoked", "file.modified",
383383
"prompt.submitted", "tool.invoked", "command.executed",

0 commit comments

Comments
 (0)