@devries-cameron20 / t3code Mirror · read-only / commits / 3f3f7f9a76
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, 07:15 UTC

fix(server): preserve raw notebook cell labels in attachment text (#38612)

Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Simone committed Nov 18, 2026 at 14:59 UTC 3f3f7f9a766bd50ffe57030608410e657acc1acf
2 files changed +7 -1
apps/server/src/provider/documentTextWorker.ts
+4 -1
@@ -360,6 +360,8 @@ async function archive(path: string): Promise<Map<string, string>> {
360 return files;
361 }
362
363 +const NOTEBOOK_CELL_TYPES = ["code", "markdown", "raw"];
364 +
365 function* notebook(source: string): Generator<string, void> {
366 const book: unknown = JSON.parse(source);
367 if (!book || typeof book !== "object" || !("cells" in book) || !Array.isArray(book.cells))
@@ -374,7 +376,8 @@ function* notebook(source: string): Generator<string, void> {
376 for (const [index, cell] of book.cells.entries()) {
377 if (index >= 10_000) throw new Truncation("Notebook cell limit");
378 if (!cell || typeof cell !== "object") continue;
377 - const kind = "cell_type" in cell && cell.cell_type === "code" ? "code" : "markdown";
379 + const cellType = "cell_type" in cell ? cell.cell_type : undefined;
380 + const kind = NOTEBOOK_CELL_TYPES.find((type) => type === cellType) ?? "markdown";
381 yield `## Cell ${index + 1} (${kind})\n`;
382 if ("source" in cell) yield* lines(cell.source);
383 if ("outputs" in cell && Array.isArray(cell.outputs)) {
apps/server/src/provider/userInputAttachments.test.ts
+3
@@ -396,6 +396,7 @@ describe("question answer paths", () => {
396 mimeType: "application/x-ipynb+json",
397 };
398 const path = NodePath.join(config.attachmentsDir, `${file.id}.ipynb`);
399 + const rawSource = String.raw`\begin{tabular}{lr} North & 120 \\ \end{tabular}`;
400 const notebook = JSON.stringify({
401 cells: [
402 { cell_type: "markdown", source: ["# Survey\n", "Vessel: Larkspur"] },
@@ -417,6 +418,7 @@ describe("question answer paths", () => {
418 },
419 ],
420 },
421 + { cell_type: "raw", source: [rawSource] },
422 ],
423 });
424 NodeFS.writeFileSync(path, notebook);
@@ -430,6 +432,7 @@ describe("question answer paths", () => {
432 expect(NodeFS.readFileSync(`${path}.txt`, "utf8")).toContain("301");
433 expect(NodeFS.readFileSync(`${path}.txt`, "utf8")).toContain("42");
434 const extracted = NodeFS.readFileSync(`${path}.txt`, "utf8");
435 + expect(extracted).toContain(`## Cell 3 (raw)\n${rawSource}`);
436 expect(extracted).toContain(
437 "ZeroDivisionError: division by zero\nCell In[1], line 1\n----> 1 1 / 0\nZeroDivisionError: division by zero",
438 );