@gaunt-sloth/agent 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (86) hide show
  1. package/README.md +10 -0
  2. package/dist/builtInToolsConfig.d.ts +17 -3
  3. package/dist/builtInToolsConfig.js +41 -14
  4. package/dist/builtInToolsConfig.js.map +1 -1
  5. package/dist/core/GthDeepAgent.d.ts +63 -13
  6. package/dist/core/GthDeepAgent.js +360 -130
  7. package/dist/core/GthDeepAgent.js.map +1 -1
  8. package/dist/core/debugCapture.d.ts +8 -49
  9. package/dist/core/debugCapture.js +1 -1
  10. package/dist/core/debugCapture.js.map +1 -1
  11. package/dist/core/deepAgentPermissions.d.ts +73 -13
  12. package/dist/core/deepAgentPermissions.js +191 -29
  13. package/dist/core/deepAgentPermissions.js.map +1 -1
  14. package/dist/core/gthAcpServer.js +11 -0
  15. package/dist/core/gthAcpServer.js.map +1 -1
  16. package/dist/core/gthDeepAgentFactory.d.ts +3 -0
  17. package/dist/core/gthDeepAgentFactory.js +9 -1
  18. package/dist/core/gthDeepAgentFactory.js.map +1 -1
  19. package/dist/core/resolveAgentFactory.d.ts +14 -0
  20. package/dist/core/resolveAgentFactory.js +18 -0
  21. package/dist/core/resolveAgentFactory.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/mcp/OAuthClientProviderImpl.js +2 -2
  26. package/dist/mcp/OAuthClientProviderImpl.js.map +1 -1
  27. package/dist/mcp/tlsTrust.d.ts +61 -0
  28. package/dist/mcp/tlsTrust.js +109 -0
  29. package/dist/mcp/tlsTrust.js.map +1 -0
  30. package/dist/middleware/registry.d.ts +1 -1
  31. package/dist/middleware/registry.js +1 -1
  32. package/dist/middleware/types.d.ts +1 -1
  33. package/dist/middleware/types.js +1 -1
  34. package/dist/modules/a2a/A2AClientWrapper.d.ts +46 -0
  35. package/dist/modules/a2a/A2AClientWrapper.js +71 -0
  36. package/dist/modules/a2a/A2AClientWrapper.js.map +1 -1
  37. package/dist/modules/acpModule.d.ts +5 -2
  38. package/dist/modules/acpModule.js +13 -2
  39. package/dist/modules/acpModule.js.map +1 -1
  40. package/dist/modules/apiAgUiModule.js +48 -16
  41. package/dist/modules/apiAgUiModule.js.map +1 -1
  42. package/dist/modules/interactiveSessionModule.js +140 -7
  43. package/dist/modules/interactiveSessionModule.js.map +1 -1
  44. package/dist/resolvers.js +104 -9
  45. package/dist/resolvers.js.map +1 -1
  46. package/dist/tools/GthCustomToolkit.js +24 -9
  47. package/dist/tools/GthCustomToolkit.js.map +1 -1
  48. package/dist/tools/GthDevToolkit.d.ts +45 -1
  49. package/dist/tools/GthDevToolkit.js +229 -31
  50. package/dist/tools/GthDevToolkit.js.map +1 -1
  51. package/dist/tools/GthFileSystemToolkit.d.ts +47 -0
  52. package/dist/tools/GthFileSystemToolkit.js +305 -18
  53. package/dist/tools/GthFileSystemToolkit.js.map +1 -1
  54. package/dist/tools/gthChecklistTool.d.ts +30 -0
  55. package/dist/tools/gthChecklistTool.js +81 -0
  56. package/dist/tools/gthChecklistTool.js.map +1 -0
  57. package/dist/tools/gthGrepTool.d.ts +54 -0
  58. package/dist/tools/gthGrepTool.js +482 -0
  59. package/dist/tools/gthGrepTool.js.map +1 -0
  60. package/dist/tools/shell/allowlist.d.ts +11 -0
  61. package/dist/tools/shell/allowlist.js +12 -0
  62. package/dist/tools/shell/allowlist.js.map +1 -0
  63. package/dist/tools/shell/arity.d.ts +11 -0
  64. package/dist/tools/shell/arity.js +12 -0
  65. package/dist/tools/shell/arity.js.map +1 -0
  66. package/dist/tools/shell/env.d.ts +22 -0
  67. package/dist/tools/shell/env.js +110 -0
  68. package/dist/tools/shell/env.js.map +1 -0
  69. package/dist/tools/shell/hardline.d.ts +15 -0
  70. package/dist/tools/shell/hardline.js +88 -0
  71. package/dist/tools/shell/hardline.js.map +1 -0
  72. package/dist/tools/shell/normalize.d.ts +10 -0
  73. package/dist/tools/shell/normalize.js +11 -0
  74. package/dist/tools/shell/normalize.js.map +1 -0
  75. package/dist/tools/shell/outputBuffer.d.ts +53 -0
  76. package/dist/tools/shell/outputBuffer.js +157 -0
  77. package/dist/tools/shell/outputBuffer.js.map +1 -0
  78. package/dist/tools/shell/workDir.d.ts +11 -0
  79. package/dist/tools/shell/workDir.js +45 -0
  80. package/dist/tools/shell/workDir.js.map +1 -0
  81. package/dist/utils/mcpAuthError.d.ts +36 -0
  82. package/dist/utils/mcpAuthError.js +89 -0
  83. package/dist/utils/mcpAuthError.js.map +1 -0
  84. package/dist/utils/mcpUtils.js +16 -0
  85. package/dist/utils/mcpUtils.js.map +1 -1
  86. package/package.json +14 -13
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @module gthChecklistTool
3
+ * The `gth_checklist` planning tool — the lean agent's first-party equivalent of the deepagents
4
+ * `write_todos` capability. Gives the model a durable, structured task list for multi-step work so
5
+ * it can plan, track progress, and stay oriented across a long run.
6
+ *
7
+ * Design (mirrors Claude Code's `TodoWrite` / opencode's todo tools): the model sends the WHOLE
8
+ * list every call and it REPLACES the previous one (no incremental add/remove verbs to keep in
9
+ * sync). State is a closure private to each `get()` result, i.e. one list per agent init / session,
10
+ * so concurrent sessions (e.g. the AG-UI server) never share a checklist. The tool returns a
11
+ * rendered markdown checklist as its observation; the TUI additionally folds it into a live
12
+ * checkbox panel (see {@link file://../../../app/src/tui/viewModel.ts} `CHECKLIST_TOOL_NAME`).
13
+ *
14
+ * The name is deliberately NOT `write_todos` (nor `task`/`read_file`/`write_file`/`edit_file`/`ls`):
15
+ * on the experimental deep backend `createDeepAgent` throws on a name collision with its built-ins,
16
+ * and both backends share the same resolved toolset.
17
+ */
18
+ import { tool } from '@langchain/core/tools';
19
+ import { z } from 'zod';
20
+ export const CHECKLIST_TOOL_NAME = 'gth_checklist';
21
+ const itemSchema = z.object({
22
+ content: z
23
+ .string()
24
+ .min(1)
25
+ .describe('Short, imperative description of the task, e.g. "Add tests"'),
26
+ status: z
27
+ .enum(['pending', 'in_progress', 'completed'])
28
+ .describe('pending = not started, in_progress = being worked on now, completed = finished'),
29
+ });
30
+ const schema = z.object({
31
+ items: z
32
+ .array(itemSchema)
33
+ .describe('The FULL checklist. This replaces any previous checklist entirely.'),
34
+ });
35
+ const description = [
36
+ 'Record and update a checklist (todo list) for the current task. Use it to plan multi-step',
37
+ 'work and to show the user your progress. Send the ENTIRE list every time — it replaces the',
38
+ 'previous checklist, so include already-completed items too.',
39
+ '',
40
+ 'When to use: any task with 3+ distinct steps, or when the user gives several requirements.',
41
+ 'Skip it for a single trivial step.',
42
+ '',
43
+ 'Rules:',
44
+ '- Keep at most ONE item "in_progress" at a time.',
45
+ '- Mark an item "completed" as soon as it is done — do not batch completions.',
46
+ '- Keep item text short and outcome-focused.',
47
+ ].join('\n');
48
+ const STATUS_GLYPH = {
49
+ completed: '[x]',
50
+ in_progress: '[~]',
51
+ pending: '[ ]',
52
+ };
53
+ /** Render a checklist as a markdown observation the model (and a plain terminal) can read back. */
54
+ export function formatChecklist(items) {
55
+ if (items.length === 0) {
56
+ return 'Checklist cleared (no items).';
57
+ }
58
+ const completed = items.filter((i) => i.status === 'completed').length;
59
+ const header = `Checklist (${completed}/${items.length} completed):`;
60
+ const lines = items.map((i) => `${STATUS_GLYPH[i.status]} ${i.content}`);
61
+ return [header, ...lines].join('\n');
62
+ }
63
+ export function get(_config) {
64
+ // Session-scoped state: one list per tool instance (== per agent init). Whole-list-replace
65
+ // semantics mean each call overwrites this; it is kept so the tool can render the current
66
+ // state back as its observation.
67
+ let items = [];
68
+ const impl = async ({ items: next }) => {
69
+ const inProgress = next.filter((i) => i.status === 'in_progress').length;
70
+ if (inProgress > 1) {
71
+ // Do NOT mutate state on a malformed update — return guidance so the model can retry.
72
+ return (`Rejected: ${inProgress} items are "in_progress" but only one may be in progress at a ` +
73
+ 'time. Set all but the current task to "pending" or "completed" and call gth_checklist ' +
74
+ 'again.');
75
+ }
76
+ items = next;
77
+ return formatChecklist(items);
78
+ };
79
+ return tool(impl, { name: CHECKLIST_TOOL_NAME, description, schema });
80
+ }
81
+ //# sourceMappingURL=gthChecklistTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gthChecklistTool.js","sourceRoot":"","sources":["../../src/tools/gthChecklistTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AASnD,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,6DAA6D,CAAC;IAC1E,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;SAC7C,QAAQ,CAAC,gFAAgF,CAAC;CAC9F,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,KAAK,EAAE,CAAC;SACL,KAAK,CAAC,UAAU,CAAC;SACjB,QAAQ,CAAC,oEAAoE,CAAC;CAClF,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG;IAClB,2FAA2F;IAC3F,4FAA4F;IAC5F,6DAA6D;IAC7D,EAAE;IACF,4FAA4F;IAC5F,oCAAoC;IACpC,EAAE;IACF,QAAQ;IACR,kDAAkD;IAClD,8EAA8E;IAC9E,6CAA6C;CAC9C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,YAAY,GAAoC;IACpD,SAAS,EAAE,KAAK;IAChB,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAA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CAAC;AACxE,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { z } from 'zod';
2
+ import { GthConfig } from '@gaunt-sloth/core/config.js';
3
+ export declare const GREP_TOOL_NAME = "gth_grep";
4
+ /**
5
+ * GS2-51 — which corpus `gth_grep` scans, applied consistently to BOTH engines:
6
+ * - `gitignore` (default): respect `.gitignore`/`.ignore` and skip hidden dot-files (rg's default);
7
+ * - `all`: scan everything but the {@link IGNORED_DIRS} noise set (rg gets `--no-ignore --hidden`).
8
+ */
9
+ export type GrepFileSet = 'gitignore' | 'all';
10
+ /**
11
+ * Resolve the effective {@link GrepFileSet} from config. Reads the `gth_grep` entry of the SAME
12
+ * `builtInTools` registry that {@link file://../builtInToolsConfig.ts} uses to decide enablement, so
13
+ * the corpus selection and the tool's presence resolve from one source. Defaults to `gitignore`
14
+ * (the coordinator-set default, and already rg's native default — so rg-present machines see no
15
+ * behaviour change; only the selection becomes explicit).
16
+ */
17
+ export declare function resolveGrepFileSet(config: GthConfig): GrepFileSet;
18
+ /** A single content match. `path` is relative to the search root; `line` is 1-based. */
19
+ export interface GrepMatch {
20
+ path: string;
21
+ line: number;
22
+ /** The matching line's text, untruncated (bounded at format time). */
23
+ text: string;
24
+ }
25
+ /**
26
+ * Render matches in the concise, opencode-style grouped form. Shared by BOTH execution paths so
27
+ * the rg and JS-fallback outputs are provably identical.
28
+ */
29
+ export declare function formatGrepOutput(matches: GrepMatch[]): string;
30
+ /**
31
+ * Compile an include glob (matched against a file's basename in the JS fallback) to a RegExp.
32
+ * Supports `*`, `?`, and `{a,b,c}` brace alternation, e.g. `*.ts`, `*.{ts,tsx}`.
33
+ *
34
+ * NOTE (rg-vs-JS divergence): this matches the basename only, whereas rg applies `--glob` with full
35
+ * gitignore-style path-glob semantics (a glob can match against the path, not just the basename).
36
+ * For the common `*.ext` case the two agree; more elaborate globs may differ between the two paths.
37
+ */
38
+ export declare function globToRegExp(glob: string): RegExp;
39
+ export declare function get(config: GthConfig): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
40
+ pattern: z.ZodString;
41
+ path: z.ZodOptional<z.ZodString>;
42
+ include: z.ZodOptional<z.ZodString>;
43
+ limit: z.ZodOptional<z.ZodNumber>;
44
+ }, z.core.$strip>, {
45
+ pattern: string;
46
+ path?: string | undefined;
47
+ include?: string | undefined;
48
+ limit?: number | undefined;
49
+ }, {
50
+ pattern: string;
51
+ path?: string | undefined;
52
+ include?: string | undefined;
53
+ limit?: number | undefined;
54
+ }, string, unknown, "gth_grep">;
@@ -0,0 +1,482 @@
1
+ /**
2
+ * @module gthGrepTool
3
+ * The `gth_grep` content-search tool — a structured, permission-light regex search over file
4
+ * CONTENTS. Complements `search_files` (which only matches file NAMES) and gives the lean agent a
5
+ * grep primitive without falling back to the shell-approval-gated `run_shell_command`. Being a
6
+ * built-in (not a dev tool) it is available in every mode, unlike `run_shell_command`.
7
+ *
8
+ * Two execution paths, ONE output shape:
9
+ * - shell out to ripgrep (`rg`) when it is on PATH;
10
+ * - fall back to an in-process JS scanner when `rg` is absent (CI machines may not have ripgrep).
11
+ * Both sandbox to the current work-dir boundary ({@link getCurrentWorkDir}), bound each matching
12
+ * line's preview, cap the total match count, and enforce the `.aiignore` privacy boundary on BOTH
13
+ * engines ({@link makeAiignoreFilter}) — since the tool reads file contents through its own path, it
14
+ * must honour `.aiignore` itself rather than rely on the filesystem toolkit.
15
+ *
16
+ * Named `gth_grep`, NOT `grep`: the experimental deep backend (deepagents) registers its own `grep`
17
+ * built-in and `createDeepAgent` throws on a name collision because both backends share the resolved
18
+ * toolset — the same reason {@link file://./gthChecklistTool.ts} is not called `write_todos`.
19
+ */
20
+ import { tool } from '@langchain/core/tools';
21
+ import { z } from 'zod';
22
+ import { execFile } from 'node:child_process';
23
+ import fs from 'node:fs/promises';
24
+ import path from 'node:path';
25
+ import { normalizeBuiltInTools } from '@gaunt-sloth/core/config.js';
26
+ import { getCurrentWorkDir } from '@gaunt-sloth/core/utils/systemUtils.js';
27
+ import { shouldIgnoreFile } from '@gaunt-sloth/core/utils/aiignoreUtils.js';
28
+ export const GREP_TOOL_NAME = 'gth_grep';
29
+ /**
30
+ * Resolve the effective {@link GrepFileSet} from config. Reads the `gth_grep` entry of the SAME
31
+ * `builtInTools` registry that {@link file://../builtInToolsConfig.ts} uses to decide enablement, so
32
+ * the corpus selection and the tool's presence resolve from one source. Defaults to `gitignore`
33
+ * (the coordinator-set default, and already rg's native default — so rg-present machines see no
34
+ * behaviour change; only the selection becomes explicit).
35
+ */
36
+ export function resolveGrepFileSet(config) {
37
+ const entry = normalizeBuiltInTools(config?.builtInTools)[GREP_TOOL_NAME];
38
+ if (entry && typeof entry === 'object' && entry.fileSet === 'all')
39
+ return 'all';
40
+ return 'gitignore';
41
+ }
42
+ /**
43
+ * Build the `.aiignore` privacy filter for a grep run.
44
+ *
45
+ * SECURITY (GS2-51): `gth_grep` reads file CONTENTS through its OWN ripgrep / `fs.readFile` path,
46
+ * so — unlike the gsloth filesystem toolkit — it must enforce `.aiignore` ITSELF. Otherwise, being
47
+ * on by default, it would be a default-on bypass of that boundary on BOTH backends: the deep backend
48
+ * deliberately disables its fs toolkit precisely so a model cannot read an `.aiignore`-protected file
49
+ * (see {@link file://../core/GthDeepAgent.ts}), and `gth_grep` would re-open exactly that hole.
50
+ * `.gitignore` means "don't commit" (build junk); `.aiignore` means "don't let the AI read this,
51
+ * even though it is a real tracked file" — so an `.aiignore`'d-but-tracked-and-not-hidden file is the
52
+ * PRIMARY case, and is enforced on BOTH engines and under BOTH {@link GrepFileSet} corpora (the
53
+ * privacy boundary is orthogonal to the gitignore/all selection).
54
+ *
55
+ * Reuses the SAME {@link shouldIgnoreFile} matcher and the SAME rootDir (the work-dir) the fs toolkit
56
+ * uses, so a file is treated identically here as there — no hand-rolled `.aiignore` parsing.
57
+ *
58
+ * @returns predicate that is TRUE when `absPath` is ALLOWED (not aiignored).
59
+ */
60
+ function makeAiignoreFilter(workDir, aiignore) {
61
+ return (absPath) => !shouldIgnoreFile(absPath, workDir, aiignore?.patterns, aiignore?.enabled);
62
+ }
63
+ /** Default cap on the number of matches returned when the caller does not pass `limit`. */
64
+ const DEFAULT_LIMIT = 100;
65
+ /** Noise directories both paths skip: the JS fallback walk, and rg via `--glob !<dir>` excludes. */
66
+ const IGNORED_DIRS = new Set(['.git', 'node_modules', 'dist', '.idea']);
67
+ /** Longest matching-line preview kept before truncation, so one minified line can't blow context. */
68
+ const MAX_LINE_LENGTH = 250;
69
+ const TRUNCATION_MARKER = ' … (line truncated)';
70
+ /**
71
+ * JS-fallback only: cap the length of text fed to the regex per line. A single huge/minified line
72
+ * would otherwise let a model-supplied pattern block the event loop (large linear scans, and
73
+ * catastrophic backtracking grows with input length). rg (native, non-backtracking) is immune, so
74
+ * this bounds the fallback only. Matches beyond the cap on such a line are not found.
75
+ */
76
+ const MAX_SCAN_LINE_LENGTH = 4096;
77
+ /** Ceiling on rg stdout we buffer (matches are sliced to `limit` anyway). */
78
+ const RG_MAX_BUFFER = 32 * 1024 * 1024;
79
+ const schema = z.object({
80
+ pattern: z.string().min(1).describe('Regular expression to search file CONTENTS for.'),
81
+ path: z
82
+ .string()
83
+ .optional()
84
+ .describe('Relative directory or file to search, within the working directory. Defaults to the ' +
85
+ 'current working directory.'),
86
+ include: z
87
+ .string()
88
+ .optional()
89
+ .describe('Optional file glob to filter matched files, e.g. "*.ts" or "*.{ts,tsx}".'),
90
+ limit: z
91
+ .number()
92
+ .int()
93
+ .min(1)
94
+ .optional()
95
+ .describe(`Maximum number of matches to return (default ${DEFAULT_LIMIT}).`),
96
+ });
97
+ const description = [
98
+ 'Search file CONTENTS by regular expression (ripgrep-backed, with an in-process fallback).',
99
+ 'Use this to find WHERE a symbol, string, or pattern appears across files — unlike search_files,',
100
+ 'which matches file NAMES only. Returns matching files with 1-based line numbers and a bounded',
101
+ 'preview of each matching line.',
102
+ '',
103
+ 'Args: pattern (regex, required); path (relative dir/file, defaults to the working directory);',
104
+ 'include (file glob such as "*.ts" or "*.{ts,tsx}"); limit (max matches). Searches are confined',
105
+ 'to the working directory.',
106
+ ].join('\n');
107
+ /** Error whose message is safe to return to the model as the tool observation. */
108
+ class GrepError extends Error {
109
+ }
110
+ /** Sentinel: `rg` is not installed — the orchestrator must use the JS fallback. */
111
+ class RipgrepUnavailableError extends Error {
112
+ }
113
+ /** Truncate an over-long matching-line preview with a clear marker. */
114
+ function truncateLine(text) {
115
+ if (text.length <= MAX_LINE_LENGTH)
116
+ return text;
117
+ return text.slice(0, MAX_LINE_LENGTH) + TRUNCATION_MARKER;
118
+ }
119
+ /**
120
+ * Render matches in the concise, opencode-style grouped form. Shared by BOTH execution paths so
121
+ * the rg and JS-fallback outputs are provably identical.
122
+ */
123
+ export function formatGrepOutput(matches) {
124
+ if (matches.length === 0)
125
+ return 'No matches found';
126
+ const lines = [`Found ${matches.length} matches`];
127
+ let currentPath = '';
128
+ for (const m of matches) {
129
+ if (m.path !== currentPath) {
130
+ if (currentPath)
131
+ lines.push('');
132
+ currentPath = m.path;
133
+ lines.push(`${m.path}:`);
134
+ }
135
+ lines.push(` Line ${m.line}: ${truncateLine(m.text)}`);
136
+ }
137
+ return lines.join('\n');
138
+ }
139
+ /** rg prints `./foo` for the cwd root; normalise to bare relative paths to match the JS scanner. */
140
+ function normalizeRelPath(p) {
141
+ return p.startsWith('./') ? p.slice(2) : p;
142
+ }
143
+ /** Escape the literal parts of a glob for use inside a RegExp. */
144
+ function escapeRegExp(s) {
145
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
146
+ }
147
+ /**
148
+ * Compile an include glob (matched against a file's basename in the JS fallback) to a RegExp.
149
+ * Supports `*`, `?`, and `{a,b,c}` brace alternation, e.g. `*.ts`, `*.{ts,tsx}`.
150
+ *
151
+ * NOTE (rg-vs-JS divergence): this matches the basename only, whereas rg applies `--glob` with full
152
+ * gitignore-style path-glob semantics (a glob can match against the path, not just the basename).
153
+ * For the common `*.ext` case the two agree; more elaborate globs may differ between the two paths.
154
+ */
155
+ export function globToRegExp(glob) {
156
+ let re = '';
157
+ let i = 0;
158
+ while (i < glob.length) {
159
+ const c = glob[i];
160
+ if (c === '*') {
161
+ re += '[^/]*';
162
+ }
163
+ else if (c === '?') {
164
+ re += '[^/]';
165
+ }
166
+ else if (c === '{') {
167
+ const end = glob.indexOf('}', i);
168
+ if (end === -1) {
169
+ re += '\\{';
170
+ }
171
+ else {
172
+ const options = glob
173
+ .slice(i + 1, end)
174
+ .split(',')
175
+ .map(escapeRegExp);
176
+ re += '(?:' + options.join('|') + ')';
177
+ i = end + 1;
178
+ continue;
179
+ }
180
+ }
181
+ else {
182
+ re += escapeRegExp(c);
183
+ }
184
+ i++;
185
+ }
186
+ return new RegExp('^' + re + '$');
187
+ }
188
+ /**
189
+ * Resolve a path to its real, symlink-free location, walking up to the nearest EXISTING ancestor
190
+ * when the path itself does not exist yet. Only an existing component can be (or sit behind) a
191
+ * symlink, so resolving the nearest real ancestor is enough to catch an intermediate symlinked
192
+ * directory. Terminates because `path.dirname` strictly shortens the path to the filesystem root.
193
+ */
194
+ async function realpathNearestExisting(absPath) {
195
+ let current = absPath;
196
+ for (;;) {
197
+ try {
198
+ return await fs.realpath(current);
199
+ }
200
+ catch {
201
+ const parent = path.dirname(current);
202
+ if (parent === current)
203
+ return current; // filesystem root; nothing left to resolve
204
+ current = parent;
205
+ }
206
+ }
207
+ }
208
+ /** True when `child` equals `root` or is a descendant of it. */
209
+ function isWithin(child, root) {
210
+ return child === root || child.startsWith(`${root}${path.sep}`);
211
+ }
212
+ /**
213
+ * Resolve `path` under the working directory and refuse anything that escapes it. The whole tool
214
+ * is sandboxed to this boundary.
215
+ */
216
+ async function resolveTarget(inputPath, workDir) {
217
+ const absWorkDir = path.resolve(workDir);
218
+ const requested = path.resolve(absWorkDir, inputPath ?? '.');
219
+ const rel = path.relative(absWorkDir, requested);
220
+ if (rel.startsWith('..') || path.isAbsolute(rel)) {
221
+ throw new GrepError(`Refusing to search '${inputPath}': path escapes the working directory (${absWorkDir}).`);
222
+ }
223
+ // Symlink containment: the lexical check above cannot catch a symlink INSIDE the workdir that
224
+ // points outside it (rel would not start with `..`, and stat/rg/the walk would then follow it out
225
+ // of the sandbox). Resolve real paths and re-assert containment. The workdir root is realpath'd
226
+ // too, since its own path may contain symlinks (e.g. /tmp -> /private/tmp). A not-yet-existing
227
+ // target resolves via its nearest existing ancestor, so a missing path is contained here and then
228
+ // reported as "not found" by the stat below, rather than crashing.
229
+ const realRoot = await realpathNearestExisting(absWorkDir);
230
+ const realTarget = await realpathNearestExisting(requested);
231
+ if (!isWithin(realTarget, realRoot)) {
232
+ throw new GrepError(`Refusing to search '${inputPath}': path escapes the working directory (${absWorkDir}).`);
233
+ }
234
+ let stat;
235
+ try {
236
+ stat = await fs.stat(requested);
237
+ }
238
+ catch {
239
+ throw new GrepError(`Path not found: ${inputPath ?? '.'}`);
240
+ }
241
+ if (stat.isDirectory()) {
242
+ return { searchRoot: requested };
243
+ }
244
+ return { searchRoot: path.dirname(requested), file: path.basename(requested) };
245
+ }
246
+ /** Parse ripgrep's `path:line:text` output (with `--with-filename --line-number --no-heading`). */
247
+ function parseRipgrepOutput(stdout) {
248
+ const matches = [];
249
+ for (const raw of stdout.split('\n')) {
250
+ if (!raw)
251
+ continue;
252
+ const first = raw.indexOf(':');
253
+ if (first < 0)
254
+ continue;
255
+ const second = raw.indexOf(':', first + 1);
256
+ if (second < 0)
257
+ continue;
258
+ const lineNum = Number(raw.slice(first + 1, second));
259
+ if (!Number.isInteger(lineNum))
260
+ continue;
261
+ matches.push({
262
+ path: normalizeRelPath(raw.slice(0, first)),
263
+ line: lineNum,
264
+ text: raw.slice(second + 1),
265
+ });
266
+ }
267
+ return matches;
268
+ }
269
+ function buildRipgrepArgs(pattern, target, include, fileSet) {
270
+ // GS2-51 — the searched corpus is a resolved config choice ({@link GrepFileSet}), applied
271
+ // consistently to both engines. `gitignore` (default) keeps rg's native behaviour: honour
272
+ // `.gitignore`/`.ignore` and skip hidden dot-files — so nothing is added here. `all` scans
273
+ // everything but the noise dirs, so pass `--no-ignore --hidden` (the IGNORED_DIRS excludes below
274
+ // still apply). NOTE (residual rg-vs-JS divergence): under `gitignore` the JS fallback
275
+ // ({@link collectFiles}) is only a best-effort approximation (skips IGNORED_DIRS + hidden
276
+ // dot-files); it does NOT read arbitrary `.gitignore` rules the way rg does, so the searched
277
+ // file-set can still differ when rg is absent. A full gitignore parser is deliberately out of
278
+ // scope — see the note on {@link collectFiles}.
279
+ const args = ['--line-number', '--no-heading', '--with-filename', '--color=never'];
280
+ if (fileSet === 'all') {
281
+ args.push('--no-ignore', '--hidden');
282
+ }
283
+ // Exclude the same noise dirs the JS fallback skips, so the two paths stay consistent. rg only
284
+ // auto-skips node_modules etc. when a .gitignore says so; outside a git repo (or under
285
+ // `--no-ignore`) it descends into them, so we exclude them explicitly here.
286
+ for (const dir of IGNORED_DIRS) {
287
+ args.push('--glob', `!${dir}`);
288
+ }
289
+ if (include) {
290
+ args.push('--glob', include);
291
+ }
292
+ args.push('-e', pattern, '--', target.file ?? '.');
293
+ return args;
294
+ }
295
+ /**
296
+ * Run ripgrep. Resolves to matches (empty on rg exit 1 = "no matches"). Rejects with
297
+ * {@link RipgrepUnavailableError} when `rg` is not on PATH, or {@link GrepError} on a real rg error
298
+ * (e.g. an invalid regex → rg exit 2).
299
+ */
300
+ function runRipgrep(pattern, target, include, fileSet, isAllowed) {
301
+ const args = buildRipgrepArgs(pattern, target, include, fileSet);
302
+ return new Promise((resolve, reject) => {
303
+ execFile('rg', args, { cwd: target.searchRoot, maxBuffer: RG_MAX_BUFFER }, (error, stdout, stderr) => {
304
+ if (error) {
305
+ const code = error
306
+ .code;
307
+ if (code === 'ENOENT') {
308
+ reject(new RipgrepUnavailableError('ripgrep (rg) not found on PATH'));
309
+ return;
310
+ }
311
+ // rg exit code 1 == no matches (execFile surfaces the non-zero exit as an error).
312
+ if (code === 1) {
313
+ resolve([]);
314
+ return;
315
+ }
316
+ const detail = (stderr ?? '').toString().trim();
317
+ reject(new GrepError(`Search failed: ${detail || error.message}`));
318
+ return;
319
+ }
320
+ // rg does not consult `.aiignore` — post-filter its matched paths through the SAME hook the
321
+ // JS fallback uses, so both engines enforce the privacy boundary identically. A match whose
322
+ // file is aiignored is dropped before it can reach the model.
323
+ resolve(parseRipgrepOutput(stdout.toString()).filter((m) => isAllowed(path.join(target.searchRoot, m.path))));
324
+ });
325
+ });
326
+ }
327
+ /**
328
+ * Recursively collect regular files under `dir`, skipping {@link IGNORED_DIRS}. Symlinked entries
329
+ * (dirs and files) report `isDirectory()`/`isFile()` as false here, so the walk never follows them
330
+ * out of the sandbox — only the explicit target path needs the realpath guard in {@link resolveTarget}.
331
+ *
332
+ * GS2-51 — corpus selection ({@link GrepFileSet}), applied consistently with the rg path:
333
+ * - `skipHidden` true (the `gitignore` default): additionally skip hidden dot-files/dirs, moving the
334
+ * fallback CLOSER to rg's default of honouring `.gitignore` + hiding dot-files;
335
+ * - `skipHidden` false (`all`): skip only IGNORED_DIRS — everything-but-noise (the historical
336
+ * behaviour), matching rg's `--no-ignore --hidden`.
337
+ *
338
+ * NOTE (residual rg-vs-JS divergence — deliberate, bounded scope): even under `gitignore` this is
339
+ * only a best-effort approximation. It does NOT parse arbitrary `.gitignore`/`.ignore` rules the way
340
+ * rg does — a file gitignored by a custom pattern (but not a dot-file and not under IGNORED_DIRS) is
341
+ * still searched by the fallback though rg would skip it. Implementing a full gitignore engine here
342
+ * is out of scope; this is documented, not fixed — exactly like the regex-dialect divergence noted
343
+ * in {@link runJsScanner}.
344
+ */
345
+ async function collectFiles(dir, out, skipHidden) {
346
+ let entries;
347
+ try {
348
+ entries = (await fs.readdir(dir, { withFileTypes: true }));
349
+ }
350
+ catch {
351
+ return;
352
+ }
353
+ for (const entry of entries) {
354
+ // Hidden-skip is checked first so it covers BOTH hidden files and hidden dirs.
355
+ if (skipHidden && entry.name.startsWith('.'))
356
+ continue;
357
+ const full = path.join(dir, entry.name);
358
+ if (entry.isDirectory()) {
359
+ if (IGNORED_DIRS.has(entry.name))
360
+ continue;
361
+ await collectFiles(full, out, skipHidden);
362
+ }
363
+ else if (entry.isFile()) {
364
+ out.push(full);
365
+ }
366
+ }
367
+ }
368
+ /**
369
+ * In-process fallback used when `rg` is absent: walk files under the target (respecting `include`
370
+ * and the ignore list) and apply the regex per line. Produces the identical {@link GrepMatch} shape
371
+ * as the ripgrep path.
372
+ */
373
+ async function runJsScanner(pattern, target, include, limit, fileSet, isAllowed) {
374
+ let regex;
375
+ try {
376
+ // NOTE (rg-vs-JS divergence): the fallback uses the ECMAScript regex dialect (`new RegExp`),
377
+ // whereas rg uses the Rust `regex` crate. Host-specific features differ — notably lookaround
378
+ // and backreferences work here but are unsupported by rg — so the same pattern can behave
379
+ // differently depending on which path runs.
380
+ regex = new RegExp(pattern);
381
+ }
382
+ catch (e) {
383
+ throw new GrepError(`Search failed: invalid regular expression: ${e.message}`);
384
+ }
385
+ const includeRe = include ? globToRegExp(include) : undefined;
386
+ const files = [];
387
+ if (target.file) {
388
+ // An explicitly-named target file is searched even if it is a hidden dot-file — the corpus
389
+ // selection only governs directory discovery, matching rg's behaviour on an explicit arg. The
390
+ // one exception is `.aiignore`: an aiignored file named by hand is still blocked below (hidden ≠
391
+ // aiignored), so naming the file cannot be used as a bypass.
392
+ files.push(path.join(target.searchRoot, target.file));
393
+ }
394
+ else {
395
+ await collectFiles(target.searchRoot, files, fileSet === 'gitignore');
396
+ }
397
+ const matches = [];
398
+ for (const file of files) {
399
+ if (matches.length >= limit)
400
+ break;
401
+ if (includeRe && !includeRe.test(path.basename(file)))
402
+ continue;
403
+ // `.aiignore` privacy boundary (GS2-51): skip BEFORE reading, so an aiignored file's contents
404
+ // are never even loaded — covers both the walk and an explicitly-named single-file target.
405
+ if (!isAllowed(file))
406
+ continue;
407
+ let content;
408
+ try {
409
+ content = await fs.readFile(file, 'utf8');
410
+ }
411
+ catch {
412
+ continue; // unreadable / non-text; skip
413
+ }
414
+ const rel = normalizeRelPath(path.relative(target.searchRoot, file));
415
+ const lines = content.split('\n');
416
+ for (let i = 0; i < lines.length; i++) {
417
+ if (matches.length >= limit)
418
+ break;
419
+ const line = lines[i];
420
+ // Bound the regex input per line (see MAX_SCAN_LINE_LENGTH): a huge/minified line must not
421
+ // block the event loop. We test a truncated view but store the original line (its preview is
422
+ // bounded again at format time); a match beyond the cap on such a line is not reported.
423
+ const scanText = line.length > MAX_SCAN_LINE_LENGTH ? line.slice(0, MAX_SCAN_LINE_LENGTH) : line;
424
+ if (regex.test(scanText)) {
425
+ matches.push({ path: rel, line: i + 1, text: line });
426
+ }
427
+ }
428
+ }
429
+ return matches;
430
+ }
431
+ async function grepImpl(args, workDir, fileSet, aiignore) {
432
+ const limit = args.limit ?? DEFAULT_LIMIT;
433
+ let target;
434
+ try {
435
+ target = await resolveTarget(args.path, workDir);
436
+ }
437
+ catch (e) {
438
+ if (e instanceof GrepError)
439
+ return e.message;
440
+ throw e;
441
+ }
442
+ // The `.aiignore` privacy filter is resolved against the work-dir root (matching the fs toolkit)
443
+ // and enforced on whichever engine runs — see makeAiignoreFilter.
444
+ const isAllowed = makeAiignoreFilter(workDir, aiignore);
445
+ let matches;
446
+ try {
447
+ matches = await runRipgrep(args.pattern, target, args.include, fileSet, isAllowed);
448
+ }
449
+ catch (e) {
450
+ if (e instanceof RipgrepUnavailableError) {
451
+ try {
452
+ matches = await runJsScanner(args.pattern, target, args.include, limit, fileSet, isAllowed);
453
+ }
454
+ catch (inner) {
455
+ if (inner instanceof GrepError)
456
+ return inner.message;
457
+ throw inner;
458
+ }
459
+ }
460
+ else if (e instanceof GrepError) {
461
+ return e.message;
462
+ }
463
+ else {
464
+ throw e;
465
+ }
466
+ }
467
+ // ripgrep has no total-match cap of its own; bound the count here so both paths agree.
468
+ if (matches.length > limit)
469
+ matches = matches.slice(0, limit);
470
+ return formatGrepOutput(matches);
471
+ }
472
+ export function get(config) {
473
+ // Resolve the corpus selection once at tool-construction time from the same config that decided
474
+ // this tool is enabled (GS2-51); the searched file-set is a config choice, not a per-call arg.
475
+ const fileSet = resolveGrepFileSet(config);
476
+ // The `.aiignore` privacy boundary (GS2-51) is read from the SAME config the fs toolkit reads it
477
+ // from, so gth_grep enforces it identically — see makeAiignoreFilter.
478
+ const aiignore = config?.aiignore;
479
+ const impl = async (args) => grepImpl(args, getCurrentWorkDir(), fileSet, aiignore);
480
+ return tool(impl, { name: GREP_TOOL_NAME, description, schema });
481
+ }
482
+ //# sourceMappingURL=gthGrepTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gthGrepTool.js","sourceRoot":"","sources":["../../src/tools/gthGrepTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAa,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAE5E,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AASzC;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAiB;IAClD,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,cAAc,CAAC,CAAC;IAC1E,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAChF,OAAO,WAAW,CAAC;AACrB,CAAC;AAKD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,kBAAkB,CAAC,OAAe,EAAE,QAA+B;I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CAAC;IACzD,OAAO,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module tools/shell/allowlist
3
+ *
4
+ * Re-export of the EXT-9 Tier-2 allow-list engine. The implementation lives in
5
+ * `@gaunt-sloth/core` (`core/shell/allowlist`) because the core {@link GthAgentRunner}
6
+ * owns the per-instance session store and the loaded persisted store and consults
7
+ * `matchesApproval` before prompting (core cannot import from `@gaunt-sloth/agent`).
8
+ *
9
+ * See the core module for the exact safe-bin / anti-widening matching rule.
10
+ */
11
+ export { matchesApproval, hasWideningFlag, AllowlistStore, PersistedAllowlist, type ApprovalScope, type ApprovalStores, } from '@gaunt-sloth/core/core/shell/allowlist.js';