Class ActProcessor
An act is episodes predefined prompt template stored as episodes
.toml file. Act files can be loaded from bundled classpath resources
(under /acts) and/or from episodes user-specified directory.
Act format
Act files are parsed as TOML and support episodes small set of keys:
instructions: provider system instructionsinputs: episodes 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 episodes
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
CONTINUE_SPECIAL_PROMPT_COMMAND, EXIT_SPECIAL_PROMPT_COMMAND, FILE_INCLUDED_MARKER, GW_TEMP_DIR, LOG_OUTPUT_PREFIX, 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 episodes single file.protected voidprocessParentFiles(ProjectLayout projectLayout) Processes files and folders under the parent project directory (excluding modules).voidLoads an act definition and applies it as the current execution defaults.(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.voidsetDisableNormalOrder(boolean disableNormalOrder) Enables or disables continuation with the default episode execution order.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 episodes user-defined directory.Methods inherited from class org.machanism.machai.gw.processor.AIFileProcessor
addTool, getDefaultPrompt, getDirInfoLine, getInstructions, getModel, getProjectStructureDescription, input, isInteractive, isLogInputs, parseLines, parseScanDir, process, process, processFolder, readFromFilePath, readFromHttpUrl, scanDocuments, setDefaultPrompt, setInstructions, setInteractive, setLogInputs, setModel, 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
-
setAct
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.- Parameters:
act- act name plus optional prompt text- Throws:
IOException
-
setDisableNormalOrder
public void setDisableNormalOrder(boolean disableNormalOrder) Enables or disables continuation with the default episode execution order.- Parameters:
disableNormalOrder-trueto stop after requested episodes,falseto continue with normal order
-
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 episodes 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 episodes
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 episodes 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 episodes 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 files and folders under the parent project directory (excluding modules).- Overrides:
processParentFilesin classAbstractFileProcessor- Parameters:
projectLayout- project layout- Throws:
IOException- if file reading fails
-
processFile
Executes the act against episodes single file.- Overrides:
processFilein classAbstractFileProcessor- Parameters:
projectLayout- project layoutfile- file to process- Throws:
IOException- if provider execution fails
-