Documentation
¶
Overview ¶
Package envelope is the versioned event contract between agent-runner and the job controllers: one JSON event per line on the runner's stdout, prefixed so it survives interleaving with any other output. The owning controller reads the full log once at Job completion. Events are self-contained and idempotent to re-apply.
Index ¶
Constants ¶
const Prefix = "PATCHY-EVENT: "
Prefix marks an event line on the agent-runner's stdout.
const Version = 4
Version is the current envelope schema version. Decode rejects every other version. Version 2 replaced the git-bundle payload with the structured Changeset. Version 3 added the investigation event and keyed events by finding name. Version 4 replaced the investigation's max_turns and token_budget with the unclamped estimated_max_turns/estimated_token_budget and added hold_reasons beside await_approval.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalysisResult ¶ added in v0.4.0
type AnalysisResult struct {
// Rating is none|low|medium|high|critical.
Rating string `json:"rating"`
// Summary is the agent's short justification.
Summary string `json:"summary,omitempty"`
}
AnalysisResult is one investigation dimension: a rating plus a short justification (the full reasoning lives in the report markdown).
type Changeset ¶ added in v0.3.0
type Changeset struct {
// BaseSHA is the remote commit the workspace was pinned to, and the
// pushed commit's parent.
BaseSHA string `json:"base_sha"`
// CommitMessage carries the agent's commit message(s); multiple local
// commits squash into one API commit.
CommitMessage string `json:"commit_message"`
Upserts []FileChange `json:"upserts,omitempty"`
Deletes []string `json:"deletes,omitempty"`
// Patch is base..branch as `git format-patch --binary --stdout`: a
// human-readable, `git am`-able rendering of the same change, kept only
// for the run archive. It never drives the push. Empty when the runner
// predates it or when adding it would have exceeded the changeset cap,
// which is spent on the pushable content first. Older controllers
// ignore it.
Patch string `json:"patch,omitempty"`
}
Changeset expresses the agent's committed change as file contents so the controller can push it through the GitHub API without git.
type Event ¶
type Event struct {
V int `json:"v"`
Type Type `json:"type"`
// Repo carries the finding's repository so events are self-contained.
Repo string `json:"repo"`
// Finding names the owning Finding resource.
Finding string `json:"finding,omitempty"`
Investigation *Investigation `json:"investigation,omitempty"`
Remediation *Remediation `json:"remediation,omitempty"`
// Error is set on fatal events.
Error string `json:"error,omitempty"`
}
Event is one envelope line.
type FileChange ¶ added in v0.3.0
type FileChange struct {
Path string `json:"path"`
// Mode is the git file mode: "100644", "100755", or "120000".
Mode string `json:"mode"`
// ContentB64 is the base64-encoded blob; for a symlink ("120000") it is
// the encoded link target.
ContentB64 string `json:"content_b64"`
}
FileChange is one file created or modified on the remediation branch.
type HoldReason ¶ added in v0.8.0
type HoldReason string
HoldReason names why a remediate verdict must wait for a human. It mirrors v1alpha1.HoldReason; the controller maps one onto the other.
const ( HoldBreakingChangeAvailable HoldReason = "breakingChangeAvailable" HoldExceedsAutomatedTurns HoldReason = "exceedsAutomatedTurns" HoldExceedsAutomatedTokens HoldReason = "exceedsAutomatedTokens" )
Approval-hold reasons the runner can raise. Low confidence is absent because the controller owns that threshold, not the pod.
type Investigation ¶ added in v0.4.0
type Investigation struct {
Stage
ReportMarkdown string `json:"report_markdown,omitempty"`
Exploitability AnalysisResult `json:"exploitability"`
Likelihood AnalysisResult `json:"likelihood"`
Impact AnalysisResult `json:"impact"`
Recommendation string `json:"recommendation,omitempty"`
// DismissReason is the agent's reason for an ignore verdict
// (false_positive, used_in_tests, wont_fix); empty otherwise.
DismissReason string `json:"dismiss_reason,omitempty"`
Priority string `json:"priority,omitempty"`
Severity string `json:"severity,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
// RemediationModel is the stage-2 model the analysis suggested; the
// controller clamps it to the allowlist before launching the job.
RemediationModel string `json:"remediation_model,omitempty"`
// EstimatedMaxTurns/EstimatedTokenBudget are the analysis's prediction of
// what the fix will cost, reported verbatim. They never bind the
// remediation, which runs on the grant the controller resolves. They are
// never clamped, because the approval gate and the calibration averages
// both read the raw prediction.
EstimatedMaxTurns int `json:"estimated_max_turns,omitempty"`
EstimatedTokenBudget int `json:"estimated_token_budget,omitempty"`
// AwaitApproval marks an approval hold; HoldReasons says why.
AwaitApproval bool `json:"await_approval"`
HoldReasons []HoldReason `json:"hold_reasons,omitempty"`
}
Investigation is the analysis-stage event payload (version 4): the agent's exploitability, likelihood, and impact assessments plus its verdict. The runner never decides continuation; the controller routes on the verdict.
type Outcome ¶
type Outcome string
Outcome describes how a stage ended.
const ( OutcomeOK Outcome = "ok" OutcomeRuntimeError Outcome = "runtime_error" OutcomeTimeout Outcome = "timeout" OutcomeBudgetExceeded Outcome = "budget_exceeded" OutcomeReportMissing Outcome = "report_missing" OutcomeReportInvalid Outcome = "report_invalid" OutcomeCommitFailed Outcome = "commit_failed" OutcomeChangesetTooLarge Outcome = "changeset_too_large" )
Stage outcomes. Only OutcomeOK carries a trusted report; every other outcome routes the issue to humans.
type Remediation ¶
type Remediation struct {
Stage
ReportMarkdown string `json:"report_markdown,omitempty"`
Success bool `json:"success"`
Confidence float64 `json:"confidence,omitempty"`
// Branch is the local branch carrying the fix; Changeset is its content
// diffed against Changeset.BaseSHA.
Branch string `json:"branch,omitempty"`
Changeset *Changeset `json:"changeset,omitempty"`
}
Remediation is the stage-2 event payload.
type Stage ¶
type Stage struct {
Outcome Outcome `json:"outcome"`
Harness string `json:"harness"`
Model string `json:"model"`
SessionID string `json:"session_id,omitempty"`
NumTurns int `json:"num_turns,omitempty"`
Usage Usage `json:"usage"`
ElapsedSeconds float64 `json:"elapsed_seconds"`
// Detail explains a non-ok outcome for humans.
Detail string `json:"detail,omitempty"`
}
Stage carries what every stage reports regardless of kind.
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheReadTokens int `json:"cache_read_tokens"`
CacheCreationTokens int `json:"cache_creation_tokens"`
CostUSD float64 `json:"cost_usd"`
}
Usage is the stage's agent accounting (all fields concrete: the envelope reports what was measured, zeros where the harness didn't say).