Synced from monorepo Changes: - grok-shell: send an expired external-provider credential to the sign-in flow, not a 401 loop - pager: clickable ▲ jumps to the top of the response being read - grok-shell: keep a large task log from making the completion message too long - Plan viewer scrollbar: widen grab zone to the border column; fix striped thumb in Terminal.app - pager: poll the tmux probe teardown grace instead of sleeping it - security: vendor-compat MCP kill switch is now actually enforced when reported as on - grok-shell: restore session eviction when a leader client disconnects - Bump rust-toolchain to 1.93.0 - workspace: lexical-normalize permission path patterns before glob matching - pager: reject garbage Enter in the /resume picker - pager: show Mermaid affordances in plan mode preview - pager: drop manage-account link from /session-info - workspace: auto-approve read-only git queries; defer write floor to auto classifier - Add free-form pattern editor to the "Always allow" command prompt - grok-shell: fix /btw caching - pager: Tab walks answers in the ask_user_question card - External-provider auth refresh: single 7s attempt instead of 3×5s - pager: don't resurrect finished background tasks as Running when completion arrives first - pager: report tmux truecolor clamping in Doctor - Fix plan viewer scrollbar click+drag hijacked by comment gutter - pager/shell: stop double Recap after the same last turn - sampler: preserve x-should-retry through stream collection - pager: clear plan-mode indicator immediately when the user approves a plan - pager: tmux does not re-read its config on reattach Source-Revision: 64c4de99cc822b25ce9c54ab5a4f372093d0885d
117 lines
3.8 KiB
Rust
117 lines
3.8 KiB
Rust
//! ACP extension handler for session search (`x.ai/session/search`).
|
|
//!
|
|
//! Exposes session full-text search as an ACP extension method.
|
|
//! The client sends a query and receives ranked results across all
|
|
//! (or workspace-filtered) past sessions.
|
|
//!
|
|
//! ```text
|
|
//! JSON-RPC -> mvp_agent.ext_method()
|
|
//! -> session_search::handle()
|
|
//! -> storage::search::execute_search()
|
|
//! -> search_fts::SessionSearchIndex (SQLite FTS5)
|
|
//! ```
|
|
|
|
use agent_client_protocol as acp;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::session::storage::search::{SessionSearchRequest, SessionSearchResponse};
|
|
use crate::session::storage::search_fts::SessionSearchRow;
|
|
|
|
use super::ExtResult;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub(crate) struct SearchSessionsRequest {
|
|
/// The search query string.
|
|
pub query: String,
|
|
/// Optional workspace directory to scope results to.
|
|
#[serde(default)]
|
|
pub cwd: Option<String>,
|
|
/// Maximum number of results to return. Defaults to 20.
|
|
#[serde(default = "default_limit")]
|
|
pub limit: usize,
|
|
/// Offset for pagination. Defaults to 0.
|
|
#[serde(default)]
|
|
pub offset: usize,
|
|
/// Whether to include content snippets in results.
|
|
#[serde(default)]
|
|
pub include_content: bool,
|
|
}
|
|
|
|
fn default_limit() -> usize {
|
|
20
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub(crate) struct SearchSessionsResponse {
|
|
pub results: Vec<SearchSessionHit>,
|
|
pub next_offset: Option<usize>,
|
|
pub total_estimate: Option<usize>,
|
|
/// True when the FTS5 index is still being bootstrapped.
|
|
pub bootstrapping: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SearchSessionHit {
|
|
pub session_id: String,
|
|
pub cwd: String,
|
|
/// Session title/summary for display
|
|
pub summary: String,
|
|
/// RFC 3339 formatted updated_at
|
|
pub updated_at: String,
|
|
pub score: f32,
|
|
pub matched_fields: Vec<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub snippet: Option<String>,
|
|
}
|
|
|
|
/// Route `x.ai/session/search` extension method calls.
|
|
pub async fn handle(args: &acp::ExtRequest) -> ExtResult {
|
|
match args.method.as_ref() {
|
|
"x.ai/session/search" => {
|
|
let req: SearchSessionsRequest = super::parse_params(args)?;
|
|
let internal_req = SessionSearchRequest {
|
|
query: req.query,
|
|
cwd: req.cwd,
|
|
limit: req.limit,
|
|
offset: req.offset,
|
|
include_content: req.include_content,
|
|
};
|
|
|
|
let root_dir = crate::util::grok_home::grok_home();
|
|
let result = crate::session::storage::search::execute_search(&root_dir, &internal_req)
|
|
.await
|
|
.map(to_response)
|
|
.map_err(|e| anyhow::anyhow!(e));
|
|
|
|
super::to_ext_response(result)
|
|
}
|
|
_ => Err(acp::Error::method_not_found()),
|
|
}
|
|
}
|
|
|
|
/// Convert the internal response to the ACP-facing response.
|
|
fn to_response(resp: SessionSearchResponse) -> SearchSessionsResponse {
|
|
SearchSessionsResponse {
|
|
results: resp
|
|
.results
|
|
.into_iter()
|
|
.map(|row: SessionSearchRow| SearchSessionHit {
|
|
session_id: row.session_id,
|
|
cwd: row.cwd,
|
|
summary: row.title,
|
|
updated_at: chrono::DateTime::from_timestamp(row.updated_at_unix, 0)
|
|
.map(|dt| dt.to_rfc3339())
|
|
.unwrap_or_default(),
|
|
score: row.score,
|
|
matched_fields: row.matched_fields,
|
|
snippet: row.snippet,
|
|
})
|
|
.collect(),
|
|
next_offset: resp.next_offset,
|
|
total_estimate: resp.total_estimate,
|
|
bootstrapping: resp.bootstrapping,
|
|
}
|
|
}
|