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 StringThe command string used in interactive mode to skip additional prompts and continue execution.static final StringThe command string used in interactive mode to terminate and exit the processing session immediately.static final StringThe special string marker used to indicate that an instruction line refers to an external file or resource that should be fetched and embedded.static final StringThe temporary folder name used within the project environment for writing input and prompt logs.static final StringThe format pattern used to prepend logger output blocks when reporting responses generated by the AI provider.static final StringFallback constant used as a placeholder string indicating a property value is undefined.static final StringThe property group prefix used to filter which placeholders are resolved during the substitutor expansion phase.Fields 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 rootDir, 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.Returns the current base instructions used for processing.getModel()Returns the configured AI model or provider identifier.getProcessInfo(ProjectLayout projectLayout, File file) 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.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.voidscanDocuments(File projectDir, String path) 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.voidsetProjectLayoutContext(ProjectLayout projectLayout) Sets the project layout context for the specifiedProjectLayoutby collecting key project metadata and directory information into a JSON object and storing it in theProjectContextFunctionToolscontext map.Methods inherited from class org.machanism.machai.gw.processor.AbstractFileProcessor
getConfigurator, getExcludes, getModuleThreadTimeoutMinutes, getPath, getPathMatcher, getRootDir, isModuleDir, isNonRecursive, match, processFile, processParentFiles, processProjectDir, scanFolder, setDegreeOfConcurrency, setExcludes, setModuleThreadTimeoutMinutes, setNonRecursive, setPath, setPathMatcher, shouldExcludePathMethods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout, processModule
-
Field Details
-
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
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
The format pattern used to prepend logger output blocks when reporting responses generated by the AI provider.- See Also:
-
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
The command string used in interactive mode to skip additional prompts and continue execution.- See Also:
-
NOT_DEFINED_VALUE
Fallback constant used as a placeholder string indicating a property value is undefined.- See Also:
-
GW_TEMP_DIR
The temporary folder name used within the project environment for writing input and prompt logs.- See Also:
-
-
Constructor Details
-
AIFileProcessor
Creates a processor for the given project directory and AI provider identifier.- Parameters:
rootDir- 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) -
getProcessInfo
-
input
-
setProjectLayoutContext
Sets the project layout context for the specifiedProjectLayoutby collecting key project metadata and directory information into a JSON object and storing it in theProjectContextFunctionToolscontext 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- theProjectLayoutinstance for which to set the context- Throws:
IllegalArgumentException- if JSON processing fails
-
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
-
scanDocuments
Configures scanning based on the provided directory or path pattern and then starts scanning the project folder.- Parameters:
projectDir- the project root directorypath- the directory or path matcher expression to scan- Throws:
IOException- if scanning fails
-
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
-