Skip to content

feat(docs,hooks): enforce rgai-first search policy#125

Open
heAdz0r wants to merge 3 commits intortk-ai:masterfrom
heAdz0r:feat/rgai-search-policy
Open

feat(docs,hooks): enforce rgai-first search policy#125
heAdz0r wants to merge 3 commits intortk-ai:masterfrom
heAdz0r:feat/rgai-search-policy

Conversation

@heAdz0r
Copy link

@heAdz0r heAdz0r commented Feb 14, 2026

Summary

Extracted from #118 per reviewer feedback. This PR adds the search policy documentation and hook rewrites that depend on #123 (upsert refactor) and #124 (rtk rgai command).

Depends on: #123, #124

What changed

Hook rewrite rules (hooks/rtk-rewrite.sh, .claude/hooks/rtk-rewrite.sh):

  • Tier 1: grepai search <query> / rgai search <query>rtk rgai <query>
  • Tier 1: rgai <query>rtk rgai <query>
  • Tier 2: rg <pattern>rtk grep <pattern> (split from combined rule)
  • Tier 3: grep <pattern>rtk grep <pattern> (split from combined rule)
  • Deterministic: most specific patterns match first

Documentation (README, INSTALL, TROUBLESHOOTING, awareness template):

  • Search priority section: rgai > rg > grep
  • Search ladder: rtk rgairtk greprtk proxy
  • Updated command tables with rtk rgai examples
  • Removed unverifiable benchmark table (was citing private repository data)

Templates (src/init.rs):

  • RTK_INSTRUCTIONS: added rtk rgai to Files & Search section
  • show_config(): displays search priority hint

Test fixes:

  • Fixed 3 pre-existing test failures (find/tree/wget expected no rewrite but hook already rewrites them on master)
  • Added 7 new hook tests for rgai/grepai rewrite rules

Benchmark table removal

The benchmark table from #118 cited "internal migration benchmark artifacts (private repository)" — not verifiable by contributors. Removed entirely. A follow-up PR will add a reproducible benchmark using a public dataset or synthetic test set.

Test plan

  • cargo test — 325 tests pass
  • cargo fmt --all --check — clean
  • bash hooks/test-rtk-rewrite.sh — 57/57 pass (was 54/57 on master)
  • No search policy references leak without the rgai command being available

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).
Replace naive append-or-skip logic in run_claude_md_mode with
upsert_rtk_block() that handles all 4 cases:
- Added: no existing block → append
- Updated: stale block → replace in-place
- Unchanged: current block → no-op
- Malformed: opening marker without closing → warn safely

Includes 4 unit tests covering each case.
Search priority (mandatory): rgai > rg > grep.

Hook changes:
- Add rewrite rules: grepai/rgai search -> rtk rgai (Tier 1)
- Split rg and grep into separate rules (Tier 2/3)
- Source-of-truth comment for hook sync
- Test infrastructure: HOOK env override, script-relative path

Doc updates (README, INSTALL, TROUBLESHOOTING, awareness template):
- Add search priority section
- Update command tables with rtk rgai examples
- Add search ladder (rgai -> grep -> proxy)
- Remove unverifiable benchmark table

Template updates (init.rs):
- RTK_INSTRUCTIONS: add rtk rgai to Files & Search section
- show_config: display search priority hint
- Tests: assert rtk rgai in top-level commands list

Test fixes:
- Fix pre-existing find/tree/wget test expectations (hook already
  rewrites them on master, tests incorrectly expected no rewrite)
- Add 7 new hook tests for rgai/grepai rewrite rules
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