Skip to content

fix: [#63] Add Jupyter notebook (.ipynb) support to edit tool#387

Open
nandanosql wants to merge 1 commit into
bytedance:mainfrom
nandanosql:fix/issue-63-jupyter-notebook-support
Open

fix: [#63] Add Jupyter notebook (.ipynb) support to edit tool#387
nandanosql wants to merge 1 commit into
bytedance:mainfrom
nandanosql:fix/issue-63-jupyter-notebook-support

Conversation

@nandanosql
Copy link
Copy Markdown

Fixes #63

Problem

The edit/view tools cannot handle .ipynb (Jupyter notebook) files. When the agent tries to view or edit a notebook, it either shows raw JSON or fails because the file contains complex structured data.

Solution

Added special handling for .ipynb files in TextEditorTool:

View command

  • Detects .ipynb files and parses the JSON notebook format
  • Displays each cell with a header showing cell type (code/markdown) and index
  • Shows cell source content in a readable format

str_replace command

  • Converts all cell sources to a flat text representation with cell marker comments (# %% Cell N (type))
  • Applies string replacement on this representation
  • Reconstructs the notebook JSON from the modified text, preserving cell structure
  • Supports the same uniqueness check as regular files

Changes

  • Added json import
  • Added _is_notebook(), _read_notebook(), _write_notebook() helpers
  • Added _notebook_cells_to_text() for view rendering
  • Added _notebook_to_source_text() for str_replace editing
  • Added _apply_str_replace_to_notebook() and _reconstruct_notebook_from_text()
  • Modified _view() to detect and render notebooks
  • Modified _str_replace_handler() to handle notebooks
  • Updated tool description to mention notebook support

Add ability to view and edit Jupyter notebooks in the TextEditorTool:

- _view(): detects .ipynb files and displays cells with type headers
  and source content instead of raw JSON
- str_replace: applies replacements on concatenated cell sources with
  cell marker comments (# %% Cell N), then reconstructs the notebook
  JSON preserving structure
- Helper methods: _read_notebook, _write_notebook,
  _notebook_cells_to_text, _notebook_to_source_text,
  _apply_str_replace_to_notebook, _reconstruct_notebook_from_text
- Updated tool description to mention notebook support
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

need smart and robust support for jupyter notebooks / .ipynb files

2 participants