workflow

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitOK           = 0
	ExitUsage        = 2
	ExitNeedsInput   = 3
	ExitReviewNeeded = 4
	ExitAction       = 5
	ExitInFlight     = 6
	ExitExhausted    = 7

	ApprovalRequiredCode = "APPROVAL_REQUIRED"
	ApprovalConflictCode = "APPROVAL_CONFLICT"
	ApprovalStaleCode    = "APPROVAL_STALE"
	ApprovalArtifactCode = "APPROVAL_ARTIFACT"
	ApprovalRecoveryCode = "APPROVAL_RECOVERY_REQUIRED"
)
View Source
const (
	HumanConfirmationFlag   = "--human-confirmed"
	ApprovalRequiredMessage = "human approval is required before this workflow can advance; after the human explicitly replies, the host agent must rerun approval respond with " + HumanConfirmationFlag
)

MaxRounds is retained for embedders that used the old workflow package constant. New tasks resolve their limit from config and persist it in the task policy snapshot.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

func RuntimeSnapshot

func RuntimeSnapshot(provider string, p config.Provider) task.RuntimeSnapshot

RuntimeSnapshot converts validated provider configuration to durable, non-secret routing metadata. CLI discovery and workflow creation share this conversion so fresh, resume, and model-list calls use the same route.

Types

type ApprovalChoice added in v0.1.2

type ApprovalChoice struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

type CapabilityContext

type CapabilityContext struct {
	Note             string
	SkillDirectories []string
}

type Control added in v0.1.2

type Control struct {
	Status      string `json:"status"`
	ReviewKind  string `json:"review_kind,omitempty"`
	ReviewRound int    `json:"review_round"`
	MaxRounds   int    `json:"max_rounds"`
	CanReview   bool   `json:"can_review"`
	NextAction  string `json:"next_action"`
	// Keep the approval contract beside NextAction so even compact or
	// truncated host output retains the required confirmation flag.
	RequiresExplicitHumanConfirmation bool                       `json:"requires_explicit_human_confirmation,omitempty"`
	HumanConfirmationFlag             string                     `json:"human_confirmation_flag,omitempty"`
	ApprovalID                        string                     `json:"approval_id,omitempty"`
	ApprovalTaskID                    string                     `json:"approval_task_id,omitempty"`
	ApprovalKind                      string                     `json:"approval_kind,omitempty"`
	Question                          string                     `json:"question,omitempty"`
	Choices                           []ApprovalChoice           `json:"choices,omitempty"`
	ArtifactPath                      string                     `json:"artifact_path,omitempty"`
	Scope                             string                     `json:"scope,omitempty"`
	ChangedFiles                      []task.ApprovalChangedFile `json:"changed_files,omitempty"`
	Source                            string                     `json:"source,omitempty"`
	Events                            []task.WorkflowEvent       `json:"events,omitempty"`
	BudgetIssue                       *task.BudgetIssue          `json:"budget_issue,omitempty"`
	Progress                          *task.Progress             `json:"progress,omitempty"`
	ExternalReview                    *task.ExternalReview       `json:"external_review,omitempty"`
	ReviewOutdated                    bool                       `json:"review_outdated,omitempty"`
}

Control is the durable host-action view of a task. It intentionally carries only workflow coordination data; provider prompts, raw output, and detailed usage stay in task.State. Review findings appear only inside bounded events.

func ControlFor added in v0.1.2

func ControlFor(st task.State) Control

ControlFor derives the next safe host action from durable state. In-flight and question state are checked before completed review metadata so a stale outcome can never mask a live recovery action.

type ControlChoice added in v0.1.2

type ControlChoice = ApprovalChoice

type Error

type Error struct {
	Code      string
	Message   string
	Retryable bool
	TaskID    string
	ExitCode  int
	Cause     error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ExternalReviewHost added in v0.1.2

type ExternalReviewHost interface {
	Publish(context.Context, task.State, task.ApprovalRecord) (task.ExternalReview, error)
	FetchFeedback(context.Context, task.ExternalReview) (reviewhost.Feedback, error)
}

type Result

type Result struct {
	State  task.State
	Status string
}

type Service

type Service struct {
	RepoRoot string
	Store    *task.Store
	Config   config.Config
	Adapters map[string]runner.Adapter
	// ModelCachePath is explicit so library users and tests never inherit the
	// process owner's cache accidentally. An empty path disables caching.
	ModelCachePath string
	Capabilities   func(provider string, role runner.Role, taskText string) CapabilityContext
	Diagnostic     func(string)
	Observe        func(string) ([]task.FileEntry, error)
	Capture        func([]task.FileEntry, string, string) ([]task.FileEntry, error)
	WritePlan      func(string, string) error
	Now            func() time.Time
	Token          func() string
	ProcessID      func() int
	ProcessAlive   func(int) bool
	// ProgressHeartbeatInterval is configurable for deterministic tests. Zero
	// uses the production interval.
	ProgressHeartbeatInterval time.Duration
	ReviewHost                ExternalReviewHost
}

func New

func New(repoRoot string, cfg config.Config, adapters map[string]runner.Adapter) *Service

func (*Service) Adopt added in v0.1.2

func (s *Service) Adopt(id, note string) (Result, error)

Adopt records host-completed changes at an interrupted implementation boundary without fabricating a provider completion. Exact manifests and a required audit note make the handoff reviewable and fail closed.

func (*Service) AnswerImplement

func (s *Service) AnswerImplement(ctx context.Context, id, answer string) (Result, error)

func (*Service) AnswerPlan

func (s *Service) AnswerPlan(ctx context.Context, id, answer string) (Result, error)

func (*Service) Approval added in v0.1.2

func (s *Service) Approval(id string) (Control, error)

Approval returns the durable host-facing approval control. It is deliberately provider-free; legacy gates are materialized from saved reviewer evidence, and artifacts are repaired from the deterministic state projection.

func (*Service) Budget added in v0.1.2

func (s *Service) Budget(id string) (map[string]task.RoleBudget, error)

func (*Service) ExtendBudget added in v0.1.2

func (s *Service) ExtendBudget(id string, role string, turns, toolCalls, timeoutSeconds int, outputBytes int64) (Result, error)

ExtendBudget is an explicit host recovery action. It never starts a provider turn; the caller must issue retry after inspecting the saved state.

func (*Service) Graph

func (s *Service) Graph(id string) (WorkGraph, error)

Graph returns live scheduling state for a planner-produced DAG. It never starts workers; the host orchestrator remains responsible for concurrency.

func (*Service) Implement

func (s *Service) Implement(ctx context.Context, id, rawScope string) (Result, error)

func (*Service) List

func (s *Service) List() ([]task.State, error)

func (*Service) PublishApprovalReview added in v0.1.2

func (s *Service) PublishApprovalReview(ctx context.Context, id string) (Result, *task.ExternalReview, error)

PublishApprovalReview creates or updates the optional external human-review surface. The host performs all Git/GitHub work before the short gate CAS.

func (*Service) RespondApproval added in v0.1.2

func (s *Service) RespondApproval(ctx context.Context, id, gateID string, decisionValue any, feedback string) (Result, error)

RespondApproval applies one decision to exactly one pending gate. The decision is validated against the saved generation before the short state mutation; provider calls, when feedback is requested, happen only after the owned continuation has been persisted.

func (*Service) Retry

func (s *Service) Retry(ctx context.Context, id string) (Result, error)

func (*Service) ReviewCode

func (s *Service) ReviewCode(ctx context.Context, id string) (Result, error)

func (*Service) ReviewIntegration

func (s *Service) ReviewIntegration(ctx context.Context, parentID string) (Result, error)

ReviewIntegration performs the one-time deep review after every DAG node has passed its task-local review. Findings are handed to one fresh integration implementer session, while subsequent fix/review rounds resume the same integration implementer and reviewer sessions.

func (*Service) ReviewPlan

func (s *Service) ReviewPlan(ctx context.Context, id string) (Result, error)

func (*Service) StartPlan

func (s *Service) StartPlan(ctx context.Context, text, id string) (Result, error)

func (*Service) StartQuick added in v0.1.2

func (s *Service) StartQuick(text, rawScope, id string) (Result, error)

StartQuick creates a reviewed-code workflow without spending planner or plan-reviewer turns. The host orchestrator owns the execution packet for this deliberately small, exact-scope task.

func (*Service) StartWork

func (s *Service) StartWork(parentID, unitID string) (Result, error)

StartWork materializes one ready DAG node as an independently resumable task. Independent nodes therefore have independent provider sessions and task locks while sharing the same checkout.

func (*Service) Status

func (s *Service) Status(id string) (task.State, error)

func (*Service) SyncApprovalReview added in v0.1.2

func (s *Service) SyncApprovalReview(ctx context.Context, id string) (Result, error)

SyncApprovalReview imports new draft-PR comments as an explicit request_changes decision and resumes the normal same-session fix loop.

type WorkGraph

type WorkGraph struct {
	TaskID              string     `json:"task_id"`
	Phase               string     `json:"phase"`
	Complexity          string     `json:"complexity,omitempty"`
	Waves               [][]string `json:"waves"`
	Ready               []string   `json:"ready"`
	Nodes               []WorkNode `json:"nodes"`
	Control             Control    `json:"control"`
	CriticalPath        []string   `json:"critical_path,omitempty"`
	CriticalPathMinutes int        `json:"critical_path_minutes,omitempty"`
}

type WorkNode

type WorkNode struct {
	task.WorkUnit
	TaskID    string   `json:"task_id"`
	Status    string   `json:"status"`
	Ready     bool     `json:"ready"`
	BlockedBy []string `json:"blocked_by,omitempty"`
}

Jump to

Keyboard shortcuts

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