Documentation
¶
Overview ¶
Package delivery hands a worktree job's branch over (GIT-02, design 2026-10-12-delivery-and-cost-estimate-design.md): merge it into the base branch, push it to a remote, or push it and open a pull / merge request on GitHub, GitLab or Gitea / Forgejo. It runs on the machine that owns the worktree — the server for a local job, the worker (through an internal exec job) otherwise — from a self-contained Plan, and never force-pushes.
Index ¶
- Constants
- Variables
- func BaseBranch(ctx context.Context, wtPath string) (main, branch string, err error)
- func CheckIdle(p Plan) error
- func CompareURL(provider string, r Remote, head, base string) string
- func DetectProvider(host, override string) string
- func FromLeaderWakeState(state string) string
- func FromMailState(state string) string
- func FromScheduleResult(lastResult string) string
- func FromSeatScheduleEvidence(lastResult string, queuedCount int) string
- func FromSessionMessage(status, channel string) string
- func FromTeamAttention(kind string) string
- func FromTeamOutcome(outcome string) string
- func FromTeamTimeline(state, outcome string) string
- func GitOut(ctx context.Context, dir string, args ...string) (string, error)
- func MainCheckout(ctx context.Context, wtPath string) (string, error)
- func MergeBranch(ctx context.Context, wtPath, branch string, squash bool) (main, base string, err error)
- func Push(ctx context.Context, dir, remote, src, dst, proxy string) error
- func RemoteURL(ctx context.Context, dir, remote string) (string, error)
- func ResolveToken(ctx context.Context, provider, override string, env Env) string
- func TokenVars(provider, override string) []string
- func ValidMode(m string) bool
- func ValidState(s string) bool
- type APIError
- type Client
- type Env
- type MergeConflictError
- type PR
- type PRRequest
- type Plan
- type RefResult
- type Remote
- type Result
- type WaitAssetsOptions
- type WaitAssetsResult
- type WaitCIOptions
- type WaitCIResult
Constants ¶
const ( ModeNone = "none" ModeMerge = "merge" ModePush = "push" ModePR = "pr" )
Modes.
const ( StatePending = "pending" StateMerged = "merged" StatePushed = "pushed" StatePROpened = "pr_opened" StateFailed = "failed" StateSkipped = "skipped" )
States of a delivery.
const ( ProviderAuto = "auto" ProviderGitHub = "github" ProviderGitLab = "gitlab" ProviderGitea = "gitea" // Gitea and Forgejo share the API )
Providers.
const ( // Queued: written down, waiting to be sent. Queued = "queued" // Sent: handed to the transport, no proof the recipient started. Sent = "sent" // Consumed: the recipient provably took the text up. Consumed = "consumed" // Unknown: attempted without evidence either way. Unknown = "unknown" // Failed: provably not delivered. Failed = "failed" )
Delivery-state vocabulary shared by every channel that hands a text to someone (design 2026-12-04-handoff-reliability-design.md §R2). The five values are read-only projections: no schema changes, each channel keeps its own words and the read layer maps them here, so the console can say the same thing about every channel.
The rule is: a value is only reached with the evidence named next to it, and no channel claims more than it can prove.
queued the text is written down and waits to be sent (nothing left gofer yet)
sent the text was handed to the transport (a delivery path returned, a peer
confirmed receipt) but nothing proves the recipient started on it
consumed the recipient really took it up: its own open turn was answered, its hook
took the letter, or it replied to it
unknown a send was attempted and no evidence came back either way
failed provably not delivered (nothing to deliver to, expired, an error)
"" means the channel has no delivery meaning for that row (a routing decision that was never a send attempt); the console then keeps showing the channel's own word.
Variables ¶
var ( ErrMergeConflict = errors.New("worktree merge has conflicts") ErrMainNotReady = errors.New("main checkout is not ready for a merge") // ErrIndexLocked: the main checkout's .git/index.lock is still held once the wait // elapsed. The lock is NEVER deleted — another git process owns it. ErrIndexLocked = errors.New("git index.lock is still held") )
Merge errors (typed so callers map them to 409).
var StepPollFloor = time.Second
StepPollFloor is the shortest interval between two platform polls. A package variable so tests can shorten it; the step's own interval comes from its `with` block.
Functions ¶
func BaseBranch ¶
BaseBranch is the branch the main checkout of wtPath's repository is on — where a merge lands and the default target of a pull request.
func CheckIdle ¶ added in v0.224.0
CheckIdle refuses a plan whose worktree another job still works in: the same rule the delivering machine applies before it merges or cleans up, checked here for a delivery that runs where the worktree is (a worker) and cannot ask the hub.
func CompareURL ¶
CompareURL is the platform's web page for opening a request by hand ("" unknown).
func DetectProvider ¶
DetectProvider names the platform of host: github.com and gitlab.com by name, a self-hosted instance when its host says so (gitlab.*, gitea.*, forgejo.*, codeberg.org); "" when it cannot tell (set provider explicitly).
func FromLeaderWakeState ¶ added in v0.230.0
FromLeaderWakeState maps a plan leader wake (jobstore.LeaderWake*) to a delivery state. Evidence:
pending armed, waiting for its due time
firing a sweep claimed it and the leader job submit is in flight
fired the leader job was submitted (leader_job_id holds it); nothing proves the
leader's session actually started on it, so it stops at sent
cancelled a person spoke (or the plan was paused) before it fired
func FromMailState ¶ added in v0.230.0
FromMailState maps a letter's state (jobstore.Mail*) to a delivery state. Evidence:
pending written down, not claimed by a delivery path yet delivering a delivery path claimed it and is in flight delivered the path confirmed it / the recipient's hook took it (reading IS delivery) answered the recipient replied to it: it was certainly taken up held nothing to deliver it to; it waits in the capture box for a person expired past its delivery deadline without being delivered failed the delivery failed and is not retried cancelled withdrawn by its sender (no delivery meaning)
func FromScheduleResult ¶ added in v0.230.0
FromScheduleResult maps a seat schedule's last delivery (jobstore.ScheduleResult*) to a delivery state. Evidence per result:
delivered the sitting session's transport accepted the text (seat deliverNow)
restarted the ACP session was restarted and the text is its opening turn (a job was
submitted; the table keeps its id after ":")
offline nobody could take it; the text waits in the seat queue (queued)
failed the send was tried and refused (the reason follows after ":")
"" (never delivered) maps to "" : no attempt has been made.
func FromSeatScheduleEvidence ¶ added in v0.230.0
FromSeatScheduleEvidence is the seat-schedule card's view: the queue is the strongest evidence (texts still waiting), then the last delivery's own word.
func FromSessionMessage ¶ added in v0.230.0
FromSessionMessage maps a session outbox message (jobstore.SessionMessage) to a delivery state. Evidence per status:
queued appended to the outbox, nothing sent yet (sessionrelay message.go:131) delivering handed to an internal delivery job that had begun (message.go:176-179) delivered a delivery path returned ok (message.go:155, 222, 330) undelivered the ladder never started it (message.go:411) failed the path ran and failed; the text may or may not have arrived (failMessage)
consumed needs the channel too: channel "turn" means the text answered the session's OWN open turn, i.e. the agent's blocked turn resumes with it — that is the recipient starting on the text. Every other channel (tmux, command, takeover, messenger) only proves the transport accepted it.
func FromTeamAttention ¶ added in v0.230.0
FromTeamAttention maps a team 「等我」 fact (team.Attention*) to a delivery state: letters wait while every member seat is vacant or offline — they are queued, and that is exactly what the card is about. The other facts (a missed evaluation, a relay handed to the leader) are not about a text that waits to go out.
func FromTeamOutcome ¶ added in v0.230.0
FromTeamOutcome maps a team routing decision (jobstore.TeamOutcome*) to a delivery state. Evidence:
pending the ledger row is written, the outcome is not settled (mail/team_route.go:281)
queued the letter is stored and waits for a delivery path (outcomeOf, team_route.go:194)
delivered the letter reached delivered, settled by the store (mail.go:578)
merged the text was absorbed into the head letter's turn (deliverer.go:588)
held the letter is held: nothing to deliver it to (team_route.go:198)
unknown the row may not have reached the table, or it went stale (teams.go:628)
dropped_self the rule dropped it on purpose (own letter) -> no delivery meaning
dup a repeat of a route key, not sent again -> no delivery meaning
handed_to_leader the relay was redirected to the leader seat; its own delivery is
settled later by the letter's state -> no delivery meaning
func FromTeamTimeline ¶ added in v0.230.0
FromTeamTimeline picks the state of a team timeline entry: the letter's state is the strongest evidence (it knows about answers), the routing outcome the fallback for the letterless ledger rows.
func GitOut ¶
GitOut runs git in dir and returns its trimmed stdout; a failure carries git's stderr.
func MainCheckout ¶
MainCheckout returns the main working tree of the repository a linked worktree belongs to.
func MergeBranch ¶
func MergeBranch(ctx context.Context, wtPath, branch string, squash bool) (main, base string, err error)
MergeBranch merges branch (checked out in the worktree wtPath) into its repository's main checkout: --no-ff with a merge commit, or --squash plus one commit. The main checkout must have no tracked changes and be on a named branch; a conflict is fully undone before the typed error is returned, and uncommitted .gofer/tracker/ changes survive the undo. It returns the main checkout and the branch merged into.
func Push ¶
Push pushes local ref src to refs/heads/dst on remote — never forced: a remote branch that moved elsewhere is an error naming the rejection. A non-empty proxy overrides git's http.proxy for this push only.
func RemoteURL ¶ added in v0.181.0
RemoteURL is the URL a remote points at (`git remote get-url`), for parsing the platform and repository out of it. An empty remote means origin.
func ResolveToken ¶
ResolveToken reads the platform token on this machine: the configured / default variables, else the logged-in CLI (`gh auth token`, `glab auth token`).
func ValidState ¶ added in v0.230.0
ValidState reports whether s is one of the five delivery states ("" is always allowed and means "this channel has no delivery meaning here").
Types ¶
type Client ¶
type Client struct {
Provider string
Remote Remote
Token string
HTTP *http.Client
// APIBase overrides the derived API root (tests, unusual installs).
APIBase string
}
Client opens requests on one platform.
type Env ¶
type Env struct {
Lookup func(string) (string, bool)
// RunTokenCLI runs a token helper (`gh auth token`); nil = exec it.
RunTokenCLI func(ctx context.Context, name string, args ...string) (string, error)
HTTPBase string // API base override (tests)
// Lang is the language of the errors a built-in step returns (zero = the default
// language): a step runs inside a workflow and carries no request language of its own.
Lang i18n.Lang
}
Env lets the caller supply the environment and the CLI token helpers (tests).
type MergeConflictError ¶
type MergeConflictError struct {
Files []string
}
MergeConflictError reports a conflict after the main checkout has been restored.
func (*MergeConflictError) Error ¶
func (e *MergeConflictError) Error() string
func (*MergeConflictError) Unwrap ¶
func (e *MergeConflictError) Unwrap() error
type PR ¶
type PR struct {
URL string
Number int
Existed bool // an open request for the same head was found and reused
}
PR is an opened (or already open) request.
type PRRequest ¶
type PRRequest struct {
Title string
Body string
Head string // the pushed branch
Base string // target branch
Draft bool
Labels []string
}
PRRequest is what a pull / merge request is opened with.
type Plan ¶
type Plan struct {
Mode string `json:"mode"`
JobID string `json:"job_id"`
Worktree string `json:"worktree"` // the job's worktree (absolute, on the executing machine)
Branch string `json:"branch"` // the local branch (gofer/<job>)
RemoteBranch string `json:"remote_branch"` // pushed as
Remote string `json:"remote"`
Base string `json:"base,omitempty"` // "" = the main checkout's branch
AllowPush bool `json:"allow_push"`
PushBase bool `json:"push_base,omitempty"`
Squash bool `json:"squash,omitempty"`
Cleanup bool `json:"cleanup,omitempty"`
Draft bool `json:"draft,omitempty"`
Labels []string `json:"labels,omitempty"`
Provider string `json:"provider,omitempty"` // auto | github | gitlab | gitea
TokenEnv string `json:"token_env,omitempty"` // variable NAME; "" = the provider's defaults
Proxy string `json:"proxy,omitempty"` // push + API proxy; "" = git's http.proxy, then the environment
Title string `json:"title"`
Body string `json:"body"`
// BusyWith names the jobs still working in Worktree, filled by the machine that
// dispatched the plan when it could see them (a worker's own job service); a merge or
// a cleanup is refused while it is not empty (CheckIdle).
BusyWith []string `json:"busy_with,omitempty"`
}
Plan is one delivery, self-contained so it can be carried to the machine that owns the worktree (an internal exec job reads it as JSON on stdin).
type RefResult ¶ added in v0.181.0
type RefResult struct {
Ref string `json:"ref"`
Kind string `json:"kind"` // branch | tag
Remote string `json:"remote"`
SHA string `json:"sha"`
}
RefResult is one ref pushed and verified against the remote.
func PushRefs ¶ added in v0.181.0
func PushRefs(ctx context.Context, dir, remote string, refs []string, proxy string) ([]RefResult, error)
PushRefs pushes every ref to remote and verifies the remote now holds the same sha. A name that resolves to a local branch is pushed to refs/heads/<name>, a local tag to refs/tags/<name>. Nothing is ever forced: a remote ref that moved elsewhere makes git reject the push and the rejection is returned as-is. After the push every ref is read back with `git ls-remote`, so a "successful" push that did not land (a hook, a mirror) is a failure here rather than a silently wrong release.
type Remote ¶
type Remote struct {
Host string // host[:port] of the web / API endpoint
Path string // owner/repo (GitLab: group/sub/repo), without .git
}
Remote is a parsed git remote URL.
func ParseRemote ¶
ParseRemote reads https://host/owner/repo(.git), ssh://git@host[:port]/owner/repo and scp-style git@host:owner/repo. An ssh port is dropped (the API is on https).
type Result ¶
type Result struct {
Mode string `json:"mode"`
State string `json:"state"`
Branch string `json:"branch,omitempty"`
Remote string `json:"remote,omitempty"`
Base string `json:"base,omitempty"`
Provider string `json:"provider,omitempty"`
PRURL string `json:"pr_url,omitempty"`
PRNumber int `json:"pr_number,omitempty"`
CompareURL string `json:"compare_url,omitempty"`
Note string `json:"note,omitempty"`
Error string `json:"error,omitempty"`
At int64 `json:"at"`
}
Result is what a delivery did.
type WaitAssetsOptions ¶ added in v0.181.0
type WaitAssetsOptions struct {
Tag string
Assets []string // globs of asset file names
TimeoutMin int
IntervalSec int
Remote string
Env Env
}
WaitAssetsOptions is what `gofer/wait-assets` asks for.
type WaitAssetsResult ¶ added in v0.181.0
type WaitAssetsResult struct {
Provider string `json:"provider"`
Tag string `json:"tag"`
URL string `json:"url,omitempty"`
Assets []string `json:"assets"`
}
WaitAssetsResult is what the step reports.
func WaitAssets ¶ added in v0.181.0
func WaitAssets(ctx context.Context, dir string, o WaitAssetsOptions) (WaitAssetsResult, error)
WaitAssets polls the release of tag until every glob matches an uploaded asset.
type WaitCIOptions ¶ added in v0.181.0
type WaitCIOptions struct {
Ref string // branch, tag or sha whose checks to wait for
Required []string // check / workflow run names that MUST pass ("" = every check must pass)
CodeScanning bool // also fail on code scanning alerts reported for this ref
TimeoutMin int // default 40
IntervalSec int // default 20, never below StepPollFloor
Remote string // "" = origin
Env Env // HTTPBase / Lookup overrides (tests)
}
WaitCIOptions is what `gofer/wait-ci` asks for.
type WaitCIResult ¶ added in v0.181.0
type WaitCIResult struct {
Provider string `json:"provider"`
Ref string `json:"ref"`
Checks []string `json:"checks,omitempty"`
Alerts int `json:"code_scanning_alerts"`
}
WaitCIResult is what the step reports.
func WaitCI ¶ added in v0.181.0
func WaitCI(ctx context.Context, dir string, o WaitCIOptions) (WaitCIResult, error)
WaitCI polls the platform until every check of ref has finished. It fails as soon as a required check fails, and it fails with the checks still running when the timeout elapses, so the workflow log names what was waited for.