append_layer: write strokes onto a tablet page in our own layer #72

Manually merged
jfro merged 13 commits from feature/51-append-layer into main 2026-11-11 15:42:45 +00:00
Owner

Refs #51. Spike for in-page write-back (docs/todo-sync.md, Write-back; D20, D22, D23). Writer only: nothing calls it yet, and nothing writes to the cloud.

What it adds

  • Lines.Writer.append_layer(original_rm, strokes, author_uuid): adds strokes to a page the tablet wrote, in a layer of our own, "rM-Analyzer".
    • Every original block is copied byte for byte, except the 0x09 author ids block. That one gets our device UUID added, or keeps it if an earlier write already added it.
    • The first write adds the layer after the page's last layer: a 0x01 tree entry, a 0x02 node and a 0x04 group item under the root. Later writes find it by the author number in its node id (F5, D27), not its label, so a layer renamed on the tablet is still reused. Our author number is never the tablet's 1, even on a page listing no authors (N8).
    • Strokes become 0x05 line items by our author, each after the one before and after the strokes already in our layer. Their counters are above every counter on the page.
    • Returns {:ok, rm, %{layer: id, stroke_ids: [...]}}. A page that isn't v6, is cut off, or has no author block gets an error sentence.
  • Lines.parse keeps each stroke's item id (Stroke.id, {author, counter}). The layer's author is its id's first element. That's what D22 needs to find our strokes again.
  • Fixtures: two tablet-written pages from rmscene's test data (MIT): two layers on 3.3.2, and highlights plus a scene info block on 3.14.4.

Checked

  • Golden test on both fixtures: every block but 0x09 is identical, then exactly tree, node, group item and the lines. Lines.parse returns the original layers unchanged, with ours on top. A second write reuses the author and layer, and its ids are higher.

  • rmscene 0.6.1 read_tree reads both written pages: the original layers as they were plus "rM-Analyzer" with 3 strokes, and 2 authors.

  • mix precommit: 1128 tests, 0 failures (ae62732).

  • PageInk.plan replaces only <doc>/<page>.rm and keeps every other file as the cloud has it; Commit.plan must add nothing.

  • PageInk.write(account, ink, expected_hash): writes only while the page is still the version we read (else {:skipped, :page_changed}) and the notebook has been quiet 10 min (else {:skipped, :tablet_busy}). On a 412 it syncs and plans again from the new bytes, up to 3 times. The old page stays in the blob store, and the page's current text is carried to the new hash (W1). Logs page, old/new hash, generation, attempt, duration.

  • OCR leaves out our layer (D22): Scene reads the author ids, and Scene.without_author/2 drops layers whose node id has the device's number. Only numbers 2 and up count. A page the app drew whole lists the app as 1, and a layer the user adds there has to stay readable. TranscribeWorker uses it both for the handwriting check and for the image (PageImage.png(..., without_author:), rendered fresh only when the page has our layer). Tests: the image matches the page without our layer, and a page with only our marks isn't sent to OCR (C30).

Not yet: the tablet test 2a–2c (D23), which is the go/no-go. (The geometric tick, Lines.Marks, landed in 5badeb7/803f4c2.)

d80680d: row-geometry task finder (D31/D32). Lines.Rows.find(scene, author, layout) returns all 36 rows of a todo page: row k is the band (rule k-1, rule k], a stroke belongs to the row holding its bbox's vertical centre, and it's writing only when its horizontal centre is right of the margin. Each row has the user's stroke ids (his), ours by author number in any layer (ours), and ticked from Marks.ticked/3 in the row's printed box. tasks/1 = rows with his writing (a tick in an empty row's box is ignored; ordinal = row index), next_free/1 = first empty row below the lowest written one, or :full, and outside/3 counts his writing below the last rule so the caller can hold the page. The layout (rules, margin, boxes) is the template's 1404×1872 geometry, passed in so this branch doesn't depend on #71; the sync passes Todos.Template.boxes/0 once both are in. Scene coordinates (x centred, the page's own size) are mapped onto it the way the template's sx/sy scale on the tablet. 8 tests, incl. our strokes vs his in our layer and a Paper Pro-sized page. Risk: the Paper Pro mapping is reasoned from sx/sy, not seen on a tablet.

Refs #51. Spike for in-page write-back (docs/todo-sync.md, Write-back; D20, D22, D23). Writer only: nothing calls it yet, and nothing writes to the cloud. **What it adds** - `Lines.Writer.append_layer(original_rm, strokes, author_uuid)`: adds strokes to a page the tablet wrote, in a layer of our own, "rM-Analyzer". - Every original block is copied byte for byte, except the 0x09 author ids block. That one gets our device UUID added, or keeps it if an earlier write already added it. - The first write adds the layer after the page's last layer: a 0x01 tree entry, a 0x02 node and a 0x04 group item under the root. Later writes find it by the author number in its node id (F5, D27), not its label, so a layer renamed on the tablet is still reused. Our author number is never the tablet's 1, even on a page listing no authors (N8). - Strokes become 0x05 line items by our author, each after the one before and after the strokes already in our layer. Their counters are above every counter on the page. - Returns `{:ok, rm, %{layer: id, stroke_ids: [...]}}`. A page that isn't v6, is cut off, or has no author block gets an error sentence. - `Lines.parse` keeps each stroke's item id (`Stroke.id`, `{author, counter}`). The layer's author is its id's first element. That's what D22 needs to find our strokes again. - Fixtures: two tablet-written pages from rmscene's test data (MIT): two layers on 3.3.2, and highlights plus a scene info block on 3.14.4. **Checked** - Golden test on both fixtures: every block but 0x09 is identical, then exactly tree, node, group item and the lines. `Lines.parse` returns the original layers unchanged, with ours on top. A second write reuses the author and layer, and its ids are higher. - rmscene 0.6.1 `read_tree` reads both written pages: the original layers as they were plus "rM-Analyzer" with 3 strokes, and 2 authors. - `mix precommit`: 1128 tests, 0 failures (ae62732). - `PageInk.plan` replaces only `<doc>/<page>.rm` and keeps every other file as the cloud has it; `Commit.plan` must add nothing. - `PageInk.write(account, ink, expected_hash)`: writes only while the page is still the version we read (else `{:skipped, :page_changed}`) and the notebook has been quiet 10 min (else `{:skipped, :tablet_busy}`). On a 412 it syncs and plans again from the new bytes, up to 3 times. The old page stays in the blob store, and the page's current text is carried to the new hash (W1). Logs page, old/new hash, generation, attempt, duration. - OCR leaves out our layer (D22): `Scene` reads the author ids, and `Scene.without_author/2` drops layers whose node id has the device's number. Only numbers 2 and up count. A page the app drew whole lists the app as 1, and a layer the user adds there has to stay readable. `TranscribeWorker` uses it both for the handwriting check and for the image (`PageImage.png(..., without_author:)`, rendered fresh only when the page has our layer). Tests: the image matches the page without our layer, and a page with only our marks isn't sent to OCR (C30). **Not yet:** the tablet test 2a–2c (D23), which is the go/no-go. (The geometric tick, `Lines.Marks`, landed in 5badeb7/803f4c2.) **d80680d: row-geometry task finder (D31/D32).** `Lines.Rows.find(scene, author, layout)` returns all 36 rows of a todo page: row k is the band (rule k-1, rule k], a stroke belongs to the row holding its bbox's vertical centre, and it's writing only when its horizontal centre is right of the margin. Each row has the user's stroke ids (`his`), ours by author number in any layer (`ours`), and `ticked` from `Marks.ticked/3` in the row's printed box. `tasks/1` = rows with his writing (a tick in an empty row's box is ignored; ordinal = row index), `next_free/1` = first empty row below the lowest written one, or `:full`, and `outside/3` counts his writing below the last rule so the caller can hold the page. The layout (rules, margin, `boxes`) is the template's 1404×1872 geometry, passed in so this branch doesn't depend on #71; the sync passes `Todos.Template.boxes/0` once both are in. Scene coordinates (x centred, the page's own size) are mapped onto it the way the template's `sx`/`sy` scale on the tablet. 8 tests, incl. our strokes vs his in our layer and a Paper Pro-sized page. Risk: the Paper Pro mapping is reasoned from `sx`/`sy`, not seen on a tablet.
fix(remarkable): our author number is never the tablet's 1 (N8) (refs #51)
Some checks failed
CI / test (pull_request) Has been cancelled
5a7a64d674
feat(ocr): OCR leaves out rM-Analyzer's own layer (D22, refs #51)
Some checks failed
CI / test (pull_request) Has been cancelled
ae627328b5
Scene reads the page's author ids. Scene.without_author/2 drops the layers
whose node id carries an author's number (2 or more, as append_layer gives
itself; a page the app drew whole lists it as 1, and a layer the user adds
there must still be read). TranscribeWorker reads pages without the
account's device layer, both for the handwriting check and the image sent
to the provider, so todo sync's marks never come back as tasks.
The tablet draws into whichever layer is selected, and ours is the top one
after a write. Scene.without_author and Marks.ticked now drop only strokes
whose item id carries our number (and our layers left empty), so the user's
writing and ticks in our layer still reach OCR and the tick finder.
Marks.present finds our stored strokes in any layer (N11), and PageInk.write
carries the page's text to the new hash before syncing (N9). A test pins
that an odd author block is skipped rather than fatal (N10).
outside/3 counts only strokes above the page; a tick in a printed box is in the margin, not outside (F7).
A stroke whose centre is in the top third of a band, just under rule k, while row k has writing, joins row k: a separate g/y tail or an underline, not a phantom task in row k+1 (F8).
The tick glyph strip takes an optional U+FE0F after the glyph and knows ✅, ✗, ✘ (F9).
A stroke centred above row 0's band (y < rule_y - line_height, per repeat)
is the title: no task, not outside. title/3 gives his strokes in the first
page's band; texts/3 drops OCR's first line when there are any and returns
it as the title ({:ok, pairs, title | nil}). A repeat's band writing has no
line dropped, so it holds the page.
fix(lines): drop each repeat title band's OCR line, never hold the page (D40, F11; refs #51)
All checks were successful
CI / test (pull_request) Successful in 2m7s
dfb611a6db
Rows.title/3 now returns the user's writing in every title band, keyed by
the first row the band heads (0 for page 1's). texts/3 places each band's
line in reading order, before the rows below it, and drops it before
pairing; page 1's is still returned as the title. A plain list of ids
still means page 1's band alone.
jfro changed title from WIP: append_layer: write strokes onto a tablet page in our own layer to append_layer: write strokes onto a tablet page in our own layer 2026-11-11 15:40:14 +00:00
jfro manually merged commit 4a417c0992 into main 2026-11-11 15:42:45 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/rm-analyzer!72
No description provided.