import static java.lang.String.join;
/**
- * Encapsulates the process of running an AI inference query via
- * llama.cpp. It prepares an input file, spawns the process, collects
- * output, and cleans up temporary files.
+ * <p>Executes AI inference tasks through llama.cpp CLI. This class handles the complete workflow
+ * from prompt construction to response formatting, including temporary file management and process execution.</p>
+ * <p>Key processing steps:
+ * <ol>
+ * <li>Build standardized input prompt</li>
+ * <li>Create temporary input file</li>
+ * <li>Execute llama.cpp with appropriate parameters</li>
+ * <li>Capture and filter output</li>
+ * <li>Perform cleanup operations</li>
+ * </ol>
+ * </p>
+ * <p>Temperature settings, context size, and thread counts are all derived from the current configuration.
+ * The response is formatted to match org-mode conventions while preserving original conversation structure.</p>
*/
public class AiTask {
"--file " + inputFile
);
-// Old solution that sometimes went into an infinite loop, for backup purposes:
-//
-// return join(" ",
-// "nice", "-n", Integer.toString(niceValue),
-// executablePath,
-// "--model " + mailQuery.model.filesystemPath,
-// "--threads " + configuration.getThreadCount(),
-// "--threads-batch " + configuration.getBatchThreadCount(),
-// "--mirostat 2",
-// "--flash-attn",
-// "--cache-type-k q8_0",
-// "--cache-type-v q8_0",
-// "--no-display-prompt",
-// "--no-warmup",
-// "--temp " + temperature,
-// "--ctx-size " + mailQuery.model.contextSizeTokens,
-// "--batch-size 8",
-// "--no-conversation",
-// "-n -1",
-// "--repeat_penalty 1.1",
-// "--file " + inputFile
-// );
-
}
/**
import java.io.IOException;
/**
- * A simple interface for all subcommands used by the Älyverkko CLI.
- * Implementing classes define a unique name (e.g., "wizard") and an
- * {@code execute} method for the command's logic.
+ * <p>Base interface for all subcommands in the Älyverkko CLI. Each command must define its name and execution logic.</p>
+ * <p>Commands typically:
+ * <ul>
+ * <li>Parse their own specific arguments</li>
+ * <li>Access the global configuration</li>
+ * <li>Handle I/O operations</li>
+ * </ul>
+ * </p>
+ * <p>Commands should be stateless and self-contained, using the configuration object for persistent data when needed.</p>
*/
public interface Command {
package eu.svjatoslav.alyverkko_cli;
/**
- * Utility functions for miscellaneous tasks such as colored console output.
+ * <p>General utility functions for the Älyverkko CLI application. Currently provides ANSI color output capabilities for
+ * console messages.</p>
+ * <p>Color formatting follows standard ANSI escape sequences, with specific methods for common message types like errors.</p>
+ * <p>For future extensions, this class could include additional helper functions for file operations or string processing.</p>
*/
public class Utils {
* alyverkko-cli joinfiles -s /path/to/source -p "*.java" -t "my_topic" --edit
* </pre>
*/
+
+/**
+ * <p>Aggregates files from a source directory into a single file for AI processing.
+ * This is particularly useful for creating comprehensive inputs from multiple files
+ * matching a specified pattern.</p>
+ * <p>Features include:
+ * <ul>
+ * <li>Recursive file discovery</li>
+ * <li>Glob pattern matching</li>
+ * <li>Header injection for file tracking</li>
+ * <li>Automatic file opening in editor</li>
+ * </ul>
+ * </p>
+ * <p>By default, the output file is saved in the mail directory with a .org extension.</p>
+ */
public class JoinFilesCommand implements Command {
/**
import static eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper.loadConfiguration;
/**
- * Lists all configured models in the system, loading them from the
- * user’s configuration and printing them to the console.
+ * <p>Displays all available AI models in the configured models directory. This command provides a quick overview of
+ * currently available models and their metadata.</p>
+ * <p>The implementation:
+ * <ul>
+ * <li>Loads the configuration</li>
+ * <li>Instantiates ModelLibrary</li>
+ * <li>Prints model details using ModelLibrary's printModels()</li>
+ * </ul>
+ * </p>
+ * <p>This command is primarily intended for administrative use to verify model availability before running tasks.</p>
*/
public class ListModelsCommand implements Command {
import static eu.svjatoslav.commons.cli_helper.CLIHelper.*;
/**
- * A single WizardCommand that:
- * 1. Loads existing configuration (if any).
- * 2. Performs "selftest" style validation checks interactively,
- * prompting the user to fix invalid or missing items.
- * 3. If no config file exists, it goes through all config parameters
- * from scratch.
- * 4. Offers to remove model entries that reference missing files.
- * 5. Autodiscovers new .gguf files and lets the user add them to the config.
- * 6. Saves the resulting (fixed) config file.
- * 7. Prints a final pass/fail summary for the user.
+ * <p>Interactive configuration wizard that helps users validate and fix their configuration files.
+ * It performs system checks and offers to fix any missing or invalid paths, discovers new models,
+ * and updates the configuration accordingly.</p>
+ * <p>Key workflow steps:
+ * <ol>
+ * <li>Load or create configuration</li>
+ * <li>Validate core directory paths</li>
+ * <li>Discover and annotate new models</li>
+ * <li>Save updated configuration</li>
+ * </ol>
+ * </p>
+ * <p>When handling split models (.gguf files with part numbering), the wizard automatically
+ * detects base models and only adds part-1 files to the configuration.</p>
*/
public class WizardCommand implements Command {
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
/**
- * The MailCorrespondentCommand continuously monitors a specified mail
- * directory for new or modified text files, checks if they have a
- * "TOCOMPUTE:" marker, and if so, processes them with an AI model.
- * Once processed, results are appended to the same file.
- * <p>
- * Usage:
- * <pre>
- * alyverkko-cli mail
- * </pre>
+ * <p>Monitors a designated mail directory for text files containing "TOCOMPUTE:" markers.
+ * When new or modified files are detected, it processes them with appropriate AI models
+ * and appends the results using a standardized format.</p>
+ * <p>The processing pipeline includes:
+ * <ol>
+ * <li>Initial scan of existing files</li>
+ * <li>WatchService registration for real-time monitoring</li>
+ * <li>Query construction from file metadata</li>
+ * <li>AI response formatting and appending</li>
+ * </ol>
+ * </p>
+ * <p>This implementation uses a sleep delay (1 second) after detecting file changes to allow complete writes before
+ * processing. The response format follows org-mode conventions for easy reading and further processing.</p>
*/
+
public class MailCorrespondentCommand implements Command {
/**
/**
- * This package contains mail processing commands for the Älyverkko CLI application.
- * <p>
- * The MailCorrespondentCommand monitors a mail directory for tasks and processes them
- * using AI models. MailQuery encapsulates the data needed for each mail-based query.
+ * <p>This subpackage implements the mail-based AI task processing functionality. It watches mail directories for
+ * new/modified files with specific markers and processes them using AI models.</p>
+ * <p>Key components:
+ * <ul>
+ * <li>File monitoring with WatchService</li>
+ * <li>Prompt parsing and execution logic</li>
+ * <li>Query object for storing processing parameters</li>
+ * </ul>
* </p>
*/
/**
- * This package contains all command implementations for the Älyverkko CLI application.
- * <p>
- * Each command class implements the Command interface and provides functionality for
- * specific user actions like model management, file joining, and mail processing.
+ * <p>This package implements all subcommands available in the Älyverkko CLI application. Each command class provides a
+ * specific functionality through the Command interface.</p>
+ * <p>Available commands include:
+ * <ul>
+ * <li>Wizard-style configuration builder</li>
+ * <li>Model listing and management</li>
+ * <li>File joining for multi-file processing</li>
+ * <li>Mail-based AI task processing</li>
+ * </ul>
* </p>
*/
import static eu.svjatoslav.commons.file.IOHelper.getFileContentsAsString;
/**
- * Encapsulates all user configuration for the Älyverkko CLI application,
- * such as model directories, mail directory, default temperature,
- * llama-cli path, etc.
+ * <p>Central configuration class storing all application parameters.
+ * This class is serialized to YAML format for user editing and persistence.</p>
+ * <p>Configuration parameters include:
+ * <ul>
+ * <li>Model and prompt directories</li>
+ * <li>Performance tuning parameters</li>
+ * <li>Model-specific configurations</li>
+ * </ul>
+ * </p>
+ * <p>All paths are resolved relative to the user's home directory by default, but can be customized. The class provides
+ * direct access to prompt content for AI query construction.</p>
*/
@Data
public class Configuration {
import java.io.File;
import java.io.IOException;
+/**
+ * <p>Helper class for configuration file operations. Provides methods for loading configurations
+ * and determining the default configuration file path in the user's home directory.</p>
+ * <p>Key functionality includes:
+ * <ul>
+ * <li>Configuration file path resolution</li>
+ * <li>YAML deserialization</li>
+ * <li>Error handling for missing configurations</li>
+ * </ul>
+ * </p>
+ */
public class ConfigurationHelper {
/**
/**
- * This package contains configuration-related classes for the Älyverkko CLI application.
- * <p>
- * The Configuration class holds global settings, while ConfigurationModel represents
- * individual model configurations. ConfigurationHelper provides utility methods for
- * loading and managing configuration files.
+ * <p>This package handles the configuration system for the Älyverkko CLI application.
+ * It provides classes for storing and retrieving application-wide settings, including
+ * model configurations, directory paths, and performance parameters.</p>
+ * <p>Configuration is stored in YAML format and includes:
+ * <ul>
+ * <li>Model directory paths</li>
+ * <li>Mail task directories</li>
+ * <li>Performance settings (thread counts, temperature)</li>
+ * </ul>
* </p>
*/
import java.io.File;
/**
- * Represents an AI model stored on the filesystem, including details such
- * as path, context size, alias, and an optional end-of-text marker.
+ * <p>Represents an AI model stored on the filesystem with metadata about its capabilities and identification.
+ * This class serves as a lightweight container for model information, enabling quick lookup and validation.</p>
+ * <p>Models are typically discovered through configuration files and stored in the ModelLibrary for easy access.
+ * <p>Key fields include:
+ * <ul>
+ * <li>filesystemPath - Location of the model file</li>
+ * <li>contextSizeTokens - Maximum token capacity for this model</li>
+ * <li>alias - User-friendly identifier for the model</li>
+ * <li>endOfTextMarker - Optional response completion marker</li>
+ * </ul>
+ * </p>
*/
public class Model {
this.endOfTextMarker = endOfTextMarker;
}
+
/**
- * Prints the model's alias, path, and context size to standard output.
+ * <p>Prints the model's metadata to standard output in a consistent format. This includes the model's alias,
+ * filesystem path, and context token capacity. The output format is designed to be both human-readable and
+ * machine-parsable when needed.</p>
+ * <p>Typical output:
+ * <pre>
+ * Model: default
+ * Path: /path/to/model.gguf
+ * Context size: 32768
+ * </pre>
+ * </p>
*/
public void printModelDetails() {
System.out.println("Model: " + alias);
/**
- * This package contains classes for managing AI models in the Älyverkko CLI application.
- * <p>
- * The Model class represents an AI model with metadata like path and context size.
- * The ModelLibrary class manages a collection of models, providing lookup and validation.
+ * <p>This package defines the model management system for the Älyverkko CLI.
+ * It includes classes for representing AI models and maintaining a library of available models.</p>
+ * <p>Key features:
+ * <ul>
+ * <li>Model metadata storage and validation</li>
+ * <li>Default model selection and management</li>
+ * <li>File system integration for model discovery</li>
+ * </ul>
* </p>
*/
/**
- * This package contains core components of the Älyverkko CLI application.
- * <p>
- * It includes the Main entry point, Command interface, and utility classes like Utils.
+ * <p>This package contains the core components of the Älyverkko CLI application, including the main entry point,
+ * command interfaces, and utility classes. It serves as the central hub for orchestrating subcommands and core
+ * application behavior.</p>
+ * <p>Key responsibilities include:
+ * <ul>
+ * <li>Command registration and execution</li>
+ * <li>Configuration loading and management</li>
+ * <li>Basic utility functions for colored console output</li>
+ * </ul>
+ * </p>
*/
package eu.svjatoslav.alyverkko_cli;
\ No newline at end of file