superloop

package
v0.175.0-rc.130 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 9 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 superloop is the supervisor's fixed procedure as a pure function: beekeeper's events, the roster and the tracked pull requests in, the transitions to take out. `beekeeper supervisor loop` gathers the input, runs each action through beekeeper's own commands and logs it under its key, which is what keeps a restarted loop from taking it twice.

Index

Constants

View Source
const (
	KindReview = "review"
	KindGo     = "go"
	// KindMerge records a coordinator mutation, never a worker grant.
	KindMerge   = "merge"
	KindForward = "forward"
	// KindRework tells the worker that parked again on the head whose
	// findings stand to fix them: the
	// review rounds stay the loop's, and no merge question reaches the
	// person.
	KindRework = "rework"
	// KindAnswer tells the worker the person's answer to an ownership
	// question that did not override the owning team.
	KindAnswer = "answer"
	// KindDone takes an agent off the roster: one that reported done, or
	// one the loop retires (a reviewer whose verdict it acted on, the
	// worker of a pull request it gave the go for that merged).
	KindDone     = "done"
	KindNext     = "next"
	KindRelease  = "release"
	KindClassify = "classify"
	KindQuestion = "question"
	// KindFile hands the problems a done report found and filed nowhere
	// to the guide's feed, to file in their owning repository.
	KindFile = "file"
	// KindEnd ends the tracking of a pull request that merged or closed.
	KindEnd = "end"
	// KindLeave says once why the loop leaves a parked pull request alone:
	// outside the desk's organisations, in supervisor.ownership.never,
	// parked before the loop's first start, opened by somebody else,
	// another team's, or green on a head past its approval with no park
	// since the round that approved it; and why a merged pull request's
	// worker stays for the open work it still serves.
	KindLeave = "leave"
	// KindRelay tells the worker parked on another team's pull request
	// that team's review, word for word.
	KindRelay = "relay"
	// KindOwnership asks the guide's person whether the desk takes over a
	// pull request whose owning team's review blocks its worker;
	// KindOverride records the person's answer that it does.
	KindOwnership = "ownership"
	KindOverride  = "override"
	// KindRed wakes the worker parked on a pull request whose parked head
	// has a check that concluded red (failed, cancelled, timed out), with
	// each such check's name and URL: once for each head, check and park.
	KindRed = "red"
	// KindIntake puts an issue the desk filed (a problem report's issue URL,
	// a follow-up named in a report, an issue a session created with gh
	// issue create) onto the configured board in Backlog and places it on the
	// board, unless it already sits on another board where it is being worked.
	KindIntake = "intake"
	// KindOwner gives an overlapping pull request a live owner when a worker
	// parks on it and its owner is gone or it has made no progress for
	// OverlapWait.
	KindOwner = "owner"
)

The kinds of action, each logged as "supervisor.<kind>".

View Source
const (
	VerbDone    = "agents.done"
	VerbIdle    = "agents.idle"
	VerbReport  = "agents.report"
	VerbProblem = "agents.problem"
	VerbPark    = "agents.park"
)

The verbs of the events the rules act on.

View Source
const (
	Approved         = "approved"
	ChangesRequested = "changes requested"
)

The verdicts of a review.

View Source
const (
	Open   = "OPEN"
	Merged = "MERGED"
	Closed = "CLOSED"
)

The states of a pull request, as gh reports them.

View Source
const MaxReviews = 2

MaxReviews is how many reviews the loop starts for one pull request, whatever happens: one, and a second only for a change an approval does not cover. A later change merges on the loop's go: the loop merges after the reviews and their fixes, and never asks a person whether to merge.

View Source
const MaxSweeps = 2

MaxSweeps is how many owners the sweep gives one head of a pull request: a head that loses its owner again after that goes to the guide.

View Source
const OrphanWait = 15 * time.Minute

OrphanWait is how long an open pull request of the desk may go without a live owner before the sweep gives it one.

View Source
const OverlapWait = 30 * time.Minute

OverlapWait is how long a worker may wait on an overlapping pull request with no progress before the loop gives that pull request an owner.

Variables

This section is empty.

Functions

func Detail

func Detail(a Action, what string) string

Detail is the log detail of action a taken for its agent.

func EventAgent

func EventAgent(verb, detail, by string) string

EventAgent is the roster name of the agent an event of verb concerns: the name its detail opens with ("<name> done: …", "<name>: …"), which agents idle and agents park write from the roster, else by, the name of the party that logged it (its session's title, which may differ).

func Filed

func Filed(problem string) bool

Filed reports whether a problem found names its issue's URL: it is filed.

func HasOverlapWait

func HasOverlapWait(workers []Worker, taken []Taken, answers []Answer) bool

HasOverlapWait reports whether any worker on the roster is waiting on another pull request.

func IsPull

func IsPull(on string) bool

IsPull reports whether a park's On names an issue or pull request.

func IsSweep

func IsSweep(key string) bool

IsSweep reports whether key is a key the sweep wrote.

func KeyHead

func KeyHead(key string) string

KeyHead is the head a key names after its ref ("<what> <ref>@<head>…"), "" when it names none.

func Overrides

func Overrides(answer string) bool

Overrides reports whether the person's answer to an ownership decision overrides it. It fails closed, as Releases does: only the first option's label ("Override", its words after it or not) or a bare override does.

func Ownerless

func Ownerless(in Input) []string

Ownerless are the open pull requests among in.Pulls the desk owns and no live session owns, sorted: the loop keeps since when each has been so (Input.Ownerless). A draft is nobody's to take over: it does not ask for a review, and an epic's plan waits for its person.

func OwnershipOptions

func OwnershipOptions(team string) []string

OwnershipOptions are an ownership decision's choices: the first overrides it.

func OwnershipQuestion

func OwnershipQuestion(url, team string) string

OwnershipQuestion is the question the guide's person is asked when the owning team's review of url blocks the desk's work.

func ParkedOn

func ParkedOn(detail string) (on, waits string)

ParkedOn reads an agents.park detail ("<name>: parked on <on>: <waits>" or "<name>: parked: <waits>"): what it is parked on and what it waits for.

func PullWorkerName

func PullWorkerName(ref string) string

PullWorkerName is the default roster name of the worker that owns ref (owner/repo#n): "<repo> <n>".

func ReviewedHead

func ReviewedHead(body, commit string) string

ReviewedHead is the head a review judged: the commit its body names on a "Head reviewed:" line, else the commit GitHub recorded it on.

func ReviewerName

func ReviewerName(ref string, rd int) string

ReviewerName is the roster name of the reviewer of round rd of ref (owner/repo#n): "Review <repo> <n> r<rd>".

func Tracked

func Tracked(workers []Worker, taken []Taken, answers []Answer, desk Desk) []string

Tracked are the pull requests a pass reads: every verified review request an agent is parked on, every overlapping pull request another worker is parked on, every one the loop started a review of that it has not seen merged or closed, and every ended one whose worker waits for its retirement. None outside the desk's organisations or in its never list is read, nor one whose park is from before the loop's first start.

func Verbs

func Verbs() []string

Verbs is every log verb the loop writes.

func Verdict

func Verdict(state, body string) string

Verdict is a review's verdict: GitHub's own (APPROVED, CHANGES_REQUESTED), else that of a commented review whose first line ends in ": approved" or ": changes requested" (a review posted from the author's own account cannot approve on GitHub). "" for a review without one.

Types

type Action

type Action struct {
	Key   string
	Kind  string
	Ref   string // the pull request, when there is one
	Block string // the overlapping pull request or issue recorded blocked by Ref
	URL   string
	Agent string // the worker it concerns
	Head  string
	Round int
	// The verdict the merge decision observed. A newer change request must
	// force replanning before the loop records its exact-head authorization.
	ReviewID      string
	ReviewVerdict string
	// SelfHosted asks for a reviewer on no self-hosted provider.
	SelfHosted bool
	// Message is what the worker or the guide is told.
	Message string
	// Question is an ownership decision's question for
	// the guide's person; Options an ownership decision's choices.
	Question string
	Options  []string
	// Event is the event a done, next or classify action acts on.
	Event *Event
	// Note is the note a question re-addresses.
	Note int
	// Version is the release to install.
	Version string
}

Action is one transition to take.

func Plan

func Plan(in Input) []Action

Plan is the pass: the actions in, in a stable order, none whose key was taken.

func ReleaseWorkers added in v0.172.0

func ReleaseWorkers(in Input) []Action

ReleaseWorkers returns the retained workers whose merged pull requests may be carried by an installed release. Containment is checked by the caller.

func (Action) Line

func (a Action) Line(what string) string

Line is the action's log detail: its key first, then what it did.

type Answer

type Answer struct {
	Ref      string // owner/repo#n, the answer's about
	Note     int
	Question string // the note's question
	Text     string // the person's words, an option's label first
	By       string
	At       time.Time
}

Answer is a person's answer (answer.recorded) to a note the loop filed.

type Check added in v0.172.4

type Check struct {
	Name, URL string
}

Check is one check on a pull request's head: its name and the URL of its run.

type Desk

type Desk struct {
	// Since is the loop's first start: a park from before it is no request
	// for a review.
	Since time.Time
	// Orgs are github.allowedOrgs: outside them the loop does nothing at
	// all. Empty: every owner.
	Orgs []string
	// Authors are the logins the desk opens its pull requests as; empty:
	// anybody's.
	Authors []string
	// Team is the desk's team as the team files name it; empty: every
	// repository in Orgs is the desk's.
	Team string
	// Review are the repositories (path.Match patterns over owner/name) the
	// desk reviews whoever owns them; Never the ones it does no work on,
	// whatever Review or an override says.
	Review, Never []string
	// OwnerWait is how long a worker waits for the owning team's review
	// before the person is asked to override it.
	OwnerWait time.Duration
	// TeamsUnknown says the team files could not be read: only Review and
	// the person's overrides say what is the desk's, and nothing else is
	// acted on until they are read.
	TeamsUnknown bool
}

Desk is whose pull requests the loop acts on: the policy every pull request passes before a review, a go or a forward.

func (Desk) Outside

func (d Desk) Outside(ref string) bool

Outside reports whether ref's owner is outside the desk's organisations.

func (Desk) Unread

func (d Desk) Unread(ref string) (reason, why string)

Unread is why the loop leaves ref alone without reading it (its reason and its words), "" when it may read it: outside Orgs or in Never.

type Event

type Event struct {
	At     time.Time
	Verb   string
	Agent  string // the party that logged it
	Detail string
}

Event is one line of the event log the loop acts on.

type FiledIssue added in v0.174.0

type FiledIssue struct {
	Ref   string
	URL   string
	Agent string
	From  string
}

FiledIssue is an issue a session on the desk created, with the issue or pull request the session was working on (From) when it filed it.

type Input

type Input struct {
	Workers []Worker
	// Pulls are the tracked pull requests (Tracked) by ref.
	Pulls map[string]Pull
	// Events are the log's events since the loop's first start.
	Events []Event
	Notes  []Note
	// Release is a newer release's version, "" when there is none.
	Release string
	// Taken are the actions already taken, oldest first.
	Taken []Taken
	// Rounds is supervisor.reviewRounds.
	Rounds int
	// Person is the guide's person.
	Person string
	// Answers are the answers to the notes the loop filed, oldest first.
	Answers []Answer
	// Desk is whose pull requests the loop acts on; Now is the pass's time.
	Desk            Desk
	Now             time.Time
	PostMergeWindow time.Duration
	// DevctlOwners is merge.devctlOwners: a go on their repositories names
	// the gate's devctl pr merge --update-branch, on any other gh pr merge
	// --match-head-commit.
	DevctlOwners []string
	// Admin is merge.admin: the repositories (owner/repo) whose go names
	// gh pr merge --admin --match-head-commit to merge past their branch
	// ruleset after the approved review.
	Admin []string
	// BaseMerged reports whether p's head only brings its base into
	// approved, an earlier head the loop's go covers: it merges the base,
	// resolving the merge's conflicts or not, or rebases onto it
	// (github.ApprovalCovers); nil: never, every new head is a new review.
	BaseMerged func(p Pull, approved string) bool
	// Open reports whether an issue or pull request (owner/repo#n) is
	// open; one it cannot read counts as open. nil: none is, so a merged
	// pull request's worker is retired as before.
	Open func(ref string) bool
	// StaleAfter is agents.staleAfter: a worker kept for the open work it
	// serves goes once it stayed quiet this long with no park or wake
	// timer (0: a day).
	StaleAfter time.Duration
	// Board reports whether a project board is configured: when true,
	// issues the desk files land on it in Backlog (KindIntake).
	Board bool
	// Filed are the issues sessions on the desk created (gh issue create,
	// create_issue, issue_write), read from their transcripts.
	Filed []FiledIssue
	// Ownerless is since when each open pull request of Ownerless has had
	// no live owner, as the loop saw it: the sweep gives one past
	// OrphanWait.
	Ownerless map[string]time.Time
}

Input is everything a pass plans from.

type Note

type Note struct {
	ID   int
	For  string
	By   string
	Text string
}

Note is an open note.

type Pull

type Pull struct {
	// Closes names the issues closed by this pull request.
	Closes                []string
	Draft                 bool
	Mergeable, MergeState string
	ReviewDecision        string
	Ref                   string // owner/repo#n
	URL                   string
	State                 string
	Head                  string
	// Base is the branch it merges into.
	Base        string
	MergeCommit string
	// Green is every non-superseded check on Head concluded successfully (none is not
	// green: they have not reported yet).
	Green bool
	// Red are the checks on Head that concluded red (failure, cancelled,
	// timed out, startup failure, action required; a commit status's
	// failure or error), by name. Superseded cancellations are excluded.
	Red []Check
	// Checks are the names of the non-superseded checks on Head.
	Checks  []string
	Reviews []Review // oldest first
	// Author is the login that opened it; Title, Branch (its head branch)
	// and Files (the paths it changes, ChangedFiles of them in all, which
	// gh may list only in part) are what may name a repository the desk
	// does no work on.
	Author, Title, Branch string
	Files                 []string
	ChangedFiles          int
	// Team is the team the team files say owns its repository, "" when
	// none does.
	Team string
	// Updated is when GitHub last saw activity on it (a push, a review, a
	// comment): the sweep counts a stretch without an owner from no earlier.
	Updated time.Time
}

Pull is a tracked pull request as GitHub reports it.

type Review

type Review struct {
	ID     string
	Author string
	URL    string
	Commit string
	// Member is a review by a member or collaborator of the repository's
	// owner: only such a review is the owning team's.
	Member  bool
	Head    string
	Verdict string
	Body    string
	At      time.Time
}

Review is one review of a pull request with a verdict.

type Taken

type Taken struct {
	Key   string
	Kind  string
	Ref   string
	Agent string
	At    time.Time
}

Taken is an action the loop took, read back from its log line.

func ParseTaken

func ParseTaken(at time.Time, verb, subject, detail string) (Taken, bool)

ParseTaken reads a loop log line (verb "supervisor.<kind>", detail "[<key>] <agent>: …") back; false for another line.

type Worker

type Worker struct {
	// ReviewRequested distinguishes a proven published branch from a plain wait.
	ReviewRequested bool
	Name            string
	// SelfHosted is a worker whose model a self-hosted provider serves:
	// its reviewer runs on none of them.
	SelfHosted bool
	// ParkedOn is what the agent is parked on (owner/repo#n, #12, …), ""
	// when it is not parked; ParkedAt since when.
	ParkedOn string
	ParkedAt time.Time
	// ParkedHead is the published head a review request proved (the
	// park's review head), "" for a plain wait.
	ParkedHead string
	// Started is a session beekeeper started: only such a one the loop
	// retires; a session its person started stays.
	Started bool
	// Waking is an open timer that wakes the agent by name (timer add
	// --wake): a park on nothing waits for it.
	Waking bool
	// LastActive is the latest observed session activity.
	LastActive time.Time
	// Serves is the issue the agent's active sessions serve record names
	// (owner/repo#n), "" without one or once it waits for "done".
	Serves string
	// Waits is what the agent's park says it waits for.
	Waits string
	// Saved is a saved review park whose agent left the roster: it keeps
	// the review flow going, and owns nothing (the sweep's live owner).
	Saved bool
	// Mentions are the issues and pull requests (owner/repo#n, lower case)
	// the agent's task names.
	Mentions []string
}

Worker is an agent on the roster.

Jump to

Keyboard shortcuts

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