envelope

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 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 = 1

Version is the current envelope schema version.

Variables

This section is empty.

Functions

This section is empty.

Types

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 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"
	OutcomeBundleTooLarge Outcome = "bundle_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; BundleB64 is the
	// base64-encoded git bundle of default..branch.
	Branch    string `json:"branch,omitempty"`
	BundleB64 string `json:"bundle_b64,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