2025-04-18 17:44:24 -07:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
2025-04-19 19:45:42 +01:00
// Import core logic and types from the server package
import { LSLogic , LSToolParams , ToolResult } from '@gemini-code/server' ;
2025-04-15 21:41:08 -07:00
2025-04-19 19:45:42 +01:00
// Import CLI-specific base class and types
import { BaseTool } from './tools.js' ;
import { ToolCallConfirmationDetails } from '../ui/types.js' ;
2025-04-15 21:41:08 -07:00
/**
2025-04-19 19:45:42 +01:00
* CLI wrapper for the LS tool
2025-04-15 21:41:08 -07:00
*/
2025-04-18 14:34:34 -04:00
export class LSTool extends BaseTool < LSToolParams , ToolResult > {
2025-04-19 19:45:42 +01:00
static readonly Name : string = LSLogic . Name ; // Use name from logic
// Core logic instance from the server package
private coreLogic : LSLogic ;
2025-04-15 21:41:08 -07:00
/**
2025-04-19 19:45:42 +01:00
* Creates a new instance of the LSTool CLI wrapper
* @param rootDirectory Root directory to ground this tool in.
2025-04-15 21:41:08 -07:00
*/
constructor ( rootDirectory : string ) {
2025-04-19 19:45:42 +01:00
// Instantiate the core logic from the server package
const coreLogicInstance = new LSLogic ( rootDirectory ) ;
// Initialize the CLI BaseTool
2025-04-15 21:41:08 -07:00
super (
2025-04-19 19:45:42 +01:00
LSTool . Name ,
'ReadFolder' , // Define display name here
'Lists the names of files and subdirectories directly within a specified directory path. Can optionally ignore entries matching provided glob patterns.' , // Define description here
( coreLogicInstance . schema . parameters as Record < string , unknown > ) ? ? { } ,
2025-04-15 21:41:08 -07:00
) ;
2025-04-19 19:45:42 +01:00
this . coreLogic = coreLogicInstance ;
2025-04-15 21:41:08 -07:00
}
/**
2025-04-19 19:45:42 +01:00
* Delegates validation to the core logic
2025-04-15 21:41:08 -07:00
*/
2025-04-18 11:06:30 -07:00
validateToolParams ( params : LSToolParams ) : string | null {
2025-04-19 19:45:42 +01:00
return this . coreLogic . validateToolParams ( params ) ;
2025-04-15 21:41:08 -07:00
}
2025-04-17 12:03:02 -07:00
2025-04-15 21:41:08 -07:00
/**
2025-04-19 19:45:42 +01:00
* Delegates getting description to the core logic
2025-04-15 21:41:08 -07:00
*/
2025-04-19 19:45:42 +01:00
getDescription ( params : LSToolParams ) : string {
return this . coreLogic . getDescription ( params ) ;
2025-04-15 21:41:08 -07:00
}
2025-04-17 12:03:02 -07:00
2025-04-15 21:41:08 -07:00
/**
2025-04-19 19:45:42 +01:00
* Define confirmation behavior (LS likely doesn't need confirmation)
2025-04-15 21:41:08 -07:00
*/
2025-04-19 19:45:42 +01:00
shouldConfirmExecute (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
params : LSToolParams ,
) : Promise < ToolCallConfirmationDetails | false > {
return Promise . resolve ( false ) ;
2025-04-18 10:57:20 -07:00
}
2025-04-15 21:41:08 -07:00
/**
2025-04-19 19:45:42 +01:00
* Delegates execution to the core logic
2025-04-15 21:41:08 -07:00
*/
2025-04-18 14:34:34 -04:00
async execute ( params : LSToolParams ) : Promise < ToolResult > {
2025-04-19 19:45:42 +01:00
// The CLI wrapper could potentially modify the returnDisplay
// from the core logic if needed, but for LS, the core logic's
// display might be sufficient.
return this . coreLogic . execute ( params ) ;
2025-04-15 21:41:08 -07:00
}
2025-04-19 19:45:42 +01:00
// Removed private methods (isWithinRoot, shouldIgnore, errorResult)
// as they are now part of LSLogic in the server package.
2025-04-17 18:06:21 -04:00
}