[PR #930] [MERGED] Fix character macro scoping in group replies #4843

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

📋 Pull Request Information

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

Base: staging ← Head: fix/924-character-macro-scoping


📝 Commits (5)

  • 467751e fix: scope character macros per group responder (#924)
  • b3de601 Merge branch 'staging' into fix/924-character-macro-scoping
  • d35e14c fix: guard deferred character macro finalization
  • 36b79de Fix manual group regen character macro target
  • 37fea16 Merge branch 'staging' into fix/924-character-macro-scoping

📊 Changes

6 files changed (+739 additions, -31 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+63 -7)
📝 packages/server/src/services/prompt/assembler.ts (+20 -5)
📝 packages/server/src/services/prompt/marker-expander.ts (+27 -2)
➕ packages/server/test/character-macro-scoping.test.ts (+498 -0)
📝 packages/server/test/macro-engine.test.ts (+46 -1)
📝 packages/shared/src/utils/macro-engine.ts (+85 -16)

📄 Description



Linked issue

Closes #924

Why this change

  • Individual-mode group prompts are assembled before Marinara prepares the separate model request for each responding character.
  • Because {{char}} was resolved during that earlier assembly step, prompt text that should follow the current responding character could be filled with the first character's name instead.
  • This introduces an optional prompt macro path that runs separately for each responding character, so text that depends on the speaking character can be filled while Marinara is preparing that character's model request. Marker content that comes from a character card is filled from that same card.

What changed

  • Added an optional deferred mode to prompt macro resolution.
    • deferCharacterMacros: "all" is used for preset section text and preset variable values such as the Character's POV option. It keeps {{char}}, {{charName}}, and character field macros unresolved until Marinara prepares the responding character's model request.
    • deferCharacterMacros: "names" is used for lorebook entries that are included in the prompt. It keeps only {{char}} and {{charName}} unresolved; all other character macros keep their existing behavior.
  • Enabled that path for multi-character individual-mode group replies, including regenerating one character's saved reply.
  • Replaced preserved character macros with the responding character's name and card fields while preparing that character's model request.
    • The send path copies messages before finalizing macros, so the prompt copy used for later group responders is not rewritten.
  • Added a send-time check that stops generation if an internal deferred character placeholder would remain in the provider request.
  • Resolved nested {{char}} usage inside each character's own marker fields and dialogue examples when expanding multi-character marker output.
  • Added focused regression coverage for the shared macro functions and for route-level model requests in a two-character individual-mode group chat, covering a non-first character's initial turn and regeneration.

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

  1. Created a two-character individual-mode roleplay group chat.
  2. Set Narration Style to Second Person and Narrative Perspective to Character's.
  3. Generated group replies and inspected the prompts with Peek Prompt.
  4. Confirmed Person A's prompt used Person A in the Character's POV instruction.
  5. Confirmed Person B's prompt used Person B in the Character's POV instruction.

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)

No UI changes.

Summary by CodeRabbit

  • New Features

    • Implemented character-scoped macro resolution for multi-character group conversations, ensuring character variables and profile attributes resolve correctly to each responder.
  • Improvements

    • Enhanced macro resolution to support deferred character macro processing during prompt assembly for better handling of character-specific information in group chat scenarios.
  • Tests

    • Added test coverage for character macro scoping in group conversations and character macro finalization workflows.

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/930 **Author:** [@NeoKazuya](https://github.com/NeoKazuya) **Created:** 5/17/2026 **Status:** ✅ Merged **Merged:** 5/17/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/924-character-macro-scoping` --- ### 📝 Commits (5) - [`467751e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/467751e17da4514633670ff6e568e60b0b7f7b35) fix: scope character macros per group responder (#924) - [`b3de601`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b3de60197e7378c7e4a50f8e8cdb8fdc19c2cdab) Merge branch 'staging' into fix/924-character-macro-scoping - [`d35e14c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d35e14cbe4f831e29ef4ff4b84a41f1eff6c2d4c) fix: guard deferred character macro finalization - [`36b79de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/36b79de41e77976a7d5e13ccbe015294422f658d) Fix manual group regen character macro target - [`37fea16`](https://github.com/Pasta-Devs/Marinara-Engine/commit/37fea1662a4f383af4c178d52456d22da449ba45) Merge branch 'staging' into fix/924-character-macro-scoping ### 📊 Changes **6 files changed** (+739 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+63 -7) 📝 `packages/server/src/services/prompt/assembler.ts` (+20 -5) 📝 `packages/server/src/services/prompt/marker-expander.ts` (+27 -2) ➕ `packages/server/test/character-macro-scoping.test.ts` (+498 -0) 📝 `packages/server/test/macro-engine.test.ts` (+46 -1) 📝 `packages/shared/src/utils/macro-engine.ts` (+85 -16) </details> ### 📄 Description <!-- Target branch: `staging`. The default base in this UI is `main` (release branch). --> <!-- Change the base to `staging` before submitting unless this is a maintainer-approved mainline change. --> <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #924 ## Why this change - Individual-mode group prompts are assembled before Marinara prepares the separate model request for each responding character. - Because `{{char}}` was resolved during that earlier assembly step, prompt text that should follow the current responding character could be filled with the first character's name instead. - This introduces an optional prompt macro path that runs separately for each responding character, so text that depends on the speaking character can be filled while Marinara is preparing that character's model request. Marker content that comes from a character card is filled from that same card. ## What changed - Added an optional deferred mode to prompt macro resolution. - `deferCharacterMacros: "all"` is used for preset section text and preset variable values such as the Character's POV option. It keeps `{{char}}`, `{{charName}}`, and character field macros unresolved until Marinara prepares the responding character's model request. - `deferCharacterMacros: "names"` is used for lorebook entries that are included in the prompt. It keeps only `{{char}}` and `{{charName}}` unresolved; all other character macros keep their existing behavior. - Enabled that path for multi-character individual-mode group replies, including regenerating one character's saved reply. - Replaced preserved character macros with the responding character's name and card fields while preparing that character's model request. - The send path copies messages before finalizing macros, so the prompt copy used for later group responders is not rewritten. - Added a send-time check that stops generation if an internal deferred character placeholder would remain in the provider request. - Resolved nested `{{char}}` usage inside each character's own marker fields and dialogue examples when expanding multi-character marker output. - Added focused regression coverage for the shared macro functions and for route-level model requests in a two-character individual-mode group chat, covering a non-first character's initial turn and regeneration. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] 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 1. Created a two-character individual-mode roleplay group chat. 2. Set Narration Style to `Second Person` and Narrative Perspective to `Character's`. 3. Generated group replies and inspected the prompts with Peek Prompt. 4. Confirmed Person A's prompt used Person A in the Character's POV instruction. 5. Confirmed Person B's prompt used Person B in the Character's POV instruction. ## 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) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Implemented character-scoped macro resolution for multi-character group conversations, ensuring character variables and profile attributes resolve correctly to each responder. * **Improvements** * Enhanced macro resolution to support deferred character macro processing during prompt assembly for better handling of character-specific information in group chat scenarios. * **Tests** * Added test coverage for character macro scoping in group conversations and character macro finalization workflows. <!-- review_stack_entry_start --> [![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/930?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- 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:11:06 +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#4843
No description provided.