Skip to content

refactor: extract shared notebook-doc crate, eliminate WASM copy drift#562

Merged
rgbkrk merged 1 commit intomainfrom
540/dead-sync-handle-methods
Mar 6, 2026
Merged

refactor: extract shared notebook-doc crate, eliminate WASM copy drift#562
rgbkrk merged 1 commit intomainfrom
540/dead-sync-handle-methods

Conversation

@rgbkrk
Copy link
Member

@rgbkrk rgbkrk commented Mar 6, 2026

Extracts the shared Automerge notebook document code into its own crate, eliminating the copy drift between runtimed (daemon) and runtimed-wasm (frontend WASM bindings).

What changed

crates/runtimed/src/notebook_doc.rscrates/notebook-doc/src/lib.rs via git mv (history preserved). The 833-line duplicate in runtimed-wasm is deleted.

Crate Dependency Features
runtimed notebook-doc = { features = ["persistence"] } File I/O: load_or_create, save_to_file
runtimed-wasm notebook-doc (no features) Core only: cell CRUD, metadata, sync

Design decisions

  • persistence feature gates load_or_create, save_to_file, preserve_corrupt, notebook_doc_filename — these need std::fs + log which are irrelevant for WASM
  • StreamOutputState moved from stream_terminal.rs to the shared crate (2-field struct, no external deps). stream_terminal.rs re-exports it.
  • doc() / doc_mut() accessors on NotebookDoc so consumers can extend via traits without forking the struct

Tests

  • 23 notebook-doc tests (19 core + 4 persistence-gated)
  • 233 runtimed tests passing
  • All notebook crate tests passing

Relay simplification status

Audited NotebookSyncHandle methods — ALL are still live:

  • send_request() — 13 call sites (kernel ops, save, env sync)
  • get_cells() — format_cell
  • update_source() — format_cell, initialize_notebook_sync
  • add_cell() — initialize_notebook_sync
  • get_metadata() / set_metadata() — 6 call sites (runtime detection, trust, metadata sync)
  • get_doc_bytes() / receive_frontend_sync_message() — Automerge relay

Only delete_cell() on the handle has zero Tauri callers, but it's used by runtimed-py (Python agent API). Reducing the relay to pure forwarding would require migrating format_cell and initial population to go through Automerge sync instead of handle methods — a separate, more involved change.

Closes the "extract shared notebook-doc crate" item in #556.

Eliminates WASM copy drift — both runtimed (daemon) and runtimed-wasm
(frontend) now depend on one source of truth for the Automerge notebook
document schema and operations.

Changes:
- git mv runtimed/src/notebook_doc.rs → notebook-doc/src/lib.rs (history preserved)
- Delete runtimed-wasm/src/notebook_doc.rs (was a diverging copy)
- File I/O methods (load_or_create, save_to_file) gated behind 'persistence' feature
- StreamOutputState moved from stream_terminal.rs to the shared crate
  (2-field struct, no external deps) — runtimed re-exports it
- NotebookDoc gains doc()/doc_mut() accessors for extension by consumers
- runtimed depends on notebook-doc with features=["persistence"]
- runtimed-wasm depends on notebook-doc (no features)

Tests: 23 notebook-doc (19 core + 4 persistence), 233 runtimed, all passing.

Closes the 'extract shared notebook-doc crate' item in #556.
@rgbkrk rgbkrk enabled auto-merge (squash) March 6, 2026 09:34
@rgbkrk rgbkrk merged commit d085a0c into main Mar 6, 2026
14 checks passed
@rgbkrk rgbkrk deleted the 540/dead-sync-handle-methods branch March 6, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant