`backend/app/worldstate/engine.py` held 918 lines covering four separate jobs: reading a scenario's schema, parsing the block the model writes, applying a change within the schema's limits, and rendering state as prompt text. Each is now its own module, the largest 418 lines. An AST comparison against the old file confirms all 29 definitions are identical. No call site changes, because `worldstate/__init__.py` exports the same names it did before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014Dix4oGV3njgWRdu7P9t6r
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""Phase 12: RPG world state.
|
|
|
|
The scenario carries a `stat_schema`, which is the template: which stats exist,
|
|
their bands and rules, and the milestones. An adventure carries a live
|
|
`world_state` instantiated from it. Each turn the AI proposes a delta holding
|
|
only what changed. `apply_delta` decides what the delta is allowed to do. It
|
|
clamps values to min and max, caps the change per turn, enforces cooldowns, and
|
|
makes milestones sticky.
|
|
|
|
Nothing here raises on bad AI output. A malformed delta returns `{}` and the turn
|
|
continues, the same way a broken script never breaks a turn.
|
|
|
|
The work is split four ways, and each module reads on its own:
|
|
|
|
schema what a scenario's `stat_schema` allows, and building state from it
|
|
parse the block the model writes, and reading it back
|
|
apply every write to world state, and the limits it is held to
|
|
render turning state and schema into prompt text
|
|
|
|
Import the names from this package rather than from those modules. The split is
|
|
an implementation detail, and the names below are the interface.
|
|
"""
|
|
|
|
from .apply import apply_delta, apply_override
|
|
from .parse import (
|
|
EMIT_REMINDER,
|
|
EMIT_RULE,
|
|
applied_delta,
|
|
extract_delta,
|
|
refusals,
|
|
render_delta_block,
|
|
render_refusals,
|
|
)
|
|
from .render import render_reference, render_state_section
|
|
from .schema import band_label, has_schema, instantiate, npc_name, npc_triggers, reconcile
|
|
|
|
__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",
|
|
]
|