workflow

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyIntent added in v1.2.0

func ClassifyIntent(ctx context.Context, p provider.LLMProvider, modelID string, input string, prompts *PromptRegistry) (*m31types.IntentResult, error)

ClassifyIntent uses an LLM to classify the user's input intent. Falls back to the keyword-based ClassifyPrompt on failure or timeout.

func ClassifyPrompt

func ClassifyPrompt(goal string, workDir string) m31types.ComplexityLevel

ClassifyPrompt estimates the complexity of a user's goal using heuristics. Factors considered:

  • Keyword/phrase matching
  • Goal length and sentence count
  • Number of existing project files (proxy for project size)

func FallbackClassifyIntent added in v1.2.0

func FallbackClassifyIntent(goal string, workDir string) *m31types.IntentResult

FallbackClassifyIntent converts the keyword-based ClassifyPrompt result into an IntentResult for consistent downstream handling.

func ParsePlan

func ParsePlan(markdown string) (*m31types.Plan, error)

ParsePlan extracts a structured Plan from rich markdown content. The markdown is expected to follow the format defined in plan-format.md. Sections that cannot be parsed are left empty rather than causing an error.

func ShouldStartWorkflow added in v1.2.0

func ShouldStartWorkflow(result *m31types.IntentResult) bool

ShouldStartWorkflow returns true when the classified intent warrants a structured workflow (feature, bugfix, refactor, chore) with sufficient confidence (≥ 0.7).

func WorkflowModeForComplexity

func WorkflowModeForComplexity(c m31types.ComplexityLevel) m31types.WorkflowMode

WorkflowModeForComplexity maps complexity to a workflow mode. ModeAuto delegates to this mapping.

Types

type DemonstrationReadyMsg

type DemonstrationReadyMsg struct {
	Content string
}

DemonstrationReadyMsg carries the generated demonstration content to the TUI.

type DiffStats

type DiffStats struct {
	FilesAdded    int
	FilesModified int
	FilesDeleted  int
	Insertions    int
	Deletions     int
}

DiffStats holds file change statistics from git diff.

type DiscussCompleteness added in v1.2.0

type DiscussCompleteness struct {
	Score        int // 0-100
	Answered     int
	Skipped      int
	Total        int
	MissingAreas []string
}

DiscussCompleteness holds the result of an answer completeness check.

type DiscussCompletenessMsg added in v1.2.0

type DiscussCompletenessMsg struct {
	Score        int // 0-100
	MissingAreas []string
}

DiscussCompletenessMsg is emitted after the answer completeness check.

type DiscussIssue added in v1.2.0

type DiscussIssue struct {
	Severity      string // "blocker" or "warning"
	Category      string // yes_no, vague, duplicate, redundant
	Message       string
	QuestionIndex int
}

DiscussIssue represents a quality issue found in generated questions.

type DiscussQualityMsg added in v1.2.0

type DiscussQualityMsg struct {
	Passed   bool
	Warnings int
	Retried  bool
}

DiscussQualityMsg is emitted after the question quality checker runs.

type DiscussState

type DiscussState struct {
	Questions []string
	Answers   map[int]string
}

DiscussState holds the questions and collected answers for the discuss phase.

type Engine

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

Engine orchestrates the six-phase workflow.

func NewEngine

func NewEngine(sessionID, workDir, backupDir, planningDir string, p provider.LLMProvider, modelID string,
	dispatcher *tools.Dispatcher, tokenEst *tokens.Estimator, sessionMgr *session.Manager, cfg *config.Config) (*Engine, error)

NewEngine creates a workflow engine.

func NewEngineFromOptions

func NewEngineFromOptions(opts EngineOptions) (*Engine, error)

NewEngineFromOptions creates a workflow engine from an EngineOptions struct.

func (*Engine) BuildSummary

func (e *Engine) BuildSummary() ShipSummary

BuildSummary creates a ShipSummary from the current session state.

func (*Engine) CheckDiscussCompleteness added in v1.2.0

func (e *Engine) CheckDiscussCompleteness() DiscussCompleteness

CheckDiscussCompleteness evaluates how well the collected answers cover the goal. Called by the TUI after all answers are collected, before proceeding to Plan.

func (*Engine) DiscussState

func (e *Engine) DiscussState() DiscussState

DiscussState returns a copy of the current discuss state. The TUI uses this to read the parsed questions after the discuss phase returns. The returned struct is a value copy so mutations by the TUI do not affect the engine's internal state.

func (*Engine) FinalizeDiscuss

func (e *Engine) FinalizeDiscuss() error

func (*Engine) GenerateFollowUpsIfNeeded added in v1.2.0

func (e *Engine) GenerateFollowUpsIfNeeded(ctx context.Context) ([]string, error)

GenerateFollowUpsIfNeeded creates follow-up questions when answers are incomplete. Called by the TUI after CheckDiscussCompleteness if score is low.

func (*Engine) HealTask

func (e *Engine) HealTask(ctx context.Context, taskID int) (bool, error)

HealTask triggers self-healing for a specific task by ID. Returns true if healing was attempted, false if the task cannot be healed.

func (*Engine) IntentResult added in v1.2.0

func (e *Engine) IntentResult() *m31types.IntentResult

IntentResult returns the stored intent classification result, or nil if unset.

func (*Engine) PlanContent

func (e *Engine) PlanContent() string

PlanContent returns the current plan markdown content.

func (*Engine) PlanVersion

func (e *Engine) PlanVersion() int

PlanVersion returns the current plan version number. Version 1 is the initial plan; each refinement increments it.

func (*Engine) RunPhase

func (e *Engine) RunPhase(ctx context.Context, phase m31types.WorkflowPhase, goal string) (*PhaseResult, error)

RunPhase executes the given workflow phase and returns the result.

func (*Engine) SessionID

func (e *Engine) SessionID() string

SessionID returns the current session ID.

func (*Engine) SetGit

func (e *Engine) SetGit(g *git.Git)

SetGit sets the git instance on the engine. Required before running any phase that uses git operations.

func (*Engine) SetIntentResult added in v1.2.0

func (e *Engine) SetIntentResult(ir *m31types.IntentResult)

SetIntentResult stores the LLM-classified intent result for downstream enrichment.

func (*Engine) SetLedger added in v1.1.0

func (e *Engine) SetLedger(l *ledger.Ledger)

SetLedger sets the shared ledger instance on the engine so the ship phase writes session records to the application-configured path instead of creating a new ledger at a hardcoded location.

func (*Engine) SetModel

func (e *Engine) SetModel(modelID string, p provider.LLMProvider)

SetModel updates the active model ID and provider for the engine.

func (*Engine) SetMsgEmitter

func (e *Engine) SetMsgEmitter(em MsgEmitter)

SetMsgEmitter sets the callback for emitting messages back to the TUI.

func (*Engine) SetPhaseModel

func (e *Engine) SetPhaseModel(phase m31types.WorkflowPhase, modelID string)

SetPhaseModel assigns a model ID to a specific workflow phase. This takes the highest priority over AgentsConfig and cfg.Model.Default. Called by the TUI after the user selects Planning/Coding models in the picker.

func (*Engine) SetRefinementFeedback

func (e *Engine) SetRefinementFeedback(feedback string)

SetRefinementFeedback stores user feedback for the next plan regeneration. The plan phase reads this field to inject feedback into the LLM context. Duplicate feedback is ignored — only new feedback bumps the plan version.

func (*Engine) SetSessionID

func (e *Engine) SetSessionID(id string)

SetSessionID updates the engine's session ID.

func (*Engine) SetWorkflowMode

func (e *Engine) SetWorkflowMode(mode m31types.WorkflowMode)

SetWorkflowMode sets the mode that controls phase-skipping behaviour.

func (*Engine) SkipDiscuss

func (e *Engine) SkipDiscuss() error

SkipDiscuss fills default (empty) answers and saves.

func (*Engine) SubmitDiscussAnswer

func (e *Engine) SubmitDiscussAnswer(index int, answer string) error

SubmitDiscussAnswer records an answer for a discuss question.

func (*Engine) Transition

func (e *Engine) Transition(ctx context.Context, from, to m31types.WorkflowPhase) error

Transition saves a checkpoint and writes STATE.md for the new phase. Validates the transition is allowed by the phase ordering guard.

func (*Engine) WorkflowMode

func (e *Engine) WorkflowMode() m31types.WorkflowMode

WorkflowMode returns the current workflow mode.

type EngineOptions

type EngineOptions struct {
	SessionID   string
	WorkDir     string
	BackupDir   string
	PlanningDir string
	Provider    provider.LLMProvider
	ModelID     string
	Dispatcher  *tools.Dispatcher
	TokenEst    *tokens.Estimator
	SessionMgr  *session.Manager
	Config      *config.Config
}

EngineOptions holds all parameters for creating a new Engine.

type ExecuteLoopDetectMsg added in v1.2.0

type ExecuteLoopDetectMsg struct {
	TaskID   int
	ToolName string
	Count    int
}

ExecuteLoopDetectMsg is emitted when a tool call loop is detected.

type ExecutePreflightMsg added in v1.2.0

type ExecutePreflightMsg struct {
	Passed bool
	Issues []string
}

ExecutePreflightMsg is emitted after pre-execution validation.

type ExecutePreflightResult added in v1.2.0

type ExecutePreflightResult struct {
	Passed bool
	Issues []string
}

ExecutePreflightResult holds the outcome of pre-execution validation.

type ExecuteQualityGateMsg added in v1.2.0

type ExecuteQualityGateMsg struct {
	TaskID  int
	Passed  bool
	Checked int
	Failed  int
}

ExecuteQualityGateMsg is emitted after per-task acceptance criteria check.

type InitAnalysisMsg added in v1.2.0

type InitAnalysisMsg struct {
	ProjectType     string
	Framework       string
	Language        string
	DependencyCount int
	TestFileRatio   float64
	FileCount       int
	HealthScore     int // 0-100
}

InitAnalysisMsg is emitted when deep project analysis completes.

type InitPreflightMsg added in v1.2.0

type InitPreflightMsg struct {
	Passed         bool
	RuntimeVersion string
	DiskSpaceOK    bool
	GitRemoteOK    bool
	Issues         []string
}

InitPreflightMsg is emitted when environment pre-flight checks complete.

type IntermediateProgressMsg

type IntermediateProgressMsg struct {
	Phase   string
	Message string
}

IntermediateProgressMsg is emitted during long operations to show progress.

type MsgEmitter

type MsgEmitter interface {
	Emit(msg any)
}

MsgEmitter is a callback interface for emitting events back to the TUI. Uses `any` to avoid coupling the workflow to the Bubble Tea framework.

type PhaseResult

type PhaseResult struct {
	Phase               m31types.WorkflowPhase
	Success             bool
	Messages            []m31types.Message
	Tasks               []m31types.Task
	Error               string
	DurationMs          int64
	NeedsAnswers        bool
	RequiresManualInput bool
	WorkflowMode        m31types.WorkflowMode // mode to use for subsequent transitions

	// Execution metrics (populated by Execute/Ship phases)
	Usage     *m31types.Usage  // token usage from LLM calls
	Cost      float64          // estimated cost
	ToolCalls int              // number of tool calls made
	Commits   []git.CommitInfo // commits created during phase
	DiffStats DiffStats        // file change statistics (Ship phase)

	// Manual verification steps from the plan (populated by Verify phase)
	ManualVerificationSteps []string

	// Demonstration content (populated by Ship phase)
	Demonstration string
}

PhaseResult holds the outcome of a workflow phase.

type PhaseTransitionCompleteMsg

type PhaseTransitionCompleteMsg struct {
	From    string
	To      string
	Success bool
	Error   string
}

PhaseTransitionCompleteMsg is emitted when a phase transition completes.

type PhaseTransitionStartMsg

type PhaseTransitionStartMsg struct {
	From    string
	To      string
	Context string
}

PhaseTransitionStartMsg is emitted when a phase transition begins.

type PlanCheckMsg added in v1.2.0

type PlanCheckMsg struct {
	Passed     bool
	IssueCount int
	Blockers   int
	Warnings   int
}

PlanCheckMsg is emitted after the plan checker reviews the plan.

type PlanCheckResult added in v1.2.0

type PlanCheckResult struct {
	Passed    bool
	Issues    []PlanIssue
	Iteration int
}

PlanCheckResult holds the outcome of the plan checker review.

type PlanChunkProgressMsg added in v1.2.0

type PlanChunkProgressMsg struct {
	Wave        int
	TotalWaves  int
	TasksInWave int
}

PlanChunkProgressMsg is emitted during chunked plan generation.

type PlanIssue added in v1.2.0

type PlanIssue struct {
	Severity string // "blocker" or "warning"
	Category string // granularity, acceptance, dependency, coverage, alignment, concreteness, security, gap
	Message  string
	TaskID   int // 0 if not task-specific
}

PlanIssue represents a single issue found by the plan checker or coverage gates.

type PlanOutline added in v1.2.0

type PlanOutline struct {
	Title      string        `json:"title"`
	Waves      []WaveOutline `json:"waves"`
	TotalTasks int           `json:"total_tasks"`
}

PlanOutline represents the high-level structure of a chunked plan.

type PlanProgressMsg

type PlanProgressMsg struct {
	Version int
	Message string
}

PlanProgressMsg reports plan generation progress with version info.

type PlanRevisionMsg added in v1.2.0

type PlanRevisionMsg struct {
	Iteration       int
	MaxIterations   int
	IssuesRemaining int
}

PlanRevisionMsg is emitted during each plan revision iteration.

type PreflightCheck added in v1.2.0

type PreflightCheck struct {
	Passed         bool
	RuntimeVersion string
	DiskSpaceOK    bool
	GitRemoteOK    bool
	Issues         []string
}

PreflightCheck holds the results of environment pre-flight checks.

type ProjectAnalysis added in v1.2.0

type ProjectAnalysis struct {
	ProjectType     string
	Framework       string
	Language        string
	DependencyCount int
	TestFileRatio   float64
	FileCount       int
	HealthScore     int
	Details         []string
}

ProjectAnalysis holds the results of deep project analysis.

type PromptRegistry

type PromptRegistry struct {
	Base             string
	ToolUse          string
	PlanFormat       string
	ExecuteTask      string
	Discuss          string
	SelfHeal         string
	Demonstration    string
	Autonomous       string
	ContextAwareness string
	CodeQuality      string
	CodeIntelligence string
	Research         string
	PlanCheck        string
	PlanRevise       string
	PlanOutline      string
	DiscussFollowup  string
	IntentClassify   string
}

PromptRegistry holds all loaded prompt templates.

func LoadPrompts

func LoadPrompts() (*PromptRegistry, error)

LoadPrompts reads all embedded prompt files and returns a registry.

type QualityGateResult added in v1.2.0

type QualityGateResult struct {
	TaskID  int
	Passed  bool
	Checked int
	Failed  int
	Details []string
}

QualityGateResult holds the outcome of checking acceptance criteria against file state.

type ResearchProgressMsg added in v1.2.0

type ResearchProgressMsg struct {
	Phase    string
	Message  string
	Complete bool
}

ResearchProgressMsg is emitted during the pre-plan research sub-step.

type SecurityFinding added in v1.2.0

type SecurityFinding struct {
	Severity string // "high", "medium", "low"
	File     string
	Line     int
	Pattern  string
	Message  string
}

SecurityFinding holds a security-related finding from scanning task files.

type SelfHealCompleteMsg

type SelfHealCompleteMsg struct {
	TaskID  int
	Attempt int
	Max     int
	Success bool
	Error   string
}

SelfHealCompleteMsg is emitted when a self-heal attempt finishes.

type SelfHealStartMsg

type SelfHealStartMsg struct {
	TaskID  int
	Attempt int
	Max     int
}

SelfHealStartMsg is emitted when a self-heal attempt begins.

type ShipChangelogMsg added in v1.2.0

type ShipChangelogMsg struct {
	Content string
	Entries int
}

ShipChangelogMsg is emitted when the changelog is generated.

type ShipPreflightMsg added in v1.2.0

type ShipPreflightMsg struct {
	Passed bool
	Issues []string
}

ShipPreflightMsg is emitted when the pre-ship checklist runs.

type ShipPreflightResult added in v1.2.0

type ShipPreflightResult struct {
	Passed bool
	Issues []string
}

ShipPreflightResult holds the outcome of the pre-ship checklist.

type ShipSummary

type ShipSummary struct {
	TaskDone    int
	TaskTotal   int
	TaskFailed  int
	TaskSkipped int
	Commits     []git.CommitInfo
	Duration    time.Duration
	SessionID   string
}

ShipSummary holds the session completion summary.

type TaskStartMsg

type TaskStartMsg struct {
	Task m31types.Task
}

TaskStartMsg is emitted when a task begins execution.

type TaskStub added in v1.2.0

type TaskStub struct {
	ID           int    `json:"id"`
	Action       string `json:"action"`
	Description  string `json:"description"`
	Dependencies []int  `json:"dependencies"`
	Category     string `json:"category"`
}

TaskStub is a minimal task representation for the outline phase.

type TaskUpdateMsg

type TaskUpdateMsg struct {
	Task   m31types.Task
	Status string
}

TaskUpdateMsg is emitted when a task status changes during execution.

type ThinkingCompleteMsg

type ThinkingCompleteMsg struct {
	Context string
}

ThinkingCompleteMsg is emitted when LLM processing ends.

type ThinkingStartMsg

type ThinkingStartMsg struct {
	Context string
}

ThinkingStartMsg is emitted when LLM processing begins.

type ToolCallTracker added in v1.2.0

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

ToolCallTracker tracks tool call patterns across iterations to detect loops.

func NewToolCallTracker added in v1.2.0

func NewToolCallTracker(maxLoop int) *ToolCallTracker

NewToolCallTracker creates a tracker with the given loop threshold.

func (*ToolCallTracker) Count added in v1.2.0

func (t *ToolCallTracker) Count() int

Count returns total tool calls recorded.

func (*ToolCallTracker) LastLoopTool added in v1.2.0

func (t *ToolCallTracker) LastLoopTool() string

LastLoopTool returns the tool name involved in the most recent loop, or empty.

func (*ToolCallTracker) Record added in v1.2.0

func (t *ToolCallTracker) Record(name, input string) bool

Record adds a tool call to the history and returns true if a loop is detected.

type ToolCompleteMsg

type ToolCompleteMsg struct {
	ToolName   string
	Success    bool
	DurationMs int64
	Error      string
	FilePath   string // populated for file-writing tools (FileWrite, Edit, FileDelete, FileMove)
}

ToolCompleteMsg is emitted when a tool call finishes execution.

type ToolStartMsg

type ToolStartMsg struct {
	ToolName    string
	Description string
}

ToolStartMsg is emitted when a tool call begins execution.

type VerificationResult

type VerificationResult struct {
	TaskID     int
	FilesExist bool
	SyntaxOK   bool
	TestsOK    bool
	Errors     []string
}

VerificationResult holds the outcome of verifying a task.

type VerifyReport added in v1.2.0

type VerifyReport struct {
	SessionID   string
	Timestamp   time.Time
	Total       int
	Passed      int
	Failed      int
	Skipped     int
	Results     []VerifyTaskReport
	Security    []SecurityFinding
	ManualSteps []string
}

VerifyReport holds the structured verification report.

type VerifyReportMsg added in v1.2.0

type VerifyReportMsg struct {
	Report   string
	PassRate int // percentage 0-100
}

VerifyReportMsg is emitted when the verification report is generated.

type VerifyTaskReport added in v1.2.0

type VerifyTaskReport struct {
	TaskID      int
	Description string
	Status      string
	FilesExist  bool
	BuildOK     bool
	TestsOK     bool
	Errors      []string
	Duration    time.Duration
}

VerifyTaskReport holds per-task verification results.

type WaveOutline added in v1.2.0

type WaveOutline struct {
	Wave  int        `json:"wave"`
	Tasks []TaskStub `json:"tasks"`
}

WaveOutline groups tasks by execution wave.

Jump to

Keyboard shortcuts

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