Type heartbeat candidate interventions

This commit is contained in:
Meta Vens 2026-05-18 07:57:11 +01:00
commit dbbc5f11d3
8 changed files with 91 additions and 52 deletions

View file

@ -1359,7 +1359,7 @@ fn build_memory_resonance(records: &[RoleMemoryRecord]) -> Value {
fn build_incubation(
previous: &Option<Value>,
bridge: &Option<Value>,
candidate_interventions: &Option<Value>,
candidate_interventions: &Option<HeartbeatCandidateInterventions>,
resonance: &Value,
records: &[RoleMemoryRecord],
) -> Value {
@ -1846,7 +1846,10 @@ fn build_thought_bridge(
})
}
fn build_candidate_interventions(bridge: &Value, incubation: &Value) -> Value {
fn build_candidate_interventions(
bridge: &Value,
incubation: &Value,
) -> HeartbeatCandidateInterventions {
let decision = bridge
.pointer("/decision/speakDecision")
.and_then(Value::as_str)
@ -1863,27 +1866,37 @@ fn build_candidate_interventions(bridge: &Value, incubation: &Value) -> Value {
let items = if decision == "draft" && strongest_status == "ripe" {
strongest_theme
.map(|theme| {
vec![serde_json::json!({
"interventionId": format!("candidate-{}", theme.get("themeId").and_then(Value::as_str).unwrap_or("theme")),
"summary": "Possible Aquarium-facing thought-weather note",
"draft": format!("I keep seeing {} rhyme across the swarm; this one finally has enough blood to inspect in the open.", theme.get("themeId").and_then(Value::as_str).unwrap_or("an unnamed seam")),
"decision": decision,
"requiresFace": true,
"requiresReview": true,
"noveltyToRoom": theme.get("noveltyToRoom").cloned().unwrap_or(Value::Null),
"saturationScore": theme.get("saturationScore").cloned().unwrap_or(Value::Null),
"createdAt": now_iso(),
})]
let theme_id = theme
.get("themeId")
.and_then(Value::as_str)
.unwrap_or("theme");
vec![HeartbeatCandidateIntervention {
intervention_id: format!("candidate-{theme_id}"),
summary: "Possible Aquarium-facing thought-weather note".to_string(),
draft: format!("I keep seeing {} rhyme across the swarm; this one finally has enough blood to inspect in the open.", theme.get("themeId").and_then(Value::as_str).unwrap_or("an unnamed seam")),
decision: decision.to_string(),
requires_face: true,
requires_review: true,
novelty_to_room: theme
.get("noveltyToRoom")
.and_then(Value::as_f64)
.unwrap_or_default(),
saturation_score: theme
.get("saturationScore")
.and_then(Value::as_f64)
.unwrap_or_default(),
created_at: now_iso(),
}]
})
.unwrap_or_default()
} else {
Vec::new()
};
serde_json::json!({
"schema_version": "epiphany.candidate_interventions.v0",
"updatedAt": now_iso(),
"items": items,
})
HeartbeatCandidateInterventions {
schema_version: "epiphany.candidate_interventions.v0".to_string(),
updated_at: now_iso(),
items,
}
}
fn build_agent_appraisals(
@ -2398,29 +2411,21 @@ fn novelty_to_self(
fn novelty_to_room(
theme_id: &str,
summary: &str,
previous_candidate_interventions: &Option<Value>,
previous_candidate_interventions: &Option<HeartbeatCandidateInterventions>,
bridge: &Option<Value>,
) -> f64 {
let mut score = 0.64_f64;
for intervention in previous_candidate_interventions
.as_ref()
.and_then(|value| value.get("items"))
.and_then(Value::as_array)
.into_iter()
.flatten()
.flat_map(|value| value.items.iter())
.take(8)
{
let similarity = theme_similarity(
theme_id,
summary,
intervention
.get("interventionId")
.and_then(Value::as_str)
.unwrap_or(""),
intervention
.get("draft")
.and_then(Value::as_str)
.unwrap_or(""),
&intervention.intervention_id,
&intervention.draft,
);
if similarity >= 0.42 {
return 0.22;

View file

@ -67,7 +67,7 @@ pub struct EpiphanyHeartbeatCognitionEntry {
#[cultcache(key = 9, default)]
pub bridge: Option<Value>,
#[cultcache(key = 10, default)]
pub candidate_interventions: Option<Value>,
pub candidate_interventions: Option<HeartbeatCandidateInterventions>,
#[cultcache(key = 11, default)]
pub appraisals: Option<HeartbeatAgentThoughtAppraisals>,
#[cultcache(key = 12, default)]
@ -126,6 +126,29 @@ pub struct HeartbeatAgentThoughtAppraisals {
pub participant_appraisals: Vec<HeartbeatAgentThoughtAppraisal>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HeartbeatCandidateInterventions {
#[serde(rename = "schema_version")]
pub schema_version: String,
pub updated_at: String,
pub items: Vec<HeartbeatCandidateIntervention>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HeartbeatCandidateIntervention {
pub intervention_id: String,
pub summary: String,
pub draft: String,
pub decision: String,
pub requires_face: bool,
pub requires_review: bool,
pub novelty_to_room: f64,
pub saturation_score: f64,
pub created_at: String,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HeartbeatAgentThoughtAppraisal {

View file

@ -83,7 +83,7 @@ pub fn heartbeat_status_projection(
"incubation": cognition.as_ref().and_then(|entry| entry.incubation.clone()),
"thoughtLanes": cognition.as_ref().and_then(|entry| entry.thought_lanes.clone()),
"bridge": cognition.as_ref().and_then(|entry| entry.bridge.clone()),
"candidateInterventions": cognition.as_ref().and_then(|entry| entry.candidate_interventions.clone()),
"candidateInterventions": cognition.as_ref().and_then(|entry| entry.candidate_interventions.as_ref()).and_then(typed_json),
"appraisals": cognition.as_ref().and_then(|entry| entry.appraisals.as_ref()).and_then(typed_json),
"reactions": cognition.as_ref().and_then(|entry| entry.reactions.as_ref()).and_then(typed_json),
"adaptivePacing": adaptive_pacing,

View file

@ -59,7 +59,8 @@ pub fn load_heartbeat_cognition_entry(
) -> Result<Option<EpiphanyHeartbeatCognitionEntry>> {
let store_path = store_path.as_ref();
let cache = heartbeat_state_cache(store_path)?;
if let Some(cognition) = cache.get::<EpiphanyHeartbeatCognitionEntry>(HEARTBEAT_COGNITION_KEY)?
if let Some(cognition) =
cache.get::<EpiphanyHeartbeatCognitionEntry>(HEARTBEAT_COGNITION_KEY)?
{
return Ok(Some(cognition));
}
@ -131,7 +132,9 @@ fn legacy_heartbeat_cognition_entry(
incubation: legacy.incubation,
thought_lanes: legacy.thought_lanes,
bridge: legacy.bridge,
candidate_interventions: legacy.candidate_interventions,
candidate_interventions: legacy
.candidate_interventions
.and_then(|value| serde_json::from_value(value).ok()),
appraisals: legacy
.appraisals
.and_then(|value| serde_json::from_value(value).ok()),
@ -237,7 +240,10 @@ mod tests {
let loaded_cognition = load_heartbeat_cognition_entry(&store_path)?
.expect("heartbeat cognition should round-trip through CultCache");
assert_eq!(loaded_cognition.schema_version, HEARTBEAT_COGNITION_SCHEMA_VERSION);
assert_eq!(
loaded_cognition.schema_version,
HEARTBEAT_COGNITION_SCHEMA_VERSION
);
assert_eq!(loaded_cognition.latest_run_id.as_deref(), Some("run-1"));
Ok(())
}

View file

@ -170,24 +170,20 @@ fn import_candidate_interventions(
let Some(candidates) = cognition.candidate_interventions.as_ref() else {
return;
};
let Some(items) = candidates.get("items").and_then(Value::as_array) else {
return;
};
let domain_id = push_domain(
domains,
EpiphanyMemoryProfile::CandidateIntervention,
"heartbeat candidate interventions",
);
let before = nodes.len();
for item in items.iter().take(8) {
let intervention_id = string_at(item, "interventionId");
for item in candidates.items.iter().take(8) {
nodes.push(EpiphanyMemoryNode {
id: memory_graph_node_id(&domain_id, "candidate", &intervention_id, None),
id: memory_graph_node_id(&domain_id, "candidate", &item.intervention_id, None),
domain_id: domain_id.clone(),
profile: EpiphanyMemoryProfile::CandidateIntervention,
kind: EpiphanyMemoryNodeKind::CandidateIntervention,
title: string_at(item, "summary"),
claim: string_at(item, "draft"),
title: item.summary.clone(),
claim: item.draft.clone(),
question: "Should this candidate intervention be spoken, deferred, or retired?"
.to_string(),
tension: "Candidate speech is not authority and still requires review.".to_string(),
@ -195,7 +191,7 @@ fn import_candidate_interventions(
.to_string(),
source_hashes: vec!["anchor:missing".to_string()],
lifecycle: EpiphanyMemoryLifecycle::Queued,
salience: score_to_u32(number_at(item, "noveltyToRoom")),
salience: score_to_u32(item.novelty_to_room),
confidence: 55,
..Default::default()
});
@ -372,6 +368,8 @@ fn incubation_lifecycle(status: &str) -> EpiphanyMemoryLifecycle {
mod tests {
use super::*;
use crate::heartbeat_state::HEARTBEAT_COGNITION_SCHEMA_VERSION;
use crate::heartbeat_state::HeartbeatCandidateIntervention;
use crate::heartbeat_state::HeartbeatCandidateInterventions;
use crate::memory_graph::validate_memory_graph_snapshot;
#[test]
@ -416,14 +414,17 @@ mod tests {
"reason": "The thought is live but not ready for speech."
}
})),
candidate_interventions: Some(serde_json::json!({
"items": [{
"interventionId": "candidate-theme-body-soul",
"summary": "Possible note",
"draft": "Evidence boundaries are lighting up.",
"noveltyToRoom": 0.7
}]
})),
candidate_interventions: Some(HeartbeatCandidateInterventions {
schema_version: "epiphany.candidate_interventions.v0".to_string(),
updated_at: "2026-05-18T00:00:00Z".to_string(),
items: vec![HeartbeatCandidateIntervention {
intervention_id: "candidate-theme-body-soul".to_string(),
summary: "Possible note".to_string(),
draft: "Evidence boundaries are lighting up.".to_string(),
novelty_to_room: 0.7,
..Default::default()
}],
}),
appraisals: None,
reactions: None,
extra: Default::default(),

View file

@ -68,6 +68,7 @@ remembers doctrine; the branch remembers the blade.
- Heartbeat adaptive pacing now lives as typed CultCache state on `EpiphanyHeartbeatStateEntry` instead of being written into `state.extra["adaptivePacing"]` as JSON. Status projection still emits JSON and reads the old extra pocket as a legacy fallback.
- Heartbeat participant scene id, personality timing, mood timing, and pending-turn cooldown multipliers now live as typed fields instead of durable `participant.extra` / `pendingTurn.extra` JSON pockets. Scheduler pacing and status projection read the typed fields first and keep legacy extra fallbacks only as sealed compatibility scars.
- Heartbeat cognition appraisals and reactions now live as typed CultCache fields instead of `Option<Value>` blobs. The mood-timing scheduler consumes typed appraisals directly; legacy cognition migration parses old appraisal/reaction JSON only when loading prior stores.
- Heartbeat cognition candidate interventions now live as typed review-gated speech candidates instead of `Option<Value>` item lists. The memory graph heartbeat profile reads typed candidate items directly; legacy cognition migration parses old candidate JSON only when loading prior stores.
- 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.
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
- Heartbeat adaptive pacing now lives in `epiphany-core/src/heartbeat_state/heartbeat_pacing.rs`, including running-turn count and effective cooldown multipliers. It has a module-local unit test for pending-turn counting; root scheduling calls the pacing seam instead of owning pressure/concurrency math directly.

Binary file not shown.

View file

@ -53,6 +53,9 @@ objective:
Heartbeat cognition appraisals and reactions are typed CultCache fields;
legacy cognition blobs are parsed only while migrating old stores, and
status/artifact JSON is projection output.
Heartbeat cognition candidate interventions are typed review-gated speech
candidates; Face/Aquarium pressure no longer reads that surface as an
arbitrary JSON item list except when migrating legacy stores.
constraints:
- No frontier-scale training tithe.