Skip to content
K1eransPublic

About

A grep inspired tool using Jev to semantically search over code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

29 Commits

Folders and files

Repository files navigation

jrep

grep for what code does. Ask in plain words and get back the functions that do it, ranked by probability. Built for coding agents and developers on top of jinter and TypeSafe's Jev model.

$ jrep "retries failed payments" src/
0.94  src/billing/retry.ts:12-80        retryFailedPayment(invoice, attempt)
0.81  src/jobs/payment-worker.ts:40-95  handlePaymentFailure(job)

jrep matches on behavior rather than identifier names, so an agent or developer does not need to guess whether the codebase calls a concept retryFailedPayment, backoffCharge, or requeueInvoice. Use rg for exact strings and symbol names; use jrep to find where a behavior lives.

Why jrep

When an agent explores an unfamiliar codebase with rg, it guesses keywords, reads false positives across tests and lockfiles, and burns context window turns. jrep replaces that loop with one behavioral query while keeping API cost and latency bounded:

  • Syntax-aware function chunking. Files are parsed into function, method, and class chunks (~10 to 300 lines) with tree-sitter (and go/parser for Go), so every match returns an exact path:start-end line range and declaration signature ready to open.
  • Noise filtering that cuts 40% to 70% of wasted tokens. jrep follows .gitignore and automatically skips binaries, lockfiles (70% of tokens in one repository), translation catalogs (43% of chunks in miniflux, with zero effect on match rank), docs (11% of tokens), files over 1 MB, and test files (unless your question asks about tests or you pass --tests). Nothing is skipped silently: stderr reports every skipped count before any chunk is sent to Jev.
  • Multi-chunk and multi-question packing (-q). Every Jev request carries ~240 tokens of fixed framing overhead. jrep packs up to 24 KB of chunks from a file into a single call and asks every -q question in that same request, reducing total tokens by about a third and making additional questions in the same scan nearly free.
  • Cheap retry narrowing (--refine). When a question misses and you reword it, --refine "earlier question" re-asks only the 300 chunks that scored highest on the earlier question from its cached answers. Across real agent retry benchmarks, --refine matched full-rescan accuracy at 9% of the cost.
  • Line-number-free SQLite cache shared across git worktrees. Answers and chunk layouts are cached in SQLite per repository (~/Library/Caches/jrep on macOS). Because cache keys omit line numbers, editing the top of a file only re-asks the modified function. Repeat searches and --threshold adjustments cost zero API calls (dropping a 15.9 s cold scan to 1.1 s warm).
  • Adaptive 4x throughput limiter. Uses an adaptive token- and request-rate limiter that bursts immediately and backs off on HTTP 429/529, scanning miniflux (658 files) in 8.3 s cold.

Install

export TYPESAFE_API_KEY=...   # fish: set -Ux TYPESAFE_API_KEY ...
make install                  # embeds 33 common language grammars (~20 MB binary)

To embed all 206 tree-sitter grammars (~33 MB binary), run go install ./cmd/jrep instead.

Usage

jrep "sends the password reset email" src/auth        # scope to the likeliest folder first
jrep "validates webhook signatures" -q "parses webhook payloads" src/
jrep --refine "validates webhook signatures" "checks the HMAC header" src/
jrep -s "exports invoices as CSV" .                   # local keyword pre-pass before calling Jev
jrep --json "retries failed payments" src/
Flag Purpose
-q "question" Ask an additional question in the same scan at almost no extra cost (repeatable)
--refine "earlier" Re-run a reworded question on only the 300 chunks that best matched "earlier" (~9% of full scan cost)
-s, --keywords 'a|b' Pre-filter chunks locally by the question's non-stopword terms, or by a custom regular expression
--threshold 0.6 Minimum probability in [0, 1] to count as a match (default 0.6)
--top 10 Maximum matches returned per question (default 10, 0 = no limit)
--tests, --docs, --no-ignore Include test files, documentation, or gitignored files
--max-filesize 1M Skip larger files and list them on stderr (default 1M, 0 = no limit)
--model jev-1.13.0 Override the pinned Jev model version
--json Emit one newline-delimited JSON object per match
--no-cache, --clear-cache Ignore cached answers on read, or delete this repository's SQLite cache and exit

Run jrep -h for the full flag and environment variable list (TYPESAFE_API_KEY, JREP_CACHE_DIR, JREP_MAX_RPS, JREP_MAX_TPS).

Exit codes: 0 when at least one chunk matches, 1 when nothing reaches --threshold (prints the highest-scoring candidate so you can lower --threshold or rephrase), and 2 on error.

Note

Every uncached chunk searched is sent to TypeSafe, and cost scales with the amount of code scanned (~0.7 cents and ~1 second per 400 chunks). Pass the folder most likely to hold the code rather than the repository root; stderr prints jrep: asking Jev about N chunks whenever uncached chunks are sent.

Architecture

jrep is a thin CLI around the jinter search engine (cmd/jrep/main.go and internal/output). See PLAN.md for the full design rationale and benchmark notes:

1. walk      list files via git ls-files / .gitignore, filter binaries, generated files, translations, docs, and tests
2. chunk     split files into ~10-300 line functions/blocks via go/parser and tree-sitter (reusing cached layouts)
3. narrow    optional -s keyword regex pre-pass or --refine top-300 lookup from an earlier question's cache
4. key       sha256(model + normalized question + repo-relative path + chunk code)
5. cache     batched SQLite lookup in WAL mode (shared across the repo's worktrees)
6. ask Jev   pack uncached chunks per file (<= 24 KB) with all -q questions, dispatch in parallel
7. save      persist each call's answers to SQLite as it returns so interrupted runs keep progress
8. rank      sort by probability, apply --threshold and --top, print text or JSON

Agent skill and AGENTS.md snippet

skills/jrep/SKILL.md teaches coding agents how to scope searches to the deepest likely folder, batch questions with -q, and recover from misses with --threshold and --refine. Run make install-skill to copy it to ~/.claude/skills/jrep/ for Claude Code.

Or paste this section into a project's AGENTS.md or CLAUDE.md:

## Searching code

Use `jrep` to find code by behavior; use `rg` for exact strings and symbol names.

    jrep "retries failed payments" src/billing/
    jrep "validates webhook signatures" -q "parses webhook payloads" src/webhooks/

- Phrase the question as what the code does: "sends the password reset email", not "where is the email code".
- Output is `probability  path:start-end  signature`, best first. Read the printed line ranges rather than whole files.
- Exit code 0 means matches, 1 means none above the threshold (prints the best candidate), 2 means error. On 1, lower `--threshold 0.3` (served from the cache for free) or rephrase.
- `-q` adds questions to the same scan at almost no extra cost; prefer one call with several `-q` flags over separate calls.
- Pass the single deepest folder likely to hold the code (`ls` first); step up to the parent or add another folder only after a miss.
- When a search misses and you reword the question, pass `--refine "your earlier question"` to search only the 300 chunks that best matched the earlier one (~10% of the cost of a new scan).
- `-s` pre-filters chunks locally by the question's words (or `--keywords 'a|b'`): faster and cheaper on large repos, at the cost of missing code that uses different vocabulary.
- Test files are skipped unless the question mentions tests ("the tests for payment retries") or you pass `--tests`. Docs are skipped unless you pass `--docs`.

About

A grep inspired tool using Jev to semantically search over code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages