worktree

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DescriptionEnterWorktree = "Creates an isolated worktree (via git or configured hooks) and switches the session into it"

Descriptions

View Source
const DescriptionExitWorktree = "Exits a worktree session created by EnterWorktree and restores the original working directory"
View Source
const EnterWorktreePrompt = `` /* 1485-byte string literal not displayed */

EnterWorktreePrompt is the system prompt for the EnterWorktree tool.

View Source
const ExitWorktreePrompt = `` /* 1250-byte string literal not displayed */

ExitWorktreePrompt is the system prompt for the ExitWorktree tool.

View Source
const SearchHintEnterWorktree = "create an isolated git worktree and switch into it"

Search hints

View Source
const SearchHintExitWorktree = "exit a worktree session and return to the original directory"
View Source
const ToolNameEnterWorktree = "enter_worktree"

Tool names

View Source
const ToolNameExitWorktree = "exit_worktree"
View Source
const WorktreeDirPrefix = ".worktree-"

Worktree directory prefix

Variables

View Source
var DefaultWorktreeConfig = WorktreeConfig{
	UseGitWorktree: true,
	CreateBranch:   true,
	DeleteWorktree: true,
}

Default worktree config

Functions

func FindGitRoot

func FindGitRoot(cwd string) (string, error)

FindGitRoot finds the canonical git root directory

func GenerateWorktreeName

func GenerateWorktreeName(slug string) string

GenerateWorktreeName generates a worktree name from a slug

func SetSession

func SetSession(id types.SessionID, s *WorktreeSession)

SetSession stores (or removes, when s == nil) the WorktreeSession for id.

func ValidateWorktreeSlug

func ValidateWorktreeSlug(slug string) error

ValidateWorktreeSlug validates a worktree name/slug

Types

type EnterWorktreeConfig

type EnterWorktreeConfig struct {
	// WorkingDir is the working directory
	WorkingDir string

	// Manager is the worktree manager
	Manager *WorktreeManager
}

Config for EnterWorktree tool

func DefaultEnterWorktreeConfig

func DefaultEnterWorktreeConfig() *EnterWorktreeConfig

Default config

type EnterWorktreeTool

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

EnterWorktreeTool is the tool for entering a worktree

func NewEnterWorktreeTool

func NewEnterWorktreeTool(config *EnterWorktreeConfig) *EnterWorktreeTool

NewEnterWorktreeTool creates a new EnterWorktree tool

func (*EnterWorktreeTool) BackfillInput

func (t *EnterWorktreeTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput enriches input

func (*EnterWorktreeTool) Call

func (t *EnterWorktreeTool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

Call executes the tool

func (*EnterWorktreeTool) CheckPermissions

func (t *EnterWorktreeTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks tool permissions

func (*EnterWorktreeTool) Definition

func (t *EnterWorktreeTool) Definition() tool.Definition

Definition returns the tool definition

func (*EnterWorktreeTool) Description

func (t *EnterWorktreeTool) Description(ctx context.Context) (string, error)

Description returns description

func (*EnterWorktreeTool) FormatResult

func (t *EnterWorktreeTool) FormatResult(data any) string

FormatResult formats result

func (*EnterWorktreeTool) IsConcurrencySafe

func (t *EnterWorktreeTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether tool is concurrency safe

func (*EnterWorktreeTool) IsEnabled

func (t *EnterWorktreeTool) IsEnabled() bool

IsEnabled returns whether tool is enabled

func (*EnterWorktreeTool) IsReadOnly

func (t *EnterWorktreeTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether tool is read-only

func (*EnterWorktreeTool) ValidateInput

func (t *EnterWorktreeTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates tool input

type ExitWorktreeConfig

type ExitWorktreeConfig struct {
	// WorkingDir is the working directory
	WorkingDir string

	// Manager is the worktree manager
	Manager *WorktreeManager
}

Config for ExitWorktree tool

func DefaultExitWorktreeConfig

func DefaultExitWorktreeConfig() *ExitWorktreeConfig

Default config

type ExitWorktreeTool

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

ExitWorktreeTool is the tool for exiting a worktree

func NewExitWorktreeTool

func NewExitWorktreeTool(config *ExitWorktreeConfig) *ExitWorktreeTool

NewExitWorktreeTool creates a new ExitWorktree tool

func (*ExitWorktreeTool) BackfillInput

func (t *ExitWorktreeTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput enriches input

func (*ExitWorktreeTool) Call

func (t *ExitWorktreeTool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

Call executes the tool

func (*ExitWorktreeTool) CheckPermissions

func (t *ExitWorktreeTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks tool permissions

func (*ExitWorktreeTool) Definition

func (t *ExitWorktreeTool) Definition() tool.Definition

Definition returns the tool definition

func (*ExitWorktreeTool) Description

func (t *ExitWorktreeTool) Description(ctx context.Context) (string, error)

Description returns description

func (*ExitWorktreeTool) FormatResult

func (t *ExitWorktreeTool) FormatResult(data any) string

FormatResult formats result

func (*ExitWorktreeTool) IsConcurrencySafe

func (t *ExitWorktreeTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether tool is concurrency safe

func (*ExitWorktreeTool) IsDestructive

func (t *ExitWorktreeTool) IsDestructive(input map[string]any) bool

IsDestructive returns whether tool is destructive

func (*ExitWorktreeTool) IsEnabled

func (t *ExitWorktreeTool) IsEnabled() bool

IsEnabled returns whether tool is enabled

func (*ExitWorktreeTool) IsReadOnly

func (t *ExitWorktreeTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether tool is read-only

func (*ExitWorktreeTool) ValidateInput

func (t *ExitWorktreeTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates tool input. Session-presence checks require the session ID, which is only available in Call via CallInput; they are performed there instead.

type WorktreeConfig

type WorktreeConfig struct {
	// UseGitWorktree uses git worktree (true) or custom hooks (false)
	UseGitWorktree bool

	// CreateBranch creates a new branch (true) or uses existing (false)
	CreateBranch bool

	// DeleteWorktree allows deleting worktrees
	DeleteWorktree bool

	// WorktreeBaseDir is the base directory for worktrees
	WorktreeBaseDir string
}

WorktreeConfig is configuration for worktree tools

type WorktreeManager

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

WorktreeManager manages worktree sessions

func NewWorktreeManager

func NewWorktreeManager(config WorktreeConfig) *WorktreeManager

NewWorktreeManager creates a new worktree manager

func (*WorktreeManager) CountWorktreeChanges

func (m *WorktreeManager) CountWorktreeChanges(worktreePath, originalCommit string) (int, int, error)

CountWorktreeChanges counts changed files and commits

func (*WorktreeManager) CreateWorktree

func (m *WorktreeManager) CreateWorktree(
	ctx context.Context,
	slug string,
	branch string,
	originalCwd string,
) (*WorktreeSession, error)

CreateWorktree creates a new worktree

func (*WorktreeManager) RemoveWorktree

func (m *WorktreeManager) RemoveWorktree(session *WorktreeSession, force bool) error

RemoveWorktree removes the given worktree from disk. The caller is responsible for clearing the session registry entry.

type WorktreeSession

type WorktreeSession struct {
	// WorktreePath is the worktree directory path
	WorktreePath string

	// WorktreeBranch is the branch name
	WorktreeBranch string

	// OriginalCwd is the original working directory
	OriginalCwd string

	// OriginalHeadCommit is the commit hash when worktree was created
	OriginalHeadCommit string

	// TmuxSessionName is the tmux session name (if any)
	TmuxSessionName string
}

WorktreeSession represents an active worktree session

func GetSession

func GetSession(id types.SessionID) *WorktreeSession

GetSession returns the active WorktreeSession for the given session ID, or nil if none exists.

Jump to

Keyboard shortcuts

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