Package org.machanism.machai.gw.tools
The package contains concrete FunctionTools
implementations used by the Ghostwriter runtime to expose file access,
command execution, HTTP integration, Act orchestration, guidance processing,
and project-context management through
Tool-annotated methods. It also defines
helper utilities for bounded logging and patch application plus lightweight
exception types that communicate control-flow decisions such as task
completion, process termination, episode repetition, and episode navigation.
Methods annotated with Tool are exposed
as callable functional AI tools, while methods annotated with
Prompt provide prompt templates for
workflow-specific requests. Resource-oriented integrations, when supplied by
the host, are used to retrieve project or web content under the same
project-bound and security-controlled execution model.
Package overview
- Act orchestration:
ActFunctionToolsloads Act metadata, executes Acts synchronously or asynchronously, and retrieves persisted Act results.ActSpecFunctionToolsprovides Act-specific control tools for jumping to another episode or requesting a repeat. - Command execution and logging:
CommandFunctionToolsruns validated operating-system commands, captures bounded output, persists logs, pages log content, and searches logs with regular expressions. Validation is delegated toCommandSecurityChecker, whileLogBuildermanages retained output and log-file reports.CommandSpecFunctionToolsexposes task and process termination controls for processors. - File-system operations:
FileFunctionToolsreads, writes, lists, and patches project files, andPatchApplierapplies unified or simplified diff patches. Recursive file and directory discovery is delegated to the project-layout utilities. File operations are intended to remain within the project directory supplied by the host. TheFileFunctionTools.getRelativePath(java.io.File, java.io.File, boolean)helper normalizes paths for tool responses. - Guidance workflows:
GuidanceFunctionToolsdiscovers files containing guidance tags, processes them with Ghostwriter guidance engines, and retrieves asynchronous processing results. - Project state and runtime control:
ProjectContextFunctionToolsstores and retrieves project-scoped context variables, whileCommandSpecFunctionToolsexposes tools for ending a task or terminating execution. TheActSpecFunctionToolsusesMoveToEpisodeExceptionandRepeatEpisodeExceptionfor episode navigation and repetition. Other specialized exceptions such asEndTaskException,ProcessTerminationException,DenyExceptionallow the host to distinguish intentional control flow from ordinary failures. - Reusable support types:
LogBuilderbounds retained output and persists command logs, whilePatchApplierapplies validated text patches.CommandSecurityCheckerand the control-flow exception classes are deliberately small integration points that can be reused by host processors without invoking a tool facade. - Web integration:
WebFunctionToolsfetches HTML or text content and executes REST requests with configurable headers, timeouts, character sets, optional selector extraction, and Basic authentication via URL user-info or explicit request headers.
Control-flow and security contracts
DenyException reports a command rejected
by the configured deny-list. The specialized exceptions
EndTaskException,
ProcessTerminationException,
MoveToEpisodeException, and
RepeatEpisodeException are intentional
signals for the embedding processor; they are not ordinary application
failures and should be handled according to the host's workflow policy.
Usage model
Most tools accept a project directory supplied by the host runtime and treat
paths relative to that directory. Several tools also accept a
Configurator so command
strings, URLs, HTTP headers, Act properties, and related values can be
resolved through runtime substitution before execution.
Example
Tool classes are typically discovered reflectively, but they can also be used directly by an integration host or test harness:
File projectDir = new File("C:/workspace/sample-project");
Configurator configurator = ...;
FileFunctionTools files = new FileFunctionTools();
String readme = files.readFile(new File("README.md"), "UTF-8", projectDir);
CommandFunctionTools commands = new CommandFunctionTools();
Object report = commands.executeCommand("mvn -q test", null, ".", 2048, "UTF-8", projectDir, configurator);
ProjectContextFunctionTools.put(projectDir, "lastCommandReport", report);
Tool methods return structured maps or lists when callers need status and metadata, and return strings for text-oriented operations. Methods that represent deliberate workflow transitions use the specialized exception types documented below; an embedding processor should not convert those signals into ordinary error messages.
Design notes
Implementations in this package favor project-bound path resolution, bounded output retention, explicit character-set handling, structured result payloads, and host-controlled security constraints. Because several tools can touch the file system, start subprocesses, or call external services, callers are expected to configure appropriate allow/deny policies in the embedding environment.
- See Also:
-
ClassDescriptionProvides function tools for managing and executing Ghostwriter Acts within a project.Provides functional tools for episode navigation and control within the ActProcessor context.Provides function tools for executing and managing system commands within a project context.Functional interface used for handling stream read failures.Auto-closeable wrapper for
ExecutorServiceso it can be used with try-with-resources.Functional interface used for streaming output line processing.Loads and evaluates command deny-list rules used by host-side command execution tools.Provides function tools for task and execution control within theAIFileProcessorcontext.Exception thrown when a command fails a deny-list security check.Exception used to signal the end of a task without terminating the application.Installs file-system tools into aGenai.Provides function tools for discovering and processing files with guidance tags in project directories.AStringBuilder-like helper that retains only the lastmaxSizecharacters.Exception used to request a jump to another act episode during execution.Utility to apply unified diff patches to text files.Runtime exception used byterminate_processto signal early termination to the host.Provides function tools for managing project-specific context variables.Exception used to request that the current act episode be executed again.Provides host-side HTTP retrieval tools for aGenaiprovider.