From f6891153a589ea227f44535a505f4437591f0b3b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 23 Aug 2026 03:08:02 +0200 Subject: [PATCH] Preserve Eve versions across assessment results --- crates/ghostlight-dungeon/src/app_session.rs | 34 ++++++++++++ crates/ghostlight-dungeon/src/main.rs | 43 +++++++++------ crates/ghostlight-dungeon/src/surface.rs | 52 ++++++++++++------- .../ghostlight-eve-native-interface.md | 11 +++- 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/crates/ghostlight-dungeon/src/app_session.rs b/crates/ghostlight-dungeon/src/app_session.rs index 89a9f04..0e3846b 100644 --- a/crates/ghostlight-dungeon/src/app_session.rs +++ b/crates/ghostlight-dungeon/src/app_session.rs @@ -308,6 +308,22 @@ impl AppSessionOwner { self.commit(next) } + pub fn clear_selected_campaign(&mut self, account_subject_hash: &str) -> anyhow::Result<()> { + let mut next = self.state.clone(); + let preferences = next + .account_preferences + .entry(account_subject_hash.into()) + .or_insert(AccountPreferences { + schema: "ghostlight.account_preferences.v1".into(), + account_subject_hash: account_subject_hash.into(), + selected_campaign_id: None, + updated_at: Utc::now(), + }); + preferences.selected_campaign_id = None; + preferences.updated_at = Utc::now(); + self.commit(next) + } + pub fn migrate_preference( &mut self, account_subject_hash: &str, @@ -510,6 +526,24 @@ mod tests { ); } + #[test] + fn campaign_entry_clears_only_the_selected_preference() { + let directory = tempdir().unwrap(); + let key = directory.path().join("session.key"); + std::fs::write(&key, [7_u8; 32]).unwrap(); + let store = directory.path().join("app-sessions.cc"); + let mut owner = AppSessionOwner::open(&store, &key).unwrap(); + let account = "sha256:player"; + owner + .select_campaign(account, uuid::Uuid::new_v4()) + .unwrap(); + + owner.clear_selected_campaign(account).unwrap(); + + assert_eq!(owner.selected_campaign(account), None); + assert!(owner.state.account_preferences.contains_key(account)); + } + #[test] fn refresh_is_exact_session_cas_and_rotates_private_claim() { let directory = tempdir().unwrap(); diff --git a/crates/ghostlight-dungeon/src/main.rs b/crates/ghostlight-dungeon/src/main.rs index 0937e38..d490a11 100644 --- a/crates/ghostlight-dungeon/src/main.rs +++ b/crates/ghostlight-dungeon/src/main.rs @@ -40,7 +40,9 @@ use ghostlight_dungeon::{ SessionZeroDirector, SessionZeroRegistry, SessionZeroState, publication_from_session, session_zero_surface, }, - surface::player_surface_for_actor, + surface::{ + campaign_interface_version, player_surface_for_actor, rebase_campaign_surface_revision, + }, turn::{SnapshotPermit, appraise_present}, vault::VoidBotMcpVault, }; @@ -772,16 +774,7 @@ async fn current_eve_surface_version(state: &AppState, account_hash: &str) -> an } if let Some(runtime) = session_runtime(state, account_hash).await? { let campaign = load_campaign(&runtime.store)?; - return Ok(campaign - .revision - .saturating_mul(1_000_000_000_000) - .saturating_add( - campaign - .resolution_policy - .resolution_epoch - .saturating_mul(1_000_000), - ) - .saturating_add(campaign.resolution_policy.provider_configuration_epoch)); + return Ok(campaign_interface_version(&campaign)); } if let Some(id) = state .session_zeros @@ -1027,6 +1020,7 @@ fn eve_operation_schema(operation: &str) -> Option<&'static str> { | "session_zero.publish" => "ghostlight.session_zero_revision_command.v1", "session_zero.member.remove" => "ghostlight.session_zero_member_remove.v1", "session_zero.decision.resolve" => "ghostlight.session_zero_decision_resolve.v1", + "campaign.entry" => "ghostlight.campaign_entry.v1", "campaign.select" => "ghostlight.campaign_select.v1", "campaign.contract_review.begin" => "ghostlight.contract_review_begin.v1", "world.speak" => "ghostlight.world_speak.v1", @@ -1409,6 +1403,19 @@ async fn dispatch_eve_product_command( ); } }, + "campaign.entry" => { + match state + .auth + .lock() + .await + .clear_selected_campaign(account_hash) + { + Ok(()) => StatusCode::NO_CONTENT.into_response(), + Err(error) => { + (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response() + } + } + } "world.speak" | "world.assess" | "world.attempt" | "world.wait" => { let (campaign, actor_id) = match current_player_context(state, account_hash).await { Ok(value) => value, @@ -1741,6 +1748,7 @@ fn transient_result_projection( result_version = assessment .get("revision") .and_then(serde_json::Value::as_u64) + .map(|revision| rebase_campaign_surface_revision(source_version, revision)) .unwrap_or(source_version); let digest = assessment.get("digest")?.as_str()?; let admissible = assessment @@ -1810,6 +1818,7 @@ fn transient_result_projection( result_version = receipt .get("revision") .and_then(serde_json::Value::as_u64) + .map(|revision| rebase_campaign_surface_revision(source_version, revision)) .unwrap_or(source_version); let d20 = roll.get("d20")?.as_u64()?; let modifier = roll.get("modifier_total")?.as_i64()?; @@ -6321,12 +6330,12 @@ mod tests { "bargains": ["Acquire an authority that actually reaches the garrison."] } }), - 4, + 4_000_000_000_000, ) .unwrap(); assert_eq!(projection["schema"], "gamecult.eve.surface.v1"); - assert_eq!(projection["version"], 4); + assert_eq!(projection["version"], 4_000_000_000_000_u64); assert!(projection["surface"]["styles"].is_object()); assert!(projection["surface"]["root"]["children"].is_array()); } @@ -6350,11 +6359,11 @@ mod tests { "bargains": [] } }), - 8, + 8_000_000_000_123, ) .unwrap(); - assert_eq!(projection["version"], 9); + assert_eq!(projection["version"], 9_000_000_000_123_u64); let roll = &projection["surface"]["root"]["children"][1]; assert_eq!(roll["kind"], "control.button"); assert_eq!(roll["props"]["command"], "world.attempt"); @@ -6383,11 +6392,11 @@ mod tests { } } }), - 2, + 2_000_000_000_000, ) .unwrap(); - assert_eq!(projection["version"], 3); + assert_eq!(projection["version"], 3_000_000_000_000_u64); assert_eq!( projection["surface"]["root"]["children"][0]["props"]["value"], "d20 12 +3 = 15 against DC 15 — success." diff --git a/crates/ghostlight-dungeon/src/surface.rs b/crates/ghostlight-dungeon/src/surface.rs index f12057f..1639b5f 100644 --- a/crates/ghostlight-dungeon/src/surface.rs +++ b/crates/ghostlight-dungeon/src/surface.rs @@ -7,6 +7,27 @@ use crate::{ }; use serde_json::{Value, json}; +pub const CAMPAIGN_REVISION_SCALE: u64 = 1_000_000_000_000; + +pub fn campaign_interface_version(campaign: &Campaign) -> u64 { + campaign + .revision + .saturating_mul(CAMPAIGN_REVISION_SCALE) + .saturating_add( + campaign + .resolution_policy + .resolution_epoch + .saturating_mul(1_000_000), + ) + .saturating_add(campaign.resolution_policy.provider_configuration_epoch) +} + +pub fn rebase_campaign_surface_revision(source_version: u64, campaign_revision: u64) -> u64 { + campaign_revision + .saturating_mul(CAMPAIGN_REVISION_SCALE) + .saturating_add(source_version % CAMPAIGN_REVISION_SCALE) +} + pub fn player_surface(campaign: &Campaign, narrations: &[NarrationProjection]) -> Value { player_surface_for_actor(campaign, &campaign.player_actor_id, narrations) } @@ -16,16 +37,7 @@ pub fn player_surface_for_actor( viewer_actor_id: &str, narrations: &[NarrationProjection], ) -> Value { - let interface_version = campaign - .revision - .saturating_mul(1_000_000_000_000) - .saturating_add( - campaign - .resolution_policy - .resolution_epoch - .saturating_mul(1_000_000), - ) - .saturating_add(campaign.resolution_policy.provider_configuration_epoch); + let interface_version = campaign_interface_version(campaign); let story = story_nodes(campaign, narrations); let player = &campaign.actors[viewer_actor_id]; let location = &campaign.locations[&player.location_id]; @@ -134,6 +146,13 @@ pub fn player_surface_for_actor( json!({}), &[], ), + command_control( + "dungeon.campaign-entry", + "Campaigns and new Session Zero", + "campaign.entry", + json!({}), + &[], + ), command_control( "dungeon.logout", "Sign out", @@ -202,6 +221,7 @@ pub fn player_surface_for_actor( eve_command("governance.travel.approve","ghostlight.group_travel_approval.v1", &[], "WorldKernel"), eve_command("world.destination.compile","ghostlight.destination_compile.v1", &["destination"], "WorldCompiler"), eve_command("world.destination.approve","ghostlight.destination_approval.v1", &[], "WorldKernel"), + eve_command("campaign.entry","ghostlight.campaign_entry.v1", &[], "ghostlight.account_preferences.v1"), eve_command("campaign.contract_review.begin","ghostlight.contract_review_begin.v1", &[], "SessionZeroKernel"), eve_command("app.auth.logout","ghostlight.app_logout.v1", &[], "ghostlight.app_session.v1") ] @@ -271,16 +291,7 @@ pub fn operator_surface( resolution_controls: &[crate::domain::ResolutionControlReceipt], live_turn_pressure: usize, ) -> Value { - let interface_version = campaign - .revision - .saturating_mul(1_000_000_000_000) - .saturating_add( - campaign - .resolution_policy - .resolution_epoch - .saturating_mul(1_000_000), - ) - .saturating_add(campaign.resolution_policy.provider_configuration_epoch); + let interface_version = campaign_interface_version(campaign); let cover_text = campaign .resolution_cover .as_ref() @@ -589,6 +600,7 @@ mod tests { } assert!(encoded.contains("governance.travel.propose")); assert!(encoded.contains("world.destination.compile")); + assert!(encoded.contains("campaign.entry")); assert!(!encoded.contains("payload.fields")); assert!(!encoded.contains("\"kind\":\"form\"")); } diff --git a/docs/architecture/ghostlight-eve-native-interface.md b/docs/architecture/ghostlight-eve-native-interface.md index 4455b92..3d4fa26 100644 --- a/docs/architecture/ghostlight-eve-native-interface.md +++ b/docs/architecture/ghostlight-eve-native-interface.md @@ -81,7 +81,16 @@ Routine requests use local verified session state. The cookie hash, stable account-subject hash, Heimdall session/revision, capabilities, expiries, and wrapped refresh claim persist in `app-sessions.cc`. Campaign authorization is always derived from `campaign_membership.v1`; account preferences contain only -the selected campaign. +the selected campaign. `campaign.entry` may clear only that preference so the +same authenticated player can return to the campaign list or begin another +Session Zero; it cannot leave, reset, fork, or mutate any campaign. + +Transient command-result surfaces preserve Eve's composite campaign interface +version. A fresh or recompiled assessment may replace only the campaign-revision +component while retaining the resolution and provider-configuration epochs. +The roll control therefore invokes against the same version namespace as the +authoritative `ghostlight.play` surface instead of collapsing it to a raw world +revision. ## Public boundary