Repository navigation
feat: build a notebook and a percent-format script from a chat's successful runs (E4.1) - #684
Conversation
Builds an nbformat 4.5 notebook and a percent-format script from a chat's successful runs. Tested with bun, nbformat and jupytext over recorded and hand-authored conversations.
… the bundle Regenerates the runtime bundle and its integrity line with Bun 1.4.3. Tested: bundle check and the bundle test, which compares the minified builder with the source.
Preview Deployment
This preview will be updated automatically when you push new commits. |
…in their step Tested: bun frontend/test-notebook-builder.js (125 passed), new cases for sys.path.insert before an import, a written helper module, two imports of one name.
…thout an article Tested: bun frontend/test-notebook-builder.js (129 passed).
…at the builder built
…book builder changes Tested: bun scripts/build-runtime-bundle.js --check
|
Review round 1: outcomes (pushed to
Also: the hoisting change made Tested: |
…e; define index before the hoisted imports Tested: bun frontend/test-notebook-builder.js
|
Review round 2: outcomes.
Tested: |
|
PM verdict: ready to merge. Criteria checked against the diff: builder tests wired into frontend-tests, Python nbformat/Jupytext tests present, runtime bundle test and bundle check covered (one OSARuntime member, buildConversationNotebook, as the issue asks; the criterion's "two members" wording was a mismatch). All review findings from both rounds have recorded outcomes. All checks pass (Lint, Test 3.11/3.12, Frontend Tests, Docker build, deploy; Integration skipping). Branch is up to date with develop. Squash merging. |
Summary
Adds
buildConversationNotebook(frontend/osa-notebook-builder.js): a pure builder that turns a conversation's stored runs into an nbformat 4.5 notebook and a percent-format script with the same cells, plusstats: {steps, leftOut}. It is exposed asOSARuntime.buildConversationNotebookand shipped infrontend/osa-runtime.bundle.js. No UI, bridge message or entry point: those are E4.2 to E4.4. The widget changes only in its generatedRUNTIME_BUNDLE_INTEGRITYline.Cells, in order: title and origin line; one setup cell (
%pip install,%matplotlib inline, imports hoisted from the steps once each in first-seen order,import eegprep_lean,read_index, withindex_urlwhenzarrBaseis given); a## Step N · titleheading and a code cell per successful run (title fromstepTitle, thendescription, then justStep N; steps the reader ran carry "(run by the reader, not the assistant)"); a closing "Left out" note when a run was not successful, with each run's position, title, status and, for errors, the first line of stderr. Cells carry no outputs: stored runs lose their figures, and Run all regenerates them (stated in the module header). Ids are deterministic (title,setup,step-N-title,step-N-code,left-out).Fixtures:
frontend/test-support/notebook-conversations.js. The recordedRUN_CARD_FIXTURESruns are real Pyodide runs. The ERP conversation shaped like board B1 is hand-authored: I could not export a real chat (that needs a browser session on develop-demo.osc.earth). Its code compiles (checked by the Python test) but was not run.Closes #667
Tests
bun frontend/test-notebook-builder.js: 106 passeduv run pytest tests/test_frontend -q --no-cov: 142 passed (includes the newtest_notebook_builder.py: nbformat 4.5 validation, every code cell compiles with top-level await after magics are stripped,jupytextlibrary andjupytext --to notebookCLI restore the same cell types and sources, a# %%line does not split a cell)bun scripts/build-runtime-bundle.js && bun scripts/build-runtime-bundle.js --check(Bun 1.4.3): currentbun frontend/test-runtime-bundle.js: 32 passed (the minified builder's output equals the source's for every conversation);bun frontend/test-workspace.js: 81 passeduv run ruff check . && uv run ruff format --check .: cleanbun frontend/test-notebook-builder.jsis wired into thefrontend-testsjob next to "Run workspace tests";jupytextis a new dev dependency (pyproject.tomlanduv.lock,uv sync --frozen --extra devverified)Notes for review
# %%as escapable: a line such as# %% x(indented one space) still splits a cell, and Jupytext itself does not round-trip such a line. The builder therefore rewrites a code line that begins# %%at any indent to# # %%, in the notebook source as well, so both outputs stay equal.jupytext/magics.py, ported in the builder): the setup cell's%pipis written# %pip, and a comment that Jupytext would read as a magic (# %pip x,# why?) is written with an extra#, so reading the script back restores each source exactly.# %%becomes an extra code cell when Jupytext reads the file. The same front matter restores the kernelspec.