Skip to content
simo8902Public

About

super duper grep lol

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

shgrep

Code search, navigation, edits and a native C++ REPL for coding agents, in one C++26 MCP stdio server (v0.3.0). ripgrep finds lines. shgrep answers the question the agent asked, in the fewest tokens, and edits the file without breaking it.

Built on CERN tech

the c++ repl runs on Cling, built at CERN for the Large Hadron Collider's physics analysis. if it holds up for particle physics, it holds up for our shgrep.

Rene Brun and Fons Rademakers, ROOT - An Object Oriented Data Analysis Framework, Proceedings AIHENP'96 Workshop, Lausanne, Sep. 1996, Nucl. Inst. & Meth. in Phys. Res. A 389 (1997) 81-86.

Compared with rg and tgrep

Same questions, same repositories, measured.

3 repos, 64 source-checked questions, MRR@10 (GPU build)
  shgrep ranked text (dense)    0.804  [0.719-0.883]
  shgrep ranked text (90% mix)  0.725
  rg, count-sorted              0.513
  rg, files                     0.205
  tgrep                         0.170

Nebula engine, 20 verified questions, answer file shown / median tokens
  rg lines                      20/20   39,000 tokens
  shgrep search, no intent      18/20      206 tokens   MRR 0.51
  shgrep search, with intent    16/20      458 tokens   MRR 0.50
  rgx --compact page 1           5/20      991 tokens   MRR 0.17

rg wins raw recall in the second table, at about 190 times the tokens. For an agent, tokens per answer is the cost that counts. Raw regex latency on a warm index is tgrep's strength: its trigram server beats rg in 17 of its 18 published runs. The whole tool list costs 2,741 schema tokens per agent step, or 1,377 in read-only mode.

Feature rg tgrep shgrep
Ranked hunks with whole enclosing functions no no yes
Dense and lexical fusion, weighted per query no no GPU build
Live per-workspace index no yes yes
Language-server navigation (definitions, references, renames) no no yes
Symbol-scoped, sha256-guarded edits no no yes
Line endings and encodings kept on edit n/a n/a yes
One call from question to evidence pack no no investigate
Native C++26 cells over the same tools no no repl

What it is

Part What it does
Search Hyperscan with PCRE2 fallback, a live index of the workspace, and BM25F-ranked hunks. The GPU build adds a dense retriever. When the index is warming or the model is unavailable, keyword results still come back, never an empty reply.
Language servers clangd, Roslyn, tsserver, ty, neocmakelsp and anything in .shgrep/lsp.json, behind one lsp tool. Symbols are found by Class::Method, Ns::Class/Method or a pasted signature. Large folder searches return partial results with a coverage_note, and the next call goes further.
Edits sha256-guarded and symbol-aware. CRLF, LF, CR, mixed endings, UTF-16/32 and BOMs survive. check=lsp|compiler|build|all returns parsed compiler diagnostics after an edit.
REPL C++26 cells on CERN's Cling, with the whole tool API inside the cell. --read-only turns it off.

Tools

Tool Notes
investigate Question to evidence pack: ranked candidates and one hunk per file.
search Ranked by default, exhaustive for scan order. The top 3 hunks show their whole function. max_results up to 100.
search_bytes Raw byte patterns.
find_files Globs.
read_file Up to 16 windows per call. Code windows widen to whole symbols, up to 100 lines.
list_dir, file_info Folder listing; size, mtime and sha256.
edit_file old_text to new_text. An empty old_text creates or fills an empty file.
write_file, delete_file, move_file, create_directory Guarded file changes.
files One tool for all file operations, same guards.
lsp method plus arguments. navigate returns body and references in one call. method=help lists every field.
repl calls for a batch of tool calls, code for a C++26 cell, or both.

SHGREP_TOOLSET=compact (the default) lists the main tools. SHGREP_TOOLSET=full lists all 14.

Downloads

Package Contents
Windows x64 ZIP shgrep.exe, shgrep-compiler.dll, shgrep.dat, orc_rt-x86_64.lib, README.txt, tools\fetch_lsp.py, licenses\, plus a .sha256 checksum
Linux x86-64 archive shgrep, libshgrep-compiler.so, shgrep.dat, tools/, licenses/, runtime-dependencies.txt and a guide

Keep every file from the same release together. Windows needs Windows 8 or later.

Running

shgrep.exe --root C:\work\repo [--root C:\other ...] [--read-only]
shgrep.exe search "TODO|FIXME" --root C:\work\repo
shgrep.exe investigate -q "where does the pool get reset" --root C:\work\repo
shgrep.exe --license

MCP client entry:

command = 'C:\tools\shgrep\shgrep.exe'
args    = ['--root', 'C:\work\my-repo']
  1. The first --root is the workspace. Only it gets a live index, pathless searches and warmed language servers. Other roots are searched when named.
  2. Progress goes to .shgrep\index.log in the workspace. Drive roots and the user profile are never indexed.
  3. .shignore is created empty at start. It uses .gitignore syntax and its rules win over .gitignore and .ignore.
SHGREP_TOOLSET            compact | full
SHGREP_READ_ONLY          1 equals --read-only
SHGREP_INDEX_MAX_FILES    default 500000, 0 for no cap
SHGREP_LSP_WARMUP         0 disables background server start
SHGREP_LSP_ROOT           parent folder of the lsp tree

Language servers are separate downloads. Run the script on a connected PC, then copy the lsp folder beside shgrep for offline use:

python tools\fetch_lsp.py C:\shared\shgrep
python3 tools/fetch_lsp_linux.py /opt/shgrep --only clangd python

C# is not available on Linux.

The REPL

Behavior (Windows) Detail
Redefinition A later cell can declare a name again.
Failed compile The cell is undone and the session keeps its declarations. At most three errors are shown.
Missing std header Added automatically, then the cell compiles once more.
Prelude About 50 standard headers, fs = std::filesystem and std::literals, ready in every cell.
Exceptions Work across cells. One that escapes a statement is that cell's error, named by type.
Timeouts Terminate the worker. Destructors are not guaranteed.
Memory 1 GiB per worker.
Sessions Up to 8. A ninth closes the least recently used idle one.
Batches 32 calls without writes, 8 with a write.

Windows needs Visual Studio or Build Tools with desktop C++, a Windows 10/11 SDK, an MSVC toolset matching the release's major.minor version, and the x64 VC++ redistributable. Set VCToolsInstallDir, WindowsSdkDir and WindowsSDKVersion to pick specific installations. Linux needs native C/C++ development headers and the matching C++ standard library. Native cells run with the user's permissions.

License

shgrep --license prints the notices in licenses\. MSVC, the Windows SDK and Clang's headers keep their own terms.

About

super duper grep lol

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages