Move retrieval query law to core
This commit is contained in:
parent
ac9550fa84
commit
fa222584e4
6 changed files with 68 additions and 32 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -70,6 +70,29 @@ impl EpiphanyRetrieveQuery {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn normalize_epiphany_retrieve_query(
|
||||
query: String,
|
||||
limit: Option<u32>,
|
||||
path_prefixes: Vec<PathBuf>,
|
||||
) -> std::result::Result<EpiphanyRetrieveQuery, &'static str> {
|
||||
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()?;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because one or more lines are too long
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Reference in a new issue