nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Jupyter notebook (.ipynb) aware read and edit tools

Open akramcodez opened this issue 2 weeks ago • 3 comments

Description

Add Jupyter notebook support to the file tools. Reading an .ipynb today returns the raw JSON (cell metadata, execution counts, base64 image outputs and all), and editing it with string_replace or write_file works on that JSON text, which is easy to corrupt. A search of source/ for ipynb or notebook handling finds nothing.

Use Case

Data and ML work happens in notebooks. A model asked to "fix the plotting cell" or "add a train/test split" has to wade through hundreds of lines of JSON and base64 output, wastes context, and often produces a notebook that no longer opens because a quote, comma or cell id was broken.

Proposed Solution

  • read_file on an .ipynb returns a compact per-cell view: cell index, type, source, and a short text-only summary of outputs (images and long outputs elided with a size note).
  • A dedicated edit_notebook tool (or notebook-aware mode in string_replace) with operations to replace a cell's source, insert a cell at an index, delete a cell, and change a cell type, which rewrites the JSON through a parser and keeps untouched cells byte-identical, including metadata and outputs.
  • Plain write_file and string_replace on a notebook are rejected with a message pointing at the notebook tool, in the same way the project already guards PDF and DOCX files.
  • The edit preview shows the changed cells rather than a JSON diff.

Alternatives Considered

  • Convert to a script with an external tool, edit, convert back. Loses outputs and metadata and needs extra tools installed.
  • Tell users to avoid notebooks with the agent. Excludes a large group of users.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

The notebook format is plain JSON (nbformat 4), so no new dependency is required. Checkpoints and the read tracker already treat files as opaque content, so they keep working unchanged.

akramcodez avatar Nov 17 '26 08:11 akramcodez

Please assign this to me, Thankyou

puri-adityakumar avatar Nov 19 '26 12:11 puri-adityakumar

@akramcodez Can I try this one

Sravan1011 avatar Nov 22 '26 04:11 Sravan1011

Hi @Sravan1011, thanks so much for your interest in this issue! @puri-adityakumar asked to be assigned first, so I'm assigning it to them. In the meantime, please feel free to look through the other open issues. We'd love to have your help! 🙌

addyCooks avatar Nov 23 '26 07:11 addyCooks