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 ¶
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.
const ( ProviderAnthropic = "anthropic" ProviderOpenAI = "openai" ProviderOpenAICompatible = "openai-compatible" ProviderOllama = "ollama" )
Provider names.
const DefaultFile = "spackle.toml"
DefaultFile is the config file looked up in the working directory.
const NamePlaceholder = "{name}"
NamePlaceholder is replaced by the test name in [test] single.
Variables ¶
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.
var Stages = []string{StagePlanner, StageInvestigator, StageProver, StageReviewer, StageFixer, StageMechanical}
Stages lists the pipeline stages that can have their own model.
Functions ¶
func DefaultKeyEnv ¶
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 Load ¶
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.
type Duration ¶
Duration parses TOML strings such as "30m".
func (*Duration) UnmarshalText ¶
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.
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 ¶
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.
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.