patch

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package patch repairs a devbay manifest using Claude.

This is the one place in devbay where a model runs. It sits behind verify.Patcher, which is the only seam the execution plane exposes to the authoring plane, and it is deliberately small: given the manifest that just failed and the evidence of how it failed, return a revised manifest.

Why a model at all

The deterministic detector reaches a useful majority of repositories and stops. What it cannot do is read an error message. "connection refused on 5432" plus "the api service starts before db is ready" is a two-line fix that no rule table will ever contain, because the space of ways an application can fail to start is not enumerable. That is the job here, and it is the whole job -- this package proposes text, and nothing else.

What it is not trusted with

Everything it returns crosses verify's airlock before anything executes it: strict parse, full validation, and unconditional removal of `egress:`. That ordering is the design. A patcher reads the error output of code from the repository, which is exactly the material an attacker can influence, so the question is never whether the model can be persuaded to write something hostile -- it is whether writing it would achieve anything. It does not.

What never reaches it

HC1: a secret must not enter model context. Container logs are the most likely carrier, since an application will happily print its own configuration, so every byte of evidence passes through a scrubber before it is put in a message -- known values first, credential shapes second.

Local-first

devbay makes no network calls except image registries, a manifest's declared egress, and this. The API key lives in the daemon on the host and is never injected into a bay, and the model is off unless the developer turns it on.

Index

Constants

View Source
const (
	DefaultModel     = anthropic.ModelClaudeOpus5
	DefaultEffort    = anthropic.OutputConfigEffortHigh
	DefaultMaxTokens = 16000
)

Defaults. The model is the current Opus because this is a correctness task on a small input where a wrong answer costs a boot cycle and a confused developer; effort is high rather than xhigh because the task is narrow -- read one failure, change a few lines -- and the extra depth buys nothing an extra attempt would not.

Variables

View Source
var ErrDisabled = errors.New("no model is configured")

ErrDisabled is returned by FromEnv when no model is configured.

Functions

This section is empty.

Types

type Claude

type Claude struct {

	// Model, Effort and MaxTokens are the request knobs, defaulted by New.
	Model     string
	Effort    anthropic.OutputConfigEffort
	MaxTokens int64

	// Scrub removes known secret values from evidence. Shape-based scrubbing
	// happens regardless; this adds the values the broker actually resolved,
	// which is the one thing a pattern matcher cannot know.
	Scrub *scrub.Scrubber

	// Log receives one line per attempt, including the model's own account of
	// what it changed. The developer is going to read the resulting file, so
	// they should be able to see how it got that way.
	Log func(format string, args ...any)
	// contains filtered or unexported fields
}

Claude proposes manifest revisions.

The zero value is not usable; call New.

func FromEnv

func FromEnv(opts ...Option) (*Claude, error)

FromEnv builds a patcher when the developer has asked for one, and returns ErrDisabled otherwise.

Opt-in rather than automatic. `devbay init` on a fresh repository should not silently make a network call to a third party and bill someone for it; a tool that runs entirely on your machine except for the times it doesn't is not a tool that runs entirely on your machine. DEVBAY_NO_MODEL turns it off again for a CI run or an airgapped machine that happens to have a key in the environment.

func New

func New(opts ...Option) *Claude

New builds a patcher.

func (*Claude) Calls

func (c *Claude) Calls() int

Calls reports how many requests have been made.

func (*Claude) Patch

func (c *Claude) Patch(ctx context.Context, current []byte, f verify.Failure) ([]byte, error)

Patch implements verify.Patcher.

type Option

type Option func(*Claude) []option.RequestOption

Option configures a Claude patcher.

func WithAPIKey

func WithAPIKey(k string) Option

WithAPIKey sets the key explicitly rather than taking it from the environment. Used by tests.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL points the client at another endpoint. Used by tests.

func WithEffort

func WithEffort(e anthropic.OutputConfigEffort) Option

WithEffort overrides the effort level.

func WithLog

func WithLog(f func(string, ...any)) Option

WithLog attaches a progress logger.

func WithModel

func WithModel(m string) Option

WithModel overrides the model.

func WithScrubber

func WithScrubber(s *scrub.Scrubber) Option

WithScrubber attaches the broker's scrubber, so values devbay itself handed to the containers are removed from evidence by value rather than by shape.

Jump to

Keyboard shortcuts

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