From 0ca51e02cab8ba88eb27d954a9f7fdf409b73e68 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 07:26:38 +0100 Subject: [PATCH] Move Epiphany automation assembly into bridge --- epiphany-codex-bridge/src/coordinator.rs | 34 ++++++++++++ epiphany-codex-bridge/src/pressure.rs | 8 +++ notes/fresh-workspace-handoff.md | 1 + state/ledgers.msgpack | Bin 146660 -> 146966 bytes state/map.yaml | 4 ++ .../epiphany_automation.rs | 49 +++++------------- 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/epiphany-codex-bridge/src/coordinator.rs b/epiphany-codex-bridge/src/coordinator.rs index 186118a2..8833c111 100644 --- a/epiphany-codex-bridge/src/coordinator.rs +++ b/epiphany-codex-bridge/src/coordinator.rs @@ -19,6 +19,7 @@ use codex_app_server_protocol::ThreadEpiphanyRoleStatus; use codex_app_server_protocol::ThreadEpiphanyRolesSource; use codex_app_server_protocol::ThreadEpiphanySceneAction; use codex_app_server_protocol::ThreadEpiphanyViewCoordinator; +use codex_core::CodexThread; use codex_protocol::protocol::EpiphanyAcceptanceReceipt; use codex_protocol::protocol::EpiphanyRetrievalState; use codex_protocol::protocol::EpiphanyThreadState; @@ -64,13 +65,17 @@ use crate::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; use crate::launch::build_epiphany_reorient_launch_request; use crate::launch::epiphany_role_label; use crate::launch::render_epiphany_coordinator_note; +use crate::invalidation::EpiphanyInvalidationManager; +use crate::invalidation::epiphany_freshness_watcher_snapshot; use crate::mutation::epiphany_modeling_finding_has_reviewable_state_patch; use crate::pressure::map_epiphany_pressure; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; use crate::reorient::map_epiphany_freshness; use crate::reorient::map_epiphany_reorient; +use crate::retrieve::thread_epiphany_retrieval_state; use crate::runtime_results::load_epiphany_reorient_result_snapshot; use crate::runtime_results::load_epiphany_role_result_snapshot; +use crate::state::runtime_spine_store_path; use std::collections::HashSet; use std::path::Path; @@ -504,6 +509,35 @@ pub async fn select_epiphany_coordinator_automation( } } +pub async fn select_thread_epiphany_coordinator_automation( + thread_id: &str, + thread: &CodexThread, + epiphany_invalidation_manager: &EpiphanyInvalidationManager, + force_checkpoint_compaction: bool, +) -> Option { + let state = thread.epiphany_state().await?; + let retrieval_override = thread_epiphany_retrieval_state(thread).await; + let config_snapshot = thread.config_snapshot().await; + epiphany_invalidation_manager + .ensure_thread_watch(thread_id, &config_snapshot.cwd) + .await; + let watcher_snapshot = epiphany_invalidation_manager.snapshot(thread_id).await; + let token_usage_info = thread.token_usage_info().await; + let runtime_store_path = runtime_spine_store_path(thread).await; + Some( + select_epiphany_coordinator_automation(EpiphanyCoordinatorAutomationInput { + thread_id, + state: &state, + retrieval_override: &retrieval_override, + watcher_snapshot: epiphany_freshness_watcher_snapshot(&watcher_snapshot), + token_usage_info: token_usage_info.as_ref(), + runtime_store_path: runtime_store_path.as_path(), + force_checkpoint_compaction, + }) + .await, + ) +} + pub fn map_epiphany_coordinator( state_status: ThreadEpiphanyReorientStateStatus, checkpoint_present: bool, diff --git a/epiphany-codex-bridge/src/pressure.rs b/epiphany-codex-bridge/src/pressure.rs index fcfc4dfd..7c762975 100644 --- a/epiphany-codex-bridge/src/pressure.rs +++ b/epiphany-codex-bridge/src/pressure.rs @@ -88,3 +88,11 @@ pub fn render_epiphany_pre_compaction_checkpoint_intervention( .replace("{pressure_level}", pressure_level_label(pressure.level)) .replace("{usage}", &usage) } + +pub fn render_pre_compaction_checkpoint_intervention_for_token_usage( + info: Option<&CoreTokenUsageInfo>, +) -> Option { + let pressure = map_epiphany_pressure(info); + should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) + .then(|| render_epiphany_pre_compaction_checkpoint_intervention(&pressure)) +} diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 138c89c1..fdd052ce 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -63,6 +63,7 @@ remembers doctrine; the branch remembers the blade. - Epiphany job launch/interrupt policy and state-update application now belong to `epiphany-codex-bridge::mutation_service`: heartbeat launch planning, runtime-spine job opening, binding/runtime-link mutation, interrupt binding cleanup, and typed patch apply are out of vendored `CodexThread`. `CodexThread` now exposes only the narrow Codex-session host seam for reading current Epiphany state/reference turn and persisting an already-mutated snapshot into rollout/session storage. - Epiphany retrieval status, indexing, and retrieval execution now belong to `epiphany-codex-bridge::retrieve`; vendored `CodexThread` only exposes cwd/codex-home host facts for that path. - Vendored app-server no longer imports `epiphany_core` directly. Retrieval query normalization and raw route job-launch DTO construction are bridge-owned adapters; the remaining direct native render call is in Codex core's model-context prompt fragment host seam. +- Coordinator automation input assembly and pre-compaction intervention text rendering now belong to `epiphany-codex-bridge`; vendored app-server keeps only host actions: submit Codex compaction, launch through bridge, steer active turns, and emit JSON-RPC notifications. - Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits. - Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage. - Heartbeat adaptive pacing now lives in `epiphany-core/src/heartbeat_state/heartbeat_pacing.rs`, including running-turn count and effective cooldown multipliers. It has a module-local unit test for pending-turn counting; root scheduling calls the pacing seam instead of owning pressure/concurrency math directly. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index fd48d6a54006f79b2f2ef0fac3f810a9a998c34c..5a15e6f08f6f23842888ee90bdd9d3f827e2f66a 100644 GIT binary patch delta 216 zcmaFzlVjQ+jtR<4ws$tFPGe;3Yu>}yzK4-<`yNInA?xY8PcZVaTZ9;xSs9s4SM+Ao zVZZs_H@_@3WxDK9MhT(Jyn@mag~a0G)ZC<;N`=I{l3@`{@P+I0JQ*WTs^%gSG1ym!zf^DHP {} EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient => { @@ -112,10 +91,11 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo token_usage_info: Option, thread_state: &Arc>, ) { - let pressure = map_epiphany_pressure(token_usage_info.as_ref()); - if !should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) { + let Some(text) = + render_pre_compaction_checkpoint_intervention_for_token_usage(token_usage_info.as_ref()) + else { return; - } + }; if thread.epiphany_state().await.is_none() { return; } @@ -129,7 +109,6 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo } } - let text = render_epiphany_pre_compaction_checkpoint_intervention(&pressure); match thread .steer_input( vec![CoreInputItem::Text {