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 file_editor command stored as shell command in shared tool-field extraction
Cursor Agent358bae89dfdf
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.goindex 4885135c..61750522 100644--- a/cli/beacon-hooks/cmd/endpoint_events.go+++ b/cli/beacon-hooks/cmd/endpoint_events.go@@ -277,8 +277,14 @@ func toolFieldsWithResponse(toolName string, toolInput, toolResponse map[string]fields["tool"] = map[string]interface{}{"name": toolName}}if command := firstToolString(toolInput, "command", "cmd", "shell_command", "CommandLine", "commandLine"); command != "" {- fields["command"] = map[string]interface{}{"command": command}- fields["tool"] = mergeNested(fields["tool"], map[string]interface{}{"name": toolName, "command": 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.+ // Promoting it into command.command would store an editor operation as shell execution and+ // let the policy seam upgrade tool.invoked to command.executed.+ if !(platformFlag == openHandsPlatform && openHandsFileEditorTools[strings.ToLower(strings.TrimSpace(toolName))]) {+ fields["command"] = map[string]interface{}{"command": command}+ fields["tool"] = mergeNested(fields["tool"], map[string]interface{}{"name": toolName, "command": command})+ }}// `absolute_path` and `notebook_path` are the snake_case siblings of `AbsolutePath` already in// this list: the first is Gemini CLI's (and so early Qwen Code's) `read_file` parameter, thediff --git a/cli/beacon-hooks/cmd/openhands_hooks_test.go b/cli/beacon-hooks/cmd/openhands_hooks_test.goindex 10dbdd67..4d865b23 100644--- a/cli/beacon-hooks/cmd/openhands_hooks_test.go+++ b/cli/beacon-hooks/cmd/openhands_hooks_test.go@@ -249,6 +249,58 @@ func TestOpenHandsPreToolObservesWithoutSynthesizingAnApproval(t *testing.T) {}}+// file_editor's `command` argument (view, str_replace, create) is the editor operation, not a+// shell command. Promoting it into command.command would store an editor operation as shell+// execution and let the policy seam upgrade tool.invoked to command.executed.+func TestOpenHandsPreToolFileEditorDoesNotCarryAShellCommandBlock(t *testing.T) {+ logPath := openHandsTestSetup(t)++ runHookWithInput(t, runPreTool, map[string]interface{}{+ "event_type": "PreToolUse",+ "session_id": "oh-session-1",+ "working_dir": "/workspace/project",+ "tool_name": "file_editor",+ "tool_input": map[string]interface{}{+ "kind": "FileEditorAction", "command": "view", "path": "/workspace/project/main.go",+ },+ "metadata": map[string]interface{}{},+ })++ event := lastEndpointEvent(t, logPath)+ if got := leaf(event, "event", "action"); got != "tool.invoked" {+ t.Fatalf("event.action = %q, want tool.invoked", got)+ }+ if got := leaf(event, "command", "command"); got != "" {+ t.Fatalf("command.command = %q, want empty -- the editor operation is not a shell command", got)+ }+}++// The policy seam must not reclassify a file_editor call as command.executed. The upgrade from+// tool.invoked to command.executed fires when fields carry a command block, so the fix is to not+// set that block for editor tools whose `command` argument names an operation, not a shell command.+func TestOpenHandsPolicyCandidateDoesNotUpgradeFileEditorToCommand(t *testing.T) {+ origPlatform := platformFlag+ t.Cleanup(func() { platformFlag = origPlatform })+ platformFlag = openHandsPlatform++ input := map[string]interface{}{+ "event_type": "PreToolUse",+ "session_id": "oh-session-1",+ "working_dir": "/workspace/project",+ "tool_name": "file_editor",+ "tool_input": map[string]interface{}{+ "kind": "FileEditorAction", "command": "view", "path": "/workspace/project/main.go",+ },+ }+ candidate := newPolicyCandidate(input, "oh-session-1")+ if candidate.action == "command.executed" {+ t.Fatalf("policy candidate action = command.executed; file_editor view is not a shell command")+ }+ if _, ok := candidate.fields["command"]; ok {+ t.Fatalf("policy candidate carried a command block: %#v", candidate.fields["command"])+ }+}+// ---------------------------------------------------------------------------// Terminal// ---------------------------------------------------------------------------@@ -411,6 +463,9 @@ func TestOpenHandsFileEditorViewIsARead(t *testing.T) {if got := leaf(event, "file", "diff"); got != "" {t.Fatalf("file.diff = %q, want no diff for a read", got)}+ if got := leaf(event, "command", "command"); got != "" {+ t.Fatalf("command.command = %q, want empty -- the editor operation is not a shell command", got)+ }}func TestOpenHandsFileEditorEditRecordsAnExactDiff(t *testing.T) {@@ -451,6 +506,9 @@ func TestOpenHandsFileEditorEditRecordsAnExactDiff(t *testing.T) {if got := leaf(event, "harness", "name"); got != "openhands" {t.Fatalf("harness.name = %q, want openhands", got)}+ if got := leaf(event, "command", "command"); got != "" {+ t.Fatalf("command.command = %q, want empty -- str_replace is an editor operation, not a shell command", got)+ }}func TestOpenHandsFileEditorCreateRecordsANewFileDiff(t *testing.T) {