From b719cfe03d9104e204102967868671f2c686fe94 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 20 May 2026 15:00:12 +0100 Subject: [PATCH] Split context protocol projection --- epiphany-codex-bridge/src/context.rs | 199 ++---------------- epiphany-codex-bridge/src/context_protocol.rs | 155 ++++++++++++++ epiphany-codex-bridge/src/lib.rs | 1 + epiphany-codex-bridge/src/view.rs | 17 +- notes/fresh-workspace-handoff.md | 1 + state/ledgers.msgpack | Bin 145309 -> 145538 bytes state/map.yaml | 4 + 7 files changed, 184 insertions(+), 193 deletions(-) create mode 100644 epiphany-codex-bridge/src/context_protocol.rs diff --git a/epiphany-codex-bridge/src/context.rs b/epiphany-codex-bridge/src/context.rs index e92f8a07..b1d4e3ce 100644 --- a/epiphany-codex-bridge/src/context.rs +++ b/epiphany-codex-bridge/src/context.rs @@ -1,202 +1,27 @@ -use codex_app_server_protocol::ThreadEpiphanyContext; -use codex_app_server_protocol::ThreadEpiphanyContextMissing; -use codex_app_server_protocol::ThreadEpiphanyContextStateStatus; -use codex_app_server_protocol::ThreadEpiphanyGraphContext; -use codex_app_server_protocol::ThreadEpiphanyGraphQueryMatched; -use codex_app_server_protocol::ThreadEpiphanyGraphQueryMissing; -use codex_app_server_protocol::ThreadEpiphanyPlanningSummary; -use epiphany_core::EpiphanyContext as CoreEpiphanyContext; -use epiphany_core::EpiphanyContextMissing as CoreEpiphanyContextMissing; -use epiphany_core::EpiphanyContextParams as CoreEpiphanyContextParams; -use epiphany_core::EpiphanyContextStateStatus as CoreEpiphanyContextStateStatus; +use epiphany_core::EpiphanyContextParams; use epiphany_core::EpiphanyContextView; -use epiphany_core::EpiphanyGraphContext as CoreEpiphanyGraphContext; -use epiphany_core::EpiphanyGraphQuery as CoreEpiphanyGraphQuery; -use epiphany_core::EpiphanyGraphQueryMatched as CoreEpiphanyGraphQueryMatched; -use epiphany_core::EpiphanyGraphQueryMissing as CoreEpiphanyGraphQueryMissing; +use epiphany_core::EpiphanyGraphQuery; use epiphany_core::EpiphanyGraphQueryView; -use epiphany_core::EpiphanyPlanningStateStatus as CoreEpiphanyPlanningStateStatus; -use epiphany_core::EpiphanyPlanningSummary as CoreEpiphanyPlanningSummary; use epiphany_core::EpiphanyPlanningView; use epiphany_core::derive_context; use epiphany_core::derive_graph_query; use epiphany_core::derive_planning_view; -use epiphany_state_model::EpiphanyGraphCheckpoint; -use epiphany_state_model::EpiphanyGraphFrontier; -use epiphany_state_model::EpiphanyPlanningState; use epiphany_state_model::EpiphanyThreadState; -pub fn map_epiphany_context( +pub fn derive_epiphany_context( state: Option<&EpiphanyThreadState>, - params: &CoreEpiphanyContextParams, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - ThreadEpiphanyContext, - ThreadEpiphanyContextMissing, -) { - map_core_epiphany_context_view(derive_context(state, params)) + params: &EpiphanyContextParams, +) -> EpiphanyContextView { + derive_context(state, params) } -fn map_core_epiphany_context_view( - view: EpiphanyContextView, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - ThreadEpiphanyContext, - ThreadEpiphanyContextMissing, -) { - ( - map_core_epiphany_context_state_status(view.state_status), - view.state_revision, - map_core_epiphany_context(view.context), - map_core_epiphany_context_missing(view.missing), - ) +pub fn derive_epiphany_planning(state: Option<&EpiphanyThreadState>) -> EpiphanyPlanningView { + derive_planning_view(state) } -fn map_core_epiphany_context_state_status( - status: CoreEpiphanyContextStateStatus, -) -> ThreadEpiphanyContextStateStatus { - match status { - CoreEpiphanyContextStateStatus::Missing => ThreadEpiphanyContextStateStatus::Missing, - CoreEpiphanyContextStateStatus::Ready => ThreadEpiphanyContextStateStatus::Ready, - } -} - -fn map_core_epiphany_context(context: CoreEpiphanyContext) -> ThreadEpiphanyContext { - ThreadEpiphanyContext { - graph: map_core_epiphany_graph_context(context.graph), - frontier: context.frontier, - checkpoint: context.checkpoint, - investigation_checkpoint: context.investigation_checkpoint, - observations: context.observations, - evidence: context.evidence, - } -} - -fn map_core_epiphany_graph_context(graph: CoreEpiphanyGraphContext) -> ThreadEpiphanyGraphContext { - ThreadEpiphanyGraphContext { - architecture_nodes: graph.architecture_nodes, - architecture_edges: graph.architecture_edges, - dataflow_nodes: graph.dataflow_nodes, - dataflow_edges: graph.dataflow_edges, - links: graph.links, - } -} - -fn map_core_epiphany_context_missing( - missing: CoreEpiphanyContextMissing, -) -> ThreadEpiphanyContextMissing { - ThreadEpiphanyContextMissing { - graph_node_ids: missing.graph_node_ids, - graph_edge_ids: missing.graph_edge_ids, - observation_ids: missing.observation_ids, - evidence_ids: missing.evidence_ids, - } -} - -pub fn map_epiphany_planning( +pub fn derive_epiphany_graph_query( state: Option<&EpiphanyThreadState>, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - EpiphanyPlanningState, - ThreadEpiphanyPlanningSummary, -) { - let view = derive_planning_view(state); - map_core_epiphany_planning_view(view) -} - -fn map_core_epiphany_planning_view( - view: EpiphanyPlanningView, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - EpiphanyPlanningState, - ThreadEpiphanyPlanningSummary, -) { - ( - match view.state_status { - CoreEpiphanyPlanningStateStatus::Missing => ThreadEpiphanyContextStateStatus::Missing, - CoreEpiphanyPlanningStateStatus::Ready => ThreadEpiphanyContextStateStatus::Ready, - }, - view.state_revision, - view.planning, - map_core_epiphany_planning_summary(view.summary), - ) -} - -fn map_core_epiphany_planning_summary( - summary: CoreEpiphanyPlanningSummary, -) -> ThreadEpiphanyPlanningSummary { - ThreadEpiphanyPlanningSummary { - capture_count: summary.capture_count, - pending_capture_count: summary.pending_capture_count, - github_issue_capture_count: summary.github_issue_capture_count, - backlog_item_count: summary.backlog_item_count, - ready_backlog_item_count: summary.ready_backlog_item_count, - roadmap_stream_count: summary.roadmap_stream_count, - objective_draft_count: summary.objective_draft_count, - draft_objective_count: summary.draft_objective_count, - active_objective: summary.active_objective, - note: summary.note, - } -} - -pub fn map_epiphany_graph_query( - state: Option<&EpiphanyThreadState>, - query: &CoreEpiphanyGraphQuery, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - ThreadEpiphanyGraphContext, - Option, - Option, - ThreadEpiphanyGraphQueryMatched, - ThreadEpiphanyGraphQueryMissing, -) { - map_core_epiphany_graph_query_view(derive_graph_query(state, query)) -} - -fn map_core_epiphany_graph_query_view( - view: EpiphanyGraphQueryView, -) -> ( - ThreadEpiphanyContextStateStatus, - Option, - ThreadEpiphanyGraphContext, - Option, - Option, - ThreadEpiphanyGraphQueryMatched, - ThreadEpiphanyGraphQueryMissing, -) { - ( - map_core_epiphany_context_state_status(view.state_status), - view.state_revision, - map_core_epiphany_graph_context(view.graph), - view.frontier, - view.checkpoint, - map_core_epiphany_graph_query_matched(view.matched), - map_core_epiphany_graph_query_missing(view.missing), - ) -} - -fn map_core_epiphany_graph_query_matched( - matched: CoreEpiphanyGraphQueryMatched, -) -> ThreadEpiphanyGraphQueryMatched { - ThreadEpiphanyGraphQueryMatched { - node_ids: matched.node_ids, - edge_ids: matched.edge_ids, - paths: matched.paths, - symbols: matched.symbols, - edge_kinds: matched.edge_kinds, - } -} - -fn map_core_epiphany_graph_query_missing( - missing: CoreEpiphanyGraphQueryMissing, -) -> ThreadEpiphanyGraphQueryMissing { - ThreadEpiphanyGraphQueryMissing { - node_ids: missing.node_ids, - edge_ids: missing.edge_ids, - } + query: &EpiphanyGraphQuery, +) -> EpiphanyGraphQueryView { + derive_graph_query(state, query) } diff --git a/epiphany-codex-bridge/src/context_protocol.rs b/epiphany-codex-bridge/src/context_protocol.rs new file mode 100644 index 00000000..949fab3a --- /dev/null +++ b/epiphany-codex-bridge/src/context_protocol.rs @@ -0,0 +1,155 @@ +use codex_app_server_protocol::ThreadEpiphanyContext; +use codex_app_server_protocol::ThreadEpiphanyContextMissing; +use codex_app_server_protocol::ThreadEpiphanyContextStateStatus; +use codex_app_server_protocol::ThreadEpiphanyGraphContext; +use codex_app_server_protocol::ThreadEpiphanyGraphQueryMatched; +use codex_app_server_protocol::ThreadEpiphanyGraphQueryMissing; +use codex_app_server_protocol::ThreadEpiphanyPlanningSummary; +use epiphany_core::EpiphanyContext as CoreEpiphanyContext; +use epiphany_core::EpiphanyContextMissing as CoreEpiphanyContextMissing; +use epiphany_core::EpiphanyContextStateStatus as CoreEpiphanyContextStateStatus; +use epiphany_core::EpiphanyContextView; +use epiphany_core::EpiphanyGraphContext as CoreEpiphanyGraphContext; +use epiphany_core::EpiphanyGraphQueryMatched as CoreEpiphanyGraphQueryMatched; +use epiphany_core::EpiphanyGraphQueryMissing as CoreEpiphanyGraphQueryMissing; +use epiphany_core::EpiphanyGraphQueryView; +use epiphany_core::EpiphanyPlanningStateStatus as CoreEpiphanyPlanningStateStatus; +use epiphany_core::EpiphanyPlanningSummary as CoreEpiphanyPlanningSummary; +use epiphany_core::EpiphanyPlanningView; +use epiphany_state_model::EpiphanyGraphCheckpoint; +use epiphany_state_model::EpiphanyGraphFrontier; +use epiphany_state_model::EpiphanyPlanningState; + +pub fn protocol_context_view( + view: EpiphanyContextView, +) -> ( + ThreadEpiphanyContextStateStatus, + Option, + ThreadEpiphanyContext, + ThreadEpiphanyContextMissing, +) { + ( + protocol_context_state_status(view.state_status), + view.state_revision, + protocol_context(view.context), + protocol_context_missing(view.missing), + ) +} + +pub fn protocol_context_state_status( + status: CoreEpiphanyContextStateStatus, +) -> ThreadEpiphanyContextStateStatus { + match status { + CoreEpiphanyContextStateStatus::Missing => ThreadEpiphanyContextStateStatus::Missing, + CoreEpiphanyContextStateStatus::Ready => ThreadEpiphanyContextStateStatus::Ready, + } +} + +fn protocol_context(context: CoreEpiphanyContext) -> ThreadEpiphanyContext { + ThreadEpiphanyContext { + graph: protocol_graph_context(context.graph), + frontier: context.frontier, + checkpoint: context.checkpoint, + investigation_checkpoint: context.investigation_checkpoint, + observations: context.observations, + evidence: context.evidence, + } +} + +pub fn protocol_graph_context(graph: CoreEpiphanyGraphContext) -> ThreadEpiphanyGraphContext { + ThreadEpiphanyGraphContext { + architecture_nodes: graph.architecture_nodes, + architecture_edges: graph.architecture_edges, + dataflow_nodes: graph.dataflow_nodes, + dataflow_edges: graph.dataflow_edges, + links: graph.links, + } +} + +fn protocol_context_missing(missing: CoreEpiphanyContextMissing) -> ThreadEpiphanyContextMissing { + ThreadEpiphanyContextMissing { + graph_node_ids: missing.graph_node_ids, + graph_edge_ids: missing.graph_edge_ids, + observation_ids: missing.observation_ids, + evidence_ids: missing.evidence_ids, + } +} + +pub fn protocol_planning_view( + view: EpiphanyPlanningView, +) -> ( + ThreadEpiphanyContextStateStatus, + Option, + EpiphanyPlanningState, + ThreadEpiphanyPlanningSummary, +) { + ( + match view.state_status { + CoreEpiphanyPlanningStateStatus::Missing => ThreadEpiphanyContextStateStatus::Missing, + CoreEpiphanyPlanningStateStatus::Ready => ThreadEpiphanyContextStateStatus::Ready, + }, + view.state_revision, + view.planning, + protocol_planning_summary(view.summary), + ) +} + +fn protocol_planning_summary( + summary: CoreEpiphanyPlanningSummary, +) -> ThreadEpiphanyPlanningSummary { + ThreadEpiphanyPlanningSummary { + capture_count: summary.capture_count, + pending_capture_count: summary.pending_capture_count, + github_issue_capture_count: summary.github_issue_capture_count, + backlog_item_count: summary.backlog_item_count, + ready_backlog_item_count: summary.ready_backlog_item_count, + roadmap_stream_count: summary.roadmap_stream_count, + objective_draft_count: summary.objective_draft_count, + draft_objective_count: summary.draft_objective_count, + active_objective: summary.active_objective, + note: summary.note, + } +} + +pub fn protocol_graph_query_view( + view: EpiphanyGraphQueryView, +) -> ( + ThreadEpiphanyContextStateStatus, + Option, + ThreadEpiphanyGraphContext, + Option, + Option, + ThreadEpiphanyGraphQueryMatched, + ThreadEpiphanyGraphQueryMissing, +) { + ( + protocol_context_state_status(view.state_status), + view.state_revision, + protocol_graph_context(view.graph), + view.frontier, + view.checkpoint, + protocol_graph_query_matched(view.matched), + protocol_graph_query_missing(view.missing), + ) +} + +fn protocol_graph_query_matched( + matched: CoreEpiphanyGraphQueryMatched, +) -> ThreadEpiphanyGraphQueryMatched { + ThreadEpiphanyGraphQueryMatched { + node_ids: matched.node_ids, + edge_ids: matched.edge_ids, + paths: matched.paths, + symbols: matched.symbols, + edge_kinds: matched.edge_kinds, + } +} + +fn protocol_graph_query_missing( + missing: CoreEpiphanyGraphQueryMissing, +) -> ThreadEpiphanyGraphQueryMissing { + ThreadEpiphanyGraphQueryMissing { + node_ids: missing.node_ids, + edge_ids: missing.edge_ids, + } +} diff --git a/epiphany-codex-bridge/src/lib.rs b/epiphany-codex-bridge/src/lib.rs index 08c2d393..95d3fafd 100644 --- a/epiphany-codex-bridge/src/lib.rs +++ b/epiphany-codex-bridge/src/lib.rs @@ -1,5 +1,6 @@ pub mod checkpoint; pub mod context; +pub mod context_protocol; pub mod coordinator; pub mod coordinator_protocol; pub mod cultnet; diff --git a/epiphany-codex-bridge/src/view.rs b/epiphany-codex-bridge/src/view.rs index 40205d08..67bfa692 100644 --- a/epiphany-codex-bridge/src/view.rs +++ b/epiphany-codex-bridge/src/view.rs @@ -19,9 +19,12 @@ use epiphany_core::reorient_finding_already_accepted; use epiphany_state_model::EpiphanyRetrievalState; use epiphany_state_model::EpiphanyThreadState; -use crate::context::map_epiphany_context; -use crate::context::map_epiphany_graph_query; -use crate::context::map_epiphany_planning; +use crate::context::derive_epiphany_context; +use crate::context::derive_epiphany_graph_query; +use crate::context::derive_epiphany_planning; +use crate::context_protocol::protocol_context_view; +use crate::context_protocol::protocol_graph_query_view; +use crate::context_protocol::protocol_planning_view; use crate::coordinator::derive_epiphany_coordinator_status; use crate::coordinator::map_epiphany_crrc_recommendation; use crate::coordinator::map_epiphany_roles; @@ -100,7 +103,8 @@ pub fn map_epiphany_context_response( state: Option<&EpiphanyThreadState>, params: &EpiphanyContextParams, ) -> ThreadEpiphanyContextResponse { - let (state_status, state_revision, context, missing) = map_epiphany_context(state, params); + let (state_status, state_revision, context, missing) = + protocol_context_view(derive_epiphany_context(state, params)); ThreadEpiphanyContextResponse { thread_id, source: if loaded { @@ -122,7 +126,7 @@ pub fn map_epiphany_graph_query_response( query: &EpiphanyGraphQuery, ) -> ThreadEpiphanyGraphQueryResponse { let (state_status, state_revision, graph, frontier, checkpoint, matched, missing) = - map_epiphany_graph_query(state, query); + protocol_graph_query_view(derive_epiphany_graph_query(state, query)); ThreadEpiphanyGraphQueryResponse { thread_id, source: if loaded { @@ -344,7 +348,8 @@ pub async fn map_epiphany_view_response( } }), planning: lenses.contains(&EpiphanyViewLens::Planning).then(|| { - let (state_status, state_revision, planning, summary) = map_epiphany_planning(state); + let (state_status, state_revision, planning, summary) = + protocol_planning_view(derive_epiphany_planning(state)); ThreadEpiphanyViewPlanning { thread_id: thread_id.clone(), source: if loaded { diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index eac87197..b5028c7e 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -88,6 +88,7 @@ remembers doctrine; the branch remembers the blade. - State-updated notification projection moved to the edge as well. `mutation.rs` now owns typed mutation/acceptance mechanics without importing app-server protocol DTOs. - `pressure.rs` is typed-only now. The convenience helper returning `ThreadEpiphanyPressure` was deleted; view response assembly derives typed pressure and calls `protocol_edge` for projection. - Coordinator projection is split out too. `coordinator.rs` no longer imports app-server protocol DTOs; it owns typed coordinator status, CRRC input shaping, role-board derivation, automation verdict selection, and note rendering. `coordinator_protocol.rs` owns Codex JSON-RPC projection for coordinator, CRRC, and role-board response payloads. +- Context/planning/graph projection is split out too. `context.rs` returns typed `epiphany-core` view documents; `context_protocol.rs` owns Codex JSON-RPC tuple/projection cargo for context, planning, and graph-query responses. - 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 bb212948c295b3d40615384f19fd01d7676a662e..c8896ada487e1a9e93120f5035bb1c8e19646c94 100644 GIT binary patch delta 181 zcmbRHo}=j_#{^|23y+Peg^Y}Anx`|iPiJJ@KAn;2qv`bdW=w*NmeUVrF-q6p+!kDr zlUbsWoS#>cT2Z23kdv5~mzkHYpI($$kfGq5pORXkP*9Ygm6}|VnV+YSnOBkzQydQz zFUe2N&(SL?wuT7;*$R32@$#!&!4IYQb1 delta 42 ycmZqr$T9al#{^|2^W=@Hg^Y}=o2N6jPiJJ@KAn;2qv`Zq3nqc-8_bwk7^47DLJlzi diff --git a/state/map.yaml b/state/map.yaml index 7e21d682..edc8c70e 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -432,6 +432,10 @@ current_status: derivation, automation verdict selection, and role-board note rendering; `coordinator_protocol.rs` owns Codex JSON-RPC projection for coordinator, CRRC, and role-board response payloads. + Context/planning/graph derivation is split the same way: + `context.rs` now returns typed `epiphany-core` view documents, while + `context_protocol.rs` owns the Codex JSON-RPC tuple/projection cargo used by + view/context/graph response builders. 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.