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

Function call

src/tools/NotebookEditTool/NotebookEditTool.ts:295–489  ·  view source on GitHub ↗
(
    {
      notebook_path,
      new_source,
      cell_id,
      cell_type,
      edit_mode: originalEditMode,
    },
    { readFileState, updateFileHistoryState },
    _,
    parentMessage,
  )

Source from the content-addressed store, hash-verified

293 return { result: true }
294 },
295 async call(
296 {
297 notebook_path,
298 new_source,
299 cell_id,
300 cell_type,
301 edit_mode: originalEditMode,
302 },
303 { readFileState, updateFileHistoryState },
304 _,
305 parentMessage,
306 ) {
307 const fullPath = isAbsolute(notebook_path)
308 ? notebook_path
309 : resolve(getCwd(), notebook_path)
310
311 if (fileHistoryEnabled()) {
312 await fileHistoryTrackEdit(
313 updateFileHistoryState,
314 fullPath,
315 parentMessage.uuid,
316 )
317 }
318
319 try {
320 // readFileSyncWithMetadata gives content + encoding + line endings in
321 // one safeResolvePath + readFileSync pass, replacing the previous
322 // detectFileEncoding + readFile + detectLineEndings chain (each of
323 // which redid safeResolvePath and/or a 4KB readSync).
324 const { content, encoding, lineEndings } =
325 readFileSyncWithMetadata(fullPath)
326 // Must use non-memoized jsonParse here: safeParseJSON caches by content
327 // string and returns a shared object reference, but we mutate the
328 // notebook in place below (cells.splice, targetCell.source = ...).
329 // Using the memoized version poisons the cache for validateInput() and
330 // any subsequent call() with the same file content.
331 let notebook: NotebookContent
332 try {
333 notebook = jsonParse(content) as NotebookContent
334 } catch {
335 return {
336 data: {
337 new_source,
338 cell_type: cell_type ?? 'code',
339 language: 'python',
340 edit_mode: 'replace',
341 error: 'Notebook is not valid JSON.',
342 cell_id,
343 notebook_path: fullPath,
344 original_file: '',
345 updated_file: '',
346 },
347 }
348 }
349
350 let cellIndex
351 if (!cell_id) {
352 cellIndex = 0 // Default to inserting at the beginning if no cell_id is provided

Callers

nothing calls this directly

Calls 13

getCwdFunction · 0.85
fileHistoryEnabledFunction · 0.85
fileHistoryTrackEditFunction · 0.85
readFileSyncWithMetadataFunction · 0.85
jsonParseFunction · 0.85
parseCellIdFunction · 0.85
jsonStringifyFunction · 0.85
writeTextContentFunction · 0.85
getFileModificationTimeFunction · 0.85
spliceMethod · 0.80
toStringMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected