diff --git a/src/features/agents/session/toolEntries.tsx b/src/features/agents/session/toolEntries.tsx index 3298401df..30c38732e 100644 --- a/src/features/agents/session/toolEntries.tsx +++ b/src/features/agents/session/toolEntries.tsx @@ -2,6 +2,7 @@ import type { AgentEntry, AgentTask } from "@/bindings"; import { useTx } from "@/platform/i18n"; import { basename } from "@/platform/project"; import { Icon, IconButton, Spinner, T } from "@/ui"; +import { AnsiStream, spanStyle } from "@/ui/ansi"; import clsx from "clsx"; import { memo, useLayoutEffect } from "react"; import { AgentReply } from "../AgentReply"; @@ -108,6 +109,16 @@ export function pathInTitle(title: string, path: string): { from: number; to: nu return { from, to: at + name.length + (end < 0 ? rest.length : end) }; } +function ToolOutput({ text }: { text: string }) { + if (!text.includes("\x1b")) return text; + return new AnsiStream().parse(text).map((span, index) => ( + // oxlint-disable-next-line react/no-array-index-key -- ANSI spans follow their order in the output. + + {span.text} + + )); +} + export const ToolEntry = memo(function ToolEntry({ task, entry, @@ -240,10 +251,16 @@ export const ToolEntry = memo(function ToolEntry({
$ {commandText}
- {run?.output && {run.output}}
+ {run?.output && (
+ ++ )} ) : ( -+
{entry.output}
+ +)} diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx index 1bbac4968..c5feaeeb8 100644 --- a/src/features/agents/sessionState.test.tsx +++ b/src/features/agents/sessionState.test.tsx @@ -1272,6 +1272,16 @@ describe("scrolling", () => { }); describe("tool calls", () => { + it.each(["pnpm dev:app", null])("renders ANSI diagnostics with command %s", (command) => { + const output = "\x1b[1m\x1b[33mwarning\x1b[0m: 未使用的字段\n\x1b[94m12 |\x1b[0m authors"; + const entry = tool("cargo", { kind: "execute", status: "running", command, output }); + useAgents.setState({ entries: new Map([["A", [entry]]]) }); + render(+