Skip to main content

Module trusty_search

Module trusty_search 

Source
Expand description

search_code tool: trusty-search-backed code discovery (PR A).

Why: local glob/grep/list_dir (#2685) find code by literal text only; the engineer routinely needs CONCEPTUAL discovery — “where is X”, “how does Y work”, “what calls Z” — which literal search cannot answer. trusty-search already indexes every registered project for semantic (embedding) and call-graph (KG) retrieval and ships as an MCP binary. This tool makes that the PRIMARY discovery path for the engineer while the local literal tools stay as the graceful-degrade FALLBACK: when trusty-search is not installed, not running, or its index is not ready, the tool returns a SUCCESSFUL “unavailable — use grep/glob” result rather than an error that would derail the agent loop (mirrors recall_session‘s fail-open contract). What: TrustySearchTool implements ToolExecutor. It lazily spawns trusty-search serve via the SHARED trusty_common::stdio_mcp_client (never a bespoke MCP/HTTP client — common-entry-point principle, mirroring trusty-agents’ TrustySearchPlugin), runs the MCP handshake, and resolves the project’s index id from list_indexes. A single search_code tool with a mode param routes to trusty-search’s real lanes: semantic (search_semantic), symbol (search_kg), and grep (grep). One tool keeps the advertised schema surface minimal and mirrors trusty-search’s own lane taxonomy. A STAGE_NOT_READY on the semantic/symbol lane (the vector stage is still building on a freshly-indexed repo) transparently retries via the always-available lexical lane and returns those degraded hits instead of empty (issue #2783). Any remaining spawn/handshake/timeout/missing-index condition is fail-open: a non-error ToolResult telling the model to use the local grep/glob tools instead. Test: tests::pick_index_prefers_exact_match, tests::pick_index_falls_back_to_longest_ancestor, tests::execute_fail_open_when_binary_absent, tests::execute_rejects_malformed_args_recoverably, tests::schema_advertises_mode_and_query, tests::mcp_text_extracts_content, tests::is_mcp_error_detects_error_flag, tests::is_stage_not_ready_detects_meta_code, tests::should_lexical_fallback_only_for_stage_not_ready, tests::lexical_params_matches_search_lexical_schema.

Structs§

TrustySearchTool
ToolExecutor for the search_code discovery tool (PR A).

Constants§

SEARCH_CODE_TOOL_NAME
The tool’s registered/advertised name.