grep: optional tgrep backend for large workspaces

Đang mở
#1,086 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
git, node.js, typescript
Lĩnh vực
cli, performance, tooling

Hướng nghiên cứu

Start by locating the grep tool implementation, its settings, and the beforeToolCall interception path. Review how the built-in grep handles output_mode, head_limit, and offset, then check whether a live tgrep server is available before considering query behavior. Done means an opt-in backend uses tgrep only when safe, preserves the built-in output behavior, and falls back to ripgrep for unavailable servers or unsuitable patterns.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Feature Description

Let the grep tool run against a tgrep trigram index when one exists for the session root, and fall back to the bundled ripgrep otherwise. Opt-in, not a default change — tgrep only pays off with an index plus a live server, and it is slower than ripgrep on patterns the index cannot narrow.

Today there is no setting to change the grep backend, and a mod cannot register a tool named grep (colliding names are skipped with mod_error), so the only seam is beforeToolCall interception.

Use Case

On a 124,465-file / 29 GB workspace, a selective search such as TODO takes ~3.1s through the grep tool. Agents issue dozens per session, serially. With a live tgrep server the same search returns in 31ms end to end — 100x. Measured on macOS arm64, tgrep 1.2.5, ripgrep 15.2.0, warm cache, best of 5:

query ripgrep (full search) tgrep
TODO (selective, 1,280 files) 3.07s 31ms
function (broad, 65,004 matching lines) 3.37s 163ms
absent token 3.01s 16ms

For comparison, engine-to-engine with full output the broad case is only 1.2x (3.31s vs 2.83s); the 21x through a tool result comes from stopping at the page limit instead of materialising everything.

Additional Context

I built this as a mod and hit six things a native implementation would need to handle:

  1. output_mode defaults differ — the built-in is files_with_matches, tgrep is content, so -l must be passed when the field is absent.
  2. tgrep omits line numbers unless -n is given explicitly.
  3. head_limit/offset need a stream that aborts at offset + limit + 1 lines; buffering a broad match set hit 23 MB and a 285k-line result.
  4. An index without a running server is not safe. It silently misses files written since the build. Reproduced: a newly created file returned exit 1 (no matches) from tgrep while ripgrep found it. A native backend should require a live server, not just an index on disk.
  5. A cheap tgrep status . probe gates it (0.00s live, 0.08s dead), plus a stderr check for falling back to local index to cover a server dying mid-query.
  6. Patterns with no literal trigrams scan every indexed file — \d{9,} took 40.5s against ripgrep's 3.0s — so a timeout fallback or trigram heuristic is required. My mod caps at 30s and then defers to the built-in.

Prototype with methodology, raw output and limitations: https://github.com/Hashimlokasher/cmd-mod-tgrep-grep (BENCHMARKS.md). tgrep also powers GitHub Copilot CLI's grep, so it is actively maintained.

Proposal: a grep.backend: "tgrep" setting, or auto-detect when tgrep is installed and a live index is present, keeping ripgrep as the default and the fallback. Happy to test or contribute.

Priority: Important for my workflow

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
4.2k
Fork
377
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CommandCodeAI/command-code

Tất cả issue của CommandCodeAI/command-code

Issue tương tự

Thêm issue về CLI

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.