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,36 @@
# Agent Note: Review turn conflict resolution and in-place YAML hand editing

Status: implemented

## Problem

Inside the full-window change-by-change agent turn Review screen ([editor-review-change-by-change](./2026-11-26-editor-review-change-by-change.md), `docs/design/editor/Review.dc.html`, issue #1032), two workflows must block **Keep** cleanly without losing either the author's or the agent's work:

1. **Overlapping edits**: the author may edit an object (for example appending a sound entry to `door_1.properties.on_open`) while a pending agent turn edits the same object. Edits to different fields must merge automatically without prompting, whereas overlapping edits to the same field or list must surface both sides (`you` and `agent`), let the author pick **Mine**, **Agent's**, or **Both** (keeping yours first), and block **Keep** until resolved.
2. **In-place YAML hand edits**: the author may edit an added or changed scene object's YAML directly in the Review right pane. Valid edits must update the Review viewport live, tag edited lines `you`, keep/undo as part of the turn, and remain readable by the agent through MCP in round 2; invalid YAML (such as typing `x 444` without a colon) must mark the exact scene line, block **Keep** and **Done**, offer a mechanical one-step fix when the parser names what is missing, and provide **Undo my typing**.

## Decision

Layer conflict resolution and in-place YAML editing directly onto the existing `turnReviewState` / `reviewFileState` / `ReviewScreenView` engine in `packages/game/editor/review.go`, `packages/game/editor/review_conflicts.go`, `packages/game/editor/review_ui.go`, and `packages/game/editor/editormcp/review.go`:

- **Three-way merge on concurrent manual edits (`syncReviewAfterMutate`, `SyncReviewPersonEdits`)**: each scene `reviewFileState` tracks `personDoc` and `personEdited` alongside `beforeDoc` and `afterDoc`. Non-agent mutations through `Editor.afterMutate` update `personDoc` for the matching open scene and run `sceneformat.Merge(beforeDoc, personDoc, afterDoc)`. Disjoint field edits auto-merge into `effectiveReviewSceneDoc` with zero conflicts; overlapping field or list edits populate `ReviewChange.Conflicts` with `you` and `agent` lines. Picking `ReviewConflictBoth` preserves common base items followed by the person's additions first and the agent's additions second.
- **Keep blockers and atomic single-step Undo**: `Editor.ReviewBlockers()` prioritizes active YAML parse errors (`"Fix YAML on line N"`) ahead of unresolved conflicts (`"Choose how <object> merges"`) and custom blockers. `KeepTurnReview()` jumps to the first blocker and returns `*ReviewBlockedError` (wrapping `ErrReviewBlocked`). When `personEdited` is true, `agentTurnKeepCmd` records the encoded `personDoc` as `beforeBytes` so one `Undo` reverts the agent turn, merge choice, and hand edits together while preserving the author's concurrent manual edits; when `personEdited` is false, exact `beforeYAML` bytes are preserved verbatim.
- **Strict, bounded YAML parsing and mechanical one-step fixes (`parseReviewObjectYAML`)**: `SetReviewYAMLDraft` enforces a 256 KiB cap, rejects NUL bytes, checks You-only boundaries (`validateReviewRelPath`), decodes with `yaml.Decoder.KnownFields(true)` (refusing unknown fields), checks duplicate mapping keys, detects plain-scalar continuation folds (`x 444` absorbed into a preceding plain scalar), validates component schemas and full-scene `sceneformat.Validate`, and produces verified `PatchedYAML` one-step fixes (**Add the colon**, **Close the quote**, **Add the closing brace**, **Add the closing bracket**, **Replace tabs with spaces**).
- **Focus-stable YAML editor and Spec Dark/Light UI (`reviewRightView`)**: `review-yaml-input` (`specInputField` with `Multiline: true` and reactive `StyleFunc`) is mounted inside a `core.Dynamic` keyed strictly on `(editing, changeID, yamlEditSessionRev)` rather than `reviewRev`, so typing never remounts `ui.Input`, steals focus, resets caret, or triggers single-letter `ScopeReview` shortcuts (`IsTyping()` guards `bindReviewShortcuts` and `KeyNotEditing`), while `ApplyReviewYAMLFix` and `UndoReviewYAMLTyping` bump `yamlEditSessionRev` to refresh the input cleanly.
- **Round-2 MCP visibility and privacy enforcement (`editormcp/review.go`, `editormcp/privacy.go`)**: `agentTurnKeepCmd.do` retains a deep snapshot of kept changes (`lastChanges`, `lastFiles`) so `Editor.ReviewStatus()` and `review_status` continue reporting conflict choices and `you`-tagged hand-edited fields/lines after Keep for round 2, while capping `HandEditLines`/`HandEditYAML` and enforcing `PrivacySceneAndData` and `PrivacyGoSource`.

Related notes: [editor-review-change-by-change](./2026-11-26-editor-review-change-by-change.md), [editor-mcp-tile-review](./2026-11-26-editor-mcp-tile-review.md).

## Alternatives considered

1. **Maintain a separate single-file `ReviewSession` parallel to `turnReviewState`**: rejected because multi-file review (`#1014`) already landed with hardened path/symlink/You-only checks, multi-tab sync, unified History metadata, and `bindReviewShortcuts` inside `ReviewScreenView`. Layering `#1032` directly onto `turnReviewState` avoids duplicate UI/state and inherits every security boundary automatically.
2. **Mount `ui.Input` inside `reviewRightView`'s `reviewRev`-driven `core.Dynamic`**: rejected because every keystroke calls `SetReviewYAMLDraft` which bumps `uiRev` to update the live viewport and diff lines; mounting `ui.Input` under `reviewRev` would remount the input and lose focus on every keystroke.

## Consequences

- **Benefits**:
- Concurrent manual edits auto-merge when disjoint and present clear **Mine / Agent's / Both** choices when overlapping, without dropping either side.
- In-place YAML edits validate strictly, update the Review viewport live, recover cleanly from common syntax typos in one click, and undo with the turn in a single History step.
- Round-2 agents observe both merge choices and `you`-tagged hand edits through `review_status` under the project's privacy switches.
- **Costs**:
- `turnReviewState` retains a cloned snapshot of kept `ReviewChange` summaries (`lastChanges`) until the next turn review starts or the project switches so round-2 MCP queries can read them after Keep.
4 changes: 4 additions & 0 deletions changelog.d/editor-review-conflicts-yaml-edit-1032.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- `game/editor`: three-way conflict detection and resolution (**Mine / Agent's / Both**, keeping yours first) for concurrent manual edits during an agent turn review (`syncReviewAfterMutate`, `SyncReviewPersonEdits`, `ResolveReviewConflict`), plus in-place YAML editing in the Review right pane (`BeginReviewYAMLEdit`, `SetReviewYAMLDraft`, `FinishReviewYAMLEdit`) with live viewport preview, `you`-tagged lines, strict unknown-field/duplicate-key validation, mechanical one-step parse fixes (`ApplyReviewYAMLFix`), **Undo my typing** (`UndoReviewYAMLTyping`), and single-step `History` Keep/Undo (#1032).
- `game/editor/editormcp`: extend `review_status` to expose conflict merge choices (`mine`, `agent`, `both`), `you`-tagged hand-edited YAML fields and lines (preserved after Keep for round 2), and YAML parse error blockers, while enforcing `PrivacySceneAndData` and `PrivacyGoSource` privacy switches (#1032).
11 changes: 10 additions & 1 deletion docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ When an agent completes a turn (`Editor.StartTurnReview`), the full-window **Rev
- **Right pane (Why + YAML)**: shows the agent's reason (**WHY**) above the line-numbered YAML lines touched by the focused change with `+` / `−` signs.
- **Esc / Resume pending state**: pressing `Esc` (`PauseReview`) returns to the editor while leaving the review pending—the main viewport renders pending change overlays (`drawPendingReviewOverlay`) and the right-rail **Agent** tab (`AgentPanelView`) shows `"Review waiting · N changes, F files"` with seen count, blockers, and **Resume review** (`ResumeReview`), which returns to the exact same focused change and seen state.
- **Keep, Revert all, and one-step Undo**: **Revert all** asks in a focus-trapped confirmation dialog naming every file that goes back and reminding that `⌘Z` / `Ctrl+Z` brings everything back. Both **Keep** (`KeepTurnReview`) and **Revert all** (`ConfirmReviewRevertAll`) execute as **one `Editor.History` step**, update saved YAML files and the open scene, show a Spec toast with **Undo**, and record `"Kept K · reverted R · one undo step"` in the Agent panel; a single `Editor.Undo()` restores every touched file byte for byte.
- **MCP read access (`editormcp`)**: the read-only `review_status` tool (`ToolReviewStatus`, `ActionRead`) lets connected agents inspect which changes have been seen or reverted, active blockers, and keep/revert outcomes without granting the agent permission to keep or revert the turn (unsent draft notes are never exposed, and `SceneAndData` / `GoSource` privacy rules are enforced).
- **MCP read access (`editormcp`)**: the read-only `review_status` tool (`ToolReviewStatus`, `ActionRead`) lets connected agents inspect which changes have been seen or reverted, overlapping conflict choices (`mine`, `agent`, `both`), hand-edited YAML fields and lines tagged `"you"`, active blockers, and keep/revert outcomes (including after Keep for round 2) without granting the agent permission to keep or revert the turn (unsent draft notes are never exposed, and `SceneAndData` / `GoSource` privacy rules are enforced).

### Review notes and second-round redo (#1031)

Expand All @@ -1479,6 +1479,15 @@ Instead of reverting everything or hand-editing YAML when one or two changes nee
- **Send notes and noted-only redo (`SendReviewNotes`, `ApplyReviewRedo`, `editormcp`)**: clicking **Send N notes** in the header (which becomes the primary accent button while unsent notes exist) dispatches all remaining notes to the agent over MCP (`review_notes_get`), naming each change's `change_id`, `file`, `object`, `field`, `kind`, and `note`. The agent revises only noted changes within the same turn via `review_redo` (un-noted changes and tampered un-noted objects in the same file are refused, You-only/permission/privacy rules are enforced). Redone changes appear unseen again in Round 2+ with `"Redone from your note: …"` in **WHY** and `"Revised in round N. Your note: …"` on the card.
- **Round tabs, banner, filters, paused card, and single-step Undo**: once Round 2 exists, the header shows **Round 1 | Round 2** tabs (`SetReviewViewRound`) and a banner below the filter chips (`"Round 2 · the agent redid only the N changes you left notes on. Both rounds keep and undo as one step."`). **Round 1** is read-only (`ErrReviewReadOnlyRound` on edit/revert/note attempts) and shows the agent's first version for comparison; **Keep** (`⌘↵`) always applies the **latest round** as **one `Editor.History` step**, so a single **Undo** (`⌘Z`) restores every touched file to its exact pre-request bytes. The **Notes** chip filters to changes with notes, the paused **Agent** panel card shows unsent note counts (`"N notes not sent"`), and the **Revert all** dialog warns that pending notes will be dropped.

### Review conflicts and in-place YAML hand editing (#1032)

Inside the change-by-change Review screen, two cases block **Keep** cleanly without losing either the author's or the agent's work:

- **Three-way conflict resolution (`syncReviewAfterMutate`, `SyncReviewPersonEdits`, `ResolveReviewConflict`)**: manual edits made through editor commands (`MoveObject`, `SetProperty`, `SetComponentField`, and so on) while a review turn is pending automatically three-way merge against the turn baseline and agent snapshot via `sceneformat.Merge`. Edits to **different fields** of the same object merge cleanly without asking; overlapping edits to the **same field or list** (such as appending to `door_1`'s `on_open` list) display both sides inside the change card with line authors (`you`, `agent`) and a **Mine / Agent's / Both** segmented control (`ReviewConflictMine`, `ReviewConflictAgent`, `ReviewConflictBoth`), where **Both** keeps both entries with **yours first**. Until every unresolved conflict is chosen, **Keep** is disabled (`*ReviewBlockedError` wrapping `ErrReviewBlocked`) with `"Choose how <object> merges"`, and pressing **Keep** or the header blocker jumps straight to that change.
- **In-place YAML editing and live viewport preview (`BeginReviewYAMLEdit`, `SetReviewYAMLDraft`, `FinishReviewYAMLEdit`)**: clicking **Edit** on any non-reverted added or changed scene object makes the right-hand YAML pane editable in place without losing text-input focus or firing single-letter Review shortcuts while typing. Drafts are bounded (256 KiB), strictly decoded with `KnownFields(true)`, checked for duplicate keys and `sceneformat.Validate` (and component registry rules), and checked against You-only boundaries. Valid edits update the Review viewport live (`ReviewEffectiveSceneDoc`) and tag hand-edited lines `you`.
- **Parse errors, mechanical one-step fixes, and Undo my typing (`ApplyReviewYAMLFix`, `UndoReviewYAMLTyping`)**: invalid YAML (such as typing `x 444` without a colon) marks the failing scene line, surfaces `"Fix YAML on line N"` in the header blocker and `"Line N isn't valid YAML"` in the alert card, disables **Done** (`ErrReviewYAMLInvalid`) and **Keep**, offers verified one-step fixes when the parser names what is missing (**Add the colon**, **Close the quote**, **Add the closing brace**, **Add the closing bracket**, **Replace tabs with spaces**), and always provides **Undo my typing**.
- **Single undo step and round-2 MCP visibility**: conflict merge choices and valid hand edits land with the turn in **one `Editor.History` step** (`KeepTurnReview`)—one `Undo` reverts the agent turn, merge choice, and hand edit together while preserving any concurrent manual edits made outside the review—and remain readable through `editormcp`'s `review_status` tool (`Editor.ReviewStatus`) tagged `"you"` for round 2.

## System notifications, Dock badge, and Play-mode dot for agent tasks (#1023)

Agent tasks (both background tasks managed via `tasks.go` / #1022 and foreground Agent panel runs) reach the person outside the editor through NSGo's native notification and badge APIs (`core.Scope.ShowNotification`, `core.Scope.RequestNotificationPermission`, `core.Scope.OnNotificationPress`, and `core.Scope.SetBadge`), matching `docs/design/editor/Tasks.dc.html`, `docs/design/editor/AgentStates.dc.html`, and `docs/design/editor/Spec.dc.html` using exclusively Spec design tokens:
Expand Down
2 changes: 1 addition & 1 deletion docs/en/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ claude mcp add game-editor -- nsgo game mcp
| `game_check` | run | none | Runs the Problems panel's check (`assetcheck` with the editor's component registry, and `project.Check`, including open unsaved documents in the editor) and returns its visible problems, each with file, 1-based line, 1-based column (where known), and message. |
| `problem_propose_fix` | read | `problem` (required), `explanation` (required), `edit` (required) | Validates a proposed fix for a live problem on a cloned scene, computes the exact `-`/`+` YAML diff, and shows the review card (with Apply fix, Show me, Ignore, and Ask about this problem…) in the editor's Agent panel. Never applies the fix or modifies any file — no MCP tool applies a fix. |
| `history_list` | read | `author` (`all`, `you`, `agent`), `limit` (1–500, default 50) (both optional) | Reads the editor's unified History timeline of manual edits, agent turns, external Git reloads, and saved points (newest first), with author, summary, detail, touched files, timestamps, change/kept counts, unsaved status, and active preview ID. |
| `review_status` | read | none | Returns the active or most recent change-by-change agent turn review state: whether it is open or pending, the quoted request, round state, file summaries, every change's seen and reverted flags, active blockers, and the last keep/revert outcome. Unsent draft notes are never exposed, privacy policies are enforced, and keeping or reverting remains the person's decision. |
| `review_status` | read | none | Returns the active or most recent change-by-change agent turn review state: whether it is open or pending, the quoted request, round state, file summaries, every change's seen and reverted flags, overlapping edit conflicts and the person's merge choice (`mine`, `agent`, `both`), in-review YAML hand edits tagged `"you"` with edited fields and lines (preserved after Keep for round 2), active blockers (including YAML parse errors), and the last keep/revert outcome. Unsent draft notes are never exposed, privacy policies (`SceneAndData` and `GoSource`) are enforced, and keeping or reverting remains the person's decision. |
| `review_notes_get` | read | none | Reads the active agent turn review's round state, changes, and the change-scoped notes explicitly sent by the author via **Send N notes** or **Revert and redo with this note** (`change_id`, `file`, `object`, `field`, `kind`, `note`, `revert_first`). Unsent draft notes and notes removed before sending are never returned. |
| `review_redo` | edit | `changes` (required non-empty array of `{change_id, detail?, x?, y?, component?, fields?, file_content?, old_value?, new_value?, delta?, yaml_lines?}`) | Redoes only changes the author left notes on in the active review, advancing the same turn to Round 2+ while keeping earlier rounds intact and read-only. Un-noted changes (and any un-noted items in a supplied `file_content`) are refused atomically; redone changes become unseen again with `"Redone from your note: …"` as their Why, and **Keep** still applies the latest round as one undo step. |
| `game_playtest` | run | `file`, `run`, `count`, `seeds`, `out`, `recordings` (all optional) | Validates `playtest.yaml`, runs the configured headless bot playtests with per-seed `.replay.yaml` recordings, writes the YAML report and returns each metric's value, goal status (`met` or `missed`) and heat-map position data. |
Expand Down
Loading
Loading