[PR #4522] [MERGED] feat(gallery): portable card://self/gallery references for chat images #6409

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4522
Author: @kolacheee
Created: 8/3/2026
Status: ✅ Merged
Merged: 8/3/2026
Merged by: @kolacheee

Base: staging ← Head: feat/card-self-gallery


📝 Commits (7)

  • 2207d52 feat(gallery): portable card://self/gallery references for chat images
  • 6011227 fix(gallery): address multi-agent review of portable references
  • cd22b20 feat(gallery): resolve card://self from any chat character's gallery on miss
  • 8070b4d docs(gallery): system messages show self refs as literal text, not broken images
  • b365d8f docs(gallery): remove em dashes from the new prose
  • 0121141 Merge branch 'staging' into feat/card-self-gallery
  • f4f62b8 fix(gallery): no cross-character fallback while the speaker's gallery is loading

📊 Changes

19 files changed (+377 additions, -30 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/characters/creating-and-editing-characters.md (+2 -0)
📝 docs/characters/galleries.md (+30 -0)
📝 docs/chats/sending-and-streaming.md (+14 -0)
📝 packages/client/src/components/characters/CharacterEditor.tsx (+39 -0)
📝 packages/client/src/components/chat/ChatCharacterDropOptions.tsx (+1 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+27 -8)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+1 -0)
📝 packages/client/src/components/chat/ConversationMessage.tsx (+30 -6)
📝 packages/client/src/components/chat/ConversationMessageBubble.tsx (+14 -0)
📝 packages/client/src/components/chat/ConversationMessageGrouped.tsx (+14 -0)
📝 packages/client/src/components/chat/ConversationMessageLine.tsx (+4 -2)
📝 packages/client/src/components/chat/ConversationMessageShared.tsx (+23 -3)
📝 packages/client/src/components/ui/MacroTextarea.tsx (+5 -1)
📝 packages/client/src/hooks/use-characters.ts (+41 -1)
📝 packages/client/src/lib/card-asset-links.ts (+79 -0)
📝 packages/client/src/localization/locales/en.json (+3 -0)
📝 packages/server/src/routes/characters.routes.ts (+9 -7)
📝 packages/server/src/services/import/marinara.importer.ts (+40 -2)

📄 Description

Linked issue

No filed issue — direct maintainer request from using the feature gap: embedding a gallery image in a greeting required an absolute URL (breaks off-host) or an id-baked card://characters/<id>/... link (breaks on import, since character ids are regenerated). Happy to open a tracking issue if maintainers prefer one on record.

Why this change

Character creators who put gallery images in greetings or messages currently ship broken images to everyone who imports their card: absolute URLs point at the author's host, and id-baked card:// links point at an id that no longer exists after import. The one identifier that can survive a native export round trip is the gallery filename — this PR makes a reference form that keys on it, and fixes the two export/import defects that would otherwise quietly break the promise.

What changed

The portable form: card://self/gallery/<filename> — self resolves at render time to the character speaking the message.

  • Conversation mode resolves in MessageContent (one chat-only component covering all render sites), with a new name-to-id map alongside charByName so group-chat multi-speaker replies resolve self per speaker segment — each character's line shows that character's own gallery.
  • Any-owner fallback (group chats): a chat-wide gallery filename index (new useChatGalleryFilenameIndex hook — group chats only, shares the per-character gallery cache, refetch-stable identity) lets a self reference resolve to whichever chat character owns the file when the speaker's gallery doesn't have it — so Roleplay merged group replies and mis-attributed segments still show the right art. The speaker always wins on filename collisions; otherwise first match in chat order (documented). When the index knows no owner (or isn't loaded), the speaker rewrite is kept, so a stale cache can never break what works today.
  • Roleplay mode resolves in renderContent, covering messages, translations, and greeting previews (both the markdown and embedded-HTML branches). Greeting pickers (ChatCharacterDropOptions, chat-settings greeting confirm) preview with the same character id the created message will carry.
  • Editor previews: MacroTextarea's markdown preview resolves self against the edited character for First Message, Alternate Greetings, Example Dialogue, Description, Creator Notes, and the Advanced prompt fields.
  • Graceful degradation: user/system messages never resolve self (deliberate isUser || isSystem gates in both modes) — the reference shows as a broken image, identical to any other unresolvable card:// scope. The resolver gains a documentary self case so nobody "fixes" it by wiring in an arbitrary participant.
  • Copy image reference button (link icon) on character-gallery tiles copies ready-to-paste markdown: ![label](card://self/gallery/<file>). Three new localization keys in en.json (sorted; key-reference regression passes).
  • The shared markdown renderer signatures are untouched; resolution is a pure prefix rewrite (literal regex, function replacer, filenames never touched) applied before rendering.

Export/import fixes that make the promise true (found by recon + adversarial review):

  • The native-export importer discarded original gallery filenames (minted random names), so no gallery reference of any form survived import. It now preserves the exported filename: sanitized stem (traversal-guarded, ..-proof including dot-run/trailing-dot recombination — property-tested), extension always derived from the decoded image (never the envelope), with the one allowed alias (.jpeg/.jpg) keeping its original spelling so references don't break, and collision suffixes for merged galleries.
  • The native export silently dropped generated gallery images (selfie/generated rows keep canonical shared/ or chat-scoped paths; the reader hardcoded the character directory). It now resolves through resolveStoredGalleryFile — the same helper the serving route uses — so generated images export and re-import like uploads.

Documentation (this was undocumented entirely — zero mentions of card:// or putting gallery images in chat anywhere in docs/):

  • docs/characters/galleries.md — new Reuse a gallery image in messages and greetings: the copy button, the self rule, where it works and deliberately doesn't (own messages, personas), the group-chat fallback with its collision rule (speaker first, then first match in chat order), why self beats the id form, and the honest PNG-export caveat.
  • docs/chats/sending-and-streaming.md — new Insert a gallery image into a message: attachments (for the AI to see) vs gallery references (for the reader to see), the markdown/card:// forms, cross-link to the galleries guide.
  • docs/characters/creating-and-editing-characters.md — cross-reference from Dialogue & Greetings.
  • CHANGELOG entry under [Unreleased].

Out of scope, per maintainer: PNG card exports (no gallery payload — documented as a caveat, not fixed). Persona-gallery portability would need its own scope and audit — untouched.

Review process

Tiered multi-agent pipeline: recon scanners mapped the render pipeline (every markdown site + id availability), gallery UI producers, the full card:// ecosystem, and docs coverage; a synthesis pass produced the design — and caught the importer filename-discard blocker that would have shipped the feature broken. After implementation, four adversarial reviewers (resolution correctness, regressions, hostile inputs, importer security + docs accuracy) produced 11 findings, each independently double-verified: 8 confirmed (deduplicating to 4 real issues — all fixed in the follow-up commit), 3 refuted with proof the flagged path is unreachable dead code.

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

Automated on the dev machine: full pnpm lint (shared + server + client typechecks + eslint) clean; client production build clean; pnpm regression:localization, pnpm regression:docs (all 11 language packs), and pnpm regression:backup pass; the stem sanitizer property-tested against hostile filenames (beach..sunset.png, a/../../b.png, dot-runs, 120-char names — none can produce ..).

To verify in a real browser before merge (server pieces need a server rebuild):

  • Character gallery: hover an image, Copy image reference, paste into First Message — the editor preview shows the image; start a chat — the greeting renders it.
  • Same reference in a Conversation-mode chat message from that character renders; paste the identical text into your own message — broken image (by design), no crash.
  • Conversation group chat, merged reply with two speakers each referencing their own gallery file — each segment shows its own character's image.
  • Roleplay merged group reply where a non-lead character's segment references that character's own gallery file — the fallback resolves it to the owning character (and a filename both characters share resolves to the speaker).
  • Roleplay mode: greeting with a self ref renders; greeting picker preview matches.
  • Round trip: native-export a character whose greeting uses card://self/gallery/... (include a .jpeg upload and a generated selfie in the gallery), import on a clean profile — gallery filenames preserved, greeting images render. This exercises both export/import fixes.
  • Editing a message shows the raw portable text; copying a message copies the portable form.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

Docs touched: docs/characters/galleries.md, docs/chats/sending-and-streaming.md, docs/characters/creating-and-editing-characters.md, CHANGELOG.md. No version bump. A [docs-i18n] follow-up issue will be filed for the translated language packs (no renames/deletions, so a follow-up issue suffices per CONTRIBUTING.md).

UI evidence (if applicable)

{9C026DE1-59E5-4F6F-9147-AA14EAE32A71} {42FA0A2B-98D7-4AA8-B44A-B94E7DF49A20}

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added portable references for displaying character Gallery images in greetings, messages, previews, and group conversations.
    • Added one-click copying for Gallery image references.
    • References resolve to the correct speaking character, including grouped conversations.
  • Bug Fixes
    • Improved Gallery image export and import with filename preservation, extension support, and collision-safe naming.
  • Documentation
    • Added guidance for using Gallery images in character cards, chats, greetings, and Roleplay Mode.

🔄 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/4522 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/3/2026 **Status:** ✅ Merged **Merged:** 8/3/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/card-self-gallery` --- ### 📝 Commits (7) - [`2207d52`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2207d52bd9b62a7d02a10dc6e5bdeb76b225065d) feat(gallery): portable card://self/gallery references for chat images - [`6011227`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6011227d4b8192cd1e625c6b500489dab10a7517) fix(gallery): address multi-agent review of portable references - [`cd22b20`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cd22b2057471085629a1a8244fffbee08ed03388) feat(gallery): resolve card://self from any chat character's gallery on miss - [`8070b4d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8070b4da99af07299465bdae3ec6936d01ff1105) docs(gallery): system messages show self refs as literal text, not broken images - [`b365d8f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b365d8ff0fd17028ac17fc6bb5e4dd8ba24a5539) docs(gallery): remove em dashes from the new prose - [`0121141`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0121141aa47d362a9d03f9cffd076e77488645a6) Merge branch 'staging' into feat/card-self-gallery - [`f4f62b8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f4f62b89dc9c6458cb0f28d0ebc3a87375fc91ab) fix(gallery): no cross-character fallback while the speaker's gallery is loading ### 📊 Changes **19 files changed** (+377 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/characters/creating-and-editing-characters.md` (+2 -0) 📝 `docs/characters/galleries.md` (+30 -0) 📝 `docs/chats/sending-and-streaming.md` (+14 -0) 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+39 -0) 📝 `packages/client/src/components/chat/ChatCharacterDropOptions.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+27 -8) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ConversationMessage.tsx` (+30 -6) 📝 `packages/client/src/components/chat/ConversationMessageBubble.tsx` (+14 -0) 📝 `packages/client/src/components/chat/ConversationMessageGrouped.tsx` (+14 -0) 📝 `packages/client/src/components/chat/ConversationMessageLine.tsx` (+4 -2) 📝 `packages/client/src/components/chat/ConversationMessageShared.tsx` (+23 -3) 📝 `packages/client/src/components/ui/MacroTextarea.tsx` (+5 -1) 📝 `packages/client/src/hooks/use-characters.ts` (+41 -1) 📝 `packages/client/src/lib/card-asset-links.ts` (+79 -0) 📝 `packages/client/src/localization/locales/en.json` (+3 -0) 📝 `packages/server/src/routes/characters.routes.ts` (+9 -7) 📝 `packages/server/src/services/import/marinara.importer.ts` (+40 -2) </details> ### 📄 Description ## Linked issue No filed issue — direct maintainer request from using the feature gap: embedding a gallery image in a greeting required an absolute URL (breaks off-host) or an id-baked `card://characters/<id>/...` link (breaks on import, since character ids are regenerated). Happy to open a tracking issue if maintainers prefer one on record. ## Why this change Character creators who put gallery images in greetings or messages currently ship broken images to everyone who imports their card: absolute URLs point at the author's host, and id-baked `card://` links point at an id that no longer exists after import. The one identifier that *can* survive a native export round trip is the gallery filename — this PR makes a reference form that keys on it, and fixes the two export/import defects that would otherwise quietly break the promise. ## What changed **The portable form:** `card://self/gallery/<filename>` — `self` resolves at render time to the character **speaking the message**. - **Conversation mode** resolves in `MessageContent` (one chat-only component covering all render sites), with a new name-to-id map alongside `charByName` so **group-chat multi-speaker replies resolve `self` per speaker segment** — each character's line shows that character's own gallery. - **Any-owner fallback (group chats):** a chat-wide gallery filename index (new `useChatGalleryFilenameIndex` hook — group chats only, shares the per-character gallery cache, refetch-stable identity) lets a `self` reference resolve to whichever chat character owns the file when the speaker's gallery doesn't have it — so Roleplay merged group replies and mis-attributed segments still show the right art. The speaker always wins on filename collisions; otherwise first match in chat order (documented). When the index knows no owner (or isn't loaded), the speaker rewrite is kept, so a stale cache can never break what works today. - **Roleplay mode** resolves in `renderContent`, covering messages, translations, and greeting previews (both the markdown and embedded-HTML branches). Greeting pickers (`ChatCharacterDropOptions`, chat-settings greeting confirm) preview with the same character id the created message will carry. - **Editor previews**: `MacroTextarea`'s markdown preview resolves `self` against the edited character for First Message, Alternate Greetings, Example Dialogue, Description, Creator Notes, and the Advanced prompt fields. - **Graceful degradation**: user/system messages never resolve `self` (deliberate `isUser || isSystem` gates in both modes) — the reference shows as a broken image, identical to any other unresolvable `card://` scope. The resolver gains a documentary `self` case so nobody "fixes" it by wiring in an arbitrary participant. - **Copy image reference** button (link icon) on character-gallery tiles copies ready-to-paste markdown: `![label](card://self/gallery/<file>)`. Three new localization keys in `en.json` (sorted; key-reference regression passes). - The shared markdown renderer signatures are untouched; resolution is a pure prefix rewrite (literal regex, function replacer, filenames never touched) applied before rendering. **Export/import fixes that make the promise true** (found by recon + adversarial review): - The native-export **importer discarded original gallery filenames** (minted random names), so no gallery reference of any form survived import. It now preserves the exported filename: sanitized stem (traversal-guarded, `..`-proof including dot-run/trailing-dot recombination — property-tested), extension always derived from the *decoded* image (never the envelope), with the one allowed alias (`.jpeg`/`.jpg`) keeping its original spelling so references don't break, and collision suffixes for merged galleries. - The native **export silently dropped generated gallery images** (selfie/generated rows keep canonical `shared/` or chat-scoped paths; the reader hardcoded the character directory). It now resolves through `resolveStoredGalleryFile` — the same helper the serving route uses — so generated images export and re-import like uploads. **Documentation** (this was undocumented entirely — zero mentions of `card://` or putting gallery images in chat anywhere in `docs/`): - `docs/characters/galleries.md` — new **Reuse a gallery image in messages and greetings**: the copy button, the `self` rule, where it works and deliberately doesn't (own messages, personas), the group-chat fallback with its collision rule (speaker first, then first match in chat order), why `self` beats the id form, and the honest PNG-export caveat. - `docs/chats/sending-and-streaming.md` — new **Insert a gallery image into a message**: attachments (for the AI to see) vs gallery references (for the reader to see), the markdown/`card://` forms, cross-link to the galleries guide. - `docs/characters/creating-and-editing-characters.md` — cross-reference from Dialogue & Greetings. - CHANGELOG entry under `[Unreleased]`. Out of scope, per maintainer: PNG card exports (no gallery payload — documented as a caveat, not fixed). Persona-gallery portability would need its own scope and audit — untouched. ### Review process Tiered multi-agent pipeline: recon scanners mapped the render pipeline (every markdown site + id availability), gallery UI producers, the full `card://` ecosystem, and docs coverage; a synthesis pass produced the design — and caught the importer filename-discard blocker that would have shipped the feature broken. After implementation, four adversarial reviewers (resolution correctness, regressions, hostile inputs, importer security + docs accuracy) produced 11 findings, each independently double-verified: 8 confirmed (deduplicating to 4 real issues — all fixed in the follow-up commit), 3 refuted with proof the flagged path is unreachable dead code. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Automated on the dev machine: full `pnpm lint` (shared + server + client typechecks + eslint) clean; client production build clean; `pnpm regression:localization`, `pnpm regression:docs` (all 11 language packs), and `pnpm regression:backup` pass; the stem sanitizer property-tested against hostile filenames (`beach..sunset.png`, `a/../../b.png`, dot-runs, 120-char names — none can produce `..`). To verify in a real browser before merge (server pieces need a server rebuild): - Character gallery: hover an image, **Copy image reference**, paste into First Message — the editor preview shows the image; start a chat — the greeting renders it. - Same reference in a Conversation-mode chat message from that character renders; paste the identical text into **your own** message — broken image (by design), no crash. - Conversation group chat, merged reply with two speakers each referencing their own gallery file — each segment shows its own character's image. - Roleplay merged group reply where a non-lead character's segment references that character's own gallery file — the fallback resolves it to the owning character (and a filename both characters share resolves to the speaker). - Roleplay mode: greeting with a `self` ref renders; greeting picker preview matches. - Round trip: native-export a character whose greeting uses `card://self/gallery/...` (include a `.jpeg` upload and a **generated** selfie in the gallery), import on a clean profile — gallery filenames preserved, greeting images render. This exercises both export/import fixes. - Editing a message shows the raw portable text; copying a message copies the portable form. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) Docs touched: `docs/characters/galleries.md`, `docs/chats/sending-and-streaming.md`, `docs/characters/creating-and-editing-characters.md`, `CHANGELOG.md`. No version bump. A `[docs-i18n]` follow-up issue will be filed for the translated language packs (no renames/deletions, so a follow-up issue suffices per `CONTRIBUTING.md`). ## UI evidence (if applicable) <img width="381" height="162" alt="{9C026DE1-59E5-4F6F-9147-AA14EAE32A71}" src="https://github.com/user-attachments/assets/e5949663-1a15-45c8-80d6-d2aeb7a46329" /> <img width="280" height="193" alt="{42FA0A2B-98D7-4AA8-B44A-B94E7DF49A20}" src="https://github.com/user-attachments/assets/3c7daea2-336e-43cc-b445-d57a5b216d93" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Added portable references for displaying character Gallery images in greetings, messages, previews, and group conversations. * Added one-click copying for Gallery image references. * References resolve to the correct speaking character, including grouped conversations. * **Bug Fixes** * Improved Gallery image export and import with filename preservation, extension support, and collision-safe naming. * **Documentation** * Added guidance for using Gallery images in character cards, chats, greetings, and Roleplay Mode. <!-- 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:10:09 +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#6409
No description provided.