fixed regressed parsing, tool sanitation

This commit is contained in:
2026-06-08 20:34:16 -04:00
parent dc3993048e
commit 85123b7755
10 changed files with 3262 additions and 33 deletions

View File

@@ -866,6 +866,20 @@ function sleep(ms: number): Promise<void> {
// ─── Tool Call Formatting ────────────────────────────────────────────────
/**
* Strip control characters and newlines from a display label so it
* does not break TUI layout (tree branches, text width calculation).
*/
function sanitizeLabel(s: string): string {
// Replace newlines/carriage returns with spaces (multi-line commands
// must fit on a single tree-branch line), then strip ASCII control
// characters except \t (which is harmless) and keep printable chars.
return s
.replace(/\r?\n/g, " ")
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "")
.trim();
}
/**
* Format a tool call argument into a short label.
*/
@@ -873,21 +887,20 @@ function formatToolArg(name: string, args: unknown): string {
const a = args as Record<string, unknown>;
switch (name) {
case "bash":
return truncateMiddle(String(a.command ?? ""), 70);
return sanitizeLabel(truncateMiddle(String(a.command ?? ""), 70));
case "write":
case "read":
return truncateMiddle(String(a.path ?? ""), 60);
return sanitizeLabel(truncateMiddle(String(a.path ?? ""), 60));
case "edit":
return truncateMiddle(String(a.path ?? ""), 60);
return sanitizeLabel(truncateMiddle(String(a.path ?? ""), 60));
case "grep":
return `${a.pattern ?? "?"}${truncateMiddle(
String(a.path ?? ""),
40,
)}`;
return sanitizeLabel(
`${a.pattern ?? "?"}${truncateMiddle(String(a.path ?? ""), 40)}`,
);
case "find":
return `${a.path ?? "."}${a.glob ?? "*"}`;
return sanitizeLabel(`${a.path ?? "."}${a.glob ?? "*"}`);
case "ls":
return truncateMiddle(String(a.path ?? "."), 60);
return sanitizeLabel(truncateMiddle(String(a.path ?? "."), 60));
default:
return name;
}