[PR #682] [MERGED] Fix nested SillyTavern random macro parsing #4726

Closed
opened 2026-10-22 04:10:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/682
Author: @Xelvanis
Created: 5/11/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @Xelvanis

Base: main ← Head: fix/sillytavern-random-macro


📝 Commits (2)

  • 4c5b089 Fix nested random macro parsing
  • 0f2186f Tighten macro random test helper

📊 Changes

2 files changed (+186 additions, -29 deletions)

View changed files

➕ packages/server/test/macro-engine.test.ts (+60 -0)
📝 packages/shared/src/utils/macro-engine.ts (+126 -29)

📄 Description

Linked issue

No linked GitHub issue yet. The original report came from a Discord "Feature request/Possible bug report" screenshot about SillyTavern random macro parity.

This should stay draft until a GitHub issue is opened/linked or a maintainer confirms the Discord report is enough context.

Why this change

  • Marinara advertises SillyTavern-style macros, but nested macros inside {{random::...}} were parsed incorrectly.
  • A random macro such as {{random::None::{{random::Alice::Bob}} appears.::The world ends.}} could leak pieces of multiple unchosen branches into the assembled prompt instead of returning exactly one selected branch.

What changed

  • Added balanced macro scanning so random and variable macros can contain nested {{...}} expressions.
  • Split {{random::...}} choices only on top-level :: separators, leaving nested macro arguments intact.
  • Resolve nested macros inside the selected random branch and inside setvar/addvar values.
  • Added regression tests for nested random, nested getvar, and setvar values containing random choices.

Validation

  • pnpm check passes locally
  • Container (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.md

Manual verification notes

  • Targeted macro test passed:
    • pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/macro-engine.test.ts
  • Baseline validation passed:
    • pnpm check
  • Manual console repro after fix returned only the selected branch:
    • Bob appears.
  • Wider server test suite was also attempted:
    • pnpm --filter @marinara-engine/server test
    • The new macro tests passed inside that run.
    • One unrelated provider test failed in openai-provider-reasoning.test.ts: custom compatible GPT-5.5 endpoints route through Responses without Chat Completions streaming extras, expecting body.max_output_tokens to equal 512 but receiving undefined. The same provider test failed when isolated.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Not applicable; this is shared prompt macro parsing logic.

Summary by CodeRabbit

  • New Features

    • Macro engine now supports nested macros — macro calls within macro options and values are properly resolved, enabling more complex template scenarios.
  • Tests

    • Added test suite for nested macro evaluation, including scenarios with random selection, variable operations, and combined macro nesting.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/682 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `main` ← **Head:** `fix/sillytavern-random-macro` --- ### 📝 Commits (2) - [`4c5b089`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4c5b0891761a1e5a44b67efde81226d721d7bf7d) Fix nested random macro parsing - [`0f2186f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0f2186fb1337a29be6323e7334f600301dbc0922) Tighten macro random test helper ### 📊 Changes **2 files changed** (+186 additions, -29 deletions) <details> <summary>View changed files</summary> ➕ `packages/server/test/macro-engine.test.ts` (+60 -0) 📝 `packages/shared/src/utils/macro-engine.ts` (+126 -29) </details> ### 📄 Description ## Linked issue No linked GitHub issue yet. The original report came from a Discord "Feature request/Possible bug report" screenshot about SillyTavern random macro parity. This should stay draft until a GitHub issue is opened/linked or a maintainer confirms the Discord report is enough context. ## Why this change - Marinara advertises SillyTavern-style macros, but nested macros inside `{{random::...}}` were parsed incorrectly. - A random macro such as `{{random::None::{{random::Alice::Bob}} appears.::The world ends.}}` could leak pieces of multiple unchosen branches into the assembled prompt instead of returning exactly one selected branch. ## What changed - Added balanced macro scanning so random and variable macros can contain nested `{{...}}` expressions. - Split `{{random::...}}` choices only on top-level `::` separators, leaving nested macro arguments intact. - Resolve nested macros inside the selected random branch and inside `setvar`/`addvar` values. - Added regression tests for nested random, nested `getvar`, and `setvar` values containing random choices. ## Validation - [x] `pnpm check` passes locally - [ ] Container (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) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Targeted macro test passed: - `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/macro-engine.test.ts` - Baseline validation passed: - `pnpm check` - Manual console repro after fix returned only the selected branch: - `Bob appears.` - Wider server test suite was also attempted: - `pnpm --filter @marinara-engine/server test` - The new macro tests passed inside that run. - One unrelated provider test failed in `openai-provider-reasoning.test.ts`: `custom compatible GPT-5.5 endpoints route through Responses without Chat Completions streaming extras`, expecting `body.max_output_tokens` to equal `512` but receiving `undefined`. The same provider test failed when isolated. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Not applicable; this is shared prompt macro parsing logic. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Macro engine now supports nested macros — macro calls within macro options and values are properly resolved, enabling more complex template scenarios. * **Tests** * Added test suite for nested macro evaluation, including scenarios with random selection, variable operations, and combined macro nesting. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/682) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:09 +07:00
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#4726
No description provided.