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 cf62ebf..eac3928 100644 --- a/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs +++ b/crates/ghostlight-dungeon/src/bin/ghostlight-gestalt-dynamics-smoke.rs @@ -188,6 +188,20 @@ async fn main() -> anyhow::Result<()> { &advanced, ) .await?; + std::fs::write( + root.join(format!( + "sustained-wave-{:02}-preflight.json", + wave_index + 1 + )), + serde_json::to_vec_pretty(&serde_json::json!({ + "wave_index":wave_index + 1, + "budget":budget, + "cover":&sustained_output.wave.cover, + "appraisals":&sustained_output.wave.appraisals, + "private_cell_traces":&sustained_output.private_cell_traces, + "model_stage_receipts":sustained_output.stages.iter().map(|stage|&stage.receipt).collect::>(), + }))?, + )?; let sustained_plan = validate_and_resolve_wave(&advanced, &sustained_output.wave)?; for appraisal in &sustained_output.wave.appraisals { for proposal in &appraisal.actions { diff --git a/crates/ghostlight-dungeon/src/persona.rs b/crates/ghostlight-dungeon/src/persona.rs index 183c272..5b19167 100644 --- a/crates/ghostlight-dungeon/src/persona.rs +++ b/crates/ghostlight-dungeon/src/persona.rs @@ -127,6 +127,24 @@ struct CellAppraisalProposal { inaction_reason: Option, } +const CELL_APPRAISAL_OUTPUT_CONTRACT: &str = r#"{ + "type":"object", + "required":["actions","inaction_reason"], + "properties":{ + "actions":{"type":"array","items":{"type":"object","required":["subject_id","intent","intended_effect","priority","state_references","public_channels","effect"],"properties":{ + "subject_id":{"type":"string"},"intent":{"type":"string"},"intended_effect":{"type":"string"},"priority":{"type":"integer"}, + "state_references":{"type":"array","items":{"type":"string"}},"public_channels":{"type":"array","items":{"type":"string"}}, + "effect":{"oneOf":[ + {"type":"object","required":["type","institution_id","posture","location_ids"],"properties":{"type":{"const":"institution"},"institution_id":{"type":"string"},"posture":{"type":"string"},"location_ids":{"type":"array","items":{"type":"string"}}}}, + {"type":"object","required":["type","gestalt_id","pressure_additions"],"properties":{"type":{"const":"gestalt"},"gestalt_id":{"type":"string"},"pressure_additions":{"type":"array","minItems":1,"maxItems":4,"items":{"type":"string"}}}}, + {"type":"object","required":["type","actor_id","destination_id"],"properties":{"type":{"const":"actor_move"},"actor_id":{"type":"string"},"destination_id":{"type":"string"}}}, + {"type":"object","required":["type","destination_gestalt_id"],"properties":{"type":{"const":"member_migration"},"destination_gestalt_id":{"type":"string"}}} + ]} + }}}, + "inaction_reason":{"type":["string","null"]} + } +}"#; + #[async_trait] pub trait ExecutionPermit: Send + Sync { async fn require(&self, actor_id: &str, snapshot_binding: &str, stage: &str) -> Result<()>; @@ -347,24 +365,34 @@ fn cell_interpreter_context(slice: &PermittedCellSlice) -> serde_json::Value { "exact_permissions": slice.constituents.iter().map(|subject| serde_json::json!({ "subject_id": subject.subject_id, "subject_kind": subject.subject_kind, + "allowed_effect_type": allowed_effect_type(&subject.subject_kind), "collective_authority_id": subject.collective_authority_id, "location_ids": subject.location_ids, - "information_channels": subject.information_channels, + "allowed_public_channels": subject.information_channels, "permitted_state_references": subject.permitted_state_references, "reachable_destination_ids": subject.reachable_destination_ids, })).collect::>(), "member_permissions": slice.member_exceptions.iter().map(|member| serde_json::json!({ "subject_id": member.subject_id, "member_id": member.member_id, + "allowed_effect_type": "member_migration", "source_gestalt_id": member.source_gestalt_id, "source_location_id": member.source_location_id, - "information_channels": member.information_channels, + "allowed_public_channels": member.information_channels, "permitted_state_references": member.permitted_state_references, "migration_destinations": member.migration_destinations, })).collect::>(), }) } +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", + } +} + #[derive(Clone)] pub struct CellProjectionEngine { pub model: Arc, @@ -468,12 +496,11 @@ impl CellProjectionEngine { self.permit .require(&slice.cell_id, &slice.snapshot_binding, "cell_interpreter") .await?; - let prompt_schema = serde_json::to_value(schema_for!(CellAppraisalProposal))?; - let mut schema = prompt_schema.clone(); + let mut schema = serde_json::to_value(schema_for!(CellAppraisalProposal))?; 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 supported by that exact subject's permission references. A named member may only emit member_migration, using one supplied destination mapping; a population or arena cannot migrate a person. The runtime, not you, binds cell identity, revisions, complete membership, and effective state. The cell id is not an actor id. Use an empty actions array plus a concrete inaction_reason when nobody acts.", + "Emit at most {} exact constituent- or named-member-attributed attempts. Copy each subject's allowed_effect_type: institution -> institution, gestalt -> gestalt, actor -> actor_move, named member -> member_migration. Use only that subject's permitted_state_references and allowed_public_channels; facet labels are not public channels. A named member uses one supplied migration destination; a population or arena cannot migrate a person. The runtime binds cell identity, revisions, membership, and effective state. The cell id is not an actor id. Use an empty actions array plus a concrete inaction_reason when nobody acts.", slice.max_actions ); let mut request = ModelStageRequest { @@ -485,7 +512,7 @@ impl CellProjectionEngine { typed_context: &interpreter_context, lived_stream: &lived.text, persona_output: &persona.narrative, - output_schema: &serde_json::to_string(&prompt_schema)?, + output_schema: CELL_APPRAISAL_OUTPUT_CONTRACT, domain_guidance: &permission_guidance, }), output_schema: Some(schema), @@ -619,16 +646,24 @@ fn validate_cell_appraisal( match &action.effect { crate::domain::StrategicCellEffect::Institution { institution_id, + posture, location_ids, - .. } if subject.subject_kind == crate::domain::AgencySubjectKind::Institution && institution_id == &subject.subject_id + && !posture.trim().is_empty() && location_ids .iter() .all(|location| subject.location_ids.contains(location)) => {} - crate::domain::StrategicCellEffect::Gestalt { gestalt_id, .. } - if subject.subject_kind == crate::domain::AgencySubjectKind::Gestalt - && gestalt_id == &subject.subject_id => {} + crate::domain::StrategicCellEffect::Gestalt { + gestalt_id, + pressure_additions, + } if subject.subject_kind == crate::domain::AgencySubjectKind::Gestalt + && gestalt_id == &subject.subject_id + && !pressure_additions.is_empty() + && pressure_additions.len() <= 4 + && pressure_additions + .iter() + .all(|pressure| !pressure.trim().is_empty() && pressure.len() <= 240) => {} crate::domain::StrategicCellEffect::ActorMove { actor_id, destination_id, @@ -913,6 +948,44 @@ mod tests { ); } + #[test] + fn compact_cell_prompt_contract_is_valid_json() { + serde_json::from_str::(CELL_APPRAISAL_OUTPUT_CONTRACT).unwrap(); + } + + #[test] + fn gestalt_pressure_shape_is_rejected_before_the_world_wave() { + let mut slice = fixture_cell_slice(); + let subject = &mut slice.constituents[0]; + subject.subject_id = "crowd".into(); + subject.subject_kind = AgencySubjectKind::Gestalt; + subject.permitted_state_references = BTreeSet::from(["gestalt:crowd".into()]); + let appraisal = bind_cell_appraisal( + &slice, + CellAppraisalProposal { + actions: vec![crate::domain::CellActionProposal { + subject_id: "crowd".into(), + intent: "respond to the pressure".into(), + intended_effect: "change the collective situation".into(), + priority: 1, + state_references: vec!["gestalt:crowd".into()], + public_channels: vec![], + effect: StrategicCellEffect::Gestalt { + gestalt_id: "crowd".into(), + pressure_additions: vec![], + }, + }], + inaction_reason: None, + }, + ); + assert!( + validate_cell_appraisal(&slice, &appraisal) + .unwrap_err() + .to_string() + .contains("exceeds exact constituent authority") + ); + } + #[tokio::test] async fn persona_receives_only_projected_stream() { let engine = PersonaProjectionEngine { diff --git a/crates/ghostlight-dungeon/src/resolution.rs b/crates/ghostlight-dungeon/src/resolution.rs index 0a8c7bb..6f8f3f8 100644 --- a/crates/ghostlight-dungeon/src/resolution.rs +++ b/crates/ghostlight-dungeon/src/resolution.rs @@ -1795,7 +1795,7 @@ fn validate_member_cell_proposal( }) .ok_or_else(|| anyhow!("named member is not a dematerialized exception of this cell"))?; let permitted_references = member_state_references(campaign, member_id)?; - let information_channels = effective_member_knowledge(campaign, member_id)?; + let information_channels = effective_member_information_channels(campaign, member_id)?; if proposal .state_references .iter() @@ -1960,6 +1960,21 @@ pub fn member_state_references(campaign: &Campaign, member_id: &str) -> Result Result> { + let member = campaign + .gestalt_members + .get(member_id) + .ok_or_else(|| anyhow!("gestalt member is unknown"))?; + campaign + .agency_profiles + .get(&member.gestalt_id) + .map(|profile| profile.information_channels.clone()) + .ok_or_else(|| anyhow!("gestalt member agency profile is unknown")) +} + pub fn effective_member_capabilities( campaign: &Campaign, member_id: &str, @@ -2643,6 +2658,12 @@ pub(crate) mod tests { }, ); ensure_agency_profiles(&mut value); + value + .agency_profiles + .get_mut("refugees") + .unwrap() + .information_channels + .insert("camp-bulletin".into()); value.agency_relations.insert( "rivalry".into(), AgencyRelation { @@ -2708,6 +2729,14 @@ pub(crate) mod tests { let plan = validate_and_resolve_wave(&value, &make_wave(proposal.clone())).unwrap(); assert_eq!(plan.member_migrations.len(), 1); + let mut announced = proposal.clone(); + announced.public_channels = vec!["camp-bulletin".into()]; + assert!(validate_and_resolve_wave(&value, &make_wave(announced)).is_ok()); + + let mut knowledge_as_channel = proposal.clone(); + knowledge_as_channel.public_channels = vec!["the player helped me".into()]; + assert!(validate_and_resolve_wave(&value, &make_wave(knowledge_as_channel)).is_err()); + let mut collective_theft = proposal.clone(); collective_theft.subject_id = "refugees".into(); assert!(validate_and_resolve_wave(&value, &make_wave(collective_theft)).is_err()); diff --git a/crates/ghostlight-dungeon/src/scheduler.rs b/crates/ghostlight-dungeon/src/scheduler.rs index f1af91a..0d29848 100644 --- a/crates/ghostlight-dungeon/src/scheduler.rs +++ b/crates/ghostlight-dungeon/src/scheduler.rs @@ -529,6 +529,8 @@ fn member_exceptions(campaign: &Campaign, cell: &SimulationCell) -> Result Result { pub fn build_projector_prompt(input: &ProjectorPrompt<'_>) -> String { format!( - "\nYou are a private Projector. Convert only the permitted typed context and visible stimulus into one compact lived narrative stream. Project what this person perceives, remembers, wants, fears, knows, and explicitly does not know. Anything absent from the permitted context is unavailable: render imagination, suspicion, or speculation as uncertainty, never as remembered or perceived fact. Do not choose actions, emit schemas, expose field names, or claim world effects. Use at most {word_budget} words; omit decorative recap that does not change the decision.\n\nDomain guidance:\n{guidance}\n\nIdentity:\n{identity}\n\nPermitted typed context:\n{context}\n\nVisible stimulus:\n{stimulus}\n\nReturn only the lived narrative stream.", + "\nYou are a private Projector. Convert only the permitted typed context and visible stimulus into one compact lived narrative stream. Project what this person perceives, remembers, wants, fears, knows, and explicitly does not know. Anything absent from the permitted context is unavailable: render imagination, suspicion, or speculation as uncertainty, never as remembered or perceived fact. Do not choose actions, emit schemas, expose field names, or claim world effects. Omit decorative recap that does not change the decision.\n\nDomain guidance:\n{guidance}\n\nIdentity:\n{identity}\n\nPermitted typed context:\n{context}\n\nVisible stimulus:\n{stimulus}\n\nUse at most {word_budget} words. Return only the lived narrative stream.", identity = input.identity, guidance = input.domain_guidance, context = input.typed_context, @@ -43,7 +43,7 @@ pub fn build_projector_prompt(input: &ProjectorPrompt<'_>) -> String { pub fn build_persona_prompt(input: &PersonaPrompt<'_>) -> String { format!( - "\nThe text below is the character's complete lived stream for this turn. Respond naturally from inside it. Treat only asserted perceptions and memories in that stream as known. New external details may appear only as explicit conjecture, imagination, or deliberate invention by the character. You may speak, remain silent, wonder, decide, or attempt something, but do not emit JSON, schemas, action DSL, tool calls, state patches, or claims that an external consequence already occurred. Use at most {word_budget} words and spend them in proportion to the moment.\n\nDomain guidance:\n{guidance}\n\nIdentity:\n{identity}\n\nLived stream:\n{stream}\n\nReturn only the natural Persona turn.", + "\nThe text below is the character's complete lived stream for this turn. Respond naturally from inside it. Treat only asserted perceptions and memories in that stream as known. New external details may appear only as explicit conjecture, imagination, or deliberate invention by the character. You may speak, remain silent, wonder, decide, or attempt something, but do not emit JSON, schemas, action DSL, tool calls, state patches, or claims that an external consequence already occurred. Spend words in proportion to the moment.\n\nDomain guidance:\n{guidance}\n\nIdentity:\n{identity}\n\nLived stream:\n{stream}\n\nUse at most {word_budget} words. Return only the natural Persona turn.", identity = input.identity, guidance = input.domain_guidance, stream = input.lived_stream, diff --git a/docs/architecture/ghostlight-multiresolution-agency.md b/docs/architecture/ghostlight-multiresolution-agency.md index e0a1a08..accc349 100644 --- a/docs/architecture/ghostlight-multiresolution-agency.md +++ b/docs/architecture/ghostlight-multiresolution-agency.md @@ -239,6 +239,17 @@ of its public channels; arena streams retain those viewer attributions. There is no global recent-event recap that can quietly teach every population the same fact. +Interpreter prompts use a compact stable output contract plus an exact +per-subject permission table. The table names the only allowed effect kind, +state references, public channels, and destinations for each constituent or +member exception. Local validation repeats every slice-expressible constraint +before accepting the terminal appraisal, so a malformed pressure marker or +wrong subject/effect pairing receives the same-snapshot correction while the +kernel still performs the authoritative canonical check. Named-member +knowledge is never treated as an information channel; while dematerialized, +the member can publish only through channels owned by their current leaf +gestalt's agency profile. + ## Public state and controls The schema catalog and CultCache stores publish: