Implements the local grep override shipped by slim. The module provides a ripgrep-first search tool with OpenCode-compatible semantics, managed backend resolution, hybrid mtime ordering, and final GNU grep fallback.
src/tools/grep/
├── tool.ts # Tool wrapper: normalize -> ask -> run -> format -> metadata
├── schema.ts # Public input schema
├── types.ts # Request/result/event types
├── constants.ts # Identity, defaults, hard caps, tool description
├── normalize.ts # Raw args -> NormalizedGrepInput, realpath/permission scope
├── rg-args.ts # ripgrep argv builder
├── runtime.ts # Process lifecycle, timeout/cancel, retries, semaphore
├── direct.ts # Streaming rg hot path for content/count/files modes
├── mtime.ts # Hybrid discover/sort/replay strategy for sort_by=mtime
├── fallback.ts # Final GNU grep fallback backend
├── resolver.ts # system rg -> managed rg -> install-on-miss -> GNU grep
├── downloader.ts # Managed ripgrep installer in user cache
├── json-stream.ts # JSON/NUL stream parsers
├── aggregate.ts # Content collector with context drain
├── result-utils.ts # Result shaping and truncation helpers
├── path-utils.ts # Display paths, byte identities, non-UTF8-safe rendering
├── summary.ts # Human summary builders
├── format.ts # Final human-readable output
└── *.test.ts # Focused subsystem suites
Direct rg path
mtime-hybrid
mtime-fallback when byte-paths are not safely orderable/replayableGNU grep fallback
The resolver follows this order:
system rgrgrg on misssystem GNU grepAborts during auto-install propagate cleanly and are not cached as permanent install failure.
Tool call
↓
tool.ts
↓ normalize.ts
NormalizedGrepInput
↓
ctx.ask(permissionPatterns)
↓
runner.ts
├─→ resolver.ts
├─→ direct.ts
├─→ mtime.ts
└─→ fallback.ts
↓
format.ts
↓
structured metadata + human output
src/index.ts as the local grep override.src/tools/index.ts and src/tools/grep/index.ts.src/utils/zip-extractor.ts for managed ripgrep archive extraction.bytes:base64:... identities when raw bytes are available.