mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #3449] [MERGED] feat(macros): support relocation macros in {{#if}} conditions (route-level deferral) #5943
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#5943
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/3449
Author: @kolacheee
Created: 7/10/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @SpicyMarinara
Base:
staging← Head:feat/3448-relocation-if-conditions📝 Commits (5)
552b631feat(macros): support relocation macros in {{#if}} via route-level deferral45ed2f7Merge remote-tracking branch 'origin/staging' into HEADb0b5532Support reply rules in deferred relocation conditions5fc4eb1Merge remote-tracking branch 'origin/staging' into HEAD7cbd51fKeep About Me fields out of relocation deferral📊 Changes
3 files changed (+274 additions, -33 deletions)
View changed files
📝
packages/server/src/routes/generate.routes.ts(+138 -10)📝
packages/shared/src/utils/macro-engine.ts(+97 -19)📝
scripts/regressions/prompt.regression.ts(+39 -4)📄 Description
Linked issue
Closes #3448
Why this change
The conversation relocation macros —
{{context}}/{{status}},{{commands}},{{reactRules}},{{memories}},{{lorebook}}— could not be tested in{{#if}}. Their value is injected by the route (replaceConversationContextMacro) after the macro engine runs, so at condition-evaluation time there's nothing to compare and{{#if memories != ""}}was always true. A preset like:always rendered the
## Memoriesheader, even with no memories. (Follow-up to #3435, which fixed the value macros.)What changed
A generic, opt-in deferral hook that reuses the engine's proven per-character-deferral mechanism.
packages/shared/src/utils/macro-engine.ts:ResolveMacroOptions.deferConditionalOperand?: (operand) => boolean. When a{{#if}}condition references such an operand, the block is encoded as a deferred token (distinctDEFERRED_RELOCATION_...prefix so it never collides with the character-macro decode) with the standalone-block whitespace trim baked into the stored branches, instead of being evaluated. The engine stays mode-agnostic — it never hardcodes relocation names.selectConditionalPayloadBranch,parseDeferredConditionalPayload,DEFERRED_RELOCATION_CONDITIONAL_TOKEN_RE, and ahasDeferredRelocationConditionalsguard for the route decode.packages/server/src/routes/generate.routes.ts:{{#if}}operand (a header-only block with no bare{{memories}}), so retrieval still runs.decodeDeferredRelocationConditionalsevaluates each token against the real values — seeded as variables under every alias spelling so bare and braced operands both resolve — and substitutes the inner relocation macros. Nested relocation conditionals inside a deferred block resolve too.Scope / known limitations
{{#if memories contains char}}) is unsupported — character deferral takes precedence. In Conversation mode character deferral is off, so this doesn't arise there.{{#if MEMORIES}}) stays always-true (no regression) rather than resolving.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Automated checks I ran locally (green):
pnpm --filter @marinara-engine/server lintandpnpm --filter @marinara-engine/shared lint(tsc) — cleanpnpm regression:prompt— full prompt/macro regression suite passes{{#if memories != ""}}…{{memories}}{{/if}}renders flush when content exists, is hidden (no blank line) when empty{{#if {{lorebook}} != ""}}, operators (contains), aliases ({{memoryRecall}}), inner{{char}}, and nested relocation conditionals all resolve{{#if char == "Kat"}}) are NOT deferred; a quoted literal that looks like a macro name does not deferStill to verify manually in the app (please tick above once done):
{{#if memories != ""}}## Memories\n{{memories}}{{/if}}→ confirm the header appears only when memories exist, with clean spacing.{{#if lorebook != ""}}/{{#if commands != ""}}/{{#if reactRules != ""}}/{{#if context != ""}}.{{#if memories}}…{{/if}}with no bare{{memories}}) still shows memories when present (retrieval triggered).{{#if commands}}is empty (commands are suppressed when impersonating).Docs and release impact
The macro reference (#3437/#3446) can gain a note that relocation macros are now
{{#if}}-testable; no version bump here.UI evidence (if applicable)
N/A (prompt-assembly logic; no UI surface changed).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.