feat(web): the dojo remembers your session #92

Merged
yuuhikaze merged 1 commit from web/dojo-memory into master 2026-10-25 10:37:26 -05:00
Owner

The sensei had alzheimer: every visit to /dojo re-played his self-introduction, and going to the editor mid-quiz threw the kata away. Root cause: all dojo state lived in component-local $state atoms of the route component, which SvelteKit destroys on navigation.

What this does

  • web/src/lib/dojo/session.svelte.ts (new) — module-level reactive session store in the house style (audio.svelte.ts / state.svelte.ts): phase, topic/difficulty/mode/minutes, problem, answer, choice, result, correctChoice, revealed, results, the sensei (line/shown/talking/mood/lastActivity), the used problem set, the shiai prefetch and the brain config. It survives client-side navigation and dies on a hard reload — a new tab boots the dojo anew, and nothing is ever persisted (the config may hold an API key).
  • Honest exam clock — the store keeps an absolute endsAt epoch-ms deadline instead of remaining seconds. The mounted page recreates the ticker from it, so time keeps running while the student is away (an exam clock does not pause because you wandered off). A remount with an overdue deadline routes through the existing time-up handling. minutes = 0 → no deadline.
  • Sensei memory — the long INTRO plays only on a fresh session (introduced flag). Returning to an idle menu gets a short tri-language line from the new RETURN set in dojo/lines.ts ("Back to the mat. It kept your place."). Returning mid-drill restores the stored line, mood and typed bubble verbatim — no new speech.
  • +page.svelte refactored to read/write the store; all behavior otherwise unchanged (brain settings modal, ask-the-sensei, grading, verdicts, scorecard, pumping link). Brain config load/save semantics preserved (localStorage stays the source of truth; the store just caches it in memory).
  • Pumping drill (dojo/pumping/) gets the same quick treatment via pumping-session.svelte.ts — language, p, string, split and bubble survive the round trip.
  • Pure timer/arrival rules live in session-logic.ts (no runes) with unit tests.

Verification

  • bun run check: 0 errors, 0 warnings
  • bun test: 82 pass (9 new for deadline/remaining/arrival rules)
  • bun run build: OK
  • Playwright against a dev server: fresh session shows "I am Supa Choi Sensei!"; starting a 5-min kata, waiting, leaving to [ EDITOR ] and returning via [ DOJO ] keeps the same problem text, the clock continues (⧗ 04:56 → ⧗ 04:51 over ~5 s away, not reset), the phase is still solving (SUBMIT on the mat), and no re-intro — the bubble still shows the problem intro. Back at an idle menu the sensei says the short return line. Pumping drill survives the same round trip. Hard reload still starts clean (module memory only).

Co-Authored-By: GLM (OpenCode) dev@yhkze.net

The sensei had alzheimer: every visit to `/dojo` re-played his self-introduction, and going to the editor mid-quiz threw the kata away. Root cause: all dojo state lived in component-local `$state` atoms of the route component, which SvelteKit destroys on navigation. ## What this does - **`web/src/lib/dojo/session.svelte.ts` (new)** — module-level reactive session store in the house style (`audio.svelte.ts` / `state.svelte.ts`): `phase`, `topic/difficulty/mode/minutes`, `problem`, `answer`, `choice`, `result`, `correctChoice`, `revealed`, `results`, the sensei (`line/shown/talking/mood/lastActivity`), the `used` problem set, the shiai prefetch and the brain config. It survives client-side navigation and dies on a hard reload — a new tab boots the dojo anew, and nothing is ever persisted (the config may hold an API key). - **Honest exam clock** — the store keeps an absolute `endsAt` epoch-ms deadline instead of remaining seconds. The mounted page recreates the ticker from it, so time keeps running while the student is away (an exam clock does not pause because you wandered off). A remount with an overdue deadline routes through the existing time-up handling. `minutes = 0` → no deadline. - **Sensei memory** — the long `INTRO` plays only on a fresh session (`introduced` flag). Returning to an idle menu gets a short tri-language line from the new `RETURN` set in `dojo/lines.ts` ("Back to the mat. It kept your place."). Returning mid-drill restores the stored line, mood and typed bubble verbatim — no new speech. - **`+page.svelte`** refactored to read/write the store; all behavior otherwise unchanged (brain settings modal, ask-the-sensei, grading, verdicts, scorecard, pumping link). Brain config load/save semantics preserved (localStorage stays the source of truth; the store just caches it in memory). - **Pumping drill** (`dojo/pumping/`) gets the same quick treatment via `pumping-session.svelte.ts` — language, `p`, string, split and bubble survive the round trip. - Pure timer/arrival rules live in `session-logic.ts` (no runes) with unit tests. ## Verification - `bun run check`: 0 errors, 0 warnings - `bun test`: 82 pass (9 new for deadline/remaining/arrival rules) - `bun run build`: OK - Playwright against a dev server: fresh session shows "I am Supa Choi Sensei!"; starting a 5-min kata, waiting, leaving to `[ EDITOR ]` and returning via `[ DOJO ]` keeps the **same problem text**, the clock **continues** (⧗ 04:56 → ⧗ 04:51 over ~5 s away, not reset), the phase is still `solving` (SUBMIT on the mat), and **no re-intro** — the bubble still shows the problem intro. Back at an idle menu the sensei says the short return line. Pumping drill survives the same round trip. Hard reload still starts clean (module memory only). Co-Authored-By: GLM (OpenCode) <dev@yhkze.net>
feat(web): the dojo remembers your session
All checks were successful
ci / image (oven/bun:1.4.2-debian=docker-image://git.yhkze.net/actions/bun:1.4.2-debian node:22-bookworm-slim=docker-image://git.yhkze.net/actions/node:22-bookworm-slim , web, web.Dockerfile, rgxr-web) (pull_request) Has been skipped
ci / image (rust:1-slim-bookworm=docker-image://git.yhkze.net/actions/rust:1-slim-bookworm debian:bookworm-slim=docker-image://git.yhkze.net/actions/debian:bookworm-slim , ., api.Dockerfile, rgxr-api) (pull_request) Has been skipped
ci / rust (pull_request) Successful in 4m28s
ci / web (pull_request) Successful in 3m24s
fedc5b5d19
The dojo kept no memory: every route component held its own $state, so
SvelteKit destroying it on navigation meant the sensei re-introduced
himself on every visit and a detour to the editor threw away the running
kata. All drill state (phase, settings, problem, answer, grading, results)
plus the sensei's line, mood and the brain config now live in a
module-level store (web/src/lib/dojo/session.svelte.ts) that survives
client-side navigation and dies on a hard reload — nothing persisted.

The exam clock stores an absolute endsAt deadline instead of remaining
seconds: time keeps ticking while the student is away, and a remount
recreates the ticker from the deadline (routing an overdue one through
the existing time-up handling). The sensei plays his long self-
introduction only on a fresh session; afterwards he greets a returning
student with a short line (new RETURN lines in dojo/lines.ts) and, mid-
drill, simply keeps whatever he was saying. The pumping drill gets the
same treatment (pumping-session.svelte.ts).

Pure timer/arrival rules live in session-logic.ts with unit tests.

Co-Authored-By: GLM (OpenCode) <dev@yhkze.net>
yuuhikaze merged commit 305aab1e61 into master 2026-10-25 10:37:26 -05:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
k8s-services/rgxr!92
No description provided.