[GH-ISSUE #3448] [Feature]: Support relocation macros ({{memories}}, {{lorebook}}, {{commands}}, ...) in {{#if}} conditions #1863

Closed
opened 2026-10-21 05:43:21 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3448

What problem does this solve?

The Conversation-mode relocation macros — {{context}}/{{status}}, {{commands}}, {{reactRules}}, {{memories}}, {{lorebook}} — cannot be tested inside {{#if}} conditions. A preset like:

{{#if memories != ""}}
## Memories
{{memories}}
{{/if}}

always renders the block, even when there are no memories, so the ## Memories header shows with nothing under it.

Why: relocation macros are not resolved by the shared macro engine at all — their content is injected by the route (replaceConversationContextMacro) after resolveMacros has already processed the {{#if}}. At condition-evaluation time the operand resolves to the literal token string ("memories"), so "memories" != "" is trivially true. This is unlike every value macro ({{char_about}}, {{date}}, {{agent::TYPE}}, …), which the engine can resolve. (Filed as the follow-up to the {{#if}} macro-resolution fixes in #3435.)

Users building modular Conversation presets want conditional headers/wrappers around these blocks, and want {{#if}} to behave consistently across all macros.

Proposed solution

Add a generic, opt-in deferral hook to the shared macro engine so a caller can mark certain {{#if}} operands as "resolved later," reusing the exact mechanism the engine already uses to defer per-character macros in group chats:

  • resolveMacros gains an optional deferConditionalOperand?: (operand: string) => boolean. When a {{#if}} condition depends on such an operand, the engine encodes the block as a deferred token (leaving inner macros raw) instead of evaluating it. The engine stays mode-agnostic — it never hardcodes conversation macro names.
  • The conversation route supplies the predicate (the relocation-macro aliases), and after all relocation content is known (right after the memory step) runs a decode pass that evaluates each deferred conditional against the real values and substitutes the inner relocation macros.

This makes {{#if memories != ""}}, {{#if lorebook contains "x"}}, etc. work with the full operator set, consistent with all other macros. Conditions that mix a character macro and a relocation macro in the same comparison are out of scope (documented).

Also required: the slot detector must recognize a relocation alias used only as an {{#if}} operand (a header-only block with no bare {{memories}}), so retrieval still runs.

Alternatives considered

  • Route-only presence block (a dedicated {{#if:memories}}…{{/if:memories}} the route strips/keeps): ~40 LOC, near-zero risk, but non-empty only (no operators) and a second conditional syntax to learn — re-introduces the inconsistency this report is about.
  • Document the limitation and rely on the blocks self-suppressing when empty: doesn't cover conditional headers/wrappers.

Additional context

Follow-up to #3435 ({{#if}} macro resolution) and the docs in #3437. The engine already has a proven per-character deferral pattern (deferCharacterMacros → encodeDeferredConditional → decode) to mirror. Implementation is planned as a single focused PR (engine hook + route decode + slot-detection fix + tests), with the dry-run debug preview mirrored so it matches.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 10, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3448 ## What problem does this solve? The Conversation-mode **relocation macros** — `{{context}}`/`{{status}}`, `{{commands}}`, `{{reactRules}}`, `{{memories}}`, `{{lorebook}}` — cannot be tested inside `{{#if}}` conditions. A preset like: ``` {{#if memories != ""}} ## Memories {{memories}} {{/if}} ``` **always renders the block**, even when there are no memories, so the `## Memories` header shows with nothing under it. **Why:** relocation macros are not resolved by the shared macro engine at all — their content is injected by the route (`replaceConversationContextMacro`) *after* `resolveMacros` has already processed the `{{#if}}`. At condition-evaluation time the operand resolves to the literal token string (`"memories"`), so `"memories" != ""` is trivially true. This is unlike every value macro (`{{char_about}}`, `{{date}}`, `{{agent::TYPE}}`, …), which the engine can resolve. (Filed as the follow-up to the `{{#if}}` macro-resolution fixes in #3435.) Users building modular Conversation presets want conditional headers/wrappers around these blocks, and want `{{#if}}` to behave consistently across all macros. ## Proposed solution Add a **generic, opt-in deferral hook** to the shared macro engine so a caller can mark certain `{{#if}}` operands as "resolved later," reusing the exact mechanism the engine already uses to defer per-character macros in group chats: - `resolveMacros` gains an optional `deferConditionalOperand?: (operand: string) => boolean`. When a `{{#if}}` condition depends on such an operand, the engine encodes the block as a deferred token (leaving inner macros raw) instead of evaluating it. The engine stays mode-agnostic — it never hardcodes conversation macro names. - The conversation route supplies the predicate (the relocation-macro aliases), and after all relocation content is known (right after the memory step) runs a decode pass that evaluates each deferred conditional against the real values and substitutes the inner relocation macros. This makes `{{#if memories != ""}}`, `{{#if lorebook contains "x"}}`, etc. work with the full operator set, consistent with all other macros. Conditions that mix a *character* macro and a *relocation* macro in the same comparison are out of scope (documented). Also required: the slot detector must recognize a relocation alias used only as an `{{#if}}` operand (a header-only block with no bare `{{memories}}`), so retrieval still runs. ## Alternatives considered - **Route-only presence block** (a dedicated `{{#if:memories}}…{{/if:memories}}` the route strips/keeps): ~40 LOC, near-zero risk, but non-empty only (no operators) and a second conditional syntax to learn — re-introduces the inconsistency this report is about. - **Document the limitation** and rely on the blocks self-suppressing when empty: doesn't cover conditional headers/wrappers. ## Additional context Follow-up to #3435 (`{{#if}}` macro resolution) and the docs in #3437. The engine already has a proven per-character deferral pattern (`deferCharacterMacros` → `encodeDeferredConditional` → decode) to mirror. Implementation is planned as a single focused PR (engine hook + route decode + slot-detection fix + tests), with the dry-run debug preview mirrored so it matches. ## Template check - [ ] I DID NOT read this template and provide the requested details.
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#1863
No description provided.