mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5921] [MERGED] fix(dice): one shared dice-notation grammar for every roller #6993
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6993
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5921
Author: @kolacheee
Created: 9/7/2026
Status: ✅ Merged
Merged: 9/7/2026
Merged by: @kolacheee
Base:
staging← Head:fix/dice-notation-consolidation📝 Commits (10+)
149c49bfix(dice): consolidate dice notation onto one shared grammar396cb68Merge remote-tracking branch 'origin/staging' into fix/dice-notation-consolidation34ef1c1fix(dice): hold the modifier to the same exactness bar as count and sides857dad4Merge remote-tracking branch 'origin/staging' into fix/dice-notation-consolidation45b6b97docs(changelog): narrow the dice grammar claim to the readers that moved9ab3793fix(dice): the sum is the dice as thrown, not total minus modifierb8441cefix(dice): hold the whole range of totals to the exactness bar, not just the modifiere050af6docs(dice): unsnarl the header's garden-path sentence and teach the tool its own headlinee0a4ca2fix(dice): a clamped roll names the dice it threw, not the ones asked for (#5921)0af0530docs(changelog): the clamp belongs to the dice menu, not the typed /roll📊 Changes
10 files changed (+871 additions, -86 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
docs/game/dice-and-skill-checks.md(+1 -1)📝
packages/client/src/lib/game-tag-parser.ts(+22 -20)📝
packages/client/src/lib/slash-commands.ts(+11 -18)📝
packages/server/src/services/game/dice.service.ts(+18 -28)📝
packages/server/src/services/tools/tool-executor.ts(+20 -17)📝
packages/shared/src/features/function-calls/tools/roll-dice/manifest.ts(+2 -2)📝
packages/shared/src/index.ts(+1 -0)➕
packages/shared/src/utils/dice-notation.ts(+168 -0)➕
scripts/regressions/dice-notation.regression.ts(+627 -0)📄 Description
Linked issue
Closes #
No issue is filed for this yet — one should be opened before this PR is submitted. This is groundwork for the Game Mode dice work being planned under #5798; it does not close that issue.
Why this change
d20was legal in/roll, in the client's/rollslash command and in the GM's[skill_check:]tag — and an error in theroll_dicetool, which demanded an explicit count.docs/game/dice-and-skill-checks.mdalready promises players the permissive form, so the tool was the odd one out against both the rest of the app and its own documentation.What changed
packages/shared/src/utils/dice-notation.tsownsparseDiceNotation,isDiceNotation, the shared ceilings androllParsedDice. All four readers import it:dice.service(the/rollroute), theroll_dicetool executor, the client slash command, and the client GM tag parser.roll_diceaccepts a bared20. This is the point of the change — the permissive form is what every other path already shipped.roll_dicetrims its notation, so" 2d6 "rolls instead of erroring, and the echoed notation and display carry the trimmed text.roll_dice's invalid-notation hint now reads2d6, d20+5, 3d8-2, so it stops teaching a die count the tool no longer requires.99999999999999999999d6) is now refused as invalid notation./rollused to accept it and silently clamp to 100 dice, printing the absurd notation beside 100 rolls.0d6and1d0now produce the invalid-notation error instead of a separate out-of-range one. Unreachable through the/rollroute, whose request validation already rejected both.roll_dice, fromDice values out of range (1-100 dice, 2-1000 sides)toInvalid dice notation …plus the hint. Refused before, refused after — an error-message reclassification, not a verdict change — but the commit frames the rule as a/rollchange only./rollclamps an oversized roll (the docs promise that),roll_dicerefuses it and keeps its two-face floor so it never reports dice it did not throw, and the skill-check tag refuses a label past the ceilings. A dice label still refuses a modifier —1d20+3names no dice — now by comparing against the parsed NdM half rather than by carrying a narrower regex.{{roll:NdM}}macro inmacro-engine.tshas its own ceilings (1000 dice, 1e6 faces), requires a count, and uses a seeded roller, so folding it in would change macro output;AnimatedDiceRoll's regex is an unanchored prefix match that reads a face count off arbitrary label text rather than a grammar.scripts/regressions/dice-notation.regression.tsdrives one accepted/refused table through the shared grammar and then through three real entry points (dice.service,executeToolCalls,parseGmTags).Evidence this is not a silent behaviour change
An independent check transcribed the four old implementations out of git and drove roughly 90 notations through the old and new code side by side, with
Math.randomreplaced by a seeded generator reset before each pair so roll sequences and RNG call counts are directly comparable. The corpus covered baredN, case, leading/trailing/interior whitespace, leading zeros, every modifier sign, both ceilings either side, the exact-integer boundary either side, 20- and 40-digit values, fullwidth and Arabic-Indic digits, NUL bytes, and about 30 malformed forms./rollservice and theroll_dicetool differ on 17 and 56 rows respectively, and every one of those rows is one of the changes listed above. No undisclosed verdict flip was found on any call site.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
What was run in the review worktree, for information — the boxes above are still yours to tick after you have run and seen this yourself:
pnpm checkexited 0 (full chain through the production build).pnpm version:checkreported in sync for 2.4.5.dice-notation,dice-display, and the game / tool / tag regression lanes passed.gallery-previews.regression.tspasses every assertion, then its cleanup block fails removing a Windows temp directory. It imports only Node builtins, touches nothing this PR changes, and reproduces without this branch.Still to verify by hand in a real browser:
/roll d20,/roll 2d6+3,/roll 101d20and/roll 1d1001in a chat — the first two roll, the last two clamp to the ceilings the way they did before.roll_dicetool in a chat with Function Calling on: ask for a bared20(now rolls), a padded" 2d6 "(now rolls, echoing the trimmed text), and500d6(still refused, not silently clamped).[skill_check:]tag still renders its dice card exactly as before.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG.mdgains one entry. No version-bearing file is touched. No file underdocs/is added, renamed or deleted, so nothing needs mirroring ondocs-i18n— but see the doc-drift item below, which is a one-sentence edit somebody should make.UI evidence (if applicable)
No UI changes. The only user-visible strings that moved are the
roll_diceerror and hint text inside a tool result.Known limitations, named here rather than left for review to find
/rollslash command has no regression entry point. It is the fourth reader the commit names, and it is the only one the new regression cannot reach. Deleting its ceiling check — the guard whose own comment says it exists so/roll 99999999d6does not lock up the render thread — leaves the suite passing.slash-commands.tsis already importable from a regression (conversation-game-slash.regression.tsdoes it), so a fourth loop over the existing table would close this in roughly fifteen lines. Not done in this PR.docs/game/dice-and-skill-checks.mdpromises that a request over the limits is trimmed instead of refused. That is still true of everything reachable in practice, but no longer true of counts or face values past the exact-integer limit, which are now refused outright. It needs a clause, and this PR does not add one.packages/shared. There are now two module-scopeMAX_DICE_COUNT/MAX_DICE_SIDESpairs with different values — the shared grammar's exported 100/1000, and the macro engine's private 1000/1e6 — and the package barrel re-exports across both files. It resolves correctly today (checked), but if anyone ever exports the macro pair, the ambiguous name is dropped silently rather than erroring. Renaming the macro constants would remove the trap.roll_dicemanifest description was left alone on purpose. It still teaches2d6, 1d20+5, 3d8-2and does not advertise the bared20the tool now accepts. Changing prompt-surface text in a consolidation change felt out of scope; flagging it so the choice is visible rather than accidental.Summary by CodeRabbit
New Features
roll_dicetool now accepts bare notation such asd20.Bug Fixes
Documentation
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.