config

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFastModel = "gemini/gemini-3.1-flash-lite"

DefaultFastModel is the default fast model reference. Flash Lite via Gemini: 92.9% AOI recall, 0 FP, 5.1s, $0.0004 per scan.

View Source
const DefaultStrongModel = "github-copilot/claude-opus-4.6"

DefaultStrongModel is the default strong model reference. Opus 4.6 via Copilot: 100% recall, 0 FP, 27 tool calls, 202s on deep review benchmark.

Variables

View Source
var KeylessProviderAvailable = map[string]func() bool{}

KeylessProviderAvailable is set by other packages (e.g. internal/ai for claude-code) to report whether a keyless provider is usable on the current machine. Keys not in this map are treated as unavailable.

Using a hook here avoids an import cycle: internal/config does not depend on internal/ai, but ConfiguredProviders needs to know whether claude-code is detected. Callers register their detector at init time.

Functions

func BenchmarkPath added in v1.4.0

func BenchmarkPath() (string, error)

BenchmarkPath returns ~/.config/prr/benchmark.json.

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns ~/.config/prr/config.json

func IsKeylessProvider added in v1.4.0

func IsKeylessProvider(provider string) bool

IsKeylessProvider reports whether a provider is usable without an API key in the prr config. claude-code authenticates via the Claude Code CLI's own keychain/subscription/OAuth, so prr does not need a key for it.

func IsKnownModel added in v1.4.0

func IsKnownModel(id string) bool

IsKnownModel returns true if the model ID is known. Accepts either "provider/model-id" or bare "model-id".

func KnownProviders added in v1.4.0

func KnownProviders() []string

KnownProviders returns the list of supported provider names.

claude-code is included unconditionally so callers (e.g. ParseModelRef validation) recognise it; whether it is actually usable on the current machine is decided by ai.DetectClaudeCode at runtime.

func LoadCustomInstructions

func LoadCustomInstructions() string

LoadCustomInstructions searches for a custom instructions file in the repo root and returns its contents. Returns empty string if no file is found.

Search order:

  1. .prr/instructions.md
  2. .github/prr-instructions.md

func LoadModels

func LoadModels() (map[string]ModelConfig, error)

LoadModels returns model configs by merging embedded defaults with user overrides from ~/.config/prr/models.json. If the user file doesn't exist, it is created with the embedded defaults.

func LoadPipeTargets added in v1.3.0

func LoadPipeTargets() []pipe.Target

LoadPipeTargets reads pipe targets from the config file. Returns nil (not an error) if the config doesn't exist or has no pipes configured.

func Save

func Save(cfg *Config) error

Save writes the config back to the default path, preserving any fields the user may have set manually. It re-reads the file first so that only known fields are overwritten (provider, model, parallel_reviews).

func SaveBenchmarkResults added in v1.4.0

func SaveBenchmarkResults(results *BenchmarkResults) error

SaveBenchmarkResults merges new benchmark results into ~/.config/prr/benchmark.json. Existing entries are updated if they match on provider+model_id+config_name; new entries are appended. The timestamp is always updated.

func SaveTo added in v1.4.0

func SaveTo(cfg *Config, path string) error

SaveTo saves config to a specific path. Exported for testing.

func ShouldExcludeFromReview

func ShouldExcludeFromReview(path string) bool

ShouldExcludeFromReview returns true if the given file path should be excluded from AI review based on default exclusion patterns.

Types

type BenchmarkResults added in v1.4.0

type BenchmarkResults struct {
	Version   int              `json:"version"`   // schema version, currently 1
	Timestamp time.Time        `json:"timestamp"` // when the benchmark was run
	Models    []ModelBenchmark `json:"models"`
}

BenchmarkResults holds the full benchmark output file.

func LoadBenchmarkResults added in v1.4.0

func LoadBenchmarkResults() (*BenchmarkResults, error)

LoadBenchmarkResults reads benchmark results, preferring a user-local file at ~/.config/prr/benchmark.json over the defaults embedded in the binary. Always returns non-nil results (falls back to embedded defaults).

func (*BenchmarkResults) GetModelBenchmark added in v1.4.0

func (b *BenchmarkResults) GetModelBenchmark(modelID string) *ModelBenchmark

GetModelBenchmark returns benchmark data for a specific model, or nil if not found. When provider is non-empty, it matches on provider+model_id. When multiple runs exist for the same model (different configs), returns the one with the highest recall.

func (*BenchmarkResults) GetModelBenchmarkForProvider added in v1.4.0

func (b *BenchmarkResults) GetModelBenchmarkForProvider(provider, modelID string) *ModelBenchmark

GetModelBenchmarkForProvider returns benchmark data matching both provider and model ID. Falls back to provider-agnostic match if no provider-specific entry exists.

type Config

type Config struct {
	// StrongModel is the "provider/model" ref for deep review, re-review, and synthesis phases.
	StrongModel string `json:"strong_model"`
	// FastModel is the "provider/model" ref for discovery and AOI phases.
	FastModel string `json:"fast_model,omitempty"`

	Theme           string                    `json:"theme,omitempty"`            // UI theme ID
	ParallelReviews int                       `json:"parallel_reviews,omitempty"` // number of concurrent batch reviews (default 3)
	Pipes           []pipe.Target             `json:"pipes,omitempty"`            // external process pipe targets
	Providers       map[string]ProviderConfig `json:"providers,omitempty"`        // per-provider configs
	Debug           bool                      `json:"-"`                          // set via --debug flag, not persisted
}

Config holds the application configuration.

Models are specified in "provider/model-id" format (e.g. "gemini/gemini-3.1-pro-preview"). This allows mixing providers — e.g. a Gemini fast model with a GitHub Copilot strong model.

func Load

func Load() (*Config, error)

Load reads the config from the default path. Returns a descriptive error if the file is missing or malformed.

func LoadFrom added in v1.4.0

func LoadFrom(path string) (*Config, error)

LoadFrom reads and validates config from a specific path.

func LoadRaw added in v1.4.0

func LoadRaw() (*Config, error)

LoadRaw reads the config from the default path without validation. Used by the config wizard to work with incomplete configs.

func LoadRawFrom added in v1.4.0

func LoadRawFrom(path string) (*Config, error)

LoadRawFrom reads config from a specific path without validation.

func (*Config) APIKeyFor added in v1.4.0

func (c *Config) APIKeyFor(provider string) string

APIKeyFor returns the API key for the given provider. Returns empty string if no key is configured.

func (*Config) ConfiguredProviders added in v1.4.0

func (c *Config) ConfiguredProviders() []string

ConfiguredProviders returns providers that are usable. A provider is usable if it has an API key set, or if it is a keyless provider (e.g. claude-code) whose detector reports it as available.

func (*Config) ProviderConfigFor added in v1.4.0

func (c *Config) ProviderConfigFor(provider string) ProviderConfig

ProviderConfigFor returns the ProviderConfig for the given provider name, if any.

func (*Config) ResolveModels added in v1.4.0

func (c *Config) ResolveModels() (strongRef, fastRef ModelRef, err error)

ResolveModels resolves which strong / fast models a command should use, applies the choice to cfg (StrongModel / FastModel), and returns the parsed refs for downstream callers (API-key checks, model profile lookups).

Precedence:

  1. PRR_REVIEW_MODEL + PRR_AOI_MODEL env vars — non-interactive. Both must be set; either may be a bare model ID or a full "provider/model-id" ref. Bare IDs are resolved against cfg.Providers (so CI environments can pin a model without knowing which provider it lives under).
  2. Interactive picker (huh form). cfg.StrongModel / cfg.FastModel are used as the pre-selected defaults when they're in the options list — so a user who has chosen models before sees their previous choice highlighted.

Returns an error if no review or AOI models are available, if the selected ref is malformed, or if the selected provider has no API key configured (and isn't a keyless provider like claude-code).

type KnownModel added in v1.4.0

type KnownModel struct {
	ID       string // API model ID (e.g. "gemini-3.1-flash-lite")
	Label    string // Human-friendly display label
	Provider string // "gemini", "anthropic", "openai"
	Thinking bool   // Whether the model supports thinking/reasoning
	AOI      bool   // Whether this model is suitable for AOI pre-scanning (cheap/fast)
	Review   bool   // Whether this model is suitable for deep review

	// Pricing per 1M tokens (USD). Zero means unknown/free-tier.
	InputPricePer1M  float64
	OutputPricePer1M float64

	// Speed is a qualitative indicator: "fast", "medium", "slow".
	// Based on benchmark data where available, otherwise estimated.
	Speed string
}

KnownModel describes a model available for selection in pickers and validation.

func AOIModels added in v1.4.0

func AOIModels(providers ...string) []KnownModel

AOIModels returns known models suitable for AOI pre-scanning. If providers is non-empty, only models from those providers are returned.

func GetKnownModel added in v1.4.0

func GetKnownModel(id string) (KnownModel, bool)

GetKnownModel returns the KnownModel for an ID. Accepts "provider/model-id" (exact match) or bare "model-id" (returns the entry with pricing when ambiguous).

func GetKnownModelForProvider added in v1.4.0

func GetKnownModelForProvider(provider, modelID string) (KnownModel, bool)

GetKnownModelForProvider returns the KnownModel for a specific provider/model pair.

func KnownModelsForProvider added in v1.4.0

func KnownModelsForProvider(provider string) []KnownModel

KnownModelsForProvider returns all known models for a given provider.

func ReviewModels added in v1.4.0

func ReviewModels(providers ...string) []KnownModel

ReviewModels returns all known models suitable for review. If providers is non-empty, only models from those providers are returned.

func (KnownModel) PriceTag added in v1.4.0

func (m KnownModel) PriceTag() string

PriceTag returns a short human-readable price string like "$0.15/1M in". Returns "" if pricing is unknown.

func (KnownModel) SpeedIcon added in v1.4.0

func (m KnownModel) SpeedIcon() string

SpeedIcon returns a short icon/label for display: "⚡" fast, "●" medium, "◐" slow.

type ModelBenchmark added in v1.4.0

type ModelBenchmark struct {
	ModelID        string  `json:"model_id"`
	Provider       string  `json:"provider"`    // e.g. "gemini", "github-copilot"
	ConfigName     string  `json:"config_name"` // e.g. "temp=0.1", "thinking=2k"
	Temperature    float64 `json:"temperature"`
	ThinkingBudget int     `json:"thinking_budget,omitempty"`
	RecallPct      float64 `json:"recall_pct"`    // overall recall percentage (0-100)
	MustFindPct    float64 `json:"must_find_pct"` // must-find recall percentage (0-100)
	LatencyMs      int     `json:"latency_ms"`    // scan latency in milliseconds
	CostPerScan    float64 `json:"cost_per_scan"` // estimated USD per scan
	TotalAOIs      int     `json:"total_aois"`    // AOIs found
	FalseAlarms    int     `json:"false_alarms"`  // false positives
}

ModelBenchmark holds benchmark results for a single model configuration.

type ModelConfig

type ModelConfig struct {
	MaxOutputTokens int             `json:"max_output_tokens"`
	Temperature     float64         `json:"temperature"`
	ThinkingBudget  ThinkingBudgets `json:"thinking_budget"`             // per-mode thinking budgets
	AOIContextLines int             `json:"aoi_context_lines,omitempty"` // diff context lines for AOI scanning (0 = default 3)
}

ModelConfig holds per-model tuning parameters.

func GetModelConfig

func GetModelConfig(models map[string]ModelConfig, modelID string) ModelConfig

GetModelConfig returns the config for a specific model. If no exact match, returns a sensible fallback.

func (ModelConfig) ResolvedAOIContextLines added in v1.4.0

func (mc ModelConfig) ResolvedAOIContextLines() int

ResolvedAOIContextLines returns the AOI context lines for a model, defaulting to 3 if not configured.

type ModelRef added in v1.4.0

type ModelRef struct {
	Provider string // e.g. "gemini", "openai", "github-copilot"
	ModelID  string // e.g. "gemini-3.1-flash-lite"
}

ModelRef is a parsed "provider/model-id" reference.

func ParseModelRef added in v1.4.0

func ParseModelRef(s string) (ModelRef, error)

ParseModelRef parses a "provider/model-id" string into a ModelRef. Returns an error if the format is invalid.

func (ModelRef) String added in v1.4.0

func (r ModelRef) String() string

String returns the canonical "provider/model-id" format.

type ModelSelection added in v1.4.0

type ModelSelection struct {
	StrongModel string // "provider/model-id" ref used for deep review
	FastModel   string // "provider/model-id" ref used for AOI pre-scan
}

ModelSelection holds the user's strong / fast model choices.

type ProviderConfig added in v1.4.0

type ProviderConfig struct {
	APIKey  string `json:"api_key,omitempty"`
	BaseURL string `json:"base_url,omitempty"` // optional endpoint override

	// UseCLI marks providers whose auth and invocation are delegated to
	// an external CLI binary (currently only claude-code). It's a
	// documentation marker rather than a switch — the actual detection
	// uses exec.LookPath at runtime via KeylessProviderAvailable. The
	// wizard writes UseCLI:true so the user sees their selection
	// persisted in config.json instead of an empty {} object.
	UseCLI bool `json:"use_cli,omitempty"`
}

ProviderConfig holds credentials and settings for a single provider.

type ThinkingBudgets added in v1.4.0

type ThinkingBudgets struct {
	Review int `json:"review"` // deep review, re-review, synthesis
	Chat   int `json:"chat"`   // interactive TUI chat
	Fast   int `json:"fast"`   // discovery, AOI pre-scan
}

ThinkingBudgets holds per-mode thinking token budgets. Zero means thinking is disabled for that mode.

Jump to

Keyboard shortcuts

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