MCPcopy
hub / github.com/codeaashu/claude-code / readNotebook

Function readNotebook

src/utils/notebook.ts:164–183  ·  view source on GitHub ↗
(
  notebookPath: string,
  cellId?: string,
)

Source from the content-addressed store, hash-verified

162 * Reads and parses a Jupyter notebook file into processed cell data
163 */
164export async function readNotebook(
165 notebookPath: string,
166 cellId?: string,
167): Promise<NotebookCellSource[]> {
168 const fullPath = expandPath(notebookPath)
169 const buffer = await getFsImplementation().readFileBytes(fullPath)
170 const content = buffer.toString('utf-8')
171 const notebook = jsonParse(content) as NotebookContent
172 const language = notebook.metadata.language_info?.name ?? 'python'
173 if (cellId) {
174 const cell = notebook.cells.find(c => c.id === cellId)
175 if (!cell) {
176 throw new Error(`Cell with ID "${cellId}" not found in notebook`)
177 }
178 return [processCell(cell, notebook.cells.indexOf(cell), language, true)]
179 }
180 return notebook.cells.map((cell, index) =>
181 processCell(cell, index, language, false),
182 )
183}
184
185/**
186 * Maps notebook cell data to tool result block parameters with sophisticated text block merging

Callers 1

callInnerFunction · 0.85

Calls 5

expandPathFunction · 0.85
getFsImplementationFunction · 0.85
jsonParseFunction · 0.85
processCellFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected