From 887bcdb827cb06fa64f071bad47aa71e058c00d5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 22 Aug 2026 22:57:28 +0200 Subject: [PATCH] Bind relationship anchor identities locally --- crates/ghostlight-dungeon/src/compiler.rs | 300 +++++++++++++++++- .../ghostlight-dungeon-session-zero.md | 10 + notes/ghostlight-current-system-map.md | 20 +- state/map.yaml | 2 +- 4 files changed, 315 insertions(+), 17 deletions(-) diff --git a/crates/ghostlight-dungeon/src/compiler.rs b/crates/ghostlight-dungeon/src/compiler.rs index cbe713c..0839ae2 100644 --- a/crates/ghostlight-dungeon/src/compiler.rs +++ b/crates/ghostlight-dungeon/src/compiler.rs @@ -473,7 +473,7 @@ impl WorldCompiler { scoped_evidence ); let base_prompt = format!( - "{shared_prefix}Compile a bounded playable region with stable topology, local actors, populations, clocks, and only those remote institutions that have a direct causal relationship to this requested start. SCOPED EVIDENCE contains direct_seed witnesses only. Setting-background and excluded witnesses remain visible in the approval coverage but are deliberately absent here: they cannot donate cast, incidents, clocks, location state, goals, or institutional posture to this branch. When direct evidence cannot ground a requested local detail, keep the local cast sparse, mark reversible texture provisional_local, and list the material gap instead of borrowing a nearby story. Do not eagerly invent remote settlements, routes, or people. Emit only supported canon facts. A canon_baseline fact must cite one or more exact receipt_id values printed in SCOPED EVIDENCE whose witnesses directly support the whole statement. Never label an invented proper noun canon. Facts that an actor can uncover through an admitted local observation must exist before play and list the exact discoverable_at_location_ids where that observation is possible. Seed enough branch_local or provisional_local discoverable facts to make the requested opening pressure and immediate goal actionable; at least one such non-canon fact must be discoverable at the player's exact starting location. The later action assessor can reveal an existing fact but cannot invent one. Facts that are private history or not directly observable have an empty discovery-location set. The player location and every actor location must exist. Every route destination and fact discovery location must exist, travel time must be positive, clocks need positive thresholds, and the player id must be unique. PRIVATE RELATIONSHIP ACTOR ANCHORS carry only player-approved existence and display names: include every one as an ordinary actor with its exact id and name, give it a plausible supplied location, and do not mention its existence or relationship in opening_narration merely because it appears in that private list. Actor relationship map keys must copy exact actor, institution, gestalt, or named-member subject IDs declared in this candidate, never display names, roles, undeclared groups, or location IDs. A relationship to a collective population names its exact gestalt; it does not union that population's knowledge or turn the actor into its authority. Represent populations that can act collectively (villages, crews, crowds, departments, corporations) as gestalt Personas. Seed a small roster of plausible durable member identities for people the player may encounter; member deltas contain only departures from their gestalt baseline and begin dematerialized. Do not duplicate a gestalt member in actors. Keep named plot-critical people as ordinary actors. Every gestalt home location and member gestalt reference must exist. Do not emit agency profiles or relations; those are compiled from the exact validated subject roster in the next stage." + "{shared_prefix}Compile a bounded playable region with stable topology, local actors, populations, clocks, and only those remote institutions that have a direct causal relationship to this requested start. SCOPED EVIDENCE contains direct_seed witnesses only. Setting-background and excluded witnesses remain visible in the approval coverage but are deliberately absent here: they cannot donate cast, incidents, clocks, location state, goals, or institutional posture to this branch. When direct evidence cannot ground a requested local detail, keep the local cast sparse, mark reversible texture provisional_local, and list the material gap instead of borrowing a nearby story. Do not eagerly invent remote settlements, routes, or people. Emit only supported canon facts. A canon_baseline fact must cite one or more exact receipt_id values printed in SCOPED EVIDENCE whose witnesses directly support the whole statement. Never label an invented proper noun canon. Facts that an actor can uncover through an admitted local observation must exist before play and list the exact discoverable_at_location_ids where that observation is possible. Seed enough branch_local or provisional_local discoverable facts to make the requested opening pressure and immediate goal actionable; at least one such non-canon fact must be discoverable at the player's exact starting location. The later action assessor can reveal an existing fact but cannot invent one. Facts that are private history or not directly observable have an empty discovery-location set. The player location and every actor location must exist. Every route destination and fact discovery location must exist, travel time must be positive, clocks need positive thresholds, and the player id must be unique. PRIVATE RELATIONSHIP ACTOR ANCHORS carry only player-approved existence, display names, and opaque server identity handles: include every one exactly once as an ordinary actor with its exact name, give it a plausible supplied location, and preferably copy its supplied id. The server binds the opaque id locally by exact normalized name, so never rename, omit, or duplicate an anchor. Do not mention its existence or relationship in opening_narration merely because it appears in that private list. Actor relationship map keys must copy exact actor, institution, gestalt, or named-member subject IDs declared in this candidate, never display names, roles, undeclared groups, or location IDs. A relationship to a collective population names its exact gestalt; it does not union that population's knowledge or turn the actor into its authority. Represent populations that can act collectively (villages, crews, crowds, departments, corporations) as gestalt Personas. Seed a small roster of plausible durable member identities for people the player may encounter; member deltas contain only departures from their gestalt baseline and begin dematerialized. Do not duplicate a gestalt member in actors. Keep named plot-critical people as ordinary actors. Every gestalt home location and member gestalt reference must exist. Do not emit agency profiles or relations; those are compiled from the exact validated subject roster in the next stage." ); let schema = serde_json::to_value(schema_for!(CompiledSeed))?; let sources = receipt_ids_for_coverage(&receipts, &evidence_coverage); @@ -490,13 +490,20 @@ impl WorldCompiler { ) .await?; compiler_receipts.push(output.1); - let seed: CompiledSeed = serde_json::from_value(output.0)?; - match seed_to_campaign(seed.clone(), &receipts).and_then(|campaign| { - validate_campaign_seed(&campaign)?; - validate_opening_playability(&campaign)?; - validate_required_relationship_actors(&campaign, required_relationship_actors)?; - Ok(campaign) - }) { + let mut seed: CompiledSeed = serde_json::from_value(output.0)?; + let validation = + bind_required_relationship_actor_ids(&mut seed, required_relationship_actors) + .and_then(|()| seed_to_campaign(seed.clone(), &receipts)) + .and_then(|campaign| { + validate_campaign_seed(&campaign)?; + validate_opening_playability(&campaign)?; + validate_required_relationship_actors( + &campaign, + required_relationship_actors, + )?; + Ok(campaign) + }); + match validation { Ok(_) => break seed, Err(error) if compiler_receipts.len() == 1 => { mark_semantic_invalid( @@ -1609,6 +1616,124 @@ fn validate_required_relationship_actor_inputs( Ok(()) } +fn bind_required_relationship_actor_ids( + seed: &mut CompiledSeed, + anchors: &[RequiredRelationshipActor], +) -> Result<()> { + if anchors.is_empty() { + return Ok(()); + } + validate_required_relationship_actor_inputs(anchors)?; + require_unique_ids("actor", seed.actors.iter().map(|actor| actor.id.as_str()))?; + + let mut bound = seed.clone(); + let reserved_non_actor_ids = std::iter::once(bound.player.id.as_str()) + .chain(bound.institutions.iter().map(|item| item.id.as_str())) + .chain(bound.gestalts.iter().map(|item| item.id.as_str())) + .collect::>(); + let mut claimed_actor_indexes = BTreeSet::new(); + let mut replacements = BTreeMap::new(); + + for anchor in anchors { + if reserved_non_actor_ids.contains(anchor.id.as_str()) { + return Err(anyhow!( + "private relationship actor identity {} collides with a non-NPC canonical subject", + anchor.id + )); + } + + let exact = bound + .actors + .iter() + .enumerate() + .filter(|(_, actor)| actor.id == anchor.id) + .map(|(index, _)| index) + .collect::>(); + let actor_index = if let [index] = exact.as_slice() { + *index + } else if exact.len() > 1 { + return Err(anyhow!( + "private relationship actor identity {} appears more than once", + anchor.id + )); + } else { + let normalized_name = normalized_identity(&anchor.name); + let matches = bound + .actors + .iter() + .enumerate() + .filter(|(index, actor)| { + !claimed_actor_indexes.contains(index) + && normalized_identity(&actor.name) == normalized_name + }) + .map(|(index, _)| index) + .collect::>(); + match matches.as_slice() { + [index] => *index, + [] => { + return Err(anyhow!( + "world seed must synthesize one ordinary actor named exactly {:?} for private relationship anchor {}", + anchor.name, + anchor.id + )); + } + _ => { + return Err(anyhow!( + "world seed ambiguously synthesized {} ordinary actors named {:?} for private relationship anchor {}", + matches.len(), + anchor.name, + anchor.id + )); + } + } + }; + if !claimed_actor_indexes.insert(actor_index) { + return Err(anyhow!( + "one compiled actor cannot satisfy more than one private relationship anchor" + )); + } + + let actor = &mut bound.actors[actor_index]; + let previous_id = std::mem::replace(&mut actor.id, anchor.id.clone()); + actor.name.clone_from(&anchor.name); + if previous_id != anchor.id { + replacements.insert(previous_id, anchor.id.clone()); + } + } + + rekey_relationships(&mut bound.player.relationships, &replacements)?; + for actor in &mut bound.actors { + rekey_relationships(&mut actor.relationships, &replacements)?; + } + for member in &mut bound.gestalt_members { + rekey_relationships(&mut member.relationships, &replacements)?; + } + require_unique_ids("actor", bound.actors.iter().map(|actor| actor.id.as_str()))?; + *seed = bound; + Ok(()) +} + +fn rekey_relationships( + relationships: &mut BTreeMap, + replacements: &BTreeMap, +) -> Result<()> { + for (old_id, new_id) in replacements { + let Some(description) = relationships.remove(old_id) else { + continue; + }; + if let Some(existing) = relationships.get(new_id) { + if existing != &description { + return Err(anyhow!( + "relationship identity binding would merge conflicting descriptions for {new_id}" + )); + } + } else { + relationships.insert(new_id.clone(), description); + } + } + Ok(()) +} + fn validate_required_relationship_actors( campaign: &Campaign, anchors: &[RequiredRelationshipActor], @@ -3403,6 +3528,165 @@ mod tests { ); } + fn binding_test_actor(id: &str, name: &str) -> ActorState { + ActorState { + id: id.into(), + name: name.into(), + location_id: "yard".into(), + capabilities: BTreeSet::new(), + knowledge: BTreeSet::new(), + equipment: BTreeSet::new(), + conditions: BTreeSet::new(), + obligations: BTreeSet::new(), + relationships: BTreeMap::new(), + goals: vec![], + memories: vec![], + } + } + + fn binding_test_seed() -> CompiledSeed { + CompiledSeed { + title: "Relationship binding".into(), + canon_cutoff: "fixture".into(), + world_time: Utc::now(), + tick_hours: 6, + player: binding_test_actor("player", "Sable"), + locations: vec![], + actors: vec![], + gestalts: vec![], + gestalt_members: vec![], + institutions: vec![], + clocks: vec![], + facts: vec![], + gaps: vec![], + branch_assumptions: vec![], + opening_narration: String::new(), + } + } + + #[test] + fn relationship_anchor_binding_rekeys_synthesized_actor_and_typed_references() { + let anchor = RequiredRelationshipActor { + id: "relationship-anchor:quartermaster".into(), + name: "convoy quartermaster".into(), + }; + let mut seed = binding_test_seed(); + let old_id = "actor-quartermaster"; + let mut synthesized = binding_test_actor(old_id, "Convoy Quartermaster"); + synthesized.capabilities.insert("convoy logistics".into()); + synthesized.location_id = "remote-convoy".into(); + let mut witness = binding_test_actor("actor-witness", "Witness"); + witness + .relationships + .insert(old_id.into(), "awaits a manifest".into()); + seed.player + .relationships + .insert(old_id.into(), "owes a life-debt".into()); + seed.actors.extend([synthesized, witness]); + seed.gestalt_members.push(GestaltMemberDelta { + schema: "ghostlight.gestalt_member_delta.v1".into(), + id: "member-runner".into(), + gestalt_id: "convoy".into(), + version: 0, + name: "Runner".into(), + capability_additions: BTreeSet::new(), + capability_removals: BTreeSet::new(), + knowledge_additions: BTreeSet::new(), + knowledge_removals: BTreeSet::new(), + equipment: BTreeSet::new(), + conditions: BTreeSet::new(), + obligations: BTreeSet::new(), + relationships: BTreeMap::from([(old_id.into(), "carries dispatches".into())]), + goals: vec![], + memories: vec![], + last_location_id: None, + materialized_actor_id: None, + last_relevant_revision: 0, + relevance_lease_until_revision: 0, + }); + + bind_required_relationship_actor_ids(&mut seed, std::slice::from_ref(&anchor)).unwrap(); + + let bound = seed + .actors + .iter() + .find(|actor| actor.id == anchor.id) + .unwrap(); + assert_eq!(bound.name, anchor.name); + assert_eq!(bound.location_id, "remote-convoy"); + assert!(bound.capabilities.contains("convoy logistics")); + assert_eq!( + seed.player.relationships.get(&anchor.id), + Some(&"owes a life-debt".into()) + ); + assert_eq!( + seed.actors[1].relationships.get(&anchor.id), + Some(&"awaits a manifest".into()) + ); + assert_eq!( + seed.gestalt_members[0].relationships.get(&anchor.id), + Some(&"carries dispatches".into()) + ); + assert!(!seed.actors.iter().any(|actor| actor.id == old_id)); + } + + #[test] + fn relationship_anchor_binding_rejects_missing_ambiguous_and_colliding_subjects() { + let anchor = RequiredRelationshipActor { + id: "relationship-anchor:quartermaster".into(), + name: "convoy quartermaster".into(), + }; + let mut missing = binding_test_seed(); + let original = missing.clone(); + assert!( + bind_required_relationship_actor_ids(&mut missing, std::slice::from_ref(&anchor)) + .unwrap_err() + .to_string() + .contains("must synthesize one ordinary actor") + ); + assert_eq!(missing, original); + + let mut ambiguous = binding_test_seed(); + ambiguous.actors.extend([ + binding_test_actor("first", "Convoy Quartermaster"), + binding_test_actor("second", "convoy-quartermaster"), + ]); + assert!( + bind_required_relationship_actor_ids(&mut ambiguous, std::slice::from_ref(&anchor)) + .unwrap_err() + .to_string() + .contains("ambiguously synthesized") + ); + + let mut collision = binding_test_seed(); + collision.player.id.clone_from(&anchor.id); + collision + .actors + .push(binding_test_actor("candidate", "convoy quartermaster")); + assert!( + bind_required_relationship_actor_ids(&mut collision, &[anchor]) + .unwrap_err() + .to_string() + .contains("collides with a non-NPC canonical subject") + ); + } + + #[test] + fn relationship_anchor_binding_accepts_exact_id_and_restores_approved_name() { + let anchor = RequiredRelationshipActor { + id: "relationship-anchor:quartermaster".into(), + name: "convoy quartermaster".into(), + }; + let mut seed = binding_test_seed(); + seed.actors + .push(binding_test_actor(&anchor.id, "Quartermaster (renamed)")); + + bind_required_relationship_actor_ids(&mut seed, std::slice::from_ref(&anchor)).unwrap(); + + assert_eq!(seed.actors[0].id, anchor.id); + assert_eq!(seed.actors[0].name, anchor.name); + } + #[tokio::test] async fn opening_stage_requires_three_distinct_axes() { let compiler = WorldCompiler::new( diff --git a/docs/architecture/ghostlight-dungeon-session-zero.md b/docs/architecture/ghostlight-dungeon-session-zero.md index 77061a1..7d95127 100644 --- a/docs/architecture/ghostlight-dungeon-session-zero.md +++ b/docs/architecture/ghostlight-dungeon-session-zero.md @@ -219,6 +219,16 @@ gaps, and branch assumptions. Relationship-anchor people remain absent from the shared cast and appear only in their owner's private relationship card. Privacy is labeled in text and never conveyed only by color. +An approved unresolved relationship person crosses world compilation as a +server-owned identity anchor. The model must synthesize exactly one ordinary +actor with the approved name and remains responsible for that person's +location, capabilities, knowledge, equipment, obligations, and goals. The +compiler then binds the opaque canonical ID locally by exact normalized name +and rewrites typed relationship references before validating the candidate. +Omission, ambiguity, ID collision, or conflicting references reject the whole +candidate. Reproducing an opaque identity token is not Persona work and is not +used as a test of model intelligence. + ## Inline grounded suggestions Opening and role generation is no longer a browser-owned creation flow. On a diff --git a/notes/ghostlight-current-system-map.md b/notes/ghostlight-current-system-map.md index 1157626..38e9bf0 100644 --- a/notes/ghostlight-current-system-map.md +++ b/notes/ghostlight-current-system-map.md @@ -601,14 +601,18 @@ and shared cast projection excludes private relationship-anchor people. Private character relationships now cross compilation through a typed identity membrane. Exact player references bind to their approved actor IDs. Each otherwise unresolved named person gets a stable server-generated -`relationship-anchor:*` actor ID; the world compiler receives only that exact -ID and approved display name, must include the actor in the candidate, and does -not receive the private relationship description. Actor, institution, Gestalt, -and `member:*` IDs are all legal directional relationship targets, but those -links never union knowledge or authority. Only the owning member's review -surface projects the compiled target, placement, and private description before -approval. A shared branch assumption exposes the number of materialized private -subjects, never their identities or relationship details. +`relationship-anchor:*` actor ID. The model receives only that identity handle +and approved display name and must synthesize exactly one matching ordinary +actor, but it does not own the opaque ID: after synthesis the compiler binds +the ID locally by exact normalized name and rewrites all typed relationship +references before validation. Omission, ambiguity, collision, or conflicting +references reject the candidate atomically. The model does not receive the +private relationship description. Actor, institution, Gestalt, and `member:*` +IDs are all legal directional relationship targets, but those links never union +knowledge or authority. Only the owning member's review surface projects the +compiled target, placement, and private description before approval. A shared +branch assumption exposes the number of materialized private subjects, never +their identities or relationship details. Roster lock is not readiness. Before world compilation the kernel checks the typed contract's core play frame and each active character's minimum actionable diff --git a/state/map.yaml b/state/map.yaml index 6e15aed..0e0ace9 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -88,7 +88,7 @@ live_architecture: - Approval-gated gestalt fission creates explicit child leaves plus `other/unknown`, preserves inactive parent lineage, and never erases member deltas. - Existing v0 training fixtures are regression evidence and have no runtime write authority. - SessionZeroKernel is the sole pre-world owner of persistent shared/private negotiation, typed contracts, character drafts, boundaries, decisions, invitations, and approvals. The WorldKernel receives only an unanimously approved brief at atomic publication. - - Approved private relationships cross compilation through exact canonical subject IDs. Player references bind to approved actors; otherwise unresolved named people become stable server-generated relationship-anchor actors whose existence and placement are privately reviewed. Relationship descriptions never enter shared compilation context, and links to actors, institutions, Gestalts, or named Gestalt members grant no knowledge or authority. + - Approved private relationships cross compilation through exact canonical subject IDs. Player references bind to approved actors; otherwise unresolved named people become stable server-generated relationship anchors. The model owns synthesis and placement of exactly one actor with the approved name; the compiler locally binds the opaque ID by exact normalized name and rewrites typed references before validation. Omission, ambiguity, collision, or conflicting references reject the candidate atomically. Relationship descriptions never enter shared compilation context, and links to actors, institutions, Gestalts, or named Gestalt members grant no knowledge or authority. - Gap-bearing compiler results remain non-canonical exact previews. Host review selection cannot approve them; every active member approval binds shared contract, private character, and the exact world-preview digest. Publication preserves that digest and the accepted evidence gaps and branch assumptions, while the Eve tree visibly renders the player-reviewable world shape without institution-private resources/goals or another player's relationship anchors. - A material counter clears its prior typed payload, enters the permitted durable channel, removes acceptance authority, and remains unresolved until a same-epoch DM turn atomically installs a fresh decision. Generated opening and role suggestions are non-material; ignoring them cannot block custom compilation. Transcript-only blank contracts and characters fail locally before world compilation. - Bounded co-op uses campaign_membership.v1 to bind one to eight authenticated members to exact actors in the existing campaign mailbox. Sequential public actions, actor-filtered surfaces, unanimous time/travel/cell-budget changes, and non-simulatable human actors are implemented; split parties, PvP, private play actions, delegation, late joining, and group lifecycle commands remain unsupported.