phase

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SignalCompleted  = status.Completed
	SignalFailed     = status.Failed
	SignalReviewDone = status.ReviewDone
	SignalCodexDone  = status.CodexDone
	SignalQuestion   = status.Question
	SignalPlanReady  = status.PlanReady
	SignalPlanDraft  = status.PlanDraft
)

Signal aliases mirror pkg/status values used by phase prompt contracts and parser helpers.

Variables

View Source
var ErrNoPlanDraftSignal = errors.New("no plan draft signal found")

ErrNoPlanDraftSignal indicates no plan draft signal was found in output.

View Source
var ErrNoQuestionSignal = errors.New("no question signal found")

ErrNoQuestionSignal indicates no question signal was found in output.

View Source
var ErrUserAborted = errors.New("user aborted")

ErrUserAborted is returned when a user aborts task execution after a break signal.

View Source
var ErrUserRejectedPlan = errors.New("user rejected plan")

ErrUserRejectedPlan is returned when a user rejects a plan draft.

Functions

func IsCodexDone

func IsCodexDone(signal string) bool

IsCodexDone reports whether signal marks external review completion.

func IsPlanReady

func IsPlanReady(signal string) bool

IsPlanReady reports whether signal marks plan creation completion.

func IsReviewDone

func IsReviewDone(signal string) bool

IsReviewDone reports whether signal marks internal review completion.

func ParsePlanDraftPayload

func ParsePlanDraftPayload(output string) (string, error)

ParsePlanDraftPayload extracts plan content from output containing a PLAN_DRAFT signal.

Types

type BreakController

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

BreakController translates break-channel events into cancellable phase contexts.

func NewBreakController

func NewBreakController(deps *Deps) *BreakController

NewBreakController creates a break controller backed by shared dependencies.

type Config

type Config struct {
	PlanDescription       string
	MaxIterations         int
	MaxExternalIterations int
	ReviewPatience        int
	CodexEnabled          bool
	ExternalReviewToolSet bool
	FinalizeEnabled       bool
	AppConfig             *config.Config
}

Config contains the runner settings consumed by phase engines.

type Deps

type Deps struct {
	Git            GitChecker
	InputCollector InputCollector
	BreakCh        <-chan struct{}
	PauseHandler   func(ctx context.Context) bool
}

Deps holds late-bound dependencies shared by phase engines.

type ExecutionResult

type ExecutionResult struct {
	Result   executor.Result
	TimedOut bool
}

ExecutionResult is the execution output plus phase-level timeout metadata.

type Executor

type Executor interface {
	Run(ctx context.Context, prompt string) executor.Result
}

Executor runs a phase prompt and returns the executor result.

type ExternalReviewLogger

type ExternalReviewLogger interface {
	Logger
	PrintSection(section status.Section)
	PrintAligned(text string)
}

ExternalReviewLogger records external review phase progress and summaries.

type ExternalReviewOutcome

type ExternalReviewOutcome struct {
	HadFindings bool
}

ExternalReviewOutcome reports whether external review found issues.

type ExternalReviewPhase

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

ExternalReviewPhase runs codex or custom external review loops.

func NewExternalReviewPhase

func NewExternalReviewPhase(opts ExternalReviewPhaseOpts) *ExternalReviewPhase

NewExternalReviewPhase creates an external review phase engine.

func (*ExternalReviewPhase) Run

Run executes the configured external review loop and reports whether fixes need post-review.

func (*ExternalReviewPhase) Tool

func (p *ExternalReviewPhase) Tool() string

Tool returns the effective external review tool after config and back-compat rules.

type ExternalReviewPhaseOpts

type ExternalReviewPhaseOpts struct {
	Cfg            Config
	Log            ExternalReviewLogger
	External       Executor
	Custom         *executor.CustomExecutor
	Review         Executor
	Policy         Policy
	Prompts        ExternalReviewPrompts
	Breaks         *BreakController
	Git            *GitState
	PhaseHolder    *status.PhaseHolder
	IterationDelay time.Duration
}

ExternalReviewPhaseOpts contains dependencies for ExternalReviewPhase.

type ExternalReviewPrompts

type ExternalReviewPrompts interface {
	CodexReviewPrompt(isFirst bool, claudeResponse string) string
	CodexEvaluationPrompt(codexOutput string) string
	CustomReviewPrompt(isFirst bool, claudeResponse string) string
	CustomEvaluationPrompt(customOutput string) string
}

ExternalReviewPrompts renders external review and evaluation prompts.

type FinalizeLogger

type FinalizeLogger interface {
	Logger
	PrintSection(section status.Section)
}

FinalizeLogger records finalize phase progress.

type FinalizePhase

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

FinalizePhase runs the optional finalize step.

func NewFinalizePhase

func NewFinalizePhase(opts FinalizePhaseOpts) *FinalizePhase

NewFinalizePhase creates a finalize phase engine.

func (*FinalizePhase) Run

func (p *FinalizePhase) Run(ctx context.Context) error

Run executes the optional finalize step; ordinary executor failures are logged and do not fail the pipeline.

type FinalizePhaseOpts

type FinalizePhaseOpts struct {
	Cfg         Config
	Log         FinalizeLogger
	Exec        Executor
	Policy      Policy
	Prompts     FinalizePrompts
	PhaseHolder *status.PhaseHolder
}

FinalizePhaseOpts contains dependencies for FinalizePhase.

type FinalizePrompts

type FinalizePrompts interface {
	FinalizePrompt() string
}

FinalizePrompts renders finalize prompts.

type GitChecker

type GitChecker interface {
	HeadHash() (string, error)
	DiffFingerprint() (string, error)
}

GitChecker reports git state used by review loops.

type GitState

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

GitState reads git state for review loops.

func NewGitState

func NewGitState(deps *Deps, log Logger) *GitState

NewGitState creates a git state reader backed by shared dependencies.

type InputCollector

type InputCollector interface {
	AskQuestion(ctx context.Context, question string, options []string) (string, error)
	AskDraftReview(ctx context.Context, question string, planContent string) (action string, feedback string, err error)
}

InputCollector collects user input for interactive plan creation.

type Locator

type Locator interface {
	Path() string
}

Locator resolves the current plan file path.

type Logger

type Logger interface {
	Print(format string, args ...any)
}

Logger records plain phase progress messages.

type PlanCreationLogger

type PlanCreationLogger interface {
	Logger
	PrintRaw(format string, args ...any)
	PrintSection(section status.Section)
	LogQuestion(question string, options []string)
	LogAnswer(answer string)
	LogDraftReview(action string, feedback string)
}

PlanCreationLogger records interactive plan creation progress and Q&A history.

type PlanCreationPhase

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

PlanCreationPhase runs interactive plan creation.

func NewPlanCreationPhase

func NewPlanCreationPhase(opts PlanCreationPhaseOpts) *PlanCreationPhase

NewPlanCreationPhase creates a plan creation phase engine.

func (*PlanCreationPhase) Run

func (p *PlanCreationPhase) Run(ctx context.Context) error

Run executes interactive plan creation until PLAN_READY, user rejection, or iteration exhaustion.

type PlanCreationPhaseOpts

type PlanCreationPhaseOpts struct {
	Cfg            Config
	Log            PlanCreationLogger
	Exec           Executor
	Policy         Policy
	Prompts        PlanCreationPrompts
	Deps           *Deps
	PhaseHolder    *status.PhaseHolder
	IterationDelay time.Duration
}

PlanCreationPhaseOpts contains dependencies for PlanCreationPhase.

type PlanCreationPrompts

type PlanCreationPrompts interface {
	PlanPrompt() string
}

PlanCreationPrompts renders interactive plan creation prompts.

type Policy

type Policy interface {
	Run(ctx context.Context, run func(context.Context, string) executor.Result, prompt string, toolName string) ExecutionResult
	HandlePatternMatchError(err error, tool string) error
	Sleep(ctx context.Context, d time.Duration) error
}

Policy applies execution retry, timeout, and sleep behavior for phase engines.

type QuestionPayload

type QuestionPayload struct {
	Question string   `json:"question"`
	Options  []string `json:"options"`
	Context  string   `json:"context,omitempty"`
}

QuestionPayload represents a question signal from the plan creation phase.

func ParseQuestionPayload

func ParseQuestionPayload(output string) (*QuestionPayload, error)

ParseQuestionPayload extracts a question payload from output containing a QUESTION signal.

type ReviewLogger

type ReviewLogger interface {
	Logger
	PrintSection(section status.Section)
}

ReviewLogger records internal review phase progress.

type ReviewPhase

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

ReviewPhase runs internal review passes.

func NewReviewPhase

func NewReviewPhase(opts ReviewPhaseOpts) *ReviewPhase

NewReviewPhase creates an internal review phase engine.

func (*ReviewPhase) First

func (p *ReviewPhase) First(ctx context.Context) error

First runs the comprehensive first review pass and applies first-review timeout semantics.

func (*ReviewPhase) Loop

func (p *ReviewPhase) Loop(ctx context.Context, prefix string) error

Loop runs critical/major review iterations until review completion or no changed HEAD.

type ReviewPhaseOpts

type ReviewPhaseOpts struct {
	Cfg            Config
	Log            ReviewLogger
	Exec           Executor
	Policy         Policy
	Prompts        ReviewPrompts
	Git            *GitState
	PhaseHolder    *status.PhaseHolder
	IterationDelay time.Duration
}

ReviewPhaseOpts contains dependencies for ReviewPhase.

type ReviewPrompts

type ReviewPrompts interface {
	FirstReviewPrompt() string
	SecondReviewPrompt(prefix string) string
}

ReviewPrompts renders internal review prompts.

type TaskLogger

type TaskLogger interface {
	Logger
	PrintRaw(format string, args ...any)
	PrintSection(section status.Section)
}

TaskLogger records task phase progress.

type TaskPhase

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

TaskPhase executes plan tasks until completion.

func NewTaskPhase

func NewTaskPhase(opts TaskPhaseOpts) *TaskPhase

NewTaskPhase creates a task phase engine.

func (*TaskPhase) HasUncompletedTasks

func (p *TaskPhase) HasUncompletedTasks() bool

HasUncompletedTasks reports whether the current plan still has actionable unchecked task work.

func (*TaskPhase) NextPlanTaskPosition

func (p *TaskPhase) NextPlanTaskPosition() int

NextPlanTaskPosition returns the 1-indexed first uncompleted task position, or zero when unavailable.

func (*TaskPhase) Run

func (p *TaskPhase) Run(ctx context.Context) error

Run executes one plan task per iteration until all actionable task checkboxes are complete.

func (*TaskPhase) ValidatePlanHasTasks

func (p *TaskPhase) ValidatePlanHasTasks() error

ValidatePlanHasTasks rejects plan files without executable task sections.

type TaskPhaseOpts

type TaskPhaseOpts struct {
	Cfg            Config
	Log            TaskLogger
	Exec           Executor
	Policy         Policy
	Prompts        TaskPrompts
	Locator        Locator
	Deps           *Deps
	Breaks         *BreakController
	IterationDelay time.Duration
	RetryCount     int
}

TaskPhaseOpts contains dependencies for TaskPhase.

type TaskPrompts

type TaskPrompts interface {
	TaskPrompt() string
}

TaskPrompts renders task phase prompts.

Jump to

Keyboard shortcuts

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