notes
All repositories: gitoria
8.7 KB
# notes mission 007 — notes#4: offline and sync in pure Hybriel — BUILT, one Hybriel gap (the editor offline)**notes-offline.js and sw.js are deleted**, along with their routes. The notes page is now plain Hybriel(`components/notes.hl`). `project.hl` has `offline = [Notes]`, so hl:web's generated worker, its kept state per user andits queue do the offline work. No hand-written JS is added (login.js and the vendored md-editor.js stay, as before).Branch w7. Not pushed, not deployed.## Hybriel #166 first (repros of mission 005, re-run on the vendored 0f396652)- `repro-rowkidless`: `client booted (window.__hl): true rows: one,two`. It was `false` + a TypeError on a832f73b.- `repro-rehydrate`: `offline reload: client booted (window.__hl): true rows: one,new`. Fixed.- `proto` (the design probe): an offline put is queued, kept over an offline reload, and replayed when back online. Theserver has both puts.## What was built (design of report 001)- `lib/notes.hl`: `notesFor(user)` gives the page's list. A save carries `by` (the login tag) and `since`; a save whose`by` + `base` match the note's `by` + `since` CONTINUES that browser's run, so queued saves made from one old base donot conflict with each other. The conflict rule is unchanged: the later edit wins and the other version becomes acopy. A browser that lost keeps writing into ITS copy (`copyOf`, `by`, `since`) instead of making a new copy forevery save. `removeNote` finds a never-synced note by `local`. The field is named `since` because `from` is areserved word.- `components/notes.hl`: `notes` (server-fed, kept offline). `rows` = notes, then `__hlQueue`, then this tab's`edits`, derived in the browser (the helper statics stay in this file). Statement-form faces `notesPut` and`notesDrop` are queued offline. Push `notesChanged(user, list)` goes to every tab of that user (audience inproject.hl). A 1 s CSS tick (`notesTick`) sends what was typed 0.6 s ago and calls the value-form `notesPull` every10 s and on `reconnected`. Sidebar links are claimed in place (`e.preventDefault()` + `history.replaceState`). A notemade offline has the id `l…` until its first save lands; then the address follows the server id. Log-out is the face`notesLogOut`, after which hl:web forgets that user's state, queue and documents. The UI keeps the same tags and ids.- The JSON API `/api/notes` stays (the gate uses it to read the server), now with `by` = '' (no continuation).## Works offline (gate, real Chrome, CDP offline on the page AND its worker, always RELOADED offline first)The kept page boots from hl:web's worker with no socket. It shows the list and the open note, and says "Offline — …".An existing note was edited and a new note written, both with real keys. Both wait in hl:web's queue and the serverhas neither. After another offline reload both are still there. Back online, the server has both, the new note has aserver id (in the address too), and device B shows the edit in its open note. Two devices both offline (serverstopped): B's later edit is the note and A's is kept as a copy. One device offline in Chrome and one online: the onlineedit wins, the offline one becomes a copy, and A's editor then shows the winner. Log-out: no note text is left in anyIndexedDB database, the queue is empty, and no kept document holds a note. PWA: manifest, icons, installable, andexactly one worker (`/__hl/sw.js`); `/sw.js` and `/notes-offline.js` answer 404.## Hybriel gap (Atlas → Anton) — this part is stopped, no workaround**hl:web offline keeps no app `file`/`directory` route, and an app cannot add a URL to the worker's precache.**- The page boots offline, but a script it loads from its own route (notes: `/md-editor.js`, the Markdown editor)fails to load.- Without the script the note opens in the plain `<textarea>` that `<md-editor>` wraps. Typing, the queue and sync allwork, but there is no Markdown view or toolbar until a reload online. Today's sw.js kept it.- Cause: `worker.hl answer()` → "everything else goes to the network untouched". `WebFramework.hl precacheList()`holds only the runtime, the package halves, the stylesheet, the modules, the manifest, the icons, the favicon andthe kept pages.- Repro: `notes-w7/.scratch/w7/repro-appfile/`. Run `REPRO_PORT=8731 ../../../bin/hybriel project.hl`, then`node run.mjs`. Output: `online: … widget.js ran: true` / `kept by the worker: /__hl/hl-runtime.js /__hl/app.css/__hl/web/client.js /page.hl /__hl/manifest.webmanifest /` / `offline: page shown: true widget.js ran: false`.- Proposal: an `offlineFiles = ['/md-editor.js', …]` setting, or keep every `file` route a kept page's View loads(`script { src }` / `link { href }` literals).- The gate checks this and FAILS on it (2 checks, below). I did not change the md-editor route's cache headers: thatwould be a workaround.## Gate (`NOTES_GATE_PORT=8720 NOTES_GATE_IDENT_PORT=8721 NOTES_GATE_CHROME=8722-8729 node tests/browser.mjs`)- Old code, old gate: **57 passed, 0 failed**.- New code, new gate: **62 passed, 2 failed** (64 checks). Both failures are the gap: "the Markdown editor is thereoffline" and "tables: offline … with the table" (the text itself is there).- Rewritten (they tested the JS files):- the worker keeps the page and the shell (`hl-shell-*`);- exactly one worker, `/__hl/sw.js`; `/sw.js` and `/notes-offline.js` answer 404;- the offline section now runs on Chrome offline instead of a stopped server;- the sync waits: socket open and hl:web's queue empty (was `__notesOffline.sync()`);- log-out scans every IndexedDB and every kept document.- New checks:- no hand-written notes JS on the page;- the offline reload booted from the worker with no socket;- the editor is there offline;- the offline edits wait in the queue while the server has neither;- three checks for one device offline and one online.- **Fails on old code** (the new gate against `git archive 0176c4b`, `NOTES_GATE_SOFT=1` so that a timed-out wait doesnot stop the run): 58 passed, 6 failed. That run was 59/6; the +1 is the check removed later, which passedthere. The failures:- hl:web worker keeps the page and shell;- one `/__hl/sw.js` worker;- no hand-written JS;- the sidebar says it is offline (old JS never says it under CDP offline);- the edits wait in hl:web's queue;- the one-offline precondition (A's edit waits in the queue).- Passing on old code as well, as they should (same behaviour as today): the one-offline conflict outcome, both log-outchecks, and "the editor is there offline" (old sw.js kept md-editor.js; the new code fails it = the gap).- The log-out check passes on old code, so I ran it on a mutated copy where `client.hl forget()` returns at once:it fails (61/3; the run was 62/3 with the since-removed check passing).- A check that did not fail under that mutation ("offline reload after log-out shows no notes") was removed.- Flake: "B follows the delete" timed out in 1 of 6 runs and did not come back in the later runs.`NOTES_GATE_DEBUG=1` dumps both devices' state if it happens again.## Real data (`node tests/realdata-offline.mjs <newest backup> 8720 8722-8726`)- Data: `notes.worldapi.org-20261019-2028.tgz`, storage/mpackdb only, as a copy (deleted after: `copy deleted: true`).The session is a file for az5b2 → 0muh6o5a3kkd.- **6 passed, 0 failed**:- all **28** live notes are listed by id;- after an offline reload, 28 are listed with no socket;- an edit typed offline with real keys is not on the server while offline;- back online, it is in the SAME note (no copy, still 28 notes);- the server logged no error.- The mission said 49 notes. This backup has 42 note records: 28 live and 14 tombstones.## Screenshots: checked as text and colours (computed styles + PNG pixel counts, no image viewer)- Every shot: header rgb(15,20,25) (token `darker`), page rgb(25,30,35), brand rgb(220,220,170) yellow, nohorizontal overflow.- 1280: list 320 px beside the reader 889 px.- 390: the list is hidden while a note is open, the reader is 358 px.- Offline: the md-editor surface rgb(35,40,45) is gone (phone 3.9 % → 0 %); the plain textarea (dark, 358/889 px)shows instead (the gap).- Files: `.scratch/gate-*.png` and `.scratch/realdata-{390,1280}-{online,offline}.png`.## Not covered- A log-out made while offline: `notesLogOut` is a statement-form face of the shell, not of the kept page.- Text typed less than ~1 s before Log out is not sent: the tick has not fired yet. The old JS sent it first.## Commits (branch w7)510aff7 server continuation · e5785b0 the page in Hybriel · 52a2aca gate · 632223f delete notes-offline.js + sw.js ·7f6a409 README + realdata-offline · 2cce9c9 code order (`let` 0 never reassigned) + gate soft/debug · (this report).Nothing of mine is left running on 8720–8739.
Branches
Latest commits
- 3a8bc0d2N5: empty Table-button table is written as a real pipe table (MdEditor 4bd1112, plain copy); gate tests/table-button.mjs; reportmre
- c16bd443N5: step 1 report (tables pass locally; his DASHBOARD note has no delimiter row)mre
- 6091320anotes: MdEditor 7437e32 (surface drawn at once when the page is claimed); gate measures claim-to-text on 5 note loads at 1280 and 390mre
- 0aa9277enotes: move each component's styles into its own Style block (shell and header selector in main.hl, list, editor frame and delete question in notes.hl); styles.hl keeps the theme inherit, the accent and the message colour; .gitignore ignores a bin symlink too; tests/shots.mjs for the pixel comparemre
- 9ba01de3notes: write the standby service out in full so the boot gate can read the main servicemre
- 98cab40anotes: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
- 1fadb473notes gate: the editor table now has 1 px cell lines from the notes thememre
- 8762115cnotes: take the components e54f83a (paste as Markdown, text typed before the editor is built is kept, Table button); table lines come from the notes thememre
- ac23e194ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 2804f0d3Merge branch 'iw-ident-widget'mre
- 52d8d242notes: e2e script checks Log out and the selector in the header instead of the user menumre
- e5abf7b7notes header: the selector alone top right plus Log out as before the theme missions; the user icon is gonemre
- a2e343aeident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 7a889b82notes: MdEditor with the Table button, typed pipe rows and the theme's table look (components mt-tables); a table note is named by its header words; gate checks that fail on mainmre
- b96c7f70theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 6140e6a0sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- cb7e6469deploy: security gate (tests/security.mjs)mre
- 774bf34bnotes security: CSRF guard on /api/notes, new session at login, Secure cookie, uploadMax 0, login rate limit, nosniff, face payload check; tests/security.mjs; SN reportmre
- ef18a68fsync components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
- c37488b1MN report: alignment updatemre