Skip to content

Read notebooks kept as one file per page, read-only (#274) - #282

Closed
OskarRabenda wants to merge 1 commit into
mainfrom
claude/issue-274-page-files
Closed

OskarRabenda wants to merge 1 commit into
mainfrom
claude/issue-274-page-files

Conversation

@OskarRabenda

Copy link
Copy Markdown
Collaborator

Refs #274. This is step B1 of the per-page storage design (review page: https://claude.ai/artifact/7Rx578iiyCVc9UBhahPjEr).

This build reads the new layout but never writes it, so it can ship one release before the writer. That way an iPad and a laptop a release apart can both open what the newer one writes. It is a draft because it fixes the on-disk format: please agree to the format before it is merged.

Format

  • The notebook file keeps its frontmatter, prose and text block. Its ink block becomes a manifest: v2+page-files:, the notebook's settings and the ordered list [{id, file}].
  • Each page is Pages/<id>.md beside the notebook file, holding one %%finenotes-page block with that page's payload, labelled with the features the page uses.
  • Page files are .md because Obsidian Sync skips other file types unless each device turns that on.
  • They use their own block label, so nothing that reads notebooks takes a page file for a one-page notebook.

Safety

  • The plain decoder refuses a page-files payload. Every whole-file reader therefore sees "unreadable" and skips it, including relinking, page transfer, calc notes and page embeds. The view's load guard holds it.
  • Builds before this one refuse the unknown feature label and hold the notebook read-only, as they do for any newer feature.
  • Page file names from the manifest are resolved only to .md files below the notebook's folder: no .., no absolute paths, no backslashes.

Changes

  • src/model/serialize.ts: splitDocument (the writer, used only by tests until B2), readPageFilesManifest, readPagePayload, assemblePageFiles.
  • src/model/page-files.ts: page file text, names, safe paths, and notebookStat, which counts page files.
  • src/view/ink-view.ts:
    • A page-files notebook shows from its page files and stays held read-only, with a notice to update.
    • A page not synced yet shows blank, with its own notice, and is read again when its file arrives.
  • src/view/library-pages.ts, library-view.ts:
    • Home reads these notebooks from their page files on the main thread.
    • Every notebook stamp in Home now counts the Pages/ files, so a page saved alone refreshes the card.
  • src/i18n/en/view.ts: two notices, in English only; other languages show the English until translated.

Tested

  • CI gates pass: typecheck, lint, lint:review, format:check, test, build.
  • On this loaded laptop the full suite needed --maxWorkers=3; with all workers, unrelated tests timed out.
  • New tests:
    • tests/model/page-files.test.ts: round trip byte for byte, sizes, refusal by the plain decoder, missing and foreign pages, names, paths.
    • tests/view/ink-view-file.test.ts: shown read-only, nothing written, a late page read on arrival.
    • tests/view/library-pages.test.ts: Home's count and text, a one-file notebook beside a Pages folder, the stat.
  • Not run in real Obsidian, on an iPad, or with a real sync. Nothing writes the format yet, so there is nothing to see in the app without a hand-made notebook.

Not in this PR (B2, after the design is agreed)

  • Writing: the "Store pages separately" item in a notebook's ⋯ menu, and saves that write only touched pages.
  • Pages/ in OWN_FOLDERS, so it moves and is hidden with the notebook.
  • Relinking page files after a file moves.
  • Page embeds that read one page file.
  • Export › Notebook as one file.

🤖 Generated with Claude Code

The first step of storing each page in its own file: this build reads the
layout but never writes it, so a device one release behind the writer can
still open such a notebook.

- serialize.ts: `splitDocument` makes a manifest (labelled `page-files`)
  and one payload per page; `readPageFilesManifest`, `readPagePayload` and
  `assemblePageFiles` put the notebook back together. The plain decoder
  refuses a `page-files` payload, so every whole-file reader sees an
  unreadable notebook and never saves its pages as empty ones.
- model/page-files.ts: page files (`Pages/<id>.md`, one `%%finenotes-page`
  block), safe paths below the notebook's folder, unique names, and a stat
  that counts the page files for Home.
- InkView: a page-files notebook is shown from its page files and stays
  held read-only; a page not synced yet shows blank and is read again when
  its file arrives.
- Home: reads such a notebook from its page files, and keys its reads on
  the page-aware stat, so a page saved alone refreshes the card.

Refs #274

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8

Joost-8 commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks Oskar, the reader you started is in #286 in a changed layout, so I'm closing this one. Two notebooks in one folder would have shared Pages/p1.md (page ids repeat across notebooks), and Sync could still merge two devices' edits to one page file. The new layout is Pages/<notebookId>/<pageId>.<deviceId>.md: each device writes only its own files, with per-device meta, version vectors and change stamps per element. Your decoder refusal, safe paths, Home counting and read-only hold carried over. The writer comes next release.

@Joost-8 Joost-8 closed this Nov 21, 2026
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.

2 participants