Documentation
¶
Overview ¶
Package worktree owns the git worktree lifecycle and diff capture, all through the Executor interface so it works identically on every target kind.
Index ¶
- func AddExcludes(ctx context.Context, ex executor.Executor, repoDir string) error
- func BranchName(taskID int64, attemptN int) string
- func Commit(ctx context.Context, ex executor.Executor, dir, branch string, o CommitOptions) ([]map[string]any, error)
- func CommitPushPR(ctx context.Context, ex executor.Executor, dir, branch, message string, ...) ([]map[string]any, error)
- func DefaultWorkroot(repoPath string) string
- func Ensure(ctx context.Context, ex executor.Executor, ...) error
- func ForcePushWithLease(ctx context.Context, ex executor.Executor, dir, branch, lease string) (map[string]any, error)
- func IntentToAddUntracked(dir string) string
- func IsGitRepo(ctx context.Context, ex executor.Executor, dir string) bool
- func MergeBase(ctx context.Context, ex executor.Executor, wt, baseRef string) (string, error)
- func NamespacedBranch(branch, namespace string) string
- func NamespacedWorkroot(workroot, namespace string) string
- func Path(workroot string, taskID int64, attemptN int) string
- func Push(ctx context.Context, ex executor.Executor, dir, branch string) (map[string]any, error)
- func PushedRefs(ctx context.Context, ex executor.Executor, dir string) ([]string, error)
- func Remove(ctx context.Context, ex executor.Executor, repo, path string) error
- func RunInteractive(ctx context.Context, ex executor.Executor, action string, plan *Interactive) error
- func RunInteractiveWithTimeout(ctx context.Context, ex executor.Executor, action string, plan *Interactive, ...) error
- type CommitOptions
- type ErrAmendPushed
- type FilePatch
- type FileStat
- type Interactive
- type InteractiveOptions
- type RepositorySelection
- type RepositorySource
- type StepError
- type WorkspaceRepository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddExcludes ¶
AddExcludes keeps our runtime dir and verify-run artifacts out of git status/diff/commit. Verify artifacts leaking into `git add -A` was a real bug found only on a live dispatch.
func BranchName ¶
BranchName is the branch one attempt works on.
func Commit ¶ added in v2.6.0
func Commit(ctx context.Context, ex executor.Executor, dir, branch string, o CommitOptions) ([]map[string]any, error)
Commit is CommitPushPR with the review workspace's options. The commit step fails as a StepError (409) exactly like CommitPushPR's.
func CommitPushPR ¶ added in v2.4.0
func CommitPushPR(ctx context.Context, ex executor.Executor, dir, branch, message string, push, pr bool, prTitle, prBody string) ([]map[string]any, error)
CommitPushPR runs `git add -A && git commit`, an optional push and an optional `gh pr create`, in dir on branch. It is the one place the task and session Commit buttons and the CI loop's own fix commits touch git, so a fix to one path fixes all of them. A push or PR step that runs but fails is recorded in steps and does not abort, except a failed push always cancels a requested PR (never open a PR for a branch that didn't reach origin).
func DefaultWorkroot ¶
DefaultWorkroot puts worktrees beside the repo, not inside it.
func Ensure ¶
Ensure creates the attempt's worktree, tolerating one that already exists — follow-up attempts and the reviewer gate deliberately reuse it.
func ForcePushWithLease ¶ added in v2.6.0
func ForcePushWithLease(ctx context.Context, ex executor.Executor, dir, branch, lease string) (map[string]any, error)
ForcePushWithLease pushes branch with --force-with-lease, pinned to lease (the remote commit the caller last saw) when one is given, so a push that would discard someone else's newer work fails instead.
func IntentToAddUntracked ¶ added in v2.6.0
IntentToAddUntracked is the command that marks every untracked, not ignored file in dir as intent-to-add, and nothing else.
func IsGitRepo ¶ added in v2.4.0
IsGitRepo reports whether dir is inside a git working tree. Used before a live diff or commit so a plain (non-git) workdir gets a clear error instead of a confusing git failure three commands later.
func MergeBase ¶ added in v2.4.0
MergeBase resolves the commit a worktree's HEAD shares with baseRef, so a live diff shows only what the worktree actually changed even if baseRef has moved on since the worktree branched from it. Returns "" (not an error) when git can't resolve one — an unborn branch, or baseRef missing entirely — so callers can fall back to diffing against baseRef directly.
func NamespacedBranch ¶
NamespacedBranch scopes an automatically-created branch to one runtime.
func NamespacedWorkroot ¶
NamespacedWorkroot keeps automatically-created allocations from separate control-plane instances out of one another's default directory.
func Push ¶ added in v2.4.0
Push runs `git push -u origin <branch>` in dir and reports it as a step. A push that runs and fails is a step with a non-zero "rc", not an error.
func PushedRefs ¶ added in v2.6.0
PushedRefs lists the remote-tracking branches that already contain HEAD. A commit on any of them is published; amending it rewrites history someone else may have.
func RunInteractive ¶
Types ¶
type CommitOptions ¶ added in v2.6.0
type CommitOptions struct {
Message string
// StageAll runs `git add -A` first; otherwise only what is staged is
// committed.
StageAll bool
Amend bool
// AllowPushedAmend overrides the guard that refuses to amend a commit a
// remote branch already contains.
AllowPushedAmend bool
Push bool
// ForceWithLease pushes with --force-with-lease. Lease, when set, is the
// remote commit the caller last saw; the push fails if origin moved.
ForceWithLease bool
Lease string
PR bool
PRTitle string
PRBody string
}
CommitOptions is the review workspace's commit: the index as staged or everything, optionally amending HEAD, then an optional push (plain or force-with-lease) and PR.
type ErrAmendPushed ¶ added in v2.6.0
type ErrAmendPushed struct{ Refs []string }
ErrAmendPushed is the amend guard's refusal. Refs names the remote branches that already contain HEAD.
func (*ErrAmendPushed) Error ¶ added in v2.6.0
func (e *ErrAmendPushed) Error() string
type FilePatch ¶
FilePatch is one file's slice of a unified diff, for the mobile viewer.
func SplitPatch ¶
SplitPatch slices a unified diff into per-file chunks.
type FileStat ¶
type FileStat struct {
Path string `json:"path"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}
FileStat is one file's line churn in a captured diff.
type Interactive ¶
type Interactive struct {
OperationActive bool `json:"operation_active,omitempty"`
ControlToken string `json:"control_token,omitempty"`
SetupCommand string `json:"setup_command,omitempty"`
SetupEnv map[string]string `json:"setup_env,omitempty"`
SetupState string `json:"setup_state,omitempty"`
SetupOutput string `json:"setup_output,omitempty"`
Repo string `json:"repo"`
Path string `json:"path"`
Branch string `json:"branch"`
Base string `json:"base"`
Commit string `json:"commit"`
Token string `json:"token,omitempty"`
State string `json:"state"`
Error string `json:"error,omitempty"`
Repositories []WorkspaceRepository `json:"repositories,omitempty"`
}
Interactive records an allocation before any remote Git mutation. A failed launch keeps this record so the directory is still discoverable and removable.
func PlanInteractive ¶
func PlanInteractive(repo string, id int64, o InteractiveOptions) *Interactive
func PlanMultiWorkspace ¶
func PlanMultiWorkspace(sources []RepositorySource, id int64, options InteractiveOptions) (*Interactive, error)
PlanMultiWorkspace creates only a plan. It never touches Git or the filesystem. Each repository has its own ownership token, base and allocation state.
func PlanWorkspaceExtension ¶
func PlanWorkspaceExtension(existing *Interactive, source RepositorySource, id int64) (*Interactive, error)
PlanWorkspaceExtension preserves existing ownership and stages one new child. The worker must validate the complete plan against the live root receipt.
func (*Interactive) HasSetupCommand ¶
func (p *Interactive) HasSetupCommand() bool
HasSetupCommand gives package installation a longer overall setup deadline.
func (*Interactive) RedactOwnership ¶
func (p *Interactive) RedactOwnership()
RedactOwnership removes all allocation tokens before an API response. It is applied to a decoded copy, never to the persisted ownership records.
type InteractiveOptions ¶
type InteractiveOptions struct {
Base string `json:"base"`
Branch string `json:"branch"`
Namespace string `json:"-"`
Workroot string `json:"-"`
ExtraRepositories []RepositorySelection `json:"extra_repositories,omitempty"`
}
type RepositorySelection ¶
type RepositorySource ¶
type RepositorySource struct {
Name, Repo, Base string
SetupCommand string
SetupEnv map[string]string
ProjectID *int64
}
RepositorySource is resolved from registered projects on one target before planning; paths and Git identities must still be verified on that target.
type StepError ¶ added in v2.4.0
StepError is a git/gh step that ran and failed on its own terms (bad commit, a real merge conflict) as opposed to the executor itself failing — the former is the caller's to fix and maps to 409, the latter is ours and maps through respondErr like any other infrastructure error.
type WorkspaceRepository ¶
type WorkspaceRepository struct {
Name string `json:"name"`
ProjectID *int64 `json:"project_id,omitempty"`
Worktree *Interactive `json:"worktree"`
}
WorkspaceRepository records each allocation independently, including a failed or removed one. The enclosing workspace owns the root directory separately.