web: SvelteKit studio — editor, run, ops, regex, saved #10

Merged
nicolas_naranjo merged 2 commits from agent/web into master 2026-10-23 22:43:18 -05:00
Owner

What changed

Scaffolds web/ (SvelteKit 3 + Svelte 5 runes + @xyflow/svelte 1.7) and adds deploy/web.Dockerfile. 41 files, no touches outside web/ + deploy/web.Dockerfile.

  • Design system (web/src/app.css): tokens copied verbatim from docs/design.md; hairline panels, bracketed [ OP ] controls, inversion-as-selection, uppercase underscored headers, one accent (--accent green), --danger only for destructive actions, blinking-pulse unsaved dot, ASCII empty states. No component library, no light mode.
  • Editor tab: xyflow canvas with a custom state node (initial → glyph, accepting states get a real double border echoing peripheries=2, trace highlighting in accent) and a custom terminal edge that handles self-loops (the default bezier degenerates when source == target, and the CONTRACT example FA has q0 -a-> q0). Drag positions → layout. New transitions: drag handle → handle creates a dashed pending edge; the first symbol commits it. Inspector handles rename / initial (exactly one) / accepting toggles / per-symbol transition editing / deletion. Sidebar: alphabet editor (usage-aware delete with confirm), run panel, inspector.
  • Run panel: input → POST /run → trace as TUI lines (> a → {q0, q1}), step buttons + click-to-step, active states highlighted on the canvas, [ ACCEPTED ] / [ REJECTED ] verdict on the final step.
  • Ops tab: to-dfa / minimize / complement (the latter two pre-checked client-side against the mirrored determinism rule → NOT A DFA: … run [ TO-DFA ] first), and union / intersection / difference / concat with operand B picked from saved automata or pasted JSON. Results can be loaded into the editor (dirty-guard confirm) or saved as new.
  • Regex tab: both directions via /regex/to-nfa and /regex/from-fa, syntax hint line, result load/save/copy.
  • Saved tab: list (AutomatonSummary), load / overwrite-row-with-current / delete, save-as-new + overwrite-current, all dirty-guarded. Payloads are { name, data: { fa, layout } } per CONTRACT.
  • API client (src/lib/api/client.ts): thin fetch wrapper over the generated schema.d.ts; the error envelope is decoded into ApiError and every panel renders it in a terminal error line — engine endpoints returning 501 show up as clean [ ERROR ] … lines, the UI is built against the contract, not a backend.
  • Status bar: MODE: DFA/NFA/EMPTY (mirrors determinism_violation client-side, violation shown as tooltip), Σ, state/transition counts, doc name + unsaved pulse dot, dim hints. Top bar tabs EDITOR / OPS / REGEX / SAVED + USER: from /me.

Semantic decisions

  1. Adapter: @sveltejs/adapter-node (not static). ssr = false (canvas app). The deciding factor: a server hook (src/hooks.server.ts) that, when API_UPSTREAM is set, forwards /api, /api-docs, /healthz, /readyz to it with paths preserved — so the compose stack needs no extra proxy container:
    web:
      build:
        context: ./web
        dockerfile: ../deploy/web.Dockerfile
      environment:
        API_UPSTREAM: http://api:8080
      ports:
        - "5173:3000"
    
    When unset (k8s/prod), requests fall through to the SPA and Traefik routes api paths directly — same contract as the vite dev proxy. The env var is declared the Kit 3 way in src/env.ts. Forwarding was tested against a stub api (GET/POST bodies intact; upstream-down → contract-shaped 502 {"error":{...}}).
  2. Kit 3 conventions: the scaffold dropped $lib/svelte.config.js — imports use package.json subpath imports (#lib/...) with explicit extensions (#lib/state/editor.svelte.ts), config lives in vite.config.ts, hooks typing imports from @sveltejs/kit/hooks.
  3. Vite dev proxy preserves paths: /api, /api-docs, /healthz, /readyz → http://localhost:8080 (bun run preview inherits it).
  4. Alphabet symbols are opaque single characters — the editor auto-registers a transition's symbol into the alphabet (removal prunes its transitions, usage counted + confirmed). This stays agnostic of the ε wire question in #5.
  5. transitions always serialized by the frontend (schema-legal, core-legal). Wire arrays are kept sorted client-side.
  6. Render endpoint surfaced as a [ RENDER ] toolbar action → modal with the SVG + FAST/LATEX engine buttons (latex expected to 503 until the render agent's image ships texlive).
  7. Dockerfile: oven/bun:1.4.2-debian build stage (bookworm, matching deploy/api.Dockerfile's pinning style — note there is no 1.4.2-bookworm tag), lockfile-frozen install, node_modules pruned to production deps, node:22-bookworm-slim runtime, PORT=3000. Build context is web/ per the .dockerignore note.

Closes #2. Related: #5 (ε wire representation question — the UI treats symbols as opaque strings, displays "" as ε, so any core decision renders fine; /regex/to-nfa output must stay validate()-clean to be loadable back into the editor).

Gate results

  • bun run check (svelte-check): 0 errors, 0 warnings
  • bun run build (adapter-node): green
  • docker build -f deploy/web.Dockerfile web/: green (image boots, serves the SPA, forwards api paths)
  • Dev server boot: green, no console errors at startup

Engine endpoints currently 501 — run/ops/regex flows will show [ ERROR ] … lines until the engine PR lands; nothing in the UI depends on a live backend.

Acceptance walkthrough (once engine + api merge)

Load [ EXAMPLE ] (the CONTRACT example FA) → run aabb with trace → step through snapshots → ops tab TO-DFA → MINIMIZE → load into editor → [ RENDER ] (fast) → saved tab [ SAVE AS NEW ] → reload via [ LOAD ].

## What changed Scaffolds `web/` (SvelteKit 3 + Svelte 5 runes + `@xyflow/svelte` 1.7) and adds `deploy/web.Dockerfile`. 41 files, no touches outside `web/` + `deploy/web.Dockerfile`. - **Design system** (`web/src/app.css`): tokens copied verbatim from `docs/design.md`; hairline panels, bracketed `[ OP ]` controls, inversion-as-selection, uppercase underscored headers, one accent (`--accent` green), `--danger` only for destructive actions, blinking-pulse unsaved dot, ASCII empty states. No component library, no light mode. - **Editor tab**: xyflow canvas with a custom `state` node (initial `→` glyph, accepting states get a real double border echoing `peripheries=2`, trace highlighting in accent) and a custom `terminal` edge that handles **self-loops** (the default bezier degenerates when source == target, and the CONTRACT example FA has `q0 -a-> q0`). Drag positions → `layout`. New transitions: drag handle → handle creates a dashed *pending* edge; the first symbol commits it. Inspector handles rename / initial (exactly one) / accepting toggles / per-symbol transition editing / deletion. Sidebar: alphabet editor (usage-aware delete with confirm), run panel, inspector. - **Run panel**: input → `POST /run` → trace as TUI lines (`> a → {q0, q1}`), step buttons + click-to-step, active states highlighted on the canvas, `[ ACCEPTED ]` / `[ REJECTED ]` verdict on the final step. - **Ops tab**: `to-dfa` / `minimize` / `complement` (the latter two pre-checked client-side against the mirrored determinism rule → `NOT A DFA: … run [ TO-DFA ] first`), and `union` / `intersection` / `difference` / `concat` with operand B picked from saved automata or pasted JSON. Results can be loaded into the editor (dirty-guard confirm) or saved as new. - **Regex tab**: both directions via `/regex/to-nfa` and `/regex/from-fa`, syntax hint line, result load/save/copy. - **Saved tab**: list (`AutomatonSummary`), load / overwrite-row-with-current / delete, save-as-new + overwrite-current, all dirty-guarded. Payloads are `{ name, data: { fa, layout } }` per CONTRACT. - **API client** (`src/lib/api/client.ts`): thin fetch wrapper over the generated `schema.d.ts`; the error envelope is decoded into `ApiError` and every panel renders it in a terminal error line — engine endpoints returning 501 show up as clean `[ ERROR ] …` lines, the UI is built against the contract, not a backend. - **Status bar**: `MODE: DFA/NFA/EMPTY` (mirrors `determinism_violation` client-side, violation shown as tooltip), `Σ`, state/transition counts, doc name + unsaved pulse dot, dim hints. Top bar tabs `EDITOR / OPS / REGEX / SAVED` + `USER:` from `/me`. ## Semantic decisions 1. **Adapter: `@sveltejs/adapter-node`** (not static). `ssr = false` (canvas app). The deciding factor: a server hook (`src/hooks.server.ts`) that, **when `API_UPSTREAM` is set**, forwards `/api`, `/api-docs`, `/healthz`, `/readyz` to it with paths preserved — so the compose stack needs no extra proxy container: ```yaml web: build: context: ./web dockerfile: ../deploy/web.Dockerfile environment: API_UPSTREAM: http://api:8080 ports: - "5173:3000" ``` When unset (k8s/prod), requests fall through to the SPA and Traefik routes api paths directly — same contract as the vite dev proxy. The env var is declared the Kit 3 way in `src/env.ts`. Forwarding was tested against a stub api (GET/POST bodies intact; upstream-down → contract-shaped `502 {"error":{...}}`). 2. **Kit 3 conventions**: the scaffold dropped `$lib`/`svelte.config.js` — imports use package.json subpath imports (`#lib/...`) **with explicit extensions** (`#lib/state/editor.svelte.ts`), config lives in `vite.config.ts`, hooks typing imports from `@sveltejs/kit/hooks`. 3. **Vite dev proxy** preserves paths: `/api`, `/api-docs`, `/healthz`, `/readyz` → `http://localhost:8080` (`bun run preview` inherits it). 4. **Alphabet symbols are opaque single characters** — the editor auto-registers a transition's symbol into the alphabet (removal prunes its transitions, usage counted + confirmed). This stays agnostic of the ε wire question in #5. 5. **`transitions` always serialized** by the frontend (schema-legal, core-legal). Wire arrays are kept sorted client-side. 6. **Render endpoint** surfaced as a `[ RENDER ]` toolbar action → modal with the SVG + `FAST`/`LATEX` engine buttons (latex expected to 503 until the render agent's image ships texlive). 7. **Dockerfile**: `oven/bun:1.4.2-debian` build stage (bookworm, matching `deploy/api.Dockerfile`'s pinning style — note there is no `1.4.2-bookworm` tag), lockfile-frozen install, node_modules pruned to production deps, `node:22-bookworm-slim` runtime, `PORT=3000`. Build context is `web/` per the `.dockerignore` note. Closes #2. Related: #5 (ε wire representation question — the UI treats symbols as opaque strings, displays `""` as `ε`, so any core decision renders fine; `/regex/to-nfa` output must stay `validate()`-clean to be loadable back into the editor). ## Gate results - `bun run check` (svelte-check): **0 errors, 0 warnings** - `bun run build` (adapter-node): **green** - `docker build -f deploy/web.Dockerfile web/`: **green** (image boots, serves the SPA, forwards api paths) - Dev server boot: green, no console errors at startup Engine endpoints currently 501 — run/ops/regex flows will show `[ ERROR ] …` lines until the engine PR lands; nothing in the UI depends on a live backend. ## Acceptance walkthrough (once engine + api merge) Load `[ EXAMPLE ]` (the CONTRACT example FA) → run `aabb` with trace → step through snapshots → ops tab `TO-DFA` → `MINIMIZE` → load into editor → `[ RENDER ]` (fast) → saved tab `[ SAVE AS NEW ]` → reload via `[ LOAD ]`.
web: sveltekit studio — editor, run, ops, regex, saved
Some checks failed
ci / web (pull_request) Successful in 13s
ci / rust (pull_request) Has been cancelled
b4feda5fef
- scaffold: sv create (svelte, ts, minimal) + @xyflow/svelte 1.7 +
  adapter-node + openapi-typescript; schema.d.ts generated from
  ../openapi.yaml
- design.md applied verbatim: tokens, hairlines, bracketed controls,
  inversion-as-selection, double border for accepting states, status
  bar with DFA/NFA mode + unsaved pulse dot, no component library
- editor: states as nodes (initial arrow glyph, accepting double
  border, trace highlighting), transitions as edges labeled with
  symbol sets, custom self-loop edge, drag positions -> layout,
  pending-connection flow for new transitions
- panels: alphabet (usage-aware delete), run panel (trace stepper,
  canvas highlight, [ ACCEPTED ]/[ REJECTED ]), inspector (rename,
  initial/accepting toggles, per-symbol transition editing)
- ops page: to-dfa/minimize/complement (client-side DFA precheck),
  union/intersection/difference/concat with operand B from saved
  docs or pasted JSON, result load-into-editor / save-as-new
- regex page: both directions, result load/save, copy
- saved page: list + load/overwrite/delete, save-as-new, dirty-guard
  confirm modals
- api client: typed fetch wrapper over generated types, error
  envelope -> ApiError (terminal error lines everywhere)
- vite dev proxy /api,/api-docs,/healthz,/readyz -> :8080 (paths
  preserved); adapter-node runtime forwards the same paths to
  API_UPSTREAM when set (src/env.ts declares it) so compose needs no
  extra proxy; unset in k8s, Traefik routes
- deploy/web.Dockerfile: bun 1.4.2-debian build stage -> node:22
  bookworm-slim runtime, lockfile-frozen install, context = web/

Gates: bun run check (svelte-check) 0 errors; bun run build green;
docker build verified; API_UPSTREAM forwarding + 502 envelope tested
against a stub api.
web: strip client-supplied Remote-* identity headers in the api forwarder
Some checks failed
ci / web (pull_request) Failing after 1m29s
ci / rust (pull_request) Failing after 16m13s
57279d53a9
Review fixes for PR #10:

- [MAJOR] hooks.server.ts: the API_UPSTREAM forwarder now strips
  client-supplied remote-user / remote-name / remote-email /
  remote-groups (case-insensitive) before proxying — the api trusts
  those headers per docs/CONTRACT.md, so forwarding them unmodified
  let any client forge an identity. X-Forwarded-* is left untouched;
  the hook only runs when API_UPSTREAM is set (compose/dev wiring) —
  in k8s/prod it is inert and Traefik + Authelia own those headers.
  The pure helpers moved to src/lib/server/forwarding.ts with a
  regression test (src/lib/server/forwarding.test.ts, bun test —
  bun's built-in runner, so no new runtime dep; @types/bun added
  types-only). End-to-end verified against the built image with a
  header-echoing stub: spoofed Remote-* never reach the upstream.
- [MINOR] drop unused @sveltejs/adapter-auto devDependency (leftover
  from the scaffold; bun.lock regenerated).
- [NIT] vite.config.ts: correct the comment — vite preview does NOT
  inherit server.proxy (it has its own preview.proxy option); built-
  app same-origin api access comes from the API_UPSTREAM hook.

Gates: bun test 5/5, bun run check 0 errors, bun run build green.
nicolas_naranjo deleted branch agent/web 2026-10-23 22:43:18 -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!10
No description provided.