Documentation
¶
Overview ¶
Package git handles git worktree operations for parallel task execution
Package git handles git worktree operations for parallel task execution
Index ¶
- type CacheState
- type FetchSyncResult
- type PoolConfig
- type PoolStats
- type PooledWorktree
- type SyncStatus
- type WorktreeManager
- func (wm *WorktreeManager) Cleanup() error
- func (wm *WorktreeManager) CleanupAll() (count int, totalFreed int64, err error)
- func (wm *WorktreeManager) Commit(taskID, message string) (bool, error)
- func (wm *WorktreeManager) Create(task *types.Task) (string, error)
- func (wm *WorktreeManager) GetBuildArtifactSizes(taskID string) (map[string]int64, error)
- func (wm *WorktreeManager) GetDiskUsage(taskID string) (int64, error)
- func (wm *WorktreeManager) GetWorktreePath(taskID string) (string, error)
- func (wm *WorktreeManager) ListOrphaned() ([]string, error)
- func (wm *WorktreeManager) ListWorktreesOnDisk() ([]string, error)
- func (wm *WorktreeManager) MergeToMain(taskID string) error
- func (wm *WorktreeManager) Path(taskID string) string
- func (wm *WorktreeManager) PruneOrphaned() ([]string, int64, error)
- func (wm *WorktreeManager) PruneStale(taskID string)
- func (wm *WorktreeManager) Remove(taskID string) error
- func (wm *WorktreeManager) RemoveAggressive(taskID string) (int64, error)
- func (wm *WorktreeManager) RemoveAggressiveByPath(worktreePath string) (int64, error)
- func (wm *WorktreeManager) RemoveByPath(worktreePath string) error
- func (wm *WorktreeManager) SetVerbose(v bool)
- type WorktreePool
- func (p *WorktreePool) Acquire(taskID string) (string, error)
- func (p *WorktreePool) FetchAll() <-chan FetchSyncResult
- func (p *WorktreePool) FetchWorktree(worktreeID string) FetchSyncResult
- func (p *WorktreePool) GetSharedCargoTargetPath() string
- func (p *WorktreePool) GetSharedGoModCachePath() string
- func (p *WorktreePool) GetSharedNodeModulesPath() string
- func (p *WorktreePool) GetSyncStatus() map[string]SyncStatus
- func (p *WorktreePool) IsEnabled() bool
- func (p *WorktreePool) IsWorktreeReadOnly(worktreeID string) bool
- func (p *WorktreePool) Release(taskID string, retain bool) error
- func (p *WorktreePool) Start() error
- func (p *WorktreePool) Stats() PoolStats
- func (p *WorktreePool) Stop() error
- type WorktreeState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheState ¶
type CacheState struct {
NodeModulesHash string `json:"node_modules_hash,omitempty"`
GoSumHash string `json:"go_sum_hash,omitempty"`
YarnLockHash string `json:"yarn_lock_hash,omitempty"`
PackageLockHash string `json:"package_lock_hash,omitempty"`
CargoLockHash string `json:"cargo_lock_hash,omitempty"`
LastUpdated int64 `json:"last_updated"`
}
CacheState tracks the state of dependency caches
type FetchSyncResult ¶
type FetchSyncResult struct {
WorktreeID string // ID of the worktree that was fetched
CompletedAt time.Time // When the fetch completed
Success bool // True if fetch succeeded
Error string // Error message if fetch failed
CommitsFetched int // Number of commits fetched (if available)
}
FetchSyncResult represents the result of an async git fetch operation
type PoolConfig ¶
type PoolConfig struct {
MinSize int // Minimum number of warm worktrees to maintain
MaxSize int // Maximum number of worktrees in the pool
ReplenishThreshold int // Create new worktree when warm count falls below this
WarmupTimeout time.Duration // Max time to wait for worktree warmup
CleanupOnExit bool // Whether to clean up pooled worktrees on exit
EnableSymlinks bool // Enable shared node_modules via symlinks
GoModCache bool // Enable Go module cache sharing
CargoTargetDir bool // Enable shared Cargo target directory for Rust projects
}
PoolConfig holds configuration for the worktree pool
func DefaultPoolConfig ¶
func DefaultPoolConfig() *PoolConfig
DefaultPoolConfig returns sensible defaults for the pool
type PoolStats ¶
type PoolStats struct {
Total int
Cold int
Warming int
Warm int
InUse int
Draining int
MinSize int
MaxSize int
}
PoolStats holds pool statistics
type PooledWorktree ¶
type PooledWorktree struct {
ID string // Unique identifier (pool index or timestamp)
TaskID string // Currently assigned task (empty if not in use)
Path string // File system path
Branch string // Git branch name
State WorktreeState // Current state
CreatedAt time.Time // When the worktree was created
WarmedAt time.Time // When the worktree became warm
AssignedAt time.Time // When the worktree was assigned to a task
// Sync state for async git fetch
LastFetchAt time.Time // When the last fetch completed
LastFetchStatus string // Status of last fetch ("", "ok", "error")
LastFetchError string // Error message if fetch failed
IsReadOnly bool // True when sync is in progress
// contains filtered or unexported fields
}
PooledWorktree represents a worktree in the pool
type SyncStatus ¶
type SyncStatus struct {
WorktreeID string `json:"worktree_id"`
LastFetchAt time.Time `json:"last_fetch_at"`
LastFetchStatus string `json:"last_fetch_status"`
LastFetchError string `json:"last_fetch_error,omitempty"`
IsReadOnly bool `json:"is_read_only"`
}
SyncStatus represents the sync status of a worktree
type WorktreeManager ¶
type WorktreeManager struct {
// contains filtered or unexported fields
}
WorktreeManager creates and manages git worktrees
func NewWorktreeManager ¶
func NewWorktreeManager(baseDir, worktreeDir string) *WorktreeManager
NewWorktreeManager creates a new worktree manager
func (*WorktreeManager) Cleanup ¶
func (wm *WorktreeManager) Cleanup() error
Cleanup removes all worktrees
func (*WorktreeManager) CleanupAll ¶
func (wm *WorktreeManager) CleanupAll() (count int, totalFreed int64, err error)
CleanupAll removes all worktrees and returns total space freed
func (*WorktreeManager) Commit ¶
func (wm *WorktreeManager) Commit(taskID, message string) (bool, error)
Commit commits all changes in the worktree Returns (hasChanges, error) - hasChanges is true if changes were committed
func (*WorktreeManager) Create ¶
func (wm *WorktreeManager) Create(task *types.Task) (string, error)
Create creates a new worktree for a task
func (*WorktreeManager) GetBuildArtifactSizes ¶
func (wm *WorktreeManager) GetBuildArtifactSizes(taskID string) (map[string]int64, error)
GetBuildArtifactSizes returns the sizes of common build artifact directories
func (*WorktreeManager) GetDiskUsage ¶
func (wm *WorktreeManager) GetDiskUsage(taskID string) (int64, error)
GetDiskUsage returns the disk usage of a specific worktree
func (*WorktreeManager) GetWorktreePath ¶
func (wm *WorktreeManager) GetWorktreePath(taskID string) (string, error)
GetWorktreePath returns the path to a worktree for a task, if it exists
func (*WorktreeManager) ListOrphaned ¶
func (wm *WorktreeManager) ListOrphaned() ([]string, error)
ListOrphaned returns all worktree task IDs that exist on disk but are not registered with git
func (*WorktreeManager) ListWorktreesOnDisk ¶
func (wm *WorktreeManager) ListWorktreesOnDisk() ([]string, error)
ListWorktreesOnDisk returns all worktree directories that exist on disk
func (*WorktreeManager) MergeToMain ¶
func (wm *WorktreeManager) MergeToMain(taskID string) error
MergeToMain merges the worktree changes to main branch
func (*WorktreeManager) Path ¶
func (wm *WorktreeManager) Path(taskID string) string
Path returns the worktree path for a task
func (*WorktreeManager) PruneOrphaned ¶
func (wm *WorktreeManager) PruneOrphaned() ([]string, int64, error)
PruneOrphaned removes all worktrees that exist on disk but are not registered with git
func (*WorktreeManager) PruneStale ¶
func (wm *WorktreeManager) PruneStale(taskID string)
PruneStale removes stale git worktree registrations and branch for a specific task
func (*WorktreeManager) Remove ¶
func (wm *WorktreeManager) Remove(taskID string) error
Remove removes a worktree and its associated branch
func (*WorktreeManager) RemoveAggressive ¶
func (wm *WorktreeManager) RemoveAggressive(taskID string) (int64, error)
RemoveAggressive removes a worktree and aggressively cleans up build artifacts This is useful after a task is completed to free up disk space
func (*WorktreeManager) RemoveAggressiveByPath ¶
func (wm *WorktreeManager) RemoveAggressiveByPath(worktreePath string) (int64, error)
RemoveAggressiveByPath removes a worktree by its full path and aggressively cleans up build artifacts
func (*WorktreeManager) RemoveByPath ¶
func (wm *WorktreeManager) RemoveByPath(worktreePath string) error
RemoveByPath removes a worktree by its full path
func (*WorktreeManager) SetVerbose ¶
func (wm *WorktreeManager) SetVerbose(v bool)
SetVerbose enables or disables verbose logging
type WorktreePool ¶
type WorktreePool struct {
// contains filtered or unexported fields
}
WorktreePool manages a pool of pre-initialized worktrees
func NewWorktreePool ¶
func NewWorktreePool(manager *WorktreeManager, config *PoolConfig) *WorktreePool
NewWorktreePool creates a new worktree pool
func (*WorktreePool) Acquire ¶
func (p *WorktreePool) Acquire(taskID string) (string, error)
Acquire acquires a warm worktree from the pool for a task Returns the worktree path, or an error if no worktree is available
func (*WorktreePool) FetchAll ¶
func (p *WorktreePool) FetchAll() <-chan FetchSyncResult
FetchAll initiates async git fetch for all worktrees in the pool. Returns a channel that will receive results for each worktree as fetches complete. The channel is closed after all results are sent.
func (*WorktreePool) FetchWorktree ¶
func (p *WorktreePool) FetchWorktree(worktreeID string) FetchSyncResult
FetchWorktree fetches updates for a specific worktree and returns the result. This is a synchronous, blocking operation.
func (*WorktreePool) GetSharedCargoTargetPath ¶
func (p *WorktreePool) GetSharedCargoTargetPath() string
GetSharedCargoTargetPath returns the path to the shared Cargo target directory
func (*WorktreePool) GetSharedGoModCachePath ¶
func (p *WorktreePool) GetSharedGoModCachePath() string
GetSharedGoModCachePath returns the path to the shared Go module cache
func (*WorktreePool) GetSharedNodeModulesPath ¶
func (p *WorktreePool) GetSharedNodeModulesPath() string
GetSharedNodeModulesPath returns the path to the shared node_modules directory
func (*WorktreePool) GetSyncStatus ¶
func (p *WorktreePool) GetSyncStatus() map[string]SyncStatus
GetSyncStatus returns the sync status for all worktrees
func (*WorktreePool) IsEnabled ¶
func (p *WorktreePool) IsEnabled() bool
IsEnabled returns true if worktree pooling is enabled
func (*WorktreePool) IsWorktreeReadOnly ¶
func (p *WorktreePool) IsWorktreeReadOnly(worktreeID string) bool
IsWorktreeReadOnly returns true if the worktree is currently in read-only mode (syncing)
func (*WorktreePool) Release ¶
func (p *WorktreePool) Release(taskID string, retain bool) error
Release releases a worktree back to the pool after task completion
func (*WorktreePool) Start ¶
func (p *WorktreePool) Start() error
Start initializes the pool and begins maintaining the minimum number of warm worktrees
type WorktreeState ¶
type WorktreeState int
WorktreeState represents the current state of a worktree in the pool
const ( // StateCold - Worktree is allocated but not yet prepared StateCold WorktreeState = iota // StateWarming - Worktree is being prepared (syncing, installing dependencies) StateWarming // StateWarm - Worktree is ready for immediate task assignment StateWarm // StateInUse - Worktree is currently assigned to a task StateInUse // StateDraining - Worktree is being cleaned up for removal StateDraining )
func (WorktreeState) String ¶
func (s WorktreeState) String() string