data/tools/grep_tool library

Classes

GrepOutput
Structured output from GrepTool.
GrepTool
Search file contents with regex -- port of neomage GrepTool.
HeadLimitResult<T>
Result of applying head_limit and offset to a list.

Constants

defaultHeadLimit → const int
Default cap on grep results when head_limit is unspecified. Unbounded content-mode greps can fill up to the 20KB persist threshold (~6-24K tokens / grep-heavy session). 250 is generous enough for exploratory searches while preventing context bloat. Pass head_limit=0 explicitly for unlimited.
grepToolName → const String
Tool name matching the TS original.
maxResultSizeChars → const int
Maximum result size before disk persistence (20K chars).
vcsDirectoriesToExclude → const List<String>
Version control directories excluded from searches automatically to avoid noise from VCS metadata.

Functions

applyHeadLimit<T>(List<T> items, int? limit, {int offset = 0}) HeadLimitResult<T>
Apply head_limit and offset to a list of items. Explicit 0 = unlimited escape hatch.
buildRipgrepArgs({required String pattern, String? glob, String? type, String outputMode = 'files_with_matches', int? contextBefore, int? contextAfter, int? contextC, int? context, bool showLineNumbers = true, bool caseInsensitive = false, bool multiline = false}) List<String>
Build ripgrep command-line arguments from tool input.
expandPath(String path) String
Expand ~ and resolve relative paths to absolute.
formatLimitInfo(int? appliedLimit, int? appliedOffset) String
Format limit/offset information for display in tool results. appliedLimit is only set when truncation actually occurred (see applyHeadLimit), so it may be undefined even when appliedOffset is set -- build parts conditionally to avoid "limit: undefined" appearing in user-visible output.
parseGlobPatterns(String glob) List<String>
Split glob patterns, preserving brace expressions. E.g. "*.{ts,tsx} *.dart" -> "*.{ts,tsx}", "*.dart"
plural(int count, String singular) String
Plural helper: returns "file" or "files" etc.
toRelativePath(String absolutePath) String
Convert an absolute path to a relative path from CWD to save tokens.

Exceptions / Errors

RipgrepTimeoutException
Exception thrown when ripgrep times out.