diff --git a/epiphany-codex-bridge/src/protocol_edge.rs b/epiphany-codex-bridge/src/protocol_edge.rs index aaede36e..a303e5ef 100644 --- a/epiphany-codex-bridge/src/protocol_edge.rs +++ b/epiphany-codex-bridge/src/protocol_edge.rs @@ -42,6 +42,8 @@ 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::ThreadEpiphanyReorientLaunchParams; +use codex_app_server_protocol::ThreadEpiphanyReorientLaunchResponse; use codex_app_server_protocol::ThreadEpiphanyReorientReason; use codex_app_server_protocol::ThreadEpiphanyReorientResultStatus; use codex_app_server_protocol::ThreadEpiphanyReorientSource; @@ -102,6 +104,7 @@ use epiphany_state_model::EpiphanyThreadState; use crate::mutation_service::EpiphanyJobInterruptApplied; use crate::mutation_service::EpiphanyJobLaunchApplied; +use crate::mutation_service::EpiphanyReorientLaunchApplied; use crate::mutation_service::EpiphanyThreadPromoteApplied; use crate::mutation_service::EpiphanyThreadUpdateApplied; @@ -431,6 +434,61 @@ pub fn plan_thread_epiphany_role_accept( }) } +pub struct ThreadEpiphanyReorientLaunchPlan { + pub thread_id: String, + pub expected_revision: Option, + pub max_runtime_seconds: Option, +} + +pub fn plan_thread_epiphany_reorient_launch( + params: ThreadEpiphanyReorientLaunchParams, +) -> ThreadEpiphanyReorientLaunchPlan { + let ThreadEpiphanyReorientLaunchParams { + thread_id, + expected_revision, + max_runtime_seconds, + } = params; + ThreadEpiphanyReorientLaunchPlan { + thread_id, + expected_revision, + max_runtime_seconds, + } +} + +pub struct ThreadEpiphanyReorientLaunchRouteOutput { + pub response: ThreadEpiphanyReorientLaunchResponse, + pub changed_fields: Vec, + pub epiphany_state: EpiphanyThreadState, +} + +pub fn thread_epiphany_reorient_launch_output( + thread_id: String, + applied: EpiphanyReorientLaunchApplied, +) -> ThreadEpiphanyReorientLaunchRouteOutput { + let changed_fields = applied.changed_fields; + let epiphany_state = applied.epiphany_state; + let response = ThreadEpiphanyReorientLaunchResponse { + thread_id, + source: protocol_reorient_source(applied.source), + state_status: protocol_reorient_state_status(applied.state_status), + state_revision: applied.state_revision, + decision: protocol_reorient_decision(applied.decision), + revision: applied.revision, + changed_fields: protocol_state_updated_fields(changed_fields.clone()), + epiphany_state: epiphany_state.clone(), + job: protocol_job_from_surface( + applied.job, + Some(applied.launcher_job_id), + Some(applied.backend_job_id), + ), + }; + ThreadEpiphanyReorientLaunchRouteOutput { + response, + changed_fields, + epiphany_state, + } +} + pub struct ThreadEpiphanyReorientAcceptPlan { pub thread_id: String, pub expected_revision: Option, diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index dc9246b9..4d35bfca 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -42,7 +42,7 @@ The spine exists in more than twenty-five live paths: - MVP operator view: native `epiphany-mvp-status` launches app-server over stdio, starts or reads one thread, gathers scene, planning, pressure, reorient, jobs, roles, Imagination/modeling/verification role results, reorient result, CRRC responses, heartbeat, and Persona bubble artifacts, and renders them as text or JSON so the loop can be dogfooded without Python owning the product surface. - MVP dogfood runner: the old Python runner was cut with the `agent_jobs` path. The replacement must be native Rust/CultCache/CultNet and complete heartbeat-owned runtime-spine job results with operator-safe artifacts. - Agent function/API telemetry: native `epiphany-agent-telemetry` mechanically parses sealed AppServerClient JSONL transcripts into operator-safe telemetry with method counts, request shape, job/status/path fields, and visible function/tool names while sealing text, turn items, raw results, and direct agent messages. -- reorientation launch: app-server now declares experimental `thread/epiphany/reorientLaunch`, requires a loaded thread plus durable investigation checkpoint, consumes the live reorientation verdict, and launches one fixed `reorient-worker` binding through the existing job-control seam with explicit resume-versus-regather scope, checkpoint-derived payload, and structured-output expectations instead of pretending CRRC suddenly grew a scheduler in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:370), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4575), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4519). +- reorientation launch: app-server now declares experimental `thread/epiphany/reorientLaunch`, requires a loaded thread plus durable investigation checkpoint, gathers host facts for retrieval/watcher/token pressure, delegates protocol param conversion and legacy response projection to `epiphany-codex-bridge::protocol_edge::plan_thread_epiphany_reorient_launch` / `thread_epiphany_reorient_launch_output`, consumes the live reorientation verdict, and launches one fixed `reorient-worker` binding through the existing job-control seam with explicit resume-versus-regather scope, checkpoint-derived payload, and structured-output expectations instead of pretending CRRC suddenly grew a scheduler in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:370), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4575), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs:240). - reorientation result/read-back/acceptance: app-server now declares experimental read-only `thread/epiphany/reorientResult` and write-gated `thread/epiphany/reorientAccept`. Result read-back supplies loaded/stored thread state plus runtime-store host facts to `epiphany-codex-bridge::view_protocol::map_thread_epiphany_reorient_result_response`, which owns the fixed `reorient-worker` binding default, source projection, runtime-spine read-back, and response mapping. Accept planning supplies `ThreadEpiphanyReorientAcceptParams` to `epiphany-codex-bridge::protocol_edge::plan_thread_epiphany_reorient_accept`, which owns the same fixed binding default before the mutation service banks accepted findings. The surface resolves heartbeat bindings through typed runtime-spine job results, seals legacy `agent_jobs` bindings, and projects a reviewable finding with mode, summary, next safe move, checkpoint-validity flag, inspected files, frontier ids, evidence ids, raw result, and any errors without mutating state, promoting evidence, or scheduling follow-up work. - reorientation finding acceptance: app-server now declares experimental `thread/epiphany/reorientAccept`, requires a loaded thread and a completed `reorient-worker` result, accepts heartbeat-backed results from typed runtime-spine receipts before falling back to old bindings, uses core acceptance bundle policy to build accepted observation/evidence/receipt payloads plus optional scratch and durable investigation-checkpoint updates, persists through the normal typed update path, and emits `thread/epiphany/stateUpdated` with source `reorientAccept` without accepting pending work, auto-promoting arbitrary worker output, launching follow-up work, or silently continuing implementation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:378), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4635), [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:150), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4885). - retrieval/indexing: app-server routes `thread/epiphany/retrieve` and `thread/epiphany/index` through `epiphany-codex-bridge::retrieve`; for retrieve, app-server reads only host cwd/Codex-home facts from `CodexThread`, while `retrieve_protocol::retrieve_thread_epiphany` accepts the protocol params and owns query/limit/path-prefix normalization, native `epiphany-core` retrieval, and Codex response projection in [retrieve_protocol.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve_protocol.rs:19), [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:42), [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:57), and [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:69). diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index f8d23238..dfa10f6a 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -919,6 +919,15 @@ now owns the legacy response DTO plus notification payload handoff from launch mutation service, sends the response, and emits the state-updated notification. `epiphany_mutation_routes.rs` is about 645 lines after this cut. +Reorient-launch write-route planning and response shaping moved to the bridge +protocol edge too. `plan_thread_epiphany_reorient_launch` owns protocol param +unpacking, while `thread_epiphany_reorient_launch_output` owns the legacy +response DTO plus notification payload handoff from +`EpiphanyReorientLaunchApplied`. App-server still owns host fact gathering: +loaded thread, read view, retrieval override, watcher snapshot, token snapshot, +mutation-service invocation, response emission, and `stateUpdated`. +`epiphany_mutation_routes.rs` is about 617 lines after this cut. + Update/promote write-route planning and response shaping moved to the bridge protocol edge. `plan_thread_epiphany_update` and `plan_thread_epiphany_promote` own protocol patch conversion, while diff --git a/state/ledgers.cc b/state/ledgers.cc index 064174a2..4c82335c 100644 Binary files a/state/ledgers.cc and b/state/ledgers.cc differ diff --git a/state/map.yaml b/state/map.yaml index bf9abd0c..0c99c568 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -139,7 +139,7 @@ accepted_design: - `epiphany-core` and `epiphany-codex-bridge` must not depend directly on vendored `codex-core`. Host-specific Codex concepts belong in vendored app-server host adapters or the thin OpenAI subscription auth/model-transport spine, while native retrieval/state/runtime/mutation policy stays in Epiphany crates. - The prompt reads typed state through a bounded `` developer fragment. - Clients read typed state through `Thread.epiphanyState`, read-only `thread/epiphany/view` lenses for scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator, freshness through `thread/epiphany/freshness`, targeted state shards through `thread/epiphany/context`, bounded graph traversal through `thread/epiphany/graphQuery`, and reviewable role output through `thread/epiphany/roleResult`. The scene, jobs, roles, planning, pressure, reorient, CRRC, and coordinator read projections now live only as view lenses, not standalone protocol verbs. - - Durable typed state writes route through `thread/epiphany/update`, accepted `thread/epiphany/promote`, `thread/epiphany/reorientAccept`, `thread/epiphany/roleAccept`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, `thread/epiphany/reorientLaunch`, and `thread/epiphany/roleLaunch` authority surfaces when they mutate state or `job_bindings`; update/promote, jobLaunch, jobInterrupt, and roleLaunch response shaping, jobLaunch request construction, plus roleLaunch/roleAccept/reorientAccept protocol/default-binding planning now live in the bridge protocol edge rather than app-server mutation routes. + - Durable typed state writes route through `thread/epiphany/update`, accepted `thread/epiphany/promote`, `thread/epiphany/reorientAccept`, `thread/epiphany/roleAccept`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, `thread/epiphany/reorientLaunch`, and `thread/epiphany/roleLaunch` authority surfaces when they mutate state or `job_bindings`; update/promote, jobLaunch, jobInterrupt, roleLaunch, and reorientLaunch response shaping, jobLaunch request construction, plus roleLaunch/reorientLaunch/roleAccept/reorientAccept protocol/default-binding planning now live in the bridge protocol edge rather than app-server mutation routes. - `thread/epiphany/retrieve`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/graphQuery`, and `thread/epiphany/view` stay read-only. - `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. Qdrant's HTTP API and acknowledgements remain JSON wire edges, but Epiphany-owned retrieval point payloads are typed at the adapter boundary before serialization/deserialization. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs index cf232633..e95b6819 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs @@ -18,21 +18,19 @@ use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_job_interrupt; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_job_launch; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_promote; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_reorient_accept; +use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_reorient_launch; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_role_accept; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_role_launch; use epiphany_codex_bridge::protocol_edge::plan_thread_epiphany_update; -use epiphany_codex_bridge::protocol_edge::protocol_job_from_surface; use epiphany_codex_bridge::protocol_edge::protocol_patch_from_core; -use epiphany_codex_bridge::protocol_edge::protocol_reorient_decision; use epiphany_codex_bridge::protocol_edge::protocol_reorient_finding; -use epiphany_codex_bridge::protocol_edge::protocol_reorient_source; -use epiphany_codex_bridge::protocol_edge::protocol_reorient_state_status; use epiphany_codex_bridge::protocol_edge::protocol_role_finding; use epiphany_codex_bridge::protocol_edge::protocol_state_updated_fields; use epiphany_codex_bridge::protocol_edge::protocol_state_updated_notification; use epiphany_codex_bridge::protocol_edge::thread_epiphany_job_interrupt_output; use epiphany_codex_bridge::protocol_edge::thread_epiphany_job_launch_output; use epiphany_codex_bridge::protocol_edge::thread_epiphany_promote_output; +use epiphany_codex_bridge::protocol_edge::thread_epiphany_reorient_launch_output; use epiphany_codex_bridge::protocol_edge::thread_epiphany_role_launch_output; use epiphany_codex_bridge::protocol_edge::thread_epiphany_update_output; use epiphany_codex_bridge::retrieve::epiphany_retrieval_state_for_paths; @@ -233,17 +231,15 @@ impl CodexMessageProcessor { request_id: ConnectionRequestId, params: ThreadEpiphanyReorientLaunchParams, ) { - let ThreadEpiphanyReorientLaunchParams { - thread_id, - expected_revision, - max_runtime_seconds, - } = params; + let launch_plan = plan_thread_epiphany_reorient_launch(params); - let (thread_uuid, loaded_thread) = - match self.load_epiphany_thread(&request_id, &thread_id).await { - Some(thread) => thread, - None => return, - }; + let (thread_uuid, loaded_thread) = match self + .load_epiphany_thread(&request_id, &launch_plan.thread_id) + .await + { + Some(thread) => thread, + None => return, + }; let thread = match self.read_thread_view(thread_uuid, false).await { Ok(thread) => thread, Err(ThreadReadViewError::InvalidRequest(message)) => { @@ -259,20 +255,20 @@ impl CodexMessageProcessor { let retrieval_override = thread_epiphany_retrieval_state(loaded_thread.as_ref()).await; let config_snapshot = loaded_thread.config_snapshot().await; self.epiphany_invalidation_manager - .ensure_thread_watch(&thread_id, &config_snapshot.cwd) + .ensure_thread_watch(&launch_plan.thread_id, &config_snapshot.cwd) .await; let watcher_snapshot = self .epiphany_invalidation_manager - .snapshot(&thread_id) + .snapshot(&launch_plan.thread_id) .await; let token_usage_info = loaded_thread.token_usage_info().await; let host = EpiphanyCodexThreadHost::new(loaded_thread.as_ref()); let token_usage_snapshot = epiphany_token_usage_snapshot(token_usage_info.as_ref()); let applied = match launch_thread_epiphany_reorient( &host, - &thread_id, - expected_revision, - max_runtime_seconds, + &launch_plan.thread_id, + launch_plan.expected_revision, + launch_plan.max_runtime_seconds, thread.epiphany_state.as_ref(), Some(&retrieval_override), Some(epiphany_freshness_watcher_snapshot(&watcher_snapshot)), @@ -296,35 +292,16 @@ impl CodexMessageProcessor { return; } }; - let changed_fields = applied.changed_fields; - let protocol_changed_fields = protocol_state_updated_fields(changed_fields.clone()); - let epiphany_state = applied.epiphany_state; + let output = thread_epiphany_reorient_launch_output(thread_uuid.to_string(), applied); self.outgoing - .send_response( - request_id, - ThreadEpiphanyReorientLaunchResponse { - thread_id: thread_uuid.to_string(), - source: protocol_reorient_source(applied.source), - state_status: protocol_reorient_state_status(applied.state_status), - state_revision: applied.state_revision, - decision: protocol_reorient_decision(applied.decision), - revision: applied.revision, - changed_fields: protocol_changed_fields, - epiphany_state: epiphany_state.clone(), - job: protocol_job_from_surface( - applied.job, - Some(applied.launcher_job_id), - Some(applied.backend_job_id), - ), - }, - ) + .send_response(request_id, output.response) .await; self.send_epiphany_state_updated( thread_uuid, ThreadEpiphanyStateUpdatedSource::JobLaunch, - changed_fields, - epiphany_state, + output.changed_fields, + output.epiphany_state, ) .await; }