`apply_delta` records three outcomes for every change the model sends: `applied`, `clamped`, and `rejected`. Everything downstream read only `applied`. A refused change reached the player as an ordinary chip, and reached the model on the next turn as a change that had succeeded. Five parts: - `Action.world_changes` reads `clamped` and `rejected` beside `applied`. Accepted stats carry a `clamped` flag; refusals become `kind: "rejected"` entries. The `fix` key is present only when the engine wrote one, because this property runs for every action of every list response. - The UI separates the three outcomes. A clamp to a standstill reads `no change - at its limit` on a dashed chip, a partial clamp is marked `(limited)`, and a rejection carries its reason. Dashed and dimmed rather than red: a refused change means the rules are working. - The goals line names the milestone id, as `milestones.<id>`. The ids appeared nowhere in the prompt before, so the model could not send one. - Each rejection, and each clamp that moved nothing, builds a `fix` string from the stat definition at the point of refusal. `render_refusals()` renders them into the next prompt above `EMIT_REMINDER`. - `_history_text` replays `applied_delta()` instead of the sent delta, so a past turn's state block shows only what the engine accepted. A clamp that reduced a change but still moved the value reports nothing. If you tell a model its 80 damage became 30, it can treat the shortfall as a debt and send the remaining 50 next turn, which is the swing `max_delta_per_turn` prevents. In the demo scenario, `pokemon_left` becomes `pokemon_fainted` (`type: counter`, `initial: 0`). Starting at the ceiling turned a wrong-signed delta into a silent no-op; counting up puts the wrong sign on the counter rule, which refuses it out loud. The instructions also now ask for `world.turn`, which sat at 0 for a whole playtest. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PacdRuPXSkQQy4ZYdH32hF
46 lines
854 B
Python
46 lines
854 B
Python
"""Phase 12: RPG world state.
|
|
|
|
The AI proposes stat and milestone deltas, and this module validates and clamps
|
|
them against a scenario's `stat_schema`.
|
|
"""
|
|
|
|
from .engine import (
|
|
EMIT_REMINDER,
|
|
EMIT_RULE,
|
|
applied_delta,
|
|
apply_delta,
|
|
apply_override,
|
|
band_label,
|
|
extract_delta,
|
|
has_schema,
|
|
instantiate,
|
|
npc_name,
|
|
npc_triggers,
|
|
reconcile,
|
|
refusals,
|
|
render_delta_block,
|
|
render_reference,
|
|
render_refusals,
|
|
render_state_section,
|
|
)
|
|
|
|
__all__ = [
|
|
"EMIT_REMINDER",
|
|
"EMIT_RULE",
|
|
"applied_delta",
|
|
"apply_delta",
|
|
"apply_override",
|
|
"band_label",
|
|
"extract_delta",
|
|
"has_schema",
|
|
"instantiate",
|
|
"npc_name",
|
|
"npc_triggers",
|
|
"reconcile",
|
|
"refusals",
|
|
"render_delta_block",
|
|
"render_reference",
|
|
"render_refusals",
|
|
"render_state_section",
|
|
]
|