Advanced Configuration
**Referenced Files in This Document** - [main.rs](file://src/main.rs) - [Cargo.toml](file://Cargo.toml) - [readme.md](file://readme.md)Table of Contents
- Introduction
- Advanced Configuration Parameters
- Runtime Behavior Tuning
- Interactive Reconfiguration
- Use Cases and Optimization Strategies
- Configuration Validation and Schema Compliance
Introduction
This document details advanced configuration options for the aicommit tool that influence internal behavior beyond basic provider settings. While not explicitly documented in the README, these parameters can be manually added to the configuration file to optimize performance, reliability, and cost efficiency. The system leverages Rust’s lazy_static and env_logger for runtime tuning while using dialoguer for interactive reconfiguration. Understanding these advanced options enables users to tailor the tool for specific environments and use cases.
Section sources
Advanced Configuration Parameters
The aicommit tool exposes several advanced configuration parameters that control internal behavior and performance characteristics. These parameters are not exposed through command-line arguments but can be manually added to the ~/.aicommit.json configuration file.
Diff Formatting Rules
The tool implements intelligent diff processing to prevent excessive API usage and maintain performance:
- MAX_DIFF_CHARS: Global limit of 15,000 characters for the entire diff output
- MAX_FILE_DIFF_CHARS: Per-file limit of 3,000 characters for individual file diffs
When these limits are exceeded, the system intelligently truncates large files while preserving context headers, adding clear truncation notices. This prevents overwhelming LLM providers with excessively large inputs while maintaining meaningful context for commit message generation.
flowchart TD
A[Process Git Diff] --> B{Diff Size > MAX_DIFF_CHARS?}
B --> |No| C[Return Full Diff]
B --> |Yes| D[Split into File Sections]
D --> E[Process Each File]
E --> F{File Size > MAX_FILE_DIFF_CHARS?}
F --> |No| G[Include Full File]
F --> |Yes| H[Truncate with Header + Notice]
H --> I[Add Truncation Marker]
G --> J[Build Processed Output]
I --> J
J --> K{Total Size > MAX_DIFF_CHARS?}
K --> |Yes| L[Final Truncation with Notice]
K --> |No| M[Return Processed Diff]
Diagram sources
Timeout Thresholds for LLM Requests
The system implements multiple timeout mechanisms to ensure responsiveness and prevent hanging requests:
- API Client Timeout: 10 seconds for establishing connections to OpenRouter
- Model Request Timeout: 30 seconds for individual model inference requests
- Model Discovery Timeout: 15 seconds for fetching available models from OpenRouter API
These timeouts are implemented using tokio::time::timeout and are designed to balance between giving models sufficient time to respond and maintaining application responsiveness. Network-related timeouts are distinguished from model failures to prevent unfairly penalizing reliable models during temporary connectivity issues.
Section sources
Custom Cost Tracking for Ollama
While OpenRouter automatically provides token cost information, Ollama configurations support manual cost tracking through optional fields:
- input_cost_per_1k_tokens: Manual specification of input token costs
- output_cost_per_1k_tokens: Manual specification of output token costs
These fields allow users to track computational costs when running local models, providing visibility into resource consumption even when no monetary cost is incurred. The values are used to generate cost estimates in the output, helping users monitor and optimize their AI usage patterns.
Section sources
Logging Verbosity Levels
The application uses env_logger for comprehensive logging with configurable verbosity levels. While not directly exposed in the configuration file, logging behavior can be controlled through environment variables:
- RUST_LOG=error: Show only critical errors
- RUST_LOG=warn: Include warnings about potential issues
- RUST_LOG=info: Display operational information and progress
- RUST_LOG=debug: Show detailed debugging information
- RUST_LOG=trace: Maximum verbosity for troubleshooting
This logging infrastructure provides insight into the internal decision-making processes, particularly useful for understanding model selection in Simple Free mode and troubleshooting connectivity issues.
Section sources
Runtime Behavior Tuning
The aicommit tool employs sophisticated runtime behavior tuning mechanisms that adapt to changing conditions and user preferences.
Lazy Initialization with lazy_static
The application uses lazy_static to manage global configuration state and preferred model lists:
const PREFERRED_FREE_MODELS: &[&str] = &[
"meta-llama/llama-4-maverick:free",
"meta-llama/llama-4-scout:free",
// ... additional models
];
This predefined ranking of free models serves as a fallback when network connectivity is unavailable or when the API query fails. The list prioritizes models by parameter count and quality, ensuring optimal model selection even in offline scenarios. The lazy_static initialization ensures this data structure is created only when first accessed, minimizing startup overhead.
Section sources
Model Jail and Blacklist System
The Simple Free OpenRouter implementation includes an advanced model management system with three-tier status tracking:
- Active: Models available for immediate use
- Jailed: Temporarily restricted due to consecutive failures
- Blacklisted: Long-term ban for persistently problematic models
The system tracks detailed statistics for each model:
- Success and failure counts
- Timestamps of last success/failure
- Jail duration and recidivism tracking
- Blacklist status with historical data
Jail durations increase exponentially for repeat offenders (initially 24 hours, doubling with each subsequent offense), while blacklisting occurs after multiple jail periods. This sophisticated system learns from experience, prioritizing reliable models while giving failing models opportunities to rehabilitate after cooling-off periods.
stateDiagram-v2
[*] --> Active
Active --> Jailed : 3+ consecutive failures
Jailed --> Active : Jail period expired
Jailed --> Blacklisted : Recidivism threshold
Blacklisted --> Active : Manual reset or weekly retry
Active --> Active : Success increments reputation
Diagram sources
Interactive Reconfiguration
The tool provides robust interactive reconfiguration capabilities through the dialoguer library, enabling users to modify settings without direct file editing.
Provider Setup Workflow
The interactive configuration process guides users through provider setup with intelligent defaults:
flowchart TD
A[Initiate Setup] --> B[Select Provider Type]
B --> C[Enter API Key]
C --> D[Configure max_tokens]
D --> E[Set temperature]
E --> F[Save Configuration]
D --> |Default| G["200"]
E --> |Default| H["0.2" for Simple Free, "0.3" otherwise]
The workflow presents sensible defaults for advanced parameters like max_tokens (200) and temperature (0.2-0.3), reducing configuration complexity while allowing customization. Provider-specific defaults reflect typical usage patterns and performance characteristics.
Section sources
Model Management Commands
The system provides specialized commands for managing the model jail system:
- —jail-status: Displays current status of all models, including jail durations and failure statistics
- —unjail [model-id]: Releases a specific model from restrictions
- —unjail-all: Resets all models to active status
These commands provide transparency into the model selection process and allow users to override automated decisions when appropriate. The —jail-status command is particularly valuable for understanding why certain models aren’t being selected and diagnosing connectivity versus model-specific issues.
Section sources
Use Cases and Optimization Strategies
Understanding advanced configuration options enables optimization for specific use cases and environmental constraints.
Low-Latency Connection Optimization
For environments with unreliable or high-latency connections, configure the system to prioritize responsiveness:
- Reduce max_tokens to minimize payload size
- Implement aggressive timeouts through environment variables
- Pre-populate the configuration with reliable fallback models
- Increase retry_attempts to compensate for intermittent failures
This configuration strategy minimizes wait times and improves user experience in challenging network conditions, trading some message quality for reliability and speed.
Constrained Environment Token Usage Reduction
In environments with limited computational resources or strict token budgets:
- Set lower max_tokens values to reduce model processing load
- Configure conservative temperature settings (0.1-0.2) to minimize randomness
- Utilize the diff truncation features to reduce input size
- Monitor and adjust based on actual token usage statistics
These adjustments significantly reduce both input and output token consumption, making the tool more efficient and cost-effective when working with rate-limited or expensive LLM providers.
High-Reliability Production Deployment
For mission-critical deployments requiring maximum reliability:
- Configure multiple providers as fallbacks
- Increase retry_attempts to 5-7 for greater resilience
- Implement monitoring of jail status to proactively address issues
- Use the simulate_offline flag for testing failover scenarios
This approach creates a robust system capable of maintaining functionality even during extended provider outages or network disruptions.
Configuration Validation and Schema Compliance
Manual configuration extension requires careful attention to schema compliance to avoid parsing errors.
Schema Validation Requirements
The configuration system uses serde for JSON serialization/deserialization with strict parsing rules:
- All field names must match exactly (case-sensitive)
- Data types must be correct (strings, numbers, booleans)
- Required fields cannot be omitted
- Unknown fields may cause deserialization failures
Invalid field names or type mismatches will result in configuration loading failures, preventing the application from starting until the issue is resolved.
Safe Manual Extension Practices
When extending the configuration manually:
- Always back up the existing configuration
- Validate JSON syntax before saving
- Test changes incrementally rather than making multiple modifications at once
- Verify functionality after each change
The system’s strict serde parsing protects against malformed configurations but requires precision when editing manually. Users should consult the codebase documentation in main.rs when uncertain about field names or types.
Section sources