Class GuidanceProcessor
The processor scans project files and modules selected by the configured path
matcher. For supported file types, it uses Reviewer implementations
discovered through ServiceLoader to extract mandatory guidance
instructions from source comments. If a default prompt is configured,
matching files without explicit guidance can still be processed by applying
that default prompt.
Guidance comments are identified by the special marker
GUIDANCE_TAG_NAME. Reviewers are responsible for preserving marker
comments in their original source locations while allowing the provider to
update surrounding content. Processing results are collected in
getReport() as relative file paths and provider messages.
Examples
Configurator configurator = ...;
GuidanceProcessor processor = new GuidanceProcessor(new File("."), "my-model", configurator);
processor.process(projectLayout, new File("src/main/java/App.java"), "Ensure documentation is current.");
List<Map<String, Object>> report = processor.getReport();
A supported source file may include a guidance block such as:
/*
* @guidance: Keep this class documented and ensure examples compile.
*/
public class App {
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSpecial comment marker used to identify guidance blocks inside supported files.private static final org.slf4j.LoggerLogger for documentation input processing events.(package private) final ResourceBundleResource bundle supplying prompt templates for generators.Reviewer associations keyed by file extension.Fields inherited from class org.machanism.machai.gw.processor.AIFileProcessor
CONTINUE_SPECIAL_PROMPT_COMMAND, ENABLED_TOOLS_PARAM_NAME, EXIT_SPECIAL_PROMPT_COMMAND, FILE_INCLUDED_MARKER, LOG_OUTPUT_PREFIX, PUBLIC_PROP_GROUP_NAMEFields inherited from class org.machanism.machai.project.ProjectProcessor
MACHAI_TEMP_DIR -
Constructor Summary
ConstructorsConstructorDescriptionGuidanceProcessor(File rootDir, String genai, Configurator configurator) Constructs a newGuidanceProcessorfor processing files with guidance tags. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current base instructions used for processing.(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.process(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
addTool, applyTools, getDefaultPrompt, getDirInfoLine, getModel, getProcessInfo, input, isInteractive, parseLines, parsePath, process, processFolder, readFromFilePath, readFromHttpUrl, removeFrontMatterData, scanDocuments, setDefaultPrompt, setInstructions, setInteractive, setModel, tryToGetFromReferenceMethods inherited from class org.machanism.machai.gw.processor.AbstractFileProcessor
addMatchingFile, getConfigurator, getExcludes, getModuleThreadTimeoutMinutes, getPath, getPathMatcher, getPatternPath, getRootDir, isModuleDir, isNonRecursive, isPathPattern, listFiles, listFiles, pathDepth, processModulesMultiThreaded, processProjectDir, scanFolder, setExcludes, setModuleThreadTimeoutMinutes, setNonRecursive, setPath, setPathMatcher, setThreads, shouldExcludePath, shouldIncludeInListFiles, shutdownExecutorMethods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout
-
Field Details
-
logger
private static final org.slf4j.Logger loggerLogger for documentation input processing events. -
GUIDANCE_TAG_NAME
Special comment marker used to identify guidance blocks inside supported files.A guidance block begins with this marker and contains mandatory processing instructions for the AI provider. For example, Java reviewers can extract comments that start with
/*@guidance:and pass their contents to this processor. The marker itself must remain unchanged in processed files so future runs can discover the same guidance.- See Also:
-
promptBundle
Resource bundle supplying prompt templates for generators. -
reviewerMap
Reviewer associations keyed by file extension. -
report
-
-
Constructor Details
-
GuidanceProcessor
Constructs a newGuidanceProcessorfor processing files with guidance tags.Initializes the processor with the specified root directory, GenAI model identifier, and configuration. Logs the root directory and GenAI model (if provided), and loads reviewer information for guidance processing.
- Parameters:
rootDir- the root directory to scan for filesgenai- the GenAI model identifier to use for processing (may benull)configurator- the configuration object for property resolution and runtime settings
-
-
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
Composes the final prompt and dispatches it to the configured provider.- Overrides:
processin classAIFileProcessor- Parameters:
projectLayout- project layoutfile- file currently being processedguidance- extracted guidance and/or default guidance- Returns:
- provider output
-
getInstructions
Returns the current base instructions used for processing.- Overrides:
getInstructionsin classAIFileProcessor- Returns:
- the configured instruction text
-
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
-
getReport
- Returns:
- the report
-