diff --git a/crates/ghostlight-dungeon/src/compiler.rs b/crates/ghostlight-dungeon/src/compiler.rs index cad5c33..cbe713c 100644 --- a/crates/ghostlight-dungeon/src/compiler.rs +++ b/crates/ghostlight-dungeon/src/compiler.rs @@ -59,6 +59,18 @@ pub struct CustomStart { pub goal: String, } +#[derive(Clone, Debug, Serialize, PartialEq)] +struct RequiredRelationshipActor { + id: String, + name: String, +} + +#[derive(Clone, Debug, PartialEq)] +struct ApprovedRelationshipPlan { + anchors: Vec, + targets: BTreeMap<(String, String), String>, +} + #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct SelectedStart { pub campaign_name: String, @@ -416,12 +428,22 @@ impl WorldCompiler { pub async fn compile_custom( &self, start: CustomStart, + ) -> Result<(WorldCompilePreview, Vec)> { + self.compile_custom_with_relationship_actors(start, &[]) + .await + } + + async fn compile_custom_with_relationship_actors( + &self, + start: CustomStart, + required_relationship_actors: &[RequiredRelationshipActor], ) -> Result<(WorldCompilePreview, Vec)> { validate_user_text("campaign name", &start.campaign_name, 80)?; validate_user_text("player identity", &start.who, 500)?; validate_user_text("starting location", &start.where_, 500)?; validate_user_text("starting time", &start.when, 500)?; validate_user_text("player goal", &start.goal, 1_000)?; + validate_required_relationship_actor_inputs(required_relationship_actors)?; let (queries, retrieval_receipt) = self .plan_queries( "custom_retrieval_plan", @@ -445,12 +467,13 @@ impl WorldCompiler { let (global_catalog, global_catalog_receipts) = global_catalog?; let scoped_evidence = direct_seed_evidence_text(&receipts, &evidence_coverage); let shared_prefix = format!( - "SOURCE-GROUNDED WORLD COMPILATION\nSTART:\n{}\nSCOPED EVIDENCE:\n{}\n\n", + "SOURCE-GROUNDED WORLD COMPILATION\nSTART:\n{}\nPRIVATE RELATIONSHIP ACTOR ANCHORS:\n{}\nSCOPED EVIDENCE:\n{}\n\n", serde_json::to_string(&start)?, + serde_json::to_string(required_relationship_actors)?, 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. Actor relationship map keys must copy exact actor or institution IDs declared in this candidate, never display names, roles, groups, or location IDs. 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 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." ); let schema = serde_json::to_value(schema_for!(CompiledSeed))?; let sources = receipt_ids_for_coverage(&receipts, &evidence_coverage); @@ -471,6 +494,7 @@ impl WorldCompiler { 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) }) { Ok(_) => break seed, @@ -506,6 +530,7 @@ impl WorldCompiler { apply_coarse_remote_agency_profiles(&mut campaign, &remote_institution_evidence)?; validate_campaign_seed(&campaign)?; validate_opening_playability(&campaign)?; + validate_required_relationship_actors(&campaign, required_relationship_actors)?; let subject_briefs = agency_subject_briefs(&campaign, &remote_institution_ids); let modeled_subject_ids = subject_briefs .iter() @@ -600,24 +625,28 @@ impl WorldCompiler { .map(|character| format!("{} — {}", character.name, character.public_premise)) .collect::>() .join("; "); + let relationship_plan = approved_relationship_plan(brief)?; let mut compiled = self - .compile_custom(CustomStart { - campaign_name: brief.contract.campaign_name.clone(), - who: format!( - "A cooperative party whose public starting identities are: {public_party}. Private histories, secrets, and individual knowledge are deliberately withheld from world generation." - ), - where_: brief.contract.starting_where.clone(), - when: format!( - "{}; canon horizon: {}", - brief.contract.starting_when, brief.contract.canon_horizon - ), - goal: format!( - "{}; opening pressure: {}; premise: {}", - brief.contract.desired_goal, - brief.contract.starting_pressure, - brief.contract.premise - ), - }) + .compile_custom_with_relationship_actors( + CustomStart { + campaign_name: brief.contract.campaign_name.clone(), + who: format!( + "A cooperative party whose public starting identities are: {public_party}. Private histories, secrets, and individual knowledge are deliberately withheld from world generation." + ), + where_: brief.contract.starting_where.clone(), + when: format!( + "{}; canon horizon: {}", + brief.contract.starting_when, brief.contract.canon_horizon + ), + goal: format!( + "{}; opening pressure: {}; premise: {}", + brief.contract.desired_goal, + brief.contract.starting_pressure, + brief.contract.premise + ), + }, + &relationship_plan.anchors, + ) .await?; let campaign = &mut compiled.0.campaign; let generated_player_id = campaign.player_actor_id.clone(); @@ -644,6 +673,8 @@ impl WorldCompiler { if member_actor_ids.len() != brief.characters.len() { return Err(anyhow!("approved characters must have unique actor IDs")); } + let mut approved_relationship_targets = canonical_relationship_subject_ids(campaign); + approved_relationship_targets.extend(member_actor_ids.iter().cloned()); for character in &brief.characters { if brief.member_actor_ids.get(&character.member_id) != Some(&character.actor_id) { return Err(anyhow!("character and membership actor binding disagree")); @@ -656,21 +687,23 @@ impl WorldCompiler { .relationships .into_iter() .map(|(subject, relationship)| { - let resolved = brief - .member_actor_ids - .get(&subject) + let resolved = relationship_plan + .targets + .get(&(character.member_id.clone(), subject.clone())) .cloned() - .unwrap_or(subject); - (resolved, relationship) + .ok_or_else(|| { + anyhow!("approved character relationship lost its compiled subject") + })?; + Ok((resolved, relationship)) }) - .collect(); + .collect::>>()?; if actor .relationships .keys() - .any(|id| !member_actor_ids.contains(id) && !campaign.institutions.contains_key(id)) + .any(|id| !approved_relationship_targets.contains(id)) { return Err(anyhow!( - "character relationship refers to an unknown member, actor, or institution" + "character relationship refers to an unknown canonical subject" )); } campaign.actors.insert(actor.id.clone(), actor); @@ -694,6 +727,12 @@ impl WorldCompiler { "Campaign contract approved in Session Zero {} at shared digest {}.", brief.session_zero_id, brief.shared_digest )); + if !relationship_plan.anchors.is_empty() { + compiled.0.branch_assumptions.push(format!( + "{} private player-approved relationship subject(s) were materialized without exposing their relationship details to the shared opening.", + relationship_plan.anchors.len() + )); + } Ok(compiled) } @@ -1492,6 +1531,123 @@ fn validate_user_text(label: &str, value: &str, max_chars: usize) -> Result<()> Ok(()) } +fn approved_relationship_plan(brief: &ApprovedCampaignBrief) -> Result { + let mut character_names = BTreeMap::>::new(); + for character in &brief.characters { + character_names + .entry(normalized_identity(&character.name)) + .or_default() + .push(character.actor_id.clone()); + } + let member_actor_ids = brief + .member_actor_ids + .values() + .cloned() + .collect::>(); + let mut anchors = BTreeMap::::new(); + let mut anchor_norms = BTreeMap::::new(); + let mut targets = BTreeMap::new(); + for character in &brief.characters { + for subject in character.relationships.keys() { + validate_user_text("relationship subject", subject, 160)?; + let normalized = normalized_identity(subject); + let target = if let Some(actor_id) = brief.member_actor_ids.get(subject) { + actor_id.clone() + } else if member_actor_ids.contains(subject) { + subject.clone() + } else if let Some(matches) = character_names.get(&normalized).filter(|v| v.len() == 1) + { + matches[0].clone() + } else { + let digest = format!( + "{:x}", + Sha256::digest(format!("private-relationship-actor\0{normalized}").as_bytes()) + ); + let id = format!("relationship-anchor:{}", &digest[..20]); + if let Some(previous) = anchor_norms.insert(id.clone(), normalized.clone()) + && previous != normalized + { + return Err(anyhow!("relationship anchor ID collision")); + } + anchors + .entry(id.clone()) + .or_insert_with(|| RequiredRelationshipActor { + id: id.clone(), + name: subject.trim().to_owned(), + }); + id + }; + targets.insert((character.member_id.clone(), subject.clone()), target); + } + } + Ok(ApprovedRelationshipPlan { + anchors: anchors.into_values().collect(), + targets, + }) +} + +fn validate_required_relationship_actor_inputs( + anchors: &[RequiredRelationshipActor], +) -> Result<()> { + if anchors.len() > 64 { + return Err(anyhow!( + "approved campaign brief cannot require more than 64 relationship actors" + )); + } + let mut ids = BTreeSet::new(); + for anchor in anchors { + validate_user_text("relationship actor name", &anchor.name, 160)?; + if !anchor.id.starts_with("relationship-anchor:") + || anchor.id.chars().count() > 80 + || !ids.insert(anchor.id.clone()) + { + return Err(anyhow!( + "relationship actors require unique server-generated IDs" + )); + } + } + Ok(()) +} + +fn validate_required_relationship_actors( + campaign: &Campaign, + anchors: &[RequiredRelationshipActor], +) -> Result<()> { + let rejected = anchors + .iter() + .filter(|anchor| { + campaign + .actors + .get(&anchor.id) + .is_none_or(|actor| actor.name != anchor.name) + }) + .map(|anchor| anchor.id.clone()) + .collect::>(); + if !rejected.is_empty() { + return Err(anyhow!( + "world seed must contain every private relationship actor with its exact server ID and player-approved name; rejected anchors={rejected:?}" + )); + } + Ok(()) +} + +fn canonical_relationship_subject_ids(campaign: &Campaign) -> BTreeSet { + let mut targets = campaign + .actors + .keys() + .chain(campaign.institutions.keys()) + .chain(campaign.gestalts.keys()) + .cloned() + .collect::>(); + targets.extend( + campaign + .gestalt_members + .keys() + .map(|member_id| format!("member:{member_id}")), + ); + targets +} + fn validate_fission_request(request: &GestaltFissionRequest) -> Result> { validate_user_text("fission reason", &request.reason, 500)?; if request.requested_partition_values.is_empty() @@ -2676,12 +2832,7 @@ pub fn validate_campaign_seed(c: &Campaign) -> Result<()> { profile.subject_id )); } - let relationship_targets = c - .actors - .keys() - .chain(c.institutions.keys()) - .cloned() - .collect::>(); + let relationship_targets = canonical_relationship_subject_ids(c); for actor in c.actors.values() { if !c.locations.contains_key(&actor.location_id) { return Err(anyhow!( @@ -2700,7 +2851,7 @@ pub fn validate_campaign_seed(c: &Campaign) -> Result<()> { .collect::>(); if !invalid_relationships.is_empty() { return Err(anyhow!( - "actor relationships must use exact declared actor or institution IDs with non-empty descriptions; rejected relationships={invalid_relationships:?}; valid target IDs={relationship_targets:?}" + "actor relationships must use exact declared actor, institution, gestalt, or named-member subject IDs with non-empty descriptions; rejected relationships={invalid_relationships:?}; valid target IDs={relationship_targets:?}" )); } } @@ -2838,7 +2989,12 @@ mod tests { request.reason = "x".repeat(501); assert!(validate_fission_request(&request).is_err()); } - use crate::{domain::SourceWitness, model::ModelPort, vault::FixtureVault}; + use crate::{ + domain::SourceWitness, + model::ModelPort, + session_zero::{CampaignContract, CharacterDraft}, + vault::FixtureVault, + }; use async_trait::async_trait; use sha2::Digest; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; @@ -3125,12 +3281,37 @@ mod tests { #[test] fn campaign_relationships_bind_to_canonical_subject_ids() { let mut campaign = crate::resolution::tests::campaign(2, 1); + campaign.gestalts.insert( + "clinic-staff".into(), + GestaltPersonaState { + schema: "ghostlight.gestalt_persona_state.v1".into(), + id: "clinic-staff".into(), + name: "Clinic staff".into(), + version: 0, + home_location_id: "center".into(), + shared_capabilities: BTreeSet::new(), + shared_knowledge: BTreeSet::new(), + resources: BTreeSet::new(), + goals: vec![], + pressures: vec![], + }, + ); + crate::resolution::ensure_agency_profiles(&mut campaign); campaign .actors .get_mut("player") .unwrap() .relationships .insert("faction-0000".into(), "cautious contact".into()); + campaign + .actors + .get_mut("player") + .unwrap() + .relationships + .insert( + "clinic-staff".into(), + "trusted by the clinic collective".into(), + ); validate_campaign_seed(&campaign).unwrap(); campaign @@ -3144,6 +3325,84 @@ mod tests { assert!(error.contains("faction-0000")); } + #[test] + fn approved_relationships_resolve_party_members_and_materialize_stable_private_anchors() { + let mut sable = CharacterDraft { + member_id: "member-sable".into(), + actor_id: "actor-sable".into(), + name: "Sable".into(), + ..Default::default() + }; + sable.relationships.insert( + "convoy quartermaster".into(), + "Sable owes them a life-debt".into(), + ); + let mut mara = CharacterDraft { + member_id: "member-mara".into(), + actor_id: "actor-mara".into(), + name: "Mara".into(), + ..Default::default() + }; + mara.relationships + .insert("Sable".into(), "trusted under pressure".into()); + let brief = ApprovedCampaignBrief { + schema: "ghostlight.approved_campaign_brief.v1".into(), + session_zero_id: Uuid::new_v4(), + host_member_id: "member-sable".into(), + contract: CampaignContract::default(), + aggregate_boundaries: vec![], + characters: vec![sable, mara], + member_actor_ids: BTreeMap::from([ + ("member-sable".into(), "actor-sable".into()), + ("member-mara".into(), "actor-mara".into()), + ]), + shared_digest: "sha256:shared".into(), + character_digests: BTreeMap::new(), + }; + + let first = approved_relationship_plan(&brief).unwrap(); + let second = approved_relationship_plan(&brief).unwrap(); + assert_eq!(first, second); + assert_eq!(first.anchors.len(), 1); + assert_eq!(first.anchors[0].name, "convoy quartermaster"); + assert!(first.anchors[0].id.starts_with("relationship-anchor:")); + assert_eq!( + first.targets[&("member-mara".into(), "Sable".into())], + "actor-sable" + ); + assert_eq!( + first.targets[&("member-sable".into(), "convoy quartermaster".into())], + first.anchors[0].id + ); + assert!( + !serde_json::to_string(&first.anchors) + .unwrap() + .contains("life-debt") + ); + } + + #[test] + fn relationship_anchor_validation_requires_the_exact_actor_identity() { + let mut campaign = crate::resolution::tests::campaign(2, 1); + let anchor = RequiredRelationshipActor { + id: "relationship-anchor:quartermaster".into(), + name: "convoy quartermaster".into(), + }; + let mut actor = campaign.actors["player"].clone(); + actor.id = anchor.id.clone(); + actor.name = anchor.name.clone(); + campaign.actors.insert(actor.id.clone(), actor); + validate_required_relationship_actors(&campaign, std::slice::from_ref(&anchor)).unwrap(); + + campaign.actors.get_mut(&anchor.id).unwrap().name = "Somebody else".into(); + assert!( + validate_required_relationship_actors(&campaign, &[anchor]) + .unwrap_err() + .to_string() + .contains("rejected anchors") + ); + } + #[tokio::test] async fn opening_stage_requires_three_distinct_axes() { let compiler = WorldCompiler::new( diff --git a/crates/ghostlight-dungeon/src/domain.rs b/crates/ghostlight-dungeon/src/domain.rs index 2641cd9..a5d6068 100644 --- a/crates/ghostlight-dungeon/src/domain.rs +++ b/crates/ghostlight-dungeon/src/domain.rs @@ -104,7 +104,8 @@ pub struct ActorState { pub struct RelationshipState { pub schema: String, pub actor_id: String, - pub other_actor_id: String, + #[serde(alias = "other_actor_id")] + pub other_subject_id: String, pub description: String, pub source_revision: u64, } diff --git a/crates/ghostlight-dungeon/src/session_zero.rs b/crates/ghostlight-dungeon/src/session_zero.rs index bd23bfb..8ae0678 100644 --- a/crates/ghostlight-dungeon/src/session_zero.rs +++ b/crates/ghostlight-dungeon/src/session_zero.rs @@ -2078,6 +2078,74 @@ fn display_decision_payload(decision: &SessionZeroDecision) -> String { sections.join("\n") } +#[derive(Clone, Debug, Serialize, PartialEq, Eq)] +struct PrivateRelationshipSubjectProjection { + target_id: String, + subject_kind: String, + name: String, + location_id: Option, + location_name: Option, + relationship: String, +} + +fn private_relationship_subjects( + preview: &WorldCompilePreview, + actor_id: &str, +) -> Vec { + let campaign = &preview.campaign; + let Some(actor) = campaign.actors.get(actor_id) else { + return Vec::new(); + }; + + actor + .relationships + .iter() + .map(|(target_id, description)| { + let (subject_kind, name, location_id) = + if let Some(target) = campaign.actors.get(target_id) { + ( + "actor", + target.name.as_str(), + Some(target.location_id.as_str()), + ) + } else if let Some(target) = campaign.institutions.get(target_id) { + ("institution", target.name.as_str(), None) + } else if let Some(target) = campaign.gestalts.get(target_id) { + ( + "gestalt", + target.name.as_str(), + Some(target.home_location_id.as_str()), + ) + } else if let Some(member_id) = target_id.strip_prefix("member:") { + if let Some(target) = campaign.gestalt_members.get(member_id) { + let location_id = target.last_location_id.as_deref().or_else(|| { + campaign + .gestalts + .get(&target.gestalt_id) + .map(|gestalt| gestalt.home_location_id.as_str()) + }); + ("gestalt_member", target.name.as_str(), location_id) + } else { + ("unknown", target_id.as_str(), None) + } + } else { + ("unknown", target_id.as_str(), None) + }; + let location_name = location_id + .and_then(|id| campaign.locations.get(id)) + .map(|location| location.name.as_str()); + PrivateRelationshipSubjectProjection { + target_id: target_id.clone(), + subject_kind: subject_kind.into(), + name: name.into(), + location_id: location_id.map(str::to_owned), + location_name: location_name.map(str::to_owned), + relationship: description.clone(), + } + }) + .collect() +} + pub fn session_zero_surface( state: &SessionZeroState, account_hash: &str, @@ -2135,6 +2203,12 @@ pub fn session_zero_surface( || decision.owner_member_id.as_deref() == Some(member.id.as_str()) }) .collect::>(); + let character = &state.character_drafts[&member.id]; + let relationship_subjects = state + .preview + .as_ref() + .map(|preview| private_relationship_subjects(preview, &character.actor_id)) + .unwrap_or_default(); let private_preview = state.preview.as_ref().map(|preview| { serde_json::json!({ "title": preview.title, @@ -2143,6 +2217,7 @@ pub fn session_zero_surface( "topology": preview.campaign.locations, "institutions": preview.campaign.institutions, "clocks": preview.campaign.clocks, + "relationship_subjects": relationship_subjects, }) }); let roster_summary = state @@ -2172,7 +2247,6 @@ pub fn session_zero_surface( state.contract.desired_goal, state.contract.tone.join(", ") ); - let character = &state.character_drafts[&member.id]; let character_summary = display_character_ledger(character); let shared_channel_id = state .channels @@ -2361,6 +2435,35 @@ pub fn session_zero_surface( )); } if state.status == SessionZeroStatus::Review { + if !relationship_subjects.is_empty() { + let relationship_summary = relationship_subjects + .iter() + .map(|subject| { + let location = subject + .location_name + .as_deref() + .or(subject.location_id.as_deref()) + .map(|value| format!(" · located at {value}")) + .unwrap_or_default(); + format!( + "{} · {}{}\n{}", + subject.name, subject.subject_kind, location, subject.relationship + ) + }) + .collect::>() + .join("\n\n"); + children.push(serde_json::json!({ + "id":"session-zero.private-relationship-subjects", + "kind":"card", + "props":{"title":"Your private compiled relationships"}, + "children":[{ + "id":"session-zero.private-relationship-subjects.text", + "kind":"text", + "props":{"value":relationship_summary}, + "children":[] + }] + })); + } children.push(command_control( "session-zero.approve", if state.approvals.contains_key(&member.id) { @@ -4389,6 +4492,64 @@ mod tests { assert!(!member_schema.contains("account_hash")); } + #[test] + fn private_preview_projects_exact_relationship_subjects_for_player_approval() { + let mut campaign = crate::resolution::tests::campaign(1, 1); + let mut quartermaster = campaign.actors["player"].clone(); + quartermaster.id = "relationship-anchor:quartermaster".into(); + quartermaster.name = "convoy quartermaster".into(); + campaign + .actors + .insert(quartermaster.id.clone(), quartermaster); + campaign + .actors + .get_mut("player") + .unwrap() + .relationships + .insert( + "relationship-anchor:quartermaster".into(), + "owes them a life-debt".into(), + ); + let preview = WorldCompilePreview { + schema: "ghostlight.world_compile_preview.v1".into(), + title: "Private relationship witness".into(), + campaign, + evidence_receipts: vec![], + evidence_coverage: vec![], + gaps: vec![], + branch_assumptions: vec![], + requires_approval: true, + }; + + let subjects = private_relationship_subjects(&preview, "player"); + assert_eq!(subjects.len(), 1); + assert_eq!(subjects[0].subject_kind, "actor"); + assert_eq!(subjects[0].name, "convoy quartermaster"); + assert_eq!(subjects[0].location_id.as_deref(), Some("center")); + assert_eq!(subjects[0].location_name.as_deref(), Some("Center")); + assert_eq!(subjects[0].relationship, "owes them a life-debt"); + assert!(private_relationship_subjects(&preview, "not-the-player").is_empty()); + + let mut draft = state(); + let actor_id = draft.character_drafts[&draft.host_member_id] + .actor_id + .clone(); + let mut projected_preview = preview; + let mut player = projected_preview.campaign.actors.remove("player").unwrap(); + player.id = actor_id.clone(); + projected_preview.campaign.player_actor_id = actor_id.clone(); + projected_preview.campaign.actors.insert(actor_id, player); + draft.preview = Some(projected_preview); + draft.status = SessionZeroStatus::Review; + let surface = serde_json::to_string( + &session_zero_surface(&draft, "account:host").expect("owner surface"), + ) + .unwrap(); + assert!(surface.contains("Your private compiled relationships")); + assert!(surface.contains("convoy quartermaster")); + assert!(surface.contains("owes them a life-debt")); + } + #[test] fn session_zero_surface_exposes_accept_counter_discuss_and_owned_boundary_controls_as_bindings() { diff --git a/docs/architecture/ghostlight-dungeon-session-zero.md b/docs/architecture/ghostlight-dungeon-session-zero.md index 85aa56a..15e1cb7 100644 --- a/docs/architecture/ghostlight-dungeon-session-zero.md +++ b/docs/architecture/ghostlight-dungeon-session-zero.md @@ -145,6 +145,18 @@ The compiler receives an `approved_campaign_brief.v1`, not the transcript. Private character history and secrets are withheld from world generation; after the grounded seed validates, Ghostlight locally replaces the provisional compiler player with the exact approved actors at one shared start. +Approved relationships cross that membrane by identity, not by free-form map +key. A relationship naming another approved player resolves to that player's +exact actor ID. An otherwise unresolved named person receives a stable, +server-generated relationship-anchor actor ID; the compiler must materialize +that exact actor and name in the seed, but it never receives the private +relationship description and may not reveal the anchor in opening narration +merely because the private ledger requires their existence. The owning player +sees the compiled subject, placement, and relationship during private review. +Their final approval therefore covers the compiler's placement without +exposing it to the table. Actors may also hold directional relationships to an +exact institution, Gestalt, or named Gestalt member. Such a relationship grants +no knowledge, resource, membership, or collective authority. If compilation fails before a preview is installed, the roster remains locked and the typed brief remains authoritative. A host whose current brief still passes the readiness gate receives the Compile action again; retrying uses the diff --git a/notes/ghostlight-current-system-map.md b/notes/ghostlight-current-system-map.md index ec9a12d..b35dc99 100644 --- a/notes/ghostlight-current-system-map.md +++ b/notes/ghostlight-current-system-map.md @@ -587,6 +587,18 @@ validation. Suggestion retrieval and model receipts remain in the Session Zero store; publication compiles the unanimously approved brief, never the conversation transcript. +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. + 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 shape. Transcript-only detail, blank contract fields, or a character with no diff --git a/state/map.yaml b/state/map.yaml index 9dd51da..232dd37 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -88,6 +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. - 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. - Contract Review reuses Session Zero against an exact world revision. Unanimous publication may amend forward-looking contract and approved actor ledger fields but cannot rewrite custody, location, topology, knowledge, memory, canon, or history. Boundary tightening becomes immediate anonymous aggregate policy; relaxation waits for publication.