Skip to content

Commit 48be0e7

Browse files
committed
docs: Rename grep options
1 parent df1a599 commit 48be0e7

2 files changed

Lines changed: 46 additions & 23 deletions

File tree

docs/04_filesystem_interface.md

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,38 +231,61 @@ const paths = await fs.ls("/workspace/.agents/skills");
231231

232232
### `grep`
233233

234-
Available on `Workspace.fs` for parity with the agent tools, and on
235-
`Workspace.runtime` when you want it to run inside the container (faster
236-
for large trees because it uses ripgrep).
234+
`Workspace.fs.grep` accepts this interface:
237235

238236
```ts
237+
interface GrepOptions {
238+
regex?: boolean;
239+
ignoreCase?: boolean;
240+
context?: number;
241+
limit?: number;
242+
offset?: number;
243+
include?: string;
244+
}
245+
246+
interface WorkspaceGrepContextLine {
247+
line: number;
248+
text: string;
249+
isMatch: boolean;
250+
}
251+
252+
interface WorkspaceGrepMatch {
253+
path: string;
254+
line: number;
255+
text: string;
256+
context?: WorkspaceGrepContextLine[];
257+
}
258+
239259
grep(
240260
pattern: string,
241-
path: string,
242-
options?: { ignoreCase?: boolean }
243-
): Promise<{ path: string; line: number; text: string }[]>
261+
path: string,
262+
options?: GrepOptions,
263+
): Promise<WorkspaceGrepMatch[]>
244264
```
245265

246-
`pattern` is a **literal substring** — not a regex, not a glob.
247-
`ignoreCase` lowercases both sides before comparing.
248-
249-
`path` may be a directory **or a single file**. Directory walks return
250-
matches in walk order. Each result row carries:
266+
Matching is literal and case-sensitive by default. Set `regex: true` to
267+
interpret `pattern` as a regular expression and `ignoreCase: true` to ignore
268+
letter case. `context` adds that many lines before and after each match.
269+
`include` is a glob relative to a searched directory. `limit` and `offset`
270+
paginate matching lines.
251271

252-
- `path` — absolute path of the matching file.
253-
- `line` — 1-indexed line number within that file.
254-
- `text` — the entire matching line (without the trailing newline), not
255-
just the matched substring.
272+
`path` may be a directory or a single file. Directory searches return matches
273+
in deterministic depth-first discovery order, then line order within each
274+
file. Results are not globally sorted by full path.
256275

257276
```ts
258-
const hits = await fs.grep("TODO", "/workspace/src", { ignoreCase: true });
277+
const hits = await fs.grep("TODO", "/workspace/src", {
278+
ignoreCase: true,
279+
include: "**/*.ts",
280+
});
259281
for (const hit of hits) {
260282
console.log(`${hit.path}:${hit.line}: ${hit.text}`);
261283
}
262284
```
263285

264-
See [05. Shell Interface](./05_runtime_interface.md) for the container-side
265-
variant.
286+
`Workspace.runtime` exposes a narrower container-side variant that accepts only
287+
`ignoreCase` and treats its pattern as a literal string. See
288+
[05. Shell Interface](./05_runtime_interface.md) for that variant.
266289

267290
## Error handling
268291

docs/09_tool_interface.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,19 @@ The pattern is relative to `path`. `*` stays within one path segment, `**` cross
168168
path?: string; // default /workspace
169169
query: string;
170170
include?: string; // glob relative to path
171-
fixedString?: boolean; // default false
172-
caseSensitive?: boolean;// default false
173-
contextLines?: number; // 0 through 10
171+
regex?: boolean; // default false
172+
ignoreCase?: boolean; // default false
173+
context?: number; // 0 through 10
174174
limit?: number; // default 200, maximum 1000
175175
offset?: number;
176176
}
177177
```
178178

179-
The AI tool defaults to case-insensitive regular expressions to match Think's tool contract. Set `fixedString` when the query should be treated as plain text. Matches include path, line number, text, and optional numbered context. Invalid regular expressions return a structured error. A non-final page includes `nextOffset`.
179+
The AI tool defaults to literal, case-sensitive matching. Set `regex: true` to interpret `query` as a regular expression and `ignoreCase: true` to ignore letter case. Matches include path, line number, text, and optional numbered context. Invalid regular expressions return a structured error. A non-final page includes `nextOffset`.
180180

181181
The tool passes `include`, `limit`, and `offset` through one `workspace.fs.grep` call. The storage search pages matching files and stops after the requested matches, so an included search does not build the full file or match list in the tool layer. Directory searches return matches in deterministic depth-first discovery order, then line order within each file. They are not globally sorted by full path.
182182

183-
The lower-level `workspace.fs.grep` keeps its existing defaults: literal and case-sensitive. Its options also accept `limit`, `offset`, `include`, `contextLines`, `fixedString`, and `caseSensitive`.
183+
The lower-level `workspace.fs.grep` uses the same literal, case-sensitive defaults. Its options also accept `limit`, `offset`, `include`, `context`, `regex`, and `ignoreCase`.
184184

185185
## `write`
186186

0 commit comments

Comments
 (0)