The best way to control Claude Code, Codex and more from any computer or phone
fix(server): remove terminal styling from saved notebook outputs (#39253)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Simone committed
Nov 19, 2026 at 19:43 UTC
9246c3235e190a669c81a75a5f3b020aaea422be
2 files changed
+14
-6
apps/server/src/provider/documentTextWorker.ts
+6
-2
@@ -373,6 +373,10 @@ function* notebook(source: string): Generator<string, void> {
373
if (typeof line === "string") yield line;
374
}
375
}
376
+ function outputText(value: unknown): string {
377
+ // Notebook fragments can split a terminal escape sequence.
378
+ return NodeUtil.stripVTControlCharacters([...lines(value)].join(""));
379
+ }
380
for (const [index, cell] of book.cells.entries()) {
381
if (index >= 10_000) throw new Truncation("Notebook cell limit");
382
if (!cell || typeof cell !== "object") continue;
@@ -384,14 +388,14 @@ function* notebook(source: string): Generator<string, void> {
388
yield "\nOutput:\n";
389
for (const output of cell.outputs) {
390
if (!output || typeof output !== "object") continue;
387
- if ("text" in output) yield* lines(output.text);
391
+ if ("text" in output) yield outputText(output.text);
392
else if (
393
"data" in output &&
394
output.data &&
395
typeof output.data === "object" &&
396
"text/plain" in output.data
397
)
394
- yield* lines(output.data["text/plain"]);
398
+ yield outputText(output.data["text/plain"]);
399
else if ("output_type" in output && output.output_type === "error") {
400
if ("ename" in output) yield* lines(output.ename);
401
if ("evalue" in output) {
apps/server/src/provider/userInputAttachments.test.ts
+8
-4
@@ -430,8 +430,12 @@ describe("question answer paths", () => {
430
cell_type: "code",
431
source: ["print(43 * 7)"],
432
outputs: [
433
- { text: ["301\n"] },
434
- { data: { "text/plain": ["42"] } },
433
+ { output_type: "stream", name: "stdout", text: "\u001b[32m301\u001b[0m\n" },
434
+ {
435
+ output_type: "display_data",
436
+ data: { "text/plain": ["\u001b[", "33m42\u001b[0m\n", "Next line"] },
437
+ metadata: {},
438
+ },
439
{
440
output_type: "error",
441
ename: "ZeroDivisionError",
@@ -455,9 +459,9 @@ describe("question answer paths", () => {
459
});
460
expect(answers.q).toContain(`text extracted to: ${JSON.stringify(path + ".txt")}`);
461
expect(NodeFS.readFileSync(`${path}.txt`, "utf8")).toContain("Vessel: Larkspur");
458
- expect(NodeFS.readFileSync(`${path}.txt`, "utf8")).toContain("301");
459
- expect(NodeFS.readFileSync(`${path}.txt`, "utf8")).toContain("42");
462
const extracted = NodeFS.readFileSync(`${path}.txt`, "utf8");
463
+ expect(extracted).toContain("Output:\n301\n");
464
+ expect(extracted).toContain("42\nNext line");
465
expect(extracted).toContain(`## Cell 3 (raw)\n${rawSource}`);
466
expect(extracted).toContain(
467
"ZeroDivisionError: division by zero\nCell In[1], line 1\n----> 1 1 / 0\nZeroDivisionError: division by zero",