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 ¶
- type Manager
- func (m *Manager) ClaudeDir(agentName string) string
- func (m *Manager) Create(ctx context.Context, agentName string) (string, error)
- func (m *Manager) EnsureClaudeDir(agentName string) error
- func (m *Manager) Exists(agentName string) bool
- func (m *Manager) Name(agentName string) string
- func (m *Manager) Path(agentName string) string
- func (m *Manager) Prune(ctx context.Context) error
- func (m *Manager) Remove(ctx context.Context, agentName string) error
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 ¶
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
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 ¶
ClaudeDir returns the path to the Claude home directory for the given agent.
func (*Manager) Create ¶
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 ¶
EnsureClaudeDir creates the Claude home directory for the given agent if it does not already exist.
func (*Manager) Path ¶
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.