[PR #683] [MERGED] Add weighted random macro choices #4729

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

📋 Pull Request Information

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

Base: main ← Head: feature/weighted-random-macros


📝 Commits (1)

  • a4a5056 Add weighted random macros

📊 Changes

5 files changed (+187 additions, -2 deletions)

View changed files

📝 README.md (+1 -0)
📝 docs/FRONTEND.md (+1 -1)
➕ docs/MACROS.md (+79 -0)
📝 packages/server/test/macro-engine.test.ts (+42 -0)
📝 packages/shared/src/utils/macro-engine.ts (+64 -1)

📄 Description

Linked issue

No linked GitHub issue. This came from a community feature request / compatibility discussion outside GitHub; maintainers may want a follow-up issue if project-board tracking is required.

Why this change

  • Prompt and card authors need a way to make some {{random::...}} choices more or less likely without duplicating entries.
  • Weighted choices improve SillyTavern-style random macro parity while keeping existing unweighted {{random::A::B::C}} behavior intact.

What changed

  • Added weighted random choice parsing for final top-level @number suffixes, including decimal weights like @0.5.
  • Kept missing weights as 1, so unweighted choices still have equal probability.
  • Preserved nested macro behavior by resolving only the selected random branch.
  • Added focused macro-engine tests for unweighted compatibility, decimal weights, zero weights, all-zero output, nested macros, and invalid suffix literals.
  • Added user-facing macro documentation in docs/MACROS.md and linked it from README/docs references.

Validation

AI-run local validation for reviewer context; checklist items below are intentionally left unchecked for human verification per repo guidance.

Commands run locally:

  • git diff --check
  • pnpm --filter @marinara-engine/shared build
  • pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/macro-engine.test.ts
  • pnpm check

Results:

  • Focused macro-engine tests passed: 9 tests passing.

  • pnpm check passed with the existing unrelated AvatarCropWidget.tsx unused eslint-disable warning.

  • git diff --check reported no whitespace errors; only normal LF-to-CRLF working-copy warnings.

  • 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

  • Macro-engine tests cover the behavior directly: unweighted choices, weighted decimal choices, zero-weight handling, all-zero choices, nested macro resolution, and invalid weight suffixes.
  • Branch was synced to C:\Users\Melis\AppData\Local\MarinaraEngineTEST for manual app testing.
  • Human browser/app verification is still pending.

Docs and release impact

Docs changed:

  • docs/MACROS.md
  • README.md
  • docs/FRONTEND.md

No version or release metadata changed.

  • 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 macro-engine behavior and documentation, with no UI surface change.


🔄 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/683 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `feature/weighted-random-macros` --- ### 📝 Commits (1) - [`a4a5056`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a4a50568f443dcdb0168d78ce2e62c8777c0872c) Add weighted random macros ### 📊 Changes **5 files changed** (+187 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -0) 📝 `docs/FRONTEND.md` (+1 -1) ➕ `docs/MACROS.md` (+79 -0) 📝 `packages/server/test/macro-engine.test.ts` (+42 -0) 📝 `packages/shared/src/utils/macro-engine.ts` (+64 -1) </details> ### 📄 Description ## Linked issue No linked GitHub issue. This came from a community feature request / compatibility discussion outside GitHub; maintainers may want a follow-up issue if project-board tracking is required. ## Why this change - Prompt and card authors need a way to make some `{{random::...}}` choices more or less likely without duplicating entries. - Weighted choices improve SillyTavern-style random macro parity while keeping existing unweighted `{{random::A::B::C}}` behavior intact. ## What changed - Added weighted random choice parsing for final top-level `@number` suffixes, including decimal weights like `@0.5`. - Kept missing weights as `1`, so unweighted choices still have equal probability. - Preserved nested macro behavior by resolving only the selected random branch. - Added focused macro-engine tests for unweighted compatibility, decimal weights, zero weights, all-zero output, nested macros, and invalid suffix literals. - Added user-facing macro documentation in `docs/MACROS.md` and linked it from README/docs references. ## Validation AI-run local validation for reviewer context; checklist items below are intentionally left unchecked for human verification per repo guidance. Commands run locally: - `git diff --check` - `pnpm --filter @marinara-engine/shared build` - `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/macro-engine.test.ts` - `pnpm check` Results: - Focused macro-engine tests passed: 9 tests passing. - `pnpm check` passed with the existing unrelated `AvatarCropWidget.tsx` unused eslint-disable warning. - `git diff --check` reported no whitespace errors; only normal LF-to-CRLF working-copy warnings. - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] 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 - Macro-engine tests cover the behavior directly: unweighted choices, weighted decimal choices, zero-weight handling, all-zero choices, nested macro resolution, and invalid weight suffixes. - Branch was synced to `C:\Users\Melis\AppData\Local\MarinaraEngineTEST` for manual app testing. - Human browser/app verification is still pending. ## Docs and release impact Docs changed: - `docs/MACROS.md` - `README.md` - `docs/FRONTEND.md` No version or release metadata changed. - [ ] No docs changes needed - [x] 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 macro-engine behavior and documentation, with no UI surface change. --- <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:10 +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#4729
No description provided.