worktree

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 11 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 worktree owns the git worktree lifecycle and diff capture, all through the Executor interface so it works identically on every target kind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddExcludes

func AddExcludes(ctx context.Context, ex executor.Executor, repoDir string) error

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

func BranchName(taskID int64, attemptN int) string

BranchName is the branch one attempt works on.

func DefaultWorkroot

func DefaultWorkroot(repoPath string) string

DefaultWorkroot puts worktrees beside the repo, not inside it.

func Ensure

func Ensure(ctx context.Context, ex executor.Executor, repo, baseBranch, branch, path string) error

Ensure creates the attempt's worktree, tolerating one that already exists — follow-up attempts and the reviewer gate deliberately reuse it.

func NamespacedBranch

func NamespacedBranch(branch, namespace string) string

NamespacedBranch scopes an automatically-created branch to one runtime.

func NamespacedWorkroot

func NamespacedWorkroot(workroot, namespace string) string

NamespacedWorkroot keeps automatically-created allocations from separate control-plane instances out of one another's default directory.

func Path

func Path(workroot string, taskID int64, attemptN int) string

Path is where one attempt's worktree lives under a workroot.

func Remove

func Remove(ctx context.Context, ex executor.Executor, repo, path string) error

Remove reclaims a worktree.

func RunInteractive

func RunInteractive(ctx context.Context, ex executor.Executor, action string, plan *Interactive) error

func RunInteractiveWithTimeout

func RunInteractiveWithTimeout(ctx context.Context, ex executor.Executor, action string, plan *Interactive, timeout float64) error

Types

type FilePatch

type FilePatch struct {
	Path  string `json:"path"`
	Patch string `json:"patch"`
}

FilePatch is one file's slice of a unified diff, for the mobile viewer.

func SplitPatch

func SplitPatch(patch string) []FilePatch

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.

func CaptureDiff

func CaptureDiff(ctx context.Context, ex executor.Executor, wt, baseBranch string) (string, []FileStat, error)

CaptureDiff returns the full patch plus per-file stats of everything the attempt changed against its base branch.

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 RepositorySelection struct {
	ProjectID int64  `json:"project_id"`
	Base      string `json:"base,omitempty"`
}

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 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.

Jump to

Keyboard shortcuts

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