tgrep-pi0.1.3
Pi grep via Microsoft tgrep — trigram-indexed search, auto-installed prebuilt binary
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
tgrep-pi
Pi extension that installs Microsoft tgrep and uses it for the built-in grep tool.
tgrep is a trigram-indexed search engine (the same engine GitHub Copilot CLI uses for large-repo grep). This package downloads the latest prebuilt binary for your OS, keeps it updated, and routes Pi’s grep calls through it.
- npm: tgrep-pi
- pi.dev: pi.dev/packages/tgrep-pi
- Source: github.com/shahidshabbir-se/pi-tgrep
- Upstream: microsoft/tgrep · releases · benchmarks
Why use it
Pi’s default grep (and tools like ripgrep) scan every file on every query — O(total bytes). In a 100k+ file monorepo that is slow enough that the agent spends more time waiting than reading.
tgrep pre-builds a trigram index, then only opens files that could match. On large trees that is often an order of magnitude faster (see tgrep’s own numbers: up to ~50× vs ripgrep on gecko-dev / Chromium / Linux).
This extension exists so you do not have to:
- Hunt for a tgrep binary
- Keep it current
- Teach the model a new tool name
You get the same grep tool Pi already uses, backed by tgrep.
| Default Pi grep | tgrep-pi | |
|---|---|---|
| Engine | built-in scanner | microsoft/tgrep |
| Large repos | linear scan | trigram index + candidate verify |
| Binary | none | latest GitHub release, checksum-verified |
| Tool name | grep |
still grep (override) |
Use it if you search big checkouts, generated trees, or anything where cold rg/grep feels sticky. On tiny repos the difference is small; tgrep still works.
Install
pi install npm:tgrep-pi
Reload Pi (/reload or restart). Confirm with /tgrep-status.
From git instead of npm:
pi install git:github.com/shahidshabbir-se/pi-tgrep
Requires a network path to GitHub Releases on first grep (or when /tgrep-update runs).
What you get
greptool override — same parameters Pi already documents (pattern,path,exclude,caseSensitive,context,limit,cursor). Smart-case by default.- Managed binary — stored next to the package (
bin/tgreporbin/tgrep.exe), not in~/.local/bin. Safe on NixOS and other immutable systems. - Latest release — fetched from microsoft/tgrep releases. Archive SHA-256 is checked against
checksums.txtwhen GitHub publishes it. Replace is atomic (tgrep.new→ rename). - Background check — session start does not block the TUI. First
grepensures the binary; a 24h cache avoids hitting the API every turn. - Platforms — Linux/macOS/Windows, x64 and arm64 (musl static builds on Linux).
Commands
| Command | What it does |
|---|---|
/tgrep-status |
Managed path, VERSION, whether the binary exists |
/tgrep-update |
Force download and replace with the current latest release |
How the binary is kept
- Detect host triple (
x86_64-unknown-linux-musl,aarch64-apple-darwin, …). GEThttps://api.github.com/repos/microsoft/tgrep/releases/latest.- Download the matching
.tar.gz/.zip, verify checksum, extract,chmod +x, atomic replace. - Write
bin/VERSION(release tag, e.g.v1.0.4).
If GitHub is down and a local binary already exists, grep keeps using it.
GitHub API rate limits are tight unauthenticated. Set GITHUB_TOKEN or GH_TOKEN if updates start failing.
Grep mapping
Pi grep arg |
tgrep |
|---|---|
pattern |
regex / literal (tgrep auto) |
path glob (*.ts, src/**) |
-g |
path file or directory |
positional path |
path comma-separated roots (modules/hyprland,hosts/nix) |
separate positional paths |
exclude directory |
-g '!dir/**' |
exclude glob |
-g '!glob' |
caseSensitive: true |
-s |
caseSensitive: false |
-i |
| omitted | -S smart-case |
context |
-C |
limit / cursor |
applied in the extension (default 20) |
Commas separate search roots; surrounding whitespace is trimmed, while spaces
inside each path are preserved. Commas inside brace globs ({src,lib}/**) and
character classes are not separators. When roots and globs are combined, the
globs filter those roots; with globs alone, tgrep searches the working directory.
Output is grouped by file, with a continuation cursor when truncated.
Optional: run tgrep serve / tgrep index in a repo yourself for the full server+index path. The extension does not start a daemon; tgrep will use a running server if one is already there.
Development
git clone https://github.com/shahidshabbir-se/pi-tgrep.git
cd pi-tgrep
Run tests with Node.js 22.19+ (no additional dependencies):
npm test
TGREP_BINARY=/absolute/path/to/tgrep npm test
TGREP_BINARY enables the real-binary regression test for single-file search,
context, pagination, and directory search. Without it, that test is explicitly skipped.
Local Pi also auto-loads ~/.pi/agent/extensions/pi-tgrep/ if you keep a copy there. Do not install the npm package and a local copy at the same time or grep will be registered twice.
License
MIT. Upstream tgrep is also MIT.