Class AIFileProcessor

Direct Known Subclasses:
ActProcessor, GuidanceProcessor

public class AIFileProcessor extends AbstractFileProcessor
File processor implementation that prepares project context and prompts for a configured AI provider and optionally supports interactive execution.
  • Field Details

  • Constructor Details

    • AIFileProcessor

      public AIFileProcessor(File projectDir, Configurator configurator, String genai)
      Creates a processor for the given project directory and AI provider identifier.
      Parameters:
      projectDir - the project root directory
      configurator - the application configuration
      genai - the AI provider or model identifier
  • Method Details

    • process

      public String process(ProjectLayout projectLayout, File file, String prompt)
      Processes the given file using the currently configured instructions.
      Parameters:
      projectLayout - the current project layout metadata
      file - the file to process
      prompt - the prompt to send to the AI provider
      Returns:
      the provider response, or null when no response is produced
    • process

      protected String process(ProjectLayout projectLayout, File file, String instructions, String... prompts)
    • input

      protected String input()
    • getProjectStructureDescription

      public String getProjectStructureDescription(ProjectLayout projectLayout, File file)
      Builds the formatted project structure description that is supplied to the AI provider as contextual information.
      Parameters:
      projectLayout - the current project layout metadata
      file - the file currently being processed
      Returns:
      the formatted project structure description
    • getDirInfoLine

      String getDirInfoLine(Collection<String> sources, File projectDir)
      Returns a formatted line describing existing directories from the supplied collection.
      Parameters:
      sources - the directory paths to inspect
      projectDir - the project root used to resolve relative paths
      Returns:
      a formatted description line for the directories
    • isLogInputs

      public boolean isLogInputs()
      Indicates whether provider input logging is enabled.
      Returns:
      true when input logging is enabled; otherwise false
    • setLogInputs

      public void setLogInputs(boolean logInputs)
      Enables or disables logging of provider inputs.
      Parameters:
      logInputs - true to enable input logging; otherwise false
    • setInstructions

      public void setInstructions(String instructions)
      Sets the base instructions used for processing after normalizing line content and resolving supported references.
      Parameters:
      instructions - the raw instruction text
    • getInstructions

      public String getInstructions()
      Returns the current base instructions used for processing.
      Returns:
      the configured instruction text
    • parseLines

      public String parseLines(String data)
      Normalizes multi-line input and resolves supported line references such as HTTP URLs and file: references.
      Parameters:
      data - the input text to parse
      Returns:
      the normalized text
    • tryToGetInstructionsFromReference

      String tryToGetInstructionsFromReference(String data) throws IOException
      Resolves a single instruction line that may point to external content.
      Parameters:
      data - the instruction line to inspect
      Returns:
      the resolved content, or the original line when no reference is found, or null when the input is null
      Throws:
      IOException - if referenced remote content cannot be read
    • readFromHttpUrl

      static String readFromHttpUrl(String urlString) throws IOException
      Reads UTF-8 text content from the given HTTP or HTTPS URL.
      Parameters:
      urlString - the URL to read
      Returns:
      the response content as text
      Throws:
      IOException - if the URL cannot be read
    • readFromFilePath

      String readFromFilePath(String filePath)
      Reads UTF-8 text content from the given file path.
      Parameters:
      filePath - the absolute or project-relative file path
      Returns:
      the file content as text
    • scanDocuments

      public void scanDocuments(File projectDir, String scanDir) throws IOException
      Configures scanning based on the provided directory or path pattern and then starts scanning the project folder.
      Parameters:
      projectDir - the project root directory
      scanDir - the directory or path matcher expression to scan
      Throws:
      IOException - if scanning fails
    • parseScanDir

      String parseScanDir(File projectDir, String scanDir)
      Resolves the effective scan directory and converts it into a glob expression when required.
      Parameters:
      projectDir - the base project directory
      scanDir - the configured scan directory
      Returns:
      the resolved path matcher expression
    • getDefaultPrompt

      public String getDefaultPrompt()
      Returns the default prompt used for folder processing.
      Returns:
      the default prompt
    • setDefaultPrompt

      public void setDefaultPrompt(String defaultPrompt)
      Sets the default prompt used for folder processing.
      Parameters:
      defaultPrompt - the default prompt text
    • processFolder

      public void processFolder(ProjectLayout projectLayout)
      Processes the project root folder using the configured default prompt.
      Overrides:
      processFolder in class AbstractFileProcessor
      Parameters:
      projectLayout - the current project layout metadata
    • getModel

      public String getModel()
      Returns the configured AI model or provider identifier.
      Returns:
      the model or provider identifier
    • setModel

      public void setModel(String genai)
      Sets the AI model or provider identifier.
      Parameters:
      genai - the model or provider identifier
    • setInteractive

      public void setInteractive(boolean interactive)
      Enables or disables interactive processing mode.
      Parameters:
      interactive - true to enable interactive mode; otherwise false
    • isInteractive

      public boolean isInteractive()
      Indicates whether interactive processing mode is enabled.
      Returns:
      true when interactive mode is enabled; otherwise false
    • addTool

      public void addTool(FunctionTools toolFunction)
      Adds a tool definition that will be exposed to the AI provider.
      Parameters:
      toolFunction - the tool definition to add