From 8465e7707a28d6449d21c53187f50dfa8bdf5d8c Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Fri, 29 May 2026 16:41:15 +0200 Subject: [PATCH] refactor(cli): make notebook read routing explicit --- packages/opencode/src/kilocode/tool/notebook.ts | 6 ++++-- packages/opencode/src/tool/read.ts | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/kilocode/tool/notebook.ts b/packages/opencode/src/kilocode/tool/notebook.ts index 51d1006f7a2..e2e1f72c755 100644 --- a/packages/opencode/src/kilocode/tool/notebook.ts +++ b/packages/opencode/src/kilocode/tool/notebook.ts @@ -25,9 +25,11 @@ const render = (kind: "markdown" | "code", text: string) => { return `<${kind}_cell>\n${body}` } -export async function open(filepath: string): Promise { - if (path.extname(filepath).toLowerCase() !== ".ipynb") return undefined +export function isFile(filepath: string) { + return path.extname(filepath).toLowerCase() === ".ipynb" +} +export async function open(filepath: string): Promise { const raw = (await Encoding.read(filepath)).text const data = parse(raw) if (!object(data) || !Array.isArray(data.cells)) return Readable.from([raw]) diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index 88c9f216e63..d5728f66844 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -359,8 +359,7 @@ export const ReadTool = Tool.define( // routed through TextStream.withFallback so non-UTF-8 files are decoded via // iconv. The body otherwise matches upstream. export async function lines(filepath: string, opts: { limit: number; offset: number }) { - const extracted = await Notebook.open(filepath) // kilocode_change - extract readable notebook cells before paging - if (extracted) return readLines(extracted, opts) // kilocode_change + if (Notebook.isFile(filepath)) return readLines(await Notebook.open(filepath), opts) // kilocode_change - extract readable notebook cells before paging return TextStream.withFallback(filepath, (stream) => readLines(stream, opts)) }