Enforce Eyes packets for research acceptance

This commit is contained in:
Meta Vens 2026-05-30 01:43:01 +01:00
commit ca3b99f267
8 changed files with 299 additions and 16 deletions

View file

@ -1,3 +1,6 @@
use crate::EpiphanyRoleFindingInterpretation;
use crate::EpiphanyRoleStatePatchDocument;
use cultcache_rs::DatabaseEntry;
use serde::Deserialize;
use serde::Serialize;
@ -14,6 +17,35 @@ pub const EYES_EVIDENCE_PACKET_SCHEMA_VERSION: &str = "epiphany.eyes.evidence_pa
pub const EYES_EVIDENCE_REFUSAL_RECEIPT_SCHEMA_VERSION: &str =
"epiphany.eyes.evidence_refusal_receipt.v0";
#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)]
#[cultcache(type = "epiphany.eyes.evidence_packet", schema = "EyesEvidencePacket")]
pub struct EyesEvidencePacket {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub packet_id: String,
#[cultcache(key = 2)]
pub source_result_id: String,
#[cultcache(key = 3)]
pub source_job_id: String,
#[cultcache(key = 4)]
pub source_role_id: String,
#[cultcache(key = 5)]
pub evidence_ids: Vec<String>,
#[cultcache(key = 6)]
pub observation_ids: Vec<String>,
#[cultcache(key = 7)]
pub source_refs: Vec<String>,
#[cultcache(key = 8)]
pub summary: String,
#[cultcache(key = 9)]
pub uncertainty: String,
#[cultcache(key = 10)]
pub emitted_at: String,
#[cultcache(key = 11)]
pub contract: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EyesCultNetContract {
@ -95,6 +127,80 @@ pub fn default_eyes_cultnet_contracts() -> Vec<EyesCultNetContract> {
]
}
pub fn eyes_evidence_packet_from_research_finding(
packet_id: String,
finding: &EpiphanyRoleFindingInterpretation,
patch: &EpiphanyRoleStatePatchDocument,
emitted_at: String,
) -> EyesEvidencePacket {
let evidence_ids = patch
.evidence
.iter()
.filter_map(|evidence| non_empty_string(&evidence.id))
.collect::<Vec<_>>();
let observation_ids = patch
.observations
.iter()
.filter_map(|observation| non_empty_string(&observation.id))
.collect::<Vec<_>>();
let mut source_refs = Vec::new();
for evidence in &patch.evidence {
for code_ref in &evidence.code_refs {
let mut rendered = code_ref.path.display().to_string();
if let Some(start_line) = code_ref.start_line {
rendered.push(':');
rendered.push_str(&start_line.to_string());
}
if let Some(end_line) = code_ref.end_line
&& Some(end_line) != code_ref.start_line
{
rendered.push('-');
rendered.push_str(&end_line.to_string());
}
if let Some(symbol) = code_ref.symbol.as_deref().filter(|value| !value.is_empty()) {
rendered.push('#');
rendered.push_str(symbol);
}
push_unique(&mut source_refs, rendered);
}
}
EyesEvidencePacket {
schema_version: EYES_EVIDENCE_PACKET_SCHEMA_VERSION.to_string(),
packet_id,
source_result_id: finding.runtime_result_id.clone().unwrap_or_default(),
source_job_id: finding.runtime_job_id.clone().unwrap_or_default(),
source_role_id: "research".to_string(),
evidence_ids,
observation_ids,
source_refs,
summary: finding.summary.clone().unwrap_or_default(),
uncertainty: if finding.evidence_gaps.is_empty() && finding.risks.is_empty() {
"no declared research gaps or risks".to_string()
} else {
finding
.evidence_gaps
.iter()
.chain(finding.risks.iter())
.cloned()
.collect::<Vec<_>>()
.join("; ")
},
emitted_at,
contract: "Eyes packet emitted from a reviewed Research lane finding; it makes the source-gathering evidence claim citable before Mind admission.".to_string(),
}
}
fn non_empty_string(value: &str) -> Option<String> {
let value = value.trim();
(!value.is_empty()).then(|| value.to_string())
}
fn push_unique(out: &mut Vec<String>, value: String) {
if !out.contains(&value) {
out.push(value);
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -121,4 +227,71 @@ mod tests {
.contains(&EYES_EVIDENCE_PACKET_TYPE.to_string())
);
}
#[test]
fn research_finding_builds_evidence_packet() {
let finding = EpiphanyRoleFindingInterpretation {
verdict: Some("evidence-ready".to_string()),
summary: Some("Found source proof.".to_string()),
next_safe_move: Some("Review evidence.".to_string()),
checkpoint_summary: None,
scratch_summary: None,
files_inspected: vec!["src/lib.rs".to_string()],
frontier_node_ids: Vec::new(),
evidence_ids: vec!["ev-source".to_string()],
artifact_refs: Vec::new(),
runtime_result_id: Some("result-1".to_string()),
runtime_job_id: Some("job-1".to_string()),
open_questions: Vec::new(),
evidence_gaps: Vec::new(),
risks: Vec::new(),
state_patch: None,
self_patch: None,
self_persistence: None,
job_error: None,
item_error: None,
};
let mut patch = EpiphanyRoleStatePatchDocument::default();
patch
.evidence
.push(epiphany_state_model::EpiphanyEvidenceRecord {
id: "ev-source".to_string(),
kind: "source".to_string(),
status: "ok".to_string(),
summary: "Source proof.".to_string(),
code_refs: vec![epiphany_state_model::EpiphanyCodeRef {
path: "src/lib.rs".into(),
start_line: Some(12),
end_line: None,
symbol: Some("thing".to_string()),
note: None,
}],
});
patch
.observations
.push(epiphany_state_model::EpiphanyObservation {
id: "obs-source".to_string(),
summary: "Observed source proof.".to_string(),
source_kind: "research".to_string(),
status: "ok".to_string(),
code_refs: Vec::new(),
evidence_ids: vec!["ev-source".to_string()],
});
let packet = eyes_evidence_packet_from_research_finding(
"eyes-packet-1".to_string(),
&finding,
&patch,
"2026-05-30T00:00:00Z".to_string(),
);
assert_eq!(packet.source_role_id, "research");
assert!(packet.evidence_ids.contains(&"ev-source".to_string()));
assert!(packet.observation_ids.contains(&"obs-source".to_string()));
assert!(
packet
.source_refs
.iter()
.any(|item| item.contains("src/lib.rs"))
);
}
}

View file

@ -210,7 +210,9 @@ pub use eyes_gateway::EYES_EVIDENCE_REVIEW_TYPE;
pub use eyes_gateway::EYES_SOURCE_LOOKUP_RECEIPT_SCHEMA_VERSION;
pub use eyes_gateway::EYES_SOURCE_LOOKUP_RECEIPT_TYPE;
pub use eyes_gateway::EyesCultNetContract;
pub use eyes_gateway::EyesEvidencePacket;
pub use eyes_gateway::default_eyes_cultnet_contracts;
pub use eyes_gateway::eyes_evidence_packet_from_research_finding;
pub use face_turn::FACE_INTERPRETER_PROMPT_SCHEMA_VERSION;
pub use face_turn::FACE_PROJECTOR_PROMPT_SCHEMA_VERSION;
pub use face_turn::FACE_TURN_PROMPT_SCHEMA_VERSION;
@ -415,11 +417,13 @@ pub use runtime_spine::initialize_runtime_spine;
pub use runtime_spine::open_runtime_spine_heartbeat_job;
pub use runtime_spine::plan_runtime_spine_heartbeat_launch;
pub use runtime_spine::put_coordinator_run_receipt;
pub use runtime_spine::put_eyes_evidence_packet;
pub use runtime_spine::put_mind_gateway_review;
pub use runtime_spine::put_mind_state_commit_receipt;
pub use runtime_spine::put_runtime_reorient_worker_result;
pub use runtime_spine::put_runtime_role_worker_result;
pub use runtime_spine::replace_or_append_epiphany_job_binding;
pub use runtime_spine::runtime_eyes_evidence_packet;
pub use runtime_spine::runtime_hello_frame;
pub use runtime_spine::runtime_job_snapshot;
pub use runtime_spine::runtime_mind_gateway_review;

View file

@ -19,6 +19,7 @@ use crate::eyes_gateway::EYES_EVIDENCE_REVIEW_SCHEMA_VERSION;
use crate::eyes_gateway::EYES_EVIDENCE_REVIEW_TYPE;
use crate::eyes_gateway::EYES_SOURCE_LOOKUP_RECEIPT_SCHEMA_VERSION;
use crate::eyes_gateway::EYES_SOURCE_LOOKUP_RECEIPT_TYPE;
use crate::eyes_gateway::EyesEvidencePacket;
use crate::hands_gateway::*;
use crate::heartbeat_state::HEARTBEAT_STATE_SCHEMA_VERSION;
use crate::heartbeat_state::HEARTBEAT_STATE_TYPE;
@ -711,6 +712,7 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
cache.register_entry_type::<EpiphanyCoordinatorRunReceipt>()?;
cache.register_entry_type::<MindGatewayReview>()?;
cache.register_entry_type::<MindStateCommitReceipt>()?;
cache.register_entry_type::<EyesEvidencePacket>()?;
cache.register_entry_type::<EpiphanyOpenAiAdapterStatus>()?;
cache.register_entry_type::<EpiphanyOpenAiModelRequest>()?;
cache.register_entry_type::<EpiphanyOpenAiStreamEvent>()?;
@ -1172,6 +1174,38 @@ pub fn runtime_mind_state_commit_receipt(
cache.get::<MindStateCommitReceipt>(receipt_id)
}
pub fn put_eyes_evidence_packet(
store_path: impl AsRef<Path>,
packet: &EyesEvidencePacket,
) -> Result<()> {
validate_non_empty(&packet.packet_id, "Eyes evidence packet id")?;
validate_non_empty(
&packet.source_result_id,
"Eyes evidence packet source result",
)?;
validate_non_empty(&packet.source_job_id, "Eyes evidence packet source job")?;
validate_non_empty(&packet.source_role_id, "Eyes evidence packet source role")?;
validate_non_empty(&packet.emitted_at, "Eyes evidence packet timestamp")?;
if packet.evidence_ids.is_empty() {
return Err(anyhow!("Eyes evidence packet must reference evidence ids"));
}
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
cache.put(&packet.packet_id, packet)?;
Ok(())
}
pub fn runtime_eyes_evidence_packet(
store_path: impl AsRef<Path>,
packet_id: &str,
) -> Result<Option<EyesEvidencePacket>> {
validate_non_empty(packet_id, "Eyes evidence packet id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
cache.get::<EyesEvidencePacket>(packet_id)
}
pub fn put_coordinator_run_receipt(
store_path: impl AsRef<Path>,
receipt: &EpiphanyCoordinatorRunReceipt,
@ -3120,6 +3154,21 @@ mod tests {
"2026-05-06T00:04:00Z".to_string(),
);
put_mind_state_commit_receipt(&store, &commit)?;
let eyes_packet = EyesEvidencePacket {
schema_version: crate::EYES_EVIDENCE_PACKET_SCHEMA_VERSION.to_string(),
packet_id: "eyes-packet-1".to_string(),
source_result_id: "result-1".to_string(),
source_job_id: "job-1".to_string(),
source_role_id: "research".to_string(),
evidence_ids: vec!["ev-1".to_string()],
observation_ids: vec!["obs-1".to_string()],
source_refs: vec!["src/lib.rs:1".to_string()],
summary: "Evidence packet.".to_string(),
uncertainty: "none declared".to_string(),
emitted_at: "2026-05-06T00:05:00Z".to_string(),
contract: "Eyes packet persists as runtime-spine proof.".to_string(),
};
put_eyes_evidence_packet(&store, &eyes_packet)?;
let stored = runtime_mind_gateway_review(&store, "mind-role-modeling-job-1")?
.expect("Mind review receipt should persist");
@ -3127,6 +3176,9 @@ mod tests {
let stored_commit = runtime_mind_state_commit_receipt(&store, "mind-commit-1")?
.expect("Mind state commit receipt should persist");
assert_eq!(stored_commit, commit);
let stored_packet = runtime_eyes_evidence_packet(&store, "eyes-packet-1")?
.expect("Eyes evidence packet should persist");
assert_eq!(stored_packet, eyes_packet);
Ok(())
}