Centralize pressure protocol projection

This commit is contained in:
Meta Vens 2026-05-20 14:04:31 +01:00
commit fa8f04b86a
6 changed files with 57 additions and 64 deletions

View file

@ -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 {

View file

@ -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)
}

View file

@ -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 {