From a23ab50d18d07ada073dac10b16e6be14573bb62 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 18 Aug 2026 00:57:51 +0200 Subject: [PATCH] Model collective gestalt migration --- .../bin/ghostlight-gestalt-dynamics-smoke.rs | 1 + .../src/bin/ghostlight-gestalt-scale-smoke.rs | 2 +- crates/ghostlight-dungeon/src/domain.rs | 13 ++ crates/ghostlight-dungeon/src/kernel.rs | 170 +++++++++++++++++- crates/ghostlight-dungeon/src/mesh.rs | 23 ++- crates/ghostlight-dungeon/src/persona.rs | 90 +++++++++- crates/ghostlight-dungeon/src/resolution.rs | 115 +++++++++++- crates/ghostlight-dungeon/src/scheduler.rs | 19 +- .../ghostlight-multiresolution-agency.md | 34 ++++ notes/fresh-workspace-handoff.md | 13 ++ notes/ghostlight-current-system-map.md | 13 +- state/map.yaml | 4 +- tools/summarize_ghostlight_live_fire.ps1 | 2 +- 13 files changed, 481 insertions(+), 18 deletions(-) diff --git a/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs b/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs index c8816c9..05acb85 100644 --- a/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs +++ b/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs @@ -211,6 +211,7 @@ async fn main() -> anyhow::Result<()> { let background_action_count = plan.institution_actions.len() + plan.gestalt_actions.len() + plan.gestalt_activities.len() + + plan.gestalt_migrations.len() + plan.actor_moves.len() + plan.member_activities.len(); for stage in &output.stages { diff --git a/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-scale-smoke.rs b/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-scale-smoke.rs index a0342ea..7a38377 100644 --- a/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-scale-smoke.rs +++ b/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-scale-smoke.rs @@ -152,7 +152,7 @@ async fn main() -> anyhow::Result<()> { "cover":cover, "appraisals":output.wave.appraisals, "plan":plan, - "material_action_count":plan.institution_actions.len() + plan.gestalt_actions.len() + plan.gestalt_activities.len() + plan.actor_moves.len() + plan.member_activities.len() + plan.member_migrations.len(), + "material_action_count":plan.institution_actions.len() + plan.gestalt_actions.len() + plan.gestalt_activities.len() + plan.gestalt_migrations.len() + plan.actor_moves.len() + plan.member_activities.len() + plan.member_migrations.len(), "explicit_inaction_count":explicit_inaction_count, "model_stage_receipts":output.stages.iter().map(|stage|&stage.receipt).collect::>(), "commit":committed, diff --git a/crates/ghostlight-dungeon/src/domain.rs b/crates/ghostlight-dungeon/src/domain.rs index 04e08ed..3f3d58e 100644 --- a/crates/ghostlight-dungeon/src/domain.rs +++ b/crates/ghostlight-dungeon/src/domain.rs @@ -440,6 +440,9 @@ pub enum StrategicCellEffect { #[serde(default)] location_ids: Vec, }, + GestaltMigration { + destination_gestalt_id: String, + }, ActorMove { actor_id: String, destination_id: String, @@ -609,6 +612,8 @@ pub struct StrategicTickPlan { pub gestalt_actions: Vec, #[serde(default)] pub gestalt_activities: Vec, + #[serde(default)] + pub gestalt_migrations: Vec, pub actor_moves: Vec, #[serde(default)] pub member_migrations: Vec, @@ -641,6 +646,14 @@ pub struct StrategicGestaltActivity { pub public_channels: Vec, } +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +pub struct StrategicGestaltMigration { + pub gestalt_id: String, + pub destination_gestalt_id: String, + pub destination_location_id: String, + pub public_channels: Vec, +} + #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct StrategicActorMove { pub actor_id: String, diff --git a/crates/ghostlight-dungeon/src/kernel.rs b/crates/ghostlight-dungeon/src/kernel.rs index da2cf7d..3118f10 100644 --- a/crates/ghostlight-dungeon/src/kernel.rs +++ b/crates/ghostlight-dungeon/src/kernel.rs @@ -1364,6 +1364,60 @@ fn apply_strategic_tick_plan( }); } + for action in &plan.gestalt_migrations { + if !seen_gestalts.insert(action.gestalt_id.clone()) { + return Err(KernelError::Invalid( + "gestalt acts twice in one strategic tick".into(), + )); + } + validate_public_channels(&action.public_channels)?; + crate::resolution::validate_gestalt_migration( + campaign, + &action.gestalt_id, + &action.destination_gestalt_id, + &action.destination_location_id, + ) + .map_err(|error| KernelError::Invalid(error.to_string()))?; + } + for action in plan.gestalt_migrations { + let origin = campaign.gestalts[&action.gestalt_id] + .home_location_id + .clone(); + let gestalt_name = campaign.gestalts[&action.gestalt_id].name.clone(); + let destination_name = campaign.gestalts[&action.destination_gestalt_id] + .name + .clone(); + let gestalt = campaign + .gestalts + .get_mut(&action.gestalt_id) + .expect("gestalt migration source was validated"); + gestalt.home_location_id = action.destination_location_id.clone(); + gestalt.version = gestalt.version.saturating_add(1); + let profile = campaign + .agency_profiles + .get_mut(&action.gestalt_id) + .expect("gestalt migration profile was validated"); + profile.location_ids = BTreeSet::from([action.destination_location_id.clone()]); + profile.profile_version = profile.profile_version.saturating_add(1); + events.push(crate::domain::Event { + id: format!( + "strategic:{revision}:gestalt-migration:{}", + action.gestalt_id + ), + at, + kind: "gestalt_migration".into(), + summary: format!( + "{gestalt_name} moves from {origin} to {} near {destination_name}.", + action.destination_location_id + ), + actor_ids: vec![], + institution_ids: vec![], + gestalt_ids: vec![action.gestalt_id, action.destination_gestalt_id], + location_ids: vec![origin, action.destination_location_id], + public_channels: action.public_channels, + }); + } + for action in plan.gestalt_activities { if !seen_gestalts.insert(action.gestalt_id.clone()) { return Err(KernelError::Invalid( @@ -1386,6 +1440,7 @@ fn apply_strategic_tick_plan( let needs_target = !matches!( action.activity, crate::domain::StrategicActivityKind::Prepare + | crate::domain::StrategicActivityKind::Investigate ); if action.target_subject_ids.len() > 4 || unique_targets.len() != action.target_subject_ids.len() @@ -1538,7 +1593,10 @@ fn apply_strategic_tick_plan( crate::resolution::dormant_member_location(campaign, &action.member_id) .map_err(|error| KernelError::Invalid(error.to_string()))?; let unique_targets = action.target_subject_ids.iter().collect::>(); - let needs_target = !matches!(action.activity, StrategicActivityKind::Prepare); + let needs_target = !matches!( + action.activity, + StrategicActivityKind::Prepare | StrategicActivityKind::Investigate + ); if action.target_subject_ids.len() > 4 || unique_targets.len() != action.target_subject_ids.len() || action @@ -1660,6 +1718,9 @@ fn strategic_activity_summary( (StrategicActivityKind::Coordinate, false) => { format!("{source_name} attempts to coordinate with {targets}.") } + (StrategicActivityKind::Investigate, true) => { + format!("{source_name} begins a local investigation.") + } (StrategicActivityKind::Investigate, false) => { format!("{source_name} begins investigating {targets}.") } @@ -2307,6 +2368,86 @@ mod tests { assert_eq!(actor.memories, identity_before.memories); } + #[test] + fn gestalt_migration_moves_only_the_population_leaf() { + let mut value = hierarchical_refugee_campaign(); + let member_before = value.gestalt_members["mira"].clone(); + let destination_before = value.gestalts["dock-neighbors"].clone(); + let events = apply_strategic_tick_plan( + &mut value, + StrategicTickPlan { + gestalt_migrations: vec![StrategicGestaltMigration { + gestalt_id: "refugees-east".into(), + destination_gestalt_id: "dock-neighbors".into(), + destination_location_id: "docks".into(), + public_channels: vec!["camp-bulletin".into()], + }], + ..Default::default() + }, + ) + .unwrap(); + + assert_eq!(value.gestalts["refugees-east"].home_location_id, "docks"); + assert_eq!(value.gestalts["refugees-east"].version, 1); + assert_eq!( + value.agency_profiles["refugees-east"].location_ids, + BTreeSet::from(["docks".into()]) + ); + assert_eq!(value.gestalt_members["mira"], member_before); + assert_eq!(value.gestalts["dock-neighbors"], destination_before); + assert_eq!(events.len(), 1); + assert_eq!(events[0].kind, "gestalt_migration"); + assert_eq!(events[0].location_ids, vec!["camp", "docks"]); + assert_eq!( + events[0].gestalt_ids, + vec!["refugees-east", "dock-neighbors"] + ); + } + + #[test] + fn population_cannot_move_without_its_exact_migration_relation() { + let mut value = hierarchical_refugee_campaign(); + value.agency_relations.clear(); + let before = value.clone(); + let error = apply_strategic_tick_plan( + &mut value, + StrategicTickPlan { + gestalt_migrations: vec![StrategicGestaltMigration { + gestalt_id: "refugees-east".into(), + destination_gestalt_id: "dock-neighbors".into(), + destination_location_id: "docks".into(), + public_channels: vec![], + }], + ..Default::default() + }, + ) + .unwrap_err(); + assert!(error.to_string().contains("source-to-destination relation")); + assert_eq!(value, before); + } + + #[test] + fn invalid_population_migration_batch_has_no_partial_move() { + let mut value = hierarchical_refugee_campaign(); + let before = value.clone(); + let action = StrategicGestaltMigration { + gestalt_id: "refugees-east".into(), + destination_gestalt_id: "dock-neighbors".into(), + destination_location_id: "docks".into(), + public_channels: vec![], + }; + let error = apply_strategic_tick_plan( + &mut value, + StrategicTickPlan { + gestalt_migrations: vec![action.clone(), action], + ..Default::default() + }, + ) + .unwrap_err(); + assert!(error.to_string().contains("acts twice")); + assert_eq!(value, before); + } + #[test] fn member_migration_requires_the_persons_route_and_typed_population_relation() { let mut value = hierarchical_refugee_campaign(); @@ -2392,6 +2533,33 @@ mod tests { assert!(events[0].institution_ids.is_empty()); } + #[test] + fn local_investigation_needs_a_location_but_not_an_invented_actor() { + let mut value = hierarchical_refugee_campaign(); + let before = value.clone(); + let events = apply_strategic_tick_plan( + &mut value, + StrategicTickPlan { + gestalt_activities: vec![StrategicGestaltActivity { + gestalt_id: "refugees-east".into(), + activity: StrategicActivityKind::Investigate, + target_subject_ids: vec![], + location_ids: vec!["camp".into()], + public_channels: vec![], + }], + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(value, before); + assert_eq!( + events[0].summary, + "Eastern transit refugees begins a local investigation." + ); + assert!(events[0].actor_ids.is_empty()); + assert!(events[0].institution_ids.is_empty()); + } + #[test] fn colocated_gestalt_can_address_a_dormant_member_without_absorbing_their_agency() { let mut value = hierarchical_refugee_campaign(); diff --git a/crates/ghostlight-dungeon/src/mesh.rs b/crates/ghostlight-dungeon/src/mesh.rs index ef372a2..0641435 100644 --- a/crates/ghostlight-dungeon/src/mesh.rs +++ b/crates/ghostlight-dungeon/src/mesh.rs @@ -6,7 +6,8 @@ use crate::{ GestaltPersonaState, InstitutionState, Location, NarrationProjection, NewsIssue, RegionExpansionPreview, RejectedProposalReceipt, RelationshipState, ResolutionControlReceipt, ResolutionCover, ResolutionDemand, ResolutionPin, - ResolutionPlanReceipt, ResolutionPolicy, RollReceipt, SimulationCell, StrategicTickPlan, + ResolutionPlanReceipt, ResolutionPolicy, RollReceipt, SimulationCell, + StrategicGestaltMigration, StrategicMemberMigration, StrategicTickPlan, StrategicTickReceipt, VaultEvidenceReceipt, VaultManifest, WorldActionProposal, WorldClock, WorldCommitReceipt, WorldCompilePreview, WorldFact, }, @@ -164,6 +165,8 @@ impl MeshPublisher { "ghostlight.actor_state_delta.v1", "ghostlight.world_action_proposal.v1", "ghostlight.strategic_tick.v1", + "ghostlight.gestalt_migration.v1", + "ghostlight.member_migration.v1", "ghostlight.news_issue.v1", "ghostlight.canon_candidate.v1", ]; @@ -356,7 +359,7 @@ impl MeshPublisher { } fn schema_catalog() -> Value { - json!({ + let mut catalog = json!({ "ghostlight.vault_manifest.v1": schemars::schema_for!(VaultManifest), "ghostlight.vault_evidence_receipt.v1": schemars::schema_for!(VaultEvidenceReceipt), "ghostlight.world_compile_preview.v1": schemars::schema_for!(WorldCompilePreview), @@ -398,7 +401,21 @@ fn schema_catalog() -> Value { "ghostlight.cell_appraisal.v1": schemars::schema_for!(CellAppraisal), "ghostlight.cell_action_proposal.v1": schemars::schema_for!(CellActionProposal), "ghostlight.gestalt_fission_preview.v1": schemars::schema_for!(GestaltFissionPreview) - }) + }); + let schemas = catalog + .as_object_mut() + .expect("schema catalog literal is an object"); + schemas.insert( + "ghostlight.gestalt_migration.v1".into(), + serde_json::to_value(schemars::schema_for!(StrategicGestaltMigration)) + .expect("gestalt migration schema serializes"), + ); + schemas.insert( + "ghostlight.member_migration.v1".into(), + serde_json::to_value(schemars::schema_for!(StrategicMemberMigration)) + .expect("member migration schema serializes"), + ); + catalog } #[cfg(test)] diff --git a/crates/ghostlight-dungeon/src/persona.rs b/crates/ghostlight-dungeon/src/persona.rs index be2cfb9..7fbb304 100644 --- a/crates/ghostlight-dungeon/src/persona.rs +++ b/crates/ghostlight-dungeon/src/persona.rs @@ -65,6 +65,7 @@ pub struct CellConstituentSlice { pub information_channels: BTreeSet, pub permitted_state_references: BTreeSet, pub reachable_destination_ids: BTreeSet, + pub migration_destinations: BTreeMap, pub activity_target_ids: BTreeSet, pub goals: Vec, pub current_posture: Option, @@ -163,6 +164,9 @@ enum CellEffectCandidate { #[serde(default)] location_ids: Vec, }, + GestaltMigration { + destination_gestalt_id: String, + }, ActorMove { destination_id: String, }, @@ -197,6 +201,7 @@ const CELL_APPRAISAL_OUTPUT_CONTRACT: &str = r#"{ {"type":"object","required":["type","posture","location_ids"],"properties":{"type":{"const":"institution"},"posture":{"type":"string"},"location_ids":{"type":"array","items":{"type":"string"}}}}, {"type":"object","required":["type","pressure_additions","pressure_resolutions"],"properties":{"type":{"const":"gestalt"},"pressure_additions":{"type":"array","maxItems":4,"items":{"type":"string"}},"pressure_resolutions":{"type":"array","maxItems":4,"items":{"type":"string"}}}}, {"type":"object","required":["type","activity","target_subject_ids","location_ids"],"properties":{"type":{"const":"gestalt_activity"},"activity":{"enum":["prepare","coordinate","investigate","recruit","obstruct","trade","communicate"]},"target_subject_ids":{"type":"array","maxItems":4,"items":{"type":"string"}},"location_ids":{"type":"array","maxItems":4,"items":{"type":"string"}}}}, + {"type":"object","required":["type","destination_gestalt_id"],"properties":{"type":{"const":"gestalt_migration"},"destination_gestalt_id":{"type":"string"}}}, {"type":"object","required":["type","destination_id"],"properties":{"type":{"const":"actor_move"},"destination_id":{"type":"string"}}}, {"type":"object","required":["type","activity","target_subject_ids","location_ids"],"properties":{"type":{"const":"member_activity"},"activity":{"enum":["prepare","coordinate","investigate","recruit","obstruct","trade","communicate"]},"target_subject_ids":{"type":"array","maxItems":4,"items":{"type":"string"}},"location_ids":{"type":"array","maxItems":1,"items":{"type":"string"}}}}, {"type":"object","required":["type","destination_gestalt_id"],"properties":{"type":{"const":"member_migration"},"destination_gestalt_id":{"type":"string"}}} @@ -388,6 +393,7 @@ fn cell_projector_context(slice: &PermittedCellSlice) -> serde_json::Value { "resources": subject.resources, "information_channels": subject.information_channels, "reachable_destination_ids": subject.reachable_destination_ids, + "migration_destinations": subject.migration_destinations, "activity_target_ids": subject.activity_target_ids, "goals": subject.goals, "current_posture": subject.current_posture, @@ -435,6 +441,7 @@ fn cell_interpreter_context(slice: &PermittedCellSlice) -> serde_json::Value { "allowed_public_channels": subject.information_channels, "permitted_state_references": subject.permitted_state_references, "reachable_destination_ids": subject.reachable_destination_ids, + "migration_destinations": subject.migration_destinations, "activity_target_ids": subject.activity_target_ids, "current_posture": subject.current_posture, "current_pressures": subject.pressures, @@ -506,7 +513,9 @@ fn allowed_effect_type(kind: &crate::domain::AgencySubjectKind) -> &'static str match kind { crate::domain::AgencySubjectKind::Actor => "actor_move", crate::domain::AgencySubjectKind::Institution => "institution", - crate::domain::AgencySubjectKind::Gestalt => "gestalt_pressure_or_gestalt_activity", + crate::domain::AgencySubjectKind::Gestalt => { + "gestalt_pressure_or_gestalt_activity_or_gestalt_migration" + } } } @@ -607,7 +616,15 @@ impl CellProjectionEngine { constrain_cell_proposal_schema(&mut schema, &slice)?; let interpreter_context = serde_json::to_string(&cell_interpreter_context(&slice))?; let permission_guidance = format!( - "Emit at most {} exact constituent- or named-member-attributed attempts. Priority is an urgency score from 0 to 100 where higher numbers resolve first; never use ordinal list rank where 1 means first. Copy each subject's allowed_effect_type: institution -> institution, gestalt -> either gestalt pressure transition or gestalt_activity, actor -> actor_move, named member -> either member_migration or member_activity. Use gestalt_activity or member_activity for a concrete attempt that does not itself change pressure. Map the natural attempt narrowly: communicate means speak, send, offer, ask, or notify; coordinate means arrange a joint attempt, not merely offer one; prepare means the subject's own concrete work such as loading, gathering, fortifying, or rehearsing; investigate means seek information; recruit means invite someone to join; trade means offer an exchange; obstruct means attempt interference. target_subject_ids must come from that exact subject's activity_target_ids and location_ids from its exact location scope. A member_activity uses exactly the member's source_location_id. Internal work by the subject alone is prepare with an empty target_subject_ids list. Coordinate, communicate, trade, recruit, investigate, or obstruct a target only when the Persona explicitly attempts to engage that exact target; permission is not evidence that contact occurred. Write intended_effect as the attempted act itself, not its hoped-for success: 'offer work to X' is valid, while 'integrate X', 'ensure departure', 'build goodwill', acceptance, and any target response are not. Institution posture must be a specific new commitment or withholding, never the current posture or a generic label. Gestalt pressure_resolutions must copy exact current_pressures that the attempted action resolves; pressure_additions are only new unresolved constraints, threats, obligations, or conditions, never completed actions. A pressure transition requires one to four total changes. Use only that subject's permitted_state_references and allowed_public_channels; facet labels are not public channels. A named member who chooses to board, depart, travel, or join one supplied destination within this strategic horizon emits member_migration; do not reduce that commitment to member_activity prepare merely because boarding or approach is the first physical step. Use prepare only when the member undertakes local preparation while departure remains unchosen. A population or arena cannot migrate a person. The runtime binds cell identity, revisions, membership, effect owner IDs, and effective state from subject_id. The cell id is not an actor id. Do not emit institution_id, gestalt_id, actor_id, or member_id inside effect; those duplicated owners are intentionally absent from the output contract. Use an empty actions array plus a concrete inaction_reason when nobody acts.", + concat!( + "Emit at most {} exact constituent- or named-member-attributed attempts. Priority is an urgency score from 0 to 100 where higher numbers resolve first. ", + "Copy each subject's allowed_effect_type: institution -> institution, gestalt -> gestalt pressure transition, gestalt_activity, or gestalt_migration, actor -> actor_move, named member -> member_migration or member_activity. ", + "Use gestalt_activity or member_activity for a concrete attempt that does not itself change pressure. Map attempts narrowly: communicate means speak, send, offer, ask, or notify; coordinate means arrange a joint attempt; prepare means the subject's own concrete work; investigate means seek information; recruit means invite; trade means offer an exchange; obstruct means attempt interference. ", + "target_subject_ids and location_ids must come from that exact subject's permissions. A member_activity uses exactly the member's source_location_id. Internal work is prepare with no targets. A local investigate may have no target and use the exact current location to seek information from the environment or an unnamed ordinary role; it records only the inquiry, never a reply or discovery. Other target-facing activities require the exact supplied target the Persona engages. ", + "Write intended_effect as the attempted act, never its hoped-for outcome or target response. Institution posture must be a specific new commitment or withholding. Gestalt pressure_resolutions copy exact current_pressures; additions are new unresolved constraints, never completed actions. Use only permitted state references and public channels. ", + "A population that chooses to board, depart, or relocate together to one supplied migration_destinations key emits gestalt_migration; do not reduce it to prepare. It relocates only that exact population leaf and never implies a named member traveled. A named member who chooses to board, depart, travel, or join a supplied destination emits member_migration; use prepare only while departure remains unchosen. ", + "A population or arena cannot migrate a person. Runtime binds identity and effect owner IDs from subject_id. Do not emit institution_id, gestalt_id, actor_id, or member_id inside effect. Use an empty actions array plus a concrete inaction_reason when nobody acts." + ), slice.max_actions ); let mut request = ModelStageRequest { @@ -672,7 +689,7 @@ impl CellProjectionEngine { model: self.interpreter_model.clone(), snapshot_binding: verifier_binding, lived_stream: format!( - "You are the private semantic verifier between an Interpreter and the world kernel. Decide whether every candidate typed effect and its intended_effect faithfully represent the exact attributed subject's own attempted consequence in the Persona turn. Structural permissions were already checked. A member_migration means that named member personally chooses to travel to the destination within the strategic horizon; giving away a berth, sending somebody else, waiting, or merely considering travel does not entail it. Conversely, when the member chooses to board, depart, travel, or join the supplied destination, reject any member_activity that reduces that commitment to preparing, queuing, or approaching. A member_activity belongs only to that exact named person's stated attempt; it cannot be reassigned to their population. An institution posture must express its stated commitment or withholding. A gestalt pressure resolution must be causally supported by its stated attempt, and an added pressure must be a resulting unresolved condition rather than completed-action prose. An activity records only the exact attempt—never successful preparation, coordination, discovery, recruitment, obstruction, exchange, delivery, persuasion, acceptance, or target response. Reject omissions, reversals, subject swaps, wishful outcomes, and effects that the Persona did not choose. Be concise. Return exactly one JSON object with this shape and no other fields: {{\"supported\":true or false,\"rejected_action_indices\":[zero-based integer indices],\"rationale\":\"one concise reason\"}}. When supported is true, rejected_action_indices must be empty. When false, list every rejected action index.\n\nCONTEXT:\n{}", + "You are the private semantic verifier between an Interpreter and the world kernel. Decide whether every candidate typed effect and its intended_effect faithfully represent the exact attributed subject's own attempted consequence in the Persona turn. Structural permissions were already checked. A gestalt_migration means that exact population leaf chooses to travel together to the supplied destination within the strategic horizon; loading, waiting, giving away passage, sending only some other subject, or merely considering travel does not entail it. Conversely, when the population chooses to board, depart, or relocate together, reject gestalt_activity prepare that erases the chosen journey. Gestalt migration never entails that a named member moved. A member_migration means that named member personally chooses to travel to the destination; giving away a berth, sending somebody else, waiting, or merely considering travel does not entail it. Conversely, when the member chooses to board, depart, travel, or join the supplied destination, reject any member_activity that reduces that commitment to preparing, queuing, or approaching. A member_activity belongs only to that exact named person's stated attempt; it cannot be reassigned to their population. An institution posture must express its stated commitment or withholding. A gestalt pressure resolution must be causally supported by its stated attempt, and an added pressure must be a resulting unresolved condition rather than completed-action prose. An activity records only the exact attempt—never successful preparation, coordination, discovery, recruitment, obstruction, exchange, delivery, persuasion, acceptance, or target response. Reject omissions, reversals, subject swaps, wishful outcomes, and effects that the Persona did not choose. Be concise. Return exactly one JSON object with this shape and no other fields: {{\"supported\":true or false,\"rejected_action_indices\":[zero-based integer indices],\"rationale\":\"one concise reason\"}}. When supported is true, rejected_action_indices must be empty. When false, list every rejected action index.\n\nCONTEXT:\n{}", serde_json::to_string(&verifier_context)? ), output_schema: Some(serde_json::to_value(schema_for!( @@ -845,6 +862,11 @@ fn bind_cell_appraisal( target_subject_ids, location_ids, }, + CellEffectCandidate::GestaltMigration { + destination_gestalt_id, + } => crate::domain::StrategicCellEffect::GestaltMigration { + destination_gestalt_id, + }, CellEffectCandidate::ActorMove { destination_id } => { crate::domain::StrategicCellEffect::ActorMove { actor_id: candidate.subject_id.clone(), @@ -978,8 +1000,11 @@ fn validate_cell_appraisal( location_ids, } => { let unique_targets = target_subject_ids.iter().collect::>(); - let needs_target = - !matches!(activity, crate::domain::StrategicActivityKind::Prepare); + let needs_target = !matches!( + activity, + crate::domain::StrategicActivityKind::Prepare + | crate::domain::StrategicActivityKind::Investigate + ); if needs_target && target_subject_ids.is_empty() { return Err(anyhow!( "named member {} activity {:?} requires one or more exact target IDs; no anonymous or unsupplied target can be encoded. Remove the action unless the Persona explicitly attempted one of {:?}", @@ -1114,7 +1139,11 @@ fn validate_constituent_effect( } => { let unique_targets = target_subject_ids.iter().collect::>(); let unique_locations = location_ids.iter().collect::>(); - let needs_target = !matches!(activity, crate::domain::StrategicActivityKind::Prepare); + let needs_target = !matches!( + activity, + crate::domain::StrategicActivityKind::Prepare + | crate::domain::StrategicActivityKind::Investigate + ); if needs_target && target_subject_ids.is_empty() { return Err(anyhow!( "gestalt {} activity {:?} requires one or more exact target IDs; no anonymous or unsupplied target can be encoded. Remove the action unless the Persona explicitly attempted one of {:?}", @@ -1147,6 +1176,22 @@ fn validate_constituent_effect( )); } } + crate::domain::StrategicCellEffect::GestaltMigration { + destination_gestalt_id, + } => { + if subject.subject_kind != crate::domain::AgencySubjectKind::Gestalt + || !subject + .migration_destinations + .contains_key(destination_gestalt_id) + { + return Err(anyhow!( + "gestalt {} may not migrate to {}; exact allowed population destinations are {:?}", + subject.subject_id, + destination_gestalt_id, + subject.migration_destinations.keys().collect::>() + )); + } + } crate::domain::StrategicCellEffect::ActorMove { actor_id, destination_id, @@ -1393,6 +1438,7 @@ mod tests { information_channels: BTreeSet::from(["public bulletin".into()]), permitted_state_references: BTreeSet::from(["institution:faction-06".into()]), reachable_destination_ids: BTreeSet::new(), + migration_destinations: BTreeMap::new(), activity_target_ids: BTreeSet::new(), goals: vec!["publish a position".into()], current_posture: Some("weighing whether to publish a position".into()), @@ -1675,6 +1721,38 @@ mod tests { location_ids: vec!["forum".into()], }; validate_constituent_effect(subject, &internal_preparation).unwrap(); + + let local_investigation = StrategicCellEffect::GestaltActivity { + gestalt_id: "refugees".into(), + activity: crate::domain::StrategicActivityKind::Investigate, + target_subject_ids: vec![], + location_ids: vec!["forum".into()], + }; + validate_constituent_effect(subject, &local_investigation).unwrap(); + } + + #[test] + fn gestalt_migration_is_bound_to_the_exact_population_destination() { + let mut slice = fixture_cell_slice(); + let subject = &mut slice.constituents[0]; + subject.subject_id = "refugees".into(); + subject.subject_kind = AgencySubjectKind::Gestalt; + subject.migration_destinations = + BTreeMap::from([("harbor-neighbors".into(), "south-harbor".into())]); + let valid = StrategicCellEffect::GestaltMigration { + destination_gestalt_id: "harbor-neighbors".into(), + }; + validate_constituent_effect(subject, &valid).unwrap(); + + let invented = StrategicCellEffect::GestaltMigration { + destination_gestalt_id: "palace-court".into(), + }; + assert!( + validate_constituent_effect(subject, &invented) + .unwrap_err() + .to_string() + .contains("exact allowed population destinations") + ); } #[test] diff --git a/crates/ghostlight-dungeon/src/resolution.rs b/crates/ghostlight-dungeon/src/resolution.rs index 3661f12..3d9c1cc 100644 --- a/crates/ghostlight-dungeon/src/resolution.rs +++ b/crates/ghostlight-dungeon/src/resolution.rs @@ -1656,6 +1656,20 @@ pub fn validate_and_resolve_wave( location_ids, public_channels: proposal.public_channels, }), + StrategicCellEffect::GestaltMigration { + destination_gestalt_id, + } => { + let gestalt_id = proposal.subject_id.clone(); + let destination_location_id = campaign.gestalts[&destination_gestalt_id] + .home_location_id + .clone(); + plan.gestalt_migrations.push(StrategicGestaltMigration { + gestalt_id, + destination_gestalt_id, + destination_location_id, + public_channels: proposal.public_channels, + }); + } StrategicCellEffect::ActorMove { actor_id, destination_id, @@ -1704,6 +1718,7 @@ pub fn validate_and_resolve_wave( if plan.institution_actions.len() + plan.gestalt_actions.len() + plan.gestalt_activities.len() + + plan.gestalt_migrations.len() + plan.actor_moves.len() + plan.member_activities.len() + plan.member_migrations.len() @@ -1798,7 +1813,10 @@ fn validate_cell_proposal( let allowed_targets = strategic_activity_targets(campaign, gestalt_id); let unique_targets = target_subject_ids.iter().collect::>(); let unique_locations = location_ids.iter().collect::>(); - let needs_target = !matches!(activity, StrategicActivityKind::Prepare); + let needs_target = !matches!( + activity, + StrategicActivityKind::Prepare | StrategicActivityKind::Investigate + ); if gestalt_id != &proposal.subject_id || !campaign.gestalts.contains_key(gestalt_id) || target_subject_ids.len() > 4 @@ -1818,6 +1836,21 @@ fn validate_cell_proposal( )); } } + StrategicCellEffect::GestaltMigration { + destination_gestalt_id, + } => { + let destination_location_id = campaign + .gestalts + .get(destination_gestalt_id) + .map(|gestalt| gestalt.home_location_id.as_str()) + .ok_or_else(|| anyhow!("gestalt migration invented a destination population"))?; + validate_gestalt_migration( + campaign, + &proposal.subject_id, + destination_gestalt_id, + destination_location_id, + )?; + } StrategicCellEffect::ActorMove { actor_id, destination_id, @@ -1942,7 +1975,10 @@ fn validate_member_cell_proposal( let allowed_targets = member_activity_targets(campaign, member_id)?; let unique_targets = target_subject_ids.iter().collect::>(); let exact_location = dormant_member_location(campaign, member_id)?; - let needs_target = !matches!(activity, StrategicActivityKind::Prepare); + let needs_target = !matches!( + activity, + StrategicActivityKind::Prepare | StrategicActivityKind::Investigate + ); if effect_member_id != member_id || target_subject_ids.len() > 4 || unique_targets.len() != target_subject_ids.len() @@ -1981,6 +2017,78 @@ fn validate_member_cell_proposal( } } +pub fn validate_gestalt_migration( + campaign: &Campaign, + source_gestalt_id: &str, + destination_gestalt_id: &str, + destination_location_id: &str, +) -> Result<()> { + if source_gestalt_id == destination_gestalt_id { + return Err(anyhow!( + "gestalt migration must name a different destination population" + )); + } + let source = campaign + .gestalts + .get(source_gestalt_id) + .ok_or_else(|| anyhow!("gestalt migration source is unknown"))?; + let destination = campaign + .gestalts + .get(destination_gestalt_id) + .filter(|destination| destination.home_location_id == destination_location_id) + .ok_or_else(|| anyhow!("gestalt migration destination or location is unknown"))?; + if source.home_location_id == destination_location_id { + return Err(anyhow!( + "gestalt migration must change the source population location" + )); + } + for (gestalt_id, gestalt) in [ + (source_gestalt_id, source), + (destination_gestalt_id, destination), + ] { + let profile = campaign + .agency_profiles + .get(gestalt_id) + .filter(|profile| { + profile.subject_kind == AgencySubjectKind::Gestalt + && profile.active_leaf + && profile.simulation_eligible + }) + .ok_or_else(|| anyhow!("gestalt migration endpoint is not an active leaf"))?; + if !profile.location_ids.contains(&gestalt.home_location_id) { + return Err(anyhow!( + "gestalt migration endpoint has incoherent location state" + )); + } + } + let relation_exists = campaign.agency_relations.values().any(|relation| { + relation.active + && relation.kind == AgencyRelationKind::Migration + && relation.from_subject_id == source_gestalt_id + && relation.to_subject_id == destination_gestalt_id + }); + if !relation_exists { + return Err(anyhow!( + "gestalt migration lacks an explicit source-to-destination relation" + )); + } + let reachable = campaign + .locations + .get(&source.home_location_id) + .is_some_and(|location| { + location.routes.values().any(|route| { + route.destination_id == destination_location_id + && route.travel_minutes <= campaign.tick_hours.saturating_mul(60) + }) + }); + if !reachable { + return Err(anyhow!( + "gestalt migration destination is not reachable within the strategic horizon" + )); + } + Ok(()) +} + pub fn validate_member_migration( campaign: &Campaign, member_id: &str, @@ -2351,6 +2459,9 @@ fn proposal_target_key(proposal: &CellActionProposal) -> String { StrategicCellEffect::GestaltActivity { gestalt_id, .. } => { format!("gestalt:{gestalt_id}") } + StrategicCellEffect::GestaltMigration { .. } => { + format!("gestalt:{}", proposal.subject_id) + } StrategicCellEffect::ActorMove { actor_id, .. } => format!("actor:{actor_id}"), StrategicCellEffect::MemberActivity { member_id, .. } => { format!("member:{member_id}") diff --git a/crates/ghostlight-dungeon/src/scheduler.rs b/crates/ghostlight-dungeon/src/scheduler.rs index 3942f75..bd20bde 100644 --- a/crates/ghostlight-dungeon/src/scheduler.rs +++ b/crates/ghostlight-dungeon/src/scheduler.rs @@ -522,7 +522,8 @@ fn member_exceptions(campaign: &Campaign, cell: &SimulationCell) -> Result Result Result Result