crucible

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package crucible orchestrates parent beads with children on feature branches.

The Crucible is where separate beads are melted together into a single unified PR. It auto-detects parent-child bead relationships, creates a feature branch, dispatches children in topological order through the pipeline, merges their PRs, and produces a final PR against main.

Index

Constants

View Source
const FeatureBranchPrefix = "feature/"

FeatureBranchPrefix is the branch prefix for Crucible feature branches.

Variables

View Source
var ErrCycle = errors.New("dependency cycle detected among children")

ErrCycle is returned when the children contain a dependency cycle.

Functions

func FetchBead

func FetchBead(ctx context.Context, beadID, dir string) (poller.Bead, error)

FetchBead calls `bd show <beadID> --json` and returns the parsed bead. bd show returns dependents as an array of objects with dependency_type, not a flat "blocks" array, so we extract blocks from the dependents.

func FetchChildren

func FetchChildren(ctx context.Context, parentID, dir string) ([]poller.Bead, error)

FetchChildren calls `bd show <parentID> --json` to get the parent's blocks, then recursively fetches all descendants (children, grandchildren, etc.). This ensures the Crucible processes the entire dependency tree, not just direct children.

func IsCrucibleCandidate

func IsCrucibleCandidate(b poller.Bead) bool

IsCrucibleCandidate returns true if a bead has children (blocks other beads) and is therefore a Crucible candidate.

func MergePR

func MergePR(ctx context.Context, prNumber int, dir string) error

MergePR merges a PR by number using gh pr merge --squash. It retries with polling if the initial merge attempt fails (e.g. checks still running).

func TopoSort

func TopoSort(beads []poller.Bead) ([]poller.Bead, error)

TopoSort sorts beads topologically based on their DependsOn relationships. Only intra-group dependencies are considered — deps pointing to beads outside the input set are ignored. Returns ErrCycle if there's a cycle.

Types

type Params

type Params struct {
	DB              *state.DB
	Logger          *slog.Logger
	WorktreeManager *worktree.Manager
	PromptBuilder   *prompt.Builder

	ParentBead  poller.Bead
	AnvilName   string
	AnvilConfig config.AnvilConfig

	ExtraFlags            []string
	Providers             []provider.Provider
	SchematicConfig       *schematic.Config
	GoRaceDetection       bool
	SmithTimeout          time.Duration
	MaxPipelineIterations int

	// StatusCallback is called when crucible state changes (for TUI tracking).
	StatusCallback func(Status)

	// AutoMergeCrucibleChildren controls whether child PRs are automatically
	// merged (squash) into the feature branch after the pipeline succeeds.
	// When false, child PRs are created but not merged (human review required).
	// Default: true (zero value auto-merges).
	AutoMergeCrucibleChildren bool

	// Test injection points — when non-nil these replace the real implementations.
	PipelineRunner    func(ctx context.Context, p pipeline.Params) *pipeline.Outcome
	PRCreator         func(ctx context.Context, p ghpr.CreateParams) (*ghpr.PR, error)
	ChildFetcher      func(ctx context.Context, parentID, dir string) ([]poller.Bead, error)
	PRMerger          func(ctx context.Context, prNumber int, dir string) error
	BeadClaimer       func(ctx context.Context, beadID, dir string) error
	BeadCloser        func(ctx context.Context, beadID, dir string) error
	BeadResetter      func(ctx context.Context, beadID, dir string) error
	EpicBranchCreator func(ctx context.Context, dir, branch string) error
	SchematicRunner   func(ctx context.Context, cfg schematic.Config, bead poller.Bead, anvilPath string, pv provider.Provider) *schematic.Result
}

Params holds all dependencies needed to run a Crucible.

type Result

type Result struct {
	Success       bool
	FinalPR       *ghpr.PR // Non-nil when final PR was created successfully.
	ChildrenDone  int
	ChildrenTotal int
	Error         error
	PausedChildID string // Non-empty if paused due to child failure.
}

Result is returned when the Crucible finishes or pauses.

func Run

func Run(ctx context.Context, p Params) *Result

Run orchestrates a parent bead's children on a feature branch.

Flow: create feature branch → topo-sort children → dispatch each child (pipeline → PR → merge) → create final PR from feature branch to main.

type Status

type Status struct {
	ParentID          string
	Anvil             string
	Branch            string
	Phase             string // "started", "parent", "dispatching", "waiting", "final_pr", "complete", "paused"
	TotalChildren     int
	CompletedChildren int
	CurrentChild      string
	StartedAt         time.Time
}

Status tracks the current state of a Crucible for monitoring.

Jump to

Keyboard shortcuts

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