2026-05-20 01:39:27 +01:00
use epiphany_core ::EpiphanyReorientFindingInterpretation as CoreEpiphanyReorientFinding ;
use epiphany_core ::EpiphanyRoleFindingInterpretation as CoreEpiphanyRoleFinding ;
2026-05-20 02:44:47 +01:00
use epiphany_core ::EpiphanyRoleResultRoleId ;
2026-05-13 03:37:32 +01:00
use epiphany_core ::EpiphanyRoleStatePatchDocument ;
2026-05-14 08:57:31 +01:00
use epiphany_core ::EpiphanyStateUpdate ;
2026-05-20 02:37:10 +01:00
use epiphany_core ::EpiphanyStateUpdatedField ;
2026-05-19 15:24:57 +01:00
use epiphany_state_model ::EpiphanyInvestigationCheckpoint ;
2026-05-13 03:37:32 +01:00
2026-07-11 19:15:27 +01:00
pub type RoleAcceptanceUpdate = epiphany_core ::EpiphanyRoleAcceptanceUpdate ;
pub type ReorientAcceptanceUpdate = epiphany_core ::EpiphanyReorientAcceptanceUpdate ;
2026-05-13 03:49:57 +01:00
2026-05-13 03:46:48 +01:00
pub fn build_role_acceptance_update (
2026-05-20 02:08:53 +01:00
expected_revision : Option < u64 > ,
2026-05-20 02:44:47 +01:00
role_id : EpiphanyRoleResultRoleId ,
2026-05-13 03:46:48 +01:00
binding_id : & str ,
2026-05-20 01:39:27 +01:00
finding : & CoreEpiphanyRoleFinding ,
2026-05-13 03:46:48 +01:00
accepted_evidence_id : String ,
accepted_observation_id : String ,
accepted_at : String ,
) -> Result < RoleAcceptanceUpdate , String > {
2026-07-11 19:15:27 +01:00
epiphany_core ::build_native_role_acceptance_update (
expected_revision ,
role_id ,
2026-05-13 03:46:48 +01:00
binding_id ,
2026-07-11 19:15:27 +01:00
finding ,
2026-05-13 03:46:48 +01:00
accepted_evidence_id ,
accepted_observation_id ,
accepted_at ,
2026-07-11 19:15:27 +01:00
)
2026-05-13 03:46:48 +01:00
}
pub fn build_reorient_acceptance_update (
2026-05-13 03:54:50 +01:00
expected_revision : Option < u64 > ,
2026-05-13 03:46:48 +01:00
binding_id : & str ,
2026-05-20 01:39:27 +01:00
finding : & CoreEpiphanyReorientFinding ,
2026-05-13 03:46:48 +01:00
accepted_evidence_id : String ,
accepted_observation_id : String ,
accepted_at : String ,
update_scratch : bool ,
update_investigation_checkpoint : bool ,
checkpoint : Option < EpiphanyInvestigationCheckpoint > ,
) -> Result < ReorientAcceptanceUpdate , String > {
2026-07-11 19:15:27 +01:00
epiphany_core ::build_native_reorient_acceptance_update (
expected_revision ,
2026-05-13 03:46:48 +01:00
binding_id ,
2026-07-11 19:15:27 +01:00
finding ,
2026-05-13 03:46:48 +01:00
accepted_evidence_id ,
accepted_observation_id ,
accepted_at ,
update_scratch ,
2026-07-11 19:15:27 +01:00
update_investigation_checkpoint ,
checkpoint ,
)
}
2026-05-13 03:46:48 +01:00
2026-07-11 19:15:27 +01:00
pub fn state_update_from_core_patch (
expected_revision : Option < u64 > ,
patch : EpiphanyRoleStatePatchDocument ,
) -> EpiphanyStateUpdate {
EpiphanyStateUpdate {
expected_revision ,
objective : patch . objective ,
active_subgoal_id : patch . active_subgoal_id ,
subgoals : patch . subgoals ,
invariants : patch . invariants ,
graphs : patch . graphs ,
graph_frontier : patch . graph_frontier ,
graph_checkpoint : patch . graph_checkpoint ,
scratch : patch . scratch ,
investigation_checkpoint : patch . investigation_checkpoint ,
job_bindings : patch . job_bindings ,
acceptance_receipts : patch . acceptance_receipts ,
runtime_links : patch . runtime_links ,
observations : patch . observations ,
evidence : patch . evidence ,
churn : patch . churn ,
mode : patch . mode ,
planning : patch . planning ,
2026-05-13 03:46:48 +01:00
}
}
2026-05-20 02:37:10 +01:00
pub fn epiphany_job_launch_changed_fields ( ) -> Vec < EpiphanyStateUpdatedField > {
2026-05-13 03:37:32 +01:00
vec! [
2026-05-20 02:37:10 +01:00
EpiphanyStateUpdatedField ::JobBindings ,
EpiphanyStateUpdatedField ::RuntimeLinks ,
2026-05-13 03:37:32 +01:00
]
}
2026-05-20 02:28:52 +01:00
pub fn thread_epiphany_patch_has_state_replacements (
patch : & EpiphanyRoleStatePatchDocument ,
) -> bool {
2026-05-13 03:37:32 +01:00
patch . objective . is_some ( )
| | patch . active_subgoal_id . is_some ( )
| | patch . subgoals . is_some ( )
| | patch . invariants . is_some ( )
| | patch . graphs . is_some ( )
| | patch . graph_frontier . is_some ( )
| | patch . graph_checkpoint . is_some ( )
| | patch . scratch . is_some ( )
| | patch . investigation_checkpoint . is_some ( )
| | patch . job_bindings . is_some ( )
| | ! patch . acceptance_receipts . is_empty ( )
| | ! patch . runtime_links . is_empty ( )
| | patch . churn . is_some ( )
| | patch . mode . is_some ( )
| | patch . planning . is_some ( )
}
pub fn epiphany_update_patch_changed_fields (
2026-05-20 08:03:27 +01:00
patch : & EpiphanyRoleStatePatchDocument ,
2026-05-20 02:37:10 +01:00
) -> Vec < EpiphanyStateUpdatedField > {
2026-07-11 19:15:27 +01:00
let update = state_update_from_core_patch ( None , patch . clone ( ) ) ;
2026-05-13 03:37:32 +01:00
let mut fields = Vec ::new ( ) ;
2026-07-11 19:15:27 +01:00
if update . objective . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Objective ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . active_subgoal_id . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::ActiveSubgoalId ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . subgoals . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Subgoals ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . invariants . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Invariants ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . graphs . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Graphs ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . graph_frontier . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::GraphFrontier ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . graph_checkpoint . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::GraphCheckpoint ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . scratch . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Scratch ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . investigation_checkpoint . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::InvestigationCheckpoint ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . job_bindings . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::JobBindings ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if ! update . acceptance_receipts . is_empty ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::AcceptanceReceipts ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if ! update . runtime_links . is_empty ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::RuntimeLinks ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if ! update . observations . is_empty ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Observations ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if ! update . evidence . is_empty ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Evidence ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . churn . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Churn ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . mode . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Mode ) ;
2026-05-13 03:37:32 +01:00
}
2026-07-11 19:15:27 +01:00
if update . planning . is_some ( ) {
2026-05-20 02:37:10 +01:00
fields . push ( EpiphanyStateUpdatedField ::Planning ) ;
2026-05-13 03:37:32 +01:00
}
fields
}
pub fn epiphany_promote_changed_fields (
2026-05-20 02:28:52 +01:00
patch : & EpiphanyRoleStatePatchDocument ,
2026-05-20 02:37:10 +01:00
) -> Vec < EpiphanyStateUpdatedField > {
2026-05-20 08:03:27 +01:00
let mut fields = epiphany_update_patch_changed_fields ( patch ) ;
2026-05-20 02:37:10 +01:00
if ! fields . contains ( & EpiphanyStateUpdatedField ::Evidence ) {
fields . push ( EpiphanyStateUpdatedField ::Evidence ) ;
2026-05-13 03:37:32 +01:00
}
fields
}