mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6734] [Feature]: Per-chat variables you can type in your own messages #3775
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#3775
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?
Originally created by @kentarofujiy on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6734
Originally assigned to: @SpicyMarinara on GitHub.
What problem does this solve?
There is no way to give a name to a piece of text and reuse it in your own messages. If you want to type
{{char1}}and have the model read "Mary", nothing in the app supports it:{{setvar::char1::Mary}}and{{getvar::char1}}typed into a message both resolve to an empty string. The client resolves macros before the message is stored, using a context built from persona and characters only (createInputMacroResolverForChatinpackages/client/src/lib/chat-macros.ts), so the stored text is already blank and the server never sees the macro.docs/prompts/macros.mdsays variables "persist in the current chat", which is true for prompt fields but not for anything you type.generate.routes.tsbefore preset values are merged into the macro context, so a preset variable namedchar1leaves the literal{{char1}}in the prompt.macroVariablesin its metadata, written by{{setvar}}from prompt sections and lorebook entries, but nothing in the UI shows or edits them. They are invisible state.The only thing that works today is a regex script with Apply To: User Input and Apply Mode: Only Prompt. That does the job, but it is an obscure route for what reads like a basic feature, it lives in a global or character-scoped script list rather than with the chat, and the two settings that make it work are easy to get wrong.
Proposed solution
A Chat Variables section in the Chat Settings drawer: rows of name and value, saved per chat.
Type
{{char1}}in any message and the model reads the value. The message bubble keeps showing the tag you typed, because resolution happens when the prompt is built — which also means changing a value later changes the earlier turns that used it.Mechanically: the
{{NAME}}catch-all in the shared macro engine falls back to the chat'slocalVariablesafter the preset variables, so 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.It reuses the existing
chatMetadata.macroVariablesstore rather than adding one, so the section doubles as a viewer and editor for variables a prompt or lorebook set.Naming rules: letters, numbers and underscores, starting with a letter or underscore, and not a built-in macro name. A built-in always resolves first, so a variable called
charcould never be read; the editor refuses it instead of failing silently. Dotted or dashed names still work with{{setvar}}and{{getvar}}, just not as a bare tag.Alternatives considered
{{setvar}}and{{getvar}}survive the client and prompt assembly resolves them. This was the first design investigated. It does not give you the short{{char1}}form that started the request, it means touching four call sites across two input components, and the bubble would show the raw tag regardless — so the display question has to be answered either way. Not pursued.{{setvar}}during assembly, and it would have to be repeated at six independent context-build sites.{{char1}}can mean different people in different stories, and because the per-chat store already exists and already persists.Additional context
The implementation is done and committed locally on
feat/chat-variables; a PR againststagingwill follow. It ships with two new regression scripts plus additions toprompt.regression.ts, and updatesdocs/prompts/macros.md,docs/prompts/preset-variables.mdanddocs/chats/chat-settings.md.Three consequences worth agreeing on before it lands:
docs/prompts/macros.mdcurrently says any unknown{{name}}survives verbatim. After this, a name that matches a chat variable resolves instead — so decorative{{mood}}text in a chat that also definesmoodwill expand. Documented, but it is a real behavior change.{{mood}}and a variable of that name exists, it expands on the next turn. Today it stays literal. The escape hatch, if it ever bites, is a resolve option that is on for prompt paths and off for assistant history — not built up front.{{setvar}}of the same name wins, since both use one store per chat. The editor warns rather than blocking, and the value a generation writes is the one that persists.The change also fixes a pre-existing leak it would otherwise widen: the catch-all did a bare property read, so
{{toString}}resolved to"function toString() { [native code] }"in any macro-enabled field. The lookup now requires an own string property.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: