Class FileFunctionTools

java.lang.Object
org.machanism.machai.gw.tools.FileFunctionTools
All Implemented Interfaces:
FunctionTools

public class FileFunctionTools extends Object implements FunctionTools
Installs file-system tools into a Genai.

Tools in this installer are intended for host-integrated use where the host controls the base working directory. All path provided to these tools are interpreted relative to the working directory supplied by the provider/runtime.

Installed tools

  • read_file – reads a file as text
  • write_file – writes a file (creating parent directories as needed)
  • list_files_in_directory – lists immediate children of a directory
  • get_recursive_file_list – recursively lists all files under a directory
Author:
Viktor Tovstyi
  • Constructor Details

    • FileFunctionTools

      public FileFunctionTools()
  • Method Details

    • getRecursiveFiles

      public Object getRecursiveFiles(String path, File projectDir)
      Implements get_recursive_file_list.

      Expected parameters:

      1. JsonNode optionally containing dir_path
      2. File working directory
    • getRecursiveFolders

      public Object getRecursiveFolders(String path, File projectDir)
      Implements get_recursive_folder_list.

      Expected parameters:

      1. JsonNode optionally containing dir_path
      2. File working directory
    • listFiles

      public List<String> listFiles(String dirPath, File projectDir)
      Implements list_files_in_directory.

      Expected parameters:

      1. JsonNode optionally containing dir_path
      2. File working directory
    • writeFile

      public Object writeFile(String filePath, String text, String charsetName, File projectDir)
      Implements write_file.
    • readFile

      public Object readFile(String filePath, String charsetName, File projectDir) throws IOException
      Implements read_file.

      Expected parameters:

      1. JsonNode containing file_path
      2. File working directory
      Throws:
      IOException
      FileNotFoundException
    • getRelativePath

      public static String getRelativePath(File dir, File file, boolean addSingleDot)
      Computes a project-relative path string.

      The returned path always uses forward slashes (/) for consistency across platforms.

      Parameters:
      dir - base directory used to relativize the file
      file - target file or directory
      addSingleDot - whether to prefix relative path with ./
      Returns:
      relative path, . if dir equals file, or null if file is not a descendant of dir
    • applyPatchToFile

      public Object applyPatchToFile(String filePath, String patch, String charsetName, File projectDir)