[PR #5115] [CLOSED] feat(tracker): Inventory Tracker agent with a grid tracker panel #6638

Closed
opened 2026-10-23 04:12:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5115
Author: @augusteo
Created: 8/16/2026
Status: ❌ Closed

Base: staging ← Head: feat/inventory-tracker-agent


📝 Commits (2)

  • d87d626 feat(tracker): add Inventory Tracker agent with a grid tracker panel
  • 3602a13 fix(tracker): enforce inventory exclusivity, migrate panel order, cap quantities

📊 Changes

35 files changed (+1513 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 README.md (+1 -1)
📝 docs/agents/built-in-agents.md (+11 -1)
📝 docs/development/frontend.md (+2 -1)
📝 docs/roleplay/hud-and-trackers.md (+6 -2)
📝 e2e/core-flows.e2e.ts (+1 -1)
➕ e2e/inventory-tracker.e2e.ts (+144 -0)
📝 packages/client/src/components/agents/AgentCatalogView.tsx (+1 -0)
📝 packages/client/src/components/agents/AgentEditor.tsx (+7 -0)
📝 packages/client/src/components/chat/RoleplayHUD.tsx (+137 -1)
📝 packages/client/src/components/chat/RoleplayHUDPanels.tsx (+219 -0)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+4 -0)
📝 packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx (+39 -2)
➕ packages/client/src/features/tracker-panel/components/sections/InventoryTrackerPanel.tsx (+174 -0)
➕ packages/client/src/features/tracker-panel/components/sections/InventoryTrackerRow.tsx (+100 -0)
📝 packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts (+67 -0)
📝 packages/client/src/features/tracker-panel/lib/tracker-panel.constants.ts (+2 -0)
📝 packages/client/src/lib/agent-suite-tracker-slices.ts (+32 -1)
📝 packages/client/src/localization/locales/en.json (+15 -0)
📝 packages/client/src/stores/ui.store.ts (+7 -2)

...and 15 more files

📄 Description

Closes #5105.

Why

In Roleplay Mode the only way to track an inventory is the Custom Tracker agent, and its contract is string-only — CustomTrackerField is { name: string; value: string }, and its prompt says "Values are always strings." An entire inventory therefore collapses into one prose value in one cell, which the panel then truncates at line-clamp-2:

Field Value
Currency 6 silver coins
Inventory Family heirloom longsword, short hunting knife, second…
Equipment Family heirloom longsword sheathed at side; hunting knife…

Expanding the tracker panel does not help — there is no structure to lay out, so a wider column just shows a bigger truncated string. #5051 improved the spacing, which helped, but could not reach the cause. Two more problems fall out of the same shape: the same item appears under both "Inventory" and "Equipment" because nothing makes equipping move it, and currencies, carried items, and worn items are indistinguishable to the UI, so none of them can be laid out well.

Game/GM mode already has a real item grid. This gives Roleplay one.

What

A new inventory-tracker agent result type backed by three new PlayerStats arrays — currencies, equipped, and carried — all sharing one { name, qty } row shape. One row shape means one merge path, one lock-key family, and one row control serve all three groups.

The agent's contract:

{
  "currencies": [{ "name": "Silver coin", "qty": 6 }],
  "equipped":   [{ "name": "Family heirloom longsword" }],
  "inventory":  [{ "name": "Billhook" }, { "name": "Scavenged axe", "qty": 2 }],
  "reasoning":  "Equipped the longsword; picked up a second axe."
}

qty is omitted when 1, so the stored payload stays compact. The prompt is prescriptive by design — the point is to stop the model writing prose: an equipped item appears only in equipped and never in inventory (equipping moves the row across), currencies is money only, names are short noun phrases, duplicates merge by name, and an omitted array means "leave unchanged" rather than "delete", which is the failure mode that made empty tracker output destructive in #2370 and #2724.

The Tracker Panel gains an Inventory section that renders the three groups as grids, sitting between Quest Board and Custom Stats alongside the other sections. The Roleplay HUD gains a matching cycling widget and popover, on both the desktop widget strip and the mobile combined player panel.

Scope note: the new arrays are the agent's own. playerStats.inventory still belongs to the Persona Stats agent and is untouched, so existing chats see no change and either agent can run on its own.

Follow-up

Agent definitions do not live in this repository — packages/server/data/ is gitignored and packages are fetched from Pasta-Devs/Marinara-Agents at runtime. The downloadable inventory-tracker package is a separate PR there. This PR lands first: it is testable on its own (below), and the package is inert without it.

A [docs-i18n] follow-up will be opened for the translated doc packs, per CLAUDE.md.

Changes

  • shared — InventoryTrackerItem and the three PlayerStats arrays; the inventory_tracker_update result type mapped to the edit_trackers capability; inventorySectionTracker* lock keys, namespaced under player.inventoryTracker so they can never collide with the persona-stats player.inventory keys; a new inventory-tracker-fields.ts with group constants, normalization, result parsing, and compact prompt formatting.
  • server — agent-type → result-type mapping and JSON-agent registration; buildLockedInventoryTrackerPatch applying all three groups through one lock pass and emitting a single game_state_patch; apply blocks in both generate.routes.ts and retry-agents-route.ts (this pair has drifted before — see #2729); an Inventory Tracker block in committed tracker context; the marker-expander auto-injection skip-list; the Professor Mari catalog entry.
  • client — the inventory tracker-panel section and its store registration; InventoryTrackerPanel / InventoryTrackerRow reusing the persona inventory shelf's grid idiom; HUD widget and popover; per-group mutations reusing reconcileListUpdate; the agent-suite JSON slice; Agent Editor result-type entry; catalog mode entry; Settings panel section card.
  • docs — docs/roleplay/hud-and-trackers.md, docs/agents/built-in-agents.md, CHANGELOG.md.
  • regressions — the new result type added to the vocabulary assertion and to the retry-anchor loop.

Screenshots

All captured from the running app via Playwright against a seeded chat. Panel at the Expanded width unless noted.

The problem, and the fix

The same inventory, same panel width — as Custom Tracker prose, then as the Inventory Tracker.

Custom Tracker (today) Inventory Tracker (this PR)

Three prose blobs where equipment and inventory repeat each other, versus one row per item with its own quantity. At the narrower panel widths in the report those values also truncate at two lines; here they merely wrap, which is why the row-per-item structure — not extra width — is the fix.

In the tracker side panel, alongside the others

Inventory sits between Quest Board and Custom Stats, in the shared section order and reorderable with the rest.

Editing modes

The section honors the panel's existing add / delete / lock modes. In the lock shot, Family heirloom longsword (name) and Scavenged axe (quantity) are locked, so a tracker re-run leaves them alone.

Add Delete Lock

Empty state and compact width

Groups stay visible when empty so the structure is discoverable before the agent has written anything. At the Compact width the grid collapses to a single column.

Empty Compact width

Roleplay HUD widget

For users who keep the docked panel closed, the compact widget cycles tracked entries and opens the same three groups in a popover.

Review fixes

An adversarial review pass over the first commit found three real bugs, all fixed in the second commit:

  • Equipped and carried could both hold the same item. The per-group merge runs independently, and mergeNamedRowsWithLocks deliberately re-appends a locked row the agent dropped — precisely what happens when a locked carried item gets equipped. Exclusivity is now enforced after merging inside applyTrackerFieldLocksToGameStatePatch, the one choke point both server apply routes and the client's SSE merge pass through.
  • Existing users would never have seen the new section. The persisted UI store stayed at version 93, so Zustand's migrate — which re-normalizes trackerPanelSectionOrder — never ran, leaving every saved five-section order without "inventory". Bumped to 94.
  • Accumulated quantities were unbounded. Two large finite values summed to Infinity, which JSON.stringify writes as null, silently corrupting the stored row. Both the parsed value and the running total are now clamped to a safe integer.

Registering the agent in the official catalog, docs/development/frontend.md, and README.md was likewise not optional — the repo's own prompt regression pins all three.

Validation

Run locally on this branch:

  • pnpm check — passed
  • pnpm regression:agent-runtime — passed, including new Inventory Tracker assertions
  • pnpm regression:roleplay — passed
  • pnpm regression:localization — passed
  • pnpm regression:docs — passed
  • pnpm regression:prompt — passes the agent-catalog coverage check this PR extends. One unrelated assertion, ElevenLabs TTS input does not prepend sprite tone tags, fails — verified to fail identically on a clean origin/staging worktree, so it is pre-existing and out of scope here.
  • e2e/inventory-tracker.e2e.ts (new) — both specs pass under desktop-chromium.

New automated coverage added by this PR:

  • scripts/regressions/agent-runtime.regression.ts — parsing (absent-vs-empty groups, qty defaulting), normalization (dedup by name, clamping), the equipped/carried exclusivity invariant including the locked-row case, and the patch shape (only touched groups streamed; unrelated playerStats fields and the persona-stats inventory left intact).
  • e2e/inventory-tracker.e2e.ts — the panel renders all three groups and every row as its own control with correct quantities, and the section stays hidden when the agent is not enabled.

Test plan

Automated coverage above does not replace a look at the real thing. Reviewer checks:

  • Manually verify in browser: create a custom agent in the Agent Editor with result type Inventory Tracker and the prompt contract above, then send a turn that picks up an item and a turn that equips it — confirm the item moves from Carried to Equipped rather than appearing in both.
  • Manually verify in browser: the HUD widget cycles entries and its popover edits save.
  • Manually verify in browser: the mobile combined player popover shows the Inventory Tracker group and its edits save.
  • Manually verify in browser: add mode, delete mode, and lock mode each work on all three groups; a locked row survives a tracker re-run; deleting a row clears its locks.
  • Manually verify in browser: re-running via the section refresh button and via Retry Failed Agents both apply — these are separate server code paths.
  • Manually verify in browser: with Persona Stats also enabled, its Inventory shelf still works and the two inventories stay independent.
  • Manually verify: an existing install (persisted UI store at version 93) gains the Inventory section after upgrading, without resetting the panel order by hand.
  • Manually verify in browser: light mode — every screenshot above is dark mode; the light palette is unverified.
  • Manually verify in browser: mobile viewport rendering of the section and the combined player popover.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5115 **Author:** [@augusteo](https://github.com/augusteo) **Created:** 8/16/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/inventory-tracker-agent` --- ### 📝 Commits (2) - [`d87d626`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d87d6264de1f1836d0dfeb1123b4e9cb437e0429) feat(tracker): add Inventory Tracker agent with a grid tracker panel - [`3602a13`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3602a138d9cc892d4ce7d528907f7b5b43c8142f) fix(tracker): enforce inventory exclusivity, migrate panel order, cap quantities ### 📊 Changes **35 files changed** (+1513 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `README.md` (+1 -1) 📝 `docs/agents/built-in-agents.md` (+11 -1) 📝 `docs/development/frontend.md` (+2 -1) 📝 `docs/roleplay/hud-and-trackers.md` (+6 -2) 📝 `e2e/core-flows.e2e.ts` (+1 -1) ➕ `e2e/inventory-tracker.e2e.ts` (+144 -0) 📝 `packages/client/src/components/agents/AgentCatalogView.tsx` (+1 -0) 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+7 -0) 📝 `packages/client/src/components/chat/RoleplayHUD.tsx` (+137 -1) 📝 `packages/client/src/components/chat/RoleplayHUDPanels.tsx` (+219 -0) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+4 -0) 📝 `packages/client/src/features/tracker-panel/components/TrackerSectionList.tsx` (+39 -2) ➕ `packages/client/src/features/tracker-panel/components/sections/InventoryTrackerPanel.tsx` (+174 -0) ➕ `packages/client/src/features/tracker-panel/components/sections/InventoryTrackerRow.tsx` (+100 -0) 📝 `packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts` (+67 -0) 📝 `packages/client/src/features/tracker-panel/lib/tracker-panel.constants.ts` (+2 -0) 📝 `packages/client/src/lib/agent-suite-tracker-slices.ts` (+32 -1) 📝 `packages/client/src/localization/locales/en.json` (+15 -0) 📝 `packages/client/src/stores/ui.store.ts` (+7 -2) _...and 15 more files_ </details> ### 📄 Description Closes #5105. ## Why In Roleplay Mode the only way to track an inventory is the Custom Tracker agent, and its contract is string-only — `CustomTrackerField` is `{ name: string; value: string }`, and its prompt says *"Values are always strings."* An entire inventory therefore collapses into one prose value in one cell, which the panel then truncates at `line-clamp-2`: | Field | Value | | --- | --- | | Currency | 6 silver coins | | Inventory | Family heirloom longsword, short hunting knife, second… | | Equipment | Family heirloom longsword sheathed at side; hunting knife… | Expanding the tracker panel does not help — there is no structure to lay out, so a wider column just shows a bigger truncated string. #5051 improved the spacing, which helped, but could not reach the cause. Two more problems fall out of the same shape: the same item appears under both "Inventory" and "Equipment" because nothing makes equipping *move* it, and currencies, carried items, and worn items are indistinguishable to the UI, so none of them can be laid out well. Game/GM mode already has a real item grid. This gives Roleplay one. ## What A new `inventory-tracker` agent result type backed by three new `PlayerStats` arrays — currencies, equipped, and carried — all sharing one `{ name, qty }` row shape. One row shape means one merge path, one lock-key family, and one row control serve all three groups. The agent's contract: ```json { "currencies": [{ "name": "Silver coin", "qty": 6 }], "equipped": [{ "name": "Family heirloom longsword" }], "inventory": [{ "name": "Billhook" }, { "name": "Scavenged axe", "qty": 2 }], "reasoning": "Equipped the longsword; picked up a second axe." } ``` `qty` is omitted when 1, so the stored payload stays compact. The prompt is prescriptive by design — the point is to stop the model writing prose: an equipped item appears only in `equipped` and never in `inventory` (equipping moves the row across), `currencies` is money only, names are short noun phrases, duplicates merge by name, and an omitted array means "leave unchanged" rather than "delete", which is the failure mode that made empty tracker output destructive in #2370 and #2724. The Tracker Panel gains an **Inventory** section that renders the three groups as grids, sitting between Quest Board and Custom Stats alongside the other sections. The Roleplay HUD gains a matching cycling widget and popover, on both the desktop widget strip and the mobile combined player panel. **Scope note:** the new arrays are the agent's own. `playerStats.inventory` still belongs to the Persona Stats agent and is untouched, so existing chats see no change and either agent can run on its own. ## Follow-up Agent definitions do not live in this repository — `packages/server/data/` is gitignored and packages are fetched from `Pasta-Devs/Marinara-Agents` at runtime. The downloadable `inventory-tracker` package is a separate PR there. This PR lands first: it is testable on its own (below), and the package is inert without it. A `[docs-i18n]` follow-up will be opened for the translated doc packs, per `CLAUDE.md`. ## Changes - **shared** — `InventoryTrackerItem` and the three `PlayerStats` arrays; the `inventory_tracker_update` result type mapped to the `edit_trackers` capability; `inventorySectionTracker*` lock keys, namespaced under `player.inventoryTracker` so they can never collide with the persona-stats `player.inventory` keys; a new `inventory-tracker-fields.ts` with group constants, normalization, result parsing, and compact prompt formatting. - **server** — agent-type → result-type mapping and JSON-agent registration; `buildLockedInventoryTrackerPatch` applying all three groups through one lock pass and emitting a single `game_state_patch`; apply blocks in **both** `generate.routes.ts` and `retry-agents-route.ts` (this pair has drifted before — see #2729); an `Inventory Tracker` block in committed tracker context; the marker-expander auto-injection skip-list; the Professor Mari catalog entry. - **client** — the `inventory` tracker-panel section and its store registration; `InventoryTrackerPanel` / `InventoryTrackerRow` reusing the persona inventory shelf's grid idiom; HUD widget and popover; per-group mutations reusing `reconcileListUpdate`; the agent-suite JSON slice; Agent Editor result-type entry; catalog mode entry; Settings panel section card. - **docs** — `docs/roleplay/hud-and-trackers.md`, `docs/agents/built-in-agents.md`, `CHANGELOG.md`. - **regressions** — the new result type added to the vocabulary assertion and to the retry-anchor loop. ## Screenshots All captured from the running app via Playwright against a seeded chat. Panel at the **Expanded** width unless noted. ### The problem, and the fix The same inventory, same panel width — as Custom Tracker prose, then as the Inventory Tracker. | Custom Tracker (today) | Inventory Tracker (this PR) | | --- | --- | | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/01-before-custom-tracker.png" width="420"> | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/02-after-inventory-tracker.png" width="420"> | Three prose blobs where equipment and inventory repeat each other, versus one row per item with its own quantity. At the narrower panel widths in the report those values also truncate at two lines; here they merely wrap, which is why the row-per-item structure — not extra width — is the fix. ### In the tracker side panel, alongside the others Inventory sits between Quest Board and Custom Stats, in the shared section order and reorderable with the rest. <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/07-full-panel.png" width="420"> ### Editing modes The section honors the panel's existing add / delete / lock modes. In the lock shot, `Family heirloom longsword` (name) and `Scavenged axe` (quantity) are locked, so a tracker re-run leaves them alone. | Add | Delete | Lock | | --- | --- | --- | | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/03-add-mode.png" width="280"> | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/04-delete-mode.png" width="280"> | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/05-lock-mode.png" width="280"> | ### Empty state and compact width Groups stay visible when empty so the structure is discoverable before the agent has written anything. At the Compact width the grid collapses to a single column. | Empty | Compact width | | --- | --- | | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/06-empty-state.png" width="320"> | <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/09-compact-profile.png" width="280"> | ### Roleplay HUD widget For users who keep the docked panel closed, the compact widget cycles tracked entries and opens the same three groups in a popover. <img src="https://raw.githubusercontent.com/augusteo/Marinara-Engine/pr-assets/inventory-tracker/shots/10-hud-popover.png" width="500"> ## Review fixes An adversarial review pass over the first commit found three real bugs, all fixed in the second commit: - **Equipped and carried could both hold the same item.** The per-group merge runs independently, and `mergeNamedRowsWithLocks` deliberately re-appends a locked row the agent dropped — precisely what happens when a locked carried item gets equipped. Exclusivity is now enforced after merging inside `applyTrackerFieldLocksToGameStatePatch`, the one choke point both server apply routes and the client's SSE merge pass through. - **Existing users would never have seen the new section.** The persisted UI store stayed at version `93`, so Zustand's `migrate` — which re-normalizes `trackerPanelSectionOrder` — never ran, leaving every saved five-section order without `"inventory"`. Bumped to `94`. - **Accumulated quantities were unbounded.** Two large finite values summed to `Infinity`, which `JSON.stringify` writes as `null`, silently corrupting the stored row. Both the parsed value and the running total are now clamped to a safe integer. Registering the agent in the official catalog, `docs/development/frontend.md`, and `README.md` was likewise not optional — the repo's own prompt regression pins all three. ## Validation Run locally on this branch: - `pnpm check` — passed - `pnpm regression:agent-runtime` — passed, including new Inventory Tracker assertions - `pnpm regression:roleplay` — passed - `pnpm regression:localization` — passed - `pnpm regression:docs` — passed - `pnpm regression:prompt` — passes the agent-catalog coverage check this PR extends. One unrelated assertion, `ElevenLabs TTS input does not prepend sprite tone tags`, fails — **verified to fail identically on a clean `origin/staging` worktree**, so it is pre-existing and out of scope here. - `e2e/inventory-tracker.e2e.ts` (new) — both specs pass under `desktop-chromium`. New automated coverage added by this PR: - `scripts/regressions/agent-runtime.regression.ts` — parsing (absent-vs-empty groups, qty defaulting), normalization (dedup by name, clamping), the equipped/carried exclusivity invariant including the locked-row case, and the patch shape (only touched groups streamed; unrelated `playerStats` fields and the persona-stats inventory left intact). - `e2e/inventory-tracker.e2e.ts` — the panel renders all three groups and every row as its own control with correct quantities, and the section stays hidden when the agent is not enabled. ## Test plan Automated coverage above does not replace a look at the real thing. Reviewer checks: - [ ] Manually verify in browser: create a custom agent in the Agent Editor with result type **Inventory Tracker** and the prompt contract above, then send a turn that picks up an item and a turn that equips it — confirm the item **moves** from Carried to Equipped rather than appearing in both. - [ ] Manually verify in browser: the HUD widget cycles entries and its popover edits save. - [ ] Manually verify in browser: the mobile combined player popover shows the Inventory Tracker group and its edits save. - [ ] Manually verify in browser: add mode, delete mode, and lock mode each work on all three groups; a locked row survives a tracker re-run; deleting a row clears its locks. - [ ] Manually verify in browser: re-running via the section refresh button and via Retry Failed Agents both apply — these are separate server code paths. - [ ] Manually verify in browser: with Persona Stats also enabled, its Inventory shelf still works and the two inventories stay independent. - [ ] Manually verify: an existing install (persisted UI store at version 93) gains the Inventory section after upgrading, without resetting the panel order by hand. - [ ] Manually verify in browser: **light mode** — every screenshot above is dark mode; the light palette is unverified. - [ ] Manually verify in browser: mobile viewport rendering of the section and the combined player popover. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:12:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6638
No description provided.