absorb

package
v0.17.14 Latest Latest
Warning

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

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

Documentation

Overview

Package absorb provides functionality for absorbing staged changes into commits downstack.

Package absorb provides functionality for absorbing staged changes into commits downstack.

Package absorb provides functionality for absorbing staged changes into commits downstack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(ctx *app.Context) error

Abort cleans up from a failed absorb state

func Action

func Action(ctx *app.Context, opts Options, handler Handler) error

Action performs the absorb operation

func GeneratePlanJSON

func GeneratePlanJSON(
	currentBranch string,
	hunkTargets []git.HunkTarget,
	unabsorbedHunks []git.Hunk,
	newFiles []string,
	eng engine.Engine,
) ([]byte, error)

GeneratePlanJSON creates a machine-readable plan from absorb results

func IsAbsorbInProgress

func IsAbsorbInProgress(ctx *app.Context) bool

IsAbsorbInProgress checks if there's a failed absorb operation that needs cleanup. This is detected by checking for: 1. Detached HEAD state, OR 2. Presence of absorb stash marker

func ShowConflict

func ShowConflict(ctx *app.Context) error

ShowConflict shows information about what absorb would do and helps diagnose conflicts. This is useful when absorb fails and you want to understand what was being attempted.

Types

type AbsorbedHunk

type AbsorbedHunk struct {
	File         string `json:"file"`
	Lines        string `json:"lines"`
	TargetBranch string `json:"target_branch"`
	TargetCommit string `json:"target_commit"`
	Content      string `json:"content"`
}

AbsorbedHunk represents a hunk that was successfully absorbed

type Handler

type Handler interface {
	// Start is called at the beginning of absorb
	Start(dryRun bool)

	// OnStep is called for each step in the absorb process
	OnStep(step Step, status handler.StepStatus, message string)

	// OnHunkTarget is called when a target is found for a hunk
	OnHunkTarget(file string, commitSHA string, branchName string)

	// OnUnabsorbedHunk is called for hunks that could not be absorbed
	OnUnabsorbedHunk(hunk git.Hunk)

	// OnApply is called when hunks are applied to a branch
	OnApply(branchName string, commitSHA string)

	// Complete is called when absorb finishes
	Complete(result Result)

	// Cleanup restores terminal state (may be no-op)
	Cleanup()

	// IsInteractive returns true if the handler supports interactive prompts
	IsInteractive() bool

	// PromptConfirm prompts user for confirmation before absorbing
	PromptConfirm(message string) (bool, error)
}

Handler receives events from absorb action

type HunkResult

type HunkResult struct {
	File       string
	CommitSHA  string
	BranchName string
	LineStart  int
	LineEnd    int
}

HunkResult represents the result of absorbing a hunk

type NullHandler

NullHandler is a no-op handler for when nil is passed. It embeds handler.NullBase for Cleanup() and IsInteractive().

func (*NullHandler) Complete

func (h *NullHandler) Complete(Result)

Complete implements Handler.

func (*NullHandler) OnApply

func (h *NullHandler) OnApply(string, string)

OnApply implements Handler.

func (*NullHandler) OnHunkTarget

func (h *NullHandler) OnHunkTarget(string, string, string)

OnHunkTarget implements Handler.

func (*NullHandler) OnUnabsorbedHunk

func (h *NullHandler) OnUnabsorbedHunk(git.Hunk)

OnUnabsorbedHunk implements Handler.

func (*NullHandler) Start

func (h *NullHandler) Start(bool)

Start implements Handler.

type Options

type Options struct {
	All    bool
	DryRun bool
	Force  bool
	Patch  bool
	JSON   bool // Output machine-readable JSON summary
}

Options contains options for the absorb command

type PlanJSON

type PlanJSON struct {
	CurrentBranch string             `json:"current_branch"`
	Absorbed      []AbsorbedHunk     `json:"absorbed"`
	Unabsorbable  []UnabsorbableHunk `json:"unabsorbable"`
	NewFiles      []string           `json:"new_files"`
	Stack         []StackNode        `json:"stack"`
}

PlanJSON is the machine-readable absorb plan for LLM consumption

type Result

type Result struct {
	Absorbed    int
	Unabsorbed  int
	BranchCount int
}

Result contains the result of the absorb action

type StackNode

type StackNode struct {
	Name      string `json:"name"`
	Parent    string `json:"parent,omitempty"`
	IsTrunk   bool   `json:"is_trunk,omitempty"`
	IsCurrent bool   `json:"is_current,omitempty"`
}

StackNode represents a branch in the stack structure

type Step

type Step string

Step represents a step in the absorb process

const (
	StepStaging    Step = "staging"
	StepParsing    Step = "parsing"
	StepFinding    Step = "finding"
	StepConfirming Step = "confirming"
	StepApplying   Step = "applying"
	StepRestacking Step = "restacking"
)

Absorb step constants

type UnabsorbableHunk

type UnabsorbableHunk struct {
	File    string `json:"file"`
	Lines   string `json:"lines"`
	Reason  string `json:"reason"`
	Content string `json:"content"`
}

UnabsorbableHunk represents a hunk that could not be absorbed

Jump to

Keyboard shortcuts

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