Repository navigation
feat: import a chat notebook as a named tab and notebook tabs (E4.2, E4.4) - #690
Conversation
The widget's importNotebookToTab hands a notebook to the notebook frame; the bridge (the only code that can write the cross-origin storage) validates it, writes <community>/<dataset> . <title>.ipynb without overwriting, opens it, and answers; the widget shows a banner with Run all (cell by cell) and Undo (until the reader edits it). The starter is never changed. - notebook/osa-notebook-files.js: pure naming, import validation (dataset pattern, nbformat 4, markdown and code only, 200 cells, 2 MB, autorun tag stripped) and message validation; built next to the bridge. - Bridge: import-notebook, run-all, undo-import, result and notebooks. - open.js runs main() only on a page with #app, so it can be imported. Tested: bun notebook/test-notebook-files.js, test-widget-notebook-import.js, the existing notebook tab and build tests, and notebook/e2e-check.js against a develop build in Chrome.
A strip under the surface tabs lists the dataset's notebooks (the playground, imports, blank ones) from the notebook page's notebooks messages: role tablist/tab with aria-selected and arrow keys, inline rename (Enter commits, Escape cancels; the file keeps its dataset prefix), close, and a + menu for a blank notebook and the closed ones to reopen. The bridge handles new-notebook, open-notebook, rename-notebook and close-notebook, keeps the open list in its own localStorage per community and dataset, and restores it after a reload; a closed notebook stays a file. Also the protocol in notebook/README.md, ADR 0017 and the changelog line. Tested: bun frontend/test-widget-notebook-strip.js, the import and tab suites, and notebook/e2e-check.js against a develop build in Chrome (create, rename, close, reload and reopen, a second import as a new tab, a foreign message).
Preview Deployment
This preview will be updated automatically when you push new commits. |
…lapsing whitespace (tested: test-notebook-files.js)
… and ignore unknown messages (tested: test-notebook-files.js)
…cannot hold the tab queue (not tested: needs the e2e browser run)
…ts; stats is not part of import-notebook
…t on strip redraw; strip is a labelled group, not a tablist; tab label contrast; stats stays out of import-notebook (tested: widget notebook import and strip suites, other widget suites)
|
Review round 1: outcome for each finding. Fix commits are on this branch (da14bce, 40e1927, b5e713b, 1ded192, 8d6a932).
Local runs on the new head: |
…imer; an import saved but not shown keeps its path, Run all and Undo (tested: widget notebook import suite)
…vives a redraw and a window blur (tested: widget notebook strip suite)
…undo-import is refused while the cells run; setup wait bound is 150 s (tested: notebook e2e check, develop environment)
|
Review round 2 outcomes (fix commits on this branch: bb1e9f4, 8199303, 73d8acd).
All widget and notebook JS suites pass; |
|
PM verdict: ready to merge. All three test files exist and are wired in tests.yml (bun notebook tests after the bootstrap tests, both widget suites after the notebook tab suite); e2e-check covers import, undo, create/rename/close, reload, second import, foreign target; both review rounds have outcomes; all checks pass on head 73d8acd and the branch is current with develop. Merging. |
Summary
The widget can hand a chat's notebook to the notebook frame, which writes it as
<community>/<dataset> · <title>.ipynb, opens it, and offers Run all and Undo; and the Notebook surface has a strip of named notebooks (the dataset's playground, imported ones, "+" for a blank one) with rename, close and reopen. Board B1 (.context/designs/nemar-ai-ux/Notebook.dc.html). The starter notebook is never changed. The design's Download menu and the chat's "Continue in notebook" card (E4.3) are out of scope;importNotebookToTabis what E4.3 will call.Two commits:
feat: import a chat's notebook into the notebook tab (#673): the pure modulenotebook/osa-notebook-files.js(naming, import validation, message validation), the bridge handlersimport-notebook,run-all,undo-importand theresultandnotebooksanswers, and the widget's request machinery,importNotebookToTaband banner.feat: named notebook tabs in the notebook surface (#676): the strip (tablist, arrow keys, inline rename, close, "+" menu), the bridge'snew-notebook,open-notebook,rename-notebookandclose-notebook, the per-dataset open list in the page'slocalStorage, the protocol innotebook/README.md, ADR 0017 and the changelog line.Why the bridge: the frame is cross-origin, so only
notebook/osa-bridge.jscan write JupyterLite's storage (serviceManager.contents) and open a document. The page trusts nothing in a message: a path is acted on only if it is in the page's own listing under<community>/for the dataset; an import is checked (dataset againststarters/index.jsonviadatasetProblem, nbformat 4, markdown and code cells only, at most 200 cells and 2 MB), theosa-autoruntag is stripped, and a name that exists gets " 2", " 3". Run all runs the cells one at a time (run-all-cellsnever settles, ADR 0012).Two JupyterLite facts that shaped it, both measured and recorded in ADR 0017: the notebooks page is a single-document shell (
docmanager:opengoes to a browser tab unless called withoptions: {ref: '_noref'}, andNotebookShell.addrefuses a second widget), so a tab switch closes the panel on screen and opens the next in its place; and the kernel of a closed panel keeps running and is reconnected on reopen, so Python state survives a switch.Closes #673
Closes #676
Tests
bun notebook/test-notebook-files.js && bun notebook/test-open.js && bun notebook/test-bridge.js: 211, 52 and 14 checks pass.bun frontend/test-widget-notebook-import.js && bun frontend/test-widget-notebook-strip.js && bun frontend/test-widget-notebook-tab.js && bun frontend/test-notebook-builder.js: 95, 121, 168 and 130 checks pass.bun notebook/e2e-check.js --environment develop: all checks pass in real Chrome on a develop build, including the framed import from the real builder (file exists, is open, no autorun tag, the starter'slast_modifiedunchanged), Run all on passing and failing notebooks, Undo, create, rename, close, a reload with the open list restored and a closed notebook reopened, a second import as a new tab, Python kept across a tab switch, and a foreigntargetignored.uv run pytest tests/test_scripts/test_build_notebook_site.py tests/test_frontend -q: 205 passed.node --check frontend/osa-chat-widget.jsuv run ruff check . && uv run ruff format --check .: clean.Run notebook files tests,Run the notebook import tests on a real DOMandRun the notebook strip tests on a real DOMintests.yml;notebook-site-check.ymlalso triggers on the builder and its fixtures, with a 20-minute timeout since the develop run is longer.