The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(telemetry): read the command of codex shell and shell_command tool results (#1071)
Rudy Mizrahi Celeklif001a241445f
diff --git a/cli/beacon-hooks/cmd/cline_event.go b/cli/beacon-hooks/cmd/cline_event.goindex aba25d2d..30519854 100644--- a/cli/beacon-hooks/cmd/cline_event.go+++ b/cli/beacon-hooks/cmd/cline_event.go@@ -664,7 +664,7 @@ func clineDiffFields(toolName string, toolInput, toolResponse map[string]interfa}func clineCommandFields(input, toolInput, toolResponse map[string]interface{}) map[string]interface{} {- fields := map[string]interface{}{"command": firstToolString(toolInput, "command", "cmd")}+ fields := map[string]interface{}{"command": normalizeToolString(asymptoteobserve.ToolCommandLine("", toolInput))}if output := firstToolString(toolResponse, "output", "stdout", "text", "result"); output != "" {fields["output"] = output}diff --git a/cli/beacon-hooks/cmd/dsh.go b/cli/beacon-hooks/cmd/dsh.goindex 689cd623..6cf882e3 100644--- a/cli/beacon-hooks/cmd/dsh.go+++ b/cli/beacon-hooks/cmd/dsh.go@@ -323,30 +323,6 @@ func dshEffectiveToolKind(toolName string, toolInput map[string]interface{}) (dsreturn kind, true}-// dshTerminalCommand reads the command line a `terminal_send` call submitted, or "" for any other-// tool.-//-// dsh's persistent terminal names its payload `text`, not `command`, so every key in the shared-// reader's list misses it and a command run through a terminal session would be recorded as a-// command event with no command in it -- invisible to every rule that matches on command.command,-// which is most of them.-//-// A call with `submit: false` is still read. It carries control characters or an incomplete REPL-// line rather than a whole command, so what is recorded is a fragment of shell input; that is worth-// stating and is worse than nothing only if a reader assumes the field is always complete.-// `submit` itself rides along under gen_ai.tool.call.arguments, so the distinction is recoverable.-// The alternative -- dropping those calls -- would make the escape hatch of sending a command in-// two writes a way to run commands Beacon does not record.-//-// Guarded on the tool name rather than on the key: `text` is an ordinary argument name that other-// tools use for other things, which is exactly why it is not in the shared key list.-func dshTerminalCommand(toolName string, toolInput map[string]interface{}) string {- if strings.ToLower(strings.TrimSpace(toolName)) != "terminal_send" {- return ""- }- return firstToolString(toolInput, "text")-}-// dshToolAction maps a dsh tool call onto an endpoint event action, or returns "" to let the// generic classifier decide.//diff --git a/cli/beacon-hooks/cmd/dsh_hooks_test.go b/cli/beacon-hooks/cmd/dsh_hooks_test.goindex 9b0c0ff4..462ed4a8 100644--- a/cli/beacon-hooks/cmd/dsh_hooks_test.go+++ b/cli/beacon-hooks/cmd/dsh_hooks_test.go@@ -326,20 +326,6 @@ func TestDshTerminalSendRecordsTheCommandLine(t *testing.T) {}}-// `text` is deliberately not in the shared key list: it is an ordinary argument name other tools-// use for other things. The reader is keyed on the tool name, and must stay that way.-func TestDshTerminalCommandIsScopedToTerminalSend(t *testing.T) {- input := map[string]interface{}{"text": "not a command"}- for _, toolName := range []string{"bash"} {- t.Run(toolName, func(t *testing.T) {- if got := dshTerminalCommand(toolName, input); got != "" {- t.Fatalf("dshTerminalCommand(%q) = %q; only terminal_send names a command `text`",- toolName, got)- }- })- }-}-// ---------------------------------------------------------------------------// Post-tool: the flattened result// ---------------------------------------------------------------------------diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.goindex cbffc568..6f60fca4 100644--- a/cli/beacon-hooks/cmd/endpoint_events.go+++ b/cli/beacon-hooks/cmd/endpoint_events.go@@ -301,16 +301,8 @@ func toolFieldsWithResponse(toolName string, toolInput, toolResponse map[string]if toolName != "" {fields["tool"] = map[string]interface{}{"name": toolName}}- command := firstToolString(toolInput, "command", "cmd", "shell_command", "CommandLine", "commandLine")- // DeepSeek Harness runs commands through a persistent terminal as well as through `bash`, and- // that tool names its command line `text` rather than `command`, so every key above misses it.- // Without this a terminal_send would be classified command.executed -- the dsh taxonomy says so- // -- and carry no command, which is invisible to every rule that matches on command.command.- // Asked after the shared list for the Kiro reason below: a payload carrying a `command` of its- // own has said something more direct.- if command == "" && platformFlag == dshPlatform {- command = dshTerminalCommand(toolName, toolInput)- }+ // normalizeToolString keeps the quote trimming every hook string field gets.+ command := normalizeToolString(asymptoteobserve.ToolCommandLine(toolName, toolInput))if command != "" {// OpenHands file editors multiplex operations onto one tool name via a `command` argument// that names the editor operation (view, str_replace, create), not a shell command.diff --git a/cli/beacon-hooks/cmd/opencode_event.go b/cli/beacon-hooks/cmd/opencode_event.goindex 050bfdca..ffa0b2fd 100644--- a/cli/beacon-hooks/cmd/opencode_event.go+++ b/cli/beacon-hooks/cmd/opencode_event.go@@ -324,7 +324,7 @@ func opencodeToolFields(input map[string]interface{}, completed bool) map[string}}if action, _ := opencodeToolAction(input); action == "command.executed" {- command := firstToolString(toolInput, "command", "cmd")+ command := normalizeToolString(asymptoteobserve.ToolCommandLine(toolName, toolInput))commandFields := map[string]interface{}{"command": command}if output, ok := toolResponse["output"]; ok {commandFields["output"] = outputdiff --git a/cli/beacon/internal/claudesession/mapper.go b/cli/beacon/internal/claudesession/mapper.goindex 06eb70a9..cf15d4b4 100644--- a/cli/beacon/internal/claudesession/mapper.go+++ b/cli/beacon/internal/claudesession/mapper.go@@ -246,7 +246,7 @@ func (m *mapper) emitToolInvoked(record Record, block int, call toolCall) {ev := m.base(record, action, category, schema.SeverityInfo, schema.FidelityObserved, "Claude Code tool invocation observed")ev.Tool = &schema.ToolInfo{Name: call.Name}ev.GenAI = mergeGenAI(ev.GenAI, &schema.GenAIInfo{Tool: &schema.GenAIToolInfo{Name: call.Name, Call: &schema.GenAIToolCallInfo{ID: call.ID, Arguments: call.Input}}})- if command := commandFromTool(call); command != "" {+ if command := asymptoteobserve.ToolCommandLine(call.Name, call.Input); command != "" {ev.Tool.Command = command}if path := pathFromTool(call); path != "" {@@ -269,10 +269,11 @@ func (m *mapper) emitToolResult(record Record, block int, result map[string]intecontent := toolResultText(result["content"])isError, _ := result["is_error"].(bool)switch {- case isCommandTool(call):+ case asymptoteobserve.IsShellCommandTool(call.Name):+ command := asymptoteobserve.ToolCommandLine(call.Name, call.Input)ev := m.base(record, "command.executed", "command", severityForError(isError), schema.FidelityObserved, "Claude Code command completed")- ev.Command = &schema.CommandInfo{Command: commandFromTool(call), Output: content}- ev.Tool = &schema.ToolInfo{Name: call.Name, Command: commandFromTool(call)}+ ev.Command = &schema.CommandInfo{Command: command, Output: content}+ ev.Tool = &schema.ToolInfo{Name: call.Name, Command: command}ev.GenAI = toolResultGenAI(call, content)m.append(record, "tool.result."+itoa(block), ev)case isFileTool(call):@@ -549,15 +550,6 @@ func toolResultText(value interface{}) string {}}-func isCommandTool(call toolCall) bool {- switch strings.ToLower(call.Name) {- case "bash", "shell", "terminal":- return true- default:- return false- }-}-func isFileTool(call toolCall) bool {switch strings.ToLower(call.Name) {case "read", "write", "edit", "multiedit", "notebookread", "notebookedit":@@ -567,10 +559,6 @@ func isFileTool(call toolCall) bool {}}-func commandFromTool(call toolCall) string {- return firstString(call.Input, "command", "cmd", "shell_command")-}-func pathFromTool(call toolCall) string {return firstString(call.Input, "file_path", "filePath", "path", "notebook_path")}diff --git a/cli/beacon/internal/codexsession/codexsession_test.go b/cli/beacon/internal/codexsession/codexsession_test.goindex b2658aa1..74326d56 100644--- a/cli/beacon/internal/codexsession/codexsession_test.go+++ b/cli/beacon/internal/codexsession/codexsession_test.go@@ -84,6 +84,20 @@ func TestMapCodexTranscriptProducesEndpointEvents(t *testing.T) {}}+// Codex 0.135-0.149 ran commands through shell_command, which names the command line `command`.+func TestMapCodexShellCommandIsACommand(t *testing.T) {+ ref := SessionRef{ID: "sess-1", Path: "/tmp/codex.jsonl", Workspace: "/tmp/repo"}+ mapped := MapSession(ref, decodeFixture(t, []string{+ sessionMetaLine("sess-1", "/tmp/repo"),+ `{"timestamp":"2026-09-19T22:00:03.000Z","type":"response_item","payload":{"type":"function_call","name":"shell_command","arguments":"{\"command\":\"git status\",\"workdir\":\"/tmp/repo\"}","call_id":"call_1"}}`,+ `{"timestamp":"2026-09-19T22:00:04.000Z","type":"response_item","payload":{"type":"function_call_output","call_id":"call_1","output":"clean"}}`,+ }), MapOptions{})+ command := findAction(t, mapped, "command.executed")+ if command.Command == nil || command.Command.Command != "git status" {+ t.Fatalf("command = %+v, want git status", command.Command)+ }+}+func TestCollectOnceUsesCursor(t *testing.T) {dir := t.TempDir()codexDir := filepath.Join(dir, ".codex")diff --git a/cli/beacon/internal/codexsession/mapper.go b/cli/beacon/internal/codexsession/mapper.goindex 82124dd4..da2708af 100644--- a/cli/beacon/internal/codexsession/mapper.go+++ b/cli/beacon/internal/codexsession/mapper.go@@ -385,7 +385,7 @@ func (m *mapper) emitToolResult(record Record, item *ResponseItem) {call.ID = item.CallID}output := toolOutputText(item.Output)- if isCommandTool(call) {+ if asymptoteobserve.IsShellCommandTool(call.Name) {ev := m.base(record, "command.executed", "command", severityForStatus(item.Status), schema.FidelityObserved, "Codex command completed")ev.Command = &schema.CommandInfo{Command: commandFromTool(call), Output: output}ev.Tool = &schema.ToolInfo{Name: call.Name, Command: commandFromTool(call)}@@ -545,7 +545,7 @@ func commandFromTool(call codexToolCall) string {case string:return strings.TrimSpace(v)case map[string]interface{}:- return firstStringOrJoinedArray(v, "command", "cmd", "shell_command")+ return asymptoteobserve.ToolCommandLine(call.Name, v)default:if call.Input == nil {return ""@@ -555,45 +555,6 @@ func commandFromTool(call codexToolCall) string {}}-func firstStringOrJoinedArray(m map[string]interface{}, keys ...string) string {- for _, key := range keys {- val, ok := m[key]- if !ok {- continue- }- switch v := val.(type) {- case string:- if v != "" {- return v- }- case []interface{}:- if s := joinStringSlice(v); s != "" {- return s- }- }- }- return ""-}--func joinStringSlice(arr []interface{}) string {- parts := make([]string, 0, len(arr))- for _, v := range arr {- if s, ok := v.(string); ok {- parts = append(parts, s)- }- }- return strings.TrimSpace(strings.Join(parts, " "))-}--func isCommandTool(call codexToolCall) bool {- switch strings.ToLower(call.Name) {- case "exec", "exec_command", "shell", "bash":- return true- default:- return false- }-}-func toolResultGenAI(call codexToolCall, result string) *schema.GenAIInfo {return &schema.GenAIInfo{Tool: &schema.GenAIToolInfo{Name: call.Name, Call: &schema.GenAIToolCallInfo{ID: call.ID, Arguments: call.Input, Result: result}}}}diff --git a/collector-builder/exporter/beaconjsonexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/exporter_test.goindex 9498ddd7..661c535d 100644--- a/collector-builder/exporter/beaconjsonexporter/exporter_test.go+++ b/collector-builder/exporter/beaconjsonexporter/exporter_test.go@@ -884,6 +884,24 @@ func TestCodexToolResultExtractsShellCommand(t *testing.T) {}}+func TestCodexToolResultExtractsShellCommandArgument(t *testing.T) {+ for _, tc := range []struct{ tool, args, want string }{+ {"shell", `{"command":["bash","-lc","git status"],"workdir":"/tmp"}`, "bash -lc git status"},+ {"shell_command", `{"command":"git status","workdir":"/tmp"}`, "git status"},+ } {+ event := newBeaconEvent("tool.invoked", "tool", "info", "codex_cli", time.Now())+ normalizeCodexToolResult(&event, map[string]interface{}{"tool": tc.tool, "arguments": tc.args})+ if event.Event.Action != "command.executed" || event.Command == nil || event.Command.Command != tc.want {+ t.Errorf("%s: action %q command %#v, want command.executed %q", tc.tool, event.Event.Action, event.Command, tc.want)+ }+ }+ event := newBeaconEvent("tool.invoked", "tool", "info", "codex_cli", time.Now())+ normalizeCodexToolResult(&event, map[string]interface{}{"tool": "deploy__run", "arguments": `{"command":"status"}`})+ if event.Event.Action != "tool.invoked" || event.Command != nil {+ t.Fatalf("non-shell tool with a command argument = %q %#v, want tool.invoked", event.Event.Action, event.Command)+ }+}+func TestConsumeLogsMapsGeminiPrompt(t *testing.T) {exp, path := newTestExporter(t)diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex 1bd45426..e040b066 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -596,24 +596,19 @@ func NormalizeCodexToolResult(event *Event, attrs map[string]interface{}) {event.Message = FirstNonEmpty(toolName, "Codex tool result")}+// codexShellCommand is the command line of a Codex shell tool call, or "" for any other tool, so an+// MCP tool that takes a `command` argument stays a tool call.func codexShellCommand(toolName, args string) string {- if strings.EqualFold(toolName, "shell") {- if cmd := codexArgumentCommand(args); cmd != "" {- return cmd- }- return args+ if !asymptoteobserve.IsShellCommandTool(toolName) {+ return ""}- return codexArgumentCommand(args)-}--func codexArgumentCommand(args string) string {- var payload struct {- Cmd string `json:"cmd"`+ if cmd := asymptoteobserve.ToolCommandLine(toolName, args); cmd != "" {+ return cmd}- if err := json.Unmarshal([]byte(args), &payload); err != nil {- return ""+ if strings.EqualFold(toolName, "shell") {+ return args}- return strings.TrimSpace(payload.Cmd)+ return ""}func isClaudeOTelLogHarness(name string) bool {diff --git a/pkg/asymptoteobserve/toolcommand.go b/pkg/asymptoteobserve/toolcommand.gonew file mode 100644index 00000000..c99180bd--- /dev/null+++ b/pkg/asymptoteobserve/toolcommand.go@@ -0,0 +1,91 @@+package asymptoteobserve++import (+ "encoding/json"+ "strings"+)++// shellCommandToolNames are the tools whose call runs a shell command line, normalized by+// normalizeToolName: Claude Code's Bash and PowerShell, Codex CLI's exec_command, shell_command,+// shell and local_shell, DeepSeek Harness's terminal_send, and the shell tools of the other+// supported runtimes.+var shellCommandToolNames = []string{+ "bash", "shell", "shellcommand", "execcommand", "exec", "localshell", "runterminalcmd",+ "runterminalcommand", "runcommand", "runshellcommand", "executebash", "executecommand", "terminal",+ "command", "cmd", "terminalsend", "powershell",+}++var shellCommandTools = func() map[string]bool {+ out := make(map[string]bool, len(shellCommandToolNames))+ for _, name := range shellCommandToolNames {+ out[name] = true+ }+ return out+}()++// IsShellCommandTool reports whether a tool's call runs a shell command line. MCP tools never do:+// their namespaced names (mcp__server__tool) are not in the set.+func IsShellCommandTool(toolName string) bool {+ return shellCommandTools[normalizeToolName(toolName)]+}++// toolCommandLineKeys are the argument names runtimes give a shell command line: `command` (Claude+// Code, Codex shell_command and shell, most others), `cmd` (Codex exec_command), `shell_command`,+// and Antigravity's `CommandLine`.+var toolCommandLineKeys = []string{"command", "cmd", "shell_command", "CommandLine", "commandLine"}++// ToolCommandLine returns the command line in a tool call's arguments, or "". args is the decoded+// argument object or its JSON text. A string value is the command line; an argv array (Codex's+// shell tool) is joined with spaces.+//+// It does not decide whether the tool is a shell: callers that classify a call as a command check+// IsShellCommandTool, and callers that keep the argument for any tool apply their own runtime's+// guards (an editor tool whose `command` names an edit operation, for one). The single name it does+// read is terminal_send, DeepSeek Harness's persistent terminal, which names its command line `text`+// -- an ordinary argument name other tools use for other things.+func ToolCommandLine(toolName string, args interface{}) string {+ input := commandArgs(args)+ if input == nil {+ return ""+ }+ for _, key := range toolCommandLineKeys {+ if command := commandLineValue(input[key]); command != "" {+ return command+ }+ }+ if normalizeToolName(toolName) == "terminalsend" {+ return commandLineValue(input["text"])+ }+ return ""+}++func commandArgs(args interface{}) map[string]interface{} {+ switch typed := args.(type) {+ case map[string]interface{}:+ return typed+ case string:+ var out map[string]interface{}+ if json.Unmarshal([]byte(typed), &out) == nil {+ return out+ }+ }+ return nil+}++func commandLineValue(value interface{}) string {+ switch typed := value.(type) {+ case string:+ return strings.TrimSpace(typed)+ case []string:+ return strings.TrimSpace(strings.Join(typed, " "))+ case []interface{}:+ parts := make([]string, 0, len(typed))+ for _, part := range typed {+ if s, ok := part.(string); ok {+ parts = append(parts, s)+ }+ }+ return strings.TrimSpace(strings.Join(parts, " "))+ }+ return ""+}diff --git a/pkg/asymptoteobserve/toolcommand_test.go b/pkg/asymptoteobserve/toolcommand_test.gonew file mode 100644index 00000000..44c52899--- /dev/null+++ b/pkg/asymptoteobserve/toolcommand_test.go@@ -0,0 +1,32 @@+package asymptoteobserve++import "testing"++func TestShellCommandToolAndCommandLine(t *testing.T) {+ for _, tc := range []struct {+ name, tool string+ args interface{}+ shell bool+ want string+ }{+ {"codex exec_command", "exec_command", `{"cmd":"go test ./...","workdir":"/repo"}`, true, "go test ./..."},+ {"codex shell argv", "shell", `{"command":["bash","-lc","git status"],"workdir":"/repo"}`, true, "bash -lc git status"},+ {"codex shell_command", "shell_command", `{"command":"git status","workdir":"/repo"}`, true, "git status"},+ {"claude Bash", "Bash", map[string]interface{}{"command": "npm test", "description": "run"}, true, "npm test"},+ {"antigravity run_command", "run_command", map[string]interface{}{"CommandLine": "npm test", "Cwd": "/repo"}, true, "npm test"},+ {"dsh terminal_send", "terminal_send", map[string]interface{}{"sessionId": "t1", "text": "ls -la", "submit": true}, true, "ls -la"},+ // `text` is an ordinary argument name; only terminal_send names its command line that way.+ {"text on another tool", "bash", map[string]interface{}{"text": "not a command"}, true, ""},+ // The argument is read for any tool; the editor guard that drops it is the caller's.+ {"str_replace_editor", "str_replace_editor", map[string]interface{}{"command": "view", "path": "/repo/a.go"}, false, "view"},+ {"mcp tool with a command argument", "mcp__deploy__run", `{"command":"status"}`, false, "status"},+ {"not json", "shell", "not json", true, ""},+ } {+ if got := IsShellCommandTool(tc.tool); got != tc.shell {+ t.Errorf("%s: IsShellCommandTool(%q) = %v, want %v", tc.name, tc.tool, got, tc.shell)+ }+ if got := ToolCommandLine(tc.tool, tc.args); got != tc.want {+ t.Errorf("%s: ToolCommandLine = %q, want %q", tc.name, got, tc.want)+ }+ }+}diff --git a/pkg/asymptoteobserve/tracemessages.go b/pkg/asymptoteobserve/tracemessages.goindex 39b0c6b0..b3fe5ab9 100644--- a/pkg/asymptoteobserve/tracemessages.go+++ b/pkg/asymptoteobserve/tracemessages.go@@ -978,11 +978,8 @@ func normalizeToolName(name string) string {// Harness, Grok Build and fx spellings.var traceToolKindsByName = func() map[string]string {table := map[string][]string{- TraceToolKindTerminalCommand: {- "bash", "shell", "execcommand", "exec", "localshell", "runterminalcmd", "runterminalcommand",- "runcommand", "runshellcommand", "executebash", "executecommand", "terminal", "command",- "bashoutput", "killshell", "killbash", "terminalsend", "ipython", "powershell", "cmd",- },+ // The shell tools, plus the tools that drive a shell without running a command line.+ TraceToolKindTerminalCommand: append([]string{"bashoutput", "killshell", "killbash", "ipython"}, shellCommandToolNames...),TraceToolKindRead: {"read", "view", "readfile", "viewfile", "cat", "notebookread", "readmanyfiles", "openfile","fsread", "readimage",