[PR #6343] [MERGED] feat(game): community rulesets from a file or a custom repository (rulesets slice 7a) #7144

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

📋 Pull Request Information

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

Base: staging ← Head: feat/rulesets-community


📝 Commits (10+)

  • c2d4641 feat(game): store community rulesets beside packaged ones
  • c58871e fix(game): name the chosen combat style in the ruleset note and list installed rulesets in the Agents panel
  • d41fcd0 docs(game): ruleset authoring guide, a non-d20 example and a generated JSON Schema
  • c05a8b1 feat(game): import community rulesets from a file or a custom agent repository
  • f8301e7 fix(game): address local review findings on the community ruleset lanes
  • 330d8e0 fix(game): second round of local review findings on the ruleset lanes
  • 643019f fix(game): skip a refused repository ruleset at confirm and allow comments on every schema object
  • f48e231 fix(agents): hold the empty Agents panel state until installed rulesets have loaded
  • a70a7b2 fix(game): bound the ruleset import request body at the route
  • 9f88a4d fix(agents): tolerate a repository preview that carries no rulesets

📊 Changes

38 files changed (+5578 additions, -95 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 docs/CONFIGURATION.md (+8 -2)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+38 -1)
➕ docs/examples/rulesets/ember-roads.json (+121 -0)
➕ docs/extending/ruleset.schema.json (+2421 -0)
➕ docs/extending/writing-rulesets.md (+148 -0)
📝 docs/game/getting-started.md (+4 -2)
📝 package.json (+3 -1)
📝 packages/client/src/components/agents/CustomAgentRepositoriesModal.tsx (+122 -18)
➕ packages/client/src/components/agents/RulesetImportReviewModal.tsx (+160 -0)
📝 packages/client/src/components/game/GameSetupRulesChooser.tsx (+23 -2)
📝 packages/client/src/components/game/GameSetupWizard.tsx (+27 -5)
📝 packages/client/src/components/panels/AgentsPanel.tsx (+252 -4)
📝 packages/client/src/hooks/use-capability-packages.ts (+26 -0)
📝 packages/client/src/hooks/use-custom-agent-repositories.ts (+13 -6)
📝 packages/client/src/hooks/use-game-ruleset.ts (+43 -6)
➕ packages/client/src/lib/ruleset-source.ts (+16 -0)
📝 packages/client/src/localization/locales/en.json (+62 -4)
📝 packages/server/src/db/file-backed-store.ts (+1 -0)
➕ packages/server/src/db/schema/game-rulesets.ts (+38 -0)

...and 18 more files

📄 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

Part of #6314 (slice 7a; it does not close the issue). Builds on #6336 and #6338 (slices 5 and 6, merged).

Why this change

  • The ruleset request came from a community author, and until now the only way to get a ruleset into the Engine was an official package. An author could not try their own file, hand it to a friend, or publish it from their own repository.
  • Two things from the first hands-on use of the 5e package: the wizard said battles use "Marinara's default combat", which reads as Classic even when Tactical is picked, and an installed rules package did not show anywhere in the Agents panel, so it looked like the install had failed.

What changed

  • Storage. A new file-backed table, game_rulesets, holds community rulesets: one row per namespaced id and version, with the exact imported text and its sha256. No STORAGE_VERSION bump (same precedent as game_dice_pools). The table has no owner and no cascade.
  • Ids. The file carries its bare id. The Engine files it as local/<id> for a picked file and <owner>/<id> for a repository, and the registry rewrites definition.id to that, so nothing imported can take an official ruleset's id and two authors' v20 are two rulesets. A GitHub account named local is refused.
  • Versions. A stored version is never rewritten. The same bytes are a no-op; different bytes under an existing version are refused with a message telling the author to raise the version. A game on a community ruleset resolves the exact version it pinned (new reason version-missing); official packages keep their existing rule.
  • Single-file import. POST /api/game-rulesets/import (privileged access plus Allow custom Agent imports, the same two gates as POST /agents/import). The Agents panel's Import agents chooser gains Game Mode ruleset. The client parses the file with the shared parser, then a review shows identity, license, coverage, how checks roll, and the Game Master text verbatim with a sentence that it is sent to the model. No capability checkboxes, because a ruleset has none.
  • Removal. DELETE /api/game-rulesets?rulesetId= removes every stored version. It needs privileged access only, so it works with imports off. When games pin the ruleset it answers 409 ruleset_in_use with the count, and the client asks again before retrying with force=true.
  • Repository lane. A custom agent repository may carry rulesets/*.json (direct children only, at most 32 files of 256 KB) beside or instead of agents.json. Every existing archive safety check is unchanged. The preview lists each ruleset with a status (new, new version, already installed, version kept, cannot be used); one unusable file is a row with its reasons, never a failed repository. The preview-to-confirm digest check covers rulesets because they come from the same archive. A ruleset withdrawn upstream stays installed, and removing the repository only detaches its rulesets.
  • Imports off. /game/create refuses a community ruleset with ruleset_imports_disabled and the wizard leaves them out. Resolution never consults the policy, so games already on one keep working, and GET /capability-packages/rulesets keeps listing them so stored sheets stay readable.
  • Agents panel. A Rules section lists every installed ruleset. A rules package gets Uninstall; an imported ruleset shows where it came from and its stored versions, with a remove button.
  • Wizard wording. The note for a ruleset without combat rules now names the chosen Combat Preference (Classic or Tactical). Community rulesets show an "Imported" line on their card.
  • For authors. New guide docs/extending/writing-rulesets.md (it leads with what a ruleset cannot do), a 2d6 example ruleset docs/examples/rulesets/ember-roads.json, and docs/extending/ruleset.schema.json, generated from the zod schema by pnpm ruleset:schema. New root dev dependency zod-to-json-schema (it was already in the lockfile as a transitive dependency, same version).
  • Regressions: game-ruleset-community (storage, namespacing, exact-version pins, policy off, the guide's example), game-ruleset-import (the two routes), game-ruleset-repository (archive parsing, statuses, verbatim bytes, detach), game-ruleset-json-schema (the committed schema is current).
  • Not in this slice: ruleset layers (for example Low Magic on 5e) were revisited and stay their own later slice; the plan records why. Catalogs (pickable spells and features) are written into the plan as a proposal.

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

Commands run locally by the agent: pnpm check (exit 0), pnpm localization:check, the full node regression lane (pnpm regression:node, 312 of 312), and the four new regressions. Six local CodeRabbit sweeps were run before opening. Their findings were fixed (error handling around the import, per-file handling in the repository lane, the wizard failing closed while the import policy loads, a route body limit), and the last complete one returned no findings. One suggestion was declined: a separate schema for the resolved community definition. Nothing re-validates a resolved definition, so the type now documents that instead.

The agent also drove a scratch server on port 7820 with a fresh data folder and a keyless dummy connection (no model was connected):

  • Import route: first import added, the same bytes unchanged, changed bytes under the same version 409 with the raise-the-version message, a higher version added, and /capability-packages/rulesets listed local/ember-roads with versions 1, 2.
  • Agents panel with no agents installed: the Rules section showed the imported ruleset with "Imported file, version 1, 2". Import agents offered Game Mode ruleset. A picked file opened the review (id local/ember-roads, version, license, coverage, how checks roll, Game Master text), and Import showed "Imported Ember Roads, version 3."
  • Setup wizard: the Rules choice listed the ruleset with an "Imported file" line, and with Tactical picked the note read "Battles run on Marinara's Tactical combat, the Combat Preference picked above."
  • A game created on the ruleset pinned the highest stored version. Removing the ruleset then asked twice, the second time saying "1 game plays on this ruleset", and Cancel kept every version.
  • With Allow custom Agent imports off: import answered 403, /game/create on the ruleset answered ruleset_imports_disabled, and the wizard's World step showed no Rules choice.
  • At 375 px the review dialog was full width with no horizontal overflow (live geometry, not a screenshot).

Still to verify by hand:

  • Manually import a ruleset file, read the review, and confirm it appears under Rules and in the setup wizard.
  • Manually edit the file without raising its version, import again, and confirm the refusal tells you to raise the version.
  • Manually turn Allow custom Agent imports off and confirm the imported ruleset leaves the wizard while a game already on it still rolls checks.
  • Manually remove an imported ruleset that a game uses and confirm the second confirmation names the number of games.
  • Manually add a real GitHub repository that has a rulesets folder (needs ENABLE_CUSTOM_AGENT_REPOS=true); the download against live GitHub was not exercised, only an in-memory archive through the real fetch path.
  • Manually verify light mode and a phone-width viewport for the review dialog and the repository preview.

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)

Docs touched: CHANGELOG.md, docs/CONFIGURATION.md (custom agent repositories), docs/game/getting-started.md (Choosing rules), new docs/extending/writing-rulesets.md, the plan. The [docs-i18n] follow-up is batched for the ruleset slices.

UI evidence (if applicable)

To be added by a human: the Rules section, the import review dialog, and the repository preview with rulesets, in light, dark and phone width.

Summary by CodeRabbit

  • New Features

    • Import custom Game Mode rulesets from JSON files or supported repositories.
    • Review ruleset details, coverage, licensing, versions, and validation results before installation.
    • Manage installed rulesets from the Agents panel, including filtering and removal.
    • Use repository-provided rulesets alongside agent definitions.
    • Preserve the exact ruleset version used by existing games.
    • Game setup identifies the selected Combat Preference when a ruleset lacks combat coverage.
    • Control custom imports through the Agent import setting.
  • Documentation

    • Added a ruleset authoring guide, example ruleset, and JSON Schema.
    • Expanded guidance for custom repository rulesets and importing workflows.

🔄 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/6343 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/18/2026 **Status:** ✅ Merged **Merged:** 9/19/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/rulesets-community` --- ### 📝 Commits (10+) - [`c2d4641`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2d4641700efdcbd23966e9c96ef49ea390b829e) feat(game): store community rulesets beside packaged ones - [`c58871e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c58871e6145da6fa722f4aafa95b9ff5ea502aa0) fix(game): name the chosen combat style in the ruleset note and list installed rulesets in the Agents panel - [`d41fcd0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d41fcd0d57e116c592bbb59c79a1fb8390979ee5) docs(game): ruleset authoring guide, a non-d20 example and a generated JSON Schema - [`c05a8b1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c05a8b10397631f4e9a16db7346b8ecd533cad8a) feat(game): import community rulesets from a file or a custom agent repository - [`f8301e7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f8301e7b09295c73743ebc795471abf0ab04c37f) fix(game): address local review findings on the community ruleset lanes - [`330d8e0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/330d8e0f1708c481d7812351e61e65b27bb52f46) fix(game): second round of local review findings on the ruleset lanes - [`643019f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/643019f252d7b5355732882f7ba688e1ef86fba8) fix(game): skip a refused repository ruleset at confirm and allow comments on every schema object - [`f48e231`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f48e231d2bd5a297e376a6eed65dbda7e558a60b) fix(agents): hold the empty Agents panel state until installed rulesets have loaded - [`a70a7b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a70a7b2597781bde3018dbfeb4ef49b3c2669263) fix(game): bound the ruleset import request body at the route - [`9f88a4d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9f88a4deefd4a6532a9230655b8d8eb9b9756ed4) fix(agents): tolerate a repository preview that carries no rulesets ### 📊 Changes **38 files changed** (+5578 additions, -95 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `docs/CONFIGURATION.md` (+8 -2) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+38 -1) ➕ `docs/examples/rulesets/ember-roads.json` (+121 -0) ➕ `docs/extending/ruleset.schema.json` (+2421 -0) ➕ `docs/extending/writing-rulesets.md` (+148 -0) 📝 `docs/game/getting-started.md` (+4 -2) 📝 `package.json` (+3 -1) 📝 `packages/client/src/components/agents/CustomAgentRepositoriesModal.tsx` (+122 -18) ➕ `packages/client/src/components/agents/RulesetImportReviewModal.tsx` (+160 -0) 📝 `packages/client/src/components/game/GameSetupRulesChooser.tsx` (+23 -2) 📝 `packages/client/src/components/game/GameSetupWizard.tsx` (+27 -5) 📝 `packages/client/src/components/panels/AgentsPanel.tsx` (+252 -4) 📝 `packages/client/src/hooks/use-capability-packages.ts` (+26 -0) 📝 `packages/client/src/hooks/use-custom-agent-repositories.ts` (+13 -6) 📝 `packages/client/src/hooks/use-game-ruleset.ts` (+43 -6) ➕ `packages/client/src/lib/ruleset-source.ts` (+16 -0) 📝 `packages/client/src/localization/locales/en.json` (+62 -4) 📝 `packages/server/src/db/file-backed-store.ts` (+1 -0) ➕ `packages/server/src/db/schema/game-rulesets.ts` (+38 -0) _...and 18 more files_ </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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Part of #6314 (slice 7a; it does not close the issue). Builds on #6336 and #6338 (slices 5 and 6, merged). ## Why this change - The ruleset request came from a community author, and until now the only way to get a ruleset into the Engine was an official package. An author could not try their own file, hand it to a friend, or publish it from their own repository. - Two things from the first hands-on use of the 5e package: the wizard said battles use "Marinara's default combat", which reads as Classic even when Tactical is picked, and an installed rules package did not show anywhere in the Agents panel, so it looked like the install had failed. ## What changed - **Storage.** A new file-backed table, `game_rulesets`, holds community rulesets: one row per namespaced id and version, with the exact imported text and its sha256. No `STORAGE_VERSION` bump (same precedent as `game_dice_pools`). The table has no owner and no cascade. - **Ids.** The file carries its bare id. The Engine files it as `local/<id>` for a picked file and `<owner>/<id>` for a repository, and the registry rewrites `definition.id` to that, so nothing imported can take an official ruleset's id and two authors' `v20` are two rulesets. A GitHub account named `local` is refused. - **Versions.** A stored version is never rewritten. The same bytes are a no-op; different bytes under an existing version are refused with a message telling the author to raise the version. A game on a community ruleset resolves the exact version it pinned (new reason `version-missing`); official packages keep their existing rule. - **Single-file import.** `POST /api/game-rulesets/import` (privileged access plus **Allow custom Agent imports**, the same two gates as `POST /agents/import`). The Agents panel's **Import agents** chooser gains **Game Mode ruleset**. The client parses the file with the shared parser, then a review shows identity, license, coverage, how checks roll, and the Game Master text verbatim with a sentence that it is sent to the model. No capability checkboxes, because a ruleset has none. - **Removal.** `DELETE /api/game-rulesets?rulesetId=` removes every stored version. It needs privileged access only, so it works with imports off. When games pin the ruleset it answers 409 `ruleset_in_use` with the count, and the client asks again before retrying with `force=true`. - **Repository lane.** A custom agent repository may carry `rulesets/*.json` (direct children only, at most 32 files of 256 KB) beside or instead of `agents.json`. Every existing archive safety check is unchanged. The preview lists each ruleset with a status (new, new version, already installed, version kept, cannot be used); one unusable file is a row with its reasons, never a failed repository. The preview-to-confirm digest check covers rulesets because they come from the same archive. A ruleset withdrawn upstream stays installed, and removing the repository only detaches its rulesets. - **Imports off.** `/game/create` refuses a community ruleset with `ruleset_imports_disabled` and the wizard leaves them out. Resolution never consults the policy, so games already on one keep working, and `GET /capability-packages/rulesets` keeps listing them so stored sheets stay readable. - **Agents panel.** A **Rules** section lists every installed ruleset. A rules package gets **Uninstall**; an imported ruleset shows where it came from and its stored versions, with a remove button. - **Wizard wording.** The note for a ruleset without combat rules now names the chosen Combat Preference (Classic or Tactical). Community rulesets show an "Imported" line on their card. - **For authors.** New guide `docs/extending/writing-rulesets.md` (it leads with what a ruleset cannot do), a 2d6 example ruleset `docs/examples/rulesets/ember-roads.json`, and `docs/extending/ruleset.schema.json`, generated from the zod schema by `pnpm ruleset:schema`. New root dev dependency `zod-to-json-schema` (it was already in the lockfile as a transitive dependency, same version). - **Regressions:** `game-ruleset-community` (storage, namespacing, exact-version pins, policy off, the guide's example), `game-ruleset-import` (the two routes), `game-ruleset-repository` (archive parsing, statuses, verbatim bytes, detach), `game-ruleset-json-schema` (the committed schema is current). - **Not in this slice:** ruleset layers (for example Low Magic on 5e) were revisited and stay their own later slice; the plan records why. Catalogs (pickable spells and features) are written into the plan as a proposal. ## 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 Commands run locally by the agent: `pnpm check` (exit 0), `pnpm localization:check`, the full node regression lane (`pnpm regression:node`, 312 of 312), and the four new regressions. Six local CodeRabbit sweeps were run before opening. Their findings were fixed (error handling around the import, per-file handling in the repository lane, the wizard failing closed while the import policy loads, a route body limit), and the last complete one returned no findings. One suggestion was declined: a separate schema for the resolved community definition. Nothing re-validates a resolved definition, so the type now documents that instead. The agent also drove a scratch server on port 7820 with a fresh data folder and a keyless dummy connection (no model was connected): - Import route: first import `added`, the same bytes `unchanged`, changed bytes under the same version 409 with the raise-the-version message, a higher version `added`, and `/capability-packages/rulesets` listed `local/ember-roads` with versions 1, 2. - Agents panel with no agents installed: the **Rules** section showed the imported ruleset with "Imported file, version 1, 2". **Import agents** offered **Game Mode ruleset**. A picked file opened the review (id `local/ember-roads`, version, license, coverage, how checks roll, Game Master text), and **Import** showed "Imported Ember Roads, version 3." - Setup wizard: the **Rules** choice listed the ruleset with an "Imported file" line, and with **Tactical** picked the note read "Battles run on Marinara's Tactical combat, the Combat Preference picked above." - A game created on the ruleset pinned the highest stored version. Removing the ruleset then asked twice, the second time saying "1 game plays on this ruleset", and **Cancel** kept every version. - With **Allow custom Agent imports** off: import answered 403, `/game/create` on the ruleset answered `ruleset_imports_disabled`, and the wizard's World step showed no **Rules** choice. - At 375 px the review dialog was full width with no horizontal overflow (live geometry, not a screenshot). Still to verify by hand: - Manually import a ruleset file, read the review, and confirm it appears under **Rules** and in the setup wizard. - Manually edit the file without raising its version, import again, and confirm the refusal tells you to raise the version. - Manually turn **Allow custom Agent imports** off and confirm the imported ruleset leaves the wizard while a game already on it still rolls checks. - Manually remove an imported ruleset that a game uses and confirm the second confirmation names the number of games. - Manually add a real GitHub repository that has a `rulesets` folder (needs `ENABLE_CUSTOM_AGENT_REPOS=true`); the download against live GitHub was not exercised, only an in-memory archive through the real fetch path. - Manually verify light mode and a phone-width viewport for the review dialog and the repository preview. ## 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) Docs touched: `CHANGELOG.md`, `docs/CONFIGURATION.md` (custom agent repositories), `docs/game/getting-started.md` (Choosing rules), new `docs/extending/writing-rulesets.md`, the plan. The `[docs-i18n]` follow-up is batched for the ruleset slices. ## UI evidence (if applicable) To be added by a human: the **Rules** section, the import review dialog, and the repository preview with rulesets, in light, dark and phone width. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Import custom Game Mode rulesets from JSON files or supported repositories. - Review ruleset details, coverage, licensing, versions, and validation results before installation. - Manage installed rulesets from the Agents panel, including filtering and removal. - Use repository-provided rulesets alongside agent definitions. - Preserve the exact ruleset version used by existing games. - Game setup identifies the selected Combat Preference when a ruleset lacks combat coverage. - Control custom imports through the Agent import setting. - **Documentation** - Added a ruleset authoring guide, example ruleset, and JSON Schema. - Expanded guidance for custom repository rulesets and importing workflows. <!-- 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:16:55 +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#7144
No description provided.