engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 29 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 engine wires the scan pipeline: it connects the stages (source, decode, detect, suppress, verify, enrich, grade, fixplan) over bounded channels, runs the worker pools and the single barrier after enrich, applies timeouts and sorts findings once. It is the only package that imports stage packages.

Index

Constants

View Source
const (
	// SourceFS reads a working tree directory or one file.
	SourceFS = "fs"
	// SourceStdin reads one stream.
	SourceStdin = "stdin"
	// SourceSurface reads agent surface files (settings, allowlists, MCP config,
	// transcripts) of one scope.
	SourceSurface = "surface"
	// SourceGitHistory reads the added lines of a repository's history.
	SourceGitHistory = "git-history"
	// SourceGitStaged reads the added lines of a repository's index.
	SourceGitStaged = "git-staged"
)

Source adapter names.

View Source
const (
	// ScopeMachine reads per-user agent files under the home directory.
	ScopeMachine = source.ScopeMachine
	// ScopeProject reads project-tier agent files below the scan root.
	ScopeProject = source.ScopeProject
)

Surface source scopes (SourceSpec.Scope).

View Source
const DefaultToolVersion = "dev"

DefaultToolVersion is Meta.ToolVersion when Config.ToolVersion is empty.

Variables

View Source
var (
	// ErrNoSources: the config names no source.
	ErrNoSources = errors.New("engine: no sources")
	// ErrSource: a source cannot be scanned at all.
	ErrSource = errors.New("engine: invalid source")
	// ErrUnknownAdapter: no adapter is registered under a configured name.
	ErrUnknownAdapter = errors.New("engine: unknown adapter")
	// ErrRegistry: the embedded registry failed to load.
	ErrRegistry = errors.New("engine: registry failed to load")
	// ErrIgnoreRule: an ignore rule in Config.Ignore is invalid.
	ErrIgnoreRule = errors.New("engine: invalid ignore rule")
	// ErrBaseline: Config.Baseline is invalid.
	ErrBaseline = errors.New("engine: invalid baseline")
)

Errors returned by Start.

Functions

func BuildFixPlan added in v0.2.0

func BuildFixPlan(f model.Finding) (*model.FixPlan, error)

BuildFixPlan returns the fix plan of f built with the embedded registry: the same plan the default fixplan stage sets during a scan.

Types

type Adapters

type Adapters struct {
	Decode, Detect, Suppress, Verify, Enrich, Grade, FixPlan string
}

Adapters names the adapter of each stage. Empty fields select the defaults.

type Config

type Config struct {
	Sources []SourceSpec
	// IncludeTestKeys keeps findings from generated test keys unsuppressed.
	IncludeTestKeys bool
	// Ignore are the ignore rules the suppress stage applies; an invalid rule makes
	// Start return ErrIgnoreRule.
	Ignore []model.IgnoreRule
	// Baseline is the accepted set of findings the suppress stage compares final ids
	// with (nil: no comparison); an invalid one makes Start return ErrBaseline.
	Baseline *model.Baseline
	// Timeout stops the scan and returns partial results; 0 means no timeout.
	Timeout time.Duration
	// Deterministic pins Meta.GeneratedAt to the Unix epoch and DurationMS to 0.
	Deterministic bool
	// Now pins Meta.GeneratedAt (and so the age of first_seen) when not zero; the zero
	// value means the wall clock, or the epoch under Deterministic.
	Now time.Time
	// IncludeIgnored makes fs sources walk every file, ignored ones too, instead of
	// listing what git would commit.
	IncludeIgnored bool
	// Git is the proxy and CA configuration handed to git.
	Git gitx.Config
	// ToolVersion is Meta.ToolVersion (DefaultToolVersion when empty).
	ToolVersion string
	// Registry is the provider registry; nil means the embedded snapshot, whose load
	// warnings are then added to the Report.
	Registry *registry.Registry
	// RegistryWarnings are added to the Report when Registry is set.
	RegistryWarnings []model.Warning
	// Adapters picks the stage adapters by name.
	Adapters Adapters
	// Workers is the number of workers per concurrent stage; 0 means GOMAXPROCS.
	Workers int
	// MaxFileBytes is the largest file or stream a source reads; larger ones are
	// skipped with a file_too_large warning. 0 or less means the source default.
	MaxFileBytes int64
	// ExtraWarnings are added to the Report as they are (config warnings).
	ExtraWarnings []model.Warning
	// DecodeMaxDepth bounds nested decoding (limits.decode_max_depth); 0 or less
	// means the decoder default (3).
	DecodeMaxDepth int
	// VerifyEnabled selects the live verify adapter when Adapters.Verify is empty; the
	// zero value keeps verification off.
	VerifyEnabled bool
	// VerifyMaxConcurrency caps concurrent verify calls (0: the verifier default, 8).
	VerifyMaxConcurrency int
	// VerifyTimeout bounds one verify call (0: the verifier default, 10s).
	VerifyTimeout time.Duration
	// Network is the transport configuration of the verify client (proxy, CA bundle,
	// and the DialAddrs test hook, which only tests set).
	Network netx.Config
	// AllowHosts are extra hosts the verify client may reach.
	AllowHosts []string
	// GradeFThresholdUSDPerDay is the summed live dollars at risk per day at which a
	// target gets grade F (0: the grader default, 500).
	GradeFThresholdUSDPerDay float64
}

Config configures one scan.

type Run

type Run struct {
	// contains filtered or unexported fields
}

Run is one running scan.

func Start

func Start(ctx context.Context, cfg Config) (*Run, error)

Start validates cfg, builds every stage and source, and starts the scan. The scan stops at cfg.Timeout or when ctx is done, and then returns partial results.

func (*Run) Events

func (r *Run) Events() <-chan model.Event

Events returns the progress event channel. The first call starts delivery; the channel is closed after the barrier once every event has been delivered. A caller that never calls Events, or stops reading, never blocks the scan.

func (*Run) Progress

func (r *Run) Progress() (files, commits int)

Progress returns how many files and streams have reached detection so far and how many commits were scanned. It is safe to call while the scan runs.

func (*Run) Wait

func (r *Run) Wait() *model.Report

Wait blocks until the scan is done and returns the Report. Every call returns the same Report.

type SourceSpec

type SourceSpec struct {
	// Adapter is the source adapter name, for example SourceFS or SourceStdin.
	Adapter string
	// Path is the directory or file of an fs source, or the repository of a git source.
	Path string
	// Since limits a git-history source to commits reachable from HEAD but not from
	// this ref (empty: the whole history).
	Since string
	// Name is the display name of a stream source ("-" when empty).
	Name string
	// Reader is the stream of a stream source.
	Reader io.Reader
	// FS replaces the operating system file system of an fs source (tests only).
	FS fs.FS
	// Scope is ScopeMachine or ScopeProject (surface source).
	Scope string
	// Home is the home directory of a machine surface scan; empty means the OS home.
	Home string
	// Root is the scan root of a project surface scan; empty means Path.
	Root string
}

SourceSpec is one source to scan: an adapter name and what it reads.

Jump to

Keyboard shortcuts

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