Class AiRuntimeBuilder
The builder is stateless and may be shared across commands. It returns
null from buildEngine(org.egothor.methodatlas.ai.AiOptions) when AI is disabled — the
orchestration layer relies on this sentinel rather than building a no-op
engine, because most commands change behaviour entirely when AI is off
(no extra columns, no confidence threshold, no taxonomy in metadata).
Failure handling
Engine construction can fail when an external provider cannot be reached
or the configured model is unknown. Such failures are wrapped in an
IllegalStateException, because they indicate a misconfigured run
rather than a recoverable I/O fault: the user must change configuration
before retrying.
Cache loading reads an arbitrary CSV produced by a previous run; a
malformed file is reported as IllegalArgumentException so that
the offending path appears in the user-facing CLI error.
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildCache(Path cacheFile) Loads the AI result cache from a previous MethodAtlas CSV output, or returns the empty no-op cache when no cache file was configured.org.egothor.methodatlas.ai.AiSuggestionEnginebuildEngine(org.egothor.methodatlas.ai.AiOptions aiOptions) Creates the AI suggestion engine for the current run, or returnsnullwhen AI support is disabled.resolveTaxonomyInfo(org.egothor.methodatlas.ai.AiOptions aiOptions, boolean aiActive) Produces a human-readable string identifying which taxonomy configuration is in effect, for inclusion in scan-metadata output.
-
Constructor Details
-
AiRuntimeBuilder
public AiRuntimeBuilder()Creates a new builder. Stateless; safe to share across commands.
-
-
Method Details
-
buildEngine
public org.egothor.methodatlas.ai.AiSuggestionEngine buildEngine(org.egothor.methodatlas.ai.AiOptions aiOptions) Creates the AI suggestion engine for the current run, or returnsnullwhen AI support is disabled.The orchestration layer treats
nullas a sentinel meaning "skip every AI step": no per-class submission, no taxonomy resolution, no confidence filtering. Returning a no-op engine would force every call site to check a different way; returningnullkeeps the decision in one place.- Parameters:
aiOptions- AI configuration for the current run; must not benull- Returns:
- initialised AI engine, or
nullwhenaiOptionsreports AI as disabled - Throws:
IllegalStateException- if engine initialisation fails — typically an unknown provider or unreachable endpoint
-
buildCache
Loads the AI result cache from a previous MethodAtlas CSV output, or returns the empty no-op cache when no cache file was configured.The empty no-op cache is a sentinel: every
lookupreturns absent andisActive()returnsfalse, which lets the scan loop short-circuit cache work entirely without per-call null checks.- Parameters:
cacheFile- path to a previous run's CSV output (must include thecontent_hashcolumn), ornullto disable caching- Returns:
- loaded cache, or the empty no-op cache; never
null - Throws:
IllegalArgumentException- if the cache file exists but cannot be read or parsed
-
resolveTaxonomyInfo
Produces a human-readable string identifying which taxonomy configuration is in effect, for inclusion in scan-metadata output.Output forms:
"n/a (AI disabled)"when no AI engine is active for the run"file:<absolute path>"whenaiOptionsnames an external taxonomy file"built-in/<mode>"(for examplebuilt-in/defaultorbuilt-in/optimized) when no external file was supplied
The string is intended for human eyes — auditors checking which taxonomy a particular scan run used. It is emitted by
-emit-metadatainto the CSV preamble and into SARIF run properties.- Parameters:
aiOptions- AI configuration for the current run; must not benullaiActive- whether an AI engine is active for this run- Returns:
- taxonomy descriptor string; never
null
-