mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #6735] [MERGED] Add per-chat variables usable in your own messages #7305
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7305
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6735
Author: @kentarofujiy
Created: 9/26/2026
Status: ✅ Merged
Merged: 9/28/2026
Merged by: @SpicyMarinara
Base:
staging← Head:feat/chat-variables📝 Commits (10+)
e0cb2fbfeat(chat): resolve per-chat {{name}} variables in messages6ad42bbfix(chat): keep chat variable edits made while a save is in flight519faadfix(chat): confirm chat variable writes and reset rows per chate3d39e4Merge staging into feat/chat-variables and resolve conflictsf97af84Merge branch 'staging' into feat/chat-variables39cde53fix(chat): preset precedence, queued renames, and legacy variable names5ece78aMerge branch 'staging' into feat/chat-variables21fd0b0refactor(prompt): read a dry run's preset parts once2934ca0Merge branch 'staging' into feat/chat-variablesf979493Merge branch 'staging' into feat/chat-variables📊 Changes
23 files changed (+1947 additions, -33 deletions)
View changed files
📝
CHANGELOG.md(+2 -0)📝
docs/chats/chat-settings.md(+14 -0)📝
docs/prompts/macros.md(+16 -2)📝
docs/prompts/preset-variables.md(+1 -1)➕
e2e/chat-variables.e2e.ts(+258 -0)📝
packages/client/src/components/chat/ChatSettingsDrawer.tsx(+21 -0)➕
packages/client/src/features/chat-settings/sections/ChatVariablesSection.tsx(+239 -0)➕
packages/client/src/features/chat-settings/sections/chat-variables-rows.ts(+119 -0)📝
packages/client/src/localization/locales/en.json(+14 -0)📝
packages/server/src/routes/chats.routes.ts(+75 -1)📝
packages/server/src/routes/generate.routes.ts(+41 -7)📝
packages/server/src/routes/generate/dry-run-route.ts(+46 -10)📝
packages/server/src/services/prompt/index.ts(+3 -0)📝
packages/server/src/services/prompt/macro-context.ts(+67 -2)📝
packages/shared/src/index.ts(+1 -0)➕
packages/shared/src/utils/chat-variables.ts(+100 -0)📝
packages/shared/src/utils/macro-engine.ts(+68 -8)➕
scripts/regressions/chat-variables-persistence.regression.ts(+290 -0)➕
scripts/regressions/chat-variables-preset-precedence.regression.ts(+136 -0)➕
scripts/regressions/chat-variables-rows.regression.ts(+149 -0)...and 3 more files
📄 Description
Linked issue
Closes #6734
Why this change
{{char1}}and having the model read "Mary" was not possible:{{setvar}}and{{getvar}}typed into a message both resolve to an empty string, because the client resolves macros before the message is stored with a context that carries no variable map, so the stored text is already blank and the server never sees the macro.char1leaves the literal tag in the prompt.macroVariables, written by{{setvar}}from prompt sections and lorebook entries, but nothing in the UI showed or edited them. That state was invisible.What changed
packages/client/src/features/chat-settings/sections/ChatVariablesSection.tsx): name/value rows, add and remove, commit on blur or Enter, an atomic rename, and live name validation. It reuses the existing per-chatmacroVariablesstore, so values a prompt or lorebook set show up as editable rows.{{NAME}}catch-all falls back to the chat's variables after the preset variables (packages/shared/src/utils/macro-engine.ts). Every path that already passes that map starts working at once: typed messages, prompt sections, lorebooks, character cards, Peek Prompt. Preset variables keep precedence on a name clash. The{{#if}}operand paths get the same fallback.{{toString}}previously resolved to"function toString() { [native code] }"in any macro-enabled field.packages/shared/src/utils/chat-variables.ts), with the reserved set derived fromSUPPORTED_MACROSrather than hand-maintained. A built-in macro name is refused, because a built-in always resolves first and such a variable could never be read.PATCH /chats/:id/metadatamergesmacroVariablesinstead of replacing them, with anullvalue meaning removal. A generation persists its own{{setvar}}writes into the same key mid-request, so a whole-map write from the drawer would have dropped them. A combined patch is refused rather than silently skipping the other keys' handling.scripts/regressions/chat-variables.regression.ts(lookup order, prototype guards, conditionals, naming rules) andscripts/regressions/chat-variables-persistence.regression.ts(merge and removal semantics against the real route), plus additions toprompt.regression.tsfor history resolution and preview isolation.docs/prompts/macros.md,docs/prompts/preset-variables.md,docs/chats/chat-settings.md, and aCHANGELOG.md[Unreleased]entry.Behavior changes to be aware of
docs/prompts/macros.mdsaid any unknown{{name}}survives verbatim. A name matching a chat variable now resolves instead, so decorative{{mood}}text in a chat that also definesmoodwill expand. Documented in the same change.{{mood}}and a variable of that name exists, it expands next turn. The escape hatch, if it ever bites, is a resolve option that is on for prompt paths and off for assistant history — deliberately not built up front.{{setvar}}shares the same store, while newer editor changes win over a generation started from an older snapshot.Validation
Final integration head:
dfbdad7a5, based on staging91163c901.Full
pnpm checkand all four chat-variable regression files pass. Prompt regressions also passed for the macro/assembly changes.24/24 focused browser cases pass on the combined navigation base, across desktop Chromium, mobile Chromium and mobile WebKit. The seven-case UI smoke suite also passes for the final feature changes; required CI repeats smoke on each integration head.
Browser coverage includes successful and failed queued renames/deletions, keeping an independently recreated original name, and reverting a value while its earlier save is pending. Those failure cases were reproduced before their fixes.
The metadata regression observes the route's actual database read instead of relying on a timer. Restoring the old stale-metadata validation makes it fail with 200 instead of 400. A separate regression pins serialization of legacy prototype-key rename deletions.
Local CodeRabbit's full review returned five findings: four fixed (fresh metadata validation, redundant spreading, character-reference name collisions, and character-scoped preset deferral); the interpolation suggestion was rejected because
EXAMPLE_TAGalready supplies{{char1}}to theexampletoken correctly. The persistence, queued-edit, and final rename follow-up reviews completed with zero findings. The hosted review of9c150f2deraised three minor findings, all addressed: pristine draft validation, filtering the queued-save fixture to variable writes, and a shorter changelog. Supplemental local review of all four follow-up files completed with zero findings. Hosted review completed ondfbdad7a5with no new findings, and all required checks passed before merge.The full local Node run passed 419/420 files. The sole local failure is the unchanged Linux-specific
decision-sidecar-runtimecase on macOS; that case passed in Linux CI. The CI failure inopen-issueswas a stale source-pattern assertion: it now directly checks the bounded merge behavior and verifies the route uses it. The corrected file passes locally, and full Linux CI ondfbdad7a5passed all 420/420 regression files.pnpm checkpasses locallyContainer (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.mdManual verification notes
The automated browser runs and screenshots use isolated synthetic data. Real-provider generation and physical-device testing are not claimed by this integration pass. The contributor's existing checklist marks are preserved above.
Still to confirm in a real browser, per mode:
char1=Mary. Reopen the drawer; the value persists.{{char1}} walks in.The bubble shows the raw tag by design; Peek Prompt shows "Mary walks in."{{char1}}— still resolves.Anna, then swipe the last reply. Peek Prompt shows "Anna" for both turns, proving resolution happens at prompt-build time.{{char1}}stays literal in Peek Prompt.{{setvar::mood::tense}}in a lorebook entry, generate, reopen the drawer —moodappears as an editable row.char(refused as reserved) andmy.var(refused on format).char1, the preset value wins in Peek Prompt.Container validation is supplied by the required GitHub container check; live-provider and human manual verification remain separate from the automated evidence above.
Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)docs/prompts/macros.md,docs/prompts/preset-variables.mdanddocs/chats/chat-settings.mdare updated here, along with aCHANGELOG.md[Unreleased]entry. No version bump. Translation follow-up: #6792 covers those three paths.UI evidence (if applicable)
Before/after screenshots in dark and light themes, desktop Chromium and iPhone-sized WebKit. Download the self-contained HTML gallery from the gist to view its embedded original PNG captures. All screenshots use disposable synthetic data; browser emulation is not a physical-device test.
Summary by CodeRabbit
{{setvar}}, which can overwrite a matching name. Preset variables take precedence over chat variables, including in conditionals. Unmatched tags remain unchanged; built-in macro names are reserved, and each chat supports up to 500 variables.{{setvar}}storage.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.