Skip to content

smelt.notebook

Tier: UiHost - Requires a terminal UI; calling these from headless mode raises.

Visibility: Public - Stable Lua API intended for user config and plugins.

Parse, read, and apply notebook cell edits, plus compute preview data for the edit_notebook tool. UiHost-only.

smelt.notebook.apply_edit

fun(args: table): any?, string?

Apply a notebook edit (cell insert/replace/delete) described by args and persist the new file. Returns (message_table, nil) on success or (nil, err_msg) on failure. Callers are expected to hold the per-path advisory flock.

smelt.notebook.apply_edit_async

fun(args: table): table?, string?

Apply a notebook edit off the main thread. Same return shape as smelt.notebook.apply_edit.

smelt.notebook.is_notebook_path

fun(path: string): boolean

Return true if path looks like a Jupyter notebook (.ipynb extension).

smelt.notebook.parse

fun(json: string): table?, string?

Parse a notebook JSON string. Returns (notebook, nil) with { nbformat, nbformat_minor, cells = { { kind, id?, source, execution_count? } } } on success, or (nil, error) on failure.

smelt.notebook.preview_data

fun(args: table): table?

Visibility: Internal - Runtime implementation detail. Bundled Lua may call it, but user config and plugins should not depend on it.

Compute the preview payload for an edit_notebook call. Returns nil when the notebook can't be read/parsed or the target cell is out of range. The returned table has { edit_mode, path, title, old_source, new_source, syntax_ext }.

smelt.notebook.read

fun(path: string, offset: integer, limit: integer): string?, string?

Render a Jupyter notebook at path as cell-by-cell text starting at offset for at most limit cells. Returns (text, nil) on success or (nil, err_msg) on parse failure, matching the output the built-in read_file tool produces.

smelt.notebook.read_async

fun(path: string, offset: integer, limit: integer): string?, string?, string?, integer?

Render a notebook off the main thread. Same return shape as smelt.notebook.read, plus raw notebook JSON and mtime on success.