parallel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool manages parallel task execution using isolated git worktrees.

func NewPool

func NewPool(repoDir string, baseBranch string, maxWorkers int) *Pool

NewPool creates a parallel execution pool rooted at the given git repo. maxWorkers caps the number of concurrent goroutines; if <= 0 it defaults to 4.

func (*Pool) AddTask

func (p *Pool) AddTask(description string) *Task

AddTask queues a task for parallel execution and returns it. The task ID and branch name are auto-generated.

func (*Pool) Cleanup

func (p *Pool) Cleanup() error

Cleanup removes all worktrees created by this pool. It is idempotent.

func (*Pool) Results

func (p *Pool) Results() []*Task

Results returns all tasks (completed, failed, or pending).

func (*Pool) Run

func (p *Pool) Run(ctx context.Context, workFn func(ctx context.Context, worktreePath string, task *Task) (string, error)) error

Run executes all queued tasks in parallel, each in its own git worktree. workFn receives the worktree path and task, and returns a result summary. Tasks that fail do not prevent other tasks from completing.

type Status

type Status int

Status represents the current state of a parallel task.

const (
	StatusPending Status = iota
	StatusRunning
	StatusDone
	StatusFailed
)

func (Status) String

func (s Status) String() string

String returns a human-readable label for the status.

type Task

type Task struct {
	ID           string
	Description  string
	Branch       string // auto-generated branch name: hawk-parallel/{ID}
	WorktreePath string // filesystem path to the worktree
	Status       Status
	Error        error
	Result       string // summary of what was done
}

Task represents a single unit of work that will execute in its own git worktree.

type Worktree added in v0.2.0

type Worktree struct {
	ID              string
	Path            string
	Branch          string
	BaseBranch      string
	CreatedAt       time.Time
	Status          WorktreeStatus
	TaskDescription string
}

Worktree represents a single managed git worktree instance.

type WorktreeManager added in v0.2.0

type WorktreeManager struct {
	BaseDir      string
	Worktrees    map[string]*Worktree
	MaxWorktrees int
	// contains filtered or unexported fields
}

WorktreeManager manages the lifecycle of git worktrees for parallel execution.

func NewWorktreeManager added in v0.2.0

func NewWorktreeManager(baseDir string) *WorktreeManager

NewWorktreeManager creates a new WorktreeManager rooted at the given base directory. The base directory must be inside a git repository.

func (*WorktreeManager) Cleanup added in v0.2.0

func (wm *WorktreeManager) Cleanup() error

Cleanup removes all worktrees that are in completed, failed, or merged state, then runs git worktree prune.

func (*WorktreeManager) Create added in v0.2.0

func (wm *WorktreeManager) Create(branch, baseBranch, taskDescription string) (*Worktree, error)

Create creates a new git worktree on a new branch derived from baseBranch. The worktree is stored under .hawk/worktrees/ within the base directory.

func (*WorktreeManager) FormatMergePreview added in v0.2.0

func (wm *WorktreeManager) FormatMergePreview(id string) string

FormatMergePreview returns a human-readable preview of what merging the worktree branch would bring into the base branch.

func (*WorktreeManager) Get added in v0.2.0

func (wm *WorktreeManager) Get(id string) *Worktree

Get returns a worktree by ID, or nil if not found.

func (*WorktreeManager) GetDiff added in v0.2.0

func (wm *WorktreeManager) GetDiff(id string) (string, error)

GetDiff returns the diff between the worktree branch and its base branch.

func (*WorktreeManager) IsClean added in v0.2.0

func (wm *WorktreeManager) IsClean(id string) (bool, error)

IsClean returns true if the worktree has no uncommitted changes.

func (*WorktreeManager) List added in v0.2.0

func (wm *WorktreeManager) List() []*Worktree

List returns all registered worktrees sorted by creation time (newest first).

func (*WorktreeManager) MergeBack added in v0.2.0

func (wm *WorktreeManager) MergeBack(id string, strategy string) error

MergeBack merges the worktree branch back into its base branch using the specified strategy. Supported strategies: "fast-forward", "squash", "merge-commit".

func (*WorktreeManager) Remove added in v0.2.0

func (wm *WorktreeManager) Remove(id string) error

Remove removes a worktree by ID, cleaning it from git and the internal map.

func (*WorktreeManager) StatusReport added in v0.2.0

func (wm *WorktreeManager) StatusReport() string

StatusReport returns a formatted string showing the current state of all worktrees.

type WorktreeStatus added in v0.2.0

type WorktreeStatus string

WorktreeStatus represents the lifecycle state of a managed worktree.

const (
	WorktreeActive   WorktreeStatus = "active"
	WorktreeComplete WorktreeStatus = "complete"
	WorktreeFailed   WorktreeStatus = "failed"
	WorktreeMerged   WorktreeStatus = "merged"
)

Jump to

Keyboard shortcuts

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