[PR #8653] [MERGED] feat(sprites): faceted sprite names let the Expression Engine choose by outfit and condition #8726

Closed
opened 2026-11-07 17:39:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8653
Author: @SpicyMarinara
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/faceted-sprite-selection-8637


📝 Commits (4)

  • 11491ba feat(sprites): faceted sprite names let the Expression Engine choose by outfit and condition (#8637)
  • ec013fb fix(sprites): a faceted name never falls back to a talk or blink frame (#8637)
  • dad12f4 fix(sprites): the client never shows a talk frame for an outfit with no face of its own (#8637)
  • 1c2998b fix(sprites): a faceted name tries its own group before a loose substring match (#8637)

📊 Changes

9 files changed (+341 additions, -22 deletions)

View changed files

📝 docs/characters/sprites.md (+2 -0)
📝 packages/client/src/components/chat/sprite-display-expression.ts (+4 -0)
📝 packages/client/src/features/avatars/renderers/pngtuber/pngtuber-layers.ts (+4 -4)
📝 packages/client/src/lib/sprite-expression-match.ts (+32 -4)
📝 packages/server/src/routes/generate/expression-agent-utils.ts (+31 -4)
📝 packages/server/src/services/avatars/generation/pngtuber-variants.ts (+4 -4)
📝 packages/server/src/services/game/sprite.service.ts (+18 -6)
📝 packages/shared/src/utils/sprite-labels.ts (+52 -0)
➕ scripts/regressions/sprite-expression-facets.regression.ts (+194 -0)

📄 Description

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 #8637

Why this change

  • Every sprite whose name starts with the same word collapsed into one group key. With happy_pajamas, happy_formalwear and angry_formalwear_soaked_01 in a library, the Expression Engine only ever saw happy and angry. The outfit or condition was left to a random roll, so a character in pajamas could appear in formalwear. The issue asks for the agent to choose by outfit and condition from what's in the scene, using names the user already writes.

What changed

  • Agent listing. buildSpriteExpressionChoices still lists each group key. For a group with more than one sprite, it now also lists each sprite's faceted name without its variant number: angry_formalwear_soaked_01 adds angry_formalwear_soaked. This list feeds both the Expression Engine's <available_sprites> and the Game Master's sprite list. PNGTuber talk and blink frames are never listed. Libraries with only numbered variants list exactly as before.
  • One shared rule. findSpriteExpressionFacetMatches in shared/utils/sprite-labels.ts treats the first word as the group key and the words after it as facets, in the order written. A faceted name picks among its own variants. When no sprite has every facet, it drops the last facet and tries again, then falls back to the group key. happy_pajamas_wounded → happy_pajamas → happy.
  • Resolvers.
    • The server (resolveExpression) rolls among a faceted name's variants. A concrete numbered name such as happy_pajamas_02 is used as is. With no facet match, it falls back to its own group before any loose substring match, and never to a talk or blink frame.
    • The client (resolveSpriteExpression) and the sprite overlay pick deterministically, so the overlay shows the most specific match across full-body and portrait sprites.
    • Group keys that contain a hyphen or dot (half-smile) still roll over their variants as before.
  • Reuse. The PNGTuber talk/blink suffix lists that the client and server each had are now one shared list.
  • Docs. docs/characters/sprites.md explains faceted names.
  • Regression. scripts/regressions/sprite-expression-facets.regression.ts covers the listing, the facet fallback chain, concrete handles, talk/blink frames on both server and client, hyphenated group keys, legacy variant groups, and the overlay's preference for the most specific match. Each case fails on the code before its fix.

Ordering, as a known limit. Facets are read in the order the name is written, with the emotion first. That differs from the issue's suggested "outfit > emotion > condition" priority. Pose-first names like kneeling_happy_armor_wounded group under kneeling. An out-of-order request like happy_wounded doesn't match happy_formalwear_wounded and falls back to happy. Supporting either would need a per-character facet schema.

Prompt. The Expression Engine's prompt template lives in Marinara-Agents (packages/expression/agents.json). The matching change, telling the agent about faceted names and to keep outfit and condition until the scene changes them, goes in a separate Agents PR. The Engine side works without it, but the agent only chooses faceted names deliberately once that template lands.

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

What the agent ran locally:

  • node ./scripts/pnpm-runner.mjs check passes, after rebasing on staging.
  • These regressions pass: sprite-expression-facets, sprite-agent-compatibility, sprite-runtime-compatibility, sprite-folders, sprite-list-security, expression-group-generation, expression-tool-retirement, game-tts-emotion, avatar-2d-main-faces, avatar-director, avatar-generation, avatar-variant-composite and open-issues.
  • An independent review agent fixed hyphenated group keys changing the listing and resolution.
  • Local CodeRabbit raised talk/blink frames reaching faceted fallbacks (server and client), the group fallback running after substring matching, and a docs wording issue. All are fixed, each with a regression.
  • CodeRabbit's last point, about the final substring match still choosing unhappy_pajamas when the library has no happy sprite at all, is the resolver's existing last resort and was left as is. Before this PR, happy and happy_pajamas both resolved that way too. Narrowing it would change plain group keys for every library.

To verify by hand:

  • Manually verify in a Roleplay chat with the Expression Engine and debug mode on, using a character with sprites happy_pajamas_01, happy_pajamas_02, happy_formalwear and angry_formalwear_soaked_01. The logged <available_sprites> line should list happy, happy_pajamas, happy_formalwear, angry, angry_formalwear_soaked, with no _01 numbers.
  • Manually verify in the browser that the sprite overlay shows a pajamas sprite when the agent returns happy_pajamas, and also when it returns the unlisted happy_pajamas_wounded.
  • Manually verify that a legacy library (happy_01, happy_02, happy_blush) still rotates between variants for happy over several turns.
  • Manually verify in Game mode that the Game Master's sprite list shows the faceted names, and that an expression tag such as happy_pajamas shows the matching sprite.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

docs/characters/sprites.md gains one paragraph. A [docs-i18n] docs/characters/sprites.md follow-up issue is opened for the translated packs.

🤖 Generated with Claude Code


🔄 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/8653 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/faceted-sprite-selection-8637` --- ### 📝 Commits (4) - [`11491ba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11491baae433bf97762194df73bedb178b6ace40) feat(sprites): faceted sprite names let the Expression Engine choose by outfit and condition (#8637) - [`ec013fb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ec013fb09be8edef83557c4f88f32346152522c7) fix(sprites): a faceted name never falls back to a talk or blink frame (#8637) - [`dad12f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dad12f4ffb9b878515de74d3b1c93fb0097c70d9) fix(sprites): the client never shows a talk frame for an outfit with no face of its own (#8637) - [`1c2998b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c2998bd6b50feca49efd2834ffe60d9003d8084) fix(sprites): a faceted name tries its own group before a loose substring match (#8637) ### 📊 Changes **9 files changed** (+341 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `docs/characters/sprites.md` (+2 -0) 📝 `packages/client/src/components/chat/sprite-display-expression.ts` (+4 -0) 📝 `packages/client/src/features/avatars/renderers/pngtuber/pngtuber-layers.ts` (+4 -4) 📝 `packages/client/src/lib/sprite-expression-match.ts` (+32 -4) 📝 `packages/server/src/routes/generate/expression-agent-utils.ts` (+31 -4) 📝 `packages/server/src/services/avatars/generation/pngtuber-variants.ts` (+4 -4) 📝 `packages/server/src/services/game/sprite.service.ts` (+18 -6) 📝 `packages/shared/src/utils/sprite-labels.ts` (+52 -0) ➕ `scripts/regressions/sprite-expression-facets.regression.ts` (+194 -0) </details> ### 📄 Description > [!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 #8637 ## Why this change - Every sprite whose name starts with the same word collapsed into one group key. With `happy_pajamas`, `happy_formalwear` and `angry_formalwear_soaked_01` in a library, the Expression Engine only ever saw `happy` and `angry`. The outfit or condition was left to a random roll, so a character in pajamas could appear in formalwear. The issue asks for the agent to choose by outfit and condition from what's in the scene, using names the user already writes. ## What changed - **Agent listing.** `buildSpriteExpressionChoices` still lists each group key. For a group with more than one sprite, it now also lists each sprite's faceted name without its variant number: `angry_formalwear_soaked_01` adds `angry_formalwear_soaked`. This list feeds both the Expression Engine's `<available_sprites>` and the Game Master's sprite list. PNGTuber talk and blink frames are never listed. Libraries with only numbered variants list exactly as before. - **One shared rule.** `findSpriteExpressionFacetMatches` in `shared/utils/sprite-labels.ts` treats the first word as the group key and the words after it as facets, in the order written. A faceted name picks among its own variants. When no sprite has every facet, it drops the last facet and tries again, then falls back to the group key. `happy_pajamas_wounded` → `happy_pajamas` → `happy`. - **Resolvers.** - The server (`resolveExpression`) rolls among a faceted name's variants. A concrete numbered name such as `happy_pajamas_02` is used as is. With no facet match, it falls back to its own group before any loose substring match, and never to a talk or blink frame. - The client (`resolveSpriteExpression`) and the sprite overlay pick deterministically, so the overlay shows the most specific match across full-body and portrait sprites. - Group keys that contain a hyphen or dot (`half-smile`) still roll over their variants as before. - **Reuse.** The PNGTuber talk/blink suffix lists that the client and server each had are now one shared list. - **Docs.** `docs/characters/sprites.md` explains faceted names. - **Regression.** `scripts/regressions/sprite-expression-facets.regression.ts` covers the listing, the facet fallback chain, concrete handles, talk/blink frames on both server and client, hyphenated group keys, legacy variant groups, and the overlay's preference for the most specific match. Each case fails on the code before its fix. **Ordering, as a known limit.** Facets are read in the order the name is written, with the emotion first. That differs from the issue's suggested "outfit > emotion > condition" priority. Pose-first names like `kneeling_happy_armor_wounded` group under `kneeling`. An out-of-order request like `happy_wounded` doesn't match `happy_formalwear_wounded` and falls back to `happy`. Supporting either would need a per-character facet schema. **Prompt.** The Expression Engine's prompt template lives in Marinara-Agents (`packages/expression/agents.json`). The matching change, telling the agent about faceted names and to keep outfit and condition until the scene changes them, goes in a separate Agents PR. The Engine side works without it, but the agent only chooses faceted names deliberately once that template lands. ## 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 What the agent ran locally: - `node ./scripts/pnpm-runner.mjs check` passes, after rebasing on staging. - These regressions pass: `sprite-expression-facets`, `sprite-agent-compatibility`, `sprite-runtime-compatibility`, `sprite-folders`, `sprite-list-security`, `expression-group-generation`, `expression-tool-retirement`, `game-tts-emotion`, `avatar-2d-main-faces`, `avatar-director`, `avatar-generation`, `avatar-variant-composite` and `open-issues`. - An independent review agent fixed hyphenated group keys changing the listing and resolution. - Local CodeRabbit raised talk/blink frames reaching faceted fallbacks (server and client), the group fallback running after substring matching, and a docs wording issue. All are fixed, each with a regression. - CodeRabbit's last point, about the final substring match still choosing `unhappy_pajamas` when the library has no `happy` sprite at all, is the resolver's existing last resort and was left as is. Before this PR, `happy` and `happy_pajamas` both resolved that way too. Narrowing it would change plain group keys for every library. To verify by hand: - Manually verify in a Roleplay chat with the Expression Engine and debug mode on, using a character with sprites `happy_pajamas_01`, `happy_pajamas_02`, `happy_formalwear` and `angry_formalwear_soaked_01`. The logged `<available_sprites>` line should list `happy, happy_pajamas, happy_formalwear, angry, angry_formalwear_soaked`, with no `_01` numbers. - Manually verify in the browser that the sprite overlay shows a pajamas sprite when the agent returns `happy_pajamas`, and also when it returns the unlisted `happy_pajamas_wounded`. - Manually verify that a legacy library (`happy_01`, `happy_02`, `happy_blush`) still rotates between variants for `happy` over several turns. - Manually verify in Game mode that the Game Master's sprite list shows the faceted names, and that an expression tag such as `happy_pajamas` shows the matching sprite. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) `docs/characters/sprites.md` gains one paragraph. A `[docs-i18n] docs/characters/sprites.md` follow-up issue is opened for the translated packs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:17 +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#8726
No description provided.