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,28 @@
# Agent Note: Editor agent threads per line of work, grouped by scene

Status: implemented

## Problem

AI-first scene editing in the NSGo Game Editor (`docs/design/editor/Threads.dc.html`, issue #1019) requires separating lines of work into persistent threads scoped by scene, keeping each external agent's session ID per thread, folding reviewed requests so long threads stay scannable, linking folded steps into History, showing an empty-thread orientation seeded from `brief.yaml`, and attributing each scene object in the Inspector footer to the request that last changed it. Previously the right rail rendered only `InspectorView` with no thread persistence, scene-bound thread switching, folded request history, or object-to-request attribution.

## Decision

We implement scene-grouped agent threads inside `packages/game/editor` (`agent_threads.go`, `agent_threads_ui.go`) and connect them to scene switching, the Inspector footer, shortcuts, and `editormcp`:

- **Strict versioned YAML per thread under `.nsgo/threads/<id>.yaml`**: `AgentThread` (`AgentThreadFileVersion = 1`, `AgentThreadSchemaURL = "https://game.nsgo.dev/schemas/agent-thread.v1.json"`) stores `version`, `id`, `title`, `scenePath`, external agent `sessionId`, RFC3339 timestamps, and chronological `requests` with `steps`, review `outcome` (`pending`, `kept`, `reverted`), change counts, changed `objects`, `files`, and `historyStep` links. `ParseAgentThreadYAML` rejects unknown fields, duplicate keys, YAML anchors/aliases/merge keys, trailing documents, path traversal, and invalid counts; `EncodeAgentThreadYAML` writes canonical 2-space YAML that round-trips byte-for-byte. Creating `.nsgo/threads/` writes `.nsgo/.gitignore` (`*\n`) if absent, skips `*.thread.yaml` task-queue files owned by #1022, and validates symlink containment inside the project root.
- **Scene-bound thread lifecycle without carrying threads across scenes**: `openProject` loads valid threads from `.nsgo/threads/` and enters the open scene's most recent thread (or an unsaved empty draft thread). `SelectTab`, `activateNewTab`, `CloseTab`, `openYAMLWithLayers`, and `SaveFile` (when `ScenePath` changes) call `syncAgentThreadForOpenScene()`, which enters the newly active scene's latest thread or a fresh scene draft and never carries the previous scene's thread along. Selecting another scene's thread from the switcher opens that scene tab before activating the chosen thread.
- **Unified right rail with `Inspector` default tab, `Agent` panel with threads, and `History` view**: `RightRailView` integrates `InspectorView` (default `RightTabInspector`, preserving all existing Inspector tests and 272 pt layout), `AgentPanelView` (380 pt matching `Threads.dc.html`, hosting the thread switcher header, popover, folded/expanded requests, empty-thread orientation, live turns, status chip, and composer), `TasksPanelView` (#1022), and `AgentHistoryView` (`RightTabHistory`). Every surface uses `ed.SpecPalette(cx)` tokens across Spec Dark and Spec Light themes.
- **Scoped `⌘N` (`ScopeAgent`)**: `CmdNewAgentThread` binds `mod+n` in a dedicated `ScopeAgent` prioritized above `ScopeGlobal` only while the Agent panel is active (`RightRailAgent`), focused, or its switcher is open, leaving `CmdNewProject` (`mod+n` in `ScopeGlobal`) intact elsewhere without shortcut conflict.
- **Inspector footer attribution and `editormcp` hook**: `LastAgentChangeForObject` scans the open scene's and project-level threads for the most recent non-reverted request touching `objectID` (including edits automatically noted by `editormcp`'s `scene_edit` via `Editor.NoteAgentEditedObjects`), rendering `inspector-thread-footer` above the existing static `inspector-footer` hint and opening/expanding that request on press.

## Alternatives considered

- **Storing all threads in one `.nsgo/threads.yaml` index file**: Rejected because concurrent or frequent per-request writes would rewrite unrelated threads, make manual inspection/deletion of one line of work harder, and diverge from issue #1019's requirement of one file per thread under `.nsgo/threads/`.
- **Making `RightRailAgent` the default right-rail tab on `EditorView` mount**: Rejected because existing editor regression tests and workflows expect `InspectorView` controls (`editor-inspector`, `inspector-footer`, field inputs) to be mounted immediately when `EditorView` starts without an extra tab switch; defaulting to `RightRailInspector` keeps every existing test intact while exposing one-click switching to `Agent` and `History`.
- **Rebinding `mod+n` globally from `CmdNewProject` to `CmdNewAgentThread`**: Rejected because `TestDesktopMenuBarMatchesRegistryAndExecutesActions` and desktop File > New Project expect `CmdNewProject` to own `mod+n` in `ScopeGlobal`; placing `CmdNewAgentThread` in `ScopeAgent` follows the editor's scope-aware shortcut architecture (`shortcuts.go`) and resolves `⌘N` cleanly inside the Agent panel.

## Consequences

- **Benefits**: Each line of work persists cleanly in readable, schema-validated YAML under `.nsgo/threads/` (ignored by git), scene switching cleanly isolates threads per scene, external agent `sessionId` survives project reloads, folded requests link directly into History, empty threads surface `brief.yaml` suggestions safely, and the Inspector links any agent-modified object back to the exact request that changed it.
- **Costs**: `RightRailView` adds a 38 pt tab header above `InspectorView` and widens the right rail to 380 pt when `Agent` or `History` is active. Full external agent CLI execution and streaming remain owned by #1009 (`Editor.OnSendAgentRequest` provides the clean hook for #1009 to attach without changing the thread storage or UI contract).
205 changes: 205 additions & 0 deletions apps/website/public/schemas/agent-thread.v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://game.nsgo.dev/schemas/agent-thread.v1.json",
"title": "NSGo game editor agent thread (version 1)",
"description": "AgentThread is the strict versioned YAML document stored per line of work under .nsgo/threads/<id>.yaml. A file looks like this:\n\n# yaml-language-server: $schema=https://game.nsgo.dev/schemas/agent-thread.v1.json version: 1 id: door-lever-pulls title: Door opens after two lever pulls scenePath: scenes/level_01.scene.yaml sessionId: sess_claude_01 createdAt: \"2026-11-26T13:40:00Z\" updatedAt: \"2026-11-26T14:18:00Z\"\n\nParseAgentThreadYAML decodes it strictly and EncodeAgentThreadYAML writes it back in canonical form so loading and saving a thread file changes nothing.",
"type": "object",
"properties": {
"version": {
"description": "Version is the schema version; it must equal AgentThreadFileVersion (1).",
"type": "integer",
"const": 1
},
"id": {
"description": "ID is the stable filename-safe identifier for this thread (stored as .nsgo/threads/<id>.yaml).",
"type": "string"
},
"title": {
"description": "Title is the thread's display name, automatically set from its first request.",
"type": "string"
},
"scenePath": {
"description": "ScenePath is the slash-separated project-relative scene path this thread belongs to, or empty for Project · no scene.",
"type": "string"
},
"sessionId": {
"description": "SessionID is the external agent's session identifier so follow-up requests continue the same agent session.",
"type": "string"
},
"createdAt": {
"description": "CreatedAt is the RFC3339 UTC timestamp when the thread was created.",
"type": "string"
},
"updatedAt": {
"description": "UpdatedAt is the RFC3339 UTC timestamp of the thread's latest activity.",
"type": "string"
},
"requests": {
"description": "Requests lists the thread's requests in chronological order (oldest first, latest last).",
"type": "array",
"items": {
"$ref": "#/definitions/AgentThreadRequest"
}
}
},
"required": [
"version",
"id",
"createdAt",
"updatedAt"
],
"additionalProperties": false,
"definitions": {
"AgentThreadRequest": {
"description": "AgentThreadRequest is one author request and its streamed steps, changed objects/files, and review outcome.",
"type": "object",
"properties": {
"id": {
"description": "ID uniquely identifies this request within its thread.",
"type": "string"
},
"title": {
"description": "Title is the short single-line summary shown when the request is folded or referenced in the Inspector footer.",
"type": "string"
},
"prompt": {
"description": "Prompt is the full request text sent to the agent.",
"type": "string"
},
"createdAt": {
"description": "CreatedAt is the RFC3339 UTC timestamp when the request was sent.",
"type": "string"
},
"updatedAt": {
"description": "UpdatedAt is the RFC3339 UTC timestamp when the request last changed state.",
"type": "string"
},
"reply": {
"description": "Reply is the agent's short completion message shown under the steps.",
"type": "string"
},
"outcome": {
"description": "Outcome records whether the request is \"pending\", \"kept\", or \"reverted\".",
"type": "string",
"enum": [
"pending",
"kept",
"reverted"
]
},
"changesTotal": {
"description": "ChangesTotal is the total number of proposed changes in this request.",
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"changesKept": {
"description": "ChangesKept is the number of proposed changes kept during review (0..ChangesTotal).",
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"files": {
"description": "Files lists project-relative slash paths of files changed by this request.",
"type": "array",
"items": {
"type": "string"
}
},
"objects": {
"description": "Objects lists scene object IDs changed by this request (used for Inspector footer attribution).",
"type": "array",
"items": {
"type": "string"
}
},
"detail": {
"description": "Detail is a compact human-readable summary of changed fields/assets shown when expanded.",
"type": "string"
},
"historyStep": {
"description": "HistoryStep names the undo step label in History linked to this request.",
"type": "string"
},
"historyIndex": {
"description": "HistoryIndex records the 1-based undo stack index in History linked to this request, when known.",
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"steps": {
"description": "Steps lists the recorded agent steps for this request in execution order.",
"type": "array",
"items": {
"$ref": "#/definitions/AgentThreadStep"
}
}
},
"required": [
"id",
"prompt",
"createdAt",
"outcome"
],
"additionalProperties": false
},
"AgentThreadStep": {
"description": "AgentThreadStep is one recorded action taken by the agent while handling a request.",
"type": "object",
"properties": {
"id": {
"description": "ID uniquely identifies this step within its request.",
"type": "string"
},
"label": {
"description": "Label is the short human-readable description shown in the thread and History.",
"type": "string"
},
"status": {
"description": "Status is the step's state (\"pending\", \"running\", \"done\", or \"failed\").",
"type": "string",
"enum": [
"pending",
"running",
"done",
"failed"
]
},
"detail": {
"description": "Detail holds optional extra context for the step (for example changed fields or files).",
"type": "string"
},
"historyStep": {
"description": "HistoryStep names the corresponding editor History label, when this step edited the scene.",
"type": "string"
},
"historyIndex": {
"description": "HistoryIndex records the 1-based History stack index created by this step, when known.",
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"objects": {
"description": "Objects lists the IDs of scene objects modified by this step.",
"type": "array",
"items": {
"type": "string"
}
},
"files": {
"description": "Files lists project-relative slash paths of files touched by this step.",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"id",
"label",
"status"
],
"additionalProperties": false
}
}
}
3 changes: 3 additions & 0 deletions changelog.d/editor-agent-threads-1019.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Add per-line-of-work agent threads persisted as strict versioned YAML under `.nsgo/threads/` (ignored by `.nsgo/.gitignore`), grouped by open scene, other scenes, and `Project · no scene`, with search, `⌘N` new thread, scene-bound thread switching, folded earlier requests with History links and Jump to latest, empty-thread brief suggestions, and an Inspector footer linking each object to the request that last changed it (#1019).
11 changes: 10 additions & 1 deletion docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,6 @@ Every interactive control in the editor carries the `docs/design/editor/Spec.dc.
- **Viewport focus is the selection**: the viewport canvas draws no focus ring of its own; while focus is in the viewport (`editor-viewport-frame`), `Tab` (`Editor.SelectNextObject`) and `Shift-Tab` (`Editor.SelectPreviousObject`) cycle through visible, unlocked scene objects in order.
- **Dialog focus trapping and opener restoration**: editor dialogs (`EditorSettingsDialogView`, `ShortcutsSheetView`, `CommandPaletteView`, unsaved-changes prompt, scene path dialog, and save-conflict dialog) trap `Tab` / `Shift-Tab` inside the topmost modal (respecting shortcut capture in `Settings › Shortcuts`), block global shortcuts behind the modal except `⌘.` / `Ctrl+.` (`Editor.OnStopAgent`) to stop an active agent, and return focus to the exact control that opened the dialog when dismissed with `Esc` or an action button.
- **Focus stability**: nothing moves focus automatically during an active drag or inspector scrub (`Editor.IsDragging`) or while typing in a text field (`Editor.IsTyping`). Showing a toast never steals focus, and `Editor.ShouldFocusAgentPrompt` returns `true` only when no drag or text input is active and focus is already inside the agent panel (`Editor.SetAgentPanelRef`).

## Connect an agent and status chip (#1009)

Connect an external coding agent (Claude Code, Codex, or any MCP client on your computer) directly from the editor or with `go tool game mcp install`, matching `docs/design/editor/Connect.dc.html`, `docs/design/editor/AgentStates.dc.html`, and `docs/design/editor/Settings.dc.html` using exclusively `docs/design/editor/Spec.dc.html` tokens:
Expand Down Expand Up @@ -1504,3 +1503,13 @@ While an agent edits a scene through `editormcp` or an active agent turn (`Edito
- **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.

## Agent threads per line of work, grouped by scene (#1019)

The right rail (`RightRailView`) switches between **Agent** (`AgentPanelView` / `AgentThreadsView`), **Inspector** (`InspectorView`, the default tab), and **History** (`AgentHistoryView`), using `docs/design/editor/Spec.dc.html` tokens matching `Threads.dc.html` across Dark and Light appearances:

- **One YAML file per thread under `.nsgo/threads/` (`AgentThread`, `AgentThreadFileVersion = 1`)**: each thread is persisted as a strict versioned YAML document at `.nsgo/threads/<id>.yaml` (with `.nsgo/.gitignore` automatically ignoring the directory from git), storing `id`, `title` (named from its first request), `scenePath`, external agent `sessionId` (`SetAgentThreadSessionID`), timestamps, and chronological `requests` with `steps`, `outcome` (`pending`, `kept`, `reverted`), change counts, changed `objects`, and `historyStep` links. Parsed with `ParseAgentThreadYAML` and written canonically with `EncodeAgentThreadYAML` (JSON Schema `https://game.nsgo.dev/schemas/agent-thread.v1.json`).
- **Grouped thread switcher, search, and `⌘N` (`AgentThreadGroups`, `CmdNewAgentThread`)**: the switcher groups threads under `<OPEN_SCENE> · OPEN SCENE`, other scenes (`<SCENE>`), and `PROJECT · NO SCENE`, each showing relative age and state (`now · 3 changes to review`, `1 h ago · kept 5 of 6`, `yesterday · reverted`, or changed files). Opening or switching scenes enters that scene's most recent thread (or a fresh draft) and never carries another scene's thread along; `⌘N` (`ScopeAgent`) starts a new empty thread.
- **Folded earlier requests, History link, and Jump to latest**: earlier reviewed requests fold to one line each (`N EARLIER REQUESTS`) and expand on click to show the full prompt, changed fields, steps, and **Open this step in History** (`OpenHistoryStep`), which opens the unified History timeline highlighted on that step. Expanding an earlier request surfaces a floating **Jump to latest** pill (`JumpToLatestAgentRequest`).
- **Empty-thread view (`AgentAlwaysReadItems`, `AgentBriefSuggestions`)**: an empty thread lists what the agent reads with every request (`<scene> · whole scene`, `brief.yaml`, `AGENTS.md`, `Viewport image`) and up to three starter prompts read safely from the project's `brief.yaml` (`FROM YOUR BRIEF`).
- **Inspector footer attribution (`LastAgentChangeForObject`, `OpenAgentRequest`)**: when a selected object was changed by a non-reverted agent request (via `SendAgentRequestWith`, `RecordAgentStep`, or `editormcp`'s `scene_edit`), the Inspector footer displays `Changed in “<request>” · <age>` and clicking it opens that thread and expands that request.
Loading
Loading