Type heartbeat candidate interventions

This commit is contained in:
Meta Vens 2026-05-19 12:17:41 +01:00
commit 3c0f0f43b6
7 changed files with 98 additions and 59 deletions

View file

@ -126,7 +126,7 @@ pub fn run_void_routine_store(
"incubation": incubation,
"thoughtLanes": thought_lanes,
"bridge": bridge,
"candidateInterventions": candidate_interventions,
"candidateInterventions": &candidate_interventions,
"appraisals": &appraisals,
"reactions": &reactions,
"reviewNotes": [
@ -1451,7 +1451,7 @@ fn build_memory_resonance(records: &[RoleMemoryRecord]) -> HeartbeatMemoryResona
fn build_incubation(
previous: &Option<Value>,
bridge: &Option<Value>,
candidate_interventions: &Option<Value>,
candidate_interventions: &Option<HeartbeatCandidateInterventions>,
resonance: &HeartbeatMemoryResonance,
records: &[RoleMemoryRecord],
) -> Value {
@ -1915,7 +1915,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)
@ -1932,27 +1935,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_id),
decision: decision.to_string(),
requires_face: true,
requires_review: true,
novelty_to_room: theme
.get("noveltyToRoom")
.and_then(Value::as_f64)
.unwrap_or(0.0),
saturation_score: theme
.get("saturationScore")
.and_then(Value::as_f64)
.unwrap_or(0.0),
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(
@ -2467,29 +2480,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

@ -69,7 +69,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)]
@ -334,6 +334,31 @@ pub struct HeartbeatAgentReaction {
pub recommended_use: String,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
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")]
#[serde(default)]
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, PartialEq, Serialize, Deserialize)]
pub struct HeartbeatInitiativeHeatPolicy {
#[serde(default = "default_heat_schema_version")]

View file

@ -130,7 +130,7 @@ fn legacy_heartbeat_cognition_entry(
incubation: legacy.incubation,
thought_lanes: legacy.thought_lanes,
bridge: legacy.bridge,
candidate_interventions: legacy.candidate_interventions,
candidate_interventions: decode_legacy_document(legacy.candidate_interventions)?,
appraisals: decode_legacy_document(legacy.appraisals)?,
reactions: decode_legacy_document(legacy.reactions)?,
}))

View file

@ -1,5 +1,9 @@
use crate::heartbeat_state::EpiphanyHeartbeatCognitionEntry;
#[cfg(test)]
use crate::heartbeat_state::HeartbeatCandidateIntervention;
#[cfg(test)]
use crate::heartbeat_state::HeartbeatCandidateInterventions;
#[cfg(test)]
use crate::heartbeat_state::HeartbeatMemoryResonance;
#[cfg(test)]
use crate::heartbeat_state::HeartbeatMemoryResonancePair;
@ -166,24 +170,21 @@ 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) {
let intervention_id = item.intervention_id.clone();
nodes.push(EpiphanyMemoryNode {
id: memory_graph_node_id(&domain_id, "candidate", &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(),
@ -191,7 +192,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()
});
@ -423,14 +424,21 @@ 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(),
decision: "draft".to_string(),
requires_face: true,
requires_review: true,
novelty_to_room: 0.7,
saturation_score: 0.1,
created_at: "2026-05-18T00:00:00Z".to_string(),
}],
}),
appraisals: None,
reactions: None,
};