Todo sync write loop (two-way: app changes onto the page) #73

Manually merged
jfro merged 50 commits from feature/51-write-loop into main 2026-11-11 15:42:44 +00:00
Owner

Closes #51 (D45: the last PR of the todo sync closes it; #70 says Refs #51).

Stacked on #72 (feature/51-append-layer, dfb611a); #70 (groundwork) and #71 are now on main, merged in at e9cf2c6. Parents are merged in again when they move, never rebased.

In this PR so far

  • Todos.Diff.plan/3: the one-way diff for a mapped page (docs/todo-sync.md, Matching and guards): creates, retexts, completes/reopens only on a changed box, deletes with the mass-removal hold, same-version guard.
  • Todos.SyncWorker: reads the page by row geometry, runs the diff, calls the provider. Cancels when there's no text yet, the page moved on, or sync isn't set up; waits on writing above the rows or a row/line count mismatch (D33).
  • Todos.WriteBack: writes app changes onto the page; an untick erases only our tick's strokes (N22).
  • Settings > Todo sync (new): the Vikunja URL and API token when VIKUNJA_URL / VIKUNJA_TOKEN are unset. Each env var, when set, wins and is shown read-only, and is never saved over. VIKUNJA_TOKEN without VIKUNJA_URL is refused at boot, so the server's token only goes to the server's URL. A URL entered here is checked like a spellcheck one (public, or in BACKUP_S3_ALLOWED_NETWORKS) and called at the checked address. The token is stored encrypted and never shown. No defaults. Test connection lists the token's projects and is logged with status and duration.
  • Nye's N24 (his note beside our line isn't a new task) and N25 (no duplicate on a same-version retext), with tests.
  • Todos.PollWorker (M5, two-way): after each tablet sync, the app's changes are written onto the page (done -> tick, reopened -> our tick erased, deleted -> struck, new open task -> next free row). F16: an app add done/deleted before its line is written is dropped, not marked on row 0.
  • Nye's N27-N30 (5417ccf): a URL moved to another host with the token left blank isn't saved ("enter the token for the new server"); with VIKUNJA_URL set, the token field says the URL it's sent to; VIKUNJA_URL without a host is refused at boot; each sync and poll sets/clears the settings' last error, so a bad token or a down server shows on the settings page.
  • Test UI (D53, a2e4e66 + 0a3324d), so the tablet test needs no iex or copied ids: the viewer's page bar has Sync todos (pick a Vikunja project, or "New project…" by name, then Map page; once mapped it says "Todos synced with " with Sync details and Unmap; when sync isn't set up it says so and links Settings > Todo sync). /todos/pages/:id is the page's sync panel: waiting for its transcription / edits not read yet / ready, the last read of the page, check of the app and write onto it with times and counts (a skip says why), the last error, and each task with its app state, pending write, task link and whether our strokes for it are still on the page (Marks.present). Sync this page now queues its poll. Back up cloud in Settings > Todo sync runs the same snapshot as mix remarkable.snapshot, with a toast. New: Provider.create_project/2 (optional; Vikunja POST /projects, logged), Todos.list_projects/2, create_project/3, unmap_page/2, sync_page_now/2, record_page/4, marks_present/3, Remarkable.Snapshot.backup/1, migration for the page's run status.

Still to do

  • Status page entries (held removals, mismatch, page full, failures)
  • D36: list the project matching the page's title first in the picker
  • Test button's permission breakdown (doc, Settings)
  • Tablet test (2a-2c) marked done by Jeremy at a6d59ef (D23, D55). Merge after #72.

mix precommit passes at 0a3324d (1331 tests).

Screenshots (59d1d49, against a local Vikunja 2.8 with example projects)

390px Desktop
Not set up
Saved and connected
Set by env vars (read-only)

Screenshots (5417ccf, N27/N28)

N27, the URL moved to another host with the token blank (390px, desktop):
n27 390 n27 desktop

N28, VIKUNJA_URL set by the server and the user's own token (390px, desktop):
n28 390 n28 desktop

Screenshots (0a3324d, test UI, local Vikunja 2.8, example notebook)

The example page is a test fixture, not the todo template, so our line sits over its text; the 1-of-1 / 26-of-26 counts are our tick's and line's strokes found on the page.

390px desktop
Viewer: picking "New project…"
Viewer: page mapped
Sync panel, after Sync this page now
Settings: Back up cloud
Closes #51 (D45: the last PR of the todo sync closes it; #70 says Refs #51). Stacked on #72 (feature/51-append-layer, dfb611a); #70 (groundwork) and #71 are now on main, merged in at e9cf2c6. Parents are merged in again when they move, never rebased. ## In this PR so far - **Todos.Diff.plan/3**: the one-way diff for a mapped page (docs/todo-sync.md, Matching and guards): creates, retexts, completes/reopens only on a changed box, deletes with the mass-removal hold, same-version guard. - **Todos.SyncWorker**: reads the page by row geometry, runs the diff, calls the provider. Cancels when there's no text yet, the page moved on, or sync isn't set up; waits on writing above the rows or a row/line count mismatch (D33). - **Todos.WriteBack**: writes app changes onto the page; an untick erases only our tick's strokes (N22). - **Settings > Todo sync** (new): the Vikunja URL and API token when `VIKUNJA_URL` / `VIKUNJA_TOKEN` are unset. Each env var, when set, wins and is shown read-only, and is never saved over. `VIKUNJA_TOKEN` without `VIKUNJA_URL` is refused at boot, so the server's token only goes to the server's URL. A URL entered here is checked like a spellcheck one (public, or in `BACKUP_S3_ALLOWED_NETWORKS`) and called at the checked address. The token is stored encrypted and never shown. No defaults. Test connection lists the token's projects and is logged with status and duration. - Nye's N24 (his note beside our line isn't a new task) and N25 (no duplicate on a same-version retext), with tests. - **Todos.PollWorker** (M5, two-way): after each tablet sync, the app's changes are written onto the page (done -> tick, reopened -> our tick erased, deleted -> struck, new open task -> next free row). F16: an app add done/deleted before its line is written is dropped, not marked on row 0. - Nye's N27-N30 (5417ccf): a URL moved to another host with the token left blank isn't saved ("enter the token for the new server"); with `VIKUNJA_URL` set, the token field says the URL it's sent to; `VIKUNJA_URL` without a host is refused at boot; each sync and poll sets/clears the settings' last error, so a bad token or a down server shows on the settings page. - **Test UI** (D53, a2e4e66 + 0a3324d), so the tablet test needs no iex or copied ids: the viewer's page bar has **Sync todos** (pick a Vikunja project, or "New project…" by name, then Map page; once mapped it says "Todos synced with <project>" with Sync details and Unmap; when sync isn't set up it says so and links Settings > Todo sync). **/todos/pages/:id** is the page's sync panel: waiting for its transcription / edits not read yet / ready, the last read of the page, check of the app and write onto it with times and counts (a skip says why), the last error, and each task with its app state, pending write, task link and whether our strokes for it are still on the page (Marks.present). **Sync this page now** queues its poll. **Back up cloud** in Settings > Todo sync runs the same snapshot as `mix remarkable.snapshot`, with a toast. New: `Provider.create_project/2` (optional; Vikunja `POST /projects`, logged), `Todos.list_projects/2`, `create_project/3`, `unmap_page/2`, `sync_page_now/2`, `record_page/4`, `marks_present/3`, `Remarkable.Snapshot.backup/1`, migration for the page's run status. ## Still to do - Status page entries (held removals, mismatch, page full, failures) - D36: list the project matching the page's title first in the picker - Test button's permission breakdown (doc, Settings) - Tablet test (2a-2c) marked done by Jeremy at a6d59ef (D23, D55). Merge after #72. `mix precommit` passes at 0a3324d (1331 tests). ## Screenshots (59d1d49, against a local Vikunja 2.8 with example projects) | | 390px | Desktop | |---|---|---| | Not set up | ![](https://git.knope.dev/attachments/50c15068-15f6-468a-8753-b72544e64326) | ![](https://git.knope.dev/attachments/344942da-bc2d-422a-b609-98562b1fc559) | | Saved and connected | ![](https://git.knope.dev/attachments/d2d4c1ba-d008-4424-b5bd-1055c1ca219c) | ![](https://git.knope.dev/attachments/ab8fb9a6-f931-4cc6-b1f1-f38046c4aa8d) | | Set by env vars (read-only) | ![](https://git.knope.dev/attachments/4de098ca-bee9-4e21-ad80-10937f7b6e44) | ![](https://git.knope.dev/attachments/4ae5b82b-f39e-47b8-bd42-57d8024ceb02) | ## Screenshots (5417ccf, N27/N28) N27, the URL moved to another host with the token blank (390px, desktop): ![n27 390](https://git.knope.dev/attachments/93f32b49-b863-4983-b081-a8f4a92b7eee) ![n27 desktop](https://git.knope.dev/attachments/de0a3ffc-cd21-4e2e-9a0f-60a28a302e95) N28, `VIKUNJA_URL` set by the server and the user's own token (390px, desktop): ![n28 390](https://git.knope.dev/attachments/a34b34dd-9f63-4407-bc8f-932b870f5c95) ![n28 desktop](https://git.knope.dev/attachments/4b5cbfbe-483c-4032-92b0-4fe01f08461c) ## Screenshots (0a3324d, test UI, local Vikunja 2.8, example notebook) The example page is a test fixture, not the todo template, so our line sits over its text; the 1-of-1 / 26-of-26 counts are our tick's and line's strokes found on the page. | | 390px | desktop | |---|---|---| | Viewer: picking "New project…" | ![](https://git.knope.dev/attachments/a433994e-6357-4389-83e3-74e230d7050f) | ![](https://git.knope.dev/attachments/593ac02c-f5c3-4bed-8728-553b42652c24) | | Viewer: page mapped | ![](https://git.knope.dev/attachments/205694e9-b523-4a1c-b308-d4e8aa49e5a9) | ![](https://git.knope.dev/attachments/a7236bbb-7b05-4b07-aeba-f213fb339c69) | | Sync panel, after Sync this page now | ![](https://git.knope.dev/attachments/1a02a713-3b0b-42ac-8b73-b3c290b808bc) | ![](https://git.knope.dev/attachments/86ee3a7b-cf63-4615-bd9b-1a4b2df5adfa) | | Settings: Back up cloud | ![](https://git.knope.dev/attachments/69384e37-05ee-48c1-8199-bec55ea9d7b3) | ![](https://git.knope.dev/attachments/d6189f88-ee95-483f-bd54-c58ba8a943ba) |
jfro added 31 commits 2026-11-08 22:11:15 +00:00
RmAnalyzer.Todos.Provider is what the sync engine will talk to; Vikunja
is its first adapter, over API v2 with Req, every call logged. Extract
reads a page's task items from its Markdown; Match pairs them with the
items as last synced. No schema, workers or UI yet: those wait on the
design being agreed.
docs(todos): Vikunja v2 calls as checked on 2.8.0 (#51)
Some checks failed
CI / test (pull_request) Has been cancelled
0b0d095e6d
feat(todos): restore_task/2 from Vikunja's trash, todos Oban queue (#51)
Some checks failed
CI / test (pull_request) Has been cancelled
f049286591
test(todos): load the adapter before checking restore_task/2 (#51)
Some checks failed
CI / test (pull_request) Has been cancelled
6ad5487279
F1: list_projects drops saved filters and Favorites (ids < 1).
F2: tasks that normalise to nothing ([illegible], emoji only) pair on the
same raw text or the same ordinal and section.
Nye's note: a 412 says the project is archived.
Nye's probes kept as regression tests.
Remarkable.NewTemplate writes a TemplateType item (.metadata, {} .content,
.template JSON) in one commit after a sync, like NewPdf. Todos.Template
builds the .template from Templates.segments/1, the same drawing the page
view uses: P Lines small's rules and a left margin. Settings > reMarkable
gets an Add to tablet card. docs/todo-template.md has the tablet check.
docs(todos): restore pseudo-project and empty-norm pairing lines (F4) (#51)
Some checks failed
CI / test (pull_request) Has been cancelled
85f4e0c378
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).
docs(todo-sync): F6 'our strokes' wording, N2 fallback edge cases
Some checks failed
CI / test (pull_request) Has been cancelled
80467f73a4
Jeremy's rM2 drew the 90°-turned rM2 item sideways (left edge ~75% down,
1404/1872), so the template is now one item for rm2 and rmPP, upright,
under a new id (the tablet caches thumbnails by id). Add to tablet takes
our earlier items 90a78e7e and 6c73ab67 out of the root in the same
commit (Commit.plan/3 remove:), logged, so the picker shows one.
Merge branch 'feature/51-todo-template' into feature/51-write-loop
Some checks failed
CI / test (pull_request) Has been cancelled
9a056dc9ef
Todos.PageMarks turns app-side changes into Hershey pen strokes on a mapped
page (D26, D31-D33): a check inside the row's printed box, a strike through
the row's writing, and a new task's text on the next free row right of the
margin, one row each. Adds with no free row come back as full (D24, page
full on Status). Long text is set smaller, then cut at a word with ...; the
mark keeps the text drawn. Extended pages draw a repeat down. with_ids/2
hands the writer's stroke ids back per mark, to store per task.

Todos.Template.layout/0 gives Rows its geometry; Rows.box/2, rule_y/2,
from_template/2 and to_template/2 are public for drawing; Report.ink_stroke/1
draws as reports do.
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).
Merge branch 'feature/51-append-layer' into feature/51-write-loop
Some checks failed
CI / test (pull_request) Has been cancelled
4bc561314a
# Conflicts:
#	lib/rm_analyzer/remarkable/lines/rows.ex
docs(todo-sync): F7/F8 row rules and F9 tick glyphs in Finding tasks
Some checks failed
CI / test (pull_request) Has been cancelled
691af3f97f
Merge feature/51-todo-sync (F7-F9 doc) into feature/51-write-loop
Some checks failed
CI / test (pull_request) Has been cancelled
4d17666158
feat(todos): todo_pages and todo_items tables and schemas
Some checks failed
CI / test (pull_request) Has been cancelled
8d1917a3ce
docs(todo-sync): D36 title band and toolbar-clear boxes
Some checks failed
CI / test (pull_request) Has been cancelled
756c0c3548
feat(todos): title band and toolbar-clear boxes on the Todo template (D36), new id (refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m48s
fe0c01ae44
Title rule at y 154.5 from the margin; 31 task rules from 258.5 every 52;
margin at x 220.5; boxes at x 160-190. Templates.rules/1 also gives
title_y and margin_x. d7fac201 joins stale_ids. Typed-page layout starts
right of the margin. Svg v6, settings icon, docs/todo-template.md.
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.
Template.layout/0 takes title_y and margin_x from Templates.rules/1. A
row with our writing only is a task to tick or strike; the strike runs
rule_lift + 10 above the row's rule; a tick on a row he ticked comes back
in already. Nothing is drawn in the title band. (refs #51)
docs(todo-sync): N17/N18 write-back for ticks and reopen
Some checks failed
CI / test (pull_request) Has been cancelled
46ca4f6a13
Merge feature/51-todo-sync (N17/N18 doc) into write loop
Some checks failed
CI / test (pull_request) Has been cancelled
7deb9c6134
feat(todos): erase our tick when a task is reopened in the app (N18)
Some checks failed
CI / test (pull_request) Has been cancelled
bae36ce22d
Lines.Writer.erase_layer/3 turns our line items into the tablet's own
deleted items, in place (deleted length 1, no value), only in our layer.
PageInk takes an :erase list and does it in the same write as any adds,
and writes nothing when the page wouldn't change. PageMarks plans
{:untick, ids} as an erase (skipped with no ids of ours, D37), and
TodoItem.drop_ids/2 drops the erased ids from the task.
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.
Merge feature/51-append-layer (dfb611a, F11) into feature/51-write-loop
Some checks failed
CI / test (pull_request) Has been cancelled
4a417c0992
docs(todo-sync): untick carries our tick's stroke ids, {:untick, ids} (Nye N21; refs #51)
All checks were successful
CI / test (pull_request) Successful in 2m14s
5fb8c13e2d
Merge branch 'feature/51-todo-sync' (N21 doc) into feature/51-write-loop
Some checks failed
CI / test (pull_request) Has been cancelled
fd314027e0
Todos context: map_page, list_items, provider_config (env when set, no
defaults), transcription_changed queues Todos.SyncWorker from
OCR.current_changed for live mapped pages at that version.

SyncWorker (todos queue, unique per user+page, newer version replaces the
waiting one): guards B1 (no text yet), page moved on, writing above the
page, D33 row/line mismatch; Rows -> texts -> Diff.plan/3 -> provider.
A flip saves its box only once the provider call succeeds, and the
version is marked applied only when every flip and delete went through.

WriteBack: PageMarks -> PageInk.write; an untick carries our tick's ids
only, never a task's line (N22), and stroke ids are saved or dropped
only after the write succeeds.
Settings > Todo sync: each env var wins and shows read-only; a user URL is
checked against Backups.Network and pinned; Test connection lists the
token's projects, logged with status and duration.
feat(todos): Vikunja changes_since, one paged listing for ids and changes (refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m40s
c5055a47b2
Merge main into feature/51-write-loop (design doc #74 + template #71; refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m40s
011070e759
# Conflicts:
#	docs/todo-sync.md
Merge main (#70 groundwork) into feature/51-write-loop
All checks were successful
CI / test (pull_request) Successful in 1m48s
e9cf2c6b04
Todo settings: Nye N27-N30 (refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m40s
5417ccf61a
N27: a URL moved to another host with the token blank isn't saved; the
saved token only goes to the server it was entered for.
N28: with VIKUNJA_URL set, the token field says the URL it's sent to.
N29: VIKUNJA_URL without a host (http:vikunja) is refused at boot.
N30: each sync and poll sets/clears the settings' last_error (upserted
Todos.record_run/2), so failures show on the settings page.
Todo settings: a URL entered after it was cleared needs its token (Nye F17, refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m41s
2f837d9925
Todo settings: the saved token typed in again counts as entered (Nye F18, refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m41s
47ba368ad0
A tick done in the app could stay 'to write' forever: a version whose read
was skipped or never queued (text before mapping) was never read again, and
a write skipped for the 10-minute quiet time had nothing to retry it. Now
the poll queues the missing read, an applied read queues the poll when
writes wait, a quiet-time skip schedules a poll after it, and Sync now
moves that retry up to now.
Todo sync: a tablet clock running ahead doesn't hold a write back (F20 clamp, refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m43s
4690378501
Todo sync: a write waits a minute of quiet on the tablet, not ten (Jeremy, D58, refs #51)
All checks were successful
CI / test (pull_request) Successful in 1m44s
a6d59efe7b
jfro changed title from WIP: Todo sync write loop (two-way: app changes onto the page) to Todo sync write loop (two-way: app changes onto the page) 2026-11-11 15:40:14 +00:00
jfro manually merged commit 97e46e8265 into main 2026-11-11 15:42:44 +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!73
No description provided.