Ghostlight/crates
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Meta Vens 48de96b0a4 ghostlight-dungeon: cut the duplicated incident-route scan, add Custody, Dependency, conservation, and evidenced admission
The cut first. `controllers.rs::typed_incident_routes` recomputed by hand the
same incident-route set `scope_digest` computed in `mod.rs`, two scans in two
modules held together by a comment. Both are gone. `mod.rs::scope_components`
is now the single owner of "what components does this subject's verification
read"; `scope_digest` and `snapshot` both consume it, and the controller view
reads `SubjectSnapshot.incident_routes` and resolves IDs against the snapshot.
`ScopePreimage`'s `position` and `routes` fields fold into one `components`
field. Three candidate mismatch names are refused before they exist:
`CustodyNotHeld` (absence is zero, so it is the boundary case of
`InsufficientCustody`), `DependencyTargetKind` (a target of the wrong kind is
`WrongKind`), and `DependencyDuplicate` / `DependencyNotBound` (an operation
that changes nothing is `NoOperationEffect`, which pass 2 already owns).

The addition.

- `WorldState` gains `holdings: BTreeMap<SubjectId, BTreeMap<EntityId,
  Quantity>>` and `dependencies: BTreeMap<SubjectId, BTreeSet<
  DependencyTarget>>`: subject-keyed partitions following `positions`, not
  `EdgeRecord` variants. `EdgeRecord`, `EdgeKind`, `ResolvedRoute`, and the
  seven accessors are untouched. Absence is zero at both levels, so no stored
  `Quantity(0)`, no empty inner map, and a duplicate holding is unrepresentable
  because a map key is unique.
- `Quantity(u64)`: unsigned, no unit, no maximum. Subtraction is `checked_sub`
  and fails as `InsufficientCustody`; addition is `checked_add` and fails as
  `QuantityOverflow`. No saturating arithmetic.
- `ComponentOp` and `ResolvedOp` gain `Transfer`, `Transform`, `Consume`,
  `Admit`, `Bind`, `Release`. `Transform` is 1:1 by construction: one `qty`
  spent and gained, so a ratio has nowhere to be written. No `ResolvedOp`
  carries a resulting balance; every arm re-derives its precondition from the
  committed partitions at apply time.
- `Mismatch` gains `InsufficientCustody`, `ZeroQuantity`, `QuantityOverflow`,
  `AdmitWithoutEvidence`, `SelfDependency`, and `CustodyNotConserved`, appended
  after the pass-2 variants so single-item assertions keep their ordering.
- `patch::check_ledger` is the one statement of conservation:
  `after == before + admitted + gained - consumed - spent`, over `u128`
  accumulators. `resolve_patch` seeds a fourth candidate map beside containers,
  routes, and positions, records each admitted operation's terms, and verdicts
  the ledger after the operation loop and before the emptiness gate.
  `admit_resolved` re-derives the same equation over the committed partitions,
  so a forged `PatchAdmitted` that reaches `apply_effect` without passing the
  resolver dies with `Invariant("custody does not conserve")`. `Transfer`
  contributes to no term: the equation proves it.
- Evidenced admission. `EvidenceRef` gains a constructor and crosses the
  facade. An `Admit` is valid when its ref is canonical text and the identical
  ref appears in the same patch's `evidence` list; otherwise
  `AdmitWithoutEvidence`. The kernel checks no store and no digest — retrieval
  and receipt authenticity belong to the retrieval organ — but the ref rides
  inside the digested, hash-chained commit, so it cannot be altered or dropped
  afterwards. There is no holdings declaration field: `Admit` with evidence is
  the only creation path, in every lane including genesis. Evidence is
  Draft-only, so `Admit` is Draft-only in this pass, with no second gate.
- Replay shape. Every `holdings` key names a canonical subject, every inner key
  a `Resource` entity at a nonzero quantity, no inner map empty; every
  `dependencies` key names a canonical subject with a non-empty set of
  canonical, distinct targets.
- Snapshot and typed view. `WorldSnapshot` gains `resources`;
  `SubjectSnapshot` gains `holdings`, `dependencies`, and `incident_routes`,
  all the acting subject's own. `typed_view` gains a `holdings` block with
  labels resolved only for what this subject holds, and a `dependencies` block
  carrying target kind and ID with no label and no target state. The
  hand-written `available_tools` string is unchanged; the derived tool catalog
  is a later pass.
- Schema bump to `ghostlight.world_state.custody.v1` /
  `ghostlight.world_commit.custody.v1` and the matching journal rows. A
  pre-pass store fails `recover` with an unadmitted row type. No migration
  adapter.

Deviations from the Imagination spec, each decided here:

- `resolve_place` generalizes into `resolve_entity(expected_kind)` rather than
  gaining a `resolve_resource` sibling. Two eight-line wrappers around one body
  bought nothing; the four place call sites pass the kind.
- Spec test 1 asks for a forged `Transfer` whose debit and credit differ.
  `ResolvedOp::Transfer` carries one `qty`, so that is unrepresentable — which
  is the outcome the shape was chosen for. The test proves the reachable
  forgery (a transfer the holder cannot cover leaves `holdings` byte-identical)
  and falsifies `check_ledger` directly beside it.
- Spec test 14 asserts against `verify_state_shape` rather than
  `verify_history`. Mutating a committed holding also breaks replay equality,
  so routing through `verify_history` would pass even with the shape clauses
  deleted.
- Spec test 11's visible half lives in `controllers.rs`, where
  `SelectedDecision` is, extending the existing typed-view non-leakage test;
  its kernel half is the world-level test of the same name.
- `EvidenceRef::new` is `#[cfg(test)]`. No `AdmitPatch` ingress exists yet, so
  every caller that builds a patch today is a test; the gate comes off in the
  same commit as the first production patch author. The type itself crosses the
  facade, as `ComponentOp::Admit` requires.

No external-owner field, no unit, rate, or recipe field anywhere, no new crate
or dependency, no compatibility shim.

cargo test -p ghostlight-dungeon --bin ghostlight-dungeon world::
  91 passed, 0 failed, 1 ignored (75 before this commit).
cargo test -p ghostlight-dungeon: 126 passed + 1, 0 failed, 1 ignored.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 19:03:59 +02:00
..
ghostlight-dungeon ghostlight-dungeon: cut the duplicated incident-route scan, add Custody, Dependency, conservation, and evidenced admission 2026-09-04 19:03:59 +02:00
ghostlight-persona-projection Pass-2 follow-ups: dead presence check, RefKind derives, stamped world_id, stale imports and comment 2026-09-04 19:03:59 +02:00