config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads spackle.toml and merges it with defaults. Flags are applied on top by the CLI. API keys are never read from config or flags: config only names the environment variable that holds one.

Index

Constants

View Source
const (
	StagePlanner      = "planner"
	StageInvestigator = "investigator"
	StageProver       = "prover"
	StageReviewer     = "reviewer"
	StageFixer        = "fixer"
	StageMechanical   = "mechanical"
)

The pipeline stages that can have their own model. The names are config keys and are stored in ledgers.

View Source
const (
	ProviderAnthropic        = "anthropic"
	ProviderOpenAI           = "openai"
	ProviderOpenAICompatible = "openai-compatible"
	ProviderOllama           = "ollama"
)

Provider names.

View Source
const DefaultFile = "spackle.toml"

DefaultFile is the config file looked up in the working directory.

View Source
const NamePlaceholder = "{name}"

NamePlaceholder is replaced by the test name in [test] single.

Variables

View Source
var ExternalScanners = []string{"semgrep", "gitleaks", "osv-scanner", "trivy", "hadolint"}

ExternalScanners are the names [scan] scanners accepts. A test in the seed package keeps it equal to the names of seed.External.

Stages lists the pipeline stages that can have their own model.

Functions

func DefaultKeyEnv

func DefaultKeyEnv(provider string) string

DefaultKeyEnv returns the conventional API key variable for a provider.

Types

type Budget

type Budget struct {
	Tokens      int      `toml:"tokens"`
	USD         float64  `toml:"usd"`
	WallTime    Duration `toml:"wall_time"`
	SandboxRuns int      `toml:"sandbox_runs"`
	MaxFindings int      `toml:"max_findings"`
	// MaxTurns caps tool-use turns for one agent task.
	MaxTurns int `toml:"max_turns"`
	// AllowUnpriced lets an unattended run start with a model that has no
	// known price although a dollar cap was set. The dollar cap cannot hold
	// for such a model, so only the other caps limit the run.
	AllowUnpriced bool `toml:"allow_unpriced"`
	// USDSet records that the dollar cap was set by the operator, in the
	// config file or with --budget-usd, and is not the built-in default.
	USDSet bool `toml:"-"`
}

Budget holds the hard caps of a run. Zero means "use the default"; caps cannot be turned off.

type Config

type Config struct {
	Model   Model            `toml:"model"`
	Stages  map[string]Model `toml:"stages"`
	Budget  Budget           `toml:"budget"`
	Scope   Scope            `toml:"scope"`
	Sandbox Sandbox          `toml:"sandbox"`
	Fix     Fix              `toml:"fix"`
	Scan    Scan             `toml:"scan"`
	Test    Test             `toml:"test"`
	Output  Output           `toml:"output"`
	Pricing map[string]Price `toml:"pricing"`
	Offline bool             `toml:"offline"`
	// StateDir is where runs and caches are stored.
	StateDir string `toml:"state_dir"`
	// Ignored lists the keys of an automatically found spackle.toml that
	// were not applied because that file is not trusted (see untrust).
	Ignored []string `toml:"-"`
}

Config is the whole configuration.

func Default

func Default() Config

Default returns the built-in configuration.

func Load

func Load(path string) (Config, string, error)

Load reads the config file at path over the defaults. When path is empty it looks for spackle.toml in the working directory and returns the defaults if there is none. The second result is the file that was read, or "" when none was.

func (Config) ForStage

func (c Config) ForStage(stage string) Model

ForStage returns the model for a stage: its own entry when one exists, otherwise the default model. Fields the stage entry leaves empty are inherited when the provider is the same.

func (Config) Validate

func (c Config) Validate() error

Validate checks the configuration and reports every problem at once.

type Duration

type Duration struct{ time.Duration }

Duration parses TOML strings such as "30m".

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Fix

type Fix struct {
	Enabled     *bool `toml:"enabled"`
	MaxAttempts int   `toml:"max_attempts"`
	// PR pushes the fix branch and opens a pull request.
	PR bool `toml:"pr"`
}

Fix configures the fixer.

func (Fix) On

func (f Fix) On() bool

On reports whether fixing is enabled (the default).

type Model

type Model struct {
	Provider string `toml:"provider"`
	Model    string `toml:"model"`
	BaseURL  string `toml:"base_url"`
	// APIKeyEnv names the environment variable holding the API key.
	APIKeyEnv string `toml:"api_key_env"`
	// MaxOutputTokens caps one completion.
	MaxOutputTokens int `toml:"max_output_tokens"`
}

Model selects a provider and model.

func (Model) Configured

func (m Model) Configured() bool

Configured reports whether a provider has been chosen.

type Output

type Output struct {
	Formats []string `toml:"formats"`
	Dir     string   `toml:"dir"`
	// FailOn is the lowest severity that makes scan exit 1.
	FailOn string `toml:"fail_on"`
	// FailOnConfidence is the lowest confidence a finding needs to count
	// toward FailOn: plausible (every finding), high or demonstrated.
	FailOnConfidence string `toml:"fail_on_confidence"`
}

Output configures reports.

type Price

type Price struct {
	InputPerMTok  float64 `toml:"input_per_mtok"`
	OutputPerMTok float64 `toml:"output_per_mtok"`
}

Price is the cost of a model per million tokens, in USD.

type Sandbox

type Sandbox struct {
	Runtime  string            `toml:"runtime"` // auto|docker|podman|none
	Network  string            `toml:"network"` // none, or scope to attach the runtime's unfiltered bridge network to code-scan proofs
	MemoryMB int               `toml:"memory_mb"`
	CPUs     float64           `toml:"cpus"`
	PIDs     int               `toml:"pids"`
	Timeout  Duration          `toml:"timeout"`
	Images   map[string]string `toml:"images"`
}

Sandbox configures the container runtime.

func (Sandbox) Profile added in v0.2.0

func (s Sandbox) Profile() sandbox.Profile

Profile returns the container limits the sandbox table asks for, as they were written: the sandbox package fills in its defaults. It is the one place the table becomes a profile, so every command that starts a container runs it under the same limits.

type Scan added in v0.2.0

type Scan struct {
	// Exclude lists forward-slash globs, relative to the target root, of
	// paths that are not read ("bench/corpus/**", "*.min.js").
	Exclude []string `toml:"exclude"`
	// Include lists directories to read although their name is skipped by
	// default ("build", "vendor/internal/**").
	Include []string `toml:"include"`
	// DisableRules lists rule ids whose leads are dropped.
	DisableRules []string `toml:"disable_rules"`
	// Scanners names the external scanners a scan may run. nil (the key
	// is absent) lets every installed one run; an empty list runs none.
	// The built-in rules always run.
	Scanners []string `toml:"scanners"`
	// Baseline is the path of a baseline file (written by spackle
	// baseline). A finding that matches one of its entries is accepted:
	// still reported, but it does not fail the run.
	Baseline string `toml:"baseline"`
}

Scan controls what a code scan covers.

type Scope

type Scope struct {
	// Hosts lists authorized hosts as host or host:port.
	Hosts        []string `toml:"hosts"`
	PathPrefixes []string `toml:"path_prefixes"`
	// AllowUnsafeMethods permits POST, PUT, PATCH and DELETE probes.
	AllowUnsafeMethods bool    `toml:"allow_unsafe_methods"`
	MaxRequests        int     `toml:"max_requests"`
	RequestsPerSecond  float64 `toml:"requests_per_second"`
	// Statement is the operator's own note on why they are authorized,
	// recorded in the ledger.
	Statement string `toml:"statement"`
}

Scope is the authorized scope for live targets.

type Test added in v0.2.0

type Test struct {
	// Command runs the whole test suite: the scan's baseline run and the
	// suite check after a fix in debug mode.
	Command []string `toml:"command"`
	// Single runs one named test for spackle debug --test. Every
	// occurrence of {name} in an argument is replaced by the test name.
	Single []string `toml:"single"`
}

Test overrides the project test commands the mapper detects. Both run only in the sandbox, as an argument vector with no shell.

func (Test) SingleFor added in v0.2.0

func (t Test) SingleFor(name string) []string

SingleFor returns the single-test command for name, or nil when none is configured.

Jump to

Keyboard shortcuts

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