[PR #8500] [MERGED] Let Browser Extensions add their own dice notation to /roll (part 3 of #8489) #8638

Closed
opened 2026-11-07 16:46:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8500
Author: @kolacheee
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @kolacheee

Base: staging ← Head: claude/project-thread-mhcusi


📝 Commits (2)

  • a13266f Let Browser Extensions register dice formats for /roll
  • 6be8c6d Treat a blank dice-format description or read text as absent

📊 Changes

9 files changed (+797 additions, -5 deletions)

View changed files

📝 docs/extending/personal-extensions.md (+35 -0)
📝 docs/extending/writing-personal-extensions.md (+2 -1)
📝 packages/client/src/components/layout/PersonalExtensionInjector.tsx (+33 -1)
➕ packages/client/src/lib/personal-extension-dice-formats.ts (+219 -0)
📝 packages/client/src/lib/slash-commands.ts (+23 -1)
📝 packages/server/src/routes/personal-extensions.routes.ts (+139 -1)
📝 packages/shared/src/types/personal-extension.ts (+25 -0)
➕ scripts/regressions/extension-dice-formats.regression.ts (+320 -0)
📝 scripts/regressions/extension-security.regression.ts (+1 -1)

📄 Description

Linked issue

Part of #8489. It follows #8495 and #8497 and is item 3 of the plan posted on the issue: a small hook so an extension can bring a dice system (for example Genesys-style narrative dice) to /roll without being able to choose its own faces.

Why this change

The issue asks for extension-defined dice formats. Marinara's plain rollers only read NdM and keep/drop pools, so any other notation is refused. Letting extensions roll on their own would let them pick the faces; this keeps the throwing in Marinara.

What changed

  • Sandboxed Browser Extensions get marinara.dice.registerFormat({ id, label, description?, parse, read }).
    • parse(notation) returns null, or { dice: [sides, ...] } naming the dice to throw (1-100 dice, 2-1000 sides). Anything else it returns stays in the sandbox and comes back to read as plan.
    • Marinara throws those dice with the shared secure roller and passes the faces to read({ notation, dice, rolls, plan }), which returns { total, text?, kept? }.
    • Limits: 4 formats per extension, 100-character notation, 200-character text, 2 seconds for each answer.
  • /roll asks the registered formats, in registration order, only for notation the shared grammar does not read. 2d6, 4d6kh3 and even a refused 500d6 never reach an extension. The first format whose parse returns dice rolls it.
  • The host re-checks everything the sandbox sends back (dice, faces, total, text, kept). The extension's text and label are posted as escaped plain text, so they can't add links, images, markup or HTML to the chat message.
  • Formats are removed when the extension stops or its code changes, and any open request is answered with nothing instead of waiting out the timeout.
  • Browser Extension API version is now 6, so extensions can feature-detect the hook.
  • Scope: /roll in the browser. The GM's roll_dice tool and other server-side rolls keep the built-in notation and ruleset dice, and full-page extensions don't get the hook.

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

Client and server typecheck clean. New extension-dice-formats regression runs the real sandbox Worker source and the host registry. It covers registering and validating formats, the host throwing the named dice and the extension only seeing those faces, refused dice/faces/totals/text/kept on both sides, stopping an extension mid-request, and /roll escaping the extension's text and never sending NdM to an extension. Also passing: extension-security (API version assertion moved to 6), extension-token-estimator, extension-ipc, dice-notation, roleplay-commands.

Manual verification notes

  • Manually verify that the narrative-dice example in docs/extending/personal-extensions.md, imported as an External Extension, makes /roll 2 boost 1 setback post the faces, total and text.
  • Manually verify /roll 2d6 still rolls normally with that extension enabled.
  • Manually verify that disabling the extension makes /roll 2 boost show "Invalid dice notation" again.

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)

docs/extending/personal-extensions.md gains an "Add a dice format" section, and docs/extending/writing-personal-extensions.md gains one API table row. Both are added to the docs-i18n catch-up issue #8499.

UI evidence (if applicable)

No new UI. An extension roll posts as an ordinary narrator message, without the dice card (the card draws one die shape per roll, which doesn't fit mixed or symbol dice).


🔄 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/8500 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `claude/project-thread-mhcusi` --- ### 📝 Commits (2) - [`a13266f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a13266f108ab9adf62b1e5c7bfcb1109596471c3) Let Browser Extensions register dice formats for /roll - [`6be8c6d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6be8c6d25e40bb08ac464068819f3ce2c0d62c73) Treat a blank dice-format description or read text as absent ### 📊 Changes **9 files changed** (+797 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/extending/personal-extensions.md` (+35 -0) 📝 `docs/extending/writing-personal-extensions.md` (+2 -1) 📝 `packages/client/src/components/layout/PersonalExtensionInjector.tsx` (+33 -1) ➕ `packages/client/src/lib/personal-extension-dice-formats.ts` (+219 -0) 📝 `packages/client/src/lib/slash-commands.ts` (+23 -1) 📝 `packages/server/src/routes/personal-extensions.routes.ts` (+139 -1) 📝 `packages/shared/src/types/personal-extension.ts` (+25 -0) ➕ `scripts/regressions/extension-dice-formats.regression.ts` (+320 -0) 📝 `scripts/regressions/extension-security.regression.ts` (+1 -1) </details> ### 📄 Description ## Linked issue Part of #8489. It follows #8495 and #8497 and is item 3 of the plan posted on the issue: a small hook so an extension can bring a dice system (for example Genesys-style narrative dice) to `/roll` without being able to choose its own faces. ## Why this change The issue asks for extension-defined dice formats. Marinara's plain rollers only read `NdM` and keep/drop pools, so any other notation is refused. Letting extensions roll on their own would let them pick the faces; this keeps the throwing in Marinara. ## What changed - Sandboxed Browser Extensions get `marinara.dice.registerFormat({ id, label, description?, parse, read })`. - `parse(notation)` returns `null`, or `{ dice: [sides, ...] }` naming the dice to throw (1-100 dice, 2-1000 sides). Anything else it returns stays in the sandbox and comes back to `read` as `plan`. - Marinara throws those dice with the shared secure roller and passes the faces to `read({ notation, dice, rolls, plan })`, which returns `{ total, text?, kept? }`. - Limits: 4 formats per extension, 100-character notation, 200-character text, 2 seconds for each answer. - `/roll` asks the registered formats, in registration order, only for notation the shared grammar does not read. `2d6`, `4d6kh3` and even a refused `500d6` never reach an extension. The first format whose `parse` returns dice rolls it. - The host re-checks everything the sandbox sends back (dice, faces, total, text, kept). The extension's text and label are posted as escaped plain text, so they can't add links, images, markup or HTML to the chat message. - Formats are removed when the extension stops or its code changes, and any open request is answered with nothing instead of waiting out the timeout. - Browser Extension API version is now 6, so extensions can feature-detect the hook. - Scope: `/roll` in the browser. The GM's `roll_dice` tool and other server-side rolls keep the built-in notation and ruleset dice, and full-page extensions don't get the hook. ## 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` Client and server typecheck clean. New `extension-dice-formats` regression runs the real sandbox Worker source and the host registry. It covers registering and validating formats, the host throwing the named dice and the extension only seeing those faces, refused dice/faces/totals/text/kept on both sides, stopping an extension mid-request, and `/roll` escaping the extension's text and never sending `NdM` to an extension. Also passing: extension-security (API version assertion moved to 6), extension-token-estimator, extension-ipc, dice-notation, roleplay-commands. ### Manual verification notes - Manually verify that the narrative-dice example in `docs/extending/personal-extensions.md`, imported as an External Extension, makes `/roll 2 boost 1 setback` post the faces, total and text. - Manually verify `/roll 2d6` still rolls normally with that extension enabled. - Manually verify that disabling the extension makes `/roll 2 boost` show "Invalid dice notation" again. ## 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) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/extending/personal-extensions.md` gains an "Add a dice format" section, and `docs/extending/writing-personal-extensions.md` gains one API table row. Both are added to the docs-i18n catch-up issue #8499. ## UI evidence (if applicable) No new UI. An extension roll posts as an ordinary narrator message, without the dice card (the card draws one die shape per roll, which doesn't fit mixed or symbol dice). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:46:09 +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#8638
No description provided.