Class GuidanceProcessor
java.lang.Object
org.machanism.machai.project.ProjectProcessor
org.machanism.machai.gw.processor.AbstractFileProcessor
org.machanism.machai.gw.processor.AIFileProcessor
org.machanism.machai.gw.processor.GuidanceProcessor
Scans a project tree, extracts per-file
@guidance directives through
Reviewers, and dispatches the resulting prompts to a configured
Genai.
The processor supports single-module and multi-module project layouts. For multi-module builds, modules are processed child-first (each module is scanned before the parent project directory). Processing is traversal-based; it does not attempt to build projects or resolve dependencies.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringTag name for guidance comments.(package private) final ResourceBundleResource bundle supplying prompt templates for generators.Fields inherited from class org.machanism.machai.gw.processor.AIFileProcessor
GW_TEMP_DIR, NOT_DEFINED_VALUEFields 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
ConstructorsConstructorDescriptionGuidanceProcessor(File projectDir, String genai, Configurator configurator) Constructs a processor. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandeleteTempFiles(File basedir) Deletes the input-log temporary directory.(package private) ReviewergetReviewerForExtension(String extension) Resolves a reviewer for a given file extension.(package private) voidLoads file reviewers via theServiceLoaderregistry, mapping supported file extensions to a reviewer.protected booleanApplies matching logic and default-guidance behavior.(package private) static StringnormalizeExtensionKey(String extension) Normalizes a file extension (with or without a leading dot) into a lower-case lookup key.(package private) StringUses aReviewer(based on file extension) to extract guidance.protected Stringprocess(ProjectLayout projectLayout, File file, String guidance) Composes the final prompt and dispatches it to the configured provider.protected voidprocessFile(ProjectLayout projectLayout, File file) Extracts guidance for a file and, when present, performs provider processing.protected voidprocessModule(File projectDir, String module) Processes a module directory.protected voidprocessParentFiles(ProjectLayout projectLayout) Processes files and folders under the parent project directory (excluding modules).Methods inherited from class org.machanism.machai.gw.processor.AIFileProcessor
getDefaultPrompt, getDirInfoLine, getInstructions, getModel, getProjectStructureDescription, getProvider, input, isInteractive, isLogInputs, parseLines, parseScanDir, process, processFolder, readFromFilePath, readFromHttpUrl, scanDocuments, setDefaultPrompt, setInstructions, setInteractive, setLogInputs, setModel, setProvider, tryToGetInstructionsFromReferenceMethods inherited from class org.machanism.machai.gw.processor.AbstractFileProcessor
addMatchingFile, findFiles, findFiles, getConfigurator, getExcludes, getModuleThreadTimeoutMinutes, getPathMatcher, getPatternPath, getProjectDir, getScanDir, isModuleDir, isNonRecursive, isPathPattern, matchPath, pathDepth, processModulesMultiThreaded, processProjectDir, scanDocuments, scanFolder, setDegreeOfConcurrency, setExcludes, setModuleThreadTimeoutMinutes, setNonRecursive, setPathMatcher, setScanDir, shouldExcludePath, shouldIncludeInFindFiles, shutdownExecutorMethods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout
-
Field Details
-
GUIDANCE_TAG_NAME
Tag name for guidance comments.- See Also:
-
promptBundle
Resource bundle supplying prompt templates for generators.
-
-
Constructor Details
-
GuidanceProcessor
Constructs a processor.- Parameters:
projectDir- root directory used as a base for relative pathsgenai- provider key/name to useconfigurator- configuration source
-
-
Method Details
-
loadReviewers
void loadReviewers()Loads file reviewers via theServiceLoaderregistry, mapping supported file extensions to a reviewer. -
normalizeExtensionKey
Normalizes a file extension (with or without a leading dot) into a lower-case lookup key.- Parameters:
extension- the extension to normalize (e.g.,"java"or".java")- Returns:
- normalized key, or
nullif the input is blank
-
match
Applies matching logic and default-guidance behavior.- Overrides:
matchin classAbstractFileProcessor- Parameters:
file- candidate file/directoryprojectDir- current project directory- Returns:
truewhen the candidate should be processed
-
processModule
Processes a module directory.When a scan directory or pattern is configured, modules are only processed when the module itself matches or contains the scan directory.
- Overrides:
processModulein classProjectProcessor- Parameters:
projectDir- parent project directorymodule- module relative path- Throws:
IOException- if scanning the module fails
-
processParentFiles
Processes files and folders under the parent project directory (excluding modules).- Overrides:
processParentFilesin classAbstractFileProcessor- Parameters:
projectLayout- project layout- Throws:
IOException- if file reading fails
-
processFile
Extracts guidance for a file and, when present, performs provider processing.- Overrides:
processFilein classAbstractFileProcessor- Parameters:
projectLayout- project layoutfile- file to process- Throws:
IOException- if reading the file or provider execution fails
-
process
protected String process(ProjectLayout projectLayout, File file, String guidance) throws IOException Composes the final prompt and dispatches it to the configured provider.- Parameters:
projectLayout- project layoutfile- file currently being processedguidance- extracted guidance and/or default guidance- Returns:
- provider output
- Throws:
IOException- if provider execution fails
-
parseFile
Uses aReviewer(based on file extension) to extract guidance.- Parameters:
projectDir- project root directoryfile- file being parsed- Returns:
- guidance text, or
nullif the file type is not supported - Throws:
IOException- if the file cannot be read
-
getReviewerForExtension
Resolves a reviewer for a given file extension.- Parameters:
extension- file extension (with or without a dot)- Returns:
- reviewer, or
nullif none is registered for that extension
-
deleteTempFiles
Deletes the input-log temporary directory.- Parameters:
basedir- project base directory- Returns:
trueif the directory was deleted, otherwisefalse
-