Skip to content

0020. Editor workspaces, version history, previews and the bring-your-own-key assistant

  • Status: Accepted 2026-11-28 (Phase 3b-1; owner decisions 2026-11-27: split 3b, run AI-written code in the offline sandbox, Claude first)
  • Date: 2026-11-28
  • Phase: 3

Phase 3b-1 adds the web editor: a game’s files live on the platform with history (commits, undo, branches), can be edited with schema checks, previewed live and changed by an AI assistant that uses the creator’s own key. Game code written by people or by the AI must never run in the web server, and keys must never leak.

  • Workspaces are content-addressed. File contents are stored once in blob storage under objects/<hash> (SHA-256). A commit is an immutable snapshot {path → hash} with a parent, a message and an author kind (human or ai). A branch has a head commit and an editable draft (also a path → hash map), so saving does not create commits and nothing is lost between commits. main always exists; other branches start at any commit.
    • Undo is “restore”: a commit’s files become the draft and are committed as Restored "…". History is never rewritten, so an undo can itself be undone.
    • Saving checks paths (the same allow-list as uploads), sizes and every JSON document against its schema; with errors nothing is saved (422 with JSON pointers). The answer lists project-wide issues (cross-references).
    • A workspace starts from a starter template or from the latest uploaded version. Uploads keep working.
  • Previews are versions of kind preview built by the same pipeline as releases, never live, numbered 0 and pruned to the 3 newest per game. Their play URL is unguessable (random version id) and served by the play origin like any build; the editor talks to the preview over the play bridge with in-memory saves (never cloud saves).
  • Releasing builds a commit (committing the draft first when needed) as the next numbered version; versions record the commit they came from.
  • The assistant runs the existing agent tools (ADR 0013) over a scratch copy of the branch draft (games/<slug>/ in a temporary folder), with the tools for listing/creating games and screenshots removed. File tools stay confined to that folder. run_headless and type-checks go through the sandbox runner: in Docker the no-network builder container (shared /work folder, now also mounted by the web container), in local mode limited child processes without secrets. Agent runs never import game code in the server process.
    • Before a run, unsaved edits are committed (Saved before the assistant ran); the result becomes one commit authored by the AI, so one restore undoes it. If the branch changed during the run, the result goes to a new branch ai-… instead of overwriting.
    • One run per game at a time; runs execute in the web process in the background and stream events over server-sent events; events (text, tool calls and results, cut to 4 KB) are stored with the run. A server restart marks unfinished runs failed.
    • Models offered: Claude Opus 5.5 (default), Sonnet 5.5, Haiku 5.5 through the official SDK, adaptive thinking. Usage of every response is recorded per user and game (ai_usage), for the metering hook of ADR 0013.
  • Bring your own key. A creator stores an Anthropic key on /account. Keys are encrypted with AES-256-GCM under PLATFORM_MASTER_KEY (local mode generates .cache/master.key), bound to user:provider as additional data, shown only as a hint (…abcd) and never returned. They are decrypted only to start a run.
  • Test assistant. In local mode (or when an operator sets PLATFORM_AI_TEST_PROVIDER=scripted; not for production) creators without a key get a scripted assistant that calls no model, so the whole flow can be tried and tested for free.
  • Editor UI: Monaco (ADR 0009) bundled with the app and loaded only on the editor page; JSON files are checked against the generated JSON Schemas as you type, TypeScript gets syntax checks (the full type-check runs in the sandbox). Workers are bundled files on the platform origin, so the CSP needs no blob: or eval.
  • Collaboration (several people editing one game at once) is not in 3b-1; it belongs with the community features.

Follow-ups (2026-11-28, filling the 3b-1 gaps)

Section titled “Follow-ups (2026-11-28, filling the 3b-1 gaps)”
  • Garbage collection. Every WORKSPACE_GC_HOURS (default 6) the web server deletes objects/… that no commit or branch draft refers to and that were written more than a day ago. Storing content always rewrites it, so reused content has a fresh time; objects are listed before references are read and listed again before deleting.
  • Merging branches. POST …/workspace/merge merges three ways against the nearest common ancestor (merge commits record a second parent, merge_parent_id). One-sided changes apply; text changed on both sides is merged line by line (diff3) when the changes do not overlap and JSON still parses; other files are conflicts the user settles per file (ours / theirs). Unsaved drafts are committed first; the merge is one commit.
  • Master-key rotation. PLATFORM_MASTER_KEY_PREVIOUS holds old keys: stored keys are re-encrypted under the new key at startup and on use. A key no master key opens asks the user to enter it again instead of failing the run.
  • Builder concurrency. The builder runs BUILDER_CONCURRENCY jobs at once (default 2; claiming is an atomic rename), so assistant checks no longer wait for a whole build. Per-task containers remain Phase 7.
  • Runs and restarts. Runs still live in the web process (a restart marks them failed); the editor offers Ask again with the same prompt. Durable runs on the job queue come with several web instances (Phase 7).
  • The assistant’s default stays Claude Opus 5.5 (owner, 2026-11-28); the editor remembers each user’s model choice.