From bd6df14ad3ab37514ab294f812e27fbbdef1524f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 9 Jun 2026 06:11:17 +0100 Subject: [PATCH] Move view route planning into bridge --- epiphany-codex-bridge/src/view_protocol.rs | 32 ++++++++++++++++++ notes/epiphany-current-algorithmic-map.md | 2 +- notes/fresh-workspace-handoff.md | 12 +++++-- state/ledgers.cc | Bin 181887 -> 182288 bytes state/map.yaml | 2 +- .../epiphany_read_routes.rs | 28 +++++---------- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/epiphany-codex-bridge/src/view_protocol.rs b/epiphany-codex-bridge/src/view_protocol.rs index d9ad5fb1..b5eaa57a 100644 --- a/epiphany-codex-bridge/src/view_protocol.rs +++ b/epiphany-codex-bridge/src/view_protocol.rs @@ -40,6 +40,11 @@ use crate::error::Result as BridgeResult; use crate::jobs::map_epiphany_jobs; use crate::launch::epiphany_role_binding_id; use crate::pressure::derive_epiphany_pressure; +use crate::protocol_edge::core_epiphany_view_needs_jobs; +use crate::protocol_edge::core_epiphany_view_needs_pressure; +use crate::protocol_edge::core_epiphany_view_needs_reorientation_inputs; +use crate::protocol_edge::core_epiphany_view_needs_runtime_store; +use crate::protocol_edge::default_core_epiphany_view_lenses; use crate::protocol_edge::protocol_context_params_to_core; use crate::protocol_edge::protocol_distill_params_to_core; use crate::protocol_edge::protocol_freshness_response_from_surface; @@ -57,6 +62,7 @@ use crate::protocol_edge::protocol_role_id_to_core; use crate::protocol_edge::protocol_role_result_status; use crate::protocol_edge::protocol_roles_source; use crate::protocol_edge::protocol_view_lens_from_core; +use crate::protocol_edge::protocol_view_lenses_to_core; use crate::reorient::EpiphanyFreshnessWatcherSnapshot; use crate::reorient::derive_epiphany_freshness_view; use crate::reorient::derive_epiphany_reorient; @@ -180,6 +186,32 @@ pub struct EpiphanyViewResponseInput<'a> { pub runtime_store_path: Option<&'a Path>, } +pub struct EpiphanyViewRoutePlan { + pub thread_id: String, + pub lenses: Vec, + pub needs_jobs: bool, + pub needs_reorientation_inputs: bool, + pub needs_pressure: bool, + pub needs_runtime_store: bool, +} + +pub fn plan_thread_epiphany_view(params: ThreadEpiphanyViewParams) -> EpiphanyViewRoutePlan { + let ThreadEpiphanyViewParams { thread_id, lenses } = params; + let lenses = if lenses.is_empty() { + default_core_epiphany_view_lenses() + } else { + protocol_view_lenses_to_core(lenses) + }; + EpiphanyViewRoutePlan { + thread_id, + needs_jobs: core_epiphany_view_needs_jobs(&lenses), + needs_reorientation_inputs: core_epiphany_view_needs_reorientation_inputs(&lenses), + needs_pressure: core_epiphany_view_needs_pressure(&lenses), + needs_runtime_store: core_epiphany_view_needs_runtime_store(&lenses), + lenses, + } +} + pub async fn map_epiphany_view_response( input: EpiphanyViewResponseInput<'_>, ) -> ThreadEpiphanyViewResponse { diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 001b0db4..c4ec9c6b 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -30,7 +30,7 @@ The spine exists in more than twenty-five live paths: - targeted context reflection: app-server declares experimental read-only `thread/epiphany/context`, reads the same live/stored Epiphany state view used by the view lenses, and derives a bounded state shard containing selected graph nodes/edges, links, active frontier, checkpoint, the full durable investigation-checkpoint packet, observations, direct evidence, linked evidence, and missing requested ids without retrieval, proposal, promotion, notification, mutation, or persistence in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:355), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4253), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4261), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11152). - graph traversal reflection: app-server declares experimental read-only `thread/epiphany/graphQuery`, reads the same live Epiphany state view used by context, and derives explicit node/edge lookup, path/symbol matches, bounded neighbors, edge-kind matches, and frontier neighborhoods with architecture/dataflow links plus frontier/checkpoint identity, matched selectors, and missing ids without retrieval, proposal, promotion, indexing, notification, mutation, or scheduling in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:379), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4720), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:5060), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15201). - planning reflection: the `planning` view lens reads the same live/stored Epiphany state view and adapts the core planning projection. `epiphany-core` returns typed captures, backlog items, roadmap streams, Objective Drafts, GitHub source refs, count summaries, and the separate active objective without adopting drafts, launching work, notifying, mutating, or scheduling in [planning.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/planning.rs:1). -- 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. +- 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. `epiphany-codex-bridge::view_protocol::plan_thread_epiphany_view` owns protocol lens conversion, default lens selection, and host-fact dependency planning; app-server only gathers the requested Codex host facts and passes them into the bridge response mapper. 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, 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). diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index beafd00a..fe6c9b64 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -823,14 +823,20 @@ now live in `epiphany-codex-bridge::view`. The same bridge view module now owns role/reorient result response construction too: it loads the mapped runtime-spine status/finding, projects the matching job, and builds `ThreadEpiphanyRoleResultResponse` / -`ThreadEpiphanyReorientResultResponse`. App-server keeps only role binding -validation, live/stored source selection, runtime-store path lookup, and -response emission for those compatibility verbs. `epiphany_read_routes.rs` is +`ThreadEpiphanyReorientResultResponse`. App-server keeps only live/stored state +loading, runtime-store path lookup, and response emission for those +compatibility verbs. `epiphany_read_routes.rs` is about 648 lines after these cuts. The remaining read-route bodies are mostly individual legacy read verbs (`roleResult`, `freshness`, `context`, `graphQuery`, `reorientResult`, `retrieve`, `distill`, `propose`) plus host loading and response/error shaping. +View route planning is bridge-owned at the route boundary now. App-server calls +`plan_thread_epiphany_view` to convert protocol lenses, apply default lenses, +and learn which host facts to gather. It no longer imports the raw +`core_epiphany_view_needs_*`, default-lens, or protocol-lens conversion helpers. +`epiphany_read_routes.rs` is about 516 lines after this cut. + Freshness/context/graph-query response construction is also bridge-owned now. `epiphany-codex-bridge::view` builds `ThreadEpiphanyFreshnessResponse`, `ThreadEpiphanyContextResponse`, and `ThreadEpiphanyGraphQueryResponse` from diff --git a/state/ledgers.cc b/state/ledgers.cc index 486c92b71c23b23c93ddb52ede83a22acaa17192..a6a3c2915cb1e2f59a8259a1f0b81a1b14d1ff2e 100644 GIT binary patch delta 289 zcmY*TKTE?v9QBTDfeI?v!Q!vDNsSHIrB32paqbeX$*;-5_3pe}Dp_=JaB;{IZgzGN z99%1EKaAjK(8SH{{o}p&^WayN|J)^hI2?~ort1y5{(ds>)q|I zXvZ6k!=VdTwCAz&!n&Iavb&`Uiy% id, @@ -65,10 +56,7 @@ impl CodexMessageProcessor { } }; - let needs_jobs = core_epiphany_view_needs_jobs(&lenses); - let needs_reorientation_inputs = core_epiphany_view_needs_reorientation_inputs(&lenses); - let needs_pressure = core_epiphany_view_needs_pressure(&lenses); - let retrieval_override = if (needs_jobs || needs_reorientation_inputs) + let retrieval_override = if (view_plan.needs_jobs || view_plan.needs_reorientation_inputs) && thread .epiphany_state .as_ref() @@ -83,7 +71,7 @@ impl CodexMessageProcessor { } else { None }; - let watcher_snapshot = if needs_reorientation_inputs { + let watcher_snapshot = if view_plan.needs_reorientation_inputs { if let Some(loaded_thread) = loaded_thread.as_ref() { let config_snapshot = loaded_thread.config_snapshot().await; self.epiphany_invalidation_manager @@ -100,7 +88,7 @@ impl CodexMessageProcessor { } else { None }; - let token_usage_info = if needs_pressure { + let token_usage_info = if view_plan.needs_pressure { if let Some(loaded_thread) = loaded_thread.as_ref() { loaded_thread.token_usage_info().await } else { @@ -112,7 +100,7 @@ impl CodexMessageProcessor { } else { None }; - let runtime_store_path = if core_epiphany_view_needs_runtime_store(&lenses) { + let runtime_store_path = if view_plan.needs_runtime_store { if let Some(loaded_thread) = loaded_thread.as_ref() { Some(loaded_thread.epiphany_runtime_spine_store_path().await) } else { @@ -124,7 +112,7 @@ impl CodexMessageProcessor { let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref()); let response = map_epiphany_view_response(EpiphanyViewResponseInput { thread_id: thread_id.clone(), - lenses, + lenses: view_plan.lenses, loaded, state: thread.epiphany_state.as_ref(), retrieval_override: retrieval_override.as_ref(),