diff --git a/epiphany-core/src/bin/epiphany-state-ledger-store.rs b/epiphany-core/src/bin/epiphany-state-ledger-store.rs index d0ba9e7a..ef869174 100644 --- a/epiphany-core/src/bin/epiphany-state-ledger-store.rs +++ b/epiphany-core/src/bin/epiphany-state-ledger-store.rs @@ -5,8 +5,6 @@ use epiphany_core::EpiphanyLedgerEvidenceRecord; use epiphany_core::add_state_branch; use epiphany_core::append_state_evidence; use epiphany_core::close_state_branch; -use epiphany_core::migrate_state_ledgers_to_cultcache; -use epiphany_core::project_state_ledgers_to_json; use epiphany_core::state_ledger_status; use std::collections::BTreeMap; use std::env; @@ -19,20 +17,6 @@ fn main() -> Result<()> { std::process::exit(2); }; match command.as_str() { - "migrate-json" => { - let branches = require_path_arg(&mut args, "--branches")?; - let evidence = require_path_arg(&mut args, "--evidence")?; - let store = require_path_arg(&mut args, "--store")?; - print_json(&migrate_state_ledgers_to_cultcache( - branches, evidence, store, - )?)?; - } - "project-json" => { - let store = require_path_arg(&mut args, "--store")?; - let branches = require_path_arg(&mut args, "--branches")?; - let evidence = require_path_arg(&mut args, "--evidence")?; - print_json(&project_state_ledgers_to_json(store, branches, evidence)?)?; - } "status" => { let store = require_path_arg(&mut args, "--store")?; print_json(&state_ledger_status(store)?)?; @@ -150,6 +134,6 @@ fn print_json(value: &T) -> Result<()> { fn print_usage() { eprintln!( - "usage: epiphany-state-ledger-store ..." + "usage: epiphany-state-ledger-store ..." ); } diff --git a/epiphany-core/src/bin/epiphany-state.rs b/epiphany-core/src/bin/epiphany-state.rs index 970f621b..dd1bcdaa 100644 --- a/epiphany-core/src/bin/epiphany-state.rs +++ b/epiphany-core/src/bin/epiphany-state.rs @@ -6,12 +6,10 @@ use epiphany_core::add_state_branch; use epiphany_core::append_state_evidence; use epiphany_core::close_state_branch; use epiphany_core::load_state_ledger; -use epiphany_core::migrate_state_ledgers_to_cultcache; use std::collections::BTreeMap; use std::env; use std::fs; use std::path::Path; -use std::path::PathBuf; fn main() -> Result<()> { let root = env::current_dir().context("failed to resolve current directory")?; @@ -25,35 +23,6 @@ fn main() -> Result<()> { }; match command.as_str() { "status" => print_status(&root, &map_path, &ledger_store)?, - "migrate-json" => { - let mut branches = None; - let mut evidence = None; - let mut store = None; - parse_named_args(&mut args, |name, value| match name { - "--branches" => { - branches = Some(PathBuf::from(value)); - Ok(()) - } - "--evidence" => { - evidence = Some(PathBuf::from(value)); - Ok(()) - } - "--store" => { - store = Some(PathBuf::from(value)); - Ok(()) - } - other => anyhow::bail!("unexpected argument {other}"), - })?; - let branches = branches.unwrap_or_else(|| state_dir.join("branches.json")); - let evidence = evidence.unwrap_or_else(|| state_dir.join("evidence.jsonl")); - let store = store.unwrap_or_else(|| ledger_store.clone()); - println!( - "{}", - serde_json::to_string_pretty(&migrate_state_ledgers_to_cultcache( - branches, evidence, store - )?)? - ); - } "add-evidence" => { let mut evidence_type = None; let mut status = None; @@ -237,7 +206,5 @@ fn parse_named_args( } fn print_usage() { - eprintln!( - "usage: epiphany-state ..." - ); + eprintln!("usage: epiphany-state ..."); } diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index d28f906f..cfc6255f 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -109,6 +109,4 @@ pub use state_ledger::add_state_branch; pub use state_ledger::append_state_evidence; pub use state_ledger::close_state_branch; pub use state_ledger::load_state_ledger; -pub use state_ledger::migrate_state_ledgers_to_cultcache; -pub use state_ledger::project_state_ledgers_to_json; pub use state_ledger::state_ledger_status; diff --git a/epiphany-core/src/state_ledger.rs b/epiphany-core/src/state_ledger.rs index b0a9a3a3..3556e8cf 100644 --- a/epiphany-core/src/state_ledger.rs +++ b/epiphany-core/src/state_ledger.rs @@ -1,4 +1,3 @@ -use anyhow::Context; use anyhow::Result; use anyhow::anyhow; use cultcache_rs::CultCache; @@ -8,7 +7,6 @@ use serde::Deserialize; use serde::Serialize; use serde_json::Value; use std::collections::BTreeMap; -use std::fs; use std::path::Path; pub const STATE_LEDGER_STORE_TYPE: &str = "epiphany.state_ledger"; @@ -52,42 +50,6 @@ pub struct EpiphanyLedgerEvidenceRecord { pub extra: BTreeMap, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] -struct BranchProjection { - pub branches: Vec, - #[serde(flatten)] - pub extra: BTreeMap, -} - -pub fn migrate_state_ledgers_to_cultcache( - branches_path: impl AsRef, - evidence_path: impl AsRef, - store_path: impl AsRef, -) -> Result { - let branches_path = branches_path.as_ref(); - let evidence_path = evidence_path.as_ref(); - let store_path = store_path.as_ref(); - let branch_raw = fs::read_to_string(branches_path) - .with_context(|| format!("failed to read {}", branches_path.display()))?; - let branches: BranchProjection = serde_json::from_str(&branch_raw) - .with_context(|| format!("failed to decode {}", branches_path.display()))?; - let evidence = read_evidence_jsonl(evidence_path)?; - let entry = EpiphanyStateLedgerEntry { - schema_version: STATE_LEDGER_SCHEMA_VERSION.to_string(), - branches: branches.branches, - evidence, - extra: branches.extra, - }; - let mut cache = state_ledger_cache(store_path)?; - cache.put(STATE_LEDGER_KEY, &entry)?; - Ok(serde_json::json!({ - "ok": true, - "store": store_path, - "branches": entry.branches.len(), - "evidence": entry.evidence.len(), - })) -} - pub fn state_ledger_status(store_path: impl AsRef) -> Result { let store_path = store_path.as_ref(); if !store_path.exists() { @@ -204,47 +166,6 @@ pub fn close_state_branch( })) } -pub fn project_state_ledgers_to_json( - store_path: impl AsRef, - branches_path: impl AsRef, - evidence_path: impl AsRef, -) -> Result { - let entry = load_state_ledger(store_path.as_ref())?; - let branches_path = branches_path.as_ref(); - let evidence_path = evidence_path.as_ref(); - if let Some(parent) = branches_path.parent() { - fs::create_dir_all(parent)?; - } - fs::write( - branches_path, - format!( - "{}\n", - serde_json::to_string_pretty(&BranchProjection { - branches: entry.branches.clone(), - extra: entry.extra.clone(), - })? - ), - ) - .with_context(|| format!("failed to write {}", branches_path.display()))?; - if let Some(parent) = evidence_path.parent() { - fs::create_dir_all(parent)?; - } - let mut lines = String::new(); - for record in &entry.evidence { - lines.push_str(&serde_json::to_string(record)?); - lines.push('\n'); - } - fs::write(evidence_path, lines) - .with_context(|| format!("failed to write {}", evidence_path.display()))?; - Ok(serde_json::json!({ - "ok": true, - "branchesPath": branches_path, - "evidencePath": evidence_path, - "branches": entry.branches.len(), - "evidence": entry.evidence.len(), - })) -} - fn state_ledger_cache(store_path: &Path) -> Result { let mut cache = CultCache::new(); cache.register_entry_type::()?; @@ -261,24 +182,6 @@ fn default_state_ledger() -> EpiphanyStateLedgerEntry { } } -fn read_evidence_jsonl(path: &Path) -> Result> { - let raw = - fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?; - let mut records = Vec::new(); - for (index, line) in raw.lines().enumerate() { - if line.trim().is_empty() { - continue; - } - let record: EpiphanyLedgerEvidenceRecord = serde_json::from_str(line) - .with_context(|| format!("failed to decode {} line {}", path.display(), index + 1))?; - validate_evidence(&record).with_context(|| { - format!("invalid evidence at {} line {}", path.display(), index + 1) - })?; - records.push(record); - } - Ok(records) -} - fn validate_branch(branch: &EpiphanyBranchRecord) -> Result<()> { if branch.id.trim().is_empty() { return Err(anyhow!("branch id must be non-empty")); @@ -314,39 +217,23 @@ mod tests { use tempfile::tempdir; #[test] - fn state_ledgers_migrate_and_append_native_evidence() -> Result<()> { + fn state_ledgers_add_branch_and_append_native_evidence() -> Result<()> { let temp = tempdir()?; - let branches = temp.path().join("branches.json"); - let evidence = temp.path().join("evidence.jsonl"); let store = temp.path().join("ledgers.msgpack"); - fs::write( - &branches, - serde_json::json!({ - "branches": [{ - "id": "main", - "hypothesis": "Typed state reduces drift.", - "status": "active", - "artifacts": ["state/map.yaml"], - "notes": "test" - }] - }) - .to_string(), - )?; - fs::write( - &evidence, - serde_json::to_string(&EpiphanyLedgerEvidenceRecord { - ts: "2026-05-06T00:00:00+00:00".to_string(), - evidence_type: "test".to_string(), - status: "ok".to_string(), - note: "The initial ledger record exists.".to_string(), - branch: None, + add_state_branch( + &store, + EpiphanyBranchRecord { + id: "main".to_string(), + hypothesis: "Typed state reduces drift.".to_string(), + status: "active".to_string(), + artifacts: vec!["state/map.yaml".to_string()], + notes: "test".to_string(), extra: BTreeMap::new(), - })? + "\n", + }, )?; - migrate_state_ledgers_to_cultcache(&branches, &evidence, &store)?; let entry = load_state_ledger(&store)?; assert_eq!(entry.branches.len(), 1); - assert_eq!(entry.evidence.len(), 1); + assert_eq!(entry.evidence.len(), 0); append_state_evidence( &store, EpiphanyLedgerEvidenceRecord { @@ -358,7 +245,7 @@ mod tests { extra: BTreeMap::new(), }, )?; - assert_eq!(load_state_ledger(&store)?.evidence.len(), 2); + assert_eq!(load_state_ledger(&store)?.evidence.len(), 1); Ok(()) } } diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index a79295a2..c4c2f16e 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 55aa9d73..82d90314 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -132,7 +132,7 @@ accepted_design: - Epiphany prompt surfaces now carry a shared Ghostlight-derived persistent memory projection before lane-specific text: prompt is not memory, durable typed state is the mind, personality and protected values are first-class salience handles, and every lane is explicitly responsible for making its own memory/model/prompt/evidence habit sharper or naming the needed repair. Each lane states self-improvement in its own rite-language: Imagination selects futures, Body clarifies anatomy, Eyes sees earlier, Hands touches source more precisely, Soul becomes harder to fool, Life loses less continuity, Self routes repair, and Face becomes clearer at turning inner weather into useful social presence. - Specialist self-memory now has a bounded Ghostlight-shaped CultCache persistence surface in `state/agents.msgpack`: Imagination, Body, Eyes, Hands, Soul, Life, Self, and Face each have an individual typed role dossier for identity, personality, semantic/episodic/relationship memory, goals, and values. These entries are lane memory only; project truth remains in authoritative `EpiphanyThreadState`. - `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, and the native `epiphany-heartbeat-store` binary are the Ghostlight-derived heartbeat initiative seam. The harness sets a target heartbeat rate; participants carry initiative speed, next-ready time, reaction bias, interrupt threshold, current load, status, and constraints; pending coordinator work can pull its owning lane through a reaction window; otherwise the earliest ready active lane wins the slot. If the winner has no routeable work, it ruminates on role quality and can apply a bounded selfPatch directly through the normal coordinator-reviewed memory rules when `--agent-store` and `--apply-rumination` are provided. Face can win `surfaceAgentThoughts` or `discordAquariumChat` work slots. The typed CultCache MessagePack store is the durable persistence seam; JSON state is gone. - - `state/ledgers.msgpack`, `epiphany-core::EpiphanyStateLedgerEntry`, the `epiphany-state-ledger-store` binary, and the native `epiphany-state` CLI now own durable branch and evidence ledgers. The old tracked `state/branches.json` and `state/evidence.jsonl` files are gone; JSON projection remains only a migration/debug escape hatch, a quarantined window into the reliquary. + - `state/ledgers.msgpack`, `epiphany-core::EpiphanyStateLedgerEntry`, the `epiphany-state-ledger-store` binary, and the native `epiphany-state` CLI now own durable branch and evidence ledgers. The old tracked JSON ledger files and the migration/projection CLI hatches are gone. - CultCache inspection, cross-language schema synchronization, and debug display tooling belong in CultLib, not in EpiphanyAgent. Epiphany should consume typed CultCache documents and expose product-specific status through its API, while general polyglot domain loading/inspection lives with the shared CultCache ecosystem. - VoidBot's current routine is the reference for the next Epiphany heartbeat/state substrate: work, rumination, and sleep turns; completion-gated cooldown; typed CultCache state; Qdrant-backed memory vectors; resonance/incubation/dream state; and Aquarium-visible internals. The first MessagePack canonical state slice is now the heartbeat store through CultCache-compatible typed Rust state. See `notes/voidbot-routine-adoption-plan.md`. - The Rust CultCache-compatible contract now lives in dedicated upstream `https://github.com/GameCult/cultcache-rs` and is vendored as `vendor/cultcache-rs`. Epiphany should consume it as the canonical typed MessagePack persistence seam instead of growing an embedded local copy like an unsanctioned organ.