Class AIFileProcessor
java.lang.Object
org.machanism.machai.project.ProjectProcessor
org.machanism.machai.gw.processor.AbstractFileProcessor
org.machanism.machai.gw.processor.AIFileProcessor
- Direct Known Subclasses:
ActProcessor,GuidanceProcessor
File processor implementation that prepares project context and prompts for a
configured AI provider and optionally supports interactive execution.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.machanism.machai.gw.processor.AbstractFileProcessor
GW_PROJECT_LAYOUT_PROP_PREFIXFields inherited from class org.machanism.machai.project.ProjectProcessor
MACHAI_TEMP_DIR -
Constructor Summary
ConstructorsConstructorDescriptionAIFileProcessor(File projectDir, Configurator configurator, String genai) Creates a processor for the given project directory and AI provider identifier. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTool(FunctionTools toolFunction) Adds a tool definition that will be exposed to the AI provider.Returns the default prompt used for folder processing.(package private) StringgetDirInfoLine(Collection<String> sources, File projectDir) Returns a formatted line describing existing directories from the supplied collection.Returns the current base instructions used for processing.getModel()Returns the configured AI model or provider identifier.getProjectStructureDescription(ProjectLayout projectLayout, File file) Builds the formatted project structure description that is supplied to the AI provider as contextual information.protected Stringinput()booleanIndicates whether interactive processing mode is enabled.booleanIndicates whether provider input logging is enabled.parseLines(String data) Normalizes multi-line input and resolves supported line references such as HTTP URLs andfile:references.(package private) StringparseScanDir(File projectDir, String scanDir) Resolves the effective scan directory and converts it into a glob expression when required.process(ProjectLayout projectLayout, File file, String prompt) Processes the given file using the currently configured instructions.protected Stringprocess(ProjectLayout projectLayout, File file, String instructions, String... prompts) voidprocessFolder(ProjectLayout projectLayout) Processes the project root folder using the configured default prompt.(package private) StringreadFromFilePath(String filePath) Reads UTF-8 text content from the given file path.(package private) static StringreadFromHttpUrl(String urlString) Reads UTF-8 text content from the given HTTP or HTTPS URL.voidscanDocuments(File projectDir, String scanDir) Configures scanning based on the provided directory or path pattern and then starts scanning the project folder.voidsetDefaultPrompt(String defaultPrompt) Sets the default prompt used for folder processing.voidsetInstructions(String instructions) Sets the base instructions used for processing after normalizing line content and resolving supported references.voidsetInteractive(boolean interactive) Enables or disables interactive processing mode.voidsetLogInputs(boolean logInputs) Enables or disables logging of provider inputs.voidSets the AI model or provider identifier.(package private) StringResolves a single instruction line that may point to external content.Methods inherited from class org.machanism.machai.gw.processor.AbstractFileProcessor
addMatchingFile, findFiles, findFiles, getConfigurator, getExcludes, getModuleThreadTimeoutMinutes, getPathMatcher, getPatternPath, getProjectDir, getScanDir, isModuleDir, isNonRecursive, isPathPattern, match, matchPath, pathDepth, processFile, processModulesMultiThreaded, processParentFiles, processProjectDir, scanDocuments, scanFolder, setDegreeOfConcurrency, setExcludes, setModuleThreadTimeoutMinutes, setNonRecursive, setPathMatcher, setScanDir, shouldExcludePath, shouldIncludeInFindFiles, shutdownExecutorMethods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout, processModule
-
Field Details
-
FILE_INCLUDED_MARKER
- See Also:
-
LOG_OUTPUT_PREFIX
- See Also:
-
EXIT_SPECIAL_PROMPT_COMMAND
- See Also:
-
CONTINUE_SPECIAL_PROMPT_COMMAND
- See Also:
-
NOT_DEFINED_VALUE
- See Also:
-
GW_TEMP_DIR
- See Also:
-
-
Constructor Details
-
AIFileProcessor
Creates a processor for the given project directory and AI provider identifier.- Parameters:
projectDir- the project root directoryconfigurator- the application configurationgenai- the AI provider or model identifier
-
-
Method Details
-
process
Processes the given file using the currently configured instructions.- Parameters:
projectLayout- the current project layout metadatafile- the file to processprompt- the prompt to send to the AI provider- Returns:
- the provider response, or
nullwhen no response is produced
-
process
protected String process(ProjectLayout projectLayout, File file, String instructions, String... prompts) -
input
-
getProjectStructureDescription
Builds the formatted project structure description that is supplied to the AI provider as contextual information.- Parameters:
projectLayout- the current project layout metadatafile- the file currently being processed- Returns:
- the formatted project structure description
-
getDirInfoLine
Returns a formatted line describing existing directories from the supplied collection.- Parameters:
sources- the directory paths to inspectprojectDir- 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:
truewhen input logging is enabled; otherwisefalse
-
setLogInputs
public void setLogInputs(boolean logInputs) Enables or disables logging of provider inputs.- Parameters:
logInputs-trueto enable input logging; otherwisefalse
-
setInstructions
Sets the base instructions used for processing after normalizing line content and resolving supported references.- Parameters:
instructions- the raw instruction text
-
getInstructions
Returns the current base instructions used for processing.- Returns:
- the configured instruction text
-
parseLines
Normalizes multi-line input and resolves supported line references such as HTTP URLs andfile:references.- Parameters:
data- the input text to parse- Returns:
- the normalized text
-
tryToGetInstructionsFromReference
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
nullwhen the input isnull - Throws:
IOException- if referenced remote content cannot be read
-
readFromHttpUrl
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
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
Configures scanning based on the provided directory or path pattern and then starts scanning the project folder.- Parameters:
projectDir- the project root directoryscanDir- the directory or path matcher expression to scan- Throws:
IOException- if scanning fails
-
parseScanDir
Resolves the effective scan directory and converts it into a glob expression when required.- Parameters:
projectDir- the base project directoryscanDir- the configured scan directory- Returns:
- the resolved path matcher expression
-
getDefaultPrompt
Returns the default prompt used for folder processing.- Returns:
- the default prompt
-
setDefaultPrompt
Sets the default prompt used for folder processing.- Parameters:
defaultPrompt- the default prompt text
-
processFolder
Processes the project root folder using the configured default prompt.- Overrides:
processFolderin classAbstractFileProcessor- Parameters:
projectLayout- the current project layout metadata
-
getModel
Returns the configured AI model or provider identifier.- Returns:
- the model or provider identifier
-
setModel
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-trueto enable interactive mode; otherwisefalse
-
isInteractive
public boolean isInteractive()Indicates whether interactive processing mode is enabled.- Returns:
truewhen interactive mode is enabled; otherwisefalse
-
addTool
Adds a tool definition that will be exposed to the AI provider.- Parameters:
toolFunction- the tool definition to add
-