refactor: move notebook metadata types to shared notebook-doc crate#566
refactor: move notebook metadata types to shared notebook-doc crate#566
Conversation
All peers (daemon, Tauri relay, WASM frontend, Python bindings) now share one definition of notebook metadata via notebook-doc. - git mv notebook_metadata.rs → notebook-doc/src/metadata.rs - Re-export from runtimed as notebook_metadata (backwards compatible) - Add typed helpers on NotebookDoc: - get_metadata_snapshot() / set_metadata_snapshot() - detect_runtime() — kernelspec + language_info detection - 31 notebook-doc tests (23 doc + 8 metadata), all passing - 225 runtimed tests, all passing Any consumer with a NotebookDoc can now do typed metadata operations without manual JSON parsing or depending on runtimed directly.
Follow-on work enabled by this PRWith metadata types in 1. Frontend reads metadata from its own WASM docThe Tauri metadata commands ( The frontend's WASM Scope: Rebuild 2. Daemon-owned initial population
Alternative: the daemon reads the ipynb file directly (it already does for saved notebooks via Scope: Larger change — touches the connection handshake protocol and the untitled-notebook creation flow. Good candidate for a dedicated spike. |
After PR #554 (dead command removal) and #566 (metadata fallback migration), NotebookState is only used in 4 functions. This PR removes those usages by: 1. Add dirty flag to WindowNotebookContext - tracks unsaved changes in context instead of NotebookState 2. Migrate clone_notebook_to_path to daemon - daemon reads from Automerge, clears outputs, generates fresh env_id 3. Decouple initialize_notebook_sync from NotebookState - daemon is source of truth; pass explicit notebook_id and cells rather than NotebookState Step 4 (removing notebook_state field from WindowNotebookContext) is deferred because fallback usages (get_kernelspec, get_dependencies, etc.) read from NotebookState when daemon isn't connected. Removing these requires either removing fallbacks or finding alternative sources. The daemon now owns notebook content via Automerge; NotebookState remains only as a local window cache and for fallback cases.
* refactor: eliminate NotebookState from save, clone, and reconnect After PR #554 (dead command removal) and #566 (metadata fallback migration), NotebookState is only used in 4 functions. This PR removes those usages by: 1. Add dirty flag to WindowNotebookContext - tracks unsaved changes in context instead of NotebookState 2. Migrate clone_notebook_to_path to daemon - daemon reads from Automerge, clears outputs, generates fresh env_id 3. Decouple initialize_notebook_sync from NotebookState - daemon is source of truth; pass explicit notebook_id and cells rather than NotebookState Step 4 (removing notebook_state field from WindowNotebookContext) is deferred because fallback usages (get_kernelspec, get_dependencies, etc.) read from NotebookState when daemon isn't connected. Removing these requires either removing fallbacks or finding alternative sources. The daemon now owns notebook content via Automerge; NotebookState remains only as a local window cache and for fallback cases. * fix: address reviewer feedback on save-as and clone 1. Fix save_notebook_as data loss risk: Read cells and metadata from the old room BEFORE disconnecting. The new room won't have them since it's a different notebook_id, so we need to carry them across to populate the new room if it's empty. 2. Fix clone_notebook_to_disk dropping metadata: Read existing notebook to preserve cell metadata, attachments, and non-snapshot notebook metadata fields. Use split_inclusive for cleaner source line splitting.
Moves notebook metadata types (
NotebookMetadataSnapshot,RuntMetadata,KernelspecSnapshot, etc.) fromruntimedto the sharednotebook-doccrate. All peers now share one definition.Why
Every peer (daemon, Tauri relay, WASM frontend, Python bindings) needs to read and write notebook metadata — kernelspec, dependencies, trust signatures. Previously these types lived in
runtimed, forcing all consumers to depend on the full daemon crate. Now they're innotebook-docalongside the Automerge doc they describe.What changed
git mv runtimed/src/notebook_metadata.rs→notebook-doc/src/metadata.rs(history preserved)runtimedasnotebook_metadata— zero breakage for existing callersNotebookDoc:get_metadata_snapshot()— deserializeNotebookMetadataSnapshotfrom docset_metadata_snapshot()— serialize and write backdetect_runtime()— kernelspec + language_info detection ("python", "deno", or None)What this enables
Any consumer with a
NotebookDoc(or WASMNotebookHandle) can do:Without manual JSON parsing or depending on
runtimed. This is the foundation for the frontend reading metadata directly from its WASM doc instead of via Tauri commands.QA
31 notebook-doc tests, 225 runtimed tests, all passing.