Remove Codex file search from Epiphany core

This commit is contained in:
Meta Vens 2026-05-13 11:37:33 +01:00
commit abfcf77f97
6 changed files with 94 additions and 57 deletions

View file

@ -13,7 +13,6 @@ path = "src/lib.rs"
anyhow = "1"
bm25 = "2.3.2"
chrono = "0.4.44"
codex-file-search = { path = "../vendor/codex/codex-rs/file-search" }
cultcache-rs = { path = "../vendor/cultcache-rs" }
cultnet-rs = { path = "../vendor/cultnet-rs" }
epiphany-openai-adapter = { path = "../epiphany-openai-adapter" }

View file

@ -3,7 +3,6 @@ use anyhow::Result;
use bm25::Document;
use bm25::Language;
use bm25::SearchEngineBuilder;
use codex_file_search as file_search;
use epiphany_state_model::EpiphanyRetrievalShardSummary;
use epiphany_state_model::EpiphanyRetrievalState;
use epiphany_state_model::EpiphanyRetrievalStatus;
@ -23,7 +22,6 @@ use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::fs;
use std::num::NonZero;
use std::path::Component;
use std::path::Path;
use std::path::PathBuf;
@ -37,7 +35,6 @@ pub const EPIPHANY_RETRIEVAL_MAX_LIMIT: usize = 50;
const EXACT_SEARCH_CANDIDATE_MULTIPLIER: usize = 5;
const EXACT_SEARCH_MAX_CANDIDATES: usize = 250;
const FILE_SEARCH_MAX_THREADS: usize = 12;
const QUERY_TIME_INDEX_REVISION: &str = "query-time-bm25-v1";
const QDRANT_INDEX_REVISION_PREFIX: &str = "qdrant-ollama-v1";
const SEMANTIC_MANIFEST_SCHEMA_VERSION: u32 = 1;
@ -490,49 +487,43 @@ fn run_exact_search(
limit: usize,
path_prefixes: &[PathBuf],
) -> Result<Vec<EpiphanyRetrieveResult>> {
let candidate_limit = if path_prefixes.is_empty() {
limit
} else {
limit
.saturating_mul(EXACT_SEARCH_CANDIDATE_MULTIPLIER)
.min(EXACT_SEARCH_MAX_CANDIDATES)
};
#[expect(clippy::expect_used)]
let candidate_limit =
NonZero::new(candidate_limit.max(1)).expect("candidate limit should be non-zero");
let query_terms = exact_search_terms(query);
if query_terms.is_empty() {
return Ok(Vec::new());
}
let search_results = file_search::run(
query,
vec![workspace_root.to_path_buf()],
file_search::FileSearchOptions {
limit: candidate_limit,
threads: search_threads(),
compute_indices: false,
..Default::default()
},
/*cancel_flag*/ None,
)?;
let mut walker = WalkBuilder::new(workspace_root);
walker.hidden(false).follow_links(true).require_git(true);
let mut results = search_results
.matches
.into_iter()
.filter_map(|file_match| {
let relative_path = file_match
.full_path()
let mut results = walker
.build()
.filter_map(Result::ok)
.filter_map(|entry| {
let relative_path = entry
.path()
.strip_prefix(workspace_root)
.ok()?
.to_path_buf();
if relative_path.as_os_str().is_empty() || should_skip_relative_path(&relative_path) {
return None;
}
if !matches_path_prefixes(&relative_path, path_prefixes) {
return None;
}
let file_type = entry.file_type()?;
let kind = if file_type.is_file() {
EpiphanyRetrieveResultKind::ExactFile
} else if file_type.is_dir() {
EpiphanyRetrieveResultKind::ExactDirectory
} else {
return None;
};
let score = score_exact_path_match(&relative_path, &query_terms)?;
Some(EpiphanyRetrieveResult {
kind: match file_match.match_type {
file_search::MatchType::File => EpiphanyRetrieveResultKind::ExactFile,
file_search::MatchType::Directory => EpiphanyRetrieveResultKind::ExactDirectory,
},
kind,
path: relative_path,
score: file_match.score as f32,
score,
line_start: None,
line_end: None,
excerpt: None,
@ -540,17 +531,64 @@ fn run_exact_search(
})
.collect::<Vec<_>>();
sort_results(&mut results);
results.truncate(limit);
Ok(results)
}
fn search_threads() -> NonZero<usize> {
let cores = std::thread::available_parallelism()
.map(NonZero::get)
.unwrap_or(1);
#[expect(clippy::expect_used)]
NonZero::new(cores.clamp(1, FILE_SEARCH_MAX_THREADS))
.expect("file-search threads should be non-zero")
fn exact_search_terms(query: &str) -> Vec<String> {
query
.split(|character: char| !character.is_alphanumeric())
.filter(|term| !term.is_empty())
.map(str::to_lowercase)
.collect()
}
fn score_exact_path_match(relative_path: &Path, query_terms: &[String]) -> Option<f32> {
let normalized_path = normalize_payload_path(relative_path).to_lowercase();
if !query_terms
.iter()
.all(|term| normalized_path.contains(term))
{
return None;
}
let file_name = relative_path
.file_name()
.map(|name| name.to_string_lossy().to_lowercase())
.unwrap_or_default();
let term_score = query_terms.iter().fold(0.0, |score, term| {
score
+ if file_name.contains(term) { 30.0 } else { 0.0 }
+ if normalized_path.contains(term) {
20.0
} else {
0.0
}
});
let joined_query = query_terms.join(" ");
let joined_with_underscores = query_terms.join("_");
let joined_with_hyphens = query_terms.join("-");
let phrase_score = if file_name == joined_query
|| file_name == joined_with_underscores
|| file_name == joined_with_hyphens
{
200.0
} else if file_name.contains(&joined_query)
|| file_name.contains(&joined_with_underscores)
|| file_name.contains(&joined_with_hyphens)
{
100.0
} else if normalized_path.contains(&joined_query)
|| normalized_path.contains(&joined_with_underscores)
|| normalized_path.contains(&joined_with_hyphens)
{
50.0
} else {
0.0
};
let depth_penalty = relative_path.components().count() as f32;
Some(term_score + phrase_score - depth_penalty)
}
#[derive(Clone, Debug)]

View file

@ -36,7 +36,7 @@ remembers doctrine; the branch remembers the blade.
- The active foundation directive is now `notes/codex-starvation-and-cultnet-liberation-plan.md`. The previous Codex app-server control-plane rebuild made Epiphany less rotten inside Codex, but that is not the destination. Epiphany must become a native CultCache/CultNet runtime. Codex is a compatibility reliquary for OpenAI subscription auth and model transport, not the host brain.
- `notes/codex-auth-spine-inventory.md` is the source-grounded keeper list for that reliquary: retain `codex-login` credential storage/refresh, `codex-model-provider` auth resolution, the model-transport subset of `codex-core::client`, and the narrow model-catalog subset of `models-manager`; do not treat Codex app-server, apps, skills, marketplace, plugin UX, MCP OAuth handlers, or collaboration-mode surfaces as auth-spine machinery.
- Edge JSON is allowed for schema description, hostile ingress before immediate typed parsing, sealed forensic artifacts, or named quarantine experiments. When both subsystems are ours, runtime data must remain typed CultCache documents and move over CultNet typed contracts. Generic `serde_json::Value` in worker launch/result/selfPatch/runtime flow is contamination until classified and replaced.
- Durable Epiphany state types now live in root crate `epiphany-state-model`. `codex-protocol` re-exports them only so old rollout/API callers keep compiling; do not add new durable `Epiphany*` state structs under `vendor/codex`. `epiphany-core` imports the native model directly and no longer depends on `codex-protocol`. Pressure derives from native `EpiphanyTokenUsageSnapshot`; Codex token telemetry is mapped at the bridge. Codex rollout/event reconstruction now lives in `codex-core::epiphany_rollout`, where the Codex `RolloutItem` / `EventMsg` types belong. The remaining direct vendored Codex dependency in `epiphany-core` is `codex-file-search`.
- Durable Epiphany state types now live in root crate `epiphany-state-model`. `codex-protocol` re-exports them only so old rollout/API callers keep compiling; do not add new durable `Epiphany*` state structs under `vendor/codex`. `epiphany-core` imports the native model directly and no longer depends on `codex-protocol`. Pressure derives from native `EpiphanyTokenUsageSnapshot`; Codex token telemetry is mapped at the bridge. Codex rollout/event reconstruction now lives in `codex-core::epiphany_rollout`, where the Codex `RolloutItem` / `EventMsg` types belong. Exact retrieval path matching is native to `epiphany-core`, so `epiphany-core` has no direct vendored Codex crate dependency.
- The May 2026 foundation migration in `notes/epiphany-ideal-architecture-rebuild-plan.md` is complete enough to defend. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code, but do not treat it as an open-ended excuse to keep shaving the altar. The rebuild moved scene projection, freshness derivation, pressure policy, targeted context shards, bounded graph traversal, 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, role/reorient result interpretation, role self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`; typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links.
- Read `notes/epiphany-ideal-architecture-rebuild-plan.md` immediately after the teardown. It defines the smallest coherent replacement architecture: durable `EpiphanyState`, runtime-spine-owned `RuntimeState`, separate role memory/heartbeat state, `epiphany-core` as policy owner, app-server as adapter, Aquarium as reflector, typed acceptance receipts, and derived view lenses instead of a protocol verb zoo.
- Do not continue Aquarium UI, bridge, Face, or dogfood expansion until the teardown has a source-grounded cleanup slice plan. Epiphany is the foundation; patches on patches are not a purification rite, they are how the altar becomes load-bearing garbage.
@ -737,14 +737,14 @@ 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: remove or isolate the last direct
vendored Codex dependency in `epiphany-core`, currently `codex-file-search`,
then keep starving the old model turn path out of `thread/epiphany/*` JSON-RPC
and `codex_message_processor.rs`. Success is Epiphany calling the model adapter
from its own CultCache/CultNet runtime boundary while Codex survives only as
subscription auth/model routing. Do not resume Rider, Unity, Aquarium, Face,
dogfood, planning, app, skill, marketplace, or bridge expansion until this
organ is being cut cleanly.
The whale-carcass cut reached native core: `epiphany-core` no longer depends on
vendored `codex-file-search`; exact retrieval path matching is owned by
retrieval itself. Keep starving the old model turn path out of
`thread/epiphany/*` JSON-RPC and `codex_message_processor.rs`. Success is
Epiphany calling the model adapter from its own CultCache/CultNet runtime
boundary while Codex survives only as subscription auth/model routing. Do not
resume Rider, Unity, Aquarium, Face, dogfood, planning, app, skill,
marketplace, or bridge expansion until this organ is being cut cleanly.
The Phase 6 freshness slice is landed. It exposes read-only
`thread/epiphany/freshness` from live retrieval summaries plus graph

Binary file not shown.

File diff suppressed because one or more lines are too long

1
vendor/codex/codex-rs/Cargo.lock generated vendored
View file

@ -5244,7 +5244,6 @@ dependencies = [
"anyhow",
"bm25",
"chrono",
"codex-file-search",
"cultcache-rs",
"cultnet-rs",
"epiphany-openai-adapter",