stack

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 27 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 stack is how a task branch stands on its base: the branch index, the After: base, base code checks, the catchup engine and verify runs.

Index

Constants

View Source
const (
	FoundLanded  = string(branchmeta.Landed)
	FoundAfter   = string(branchmeta.AfterBranch)
	FoundGone    = string(branchmeta.AfterBranch) + " gone"
	FoundDefault = "default branch"
)

What a base was found through, in the step's words.

View Source
const (
	CodeYes  = "yes"
	CodeNone = "none"
)

The code row's values.

View Source
const (
	MethodMerge  = "merge"
	MethodRebase = "rebase"
	MethodOnto   = "onto"
	MethodNone   = "none"
	MethodSkip   = "skip"
)

Methods besides merge and rebase: none has nothing to bring in, skip is a guard with nothing to do.

View Source
const (
	// DivergeFail refuses: a local landing would fold one side's commits into the other.
	DivergeFail tipPolicy = iota
)
View Source
const SlugMax = 40

SlugMax is where a slug is cut: long enough to carry a title's meaning, short enough for a tab label and a worktree path.

Variables

View Source
var (
	VerifyLimit     = 30 * time.Minute
	VerifyWaitDelay = 5 * time.Second
)

VerifyLimit bounds one verify command the drive runs itself, and VerifyWaitDelay how long its output is read once it was killed.

View Source
var ErrBaseNotPushed = errors.New("its base is not on origin yet")

ErrBaseNotPushed is a push held back because the base the catchup brought in is not on origin yet: the push would carry its commits into the PR.

View Source
var ErrOpUnread = errors.New("could not tell whether a merge or rebase is in progress")

ErrOpUnread is a read of a worktree that could not tell whether a merge or rebase is in progress there.

View Source
var PolicyLocal = BranchPolicy{"refs/heads/"}

PolicyLocal never tracks origin's copy, as a landed pickup must not

View Source
var PolicyLocalOrOrigin = BranchPolicy{"refs/heads/", "refs/remotes/origin/"}

Functions

func BaseHasCode

func BaseHasCode(ctx context.Context, main, branch, def string) bool

BaseHasCode reports a non-merge commit on a base task's branch past the default branch, its own recorded base and its creation commit: a merge is a catchup's, never code. The drive and ship's guard both decide by it, on local refs, so a branch never pushed counts.

func BodyAfter

func BodyAfter(ctx context.Context, tr Tracker, main string, task ref.Ref, body string) (string, string, error)

BodyAfter is the base the body's After: line gives start when no flag names one. A base with a branch is the dependency, a finished one is in the default branch already; anything else is refused before anything is made.

func BranchDiff

func BranchDiff(ctx context.Context, dir, main string) (string, []string, error)

BranchDiff is VerifyDiff for the checkout at dir, main the main checkout.

func BranchName

func BranchName(
	ctx context.Context,
	d *trackerdriver.Driver,
	task ref.Ref,
	suffix string,
	title func(context.Context) (string, error),
) (string, string, error)

BranchName is the task's branch name and, when no slug came, the note saying why.

func BranchUnsettled

func BranchUnsettled(ctx context.Context, main, dir, branch string) string

BranchUnsettled says why a catchup did not bring branch up to date, or "". Read from git, since catchup clears the mark only once verify is green.

func BundleAfter

func BundleAfter(ctx context.Context, tr Tracker, task ref.Ref, body string) (string, error)

BundleAfter is the After: line a task answers to: its body's, or for a bundle the one base its members name outside the bundle. A line naming another member orders work inside the branch; two bases cannot both be it.

func CatchupConflict

func CatchupConflict(ctx context.Context, main, dir, branch string, key branchmeta.Key) (string, string, error)

CatchupConflict is the fingerprint of the conflict branch meets with a mark's target now, and the files it conflicts on.

func CatchupRecord

func CatchupRecord(
	ctx context.Context, main, dir, branch string, key branchmeta.Key, now time.Time, fetched *FetchOnce,
) (*drivestore.Catchup, error)

CatchupRecord notes what the catchup about to go out for a mark starts from. A read git cannot answer fails: a record made up would halt a healthy task, or loop on a doomed one.

func ChangeTrailer

func ChangeTrailer(task, change string) string

ChangeTrailer names a later series' lore change, since a squash drops the branch's own trailers and Task: alone leads lore why to the first PR.

func ChildRefs

func ChildRefs(rows []ChildRow) []ledger.TaskRef

func ClearMarks

func ClearMarks(ctx context.Context, main, branch string, p CatchupPlan) error

ClearMarks unsets the catchup marks once the base is in and verify is green, and records the base the branch now stands on, as the step does.

func ConflictFingerprint

func ConflictFingerprint(ctx context.Context, dir, target string) (string, string, error)

ConflictFingerprint is the fingerprint of the conflict the worktree at dir meets merging target, and the files it conflicts on; the drive and the watcher compare these, so both build them here.

func DefaultBranch

func DefaultBranch(ctx context.Context, dir string) string

DefaultBranch is what origin points HEAD at (`origin/main`), or "" to let git use the current HEAD - the same default worktrunk applies.

func DefaultTargetOf

func DefaultTargetOf(ctx context.Context, main, def string) (string, string, error)

func DefaultTip

func DefaultTip(ctx context.Context, dir, def string, policy tipPolicy) (string, string, error)

DefaultTip is the default branch's tip to work from, and its name (def or origin/<def>). One side missing gives the other; otherwise a side that holds the other wins, and divergence goes by policy.

func FingerprintOf added in v0.61.0

func FingerprintOf(target string, conflicts []gitx.Conflict) string

FingerprintOf is ConflictFingerprint's fingerprint for conflicts already read, so a caller that needs them too merges once.

func FinishedTask

func FinishedTask(info tasksource.TaskInfo, root storage.Root, id string, hasBranch bool) bool

FinishedTask is the one "is this task done with": no branch, no live plan (a re-plan is pending work whatever the tracker says), and closed or its plan archived, which catches a merge whose PR body closed no issue.

func ForkPoint

func ForkPoint(ctx context.Context, dir, head, base string) (string, error)

ForkPoint is where the subject's branch left its base: the newer of the merge bases with the local and origin copies, so neither unpushed commits of the base nor origin moving ahead read as this change.

func HasTaskBranch

func HasTaskBranch(ctx context.Context, dir, id string) (bool, error)

HasTaskBranch reports a branch of the task, linked, local or on origin.

func IntegrateWith

func IntegrateWith(
	resolve func(context.Context, CatchupInput) (CatchupPlan, error),
) func(context.Context, CatchupInput, func(CatchupPlan) []string) (CatchupPlan, bool, error)

IntegrateWith is IntegrateBranch deciding the base with resolve, which a test scripts. A failed fetch decides on the refs at hand, as the step does: an integration needs some base, where originTip needs origin's real tip.

func LinkAfter

func LinkAfter(body, link string) string

LinkAfter puts link in place of the value on body's first After: line.

func ListOrNone

func ListOrNone(paths []string) string

func LocalDefault

func LocalDefault(ctx context.Context, dir string) (string, error)

LocalDefault is the default branch as a local name. Without it finish cannot tell a stacked PR from one against main, nor what to pull.

func MarkOn

func MarkOn(ctx context.Context, main, branch string) (branchmeta.Key, error)

func NamedRef

func NamedRef(ctx context.Context, dir, branch string) (string, string, error)

NamedRef is the ref --base names, with its commit. Exact refs rather than for-each-ref, since a base is one commit and a literal pattern would also match everything below the name at a slash.

func NewerMergeBase

func NewerMergeBase(ctx context.Context, dir, head, base string) (string, error)

NewerMergeBase is the newer of head's merge bases with base's local and origin copies, "" with neither. Two that diverged give origin's, the copy a request is compared against and a guard integrates.

func OpenSubtasks

func OpenSubtasks(ctx context.Context, tr Tracker, r ref.Ref) ([]string, error)

OpenSubtasks is the check start and drive make before a task runs as one of its own.

func OriginBaseHasCode

func OriginBaseHasCode(ctx context.Context, main, branch, def string) bool

OriginBaseHasCode is BaseHasCode for a base only origin holds: with no reflog there is no creation commit, so the base's own base is read on origin too.

func PRBase

func PRBase(ctx context.Context, warn io.Writer, main, branch string) (string, error)

PRBase is the branch the subject's request targets or would target. A recorded base found nowhere was finished and deleted, so its code is on the default branch; that is said on warn. PRTargetOf keeps "found nowhere" as its own answer, which drive and the watcher wait on.

func PushCatchup

func PushCatchup(ctx context.Context, dir, branch string, rec *drivestore.Catchup) (string, error)

PushCatchup is the one push after a clean catchup of a branch origin has: plain when it fast-forwards origin, leased against rec's origin tip after a rewrite, and never carrying a base origin lacks. A rewrite with no live lease is refused as unseen; a push or a refusal spends the lease.

func RawChildrenFor

func RawChildrenFor(ctx context.Context, t *target.Target, task ref.Ref) ([]tasksource.RawChild, error)

RawChildrenFor is the task's subtasks as the tracker holds them; ErrNoParentLink when it has no parent link to read.

func ReadTarget

func ReadTarget(ctx context.Context, main string, t PRTarget, prBase, local, origin string) (targetState, error)

ReadTarget reads t against the PR's base and the branch's local and origin tips; a prBase of "" skips the retarget check.

func RecordTip

func RecordTip(ctx context.Context, dir, branch, base string) error

RecordTip records the base commit branch is built on, so a catchup after the base's history is rewritten replays only branch's own commits. The newer of the local and origin merge-bases wins: a guard integrates origin's copy, which a stale local branch would hide. A base found nowhere keeps the tip recorded before.

func RecordedBase

func RecordedBase(ctx context.Context, main, branch string) (string, string, error)

RecordedBase is the f10-after-branch base start recorded on branch, and its sha, origin's copy first; sha is "" for a base found nowhere.

func RefSHA

func RefSHA(ctx context.Context, dir, r string) string

func RememberRefsFor

func RememberRefsFor(ctx context.Context, t *target.Target, refs ...ledger.TaskRef)

RememberRefsFor records refs as this project's; it never fails its caller.

func RiderRefs

func RiderRefs(root, id string) []string

RiderRefs are the patterns of a bundle branch the id rides in, past its lead: `<lead>+<id>`, `<lead>+<id>+<more>`, each bare or slugged.

func SetMark added in v0.60.0

func SetMark(ctx context.Context, dir, main, mark string) (string, string, error)

SetMark writes the mark a guard printed (`<key> <value>`) on the branch dir works on, and returns that branch and the mark as stored. Resolving the catchup again would name no mark: a stopped rebase leaves HEAD on the base, which reads as already in.

func ShipCode added in v0.62.0

func ShipCode(ctx context.Context, main, branch, def string) bool

ShipCode is BaseHasCode for the task's own branch, less the commits a catchup made: its fix for a red verify is not the task's work.

func Slugify

func Slugify(title string) string

Slugify cuts at the last hyphen at or before SlugMax so no word is split, hard at SlugMax when there is none.

func TaskCheckout

func TaskCheckout(
	ctx context.Context,
	main string,
	d *trackerdriver.Driver,
	task ref.Ref,
	suffix string,
) (string, string, error)

TaskCheckout is the task's branch and the checkout that has it checked out: both "" with no local branch, the path "" when checked out nowhere. No title lookup: a slug would cost a host call for nothing.

func TaskRefs

func TaskRefs(root, id string) []string

TaskRefs are the patterns a task's branch can sit under a root. for-each-ref extends a bare id to everything below it at a slash, but a `*` stops at a slash, so a slugged bundle needs its own pattern.

func TaskRows

func TaskRows(ctx context.Context, t *target.Target, limit int) ([]hostops.Row, error)

func TreeBusy

func TreeBusy(ctx context.Context, dir string) string

func WorktreeOf

func WorktreeOf(wts []gitx.Worktree, branch string) string

Types

type BranchIndex

type BranchIndex struct {
	// contains filtered or unexported fields
}

A BranchIndex answers which branch is a task's, from every branch's record read once. Build one per command and never keep it across a write to the records, since it answers from the read.

func LoadBranchIndex

func LoadBranchIndex(ctx context.Context, dir string) (*BranchIndex, error)

func (*BranchIndex) After

func (x *BranchIndex) After(ctx context.Context, id string) (string, error)

After is the branch --after names. Nothing or several matching fails before anything is created, since guessing would base the work on the wrong attempt.

func (*BranchIndex) Any

func (x *BranchIndex) Any(ctx context.Context, id string) (string, error)

Any is the first branch of the task, linked, local or origin's (`origin/<name>`), or "" for none.

func (*BranchIndex) Bundle

func (x *BranchIndex) Bundle(branch, prefix string) (string, []string)

Bundle is the lead and riders a branch ships: its recorded riders, led by its link else the id its name carries, then the ids its name spells, as a fetched branch carries them.

func (*BranchIndex) Find

func (x *BranchIndex) Find(ctx context.Context, want, id, suffix string, roots BranchPolicy) (FoundBranch, error)

Find is the branch to reuse, or none when the task has none yet. Several is an error, since a suffix exists to say which; a suffix skips the link, naming an attempt by its branch name.

func (*BranchIndex) Linked

func (x *BranchIndex) Linked(id string) []string

Linked are the local branches linked to id as lead or rider: a picked-up PR's branch need not carry the id, and a bundle's branch is found by any member.

func (*BranchIndex) Record

func (x *BranchIndex) Record(branch string) branchmeta.Record

func (*BranchIndex) Under

func (x *BranchIndex) Under(ctx context.Context, root, id, suffix string) ([]string, error)

Under lists the task's branches under root, narrowed to a suffix when given. Locally, a miss on the shapes start creates falls back to the id anywhere in the name (`feat/ABC-6-slug`), as `task read` reads a branch.

type BranchPolicy

type BranchPolicy []string

A BranchPolicy is where find looks past the link: the roots it searches, in order.

type CatchupEngine

type CatchupEngine struct {
	// Policy holds the catchup keys; dir, main and ShipStopped are set per task
	Policy CatchupInput

	// AgentVerifies says why the agent runs verify after a clean integration
	// and clears the marks once green, "" when the binary runs verify
	AgentVerifies string
	// Integrate, verify and base are the git and the verify the engine
	// runs, replaced by tests that script neither; base reads the base the
	// marks name without a fetch
	Integrate func(ctx context.Context, in CatchupInput, message func(CatchupPlan) []string) (CatchupPlan, bool, error)
	Verify    func(ctx context.Context, dir, log string) (VerifyRun, error)
	Base      func(ctx context.Context, in CatchupInput) (CatchupPlan, error)
	// contains filtered or unexported fields
}

CatchupEngine is how a branch is caught up from outside its agent.

func NewCatchupEngine

func NewCatchupEngine(policy CatchupInput, spec VerifySpec, why string, traces bool, main string) *CatchupEngine

NewCatchupEngine is the real git and verify; why, when not "", is the reason spec cannot run and the agent verifies instead.

func (*CatchupEngine) CleanSteering

func (e *CatchupEngine) CleanSteering(base string) string

CleanSteering is the turn the agent gets after a clean integration when the binary cannot run verify.

func (*CatchupEngine) ConflictSteering

func (e *CatchupEngine) ConflictSteering(p CatchupPlan, branch, who string, paths []string) string

ConflictSteering is what a turn settles after git stopped on conflicts.

func (*CatchupEngine) Input

func (e *CatchupEngine) Input(main, dir string) CatchupInput

Input is the policy for one worktree.

func (*CatchupEngine) Left

func (e *CatchupEngine) Left(ctx context.Context, main, dir, branch string, p CatchupPlan) (TreeState, error)

Left reads what keeps the branch from being caught up with p (TreeState's left), and when the agent verifies, whether a mark is still set.

func (*CatchupEngine) Message

func (e *CatchupEngine) Message(tasks []string, change string) func(CatchupPlan) []string

Message is a catchup merge's message: git's own subject, then the trailers a catchup commit carries for tasks, change naming its PR series.

func (*CatchupEngine) VerifyClause

func (e *CatchupEngine) VerifyClause() string

VerifyClause tells a turn under an agent-run verify to verify and clear the marks itself; under the binary's verify it adds nothing.

type CatchupInput

type CatchupInput struct {
	Dir, Main string
	Guard     string // "" for a run asked for by name, else the entry it guards

	Catchup, Stacked               string
	CatchupDefault, StackedDefault bool // the value is the default, not declared

	ShipStopped bool

	// Fetched is the tick's or the watcher pass's fetch, nil outside one
	Fetched *FetchOnce
}

func CatchupPolicy

func CatchupPolicy(eff *facts.Effective) CatchupInput

CatchupPolicy is the catchup keys of the effective configuration.

type CatchupPlan

type CatchupPlan struct {
	Branch, Base, SHA, Found, How, Method, Why, Mark string
	// Upstream is the base's old tip that onto rebases from
	Upstream string
	// Code says whether a recorded base branch has commits of its own: ship
	// waits on one with none, by the rule the drive releases dependents on
	Code string
}

func IntegrateBranch

func IntegrateBranch(
	ctx context.Context,
	in CatchupInput,
	message func(CatchupPlan) []string,
) (CatchupPlan, bool, error)

IntegrateBranch decides the base and method as f10 pr catchup does and integrates; stopped is a conflict left in progress.

func ResolveCatchup

func ResolveCatchup(ctx context.Context, in CatchupInput) (CatchupPlan, error)

func (*CatchupPlan) Write

func (p *CatchupPlan) Write(w io.Writer) error

type ChildRow

type ChildRow struct {
	ID       string   `json:"id"`
	Title    string   `json:"title"`
	URL      string   `json:"url,omitempty"`
	State    string   `json:"state,omitempty"`
	Labels   []string `json:"labels"`
	After    string   `json:"after,omitempty"`
	Finished bool     `json:"finished"`
	Depth    int      `json:"depth"`

	Number int    `json:"-"`
	Suffix string `json:"-"` // a launched start's worktree suffix: the checkout read is that one
	Queued bool   `json:"-"` // a drive's cap holds it back
	Phase  string `json:"-"` // where its drive's record says it stands, a drivestore.Phase name
	// OnChecks: a waiting Phase holds finish on running checks, not on a base
	OnChecks bool `json:"-"`
}

A ChildRow is one open subtask. Rows come in tree order: a child whose After: base is a sibling follows that sibling one level deeper.

func ChildTree

func ChildTree(rows []ChildRow) []ChildRow

ChildTree orders rows under their After: base, siblings by number, else in the order given. Rows caught in a cycle come out at the top level, so the listing stays readable and drive refuses the cycle itself.

func ShapeChildren

func ShapeChildren(
	ctx context.Context,
	tr Tracker,
	main string,
	raw []tasksource.RawChild,
	keepClosed bool,
) ([]ChildRow, error)

type FetchOnce

type FetchOnce struct{ Done bool }

A FetchOnce fetches origin at most once, a tick's or a watcher pass's: every worktree shares the main checkout's remote refs, so one fetch serves them all. A failed fetch is not kept, so the next caller tries again. A nil one, a caller outside any tick, fetches every time.

func (*FetchOnce) Fetch

func (f *FetchOnce) Fetch(ctx context.Context, dir string) error

type FoundBranch

type FoundBranch struct {
	Name   string
	Remote bool
}

A FoundBranch is the branch find settled on, and whether only origin has it, in which case start creates the local branch tracking it.

type OriginMovedError

type OriginMovedError struct {
	Branch, Path string
	Unseen       bool
	// contains filtered or unexported fields
}

OriginMovedError refuses a force-push that could drop commits pushed to the branch while its catchup ran: origin moved, or, unseen, nothing recorded what origin held when the catchup went out.

func (OriginMovedError) Error

func (e OriginMovedError) Error() string

type PRTarget

type PRTarget struct {
	SHA, Name, Value string
	Key              branchmeta.Key
}

PRTarget is what a task's PR targets and the mark that sends a catchup for it: origin's copy of the f10-after-branch base, else its local copy, else the default branch. sha is "" for a base found nowhere.

func PRTargetOf

func PRTargetOf(ctx context.Context, main, branch string) (PRTarget, error)

type Tracker

type Tracker struct {
	Resolve func(ctx context.Context, token string) (ref.Ref, error)
	Info    func(ctx context.Context, task ref.Ref) (tasksource.TaskInfo, error)
	// Children is the task's open subtasks; nil, like ErrNoParentLink, is a
	// tracker with no parent link
	Children func(ctx context.Context, task ref.Ref) ([]ChildRow, error)
	// AllChildren is children with the closed ones kept, for status
	AllChildren func(ctx context.Context, task ref.Ref) ([]ChildRow, error)
	Storage     storage.Root // where a finished task's plan is archived
	// contains filtered or unexported fields
}

A Tracker answers the questions start and drive ask of the task source. Funcs rather than a target, so the flows run under test without one.

func TrackerFor

func TrackerFor(t *target.Target) Tracker

TrackerFor binds the lookups to this target: the driver's `read` for the body where the project has one, the host's issue otherwise.

type TreeState

type TreeState struct {
	Op    gitx.Operation
	Dirty int
	// contains filtered or unexported fields
}

A TreeState is what git shows of a worktree a catchup acts on: an operation in progress and the uncommitted paths, and once WithBase ran, whether the branch holds the base and the conflict markers left past it.

func ReadTree

func ReadTree(ctx context.Context, dir string) (TreeState, error)

ReadTree reads the operation in progress and the uncommitted paths in dir.

func (TreeState) BaseLost

func (t TreeState) BaseLost() bool

BaseLost reports a branch that no longer holds the base WithBase read.

func (TreeState) Busy

func (t TreeState) Busy() string

Busy says what keeps a catchup from starting, "" for nothing.

func (TreeState) Left

func (t TreeState) Left() string

Left says what keeps the branch from being caught up, "" for nothing: an operation in progress (a rebase with its place), uncommitted paths, the base not in the branch, a conflict marker, or a mark still set.

func (TreeState) WithBase

func (t TreeState) WithBase(ctx context.Context, branch string, p CatchupPlan) (TreeState, error)

WithBase is t with whether branch holds p read, and if it does, the conflict markers left in the paths it changes past p.

type VerifyRun

type VerifyRun struct {
	Failed, Log string
}

A VerifyRun is verify run once: the first command that failed, with its output in log, or "" when every command passed.

func RunVerify

func RunVerify(ctx context.Context, dir string, cmds []string, log string) (VerifyRun, error)

RunVerify runs each command in dir in order and stops at the first that fails, writing its output to log.

type VerifySpec

type VerifySpec struct {
	List []facts.VerifyDecl
	Cmds []string
}

A VerifySpec is the verify the drive can run without a model: the frontmatter list, scoped to the branch's diff, or a fixed set of commands.

Jump to

Keyboard shortcuts

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