@agi-cli/sdk 0.1.49 → 0.1.50

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 (49) hide show
  1. package/package.json +6 -5
  2. package/src/agent/types.ts +1 -1
  3. package/src/index.ts +10 -77
  4. package/src/errors.ts +0 -102
  5. package/src/providers/resolver.ts +0 -84
  6. package/src/streaming/artifacts.ts +0 -41
  7. package/src/tools/builtin/bash.ts +0 -73
  8. package/src/tools/builtin/bash.txt +0 -7
  9. package/src/tools/builtin/edit.ts +0 -145
  10. package/src/tools/builtin/edit.txt +0 -7
  11. package/src/tools/builtin/file-cache.ts +0 -39
  12. package/src/tools/builtin/finish.ts +0 -11
  13. package/src/tools/builtin/finish.txt +0 -5
  14. package/src/tools/builtin/fs/cd.ts +0 -19
  15. package/src/tools/builtin/fs/cd.txt +0 -5
  16. package/src/tools/builtin/fs/index.ts +0 -20
  17. package/src/tools/builtin/fs/ls.ts +0 -57
  18. package/src/tools/builtin/fs/ls.txt +0 -8
  19. package/src/tools/builtin/fs/pwd.ts +0 -17
  20. package/src/tools/builtin/fs/pwd.txt +0 -5
  21. package/src/tools/builtin/fs/read.ts +0 -49
  22. package/src/tools/builtin/fs/read.txt +0 -8
  23. package/src/tools/builtin/fs/tree.ts +0 -67
  24. package/src/tools/builtin/fs/tree.txt +0 -8
  25. package/src/tools/builtin/fs/util.ts +0 -95
  26. package/src/tools/builtin/fs/write.ts +0 -61
  27. package/src/tools/builtin/fs/write.txt +0 -8
  28. package/src/tools/builtin/git.commit.txt +0 -6
  29. package/src/tools/builtin/git.diff.txt +0 -5
  30. package/src/tools/builtin/git.status.txt +0 -5
  31. package/src/tools/builtin/git.ts +0 -112
  32. package/src/tools/builtin/glob.ts +0 -82
  33. package/src/tools/builtin/glob.txt +0 -8
  34. package/src/tools/builtin/grep.ts +0 -138
  35. package/src/tools/builtin/grep.txt +0 -9
  36. package/src/tools/builtin/ignore.ts +0 -45
  37. package/src/tools/builtin/patch.ts +0 -273
  38. package/src/tools/builtin/patch.txt +0 -7
  39. package/src/tools/builtin/plan.ts +0 -58
  40. package/src/tools/builtin/plan.txt +0 -6
  41. package/src/tools/builtin/progress.ts +0 -55
  42. package/src/tools/builtin/progress.txt +0 -7
  43. package/src/tools/builtin/ripgrep.ts +0 -71
  44. package/src/tools/builtin/ripgrep.txt +0 -7
  45. package/src/tools/builtin/websearch.ts +0 -219
  46. package/src/tools/builtin/websearch.txt +0 -12
  47. package/src/tools/loader.ts +0 -390
  48. package/src/types/index.ts +0 -11
  49. package/src/types/types.ts +0 -4
@@ -1,219 +0,0 @@
1
- import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
3
- import DESCRIPTION from './websearch.txt' with { type: 'text' };
4
-
5
- export function buildWebSearchTool(): {
6
- name: string;
7
- tool: Tool;
8
- } {
9
- const websearch = tool({
10
- description: DESCRIPTION,
11
- inputSchema: z
12
- .object({
13
- url: z
14
- .string()
15
- .optional()
16
- .describe(
17
- 'URL to fetch content from (mutually exclusive with query)',
18
- ),
19
- query: z
20
- .string()
21
- .optional()
22
- .describe(
23
- 'Search query to search the web (mutually exclusive with url)',
24
- ),
25
- maxLength: z
26
- .number()
27
- .optional()
28
- .default(50000)
29
- .describe(
30
- 'Maximum content length to return (default: 50000 characters)',
31
- ),
32
- })
33
- .strict()
34
- .refine((data) => (data.url ? !data.query : !!data.query), {
35
- message: 'Must provide either url or query, but not both',
36
- }),
37
- async execute({
38
- url,
39
- query,
40
- maxLength,
41
- }: {
42
- url?: string;
43
- query?: string;
44
- maxLength?: number;
45
- }) {
46
- const maxLen = maxLength ?? 50000;
47
-
48
- if (url) {
49
- // Fetch URL content
50
- try {
51
- const response = await fetch(url, {
52
- headers: {
53
- 'User-Agent':
54
- 'Mozilla/5.0 (compatible; AGI-Bot/1.0; +https://github.com/anthropics/agi)',
55
- Accept:
56
- 'text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.7',
57
- },
58
- redirect: 'follow',
59
- signal: AbortSignal.timeout(30000), // 30 second timeout
60
- });
61
-
62
- if (!response.ok) {
63
- throw new Error(
64
- `HTTP error! status: ${response.status} ${response.statusText}`,
65
- );
66
- }
67
-
68
- const contentType = response.headers.get('content-type') || '';
69
- let content = '';
70
-
71
- if (
72
- contentType.includes('text/') ||
73
- contentType.includes('application/json') ||
74
- contentType.includes('application/xml') ||
75
- contentType.includes('application/xhtml')
76
- ) {
77
- content = await response.text();
78
- } else {
79
- return {
80
- error: `Unsupported content type: ${contentType}. Only text-based content can be fetched.`,
81
- };
82
- }
83
-
84
- // Strip HTML tags for better readability (basic cleaning)
85
- const cleanContent = content
86
- .replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
87
- .replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
88
- .replace(/<[^>]+>/g, ' ')
89
- .replace(/\s+/g, ' ')
90
- .trim();
91
-
92
- const truncated = cleanContent.slice(0, maxLen);
93
- const wasTruncated = cleanContent.length > maxLen;
94
-
95
- return {
96
- url,
97
- content: truncated,
98
- contentLength: cleanContent.length,
99
- truncated: wasTruncated,
100
- contentType,
101
- };
102
- } catch (error) {
103
- const errorMessage =
104
- error instanceof Error ? error.message : String(error);
105
- return {
106
- error: `Failed to fetch URL: ${errorMessage}`,
107
- };
108
- }
109
- }
110
-
111
- if (query) {
112
- // Web search functionality
113
- // Use DuckDuckGo's HTML search (doesn't require API key)
114
- try {
115
- const searchUrl = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
116
- const response = await fetch(searchUrl, {
117
- headers: {
118
- 'User-Agent':
119
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
120
- Accept: 'text/html',
121
- },
122
- redirect: 'follow',
123
- signal: AbortSignal.timeout(30000),
124
- });
125
-
126
- if (!response.ok) {
127
- throw new Error(`Search failed: ${response.status}`);
128
- }
129
-
130
- const html = await response.text();
131
-
132
- // Parse DuckDuckGo results (basic parsing)
133
- const results: Array<{
134
- title: string;
135
- url: string;
136
- snippet: string;
137
- }> = [];
138
-
139
- // Match result blocks
140
- const resultPattern =
141
- /<a[^>]+class="result__a"[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>[\s\S]*?<a[^>]+class="result__snippet"[^>]*>([\s\S]*?)<\/a>/gi;
142
-
143
- let match: RegExpExecArray | null = null;
144
- match = resultPattern.exec(html);
145
- while (match !== null && results.length < 10) {
146
- const url = match[1]?.trim();
147
- const title = match[2]?.trim();
148
- let snippet = match[3]?.trim();
149
-
150
- if (url && title) {
151
- // Clean snippet
152
- snippet = snippet
153
- ?.replace(/<[^>]+>/g, '')
154
- .replace(/\s+/g, ' ')
155
- .trim();
156
-
157
- results.push({
158
- title,
159
- url,
160
- snippet: snippet || '',
161
- });
162
- }
163
- match = resultPattern.exec(html);
164
- }
165
-
166
- // Fallback: simpler pattern if the above doesn't work
167
- if (results.length === 0) {
168
- const simplePattern =
169
- /<a[^>]+rel="nofollow"[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>/gi;
170
- match = simplePattern.exec(html);
171
- while (match !== null && results.length < 10) {
172
- const url = match[1]?.trim();
173
- const title = match[2]?.trim();
174
- if (url && title && url.startsWith('http')) {
175
- results.push({
176
- title,
177
- url,
178
- snippet: '',
179
- });
180
- }
181
- match = simplePattern.exec(html);
182
- }
183
- }
184
-
185
- if (results.length === 0) {
186
- return {
187
- error:
188
- 'No search results found. The search service may have changed its format or blocked the request.',
189
- query,
190
- suggestion:
191
- 'Try using the url parameter to fetch a specific webpage instead.',
192
- };
193
- }
194
-
195
- return {
196
- query,
197
- results,
198
- count: results.length,
199
- };
200
- } catch (error) {
201
- const errorMessage =
202
- error instanceof Error ? error.message : String(error);
203
- return {
204
- error: `Search failed: ${errorMessage}`,
205
- query,
206
- suggestion:
207
- 'Search services may be temporarily unavailable. Try using the url parameter to fetch a specific webpage instead.',
208
- };
209
- }
210
- }
211
-
212
- return {
213
- error: 'Must provide either url or query parameter',
214
- };
215
- },
216
- });
217
-
218
- return { name: 'websearch', tool: websearch };
219
- }
@@ -1,12 +0,0 @@
1
- - Search the web or fetch content from URLs
2
- - Use `query` to search the web and get a list of results with titles, URLs, and snippets
3
- - Use `url` to fetch and read the content of a specific webpage
4
- - Returns cleaned, text-based content (HTML tags are stripped)
5
- - Cannot be used for both search and URL fetch in the same call
6
-
7
- Usage tips:
8
- - For research: use `query` to find relevant pages, then `url` to read specific ones
9
- - Search returns up to 10 results with titles, URLs, and snippets
10
- - URL fetching works for text-based content (HTML, JSON, XML, plain text)
11
- - Content is automatically truncated if it exceeds maxLength (default 50,000 chars)
12
- - Use this to gather current information, read documentation, or verify facts
@@ -1,390 +0,0 @@
1
- import { tool, type Tool } from 'ai';
2
- import { z } from 'zod';
3
- import { finishTool } from './builtin/finish.ts';
4
- import { buildFsTools } from './builtin/fs/index.ts';
5
- import { buildGitTools } from './builtin/git.ts';
6
- import { progressUpdateTool } from './builtin/progress.ts';
7
- import { buildBashTool } from './builtin/bash.ts';
8
- import { buildRipgrepTool } from './builtin/ripgrep.ts';
9
- import { buildGrepTool } from './builtin/grep.ts';
10
- import { buildGlobTool } from './builtin/glob.ts';
11
- import { buildApplyPatchTool } from './builtin/patch.ts';
12
- import { updatePlanTool } from './builtin/plan.ts';
13
- import { editTool } from './builtin/edit.ts';
14
- import { buildWebSearchTool } from './builtin/websearch.ts';
15
- import { Glob } from 'bun';
16
- import { dirname, isAbsolute, join } from 'node:path';
17
- import { pathToFileURL } from 'node:url';
18
- import { promises as fs } from 'node:fs';
19
-
20
- export type DiscoveredTool = { name: string; tool: Tool };
21
-
22
- type PluginParameter = {
23
- type: 'string' | 'number' | 'boolean';
24
- description?: string;
25
- default?: string | number | boolean;
26
- enum?: string[];
27
- optional?: boolean;
28
- };
29
-
30
- type PluginDescriptor = {
31
- name?: string;
32
- description?: string;
33
- parameters?: Record<string, PluginParameter>;
34
- execute?: PluginExecutor;
35
- run?: PluginExecutor;
36
- handler?: PluginExecutor;
37
- setup?: (context: PluginContext) => unknown | Promise<unknown>;
38
- onInit?: (context: PluginContext) => unknown | Promise<unknown>;
39
- };
40
-
41
- type PluginExecutor = (args: PluginExecuteArgs) => unknown | Promise<unknown>;
42
-
43
- type PluginExecuteArgs = {
44
- input: Record<string, unknown>;
45
- project: string;
46
- projectRoot: string;
47
- directory: string;
48
- worktree: string;
49
- exec: ExecFn;
50
- run: ExecFn;
51
- $: TemplateExecFn;
52
- fs: FsHelpers;
53
- env: Record<string, string>;
54
- context: PluginContext;
55
- };
56
-
57
- type PluginContext = {
58
- project: string;
59
- projectRoot: string;
60
- directory: string;
61
- worktree: string;
62
- toolDir: string;
63
- };
64
-
65
- type ExecFn = (
66
- command: string,
67
- args?: string[] | ExecOptions,
68
- options?: ExecOptions,
69
- ) => Promise<ExecResult>;
70
-
71
- type TemplateExecFn = (
72
- strings: TemplateStringsArray,
73
- ...values: unknown[]
74
- ) => Promise<ExecResult>;
75
-
76
- type ExecOptions = {
77
- cwd?: string;
78
- env?: Record<string, string>;
79
- allowNonZeroExit?: boolean;
80
- };
81
-
82
- type ExecResult = { exitCode: number; stdout: string; stderr: string };
83
-
84
- type FsHelpers = {
85
- readFile: (path: string, encoding?: BufferEncoding) => Promise<string>;
86
- writeFile: (path: string, content: string) => Promise<void>;
87
- exists: (path: string) => Promise<boolean>;
88
- };
89
-
90
- const pluginPatterns = ['tools/*/tool.js', 'tools/*/tool.mjs'];
91
-
92
- export async function discoverProjectTools(
93
- projectRoot: string,
94
- globalConfigDir?: string,
95
- ): Promise<DiscoveredTool[]> {
96
- const tools = new Map<string, Tool>();
97
- for (const { name, tool } of buildFsTools(projectRoot)) tools.set(name, tool);
98
- for (const { name, tool } of buildGitTools(projectRoot))
99
- tools.set(name, tool);
100
- // Built-ins
101
- tools.set('finish', finishTool);
102
- tools.set('progress_update', progressUpdateTool);
103
- const bash = buildBashTool(projectRoot);
104
- tools.set(bash.name, bash.tool);
105
- // Search
106
- const rg = buildRipgrepTool(projectRoot);
107
- tools.set(rg.name, rg.tool);
108
- const grep = buildGrepTool(projectRoot);
109
- tools.set(grep.name, grep.tool);
110
- const glob = buildGlobTool(projectRoot);
111
- tools.set(glob.name, glob.tool);
112
- // Patch/apply
113
- const ap = buildApplyPatchTool(projectRoot);
114
- tools.set(ap.name, ap.tool);
115
- // Plan update
116
- tools.set('update_plan', updatePlanTool);
117
- // Edit
118
- tools.set('edit', editTool);
119
- // Web search
120
- const ws = buildWebSearchTool();
121
- tools.set(ws.name, ws.tool);
122
-
123
- async function loadFromBase(base: string | null | undefined) {
124
- if (!base) return;
125
- try {
126
- await fs.readdir(base);
127
- } catch {
128
- return;
129
- }
130
- for (const pattern of pluginPatterns) {
131
- const glob = new Glob(pattern);
132
- for await (const rel of glob.scan(base)) {
133
- const match = rel.match(/^tools\/([^/]+)\/tool\.(m?js)$/);
134
- if (!match || !match[1]) continue;
135
- const folder = match[1];
136
- const absPath = join(base, rel).replace(/\\/g, '/');
137
- try {
138
- const plugin = await loadPlugin(absPath, folder, projectRoot);
139
- if (plugin) tools.set(plugin.name, plugin.tool);
140
- } catch (err) {
141
- if (process.env.AGI_DEBUG_TOOLS === '1')
142
- console.error('Failed to load tool', absPath, err);
143
- }
144
- }
145
- }
146
- // Fallback: manual directory scan
147
- try {
148
- const toolsDir = join(base, 'tools');
149
- const entries = await fs.readdir(toolsDir).catch(() => [] as string[]);
150
- for (const folder of entries) {
151
- const js = join(toolsDir, folder, 'tool.js');
152
- const mjs = join(toolsDir, folder, 'tool.mjs');
153
- const candidate = await fs
154
- .stat(js)
155
- .then(() => js)
156
- .catch(
157
- async () =>
158
- await fs
159
- .stat(mjs)
160
- .then(() => mjs)
161
- .catch(() => null),
162
- );
163
- if (!candidate) continue;
164
- try {
165
- const plugin = await loadPlugin(
166
- candidate.replace(/\\/g, '/'),
167
- folder,
168
- projectRoot,
169
- );
170
- if (plugin) tools.set(plugin.name, plugin.tool);
171
- } catch {}
172
- }
173
- } catch {}
174
- }
175
-
176
- await loadFromBase(globalConfigDir);
177
- await loadFromBase(join(projectRoot, '.agi'));
178
- return Array.from(tools.entries()).map(([name, tool]) => ({ name, tool }));
179
- }
180
-
181
- async function loadPlugin(
182
- absPath: string,
183
- folder: string,
184
- projectRoot: string,
185
- ): Promise<DiscoveredTool | null> {
186
- const mod = await import(`${pathToFileURL(absPath).href}?t=${Date.now()}`);
187
- const candidate = resolveExport(mod);
188
- if (!candidate) throw new Error('No plugin export found');
189
-
190
- const context: PluginContext = {
191
- project: projectRoot,
192
- projectRoot,
193
- directory: projectRoot,
194
- worktree: projectRoot,
195
- toolDir: absPath.slice(0, absPath.lastIndexOf('/')),
196
- };
197
-
198
- let descriptor: PluginDescriptor | null | undefined;
199
- if (typeof candidate === 'function') descriptor = await candidate(context);
200
- else descriptor = candidate;
201
- if (!descriptor || typeof descriptor !== 'object')
202
- throw new Error('Plugin must return an object descriptor');
203
-
204
- if (typeof descriptor.setup === 'function') await descriptor.setup(context);
205
- if (typeof descriptor.onInit === 'function') await descriptor.onInit(context);
206
-
207
- const name = sanitizeName(descriptor.name ?? folder);
208
- const description = descriptor.description ?? `Custom tool ${name}`;
209
- const parameters = descriptor.parameters ?? {};
210
- const inputSchema = createInputSchema(parameters);
211
- const executor = resolveExecutor(descriptor);
212
-
213
- const helpersFactory = createHelpers(projectRoot, context.toolDir);
214
-
215
- const wrapped = tool({
216
- description,
217
- inputSchema,
218
- async execute(input) {
219
- const helpers = helpersFactory();
220
- const result = await executor({
221
- input: input as Record<string, unknown>,
222
- project: helpers.context.project,
223
- projectRoot: helpers.context.projectRoot,
224
- directory: helpers.context.directory,
225
- worktree: helpers.context.worktree,
226
- exec: helpers.exec,
227
- run: helpers.exec,
228
- $: helpers.templateExec,
229
- fs: helpers.fs,
230
- env: helpers.env,
231
- context: helpers.context,
232
- });
233
- return result ?? { ok: true };
234
- },
235
- });
236
-
237
- return { name, tool: wrapped };
238
- }
239
-
240
- function resolveExport(mod: Record<string, unknown>) {
241
- if (mod.default) return mod.default;
242
- if (mod.tool) return mod.tool;
243
- if (mod.plugin) return mod.plugin;
244
- if (mod.Tool) return mod.Tool;
245
- const values = Object.values(mod);
246
- return values.find(
247
- (value) => typeof value === 'function' || typeof value === 'object',
248
- );
249
- }
250
-
251
- function resolveExecutor(descriptor: PluginDescriptor): PluginExecutor {
252
- const fn = descriptor.execute ?? descriptor.run ?? descriptor.handler;
253
- if (typeof fn !== 'function')
254
- throw new Error('Plugin must provide an execute/run/handler function');
255
- return fn;
256
- }
257
-
258
- function sanitizeName(name: string) {
259
- const cleaned = name.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 128);
260
- return cleaned || 'tool';
261
- }
262
-
263
- function createInputSchema(parameters: Record<string, PluginParameter>) {
264
- const shape: Record<string, z.ZodTypeAny> = {};
265
- for (const [key, def] of Object.entries(parameters)) {
266
- let schema: z.ZodTypeAny;
267
- if (def.type === 'string') {
268
- const values = def.enum;
269
- schema = values?.length
270
- ? z.enum(values as [string, ...string[]])
271
- : z.string();
272
- } else if (def.type === 'number') schema = z.number();
273
- else schema = z.boolean();
274
- if (def.description) schema = schema.describe(def.description);
275
- if (def.default !== undefined)
276
- schema = schema.default(def.default as never);
277
- else if (def.optional) schema = schema.optional();
278
- shape[key] = schema;
279
- }
280
- return Object.keys(shape).length ? z.object(shape).strict() : z.object({});
281
- }
282
-
283
- function createHelpers(projectRoot: string, toolDir: string) {
284
- return () => {
285
- const exec = createExec(projectRoot);
286
- const fsHelpers = createFsHelpers(projectRoot);
287
- const context: PluginContext = {
288
- project: projectRoot,
289
- projectRoot,
290
- directory: projectRoot,
291
- worktree: projectRoot,
292
- toolDir,
293
- };
294
- const env: Record<string, string> = {};
295
- for (const [key, value] of Object.entries(process.env))
296
- if (typeof value === 'string') env[key] = value;
297
- const templateExec: TemplateExecFn = (strings, ...values) => {
298
- const commandLine = strings.reduce((acc, part, index) => {
299
- const value = index < values.length ? String(values[index]) : '';
300
- return acc + part + value;
301
- }, '');
302
- const pieces = commandLine.trim().split(/\s+/).filter(Boolean);
303
- if (pieces.length === 0)
304
- throw new Error('Empty command passed to template executor');
305
- const firstPiece = pieces[0];
306
- if (!firstPiece)
307
- throw new Error('Empty command passed to template executor');
308
- return exec(firstPiece, pieces.slice(1));
309
- };
310
- return {
311
- exec,
312
- fs: fsHelpers,
313
- env,
314
- templateExec,
315
- context,
316
- };
317
- };
318
- }
319
-
320
- function createExec(projectRoot: string): ExecFn {
321
- return async (
322
- command: string,
323
- argsOrOptions?: string[] | ExecOptions,
324
- maybeOptions?: ExecOptions,
325
- ) => {
326
- let args: string[] = [];
327
- let options: ExecOptions = {};
328
- if (Array.isArray(argsOrOptions)) {
329
- args = argsOrOptions;
330
- options = maybeOptions ?? {};
331
- } else if (argsOrOptions) options = argsOrOptions;
332
-
333
- const cwd = options.cwd
334
- ? resolveWithinProject(projectRoot, options.cwd)
335
- : projectRoot;
336
- const env: Record<string, string> = {};
337
- for (const [key, value] of Object.entries(process.env))
338
- if (typeof value === 'string') env[key] = value;
339
- if (options.env)
340
- for (const [key, value] of Object.entries(options.env)) env[key] = value;
341
-
342
- const proc = Bun.spawn([command, ...args], {
343
- cwd,
344
- env,
345
- stdout: 'pipe',
346
- stderr: 'pipe',
347
- });
348
- const exitCode = await proc.exited;
349
- const stdout = await new Response(proc.stdout).text();
350
- const stderr = await new Response(proc.stderr).text();
351
- if (exitCode !== 0 && !options.allowNonZeroExit) {
352
- const message = stderr.trim() || stdout.trim() || `${command} failed`;
353
- throw new Error(`${command} exited with code ${exitCode}: ${message}`);
354
- }
355
- return { exitCode, stdout, stderr };
356
- };
357
- }
358
-
359
- function createFsHelpers(projectRoot: string): FsHelpers {
360
- return {
361
- async readFile(path: string, encoding: BufferEncoding = 'utf-8') {
362
- const abs = resolveWithinProject(projectRoot, path);
363
- return fs.readFile(abs, { encoding });
364
- },
365
- async writeFile(path: string, content: string) {
366
- const abs = resolveWithinProject(projectRoot, path);
367
- await fs.mkdir(dirname(abs), { recursive: true });
368
- await fs.writeFile(abs, content, 'utf-8');
369
- },
370
- async exists(path: string) {
371
- const abs = resolveWithinProject(projectRoot, path);
372
- try {
373
- await fs.access(abs);
374
- return true;
375
- } catch {
376
- return false;
377
- }
378
- },
379
- };
380
- }
381
-
382
- function resolveWithinProject(projectRoot: string, target: string) {
383
- if (!target) return projectRoot;
384
- if (target.startsWith('~/')) {
385
- const home = process.env.HOME || process.env.USERPROFILE || '';
386
- return join(home, target.slice(2));
387
- }
388
- if (isAbsolute(target)) return target;
389
- return join(projectRoot, target);
390
- }
@@ -1,11 +0,0 @@
1
- export type ExecutionContext = {
2
- projectRoot: string;
3
- workingDir?: string;
4
- env?: Record<string, string>;
5
- };
6
-
7
- export type ToolResult = {
8
- success: boolean;
9
- output?: string;
10
- error?: string;
11
- };
@@ -1,4 +0,0 @@
1
- export interface ToolContext {
2
- projectRoot: string;
3
- // Consider adding db, logger etc. when integrated
4
- }