Class ActProcessor
An act is a predefined prompt template stored as a .toml
file. Act files can be loaded from bundled classpath resources (under
/acts) and/or from a user-specified directory.
Act format
Act files are parsed as TOML and support a small set of keys:
instructions: provider system instructionsinputs: a prompt template;String.format(String, Object...)is used to inject user-provided prompt textgw.threads: enables module multi-threadinggw.excludes: comma-separated scan exclusionsgw.nonRecursive: disables module recursion- any other key is forwarded to the underlying configuration
Execution
When executing an act, Ghostwriter will scan matching files and run the act's
composed prompt against each file. Acts may also declare a prologue
and/or epilogue list of related acts to run before/after the main
scan.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClasspath base directory for built-in act definitions.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
ConstructorsConstructorDescriptionActProcessor(File projectDir, Configurator configurator, String genai) Creates an act processor. -
Method Summary
Modifier and TypeMethodDescription(package private) voidapplyActData(Map<String, Object> properties) Applies loaded act data to this processor's configuration and runtime settings.static voidLoads an act definition into the provided map, supporting inheritance via thebasedOnproperty.protected voidprocessFile(ProjectLayout projectLayout, File file) Executes the act against a single file.protected voidprocessParentFiles(ProjectLayout projectLayout) Processes non-module files and directories directly under the project directory.(package private) static voidsetActData(Map<String, Object> properties, org.tomlj.TomlParseResult toml) Copies dotted-string keys from the TOML parse result intoproperties.voidsetActsLocation(String actsLocation) Sets the directory used for loading external act definition files.voidsetDefaultPrompt(String act) Loads an act definition and applies it as the current execution defaults.static org.tomlj.TomlParseResulttryLoadActFromClasspath(Map<String, Object> properties, String name) Attempts to load an act definition from classpath resources.static org.tomlj.TomlParseResultAttempts to load an act definition from a user-defined directory.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, 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, match, matchPath, pathDepth, processModulesMultiThreaded, processProjectDir, scanDocuments, scanFolder, setDegreeOfConcurrency, setExcludes, setModuleThreadTimeoutMinutes, setNonRecursive, setPathMatcher, setScanDir, shouldExcludePath, shouldIncludeInFindFiles, shutdownExecutorMethods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout, processModule
-
Field Details
-
ACTS_BASENAME_PREFIX
Classpath base directory for built-in act definitions.- See Also:
-
-
Constructor Details
-
ActProcessor
Creates an act processor.- Parameters:
projectDir- root directory used as a base for relative pathsconfigurator- configuration sourcegenai- provider key/name (including model)
-
-
Method Details
-
setDefaultPrompt
Loads an act definition and applies it as the current execution defaults.The
actargument supports the form<name> [prompt], where the optional prompt portion is inserted into the act'sinputstemplate. If no prompt is provided,AIFileProcessor.getDefaultPrompt()is used.- Overrides:
setDefaultPromptin classAIFileProcessor- Parameters:
act- act name plus optional prompt text
-
loadAct
public static void loadAct(String name, Map<String, Object> properties, String actsLocation) throws IOExceptionLoads an act definition into the provided map, supporting inheritance via thebasedOnproperty.This method attempts to load the specified act from both a user-defined directory (custom act) and the built-in classpath resources. If both are present, the custom act wraps (overrides) the built-in act, allowing for extension or modification of base act behavior.
If the act specifies a
basedOnproperty, the parent act is loaded first (recursively), and its properties are merged. The child act's properties then override or extend the parent.- Parameters:
name- the name of the act to load (without the.tomlextension)properties- destination map to populate with parsed act propertiesactsLocation- optional directory containing user-defined (custom) act files; may benull- Throws:
IOException- if reading act content failsIllegalArgumentException- if the specified act cannot be found in either location
-
tryLoadActFromClasspath
public static org.tomlj.TomlParseResult tryLoadActFromClasspath(Map<String, Object> properties, String name) throws IOExceptionAttempts to load an act definition from classpath resources.- Parameters:
properties- destination for parsed dotted propertiesname- act name (without.toml)- Returns:
- parsed TOML result, or
nullwhen the act is not found - Throws:
IOException- if the resource cannot be read
-
tryLoadActFromDirectory
public static org.tomlj.TomlParseResult tryLoadActFromDirectory(Map<String, Object> properties, String name, String actsLocation) throws IOExceptionAttempts to load an act definition from a user-defined directory.- Parameters:
properties- destination for parsed dotted propertiesname- act name (without.toml)actsLocation- directory containing*.tomlact files (may benull)- Returns:
- parsed TOML result, or
nullwhen not found - Throws:
IOException- if the file cannot be read
-
setActData
Copies dotted-string keys from the TOML parse result intoproperties.If a key already exists in
properties, the new value is formatted into the old value usingString.format(String, Object...).- Parameters:
properties- properties destinationtoml- TOML parse result
-
applyActData
Applies loaded act data to this processor's configuration and runtime settings.- Parameters:
properties- properties loaded from TOML acts
-
setActsLocation
Sets the directory used for loading external act definition files.- Parameters:
actsLocation- directory containing*.tomlact files
-
processParentFiles
Processes non-module files and directories directly under the project directory.- Overrides:
processParentFilesin classAbstractFileProcessor- Parameters:
projectLayout- project layout- Throws:
IOException- if file reading fails
-
processFile
Executes the act against a single file.- Overrides:
processFilein classAbstractFileProcessor- Parameters:
projectLayout- project layoutfile- file to process- Throws:
IOException- if provider execution fails
-