[PR #6957] [MERGED] feat(macros): character ID names for chat members, an include macro, and until/while decisions #7402

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6957
Author: @SpicyMarinara
Created: 10/1/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/macro-sweep


📝 Commits (7)

  • 370d124 fix(macros): resolve character ID macros for chat members
  • ea68da5 feat(macros): add an include macro for lorebook entries
  • 1627c7f feat(decisions): add until and while to decision blocks
  • 0fb24a2 Merge remote-tracking branch 'origin/staging' into fix/macro-sweep
  • 60e0ee6 Merge remote-tracking branch 'origin/staging' into fix/macro-sweep
  • 9c55194 Merge remote-tracking branch 'origin/staging' into fix/macro-sweep
  • f1ea4d3 chore(lorebook): note when the include source is loaded

📊 Changes

16 files changed (+1078 additions, -29 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 docs/lorebooks/entries.md (+1 -0)
📝 docs/prompts/conditional-prompts.md (+34 -0)
📝 docs/prompts/macros.md (+21 -2)
📝 packages/server/src/routes/chats.routes.ts (+4 -1)
📝 packages/server/src/routes/generate.routes.ts (+4 -1)
📝 packages/server/src/routes/generate/dry-run-route.ts (+4 -1)
📝 packages/server/src/services/decision/decision-timers.ts (+64 -7)
📝 packages/server/src/services/decision/prompt-decisions.ts (+34 -2)
📝 packages/server/src/services/lorebook/index.ts (+62 -1)
📝 packages/server/src/services/prompt/assembler.ts (+5 -2)
📝 packages/server/src/services/prompt/macro-context.ts (+29 -9)
📝 packages/shared/src/utils/macro-engine.ts (+133 -3)
➕ scripts/regressions/active-character-reference.regression.ts (+124 -0)
➕ scripts/regressions/decision-until-while.regression.ts (+274 -0)
➕ scripts/regressions/lorebook-include-macro.regression.ts (+281 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6924
Closes #6912
Closes #6922

One commit per issue.

Why this change

  • #6924: {{<character ID>}} stayed as raw text when that character was already in the chat. The docs say it becomes the character's name.
  • #6912: There was no way to reuse a lorebook entry's text somewhere else without copying it.
  • #6922: Decision blocks could only stay on for a fixed number of turns (sticky). You couldn't say "stay on until the fight ends".

What changed

Character ID macros (#6924)

  • Characters already in the chat now get their name. Their card isn't added a second time, and they no longer use up the 8 slots for cards pulled in from outside the chat.
  • Code: macro-context.ts and assembler.ts.

{{include::ENTRY}} and {{include::BOOK::ENTRY}} (#6912)

  • These put a lorebook entry's text where the macro is. They look up an ID first, then a name, ignoring case.
  • Inside an entry, the short form looks in that entry's own lorebook. Elsewhere it looks in the chat's lorebooks. The long form can read any lorebook, even one the chat doesn't use.
  • Included text can include more. An entry that loops back to itself reads as empty, so it can't run forever, and a missing entry also reads as empty.
  • It runs before the other macros, so included text gets the normal macro pass.
  • Lorebooks are only loaded when some text actually uses the macro.
  • It's listed in the in-app macro reference and in /macros.

until and while for decision blocks (#6922)

  • {{#if decision:"A fight starts" until:"The fight ends"}} stays on after a yes until the second question gets a yes. while:"…" stays on while its question keeps getting a yes.
  • With sticky:N, a :and/:restrict or :or/:extend suffix picks whether the condition cuts the time short or extends it. The defaults follow the issue's tables.
  • cooldown:N applies after the block turns off.
  • The condition is asked as an ordinary decision statement, so there's no new model call and the existing per-turn limit applies. If the condition gets no answer, the block stays on and its timers don't move.
  • The old parser folded until:"…" into the question itself; that's fixed too.

Docs and changelog

  • Docs: docs/prompts/macros.md, docs/prompts/conditional-prompts.md (a new "Until and while" section) and docs/lorebooks/entries.md.
  • CHANGELOG: one entry per issue.

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

What I ran (not a replacement for the checklist):

  • Checks: pnpm check and pnpm regression:prompt pass.
  • Three new regressions, each failing without its fix:
    • active-character-reference: the name map was empty before the fix.
    • lorebook-include-macro: covers the macro rules, the lorebook scan, preset sections, chat messages, and a real generate turn with an author's note.
    • decision-until-while: covers every row of the issue's tables, cooldown, a missing answer, and a real 4-turn chat.
  • Full Node suite: 483/484 pass. The one failure, decision-sidecar-runtime, also fails on untouched staging on this machine (a local-model disk check).
  • After merging the latest staging: I re-ran pnpm check, the new regressions and pnpm regression:prompt.
  • Local CodeRabbit: 2 trivial findings, neither changed.
    • It asked the new regression to import shared from src instead of dist. Other regressions, like #6950's, use dist too, and the runner builds shared first.
    • It asked to cache the include source across lorebook scans. That load only happens when an entry actually uses {{include::}}, so it's marked with a ponytail: note instead.

To check by hand:

  • Put a chat member's ID in a lorebook entry as {{ID}} and check Peek Prompt shows their name.
  • Make an entry that uses {{include::Some Entry}}, plus one that includes itself, and check Peek Prompt.
  • Try {{#if decision:"A fight starts" until:"The fight ends"}}…{{/if}} over a few turns with a Decision model set up.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

The three docs pages above changed. Their translations go into the one docs-i18n PR for this sweep.

UI evidence (if applicable)

No layout changes; the macro reference just gains three entries.

Summary by CodeRabbit

  • New Features
    • Decision blocks can now use until and while conditions, with sticky behavior and cooldown timing.
    • Added lorebook include macros to insert entries by name or ID, including inactive entries and nested content.
    • Character ID macros now show the character’s name when they’re already in the chat, without adding their card again.
  • Documentation
    • Added guidance for decision lifetimes and lorebook include macros.

🔄 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/6957 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/1/2026 **Status:** ✅ Merged **Merged:** 10/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/macro-sweep` --- ### 📝 Commits (7) - [`370d124`](https://github.com/Pasta-Devs/Marinara-Engine/commit/370d124aa4863d6ec1f61f2c9893cc3bac94cb73) fix(macros): resolve character ID macros for chat members - [`ea68da5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ea68da56bb684cb7a951f571c8bb11ab06a2ed8a) feat(macros): add an include macro for lorebook entries - [`1627c7f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1627c7ffe23cfc37db1951ae712510ec8ae7d5e8) feat(decisions): add until and while to decision blocks - [`0fb24a2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0fb24a2061f0d63ae38ef5647be08d74f53e5cc8) Merge remote-tracking branch 'origin/staging' into fix/macro-sweep - [`60e0ee6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60e0ee69d9425a848b50156f40f2387c066ba91c) Merge remote-tracking branch 'origin/staging' into fix/macro-sweep - [`9c55194`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9c5519460700d5302a3bc1e175dc11e22173f4c3) Merge remote-tracking branch 'origin/staging' into fix/macro-sweep - [`f1ea4d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f1ea4d36caf6408ebaabafe70da6300088efc922) chore(lorebook): note when the include source is loaded ### 📊 Changes **16 files changed** (+1078 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `docs/lorebooks/entries.md` (+1 -0) 📝 `docs/prompts/conditional-prompts.md` (+34 -0) 📝 `docs/prompts/macros.md` (+21 -2) 📝 `packages/server/src/routes/chats.routes.ts` (+4 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+4 -1) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+4 -1) 📝 `packages/server/src/services/decision/decision-timers.ts` (+64 -7) 📝 `packages/server/src/services/decision/prompt-decisions.ts` (+34 -2) 📝 `packages/server/src/services/lorebook/index.ts` (+62 -1) 📝 `packages/server/src/services/prompt/assembler.ts` (+5 -2) 📝 `packages/server/src/services/prompt/macro-context.ts` (+29 -9) 📝 `packages/shared/src/utils/macro-engine.ts` (+133 -3) ➕ `scripts/regressions/active-character-reference.regression.ts` (+124 -0) ➕ `scripts/regressions/decision-until-while.regression.ts` (+274 -0) ➕ `scripts/regressions/lorebook-include-macro.regression.ts` (+281 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6924 Closes #6912 Closes #6922 One commit per issue. ## Why this change - **#6924:** `{{<character ID>}}` stayed as raw text when that character was already in the chat. The docs say it becomes the character's name. - **#6912:** There was no way to reuse a lorebook entry's text somewhere else without copying it. - **#6922:** Decision blocks could only stay on for a fixed number of turns (`sticky`). You couldn't say "stay on until the fight ends". ## What changed **Character ID macros (#6924)** - Characters already in the chat now get their name. Their card isn't added a second time, and they no longer use up the 8 slots for cards pulled in from outside the chat. - Code: `macro-context.ts` and `assembler.ts`. **`{{include::ENTRY}}` and `{{include::BOOK::ENTRY}}` (#6912)** - These put a lorebook entry's text where the macro is. They look up an ID first, then a name, ignoring case. - Inside an entry, the short form looks in that entry's own lorebook. Elsewhere it looks in the chat's lorebooks. The long form can read any lorebook, even one the chat doesn't use. - Included text can include more. An entry that loops back to itself reads as empty, so it can't run forever, and a missing entry also reads as empty. - It runs before the other macros, so included text gets the normal macro pass. - Lorebooks are only loaded when some text actually uses the macro. - It's listed in the in-app macro reference and in `/macros`. **`until` and `while` for decision blocks (#6922)** - `{{#if decision:"A fight starts" until:"The fight ends"}}` stays on after a yes until the second question gets a yes. `while:"…"` stays on while its question keeps getting a yes. - With `sticky:N`, a `:and`/`:restrict` or `:or`/`:extend` suffix picks whether the condition cuts the time short or extends it. The defaults follow the issue's tables. - `cooldown:N` applies after the block turns off. - The condition is asked as an ordinary decision statement, so there's no new model call and the existing per-turn limit applies. If the condition gets no answer, the block stays on and its timers don't move. - The old parser folded `until:"…"` into the question itself; that's fixed too. **Docs and changelog** - **Docs:** `docs/prompts/macros.md`, `docs/prompts/conditional-prompts.md` (a new "Until and while" section) and `docs/lorebooks/entries.md`. - **CHANGELOG:** one entry per issue. ## 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 What I ran (not a replacement for the checklist): - **Checks:** `pnpm check` and `pnpm regression:prompt` pass. - **Three new regressions**, each failing without its fix: - `active-character-reference`: the name map was empty before the fix. - `lorebook-include-macro`: covers the macro rules, the lorebook scan, preset sections, chat messages, and a real generate turn with an author's note. - `decision-until-while`: covers every row of the issue's tables, cooldown, a missing answer, and a real 4-turn chat. - **Full Node suite:** 483/484 pass. The one failure, `decision-sidecar-runtime`, also fails on untouched staging on this machine (a local-model disk check). - **After merging the latest staging:** I re-ran `pnpm check`, the new regressions and `pnpm regression:prompt`. - **Local CodeRabbit:** 2 trivial findings, neither changed. - It asked the new regression to import shared from `src` instead of `dist`. Other regressions, like #6950's, use `dist` too, and the runner builds shared first. - It asked to cache the include source across lorebook scans. That load only happens when an entry actually uses `{{include::}}`, so it's marked with a `ponytail:` note instead. To check by hand: - Put a chat member's ID in a lorebook entry as `{{ID}}` and check Peek Prompt shows their name. - Make an entry that uses `{{include::Some Entry}}`, plus one that includes itself, and check Peek Prompt. - Try `{{#if decision:"A fight starts" until:"The fight ends"}}…{{/if}}` over a few turns with a Decision model set up. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) The three docs pages above changed. Their translations go into the one `docs-i18n` PR for this sweep. ## UI evidence (if applicable) No layout changes; the macro reference just gains three entries. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Decision blocks can now use `until` and `while` conditions, with sticky behavior and cooldown timing. * Added lorebook include macros to insert entries by name or ID, including inactive entries and nested content. * Character ID macros now show the character’s name when they’re already in the chat, without adding their card again. * **Documentation** * Added guidance for decision lifetimes and lorebook include macros. <!-- 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-23 04:19:26 +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#7402
No description provided.