validate

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package validate checks the artifacts a /plan session produces against a machine-readable contract.

Before it, the only check on a whole plan was a single os.Stat on PROMPT.md (internal/tui/plan.go). Everything else the PDD SOP asks for — an outline, slices that name their files and verify command, gates that actually run, Done Criteria that are not template placeholders — was prose the model could decline. Across 53 spec directories, 3 had a complete artifact set and outline.md was missing from 70%.

A rule here returns Findings rather than a bool, because a Finding is fed back to the agent that produced the artifact: Message says what is wrong and Fix says what to do about it.

Index

Constants

View Source
const ManifestName = ".sop-manifest.json"

ManifestName duplicates sop.ManifestName for the same reason.

Variables

This section is empty.

Functions

func Register

func Register(name string, r Rule)

Register adds a rule under name. It panics on a duplicate: a silently shadowed rule would validate nothing while appearing to pass.

func RuleNames

func RuleNames() []string

RuleNames lists every registered rule.

Types

type Args

type Args struct {
	Positional []string
	List       []string
	Named      map[string]string
}

Args holds a rule invocation's arguments. The three shapes cover every rule the SOP schema needs: `max_lines(2000)`, `has_headings(["A","B"])`, and `slice_budget(max_files: 10, max_changed_lines: 400)`.

func ParseRule

func ParseRule(spec string) (string, Args, error)

ParseRule splits a rule spec such as `slice_budget(max_files: 10)` into its name and arguments.

func (Args) Bool

func (a Args) Bool(name string, def bool) bool

Bool returns the named boolean argument, or def.

func (Args) Int

func (a Args) Int(name string, def int) int

Int returns the named argument, or the first positional one when name is empty or absent, falling back to def.

func (Args) Items

func (a Args) Items() []string

Items returns the list argument, falling back to the positional strings.

type ArtifactContract

type ArtifactContract struct {
	Artifact string   `json:"artifact"`
	Required bool     `json:"required"`
	Rules    []string `json:"rules"`
}

ArtifactContract binds an artifact to the rules it must satisfy.

type Contract

type Contract struct {
	Name      string             `json:"name"`
	Artifacts []ArtifactContract `json:"artifacts"`
}

Contract is the full set of checks for one gate in the pipeline.

func PlanContract

func PlanContract() Contract

PlanContract is what a finished /plan session must satisfy. It is the prose PDD SOP's own rules, made checkable: every phase produces its artifact, the plan's slices are sized and self-describing, and PROMPT.md carries gates and Done Criteria that are real rather than template text.

func RunPreflightContract

func RunPreflightContract() Contract

RunPreflightContract is what /run requires before it will start. It is deliberately narrower than PlanContract: a spec written by hand, or planned under an older SOP, should still run if the two artifacts a run actually consumes are sound.

func (Contract) Describe

func (c Contract) Describe() string

Describe renders the contract as instruction text for the agent that must satisfy it.

This is the half that makes validation a loop rather than a gate: the planner is told the exact rules its artifacts are checked against, in the same session where the findings come back. A contract the producer cannot see is just a way to fail late.

type Finding

type Finding struct {
	Artifact string   `json:"artifact"`
	Rule     string   `json:"rule"`
	Severity Severity `json:"severity"`
	Line     int      `json:"line,omitempty"`
	Message  string   `json:"message"`
	Fix      string   `json:"fix,omitempty"`
}

Finding is one rule violation.

func (Finding) String

func (f Finding) String() string

type Findings

type Findings []Finding

Findings is a rule result set.

func Apply

func Apply(spec string, t Target) Findings

Apply runs one rule spec against a target.

func Check

func Check(spec *specdoc.Spec, repoRoot string, c Contract) Findings

Check runs a contract over a loaded spec. repoRoot is the checkout the spec lives in; rules that resolve paths or probe commands need it, and pass when it is empty.

func (Findings) Errors

func (fs Findings) Errors() Findings

Errors returns only the blocking findings.

func (Findings) Format

func (fs Findings) Format() string

Format renders findings as a Markdown list, errors first.

func (Findings) OK

func (fs Findings) OK() bool

OK reports whether nothing blocking was found.

type Rule

type Rule func(Target, Args) Findings

Rule checks one property of a Target.

func Lookup

func Lookup(name string) (Rule, bool)

Lookup returns the rule registered under name.

type Severity

type Severity string

Severity distinguishes a finding that blocks the pipeline from one that is only worth saying.

const (
	// SeverityError blocks: /plan will not finish and /run will not start.
	SeverityError Severity = "error"
	// SeverityWarn is reported and recorded but blocks nothing.
	SeverityWarn Severity = "warn"
)

type Target

type Target struct {
	Artifact string // "plan.md"
	Content  string
	Spec     *specdoc.Spec
	RepoRoot string // for rules that resolve paths or probe commands
}

Target is what a rule is asked about: one artifact, plus the spec it belongs to so cross-artifact rules can reach its siblings.

Jump to

Keyboard shortcuts

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