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,55 @@
# Agent Note: Row-by-row Data Table agent review with lossless Keep and MCP check figures

Status: implemented

## Problem

Agents can edit versioned YAML data tables with dozens of records (such as shop price or loot rebalances), but reviewing those changes line-by-line in a raw text diff obscures numeric percentage deltas (`old → new` and `Δ%`), makes reverting individual records error-prone, and offers no way for the agent to attach verifiable check figures (like playtest-derived coin-rate metrics) that turn stale once the person reverts or tweaks rows (#1033). Meanwhile, saving kept changes must preserve the Data Table editor's lossless guarantee from [Data Table editor](2026-11-25-datatable-editor.md): a kept change to one cell changes only that line, and one Undo restores the original file byte for byte.

## Decision

Add a dedicated full-window Data Table review mode (`packages/game/editor/datatable_review.go` and `packages/game/editor/datatable_review_ui.go`) backed by `datatable.Document` line metadata (`RowLine` / `CellLine` in `packages/game/tooling/datatable/document.go`) and three MCP tools in `packages/game/editor/editormcp/datatable_review.go`:

- **Record matching and lossless Keep composition**:
- Each file in a turn pairs `Base` and `Proposed` rows by a unique identity column (`id`, falling back to `key`, `slug`, `name`, or row index).
- On `KeepDataTableReview`, when no rows were added, removed, or reordered, `composeDataTableReviewFile` clones `f.base` (preserving its raw bytes) and invokes `doc.SetCell` only on non-reverted cells whose active value (proposed or person-edited) differs from `base`. `datatable.Document.Marshal` then patches only those exact lines in `raw`, leaving reverted records, untouched fields, comments, and blank lines byte-for-byte identical.
- When rows were added, removed, or reordered, composition still starts from `f.base.Clone()` and applies `DeleteRow` / `AppendRow` / `SetCell` / `MoveRow` on the YAML AST so untouched rows keep their key order and comments.
- All file writes in a Keep commit run inside one `dataTableReviewKeepCmd` on `Editor.History`, recording exact pre-Keep bytes and file existence so a single `Undo()` restores every file byte for byte (and deletes newly created files).
- **Interactive review surface (`DataTableReviewView`)**:
- Uses exclusively `SpecPalette` tokens (`Dark` and `Light`), matching `docs/design/editor/ReviewData.dc.html` and `Spec.dc.html` (including `p.Accent.OnFill` on `p.Accent.Fg` for the Keep button to meet WCAG 2.2 AA contrast).
- Left rail shows all turn files (`27 of 40 changed`, `new · 0 records`) and the **Agent's check** card (`DataTableReviewCheck`: `Label`, `Value`, `Before`, `Basis`). Any user revert, restore, cell edit, or row reorder sets `checksOutOfDate = true`, displaying a warning badge until refreshed via `SetDataTableReviewChecks` / `datatable_review_checks`.
- Center pane renders the empty-file message (`"No records — ask the agent to add some"`) when a table has 0 rows, or the filter chip bar (`All`, `Changed`, `Unchanged`, `Reverted`, `Yours`), search input, and sortable table (`CycleDataTableReviewSort`, `DataTableReviewAriaSort`). Numeric columns with changes show a `Δ` header and sort by percentage delta without mutating file order; zero numeric values render as `—`; changed cells use dashed `Changed` borders while person-edited cells switch to solid `Accent` borders.
- In-place cell edits (`SetDataTableReviewCellText` / `StepDataTableReviewCellNumber`) validate against any registered `datatable.RowType` or inferred `ValueKind` and join the review under `Yours`; drag-to-reorder uses `dragdrop.Area`/`Source`/`Target` calling `ReorderDataTableReviewRecord` and also joins under `Yours`.
- Right pane shows the focused record's YAML with real 1-based line numbers from `Document.CellLine`, `+`/`-` diff styling, and trailing `you` tags on person-edited or reordered lines.
- Pressing `Esc` (`PauseDataTableReview`) pauses the review while keeping `HasOpenReview()` true (pausing autosave), showing a `"Review paused"` toast with a **Resume** action and a pending review card in `AgentPanelView` (without duplicating `RightRailView`, `AgentPanelView`, or `AgentTurn`).
- **MCP tools (`packages/game/editor/editormcp/datatable_review.go`)**:
- `datatable_review_propose` validates proposed YAML files against `datatable.ParseDocument` and any registered `RowType` and opens the review without touching disk.
- `datatable_review_checks` attaches or refreshes named check figures and clears `checksOutOfDate`.
- `datatable_review_status` returns open/paused state, per-file counts, active record statuses, current checks, and `checksOutOfDate`.

## Alternatives considered

### Compose Keep by saving `Proposed` and rolling back reverted rows

Applying reverts on top of `Proposed` instead of applying kept edits on top of `Base` would lose `Base`'s exact raw bytes, comments, blank lines, and indentation whenever the agent re-serialized `Proposed`. Starting from `Base.Clone()` and patching only kept/edited cells via `SetCell` guarantees byte-exact preservation of untouched and reverted lines.

### Recompute agent check figures automatically inside the editor on user edits

The editor cannot generically know how an agent derived domain-specific figures (such as coin rates from 20 playtests of floor 3). Marking the attached figures **Out of date** on any revert, edit, or reorder and exposing `checksOutOfDate` through `datatable_review_status` lets the agent recompute them accurately and push fresh numbers with `datatable_review_checks`.

### Render Data Table review inside the bottom `DataTablePanelView`

A 256 pt bottom panel cannot comfortably host the three-column file list, agent's check card, 40-row sortable `old → new` table, and focused YAML diff simultaneously. Mounting `DataTableReviewView` as a full-window screen in `EditorView` matches `ReviewData.dc.html` and the existing full-window `ChangesPanelView` / `PlaytestReportView` screens while leaving `DataTablePanelView` untouched for direct editing.

## Consequences

- Designers can review multi-file agent data table turns row by row, sort by numeric `Δ%`, revert individual records, tweak values in place, reorder rows, inspect focused YAML diffs with `you` tags, pause/resume via `Esc`, and keep changes in one lossless, single-undo step.
- Agents can propose data table reviews and attach/refresh verifiable check figures over MCP, and detect when user edits have invalidated prior figures.
- Structural changes (reordering, adding, or removing rows) still fall back to AST serialization via `yaml.v3` with 2-space indentation, matching the trade-off documented in [Data Table editor](2026-11-25-datatable-editor.md).

## Verification

- `cd packages/game && env -u GOROOT go tool nsgo test ./tooling/datatable`: verifies `RowLine` and `CellLine` line-number tracking alongside existing lossless round-trip tests.
- `cd packages/game && TMPDIR=/tmp env -u GOROOT go tool nsgo test ./editor -run "TestDataTableReview|TestLocaleCatalogsComplete"`: verifies the 27-of-40 shop review, sorting by `price Δ` with `aria-sort`, reverting two records, editing one value, lossless kept-only line diffs, single-step byte-for-byte Undo, out-of-date agent check figures on revert/edit/reorder, `Esc` pause/resume toast and Agent panel card, and real macOS `nsgotest` screenshots in Dark and Light appearances.
- `cd packages/game && TMPDIR=/tmp env -u GOROOT go tool nsgo test ./editor/editormcp -run TestDataTableReview`: verifies `datatable_review_propose`, `datatable_review_status`, and `datatable_review_checks` end-to-end.
- `cd packages/game && env -u GOROOT go tool nsgo check` (host and `-target ios`) on `./tooling/datatable`, `./editor`, and `./editor/editormcp`, plus `env -u GOROOT go run ./tools/changelog check` and `bun run verify-notes`.
3 changes: 3 additions & 0 deletions changelog.d/editor-review-datatable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- `game/editor`, `game/editor/editormcp`, `game/tooling/datatable`: add full-window row-by-row Data Table review (`DataTableReviewView`, `OpenDataTableReview`, `datatable_review_propose`, `datatable_review_checks`, `datatable_review_status`) with old → new and `Δ%` cells, sortable `aria-sort` column headers, filter chips (`All`, `Changed`, `Unchanged`, `Reverted`, `Yours`), in-place value editing, drag-to-reorder, right-hand `+/-` YAML diff with `you` tags, out-of-date agent check figures, `Esc` pause/resume toast, lossless single-line Keep saves, and single-step Undo (#1033).
10 changes: 10 additions & 0 deletions docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ if err := editor.RegisterDataTableType[Enemy](ed, "data/enemies/*.yaml"); err !=
}
```

### Reviewing an agent's data table changes (#1033)

When an agent proposes changes to one or more data table files (through `Editor.OpenDataTableReview` or the `datatable_review_propose` MCP tool), the editor opens a full-window row-by-row Data Table review (`DataTableReviewView`) using exclusively the editor's design spec tokens:

- **Turn files and empty tables**: the left sidebar lists every data table touched in the turn (`27 of 40 changed`, `new · 0 records`); selecting a newly created empty file shows `"No records — ask the agent to add some"`.
- **Filter chips, search, and sorting**: switch between **All**, **Changed**, **Unchanged**, **Reverted**, and **Yours** chips with live counts (`SetDataTableReviewFilter`), search across all fields (`SetDataTableReviewSearch`), and click any column header (`CycleDataTableReviewSort`) to cycle ascending, descending, and back to file order (reporting `aria-sort` via `DataTableReviewAriaSort`). Numeric columns with changes show a `Δ` header and sort by percentage delta without mutating file order.
- **Old → new cells, in-place edits, and drag-to-reorder**: changed cells render in the Spec `changed` dashed pill showing struck-through old value `→` new value and `Δ%`, while numeric zeros render as `—` (`FormatReviewCellValue`). Each changed record has its own **Revert** / **Restore** button (`ToggleDataTableReviewRecord`). Clicking a cell value edits it in place (`StartDataTableReviewCellEdit`, `SetDataTableReviewCellText`, `StepDataTableReviewCellNumber`) and dragging a row's grip handle reorders it (`ReorderDataTableReviewRecord`); both join the review under **Yours** with a solid accent border and a `you` tag in the right-hand YAML diff pane (`DataTableReviewFocusedYAML`).
- **Agent's check figures**: the agent attaches named figures (`DataTableReviewCheck`: label, value, optional value before the request, and basis) via `SetDataTableReviewChecks` or the `datatable_review_checks` MCP tool. Any person revert, restore, in-place edit, or row reorder marks those figures **Out of date** (`DataTableReviewChecksOutOfDate`) until the agent refreshes them.
- **Pause, lossless Keep, and single-step Undo**: pressing `Esc` or **Editor** pauses the review (`PauseDataTableReview`), keeping autosave paused (`HasOpenReview`) and showing a `"Review paused"` toast with **Resume** plus a pending review card in the Agent panel (`ResumeDataTableReview`). **Keep N of M** (`KeepDataTableReview`, `⌘↵`) starts from the original parsed `datatable.Document` bytes and patches only the kept and edited lines so untouched and reverted lines stay byte-for-byte identical, committing every file in **one atomic Undo step** (`Undo` restores all files byte for byte and removes newly created files). **Revert all** (`RevertAllDataTableReview`, `⌘⌫`) closes the review cleanly without modifying disk and stays undoable with `⌘Z`.

### 2D viewport navigation (#864)

The 2D viewport's canvas fills its panel and shows the scene through the editor's own view (`View2D`: the world point at the canvas's center, a zoom and a rotation), separate from the scene's `camera`, so a level larger than one screen can be seen and edited anywhere. The view is never saved to the scene nor recorded in the undo history.
Expand Down
3 changes: 3 additions & 0 deletions docs/en/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ claude mcp add game-editor -- nsgo game mcp
| `history_list` | read | `author` (`"all"`, `"you"`, `"agent"`), `limit` (optional) | Lists the editor's unified History timeline of manual edits, agent turns, and saved points, newest first. |
| `permissions_draft` | read | `request` (optional), `rules` (required) | Opens a You-only permissions draft card with nothing ticked by default; never modifies `permissions.yaml` directly. |
| `game_delete_file` | delete | `file` (required), `reason` (optional) | Turned off by default in **Settings › Tools** (not offered to connected clients until enabled). When enabled, proposes deleting a project file in the Review changes panel with its line count and scene usages without touching disk until confirmed (refusing You-only files, symlinks, `.git/**`, `game.yaml`, open scene tabs, and >1 MiB files). |
| `datatable_review_propose` | edit | `files` (required), `prompt`, `checks` (optional) | Validates one or more version-1 YAML data table files against `datatable.ParseDocument` (and any registered Go row type) and opens the row-by-row Data Table review screen with old → new, `Δ%`, per-record Revert/Restore, and optional named agent check figures without modifying disk until Keep. |
| `datatable_review_checks` | edit | `checks` (required) | Attaches or refreshes named agent check figures (`label`, `value`, `before`, `basis`) on the active Data Table review and clears `checksOutOfDate` after the person reverts, edits, or reorders records. |
| `datatable_review_status` | read | `file` (optional) | Reports the active Data Table review's files, kept/reverted/user-edited counts, active record states, attached check figures, and whether `checksOutOfDate` is true. |

Every tool registered on the editor's MCP server can be turned on or off per computer in **Settings › Tools** (`Editor.SetMCPToolEnabled`): disabling a tool removes it from the server's advertised tool list (`tools/list_changed`) and returns a readable refusal if called. Outbound content categories in **Settings › Usage and privacy** (**WHAT MAY LEAVE THIS COMPUTER**: Scene and data files, Viewport images, Go source code, Art and audio files) are enforced for every connected agent across all tools (including symlink-resolved file paths) and all resources (`editor://scene`, `editor://selection`, `editor://agent/turn`, `editor://brief`, `editor://rules`, `editor://context`), refusing calls with the reason whenever the requested content kind is switched off. Additional MCP servers configured in **Settings › Tools** (starting with `nsgo-game` for the running game via `go tool nsgo mcp`) are synced into `.mcp.json` and `.codex/config.toml` via `editormcp.InstallWithServers`.

Expand Down
10 changes: 10 additions & 0 deletions docs/zh/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ if err := editor.RegisterDataTableType[Enemy](ed, "data/enemies/*.yaml"); err !=
}
```

### 逐行审查智能体的数据表改动(#1033)

当智能体为一个或多个数据表文件提出修改建议时(通过 `Editor.OpenDataTableReview` 或 `datatable_review_propose` MCP 工具),编辑器会打开全窗口的逐行数据表审查界面(`DataTableReviewView`),完全采用设计规范配色与控件令牌:

- **本轮文件与空数据表**:左侧栏列出本轮涉及的每个数据表文件(如 `27 of 40 changed`、`new · 0 records`);选中尚无记录的新建数据表时显示 `"No records — ask the agent to add some"`(中文界面为“暂无记录 — 请让智能体添加一些”)。
- **筛选标签、搜索与排序**:支持带实时计数的 **All / Changed / Unchanged / Reverted / Yours** 筛选标签(`SetDataTableReviewFilter`)、跨列实时筛选输入框(`SetDataTableReviewSearch`),以及点击任意列头在升序、降序与文件原序之间循环排序(`CycleDataTableReviewSort`,通过 `DataTableReviewAriaSort` 暴露 `aria-sort` 状态)。含改动的数值列以 `Δ` 标注列头并按涨跌幅百分比排序,且不改写底层文件行顺序。
- **旧值 → 新值单元格、就地编辑与拖拽重排**:有改动的单元格采用设计规范 `changed` 虚线胶囊显示删除线旧值 `→` 新值及 `Δ%`,数值 `0` 显示为 `—`(`FormatReviewCellValue`)。每条改动记录提供独立的 **Revert / Restore** 按钮(`ToggleDataTableReviewRecord`)。点击单元格可就地修改新值(`StartDataTableReviewCellEdit`、`SetDataTableReviewCellText`、`StepDataTableReviewCellNumber`),拖动行首手柄可重排记录顺序(`ReorderDataTableReviewRecord`);两者都会作为你的编辑纳入本次审查,以实线强调边框显示、可由 **Yours** 标签筛选,并在右侧焦点记录的 `+`/`-` YAML 差异面板(`DataTableReviewFocusedYAML`)中标注 `you`。
- **智能体核验指标**:智能体可通过 `SetDataTableReviewChecks` 或 `datatable_review_checks` MCP 工具为本轮审查附上具名核验指标(`DataTableReviewCheck`:指标名、当前值、请求前的值及测算依据)。一旦作者还原、恢复、就地编辑或重排记录,指标会被标记为 **已过期**(`DataTableReviewChecksOutOfDate`),直到智能体重新刷新。
- **暂停审查、无损保留与单步撤销**:按 `Esc` 或点击 **Editor** 会暂停审查(`PauseDataTableReview`),继续暂停自动保存(`HasOpenReview`),并弹出带 **Resume** 按钮的“审查已暂停”提示条,同时在 Agent 面板中展示待继续卡片(`ResumeDataTableReview`)。点击 **Keep N of M**(`KeepDataTableReview`、`⌘↵`)会基于原始 `datatable.Document` 字节仅修补保留与编辑过的单元格行,未改动行与已还原行保持逐字节不变,并将所有文件变更合并为**单个原子撤销步骤**(一次 `Undo` 即可逐字节还原原文件并删除本轮新建的文件)。**Revert all**(`RevertAllDataTableReview`、`⌘⌫`)不触碰磁盘文件并支持通过 `⌘Z` 撤销恢复审查。

### 2D 视口导航(#864)

2D 视口的画布填满所在面板,并通过编辑器自己的视图(`View2D`:画布中心对应的世界坐标点、缩放和旋转)显示场景,它与场景的 `camera` 相互独立,因此比一屏更大的关卡在任何位置都能看到和编辑。视图从不保存到场景中,也不记入撤销历史。
Expand Down
Loading
Loading