contract

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 11 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 contract turns a task's stated success criteria into checks the orchestrator runs itself. An agent's own "done" is a claim; a contract is evidence.

The package is deliberately dependency-free: it parses, enumerates, executes and evaluates, and the caller supplies the process launcher. That keeps the rules testable without a daemon and lets the core run checks through the same sandboxed executor native commands use.

Index

Constants

View Source
const (
	KindCommand  = "command"
	KindArtifact = "artifact"
)

Check kinds. A command runs a program; an artifact asserts that paths exist.

View Source
const (
	MaxChecks    = 8
	MaxArgs      = 64
	MaxRunLength = 1024
)

Limits keep a model-authored contract from becoming a workload of its own.

View Source
const (
	VerdictVerified = "verified"
	VerdictFailed   = "failed"
	VerdictPartial  = "partial"
	VerdictSkipped  = "skipped"
)

Verdict statuses. verified means every selected check ran and passed.

View Source
const (
	DefaultCheckTimeout = 10 * time.Minute
	DefaultBudget       = 30 * time.Minute
)

DefaultCheckTimeout and DefaultBudget bound one check and the whole phase. They are the operators' floor, not a model's choice: an acceptance suite that wants an hour needs an explicit configuration.

Variables

This section is empty.

Functions

func SplitCommand

func SplitCommand(line string) ([]string, error)

SplitCommand splits a command line into argv without invoking a shell. Single and double quotes group words; a backslash escapes the next rune outside single quotes when it precedes a quote, a backslash or whitespace. Any shell metacharacter outside quotes is an error.

Types

type Candidate

type Candidate struct {
	ID     string `json:"id"`
	Run    string `json:"run"`
	Source string `json:"source"`
}

Candidate is one verification entry point the project already declares. The model and the user select from this list; they never invent a command, which is what keeps the acceptance layer from becoming a new attack surface.

func Enumerate

func Enumerate(root string) []Candidate

Enumerate inspects root for verification entry points the project already declares. It reads fixed, small files and never walks the tree, so it is cheap enough to run before every ask.

type Check

type Check struct {
	ID     string   `json:"id"`
	Kind   string   `json:"kind,omitempty"`
	Run    string   `json:"run,omitempty"`
	Exists []string `json:"exists,omitempty"`
	Expect Expect   `json:"expect,omitempty"`
}

Check is one acceptance criterion. The zero Expect means "exit 0".

func Validate

func Validate(checks []Check) ([]Check, error)

Validate normalizes and checks a set of acceptance criteria. IDs are assigned when empty and must be unique when present. Commands must parse without a shell, artifact paths must stay inside the workspace.

func (Check) EffectiveKind

func (c Check) EffectiveKind() string

EffectiveKind normalizes the kind field: an empty kind is an artifact check when it lists paths and a command check otherwise.

func (Check) ExpectedExit

func (c Check) ExpectedExit() int

ExpectedExit is the exit code the check requires.

type ExecFunc

type ExecFunc func(ctx context.Context, dir string, argv []string) ExecResult

ExecFunc runs argv in dir. The core supplies one backed by its sandboxed native executor; tests supply fakes.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Duration time.Duration
	Err      error
}

ExecResult is what a process launcher returns. Err is set when the process could not be started at all; a nonzero ExitCode with Err nil is a normal failed run.

type Expect

type Expect struct {
	Exit           *int   `json:"exit,omitempty"`
	StdoutContains string `json:"stdout_contains,omitempty"`
}

Expect describes what a successful run looks like. Exit nil means 0.

type Result

type Result struct {
	Phase      string        `json:"phase"`
	CheckID    string        `json:"check_id"`
	Kind       string        `json:"kind"`
	Command    string        `json:"command,omitempty"`
	Status     Status        `json:"status"`
	ExitCode   int           `json:"exit_code"`
	DurationMS int64         `json:"duration_ms"`
	OutputHead string        `json:"output_head,omitempty"`
	OutputTail string        `json:"output_tail,omitempty"`
	Reason     string        `json:"reason,omitempty"`
	Duration   time.Duration `json:"-"`
}

Result is one check's outcome, ready to persist and render.

type Runner

type Runner struct {
	Dir        string
	Timeout    time.Duration // per check; 0 = DefaultCheckTimeout
	Budget     time.Duration // whole phase; 0 = DefaultBudget, negative = unbounded
	Exec       ExecFunc
	RetryFlaky bool
	Now        func() time.Time
	// Guard may refuse a command before it runs. The core uses it to keep
	// irreversible commands out of acceptance checks: a contract is evidence,
	// not a second, ungated way to execute. A refused check is recorded as
	// skipped with the reason, never as a failure of the work.
	Guard func(argv []string) error
}

Runner executes checks in one directory. The zero value is usable for artifact checks; command checks need Exec.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, phase string, checks []Check) []Result

Run executes checks and returns one Result per check, in order.

type Status

type Status string

Status is the outcome of one check.

const (
	StatusPass    Status = "pass"
	StatusFail    Status = "fail"
	StatusError   Status = "error"   // the check could not run (launch failure)
	StatusSkipped Status = "skipped" // budget exhausted before it ran
	StatusFlaky   Status = "flaky"   // failed, then passed on a single retry
)

type Verdict

type Verdict struct {
	Status      string   `json:"status"`
	Passed      []string `json:"passed,omitempty"`
	Failed      []string `json:"failed,omitempty"`
	Regressions []string `json:"regressions,omitempty"`
	PreExisting []string `json:"pre_existing,omitempty"`
	Skipped     []string `json:"skipped,omitempty"`
	Flaky       []string `json:"flaky,omitempty"`
	Reasons     []string `json:"reasons,omitempty"`
}

Verdict is the combined judgment of a contract. It is computed from the baseline and final results, and it names the checks by id so every renderer can phrase them in its own language.

func Evaluate

func Evaluate(checks []Check, baseline, final []Result) Verdict

Evaluate compares the final results against the baseline. A check that fails after passing at baseline is named a regression; one that was already failing is named as pre-existing. Either way the contract is not verified: the baseline explains the failure, it does not excuse it.

Jump to

Keyboard shortcuts

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