web: std/live page placement (WEB slice 6) and the client script (slice 7) #103

Open
opened 2026-10-05 21:07:20 +00:00 by orion · 6 comments
Collaborator

Context

The live UI's protocol (WEB slice 6) and its one JavaScript file (WEB slice 7). The two slices do not fit one PR (the protocol is the highest-risk part of the web framework; the script is a second language and a second test platform), so this issue is an epic: step 1 is the work of this issue, step 2 is filed when step 1 has landed.

Source

  • WEB.md slices 6, 7; sections 6.1 (the model), 6.4 (page placement), 6.5 (the wire), 6.8 (the client script)

Dependencies

  • Depends on #101 (closed) and #94 (std/web core). Step 1 starts only after #777 (Middleware, Next, WebApp, web { }, answer) has merged: LiveTest builds on WebTest, and the live endpoint is a Handler.
  • std/html (#93) and F7 (HMAC-SHA256, Digest.equalsConstantTime) are done.

Steps

  • Step 1 (this issue): std/live, page placement (slice 6)
  • Step 2: the client script (slice 7), filed as its own issue when step 1 has landed; criteria below

Step 1: goal

A type X with Live<Message> renders as a complete HTML page with a live region and answers events over an HTTP POST that carries the model in a signed snapshot. No connection, no session state between events (WEB.md 6.4, 6.5).

Step 1: acceptance criteria

  • std/live exports Live<Message>, Effect (Effect.none(), Effect.task), fragment-based views typed by Html<Message>, and a generic live endpoint that finds Message through the trait bound (F3, #101), not through a type argument written by the caller.
  • Per event, in this order: decode the snapshot, check signature and build id; render the old model's view only to rebuild the handler table; take the handler the event names; update; run the effects to their answer within a time limit, applying each message; render the new view; answer the parts whose hash differs from hashes plus the new snapshot (WEB.md 6.4).
  • The wire is the JSON of WEB.md 6.5: page markup (data-live, data-snapshot, data-build, data-part, data-hash, data-on-*, data-debounce), the POST body and answer, { "reload": true } for a different build. Handler indexes are positions in the handler table, never strings of code.
  • A snapshot with a bad signature, a bad encoding or a handler index outside the table is refused with a WebError status (4xx), never a panic; a forged message is impossible by construction. Signing is HMAC-SHA256 over the encoded model with an application-supplied key (std/digest); no new native, no random source.
  • Model requirement Encode & Decode (derived); a model that is not fails at compile time with the checker's own message, covered by a conformance test.
  • A second event before the first effect answered cancels the first task (last keystroke wins), shown by a test.
  • LiveTest (in the std/live test module, beside WebTest): renders a page, posts an event by handler position, returns the parts and the next model; tests for the search example of WEB.md 6.1 (typed, found, cleared), a build mismatch, a forged snapshot, a superseded effect.
  • examples/ gets the search page as a small live example served through web { } (only if #777 has the example scaffold; otherwise the test is the example).
  • CSRF: the protocol carries the CSRF token as a header; verification is slice 3 (forms/CSRF) and is not part of this step. The endpoint takes an optional Middleware-level hook so slice 3 plugs in without a protocol change.
  • Docs: docs/design/WEB.md slice 6 marked done with the PR/commit reference, std/live documented, skills/ regenerated.

Step 2 (filed later): goal and criteria (slice 7)

  • One hand-written JavaScript file of a few KB as an EmbeddedText of std/live, served as a fingerprinted asset (needs slice 5 assets, or the file served by the live endpoint itself until then, decided when filed): forwards events with debounce, posts them, applies parts by morphing, keeps the snapshot, marks data-loading while a request is in flight, reloads on { "reload": true }, keeps what the user typed while the answer is in flight, runs Client.toggle-style commands without a round trip.
  • Browser test of the example search: see the decision below.

Seed impact

None expected: pure std/ TorbScript over existing natives (std/digest, std/json, std/task). No syntax change, no new native, no driver flag. A std name the compiler looks up by string must not be added; if the implementer finds one is needed, stop and say so in the PR (two-commit rule, seed refresh is Torben's).

Size

One PR, two Conventional Commits: (1) feat(std/live): Live, Effect, handler table, parts and hashes, LiveTest (2) feat(std/live): snapshots and the POST protocol. If it does not fit, split at that line and file the second commit as its own issue.

Moved from the planning lists of the docs; the design record stays the specification.

## Context The live UI's protocol (WEB slice 6) and its one JavaScript file (WEB slice 7). The two slices do not fit one PR (the protocol is the highest-risk part of the web framework; the script is a second language and a second test platform), so this issue is an epic: step 1 is the work of this issue, step 2 is filed when step 1 has landed. ## Source - [WEB.md slices 6, 7](https://git.torb.dev/torbscript/language/src/commit/393ef2608e4a60b8ff76d8b6b408951b822d887d/docs/design/WEB.md#L979); sections 6.1 (the model), 6.4 (page placement), 6.5 (the wire), 6.8 (the client script) ## Dependencies - Depends on #101 (closed) and #94 (`std/web` core). **Step 1 starts only after #777 (`Middleware`, `Next`, `WebApp`, `web { }`, `answer`) has merged**: `LiveTest` builds on `WebTest`, and the live endpoint is a `Handler`. - `std/html` (#93) and F7 (HMAC-SHA256, `Digest.equalsConstantTime`) are done. ## Steps - [ ] **Step 1 (this issue): `std/live`, page placement (slice 6)** - [ ] **Step 2: the client script (slice 7)**, filed as its own issue when step 1 has landed; criteria below ## Step 1: goal A `type X with Live<Message>` renders as a complete HTML page with a live region and answers events over an HTTP `POST` that carries the model in a signed snapshot. No connection, no session state between events (WEB.md 6.4, 6.5). ## Step 1: acceptance criteria - [ ] `std/live` exports `Live<Message>`, `Effect` (`Effect.none()`, `Effect.task`), `fragment`-based views typed by `Html<Message>`, and a generic live endpoint that finds `Message` through the trait bound (F3, #101), not through a type argument written by the caller. - [ ] Per event, in this order: decode the snapshot, check signature and build id; render the old model's view only to rebuild the handler table; take the handler the event names; `update`; run the effects to their answer within a time limit, applying each message; render the new view; answer the parts whose hash differs from `hashes` plus the new snapshot (WEB.md 6.4). - [ ] The wire is the JSON of WEB.md 6.5: page markup (`data-live`, `data-snapshot`, `data-build`, `data-part`, `data-hash`, `data-on-*`, `data-debounce`), the `POST` body and answer, `{ "reload": true }` for a different build. Handler indexes are positions in the handler table, never strings of code. - [ ] A snapshot with a bad signature, a bad encoding or a handler index outside the table is refused with a `WebError` status (4xx), never a panic; a forged message is impossible by construction. Signing is HMAC-SHA256 over the encoded model with an application-supplied key (`std/digest`); no new native, no random source. - [ ] Model requirement `Encode & Decode` (derived); a model that is not fails at compile time with the checker's own message, covered by a conformance test. - [ ] A second event before the first effect answered cancels the first task (last keystroke wins), shown by a test. - [ ] `LiveTest` (in the `std/live` test module, beside `WebTest`): renders a page, posts an event by handler position, returns the parts and the next model; tests for the search example of WEB.md 6.1 (typed, found, cleared), a build mismatch, a forged snapshot, a superseded effect. - [ ] `examples/` gets the search page as a small live example served through `web { }` (only if #777 has the example scaffold; otherwise the test is the example). - [ ] CSRF: the protocol carries the CSRF token as a header; verification is slice 3 (forms/CSRF) and is **not** part of this step. The endpoint takes an optional `Middleware`-level hook so slice 3 plugs in without a protocol change. - [ ] Docs: `docs/design/WEB.md` slice 6 marked done with the PR/commit reference, `std/live` documented, `skills/` regenerated. ## Step 2 (filed later): goal and criteria (slice 7) - [ ] One hand-written JavaScript file of a few KB as an `EmbeddedText` of `std/live`, served as a fingerprinted asset (needs slice 5 `assets`, or the file served by the live endpoint itself until then, decided when filed): forwards events with `debounce`, posts them, applies `parts` by morphing, keeps the snapshot, marks `data-loading` while a request is in flight, reloads on `{ "reload": true }`, keeps what the user typed while the answer is in flight, runs `Client.toggle`-style commands without a round trip. - [ ] Browser test of the example search: see the decision below. ## Seed impact None expected: pure `std/` TorbScript over existing natives (`std/digest`, `std/json`, `std/task`). No syntax change, no new native, no driver flag. A std name the compiler looks up by string must not be added; if the implementer finds one is needed, stop and say so in the PR (two-commit rule, seed refresh is Torben's). ## Size One PR, two Conventional Commits: (1) `feat(std/live): Live, Effect, handler table, parts and hashes, LiveTest` (2) `feat(std/live): snapshots and the POST protocol`. If it does not fit, split at that line and file the second commit as its own issue. _Moved from the planning lists of the docs; the design record stays the specification._
Author
Collaborator

[loop:torbscript] intake: in scope (author orion, label loop), source WEB.md slices 6 and 7, not a duplicate. Two slices, one of them ships a JavaScript file with a browser test (CI platform question for refine). Depends on #94 and #101. next: waiting (dependencies #94 and #101) until 2026-10-10T04:00:00Z

[loop:torbscript] intake: in scope (author orion, label loop), source WEB.md slices 6 and 7, not a duplicate. Two slices, one of them ships a JavaScript file with a browser test (CI platform question for refine). Depends on #94 and #101. next: waiting (dependencies #94 and #101) until 2026-10-10T04:00:00Z
Author
Collaborator

[loop:torbscript] claim refine by session:loop-torbscript-20261114 until 2026-11-14T06:00:00Z

[loop:torbscript] claim refine by session:loop-torbscript-20261114 until 2026-11-14T06:00:00Z
orion changed title from web: std/live page placement and the client script (WEB slices 6 and 7) to web: std/live page placement (WEB slice 6) and the client script (slice 7) 2026-11-14 04:01:41 +00:00
Author
Collaborator

[loop:torbscript] decided by the loop: CI platform for the slice 7 browser test. Forge CI (.forgejo/workflows/gates.yml) runs on one ubuntu-latest runner; the only JavaScript runtime is the pinned Node.js 24.21.0 (.forgejo/actions/node, used by conformance-js and the editor tests); the emscripten job runs node too. There is no browser, no WebDriver and no DOM library (jsdom, happy-dom) anywhere in CI or tools/, and the repo has no npm dependency flow for tests. Decision: the slice 7 "browser test" is a Node test (node --test, like .forgejo/scripts/*.test.mjs) that runs the client script against a small in-repo DOM double covering only what the script touches (element tree, attributes, fetch, timers for debounce, location.reload), driven through the real example search page rendered by LiveTest/the live endpoint. Why: no new job image, no download of a browser, no external or hosted browser service (which would be a cost/account matter for Torben), deterministic, minutes of CI. A real-browser run stays a possible later addition if the double proves too weak; not needed for v1.
decided by the loop: #103 is an epic of two steps (slice 6 protocol, slice 7 script); step 1 is this issue and ships as one PR of two commits, step 2 is filed just in time after step 1 lands. CSRF verification stays in slice 3; no seed impact expected (pure std/ code over existing natives).

[loop:torbscript] decided by the loop: CI platform for the slice 7 browser test. Forge CI (.forgejo/workflows/gates.yml) runs on one `ubuntu-latest` runner; the only JavaScript runtime is the pinned Node.js 24.21.0 (`.forgejo/actions/node`, used by `conformance-js` and the editor tests); the emscripten job runs node too. There is no browser, no WebDriver and no DOM library (jsdom, happy-dom) anywhere in CI or tools/, and the repo has no npm dependency flow for tests. Decision: the slice 7 "browser test" is a Node test (`node --test`, like `.forgejo/scripts/*.test.mjs`) that runs the client script against a small in-repo DOM double covering only what the script touches (element tree, attributes, `fetch`, timers for debounce, `location.reload`), driven through the real example search page rendered by `LiveTest`/the live endpoint. Why: no new job image, no download of a browser, no external or hosted browser service (which would be a cost/account matter for Torben), deterministic, minutes of CI. A real-browser run stays a possible later addition if the double proves too weak; not needed for v1. decided by the loop: #103 is an epic of two steps (slice 6 protocol, slice 7 script); step 1 is this issue and ships as one PR of two commits, step 2 is filed just in time after step 1 lands. CSRF verification stays in slice 3; no seed impact expected (pure std/ code over existing natives).
Author
Collaborator

[loop:torbscript] refine: issue body rewritten to the definition of ready for step 1 (slice 6: goal, testable criteria, design points WEB.md 6.1/6.4/6.5, seed impact none, size one PR / two commits); step 2 (slice 7) is a checklist item with its criteria, filed when step 1 landed; browser-test platform decided above (Node + in-repo DOM double). Startable once #777 (std/web core step 2) has merged; label ready set on that basis. Claim 12351 released. next: implement (ready, after #777 merged)

[loop:torbscript] refine: issue body rewritten to the definition of ready for step 1 (slice 6: goal, testable criteria, design points WEB.md 6.1/6.4/6.5, seed impact none, size one PR / two commits); step 2 (slice 7) is a checklist item with its criteria, filed when step 1 landed; browser-test platform decided above (Node + in-repo DOM double). Startable once #777 (std/web core step 2) has merged; label `ready` set on that basis. Claim 12351 released. next: implement (ready, after #777 merged)
Author
Collaborator

[loop:torbscript] refine: this issue is an epic (step 1 slice 6, step 2 slice 7), so it loses ready; step 1 is filed as its own ready issue just in time once PR #777 has merged. next: waiting (dependency #776)

[loop:torbscript] refine: this issue is an epic (step 1 slice 6, step 2 slice 7), so it loses `ready`; step 1 is filed as its own ready issue just in time once PR #777 has merged. next: waiting (dependency #776)
Author
Collaborator

[loop:torbscript] refine: the dependency is met (#776 closed, PR #777 merged), so step 1 (slice 6) can be filed as its own ready issue. The ready buffer holds 4 (#836, #620, #565, #365), so it is filed when fewer than 4 issues are ready. next: waiting (ready buffer full)

[loop:torbscript] refine: the dependency is met (#776 closed, PR #777 merged), so step 1 (slice 6) can be filed as its own ready issue. The ready buffer holds 4 (#836, #620, #565, #365), so it is filed when fewer than 4 issues are ready. next: waiting (ready buffer full)
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#103
No description provided.