workflow

package
v0.1.4-beta Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

CommitService orchestrates the commit workflow: status → LLM decides what to stage → security check → chunk diff → LLM messages → git commit(s).

Package workflow implements the unified git workflow engine.

All operations follow four phases:

  1. PREPARE — gather git context
  2. GENERATE — LLM interprets instruction → concrete args
  3. CONFIRM — (optional) save plan + blocker; return pending
  4. EXECUTE — run the git command

Operations that require confirmation use a three-step MCP protocol:

*_START  → Run()   → returns {status: "pending_approval", preview: "..."}
*_APPLY  → Apply() → executes the saved plan
*_ABORT  → Abort() → discards the plan

Index

Constants

View Source
const (
	StatusCompleted = "completed"
	StatusPending   = "pending_approval"
	StatusAborted   = "aborted"
)

Status values returned in Result.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitResult

type CommitResult struct {
	Operation string                `json:"operation"`
	Message   string                `json:"result,omitempty"`
	Commits   []string              `json:"commits,omitempty"`
	Excluded  []domain.ExcludedFile `json:"excluded,omitempty"`
	Warnings  []string              `json:"warnings,omitempty"`
	Type      string                `json:"type"`
}

CommitResult holds the outcome of a commit operation.

type CommitService

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

CommitService handles the commit workflow.

func NewCommitService

func NewCommitService(git ports.Git, llm ports.LLM, chunker ports.DiffChunker, security ports.SecurityService, cfg CommitServiceConfig) *CommitService

NewCommitService creates a new CommitService.

func (*CommitService) Execute

func (s *CommitService) Execute(instruction string, preview bool) (string, error)

Execute runs the full commit workflow (prepare + execute).

func (*CommitService) ExecuteFromPlan

func (s *CommitService) ExecuteFromPlan(messages []string, files []string, instruction string) (string, error)

ExecuteFromPlan commits using pre-approved messages and files from the plan. This avoids re-running PrepareCommit which might produce different results.

func (*CommitService) ExecutePrepared

func (s *CommitService) ExecutePrepared(messages []string, chunks []domain.DiffChunk, instruction string) (string, error)

ExecutePrepared commits using pre-generated messages from PrepareCommit.

func (*CommitService) PrepareCommit

func (s *CommitService) PrepareCommit(instruction string) ([]string, []domain.DiffChunk, []string, string, error)

PrepareCommit prepares the commit without executing it. Returns generated messages, chunks, warnings, and the decision reasoning.

type CommitServiceConfig

type CommitServiceConfig struct {
	BackgroundThreshold int    // diff size (chars) above which we run async
	ChunkSize           int    // max chars per diff chunk sent to LLM
	MaxLogLines         int    // circular buffer size for task.log
	LogPath             string // path to task log file
}

CommitServiceConfig holds tuneable values for the commit service.

func DefaultCommitServiceConfig

func DefaultCommitServiceConfig(contextWindow, backgroundThreshold, maxLogLines int, logPath string) CommitServiceConfig

DefaultCommitServiceConfig returns sensible defaults derived from Ollama context window.

type PrepContext

type PrepContext struct {
	CurrentBranch string
	Branches      string
	Tags          string
	Log           string
	UntrackedList string
}

PrepContext holds the git context gathered before calling the LLM. Each operation populates only the fields it needs.

type Result

type Result struct {
	Status  string            // "completed" | "pending_approval" | "aborted"
	Output  string            // Human-readable output (for completed)
	Preview string            // What will be done (for pending)
	Args    map[string]string // Resolved args from LLM (for pending)
}

Result is the return value of Run / Apply / Abort.

type Workflow

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

Workflow is the main workflow engine for git review operations.

func New

func New(git ports.Git, llm ports.LLM, confirm ports.Confirm, cfg *config.Config) *Workflow

New creates a new Workflow.

func (*Workflow) Abort

func (w *Workflow) Abort() error

Abort discards a pending operation (user cancelled via *_ABORT).

func (*Workflow) Apply

func (w *Workflow) Apply(ctx context.Context) (Result, error)

Apply executes a previously planned operation (user approved via *_APPLY).

func (*Workflow) PlanStatus

func (w *Workflow) PlanStatus() (string, error)

PlanStatus returns a human-readable summary of the current pending plan (if any).

func (*Workflow) RequiresConfirm

func (w *Workflow) RequiresConfirm(op string) bool

RequiresConfirm returns true if the operation needs user confirmation before executing.

func (*Workflow) Run

func (w *Workflow) Run(ctx context.Context, op, instruction string, explicitArgs map[string]string) (Result, error)

Run executes a workflow operation. If confirm is needed → saves plan + returns pending_approval. If no confirm → executes immediately and returns completed.

Jump to

Keyboard shortcuts

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