gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit996768bf996768bf|||PR WIP sequence note creation before provisional-id adoptionAtlas996768bf/README.md

19.8 KB

  1. # notes.worldapi.org
  2. A notes app in Hybriel (hl:web). Log in with ident; the **sidebar** lists your notes by subject, last edited first;
  3. a click opens the note on the right, edited with the Hybriel MdEditor block (`components/md-editor/`); **New note** and **Delete note**.
  4. The notes are also kept **in the browser (IndexedDB)**: they open and can be edited offline, and sync with the server
  5. (and other devices) when the network is back. Concept: `CONCEPT.md`.
  6. ## How it works
  7. - **Subject** = the first non-empty line of the note without leading `#` (at most 80 characters); an empty note is
  8. "Untitled note". No separate title field.
  9. - **Markdown** = what the MdEditor block shows and writes (`components/md-editor/`, no server-side renderer): headings, lists, code,
  10. links, emphasis and (notes#5) **GitHub pipe tables** — header row, `| --- | :-: | --: |` (alignment), body rows, outer pipes
  11. optional, `\|` = a pipe in a cell, inline Markdown in cells. Typing `| a | b |` ⏎ `|---|---|` ⏎ makes the table; Tab /
  12. Shift+Tab go from cell to cell (Tab in the last cell adds a row), Enter adds a row, Enter in an empty last row leaves the
  13. table. A line with pipes but no delimiter row stays text. Wide tables scroll inside their box.
  14. - **Order** = `edited` (ms), last first. Only a *changed* text moves a note to the top.
  15. - **Pages**: `/` (the list; on a phone the list alone) and `/note/:id` (the note; on a phone it replaces the list,
  16. "All notes" leads back; from 50rem wide both show side by side). Signed out: only "Log in with ident".
  17. - **Offline + sync** (tickets notes#2, notes#4 — plain Hybriel since mission 007, no JavaScript of our own):
  18. `project.hl` `offline = [Notes]` makes hl:web register its generated service worker (`/__hl/sw.js`), keep the page
  19. document and the page's state (the user's notes, as the server last said) in the browser (IndexedDB `hl-offline`,
  20. per user), and queue the saves and deletes made without a network (replayed in order when the socket is back).
  21. `components/notes.hl`: the list = the server's notes, then the queue, then this tab's typed edits laid over; what was
  22. typed goes to the face `notesPut` about 0.6–1.6 s later (a 1 s CSS tick, `notesTick`), every save or delete pushes
  23. `notesChanged` to every tab of that user, and every 10 s (and on a reconnect) `notesPull` asks for the other devices'
  24. changes. A note made offline gets a local id (`l…`) and its server id when its first save arrives (the address
  25. follows). **Continuation**: a browser's queued saves all carry the same old `base`; the server accepts a save whose
  26. login tag (`by`) and `base` match the note's `by` + `since` as the next one of that run. **Conflict** (changed here and
  27. elsewhere): the later edit wins, the other version is kept as a copy note ("kept as a copy …" line at its end); a
  28. browser that lost keeps writing into its copy (`copyOf`, `by`, `since`), and its editor then shows the winner. A
  29. delete of a note changed elsewhere meanwhile is refused (the changed note stays). Deleted notes stay on the server as
  30. tombstones (`gone`). Log out (the face `notesLogOut`): hl:web forgets the kept state, queue and documents of that user.
  31. The editor offline: the MdEditor block is Hybriel in the page itself, so there is no editor script to keep (mission 010:
  32. `offlineFiles` and `/md-editor.js` are gone). It builds its surface when the page is live (a 100 ms CSS animation: a
  33. background tab that does not run animations shows an empty surface until it is in front).
  34. - **Private**: every function in `lib/notes.hl` takes the owner's user id and only reaches that user's notes; another
  35. user's note id answers "does not exist"; saving/deleting it is refused. A note is at most 200 000 characters
  36. (refused, never cut).
  37. - **Login**: ident's button flow (`/login/callback` → `?ident_code=` → server-side exchange) plus the identity
  38. selector, as in gitoria; the session cookie is `notessid`, idle time 14 days. The session carries the users `@id`
  39. only; the ident identity id never leaves the server.
  40. - **Short ids (ident#23, antcolony mission 039)**: `users.identity` holds what ident's exchange answers — since ident#23 the identity's
  41. public 5-character short id (`a68sz`), before that the per-app id (32 hex); `lib/util.hl isIdentId` accepts both (the old
  42. `isHex` check refused short ids). The switch: one-off `tools/migrate-short-ids.hl` (old → short id, idempotent, never
  43. `finish`), gate `node tests/short-id-switch.mjs` (ports 8720/8721, no browser), runbook
  44. `antcolony-docs/docs/short-id-switch.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/short-id-switch.md` once synced).
  45. ## Files
  46. Code order (antcolony `docs/code-order.md`, notes mission 002): `project.hl` is the map (config, routes, audience, an
  47. index of which file handles what); one `lib/` file per topic holds its central logic, `lib/<topic>-helpers.hl` what it
  48. looks up; the function routes are thin wrappers. `let` only for a variable that is reassigned (or re-bound in a loop
  49. body). Imports go one way: util ← users, notes-helpers ← notes ← api-helpers ← api ← project.hl.
  50. | file | what |
  51. |---|---|
  52. | `project.hl` | the map: index comment, PWA config, routes, audience, server |
  53. | `lib/notes.hl` | `notes` table (`@id`, index `owner`; `{ owner, text, created, edited, gone, local, by, since, copyOf }`), every write to it: save (`pushNote`: continuation, conflict copy) / delete (`removeNote`), `notesFor` (the page's list), `metaRows`, `noteView` |
  54. | `lib/notes-helpers.hl` | size limit (`textError`), `isAlive` (tombstones), `stampOf` (version stamps), `copyMark` |
  55. | `lib/users.hl` | `users` table (`@id`, `!identity`), ident config + exchange, `userOfLoginCode` (both logins), `userIdOfSession`, `tagOf` |
  56. | `lib/api.hl` | the function routes: `/login/callback` (+ `loginFailed`; take `&req`, `&sessions`), `/api/me`, `/api/notes` |
  57. | `lib/api-helpers.hl` | JSON `reply`, `isText` / `isTime`, `safePath` (the login's `?next=`) |
  58. | `lib/jsoncheck.hl` | JSON syntax pre-check (copy from tickets; workaround for hybriel#6/#12 — delete when fixed) |
  59. | `lib/util.hl` | `envOr`, `storageDir`, `countOfList`, `firstOf`, `isHex`, `isIdentId` |
  60. | `components/main.hl` | the shell on the layouts theme (mission 011): AppHeader, MainMenu, UserMenu, phone Sidebar, ident icon/login, faces `notesLogin` / `notesLogOut` |
  61. | `components/notes.hl` | the page (`/`, `/note/:id`, kept offline): sidebar, editor, New / Delete, the list derivation (`rowsOf`, statics in the file so it runs in the browser), faces `notesPut` / `notesDrop` / `notesPull`, push `notesChanged` |
  62. | `components/loginfailed.hl` | `/login/failed`: the reason parked in the session |
  63. | `components/styles.hl` | the app's own CSS on top of `theme/theme.hl` (mobile first; accent = yellow); `theme/` = layouts.worldapi.org dbe3de7 verbatim (+ `theme/check-theme.mjs`, a deploy gate; `.check-theme-ignore` skips the vendored md-editor); `shared/tokens.hl` = copy of worldapi-tokens |
  64. | `icons/` | app icons: `icon.svg` (source), `icon-192/512.png`, `apple-touch-icon.png`, `favicon.svg`, `favicon.ico` |
  65. | `components/md-editor/` + `components/SOURCE` | the Hybriel MdEditor block, copied BYTE-VERBATIM from components.hybriel by `tools/sync-components.sh` (`--check` compares; never edit the copies). Used as `MdEditor { name = "text" ... files = "off" }` in `components/notes.hl`; its hidden field `text` fires the `input` event the page catches (`typed`); it is the only Markdown renderer of notes (editor, offline) |
  66. | `login.js` | ident selector ↔ shell bridge |
  67. | `tools/migrate-short-ids.hl` | one-off ident#23 migration (README "Short ids") |
  68. | `tests/browser.mjs` | the gate (own server, own ident copy, real Chrome; offline = CDP page + worker, reloaded offline first); `deploy.sh` runs it |
  69. | `tests/realdata-offline.mjs` | offline on a real-data COPY: all notes listed, Chrome offline edit synced (mission 007) |
  70. | `tests/short-id-switch.mjs` | gate of the short-id switch (fixed ports 8720/8721) |
  71. | `tests/realdata-baseline.mjs`, `tests/realdata-compare.py` | same-output check of two code trees on a live-data copy (below) |
  72. | `tests/letcount.py` | code-order counts: root `.hl` files, project.hl lines, `let`s (`-v` lists any that should be plain) |
  73. Data: `storage/mpackdb/{users,notes}.db` (never sent by deploy.sh). Only ever open COPIES of live data.
  74. ## PWA (installable app, antcolony mission 046)
  75. - `project.hl` `appIcons` / `appTouchIcon` / `appFavicon` / `appThemeColor` (token `darker`, the header) / `appBackgroundColor`
  76. (`dark`) → hl:web serves `/__hl/manifest.webmanifest` (name `notes`, start_url/scope `/`, standalone) and links it,
  77. the apple-touch-icon and theme-color from every head. Each icon has its own `file` route in `project.hl`.
  78. - **Offline is hl:web's** since notes#4 (mission 007): `offline = [Notes]`, one worker `/__hl/sw.js` for scope `/`
  79. (the gate checks it, and that `/sw.js` and `/notes-offline.js` are 404).
  80. - **Icons** (`icons/`): `icon.svg` = source (512; a note page with a folded corner and a pencil, yellow on
  81. rgb(25,30,35); everything inside the maskable safe circle r=204, so one image serves `any` and `maskable`);
  82. `favicon.svg` = the same drawing cropped tight, thicker strokes. Render:
  83. ```
  84. rsvg-convert -w 192 -h 192 icons/icon.svg -o icons/icon-192.png
  85. rsvg-convert -w 512 -h 512 icons/icon.svg -o icons/icon-512.png
  86. rsvg-convert -w 180 -h 180 icons/icon.svg -o icons/apple-touch-icon.png
  87. for s in 16 32 48; do rsvg-convert -w $s -h $s icons/favicon.svg -o /tmp/fav-$s.png; done
  88. magick /tmp/fav-16.png /tmp/fav-32.png /tmp/fav-48.png icons/favicon.ico
  89. ```
  90. ## The JSON API (`lib/api.hl`; kept from notes#2, the page itself syncs through its faces; JSON, the session cookie is the login; 401 signed out, 400 for bad JSON/fields)
  91. - `GET /api/me` → `{ user }` · `GET /api/notes` → `{ notes: [{ id, edited, gone }] }` · `GET /api/notes?id=` → `{ id, text, edited, created }`
  92. - `POST /api/notes` `{ op:'save', id, local, text, base, at }` → `{ id, edited, text, copy? }` ·
  93. `{ op:'delete', id, base }` → `{ ok }` | `{ kept, id, edited, text }`. `base` = the `edited` the device last saw, `at` = when it edited.
  94. - **Access keys (ident#27).** `Authorization: Bearer idt_…` — an ident access key for the app `notes` — works on `/api/me` and `/api/notes` instead of the cookie, no browser login: the key's identity is the notes user (made at the first call), a `write` key reads and writes, a `read` key only reads (POST 403); a bad, revoked or foreign key is 401, ident not answering 503, nothing is written. ident is asked on every call (`lib/ident-access.hl`, a copy from tickets; settings `IDENT_API_KEY` / `IDENT_API_SECRET`). Gate: `tests/ident-access-notes.mjs`.
  95. ## Run and test
  96. ```
  97. NOTES_PORT=8710 NOTES_WATCH=0 ./bin/hybriel project.hl # dev; needs IDENT_API_KEY/SECRET for a login
  98. node tests/browser.mjs # the gate: ports 8701 (ident), 8702 (app), Chrome 8703–8709
  99. # (other ports: NOTES_GATE_PORT / _IDENT_PORT / _CHROME=8722-8726)
  100. # includes the PWA checks; screenshots in .scratch/gate-*.png
  101. ./deploy.sh [--dry-run] # gate → backup → rsync to Byrodin → restart → URL 200 (architect)
  102. python3 tests/letcount.py . [-v] # code order: must say `never reassigned 0`, root .hl files 1
  103. ```
  104. PR #7 regression checks: `node tests/pr7-regressions.mjs` (in GATES) covers rejected-draft conflict bases and retained-page canonical navigation. Waiting on Hybriel, outside GATES, no notes workaround: `node tests/waiting-back-hybriel-390.mjs` and `node tests/waiting-hybriel-390.mjs` (an edit typed in the last 0.6 s before Back; queued saves per keystroke, hybriel#390), `node tests/waiting-hybriel-388.mjs` (offline stand-in route, hybriel#388).
  105. **Same output** (for a cleanup that must not change behaviour; notes mission 002): a copy of the live tables, then the
  106. old tree and the new tree each answer every page (signed in as az5b2 = users `0muh6o5a3kkd`, and signed out), every
  107. API read, the POST refusals, the login routes/faces against a fake ident, and a fixed write sequence (save, retry,
  108. conflict both ways, delete, tombstone, logout); then compare:
  109. ```
  110. tar -C /CONTAINERS/projects/notes.worldapi.org -cf - storage/mpackdb | ssh loreana tar -C <repo>/.scratch/realdata -xf - # on Byrodin
  111. git archive <old commit> | tar -C .scratch/old -xf - && cp -a bin plugins .scratch/old/
  112. node tests/realdata-baseline.mjs .scratch/old 8762 .scratch/base-old # app on 8762, fake ident on 8767 (port + 5)
  113. node tests/realdata-baseline.mjs . 8762 .scratch/base-new
  114. python3 tests/realdata-compare.py .scratch/base-old .scratch/base-new -v # exit 0 = the same
  115. ```
  116. It masks only source positions, `?v=` hashes, the seed time and (writes) new ids, `edited` stamps and login tags; two
  117. runs of the same tree compare clean. Delete the live copy and the outputs afterwards (they hold live notes).
  118. Environment: `NOTES_PORT` (dev 8710, container 45007), `NOTES_STORAGE`, `NOTES_SESSIONS`, `NOTES_WATCH=0`,
  119. `NOTES_PUBLIC_URL` (default https://notes.worldapi.org), `IDENT_URL`, `IDENT_EXCHANGE_URL`, `IDENT_API_KEY`,
  120. `IDENT_API_SECRET` (`.env` beside `project.hl`, never read by workers).
  121. ## First deploy (architect)
  122. Container `notes.worldapi.org` on `127.0.0.1:45007` replaces the demo-notes at the same address: back the demo up,
  123. stop it, point the vhost to 45007 (WebSocket Upgrade headers needed), register the app in ident with the origin
  124. `https://notes.worldapi.org`, put the key and secret into `.env`.
  125. ## Hybriel notes
  126. - Current vendor: Hybriel day61, SOURCE `a05af47ce2b209686dbd8184e72077622de526c3`; binary SHA-256 `a11042e548b96f3c2c7c2382624ba11e3386a08f69fcf4697e2dcfb0ab3ac725`. `bin/` contains the checked day61 set bin/ and lib/. Every existing plugin directory comes from that source commit (including README and build input metadata); its shared libraries come from the checked day61 set.
  127. - **Vendor = hybriel master 0f396652 (native, static, notes mission 006; was a832f73b)**: `bin/hybriel` (sha256 `60fa02f3…9080`) +
  128. `bin/libhlrt.a` + `bin/hlc.o` + `bin/hlrt/` (copied from /media/STORAGE/claude-scratch/vendor-0f396652, see its README.txt; `bin/` is gitignored, deploy.sh
  129. rsyncs it) + `plugins/` (core crypto data fetch fs http http1 mpackdb proc time web = `git archive 0f396652 plugins`; no local plugin patch). Hybriel compiles the app at its start: cold ~10 s (empty cache), warm 0.13 s; docker-compose
  130. mounts the build cache on the named volume `hybriel-cache` (`HL_CACHE_DIR`) and `/tmp` as tmpfs; tests wait up to 120 s for a start;
  131. deploy.sh waits `DEPLOY_URL_WAIT` (120 s) for the URL. Previous vendor (06617221) in `.scratch/old/` of the w4 worktree.
  132. Before: `bin/hybriel` + `plugins/` (core crypto data fetch fs http http1 mpackdb proc time web) are vendored = hybriel **master
  133. 06617221** (2026-10-03, antcolony mission 074: plugin allocators 3a781359 + 413f60e4 (#126, plugins allocate with malloc via
  134. plugin_api.zig), mpackdb 2cb7ae5e, http1 773de63e, f0ac2d2d (plugin ABI field — bin and .so must match); no lambda semantics
  135. change), sha256 `21059cc7…d77bdb`, built the same way from `git archive 06617221` (`~/scratch-074/src`, removed); previous copy
  136. (190aa11d) in `.scratch/pre-074/`. Gates: browser 50/0 (`NOTES_GATE_PORT=8760 NOTES_GATE_IDENT_PORT=8761
  137. NOTES_GATE_CHROME=8762-8769`), short-id-switch 18/0 (temp copy with ports 8760/8761). Memory: `LOADS=N ROUNDS=N [MODE=pull|push]
  138. node .scratch/w074/memtest.mjs <app dir> <mpackdb copy> <label> <users @id>` (port 8760, Chrome 8761–8769; loadMarks/apiMarks =
  139. RSS every 250). Pages and pulls are flat now; **saves still grow ~0.09 MB per save on old and new alike** (mpackdb update path).
  140. Before: master 190aa11d (2026-10-02, antcolony mission 072: fc838894 GC correctness (string index / plugin error read freed memory),
  141. 038d84b3 #126 returned closure scopes, #127 d98926c6/04df4428; no lambda semantics change since 8efba065), sha256
  142. `860f5e61…0a23626`, built read-only from `git archive 190aa11d` (`~/scratch-072/src`, removed); previous copy (8efba065) in
  143. `.scratch/pre-072/`. Gates: browser 50/0 (`NOTES_GATE_PORT=8720 NOTES_GATE_IDENT_PORT=8721 NOTES_GATE_CHROME=8722-8729`),
  144. short-id-switch 18/0. Memory: `node .scratch/w072/memtest.mjs <app dir> <mpackdb copy> <label> <users @id>` (port 8720,
  145. Chrome 8721-8728; LOADS / ROUNDS env): 200 loads + 200 sync rounds new 114 → 186 → 230 MB, old (8efba065) 124 → 222 → 277 MB;
  146. 1000 + 1000: 213 MB after the loads (pages plateau), 486 MB after the sync rounds (~0.27 MB per round, still grows).
  147. Before: master 8efba065 (2026-10-02, antcolony mission 069: #126 = f685f240 the interpreter GC also collects by bytes, #48 = 4371b7aa a
  148. lambda parameter COPIES its argument (`&p` = reference), #112 #117 #119 #120 opt-in, not used), sha256 `ebf31876…5c0ad2a2`,
  149. same build command as below; previous copy (ff51cf46) in `.scratch/pre-069/`.
  150. **#48 audit**: no lambda in notes writes a parameter the caller relies on (`project.hl` failed/loginCallback alias
  151. `req.session` and save it themselves; faces `on server …(session)` are not lambdas) → no `&` needed. WRONG for
  152. `failed(req, why)` with a cookie: its write was lost ("the login did not finish" instead of the reason) — fixed in
  153. notes mission 002 by `&req`/`&sessions` (lib/api.hl). Audit:
  154. `python3 .scratch/w069/lambdas.py` (writes to params) + `lambdas2.py` (params handed on/aliased). **Memory (#126)**:
  155. `node .scratch/w069/memtest.mjs <app copy without .env> <mpackdb copy> <label> <users @id>` (port 8730, Chrome
  156. 8722-8729; LOADS / ROUNDS env) — live-data copy, 200 Chrome loads + 200 sync rounds: new 124 → 287 MB, old 97 → 1282 MB.
  157. Before that: master ff51cf46 (2026-10-01, antcolony mission 048: #113 mpackdb update() duplicate ids, #115/#116 lambda members on faces, #118 `for`
  158. over a literal list, client-built SVG namespace, hl:markdown #111 — notes uses none of these directly; before: e6720b1f,
  159. antcolony mission 037: #103/#104 client fixes, #105 `headers`, #106 `let` per loop pass, #94 files in emit;
  160. earlier #83 hashed `/__hl/…?v=` URLs + immutable cache, #82 socket reconnect, #95–#97 offline/PWA from project.hl — the
  161. manifest (`appIcons`) is used since antcolony mission 046, `offline = [Notes]` since notes#4, mission 007). Built from a read-only `git archive master` (`zig build
  162. -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.39` in `native/`), sha256 `e70631f0…eff3471b`. No local patch:
  163. re-vendor = copy binary + plugins, run the gate. Copy before 048 (e6720b1f): `.scratch/pre-048/`.
  164. - Rejected saves are kept in `drafts.db` by user, note and login (maximum 1 000 000 characters), so reopening a note preserves a draft longer than the note limit. Accepted saves and note deletions clear it. Draft writes and reads live in `lib/drafts.hl`; ownership is resolved in the notes topic.
  165. - The notes area is Hybriel since notes#4 (mission 007; before it was plain JS, notes-offline.js + sw.js). The sidebar
  166. uses framework navigation, so each opened note has a history entry and Back returns to the list or previous note.
  167. A provisional id becomes its canonical address through replace navigation. Kept pages navigate offline through hl:web.
  168. - Gate needs a secure origin for the service worker: Chrome runs with `--unsafely-treat-insecure-origin-as-secure`.
  169. - Server restart closed open tabs' sockets for good (hybriel#82) — fixed in the vendored master since 035 (reconnect); not
  170. checked by the notes gate. The notes area still uses its own JS (candidate for hl:web offline, #95–#97).
  171. ## History and worker briefs
  172. - `LOG.md` — append-only history, one dated line per step (moved here from the antcolony LOG on 2026-10-01).
  173. - `missions/NNN-*.md` — worker briefs for this app; `reports/NNN-*.md` — their reports (same name). Numbered per
  174. project since 2026-10-01 (antcolony#40); older text, code comments and commits use the old antcolony numbers →
  175. map: `/media/STORAGE/projects/antcolony-docs/docs/mission-map.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/mission-map.md`).

Branches

Latest commits

  • 996768bf|||PR WIP sequence note creation before provisional-id adoptionAtlas
  • c49ce093|||PR WIP remove notes polling and use framework reachabilityAtlas
  • c028ac61Merge branch 'notes-pr7-kunibert' into mainAtlas
  • 9cc92bdfKeep conflict and history fixes while awaiting queued save supportAtlas
  • a5c27cb6Allow real edits back to earlier text and honor configured identAtlas
  • 15c46ced|||PR Preserve note edits, conflict bases and visible historyAtlas
  • 4c6e0bf6Merge branch 'notes13-day61' into mainAtlas
  • eb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlas
  • 3537cf7eMerge branch 'vendor-day59' into mainAtlas
  • c13d188b|||PR Vendor Hybriel day59Atlas
  • 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
  • ae1075b2Preserve rejected drafts during note ID adoptionAtlas
  • 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
  • 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
  • 649cef37|||PR Vendor Hybriel day56Atlas
  • aadd0abcMerge branch 'hl-standard-2' into mainAtlas
  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre