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,30 @@
# Agent Note: Live agent edit overlays, scene tree markers, read-only step lock, and interactive legend (#1013)

Status: implemented

## Problem

When an AI agent edits an open scene through `editormcp`, the scene changes landed immediately on `Editor.Doc` with no visual distinction in the viewport or scene tree between objects the agent added, changed, removed, or is actively working on. Users could also accidentally drag or edit the exact object an agent step was mutating mid-turn, had no interactive way to filter live overlay categories, and had no header indicator showing whether the agent was actively working, waiting for input, or awaiting Keep/Revert review.

## Decision

Add a self-contained pending agent turn, step-lock, and live overlay subsystem on `Editor` (`packages/game/editor/agent_live.go` and `agent_live_ui.go`), wire `editormcp` mutations and checks into it automatically, and upgrade the Spec top-left overlay legend (`spec_feedback_ui.go`) into interactive per-user switches persisted in `EditorSettings`.

### Key design choices

- **Structural baseline diff on pending turns (`BeginAgentTurn`, `KeepAgentTurn`, `RevertAgentTurn`)**: Opening a turn snapshots a deep clone of `e.Doc` plus a `sceneformat.Build` baseline and records `History.Index()`. After every `afterMutate()`, `syncAgentTurnAfterMutate` diffs baseline vs current objects deterministically to compute `Added`, `Changed` (with `"<field> <old> → <new>"` diffs synced into `e.inspectorReviewChanges`), and `Removed` (preserving `RemovedDoc` and pre-turn layer/parent placement so viewport ghosts and struck-through `DEL` scene tree rows render in place). `KeepAgentTurn` collapses the turn's `History` commands into a single `groupCmd` undo step and clears overlays; `RevertAgentTurn` undoes back to `historyStart` and clears overlays. Tab switches preserve the active `agentTurn` on `sceneTab`.
- **Inspectable overlay list shared by rendering and tests (`ViewportLiveOverlays`, `VisibleViewportLiveOverlays`)**: Both 2D (`drawAgentLiveOverlays`) and 3D (`drawAgentLiveOverlays3D`) viewports render directly from `VisibleViewportLiveOverlays()`, using only `SpecPalette` tokens (`Added`, `Changed`, `Removed`, `Agent`, `Problem`, `PillBg`, `TextSecondary`) and tracking placed pill rectangles (`resolvePillRect`) so adjacent or stacked pills never overlap. When an object is both selected and actively touched by the agent, Selection keeps its 2D/3D handles (`OutsetPx: 0`) and Agent working renders 3 px further out (`OutsetPx: 6`). Reduced motion (`cx.Env().ReduceMotion()` or `SetReducedMotionOverride`) holds the violet outline solid at 100% instead of running the 1.6 s pulse loop.
- **Step-scoped read-only lock (`BeginAgentStep`, `EndAgentStep`, `ErrAgentTouchingObject`)**: Manual edits are allowed on untouched objects while the agent works, but any manual mutation targeting a currently touched object (2D/3D gizmo drags, shape/handle drags, `MoveObject`/`RotateObject`/`ScaleObject`/`SetObject*`/`DeleteObject`, `BeginInspectorScrub`, inspector fields/banner, scene tree rename/reparent, and object context menu) returns `ErrAgentTouchingObject`. Calls wrapped in `Editor.RunAsAgent` (used by `editormcp`'s `asAgent`) bypass the lock so the agent itself can keep mutating the object until `EndAgentStep` releases it.
- **Per-user legend persistence in `EditorSettings` (`hiddenOverlayKinds`)**: Rather than mutating scene or project YAML, toggling any of the six legend rows (`selection`, `agent`, `added`, `changed`, `removed`, `problem`) updates `EditorSettings.HiddenOverlayKinds` in `editor.yaml` (strictly validated against the canonical kind set, sorted deterministically, round-trip tested, and reflected in `apps/website/public/schemas/editor-settings.v1.json`). The top-left legend appears automatically whenever `HasAgentLiveOverlays()` or `OverlayLegendOpen()` is true.
- **Camera-never-moves invariant and header pill**: Neither `editormcp` nor `Editor`'s agent turn/step APIs touch `View2D` or `Camera3D`. The toolbar header pill (`toolbarAgentPillView`) reflects `AgentStateWorking` (`"Agent is <activity> · manual edits stay available"`), `AgentStateWaiting`, and `AgentStatePendingReview` (with `Keep` and `Revert` buttons), and hides when `AgentStateIdle`.

## Alternatives considered

- **Waiting for a separate agent-panel turn runner before implementing live viewport/tree state**: rejected because issue #1013 explicitly scopes live viewport overlays, scene tree badges, header pill, interactive legend, and MCP step tracking independently of the Agent panel's step list and permission cards. Exposing clean `BeginAgentTurn`/`KeepAgentTurn`/`RevertAgentTurn`/`BeginAgentStep`/`EndAgentStep`/`SetAgentState` hooks on `Editor` and `editormcp.Server` lets the future Agent panel plug straight in without rewriting overlays or tree rows.
- **Blocking all manual edits globally while the agent works**: rejected because `docs/design/editor/Working.dc.html` explicitly promises `"manual edits stay available"` and only the specific object(s) the agent's current step is touching should be read-only.
- **Storing overlay legend toggles in `.scene.yaml` or `game.yaml`**: rejected because visibility filters are personal workspace preferences, matching how `viewportOverlays` is stored in `EditorSettings` (`editor.yaml`) outside the project.

## Consequences

- **Benefits**: Authors immediately see every added, changed, removed, and actively-edited object live in both the 2D/3D viewport and scene tree, can keep editing untouched objects safely, can filter any overlay kind per-user, and can Keep (one undo step) or Revert directly from the header pill.
- **Costs**: `afterMutate()` performs a lightweight object-list diff while an agent turn is pending (no overhead when idle), and any future object-mutation entry point added to `Editor` should call `e.checkAgentTouchLock(id)` so the step read-only invariant stays airtight.
7 changes: 7 additions & 0 deletions apps/website/public/schemas/editor-settings.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
"type": "string"
}
},
"hiddenOverlayKinds": {
"description": "HiddenOverlayKinds lists Spec overlay legend kinds toggled off by the user (\"selection\", \"agent\", \"added\", \"changed\", \"removed\", \"problem\") in canonical sorted order.",
"type": "array",
"items": {
"type": "string"
}
},
"shortcuts": {
"description": "Shortcuts overrides default command shortcuts keyed by command ID (for example \"view.frame\": \"g\"). An empty string explicitly unbinds a command.",
"type": "object",
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/editor-agent-live-edits-1013.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added
- Editor viewport live agent overlays for pending turns: 1.5 px dashed Added (`+ name`) and Changed (`field old → new`) outlines, 25% grey ghost with 1.5 px solid Removed (`name removed` struck through) outline, pulsing 1.5 px violet Agent working outline (solid under reduced motion, 3 px outer offset when coexisting with Selection), Problem outlines, and automatic pill collision avoidance in both 2D and 3D viewports (#1013).
- Scene tree live agent markers (`NEW`, `MOD`, struck-through `DEL` ghost rows, and violet agent-working dot), header state pill (`Working`, `Waiting`, and `Pending review` with `Keep`/`Revert`), and step-scoped read-only lock (`ErrAgentTouchingObject`) with inspector read-only banner while `editormcp` touches an object (#1013).
- Interactive top-left Spec Overlay Legend toggles (`Selection`, `Agent working`, `Added`, `Changed`, `Removed`, `Problem`) persisted per-user in `EditorSettings.HiddenOverlayKinds` (`editor.yaml` / `editor-settings.v1.json`) without moving the viewport camera on the agent's behalf (#1013).
16 changes: 16 additions & 0 deletions docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1468,3 +1468,19 @@ Agent tasks (both background tasks managed via `tasks.go` / #1022 and foreground
- **Click opens the task in its scene**: `cx.OnNotificationPress` (delegating to `Editor.HandleNotificationPress` / `Editor.OpenAgentTask`) brings the editor window to the front (also calling `Editor.OnFocusWindow` when set), stops Play if running, dismisses obstructing panels (Settings, History, Problem agent panel, Ask-in-place, Assets mode), switches to or safely opens the task's scene tab strictly confined inside the project root (refusing traversal and symlink escapes), opens the Tasks or Agent panel, and focuses the task and any open request card.
- **Dock badge (`cx.SetBadge`)**: `Editor.AgentDockBadgeCount` counts waiting (`TaskNeedsYou`), ready to review (`TaskReadyToReview`), and failed (`TaskFailed`) tasks (`AgentTaskCounts.BadgeCount()`); running and queued tasks never add to the badge, and `0` clears it (including on scope cleanup).
- **Play-mode corner dot and deferred notifications (`PlayTaskDotView`)**: while Play mode is active (`Editor.Playing()`), agent task notifications do not pop over the running game and are held (`Editor.HeldAgentNotifications`) until `Editor.Stop()` flushes any tasks still needing attention. A single 8 pt dot with a 3 pt halo stays stably mounted in the top-right corner of the viewport in the Spec color of the most urgent state (**Failed** `Removed.Fg` > **Waiting** `Warning.Fg` > **Ready to review** `Accent.Fg`), revealing its label pill (such as `"1 task needs you · stop Play to open"`) only on hover or keyboard focus.

## Live agent edits in the viewport and scene tree (#1013)

While an agent edits a scene through `editormcp` or an active agent turn (`Editor.BeginAgentTurn` / `Editor.RunAsAgent`), the editor shows its pending changes live in both the viewport and scene tree (`docs/design/editor/Working.dc.html`, `Main.dc.html`, and `Spec.dc.html`) without ever moving the 2D or 3D viewport camera on the agent's behalf:

- **Live viewport overlays (`ViewportLiveOverlays` / `VisibleViewportLiveOverlays`)**:
- **Added**: 1.5 px dashed green outline (`SpecPalette.Added`) and `"+ <name>"` mono pill.
- **Changed**: 1.5 px dashed amber outline (`SpecPalette.Changed`) and `"<field> <old> → <new>"` mono pill (also synced into the Inspector's amber review markers).
- **Removed**: 25% grey ghost at the object's pre-turn bounds, 1.5 px solid red outline (`SpecPalette.Removed`), and a `"<name> removed"` pill with the object's name struck through.
- **Agent working**: 1.5 px solid pulsing violet outline (`SpecPalette.Agent`, 1.6 s pulse between 45% and 100% opacity, held solid at 100% under reduced motion) with no resize handles and a pill carrying the violet sparkle glyph and activity text (for example `playing level_01 headless`).
- **Problem**: 2 px solid red outline and filled alert pill for object-scoped diagnostics.
- Non-overlapping pill placement automatically stacks colliding pills vertically so adjacent objects stay readable.
- **Selection coexistence and read-only step guard**: when the user selects an object the agent is actively touching (`Editor.BeginAgentStep` / `editormcp.Server.BeginStep`), the selection keeps its resize/transform handles and the agent outline sits 3 px further out (`OutsetPx: 6`). Until the agent's step moves on (`EndAgentStep`), manual edits to that object are refused with `ErrAgentTouchingObject` across the viewport, 2D/3D gizmos, inspector (which shows a violet read-only banner), scene tree (rename and reparent), context menu, and direct `Editor` mutation methods, while untouched objects remain freely editable.
- **Scene tree markers**: added nodes show a `NEW` badge, changed nodes show a `MOD` badge, removed nodes remain visible as struck-through ghost rows with a `DEL` badge, and currently touched nodes display a violet agent-working dot until **Keep** or **Revert**.
- **Header pill**: follows the agent's state (`Editor.SetAgentState` / `Editor.AgentState`): violet working pill (`"Agent is <activity> · manual edits stay available"`), warning waiting pill (`"Waiting for you · <detail>"`), pending-review pill with **Keep** (`KeepAgentTurn`, collapsing the turn into one undo step) and **Revert** (`RevertAgentTurn`, undoing the turn and restoring removed objects), and hidden while idle.
- **Interactive top-left Overlay Legend**: appears automatically whenever live overlays are active (or when `OverlayLegendOpen` is true). Each row (**Selection**, **Agent working**, **Added**, **Changed**, **Removed**, **Problem**) is a `RoleSwitch` toggle (`ToggleOverlayLegendKind` / `SetOverlayLegendKind`) persisted per-user in `EditorSettings.HiddenOverlayKinds` (`hiddenOverlayKinds` in `editor.yaml`, schema `editor-settings.v1.json`) without modifying project files.
16 changes: 16 additions & 0 deletions docs/zh/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1468,3 +1468,19 @@ func main() {
- **点击通知回到对应场景中的任务**:`cx.OnNotificationPress`(经由 `Editor.HandleNotificationPress` / `Editor.OpenAgentTask`)将编辑器窗口置前(并触发可选的 `Editor.OnFocusWindow` 钩子)、若在播放中先停止播放、关闭遮挡面板(设置、历史、问题智能体面板、就地提问、资源模式)、切换到或严格在项目根目录内打开该任务所在的场景标签页(拒绝路径遍历与符号链接逃逸)、打开任务或智能体面板并聚焦对应任务及待处理请求卡片。
- **Dock 图标角标(`cx.SetBadge`)**:`Editor.AgentDockBadgeCount` 仅统计等待中(`TaskNeedsYou`)、待审查(`TaskReadyToReview`)与失败(`TaskFailed`)任务的总数(`AgentTaskCounts.BadgeCount()`);运行中与排队中的任务绝不计入角标,归零或在作用域清理时自动清除。
- **播放模式角落提示点与延后通知(`PlayTaskDotView`)**:在播放模式(`Editor.Playing()`)期间,运行中的游戏上方不会弹出任何智能体任务通知,系统通知会暂存(`Editor.HeldAgentNotifications`)直至 `Editor.Stop()` 停止播放后才对仍需处理的任务发出。视口右上角稳定挂载一个带 3 pt 光晕的 8 pt 圆点,颜色取当前最紧急状态的 Spec 令牌色(**失败** `Removed.Fg` > **等待处理** `Warning.Fg` > **待审查** `Accent.Fg`),仅在悬停或键盘聚焦时显示提示胶囊(例如 `"1 task needs you · stop Play to open"`)。

## 在视口与场景树中实时显示智能体编辑(#1013)

当智能体通过 `editormcp` 或待定智能体回合(`Editor.BeginAgentTurn` / `Editor.RunAsAgent`)编辑场景时,编辑器会在视口与场景树中实时呈现其未确认改动(对应 `docs/design/editor/Working.dc.html`、`Main.dc.html` 与 `Spec.dc.html`),且绝不会替智能体移动 2D 或 3D 视口相机:

- **实时视口叠加层(`ViewportLiveOverlays` / `VisibleViewportLiveOverlays`)**:
- **新增(Added)**:1.5 px 绿色虚线框(`SpecPalette.Added`)与 `"+ <name>"` 等宽胶囊标签。
- **修改(Changed)**:1.5 px 琥珀色虚线框(`SpecPalette.Changed`)与 `"<field> <old> → <new>"` 等宽胶囊标签(同时自动同步到检查器的琥珀色审查提示)。
- **移除(Removed)**:位于对象原边界处的 25% 灰色虚影、1.5 px 红色实线框(`SpecPalette.Removed`)以及带删除线名称的 `"<name> removed"` 胶囊标签。
- **智能体处理中(Agent working)**:1.5 px 紫色脉冲实线框(`SpecPalette.Agent`,1.6 秒在 45%–100% 不透明度间循环;开启“减少动态效果”时固定 100% 实线),不带缩放手柄,上方显示带紫色星芒图标与活动描述的胶囊(如 `playing level_01 headless`)。
- **问题(Problem)**:2 px 红色实线框与实心高对比度告警胶囊。
- 胶囊排布自动避让碰撞并向上错开,避免相邻对象或叠加状态互相遮挡。
- **选中对象共存与步骤级只读保护**:当用户选中智能体当前正在操作的对象(`Editor.BeginAgentStep` / `editormcp.Server.BeginStep`)时,选中框保留其变换手柄,智能体轮廓自动再向外偏移 3 px(`OutsetPx: 6`)。在该步骤离开此对象(`EndAgentStep`)之前,视口、2D/3D 手柄、检查器(顶部显示紫色只读提示条)、场景树(重命名与拖拽重挂)、右键菜单及直接调用的 `Editor` 修改方法均会以 `ErrAgentTouchingObject` 拒绝手动修改;未被智能体触及的其他对象仍可自由手动编辑。
- **场景树标记**:新增节点显示 `NEW` 徽章,修改节点显示 `MOD` 徽章,被移除节点以带删除线的虚影行与 `DEL` 徽章保留在树中,智能体正在操作的节点显示紫色圆点,直至执行 **Keep** 或 **Revert**。
- **顶栏状态胶囊**:随智能体状态自动切换(`Editor.SetAgentState` / `Editor.AgentState`):工作中显示紫色胶囊(`"Agent is <activity> · manual edits stay available"`),等待确认显示警告胶囊(`"Waiting for you · <detail>"`),待审查状态显示改动数量与 **Keep**(`KeepAgentTurn`,将整个回合合并为单步撤销)/**Revert**(`RevertAgentTurn`,回滚回合改动并还原已删除对象)按钮,空闲时自动隐藏。
- **左上角可交互叠加层图例**:当存在任意实时叠加层(或 `OverlayLegendOpen` 为真)时自动显示。图例中的每一行(**Selection**、**Agent working**、**Added**、**Changed**、**Removed**、**Problem**)都是可点击的 `RoleSwitch` 开关(`ToggleOverlayLegendKind` / `SetOverlayLegendKind`),隐藏项按用户持久化到项目之外的 `EditorSettings.HiddenOverlayKinds`(`editor.yaml` 中的 `hiddenOverlayKinds`,Schema 为 `editor-settings.v1.json`),绝不污染项目文件。
Loading
Loading