processor

package
v0.137.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package processor manages the prompt execution lifecycle.

Index

Constants

This section is empty.

Variables

ErrPreflightFailed re-exports preflightconditions.ErrPreflightFailed so callers can use stderrors.Is(err, processor.ErrPreflightFailed) without importing preflightconditions.

Functions

func NewProcessor

func NewProcessor(
	exec executor.Executor,
	promptManager PromptManager,
	releaser git.Releaser,
	versionGetter version.Getter,
	workflowExecutor WorkflowExecutor,
	autoCompleter spec.AutoCompleter,
	specSweeper specsweeper.Sweeper,
	preflightConditions preflightconditions.Conditions,
	containerSlotManager containerslot.Manager,
	cancellationWatcher cancellationwatcher.Watcher,
	wakeup <-chan struct{},
	dirs Dirs,
	projectName project.Name,
	failureHandler failurehandler.Handler,
	resumer promptresumer.Resumer,
	verificationGate bool,
	completionReportValidator completionreport.Validator,
	promptEnricher promptenricher.Enricher,
	committingRecoverer committingrecoverer.Recoverer,
	queueScanner queuescanner.Scanner,

	queueInterval time.Duration,

	sweepInterval time.Duration,

	onIdle NothingToDoCallback,
) *processor

NewProcessor creates a new Processor.

Types

type Dirs added in v0.135.5

type Dirs struct {
	Queue, Completed, Log string
}

Dirs groups the three prompt directory paths used by the processor.

type DirtyFileChecker added in v0.96.0

type DirtyFileChecker interface {
	CountDirtyFiles(ctx context.Context) (int, error)
}

DirtyFileChecker counts dirty files in a git working tree.

func NewDirtyFileChecker added in v0.96.0

func NewDirtyFileChecker(repoDir string) DirtyFileChecker

NewDirtyFileChecker creates a DirtyFileChecker that runs git status on the host.

type GitLockChecker added in v0.102.0

type GitLockChecker interface {
	Exists() bool
}

GitLockChecker checks whether .git/index.lock exists in the working tree.

func NewGitLockChecker added in v0.102.0

func NewGitLockChecker(repoDir string) GitLockChecker

NewGitLockChecker creates a GitLockChecker for the given repo directory.

type NothingToDoCallback added in v0.135.4

type NothingToDoCallback func(ctx context.Context, cancel context.CancelFunc)

NothingToDoCallback fires when a Process tick ends with no progress made. Daemon mode passes a log-only callback. One-shot mode passes one that calls cancel().

type Processor

type Processor interface {
	Process(ctx context.Context) error
	// ResumeExecuting resumes any prompts still in "executing" state on startup.
	// Called once by the runner before the normal event loop begins.
	// For each executing prompt, it reattaches to the running container and drives
	// the prompt to completion through the normal post-execution flow.
	ResumeExecuting(ctx context.Context) error
	// ResumeCommitting retries git commits for any prompts in "committing" state on startup.
	// Called once by the runner before the normal event loop begins.
	// Unlike ResumeExecuting, failures are non-fatal: the prompt stays committing and is
	// retried on the next daemon cycle.
	ResumeCommitting(ctx context.Context) error
}

Processor processes queued prompts.

type PromptManager added in v0.119.2

type PromptManager interface {
	ListQueued(ctx context.Context) ([]prompt.Prompt, error)
	Load(ctx context.Context, path string) (*prompt.PromptFile, error)
	AllPreviousCompleted(ctx context.Context, n int) bool
	FindMissingCompleted(ctx context.Context, n int) []int
	FindPromptStatusInProgress(ctx context.Context, number int) string
	SetStatus(ctx context.Context, path string, status string) error
	MoveToCompleted(ctx context.Context, path string) error
	HasQueuedPromptsOnBranch(ctx context.Context, branch string, excludePath string) (bool, error)
	SetPRURL(ctx context.Context, path string, url string) error
	FindCommitting(ctx context.Context) ([]string, error)
}

PromptManager is the subset of prompt.Manager that the processor package uses.

type WorkflowDeps added in v0.119.0

type WorkflowDeps struct {
	ProjectName   project.Name
	PromptManager PromptManager
	AutoCompleter spec.AutoCompleter
	Releaser      git.Releaser
	VersionGetter version.Getter
	Brancher      git.Brancher
	PRCreator     git.PRCreator
	Cloner        git.Cloner
	Worktreer     git.Worktreer
	PRMerger      git.PRMerger
	PR            bool
	AutoMerge     bool
	AutoReview    bool
	AutoRelease   bool
}

WorkflowDeps holds all dependencies that WorkflowExecutor implementations may need. Factory functions populate only the fields required by the selected implementation; unused fields are nil and must not be dereferenced by implementations that do not need them.

type WorkflowExecutor added in v0.119.0

type WorkflowExecutor interface {
	// Setup prepares the execution environment before the YOLO container runs.
	// For clone/worktree: creates the isolated directory and chdirs into it.
	// For branch: creates or switches to the feature branch in-place.
	// For direct: no-op.
	// Returns a wrapped error on failure; partial setup is cleaned up before returning.
	Setup(ctx context.Context, baseName prompt.BaseName, pf *prompt.PromptFile) error

	// CleanupOnError undoes any environment setup performed by Setup when
	// execution or post-execution fails. Idempotent — safe to call if Setup was
	// not called or has already been cleaned up. No-op for direct and branch
	// executors where no isolated directory exists.
	CleanupOnError(ctx context.Context)

	// Complete performs all post-execution git operations after the YOLO container
	// exits successfully: commit, chdir back, cleanup isolation, push, optional PR
	// creation/merge, and moving the prompt file to completedPath.
	//
	// gitCtx is a non-cancellable context (context.WithoutCancel) for git ops.
	// ctx is the normal request context (used for prompt-manager calls and error wrapping).
	// completedPath is the destination path — the prompt has NOT been moved yet when
	// Complete is called; each implementation calls moveToCompleted internally.
	Complete(
		gitCtx context.Context,
		ctx context.Context,
		pf *prompt.PromptFile,
		title, promptPath, completedPath string,
	) error

	// ReconstructState restores internal state for a prompt being resumed after a
	// daemon restart. Returns canResume=false if the isolated directory no longer
	// exists (caller resets the prompt to approved). Returns an error only for
	// unexpected filesystem failures.
	ReconstructState(
		ctx context.Context,
		baseName prompt.BaseName,
		pf *prompt.PromptFile,
	) (canResume bool, err error)
}

WorkflowExecutor handles the git lifecycle for a single prompt execution. It encapsulates the pre-execution environment setup and post-execution git operations for one workflow variant (direct, branch, clone, or worktree).

Implementations are stateful: Setup stores paths and branches internally so that CleanupOnError and Complete can use them without the caller tracking workflowState.

func NewBranchWorkflowExecutor added in v0.119.3

func NewBranchWorkflowExecutor(deps WorkflowDeps) WorkflowExecutor

NewBranchWorkflowExecutor creates a WorkflowExecutor for the branch workflow.

func NewCloneWorkflowExecutor added in v0.119.3

func NewCloneWorkflowExecutor(deps WorkflowDeps) WorkflowExecutor

NewCloneWorkflowExecutor creates a WorkflowExecutor for the clone workflow.

func NewDirectWorkflowExecutor added in v0.119.3

func NewDirectWorkflowExecutor(deps WorkflowDeps) WorkflowExecutor

NewDirectWorkflowExecutor creates a WorkflowExecutor for the direct workflow.

func NewWorktreeWorkflowExecutor added in v0.119.3

func NewWorktreeWorkflowExecutor(deps WorkflowDeps) WorkflowExecutor

NewWorktreeWorkflowExecutor creates a WorkflowExecutor for the worktree workflow.

Jump to

Keyboard shortcuts

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