wt

package module
v0.0.0-...-b99f81e Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package wt provides Git worktree management operations.

Package wt provides Git worktree management for concurrent branch development.

Overview

wt manages multiple Git worktrees using a bare clone structure:

~/worktrees/
└── repo-name/
    ├── .bare/          # Bare clone (shared Git objects)
    ├── main/           # Worktree for main branch
    └── feature-x/      # Worktree for feature-x branch

This structure allows working on multiple branches simultaneously without stashing or switching contexts. Each worktree is a full checkout with its own working directory.

User Journeys

1. Starting with a new repository:

wt init git@github.com:user/repo.git
cd ~/worktrees/repo/main

2. Creating and maintaining a feature branch:

	wt new feature-x              # Creates from default base (main)
	wt new feature-y --from dev   # Creates from specific branch

   Staying in sync with upstream:

	wt cd feature-x
	wt sync                       # Fetch latest (shows ahead/behind)
	wt sync --rebase              # Fetch and rebase onto origin

   Cascading branches (feature-b depends on feature-a):

	wt new feature-a              # First feature from main
	wt new feature-b --from feature-a  # Second feature from first

   When feature-a is updated, rebase feature-b:

	wt cd feature-b
	git rebase feature-a          # Rebase onto updated parent

   After PR is merged:

	wt cd main
	git pull                      # Update main with merged changes
	wt rm feature-x -D            # Remove worktree + delete branch

   If you have cascading branches after parent merges:

	wt cd feature-b
	git rebase main               # Rebase onto main (parent is now in main)
	git push --force-with-lease   # Update remote

3. Opening an existing remote branch:

wt open existing-branch

4. Day-to-day navigation:

wt ls                         # List worktrees in current repo
wt ls -a                      # List all repos
wt cd feature-x               # Navigate to worktree
wt status                     # Show sync/dirty status
wt sync                       # Fetch all branches

5. Cleanup:

wt rm feature-x               # Remove worktree only
wt rm feature-x -D            # Remove worktree + delete branch

Shell Integration

Add to ~/.bashrc or ~/.zshrc:

eval "$(wt shellenv)"

This enables `wt cd` to change your shell's working directory.

Configuration

Create .wt.yaml in your repository root:

default_base: main
# Legacy names
post_create:
  - npm install
post_remove:
  - echo "cleaned up"
# Bramble names
on_worktree_create:
  - npm install
on_worktree_delete:
  - echo "cleaned up"

SECURITY WARNING: Hooks in .wt.yaml are executed automatically during init, new, open, and rm operations with no confirmation prompt. Only use wt with repositories you trust. A malicious .wt.yaml can execute arbitrary shell commands on your machine.

Library Usage

m := wt.NewManager("~/worktrees", "repo-name")

// Initialize a new repo
mainPath, err := m.Init(ctx, "git@github.com:user/repo.git")

// Create a new branch worktree
path, err := m.New(ctx, "feature-x", "main")

// List and check status
worktrees, _ := m.List(ctx)
for _, w := range worktrees {
    status, _ := m.GetStatus(ctx, w)
    fmt.Printf("%s: dirty=%v ahead=%d\n", w.Branch, status.IsDirty, status.Ahead)
}

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorBold   = "\033[1m"
	ColorDim    = "\033[2m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorCyan   = "\033[36m"
)

ANSI color codes.

Variables

View Source
var (
	ErrRepoNotInitialized = errors.New("repository not initialized")
	ErrWorktreeExists     = errors.New("worktree already exists")
	ErrWorktreeNotFound   = errors.New("worktree not found")
	ErrBranchNotFound     = errors.New("branch not found on remote")
)

Common errors.

View Source
var ErrGitHubAuthRequired = errors.New("GitHub authentication required: run 'gh auth login' to authenticate")

ErrGitHubAuthRequired indicates that GitHub authentication is needed.

Functions

func CheckGitHubAuth

func CheckGitHubAuth(ctx context.Context, runner GHRunner) error

CheckGitHubAuth verifies that the user is authenticated with GitHub CLI.

func GetBranchDescription

func GetBranchDescription(ctx context.Context, runner GitRunner, branch, dir string) (string, error)

GetBranchDescription gets the description for a branch.

func GetBranchGoal

func GetBranchGoal(ctx context.Context, runner GitRunner, branch, dir string) (string, error)

GetBranchGoal gets the goal for a branch.

func GetCurrentRepoName

func GetCurrentRepoName(ctx context.Context, runner GitRunner, root string) (string, error)

GetCurrentRepoName determines the repository name from the current directory. It first checks if we're in a wt-managed worktree, then falls back to git remote.

func GetDefaultBranch

func GetDefaultBranch(ctx context.Context, runner GitRunner, repoPath string) (string, error)

GetDefaultBranch returns the default branch for a repository.

func GetRepoNameFromURL

func GetRepoNameFromURL(url string) string

GetRepoNameFromURL extracts the repository name from a Git URL.

func IsAuthError

func IsAuthError(stderr string) bool

IsAuthError checks if command output indicates an authentication failure.

func IsPRMerged

func IsPRMerged(ctx context.Context, runner GHRunner, branch, dir string) (bool, error)

IsPRMerged checks if the PR for a branch is merged.

func ListAllRepos

func ListAllRepos(root string) ([]string, error)

ListAllRepos lists all wt-managed repository names under the given root.

func Pad

func Pad(s string, width int) string

Pad pads a string (which may contain ANSI codes) to the specified visible width.

func RemoteBranchExists

func RemoteBranchExists(ctx context.Context, runner GitRunner, branch, dir string) (bool, error)

RemoteBranchExists checks if a branch exists on the remote.

func RunHooks

func RunHooks(commands []string, worktreePath, branch string, output *Output) error

RunHooks executes hook commands in a worktree.

func SetBranchDescription

func SetBranchDescription(ctx context.Context, runner GitRunner, branch, description, dir string) error

SetBranchDescription sets the description for a branch.

func SetBranchGoal

func SetBranchGoal(ctx context.Context, runner GitRunner, branch, goal, dir string) error

SetBranchGoal sets the goal for a branch.

func SetDefaultColorMode

func SetDefaultColorMode(m ColorMode)

SetDefaultColorMode pins the color preference used by DefaultOutput. Intended to be called once from main.

func UpdatePRBase

func UpdatePRBase(ctx context.Context, runner GHRunner, prNumber int, newBase, dir string) error

UpdatePRBase changes the base branch of a PR.

Types

type AtomicOp

type AtomicOp struct {
	// contains filtered or unexported fields
}

AtomicOp represents a worktree operation that can be rolled back. It accumulates undo steps as sub-operations succeed, and executes them in reverse order on failure.

func (*AtomicOp) AddUndo

func (op *AtomicOp) AddUndo(fn func(ctx context.Context) error)

AddUndo registers a rollback step. Steps are executed in reverse order on Rollback.

func (*AtomicOp) Commit

func (op *AtomicOp) Commit()

Commit marks the operation as successful. Rollback becomes a no-op after this.

func (*AtomicOp) Rollback

func (op *AtomicOp) Rollback(ctx context.Context) error

Rollback executes all undo steps in reverse order. Returns the first error encountered but continues rolling back all steps. If the operation was committed, Rollback is a no-op.

type BranchDependency

type BranchDependency struct {
	Branch       string
	BaseBranch   string
	WorktreePath string
	PRNumber     int
	HasWorktree  bool
}

BranchDependency represents a branch that depends on another.

type CmdResult

type CmdResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

CmdResult holds command execution results.

type ColorMode

type ColorMode int

ColorMode controls whether DefaultOutput emits ANSI color codes.

const (
	// ColorAuto colorizes when stdout is a terminal and NO_COLOR is unset.
	ColorAuto ColorMode = iota
	// ColorAlways always colorizes.
	ColorAlways
	// ColorNever never colorizes.
	ColorNever
)

type CommitInfo

type CommitInfo struct {
	Date    time.Time `json:"date"`
	Hash    string    `json:"hash"`
	Subject string    `json:"subject"`
	Author  string    `json:"author"`
}

CommitInfo holds information about a single commit.

type ContextOptions

type ContextOptions struct {
	IncludeCommits  int
	MaxDiffBytes    int
	IncludeDiff     bool
	IncludeDiffStat bool
	IncludeFileList bool
	IncludePRInfo   bool
}

ContextOptions controls what data to gather for a WorktreeContext.

func DefaultContextOptions

func DefaultContextOptions() ContextOptions

DefaultContextOptions returns options suitable for agent consumption.

type DefaultGHRunner

type DefaultGHRunner struct{}

DefaultGHRunner implements GHRunner using os/exec.

func (*DefaultGHRunner) Run

func (r *DefaultGHRunner) Run(ctx context.Context, args []string, dir string) (*CmdResult, error)

Run executes a gh command.

type DefaultGitRunner

type DefaultGitRunner struct{}

DefaultGitRunner implements GitRunner using os/exec.

func (*DefaultGitRunner) Run

func (r *DefaultGitRunner) Run(ctx context.Context, args []string, dir string) (*CmdResult, error)

Run executes a git command.

type GCOptions

type GCOptions struct {
	DryRun         bool // Preview only, no changes
	DeleteBranches bool // Delete orphaned local branches
	DeleteRemote   bool // Also delete remote branches (requires DeleteBranches)
	MergedPRs      bool // Also remove worktrees whose GitHub PRs are merged
}

GCOptions configures garbage collection behavior.

type GCResult

type GCResult struct {
	PrunedWorktrees  []string // Lines from git worktree prune
	MergedWorktrees  []string // Worktrees removed because their PR was merged
	OrphanedBranches []string // Local branches with no worktree
	DeletedBranches  []string // Actually deleted local branches
	DeletedRemote    []string // Actually deleted remote branches
	FetchPruned      bool     // Whether fetch --prune ran
	GCRan            bool     // Whether git gc ran
}

GCResult contains the results of garbage collection.

type GHRunner

type GHRunner interface {
	Run(ctx context.Context, args []string, dir string) (*CmdResult, error)
}

GHRunner executes gh CLI commands.

type GitRunner

type GitRunner interface {
	Run(ctx context.Context, args []string, dir string) (*CmdResult, error)
}

GitRunner executes git commands.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles worktree operations for a repository.

func NewManager

func NewManager(root, repoName string, opts ...Option) *Manager

NewManager creates a Manager for the given repository.

func (*Manager) BareDir

func (m *Manager) BareDir() string

BareDir returns the path to the bare repository.

func (*Manager) CreatePR

func (m *Manager) CreatePR(ctx context.Context, opts PROptions) (*PRResult, error)

CreatePR pushes the current branch and creates a GitHub PR. Base branch is auto-detected: parent branch for cascading, otherwise default.

func (*Manager) FetchAllPRInfo

func (m *Manager) FetchAllPRInfo(ctx context.Context, dir string) ([]PRInfo, error)

FetchAllPRInfo fetches all open PRs in a single API call. dir must be a valid Git worktree path (not the bare repo parent) because gh requires a Git repository context.

func (*Manager) FetchOrigin

func (m *Manager) FetchOrigin(ctx context.Context) error

FetchOrigin fetches the default branch from origin for this repo's bare clone. Call this before parallel New calls to avoid concurrent git-fetch conflicts.

func (*Manager) FetchPRInfo

func (m *Manager) FetchPRInfo(ctx context.Context, wt Worktree) (*PRInfo, error)

FetchPRInfo fetches PR information for a worktree via the GitHub CLI. This makes a network call and may be slow.

func (*Manager) GC

func (m *Manager) GC(ctx context.Context, opts GCOptions) (*GCResult, error)

GC performs comprehensive garbage collection: prunes stale worktree metadata, fetches and prunes remote refs, detects and optionally deletes orphaned branches, and runs git gc.

func (*Manager) GatherContext

func (m *Manager) GatherContext(ctx context.Context, wt Worktree, opts ContextOptions) (*WorktreeContext, error)

GatherContext collects structured context about a worktree.

func (*Manager) GetAllGitStatuses

func (m *Manager) GetAllGitStatuses(ctx context.Context, worktrees []Worktree) (map[string]*WorktreeStatus, error)

GetAllGitStatuses returns local git status for worktrees with bounded subprocess concurrency. Each worktree uses a single git status invocation.

func (*Manager) GetAllWorktreeInfo

func (m *Manager) GetAllWorktreeInfo(ctx context.Context) ([]*WorktreeInfo, error)

GetAllWorktreeInfo returns extended information for all worktrees.

func (*Manager) GetGitStatus

func (m *Manager) GetGitStatus(ctx context.Context, wt Worktree) (*WorktreeStatus, error)

GetGitStatus returns local git status for a worktree (no network calls). This is fast and suitable for UI that needs immediate feedback.

func (*Manager) GetGoal

func (m *Manager) GetGoal(ctx context.Context, branch, dir string) (string, error)

GetGoal returns the goal for a branch in a worktree. If the current branch has no goal config, it falls back to checking the directory name, which handles the case where the user ran `git checkout -b` inside a worktree.

func (*Manager) GetParentBranch

func (m *Manager) GetParentBranch(ctx context.Context, branch, dir string) (string, error)

GetParentBranch returns the parent branch for a given branch if tracked. If the current branch has no parent config, it falls back to checking the directory name (the original branch the worktree was created for), which handles the case where the user ran `git checkout -b` inside a worktree.

func (*Manager) GetStatus

func (m *Manager) GetStatus(ctx context.Context, wt Worktree) (*WorktreeStatus, error)

GetStatus returns extended status for a worktree including PR info. This makes a network call for PR info; use GetGitStatus for local-only status.

func (*Manager) GetWorktreeByBranch

func (m *Manager) GetWorktreeByBranch(ctx context.Context, branch string) (*Worktree, error)

GetWorktreeByBranch returns a Worktree by branch name.

func (*Manager) GetWorktreeInfo

func (m *Manager) GetWorktreeInfo(ctx context.Context, branch string) (*WorktreeInfo, error)

GetWorktreeInfo returns extended information about a worktree.

func (*Manager) GetWorktreePath

func (m *Manager) GetWorktreePath(branch string) (string, error)

GetWorktreePath returns the path to a worktree by branch name.

func (*Manager) GitRunner

func (m *Manager) GitRunner() GitRunner

GitRunner returns the git runner used by this manager.

func (*Manager) Init

func (m *Manager) Init(ctx context.Context, url string) (string, error)

Init initializes a new repository with a bare clone.

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Worktree, error)

List returns all worktrees for the repository.

func (*Manager) MergePR

func (m *Manager) MergePR(ctx context.Context, opts MergeOptions) error

MergePR merges the PR for the current worktree and handles cleanup.

func (*Manager) MergePRForBranch

func (m *Manager) MergePRForBranch(ctx context.Context, branch string, opts MergeOptions) (int, error)

MergePRForBranch merges the PR for the given branch. Unlike MergePR, it does not rely on os.Getwd() and always keeps the worktree (caller handles cleanup).

func (*Manager) New

func (m *Manager) New(ctx context.Context, branch, baseBranch, goal string, opts ...NewOptions) (string, error)

New creates a new worktree with a new branch.

func (*Manager) NewAtomic

func (m *Manager) NewAtomic(ctx context.Context, branch, baseBranch, goal string, opts ...NewOptions) (string, error)

NewAtomic creates a worktree with rollback on failure. If any step fails, all previously completed steps are undone, leaving no orphaned worktrees or branches.

Note: post_create hook failures are non-fatal. The worktree remains created; hooks are side-effectful by nature and may not be safely reversible.

func (*Manager) NewAtomicOp

func (m *Manager) NewAtomicOp() *AtomicOp

NewAtomicOp creates a new atomic operation context.

func (*Manager) Open

func (m *Manager) Open(ctx context.Context, branch, goal string) (string, error)

Open creates a worktree for an existing remote branch.

func (*Manager) Prune

func (m *Manager) Prune(ctx context.Context, opts PruneOptions) (*PruneResult, error)

Prune cleans stale worktree metadata and optionally removes worktrees whose GitHub PRs have been merged.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, nameOrBranch string, deleteBranch bool, force bool) error

Remove removes a worktree by name (directory) or branch name. If deleteBranch is true, the local and remote branch are deleted after the worktree is removed. If force is true, passes --force to git worktree remove, allowing removal of worktrees with modified or untracked files (equivalent to git worktree remove --force).

func (*Manager) RepoDir

func (m *Manager) RepoDir() string

RepoDir returns the path to the repository root.

func (*Manager) SetGoal

func (m *Manager) SetGoal(ctx context.Context, branch, goal, dir string) error

SetGoal sets the goal for a branch in a worktree.

func (*Manager) Sync

func (m *Manager) Sync(ctx context.Context, branch string, opts ...SyncOptions) error

Sync fetches the latest changes and rebases worktrees. If branch is non-empty, only that worktree is synced. If branch is empty, all worktrees in the repo are synced.

func (*Manager) SyncDefaultBranch

func (m *Manager) SyncDefaultBranch(ctx context.Context)

SyncDefaultBranch fast-forwards the local default branch to match origin. This keeps the main worktree current when creating new worktrees. It's safe to call even if the main worktree doesn't exist (no-op in that case). All errors are handled internally; the function is intentionally best-effort.

type MergeOptions

type MergeOptions struct {
	MergeMethod string
	Keep        bool
}

MergeOptions configures the merge operation.

type NewOptions

type NewOptions struct {
	SkipFetch bool // skip git-fetch (caller already fetched)
}

NewOptions configures optional behavior for New.

type Option

type Option func(*Manager)

Option configures a Manager.

func WithGHRunner

func WithGHRunner(r GHRunner) Option

WithGHRunner sets a custom gh runner.

func WithGitRunner

func WithGitRunner(r GitRunner) Option

WithGitRunner sets a custom git runner.

func WithOutput

func WithOutput(o *Output) Option

WithOutput sets a custom output writer.

type Output

type Output struct {
	// contains filtered or unexported fields
}

Output provides colored console output.

func DefaultOutput

func DefaultOutput() *Output

DefaultOutput creates an Output for stdout, honoring the color mode set via SetDefaultColorMode (ColorAuto by default).

func NewOutput

func NewOutput(w io.Writer, colorized bool) *Output

NewOutput creates an Output that writes to w. If colorized is true, output will include ANSI color codes.

func (*Output) Colorize

func (o *Output) Colorize(color, text string) string

Colorize wraps text with the given color code.

func (*Output) Error

func (o *Output) Error(msg string)

Error prints an error message with a red X.

func (*Output) Info

func (o *Output) Info(msg string)

Info prints an info message with a dim arrow.

func (*Output) Print

func (o *Output) Print(msg string)

Print prints a message without any prefix.

func (*Output) Printf

func (o *Output) Printf(format string, args ...any)

Printf prints a formatted message without any prefix.

func (*Output) Success

func (o *Output) Success(msg string)

Success prints a success message with a green checkmark.

func (*Output) Warn

func (o *Output) Warn(msg string)

Warn prints a warning message with a yellow exclamation.

func (*Output) Writer

func (o *Output) Writer() io.Writer

Writer returns the underlying writer for direct output.

type PRInfo

type PRInfo struct {
	URL            string `json:"url"`
	HeadRefName    string `json:"headRefName"`
	BaseRefName    string `json:"baseRefName"`
	State          string `json:"state"` // OPEN, CLOSED, MERGED
	ReviewDecision string `json:"reviewDecision"`
	Number         int    `json:"number"`
	IsDraft        bool   `json:"isDraft"`
}

PRInfo holds GitHub PR information.

func CreatePR

func CreatePR(ctx context.Context, runner GHRunner, title, body, base, head string, draft bool, dir string) (*PRInfo, error)

CreatePR creates a new GitHub PR using the REST API (gh api). The head parameter is the branch name containing the changes. The dir parameter is used by gh to resolve {owner}/{repo} from git remotes.

func GetPRByBranch

func GetPRByBranch(ctx context.Context, runner GHRunner, branch, dir string) (*PRInfo, error)

GetPRByBranch fetches PR information for a specific branch.

func GetPRForBranch

func GetPRForBranch(ctx context.Context, runner GHRunner, dir string) (*PRInfo, error)

GetPRForBranch fetches PR information for the current branch.

func ListMergedPRs

func ListMergedPRs(ctx context.Context, runner GHRunner, dir string) ([]PRInfo, error)

ListMergedPRs returns recently merged PRs in the repository. Uses --limit 200 to cover typical worktree counts without excessive pagination.

func ListOpenPRs

func ListOpenPRs(ctx context.Context, runner GHRunner, dir string) ([]PRInfo, error)

ListOpenPRs returns all open PRs in the repository with full details. Uses --limit 1000 to avoid gh's default cap of 30 results.

func (*PRInfo) IsMergeable

func (p *PRInfo) IsMergeable() bool

IsMergeable returns true if the PR is approved and all checks pass.

type PROptions

type PROptions struct {
	Title  string
	Body   string
	Base   string // Override auto-detected base
	Draft  bool
	NoPush bool
}

PROptions configures PR creation.

type PRResult

type PRResult struct {
	URL     string
	Branch  string
	Base    string
	Number  int
	Existed bool
}

PRResult contains the result of PR creation.

type PruneOptions

type PruneOptions struct {
	DryRun    bool // Preview only, no changes
	MergedPRs bool // Also remove worktrees whose GitHub PRs are merged
}

PruneOptions configures prune behavior.

type PruneResult

type PruneResult struct {
	StaleWorktrees  []string // Lines from git worktree prune
	MergedWorktrees []string // Worktrees removed because their PR was merged
}

PruneResult contains the results of pruning.

type RepoConfig

type RepoConfig struct {
	DefaultBase      string   `yaml:"default_base"`
	PostCreate       []string `yaml:"post_create"`
	PostRemove       []string `yaml:"post_remove"`
	OnWorktreeCreate []string `yaml:"on_worktree_create"`
	OnWorktreeDelete []string `yaml:"on_worktree_delete"`
}

RepoConfig holds per-repository configuration from .wt.yaml.

func LoadRepoConfig

func LoadRepoConfig(repoPath string) (*RepoConfig, error)

LoadRepoConfig loads .wt.yaml from a repository path. Returns a default config if the file doesn't exist.

func (*RepoConfig) WorktreeCreateCommands

func (c *RepoConfig) WorktreeCreateCommands() []string

WorktreeCreateCommands returns commands that should run after creating a worktree. It supports both legacy wt keys and bramble-specific keys.

func (*RepoConfig) WorktreeDeleteCommands

func (c *RepoConfig) WorktreeDeleteCommands() []string

WorktreeDeleteCommands returns commands that should run before deleting a worktree. It supports both legacy wt keys and bramble-specific keys.

type StatusCheck

type StatusCheck struct {
	State string `json:"state"` // SUCCESS, FAILURE, PENDING
}

StatusCheck represents a CI status check.

type SyncOptions

type SyncOptions struct {
	FetchAll bool // fetch all remote branches instead of only the default branch
}

SyncOptions configures optional behavior for Sync.

type Worktree

type Worktree struct {
	Path       string
	Branch     string
	Commit     string
	IsDetached bool
	// IsGone is true when git knows about the worktree but its directory no
	// longer exists on disk (e.g. removed via `rm -rf` or `git worktree remove`).
	IsGone bool
}

Worktree represents a Git worktree.

func (*Worktree) Name

func (w *Worktree) Name() string

Name returns the worktree name (directory name).

type WorktreeContext

type WorktreeContext struct {
	GatheredAt     time.Time    `json:"gathered_at"`
	PRState        string       `json:"pr_state,omitempty"`
	Path           string       `json:"path"`
	Goal           string       `json:"goal,omitempty"`
	Parent         string       `json:"parent,omitempty"`
	DiffStat       string       `json:"diff_stat,omitempty"`
	DiffContent    string       `json:"diff_content,omitempty"`
	Branch         string       `json:"branch"`
	PRURL          string       `json:"pr_url,omitempty"`
	ChangedFiles   []string     `json:"changed_files,omitempty"`
	UntrackedFiles []string     `json:"untracked_files,omitempty"`
	RecentCommits  []CommitInfo `json:"recent_commits,omitempty"`
	Ahead          int          `json:"ahead"`
	PRNumber       int          `json:"pr_number,omitempty"`
	Behind         int          `json:"behind"`
	IsDirty        bool         `json:"is_dirty"`
}

WorktreeContext provides structured context about a worktree for agent consumption. When an agent runs in a worktree, this type automatically provides the tree's diffs, changed files, branch history, and PR status.

func (*WorktreeContext) FormatForPrompt

func (wc *WorktreeContext) FormatForPrompt() string

FormatForPrompt formats the WorktreeContext as structured text suitable for inclusion in an agent's system prompt or message.

type WorktreeInfo

type WorktreeInfo struct {
	LastCommitTime time.Time
	Goal           string
	Parent         string
	PRState        string
	PRURL          string
	LastCommitMsg  string
	Worktree       Worktree
	Ahead          int
	Behind         int
	PRNumber       int
	IsMerged       bool
	IsAhead        bool
	IsDirty        bool
}

WorktreeInfo contains extended information about a worktree. This combines Worktree data with branch metadata like goals and parent.

type WorktreeStatus

type WorktreeStatus struct {
	LastCommitTime time.Time
	LastCommitMsg  string
	PRURL          string
	PRState        string // OPEN, MERGED, CLOSED
	PRReviewStatus string // APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED, etc.
	Worktree       Worktree
	Ahead          int
	Behind         int
	PRNumber       int
	IsDirty        bool
	PRIsDraft      bool
}

WorktreeStatus holds extended status for a worktree.

Directories

Path Synopsis
cmd
wt command
wt - Git worktree CLI for power users managing multiple concurrent branches.
wt - Git worktree CLI for power users managing multiple concurrent branches.
Package taskrouter provides AI-powered routing for task-to-worktree assignment.
Package taskrouter provides AI-powered routing for task-to-worktree assignment.

Jump to

Keyboard shortcuts

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