2026-05-13 00:53:56 +01:00
use epiphany_core ::EpiphanyFreshnessInput ;
use epiphany_core ::EpiphanyFreshnessView ;
use epiphany_core ::EpiphanyFreshnessWatcherInput ;
use epiphany_core ::EpiphanyGraphFreshness as CoreEpiphanyGraphFreshness ;
use epiphany_core ::EpiphanyGraphFreshnessStatus as CoreEpiphanyGraphFreshnessStatus ;
use epiphany_core ::EpiphanyInvalidationInput as CoreEpiphanyInvalidationInput ;
use epiphany_core ::EpiphanyInvalidationStatus as CoreEpiphanyInvalidationStatus ;
2026-05-19 16:47:28 +01:00
use epiphany_core ::EpiphanyPressure ;
use epiphany_core ::EpiphanyPressureLevel ;
2026-05-19 17:05:26 +01:00
use epiphany_core ::EpiphanyReorientDecision as CoreEpiphanyReorientDecision ;
2026-05-13 00:53:56 +01:00
use epiphany_core ::EpiphanyReorientFreshnessStatus as CoreEpiphanyReorientFreshnessStatus ;
use epiphany_core ::EpiphanyReorientInput ;
use epiphany_core ::EpiphanyReorientPressureLevel as CoreEpiphanyReorientPressureLevel ;
use epiphany_core ::EpiphanyReorientStateStatus as CoreEpiphanyReorientStateStatus ;
use epiphany_core ::EpiphanyRetrievalFreshness as CoreEpiphanyRetrievalFreshness ;
use epiphany_core ::EpiphanyRetrievalFreshnessStatus as CoreEpiphanyRetrievalFreshnessStatus ;
use epiphany_core ::derive_freshness ;
use epiphany_core ::recommend_reorientation ;
2026-05-19 15:24:57 +01:00
use epiphany_state_model ::EpiphanyRetrievalState ;
use epiphany_state_model ::EpiphanyThreadState ;
2026-05-13 03:07:24 +01:00
use std ::path ::Path ;
use std ::path ::PathBuf ;
2026-05-13 00:53:56 +01:00
2026-05-13 03:07:24 +01:00
pub struct EpiphanyFreshnessWatcherSnapshot < ' a > {
pub available : bool ,
pub workspace_root : Option < & ' a Path > ,
pub observed_at_unix_seconds : Option < i64 > ,
pub changed_paths : & ' a [ PathBuf ] ,
}
2026-05-13 00:53:56 +01:00
2026-05-19 16:35:58 +01:00
pub fn derive_epiphany_freshness_view (
state : Option < & EpiphanyThreadState > ,
retrieval_override : Option < & EpiphanyRetrievalState > ,
watcher_snapshot : Option < EpiphanyFreshnessWatcherSnapshot < '_ > > ,
) -> EpiphanyFreshnessView {
2026-05-13 00:53:56 +01:00
let watcher = watcher_snapshot . map ( | snapshot | EpiphanyFreshnessWatcherInput {
available : snapshot . available ,
2026-05-13 03:07:24 +01:00
workspace_root : snapshot . workspace_root ,
2026-05-13 00:53:56 +01:00
observed_at_unix_seconds : snapshot . observed_at_unix_seconds ,
2026-05-13 03:07:24 +01:00
changed_paths : snapshot . changed_paths ,
2026-05-13 00:53:56 +01:00
} ) ;
2026-05-19 16:35:58 +01:00
derive_freshness ( EpiphanyFreshnessInput {
2026-05-13 00:53:56 +01:00
state ,
retrieval_override ,
watcher ,
2026-05-19 16:35:58 +01:00
} )
2026-05-13 00:53:56 +01:00
}
2026-05-19 17:05:26 +01:00
pub fn derive_epiphany_reorient (
state : Option < & EpiphanyThreadState > ,
pressure : & EpiphanyPressure ,
retrieval : & CoreEpiphanyRetrievalFreshness ,
graph : & CoreEpiphanyGraphFreshness ,
watcher : & CoreEpiphanyInvalidationInput ,
) -> (
CoreEpiphanyReorientStateStatus ,
CoreEpiphanyReorientDecision ,
) {
recommend_reorientation ( EpiphanyReorientInput {
2026-05-13 00:53:56 +01:00
checkpoint : state . and_then ( | state | state . investigation_checkpoint . as_ref ( ) ) ,
state_present : state . is_some ( ) ,
pressure_level : map_core_reorient_pressure_level ( pressure . level ) ,
retrieval_status : map_core_reorient_retrieval_status ( retrieval . status ) ,
retrieval_dirty_paths : retrieval . dirty_paths . clone ( ) ,
graph_status : map_core_reorient_graph_status ( graph . status ) ,
graph_dirty_paths : graph . dirty_paths . clone ( ) ,
watcher_status : map_core_reorient_watcher_status ( watcher . status ) ,
watcher_changed_paths : watcher . changed_paths . clone ( ) ,
watcher_graph_node_ids : watcher . graph_node_ids . clone ( ) ,
active_frontier_node_ids : watcher . active_frontier_node_ids . clone ( ) ,
watched_root : watcher . watched_root . clone ( ) ,
2026-05-19 17:05:26 +01:00
} )
2026-05-13 00:53:56 +01:00
}
fn map_core_reorient_pressure_level (
2026-05-19 16:47:28 +01:00
level : EpiphanyPressureLevel ,
2026-05-13 00:53:56 +01:00
) -> CoreEpiphanyReorientPressureLevel {
match level {
2026-05-19 16:47:28 +01:00
EpiphanyPressureLevel ::Unknown = > CoreEpiphanyReorientPressureLevel ::Unknown ,
EpiphanyPressureLevel ::Low = > CoreEpiphanyReorientPressureLevel ::Low ,
EpiphanyPressureLevel ::Elevated = > CoreEpiphanyReorientPressureLevel ::Medium ,
EpiphanyPressureLevel ::High = > CoreEpiphanyReorientPressureLevel ::High ,
EpiphanyPressureLevel ::Critical = > CoreEpiphanyReorientPressureLevel ::Critical ,
2026-05-13 00:53:56 +01:00
}
}
fn map_core_reorient_retrieval_status (
2026-05-19 16:58:37 +01:00
status : CoreEpiphanyRetrievalFreshnessStatus ,
2026-05-13 00:53:56 +01:00
) -> CoreEpiphanyReorientFreshnessStatus {
match status {
2026-05-19 16:58:37 +01:00
CoreEpiphanyRetrievalFreshnessStatus ::Missing
| CoreEpiphanyRetrievalFreshnessStatus ::Unavailable = > {
2026-05-13 00:53:56 +01:00
CoreEpiphanyReorientFreshnessStatus ::Unknown
}
2026-05-19 16:58:37 +01:00
CoreEpiphanyRetrievalFreshnessStatus ::Ready = > CoreEpiphanyReorientFreshnessStatus ::Clean ,
CoreEpiphanyRetrievalFreshnessStatus ::Stale = > CoreEpiphanyReorientFreshnessStatus ::Stale ,
CoreEpiphanyRetrievalFreshnessStatus ::Indexing = > {
2026-05-13 00:53:56 +01:00
CoreEpiphanyReorientFreshnessStatus ::Dirty
}
}
}
fn map_core_reorient_graph_status (
2026-05-19 16:58:37 +01:00
status : CoreEpiphanyGraphFreshnessStatus ,
2026-05-13 00:53:56 +01:00
) -> CoreEpiphanyReorientFreshnessStatus {
match status {
2026-05-19 16:58:37 +01:00
CoreEpiphanyGraphFreshnessStatus ::Missing = > CoreEpiphanyReorientFreshnessStatus ::Unknown ,
CoreEpiphanyGraphFreshnessStatus ::Ready = > CoreEpiphanyReorientFreshnessStatus ::Clean ,
CoreEpiphanyGraphFreshnessStatus ::Stale = > CoreEpiphanyReorientFreshnessStatus ::Stale ,
2026-05-13 00:53:56 +01:00
}
}
fn map_core_reorient_watcher_status (
2026-05-19 16:58:37 +01:00
status : CoreEpiphanyInvalidationStatus ,
2026-05-13 00:53:56 +01:00
) -> CoreEpiphanyReorientFreshnessStatus {
match status {
2026-05-19 22:11:58 +01:00
CoreEpiphanyInvalidationStatus ::Unavailable = > CoreEpiphanyReorientFreshnessStatus ::Unknown ,
2026-05-19 16:58:37 +01:00
CoreEpiphanyInvalidationStatus ::Clean = > CoreEpiphanyReorientFreshnessStatus ::Clean ,
CoreEpiphanyInvalidationStatus ::Changed = > CoreEpiphanyReorientFreshnessStatus ::Changed ,
2026-05-13 00:53:56 +01:00
}
}