From 5e5dba50d5e99e4938cb6f3bdf877744fa13c7ba Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 6 May 2026 04:48:20 +0100 Subject: [PATCH] Integrate CultCache heartbeat store --- .gitignore | 2 + .../src/bin/epiphany-heartbeat-store.rs | 98 +++++ epiphany-core/src/heartbeat_state.rs | 399 ++++++++++++++++++ epiphany-core/src/lib.rs | 18 + notes/fresh-workspace-handoff.md | 6 +- state/agent-heartbeats.msgpack | Bin 0 -> 5936 bytes state/evidence.jsonl | 1 + state/map.yaml | 8 +- tools/epiphany_agent_heartbeat.py | 25 ++ 9 files changed, 550 insertions(+), 7 deletions(-) create mode 100644 epiphany-core/src/bin/epiphany-heartbeat-store.rs create mode 100644 epiphany-core/src/heartbeat_state.rs create mode 100644 state/agent-heartbeats.msgpack diff --git a/.gitignore b/.gitignore index f21eb401..67e6e6e5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ apps/epiphany-gui/src-tauri/target/ .epiphany-dogfood/ .epiphany-heartbeats/ .epiphany-face/ +state/*.msgpack.lock +state/*.projection.json diff --git a/epiphany-core/src/bin/epiphany-heartbeat-store.rs b/epiphany-core/src/bin/epiphany-heartbeat-store.rs new file mode 100644 index 00000000..2b4e6fb0 --- /dev/null +++ b/epiphany-core/src/bin/epiphany-heartbeat-store.rs @@ -0,0 +1,98 @@ +use anyhow::Result; +use anyhow::anyhow; +use epiphany_core::load_heartbeat_state_entry; +use epiphany_core::migrate_heartbeat_json_to_cultcache; +use epiphany_core::write_heartbeat_json_projection; +use std::env; +use std::path::PathBuf; + +fn main() -> Result<()> { + let mut args = env::args().skip(1); + let Some(command) = args.next() else { + return usage(); + }; + let mut json_path: Option = None; + let mut store_path: Option = None; + let mut projection_path: Option = None; + + while let Some(arg) = args.next() { + match arg.as_str() { + "--json" => json_path = Some(next_path(&mut args, "--json")?), + "--store" => store_path = Some(next_path(&mut args, "--store")?), + "--projection" => projection_path = Some(next_path(&mut args, "--projection")?), + _ => return Err(anyhow!("unknown argument {arg:?}")), + } + } + + match command.as_str() { + "migrate-json" => { + let json_path = json_path.ok_or_else(|| anyhow!("migrate-json requires --json"))?; + let store_path = store_path.ok_or_else(|| anyhow!("migrate-json requires --store"))?; + let state = migrate_heartbeat_json_to_cultcache(&json_path, &store_path)?; + if let Some(projection_path) = projection_path { + write_heartbeat_json_projection(&store_path, projection_path)?; + } + println!( + "{}", + serde_json::json!({ + "ok": true, + "command": "migrate-json", + "json": json_path, + "store": store_path, + "schemaVersion": state.schema_version, + "participants": state.participants.len(), + "history": state.history.len(), + }) + ); + } + "project" => { + let store_path = store_path.ok_or_else(|| anyhow!("project requires --store"))?; + let projection_path = + projection_path.ok_or_else(|| anyhow!("project requires --projection"))?; + let state = write_heartbeat_json_projection(&store_path, &projection_path)?; + println!( + "{}", + serde_json::json!({ + "ok": true, + "command": "project", + "store": store_path, + "projection": projection_path, + "schemaVersion": state.schema_version, + "participants": state.participants.len(), + "history": state.history.len(), + }) + ); + } + "status" => { + let store_path = store_path.ok_or_else(|| anyhow!("status requires --store"))?; + let state = load_heartbeat_state_entry(&store_path)?; + println!( + "{}", + serde_json::json!({ + "ok": true, + "command": "status", + "store": store_path, + "present": state.is_some(), + "schemaVersion": state.as_ref().map(|value| value.schema_version.as_str()), + "participants": state.as_ref().map(|value| value.participants.len()), + "history": state.as_ref().map(|value| value.history.len()), + }) + ); + } + _ => return usage(), + } + + Ok(()) +} + +fn next_path(args: &mut impl Iterator, name: &str) -> Result { + args.next() + .map(PathBuf::from) + .ok_or_else(|| anyhow!("{name} requires a value")) +} + +fn usage() -> Result<()> { + Err(anyhow!( + "usage: epiphany-heartbeat-store migrate-json --json --store [--projection ]\n epiphany-heartbeat-store project --store --projection \n epiphany-heartbeat-store status --store " + )) +} diff --git a/epiphany-core/src/heartbeat_state.rs b/epiphany-core/src/heartbeat_state.rs new file mode 100644 index 00000000..a4e3f110 --- /dev/null +++ b/epiphany-core/src/heartbeat_state.rs @@ -0,0 +1,399 @@ +use anyhow::Context; +use anyhow::Result; +use anyhow::anyhow; +use cultcache_rs::CultCache; +use cultcache_rs::DatabaseEntry; +use cultcache_rs::SingleFileMessagePackBackingStore; +use serde::Deserialize; +use serde::Serialize; +use serde_json::Value; +use std::collections::BTreeMap; +use std::fs; +use std::path::Path; + +pub const HEARTBEAT_STATE_TYPE: &str = "epiphany.agent_heartbeat"; +pub const HEARTBEAT_STATE_KEY: &str = "default"; +pub const HEARTBEAT_STATE_SCHEMA_VERSION: &str = "epiphany.agent_heartbeat.v0"; + +#[derive(Clone, Debug, PartialEq, DatabaseEntry)] +#[cultcache( + type = "epiphany.agent_heartbeat", + schema = "EpiphanyHeartbeatStateEntry" +)] +pub struct EpiphanyHeartbeatStateEntry { + #[cultcache(key = 0)] + pub schema_version: String, + #[cultcache(key = 1)] + pub target_heartbeat_rate: f64, + #[cultcache(key = 2)] + pub scene_clock: f64, + #[cultcache(key = 3)] + pub selection_policy: HeartbeatSelectionPolicy, + #[cultcache(key = 4)] + pub pacing_policy: HeartbeatPacingPolicy, + #[cultcache(key = 5)] + pub participants: Vec, + #[cultcache(key = 6)] + pub history: Vec, + #[cultcache(key = 7, default)] + pub sleep_cycle: Option, + #[cultcache(key = 8, default)] + pub memory_resonance: Option, + #[cultcache(key = 9, default)] + pub incubation: Option, + #[cultcache(key = 10, default)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +pub struct HeartbeatSelectionPolicy { + pub mode: String, + pub reaction_precedence: bool, + pub minimum_speed: f64, + pub tie_breakers: Vec, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +pub struct HeartbeatPacingPolicy { + pub cooldown_starts_after_turn_completion: bool, + pub work_base_recovery: f64, + pub idle_base_recovery: f64, + pub sleep_heartbeat_rate_multiplier: f64, + pub minimum_effective_rate: f64, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +pub struct HeartbeatParticipant { + pub agent_id: String, + pub role_id: String, + pub display_name: String, + pub initiative_speed: f64, + pub next_ready_at: f64, + pub reaction_bias: f64, + pub interrupt_threshold: f64, + pub current_load: f64, + pub status: String, + pub constraints: Vec, + pub last_action_id: Option, + pub last_woke_at: Option, + pub last_finished_at: Option, + pub pending_turn: Option, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +pub struct HeartbeatPendingTurn { + pub status: String, + #[serde(rename = "scheduleId")] + pub schedule_id: String, + #[serde(rename = "actionId")] + pub action_id: String, + #[serde(rename = "actionType")] + pub action_type: String, + #[serde(rename = "startedAt")] + pub started_at: String, + #[serde(rename = "startedSceneClock")] + pub started_scene_clock: f64, + #[serde(rename = "baseRecovery")] + pub base_recovery: f64, + pub recovery: f64, + #[serde(rename = "cooldownPolicy")] + pub cooldown_policy: String, + #[serde(rename = "completedAt", default)] + pub completed_at: Option, + #[serde(rename = "completedSceneClock", default)] + pub completed_scene_clock: Option, + #[serde(rename = "nextReadyAt", default)] + pub next_ready_at: Option, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +pub struct HeartbeatHistoryEvent { + pub ts: String, + #[serde(rename = "scheduleId")] + pub schedule_id: String, + #[serde(rename = "selectedRole")] + pub selected_role: String, + #[serde(rename = "selectedAgentId")] + pub selected_agent_id: String, + #[serde(rename = "actionId")] + pub action_id: String, + #[serde(rename = "actionType")] + pub action_type: String, + #[serde(rename = "coordinatorAction", default)] + pub coordinator_action: Option, + #[serde(rename = "targetRole", default)] + pub target_role: Option, + #[serde(rename = "workRole", default)] + pub work_role: Option, + #[serde(rename = "sceneClock", default)] + pub scene_clock: Option, + #[serde(rename = "nextReadyAt", default)] + pub next_ready_at: Option, + #[serde(rename = "turnStatus", default)] + pub turn_status: Option, + #[serde(rename = "cooldownStartedAfterCompletion", default)] + pub cooldown_started_after_completion: Option, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +struct EpiphanyHeartbeatStateProjection { + pub schema_version: String, + pub target_heartbeat_rate: f64, + pub scene_clock: f64, + pub selection_policy: HeartbeatSelectionPolicy, + pub pacing_policy: HeartbeatPacingPolicy, + pub participants: Vec, + pub history: Vec, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub sleep_cycle: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub memory_resonance: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub incubation: Option, + #[serde(flatten)] + pub extra: BTreeMap, +} + +impl From for EpiphanyHeartbeatStateEntry { + fn from(value: EpiphanyHeartbeatStateProjection) -> Self { + Self { + schema_version: value.schema_version, + target_heartbeat_rate: value.target_heartbeat_rate, + scene_clock: value.scene_clock, + selection_policy: value.selection_policy, + pacing_policy: value.pacing_policy, + participants: value.participants, + history: value.history, + sleep_cycle: value.sleep_cycle, + memory_resonance: value.memory_resonance, + incubation: value.incubation, + extra: value.extra, + } + } +} + +impl From for EpiphanyHeartbeatStateProjection { + fn from(value: EpiphanyHeartbeatStateEntry) -> Self { + Self { + schema_version: value.schema_version, + target_heartbeat_rate: value.target_heartbeat_rate, + scene_clock: value.scene_clock, + selection_policy: value.selection_policy, + pacing_policy: value.pacing_policy, + participants: value.participants, + history: value.history, + sleep_cycle: value.sleep_cycle, + memory_resonance: value.memory_resonance, + incubation: value.incubation, + extra: value.extra, + } + } +} + +pub fn heartbeat_state_cache(store_path: impl AsRef) -> Result { + let mut cache = CultCache::new(); + cache.register_entry_type::()?; + cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(store_path.as_ref())); + cache.pull_all_backing_stores()?; + Ok(cache) +} + +pub fn load_heartbeat_state_entry( + store_path: impl AsRef, +) -> Result> { + let cache = heartbeat_state_cache(store_path)?; + cache.get::(HEARTBEAT_STATE_KEY) +} + +pub fn write_heartbeat_state_entry( + store_path: impl AsRef, + state: &EpiphanyHeartbeatStateEntry, +) -> Result { + validate_heartbeat_state(state)?; + let mut cache = heartbeat_state_cache(store_path)?; + cache.put(HEARTBEAT_STATE_KEY, state) +} + +pub fn migrate_heartbeat_json_to_cultcache( + json_path: impl AsRef, + store_path: impl AsRef, +) -> Result { + let state = read_heartbeat_json_projection(json_path)?; + write_heartbeat_state_entry(store_path, &state) +} + +pub fn write_heartbeat_json_projection( + store_path: impl AsRef, + json_path: impl AsRef, +) -> Result { + let state = load_heartbeat_state_entry(store_path.as_ref())?.ok_or_else(|| { + anyhow!( + "CultCache store {} has no heartbeat state entry", + store_path.as_ref().display() + ) + })?; + write_projection_json(json_path, &state)?; + Ok(state) +} + +pub fn read_heartbeat_json_projection( + json_path: impl AsRef, +) -> Result { + let path = json_path.as_ref(); + let raw = fs::read_to_string(path) + .with_context(|| format!("failed to read heartbeat JSON {}", path.display()))?; + let projection: EpiphanyHeartbeatStateProjection = serde_json::from_str(&raw) + .with_context(|| format!("failed to decode heartbeat JSON {}", path.display()))?; + let state = EpiphanyHeartbeatStateEntry::from(projection); + validate_heartbeat_state(&state)?; + Ok(state) +} + +pub fn write_projection_json( + json_path: impl AsRef, + state: &EpiphanyHeartbeatStateEntry, +) -> Result<()> { + validate_heartbeat_state(state)?; + let path = json_path.as_ref(); + if let Some(parent) = path.parent() { + fs::create_dir_all(parent) + .with_context(|| format!("failed to create {}", parent.display()))?; + } + let projection = EpiphanyHeartbeatStateProjection::from(state.clone()); + let raw = serde_json::to_string_pretty(&projection) + .context("failed to encode heartbeat JSON projection")?; + fs::write(path, format!("{raw}\n")) + .with_context(|| format!("failed to write heartbeat JSON {}", path.display()))?; + Ok(()) +} + +pub fn validate_heartbeat_state(state: &EpiphanyHeartbeatStateEntry) -> Result<()> { + if state.schema_version != HEARTBEAT_STATE_SCHEMA_VERSION { + return Err(anyhow!( + "heartbeat state schema_version is {:?}, expected {:?}", + state.schema_version, + HEARTBEAT_STATE_SCHEMA_VERSION + )); + } + if state.participants.is_empty() { + return Err(anyhow!("heartbeat state has no participants")); + } + if state.target_heartbeat_rate < 0.0 { + return Err(anyhow!( + "heartbeat target_heartbeat_rate must be non-negative" + )); + } + for participant in &state.participants { + if participant.agent_id.trim().is_empty() { + return Err(anyhow!("heartbeat participant has empty agent_id")); + } + if participant.role_id.trim().is_empty() { + return Err(anyhow!( + "heartbeat participant {} has empty role_id", + participant.agent_id + )); + } + if participant.initiative_speed <= 0.0 { + return Err(anyhow!( + "heartbeat participant {} initiative_speed must be positive", + participant.agent_id + )); + } + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn heartbeat_json_migrates_to_typed_cultcache_and_projects_back() -> Result<()> { + let temp = tempfile::tempdir()?; + let json_path = temp.path().join("heartbeats.json"); + let store_path = temp.path().join("heartbeats.msgpack"); + let projected_path = temp.path().join("heartbeats.projected.json"); + fs::write(&json_path, sample_json())?; + + let migrated = migrate_heartbeat_json_to_cultcache(&json_path, &store_path)?; + assert_eq!(migrated.schema_version, HEARTBEAT_STATE_SCHEMA_VERSION); + assert_eq!(migrated.participants[0].role_id, "coordinator"); + + let loaded = load_heartbeat_state_entry(&store_path)?.expect("persisted heartbeat state"); + assert_eq!(loaded, migrated); + + write_heartbeat_json_projection(&store_path, &projected_path)?; + let projected = read_heartbeat_json_projection(&projected_path)?; + assert_eq!(projected, migrated); + Ok(()) + } + + #[test] + fn live_heartbeat_json_shape_is_compatible_when_present() -> Result<()> { + let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../state/agent-heartbeats.json"); + if !path.exists() { + return Ok(()); + } + let state = read_heartbeat_json_projection(&path)?; + validate_heartbeat_state(&state)?; + assert!(state.participants.iter().any(|item| item.role_id == "face")); + assert!( + state + .participants + .iter() + .any(|item| item.role_id == "coordinator") + ); + Ok(()) + } + + fn sample_json() -> &'static str { + r#"{ + "schema_version": "epiphany.agent_heartbeat.v0", + "target_heartbeat_rate": 1.0, + "scene_clock": 0.0, + "selection_policy": { + "mode": "readiness_queue", + "reaction_precedence": true, + "minimum_speed": 0.2, + "tie_breakers": ["next_ready_at_asc"] + }, + "pacing_policy": { + "cooldown_starts_after_turn_completion": true, + "work_base_recovery": 6.0, + "idle_base_recovery": 2.0, + "sleep_heartbeat_rate_multiplier": 0.05, + "minimum_effective_rate": 0.001 + }, + "participants": [ + { + "agent_id": "epiphany.self", + "role_id": "coordinator", + "display_name": "Self", + "initiative_speed": 1.28, + "next_ready_at": 0.0, + "reaction_bias": 0.88, + "interrupt_threshold": 0.42, + "current_load": 0.0, + "status": "active", + "constraints": ["Routes and reviews."], + "last_action_id": null, + "last_woke_at": null, + "last_finished_at": null, + "pending_turn": null + } + ], + "history": [] +}"# + } +} diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 021b311a..7b91278a 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -1,4 +1,5 @@ mod distillation; +mod heartbeat_state; mod promotion; mod prompt; mod proposal; @@ -14,6 +15,23 @@ pub use cultcache_rs::SingleFileMessagePackBackingStore; pub use distillation::EpiphanyDistillInput; pub use distillation::EpiphanyDistillProposal; pub use distillation::distill_observation; +pub use heartbeat_state::EpiphanyHeartbeatStateEntry; +pub use heartbeat_state::HEARTBEAT_STATE_KEY; +pub use heartbeat_state::HEARTBEAT_STATE_SCHEMA_VERSION; +pub use heartbeat_state::HEARTBEAT_STATE_TYPE; +pub use heartbeat_state::HeartbeatHistoryEvent; +pub use heartbeat_state::HeartbeatPacingPolicy; +pub use heartbeat_state::HeartbeatParticipant; +pub use heartbeat_state::HeartbeatPendingTurn; +pub use heartbeat_state::HeartbeatSelectionPolicy; +pub use heartbeat_state::heartbeat_state_cache; +pub use heartbeat_state::load_heartbeat_state_entry; +pub use heartbeat_state::migrate_heartbeat_json_to_cultcache; +pub use heartbeat_state::read_heartbeat_json_projection; +pub use heartbeat_state::validate_heartbeat_state; +pub use heartbeat_state::write_heartbeat_json_projection; +pub use heartbeat_state::write_heartbeat_state_entry; +pub use heartbeat_state::write_projection_json; pub use promotion::EpiphanyPromotionDecision; pub use promotion::EpiphanyPromotionInput; pub use promotion::EpiphanyStateReplacementValidationInput; diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 60028e19..256282f3 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -41,9 +41,9 @@ Do not trust this file for the exact live HEAD. Always check git. - The prompt doctrine pass is landed. Shared Epiphany prompts now carry distilled memory/evidence discipline. Rendered state intro/doctrine text lives in `epiphany-core/src/prompts/`, and lane/control prompt text lives in `vendor/codex/codex-rs/app-server/src/prompts/epiphany_specialists.toml`: modeling is the Body, implementation is the Hands and GUI-launched main coding lane, verification is the Soul, reorientation is Life, coordinator remains the read-only Self, and CRRC owns the pre-compaction intervention template. - The Ghostlight memory pass is landed. `epiphany_specialists.toml` now has a shared persistent-memory projection prepended by the harness to fixed role specialists, reorientation workers, coordinator notes, and CRRC checkpoint interventions; `tools/epiphany_gui_action.py` prepends the same memory to GUI-launched implementation prompts. The rendered base doctrine also states the Perfect Machine rule directly: prompt is projection, durable typed state is the mind, every lane must improve its own memory/model/prompt/evidence habit or name the repair, and each lane phrases that duty in its own organ language so the salience sticks. - The role self-memory persistence pass is landed. Each lane has a Ghostlight-shaped dossier under `state/agents`, and specialists may return optional `selfPatch` requests beside their normal role result. `roleResult`/`roleAccept` project coordinator review as `selfPersistence`: accepted requests are role-matched, bounded lane memory/goal/value/private-note mutations; refused requests explain wrong role, project-truth smuggling, authority grabs, bloat, missing reason, or malformed records. GUI/coordinator accept paths apply accepted `selfPatch` requests through `tools/epiphany_agent_memory.py`; project truth still belongs only in `EpiphanyThreadState`. -- The heartbeat initiative pass is landed as a bounded tool seam. `state/agent-heartbeats.json` tracks Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life as Ghostlight-style initiative participants with speed, next-ready time, reaction bias, interrupt threshold, load, status, and constraints. `tools/epiphany_agent_heartbeat.py` lets the harness set a target heartbeat rate, emits Ghostlight-shaped initiative receipts, pulls pending coordinator work through reaction windows, and makes idle winners ruminate into bounded self-memory instead of inventing project work. This is a callable scheduler seam, not yet an always-on daemon. +- The heartbeat initiative pass is landed as a bounded tool seam. `state/agent-heartbeats.json` tracks Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life as Ghostlight-style initiative participants with speed, next-ready time, reaction bias, interrupt threshold, load, status, and constraints. `state/agent-heartbeats.msgpack` is now the first typed CultCache-backed MessagePack store for that same state, through `epiphany-core::EpiphanyHeartbeatStateEntry` and the `epiphany-heartbeat-store` bridge binary. `tools/epiphany_agent_heartbeat.py` still operates on the JSON projection for compatibility, reports the CultCache store status, lets the harness set a target heartbeat rate, emits Ghostlight-shaped initiative receipts, pulls pending coordinator work through reaction windows, and makes idle winners ruminate into bounded self-memory instead of inventing project work. This is a callable scheduler seam, not yet an always-on daemon. - The Face public-surface pass is landed as a bounded lane. `state/agents/face.agent-state.json` gives Face a Ghostlight-shaped dossier; `epiphany_specialists.toml` gives it a VoidBot-heartbeat-derived prompt stripped of moderation authority; `state/face-discord.json` and `tools/epiphany_face_discord.py` enforce that Face may interact only through #aquarium. Missing channel id or token writes candidate chat artifacts instead of posting elsewhere. -- The heartbeat/Face operator API pass is landed. `tools/epiphany_agent_heartbeat.py status` returns machine-readable initiative state, `tools/epiphany_face_discord.py bubble` writes Discord-independent `epiphany.face_bubble.v0` artifacts, `tools/epiphany_mvp_status.py` includes `heartbeat` and `face` blocks, and `tools/epiphany_gui_action.py` exposes `heartbeatStatus`, `runHeartbeat`, and `faceBubble`. `runHeartbeat` advances one slot and emits a Face bubble so Aquarium can show chat even before Discord posting is configured. +- The heartbeat/Face operator API pass is landed. `tools/epiphany_agent_heartbeat.py status` returns machine-readable initiative state plus CultCache store presence, `tools/epiphany_face_discord.py bubble` writes Discord-independent `epiphany.face_bubble.v0` artifacts, `tools/epiphany_mvp_status.py` includes `heartbeat` and `face` blocks, and `tools/epiphany_gui_action.py` exposes `heartbeatStatus`, `runHeartbeat`, and `faceBubble`. `runHeartbeat` advances one slot and emits a Face bubble so Aquarium can show chat even before Discord posting is configured. - The Aetheria dogfood run has a contamination scar. The supervising Codex session directly edited and committed target-repo work on `E:\Projects\Aetheria-Economy` instead of only driving Epiphany lanes. Treat those Aetheria commits as supervisor-seeded implementation, not clean evidence that Epiphany coordinated the work. Future dogfood must run through the GUI/coordinator/fixed role lanes with auditable artifacts unless the user explicitly authorizes an operator intervention. - The dogfood quarantine now has a direct-thought boundary. The supervisor may read coordinator actions, role/reorient statuses, structured finding summaries, reviewed state patches, rendered status snapshots, and artifact manifests. It must not read raw worker transcripts, direct worker messages, full turn logs, or `rawResult` payloads during normal dogfood. Those artifacts are sealed for explicit forensic debugging only. - `tools/epiphany_agent_telemetry.py` is the safe instrument panel for sealed runs. Status/coordinator/GUI/dogfood/live-specialist tools generate telemetry JSON from sealed transcripts that preserves method names, call shape, job/status/path counts, and any visible function/tool names while sealing text, direct messages, and raw results. @@ -132,7 +132,7 @@ The current spine: - durable investigation checkpoint packet through typed state, prompt, scene, and context - distilled shared and config-backed prompt doctrine through the base prompt, rendered Epiphany state prompt files, modeling/Body, implementation/Hands, verification/Soul, reorientation/Life, coordinator/Self, and CRRC intervention surfaces - shared Ghostlight-derived persistent memory projection across Imagination, Body, Soul, Life, Self, CRRC checkpoint steering, and the GUI-launched Hands implementation lane -- Ghostlight-derived heartbeat initiative scheduling through `tools/epiphany_agent_heartbeat.py`, with Self and Face included as first-class participants and idle rumination routed through normal `selfPatch` review/application +- Ghostlight-derived heartbeat initiative scheduling through `tools/epiphany_agent_heartbeat.py`, with Self and Face included as first-class participants, idle rumination routed through normal `selfPatch` review/application, and the heartbeat state round-tripped through the typed CultCache MessagePack store in `state/agent-heartbeats.msgpack` - Face as the public #aquarium-only surface for translating agent thought-weather into short chats or candidate drafts, without moderator authority - Ghostlight-shaped role dossiers under `state/agents`, plus `selfPatch` review projection through `roleResult`/`roleAccept` and accepted memory application through `tools/epiphany_agent_memory.py` - first Unity runtime bridge through `tools/epiphany_unity_bridge.py`, `tools/epiphany_unity_bridge_smoke.py`, GUI Inspect Unity, runtime artifact listing, and implementation prompt guardrails diff --git a/state/agent-heartbeats.msgpack b/state/agent-heartbeats.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..0fd5dbe4fbf0457da466affc4f2616d3c4fe2469 GIT binary patch literal 5936 zcmd^DU1%It6fXGYvx-kLB85t`+s$^hQkD{5UVKFGfLA`#KnACy|91uKX?c<#*3?94c6Qffis5(2w( z=FXk(`_4JvJ+B=;YC@fOmOKwGbsNNK<;f&CQf~m^vIazcdf$z=K3M5ue!9@9UfbY* zIz#u`XMecs&+>~iHZ$P_2VznOgwPLo;K34pHzZ|_?s71|1jm4j3pRDA?b*6;0nASI zvp3Y|&3Q>dui*_-z{TNn(Ve{|O%TQ@2cDC<`mLoCsS{zmhpS0SB%Ov}MP0=$2}x=e z==gZXb!w`}L(3Zt#w?RH9UU)oDRfeoz;)?yM>m-5TA((2@pO~%DZNGn;FAnC4ZPJE zx<7d1)6~ReQ`dq^8$K2mfZKyn=R|^TBhu8hDDY18Sn#fALkOT=2LuSWu0lK2{k46c zUqANO>#xiPj8JnSqCtRFKgt3b7v`+(W(-D#rTt^&U&X0MH&_)_eNQ+K3WKJ}Q3#R5G;Z#Um zOH;3>*9b=vZ;jhSHnnF`NqS>C1ekg9k0vos3r=c8Z zz162Nt`WlkS87xW4MnA)gzAjT{Gvq!YBNwiH7`VYm5_~L6#`lyLY`;w=~&KerXPDW?m1H>>|wBG@~@JR~}lfyNxGr8Oy|eVgfTx(XeLF`#8pB(0ff8Ja=Y|^eXz0!)$uL3JwtKjouQTF(mpo zfo0vn*6vZ+iq-$RI*|yEPouvx{SZ8?-T|KL#E5vFQD2hTyBmMWp!d4Z*wqxhLmPtw ze7fLY2`qdzy_W)|tT%d%{a($Y23C1IvpT}UG{ttWMkAQC%)=vV;O!nF2Ry>5XZtN7 zCIIEa)InaI4RN|brZnXlu?MK6$HOhN(`s1ibpl1?s`bBAsFc=N{|~?XwiGM3k2!(8 z&Gal7HJ2X@eMK(XPA=J)=5hLf!UuBjcbW1L*%)LbV4Z+y6u z#x~Z<@wN!sRYnXkY)^z^2R#_G{1f4JCYJ40(F=!3w~5}?LS<`z;BaE-oy$PauY95Q z6yJU=Tp2MHA0d{Ncrlo6Cc!gU;?-Kd+$Vyf5e>mhCUUo_-3p@ZcKd}h(e!QGL}6>C KRH~GUPyY>ef@2^6 literal 0 HcmV?d00001 diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 2e74624a..a784c188 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -82,3 +82,4 @@ {"ts": "2026-05-06T00:08:00+00:00", "type": "implementation", "status": "ok", "note": "Heartbeat pacing now supports deferred turn completion: `tick --defer-completion` leaves a lane in-flight and `complete --role ...` starts cooldown only after the heartbeat turn finishes. Idle/no-work heartbeats use a sleep multiplier so the swarm continues slow rumination and memory distillation without waking every lane at work tempo."} {"ts": "2026-05-06T00:25:00+00:00", "type": "architecture", "status": "ok", "note": "VoidBot's new routine should become the reference Epiphany agent substrate: work/rumination/sleep heartbeats, completion-gated cooldown, typed MessagePack persistence through a Rust CultCache-compatible contract, JSON working projections, Qdrant-backed memory vectors, resonance/incubation/dream organs, and Aquarium-visible internals. Captured the migration plan in notes/voidbot-routine-adoption-plan.md."} {"ts": "2026-05-06T03:05:00+00:00", "type": "implementation", "status": "ok", "note": "Created the dedicated GameCult/cultcache-rs repo and wired it into EpiphanyAgent as vendor/cultcache-rs. The Rust API follows CultCache ergonomics: domain structs implement CultCacheDocument, consumers register/get/put typed domain values directly, entries are keyed by type::key, backing stores are persistence adapters, and SingleFileMessagePackBackingStore provides the initial canonical MessagePack store."} +{"ts": "2026-05-06T03:46:28+00:00", "type": "implementation", "status": "ok", "note": "Integrated CultCache into the first live Epiphany state surface: heartbeat initiative state now has epiphany-core::EpiphanyHeartbeatStateEntry, an epiphany-heartbeat-store migrate/project/status bridge, committed state/agent-heartbeats.msgpack, and heartbeat status reflects the backing store while JSON remains the reviewable projection."} diff --git a/state/map.yaml b/state/map.yaml index 9e7fe45d..f0f2be47 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -127,11 +127,11 @@ accepted_design: - Specialist prompts are role-distilled instead of generic and their live text is config-backed in app-server: modeling/checkpoint is the Body of code, dataflow, seams, and frontier; research/scout is the Eyes prompt surface for existing work, vendor guidance, libraries, papers, and anti-Greenspun source selection; implementation is the Hands, the main coding lane and actuator rather than a `roleLaunch` specialist; verification/review is the Soul of promise, invariants, evidence, and user truth; reorientation is Life across compaction and source drift; coordinator is the read-only Self that routes attention without implementing, verifying, promoting, or accepting; Face is the public Discord #aquarium surface that translates agent thought-weather without moderating or leaking sealed thought. - 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 also states that self-improvement in its own role 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 persistence surface under `state/agents`: Imagination, Body, Eyes, Hands, Soul, Life, Self, and Face each have an individual role dossier for identity, personality, semantic/episodic/relationship memory, goals, and values. These files are lane memory only; project truth remains in authoritative `EpiphanyThreadState`. - - `state/agent-heartbeats.json` and `tools/epiphany_agent_heartbeat.py` are the first 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 may apply a bounded selfPatch through the normal coordinator-reviewed memory rules. Face can win `surfaceAgentThoughts` or `discordAquariumChat` work slots. - - VoidBot's current routine is the reference for the next Epiphany heartbeat/state substrate: work, rumination, and sleep turns; completion-gated cooldown; MessagePack canonical state through a CultCache-compatible typed store; JSON working projections; Qdrant-backed memory vectors; resonance/incubation/dream state; and Aquarium-visible internals. See `notes/voidbot-routine-adoption-plan.md`. + - `state/agent-heartbeats.json`, `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, and `tools/epiphany_agent_heartbeat.py` are the first 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 may apply a bounded selfPatch through the normal coordinator-reviewed memory rules. Face can win `surfaceAgentThoughts` or `discordAquariumChat` work slots. JSON remains the human-readable projection while the typed CultCache MessagePack store is the canonical Rust persistence seam. + - VoidBot's current routine is the reference for the next Epiphany heartbeat/state substrate: work, rumination, and sleep turns; completion-gated cooldown; JSON working projections; 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. - `state/face-discord.json` and `tools/epiphany_face_discord.py` are the first Face Discord boundary. Face may interact only through #aquarium; missing or mismatched channel configuration produces candidate chat artifacts instead of posting elsewhere. - - `tools/epiphany_agent_heartbeat.py status`, the `heartbeat` block in `tools/epiphany_mvp_status.py`, and GUI actions `heartbeatStatus` / `runHeartbeat` are the first operator API surface for heartbeat initiative state and outputs. `runHeartbeat` advances one slot and emits a Discord-independent Face bubble artifact. + - `tools/epiphany_agent_heartbeat.py status`, the `heartbeat` block in `tools/epiphany_mvp_status.py`, and GUI actions `heartbeatStatus` / `runHeartbeat` are the first operator API surface for heartbeat initiative state and outputs. `runHeartbeat` advances one slot and emits a Discord-independent Face bubble artifact. Status now reflects the backing CultCache store so Aquarium can see whether the typed heartbeat memory is present. - `tools/epiphany_face_discord.py bubble`, the `face` block in `tools/epiphany_mvp_status.py`, and GUI action `faceBubble` are the first Aquarium bubble surface. Face can open a local chat bubble artifact even when Discord channel id/token configuration is absent. - `thread/epiphany/roleResult` and `thread/epiphany/roleAccept` now project optional specialist `selfPatch` requests with coordinator review through `selfPersistence`: good mutations are role-matched, bounded, evidence-grounded lane memory/goal/value/private-note updates; project truth, authority, code edits, graphs, checkpoints, planning, scratch, jobs, and raw transcripts are refused with reasons. GUI/coordinator acceptance paths apply accepted `selfPatch` requests through `tools/epiphany_agent_memory.py`. - The base Epiphany prompt now keeps Codex's useful harness DNA explicitly: AGENTS scope, concise progress updates, plan discipline, scoped edits, non-destructive filesystem/git behavior, focused validation, and concise honest finals remain first-class rather than overwritten by Epiphany metaphor. @@ -186,7 +186,7 @@ landed_baseline: - Phase 6 Aquarium graph and Rider bridge slice: the Tauri/React/WebGL Aquarium embeds the adjacent EpiphanyGraph viewer over typed graph state, `tools/epiphany_rider_bridge.py` writes Rider/source-context artifacts, Aquarium Inspect Rider surfaces those artifacts, and `integrations/rider` scaffolds the first frontend-only Rider tool-window/context-action plugin. - Phase 6 role self-memory slice: Ghostlight-shaped role dossiers live under `state/agents`, specialists may request bounded `selfPatch` lane-memory mutations, coordinator review projects acceptance/refusal reasons through `selfPersistence`, and GUI/coordinator accept paths apply accepted requests with `tools/epiphany_agent_memory.py`. - Phase 6 Face public-surface slice: `state/agents/face.agent-state.json`, Face prompt text, `state/face-discord.json`, and `tools/epiphany_face_discord.py` establish Face as the public #aquarium-only translator of Epiphany agent thought-weather, without VoidBot's moderation authority. - - Phase 6 heartbeat initiative slice: `tools/epiphany_agent_heartbeat.py`, `state/agent-heartbeats.json`, and heartbeat smoke coverage borrow Ghostlight initiative scheduling so Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life compete for heartbeat slots; idle slots become bounded memory rumination instead of fake project work. + - Phase 6 heartbeat initiative slice: `tools/epiphany_agent_heartbeat.py`, `state/agent-heartbeats.json`, `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, the `epiphany-heartbeat-store` bridge binary, and heartbeat smoke coverage borrow Ghostlight initiative scheduling so Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life compete for heartbeat slots; idle slots become bounded memory rumination instead of fake project work, and the first live state surface can round-trip through typed CultCache MessagePack. guardrails: - Use `tools/epiphany_phase5_smoke.py` before modifying update, distill, propose, promote, read-projection, or notification behavior. - Use `tools/epiphany_phase6_scene_smoke.py` before modifying scene projection behavior. diff --git a/tools/epiphany_agent_heartbeat.py b/tools/epiphany_agent_heartbeat.py index aa222c94..ea9e682b 100644 --- a/tools/epiphany_agent_heartbeat.py +++ b/tools/epiphany_agent_heartbeat.py @@ -16,6 +16,7 @@ from epiphany_agent_memory import validate_all ROOT = Path(__file__).resolve().parents[1] DEFAULT_HEARTBEAT_STATE = ROOT / "state" / "agent-heartbeats.json" +DEFAULT_HEARTBEAT_STORE = ROOT / "state" / "agent-heartbeats.msgpack" DEFAULT_ARTIFACT_DIR = ROOT / ".epiphany-heartbeats" SCHEMA_VERSION = "epiphany.agent_heartbeat.v0" STATUS_SCHEMA_VERSION = "epiphany.agent_heartbeat_status.v0" @@ -155,6 +156,25 @@ def latest_json_artifacts(artifact_dir: Path, *, limit: int = 8) -> list[dict[st return artifacts +def cultcache_store_status(store_file: Path = DEFAULT_HEARTBEAT_STORE) -> dict[str, Any]: + if not store_file.exists(): + return { + "storeFile": str(store_file), + "present": False, + "sizeBytes": None, + "modifiedAt": None, + } + stat = store_file.stat() + return { + "storeFile": str(store_file), + "present": True, + "sizeBytes": stat.st_size, + "modifiedAt": datetime.fromtimestamp(stat.st_mtime, timezone.utc).replace(microsecond=0).isoformat(), + "entryType": "epiphany.agent_heartbeat", + "entryKey": "default", + } + + def artifact_summary(payload: Any) -> dict[str, Any]: if not isinstance(payload, dict): return {"type": type(payload).__name__} @@ -271,6 +291,7 @@ def load_state(path: Path, *, target_heartbeat_rate: float) -> dict[str, Any]: def heartbeat_status( *, state_file: Path = DEFAULT_HEARTBEAT_STATE, + store_file: Path = DEFAULT_HEARTBEAT_STORE, artifact_dir: Path = DEFAULT_ARTIFACT_DIR, target_heartbeat_rate: float = 0.0, artifact_limit: int = 8, @@ -281,6 +302,7 @@ def heartbeat_status( "ok": True, "status": "missing", "stateFile": str(state_file), + "cultCacheStore": cultcache_store_status(store_file), "artifactDir": str(artifact_dir), "targetHeartbeatRate": target_heartbeat_rate if target_heartbeat_rate > 0 else None, "sceneClock": None, @@ -324,6 +346,7 @@ def heartbeat_status( "ok": True, "status": "ready", "stateFile": str(state_file), + "cultCacheStore": cultcache_store_status(store_file), "artifactDir": str(artifact_dir), "targetHeartbeatRate": state.get("target_heartbeat_rate"), "sceneClock": state.get("scene_clock"), @@ -733,6 +756,7 @@ def run_complete(args: argparse.Namespace) -> dict[str, Any]: def run_status(args: argparse.Namespace) -> dict[str, Any]: return heartbeat_status( state_file=args.state_file, + store_file=args.store_file, artifact_dir=args.artifact_dir, target_heartbeat_rate=args.target_heartbeat_rate, artifact_limit=args.limit, @@ -903,6 +927,7 @@ def build_parser() -> argparse.ArgumentParser: status = subparsers.add_parser("status") status.add_argument("--state-file", type=Path, default=DEFAULT_HEARTBEAT_STATE) + status.add_argument("--store-file", type=Path, default=DEFAULT_HEARTBEAT_STORE) status.add_argument("--artifact-dir", type=Path, default=DEFAULT_ARTIFACT_DIR) status.add_argument("--target-heartbeat-rate", type=float, default=0.0) status.add_argument("--limit", type=int, default=8)