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 ¶
const ( KindCommand = "command" KindArtifact = "artifact" )
Check kinds. A command runs a program; an artifact asserts that paths exist.
const ( MaxChecks = 8 MaxArgs = 64 MaxRunLength = 1024 )
Limits keep a model-authored contract from becoming a workload of its own.
const ( VerdictVerified = "verified" VerdictFailed = "failed" VerdictPartial = "partial" VerdictSkipped = "skipped" VerdictUnverified = "unverified" )
Verdict statuses. verified means every selected check ran and passed. unverified is the honest label for an agent run that had neither a supervisor nor a delivery contract: the work may well be fine, but nothing checked it, so the row must not read like a verified one.
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 ¶
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.
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 ¶
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 ¶
EffectiveKind normalizes the kind field: an empty kind is an artifact check when it lists paths and a command check otherwise.
func (Check) ExpectedExit ¶
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.
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.