Skip to content

feat: add rtk rgai command for semantic code search#124

Open
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
heAdz0r:feat/rgai-command
Open

feat: add rtk rgai command for semantic code search#124
heAdz0r wants to merge 1 commit intortk-ai:masterfrom
heAdz0r:feat/rgai-command

Conversation

@heAdz0r
Copy link

@heAdz0r heAdz0r commented Feb 14, 2026

Summary

Extracted from #118 per reviewer feedback. This is the actual feature implementation — the command that #118's docs/hooks referenced but didn't include.

rtk rgai is a Rust-native semantic search that scores files by term relevance without requiring external embedding services.

Usage

rtk rgai "auth token refresh"              # multi-word semantic query
rtk rgai auth token refresh --compact      # unquoted, compact output
rtk rgai "error handler" --json            # machine-readable JSON
rtk rgai "database migration" -t rust      # filter by file type
rtk rgai "auth flow" -p ./src              # explicit path

How it works

  1. Parse query → remove stop words, stem tokens
  2. Walk project (gitignore-aware, skip binary/large files)
  3. Score each line: term match (+1.4-1.7), phrase match (+6.0), multi-term bonus (+1.2), symbol definition boost (+2.5), comment penalty (×0.7)
  4. Score each file: path relevance + top snippet scores + match density
  5. Rank files, emit top N with context snippets

Token savings

  • 75-90% reduction vs raw grep output (fewer files, ranked by relevance, truncated lines)
  • Compact mode: 1 snippet per file, 0 context lines
  • JSON mode: structured output for programmatic consumption

Changes

  • src/rgai_cmd.rs: 789 lines — full search implementation with scoring, ranking, output formatting
  • src/main.rs: Commands::Rgai variant, match arm, normalize_rgai_args() for backward-compat path detection

Test plan

  • cargo test rgai — 8 tests pass (5 unit + 3 arg normalization)
  • cargo test — 321 total tests pass
  • cargo fmt --all --check — clean
  • cargo clippy --all-targets — no new warnings
  • Manual: rtk rgai "token tracking" -p . returns ranked results from this repo

Rust-native semantic search that scores files and lines by term
relevance, symbol definitions, and path matching. No external
dependencies (no grepai/embeddings required).

Features:
- Natural-language multi-word queries: rtk rgai "auth token refresh"
- File scoring with symbol definition boost (+2.5) and comment penalty
- Stop word removal + basic stemming for better recall
- Compact and JSON output modes
- File type filtering (--file-type ts/py/rust/etc.)
- gitignore-aware traversal via `ignore` crate
- Binary and large file skipping
- Backward-compat: trailing path token auto-detection

Includes 8 unit tests (5 in rgai_cmd, 3 for arg normalization).
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.

1 participant