fix (tui): sanitize binary-heavy history text before render

This commit is contained in:
Vignesh Natarajan
2026-02-14 18:29:12 -08:00
parent 914b9d1e79
commit 750a7146e4
3 changed files with 81 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { Box, Container, Markdown, Spacer, Text } from "@mariozechner/pi-tui";
import { formatToolDetail, resolveToolDisplay } from "../../agents/tool-display.js";
import { markdownTheme, theme } from "../theme/theme.js";
import { sanitizeRenderableText } from "../tui-formatters.js";
type ToolResultContent = {
type?: string;
@@ -21,13 +22,13 @@ function formatArgs(toolName: string, args: unknown): string {
const display = resolveToolDisplay({ name: toolName, args });
const detail = formatToolDetail(display);
if (detail) {
return detail;
return sanitizeRenderableText(detail);
}
if (!args || typeof args !== "object") {
return "";
}
try {
return JSON.stringify(args);
return sanitizeRenderableText(JSON.stringify(args));
} catch {
return "";
}
@@ -40,7 +41,7 @@ function extractText(result?: ToolResult): string {
const lines: string[] = [];
for (const entry of result.content) {
if (entry.type === "text" && entry.text) {
lines.push(entry.text);
lines.push(sanitizeRenderableText(entry.text));
} else if (entry.type === "image") {
const mime = entry.mimeType ?? "image";
const size = entry.bytes ? ` ${Math.round(entry.bytes / 1024)}kb` : "";