Split context protocol projection

This commit is contained in:
Meta Vens 2026-05-20 15:00:12 +01:00
commit b719cfe03d
7 changed files with 184 additions and 193 deletions

View file

@ -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<u64>,
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<u64>,
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<u64>,
EpiphanyPlanningState,
ThreadEpiphanyPlanningSummary,
) {
let view = derive_planning_view(state);
map_core_epiphany_planning_view(view)
}
fn map_core_epiphany_planning_view(
view: EpiphanyPlanningView,
) -> (
ThreadEpiphanyContextStateStatus,
Option<u64>,
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<u64>,
ThreadEpiphanyGraphContext,
Option<EpiphanyGraphFrontier>,
Option<EpiphanyGraphCheckpoint>,
ThreadEpiphanyGraphQueryMatched,
ThreadEpiphanyGraphQueryMissing,
) {
map_core_epiphany_graph_query_view(derive_graph_query(state, query))
}
fn map_core_epiphany_graph_query_view(
view: EpiphanyGraphQueryView,
) -> (
ThreadEpiphanyContextStateStatus,
Option<u64>,
ThreadEpiphanyGraphContext,
Option<EpiphanyGraphFrontier>,
Option<EpiphanyGraphCheckpoint>,
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)
}

View file

@ -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<u64>,
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<u64>,
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<u64>,
ThreadEpiphanyGraphContext,
Option<EpiphanyGraphFrontier>,
Option<EpiphanyGraphCheckpoint>,
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,
}
}

View file

@ -1,5 +1,6 @@
pub mod checkpoint;
pub mod context;
pub mod context_protocol;
pub mod coordinator;
pub mod coordinator_protocol;
pub mod cultnet;

View file

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

View file

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

Binary file not shown.

View file

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