[PR #5944] [MERGED] Let an Experience pass player-picked lorebook entries into world generation #7001

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5944
Author: @kolacheee
Created: 9/8/2026
Status: ✅ Merged
Merged: 9/8/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/experience-lore-entries


📝 Commits (10+)

  • fd4ba68 feat(lorebook): let a caller size the forced-entry budget and skip its roll
  • 82821de feat(game): let an Experience read the lorebook entries a player picked
  • 60df2ac fix(game): keep an Experience's lore selection to exactly what was ticked (#5942)
  • 4798e45 fix(game): keep a set-aside Experience lore entry out of the call (#5942)
  • 43eaeb6 fix(game): always answer an Experience's lore selection, even at zero (#5942)
  • f5715e5 refactor(game): the lore party fallback reads the chat cast through the existing parser (#5942)
  • 2bdd3d6 Merge remote-tracking branch 'origin/staging' into codex/review-pr-5944-sep8
  • 6b611eb fix(lore): enforce exact selection budgets for recursive books
  • 611d839 Merge remote-tracking branch 'origin/staging' into codex/review-pr-5944-sep8
  • 77ca164 test(ui): scope character action proof to its fixture

📊 Changes

6 files changed (+1093 additions, -9 deletions)

View changed files

📝 CHANGELOG.md (+5 -0)
📝 e2e/core-flows.e2e.ts (+2 -0)
📝 packages/server/src/routes/game.routes.ts (+198 -3)
📝 packages/server/src/services/lorebook/index.ts (+50 -6)
📝 packages/server/src/services/lorebook/keyword-scanner.ts (+9 -0)
➕ scripts/regressions/experience-lore-entries.regression.ts (+829 -0)

📄 Description

Linked issue

Closes #5942

Why this change

  • Pixelforge's 0.16.2 setup lets the player pick specific lorebook entries to inform the world-writing generation ("the GM knows other settlements from the lorebook like Viridian City, Cinnabar Island" — maintainer ruling on the feature). The experience-generation route had no lorebook machinery at all, so this adds the minimal server half: a selection of entry ids reaches the call, exactly the selection and nothing else, with honest reporting of what was set aside.

What changed

  • experienceGenerationSchema gains lorebookEntryIds — z.array(z.string()).max(LIMITS.MAX_LOREBOOK_ENTRIES).optional(). Absent or empty is a byte-identical no-op: no storage read, no macro context, no appended content, no response key (the regression captures upstream messages against a baseline and asserts deep equality).
  • The experience-generation handler gains a processLorebooks call modeled on /setup's block (macro context re-derived from chat metadata, scope exclusions, the three-part worldInfo join, appended to the outbound content), passing the selection as forcedEntryIds with generationTriggers supplied explicitly.
  • Exact-selection contract — new forcedEntriesOnly mode on processLorebooks: the ambient book filter and entry listing are suppressed, so a global book's constant entries cannot ride in on somebody else's tick; eligibility gates (enabled, character/tag/trigger filters, timing) still refuse. A set-aside entry also stays out of the call — the ordinary scan is skipped outright under this mode, closing the scan-then-merge re-admission for this route (the pre-existing shape on older callers is #5943, with a measured second door recorded there).
  • A ticked entry never dice-rolls away — ignoreProbability on ScanOptions, read in exactly one place (passesForcedEntryActivationGates), set in exactly one spread, copying the ignoreTiming precedent; every existing caller byte-identical (all construction sites enumerated in review).
  • The budget answers to the caller — the route passes a 3,000-token forced-entry location budget through applyCurrentLocationLoreBudget's existing defaulted parameter; drops follow the existing selection order (constants survive first) at whole-entry granularity; budgetSkippedEntries is projected into the response as lorebook: { includedEntries, skippedEntries[] }.
  • The response never goes silent on a selection: whenever the request carried a non-empty selection, the lorebook key is present — all-refused is { includedEntries: 0, skippedEntries: [...] }, cleanly distinguishable from an Engine that predates the feature (no key). This is what lets the client side avoid writing a false "all your picks were refused" record against an older server.
  • scripts/regressions/experience-lore-entries.regression.ts — eleven scenarios, twelve pinned behaviors; every load-bearing line was mutation-tested across the review rounds (22 distinct seeded bugs killed).
  • CHANGELOG entry under [Unreleased].

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

  • Manually verify with the Pixelforge 0.16.2 package (Agents PR #750): tick entries in the setup picker, generate a world, and confirm the world references the ticked lore; untick everything and confirm generation is unchanged from today.
  • Manually verify a global always-on lorebook attached to the chat does NOT leak into a world generated from a selection in a different book.
  • Machine-side evidence (all run): pnpm check exit 0; the feature regression green; full regression runner 220/221 (the one red is the known gallery-previews Windows EPERM teardown flake, reproduced on clean HEAD; note the full suite needs Git Bash — under PowerShell launcher/format-guard can't spawn bash); three independent adversarial review rounds with 22 seeded mutants killed, including one that re-implements the rejected design candidate and proves it leaks.

Maintainer review follow-up: Fixed the exact-selection recursive re-admission in this PR: forcedEntriesOnly now skips recursive activation as well as the ordinary scan. A regression first reproduced ten entries entering a seven-entry budget while three were reported skipped; it now tests both recursive and non-recursive selected books and passes. Legacy /setup and spatial caller behavior is unchanged, so #5943 remains open for those paths.

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)

CHANGELOG updated; no user-facing docs/ pages touched (the player-facing surface is the package's, documented in Agents PR #750).

UI evidence (if applicable)

  • No Engine UI changes; the UI is package-side (Agents PR #750).

Summary by CodeRabbit

  • New Features

    • Game-surface Experiences can use explicitly selected lorebook entries.
    • Selected entries are filtered by eligibility and capacity limits; unrelated entries are excluded.
    • Responses report included and skipped entries, including when none can be used.
    • Oversized selections receive validation feedback.
    • Experience generation remains unchanged when no entries are selected.
  • Bug Fixes

    • Explicit selections bypass probability checks while retaining other eligibility rules.
    • Experience lore selections now respect token limits, including when recursive scanning is enabled.

Maintainer staging integration

Updated against current staging. pnpm check, experience-lore-entries, and neighboring lorebook and prompt regressions pass locally. The recursive budget case was red before the fix and green after it. Validation uses local synthetic provider responses, not paid-provider or Experience-package UI proof. Human/manual validation checkboxes remain unchecked.


🔄 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/5944 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/8/2026 **Status:** ✅ Merged **Merged:** 9/8/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/experience-lore-entries` --- ### 📝 Commits (10+) - [`fd4ba68`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fd4ba687f913f308500788533a558b7da8f43fd6) feat(lorebook): let a caller size the forced-entry budget and skip its roll - [`82821de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/82821dea4e9101cb14ab015fd8a678b5bab2c792) feat(game): let an Experience read the lorebook entries a player picked - [`60df2ac`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60df2acc4bcc0b1b5e4c2b8ecd88161c583fa966) fix(game): keep an Experience's lore selection to exactly what was ticked (#5942) - [`4798e45`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4798e454c336cbb1f8dc70db8e4695801ef22a1f) fix(game): keep a set-aside Experience lore entry out of the call (#5942) - [`43eaeb6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43eaeb6f414e60faf46c3dd8491bb7cf1b8693fb) fix(game): always answer an Experience's lore selection, even at zero (#5942) - [`f5715e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f5715e5260fd96fab883b54a9ddcd1331f44138f) refactor(game): the lore party fallback reads the chat cast through the existing parser (#5942) - [`2bdd3d6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2bdd3d67e281058aca825b5edc953058dba7b715) Merge remote-tracking branch 'origin/staging' into codex/review-pr-5944-sep8 - [`6b611eb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6b611eb88af7de3f1fff70aa87fdaef453881577) fix(lore): enforce exact selection budgets for recursive books - [`611d839`](https://github.com/Pasta-Devs/Marinara-Engine/commit/611d8395049965bd59a1d9fc9383eb3079471aa8) Merge remote-tracking branch 'origin/staging' into codex/review-pr-5944-sep8 - [`77ca164`](https://github.com/Pasta-Devs/Marinara-Engine/commit/77ca164924570aa44e39316da8f4d044d37a1108) test(ui): scope character action proof to its fixture ### 📊 Changes **6 files changed** (+1093 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+5 -0) 📝 `e2e/core-flows.e2e.ts` (+2 -0) 📝 `packages/server/src/routes/game.routes.ts` (+198 -3) 📝 `packages/server/src/services/lorebook/index.ts` (+50 -6) 📝 `packages/server/src/services/lorebook/keyword-scanner.ts` (+9 -0) ➕ `scripts/regressions/experience-lore-entries.regression.ts` (+829 -0) </details> ### 📄 Description ## Linked issue Closes #5942 ## Why this change - Pixelforge's 0.16.2 setup lets the player pick specific lorebook entries to inform the world-writing generation ("the GM knows other settlements from the lorebook like Viridian City, Cinnabar Island" — maintainer ruling on the feature). The experience-generation route had no lorebook machinery at all, so this adds the minimal server half: a selection of entry ids reaches the call, exactly the selection and nothing else, with honest reporting of what was set aside. ## What changed - `experienceGenerationSchema` gains `lorebookEntryIds` — `z.array(z.string()).max(LIMITS.MAX_LOREBOOK_ENTRIES).optional()`. **Absent or empty is a byte-identical no-op**: no storage read, no macro context, no appended content, no response key (the regression captures upstream messages against a baseline and asserts deep equality). - The experience-generation handler gains a `processLorebooks` call modeled on `/setup`'s block (macro context re-derived from chat metadata, scope exclusions, the three-part worldInfo join, appended to the outbound content), passing the selection as `forcedEntryIds` with `generationTriggers` supplied explicitly. - **Exact-selection contract** — new `forcedEntriesOnly` mode on `processLorebooks`: the ambient book filter and entry listing are suppressed, so a global book's constant entries cannot ride in on somebody else's tick; eligibility gates (enabled, character/tag/trigger filters, timing) still refuse. A set-aside entry also stays out of the call — the ordinary scan is skipped outright under this mode, closing the scan-then-merge re-admission for this route (the pre-existing shape on older callers is #5943, with a measured second door recorded there). - **A ticked entry never dice-rolls away** — `ignoreProbability` on `ScanOptions`, read in exactly one place (`passesForcedEntryActivationGates`), set in exactly one spread, copying the `ignoreTiming` precedent; every existing caller byte-identical (all construction sites enumerated in review). - **The budget answers to the caller** — the route passes a 3,000-token forced-entry location budget through `applyCurrentLocationLoreBudget`'s existing defaulted parameter; drops follow the existing selection order (constants survive first) at whole-entry granularity; `budgetSkippedEntries` is projected into the response as `lorebook: { includedEntries, skippedEntries[] }`. - **The response never goes silent on a selection**: whenever the request carried a non-empty selection, the `lorebook` key is present — all-refused is `{ includedEntries: 0, skippedEntries: [...] }`, cleanly distinguishable from an Engine that predates the feature (no key). This is what lets the client side avoid writing a false "all your picks were refused" record against an older server. - `scripts/regressions/experience-lore-entries.regression.ts` — eleven scenarios, twelve pinned behaviors; every load-bearing line was mutation-tested across the review rounds (22 distinct seeded bugs killed). - CHANGELOG entry under [Unreleased]. ## 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 - Manually verify with the Pixelforge 0.16.2 package (Agents PR #750): tick entries in the setup picker, generate a world, and confirm the world references the ticked lore; untick everything and confirm generation is unchanged from today. - Manually verify a global always-on lorebook attached to the chat does NOT leak into a world generated from a selection in a different book. - Machine-side evidence (all run): `pnpm check` exit 0; the feature regression green; full regression runner 220/221 (the one red is the known `gallery-previews` Windows EPERM teardown flake, reproduced on clean HEAD; note the full suite needs Git Bash — under PowerShell `launcher/format-guard` can't spawn bash); three independent adversarial review rounds with 22 seeded mutants killed, including one that re-implements the rejected design candidate and proves it leaks. **Maintainer review follow-up:** Fixed the exact-selection recursive re-admission in this PR: `forcedEntriesOnly` now skips recursive activation as well as the ordinary scan. A regression first reproduced ten entries entering a seven-entry budget while three were reported skipped; it now tests both recursive and non-recursive selected books and passes. Legacy `/setup` and spatial caller behavior is unchanged, so #5943 remains open for those paths. ## 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) CHANGELOG updated; no user-facing docs/ pages touched (the player-facing surface is the package's, documented in Agents PR #750). ## UI evidence (if applicable) - No Engine UI changes; the UI is package-side (Agents PR #750). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Game-surface Experiences can use explicitly selected lorebook entries. * Selected entries are filtered by eligibility and capacity limits; unrelated entries are excluded. * Responses report included and skipped entries, including when none can be used. * Oversized selections receive validation feedback. * Experience generation remains unchanged when no entries are selected. * **Bug Fixes** * Explicit selections bypass probability checks while retaining other eligibility rules. * Experience lore selections now respect token limits, including when recursive scanning is enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Maintainer staging integration Updated against current `staging`. `pnpm check`, `experience-lore-entries`, and neighboring lorebook and prompt regressions pass locally. The recursive budget case was red before the fix and green after it. Validation uses local synthetic provider responses, not paid-provider or Experience-package UI proof. Human/manual validation checkboxes remain unchecked. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:15:38 +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#7001
No description provided.