Repository navigation
fs_grep: ripgrep-inspired tier 1-4 speedups - #240
Conversation
Four cheap wins for fs_grep, modelled after ripgrep's tier-1 filters:
1. Defer ComputeFileHash until first match in a file. Most scanned
files have zero matches and were being hashed for nothing.
2. Skip well-known VCS / build / deps directories by name at walk
time (.git, .hg, .svn, node_modules, target, build, dist, vendor,
.venv, __pycache__, .gradle, .next). The model never wants
results from these and they dominate file count on real repos.
3. Binary file detection: NUL byte in first 1 KiB -> skip. Source
code never embeds NUL; PDFs / PNGs / archives / executables
always do at the file header.
4. File-size cap (default 10 MiB, override via max_file_bytes arg).
Prevents one accidental fs_grep over a giant log file from
stalling a session.
The walk-time skips (2, 4) avoid the read entirely; the body-time
skips (1, 3) avoid line-splitting and hashing on files that wouldn't
contribute to output anyway.
Observable behaviour pinned by src/tests/fs_grep_tier1_4_tests.pas:
seeds a temp tree with marker tripwires inside each blocked dir, a
binary file, and a 11 MiB file, then asserts the markers do NOT
surface in fs_grep output -- and that raising max_file_bytes brings
the large file back in scope. Tier 1 is covered indirectly by the
hashline-header assertion (the deferred hash still has to be correct
on the match path).
There was a problem hiding this comment.
💡 Codex Review
PasClaw/src/pkg/tools/PasClaw.Tools.FS.pas
Lines 565 to 566 in fa8ff56
When fs_grep is called with path set directly to a file, this branch calls ScanFile without checking the new size cap, so an explicit grep of an 11 MiB or multi-GB log still reads and scans it despite the schema/description promising that files larger than max_file_bytes are skipped. The cap is only enforced during directory walking via TSearchRec.Size, which misses this direct-file path case.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Code review on PR #240 caught that the size cap was only enforced during directory walk (via TSearchRec.Size in Walk), missing the direct-file branch where path points straight at a file. An explicit `fs_grep path=server.log pattern=...` on an 11 MiB log would scan it despite the schema and tool description promising otherwise. Fix: stat the direct-file path through FindFirst (same data source Walk uses) and skip if SR.Size > MaxFileBytes. No body read on the skip path; identical cost to Walk's check. Pin both directions in fs_grep_tier1_4_tests.pas: TestDirectFilePathRespectsCap asserts (a) oversize direct-file gets `(no matches)` at the default 10 MiB cap, and (b) the same file IS scanned when max_file_bytes is raised.
Both changelog files were stuck at the 2026-06-10 TUI / background- subagent / session_search / tool-RPC entries. ~7 weeks of merged PRs (#214 through #244) had landed without a corresponding entry in either file -- the git log was the only record of features like the knowledgebase, inbound MCP server mode, checkpoints + /undo, heartbeat daemon, shell backends (local | docker), send_message, promptware defense, Windows shell-output encoding fixes, fs_grep ripgrep optimisations, OpenTelemetry traces, and `pasclaw agent --quiet`. Added (newest first): 2026-06-13 #244 agent --quiet log-level clamp 2026-06-12 #243 dcc64 search path + agent --quiet / -q #242 OpenTelemetry traces (OTLP/HTTP+JSON) #241 fs_grep tier 5+6 (byte walker + Boyer-Moore-Horspool) #240 fs_grep tier 1-4 (deferred hash + skip-dirs + binary sniff + size cap) 2026-06-11 #239 Windows shell output: auto-detect UTF-8 vs OEM #238 Hashline fs_read header mojibake fix (¶ vs ¶) #237 Windows shell output: OEM codepage decode 2026-06-10 #233 Shell backends (local | docker via IShellBackend) #232 Heartbeat daemon + reversible condensation (CCR) #230 send_message tool + condenser families + promptware defense + task-aware MEMORY.md slicing 2026-06-09 #223 /goal Ralph loop + judge model + JSON-aware condenser #222 /undo wired into agent + sample dprojs #221 Checkpoints (auto-snapshot + TUI /undo) #220 mcp catalog: lenient hub projector #219 mcp: SSE / Streamable HTTP / stdio hub transports #218 Inbound MCP server mode #217 onboard: offer to index docs into the knowledgebase #214 Knowledgebase (RAG over operator-curated docs) Skipped from this changelog (build-system / Delphi-fix / FPC-fix PRs visible in the git log but not user-facing features): #215, #216, #224, #225, #226, #227, #228, #229, #231, #234, #236. Both files (README.md and docs/changelog.md) updated with the same entries -- intentional mirror so a reader on either surface sees the same history. Same prose in both; same footnote refs at the bottom. Validated: every [#N] reference in both files has a matching [#N]: URL footnote (no broken links).
Four cheap wins for fs_grep, modelled after ripgrep's tier-1 filters:
The walk-time skips (2, 4) avoid the read entirely; the body-time skips (1, 3) avoid line-splitting and hashing on files that wouldn't contribute to output anyway.
Observable behaviour pinned by src/tests/fs_grep_tier1_4_tests.pas: seeds a temp tree with marker tripwires inside each blocked dir, a binary file, and a 11 MiB file, then asserts the markers do NOT surface in fs_grep output -- and that raising max_file_bytes brings the large file back in scope. Tier 1 is covered indirectly by the hashline-header assertion (the deferred hash still has to be correct on the match path).