Class FileIoTools

java.lang.Object
com.tnsai.tools.file.FileIoTools

public class FileIoTools extends Object
Function-shape filesystem read/write tools. Sandbox containment, size caps, and extension whitelist are delegated to FileGuard; the byte-level I/O code below is the only thing this class owns directly.

Two ctors:

  • FileIoTools() — uses FileGuardConfig.defaults() and DEFAULT_EXTENSIONS. Required by the BuiltInTool catalog which auto-instantiates POJOs via no-arg constructor.
  • FileIoTools(FileGuardConfig) — explicit per-tenant config; use via agentBuilder.toolPojos(new FileIoTools(tenantConfig)).

fileWrite(java.lang.String, java.lang.String) truncates and overwrites by default. Atomic move + temp-file would be safer for crash tolerance but is out of scope; consumers needing it should supply a custom tool.

  • Field Details

    • DEFAULT_EXTENSIONS

      public static final Set<String> DEFAULT_EXTENSIONS
      Default extension whitelist for general filesystem read/write.
  • Constructor Details

    • FileIoTools

      public FileIoTools()
    • FileIoTools

      public FileIoTools(FileGuardConfig guardConfig)
  • Method Details

    • fileRead

      @Tool(name="file_read", description="Read the UTF-8 text content of a file from the local filesystem. The path must resolve under the configured sandbox root; absolute paths to system files are rejected. The file size is checked before any byte is read into the JVM heap. Returns the entire file content as a string.", keywords={"file","read","open","load"}, idempotent=true) public String fileRead(@ToolParam(description="File path \u2014 absolute or relative; must resolve under the sandbox root") String path) throws IOException
      Throws:
      IOException
    • fileWrite

      @Tool(name="file_write", description="Write UTF-8 text content to a file. Creates the file (and any missing parent directories) if absent, truncates and overwrites if it exists. Path must resolve under the configured sandbox root. Content size is capped to prevent disk-fill DoS. Returns a success message including the resolved path.", keywords={"file","write","save","output"}) public String fileWrite(@ToolParam(description="File path \u2014 absolute or relative; must resolve under the sandbox root") String path, @ToolParam(description="Content to write (UTF-8). Bound by the configured write cap.") String content) throws IOException
      Throws:
      IOException