Resolve strategic activities into typed outcomes
This commit is contained in:
parent
15cafa81d1
commit
622d5ba167
17 changed files with 2540 additions and 79 deletions
|
|
@ -232,6 +232,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
"elapsed_seconds":started.elapsed().as_secs_f64(),
|
||||
"cover":&output.wave.cover,
|
||||
"appraisals":&output.wave.appraisals,
|
||||
"activity_outcomes":&output.wave.activity_outcomes,
|
||||
"model_stage_receipts":output.stages.iter().map(|stage|&stage.receipt).collect::<Vec<_>>(),
|
||||
"private_cell_traces":&output.private_cell_traces,
|
||||
"private_model_stage_outputs":output.stages.iter().map(|stage|serde_json::json!({
|
||||
|
|
@ -380,6 +381,9 @@ async fn main() -> anyhow::Result<()> {
|
|||
let mut rejected_wave_pulses = Vec::new();
|
||||
let mut background_subject_ids = BTreeSet::new();
|
||||
let mut detail_focus_subject_ids = BTreeSet::new();
|
||||
let mut sustained_material_consequence_count = 0usize;
|
||||
let mut sustained_material_outcome_count = 0usize;
|
||||
let mut mira_outcome_kinds = BTreeSet::new();
|
||||
detail_focus_subject_ids.extend(direct_resolution_subject_ids(&output.wave.cover.cells));
|
||||
let sustained_budgets = if presence_only {
|
||||
vec![]
|
||||
|
|
@ -469,11 +473,34 @@ async fn main() -> anyhow::Result<()> {
|
|||
"budget":budget,
|
||||
"cover":&sustained_output.wave.cover,
|
||||
"appraisals":&sustained_output.wave.appraisals,
|
||||
"activity_outcomes":&sustained_output.wave.activity_outcomes,
|
||||
"private_cell_traces":&sustained_output.private_cell_traces,
|
||||
"model_stage_receipts":sustained_output.stages.iter().map(|stage|&stage.receipt).collect::<Vec<_>>(),
|
||||
}))?,
|
||||
)?;
|
||||
let sustained_plan = validate_and_resolve_wave(&advanced, &sustained_output.wave)?;
|
||||
let direct_material_count = sustained_plan.institution_actions.len()
|
||||
+ sustained_plan.gestalt_actions.len()
|
||||
+ sustained_plan.gestalt_migrations.len()
|
||||
+ sustained_plan.actor_moves.len()
|
||||
+ sustained_plan.member_migrations.len();
|
||||
let material_outcome_count = sustained_plan
|
||||
.activity_outcomes
|
||||
.iter()
|
||||
.filter(|outcome| {
|
||||
!matches!(
|
||||
outcome.effect,
|
||||
ghostlight_dungeon::domain::StrategicOutcomeEffect::NoMaterialChange { .. }
|
||||
)
|
||||
})
|
||||
.count();
|
||||
sustained_material_consequence_count += direct_material_count + material_outcome_count;
|
||||
sustained_material_outcome_count += material_outcome_count;
|
||||
for outcome in &sustained_plan.activity_outcomes {
|
||||
if let Some(kind) = member_outcome_kind(&outcome.effect, "mira-venn") {
|
||||
mira_outcome_kinds.insert(kind.to_owned());
|
||||
}
|
||||
}
|
||||
for appraisal in &sustained_output.wave.appraisals {
|
||||
for proposal in &appraisal.actions {
|
||||
if proposal.subject_id != "member:mira-venn" {
|
||||
|
|
@ -529,6 +556,9 @@ async fn main() -> anyhow::Result<()> {
|
|||
background_subject_ids.len()
|
||||
)
|
||||
}
|
||||
if !presence_only && sustained_material_consequence_count == 0 {
|
||||
anyhow::bail!("sustained multiresolution waves resolved no material background consequence")
|
||||
}
|
||||
let fairness_missing_subject_ids = if fairness_stress_waves == 0 {
|
||||
BTreeSet::new()
|
||||
} else {
|
||||
|
|
@ -546,13 +576,25 @@ async fn main() -> anyhow::Result<()> {
|
|||
}
|
||||
let member_after_sustained = &advanced.gestalt_members["mira-venn"];
|
||||
if member_after_sustained.gestalt_id != "harbor-neighbors"
|
||||
|| member_after_sustained.relationships != member_before.relationships
|
||||
|| member_after_sustained.memories != member_before.memories
|
||||
|| member_after_sustained.name != member_before.name
|
||||
|| member_after_sustained.conditions != member_before.conditions
|
||||
|| effective_member_capabilities(&advanced, "mira-venn")? != capabilities_before
|
||||
|| effective_member_knowledge(&advanced, "mira-venn")? != knowledge_before
|
||||
{
|
||||
anyhow::bail!("sustained population simulation damaged Mira's dormant identity")
|
||||
}
|
||||
if (member_after_sustained.relationships != member_before.relationships
|
||||
&& !mira_outcome_kinds.contains("relationship"))
|
||||
|| (member_after_sustained.memories != member_before.memories
|
||||
&& !mira_outcome_kinds.contains("memory"))
|
||||
|| (member_after_sustained.obligations != member_before.obligations
|
||||
&& !mira_outcome_kinds.contains("obligation"))
|
||||
|| (member_after_sustained.equipment != member_before.equipment
|
||||
&& !mira_outcome_kinds.contains("resource"))
|
||||
|| (effective_member_knowledge(&advanced, "mira-venn")? != knowledge_before
|
||||
&& !mira_outcome_kinds.contains("knowledge"))
|
||||
{
|
||||
anyhow::bail!("Mira's dormant delta changed without an exact member-bound outcome")
|
||||
}
|
||||
|
||||
let return_event = "The player spends a quiet afternoon repairing the South Harbor ferry steps after the resettlement. The settled harbor populations move through their ordinary routines nearby.";
|
||||
let presence_planner = GestaltPresencePlanner {
|
||||
|
|
@ -634,6 +676,9 @@ async fn main() -> anyhow::Result<()> {
|
|||
"initial_background_action_count":background_action_count,
|
||||
"sustained_background_subject_ids":background_subject_ids,
|
||||
"sustained_detail_focus_subject_ids":detail_focus_subject_ids,
|
||||
"sustained_material_consequence_count":sustained_material_consequence_count,
|
||||
"sustained_material_outcome_count":sustained_material_outcome_count,
|
||||
"mira_outcome_kinds":mira_outcome_kinds,
|
||||
"fairness_stress_waves":fairness_stress_waves,
|
||||
"presence_only":presence_only,
|
||||
"fairness_stress_budget":fairness_stress_budget,
|
||||
|
|
@ -650,7 +695,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
"automatic_presence_plan":presence_plan,
|
||||
"automatic_presence_receipt":presence_receipt,
|
||||
"identity_preserved":true,
|
||||
"effective_state_preserved":true,
|
||||
"member_delta_changes_bound_to_outcomes":true,
|
||||
"player_unchanged":true,
|
||||
"return_encounter_same_person":true,
|
||||
"event_kinds":event_kinds,
|
||||
|
|
@ -667,6 +712,44 @@ async fn main() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn member_outcome_kind(
|
||||
effect: &ghostlight_dungeon::domain::StrategicOutcomeEffect,
|
||||
member_id: &str,
|
||||
) -> Option<&'static str> {
|
||||
use ghostlight_dungeon::domain::StrategicOutcomeEffect;
|
||||
|
||||
let member_subject_id = format!("member:{member_id}");
|
||||
match effect {
|
||||
StrategicOutcomeEffect::MemberMemory {
|
||||
member_id: owner, ..
|
||||
} if owner == member_id => Some("memory"),
|
||||
StrategicOutcomeEffect::MemberObligation {
|
||||
member_id: owner, ..
|
||||
} if owner == member_id => Some("obligation"),
|
||||
StrategicOutcomeEffect::MemberRelationship {
|
||||
member_id: owner, ..
|
||||
} if owner == member_id => Some("relationship"),
|
||||
StrategicOutcomeEffect::KnowledgeLearned {
|
||||
owner_subject_id, ..
|
||||
} if owner_subject_id == &member_subject_id => Some("knowledge"),
|
||||
StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id, ..
|
||||
}
|
||||
| StrategicOutcomeEffect::ResourceConsumed {
|
||||
owner_subject_id, ..
|
||||
} if owner_subject_id == &member_subject_id => Some("resource"),
|
||||
StrategicOutcomeEffect::ResourceTransferred {
|
||||
from_subject_id,
|
||||
to_subject_id,
|
||||
..
|
||||
} if from_subject_id == &member_subject_id || to_subject_id == &member_subject_id => {
|
||||
Some("resource")
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn lineage_depth(
|
||||
campaign: &ghostlight_dungeon::domain::Campaign,
|
||||
|
|
|
|||
|
|
@ -66,15 +66,25 @@ async fn main() -> anyhow::Result<()> {
|
|||
)
|
||||
.await?;
|
||||
let plan = ghostlight_dungeon::resolution::validate_and_resolve_wave(&campaign, &output.wave)?;
|
||||
let material_activity_outcomes = plan
|
||||
.activity_outcomes
|
||||
.iter()
|
||||
.filter(|outcome| {
|
||||
!matches!(
|
||||
outcome.effect,
|
||||
ghostlight_dungeon::domain::StrategicOutcomeEffect::NoMaterialChange { .. }
|
||||
)
|
||||
})
|
||||
.count();
|
||||
if plan.institution_actions.is_empty()
|
||||
&& plan.gestalt_actions.is_empty()
|
||||
&& plan.gestalt_activities.is_empty()
|
||||
&& plan.gestalt_migrations.is_empty()
|
||||
&& plan.actor_moves.is_empty()
|
||||
&& plan.member_activities.is_empty()
|
||||
&& plan.member_migrations.is_empty()
|
||||
&& material_activity_outcomes == 0
|
||||
{
|
||||
anyhow::bail!(
|
||||
"strategic model proposed no material offscreen change: {}",
|
||||
"all cells explicitly chose inaction"
|
||||
"strategic model resolved no material offscreen change: direct transitions were empty and every selected activity outcome was no_material_change"
|
||||
);
|
||||
}
|
||||
for stage in &output.stages {
|
||||
|
|
|
|||
|
|
@ -516,9 +516,81 @@ pub struct ResolutionWaveCommit {
|
|||
pub cover: ResolutionCover,
|
||||
pub plan_receipt: ResolutionPlanReceipt,
|
||||
pub appraisals: Vec<CellAppraisal>,
|
||||
#[serde(default)]
|
||||
pub activity_outcomes: Vec<StrategicActivityOutcome>,
|
||||
pub model_receipt_hashes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StrategicOutcomeBand {
|
||||
Success,
|
||||
Mixed,
|
||||
Failure,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct StrategicActivityOutcome {
|
||||
pub schema: String,
|
||||
pub action_digest: String,
|
||||
pub source_subject_id: String,
|
||||
pub band: StrategicOutcomeBand,
|
||||
#[schemars(length(min = 1, max = 240))]
|
||||
pub summary: String,
|
||||
#[serde(default)]
|
||||
pub supporting_state_references: Vec<String>,
|
||||
pub effect: StrategicOutcomeEffect,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum StrategicOutcomeEffect {
|
||||
NoMaterialChange {
|
||||
reason: String,
|
||||
},
|
||||
ResourceCreated {
|
||||
owner_subject_id: String,
|
||||
resource: String,
|
||||
},
|
||||
ResourceConsumed {
|
||||
owner_subject_id: String,
|
||||
resource: String,
|
||||
},
|
||||
ResourceTransferred {
|
||||
from_subject_id: String,
|
||||
to_subject_id: String,
|
||||
resource: String,
|
||||
},
|
||||
GestaltPressure {
|
||||
gestalt_id: String,
|
||||
#[serde(default)]
|
||||
pressure_additions: Vec<String>,
|
||||
#[serde(default)]
|
||||
pressure_resolutions: Vec<String>,
|
||||
},
|
||||
AgencyRelationShift {
|
||||
relation_id: String,
|
||||
strength_delta: i16,
|
||||
},
|
||||
MemberMemory {
|
||||
member_id: String,
|
||||
memory: String,
|
||||
},
|
||||
MemberObligation {
|
||||
member_id: String,
|
||||
obligation: String,
|
||||
},
|
||||
MemberRelationship {
|
||||
member_id: String,
|
||||
other_subject_id: String,
|
||||
description: String,
|
||||
},
|
||||
KnowledgeLearned {
|
||||
owner_subject_id: String,
|
||||
fact_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct GestaltFissionPreview {
|
||||
pub schema: String,
|
||||
|
|
@ -633,6 +705,8 @@ pub struct StrategicTickPlan {
|
|||
pub member_migrations: Vec<StrategicMemberMigration>,
|
||||
#[serde(default)]
|
||||
pub member_activities: Vec<StrategicMemberActivity>,
|
||||
#[serde(default)]
|
||||
pub activity_outcomes: Vec<StrategicActivityOutcome>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
|
|
@ -653,6 +727,7 @@ pub struct StrategicGestaltAction {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct StrategicGestaltActivity {
|
||||
pub action_digest: String,
|
||||
pub gestalt_id: String,
|
||||
pub activity: StrategicActivityKind,
|
||||
pub target_subject_ids: Vec<String>,
|
||||
|
|
@ -686,6 +761,7 @@ pub struct StrategicMemberMigration {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct StrategicMemberActivity {
|
||||
pub action_digest: String,
|
||||
pub member_id: String,
|
||||
pub source_gestalt_id: String,
|
||||
pub activity: StrategicActivityKind,
|
||||
|
|
|
|||
|
|
@ -414,6 +414,11 @@ fn execute(
|
|||
.iter()
|
||||
.filter(|appraisal| !appraisal.actions.is_empty())
|
||||
.count();
|
||||
let outcome_digests = resolved_plan
|
||||
.as_ref()
|
||||
.map(crate::outcome::plan_activity_digests)
|
||||
.unwrap_or_default();
|
||||
let outcome_stage_count = usize::from(!outcome_digests.is_empty());
|
||||
if unique_hashes.len() != wave.model_receipt_hashes.len()
|
||||
|| wave.model_receipt_hashes.len()
|
||||
< wave
|
||||
|
|
@ -422,6 +427,7 @@ fn execute(
|
|||
.len()
|
||||
.saturating_mul(3)
|
||||
.saturating_add(actionful_cell_count)
|
||||
.saturating_add(outcome_stage_count)
|
||||
{
|
||||
return Err(KernelError::Invalid(
|
||||
"resolution wave does not carry one distinct stage receipt per cell stage"
|
||||
|
|
@ -490,6 +496,20 @@ fn execute(
|
|||
}
|
||||
}
|
||||
}
|
||||
if !outcome_digests.is_empty() {
|
||||
let binding = crate::outcome::activity_outcome_binding(
|
||||
campaign.id,
|
||||
campaign.revision,
|
||||
campaign.resolution_policy.resolution_epoch,
|
||||
&outcome_digests,
|
||||
);
|
||||
if !stage_bindings.contains(&("strategic_outcome_resolver".into(), binding)) {
|
||||
return Err(KernelError::Invalid(
|
||||
"resolution wave lacks an activity-bound strategic outcome receipt"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
campaign.world_time += Duration::hours(i64::from(campaign.tick_hours));
|
||||
for clock in campaign.clocks.values_mut() {
|
||||
|
|
@ -1270,6 +1290,30 @@ fn apply_strategic_tick_plan(
|
|||
campaign: &mut Campaign,
|
||||
plan: crate::domain::StrategicTickPlan,
|
||||
) -> Result<Vec<crate::domain::Event>, KernelError> {
|
||||
crate::outcome::validate_plan_activity_outcomes(campaign, &plan)
|
||||
.map_err(|error| KernelError::Invalid(error.to_string()))?;
|
||||
let activity_outcomes = plan.activity_outcomes.clone();
|
||||
let mut outcome_event_context = BTreeMap::new();
|
||||
for activity in &plan.gestalt_activities {
|
||||
outcome_event_context.insert(
|
||||
activity.action_digest.clone(),
|
||||
(
|
||||
activity.gestalt_id.clone(),
|
||||
activity.location_ids.clone(),
|
||||
activity.public_channels.clone(),
|
||||
),
|
||||
);
|
||||
}
|
||||
for activity in &plan.member_activities {
|
||||
outcome_event_context.insert(
|
||||
activity.action_digest.clone(),
|
||||
(
|
||||
format!("member:{}", activity.member_id),
|
||||
activity.location_ids.clone(),
|
||||
activity.public_channels.clone(),
|
||||
),
|
||||
);
|
||||
}
|
||||
// Every action in a strategic wave was chosen against the same committed
|
||||
// snapshot. Keep that snapshot immutable while applying to a private copy
|
||||
// so action ordering cannot rewrite another action's permissions and an
|
||||
|
|
@ -1706,10 +1750,291 @@ fn apply_strategic_tick_plan(
|
|||
public_channels: action.public_channels,
|
||||
});
|
||||
}
|
||||
for outcome in activity_outcomes {
|
||||
let (source_subject_id, locations, public_channels) = outcome_event_context
|
||||
.remove(&outcome.action_digest)
|
||||
.ok_or_else(|| {
|
||||
KernelError::Invalid("strategic outcome lost its activity context".into())
|
||||
})?;
|
||||
apply_strategic_outcome_effect(&mut next, &outcome.effect)?;
|
||||
let mut subject_ids = BTreeSet::from([source_subject_id]);
|
||||
collect_outcome_subject_ids(&outcome.effect, &mut subject_ids);
|
||||
let mut actor_ids = Vec::new();
|
||||
let mut institution_ids = Vec::new();
|
||||
let mut gestalt_ids = Vec::new();
|
||||
for subject_id in subject_ids {
|
||||
if let Some(member_id) = subject_id.strip_prefix("member:") {
|
||||
actor_ids.push(subject_id.clone());
|
||||
if let Some(member) = next.gestalt_members.get(member_id) {
|
||||
gestalt_ids.push(member.gestalt_id.clone());
|
||||
}
|
||||
} else if next.actors.contains_key(&subject_id) {
|
||||
actor_ids.push(subject_id);
|
||||
} else if next.institutions.contains_key(&subject_id) {
|
||||
institution_ids.push(subject_id);
|
||||
} else if next.gestalts.contains_key(&subject_id) {
|
||||
gestalt_ids.push(subject_id);
|
||||
}
|
||||
}
|
||||
actor_ids.sort();
|
||||
actor_ids.dedup();
|
||||
institution_ids.sort();
|
||||
institution_ids.dedup();
|
||||
gestalt_ids.sort();
|
||||
gestalt_ids.dedup();
|
||||
let digest_suffix = outcome
|
||||
.action_digest
|
||||
.strip_prefix("sha256:")
|
||||
.unwrap_or(&outcome.action_digest)
|
||||
.chars()
|
||||
.take(16)
|
||||
.collect::<String>();
|
||||
events.push(Event {
|
||||
id: format!("strategic:{revision}:activity-outcome:{digest_suffix}"),
|
||||
at,
|
||||
kind: "strategic_activity_outcome".into(),
|
||||
summary: outcome.summary,
|
||||
actor_ids,
|
||||
institution_ids,
|
||||
gestalt_ids,
|
||||
location_ids: locations,
|
||||
public_channels,
|
||||
});
|
||||
}
|
||||
*campaign = next;
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
fn apply_strategic_outcome_effect(
|
||||
campaign: &mut Campaign,
|
||||
effect: &crate::domain::StrategicOutcomeEffect,
|
||||
) -> Result<(), KernelError> {
|
||||
use crate::domain::StrategicOutcomeEffect;
|
||||
match effect {
|
||||
StrategicOutcomeEffect::NoMaterialChange { .. } => {}
|
||||
StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id,
|
||||
resource,
|
||||
} => insert_subject_resource(campaign, owner_subject_id, resource)?,
|
||||
StrategicOutcomeEffect::ResourceConsumed {
|
||||
owner_subject_id,
|
||||
resource,
|
||||
} => remove_subject_resource(campaign, owner_subject_id, resource)?,
|
||||
StrategicOutcomeEffect::ResourceTransferred {
|
||||
from_subject_id,
|
||||
to_subject_id,
|
||||
resource,
|
||||
} => {
|
||||
remove_subject_resource(campaign, from_subject_id, resource)?;
|
||||
insert_subject_resource(campaign, to_subject_id, resource)?;
|
||||
}
|
||||
StrategicOutcomeEffect::GestaltPressure {
|
||||
gestalt_id,
|
||||
pressure_additions,
|
||||
pressure_resolutions,
|
||||
} => {
|
||||
let gestalt = campaign
|
||||
.gestalts
|
||||
.get_mut(gestalt_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome gestalt vanished".into()))?;
|
||||
crate::resolution::validate_gestalt_pressure_transition(
|
||||
&gestalt.pressures,
|
||||
pressure_additions,
|
||||
pressure_resolutions,
|
||||
)
|
||||
.map_err(|error| KernelError::Invalid(error.to_string()))?;
|
||||
let resolved = pressure_resolutions.iter().collect::<BTreeSet<_>>();
|
||||
gestalt
|
||||
.pressures
|
||||
.retain(|pressure| !resolved.contains(pressure));
|
||||
gestalt.pressures.extend(pressure_additions.iter().cloned());
|
||||
gestalt.version = gestalt.version.saturating_add(1);
|
||||
}
|
||||
StrategicOutcomeEffect::AgencyRelationShift {
|
||||
relation_id,
|
||||
strength_delta,
|
||||
} => {
|
||||
let relation = campaign
|
||||
.agency_relations
|
||||
.get_mut(relation_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome relation vanished".into()))?;
|
||||
relation.strength = u8::try_from(i16::from(relation.strength) + strength_delta)
|
||||
.map_err(|_| KernelError::Invalid("outcome relation shift overflowed".into()))?;
|
||||
}
|
||||
StrategicOutcomeEffect::MemberMemory { member_id, memory } => {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome member vanished".into()))?;
|
||||
if !member.memories.contains(memory) {
|
||||
member.memories.push(memory.clone());
|
||||
}
|
||||
member.version = member.version.saturating_add(1);
|
||||
}
|
||||
StrategicOutcomeEffect::MemberObligation {
|
||||
member_id,
|
||||
obligation,
|
||||
} => {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome member vanished".into()))?;
|
||||
member.obligations.insert(obligation.clone());
|
||||
member.version = member.version.saturating_add(1);
|
||||
}
|
||||
StrategicOutcomeEffect::MemberRelationship {
|
||||
member_id,
|
||||
other_subject_id,
|
||||
description,
|
||||
} => {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome member vanished".into()))?;
|
||||
member
|
||||
.relationships
|
||||
.insert(other_subject_id.clone(), description.clone());
|
||||
member.version = member.version.saturating_add(1);
|
||||
}
|
||||
StrategicOutcomeEffect::KnowledgeLearned {
|
||||
owner_subject_id,
|
||||
fact_id,
|
||||
} => {
|
||||
let statement = campaign
|
||||
.facts
|
||||
.get(fact_id)
|
||||
.map(|fact| fact.statement.clone())
|
||||
.ok_or_else(|| KernelError::Invalid("outcome fact vanished".into()))?;
|
||||
if let Some(member_id) = owner_subject_id.strip_prefix("member:") {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("outcome member vanished".into()))?;
|
||||
member.knowledge_removals.remove(&statement);
|
||||
member.knowledge_additions.insert(statement);
|
||||
member.version = member.version.saturating_add(1);
|
||||
} else {
|
||||
let gestalt = campaign.gestalts.get_mut(owner_subject_id).ok_or_else(|| {
|
||||
KernelError::Invalid("outcome knowledge owner vanished".into())
|
||||
})?;
|
||||
gestalt.shared_knowledge.insert(statement);
|
||||
gestalt.version = gestalt.version.saturating_add(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_subject_resource(
|
||||
campaign: &mut Campaign,
|
||||
subject_id: &str,
|
||||
resource: &str,
|
||||
) -> Result<(), KernelError> {
|
||||
if let Some(member_id) = subject_id.strip_prefix("member:") {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("resource member vanished".into()))?;
|
||||
member.equipment.insert(resource.into());
|
||||
member.version = member.version.saturating_add(1);
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(gestalt) = campaign.gestalts.get_mut(subject_id) {
|
||||
gestalt.resources.insert(resource.into());
|
||||
gestalt.version = gestalt.version.saturating_add(1);
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(institution) = campaign.institutions.get_mut(subject_id) {
|
||||
institution.resources.push(resource.into());
|
||||
institution.resources.sort();
|
||||
institution.resources.dedup();
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(actor) = campaign.actors.get_mut(subject_id) {
|
||||
actor.equipment.insert(resource.into());
|
||||
return Ok(());
|
||||
}
|
||||
Err(KernelError::Invalid("resource recipient vanished".into()))
|
||||
}
|
||||
|
||||
fn remove_subject_resource(
|
||||
campaign: &mut Campaign,
|
||||
subject_id: &str,
|
||||
resource: &str,
|
||||
) -> Result<(), KernelError> {
|
||||
let removed = if let Some(member_id) = subject_id.strip_prefix("member:") {
|
||||
let member = campaign
|
||||
.gestalt_members
|
||||
.get_mut(member_id)
|
||||
.ok_or_else(|| KernelError::Invalid("resource member vanished".into()))?;
|
||||
let removed = member.equipment.remove(resource);
|
||||
member.version = member.version.saturating_add(1);
|
||||
removed
|
||||
} else if let Some(gestalt) = campaign.gestalts.get_mut(subject_id) {
|
||||
let removed = gestalt.resources.remove(resource);
|
||||
gestalt.version = gestalt.version.saturating_add(1);
|
||||
removed
|
||||
} else if let Some(institution) = campaign.institutions.get_mut(subject_id) {
|
||||
let previous = institution.resources.len();
|
||||
institution.resources.retain(|value| value != resource);
|
||||
institution.resources.len() != previous
|
||||
} else if let Some(actor) = campaign.actors.get_mut(subject_id) {
|
||||
actor.equipment.remove(resource)
|
||||
} else {
|
||||
return Err(KernelError::Invalid("resource owner vanished".into()));
|
||||
};
|
||||
if !removed {
|
||||
return Err(KernelError::Invalid(
|
||||
"outcome attempted to spend a missing resource".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_outcome_subject_ids(
|
||||
effect: &crate::domain::StrategicOutcomeEffect,
|
||||
subjects: &mut BTreeSet<String>,
|
||||
) {
|
||||
use crate::domain::StrategicOutcomeEffect;
|
||||
match effect {
|
||||
StrategicOutcomeEffect::NoMaterialChange { .. } => {}
|
||||
StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id, ..
|
||||
}
|
||||
| StrategicOutcomeEffect::ResourceConsumed {
|
||||
owner_subject_id, ..
|
||||
}
|
||||
| StrategicOutcomeEffect::KnowledgeLearned {
|
||||
owner_subject_id, ..
|
||||
} => {
|
||||
subjects.insert(owner_subject_id.clone());
|
||||
}
|
||||
StrategicOutcomeEffect::ResourceTransferred {
|
||||
from_subject_id,
|
||||
to_subject_id,
|
||||
..
|
||||
} => {
|
||||
subjects.insert(from_subject_id.clone());
|
||||
subjects.insert(to_subject_id.clone());
|
||||
}
|
||||
StrategicOutcomeEffect::GestaltPressure { gestalt_id, .. } => {
|
||||
subjects.insert(gestalt_id.clone());
|
||||
}
|
||||
StrategicOutcomeEffect::AgencyRelationShift { .. } => {}
|
||||
StrategicOutcomeEffect::MemberMemory { member_id, .. }
|
||||
| StrategicOutcomeEffect::MemberObligation { member_id, .. }
|
||||
| StrategicOutcomeEffect::MemberRelationship { member_id, .. } => {
|
||||
subjects.insert(format!("member:{member_id}"));
|
||||
if let StrategicOutcomeEffect::MemberRelationship {
|
||||
other_subject_id, ..
|
||||
} = effect
|
||||
{
|
||||
subjects.insert(other_subject_id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn strategic_activity_summary(
|
||||
source_name: &str,
|
||||
activity: &StrategicActivityKind,
|
||||
|
|
@ -2132,8 +2457,41 @@ fn persist(e: anyhow::Error) -> KernelError {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
fn test_action_digest(label: &str) -> String {
|
||||
format!("sha256:{:x}", Sha256::digest(label.as_bytes()))
|
||||
}
|
||||
|
||||
fn resolve_test_activities(mut plan: StrategicTickPlan) -> StrategicTickPlan {
|
||||
plan.activity_outcomes.extend(
|
||||
plan.gestalt_activities
|
||||
.iter()
|
||||
.map(|activity| (activity.action_digest.clone(), activity.gestalt_id.clone()))
|
||||
.chain(plan.member_activities.iter().map(|activity| {
|
||||
(
|
||||
activity.action_digest.clone(),
|
||||
format!("member:{}", activity.member_id),
|
||||
)
|
||||
}))
|
||||
.map(
|
||||
|(action_digest, source_subject_id)| StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest,
|
||||
source_subject_id,
|
||||
band: StrategicOutcomeBand::Mixed,
|
||||
summary: "The attempt produces no durable material change.".into(),
|
||||
supporting_state_references: vec![],
|
||||
effect: StrategicOutcomeEffect::NoMaterialChange {
|
||||
reason: "No response is established in this test snapshot.".into(),
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
plan
|
||||
}
|
||||
|
||||
fn campaign() -> Campaign {
|
||||
let id = uuid::Uuid::new_v4();
|
||||
let actor = ActorState {
|
||||
|
|
@ -2741,7 +3099,7 @@ mod tests {
|
|||
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_migrations: vec![StrategicGestaltMigration {
|
||||
gestalt_id: "refugees-east".into(),
|
||||
destination_gestalt_id: "dock-neighbors".into(),
|
||||
|
|
@ -2749,6 +3107,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("simultaneous communication"),
|
||||
gestalt_id: "camp-neighbors".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec!["refugees-east".into()],
|
||||
|
|
@ -2756,12 +3115,12 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(value.gestalts["refugees-east"].home_location_id, "docks");
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(events.len(), 3);
|
||||
assert_eq!(events[1].kind, "gestalt_activity");
|
||||
assert_eq!(events[1].location_ids, vec!["camp"]);
|
||||
assert_eq!(
|
||||
|
|
@ -2776,7 +3135,7 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let error = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_migrations: vec![StrategicGestaltMigration {
|
||||
gestalt_id: "refugees-east".into(),
|
||||
destination_gestalt_id: "dock-neighbors".into(),
|
||||
|
|
@ -2784,6 +3143,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("conflicting refugee preparation"),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Prepare,
|
||||
target_subject_ids: vec![],
|
||||
|
|
@ -2791,7 +3151,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap_err();
|
||||
|
||||
|
|
@ -2896,13 +3256,14 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn gestalt_activity_records_an_attributed_attempt_without_claiming_an_outcome() {
|
||||
fn gestalt_activity_requires_an_explicit_resolved_no_material_outcome() {
|
||||
let mut value = hierarchical_refugee_campaign();
|
||||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("refugee coordination"),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Coordinate,
|
||||
target_subject_ids: vec!["dock-neighbors".into()],
|
||||
|
|
@ -2910,11 +3271,11 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(events[0].kind, "gestalt_activity");
|
||||
assert_eq!(
|
||||
events[0].summary,
|
||||
|
|
@ -2926,6 +3287,173 @@ mod tests {
|
|||
);
|
||||
assert!(events[0].actor_ids.is_empty());
|
||||
assert!(events[0].institution_ids.is_empty());
|
||||
assert_eq!(events[1].kind, "strategic_activity_outcome");
|
||||
assert_eq!(
|
||||
events[1].summary,
|
||||
"The attempt produces no durable material change."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strategic_outcome_materializes_a_bounded_resource_from_exact_capability() {
|
||||
let mut value = hierarchical_refugee_campaign();
|
||||
let digest = test_action_digest("refugees prepare storm lashings");
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: digest.clone(),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Prepare,
|
||||
target_subject_ids: vec![],
|
||||
location_ids: vec!["camp".into()],
|
||||
public_channels: vec![],
|
||||
}],
|
||||
activity_outcomes: vec![StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest: digest,
|
||||
source_subject_id: "refugees-east".into(),
|
||||
band: StrategicOutcomeBand::Success,
|
||||
summary: "The refugees finish a set of storm lashings.".into(),
|
||||
supporting_state_references: vec![
|
||||
"capability:survive transit".into(),
|
||||
"location:camp".into(),
|
||||
],
|
||||
effect: StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id: "refugees-east".into(),
|
||||
resource: "storm lashings".into(),
|
||||
},
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
value.gestalts["refugees-east"]
|
||||
.resources
|
||||
.contains("storm lashings")
|
||||
);
|
||||
assert_eq!(value.gestalts["refugees-east"].version, 1);
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(events[1].kind, "strategic_activity_outcome");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_outcome_bundle_cannot_apply_an_earlier_material_effect() {
|
||||
let mut value = hierarchical_refugee_campaign();
|
||||
let before = value.clone();
|
||||
let first = test_action_digest("valid material preparation");
|
||||
let second = test_action_digest("invalid resource spend");
|
||||
let error = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
gestalt_activities: vec![
|
||||
StrategicGestaltActivity {
|
||||
action_digest: first.clone(),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Prepare,
|
||||
target_subject_ids: vec![],
|
||||
location_ids: vec!["camp".into()],
|
||||
public_channels: vec![],
|
||||
},
|
||||
StrategicGestaltActivity {
|
||||
action_digest: second.clone(),
|
||||
gestalt_id: "dock-neighbors".into(),
|
||||
activity: StrategicActivityKind::Prepare,
|
||||
target_subject_ids: vec![],
|
||||
location_ids: vec!["docks".into()],
|
||||
public_channels: vec![],
|
||||
},
|
||||
],
|
||||
activity_outcomes: vec![
|
||||
StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest: first,
|
||||
source_subject_id: "refugees-east".into(),
|
||||
band: StrategicOutcomeBand::Success,
|
||||
summary: "A valid first result.".into(),
|
||||
supporting_state_references: vec!["capability:survive transit".into()],
|
||||
effect: StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id: "refugees-east".into(),
|
||||
resource: "valid new shelter frame".into(),
|
||||
},
|
||||
},
|
||||
StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest: second,
|
||||
source_subject_id: "dock-neighbors".into(),
|
||||
band: StrategicOutcomeBand::Failure,
|
||||
summary: "An invalid second result.".into(),
|
||||
supporting_state_references: vec!["capability:repair nets".into()],
|
||||
effect: StrategicOutcomeEffect::ResourceConsumed {
|
||||
owner_subject_id: "dock-neighbors".into(),
|
||||
resource: "invented missing winch".into(),
|
||||
},
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("custody"));
|
||||
assert_eq!(value, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn member_outcome_preserves_its_own_relationship_without_mutating_the_player() {
|
||||
let mut value = hierarchical_refugee_campaign();
|
||||
value.agency_relations.insert(
|
||||
"refugee-message-to-player".into(),
|
||||
AgencyRelation {
|
||||
schema: "ghostlight.agency_relation.v1".into(),
|
||||
id: "refugee-message-to-player".into(),
|
||||
from_subject_id: "refugees-east".into(),
|
||||
to_subject_id: "player".into(),
|
||||
kind: AgencyRelationKind::Communication,
|
||||
strength: 40,
|
||||
active: true,
|
||||
evidence_receipt_ids: vec![],
|
||||
},
|
||||
);
|
||||
let player_before = value.actors["player"].clone();
|
||||
let digest = test_action_digest("mira renews her promise");
|
||||
apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
member_activities: vec![StrategicMemberActivity {
|
||||
action_digest: digest.clone(),
|
||||
member_id: "mira".into(),
|
||||
source_gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec!["player".into()],
|
||||
location_ids: vec!["camp".into()],
|
||||
public_channels: vec![],
|
||||
}],
|
||||
activity_outcomes: vec![StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest: digest,
|
||||
source_subject_id: "member:mira".into(),
|
||||
band: StrategicOutcomeBand::Success,
|
||||
summary: "Mira keeps the promise alive despite the distance.".into(),
|
||||
supporting_state_references: vec!["member:mira".into()],
|
||||
effect: StrategicOutcomeEffect::MemberRelationship {
|
||||
member_id: "mira".into(),
|
||||
other_subject_id: "player".into(),
|
||||
description: "intends to find and repay the rescuer after settling".into(),
|
||||
},
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(value.actors["player"], player_before);
|
||||
assert_eq!(
|
||||
value.gestalt_members["mira"].relationships["player"],
|
||||
"intends to find and repay the rescuer after settling"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2934,8 +3462,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("local refugee investigation"),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Investigate,
|
||||
target_subject_ids: vec![],
|
||||
|
|
@ -2943,7 +3472,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
|
|
@ -2961,8 +3490,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("local refugee communication"),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec![],
|
||||
|
|
@ -2970,7 +3500,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
|
|
@ -2989,8 +3519,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
member_activities: vec![StrategicMemberActivity {
|
||||
action_digest: test_action_digest("mira local communication"),
|
||||
member_id: "mira".into(),
|
||||
source_gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
|
|
@ -2999,7 +3530,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
|
|
@ -3024,8 +3555,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("neighbors address mira"),
|
||||
gestalt_id: "dock-neighbors".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec!["member:mira".into()],
|
||||
|
|
@ -3033,11 +3565,11 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(
|
||||
events[0].summary,
|
||||
"South dock neighbors sends a communication to Mira Venn."
|
||||
|
|
@ -3052,8 +3584,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let error = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("remote address mira"),
|
||||
gestalt_id: "dock-neighbors".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec!["member:mira".into()],
|
||||
|
|
@ -3061,7 +3594,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("exact graph or location scope"));
|
||||
|
|
@ -3090,8 +3623,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let error = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
gestalt_activities: vec![StrategicGestaltActivity {
|
||||
action_digest: test_action_digest("nonadjacent communication"),
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
target_subject_ids: vec!["distant-crowd".into()],
|
||||
|
|
@ -3099,7 +3633,7 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("exact graph or location scope"));
|
||||
|
|
@ -3112,8 +3646,9 @@ mod tests {
|
|||
let before = value.clone();
|
||||
let events = apply_strategic_tick_plan(
|
||||
&mut value,
|
||||
StrategicTickPlan {
|
||||
resolve_test_activities(StrategicTickPlan {
|
||||
member_activities: vec![StrategicMemberActivity {
|
||||
action_digest: test_action_digest("mira addresses refugees"),
|
||||
member_id: "mira".into(),
|
||||
source_gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Communicate,
|
||||
|
|
@ -3122,11 +3657,11 @@ mod tests {
|
|||
public_channels: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(value, before);
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(events[0].kind, "gestalt_member_activity");
|
||||
assert_eq!(
|
||||
events[0].summary,
|
||||
|
|
@ -4263,6 +4798,7 @@ mod tests {
|
|||
})
|
||||
.collect(),
|
||||
cover,
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: hashes,
|
||||
}
|
||||
}
|
||||
|
|
@ -4510,6 +5046,177 @@ mod tests {
|
|||
assert_eq!(stored.world_time, seed.world_time);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn activity_outcome_receipt_must_bind_the_exact_selected_digest_set() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = CampaignStore::open(dir.path().join("campaign.cc")).unwrap();
|
||||
let kernel = WorldKernel::start(store.clone());
|
||||
let seed = hierarchical_refugee_campaign();
|
||||
kernel
|
||||
.command(WorldCommand::CreateCampaign {
|
||||
campaign: seed.clone(),
|
||||
evidence_receipts: vec![],
|
||||
model_stage_receipts: vec![],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let persisted = store
|
||||
.load::<Campaign>("campaign.v1", &seed.id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
let mut wave = inaction_wave(&persisted, &store);
|
||||
let appraisal = wave
|
||||
.appraisals
|
||||
.iter_mut()
|
||||
.find(|appraisal| appraisal.considered_subject_ids.contains("refugees-east"))
|
||||
.unwrap();
|
||||
let proposal = CellActionProposal {
|
||||
subject_id: "refugees-east".into(),
|
||||
intent: "prepare storm lashings".into(),
|
||||
intended_effect: "finish one bounded set of camp lashings".into(),
|
||||
priority: 60,
|
||||
state_references: vec![
|
||||
"subject:refugees-east".into(),
|
||||
"capability:survive transit".into(),
|
||||
"location:camp".into(),
|
||||
],
|
||||
public_channels: vec![],
|
||||
effect: StrategicCellEffect::GestaltActivity {
|
||||
gestalt_id: "refugees-east".into(),
|
||||
activity: StrategicActivityKind::Prepare,
|
||||
target_subject_ids: vec![],
|
||||
location_ids: vec!["camp".into()],
|
||||
},
|
||||
};
|
||||
let action_digest = crate::resolution::cell_action_digest(&proposal).unwrap();
|
||||
appraisal.actions = vec![proposal];
|
||||
appraisal.inactions.clear();
|
||||
let appraisal_cell_id = appraisal.cell_id.clone();
|
||||
let appraisal_actions = appraisal.actions.clone();
|
||||
wave.activity_outcomes = vec![StrategicActivityOutcome {
|
||||
schema: "ghostlight.strategic_activity_outcome.v1".into(),
|
||||
action_digest: action_digest.clone(),
|
||||
source_subject_id: "refugees-east".into(),
|
||||
band: StrategicOutcomeBand::Success,
|
||||
summary: "The camp finishes one set of storm lashings.".into(),
|
||||
supporting_state_references: vec!["capability:survive transit".into()],
|
||||
effect: StrategicOutcomeEffect::ResourceCreated {
|
||||
owner_subject_id: "refugees-east".into(),
|
||||
resource: "storm lashings".into(),
|
||||
},
|
||||
}];
|
||||
|
||||
let base_binding = format!(
|
||||
"campaign:{}:revision:{}:resolution:{}:cell:{}",
|
||||
persisted.id,
|
||||
persisted.revision,
|
||||
persisted.resolution_policy.resolution_epoch,
|
||||
appraisal_cell_id
|
||||
);
|
||||
let mut verifier =
|
||||
resolution_stage(&appraisal_cell_id, &persisted, "cell_effect_verifier", '7');
|
||||
verifier.snapshot_binding =
|
||||
crate::persona::cell_effect_verification_binding(&base_binding, &appraisal_actions)
|
||||
.unwrap();
|
||||
let wrong_outcome = resolution_stage(
|
||||
&appraisal_cell_id,
|
||||
&persisted,
|
||||
"strategic_outcome_resolver",
|
||||
'8',
|
||||
);
|
||||
for receipt in [verifier, wrong_outcome] {
|
||||
store
|
||||
.insert(
|
||||
"persona_stage_receipt.v1",
|
||||
"ghostlight.persona_stage_receipt.v1",
|
||||
receipt.storage_key(),
|
||||
&receipt,
|
||||
)
|
||||
.unwrap();
|
||||
wave.model_receipt_hashes
|
||||
.push(receipt.storage_key().to_owned());
|
||||
}
|
||||
let mut correct_wave = wave.clone();
|
||||
let mut correct_outcome = resolution_stage(
|
||||
&appraisal_cell_id,
|
||||
&persisted,
|
||||
"strategic_outcome_resolver",
|
||||
'9',
|
||||
);
|
||||
correct_outcome.snapshot_binding = crate::outcome::activity_outcome_binding(
|
||||
persisted.id,
|
||||
persisted.revision,
|
||||
persisted.resolution_policy.resolution_epoch,
|
||||
&[action_digest],
|
||||
);
|
||||
store
|
||||
.insert(
|
||||
"persona_stage_receipt.v1",
|
||||
"ghostlight.persona_stage_receipt.v1",
|
||||
correct_outcome.storage_key(),
|
||||
&correct_outcome,
|
||||
)
|
||||
.unwrap();
|
||||
correct_wave.model_receipt_hashes.pop();
|
||||
correct_wave
|
||||
.model_receipt_hashes
|
||||
.push(correct_outcome.storage_key().to_owned());
|
||||
|
||||
let error = kernel
|
||||
.command(WorldCommand::AdvanceStrategicTick {
|
||||
expected_revision: 0,
|
||||
source: TickSource::Scheduler,
|
||||
plan: None,
|
||||
model_receipt_hash: Some(format!("sha256:{}", "9".repeat(64))),
|
||||
resolution_wave: Some(wave),
|
||||
})
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("lacks an activity-bound strategic outcome receipt"),
|
||||
"unexpected kernel rejection: {error}"
|
||||
);
|
||||
let stored = store
|
||||
.load::<Campaign>("campaign.v1", &seed.id.to_string())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(stored.revision, 0);
|
||||
assert_eq!(stored.world_time, seed.world_time);
|
||||
assert!(
|
||||
!stored.gestalts["refugees-east"]
|
||||
.resources
|
||||
.contains("storm lashings")
|
||||
);
|
||||
|
||||
let result = kernel
|
||||
.command(WorldCommand::AdvanceStrategicTick {
|
||||
expected_revision: 0,
|
||||
source: TickSource::Scheduler,
|
||||
plan: None,
|
||||
model_receipt_hash: Some(format!("sha256:{}", "a".repeat(64))),
|
||||
resolution_wave: Some(correct_wave),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let CommandResult::Committed { campaign, .. } = result else {
|
||||
panic!()
|
||||
};
|
||||
assert_eq!(campaign.revision, 1);
|
||||
assert!(
|
||||
campaign.gestalts["refugees-east"]
|
||||
.resources
|
||||
.contains("storm lashings")
|
||||
);
|
||||
assert_eq!(
|
||||
store.keys("strategic_activity_outcome.v1").unwrap().len(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stale_resolution_wave_leaves_time_clocks_and_campaign_unmutated() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ pub mod kernel;
|
|||
pub mod mesh;
|
||||
pub mod model;
|
||||
pub mod narrator;
|
||||
pub mod outcome;
|
||||
pub mod persistence;
|
||||
pub mod persona;
|
||||
pub mod registry;
|
||||
|
|
|
|||
|
|
@ -1518,6 +1518,7 @@ async fn refresh_mesh(state: &AppState) -> anyhow::Result<serde_json::Value> {
|
|||
rejected: runtime.store.load_all("rejected_proposal_receipt.v1")?,
|
||||
resolution_plans: runtime.store.load_all("resolution_plan_receipt.v1")?,
|
||||
cell_appraisals: runtime.store.load_all("cell_appraisal.v1")?,
|
||||
activity_outcomes: runtime.store.load_all("strategic_activity_outcome.v1")?,
|
||||
resolution_controls: runtime.store.load_all("resolution_control_receipt.v1")?,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ use crate::{
|
|||
RegionExpansionPreview, RejectedProposalReceipt, RelationshipState,
|
||||
ResolutionControlReceipt, ResolutionCover, ResolutionDemand, ResolutionPin,
|
||||
ResolutionPlanReceipt, ResolutionPolicy, RollReceipt, SimulationCell,
|
||||
StrategicGestaltMigration, StrategicMemberMigration, StrategicTickPlan,
|
||||
StrategicTickReceipt, VaultEvidenceReceipt, VaultManifest, WorldActionProposal, WorldClock,
|
||||
WorldCommitReceipt, WorldCompilePreview, WorldFact,
|
||||
StrategicActivityOutcome, StrategicGestaltMigration, StrategicMemberMigration,
|
||||
StrategicTickPlan, StrategicTickReceipt, VaultEvidenceReceipt, VaultManifest,
|
||||
WorldActionProposal, WorldClock, WorldCommitReceipt, WorldCompilePreview, WorldFact,
|
||||
},
|
||||
model::ModelStageReceipt,
|
||||
surface::{operator_surface, player_surface},
|
||||
|
|
@ -43,6 +43,7 @@ pub struct CampaignMeshSnapshot {
|
|||
pub rejected: Vec<RejectedProposalReceipt>,
|
||||
pub resolution_plans: Vec<ResolutionPlanReceipt>,
|
||||
pub cell_appraisals: Vec<CellAppraisal>,
|
||||
pub activity_outcomes: Vec<StrategicActivityOutcome>,
|
||||
pub resolution_controls: Vec<ResolutionControlReceipt>,
|
||||
}
|
||||
|
||||
|
|
@ -279,6 +280,7 @@ impl MeshPublisher {
|
|||
&snapshot.rejected,
|
||||
&snapshot.resolution_plans,
|
||||
&snapshot.cell_appraisals,
|
||||
&snapshot.activity_outcomes,
|
||||
&snapshot.resolution_controls,
|
||||
live_turn_pressure,
|
||||
);
|
||||
|
|
@ -405,6 +407,11 @@ fn schema_catalog() -> Value {
|
|||
let schemas = catalog
|
||||
.as_object_mut()
|
||||
.expect("schema catalog literal is an object");
|
||||
schemas.insert(
|
||||
"ghostlight.strategic_activity_outcome.v1".into(),
|
||||
serde_json::to_value(schemars::schema_for!(StrategicActivityOutcome))
|
||||
.expect("strategic activity outcome schema serializes"),
|
||||
);
|
||||
schemas.insert(
|
||||
"ghostlight.gestalt_migration.v1".into(),
|
||||
serde_json::to_value(schemars::schema_for!(StrategicGestaltMigration))
|
||||
|
|
|
|||
1332
crates/ghostlight-dungeon/src/outcome.rs
Normal file
1332
crates/ghostlight-dungeon/src/outcome.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -312,6 +312,17 @@ impl CampaignStore {
|
|||
appraisal,
|
||||
)?);
|
||||
}
|
||||
for outcome in &wave.activity_outcomes {
|
||||
rows.push(envelope(
|
||||
"strategic_activity_outcome.v1",
|
||||
"ghostlight.strategic_activity_outcome.v1",
|
||||
&format!(
|
||||
"{}:{}:{}",
|
||||
next.revision, wave.resolution_epoch, outcome.action_digest
|
||||
),
|
||||
outcome,
|
||||
)?);
|
||||
}
|
||||
}
|
||||
if !self
|
||||
.inner
|
||||
|
|
|
|||
|
|
@ -1564,10 +1564,23 @@ pub fn plan_receipt(campaign: &Campaign, cover: &ResolutionCover) -> ResolutionP
|
|||
}
|
||||
}
|
||||
|
||||
pub fn validate_and_resolve_wave(
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ResolutionWaveSelection {
|
||||
pub plan: StrategicTickPlan,
|
||||
pub activity_proposals: Vec<CellActionProposal>,
|
||||
}
|
||||
|
||||
pub fn cell_action_digest(proposal: &CellActionProposal) -> Result<String> {
|
||||
Ok(format!(
|
||||
"sha256:{:x}",
|
||||
Sha256::digest(rmp_serde::to_vec_named(proposal)?)
|
||||
))
|
||||
}
|
||||
|
||||
pub fn select_resolution_wave(
|
||||
campaign: &Campaign,
|
||||
wave: &ResolutionWaveCommit,
|
||||
) -> Result<StrategicTickPlan> {
|
||||
) -> Result<ResolutionWaveSelection> {
|
||||
if wave.world_revision != campaign.revision
|
||||
|| wave.resolution_epoch != campaign.resolution_policy.resolution_epoch
|
||||
|| wave.cover.world_revision != campaign.revision
|
||||
|
|
@ -1655,11 +1668,19 @@ pub fn validate_and_resolve_wave(
|
|||
let consequence_limit = 16usize.min(usize::from(wave.cover.effective_budget) * 2);
|
||||
let mut used = BTreeSet::new();
|
||||
let mut plan = StrategicTickPlan::default();
|
||||
let mut activity_proposals = Vec::new();
|
||||
for proposal in proposals {
|
||||
let key = proposal_target_key(&proposal);
|
||||
if !used.insert(key) {
|
||||
continue;
|
||||
}
|
||||
let action_digest = cell_action_digest(&proposal)?;
|
||||
let is_activity = matches!(
|
||||
proposal.effect,
|
||||
StrategicCellEffect::GestaltActivity { .. }
|
||||
| StrategicCellEffect::MemberActivity { .. }
|
||||
);
|
||||
let selected_activity_proposal = is_activity.then(|| proposal.clone());
|
||||
match proposal.effect {
|
||||
StrategicCellEffect::Institution {
|
||||
institution_id,
|
||||
|
|
@ -1687,6 +1708,7 @@ pub fn validate_and_resolve_wave(
|
|||
target_subject_ids,
|
||||
location_ids,
|
||||
} => plan.gestalt_activities.push(StrategicGestaltActivity {
|
||||
action_digest,
|
||||
gestalt_id,
|
||||
activity,
|
||||
target_subject_ids,
|
||||
|
|
@ -1723,6 +1745,7 @@ pub fn validate_and_resolve_wave(
|
|||
} => {
|
||||
let source_gestalt_id = campaign.gestalt_members[&member_id].gestalt_id.clone();
|
||||
plan.member_activities.push(StrategicMemberActivity {
|
||||
action_digest,
|
||||
member_id,
|
||||
source_gestalt_id,
|
||||
activity,
|
||||
|
|
@ -1752,6 +1775,9 @@ pub fn validate_and_resolve_wave(
|
|||
});
|
||||
}
|
||||
}
|
||||
if let Some(proposal) = selected_activity_proposal {
|
||||
activity_proposals.push(proposal);
|
||||
}
|
||||
if plan.institution_actions.len()
|
||||
+ plan.gestalt_actions.len()
|
||||
+ plan.gestalt_activities.len()
|
||||
|
|
@ -1764,7 +1790,24 @@ pub fn validate_and_resolve_wave(
|
|||
break;
|
||||
}
|
||||
}
|
||||
Ok(plan)
|
||||
Ok(ResolutionWaveSelection {
|
||||
plan,
|
||||
activity_proposals,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn validate_and_resolve_wave(
|
||||
campaign: &Campaign,
|
||||
wave: &ResolutionWaveCommit,
|
||||
) -> Result<StrategicTickPlan> {
|
||||
let mut selection = select_resolution_wave(campaign, wave)?;
|
||||
crate::outcome::validate_activity_outcomes(
|
||||
campaign,
|
||||
&selection.activity_proposals,
|
||||
&wave.activity_outcomes,
|
||||
)?;
|
||||
selection.plan.activity_outcomes = wave.activity_outcomes.clone();
|
||||
Ok(selection.plan)
|
||||
}
|
||||
|
||||
fn validate_cell_proposal(
|
||||
|
|
@ -3113,6 +3156,7 @@ pub(crate) mod tests {
|
|||
inactions: vec![],
|
||||
}],
|
||||
cover: cover.clone(),
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: vec![],
|
||||
};
|
||||
let collective = CellActionProposal {
|
||||
|
|
@ -3286,6 +3330,7 @@ pub(crate) mod tests {
|
|||
inactions: vec![],
|
||||
}],
|
||||
cover: cover.clone(),
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: vec![],
|
||||
};
|
||||
let plan = validate_and_resolve_wave(&value, &make_wave(proposal.clone())).unwrap();
|
||||
|
|
@ -3305,8 +3350,9 @@ pub(crate) mod tests {
|
|||
location_ids: vec!["center".into()],
|
||||
},
|
||||
};
|
||||
let activity_plan =
|
||||
validate_and_resolve_wave(&value, &make_wave(member_activity.clone())).unwrap();
|
||||
let activity_plan = select_resolution_wave(&value, &make_wave(member_activity.clone()))
|
||||
.unwrap()
|
||||
.plan;
|
||||
assert_eq!(activity_plan.member_activities.len(), 1);
|
||||
assert!(activity_plan.member_migrations.is_empty());
|
||||
|
||||
|
|
@ -3318,7 +3364,7 @@ pub(crate) mod tests {
|
|||
unreachable!()
|
||||
};
|
||||
target_subject_ids.clear();
|
||||
assert!(validate_and_resolve_wave(&value, &make_wave(local_member_communication)).is_ok());
|
||||
assert!(select_resolution_wave(&value, &make_wave(local_member_communication)).is_ok());
|
||||
|
||||
let same_member_wave = ResolutionWaveCommit {
|
||||
schema: "ghostlight.resolution_wave_commit.v1".into(),
|
||||
|
|
@ -3335,9 +3381,12 @@ pub(crate) mod tests {
|
|||
inactions: vec![],
|
||||
}],
|
||||
cover: cover.clone(),
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: vec![],
|
||||
};
|
||||
let same_member_plan = validate_and_resolve_wave(&value, &same_member_wave).unwrap();
|
||||
let same_member_plan = select_resolution_wave(&value, &same_member_wave)
|
||||
.unwrap()
|
||||
.plan;
|
||||
assert_eq!(same_member_plan.member_activities.len(), 1);
|
||||
assert!(same_member_plan.member_migrations.is_empty());
|
||||
|
||||
|
|
@ -3374,7 +3423,9 @@ pub(crate) mod tests {
|
|||
},
|
||||
};
|
||||
let activity_plan =
|
||||
validate_and_resolve_wave(&value, &make_wave(exact_rival_activity.clone())).unwrap();
|
||||
select_resolution_wave(&value, &make_wave(exact_rival_activity.clone()))
|
||||
.unwrap()
|
||||
.plan;
|
||||
assert_eq!(activity_plan.gestalt_activities.len(), 1);
|
||||
assert!(activity_plan.gestalt_actions.is_empty());
|
||||
|
||||
|
|
@ -3406,15 +3457,18 @@ pub(crate) mod tests {
|
|||
inactions: vec![],
|
||||
}],
|
||||
cover: cover.clone(),
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: vec![],
|
||||
};
|
||||
let same_subject_plan = validate_and_resolve_wave(&value, &same_subject_wave).unwrap();
|
||||
let same_subject_plan = select_resolution_wave(&value, &same_subject_wave)
|
||||
.unwrap()
|
||||
.plan;
|
||||
assert_eq!(same_subject_plan.gestalt_activities.len(), 1);
|
||||
assert!(same_subject_plan.gestalt_actions.is_empty());
|
||||
|
||||
let mut borrowed_rival_channel = exact_rival_activity.clone();
|
||||
borrowed_rival_channel.public_channels = vec!["private dock code".into()];
|
||||
assert!(validate_and_resolve_wave(&value, &make_wave(borrowed_rival_channel)).is_err());
|
||||
assert!(select_resolution_wave(&value, &make_wave(borrowed_rival_channel)).is_err());
|
||||
|
||||
let mut invented_target = exact_rival_activity;
|
||||
let StrategicCellEffect::GestaltActivity {
|
||||
|
|
@ -3424,7 +3478,7 @@ pub(crate) mod tests {
|
|||
unreachable!()
|
||||
};
|
||||
*target_subject_ids = vec!["unseen-stranger".into()];
|
||||
assert!(validate_and_resolve_wave(&value, &make_wave(invented_target)).is_err());
|
||||
assert!(select_resolution_wave(&value, &make_wave(invented_target)).is_err());
|
||||
|
||||
assert!(strategic_activity_targets(&value, "dockers").contains("member:mira"));
|
||||
let address_mira = CellActionProposal {
|
||||
|
|
@ -3441,7 +3495,9 @@ pub(crate) mod tests {
|
|||
location_ids: vec!["center".into()],
|
||||
},
|
||||
};
|
||||
let address_plan = validate_and_resolve_wave(&value, &make_wave(address_mira)).unwrap();
|
||||
let address_plan = select_resolution_wave(&value, &make_wave(address_mira))
|
||||
.unwrap()
|
||||
.plan;
|
||||
assert_eq!(address_plan.gestalt_activities.len(), 1);
|
||||
assert_eq!(address_plan.gestalt_activities[0].gestalt_id, "dockers");
|
||||
assert_eq!(
|
||||
|
|
@ -3488,6 +3544,7 @@ pub(crate) mod tests {
|
|||
inactions: vec![],
|
||||
}],
|
||||
cover,
|
||||
activity_outcomes: vec![],
|
||||
model_receipt_hashes: vec![],
|
||||
};
|
||||
let plan = validate_and_resolve_wave(&value, &wave).unwrap();
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ use crate::{
|
|||
SimulationCell,
|
||||
},
|
||||
model::{ModelPort, ModelStageOutput, ModelStageRequest, run_validated_stage},
|
||||
outcome::{activity_outcome_binding, resolve_activity_outcomes},
|
||||
persona::{
|
||||
CellConstituentSlice, CellMemberSlice, CellPerceivedEventSlice, CellProjectionEngine,
|
||||
ExecutionPermit, PermittedCellSlice,
|
||||
},
|
||||
resolution::{
|
||||
cell_action_limit, default_demand, plan_cover, plan_receipt, validate_and_resolve_wave,
|
||||
validate_demand,
|
||||
cell_action_digest, cell_action_limit, default_demand, plan_cover, plan_receipt,
|
||||
select_resolution_wave, validate_and_resolve_wave, validate_demand,
|
||||
},
|
||||
};
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
|
|
@ -57,6 +58,8 @@ pub async fn propose_resolution_wave(
|
|||
let (demand, mut stages) = project_resolution_demand(model.as_ref(), campaign).await;
|
||||
let cover = plan_cover(campaign, demand)?;
|
||||
let receipt = plan_receipt(campaign, &cover);
|
||||
let outcome_model = model.clone();
|
||||
let outcome_permit = permit.clone();
|
||||
let engine = CellProjectionEngine {
|
||||
model,
|
||||
permit,
|
||||
|
|
@ -110,24 +113,67 @@ pub async fn propose_resolution_wave(
|
|||
}),
|
||||
);
|
||||
}
|
||||
let model_receipt_hashes = stages
|
||||
let cell_model_receipt_hashes = stages
|
||||
.iter()
|
||||
.map(|stage| stage.receipt.storage_key().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
let aggregate_receipt_hash = format!(
|
||||
"sha256:{:x}",
|
||||
Sha256::digest(model_receipt_hashes.join("|").as_bytes())
|
||||
);
|
||||
let wave = ResolutionWaveCommit {
|
||||
let mut wave = ResolutionWaveCommit {
|
||||
schema: "ghostlight.resolution_wave_commit.v1".into(),
|
||||
world_revision: campaign.revision,
|
||||
resolution_epoch: campaign.resolution_policy.resolution_epoch,
|
||||
cover,
|
||||
plan_receipt: receipt,
|
||||
appraisals,
|
||||
model_receipt_hashes,
|
||||
activity_outcomes: Vec::new(),
|
||||
model_receipt_hashes: cell_model_receipt_hashes,
|
||||
};
|
||||
let selection = select_resolution_wave(campaign, &wave)?;
|
||||
let outcome_digests = selection
|
||||
.activity_proposals
|
||||
.iter()
|
||||
.map(cell_action_digest)
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let outcome_binding = activity_outcome_binding(
|
||||
campaign.id,
|
||||
campaign.revision,
|
||||
campaign.resolution_policy.resolution_epoch,
|
||||
&outcome_digests,
|
||||
);
|
||||
if !outcome_digests.is_empty() {
|
||||
outcome_permit
|
||||
.require(
|
||||
"strategic-outcomes",
|
||||
&outcome_binding,
|
||||
"strategic_outcome_resolver",
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
let (activity_outcomes, outcome_stages) = resolve_activity_outcomes(
|
||||
outcome_model.as_ref(),
|
||||
campaign,
|
||||
&selection.activity_proposals,
|
||||
)
|
||||
.await?;
|
||||
if !outcome_digests.is_empty() {
|
||||
outcome_permit
|
||||
.require(
|
||||
"strategic-outcomes",
|
||||
&outcome_binding,
|
||||
"strategic_outcome_terminal",
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
stages.extend(outcome_stages);
|
||||
wave.activity_outcomes = activity_outcomes;
|
||||
wave.model_receipt_hashes = stages
|
||||
.iter()
|
||||
.map(|stage| stage.receipt.storage_key().to_owned())
|
||||
.collect();
|
||||
validate_and_resolve_wave(campaign, &wave)?;
|
||||
let aggregate_receipt_hash = format!(
|
||||
"sha256:{:x}",
|
||||
Sha256::digest(wave.model_receipt_hashes.join("|").as_bytes())
|
||||
);
|
||||
Ok(StrategicResolutionOutput {
|
||||
wave,
|
||||
stages,
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ pub fn operator_surface(
|
|||
rejected: &[RejectedProposalReceipt],
|
||||
resolution_plans: &[crate::domain::ResolutionPlanReceipt],
|
||||
cell_appraisals: &[crate::domain::CellAppraisal],
|
||||
activity_outcomes: &[crate::domain::StrategicActivityOutcome],
|
||||
resolution_controls: &[crate::domain::ResolutionControlReceipt],
|
||||
live_turn_pressure: usize,
|
||||
) -> Value {
|
||||
|
|
@ -205,6 +206,7 @@ pub fn operator_surface(
|
|||
"rejected_proposals": rejected,
|
||||
"resolution_plan_receipts": resolution_plans,
|
||||
"cell_appraisals": cell_appraisals,
|
||||
"strategic_activity_outcomes": activity_outcomes,
|
||||
"resolution_control_receipts": resolution_controls,
|
||||
"scheduler": {"live_turn_pressure": live_turn_pressure}
|
||||
});
|
||||
|
|
@ -223,6 +225,7 @@ pub fn operator_surface(
|
|||
{"id":"dungeon.operator.status","kind":"card","props":{"title":format!("Revision {} · {} model stages / {} provider attempts · {} tokens · {} rejected proposals",campaign.revision,stages.len(),provider_attempt_count,token_usage.total_tokens,rejected.len())},"children":[{"id":"dungeon.operator.usage","kind":"text","props":{"value":format!("Prompt {} (cache hit {}, miss {}, {}%) · completion {} · reasoning {} · retries {}",token_usage.prompt_tokens,token_usage.prompt_cache_hit_tokens,token_usage.prompt_cache_miss_tokens,cache_hit_percent,token_usage.completion_tokens,token_usage.reasoning_tokens,retry_count)},"children":[]}]},
|
||||
{"id":"dungeon.operator.cover","kind":"card","props":{"title":format!("Agency cover · epoch {} · budget {}",campaign.resolution_policy.resolution_epoch,campaign.resolution_policy.active_cell_budget)},"children":[{"id":"dungeon.operator.cover.text","kind":"text","props":{"value":cover_text},"children":[]}]},
|
||||
{"id":"dungeon.operator.graph","kind":"card","props":{"title":format!("Agency graph · {} profiles · {} relations",campaign.agency_profiles.len(),campaign.agency_relations.len())},"children":[{"id":"dungeon.operator.graph.text","kind":"text","props":{"value":graph_text},"children":[]}]},
|
||||
{"id":"dungeon.operator.outcomes","kind":"card","props":{"title":format!("Strategic activity outcomes · {}",activity_outcomes.len())},"children":[{"id":"dungeon.operator.outcomes.text","kind":"text","props":{"value":activity_outcomes.iter().rev().take(16).map(|outcome|format!("{} {:?} — {}",outcome.source_subject_id,outcome.band,outcome.summary)).collect::<Vec<_>>().join("\n")},"children":[]}]},
|
||||
{"id":"dungeon.operator.typed","kind":"code","props":{"language":"json","value":serde_json::to_string_pretty(&typed).unwrap_or_else(|_| "operator projection failed".into())},"children":[]}
|
||||
]},"styles":{"tokens":{"colorBackground":"#0c1110","colorPanel":"#17201d","colorText":"#e8e1cf","colorMuted":"#9aa69f","colorAccent":"#d49b58"}}},
|
||||
"commands":[]
|
||||
|
|
|
|||
|
|
@ -836,6 +836,7 @@ Ghostlight publishes JSON Schema for:
|
|||
- `ghostlight.resolution_control_receipt.v1`
|
||||
- `ghostlight.cell_appraisal.v1`
|
||||
- `ghostlight.cell_action_proposal.v1`
|
||||
- `ghostlight.strategic_activity_outcome.v1`
|
||||
- `ghostlight.gestalt_fission_preview.v1`
|
||||
|
||||
The UI consumes existing `gamecult.eve.surface.v1` and
|
||||
|
|
|
|||
|
|
@ -256,6 +256,75 @@ exact constituent. The kernel validates that subject's knowledge, information
|
|||
channel, resources, authority, relationships, location, and reachable
|
||||
destinations. Secrets are never unioned.
|
||||
|
||||
## Strategic outcome authority
|
||||
|
||||
A valid attributed attempt is not yet a world consequence. The Interpreter
|
||||
owns the narrow claim that a constituent chose an admissible attempt; it does
|
||||
not decide whether the attempt worked, what opposition did, or which durable
|
||||
state changed. Treating the attempt event as a sufficient result made the
|
||||
world busy in prose while its resources, relationships, knowledge, and
|
||||
pressures mostly stood still.
|
||||
|
||||
One wave-level strategic outcome resolver owns that missing decision. It runs
|
||||
after priority and incompatibility selection but before the command enters the
|
||||
kernel:
|
||||
|
||||
1. Ghostlight content-addresses every selected `gestalt_activity` and
|
||||
`member_activity` proposal. The digest binds exact source, intent, intended
|
||||
effect, targets, locations, state references, channels, and typed activity.
|
||||
2. A local context compiler supplies only those selected attempts and their
|
||||
legal consequence handles: source capabilities and holdings, exact target
|
||||
state, active incident relations, current pressures, eligible named-member
|
||||
deltas, and source-discoverable canonical facts.
|
||||
3. One cheap structured model call resolves the batch. It returns exactly one
|
||||
success, mixed, or failure result for every digest and chooses one bounded
|
||||
typed effect, including an explicit `no_material_change` when the attempt
|
||||
cannot honestly alter canonical state.
|
||||
4. Local validation recomputes every permission from the unchanged campaign
|
||||
snapshot. It rejects invented owners, resources, relations, facts, pressure
|
||||
resolutions, player mutation, missing outcomes, duplicate outcomes, and
|
||||
conflicting effect targets. One same-snapshot correction is permitted.
|
||||
5. `WorldKernel` requires the outcome-stage receipt bound to the complete
|
||||
ordered digest set, then applies the plan and all outcomes to one private
|
||||
campaign copy. A late invalid effect aborts the wave; no clock, activity,
|
||||
outcome, detail debt, or world state reaches the committed campaign.
|
||||
|
||||
The public `strategic_activity_outcome.v1` contract is a typed sum. Its MVP
|
||||
effects are deliberately small:
|
||||
|
||||
- create, spend, or give away a resource owned by the acting population or
|
||||
named member;
|
||||
- add or resolve pressure on the acting population or an exact targeted
|
||||
population;
|
||||
- shift one exact active agency relation incident to the source and a supplied
|
||||
target by a bounded amount;
|
||||
- add one memory, obligation, or relationship description to an exact named
|
||||
member who owns that perspective;
|
||||
- learn one exact canonical fact that was discoverable at the attempt location
|
||||
or already known by an exact communication target;
|
||||
- or record an explicit reason why no durable material change occurred.
|
||||
|
||||
The provider boundary uses a flat JSON proposal rather than asking the model to
|
||||
emit the public tagged sum directly. The private flat shape avoids fragile
|
||||
`oneOf` generation; a local interpreter is the only component allowed to turn
|
||||
it into the typed public effect. JSON remains a model-provider boundary. The
|
||||
accepted outcome, its binding, and its receipt are persisted through the
|
||||
campaign's CultCache path.
|
||||
|
||||
Outcome resolution does not grant an arena collective authority. Every result
|
||||
remains bound to the exact constituent proposal digest. A rival can suffer a
|
||||
pressure or relation consequence, but cannot be made to speak, spend a
|
||||
resource, reveal knowledge, or acquire a private relationship as though the
|
||||
arena had chosen for it. Effects on the player are forbidden; accessible news
|
||||
may later reveal a committed consequence, but the absent player is never
|
||||
puppeted or directly harmed.
|
||||
|
||||
The resolver is batched once per strategic wave rather than once per cell or
|
||||
attempt. This keeps the stable rules and schema in one cacheable prompt prefix,
|
||||
lets it compare simultaneous opposition, and spends completion tokens only on
|
||||
the handful of attempts that survived selection. Provider concurrency still
|
||||
controls the preceding Persona-cell wave and does not alter outcome authority.
|
||||
|
||||
## Fairness and quiet-world agency
|
||||
|
||||
Every active profile carries persistent non-fictional `detail_debt`. Aggregate
|
||||
|
|
@ -496,6 +565,8 @@ The schema catalog and CultCache stores publish:
|
|||
`resolution_plan_receipt.v1`, and `resolution_control_receipt.v1`;
|
||||
- `cell_appraisal.v1`, `cell_action_proposal.v1`, and the internal atomic
|
||||
`resolution_wave_commit.v1` bundle;
|
||||
- `strategic_activity_outcome.v1`, persisted individually for inspection and
|
||||
also bound inside the atomic resolution wave;
|
||||
- `gestalt_migration.v1` and `member_migration.v1` as distinct collective and
|
||||
individual movement contracts inside strategic plans;
|
||||
- `gestalt_fission_preview.v1` and approval-gated `FissionGestalt`.
|
||||
|
|
@ -526,6 +597,15 @@ lineage parents as simulation subjects, and repeats the identity/callback check
|
|||
after sustained compression. Both migration endpoints must be active leaves at
|
||||
lineage depth two or greater.
|
||||
|
||||
Both modes distinguish selected attempts from resolved material consequences.
|
||||
The harness counts direct typed transitions and non-`no_material_change`
|
||||
activity outcomes separately, rejects a sustained run that never changes the
|
||||
background world materially, and records every outcome in the private
|
||||
preflight. A named member's dormant delta may now evolve offscreen, but any
|
||||
change to memory, obligation, relationship, equipment, or knowledge must be
|
||||
accounted for by an exact member-bound outcome before the return callback is
|
||||
accepted.
|
||||
|
||||
Fairness acceptance treats a rejected provider wave the same way the daemon's
|
||||
scheduler does: the failed pulse records its private trace and commits nothing;
|
||||
a later pulse may try the same still-current revision again. The harness permits
|
||||
|
|
@ -538,7 +618,7 @@ proof of the attributed-inaction and immutable-batch machinery together. It ran
|
|||
23 sustained waves over 24 active subjects in 742.435 seconds. Every subject
|
||||
received direct resolution attention; 22 background subjects acted, while the
|
||||
two without a committed action were represented by exact attributed inaction.
|
||||
The wave plans committed 175 consequences: 85 population activities, 66
|
||||
The wave plans selected 175 strategic effects: 85 population activities, 66
|
||||
institution postures, 22 named-member activities, one population migration,
|
||||
and one population-pressure transition. The appraisals also retained 179
|
||||
attributed inactions, including 31 cells where some constituents acted while
|
||||
|
|
@ -560,11 +640,14 @@ victory lap. Observed traffic used 1,988,812 prompt and 233,146 completion
|
|||
tokens at a 66.64% prompt-cache hit rate. Nineteen rejected pulses consumed
|
||||
807,304 prompt tokens—40.59% of observed prompt work. Eleven were caught by the
|
||||
action-bound semantic verifier, three by Interpreter semantic validation, two
|
||||
by JSON Schema, and three by transport failure. Most population consequences
|
||||
are still attributed attempts recorded in event history rather than resolved
|
||||
changes to resources, bargains, obligations, relationships, or pressures. A
|
||||
separate strategic outcome resolver must own those material consequences; the
|
||||
Interpreter must not be promoted into asserting success.
|
||||
by JSON Schema, and three by transport failure. In that build, most population
|
||||
effects were still attributed attempts recorded in event history rather than
|
||||
resolved changes to resources, obligations, relationships, knowledge, or
|
||||
pressures. The current candidate adds the separate strategic outcome resolver
|
||||
described above without promoting the Interpreter into asserting success. A
|
||||
revised live result is still required; the `d044951` profile is evidence for
|
||||
cover, fairness, attribution, and atomic batch behavior, not evidence for
|
||||
material activity outcomes.
|
||||
|
||||
The callback and fairness claims are independently falsifiable. Strict live
|
||||
mode requires Mira's Persona to choose resettlement and proves the later
|
||||
|
|
|
|||
|
|
@ -354,16 +354,29 @@ recovered 19 rejected pulses with no partial mutation. Observed usage was
|
|||
1,988,812 prompt / 233,146 completion tokens at 66.64% prompt-cache hits;
|
||||
rejected pulses consumed 807,304 prompt tokens (40.59%). The next efficiency
|
||||
cut is the failed-pulse tail, led by semantic effect-verifier rejection. The
|
||||
next dramatic cut is a separate strategic outcome resolver: 85 committed
|
||||
population activities are still attempts, not enough typed material change.
|
||||
dramatic result was still missing: 85 committed population activities were
|
||||
attempts rather than typed material change.
|
||||
|
||||
Do not call setting-wide material agency finished yet. Most population output
|
||||
is still an attributed `gestalt_activity` attempt stored as history. The long
|
||||
run became repetitive around ferry loading and shelter requests because no
|
||||
separate owner resolved enough attempts into typed resources, bargains,
|
||||
relationships, obligations, or pressure changes. Add a strategic outcome
|
||||
resolver between attributed proposals and WorldKernel commit; do not grant the
|
||||
Interpreter permission to assert successful outcomes.
|
||||
The candidate now contains that separate owner. Priority selection
|
||||
content-addresses each selected population/member activity, one batched Flash
|
||||
stage resolves the exact attempt set, and WorldKernel requires one outcome per
|
||||
digest plus a stage receipt bound to the whole digest set. Outcomes are locally
|
||||
limited to exact resources, population pressures, incident relations,
|
||||
named-member memories/obligations/relationships, discoverable facts, or an
|
||||
explicit no-material-change result. The Interpreter still owns attempts only.
|
||||
Kernel tests prove a wrong outcome binding leaves time and state untouched, a
|
||||
correct binding commits the material result, and a malformed late outcome
|
||||
cannot partially apply an earlier one. CultCache stores outcomes individually
|
||||
and the operator Eve projection exposes them.
|
||||
|
||||
Do not call setting-wide material agency finished until the revised live
|
||||
Gestalt harness passes. It now refuses to count an activity attempt as a
|
||||
material consequence, requires at least one sustained direct or typed material
|
||||
result, and permits Mira's dormant delta to evolve only when an exact
|
||||
member-bound outcome accounts for the change. Run a small golden first, then a
|
||||
budget/parallelism pressure profile; inspect material-outcome rate, no-change
|
||||
rate, retries, cache hits, and player/arena invariants before the two-tester
|
||||
playtest.
|
||||
|
||||
The multiresolution body is deployed on Starfire. Typed health matched the
|
||||
immutable release, DeepSeek was ready, and the disposable live strategic-cell
|
||||
|
|
|
|||
|
|
@ -42,8 +42,10 @@ exact campaign revision
|
|||
-> cohesive or arena simulation-cell cover
|
||||
-> one private Projector/Persona/Interpreter membrane per cell
|
||||
-> model proposes exact constituent-attributed actions or explicit inaction
|
||||
-> runtime selects compatible attempts and content-addresses each activity
|
||||
-> one batched outcome resolver chooses bounded typed consequences
|
||||
-> runtime binds complete cell membership + world/resolution revisions
|
||||
-> WorldKernel validates cover, receipts, knowledge, scope, topology, and bounds
|
||||
-> WorldKernel validates cover, stage/outcome receipts, knowledge, scope, custody, topology, and bounds
|
||||
-> AdvanceStrategicTick through the campaign mailbox
|
||||
-> one atomic campaign/event/news/cover/appraisal commit
|
||||
```
|
||||
|
|
@ -110,11 +112,26 @@ Gestalt background choices use three distinct typed paths. Pressure transitions
|
|||
change exact unresolved markers. `gestalt_activity` records an attributed
|
||||
preparation, coordination, investigation, recruitment, obstruction, trade, or
|
||||
communication attempt against subjects connected by an explicit agency
|
||||
relation or exact shared location without claiming the outcome. A selected
|
||||
relation or exact shared location without claiming the outcome. After
|
||||
selection, one wave-level Flash resolver receives only those attempts and
|
||||
precomputed legal consequence handles. It must return one digest-bound
|
||||
`strategic_activity_outcome.v1` per activity; missing, duplicate, stale,
|
||||
player-mutating, or invented effects reject the entire wave. Accepted outcomes
|
||||
may change exact resources, population pressures, incident agency relations,
|
||||
named-member deltas, or discoverable canonical knowledge, or explicitly record
|
||||
that no durable material change occurred. A selected
|
||||
dormant member can be addressed by their durable ID; this does not union them
|
||||
into the source population. The kernel derives the event text and exact
|
||||
participant IDs; the arena and model prose own neither.
|
||||
|
||||
The outcome resolver does not repair or reinterpret Persona intent. The
|
||||
Interpreter owns the attempt; the resolver owns opposition and result;
|
||||
WorldKernel alone owns mutation. Its stage receipt binds the sorted set of
|
||||
MessagePack proposal digests, and every outcome is stored independently in
|
||||
CultCache and projected on the operator Eve surface. All effects apply to the
|
||||
same private campaign copy as the rest of the strategic wave, so a late invalid
|
||||
outcome cannot leave an earlier action, clock, detail debt, or event committed.
|
||||
|
||||
`gestalt_migration` records a collective decision by one exact active leaf to
|
||||
move along an explicit migration relation and reachable route. WorldKernel
|
||||
changes the leaf's home location and agency-profile location together. The
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ strings are bound to witnesses locally, rejected candidates become coverage
|
|||
gaps, and deterministic coarse profiles keep unknown facets unknown. The Pro
|
||||
agency stage no longer spends output tokens restating remote profiles.
|
||||
|
||||
Strategic activity outcomes now have their own authority between attempt
|
||||
selection and commit. One batched Flash resolver receives only selected
|
||||
digest-bound attempts plus exact legal consequence handles. It emits one
|
||||
bounded typed result per activity; local validation rejects invented custody,
|
||||
relations, facts, pressure resolutions, member owners, and player mutation.
|
||||
WorldKernel requires the action-set-bound stage receipt and applies every
|
||||
outcome with the rest of the wave on one private campaign copy. Accepted
|
||||
outcomes are stored in CultCache and shown through the operator Eve surface.
|
||||
|
||||
The current browser/compiler hardening adds three ownership cuts before the
|
||||
next isolated acceptance run: compiler evidence is triaged into direct,
|
||||
background, and excluded lanes before generation, with only direct source text
|
||||
|
|
@ -65,11 +74,15 @@ ownership, single-use invite rejection, fork/reset/export, four persisted
|
|||
campaigns, and exact-commit restart. Live priority cancels in-flight scheduler
|
||||
inference and excludes its commit gate.
|
||||
|
||||
Next, run the two-tester playtest. Treat player confusion, dramatic flatness,
|
||||
and token-heavy low-consequence stages as evidence about missing context or
|
||||
Next, run the revised Gestalt live golden and a bounded multiresolution pressure
|
||||
profile. The harness must observe real typed background change rather than
|
||||
counting attempts, preserve exact arena/member/player authority, and report
|
||||
material-outcome rate, no-change rate, retries, cache hits, and token cost.
|
||||
Then run the two-tester playtest. Treat player confusion, dramatic flatness, and
|
||||
token-heavy low-consequence stages as evidence about missing context or
|
||||
misplaced authority. Use model-stage cache usage, rejection receipts, cover
|
||||
plans, and world commits to improve satisfaction and cognitive efficiency
|
||||
without weakening state admission.
|
||||
plans, outcomes, and world commits to improve satisfaction and cognitive
|
||||
efficiency without weakening state admission.
|
||||
|
||||
## Prior research-program phase
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue