[PR #8587] [MERGED] feat(roleplay): add an [html] artifact command with narrator memory #8688

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8587
Author: @ylli-selmani
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/html-artifact-command


📝 Commits (10+)

  • 05fe6b0 feat(roleplay): add the [html: …] command, advertised only with Immersive HTML
  • 5240ee0 feat(roleplay): run Immersive HTML on demand, guided and alone
  • ef24c0d docs(roleplay): document the [html] command, /html, and Only when asked
  • 4561ec2 fix(roleplay): address review findings on the on-demand HTML path
  • 522e0b2 fix(roleplay): keep an [html] request on the reply that made it
  • 069675c fix(roleplay): run earlier responders' guided rewrites in turn order
  • 02a11cf feat(roleplay): make [html] artifacts a command result with narrator memory
  • f9bd611 fix(roleplay): tidy the html artifact call after review
  • 7dfb365 fix(roleplay): html artifacts can draw, know the scene and run in parallel
  • ad24ee9 fix(roleplay): keep messages hidden from the speaker out of an artifact's scene

📊 Changes

21 files changed (+859 additions, -18 deletions)

View changed files

📝 docs/chats/slash-commands.md (+3 -0)
📝 docs/roleplay/getting-started.md (+10 -0)
📝 packages/client/src/components/chat/ChatArea.tsx (+16 -0)
📝 packages/client/src/components/chat/ChatInput.tsx (+4 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+17 -0)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+3 -0)
📝 packages/client/src/components/chat/RoleplayCommandResults.tsx (+40 -9)
📝 packages/client/src/hooks/use-generate.ts (+4 -0)
📝 packages/client/src/hooks/use-roleplay-commands.ts (+27 -1)
➕ packages/client/src/lib/artifact-svg.ts (+90 -0)
📝 packages/client/src/lib/chat-html.ts (+20 -3)
📝 packages/client/src/lib/slash-commands.ts (+19 -0)
📝 packages/client/src/localization/locales/en.json (+4 -0)
📝 packages/server/src/routes/chats.routes.ts (+49 -0)
📝 packages/server/src/routes/generate.routes.ts (+49 -4)
📝 packages/server/src/routes/generate/conversation-prompt-formatting.ts (+7 -1)
➕ packages/server/src/services/generation/html-artifact.ts (+320 -0)
📝 packages/server/src/services/generation/roleplay-commands.ts (+8 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+25 -0)
📝 packages/shared/src/types/roleplay-command.ts (+16 -0)

...and 1 more files

📄 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

Part of #8586

Why this change

Roleplay can put in-world HTML on screen in two ways, and both sit at an extreme. The Documents command is free and instant, but it renders one of six fixed styles, so "a spellbook page" arrives as a letter-styled card. The Immersive HTML agent makes bespoke HTML, but it runs after every reply, costs a model call per message, and picks the visual itself. There is no way to say "this moment needs exactly this artifact".

This adds the middle ground: the narrator asks for one artifact, the way it already asks for an image with [illustrate: subject="…"], and one model call makes it.

An artifact is a command result, not message text. Live testing of the first version showed why: its markup was saved into the message and sent back to the narrator on every later turn, and nothing showed that the command had been used.

What changed

  • [html: prompt="…"] Roleplay command. It has its own HTML Artifacts toggle under Roleplay Commands, starts off, and needs no agent in the chat. The request is capped at 2,000 characters. A reply can make 3; further commands show a limit error on their marker instead of costing a call. The narrator's command does not run in multiplayer rooms, and a card's defined intro is left as written.
  • A call of its own. The artifact is made after the reply is saved, using Immersive HTML's connection if it has one, else the default agent connection, else the chat's. Artifacts run at once up to that connection's Max Parallel Agent Jobs. The agent's prompt is not used. The call has its own short instructions and sees the speaker's description, the recent messages (formatted like the narrator's history, so whispers stay private) and where the command was placed.
  • Narrator memory. The model answers with <artifact> and <memory>: the artifact's readable text word for word, plus one line on how it looks. The narrator sees Artifact: <memory> in later turns and never the markup. This follows how the Documents command stays in history, so agents' history does not see it either.
  • The marker controls both. The "used html command" marker lets the player read and edit the memory, or delete the artifact, which removes it from view and from the narrator's memory. A failed run says why on the marker.
  • Display. The artifact renders inline where the command was placed, sanitized and with scoped CSS, following the HTML path of renderContent. It is at most 28rem wide and centered, and the prompt asks for a compact piece. It appears as a marker only in Visual Novel.
  • Drawing SVG, for artifacts only. The chat sanitizer removes all SVG, so sanitizeChatHtml gains an option that keeps a small set: shapes, text, groups, gradients and clip paths (lib/artifact-svg.ts). use, image, foreignObject, filters, animation and links stay out. Ids get a per-artifact prefix, and any url() or href that points outside the artifact is removed. Messages never set the option and keep the full ban.
  • /html <prompt>. The manual twin, through POST /chats/:chatId/roleplay-html. It adds one artifact at the end of the latest reply, works with the toggle off, and is refused during a generation. Command markers wait while it runs, so an edit cannot erase its new entry from a stale copy.
  • Proof. scripts/regressions/roleplay-commands.regression.ts covers parsing, gating, the model output parser, the prompt, the memory seam, and the limit.

UI precedents: the inline placement follows inline [illustrate], the marker and its Edit and Delete follow the other Roleplay command results in RoleplayCommandResults.tsx, and the rendering follows renderContent in ChatMessage.tsx.

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

  • Manually verify with HTML Artifacts on and no agent added: the narrator's command shows the artifact in place and a "used html command" marker.
  • Manually verify the next turn's prompt has the Artifact: line and no HTML.
  • Manually verify editing the memory on the marker changes that line, and deleting removes the artifact and the line.
  • Manually verify a fourth command in one reply shows the limit error and makes no call.
  • Manually verify /html a terminal readout works with the toggle off, and is refused during a generation.
  • Manually verify two commands in one reply run at the same time when the connection allows it, and one after the other at Max Parallel Agent Jobs 1.
  • Manually verify a marker's Edit and Delete are disabled while /html runs and work again afterwards.
  • Manually verify Visual Novel shows the marker only, and the artifact reads well in light and dark mode on a narrow screen.
  • Manually run the roleplay-commands regression: node scripts/run-regressions.mjs --filter roleplay-commands.

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
  • Version/release files updated (only if this PR includes a version bump)

docs/roleplay/getting-started.md and docs/chats/slash-commands.md are updated on this branch. The [docs-i18n] follow-up is #8603.

UI evidence (if applicable)

Pending: screenshots from live testing. The sanitizer was run in a browser against a drawn artifact and against markup with script, onload, remote image/use, foreignObject, javascript: links and escaped url(): the drawing survived and all of those were removed. Two saved artifacts then rendered correctly in a real chat, and new artifacts were generated in live testing. The 28rem cap was measured on a saved artifact; the compact prompt line has not been tried on a new one yet.

🤖 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/8587 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/html-artifact-command` --- ### 📝 Commits (10+) - [`05fe6b0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/05fe6b05dd52404f093aa0881b1d88659b44ab38) feat(roleplay): add the [html: …] command, advertised only with Immersive HTML - [`5240ee0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5240ee00dc91d6788dc3b4dfd2b6d8b74da0fbec) feat(roleplay): run Immersive HTML on demand, guided and alone - [`ef24c0d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef24c0df3c67e7521b9baf34ee4669e228223ebf) docs(roleplay): document the [html] command, /html, and Only when asked - [`4561ec2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4561ec2d6d03f6917ed68312e73df6e22ec90f4b) fix(roleplay): address review findings on the on-demand HTML path - [`522e0b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/522e0b2ecdadc822679564f329bc6fbe3d820a44) fix(roleplay): keep an [html] request on the reply that made it - [`069675c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/069675cc59deb8b6c501f42ce1b93aa826db84e2) fix(roleplay): run earlier responders' guided rewrites in turn order - [`02a11cf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/02a11cfd65d767552413a154ac64b828f6d9cf69) feat(roleplay): make [html] artifacts a command result with narrator memory - [`f9bd611`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f9bd611bbd0af74a8da827b7840c1bd9284ecbf6) fix(roleplay): tidy the html artifact call after review - [`7dfb365`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7dfb3658a85f54bac5581466c461b4791112d5e8) fix(roleplay): html artifacts can draw, know the scene and run in parallel - [`ad24ee9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad24ee93261a85fe73f37b3e225149d6f0c96cf1) fix(roleplay): keep messages hidden from the speaker out of an artifact's scene ### 📊 Changes **21 files changed** (+859 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `docs/chats/slash-commands.md` (+3 -0) 📝 `docs/roleplay/getting-started.md` (+10 -0) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+16 -0) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+4 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+17 -0) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+3 -0) 📝 `packages/client/src/components/chat/RoleplayCommandResults.tsx` (+40 -9) 📝 `packages/client/src/hooks/use-generate.ts` (+4 -0) 📝 `packages/client/src/hooks/use-roleplay-commands.ts` (+27 -1) ➕ `packages/client/src/lib/artifact-svg.ts` (+90 -0) 📝 `packages/client/src/lib/chat-html.ts` (+20 -3) 📝 `packages/client/src/lib/slash-commands.ts` (+19 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+49 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+49 -4) 📝 `packages/server/src/routes/generate/conversation-prompt-formatting.ts` (+7 -1) ➕ `packages/server/src/services/generation/html-artifact.ts` (+320 -0) 📝 `packages/server/src/services/generation/roleplay-commands.ts` (+8 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+25 -0) 📝 `packages/shared/src/types/roleplay-command.ts` (+16 -0) _...and 1 more files_ </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 Part of #8586 ## Why this change Roleplay can put in-world HTML on screen in two ways, and both sit at an extreme. The **Documents** command is free and instant, but it renders one of six fixed styles, so "a spellbook page" arrives as a letter-styled card. The **Immersive HTML** agent makes bespoke HTML, but it runs after every reply, costs a model call per message, and picks the visual itself. There is no way to say "this moment needs exactly this artifact". This adds the middle ground: the narrator asks for one artifact, the way it already asks for an image with `[illustrate: subject="…"]`, and one model call makes it. An artifact is a command result, not message text. Live testing of the first version showed why: its markup was saved into the message and sent back to the narrator on every later turn, and nothing showed that the command had been used. ## What changed - **`[html: prompt="…"]` Roleplay command.** It has its own **HTML Artifacts** toggle under Roleplay Commands, starts off, and needs no agent in the chat. The request is capped at 2,000 characters. A reply can make 3; further commands show a limit error on their marker instead of costing a call. The narrator's command does not run in multiplayer rooms, and a card's defined intro is left as written. - **A call of its own.** The artifact is made after the reply is saved, using Immersive HTML's connection if it has one, else the default agent connection, else the chat's. Artifacts run at once up to that connection's **Max Parallel Agent Jobs**. The agent's prompt is not used. The call has its own short instructions and sees the speaker's description, the recent messages (formatted like the narrator's history, so whispers stay private) and where the command was placed. - **Narrator memory.** The model answers with `<artifact>` and `<memory>`: the artifact's readable text word for word, plus one line on how it looks. The narrator sees `Artifact: <memory>` in later turns and never the markup. This follows how the Documents command stays in history, so agents' history does not see it either. - **The marker controls both.** The "used html command" marker lets the player read and edit the memory, or delete the artifact, which removes it from view and from the narrator's memory. A failed run says why on the marker. - **Display.** The artifact renders inline where the command was placed, sanitized and with scoped CSS, following the HTML path of `renderContent`. It is at most 28rem wide and centered, and the prompt asks for a compact piece. It appears as a marker only in Visual Novel. - **Drawing SVG, for artifacts only.** The chat sanitizer removes all SVG, so `sanitizeChatHtml` gains an option that keeps a small set: shapes, text, groups, gradients and clip paths (`lib/artifact-svg.ts`). `use`, `image`, `foreignObject`, filters, animation and links stay out. Ids get a per-artifact prefix, and any `url()` or `href` that points outside the artifact is removed. Messages never set the option and keep the full ban. - **`/html <prompt>`.** The manual twin, through `POST /chats/:chatId/roleplay-html`. It adds one artifact at the end of the latest reply, works with the toggle off, and is refused during a generation. Command markers wait while it runs, so an edit cannot erase its new entry from a stale copy. - **Proof.** `scripts/regressions/roleplay-commands.regression.ts` covers parsing, gating, the model output parser, the prompt, the memory seam, and the limit. **UI precedents:** the inline placement follows inline `[illustrate]`, the marker and its Edit and Delete follow the other Roleplay command results in `RoleplayCommandResults.tsx`, and the rendering follows `renderContent` in `ChatMessage.tsx`. ## 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 - [ ] Manually verify with **HTML Artifacts** on and no agent added: the narrator's command shows the artifact in place and a "used html command" marker. - [ ] Manually verify the next turn's prompt has the `Artifact:` line and no HTML. - [ ] Manually verify editing the memory on the marker changes that line, and deleting removes the artifact and the line. - [ ] Manually verify a fourth command in one reply shows the limit error and makes no call. - [ ] Manually verify `/html a terminal readout` works with the toggle off, and is refused during a generation. - [ ] Manually verify two commands in one reply run at the same time when the connection allows it, and one after the other at Max Parallel Agent Jobs 1. - [ ] Manually verify a marker's Edit and Delete are disabled while `/html` runs and work again afterwards. - [ ] Manually verify Visual Novel shows the marker only, and the artifact reads well in light and dark mode on a narrow screen. - [ ] Manually run the roleplay-commands regression: `node scripts/run-regressions.mjs --filter roleplay-commands`. ## 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 - [ ] Version/release files updated (only if this PR includes a version bump) `docs/roleplay/getting-started.md` and `docs/chats/slash-commands.md` are updated on this branch. The `[docs-i18n]` follow-up is #8603. ## UI evidence (if applicable) Pending: screenshots from live testing. The sanitizer was run in a browser against a drawn artifact and against markup with script, `onload`, remote `image`/`use`, `foreignObject`, `javascript:` links and escaped `url()`: the drawing survived and all of those were removed. Two saved artifacts then rendered correctly in a real chat, and new artifacts were generated in live testing. The 28rem cap was measured on a saved artifact; the compact prompt line has not been tried on a new one yet. 🤖 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:38:56 +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#8688
No description provided.