дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
fix(agents): render ANSI styles in tool output
Цей коміт міститься в:
1 джерело
74f61a3540
коміт
5c9dfbc1cb
2 files changed
+29
-2
No files matched your search
@@ -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 key={index} style={spanStyle(span)}>
|
||||
{span.text}
|
||||
</span>
|
||||
));
|
||||
}
|
||||
|
||||
export const ToolEntry = memo(function ToolEntry({
|
||||
task,
|
||||
entry,
|
||||
@@ -240,10 +251,16 @@ export const ToolEntry = memo(function ToolEntry({
|
||||
<pre className={styles.terminalCommand}>
|
||||
<span className={styles.prompt}>$</span> {commandText}
|
||||
</pre>
|
||||
{run?.output && <pre className={styles.terminalOutput}>{run.output}</pre>}
|
||||
{run?.output && (
|
||||
<pre className={styles.terminalOutput}>
|
||||
<ToolOutput text={run.output} />
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<pre className={styles.output}>{entry.output}</pre>
|
||||
<pre className={styles.output}>
|
||||
<ToolOutput text={entry.output} />
|
||||
</pre>
|
||||
)}
|
||||
</Fold>
|
||||
</div>
|
||||
|
||||
@@ -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(<SessionEditor input={input("A")} />);
|
||||
const warning = screen.getByText("warning");
|
||||
expect(warning.style.color).toBe("var(--ansi-yellow)");
|
||||
expect(warning.closest("pre")?.textContent).toBe("warning: 未使用的字段\n12 | authors");
|
||||
});
|
||||
|
||||
it.each(["pending", "running"] as const)("keeps %s tools in their run, named on its summary", async (status) => {
|
||||
backend.entries.set("A", [tool("done one"), tool("done two"), tool("live", { status, output: "Reading files…" })]);
|
||||
useAgents.setState({ entries: new Map(backend.entries) });
|
||||
|
||||
Reference in new issue
Заблокувати користувача