feat(agents): show the command a tool call ran in the session UI (#6429)

A command tool call showed only the agent's own title ("Run command"). The timeline now keeps the command from the call's structured input (rawInput.command / rawInput.cmd, a string or an argv array, <shell> -c <script> unwrapped), and the session UI uses it as the row title, its tooltip and the $ line of the expanded terminal block, falling back to the output's $ line and then the title. Saved sessions without the field still load.

Closes #6428

Co-authored-by: xuejike <[email protected]>
Цей коміт міститься в:
薛纪克таxuejike authored and GitHub committed 2026-11-27 18:42:02 +08:00
1 джерело e2a5a5db81
коміт f64dbe65b4
7 files changed
+54 -9

No files matched your search

+3 -1
Переглянути файл
@@ -5105,7 +5105,8 @@ fn tool_event(
i: usize,
entry: &AgentEntry,
) -> Option<AgentEvent> {
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);
+3
Переглянути файл
@@ -547,6 +547,9 @@ pub enum AgentEntry {
started_ms: Option<f64>,
#[serde(default)]
ended_ms: Option<f64>,
/// The command an `execute` call runs, from its structured input; `None` when the agent gave none.
#[serde(default)]
command: Option<String>,
},
Plan {
items: Vec<AgentPlanItem>,
+1 -1
Переглянути файл
@@ -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<String> {
pub(crate) fn command_from_value(val: &Value) -> Option<String> {
match val {
Value::String(s) => {
let trimmed = s.trim();
+1
Переглянути файл
@@ -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| {
+35 -1
Переглянути файл
@@ -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;
+3 -1
Переглянути файл
@@ -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. */
+8 -5
Переглянути файл
@@ -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 <dir> &&` 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)}
</span>
)}
<span className={styles.toolTitle} title={entry.title || entry.kind}>
<span className={styles.toolTitle} title={fullTitle}>
{title}
</span>
{links.map((path) => (
@@ -194,12 +197,12 @@ export const ToolEntry = memo(function ToolEntry({
</summary>
}
>
{run?.command ? (
{commandText ? (
<div className={styles.terminalBlock}>
<pre className={styles.terminalCommand}>
<span className={styles.prompt}>$</span> {run.command}
<span className={styles.prompt}>$</span> {commandText}
</pre>
{run.output && <pre className={styles.terminalOutput}>{run.output}</pre>}
{run?.output && <pre className={styles.terminalOutput}>{run.output}</pre>}
</div>
) : (
<pre className={styles.output}>{entry.output}</pre>