From fa222584e47602157c1ab57259345b4db9a65a7c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 17 May 2026 20:34:59 +0100 Subject: [PATCH] Move retrieval query law to core --- epiphany-core/src/lib.rs | 1 + epiphany-core/src/retrieval.rs | 45 ++++++++++++++++++ notes/fresh-workspace-handoff.md | 6 +++ state/ledgers.msgpack | Bin 118112 -> 118392 bytes state/map.yaml | 11 +++-- .../epiphany_read_routes.rs | 37 ++++---------- 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 79b001d1..c0b4a89a 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -88,6 +88,7 @@ pub use retrieval::EpiphanyRetrieveResponse; pub use retrieval::EpiphanyRetrieveResult; pub use retrieval::EpiphanyRetrieveResultKind; pub use retrieval::index_workspace; +pub use retrieval::normalize_epiphany_retrieve_query; pub use retrieval::retrieval_state_for_workspace; pub use retrieval::retrieve_workspace; pub use runtime_spine::EpiphanyRuntimeEvent; diff --git a/epiphany-core/src/retrieval.rs b/epiphany-core/src/retrieval.rs index d8fe4718..1737fcfe 100644 --- a/epiphany-core/src/retrieval.rs +++ b/epiphany-core/src/retrieval.rs @@ -70,6 +70,29 @@ impl EpiphanyRetrieveQuery { } } +pub fn normalize_epiphany_retrieve_query( + query: String, + limit: Option, + path_prefixes: Vec, +) -> std::result::Result { + let query = query.trim().to_string(); + if query.is_empty() { + return Err("query must not be empty"); + } + if matches!(limit, Some(0)) { + return Err("limit must be greater than zero"); + } + let limit = limit + .map(|value| value as usize) + .unwrap_or(EPIPHANY_RETRIEVAL_DEFAULT_LIMIT) + .clamp(1, EPIPHANY_RETRIEVAL_MAX_LIMIT); + Ok(EpiphanyRetrieveQuery { + query, + limit, + path_prefixes, + }) +} + #[derive(Clone, Debug, PartialEq, Eq)] pub enum EpiphanyRetrieveResultKind { ExactFile, @@ -1670,6 +1693,28 @@ mod tests { use wiremock::matchers::method; use wiremock::matchers::path; + #[test] + fn normalize_epiphany_retrieve_query_trims_and_clamps_limit() { + let query = + normalize_epiphany_retrieve_query(" auth spine ".to_string(), Some(999), Vec::new()) + .unwrap(); + + assert_eq!(query.query, "auth spine"); + assert_eq!(query.limit, EPIPHANY_RETRIEVAL_MAX_LIMIT); + } + + #[test] + fn normalize_epiphany_retrieve_query_rejects_empty_query_and_zero_limit() { + assert_eq!( + normalize_epiphany_retrieve_query(" ".to_string(), Some(1), Vec::new()), + Err("query must not be empty") + ); + assert_eq!( + normalize_epiphany_retrieve_query("auth".to_string(), Some(0), Vec::new()), + Err("limit must be greater than zero") + ); + } + #[test] fn retrieve_workspace_prioritizes_exact_hits_without_losing_semantic_chunks() -> Result<()> { let temp_dir = TempDir::new()?; diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 86100655..2e133c73 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -808,6 +808,12 @@ host wrapper/tag smoke. The full render contract and graph-heavy fixture live in native `epiphany-core::prompt`; do not re-grow that duplicated Epiphany prompt authority inside `codex-core`. +Retrieval query normalization is native too: +`epiphany-core::normalize_epiphany_retrieve_query` owns trimming, empty-query +rejection, zero-limit rejection, and default/max limit clamping. Vendored +`thread/epiphany/retrieve` only turns that native validation verdict into a +JSON-RPC response and invokes the loaded CodexThread host seam. + The native OpenAI auth spine overcut has been corrected. It no longer owns a clone of Codex keyring/file/env auth or ChatGPT token refresh; it re-exports vendored `codex-login` and carries the Codex workspace tungstenite patches diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 893b8f07abc211577ca79e5fbb2431f59d2c1472..3da15b573c55a1ec91a63d651702fae1481184fe 100644 GIT binary patch delta 261 zcmaDbi~YwO_6f>N=j=ABPGe-WZr;PVeGemJ-)Yg7MJ2^MjSP&;bPY^(4b4LgEv<}A zrqAEasLOQKclrcrMp5^~9EHNt)S^m-y!@iv#GK5k#FEVXJcYEP{9J{Sj8uiP)V!4Z zqSO>1rzkZsML)G5vmhfeuTsA#wWKIBwJcSkD8IBMb?QV$;c6=@m?5e0Fm>@Tb@5

6f5KbZ3Y@w26RLU)Del9Ii*FZ#R?_)3SPnf Te!4*c&Uy`7&^=^jY#0Rqg)m+} delta 49 zcmew{hyB4U_6f>NXVo^UPGe-WYTm=ReGemJ-)XUiEk*`LX1WHZx`yT` or `` prompt compatibility, memory usage classification, snapshot normalization, or cleanup paths. Remaining product-shaped skill residue is also cut from memory templates, app-server docs/tests/warnings, TUI tooltips/placeholders/warnings/comments, app-server v1 docs, agent-tool schema text, stale `UserInput::Skill` test arms, and obsolete feature flags/schema entries. App-instruction prompt compatibility is cut too: no `APPS_INSTRUCTIONS` protocol constants, no `` snapshot canonicalization, and MCP fixture tests now use neutral `demo_mcp` / `calendar_mcp` names instead of `codex_apps` / `/api/codex/apps` branding. The TUI app connector product path is also deleted: no `/apps` slash command, app-link view, connector AppEvent variants, app connector cache/popup/refresh loop, app mention insertion, `app://` mention codec support, stale app-popup tests, or TUI browser-opening shim remains. The `app/list` route and `app/list/updated` notification are gone from app-server protocol, generated schemas, app-server dispatch, test helpers, and docs; `AppInfo`/app-list metadata schema structs are deleted; the orphaned `codex-connectors` crate and `core::connectors` shim are deleted from the workspace; Codex app analytics no longer tracks `codex_app_mentioned` / `codex_app_used` facts, events, reducer arms, client APIs, or dedupe cache state; `[apps.*]`, `Feature::Apps`, `include_apps_instructions`, app config/read schemas, app managed requirements, app prompt tests, and app file-MCP tests are gone; `Feature::Plugins`, `Feature::RemotePlugin`, `plugin://` structured mentions, plugin instruction tags, and stale plugin popup snapshots are gone too; `[plugins]` / `[marketplaces]`, `PluginConfig`, `MarketplaceConfig`, marketplace edit helpers, stale plugin/external-agent README route claims, and generated schema entries are removed from config; and the bundled `codex-skills` sample-skill crate plus embedded imagegen/openai-docs/plugin-creator/skill-creator/skill-installer payloads are deleted from the workspace. The vendored `vendor/codex/sdk` subtree is deleted as non-spine app-server client/release scaffolding, including stale generated Python SDK route types for removed product surfaces; the root pnpm workspace no longer lists `sdk/typescript`. Live MCP tool approval is named `McpToolApproval`, not `AppToolApproval`, and remains under MCP server config; live structured user-input mentions are MCP-shaped only. `codex_message_processor.rs` is about 9,482 lines; root `message_processor.rs` is about 1,292 lines after the external-agent/config-product cuts; `epiphany_read_routes.rs` is about 579 lines after the full view and read-response extractions; `epiphany_mutation_routes.rs` is about 694 lines after route-load/notification helper cuts and product-surface starvation; the old vendored `epiphany_state_helpers.rs` rollout-state loader is deleted and its remaining function lives in `epiphany-codex-bridge::state`; 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` owns the native OpenAI model transport path: it exposes `default_codex_home` and `auth_manager`, projects `epiphany-openai-auth-spine` `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, builds a local serializable OpenAI Responses request body instead of Codex protocol request/item/config types, opens HTTP Responses streams through `codex-client`, parses Responses SSE frames into typed stream events and receipts, and no longer directly or transitively depends on Codex's Responses client, model-provider stack, `codex-protocol`, `codex-api`, `codex-model-provider`, or `codex-model-provider-info`; it intentionally reaches retained vendored `codex-login` only through `epiphany-openai-auth-spine`. Auth identity, credential storage, and ChatGPT token refresh remain owned by the Codex-compatible auth organ; external bearer command auth and agent identity remain retained Codex auth capabilities to expose only if a typed Epiphany surface needs them. `epiphany-openai-runtime` no longer depends directly on `codex-login`; it 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 through the spine, 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 require typed worker result documents; generic job summaries are lifecycle receipts, not reviewable findings; `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`, or `epiphany_retrieval` husk modules; it re-exports native surfaces from `epiphany-core` directly, and now owns only the real Codex rollout adapter because it is a host seam. `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 request path no longer pulls `codex-api`; `codex-login` remains deliberately sealed behind `epiphany-openai-auth-spine`, and the next spine decision is another Epiphany-in-vendor evacuation surface unless a concrete typed auth-status/runtime need requires exposing external bearer or agent-identity auth. latest_cut: > - The vendored Codex prompt-fragment test for `` was reduced - to a host-wrapper/tag smoke. The full Epiphany graph/prompt rendering - fixture already lives in native `epiphany-core::prompt`; Codex core no - longer carries a duplicate graph-rendering catechism as if it owned the - contract. + Retrieval query input law moved from the vendored + `thread/epiphany/retrieve` route into + `epiphany-core::normalize_epiphany_retrieve_query`. App-server still maps + native validation failures to JSON-RPC invalid-request responses, but query + trimming, empty-query rejection, zero-limit rejection, and limit clamping + are now native Epiphany retrieval policy. next_action: Continue the Codex starvation campaign at the next Epiphany-in-vendor evacuation surface; keep vendored Codex code as host routing/lifecycle glue only, and do not cut the retained `codex-login` auth organ unless replacing it with an explicitly permitted OpenAI path rather than a lookalike. 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 6b98974c..bba35e31 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 @@ -21,9 +21,7 @@ use epiphany_codex_bridge::view::map_epiphany_propose_response; use epiphany_codex_bridge::view::map_epiphany_reorient_result_response; use epiphany_codex_bridge::view::map_epiphany_role_result_response; use epiphany_codex_bridge::view::map_epiphany_view_response; -use epiphany_core::EPIPHANY_RETRIEVAL_DEFAULT_LIMIT; -use epiphany_core::EPIPHANY_RETRIEVAL_MAX_LIMIT; -use epiphany_core::EpiphanyRetrieveQuery; +use epiphany_core::normalize_epiphany_retrieve_query; use super::CodexMessageProcessor; use super::ConnectionRequestId; @@ -419,21 +417,14 @@ impl CodexMessageProcessor { } }; - let query = query.trim().to_string(); - if query.is_empty() { - self.send_invalid_request_error(request_id, "query must not be empty".to_string()) - .await; - return; - } - - if matches!(limit, Some(0)) { - self.send_invalid_request_error( - request_id, - "limit must be greater than zero".to_string(), - ) - .await; - return; - } + let query = match normalize_epiphany_retrieve_query(query, limit, path_prefixes) { + Ok(query) => query, + Err(message) => { + self.send_invalid_request_error(request_id, message.to_string()) + .await; + return; + } + }; let thread = match self.thread_manager.get_thread(thread_uuid).await { Ok(thread) => thread, @@ -447,16 +438,8 @@ impl CodexMessageProcessor { } }; - let limit = limit - .map(|value| value as usize) - .unwrap_or(EPIPHANY_RETRIEVAL_DEFAULT_LIMIT) - .clamp(1, EPIPHANY_RETRIEVAL_MAX_LIMIT); let response = match thread - .epiphany_retrieve(EpiphanyRetrieveQuery { - query, - limit, - path_prefixes, - }) + .epiphany_retrieve(query) .await .and_then(map_epiphany_retrieve_response) {