feat(runtime): code_search workspace regex search tool (#6295)#6307
Merged
Conversation
Coding agents previously located code by looping file_list + file_read, spending tool calls and context rediscovering structure. code_search regex-searches every text file under a workspace-relative path in one call and returns relpath:line: content rows. It skips .git/target/node_modules, hidden, binary, and >2MB files; sorts results by path then line for deterministic output (#3298); and bounds the response with max_results (default 100, hard cap 1000). Read-only, always-native (no approval gate, like file_list), zero new dependencies — a hand-rolled tokio::fs DFS plus the existing regex crate. First lexical-only slice of the #6295 workspace code-intelligence layer; structural symbol indexing, repo maps, and LSP/vector backends are out of scope here and tracked as later stages. Wiring: tool_name const + ToolDefinition + ALWAYS_NATIVE_TOOLS (definitions.rs), dispatch match arm (dispatch.rs), handler + tests (search.rs), guest read-only allowlist (kernel/auth.rs), and tool category/hint (prompt_builder.rs).
houko
enabled auto-merge (squash)
June 24, 2026 04:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First slice of the #6295 workspace code-intelligence layer: a
code_searchagent tool that regex-searches the workspace in one call.Coding agents currently locate code by looping
file_list+file_read— there is nogrep-equivalent built-in.code_searchcloses that gap: one call returnsrelpath:line: contentrows for every match under a workspace-relative path.Scope (deliberately minimal)
Lexical / regex search only. Structural symbol indexing, repo maps, reference graphs, and LSP / vector backends from @pavver's proposal are out of scope for this slice and tracked as later stages of #6295. Starting with lexical search follows the discussion's "FTS / repo maps before LSP and vectors" ordering and keeps the first slice small and reviewable.
Behaviour
query(regex, required),path(workspace-relative, default root),case_sensitive(default false),max_results(default 100, hard cap 1000)..git/.hg/.svn/target/node_modules, hidden dirs, symlinks (not followed), binary files (NUL-byte sniff), and files larger than 2 MB. Caps total files scanned at 20k.charboundary; truncation is flagged in the output.Design decisions
tokio::fs::read_dirDFS + the already-vendoredregexcrate. Nowalkdir, notree-sitter.librefang-runtime/src/tool_runner/search.rs, wired like any other built-in tool — no new crate (the crate-boundary question from Workspace Code Intelligence Layer for Coding Agents #6295 is left for the structural-index stage).ALWAYS_NATIVE_TOOLS(eager, no lazy-load round-trip) and to the guest read-only allowlist inkernel/auth.rs, so it needs no approval gate — same treatment asfile_list. Path access goes through the existingresolve_file_path_extsandbox.Wiring
tool_runner/search.rs— handlertool_code_search+ 5 unit tests.tool_runner/definitions.rs—tool_name::CODE_SEARCH,ToolDefinition(JSON schema),ALWAYS_NATIVE_TOOLS.tool_runner/dispatch.rs—"code_search"match arm (named-workspace + download-dir read allowlist, likefile_list).tool_runner/mod.rs—mod search;+ handler import.kernel/auth.rs— guestREAD_ONLY_TOOLSallowlist.prompt_builder.rs—tool_category(Files) +tool_hint.Tests (in
search.rs)missing_query_is_missing_parameterinvalid_regex_is_invalid_parameterfinds_matches_with_line_numbersis_case_insensitive_by_default_and_respects_flagskips_git_dir_and_binary_filesno_matches_returns_friendly_messageVerification
This box has no native Rust toolchain and Docker was unavailable in this session, so
cargo check/cargo fmtcould not be run locally (the pre-commit fmt hook took its documented no-rustfmt soft-skip). CI is the authoritative check — the runtime unit lane compiles + runs the new tests, and the fmt lane validates formatting. Types were cross-checked against thefile_listhandler template (ToolError/ToolResult/resolve_file_path_extsignatures) and the existing drift tests (no_duplicate_tool_names,tools.len() at least 40) cover the new registration.refs #6295