diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 76430b69..6e1a9f2b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -425,14 +425,17 @@ about 19,377 lines. This is progress, not absolution: handlers, roles/coordinator mappers, route orchestration, accept policy plumbing, and tests still keep too much Epiphany inside Codex. The eighth cut moved retrieve projection into `vendor/codex/codex-rs/app-server/src/epiphany_retrieve.rs`, -taking the processor to about 19,307 lines. +taking the processor to about 19,307 lines. The ninth cut moved pressure and +pre-compaction checkpoint projection into +`vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs`, taking the +processor to about 19,232 lines. 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. Continue with the actual whale-carcass cut: extract Epiphany roles/coordinator -projection mappers, route handlers, and remaining policy-shaped code out of +projection mappers as one owned block, then route handlers and remaining policy-shaped code out of `codex_message_processor.rs` into Epiphany-owned app-server modules, moving logic further into `epiphany-core` whenever it owns real policy. Success is a visibly smaller `codex_message_processor.rs`, not merely nicer payload names. Do diff --git a/notes/json-contamination-ledger.md b/notes/json-contamination-ledger.md index d35500d1..7eb3643e 100644 --- a/notes/json-contamination-ledger.md +++ b/notes/json-contamination-ledger.md @@ -62,6 +62,6 @@ Rule: JSON is allowed at external schema/wire boundaries. Inside Epiphany, live 3. Done: replace role `statePatch` JSON with typed map/planning/graph patch documents. `EpiphanyRoleFindingInterpretation` now carries `EpiphanyRoleStatePatchDocument`; app-server maps it to the legacy protocol patch without JSON round-tripping. 4. Done: replace runtime job result JSON projections. Runtime-spine results now project through typed role/reorient interpreters instead of `runtime_job_result_to_role_json` and `runtime_job_result_to_reorient_json`. 5. Done: replace app-server launch protocol `input_json` / `output_schema_json` with typed launch documents and `output_contract_id`. -6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, and retrieve projection into `epiphany_retrieve.rs`, reducing `codex_message_processor.rs` from about 21,263 to 19,307 lines. Next move roles/coordinator projection mappers, route handlers, and policy-shaped code out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. +6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, retrieve projection into `epiphany_retrieve.rs`, and pressure/pre-compaction checkpoint projection into `epiphany_pressure.rs`, reducing `codex_message_processor.rs` from about 21,263 to 19,232 lines. Next move roles/coordinator projection mappers, route handlers, and policy-shaped code out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. 7. Seal MCP payloads behind an Epiphany boundary that speaks typed Epiphany documents internally and MCP JSON externally. 8. Audit heartbeat cognition values and either type them or explicitly expire them. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 9a2852e2..61ff38e0 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 1e094e84..84175f86 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -278,5 +278,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 plus eight real carcass cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, freshness/reorientation input mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`, context/planning/graph-query projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_context.rs`, jobs projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_jobs.rs`, and retrieve projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_retrieve.rs`. The processor is down from about 21,263 lines to 19,307 lines. This is progress, not absolution: route handlers, roles/coordinator mappers, accept policy plumbing, and tests still keep too much Epiphany inside Codex. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. - next_action: Continue the actual whale-carcass cut: extract Epiphany roles/coordinator projection mappers and then route handlers out of `codex_message_processor.rs` into Epiphany-owned app-server modules, moving logic further into `epiphany-core` whenever it owns real policy. Success metric remains a visibly smaller processor and clearer ownership, not merely typed payloads. + summary: The Codex starvation pass has five typing receipts plus nine real carcass cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, freshness/reorientation input mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`, context/planning/graph-query projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_context.rs`, jobs projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_jobs.rs`, retrieve projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_retrieve.rs`, and pressure/pre-compaction checkpoint projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs`. The processor is down from about 21,263 lines to 19,232 lines. This is progress, not absolution: route handlers, roles/coordinator mappers, accept policy plumbing, and tests still keep too much Epiphany inside Codex. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. + next_action: Continue the actual whale-carcass cut: extract Epiphany roles/coordinator projection mappers as one owned block, then route handlers out of `codex_message_processor.rs` into Epiphany-owned app-server modules, moving logic further into `epiphany-core` whenever it owns real policy. Success metric remains a visibly smaller processor and clearer ownership, not merely typed payloads. 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 864e4f6e..7b4fa54e 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 @@ -22,15 +22,16 @@ use crate::epiphany_launch::EPIPHANY_VERIFICATION_ROLE_BINDING_ID; use crate::epiphany_launch::build_epiphany_reorient_launch_instruction; use crate::epiphany_launch::build_epiphany_reorient_launch_request; use crate::epiphany_launch::build_epiphany_role_launch_request; -use crate::epiphany_launch::epiphany_agent_prompt_with_memory; use crate::epiphany_launch::epiphany_reorient_launch_output_schema; use crate::epiphany_launch::epiphany_role_binding_id; use crate::epiphany_launch::epiphany_role_label; use crate::epiphany_launch::epiphany_role_launch_output_schema; use crate::epiphany_launch::epiphany_specialist_prompt_config; use crate::epiphany_launch::map_core_worker_launch_document; -use crate::epiphany_launch::pressure_level_label; use crate::epiphany_launch::render_epiphany_coordinator_note; +use crate::epiphany_pressure::map_epiphany_pressure; +use crate::epiphany_pressure::render_epiphany_pre_compaction_checkpoint_intervention; +use crate::epiphany_pressure::should_run_epiphany_pre_compaction_checkpoint_intervention; use crate::epiphany_reorient::map_epiphany_freshness; use crate::epiphany_reorient::map_epiphany_reorient; use crate::epiphany_results::map_core_role_result_role_id; @@ -220,9 +221,7 @@ use codex_app_server_protocol::ThreadEpiphanyJobLaunchParams; use codex_app_server_protocol::ThreadEpiphanyJobLaunchResponse; use codex_app_server_protocol::ThreadEpiphanyJobStatus; use codex_app_server_protocol::ThreadEpiphanyPressure; -use codex_app_server_protocol::ThreadEpiphanyPressureBasis; use codex_app_server_protocol::ThreadEpiphanyPressureLevel; -use codex_app_server_protocol::ThreadEpiphanyPressureStatus; use codex_app_server_protocol::ThreadEpiphanyPromoteParams; use codex_app_server_protocol::ThreadEpiphanyPromoteResponse; use codex_app_server_protocol::ThreadEpiphanyProposeParams; @@ -529,10 +528,6 @@ use epiphany_core::EpiphanyCrrcReorientAction as CoreEpiphanyCrrcReorientAction; use epiphany_core::EpiphanyCrrcResultStatus as CoreEpiphanyCrrcResultStatus; use epiphany_core::EpiphanyCrrcSceneAction as CoreEpiphanyCrrcSceneAction; use epiphany_core::EpiphanyCrrcStateStatus as CoreEpiphanyCrrcStateStatus; -use epiphany_core::EpiphanyPressure; -use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis; -use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel; -use epiphany_core::EpiphanyPressureStatus as CoreEpiphanyPressureStatus; use epiphany_core::EpiphanyReorientAcceptanceFinding; use epiphany_core::EpiphanyRoleAcceptanceFinding; use epiphany_core::EpiphanyRoleBoardCheckpointSummary; @@ -549,7 +544,6 @@ use epiphany_core::EpiphanyWorkerLaunchDocument; use epiphany_core::build_reorient_acceptance_bundle; use epiphany_core::build_role_acceptance_bundle; use epiphany_core::coordinator_automation_action; -use epiphany_core::derive_pressure_view; use epiphany_core::derive_role_board; use epiphany_core::derive_scene; use epiphany_core::imagination_role_state_patch_policy_errors; @@ -13818,75 +13812,6 @@ fn reorient_finding_investigation_checkpoint( checkpoint } -fn map_epiphany_pressure(info: Option<&CoreTokenUsageInfo>) -> ThreadEpiphanyPressure { - map_core_epiphany_pressure(derive_pressure_view(info)) -} - -fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure { - ThreadEpiphanyPressure { - status: match pressure.status { - CoreEpiphanyPressureStatus::Unknown => ThreadEpiphanyPressureStatus::Unknown, - CoreEpiphanyPressureStatus::Ready => ThreadEpiphanyPressureStatus::Ready, - }, - level: match pressure.level { - CoreEpiphanyPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, - CoreEpiphanyPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, - CoreEpiphanyPressureLevel::Elevated => ThreadEpiphanyPressureLevel::Elevated, - CoreEpiphanyPressureLevel::High => ThreadEpiphanyPressureLevel::High, - CoreEpiphanyPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, - }, - basis: match pressure.basis { - CoreEpiphanyPressureBasis::Unknown => ThreadEpiphanyPressureBasis::Unknown, - CoreEpiphanyPressureBasis::AutoCompactLimit => { - ThreadEpiphanyPressureBasis::AutoCompactLimit - } - CoreEpiphanyPressureBasis::ModelContextWindow => { - ThreadEpiphanyPressureBasis::ModelContextWindow - } - }, - used_tokens: pressure.used_tokens, - model_context_window: pressure.model_context_window, - model_auto_compact_token_limit: pressure.model_auto_compact_token_limit, - remaining_tokens: pressure.remaining_tokens, - ratio_per_mille: pressure.ratio_per_mille, - should_prepare_compaction: pressure.should_prepare_compaction, - note: pressure.note, - } -} - -fn should_run_epiphany_pre_compaction_checkpoint_intervention( - pressure: &ThreadEpiphanyPressure, -) -> bool { - pressure.status == ThreadEpiphanyPressureStatus::Ready && pressure.should_prepare_compaction -} - -fn render_epiphany_pre_compaction_checkpoint_intervention( - pressure: &ThreadEpiphanyPressure, -) -> String { - let usage = match ( - pressure.used_tokens, - pressure.remaining_tokens, - pressure.ratio_per_mille, - ) { - (Some(used), Some(remaining), Some(ratio)) => format!( - "{used} tokens used, {remaining} remaining, {}.{}% of the selected limit", - ratio / 10, - ratio % 10 - ), - (Some(used), _, _) => format!("{used} tokens used"), - _ => "token usage known only as a pressure threshold crossing".to_string(), - }; - let template = epiphany_agent_prompt_with_memory( - &epiphany_specialist_prompt_config() - .crrc - .pre_compaction_checkpoint_intervention, - ); - template - .trim() - .replace("{pressure_level}", pressure_level_label(pressure.level)) - .replace("{usage}", &usage) -} - pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary( thread_id: ThreadId, thread: Arc, diff --git a/vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs b/vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs new file mode 100644 index 00000000..700431c9 --- /dev/null +++ b/vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs @@ -0,0 +1,83 @@ +use codex_app_server_protocol::ThreadEpiphanyPressure; +use codex_app_server_protocol::ThreadEpiphanyPressureBasis; +use codex_app_server_protocol::ThreadEpiphanyPressureLevel; +use codex_app_server_protocol::ThreadEpiphanyPressureStatus; +use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo; +use epiphany_core::EpiphanyPressure; +use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis; +use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel; +use epiphany_core::EpiphanyPressureStatus as CoreEpiphanyPressureStatus; +use epiphany_core::derive_pressure_view; + +use crate::epiphany_launch::epiphany_agent_prompt_with_memory; +use crate::epiphany_launch::epiphany_specialist_prompt_config; +use crate::epiphany_launch::pressure_level_label; + +pub(super) fn map_epiphany_pressure(info: Option<&CoreTokenUsageInfo>) -> ThreadEpiphanyPressure { + map_core_epiphany_pressure(derive_pressure_view(info)) +} + +fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure { + ThreadEpiphanyPressure { + status: match pressure.status { + CoreEpiphanyPressureStatus::Unknown => ThreadEpiphanyPressureStatus::Unknown, + CoreEpiphanyPressureStatus::Ready => ThreadEpiphanyPressureStatus::Ready, + }, + level: match pressure.level { + CoreEpiphanyPressureLevel::Unknown => ThreadEpiphanyPressureLevel::Unknown, + CoreEpiphanyPressureLevel::Low => ThreadEpiphanyPressureLevel::Low, + CoreEpiphanyPressureLevel::Elevated => ThreadEpiphanyPressureLevel::Elevated, + CoreEpiphanyPressureLevel::High => ThreadEpiphanyPressureLevel::High, + CoreEpiphanyPressureLevel::Critical => ThreadEpiphanyPressureLevel::Critical, + }, + basis: match pressure.basis { + CoreEpiphanyPressureBasis::Unknown => ThreadEpiphanyPressureBasis::Unknown, + CoreEpiphanyPressureBasis::AutoCompactLimit => { + ThreadEpiphanyPressureBasis::AutoCompactLimit + } + CoreEpiphanyPressureBasis::ModelContextWindow => { + ThreadEpiphanyPressureBasis::ModelContextWindow + } + }, + used_tokens: pressure.used_tokens, + model_context_window: pressure.model_context_window, + model_auto_compact_token_limit: pressure.model_auto_compact_token_limit, + remaining_tokens: pressure.remaining_tokens, + ratio_per_mille: pressure.ratio_per_mille, + should_prepare_compaction: pressure.should_prepare_compaction, + note: pressure.note, + } +} + +pub(super) fn should_run_epiphany_pre_compaction_checkpoint_intervention( + pressure: &ThreadEpiphanyPressure, +) -> bool { + pressure.status == ThreadEpiphanyPressureStatus::Ready && pressure.should_prepare_compaction +} + +pub(super) fn render_epiphany_pre_compaction_checkpoint_intervention( + pressure: &ThreadEpiphanyPressure, +) -> String { + let usage = match ( + pressure.used_tokens, + pressure.remaining_tokens, + pressure.ratio_per_mille, + ) { + (Some(used), Some(remaining), Some(ratio)) => format!( + "{used} tokens used, {remaining} remaining, {}.{}% of the selected limit", + ratio / 10, + ratio % 10 + ), + (Some(used), _, _) => format!("{used} tokens used"), + _ => "token usage known only as a pressure threshold crossing".to_string(), + }; + let template = epiphany_agent_prompt_with_memory( + &epiphany_specialist_prompt_config() + .crrc + .pre_compaction_checkpoint_intervention, + ); + template + .trim() + .replace("{pressure_level}", pressure_level_label(pressure.level)) + .replace("{usage}", &usage) +} diff --git a/vendor/codex/codex-rs/app-server/src/lib.rs b/vendor/codex/codex-rs/app-server/src/lib.rs index 3f509062..bc4b3b8a 100644 --- a/vendor/codex/codex-rs/app-server/src/lib.rs +++ b/vendor/codex/codex-rs/app-server/src/lib.rs @@ -79,6 +79,7 @@ mod epiphany_context; mod epiphany_invalidation; mod epiphany_jobs; mod epiphany_launch; +mod epiphany_pressure; mod epiphany_reorient; mod epiphany_results; mod epiphany_retrieve;