Tighten CultMesh state access ergonomics contract

This commit is contained in:
Meta Vens 2026-06-27 13:28:21 +01:00
commit 9948d5eeca
2 changed files with 141 additions and 2 deletions

View file

@ -11,6 +11,14 @@ C# clients should read like domain code:
```csharp
var aetheria = verse.Aetheria();
var currentDockingBay = await aetheria.Current
.DockingBay
.LatestAsync();
using var inventorySubscription = aetheria.Current
.Inventory
.Watch(inventory => RenderInventory(inventory));
await aetheria.Entity(actorEntityId)
.Pilot
.MoveAsync(CultMesh.Vec2(input.X, input.Y));
@ -31,6 +39,14 @@ TypeScript clients should have the same semantic shape:
```ts
const aetheria = verse.aetheria();
const dockingBay = await aetheria.current()
.dockingBay()
.latest();
const stopInventory = aetheria.current()
.inventory()
.watch(renderInventory);
await aetheria.entity(actorEntityId)
.pilot.move(CultMesh.vec2(input.x, input.y));
@ -85,7 +101,18 @@ The project already has the first layer of primitive sugar:
- Aetheria Eve surfaces persist CultMesh binding/invocation records and keep legacy fields as compatibility mirrors.
- `AetheriaClient`, `AetheriaControl`, and `AetheriaUi` expose ergonomic C# entry points, but the domain facade is still incomplete.
The remaining problem is that the sugar is not yet the only obvious path. There are still public or semi-public seams where clients can fall back into raw envelopes, record keys, ad hoc frame projection, manual state resolution, and locality-specific wiring.
The remaining problem is that the sugar is not yet the only obvious path. There are still public or semi-public seams where clients can fall back into raw envelopes, record keys, ad hoc frame projection, manual state resolution, locality-specific wiring, and renderer-side facade adaptation.
The worst current pattern is not one bad helper. It is a repeated protocol walk:
1. read one projected document;
2. extract a record key, index, schema-specific row, or state reference;
3. read another projected document or local frame;
4. resolve the key through a renderer-local facade index;
5. adapt the result into a domain object;
6. wire manual refresh or blocking reads around the whole path.
That entire stack must collapse behind one typed CultMesh document, collection, query, or operation handle. If a client wants current docking, current inventory, current target, current stats, zone contacts, station refit state, or visible render objects, the caller should make one semantic CultMesh call and receive a typed reactive value. CultMesh owns cache hydration, routing, sync, invalidation, watch lifetimes, schema binding, derived-state execution, and locality choice.
## Migration Rules
@ -96,6 +123,8 @@ The remaining problem is that the sugar is not yet the only obvious path. There
5. Compatibility mirrors are temporary scaffolding. They must have a named removal stage.
6. Unity is a renderer/input client. It should not own gameplay state, zone hierarchy, simulation cadence, physics, or entity authority by accident.
7. The browser/RTS client and Unity client must use the same semantic Verse facade, even when their locality/runtime routes differ.
8. Client code must not manually compose state access from multiple protocol layers. A semantic state read is one CultMesh call from the caller's point of view.
9. Renderer-local object facades are presentation caches. They are not the API for game state, inventory, docking, targeting, or station services.
## Stage 0: Freeze The Vocabulary
@ -123,6 +152,7 @@ Gates:
- No new public API may introduce `Apply(command, payload)` style call sites.
- No new client API may require a caller to know transport record keys or raw schema slots.
- No new client API may require a caller to join projected documents, frame rows, record keys, and renderer-local facades to obtain one domain value.
- All new examples in docs must use the North Star shape.
## Stage 1: Harden Shared CultMesh Primitives
@ -236,6 +266,75 @@ Gates:
- `ZoneRenderer.LoadZone` and ActionGameManager-owned zone state become vestigial or disappear.
- Public client code has no direct dependency on current daemon frame layout except through generated/internal projection code.
## Stage 3A: Collapse State Access To Typed Reactive Handles
Status: not started; current Unity and RTS clients still perform byzantine protocol walks.
Goal: every client-facing state access becomes a single CultMesh document, collection, query, or pointer call. The caller names the domain state it wants and gets a typed reactive value. It does not manually inspect daemon frames, current-state projections, station rows, record keys, local facade indexes, or transport route details.
Targets:
- Current entity.
- Current docking.
- Current docking bay.
- Current inventory.
- Current target and target details.
- Current ship settings.
- Station refit state.
- Trade cargo targets.
- Zone contacts.
- Selected object.
- Runtime catalog collections.
- Player settings and input bindings.
Desired C# shape:
```csharp
var current = client.Aetheria().Current;
using var docking = current.Docking.Watch(RenderDocking);
using var bay = current.DockingBay.Watch(RenderDockingBay);
using var inventory = current.Inventory.Watch(RenderInventory);
var refit = await client.Aetheria()
.Station
.Refit
.LatestAsync();
```
Desired TS shape:
```ts
const current = client.aetheria().current();
const stopDocking = current.docking().watch(renderDocking);
const stopBay = current.dockingBay().watch(renderDockingBay);
const stopInventory = current.inventory().watch(renderInventory);
const refit = await client.aetheria()
.station()
.refit()
.latest();
```
Work:
- Add shared CultMesh typed reactive document and collection handles if the existing state-pointer/query primitives are not enough.
- Generate Aetheria current/station/zone/catalog accessors from schema metadata.
- Move derived-state joins, such as current docking bay from current docking plus station refit plus entity records, into generated/internal query executors.
- Replace Unity menu/HUD/render calls to `Current*Async()`, `StationRefitAsync()`, `TryResolve*`, and `_observedFacadeIndex` with typed handles.
- Replace blocking `GetAwaiter().GetResult()` reads in client presentation code with watch/latest handles that own lifetimes.
- Keep renderer-local facade indexes only inside render adapter internals while native/query views are still being migrated.
- Add verifiers that treat multi-hop state reads in client code as failures.
Gates:
- `InventoryMenu`, `InventoryPanel`, `TradeMenu`, `LocalMenu`, `SchematicDisplay`, `SectorRenderer`, `MapRenderer`, and `ZoneRenderer` do not manually join state projections to obtain domain values.
- Client-facing code contains no `_observedFacadeIndex.TryResolve*` outside Unity render adapter internals.
- Client-facing code contains no `ResolveClient().Current*Async().GetAwaiter().GetResult()` or equivalent blocking state reads.
- `TryGetTypedCurrentDockingBayFacade` and similar transitional helpers are deleted rather than renamed.
- Verifiers assert the semantic API shape, not the transitional facade-adaptation scaffolding.
## Stage 4: Resolve Eve State Pointers Automatically
Status: primitive records exist; runtime resolution is not yet the whole story.

View file

@ -6,6 +6,14 @@ as Verse records. Unity, tools, test harnesses, and later non-Unity clients open
the same state store with the same runtime document registry and read/write typed
documents through CultNet.
The ergonomic contract is stricter than "typed records are available
somewhere." A client must be able to ask CultMesh for the domain state it wants
in one semantic call and receive a typed reactive document, collection, query
result, operation handle, or native view. The caller should not manually walk
through daemon frames, projected rows, record keys, schema slots, state refs,
renderer-local facade indexes, or transport route decisions to reconstruct one
gameplay value.
The shared entrypoint is `AetheriaRuntimeVerseClient` in the runtime state
package. It opens a local `CultMeshNode` with the runtime-only Aetheria contract
registry and exposes:
@ -20,7 +28,7 @@ registry and exposes:
- typed daemon and Eve command submission through the same command record keys
used by the daemon.
This is the intended shape for the Unity client:
This is the baseline local-record shape:
```csharp
using var client = await AetheriaRuntimeVerseClient.OpenAsync(
@ -39,12 +47,44 @@ using var frames = client.WatchLatestFrames().Subscribe(change =>
var soa = await client.GetLatestSoaViewAsync();
```
That baseline is not the desired presentation API for gameplay state. Unity
menus, HUDs, renderers, RTS panels, and tools should move toward semantic
handles:
```csharp
var aetheria = client.Aetheria();
using var inventory = aetheria.Current.Inventory.Watch(RenderInventory);
using var docking = aetheria.Current.Docking.Watch(RenderDocking);
using var dockingBay = aetheria.Current.DockingBay.Watch(RenderDockingBay);
var stationRefit = await aetheria.Station.Refit.LatestAsync();
var visibleObjects = await aetheria.Zone(currentZoneId)
.Objects
.VisibleToCurrentPlayer()
.Within(cameraRect)
.LatestAsync();
```
The implementation behind those handles may read a local CultCache record,
execute a derived query against the latest daemon frame, subscribe to a remote
Verse, bind an Eve state pointer, or expose a native slab view. That decision is
CultMesh infrastructure. The caller gets a typed domain value and diagnostics
when it asks for them.
Unity should treat the client as its Aetheria-facing runtime surface. It can
still use Burst, DOTS rendering, and native views for presentation, but the state
authority boundary is the typed CultMesh contract. No Unity-facing code should
reach for string command names, mutable payload dictionaries, local simulation
ticks, or daemon implementation classes.
No Unity-facing code should reconstruct state by joining `Current*Async()`,
`StationRefitAsync()`, raw frame projections, typed rows, record keys, and
`AetheriaUnityObservedFacadeIndex`. Renderer-local facades are temporary
presentation caches, not gameplay-state accessors. If the caller wants current
docking bay, target details, station stock, current inventory, or zone contacts,
the public API should expose that as a typed CultMesh handle directly.
## Embedded Host Option
Running an embeddable daemon core in Unity remains a deployment option, but it