@qmediat.io/gemini-code-context-mcp 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +26 -3
  3. package/dist/config.d.ts +23 -0
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +9 -0
  6. package/dist/config.js.map +1 -1
  7. package/dist/indexer/globs.d.ts +106 -0
  8. package/dist/indexer/globs.d.ts.map +1 -1
  9. package/dist/indexer/globs.js +151 -11
  10. package/dist/indexer/globs.js.map +1 -1
  11. package/dist/tools/agentic/sandbox.d.ts +55 -0
  12. package/dist/tools/agentic/sandbox.d.ts.map +1 -0
  13. package/dist/tools/agentic/sandbox.js +272 -0
  14. package/dist/tools/agentic/sandbox.js.map +1 -0
  15. package/dist/tools/agentic/workspace-tools.d.ts +104 -0
  16. package/dist/tools/agentic/workspace-tools.d.ts.map +1 -0
  17. package/dist/tools/agentic/workspace-tools.js +518 -0
  18. package/dist/tools/agentic/workspace-tools.js.map +1 -0
  19. package/dist/tools/ask-agentic.tool.d.ts +85 -0
  20. package/dist/tools/ask-agentic.tool.d.ts.map +1 -0
  21. package/dist/tools/ask-agentic.tool.js +727 -0
  22. package/dist/tools/ask-agentic.tool.js.map +1 -0
  23. package/dist/tools/ask.tool.d.ts +12 -12
  24. package/dist/tools/ask.tool.d.ts.map +1 -1
  25. package/dist/tools/ask.tool.js +522 -477
  26. package/dist/tools/ask.tool.js.map +1 -1
  27. package/dist/tools/code.tool.d.ts +8 -8
  28. package/dist/tools/code.tool.d.ts.map +1 -1
  29. package/dist/tools/code.tool.js +457 -423
  30. package/dist/tools/code.tool.js.map +1 -1
  31. package/dist/tools/index.d.ts.map +1 -1
  32. package/dist/tools/index.js +2 -0
  33. package/dist/tools/index.js.map +1 -1
  34. package/dist/tools/registry.d.ts +1 -1
  35. package/dist/tools/registry.d.ts.map +1 -1
  36. package/dist/tools/registry.js +8 -2
  37. package/dist/tools/registry.js.map +1 -1
  38. package/package.json +2 -2
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Path-safety primitives for agentic workspace tools.
3
+ *
4
+ * The `ask_agentic` path exposes Gemini function calls that read arbitrary
5
+ * user-supplied paths. If the model (or a prompt-injected document) smuggles
6
+ * `../../.ssh/id_ed25519` or a symlink pointing outside the workspace, we
7
+ * must reject at every step — not only at schema validation.
8
+ *
9
+ * Two classes of defence:
10
+ * 1. **Structural jail** via `realpath` on BOTH the root and the target.
11
+ * Prevents symlink escape and `..` traversal. `path.resolve +
12
+ * startsWith(root)` is NOT safe — a symlink inside the root that points
13
+ * outside the root will lexically look fine but actually escape.
14
+ *
15
+ * 2. **Content denylist** — even inside the jail, refuse known secret-
16
+ * bearing filenames (`.env`, `*.pem`, `.ssh/*`, `credentials`…) and
17
+ * path fragments that match `DEFAULT_EXCLUDE_DIRS` (already covers
18
+ * `.aws`, `.kube`, `.gnupg`, etc.). Belt and suspenders.
19
+ *
20
+ * Codex PR #20 review #2 flagged that `resolve+startsWith` is symlink-
21
+ * unsafe. This module implements `realpath + root jail` per that feedback.
22
+ */
23
+ export type SandboxErrorCode = 'PATH_TRAVERSAL' | 'SECRET_DENYLIST' | 'EXCLUDED_DIR' | 'EXCLUDED_FILENAME' | 'NON_SOURCE_FILE' | 'NOT_A_DIRECTORY' | 'NOT_FOUND' | 'NOT_INSIDE_ROOT' | 'INVALID_INPUT';
24
+ export declare class SandboxError extends Error {
25
+ readonly code: SandboxErrorCode;
26
+ readonly requestedPath: string;
27
+ constructor(code: SandboxErrorCode, message: string, requestedPath: string);
28
+ }
29
+ /** Absolute, real (symlink-resolved) path of `rootInput`. The caller must
30
+ * cache this value for the life of an agentic call so we avoid repeated
31
+ * `realpath` calls on the same root. */
32
+ export declare function resolveWorkspaceRoot(rootInput: string): Promise<string>;
33
+ /**
34
+ * Resolve `relOrAbs` to a real (symlink-resolved) absolute path, or throw
35
+ * `SandboxError` if it escapes the workspace or matches a denylist.
36
+ *
37
+ * Returns both the resolved absolute path and the POSIX relative path —
38
+ * callers need the absolute for FS operations and the relative for logging
39
+ * and response payloads. Relative path is always forward-slash form
40
+ * regardless of host OS.
41
+ *
42
+ * Missing-file policy: when the target path doesn't exist on disk, we
43
+ * still enforce the structural jail on the PARENT of the missing leaf so
44
+ * a request like `read_file(".ssh/id_ed25519")` fails with `PATH_TRAVERSAL`
45
+ * even if that specific file is absent. Without walking to a real parent
46
+ * we'd leak a `NOT_FOUND` error that confirms the path shape to an
47
+ * attacker — indirect enumeration signal. Acceptable trade-off: the
48
+ * missing-file error for a valid path inside the root still surfaces as
49
+ * `NOT_FOUND` once the parent resolves.
50
+ */
51
+ export declare function resolveInsideWorkspace(workspaceRoot: string, relOrAbs: string): Promise<{
52
+ absolutePath: string;
53
+ relpath: string;
54
+ }>;
55
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAyDH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,GACd,mBAAmB,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,eAAe,CAAC;AAmDpB,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBACnB,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAM3E;AAED;;wCAEwC;AACxC,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU7E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,sBAAsB,CAC1C,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CA6IpD"}
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Path-safety primitives for agentic workspace tools.
3
+ *
4
+ * The `ask_agentic` path exposes Gemini function calls that read arbitrary
5
+ * user-supplied paths. If the model (or a prompt-injected document) smuggles
6
+ * `../../.ssh/id_ed25519` or a symlink pointing outside the workspace, we
7
+ * must reject at every step — not only at schema validation.
8
+ *
9
+ * Two classes of defence:
10
+ * 1. **Structural jail** via `realpath` on BOTH the root and the target.
11
+ * Prevents symlink escape and `..` traversal. `path.resolve +
12
+ * startsWith(root)` is NOT safe — a symlink inside the root that points
13
+ * outside the root will lexically look fine but actually escape.
14
+ *
15
+ * 2. **Content denylist** — even inside the jail, refuse known secret-
16
+ * bearing filenames (`.env`, `*.pem`, `.ssh/*`, `credentials`…) and
17
+ * path fragments that match `DEFAULT_EXCLUDE_DIRS` (already covers
18
+ * `.aws`, `.kube`, `.gnupg`, etc.). Belt and suspenders.
19
+ *
20
+ * Codex PR #20 review #2 flagged that `resolve+startsWith` is symlink-
21
+ * unsafe. This module implements `realpath + root jail` per that feedback.
22
+ */
23
+ import { realpath } from 'node:fs/promises';
24
+ import { basename, sep as pathSep, relative, resolve } from 'node:path';
25
+ import { DEFAULT_EXCLUDE_DIRS, DEFAULT_EXCLUDE_FILE_NAMES_LOWER } from '../../indexer/globs.js';
26
+ /** Filename-basename entries that NEVER leak through `read_file`. Even when
27
+ * the path resolves safely under the workspace root, any of these basenames
28
+ * is a hard reject — protects against secrets dropped into the project by
29
+ * the user (`.env.local`) or by dev tooling (`credentials`).
30
+ *
31
+ * Stored in lowercase so the lookup set works on case-insensitive
32
+ * filesystems (macOS APFS, Windows NTFS) where `.ENV` resolves to the same
33
+ * file as `.env`. The `Set` below is built at load time. */
34
+ const AGENTIC_SECRET_BASENAMES = [
35
+ '.env',
36
+ '.env.local',
37
+ '.env.development',
38
+ '.env.production',
39
+ '.env.test',
40
+ '.env.staging',
41
+ '.netrc',
42
+ '.npmrc',
43
+ '.pgpass',
44
+ '.git-credentials',
45
+ '.htpasswd',
46
+ 'credentials',
47
+ 'credentials.json',
48
+ 'secrets.json',
49
+ 'secrets.yaml',
50
+ 'secrets.yml',
51
+ 'service-account.json',
52
+ ];
53
+ /** Lowercased `Set` for O(1) case-insensitive basename denylist lookup. */
54
+ const AGENTIC_SECRET_BASENAMES_LOWER = new Set(AGENTIC_SECRET_BASENAMES.map((s) => s.toLowerCase()));
55
+ /** Extensions that frequently carry sensitive key material. Extra gate on
56
+ * top of `AGENTIC_SECRET_BASENAMES`. Matched via `endsWith(lowerBase, ext)`. */
57
+ const AGENTIC_SECRET_EXTENSIONS = [
58
+ '.pem',
59
+ '.key',
60
+ '.crt',
61
+ '.cer',
62
+ '.p12',
63
+ '.pfx',
64
+ '.p8',
65
+ '.asc',
66
+ '.gpg',
67
+ '.keystore',
68
+ '.jks',
69
+ '.ppk',
70
+ '.ovpn',
71
+ ];
72
+ /**
73
+ * Directories that carry sensitive material and should trip the
74
+ * `SECRET_DENYLIST` error code (not the generic `EXCLUDED_DIR`). The
75
+ * distinction matters for observability: a downstream audit log tracing
76
+ * "model tried to read secrets" vs. "model tried to read a generated
77
+ * dist file" can filter on the error code. Functionally both are
78
+ * rejected, so security posture is identical.
79
+ *
80
+ * Introduced in PR #24 round-3 self-review finding #7.
81
+ */
82
+ const SECRET_EXCLUDE_DIRS = new Set([
83
+ '.ssh',
84
+ '.aws',
85
+ '.gnupg',
86
+ '.gpg',
87
+ '.kube',
88
+ '.docker',
89
+ '.1password',
90
+ '.pki',
91
+ '.gcloud',
92
+ '.azure',
93
+ '.config/gcloud',
94
+ '.config/azure',
95
+ 'Keychains',
96
+ ].map((s) => s.toLowerCase()));
97
+ // ---------------------------------------------------------------------------
98
+ // Path-compare helpers (declared at the top of the file so no function is
99
+ // referenced before its declaration in source order — a defensive tidy-up
100
+ // after PR #24 round-3 review flagged the hoisting-dependent layout. JS
101
+ // `function` declarations are hoisted to the enclosing scope, so the
102
+ // previous order worked at runtime — but a future refactor replacing
103
+ // `function` with `const arrow` would introduce a TDZ crash. Putting them
104
+ // BEFORE `resolveInsideWorkspace` removes that footgun.
105
+ // ---------------------------------------------------------------------------
106
+ function isInside(root, candidate) {
107
+ if (candidate === root)
108
+ return true;
109
+ // Compare with the native separator so Windows behaves correctly; the
110
+ // caller's relpath is converted to POSIX *after* this structural check.
111
+ return candidate.startsWith(`${root}${pathSep}`);
112
+ }
113
+ function toPosix(p) {
114
+ return pathSep === '/' ? p : p.split(pathSep).join('/');
115
+ }
116
+ export class SandboxError extends Error {
117
+ code;
118
+ requestedPath;
119
+ constructor(code, message, requestedPath) {
120
+ super(message);
121
+ this.name = 'SandboxError';
122
+ this.code = code;
123
+ this.requestedPath = requestedPath;
124
+ }
125
+ }
126
+ /** Absolute, real (symlink-resolved) path of `rootInput`. The caller must
127
+ * cache this value for the life of an agentic call so we avoid repeated
128
+ * `realpath` calls on the same root. */
129
+ export async function resolveWorkspaceRoot(rootInput) {
130
+ try {
131
+ return await realpath(resolve(rootInput));
132
+ }
133
+ catch (err) {
134
+ throw new SandboxError('NOT_FOUND', `workspace root does not exist or is unreadable: ${rootInput} (${String(err)})`, rootInput);
135
+ }
136
+ }
137
+ /**
138
+ * Resolve `relOrAbs` to a real (symlink-resolved) absolute path, or throw
139
+ * `SandboxError` if it escapes the workspace or matches a denylist.
140
+ *
141
+ * Returns both the resolved absolute path and the POSIX relative path —
142
+ * callers need the absolute for FS operations and the relative for logging
143
+ * and response payloads. Relative path is always forward-slash form
144
+ * regardless of host OS.
145
+ *
146
+ * Missing-file policy: when the target path doesn't exist on disk, we
147
+ * still enforce the structural jail on the PARENT of the missing leaf so
148
+ * a request like `read_file(".ssh/id_ed25519")` fails with `PATH_TRAVERSAL`
149
+ * even if that specific file is absent. Without walking to a real parent
150
+ * we'd leak a `NOT_FOUND` error that confirms the path shape to an
151
+ * attacker — indirect enumeration signal. Acceptable trade-off: the
152
+ * missing-file error for a valid path inside the root still surfaces as
153
+ * `NOT_FOUND` once the parent resolves.
154
+ */
155
+ export async function resolveInsideWorkspace(workspaceRoot, relOrAbs) {
156
+ if (typeof relOrAbs !== 'string' || relOrAbs.length === 0) {
157
+ throw new SandboxError('PATH_TRAVERSAL', 'path argument is empty', relOrAbs);
158
+ }
159
+ // Empty after normalisation (only whitespace) → reject.
160
+ const cleaned = relOrAbs.trim();
161
+ if (cleaned.length === 0) {
162
+ throw new SandboxError('PATH_TRAVERSAL', 'path argument is whitespace only', relOrAbs);
163
+ }
164
+ const candidate = resolve(workspaceRoot, cleaned);
165
+ // First pass: try to realpath the target. If it exists, we get a canonical
166
+ // symlink-resolved form. If not, walk up to the nearest existing parent
167
+ // and realpath that — so we detect escapes through symlinks that exist
168
+ // even if the leaf does not.
169
+ let resolved;
170
+ try {
171
+ resolved = await realpath(candidate);
172
+ }
173
+ catch {
174
+ // Target doesn't exist (yet). Walk to nearest existing ancestor so we
175
+ // can still assert "the parent is inside the workspace". This avoids
176
+ // leaking "file not found" for paths that are structurally illegal.
177
+ let parent = candidate;
178
+ let existingAncestor = null;
179
+ while (true) {
180
+ const next = resolve(parent, '..');
181
+ if (next === parent)
182
+ break; // hit filesystem root
183
+ parent = next;
184
+ try {
185
+ existingAncestor = await realpath(parent);
186
+ break;
187
+ }
188
+ catch {
189
+ /* keep walking */
190
+ }
191
+ }
192
+ if (existingAncestor === null) {
193
+ throw new SandboxError('NOT_FOUND', `path has no existing ancestor: ${relOrAbs}`, relOrAbs);
194
+ }
195
+ // Assert the existing ancestor is inside the jail. If YES, the missing
196
+ // leaf is legitimately absent inside the workspace; we return a
197
+ // `NOT_FOUND`. If NO, the request was trying to escape via a path
198
+ // whose leaf doesn't exist — treat as traversal.
199
+ if (!isInside(workspaceRoot, existingAncestor)) {
200
+ throw new SandboxError('PATH_TRAVERSAL', `path escapes workspace root: ${relOrAbs}`, relOrAbs);
201
+ }
202
+ throw new SandboxError('NOT_FOUND', `path does not exist: ${relOrAbs}`, relOrAbs);
203
+ }
204
+ // realpath succeeded — enforce jail on the RESOLVED path so symlinks are caught.
205
+ if (!isInside(workspaceRoot, resolved)) {
206
+ throw new SandboxError('PATH_TRAVERSAL', `path escapes workspace root (symlink or absolute outside): ${relOrAbs}`, relOrAbs);
207
+ }
208
+ const rel = toPosix(relative(workspaceRoot, resolved));
209
+ // Content denylist (Codex #4): secrets-by-basename + extension.
210
+ // Both checks are case-insensitive — macOS/APFS and Windows/NTFS are
211
+ // case-insensitive by default, so `.ENV` resolves to the same inode as
212
+ // `.env`. Comparing pre-lowercased protects against a file literally
213
+ // stored as `.ENV` (or `.Env.Local`, `CREDENTIALS`, …) bypassing the
214
+ // list. Extension check was already case-insensitive; basename check
215
+ // used to be strict-equal — bug reported in PR #24 review by Gemini.
216
+ const base = basename(resolved);
217
+ const lowerBase = base.toLowerCase();
218
+ if (AGENTIC_SECRET_BASENAMES_LOWER.has(lowerBase)) {
219
+ throw new SandboxError('SECRET_DENYLIST', `filename on secret-basename denylist: ${base}`, relOrAbs);
220
+ }
221
+ for (const ext of AGENTIC_SECRET_EXTENSIONS) {
222
+ if (lowerBase.endsWith(ext)) {
223
+ throw new SandboxError('SECRET_DENYLIST', `filename on secret-extension denylist: ${base}`, relOrAbs);
224
+ }
225
+ }
226
+ // Excluded-dir check: if the POSIX relative path sits under any entry in
227
+ // `DEFAULT_EXCLUDE_DIRS`, refuse. Same semantics as `globs.ts#isPathExcluded`
228
+ // but we reuse the table rather than the function to skip the MatchConfig
229
+ // plumbing (we already know we're inside the jail, so only dir-name
230
+ // matching matters here).
231
+ //
232
+ // Case-insensitive matching (PR #24 round-3 #2): we compare against the
233
+ // lowercased relative path + lowercased dir entries so macOS APFS /
234
+ // Windows NTFS (case-insensitive by default) don't let a file named
235
+ // `NODE_MODULES/foo.js` slip past a strict-case check.
236
+ //
237
+ // `SECRET_EXCLUDE_DIRS` wins before the generic list so `.ssh/id_ed25519`
238
+ // yields `SECRET_DENYLIST` (not `EXCLUDED_DIR`) — distinguishes "user
239
+ // tried to exfiltrate" from "this dir is just boring build output" in
240
+ // observability. Functionally both are blocked.
241
+ const relLower = rel.toLowerCase();
242
+ for (const dir of DEFAULT_EXCLUDE_DIRS) {
243
+ const dirLower = dir.toLowerCase();
244
+ const isHit = relLower === dirLower ||
245
+ relLower.startsWith(`${dirLower}/`) ||
246
+ relLower.includes(`/${dirLower}/`);
247
+ if (!isHit)
248
+ continue;
249
+ const code = SECRET_EXCLUDE_DIRS.has(dirLower)
250
+ ? 'SECRET_DENYLIST'
251
+ : 'EXCLUDED_DIR';
252
+ const detail = code === 'SECRET_DENYLIST'
253
+ ? `path is inside a secret-bearing directory: ${dir}`
254
+ : relLower === dirLower
255
+ ? `path is an excluded directory: ${dir}`
256
+ : `path is inside excluded directory: ${dir}`;
257
+ throw new SandboxError(code, detail, relOrAbs);
258
+ }
259
+ // And one more pass over DEFAULT_EXCLUDE_FILE_NAMES — lockfiles,
260
+ // tsconfig.tsbuildinfo, etc. — they were uninteresting even in the
261
+ // eager path, and definitely shouldn't cost agentic iterations.
262
+ // Uses the lowercased `Set` so mis-cased files (e.g. `PACKAGE-LOCK.JSON`
263
+ // on case-insensitive FS) still match. Uses `EXCLUDED_FILENAME`
264
+ // (distinct from `EXCLUDED_DIR`) so the calling model can tell
265
+ // "this is a blacklisted filename" from "this is a blacklisted
266
+ // directory" in the `functionResponse.error` payload.
267
+ if (DEFAULT_EXCLUDE_FILE_NAMES_LOWER.has(lowerBase)) {
268
+ throw new SandboxError('EXCLUDED_FILENAME', `filename on default exclude list: ${base}`, relOrAbs);
269
+ }
270
+ return { absolutePath: resolved, relpath: rel };
271
+ }
272
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../../src/tools/agentic/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;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IACJ,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAClD,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Executor functions for the four Gemini function-call tools used by
3
+ * `ask_agentic`. Each executor takes a workspace-rooted sandbox (from
4
+ * `./sandbox.ts`) and returns a JSON-serialisable result payload, or
5
+ * throws `SandboxError` on security violations / missing files.
6
+ *
7
+ * Hard size limits applied unconditionally (Codex PR2 review critical):
8
+ * - `read_file` per-file: ≤ 200 000 bytes returned (files over that
9
+ * get head-truncated and the response carries `truncated: true` + size
10
+ * metadata so the model can reason about the gap).
11
+ * - `grep` per-call response: ≤ 500 000 bytes of JSON body (matches
12
+ * truncated to fit, response carries `truncated: true`).
13
+ * - `list_directory` / `find_files`: capped by entry count (`MAX_LIST_ENTRIES`
14
+ * / `MAX_FIND_MATCHES`, both small integers) rather than a byte budget —
15
+ * each entry is a short record so the resulting JSON is bounded well
16
+ * under any per-call ceiling.
17
+ *
18
+ * Together these protect the per-iteration token budget from a single
19
+ * minified bundle or a massive listing burning output tokens on one call.
20
+ */
21
+ export interface DirEntry {
22
+ relpath: string;
23
+ type: 'file' | 'dir';
24
+ size?: number;
25
+ }
26
+ export interface ListDirectoryResult {
27
+ path: string;
28
+ entries: DirEntry[];
29
+ truncated: boolean;
30
+ totalEntries: number;
31
+ }
32
+ /**
33
+ * List immediate children of `relPath` (non-recursive). Default-excluded
34
+ * dirs and denylisted filenames are silently omitted; the model sees only
35
+ * paths it is allowed to ask for via `read_file` / `grep`.
36
+ */
37
+ export declare function listDirectoryExecutor(workspaceRoot: string, relPath: string): Promise<ListDirectoryResult>;
38
+ export interface FindFilesResult {
39
+ pattern: string;
40
+ matches: string[];
41
+ truncated: boolean;
42
+ totalMatches: number;
43
+ }
44
+ /**
45
+ * Recursive glob search inside the workspace. Respects default excludes +
46
+ * extension gating (same rules as the eager scanner, so the model never
47
+ * sees paths it couldn't `read_file` on anyway — avoids a foot-gun where
48
+ * the model tries to open a secret it saw in a `find_files` response).
49
+ */
50
+ export declare function findFilesExecutor(workspaceRoot: string, pattern: string): Promise<FindFilesResult>;
51
+ export interface ReadFileResult {
52
+ relpath: string;
53
+ content: string;
54
+ startLine: number;
55
+ endLine: number;
56
+ totalLines: number;
57
+ truncated: boolean;
58
+ truncationReason?: 'max_lines' | 'max_bytes';
59
+ totalBytes: number;
60
+ }
61
+ /**
62
+ * Read a file with bounded bytes + lines. Every response includes enough
63
+ * metadata (`totalLines`, `totalBytes`, `truncated`, `truncationReason`) for
64
+ * the model to request the next slice intelligently.
65
+ *
66
+ * Slicing semantics:
67
+ * - `startLine` / `endLine` are 1-indexed inclusive ranges when given.
68
+ * - Omit both → return the first `DEFAULT_READ_LINE_LIMIT` lines, up to
69
+ * `MAX_READ_BYTES`, whichever hits first.
70
+ */
71
+ export declare function readFileExecutor(workspaceRoot: string, relPath: string, startLine?: number, endLine?: number): Promise<ReadFileResult>;
72
+ export interface GrepMatch {
73
+ relpath: string;
74
+ line: number;
75
+ text: string;
76
+ }
77
+ export interface GrepResult {
78
+ pattern: string;
79
+ pathPrefix: string | null;
80
+ matches: GrepMatch[];
81
+ truncated: boolean;
82
+ totalMatches: number;
83
+ }
84
+ /**
85
+ * Recursive regex search. Supports a basic anchored `pathPrefix` so the
86
+ * model can scope to a subtree. Pattern is compiled as JS RegExp — the
87
+ * model can use standard metacharacters.
88
+ *
89
+ * Hard caps:
90
+ * - `MAX_GREP_MATCHES` matches returned
91
+ * - each match line truncated to 500 chars (guard against minified
92
+ * lines flooding the payload)
93
+ */
94
+ export declare function grepExecutor(workspaceRoot: string, pattern: string, pathPrefix?: string): Promise<GrepResult>;
95
+ /** Export knobs for tests to reference without re-declaring numeric values. */
96
+ export declare const AGENTIC_LIMITS: Readonly<{
97
+ readonly MAX_READ_BYTES: 200000;
98
+ readonly MAX_RESPONSE_BYTES: 500000;
99
+ readonly DEFAULT_READ_LINE_LIMIT: 500;
100
+ readonly MAX_GREP_MATCHES: 100;
101
+ readonly MAX_LIST_ENTRIES: 200;
102
+ readonly MAX_FIND_MATCHES: 200;
103
+ }>;
104
+ //# sourceMappingURL=workspace-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-tools.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/workspace-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqGH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC,CA4D9B;AAMD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC,CA6E1B;AAMD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IAC7C,U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