Documentation
¶
Overview ¶
Package aider provides a client for the Aider CLI.
Aider is a git-aware AI coding assistant that supports local models via Ollama. This package wraps the `aider` CLI for programmatic use, particularly suited for code editing workflows that integrate with git.
Installation ¶
Install Aider:
pip install aider-chat
Usage ¶
Via provider registry:
import _ "github.com/randalmurphal/llmkit/aider" // Register provider
client, err := provider.New("aider", provider.Config{
Provider: "aider",
Model: "ollama_chat/llama3.2:latest",
WorkDir: "/path/to/project",
Options: map[string]any{
"editable_files": []string{"src/main.go"},
"yes_always": true,
},
})
Direct instantiation:
client := aider.NewAiderCLI(
aider.WithModel("ollama_chat/llama3.2:latest"),
aider.WithWorkdir("/path/to/project"),
aider.WithEditableFiles([]string{"src/main.go"}),
aider.WithYesAlways(),
)
Ollama Configuration ¶
Use the ollama_chat/ prefix for Ollama models:
client := aider.NewAiderCLI(
aider.WithModel("ollama_chat/llama3.2:latest"),
aider.WithOllamaAPIBase("http://localhost:11434"),
)
Note: Ollama defaults to 2k context window which is small for Aider. Set OLLAMA_CONTEXT_LENGTH=8192 (or higher) when running ollama serve.
Capabilities ¶
Aider provides git-centric code editing:
- File editing with git integration
- Shell command suggestions
- Automatic commits (can be disabled)
Aider does NOT currently support:
- MCP servers (PR pending)
- Session persistence
- Image inputs
- JSON output format (text parsing required)
Git Integration ¶
Aider is deeply integrated with git. Control git behavior with:
client := aider.NewAiderCLI(
aider.WithNoGit(), // Disable git entirely
aider.WithNoAutoCommits(), // Disable auto-commits
)
Index ¶
- func ContainsCommit(output string) bool
- func ExtractCommitHash(output string) string
- func ExtractErrorMessage(output string) string
- func ParseAiderOutput(output string) *provider.Response
- type AiderCLI
- func (c *AiderCLI) Capabilities() provider.Capabilities
- func (c *AiderCLI) Close() error
- func (c *AiderCLI) Complete(ctx context.Context, req provider.Request) (*provider.Response, error)
- func (c *AiderCLI) Provider() string
- func (c *AiderCLI) Stream(ctx context.Context, req provider.Request) (<-chan provider.StreamChunk, error)
- type Config
- type EditMarker
- type Option
- func WithDryRun() Option
- func WithEditFormat(format string) Option
- func WithEditableFiles(files []string) Option
- func WithEnv(env map[string]string) Option
- func WithEnvVar(key, value string) Option
- func WithModel(model string) Option
- func WithNoAutoCommits() Option
- func WithNoGit() Option
- func WithNoStream() Option
- func WithOllamaAPIBase(url string) Option
- func WithPath(path string) Option
- func WithReadOnlyFiles(files []string) Option
- func WithTimeout(d time.Duration) Option
- func WithWorkdir(dir string) Option
- func WithYesAlways() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsCommit ¶
ContainsCommit checks if the output indicates a git commit was made.
func ExtractCommitHash ¶
ExtractCommitHash extracts a git commit hash from Aider output. Looks for patterns like "Committed abc1234" or "commit a1b2c3d4".
func ExtractErrorMessage ¶
ExtractErrorMessage extracts error messages from Aider output.
func ParseAiderOutput ¶
ParseAiderOutput parses Aider's text output into a provider.Response. Aider does not have native JSON output, so we parse the text for patterns.
Types ¶
type AiderCLI ¶
type AiderCLI struct {
// contains filtered or unexported fields
}
AiderCLI implements provider.Client using the Aider CLI binary.
func NewAiderCLI ¶
NewAiderCLI creates a new Aider CLI client. Assumes "aider" is available in PATH unless overridden with WithPath.
func (*AiderCLI) Capabilities ¶
func (c *AiderCLI) Capabilities() provider.Capabilities
Capabilities implements provider.Client.
func (*AiderCLI) Complete ¶
Complete implements provider.Client. Executes aider with --message flag and returns the response.
type Config ¶
type Config struct {
// Path is the path to the aider binary.
// Default: "aider"
Path string `json:"path" yaml:"path"`
// Model is the model to use.
// For Ollama, use "ollama_chat/<model>" prefix.
// Example: "ollama_chat/llama3.2:latest"
Model string `json:"model" yaml:"model"`
// WorkDir is the working directory for the CLI.
WorkDir string `json:"work_dir" yaml:"work_dir"`
// Timeout is the API request timeout.
// Default: 5 minutes.
Timeout time.Duration `json:"timeout" yaml:"timeout"`
// EditableFiles are files that Aider can modify.
// These are passed with --file flags.
EditableFiles []string `json:"editable_files" yaml:"editable_files"`
// ReadOnlyFiles are files for context only (not editable).
// These are passed with --read flags.
ReadOnlyFiles []string `json:"read_only_files" yaml:"read_only_files"`
// NoGit disables git integration entirely.
NoGit bool `json:"no_git" yaml:"no_git"`
// NoAutoCommits disables automatic commits after edits.
NoAutoCommits bool `json:"no_auto_commits" yaml:"no_auto_commits"`
// NoStream disables streaming responses.
NoStream bool `json:"no_stream" yaml:"no_stream"`
// DryRun previews changes without modifying files.
DryRun bool `json:"dry_run" yaml:"dry_run"`
// YesAlways automatically confirms all prompts.
// Required for non-interactive automation.
YesAlways bool `json:"yes_always" yaml:"yes_always"`
// EditFormat specifies the edit format (diff, whole, etc.).
EditFormat string `json:"edit_format" yaml:"edit_format"`
// Env provides additional environment variables.
Env map[string]string `json:"env" yaml:"env"`
// OllamaAPIBase is the Ollama API base URL.
// Can also be set via OLLAMA_API_BASE env var.
// Default: http://127.0.0.1:11434
OllamaAPIBase string `json:"ollama_api_base" yaml:"ollama_api_base"`
}
Config holds Aider CLI configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
func (Config) WithDefaults ¶
WithDefaults returns a copy of the config with defaults applied.
type EditMarker ¶
EditMarker represents a detected file edit.
func ParseEditMarkers ¶
func ParseEditMarkers(output string) []EditMarker
ParseEditMarkers extracts file edit markers from Aider output. Aider outputs patterns like:
- "Applied edit to file.go"
- "Created file.go"
- "Modified file.go"
- "Wrote file.go"
type Option ¶
type Option func(*AiderCLI)
Option configures an AiderCLI.
func WithDryRun ¶
func WithDryRun() Option
WithDryRun enables dry-run mode (preview without modifying).
func WithEditFormat ¶
WithEditFormat sets the edit format.
func WithEditableFiles ¶
WithEditableFiles sets files that can be modified.
func WithEnvVar ¶
WithEnvVar adds a single environment variable.
func WithNoAutoCommits ¶
func WithNoAutoCommits() Option
WithNoAutoCommits disables automatic commits.
func WithOllamaAPIBase ¶
WithOllamaAPIBase sets the Ollama API base URL.
func WithReadOnlyFiles ¶
WithReadOnlyFiles sets read-only context files.
func WithYesAlways ¶
func WithYesAlways() Option
WithYesAlways enables automatic confirmation of all prompts.