notes
All repositories: gitoria
7.0 KB
# notes.worldapi.orgA notes app in Hybriel (hl:web). Log in with ident; the **sidebar** lists your notes by subject, last edited first;a click opens the note on the right, edited with the Markdown editor `<md-editor>`; **New note** and **Delete note**.The notes are also kept **in the browser (IndexedDB)**: they open and can be edited offline, and sync with the server(and other devices) when the network is back. Concept: `CONCEPT.md`.## How it works- **Subject** = the first non-empty line of the note without leading `#` (at most 80 characters); an empty note is"Untitled note". No separate title field.- **Order** = `edited` (ms), last first. Only a *changed* text moves a note to the top.- **Pages**: `/` (the list; on a phone the list alone) and `/note/:id` (the note; on a phone it replaces the list,"All notes" leads back; from 50rem wide both show side by side). Signed out: only "Log in with ident".- **Offline + sync** (ticket notes#2): `notes-offline.js` fills the notes area from the browser's own copy (IndexedDB`notes-<user>`), every change is written there first and sent to `/api/notes` about 0.6 s later (and every 10 s apull looks for other devices' changes; also on "online", on returning to the tab; other tabs follow throughBroadcastChannel). `sw.js` (service worker, network first) keeps the page and assets, so a reload works with nonetwork; the page carries no note data. A note made offline gets a local id (`l…`) and its server id at the firstpush (the address follows). **Conflict** (changed here and elsewhere): the later edit wins, the other version is keptas a copy note ("kept as a copy …" line at its end). A delete of a note changed elsewhere meanwhile is refused (thechanged note stays). Deleted notes stay on the server as tombstones (`gone`) so other devices learn of it. Log outfirst sends what is unsent, then this browser deletes its copy of the notes.- **Private**: every function in `notes.hl` takes the owner's user id and only reaches that user's notes; anotheruser's note id answers "does not exist"; saving/deleting it is refused. A note is at most 200 000 characters(refused, never cut).- **Login**: ident's button flow (`/login/callback` → `?ident_code=` → server-side exchange) plus the identityselector, as in gitoria; the session cookie is `notessid`, idle time 14 days. The session carries the users `@id`only; the ident identity id never leaves the server.- **Short ids (ident#23, mission 039)**: `users.identity` holds what ident's exchange answers — since ident#23 the identity'spublic 5-character short id (`a68sz`), before that the per-app id (32 hex); `users.hl isIdentId` accepts both (the old`isHex` check refused short ids). The switch: one-off `tools/migrate-short-ids.hl` (old → short id, idempotent, never`finish`), gate `node tests/short-id-switch.mjs` (ports 8720/8721, no browser), runbook`antcolony-docs/docs/short-id-switch.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/short-id-switch.md` once synced).## Files| file | what ||---|---|| `project.hl` | routes, login callback, audience, server || `users.hl` | `users` table (`@id`, `!identity`), the ident exchange || `notes.hl` | `notes` table (`@id`, index `owner`; `{ owner, text, created, edited, gone, local }`), sync push / delete / conflict rules || `components/main.hl` | the shell: header, login/logout, faces `notesLogin` / `notesLogOut` || `components/notes.hl` | the page (`/`, `/note/:id`): only `<note-book id="notesapp">` || `notes-offline.js` | the notes area: sidebar, editor, New / Delete, IndexedDB, sync (served at `/notes-offline.js`) || `sw.js` | service worker: keeps the page + assets for offline use || `jsoncheck.hl` | JSON syntax pre-check (copy from tickets; hybriel#6) || `styles.hl` | all CSS (mobile first; accent = yellow); `shared/tokens.hl` = copy of worldapi-tokens || `shared/md-editor.js` | vendored copy of worldapi-components `md-editor.js` (served at `/md-editor.js`) || `login.js` | ident selector ↔ shell bridge || `tests/browser.mjs` | the gate (own server, own ident copy, real Chrome); `deploy.sh` runs it |Data: `storage/mpackdb/{users,notes}.db` (never sent by deploy.sh). Only ever open COPIES of live data.## The sync API (`project.hl`; JSON, the session cookie is the login; 401 signed out, 400 for bad JSON/fields)- `GET /api/me` → `{ user }` · `GET /api/notes` → `{ notes: [{ id, edited, gone }] }` · `GET /api/notes?id=` → `{ id, text, edited, created }`- `POST /api/notes` `{ op:'save', id, local, text, base, at }` → `{ id, edited, text, copy? }` ·`{ op:'delete', id, base }` → `{ ok }` | `{ kept, id, edited, text }`. `base` = the `edited` the device last saw, `at` = when it edited.## Run and test```NOTES_PORT=8710 NOTES_WATCH=0 ./bin/hybriel project.hl # dev; needs IDENT_API_KEY/SECRET for a loginnode tests/browser.mjs # the gate: ports 8701 (ident), 8702 (app), Chrome 8703–8709./deploy.sh [--dry-run] # gate → rsync to Byrodin → restart → URL 200 (architect)```Environment: `NOTES_PORT` (dev 8710, container 45007), `NOTES_STORAGE`, `NOTES_SESSIONS`, `NOTES_WATCH=0`,`NOTES_PUBLIC_URL` (default https://notes.worldapi.org), `IDENT_URL`, `IDENT_EXCHANGE_URL`, `IDENT_API_KEY`,`IDENT_API_SECRET` (`.env` beside `project.hl`, never read by workers).## First deploy (architect)Container `notes.worldapi.org` on `127.0.0.1:45007` replaces the demo-notes at the same address: back the demo up,stop it, point the vhost to 45007 (WebSocket Upgrade headers needed), register the app in ident with the origin`https://notes.worldapi.org`, put the key and secret into `.env`.## Hybriel notes- `bin/hybriel` + `plugins/` (core crypto data fetch fs http http1 mpackdb proc time web) are vendored = hybriel **mastere6720b1f** (2026-09-26, mission 037: #103/#104 client fixes, #105 `headers`, #106 `let` per loop pass, #94 files in emit;earlier #83 hashed `/__hl/…?v=` URLs + immutable cache, #82 socket reconnect, #95–#97 offline/PWA from project.hl — NOTused, notes keeps its own sw.js / notes-offline.js). Built from a read-only `git archive master` (`zig build-Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.39` in `native/`), sha256 `4316934e…8a2003`. No local patch:re-vendor = copy binary + plugins, run the gate. Previous copy (13ef4f9b): `.scratch/pre-037/`.- The notes area is plain JS on purpose: IndexedDB, a service worker and offline edits cannot go through hl:web'sfaces (they need the socket; it never reopens, hybriel#82). The framework's link click and `popstate` would navigatethrough the socket, so the area claims its own link clicks and uses `history.replaceState` (Back leaves the app).- Gate needs a secure origin for the service worker: Chrome runs with `--unsafely-treat-insecure-origin-as-secure`.- Server restart closed open tabs' sockets for good (hybriel#82) — fixed in the vendored master since 035 (reconnect); notchecked by the notes gate. The notes area still uses its own JS (candidate for hl:web offline, #95–#97).
Branches
- mainmain branch