From 3c96fdee4d3018e3c43046a80dc653697e20ac07 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 10:13:41 +0100 Subject: [PATCH] Move read response projections into bridge --- epiphany-codex-bridge/src/view.rs | 78 ++++++++++++++++++ notes/fresh-workspace-handoff.md | 7 ++ state/ledgers.msgpack | Bin 90624 -> 90907 bytes state/map.yaml | 2 +- .../epiphany_read_routes.rs | 70 +++++----------- 5 files changed, 107 insertions(+), 50 deletions(-) diff --git a/epiphany-codex-bridge/src/view.rs b/epiphany-codex-bridge/src/view.rs index d01e28ea..b8c174dc 100644 --- a/epiphany-codex-bridge/src/view.rs +++ b/epiphany-codex-bridge/src/view.rs @@ -7,6 +7,8 @@ use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo; use epiphany_core::EpiphanySceneInput; use epiphany_core::derive_scene; +use crate::context::map_epiphany_context; +use crate::context::map_epiphany_graph_query; use crate::context::map_epiphany_planning; use crate::coordinator::derive_epiphany_coordinator_status; use crate::coordinator::epiphany_reorient_finding_already_accepted; @@ -63,6 +65,82 @@ pub fn epiphany_view_needs_runtime_store(lenses: &[ThreadEpiphanyViewLens]) -> b || lenses.contains(&ThreadEpiphanyViewLens::Coordinator) } +pub struct EpiphanyFreshnessResponseInput<'a> { + pub thread_id: String, + pub loaded: bool, + pub state: Option<&'a EpiphanyThreadState>, + pub retrieval_override: Option<&'a EpiphanyRetrievalState>, + pub watcher_snapshot: Option>, +} + +pub fn map_epiphany_freshness_response( + input: EpiphanyFreshnessResponseInput<'_>, +) -> ThreadEpiphanyFreshnessResponse { + let (state_revision, retrieval, graph, watcher) = map_epiphany_freshness( + input.state, + input.retrieval_override, + input.watcher_snapshot, + ); + ThreadEpiphanyFreshnessResponse { + thread_id: input.thread_id, + source: if input.loaded { + ThreadEpiphanyFreshnessSource::Live + } else { + ThreadEpiphanyFreshnessSource::Stored + }, + state_revision, + retrieval, + graph, + watcher, + } +} + +pub fn map_epiphany_context_response( + thread_id: String, + loaded: bool, + state: Option<&EpiphanyThreadState>, + params: &ThreadEpiphanyContextParams, +) -> ThreadEpiphanyContextResponse { + let (state_status, state_revision, context, missing) = map_epiphany_context(state, params); + ThreadEpiphanyContextResponse { + thread_id, + source: if loaded { + ThreadEpiphanyContextSource::Live + } else { + ThreadEpiphanyContextSource::Stored + }, + state_status, + state_revision, + context, + missing, + } +} + +pub fn map_epiphany_graph_query_response( + thread_id: String, + loaded: bool, + state: Option<&EpiphanyThreadState>, + query: &ThreadEpiphanyGraphQuery, +) -> ThreadEpiphanyGraphQueryResponse { + let (state_status, state_revision, graph, frontier, checkpoint, matched, missing) = + map_epiphany_graph_query(state, query); + ThreadEpiphanyGraphQueryResponse { + thread_id, + source: if loaded { + ThreadEpiphanyContextSource::Live + } else { + ThreadEpiphanyContextSource::Stored + }, + state_status, + state_revision, + graph, + frontier, + checkpoint, + matched, + missing, + } +} + pub struct EpiphanyViewResponseInput<'a> { pub thread_id: String, pub lenses: Vec, diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 0cd496b0..b2186361 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -715,6 +715,13 @@ legacy read verbs (`roleResult`, `freshness`, `context`, `graphQuery`, `reorientResult`, `retrieve`, `distill`, `propose`) plus host loading and response/error shaping. +Freshness/context/graph-query response construction is also bridge-owned now. +`epiphany-codex-bridge::view` builds `ThreadEpiphanyFreshnessResponse`, +`ThreadEpiphanyContextResponse`, and `ThreadEpiphanyGraphQueryResponse` from +typed state plus host-supplied watcher/retrieval inputs. App-server still owns +loading and watcher registration because those are host lifecycle seams. +`epiphany_read_routes.rs` is about 620 lines after this cut. + 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 intent/result/receipt documents internally and normal MCP JSON-RPC externally. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 2a195a47ba5515f71049db4742603e66c2197008..6f3c3e6e10de25a20085e146649c9cbaa2dfd537 100644 GIT binary patch delta 197 zcmZoT!aDmH>jY({q=y?-r!g|VY2L%QeGem}Ucz+CI7UG>ODjWTD}%|7tF%;a-tf&Y zOHENoD@rZS$V)9Q)=$pQD@m;=(N8Z*EXdF;EKMz{oUWV5Xdb6fo{^c8s!#w_nOanq znU}7RSWut~Vy6}<IcBxe8xi&E1wi%W_UOEUBG6cY1N6f*LQ rOB6~nic%9(6ms$tQ-Fr(DTJjKWu|3L|ESL>GW}j6qYN9!aVAj!ZR|*7 delta 38 ucmbPzjJ4qi>jY({#A6#(r!g|VZr;PVeGem}Ucz+NWJUot15+ylqbL9y;tZJp diff --git a/state/map.yaml b/state/map.yaml index 4e04841c..0052443a 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -279,5 +279,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, twenty-one processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation/view/coordinator projection services in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, full `thread/epiphany/view` response construction, role/reorient result response construction, coordinator status/view construction, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission, but its root no longer imports the evacuated Epiphany policy/protocol registry. `epiphany_read_routes.rs` is about 648 lines after the full view and result-response extractions; `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move; `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader; and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-mvp-coordinator` now invokes `epiphany-openai-runtime run-worker` for launched runtime job ids and no longer creates a second coordinator-owned shadow runtime job/result as a compensator. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. Vendored `codex-core` no longer has `epiphany_distillation`, `epiphany_promotion`, `epiphany_proposal`, `epiphany_retrieval`, or `epiphany_rollout` husk modules; it re-exports native surfaces from `epiphany-core` directly, and the only rollout adapter left is the real host seam that supplies Codex's turn-boundary predicate. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move. + summary: The Codex starvation pass has five typing receipts, twenty-two processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation/view/coordinator projection services in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, full `thread/epiphany/view` response construction, freshness/context/graph-query response construction, role/reorient result response construction, coordinator status/view construction, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission, but its root no longer imports the evacuated Epiphany policy/protocol registry. `epiphany_read_routes.rs` is about 620 lines after the full view and read-response extractions; `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move; `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader; and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-mvp-coordinator` now invokes `epiphany-openai-runtime run-worker` for launched runtime job ids and no longer creates a second coordinator-owned shadow runtime job/result as a compensator. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. Vendored `codex-core` no longer has `epiphany_distillation`, `epiphany_promotion`, `epiphany_proposal`, `epiphany_retrieval`, or `epiphany_rollout` husk modules; it re-exports native surfaces from `epiphany-core` directly, and the only rollout adapter left is the real host seam that supplies Codex's turn-boundary predicate. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move. next_action: Move remaining coordinator/runtime execution and operator surfaces off app-server JSON-RPC where possible, then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs index 7e45224f..21ae10c4 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_read_routes.rs @@ -6,12 +6,10 @@ use codex_core::EpiphanyMapProposalInput; use codex_core::EpiphanyRetrieveQuery; use codex_core::distill_observation; use codex_protocol::ThreadId; -use epiphany_codex_bridge::context::map_epiphany_context; -use epiphany_codex_bridge::context::map_epiphany_graph_query; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; use epiphany_codex_bridge::launch::epiphany_role_binding_id; -use epiphany_codex_bridge::reorient::map_epiphany_freshness; use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_response; +use epiphany_codex_bridge::view::EpiphanyFreshnessResponseInput; use epiphany_codex_bridge::view::EpiphanyReorientResultResponseInput; use epiphany_codex_bridge::view::EpiphanyRoleResultResponseInput; use epiphany_codex_bridge::view::EpiphanyViewResponseInput; @@ -20,6 +18,9 @@ use epiphany_codex_bridge::view::epiphany_view_needs_jobs; use epiphany_codex_bridge::view::epiphany_view_needs_pressure; use epiphany_codex_bridge::view::epiphany_view_needs_reorientation_inputs; use epiphany_codex_bridge::view::epiphany_view_needs_runtime_store; +use epiphany_codex_bridge::view::map_epiphany_context_response; +use epiphany_codex_bridge::view::map_epiphany_freshness_response; +use epiphany_codex_bridge::view::map_epiphany_graph_query_response; use epiphany_codex_bridge::view::map_epiphany_reorient_result_response; use epiphany_codex_bridge::view::map_epiphany_role_result_response; use epiphany_codex_bridge::view::map_epiphany_view_response; @@ -257,25 +258,15 @@ impl CodexMessageProcessor { } else { None }; - let (state_revision, retrieval, graph, watcher) = map_epiphany_freshness( - thread.epiphany_state.as_ref(), - retrieval_override.as_ref(), - watcher_snapshot + let response = map_epiphany_freshness_response(EpiphanyFreshnessResponseInput { + thread_id, + loaded: loaded_thread.is_some(), + state: thread.epiphany_state.as_ref(), + retrieval_override: retrieval_override.as_ref(), + watcher_snapshot: watcher_snapshot .as_ref() .map(epiphany_freshness_watcher_snapshot), - ); - let response = ThreadEpiphanyFreshnessResponse { - thread_id, - source: if loaded_thread.is_some() { - ThreadEpiphanyFreshnessSource::Live - } else { - ThreadEpiphanyFreshnessSource::Stored - }, - state_revision, - retrieval, - graph, - watcher, - }; + }); self.outgoing.send_response(request_id, response).await; } @@ -307,20 +298,12 @@ impl CodexMessageProcessor { } }; - let (state_status, state_revision, context, missing) = - map_epiphany_context(thread.epiphany_state.as_ref(), ¶ms); - let response = ThreadEpiphanyContextResponse { + let response = map_epiphany_context_response( thread_id, - source: if loaded { - ThreadEpiphanyContextSource::Live - } else { - ThreadEpiphanyContextSource::Stored - }, - state_status, - state_revision, - context, - missing, - }; + loaded, + thread.epiphany_state.as_ref(), + ¶ms, + ); self.outgoing.send_response(request_id, response).await; } @@ -352,23 +335,12 @@ impl CodexMessageProcessor { } }; - let (state_status, state_revision, graph, frontier, checkpoint, matched, missing) = - map_epiphany_graph_query(thread.epiphany_state.as_ref(), ¶ms.query); - let response = ThreadEpiphanyGraphQueryResponse { + let response = map_epiphany_graph_query_response( thread_id, - source: if loaded { - ThreadEpiphanyContextSource::Live - } else { - ThreadEpiphanyContextSource::Stored - }, - state_status, - state_revision, - graph, - frontier, - checkpoint, - matched, - missing, - }; + loaded, + thread.epiphany_state.as_ref(), + ¶ms.query, + ); self.outgoing.send_response(request_id, response).await; }