// Comprehensive code documentation for yact project
YACT (Yet Another Coding Tool) is a CLI application that integrates with Claude AI to assist with code generation, analysis, and planning tasks. The codebase is organized into four main packages: api, commands, config, and logic.
Struct that implements the Client interface for interacting with the Anthropic Claude API. Manages API credentials, model selection, token limits, and cost calculation.
Methods:
Init(cfg *config.Config)- Initializes the client with configuration settings including API key, model selection, and token budgetsselectModel(cfg *config.Config) anthropic.Model- Selects the appropriate Claude model variant (Opus, Sonnet, or Haiku) based on configurationselectInputPrice(cfg *config.Config) int- Returns the input token price in cents per million tokens for the selected modelselectOutputPrice(cfg *config.Config) int- Returns the output token price in cents per million tokens for the selected modelGetModelName() string- Returns the name of the currently selected modelcalculateCost(inputTokens int64, outputTokens int64) float64- Calculates API call cost based on token usageCall(transaction logic.Transaction, think bool, systemPrompt string) (string, error)- Sends a request to Claude with context files and prompts, returns the model's response
Interface defining the contract for AI client implementations with three required methods.
Methods:
Init(cfg *config.Config)- Initializes the client with configurationGetModelName() string- Returns the model name as a stringCall(transaction logic.Transaction, think bool, systemPrompt string) (string, error)- Executes an AI request and returns the response
Reads a file from disk and formats it as a delimited code block with file path comment for inclusion in prompts.
Generates code based on the current transaction context and request, optionally writing generated files to disk or displaying response only.
Requests a plan for implementation from Claude and saves it as the transaction request for later reference.
Sends a question about the codebase to Claude and displays the response without saving files.
Manages user configuration by displaying current settings or setting individual configuration values like API key, model, and token limits.
Discovers relevant files for the current task by analyzing the task prompt against the project index and updates the transaction context accordingly.
Uses Claude to identify which files from a project index are most relevant to a given task prompt, returning a list of relevant file paths.
Constructs a formatted string containing all project files with their descriptions for presentation to Claude during context discovery.
Scans the project directory, merges findings with existing index entries, fetches AI-generated descriptions for files without descriptions, and saves the updated index.
Uses Claude to generate brief descriptions for files that lack descriptions in the project index.
Creates a new empty transaction context for starting a fresh task.
Adds file references to the current transaction context using glob pattern matching to support multiple files.
Requests code modifications for a specific line range in a file, applies Claude's response while preserving indentation, and writes the result back to the file.
Displays usage information for all available commands and configuration options.
Contains user configuration settings for API access and model behavior with fields for API key, model selection, and token budgets.
Fields:
AnthropicAPIKey string- Claude API authentication keyClaudeModel string- Selected model variant (haiku, sonnet, or opus)MaxTokens int- Maximum output tokens per API callThinkBudget int- Token budget for extended thinking mode
Methods:
Save() error- Persists configuration to the user's home directory config file
Returns a Config struct with sensible default values for all fields.
Reads configuration from the user's home directory, returning defaults if the config file doesn't exist.
Reads system prompt content from files stored in the user's config directory by prompt name.
Represents a source code file with its path, content, and optional description extracted from code comments.
Methods:
Write() error- Creates necessary directories and writes the code file to disk
Creates a CodeFile from a path and content string, with automatic path normalization.
Reads an existing file from disk and returns it as a CodeFile struct.
Parses Claude's response to extract code blocks delimited by backticks, returning both CodeFile objects and any text outside code blocks.
Represents an indexed project file with its path and cached description.
Fields:
Path string- Relative file pathDescription string- Brief description of file purpose
Reads the project file index from a CSV file, returning an empty index if the file doesn't exist.
Recursively scans the project directory excluding common directories like .git and node_modules, returning entries for all discovered files.
Combines newly discovered disk files with existing index entries, preserving descriptions and removing entries for deleted files.
Writes the file index to a CSV file for later retrieval and analysis.
Represents the context and request for an AI operation with two components: context files and the task request.
Fields:
Request []string- The task description or prompt for ClaudeContext []string- Paths to files to include as context
Methods:
Save() error- Persists the transaction to the .yact file in the current directory
Reads the transaction from the .yact file in the current directory, returning an empty transaction if the file doesn't exist.