processor

package
v0.135.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 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

View Source
var ErrPreflightSkip = stderrors.New("preflight baseline broken — skip cycle")

ErrPreflightSkip is returned by processPrompt when the baseline preflight check failed and the prompt should NOT be retried within the same scan cycle. The caller in processExistingQueued recognizes this sentinel and returns, which gives control back to the 5s ticker in Process().

Do NOT use this for the other skip conditions (git-index-lock, dirty-files) — those are transient and it is safe to advance to the next prompt in the queue.

Functions

This section is empty.

Types

type AutoRetryLimit added in v0.135.5

type AutoRetryLimit int

AutoRetryLimit is the maximum number of automatic retries for a failed prompt (0 = disabled).

type BaseName added in v0.135.5

type BaseName string

BaseName is the prompt filename without the .md extension and with special characters replaced.

func (BaseName) String added in v0.135.5

func (b BaseName) String() string

String returns the underlying string value.

type ContainerName added in v0.135.5

type ContainerName string

ContainerName is a sanitized Docker container name derived from project and prompt names.

func (ContainerName) Sanitize added in v0.135.5

func (n ContainerName) Sanitize() ContainerName

Sanitize replaces any character not in [a-zA-Z0-9_-] with '-'.

func (ContainerName) String added in v0.135.5

func (n ContainerName) String() string

String returns the underlying string for use with exec / docker.

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 DirtyFileThreshold added in v0.135.5

type DirtyFileThreshold int

DirtyFileThreshold is the maximum number of dirty (modified) files before execution is blocked.

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 MaxContainers added in v0.135.5

type MaxContainers int

MaxContainers is the maximum number of concurrently running containers allowed.

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.

func NewProcessor

func NewProcessor(
	exec executor.Executor,
	promptManager PromptManager,
	releaser git.Releaser,
	versionGetter version.Getter,
	workflowExecutor WorkflowExecutor,
	autoCompleter spec.AutoCompleter,
	specLister spec.Lister,
	n notifier.Notifier,
	containerCounter executor.ContainerCounter,
	containerLock containerlock.ContainerLock,
	containerChecker executor.ContainerChecker,
	dirtyFileChecker DirtyFileChecker,
	gitLockChecker GitLockChecker,
	preflightChecker preflight.Checker,
	wakeup <-chan struct{},
	dirs Dirs,
	projectName ProjectName,
	maxContainers MaxContainers,
	dirtyFileThreshold DirtyFileThreshold,
	autoRetryLimit AutoRetryLimit,
	maxPromptDuration time.Duration,
	verificationGate VerificationGate,
	completionReportValidator completionreport.Validator,
	promptEnricher promptenricher.Enricher,

	queueInterval time.Duration,

	sweepInterval time.Duration,

	onIdle NothingToDoCallback,
) Processor

NewProcessor creates a new Processor.

type ProjectName added in v0.135.5

type ProjectName string

ProjectName is the name identifying a dark-factory project.

func (ProjectName) String added in v0.135.5

func (p ProjectName) String() string

String returns the underlying string value.

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 VerificationGate added in v0.135.5

type VerificationGate bool

VerificationGate controls whether execution pauses for manual verification before git operations.

type WorkflowDeps added in v0.119.0

type WorkflowDeps struct {
	ProjectName   ProjectName
	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 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 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