Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-9015: feat(transcript): show command tool input line by line (#10413)

Bohan Jiangfe984c64e31e
diff --git a/packages/views/chat/components/chat-message-list.test.tsx b/packages/views/chat/components/chat-message-list.test.tsx
index d41aee9472..a972470c7f 100644
--- a/packages/views/chat/components/chat-message-list.test.tsx
+++ b/packages/views/chat/components/chat-message-list.test.tsx
@@ -526,6 +526,43 @@ describe("ChatMessageList tool rows (#8835 regression)", () => {
});
});
+describe("ChatMessageList command tool rows", () => {
+ it("shows a command line by line, not as escaped JSON", async () => {
+ const qc = new QueryClient();
+ qc.setQueryData(chatKeys.taskMessages(TASK_ID), [
+ taskMsg(0, "tool_use", {
+ tool: "Bash",
+ input: { command: "pnpm test\npnpm lint", description: "Run checks" },
+ }),
+ ]);
+
+ render(
+ <I18nProvider locale="en" resources={TEST_RESOURCES}>
+ <QueryClientProvider client={qc}>
+ <ChatMessageList
+ messages={[]}
+ pendingTask={{ task_id: TASK_ID, status: "running" }}
+ availability="online"
+ />
+ </QueryClientProvider>
+ </I18nProvider>,
+ );
+
+ fireEvent.click(await screen.findByText("Bash"));
+
+ // Match the raw text: the default matcher collapses the newline that this
+ // test is about.
+ const command = Array.from(document.querySelectorAll("pre > div")).find(
+ (line) => line.textContent === "pnpm test\npnpm lint",
+ );
+ expect(command).toHaveClass("text-foreground");
+ // Same capped, scrolling box as the panel's other inputs and results.
+ expect(command?.parentElement).toHaveClass("max-h-32", "overflow-auto");
+ expect(screen.queryByText(/"command":/)).not.toBeInTheDocument();
+ expect(command?.nextElementSibling?.textContent).toContain('"description": "Run checks"');
+ });
+});
+
describe("ChatMessageList footer spacing", () => {
it("keeps the bottom inset when no task is pending", () => {
const { container } = render(
diff --git a/packages/views/chat/components/chat-message-list.tsx b/packages/views/chat/components/chat-message-list.tsx
index 3d2f29da58..da0dd5e911 100644
--- a/packages/views/chat/components/chat-message-list.tsx
+++ b/packages/views/chat/components/chat-message-list.tsx
@@ -44,7 +44,7 @@ import type {
} from "@multica/core/types";
import type { ChatTimelineItem } from "@multica/core/chat";
import { buildTimeline } from "../../common/task-transcript";
-import { traceToolArgSummary } from "../../common/task-transcript/trace-event-presenter";
+import { readCommandInput, traceToolArgSummary } from "../../common/task-transcript/trace-event-presenter";
import { OnboardingStarterCards } from "./onboarding-starter-cards";
import { TaskStatusPill } from "./task-status-pill";
import { CHAT_COLUMN, CHAT_GUTTER } from "./chat-column";
@@ -1330,6 +1330,7 @@ function ToolCallRow({ item }: { item: ChatTimelineItem }) {
t(($) => $.transcript.patch_summary_more, { path, extra: extraCount }),
});
const hasInput = item.input && Object.keys(item.input).length > 0;
+ const command = useMemo(() => readCommandInput(item.input), [item.input]);
return (
<Collapsible open={open} onOpenChange={setOpen}>
@@ -1346,9 +1347,19 @@ function ToolCallRow({ item }: { item: ChatTimelineItem }) {
</CollapsibleTrigger>
{hasInput && (
<CollapsibleContent>
- <pre className="ml-[18px] mt-0.5 max-h-32 overflow-auto rounded-xs bg-muted/50 p-2 text-caption text-muted-foreground whitespace-pre-wrap break-all">
- {JSON.stringify(item.input, null, 2)}
- </pre>
+ {command ? (
+ // Same capped box as every other input and result in the panel, so a
+ // long script scrolls in place instead of stretching the chat. The
+ // command reads in the foreground colour, its arguments stay muted.
+ <pre className="ml-[18px] mt-0.5 max-h-32 overflow-auto rounded-xs bg-muted/50 p-2 text-caption text-muted-foreground whitespace-pre-wrap wrap-anywhere">
+ <div className="text-foreground">{command.command}</div>
+ {command.params && <div className="mt-1.5">{command.params}</div>}
+ </pre>
+ ) : (
+ <pre className="ml-[18px] mt-0.5 max-h-32 overflow-auto rounded-xs bg-muted/50 p-2 text-caption text-muted-foreground whitespace-pre-wrap break-all">
+ {JSON.stringify(item.input, null, 2)}
+ </pre>
+ )}
</CollapsibleContent>
)}
</Collapsible>
diff --git a/packages/views/common/task-transcript/agent-transcript-dialog.test.tsx b/packages/views/common/task-transcript/agent-transcript-dialog.test.tsx
index e6769449e9..b6b87119e1 100644
--- a/packages/views/common/task-transcript/agent-transcript-dialog.test.tsx
+++ b/packages/views/common/task-transcript/agent-transcript-dialog.test.tsx
@@ -248,6 +248,11 @@ afterEach(() => {
cleanup();
});
+// Match a body's raw text: the default matcher collapses newlines.
+function codeBlock(text: string) {
+ return Array.from(document.querySelectorAll("pre")).find((pre) => pre.textContent === text);
+}
+
describe("AgentTranscriptDialog", () => {
it.each([
{ type: "text", label: "Agent", icon: ".icon-bot" },
@@ -397,11 +402,28 @@ describe("AgentTranscriptDialog", () => {
// The report is the narrative and renders whole; a tool call is a line
// whose body waits in the inspector. This inversion is the redesign.
expect(screen.getByTestId("rich-content")).toHaveTextContent("Agent hidden detail");
- expect(screen.queryByText(/"command": "pnpm test"/)).not.toBeInTheDocument();
+ expect(codeBlock("pnpm test")).toBeUndefined();
fireEvent.click(screen.getByRole("button", { name: /pnpm test/ }));
- expect(screen.getByText(/"command": "pnpm test"/)).toBeInTheDocument();
+ expect(codeBlock("pnpm test")).toBeDefined();
+ });
+
+ it("shows a command line by line with its other arguments as JSON below", () => {
+ renderDialog([
+ {
+ seq: 1,
+ type: "tool_use",
+ tool: "Bash",
+ input: { command: "pnpm test\npnpm lint", description: "Run checks" },
+ },
+ ]);
+
+ fireEvent.click(screen.getByRole("button", { name: /^Bash/ }));
+
+ expect(codeBlock("pnpm test\npnpm lint")).toHaveClass("text-foreground");
+ expect(screen.queryByText(/"command":/)).not.toBeInTheDocument();
+ expect(screen.getByText(/"description": "Run checks"/, { selector: "pre" })).toBeInTheDocument();
});
// Regression, #7125: a run of short prose steps under a long agent name put
diff --git a/packages/views/common/task-transcript/agent-transcript-dialog.tsx b/packages/views/common/task-transcript/agent-transcript-dialog.tsx
index 6429cc6b53..870cc3843f 100644
--- a/packages/views/common/task-transcript/agent-transcript-dialog.tsx
+++ b/packages/views/common/task-transcript/agent-transcript-dialog.tsx
@@ -91,6 +91,7 @@ import {
} from "./trace-event-presenter";
import type { TraceSummaryLabels } from "./trace-event-presenter";
import {
+ CommandDetailSurface,
DiffDetailSurface,
FileWriteSurface,
PatchDetailSurface,
@@ -1854,6 +1855,12 @@ export function StepBody({ item }: { item: TimelineItem }) {
);
}
+ // Tool input has no server-side budget, so it is clipped for display.
+ const clipForDisplay = (text: string) =>
+ text.length > DISPLAY_CLIP_CHARS
+ ? `${redactSecrets(text.slice(0, DISPLAY_CLIP_CHARS))}\n${t(($) => $.transcript.display_clipped)}`
+ : redactSecrets(text);
+
switch (detail.kind) {
case "diff":
return <DiffDetailSurface lines={detail.lines} path={detail.path} />;
@@ -1861,18 +1868,19 @@ export function StepBody({ item }: { item: TimelineItem }) {
return <PatchDetailSurface files={detail.files} truncated={detail.truncated} />;
case "file":
return <FileWriteSurface text={detail.text} lineCount={detail.lineCount} path={detail.path} />;
+ case "command":
+ return (
+ <CommandDetailSurface
+ command={clipForDisplay(detail.command)}
+ params={detail.params && clipForDisplay(detail.params)}
+ />
+ );
default: {
- const text = detail.text;
// A stored tool result is already capped at 8192 bytes by the daemon, so
// clipping it again could only shave a couple of hundred more characters
- // — under a note that already reports the same loss. Tool input has no
- // server-side budget and keeps the clip at its existing length; nothing
- // about how long an input renders is this change's business.
- const clip = item.type === "tool_result" ? null : DISPLAY_CLIP_CHARS;
+ // — under a note that already reports the same loss.
const clipped =
- clip !== null && text.length > clip
- ? `${redactSecrets(text.slice(0, clip))}\n${t(($) => $.transcript.display_clipped)}`
- : redactSecrets(text);
+ item.type === "tool_result" ? redactSecrets(detail.text) : clipForDisplay(detail.text);
const path = item.type === "tool_use" ? readPathFromInput(item.input) : undefined;
return (
<ToolDetailSurface
diff --git a/packages/views/common/task-transcript/detail-surfaces.tsx b/packages/views/common/task-transcript/detail-surfaces.tsx
index 4d060c7885..5c20e71a20 100644
--- a/packages/views/common/task-transcript/detail-surfaces.tsx
+++ b/packages/views/common/task-transcript/detail-surfaces.tsx
@@ -229,13 +229,42 @@ export function DiffDetailSurface({ lines, path }: { lines: TraceDiffLine[]; pat
);
}
+/**
+ * A command tool's input: the command verbatim, line by line, with any
+ * remaining arguments as JSON under it. Laid flat like every other body in the
+ * inspector, so an input reads with the same weight as its result; the command
+ * takes the foreground colour and the arguments stay muted.
+ */
+export function CommandDetailSurface({
+ command,
+ params,
+}: {
+ command: string;
+ params: string | null;
+}) {
+ return (
+ <div>
+ <ToolDetailSurface text={command} emphasis className={params ? "pb-1.5" : undefined} />
+ {params && <ToolDetailSurface text={params} className="pt-0" />}
+ </div>
+ );
+}
+
export function ToolDetailSurface({
text,
language,
+ emphasis = false,
+ className,
note,
}: {
text: string;
language?: string;
+ /**
+ * Foreground text that wraps at spaces, for a command a reviewer reads as
+ * prose. Other bodies stay muted and may break anywhere (long JSON tokens).
+ */
+ emphasis?: boolean;
+ className?: string;
/**
* A remark about the body, shown at its end once the whole body is on
* screen. Withheld while the fade is up: a note that answers "was that all
@@ -247,15 +276,17 @@ export function ToolDetailSurface({
const [showAll, setShowAll] = useState(false);
const isLong = text.length > 1600 || text.split("\n").length > 14;
const revealed = !isLong || showAll;
- // Only file bodies carry a language; command output and JSON stay plain.
+ // Only file bodies carry a language; commands, output and JSON stay plain.
const html = useMemo(() => (language ? highlightBlock(text, language) : null), [text, language]);
return (
<div className="relative">
<pre
className={cn(
- "transcript-code p-3 font-mono text-micro text-muted-foreground whitespace-pre-wrap break-all",
+ "transcript-code p-3 font-mono text-micro whitespace-pre-wrap",
+ emphasis ? "text-foreground wrap-anywhere" : "text-muted-foreground break-all",
isLong && !showAll && "max-h-52 overflow-hidden",
+ className,
)}
>
{html === null ? (
diff --git a/packages/views/common/task-transcript/run-outcome.ts b/packages/views/common/task-transcript/run-outcome.ts
index b4dae34ddb..62f5ce5ec8 100644
--- a/packages/views/common/task-transcript/run-outcome.ts
+++ b/packages/views/common/task-transcript/run-outcome.ts
@@ -68,6 +68,7 @@ export function buildRunOutcome(steps: TraceStep[]): RunOutcome | null {
}
break;
}
+ case "command":
case "text": {
// Shell-shaped by input, not by tool name: every backend names its
// shell differently (Bash, shell, run_command, terminal) but they all
diff --git a/packages/views/common/task-transcript/trace-event-presenter.test.ts b/packages/views/common/task-transcript/trace-event-presenter.test.ts
index 57e91eb69c..406063b228 100644
--- a/packages/views/common/task-transcript/trace-event-presenter.test.ts
+++ b/packages/views/common/task-transcript/trace-event-presenter.test.ts
@@ -240,15 +240,36 @@ describe("traceEventDetail", () => {
expect(detail.lines).toEqual([{ kind: "remove", text: "gone" }]);
});
- it("falls back to pretty JSON for a tool call that is not an edit", () => {
+ it("reads a command tool's input as the command, keyed off shape not tool name", () => {
+ expect(
+ traceEventDetail({ type: "tool_use", tool: "Bash", input: { command: "ls -la" } }),
+ ).toEqual({ kind: "command", command: "ls -la", params: null });
+ expect(
+ traceEventDetail({
+ type: "tool_use",
+ tool: "exec_command",
+ input: { cmd: "git status", workdir: "/repo" },
+ }),
+ ).toEqual({ kind: "command", command: "git status", params: '{\n "workdir": "/repo"\n}' });
+ });
+
+ it("keeps a file editor's `command` operation as JSON, not shell code", () => {
+ const input = { command: "view", path: "/repo/a.ts" };
+ expect(traceEventDetail({ type: "tool_use", tool: "str_replace_editor", input })).toEqual({
+ kind: "text",
+ text: JSON.stringify(input, null, 2),
+ });
+ });
+
+ it("falls back to pretty JSON for a tool call that is not an edit or a command", () => {
const detail = traceEventDetail({
type: "tool_use",
- tool: "Bash",
- input: { command: "ls -la" },
+ tool: "Grep",
+ input: { pattern: "TODO", command: "" },
});
expect(detail.kind).toBe("text");
if (detail.kind !== "text") return;
- expect(detail.text).toBe('{\n "command": "ls -la"\n}');
+ expect(detail.text).toBe('{\n "pattern": "TODO",\n "command": ""\n}');
});
it("unwraps a tool result so it reads as the terminal output it was", () => {
diff --git a/packages/views/common/task-transcript/trace-event-presenter.ts b/packages/views/common/task-transcript/trace-event-presenter.ts
index 99b0a39dde..283fe5d007 100644
--- a/packages/views/common/task-transcript/trace-event-presenter.ts
+++ b/packages/views/common/task-transcript/trace-event-presenter.ts
@@ -237,6 +237,11 @@ export type TraceEventDetail =
| { kind: "diff"; path: string; lines: TraceDiffLine[] }
| { kind: "file"; path: string; text: string; lineCount: number }
| { kind: "patch"; files: TracePatchFile[]; truncated: boolean }
+ /**
+ * A shell command, verbatim. Any other arguments (description, timeout…)
+ * stay as JSON under it, so nothing the input carried is hidden.
+ */
+ | { kind: "command"; command: string; params: string | null }
| { kind: "text"; text: string };
/** Body of one file inside a multi-file patch. */
@@ -512,6 +517,31 @@ function readFileMutation(input: Record<string, unknown>): FileMutation | null {
return null;
}
+/**
+ * A shell command and the call's other arguments, or null when the input is
+ * not a shell command. Keyed on shape like the summary, not on tool name:
+ * every backend names its shell differently, but they all pass a non-empty
+ * `command` (or `cmd`) string.
+ *
+ * A file editor such as `str_replace_editor` uses the same key for an
+ * operation (`view`, `create`) on a `path`, so a call that targets a file
+ * is not a command — the precedence the summary gives `path` over `command`.
+ */
+export function readCommandInput(
+ input: Record<string, unknown> | undefined,
+): { command: string; params: string | null } | null {
+ if (!input) return null;
+ if (typeof input.path === "string" || typeof input.file_path === "string") return null;
+ for (const key of ["command", "cmd"]) {
+ const command = input[key];
+ if (typeof command !== "string" || command.trim().length === 0) continue;
+ const { [key]: _, ...rest } = input;
+ const params = Object.keys(rest).length > 0 ? JSON.stringify(rest, null, 2) : null;
+ return { command, params };
+ }
+ return null;
+}
+
/**
* Structured body for the expanded row. Edits become a diff so a reviewer sees
* what changed rather than two escaped string literals; results are unwrapped;
@@ -541,6 +571,8 @@ export function traceEventDetail(event: TraceEvent): TraceEventDetail {
lineCount: toLines(mutation.content).length,
};
}
+ const command = readCommandInput(event.input);
+ if (command !== null) return { kind: "command", ...command };
return { kind: "text", text: JSON.stringify(event.input, null, 2) };
}
case "tool_result":
diff --git a/packages/views/common/task-transcript/trace-issue-labels.test.ts b/packages/views/common/task-transcript/trace-issue-labels.test.ts
index 512ed12ecc..551be30d21 100644
--- a/packages/views/common/task-transcript/trace-issue-labels.test.ts
+++ b/packages/views/common/task-transcript/trace-issue-labels.test.ts
@@ -38,7 +38,7 @@ describe("trace issue labels", () => {
expect(traceToolArgSummary({ cmd: command }, { formatText: (text) => replaceTraceIssueIds(text, labels) }))
.toBe("multica issue update DEV-17 --description 'DEV-14 DEV-17 visible-tail'");
expect(input.command).toBe(command);
- expect(traceEventDetail(event)).toEqual({ kind: "text", text: JSON.stringify(input, null, 2) });
+ expect(traceEventDetail(event)).toEqual({ kind: "command", command, params: null });
expect(traceEventCopyText(event)).toContain(issue);
expect(traceEventCopyText(event)).not.toContain("DEV-17");
});