Skip to content

Comments

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

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

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
Contributor

@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
@heAdz0r
Copy link
Contributor Author

heAdz0r commented Feb 15, 2026

Hi! I noticed the awaiting-changes label was added but there are no review comments or inline feedback. Could you clarify what needs to be addressed?

The PR currently has no merge conflicts and all tests pass locally. It does depend on #123 and #124 — is the label related to waiting for those to merge first, or are there specific changes you'd like to see?

Thanks!

@pszymkowiak
Copy link
Collaborator

We're still reviewing #124.

We cannot force the use of a tool — # Search priority (mandatory): rgai > rg > grep is not acceptable. rtk is a proxy, not a policy enforcer.

If rtk rgai is to exist, it should follow the same pattern as every other rtk command: proxy an existing external command (grepai/rgai) if installed, compress its output, and that's it.
Not implement a 800-line built-in search engine, not rewrite hooks to enforce priority, not modify documentation to push a search ladder.

Please remove all the hook rewrites, documentation changes, and init template modifications from this PR. Otherwise, please close PRs #124, #125, #127, and #136.

we are open for discussion if you want.

@heAdz0r
Copy link
Contributor Author

heAdz0r commented Feb 17, 2026

Closing — agreed with maintainers to keep grepai/rgai activity in my fork (heAdz0r/rtk) and not mix it into upstream for now.

@heAdz0r heAdz0r closed this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants