refactor: align project directory architecture

This commit is contained in:
leookun committed 2026-08-29 20:45:51 +08:00
1 parent 88f258f184
commit 279e6bb07c
236 files changed
+1982 -57487

No files matched your search

+1 -1
View File
@@ -193,7 +193,7 @@ impl CursorActor {
return;
}
let cancellation = handle.cancellation();
let (port, core) = crate::client::session(256);
let (port, core) = crate::run::session(256);
let core_commands = core.commands.clone();
let actor = RunActor::new(
dependencies.store.clone(),
+1 -2
View File
@@ -3,7 +3,6 @@ use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use tokio::sync::{mpsc, oneshot};
use crate::{
client::{ClientCommand, ClientEvent, ClientSession, CommitCause},
cursor::{
blob_sync::BlobSynchronizer,
checkpoint::{
@@ -26,7 +25,7 @@ use crate::{
},
},
model::{ToolCall, ToolRoundId, Usage},
run::{RunFailure, RunOutcome},
run::{ClientCommand, ClientEvent, ClientSession, CommitCause, RunFailure, RunOutcome},
store::{Store, ToolRoundStatus},
Error, Result,
};
@@ -3,7 +3,7 @@
use crate::{
cursor::{interaction, proto::agent::v1 as pb},
model::ToolCall,
web::{WebFetch, WebSearch},
search::{WebFetch, WebSearch},
Error, Result,
};
@@ -117,7 +117,7 @@ mod tests {
use crate::{
cursor::{proto::agent::v1 as pb, tools::result::tool_result_channel},
model::ToolCall,
web::{HtmlEngine, WebFetch, WebSearch},
search::{HtmlEngine, WebFetch, WebSearch},
};
use super::{resume, InteractionContinuation, PendingInteraction};
+1 -1
View File
@@ -9,8 +9,8 @@ use std::collections::BTreeMap;
use crate::{
cursor::proto::agent::v1 as pb,
model::ToolCall,
search::{WebFetch, WebSearch},
store::Store,
web::{WebFetch, WebSearch},
Error, Result,
};
+14 -177
View File
@@ -1,79 +1,30 @@
//! Asynchronous dispatch for the application-owned Semble search tools.
//! Cursor tool orchestration for application-owned Semble search.
use std::sync::Arc;
use semble_core::{ContentType, FindRelatedRequest, SearchEngine, SearchRequest, SembleConfig};
use serde::Deserialize;
use serde_json::Value;
use tokio::sync::OnceCell;
use crate::{model::ToolCall, store::Store, Error, Result};
use super::ToolStart;
use crate::cursor::tools::{
result::{self, ToolResultSender},
runtime::now_ms,
use crate::{
cursor::tools::{
result::{self, ToolResultSender},
runtime::now_ms,
},
model::ToolCall,
search,
store::Store,
Result,
};
static ENGINE: OnceCell<Arc<SearchEngine>> = OnceCell::const_new();
#[derive(Clone, Copy, Debug, Default, Deserialize)]
#[serde(rename_all = "snake_case")]
enum ContentSelection {
#[default]
Code,
Docs,
Config,
All,
}
#[derive(Debug, Deserialize)]
struct SearchArguments {
query: String,
repo: String,
#[serde(default = "default_top_k")]
top_k: usize,
#[serde(default = "default_snippet_lines")]
max_snippet_lines: Option<usize>,
#[serde(default)]
content: ContentSelection,
}
#[derive(Debug, Deserialize)]
struct FindRelatedArguments {
repo: String,
file_path: String,
line: usize,
#[serde(default = "default_top_k")]
top_k: usize,
#[serde(default = "default_snippet_lines")]
max_snippet_lines: Option<usize>,
#[serde(default)]
content: ContentSelection,
}
use super::ToolStart;
pub(super) fn start(
results: &ToolResultSender,
call: &ToolCall,
store: Option<Store>,
) -> Result<ToolStart> {
let operation = match super::normalized(&call.name).as_str() {
"semblesearch" => Operation::Search(serde_json::from_value(call.arguments.clone())?),
"semblefindrelated" => {
Operation::FindRelated(serde_json::from_value(call.arguments.clone())?)
}
_ => {
return Err(Error::Protocol(format!(
"unsupported Semble tool: {}",
call.name
)))
}
};
let tool_name = super::normalized(&call.name);
let arguments = call.arguments.clone();
let call = call.clone();
let results = results.clone();
let started_at_ms = now_ms();
tokio::spawn(async move {
let output = execute(operation, store).await;
let output = search::execute_semble(&tool_name, arguments, store).await;
match result::semble(&call, started_at_ms, output) {
Ok(completion) => results.send(completion),
Err(error) => results.send_error(error),
@@ -84,117 +35,3 @@ pub(super) fn start(
completion: None,
})
}
enum Operation {
Search(SearchArguments),
FindRelated(FindRelatedArguments),
}
async fn execute(operation: Operation, store: Option<Store>) -> std::result::Result<Value, String> {
let engine = engine(store).await.map_err(|error| error.to_string())?;
tokio::task::spawn_blocking(move || match operation {
Operation::Search(arguments) => engine
.search(SearchRequest {
query: arguments.query,
repo: arguments.repo.into(),
top_k: arguments.top_k,
max_snippet_lines: arguments.max_snippet_lines,
content: content(arguments.content),
})
.and_then(json_value),
Operation::FindRelated(arguments) => engine
.find_related(FindRelatedRequest {
repo: arguments.repo.into(),
file_path: arguments.file_path,
line: arguments.line,
top_k: arguments.top_k,
max_snippet_lines: arguments.max_snippet_lines,
content: content(arguments.content),
})
.and_then(json_value),
})
.await
.map_err(|error| format!("Semble search worker failed: {error}"))?
.map_err(|error| error.to_string())
}
async fn engine(store: Option<Store>) -> Result<Arc<SearchEngine>> {
ENGINE
.get_or_try_init(|| async move {
let builder = match store {
Some(store) => crate::network::blocking_client_builder(&store).await?,
None => reqwest::blocking::Client::builder().use_native_tls(),
};
tokio::task::spawn_blocking(move || {
let client = builder.build()?;
SearchEngine::load_default_with_client(SembleConfig::default(), &client)
.map(Arc::new)
.map_err(|error| Error::Config(format!("load Semble search engine: {error}")))
})
.await
.map_err(|error| Error::Config(format!("load Semble search engine: {error}")))?
})
.await
.cloned()
}
fn json_value(response: semble_core::SearchResponse) -> semble_core::Result<serde_json::Value> {
serde_json::to_value(response)
.map_err(|error| semble_core::Error::Serialization(error.to_string()))
}
fn content(selection: ContentSelection) -> Vec<ContentType> {
match selection {
ContentSelection::Code => vec![ContentType::Code],
ContentSelection::Docs => vec![ContentType::Docs],
ContentSelection::Config => vec![ContentType::Config],
ContentSelection::All => vec![ContentType::Code, ContentType::Docs, ContentType::Config],
}
}
fn default_top_k() -> usize {
5
}
fn default_snippet_lines() -> Option<usize> {
Some(10)
}
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
#[test]
fn search_arguments_use_code_search_defaults() {
let arguments: SearchArguments = serde_json::from_value(json!({
"query": "request persistence",
"repo": "/tmp/repo"
}))
.unwrap();
assert_eq!(arguments.top_k, 5);
assert_eq!(arguments.max_snippet_lines, Some(10));
assert!(matches!(arguments.content, ContentSelection::Code));
}
#[test]
fn find_related_does_not_require_a_ui_description() {
let arguments: FindRelatedArguments = serde_json::from_value(json!({
"repo": "/tmp/repo",
"file_path": "src/auth.ts",
"line": 42
}))
.unwrap();
assert_eq!(arguments.file_path, "src/auth.ts");
assert_eq!(arguments.line, 42);
}
#[test]
fn all_content_expands_to_every_indexed_scope() {
assert_eq!(
content(ContentSelection::All),
vec![ContentType::Code, ContentType::Docs, ContentType::Config]
);
}
}
+1 -1
View File
@@ -18,8 +18,8 @@ mod tests;
use crate::{
model::{CanonicalMessage, MessageContent, Role, ToolCall},
search::{WebFetch, WebSearch},
store::Store,
web::{WebFetch, WebSearch},
Error, Result,
};
@@ -1,6 +1,6 @@
use crate::{
cursor::{interaction, proto::agent::v1 as pb},
web::{FetchedPage, SearchHit},
search::{FetchedPage, SearchHit},
Error, Result,
};
@@ -335,7 +335,7 @@ mod tests {
use crate::{
cursor::proto::agent::v1 as pb,
model::ToolCall,
web::{FetchedPage, SearchHit},
search::{FetchedPage, SearchHit},
};
use super::{complete_web_fetch, complete_web_search, PendingInteraction};