Render dynamic Verse prompt context

This commit is contained in:
Meta Vens 2026-06-02 13:40:13 +01:00
commit 0fca183873
7 changed files with 384 additions and 4 deletions

View file

@ -0,0 +1,155 @@
use anyhow::Result;
use epiphany_core::EpiphanyMemoryContextQuery;
use epiphany_core::EpiphanyMemoryDomain;
use epiphany_core::EpiphanyMemoryFreshnessStatus;
use epiphany_core::EpiphanyMemoryGraphSnapshot;
use epiphany_core::EpiphanyMemoryLifecycle;
use epiphany_core::EpiphanyMemoryNode;
use epiphany_core::EpiphanyMemoryNodeKind;
use epiphany_core::EpiphanyMemoryProfile;
use epiphany_core::EpiphanyMemorySummary;
use epiphany_core::EpiphanyPromptContextInput;
use epiphany_core::memory_graph_domain_id;
use epiphany_core::memory_graph_node_id;
use epiphany_core::plan_memory_graph_context_cut;
use epiphany_core::query_epiphany_local_verse_context;
use epiphany_core::render_epiphany_prompt_context;
use epiphany_core::seed_epiphany_local_verse_context;
use serde_json::json;
use std::env;
use std::path::PathBuf;
fn main() -> Result<()> {
let store = env::args().nth(1).map(PathBuf::from).unwrap_or_else(|| {
PathBuf::from(".epiphany-smoke")
.join("cultmesh")
.join("epiphany-prompt-context.ccmp")
});
if let Some(parent) = store.parent() {
std::fs::create_dir_all(parent)?;
}
seed_epiphany_local_verse_context(
&store,
"epiphany-prompt-context-smoke",
"2026-06-02T00:00:00Z",
)?;
let local_verse = query_epiphany_local_verse_context(&store, "epiphany-prompt-context-smoke")?;
let memory_context = plan_memory_graph_context_cut(
&smoke_snapshot(),
&EpiphanyMemoryContextQuery {
id: "prompt-context-smoke-query".to_string(),
profile: Some(EpiphanyMemoryProfile::RepoArchitecture),
text: Some("Verse prompt assembly".to_string()),
budget: Some(4),
..Default::default()
},
);
let rendered = render_epiphany_prompt_context(&EpiphanyPromptContextInput {
focus: "Build a bounded worker prompt from local Verse and memory context.".to_string(),
local_verse,
memory_context,
});
let checks = [
rendered.contains("<epiphany_dynamic_context>"),
rendered.contains("Odin"),
rendered.contains("Yggdrasil"),
rendered.contains("Bifrost"),
rendered.contains("gamecult-local"),
rendered.contains("Verse-backed prompt assembly"),
rendered.contains("Mind reviews durable state effects"),
!rendered.contains("raw private worker transcript should never render"),
];
if checks.iter().any(|passed| !passed) {
anyhow::bail!("prompt context smoke failed rendered packet checks:\n{rendered}");
}
println!(
"{}",
serde_json::to_string_pretty(&json!({
"status": "ok",
"store": store,
"renderedBytes": rendered.len(),
"containsVerseContext": true,
"containsMemoryContext": true,
"omitsUnselectedPrivateText": true,
}))?
);
Ok(())
}
fn smoke_snapshot() -> EpiphanyMemoryGraphSnapshot {
let domain_id = memory_graph_domain_id(
EpiphanyMemoryProfile::RepoArchitecture,
"crate",
"epiphany-core",
);
let selected_node = memory_graph_node_id(
&domain_id,
"module",
"epiphany-core/src/prompt_context.rs",
Some("prompt_context"),
);
let unselected_node = memory_graph_node_id(
&domain_id,
"module",
"sealed/raw_worker_transcript.rs",
Some("sealed_private_text"),
);
EpiphanyMemoryGraphSnapshot {
graph_id: "prompt-context-smoke".to_string(),
domains: vec![EpiphanyMemoryDomain {
id: domain_id.clone(),
profile: EpiphanyMemoryProfile::RepoArchitecture,
title: "epiphany-core".to_string(),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
..Default::default()
}],
nodes: vec![
EpiphanyMemoryNode {
id: selected_node.clone(),
domain_id: domain_id.clone(),
profile: EpiphanyMemoryProfile::RepoArchitecture,
kind: EpiphanyMemoryNodeKind::Module,
title: "prompt_context".to_string(),
claim: "Verse-backed prompt assembly injects bounded local Verse and semantic memory packets.".to_string(),
action_implication:
"Use compact dynamic context before launching broad swarm turns."
.to_string(),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
confidence: 90,
salience: 90,
..Default::default()
},
EpiphanyMemoryNode {
id: unselected_node,
domain_id: domain_id.clone(),
profile: EpiphanyMemoryProfile::RepoArchitecture,
kind: EpiphanyMemoryNodeKind::Module,
title: "sealed_private_text".to_string(),
claim: "raw private worker transcript should never render".to_string(),
action_implication: "This text must stay absent from the smoke output.".to_string(),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
confidence: 90,
salience: 10,
..Default::default()
},
],
summaries: vec![EpiphanyMemorySummary {
id: "summary-prompt-context".to_string(),
domain_id,
covers_node_ids: vec![selected_node],
target: "prompt_context".to_string(),
claim: "Verse-backed prompt assembly can ask the local Verse and memory graph for compact context.".to_string(),
action_implication:
"Render this packet into worker prompts, then keep Mind as the durable-state gate."
.to_string(),
freshness: EpiphanyMemoryFreshnessStatus::Ready,
confidence: 95,
..Default::default()
}],
..Default::default()
}
}

View file

@ -12,6 +12,7 @@ mod memory_graph;
mod mind_gateway;
mod organ_dependencies;
mod promotion;
mod prompt_context;
mod proposal;
mod retrieval;
mod runtime_spine;
@ -357,6 +358,8 @@ pub use promotion::EpiphanyPromotionInput;
pub use promotion::EpiphanyStateReplacementValidationInput;
pub use promotion::evaluate_promotion;
pub use promotion::validate_state_replacement_patch;
pub use prompt_context::EpiphanyPromptContextInput;
pub use prompt_context::render_epiphany_prompt_context;
pub use proposal::EpiphanyMapProposal;
pub use proposal::EpiphanyMapProposalInput;
pub use proposal::propose_map_update;

View file

@ -0,0 +1,213 @@
use crate::EpiphanyLocalVerseContext;
use epiphany_state_model::EpiphanyMemoryContextPacket;
use epiphany_state_model::EpiphanyMemoryFreshnessStatus;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EpiphanyPromptContextInput {
pub focus: String,
pub local_verse: EpiphanyLocalVerseContext,
pub memory_context: EpiphanyMemoryContextPacket,
}
pub fn render_epiphany_prompt_context(input: &EpiphanyPromptContextInput) -> String {
let mut lines = vec![
"<epiphany_dynamic_context>".to_string(),
"## Dynamic Context".to_string(),
format!("- Focus: {}", compact_line(&input.focus)),
"- Boundary: this packet is prompt context, not durable state admission.".to_string(),
"- Boundary: Mind reviews durable state effects; Substrate Gate reviews repo access; public Verse material is thought weather until adoption.".to_string(),
String::new(),
"## Local Verse".to_string(),
format!("- Runtime: `{}`", input.local_verse.runtime_id),
format!("- Store: `{}`", input.local_verse.store_path),
format!("- Odin: {}", compact_line(&input.local_verse.odin_scope)),
format!(
"- Yggdrasil: {}",
compact_line(&input.local_verse.yggdrasil_scope)
),
format!(
"- Prompt assembly: {}",
compact_line(&input.local_verse.prompt_assembly_note)
),
];
for policy in input.local_verse.verse_policies.iter().take(3) {
lines.push(format!(
"- Verse `{}` [{}]: private={}, untrusted_ingress={}, yggdrasil_tunnel={}; {}",
policy.verse_id,
policy.tier,
policy.private_state_allowed,
policy.untrusted_ingress_allowed,
policy.yggdrasil_tunnel_allowed,
compact_line(&policy.purpose)
));
}
if let Some(status) = input.local_verse.operator_status.as_ref() {
lines.push(format!(
"- Operator status `{}`: {}",
status.status,
compact_line(&status.summary)
));
}
if !input.local_verse.contract_summaries.is_empty() {
lines.push("## Organ Contract Summary".to_string());
for contract in input.local_verse.contract_summaries.iter().take(8) {
lines.push(format!(
"- `{}` [{} -> {}]: ops={}, receipts={}",
contract.contract_id,
contract.authority,
contract.verse_id,
contract.operations.len(),
contract.receipt_document_types.len()
));
}
push_omitted_count(
&mut lines,
input.local_verse.contract_summaries.len(),
8,
"organ contract summaries",
);
}
lines.push("## Semantic Memory Context".to_string());
lines.push(format!(
"- Packet `{}` from query `{}`",
input.memory_context.id, input.memory_context.query_id
));
for summary in input.memory_context.summaries.iter().take(4) {
lines.push(format!(
"- Summary `{}` [{}]: {}; next: {}",
summary.id,
render_freshness(summary.freshness),
compact_line(&summary.claim),
compact_line(&summary.action_implication)
));
}
push_omitted_count(
&mut lines,
input.memory_context.summaries.len(),
4,
"memory summaries",
);
for node in input.memory_context.nodes.iter().take(6) {
lines.push(format!(
"- Node `{}` [{}]: {}; next: {}",
node.id,
node.title,
compact_line(&node.claim),
compact_line(&node.action_implication)
));
}
push_omitted_count(
&mut lines,
input.memory_context.nodes.len(),
6,
"memory nodes",
);
if !input.memory_context.warnings.is_empty() {
lines.push("## Memory Context Warnings".to_string());
for warning in input.memory_context.warnings.iter().take(4) {
lines.push(format!("- {}", compact_line(warning)));
}
}
if !input.memory_context.missing_node_ids.is_empty()
|| !input.memory_context.missing_edge_ids.is_empty()
{
lines.push("## Missing Memory References".to_string());
if !input.memory_context.missing_node_ids.is_empty() {
lines.push(format!(
"- Missing nodes: {}",
input.memory_context.missing_node_ids.join(", ")
));
}
if !input.memory_context.missing_edge_ids.is_empty() {
lines.push(format!(
"- Missing edges: {}",
input.memory_context.missing_edge_ids.join(", ")
));
}
}
lines.push("</epiphany_dynamic_context>".to_string());
lines.join("\n")
}
fn render_freshness(status: EpiphanyMemoryFreshnessStatus) -> &'static str {
match status {
EpiphanyMemoryFreshnessStatus::Missing => "missing",
EpiphanyMemoryFreshnessStatus::Ready => "ready",
EpiphanyMemoryFreshnessStatus::Stale => "stale",
EpiphanyMemoryFreshnessStatus::Indexing => "indexing",
EpiphanyMemoryFreshnessStatus::Unavailable => "unavailable",
}
}
fn compact_line(value: &str) -> String {
let mut compacted = value.split_whitespace().collect::<Vec<_>>().join(" ");
if compacted.len() > 260 {
compacted.truncate(257);
compacted.push_str("...");
}
compacted
}
fn push_omitted_count(lines: &mut Vec<String>, total: usize, shown: usize, label: &str) {
if total > shown {
lines.push(format!("- ... {} more {} not shown", total - shown, label));
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::query_epiphany_local_verse_context;
use crate::seed_epiphany_local_verse_context;
use epiphany_state_model::EpiphanyMemoryContextPacket;
use epiphany_state_model::EpiphanyMemoryFreshnessStatus;
use epiphany_state_model::EpiphanyMemorySummary;
#[test]
fn prompt_context_renders_verse_and_memory_without_state_authority() -> anyhow::Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("epiphany-local-verse.ccmp");
seed_epiphany_local_verse_context(&store, "epiphany-test", "2026-06-02T00:00:00Z")?;
let local_verse = query_epiphany_local_verse_context(&store, "epiphany-test")?;
let memory_context = EpiphanyMemoryContextPacket {
id: "memctx-test".to_string(),
query_id: "query-test".to_string(),
summaries: vec![EpiphanyMemorySummary {
id: "summary-test".to_string(),
claim: "Shared graph law lets prompt assembly ask for relevant memory instead of hauling the archive.".to_string(),
action_implication:
"Inject the compact packet, then let Mind review any durable effect."
.to_string(),
freshness: EpiphanyMemoryFreshnessStatus::Ready,
confidence: 90,
..Default::default()
}],
..Default::default()
};
let rendered = render_epiphany_prompt_context(&EpiphanyPromptContextInput {
focus: "Assemble context for a bounded worker prompt.".to_string(),
local_verse,
memory_context,
});
assert!(rendered.contains("<epiphany_dynamic_context>"));
assert!(rendered.contains("Odin"));
assert!(rendered.contains("Yggdrasil"));
assert!(rendered.contains("Bifrost"));
assert!(rendered.contains("gamecult-local"));
assert!(rendered.contains("Shared graph law"));
assert!(rendered.contains("Mind reviews durable state effects"));
assert!(!rendered.contains("raw worker transcript"));
Ok(())
}
}