Add Ghostlight scene heartbeat profile

This commit is contained in:
Meta Vens 2026-05-06 14:20:42 +01:00
commit 66f8c82a9f
6 changed files with 401 additions and 70 deletions

View file

@ -1,11 +1,13 @@
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use epiphany_core::GhostlightSceneParticipantSeed;
use epiphany_core::HeartbeatCompleteOptions;
use epiphany_core::HeartbeatTickOptions;
use epiphany_core::apply_agent_self_patch;
use epiphany_core::complete_heartbeat_store;
use epiphany_core::heartbeat_status_projection;
use epiphany_core::initialize_ghostlight_scene_heartbeat_store;
use epiphany_core::initialize_heartbeat_store;
use epiphany_core::load_heartbeat_state_entry;
use epiphany_core::tick_heartbeat_store;
@ -35,6 +37,9 @@ fn main() -> Result<()> {
let mut limit = 8_usize;
let mut agent_store: Option<PathBuf> = None;
let mut apply_rumination = false;
let mut profile = "epiphany".to_string();
let mut scene_id = "ghostlight.scene".to_string();
let mut scene_participants = Vec::<GhostlightSceneParticipantSeed>::new();
while let Some(arg) = args.next() {
match arg.as_str() {
@ -56,6 +61,11 @@ fn main() -> Result<()> {
"--limit" => limit = next_value(&mut args, "--limit")?.parse()?,
"--agent-store" => agent_store = Some(next_path(&mut args, "--agent-store")?),
"--apply-rumination" => apply_rumination = true,
"--profile" => profile = next_value(&mut args, "--profile")?,
"--scene-id" => scene_id = next_value(&mut args, "--scene-id")?,
"--scene-participant" => scene_participants.push(parse_scene_participant(
&next_value(&mut args, "--scene-participant")?,
)?),
_ => return Err(anyhow!("unknown argument {arg:?}")),
}
}
@ -63,12 +73,22 @@ fn main() -> Result<()> {
match command.as_str() {
"init" => {
let store_path = store_path.ok_or_else(|| anyhow!("init requires --store"))?;
let state = initialize_heartbeat_store(&store_path, target_heartbeat_rate)?;
let state = match profile.as_str() {
"epiphany" => initialize_heartbeat_store(&store_path, target_heartbeat_rate)?,
"ghostlight-scene" => initialize_ghostlight_scene_heartbeat_store(
&store_path,
target_heartbeat_rate,
scene_id.clone(),
scene_participants,
)?,
other => return Err(anyhow!("unknown heartbeat profile {other:?}")),
};
println!(
"{}",
serde_json::json!({
"ok": true,
"command": "init",
"profile": profile,
"storeFile": store_path,
"schemaVersion": state.schema_version,
"participants": state.participants.len(),
@ -177,10 +197,32 @@ fn next_value(args: &mut impl Iterator<Item = String>, name: &str) -> Result<Str
fn usage() -> Result<()> {
Err(anyhow!(
"usage: epiphany-heartbeat-store init --store <path>\n epiphany-heartbeat-store tick --store <path> --artifact-dir <path> [--coordinator-action <action>] [--agent-store <path> --apply-rumination] [--defer-completion]\n epiphany-heartbeat-store complete --store <path> --artifact-dir <path> --role <role> [--action-id <id>]\n epiphany-heartbeat-store status --store <path> [--artifact-dir <path>]\n epiphany-heartbeat-store smoke [--agent-store <path>]"
"usage: epiphany-heartbeat-store init --store <path> [--profile epiphany|ghostlight-scene] [--scene-id <id>] [--scene-participant <id|name|speed|reaction|threshold|constraint;constraint>]\n epiphany-heartbeat-store tick --store <path> --artifact-dir <path> [--coordinator-action <action>] [--agent-store <path> --apply-rumination] [--defer-completion]\n epiphany-heartbeat-store complete --store <path> --artifact-dir <path> --role <role> [--action-id <id>]\n epiphany-heartbeat-store status --store <path> [--artifact-dir <path>]\n epiphany-heartbeat-store smoke [--agent-store <path>]"
))
}
fn parse_scene_participant(raw: &str) -> Result<GhostlightSceneParticipantSeed> {
let parts = raw.split('|').collect::<Vec<_>>();
if parts.len() != 6 {
return Err(anyhow!(
"--scene-participant must be id|name|speed|reaction|threshold|constraint;constraint"
));
}
Ok(GhostlightSceneParticipantSeed {
agent_id: parts[0].trim().to_string(),
display_name: parts[1].trim().to_string(),
initiative_speed: parts[2].trim().parse()?,
reaction_bias: parts[3].trim().parse()?,
interrupt_threshold: parts[4].trim().parse()?,
constraints: parts[5]
.split(';')
.map(str::trim)
.filter(|item| !item.is_empty())
.map(str::to_string)
.collect(),
})
}
fn run_smoke(agent_store: &Path) -> Result<serde_json::Value> {
let temp_dir = scoped_temp_dir("epiphany-heartbeat-smoke")?;
let temp_agent_store = temp_dir.join("agents.msgpack");
@ -423,6 +465,9 @@ fn validate_schedule_shape(schedule: &serde_json::Value) -> Vec<String> {
"attack",
"wait",
"mixed",
"role_work",
"ruminate_memory",
"scene_turn",
]
.contains(&action["action_type"].as_str().unwrap_or_default())
{
@ -461,6 +506,8 @@ fn validate_schedule_shape(schedule: &serde_json::Value) -> Vec<String> {
.filter(|key| {
![
"agent_id",
"arena",
"participant_kind",
"next_ready_at",
"reaction_readiness",
"eligible_for_reaction",

View file

@ -18,6 +18,11 @@ pub const HEARTBEAT_STATE_SCHEMA_VERSION: &str = "epiphany.agent_heartbeat.v0";
pub const HEARTBEAT_STATUS_SCHEMA_VERSION: &str = "epiphany.agent_heartbeat_status.v0";
pub const INITIATIVE_SCHEMA_VERSION: &str = "ghostlight.initiative_schedule.v0";
const HEARTBEAT_ARENA_MAINTENANCE: &str = "maintenance";
const HEARTBEAT_ARENA_SCENE: &str = "scene";
const PARTICIPANT_KIND_AGENT: &str = "agent";
const PARTICIPANT_KIND_CHARACTER: &str = "character";
const ROLE_ORDER: &[&str] = &[
"coordinator",
"face",
@ -85,6 +90,10 @@ pub struct HeartbeatParticipant {
pub agent_id: String,
pub role_id: String,
pub display_name: String,
#[serde(default)]
pub arena: String,
#[serde(default)]
pub participant_kind: String,
pub initiative_speed: f64,
pub next_ready_at: f64,
pub reaction_bias: f64,
@ -109,6 +118,10 @@ pub struct HeartbeatPendingTurn {
pub action_id: String,
#[serde(rename = "actionType")]
pub action_type: String,
#[serde(rename = "actionScale", default)]
pub action_scale: String,
#[serde(rename = "localAffordanceBasis", default)]
pub local_affordance_basis: Vec<String>,
#[serde(rename = "startedAt")]
pub started_at: String,
#[serde(rename = "startedSceneClock")]
@ -141,6 +154,12 @@ pub struct HeartbeatHistoryEvent {
pub action_id: String,
#[serde(rename = "actionType")]
pub action_type: String,
#[serde(default)]
pub arena: String,
#[serde(rename = "participantKind", default)]
pub participant_kind: String,
#[serde(rename = "actionScale", default)]
pub action_scale: String,
#[serde(rename = "coordinatorAction", default)]
pub coordinator_action: Option<String>,
#[serde(rename = "targetRole", default)]
@ -176,6 +195,28 @@ pub struct HeartbeatCompleteOptions {
pub action_id: Option<String>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct GhostlightSceneParticipantSeed {
pub agent_id: String,
pub display_name: String,
pub initiative_speed: f64,
pub reaction_bias: f64,
pub interrupt_threshold: f64,
pub constraints: Vec<String>,
}
#[derive(Clone, Debug, PartialEq)]
struct HeartbeatAction {
action_id: String,
action_type: &'static str,
action_scale: &'static str,
base_recovery: f64,
initiative_cost: f64,
interruptibility: f64,
commitment: f64,
local_affordance_basis: Vec<String>,
}
pub fn heartbeat_state_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
let mut cache = CultCache::new();
cache.register_entry_type::<EpiphanyHeartbeatStateEntry>()?;
@ -232,6 +273,25 @@ pub fn validate_heartbeat_state(state: &EpiphanyHeartbeatStateEntry) -> Result<(
participant.agent_id
));
}
let arena = participant_arena(participant);
if !matches!(arena, HEARTBEAT_ARENA_MAINTENANCE | HEARTBEAT_ARENA_SCENE) {
return Err(anyhow!(
"heartbeat participant {} arena {:?} is unsupported",
participant.agent_id,
arena
));
}
let participant_kind = participant_kind(participant);
if !matches!(
participant_kind,
PARTICIPANT_KIND_AGENT | PARTICIPANT_KIND_CHARACTER
) {
return Err(anyhow!(
"heartbeat participant {} participant_kind {:?} is unsupported",
participant.agent_id,
participant_kind
));
}
}
Ok(())
}
@ -280,6 +340,45 @@ pub fn initialize_heartbeat_store(
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 heartbeat_status_projection(
store_path: impl AsRef<Path>,
artifact_dir: impl AsRef<Path>,
@ -411,6 +510,9 @@ pub fn complete_heartbeat_store(
selected_agent_id: participant.agent_id.clone(),
action_id: completed.action_id.clone(),
action_type: completed.action_type.clone(),
arena: participant_arena(participant).to_string(),
participant_kind: participant_kind(participant).to_string(),
action_scale: completed.action_scale.clone(),
coordinator_action: None,
target_role: None,
work_role: None,
@ -454,31 +556,28 @@ fn tick_once(
let (selected_index, selection_kind, selection_reason) =
select_participant(state, work_role.as_deref(), options.urgency)?;
let selected = state.participants[selected_index].clone();
let (action_id, action_type, base_recovery, initiative_cost, interruptibility, action_reason) =
action_for_selection(
state,
&selected,
work_role.as_deref(),
options.coordinator_action.as_deref(),
rate,
);
let action = action_for_selection(
state,
&selected,
work_role.as_deref(),
options.coordinator_action.as_deref(),
rate,
);
let scene_clock = state.scene_clock.max(selected.next_ready_at);
let recovery = base_recovery
let recovery = action.base_recovery
/ selected
.initiative_speed
.max(state.selection_policy.minimum_speed);
let pending = HeartbeatPendingTurn {
status: "running".to_string(),
schedule_id: options.schedule_id.clone(),
action_id: action_id.clone(),
action_type: if action_id.ends_with(".ruminate") {
"ruminate_memory".to_string()
} else {
"role_work".to_string()
},
action_id: action.action_id.clone(),
action_type: action.action_type.to_string(),
action_scale: action.action_scale.to_string(),
local_affordance_basis: action.local_affordance_basis.clone(),
started_at: now_iso(),
started_scene_clock: round6(scene_clock),
base_recovery: round6(base_recovery),
base_recovery: round6(action.base_recovery),
recovery: round6(recovery),
cooldown_policy: "after_turn_completion".to_string(),
completed_at: None,
@ -487,7 +586,7 @@ fn tick_once(
extra: BTreeMap::new(),
};
state.participants[selected_index].pending_turn = Some(pending.clone());
state.participants[selected_index].last_action_id = Some(action_id.clone());
state.participants[selected_index].last_action_id = Some(action.action_id.clone());
state.participants[selected_index].last_woke_at = Some(now_iso());
state.participants[selected_index].current_load =
round6((state.participants[selected_index].current_load * 0.75).clamp(0.0, 1.0));
@ -497,18 +596,16 @@ fn tick_once(
}
let selected_after = state.participants[selected_index].clone();
let action_event_type = if action_id.ends_with(".ruminate") {
"ruminate_memory"
} else {
"role_work"
};
let event = HeartbeatHistoryEvent {
ts: now_iso(),
schedule_id: options.schedule_id.clone(),
selected_role: selected_after.role_id.clone(),
selected_agent_id: selected_after.agent_id.clone(),
action_id: action_id.clone(),
action_type: action_event_type.to_string(),
action_id: action.action_id.clone(),
action_type: action.action_type.to_string(),
arena: participant_arena(&selected_after).to_string(),
participant_kind: participant_kind(&selected_after).to_string(),
action_scale: action.action_scale.to_string(),
coordinator_action: options.coordinator_action.clone(),
target_role: options.target_role.clone(),
work_role: work_role.clone(),
@ -533,26 +630,24 @@ fn tick_once(
"scene_clock": state.scene_clock,
"participants": state.participants.iter().map(schedule_participant_json).collect::<Vec<_>>(),
"action_catalog": [{
"action_id": action_id,
"action_id": action.action_id,
"actor_id": selected_after.agent_id,
"action_type": action_type,
"action_scale": if action_id.ends_with(".ruminate") { "short" } else { "standard" },
"base_recovery": base_recovery,
"initiative_cost": initiative_cost,
"interruptibility": interruptibility,
"commitment": if action_id.ends_with(".ruminate") { 0.25 } else { 0.65 },
"local_affordance_basis": [
action_reason,
"Heartbeat slots control opportunity, not project authority.",
"Cooldown starts only after the heartbeat turn completes, so an unfinished sub-agent thread cannot be heartbeaten again."
],
"arena": participant_arena(&selected_after),
"participant_kind": participant_kind(&selected_after),
"action_type": action.action_type,
"action_scale": action.action_scale,
"base_recovery": action.base_recovery,
"initiative_cost": action.initiative_cost,
"interruptibility": action.interruptibility,
"commitment": action.commitment,
"local_affordance_basis": action.local_affordance_basis,
}],
"reaction_windows": if let Some(work_role) = &work_role {
serde_json::json!([{
"window_id": format!("{}.pending-work", options.schedule_id),
"trigger_event_ref": options.source_scene_ref,
"urgency": options.urgency,
"eligible_actor_ids": [agent_id_for_role(work_role)],
"eligible_actor_ids": [agent_id_for_work_role(state, work_role)],
"allowed_action_scales": ["short", "standard"],
"expires_at": round6(state.scene_clock + 1.0),
"notes": "Pending coordinator work can pull its owning lane forward only if readiness clears threshold."
@ -564,7 +659,7 @@ fn tick_once(
"next_actor_selection": {
"selection_kind": selection_kind,
"selected_actor_id": selected_after.agent_id,
"selected_action_ids": [action_id],
"selected_action_ids": [event.action_id.clone()],
"scene_clock_after_selection": state.scene_clock,
"selection_reason": selection_reason,
"override_reason": null,
@ -577,10 +672,10 @@ fn tick_once(
],
});
let rumination = if action_id.ends_with(".ruminate") {
let rumination = if event.action_type == "ruminate_memory" {
serde_json::json!({
"roleId": selected_after.role_id,
"selfPatch": rumination_patch(&selected_after.role_id, &action_id),
"selfPatch": rumination_patch(&selected_after.role_id, &event.action_id),
"result": null,
"applied": false,
})
@ -698,23 +793,51 @@ fn action_for_selection(
work_role: Option<&str>,
coordinator_action: Option<&str>,
target_heartbeat_rate: f64,
) -> (String, &'static str, f64, f64, f64, String) {
) -> HeartbeatAction {
let minimum_rate = state.pacing_policy.minimum_effective_rate.max(0.001);
if participant_arena(selected) == HEARTBEAT_ARENA_SCENE {
let heartbeat_rate = target_heartbeat_rate.max(minimum_rate);
return HeartbeatAction {
action_id: format!("heartbeat.{}.scene-turn", selected.role_id),
action_type: "scene_turn",
action_scale: "standard",
base_recovery: state.pacing_policy.work_base_recovery / heartbeat_rate,
initiative_cost: 4.0,
interruptibility: 0.5,
commitment: 0.7,
local_affordance_basis: vec![
format!(
"Project {} from current Ghostlight scene state and run one local character turn.",
selected.display_name
),
"Selected actor receives only projected local context, not omniscient coordinator state."
.to_string(),
"The same heartbeat timing law schedules scene characters and maintenance organs."
.to_string(),
],
};
}
if Some(selected.role_id.as_str()) == work_role {
let heartbeat_rate = target_heartbeat_rate.max(minimum_rate);
let action_id = format!("heartbeat.{}.work", selected.role_id);
return (
return HeartbeatAction {
action_id,
"mixed",
state.pacing_policy.work_base_recovery / heartbeat_rate,
4.0,
0.45,
format!(
action_type: "role_work",
action_scale: "standard",
base_recovery: state.pacing_policy.work_base_recovery / heartbeat_rate,
initiative_cost: 4.0,
interruptibility: 0.45,
commitment: 0.65,
local_affordance_basis: vec![
format!(
"Wake {} for coordinator action {}.",
selected.display_name,
coordinator_action.unwrap_or("pending work")
),
);
"Heartbeat slots control opportunity, not project authority.".to_string(),
"Cooldown starts only after the heartbeat turn completes, so an unfinished sub-agent thread cannot be heartbeaten again.".to_string(),
],
};
}
let sleep_multiplier = state
.pacing_policy
@ -722,22 +845,28 @@ fn action_for_selection(
.max(minimum_rate);
let heartbeat_rate = (target_heartbeat_rate * sleep_multiplier).max(minimum_rate);
let action_id = format!("heartbeat.{}.ruminate", selected.role_id);
(
HeartbeatAction {
action_id,
"wait",
state.pacing_policy.idle_base_recovery / heartbeat_rate,
1.0,
0.9,
format!(
action_type: "ruminate_memory",
action_scale: "short",
base_recovery: state.pacing_policy.idle_base_recovery / heartbeat_rate,
initiative_cost: 1.0,
interruptibility: 0.9,
commitment: 0.25,
local_affordance_basis: vec![
format!(
"{} has no actionable lane work; ruminate and distill role memory.",
selected.display_name
),
)
"Heartbeat slots control opportunity, not project authority.".to_string(),
"When no coordinator work is active, idle rumination uses the sleep heartbeat multiplier so the swarm dreams slowly instead of thrashing.".to_string(),
],
}
}
fn work_role_for_action(action: Option<&str>, target_role: Option<&str>) -> Option<String> {
if let Some(target_role) = target_role
&& ROLE_ORDER.contains(&target_role)
&& (ROLE_ORDER.contains(&target_role) || target_role.starts_with("ghostlight.character."))
{
return Some(target_role.to_string());
}
@ -761,14 +890,16 @@ fn work_role_for_action(action: Option<&str>, target_role: Option<&str>) -> Opti
}
fn patch_missing_participants(state: &mut EpiphanyHeartbeatStateEntry) {
let present: Vec<String> = state
.participants
.iter()
.map(|item| item.role_id.clone())
.collect();
for role_id in ROLE_ORDER {
if !present.iter().any(|present| present == role_id) {
state.participants.push(default_participant(role_id));
if !is_ghostlight_scene_state(state) {
let present: Vec<String> = state
.participants
.iter()
.map(|item| item.role_id.clone())
.collect();
for role_id in ROLE_ORDER {
if !present.iter().any(|present| present == role_id) {
state.participants.push(default_participant(role_id));
}
}
}
for participant in &mut state.participants {
@ -788,11 +919,23 @@ fn patch_missing_participants(state: &mut EpiphanyHeartbeatStateEntry) {
}
}
fn is_ghostlight_scene_state(state: &EpiphanyHeartbeatStateEntry) -> bool {
state
.extra
.get("protocol")
.and_then(Value::as_object)
.and_then(|protocol| protocol.get("domain"))
.and_then(Value::as_str)
== 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),
@ -811,6 +954,52 @@ fn default_participant(role_id: &str) -> HeartbeatParticipant {
}
}
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
@ -841,6 +1030,8 @@ fn readiness_snapshot(
eligible.then_some(round6(item.reaction_bias * urgency - item.current_load));
serde_json::json!({
"agent_id": item.agent_id,
"arena": participant_arena(item),
"participant_kind": participant_kind(item),
"next_ready_at": item.next_ready_at,
"reaction_readiness": reaction_readiness,
"eligible_for_reaction": eligible,
@ -849,6 +1040,31 @@ fn readiness_snapshot(
.collect()
}
fn participant_arena(participant: &HeartbeatParticipant) -> &str {
if participant.arena.trim().is_empty() {
HEARTBEAT_ARENA_MAINTENANCE
} else {
participant.arena.as_str()
}
}
fn participant_kind(participant: &HeartbeatParticipant) -> &str {
if participant.participant_kind.trim().is_empty() {
PARTICIPANT_KIND_AGENT
} else {
participant.participant_kind.as_str()
}
}
fn agent_id_for_work_role(state: &EpiphanyHeartbeatStateEntry, role_id: &str) -> String {
state
.participants
.iter()
.find(|participant| participant.role_id == role_id)
.map(|participant| participant.agent_id.clone())
.unwrap_or_else(|| agent_id_for_role(role_id).to_string())
}
fn trim_history(state: &mut EpiphanyHeartbeatStateEntry) {
let len = state.history.len();
if len > 128 {
@ -957,6 +1173,8 @@ fn participant_status_json(participant: &HeartbeatParticipant) -> Value {
"agentId": participant.agent_id,
"roleId": participant.role_id,
"displayName": participant.display_name,
"arena": participant_arena(participant),
"participantKind": participant_kind(participant),
"initiativeSpeed": participant.initiative_speed,
"nextReadyAt": participant.next_ready_at,
"reactionBias": participant.reaction_bias,
@ -973,7 +1191,10 @@ fn participant_status_json(participant: &HeartbeatParticipant) -> Value {
fn schedule_participant_json(participant: &HeartbeatParticipant) -> Value {
serde_json::json!({
"agent_id": participant.agent_id,
"role_id": participant.role_id,
"display_name": participant.display_name,
"arena": participant_arena(participant),
"participant_kind": participant_kind(participant),
"initiative_speed": participant.initiative_speed,
"next_ready_at": participant.next_ready_at,
"reaction_bias": participant.reaction_bias,
@ -1000,6 +1221,8 @@ fn pending_turn_json(turn: &HeartbeatPendingTurn) -> Value {
"scheduleId": turn.schedule_id,
"actionId": turn.action_id,
"actionType": turn.action_type,
"actionScale": turn.action_scale,
"localAffordanceBasis": turn.local_affordance_basis,
"startedAt": turn.started_at,
"startedSceneClock": turn.started_scene_clock,
"baseRecovery": turn.base_recovery,
@ -1019,6 +1242,9 @@ fn history_event_json(event: HeartbeatHistoryEvent) -> Value {
"selectedAgentId": event.selected_agent_id,
"actionId": event.action_id,
"actionType": event.action_type,
"arena": event.arena,
"participantKind": event.participant_kind,
"actionScale": event.action_scale,
"coordinatorAction": event.coordinator_action,
"targetRole": event.target_role,
"workRole": event.work_role,
@ -1221,4 +1447,58 @@ mod tests {
assert!(artifact_dir.join("native-work.completion.json").exists());
Ok(())
}
#[test]
fn ghostlight_scene_heartbeat_selects_character_turns() -> Result<()> {
let temp = tempfile::tempdir()?;
let store_path = temp.path().join("ghostlight-heartbeats.msgpack");
let artifact_dir = temp.path().join("artifacts");
initialize_ghostlight_scene_heartbeat_store(
&store_path,
1.0,
"pallas-training-loop-v0",
vec![
GhostlightSceneParticipantSeed {
agent_id: "nara-7".to_string(),
display_name: "Nara-7".to_string(),
initiative_speed: 1.1,
reaction_bias: 0.6,
interrupt_threshold: 0.35,
constraints: vec!["Receives only projected local context.".to_string()],
},
GhostlightSceneParticipantSeed {
agent_id: "orrin-dax".to_string(),
display_name: "Orrin Dax".to_string(),
initiative_speed: 0.9,
reaction_bias: 0.55,
interrupt_threshold: 0.4,
constraints: vec!["Acts from current scene pressure.".to_string()],
},
],
)?;
let tick = tick_heartbeat_store(
&store_path,
&artifact_dir,
HeartbeatTickOptions {
target_heartbeat_rate: 1.0,
coordinator_action: None,
target_role: None,
urgency: 0.75,
schedule_id: "pallas.turn-001".to_string(),
source_scene_ref: "ghostlight/pallas-training-loop-v0".to_string(),
defer_completion: true,
},
)?;
assert_eq!(tick["event"]["arena"], "scene");
assert_eq!(tick["event"]["participantKind"], "character");
assert_eq!(tick["event"]["actionType"], "scene_turn");
assert_eq!(
tick["schedule"]["action_catalog"][0]["action_type"],
"scene_turn"
);
assert_eq!(tick["schedule"]["participants"][0]["arena"], "scene");
Ok(())
}
}

View file

@ -28,6 +28,7 @@ pub use distillation::EpiphanyDistillInput;
pub use distillation::EpiphanyDistillProposal;
pub use distillation::distill_observation;
pub use heartbeat_state::EpiphanyHeartbeatStateEntry;
pub use heartbeat_state::GhostlightSceneParticipantSeed;
pub use heartbeat_state::HEARTBEAT_STATE_KEY;
pub use heartbeat_state::HEARTBEAT_STATE_SCHEMA_VERSION;
pub use heartbeat_state::HEARTBEAT_STATE_TYPE;
@ -40,8 +41,10 @@ pub use heartbeat_state::HeartbeatSelectionPolicy;
pub use heartbeat_state::HeartbeatTickOptions;
pub use heartbeat_state::complete_heartbeat_store;
pub use heartbeat_state::default_heartbeat_state;
pub use heartbeat_state::ghostlight_scene_heartbeat_state;
pub use heartbeat_state::heartbeat_state_cache;
pub use heartbeat_state::heartbeat_status_projection;
pub use heartbeat_state::initialize_ghostlight_scene_heartbeat_store;
pub use heartbeat_state::initialize_heartbeat_store;
pub use heartbeat_state::load_heartbeat_state_entry;
pub use heartbeat_state::tick_heartbeat_store;

View file

@ -43,7 +43,8 @@ remembers doctrine; the branch remembers the blade.
- 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. 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 native now. Each lane has a Ghostlight-shaped typed dossier in `state/agents.msgpack`, 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 the native `epiphany-agent-memory-store` binary; project truth still belongs only in `EpiphanyThreadState`.
- 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 speed, next-ready time, reaction bias, interrupt threshold, load, status, constraints, history, and pending turns through `epiphany-core::EpiphanyHeartbeatStateEntry` and the native `epiphany-heartbeat-store` binary. Tick/status/complete and idle rumination selfPatch application now run through Rust/CultCache directly. 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 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, history, and pending turns through `epiphany-core::EpiphanyHeartbeatStateEntry` and the native `epiphany-heartbeat-store` binary. Tick/status/complete and idle rumination selfPatch application now run through Rust/CultCache directly. 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 outward Ghostlight absorption slice is landed in Epiphany. `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 Ghostlight scene stores.
- 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.
- The heartbeat/Face operator API pass is landed. Native `epiphany-heartbeat-store status` returns machine-readable initiative state plus CultCache store presence, native `epiphany-face-discord bubble` writes Discord-independent `epiphany.face_bubble.v0` artifacts, and native `epiphany-mvp-status` includes `heartbeat` and `face` blocks. Aquarium should call native/backend surfaces rather than resurrecting deleted Python action shims.
- The native runtime-spine pass is landed as a first vertebra, not a full daemon. `state/runtime-spine.msgpack` is the default store, `.epiphany-dogfood/runtime-spine-job/runtime.msgpack` and `hello.cultnet` are the latest job/result smoke artifacts, and specialist launch/result flows now route through typed heartbeat/runtime-spine documents.
@ -135,7 +136,7 @@ The current spine, blessed but not yet finished:
- 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 the native `epiphany-heartbeat-store` binary, 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`
- Ghostlight-derived heartbeat initiative scheduling through the native `epiphany-heartbeat-store` binary, with Self and Face included as first-class Epiphany maintenance participants, Ghostlight scene characters supported through the same timing law, idle rumination routed through normal `selfPatch` review/application, and heartbeat state persisted through typed CultCache MessagePack stores
- 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 in `state/agents.msgpack`, plus `selfPatch` review projection through `roleResult`/`roleAccept` and accepted memory application through the native `epiphany-agent-memory-store` binary
- first Unity runtime bridge through native `epiphany-unity-bridge`, native `epiphany-unity-bridge-smoke`, GUI Inspect Unity, runtime artifact listing, and implementation prompt guardrails

Binary file not shown.

View file

@ -131,7 +131,7 @@ 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 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/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 arena, participant kind, 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 participant wins the slot. If the winner has no routeable maintenance 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. Ghostlight scene stores use the same typed CultCache MessagePack contract with `arena=scene` and `participantKind=character`, so scene characters take turns through the same timing law without inheriting Epiphany's maintenance organs.
- `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`.
@ -191,7 +191,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, native `epiphany-rider-bridge` 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 in typed CultCache `state/agents.msgpack`, 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 the native `epiphany-agent-memory-store` binary.
- Phase 6 Face public-surface slice: Face's typed role dossier, Face prompt text, `state/face-discord.toml`, and the native `epiphany-face-discord` binary establish Face as the public #aquarium-only translator of Epiphany agent thought-weather, without VoidBot's moderation authority.
- Phase 6 heartbeat initiative slice: `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, the native `epiphany-heartbeat-store` 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 live state surface now ticks/completes/applies rumination through typed CultCache MessagePack instead of JSON or Python wrapper state.
- Phase 6 heartbeat initiative slice: `state/agent-heartbeats.msgpack`, `epiphany-core::EpiphanyHeartbeatStateEntry`, the native `epiphany-heartbeat-store` 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 live state surface now ticks/completes/applies rumination through typed CultCache MessagePack instead of JSON or Python wrapper state. The same store can now initialize a `ghostlight-scene` profile for character scene turns.
- Native runtime spine slice: `epiphany-core::EpiphanyRuntimeIdentity`, `EpiphanyRuntimeSession`, `EpiphanyRuntimeJob`, `EpiphanyRuntimeJobResult`, and `EpiphanyRuntimeEvent` plus the native `epiphany-runtime-spine` binary establish a CultCache-backed spine, native job/result lifecycle, status projection, and framed CultNet hello output so the old Codex app-server runtime can be starved down to a temporary evacuation bridge instead of remaining the throne.
guardrails:
- Use focused Rust app-server mapper/handler tests plus matching native `epiphany-core` smoke binaries before modifying update, distill, propose, promote, read-projection, or notification behavior. The old Python smoke shims have been cut.