Move coordinator status derivation into bridge
This commit is contained in:
parent
6e8b27613e
commit
431c56f525
7 changed files with 221 additions and 339 deletions
|
|
@ -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<ThreadEpiphanyRoleLane>,
|
||||
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<ThreadEpiphanyRoleLane>,
|
||||
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<u64>,
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because one or more lines are too long
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue