Split heartbeat role defaults

This commit is contained in:
Meta Vens 2026-05-18 00:41:34 +01:00
commit 3b55f322f1
5 changed files with 284 additions and 264 deletions

View file

@ -10,9 +10,14 @@ use std::path::Path;
mod heartbeat_documents;
mod heartbeat_projection;
mod heartbeat_roles;
mod heartbeat_store;
pub use heartbeat_documents::*;
pub use heartbeat_projection::heartbeat_status_projection;
pub use heartbeat_roles::default_heartbeat_state;
pub use heartbeat_roles::ghostlight_scene_heartbeat_state;
pub use heartbeat_roles::initialize_ghostlight_scene_heartbeat_store;
pub use heartbeat_roles::initialize_heartbeat_store;
pub use heartbeat_store::heartbeat_state_cache;
pub use heartbeat_store::load_heartbeat_cognition_entry;
pub use heartbeat_store::load_heartbeat_state_entry;
@ -24,23 +29,16 @@ use heartbeat_projection::history_event_json;
use heartbeat_projection::pending_turn_json;
use heartbeat_projection::schedule_participant_json;
use heartbeat_projection::selection_policy_json;
use heartbeat_roles::ROLE_ORDER;
use heartbeat_roles::agent_id_for_role;
use heartbeat_roles::default_participant;
use heartbeat_roles::display_name_for_role;
pub(super) const HEARTBEAT_ARENA_MAINTENANCE: &str = "maintenance";
pub(super) const HEARTBEAT_ARENA_SCENE: &str = "scene";
pub(super) const PARTICIPANT_KIND_AGENT: &str = "agent";
pub(super) const PARTICIPANT_KIND_CHARACTER: &str = "character";
const ROLE_ORDER: &[&str] = &[
"coordinator",
"face",
"imagination",
"research",
"modeling",
"implementation",
"verification",
"reorientation",
];
#[derive(Clone, Debug, PartialEq)]
struct HeartbeatAction {
action_id: String,
@ -53,86 +51,6 @@ struct HeartbeatAction {
local_affordance_basis: Vec<String>,
}
pub fn default_heartbeat_state(target_heartbeat_rate: f64) -> EpiphanyHeartbeatStateEntry {
EpiphanyHeartbeatStateEntry {
schema_version: HEARTBEAT_STATE_SCHEMA_VERSION.to_string(),
target_heartbeat_rate,
scene_clock: 0.0,
selection_policy: HeartbeatSelectionPolicy {
mode: "readiness_queue".to_string(),
reaction_precedence: true,
minimum_speed: 0.2,
tie_breakers: vec![
"reaction_readiness_desc".to_string(),
"next_ready_at_asc".to_string(),
"initiative_speed_desc".to_string(),
"stable_actor_id_asc".to_string(),
],
extra: BTreeMap::new(),
},
pacing_policy: HeartbeatPacingPolicy {
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,
extra: BTreeMap::new(),
},
participants: ROLE_ORDER
.iter()
.map(|role_id| default_participant(role_id))
.collect(),
history: Vec::new(),
extra: BTreeMap::new(),
}
}
pub fn initialize_heartbeat_store(
store_path: impl AsRef<Path>,
target_heartbeat_rate: f64,
) -> Result<EpiphanyHeartbeatStateEntry> {
write_heartbeat_state_entry(store_path, &default_heartbeat_state(target_heartbeat_rate))
}
pub fn ghostlight_scene_heartbeat_state(
target_heartbeat_rate: f64,
scene_id: impl Into<String>,
participants: Vec<GhostlightSceneParticipantSeed>,
) -> Result<EpiphanyHeartbeatStateEntry> {
if participants.is_empty() {
return Err(anyhow!(
"Ghostlight scene heartbeat requires at least one participant"
));
}
let scene_id = scene_id.into();
let mut state = default_heartbeat_state(target_heartbeat_rate);
state.participants = participants
.into_iter()
.map(|seed| ghostlight_scene_participant(&scene_id, seed))
.collect();
state.extra.insert(
"protocol".to_string(),
serde_json::json!({
"domain": "ghostlight",
"sceneId": scene_id,
"arena": HEARTBEAT_ARENA_SCENE,
"contract": "Characters and maintenance organs use one initiative timing law; scene participants receive only projected local context.",
}),
);
validate_heartbeat_state(&state)?;
Ok(state)
}
pub fn initialize_ghostlight_scene_heartbeat_store(
store_path: impl AsRef<Path>,
target_heartbeat_rate: f64,
scene_id: impl Into<String>,
participants: Vec<GhostlightSceneParticipantSeed>,
) -> Result<EpiphanyHeartbeatStateEntry> {
let state = ghostlight_scene_heartbeat_state(target_heartbeat_rate, scene_id, participants)?;
write_heartbeat_state_entry(store_path, &state)
}
pub fn run_void_routine_store(
store_path: impl AsRef<Path>,
artifact_dir: impl AsRef<Path>,
@ -885,77 +803,6 @@ fn is_ghostlight_scene_state(state: &EpiphanyHeartbeatStateEntry) -> bool {
== Some("ghostlight")
}
fn default_participant(role_id: &str) -> HeartbeatParticipant {
HeartbeatParticipant {
agent_id: agent_id_for_role(role_id).to_string(),
role_id: role_id.to_string(),
display_name: display_name_for_role(role_id).to_string(),
arena: HEARTBEAT_ARENA_MAINTENANCE.to_string(),
participant_kind: PARTICIPANT_KIND_AGENT.to_string(),
initiative_speed: initiative_speed_for_role(role_id),
next_ready_at: 0.0,
reaction_bias: reaction_bias_for_role(role_id),
interrupt_threshold: interrupt_threshold_for_role(role_id),
current_load: 0.0,
status: "active".to_string(),
constraints: participant_constraints(role_id)
.into_iter()
.map(str::to_string)
.collect(),
last_action_id: None,
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
extra: BTreeMap::new(),
}
}
fn ghostlight_scene_participant(
scene_id: &str,
seed: GhostlightSceneParticipantSeed,
) -> HeartbeatParticipant {
let role_id = ghostlight_role_id(seed.agent_id.as_str());
let mut extra = BTreeMap::new();
extra.insert("sceneId".to_string(), Value::String(scene_id.to_string()));
HeartbeatParticipant {
agent_id: seed.agent_id,
role_id,
display_name: seed.display_name,
arena: HEARTBEAT_ARENA_SCENE.to_string(),
participant_kind: PARTICIPANT_KIND_CHARACTER.to_string(),
initiative_speed: seed.initiative_speed,
next_ready_at: 0.0,
reaction_bias: seed.reaction_bias,
interrupt_threshold: seed.interrupt_threshold,
current_load: 0.0,
status: "active".to_string(),
constraints: seed.constraints,
last_action_id: None,
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
extra,
}
}
fn ghostlight_role_id(agent_id: &str) -> String {
format!(
"ghostlight.character.{}",
agent_id
.trim()
.chars()
.map(|ch| {
if ch.is_ascii_alphanumeric() {
ch.to_ascii_lowercase()
} else {
'-'
}
})
.collect::<String>()
.trim_matches('-')
)
}
fn participant_index_by_role(state: &EpiphanyHeartbeatStateEntry, role_id: &str) -> Result<usize> {
state
.participants
@ -3399,104 +3246,6 @@ const STOP_WORDS: &[&str] = &[
"through", "when", "with", "work",
];
fn agent_id_for_role(role_id: &str) -> &'static str {
match role_id {
"coordinator" => "epiphany.self",
"face" => "epiphany.face",
"imagination" => "epiphany.imagination",
"research" => "epiphany.eyes",
"modeling" => "epiphany.body",
"implementation" => "epiphany.hands",
"verification" => "epiphany.soul",
"reorientation" => "epiphany.life",
_ => "epiphany.unknown",
}
}
fn display_name_for_role(role_id: &str) -> &'static str {
match role_id {
"coordinator" => "Self",
"face" => "Face",
"imagination" => "Imagination",
"research" => "Eyes",
"modeling" => "Body",
"implementation" => "Hands",
"verification" => "Soul",
"reorientation" => "Life",
_ => "Unknown",
}
}
fn initiative_speed_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 1.28,
"face" => 1.12,
"imagination" => 0.82,
"research" => 0.78,
"modeling" => 0.92,
"implementation" => 0.74,
"verification" => 0.88,
"reorientation" => 1.04,
_ => 1.0,
}
}
fn reaction_bias_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 0.88,
"face" => 0.84,
"imagination" => 0.54,
"research" => 0.62,
"modeling" => 0.74,
"implementation" => 0.58,
"verification" => 0.82,
"reorientation" => 0.86,
_ => 0.5,
}
}
fn interrupt_threshold_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 0.42,
"face" => 0.52,
"imagination" => 0.64,
"research" => 0.58,
"modeling" => 0.5,
"implementation" => 0.5,
"verification" => 0.48,
"reorientation" => 0.44,
_ => 0.5,
}
}
fn participant_constraints(role_id: &str) -> Vec<&'static str> {
let role_specific = match role_id {
"coordinator" => {
"Routes and reviews; must not implement, verify, or accept its own comfort."
}
"face" => {
"Publicly translates agent thought into #aquarium only; must not moderate or speak outside the room."
}
"imagination" => "Synthesizes futures; must not adopt objectives.",
"research" => "Scouts known work; must not turn research into procrastination.",
"modeling" => {
"Grows source-grounded maps and checkpoints; must not edit implementation code."
}
"implementation" => {
"Touches source only with accepted guidance and verifier-readable evidence."
}
"verification" => "Falsifies promises; must not bless theater.",
"reorientation" => "Protects continuity; must not fake survived context.",
_ => "Unknown role.",
};
vec![
"Runs Ghostlight-shaped persistent role memory.",
"May improve lane memory when awake and idle.",
"Project truth belongs in EpiphanyThreadState, not role memory.",
role_specific,
]
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -0,0 +1,271 @@
use super::EpiphanyHeartbeatStateEntry;
use super::GhostlightSceneParticipantSeed;
use super::HEARTBEAT_ARENA_MAINTENANCE;
use super::HEARTBEAT_ARENA_SCENE;
use super::HEARTBEAT_STATE_SCHEMA_VERSION;
use super::HeartbeatPacingPolicy;
use super::HeartbeatParticipant;
use super::HeartbeatSelectionPolicy;
use super::PARTICIPANT_KIND_AGENT;
use super::PARTICIPANT_KIND_CHARACTER;
use super::write_heartbeat_state_entry;
use anyhow::Result;
use anyhow::anyhow;
use std::collections::BTreeMap;
use std::path::Path;
pub(super) const ROLE_ORDER: &[&str] = &[
"coordinator",
"face",
"imagination",
"research",
"modeling",
"implementation",
"verification",
"reorientation",
];
pub fn default_heartbeat_state(target_heartbeat_rate: f64) -> EpiphanyHeartbeatStateEntry {
EpiphanyHeartbeatStateEntry {
schema_version: HEARTBEAT_STATE_SCHEMA_VERSION.to_string(),
target_heartbeat_rate,
scene_clock: 0.0,
selection_policy: HeartbeatSelectionPolicy {
mode: "readiness_queue".to_string(),
reaction_precedence: true,
minimum_speed: 0.2,
tie_breakers: vec![
"reaction_readiness_desc".to_string(),
"next_ready_at_asc".to_string(),
"initiative_speed_desc".to_string(),
"stable_actor_id_asc".to_string(),
],
extra: BTreeMap::new(),
},
pacing_policy: HeartbeatPacingPolicy {
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,
extra: BTreeMap::new(),
},
participants: ROLE_ORDER
.iter()
.map(|role_id| default_participant(role_id))
.collect(),
history: Vec::new(),
extra: BTreeMap::new(),
}
}
pub fn initialize_heartbeat_store(
store_path: impl AsRef<Path>,
target_heartbeat_rate: f64,
) -> Result<EpiphanyHeartbeatStateEntry> {
write_heartbeat_state_entry(store_path, &default_heartbeat_state(target_heartbeat_rate))
}
pub fn ghostlight_scene_heartbeat_state(
target_heartbeat_rate: f64,
scene_id: impl Into<String>,
participants: Vec<GhostlightSceneParticipantSeed>,
) -> Result<EpiphanyHeartbeatStateEntry> {
if participants.is_empty() {
return Err(anyhow!(
"Ghostlight scene heartbeat requires at least one participant"
));
}
let scene_id = scene_id.into();
let mut state = default_heartbeat_state(target_heartbeat_rate);
state.participants = participants
.into_iter()
.map(|seed| ghostlight_scene_participant(&scene_id, seed))
.collect();
state.extra.insert(
"protocol".to_string(),
serde_json::json!({
"domain": "ghostlight",
"sceneId": scene_id,
"arena": HEARTBEAT_ARENA_SCENE,
"contract": "Characters and maintenance organs use one initiative timing law; scene participants receive only projected local context.",
}),
);
super::validate_heartbeat_state(&state)?;
Ok(state)
}
pub fn initialize_ghostlight_scene_heartbeat_store(
store_path: impl AsRef<Path>,
target_heartbeat_rate: f64,
scene_id: impl Into<String>,
participants: Vec<GhostlightSceneParticipantSeed>,
) -> Result<EpiphanyHeartbeatStateEntry> {
let state = ghostlight_scene_heartbeat_state(target_heartbeat_rate, scene_id, participants)?;
write_heartbeat_state_entry(store_path, &state)
}
pub(super) fn default_participant(role_id: &str) -> HeartbeatParticipant {
HeartbeatParticipant {
agent_id: agent_id_for_role(role_id).to_string(),
role_id: role_id.to_string(),
display_name: display_name_for_role(role_id).to_string(),
arena: HEARTBEAT_ARENA_MAINTENANCE.to_string(),
participant_kind: PARTICIPANT_KIND_AGENT.to_string(),
initiative_speed: initiative_speed_for_role(role_id),
next_ready_at: 0.0,
reaction_bias: reaction_bias_for_role(role_id),
interrupt_threshold: interrupt_threshold_for_role(role_id),
current_load: 0.0,
status: "active".to_string(),
constraints: participant_constraints(role_id)
.into_iter()
.map(str::to_string)
.collect(),
last_action_id: None,
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
extra: BTreeMap::new(),
}
}
fn ghostlight_scene_participant(
scene_id: &str,
seed: GhostlightSceneParticipantSeed,
) -> HeartbeatParticipant {
let role_id = ghostlight_role_id(seed.agent_id.as_str());
let mut extra = BTreeMap::new();
extra.insert("sceneId".to_string(), serde_json::json!(scene_id));
HeartbeatParticipant {
agent_id: seed.agent_id,
role_id,
display_name: seed.display_name,
arena: HEARTBEAT_ARENA_SCENE.to_string(),
participant_kind: PARTICIPANT_KIND_CHARACTER.to_string(),
initiative_speed: seed.initiative_speed,
next_ready_at: 0.0,
reaction_bias: seed.reaction_bias,
interrupt_threshold: seed.interrupt_threshold,
current_load: 0.0,
status: "active".to_string(),
constraints: seed.constraints,
last_action_id: None,
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
extra,
}
}
fn ghostlight_role_id(agent_id: &str) -> String {
let sanitized = agent_id
.chars()
.map(|character| {
if character.is_ascii_alphanumeric() {
character.to_ascii_lowercase()
} else {
'-'
}
})
.collect::<String>()
.trim_matches('-')
.to_string();
format!("ghostlight.character.{sanitized}")
}
pub(super) fn agent_id_for_role(role_id: &str) -> &'static str {
match role_id {
"coordinator" => "epiphany.self",
"face" => "epiphany.face",
"imagination" => "epiphany.imagination",
"research" => "epiphany.eyes",
"modeling" => "epiphany.body",
"implementation" => "epiphany.hands",
"verification" => "epiphany.soul",
"reorientation" => "epiphany.life",
_ => "epiphany.unknown",
}
}
pub(super) fn display_name_for_role(role_id: &str) -> &'static str {
match role_id {
"coordinator" => "Self",
"face" => "Face",
"imagination" => "Imagination",
"research" => "Eyes",
"modeling" => "Body",
"implementation" => "Hands",
"verification" => "Soul",
"reorientation" => "Life",
_ => "Unknown",
}
}
fn initiative_speed_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 1.28,
"face" => 1.12,
"imagination" => 0.82,
"research" => 0.78,
"modeling" => 0.92,
"implementation" => 0.74,
"verification" => 0.88,
"reorientation" => 1.04,
_ => 1.0,
}
}
fn reaction_bias_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 0.88,
"face" => 0.84,
"imagination" => 0.54,
"research" => 0.62,
"modeling" => 0.74,
"implementation" => 0.58,
"verification" => 0.82,
"reorientation" => 0.86,
_ => 0.5,
}
}
fn interrupt_threshold_for_role(role_id: &str) -> f64 {
match role_id {
"coordinator" => 0.42,
"face" => 0.52,
"imagination" => 0.64,
"research" => 0.58,
"modeling" => 0.5,
"implementation" => 0.5,
"verification" => 0.48,
"reorientation" => 0.44,
_ => 0.5,
}
}
fn participant_constraints(role_id: &str) -> Vec<&'static str> {
let role_specific = match role_id {
"coordinator" => {
"Routes and reviews; must not implement, verify, or accept its own comfort."
}
"face" => {
"Publicly translates agent thought into #aquarium only; must not moderate or speak outside the room."
}
"imagination" => "Synthesizes futures; must not adopt objectives.",
"research" => "Scouts known work; must not turn research into procrastination.",
"modeling" => "Grows source-grounded maps and checkpoints; must not edit implementation code.",
"implementation" => {
"Touches source only with accepted guidance and verifier-readable evidence."
}
"verification" => "Falsifies promises; must not bless theater.",
"reorientation" => "Protects continuity; must not fake survived context.",
_ => "Unknown role.",
};
vec![
"Runs Ghostlight-shaped persistent role memory.",
"May improve lane memory when awake and idle.",
"Project truth belongs in EpiphanyThreadState, not role memory.",
role_specific,
]
}

View file

@ -58,7 +58,7 @@ remembers doctrine; the branch remembers the blade.
- Thread start route handling and its async lifecycle task now live in `codex_message_processor/thread_start_routes.rs`; root no longer owns `thread_start_task`.
- Thread config helpers now live in `codex_message_processor/thread_config.rs`: instruction-source loading, thread config override construction, config-load error shaping, and dynamic-tool validation. The pure dynamic-tool validation contract has module-local unit tests.
- Turn control routes now live in `codex_message_processor/turn_routes.rs`: turn start, thread item injection, app-server client info setting, turn steer, turn interrupt, mode normalization, and input-limit validation with module-local unit tests.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Thread projection now lives in `codex_message_processor/thread_projection.rs`: state-db/thread-store/rollout summary projection, `ConversationSummary` to API `Thread` mapping, thread-title attachment helpers, turn pagination, and rollout turn reconstruction. `codex_message_processor.rs` is about 1,009 lines after this extraction and mostly owns JSON-RPC dispatch, processor construction, shared thread lookup/submit/error helpers, and lifecycle shutdown.
- Turn paging/reconstruction now lives in `codex_message_processor/thread_turn_projection.rs`; `thread_projection.rs` keeps state-db/thread-store/rollout summary projection and `ConversationSummary` to API `Thread` mapping. Focused `thread_turns_list` cursor tests and stale in-progress turn interruption coverage pass.
- The `thread/turns/list` route handler now lives in `codex_message_processor/thread_turn_routes.rs`, beside the turn projection helpers it consumes. `thread_read_routes.rs` is back to persisted/live thread listing, `thread/read`, loaded-thread listing, and summary reads.

Binary file not shown.

File diff suppressed because one or more lines are too long