diff --git a/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs b/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs new file mode 100644 index 00000000..cda0c26f --- /dev/null +++ b/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs @@ -0,0 +1,91 @@ +use epiphany_core::PersonaIdentity; +use epiphany_core::PersonaInterpreterInput; +use epiphany_core::PersonaProjectorInput; +use epiphany_core::PersonaTurnInput; +use epiphany_core::build_persona_interpreter_prompt; +use epiphany_core::build_persona_projector_prompt; +use epiphany_core::build_persona_turn_prompt; +use epiphany_core::render_persona_semantic_memory_recall; +use epiphany_state_model::EpiphanyMemoryContextPacket; +use epiphany_state_model::EpiphanyMemoryFreshnessStatus; +use epiphany_state_model::EpiphanyMemoryNode; +use epiphany_state_model::EpiphanyMemorySummary; + +fn main() { + let recall = render_persona_semantic_memory_recall(&EpiphanyMemoryContextPacket { + id: "memctx-persona-smoke".to_string(), + query_id: "persona-smoke-current-turn".to_string(), + summaries: vec![EpiphanyMemorySummary { + id: "summary-persona-contracts".to_string(), + target: "role:Persona".to_string(), + claim: "Persona remembers that public speech is a reviewed mouth edge, not raw side effect authority." + .to_string(), + action_implication: "Shape the public voice, then let Mind and the mouth edge route effects." + .to_string(), + freshness: EpiphanyMemoryFreshnessStatus::Ready, + confidence: 84, + ..Default::default() + }], + nodes: vec![EpiphanyMemoryNode { + id: "node-persona-qdrant-pressure".to_string(), + title: "Persona memory retrieval pressure".to_string(), + claim: "VoidBot rebuilds semantic Persona recall from typed memory before each Face turn." + .to_string(), + action_implication: + "Epiphany Persona prompts must receive derived memory recall as hints before speech." + .to_string(), + ..Default::default() + }], + ..Default::default() + }); + + let identity = PersonaIdentity { + identity_id: "epiphany".to_string(), + display_name: "Epiphany".to_string(), + repo_name: "EpiphanyAgent".to_string(), + public_description: "Repo Persona for typed agent substrate.".to_string(), + jurisdiction: vec!["typed state and review-gated agency".to_string()], + }; + + let projector_prompt = build_persona_projector_prompt(&PersonaProjectorInput { + identity: identity.clone(), + semantic_memory_recall: recall.clone(), + ..Default::default() + }); + assert_contains(&projector_prompt, "Semantic memory recall"); + assert_contains(&projector_prompt, "typed memory graph"); + assert_contains(&projector_prompt, "not durable authority"); + + let persona_prompt = build_persona_turn_prompt(&PersonaTurnInput { + identity: identity.clone(), + projected_state: "Epiphany feels the mouth edge as a public contract, not a vent." + .to_string(), + semantic_memory_recall: recall.clone(), + ..Default::default() + }); + assert_contains(&persona_prompt, "Semantic memory recall"); + assert_contains(&persona_prompt, "VoidBot rebuilds semantic Persona recall"); + + let interpreter_prompt = build_persona_interpreter_prompt(&PersonaInterpreterInput { + identity, + persona_prompt, + persona_output: "I can speak, but the effect needs a receipt.".to_string(), + semantic_memory_recall: recall, + pending_mentions: Vec::new(), + allowed_channel_ids: vec!["aquarium".to_string()], + }); + assert_contains(&interpreter_prompt, "Dynamic semantic memory recall"); + assert_contains(&interpreter_prompt, "STATE NOTE"); + assert_contains(&interpreter_prompt, "SAY"); + + println!( + "status=ok recallSource=typed-memory-graph qdrantCache=not-wired personaLayers=projector,persona,interpreter privateStateExposed=false" + ); +} + +fn assert_contains(haystack: &str, needle: &str) { + assert!( + haystack.contains(needle), + "expected prompt to contain `{needle}`" + ); +} diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index de7aa514..4abb89a5 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -610,6 +610,7 @@ pub use persona_turn::build_persona_interpreter_prompt; pub use persona_turn::build_persona_projector_prompt; pub use persona_turn::build_persona_turn_prompt; pub use persona_turn::persona_projected_surface_is_clean; +pub use persona_turn::render_persona_semantic_memory_recall; pub use promotion::EpiphanyPromotionDecision; pub use promotion::EpiphanyPromotionInput; pub use promotion::EpiphanyStateReplacementValidationInput; diff --git a/epiphany-core/src/persona_turn.rs b/epiphany-core/src/persona_turn.rs index 175406d9..012fccb0 100644 --- a/epiphany-core/src/persona_turn.rs +++ b/epiphany-core/src/persona_turn.rs @@ -3,6 +3,7 @@ use crate::EpiphanyOrganDependency; use crate::HeartbeatPendingMention; use crate::default_organ_dependencies_for; use crate::render_organ_dependencies; +use epiphany_state_model::EpiphanyMemoryContextPacket; use serde::Deserialize; use serde::Serialize; @@ -62,6 +63,8 @@ pub struct PersonaProjectorInput { #[serde(default)] pub memory: Option, #[serde(default)] + pub semantic_memory_recall: String, + #[serde(default)] pub pending_mentions: Vec, #[serde(default)] pub repo_activity: Vec, @@ -77,6 +80,8 @@ pub struct PersonaTurnInput { pub identity: PersonaIdentity, pub projected_state: String, #[serde(default)] + pub semantic_memory_recall: String, + #[serde(default)] pub pending_mentions: Vec, #[serde(default)] pub repo_activity: Vec, @@ -93,6 +98,8 @@ pub struct PersonaInterpreterInput { pub persona_prompt: String, pub persona_output: String, #[serde(default)] + pub semantic_memory_recall: String, + #[serde(default)] pub pending_mentions: Vec, #[serde(default)] pub allowed_channel_ids: Vec, @@ -130,6 +137,9 @@ Persona identity: Typed memory packet: {memory} +Semantic memory recall: +{semantic_recall} + Pending addressed pressure: {mentions} @@ -148,6 +158,7 @@ Return only narrative context for the Persona to inhabit. name = input.identity.display_name, identity = render_identity(&input.identity), memory = memory, + semantic_recall = render_semantic_memory_recall_text(&input.semantic_memory_recall), mentions = render_pending_mentions(&input.pending_mentions), activity = render_repo_activity(&input.repo_activity), affordances = render_social_affordances(&input.social_affordances), @@ -171,6 +182,9 @@ Hard boundary: Projected inner state from Imagination: {projected} +Semantic memory recall: +{semantic_recall} + Recent home-repo activity, before room pressure: {activity} @@ -189,6 +203,7 @@ Write one natural Persona turn. name = input.identity.display_name, repo = input.identity.repo_name, projected = input.projected_state.trim(), + semantic_recall = render_semantic_memory_recall_text(&input.semantic_memory_recall), activity = render_repo_activity(&input.repo_activity), mentions = render_pending_mentions(&input.pending_mentions), affordances = render_social_affordances(&input.social_affordances), @@ -223,6 +238,9 @@ Allowed channel ids: Pending addressed pressure: {mentions} +Dynamic semantic memory recall: +{semantic_recall} + Original Persona prompt: ``` {persona_prompt} @@ -239,11 +257,55 @@ Return concise structured effect blocks. No prose outside the blocks. name = input.identity.display_name, channels = render_allowed_channels(&input.allowed_channel_ids), mentions = render_pending_mentions(&input.pending_mentions), + semantic_recall = render_semantic_memory_recall_text(&input.semantic_memory_recall), persona_prompt = input.persona_prompt.trim(), persona_output = input.persona_output.trim(), ) } +pub fn render_persona_semantic_memory_recall(packet: &EpiphanyMemoryContextPacket) -> String { + let mut lines = vec![ + format!( + "Derived semantic recall packet `{}` from query `{}`.", + packet.id, packet.query_id + ), + "These hits come from Epiphany's typed memory graph. They are hints, not durable authority; reviewed memory/state remains the owner.".to_string(), + ]; + + if packet.summaries.is_empty() && packet.nodes.is_empty() { + lines.push("- no matching memory graph entries in this packet".to_string()); + } + + for (index, summary) in packet.summaries.iter().take(4).enumerate() { + lines.push(format!( + "- summary {}. {}: {}; next: {}", + index + 1, + fallback(&summary.target, "unknown target"), + compact_semantic_recall_line(&summary.claim, 420), + compact_semantic_recall_line(&summary.action_implication, 260) + )); + } + + for (index, node) in packet.nodes.iter().take(8).enumerate() { + lines.push(format!( + "- hit {}. {}: {}; next: {}", + index + 1, + fallback(&node.title, "untitled memory"), + compact_semantic_recall_line(&node.claim, 420), + compact_semantic_recall_line(&node.action_implication, 260) + )); + } + + if !packet.warnings.is_empty() { + lines.push("Warnings:".to_string()); + for warning in packet.warnings.iter().take(4) { + lines.push(format!("- {}", compact_semantic_recall_line(warning, 260))); + } + } + + lines.join("\n") +} + pub fn persona_projected_surface_is_clean(surface: &str) -> bool { let forbidden = [ "STATE NOTE", @@ -382,6 +444,24 @@ fn render_allowed_channels(channel_ids: &[String]) -> String { .join("\n") } +fn render_semantic_memory_recall_text(value: &str) -> String { + if value.trim().is_empty() { + return "- semantic memory recall unavailable in this packet; do not pretend it ran" + .to_string(); + } + value.trim().to_string() +} + +fn compact_semantic_recall_line(value: &str, max_len: usize) -> String { + let mut compacted = value.split_whitespace().collect::>().join(" "); + if compacted.len() > max_len { + let keep = max_len.saturating_sub(3); + compacted.truncate(keep); + compacted.push_str("..."); + } + compacted +} + fn fallback<'a>(value: &'a str, fallback: &'a str) -> &'a str { if value.trim().is_empty() { fallback @@ -393,6 +473,10 @@ fn fallback<'a>(value: &'a str, fallback: &'a str) -> &'a str { #[cfg(test)] mod tests { use super::*; + use epiphany_state_model::EpiphanyMemoryContextPacket; + use epiphany_state_model::EpiphanyMemoryFreshnessStatus; + use epiphany_state_model::EpiphanyMemoryNode; + use epiphany_state_model::EpiphanyMemorySummary; fn identity() -> PersonaIdentity { PersonaIdentity { @@ -463,6 +547,7 @@ mod tests { identity: identity(), persona_prompt: persona, persona_output: "I want to answer, but only if I can name the cut plainly.".to_string(), + semantic_memory_recall: String::new(), pending_mentions: vec![pending], allowed_channel_ids: vec!["aquarium".to_string()], }); @@ -471,6 +556,65 @@ mod tests { assert!(interpreter.contains("SAY")); } + #[test] + fn persona_turn_prompts_include_semantic_memory_recall_as_hint_not_authority() { + let recall = render_persona_semantic_memory_recall(&EpiphanyMemoryContextPacket { + id: "memctx-persona-current-room".to_string(), + query_id: "persona-current-room".to_string(), + summaries: vec![EpiphanyMemorySummary { + id: "summary-role-persona".to_string(), + target: "role:Persona".to_string(), + claim: "Persona remembers that public speech should preserve dignity and clean contracts." + .to_string(), + action_implication: "Let this pressure shape tone, but route effects through Mind." + .to_string(), + freshness: EpiphanyMemoryFreshnessStatus::Ready, + confidence: 82, + ..Default::default() + }], + nodes: vec![EpiphanyMemoryNode { + id: "node-persona-value-contracts".to_string(), + title: "Persona value: clean contracts".to_string(), + claim: "Clean typed contracts matter more than fast improvised glue.".to_string(), + action_implication: + "Use as Persona-local context, not as authorization to mutate state." + .to_string(), + ..Default::default() + }], + ..Default::default() + }); + + let projector = build_persona_projector_prompt(&PersonaProjectorInput { + identity: identity(), + semantic_memory_recall: recall.clone(), + ..PersonaProjectorInput::default() + }); + assert!(projector.contains("Semantic memory recall")); + assert!(projector.contains("typed memory graph")); + assert!(projector.contains("not durable authority")); + + let persona = build_persona_turn_prompt(&PersonaTurnInput { + identity: identity(), + projected_state: "Epiphany feels the pressure of the public room.".to_string(), + semantic_memory_recall: recall.clone(), + ..PersonaTurnInput::default() + }); + assert!(persona.contains("Semantic memory recall")); + assert!(persona.contains("Clean typed contracts")); + + let interpreter = build_persona_interpreter_prompt(&PersonaInterpreterInput { + identity: identity(), + persona_prompt: persona, + persona_output: "I can answer, but the answer should stay review-gated.".to_string(), + semantic_memory_recall: recall, + pending_mentions: Vec::new(), + allowed_channel_ids: vec!["aquarium".to_string()], + }); + assert!(interpreter.contains("Dynamic semantic memory recall")); + assert!(interpreter.contains("STATE NOTE")); + assert!(interpreter.contains("SAY")); + } + #[test] fn projected_surface_rejects_side_effect_syntax() { assert!(persona_projected_surface_is_clean( diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 7f9725e9..b328df0c 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ