Package org.machanism.machai.gw.reviewer


package org.machanism.machai.gw.reviewer
Provides the file-format-specific review layer for the Ghostwriter guidance processing pipeline.

A Reviewer is a format adapter: it recognizes the guidance convention supported by a file type, reads the candidate file as UTF-8, computes project-relative context when required by the prompt format, and returns a localized prompt fragment. A file that does not contain guidance for the adapter is represented by null; I/O failures are propagated as IOException.

Reviewer is the package's service-provider interface. Its perform operation receives the project root and candidate file. Implementations advertise the extensions they can inspect through Reviewer.getSupportedFileExtensions(); the caller chooses an appropriate reviewer and decides how non-null prompt fragments are ordered and submitted. Extension matching alone does not replace each reviewer's format-specific guidance detection.

The concrete reviewers combine format detection with prompt construction as follows:

  • JavaReviewer handles Java comments and gives package-info.java package-level treatment by returning the package-info prompt without its complete source content. Other matching Java files contribute their complete UTF-8 source content.
  • HtmlReviewer handles HTML and XML comment blocks and includes the complete UTF-8 source in its prompt.
  • MarkdownReviewer handles guidance in Markdown HTML comments and includes the complete UTF-8 document in its prompt.
  • PythonReviewer handles guidance in Python line comments and triple-quoted strings, returning the extracted non-blank guidance text.
  • TypeScriptReviewer handles guidance in TypeScript line and block comments, returning the extracted non-blank guidance text.
  • PumlReviewer handles PlantUML files containing the guidance tag and includes the complete UTF-8 document in its prompt.
  • TextReviewer handles only files named @guidance.txt and formats their complete text with the containing directory's context.

All reviewers use the document-prompts resource bundle to create localized results; the bundle keys and argument order are format-specific. Callers should therefore treat each returned string as an opaque prompt fragment rather than depending on its presentation. The reviewers do not traverse directories, register themselves, or submit prompts.

A caller can select a reviewer by extension, invoke it with the project directory and candidate file, and forward a non-null result:

 File projectDirectory = new File(".");
 File sourceFile = new File(projectDirectory, "src/main/java/Example.java");
 Reviewer reviewer = new JavaReviewer();
 String prompt = reviewer.perform(projectDirectory, sourceFile);
 if (prompt != null) {
     promptPipeline.accept(prompt);
 }
 

In the example, promptPipeline represents an application-owned consumer; production code can select a reviewer by checking the extension returned by Reviewer.getSupportedFileExtensions() and can provide a different reviewer for each supported format. Additional Reviewer implementations can consequently be introduced without changing this package contract.

  • Class
    Description
    A Reviewer implementation for HTML and XML files with the .html, .htm, or .xml extension.
    Reviewer implementation for Java source files (.java).
    Reviewer implementation for Markdown files (.md).
    Reviewer implementation for PlantUML files (.puml).
    Reviewer implementation for Python source files (.py).
    Service-provider interface (SPI) for components that scan project files and extract @guidance instructions for downstream processing.
    Reviewer implementation for generic guidance text files.
    Reviewer implementation for TypeScript source files (.ts).