Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Agent Note: Editor Spec design tokens, geometry and motion constants, and zero-literal enforcement

Status: implemented

## Problem

While [the Spec light/dark theme note](./2026-11-26-editor-spec-light-theme.md) established the embedded `spec_theme.yaml` file and WCAG 2.2 contrast table for `SpecPalette`, dozens of editor views, 2D/3D viewport overlays, gizmos, handles, and debug layers still hardcoded `core.RGB`/`core.RGBA` and hex color literals (including Tailwind slate/sky/emerald hues and duplicate local token tables). There was also no exported single source of truth for the Spec's typography, spacing, corner radius, height, and reduced-motion constants, no 3D axis tokens in `spec_theme.yaml`, and no automated test preventing new hardcoded UI color literals from creeping back into `packages/game/editor`.

## Decision

`packages/game/editor/spec_theme.yaml` and `packages/game/editor/spec_theme.go` are the sole source of UI color, type, spacing, shape, height, and motion tokens across the editor, enforced by both WCAG contrast tests and an AST-based zero-literal test.

### Key design choices

- **3D axis and interaction tokens in `spec_theme.yaml`**: Added `specAxisX` (`#FF6B6B` dark / `#C92A2A` light), `specAxisY` (`#4FD38A` dark / `#0D7A43` light), `specAxisZ` (`#3B7BFF` dark / `#1D5CE6` light) from `docs/design/editor/Viewport3D.dc.html`, plus `specPrimaryHover`, `specViewport3DGround`, and `specViewport3DGrid`, and exposed `HoverOverlay`/`ActiveOverlay` from `core.Palette.SurfaceHover`/`SurfacePressed`. All three 3D axis tokens are checked at `>= 3.0:1` against `Viewport` in `SpecContrastTable` for both dark and light appearances.
- **Exported Spec geometry, type, and motion constants**: Defined `SpecFont*` (Inter title `14/600`, body `12.5/400`, section `11/600` at `+6%` tracking, JetBrains Mono `11.5`), `SpecSpace4`–`SpecSpace24` (`4, 8, 12, 16, 24`), `SpecRadiusControl`/`Button`/`Card`/`Dialog` (`6, 8, 12, 18`), `SpecRowHeight`/`SpecMinHitSize`/`SpecButtonHeight`/`SpecButtonTallHeight`/`SpecHeaderHeight` (`28, 28, 30, 32, 44`), `SpecBorderWidth` (`1`), `SpecIconSize`/`SpecIconStrokeWidth` (`15, 1.8`), and `SpecMotionHover`/`Panel`/`Overlay`/`AgentPulse` (`120 ms, 180 ms, 240 ms, 1.6 s`). `SpecMotionDuration` and `SpecAgentPulseOpacity` turn off all motion (`0` duration, solid `1.0` opacity) under `Env.ReduceMotion()`.
- **Var-time theme loading**: `parsedSpecTheme`, `darkSpecPalette`, and `lightSpecPalette` are loaded by a package-level variable initializer (`loadSpecTheme()`) rather than `init()`, guaranteeing deterministic initialization order for package-level derived color variables across other files in `editor`.
- **Zero hardcoded UI color literals outside `spec_theme.go`**: Every non-test `.go` file in `packages/game/editor` (including `editormcp/`) replaces `core.RGB`/`core.RGBA` and UI hex literals with `SpecPalette` tokens, `specAlpha`, `CompositeOver`, or `colorFromRGBA8` (for dynamic raster asset pixels and heightmap layer RGB data). Scene content defaults (such as `BackgroundColor`, default 3D light/sky/fog colors, and hex text-field placeholders) remain scene data, not UI chrome. Side panels (`SceneTreeView`, `LayersView`, `AssetBrowserView`, `FilesView`, `LibraryView`) render in `panel` (`colors.Surface()`) with `line` dividers, and `InspectorView` inherits the root `SpecTheme()` / `Editor.SpecPalette(cx)` directly instead of overriding a dark-only subtree theme.
- **AST-enforced guardrail and WCAG mutation test**: `TestSpecNoHardcodedColorLiteralsInEditor` parses every non-test `.go` file under `packages/game/editor` (excluding `spec_theme.go`) with `go/parser` and fails on any `core.RGB`/`core.RGBA` call or hardcoded UI hex color literal. `TestSpecContrastTableRejectsRetiredMutedColor` verifies that mutating dark `textMuted`/`specTextFaint` back to `#6F7684` causes the contrast check to fail.
- **PR checklist and synchronized docs**: Added the Spec's "Acceptance for every editor PR" checklist to `.github/PULL_REQUEST_TEMPLATE.md` and documented the full design-token contract in both `docs/en/editor.md` and `docs/zh/editor.md`.

## Alternatives considered

- **Regex-only grep test instead of `go/parser` AST scanning**: rejected because regex scans produce false positives on non-color 64-bit PRNG constants (`splitmix64` in `tilebrush.go`) and scene content YAML defaults (`BackgroundColor`, sky/fog placeholders), whereas AST inspection accurately targets `core.RGB`/`core.RGBA` calls and color-typed expressions while keeping exemptions minimal and explicit.
- **Keeping separate Tailwind hues for 2D/3D debug overlays (physics, navmesh, rig, terrain, LOD)**: rejected because the Spec explicitly forbids off-board UI color literals in `packages/game/editor`, and mapping debug overlays onto `SpecPalette` roles (`Accent`, `Agent`, `Added`, `Changed`, `Removed`, `Warning`, `AxisX`/`Y`/`Z`) ensures visual consistency and WCAG-checked contrast in both dark and light modes.

## Consequences

- **Benefits**: Every editor chrome region, gizmo, overlay, and debug canvas now draws strictly from `spec_theme.yaml` with dark/light parity; CI automatically blocks accidental re-introduction of `core.RGB`/`core.RGBA` or retired contrast-failing colors; typography, spacing, radii, heights, and reduced-motion rules are codified as reusable exported constants.
- **Costs**: Adding any new semantic color to the editor requires adding a named token to both `dark` and `light` in `spec_theme.yaml`, wiring it into `SpecPalette`, and verifying it in `SpecContrastTable` rather than writing an inline hex literal.
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ Fixes #
## Screenshots

<!-- Attach screenshots or a short recording for website, example, or visual changes. -->

## Acceptance for every editor PR

<!-- Complete this checklist for any PR touching `packages/game/editor` (from `docs/design/editor/Spec.dc.html`). -->

- [ ] Real screenshots from `nsgotest` on macOS, before and after, beside the matching artboard.
- [ ] Uses only the tokens in `packages/game/editor/spec_theme.yaml` (`SpecPalette`), and every text pair is in the WCAG 2.2 contrast table.
- [ ] Every control shows the focus ring and is reachable with `Tab`, `F6`, or arrow keys.
- [ ] Every action has a shortcut row with a scope and a matching MCP tool (when applicable).
- [ ] Overlays follow the Spec line-style legend; nothing is told apart by hue alone.
- [ ] Reviewed by a person looking at the screenshots, not only by tests.
7 changes: 7 additions & 0 deletions changelog.d/editor-spec-design-tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- `game/editor`: added Spec typography, spacing, radius, height, border, and reduced-motion constants (`SpecFont*`, `SpecSpace*`, `SpecRadius*`, `SpecRowHeight`, `SpecButtonHeight`, `SpecHeaderHeight`, `SpecMotion*`, `SpecMotionDuration`, `SpecAgentPulseOpacity`), 3D axis tokens (`AxisX`, `AxisY`, `AxisZ`) from `Viewport3D.dc.html` in `spec_theme.yaml`, an AST test refusing `core.RGB`/`core.RGBA` and hardcoded UI hex color literals outside `spec_theme.go`, a Design tokens section in `docs/en/editor.md` and `docs/zh/editor.md`, and the Spec editor PR acceptance checklist in `.github/PULL_REQUEST_TEMPLATE.md` (#1002).

### Changed

- `game/editor`: replaced all hardcoded UI `core.RGB`/`core.RGBA` and hex color literals across the editor's panels, 2D/3D viewports, gizmos, handles, and debug overlays with `SpecPalette` tokens from `spec_theme.yaml`, and updated the toolbar scene title to Spec `14 / 600` (`SpecFontTitleSize`, `SpecFontTitleWeight`) (#1002).
20 changes: 18 additions & 2 deletions docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,6 @@ Draw session-only numbered annotations directly over the 2D viewport to point at
- **Sending a sketch to the agent (`SendSketch` / `Editor.OnSendSketch`)**: the composer attaches a `"Sketch · N marks"` context chip (clicking toggles a `"Sent with this request"` scene-coordinate preview). Sending delivers `SketchAgentRequest` with structured marks (`number`, `kind`, geometry in scene coordinates, `label`) and a rendered PNG of the viewport with numbered marks overlaid (`RenderSketchViewportPNG`).
- **Agent reading card & `scene_edit` confirmation hold**: sending a sketch arms a hold gate (`SketchHoldActive() == true`) that causes `scene_edit` and other mutating scene MCP tools to refuse edits until the person confirms. The agent reads marks via `sketch_read` and posts its restatement (`"I read your sketch as: …"` with numbered items and assumptions) via `sketch_reading` (`PostSketchReading`). Clicking **Go ahead** (`ApproveSketchReading`, `⌘↵`) releases the hold; clicking **Correct a mark** (`CorrectSketchMark`, `⇧M`, or clicking any numbered item) reopens sketch mode with that exact mark selected while keeping the hold active; replying in words (`ReplyToSketchReading`) works too.
- **Review overlay & Keep / Revert**: after approval, agent edits open a review card (`SketchReviewOpen`) with a **Sketch overlay** toggle (`O`, `ToggleSketchReviewOverlay`, also available in `TileReview`) that lays the faint dotted sketch over the result. **Keep** (`KeepSketchReview` / `KeepTileReview`) keeps the edits and clears the sketch layer; **Revert** (`RevertSketchReview` / `RevertAllTileReview`) undoes the edits while keeping the sketch marks intact to send again.

## Reference images in the agent composer and pinning to the brief (#1027)

Attach PNG, JPEG, or WebP reference images to a single agent request or pin them to the project's game brief, matching `docs/design/editor/Sketch.dc.html` (*Paste or drop an image*, *Pin to brief*) using exclusively `docs/design/editor/Spec.dc.html` tokens:
Expand All @@ -1564,7 +1563,6 @@ Every edit an agent makes through the editor's MCP server between the start and
- **Right-panel Agent tab & Summary Card (`RightRailView` / `AgentPanelView`)**: switch between **Agent** (`mod+1` / `CmdAgentTab`) and **Inspector** (`mod+2` / `CmdInspectorTab`) in the right panel header (showing a live pending indicator dot and MCP connection status). Styled exclusively with `Spec.dc.html` tokens matching `Main.dc.html` (localized in English and Chinese), the Agent panel displays the request bubble, progress steps, working **Stop (`⌘.`)** control, completion summary, the small summary card (`"6 changes · 1 file · +38 −0"`, grouped changes with per-change and per-file Revert/Restore, **Keep**, **Review**, **Revert**), Kept/Reverted notes (`"one undo step (⌘Z)"`), and the composer with `"Edits stay unsaved until you keep them"`.
- **Navigation, close, and boundary protection**: opening another scene (`RequestOpenScene`), switching scene tabs (`RequestSelectTab`), switching projects (`RequestOpenProject`), closing the window, or quitting with a pending turn prompts **Keep**, **Revert**, or **Cancel** (`pendingTurnDialog`), matching unsaved-changes behavior. Every staged file enforces project-root symlink containment, refuses `.git/**` and You-only files, enforces a 2 MiB per-file limit, and resets cleanly on `OpenProject` and `OpenDemo`.
- **MCP surface (`editormcp`)**: `turn_start`, `turn_end`, `turn_status` (read-only, reporting reverted changes), and `file_edit` (validating `game.yaml`, data tables, clips, prefabs, and scenes in memory) work alongside `scene_edit` and `object_set_field`'s `why` support. By design there is no MCP tool that keeps or reverts a turn.

## Agent panel failure, recovery, and offline states (#1024)

When an agent request does not simply succeed, `AgentPanelView` renders dedicated `docs/design/editor/AgentStates.dc.html` cards using exclusively `SpecPalette` tokens (both Dark and Light themes) while keeping every manual editing tool (Select, Move, Inspector, `CheckProblems`, and Play) working in every state:
Expand All @@ -1575,3 +1573,21 @@ When an agent request does not simply succeed, `AgentPanelView` renders dedicate
- **Stopped (`AgentStoppedState`)**: stopping a running turn records `DONE` and `NOT DONE` step sections, **Resume** (`ResumeAgentTurn`, which starts strictly at the first not-done step and skips steps already done), and **Review N changes**; completed changes stay unkept until explicitly reviewed and kept.
- **Mismatch (`AgentMismatchReport`)**: the editor automatically checks every turn summary against the actual diff (`CheckAgentSummaryAgainstDiff`) and displays a `WHAT · SUMMARY · REVIEW` table when they disagree, including the auto-derived reason when known (for example, an object added at step 3 and removed at step 5), **Ask why** (`AskAgentWhyMismatch`), and **Open review** (`OpenAgentTurnReview`). **Keep** always applies the actual review diff, never the prose summary.
- **Offline (`AgentStatusOffline`, `SetAgentOffline`)**: displays `"You're offline"` and queues submitted requests with timestamps (`AgentQueuedRequests`, `QueueAgentRequest`, `RemoveQueuedAgentRequest`) while Select, Move, the Inspector, game check, and Play keep working. Returning online never runs queued requests on its own; each queued request waits for an explicit **Send** (`SendQueuedAgentRequest`).

## Design tokens (#1002)

Every color, type size, spacing step, corner radius, height, and motion duration in the editor comes from the embedded YAML theme and constants defined in `packages/game/editor/spec_theme.yaml` and `packages/game/editor/spec_theme.go`, matching `docs/design/editor/Spec.dc.html` and `docs/design/editor/Viewport3D.dc.html`:

- **Embedded YAML theme (`spec_theme.yaml`, `SpecTheme`, `SpecPalette`)**: loaded with `core.ParseTheme` and attached on `EditorView`'s root scope via `cx.SetTheme(SpecTheme())`. Every NSGo `core.Palette` and `ui.ColorsOf` role (`Background`, `Surface`, `Raised`, `Line`, `Border`, `Text`, `TextMuted`, `Accent`, `AccentText`, `Success`, `Warning`, `Danger`, `Focus`) maps directly onto the Spec palette in both dark and light appearances, while `Editor.SpecPalette(cx)` (`DarkSpecPalette()`, `LightSpecPalette()`, `SpecPaletteFor(dark)`) exposes the additional Spec roles (`TextPrimary` / text strong, `TextSecondary` / text, `TextMuted` / text secondary, `TextFaint` / text muted, `OnTextPrimary`, `Viewport`, `ViewportDot`, `PillBg`, `HoverOverlay`, `ActiveOverlay`, `PrimaryHover`, `AccentHover`, `AccentPressed`, `Viewport3DGround`, `Viewport3DGrid`, `Accent`, `Agent`, `Added`, `Changed`, `Removed`/`Problem`, `Warning` with dedicated `Fill` and `Edge`, and 3D axis tokens `AxisX`, `AxisY`, `AxisZ`).
- **Dark palette tokens (`Spec.dc.html` & `Viewport3D.dc.html`)**:
- Surfaces & borders: `bg #101216`, `panel #12141A`, `raised #171A21`, `line #1F232A`, `line raised #262B35`, `viewport #15181D`, `viewportDot #2A2F38`.
- Text ladder: `text strong #FFFFFF`, `text #D9DDE5`, `text secondary #B4BAC6`, `text muted #8B92A0`. The retired `#6F7684`, `#5D6472`, and `#4A505C` are never used for text.
- Semantic roles: `accent #3B7BFF` (on-fill ink `#101216` at weight 600; `#FFFFFF` on dark accent or agent is never used), `agent #9B7BFF`, `added #4FD38A`, `changed #E9A84A`, `removed · problem #FF6B6B`, `warning #F2C14E` (on fill `#2A2414`, edge `#4A3F1F`).
- 3D axes (`Viewport3D.dc.html`): `axisX #FF6B6B`, `axisY #4FD38A`, `axisZ #3B7BFF` (with WCAG-passing light equivalents `#C92A2A`, `#0D7A43`, `#1D5CE6`).
- **Measured WCAG 2.2 contrast table (`SpecContrastTable`, `ContrastRatio`)**: `TestSpecContrastTableDarkAndLight` computes the WCAG 2.2 luminance contrast ratio of every foreground/background, on-fill, warning-card, pill, overlay, and 3D axis pair directly from `spec_theme.yaml` for both dark and light palettes, failing below `4.5:1` for text/on-fill or `3.0:1` for UI/overlay edges. A dedicated regression test verifies that reverting dark `text_muted` to `#6F7684` fails the check.
- **Type, spacing, shape, heights, and motion constants**:
- Type scale: Inter title `14 / 600` (`SpecFontTitleSize`, `SpecFontTitleWeight`), body `12.5 / 400` (`SpecFontBodySize`, `SpecFontBodyWeight`), section `11 / 600` at `+6%` tracking (`SpecFontSectionSize`, `SpecFontSectionWeight`, `SpecFontSectionTrack`), JetBrains Mono `11.5` (`SpecFontCodeSize`, `SpecFontFamilyMono`).
- Spacing: `4`, `8`, `12`, `16`, `24` px only (`SpecSpace4`–`SpecSpace24`).
- Radii & geometry: `6` controls (`SpecRadiusControl`), `8` buttons (`SpecRadiusButton`), `12` cards and toasts (`SpecRadiusCard`), `18` dialogs (`SpecRadiusDialog`); heights `28` rows/tool buttons (`SpecRowHeight`, minimum hit area `SpecMinHitSize = 28`), `30`–`32` buttons (`SpecButtonHeight`, `SpecButtonTallHeight`), `44` header (`SpecHeaderHeight`); `1` px inner borders (`SpecBorderWidth`).
- Motion: `120 ms` hover/press (`SpecMotionHover`), `180 ms` panels/popovers/toasts (`SpecMotionPanel`), `240 ms` agent overlays (`SpecMotionOverlay`), `1.6 s` agent pulse (`SpecMotionAgentPulse`, `100%` ↔ `45%` opacity). `SpecMotionDuration` and `SpecAgentPulseOpacity` disable all motion (`0` duration, solid `1.0` opacity) whenever `Env.ReduceMotion` is enabled.
- **No hardcoded UI color literals**: every non-test `.go` file in `packages/game/editor` outside `spec_theme.go` draws UI chrome, gizmos, overlays, and debug views exclusively from `SpecPalette` tokens (scene content data such as `scene.BackgroundColor` stays scene data). `TestSpecNoHardcodedColorLiteralsInEditor` scans the package AST and fails on any `core.RGB`/`core.RGBA` call or hardcoded UI hex color literal outside `spec_theme.go`.
Loading