mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #3440] [MERGED] fix(macros): resolve flat-pass macros in {{#if}} conditions + trim standalone blocks #5936
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#5936
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/3440
Author: @kolacheee
Created: 7/10/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/3435-convo-macros-in-if📝 Commits (2)
666cba8fix(macros): resolve conversation macros in {{#if}} and trim standalone blocksded115efix(macros): resolve any flat-pass macro in bare {{#if}} conditions📊 Changes
1 file changed (+56 additions, -6 deletions)
View changed files
📝
packages/shared/src/utils/macro-engine.ts(+56 -6)📄 Description
Linked issue
Closes #3435
Why this change
Two problems with the new (and old) preset macros inside
{{#if}}blocks:(functional)
{{#if MACRO != ""}}was always true for a whole class of macros. The{{#if}}condition evaluator resolved bare operands from a hand-maintained switch inresolveConditionalOperand, and any macro not listed fell through to the literal-token fallback ("MACRO" != ""→ always true). That switch had drifted out of sync with the flat{{...}}pass. The reported case was the conversation macros ({{char_about}},{{persona_about}},{{convo_display}},{{convo_behavior}}), but an audit found the same bug for{{date}}/{{time}}/{{weekday}}/{{timezone}}/{{datetime}},{{lastGenerationType}},{{idle_duration}},{{agent::TYPE}},{{random}}/{{roll}}, and{{getvar::name}}— all broken in bare form (they worked only in the braced{{ {{macro}} }}form).(cosmetic) A standalone
{{#if}}block left an extra blank line — whether removed or rendered.What changed
packages/shared/src/utils/macro-engine.ts:resolveConditionalOperandnow routes any unresolved bare operand through the same flat pass used for{{token}}. So every read macro valid in{{...}}is automatically testable bare in{{#if}}, and it stays in sync forever. Guards:setvar/addvar/incvar/decvar) as an operand side-effect;deferCharacterMacrosoff) so a group chat compares the real value, not a deferred per-character placeholder.{{#if}}/{{/if}}tags get Jinja-styletrim_blocks/lstrip_blocks, judged from the raw layout, so a removed or rendered block no longer leaves a blank line. Inline tags andelsebranches are left as authored. Pre-tag text is resolved before the condition, preserving{{setvar}}-before-condition ordering.Out of scope (handled separately): the relocation macros (
{{memories}},{{lorebook}},{{commands}},{{context}},{{reactRules}}) still can't be{{#if}}-tested here — their value is injected by the route after macro resolution, so there's nothing to compare at this layer. That needs route-level handling and is being done in a follow-up.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Automated checks I ran locally (green):
pnpm --filter @marinara-engine/shared build(tsc) and… lint— cleanpnpm regression:prompt— full prompt/macro regression suite passes{{#if char_about != ""}}/persona_about/convo_behavior,{{#if lastGenerationType == "regenerate"}},{{#if idle_duration != ""}},{{#if agent::tracker != ""}},{{#if date != ""}}all test the real value now{{#if setvar::x::1}}does not execute the write; set variables resolve;{{#if var:mood == "happy"}}and{{#if char == "Kat"}}unchanged; braced form still worksStill to verify manually in the app (please tick above once done):
{{#if char_about != ""}}and generate with an empty vs. non-empty about-me — confirm hide vs. render and no blank-line gaps.{{#if lastGenerationType == "regenerate"}}/{{#if {{weekday}} == "Monday"}}behave as expected.Docs and release impact
Macro-reference docs (including which macros are
{{#if}}-testable) are tracked in #3437; 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.