Class SourceCodeReader

java.lang.Object
atessera.sensei.tools.SourceCodeReader

public final class SourceCodeReader extends Object
LangChain4j tools that expose files inside a base directory.

Both tools accept only paths relative to the base directory supplied through the constructor. Absolute paths are rejected, and the resolved path must stay inside the base directory. Binary files are skipped during directory listing and return "BINARY" when read.

  • Constructor Details

    • SourceCodeReader

      public SourceCodeReader(Path baseDirectory)
      Creates a reader rooted at the given directory.
      Parameters:
      baseDirectory - base directory served by the tools
  • Method Details

    • listFiles

      public String listFiles(String subdirectory)
      Lists files in a subdirectory of the base directory.

      Hidden files, whose names start with a dot, and binary files are skipped. Returned paths are relative to the base directory.

      Parameters:
      subdirectory - subdirectory path relative to the base directory; use an empty string for the base directory itself
      Returns:
      newline separated list of relative file paths
    • readFile

      public String readFile(String relativePath)
      Reads a file by its path relative to the base directory.
      Parameters:
      relativePath - file path relative to the base directory
      Returns:
      file contents or "BINARY" if the file is a binary file