Help us shape the future of Go! Take the 2026 Go Developer Survey

revision

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package revision applies explicitly requested literal edits to pinned text. It has no model, provider, tool, semantic rewriting, or automatic fallback.

Index

Constants

View Source
const (
	Schema              = 1
	MaxRequestBytes     = 1 << 20
	MaxTextBytes        = 256 << 10
	MaxEdits            = 32
	MaxReplacementBytes = 16 << 10
	ResultPrefix        = "revision/v1/results/"
)

Variables

View Source
var (
	ErrSourceMismatch = errors.New("checked revision source hash, reference, or stored provenance does not match")
	ErrCountMismatch  = errors.New("checked revision literal occurrence count does not match")
	ErrQualityFailed  = errors.New("checked revision did not pass every declared deterministic check")
	ErrPublication    = errors.New("checked revision publication is not confirmed; output withheld")
)
View Source
var ErrInvalid = errors.New("invalid checked revision request")

Functions

func Digest

func Digest(text string) string

Digest hashes the exact UTF-8 text bytes, without normalizing whitespace, Unicode, line endings, Markdown, or JSON escaping.

func RequestDigest

func RequestDigest(request Request) (string, error)

RequestDigest returns the canonical operation identity. Accounting opt-in is excluded because it changes neither the transformation nor its predicates.

func Validate

func Validate(request Request) error

Types

type Edit

type Edit struct {
	Old             string `json:"old"`
	New             string `json:"new"`
	ExpectedMatches int    `json:"expected_matches"`
}

Edit replaces every nonoverlapping literal occurrence in the current text. Edits run in order; ExpectedMatches counts occurrences before that edit.

type Ref

type Ref struct {
	Key     string `json:"key"`
	Version int64  `json:"version"`
	SHA256  string `json:"sha256"`
}

Ref pins a revision result without duplicating its text in a response.

type Request

type Request struct {
	Schema       int                `json:"schema"`
	Task         string             `json:"task"`
	Revision     string             `json:"revision"`
	Source       Source             `json:"source"`
	Edits        []Edit             `json:"edits"`
	SourceChecks []evaluation.Check `json:"source_checks"`
	Checks       []evaluation.Check `json:"checks"`
	TrackOutcome bool               `json:"track_outcome,omitempty"`
}

Request binds a transformation and its checks to a task revision. Checks establish only their declared predicates; human acceptance is never inferred.

func Load

func Load(reader io.Reader) (Request, error)

Load rejects duplicate members, unknown/case-variant fields, invalid UTF-8, trailing data and nesting beyond 64. It validates limits before execution.

type Result

type Result struct {
	Status           string                      `json:"status"`
	RequestSHA256    string                      `json:"request_sha256,omitempty"`
	SourceSHA256     string                      `json:"source_sha256,omitempty"`
	OutputSHA256     string                      `json:"output_sha256,omitempty"`
	Text             string                      `json:"text,omitempty"`
	SourceChecks     []evaluation.CheckResult    `json:"source_checks"`
	Checks           []evaluation.CheckResult    `json:"checks"`
	Reused           bool                        `json:"reused"`
	Durable          bool                        `json:"durable"`
	Artifact         *Ref                        `json:"artifact,omitempty"`
	GenerationCalled bool                        `json:"generation_called"`
	ThisRunUsage     inference.Usage             `json:"this_run_usage"`
	ProviderCostUSD  float64                     `json:"provider_cost_usd"`
	CostBasis        string                      `json:"cost_basis"`
	ElapsedMS        float64                     `json:"elapsed_ms"`
	OutcomeTracking  *delegation.OutcomeTracking `json:"outcome_tracking,omitempty"`
}

type Runner

type Runner struct{ Broker inference.Broker }

func (Runner) Plan

func (r Runner) Plan(ctx context.Context, request Request) (result Result, runErr error)

Plan executes and checks a bounded transformation without publication or outcome registration. It reads a broker only when Source pins an artifact.

func (Runner) Run

func (r Runner) Run(ctx context.Context, request Request) (result Result, runErr error)

Run publishes once with expected version zero. Known conflicts may be read once to prove identical immutable content. Transport uncertainty never causes another publication, edit execution, model call, or disclosure of the output.

type Source

type Source struct {
	Text    *string `json:"text,omitempty"`
	Key     string  `json:"key,omitempty"`
	Version int64   `json:"version,omitempty"`
	SHA256  string  `json:"sha256"`
}

Source is either inline text or an exact immutable revision artifact. SHA256 is always the lowercase digest of the unmodified source text, not its JSON.

Jump to

Keyboard shortcuts

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