feat: in-process ast-grep structural search tool#392
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8936c07b03
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8a42521 to
c8312fa
Compare
Add tracedecay_ast_grep_search: a read-only structural (AST) search tool for call shapes, argument orders, and expression forms that a text regex cannot express. Structural search previously had no tool at all — only tracedecay_ast_grep_rewrite existed. Backend: ast-grep-core as a LIBRARY, not the CLI. It is generic over a tree-sitter Language, so the repo's own bundled 0.26 grammars (via extraction::ts_provider) are wired into its Language trait. Compat check: ast-grep-core 0.44 pins tree-sitter ^0.26.3, ABI-compatible with the 0.26 grammars this repo builds — TSLanguage is exactly tree_sitter::Language. Result: no external ast-grep binary, no new grammar crates, no ast_grep_available() gating (the tool registers unconditionally). The existing CLI-backed ast_grep_rewrite tool is left unchanged. Metavariable pre-processing and per-language expando chars mirror ast-grep-language so pattern semantics match the upstream CLI. Each hit is graph-enriched with its enclosing symbol like tracedecay_grep. Also: - hints: extend the search category to route structural patterns to ast_grep_search (existing rewrite mention in the edit category kept); hint-signature drift guard still green. - skills: exploring-code gains a structural-search row; editing-safely links search->rewrite. - evals: one active search scenario (grounded in the fixture) and one deferred rewrite scenario (fixture has a single call site; rewrite tool is CLI-gated). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
c8312fa to
f7c8776
Compare
What
Adds
tracedecay_ast_grep_search— a read-only structural (AST) search tool for call shapes, argument orders, and expression forms that a text regex cannot express. Structural search previously had no tool at all; onlytracedecay_ast_grep_rewriteexisted.Backend: ast-grep as a library, not the CLI
Per the design directive, this evaluates
ast-grep-coreas an in-process backend and ships it:ast-grep-core0.44 pinstree-sitter ^0.26.3; this repo builds its grammars againsttree-sitter0.26.8 — same 0.26 minor, ABI-compatible.ast_grep_core::tree_sitter::TSLanguageis a re-export oftree_sitter::Language, exactly whatextraction::ts_provider::try_languagealready returns.TdLangwrapper implements ast-grep-core'sLanguage/LanguageExttraits over the repo's own bundled grammars — no new grammar crates, no externalast-grepbinary, and noast_grep_available()gating (the tool registers unconditionally). Metavariable pre-processing and per-language expando chars (µ,𐀀,_) are mirrored fromast-grep-languageso pattern semantics match the upstream CLI.ast_grep_rewritetool is left unchanged (library-backed rewrite, with its apply/diff semantics, is a follow-up).New deps:
ast-grep-core(+bit-set/bit-vec). No new tree-sitter grammar crates.Tool
pattern(required),lang(optional; auto-detected per file otherwise),path_glob(optional scope),max_results(default 50, cap 200).format: json; each hit is graph-enriched with its enclosing symbol liketracedecay_grep, so the next call istracedecay_body. CLI twin works:tracedecay tool tracedecay_ast_grep_search.Discovery wiring
tracedecay_ast_grep_search(the edit category keeps itsast_grep_rewritemention). Hint-signature drift guard stays green.exploring-codegains a structural-search routing row;editing-safelylinks search→rewrite.reserve_stock(...)three-arg call shape inplace_order), and one deferred rewrite scenario (fixture has a single call site and the rewrite tool is CLI-gated).Gates (all green)
cargo fmt --checkcargo clippy --workspace --all-targets --locked -- -D warningscargo nextest run --test mcp_suite --test agent_suite --no-fail-fast→ 852 + 488 passgrade.py --lint-only(53 neutral),--check-hints(21 signatures intact),selftest.py(all pass)Live smoke (against this repo)
pattern: "ToolResult::new($$$)"→ real matches with enclosing symbols, e.g.:🤖 Generated with Claude Code
Review follow-up
The working-tree walk and AST parsing now run on Tokio's blocking pool so a broad or zero-match search cannot stall the MCP async runtime. Added a current-thread wrapper regression; focused engine tests and full clippy remain green.