agentrun

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 26 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 agentrun orchestrates the coding-agent stage inside the Job pod: render the prompt, drive the harness under a token-budget kill switch, and report the stage as an envelope event on stdout. The investigate phase runs the analysis and emits the verdict without ever deciding continuation; the remediate phase executes a controller-provided analysis, then verifies and packages the resulting changeset.

The runner trusts the repository over the agent: a remediation report claiming success is downgraded unless commit.sh ran cleanly and left real commits on the branch. It never talks to a forge: the pod holds no forge credential, and the controllers own every side effect.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent drives the stages.

func New

func New(cfg Config, exec Executor) *Agent

New builds an Agent.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run executes the configured phase. It returns an error only for fatal, before-any-stage failures (also emitted as a fatal event). Stage outcomes, including failed stages, are envelope events with a nil return, so the controller, not the Job status, routes the issue.

type Config

type Config struct {
	Workspace string
	Repo      string
	// Finding names the owning Finding resource; events echo it so the
	// controller can key them.
	Finding string
	// BaseSHA is the remote commit the workspace tree corresponds to. The
	// local git base is a synthetic commit over the artifact tarball, so the
	// changeset's push base must come from here instead.
	BaseSHA string
	Phase   Phase

	// InvestigateHarness/RemediateHarness are the harness ids the stages run
	// on, resolved controller-side from the stage model and passed per-Job.
	InvestigateHarness string
	RemediateHarness   string
	// InvestigateModel/RemediateModel are canonical provider-qualified model
	// ids (e.g. "anthropic/claude-sonnet-5"). The controller resolves the
	// harness and clamps the remediation model to the allowlist before the
	// Job is created, so these already match the runner image the pod is in.
	InvestigateModel string
	RemediateModel   string
	// ModelAllowlist is the canonical model ids the investigation may suggest
	// for remediation; rendered into the analysis prompt.
	ModelAllowlist []string
	// BrokerTokenFile is the projected ServiceAccount token file the pod
	// authenticates to the egress broker with; empty on a non-brokered run.
	// It is read fresh per stage because the kubelet rotates the projection.
	BrokerTokenFile string
	// CodexConfig is the config.toml a brokered codex run writes to
	// CodexHome before each stage (provider.CodexConfig, carried as
	// PATCHY_CODEX_CONFIG); empty on claude and non-brokered runs.
	CodexConfig string
	// CodexHome is where the codex CLI reads config.toml from:
	// $CODEX_HOME, else $HOME/.codex (the CLI's own resolution).
	CodexHome string
	// ModelMap translates canonical model ids to the provider-specific CLI
	// ids a brokered provider expects (Bedrock inference profiles, Foundry
	// deployment names); consulted before the registry in cliModel.
	ModelMap map[string]string

	// The investigation stage's limits are absolute: it runs on exactly
	// these.
	InvestigateMaxTurns    int
	InvestigateTokenBudget int

	// The remediation budget, split by who authorized the run.
	//
	// RemediateAutoMaxTurns/RemediateAutoTokenBudget is what patchy will spend
	// unattended: every remediation gets at least this, whatever the
	// investigation predicted (including when it predicted nothing). It is
	// also the line past which a fix stops being automatic: an estimate above
	// it holds the finding for a human instead of queueing it.
	RemediateAutoMaxTurns    int
	RemediateAutoTokenBudget int
	// RemediateManualMaxTurns/RemediateManualTokenBudget is the most a
	// human-approved run may spend. Approving an over-auto estimate grants
	// that estimate, so this bounds what one approval can authorize.
	RemediateManualMaxTurns    int
	RemediateManualTokenBudget int
	// GrantedMaxTurns/GrantedTokenBudget are what the controller granted this
	// run, already resolved against the estimate and the manual bound. Zero
	// means "no per-run grant" and falls back to the automated budget.
	GrantedMaxTurns    int
	GrantedTokenBudget int

	// Calibration is how previous remediations in this repository actually
	// compared to their estimates, rendered into the investigation prompt so
	// its next estimate can correct for the observed skew. Nil on a cold
	// start, and the prompt then omits the section entirely.
	Calibration *templates.Calibration

	InvestigateTimeout time.Duration
	RemediateTimeout   time.Duration

	// ChangesetMaxBytes caps the cumulative raw content of the changeset the
	// remediation stage may emit.
	ChangesetMaxBytes int

	// The Transcript* fields bound the conversation the recorder streams to
	// stdout, which is what a live viewer sees. They are stream limits, not
	// storage limits: the controller compacts the persisted record to fit its
	// ConfigMap independently (transcript.Compact). Zero takes the transcript
	// package's stream default (for MaxTurns, unbounded) and negative disables
	// that bound.
	TranscriptMaxTurnBytes  int
	TranscriptMaxTurns      int
	TranscriptMaxTotalBytes int

	// Out receives the envelope events and transcript turns (stdout in the pod).
	Out io.Writer
	Log *slog.Logger
}

Config is the runner's configuration; in the pod every field arrives as PATCHY_* environment (see FromEnv).

func FromEnv

func FromEnv(getenv func(string) string) (Config, error)

FromEnv builds the pod configuration from PATCHY_* environment variables, applying defaults.

type Executor

type Executor interface {
	Run(ctx context.Context, spec runner.CommandSpec, timeout time.Duration,
		onLine func([]byte) (bool, string)) (runner.Result, error)
}

Executor runs harness command specs; *runner.Exec satisfies it, tests fake it.

type Phase

type Phase string

Phase selects which stage runs.

const (
	PhaseInvestigate Phase = "investigate"
	PhaseRemediate   Phase = "remediate"
)

PhaseInvestigate runs the analysis stage only; PhaseRemediate remediates from a controller-provided analysis file.

Jump to

Keyboard shortcuts

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