[PR #5922] [MERGED] feat(game): the GM writes back to Experience packages through declared verbs (#5798) #6991

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5922
Author: @kolacheee
Created: 9/7/2026
Status: ✅ Merged
Merged: 9/7/2026
Merged by: @kolacheee

Base: staging ← Head: feat/5798-gm-verb-runtime


📝 Commits (10+)

  • 4dae701 feat(capability): gated reader for a package's GM verb table (#5798)
  • ea191f5 feat(capability): engine-generic GM verb executor for both effects (#5798)
  • 5d5ea05 feat(game): render, parse and execute package GM verbs on a game turn (#5798)
  • faceb0b feat(client): handle gm_verb in both SSE switches, and metadata_patch in the retry twin (#5798)
  • 3b488bb feat(capability): advertise capability API 1.16 (#5798)
  • c2dd8e5 test(capability): behavioral regression for the GM verb runtime (#5798)
  • 5c3200b fix(capability): fold GM verb tag names locale-independently (#5798)
  • a4ad584 docs(capability): name the two unstated GM verb behaviors (#5798)
  • 6a78b9b test(capability): make the GM verb byte-ceiling pin discriminate (#5798)
  • ce8a5aa fix(capability): teach GM verb argument vocabularies from the table (#5798)

📊 Changes

17 files changed (+1971 additions, -37 deletions)

View changed files

📝 CHANGELOG.md (+4 -1)
📝 docs/development/optional-agent-packages.md (+35 -11)
➕ e2e/game-verb-only-turn.e2e.ts (+172 -0)
📝 packages/client/src/components/game/GameNarration.tsx (+25 -1)
📝 packages/client/src/hooks/use-generate.ts (+40 -0)
📝 packages/server/src/routes/generate.routes.ts (+117 -1)
📝 packages/server/src/routes/generate/spatial-transition-request.ts (+8 -1)
📝 packages/server/src/services/capability-packages/capability-command-registry.service.ts (+18 -6)
➕ packages/server/src/services/capability-packages/capability-gm-verb-runtime.service.ts (+438 -0)
📝 packages/server/src/services/capability-packages/package-manager.service.ts (+90 -0)
📝 packages/server/src/services/game/gm-prompts.ts (+11 -0)
📝 packages/shared/src/index.ts (+1 -0)
📝 packages/shared/src/schemas/capability-package.schema.ts (+5 -1)
📝 scripts/regressions/capability-conversation-actions.regression.ts (+5 -1)
➕ scripts/regressions/capability-gm-verb-runtime.regression.ts (+977 -0)
📝 scripts/regressions/capability-gm-verbs.regression.ts (+20 -9)
📝 scripts/regressions/capability-package-lifecycle.regression.ts (+5 -5)

📄 Description

Warning

Stack note — this PR is stacked on the GM verb schema PR. Merge that one first. Until it merges, the diff below also contains its five commits (the shared schema file, its docs section, its regression and its CHANGELOG line). Review those there, not here; once it lands, this diff shrinks to the eleven commits that add the runtime.

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5798

Why this change

An Experience package can read a chat and cannot write to it. The host hands the package props every turn and dispatches a small set of engine-defined events at it, but nothing carries anything the model said. So when the GM narrates the storm rolling in, the package never hears; the sky stays fair, the town keeps its fair-weather schedule, and the only thing holding the story and the world together is that the package writes a few words into the prompt header and hopes.

The request that opened this names four vocabularies that want the lane: world flags (a burnt barn stays burnt, a held NPC stays put), weather, economy verbs, and one fishing tuning row. They are one channel and one validation story, not one release — any subset is a useful first cut.

Weather is first because it is the one that is already read-complete. Pixelforge derives the sky from the world's own climate and calendar and already reads an override out of chat metadata, folds it defensively, and re-places the town on the next props delivery when the key changes. It has shipped that reader with a browser console as its only writer. Every piece of that feature exists except the half that lets the narrator use it. This PR is that half, built generically: the Engine does not know what weather is, only that a package declared an action, that the model used it, and that the values check out.

The second reason to do it now is that the package needing it cannot run server code at all. Pixelforge declares only agent and client entrypoints, so it can never register a server-side command handler — the channel has to be declaration-driven with an Engine-generic executor, or it does not reach the package that asked for it.

What changed

One table resolution per turn, threaded to both ends. The chat's Experience id resolves to an installed package, its action table is read and validated once, and that one resolution is handed to both the prompt render and the post-save scan. Two separate resolutions could disagree — a package updated mid-turn, a table that stops verifying — and then the prompt would advertise an action the parser no longer matches, leaving a raw bracket tag sitting in the player's prose. The resolution is lazy, so a chat with no Experience package pays nothing.

A gated reader, gmVerbTableSource(packageId). The verified-file reader is module-private and there is no exported by-id package accessor, so the runtime gets exactly one narrow export that returns verified bytes or nothing and never hands back an installed-package object. Its gate chain is: package readiness (not servability — the servable path falls back to the previous version's manifest for a package awaiting restart, which would serve a vocabulary the running Engine no longer matches), then the file actually being a declared asset, then the chat-write permission, then a 64 KB check against the declared byte count before any read, then the verified read. Failure tiers are the function's contract and the turn survives all of them: not installed, not ready or no table declared are silent; a packaging mistake warns; a hash or tamper failure logs an error naming tampering.

The tag grammar is shared, not re-written. The conversation-command tag pattern is exported as a source string and the new scan uses it against a different vocabulary. An action the prompt advertises but the parser cannot match would leave a raw tag in the player's prose, and two copies of a regex is how that happens.

A new engine-generic executor resolves, renders, parses, validates and executes, with no package server code anywhere in the path.

Render, parse and strip on the game turn. Action lines render inside the GM format reminder's COMMANDS: block through a new parameter beside the existing experience systems list — not the system message, which is rebuilt wholesale later and would overwrite anything spliced into it. The scan is its own game-mode-only path: the conversation-commands flag gates that entire surface, so flipping it here would arm every registered conversation command on every game turn, and it stays untouched. The scan runs before the content-replacement frame, because anything that must reach the client has to be in the response by then. A tag is removed from the saved text on the name match, never on validation success — a command the model got slightly wrong must not show the player machinery.

Its own execution site. Not the conversation-command block: that one brackets its work in frames the game client does not consume, and never runs in Game Mode anyway. Nothing executes on an aborted turn.

The executor's write discipline

  • patchMetadata and nothing else. Never updateMetadata, never the capability persistence host. The doc comment states the rule at the function.
  • Absolute writes. An action's validated arguments are written wholesale under its key. The merge is a top-level shallow spread, so the write replaces the whole value. That — not the claim record — is why a duplicate apply is harmless, and it is equally why a relative action ("add 5 gold") cannot be expressed here by construction. A duplicate identical write moves no ordinal and costs nothing.
  • touchUpdatedAt: false, so a weather change does not reorder the user's chat list.
  • Write, then claim. Each executed action claims gmVerb:<name> on the saved swipe with a truthy object value ({verb, args, at}) — a scalar would leave the storage guard a permanent no-op. The claim is skipped, never the write, when the saved message id is empty. The claim buys provenance, not dedupe, and the code says so where it is written.
  • Refusals are per action, per turn and per call. A reserved name or a foreign key drops that action and the rest of the table still runs; an invalid payload drops that call; one action throwing never costs another its effect.
  • One metadata_patch frame is emitted if any write committed, flagged the instant the row commits rather than after the claim — a committed write the client is never told to refetch would leave the package showing a stale world. The payload itself is inert: the client's handler invalidates the chat detail and the active lorebook and ignores the data. The props re-delivery after that refetch is the delivery mechanism for a written value; there is no second event carrying it.

The live-delivery half, and its honesty

An action that names no key is delivered to the package instead of written: one gm_verb frame carrying an explicit packageId plus the chat, message and swipe it came from, dispatched into the shipped capability client-event bridge. The address is explicit because the executor already holds the resolved package id — the client is not asked to infer it from a convention field inside the payload the way the existing turn-game bridge does. The case lands in both SSE switches in the same change, including the agents-retry switch where GM actions do not run today, so the next wiring does not have to rediscover that the two are twins.

What this half honestly is:

  • The channel has no memory. One frame, one synchronous browser dispatch. No queue, no replay, no acknowledgement. An effect is lost — silently — on an aborted turn (the stream is already gone), a tab closed or reloaded mid-stream, a dispatch that arrives before the package's element has mounted for the first time in that page's life, a chat the player has switched away from, and the package's own loading gate. Nothing re-delivers it.
  • One warning is the only trace. An unwritable reply is warned about; ordinary backpressure is not, because a queued frame is not a lost one, and folding the two would make the warning meaningless.
  • The claim cannot buy at-most-once here even in principle — it is written after the frame, and the client may never have received the frame.
  • The regeneration nuance, stated plainly because it shapes what may ship on this half. Regenerating a turn mints a fresh swipe, and a new swipe's extras are rebuilt from a fixed allowlist that does not carry these claims forward. So a relative live-delivered action would apply once per swipe generated, and no key on the message can stop it: the key guards redelivery of one generation, and redelivery is the one thing a channel with no replay cannot do. This is why relative shapes are refused at declaration and why the first action on this half is one whose package-side write is absolute in every field.
  • The two halves genuinely differ on rewind. A written chat setting does not rewind with the story — it survives swiping away, editing or deleting the turn. A live-delivered effect applied into a package's own state does revert with a rewind, because the package rebuilds that state from its save.
  • Ordering on a turn that carries both. The live dispatch is synchronous and reaches the package before the written value's refetch lands. A handler must not read a same-turn written value and expect the new one. The docs say this rather than leaving it to be found.
  • Refusal asymmetry. The Engine can only check shape; an NPC name cannot be enumerated at declaration time, because the world is compiled per chat. So the package's own re-validation is advisory for a written value (the row is already committed) and binding for a live-delivered one (nothing was committed Engine-side). That asymmetry is a feature and the docs state it.

The chat-write gate, and what it widens

Reading a package's table requires the package to declare chat-write, and the permission check sits ahead of the read so an unpermitted package's bytes are never loaded — and behind the declaration test, so a package with no table stays silent while one that ships a table and forgot the permission is told.

Stated up front rather than discovered: this changes what that permission means. Today chat-write means "this package's own client code writes chat data". After this PR it also means "the Engine will execute writes on this package's behalf, from model output". Permissions are shown before install and nothing re-consents on update, so a user who granted the old meaning receives the new one without being asked again. The separate issue about capability permissions that are declared and enforced nowhere (#5899) carries this note; the first counter-example to that issue is this gate.

Practically the blast radius today is zero: no released package ships an action table at all, so no install changes behavior until one does.

Capability API 1.16

The bump waited for this PR on purpose. The compatibility check compares a package's declared version against that constant alone, so bumping it advertises the seam whether or not the runtime exists. It exists now. It carries its own line in the version ladder, and the lifecycle regression pins the constant and its compatibility message in four places so the bump moves them with it.

Teaching the model the vocabulary it is allowed to use

The reminder line originally rendered a name, a description and one example, so an action's closed vocabulary reached the GM only if the package happened to spell it inside a 200-character description. A GM told to set the weather writes "sunny" for "fair"; the validator refuses a word it was never shown; and the refusal is invisible, because the tag is stripped on the name match — the narration reads clean and the world simply never changed.

The line now carries the two payload slots the sibling conversation-command renderer already uses, and the first one is derived from the same parsed table the validator reads: every argument in declaration order, optional ones marked outside the JSON string, a closed list rendered as the full alternation the built-in commands already use, an open string shown with its cap, numbers and booleans unquoted because the validator refuses "3" for a number rather than coercing it. Deriving it here instead of from prose is what stops prompt and validator drifting: a description can no longer promise a value the validator refuses.

One prompt hazard, named

The GM format reminder already renders a built-in [reputation: npc= action=] line on every Game Mode turn, consumed by the Engine's own relative reputation service against records Pixelforge never populates. The reserved-name rule correctly makes reputation an illegal package action name — but a package's own standing action will sit one line away from a do-nothing Engine stance verb in the same block, and a model handed two overlapping stance verbs will sometimes reach for the wrong one. The name rule cannot fix that. Suppressing the Engine line on chats whose package declares a standing action is a candidate follow-up, not part of this PR.

Also in this PR

  • The retry SSE switch gains metadata_patch, which is load-bearing rather than tidy: the retry route has been emitting that frame with no case to receive it, so a metadata write on a retried turn never reached the package until the chat was reopened.
  • A misleading comment in the conversation-actions regression is fixed. It claimed "regeneration cannot double-send" four lines above an assertion that the handler ran twice. The dispatch key is an in-flight lock released in a finally, not a ledger; what the second call refuses is the claim, after the handler has already run. That comment is where a false safety claim in the original design notes came from.

Known shortcuts

Named here so review does not have to find them:

  1. One instance per action name per message. Correct for the two proving actions; a real ceiling for any future repeatable live-delivered action, where a repeat is meaningful prose ("two coins, then two more"). A payload-hash dedupe behind a repeatable flag is sketched, not built.

  2. Flat, single-line JSON payloads only. Argument values are string, number or boolean; there is no nesting.

  3. A written value survives swiping away, editing or deleting the turn, and nothing reverts it. The visible symptom is that the last swipe generated wins, not the last displayed — the prose on screen and the world can disagree within a session with nothing reconciling them. A live-delivered effect does revert with a rewind; the halves genuinely differ here.

  4. The claim buys provenance, not dedupe — and on the live-delivery half it cannot buy at-most-once even in principle. Safety comes entirely from the write being absolute.

  5. A package's semantic refusal of a written value is advisory; the row is already committed. A refusal of a live-delivered action is binding.

  6. Math.random() stays unseeded everywhere. There are three separate unseeded implementations in the tree; this PR neither uses nor fixes them.

  7. After an update that leaves a package awaiting restart, its actions stop resolving until the restart — a log line only, no user-facing notice. No shipped package can trip this today.

  8. A GM turn that is nothing but an action tag now lands rather than being discarded — a review round pulled the narrow fix in: the empty-response guard's hidden-anchor gate now counts parsed GM verb calls, so a tags-only turn saves its hidden anchor, executes its validated writes, and shows the player a silent turn instead of an error; the game surface skips the hidden anchor when picking the narration to display, so the previous turn's text stays on screen. #5902 remains open for the generic anchor surface (the gate still cannot see command shapes it was never taught), and two follow-ups were filed from the review: #5926 (a command-only regenerate appends its anchor instead of replacing the message — pre-existing shape shared with Conversation) and #5927 (the game surface's sibling readers still see raw hidden rows).

  9. A live-delivered effect is lost, silently, in the five cases listed above. The only trace it ever leaves is one warning, and only for the unwritable-reply case.

  10. The rendered reminder has no length budget of its own. Every value it prints is a verbatim substring of a table file already refused above 64 KB, so the bound exists — but a maximal legal table would render roughly 60 KB into every Game turn's reminder. That is entirely self-inflicted by the package, and it is a named cost rather than a guarded one.

What the tests prove, and what they do not

  • The behavioral regression drives the executor against a real installed-package registry in a temporary data directory and a real chats store, because the claims worth pinning are claims about persisted state: the write lands with its ordinal stamped and updatedAt untouched, a second identical apply moves nothing, the live frame is emitted exactly once carrying the package id and the message triple, and every refusal tier (no table, no permission, oversized, tampered, malformed, not ready, wrong owner) is exercised without throwing. The byte ceiling is proved to key on the declared size: the same file on disk is refused when the manifest inflates it and accepted when the manifest tells the truth.
  • Three route behaviors are pinned by source-text search, not by execution — the abort guard, the metadata_patch emit, and the once-per-turn resolution. The execution site lives inside a several-thousand-line route handler no regression can drive, and the file labels those three as searches rather than dressing them up as exercised behavior. Their reachability rests on review, not on a check.
  • The case-folding fix is not pinned, and is not pinnable in process: it only misbehaves under a Turkish or Azeri runtime locale. The regression says so where it would otherwise be assumed.
  • Three render branches are not exercised by CI — a number argument, a boolean argument, and an open string with no cap. All three were driven by hand and are correct; one extra fixture action would close the gap at near-zero cost.
  • No automated coverage of the prose experience. Whether the rendered reminder actually gets a model to use these actions well is a playtest question, not a test question.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

These twelve items need a Pixelforge build that ships a gm-verbs.json declaration installed as the chat's Experience. No released package declares an action table, so on a stock install this PR is unobservable by design — a chat with no declaring package resolves zero actions, renders no extra prompt lines, parses nothing and writes nothing. Items 10–12 additionally need the package-side consumption of the standing action, which lives in the Agents repo.

  • Manually verify in the browser that the GM emits a weather tag on a Pixelforge chat and that the tag is not visible in the saved narration.
  • Manually read the chat's metadata row directly and confirm the value landed there — do this before looking at the sky, so a passing sky cannot mask a failed write.
  • Manually verify in the browser that the sky changes without a reload.
  • Manually verify that a deliberately malformed payload is still stripped out of the prose (the player must never see machinery), and that the world does not change.
  • Manually verify in a Conversation-mode chat that none of this appears: no extra prompt lines, no parsing, no writes.
  • Manually verify that streaming on a Game turn looks exactly as it did before.
  • Manually verify that a Game chat with no Experience package is unchanged end to end.
  • Manually verify that a retried turn still updates the sky (this is the retry-switch case that was previously missing).
  • Manually verify that a stopped turn changes nothing — no write, no delivery, no claim.
  • Manually verify in the browser that the GM emitting a standing action produces the package's own sentence and changes the world header standing word and the talk-window title, without a reload.
  • Manually verify that regenerating that same turn does not stack anything — the write is absolute, and the last generated swipe wins.
  • Manually verify that an unknown NPC name is refused by the package: no sentence, no change — and the tag was still stripped from the prose.

Alongside those:

  • Run pnpm check and confirm it exits clean.
  • Run the regressions: capability-gm-verb-runtime, capability-gm-verbs, capability-conversation-actions, capability-package-lifecycle, prompt.
  • Confirm no console.* was introduced in server code (the shared logger is used throughout the new service).

During development pnpm check exited clean and those five regression lanes passed. That is context for the reviewer, not evidence for the boxes above — every browser item is genuinely unverified until someone runs it with a declaring package installed.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

What this PR actually does, for the reviewer to confirm against the boxes:

  • Adds the Capability API 1.16 section to docs/development/optional-agent-packages.md — the delivery-and-durability contrast, the mixed-turn ordering rule, the binding-versus-advisory refusal split, the honest gate scope, the fact that a table declared in the package's file list but left out of its asset paths yields zero actions and zero diagnostics, and the fact that a declared asset is served unguarded over HTTP so a table must never hold anything sensitive.
  • Adds two CHANGELOG lines under Added (the second one is this PR's; the first belongs to the stacked schema PR and lands with it).
  • Translated docs on docs-i18n are not updated here; this file's changes belong in the batched [docs-i18n] follow-up.
  • No app version bump. The capability API constant moves from 1.15 to 1.16, which is a package-compatibility version and not one of the files pnpm version:sync owns.

UI evidence (if applicable)

Nothing in this PR draws anything. The user-visible result is a world that changes when the narrator says it changed — which is a recording of a Pixelforge chat, not a screenshot of an Engine screen. Worth attaching if the browser pass above is recorded: one clip of the sky changing mid-turn without a reload.

Summary by CodeRabbit

  • New Features

    • Added support for package-declared Game Master actions in Game mode.
    • Actions can update chat state or be delivered live to connected packages when permitted.
    • Upgraded Capability API support to version 1.16.
  • Bug Fixes

    • Game turns containing only hidden actions no longer erase the narration panel or get dropped.
    • Hidden, empty, and command-only turns are excluded from visible narration and navigation.

🔄 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/5922 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/7/2026 **Status:** ✅ Merged **Merged:** 9/7/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5798-gm-verb-runtime` --- ### 📝 Commits (10+) - [`4dae701`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4dae70154fb0afd6c5fded245aaeed5b59003ef6) feat(capability): gated reader for a package's GM verb table (#5798) - [`ea191f5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ea191f5cf03ec75a203453819ed64d8a67a9d251) feat(capability): engine-generic GM verb executor for both effects (#5798) - [`5d5ea05`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d5ea05ac8b3bd9d39cd866f889f0ed603eeb4cc) feat(game): render, parse and execute package GM verbs on a game turn (#5798) - [`faceb0b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/faceb0b92043ef910f5ff5a4e7741e4f57b0b949) feat(client): handle gm_verb in both SSE switches, and metadata_patch in the retry twin (#5798) - [`3b488bb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b488bb43b4454ae2e8ac35539bba391beb7415c) feat(capability): advertise capability API 1.16 (#5798) - [`c2dd8e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2dd8e548dabd6acfe306b12020a346ff0d94819) test(capability): behavioral regression for the GM verb runtime (#5798) - [`5c3200b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c3200b910ce7ebd505b7c99b4330abb91f59b56) fix(capability): fold GM verb tag names locale-independently (#5798) - [`a4ad584`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a4ad584c81d5793bf61d613b534037ef86e3b2df) docs(capability): name the two unstated GM verb behaviors (#5798) - [`6a78b9b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6a78b9b5749623a35044a7cba565fffd6e2bd419) test(capability): make the GM verb byte-ceiling pin discriminate (#5798) - [`ce8a5aa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ce8a5aaeabf6d7db6d63d88210090a5777679bd6) fix(capability): teach GM verb argument vocabularies from the table (#5798) ### 📊 Changes **17 files changed** (+1971 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -1) 📝 `docs/development/optional-agent-packages.md` (+35 -11) ➕ `e2e/game-verb-only-turn.e2e.ts` (+172 -0) 📝 `packages/client/src/components/game/GameNarration.tsx` (+25 -1) 📝 `packages/client/src/hooks/use-generate.ts` (+40 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+117 -1) 📝 `packages/server/src/routes/generate/spatial-transition-request.ts` (+8 -1) 📝 `packages/server/src/services/capability-packages/capability-command-registry.service.ts` (+18 -6) ➕ `packages/server/src/services/capability-packages/capability-gm-verb-runtime.service.ts` (+438 -0) 📝 `packages/server/src/services/capability-packages/package-manager.service.ts` (+90 -0) 📝 `packages/server/src/services/game/gm-prompts.ts` (+11 -0) 📝 `packages/shared/src/index.ts` (+1 -0) 📝 `packages/shared/src/schemas/capability-package.schema.ts` (+5 -1) 📝 `scripts/regressions/capability-conversation-actions.regression.ts` (+5 -1) ➕ `scripts/regressions/capability-gm-verb-runtime.regression.ts` (+977 -0) 📝 `scripts/regressions/capability-gm-verbs.regression.ts` (+20 -9) 📝 `scripts/regressions/capability-package-lifecycle.regression.ts` (+5 -5) </details> ### 📄 Description > [!WARNING] > **Stack note — this PR is stacked on the GM verb schema PR. Merge that one first.** Until it merges, the diff below also contains its five commits (the shared schema file, its docs section, its regression and its CHANGELOG line). Review those there, not here; once it lands, this diff shrinks to the eleven commits that add the runtime. > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5798 ## Why this change An Experience package can read a chat and cannot write to it. The host hands the package props every turn and dispatches a small set of engine-defined events at it, but nothing carries anything the *model* said. So when the GM narrates the storm rolling in, the package never hears; the sky stays fair, the town keeps its fair-weather schedule, and the only thing holding the story and the world together is that the package writes a few words into the prompt header and hopes. The request that opened this names four vocabularies that want the lane: world flags (a burnt barn stays burnt, a held NPC stays put), weather, economy verbs, and one fishing tuning row. They are one channel and one validation story, not one release — any subset is a useful first cut. **Weather is first because it is the one that is already read-complete.** Pixelforge derives the sky from the world's own climate and calendar and *already* reads an override out of chat metadata, folds it defensively, and re-places the town on the next props delivery when the key changes. It has shipped that reader with a browser console as its only writer. Every piece of that feature exists except the half that lets the narrator use it. This PR is that half, built generically: the Engine does not know what weather is, only that a package declared an action, that the model used it, and that the values check out. The second reason to do it now is that the package needing it cannot run server code at all. Pixelforge declares only agent and client entrypoints, so it can never register a server-side command handler — the channel has to be declaration-driven with an Engine-generic executor, or it does not reach the package that asked for it. ## What changed **One table resolution per turn, threaded to both ends.** The chat's Experience id resolves to an installed package, its action table is read and validated once, and that one resolution is handed to both the prompt render and the post-save scan. Two separate resolutions could disagree — a package updated mid-turn, a table that stops verifying — and then the prompt would advertise an action the parser no longer matches, leaving a raw bracket tag sitting in the player's prose. The resolution is lazy, so a chat with no Experience package pays nothing. **A gated reader, `gmVerbTableSource(packageId)`.** The verified-file reader is module-private and there is no exported by-id package accessor, so the runtime gets exactly one narrow export that returns verified bytes or nothing and never hands back an installed-package object. Its gate chain is: package readiness (not servability — the servable path falls back to the *previous* version's manifest for a package awaiting restart, which would serve a vocabulary the running Engine no longer matches), then the file actually being a declared asset, then the `chat-write` permission, then a 64 KB check against the *declared* byte count before any read, then the verified read. Failure tiers are the function's contract and the turn survives all of them: not installed, not ready or no table declared are silent; a packaging mistake warns; a hash or tamper failure logs an error naming tampering. **The tag grammar is shared, not re-written.** The conversation-command tag pattern is exported as a source string and the new scan uses it against a different vocabulary. An action the prompt advertises but the parser cannot match would leave a raw tag in the player's prose, and two copies of a regex is how that happens. **A new engine-generic executor** resolves, renders, parses, validates and executes, with no package server code anywhere in the path. **Render, parse and strip on the game turn.** Action lines render inside the GM format reminder's `COMMANDS:` block through a new parameter beside the existing experience systems list — not the system message, which is rebuilt wholesale later and would overwrite anything spliced into it. The scan is its own game-mode-only path: the conversation-commands flag gates that entire surface, so flipping it here would arm every registered conversation command on every game turn, and it stays untouched. The scan runs before the content-replacement frame, because anything that must reach the client has to be in the response by then. **A tag is removed from the saved text on the name match, never on validation success** — a command the model got slightly wrong must not show the player machinery. **Its own execution site.** Not the conversation-command block: that one brackets its work in frames the game client does not consume, and never runs in Game Mode anyway. Nothing executes on an aborted turn. ### The executor's write discipline - **`patchMetadata` and nothing else.** Never `updateMetadata`, never the capability persistence host. The doc comment states the rule at the function. - **Absolute writes.** An action's validated arguments are written wholesale under its key. The merge is a top-level shallow spread, so the write replaces the whole value. *That* — not the claim record — is why a duplicate apply is harmless, and it is equally why a relative action ("add 5 gold") cannot be expressed here by construction. A duplicate identical write moves no ordinal and costs nothing. - **`touchUpdatedAt: false`**, so a weather change does not reorder the user's chat list. - **Write, then claim.** Each executed action claims `gmVerb:<name>` on the saved swipe with a truthy object value (`{verb, args, at}`) — a scalar would leave the storage guard a permanent no-op. The claim is skipped, never the write, when the saved message id is empty. **The claim buys provenance, not dedupe**, and the code says so where it is written. - **Refusals are per action, per turn and per call.** A reserved name or a foreign key drops that action and the rest of the table still runs; an invalid payload drops that call; one action throwing never costs another its effect. - **One `metadata_patch` frame** is emitted if any write committed, flagged the instant the row commits rather than after the claim — a committed write the client is never told to refetch would leave the package showing a stale world. The payload itself is inert: the client's handler invalidates the chat detail and the active lorebook and ignores the data. The props re-delivery after that refetch *is* the delivery mechanism for a written value; there is no second event carrying it. ### The live-delivery half, and its honesty An action that names no key is delivered to the package instead of written: one `gm_verb` frame carrying an explicit `packageId` plus the chat, message and swipe it came from, dispatched into the shipped capability client-event bridge. The address is explicit because the executor already holds the resolved package id — the client is not asked to infer it from a convention field inside the payload the way the existing turn-game bridge does. The case lands in **both** SSE switches in the same change, including the agents-retry switch where GM actions do not run today, so the next wiring does not have to rediscover that the two are twins. What this half honestly is: - **The channel has no memory.** One frame, one synchronous browser dispatch. No queue, no replay, no acknowledgement. An effect is lost — silently — on an aborted turn (the stream is already gone), a tab closed or reloaded mid-stream, a dispatch that arrives before the package's element has mounted for the first time in that page's life, a chat the player has switched away from, and the package's own loading gate. Nothing re-delivers it. - **One warning is the only trace.** An unwritable reply is warned about; ordinary backpressure is not, because a queued frame is not a lost one, and folding the two would make the warning meaningless. - **The claim cannot buy at-most-once here even in principle** — it is written after the frame, and the client may never have received the frame. - **The regeneration nuance, stated plainly because it shapes what may ship on this half.** Regenerating a turn mints a fresh swipe, and a new swipe's extras are rebuilt from a fixed allowlist that does not carry these claims forward. So a *relative* live-delivered action would apply once per swipe generated, and no key on the message can stop it: the key guards redelivery of one generation, and redelivery is the one thing a channel with no replay cannot do. This is why relative shapes are refused at declaration and why the first action on this half is one whose package-side write is absolute in every field. - **The two halves genuinely differ on rewind.** A written chat setting does not rewind with the story — it survives swiping away, editing or deleting the turn. A live-delivered effect applied into a package's own state does revert with a rewind, because the package rebuilds that state from its save. - **Ordering on a turn that carries both.** The live dispatch is synchronous and reaches the package *before* the written value's refetch lands. A handler must not read a same-turn written value and expect the new one. The docs say this rather than leaving it to be found. - **Refusal asymmetry.** The Engine can only check shape; an NPC name cannot be enumerated at declaration time, because the world is compiled per chat. So the package's own re-validation is advisory for a written value (the row is already committed) and **binding** for a live-delivered one (nothing was committed Engine-side). That asymmetry is a feature and the docs state it. ### The `chat-write` gate, and what it widens Reading a package's table requires the package to declare `chat-write`, and the permission check sits ahead of the read so an unpermitted package's bytes are never loaded — and behind the declaration test, so a package with no table stays silent while one that ships a table and forgot the permission is told. **Stated up front rather than discovered:** this changes what that permission means. Today `chat-write` means "this package's own client code writes chat data". After this PR it also means "the Engine will execute writes on this package's behalf, from model output". Permissions are shown before install and nothing re-consents on update, so a user who granted the old meaning receives the new one without being asked again. The separate issue about capability permissions that are declared and enforced nowhere (#5899) carries this note; the first counter-example to that issue is this gate. Practically the blast radius today is zero: no released package ships an action table at all, so no install changes behavior until one does. ### Capability API 1.16 The bump waited for this PR on purpose. The compatibility check compares a package's declared version against that constant alone, so bumping it advertises the seam whether or not the runtime exists. It exists now. It carries its own line in the version ladder, and the lifecycle regression pins the constant and its compatibility message in four places so the bump moves them with it. ### Teaching the model the vocabulary it is allowed to use The reminder line originally rendered a name, a description and one example, so an action's closed vocabulary reached the GM only if the package happened to spell it inside a 200-character description. A GM told to set the weather writes "sunny" for "fair"; the validator refuses a word it was never shown; and **the refusal is invisible**, because the tag is stripped on the name match — the narration reads clean and the world simply never changed. The line now carries the two payload slots the sibling conversation-command renderer already uses, and the first one is derived from the same parsed table the validator reads: every argument in declaration order, optional ones marked outside the JSON string, a closed list rendered as the full alternation the built-in commands already use, an open string shown with its cap, numbers and booleans unquoted because the validator refuses `"3"` for a number rather than coercing it. Deriving it here instead of from prose is what stops prompt and validator drifting: a description can no longer promise a value the validator refuses. ### One prompt hazard, named The GM format reminder already renders a built-in `[reputation: npc= action=]` line on every Game Mode turn, consumed by the Engine's own relative reputation service against records Pixelforge never populates. The reserved-name rule correctly makes `reputation` an illegal package action name — but a package's own standing action will sit one line away from a do-nothing Engine stance verb in the same block, and a model handed two overlapping stance verbs will sometimes reach for the wrong one. The name rule cannot fix that. Suppressing the Engine line on chats whose package declares a standing action is a candidate follow-up, not part of this PR. ### Also in this PR - The retry SSE switch gains `metadata_patch`, which is load-bearing rather than tidy: the retry route has been emitting that frame with no case to receive it, so a metadata write on a retried turn never reached the package until the chat was reopened. - A misleading comment in the conversation-actions regression is fixed. It claimed "regeneration cannot double-send" four lines above an assertion that the handler ran twice. The dispatch key is an in-flight lock released in a `finally`, not a ledger; what the second call refuses is the claim, after the handler has already run. That comment is where a false safety claim in the original design notes came from. ## Known shortcuts Named here so review does not have to find them: 1. **One instance per action name per message.** Correct for the two proving actions; a real ceiling for any future repeatable live-delivered action, where a repeat is meaningful prose ("two coins, then two more"). A payload-hash dedupe behind a `repeatable` flag is sketched, not built. 2. **Flat, single-line JSON payloads only.** Argument values are string, number or boolean; there is no nesting. 3. **A written value survives swiping away, editing or deleting the turn, and nothing reverts it.** The visible symptom is that the last swipe *generated* wins, not the last *displayed* — the prose on screen and the world can disagree within a session with nothing reconciling them. A live-delivered effect does revert with a rewind; the halves genuinely differ here. 4. **The claim buys provenance, not dedupe** — and on the live-delivery half it cannot buy at-most-once even in principle. Safety comes entirely from the write being absolute. 5. **A package's semantic refusal of a written value is advisory**; the row is already committed. A refusal of a live-delivered action is binding. 6. **`Math.random()` stays unseeded everywhere.** There are three separate unseeded implementations in the tree; this PR neither uses nor fixes them. 7. **After an update that leaves a package awaiting restart, its actions stop resolving until the restart** — a log line only, no user-facing notice. No shipped package can trip this today. 8. **A GM turn that is nothing but an action tag now lands rather than being discarded** — a review round pulled the narrow fix in: the empty-response guard's hidden-anchor gate now counts parsed GM verb calls, so a tags-only turn saves its hidden anchor, executes its validated writes, and shows the player a silent turn instead of an error; the game surface skips the hidden anchor when picking the narration to display, so the previous turn's text stays on screen. #5902 remains open for the generic anchor surface (the gate still cannot see command shapes it was never taught), and two follow-ups were filed from the review: #5926 (a command-only regenerate appends its anchor instead of replacing the message — pre-existing shape shared with Conversation) and #5927 (the game surface's sibling readers still see raw hidden rows). 9. **A live-delivered effect is lost, silently, in the five cases listed above.** The only trace it ever leaves is one warning, and only for the unwritable-reply case. 10. **The rendered reminder has no length budget of its own.** Every value it prints is a verbatim substring of a table file already refused above 64 KB, so the bound exists — but a maximal legal table would render roughly 60 KB into every Game turn's reminder. That is entirely self-inflicted by the package, and it is a named cost rather than a guarded one. ### What the tests prove, and what they do not - The behavioral regression drives the executor against a real installed-package registry in a temporary data directory and a real chats store, because the claims worth pinning are claims about persisted state: the write lands with its ordinal stamped and `updatedAt` untouched, a second identical apply moves nothing, the live frame is emitted exactly once carrying the package id and the message triple, and every refusal tier (no table, no permission, oversized, tampered, malformed, not ready, wrong owner) is exercised without throwing. The byte ceiling is proved to key on the *declared* size: the same file on disk is refused when the manifest inflates it and accepted when the manifest tells the truth. - **Three route behaviors are pinned by source-text search, not by execution** — the abort guard, the `metadata_patch` emit, and the once-per-turn resolution. The execution site lives inside a several-thousand-line route handler no regression can drive, and the file labels those three as searches rather than dressing them up as exercised behavior. Their *reachability* rests on review, not on a check. - **The case-folding fix is not pinned**, and is not pinnable in process: it only misbehaves under a Turkish or Azeri runtime locale. The regression says so where it would otherwise be assumed. - **Three render branches are not exercised by CI** — a number argument, a boolean argument, and an open string with no cap. All three were driven by hand and are correct; one extra fixture action would close the gap at near-zero cost. - **No automated coverage of the prose experience.** Whether the rendered reminder actually gets a model to use these actions well is a playtest question, not a test question. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes **These twelve items need a Pixelforge build that ships a `gm-verbs.json` declaration installed as the chat's Experience.** No released package declares an action table, so on a stock install this PR is unobservable by design — a chat with no declaring package resolves zero actions, renders no extra prompt lines, parses nothing and writes nothing. Items 10–12 additionally need the package-side consumption of the standing action, which lives in the Agents repo. - [ ] Manually verify in the browser that the GM emits a weather tag on a Pixelforge chat and that the tag is **not** visible in the saved narration. - [ ] Manually read the chat's metadata row directly and confirm the value landed there — do this **before** looking at the sky, so a passing sky cannot mask a failed write. - [ ] Manually verify in the browser that the sky changes without a reload. - [ ] Manually verify that a deliberately malformed payload is still stripped out of the prose (the player must never see machinery), and that the world does not change. - [ ] Manually verify in a Conversation-mode chat that none of this appears: no extra prompt lines, no parsing, no writes. - [ ] Manually verify that streaming on a Game turn looks exactly as it did before. - [ ] Manually verify that a Game chat with no Experience package is unchanged end to end. - [ ] Manually verify that a **retried** turn still updates the sky (this is the retry-switch case that was previously missing). - [ ] Manually verify that a **stopped** turn changes nothing — no write, no delivery, no claim. - [ ] Manually verify in the browser that the GM emitting a standing action produces the package's own sentence and changes the world header standing word and the talk-window title, without a reload. - [ ] Manually verify that regenerating that same turn does not stack anything — the write is absolute, and the last generated swipe wins. - [ ] Manually verify that an unknown NPC name is refused by the package: no sentence, no change — and the tag was still stripped from the prose. Alongside those: - [ ] Run `pnpm check` and confirm it exits clean. - [ ] Run the regressions: `capability-gm-verb-runtime`, `capability-gm-verbs`, `capability-conversation-actions`, `capability-package-lifecycle`, `prompt`. - [ ] Confirm no `console.*` was introduced in server code (the shared logger is used throughout the new service). During development `pnpm check` exited clean and those five regression lanes passed. That is context for the reviewer, not evidence for the boxes above — every browser item is genuinely unverified until someone runs it with a declaring package installed. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) What this PR actually does, for the reviewer to confirm against the boxes: - Adds the Capability API 1.16 section to `docs/development/optional-agent-packages.md` — the delivery-and-durability contrast, the mixed-turn ordering rule, the binding-versus-advisory refusal split, the honest gate scope, the fact that a table declared in the package's file list but left out of its asset paths yields zero actions and zero diagnostics, and the fact that a declared asset is served unguarded over HTTP so a table must never hold anything sensitive. - Adds two CHANGELOG lines under Added (the second one is this PR's; the first belongs to the stacked schema PR and lands with it). - Translated docs on `docs-i18n` are not updated here; this file's changes belong in the batched `[docs-i18n]` follow-up. - No app version bump. The capability API constant moves from 1.15 to 1.16, which is a package-compatibility version and not one of the files `pnpm version:sync` owns. ## UI evidence (if applicable) Nothing in this PR draws anything. The user-visible result is a world that changes when the narrator says it changed — which is a recording of a Pixelforge chat, not a screenshot of an Engine screen. Worth attaching if the browser pass above is recorded: one clip of the sky changing mid-turn without a reload. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for package-declared Game Master actions in Game mode. - Actions can update chat state or be delivered live to connected packages when permitted. - Upgraded Capability API support to version 1.16. - **Bug Fixes** - Game turns containing only hidden actions no longer erase the narration panel or get dropped. - Hidden, empty, and command-only turns are excluded from visible narration and navigation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:15:32 +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#6991
No description provided.