grokkit/todo/queued/rg.md
Greg Gauthier 95ce892fa4
All checks were successful
CI / Test (push) Successful in 34s
CI / Lint (push) Successful in 39s
CI / Build (push) Successful in 21s
docs(todo): update queued task priorities and add README
Adjusted priorities for features including audit, changelog, gotools, interactive-agent, and rg.
Added todo/README.md as a table of contents listing all queued and completed tasks.
2026-03-03 21:00:03 +00:00

2.1 KiB

grokkit agent ripgrep (rg) integration

Priority: 7 of 12

Description: Fast search wrapper for ripgrep (rg). Enables agent to grep project for symbols/patterns/context before edits.

Problem It Solves

Agent lacks quick codebase search—relies on full file scans or manual grep. rg is 10x faster, regex-aware.

Benefits

  • Lightning search: Multi-line, git-ignored, type-aware (--type=go).
  • Context gathering: "rg 'err handling' → snippets for prompt".
  • Safe: Read-only, project-only, no filespecs.
  • Stats: Count matches, paths.
  • Workflow: "Search todos → prioritize → edit".

Agent Tool Examples

grokkit agent "Find all error returns in cmd/, improve handling"
# Grok: rg 'return err' cmd/ → analyzes → targeted edits
grokkit agent "Count test coverage gaps: rg 't.Skip' or untested funcs"
# Grok: rg --type=go '_test\.go' → stats → testgen suggestions

High-Level Implementation

  1. Detect: rg --version.
  2. Tool schemas:
    • search(pattern: string, path?: string) → matches[]
    • count(pattern: string) → int
  3. Wrappers in internal/tools/rg.go:
    func Search(ctx context.Context, args map[string]any) (string, error)
    
  4. Agent integration: Pre-plan search → richer context.
  5. Safety:
    • Args whitelist: --type, --no-heading, project root.
    • Max 100 matches.
    • Config: [tools.rg.enabled].
  6. Parsing: JSON output (--json), or lines → structured.

Flags / Config

Key Description
tools.rg.enabled Enable rg tools
tools.rg.max_matches Limit results

Implementation Notes

  • Commands: rg PATTERN [PATH] --no-heading --colors=never.
  • Extend agent: Optional search phase in planning.
  • Errors: RgError.
  • Tests: Mock, table-driven patterns.
  • Effort: Low (~100 LOC).
  • Prereq: rg installed (apt install ripgrep).

ROI

High. Search is dev superpower:

Stage Covered
Search rg ← new
Edit agent
Verify make (sibling)

Agent plans smarter with instant intel.