Documentation
¶
Overview ¶
Package orchestrate runs typed repository mutations through isolated worktrees, local verification, and optional GitHub publication stages.
Index ¶
Constants ¶
const DefaultCheckPollInterval = 30 * time.Second
DefaultCheckPollInterval deliberately leaves room for other WB operations sharing the authenticated GitHub user budget. A PR receipt still reads every dynamic fact on each observation; only static branch policy is cached within the bounded slice and is fetched again before a pass is returned.
const MaxForegroundCheckWaitSlice = 9 * time.Minute
MaxForegroundCheckWaitSlice keeps a single agent-tool call under the common ten-minute harness ceiling. Longer CI is observed by explicit re-invocation, never a detached worker or a hidden thirty-minute loop.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assessment ¶
Assessment is adapter-owned planning metadata plus an execution decision.
type Handler ¶
type Handler[T any] interface { Inspect(context.Context, string, string, Repository) (Assessment[T], error) Apply(context.Context, string, Repository) (T, error) ValidatePublishable(context.Context, string, Repository) error CommitMessage(Repository) string PullRequest(Repository) (title, body string) }
Handler supplies mutation policy while Engine owns repository lifecycle.
type OperationLock ¶
type OperationLock struct {
// contains filtered or unexported fields
}
OperationLock prevents two processes from mutating the same operation worktrees. Higher-level planners may hold a campaign lock while individual lifecycle runs also protect their wave directories.
func AcquireOperationLock ¶
func AcquireOperationLock(githubDir, operation string, resume bool) (OperationLock, error)
AcquireOperationLock creates an exclusive lock below the operation root. An unheld remnant is reclaimable only by an explicit resume and only when its descriptor proves exact ownership of this operation.
func (OperationLock) Release ¶
func (lock OperationLock) Release() error
Release retires the exact held lock inode. It is safe to call from defer and cannot unlink a successor lock installed after this operation acquired one.
type Options ¶
type Options struct {
GitHubDir string
Operation string
Branch string
Ref string
Parallel int
DryRun bool
Resume bool
Verify bool
Checks []quality.Check
Timeout time.Duration
Retry int
// CheckPollInterval overrides the GitHub-check polling delay. A zero value
// uses the production default. It is primarily useful for deterministic
// lifecycle tests.
CheckPollInterval time.Duration
Commit bool
Push bool
PR bool
Merge bool
Progress progress.Reporter
// Prompt is recorded as the originating instruction in the WB manifest
// journal of every worktree this operation creates, satisfying wb's own
// commit-admission hook (internal/worktrees.CheckAdmission) — without it,
// a worktree this engine creates and then commits into is rejected by
// wb's own pre-commit hook as carrying no record of what it is or who
// asked for it. Normalize fills in an operation-derived default when
// empty, so every caller gets a truthful record even if it has nothing
// more specific to say.
Prompt string
// Model, AgentRuntime, Initiator, CLI, and Provider identify who or what
// asked for this operation, recorded in the same manifest for
// provenance. Normalize defaults Model to "unknown" when empty, matching
// the same explicit-over-guessed convention used everywhere else a
// child model identity is recorded (see internal/worktrees.WorkLogOptions).
Model string
AgentRuntime string
Initiator string
CLI string
Provider string
}
Options controls a repository operation independently of mutation policy.
type PullRequestWaitOptions ¶ added in v0.28.0
type PullRequestWaitOptions struct {
Repository string
PullRequest string
Target string
Head string
Slice time.Duration
CheckPollInterval time.Duration
// Progress receives completed GitHub observations. It is diagnostic only;
// callers must use the returned result as the authoritative receipt.
Progress func(PullRequestWaitProgress)
}
PullRequestWaitOptions identifies exactly one direct-push or pull-request head whose observed checks are read by a bounded foreground invocation. A caller resumes a pending result with the same repository, target, PR (when supplied), and head; any later head is a distinct integration candidate.
type PullRequestWaitProgress ¶ added in v0.50.0
type PullRequestWaitProgress struct {
Observation int
Result PullRequestWaitResult
NextPoll time.Duration
}
PullRequestWaitProgress is one completed observation inside a bounded wait.
type PullRequestWaitResult ¶ added in v0.28.0
type PullRequestWaitResult struct {
Status PullRequestWaitStatus `json:"status" yaml:"status"`
Repository string `json:"repository" yaml:"repository"`
PullRequest string `json:"pull_request,omitempty" yaml:"pull_request,omitempty"`
Target string `json:"target" yaml:"target"`
Head string `json:"head" yaml:"head"`
ObservedHead string `json:"observed_head,omitempty" yaml:"observed_head,omitempty"`
ObservedTargetHead string `json:"observed_target_head,omitempty" yaml:"observed_target_head,omitempty"`
CandidateContainsTarget bool `json:"candidate_contains_target,omitempty" yaml:"candidate_contains_target,omitempty"`
TargetFreshnessAuthority string `json:"target_freshness_authority,omitempty" yaml:"target_freshness_authority,omitempty"`
Checks []RemoteCheck `json:"checks,omitempty" yaml:"checks,omitempty"`
RequiredChecks []RequiredRemoteCheck `json:"required_checks,omitempty" yaml:"required_checks,omitempty"`
RequiredChecksAuthority string `json:"required_checks_authority,omitempty" yaml:"required_checks_authority,omitempty"`
StableObservations int `json:"stable_observations" yaml:"stable_observations"`
Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`
}
PullRequestWaitResult is one terminating foreground observation slice. Pending means resume is required, not that the merger is finished.
func WaitForCommitChecks ¶ added in v0.28.0
func WaitForCommitChecks(ctx context.Context, options PullRequestWaitOptions) (PullRequestWaitResult, error)
WaitForCommitChecks observes checks for one exact target commit. PullRequest is optional: when present it corroborates that exact PR head and target and augments the exact-head check-run/status receipt with GitHub's PR view. Every mode observes the exact commit through producer-aware APIs. Pending is an intermediate terminal result that callers resume with the same identity, not successful completion.
func WaitForPullRequestChecks ¶ added in v0.28.0
func WaitForPullRequestChecks(ctx context.Context, options PullRequestWaitOptions) (PullRequestWaitResult, error)
WaitForPullRequestChecks retains the original internal seam for existing orchestrated PR flows while using the exact-commit waiter above.
type PullRequestWaitStatus ¶ added in v0.28.0
type PullRequestWaitStatus string
PullRequestWaitStatus is intentionally small so callers can branch on a machine result instead of parsing human GitHub CLI output.
const ( PullRequestWaitPassed PullRequestWaitStatus = "passed" PullRequestWaitPending PullRequestWaitStatus = "pending" PullRequestWaitFailed PullRequestWaitStatus = "failed" )
type RemoteCheck ¶
type RemoteCheck struct {
Name string `json:"name" yaml:"name"`
Bucket string `json:"bucket" yaml:"bucket"`
Link string `json:"link,omitempty" yaml:"link,omitempty"`
AppID int64 `json:"app_id,omitempty" yaml:"app_id,omitempty"`
}
RemoteCheck is the normalized GitHub check state observed before merge.
type Repository ¶
Repository identifies a canonical clone selected by command-level discovery.
type RequiredRemoteCheck ¶ added in v0.28.0
type RequiredRemoteCheck struct {
Name string `json:"name" yaml:"name"`
IntegrationID int64 `json:"integration_id,omitempty" yaml:"integration_id,omitempty"`
}
RequiredRemoteCheck is GitHub's target-policy expectation. IntegrationID is non-zero when a ruleset pins the context to one GitHub App; every receipt must then observe the matching exact-head check-run producer, not merely a same-named PR summary or legacy status from another actor.
type ResolvedBase ¶ added in v0.59.2
type ResolvedBase struct {
// Ref is the short branch name (no "origin/" prefix).
Ref string
// Fallback is true when the operation's configured ref did not exist for
// this repository and Ref instead names its actual origin/HEAD default
// branch. Nothing about this is silent: every caller that receives a
// Fallback result is expected to surface it in its own report.
Fallback bool
}
ResolvedBase is the git ref EnsureCanonical verified exists in a repository's canonical clone. Every remaining lifecycle stage for this repository — graph inspection, worktree creation, and any eventual pull request base — must use Ref rather than the operation's configured options.Ref, since the two differ exactly when Fallback is true.
func EnsureCanonical ¶
func EnsureCanonical(ctx context.Context, repository Repository, canonical string, options Options) (ResolvedBase, error)
EnsureCanonical clones a missing repository, fetches origin, and verifies a usable base ref without checking out or modifying the canonical tree. It first tries the operation's configured options.Ref (default "main"); a fleet inevitably contains repositories whose default branch is something else (commonly "master", or a branch renamed after the local clone was made), so a repository that lacks options.Ref falls back to its actual origin/HEAD default branch instead of failing outright. A repository for which neither ref resolves still fails loudly — this is a fallback to a known-good alternative, never a silent skip.
type Result ¶
type Result[T any] struct { Repository string CanonicalDir string WorktreeDir string Branch string Ref string Status string Reason string Metadata T ChangedFiles []string Verifications []quality.VerificationEntry Commit string Pushed bool PR string Checks []RemoteCheck Merged bool }
Result records lifecycle state and typed adapter metadata for one repository.