workflow

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinWorkflows = []WorkflowDefinition{
	{
		Name:        "sentry-fixer",
		Description: "Analyze and fix unresolved Sentry errors in a project, then create a PR with all fixes",
		Builtin:     true,
		Steps: []StepDefinition{
			{
				Name: "fix_bugs",
				Type: StepTypeSession,
				Config: mustJSON(SessionStepConfig{
					RepoURL: "{{.Params.repo_url}}",
					Prompt: `You are fixing Sentry errors for a project.

## Sentry Project
- **Organization:** {{.Params.sentry_org}}
- **Project:** {{.Params.sentry_project}}
{{if .Params.max_issues}}- **Max issues to fix:** {{.Params.max_issues}}{{end}}

## Instructions
1. Use the Sentry MCP tools to list unresolved issues for this project:
   - Call list_sentry_issues with organization "{{.Params.sentry_org}}" and project "{{.Params.sentry_project}}" to get all unresolved errors
2. Prioritize issues by occurrence count and severity (fatal > error > warning)
3. {{if .Params.max_issues}}Process the top {{.Params.max_issues}} most important issues only.{{else}}Process all promising issues.{{end}} For each:
   a. Call get_sentry_issue to get full details (title, culprit, message)
   b. Call get_sentry_issue_events to get the latest event with stack trace, breadcrumbs, and context
   c. Analyze the stack trace — find the relevant code in this repository
   d. Determine if it's fixable in code (skip infrastructure/network/external service errors)
   e. If fixable: implement the fix and create a separate git commit with message "fix(sentry): <short description>"
4. After processing issues, summarize what you fixed and what you skipped (and why)

## Rules
- Do NOT create placeholder or stub fixes
- Do NOT add generic try/catch wrappers that hide errors
- If an error is from an external dependency or infrastructure, skip it and explain why
- Only modify files directly related to each fix
- Each fix should be a SEPARATE commit so the PR is easy to review
- If no issues are fixable in code, make NO changes and explain why`,
					ProviderKey: "{{.Params.provider_key}}",
					ToolKeyRef:  "{{.Params.key_name}}",
					Tools: mustJSON([]tools.SessionTool{
						{Name: "sentry"},
					}),
				}),
			},
		},
		Parameters: []ParameterDefinition{
			{Name: "sentry_org", Required: true},
			{Name: "sentry_project", Required: true},
			{Name: "repo_url", Required: true},
			{Name: "key_name", Required: true},
			{Name: "provider_key", Required: false},
			{Name: "max_issues", Default: "5"},
		},
	},
}

BuiltinWorkflows defines the set of built-in workflow definitions.

Functions

func BuildSessionRequest added in v0.4.0

func BuildSessionRequest(ctx context.Context, def WorkflowDefinition, params map[string]string, keyReg keys.Registry) (*session.CreateSessionRequest, error)

BuildSessionRequest builds a CreateSessionRequest from a workflow definition, preset params, and key registry. It finds the first "session" step in the definition and renders its config with the provided params.

func MarshalMapJSON

func MarshalMapJSON(m map[string]string) string

MarshalMapJSON serializes a map to a JSON string.

func Render

func Render(tmpl string, ctx TemplateContext) (string, error)

Render evaluates a Go text/template string against the given context. Returns an error on missing keys or if the output exceeds 1MB.

func SeedBuiltins

func SeedBuiltins(ctx context.Context, reg Registry, cfgStore *SQLiteConfigStore) error

SeedBuiltins inserts or replaces built-in workflow definitions. It also removes stale built-in workflows (and their configs) that are no longer defined in code. This is idempotent and safe to call on every startup.

func UnmarshalMapJSON

func UnmarshalMapJSON(data string) map[string]string

UnmarshalMapJSON deserializes a JSON string to a map.

Types

type ConfigStore added in v0.4.0

type ConfigStore interface {
	Create(ctx context.Context, cfg WorkflowConfig) (int64, error)
	List(ctx context.Context) ([]WorkflowConfig, error)
	Get(ctx context.Context, id int) (*WorkflowConfig, error)
	Delete(ctx context.Context, id int) error
}

ConfigStore persists workflow configurations.

type ParameterDefinition

type ParameterDefinition struct {
	Name     string `json:"name"`
	Required bool   `json:"required"`
	Default  string `json:"default,omitempty"`
}

ParameterDefinition describes a workflow input parameter.

type Registry

type Registry interface {
	Create(ctx context.Context, def WorkflowDefinition) error
	List(ctx context.Context) ([]WorkflowDefinition, error)
	Get(ctx context.Context, name string) (*WorkflowDefinition, error)
	Delete(ctx context.Context, name string) error
	DeleteBuiltin(ctx context.Context, name string) error            // for cleanup of stale builtins
	UpdateBuiltin(ctx context.Context, def WorkflowDefinition) error // for updating existing builtins on startup
}

Registry manages workflow definitions.

type SQLiteConfigStore added in v0.4.0

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

SQLiteConfigStore implements ConfigStore backed by SQLite.

func NewSQLiteConfigStore added in v0.4.0

func NewSQLiteConfigStore(db *sql.DB) *SQLiteConfigStore

NewSQLiteConfigStore creates a new SQLite-backed workflow config store.

func (*SQLiteConfigStore) Create added in v0.4.0

func (s *SQLiteConfigStore) Create(ctx context.Context, cfg WorkflowConfig) (int64, error)

Create inserts a new workflow config and returns the auto-generated ID.

func (*SQLiteConfigStore) Delete added in v0.4.0

func (s *SQLiteConfigStore) Delete(ctx context.Context, id int) error

Delete removes a workflow config by ID.

func (*SQLiteConfigStore) DeleteByWorkflow added in v0.4.0

func (s *SQLiteConfigStore) DeleteByWorkflow(ctx context.Context, workflowName string) (int64, error)

DeleteByWorkflow removes all configs referencing a given workflow name.

func (*SQLiteConfigStore) Get added in v0.4.0

Get returns a single workflow config by ID.

func (*SQLiteConfigStore) List added in v0.4.0

List returns all workflow configs ordered by creation time.

type SQLiteRegistry

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

SQLiteRegistry implements Registry backed by SQLite.

func NewSQLiteRegistry

func NewSQLiteRegistry(db *sql.DB) *SQLiteRegistry

NewSQLiteRegistry creates a new SQLite-backed workflow registry.

func (*SQLiteRegistry) Create

func (*SQLiteRegistry) Delete

func (r *SQLiteRegistry) Delete(ctx context.Context, name string) error

func (*SQLiteRegistry) DeleteBuiltin

func (r *SQLiteRegistry) DeleteBuiltin(ctx context.Context, name string) error

DeleteBuiltin removes a built-in workflow definition (used for cleanup of stale builtins on startup).

func (*SQLiteRegistry) Get

func (*SQLiteRegistry) List

func (*SQLiteRegistry) UpdateBuiltin

func (r *SQLiteRegistry) UpdateBuiltin(ctx context.Context, def WorkflowDefinition) error

UpdateBuiltin updates an existing built-in workflow definition's steps, params, and description.

type SessionStepConfig

type SessionStepConfig struct {
	RepoURL      string `json:"repo_url"`
	Prompt       string `json:"prompt"`
	SessionType  string `json:"session_type,omitempty"`
	ProviderKey  string `json:"provider_key,omitempty"`
	AccessToken  string `json:"access_token,omitempty"`
	CLI          string `json:"cli,omitempty"`
	AIModel      string `json:"ai_model,omitempty"`
	SourceBranch string `json:"source_branch,omitempty"`
	TargetBranch string `json:"target_branch,omitempty"`

	// PR review fields
	PRNumber   int    `json:"pr_number,omitempty"`
	OutputMode string `json:"output_mode,omitempty"`

	// Tool/MCP overrides
	Tools      json.RawMessage `json:"tools,omitempty"`
	MCPServers json.RawMessage `json:"mcp_servers,omitempty"`
	ToolKeyRef string          `json:"tool_key_ref,omitempty"`
}

SessionStepConfig is the configuration for a session step.

type StepDefinition

type StepDefinition struct {
	Name   string          `json:"name"`
	Type   StepType        `json:"type"`
	Config json.RawMessage `json:"config"`
}

StepDefinition describes a single step in a workflow.

type StepType

type StepType string

StepType defines what kind of action a workflow step performs.

const (
	StepTypeSession StepType = "session"
)

type TemplateContext

type TemplateContext struct {
	Params map[string]string            // workflow input parameters
	Steps  map[string]map[string]string // step name → output key → value
}

TemplateContext holds data available to Go templates in workflow steps.

type WorkflowConfig added in v0.4.0

type WorkflowConfig struct {
	ID             int               `json:"id"`
	Name           string            `json:"name"`
	Workflow       string            `json:"workflow"` // template name e.g. "sentry-fixer"
	Params         map[string]string `json:"params"`
	TimeoutSeconds int               `json:"timeout_seconds,omitempty"` // 0 = use default
	CreatedAt      time.Time         `json:"created_at"`
}

WorkflowConfig is a saved workflow configuration that can be run later.

type WorkflowDefinition

type WorkflowDefinition struct {
	Name        string                `json:"name"`
	Description string                `json:"description"`
	Builtin     bool                  `json:"builtin"`
	Steps       []StepDefinition      `json:"steps"`
	Parameters  []ParameterDefinition `json:"parameters"`
	CreatedAt   time.Time             `json:"created_at,omitempty"`
}

WorkflowDefinition describes a reusable workflow template.

Jump to

Keyboard shortcuts

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