Documentation
¶
Index ¶
- Constants
- Variables
- func FindGitRoot(cwd string) (string, error)
- func GenerateWorktreeName(slug string) string
- func SetSession(id types.SessionID, s *WorktreeSession)
- func ValidateWorktreeSlug(slug string) error
- type EnterWorktreeConfig
- type EnterWorktreeTool
- func (t *EnterWorktreeTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any
- func (t *EnterWorktreeTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)
- func (t *EnterWorktreeTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
- func (t *EnterWorktreeTool) Definition() tool.Definition
- func (t *EnterWorktreeTool) Description(ctx context.Context) (string, error)
- func (t *EnterWorktreeTool) FormatResult(data any) string
- func (t *EnterWorktreeTool) IsConcurrencySafe(input map[string]any) bool
- func (t *EnterWorktreeTool) IsEnabled() bool
- func (t *EnterWorktreeTool) IsReadOnly(input map[string]any) bool
- func (t *EnterWorktreeTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)
- type ExitWorktreeConfig
- type ExitWorktreeTool
- func (t *ExitWorktreeTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any
- func (t *ExitWorktreeTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)
- func (t *ExitWorktreeTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
- func (t *ExitWorktreeTool) Definition() tool.Definition
- func (t *ExitWorktreeTool) Description(ctx context.Context) (string, error)
- func (t *ExitWorktreeTool) FormatResult(data any) string
- func (t *ExitWorktreeTool) IsConcurrencySafe(input map[string]any) bool
- func (t *ExitWorktreeTool) IsDestructive(input map[string]any) bool
- func (t *ExitWorktreeTool) IsEnabled() bool
- func (t *ExitWorktreeTool) IsReadOnly(input map[string]any) bool
- func (t *ExitWorktreeTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)
- type WorktreeConfig
- type WorktreeManager
- func (m *WorktreeManager) CountWorktreeChanges(worktreePath, originalCommit string) (int, int, error)
- func (m *WorktreeManager) CreateWorktree(ctx context.Context, slug string, branch string, originalCwd string) (*WorktreeSession, error)
- func (m *WorktreeManager) RemoveWorktree(session *WorktreeSession, force bool) error
- type WorktreeSession
Constants ¶
const DescriptionEnterWorktree = "Creates an isolated worktree (via git or configured hooks) and switches the session into it"
Descriptions
const DescriptionExitWorktree = "Exits a worktree session created by EnterWorktree and restores the original working directory"
const EnterWorktreePrompt = `` /* 1485-byte string literal not displayed */
EnterWorktreePrompt is the system prompt for the EnterWorktree tool.
const ExitWorktreePrompt = `` /* 1250-byte string literal not displayed */
ExitWorktreePrompt is the system prompt for the ExitWorktree tool.
const SearchHintEnterWorktree = "create an isolated git worktree and switch into it"
Search hints
const SearchHintExitWorktree = "exit a worktree session and return to the original directory"
const ToolNameEnterWorktree = "enter_worktree"
Tool names
const ToolNameExitWorktree = "exit_worktree"
const WorktreeDirPrefix = ".worktree-"
Worktree directory prefix
Variables ¶
var DefaultWorktreeConfig = WorktreeConfig{ UseGitWorktree: true, CreateBranch: true, DeleteWorktree: true, }
Default worktree config
Functions ¶
func FindGitRoot ¶
FindGitRoot finds the canonical git root directory
func GenerateWorktreeName ¶
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 ¶
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 ¶
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 ¶
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.