diff --git a/crates/ghostlight-dungeon/src/session_zero.rs b/crates/ghostlight-dungeon/src/session_zero.rs index 0c0407c..3215a72 100644 --- a/crates/ghostlight-dungeon/src/session_zero.rs +++ b/crates/ghostlight-dungeon/src/session_zero.rs @@ -405,14 +405,23 @@ pub struct CharacterDraftPatch { pub name: Option, pub public_premise: Option, pub private_history_add: Vec, + pub private_history_remove: Vec, pub secrets_add: Vec, + pub secrets_remove: Vec, pub capabilities_add: Vec, + pub capabilities_remove: Vec, pub knowledge_add: Vec, + pub knowledge_remove: Vec, pub equipment_add: Vec, + pub equipment_remove: Vec, pub relationships: BTreeMap, + pub relationship_removals: Vec, pub obligations_add: Vec, + pub obligations_remove: Vec, pub vulnerabilities_add: Vec, + pub vulnerabilities_remove: Vec, pub goals_add: Vec, + pub goals_remove: Vec, } #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Default)] @@ -2113,13 +2122,21 @@ fn display_character_patch(patch: &CharacterDraftPatch) -> String { } for (values, label) in [ (&patch.private_history_add, "Private history to add"), + (&patch.private_history_remove, "Private history to remove"), (&patch.secrets_add, "Secrets to add"), + (&patch.secrets_remove, "Secrets to remove"), (&patch.capabilities_add, "Capabilities to add"), + (&patch.capabilities_remove, "Capabilities to remove"), (&patch.knowledge_add, "Knowledge to add"), + (&patch.knowledge_remove, "Knowledge to remove"), (&patch.equipment_add, "Equipment to add"), + (&patch.equipment_remove, "Equipment to remove"), (&patch.obligations_add, "Obligations to add"), + (&patch.obligations_remove, "Obligations to remove"), (&patch.vulnerabilities_add, "Vulnerabilities to add"), + (&patch.vulnerabilities_remove, "Vulnerabilities to remove"), (&patch.goals_add, "Goals to add"), + (&patch.goals_remove, "Goals to remove"), ] { if !values.is_empty() { lines.push(format!("{label}: {}", values.join("; "))); @@ -2131,6 +2148,12 @@ fn display_character_patch(patch: &CharacterDraftPatch) -> String { display_relationships(&patch.relationships) )); } + if !patch.relationship_removals.is_empty() { + lines.push(format!( + "Relationship keys to remove: {}", + patch.relationship_removals.join("; ") + )); + } lines.join("\n") } @@ -3891,17 +3914,36 @@ fn apply_character_patch(draft: &mut CharacterDraft, patch: CharacterDraftPatch) if let Some(value) = patch.public_premise { draft.public_premise = value; } + remove_exact(&mut draft.private_history, patch.private_history_remove); extend_unique(&mut draft.private_history, patch.private_history_add); + remove_exact(&mut draft.secrets, patch.secrets_remove); extend_unique(&mut draft.secrets, patch.secrets_add); + remove_exact(&mut draft.capabilities, patch.capabilities_remove); extend_unique(&mut draft.capabilities, patch.capabilities_add); + remove_exact(&mut draft.knowledge, patch.knowledge_remove); extend_unique(&mut draft.knowledge, patch.knowledge_add); + remove_exact(&mut draft.equipment, patch.equipment_remove); extend_unique(&mut draft.equipment, patch.equipment_add); + for key in patch.relationship_removals { + draft.relationships.remove(&key); + } draft.relationships.extend(patch.relationships); + remove_exact(&mut draft.obligations, patch.obligations_remove); extend_unique(&mut draft.obligations, patch.obligations_add); + remove_exact(&mut draft.vulnerabilities, patch.vulnerabilities_remove); extend_unique(&mut draft.vulnerabilities, patch.vulnerabilities_add); + remove_exact(&mut draft.goals, patch.goals_remove); extend_unique(&mut draft.goals, patch.goals_add); } +fn remove_exact(target: &mut Vec, values: Vec) { + if values.is_empty() { + return; + } + let removals = values.into_iter().collect::>(); + target.retain(|value| !removals.contains(value)); +} + fn extend_unique(target: &mut Vec, values: Vec) { for value in values { if !value.trim().is_empty() && !target.contains(&value) { @@ -4767,6 +4809,42 @@ mod tests { .unwrap(); } + #[test] + fn character_patch_can_correct_accepted_identity_without_duplicate_subjects() { + let mut character = CharacterDraft { + relationships: BTreeMap::from([( + "Reed".into(), + "Ash promised not to let Reed disappear into a manifest.".into(), + )]), + capabilities: vec![ + "manifest reconciliation".into(), + "mistaken capability".into(), + ], + ..Default::default() + }; + let full_name = + "Reed — full sung name: Rain gathering every lost footstep beneath one patient wing"; + let patch = CharacterDraftPatch { + relationship_removals: vec!["Reed".into()], + relationships: BTreeMap::from([( + full_name.into(), + "Ash promised not to let Reed disappear into a destination manifest.".into(), + )]), + capabilities_remove: vec!["mistaken capability".into()], + ..Default::default() + }; + let visible = display_character_patch(&patch); + assert!(visible.contains("Relationship keys to remove: Reed")); + assert!(visible.contains("Capabilities to remove: mistaken capability")); + + apply_character_patch(&mut character, patch); + + assert_eq!(character.relationships.len(), 1); + assert!(!character.relationships.contains_key("Reed")); + assert!(character.relationships.contains_key(full_name)); + assert_eq!(character.capabilities, ["manifest reconciliation"]); + } + #[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 480dfee..8a12fb2 100644 --- a/docs/architecture/ghostlight-dungeon-session-zero.md +++ b/docs/architecture/ghostlight-dungeon-session-zero.md @@ -117,6 +117,10 @@ player-entitled draft field, including history, secrets, knowledge, equipment, relationships, goals, and the complete terms of extraordinary permissions. Prose explains a bargain; the visible typed payload is the state the player is actually consenting to. +Character patches are reversible during negotiation. Every list supports exact +removals before additions, and relationship keys support exact removal before a +replacement is installed. This permits spelling, identity, and mistaken-ledger +corrections without duplicate private subjects or transcript replay. Accept applies only the exact typed payload currently stored in the decision. Counter preserves that payload as an inert, visible audit and replacement basis, records the player's text in the decision's durable channel, marks the