diff options
| author | Taylor Mullen <[email protected]> | 2025-04-18 14:34:34 -0400 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-04-18 14:41:36 -0400 |
| commit | abb60a4d1031fb32f6d40e2bbe2b2aca7b1433ee (patch) | |
| tree | 1f76fbf913a6eeaef21b12bfb63feb719746d939 /packages/cli/src/tools/ls.tool.ts | |
| parent | 328846c6e31a3957ecb625c2a93fa9a1dce9580c (diff) | |
Finish manually fixing linter errors for tools dir (partial).
- More changes are to come, this is truly a partial change in order to not disrupt as many people as possible.
Part of https://b.corp.google.com/issues/411384603
Diffstat (limited to 'packages/cli/src/tools/ls.tool.ts')
| -rw-r--r-- | packages/cli/src/tools/ls.tool.ts | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/packages/cli/src/tools/ls.tool.ts b/packages/cli/src/tools/ls.tool.ts index 82f4e913..d2f6a3c7 100644 --- a/packages/cli/src/tools/ls.tool.ts +++ b/packages/cli/src/tools/ls.tool.ts @@ -50,29 +50,9 @@ export interface FileEntry { } /** - * Result from the LS tool - */ -export interface LSToolResult extends ToolResult { - /** - * List of file entries - */ - entries: FileEntry[]; - - /** - * The directory that was listed - */ - listedPath: string; - - /** - * Total number of entries found - */ - totalEntries: number; -} - -/** * Implementation of the LS tool that lists directory contents */ -export class LSTool extends BaseTool<LSToolParams, LSToolResult> { +export class LSTool extends BaseTool<LSToolParams, ToolResult> { /** * The root directory that this tool is grounded in. * All path operations will be restricted to this directory. @@ -184,12 +164,9 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> { return shortenPath(relativePath); } - private errorResult(params: LSToolParams, llmContent: string, returnDisplay: string): LSToolResult { + private errorResult(llmContent: string, returnDisplay: string): ToolResult { return { - entries: [], - listedPath: params.path, - totalEntries: 0, - llmContent: llmContent, + llmContent, returnDisplay: `**Error:** ${returnDisplay}`, }; } @@ -199,11 +176,10 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> { * @param params Parameters for the LS operation * @returns Result of the LS operation */ - async execute(params: LSToolParams): Promise<LSToolResult> { + async execute(params: LSToolParams): Promise<ToolResult> { const validationError = this.validateToolParams(params); if (validationError) { return this.errorResult( - params, `Error: Invalid parameters provided. Reason: ${validationError}`, `Failed to execute tool.`); } @@ -212,13 +188,11 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> { const stats = fs.statSync(params.path); if (!stats) { return this.errorResult( - params, `Directory does not exist: ${params.path}`, `Directory does not exist.`); } if (!stats.isDirectory()) { return this.errorResult( - params, `Path is not a directory: ${params.path}`, `Path is not a directory.`); } @@ -227,7 +201,6 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> { const entries: FileEntry[] = []; if (files.length === 0) { return this.errorResult( - params, `Directory is empty: ${params.path}`, `Directory is empty.`); } @@ -270,15 +243,11 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> { .join('\n'); return { - entries, - listedPath: params.path, - totalEntries: entries.length, llmContent: `Directory listing for ${params.path}:\n${directoryContent}`, returnDisplay: `Found ${entries.length} item(s).`, }; } catch (error) { return this.errorResult( - params, `Error listing directory: ${error instanceof Error ? error.message : String(error)}`, 'Failed to list directory.'); } |
