@devries-cameron20 / t3code Mirror · read-only / commits / 0fdc99c870
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 14:45 UTC

fix(web): notebook previews strip ANSI colors from saved tracebacks (#36703)

Julius Marminge committed Nov 14, 2026 at 04:15 UTC 0fdc99c87051885520c28aab0b6dcb5e9bad135b
2 files changed +7 -4
apps/web/src/components/files/FilePreviewPanel.test.ts
+1 -1
@@ -351,7 +351,7 @@ Third}`;
351 },
352 {
353 kind: "text",
354 - text: "\u001b[31mTraceback (most recent call last):\n\u001b[0m\u001b[32mCell In[3], line 1\n----> 1 fail()\n\u001b[0m\u001b[39m\u001b[31mValueError: preview proof\u001b[0m\nfinal entry",
354 + text: "Traceback (most recent call last):\nCell In[3], line 1\n----> 1 fail()\nValueError: preview proof\nfinal entry",
355 },
356 ]);
357 expect(() => openNotebook(bytes('{"nbformat":3,"cells":[]}'))).toThrow("version 4");
apps/web/src/components/files/extendedDocumentPreview.ts
+6 -3
@@ -6,6 +6,7 @@ import {
6 import { XMLParser, XMLValidator } from "fast-xml-parser";
7 import { decodeHTMLAttribute, decodeHTMLStrict as decodeEntities } from "entities";
8 import type JSZip from "jszip";
9 +import { terminalOutputPlainText } from "@t3tools/shared/terminalOutput";
10
11 import { type OfficeWorkerResult, type NotebookCell } from "./officePreviewProtocol";
12
@@ -439,12 +440,14 @@ function notebookText(value: unknown, limit = 256_000): string {
440 if (result.length > limit) throw new Error("A notebook cell is too large to preview.");
441 return result;
442 }
442 -// IPython traceback frames may omit a final newline or follow it with ANSI SGR sequences.
443 +// IPython traceback frames carry ANSI SGR colors and may omit a final newline.
444 function tracebackLines(value: unknown): unknown {
445 if (!Array.isArray(value)) return value;
445 - const frames = value.filter((frame): frame is string => typeof frame === "string");
446 + const frames = value
447 + .filter((frame): frame is string => typeof frame === "string")
448 + .map(terminalOutputPlainText);
449 return frames.map((frame, index) =>
447 - index && !/\n(?:\u001b\[[\d;:]*m)*$/.test(frames[index - 1]!) ? `\n${frame}` : frame,
450 + index && !frames[index - 1]!.endsWith("\n") ? `\n${frame}` : frame,
451 );
452 }
453 export function openNotebook(bytes: ArrayBuffer): OfficeWorkerResult {