UNPKG

gaunt-sloth-assistant

Version:

[![Tests and Lint](https://github.com/Galvanized-Pukeko/gaunt-sloth-assistant/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/Galvanized-Pukeko/gaunt-sloth-assistant/actions/workflows/unit-tests.yml) [![Integration Tests](https://github.co

299 lines (298 loc) 11 kB
import type { MiddlewareConfig } from '#src/middleware/types.js'; import { JiraConfig } from '#src/providers/types.js'; import type { BaseChatModel } from '@langchain/core/language_models/chat_models'; import type { BaseToolkit, StructuredToolInterface } from '@langchain/core/tools'; import type { Connection } from '@langchain/mcp-adapters'; /** * This is a processed Gaunt Sloth config ready to be passed down into components. * * Default values can be found in {@link DEFAULT_CONFIG} */ export interface GthConfig { llm: BaseChatModel; /** * Content Provider. Provider used to fetch content (usually diff) for `review` or `pr` command. * * {@link DEFAULT_CONFIG#contentProvider} */ contentProvider: string; requirementsProvider: string; /** * Path to project-specific guidelines. * The default is `.gsloth.guidelines.md`; this config may be used to point Gaunt Sloth to a different file, * for example, to AGENTS.md */ projectGuidelines: string; /** * Separate identity profile. * May include separate identity, guidelines and command protocol, * making gsloth behave as an agent different from default profile behaviour. * for example, `devops` profile to detect changes such as properties and environment variables. * Custom config can still win over this one. * This setting requires .gsloth/.gsloth-settings directory to exist. */ identityProfile?: string; /** * Whether to include the current date in the project review instructions or not. */ includeCurrentDateAfterGuidelines: boolean; /** * Organisation name, locale and timezone. * Only used with {@link includeCurrentDateAfterGuidelines}. * timeZone and locale should be in format supported by Intl.DateTimeFormat */ organization?: { name?: string; locale?: string; timezone?: string; }; projectReviewInstructions: string; filesystem: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; tools?: StructuredToolInterface[] | BaseToolkit[] | ServerTool[]; /** * Middleware configuration for LangChain v1. * Middleware provides hooks to intercept and control agent execution at critical points. * * Middleware can be: * - Predefined middleware (string or config object) - works in both JSON and JS configs * - Custom middleware objects - only available in JS configs * * Example (JSON config): * ```json * { * "middleware": [ * "summarization", * { "name": "anthropic-prompt-caching", "ttl": "5m" } * ] * } * ``` * * Example (JS config): * ```js * { * middleware: [ * "summarization", * { beforeModel: (state) => { /* custom logic *\/ return state; } } * ] * } * ``` * * Available predefined middleware: * - `anthropic-prompt-caching`: Reduces API costs by caching prompts (Anthropic only) * - `summarization`: Condenses conversation history when approaching token limits */ middleware?: MiddlewareConfig[]; /** * Stream output. Some models do not support streaming. Set value to `false` for them. * * {@link DEFAULT_CONFIG#streamOutput} */ streamOutput: boolean; /** * Should the output be written to md file. * (e.g. gth_2025-07-26_22-59-06_REVIEW.md). * Can be set to false with `-wn` or `-w0` * Can be set to a specific filename or path by passing a string (e.g. `-w review.md`) * Please note the string does not accept absolute path, but allows to exit project with `..` if necessary. */ writeOutputToFile: boolean | string; /** * Use colour in output */ useColour: boolean; /** * Stream session log instead of writing it when inference streaming is complete. * (only works when {@link streamOutput} is true) */ streamSessionInferenceLog: boolean; /** * Allow inference to be interrupted with esc. Only has an effect in TTY mode. */ canInterruptInferenceWithEsc: boolean; /** * Log messages and events to gaunt-sloth.log, * use llm.verbose or `gth --verbose` as more intrusive option, setting verbose to LangChain / LangGraph */ debugLog?: boolean; customToolsConfig?: CustomToolsConfig; requirementsProviderConfig?: Record<string, unknown>; contentProviderConfig?: Record<string, unknown>; mcpServers?: Record<string, Connection>; builtInToolsConfig?: BuiltInToolsConfig; commands?: { pr?: { contentProvider?: string; requirementsProvider?: string; filesystem?: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; logWorkForReviewInSeconds?: number; }; review?: { requirementsProvider?: string; contentProvider?: string; filesystem?: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; }; ask?: { filesystem?: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; }; chat?: { filesystem?: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; }; code?: { filesystem?: string[] | 'all' | 'read' | 'none'; builtInTools?: string[]; devTools?: GthDevToolsConfig; }; }; modelDisplayName?: string; } /** * Server tools such as Anthropic Web Search. * These tools are meant to be magic objects like * `{"type": "web_search_20250305", "name": "web_search", "max_uses": 10}`, * AI Provider does the rest of the magic on their side. */ export interface ServerTool extends Record<string, unknown> { type: string; name?: string; } /** * Raw, unprocessed Gaunt Sloth config. */ export interface RawGthConfig extends Omit<GthConfig, 'llm'> { llm: LLMConfig; } export type CustomToolsConfig = Record<string, object>; export type BuiltInToolsConfig = { jira: JiraConfig; }; /** * Config for {@link GthDevToolkit}. * Tools are not applied when config is not provided. * Only available in `code` mode. */ export interface GthDevToolsConfig { /** * Optional shell command to run tests. * Not applied when config is not provided. */ run_tests?: string; /** * Optional shell command to run static analysis (lint). * Not applied when config is not provided. */ run_lint?: string; /** * Optional shell command to run the build. * Not applied when config is not provided. */ run_build?: string; /** * Optional shell command to run a single test file. * Supports command interpolation with the `${testPath}` placeholder. * Example: "npm test -- ${testPath}" or "jest ${testPath}" * Example: "npm test" - the test will simply be appended * Not applied when config is not provided. */ run_single_test?: string; } export interface LLMConfig extends Record<string, unknown> { type: string; model: string; configuration: Record<string, unknown>; apiKeyEnvironmentVariable?: string; } export declare const availableDefaultConfigs: readonly ["vertexai", "anthropic", "groq", "deepseek", "openai", "google-genai", "xai", "openrouter"]; export type ConfigType = (typeof availableDefaultConfigs)[number]; export interface CommandLineConfigOverrides { /** * Custom config path */ customConfigPath?: string; /** * Set LangChain/LangGraph to verbose mode, * causing LangChain/LangGraph to log many details to the console. * debugLog from config.ts may be a less intrusive option. */ verbose?: boolean; /** * Should the output be written to md file. * (e.g. gth_2025-07-26_22-59-06_REVIEW.md). * Can be set to false with `-wn` or `-w0` * Can be set to a specific filename or path by passing a string (e.g. `-w review.md`) * Please note the string does not accept absolute path, but allows to exit project with `..` if necessary. */ writeOutputToFile?: boolean | string; /** * Separate identity profile. * May include separate identity, guidelines and command protocol, * making gsloth behave as an agent different from default profile behaviour. * for example, `devops` profile to detect changes such as properties and environment variables. * Custom config can still win over this one. * This setting requires .gsloth/.gsloth-settings directory to exist. * Important to note that the profile directory substitutes the entire config directory, * in the case if some prompt files are missing - a file from the installation directory will be used. */ identityProfile?: string; } /** * Default config */ export declare const DEFAULT_CONFIG: { readonly contentProvider: "file"; readonly requirementsProvider: "file"; /** * Path to project-specific guidelines. * The default is `.gsloth.guidelines.md`; this config may be used to point Gaunt Sloth to a different file, * for example, to AGENTS.md */ readonly projectGuidelines: ".gsloth.guidelines.md"; /** * Whether to include the current date in the project review instructions or not. */ readonly includeCurrentDateAfterGuidelines: false; readonly projectReviewInstructions: ".gsloth.review.md"; readonly filesystem: "read"; readonly debugLog: false; /** * Default provider for both requirements and content is GitHub. * It needs GitHub CLI (gh). * * `github` content provider uses `gh pr diff NN` internally. {@link src/providers/ghPrDiffProvider.ts!} * * * `github` requirements provider `gh issue view NN` internally */ readonly commands: { readonly pr: { readonly contentProvider: "github"; readonly requirementsProvider: "github"; }; readonly code: { readonly filesystem: "all"; }; }; readonly streamOutput: true; readonly writeOutputToFile: true; readonly useColour: true; readonly streamSessionInferenceLog: true; readonly canInterruptInferenceWithEsc: true; }; /** * Initialize configuration by loading from available config files * @returns The loaded GthConfig */ export declare function initConfig(commandLineConfigOverrides: CommandLineConfigOverrides): Promise<GthConfig>; /** * Process JSON LLM config by creating the appropriate LLM instance * @param jsonConfig - The parsed JSON config * @param commandLineConfigOverrides - command line config overrides * @returns Promise<GthConfig> */ export declare function tryJsonConfig(jsonConfig: RawGthConfig, commandLineConfigOverrides: CommandLineConfigOverrides): Promise<GthConfig>; export declare function createProjectConfig(configType: string): Promise<void>; export declare function writeProjectReviewPreamble(): void;