Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,19 @@ Terse command-style prompts produce shallow, generic work.
return new Text("▸ " + theme.fg("toolTitle", theme.bold(displayName)) + (desc ? " " + theme.fg("muted", desc) : ""), 0, 0);
},

renderResult(result, { expanded, isPartial }, theme) {
renderResult(result, { expanded, isPartial }, theme, renderContext) {
const details = result.details as AgentDetails | undefined;
if (!details) {
const text = result.content[0]?.type === "text" ? result.content[0].text : "";
const text = result.content[0]?.type === "text" ? result.content[0].text : "";
const knownStatuses = new Set<AgentDetails["status"]>([
"running",
"background",
"completed",
"steered",
"stopped",
"error",
"aborted",
]);
if (renderContext.isError || !details || !knownStatuses.has(details.status)) {
return new Text(text, 0, 0);
}

Expand Down
59 changes: 59 additions & 0 deletions test/agent-tool-error-rendering.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, expect, it, vi } from "vitest";
import subagentsExtension from "../src/index.js";

function agentTool() {
const tools = new Map<string, any>();
const pi = {
registerMessageRenderer: vi.fn(),
registerTool: vi.fn((tool: any) => tools.set(tool.name, tool)),
registerCommand: vi.fn(),
on: vi.fn(),
events: { emit: vi.fn(), on: vi.fn(() => vi.fn()) },
appendEntry: vi.fn(),
sendMessage: vi.fn(),
} as any;
subagentsExtension(pi);
return tools.get("Agent");
}

const theme = {
fg: (_color: string, text: string) => text,
bold: (text: string) => text,
} as any;

function render(tool: any, result: any): string {
return tool.renderResult(
{ content: result.content, details: result.details },
{ expanded: false, isPartial: false },
theme,
{ isError: result.isError },
).render(120).join("\n");
}

describe("Agent tool invocation error rendering", () => {
it("shows a Pi tool error instead of structured terminal status", () => {
const output = render(agentTool(), {
content: [{ type: "text", text: 'Cannot run with isolation: "worktree" — Git probe failed.' }],
isError: true,
details: { status: "aborted" },
});

expect(output).toContain('Cannot run with isolation: "worktree" — Git probe failed.');
expect(output).not.toContain("Aborted (max turns exceeded)");
});

it.each([
["missing details", undefined],
["empty details", {}],
["unknown status", { status: "unknown" }],
])("shows the real result text for %s", (_name, details) => {
const output = render(agentTool(), {
content: [{ type: "text", text: "Unstructured Agent result." }],
isError: false,
details,
});

expect(output).toContain("Unstructured Agent result.");
expect(output).not.toContain("Aborted (max turns exceeded)");
});
});
Loading