diff --git a/scripts/test-tool-descriptions.mjs b/scripts/test-tool-descriptions.mjs index 73fe01de4..a750a6559 100644 --- a/scripts/test-tool-descriptions.mjs +++ b/scripts/test-tool-descriptions.mjs @@ -15,6 +15,8 @@ const { dmTurnTools } = await import("../src/lib/dm/turn.ts"); const { readCardTool } = await import("../src/lib/dm/prep-card-tool.ts"); const { runPreparedEncounterTool } = await import("../src/lib/dm/prepared-encounter-tool.ts"); const { completeBeatTool, recallStoryTool } = await import("../src/lib/dm/prompt.ts"); +const { AI_NUMBER_REFUSAL } = await import("../src/lib/dm/ai-boundary.ts"); +const { DM_SYSTEM, ENCOUNTER_RULES } = await import("../src/lib/dm/prompt-rules.ts"); let passed = 0; function test(name, fn) { @@ -147,6 +149,10 @@ const MUST_KEEP = { take_action: [/a character or an enemy/], "take_action.enemyId": [/Dash/, /Disengage/, /Dodge/, /Escape/, /GAME STATE/], "pass_time.water": [/half/, /none/], + // Issue #915, ruling 3: a request_roll is the roll of the character it + // names, and harm nobody at the table rolls is dice. + request_roll: [/a character's own dice/], + "apply_damage.amount": [/character's own damage total/, /request_roll/], }; test("what the engine reads survives the compact cut", () => { @@ -157,6 +163,32 @@ test("what the engine reads survives the compact cut", () => { } }); +// Issue #915, ruling 3. A request_roll with a characterId is that character's +// roll, the one who would pick up the dice at a table. The words the model +// reads used to offer it as a second way to roll harm ("roll it first with +// request_roll kind damage and send that total"), and a trap's damage rolled +// that way is stored as the roll of the character it lands on. So no text +// about harm or healing by hand sends the model to request_roll: the rule, +// both refusals and apply_damage's own fields offer dice. +test("harm and healing by hand are dice in every text the model reads, and a request_roll is its character's own roll", () => { + for (const what of ["damage", "healing"]) { + const { error } = AI_NUMBER_REFUSAL(what); + assert.match(error, /send dice \("\d+d\d+(?:\+\d+)?"\) instead of amount/, `the ${what} refusal offers dice`); + assert.doesNotMatch(error, /request_roll/, `the ${what} refusal offers no roll of a character's`); + } + // The one rule on harm by hand is a fight rule; out of a fight the tools' + // own first sentences carry it (MUST_KEEP above). + const byHand = ENCOUNTER_RULES.split("\n").find((line) => line.includes("you apply by hand")); + assert.ok(byHand, "the fight rules say how harm by hand is rolled"); + assert.match(byHand, /send dice \("2d6"\) and it rolls them; a number of your own is refused\./); + assert.match(byHand, /request_roll is the roll of the character it names/); + assert.doesNotMatch(`${DM_SYSTEM}\n${ENCOUNTER_RULES}`, /total it rolled this turn|roll it first/, "no rule offers a roll made first"); + // Where the model fills in whose roll it is, the full words say whose it is not. + assert.match(field("request_roll", "characterId").full, /Who rolls, never who a trap or hazard harms./); + // apply_damage takes a rolled total as a character's own roll only. + assert.doesNotMatch(field("apply_damage", "amount").full, /the server rolled this turn/); +}); + test("a field several tools share reads the same in each", () => { const SHARED = { atX: ["aoe_damage", "cast_at_enemy", "use_spell_slot"], diff --git a/src/lib/dm/ai-boundary.ts b/src/lib/dm/ai-boundary.ts index 6b430cf83..32027d19f 100644 --- a/src/lib/dm/ai-boundary.ts +++ b/src/lib/dm/ai-boundary.ts @@ -66,11 +66,15 @@ export const AI_CLEAR_REFUSAL = (who: string, condition: string): ToolError => ( // Damage or healing the model sends as a bare number. It must have been // rolled by the server this turn (a request_roll of kind damage, not yet -// applied), or be sent as dice the server rolls now. +// applied), or be sent as dice the server rolls now. The refusal offers the +// dice alone: a request_roll is the roll of the character it names (issue +// 915, prompt.ts requestRollTool), so a trap's damage "rolled first" with the +// id of the character it lands on is stored and shown as that character's +// own roll. export const AI_NUMBER_REFUSAL = (what: "damage" | "healing"): ToolError => ({ error: what === "damage" - ? "Damage is rolled by the server, never written: an attack is enemy_attack or pc_attack, a spell its cast tool, a trap or a fall apply_hazard. For other harm send dice (\"2d6\") instead of amount and the server rolls them, or roll it first with request_roll kind damage and send that total." - : "Healing is rolled by the server, never written: a spell goes through heal with spell, a potion through use_item, hit dice through take_rest. For other healing send dice (\"2d4+2\") instead of amount and the server rolls them, or roll it first with request_roll kind damage and send that total.", + ? "Damage is rolled by the server, never written: an attack is enemy_attack or pc_attack, a spell its cast tool, a trap or a fall apply_hazard. For other harm send dice (\"2d6\") instead of amount and the server rolls them." + : "Healing is rolled by the server, never written: a spell goes through heal with spell, a potion through use_item, hit dice through take_rest. For other healing send dice (\"2d4+2\") instead of amount and the server rolls them.", retry: true, }); diff --git a/src/lib/dm/merged-tool-defs.ts b/src/lib/dm/merged-tool-defs.ts index b5086af2c..7da3d8403 100644 --- a/src/lib/dm/merged-tool-defs.ts +++ b/src/lib/dm/merged-tool-defs.ts @@ -45,7 +45,10 @@ export const applyDamageTool: ToolDef = { }, description: "Several targets from ONE total, each at its share for a reason no save covers (cover, immunity). Instead of characterId or enemyId.", }, - amount: { type: "integer", minimum: 1, maximum: 200, description: "A damage total the server rolled this turn (request_roll kind=damage)." }, + // A total is a character's own roll and nothing else: the harm this + // tool is for (a hazard's, the world's) nobody at the table rolls, + // so it is sent as dice (prompt.ts requestRollTool). + amount: { type: "integer", minimum: 1, maximum: 200, description: "A character's own damage total, rolled this turn (request_roll kind=damage)." }, dice: { type: "string", description: "Dice the server rolls instead ('2d6')." }, fallFeet: { type: "integer", diff --git a/src/lib/dm/prompt-rules.ts b/src/lib/dm/prompt-rules.ts index cb4327e19..3baf8b311 100644 --- a/src/lib/dm/prompt-rules.ts +++ b/src/lib/dm/prompt-rules.ts @@ -167,7 +167,7 @@ function encounterLines(ammunitionTracked: boolean): RuleLine[] { return [ { bullet: false, pieces: [{ text: `Combat rules (an encounter is active):` }] }, { bullet: true, pieces: [{ text: `Enemy HP and AC in GAME STATE are tracked by the server and are authoritative. You cannot wound, drop, or kill an enemy in narration alone. When a player attacks, call pc_attack once with their characterId and attacks: every attack they declared, in order, one entry each with the targetEnemyId and their weapon (or an attack-roll spell by name: the server derives a known spell's dice, beams and scaling itself and takes damage dice from you only for a homebrew spell it cannot read): the server derives their attack bonus from their sheet, rolls to-hit against the enemy's real AC, rolls and applies damage on a hit, and reports the outcome for you to narrate. Never decide yourself whether a player's attack hits. The server also applies everything the character's own features add: fighting styles, magic weapon bonuses, Sneak Attack when its conditions are met, an expanded critical range, and Brutal Critical dice. On an entry, pass twoHanded when they grip a versatile weapon in both hands, smite with a slot level for a paladin's Divine Smite (the server spends the slot), and maneuver with the maneuver's name for a Battle Master (the server validates the pick, spends the Superiority Die, adds it to the right roll, and rolls the target's save for Trip, Menacing, Disarm, and Goading riders). Pass reckless for a barbarian's Reckless Attack, stunningStrike for a monk's Stunning Strike (1 ki on a hit, the server rolls the CON save), nonlethal when a melee attacker means to knock the creature out rather than kill it, and feature with the name of what the attack is made with: "Martial Arts", "Frenzy", "Two-Weapon Fighting" for the bonus-action second weapon, "Flurry of Blows" on each of its strikes, "Action Surge" on each attack of the action it grants, "Horde Breaker", or a subclass's or feat's bonus-action weapon attack by its name (Battle Magic, War Magic, Sudden Strike, Curving Shot, Telekinetic Master); a weapon a subclass feature makes is named as the weapon (a raging Path of the Beast barbarian's bite, claws or tail, a Soulknife's psychic blade with feature "Two-Weapon Fighting" for the second blade, a Sun Soul monk's radiant sun bolt), and rapidStrike is a Samurai's Rapid Strike on an attack that has advantage; feature "Whirlwind Attack" or "Volley" is a Hunter's Multiattack, one entry per creature (the first spends the whole action); useInspiration to spend the character's Inspiration for advantage, strokeOfLuck for a 20th level rogue (spent only if the attack misses), openHand ('prone', 'push' or 'no reactions') on an Open Hand monk's Flurry of Blows strike, and hurlThroughHell for a Fiend warlock's hit; the server checks each against the sheet and spends what it costs. Shillelagh, Feral Senses, Foe Slayer, a magic weapon's typed and natural-20 dice, and a weapon coated with basic poison (use_item on the vial) are applied by the server. A knocked-out enemy is out of the fight but alive, and stays down after it: GAME STATE lists who a fight left about, and returning with their enemyId brings one into a later fight as they were. The advantage argument on pc_attack or enemy_attack counts only with advantageSource 'other' and advantageReason naming a circumstance the server cannot see; the server already applies conditions, hiding, invisibility, light and darkvision, cover (walls and creatures), range, Help, flanking, Reckless Attack, Pack Tactics, and every class feature, so never claim those.` }, { text: `Hunter's Mark and Hex ride hits on one creature: the first one the caster attacks after casting, or the one named.`, needs: ["caster"] }, { text: `Invisibility (not Greater Invisibility) ends when the invisible character attacks or casts, and the server removes it.` }, { text: `Guiding Bolt's advantage and the smites' dice are applied and spent by the server.`, needs: ["caster"] }, { text: `Subclass damage riders (Divine Strike, Improved Divine Smite, Agonizing Blast) and magical-attack features are applied by the server automatically; never add their dice yourself.`, needs: ["caster"] }, { text: `When a result mentions extraAttack, that character has swings left: any they declare go as entries of one more pc_attack before their turn ends. Damage an enemy with apply_damage ONLY for harm from a hazard or the environment that is neither an attack nor a spell nor a trap (a falling chandelier, burning oil), with its enemyId and source 'hazard' or 'environment': the server refuses it for anything else. An enemy dies ONLY when a tool result says dead: true, never before, no matter how dramatic the moment. A creature whose Regeneration says it dies only at the start of its turn (a troll) falls at 0 hit points without dying; the server raises it at its turn start unless acid or fire damage landed first, so narrate it collapsing, not dying, until the server reports it dead. Parry and similar monster reactions are taken by the server when they turn a hit into a miss; never narrate a parry the attack result does not report. ${ammunitionTracked ? "Ammunition is tracked: a shot spends a piece, and pc_attack refuses a shot when none is left." : "Ammunition is never tracked: bows, crossbows, and firearms are always assumed supplied, even if older narration claimed otherwise."}` }, { text: `A player who closes in to strike an enemy out of reach gets approach true on that attack's entry: the server walks them beside it first.`, needs: ["map"] }, { text: `When they say the attacks end their turn, pass endTurn true on the pc_attack call instead of calling end_turn after it.` }] }, - { bullet: true, pieces: [{ text: `Damage and healing you apply by hand (apply_damage, heal without a spell) are the server's to roll: send dice ("2d6") and it rolls them, or send a total it rolled this turn (request_roll kind damage); a number of your own is refused. A condition that binds a creature (blinded, charmed, deafened, frightened, grappled, incapacitated, paralyzed, petrified, poisoned, prone, restrained, stunned, unconscious) lands through set_condition only with saveAbility and saveDc: the server rolls the save first and lays it on a failure. A binding condition a save, a duration or a spell keeps is never cleared by hand; it ends by itself or through the cure cast for it.` }] }, + { bullet: true, pieces: [{ text: `Damage and healing you apply by hand (apply_damage, heal without a spell) are the server's to roll: send dice ("2d6") and it rolls them; a number of your own is refused. request_roll is the roll of the character it names ("roll your damage"), never the dice of a trap, a hazard or anything else that harms them. A condition that binds a creature (blinded, charmed, deafened, frightened, grappled, incapacitated, paralyzed, petrified, poisoned, prone, restrained, stunned, unconscious) lands through set_condition only with saveAbility and saveDc: the server rolls the save first and lays it on a failure. A binding condition a save, a duration or a spell keeps is never cleared by hand; it ends by itself or through the cure cast for it.` }] }, { bullet: true, pieces: [{ text: `When a monster forces a saving throw on ONE character, call cast_at_player: the server rolls that character's save from their real sheet and applies the damage and condition itself. Pass casterEnemyId with enemyAbility or spell by the name its block uses: it is that enemy's action, the save, DC, dice and condition come from the block or the spell whatever you send, a Recharge ability is refused until it recharges, and a spell must be on its list and spends its slot. Several characters caught at once go through aoe_damage. NEVER apply a condition with set_condition when a saving throw should have decided it, and never decide a character's save yourself.` }] }, { bullet: true, pieces: [{ text: `Harm from the environment to characters (a fall, a sprung trap, a gout of flame, a collapsing floor, running out of air) goes through apply_hazard, never through numbers you invent (an enemy caught in a trap, a fall or a hazard of your own goes in enemyIds, and the server rolls its save from its stat block): pass type 'falling' with the feet, type 'trap' with a severity (setback, dangerous, deadly), type 'generic' with your own dice, save, and DC, type 'suffocation'/'drowning' with roundsWithoutAir for a character with no air, or type 'extreme_cold'/'extreme_heat' with the hours of exposure; list every character caught. The server sets falling damage at 1d6 per 10 feet, scales a trap's save DC and damage to each victim's level, derives from Constitution how long a suffocating character lasts before dropping to 0 HP, rolls each save, and applies the result. This is how the hidden trap check_notice warned you about actually goes off. Never decide a drowning character's fate yourself; let the tool say when they go down. Healing spells go through heal with the spell name and slot level, not a number you chose: the server rolls the real dice and adds the caster's modifier. Spell damage is derived too, so a cantrip grows with its caster's level and an upcast spell scales, without you working it out.` }] }, { bullet: true, pieces: [{ text: `Enemies act through enemy_attack: name the enemy, its attack, and the target character. The server rolls to-hit from the enemy's real stat block against the target's real AC and applies real damage, and on a hit it also resolves the rider the attack prints (a wolf's Strength save or prone, a spider's poison save, a grapple), so never follow it with set_condition or cast_at_player for that rider. Never use request_roll for an enemy's attack or damage, and never invent an enemy's numbers.` }] }, diff --git a/src/lib/dm/prompt.ts b/src/lib/dm/prompt.ts index 50bda18a9..64d69a72e 100644 --- a/src/lib/dm/prompt.ts +++ b/src/lib/dm/prompt.ts @@ -1578,19 +1578,36 @@ function tableHazardLine(campaignId: string): string { // The request_roll tool. characterId must match a party characterId from // GAME STATE; the server computes the modifier from the sheet, so the model // never supplies raw numbers except the DC. +// +// One tool, one meaning (issue 915): the roll is the roll of the character it +// names, the one who would pick up the dice at a table. "Aria, roll your +// damage" is Aria's roll; a trap's dice are never handed to the character +// they land on. Harm done to a character is rolled by the tool that deals it +// (apply_hazard, cast_at_player, apply_damage with dice), which names what +// rolled. The roll cannot tell the two intents apart once it is stored, so +// the words here have to. "A character's own dice" rides in the tool's first +// sentence, the one a compact call keeps (src/lib/dm/tool-profiles.ts). +// characterId says whose roll it is not in a second sentence, which a +// compact call drops: a 16K window had no room for it, and with it in the +// first the players' words no longer opened a group on the first call +// (scripts/test-tool-profiles.mjs). The trimmed tool set has a token budget +// too (scripts/test-prompt-window.mjs), so those words are paid for by a +// sentence targetEnemyId used to end on ("A party character's damage goes +// through pc_attack or the spell tools"), which the server says itself when +// a model tries it (src/lib/dm/invoke-roll.ts). export const requestRollTool = { type: "function", function: { name: "request_roll", description: - "Roll dice for an uncertain outcome; the server takes the modifier from the sheet.", + "Roll a character's own dice for an uncertain outcome; the server takes the modifier from the sheet.", parameters: { type: "object", additionalProperties: false, properties: { characterId: { type: "string", - description: "Exact characterId from GAME STATE.", + description: "Exact characterId from GAME STATE. Who rolls, never who a trap or hazard harms.", }, kind: { type: "string", @@ -1655,7 +1672,7 @@ export const requestRollTool = { targetEnemyId: { type: "string", description: - "damage only, in combat, by an NPC with no sheet: the enemy struck (enemyId). Exact enemyId from GAME STATE; the server applies the total, no apply_damage after. A party character's damage goes through pc_attack or the spell tools.", + "damage only, in combat, by an NPC with no sheet: the enemy struck (enemyId). Exact enemyId from GAME STATE; the server applies the total, no apply_damage after.", }, reason: { type: "string",