diff --git a/epiphany-codex-bridge/src/coordinator.rs b/epiphany-codex-bridge/src/coordinator.rs index 42dbd0b5..e3fc34c6 100644 --- a/epiphany-codex-bridge/src/coordinator.rs +++ b/epiphany-codex-bridge/src/coordinator.rs @@ -64,6 +64,7 @@ use crate::launch::build_epiphany_reorient_launch_request; use crate::launch::render_epiphany_coordinator_note; use crate::pressure::derive_epiphany_pressure; use crate::protocol_edge::protocol_job_from_surface; +use crate::protocol_edge::protocol_pressure_level; use crate::protocol_edge::protocol_reorient_result_status; use crate::protocol_edge::protocol_role_result_status; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; @@ -119,7 +120,7 @@ fn map_protocol_coordinator_source_signals( signals: EpiphanyCoordinatorSourceSignals, ) -> ThreadEpiphanyCoordinatorSignals { ThreadEpiphanyCoordinatorSignals { - pressure_level: map_protocol_pressure_level(signals.pressure_level), + pressure_level: protocol_pressure_level(signals.pressure_level), should_prepare_compaction: signals.should_prepare_compaction, reorient_action: map_protocol_reorient_action(signals.reorient_action), crrc_action: map_protocol_crrc_action(signals.crrc_action), @@ -129,28 +130,6 @@ fn map_protocol_coordinator_source_signals( } } -fn map_protocol_pressure_level( - level: epiphany_core::EpiphanyPressureLevel, -) -> codex_app_server_protocol::ThreadEpiphanyPressureLevel { - match level { - epiphany_core::EpiphanyPressureLevel::Unknown => { - codex_app_server_protocol::ThreadEpiphanyPressureLevel::Unknown - } - epiphany_core::EpiphanyPressureLevel::Low => { - codex_app_server_protocol::ThreadEpiphanyPressureLevel::Low - } - epiphany_core::EpiphanyPressureLevel::Elevated => { - codex_app_server_protocol::ThreadEpiphanyPressureLevel::Elevated - } - epiphany_core::EpiphanyPressureLevel::High => { - codex_app_server_protocol::ThreadEpiphanyPressureLevel::High - } - epiphany_core::EpiphanyPressureLevel::Critical => { - codex_app_server_protocol::ThreadEpiphanyPressureLevel::Critical - } - } -} - fn map_protocol_reorient_action( action: CoreEpiphanyReorientAction, ) -> ThreadEpiphanyReorientAction { diff --git a/epiphany-codex-bridge/src/pressure.rs b/epiphany-codex-bridge/src/pressure.rs index b18d17d2..44958f8e 100644 --- a/epiphany-codex-bridge/src/pressure.rs +++ b/epiphany-codex-bridge/src/pressure.rs @@ -1,9 +1,5 @@ use codex_app_server_protocol::ThreadEpiphanyPressure; -use codex_app_server_protocol::ThreadEpiphanyPressureBasis; -use codex_app_server_protocol::ThreadEpiphanyPressureLevel; -use codex_app_server_protocol::ThreadEpiphanyPressureStatus; use epiphany_core::EpiphanyPressure; -use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis; use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel; use epiphany_core::EpiphanyPressureStatus as CoreEpiphanyPressureStatus; pub use epiphany_core::EpiphanyTokenUsageSnapshot; @@ -11,49 +7,16 @@ use epiphany_core::derive_pressure_view; use crate::launch::epiphany_agent_prompt_with_memory; use crate::launch::epiphany_specialist_prompt_config; +use crate::protocol_edge::protocol_pressure_from_core; -pub fn derive_epiphany_pressure( - snapshot: Option<&EpiphanyTokenUsageSnapshot>, -) -> EpiphanyPressure { +pub fn derive_epiphany_pressure(snapshot: Option<&EpiphanyTokenUsageSnapshot>) -> EpiphanyPressure { derive_pressure_view(snapshot) } pub fn map_epiphany_pressure( snapshot: Option<&EpiphanyTokenUsageSnapshot>, ) -> ThreadEpiphanyPressure { - map_core_epiphany_pressure(derive_epiphany_pressure(snapshot)) -} - -fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure { - ThreadEpiphanyPressure { - status: match pressure.status { - CoreEpiphanyPressureStatus::Unknown => ThreadEpiphanyPressureStatus::Unknown, - CoreEpiphanyPressureStatus::Ready => ThreadEpiphanyPressureStatus::Ready, - }, - level: match pressure.level { - CoreEpiphanyPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, - CoreEpiphanyPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, - CoreEpiphanyPressureLevel::Elevated => ThreadEpiphanyPressureLevel::Elevated, - CoreEpiphanyPressureLevel::High => ThreadEpiphanyPressureLevel::High, - CoreEpiphanyPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, - }, - basis: match pressure.basis { - CoreEpiphanyPressureBasis::Unknown => ThreadEpiphanyPressureBasis::Unknown, - CoreEpiphanyPressureBasis::AutoCompactLimit => { - ThreadEpiphanyPressureBasis::AutoCompactLimit - } - CoreEpiphanyPressureBasis::ModelContextWindow => { - ThreadEpiphanyPressureBasis::ModelContextWindow - } - }, - used_tokens: pressure.used_tokens, - model_context_window: pressure.model_context_window, - model_auto_compact_token_limit: pressure.model_auto_compact_token_limit, - remaining_tokens: pressure.remaining_tokens, - ratio_per_mille: pressure.ratio_per_mille, - should_prepare_compaction: pressure.should_prepare_compaction, - note: pressure.note, - } + protocol_pressure_from_core(derive_epiphany_pressure(snapshot)) } pub fn should_run_epiphany_pre_compaction_checkpoint_intervention( @@ -85,7 +48,10 @@ pub fn render_epiphany_pre_compaction_checkpoint_intervention( ); template .trim() - .replace("{pressure_level}", core_pressure_level_label(pressure.level)) + .replace( + "{pressure_level}", + core_pressure_level_label(pressure.level), + ) .replace("{usage}", &usage) } diff --git a/epiphany-codex-bridge/src/protocol_edge.rs b/epiphany-codex-bridge/src/protocol_edge.rs index 8bc8ef45..d9d796b4 100644 --- a/epiphany-codex-bridge/src/protocol_edge.rs +++ b/epiphany-codex-bridge/src/protocol_edge.rs @@ -27,7 +27,10 @@ use codex_app_server_protocol::ThreadEpiphanyInvalidationStatus; use codex_app_server_protocol::ThreadEpiphanyJob; use codex_app_server_protocol::ThreadEpiphanyJobKind; use codex_app_server_protocol::ThreadEpiphanyJobStatus; +use codex_app_server_protocol::ThreadEpiphanyPressure; +use codex_app_server_protocol::ThreadEpiphanyPressureBasis; use codex_app_server_protocol::ThreadEpiphanyPressureLevel; +use codex_app_server_protocol::ThreadEpiphanyPressureStatus; use codex_app_server_protocol::ThreadEpiphanyReorientAction; use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus; use codex_app_server_protocol::ThreadEpiphanyReorientDecision; @@ -50,6 +53,10 @@ use epiphany_core::EpiphanyDistillInput; use epiphany_core::EpiphanyGraphQuery; use epiphany_core::EpiphanyGraphQueryDirection; use epiphany_core::EpiphanyGraphQueryKind; +use epiphany_core::EpiphanyPressure; +use epiphany_core::EpiphanyPressureBasis; +use epiphany_core::EpiphanyPressureLevel; +use epiphany_core::EpiphanyPressureStatus; use epiphany_core::EpiphanyReorientWorkerLaunchDocument; use epiphany_core::EpiphanyRoleStatePatchDocument; use epiphany_core::EpiphanyRoleWorkerLaunchDocument; @@ -342,6 +349,42 @@ pub fn protocol_reorient_decision( } } +pub fn protocol_pressure_from_core(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure { + ThreadEpiphanyPressure { + status: match pressure.status { + EpiphanyPressureStatus::Unknown => ThreadEpiphanyPressureStatus::Unknown, + EpiphanyPressureStatus::Ready => ThreadEpiphanyPressureStatus::Ready, + }, + level: protocol_pressure_level(pressure.level), + basis: match pressure.basis { + EpiphanyPressureBasis::Unknown => ThreadEpiphanyPressureBasis::Unknown, + EpiphanyPressureBasis::AutoCompactLimit => { + ThreadEpiphanyPressureBasis::AutoCompactLimit + } + EpiphanyPressureBasis::ModelContextWindow => { + ThreadEpiphanyPressureBasis::ModelContextWindow + } + }, + used_tokens: pressure.used_tokens, + model_context_window: pressure.model_context_window, + model_auto_compact_token_limit: pressure.model_auto_compact_token_limit, + remaining_tokens: pressure.remaining_tokens, + ratio_per_mille: pressure.ratio_per_mille, + should_prepare_compaction: pressure.should_prepare_compaction, + note: pressure.note, + } +} + +pub fn protocol_pressure_level(level: EpiphanyPressureLevel) -> ThreadEpiphanyPressureLevel { + match level { + EpiphanyPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, + EpiphanyPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, + EpiphanyPressureLevel::Elevated => ThreadEpiphanyPressureLevel::Elevated, + EpiphanyPressureLevel::High => ThreadEpiphanyPressureLevel::High, + EpiphanyPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, + } +} + pub fn protocol_role_result_status( status: EpiphanyCoordinatorRoleResultStatus, ) -> ThreadEpiphanyRoleResultStatus { diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index bdd795db..dd8b7b82 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -82,6 +82,7 @@ remembers doctrine; the branch remembers the blade. - Freshness/job/reorient response projection also belongs to the bridge edge now. Vendored app-server no longer keeps local helpers for `EpiphanyFreshnessSurface`, `EpiphanyJobView`, `EpiphanySurfaceSource`, or reorient decision/status enum projection; it gathers host facts, invokes bridge/core services, and sends the Codex JSON-RPC response. - Job projection has one mapper now. `epiphany-codex-bridge::jobs` derives typed `EpiphanyJobView` and no longer imports app-server protocol DTOs; `protocol_edge::protocol_job_from_surface` is the only `EpiphanyJobView` -> `ThreadEpiphanyJob` conversion path. - Runtime result loading is typed-only now. Role/reorient result status projection moved out of `runtime_results` and duplicate coordinator helpers into `protocol_edge`, so view and coordinator response builders share one Codex JSON-RPC status mapper. +- Pressure projection is centralized too. `pressure.rs` derives typed `EpiphanyPressure`, coordinator consumes typed pressure signals, and `protocol_edge` owns the `ThreadEpiphanyPressure*` DTO mapping. - MCP remains JSON because MCP is a JSON protocol. The latest processor cut only moved MCP refresh/OAuth/status/resource/tool-call route handling into `codex_message_processor/mcp_routes.rs`, reducing the root processor to about 8,977 lines; it did not claim MCP payloads are CultNet or make MCP an Epiphany-owned runtime contract. - Codex account auth route handling remains in vendored Codex but now lives in `codex_message_processor/auth_routes.rs`: API-key login, ChatGPT browser/device-code/external-token login, logout, auth status, account, rate limits, and add-credits nudge handling. This preserves Codex ownership of subscription auth while cutting the root processor to about 8,094 lines. - One-off command execution and command stream write/resize/terminate route handling now live in `codex_message_processor/command_routes.rs`; `CommandExecManager` remains the lifecycle owner, while the root processor is about 7,800 lines. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index b373dec7..62b38834 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index af07fec4..66c68ac7 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -406,6 +406,10 @@ current_status: role/reorient result status projection moved from `runtime_results` and duplicate coordinator helpers into `protocol_edge`, so coordinator/view response builders share the same Codex JSON-RPC status mapper. + Pressure projection is centralized at the same edge: `pressure.rs` derives + typed `EpiphanyPressure`, coordinator consumes typed pressure signals, and + `protocol_edge` owns the `EpiphanyPressure` / + `EpiphanyPressureLevel` -> `ThreadEpiphanyPressure*` mapping. The bridge still depends on vendored Codex for app-server protocol DTOs and absolute path validation, so the purification is not done. next_action: Continue Codex starvation and CultNet liberation by cutting bridge-internal response/projection authority. Prioritize the next coordinator/view seam that still composes policy-shaped facts instead of merely loading host facts and projecting core surfaces; keep MCP/OpenAI JSON only at their true protocol/text edges. Do not add compatibility adapters unless they protect a named ownership invariant.