Documentation
¶
Overview ¶
Package engine runs the Spackle pipeline for one target and writes the run's ledger, evidence folders and reports.
Index ¶
- Constants
- Variables
- func CacheDir(stateDir string) string
- func CheckStateDir(stateDir string) error
- func CloneDir(stateDir, runID string) string
- func FromLead(l seed.Lead, notRunReason string) finding.Finding
- func NewRunID(stateDir string, now time.Time) (string, error)
- func ResolveRun(stateDir, id string) (string, error)
- func Resumable(run report.Run) bool
- func ResumeFlags(run report.Run) string
- func RunDirs(stateDir, runID string) []string
- func RunsDir(stateDir string) string
- func WorktreeDir(stateDir, runID string) string
- func WriteArtifacts(runDir string, run report.Run) error
- type DebugOptions
- type Estimate
- type Options
- type Plan
- type Result
- type VerifyOptions
- type VerifyOutcome
Constants ¶
const ( DiffScopeFile = "file" DiffScopeLines = "lines" )
The values of Options.DiffScope.
const DisabledScannerNote = "not run: [scan] scanners in the configuration leaves it out"
DisabledScannerNote is what the report and doctor say about an external scanner that [scan] scanners leaves out.
Variables ¶
var ErrRefused = errors.New("run refused")
ErrRefused marks a run that was refused before it started (bad target, missing authorization). The CLI maps it to the usage exit code.
Functions ¶
func CheckStateDir ¶ added in v0.2.0
CheckStateDir refuses a state directory whose runs folder holds files tracked by git. Spackle never commits runs, so tracked runs came with the repository, not from a scan on this machine, and reading them would let the repository choose what report, verify and the MCP tools act on.
func CloneDir ¶ added in v0.2.0
CloneDir returns where the clone of a git URL target of run runID is kept.
func FromLead ¶
FromLead turns a lead into a finding at the lowest confidence level. It is used when no model investigates the lead.
func NewRunID ¶
NewRunID returns an id of the form 20261122-153045-00a1b2: the UTC start time to the second, a sequence number in two hex digits, and two random bytes. The sequence number is one more than the highest among the runs in stateDir that started in the same second, so ids sort in the order the runs were started, which "latest" and every listing rely on. It stops at ff. Runs started at the same moment by two processes share a sequence number, and the random bytes keep their ids apart.
func ResolveRun ¶
ResolveRun finds a run directory by id, accepting a unique prefix or the word "latest".
func Resumable ¶ added in v0.2.0
Resumable reports whether a stored run stopped on its budget with planned investigations it did not reach, which scan --resume can continue.
func ResumeFlags ¶ added in v0.2.0
ResumeFlags returns the scan flags that resume a stored run with the same file set: --resume with its id, and its --since or --changed.
func RunDirs ¶ added in v0.2.0
RunDirs returns every directory a run owns in the state directory: its run directory, the clone of its target and its fix worktree. Deleting a run deletes them all; the map cache is shared and is not among them.
func WorktreeDir ¶ added in v0.2.0
WorktreeDir returns where the fix worktree of run runID is kept.
Types ¶
type DebugOptions ¶
type DebugOptions struct {
// Target is a local directory. Git URLs and live URLs are refused.
Target string
// Test is the name of a failing test. Exactly one of Test and Issue is set.
Test string
// Issue is the text of an issue description. It is untrusted input.
Issue string
// Good is an optional known-good revision; it enables bisect.
Good string
Config config.Config
Progress io.Writer
// Clock and RunID make runs reproducible in tests.
Clock func() time.Time
RunID string
// Confirm is asked before any model call. Nil means proceed.
Confirm func(Estimate) bool
// ProviderFactory overrides how model providers are built, for tests.
ProviderFactory func(config.Model) (llm.Provider, error)
// DetectRuntime overrides container runtime detection, for tests.
DetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)
}
DebugOptions configure one debug run.
type Estimate ¶
type Estimate struct {
Investigations int
Model string
USD float64
CostKnown bool
Local bool
CapUSD float64
CapTokens int
}
Estimate describes the expected cost of the agentic stages.
type Options ¶
type Options struct {
Target string
Config config.Config
// Progress receives one-line status messages. Nil discards them.
Progress io.Writer
// Seeders overrides the seeder set; nil means seed.All().
Seeders []seed.Seeder
// Clock and RunID make runs reproducible in tests.
Clock func() time.Time
RunID string
// Confirm is asked before a run that will call a model. It receives the
// estimate and returns whether to proceed. Nil means proceed without
// asking (the caller has already handled --yes).
Confirm func(Estimate) bool
// ProviderFactory overrides how model providers are built, for tests.
ProviderFactory func(config.Model) (llm.Provider, error)
// DryRun stops after mapping and seeding: Result.Plan says what would
// be scanned and what it would cost. No model is called and no run
// directory is written.
DryRun bool
// Ref is the branch or tag to scan for a git URL target. Empty means
// the remote's default branch.
Ref string
// RoutesFrom is a local directory holding the source of a running
// target. Its HTTP routes, as the mapper finds them, are added to the
// crawl next to the start URL. Only for a running target.
RoutesFrom string
// Since limits a scan of a directory to the files changed since this
// revision (see gitx.ChangedSince). Empty scans everything.
Since string
// Changed limits a scan of a directory to the files that differ from
// HEAD, staged or not, and the untracked files git does not ignore: a
// pre-commit scan (see gitx.ChangedUncommitted). It excludes Since.
Changed bool
// Staged limits a scan of a directory to the files whose staged
// version differs from HEAD: what the next commit would contain (see
// gitx.ChangedStaged). The files are read from the working tree. It
// excludes Since and Changed, and a staged scan cannot be resumed.
Staged bool
// DiffScope narrows a diff scan (Since, Changed or Staged): DiffScopeFile, the
// default, reports every lead in a changed file; DiffScopeLines reports
// only leads on the changed lines. Empty means DiffScopeFile, or, for
// a resumed run, the scope of the run it continues.
DiffScope string
// Resume is the id of a stored scan to continue ("latest" for the
// newest): its remaining investigations are run with a fresh budget
// and its findings are carried into the new run. Force allows that
// when the target's commit has changed since.
Resume string
Force bool
// ScopeFile is the --authorize scope file for a live target.
ScopeFile string
// Yes is true for --yes and CI: never prompt for authorization.
Yes bool
// Interactive is true when Stdin is a terminal a person can answer on.
Interactive bool
// Stdin is read for the interactive scope confirmation.
Stdin io.Reader
// OpenPR overrides how a pull request is opened for --pr, for tests.
OpenPR func(ctx context.Context, req gitx.PRRequest) (string, error)
// DetectRuntime overrides container runtime detection, for tests.
DetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)
// contains filtered or unexported fields
}
Options configure one run.
type Plan ¶ added in v0.2.0
type Plan struct {
Target string `json:"target"`
TargetKind string `json:"target_kind"`
Mode string `json:"mode"` // deterministic|agentic
Files int `json:"files"`
Languages []string `json:"languages"`
NotRead []string `json:"not_read"`
Seeders []seed.Status `json:"seeders"`
Leads int `json:"leads"`
// LeadsByClass and LeadsBySeverity count the leads; the severity is
// the seeder's hint, not a computed score.
LeadsByClass map[string]int `json:"leads_by_class"`
LeadsBySeverity map[string]int `json:"leads_by_severity"`
// Investigations is how many the planner would be asked for at most.
// It is 0 in deterministic mode.
Investigations int `json:"investigations"`
Model string `json:"model,omitempty"`
Estimate string `json:"estimate"`
Notes []string `json:"notes"`
}
Plan is what a dry run reports: what a scan of the target would read and do, without doing the part that costs money or writes a run.
type Result ¶
type Result struct {
RunID string
RunDir string
Run report.Run
// Plan is set, and nothing else is, for a dry run.
Plan *Plan
}
Result identifies a finished run.
func Debug ¶
func Debug(ctx context.Context, opts DebugOptions) (_ Result, err error)
Debug starts from a failing test or an issue description, reproduces the failure in the sandbox, finds the root cause (bisecting when a good revision is given), writes a fix and verifies it. Nothing is executed outside the sandbox and the working tree is never modified.
type VerifyOptions ¶
type VerifyOptions struct {
Config config.Config
RunDir string
Progress io.Writer
Clock func() time.Time
// DetectRuntime overrides container runtime detection, for tests.
DetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)
// Findings, when set, limits verify to the proofs of these finding ids.
Findings []string
// Dir is the directory verify is run from. When set, the run's target
// must be it or inside it.
Dir string
}
VerifyOptions configure a verify run.
type VerifyOutcome ¶
type VerifyOutcome struct {
FindingID string
Title string
Reproduces bool
// Inconclusive is true when the proof could not be run to an answer
// (it timed out, was killed, or the sandbox failed). The finding's
// status is then left as it was.
Inconclusive bool
Note string
}
VerifyOutcome is the result of re-running one stored proof.
func Verify ¶
func Verify(ctx context.Context, opts VerifyOptions) ([]VerifyOutcome, error)
Verify re-runs the stored proof of concept of every finding the scan demonstrated against the target as it is now, appends the outcomes to the run's ledger, and rewrites the reports. A proof that no longer succeeds marks its finding fixed. A stored proof that never succeeded is skipped. Nothing is executed outside the sandbox, so without a container runtime Verify refuses instead of guessing.