envelope

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 4 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 envelope is the versioned event contract between agent-runner and the remediation-controller: one JSON event per line on the runner's stdout, prefixed so it survives interleaving with any other output. The controller follows the pod log live (issue updates land between the classification and remediation stages of one pod) and re-reads the full log at Job completion as the fallback — events are self-contained and idempotent to re-apply.

Index

Constants

View Source
const Prefix = "PATCHY-EVENT: "

Prefix marks an event line on the agent-runner's stdout.

View Source
const Version = 2

Version is the current envelope schema version. Version 2 replaced the git-bundle payload with the structured Changeset.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changeset added in v0.3.0

type Changeset struct {
	// BaseSHA is the commit the clone was pinned to; 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"`
}

Changeset expresses the agent's committed change as file contents so the controller can push it through the GitHub API without git.

type Classification

type Classification struct {
	Stage
	ReportMarkdown string  `json:"report_markdown,omitempty"`
	Recommendation string  `json:"recommendation,omitempty"`
	Priority       string  `json:"priority,omitempty"`
	Severity       string  `json:"severity,omitempty"`
	Confidence     float64 `json:"confidence,omitempty"`
	// RemediationModel/MaxTurns/TokenBudget are the CLAMPED stage-2
	// parameters (allowlist and ceilings applied), not the raw suggestion.
	RemediationModel string `json:"remediation_model,omitempty"`
	MaxTurns         int    `json:"max_turns,omitempty"`
	TokenBudget      int    `json:"token_budget,omitempty"`
	// WillRemediate is the runner's local decision to continue to stage 2.
	WillRemediate bool `json:"will_remediate"`
	// AwaitApproval marks the breaking-change hold (a better-but-breaking
	// fix exists): remediation waits for a human /approve.
	AwaitApproval bool `json:"await_approval"`
}

Classification is the stage-1 event payload.

type Event

type Event struct {
	V    int  `json:"v"`
	Type Type `json:"type"`
	// Issue context so events are self-contained.
	Repo  string `json:"repo"`
	Issue int    `json:"issue"`

	Classification *Classification `json:"classification,omitempty"`
	Remediation    *Remediation    `json:"remediation,omitempty"`
	// Error is set on fatal events.
	Error string `json:"error,omitempty"`
}

Event is one envelope line.

func Decode

func Decode(line []byte) (Event, bool)

Decode recovers an event from one log line; ok is false for any line that is not an envelope event.

func (Event) Encode

func (e Event) Encode() (string, error)

Encode renders the event as one stdout line (prefix included, newline excluded).

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 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 Type

type Type string

Type discriminates events.

const (
	TypeClassification Type = "classification"
	TypeRemediation    Type = "remediation"
	TypeFatal          Type = "fatal"
)

The event types: one per completed stage, plus fatal for a runner that could not produce a stage result at all.

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).

Jump to

Keyboard shortcuts

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