[PR #1748] [MERGED] feat: creator notes CSS injection with tri-state mode #5258

Closed
opened 2026-10-22 04:14:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1748
Author: @kolacheee
Created: 5/31/2026
Status: ✅ Merged
Merged: 5/31/2026
Merged by: @cha1latte

Base: refactor ← Head: feat/creator-notes-css


📝 Commits (8)

  • 5e66284 feat: creator notes CSS injection with tri-state mode
  • 8d5b2b8 feat: @chat-mode query system for mode-aware card CSS
  • 94c595a fix: add data-card-css to grouped conversation message wrapper
  • beefe14 fix: treat [data-card-css] as scope-root in CSS scoping
  • 58823b3 security: harden CSS sanitizer and regex import against malicious cards
  • a7ebc68 docs: add card CSS theming guide for character creators
  • 7f0b8b3 fix: resolve architecture violations and unused export
  • 19726d3 Prepare creator notes CSS PR for review

📊 Changes

20 files changed (+1052 additions, -5 deletions)

View changed files

➕ docs/card-css-theming-guide.md (+345 -0)
📝 src/engine/contracts/types/chat.ts (+4 -0)
📝 src/features/modes/conversation/components/ConversationMessage.tsx (+2 -0)
📝 src/features/modes/conversation/components/ConversationModeRoute.tsx (+13 -0)
📝 src/features/modes/conversation/components/ConversationView.tsx (+1 -1)
📝 src/features/modes/game/components/GameConversationView.tsx (+13 -0)
📝 src/features/modes/game/components/GameNarration.tsx (+10 -2)
📝 src/features/modes/game/components/GameSurface.tsx (+1 -1)
📝 src/features/modes/roleplay/components/ChatRoleplaySurface.tsx (+1 -1)
📝 src/features/modes/roleplay/components/RoleplayModeRoute.tsx (+13 -0)
📝 src/features/modes/shared/chat-ui/components/ChatMessage.tsx (+3 -0)
📝 src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx (+95 -0)
➕ src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.test.tsx (+81 -0)
➕ src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.tsx (+100 -0)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts (+1 -0)
📝 src/features/modes/shared/chat-ui/index.ts (+2 -0)
➕ src/shared/lib/chat-css.test.ts (+83 -0)
➕ src/shared/lib/chat-css.ts (+259 -0)
➕ src/shared/lib/creator-notes-css.test.ts (+13 -0)
➕ src/shared/lib/creator-notes-css.ts (+12 -0)

📄 Description

Linked issue

Closes #1757

Why this change

Character card creators should be able to embed custom CSS in their cards to give characters a unique visual identity across roleplay, conversation, and game surfaces. This brings the refactored Tauri architecture a clean client-side version of the card theming idea that was partially explored in old-engine PR #1058.

What changed

  • Added creator-notes CSS extraction from <style> blocks.
  • Added card CSS filtering for @chat-mode roleplay, @chat-mode conversation, and @chat-mode game.
  • Added sanitization/scoping for card-authored CSS before it is injected into the page.
  • Added CreatorNotesCssInjector for chat-wide, character-exclusive, and disabled card CSS modes.
  • Added cardCssMode to chat metadata and a Card Theming section in chat settings.
  • Added mari-card-css / data-chat-mode surface attributes and data-card-css message attributes across roleplay, conversation, and game surfaces.
  • Added docs/card-css-theming-guide.md.
  • Follow-up readiness fix: exported CreatorNotesCssInjector through the shared chat-ui barrel so mode routes no longer import a private component path.
  • Follow-up security fix: blocked non-empty CSS content declarations even when the declaration omits a trailing semicolon.
  • Follow-up proof: added focused tests for CSS extraction, mode filtering, sanitizer/scoping behavior, and injector enabled/disabled/exclusive paths.

Refactor impact

Primary owner: shared mode UI, with consumer changes in roleplay, conversation, and game mode surfaces.

Impact areas reviewed:

  • src/engine/contracts/types/chat.ts adds optional ChatMetadata.cardCssMode.
  • src/shared/lib/creator-notes-css.ts extracts card CSS from creator notes.
  • src/shared/lib/chat-css.ts filters, sanitizes, and scopes card CSS.
  • src/features/modes/shared/chat-ui/ owns the injector, settings UI, metadata access, and shared exports.
  • src/features/modes/roleplay/, src/features/modes/conversation/, and src/features/modes/game/ render the injector and expose targetable surface/message attributes.
  • docs/card-css-theming-guide.md documents author-facing usage and limits.

Boundary notes:

  • No Rust/Tauri changes.
  • No prompt assembly or generation changes.
  • No remote runtime changes.
  • Existing character/card data is read but not mutated or migrated.

Pressure points touched:

  • ChatRoleplaySurface, ConversationView, and GameSurface surface attributes.
  • ChatMessage, ConversationMessage, and GameNarration message wrapper attributes.
  • ChatSettingsDrawer Card Theming controls.
  • CSS sanitizer handling for untrusted user-authored card styles.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • pnpm check passes locally before PR push/handoff, including the unused-code check
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Browser screenshot/recording evidence added when UI/browser state is the claim
  • Remote runtime smoke checked when relevant

Manual verification notes

Codex machine proof:

  • pnpm test -- src/shared/lib/creator-notes-css.test.ts src/shared/lib/chat-css.test.ts src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.test.tsx passed: 3 files, 11 tests.
  • pnpm check passed after the final diff.
  • Local Marinara proof gate passed against the scratch verification ledger.
  • Bunny review passed locally with the UI screenshot note below as a non-blocking disclosed limitation.

Human/manual note:

  • No GitHub-hosted browser screenshots or recordings were uploaded during this local readiness pass. The core extraction/sanitization/scoping/injection behavior is covered by tests and the full repo check; screenshots would still be useful reviewer evidence for the visible styling surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

Docs note: added docs/card-css-theming-guide.md.

UI evidence (if applicable)

No GitHub-hosted screenshots or recordings were uploaded in this pass. The visible UI behavior is supported by focused jsdom injector coverage plus full local validation; a reviewer can add screenshots later if they want reviewer-visible visual evidence before merge.


🔄 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/1748 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 5/31/2026 **Status:** ✅ Merged **Merged:** 5/31/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `feat/creator-notes-css` --- ### 📝 Commits (8) - [`5e66284`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5e6628427faa660e74306d7bef57103063676249) feat: creator notes CSS injection with tri-state mode - [`8d5b2b8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8d5b2b8b1a234f42b623556444490be7c75c7988) feat: @chat-mode query system for mode-aware card CSS - [`94c595a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/94c595ac3d9b663d51be87e524e9c796916f5853) fix: add data-card-css to grouped conversation message wrapper - [`beefe14`](https://github.com/Pasta-Devs/Marinara-Engine/commit/beefe1410380c23edec7473385db3e269b2870c9) fix: treat [data-card-css] as scope-root in CSS scoping - [`58823b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/58823b30af3d81622a6ad88f38d2bc3b1dd90eb5) security: harden CSS sanitizer and regex import against malicious cards - [`a7ebc68`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7ebc68b0dee2f8005a0fdb13446ca7827f0f684) docs: add card CSS theming guide for character creators - [`7f0b8b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7f0b8b3c75d4848047b1b244797448f9410af1c3) fix: resolve architecture violations and unused export - [`19726d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/19726d3f8fd0405fc30c178df3d85b8c8d0cd8c7) Prepare creator notes CSS PR for review ### 📊 Changes **20 files changed** (+1052 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `docs/card-css-theming-guide.md` (+345 -0) 📝 `src/engine/contracts/types/chat.ts` (+4 -0) 📝 `src/features/modes/conversation/components/ConversationMessage.tsx` (+2 -0) 📝 `src/features/modes/conversation/components/ConversationModeRoute.tsx` (+13 -0) 📝 `src/features/modes/conversation/components/ConversationView.tsx` (+1 -1) 📝 `src/features/modes/game/components/GameConversationView.tsx` (+13 -0) 📝 `src/features/modes/game/components/GameNarration.tsx` (+10 -2) 📝 `src/features/modes/game/components/GameSurface.tsx` (+1 -1) 📝 `src/features/modes/roleplay/components/ChatRoleplaySurface.tsx` (+1 -1) 📝 `src/features/modes/roleplay/components/RoleplayModeRoute.tsx` (+13 -0) 📝 `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` (+3 -0) 📝 `src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx` (+95 -0) ➕ `src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.test.tsx` (+81 -0) ➕ `src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.tsx` (+100 -0) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` (+1 -0) 📝 `src/features/modes/shared/chat-ui/index.ts` (+2 -0) ➕ `src/shared/lib/chat-css.test.ts` (+83 -0) ➕ `src/shared/lib/chat-css.ts` (+259 -0) ➕ `src/shared/lib/creator-notes-css.test.ts` (+13 -0) ➕ `src/shared/lib/creator-notes-css.ts` (+12 -0) </details> ### 📄 Description ## Linked issue Closes #1757 ## Why this change Character card creators should be able to embed custom CSS in their cards to give characters a unique visual identity across roleplay, conversation, and game surfaces. This brings the refactored Tauri architecture a clean client-side version of the card theming idea that was partially explored in old-engine PR #1058. ## What changed - Added creator-notes CSS extraction from `<style>` blocks. - Added card CSS filtering for `@chat-mode roleplay`, `@chat-mode conversation`, and `@chat-mode game`. - Added sanitization/scoping for card-authored CSS before it is injected into the page. - Added `CreatorNotesCssInjector` for chat-wide, character-exclusive, and disabled card CSS modes. - Added `cardCssMode` to chat metadata and a Card Theming section in chat settings. - Added `mari-card-css` / `data-chat-mode` surface attributes and `data-card-css` message attributes across roleplay, conversation, and game surfaces. - Added `docs/card-css-theming-guide.md`. - Follow-up readiness fix: exported `CreatorNotesCssInjector` through the shared chat-ui barrel so mode routes no longer import a private component path. - Follow-up security fix: blocked non-empty CSS `content` declarations even when the declaration omits a trailing semicolon. - Follow-up proof: added focused tests for CSS extraction, mode filtering, sanitizer/scoping behavior, and injector enabled/disabled/exclusive paths. ## Refactor impact Primary owner: shared mode UI, with consumer changes in roleplay, conversation, and game mode surfaces. Impact areas reviewed: - `src/engine/contracts/types/chat.ts` adds optional `ChatMetadata.cardCssMode`. - `src/shared/lib/creator-notes-css.ts` extracts card CSS from creator notes. - `src/shared/lib/chat-css.ts` filters, sanitizes, and scopes card CSS. - `src/features/modes/shared/chat-ui/` owns the injector, settings UI, metadata access, and shared exports. - `src/features/modes/roleplay/`, `src/features/modes/conversation/`, and `src/features/modes/game/` render the injector and expose targetable surface/message attributes. - `docs/card-css-theming-guide.md` documents author-facing usage and limits. Boundary notes: - No Rust/Tauri changes. - No prompt assembly or generation changes. - No remote runtime changes. - Existing character/card data is read but not mutated or migrated. Pressure points touched: - `ChatRoleplaySurface`, `ConversationView`, and `GameSurface` surface attributes. - `ChatMessage`, `ConversationMessage`, and `GameNarration` message wrapper attributes. - `ChatSettingsDrawer` Card Theming controls. - CSS sanitizer handling for untrusted user-authored card styles. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] `pnpm check` passes locally before PR push/handoff, including the unused-code check - [x] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [x] `pnpm check:architecture` passes locally - [x] `pnpm check:docs` passes locally - [x] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Browser screenshot/recording evidence added when UI/browser state is the claim - [ ] Remote runtime smoke checked when relevant ### Manual verification notes Codex machine proof: - `pnpm test -- src/shared/lib/creator-notes-css.test.ts src/shared/lib/chat-css.test.ts src/features/modes/shared/chat-ui/components/CreatorNotesCssInjector.test.tsx` passed: 3 files, 11 tests. - `pnpm check` passed after the final diff. - Local Marinara proof gate passed against the scratch verification ledger. - Bunny review passed locally with the UI screenshot note below as a non-blocking disclosed limitation. Human/manual note: - No GitHub-hosted browser screenshots or recordings were uploaded during this local readiness pass. The core extraction/sanitization/scoping/injection behavior is covered by tests and the full repo check; screenshots would still be useful reviewer evidence for the visible styling surface. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims Docs note: added `docs/card-css-theming-guide.md`. ## UI evidence (if applicable) No GitHub-hosted screenshots or recordings were uploaded in this pass. The visible UI behavior is supported by focused jsdom injector coverage plus full local validation; a reviewer can add screenshots later if they want reviewer-visible visual evidence before merge. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:14:40 +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#5258
No description provided.