[PR #7705] [MERGED] feat(macros): add {{reasoning}} for the request's reasoning level #7891

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7705
Author: @ylli-selmani
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/model-reasoning-macros-hgo3l3


📝 Commits (3)

  • aa653b5 feat(macros): add {{reasoning}} for the request's reasoning level
  • b2a3371 fix(macros): let a variable own {{reasoning}} in any spelling
  • 6456383 fix(macros): match {{reasoning}} previews to their requests

📊 Changes

12 files changed (+395 additions, -4 deletions)

View changed files

📝 docs/prompts/conditional-prompts.md (+24 -2)
📝 docs/prompts/macros.md (+3 -0)
📝 packages/server/src/routes/chats.routes.ts (+23 -0)
📝 packages/server/src/routes/generate.routes.ts (+18 -1)
📝 packages/server/src/routes/generate/dry-run-route.ts (+21 -0)
📝 packages/server/src/routes/prompts.routes.ts (+14 -1)
📝 packages/server/src/services/generation/provider-generation-runtime.ts (+43 -0)
📝 packages/server/src/services/prompt/assembler.ts (+3 -0)
📝 packages/server/src/services/prompt/macro-context.ts (+2 -0)
📝 packages/shared/src/utils/macro-engine.ts (+36 -0)
➕ scripts/regressions/reasoning-macro-routes.regression.ts (+138 -0)
➕ scripts/regressions/reasoning-macro.regression.ts (+70 -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 #7704

Why this change

Before: a preset can't tell whether the model is thinking, so chain-of-thought sections have to be toggled by hand whenever the reasoning level changes.

After: {{reasoning}} resolves to the level the model is actually sent (low … max) or off, so {{#if reasoning}}…{{else}}…{{/if}} keeps a CoT section only when it's needed, and {{#if reasoning == "max"}} targets one level. {{model}} already existed; the docs now show model-specific conditionals with it ({{#if model contains "opus"}}).

What changed

  • macro-engine.ts: new reasoning context field, {{reasoning}} macro, reasoning condition operand (fixed for the turn in decision planning), and a Macro Reference entry. A preset or chat variable that already owns the name (in any spelling, e.g. Reasoning) keeps it, so existing presets don't change.
  • resolveReasoningMacroValue (provider-generation-runtime): runs the same layering as the request (preset → connection → chat → scene force → Codex default → provider/model mapping) but before assembly, because macros resolve while the prompt is built and the final parameters are only known afterwards. It reuses resolveGenerationParameters, so the two can't drift.
  • Wired into generation, the dry-run preview, the chat's live Peek Prompt fallback, and the preset preview.
  • Docs: macros.md and conditional-prompts.md (two new worked examples).
  • New reasoning-macro.regression.ts.

How: the macro reads resolvedEffort, the same value that turns thinking mode on, so "Maximum" shows as max, xhigh or high depending on the model.

Notes:

  • The Peek Prompt fallback (before a chat has generated anything) takes {{reasoning}} from the chat's own or default connection, exactly like {{model}} there already does. Matching per-request/random connection selection is out of scope on purpose.
  • The dry-run route layers a Conversation/Game preset's parameters while real generation doesn't (pre-existing). {{reasoning}} follows each route's own parameters, so it matches what each one reports.

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

  • Added a preset section with {{model}}, {{reasoning}} and checked the sent prompt: deepseek/deepseek-v4.1-flash:thinking, medium with Medium set, and on a random-connection chat z-ai/glm-5.3-flash, medium.
  • Regressions: reasoning-macro (incl. a Reasoning preset variable, @reasoning operand, deferred preset value), prompt, decision-conditionals, chat-variables all pass.
  • Local CodeRabbit: 3 minor findings; the two real ones (variable-name case, operand lookup key) are fixed in b2a3371ed, the third is the Peek Prompt note above.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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): #7710
  • Version/release files updated (only if this PR includes a version bump)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a {{reasoning}} prompt macro that reflects the effective reasoning setting, including off, medium, high, and max.
    • Use reasoning levels and model names in conditional prompts. Existing variables named reasoning retain precedence over the macro.
    • Prompt previews, dry runs, and generation now resolve reasoning consistently across connection, chat, scene, and preset settings.
  • Documentation
    • Expanded the conditional-prompt guide with model-specific and reasoning-dependent examples, and clarified how reasoning values are resolved.

🔄 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/7705 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/model-reasoning-macros-hgo3l3` --- ### 📝 Commits (3) - [`aa653b5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aa653b5061785e9d029e83d8fda36ac793c99db1) feat(macros): add {{reasoning}} for the request's reasoning level - [`b2a3371`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b2a3371ed56aebdc2560841f78cc26389657a914) fix(macros): let a variable own {{reasoning}} in any spelling - [`6456383`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6456383191c0919b58b5b6fe41b4e094c665360c) fix(macros): match {{reasoning}} previews to their requests ### 📊 Changes **12 files changed** (+395 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/prompts/conditional-prompts.md` (+24 -2) 📝 `docs/prompts/macros.md` (+3 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+23 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+18 -1) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+21 -0) 📝 `packages/server/src/routes/prompts.routes.ts` (+14 -1) 📝 `packages/server/src/services/generation/provider-generation-runtime.ts` (+43 -0) 📝 `packages/server/src/services/prompt/assembler.ts` (+3 -0) 📝 `packages/server/src/services/prompt/macro-context.ts` (+2 -0) 📝 `packages/shared/src/utils/macro-engine.ts` (+36 -0) ➕ `scripts/regressions/reasoning-macro-routes.regression.ts` (+138 -0) ➕ `scripts/regressions/reasoning-macro.regression.ts` (+70 -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 #7704 ## Why this change Before: a preset can't tell whether the model is thinking, so chain-of-thought sections have to be toggled by hand whenever the reasoning level changes. After: `{{reasoning}}` resolves to the level the model is actually sent (`low` … `max`) or `off`, so `{{#if reasoning}}…{{else}}…{{/if}}` keeps a CoT section only when it's needed, and `{{#if reasoning == "max"}}` targets one level. `{{model}}` already existed; the docs now show model-specific conditionals with it (`{{#if model contains "opus"}}`). ## What changed - `macro-engine.ts`: new `reasoning` context field, `{{reasoning}}` macro, `reasoning` condition operand (fixed for the turn in decision planning), and a Macro Reference entry. A preset or chat variable that already owns the name (in any spelling, e.g. `Reasoning`) keeps it, so existing presets don't change. - `resolveReasoningMacroValue` (provider-generation-runtime): runs the same layering as the request (preset → connection → chat → scene force → Codex default → provider/model mapping) but before assembly, because macros resolve while the prompt is built and the final parameters are only known afterwards. It reuses `resolveGenerationParameters`, so the two can't drift. - Wired into generation, the dry-run preview, the chat's live Peek Prompt fallback, and the preset preview. - Docs: `macros.md` and `conditional-prompts.md` (two new worked examples). - New `reasoning-macro.regression.ts`. How: the macro reads `resolvedEffort`, the same value that turns thinking mode on, so "Maximum" shows as `max`, `xhigh` or `high` depending on the model. Notes: - The Peek Prompt fallback (before a chat has generated anything) takes `{{reasoning}}` from the chat's own or default connection, exactly like `{{model}}` there already does. Matching per-request/random connection selection is out of scope on purpose. - The dry-run route layers a Conversation/Game preset's parameters while real generation doesn't (pre-existing). `{{reasoning}}` follows each route's own parameters, so it matches what each one reports. ## Validation - [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 - Added a preset section with `{{model}}, {{reasoning}}` and checked the sent prompt: `deepseek/deepseek-v4.1-flash:thinking, medium` with Medium set, and on a random-connection chat `z-ai/glm-5.3-flash, medium`. - Regressions: `reasoning-macro` (incl. a `Reasoning` preset variable, `@reasoning` operand, deferred preset value), `prompt`, `decision-conditionals`, `chat-variables` all pass. - Local CodeRabbit: 3 minor findings; the two real ones (variable-name case, operand lookup key) are fixed in b2a3371ed, the third is the Peek Prompt note above. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [x] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation): #7710 - [ ] Version/release files updated (only if this PR includes a version bump) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a `{{reasoning}}` prompt macro that reflects the effective reasoning setting, including `off`, `medium`, `high`, and `max`. - Use reasoning levels and model names in conditional prompts. Existing variables named `reasoning` retain precedence over the macro. - Prompt previews, dry runs, and generation now resolve reasoning consistently across connection, chat, scene, and preset settings. - **Documentation** - Expanded the conditional-prompt guide with model-specific and reasoning-dependent examples, and clarified how reasoning values are resolved. <!-- 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-24 04:08:32 +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#7891
No description provided.