From 431c56f52512c4e9380e478d0c46d04419da9aa1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 09:41:16 +0100 Subject: [PATCH] Move coordinator status derivation into bridge --- epiphany-codex-bridge/src/coordinator.rs | 180 +++++++++++++++++- notes/fresh-workspace-handoff.md | 11 ++ state/ledgers.msgpack | Bin 89679 -> 90038 bytes state/map.yaml | 4 +- .../app-server/src/codex_message_processor.rs | 99 ---------- .../epiphany_automation.rs | 99 ++-------- .../epiphany_read_routes.rs | 169 ++-------------- 7 files changed, 222 insertions(+), 340 deletions(-) diff --git a/epiphany-codex-bridge/src/coordinator.rs b/epiphany-codex-bridge/src/coordinator.rs index 7eb05d1c..2a070459 100644 --- a/epiphany-codex-bridge/src/coordinator.rs +++ b/epiphany-codex-bridge/src/coordinator.rs @@ -16,7 +16,9 @@ use codex_app_server_protocol::ThreadEpiphanyRoleId; use codex_app_server_protocol::ThreadEpiphanyRoleLane; use codex_app_server_protocol::ThreadEpiphanyRoleResultStatus; 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_protocol::protocol::EpiphanyAcceptanceReceipt; use codex_protocol::protocol::EpiphanyThreadState; use epiphany_core::EpiphanyCoordinatorAction as CoreEpiphanyCoordinatorAction; @@ -56,8 +58,12 @@ use crate::launch::EPIPHANY_MODELING_ROLE_BINDING_ID; use crate::launch::EPIPHANY_REORIENT_OWNER_ROLE; use crate::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; use crate::launch::epiphany_role_label; +use crate::launch::render_epiphany_coordinator_note; +use crate::mutation::epiphany_modeling_finding_has_reviewable_state_patch; +use crate::runtime_results::load_epiphany_role_result_snapshot; use std::collections::HashSet; +use std::path::Path; pub fn map_epiphany_crrc_recommendation( loaded: bool, @@ -174,6 +180,176 @@ pub struct EpiphanyCoordinatorDecision { pub reason: String, } +pub struct EpiphanyCoordinatorStatus { + pub decision: EpiphanyCoordinatorDecision, + pub source_signals: ThreadEpiphanyCoordinatorSignals, + pub roles: Vec, + pub note: String, + pub modeling_result_accepted: bool, + pub verification_result_accepted: bool, + pub reorient_finding_accepted: bool, +} + +pub async fn derive_epiphany_coordinator_status( + state: Option<&EpiphanyThreadState>, + runtime_store_path: Option<&Path>, + state_status: ThreadEpiphanyReorientStateStatus, + pressure: &ThreadEpiphanyPressure, + recommendation: &ThreadEpiphanyCrrcRecommendation, + roles: Vec, + reorient_decision: Option<&ThreadEpiphanyReorientDecision>, + reorient_result_status: ThreadEpiphanyReorientResultStatus, + reorient_finding: Option<&ThreadEpiphanyReorientFinding>, + checkpoint_present: bool, +) -> EpiphanyCoordinatorStatus { + let (modeling_result_status, modeling_finding, _) = if let Some(state) = state { + load_epiphany_role_result_snapshot( + state, + runtime_store_path, + ThreadEpiphanyRoleId::Modeling, + EPIPHANY_MODELING_ROLE_BINDING_ID, + ) + .await + } else { + ( + ThreadEpiphanyRoleResultStatus::MissingState, + None, + "No authoritative Epiphany state exists for this thread.".to_string(), + ) + }; + let modeling_result_accepted = modeling_finding.as_ref().is_some_and(|finding| { + state.is_some_and(|state| epiphany_role_finding_already_accepted(state, finding)) + }); + let modeling_result_reviewable = modeling_finding + .as_ref() + .is_some_and(epiphany_modeling_finding_has_reviewable_state_patch); + let (verification_result_status, verification_finding, _) = if let Some(state) = state { + load_epiphany_role_result_snapshot( + state, + runtime_store_path, + ThreadEpiphanyRoleId::Verification, + EPIPHANY_VERIFICATION_ROLE_BINDING_ID, + ) + .await + } else { + ( + ThreadEpiphanyRoleResultStatus::MissingState, + None, + "No authoritative Epiphany state exists for this thread.".to_string(), + ) + }; + let verification_result_accepted = verification_finding.as_ref().is_some_and(|finding| { + state.is_some_and(|state| epiphany_role_finding_already_accepted(state, finding)) + }); + let verification_result_covers_current_modeling = state.is_none_or(|state| { + epiphany_verification_finding_covers_current_modeling( + state, + modeling_result_accepted, + modeling_finding.as_ref(), + verification_finding.as_ref(), + ) + }); + let modeling_result_accepted_after_verification = state.is_some_and(|state| { + role_finding_accepted_after( + state, + modeling_finding.as_ref(), + verification_finding.as_ref(), + ) + }); + let implementation_evidence_after_verification = state.is_some_and(|state| { + implementation_evidence_after_role_finding(state, verification_finding.as_ref()) + }); + let verification_result_cites_implementation_evidence = state.is_some_and(|state| { + epiphany_role_finding_cites_implementation_evidence(state, verification_finding.as_ref()) + }); + let verification_result_allows_implementation = verification_result_accepted + && verification_finding + .as_ref() + .is_some_and(epiphany_verification_finding_allows_implementation); + let verification_result_needs_evidence = verification_result_accepted + && verification_finding + .as_ref() + .is_some_and(epiphany_verification_finding_needs_evidence); + let reorient_finding_accepted = reorient_finding.is_some_and(|finding| { + state.is_some_and(|state| epiphany_reorient_finding_already_accepted(state, finding)) + }); + let source_signals = ThreadEpiphanyCoordinatorSignals { + pressure_level: pressure.level, + should_prepare_compaction: pressure.should_prepare_compaction, + reorient_action: reorient_decision + .map(|decision| decision.action) + .unwrap_or(ThreadEpiphanyReorientAction::Resume), + crrc_action: recommendation.action, + modeling_result_status, + verification_result_status, + reorient_result_status, + }; + let decision = map_epiphany_coordinator( + state_status, + checkpoint_present, + pressure, + recommendation, + &roles, + &source_signals, + modeling_result_accepted, + modeling_result_reviewable, + modeling_result_accepted_after_verification, + implementation_evidence_after_verification, + verification_result_cites_implementation_evidence, + verification_result_covers_current_modeling, + verification_result_accepted, + verification_result_allows_implementation, + verification_result_needs_evidence, + reorient_finding_accepted, + ); + let note = render_epiphany_coordinator_note( + recommendation.action, + pressure.level, + modeling_result_status, + verification_result_status, + reorient_result_status, + decision.action, + ); + + EpiphanyCoordinatorStatus { + decision, + source_signals, + roles, + note, + modeling_result_accepted, + verification_result_accepted, + reorient_finding_accepted, + } +} + +pub fn map_epiphany_coordinator_view( + thread_id: String, + loaded: bool, + state_status: ThreadEpiphanyReorientStateStatus, + state_revision: Option, + status: EpiphanyCoordinatorStatus, +) -> ThreadEpiphanyViewCoordinator { + ThreadEpiphanyViewCoordinator { + thread_id, + source: if loaded { + ThreadEpiphanyRolesSource::Live + } else { + ThreadEpiphanyRolesSource::Stored + }, + state_status, + state_revision, + action: status.decision.action, + target_role: status.decision.target_role, + recommended_scene_action: status.decision.recommended_scene_action, + requires_review: status.decision.requires_review, + can_auto_run: status.decision.can_auto_run, + reason: status.decision.reason, + source_signals: status.source_signals, + roles: status.roles, + note: status.note, + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum EpiphanyCoordinatorAutomationAction { None, @@ -715,9 +891,7 @@ pub fn epiphany_verification_finding_allows_implementation( .is_some_and(|verdict| verdict.eq_ignore_ascii_case("pass")) } -pub fn epiphany_verification_finding_needs_evidence( - finding: &ThreadEpiphanyRoleFinding, -) -> bool { +pub fn epiphany_verification_finding_needs_evidence(finding: &ThreadEpiphanyRoleFinding) -> bool { finding.role_id == ThreadEpiphanyRoleId::Verification && finding .verdict diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 2826cef7..397ec8ce 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -687,6 +687,17 @@ adapter consolidation, not a new architectural throne: app-server still owns JSON-RPC response shape and watcher/thread-view details while the bridge owns route-independent Epiphany work. +The coordinator projection cut has also landed. The duplicated modeling / +verification / reorient acceptance and source-signal derivation that lived in +both `epiphany_read_routes.rs` and `epiphany_automation.rs` now lives in +`epiphany-codex-bridge::coordinator::derive_epiphany_coordinator_status`, with +`map_epiphany_coordinator_view` shaping the protocol view. App-server still +loads live thread state, watcher snapshots, token pressure, and runtime-store +paths, then emits JSON-RPC responses or safe-boundary notifications; it no +longer owns that coordinator policy. The root `codex_message_processor.rs` +imports for the evacuated Epiphany protocol/policy registry were cut as proof +that those names no longer belong to the host file. + 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 bef56b9f2c20777b7c75e446ec2cc919fb320f99..5d6148fc0237521e14439305f45a4201188500d5 100644 GIT binary patch delta 300 zcmYk2u}T9$6h#>!X{;=?5#d3w5#p|i28oreU}qHqI_$h;2a|c@ytf+y3W7f%2-&|7 z1kq+e|G?f45c~maN7C4x;#@e~kGk>l*0^u2oL@g}FO>SetJQ0*)XlK^IaX`U!~TBS z?>t;BcJfcvI;9c~n8HtNrX^xV6pVFRC;*F=f|JtX3=9TaYO&;i3IQ5HiOx`n6YYJQ zF_ah}pf-svgr-Y1L>IYw?5WL*qyM6#8IYUIVXP&`z>pIQSmz62(9Qr(ZKQzg$uV-` zNbKmZF%~e4Vx8n#z*7vL1EZc+?@hH)Z4K0F^>w1wTbT}Hf-J}El6P;PJ87raP7m69 L-LrK0L3i*AGgNHh delta 49 zcmdnCpY{A6)(Of?aiSYlr!g|VXx_uPeGemJZH!pM79#^AGhG8yT|?s#0}Crdb1PHh FC;+|l52yeD diff --git a/state/map.yaml b/state/map.yaml index 29d6444c..001eb53a 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -106,7 +106,7 @@ accepted_design: - `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding; catalog is auspex output, not doctrine. - Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path. - `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, scene projection, freshness derivation, pressure derivation, job/progress view derivation, planning view derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible. - - Vendored Codex keeps the thin typed host seam: protocol types, thread bridges, app-server protocol, request routing, and rollout integration. + - Vendored Codex keeps the thin typed host seam: protocol types, thread bridges, app-server protocol, request routing, watcher lifecycle, notifications, and rollout integration. Epiphany projection and coordinator policy should keep moving into `epiphany-core` / `epiphany-codex-bridge` instead of living in `codex_message_processor.rs`. - The current algorithmic map is the source-grounded description of live control flow. - Compact-Rehydrate-Reorient-Continue is an architecture primitive; automatic runtime coordination is not landed yet. - Context pressure must become an explicit runtime signal for automatic CRRC; inference from transcript vibes, user warnings, or shrinking safe scope is useful only as a temporary human/agent heuristic. @@ -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, eighteen 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 service 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, 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. The processor is about 10,339 lines, `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, nineteen 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/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, 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. The processor was about 10,339 lines before the coordinator extraction, `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.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs index 5831c31d..2376b918 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs @@ -156,48 +156,8 @@ use codex_app_server_protocol::ThreadCompactStartParams; use codex_app_server_protocol::ThreadCompactStartResponse; use codex_app_server_protocol::ThreadDecrementElicitationParams; use codex_app_server_protocol::ThreadDecrementElicitationResponse; -use codex_app_server_protocol::ThreadEpiphanyContext; -use codex_app_server_protocol::ThreadEpiphanyContextParams; -use codex_app_server_protocol::ThreadEpiphanyContextStateStatus; -use codex_app_server_protocol::ThreadEpiphanyCoordinatorAction; -use codex_app_server_protocol::ThreadEpiphanyCoordinatorSignals; -use codex_app_server_protocol::ThreadEpiphanyCrrcAction; -use codex_app_server_protocol::ThreadEpiphanyCrrcRecommendation; -use codex_app_server_protocol::ThreadEpiphanyGraphFreshness; -use codex_app_server_protocol::ThreadEpiphanyGraphFreshnessStatus; -use codex_app_server_protocol::ThreadEpiphanyGraphQuery; -use codex_app_server_protocol::ThreadEpiphanyGraphQueryDirection; -use codex_app_server_protocol::ThreadEpiphanyGraphQueryKind; -use codex_app_server_protocol::ThreadEpiphanyInvalidationInput; -use codex_app_server_protocol::ThreadEpiphanyInvalidationStatus; -use codex_app_server_protocol::ThreadEpiphanyJob; -use codex_app_server_protocol::ThreadEpiphanyJobKind; -use codex_app_server_protocol::ThreadEpiphanyJobStatus; -use codex_app_server_protocol::ThreadEpiphanyPressure; -use codex_app_server_protocol::ThreadEpiphanyPressureLevel; -use codex_app_server_protocol::ThreadEpiphanyReorientAction; -use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus; -use codex_app_server_protocol::ThreadEpiphanyReorientDecision; -use codex_app_server_protocol::ThreadEpiphanyReorientFinding; -use codex_app_server_protocol::ThreadEpiphanyReorientReason; -use codex_app_server_protocol::ThreadEpiphanyReorientResultStatus; -use codex_app_server_protocol::ThreadEpiphanyReorientStateStatus; -use codex_app_server_protocol::ThreadEpiphanyRetrievalFreshness; -use codex_app_server_protocol::ThreadEpiphanyRetrievalFreshnessStatus; #[cfg(test)] use codex_app_server_protocol::ThreadEpiphanyRetrieveResultKind; -use codex_app_server_protocol::ThreadEpiphanyRoleId; -use codex_app_server_protocol::ThreadEpiphanyRoleLane; -use codex_app_server_protocol::ThreadEpiphanyRoleResultStatus; -use codex_app_server_protocol::ThreadEpiphanyRoleSelfPersistenceStatus; -use codex_app_server_protocol::ThreadEpiphanyRoleStatus; -use codex_app_server_protocol::ThreadEpiphanySceneAction; -use codex_app_server_protocol::ThreadEpiphanySceneGraph; -use codex_app_server_protocol::ThreadEpiphanySceneSource; -use codex_app_server_protocol::ThreadEpiphanySceneStateStatus; -use codex_app_server_protocol::ThreadEpiphanySceneStatusCount; -use codex_app_server_protocol::ThreadEpiphanyStateUpdatedField; -use codex_app_server_protocol::ThreadEpiphanyUpdatePatch; use codex_app_server_protocol::ThreadForkParams; use codex_app_server_protocol::ThreadForkResponse; use codex_app_server_protocol::ThreadIncrementElicitationParams; @@ -367,13 +327,6 @@ use codex_protocol::protocol::ConversationAudioParams; use codex_protocol::protocol::ConversationStartParams; use codex_protocol::protocol::ConversationStartTransport; use codex_protocol::protocol::ConversationTextParams; -use codex_protocol::protocol::EpiphanyAcceptanceReceipt; -use codex_protocol::protocol::EpiphanyEvidenceRecord; -use codex_protocol::protocol::EpiphanyInvestigationCheckpoint; -use codex_protocol::protocol::EpiphanyInvestigationDisposition; -use codex_protocol::protocol::EpiphanyRetrievalState; -use codex_protocol::protocol::EpiphanyRetrievalStatus; -use codex_protocol::protocol::EpiphanyThreadState; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::GitInfo as CoreGitInfo; use codex_protocol::protocol::InitialHistory; @@ -388,7 +341,6 @@ use codex_protocol::protocol::ReviewTarget as CoreReviewTarget; use codex_protocol::protocol::RolloutItem; use codex_protocol::protocol::SessionConfiguredEvent; use codex_protocol::protocol::SessionMetaLine; -use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo; use codex_protocol::protocol::TurnEnvironmentSelection; use codex_protocol::protocol::USER_MESSAGE_BEGIN; use codex_protocol::protocol::W3cTraceContext; @@ -416,59 +368,8 @@ use codex_thread_store::ThreadStoreError; use codex_thread_store::UpdateThreadMetadataParams as StoreUpdateThreadMetadataParams; use codex_utils_absolute_path::AbsolutePathBuf; use codex_utils_pty::DEFAULT_OUTPUT_BYTES_CAP; -use epiphany_codex_bridge::context::map_epiphany_context; -use epiphany_codex_bridge::context::map_epiphany_graph_query; -use epiphany_codex_bridge::context::map_epiphany_planning; -use epiphany_codex_bridge::coordinator::EpiphanyCoordinatorAutomationAction; -use epiphany_codex_bridge::coordinator::EpiphanyCoordinatorDecision; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_accepted_evidence_id; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_already_accepted; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_covers_current_modeling; -use epiphany_codex_bridge::coordinator::implementation_evidence_after_role_finding; -use epiphany_codex_bridge::coordinator::map_epiphany_coordinator; -use epiphany_codex_bridge::coordinator::map_epiphany_coordinator_automation_action; -use epiphany_codex_bridge::coordinator::map_epiphany_crrc_recommendation; -use epiphany_codex_bridge::coordinator::map_epiphany_roles; -use epiphany_codex_bridge::coordinator::role_finding_accepted_after; -use epiphany_codex_bridge::coordinator::select_epiphany_coordinator_automation_action; -use epiphany_codex_bridge::jobs::map_epiphany_jobs; -use epiphany_codex_bridge::launch::EPIPHANY_IMAGINATION_OWNER_ROLE; -use epiphany_codex_bridge::launch::EPIPHANY_IMAGINATION_ROLE_BINDING_ID; -use epiphany_codex_bridge::launch::EPIPHANY_MODELING_OWNER_ROLE; -use epiphany_codex_bridge::launch::EPIPHANY_MODELING_ROLE_BINDING_ID; -use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; -use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_OWNER_ROLE; -use epiphany_codex_bridge::launch::EPIPHANY_VERIFICATION_OWNER_ROLE; -use epiphany_codex_bridge::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; -use epiphany_codex_bridge::launch::build_epiphany_reorient_launch_instruction; -use epiphany_codex_bridge::launch::build_epiphany_reorient_launch_request; -use epiphany_codex_bridge::launch::build_epiphany_role_launch_request; -use epiphany_codex_bridge::launch::epiphany_reorient_launch_output_schema; -use epiphany_codex_bridge::launch::epiphany_role_launch_output_schema; -use epiphany_codex_bridge::launch::epiphany_specialist_prompt_config; -use epiphany_codex_bridge::launch::render_epiphany_coordinator_note; -use epiphany_codex_bridge::mutation::epiphany_imagination_finding_has_reviewable_state_patch; -use epiphany_codex_bridge::mutation::epiphany_modeling_finding_has_reviewable_state_patch; -use epiphany_codex_bridge::mutation::epiphany_promote_changed_fields; -use epiphany_codex_bridge::mutation::epiphany_update_patch_changed_fields; -use epiphany_codex_bridge::mutation::reorient_finding_code_refs; -use epiphany_codex_bridge::mutation::reorient_finding_investigation_checkpoint; -use epiphany_codex_bridge::mutation::reorient_finding_scratch; -use epiphany_codex_bridge::mutation::role_finding_summary; -use epiphany_codex_bridge::pressure::map_epiphany_pressure; -use epiphany_codex_bridge::pressure::render_epiphany_pre_compaction_checkpoint_intervention; -use epiphany_codex_bridge::pressure::should_run_epiphany_pre_compaction_checkpoint_intervention; use epiphany_codex_bridge::reorient::EpiphanyFreshnessWatcherSnapshot; -use epiphany_codex_bridge::reorient::map_epiphany_freshness; -use epiphany_codex_bridge::reorient::map_epiphany_reorient; -use epiphany_codex_bridge::results::map_epiphany_reorient_finding; -use epiphany_codex_bridge::results::map_epiphany_role_finding; -use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_index_summary; -use epiphany_codex_bridge::retrieve::map_epiphany_retrieve_response; -use epiphany_codex_bridge::runtime_results::load_epiphany_role_result_from_runtime_spine_job; -use epiphany_codex_bridge::scene::map_epiphany_scene; use epiphany_codex_bridge::state::live_thread_epiphany_state; -use epiphany_core::EpiphanyWorkerLaunchDocument; use std::collections::HashMap; use std::collections::HashSet; use std::io::Error as IoError; diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs index c6b30e7c..0dddc7ad 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_automation.rs @@ -1,9 +1,7 @@ use std::sync::Arc; use codex_app_server_protocol::ServerNotification; -use codex_app_server_protocol::ThreadEpiphanyCoordinatorSignals; use codex_app_server_protocol::ThreadEpiphanyReorientStateStatus; -use codex_app_server_protocol::ThreadEpiphanyRoleId; use codex_app_server_protocol::ThreadEpiphanyStateUpdatedNotification; use codex_app_server_protocol::ThreadEpiphanyStateUpdatedSource; use codex_core::CodexThread; @@ -13,32 +11,21 @@ use codex_protocol::protocol::Op; use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo; use codex_protocol::user_input::UserInput as CoreInputItem; use epiphany_codex_bridge::coordinator::EpiphanyCoordinatorAutomationAction; +use epiphany_codex_bridge::coordinator::derive_epiphany_coordinator_status; use epiphany_codex_bridge::coordinator::epiphany_reorient_finding_already_accepted; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_already_accepted; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_cites_implementation_evidence; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_allows_implementation; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_covers_current_modeling; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_needs_evidence; -use epiphany_codex_bridge::coordinator::implementation_evidence_after_role_finding; -use epiphany_codex_bridge::coordinator::map_epiphany_coordinator; use epiphany_codex_bridge::coordinator::map_epiphany_crrc_recommendation; use epiphany_codex_bridge::coordinator::map_epiphany_roles; -use epiphany_codex_bridge::coordinator::role_finding_accepted_after; use epiphany_codex_bridge::coordinator::select_epiphany_coordinator_automation_action; use epiphany_codex_bridge::jobs::map_epiphany_jobs; -use epiphany_codex_bridge::launch::EPIPHANY_MODELING_ROLE_BINDING_ID; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; -use epiphany_codex_bridge::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; use epiphany_codex_bridge::launch::build_epiphany_reorient_launch_request; use epiphany_codex_bridge::mutation::epiphany_job_launch_changed_fields; -use epiphany_codex_bridge::mutation::epiphany_modeling_finding_has_reviewable_state_patch; use epiphany_codex_bridge::pressure::map_epiphany_pressure; use epiphany_codex_bridge::pressure::render_epiphany_pre_compaction_checkpoint_intervention; use epiphany_codex_bridge::pressure::should_run_epiphany_pre_compaction_checkpoint_intervention; use epiphany_codex_bridge::reorient::map_epiphany_freshness; use epiphany_codex_bridge::reorient::map_epiphany_reorient; use epiphany_codex_bridge::runtime_results::load_epiphany_reorient_result_snapshot; -use epiphany_codex_bridge::runtime_results::load_epiphany_role_result_snapshot; use epiphany_codex_bridge::state::client_visible_live_thread_epiphany_state; use tokio::sync::Mutex; use tracing::warn; @@ -116,82 +103,24 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary( reorient_result_status, reorient_job.as_ref(), ); - let (modeling_result_status, modeling_finding, _) = load_epiphany_role_result_snapshot( - &state, + let coordinator = derive_epiphany_coordinator_status( + Some(&state), Some(runtime_store_path.as_path()), - ThreadEpiphanyRoleId::Modeling, - EPIPHANY_MODELING_ROLE_BINDING_ID, - ) - .await; - let modeling_result_accepted = modeling_finding - .as_ref() - .is_some_and(|finding| epiphany_role_finding_already_accepted(&state, finding)); - let modeling_result_reviewable = modeling_finding - .as_ref() - .is_some_and(epiphany_modeling_finding_has_reviewable_state_patch); - let (verification_result_status, verification_finding, _) = load_epiphany_role_result_snapshot( - &state, - Some(runtime_store_path.as_path()), - ThreadEpiphanyRoleId::Verification, - EPIPHANY_VERIFICATION_ROLE_BINDING_ID, - ) - .await; - let verification_result_accepted = verification_finding - .as_ref() - .is_some_and(|finding| epiphany_role_finding_already_accepted(&state, finding)); - let verification_result_covers_current_modeling = - epiphany_verification_finding_covers_current_modeling( - &state, - modeling_result_accepted, - modeling_finding.as_ref(), - verification_finding.as_ref(), - ); - let modeling_result_accepted_after_verification = role_finding_accepted_after( - &state, - modeling_finding.as_ref(), - verification_finding.as_ref(), - ); - let implementation_evidence_after_verification = - implementation_evidence_after_role_finding(&state, verification_finding.as_ref()); - let verification_result_cites_implementation_evidence = - epiphany_role_finding_cites_implementation_evidence(&state, verification_finding.as_ref()); - let verification_result_allows_implementation = verification_result_accepted - && verification_finding - .as_ref() - .is_some_and(epiphany_verification_finding_allows_implementation); - let verification_result_needs_evidence = verification_result_accepted - && verification_finding - .as_ref() - .is_some_and(epiphany_verification_finding_needs_evidence); - let source_signals = ThreadEpiphanyCoordinatorSignals { - pressure_level: pressure.level, - should_prepare_compaction: pressure.should_prepare_compaction, - reorient_action: reorient_decision.action, - crrc_action: crrc_recommendation.action, - modeling_result_status, - verification_result_status, - reorient_result_status, - }; - let coordinator = map_epiphany_coordinator( state_status, - state.investigation_checkpoint.as_ref().is_some(), &pressure, &crrc_recommendation, - &roles, - &source_signals, - modeling_result_accepted, - modeling_result_reviewable, - modeling_result_accepted_after_verification, - implementation_evidence_after_verification, - verification_result_cites_implementation_evidence, - verification_result_covers_current_modeling, - verification_result_accepted, - verification_result_allows_implementation, - verification_result_needs_evidence, - reorient_finding_accepted, - ); + roles, + Some(&reorient_decision), + reorient_result_status, + reorient_finding.as_ref(), + state.investigation_checkpoint.as_ref().is_some(), + ) + .await; - match select_epiphany_coordinator_automation_action(&coordinator, force_checkpoint_compaction) { + match select_epiphany_coordinator_automation_action( + &coordinator.decision, + force_checkpoint_compaction, + ) { EpiphanyCoordinatorAutomationAction::None => {} EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient => { if let Err(err) = thread.submit(Op::Compact).await { 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 2f5e7be8..bc9a5c85 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 @@ -9,25 +9,15 @@ 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::context::map_epiphany_planning; +use epiphany_codex_bridge::coordinator::derive_epiphany_coordinator_status; use epiphany_codex_bridge::coordinator::epiphany_reorient_finding_already_accepted; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_already_accepted; -use epiphany_codex_bridge::coordinator::epiphany_role_finding_cites_implementation_evidence; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_allows_implementation; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_covers_current_modeling; -use epiphany_codex_bridge::coordinator::epiphany_verification_finding_needs_evidence; -use epiphany_codex_bridge::coordinator::implementation_evidence_after_role_finding; -use epiphany_codex_bridge::coordinator::map_epiphany_coordinator; +use epiphany_codex_bridge::coordinator::map_epiphany_coordinator_view; use epiphany_codex_bridge::coordinator::map_epiphany_crrc_recommendation; use epiphany_codex_bridge::coordinator::map_epiphany_roles; use epiphany_codex_bridge::coordinator::render_epiphany_roles_note; -use epiphany_codex_bridge::coordinator::role_finding_accepted_after; use epiphany_codex_bridge::jobs::map_epiphany_jobs; -use epiphany_codex_bridge::launch::EPIPHANY_MODELING_ROLE_BINDING_ID; use epiphany_codex_bridge::launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID; -use epiphany_codex_bridge::launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; use epiphany_codex_bridge::launch::epiphany_role_binding_id; -use epiphany_codex_bridge::launch::render_epiphany_coordinator_note; -use epiphany_codex_bridge::mutation::epiphany_modeling_finding_has_reviewable_state_patch; use epiphany_codex_bridge::pressure::map_epiphany_pressure; use epiphany_codex_bridge::reorient::map_epiphany_freshness; use epiphany_codex_bridge::reorient::map_epiphany_reorient; @@ -256,149 +246,26 @@ impl CodexMessageProcessor { if let (Some(pressure), Some(recommendation), Some(roles)) = (pressure.as_ref(), recommendation.as_ref(), roles.clone()) { - let (modeling_result_status, modeling_finding, _) = - if let Some(state) = thread.epiphany_state.as_ref() { - load_epiphany_role_result_snapshot( - state, - runtime_store_path.as_deref(), - ThreadEpiphanyRoleId::Modeling, - EPIPHANY_MODELING_ROLE_BINDING_ID, - ) - .await - } else { - ( - ThreadEpiphanyRoleResultStatus::MissingState, - None, - "No authoritative Epiphany state exists for this thread.".to_string(), - ) - }; - let modeling_result_accepted = modeling_finding.as_ref().is_some_and(|finding| { - thread - .epiphany_state - .as_ref() - .is_some_and(|state| epiphany_role_finding_already_accepted(state, finding)) - }); - let modeling_result_reviewable = modeling_finding - .as_ref() - .is_some_and(epiphany_modeling_finding_has_reviewable_state_patch); - let (verification_result_status, verification_finding, _) = - if let Some(state) = thread.epiphany_state.as_ref() { - load_epiphany_role_result_snapshot( - state, - runtime_store_path.as_deref(), - ThreadEpiphanyRoleId::Verification, - EPIPHANY_VERIFICATION_ROLE_BINDING_ID, - ) - .await - } else { - ( - ThreadEpiphanyRoleResultStatus::MissingState, - None, - "No authoritative Epiphany state exists for this thread.".to_string(), - ) - }; - let verification_result_accepted = - verification_finding.as_ref().is_some_and(|finding| { - thread.epiphany_state.as_ref().is_some_and(|state| { - epiphany_role_finding_already_accepted(state, finding) - }) - }); - let verification_result_covers_current_modeling = - thread.epiphany_state.as_ref().is_none_or(|state| { - epiphany_verification_finding_covers_current_modeling( - state, - modeling_result_accepted, - modeling_finding.as_ref(), - verification_finding.as_ref(), - ) - }); - let modeling_result_accepted_after_verification = - thread.epiphany_state.as_ref().is_some_and(|state| { - role_finding_accepted_after( - state, - modeling_finding.as_ref(), - verification_finding.as_ref(), - ) - }); - let implementation_evidence_after_verification = - thread.epiphany_state.as_ref().is_some_and(|state| { - implementation_evidence_after_role_finding( - state, - verification_finding.as_ref(), - ) - }); - let verification_result_cites_implementation_evidence = - thread.epiphany_state.as_ref().is_some_and(|state| { - epiphany_role_finding_cites_implementation_evidence( - state, - verification_finding.as_ref(), - ) - }); - let verification_result_allows_implementation = verification_result_accepted - && verification_finding - .as_ref() - .is_some_and(epiphany_verification_finding_allows_implementation); - let verification_result_needs_evidence = verification_result_accepted - && verification_finding - .as_ref() - .is_some_and(epiphany_verification_finding_needs_evidence); - let source_signals = ThreadEpiphanyCoordinatorSignals { - pressure_level: pressure.level, - should_prepare_compaction: pressure.should_prepare_compaction, - reorient_action: reorient_decision - .as_ref() - .map(|decision| decision.action) - .unwrap_or(ThreadEpiphanyReorientAction::Resume), - crrc_action: recommendation.action, - modeling_result_status, - verification_result_status, - reorient_result_status, - }; - let coordinator = map_epiphany_coordinator( + let status = derive_epiphany_coordinator_status( + thread.epiphany_state.as_ref(), + runtime_store_path.as_deref(), reorient_state_status, - checkpoint_present, pressure, recommendation, - &roles, - &source_signals, - modeling_result_accepted, - modeling_result_reviewable, - modeling_result_accepted_after_verification, - implementation_evidence_after_verification, - verification_result_cites_implementation_evidence, - verification_result_covers_current_modeling, - verification_result_accepted, - verification_result_allows_implementation, - verification_result_needs_evidence, - reorient_finding_accepted, - ); - let note = render_epiphany_coordinator_note( - recommendation.action, - pressure.level, - modeling_result_status, - verification_result_status, - reorient_result_status, - coordinator.action, - ); - Some(ThreadEpiphanyViewCoordinator { - thread_id: thread_id.clone(), - source: if loaded { - ThreadEpiphanyRolesSource::Live - } else { - ThreadEpiphanyRolesSource::Stored - }, - state_status: reorient_state_status, - state_revision, - action: coordinator.action, - target_role: coordinator.target_role, - recommended_scene_action: coordinator.recommended_scene_action, - requires_review: coordinator.requires_review, - can_auto_run: coordinator.can_auto_run, - reason: coordinator.reason, - source_signals, roles, - note, - }) + reorient_decision.as_ref(), + reorient_result_status, + reorient_finding.as_ref(), + checkpoint_present, + ) + .await; + Some(map_epiphany_coordinator_view( + thread_id.clone(), + loaded, + reorient_state_status, + state_revision, + status, + )) } else { None }