aider

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsCommit

func ContainsCommit(output string) bool

ContainsCommit checks if the output indicates a git commit was made.

func ExtractCommitHash

func ExtractCommitHash(output string) string

ExtractCommitHash extracts a git commit hash from Aider output. Looks for patterns like "Committed abc1234" or "commit a1b2c3d4".

func ExtractErrorMessage

func ExtractErrorMessage(output string) string

ExtractErrorMessage extracts error messages from Aider output.

func ParseAiderOutput

func ParseAiderOutput(output string) *provider.Response

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

func NewAiderCLI(opts ...Option) *AiderCLI

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) Close

func (c *AiderCLI) Close() error

Close implements provider.Client.

func (*AiderCLI) Complete

func (c *AiderCLI) Complete(ctx context.Context, req provider.Request) (*provider.Response, error)

Complete implements provider.Client. Executes aider with --message flag and returns the response.

func (*AiderCLI) Provider

func (c *AiderCLI) Provider() string

Provider implements provider.Client.

func (*AiderCLI) Stream

func (c *AiderCLI) Stream(ctx context.Context, req provider.Request) (<-chan provider.StreamChunk, error)

Stream implements provider.Client. Aider streams output by default, so we read it line by line.

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) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

func (Config) WithDefaults

func (c Config) WithDefaults() Config

WithDefaults returns a copy of the config with defaults applied.

type EditMarker

type EditMarker struct {
	Action string // "created", "modified", "applied"
	File   string
}

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

func WithEditFormat(format string) Option

WithEditFormat sets the edit format.

func WithEditableFiles

func WithEditableFiles(files []string) Option

WithEditableFiles sets files that can be modified.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv adds environment variables.

func WithEnvVar

func WithEnvVar(key, value string) Option

WithEnvVar adds a single environment variable.

func WithModel

func WithModel(model string) Option

WithModel sets the model name.

func WithNoAutoCommits

func WithNoAutoCommits() Option

WithNoAutoCommits disables automatic commits.

func WithNoGit

func WithNoGit() Option

WithNoGit disables git integration.

func WithNoStream

func WithNoStream() Option

WithNoStream disables streaming responses.

func WithOllamaAPIBase

func WithOllamaAPIBase(url string) Option

WithOllamaAPIBase sets the Ollama API base URL.

func WithPath

func WithPath(path string) Option

WithPath sets the path to the aider binary.

func WithReadOnlyFiles

func WithReadOnlyFiles(files []string) Option

WithReadOnlyFiles sets read-only context files.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the API timeout.

func WithWorkdir

func WithWorkdir(dir string) Option

WithWorkdir sets the working directory.

func WithYesAlways

func WithYesAlways() Option

WithYesAlways enables automatic confirmation of all prompts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL