world-contract

The boundary between the simulation (tosijs-3d) and an external driver (an AI narrative engine, a scripted demo, anything). The simulation is the authority on physical and systemic reality; the driver decides what any of it means. These two halves never call each other's functions — they share a serializable WorldState, a stream of best-effort SimulationEvents, and the WorldApi surface below.

Hard rules baked into these types

The driver belongs OFF-THREAD — and this contract is already the membrane

A GM/narrative driver thinks: a planner, a search, an LLM round-trip. That's 100ms–2s, which inline is 20–200 dropped frames. It must never run on the frame thread. (See PERF-DESIGN.md — this is the one acceleration case we've approved; terrain's worker was measured and rejected.)

The seam is latency tolerance, not CPU cost, and it is exactly the seam these rules already draw. Every hard rule above, written for decoupling, turns out to be precisely what makes a worker correct:

Two shape notes, because they decide the plumbing:

Testing a driver: THREE parts, and dead air is the point

A driver can be developed and tested as a black box, with no renderer and no browser — the boundary is serializable, so nothing about it needs a 3D engine.

But be precise about the determinism, because the useful property is not the obvious one. The driver is LLM-backed and therefore stochastic. Everything else is seeded — the store, the player persona, the transport's losses. So the stimulus is exactly reproducible even though the response is not, which is what makes testing a stochastic system tractable at all: the non-determinism is confined to one place, and any variance in outcome is attributable to the model rather than to a harness that was also wandering.

Consequences for how you assert:

The rig needs three parts, and the middle one is the whole job:

  1. The real store — don't fake the mechanics. world-store is pure, deterministic and Babylon-free precisely so it can run headless. A hand-written "fake simulation" would drift from it and then lie to you.

  2. Synthetic PLAYER PERSONAS — fake the player, because that's the real input. The store on its own emits nothing. What a driver actually consumes is a stream produced by somebody blundering about: walking past the clue eleven times, talking to the wrong NPC, getting bored, ignoring a nudge entirely. That distribution — the pacing, the backtracking, the not engaging — is the input, and it is the thing that must be synthesised. Seeded and reproducible; knobs for engagement, attention, persistence, goal-directedness.

    These personas ARE the "artificial stupidity" work (AI-DESIGN), pointed at testing. A GM that only copes with a competent player is pointless — a GM exists for the player who is lost.

  3. A HOSTILE transport. The membrane is lossy and async by contract, so the double must drop, delay and reorder events, and answer getState from a snapshot the world has already moved past. That isn't a stress test, it's a conformance test: a driver that only works against a perfect synchronous stream will break the instant it's in a worker, and a friendly mock will never show you.

Dead air is a first-class test case. Because events are commitments, not proximity, a player who blunders past the clue a dozen times generates no events at all. The driver must infer stuckness from silence plus state queries — which is exactly why WorldState.now crosses the boundary. That is the hardest driver behaviour there is, and a harness that replays canned event logs can never produce it: the interesting signal is the absence of one. Only a persona that nearly engages generates it.

Assert in both directions, or it's a demo rather than a test:

And in reverse, to prove the sim is the sandbox it claims to be: a scripted adversarial driver pushing intents that are stale, impossible, contradictory, aimed at dead entities, or simply flooding — none of which may corrupt anything, because intents are advisory.