Skip to content
Merged
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,40 @@
# Agent Note: AI-first editor main layout with scene rail, Agent/Inspector tabs, and status bar

Status: implemented

## Problem

The previous editor shell placed over twenty tool buttons, panel toggles, and secondary controls across a multi-group top toolbar and exposed docked Files, Assets, Layers, and Library panels by default. That layout left too little space for the viewport and the AI Agent workflow, lacked designed empty, loading, and scene-open error states (failing to open a missing or invalid scene left an ambiguous blank canvas), and mixed legacy control sizing and toggle semantics instead of the `docs/design/editor/Main.dc.html` and `docs/design/editor/Spec.dc.html` contract.

## Decision

The editor main window (`packages/game/editor/main_layout_ui.go`, `ui.go`, `agent_ui.go`, `overlays_ui.go`, `scenetree.go`) adopts the five-region AI-first chrome specified in `Main.dc.html` and `Spec.dc.html` while keeping every secondary editor view reachable via commands, menus, Settings, and the status bar.

### Layout and region contract

- **44 px header (`mainHeaderView`)**: `<project> / <scene>` breadcrumb with a scene File menu and unsaved dot (`Label: "unsaved changes"`), centered icon-only tool `base.RadioGroup` (`Select V`, `Move W`, `Rotate E`, `Scale R`, `Pan Space` using 1.8 px@15 px `currentColor` Lucide strokes with `"Label · key"` tooltips), `2D / 3D` segmented radio group, `History (⌘Y)` icon button, `Search ⌘K` Command Palette trigger, and `Play (⌘P)` as the single primary button.
- **232 px left rail (`leftRailSceneView`)**: `Scene / Assets` switch, `SCENE · N nodes` header, scene tree rows showing kind dots, kind tags, and `NEW` badges for pending-review proposed objects (`IsObjectProposedNew`), and a bottom `FILES` section listing the active scene, prefabs/instanced scenes referenced by the open scene (`SceneUsedPrefabs`), and `game.yaml`. Selecting a scene tree row switches the right rail to **Inspector**.
- **Viewport (`ViewportView`, `viewportCameraCaptionView`, `viewportOverlayBarView`)**: camera frame caption (`Camera · W × H`), bottom bar (`Zoom out`, zoom `%`, `Zoom in`, `Snap` `base.Switch` with `RoleSwitch`, `Fit`, `Overlays N`), and top-left overlay legend slot.
- **380 px right panel (`RightRailView`, `AgentPanelView`)**: `Agent` (`⌘1`) and `Inspector` (`⌘2`) radio tabs paired with the live MCP connection chip (`Connected · MCP` and all five states). The header uses `MinHeight: 44` with `Wrap: core.Wrap` so single-line states stay 44 px while the multi-button `Disconnected` state wraps cleanly without clipping inside the 380 px rail.
- **32 px status bar (`mainStatusBarView`)**: muted text on `bg` displaying the active layer button (toggling Layers), live 2D pointer coordinates (`SubscribePointer`), current tool, problem count pill (opening Problems), Output, and Debugger.
- **Keyboard and Spec controls**: builds directly on [focus rings and F6 regions](./2026-11-26-editor-focus-ring-and-regions.md) and [Spec light/dark theme](./2026-11-26-editor-spec-light-theme.md). Every interactive button/radio/switch keeps a hit area of at least `28 × 28`, accessible names, and 2 px Spec focus rings. `bindShortcuts` deliberately skips registering a root-scope `"space"` key listener for `CmdToolPan` because `viewport.go` handles Space-hold panning via `core.KeyHeld(cx, "space")` and a root `"space"` handler would intercept Space before focused buttons, switches, and radios can activate.

### Workspace states

`Editor.WorkspaceState()` classifies the workspace into `WorkspaceReady`, `WorkspaceNoProject`, `WorkspaceNoScene`, `WorkspaceLoading` (`SetProjectLoading`), and `WorkspaceSceneError` (`SceneOpenError`, `RetryOpenScene`, `ClearSceneOpenError`). `OpenFile` and `OpenScene` record structured `*loaderr.Error` metadata (file path, line, column, problem, fix) on failure so the left rail, viewport (`RoleAlert` card with Retry and Dismiss), inspector, and status bar render designed recovery states instead of a blank viewport.

## Alternatives considered

- **Keeping all secondary panel buttons in a collapsible overflow toolbar**: rejected because the design contract reserves the 44 px header exclusively for breadcrumb, core manipulation tools, 2D/3D, History, Search, and Play; Command Palette (`⌘K`), Menu bar, Settings, and Status bar already provide keyboard-first discovery for every secondary panel (`CmdLayersPanel`, `CmdFileBrowser`, `CmdAssetBrowser`, `CmdLibraryPanel`, `CmdAudioMixer`, `CmdInputMap`, `CmdLocalization`, `CmdExport`, `CmdDataTable`, `CmdSearchPanel`, `CmdAnimate`, `CmdParticleEditor`, `CmdMaterialEditor`, `CmdHUDLayout`, `CmdTerrainEditor`, `CmdNavMeshPanel`).
- **Binding `CmdToolPan`'s `"space"` shortcut via `cx.OnKeyWith("space", ...)` in `bindShortcuts`**: rejected because NSGo root-scope key bindings run ahead of focused button/switch/radio Space activation, breaking keyboard accessibility across panels. Keeping `"space"` on `CmdToolPan` for tooltip/shortcut display while handling Space-hold in `viewport.go` satisfies both panning and keyboard activation.
- **Hardcoding a fixed `Height: 44` without wrap on `right-rail-header`**: rejected because `AgentStatusDisconnected` renders `Disconnected`, `Reconnect`, and `Troubleshoot` beside the `Agent` and `Inspector` tabs, overflowing 380 px when wrapping is disabled.

## Consequences

- **Benefits**:
- Clean AI-first chrome matching `Main.dc.html` and `Spec.dc.html` in both Dark and Light appearances at `1440 × 900`.
- Missing or malformed scene files present an actionable alert card with path, line, fix hint, Retry, and Dismiss instead of a blank viewport.
- All five `F6` regions, radio groups, switches, and `>= 28 × 28` hit targets work consistently with keyboard navigation.
- **Costs**:
- Tests and muscle memory that previously clicked legacy top-toolbar panel toggles now invoke the corresponding commands (`CmdSave`, `CmdUndo`, `CmdAudioMixer`, etc.) or status-bar/drawer controls.
- Legacy helper functions still referenced only by dead code paths should be pruned once no remaining callers depend on them.
3 changes: 3 additions & 0 deletions changelog.d/editor-ai-first-main-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- `game/editor`: replace the legacy toolbar shell with the AI-first main layout featuring a 44 px header (breadcrumb with unsaved dot, Select/Move/Rotate/Scale/Pan tool radio group, 2D/3D segmented radio, History, Search ⌘K, and Play), 232 px left rail (`SCENE · N nodes` with kind dots, `NEW` review tags, and bottom `FILES` list), viewport camera caption and bottom bar (`Snap` switch, zoom, Fit, Overlays), 380 px right panel (`Agent`/`Inspector` tabs with MCP connection chip), 32 px muted status bar (active layer, pointer coords, tool, Problems, Output, Debugger), and designed empty/loading/scene-error states across all regions (#1007).
12 changes: 12 additions & 0 deletions docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1602,3 +1602,15 @@ Inside the unified right-rail **Agent** tab (`RightRailView` / `AgentPanelView`,
- **Context chips and exact hover preview**: above the composer, attached chips show what joins the request (removable by clicking `×` via `RemoveComposerChip` or pressing `⌫` in an empty composer via `RemoveLastComposerChip`), **Always** chips show `brief.yaml` and `AGENTS.md` when present in the project root, and **Viewport image** is a toggleable chip (`SetViewportImageIncluded` / `ToggleViewportImage`). Selecting an object in the viewport or scene tree only surfaces a dashed `+ <Name> · selected` suggestion chip (`SuggestedChip`)—nothing joins the request unless explicitly added (`AcceptSuggestedChip`). `TriggerAskAgentShortcut` attaches the selected object or, when nothing is selected, the whole open scene (`AttachWholeSceneChip`) and focuses the composer. Hovering any chip (`SetHoveredChip` / `HoveredChipPayload`) displays the exact header (`# level_01.scene.yaml · lines 72–78`) and YAML text or image bytes resolved by `ResolveChipPayload`.
- **Single-source request assembly**: `AssembleAgentRequest` builds `AgentRequest` from the active chips and nothing else—calling the exact same `ResolveChipPayload` function used on hover—and feeds both `SendComposerPrompt` (`Editor.OnSendAgentComposerRequest`) and `SubmitAgentPrompt` (`Editor.AgentRunner`).
- **Context meter ring, breakdown, Compact, and Start fresh**: a 20×20 circular progress ring reflects reported token usage (`SetAgentTokenUsage` or `AgentResponse.Usage`) across three Spec states (normal `≤ 70%`, amber warning `71–89%`, and critical `≥ 90%` `"compact now"`). Clicking the ring opens a 6-row breakdown (**Conversation**, **Open scene**, **Attached**, **Always**, **Tools and instructions**, **Viewport image**) with **Compact thread** (`CompactAgentThread`, folding earlier requests into a summary while keeping the last request whole and dropping the ring) and **Start fresh with summary** (`StartFreshAgentThread`, opening a new thread seeded with that summary).

## AI-first main layout (#1007)

The editor's main window (`main_layout_ui.go`, `ui.go`, `agent_ui.go`, `overlays_ui.go`, `scenetree.go`) implements the AI-first workspace from `docs/design/editor/Main.dc.html` using exclusively `docs/design/editor/Spec.dc.html` tokens, sizing, and accessible controls:

- **44 px header (`mainHeaderView`)**: displays the `<project> / <scene>` breadcrumb (`ProjectDisplayName`, `SceneBreadcrumbName`) with a Scene file menu and unsaved dot (`aria-label: "unsaved changes"` / `"save failed"`), a centered tool `base.RadioGroup` (`Select V`, `Move W`, `Rotate E`, `Scale R`, `Pan Space` as icon-only Lucide 1.8 px@15 px `currentColor` icons with `"Label · key"` tooltips), a `2D / 3D` segmented radio group, `History (⌘Y)` icon button, `Search ⌘K` palette button, and `Play (⌘P)` as the single primary button.
- **232 px left rail (`leftRailSceneView`)**: combines the `Scene / Assets` switcher with `SCENE · N nodes` (`SceneNodeCount`), scene tree rows carrying kind color dots (`ObjectKindColor`), kind tags (`SceneRailObjectKind`, `LayerKindLabel`), and `NEW` badges on pending-review proposed objects (`IsObjectProposedNew`, `SetProposedNewObjectIDs`), and a bottom `FILES` section listing the open scene, prefabs/instanced scenes it uses (`SceneUsedPrefabs`), and `game.yaml`. Picking a scene tree row switches the right rail to **Inspector**.
- **Viewport caption, bottom bar, and overlay legend**: draws the `Camera · W × H` caption above the 2D camera frame (`viewportCameraCaptionView`), the bottom bar (`Zoom out`, zoom `%`, `Zoom in`, `Snap` as a `base.Switch` with `RoleSwitch` / `aria-checked`, `Fit`, and `Overlays N`), and the top-left overlay legend slot.
- **380 px right panel (`RightRailView`)**: hosts the `Agent` (`⌘1`) and `Inspector` (`⌘2`) radio tabs alongside the thread History toggle and live agent connection chip (`Connected · MCP`, `Working`, `Waiting for you`, `Reconnecting`, `Disconnected`); choosing a tree row switches directly to **Inspector**.
- **32 px status bar (`mainStatusBarView`)**: renders muted text on `bg` with the active layer button (toggling Layers), live 2D pointer coordinates, current tool readout, problem count pill (opening Problems), Output, and Debugger. Secondary views previously hosted on the old toolbar (Settings, Audio Mixer, Input Map, Localization/Strings, Export, Library, Data Table, Project Search, Files, Assets, Animation, Particles, Material, HUD Layout, Terrain, NavMesh) remain reachable through the Command Palette (`⌘K`), Menu bar, Settings, and Status bar.
- **Designed empty, loading, and error states (`WorkspaceState`, `SceneOpenError`)**: every region renders a dedicated state for `WorkspaceNoProject`, `WorkspaceNoScene`, `WorkspaceLoading` (`SetProjectLoading`), and `WorkspaceSceneError` (`SceneOpenError`, `RetryOpenScene`, `ClearSceneOpenError`). Opening a missing or malformed scene YAML renders an alert card with file path, line/column, message, fix guidance, **Retry**, and **Dismiss** instead of a blank viewport.
- **Spec controls and keyboard navigation**: preserves Spec heights (`28 px` rows/tool buttons, `30–32 px` buttons, `44 px` header, `32 px` status bar, no interactive hit area under `28 × 28`), spacing (`4 / 8 / 12 / 16 / 24`), radii (`6 / 8`), `base.RadioGroup` / `base.Radio` and `base.Switch` semantics, 2 px Spec focus rings, accessible names, and `F6` cycling across all five regions (`Header`, `Scene tree`, `Viewport`, `Agent / Inspector`, `Status bar`).
12 changes: 12 additions & 0 deletions docs/zh/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1602,3 +1602,15 @@ func main() {
- **上下文标签与精确悬停预览**:输入框上方依次展示已附加标签(点击 `×` 通过 `RemoveComposerChip` 移除,或在空输入框中按 `⌫` 通过 `RemoveLastComposerChip` 移除)、**始终附加**标签(项目根目录中的 `brief.yaml` 与 `AGENTS.md`)以及可开关的 **视口图像** 标签(`SetViewportImageIncluded` / `ToggleViewportImage`)。在视口或场景树中选中对象只会显示虚线建议标签 `+ <名称> · 已选中`(`SuggestedChip`),除非主动添加(`AcceptSuggestedChip`),否则绝不会随请求发送;`TriggerAskAgentShortcut` 会在选中对象时附加该对象,未选中任何对象时附加整个打开的场景(`AttachWholeSceneChip`)并聚焦输入框。悬停任意标签(`SetHoveredChip` / `HoveredChipPayload`)都会通过 `ResolveChipPayload` 显示实际发送的精确头部(如 `# level_01.scene.yaml · lines 72–78`)及对应的 YAML 文本或图像。
- **单一数据源的请求组装**:`AssembleAgentRequest` 仅从当前生效的标签组装 `AgentRequest`(调用与悬停预览完全相同的 `ResolveChipPayload`),并统一供 `SendComposerPrompt`(`Editor.OnSendAgentComposerRequest`)与 `SubmitAgentPrompt`(`Editor.AgentRunner`)使用。
- **上下文计量环、明细、压缩与新开线程**:20×20 环形进度指示器根据智能体回报的 token 用量(`SetAgentTokenUsage` 或 `AgentResponse.Usage`)呈现三种规范状态(正常 `≤ 70%`、超过 70% 警告 `71–89%`、以及 `≥ 90%` 的“立即压缩”状态)。点击计量环可展开 6 项明细(**Conversation**、**Open scene**、**Attached**、**Always**、**Tools and instructions**、**Viewport image**),并提供 **压缩线程**(`CompactAgentThread`,将较早请求折叠为摘要并完整保留最后一条请求,同时降低计量环占比)与 **使用摘要新开**(`StartFreshAgentThread`,以该摘要启动新线程)。

## AI 优先的主界面布局(#1007)

编辑器主窗口(`main_layout_ui.go`、`ui.go`、`agent_ui.go`、`overlays_ui.go`、`scenetree.go`)按 `docs/design/editor/Main.dc.html` 实现 AI 优先工作区,并严格使用 `docs/design/editor/Spec.dc.html` 的颜色令牌、尺寸比例与无障碍控件:

- **44 px 顶部栏(`mainHeaderView`)**:左侧展示 `<项目> / <场景>` 面包屑(`ProjectDisplayName`、`SceneBreadcrumbName`)、场景文件菜单及未保存圆点(`aria-label` 为 `"unsaved changes"` / `"save failed"`);居中放置工具单选组(`Select V`、`Move W`、`Rotate E`、`Scale R`、`Pan Space`,纯图标 1.8 px@15 px `currentColor` Lucide 图标,悬停提示 `"名称 · 快捷键"`)与 `2D / 3D` 分段单选组;右侧为 `History (⌘Y)` 图标按钮、`Search ⌘K` 命令面板按钮,以及唯一主按钮 `Play (⌘P)`。
- **232 px 左侧栏(`leftRailSceneView`)**:包含 `Scene / Assets` 切换与 `SCENE · N nodes`(`SceneNodeCount`)标题、带类型色点(`ObjectKindColor`)、类型标签(`SceneRailObjectKind`、`LayerKindLabel`)以及待审查新增对象 `NEW` 标记(`IsObjectProposedNew`、`SetProposedNewObjectIDs`)的场景树行;底部 `FILES` 区域列出当前打开的场景、场景引用的预制体/实例场景(`SceneUsedPrefabs`)以及 `game.yaml`。选中场景树中的节点会自动将右侧栏切换至**检视器(Inspector)**。
- **视口标题、底部控制条与叠加层图例**:在 2D 相机框上方显示 `Camera · W × H` 标题(`viewportCameraCaptionView`),底部提供缩放控制(缩小、百分比、放大)、`Snap` 开关(`base.Switch`,`RoleSwitch` / `aria-checked`)、`Fit` 与 `Overlays N`,并在左上角保留叠加层图例槽位。
- **380 px 右侧面板(`RightRailView`)**:承载 `Agent`(`⌘1`)与 `Inspector`(`⌘2`)单选标签、线程历史记录切换按钮及实时连接状态胶囊(`Connected · MCP`、`Working`、`Waiting for you`、`Reconnecting`、`Disconnected`);点击场景树行会自动切到 **Inspector**。
- **32 px 状态栏(`mainStatusBarView`)**:在 `bg` 表面以弱化文本呈现左侧的活动图层按钮(可切换图层面板)、实时 2D 指针坐标与当前工具,以及右侧的问题数胶囊(打开问题面板)、输出(Output)与调试器(Debugger)。原工具栏中的其余面板(设置、混音器、输入映射、多语言、导出、资源库、数据表、项目搜索、文件、资源、动画、粒子、材质、HUD 布局、地形、导航网格)全部保留,可通过命令面板(`⌘K`)、菜单栏、设置窗口与状态栏访问。
- **空状态、加载状态与错误状态(`WorkspaceState`、`SceneOpenError`)**:各区域均为 `WorkspaceNoProject`、`WorkspaceNoScene`、`WorkspaceLoading`(`SetProjectLoading`)和 `WorkspaceSceneError`(`SceneOpenError`、`RetryOpenScene`、`ClearSceneOpenError`)提供专门的界面状态。打开缺失或 YAML 格式错误的场景文件时,视口会展示带有路径、行/列号、错误描述、修复建议、**重试**和**关闭**按钮的告警卡片,而非空白视口。
- **规范控件与键盘可达性**:遵循 Spec 尺寸(行与工具按钮 `28 px`、按钮 `30–32 px`、顶部栏 `44 px`、状态栏 `32 px`,无小于 `28 × 28` 的交互热区)、间距(`4 / 8 / 12 / 16 / 24`)、圆角(`6 / 8`)、`base.RadioGroup` / `base.Radio` 与 `base.Switch` 语义、2 px Spec 焦点环、完整无障碍名称,以及覆盖全部五个区域的 `F6` 循环导航(顶部栏、场景树、视口、智能体/检视器、状态栏)。
6 changes: 4 additions & 2 deletions examples/fieldmedic/healthplugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func TestPluginAddsTheWardPanelTheInspectorAndTheAdmitTool(t *testing.T) {
if ed.History.Index() != undos+1 || ed.History.UndoLabel() != "Heal All" {
t.Fatalf("Heal All added %d steps, labeled %q", ed.History.Index()-undos, ed.History.UndoLabel())
}
app.Press("id:toolbar-undo")
app.Post(func() { ed.Undo() })
app.Settle()
if got, want := app.Find("id:health-ward").Text, "ada 8/10\nbram 9/12\ncleo 9/10\ndov 4/8"; got != want {
t.Fatalf("Ward panel after Undo = %q, want %q", got, want)
}
Expand All @@ -147,7 +148,8 @@ func TestPluginAddsTheWardPanelTheInspectorAndTheAdmitTool(t *testing.T) {
if wx, wy := ed.CanvasToWorld(120, 80); admitted.X != wx || admitted.Y != wy || hp(ed, admitted.ID) != healthplugin.AdmitHP {
t.Fatalf("admitted %+v, want at (%v, %v) with %d hp", admitted, wx, wy, healthplugin.AdmitHP)
}
app.Press("id:toolbar-undo")
app.Post(func() { ed.Undo() })
app.Settle()
if got := health.Objects(ed.Doc); len(got) != 4 {
t.Fatalf("Undo left the admitted patient: %v", got)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/game/cmd/game/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestGameMCPEditsTheOpenEditor(t *testing.T) {
}
app.Screenshot("editormcp/placed-by-agent")

app.Press("id:toolbar-undo")
app.Post(func() { ed.Undo() })
app.Settle()
if app.Exists("id:scene-tree-label-slime_1") {
t.Fatal("Undo left the object in the scene tree")
Expand Down
1 change: 1 addition & 0 deletions packages/game/editor/agent_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
// AgentReviewChange is one non-deletion file change listed in the Review changes panel.
type AgentReviewChange struct {
ID string `json:"id"`
ObjectID string `json:"object_id,omitempty"`
Path string `json:"path"`
Kind AgentReviewChangeKind `json:"kind"`
Title string `json:"title"`
Expand Down
1 change: 1 addition & 0 deletions packages/game/editor/agent_turn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestAgentTurnPendingPromptsGuardNavigation(t *testing.T) {
}

// Opening another scene from the file browser with a pending turn must prompt Keep / Revert / Cancel!
openFileBrowserInUI(app, ed)
app.DoublePress("id:files-row-scenes/other.scene.yaml")
app.Settle()
if !ed.PendingTurnPromptOpen() || !app.Exists("id:pending-turn-dialog") {
Expand Down
Loading
Loading