feat: nation-op split/merge review — dialog (part list + successor radio, merge name), docs (P4b, #16)
This commit is contained in:
@@ -68,13 +68,13 @@ history/
|
||||
├── shared/ # NO runtime deps — the single source of truth
|
||||
│ ├── types.ts # domain types (Nation, GameState, RoundItem, Preset, …)
|
||||
│ └── protocol.ts # LLM TurnResult schema (incl. `unowned`, v0.22 #16 P3, and
|
||||
│ # `nationOps`, v0.23 #16 P4a) + AddAction/AddDiplomacy/RemoveQueueItem/
|
||||
│ # `nationOps`, v0.23 #16 P4a; v0.24 #16 P4b) + AddAction/AddDiplomacy/RemoveQueueItem/
|
||||
│ # Jump + NationOp confirm/reject request types + pure helpers
|
||||
├── server/
|
||||
│ ├── index.ts # Express: /api/* (health|action|diplomacy|queue/remove|jump|advisor|
|
||||
│ │ # nation-op/confirm|nation-op/reject|games|map|presets), /sse/:id; reads
|
||||
│ │ # PORT/LLM_*/DATA_DIR
|
||||
│ ├── engine.ts # pure: prompts / parse+validate / applyTurnResult (sole-ownership + no-man's-land releases, v0.22 #16 P3) / runTurn (tool path + plain fallback) / getNeighbours tool + executor / playerFrontier / queue ops / advisor / nation-op ops (resolveNationRef / applyNationOp / confirmNationOp / rejectNationOp, v0.23 #16 P4a)
|
||||
│ ├── engine.ts # pure: prompts / parse+validate / applyTurnResult (sole-ownership + no-man's-land releases, v0.22 #16 P3) / runTurn (tool path + plain fallback) / getNeighbours tool + executor / playerFrontier / queue ops / advisor / nation-op ops (resolveNationRef / freshNationId / NEW_NATION_STATS / applyNationOp rename+split+merge / confirmNationOp / rejectNationOp, v0.23 #16 P4a; v0.24 #16 P4b)
|
||||
│ ├── llm.ts # LlmClient: chat() + chatWithTools() (bounded function-calling loop), injectable transport, retry+backoff, logging + env config
|
||||
│ ├── regions.ts # turf-free region-key data access: load manifest/geo/adjacency (public/ then dist/), country→keys expansion, reference table, neighboursOf/hasAdjacency
|
||||
│ ├── stub.ts # deterministic LLM transport (tests/e2e): one frontier conquest per turn + ADVISOR_MARKER
|
||||
@@ -96,7 +96,7 @@ history/
|
||||
├── WorldMap.tsx # MapLibre basemap + choropleth + click→dossier + hover tooltip + player highlight
|
||||
├── NationPanel.tsx # a nation's stats/territory/diplomacy dossier
|
||||
├── ActionPanel.tsx # tabs: Action / Diplomacy / Advisor + pending-queue list (per-item trash button + confirm dialog) + "Jump forward" + "Nation proposals" trigger (v0.23 #16 P4a)
|
||||
├── NationOpDialog.tsx # review LLM-proposed nation ops (rename/split/merge) — confirm (editable rename) or reject (v0.23 #16 P4a)
|
||||
├── NationOpDialog.tsx # review LLM-proposed nation ops (rename/split/merge) — confirm (editable rename/merge name, split successor radio) or reject (v0.24 #16 P4b)
|
||||
├── EventFeed.tsx # scrolling event log (newest first)
|
||||
├── FloatingWindow.tsx # the HUD window primitive — free-floating (draggable, position persisted), or `pinned` (fixed top-center bar), or `dock`ed (full-height left/right column); renders dock controls when `onDockChange` is set
|
||||
├── StatBar.tsx
|
||||
@@ -189,24 +189,44 @@ history/
|
||||
— the distinction is decided by the client from `GameState.unowned` (via `regionFillStyle` /
|
||||
`unownedTooltipLabel`), never by the `RegionMap`, which only knows "owned" vs "absent". A fresh
|
||||
game always starts with `unowned: []` (legacy SQLite rows load with it defaulted).
|
||||
- **Nation ops — “LLM proposes, player confirms” (v0.23, #16 P4a).** `TurnResult.nationOps` (required
|
||||
in the schema) carries the LLM’s proposed **`NationOp`s** — a discriminated union of `rename` /
|
||||
`split` / `merge`. `rename` is fully applied; `split` and `merge` are **declared shapes only**
|
||||
(accepted and stored as pending, but a no-op until P4b implements them). Each op names its target
|
||||
via `nationRef` — the LLM may use a nation’s **id or name**; `resolveNationRef` resolves id-first,
|
||||
then a case-insensitive unique-name match, and returns `null` for an unknown or ambiguous ref (such
|
||||
ops are dropped defensively in `validateNationOps`, never thrown). A turn’s ops are appended to
|
||||
`GameState.pendingNationOps`, which is **never cleared on a turn commit** — pending proposals persist
|
||||
across turns until resolved (like the action queue). The player then decides per op via
|
||||
`POST /api/games/:id/nation-op/confirm` (`{index, edits?{name?}}`) or `.../nation-op/reject`
|
||||
(`{index}`): `confirmNationOp` applies the op to a clone (a rename sets `Nation.name` to the edited
|
||||
value or, failing that, the proposed `to`; id / territory / relations / `playerNationId` stay valid,
|
||||
so a renamed player is re-named in place) and `rejectNationOp` just drops it — both splice by index
|
||||
and bump `version` once (an invalid index → `null` → HTTP 400). The response is `{ game }` and the
|
||||
server broadcasts a version-bumped SSE `state`, so every tab’s version-guarded `applyState` stays in
|
||||
sync. The client lists the pending ops in a “Nation proposals” dialog (in the “Your move” panel) with
|
||||
an editable rename name plus Confirm / Reject. The stub never proposes a nation op (`nationOps: []`),
|
||||
so this path is covered by unit tests only (`server/engine.test.ts`).
|
||||
- **Nation ops — “LLM proposes, player confirms” (v0.23, #16 P4a; v0.24, #16 P4b).**
|
||||
`TurnResult.nationOps` (required in the schema) carries the LLM’s proposed **`NationOp`s** — a
|
||||
discriminated union of `rename` / `split` / `merge`, all three of which are now applied on confirm
|
||||
(P4b implemented split/merge). Each op names its target via `nationRef` — the LLM may use a
|
||||
nation’s **id or name**; `resolveNationRef` resolves id-first, then a case-insensitive
|
||||
unique-name match, and returns `null` for an unknown or ambiguous ref (such ops are dropped
|
||||
defensively in `validateNationOps`, never thrown). A turn’s ops are appended to
|
||||
`GameState.pendingNationOps`, which is **never cleared on a turn commit** — pending proposals
|
||||
persist across turns until resolved (like the action queue). The player then decides per op via
|
||||
`POST /api/games/:id/nation-op/confirm` (`{index, edits?{name?, playerPart?}}`) or
|
||||
`.../nation-op/reject` (`{index}`): `confirmNationOp` applies the op to a clone — **rename** sets
|
||||
`Nation.name` to the edited value or, failing that, the proposed `to` (id / territory / relations /
|
||||
`playerNationId` stay valid, so a renamed player is re-named in place); **split** (the parent
|
||||
must resolve and have ≥2 named parts, else a no-op) partitions the parent’s region-key territory
|
||||
into new nations in parts order — each new nation gets a fresh id (`freshNationId`: first free of
|
||||
`n1`, `n2`, …) and the baseline `NEW_NATION_STATS` (not a copy of the parent’s), plus a copy of
|
||||
the parent’s relations; a key named by several parts goes to the first, and the parent’s
|
||||
unclaimed keys go to part 0 (in territory order), so sole ownership holds and nothing is
|
||||
orphaned; if the parent was the player’s nation, `playerNationId` moves to the part chosen by
|
||||
`edits.playerPart` (clamped into range, default 0), which also receives `edits.name`; **merge**
|
||||
(every ref must resolve, ≥2 DISTINCT inputs, and the survivor must be one of them, else a
|
||||
no-op) folds the inputs into the survivor, which keeps its id and its own stats, gains the
|
||||
union of the inputs’ territories (the survivor’s keys first) and a union of their relations
|
||||
(the survivor’s own view of a third party wins, else the first input’s), is renamed
|
||||
`edits.name` → `into` → its own name, while the other inputs are removed and their ids dropped
|
||||
from every remaining nation’s relations maps; if the player led a removed input,
|
||||
`playerNationId` moves to the survivor. An op that is invalid at confirm time (an ambiguous ref,
|
||||
…) is a no-op on the world but is still removed — and `rejectNationOp` just drops it; both
|
||||
splice by index and bump `version` once (an invalid index → `null` → HTTP 400). The response is
|
||||
`{ game }` and the server broadcasts a version-bumped SSE `state`, so every tab’s
|
||||
version-guarded `applyState` stays in sync. The client lists the pending ops in a “Nation
|
||||
proposals” dialog (in the “Your move” panel): a rename and a merge show an editable name field
|
||||
(the merge also highlights the survivor among the input chips); a split lists each part (name +
|
||||
proposed region count) with a successor radio that appears only when the parent is the player’s
|
||||
own nation (preselected part 0 — the choice is always valid). The system prompt documents all
|
||||
three op shapes as a proposal queue (at most 1–2 per turn, each narrated in events). The stub
|
||||
never proposes a nation op (`nationOps: []`), so this path is covered by unit tests only
|
||||
(`server/engine.test.ts`).
|
||||
- **Map click → dossier target (owner resolved from the RegionMap, by region key).**
|
||||
Clicking a sub-region does NOT open a popup — it switches the dossier to that sub-region's
|
||||
owning nation (`focusNation(ownerId, {name})` in `App.tsx`, which also records which region was
|
||||
@@ -233,9 +253,9 @@ history/
|
||||
no man's land (it always returns `unowned: []` and ignores the payload's `unowned` field) — its
|
||||
one-conquest behavior is what the e2e assertions rely on, so the release/re-claim path is
|
||||
covered by unit tests only (`server/engine.test.ts`, `server/map.test.ts`). Since v0.23 (#16 P4a)
|
||||
the stub also returns `nationOps: []` — it **never proposes** a nation op (rename/split/merge), so
|
||||
the confirm/reject path is covered by unit tests only, mirroring the P3 approach; all e2e
|
||||
assertions are unaffected. The stub answers plain `content` (never tool calls), so it naturally
|
||||
the stub also returns `nationOps: []` — it **never proposes** a nation op (rename/split/merge;
|
||||
still true since P4b implemented split/merge), so the confirm/reject path is covered by unit
|
||||
tests only, mirroring the P3 approach; all e2e assertions are unaffected. The stub answers plain `content` (never tool calls), so it naturally
|
||||
bypasses the tool loop in a single round. Unit + e2e assertions rely on these exact values, so
|
||||
keep the stub deterministic.
|
||||
- **HUD layout.** The game screen is a full-viewport map (z-0) with `FloatingWindow` overlays. The
|
||||
|
||||
Reference in New Issue
Block a user