gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchk40-lists9af8e780|||PR Use keyed list mutations for live ticket updatesmrek40-lists/README.md

100.1 KB

  1. # tickets.worldapi.org
  2. **How changes land (gitoria#50, 2026-11-09):** changes to this repo land as PRs: push a branch with a `|||PR ` commit, Kunibert reviews (non-blocking), the conductor merges fixes and utility changes on https://tickets.gitoria.worldapi.org/pulls; features wait for caramboleyo's accept. Direct pushes to main stay possible until a date announced on gitoria#50 (after hybriel/docs/HL-STANDARD.md and a PR-based deploy-init).
  3. The World Ticket System: the only state store of AntColony (see byrodin
  4. `/CONTAINERS/projects/antcolony/README.md`). Projects, tickets, an append-only event
  5. history per ticket (created / comment / state change), a web UI with live push, a JSON
  6. API for the scheduler/CLI, and an idempotent import of the AntColony ticket files.
  7. Written in **Hybriel** on **hl:web** (SSR + WebSocket push; hybriel master since antcolony mission 036), modelled on the hybriel
  8. repo's `projects/demo-social-network`. **Login via ident** (ticket #7, `CONCEPT.md` "Login via
  9. ident"): reading is public; writing (tickets, comments, states) needs a login; the author is
  10. the logged-in user; since ticket #20 roles per project decide who may do what (the creator-only confirm is gone); machine clients write with API tokens.
  11. See section "Login (ident)". **Markdown** in text fields and a Markdown read view for LLMs
  12. (ticket #6), **editing** by the ticket's author (ticket #8): section "Markdown, editing".
  13. **Relations** (ticket #4): parent / child and blocked-by, across projects — section "Relations".
  14. **Markdown editor** (ticket #12): every Markdown field is edited visually — section "Markdown editor".
  15. **Comments** (mission 016, layouts#2): the shared Comments block — edit, delete, like — section "Comments".
  16. ## Run
  17. ```bash
  18. cd /media/STORAGE/projects/WorldAPI/tickets.worldapi.org
  19. setsid nohup ./bin/hybriel project.hl > server.log 2>&1 < /dev/null & echo $! > server.pid
  20. # stop: kill $(cat server.pid)
  21. ```
  22. * Port **8350** on 0.0.0.0 (`TICKETS_PORT` moves it): http://192.168.178.75:8350 (LAN),
  23. http://100.77.141.84:8350 (tailnet), http://127.0.0.1:8350.
  24. * Data: `storage/mpackdb/{projects,tickets,events}.*` (hl:mpackdb, primary key = mpackdb
  25. UUID `@id` everywhere — creator's convention; `TICKETS_STORAGE=<dir>` moves them).
  26. Sessions: `.sessions/` (`TICKETS_SESSIONS`). The OLD global-numbered tables
  27. `storage/tickets-*` (before ticket #38) stay as a read-only backup — nothing reads them.
  28. * The framework's dev watcher is on: saving a `.hl` file re-analyses and reloads open tabs.
  29. A restart is needed after changing `components/styles.hl` root rules, `shared/tokens.hl`, env vars or the binary.
  30. * `HL_HOST` (or `HOST`): interface to bind, default 0.0.0.0; `127.0.0.1` on Byrodin. hl:web
  31. reads it itself (hybriel#24; until antcolony mission 036 `project.hl` built the listener). `TICKETS_WATCH=0` turns
  32. the dev watcher off (the container).
  33. * Login env (section "Login (ident)"): `IDENT_API_KEY`, `IDENT_API_SECRET`,
  34. `TICKETS_CREATOR_IDENTITY`, `IDENT_URL`, `IDENT_EXCHANGE_URL`, `TICKETS_PUBLIC_URL`. Without
  35. key/secret the app runs read-only for everyone (a login answers "login is not set up").
  36. ## Moving tickets: permissions
  37. Moving requires the caller to be an **admin of both the source and target projects**. Source-only or target-only admin rights, edit rights, and project connection keys do not authorize a move. The ticket page shows the Move form only when the current user administers the source and at least one other project. Permissions are checked again when submitted.
  38. A move keeps the ticket UUID, comments, history, attachments, state and relations. It assigns the next target number, respecting `numberFloor`, and reserves the old source number permanently. All projects use the same defined state names, so the state is preserved; project-specific states are not supported. The assignee is retained. Old paths resolve by UUID, even after further moves or project slug changes.
  39. The API returns permanent redirects. The short HTML component URL currently returns a plain linked notice with status 200, as approved by the conductor pending the hl:web conditional component-redirect feature (M32/GAP-301.md); it does not automatically navigate. Following the Move form's successful submission navigates to the new ticket.
  40. ## Projects, members, roles, new states (ticket #20 — supersedes #19 and the creator-only workflow)
  41. - **Projects are records** (`projects` table): title, slug (generated from the title — letters, digits, `.`, `_`, `-`; an admin can change
  42. it, the old slug keeps resolving), description (Markdown, the shared `<md-editor>`), members. Tickets point at their project by its **id**
  43. (never by name); `path` = `<project id>/<number>`. Pages: `/new-project`, `/<slug>` (the tickets; ticket #25 — was `/projects/<slug>`), `/projects/<slug>/settings`
  44. (admin: title, slug, description, members, invite link).
  45. - **Roles** (`members` table, one row per project + user): `use` = comment + move a ticket between open and review; `edit` = use + create, edit,
  46. assign, any state, relations; `admin` = edit + settings and members. A project always keeps at least one admin. Everybody else only reads.
  47. Any logged-in user with a display name may open a project and becomes its admin.
  48. - **Tickets** carry `createdBy` and `assignee` (members). **States**: open, progress, pending, review, reopened, done, canceled. A ticket that
  49. goes to review / pending with nobody assigned is assigned to the project's oldest admin (a second, `assign` event). The **inbox**
  50. (`/inbox`, `GET /api/inbox` with a token) shows what is assigned to you, as two lists: pending and review.
  51. - **API aliases**: the old state names are accepted as input (`in progress`, `awaiting creator`, `awaiting-creator`, `confirmed`, `rejected`, `on hold`)
  52. and mean progress / review / done / reopened / pending. Output uses only the new names.
  53. New endpoints: `GET/POST /api/projects`, `GET/POST /api/projects/:slug`, `POST /api/projects/:slug/members` (`{user, role}`; user = display name,
  54. ident id or user id), `POST …/members/remove`, `POST …/invites` (`{role, uses?, days?, email?}` → an ident invite link, ident#22),
  55. `POST /api/tickets/:ref/assign` (`{assignee}`), `GET /api/inbox`. A refused role → 403.
  56. - **Invites**: the person opens ident's link, picks an identity, ident sends them to `/login/callback?ident_code=…&invite=<id>`; only when ident
  57. says that identity accepted the invite (`/api/invites/get`) does the person join with the invite's role.
  58. - **Migration** (`lib/migrate.hl`, idempotent, runs at every start): old projects `{name}` → records, tickets re-linked by id, states renamed
  59. (awaiting creator → review, a "Question…" ticket → pending, confirmed → done, rejected → reopened, in progress → progress, on hold → pending;
  60. review / pending tickets go to the creator), `createdBy` from the created event; members: the creator (TICKETS_CREATOR_IDENTITY, read ONLY here)
  61. is admin, users named Architect / AntColonyScheduler that wrote in a project are edit, everybody else who wrote is use. It compacts the tables
  62. it changed (a second open of a table — the page realm — compacts on open and would rewrite the file under the first handle).
  63. - Short ids: `isIdentId` in `users.hl` accepts old 64-hex and new short ids (ident#23); `tools/migrate-short-ids.hl` + `tests/short-id-switch.mjs` kept.
  64. - Gate: `tests/browser.mjs` (233 checks). The pre-roles browser checks (creator-only confirm, author-only edit, relations by author, tokens page …)
  65. are PARKED in `tests/browser-pre20-parked.txt` — they need porting to the roles.
  66. ## Login (ident) — ticket #7
  67. * **How it works**: ident's identity selector top right (`<ident-selector key=IDENT_API_KEY>`
  68. from `<IDENT_URL>/selector.js`) plus a "Log in with ident" button
  69. (`<IDENT_URL>/login?key=…&return=<TICKETS_PUBLIC_URL>/login/callback`). Both hand tickets a
  70. one-time code; the SERVER exchanges it (`POST <IDENT_EXCHANGE_URL>/api/exchange` with key +
  71. secret) for the **per-app identity id**. Selector: `login.js` bridges the `ident-login` DOM
  72. event into the shell's face `identLogin` — no reload, the pages show their forms (`signedIn`
  73. push to this session's tabs). Button: `/login/callback` sets the session and redirects back to
  74. the page the login started from (ticket #10: at the click `login.js` adds
  75. `?next=<path + query>` to the button's return URL; the server follows only a same-origin
  76. path — one leading `/`, not `//`, no `\`, URL-safe chars, ≤ 500, not `/login/…` — else `/`).
  77. Logout (top right) = the shell's face `logOut`; the selector is reset (class `out` → `loggedIn = false`).
  78. * **`login.js` runs more than once per page** (ticket #9): hl:webex re-creates the header —
  79. the selector element AND the `<script>` elements — whenever the login state flips, and the
  80. browser executes a re-inserted script again. It therefore installs itself once per document
  81. (`window.__ticketsLogin`), listens for `ident-login` on `document`, always looks up the
  82. CURRENT `#selector`, and hands each one-time code to `#identcode` only once. (Before: one more
  83. listener per run → after a logout one selection = two exchanges of the same code → red banner
  84. "ident refused the login (400: unknown or already used code)", although the first logged in.)
  85. * **Users** (`storage/mpackdb/users.*`, `lib/users.hl`): one per identity id `{identity, name,
  86. created}`. The first login asks once for a **display name** (a normal field — ident may fill it
  87. later, CONCEPT point 6); writing waits for it; it cannot be changed afterwards (no UI).
  88. The session holds only `user = { id = <users @id> }` (hl:webex ships `session.user` to the
  89. page); the identity id is never in a page except the user's own `/you`.
  90. * **Authors**: new events store `user` (+ the name as `author`); the history shows the user's
  91. display name. Old events keep their free-text `author`. The web forms and the API have no
  92. author field (API: a body with `author` → 400 naming it).
  93. * **Creator**: `TICKETS_CREATOR_IDENTITY` = the creator's per-app identity id. Only that user
  94. may set `confirmed` / `rejected` (web: message; API: **403** `{error, field:"state"}`).
  95. **Unset = nobody can.** To set it on Byrodin: the creator logs in to tickets, opens **`/you`**
  96. ("Your tickets identity id", 32 hex), the architect puts `TICKETS_CREATOR_IDENTITY=<id>`
  97. into `/CONTAINERS/projects/tickets.worldapi.org/.env` and restarts the container.
  98. `/you` then says "You are the creator".
  99. * **API tokens** (`storage/mpackdb/tokens.*`): on `/you` a logged-in user creates (optional
  100. label), lists and revokes tokens. Shown ONCE (`tkt_` + 48 hex), stored as sha256 only.
  101. `Authorization: Bearer <token>` acts as that user on every API write; no / wrong / revoked
  102. token → **401** (checked before the body). Reads need no token.
  103. **Ident access keys** (ident#27): `Authorization: Bearer idt_…`, a key an identity was given for tickets in ident's Access tab, acts as that
  104. identity with no token made by hand. tickets asks ident on every call (`lib/ident-access.hl`, copied from the components repo; it needs
  105. `IDENT_API_KEY` / `IDENT_API_SECRET`), so a revoked key is refused at the next call. A `write` key may do what that user may do, a `read`
  106. key only GETs (every write answers **403**), a bad or other-app key is **401**, ident not answering is **503** and nothing is written.
  107. A user that never logged in here is made on the first call, named as the identity is named in ident. tkt_ tokens and project keys work as before.
  108. * **Env**: `IDENT_API_KEY` / `IDENT_API_SECRET` (tickets' registration in ident, origin
  109. `https://tickets.worldapi.org`), `TICKETS_CREATOR_IDENTITY` — all in `.env` on Byrodin (the
  110. hybriel runtime loads `.env` beside project.hl; the real environment wins; never commit it).
  111. `IDENT_URL` (default `https://ident.worldapi.org`: selector script + button),
  112. `IDENT_EXCHANGE_URL` (server side; default = IDENT_URL; `docker-compose.yml` sets
  113. `http://127.0.0.1:45002` = ident's loopback port on Byrodin), `TICKETS_PUBLIC_URL` (default
  114. `https://tickets.worldapi.org`: the button's return URL).
  115. * **ident down**: a login answers "ident did not answer" (the global `on Error` in project.hl
  116. absorbs hl:fetch's failure — it logs `error absorbed: …` for every plugin error).
  117. ## Markdown, editing (tickets #6, #8 — mission 007 (old 014))
  118. * **Markdown in text fields** (summary, comment text, state note): `lib/markdown.hl` parses the text
  119. into plain data (blocks → spans), `components/markdown.hl` builds elements from it — every
  120. character ends up in a TEXT node, no HTML string exists, so raw HTML / `<script>` shows as text.
  121. Links only when `safeHref` accepts them: `http(s):`, `mailto:`, `/path` (not `//`), `#…`;
  122. `javascript:`, `data:`, `vbscript:` etc. stay text. Understood: `#`…`######` headings (shown as
  123. h3/h4/h5), `-`/`*`/`+` and `1.`/`1)` lists (one level; a list may interrupt a paragraph), fenced
  124. code (``` / ~~~), `code`, `[text](url)`, `<https://…>`, bare http(s) URLs, `*em*`, `**strong**`,
  125. `***both***` (also `_`), `\` escapes, **GitHub pipe tables** (mission 013, below). Single line breaks inside a paragraph
  126. are KEPT (the page showed them before). Not: quotes, images, nested lists.
  127. * **Tables (mission 013, the rules of notes#5 — notes.worldapi.org reports/003-md-tables.md)**: a header row with a
  128. delimiter row right under it that has as many cells (`|---|:--:|--:|`: each cell `:?-+:?`, the colons = left / center /
  129. right; the delimiter row must hold a `|`); body rows up to a blank line, a heading, a fence or a list item (a short row is
  130. padded, a long one cut); cells split at every unescaped `|` (`\|` is a pipe in the cell, also inside `code`); outer pipes
  131. optional; every cell is inline Markdown; a table may interrupt a paragraph; a line with pipes but no delimiter row under it
  132. stays text. Rendered as `<markdown-table><table>` (`<th>`/`<td>` with `data-align`), every character a text node like the
  133. rest; thin grey lines (`colorBorder`), bold header, no colour; the `<markdown-table>` box scrolls sideways when the table
  134. is wider (cells keep their words whole) — the page never does. Only pages change: API JSON and `Accept: text/markdown`
  135. answer the raw text as before. The editor (`shared/md-editor.js`) does NOT know tables (it is being retired for the
  136. Hybriel MdEditor): its visual mode shows the pipe lines as text; its "Markdown source" view types them as they are.
  137. Gate: `tests/browser.mjs` "tables:" (a comment typed with real keys in the source view). Real data:
  138. `tests/realdata-compare-md.py` (README "Test"). Only pages and pushes carry the
  139. parsed blocks (`md`, `summaryMd`, `oldSummaryMd` via `lib/events.hl pageEventOf`); **API JSON unchanged**.
  140. * **Read view for LLMs**: `Accept: text/markdown` on `GET /api/tickets`, `/api/projects/:slug/tickets`,
  141. `/api/tickets/:ref`, `/api/projects/:slug/tickets/:number` → `text/markdown` (+ `Vary: Accept`),
  142. built by `lib/mdview.hl`: one ticket = `# <project> #n: <subject>`, a meta line, URL, the summary as
  143. written, `## History` with one `### <seq> · <when> · <author> <what>` per event (texts below, an
  144. edit shows "Subject before:" / "Summary before:" quoted); a list = `# Tickets (<filters>): N` +
  145. one line per ticket. Markdown wins only if it is listed with q > 0 and preferred to
  146. `application/json` (higher q, or same q and first); `*/*` / none → JSON. Errors stay JSON.
  147. `curl -s -H 'Accept: text/markdown' http://127.0.0.1:8350/api/projects/tickets.worldapi.org/tickets/6`
  148. * **Editing**: the ticket's AUTHOR (the user of its `created` event) edits subject + summary —
  149. web: "Edit" on the ticket page (form, Save/Cancel), API: `POST …/edit { subject?, summary? }`.
  150. **A ticket from before the login** (created event without a user, only an author string):
  151. **only the creator** (`TICKETS_CREATOR_IDENTITY`) may edit it. Anyone else: web message, API
  152. **403**. The edit is a new history event `kind:"edit"` with `oldSubject`/`oldSummary` +
  153. `newSubject`/`newSummary` (+ `subjectChanged`/`summaryChanged`, `isEdit`) — earlier versions stay
  154. (append-only); pushed live like a comment (the page takes over subject + summary). The page
  155. shows "X edited the ticket", "Subject before" (struck through) and the previous summary folded.
  156. No migration: only NEW events have the edit fields; existing JSON is byte-identical (mission 007 (old 014)
  157. `.scratch/m014/compat.sh`).
  158. * **SECURITY (hl:webex, patched locally until antcolony mission 036; hl:web escapes it itself, hybriel#34)**: webex put the page's state (= user text) into an
  159. inline `<script>` without escaping `</script>` → a summary/comment with
  160. `</script><img src=x onerror=…>` RAN in every viewer's browser (stored XSS, reproduced on the
  161. pre-m014 code: `node .scratch/m014/xsscheck.mjs <url>` → `__pwned = 1`). Fixed in the vendored
  162. `plugins/webex/WebFramework.hl` (seed: every `<` written as `\u003c`); to be filed as a Hybriel issue (mission 007 (old 014) report).
  163. The gate's `</script>` check (MD_RICH) still guards it.
  164. ## Markdown editor (ticket #12 — missions 009 (old 024) + antcolony 025; mission 016: the Hybriel MdEditor)
  165. * Since mission 016 every Markdown field — the new-ticket summary, the edit summary, the state note, a project's description and
  166. the comment form — is the **Hybriel MdEditor** (`components/md-editor/md-editor.hl`, copied verbatim from
  167. components.hybriel.worldapi.org with the Comments block; its README beside it: toolbar, keyboard, tables, "Markdown source").
  168. Edited visually, the value stays plain Markdown in the editor's hidden field `<input name>`, which fires a bubbling `input`;
  169. the page wraps the editor in an `<md-field>` (caption + editor) whose `on input` takes the value when `e.target.name` is the
  170. editor's name (its link and source fields fire `input` too). Ctrl/Cmd+Enter sends the form. Members, faces, API and stored
  171. data are unchanged.
  172. * **Not inside a `<label>`**: a label hands a click to its first labelable descendant — the editor's "B" button.
  173. * The editor is built ONCE per element and builds again when the bound `value` changes: the pages bind a start value that does
  174. not change while typing (`editStart`, `descriptionStart`) and, to empty a form after a send, give it a new key
  175. (`noteForms` / `summaryForms` = `[{ id = 'note-' + n }]`, as the Comments block does with its own form).
  176. * **`shared/md-editor.js` (the old JS `<md-editor>`, worldapi-components) is gone from this app** (and `/md-editor.js`): it
  177. defined the custom element `md-editor` for the whole document and took over the MdEditor's own `<md-editor>` elements (shadow
  178. DOM; the block's comment text collapsed to 1 px — measured in mission 016). `md-editor.js` stays a reserved slug.
  179. * Without JS a page shows no editor content (the MdEditor builds it in the browser); the forms need JS as before.
  180. ## Comments (mission 016 — layouts#2: the shared Comments block, edit, delete, like)
  181. * **The block**: `components/comments/comments.hl` (+ `components/md-editor/`), BYTE-VERBATIM copies of
  182. components.hybriel.worldapi.org — `tools/sync-components.sh [commit]` copies them out of git and writes `components/SOURCE`
  183. (now `8176eb1`); `tools/sync-components.sh --check` compares. Never edit the copies (change them there, commit, sync, run the
  184. gates). Its README: `components/comments/README.md` (data in, the four functions, the markup).
  185. * **The ticket page** (`components/ticket.hl`): the history stays as it was; only its comments are drawn by the block. Every RUN
  186. of comments that follow each other is one block in its place between the other entries (`entriesOf`: a list of `{ id,
  187. isGroup, comments }` / `{ id, isEvent, ev }`), so state changes, edits, assigns, links stay where they were. "Write a
  188. comment" under "Respond" is one more block, showing only its form. Inside the history the block's count line ("2 comments"),
  189. its "No comments yet." and its form are hidden by `components/ticket.hl`'s Style block — **the block has no switch for them** (a wish for
  190. components.hybriel: `count` / `form` switches, so a host can place runs of comments between other entries).
  191. `user` = the display name of a member, else `''` (signed out / no member: read only — no form, no Edit / Delete, the like
  192. does nothing). The block shows Edit / Delete where `author == user` (display names); the SERVER decides by the user id.
  193. * **Rights** (`lib/comments.hl`): **edit** and **delete** — the comment's author (its `user`), while a member of the project;
  194. a comment from before the login (no `user`) cannot be changed. **Like** — any member; one per user, pressing again takes it
  195. back. Faces `ticketCommentEdit(ticketId, commentId, text)`, `ticketCommentDelete(ticketId, commentId)`,
  196. `ticketCommentLike(ticketId, commentId)` (and `commentOn` for a post, as before).
  197. * **Storage** (append only, no migration — both tables are created empty at the first start): a comment stays its history
  198. event (kind `comment`, its FIRST text). `storage/mpackdb/comment-changes.*` `{ event, ticket, kind: 'edit' | 'delete', user,
  199. text (edit: the new one), created }`; `storage/mpackdb/comment-likes.*` `{ event, ticket, user, key: event/user, created }`
  200. (a taken-back like is deleted). The comment shown = the newest edit; its earlier versions = the first text + every edit but
  201. the newest. An edit / delete / like does NOT change the ticket's `updated` or `events` and is no history event.
  202. * **A deleted comment leaves one line in the history** (decision, mission 016): "alice commented (deleted 2026-10-20 11:40)" in
  203. its place, no text — so a state change or comment that answered it still reads in order. Its text is gone from the page, the
  204. pushes, the JSON API and the Markdown view; the stored texts stay (append only).
  205. * **Live**: a post is the `ticketEvent` push as before; an edit, delete or like pushes `commentChanged(ticketId, event)` (public
  206. audience, project.hl) and every open page swaps that row. The page rows of comments carry `likedBy` (users @ids — public like
  207. the API's `userId`) so each page works out "liked" for its own user. A block whose list changes is built anew (hl:web), so an
  208. edit someone has open in that run of comments is closed by a push to the same run.
  209. * **The block draws the texts in the browser** (MdEditor readonly): the server's HTML carries each comment's Markdown in the
  210. block's hidden field, escaped — comments are no longer formatted by `lib/markdown.hl` on the server (summaries and state
  211. notes still are). Tables in comments are the MdEditor's (the table itself scrolls).
  212. * **API for programs** (both URL forms, `Authorization: Bearer` as for a comment; a connected app's key + `X-Tickets-Identity`
  213. works too): `POST …/comments/:comment/edit { text }`, `POST …/comments/:comment/delete` (body empty or `{}`),
  214. `POST …/comments/:comment/like` (body empty or `{}`; again = take it back), `:comment` = the comment's event `id` →
  215. **200** `{ ticket, event (the comment as it is now), liked (like only) }`; 401 no token, 403 not the author / not a member,
  216. 404 no such ticket / comment, 400 empty or unchanged text, a deleted comment, a non-comment entry, a bad body.
  217. **Event rows (JSON): unchanged for every untouched comment.** Only a changed comment carries more keys: edited → `text` is the
  218. newest, `edited: true`, `editedWhen`, `earlier: [{ when, text }]` (oldest first); deleted → `text: ""`, `hasText: false`,
  219. `deleted: true`, `deletedWhen`, `label: "commented (deleted …)"`; liked → `likes` (the count, only when > 0). The Markdown view
  220. shows the newest text with "commented (edited …)", a deleted one as its label without text. **The event stream
  221. (`/api/events`) is unchanged: edits, deletions and likes are not sent to programs** (no new event kind; a program that needs
  222. them reads the ticket again).
  223. * **Test**: `tests/browser.mjs` "m016:" (21 checks, own project "Comments block": interleaving, a non-member reads only and is
  224. refused by faces + API, post with real keys + Ctrl+Enter, edit with the earlier version folding out, like toggle seen live,
  225. Edit / Delete only on your own comment, delete asks (Keep / Delete) and leaves its line, the API table, the keys of an untouched
  226. comment, no overflow at 390 / 1280 px; screenshots `gate-{phone,desktop}-comments.png`).
  227. ## Attachments in comments (mission 017/018 — ticket #27)
  228. Pictures and files in a comment: on the ticket page the "Respond" form sits inside the shared FilesUpload (pick mode) — choose files,
  229. Camera (phone), drop or Ctrl+V a picture; they wait as thumbnails; Ctrl+Enter / Comment sends text + files as one comment (files only is fine).
  230. In the thread pictures are 6 rem thumbnails (tap = full picture in a new tab), other files are rows (kind, name, size). A non-member sees name + size only.
  231. * **Limits**: 10 files, 10 MiB each, 25 MiB per comment, no empty file. Type from the CONTENT (PNG, JPEG, GIF, WebP, PDF; text types; else octet-stream);
  232. a fake picture is refused. Bytes in `storage/attachments/<id>` (`TICKETS_ATTACHMENTS` moves it; deploy backups of `storage/` include them), rows in `attachments.db`.
  233. * **Who may fetch**: members of the project (session, user token or the project's app key) — reading a ticket is public, its files are not. 401 no login, 403 not a member.
  234. Delete drops the files (404); edit keeps them. Served with nosniff, a sandbox CSP, pictures inline, the rest as download.
  235. * **API**: `POST /api/projects/:slug/tickets/:n/comments` takes `multipart/form-data` (fields `text`, `file` repeated; JSON as before) → 201,
  236. `event.attachments = [{ id, name, type, size, image, url }]`; `GET /api/attachments/:id`. 413 over a limit, 400 fake picture / unknown field.
  237. Only comments with files carry `attachments`; every other row is unchanged.
  238. ```
  239. curl -H "Authorization: Bearer $TOKEN" -F 'text=390 px review' -F [email protected] -F [email protected] \
  240. https://tickets.worldapi.org/api/projects/<slug>/tickets/<n>/comments
  241. curl -H "Authorization: Bearer $TOKEN" -o shot.png https://tickets.worldapi.org/api/attachments/<id>
  242. ```
  243. * **Test**: `tests/browser.mjs` "m017:" (22 checks: API multipart, refusals, member-only fetch, page with real choose / paste / Ctrl+Enter, live view for B,
  244. edit keeps, delete drops, Markdown view, 390 px targets ≥ 44 px, no overflow). Gate **373 / 0** (was 351; events 52 / 0).
  245. The m017 checks fail on the old code (2 fail, the run aborts).
  246. ## Relations: parent / child, blocked by (ticket #4 — mission 008 (old 017))
  247. * **Parent / child**: a ticket has at most one parent (any project). The parent's page lists its
  248. children with their states ("Children"); a child says "Part of <parent>". **Blocked by**: a ticket
  249. can wait on any number of tickets (any project); the blocked page lists "Blocked by", the other
  250. side "Blocks" — each with its state.
  251. * **Parent state** (smallest rule): `allChildrenConfirmed` = the ticket has children and every child
  252. is `confirmed`. The page shows "all children confirmed (n)" in green, else "k of n children
  253. confirmed". The parent's own state is NEVER changed by it — only the creator confirms.
  254. * **Who may set / remove a relation** (mission ST): a member with the role edit or admin in THIS ticket's
  255. project (the ticket whose parent / blocker changes: for a blocker, the BLOCKED one). Naming a ticket of
  256. another project is fine; changing the relations of a ticket in a project where you have no such role is
  257. 403. (It used to be enough to have the role in either project.) Refused: a ticket as its own parent /
  258. blocker, loops (a parent below the ticket, a blocker that already waits on it, also transitively),
  259. duplicates, unknown tickets.
  260. * **Naming a ticket**: `<project>#<number>` (spaces around `#` allowed, e.g. `ident.worldapi.org#1`)
  261. or its UUID.
  262. * **Storage**: a NEW table `storage/mpackdb/links.*` (`{ kind: 'parent'|'blockedBy', ticket, other,
  263. user, created }`, indexes `@ticket`, `@other`), created empty at the first start — no migration. A
  264. removed relation is deleted there; the HISTORY keeps every change: an event `kind:"link"` on the
  265. child / the blocked ticket ("set the parent to X #1 (was Y #2)", "removed the parent X #1", "marked
  266. it blocked by X #5", "removed the blocker X #5"; extra JSON keys `isLink, linkKind ('parent' |
  267. 'blockedBy'), linkAction ('set' | 'removed'), otherRef, otherHref, previousRef` — only on link events).
  268. * **JSON**: every ticket row (list AND single GET, pushes) has `parent` (a ref or `null`), `children`,
  269. `blockedBy`, `blocks` (lists of refs, oldest link first) and `allChildrenConfirmed`. A ref =
  270. `{ id, project, number, ref ('#1'), key ('ident.worldapi.org#1'), subject, state, stateSlug, href,
  271. apiHref }`. All other keys unchanged (mission 008 (old 017) `.scratch/m017/compat.sh`).
  272. * **Markdown view**: under the URL line `Parent: <p> #n [state] subject · url`, `Children (k of n
  273. confirmed):` / `Children (all n confirmed):`, `Blocked by:`, `Blocks:` (one `- <p> #n [state]
  274. subject · url` line each); a list line ends with ` · parent … · children n, k confirmed | all
  275. confirmed · blocked by <p> #n [state], … · blocks …` (only the parts that exist).
  276. * **Web** (logged in): under "Respond" the forms "Parent ticket (project#number)" → Set parent /
  277. Remove parent, "Blocked by (project#number)" → Add blocker; a "Remove" button per blocker row.
  278. Faces `ticketSetParent(id, key)` ('' = remove), `ticketAddBlocker`, `ticketRemoveBlocker`.
  279. * **Live**: every relation write, state change and edit pushes `ticketsRelated(views)` — the relation
  280. view of the ticket and of every ticket related to it (+ one just unlinked); an open page of any of
  281. them follows without a reload (a child confirmed → the parent's "k of n" moves).
  282. * **For the scheduler**: parent tickets = rows with `children.length > 0` (don't pick them as work);
  283. a ticket waits while any `blockedBy[].state` is not what the scheduler counts as done. A report's
  284. `issues[].blocks = true` → create the issue ticket, then `POST <original>/blocked-by {"add":
  285. "<project>#<n>"}` with the scheduler's token (it is the issue's author, so it may).
  286. ## PWA — installable app, icons, offline shell (antcolony mission 046)
  287. Done the way calendar.worldapi.org does it: hl:web generates everything from `project.hl` — no JavaScript of ours.
  288. - `appTitle` "tickets", `appIcons` (192/512, `any` + `maskable`, same PNGs), `appTouchIcon`, `appFavicon`,
  289. `appThemeColor` = the header's `darker` `rgb(15, 20, 25)` (as tracker), `appBackgroundColor` = dark `rgb(25, 30, 35)` (both from `shared/tokens.hl`).
  290. Served: `/__hl/manifest.webmanifest` (linked from every head with apple-touch-icon + theme-color), `/__hl/sw.js`.
  291. - `offline = [ TicketList ]`: `/` is the ticket list, so offline it is the list as this browser last loaded it (the worker
  292. precaches `/` at install; a visited `/<slug>` is kept too). Every other page offline → hl:web's "Unavailable
  293. offline" (503). TicketList's emits are all value-form, so nothing is queued offline.
  294. - "You are offline" note in the shell (`components/main.hl` `offline`, `#offline`): hl:web has no connection state and no
  295. mount hook, so an invisible `<net-probe>` runs an endless 1 s CSS animation (`components/main.hl`'s Style, `tickets-net-tick`) and every
  296. `animationiteration` reads `navigator.onLine` (same trick as tracker).
  297. - Icons `icons/`: `icon.svg` is the SOURCE (a tilted ticket stub, purple on dark, inside the maskable safe circle r=205).
  298. Rebuild after editing it:
  299. ```bash
  300. cd icons && for s in 192 512; do rsvg-convert -w $s -h $s icon.svg -o icon-$s.png; done
  301. rsvg-convert -w 180 -h 180 icon.svg -o apple-touch-icon.png
  302. for s in 16 32 48; do rsvg-convert -w $s -h $s icon.svg -o /tmp/fav-$s.png; done
  303. magick /tmp/fav-16.png /tmp/fav-32.png /tmp/fav-48.png favicon.ico
  304. ```
  305. Each icon has its own `file` route in `project.hl` (`/favicon.ico` serves `icons/favicon.ico`).
  306. - Test: the gate's last part (browser C) — see "Test (the gate)".
  307. ## Deploy (Byrodin)
  308. Target: `/CONTAINERS/projects/tickets.worldapi.org` on Byrodin, container `tickets.worldapi.org`
  309. (`docker-compose.yml`: debian:12-slim, host network, `HL_HOST=127.0.0.1`, `TICKETS_PORT=45003`,
  310. `TICKETS_WATCH=0`, the folder mounted at `/home/tickets`, `./bin/hybriel project.hl`), public
  311. https://tickets.worldapi.org/ via nginx (TLS ends there; the vhost needs the WebSocket Upgrade
  312. headers — the live push rides `/__hl/socket`; no baseUrl/tls in the app, like notes).
  313. * **First deploy: done by the architect** (folder + data, nginx vhost, cert, DNS).
  314. * **Later: `./deploy.sh`** on Loreana, in this folder: runs the gate (refuses on a failure;
  315. `--skip-tests` skips it LOUDLY), backs up `storage/`/`.sessions/`/`.env` (what exists) to
  316. Loreana's `/media/SLOW1TB2/deploy-backups/<app>/` (newest 5 kept; an empty/failed backup stops
  317. the deploy), then rsyncs the code to
  318. `[email protected]:/CONTAINERS/projects/tickets.worldapi.org` (never `storage/`, `.sessions/`,
  319. `.env`, `.scratch/`, `server.*`, `testapp/`, logs — the preview is checked for them; no
  320. `--delete`), `docker compose up -d && docker compose restart` over `ssh -F /dev/null`, then
  321. waits for https://tickets.worldapi.org/ to answer 200 (up to `DEPLOY_URL_WAIT`, default 120 s: a new binary or new code
  322. compiles at the first start, ~23 s, hybriel#148). Every step is printed. Gates: `tests/browser.mjs` and `tests/events.mjs`
  323. (the event stream is used by a live push service).
  324. * Container (worker w9): `/tmp` is a tmpfs (`exec`, the compiler writes scratch files there) and `/root/.hybriel` (the build
  325. cache; HOME=/root in the container) is the named volume `hybriel-cache`, so a restart starts warm. Checked locally with a
  326. copy of this compose file (own name, port 8739, copy of real data): first start 200 after 33 s (incl. image build), warm
  327. `down`+`up` 2.4 s, cache emptied → 27 s, stop 0.1 s.
  328. * `./deploy.sh --dry-run` = gate + `rsync -n` + the commands it would run (no restart, no URL
  329. check). `--target DIR|HOST:DIR` / `--url URL` point it elsewhere (tested only against a local
  330. directory, ident STATUS "ident mission 006 (old 010)").
  331. * Import on Byrodin: `TICKETS_URL=http://127.0.0.1:45003 TICKETS_TOKEN=tkt_… ./bin/hybriel tools/import.hl` (in the container
  332. or on the host with the vendored binary).
  333. * Session cookie `hlsid` (hl:web default; on https also `Secure`, mission ST2 — the NAME is unchanged so no one is signed out; host-only; tickets has its own host on Byrodin). Login: `.env` needs
  334. `IDENT_API_KEY`, `IDENT_API_SECRET`, later `TICKETS_CREATOR_IDENTITY` (section "Login (ident)").
  335. No migration: `users.*` / `tokens.*` are created empty at the first start; old events keep
  336. their authors (checked mission 005 (old 011): every GET of old vs new code on a copy of the store identical).
  337. ## Import the AntColony ticket files
  338. ```bash
  339. # on byrodin — refresh the copies:
  340. scp /CONTAINERS/projects/antcolony/tickets/*.md loreana:/media/STORAGE/projects/WorldAPI/tickets.worldapi.org/import/tickets/
  341. # on loreana, with the server running (an API token of the user who should open them, /you):
  342. TICKETS_TOKEN=tkt_… ./bin/hybriel tools/import.hl # TICKETS_IMPORT_DIR (default import/tickets of the app), TICKETS_URL (default http://127.0.0.1:8350)
  343. ```
  344. Format: `project:` and `subject:` header lines, blank line, summary (`lib/import.hl`). The
  345. summary is hard-wrapped text: its lines are joined into paragraphs (one space), a blank line
  346. starts a new paragraph; a Markdown list line (`- `, `* `, `1. ` after trimming) starts a new
  347. line (`\n`) and following ordinary lines join onto it (wrapped item; nesting indentation is
  348. dropped); stored as paragraphs separated by `\n\n`, shown with `white-space: pre-wrap`. CRLF files work. Each file is POSTed to
  349. the RUNNING server (`/api/tickets` with `source` = file name); a known source answers the
  350. existing ticket, so re-running prints `0 new, N already there`. New tickets are numbered
  351. per project in sorted file-name order (output: `NEW 0004-scheduler.md → antcolony #1`).
  352. ## Ticket numbers, URLs, the migration (ticket #38)
  353. * A ticket's key is the mpackdb UUID (`id`, e.g. `0mufbphip3w7`). People use **project +
  354. number**: numbers count per project from 1 (next = highest in the project + 1).
  355. * **Slug rule: the project slug IS the project name, as is.** A new project name may only hold
  356. letters, digits, `.`, `_`, `-` (all existing names do), so it goes into URLs unescaped.
  357. * Ticket page: **`/<project>/<number>`** (e.g. `/tickets.worldapi.org/5`; ticket #25 — before it was
  358. `/projects/<project>/<number>`, which now answers 301). `/<project>` = the project's list (same as `/project/<project>`).
  359. * **Old global numbers** (`#1`…`#39` in docs and comments) are kept on the migrated tickets
  360. as `oldNumber`; the ticket page shows "formerly #38"; **`/tickets/<old n>` → 301** to the new
  361. URL (also `/tickets/<uuid>`); `/api/tickets/<old n>` keeps answering. New tickets get no old number.
  362. * Ordering never uses key order: lists by stored `updated`, a history by (`created`, `seq`),
  363. projects by `created`.
  364. * Migration 2026-09-24 (`tools/migrate-008.hl`, idempotent, header explains it): old #N →
  365. `<project> #k` by creation order. Mapping printed in `.scratch/deploy-008-<ts>/migrate-run1.txt`;
  366. or ask the API: `curl -s localhost:8350/api/tickets/38 | jq .ticket.href`.
  367. ## Short URLs (ticket #25)
  368. * **Pages**: project `/<slug>`, ticket `/<slug>/<number>` (`lib/util.hl` `projectHrefOf` / `ticketHref` — every page link
  369. and the `href` / `projectHref` of the API rows). Settings stay at `/projects/<slug>/settings`; the filter pages
  370. `/project/<slug>[/state/<s>]` and `/state/<s>` are unchanged.
  371. * **Old URLs answer 301** (`lib/api.hl`, to the project's CURRENT slug, so an old slug lands on the new one):
  372. `/projects/<slug>` → `/<slug>`, `/projects/<slug>/<n>` and `/projects/<slug>/tickets/<n>` (the form the conductor sent)
  373. → `/<slug>/<n>`, `/tickets/<old n | uuid>` → `/<slug>/<n>`. What names no project / ticket → 404 text, no Location.
  374. * **The API paths are unchanged** (`/api/projects/<slug>/…`, `/api/tickets/<ref>`); only the page links inside its answers
  375. are the short ones (`apiHref`, `settingsHref` unchanged).
  376. * **A project by its id (mission 012, ticket #25 comments 2 + 4)**: every `/api/projects/<x>/…` route takes the project's
  377. slug (also an old one) OR its id — the 12-character record id of the projects table (`[0-9a-z]{12}`, e.g.
  378. `0mufbw18nsuj` = tickets.worldapi.org; `id` in `GET /api/projects` `details` and in `GET /api/projects/<x>` `project`).
  379. It never changes, also not when the slug does. `lib/projects.hl slugOfRef` turns an id into the CURRENT slug (a slug is
  380. tried first, so it wins should a slug ever equal an id); the routes then run exactly as with the slug — the answers are
  381. byte for byte the same. Tickets stay under their project (`/api/projects/<x>/tickets/<n>`, numbers count per project);
  382. there is NO new global `/api/tickets/<x>` (the old one — old global number or ticket UUID — stays as it was).
  383. Pages are not affected (`/<slug>`, `/projects/<slug>` take slugs only).
  384. * **Route order** (hl:web: the FIRST matching route answers, authored order): explicit routes first, the two slug pages
  385. last (`lastPage = true` in `project.hl`). hl:web APPENDS its own urls (`/__hl/app.css`, `/__hl/emit`, `/__hl/sw.js`,
  386. `/__hl/manifest.webmanifest`, `/__hl/hl-runtime.js`, the component modules `/components/<file>.hl`) to the table while
  387. it is constructed, i.e. AFTER the app's — at the end of our table `/:projectSlug/:ticketNumber` still answered them
  388. with a ticket page (measured; the gate fails 15 checks and stops). So project.hl moves the `lastPage` routes to the end
  389. of `server.router.routes` right after `new WebFramework(…)`. They stay in the table itself because hl:web serves the
  390. module of a component only if a route mounts it at construction, and the service worker's page table reads it.
  391. Survives the dev watcher's re-analysis (checked). Upstream fix would be hl:web matching its own urls first.
  392. * **Reserved slugs** (`lib/projects.hl` `reservedSlugs`, lower-case compare): every first path segment a route answers
  393. (`api`, `__hl`, `components`, `login`, `projects`, `inbox`, `you`, …) plus a few for later (`my`, `assets`, `sign-in`,
  394. `settings`, `search`, …). A new project or a slug change to one → 400 `field:"slug"` "… is reserved"; a proposed slug
  395. from a title skips them (`Inbox` → `inbox-2`). The gate checks that every first segment of project.hl's routes is in the
  396. list — **a new route with a new first segment must add it there.** Live data 2026-10-03: no collision (11 slugs, no old slugs).
  397. ## Test (the gate)
  398. `node tests/move.mjs` gates administrative moves on isolated fixtures (default port 8740). It checks both-admin permissions, unchanged data on 403, target numbering and numberFloor, comments, both relation directions, both project histories in HTML/Markdown, API 301s including subpaths, repeated moves, event-stream delivery, source number reservation and persistence after restart. `MOVE_TREE`, `MOVE_BIN`, `MOVE_STORE`, `MOVE_PORT` select an old checkout for the required failing comparison.
  399. **The #94 purge (mission 028, `lib/migrate.hl` purgeTicket94):** `node tests/purge94.mjs <fixtureDir> <workDir> <oldTree> <newTree> <portA> <portB>` runs a fixture (fake project miserit-anthar, built by `tests/purge94-seed.hl` into `<fixtureDir>/base/storage`, its output line in `<fixtureDir>/seed.json`) through an old and the new tree and checks counts per table (`tests/purge94-count.hl`), 404s, no trace of the ticket id in any file, other tickets byte-identical, numbering 95, and that a further start rewrites no file. The old tree must fail it.
  400. ```bash
  401. node tests/browser.mjs # 351 checks (mission 016; 315 in mission 012), ~6 min with the cold starts; own server on :8352, own ident on :8353,
  402. # exchange-counting proxy on :8357 (TICKETS_GATE_EXCHANGE_PORT),
  403. # own storage in .scratch/gate-store (ident's code copied WITHOUT
  404. # .env to .scratch/gate-store/ident, mail to a sink — never real mail)
  405. ```
  406. **Cold start** (hybriel#148, worker w9): every start of a .hl program (server, ident, `tools/import.hl`, `tests/*.hl`)
  407. compiles first (~23 s cold, ~1.5 s warm). The tests wait up to `TICKETS_COLD_MS` (default 120000) for a start. All gates of
  408. this app, as `deploy.sh` runs them: `node tests/browser.mjs`, `node tests/events.mjs`; besides: `node tests/connect.mjs`,
  409. `node tests/short-id-switch.mjs`. Worker w9 ran them in slot 8720–8739:
  410. `TICKETS_GATE_PORT=8725 TICKETS_GATE_IDENT_PORT=8726 TICKETS_GATE_EXCHANGE_PORT=8727 TICKETS_GATE_CHROME_A=8728-8729
  411. TICKETS_GATE_CHROME_B=8730-8731 TICKETS_GATE_CHROME_C=8732-8733 node tests/browser.mjs`,
  412. `TICKETS_EVENTS_PORT=8721 TICKETS_EVENTS_CHROME=8722-8724 node tests/events.mjs`,
  413. `TICKETS_CONNECT_PORT=8734 TICKETS_CONNECT_IDENT_PORT=8735 TICKETS_CONNECT_APP_PORT=8736 TICKETS_CONNECT_CHROME=8737-8739 node tests/connect.mjs`,
  414. `SWITCH_IDENT_PORT=8735 SWITCH_PORT=8736 node tests/short-id-switch.mjs`.
  415. Worker w13 (mission 013, tables; slot 8740–8759): `.scratch/w13/gates.sh <outdir> browser|events|connect|switch` (browser
  416. 8740–8751, events 8752–8755, connect 8756–8758 + Chrome 8753–8755, short-id 8758/8759).
  417. **Real data, Markdown rendering** (mission 013): run `tests/realdata-baseline.mjs` for the OLD tree (`git archive` of the
  418. base commit + this `bin/`, so only the code differs) and the new one on two ports, then
  419. `python3 tests/realdata-compare-md.py <old> <new> <oldPort> <newPort>`: every answer must be the same except the pages of
  420. tickets whose texts hold a table (it prints them with their `<table>` counts). Besides realdata-compare.py's masks it removes
  421. the port, the Markdown View's one new template fragment and the empty `if` markers `<!--[--><!--]-->`.
  422. **Ports** (mission 008 (old 017)): `TICKETS_GATE_PORT`, `TICKETS_GATE_IDENT_PORT`, `TICKETS_GATE_EXCHANGE_PORT`,
  423. `TICKETS_GATE_CHROME_A` / `TICKETS_GATE_CHROME_B` (`"8810-8814"`; default 8620-8629 / 8630-8639) — a
  424. worker with a port range runs e.g. `bash .scratch/m017/gate.sh <out.txt>` (8800-8819).
  425. `TICKETS_GATE_CHROME_C` (default 8640-8649) is the PWA browser. antcolony Mission 046 ran it as
  426. `TICKETS_GATE_PORT=8750 TICKETS_GATE_IDENT_PORT=8751 TICKETS_GATE_EXCHANGE_PORT=8752 TICKETS_GATE_CHROME_A=8753-8754
  427. TICKETS_GATE_CHROME_B=8755-8756 TICKETS_GATE_CHROME_C=8757-8759 node tests/browser.mjs` → 245 passed (~30 s).
  428. antcolony Mission 046 part (**PWA**, at the very end, own fresh Chrome C): head links manifest / apple-touch-icon / favicon /
  429. theme-color; manifest fields; every icon a real PNG of its size; favicon.ico + icon.svg; the worker registered with
  430. scope `/` and controlling; `Page.getInstallabilityErrors` empty; then the SERVER IS STOPPED and the page set offline
  431. (CDP) → reload `/` shows header + last list + `#offline`; `/inbox` → "Unavailable offline"; online again → the note goes.
  432. Screenshots `.scratch/gate-pwa-phone-online.png` / `gate-pwa-phone-offline.png` (390 px) — LOOK at them.
  433. **Ident for the gate**: the gate runs ident's CODE from `../ident.worldapi.org` (or `TICKETS_GATE_IDENT_DIR`). On 2026-10-01 ident was
  434. being re-vendored to hybriel master and its own sign-in broke (`ident /code page` timeout at browser.mjs:552; ident's own gate fails
  435. the same way). Tickets' gate then ran against a snapshot of ident's code with ident's 837fe120 bin/plugins (what live ident runs):
  436. `.scratch/w048/ident-snap` (`TICKETS_GATE_IDENT_DIR=$PWD/.scratch/w048/ident-snap`). Remake it from ident (without .env/storage/.sessions/.scratch) if ident moves on.
  437. antcolony Mission 048 "**once:**" checks: after a comment, a state change and adding a member, the new row is in the list exactly once
  438. (hybriel 64527baa+ answers a session face with a sync of session-derived members — a handler appending the row too would double it).
  439. `connected(page)` in the gate waits until the server has READ the tab's `hello` (a ping on the same socket, its pong),
  440. not just an open socket: a push sent before that reaches no component (the inbox-live check failed ~1 in 5 without it).
  441. Mission 011 part (**#25 short URLs**, after "numbers"): `/gamma`, `/gamma/1`, `/beta.example.org/2`, `/alpha/3` SSR 200;
  442. 6 old URLs → 301 to the short one (`/projects/<s>`, `/projects/<s>/<n>`, `/projects/<s>/tickets/<n>`, `/tickets/<old n>`), 6 that name
  443. nothing → 404 without Location (incl. a CR/LF number); `/nope` says no such project; hl:web's own urls keep their content types
  444. (`/__hl/app.css`, runtime, sw, manifest, client.js, `/components/{ticket,ticket_list,main}.hl`, POST `/__hl/emit`); in Chrome
  445. `/projects/gamma/tickets/1` lands on `/gamma/1`, the project link → `/gamma` and a row → `/gamma/2` without a reload; 10 reserved
  446. slugs refused at creation, a slug change to `inbox` refused; every first segment of project.hl's routes is in `reservedSlugs`;
  447. `/projects/<old slug>` → 301 `/<current slug>`. Control: without the reorder in project.hl the gate ends 35 passed, 15 failed.
  448. Mission 009 (old 024) part (**#12 Markdown editor**, before the console check): bob on his ticket — SSR has the
  449. plain textareas inside `<md-editor>`, `/md-editor.js` served, editors upgraded; a comment by REAL typing
  450. (`**x**`, `` `x` ``, `- ` list) sent with Ctrl+Enter → stored Markdown + rendered + editor cleared; a
  451. state note with the toolbar "B"; a hostile rich paste (img onerror, script, javascript: link) reduced
  452. to the subset, sent, rendered safely; the edit form opens the stored summary formatted and byte for
  453. byte, typing at the end changes only that block, saved; at 390px the new-ticket form with toolbar
  454. taps (inline code) → stored. Screenshots `gate-{phone,desktop}-mdeditor.png`, `gate-phone-newticket-mdeditor.png`.
  455. The component's own test (72 checks): `worldapi-components/test/run.mjs`.
  456. Mission 008 (old 017) part (**#4 relations**, after #8/#6): project `rel.example` — the gate user opens P (#1)
  457. and C1–C3 (#2–#4), bob X (#5). API: set parent 3 ways (per-project, UUID route + UUID, `rel.example # 1`),
  458. P's children + states, list rows carry the relations, row keys = old + exactly the 5 new, 14 refused
  459. parent writes (401, 403 ×2, itself, unknown, no `#`, loop, same, none to remove, `{}`, unknown field,
  460. non-string, author, 404) write nothing; who: bob (author of the child) sets/removes, a legacy ticket →
  461. 403 for bob, 201 for alice (creator); replace (label "(was …)"), a grandchild loop. Blocked-by: add,
  462. 13 refusals (401, 403, itself, twice, direct + 2-step loop, add+remove, `{}`, empty, unknown, not
  463. blocking, unknown field, 404), remove; non-link events keep the old keys. Markdown: child
  464. "Parent:" + "Blocked by:", parent "Children (0 of 3 confirmed):", blocker "Blocks:", list-line tails.
  465. Browsers: B (bob) on P sees 3 children + "0 of 3"; signed out: relations yes, forms no; A (alice) on C2
  466. "Part of …", "Remove parent" → B drops to 2 live, typed "Set parent" → 3 again, unknown parent →
  467. message; B on X "Blocks", A "Add blocker" → both live, bob's face refused, 3 forged faces refused, the
  468. row's "Remove"; alice confirms C1, C2 (API) → B "2 of 3", C3 (web) → "all children confirmed (3)" green,
  469. P stays open. Screenshots `gate-{phone,desktop}-{parent,blocked}.png` — look at them.
  470. Mission 007 (old 014) parts: **#8** — the gate user opens gamma #3 with a Markdown summary, edits subject
  471. (per-project URL) and summary (`/api/tickets/<uuid>/edit`), history created/edit/edit with the old
  472. values; 9 refused edits (no token 401, bob / alice (creator, not author) 403, `{}`, empty subject,
  473. same values, unknown field, non-string, author → 400) write nothing; 404s; legacy alpha #1: gate /
  474. bob 403, alice (creator) 201. In Chrome: bob's ticket (gamma #4) — "Edit" only for bob (not
  475. alice, not signed out), the form (screenshots `gate-{phone,desktop}-edit.png`,
  476. `gate-desktop-editbutton.png`), Cancel writes nothing, an empty subject is refused, Save → both
  477. browsers show the new subject + rendered summary + "bob edited the ticket" with the previous
  478. values, no reload (`gate-{phone,desktop}-markdown.png`); faces: alice refused, forged session
  479. refused; legacy alpha #1: "Edit" for alice only; logout hides it, a selector login brings it back
  480. without a reload. **#6** — JSON unchanged (non-edit events keep exactly the old keys;
  481. `Accept: application/json` = no Accept); the read view (ticket, uuid form, project list, state
  482. list, 7 Accept variants, errors stay JSON); the parser table (`tests/markdown.hl`); the rendered
  483. summary in Chrome (headings, em/strong, code, lists, code block; ONLY the 3 safe links; no
  484. script/img/handler element; raw HTML incl. `</script><img …>` shown as text; `window.__xss` unset);
  485. a Markdown comment pushed live to both, a Markdown state note. **#11** — every page wait is
  486. `TICKETS_GATE_SLOW`× (default 3) its timeout; the console check runs BEFORE ident is stopped,
  487. both browsers park on `about:blank` first, then "nothing new in the console" after.
  488. Load proof (mission 007 (old 014)): `node .scratch/m014/load.mjs <tickets url> 4 6` (4 headless Chromes ×
  489. 6 tabs looping pages, ports 8700-8719, SIGTERM closes them) while the gate runs.
  490. Ticket #7 part (login via ident, `tests/identkit.mjs`): our own ident from
  491. `../ident.worldapi.org` (or `TICKETS_GATE_IDENT_DIR`), accounts alice / bob / gate, tickets
  492. registered with origin `http://127.0.0.1:8352`, alice's per-app id computed (selector code +
  493. exchange). Server #1 WITHOUT a creator: the machine user "gate" logs in through
  494. `/login/callback` (no / unknown / reused code → 400), the name prompt, the name rules (empty,
  495. 61 chars, asked once), a token over the face, `/you` shows its id, confirm / reject → 403.
  496. Server #2 with `TICKETS_CREATOR_IDENTITY` = alice: the session survives the restart; every API
  497. write with the gate token, `author` in a body → 400, 14 unauthenticated cases → 401 (auth before
  498. the body), reads without token. Browsers: signed out = history + hint, no forms, a face write
  499. refused, screenshots `gate-{phone,desktop}-signedout.png`; A = alice signs in to ident, then the
  500. SELECTOR (no reload, `logged-in`, name prompt `gate-*-name.png`, forms appear,
  501. `gate-*-loggedin.png`); B = bob via the LOGIN BUTTON (ident /signin → /login/callback → name);
  502. writes show alice / bob / gate as authors; bob's confirm / reject refused (web + API 403), alice
  503. confirms; bob's token on /you (shown once, `gate-*-tokens.png`, not after reload) → API write as
  504. bob → revoke → 401; alice cannot revoke bob's token; 8 faces with a forged session (#31) refused;
  505. old events keep "creator" / "worker"; logout resets the selector without a reload; ident stopped
  506. → "ident did not answer" (400, no 500). Ident's log: `.scratch/gate-ident.log`.
  507. Ticket #9: tickets reaches ident's `/api/exchange` through a proxy in the gate that COUNTS the
  508. exchanges. alice gets a 2nd identity "alice two"; on a ticket page: logged in → Log out →
  509. selector → "alice two": no `#loginerror`, exactly ONE exchange (200), no reload, `/you` shows
  510. alice two's per-app id; then Log out → in-app click to the list → selector → "Default": again
  511. one exchange, logged in as alice. Ticket #10: `/login/callback?next=` table (16 cases: paths
  512. kept, `//host`, `https://`, `/\host`, `javascript:`, CR/LF, quotes, `/login/…`, 501 chars → `/`);
  513. in Chrome bob logs out, clicks to a ticket (pushState URL), "Log in with ident" → ident → back
  514. on that ticket, logged in; same from `/state/open`.
  515. Manual repro of #9 with instrumentation (listeners, `change`s, socket frames, exchanges):
  516. `node .scratch/m012/repro.mjs [appDir]` (`SCEN=ticket-nav|list|ticket-direct`, `SECOND=<identity>`;
  517. ident :8363, proxy :8366, tickets :8362, Chrome 8640-8649; output `.scratch/m012/repro-run/out.txt`).
  518. Ticket #38 part (runs first): `tests/oldstore.hl` writes an OLD-format store (5 tickets,
  519. old #1–#5 in `alpha` / `beta.example.org`, a same-ms tie), `tools/migrate-008.hl` migrates a
  520. copy of it TWICE (second run must print `0 new`), the server runs on the migrated tables:
  521. old-number and per-project API (GET + POSTs), `/tickets/<n>` 301 (fetch and in Chrome),
  522. "formerly #n", a real click on a list row, new tickets continue the numbering (alpha #4,
  523. new project gamma #1), pushed rows carry `/projects/…` hrefs (list + inbox in browser B).
  524. Screenshots also `gate-{phone,desktop}-legacy.png`.
  525. It starts its own server, runs the import twice, drives the API, and opens TWO headless
  526. Chromes (debug ports 8620-8629 / 8630-8639, `--disable-gpu`, killed by PID at the end):
  527. filters by real clicks, a comment and state changes in browser A appear live in browser B
  528. (no reload — checked with a window marker), API writes appear live in both, the inbox and
  529. header count follow, the new-ticket form, and the layout at 390px and 1280px (no horizontal
  530. overflow; screenshots `.scratch/gate-{phone,desktop}-{list,ticket,inbox}.png`,
  531. `gate-phone-newticket.png`, `gate-phone-paragraphs.png` — look at them). Also: the strict-API
  532. table (26 refused bodies, nothing written), Vienna time against node's `Intl`
  533. (`bin/hybriel tests/localtime.hl` prints DST-edge samples), and a CRLF paragraph fixture
  534. imported from `.scratch/gate-import` (→ #7). Ticket #15 (author cases replaced by ticket #7's "no author field"), 13 invalid
  535. JSON bodies → 400 at the right character and no source path, valid escapes still accepted,
  536. no name field in either form, a list fixture `.scratch/gate-import-lists` (→ #8) rendered as
  537. separate lines (`gate-phone-lists.png`). Server log: `.scratch/gate-server.log`.
  538. Chrome: `HL_CHROME` (default `/opt/google/chrome/chrome`, google-chrome is not on PATH).
  539. Check for leaked Chromes afterwards: `ps -eo pid,args | grep [h]l-browser-tier` (must be empty).
  540. ### Short URLs on real data (ticket #25)
  541. ```bash
  542. # a copy of the live tables (never run on the original), then a server on it (port of your range, watcher off)
  543. tar -C /CONTAINERS/projects/tickets.worldapi.org -cf - storage/mpackdb | ssh loreana tar -C /media/STORAGE/projects/WorldAPI/tickets.worldapi.org/.scratch/w083/realdata -xf -
  544. mkdir -p .scratch/w083/run && cp -a .scratch/w083/realdata/storage .scratch/w083/run/ # a fresh copy per run
  545. TICKETS_PORT=8763 TICKETS_STORAGE=$PWD/.scratch/w083/run/storage/mpackdb TICKETS_SESSIONS=$PWD/.scratch/w083/run/sess TICKETS_WATCH=0 ./bin/hybriel project.hl &
  546. node tests/shorturls-realdata.mjs http://127.0.0.1:8763 20 # every project + 20 tickets: short URL 200 (the page), every old URL 301 → it → 200; collisions with reserved slugs
  547. ```
  548. Mission 011: 187 passed, 0 failed (11 projects, 20 tickets). The API of the old and new code on the same copy
  549. (`.scratch/w083/apicompare.py <old url> <new url>`): 1,348 answers (JSON + Markdown), 17 identical, 1,331 differ only by
  550. the page links (`href` values, the Markdown URL lines), 0 different.
  551. ### Project ids on real data (mission 012)
  552. ```bash
  553. # a copy of the live tables (as above, into .scratch/<you>/realdata), the OLD tree (as in "Same output" step 2), each on a fresh copy:
  554. TICKETS_PORT=8763 TICKETS_STORAGE=<old copy>/mpackdb TICKETS_SESSIONS=<dir> TICKETS_WATCH=0 ./bin/hybriel project.hl & # in the old tree
  555. TICKETS_PORT=8764 TICKETS_STORAGE=<new copy>/mpackdb TICKETS_SESSIONS=<dir> TICKETS_WATCH=0 ./bin/hybriel project.hl & # here
  556. python3 tests/projectids-realdata.py http://127.0.0.1:8763 http://127.0.0.1:8764 # must end "0 FAILED"; then kill both by PID
  557. ```
  558. Old vs new: every API read (JSON + Markdown) byte for byte; on new: every `/api/projects/<slug>/…` read again with the
  559. id = the same bytes; unknown id and `/api/tickets/<project id>` → 404. Mission 012 (Byrodin copy 2026-10-04 ~05:00):
  560. 11 projects, 309 tickets, 1,484 old-vs-new answers + 772 slug-vs-id answers, 0 FAILED. The gate's part: "ids (#25)" (22
  561. checks: reads by id = slug form byte for byte, every write route by id, unknown id 404, id after a slug change); on the
  562. old code exactly those fail (control run: 286 passed, 13 failed, then it stops).
  563. ### Same output (a cleanup must not change behaviour — mission 010)
  564. The gate proves the features; this proves a refactor answers byte for byte what the old code answered, on REAL data.
  565. ```bash
  566. # 1. a copy of the live tables (Byrodin → Loreana; opening a table rewrites its index files: never run on the original)
  567. tar -C /CONTAINERS/projects/tickets.worldapi.org -cf - storage/mpackdb | ssh loreana tar -C /media/STORAGE/projects/WorldAPI/tickets.worldapi.org/.scratch/realdata -xf -
  568. # 2. the old code as a tree of its own (bin + plugins included), e.g. before the change:
  569. rsync -a --exclude /.scratch --exclude /storage --exclude /.sessions --exclude '/.env*' --exclude /.git --exclude '/server.*' --exclude /import ./ .scratch/old/
  570. # 3. both trees on a fresh copy each: ~2,200 answers — every page signed in (as az5b2, users @id 0mufikk6hj1u, through a
  571. # session file) AND signed out, every API read as JSON and Markdown, refusals, then ~70 writes (API + faces) and the reads after
  572. node tests/realdata-baseline.mjs .scratch/old 8750 .scratch/base-old
  573. node tests/realdata-baseline.mjs . 8750 .scratch/base-new
  574. python3 tests/realdata-compare.py .scratch/base-old .scratch/base-new # reads: must say 0 DIFFERENT
  575. python3 tests/realdata-compare-writes.py .scratch/base-old .scratch/base-new # writes: must say 0 DIFFERENT
  576. python3 tests/letcount.py . # code order: 1 root .hl, never-reassigned let 0
  577. ```
  578. Masked (not app output): the session seed's `at` time, the View's source positions (`site`, `Child@line:col` mount keys)
  579. and the `?v=` content hashes; in writes also the new ids, today's times and the token. Two runs of the SAME code compare
  580. clean with these masks (checked). Mission 010 numbers: 2,172 reads (1,460 byte-identical, 712 identical after masking),
  581. 72 write answers identical after masking.
  582. ## Pages
  583. | Route | Component | |
  584. |---|---|---|
  585. | `/` | `components/ticket_list.hl` | all tickets, newest update first; project + state filter chips; "New ticket" form |
  586. | `/project/:projectName`, `/state/:stateSlug`, `/project/:p/state/:s` | same | filtered (state slug: `in-progress`, `awaiting-creator`, `on-hold`, …) |
  587. | `/:projectSlug/:ticketNumber` (last, ticket #25) | `components/ticket.hl` | ticket, history, comment form, state change (select + optional note), "Edit" for the author (#8); texts rendered as Markdown (#6) |
  588. | `/:projectName` (last, ticket #25) | `components/ticket_list.hl` | the project's page (= `/project/:projectName`) |
  589. | `/projects/:slug`, `/projects/:slug/:number`, `/projects/:slug/tickets/:number` | function routes | 301 → `/<slug>` / `/<slug>/<n>` (current slug), else 404 (ticket #25) |
  590. | `/tickets/:ref` | function route | 301 → `/<p>/<n>` (`:ref` = old global number or UUID), else 404 |
  591. | `/inbox` | `components/inbox.hl` | every ticket in `awaiting creator`, across projects (the creator's comment on one sets it to `answered` and it leaves the inbox) |
  592. | `/you` | `components/you.hl` | the logged-in user: display name, own per-app identity id, creator or not; API tokens (create / list / revoke) |
  593. | `/login/callback` | function route | the login button's return: `?ident_code=` → exchange → session → 302 to `?next=` (same-origin path only, else `/`; 400 page on failure) |
  594. | `/login.js` | file | the selector bridge (`ident-login` → the shell's hidden `#identcode`, once per code) + `next=` on the login button |
  595. Shell: `components/main.hl` (header, Inbox link with live count, top right the login: selector +
  596. button, or name link to `/you` + Log out; the display-name prompt). Each component carries its own CSS in a nested `Style {}` block in its own file; `components/styles.hl` keeps only the theme inherit, the accent and a few site-wide rules
  597. (tokens imported from `shared/tokens.hl` — section "Design tokens"; accent `colorAccent = var(purple)`
  598. = #c586c0, `--color-danger: var(--red)` = #f44747; domain tags `<ticket-board>`, `<ticket-state>`, `<ticket-view>`,
  599. `<event-head>`, …; mobile first, one `min-width: 45rem` block).
  600. Live push (audience in `project.hl`): `ticketCreated(row, inboxCount)` and
  601. `ticketEvent(ticketId (UUID), event, row, inboxCount)` (public), raised by the web faces AND the
  602. API; `commentChanged(ticketId, event)` (public, mission 016: a comment edited / deleted / (un)liked); `signedIn(tag, {name, named, creator})` / `signedOut(tag)` only to the tabs of the session
  603. whose login carries that random tag (`session.data.tag`).
  604. ## API (JSON)
  605. **Move a ticket:** `POST /api/projects/:slug/tickets/:number/move {"project":"<target slug or id>"}` with a user bearer token returns `200 {ticket,event,related}`. The caller must be admin in **both** projects; otherwise **403** with no changes. Unknown target also returns 403. Missing authentication is 401; malformed body or the same project is 400. The old API ticket URL (JSON or Markdown) and its subpaths return 301 with Location pointing to the current URL and the same subpath, also after repeated moves. UUID API references remain stable. Migrated old global-number API references redirect after a move.
  606. Moves add `kind:"move"` history/stream events, preserving the existing event payload fields and resume numbering. One event in the target says `moved from <source>#<n>`; one in the source says `moved to <target>#<n>`. The ticket history keeps its target event, while each project's move journal remains visible on its project page. `GET /api/projects/:slug/tickets` adds `moves` (records with id, text, href, when); its Markdown view includes the same project journal. Existing ticket and event shapes are unchanged for other kinds. Consumers should accept additive event kinds.
  607. `:ref` = the OLD global number of a migrated ticket (`38`) or the ticket's UUID (`id`).
  608. `:slug` = the project's slug (also an old one) or its id (12 characters, mission 012 — every `/api/projects/:slug/…` route),
  609. `:number` = per-project number. Both forms answer the same shapes.
  610. | Method + path | Body | Answer |
  611. |---|---|---|
  612. | `GET /api/tickets[?project=&state=]` | — | `{ tickets: [row] }` (state as `awaiting creator` or slug) |
  613. | `POST /api/tickets` | `{ project, subject, summary?, source? }` | 201 `{ ticket, existed:false }`; known `source` → 200 `{ ticket, existed:true }` |
  614. | `GET /api/tickets/:ref` | — | `{ ticket, events: [event] }` (oldest first); 404 |
  615. | `POST /api/tickets/:ref/comments` | `{ text }` | 201 `{ ticket, event }` |
  616. | `POST /api/tickets/:ref/comments/:comment/edit` (and `…/delete`, `…/like`; also under `/api/projects/:slug/tickets/:number/`) | `{ text }` (edit); empty or `{}` | 200 `{ ticket, event, liked? }`; 403 not the author / no member — section "Comments" (mission 016) |
  617. | `POST /api/tickets/:ref/state` | `{ state, text? }` | 201 `{ ticket, event }`; 400 unknown/same state; 403 confirmed/rejected by a non-creator |
  618. | `GET /api/projects/:slug/tickets[?state=]` | — | `{ tickets }`; 404 unknown project |
  619. | `POST /api/projects/:slug/tickets` | `{ subject, summary?, source? }` | as `POST /api/tickets` |
  620. | `GET /api/projects/:slug/tickets/:number` | — | `{ ticket, events }`; 404 |
  621. | `POST /api/projects/:slug/tickets/:number/comments` | `{ text }` | 201 `{ ticket, event }` |
  622. | `POST /api/projects/:slug/tickets/:number/state` | `{ state, text? }` | 201 `{ ticket, event }`; 403 as above |
  623. | `POST /api/tickets/:ref/edit`, `POST /api/projects/:slug/tickets/:number/edit` | `{ subject?, summary? }` (≥ 1) | 201 `{ ticket, event (kind edit) }`; 403 not the author; 400 empty subject / nothing changed |
  624. | `POST …/parent` (both forms) | `{ parent }` — `<project>#<n>` or UUID; `""` removes it | 201 `{ ticket, event (kind link) }`; 403 neither author nor creator; 400 `field:"parent"` (unknown, itself, loop, same, none to remove) |
  625. | `POST …/blocked-by` (both forms) | `{ add }` or `{ remove }` (exactly one) | 201 `{ ticket, event (kind link) }`; 403 as above; 400 `field:"add"`/`"remove"` (unknown, itself, loop, twice, not blocking) |
  626. Every ticket GET answers `Accept: text/markdown` with a Markdown document (section "Markdown, editing").
  627. **Every POST needs `Authorization: Bearer <token>`** (ticket #7; a token from `/you`): missing,
  628. malformed, unknown or revoked → **401** `{ error }` + `WWW-Authenticate: Bearer`, checked
  629. before the body. The author is the token's user. GETs need nothing.
  630. | `GET /api/projects` | — | `{ projects, states }` (projects in creation order) |
  631. | `GET /api/events[?project=&assignee=&notMine=&after=]` | — (token required) | `text/event-stream`, held open — section "Event stream for programs (ticket #26)" |
  632. Ticket row: `id` (UUID), `project`, `number`, `ref` (`#5`), `href` (`/<p>/<n>`, ticket #25),
  633. `apiHref`, `oldNumber` (only if migrated) + `oldRef`/`hasOld`, `subject`, `summary`,
  634. `state`, `stateSlug`, `source`, `created`/`updated` (+`Ms`), `events`, `projectHref`.
  635. Event row: `id` (UUID), `ticket` (UUID), `project`, `number`, `seq`, `kind`, `author`,
  636. `text`, `from`, `to`, `when`, `createdMs`, … (a changed comment also `edited`/`editedWhen`/`earlier`, `deleted`/`deletedWhen`, `likes` —
  637. section "Comments")
  638. **Since #38 `ticket.id` is a UUID, not a number** — scripts that did `/api/tickets/${ticket.id}`
  639. keep working (UUIDs are accepted); for display use `project` + `ref`.
  640. **Strict** (ticket #10, `bodyError` in `lib/api-helpers.hl`): a POST body must be a JSON object; an unknown
  641. field, a missing or empty (after trim) required field, or a non-string value (null included)
  642. → **400 `{ error, field }`** naming the field, and nothing is written. Semantic refusals
  643. (unknown/same state, bad project name) also carry `field`. `author` is gone (ticket #7): a body
  644. that has it → 400 `field:"author"` ("no field 'author' any more: the author is the user of your
  645. API token"). Invalid JSON → **400 `{ error: "invalid JSON at
  646. character N" }`** (no `field`, no source path): `lib/jsoncheck.hl` checks the syntax BEFORE
  647. `JSON.parse` — a WORKAROUND for hybriel #12 (no soft parse); remove it (and `readBody`'s call
  648. in `lib/api-helpers.hl`) once #12 is fixed. A LONE `\uD800`–`\uDFFF` escape is refused
  649. too, because hl's `JSON.parse` aborts on it; a valid pair (`\ud83d\ude00`, Python's default
  650. `ensure_ascii=True`) is accepted since hybriel#15 (antcolony mission 036). Other errors: `{ error }` with 404/405.
  651. **Times**: `created` / `updated` / `when` are Europe/Vienna wall time `YYYY-MM-DD HH:MM`
  652. (`lib/util.hl` `localStamp`: EU DST rule, correct from 1996 on — hl:time has no time zones);
  653. `updatedMs` / `createdMs` and the stored values are epoch ms (UTC). Example:
  654. ```bash
  655. curl -s -XPOST -H "Authorization: Bearer $TICKETS_TOKEN" -d '{"state":"awaiting creator","text":"done"}' http://127.0.0.1:8350/api/projects/tickets.worldapi.org/tickets/5/state
  656. curl -s http://127.0.0.1:8350/api/tickets/38 | jq '.ticket | {project, number, href, oldNumber}' # old number still works
  657. ```
  658. Query the store directly: `curl -s http://127.0.0.1:8350/api/tickets | jq` (the mpackdb files
  659. are binary; the API is the query tool).
  660. ## Event stream for programs (ticket #26)
  661. A program subscribes ONCE and gets every change live: new ticket, comment, state change, edit, assign, relation change.
  662. Server-Sent Events over the app's own hl:http1 server — plain `curl -N`, Python, Hybriel (`hl:fetch` with `stream = true`)
  663. all read it. Code: `lib/stream.hl` (topic), `lib/api.hl getEvents` (thin route), the transport handed in by `project.hl`.
  664. ```bash
  665. curl -N -H "Authorization: Bearer $TICKETS_TOKEN" 'https://tickets.worldapi.org/api/events?project=routger&notMine=1'
  666. # resume after a drop (EventSource sends the header itself):
  667. curl -N -H "Authorization: Bearer $TICKETS_TOKEN" -H 'Last-Event-ID: 4711' 'https://tickets.worldapi.org/api/events?project=routger'
  668. ```
  669. * **Auth**: `Authorization: Bearer <token>` — a user's token (`tkt_`, /you) or a project key (`tktc_`, ticket #21). None /
  670. bad / revoked → **401** (+ `WWW-Authenticate: Bearer`). Reading is public (CONCEPT point 1), so a user's token sees every
  671. project; a project key ONLY its own project (asking for another → **403** `field:"project"`). `lib/stream.hl
  672. subscriptionOf` is the one place to narrow this once projects can be private.
  673. * **Filters** (query, all optional, combined with AND): `project=<slug or id>[,<slug or id>…]`; `assignee=<display name |
  674. users id | me>` (the ticket's assignee after the event; an `assign` event also reaches the one who HAD it); `notMine=1`
  675. (skip what the token's user wrote — user tokens only, a key → 400). Unknown project / person, bad id → **400** `{error, field}`.
  676. * **Frames**: `data: <one JSON line>` then `id: <n>`, a blank line. JSON:
  677. `{id, at (ISO UTC), project (slug), ticket (UUID), ref ("#5"), number, kind, actor (display name), state (the ticket's state
  678. AFTER the event), assignee (name or ""), text, href (absolute page URL)}`; `kind` = created | comment | state | edit |
  679. assign | link; `text` = first 300 characters of: the comment / the state note / the summary (created, edit) / the label
  680. (assign, link: "marked it blocked by beta #1").
  681. * **Ids and resume**: `id` = the `*n` counter of the `stream` table (1, 2, 3, … — every event since ticket #26 went live has
  682. one; older history has none, read it with the ticket GETs). `Last-Event-ID: <n>` (wins) or `?after=<n>` first sends every
  683. event after n that passes the filters, oldest first, then the live ones — exactly once (one event loop: no write slips
  684. between the replay and the registration). `?after=0` = everything numbered.
  685. * **Keep-alive**: hl:http1 writes `: connected` at once and a `:` comment every 5 s (SSE comments, ignored by clients); a
  686. closed peer is reaped at once (EPOLLRDHUP) and drops out of the subscriber list at the next event.
  687. * **Where it hooks in**: `lib/tickets.hl` calls `recordEvent(eventId, ticketAfterTheWrite)` after every write (create,
  688. comment, state + its auto-assign, assign, edit, parent / blocked-by) — so the web faces and the API both feed it.
  689. Not: a comment's edit, deletion or like (mission 016, section "Comments") — no history events, nothing sent.
  690. * **Transport**: hl:http1's native SSE, imported by name since hybriel#144 — `import { sseStart, sseSend, sseAlive } from
  691. 'hl:http1'` in `lib/stream.hl` (`sseSend` / `sseAlive` answer true / false). The pages' browser build binds them to a
  692. refusal that throws only when called. (Until w9: project.hl's root handed three `__native` calls in via `useTransport`.)
  693. Plain HTTP only (on hl:http1's own TLS `sseStart` answers null — fine behind nginx).
  694. * **nginx (Byrodin vhost `tickets.conf`)**: the existing `location /` already works — `proxy_http_version 1.1` is there, the
  695. app sends `X-Accel-Buffering: no` (nginx then does not buffer this response) and the 5 s comments stay far below the
  696. default `proxy_read_timeout` 60 s. Tested through nginx 1.27 with that block (`EVENTS_VIA`, below). Optional hardening,
  697. not required: `location = /api/events { proxy_pass http://127.0.0.1:45003; proxy_http_version 1.1; proxy_set_header
  698. Connection ""; proxy_set_header Host $host; proxy_buffering off; proxy_read_timeout 1h; }` (+ the X-Forwarded-* lines).
  699. * **A stream opened right after a start gets live events** (mission 014, Apollo's report of 2026-10-19 — not a bug: his subscriber
  700. holds events of other actors for `BATCH` = 120 s, its own journal shows them delivered live at 00:58:18; reports/014-events-after-start.md).
  701. The gate checks it: a stream retried from process start (the server's first request), one right after, one later — a comment
  702. must reach all three within 2 s.
  703. * **Test**: `node tests/events.mjs` (52 checks, ~2.5 min: server :8790, Chrome 8793-8799; `EVENTS_IDLE_SECONDS` shortens the
  704. 2-minute idle check; `EVENTS_VIA=http://127.0.0.1:<port>` sends the subscribers through a proxy). Its fixture:
  705. `tests/events-seed.hl`; a Hybriel subscriber to copy: `tests/events-client.hl`.
  706. ## Connecting an app to a project (ticket #21)
  707. Another app (first: gitoria) is connected to ONE project; it then gets a key that reaches that project only. Code: `lib/connections.hl`,
  708. `components/connect.hl`, the connections line on the project page (`components/ticket_list.hl`), routes in `project.hl`. Data:
  709. `storage/mpackdb/connections.db` (created empty at the first start; no migration).
  710. 1. The app sends the browser to `GET /connect?app=<name>&label=<owner/repo>&return=<url>&state=<opaque>` (`label` and `state` optional; the state
  711. comes back unchanged). The return URL must be https on `worldapi.org` or a subdomain — or start with an origin listed in the env
  712. `TICKETS_CONNECT_ORIGINS` (comma separated, for dev copies). Else 400. A valid request is stored (1 hour) and the browser goes to `/connect/<nonce>`.
  713. 2. On that page the person, logged in through ident with a display name, picks a project they are ADMIN of or makes a new one (they become its
  714. admin) and confirms. The page says which app and host ask, then links back: `<return>?code=<one-time code>&state=<state>` (code valid 5 minutes).
  715. A second connection of the same app + label to the same project replaces the first (its key dies).
  716. 3. The app's SERVER swaps the code: `POST /api/connect/exchange {"code": "…"}` → `200 {key, project (slug), title, api}`. The key is `tktc_` + 48 hex,
  717. shown once, only its sha256 is stored. Wrong / used / expired code → 400.
  718. 4. The key: `Authorization: Bearer tktc_…` plus, on every write, `X-Tickets-Identity: <ident public id of the person>`. It works only on
  719. `POST /api/projects/<slug>/tickets` and `POST /api/tickets` (create), `…/comments` and `…/state` of tickets of ITS project — the same
  720. endpoints a user token uses, so "mentioned in PR" / "fixed by commit" is a comment or a state change with a note. The named person must have
  721. logged in to tickets once and chosen a display name; **the project's roles apply to them** (use: comment, open ↔ review; edit / admin: more).
  722. The author of what is written is that person. A key on any other endpoint (settings, members, invites, edit, assign, relations, inbox,
  723. new project, disconnect) → 401; another project → 403; no / unknown identity → 403 naming the header. Reads need nothing.
  724. 5. The project page shows "Connected to <app>: <label>" to everybody; an admin's **Disconnect** deletes the connection — the key is dead at once.
  725. `GET /api/projects/<slug>/connections` lists them; `POST /api/projects/<slug>/connections/remove {"id"}` (user token, admin) disconnects.
  726. Short copy for app workers: `docs/connect-apps.md` (the architect copies it next to antcolony-docs).
  727. Gate: `node tests/connect.mjs` (ports 8700 / 8701 + Chrome 8703–8709; an ident stub, a real headless Chrome) → 60 checks.
  728. Other ports: `TICKETS_CONNECT_PORT`, `TICKETS_CONNECT_IDENT_PORT`, `TICKETS_CONNECT_APP_PORT` (the app URL, nothing listens),
  729. `TICKETS_CONNECT_CHROME` (`"8737-8739"`).
  730. ## Design tokens (shared, ticket antcolony#3 — antcolony mission 021)
  731. * **`shared/tokens.hl`** declares the WorldAPI palette + semantic tokens as hl:web css variables,
  732. hand-written: `static dark = var('rgb(25, 30, 35)')`, `static colorText = var(light)`, …
  733. (`import { var } from 'hl:web/css'`). It is a copy of the one source
  734. `loreana:/media/STORAGE/projects/WorldAPI/worldapi-tokens/tokens.hl` (vendored like `plugins/`, no generator):
  735. edit it THERE, then `cp /media/STORAGE/projects/WorldAPI/worldapi-tokens/tokens.hl shared/tokens.hl` in every
  736. app and restart it. Check: `cmp /media/STORAGE/projects/WorldAPI/worldapi-tokens/tokens.hl shared/tokens.hl`.
  737. (2026-09-26: the apps' copy = gitoria's/ident's; it differs from the source only in 3 COMMENT lines that
  738. still say webex — update the source's comments, then the check is byte-exact again.)
  739. * `components/styles.hl` (the components' Style blocks write the same tokens as `var(--color-…)` strings) IMPORTS the tokens it uses (`import { colorText, colorBorder, … } from '../shared/tokens.hl'`)
  740. and writes them as members: `color = colorText`, `border = '1px solid ' + colorBorder`. It sets only
  741. its accent: `colorAccent = var(purple)` (#c586c0). A token it uses must be in the import list,
  742. a new token must be added to tokens.hl (static) first.
  743. * hl:web names each token after its member (`colorTextMuted` → `--color-text-muted`), writes EVERY
  744. token of tokens.hl into the one `:root` (declaration order), then the app's `colorAccent` (a second
  745. `--color-accent`, later wins), and writes each use as `var(--…)`. Components/JS may still use
  746. `var(--color-…)` strings — the custom property names are the same.
  747. * hl:web does this itself since hybriel#39 (the webex LOCAL PATCH of antcolony mission 021 is gone, antcolony mission 036).
  748. * A change of tokens.hl or of components/styles.hl root members needs a RESTART: the dev watcher re-analyses
  749. but the served sheet keeps the old values (measured, antcolony mission 021).
  750. * Deploy: `shared/` is part of the app folder; `deploy.sh`'s rsync sends it (proved in antcolony mission 021:
  751. deploy.sh excludes + debian:12-slim container → byte-identical `/__hl/app.css`).
  752. ## Vendored Hybriel
  753. Mission 035: Hybriel set day72, source `00c9dbb84d7f90a2f1cd124d7e512eda6c066747`.
  754. SHA256SUMS passed. Untracked bin/ contains set bin/ plus set lib/.
  755. Binary SHA-256: `69f9421ab58e4b7811bb1b0481947a918021b1142d96375d383427937ffc50fe`.
  756. All 11 vendored plugin directories are byte-identical to the source commit.
  757. Mission 029: Hybriel set day38b, source `1e554d758497e16ee535ff71ee1b9c01051cef67` (day38 without m542, branch day38b).
  758. The set passed SHA256SUMS. `bin/` contains set `bin/` plus set `lib/` (untracked);
  759. `bin/hybriel` SHA-256 is `5ff2a46db81ef88fd7a72a3c32c3d67ca1faff7bfed60587341d2307b10b6e96`.
  760. All 11 vendored plugin directories (`core`, `crypto`, `data`, `fetch`, `fs`, `http`, `http1`, `mpackdb`, `proc`, `time`, `web`)
  761. are byte-identical to that source commit, including the `.so` files and their `.inputs.json` (the set's `.so` files equal the
  762. commit's). Plugins the app does not vendor (gui, http2, http3, ipc, mariadb, math, smtp) stay out.
  763. Mission 025: Hybriel set day35, source `cb9e480dafb867b9345772c96ae9fedb476a1b03`.
  764. The set passed SHA256SUMS. `bin/` contains set `bin/` plus set `lib/` (untracked);
  765. `bin/hybriel` SHA-256 is `4bb25cfa94ddcbaffbb7ae729a7e696182c13f484d269d1023ff87d80e9490a4`.
  766. `plugins/core` and `plugins/web`, including README, come from that source commit.
  767. Other plugin sources stay unchanged.
  768. **hybriel master a832f73b** (worker w13, mission 013, 2026-10-19, branch `w13-md-tables`; = 9f912f3b + mission 332: incremental
  769. compile (BuildCache), the one-file compiler (`--carry-lib`: libhlrt.a, hlc.o, hlrt/ ride inside the binary), `HL_CACHE_DIR`,
  770. #151 (the run cache counts only the listing entries a build looked for — a new `.sessions/`, log or unrelated file in the app
  771. root no longer forces a cold compile)). Built read-only: `git -C /media/STORAGE/projects/hybriel archive a832f73b | tar -x -C
  772. ~/scratch-w13/src`, `HL_NO_PLUGINS=1 bash native/build.sh` (54 s). Vendor as before (the binary would also work alone; the
  773. files beside it win): `bin/hybriel` sha256 `e1b53f7ce687f5afbe3db34bcda69958f56e730571e4841923c9c8eb3d272db9`, `bin/libhlrt.a`
  774. `975f2b61e573d127993f5a275b238642e82647479c2d4650d67abfe7724fc0da` and `bin/hlc.o`
  775. `ba72ab5c78d4590f631db3bcf8d11e6f62065acd97a252e69ce160b7541896b9` (both unchanged since 9f912f3b), `bin/hlrt/`;
  776. `plugins/` byte-identical to a832f73b's (unchanged). Cache: `HL_CACHE_DIR` (default `~/.hybriel/cache`: `run/`, `incr/`,
  777. `lib/`); docker-compose.yml sets it to `/root/.hybriel/cache` = inside the `hybriel-cache` volume. Old vendor (9f912f3b, and the
  778. pre-w9 06617221 binary this worktree had) in `.scratch/pre-w13/`.
  779. **hybriel master 9f912f3b** (worker w9 2nd pass, 2026-10-18, branch `w9-hybriel`; = edfd400a + #146 (a bare `emit` in a lib
  780. file's static is raised by the module) + #147 (sibling blocks may reuse a `let` name)). Since mission 326 the interpreter is
  781. gone: `bin/hybriel project.hl` COMPILES the app to machine code and runs that — **cold ~23 s on Loreana (hybriel#148), then
  782. ~1.5 s from the build cache** `$HOME/.hybriel/cache/run` (`HL_NO_BUILD_CACHE=1` turns it off; the gates were run that way once,
  783. every start cold). Built read-only: `git -C /media/STORAGE/projects/hybriel archive 9f912f3b | tar -x -C ~/scratch-w9b/src`,
  784. then `HL_NO_PLUGINS=1 bash native/build.sh` there (the plugins' committed `.so` files; seed → stage 1 → stage 2, ~1 min). The
  785. vendor is FOUR things in `bin/` (from `native/zig-out/`) + plugins:
  786. `bin/hybriel` sha256 `7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a` (byte-identical to the hybriel
  787. checkout's own `native/zig-out/bin/hybriel` at 9f912f3b), `bin/libhlrt.a` (`975f2b61e573d127993f5a275b238642e82647479c2d4650d67abfe7724fc0da`),
  788. `bin/hlc.o` (`ba72ab5c78d4590f631db3bcf8d11e6f62065acd97a252e69ce160b7541896b9`), `bin/hlrt/` (= `zig-out/lib/hlrt/`), and
  789. `plugins/{core,crypto,data,fetch,fs,http,http1,mpackdb,proc,time,web}` (master's, no local patch — webex is not vendored, so
  790. the hybriel#34 patch does not apply; unchanged since edfd400a). The binary looks for `../lib/libhlrt.a` first (the app's `lib/`
  791. has none — keep it so), then `libhlrt.a` beside itself; `hlrt/` and `hlc.o` are read beside libhlrt.a.
  792. Re-vendor = copy those four + the plugins (`rsync -a --delete --exclude=.zig-cache`), run ALL gates (README "Test").
  793. The 12 `emit client …` live pushes in lib/api.hl are real (they compile since #146; there was never a workaround in the
  794. code). No `x = emit …` in a static (hybriel#149) in this app. Old vendor (edfd400a) in `.scratch/pre-w9b/`, the one before
  795. (06617221) in `.scratch/pre-w9/` (w9 worktree).
  796. **The build cache lists the app's ROOT directory**: a new entry there (e.g. `.sessions/` made by the first start, a log file)
  797. makes the next start compile again (seen in the container test: first start cold, first restart cold again, then warm).
  798. Before: **hybriel master edfd400a** (worker w9, 2026-10-18, commit 43be657; never runnable — `emit client` in a static refused,
  799. #146; bin/hybriel sha256 `ed337ce191029c0c9446887793fd6676a3001e2f1b80ee61376ec93d5f510484`). Kept from it: lib/stream.hl's SSE
  800. from 'hl:http1' (#144) and `tools/import.hl`'s plain declarations (a body with a closure could not `let` a name twice, #147).
  801. Before: **hybriel master 06617221** (antcolony mission 074, 2026-10-03; adds the plugin allocators 3a781359 + 413f60e4 (#126:
  802. every plugin allocates with malloc via plugin_api.zig), mpackdb 2cb7ae5e (frees per-operation buffers), http1 773de63e (request
  803. owns its parse), f0ac2d2d (event order; plugin ABI field — bin and .so must match); no lambda semantics change). sha256
  804. `21059cc741459ded8a004d44ed17c071aa296609be9fd0359202383210d77bdb`, built the same way from `git archive 06617221`
  805. (`~/scratch-074/src`, removed). Old vendor (190aa11d) in `.scratch/pre-074/`. Gates on 8760–8769: `TICKETS_GATE_PORT=8760
  806. TICKETS_GATE_IDENT_PORT=8761 TICKETS_GATE_EXCHANGE_PORT=8762 TICKETS_GATE_CHROME_A=8763-8764 TICKETS_GATE_CHROME_B=8767-8768
  807. TICKETS_GATE_CHROME_C=8769-8769 node tests/browser.mjs` → 249/0; connect.mjs as a temp copy (app URL :8762, Chrome 8763–8769,
  808. TICKETS_CONNECT_PORT=8760 TICKETS_CONNECT_IDENT_PORT=8761) → 60/0. Memory: `LONG=1 node .scratch/w074/mem.mjs <tag> <app tree>
  809. 8760` (live-storage copy in `.scratch/w074/realdata/storage`, deleted after the run; prints RSS + swap): new 315 → 335 (200) →
  810. 312 (1200) → 315 MiB (5700 pairs) — **flat**; old 190aa11d 319 → 358 → 451 → 743 MiB.
  811. Before: **hybriel master 190aa11d** (antcolony mission 072, 2026-10-02; adds fc838894 GC correctness (string index / plugin error message
  812. read freed memory), 038d84b3 (#126 returned closure scopes collected), #127 (d98926c6, 04df4428); no lambda semantics change since
  813. 7eea0d32). `bin/hybriel` sha256 `860f5e61878be75fe84a569eee03c95a25f2757940903b2ed0afee0871a23626`, built read-only from
  814. `git archive 190aa11d` (`~/scratch-072/src`, removed) with `/media/STORAGE/projects/hybriel/native/zig-toolchain/zig build
  815. -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.39` in `native/`; old copy (7eea0d32) in `.scratch/pre-072/`.
  816. Memory proof: `node .scratch/w072/mem.mjs <tag> <app tree> <port>` (needs a live-storage copy in `.scratch/w072/realdata/storage`,
  817. deleted after each run — re-tar it; env LONG=1 adds 3×1500): new 315 → 355 (200) → 418 (1200) → 706 MiB (5700), old 697 → 1365 → 1719 MiB.
  818. Before: **hybriel master 7eea0d32** (antcolony mission 069, 2026-10-02; ≥ f685f240 = #126 collector also by bytes, includes #48 #112 #117 #119 #120).
  819. `bin/hybriel` sha256 `f0d3019f46f83cbf119d0a426fab18394bfc6c02c58abaa725983fcc4bc734a0`, built read-only
  820. (`git -C /media/STORAGE/projects/hybriel archive master | tar -x -C ~/scratch-…/src`, then
  821. `cd native && /media/STORAGE/projects/termuplex/.tools/zig/zig build -Dtarget=x86_64-linux-gnu.2.39 -Doptimize=ReleaseFast`).
  822. `plugins/{core,crypto,data,fetch,fs,http,http1,mpackdb,proc,time,web}` = master's — **no local patch**.
  823. Re-vendor = copy the binary + these plugins, run the gate. The previous copy (73267707, sha 9707e0cc…) is in `.scratch/pre-069/`
  824. (the one before, 837fe120, in `.scratch/pre-048/`).
  825. **Lambda parameters COPY their argument since hybriel #48** (like methods); `&p` makes it a reference. A lambda that fills a list/record
  826. it was given needs `&`: `migrate.hl` `migrateProjects/Tickets/Events/Members = (&log, …)` (without it the gate fails at
  827. "migration: at the first start the log says what was migrated"). Audit script `.scratch/w069/audit.py <files>` (param mutations +
  828. `for (x of param)` aliases). `store.hl` `sortByUpdated(rows)` sorts its copy and RETURNS it — callers use the return, fine.
  829. antcolony Mission 048: `migrate.hl`'s `compactNow()` block (hybriel #110) removed (proof logs `.scratch/w048/`). Lesson (hybriel #122):
  830. a post-face session sync must keep the route params — repro `.scratch/w048/repro/` (`node repro.mjs <bin>` must keep "you may edit").
  831. The old webex generation (e565176b + LOCAL
  832. PATCHes #34 seed escape, #39 tokens) is backed up in `.scratch/pre-036/` (bin, plugins, sources, tests).
  833. * Framework pages use content-hashed URLs `/__hl/{hl-runtime.js,web/client.js,app.css}?v=…` (hashed =
  834. `immutable`, bare = `no-cache`). Check: `~/scratch-036/hashcheck.sh tickets.worldapi.org TICKETS /` (own server :8730).
  835. * Dropped with antcolony mission 036: plugins/webex + both LOCAL PATCHes, the NativeWebSocketServer listener
  836. (HL_HOST, #24), `sessions.resolve(cookie)` in /login/callback (→ `req.session`, #11), `realSession()`
  837. (→ `session == null`; hl:web refuses a forged trailing session itself, #16 — the gate's 12 forged checks
  838. accept that ack `ok:false` "the `session` parameter is filled by the server"), the hand URL encoder
  839. (→ `encodeURIComponent`, #14), import.hl's charCodeAt string order (→ `a > b`, #2), jsoncheck's refusal
  840. of VALID surrogate pairs (#15; lone surrogates still abort JSON.parse → still 400).
  841. * Kept on purpose: `jsoncheck.hl` (JSON.parse still aborts on bad input), `localtime.hl` (no time zones),
  842. hand insertion sorts (no list `sort()`), `login.js` once-per-document guard (harmless).
  843. The binary finds `plugins/` beside the app (it walks up from the script's directory).
  844. `tests/cdp.mjs` + `tests/ports.mjs` are copies of the hybriel repo's `tests/browser/`.
  845. ## Files
  846. Code order (antcolony `docs/code-order.md`, mission 010): `project.hl` is the map, no other `.hl` in the root, one `lib/`
  847. file per topic holding its central logic and every write to its tables; the API routes and the faces are thin wrappers.
  848. Imports only go downwards (Hybriel refuses an import cycle): util ← users ← projects ← tickets-helpers ← comments ← events ← stream ← tickets
  849. ← invites / connections ← api-helpers ← api ← project.hl.
  850. | File | |
  851. |---|---|
  852. | `project.hl` | THE MAP: index comment (feature → file), config (PWA, port, env), routes, audience (who hears which push), migrate at start, the server |
  853. | `lib/tickets.hl` | tickets + their relations: `tickets` and `links` tables, rows, finding (`ticketAt`, `ticketByRef`, `ticketByKey`), lists, inbox, create / comment / state / assign / edit, parent / blocked-by, `removeMember` (also unassigns), `ticketRights` |
  854. | `lib/tickets-helpers.hl` | state names + old aliases (`stateOf`), a related ticket's ref, the relation view, the list's filter links |
  855. | `lib/stream.hl` | ticket #26: the event stream for programs — `stream` table (`*n` = the event id), `recordEvent` (tickets.hl calls it after every write), filters, replay, the live subscribers |
  856. | `lib/events.hl` | the history: `events` table (append only, `putEvent`), event rows + labels, page rows with Markdown blocks |
  857. | `lib/comments.hl` | mission 016: comments after they are written — `comment-changes` (edit / delete) and `comment-likes` tables, who may, the comment as shown |
  858. | `lib/projects.hl` | projects + members: `projects` / `members` tables, slugs (old ones keep resolving; `reservedSlugs`, ticket #25), roles use / edit / admin |
  859. | `lib/users.hl` | ticket #7: `users` + `tokens` tables, the ident exchange, sessions → users, the login env, `tagOf` |
  860. | `lib/invites.hl` | ident invites: `mayInvite`, `createInvite`, `joinByInvite` (the login callback's `invite=`) |
  861. | `lib/connections.hl` | ticket #21: an app connected to one project (`connections` table, request → code → key) |
  862. | `lib/markdown.hl` | ticket #6: Markdown text → blocks/spans (safe links), pipe tables (mission 013); `components/markdown.hl` renders them |
  863. | `lib/mdview.hl` | ticket #6: the `Accept: text/markdown` documents (one ticket / a list; relations #4) |
  864. | `lib/migrate.hl` | the ticket #20 migration, idempotent, every start (the one file writing other topics' tables) |
  865. | `lib/import.hl` | the AntColony ticket-file format + `paragraphsOf` (import tool and fix tool) |
  866. | `lib/api.hl` | the function routes: JSON API, `/login/callback`, `/connect`, the old page URLs' 301s (`/tickets/:ref`, `/projects/…`) — thin wrappers |
  867. | `lib/api-helpers.hl` | replies, query/body (`readBody` = JSON check + strict fields), token / app-key auth, list filters, the Markdown Accept check, the small HTML page |
  868. | `lib/jsoncheck.hl` | hand-written JSON syntax check (workaround for hybriel #12 — delete with its one call once JSON.parse can fail softly) |
  869. | `lib/util.hl` | shared small helpers: env, the storage dir, URLs, `countOf` / `first` / `merged`, insertion sorts, text checks, Vienna time |
  870. | `components/` | the shell (`main.hl`) and the pages; `styles.hl` = all CSS (imports the tokens from `shared/tokens.hl`, sets the accent) |
  871. | `components/you.hl` | `/you`: account + API tokens |
  872. | `components/comments/`, `components/md-editor/`, `components/SOURCE` | mission 016: the Comments block and the MdEditor, verbatim from components.hybriel.worldapi.org (`tools/sync-components.sh`) |
  873. | `login.js` | the selector bridge (plain JS, served at `/login.js`) |
  874. | `shared/tokens.hl` | the WorldAPI tokens (webex `var()`), verbatim copy of worldapi-tokens/tokens.hl — README "Design tokens" |
  875. | `tools/import.hl` | the import command (needs `TICKETS_TOKEN`; section "Import") |
  876. | `tools/fix-import-summaries.hl`, `tools/migrate-short-ids.hl` | one-offs (2026-09-24 summaries; ident#23 short ids) |
  877. | `tools/sync-components.sh` | mission 016: copies the blocks from components.hybriel.worldapi.org byte-verbatim (`--check` compares) |
  878. | `tests/browser.mjs` | the gate; `tests/connect.mjs` the connect gate; `tests/identkit.mjs` the gate's own ident |
  879. | `tests/oldstore.hl` | the gate's old-format fixture for the migration |
  880. | `tests/events.mjs`, `tests/events-seed.hl`, `tests/events-client.hl` | ticket #26: the event-stream test, its fixture, a Hybriel subscriber |
  881. | `tests/localtime.hl`, `tests/markdown.hl` | print Vienna renderings of DST edges / markdown.hl's blocks for `MD_INPUT` |
  882. | `tests/realdata-baseline.mjs`, `tests/realdata-compare*.py` | a cleanup answers the same: reads + a write sequence on a live-data copy (section "Test" → "Same output") |
  883. | `tests/shorturls-realdata.mjs` | ticket #25 on a live-data copy: every project + N tickets on the short and the old URLs (section "Test" → "Short URLs on real data") |
  884. | `tests/projectids-realdata.py` | mission 012 on a live-data copy: old vs new API byte for byte, slug vs id byte for byte (section "Test" → "Project ids on real data") |
  885. | `tests/letcount.py` | code-order counts: root `.hl` files, project.hl lines, `let` that should be plain |
  886. | `icons/` | antcolony mission 046: `icon.svg` (source), `icon-192/512.png`, `apple-touch-icon.png`, `favicon.ico` — README "PWA" |
  887. | `docker-compose.yml`, `deploy.sh` | Byrodin container; the deploy from Loreana (section "Deploy") |
  888. | `import/tickets/` | copies of the AntColony ticket files (source: byrodin) |
  889. ## History and worker briefs
  890. - `LOG.md` — append-only history, one dated line per step (moved here from the antcolony LOG on 2026-10-01).
  891. - `missions/NNN-*.md` — worker briefs for this app; `reports/NNN-*.md` — their reports (same name). Numbered per
  892. project since 2026-10-01 (antcolony#40); older text, code comments and commits use the old antcolony numbers →
  893. map: `/media/STORAGE/projects/antcolony-docs/docs/mission-map.md` (Byrodin: `/CONTAINERS/projects/antcolony/docs/mission-map.md`).
  894. Mission 025 theme source: `theme/` is copied unchanged using git archive from layouts
  895. commit `17e0f03ecd09b4427fab17276f646e0094260fd5`. Recording this source commit
  896. is the mission author’s bookkeeping requirement, not a user design instruction.
  897. ## Subscriptions (ticket #51)
  898. Conductors can receive one content-free wake when changes become pending, then pull one combined delta. Use a tickets `tkt_` user token. Subscribe yourself to a list of up to 100 project IDs from `/api/projects`, or use `"projects":"all"` for your own overview:
  899. ```sh
  900. curl -s -A Jukebox -H "Authorization: Bearer $TICKETS_TOKEN" \
  901. -H 'Content-Type: application/json' \
  902. -d '{"projects":["PROJECT_ID"],"label":"Jukebox"}' \
  903. https://tickets.worldapi.org/api/subscriptions
  904. curl -s -A Jukebox -H "Authorization: Bearer $TICKETS_TOKEN" \
  905. -H 'Accept: text/markdown' \
  906. https://tickets.worldapi.org/api/subscriptions/SUBSCRIPTION_ID/delta
  907. ```
  908. An admin of **every** listed project may also set `"owner":"TICKETS_USER_ID"` to subscribe another user. All-project subscriptions are self only. GET `/api/subscriptions` lists your subscriptions and those you administer, including cursor, wakePending and wakeStatus. POST `/api/subscriptions/:id/remove` removes one you own or administer. Only its owner may GET the delta. Cookies, project keys and ident access keys do not authenticate these endpoints.
  909. Creation starts at the current stream high-water (no old history). Delta JSON is `{subscription,from,upTo,tickets:[{project,number,ref,subject,href,changes,relevance,actors,lastAt}],more}`. `from` is the previous cursor, `upTo` is the numbered stream snapshot; `more` is false because JSON contains every coalesced ticket. Actor and assignee values are stable tickets user IDs. Changes contain `created`, `state:{from,to}`, `titleEdited`, `summaryEdited`, `assignee:{from,to}`, `comments`, `lastComment` (200 characters), and `links` where applicable. Only non-owner stream events in scope contribute. State and assignee transitions merge first to last. Comment edits/deletions/likes are outside the existing stream and therefore outside deltas.
  910. Relevance is `assigned` (owner is current or previous assignee on a contributing row), `own` (owner created the ticket), and `mention`. The exact mention rule is case-insensitive literal substring matching of the owner's current nonempty display name in the **full original** comment or new summary of a contributing created/edit row. `@` is optional; code and quoted text count; substrings inside words count. Names are the handles tickets exposes. This rule does not guess identities from display-name equality for self exclusion.
  911. Markdown puts relevant tickets first, one line per ticket, with a 4096 UTF-8-byte budget and an overflow line `… and N more tickets in P1 (a), P2 (b)`. If project names alone would exceed the budget, remaining projects are grouped as `K other projects (N)` after 2000 bytes of named project counts. The overflow is part of the same delivered digest. JSON retains all details. Fetching either representation **marks the snapshot delivered**, advances cursor to upTo and clears wakePending. `?peek=1` previews without marking. A second fetch is empty unless more non-own events arrived. A lost response may have been marked delivered: use peek when inspecting. There is no second digest or separate acknowledgement.
  912. Each subscription may also provide `pushUrl` and `secret` at creation. Obtain the per-chat secret from HyperConductor (shown there once); tickets never returns it, including on creation. Example additional JSON fields: `"pushUrl":"http://HC_INSTANCE:PORT/api/push/CHAT_ID","secret":"CHAT_PUSH_SECRET"`. Leave pushUrl unset for delta-only use. Only the owner or an admin of every listed project can set these fields under the creation rights above.
  913. Tickets sends directly to that chat, with no intermediary service or HC instance control token:
  914. ```text
  915. POST <instance>/api/push/<chatId>
  916. X-Push-Delivery: <uuid>
  917. X-Push-Signature-256: sha256=<HMAC-SHA256(chat secret, raw UTF-8 JSON body)>
  918. Content-Type: application/json
  919. {"source":"tickets","delivery":"<same uuid>","text":"tickets: new changes for you. Read them: curl ... /api/subscriptions/<id>/delta"}
  920. ```
  921. The text is at most 500 characters and contains the self-explanatory curl command with placeholders for the conductor's agent name and tickets token. It contains no ticket content or secret. A pending episode produces one push, then no further push until fetch. HC's 202 means accepted; 409 means this delivery was already accepted and is also success. Failures, including 401, 404, 429 and transport errors, retry after 1, 5, 30, 120 minutes, then show failed. Thus a 429 always waits longer than HC's 10-second per-chat rate interval. Redirects are never followed; timeout is 10 seconds. Retries and startup recovery reuse the exact delivery ID and JSON body. Standby's dispatcher remains disabled, and main reconciles its stream rows.
  922. Before enabling pushes, the operator sets `TICKETS_PUSH_ALLOWED` to a comma-separated list of trusted HC base URLs, for example `http://100.77.141.84:8100,http://127.0.0.1:45010`. A pushUrl must match a full base followed by `/api/push/<chatId>` with a nonempty ID containing only digits and hyphens. Prefix lookalikes, userinfo, query strings, fragments and other paths are refused with 400. An empty allowlist disables creation/dispatch of push destinations; deltas continue working.
  923. The operator also sets a private `TICKETS_PUSH_KEY` of at least 32 characters (use 32 random bytes rendered as 64 hex characters). A subscription with a push destination cannot be created without this storage key. Hybriel's documented HKDF-SHA256 derives a 16-byte AES key; AES-128-GCM encrypts each chat secret with a fresh random 12-byte nonce and the destination URL as authenticated data. Only ciphertext and nonce enter subscriptions.db. Keep the storage key stable and back it up separately: changing/loss of it prevents decryption; recreate affected subscriptions with their chat secrets after a deliberate key change. Do not put either secret in git or logs. The API exposes only whitelisted public subscription fields, never the secret or ciphertext. No HC control token is needed.
  924. After review, deployment may proceed with push destinations omitted until Hermes' HC endpoint is available. Then configure the allowlist/key, obtain the target chat's push secret, create a push-test subscription, and perform the brief's parked-chat live proof before normal conductor cutover. Existing `/api/events`, Markdown ticket views, sessions and connect APIs are unchanged.

Branches

Latest commits

  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre