diff --git a/crates/ide-agent/src/lib.rs b/crates/ide-agent/src/lib.rs index e700e9cf2..21c132053 100644 --- a/crates/ide-agent/src/lib.rs +++ b/crates/ide-agent/src/lib.rs @@ -5105,7 +5105,8 @@ fn tool_event( i: usize, entry: &AgentEntry, ) -> Option { - let AgentEntry::Tool { id, title, kind, status, locations, images, output, diffs, started_ms, ended_ms } = entry + let AgentEntry::Tool { id, title, kind, status, locations, images, output, diffs, started_ms, ended_ms, command } = + entry else { return None; }; @@ -5120,6 +5121,7 @@ fn tool_event( diffs: diffs.clone(), started_ms: *started_ms, ended_ms: *ended_ms, + command: command.clone(), }; let text = output.as_deref().unwrap_or_default(); let key = (subagent, i); diff --git a/crates/ide-agent/src/model.rs b/crates/ide-agent/src/model.rs index 59477786a..3e3ed9bb6 100644 --- a/crates/ide-agent/src/model.rs +++ b/crates/ide-agent/src/model.rs @@ -547,6 +547,9 @@ pub enum AgentEntry { started_ms: Option, #[serde(default)] ended_ms: Option, + /// The command an `execute` call runs, from its structured input; `None` when the agent gave none. + #[serde(default)] + command: Option, }, Plan { items: Vec, diff --git a/crates/ide-agent/src/security.rs b/crates/ide-agent/src/security.rs index f1f953d91..62f7d1b83 100644 --- a/crates/ide-agent/src/security.rs +++ b/crates/ide-agent/src/security.rs @@ -32,7 +32,7 @@ pub fn widens_access(params: &Value) -> bool { tool.and_then(|t| t.pointer("/rawInput/networkApprovalContext")).is_some_and(|c| !c.is_null()) } -fn command_from_value(val: &Value) -> Option { +pub(crate) fn command_from_value(val: &Value) -> Option { match val { Value::String(s) => { let trimmed = s.trim(); diff --git a/crates/ide-agent/src/tests.rs b/crates/ide-agent/src/tests.rs index dac9d4998..7f84242b7 100644 --- a/crates/ide-agent/src/tests.rs +++ b/crates/ide-agent/src/tests.rs @@ -4369,6 +4369,7 @@ fn a_running_tools_output_is_sent_as_appends() { diffs: Vec::new(), started_ms: Some(1.0), ended_ms: None, + command: None, }; let running = |output| call(AgentToolStatus::Running, output); let event = |streamed: &mut Streamed, session: Session, i, entry: &AgentEntry| { diff --git a/crates/ide-agent/src/timeline.rs b/crates/ide-agent/src/timeline.rs index f5d09bc26..e4579790f 100644 --- a/crates/ide-agent/src/timeline.rs +++ b/crates/ide-agent/src/timeline.rs @@ -91,6 +91,7 @@ impl Timeline { diffs: Vec::new(), started_ms: Some(crate::now_ms()), ended_ms: None, + command: None, }; let index = match self.tools.get(&id) { Some(&i) => { @@ -154,7 +155,7 @@ impl Timeline { } fn merge_tool(&mut self, index: usize, update: &Value) { - let AgentEntry::Tool { title, kind, status, locations: locs, output, images, diffs, ended_ms, .. } = + let AgentEntry::Tool { title, kind, status, locations: locs, output, images, diffs, ended_ms, command, .. } = &mut self.entries[index] else { return; @@ -171,6 +172,11 @@ impl Timeline { *ended_ms = Some(crate::now_ms()); } } + if let Some(raw) = update.pointer("/rawInput/command").or_else(|| update.pointer("/rawInput/cmd")) + && let Some(cmd) = crate::security::command_from_value(raw) + { + *command = Some(crate::shell_script(&cmd).unwrap_or(cmd)); + } if update.get("locations").is_some_and(Value::is_array) { *locs = locations(update.get("locations")); } @@ -471,6 +477,34 @@ mod tests { assert!(matches!(&t.entries[0], AgentEntry::Question { chosen: Some(answer), .. } if answer == "One")); } + #[test] + fn an_execute_call_keeps_the_command_from_its_structured_input() { + let mut t = Timeline::default(); + let command = |t: &Timeline, i: usize| match &t.entries[i] { + AgentEntry::Tool { command, .. } => command.clone(), + _ => panic!(), + }; + t.apply(&json!({"sessionUpdate": "tool_call", "toolCallId": "a", "title": "Run command", "kind": "execute", + "rawInput": {"command": "python hello_world.py"}})); + assert_eq!(command(&t, 0).as_deref(), Some("python hello_world.py")); + // An argv array whose shell wraps the script, sent with a later update. + t.apply(&json!({"sessionUpdate": "tool_call", "toolCallId": "b", "title": "Run command", "kind": "execute"})); + assert_eq!(command(&t, 1), None); + t.apply(&json!({"sessionUpdate": "tool_call_update", "toolCallId": "b", + "rawInput": {"cmd": ["bash", "-lc", "cargo test -p ide-agent"]}})); + assert_eq!(command(&t, 1).as_deref(), Some("cargo test -p ide-agent")); + // One shell line, unwrapped as the permission card does. + t.apply(&json!({"sessionUpdate": "tool_call", "toolCallId": "c", "kind": "execute", + "rawInput": {"command": "/bin/zsh -lc 'node hello.js'"}})); + assert_eq!(command(&t, 2).as_deref(), Some("node hello.js")); + // A later update without one keeps it; tasks saved before the field load without it. + t.apply(&json!({"sessionUpdate": "tool_call_update", "toolCallId": "c", "status": "completed"})); + assert_eq!(command(&t, 2).as_deref(), Some("node hello.js")); + let mut old = serde_json::to_value(&t.entries[2]).unwrap(); + old.as_object_mut().unwrap().remove("command"); + assert!(matches!(serde_json::from_value(old).unwrap(), AgentEntry::Tool { command: None, .. })); + } + #[test] fn tool_images_survive_updates_text_truncation_and_serialization() { use base64::Engine; diff --git a/src/bindings.ts b/src/bindings.ts index e01d2a729..e09adeedb 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -2799,7 +2799,9 @@ images?: AgentImage[]; /** Text the tool reported (command output…), truncated. */ output: string | null; diffs: AgentToolDiff[]; /** When the call started and ended (ms since the epoch); `None` in tasks saved before. */ -startedMs?: number | null; endedMs?: number | null } | { type: "plan"; items: AgentPlanItem[] } | +startedMs?: number | null; endedMs?: number | null; +/** The command an `execute` call runs, from its structured input; `None` when the agent gave none. */ +command?: string | null } | { type: "plan"; items: AgentPlanItem[] } | /** A subagent the agent started: its own session, whose entries are listed separately. */ { type: "subagent"; /** The subagent's session id. */ diff --git a/src/features/agents/session/toolEntries.tsx b/src/features/agents/session/toolEntries.tsx index 0d7238731..0e02ff83a 100644 --- a/src/features/agents/session/toolEntries.tsx +++ b/src/features/agents/session/toolEntries.tsx @@ -105,9 +105,12 @@ export const ToolEntry = memo(function ToolEntry({ const took = toolDuration(entry); const run = entry.kind === "execute" ? toolRun(entry) : null; // Commands lose the `cd &&` agents start them with; another folder shows as a tag. + // The structured command, when the agent sent one, names what ran better than a generic title ("Run command"). + const commandText = entry.kind === "execute" ? entry.command?.trim() || run?.command || null : null; + const fullTitle = commandText ?? (entry.title || entry.kind); const { title, dir } = entry.kind === "execute" - ? commandTitle(task, entry.title || entry.kind) + ? commandTitle(task, fullTitle) : { title: shortTitle(task, entry.title || entry.kind), dir: null }; // A title that already names the file ("Read pom.xml") needs no second link to it. const links = @@ -120,7 +123,7 @@ export const ToolEntry = memo(function ToolEntry({ {basename(dir)} )} - + {title} {links.map((path) => ( @@ -194,12 +197,12 @@ export const ToolEntry = memo(function ToolEntry({ } > - {run?.command ? ( + {commandText ? (
-              $ {run.command}
+              $ {commandText}
             
- {run.output &&
{run.output}
} + {run?.output &&
{run.output}
}
) : (
{entry.output}