From 4ed1cef56f74294773a312fd916f3b19cb123b42 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 12 May 2026 21:04:16 +0100 Subject: [PATCH] Extract Epiphany reorientation policy into core --- epiphany-core/src/lib.rs | 9 + epiphany-core/src/surfaces/mod.rs | 10 + epiphany-core/src/surfaces/reorient.rs | 430 ++++++++++++++++++ notes/epiphany-current-algorithmic-map.md | 2 +- notes/fresh-workspace-handoff.md | 4 +- state/ledgers.msgpack | Bin 64600 -> 64920 bytes state/map.yaml | 6 +- .../app-server/src/codex_message_processor.rs | 423 +++++++++-------- 8 files changed, 666 insertions(+), 218 deletions(-) create mode 100644 epiphany-core/src/surfaces/reorient.rs diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 7c5fa41e..df7da2c3 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -156,6 +156,14 @@ pub use surfaces::EpiphanyPressureLevel; pub use surfaces::EpiphanyPressureStatus; pub use surfaces::EpiphanyReorientAcceptanceBundle; pub use surfaces::EpiphanyReorientAcceptanceFinding; +pub use surfaces::EpiphanyReorientAction; +pub use surfaces::EpiphanyReorientCheckpointStatus; +pub use surfaces::EpiphanyReorientDecision; +pub use surfaces::EpiphanyReorientFreshnessStatus; +pub use surfaces::EpiphanyReorientInput; +pub use surfaces::EpiphanyReorientPressureLevel; +pub use surfaces::EpiphanyReorientReason; +pub use surfaces::EpiphanyReorientStateStatus; pub use surfaces::EpiphanyRoleAcceptanceFinding; pub use surfaces::EpiphanyRoleBoardCheckpointSummary; pub use surfaces::EpiphanyRoleBoardInput; @@ -181,6 +189,7 @@ pub use surfaces::interpret_role_finding; pub use surfaces::modeling_role_state_patch_policy_errors; pub use surfaces::recommend_coordinator_action; pub use surfaces::recommend_crrc_action; +pub use surfaces::recommend_reorientation; pub use surfaces::render_role_board_note; pub use surfaces::reorientation_role_status; pub use surfaces::review_role_self_patch; diff --git a/epiphany-core/src/surfaces/mod.rs b/epiphany-core/src/surfaces/mod.rs index e6c8cf91..44d08380 100644 --- a/epiphany-core/src/surfaces/mod.rs +++ b/epiphany-core/src/surfaces/mod.rs @@ -1,6 +1,7 @@ mod coordinator; mod crrc; mod pressure; +mod reorient; mod role_board; mod role_result; @@ -32,6 +33,15 @@ pub use pressure::EpiphanyPressureBasis; pub use pressure::EpiphanyPressureLevel; pub use pressure::EpiphanyPressureStatus; pub use pressure::derive_pressure_view; +pub use reorient::EpiphanyReorientAction; +pub use reorient::EpiphanyReorientCheckpointStatus; +pub use reorient::EpiphanyReorientDecision; +pub use reorient::EpiphanyReorientFreshnessStatus; +pub use reorient::EpiphanyReorientInput; +pub use reorient::EpiphanyReorientPressureLevel; +pub use reorient::EpiphanyReorientReason; +pub use reorient::EpiphanyReorientStateStatus; +pub use reorient::recommend_reorientation; pub use role_board::EpiphanyRoleBoardCheckpointSummary; pub use role_board::EpiphanyRoleBoardInput; pub use role_board::EpiphanyRoleBoardJob; diff --git a/epiphany-core/src/surfaces/reorient.rs b/epiphany-core/src/surfaces/reorient.rs new file mode 100644 index 00000000..59a33761 --- /dev/null +++ b/epiphany-core/src/surfaces/reorient.rs @@ -0,0 +1,430 @@ +use codex_protocol::protocol::EpiphanyInvestigationCheckpoint; +use codex_protocol::protocol::EpiphanyInvestigationDisposition; +use std::collections::HashSet; +use std::path::Path; +use std::path::PathBuf; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientAction { + Resume, + Regather, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientStateStatus { + Missing, + Ready, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientCheckpointStatus { + Missing, + ResumeReady, + RegatherRequired, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientReason { + MissingState, + MissingCheckpoint, + CheckpointReady, + CheckpointRequestedRegather, + CheckpointPathsDirty, + CheckpointPathsChanged, + FrontierChanged, + UnanchoredCheckpointWhileStateStale, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientPressureLevel { + Unknown, + Low, + Medium, + High, + Critical, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EpiphanyReorientFreshnessStatus { + Unknown, + Clean, + Dirty, + Stale, + Changed, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EpiphanyReorientInput<'a> { + pub checkpoint: Option<&'a EpiphanyInvestigationCheckpoint>, + pub state_present: bool, + pub pressure_level: EpiphanyReorientPressureLevel, + pub retrieval_status: EpiphanyReorientFreshnessStatus, + pub retrieval_dirty_paths: Vec, + pub graph_status: EpiphanyReorientFreshnessStatus, + pub graph_dirty_paths: Vec, + pub watcher_status: EpiphanyReorientFreshnessStatus, + pub watcher_changed_paths: Vec, + pub watcher_graph_node_ids: Vec, + pub active_frontier_node_ids: Vec, + pub watched_root: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EpiphanyReorientDecision { + pub action: EpiphanyReorientAction, + pub checkpoint_status: EpiphanyReorientCheckpointStatus, + pub checkpoint_id: Option, + pub pressure_level: EpiphanyReorientPressureLevel, + pub retrieval_status: EpiphanyReorientFreshnessStatus, + pub graph_status: EpiphanyReorientFreshnessStatus, + pub watcher_status: EpiphanyReorientFreshnessStatus, + pub reasons: Vec, + pub checkpoint_dirty_paths: Vec, + pub checkpoint_changed_paths: Vec, + pub active_frontier_node_ids: Vec, + pub next_action: String, + pub note: String, +} + +pub fn recommend_reorientation( + input: EpiphanyReorientInput<'_>, +) -> (EpiphanyReorientStateStatus, EpiphanyReorientDecision) { + let build_decision = |action: EpiphanyReorientAction, + checkpoint_status: EpiphanyReorientCheckpointStatus, + checkpoint_id: Option, + reasons: Vec, + checkpoint_dirty_paths: Vec, + checkpoint_changed_paths: Vec, + active_frontier_node_ids: Vec, + next_action: String, + note: String| EpiphanyReorientDecision { + action, + checkpoint_status, + checkpoint_id, + pressure_level: input.pressure_level, + retrieval_status: input.retrieval_status, + graph_status: input.graph_status, + watcher_status: input.watcher_status, + reasons, + checkpoint_dirty_paths, + checkpoint_changed_paths, + active_frontier_node_ids, + next_action, + note, + }; + + let high_pressure = matches!( + input.pressure_level, + EpiphanyReorientPressureLevel::High | EpiphanyReorientPressureLevel::Critical + ); + + if !input.state_present { + let note = if high_pressure { + "No Epiphany state survived, and the last recorded context pressure was high; re-gather before editing." + .to_string() + } else { + "No Epiphany state survived, so there is no authoritative checkpoint to resume." + .to_string() + }; + return ( + EpiphanyReorientStateStatus::Missing, + build_decision( + EpiphanyReorientAction::Regather, + EpiphanyReorientCheckpointStatus::Missing, + None, + vec![ + EpiphanyReorientReason::MissingState, + EpiphanyReorientReason::MissingCheckpoint, + ], + Vec::new(), + Vec::new(), + Vec::new(), + "Re-gather source context before editing.".to_string(), + note, + ), + ); + } + + let Some(checkpoint) = input.checkpoint else { + let note = if high_pressure { + "Epiphany state survived, but no durable investigation checkpoint was banked before high context pressure; re-gather before editing." + .to_string() + } else { + "Epiphany state survived, but there is no durable investigation checkpoint to resume from." + .to_string() + }; + return ( + EpiphanyReorientStateStatus::Ready, + build_decision( + EpiphanyReorientAction::Regather, + EpiphanyReorientCheckpointStatus::Missing, + None, + vec![EpiphanyReorientReason::MissingCheckpoint], + Vec::new(), + Vec::new(), + Vec::new(), + "Re-gather source context before editing.".to_string(), + note, + ), + ); + }; + + let checkpoint_status = match checkpoint.disposition { + EpiphanyInvestigationDisposition::ResumeReady => { + EpiphanyReorientCheckpointStatus::ResumeReady + } + EpiphanyInvestigationDisposition::RegatherRequired => { + EpiphanyReorientCheckpointStatus::RegatherRequired + } + }; + let workspace_root = input.watched_root.as_deref(); + let checkpoint_dirty_paths = overlapping_checkpoint_paths( + checkpoint, + input + .retrieval_dirty_paths + .iter() + .chain(input.graph_dirty_paths.iter()), + workspace_root, + ); + let checkpoint_changed_paths = overlapping_checkpoint_paths( + checkpoint, + input.watcher_changed_paths.iter(), + workspace_root, + ); + let frontier_changed = !input.active_frontier_node_ids.is_empty(); + let unanchored_checkpoint_while_state_stale = checkpoint.code_refs.is_empty() + && (!input.retrieval_dirty_paths.is_empty() + || !input.graph_dirty_paths.is_empty() + || !input.watcher_graph_node_ids.is_empty() + || frontier_changed); + + let mut reasons = Vec::new(); + if checkpoint.disposition == EpiphanyInvestigationDisposition::RegatherRequired { + reasons.push(EpiphanyReorientReason::CheckpointRequestedRegather); + } + if !checkpoint_dirty_paths.is_empty() { + reasons.push(EpiphanyReorientReason::CheckpointPathsDirty); + } + if !checkpoint_changed_paths.is_empty() { + reasons.push(EpiphanyReorientReason::CheckpointPathsChanged); + } + if frontier_changed { + reasons.push(EpiphanyReorientReason::FrontierChanged); + } + if unanchored_checkpoint_while_state_stale { + reasons.push(EpiphanyReorientReason::UnanchoredCheckpointWhileStateStale); + } + + let should_regather = checkpoint.disposition + == EpiphanyInvestigationDisposition::RegatherRequired + || !checkpoint_dirty_paths.is_empty() + || !checkpoint_changed_paths.is_empty() + || frontier_changed + || unanchored_checkpoint_while_state_stale; + + if !should_regather { + reasons.push(EpiphanyReorientReason::CheckpointReady); + return ( + EpiphanyReorientStateStatus::Ready, + build_decision( + EpiphanyReorientAction::Resume, + checkpoint_status, + Some(checkpoint.checkpoint_id.clone()), + reasons, + Vec::new(), + Vec::new(), + Vec::new(), + checkpoint.next_action.clone().unwrap_or_else(|| { + "Resume from the durable checkpoint focus and verify the seam before broad edits." + .to_string() + }), + "Resume-ready checkpoint remains aligned with current freshness and watcher signals." + .to_string(), + ), + ); + } + + let mut note_fragments = Vec::new(); + if checkpoint.disposition == EpiphanyInvestigationDisposition::RegatherRequired { + note_fragments.push("the checkpoint explicitly requests re-gather".to_string()); + } + if !checkpoint_dirty_paths.is_empty() { + note_fragments.push(format!( + "{} checkpoint path(s) are already marked dirty", + checkpoint_dirty_paths.len() + )); + } + if !checkpoint_changed_paths.is_empty() { + note_fragments.push(format!( + "watcher observed {} changed checkpoint path(s)", + checkpoint_changed_paths.len() + )); + } + if frontier_changed { + note_fragments.push(format!( + "watcher hit {} active frontier node(s)", + input.active_frontier_node_ids.len() + )); + } + if unanchored_checkpoint_while_state_stale { + note_fragments.push( + "the checkpoint has no code refs while freshness signals already show drift" + .to_string(), + ); + } + + ( + EpiphanyReorientStateStatus::Ready, + build_decision( + EpiphanyReorientAction::Regather, + checkpoint_status, + Some(checkpoint.checkpoint_id.clone()), + reasons, + checkpoint_dirty_paths, + checkpoint_changed_paths, + input.active_frontier_node_ids, + checkpoint + .next_action + .clone() + .unwrap_or_else(|| "Re-gather source context before editing.".to_string()), + format!("Re-gather before editing: {}.", note_fragments.join("; ")), + ), + ) +} + +fn overlapping_checkpoint_paths<'a>( + checkpoint: &EpiphanyInvestigationCheckpoint, + candidate_paths: impl IntoIterator, + workspace_root: Option<&Path>, +) -> Vec { + let checkpoint_path_keys: HashSet = checkpoint + .code_refs + .iter() + .map(|code_ref| code_ref_path_key(code_ref.path.as_path(), workspace_root)) + .collect(); + if checkpoint_path_keys.is_empty() { + return Vec::new(); + } + + let mut overlaps = Vec::new(); + let mut seen = HashSet::new(); + for path in candidate_paths { + let path_key = code_ref_path_key(path.as_path(), workspace_root); + if checkpoint_path_keys.contains(&path_key) && seen.insert(path_key) { + overlaps.push(path.clone()); + } + } + overlaps +} + +fn code_ref_path_key(path: &Path, workspace_root: Option<&Path>) -> String { + if let Some(workspace_root) = workspace_root + && let Ok(relative_path) = path.strip_prefix(workspace_root) + { + return epiphany_path_key(relative_path); + } + epiphany_path_key(path) +} + +fn epiphany_path_key(path: &Path) -> String { + path.to_string_lossy() + .replace('\\', "/") + .trim_start_matches("./") + .to_string() +} + +#[cfg(test)] +mod tests { + use super::*; + use codex_protocol::protocol::EpiphanyCodeRef; + + fn checkpoint() -> EpiphanyInvestigationCheckpoint { + EpiphanyInvestigationCheckpoint { + checkpoint_id: "ix-1".to_string(), + kind: "implementation".to_string(), + disposition: EpiphanyInvestigationDisposition::ResumeReady, + focus: "runtime seam".to_string(), + summary: Some("resume here".to_string()), + next_action: Some("Continue from the seam.".to_string()), + captured_at_turn_id: Some("turn-1".to_string()), + open_questions: Vec::new(), + code_refs: vec![EpiphanyCodeRef { + path: PathBuf::from("src/lib.rs"), + start_line: None, + end_line: None, + symbol: None, + note: None, + }], + evidence_ids: vec!["ev-1".to_string()], + } + } + + fn input(checkpoint: Option<&EpiphanyInvestigationCheckpoint>) -> EpiphanyReorientInput<'_> { + EpiphanyReorientInput { + checkpoint, + state_present: true, + pressure_level: EpiphanyReorientPressureLevel::Low, + retrieval_status: EpiphanyReorientFreshnessStatus::Clean, + retrieval_dirty_paths: Vec::new(), + graph_status: EpiphanyReorientFreshnessStatus::Clean, + graph_dirty_paths: Vec::new(), + watcher_status: EpiphanyReorientFreshnessStatus::Clean, + watcher_changed_paths: Vec::new(), + watcher_graph_node_ids: Vec::new(), + active_frontier_node_ids: Vec::new(), + watched_root: None, + } + } + + #[test] + fn resumes_when_checkpoint_is_clean() { + let checkpoint = checkpoint(); + let (state_status, decision) = recommend_reorientation(input(Some(&checkpoint))); + + assert_eq!(state_status, EpiphanyReorientStateStatus::Ready); + assert_eq!(decision.action, EpiphanyReorientAction::Resume); + assert_eq!(decision.checkpoint_id.as_deref(), Some("ix-1")); + assert_eq!( + decision.reasons, + vec![EpiphanyReorientReason::CheckpointReady] + ); + } + + #[test] + fn regathers_when_checkpoint_path_changes() { + let checkpoint = checkpoint(); + let mut input = input(Some(&checkpoint)); + input.watcher_status = EpiphanyReorientFreshnessStatus::Changed; + input.watcher_changed_paths = vec![PathBuf::from("./src/lib.rs")]; + + let (_state_status, decision) = recommend_reorientation(input); + + assert_eq!(decision.action, EpiphanyReorientAction::Regather); + assert_eq!( + decision.reasons, + vec![EpiphanyReorientReason::CheckpointPathsChanged] + ); + assert_eq!( + decision.checkpoint_changed_paths, + vec![PathBuf::from("./src/lib.rs")] + ); + } + + #[test] + fn missing_state_regathers() { + let mut input = input(None); + input.state_present = false; + input.pressure_level = EpiphanyReorientPressureLevel::High; + + let (state_status, decision) = recommend_reorientation(input); + + assert_eq!(state_status, EpiphanyReorientStateStatus::Missing); + assert_eq!(decision.action, EpiphanyReorientAction::Regather); + assert!( + decision + .reasons + .contains(&EpiphanyReorientReason::MissingState) + ); + assert!(decision.note.contains("high")); + } +} diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index a33517c7..7dc33815 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -33,7 +33,7 @@ The spine exists in more than twenty-five live paths: - canonical view lens reflection: app-server declares experimental read-only `thread/epiphany/view` with selectable lenses and uses it as the canonical operator read surface for pressure, reorient, CRRC, and coordinator projections. Those projections no longer have standalone protocol verbs; the separate `reorientLaunch`, `reorientResult`, and `reorientAccept` surfaces remain because they carry authority, result read-back, and review acceptance rather than mere reflection. - context-pressure reflection: core token telemetry carries `model_auto_compact_token_limit` beside total/last usage and `model_context_window`; the `pressure` view lens reads live token usage or the latest stored rollout `TokenCount`, derives current context pressure from `last_token_usage` rather than cumulative thread spend, treats cumulative-only telemetry as unknown, and raises `shouldPrepareCompaction` at 80% of the active auto-compact/context limit without mutating Epiphany state or scheduling compaction in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2237), [turn_context.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn_context.rs:103), [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2716), [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:360), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4361), [token_usage_replay.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/token_usage_replay.rs:75), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4306), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11028). - pre-compaction checkpoint intervention: app-server `TokenCount` handling now checks the same pressure mapper, and for loaded Epiphany threads crossing `shouldPrepareCompaction` it steers the active turn once with a bounded CRRC checkpoint directive to bank working context before compaction/reorientation. The per-turn dedupe bit and the pending compact handoff live in listener `ThreadState`; successful steering marks the active turn for a forced compact action at clean turn completion, while aborted turns clear the handoff. The intervention uses existing turn steering and turn-boundary automation rather than a new scheduler in [bespoke_event_handling.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs:1467), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15405), and [thread_state.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/thread_state.rs:144). -- reorientation policy: the `reorient` view lens reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, and derives a bounded `resume`/`regather` verdict with checkpoint-path/frontier reasons without mutating, compacting, scheduling, notifying, or continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4394), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11424). +- reorientation policy: the `reorient` view lens reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, then adapts those inputs into pure `epiphany-core` verdict policy. Core derives the bounded `resume`/`regather` decision with checkpoint-path/frontier reasons; app-server only maps the core decision back to protocol shape, without mutating, compacting, scheduling, notifying, or continuing work in [reorient.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/reorient.rs:1), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15296). - CRRC coordinator recommendation: the `crrc` view lens reuses pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and calls pure `epiphany-core` CRRC policy to return one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4661), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546). - role ownership projection: the `roles` view lens reuses the same state/jobs/pressure/reorient/result/CRRC signals as the coordinator loop, and projects implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation lanes with owner roles, status, linked jobs, authority scopes, and recommended scene actions without launching, scheduling, accepting, compacting, notifying, or mutating state. App-server adapts concrete protocol jobs and thread state, while the pure role-board projection policy now lives in [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70). - role specialist launch/read-back/acceptance: app-server declares experimental `thread/epiphany/roleLaunch`, read-only `thread/epiphany/roleResult`, and write-gated `thread/epiphany/roleAccept`. `roleLaunch` accepts fixed Imagination/planning, modeling/checkpoint, and verification/review role ids, builds bounded specialist payloads from authoritative Epiphany state, routes them through the heartbeat-backed `epiphany_launch_job` seam, opens a typed runtime-spine job receipt, and emits the normal `jobLaunch` state update for `jobBindings` only. `roleResult` resolves heartbeat bindings through typed runtime-spine job results and seals legacy `agent_jobs` bindings, then adapts worker JSON through core role-result interpretation in [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:45), projecting structured output as a reviewable finding with verdict, summary, next safe move, inspected files, frontier/evidence ids, optional `statePatch`, optional `selfPatch`, coordinator `selfPersistence` review, and errors without mutation, promotion, scheduling, or hidden continuation. `selfPatch` is a Ghostlight-shaped lane-memory request, not project truth: core accepts only role-matched, bounded, evidence-grounded memory/goal/value/private-note mutations and refuses objectives, graphs, checkpoints, scratch, planning, jobs, authority, code edits, or raw transcripts with reasons. `roleAccept` accepts completed heartbeat findings from typed runtime-spine results, accepts completed Imagination findings only when they contain a valid planning-only patch with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, applies accepted project patches through the existing Epiphany state validator, and uses core acceptance bundle policy to build the audit observation, evidence, and typed receipt. GUI/coordinator accept paths then apply accepted `selfPatch` requests to typed CultCache role dossiers in `state/agents.msgpack` through the native `epiphany-agent-memory-store` binary. Implementation stays owned by the main coding agent, verification output remains review-only, and reorientation stays on the CRRC-specific `reorientLaunch` / `reorientResult` / `reorientAccept` path. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 2255ad54..5a99c03a 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -32,7 +32,7 @@ remembers doctrine; the branch remembers the blade. ## Current Orientation - Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`. -- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy moved into `epiphany-core`, typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links. +- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy moved into `epiphany-core`, typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links. - Read `notes/epiphany-ideal-architecture-rebuild-plan.md` immediately after the teardown. It defines the smallest coherent replacement architecture: durable `EpiphanyState`, runtime-spine-owned `RuntimeState`, separate role memory/heartbeat state, `epiphany-core` as policy owner, app-server as adapter, Aquarium as reflector, typed acceptance receipts, and derived view lenses instead of a protocol verb zoo. - Do not continue Aquarium UI, bridge, Face, or dogfood expansion until the teardown has a source-grounded cleanup slice plan. Epiphany is the foundation; patches on patches are not a purification rite, they are how the altar becomes load-bearing garbage. - Phase 1 through Phase 5 are complete enough. @@ -369,7 +369,7 @@ Phase 6 bridge/UI trail. Landed rebuild cuts: `epiphany-core/src/surfaces/` exists, pressure view derivation/tests, pure CRRC recommendation policy/tests, fixed-lane coordinator decision policy/tests, role-board projection policy/tests, role-result interpretation/self-persistence review policy/tests, and role/reorient -acceptance bundle policy/tests live in core, live acceptance writes typed receipts keyed by runtime result id, +acceptance bundle policy/tests, and reorientation resume/regather verdict policy/tests live in core, live acceptance writes typed receipts keyed by runtime result id, summary-string acceptance identity is gone for live paths, launches dual-write runtime links, result read-back prefers those runtime links, normal public `raw_result` is sealed, MVP consumers use `thread/epiphany/view`, heartbeat diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index fd181d03f05cad9c4f2552dc8400af4c1125742d..75b2463dca53ea51e668ba448d231b0d010028f6 100644 GIT binary patch delta 283 zcmccdgL%ep<_U^Se-kz;Ph(_UvUwL{$FIp&_j$PtjY5nJtPD)73?>KO*V4WD*Ehc` zHASH)HNPk`HLoPGBr`t`$SW?*P1P?-O;0SzNG(z*OD#&tOfH$s^IdB4j-P^)9lo>I z7XTF%mlmb!rvVumc|eYSd16U2P`N&kNX{bc<7qfKG!u9%MrSkPlX^*RaLNz{pJ3z*HCEXQL!WPQ2?nV B56%Dp diff --git a/state/map.yaml b/state/map.yaml index 720174ee..8021c7ec 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -100,7 +100,7 @@ accepted_design: - `thread/epiphany/retrieve`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/graphQuery`, and `thread/epiphany/view` stay read-only. - `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding; catalog is auspex output, not doctrine. - Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path. - - `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible. + - `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible. - Vendored Codex keeps the thin typed host seam: protocol types, thread bridges, app-server protocol, request routing, and rollout integration. - The current algorithmic map is the source-grounded description of live control flow. - Compact-Rehydrate-Reorient-Continue is an architecture primitive; automatic runtime coordination is not landed yet. @@ -272,5 +272,5 @@ rejected_paths: reason: persistent state that accumulates every local truth becomes memory cruft and weakens rehydration current_status: - summary: Phase 1 durable state through Phase 6 coordinator/specialist/CRRC/backend organs are landed, and the May 2026 rebuild has started cutting the app-server control-plane tumor. Pressure, CRRC, coordinator, role-board, role-result interpretation/self-persistence review, and role/reorient acceptance bundle policy now live in `epiphany-core`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; role/reorient result read-back follows runtime links; and `jobBindings` no longer store launcher/backend/progress lifecycle fields. - next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`. The next pass is to audit the plan's remaining success criteria and cut whatever still makes app-server more than routing/adaptation. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is complete enough to defend. + summary: Phase 1 durable state through Phase 6 coordinator/specialist/CRRC/backend organs are landed, and the May 2026 rebuild has started cutting the app-server control-plane tumor. Pressure, reorientation resume/regather verdicts, CRRC, coordinator, role-board, role-result interpretation/self-persistence review, and role/reorient acceptance bundle policy now live in `epiphany-core`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; role/reorient result read-back follows runtime links; and `jobBindings` no longer store launcher/backend/progress lifecycle fields. + next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, reorientation resume/regather verdict policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`. The next pass is to audit the plan's remaining success criteria and cut whatever still makes app-server more than routing/adaptation. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is complete enough to defend. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs index fb633dad..0d6e5df3 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs @@ -517,6 +517,13 @@ use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis; use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel; use epiphany_core::EpiphanyPressureStatus as CoreEpiphanyPressureStatus; use epiphany_core::EpiphanyReorientAcceptanceFinding; +use epiphany_core::EpiphanyReorientAction as CoreEpiphanyReorientAction; +use epiphany_core::EpiphanyReorientCheckpointStatus as CoreEpiphanyReorientCheckpointStatus; +use epiphany_core::EpiphanyReorientFreshnessStatus as CoreEpiphanyReorientFreshnessStatus; +use epiphany_core::EpiphanyReorientInput; +use epiphany_core::EpiphanyReorientPressureLevel as CoreEpiphanyReorientPressureLevel; +use epiphany_core::EpiphanyReorientReason as CoreEpiphanyReorientReason; +use epiphany_core::EpiphanyReorientStateStatus as CoreEpiphanyReorientStateStatus; use epiphany_core::EpiphanyRoleAcceptanceFinding; use epiphany_core::EpiphanyRoleBoardCheckpointSummary; use epiphany_core::EpiphanyRoleBoardInput; @@ -541,6 +548,7 @@ use epiphany_core::interpret_role_finding; use epiphany_core::modeling_role_state_patch_policy_errors; use epiphany_core::recommend_coordinator_action; use epiphany_core::recommend_crrc_action; +use epiphany_core::recommend_reorientation; use epiphany_core::render_role_board_note; use epiphany_core::runtime_job_snapshot; use epiphany_core::select_coordinator_automation_action; @@ -15288,226 +15296,217 @@ fn map_epiphany_reorient( ThreadEpiphanyReorientStateStatus, ThreadEpiphanyReorientDecision, ) { - let build_decision = |action: ThreadEpiphanyReorientAction, - checkpoint_status: ThreadEpiphanyReorientCheckpointStatus, - checkpoint_id: Option, - reasons: Vec, - checkpoint_dirty_paths: Vec, - checkpoint_changed_paths: Vec, - active_frontier_node_ids: Vec, - next_action: String, - note: String| ThreadEpiphanyReorientDecision { - action, - checkpoint_status, - checkpoint_id, - pressure_level: pressure.level, - retrieval_status: retrieval.status, - graph_status: graph.status, - watcher_status: watcher.status, - reasons, - checkpoint_dirty_paths, - checkpoint_changed_paths, - active_frontier_node_ids, - next_action, - note, - }; - - let high_pressure = matches!( - pressure.level, - ThreadEpiphanyPressureLevel::High | ThreadEpiphanyPressureLevel::Critical - ); - - let Some(state) = state else { - let note = if high_pressure { - "No Epiphany state survived, and the last recorded context pressure was high; re-gather before editing." - .to_string() - } else { - "No Epiphany state survived, so there is no authoritative checkpoint to resume." - .to_string() - }; - return ( - ThreadEpiphanyReorientStateStatus::Missing, - build_decision( - ThreadEpiphanyReorientAction::Regather, - ThreadEpiphanyReorientCheckpointStatus::Missing, - None, - vec![ - ThreadEpiphanyReorientReason::MissingState, - ThreadEpiphanyReorientReason::MissingCheckpoint, - ], - Vec::new(), - Vec::new(), - Vec::new(), - "Re-gather source context before editing.".to_string(), - note, - ), - ); - }; - - let Some(checkpoint) = state.investigation_checkpoint.as_ref() else { - let note = if high_pressure { - "Epiphany state survived, but no durable investigation checkpoint was banked before high context pressure; re-gather before editing." - .to_string() - } else { - "Epiphany state survived, but there is no durable investigation checkpoint to resume from." - .to_string() - }; - return ( - ThreadEpiphanyReorientStateStatus::Ready, - build_decision( - ThreadEpiphanyReorientAction::Regather, - ThreadEpiphanyReorientCheckpointStatus::Missing, - None, - vec![ThreadEpiphanyReorientReason::MissingCheckpoint], - Vec::new(), - Vec::new(), - Vec::new(), - "Re-gather source context before editing.".to_string(), - note, - ), - ); - }; - - let checkpoint_status = match checkpoint.disposition { - EpiphanyInvestigationDisposition::ResumeReady => { - ThreadEpiphanyReorientCheckpointStatus::ResumeReady - } - EpiphanyInvestigationDisposition::RegatherRequired => { - ThreadEpiphanyReorientCheckpointStatus::RegatherRequired - } - }; - let workspace_root = watcher.watched_root.as_deref(); - let checkpoint_dirty_paths = overlapping_checkpoint_paths( - checkpoint, - retrieval.dirty_paths.iter().chain(graph.dirty_paths.iter()), - workspace_root, - ); - let checkpoint_changed_paths = - overlapping_checkpoint_paths(checkpoint, watcher.changed_paths.iter(), workspace_root); - let frontier_changed = !watcher.active_frontier_node_ids.is_empty(); - let unanchored_checkpoint_while_state_stale = checkpoint.code_refs.is_empty() - && (!retrieval.dirty_paths.is_empty() - || !graph.dirty_paths.is_empty() - || !watcher.graph_node_ids.is_empty() - || frontier_changed); - - let mut reasons = Vec::new(); - if checkpoint.disposition == EpiphanyInvestigationDisposition::RegatherRequired { - reasons.push(ThreadEpiphanyReorientReason::CheckpointRequestedRegather); - } - if !checkpoint_dirty_paths.is_empty() { - reasons.push(ThreadEpiphanyReorientReason::CheckpointPathsDirty); - } - if !checkpoint_changed_paths.is_empty() { - reasons.push(ThreadEpiphanyReorientReason::CheckpointPathsChanged); - } - if frontier_changed { - reasons.push(ThreadEpiphanyReorientReason::FrontierChanged); - } - if unanchored_checkpoint_while_state_stale { - reasons.push(ThreadEpiphanyReorientReason::UnanchoredCheckpointWhileStateStale); - } - - let should_regather = checkpoint.disposition - == EpiphanyInvestigationDisposition::RegatherRequired - || !checkpoint_dirty_paths.is_empty() - || !checkpoint_changed_paths.is_empty() - || frontier_changed - || unanchored_checkpoint_while_state_stale; - - if !should_regather { - reasons.push(ThreadEpiphanyReorientReason::CheckpointReady); - return ( - ThreadEpiphanyReorientStateStatus::Ready, - build_decision( - ThreadEpiphanyReorientAction::Resume, - checkpoint_status, - Some(checkpoint.checkpoint_id.clone()), - reasons, - Vec::new(), - Vec::new(), - Vec::new(), - checkpoint.next_action.clone().unwrap_or_else(|| { - "Resume from the durable checkpoint focus and verify the seam before broad edits." - .to_string() - }), - "Resume-ready checkpoint remains aligned with current freshness and watcher signals." - .to_string(), - ), - ); - } - - let mut note_fragments = Vec::new(); - if checkpoint.disposition == EpiphanyInvestigationDisposition::RegatherRequired { - note_fragments.push("the checkpoint explicitly requests re-gather".to_string()); - } - if !checkpoint_dirty_paths.is_empty() { - note_fragments.push(format!( - "{} checkpoint path(s) are already marked dirty", - checkpoint_dirty_paths.len() - )); - } - if !checkpoint_changed_paths.is_empty() { - note_fragments.push(format!( - "watcher observed {} changed checkpoint path(s)", - checkpoint_changed_paths.len() - )); - } - if frontier_changed { - note_fragments.push(format!( - "watcher hit {} active frontier node(s)", - watcher.active_frontier_node_ids.len() - )); - } - if unanchored_checkpoint_while_state_stale { - note_fragments.push( - "the checkpoint has no code refs while freshness signals already show drift" - .to_string(), - ); - } - + let (state_status, decision) = recommend_reorientation(EpiphanyReorientInput { + 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(), + }); ( - ThreadEpiphanyReorientStateStatus::Ready, - build_decision( - ThreadEpiphanyReorientAction::Regather, - checkpoint_status, - Some(checkpoint.checkpoint_id.clone()), - reasons, - checkpoint_dirty_paths, - checkpoint_changed_paths, - watcher.active_frontier_node_ids.clone(), - checkpoint - .next_action - .clone() - .unwrap_or_else(|| "Re-gather source context before editing.".to_string()), - format!("Re-gather before editing: {}.", note_fragments.join("; ")), - ), + map_protocol_reorient_state_status(state_status), + map_protocol_reorient_decision(decision), ) } -fn overlapping_checkpoint_paths<'a>( - checkpoint: &codex_protocol::protocol::EpiphanyInvestigationCheckpoint, - candidate_paths: impl IntoIterator, - workspace_root: Option<&Path>, -) -> Vec { - let checkpoint_path_keys: HashSet = checkpoint - .code_refs - .iter() - .map(|code_ref| code_ref_path_key(code_ref.path.as_path(), workspace_root)) - .collect(); - if checkpoint_path_keys.is_empty() { - return Vec::new(); +fn map_core_reorient_pressure_level( + level: ThreadEpiphanyPressureLevel, +) -> CoreEpiphanyReorientPressureLevel { + match level { + ThreadEpiphanyPressureLevel::Unknown => CoreEpiphanyReorientPressureLevel::Unknown, + ThreadEpiphanyPressureLevel::Low => CoreEpiphanyReorientPressureLevel::Low, + ThreadEpiphanyPressureLevel::Elevated => CoreEpiphanyReorientPressureLevel::Medium, + ThreadEpiphanyPressureLevel::High => CoreEpiphanyReorientPressureLevel::High, + ThreadEpiphanyPressureLevel::Critical => CoreEpiphanyReorientPressureLevel::Critical, } +} - let mut overlaps = Vec::new(); - let mut seen = HashSet::new(); - for path in candidate_paths { - let path_key = code_ref_path_key(path.as_path(), workspace_root); - if checkpoint_path_keys.contains(&path_key) && seen.insert(path_key) { - overlaps.push(path.clone()); +fn map_core_reorient_retrieval_status( + status: ThreadEpiphanyRetrievalFreshnessStatus, +) -> CoreEpiphanyReorientFreshnessStatus { + match status { + ThreadEpiphanyRetrievalFreshnessStatus::Missing + | ThreadEpiphanyRetrievalFreshnessStatus::Unavailable => { + CoreEpiphanyReorientFreshnessStatus::Unknown + } + ThreadEpiphanyRetrievalFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, + ThreadEpiphanyRetrievalFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, + ThreadEpiphanyRetrievalFreshnessStatus::Indexing => { + CoreEpiphanyReorientFreshnessStatus::Dirty + } + } +} + +fn map_core_reorient_graph_status( + status: ThreadEpiphanyGraphFreshnessStatus, +) -> CoreEpiphanyReorientFreshnessStatus { + match status { + ThreadEpiphanyGraphFreshnessStatus::Missing => CoreEpiphanyReorientFreshnessStatus::Unknown, + ThreadEpiphanyGraphFreshnessStatus::Ready => CoreEpiphanyReorientFreshnessStatus::Clean, + ThreadEpiphanyGraphFreshnessStatus::Stale => CoreEpiphanyReorientFreshnessStatus::Stale, + } +} + +fn map_core_reorient_watcher_status( + status: ThreadEpiphanyInvalidationStatus, +) -> CoreEpiphanyReorientFreshnessStatus { + match status { + ThreadEpiphanyInvalidationStatus::Unavailable => { + CoreEpiphanyReorientFreshnessStatus::Unknown + } + ThreadEpiphanyInvalidationStatus::Clean => CoreEpiphanyReorientFreshnessStatus::Clean, + ThreadEpiphanyInvalidationStatus::Changed => CoreEpiphanyReorientFreshnessStatus::Changed, + } +} + +fn map_protocol_reorient_state_status( + status: CoreEpiphanyReorientStateStatus, +) -> ThreadEpiphanyReorientStateStatus { + match status { + CoreEpiphanyReorientStateStatus::Missing => ThreadEpiphanyReorientStateStatus::Missing, + CoreEpiphanyReorientStateStatus::Ready => ThreadEpiphanyReorientStateStatus::Ready, + } +} + +fn map_protocol_reorient_decision( + decision: epiphany_core::EpiphanyReorientDecision, +) -> ThreadEpiphanyReorientDecision { + ThreadEpiphanyReorientDecision { + action: map_protocol_reorient_action(decision.action), + checkpoint_status: map_protocol_reorient_checkpoint_status(decision.checkpoint_status), + checkpoint_id: decision.checkpoint_id, + pressure_level: map_protocol_reorient_pressure_level(decision.pressure_level), + retrieval_status: map_protocol_reorient_retrieval_status(decision.retrieval_status), + graph_status: map_protocol_reorient_graph_status(decision.graph_status), + watcher_status: map_protocol_reorient_watcher_status(decision.watcher_status), + reasons: decision + .reasons + .into_iter() + .map(map_protocol_reorient_reason) + .collect(), + checkpoint_dirty_paths: decision.checkpoint_dirty_paths, + checkpoint_changed_paths: decision.checkpoint_changed_paths, + active_frontier_node_ids: decision.active_frontier_node_ids, + next_action: decision.next_action, + note: decision.note, + } +} + +fn map_protocol_reorient_action( + action: CoreEpiphanyReorientAction, +) -> ThreadEpiphanyReorientAction { + match action { + CoreEpiphanyReorientAction::Resume => ThreadEpiphanyReorientAction::Resume, + CoreEpiphanyReorientAction::Regather => ThreadEpiphanyReorientAction::Regather, + } +} + +fn map_protocol_reorient_checkpoint_status( + status: CoreEpiphanyReorientCheckpointStatus, +) -> ThreadEpiphanyReorientCheckpointStatus { + match status { + CoreEpiphanyReorientCheckpointStatus::Missing => { + ThreadEpiphanyReorientCheckpointStatus::Missing + } + CoreEpiphanyReorientCheckpointStatus::ResumeReady => { + ThreadEpiphanyReorientCheckpointStatus::ResumeReady + } + CoreEpiphanyReorientCheckpointStatus::RegatherRequired => { + ThreadEpiphanyReorientCheckpointStatus::RegatherRequired + } + } +} + +fn map_protocol_reorient_pressure_level( + level: CoreEpiphanyReorientPressureLevel, +) -> ThreadEpiphanyPressureLevel { + match level { + CoreEpiphanyReorientPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, + CoreEpiphanyReorientPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, + CoreEpiphanyReorientPressureLevel::Medium => ThreadEpiphanyPressureLevel::Elevated, + CoreEpiphanyReorientPressureLevel::High => ThreadEpiphanyPressureLevel::High, + CoreEpiphanyReorientPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, + } +} + +fn map_protocol_reorient_retrieval_status( + status: CoreEpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyRetrievalFreshnessStatus { + match status { + CoreEpiphanyReorientFreshnessStatus::Unknown => { + ThreadEpiphanyRetrievalFreshnessStatus::Missing + } + CoreEpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyRetrievalFreshnessStatus::Ready, + CoreEpiphanyReorientFreshnessStatus::Dirty => { + ThreadEpiphanyRetrievalFreshnessStatus::Indexing + } + CoreEpiphanyReorientFreshnessStatus::Stale + | CoreEpiphanyReorientFreshnessStatus::Changed => { + ThreadEpiphanyRetrievalFreshnessStatus::Stale + } + } +} + +fn map_protocol_reorient_graph_status( + status: CoreEpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyGraphFreshnessStatus { + match status { + CoreEpiphanyReorientFreshnessStatus::Unknown => ThreadEpiphanyGraphFreshnessStatus::Missing, + CoreEpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyGraphFreshnessStatus::Ready, + CoreEpiphanyReorientFreshnessStatus::Dirty + | CoreEpiphanyReorientFreshnessStatus::Stale + | CoreEpiphanyReorientFreshnessStatus::Changed => ThreadEpiphanyGraphFreshnessStatus::Stale, + } +} + +fn map_protocol_reorient_watcher_status( + status: CoreEpiphanyReorientFreshnessStatus, +) -> ThreadEpiphanyInvalidationStatus { + match status { + CoreEpiphanyReorientFreshnessStatus::Unknown => { + ThreadEpiphanyInvalidationStatus::Unavailable + } + CoreEpiphanyReorientFreshnessStatus::Clean => ThreadEpiphanyInvalidationStatus::Clean, + CoreEpiphanyReorientFreshnessStatus::Dirty + | CoreEpiphanyReorientFreshnessStatus::Stale + | CoreEpiphanyReorientFreshnessStatus::Changed => ThreadEpiphanyInvalidationStatus::Changed, + } +} + +fn map_protocol_reorient_reason( + reason: CoreEpiphanyReorientReason, +) -> ThreadEpiphanyReorientReason { + match reason { + CoreEpiphanyReorientReason::MissingState => ThreadEpiphanyReorientReason::MissingState, + CoreEpiphanyReorientReason::MissingCheckpoint => { + ThreadEpiphanyReorientReason::MissingCheckpoint + } + CoreEpiphanyReorientReason::CheckpointReady => { + ThreadEpiphanyReorientReason::CheckpointReady + } + CoreEpiphanyReorientReason::CheckpointRequestedRegather => { + ThreadEpiphanyReorientReason::CheckpointRequestedRegather + } + CoreEpiphanyReorientReason::CheckpointPathsDirty => { + ThreadEpiphanyReorientReason::CheckpointPathsDirty + } + CoreEpiphanyReorientReason::CheckpointPathsChanged => { + ThreadEpiphanyReorientReason::CheckpointPathsChanged + } + CoreEpiphanyReorientReason::FrontierChanged => { + ThreadEpiphanyReorientReason::FrontierChanged + } + CoreEpiphanyReorientReason::UnanchoredCheckpointWhileStateStale => { + ThreadEpiphanyReorientReason::UnanchoredCheckpointWhileStateStale } } - overlaps } fn map_epiphany_scene_subgoals(state: &EpiphanyThreadState) -> Vec {