gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitebda0fd1ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mreebda0fd1/README.md

17.0 KB

  1. # calendar.worldapi.org
  2. The creator's calendar (CONCEPT.md), in Hybriel on hl:web. The month view at `/` — prev / next buttons on top, month name
  3. and year between them, today marked, weeks start on Monday, names in the browser's language — and, since ticket #2,
  4. **login with ident and private events**. https://calendar.worldapi.org
  5. Since mission 006 the page is the layouts theme (`theme/`, layouts.worldapi.org dbe3de7) in its **ContentFirst** shell: a month is one big content area, so no list beside it. Mobile first: ☰ menu (MainMenu + Sidebar, "Calendar") and the user menu (the user icon: signed in → Log out; signed out → Log in with ident); taps ≥ 44 px, inputs ≥ 16 px at 390 px. `components/styles.hl` keeps only the app's own rules; the month-view fork keeps only **its own** styles in its `styles.hl` part (the month grid, event chips, editor), everything else (colours, buttons, header, menus) comes from the theme. `node theme/check-theme.mjs .` (in deploy.sh) fails on hard-coded colours, decorative borders and odd radii.
  6. ## Use
  7. - Signed out: the month view and "Log in with ident" (top right; the identity selector or the button).
  8. - Signed in: click a day to add an event, click an event to edit or delete it. An event has a title, "At a time" (from /
  9. to, date and time) or "All day" (from / to, dates), a place and notes. It shows on every day it covers (a day shows four
  10. chips, the fourth says "+N more"). Only the owner sees, changes or deletes an event.
  11. - Events are stored as **WorldAPI Events** (https://worldapi.org/standards/event): `$type $version $kind $title
  12. $description $start $end $timezone $location $status $visibility $created $updated` plus `owner` (users `@id`). Timed
  13. events: local wall-clock `$start`/`$end` + `$timezone` (the browser's); all-day: `$kind = 'allday'`, date `$start`, exclusive
  14. date `$end` (left out for one day); `$created`/`$updated` are UTC instants; `$visibility` is always `private`.
  15. - **Short ids (ident#23, antcolony mission 039)**: `users.identity` holds what ident's exchange answers — since ident#23 the identity's
  16. public 5-character short id (`a68sz`), before that the per-app id (32 hex); `lib/util.hl isIdentId` accepts both (the old
  17. `isHex` check refused short ids). The switch: one-off `tools/migrate-short-ids.hl` (old → short id, idempotent, never
  18. `finish`), gate `node tests/short-id-switch.mjs` (ports 8722/8723, no browser), runbook
  19. `antcolony-docs/docs/short-id-switch.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/short-id-switch.md` once synced).
  20. ## Reminders and notifications (ticket #4)
  21. - **Reminder settings** (button under the month, signed in): the calendar's default reminders — 1 hour before and the day before at
  22. 20:00 until changed. Every event without reminders of its own gets them. In an event, "Calendar's" / "Own" chooses; "Own" is a list
  23. of rows (N minutes before, N hours before, N days before at HH:MM), also none at all.
  24. - Stored as WorldAPI Event `$reminders` (`{ $before: 'PT1H' }`, `{ $days_before: 1, $time: '20:00' }`); no `$reminders` = inherit; the
  25. defaults are the Calendar's `$reminders` in `storage/mpackdb/settings.db` (one row per owner).
  26. - The page keeps the events of the next days with the reminders that apply (`soon`, part of the page state — the offline layer stores it)
  27. and sets one browser timer per reminder of the next 7 days (`arm()`; set again after every save / delete / paging and every 10 minutes
  28. of use). A timer shows the notification (hl:web `notify`, through the service worker). "Turn on notifications" is the click the browser
  29. wants before it allows them.
  30. - **Missed reminders (calendar#9):** a phone freezes or drops an app it switched away from, and its timers with it. Each
  31. device keeps in `localStorage` (`calendar-reminded-until-<users @id>`) the instant up to which it planned or showed the
  32. reminders; every `arm()` first shows, at once, the reminders that came due since then for events that have not started
  33. yet (one per event, "Starts at 14:00" instead of "Starts in 1 hour"; none kept yet = the last 12 hours). `arm()` also
  34. runs whenever the app is shown again (`visibilitychange` → visible, `pageshow`; listeners set on the first touch).
  35. - **Offline:** the timers need no network, and the offline page has `soon`. An event saved while the server cannot be reached shows at once,
  36. its reminders are set, and the save waits in hl:web's emit queue until the connection is back.
  37. - **Limits (Hybriel gaps, calendar mission 003, report `reports/003-notifications-never-fired.md`):** (1) a timer lives only while
  38. the app is open AND in front — on a phone that is almost never at the reminder time; a closed, frozen or dropped app is only
  39. reached by **Web Push**, and Hybriel has none (hl:crypto: no ES256 / ECDH / HKDF / AES-GCM for VAPID and the payload; hl:web's
  40. service worker has no `push` listener; no `pushManager.subscribe`). (2) hl:web has no client hook when a page is shown, so
  41. nothing is planned (and "Turn on notifications" is not offered) until the first pointer / focus / touch on the month view.
  42. `notifyAt` cannot cancel, so `arm()` uses `setTimeout` directly and calls `notify` (hl:web: through the service worker's
  43. `showNotification`, which Chrome on Android requires — `new Notification()` is refused there).
  44. - Code: `components/month-view/reminders.hl` (rows ↔ `$reminders`, describe, time-zone instants, the plan) shared by `lib/settings.hl` (settings
  45. table), `lib/events.hl` (`upcoming`) and `month-view.hl` (editor, timers).
  46. ## Layout
  47. Code order (antcolony `docs/code-order.md`, calendar mission 001): `project.hl` is the map (config, routes, audience, an
  48. index of which file handles what); one `lib/` file per topic holds its central logic, `lib/<topic>-helpers.hl` what it
  49. looks up; the function route and the faces are thin wrappers. `let` only for a variable that is reassigned (or re-bound
  50. in a loop body). Imports go one way: util ← users, settings, events-helpers ← events ← api-helpers ← api ← project.hl.
  51. | file | what |
  52. |---|---|
  53. | `project.hl` | the map: index comment, PWA config, routes, audience, server |
  54. | `lib/events.hl` | `events` table (`storage/mpackdb/events.db`, index `owner`) and every write to it (`saveEvent` / `createEvent` / `changeEvent` / `deleteEvent`), `eventsBetween`, `upcoming`, `soonOf`, the faces' answers `calendarView` / `settingsView` |
  55. | `lib/events-helpers.hl` | `build` (page fields → WorldAPI Event, strict validation), `viewOf`, `isLocalId`, `validWindow`, `byStart`, size limits |
  56. | `lib/settings.hl` | `settings` table (`storage/mpackdb/settings.db`, unique `owner`): the default reminders (`defaultsOf`, `saveDefaults`) |
  57. | `lib/users.hl` | `users` table (ident identity → user `@id`), ident config + exchange, `userOfLoginCode` (both logins), `userIdOfSession`, `tagOf` |
  58. | `lib/api.hl` | `/login/callback` (+ `loginFailed`; take `&req`, `&sessions`) |
  59. | `lib/api-helpers.hl` | `safePath` (the login's `?next=`) |
  60. | `lib/util.hl` | `envOr`, `storageDir`, `countOfList`, `firstOf`, `isHex`, `isIdentId` |
  61. | `components/main.hl` | the shell with the login, faces `calendarLogin` / `calendarLogOut` |
  62. | `components/calendar.hl` | the page `/` and the faces `calLoad` / `calSave` / `calDelete` / `calSettingsLoad` / `calSettingsSave` / `calSaveQueued` |
  63. | `components/loginfailed.hl` | `/login/failed` |
  64. | `components/styles.hl` | the app's OWN CSS only (month grid, chips, editor); the look comes from `theme/` (layouts dbe3de7) and the tokens |
  65. | `theme/` | the layouts theme (shell ContentFirst / AppHeader / MainMenu / UserMenu / Sidebar) + `check-theme.mjs` |
  66. | `tools/migrate-short-ids.hl` | one-off ident#23 migration |
  67. | `tests/browser.mjs`, `tests/short-id-switch.mjs`, `tests/notify-paths.mjs` | the gates (below) |
  68. | `tests/realdata-baseline.mjs`, `tests/realdata-compare.py` | same-output check of two code trees on a live-data copy (below) |
  69. | `tests/letcount.py` | code-order counts: root `.hl` files, project.hl lines, `let`s (`-v` lists any that should be plain) |
  70. - `components/month-view/` the month view, vendored from components.hybriel.worldapi.org and EXTENDED here (events on the
  71. days, the editor; `dates.hl` = date helpers shared with the server; it carries its own `Style`). Re-vendoring needs these changes carried over.
  72. - `login.js` ident selector ↔ shell bridge (the only hand-written JavaScript). The month view reads the browser's today / language / time zone itself (Hybriel `Date` / `Intl` in a handler, on the first pointer / focus / touch), no `month-view.js`.
  73. - PWA (ticket #3): installable and offline through hl:web's own support — `appIcons`, `appThemeColor`, `offline = [ Calendar ]` in project.hl (manifest link in the head, `/__hl/manifest.webmanifest`, `/__hl/sw.js`); icons in `icons/`. No JavaScript of ours.
  74. - `bin/hybriel` + `plugins/` (core crypto data fetch fs http http1 mpackdb proc time web) are vendored = the shared STATIC Hybriel build
  75. **0f396652** (2026-10-19, `/media/STORAGE/claude-scratch/vendor-0f396652`, README.txt there), bin/hybriel sha256 `60fa02f3…c39080`
  76. (statically linked); previous copy 06617221 (sha256 `21059cc7…d77bdb`). Compose: cache volume `hybriel-cache` + `HL_CACHE_DIR` + tmpfs /tmp +
  77. `init: true`; a gate start waits up to 150 s (cold compile ~20 s). Gates: `CALENDAR_GATE_PORT=8760 CALENDAR_GATE_IDENT_PORT=8761 CALENDAR_GATE_CHROME=8762-8769
  78. node tests/browser.mjs` 78/0, `NOTIFY_GATE_PORT=8760 NOTIFY_GATE_SCRATCH=<short path> node tests/notify-paths.mjs` 7/0 (3 Hybriel gaps; Chrome's
  79. socket path must stay < 108 chars), `CALENDAR_SWITCH_IDENT_PORT=8760 CALENDAR_SWITCH_PORT=8761 node tests/short-id-switch.mjs` 18/0 (not in deploy.sh).
  80. Memory: `LOADS=N PAGES=N node .scratch/w074/memtest.mjs <app dir> <mpackdb copy> <label> 0muh8y8myb5z` (port 8760, Chrome
  81. 8761–8769; RSS marks every 250): 1000 loads + 1000 pagings new 194 → 214 → 218 MB, old 190aa11d 194 → 227 → 231 MB.
  82. Before: master 190aa11d (2026-10-02, antcolony mission 072: fc838894 GC correctness (string index / plugin error read freed memory),
  83. 038d84b3 #126 returned closure scopes, #127 d98926c6/04df4428; no lambda semantics change since 8efba065), sha256
  84. `860f5e61…0a23626`, built read-only from `git archive 190aa11d`; previous copy (8efba065) in `.scratch/pre-072/`. Gates:
  85. `CALENDAR_GATE_PORT=8720 CALENDAR_GATE_IDENT_PORT=8721 CALENDAR_GATE_CHROME=8722-8729 node tests/browser.mjs` 78/0,
  86. `CALENDAR_SWITCH_IDENT_PORT=8730 CALENDAR_SWITCH_PORT=8731 node tests/short-id-switch.mjs` 18/0. Memory:
  87. `.scratch/w072/memtest.mjs` (port 8720, Chrome 8721-8728, same args): 200+200 new 194 → 214 → 215 MB (old 283 → 368 → 376),
  88. 1000+1000 new 229 → 233 MB — flat.
  89. Before: master 8efba065 (2026-10-02, antcolony mission 069: #126 memory freed by bytes too, #48 lambda parameters COPY; earlier ff51cf46 #113,
  90. #115/#116, #118, client SVG namespace, hl:markdown #111; #103–#106, #94, #83, #82, #95–#97). Built from a
  91. read-only `git archive master` (`zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.39` in `native/`, zig =
  92. hybriel's `native/zig-toolchain` link), sha256 `56b108f3…f4f201ea`. **No local patch**: re-vendor = copy binary + the
  93. plugins above, run both gates. Previous copy (ff51cf46): `.scratch/pre-069/`.
  94. - **Lambdas copy their arguments (hybriel #48)**: `f = (x) => { x.n = 1 }` changes a COPY; a lambda that must change the
  95. caller's hybrid/list takes `&x`. Audit 2026-10-02 (`python3 .scratch/w069/lambdas.py` / `lambdas2.py`, 64 lambdas): none
  96. writes a parameter the caller reads — `project.hl` failed/loginCallback save `req.session` themselves, the rest build new
  97. values. WRONG for `failed(req, why)` with a cookie: its write was lost ("the login did not finish" instead of the
  98. reason) — fixed in calendar mission 001 by `&req`/`&sessions` (lib/api.hl). Probe: `bin/hybriel .scratch/w069/probe48.hl`. New lambdas: use `&` when the caller relies on the change.
  99. - Memory check (#126): `node .scratch/w069/memtest.mjs <app copy> <mpackdb copy> <label> <users @id>` (port 8730, Chrome
  100. 8722-8729; env LOADS/PAGES): RSS at boot, after N signed-in page loads, after N month pagings (calLoad), after 5 s idle.
  101. - `validWindow` / `soonOf` (were plain members of `components/calendar.hl` since antcolony mission 048) are statics in
  102. `lib/events-helpers.hl` / `lib/events.hl` since calendar mission 001; the gate checks both (bad window refused, `soon`).
  103. - Language of the first render (calendar#6): `components/calendar.hl` declares `headers = null` (hybriel #105) and hands
  104. `headers['accept-language']` to `MonthView { acceptLanguage = requestLanguage }`; `names.hl` knows en de fr es it nl pt,
  105. any other → neutral names until the browser fills in its own. Names written by the server stay while paging.
  106. - Reminder timers: `arm()` creates the `setTimeout` closure inline in its `while` loop — `let p` is a new binding per pass
  107. (hybriel #106). On an older Hybriel the closures shared `p` and only the last reminder fired (antcolony mission 037 proved it:
  108. gate on 13ef4f9b → "the notifications came on time" FAIL, only "Has its own reminder" came).
  109. ## Run, test, deploy
  110. - `CALENDAR_PORT=8700 ./bin/hybriel project.hl` (env: `CALENDAR_WATCH=0` no watcher, `HL_HOST`, `CALENDAR_SESSIONS`,
  111. `CALENDAR_STORAGE`, `CALENDAR_PUBLIC_URL` default https://calendar.worldapi.org, `IDENT_URL`, `IDENT_EXCHANGE_URL`,
  112. `IDENT_API_KEY`, `IDENT_API_SECRET` — `.env` beside `project.hl`, never read by workers). A login needs the ident key.
  113. - `node tests/browser.mjs` — the gate: own ident (a copy without `.env`), own server + storage, headless Chrome
  114. (ports 8700 app, 8701 ident, 8702–8709 Chrome; `CALENDAR_GATE_PORT`, `CALENDAR_GATE_IDENT_PORT`, `CALENDAR_GATE_CHROME`).
  115. Second gate: `node tests/short-id-switch.mjs` (ports 8722/8723; `CALENDAR_SWITCH_IDENT_PORT`, `CALENDAR_SWITCH_PORT`).
  116. `GATE_SKIP_EVENTS=1` skips the events part (40 checks run instead of 76, ~1.5 min instead of ~4). The language checks (`languagePart`)
  117. open a tab per language with CDP `Network.setExtraHTTPHeaders` Accept-Language de / en and the browser's own language
  118. (Intl locale + navigator.language) set to the OTHER one; first page, server HTML, next/next/prev.
  119. Known flake: one run in a few times out on "next month" (a loaded machine; see STATUS 2026-09-26) — run it again.
  120. - `node tests/notify-paths.mjs [app dir]` — where a reminder fires (calendar#9): six phones (390 px, touch, Android UA), one
  121. identity and one Chrome each, all at once (~4 min): permission, open untouched, open touched (+ not twice), switched away
  122. (frozen), tab dropped, closed (+ opened again). `NOTIFY_GATE_PORT` (default 8700; ident +1, Chrome +2…+7),
  123. `NOTIFY_GATE_SCRATCH`, `NOTIFY_GATE_ONLY=a,b`. What needs a Hybriel piece prints `GAP` and is not counted
  124. (`NOTIFY_GATE_STRICT=1` counts it). Give an old tree as the argument to see the old behaviour.
  125. - `python3 tests/letcount.py . [-v]` — code order: must say `never reassigned 0`, root .hl files 1.
  126. - **Same output** (for a cleanup that must not change behaviour; calendar mission 001): a copy of the live tables, then
  127. the old tree and the new tree each answer the pages (signed in as az5b2 = users `0muh8y8myb5z`, and signed out; de/fr),
  128. the browser modules, `calLoad` for every month with a live event, the login route/faces against a fake ident, and a
  129. fixed write sequence through the faces (create appointment / all-day / overnight / own reminders, 18 refusals, edit,
  130. offline queue with a `local-` id, delete, a live event changed and deleted, the defaults, logins, logout); then:
  131. ```
  132. tar -C /CONTAINERS/projects/calendar.worldapi.org -cf - storage/mpackdb | ssh loreana tar -C <repo>/.scratch/realdata -xf - # on Byrodin
  133. git archive <old commit> | tar -C .scratch/old -xf - && cp -a bin plugins .scratch/old/
  134. node tests/realdata-baseline.mjs .scratch/old 8762 .scratch/base-old # app on 8762, fake ident on 8767 (port + 5)
  135. node tests/realdata-baseline.mjs . 8762 .scratch/base-new
  136. python3 tests/realdata-compare.py .scratch/base-old .scratch/base-new -v # exit 0 = the same
  137. ```
  138. It masks only source positions, `?v=` / `hl-shell-` hashes, request times, the Host port and (writes) new ids, ms stamps
  139. and login tags; browser modules count as the same when their own code and the imported functions they use are. Two
  140. runs of the same tree compare clean. Run both trees on the same UTC day (`soon` follows the server's today). Delete
  141. the live copy and the outputs afterwards.
  142. - `./deploy.sh` on Loreana (architect): gate → backup → rsync → `docker compose up -d --build` on Byrodin (127.0.0.1:45005).
  143. ## First deploy of ticket #2 (architect)
  144. Register the app in ident with the origin `https://calendar.worldapi.org` and put `IDENT_API_KEY` / `IDENT_API_SECRET`
  145. into `.env` on Byrodin (as notes does), otherwise the login button has no key.
  146. ## History and worker briefs
  147. - `LOG.md` — append-only history, one dated line per step (moved here from the antcolony LOG on 2026-10-01).
  148. - `missions/NNN-*.md` — worker briefs for this app; `reports/NNN-*.md` — their reports (same name). Numbered per
  149. project since 2026-10-01 (antcolony#40); older text, code comments and commits use the old antcolony numbers →
  150. map: `/media/STORAGE/projects/antcolony-docs/docs/mission-map.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/mission-map.md`).

Branches

Latest commits

  • ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mre
  • d063dad3calendar mission 008 (A7): Web Push (WIP): lib/push.hl subscriptions + sender clock, faces calPushSave/calPushOff, button subscribes, VAPID tool, tests/push.mjs; instantOf on hl:timemre
  • cf175c80calendar mission 008 (A7): re-vendor Hybriel master 0e3c9830 (bin 9d957fed, plugins whole: hl:crypto Web Push primitives, hl:web sendPush)mre
  • 9bf3c38bcalendar mission 008: re-vendor Hybriel f9833544 (gates old = new); Web Push stopped: hl:crypto half missing on mastermre
  • 186f969bcalendar mission 007: signed-in gate for the first-pointer race (fails on 3c5604f), README theme section, reportmre
  • ba9b4955calendar mission 006: first pointer event no longer re-runs the month (stale overwrite race), gate check, e2e settings cleanup, reportmre
  • bd730759calendar mission 006: theme move (WIP): brief, report, LOG, STATUSmre
  • b117b153calendar mission 006 WIP: reminder row fields keep 44 px; e2e script flagsmre
  • 53e3b0debrowser gate: Log out through the user menu, theme colour rgb(15, 20, 25)mre
  • 90bf9e2ecalendar mission 006 WIP: theme dbe3de7, theme shell (AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst), styles cut to the app's own rules, check-theme gate, e2e toolsmre
  • 3c5604f9identkit: refuse a taken ident port, cold-start deadline, abort on dead ident, clear no-code error (as notes)mre
  • 4996bbe7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • f5bf0803calendar mission 004: re-vendor Hybriel to the shared static build 0f396652; compose cache volume + tmpfs; notify-paths gate in deploy.sh; gate start waits 150 s; reportmre
  • eb86526fmission brief 004mre
  • 2f953b16deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • 9078e1b7calendar mission 003 (2/2): report, LOG, STATUS (cause: timers only in an open, front, touched page; gate old 5/2 new 7/0; Hybriel gaps Web Push + page-shown hook, STOP)mre
  • 31ffe910calendar mission 003 (1/2): calendar#9 — missed reminders shown when the app is back, timers set again when it is shownmre
  • 26c997d3mission brief 003mre
  • c6809c76calendar mission 002: report, LOG, STATUS (test bug; fixed gate 78/0 at 00:30 05:40 12:00 19:59 20:01; 23:30 not run, quota stop)mre
  • 00f72783calendar mission 002 (2/2): TEST bug — the reminder steps get their own identity (carol): alice's all-day Vacation (20th-22nd) from the events steps added 2 reminders from the 12th 20:00 to the 19th 23:00; Tokyo check no longer skipped in the Tokyo eveningmre