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 review notes and second-round redo

Status: implemented

## Problem

When reviewing an agent's multi-file edits (`docs/design/editor/Review.dc.html`, #1014), authors often want the agent to adjust one or two specific changes ("Move it about 40 px left") rather than reverting everything or hand-editing YAML. Sending feedback in a separate chat turn loses per-change provenance, risks modifying un-noted changes, and splits the undo history into multiple steps. Notes must also remain strictly ephemeral to the turn so they never pollute project YAML files or leak to the agent before the author explicitly sends them (#1031).

## Decision

Layer change-scoped notes and per-round immutable snapshots cleanly onto `Editor.review` (`packages/game/editor/review.go`, `review_notes.go`, `review_ui.go`) and expose explicit MCP handoff tools (`review_notes_get`, `review_redo` in `packages/game/editor/editormcp/review.go`) with full privacy, permission, You-only, and noted-only isolation guarantees:

- **Turn-scoped notes & immutable round versions (`review_notes.go`, `review.go`)**: Each `ReviewChange` stores `Note` (unsent draft, bounded to `maxReviewNoteLen = 4096` runes and `maxReviewNotesCount = 256`), `SentNote`, `RedoneInRound`, `RedoneNote`, and `Versions []ReviewChangeVersion` (1-based). Each `reviewFileState` keeps `rounds []reviewFileRound` (bounded to `maxReviewRounds = 20`). Notes live strictly in memory and are never written to any scene, prefab, data, or Go file. `RemoveReviewNote` clears `Note` before `SendReviewNotes`, so removed notes never enter `pendingBatch` and never reach the agent.
- **Noted-only MCP handoff, privacy & isolation (`editormcp/review.go`, `editormcp/privacy.go`)**: `review_status` scrubs unsent `Note` fields and redacts diff lines for privacy-blocked files (such as `.go` when `GoSource` privacy is off). `review_notes_get` returns only `pendingBatch` notes sent via **Send N notes** or **Revert and redo with this note**, naming `change_id`, `file`, `object`, `field`, `kind`, `note`, and `revert_first`. `review_redo` maps targeted change IDs to `PermissionRequest` targets (enforcing MCP permission profiles/rules and You-only checks) and privacy rules, atomically refuses un-noted changes (`ErrReviewChangeNotNoted`), extracts only the noted object/field/row even when `file_content` is supplied so un-noted items in the same file cannot be altered, advances to Round `N+1` while keeping earlier rounds read-only (`ErrReviewReadOnlyRound`), and marks redone changes unseen again with `"Redone from your note: <note>"` as their `Why`.
- **Single-step Keep and Undo**: `KeepTurnReview` always reconstructs files from the latest round (`e.reviewLatestRound()`), even if the author is inspecting Round 1, and records one `agentTurnKeepCmd` on `Editor.History` whose `beforeBytes` are the exact pre-request bytes. One `Undo()` restores every touched file and open scene tab to its exact pre-request state.
- **Focus-stable, Spec-token UI (`review_ui.go`, `commands.go`)**: `CmdReviewNote` (`C`) is registered in `ScopeReview` and bound strictly inside `ReviewScreenView` via `bindReviewShortcuts` (`core.KeyNotEditing`), so it never steals keys when Review is closed or when typing in inputs. The inline note composer uses a dedicated draft signal synced only on composer target switches so typing never remounts rows or trims spaces. Both Dark and Light Spec palettes (`SpecPalette`) style the **Round 1 | Round 2** switcher, round banner, saved note box, composer, **Send N notes** accent CTA, viewport speech-bubble pins (in both Review and paused 2D viewports), paused Agent panel card, and Revert all warning dialog.

## Alternatives considered

- **Persisting notes as YAML comments or sidecar files**: Rejected because the editor's "Text is the truth" principle and #1031 require notes to belong strictly to the turn and never touch version-controlled game files.
- **Replacing the whole file from `review_redo.file_content`**: Rejected because an agent could accidentally or silently modify un-noted objects, prefab fields, or data rows in the same file; extracting only the noted object/field/row guarantees structural isolation for un-noted changes.
- **Recording one `History` step per review round**: Rejected because `Review.dc.html` and #1031 specify that both rounds keep and undo as one single step.

## Consequences

- **Benefits**: Authors iterate on specific changes with full Round 1 vs. Round 2 comparison, viewport pins, and guaranteed one-step Undo across multi-file turns; unsent or removed notes can never leak over MCP, and un-noted changes cannot be tampered with.
- **Costs**: Holding per-round file snapshots in memory grows with rounds (bounded by `maxReviewRounds = 20` and `maxReviewFileBytes = 8 MiB`), and snapshots are freed immediately on `KeepTurnReview`, `ConfirmReviewRevertAll`, or `resetTurnReviewForProject`.
- **Verification**: Covered by `packages/game/editor/review_notes_test.go`, `packages/game/editor/editormcp/review_notes_test.go`, `packages/game/editor/editorcmd/review_notes_screenshot_test.go`, `go tool nsgo check ./editor/...`, `go run ./cmd/gameschema -check`, `go run ./tools/changelog check`, and `bun run verify-notes`.
3 changes: 3 additions & 0 deletions changelog.d/editor-review-notes-second-round-1031.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- `game/editor`, `game/editor/editormcp`: add change-scoped review notes (`C` / `CmdReviewNote`, inline note composer, viewport note pins, Notes filter chip, paused Agent panel unsent-note counts, and Revert all dropped-note warning), multi-round review tabs (`Round 1` read-only / `Round 2` latest with round banner and `"Redone from your note: …"` Why), and MCP tools `review_notes_get` and `review_redo` (with privacy, permission, You-only, and noted-only isolation enforcement) so redoing noted changes stays within one turn and one undo step (#1031).
10 changes: 9 additions & 1 deletion docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,15 @@ 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.
- **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).

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

Instead of reverting everything or hand-editing YAML when one or two changes need adjustment, authors can leave change-scoped notes on the active turn and have the agent redo only those changes as **Round 2** within the same review (`docs/design/editor/Review.dc.html`):

- **Inline note composer (`C` / `CmdReviewNote`) and viewport pins**: pressing `C` on a focused change (or clicking its speech-bubble button) opens an inline note composer under the card (`"Note for the agent · not sent"`) with **Add note** (`CommitReviewNote`), **Revert and redo with this note** (`RevertAndRedoReviewChange`), and **Cancel** (`CancelReviewNoteComposer`, or `Esc`). Saved notes appear on the card with **Edit** and **Remove** (`RemoveReviewNote`) and as Spec-token speech-bubble pins beside noted objects in both the Review viewport and the paused 2D viewport (`ReviewViewportPins`). Notes live strictly in memory on the turn, are bounded in length and count, and are never written to any scene, prefab, or data file; a note added and removed before sending never reaches the agent.
- **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.

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

Expand Down
4 changes: 3 additions & 1 deletion docs/en/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ 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, file summaries, every change's seen and reverted flags, active blockers, and the last keep/revert outcome. Read-only: 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, 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_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. |
| `playtest_define` | edit | `metric` (required), `file`, `rationale`, `replace` (optional) | Validates a proposed playtest metric, generates the canonical `playtest.yaml` diff and queues it as a pending review (`Server.PlaytestReviews` / `ApplyPlaytestReview` / `DismissPlaytestReview`) without modifying `playtest.yaml` on disk until reviewed. |
| `playtest_report` | edit | `file`, `open`, `read`, `suggestions`, `watchRun` (all optional) | Opens or inspects the editor's Playtest Report screen, loads a `playtest.report.yaml` file, updates the Agent's read summary and actionable suggestions, or opens a 1-based run's saved `.replay.yaml` recording in Play mode. |
Expand Down
10 changes: 9 additions & 1 deletion docs/zh/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,15 @@ func main() {
- **右侧面板(Why 与 YAML)**:在顶部显示智能体给出该改动的原因(**WHY**),下方展示带行号与 `+` / `−` 符号的精确 YAML 差异行。
- **按 `Esc` 挂起与恢复审核**:按 `Esc`(`PauseReview`)回到编辑器并保持审核挂起——主视口继续绘制待审核改动叠加层(`drawPendingReviewOverlay`),右侧 **Agent** 标签页(`AgentPanelView`)展示 `"Review waiting · N changes, F files"`、已读计数、阻塞数与 **Resume review** 按钮(`ResumeReview`),点击后精确回到离开时的聚焦改动与已读状态。
- **保留、全部撤回与单步撤销**:**Revert all** 弹出带焦点限制的确认对话框,列出将还原的文件并提示 `⌘Z` / `Ctrl+Z` 可全部恢复。**Keep**(`KeepTurnReview`)与 **Revert all**(`ConfirmReviewRevertAll`)均记录为 `Editor.History` 中的**单个步骤**,更新磁盘 YAML 文件与当前打开场景、弹出带 **Undo** 的规范 Toast,并在 Agent 面板显示 `"Kept K · reverted R · one undo step"`;执行一次 `Editor.Undo()` 即可按字节完整还原全部改动文件。
- **MCP 只读接口(`editormcp`)**:新增只读工具 `review_status`(`ToolReviewStatus`、`ActionRead`),供智能体读取哪些改动已被查看或撤回、当前阻塞项以及保留/撤回结果,但保持保留与撤回决定权始终属于用户。
- **MCP 只读接口(`editormcp`)**:新增只读工具 `review_status`(`ToolReviewStatus`、`ActionRead`),供智能体读取哪些改动已被查看或撤回、当前阻塞项以及保留/撤回结果,但保持保留与撤回决定权始终属于用户(绝不暴露未发送的草稿批注,并强制执行 `SceneAndData` / `GoSource` 隐私规则)。

### 审核批注与第二轮局部重做(#1031)

当审核中只需微调一两处改动而不想全部撤回或手改 YAML 时,作者可以在当前回合的任意改动上添加批注并交由智能体在同一审核内仅重做带批注的改动作为 **Round 2**(`docs/design/editor/Review.dc.html`):

- **行内批注编辑器(`C` / `CmdReviewNote`)与视口图钉**:在聚焦改动上按 `C`(或点击批注图标按钮)会在卡片下方展开行内批注框(`"Note for the agent · not sent"`),提供 **Add note**(`CommitReviewNote`)、**Revert and redo with this note**(`RevertAndRedoReviewChange`)与 **Cancel**(`CancelReviewNoteComposer` 或 `Esc`)。已保存的批注会显示在卡片上(支持 **Edit** 与 **Remove** / `RemoveReviewNote`),并在审核视口与挂起后的 2D 主视口中以规范配色图钉标注在对应对象旁(`ReviewViewportPins`)。批注仅保存在当前回合的内存状态中(且限制长度与数量),绝不写入任何场景、预制体或数据文件;发送前被移除的批注绝不会到达智能体。
- **发送批注与仅重做批注项(`SendReviewNotes`、`ApplyReviewRedo`、`editormcp`)**:点击顶栏的 **Send N notes**(存在未发送批注时切换为主强调色按钮)会通过 MCP(`review_notes_get`)将所有未发送批注连同每项改动的 `change_id`、`file`、`object`、`field`、`kind` 与 `note` 发给智能体。智能体在同一回合内调用 `review_redo` 仅重做带有批注的改动(未加批注的改动以及同一文件中被夹带修改的未批注对象均会被原子拒绝,同时强制执行 You-only、权限规则与隐私边界);重做后的改动在 Round 2+ 中重新标为未读,并在 **WHY** 中显示 `"Redone from your note: …"`、在卡片下方显示 `"Revised in round N. Your note: …"`。
- **轮次标签页、横幅、过滤、挂起卡片与单步撤销**:进入 Round 2 后,顶栏展示 **Round 1 | Round 2** 切换标签(`SetReviewViewRound`),过滤标签下方展示轮次横幅(`"Round 2 · the agent redid only the N changes you left notes on. Both rounds keep and undo as one step."`)。**Round 1** 以只读方式保留智能体最初版本供对照(编辑、撤回或批注操作返回 `ErrReviewReadOnlyRound`);**Keep**(`⌘↵`)始终将**最新一轮**合并为 `Editor.History` 中的**单个步骤**,按一次 **Undo**(`⌘Z`)即可将全部受影响文件按字节还原至请求前状态。**Notes** 标签用于筛选带批注的改动,挂起时的 **Agent** 面板卡片会显示未发送批注数(`"N notes not sent"`),**Revert all** 对话框也会提示将丢弃未发送批注。

## 智能体任务的系统通知、Dock 角标与播放模式提示点(#1023)

Expand Down
Loading