Skip to content

Web UI / Schema Editor (Stage 3) ​

First item of Stage 3: a web-based Schema editing entry point for designers and programmers. The red lines are unchanged: no Excel editor, no game-logic framework. The Web UI is only a front door to the Schema, not a data runtime.

Positioning ​

Cage's CLI is the interface of record for the compile chain; the Web UI is another front door to the same core: the editor does not parse or render YAML, it only exchanges documents with the core and delegates validation. All editing semantics (the 19 editable field types—core defines 20 kinds, TaggedUnion is preserved verbatim with no dedicated editor—constraints, references, targets visibility, expression rules) come from cage-core; the front end replicates no rules.

Architecture Decisions ​

Swap model = the existing serde Canonical shape ​

The editor document is the serde shape of Schema—the same document as schema.json in a Configuration Snapshot and the HTTP API. One document, consumed in three places:

text
snapshot/schema.json  ≡  cage-core::edit::to_editor_json  ≡  HTTP GET /api/schema

Editor JSON preserves insertion order (tables/fields in document order), omits the optional fields covered by skip_serializing_if, and emits default explicitly as null because it has no skip attribute (the front end can edit either).

Save = canonical YAML write-back (whole-file / per-source incremental) ​

The editor works on the merged canonical Schema (the CLI merges the multiple files under schemas/ into one Schema at load time, and the editor builds on that shape). Write-back is canonical YAML (to_canonical_yaml); a .json schema file is written back as pretty-printed JSON (its format is honored, never clobbered into YAML): the same Schema → the same bytes (including a single trailing newline), and the round trip through from_canonical_yaml is idempotent. A single-file schema_path is overwritten whole (atomic replace: sibling temp file + rename). A multi-file (directory) schema_path saves incrementally: GET /api/schema carries a sources index (per-file sha256 revision + table/enum ownership), the save envelope {"schema": …, "sources": …} echoes it back — the index is conflict-checked (any file whose on-disk sha256 no longer matches its load-time revision → 409 refused, nothing written), only the files owning a changed table/enum/metadata are rewritten (each atomically), and the response returns the post-save index for the client's next save. POST /api/schema/preview is the same planning run without writing: it answers with the unified diff of exactly the files the save would rewrite, so the editor shows the changes before they land. Determinism contract: artifacts produced by cage build from editor-saved YAML are byte-identical to those built from the same hand-written Schema. The generator only ever sees Schema values, so any value-preserving edit round-trip is sufficient.

The E1701 editing-state error family ​

When the editor document cannot be deserialized into Schema (syntax / shape / unknown kind), it reports E1701 with the JSON path (tables.Item.fields.id.type) pinpointing the specific input (the front end's highlight anchor); internal schema consistency (a missing primary key, a dangling reference) still goes through L1's E1004. The two error classes are kept separate—the editor and the validator each report their own.

No node front-end toolchain ​

The front end is a static single page under docs/public (vanilla ES modules), served directly by cage web. The editor path introduces no Node/npm build chain; cargo does it in one step (the docs site itself is built with VitePress, unrelated to the editor).

The trusted-environment boundary (P3-3, 2026-11-22) ​

cage web is a local-first, single-user workbench for a trusted environment — one machine, one author, the browser on the same box. It is not a server product, and it does not grow into one incrementally:

  • No accounts, logins or roles. There is no identity to authenticate; the tool assumes the author already owns the machine (the same trust model as the plugin decision, §17.1 — locally trusted code).
  • No remote administration. The only clients are the local browser and local tooling; there is no admin surface to secure because there is none by design.
  • No secret management. Passwords, tokens and keys do not belong in ordinary game configuration — the standing "what Cage should not do" red line applies here too.
  • No multi-user coordination. The server never mediates between two authors; review/approval/conflict-resolution between people is out of scope.

The collaboration model is Git, not the server. Schema files are the source of truth in the repo; planners share work through Git (push/pull/branch/merge — merge conflicts are resolved by Git's own tooling, and cage check is the shared arbiter of a merged tree). The web workbench is what each author edits with; a second author is never served a second session.

Do not expose the port. The listener binds 127.0.0.1 only and the CLI offers no --bind (the --port flag's own doc says "binds 127.0.0.1 only"). A remote client reaches the workbench through SSH port forwarding (the UI facade's remote-access policy, decided). --bind/LAN exposure would need authentication first and stays a registered sticking-point condition — exposing an unauthenticated local service onto a LAN is a security regression, and no exception is made for convenience.

The boundary as enforced (as-built, test-pinned):

  • Bind: tiny_http::Server::http(("127.0.0.1", port)) in cage-cli/src/web/mod.rs; the bind-failure test holds a port and asserts the serve loop tried 127.0.0.1 — changing the bind address fails the suite.
  • Host/Origin gate: a request whose Host does not name 127.0.0.1/localhost/::1, a missing Host (HTTP/1.0), or a POST carrying a non-loopback Origin gets 403 (local_boundary_violation — the DNS-rebinding / cross-site-write guard); pinned by local_boundary_checks_host_and_origin (foreign Host, missing Host, cross-origin write refused; every loopback spelling passes).
  • Bounds: 8 MiB body cap (413) and a 30-second read budget (408) on the single-threaded serve loop.
  • Data discipline: uploads are double-guarded to the project root and a registered source_roots entry after canonicalization (symlink escapes refused); artifacts are served only from the build-manifest ledger and re-verified (blake3) before send.

Re-evaluation condition: only if a real scenario demands centralized multi-planner coordination — then authentication, permissions, review flow, conflict-merge and release workflow get designed as a product (review §八 / P3-3), not bolted onto this tool. Until then the boundary stands.

Status ​

W1 implemented: editor swap model (cage-core::edit) ​

W2 implemented: cage web local HTTP service (cage-cli/src/web/) ​

W3 implemented: Schema editor front end (docs/public/editor/, compiled in at build time) ​

W4 implemented: finalized editing flow + example project smoke test + CI ​

W5 implemented: project status panel (U1, see the roadmap in UI facade) ​

    • 3 integration tests (status page routing and the 301 / status-build end to end / bad data end to end) + web-smoke step 5 (the status page against a real server → fresh → up-to-date)

W6 implemented: artifact browsing (U2a, roadmap in UI facade) ​

    • 1 integration test (list → byte-exact serving → 404 → 409 end to end) + artifact assertions added to web-smoke step 5

W7 implemented: targets badges + profile-scoped view (U2b, roadmap in UI facade) ​

    • 1 integration test (no profile → no projection → client drops the server-only field → server keeps it → ghost 400)
    • web-smoke step 7 (game-config's internal_note: dropped by the client projection, kept by server, ghost 400)

W8 implemented: snapshots / layered diff / registry browsing (U3, roadmap in UI facade) ​

    • cage snapshot CLI tests (--list package listing and a tampering verdict, --list conflicting with --verify/--env)
    • 1 integration test (registry not configured → pack → list → cross-snapshot diff → ghost 400)
    • web-smoke step 5 (pack → self-verify → a zero-difference diff → the empty registry state)

W9 implemented: data panel (planner interface P0, 2026-10-20, roadmap in UI facade) ​

W10 implemented: editor immediate re-validation + one-click artifact export (planner interface P1, 2026-10-20) ​

W11 implemented: diagnostics diff + field template library (planner interface P2, 2026-10-20) ​

W12 implemented: table source upload (planner interface P0, 2026-10-21, roadmap in UI facade) ​

W13 implemented: three-tier editor modes (review P1-1, 2026-11-21) ​

W14 implemented: structured rule AST + visual condition builder (review P1-2, 2026-11-22) ​

W15 implemented: nine built-in rule templates (review P1-3, 2026-11-22) ​

W16 implemented: rule human layer (review P1-4, 2026-11-22) ​

W17 implemented: expressiveness boundary notice (review P1-5, 2026-11-22) ​

W18 implemented: data-file → Schema draft import (review P1-6, 2026-11-22) ​

Roadmap ​

With this, the whole Stage 3 W series and the subsequent UI increments are complete (W1 swap model → W2 local service → W3 editor front end → W4 docs and example → W5 project status panel → W6 artifact browsing → W7 scoped view → W8 snapshots / layered diff / registry browsing; the planner-interface increments are in UI facade (the data panel, W9, has landed). Example entry point: examples/web-smoke.sh (the same one CI runs). The roadmap and decisions for later UI increments are in UI facade.

Released under the Apache-2.0 license