Documentation
¶
Overview ¶
Package agent holds the model-driven stages of the pipeline: planner, investigators, reviewer and the shared tool loop they run on.
The loop gives a model nothing but an allowlisted, read-only tool registry. Scope, budgets and tool permissions are enforced here in Go. Nothing a model or a target says can change them, because there is no tool whose effect is to change them.
Index ¶
- Constants
- func ApplyReview(f finding.Finding, rev Review) finding.Finding
- func BuildFinding(root string, d Draft, origin []string) (finding.Finding, error)
- func CheckProofCommand(language string, cmd []string) error
- func CheckProofFile(name string) (string, error)
- func Correlate(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, ...) ([]finding.Finding, error)
- func InconclusiveWhy(res sandbox.Result) string
- func NewMarker() (string, error)
- type Box
- type Check
- type Diagnosis
- type Draft
- type DraftStep
- type EndpointReview
- type FixInput
- type FixResult
- type Intent
- type Investigation
- type Outcome
- type PoC
- type ProofOutcome
- type ProofResult
- type Review
- type Runner
Constants ¶
const ( StopNone = "" StopTurns = "turn limit" StopStagnation = "stagnation" StopRefusal = "provider refusal" StopTruncated = "output truncated" )
Why a conversation stopped before the model chose to.
const ( ReviewConfirmed = "confirmed" ReviewRefuted = "refuted" ReviewUncertain = "uncertain" )
Review verdicts.
Variables ¶
This section is empty.
Functions ¶
func ApplyReview ¶
ApplyReview returns the finding updated with the review's outcome.
- confirmed: unchanged, apart from a corrected severity.
- refuted: dismissed, with the reviewer's reason kept.
- uncertain: kept open, but confidence drops to plausible, because a second reader could not verify it.
func BuildFinding ¶
BuildFinding validates a draft against the target and converts it. It returns an error describing every problem, so a rejected draft can be sent back to the model once with specific corrections.
What is checked: the class is known; the file exists inside the target; the line range is inside the file; every quoted line really appears in the file it cites (line numbers are corrected when the quote is found elsewhere in the same file); and the CVSS vector is valid. The score and label are computed here, never taken from the model.
func CheckProofCommand ¶ added in v0.2.0
CheckProofCommand checks the command of a proof: 1 to 16 arguments, the first a program the language table allows, with no control characters. There is no shell: a proof is one program run with an argument vector.
func CheckProofFile ¶ added in v0.2.0
CheckProofFile checks the name of one proof file and returns it cleaned: a relative path inside spackle_poc/, or a file named spackle_poc_test.go. A stored proof is held to it again before spackle verify runs it.
func Correlate ¶
func Correlate(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, fs []finding.Finding) ([]finding.Finding, error)
Correlate asks the model which confirmed findings combine into a larger attack and returns the findings with their kill chain and related ids filled in. Chains that name unknown ids are ignored. A failure here is not fatal: the findings are returned unchanged with the error.
func InconclusiveWhy ¶ added in v0.2.0
InconclusiveWhy says, for a sentence, why a proof run was inconclusive: "the proof <why>".
Types ¶
type Box ¶
type Box struct {
Runtime sandbox.Runtime
Profile sandbox.Profile
Budget *budget.Budget
Root string
// Record is called after every sandbox run so the engine can write the
// ledger event and the evidence file.
Record func(purpose string, spec sandbox.Spec, res sandbox.Result) error
}
Box runs things in the sandbox and accounts for them. The engine supplies it; it is the only way the prover and fixer can execute anything.
func (*Box) Exec ¶ added in v0.2.0
func (b *Box) Exec(ctx context.Context, purpose, image string, cmd []string, files map[string]string, sourceDir string) (sandbox.Result, error)
Exec executes one command against a copy of sourceDir (the target when it is "") plus extra files. It is the one way to start a sandbox run: it counts the run against the sandbox cap, bounds it by the wall time that is left, and records it. A run stopped by the wall time cap returns an error wrapping budget.ErrExhausted.
type Check ¶
type Check func(ctx context.Context, files map[string]string) (problem string, verification string, verified bool, err error)
Check verifies one candidate fix. A non-empty problem rejects the fix and is sent back to the model. With an empty problem the fix is kept, and verified says whether it is proven or only offered.
type Diagnosis ¶
type Diagnosis struct {
Title, RootCause string
// File and Line name the faulty code. File is empty when the model named
// a file that is not in the target.
File string
Line int
// Quotes are the evidence lines that really appear in the files they
// cite, with corrected line numbers. Quotes that do not match are gone.
Quotes []DraftStep
FixSummary, Why string
// Files maps a target-relative path to its complete new content.
Files map[string]string
// Patch is the unified diff Spackle computed from Files.
Patch string
Verified bool
Verification string
Attempts int
// Reason explains why there is no root cause or no accepted fix.
Reason string
}
Diagnosis is the outcome of looking for a root cause and a fix.
func Diagnose ¶
func Diagnose(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, reg *tools.Registry, root string, failure string, wantFix bool, maxAttempts int, check Check) (Diagnosis, error)
Diagnose asks the model for the root cause and a fix, calls check to verify each candidate patch, and feeds a rejected attempt's problem back, up to maxAttempts times. When wantFix is false it asks only for the root cause. The failure text is untrusted and reaches the model only inside an envelope. A fix that check rejected is never returned.
type Draft ¶
type Draft struct {
Title string `json:"title"`
Class string `json:"class"`
CWE []string `json:"cwe"`
File string `json:"file"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
Symbol string `json:"symbol"`
Vector string `json:"cvss_vector"`
SeverityReasoning string `json:"severity_reasoning"`
Description string `json:"description"`
Flow []DraftStep `json:"flow"`
Preconditions []string `json:"preconditions"`
AttackSteps []string `json:"attack_steps"`
ChainsInto []string `json:"chains_into"`
Gains []string `json:"gains"`
Exposed []string `json:"exposed"`
FixSummary string `json:"fix_summary"`
FixWhy string `json:"fix_why"`
DefenseInDepth []string `json:"defense_in_depth"`
Confidence string `json:"confidence"`
ConfidenceReason string `json:"confidence_reason"`
}
Draft is a finding as a model proposes it. Nothing in a draft is trusted: BuildFinding checks every claim it can against the target before the draft becomes a finding.
type DraftStep ¶
type DraftStep struct {
Role string `json:"role"`
File string `json:"file"`
Line int `json:"line"`
Quote string `json:"quote"`
Note string `json:"note"`
}
DraftStep is one flow step in a draft.
type EndpointReview ¶
type EndpointReview struct {
// Confirmed is false when the investigator concluded the observation is
// not a real flaw; Reason then says why.
Confirmed bool
Reason string
Finding finding.Finding
// Rejected is set when the answer could not be used. The finding is
// then left as the probe reported it.
Rejected string
}
EndpointReview is an investigator's assessment of one running-target finding.
func InvestigateEndpoint ¶
func InvestigateEndpoint(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, reg *tools.Registry, f finding.Finding, exchanges string, known func(id string) bool) (EndpointReview, error)
InvestigateEndpoint asks the model to confirm and explain one running-target finding. exchanges are the recorded request and response pairs that produced it, already redacted, as text. known reports whether an exchange id exists, so the model cannot cite evidence that was never recorded.
type FixInput ¶
type FixInput struct {
Language string
Image string
// PoC is the proof that demonstrated the finding, or nil.
PoC *PoC
// TestCmd is the project's test command as an argument vector, or nil.
TestCmd []string
// BaselineTestsPass says whether TestCmd passed on the unmodified code.
// A patch is only held to the suite when the suite was green to begin
// with: a suite that already fails cannot tell a regression from noise.
BaselineTestsPass bool
MaxAttempts int
}
FixInput is what the fixer needs besides the finding.
type FixResult ¶
type FixResult struct {
// Files maps a target-relative path to its full new content.
Files map[string]string
// Patch is the unified diff Spackle computed from Files.
Patch string
Why string
// Verified is true only when a proof of concept that used to succeed no
// longer does, and nothing that was checked got worse.
Verified bool
// Verification says, in a sentence, exactly what was and was not checked.
Verification string
Attempts int
// Reason explains a failure to produce any acceptable patch.
Reason string
}
FixResult is the outcome of trying to fix a finding.
func Fix ¶
func Fix(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, reg *tools.Registry, box *Box, in FixInput, f finding.Finding) (FixResult, error)
Fix asks the model for a patch and verifies it in the sandbox, up to MaxAttempts times. Each rejected attempt is sent back with the reason. A patch that fails verification is never returned.
type Intent ¶
Intent is one planned investigation.
func FallbackPlan ¶
FallbackPlan builds intents straight from leads, one per file and class, worst severity first. It is used when the planner fails or returns nothing usable, so a model problem degrades the run instead of ending it.
func Plan ¶
func Plan(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, m mapper.Map, leads []seed.Lead, limit int) ([]Intent, error)
Plan asks the model for a prioritized list of investigations. Whatever the model returns is validated against the real map and leads: intents that name files or leads that do not exist lose those references, and intents left with nothing to look at are dropped.
func ResumePlan ¶ added in v0.2.0
ResumePlan returns the plan of a resumed run: the investigations an earlier run planned and did not reach. They are checked against the current map and leads like any other plan, so a file or a lead that is gone since then drops out.
type Investigation ¶
type Investigation struct {
Intent Intent
// Finding is set when the investigator reported a flaw that passed
// validation.
Finding *finding.Finding
// NoFinding is the investigator's reason when it concluded the lead
// does not hold up.
NoFinding string
// Rejected is why the result could not be used: malformed output, a
// quote that is not in the file, a refusal, a cut-off answer.
Rejected string
}
Investigation is the result of investigating one intent.
func Investigate ¶
func Investigate(ctx context.Context, r *Runner, parent int64, root string, sealer *envelope.Sealer, reg *tools.Registry, intent Intent, leads []seed.Lead) (Investigation, error)
Investigate runs one investigation. A draft that fails validation is sent back once with the specific problems; if the second answer also fails, the investigation is rejected and recorded, and the run continues.
type Outcome ¶
type Outcome struct {
Text string
Turns int
Stopped string
// Note explains Stopped when there is more to say (a refusal category).
Note string
}
Outcome is the result of one conversation.
type PoC ¶
type PoC struct {
Files map[string]string `json:"files"`
Command []string `json:"command"`
Marker string `json:"marker"`
Language string `json:"language"`
Image string `json:"image"`
Explanation string `json:"explanation,omitempty"`
}
PoC is a proof of concept: files added to a copy of the target and the command that runs them inside the sandbox.
func (*PoC) SortedFiles ¶
SortedFiles returns the proof's file names in a stable order.
type ProofOutcome ¶ added in v0.2.0
type ProofOutcome int
ProofOutcome is what one run of a proof of concept showed.
const ( // ProofNotShown means the proof ran to an end and did not print its // marker: the flaw's effect was not observed. ProofNotShown ProofOutcome = iota // ProofSucceeded means the proof printed its marker and exited with // code 0: the flaw's effect was observed. ProofSucceeded // ProofInconclusive means the run shows neither: the proof timed out, // was killed, or printed its marker and then failed. A caller must not // read it as "demonstrated" and must not read it as "fixed". ProofInconclusive )
func JudgeProof ¶ added in v0.2.0
func JudgeProof(res sandbox.Result, marker string) ProofOutcome
JudgeProof decides what one run of a proof showed. It is the one rule for the prover, the debugger's reproduction, the fixer's check of a patch and spackle verify, so "demonstrated" and "fixed" mean the same everywhere.
type ProofResult ¶
type ProofResult struct {
PoC *PoC
Demonstrated bool
Output string // redacted, clipped
Isolation string
Reason string // why it was not demonstrated
Attempts int
}
ProofResult is the outcome of trying to demonstrate a finding.
func Prove ¶
func Prove(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, reg *tools.Registry, box *Box, language, image string, f finding.Finding) (ProofResult, error)
Prove asks the model for a proof of concept and runs it in the sandbox. A proof that fails is sent back once with its output. The finding counts as demonstrated only when the run exits 0 and prints the marker.
func Reproduce ¶
func Reproduce(ctx context.Context, r *Runner, parent int64, sealer *envelope.Sealer, reg *tools.Registry, box *Box, language, image, issue string) (ProofResult, error)
Reproduce asks the model for a script that reproduces the issue. Same file and command rules as proofs (validatePoC); the script prints the marker only when the buggy behavior is observed. The issue counts as reproduced only when the run exits 0 and prints the marker. A script that fails is sent back once with its output.
type Review ¶
type Review struct {
Verdict string
Reason string
// Severity is set when the reviewer supplied a valid corrected vector.
Severity *finding.Severity
}
Review is the reviewer's verdict on one finding.
type Runner ¶
type Runner struct {
Provider llm.Provider
Pricer llm.Pricer
Budget *budget.Budget
Ledger *ledger.Writer
// Stage names the pipeline stage in the ledger: planner, investigator,
// reviewer, prover, fixer or mechanical.
Stage string
// MaxTurns caps tool-use turns in one conversation.
MaxTurns int
// MaxTokens caps one completion.
MaxTokens int
}
Runner runs one stage's conversations against a provider.
func (*Runner) Run ¶
func (r *Runner) Run(ctx context.Context, parent int64, system, user string, reg *tools.Registry) (Outcome, error)
Run holds a conversation: it sends system and user, executes any tool calls through reg, and returns the model's final text. reg may be nil for a conversation with no tools. A budget error is returned as an error wrapping budget.ErrExhausted, with whatever was produced so far.