{"modulePath":"github.com/TMHSDigital/spackle","version":"v0.2.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package engine\n\nPackage engine runs the Spackle pipeline for one target and writes the run's ledger, evidence folders and reports.\n\n## Constants\n\n```go\nconst (\n\tDiffScopeFile  = \"file\"\n\tDiffScopeLines = \"lines\"\n)\n```\nThe values of Options.DiffScope.\n\n```go\nconst DisabledScannerNote = \"not run: [scan] scanners in the configuration leaves it out\"\n```\nDisabledScannerNote is what the report and doctor say about an external scanner that \\[scan] scanners leaves out.\n\n## Variables\n\n```go\nvar ErrRefused = errors.New(\"run refused\")\n```\nErrRefused marks a run that was refused before it started (bad target, missing authorization). The CLI maps it to the usage exit code.\n\n## Functions\n\n```go\nfunc CacheDir(stateDir string) string\n```\nCacheDir returns the directory of the map cache, which runs share.\n\n```go\nfunc CheckStateDir(stateDir string) error\n```\nCheckStateDir 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.\n\n```go\nfunc CloneDir(stateDir, runID string) string\n```\nCloneDir returns where the clone of a git URL target of run runID is kept.\n\n```go\nfunc FromLead(l seed.Lead, notRunReason string) finding.Finding\n```\nFromLead turns a lead into a finding at the lowest confidence level. It is used when no model investigates the lead.\n\n```go\nfunc NewRunID(stateDir string, now time.Time) (string, error)\n```\nNewRunID 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.\n\n```go\nfunc ResolveRun(stateDir, id string) (string, error)\n```\nResolveRun finds a run directory by id, accepting a unique prefix or the word \"latest\".\n\n```go\nfunc Resumable(run report.Run) bool\n```\nResumable reports whether a stored run stopped on its budget with planned investigations it did not reach, which scan --resume can continue.\n\n```go\nfunc ResumeFlags(run report.Run) string\n```\nResumeFlags returns the scan flags that resume a stored run with the same file set: --resume with its id, and its --since or --changed.\n\n```go\nfunc RunDirs(stateDir, runID string) []string\n```\nRunDirs 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.\n\n```go\nfunc RunsDir(stateDir string) string\n```\nRunsDir returns the directory that holds runs for a state directory.\n\n```go\nfunc WorktreeDir(stateDir, runID string) string\n```\nWorktreeDir returns where the fix worktree of run runID is kept.\n\n```go\nfunc WriteArtifacts(runDir string, run report.Run) error\n```\nWriteArtifacts writes findings/\\\u003cid\u003e/finding.json (plus fix.patch and review.md when present), reports/report.\\\u003cext\u003e for every format, and the run summary that listings read.\n\n## Types\n\n```go\ntype DebugOptions struct {\n\t// Target is a local directory. Git URLs and live URLs are refused.\n\tTarget string\n\t// Test is the name of a failing test. Exactly one of Test and Issue is set.\n\tTest string\n\t// Issue is the text of an issue description. It is untrusted input.\n\tIssue string\n\t// Good is an optional known-good revision; it enables bisect.\n\tGood     string\n\tConfig   config.Config\n\tProgress io.Writer\n\t// Clock and RunID make runs reproducible in tests.\n\tClock func() time.Time\n\tRunID string\n\t// Confirm is asked before any model call. Nil means proceed.\n\tConfirm func(Estimate) bool\n\t// ProviderFactory overrides how model providers are built, for tests.\n\tProviderFactory func(config.Model) (llm.Provider, error)\n\t// DetectRuntime overrides container runtime detection, for tests.\n\tDetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)\n}\n```\nDebugOptions configure one debug run.\n\n```go\ntype Estimate struct {\n\tInvestigations int\n\tModel          string\n\tUSD            float64\n\tCostKnown      bool\n\tLocal          bool\n\tCapUSD         float64\n\tCapTokens      int\n}\n```\nEstimate describes the expected cost of the agentic stages.\n\n```go\nfunc (e Estimate) String() string\n```\nString renders the estimate as the one-line notice shown to the operator.\n\n```go\ntype Options struct {\n\tTarget string\n\tConfig config.Config\n\t// Progress receives one-line status messages. Nil discards them.\n\tProgress io.Writer\n\t// Seeders overrides the seeder set; nil means seed.All().\n\tSeeders []seed.Seeder\n\t// Clock and RunID make runs reproducible in tests.\n\tClock func() time.Time\n\tRunID string\n\t// Confirm is asked before a run that will call a model. It receives the\n\t// estimate and returns whether to proceed. Nil means proceed without\n\t// asking (the caller has already handled --yes).\n\tConfirm func(Estimate) bool\n\t// ProviderFactory overrides how model providers are built, for tests.\n\tProviderFactory func(config.Model) (llm.Provider, error)\n\t// DryRun stops after mapping and seeding: Result.Plan says what would\n\t// be scanned and what it would cost. No model is called and no run\n\t// directory is written.\n\tDryRun bool\n\t// Ref is the branch or tag to scan for a git URL target. Empty means\n\t// the remote's default branch.\n\tRef string\n\t// RoutesFrom is a local directory holding the source of a running\n\t// target. Its HTTP routes, as the mapper finds them, are added to the\n\t// crawl next to the start URL. Only for a running target.\n\tRoutesFrom string\n\t// Since limits a scan of a directory to the files changed since this\n\t// revision (see gitx.ChangedSince). Empty scans everything.\n\tSince string\n\t// Changed limits a scan of a directory to the files that differ from\n\t// HEAD, staged or not, and the untracked files git does not ignore: a\n\t// pre-commit scan (see gitx.ChangedUncommitted). It excludes Since.\n\tChanged bool\n\t// Staged limits a scan of a directory to the files whose staged\n\t// version differs from HEAD: what the next commit would contain (see\n\t// gitx.ChangedStaged). The files are read from the working tree. It\n\t// excludes Since and Changed, and a staged scan cannot be resumed.\n\tStaged bool\n\t// DiffScope narrows a diff scan (Since, Changed or Staged): DiffScopeFile, the\n\t// default, reports every lead in a changed file; DiffScopeLines reports\n\t// only leads on the changed lines. Empty means DiffScopeFile, or, for\n\t// a resumed run, the scope of the run it continues.\n\tDiffScope string\n\t// Resume is the id of a stored scan to continue (\"latest\" for the\n\t// newest): its remaining investigations are run with a fresh budget\n\t// and its findings are carried into the new run. Force allows that\n\t// when the target's commit has changed since.\n\tResume string\n\tForce  bool\n\t// ScopeFile is the --authorize scope file for a live target.\n\tScopeFile string\n\t// Yes is true for --yes and CI: never prompt for authorization.\n\tYes bool\n\t// Interactive is true when Stdin is a terminal a person can answer on.\n\tInteractive bool\n\t// Stdin is read for the interactive scope confirmation.\n\tStdin io.Reader\n\t// OpenPR overrides how a pull request is opened for --pr, for tests.\n\tOpenPR func(ctx context.Context, req gitx.PRRequest) (string, error)\n\t// DetectRuntime overrides container runtime detection, for tests.\n\tDetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)\n\t// contains filtered or unexported fields\n}\n```\nOptions configure one run.\n\n```go\ntype Plan struct {\n\tTarget     string        `json:\"target\"`\n\tTargetKind string        `json:\"target_kind\"`\n\tMode       string        `json:\"mode\"` // deterministic|agentic\n\tFiles      int           `json:\"files\"`\n\tLanguages  []string      `json:\"languages\"`\n\tNotRead    []string      `json:\"not_read\"`\n\tSeeders    []seed.Status `json:\"seeders\"`\n\tLeads      int           `json:\"leads\"`\n\t// LeadsByClass and LeadsBySeverity count the leads; the severity is\n\t// the seeder's hint, not a computed score.\n\tLeadsByClass    map[string]int `json:\"leads_by_class\"`\n\tLeadsBySeverity map[string]int `json:\"leads_by_severity\"`\n\t// Investigations is how many the planner would be asked for at most.\n\t// It is 0 in deterministic mode.\n\tInvestigations int      `json:\"investigations\"`\n\tModel          string   `json:\"model,omitempty\"`\n\tEstimate       string   `json:\"estimate\"`\n\tNotes          []string `json:\"notes\"`\n}\n```\nPlan 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.\n\n```go\ntype Result struct {\n\tRunID  string\n\tRunDir string\n\tRun    report.Run\n\t// Plan is set, and nothing else is, for a dry run.\n\tPlan *Plan\n}\n```\nResult identifies a finished run.\n\n```go\nfunc Debug(ctx context.Context, opts DebugOptions) (_ Result, err error)\n```\nDebug 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.\n\n```go\nfunc Run(ctx context.Context, opts Options) (_ Result, err error)\n```\nRun executes the pipeline.\n\n```go\ntype VerifyOptions struct {\n\tConfig   config.Config\n\tRunDir   string\n\tProgress io.Writer\n\tClock    func() time.Time\n\t// DetectRuntime overrides container runtime detection, for tests.\n\tDetectRuntime func(ctx context.Context, preferred string) (sandbox.Runtime, error)\n\t// Findings, when set, limits verify to the proofs of these finding ids.\n\tFindings []string\n\t// Dir is the directory verify is run from. When set, the run's target\n\t// must be it or inside it.\n\tDir string\n}\n```\nVerifyOptions configure a verify run.\n\n```go\ntype VerifyOutcome struct {\n\tFindingID  string\n\tTitle      string\n\tReproduces bool\n\t// Inconclusive is true when the proof could not be run to an answer\n\t// (it timed out, was killed, or the sandbox failed). The finding's\n\t// status is then left as it was.\n\tInconclusive bool\n\tNote         string\n}\n```\nVerifyOutcome is the result of re-running one stored proof.\n\n```go\nfunc Verify(ctx context.Context, opts VerifyOptions) ([]VerifyOutcome, error)\n```\nVerify 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.\n\n","path":"github.com/TMHSDigital/spackle/internal/engine","name":"engine","synopsis":"Package engine runs the Spackle pipeline for one target and writes the run's ledger, evidence folders and reports.","isRedistributable":true}
