Skip to content

Update search tools to redirect dotted queries to symbol references (#6) - #134

Open
Spandan-Mishra wants to merge 1 commit into
unstablebuild:mainfrom
Spandan-Mishra:feat/agent-redirect-dotted-search-to-lsp-refs
Open

Spandan-Mishra wants to merge 1 commit into
unstablebuild:mainfrom
Spandan-Mishra:feat/agent-redirect-dotted-search-to-lsp-refs

Conversation

@Spandan-Mishra

Copy link
Copy Markdown
Contributor

Summary

Resolves #6 by intercepting dotted query patterns in search_content and grep_files (e.g. pkg.Symbol) and redirecting them to indexed symbol resolution and LSP references.

When an agent issues a dotted query, resolving via LSP references directly avoids expensive, slow filesystem walks across large repositories while prepending an educational note to guide the agent toward using find_references directly.

Behavior Matrix

Pattern / State Parser Symbol Match LSP References Found Outcome Note Present?
pkg.Symbol (dotted) Yes Yes (>= 1) Return references; skip regex walk Yes
pkg.NonExistent (dotted) No / Error N/A Fall back to standard regex walk No
pkg.Unreferenced (dotted) Yes No (0) Fall back to standard regex walk No
Symbol (bare, no dot) N/A (parser not queried) N/A Standard regex walk No
pkg.Symbol (LSP or parser nil) N/A N/A Standard regex walk No

Implementation Details

  1. Dependency Plumbing:

    • Extended agentools.DefaultTools, newSearch, and NewGrepFiles to accept lsp semanticapi.LSP and parser syntaxapi.Parser.
    • Wired dependencies at extension command handler, headless bootstrap, and dream agent boundaries.
  2. Resolution & References:

    • Added resolveIndexedSymbol in cmd/rune-agent/agent/agentools/lsp.go using parser.ResolveSymbol(ctx, symbol, nil) with strict indexed lookup (no fuzzy workspace fallback).
    • Added resolveDottedReferences to short-circuit non-dotted patterns, locate definitions, and query lsp.References with IncludeDeclaration: true.
  3. Tool Execution:

    • search.go: When references are found, formats line snippets via renderMultiLocation, tracks discovered files with FileTracker.TrackDiscovery, and prepends the educational note.
    • grep_files.go: When references are found, collects deduplicated relative file paths, applies truncation limits, tracks discovery, and prepends the educational note.

Testing

  • Added hermetic table-driven regression tests in cmd/rune-agent/agent/agentools/search_redirect_test.go asserting all 5 behavior rows, walk skipping via atomic ReadDir counters, parser call gating, and discovery tracking.
  • Verified test suite:
    go test -race ./cmd/rune-agent/agent/agentools/...
    go test -race ./cmd/rune-agent/...

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.96296% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/rune-agent/agent/agentools/lsp.go 83.67% 4 Missing and 4 partials ⚠️
cmd/rune-agent/extension/handler.go 0.00% 3 Missing ⚠️
cmd/rune-agent/headless/bootstrap.go 0.00% 1 Missing ⚠️
cmd/rune-agent/memory/dream/dream.go 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

When search_content or grep_files receives a query containing a dot
(e.g., "pkg.Symbol"), resolve the pattern against the indexed syntax
parser and query LSP references. If references exist, return them directly
with an educational note pointing the model toward find_references,
skipping the expensive repository-wide filesystem regex walk.

Fall back to the normal regex walk if the pattern contains no dot, does
not resolve in the parser, yields zero references, or if parser or LSP
dependencies are nil.

Fixes unstablebuild#6

Signed-off-by: Spandan Mishra <spandanmishra69@gmail.com>
@Spandan-Mishra
Spandan-Mishra force-pushed the feat/agent-redirect-dotted-search-to-lsp-refs branch from 97cd381 to 2421cf0 Compare September 26, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redirect dotted search_content/grep_files queries to symbol references

2 participants