cardcontract

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cardcontract is the frame around a card's task (docs/SPEC-CARD-CONTRACT.md): the frame the member hands native (Frame), the result shape a child ends with (Result), and the profiles, keyed by model family, that write JOB.md and the shims first on the child's PATH so the child meets the frame through the commands it already knows.

Index

Constants

View Source
const (
	CarryNone     = "none"     // no earlier attempt pushed: the checkout is the tip
	CarryOK       = "carried"  // the earlier work applied cleanly: the checkout is the tip and that work
	CarryHeld     = "held"     // the tip already holds the earlier work: the checkout is the tip
	CarryConflict = "conflict" // the earlier work did not apply cleanly: the checkout is the bare tip
)

The states of a carry.

View Source
const BrokenFindingText = "" /* 343-byte string literal not displayed */

BrokenFindingText is what every profile's read JOB.md says of a broken verdict (docs/SPEC-CARD-CONTRACT.md section 3): it names the defect, or it is no verdict.

View Source
const CarryLinePrefix = "STAGE CARRY "

CarryLinePrefix begins native's one line about a rework's carry, which the member reads from native's log into the finish's report, so the card's timeline says where the attempt was staged and whether the work before it came with it.

View Source
const FinishName = ".sprint/finish.md"

FinishName is the file in the job directory the gh shim records the finish in (gh pr create, gh pr review), in the result shape: a file the child is never told to write, so a RESULT.md the child writes after it does not overwrite it.

View Source
const FrameName = ".frame.json"

FrameName is the file name the member writes a frame under, beside the card file.

View Source
const JobName = "JOB.md"

JobName is the frame's text in the job directory, the first thing the child reads.

View Source
const PushedName = ".sprint/pushed.tsv"

PushedName is the file in the job directory the git shim records each push in: branch, head and checkout top, tab separated, one line a push.

View Source
const ReadTitle = "# JOB: read"

ReadTitle begins the first line of a read's JOB.md in every profile, and of no work's: a brief that speaks to its readers names it, so a work card never takes itself for a read and stops with nothing to do.

View Source
const RecipesName = "recipes"

RecipesName is the directory recipes are kept in, in the member's root, and staged into, in the job directory.

View Source
const StagedName = "staged"

StagedName is the file in the slot directory (outside the job, which the wall lets the child write) where native records the commit it staged, the one the member counts the child's commits from.

Variables

View Source
var Families = []string{"claude", "openai", "gemini", "grok", "deepseek", "plain"}

Families are the model families a profile is keyed by, plain last: the fallback.

Functions

func FamilyOf

func FamilyOf(model string) string

FamilyOf is the family of a model id: the first family word it carries, else plain.

func Install

func Install(p Profile, f Frame, s Staged, shimDir string) error

Install writes JOB.md into the job directory and the profile's shims into shimDir.

func IsFinish

func IsFinish(job string, raw []byte) bool

IsFinish is whether raw is the finish the gh shim recorded in the job, byte for byte: native publishes that record as the card's result when the child wrote no RESULT.md.

func LastPushed

func LastPushed(job string) (branch, head string)

LastPushed is the last head the git shim recorded in the job directory, "" when none.

func ParseCarryLine

func ParseCarryLine(log []byte) string

ParseCarryLine is the words of the last carry line in native's log, "" when it has none.

func Prompt

func Prompt(job, card string) string

Prompt is the harness prompt of a framed card: JOB.md first, then the card.

func ReadFinish

func ReadFinish(job string) (typedrec.CardResult, bool)

ReadFinish is the finish the gh shim recorded in the job directory, and whether there is one (an empty file is none).

func ShapeText

func ShapeText(kind string) string

ShapeText is the result shape as JOB.md quotes it, for a work card or a read.

func StageRecipes

func StageRecipes(f Frame, job string) error

StageRecipes copies the recipe files a frame names from the member's recipes directory into <job>/recipes, each at its own relative path (docs/SPEC-CARD-CONTRACT.md, staged recipes): a brief holds 16 KiB, a recipe a card works from can be larger, and the wall gives the child no forge to fetch one from. A name that is not a local relative path, or is not a regular file in the recipes directory, refuses the whole staging; every source is opened through an os.Root of the recipes directory, so no path component, a symlinked directory included, leaves it, and a refusal names the Stage line and the reason.

func WriteFrame

func WriteFrame(path string, f Frame) error

WriteFrame writes a frame as JSON at path.

Types

type Carry

type Carry struct {
	Base   string // the base branch
	Tip    string // its tip on origin when the checkout was staged, a full sha
	Prev   string // the head carried: the last pushed head of any earlier attempt; "" when none pushed
	From   int    // the attempt Prev is the head of
	Staged string // the commit the checkout is at, the one the finish counts from
	State  string // CarryNone, CarryOK, CarryHeld or CarryConflict
}

Carry is how a rework's checkout was staged (docs/SPEC-CARD-CONTRACT.md, where a rework starts): at the tip of its base branch as staging found it on origin, with the work of the attempt whose head it continues carried on top when that work applies cleanly there. A rework staged at an earlier attempt's head instead stayed on a base hours old, and a fix that said to start again from the tip could not be obeyed: the finish refuses a head that does not descend from the staged commit (nova-tools#5215).

func (Carry) Line

func (c Carry) Line() string

Line is native's line about the carry: CarryLinePrefix, then its words (Words).

func (Carry) Words

func (c Carry) Words() string

Words are the carry in one line of key=value words: the staged commit, the tip and its branch, and the state, with the attempt carried when there was one.

type Frame

type Frame struct {
	Kind       string   `json:"kind"` // work or read
	Card       string   `json:"card"`
	Attempt    int      `json:"attempt"`
	Tier       string   `json:"tier,omitempty"`
	Model      string   `json:"model"`
	Repo       string   `json:"repo"`                   // the clone URL or local path the card works in; "" when it names none
	BaseRef    string   `json:"base_ref,omitempty"`     // the ref the card's work is based on (a pull request's base)
	StageSha   string   `json:"stage_sha,omitempty"`    // the commit staged: a previous attempt's pushed head, a read's head under read, else the card's base sha
	Branch     string   `json:"branch"`                 // the branch the checkout is on: the card's sprint branch, a read's work branch
	PrevHead   string   `json:"prev_head,omitempty"`    // the last pushed head of any earlier attempt (sprint.BaseOf)
	PrevFrom   int      `json:"prev_attempt,omitempty"` // the attempt PrevHead is the head of
	Why        string   `json:"why,omitempty"`          // a rework: how the attempt before ended
	Finding    string   `json:"finding,omitempty"`      // a rework: what the readers of the attempt before found
	Fix        string   `json:"fix,omitempty"`          // a rework: what the coordinator asks of this attempt
	ReviewBase string   `json:"review_base,omitempty"`  // a read: the ref the change is reviewed against
	Stage      []string `json:"stage,omitempty"`        // the recipe files the brief's Stage: header lines name, relative to Recipes
	Recipes    string   `json:"recipes,omitempty"`      // the member's recipes directory, <root>/recipes
	// A decide read's bars on p(defect) (docs/SPEC-SPRINT.md section 6): native asks the
	// read decision over the card and the diff before any child and routes the read by
	// them; both empty for a strings read.
	DecideBounce string `json:"decide_bounce,omitempty"`
	DecideReview string `json:"decide_review,omitempty"`
	// A work card's gate decision bars (docs/SPEC-SPRINT.md section 5, the gate verdict):
	// native classifies a red gate's failures by them after the child, before the member
	// reports the take; both empty for none.
	DecideGateFlaky       string `json:"decide_gate_flaky,omitempty"`
	DecideGatePreexisting string `json:"decide_gate_preexisting,omitempty"`
}

Frame is what the member knows of one launch and hands native as a file: the repository and the commit to stage, the branch the checkout is on (and the member pushes), the attempt, what the attempt before left, the tier and the model. It is the packet's, never the brief's prose.

func ReadFrame

func ReadFrame(path string) (Frame, error)

ReadFrame reads the frame at path; a frame with no kind or no card is refused.

type Gate

type Gate struct {
	Packages []string // ./dir, sorted
	Runs     []GateRun
	Module   bool
}

Gate is a read's gate: the packages it vets and tests whole, the class-test packages it runs some tests of, and whether go.mod or go.sum changed (the whole module is built).

func ReadGate

func ReadGate(repo string, changed []string) (*Gate, error)

ReadGate is the gate of a read whose diff changed these files (repository-relative, slash separated) in the checkout at repo. A checkout with no go.mod has none (nil): the card's gate stands.

type GateRun

type GateRun struct {
	Pkg   string   // ./dir
	Tests []string // the Test functions it runs, sorted
}

GateRun is a package a read runs only some tests of: one CI runs whole on every change.

type Profile

type Profile interface {
	Family() string
	JobText(f Frame, s Staged) string
	Shims(f Frame, s Staged) []Shim
}

Profile is how one model family meets the frame (docs/SPEC-CARD-CONTRACT.md section 5).

func For

func For(family string) Profile

For is the profile of a family: its own, else plain under the family's name.

type Shim

type Shim struct {
	Name   string // the command it answers for: git, gh
	Script string // a POSIX sh script
}

Shim is one script a profile writes first on the child's PATH.

func ContractShim

func ContractShim(family string, f Frame, s Staged) Shim

ContractShim is the git every profile may reuse: push recorded, everything else real.

type Staged

type Staged struct {
	Job  string // <slot>/jobs/<label>
	Repo string // <job>/repo
	Head string // the full sha the checkout is at
	Git  string // the real git, absolute
	// Start is a read's: the commit the work under review started from, a full sha (the
	// merge base of Head and the review base, found when the checkout was staged), so the
	// read sees exactly the work's change however far the base branch has moved since;
	// "" for work, or when no merge base was found.
	Start   string
	GoCache string // the machine's shared build cache the child's GOCACHE names; "" when it has none
	Gate    *Gate  // a read's gate (ReadGate); nil: the card's
	// Carry is a rework's staging at the tip of its base branch (Carry); nil for a first
	// attempt, a read, and a rework whose base is a sha or a tag, which never moves.
	Carry *Carry
}

Staged is what native knows once the checkout is staged: the job directory, the checkout, the commit it is at, and the real git the shims hand through to.

Jump to

Keyboard shortcuts

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