This section documents ONLY the generic engine (engine/ folder). It excludes any OSRIC domain specifics. Use it to understand how to add or modify engine primitives without leaking domain concerns.
Included:
- Command DSL (
authoring/dsl.ts) - Command execution pipeline & stages
- Result & failure model
- Effects buffering & commit semantics
- Deterministic RNG & snapshot semantics
- Batch (atomic & non-atomic) execution
- Simulation & diff
- Integrity hashing & immutability enforcement
- Public API boundaries & barrel exports
Excluded (see domain docs):
- Domain entities or store shapes
- Domain-specific effects (e.g. battle mirroring)
- Scenario scripts & domain commands
The engine orchestrates a single linear stage sequence per command: validate -> load -> calc -> mutate -> emit. Each stage can register multiple rule functions. Rule functions return disjoint object fragments merged into an immutable accumulator. Any fragment key collision is an engine failure (DUPLICATE_RESULT_KEY). Effects are staged in a buffer and only committed if the command (or atomic batch) succeeds.
command(key)DSL builderEnginefacade exposingexecute,simulate,batch- Result helpers:
success,domainFail,engineFail - Types:
CommandOutcome,Effect, etc.
- RNG seeded at engine construction; every command advances RNG once at start for sequence stability.
- Simulation and atomic rollback restore RNG state exactly.
- Hash-based integrity guard detects mutation of the accumulator.
- Atomic: roll back store + RNG on first failure.
- Non-Atomic: retain successes;
oktrue if at least one success. - Effects aggregated from successful commands only.
simulate(key, params) runs the identical pipeline against a deep-clone snapshot of the store and RNG state, returning { result, diff, effects } with no persistence. Diff identifies created/mutated/deleted entities by sparse heuristic (arrays of objects with id).
- Define core primitive in
engine/core/*with unit tests (CE-* style id optional if extending sequence). - Integrate into executor or facade as needed.
- Expose via barrel only if intended for public consumption.
- Update redesign docs if the conceptual surface expands.
- Generic plugin hooks
- Parallel rule execution