workflow

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package workflow is the Stage-1 namespace for workflow + workspace + trajectory types in package engine. See ../REFACTOR_PLAN.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinWorkflows

func BuiltinWorkflows() map[string]*Workflow

BuiltinWorkflows returns the built-in workflow templates.

func CompareReports

func CompareReports(before, after *WorkspaceDiffReport) string

CompareReports shows the differences between two report snapshots.

func EvalCondition

func EvalCondition(condition string, vars map[string]string) bool

EvalCondition evaluates a simple condition expression with variable substitution. Supports: == != > < >= <= comparisons after substitution.

func FormatAsMarkdown

func FormatAsMarkdown(report *WorkspaceDiffReport) string

FormatAsMarkdown renders the report as a markdown document suitable for PR descriptions.

func FormatAsTerminal

func FormatAsTerminal(report *WorkspaceDiffReport) string

FormatAsTerminal renders the report with ANSI color codes for terminal display.

func FormatForCommit

func FormatForCommit(report *WorkspaceDiffReport) string

FormatForCommit renders the report in a compact format suitable for a commit message body.

func FormatResult

func FormatResult(result *WorkflowResult) string

FormatResult produces a human-readable summary of a workflow result.

func SubstituteVars

func SubstituteVars(template string, vars map[string]string) string

SubstituteVars replaces {{.varName}} placeholders in the template with values from vars.

func ValidateWorkflow

func ValidateWorkflow(wf *Workflow) []string

ValidateWorkflow checks the workflow for issues and returns a list of warnings.

Types

type DiffReporter

type DiffReporter struct {
	ProjectDir string
	// contains filtered or unexported fields
}

DiffReporter generates comprehensive diff reports for a workspace.

func NewDiffReporter

func NewDiffReporter(projectDir string) *DiffReporter

NewDiffReporter creates a new DiffReporter for the given project directory.

func (*DiffReporter) GenerateFromGit

func (dr *DiffReporter) GenerateFromGit() (*WorkspaceDiffReport, error)

GenerateFromGit builds a WorkspaceDiffReport by running git diff commands in the project directory.

func (*DiffReporter) GenerateReport

func (dr *DiffReporter) GenerateReport(modifiedFiles map[string]string) *WorkspaceDiffReport

GenerateReport creates a WorkspaceDiffReport from a map of modified file paths to their diff content. The modifiedFiles map keys are file paths and values are unified diff content for each file.

type Engine

type Engine = WorkflowEngine

Engine executes Workflows against a model-call function.

func NewEngine

func NewEngine(executeFn func(ctx context.Context, agent, prompt string) (string, error)) *Engine

NewEngine returns a workflow engine that delegates step execution to the provided function (which typically wraps an LLM call).

type FileDiffReport

type FileDiffReport struct {
	Path       string
	Status     string // "added", "modified", "deleted"
	Additions  int
	Deletions  int
	Summary    string
	KeyChanges []string
}

FileDiffReport describes the diff status and summary for a single file.

type FileState

type FileState struct {
	Path        string
	Size        int64
	ModTime     time.Time
	Language    string
	IsTest      bool
	IsGenerated bool
	Hash        string
}

FileState represents the tracked state of a single file in the workspace.

type Result

type Result = WorkflowResult

Result is the outcome of running a Workflow.

type Step

type Step = WorkflowStep

Step is one node in a Workflow.

type StepResult

type StepResult struct {
	StepName string        `json:"step_name"`
	Status   string        `json:"status"` // "success", "failed", "skipped"
	Output   string        `json:"output"`
	Duration time.Duration `json:"duration"`
	Error    string        `json:"error"`
}

StepResult holds the result of a single step execution.

type TrajectoryEvent

type TrajectoryEvent struct {
	Index     int               `json:"index"`
	Type      string            `json:"type"` // "thought", "action", "observation", "error", "decision"
	Content   string            `json:"content"`
	ToolName  string            `json:"tool_name,omitempty"`
	Duration  time.Duration     `json:"duration"`
	Tokens    int               `json:"tokens"`
	Timestamp time.Time         `json:"timestamp"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

TrajectoryEvent represents a single event in an agent's trajectory.

type TrajectoryInspector

type TrajectoryInspector struct {
	Events    []TrajectoryEvent `json:"events"`
	SessionID string            `json:"session_id"`
	StartTime time.Time         `json:"start_time"`
	// contains filtered or unexported fields
}

TrajectoryInspector records and visualizes agent action sequences for debugging and analysis. Inspired by SWE-agent's trajectory inspector.

func NewTrajectoryInspector

func NewTrajectoryInspector(sessionID string) *TrajectoryInspector

NewTrajectoryInspector creates a new inspector for the given session.

func (*TrajectoryInspector) ExportJSON

func (ti *TrajectoryInspector) ExportJSON() (string, error)

ExportJSON serializes the trajectory inspector state to JSON.

func (*TrajectoryInspector) FindPatterns

func (ti *TrajectoryInspector) FindPatterns() []string

FindPatterns analyzes the trajectory for common patterns and returns descriptions.

func (*TrajectoryInspector) GetByType

func (ti *TrajectoryInspector) GetByType(eventType string) []TrajectoryEvent

GetByType returns all events matching the given type.

func (*TrajectoryInspector) GetToolUsage

func (ti *TrajectoryInspector) GetToolUsage() map[string]int

GetToolUsage returns a map of tool names to their usage counts.

func (*TrajectoryInspector) Record

func (ti *TrajectoryInspector) Record(eventType, content string, toolName string, duration time.Duration, tokens int)

Record adds a new event to the trajectory.

func (*TrajectoryInspector) RenderStats

func (ti *TrajectoryInspector) RenderStats() string

RenderStats returns a formatted summary of trajectory statistics.

func (*TrajectoryInspector) RenderTimeline

func (ti *TrajectoryInspector) RenderTimeline() string

RenderTimeline returns a formatted timeline of all events in the trajectory.

func (*TrajectoryInspector) Replay

func (ti *TrajectoryInspector) Replay(speed float64) <-chan TrajectoryEvent

Replay returns a channel that emits events at the given speed multiplier. A speed of 1.0 replays in real-time, 2.0 at double speed, etc.

func (*TrajectoryInspector) Summarize

func (ti *TrajectoryInspector) Summarize() string

Summarize returns a one-paragraph summary of what happened in the trajectory.

type Workflow

type Workflow struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Steps       []WorkflowStep    `json:"steps"`
	Variables   map[string]string `json:"variables"`
	OnFailure   string            `json:"on_failure"` // "abort", "continue", "retry"
	MaxDuration time.Duration     `json:"max_duration"`
	CreatedAt   time.Time         `json:"created_at"`
}

Workflow represents a multi-step automated workflow definition.

type WorkflowEngine

type WorkflowEngine struct {
	Workflows map[string]*Workflow
	ExecuteFn func(ctx context.Context, action, input string) (string, error)
	// contains filtered or unexported fields
}

WorkflowEngine manages and executes workflows.

func NewWorkflowEngine

func NewWorkflowEngine(executeFn func(context.Context, string, string) (string, error)) *WorkflowEngine

NewWorkflowEngine creates a new WorkflowEngine with the given execution function.

func (*WorkflowEngine) Execute

func (we *WorkflowEngine) Execute(ctx context.Context, workflow *Workflow) (*WorkflowResult, error)

Execute runs a workflow to completion, resolving dependencies and executing steps.

func (*WorkflowEngine) LoadWorkflow

func (we *WorkflowEngine) LoadWorkflow(path string) (*Workflow, error)

LoadWorkflow parses a JSON workflow file and validates the step dependencies form a DAG.

type WorkflowResult

type WorkflowResult struct {
	Status    string            `json:"status"` // "success", "failed", "aborted"
	Steps     []StepResult      `json:"steps"`
	Duration  time.Duration     `json:"duration"`
	Variables map[string]string `json:"variables"`
}

WorkflowResult holds the result of a workflow execution.

type WorkflowStep

type WorkflowStep struct {
	Name       string        `json:"name"`
	Action     string        `json:"action"` // "prompt", "bash", "edit", "read", "condition", "loop"
	Input      string        `json:"input"`  // template with {{.Variable}} substitution
	Output     string        `json:"output"` // variable name to store result
	Condition  string        `json:"condition"`
	MaxRetries int           `json:"max_retries"`
	Timeout    time.Duration `json:"timeout"`
	DependsOn  []string      `json:"depends_on"`
}

WorkflowStep represents a single step in a workflow.

type WorkspaceDiffReport

type WorkspaceDiffReport struct {
	Files           []FileDiffReport
	TotalAdditions  int
	TotalDeletions  int
	FilesAdded      int
	FilesModified   int
	FilesDeleted    int
	SessionDuration time.Duration
	GeneratedAt     time.Time
}

WorkspaceDiffReport contains the full report of all workspace changes made during a session.

type WorkspaceState

type WorkspaceState struct {
	OpenFiles     map[string]*FileState
	ModifiedFiles map[string]time.Time
	StagedFiles   []string
	ProjectDir    string
	LastScan      time.Time
	// contains filtered or unexported fields
}

WorkspaceState maintains awareness of the current project state including which files are open, modified, and staged. It provides workspace context to the agent for informed decision-making.

func NewWorkspaceState

func NewWorkspaceState(projectDir string) *WorkspaceState

NewWorkspaceState creates a new WorkspaceState for the given project directory.

func (*WorkspaceState) BuildContextForAgent

func (ws *WorkspaceState) BuildContextForAgent() string

BuildContextForAgent formats workspace awareness for inclusion in a system prompt.

func (*WorkspaceState) DetectExternalChanges

func (ws *WorkspaceState) DetectExternalChanges() []string

DetectExternalChanges returns files that changed outside of hawk's modifications.

func (*WorkspaceState) GetModified

func (ws *WorkspaceState) GetModified() []string

GetModified returns all files modified in this session.

func (*WorkspaceState) GetOpened

func (ws *WorkspaceState) GetOpened() []string

GetOpened returns all files the agent has read.

func (*WorkspaceState) HasChanged

func (ws *WorkspaceState) HasChanged(path string) bool

HasChanged returns true if the file has changed on disk since it was last read.

func (*WorkspaceState) MarkModified

func (ws *WorkspaceState) MarkModified(path string)

MarkModified tracks that the agent has modified this file.

func (*WorkspaceState) MarkOpened

func (ws *WorkspaceState) MarkOpened(path string)

MarkOpened tracks that the agent has read this file.

func (*WorkspaceState) MarkStaged

func (ws *WorkspaceState) MarkStaged(path string)

MarkStaged tracks that a file is staged for commit.

func (*WorkspaceState) Reset

func (ws *WorkspaceState) Reset()

Reset clears all tracking state.

func (*WorkspaceState) Scan

func (ws *WorkspaceState) Scan() error

Scan walks the project directory and updates file states, detecting changes since the last scan.

func (*WorkspaceState) Summary

func (ws *WorkspaceState) Summary() string

Summary returns a human-readable summary of the workspace state.

Jump to

Keyboard shortcuts

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