Add memory graph repo profile import

This commit is contained in:
Meta Vens 2026-05-18 01:45:04 +01:00
commit e26e3d2f42
7 changed files with 483 additions and 2 deletions

View file

@ -102,6 +102,7 @@ pub use memory_graph::load_memory_graph_snapshot;
pub use memory_graph::memory_graph_cache;
pub use memory_graph::memory_graph_domain_id;
pub use memory_graph::memory_graph_edge_id;
pub use memory_graph::memory_graph_from_epiphany_graphs;
pub use memory_graph::memory_graph_node_id;
pub use memory_graph::plan_memory_graph_context_cut;
pub use memory_graph::validate_memory_graph_entry;

View file

@ -1,6 +1,7 @@
pub mod context_cut;
pub mod freshness;
pub mod ids;
pub mod profiles;
pub mod store;
pub mod validation;
@ -27,6 +28,7 @@ pub use freshness::derive_memory_graph_freshness;
pub use ids::memory_graph_domain_id;
pub use ids::memory_graph_edge_id;
pub use ids::memory_graph_node_id;
pub use profiles::memory_graph_from_epiphany_graphs;
pub use store::EpiphanyMemoryGraphEntry;
pub use store::MEMORY_GRAPH_KEY;
pub use store::MEMORY_GRAPH_SCHEMA_VERSION;

View file

@ -0,0 +1,3 @@
pub mod repo;
pub use repo::memory_graph_from_epiphany_graphs;

View file

@ -0,0 +1,475 @@
use crate::memory_graph::EpiphanyMemoryAnchor;
use crate::memory_graph::EpiphanyMemoryDomain;
use crate::memory_graph::EpiphanyMemoryEdge;
use crate::memory_graph::EpiphanyMemoryEdgeKind;
use crate::memory_graph::EpiphanyMemoryFreshness;
use crate::memory_graph::EpiphanyMemoryFreshnessStatus;
use crate::memory_graph::EpiphanyMemoryGraphSnapshot;
use crate::memory_graph::EpiphanyMemoryLifecycle;
use crate::memory_graph::EpiphanyMemoryNode;
use crate::memory_graph::EpiphanyMemoryNodeKind;
use crate::memory_graph::EpiphanyMemoryProfile;
use crate::memory_graph::EpiphanyMemorySummary;
use crate::memory_graph::memory_graph_domain_id;
use crate::memory_graph::memory_graph_edge_id;
use crate::memory_graph::memory_graph_node_id;
use epiphany_state_model::EpiphanyCodeRef;
use epiphany_state_model::EpiphanyGraph;
use epiphany_state_model::EpiphanyGraphEdge;
use epiphany_state_model::EpiphanyGraphLink;
use epiphany_state_model::EpiphanyGraphNode;
use epiphany_state_model::EpiphanyGraphs;
use std::collections::HashMap;
pub fn memory_graph_from_epiphany_graphs(
graph_id: impl Into<String>,
graphs: &EpiphanyGraphs,
) -> EpiphanyMemoryGraphSnapshot {
let architecture_domain = memory_graph_domain_id(
EpiphanyMemoryProfile::RepoArchitecture,
"accepted_graph",
"architecture",
);
let dataflow_domain = memory_graph_domain_id(
EpiphanyMemoryProfile::RepoDataflow,
"accepted_graph",
"dataflow",
);
let mut domains = Vec::new();
let mut nodes = Vec::new();
let mut edges = Vec::new();
let mut summaries = Vec::new();
let mut node_map = HashMap::new();
if !graphs.architecture.is_empty() {
domains.push(repo_domain(
architecture_domain.clone(),
EpiphanyMemoryProfile::RepoArchitecture,
"Accepted architecture graph",
));
import_graph_nodes(
&graphs.architecture,
&architecture_domain,
EpiphanyMemoryProfile::RepoArchitecture,
&mut node_map,
&mut nodes,
);
import_graph_edges(
&graphs.architecture,
EpiphanyMemoryProfile::RepoArchitecture,
&node_map,
&mut edges,
);
summaries.push(repo_summary(
"summary-accepted-architecture-graph",
&architecture_domain,
"accepted architecture graph",
"Accepted architecture graph nodes are available as memory graph repo-profile claims.",
&nodes,
&edges,
EpiphanyMemoryProfile::RepoArchitecture,
));
}
if !graphs.dataflow.is_empty() {
domains.push(repo_domain(
dataflow_domain.clone(),
EpiphanyMemoryProfile::RepoDataflow,
"Accepted dataflow graph",
));
import_graph_nodes(
&graphs.dataflow,
&dataflow_domain,
EpiphanyMemoryProfile::RepoDataflow,
&mut node_map,
&mut nodes,
);
import_graph_edges(
&graphs.dataflow,
EpiphanyMemoryProfile::RepoDataflow,
&node_map,
&mut edges,
);
summaries.push(repo_summary(
"summary-accepted-dataflow-graph",
&dataflow_domain,
"accepted dataflow graph",
"Accepted dataflow graph nodes are available as memory graph repo-profile claims.",
&nodes,
&edges,
EpiphanyMemoryProfile::RepoDataflow,
));
}
import_graph_links(graphs.links.as_slice(), &node_map, &mut edges);
EpiphanyMemoryGraphSnapshot {
schema_version: Some("epiphany.memory_graph.v0".to_string()),
graph_id: graph_id.into(),
domains,
nodes,
edges,
summaries,
freshness: Some(EpiphanyMemoryFreshness {
status: EpiphanyMemoryFreshnessStatus::Ready,
note: Some("Imported from accepted Epiphany graph state.".to_string()),
..Default::default()
}),
..Default::default()
}
}
fn repo_domain(id: String, profile: EpiphanyMemoryProfile, title: &str) -> EpiphanyMemoryDomain {
EpiphanyMemoryDomain {
id,
profile,
title: title.to_string(),
description: Some("Repo profile imported from accepted Epiphany graph state.".to_string()),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
}
}
fn import_graph_nodes(
graph: &EpiphanyGraph,
domain_id: &str,
profile: EpiphanyMemoryProfile,
node_map: &mut HashMap<String, String>,
nodes: &mut Vec<EpiphanyMemoryNode>,
) {
for node in &graph.nodes {
let memory_id = memory_graph_node_id(domain_id, "accepted_graph_node", &node.id, None);
node_map.insert(node.id.clone(), memory_id.clone());
nodes.push(memory_node_from_graph_node(
memory_id, domain_id, profile, node,
));
}
}
fn memory_node_from_graph_node(
id: String,
domain_id: &str,
profile: EpiphanyMemoryProfile,
node: &EpiphanyGraphNode,
) -> EpiphanyMemoryNode {
let anchors = anchors_from_code_refs(&id, &node.code_refs);
let source_hashes = if anchors.is_empty() {
vec!["anchor:missing".to_string()]
} else {
anchors.iter().map(|anchor| anchor.id.clone()).collect()
};
EpiphanyMemoryNode {
id,
domain_id: domain_id.to_string(),
profile,
kind: memory_node_kind(node),
title: node.title.clone(),
claim: graph_node_claim(node),
question: "What changes if this accepted graph node is stale?".to_string(),
tension: node.mechanism.clone().unwrap_or_default(),
action_implication: format!(
"Use accepted graph node {} when selecting repo context.",
node.id
),
anchors,
source_hashes,
lifecycle: graph_status_lifecycle(node.status.as_deref()),
salience: 70,
confidence: 80,
..Default::default()
}
}
fn import_graph_edges(
graph: &EpiphanyGraph,
profile: EpiphanyMemoryProfile,
node_map: &HashMap<String, String>,
edges: &mut Vec<EpiphanyMemoryEdge>,
) {
for edge in &graph.edges {
let source_id = node_map
.get(&edge.source_id)
.cloned()
.unwrap_or_else(|| edge.source_id.clone());
let target_id = node_map
.get(&edge.target_id)
.cloned()
.unwrap_or_else(|| edge.target_id.clone());
edges.push(memory_edge_from_graph_edge(
source_id, target_id, profile, edge,
));
}
}
fn memory_edge_from_graph_edge(
source_id: String,
target_id: String,
profile: EpiphanyMemoryProfile,
edge: &EpiphanyGraphEdge,
) -> EpiphanyMemoryEdge {
let id = edge.id.clone().unwrap_or_else(|| {
memory_graph_edge_id(
&source_id,
&target_id,
edge.kind.as_str(),
edge.code_refs.iter().map(code_ref_key),
)
});
EpiphanyMemoryEdge {
id,
source_id,
target_id,
kind: memory_edge_kind(edge.kind.as_str()),
profile,
claim: graph_edge_claim(edge),
anchors: anchors_from_code_refs(edge.id.as_deref().unwrap_or("edge"), &edge.code_refs),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
confidence: 80,
}
}
fn import_graph_links(
links: &[EpiphanyGraphLink],
node_map: &HashMap<String, String>,
edges: &mut Vec<EpiphanyMemoryEdge>,
) {
for link in links {
let Some(source_id) = node_map.get(&link.dataflow_node_id).cloned() else {
continue;
};
let Some(target_id) = node_map.get(&link.architecture_node_id).cloned() else {
continue;
};
edges.push(EpiphanyMemoryEdge {
id: memory_graph_edge_id(
&source_id,
&target_id,
"grounds",
link.code_refs.iter().map(code_ref_key),
),
source_id,
target_id,
kind: EpiphanyMemoryEdgeKind::Grounds,
profile: EpiphanyMemoryProfile::RepoDataflow,
claim: link
.relationship
.clone()
.unwrap_or_else(|| "Dataflow node is linked to architecture node.".to_string()),
anchors: anchors_from_code_refs("link", &link.code_refs),
lifecycle: EpiphanyMemoryLifecycle::Accepted,
confidence: 75,
});
}
}
fn repo_summary(
id: &str,
domain_id: &str,
target: &str,
claim: &str,
nodes: &[EpiphanyMemoryNode],
edges: &[EpiphanyMemoryEdge],
profile: EpiphanyMemoryProfile,
) -> EpiphanyMemorySummary {
let covers_node_ids = nodes
.iter()
.filter(|node| node.profile == profile)
.map(|node| node.id.clone())
.collect::<Vec<_>>();
let covers_edge_ids = edges
.iter()
.filter(|edge| edge.profile == profile)
.map(|edge| edge.id.clone())
.collect::<Vec<_>>();
let anchor_count = nodes
.iter()
.filter(|node| node.profile == profile)
.map(|node| node.anchors.len() as u32)
.sum();
EpiphanyMemorySummary {
id: id.to_string(),
domain_id: domain_id.to_string(),
covers_node_ids,
covers_edge_ids,
target: target.to_string(),
claim: claim.to_string(),
question: "Which profile producer should refresh this accepted graph next?".to_string(),
tension: String::new(),
action_implication: "Use this summary for broad repo context; descend when exact nodes are stale or relevant.".to_string(),
anchor_count,
freshness: EpiphanyMemoryFreshnessStatus::Ready,
confidence: 80,
..Default::default()
}
}
fn anchors_from_code_refs(
prefix: &str,
code_refs: &[EpiphanyCodeRef],
) -> Vec<EpiphanyMemoryAnchor> {
code_refs
.iter()
.enumerate()
.map(|(index, code_ref)| EpiphanyMemoryAnchor {
id: format!("anchor-{prefix}-{index}"),
kind: "code_ref".to_string(),
target: code_ref_key(code_ref),
code_ref: Some(code_ref.clone()),
source_hash: Some(code_ref_key(code_ref)),
..Default::default()
})
.collect()
}
fn code_ref_key(code_ref: &EpiphanyCodeRef) -> String {
let mut key = code_ref.path.to_string_lossy().replace('\\', "/");
if let Some(symbol) = code_ref.symbol.as_deref() {
key.push('#');
key.push_str(symbol);
}
key
}
fn graph_node_claim(node: &EpiphanyGraphNode) -> String {
if !node.purpose.trim().is_empty() {
return node.purpose.clone();
}
format!("Accepted graph node {} exists.", node.id)
}
fn graph_edge_claim(edge: &EpiphanyGraphEdge) -> String {
edge.mechanism
.clone()
.or_else(|| edge.label.clone())
.unwrap_or_else(|| {
format!(
"Accepted graph edge {} connects {} to {}.",
edge.kind, edge.source_id, edge.target_id
)
})
}
fn graph_status_lifecycle(status: Option<&str>) -> EpiphanyMemoryLifecycle {
match status.unwrap_or_default() {
"observed" => EpiphanyMemoryLifecycle::Observed,
"proposed" => EpiphanyMemoryLifecycle::Proposed,
"stale" => EpiphanyMemoryLifecycle::Stale,
"retired" => EpiphanyMemoryLifecycle::Retired,
_ => EpiphanyMemoryLifecycle::Accepted,
}
}
fn memory_node_kind(node: &EpiphanyGraphNode) -> EpiphanyMemoryNodeKind {
let text = format!("{} {}", node.title, node.purpose).to_lowercase();
if text.contains("schema") {
EpiphanyMemoryNodeKind::Schema
} else if text.contains("runtime") || text.contains("contract") {
EpiphanyMemoryNodeKind::RuntimeContract
} else if text.contains("adapter") || text.contains("bridge") {
EpiphanyMemoryNodeKind::Adapter
} else if text.contains("test") || text.contains("smoke") {
EpiphanyMemoryNodeKind::TestSeam
} else if text.contains("state") || text.contains("store") {
EpiphanyMemoryNodeKind::StateStore
} else {
EpiphanyMemoryNodeKind::Module
}
}
fn memory_edge_kind(kind: &str) -> EpiphanyMemoryEdgeKind {
match kind {
"owns" => EpiphanyMemoryEdgeKind::Owns,
"reads" => EpiphanyMemoryEdgeKind::Reads,
"writes" => EpiphanyMemoryEdgeKind::Writes,
"derives" => EpiphanyMemoryEdgeKind::Derives,
"adapts" => EpiphanyMemoryEdgeKind::Adapts,
"persists" => EpiphanyMemoryEdgeKind::Persists,
"launches" => EpiphanyMemoryEdgeKind::Launches,
"verifies" | "tests" => EpiphanyMemoryEdgeKind::Verifies,
"depends_on" | "depends" => EpiphanyMemoryEdgeKind::DependsOn,
_ => EpiphanyMemoryEdgeKind::Other,
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::memory_graph::validate_memory_graph_snapshot;
use epiphany_state_model::EpiphanyCodeRef;
use epiphany_state_model::EpiphanyGraph;
use epiphany_state_model::EpiphanyGraphEdge;
use epiphany_state_model::EpiphanyGraphNode;
use epiphany_state_model::EpiphanyGraphs;
use std::path::PathBuf;
#[test]
fn repo_profile_imports_accepted_graphs_into_valid_memory_graph() {
let graphs = EpiphanyGraphs {
architecture: EpiphanyGraph {
nodes: vec![EpiphanyGraphNode {
id: "core".to_string(),
title: "Core policy".to_string(),
purpose: "Owns shared policy.".to_string(),
code_refs: vec![EpiphanyCodeRef {
path: PathBuf::from("epiphany-core/src/lib.rs"),
symbol: Some("policy".to_string()),
..Default::default()
}],
..Default::default()
}],
edges: vec![EpiphanyGraphEdge {
id: Some("edge-core-self".to_string()),
source_id: "core".to_string(),
target_id: "core".to_string(),
kind: "owns".to_string(),
label: Some("owns itself for fixture".to_string()),
..Default::default()
}],
},
..Default::default()
};
let snapshot = memory_graph_from_epiphany_graphs("repo-profile", &graphs);
let errors = validate_memory_graph_snapshot(&snapshot);
assert!(errors.is_empty(), "{errors:?}");
assert_eq!(snapshot.domains.len(), 1);
assert_eq!(snapshot.nodes.len(), 1);
assert_eq!(snapshot.edges.len(), 1);
assert_eq!(snapshot.summaries.len(), 1);
assert_eq!(
snapshot.nodes[0].profile,
EpiphanyMemoryProfile::RepoArchitecture
);
}
#[test]
fn repo_profile_keeps_bad_topology_visible() {
let graphs = EpiphanyGraphs {
architecture: EpiphanyGraph {
edges: vec![EpiphanyGraphEdge {
source_id: "missing-source".to_string(),
target_id: "missing-target".to_string(),
kind: "owns".to_string(),
..Default::default()
}],
..Default::default()
},
..Default::default()
};
let snapshot = memory_graph_from_epiphany_graphs("repo-profile", &graphs);
let errors = validate_memory_graph_snapshot(&snapshot);
assert!(
errors
.iter()
.any(|error| error.message.contains("missing source node"))
);
assert!(
errors
.iter()
.any(|error| error.message.contains("missing target node"))
);
}
}

View file

@ -96,7 +96,7 @@ remembers doctrine; the branch remembers the blade.
- The heartbeat initiative pass is landed as a bounded tool seam. `state/agent-heartbeats.msgpack` tracks Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life as Ghostlight-style initiative participants with arena, participant kind, speed, next-ready time, reaction bias, interrupt threshold, load, status, constraints, personality cooldown, mood cooldown, effective cooldown, adaptive pacing, history, and pending turns through `epiphany-core::EpiphanyHeartbeatStateEntry` and the native `epiphany-heartbeat-store` binary. Role dossiers set baseline timing; appraisal mood/anxiety bends it through urgency, arousal, thought pressure, guardedness, and reaction intensity, so Hands-like work pressure and high-need anxious lanes recover sooner without being heartbeaten while a prior turn is running. `epiphany-heartbeat-store pump` computes pressure from external urgency, mood/anxiety, reaction intensity, thought pressure, and current pending load, then chooses tempo plus target concurrency: calm can launch zero and sleep slow; alarm can fill most active lanes. Idle turns are for rumination: light thought shuffling, role-quality attention, and candidate selfPatch pressure. Sleep/dream cycle passes are the intended distillation window for durable self-memory and doctrine. JSON heartbeat state and Python wrapper state are gone; general CultCache schema sync, polyglot domain loading, and debug display tools belong in CultLib. This is a callable scheduler seam, not yet an always-on daemon; a heart valve, not a whole circulatory god.
- The first Ghostlight-derived timing slice is landed in Epiphany, but Ghostlight is reference lineage rather than a sibling runtime to preserve. `epiphany-heartbeat-store init --profile ghostlight-scene --scene-id <id> --scene-participant <id|name|speed|reaction|threshold|constraints>` creates a typed CultCache MessagePack scene heartbeat store whose participants are `arena=scene`, `participantKind=character`; `tick` emits `ghostlight.initiative_schedule.v0` receipts with `scene_turn` actions and local-affordance basis. The generic Epiphany maintenance lanes are not auto-patched into scene stores.
- The first Void-derived routine slice is landed in Epiphany, but VoidBot is reference lineage rather than a runtime dependency. `epiphany-heartbeat-store routine --store .\state\agent-heartbeats.msgpack --artifact-dir .\.epiphany-heartbeats --agent-store .\state\agents.msgpack` reads typed role dossiers, computes bounded memory resonance, maintains incubation themes, runs analytic and associative cognition lanes, writes bridge syntheses/saturation/tension, projects the active thought cluster through each role's Ghostlight-shaped personality vectors, derives participant-local reactions, applies personality/mood timing, advances the sleep/dream cycle, updates the typed heartbeat store, and emits an auditable `epiphany.void_routine.v0` receipt. The routine now also carries anti-loop physiology imported from Void's calmer brain: `noveltyToSelf`, `noveltyToRoom`, source coverage, saturation pressure, refractory cooling, and explicit permission to let a live unsaturated thought deepen without forcing novelty theater every pass. This mutates only heartbeat physiology fields: project truth and role memory mutation remain on their reviewed surfaces.
- The next memory foundation must not build separate engines for repo graph and agent mind. Heartbeat cognition, role self-memory, repo architecture/dataflow, evidence scars, incubation, agency pressure, and context packets should converge through `EpiphanyMemoryGraph` profiles so one typed graph owns anchors, lifecycle, summaries, freshness, context cuts, and Qdrant embedding manifests. The next clean implementation slice is a repo profile producer that maps existing accepted architecture/dataflow graph state into memory graph fixtures/profile documents before any scanner, sleep runner, Qdrant, CultNet, or prompt integration.
- The next memory foundation must not build separate engines for repo graph and agent mind. Heartbeat cognition, role self-memory, repo architecture/dataflow, evidence scars, incubation, agency pressure, and context packets should converge through `EpiphanyMemoryGraph` profiles so one typed graph owns anchors, lifecycle, summaries, freshness, context cuts, and Qdrant embedding manifests. The repo profile producer now maps existing accepted architecture/dataflow graph state into memory graph documents without scanner/Qdrant/model work and deliberately keeps bad topology visible as validation failure. The next clean implementation slice is an agent profile producer over reviewed role self-memory and heartbeat cognition pressure, still before sleep runner, Qdrant, CultNet, or prompt integration.
- Manual Codex-run rumination still has an explicit aftercare rule until Epiphany owns the full sleep consolidator. In the intended Epiphany cycle, sub-agents ruminate when idle and distill when they sleep; in this supervising Codex thread, a heartbeat/routine vigil is only physiology until a separate closing pass reviews the receipts and decides whether map, handoff, evidence, or role self-memory should change.
- The Face public-surface pass is landed as a bounded lane. Face's role dossier lives in `state/agents.msgpack`; `epiphany_specialists.toml` gives it a VoidBot-heartbeat-derived prompt stripped of moderation authority; `state/face-discord.toml` and the native `epiphany-face-discord` binary enforce that Face may interact only through #aquarium. Missing channel id or token writes candidate chat artifacts instead of posting elsewhere. If a Face has a persona name/avatar, `post` uses the shared Discord webhook pipe so each Epiphany can speak with its own nickname and avatar without a separate bot identity.
- The Void memory bridge is now native enough to keep the useful organs attached. `state/void-memory.toml` and `epiphany-void-memory` can check Void's Docker Postgres state spine, query Qdrant Discord-history and source/lore collections with the configured Ollama embedding model, and fetch raw archive context windows from Void's file-backed Discord archive. Native `epiphany-mvp-status` includes a `voidMemory` block so Aquarium/backend clients can inspect whether the mouth and memory are actually wired.

Binary file not shown.

View file

@ -297,4 +297,4 @@ current_status:
freshness propagation, summary-versus-child context cuts, and a validated
CultCache store entry; the native `epiphany-memory-graph` binary can
status/validate/query/smoke the store without Qdrant.
next_action: Continue the memory graph build unless a more urgent Codex starvation regression appears. The next clean slice is a repo profile producer that maps existing accepted architecture/dataflow graph state into `EpiphanyMemoryGraph` fixture/profile documents before any scanner, Qdrant, sleep consolidation, CultNet advertisement, or prompt integration.
next_action: Continue the memory graph build unless a more urgent Codex starvation regression appears. The repo profile producer now maps existing accepted architecture/dataflow graph state into `EpiphanyMemoryGraph` documents without scanner/Qdrant/model work. The next clean slice is an agent profile producer that maps reviewed role self-memory and heartbeat cognition pressure into shared memory graph profile documents, still without sleep runner, Qdrant, CultNet advertisement, or prompt integration.