From 61d8c65e84a17ac0bd7ac28df978ac40acb9dc77 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 23 Aug 2026 03:30:06 +0200 Subject: [PATCH] Isolate Session Zero suggestions from model state --- crates/ghostlight-dungeon/src/session_zero.rs | 195 +++++++++++++++++- .../ghostlight-dungeon-session-zero.md | 14 +- 2 files changed, 205 insertions(+), 4 deletions(-) diff --git a/crates/ghostlight-dungeon/src/session_zero.rs b/crates/ghostlight-dungeon/src/session_zero.rs index 72bf688..25cb4f8 100644 --- a/crates/ghostlight-dungeon/src/session_zero.rs +++ b/crates/ghostlight-dungeon/src/session_zero.rs @@ -1451,6 +1451,7 @@ impl SessionZeroDirector { let mut interpreter_schema = serde_json::to_value(schema_for!(SessionZeroInterpretation))?; require_typed_decision_payloads(&mut interpreter_schema)?; + require_single_lane_ownership(&mut interpreter_schema)?; let interpreter = run_validated_stage( self.model.as_ref(), &ModelStageRequest { @@ -1639,6 +1640,58 @@ fn require_typed_decision_payloads(schema: &mut serde_json::Value) -> Result<()> Ok(()) } +fn require_single_lane_ownership(schema: &mut serde_json::Value) -> Result<()> { + let root = schema + .as_object_mut() + .ok_or_else(|| anyhow!("Session Zero Interpreter schema has no object root"))?; + root.insert( + "allOf".into(), + serde_json::json!([ + { + "if": { + "properties": { + "decisions": { + "contains": { + "required": ["proposed_contract_patch"], + "properties": {"proposed_contract_patch": {"type": "object"}} + } + } + } + }, + "then": { + "properties": { + "contract_patch": {"const": CampaignContractPatch::default()} + } + } + }, + { + "if": { + "properties": { + "decisions": { + "contains": { + "anyOf": [ + { + "required": ["proposed_character_patch"], + "properties": {"proposed_character_patch": {"type": "object"}} + }, + { + "required": ["proposed_extraordinary_permission"], + "properties": {"proposed_extraordinary_permission": {"type": "object"}} + } + ] + } + } + } + }, + "then": { + "properties": {"character_patch": {"type": "null"}} + } + } + ]), + ); + Ok(()) +} + fn require_channel_access_by_member( state: &SessionZeroState, channel_id: &str, @@ -1912,7 +1965,10 @@ fn visible_decisions_for_turn<'a>( .decisions .values() .filter(|decision| { - decision.owner_member_id.is_none() || decision.owner_member_id.as_deref() == member_id + decision.material + && !decision.resolved + && (decision.owner_member_id.is_none() + || decision.owner_member_id.as_deref() == member_id) }) .collect()) } @@ -3655,6 +3711,24 @@ fn validate_dm_delta( } } } + let proposes_contract_decision = delta + .decisions + .iter() + .any(|decision| decision.proposed_contract_patch.is_some()); + if contract_patch_changes_shared(&delta.contract_patch) && proposes_contract_decision { + return Err(anyhow!( + "a DM turn cannot directly edit the contract and offer a contract decision" + )); + } + let proposes_private_decision = delta.decisions.iter().any(|decision| { + decision.proposed_character_patch.is_some() + || decision.proposed_extraordinary_permission.is_some() + }); + if delta.character_patch.is_some() && proposes_private_decision { + return Err(anyhow!( + "a DM turn cannot directly edit a character and offer a private decision" + )); + } validate_bounded("DM speech", &delta.dm_speech, 0, 6_000)?; for reply in &delta.suggested_replies { validate_bounded("suggested reply", reply, 1, 500)?; @@ -4528,6 +4602,125 @@ mod tests { assert!(validator.is_valid(&serde_json::to_value(valid).unwrap())); } + #[test] + fn ui_suggestions_never_enter_dm_or_interpreter_cognition() { + let mut draft = state(); + draft.decisions.insert( + "opening:unselected".into(), + SessionZeroDecision { + schema: "ghostlight.session_zero_decision.v1".into(), + id: "opening:unselected".into(), + owner_member_id: None, + prompt: "Use an unselected opening?".into(), + proposed_resolution: "Age-of-Automation suggestion must remain UI-only.".into(), + proposed_extraordinary_permission: None, + proposed_contract_patch: Some(CampaignContractPatch { + starting_when: Some("Age of Automation (2160-2163)".into()), + ..Default::default() + }), + proposed_character_patch: None, + evidence_receipt_ids: vec![], + pending_counter: None, + material: false, + resolved: false, + }, + ); + draft.decisions.insert( + "decision:material".into(), + SessionZeroDecision { + schema: "ghostlight.session_zero_decision.v1".into(), + id: "decision:material".into(), + owner_member_id: None, + prompt: "Adopt the negotiated post-Burden horizon?".into(), + proposed_resolution: "Begin after Burden of Proof.".into(), + proposed_extraordinary_permission: None, + proposed_contract_patch: Some(CampaignContractPatch { + canon_horizon: Some("After Burden of Proof".into()), + ..Default::default() + }), + proposed_character_patch: None, + evidence_receipt_ids: vec![], + pending_counter: None, + material: true, + resolved: false, + }, + ); + + let dm = permitted_dm_context(&draft, "shared:table", None, None).unwrap(); + let interpreter = + permitted_interpreter_context(&draft, "shared:table", None, None).unwrap(); + for context in [dm, interpreter] { + let rendered = serde_json::to_string(&context).unwrap(); + assert!(!rendered.contains("Age of Automation")); + assert!(!rendered.contains("opening:unselected")); + assert!(rendered.contains("decision:material")); + assert!(rendered.contains("After Burden of Proof")); + } + } + + #[test] + fn dm_turn_cannot_split_one_lane_between_direct_and_decision_ownership() { + let draft = state(); + let duplicate_contract = SessionZeroDelta { + contract_patch: CampaignContractPatch { + canon_horizon: Some("After Burden of Proof".into()), + ..Default::default() + }, + decisions: vec![SessionZeroDecision { + schema: "ghostlight.session_zero_decision.v1".into(), + id: "decision:duplicate-contract".into(), + owner_member_id: None, + prompt: "Adopt the horizon?".into(), + proposed_resolution: "Begin after Burden of Proof.".into(), + proposed_extraordinary_permission: None, + proposed_contract_patch: Some(CampaignContractPatch { + canon_horizon: Some("After Burden of Proof".into()), + ..Default::default() + }), + proposed_character_patch: None, + evidence_receipt_ids: vec![], + pending_counter: None, + material: true, + resolved: false, + }], + ..Default::default() + }; + + let mut schema = serde_json::to_value(schema_for!(SessionZeroInterpretation)).unwrap(); + require_typed_decision_payloads(&mut schema).unwrap(); + require_single_lane_ownership(&mut schema).unwrap(); + let validator = jsonschema::validator_for(&schema).unwrap(); + let split_interpretation = SessionZeroInterpretation { + contract_patch: duplicate_contract.contract_patch.clone(), + decisions: duplicate_contract.decisions.clone(), + ..Default::default() + }; + assert!(!validator.is_valid(&serde_json::to_value(&split_interpretation).unwrap())); + assert!( + validator.is_valid( + &serde_json::to_value(SessionZeroInterpretation { + contract_patch: duplicate_contract.contract_patch.clone(), + ..Default::default() + }) + .unwrap() + ) + ); + assert!( + validator.is_valid( + &serde_json::to_value(SessionZeroInterpretation { + decisions: duplicate_contract.decisions.clone(), + ..Default::default() + }) + .unwrap() + ) + ); + + let error = validate_dm_delta(&draft, "shared:table", None, &duplicate_contract) + .unwrap_err() + .to_string(); + assert!(error.contains("directly edit the contract")); + } + #[test] fn private_dm_context_carries_bounded_public_session_continuity() { let mut draft = state(); diff --git a/docs/architecture/ghostlight-dungeon-session-zero.md b/docs/architecture/ghostlight-dungeon-session-zero.md index 3877b42..9a7e6ca 100644 --- a/docs/architecture/ghostlight-dungeon-session-zero.md +++ b/docs/architecture/ghostlight-dungeon-session-zero.md @@ -75,8 +75,10 @@ Persona while extracting state. The kernel still treats the three stages as one atomic proposal; an invalid Interpreter commits neither speech nor state. The Interpreter receives only the current contract, its channel and member -scope, the entitled private character when applicable, visible typed decisions, -and the exact Persona response. Transcript windows, evidence coverage, +scope, the entitled private character when applicable, unresolved material +decisions, and the exact Persona response. Non-material opening and role cards +remain renderer-visible suggestions but never enter Projector or Interpreter +cognition unless the player explicitly selects or discusses one. Transcript windows, evidence coverage, boundaries, and public-party narrative already served their purpose in the Projector and are not replayed into extraction. It cannot restate existing draft fields or unresolved decisions as new proposals. Stable schema-first @@ -86,9 +88,15 @@ fail, the kernel may append a fixed local DM notice to the conversation while leaving contract, characters, decisions, boundaries, approvals, and model receipts unchanged. +One Interpreter turn has one owner per typed lane. A shared turn may directly +edit the draft contract or offer a contract decision, never both; a private turn +may directly edit the character draft or offer a character/permission decision, +never both. The model-facing schema requests a same-snapshot correction for a +split-lane output, and the kernel repeats the invariant before mutation. + Generated opening and role suggestions are non-material decisions: the player may accept, counter, discuss, or ignore them without blocking a fully custom -draft. On daemon load, the registry demotes pre-cut payloadless questions and +draft. They are UI affordances, not implicit DM memory. On daemon load, the registry demotes pre-cut payloadless questions and generated opening records whose old `material` flags would otherwise veto a custom draft. A payloadless question cannot own compilation readiness because it has no typed change to accept. This migration uses an exact CultCache