feat(chatbook): add Convert to Chatbook for ordinary notebooks - #508
Merged
Merged
Conversation
Chatbook could export a Chatbook as a code notebook but had no way back, so an existing notebook could only become a Chatbook by copying cells by hand. Ordinary notebooks now get a toolbar button and a palette command that write a Chatbook copy beside the original (<stem>-chatbook.ipynb, numbered when taken) and open it. Every code cell becomes a Chatbook code cell that runs exactly as written; outputs, execution counts, attachments, markdown and other metadata are kept, and the original is not changed. An English description is kept only when the cell's metadata ties it to that exact code, so a Chatbook exported and converted back keeps its prompts. Conversion sends nothing to a model. The first successful run of each cell generates its description, as for any code cell, and the dialog says so. The Chatbook execution kernel is one setting shared by every Chatbook, so a notebook in a different language is not converted and the dialog points to that setting instead of changing it. The source kernel name is recorded under nbi.chatbook.sourceKernel. The export's collision-safe save is shared with conversion through saveNotebookCopy.
- Leave the run natural-language cells of a Chatbook whose kernel was switched as they are. They hold a prompt, not code, and converting them made English into code cells. Exported natural-language cells hold code or a comment and still convert. - Keep a prior English description only when it still describes the code: not after a failed refresh (summaryError), and through the prompt-hash path only for a cell still in natural-language mode. - Compare languages the way the backend kernel list does (py is Python, an empty kernelspec language falls back to language_info), sharing one helper with normalizeNotebookLanguage. - Show the button only once the file has loaded, re-check it when the kernelspec metadata or the Chatbook config changes, and never on a notebook when Chatbook is off. - Allow one conversion at a time, open the copy without a redundant kernel argument, and report a failed open without losing the toast. - Rewrite the dialogs: the language dialog names the language, says what to do next and that the setting affects every Chatbook, and closes with a cancel button; the confirm dialog says where the copy goes and when code is sent to the model. Use sentence case for the command. - Correct the docs on what metadata is kept and when a description is generated. - Test the toolbar entry point: visibility, every dialog branch, the one-at-a-time guard and a failed save, plus a Chatbook to export to Chatbook round trip.
mbektas
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds the reverse of Export as code notebook: a way to turn an existing notebook into a Chatbook, as requested in #504. Ordinary notebooks get a Convert to Chatbook toolbar button and a Convert notebook to Chatbook palette command. Both write a Chatbook copy beside the original and open it. Every code cell arrives as a Cd cell, ready to switch to natural language.
Solution
What the copy contains
<stem>-chatbook.ipynb, numbered when that name is taken, following the export's-pythonnaming. It uses the export's collision-safe save, which is now shared assaveNotebookCopy.nbi.chatbook = {mode: 'code', origin: 'code', codeSource, generatedCode}and run exactly as written.language_infochange to Chatbook's. When the source names its kernel, the name is recorded undernbi.chatbook.sourceKernel.English descriptions
Language check
Visibility
Testing
tests/ts/chatbook.test.ts: the conversion contract. It covers:tests/ts/chatbook-convert.test.ts: drivesconvertNotebookToChatbookwith a fake Contents service. It checks that a taken name is numbered rather than overwritten, the source is not modified, and no summarize call orfetchhappens.tests/ts/chatbook-toolbar-convert.test.ts: covers button visibility, every dialog branch (convert, cancel, unknown language, blocked with and without an installed kernel), one conversion at a time, and a failed save.pytest tests/ -q(2233 passed),jlpm tsc --noEmit,jlpm lint:check,jlpm jest(53 suites, 614 tests).-chatbook-1with the "Created Chatbook copy" toast.Risks / follow-ups
sourceKernelwould feed it);cellTypetoolbar item being present.Screenshots
Closes #504