diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index bef18104..45dc4767 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -414,9 +414,12 @@ to about 20,331 lines. The third cut moved protocol-to-core launch document mapping into `epiphany_launch.rs`, taking the processor to about 20,255 lines. The fourth cut moved scene projection into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, taking the processor -to about 20,059 lines. This is progress, not absolution: handlers, remaining -view mappers, route orchestration, coordinator glue, accept policy plumbing, -and tests still keep too much Epiphany inside Codex. +to about 20,059 lines. The fifth cut moved freshness/reorientation input +mapping into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`, +taking the processor to about 19,708 lines. This is progress, not absolution: +handlers, context/planning/graph/jobs/roles/coordinator mappers, route +orchestration, accept policy plumbing, and tests still keep too much Epiphany +inside Codex. Also: MCP itself is allowed to be JSON. The target is not "replace MCP JSON"; the target is an Epiphany-owned boundary that speaks typed Epiphany diff --git a/notes/json-contamination-ledger.md b/notes/json-contamination-ledger.md index 81b22b9a..94fad164 100644 --- a/notes/json-contamination-ledger.md +++ b/notes/json-contamination-ledger.md @@ -62,6 +62,6 @@ Rule: JSON is allowed at external schema/wire boundaries. Inside Epiphany, live 3. Done: replace role `statePatch` JSON with typed map/planning/graph patch documents. `EpiphanyRoleFindingInterpretation` now carries `EpiphanyRoleStatePatchDocument`; app-server maps it to the legacy protocol patch without JSON round-tripping. 4. Done: replace runtime job result JSON projections. Runtime-spine results now project through typed role/reorient interpreters instead of `runtime_job_result_to_role_json` and `runtime_job_result_to_reorient_json`. 5. Done: replace app-server launch protocol `input_json` / `output_schema_json` with typed launch documents and `output_contract_id`. -6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, and scene projection into `epiphany_scene.rs`, reducing `codex_message_processor.rs` from about 21,263 to 20,059 lines. Next move route handlers, remaining view projection mappers, coordinator glue, and policy-shaped code out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. +6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, and freshness/reorientation mapping into `epiphany_reorient.rs`, reducing `codex_message_processor.rs` from about 21,263 to 19,708 lines. Next move route handlers, remaining view projection mappers, coordinator glue, and policy-shaped code out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. 7. Seal MCP payloads behind an Epiphany boundary that speaks typed Epiphany documents internally and MCP JSON externally. 8. Audit heartbeat cognition values and either type them or explicitly expire them. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 6275c92a..5627e6e8 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 6a8151f1..849fd080 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -278,5 +278,5 @@ rejected_paths: reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet. current_status: - summary: The Codex starvation pass has five typing receipts plus four real carcass cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, and scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`. The processor is down from about 21,263 lines to 20,059 lines. This is progress, not absolution: route handlers, remaining view mappers, coordinator glue, accept policy plumbing, and tests still keep too much Epiphany inside Codex. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. + summary: The Codex starvation pass has five typing receipts plus five real carcass cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, and freshness/reorientation input mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`. The processor is down from about 21,263 lines to 19,708 lines. This is progress, not absolution: route handlers, context/planning/graph/jobs/roles/coordinator mappers, accept policy plumbing, and tests still keep too much Epiphany inside Codex. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. next_action: Continue the actual whale-carcass cut: extract Epiphany route handlers, scene/view projection mappers, coordinator glue, and remaining policy-shaped code out of `codex_message_processor.rs` into Epiphany-owned app-server modules, moving logic further into `epiphany-core` whenever it owns real policy. Success metric remains a visibly smaller processor and clearer ownership, not merely typed payloads. 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 22bd618f..ed86407b 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 @@ -25,6 +25,8 @@ use crate::epiphany_launch::epiphany_specialist_prompt_config; use crate::epiphany_launch::map_core_worker_launch_document; use crate::epiphany_launch::pressure_level_label; use crate::epiphany_launch::render_epiphany_coordinator_note; +use crate::epiphany_reorient::map_epiphany_freshness; +use crate::epiphany_reorient::map_epiphany_reorient; use crate::epiphany_results::map_core_role_result_role_id; use crate::epiphany_results::map_epiphany_reorient_finding; use crate::epiphany_results::map_epiphany_role_finding; @@ -537,20 +539,13 @@ use epiphany_core::EpiphanyCrrcReorientAction as CoreEpiphanyCrrcReorientAction; use epiphany_core::EpiphanyCrrcResultStatus as CoreEpiphanyCrrcResultStatus; use epiphany_core::EpiphanyCrrcSceneAction as CoreEpiphanyCrrcSceneAction; use epiphany_core::EpiphanyCrrcStateStatus as CoreEpiphanyCrrcStateStatus; -use epiphany_core::EpiphanyFreshnessInput; -use epiphany_core::EpiphanyFreshnessView; -use epiphany_core::EpiphanyFreshnessWatcherInput; use epiphany_core::EpiphanyGraphContext as CoreEpiphanyGraphContext; -use epiphany_core::EpiphanyGraphFreshness as CoreEpiphanyGraphFreshness; -use epiphany_core::EpiphanyGraphFreshnessStatus as CoreEpiphanyGraphFreshnessStatus; use epiphany_core::EpiphanyGraphQuery as CoreEpiphanyGraphQuery; use epiphany_core::EpiphanyGraphQueryDirection as CoreEpiphanyGraphQueryDirection; use epiphany_core::EpiphanyGraphQueryKind as CoreEpiphanyGraphQueryKind; use epiphany_core::EpiphanyGraphQueryMatched as CoreEpiphanyGraphQueryMatched; use epiphany_core::EpiphanyGraphQueryMissing as CoreEpiphanyGraphQueryMissing; use epiphany_core::EpiphanyGraphQueryView; -use epiphany_core::EpiphanyInvalidationInput as CoreEpiphanyInvalidationInput; -use epiphany_core::EpiphanyInvalidationStatus as CoreEpiphanyInvalidationStatus; use epiphany_core::EpiphanyJobStatus as CoreEpiphanyJobStatus; use epiphany_core::EpiphanyJobView; use epiphany_core::EpiphanyJobsInput; @@ -562,15 +557,6 @@ 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::EpiphanyRetrievalFreshness as CoreEpiphanyRetrievalFreshness; -use epiphany_core::EpiphanyRetrievalFreshnessStatus as CoreEpiphanyRetrievalFreshnessStatus; use epiphany_core::EpiphanyRoleAcceptanceFinding; use epiphany_core::EpiphanyRoleBoardCheckpointSummary; use epiphany_core::EpiphanyRoleBoardInput; @@ -587,7 +573,6 @@ use epiphany_core::build_reorient_acceptance_bundle; use epiphany_core::build_role_acceptance_bundle; use epiphany_core::coordinator_automation_action; use epiphany_core::derive_context; -use epiphany_core::derive_freshness; use epiphany_core::derive_graph_query; use epiphany_core::derive_jobs; use epiphany_core::derive_planning_view; @@ -600,7 +585,6 @@ use epiphany_core::interpret_role_runtime_job_result; 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; @@ -13861,118 +13845,6 @@ fn reorient_finding_investigation_checkpoint( checkpoint } -fn map_epiphany_freshness( - state: Option<&EpiphanyThreadState>, - retrieval_override: Option<&EpiphanyRetrievalState>, - watcher_snapshot: Option<&EpiphanyInvalidationSnapshot>, -) -> ( - Option, - ThreadEpiphanyRetrievalFreshness, - ThreadEpiphanyGraphFreshness, - ThreadEpiphanyInvalidationInput, -) { - let watcher = watcher_snapshot.map(|snapshot| EpiphanyFreshnessWatcherInput { - available: snapshot.available, - workspace_root: snapshot.workspace_root.as_deref(), - observed_at_unix_seconds: snapshot.observed_at_unix_seconds, - changed_paths: snapshot.changed_paths.as_slice(), - }); - let freshness = derive_freshness(EpiphanyFreshnessInput { - state, - retrieval_override, - watcher, - }); - map_core_epiphany_freshness(freshness) -} - -fn map_core_epiphany_freshness( - freshness: EpiphanyFreshnessView, -) -> ( - Option, - ThreadEpiphanyRetrievalFreshness, - ThreadEpiphanyGraphFreshness, - ThreadEpiphanyInvalidationInput, -) { - ( - freshness.state_revision, - map_core_epiphany_retrieval_freshness(freshness.retrieval), - map_core_epiphany_graph_freshness(freshness.graph), - map_core_epiphany_invalidation_input(freshness.watcher), - ) -} - -fn map_core_epiphany_retrieval_freshness( - retrieval: CoreEpiphanyRetrievalFreshness, -) -> ThreadEpiphanyRetrievalFreshness { - ThreadEpiphanyRetrievalFreshness { - status: match retrieval.status { - CoreEpiphanyRetrievalFreshnessStatus::Missing => { - ThreadEpiphanyRetrievalFreshnessStatus::Missing - } - CoreEpiphanyRetrievalFreshnessStatus::Ready => { - ThreadEpiphanyRetrievalFreshnessStatus::Ready - } - CoreEpiphanyRetrievalFreshnessStatus::Stale => { - ThreadEpiphanyRetrievalFreshnessStatus::Stale - } - CoreEpiphanyRetrievalFreshnessStatus::Indexing => { - ThreadEpiphanyRetrievalFreshnessStatus::Indexing - } - CoreEpiphanyRetrievalFreshnessStatus::Unavailable => { - ThreadEpiphanyRetrievalFreshnessStatus::Unavailable - } - }, - semantic_available: retrieval.semantic_available, - last_indexed_at_unix_seconds: retrieval.last_indexed_at_unix_seconds, - indexed_file_count: retrieval.indexed_file_count, - indexed_chunk_count: retrieval.indexed_chunk_count, - dirty_paths: retrieval.dirty_paths, - note: retrieval.note, - } -} - -fn map_core_epiphany_graph_freshness( - graph: CoreEpiphanyGraphFreshness, -) -> ThreadEpiphanyGraphFreshness { - ThreadEpiphanyGraphFreshness { - status: match graph.status { - CoreEpiphanyGraphFreshnessStatus::Missing => { - ThreadEpiphanyGraphFreshnessStatus::Missing - } - CoreEpiphanyGraphFreshnessStatus::Ready => ThreadEpiphanyGraphFreshnessStatus::Ready, - CoreEpiphanyGraphFreshnessStatus::Stale => ThreadEpiphanyGraphFreshnessStatus::Stale, - }, - graph_freshness: graph.graph_freshness, - checkpoint_id: graph.checkpoint_id, - dirty_path_count: graph.dirty_path_count, - dirty_paths: graph.dirty_paths, - open_question_count: graph.open_question_count, - open_gap_count: graph.open_gap_count, - note: graph.note, - } -} - -fn map_core_epiphany_invalidation_input( - watcher: CoreEpiphanyInvalidationInput, -) -> ThreadEpiphanyInvalidationInput { - ThreadEpiphanyInvalidationInput { - status: match watcher.status { - CoreEpiphanyInvalidationStatus::Unavailable => { - ThreadEpiphanyInvalidationStatus::Unavailable - } - CoreEpiphanyInvalidationStatus::Clean => ThreadEpiphanyInvalidationStatus::Clean, - CoreEpiphanyInvalidationStatus::Changed => ThreadEpiphanyInvalidationStatus::Changed, - }, - watched_root: watcher.watched_root, - observed_at_unix_seconds: watcher.observed_at_unix_seconds, - changed_path_count: watcher.changed_path_count, - changed_paths: watcher.changed_paths, - graph_node_ids: watcher.graph_node_ids, - active_frontier_node_ids: watcher.active_frontier_node_ids, - note: watcher.note, - } -} - fn map_epiphany_pressure(info: Option<&CoreTokenUsageInfo>) -> ThreadEpiphanyPressure { map_core_epiphany_pressure(derive_pressure_view(info)) } @@ -14042,229 +13914,6 @@ fn render_epiphany_pre_compaction_checkpoint_intervention( .replace("{usage}", &usage) } -fn map_epiphany_reorient( - state: Option<&EpiphanyThreadState>, - pressure: &ThreadEpiphanyPressure, - retrieval: &ThreadEpiphanyRetrievalFreshness, - graph: &ThreadEpiphanyGraphFreshness, - watcher: &ThreadEpiphanyInvalidationInput, -) -> ( - ThreadEpiphanyReorientStateStatus, - ThreadEpiphanyReorientDecision, -) { - 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(), - }); - ( - map_protocol_reorient_state_status(state_status), - map_protocol_reorient_decision(decision), - ) -} - -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, - } -} - -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 - } - } -} - fn map_epiphany_context( state: Option<&EpiphanyThreadState>, params: &ThreadEpiphanyContextParams, diff --git a/vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs b/vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs new file mode 100644 index 00000000..1f7eee74 --- /dev/null +++ b/vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs @@ -0,0 +1,370 @@ +use codex_app_server_protocol::ThreadEpiphanyGraphFreshness; +use codex_app_server_protocol::ThreadEpiphanyGraphFreshnessStatus; +use codex_app_server_protocol::ThreadEpiphanyInvalidationInput; +use codex_app_server_protocol::ThreadEpiphanyInvalidationStatus; +use codex_app_server_protocol::ThreadEpiphanyPressure; +use codex_app_server_protocol::ThreadEpiphanyPressureLevel; +use codex_app_server_protocol::ThreadEpiphanyReorientAction; +use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus; +use codex_app_server_protocol::ThreadEpiphanyReorientDecision; +use codex_app_server_protocol::ThreadEpiphanyReorientReason; +use codex_app_server_protocol::ThreadEpiphanyReorientStateStatus; +use codex_app_server_protocol::ThreadEpiphanyRetrievalFreshness; +use codex_app_server_protocol::ThreadEpiphanyRetrievalFreshnessStatus; +use codex_protocol::protocol::EpiphanyRetrievalState; +use codex_protocol::protocol::EpiphanyThreadState; +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; +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::EpiphanyRetrievalFreshness as CoreEpiphanyRetrievalFreshness; +use epiphany_core::EpiphanyRetrievalFreshnessStatus as CoreEpiphanyRetrievalFreshnessStatus; +use epiphany_core::derive_freshness; +use epiphany_core::recommend_reorientation; + +use crate::epiphany_invalidation::EpiphanyInvalidationSnapshot; + +pub(super) fn map_epiphany_freshness( + state: Option<&EpiphanyThreadState>, + retrieval_override: Option<&EpiphanyRetrievalState>, + watcher_snapshot: Option<&EpiphanyInvalidationSnapshot>, +) -> ( + Option, + ThreadEpiphanyRetrievalFreshness, + ThreadEpiphanyGraphFreshness, + ThreadEpiphanyInvalidationInput, +) { + let watcher = watcher_snapshot.map(|snapshot| EpiphanyFreshnessWatcherInput { + available: snapshot.available, + workspace_root: snapshot.workspace_root.as_deref(), + observed_at_unix_seconds: snapshot.observed_at_unix_seconds, + changed_paths: snapshot.changed_paths.as_slice(), + }); + let freshness = derive_freshness(EpiphanyFreshnessInput { + state, + retrieval_override, + watcher, + }); + map_core_epiphany_freshness(freshness) +} + +fn map_core_epiphany_freshness( + freshness: EpiphanyFreshnessView, +) -> ( + Option, + ThreadEpiphanyRetrievalFreshness, + ThreadEpiphanyGraphFreshness, + ThreadEpiphanyInvalidationInput, +) { + ( + freshness.state_revision, + map_core_epiphany_retrieval_freshness(freshness.retrieval), + map_core_epiphany_graph_freshness(freshness.graph), + map_core_epiphany_invalidation_input(freshness.watcher), + ) +} + +fn map_core_epiphany_retrieval_freshness( + retrieval: CoreEpiphanyRetrievalFreshness, +) -> ThreadEpiphanyRetrievalFreshness { + ThreadEpiphanyRetrievalFreshness { + status: match retrieval.status { + CoreEpiphanyRetrievalFreshnessStatus::Missing => { + ThreadEpiphanyRetrievalFreshnessStatus::Missing + } + CoreEpiphanyRetrievalFreshnessStatus::Ready => { + ThreadEpiphanyRetrievalFreshnessStatus::Ready + } + CoreEpiphanyRetrievalFreshnessStatus::Stale => { + ThreadEpiphanyRetrievalFreshnessStatus::Stale + } + CoreEpiphanyRetrievalFreshnessStatus::Indexing => { + ThreadEpiphanyRetrievalFreshnessStatus::Indexing + } + CoreEpiphanyRetrievalFreshnessStatus::Unavailable => { + ThreadEpiphanyRetrievalFreshnessStatus::Unavailable + } + }, + semantic_available: retrieval.semantic_available, + last_indexed_at_unix_seconds: retrieval.last_indexed_at_unix_seconds, + indexed_file_count: retrieval.indexed_file_count, + indexed_chunk_count: retrieval.indexed_chunk_count, + dirty_paths: retrieval.dirty_paths, + note: retrieval.note, + } +} + +fn map_core_epiphany_graph_freshness( + graph: CoreEpiphanyGraphFreshness, +) -> ThreadEpiphanyGraphFreshness { + ThreadEpiphanyGraphFreshness { + status: match graph.status { + CoreEpiphanyGraphFreshnessStatus::Missing => { + ThreadEpiphanyGraphFreshnessStatus::Missing + } + CoreEpiphanyGraphFreshnessStatus::Ready => ThreadEpiphanyGraphFreshnessStatus::Ready, + CoreEpiphanyGraphFreshnessStatus::Stale => ThreadEpiphanyGraphFreshnessStatus::Stale, + }, + graph_freshness: graph.graph_freshness, + checkpoint_id: graph.checkpoint_id, + dirty_path_count: graph.dirty_path_count, + dirty_paths: graph.dirty_paths, + open_question_count: graph.open_question_count, + open_gap_count: graph.open_gap_count, + note: graph.note, + } +} + +fn map_core_epiphany_invalidation_input( + watcher: CoreEpiphanyInvalidationInput, +) -> ThreadEpiphanyInvalidationInput { + ThreadEpiphanyInvalidationInput { + status: match watcher.status { + CoreEpiphanyInvalidationStatus::Unavailable => { + ThreadEpiphanyInvalidationStatus::Unavailable + } + CoreEpiphanyInvalidationStatus::Clean => ThreadEpiphanyInvalidationStatus::Clean, + CoreEpiphanyInvalidationStatus::Changed => ThreadEpiphanyInvalidationStatus::Changed, + }, + watched_root: watcher.watched_root, + observed_at_unix_seconds: watcher.observed_at_unix_seconds, + changed_path_count: watcher.changed_path_count, + changed_paths: watcher.changed_paths, + graph_node_ids: watcher.graph_node_ids, + active_frontier_node_ids: watcher.active_frontier_node_ids, + note: watcher.note, + } +} + +pub(super) fn map_epiphany_reorient( + state: Option<&EpiphanyThreadState>, + pressure: &ThreadEpiphanyPressure, + retrieval: &ThreadEpiphanyRetrievalFreshness, + graph: &ThreadEpiphanyGraphFreshness, + watcher: &ThreadEpiphanyInvalidationInput, +) -> ( + ThreadEpiphanyReorientStateStatus, + ThreadEpiphanyReorientDecision, +) { + 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(), + }); + ( + map_protocol_reorient_state_status(state_status), + map_protocol_reorient_decision(decision), + ) +} + +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, + } +} + +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 + } + } +} diff --git a/vendor/codex/codex-rs/app-server/src/lib.rs b/vendor/codex/codex-rs/app-server/src/lib.rs index 97c6f45e..b255ccc1 100644 --- a/vendor/codex/codex-rs/app-server/src/lib.rs +++ b/vendor/codex/codex-rs/app-server/src/lib.rs @@ -77,6 +77,7 @@ mod device_key_api; mod dynamic_tools; mod epiphany_invalidation; mod epiphany_launch; +mod epiphany_reorient; mod epiphany_results; mod epiphany_scene; mod error_code;