[PR #7808] [MERGED] feat(decision): let Choice options carry criteria for the Decision model #7935

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

📋 Pull Request Information

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

Base: staging ← Head: feat/7791-decision-criteria


📝 Commits (2)

  • 7c72055 feat(decision): let Choice options carry criteria for the Decision model
  • 520fdb5 docs(decision): say what happens when criteria quotes differ

📊 Changes

6 files changed (+377 additions, -40 deletions)

View changed files

📝 docs/prompts/conditional-prompts.md (+10 -0)
📝 packages/server/src/services/decision/decision-default.ts (+3 -1)
📝 packages/server/src/services/decision/prompt-decisions.ts (+30 -12)
📝 packages/server/src/services/decision/system-one.client.ts (+9 -5)
📝 packages/shared/src/utils/macro-engine.ts (+75 -22)
➕ scripts/regressions/decision-choice-criteria.regression.ts (+250 -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 #7791

Why this change

  • A decision_choice: option is only a word like "angry", so the Decision model has to guess what it means from its own preconceptions. Authors wanted to tell the model what each answer means in their story, without rewording the question or renaming the options.

What changed

  • New, additive syntax: an option can be written as "option":"criteria", e.g. {{#if decision_choice:"Kaelen's mood in the latest message" == "angry":"Kaelen raises his voice, makes threats or breaks something"}}. It works on either side of the comparison, with ==/!=/is/is not, and in the short form (== "rain":"..." || "snow":"..."). Both parts are quoted with the same kind of quote and escape like any other quoted value.
  • The answer is still the option: the model returns "angry", and every comparison (live evaluation, Peek Prompt planning, the lorebook settled-branch pass, group and per-responder blocks) compares with "angry", never with the criteria.
  • The Decision prompt: System One backends get the criteria as the option's criteria description (they used to be empty strings); a chat-model backend asks each option as statement: option (criteria). Options without criteria are sent exactly as before. The prompt stays visible in debug mode through the existing logDebugOverride request logging and the Decision debug inspection trace.
  • Macros in criteria resolve in the same context as their statement, so a per-character {{char}} statement gets per-character criteria. If one option has criteria in several places, the first non-empty ones count. Edited criteria change the turn's Choice cache key, so they are asked again rather than reusing an answer to the old wording.
  • Backward compatibility: anything that is not exactly "option":"criteria" keeps its old meaning (a colon inside one quoted value, unescaped inner quotes, mixed quote kinds, a trailing colon). Only comparisons against a decision_choice: operand read criteria; every other comparison is untouched. The only syntax whose meaning changes is a decision_choice literal of the exact form "x":"y", which used to be offered to the model as the single option x":"y.
  • Docs: one short paragraph and example in docs/prompts/conditional-prompts.md (English only; translations follow in the release docs sweep).
  • Regression: scripts/regressions/decision-choice-criteria.regression.ts.

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

Commands actually run in this branch:

  • pnpm build:shared && node ./scripts/run-regressions.mjs --filter decision-choice-criteria: passed. It covers old syntax unchanged, new syntax parsed (both sides, short form, escapes, curly and single quotes, &&/|| inside criteria), malformed input falling back, evaluation and settled-branch planning comparing the option alone, criteria merged and macro-resolved per character, criteria in the System One request body and in the chat-model per-option statement, and edited criteria re-asking the turn.
  • The same old-syntax and malformed-input assertions were also run against an origin/staging build of macro-engine.ts and hold there, so they pin the old behaviour, not just the new one.
  • node ./scripts/run-regressions.mjs --filter decision: 17/17 passed.
  • node ./scripts/run-regressions.mjs --filter macro, --filter conditional, --filter lorebook: all passed.
  • pnpm regression:prompt: passed.
  • pnpm check: passed.

Manual verification notes

  • Manually verify in a chat with a System One Decision connection that a preset section using decision_choice:"..." == "angry":"..." sends the criteria (check the request with debug mode on in the server log or the Decision debug panel) and that the angry branch is still selected when the model answers "angry".
  • Manually verify the same preset with a local chat-model Decision slot: the per-option question reads statement: angry (criteria) in the debug log.
  • Manually verify that an existing preset using the old decision_choice:"..." == "angry" syntax picks the same branches as before.
  • Manually verify in Peek Prompt that a branch gated by an option with criteria shows the held or cached answer correctly.

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)
  • Version/release files updated (only if this PR includes a version bump)

Changed English docs: docs/prompts/conditional-prompts.md (translations are handled in the release docs sweep).

UI evidence (if applicable)

  • No UI changes.

Summary by CodeRabbit

  • New Features
    • Choice options can now include descriptive criteria that guide AI-generated decisions without changing how options are compared.
    • Criteria support quoted text and macros. When the same option appears more than once, its first supplied criteria are used; options without criteria keep their existing behavior.
  • Documentation
    • Updated guidance with syntax, examples, and details about matching quotes and repeated options.

🔄 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/7808 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/7791-decision-criteria` --- ### 📝 Commits (2) - [`7c72055`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7c7205555684ea609d2b3f9fc56ff6476e5cf8cb) feat(decision): let Choice options carry criteria for the Decision model - [`520fdb5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/520fdb523477f35ea04b0967c7c635340cb25399) docs(decision): say what happens when criteria quotes differ ### 📊 Changes **6 files changed** (+377 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `docs/prompts/conditional-prompts.md` (+10 -0) 📝 `packages/server/src/services/decision/decision-default.ts` (+3 -1) 📝 `packages/server/src/services/decision/prompt-decisions.ts` (+30 -12) 📝 `packages/server/src/services/decision/system-one.client.ts` (+9 -5) 📝 `packages/shared/src/utils/macro-engine.ts` (+75 -22) ➕ `scripts/regressions/decision-choice-criteria.regression.ts` (+250 -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 #7791 ## Why this change - A `decision_choice:` option is only a word like "angry", so the Decision model has to guess what it means from its own preconceptions. Authors wanted to tell the model what each answer means in their story, without rewording the question or renaming the options. ## What changed - **New, additive syntax:** an option can be written as `"option":"criteria"`, e.g. `{{#if decision_choice:"Kaelen's mood in the latest message" == "angry":"Kaelen raises his voice, makes threats or breaks something"}}`. It works on either side of the comparison, with `==`/`!=`/`is`/`is not`, and in the short form (`== "rain":"..." || "snow":"..."`). Both parts are quoted with the same kind of quote and escape like any other quoted value. - **The answer is still the option:** the model returns "angry", and every comparison (live evaluation, Peek Prompt planning, the lorebook settled-branch pass, group and per-responder blocks) compares with "angry", never with the criteria. - **The Decision prompt:** System One backends get the criteria as the option's `criteria` description (they used to be empty strings); a chat-model backend asks each option as `statement: option (criteria)`. Options without criteria are sent exactly as before. The prompt stays visible in debug mode through the existing `logDebugOverride` request logging and the Decision debug inspection trace. - Macros in criteria resolve in the same context as their statement, so a per-character `{{char}}` statement gets per-character criteria. If one option has criteria in several places, the first non-empty ones count. Edited criteria change the turn's Choice cache key, so they are asked again rather than reusing an answer to the old wording. - **Backward compatibility:** anything that is not exactly `"option":"criteria"` keeps its old meaning (a colon inside one quoted value, unescaped inner quotes, mixed quote kinds, a trailing colon). Only comparisons against a `decision_choice:` operand read criteria; every other comparison is untouched. The only syntax whose meaning changes is a decision_choice literal of the exact form `"x":"y"`, which used to be offered to the model as the single option `x":"y`. - Docs: one short paragraph and example in `docs/prompts/conditional-prompts.md` (English only; translations follow in the release docs sweep). - Regression: `scripts/regressions/decision-choice-criteria.regression.ts`. ## 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` Commands actually run in this branch: - `pnpm build:shared && node ./scripts/run-regressions.mjs --filter decision-choice-criteria`: passed. It covers old syntax unchanged, new syntax parsed (both sides, short form, escapes, curly and single quotes, `&&`/`||` inside criteria), malformed input falling back, evaluation and settled-branch planning comparing the option alone, criteria merged and macro-resolved per character, criteria in the System One request body and in the chat-model per-option statement, and edited criteria re-asking the turn. - The same old-syntax and malformed-input assertions were also run against an `origin/staging` build of `macro-engine.ts` and hold there, so they pin the old behaviour, not just the new one. - `node ./scripts/run-regressions.mjs --filter decision`: 17/17 passed. - `node ./scripts/run-regressions.mjs --filter macro`, `--filter conditional`, `--filter lorebook`: all passed. - `pnpm regression:prompt`: passed. - `pnpm check`: passed. ### Manual verification notes - Manually verify in a chat with a System One Decision connection that a preset section using `decision_choice:"..." == "angry":"..."` sends the criteria (check the request with debug mode on in the server log or the Decision debug panel) and that the `angry` branch is still selected when the model answers "angry". - Manually verify the same preset with a local chat-model Decision slot: the per-option question reads `statement: angry (criteria)` in the debug log. - Manually verify that an existing preset using the old `decision_choice:"..." == "angry"` syntax picks the same branches as before. - Manually verify in Peek Prompt that a branch gated by an option with criteria shows the held or cached answer correctly. ## 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) - [ ] Version/release files updated (only if this PR includes a version bump) Changed English docs: `docs/prompts/conditional-prompts.md` (translations are handled in the release docs sweep). ## UI evidence (if applicable) - No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Choice options can now include descriptive criteria that guide AI-generated decisions without changing how options are compared. * Criteria support quoted text and macros. When the same option appears more than once, its first supplied criteria are used; options without criteria keep their existing behavior. * **Documentation** * Updated guidance with syntax, examples, and details about matching quotes and repeated options. <!-- 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:58 +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#7935
No description provided.