worktree

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package worktree manages git worktree lifecycle for agent isolation. Each agent gets its own worktree at <DataDir>/agents/<name>/bc-<ws>-<name>/. Before M11 the worktrees lived under <repoRoot>/.bc/agents/...; after M11 they move to ~/.bc/workspaces/<id>/agents/... so the project directory stays a pristine git repo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager handles git worktree lifecycle for agent isolation.

func NewManager

func NewManager(repoRoot string) *Manager

NewManager creates a worktree manager whose worktrees live under the legacy <repoRoot>/.bc/agents/ directory. Prefer NewManagerWithDataDir for M11+ layouts where runtime state lives at ~/.bc/workspaces/<id>/.

This constructor is kept for older call sites and tests that still operate on the legacy layout.

func NewManagerWithDataDir added in v0.2.0

func NewManagerWithDataDir(repoRoot, dataDir string) *Manager

NewManagerWithDataDir creates a worktree manager rooted at repoRoot (the project git repo) whose worktrees live under <dataDir>/agents/. This is the M11 constructor: dataDir is the per-workspace runtime directory (~/.bc/workspaces/<id>/) and repoRoot stays untouched.

Reads BC_HOST_WORKSPACE to determine the host base name for worktree naming so containers mounting the host repo get the expected label.

func (*Manager) ClaudeDir

func (m *Manager) ClaudeDir(agentName string) string

ClaudeDir returns the path to the Claude home directory for the given agent.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, agentName string) (string, error)

Create creates a git worktree for the given agent. It prunes stale worktrees, removes any existing worktree at the path, and creates a new detached worktree to avoid branch conflicts.

func (*Manager) EnsureClaudeDir

func (m *Manager) EnsureClaudeDir(agentName string) error

EnsureClaudeDir creates the Claude home directory for the given agent if it does not already exist.

func (*Manager) Exists

func (m *Manager) Exists(agentName string) bool

Exists checks whether the worktree directory exists for the given agent.

func (*Manager) Name

func (m *Manager) Name(agentName string) string

Name returns the worktree name for an agent: bc-<hostBaseName>-<agentName>.

func (*Manager) Path

func (m *Manager) Path(agentName string) string

Path returns the filesystem path for an agent's worktree. The directory is named bc-<workspace>-<agent> so git's internal worktree name matches the naming convention.

func (*Manager) Prune

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

Prune runs git worktree prune to clean stale worktree refs.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, agentName string) error

Remove removes the git worktree for the given agent.

Jump to

Keyboard shortcuts

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