portal_grep
Search file contents on a remote host using regex patterns. Returns structured JSON with capped results and supports pagination, globs, and file type filters.
Instructions
Search file contents with a regex on a remote host (ripgrep, fallback
grep). Prefer this over running raw rg/grep through portal_exec —
it returns structured JSON and caps output so a broad search can't blow up
your context. Pair it with portal_glob to find files by name.
Args:
host: SSH host alias / registered name.
pattern: the regex to search for (rg/PCRE-ish syntax).
path: file or directory to search under (default: cwd "."). Result
paths are returned relative to it.
glob: filter files by a glob, e.g. ".py" or "!.test.ts".
file_type: rg --type filter, e.g. "py", "rust", "js".
output_mode:
- "files_with_matches" (default): just the matching file paths,
NEWEST FIRST. Cheapest; use it to locate, then re-grep with
output_mode="content" on the file you care about.
- "content": matching lines as {file, line, text} (context lines
carry "context": true). head_limit caps the TOTAL lines
returned and offset pages through them.
- "count": per-file match counts + a grand total.
ignore_case: case-insensitive match.
before_context / after_context / context: lines of context to include
around each match in "content" mode (context = both sides).
head_limit: cap on results (files / content lines / count rows). Default
250; a truncated flag in the result tells you more were dropped.
offset: skip the first offset results (pagination).
multiline: let . and the pattern span line boundaries.
Respects .gitignore (ripgrep's default). Returns JSON whose shape depends
on output_mode; every shape includes a truncated flag.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| glob | No | ||
| host | Yes | ||
| path | No | . | |
| offset | No | ||
| context | No | ||
| pattern | Yes | ||
| file_type | No | ||
| multiline | No | ||
| head_limit | No | ||
| ignore_case | No | ||
| output_mode | No | files_with_matches | |
| after_context | No | ||
| before_context | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |