modes

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package modes implements building execution mode

Package modes implements planning and building worker modes

Package modes provides default prompts for different worker modes

Package modes implements planning/building worker mode separation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertPlanToDB

func ConvertPlanToDB(plan *db.Plan) *db.Plan

ConvertPlanToDB converts a modes.Plan to db.Plan (no-op since we use db.Plan directly now) This function is kept for compatibility

func ConvertPlanToModes

func ConvertPlanToModes(plan *db.Plan) *db.Plan

ConvertPlanToModes converts a db.Plan to modes.Plan (no-op since we use db.Plan directly now) This function is kept for compatibility

func DefaultBuildingPrompt

func DefaultBuildingPrompt() string

DefaultBuildingPrompt returns the default prompt for building mode

func DefaultPlanningPrompt

func DefaultPlanningPrompt() string

DefaultPlanningPrompt returns the default prompt for planning mode

func DefaultRefinementPrompt

func DefaultRefinementPrompt() string

DefaultRefinementPrompt returns the default prompt for plan refinement

func FormatPlanForDisplay

func FormatPlanForDisplay(plan *db.Plan) string

FormatPlanForDisplay formats a plan for human display

func JSONToPlan

func JSONToPlan(data string) (*db.Plan, error)

JSONToPlan converts JSON to a plan

func ParsePlanFromOutput

func ParsePlanFromOutput(output string) (*db.Plan, error)

ParsePlanFromOutput parses a plan from agent output

func PlanToJSON

func PlanToJSON(plan *db.Plan) (string, error)

PlanToJSON converts a plan to JSON for storage

Types

type BuildResult

type BuildResult struct {
	Success         bool          `json:"success"`
	PlanID          string        `json:"plan_id"`
	TaskID          string        `json:"task_id"`
	StepsCompleted  int           `json:"steps_completed"`
	TotalSteps      int           `json:"total_steps"`
	StepResults     []StepResult  `json:"step_results"`
	Output          string        `json:"output"`
	Error           error         `json:"error,omitempty"`
	Duration        time.Duration `json:"duration"`
	NeedsRefinement bool          `json:"needs_refinement,omitempty"`
	FailureReason   string        `json:"failure_reason,omitempty"`
}

BuildResult represents the result of building a plan

type Builder

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

Builder executes approved implementation plans

func NewBuilder

func NewBuilder(cfg *Config, agent BuildingAgent, store PlanStore) *Builder

NewBuilder creates a new Builder

func (*Builder) BuildExecutionPrompt

func (b *Builder) BuildExecutionPrompt(plan *db.Plan, task *types.Task) string

BuildExecutionPrompt builds the prompt for building mode

func (*Builder) CheckPlanReady

func (b *Builder) CheckPlanReady(plan *db.Plan) error

CheckPlanReady checks if a plan is ready to be executed

func (*Builder) ExecutePlan

func (b *Builder) ExecutePlan(ctx context.Context, plan *db.Plan, task *types.Task, worktreePath string, span ...trace.Span) *BuildResult

ExecutePlan executes an approved plan

func (*Builder) ExecutionContext

func (b *Builder) ExecutionContext(plan *db.Plan, task *types.Task, workDir string) *ExecutionContext

ExecutionContext creates an execution context for a plan

func (*Builder) RequestRefinement

func (b *Builder) RequestRefinement(ctx context.Context, plan *db.Plan, result *BuildResult, workerID string) (*db.Plan, error)

RequestRefinement creates a refinement request for a failed plan

func (*Builder) SetVerbose

func (b *Builder) SetVerbose(v bool)

SetVerbose enables verbose logging

func (*Builder) ShouldRefine

func (b *Builder) ShouldRefine(plan *db.Plan, result *BuildResult) bool

ShouldRefine determines if a failed plan should be refined

type BuildingAgent

type BuildingAgent interface {
	// ExecutePlan executes a plan and returns the result
	ExecutePlan(ctx context.Context, plan *db.Plan, task *types.Task, worktreePath string, span ...trace.Span) *BuildResult
}

BuildingAgent is the interface for agents that can execute plans

type BuildingConfig

type BuildingConfig struct {
	// ExecuteApprovedOnly only executes approved plans
	ExecuteApprovedOnly bool `json:"execute_approved_only" yaml:"execute_approved_only"`

	// VerifySteps verifies each step after execution
	VerifySteps bool `json:"verify_steps" yaml:"verify_steps"`

	// PromptTemplate is the template for building prompts
	PromptTemplate string `json:"prompt_template,omitempty" yaml:"prompt_template,omitempty"`
}

BuildingConfig holds configuration for building mode

type Config

type Config struct {
	// Mode is the current worker mode
	Mode WorkerMode `json:"mode" yaml:"mode"`

	// Planning configuration
	Planning PlanningConfig `json:"planning" yaml:"planning"`

	// Building configuration
	Building BuildingConfig `json:"building" yaml:"building"`

	// Refinement configuration
	Refinement RefinementConfig `json:"refinement" yaml:"refinement"`
}

Config holds configuration for worker modes

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

type ExecutionContext

type ExecutionContext struct {
	// The plan being executed
	Plan *db.Plan `json:"plan"`

	// Current step being executed
	CurrentStep int `json:"current_step"`

	// Results from previous steps
	StepResults map[int]StepResult `json:"step_results,omitempty"`

	// Working directory
	WorkDir string `json:"work_dir"`

	// Task context
	Task *types.Task `json:"task"`
}

ExecutionContext provides context for plan execution

type PlanRefinementTrigger

type PlanRefinementTrigger string

PlanRefinementTrigger defines when a plan should be refined

const (
	TriggerOnFailure    PlanRefinementTrigger = "on_failure"    // Auto-refine on execution failure
	TriggerOnFeedback   PlanRefinementTrigger = "on_feedback"   // User requests refinement
	TriggerOnComplexity PlanRefinementTrigger = "on_complexity" // Plan too complex
	TriggerOnDependency PlanRefinementTrigger = "on_dependency" // Dependencies changed
)

func (PlanRefinementTrigger) String

func (t PlanRefinementTrigger) String() string

String returns the string representation of the trigger

type PlanStore

type PlanStore interface {
	// SavePlan saves a plan to storage
	SavePlan(plan *db.Plan) error

	// GetPlan retrieves a plan by ID
	GetPlan(planID string) (*db.Plan, error)

	// GetPlanByTaskID retrieves a plan for a specific task
	GetPlanByTaskID(taskID string) (*db.Plan, error)

	// ListPlans lists all plans, optionally filtered by status
	ListPlans(status db.PlanStatus) ([]*db.Plan, error)

	// UpdatePlanStatus updates the status of a plan
	UpdatePlanStatus(planID string, status db.PlanStatus, reason string) error

	// AddFeedback adds feedback to a plan
	AddFeedback(planID string, feedback string) error
}

PlanStore defines the interface for storing and retrieving plans

type Planner

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

Planner creates implementation plans without making code changes

func NewPlanner

func NewPlanner(cfg *Config, agent PlanningAgent, store PlanStore) *Planner

NewPlanner creates a new Planner

func (*Planner) CreatePlan

func (p *Planner) CreatePlan(ctx context.Context, task *types.Task, workerID string) (*db.Plan, error)

CreatePlan generates a plan for the given task

func (*Planner) SetVerbose

func (p *Planner) SetVerbose(v bool)

SetVerbose enables verbose logging

type PlanningAgent

type PlanningAgent interface {
	// GeneratePlan creates a plan from a task
	GeneratePlan(ctx context.Context, task *types.Task, prompt string) (*db.Plan, error)
}

PlanningAgent is the interface for agents that can create plans

type PlanningConfig

type PlanningConfig struct {
	// RequireApproval requires manual approval before plans can be built
	RequireApproval bool `json:"require_approval" yaml:"require_approval"`

	// AutoApproveLowComplexity automatically approves low-complexity plans
	AutoApproveLowComplexity bool `json:"auto_approve_low_complexity" yaml:"auto_approve_low_complexity"`

	// MaxStepsPerPlan limits the number of steps in a single plan
	MaxStepsPerPlan int `json:"max_steps_per_plan" yaml:"max_steps_per_plan"`

	// PromptTemplate is the template for planning prompts
	PromptTemplate string `json:"prompt_template,omitempty" yaml:"prompt_template,omitempty"`
}

PlanningConfig holds configuration for planning mode

type RefinementConfig

type RefinementConfig struct {
	// Enabled enables automatic plan refinement
	Enabled bool `json:"enabled" yaml:"enabled"`

	// Triggers defines when refinement should occur
	Triggers []PlanRefinementTrigger `json:"triggers" yaml:"triggers"`

	// MaxRefinements is the maximum number of refinements allowed
	MaxRefinements int `json:"max_refinements" yaml:"max_refinements"`

	// PromptTemplate is the template for refinement prompts
	PromptTemplate string `json:"prompt_template,omitempty" yaml:"prompt_template,omitempty"`
}

RefinementConfig holds configuration for plan refinement

type StepResult

type StepResult struct {
	Success     bool          `json:"success"`
	Output      string        `json:"output,omitempty"`
	Error       string        `json:"error,omitempty"`
	CompletedAt time.Time     `json:"completed_at"`
	Duration    time.Duration `json:"duration"`
}

StepResult represents the result of executing a plan step

type WorkerMode

type WorkerMode string

WorkerMode defines the operational mode for workers

const (
	// ModeCombined is the traditional mode where planning and building happen together
	ModeCombined WorkerMode = "combined"
	// ModePlanning is for creating detailed plans without making changes
	ModePlanning WorkerMode = "planning"
	// ModeBuilding is for executing approved plans
	ModeBuilding WorkerMode = "building"
)

func (WorkerMode) IsValid

func (m WorkerMode) IsValid() bool

IsValid checks if the mode is valid

func (WorkerMode) String

func (m WorkerMode) String() string

String returns the string representation of the mode

Jump to

Keyboard shortcuts

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