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

    • PUBLIC_PROP_GROUP_NAME

      public static final String PUBLIC_PROP_GROUP_NAME
      The property group prefix used to filter which placeholders are resolved during the substitutor expansion phase.
      See Also:
    • FILE_INCLUDED_MARKER

      public static final String FILE_INCLUDED_MARKER
      The special string marker used to indicate that an instruction line refers to an external file or resource that should be fetched and embedded.
      See Also:
    • LOG_OUTPUT_PREFIX

      public static final String LOG_OUTPUT_PREFIX
      The format pattern used to prepend logger output blocks when reporting responses generated by the AI provider.
      See Also:
    • EXIT_SPECIAL_PROMPT_COMMAND

      public static final String EXIT_SPECIAL_PROMPT_COMMAND
      The command string used in interactive mode to terminate and exit the processing session immediately.
      See Also:
    • CONTINUE_SPECIAL_PROMPT_COMMAND

      public static final String CONTINUE_SPECIAL_PROMPT_COMMAND
      The command string used in interactive mode to skip additional prompts and continue execution.
      See Also:
    • NOT_DEFINED_VALUE

      public static final String NOT_DEFINED_VALUE
      Fallback constant used as a placeholder string indicating a property value is undefined.
      See Also:
    • GW_TEMP_DIR

      public static final String GW_TEMP_DIR
      The temporary folder name used within the project environment for writing input and prompt logs.
      See Also:
  • Constructor Details

    • AIFileProcessor

      public AIFileProcessor(File rootDir, Configurator configurator, String genai)
      Creates a processor for the given project directory and AI provider identifier.
      Parameters:
      rootDir - 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)
    • getProcessInfo

      public String getProcessInfo(ProjectLayout projectLayout, File file)
    • input

      protected String input()
    • setProjectLayoutContext

      public void setProjectLayoutContext(ProjectLayout projectLayout)
      Sets the project layout context for the specified ProjectLayout by collecting key project metadata and directory information into a JSON object and storing it in the ProjectContextFunctionTools context map.

      The context includes details such as operating system, project and parent names/IDs, relative paths, layout type, and lists of source, test, documentation, and module directories. The resulting JSON string is stored under the key "PROJECT_LAYOUT_CONTEXT" for the given project directory.

      Parameters:
      projectLayout - the ProjectLayout instance for which to set the context
      Throws:
      IllegalArgumentException - if JSON processing fails
    • 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
    • scanDocuments

      public void scanDocuments(File projectDir, String path) 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
      path - the directory or path matcher expression to scan
      Throws:
      IOException - if scanning fails
    • 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