Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeDecomposition(b []byte) (goal.DecompositionContent, error)
- func Dispatch(ctx context.Context, h Handler, action string, args map[string]any) (any, error)
- func InputSchema() map[string]any
- func ResolveInputs(specs []InputSpec, provided map[string]string) (map[string]string, error)
- func ValidatePlaceholders(specs []InputSpec, texts ...string) error
- func ValidateSpecs(specs []InputSpec) error
- type Access
- func (a *Access) Delete(ctx context.Context, id string) error
- func (a *Access) Get(ctx context.Context, id string) (Workflow, error)
- func (a *Access) Instantiate(ctx context.Context, id string, inputs map[string]string, ...) (Run, bool, error)
- func (a *Access) List(ctx context.Context, agentFilter string) ([]Workflow, error)
- func (a *Access) ListRuns(ctx context.Context, id string, limit, offset int) ([]RunListItem, int64, error)
- func (a *Access) SaveGoalAsWorkflow(ctx context.Context, in SaveInput) (Workflow, error)
- type FrozenNode
- type FrozenPlan
- type GetInput
- type GoalWriter
- type Handler
- type InputSpec
- type InstantiateInput
- type ListInput
- type Run
- type RunInput
- type RunListItem
- type RunState
- type SaveInput
- type ScheduledWorkflow
- type Service
- func (s *Service) Authorize(ctx context.Context, authority authz.Authority, workflowID string, ...) error
- func (s *Service) Begin(_ context.Context, authority authz.Authority) (*Access, error)
- func (s *Service) InstantiateAs(ctx context.Context, authority authz.Authority, id string, ...) (Run, bool, error)
- func (s *Service) LatestRunState(ctx context.Context, workflowID string) (RunState, error)
- func (s *Service) ValidateScheduledWorkflow(ctx context.Context, userID, agentID, workflowID string) (ScheduledWorkflow, error)
- type Tool
- type ToolSaveInput
- type Workflow
Constants ¶
const ( OwnerUser = "user" OwnerAgent = "agent" RunClaimed = "claimed" RunMaterializing = "materializing" RunDone = "done" RunFailed = "failed" )
const InputSchemaJSON = `` /* 2691-byte string literal not displayed */
const PayloadFormatFrozenV0 = "frozen/v0"
const ToolName = "workflow"
Variables ¶
var ( ErrForbidden = errors.New("workflow access forbidden") ErrNotFound = errors.New("workflow not found") ErrInvalidPage = errors.New("workflow pagination is outside the supported range") )
Errors returned by the Workflow access boundary. Denials are opaque (ErrNotFound) so a foreign or revoked workflow cannot be distinguished from a missing one, preserving the pre-cutover 404 contract.
var ( ErrRunAlreadyFailed = errors.New("workflow run already failed") ErrWorkflowHasRuns = errors.New("workflow has runs") ErrWorkflowHasSchedulerJob = errors.New("workflow has enabled scheduler jobs") ErrWorkflowVersionConflict = errors.New("workflow version conflict; retry") // ErrInvalidWorkflowInput marks input errors the caller can fix (bad spec // name, unknown or missing input, unresolved placeholder) -- mapped to 400. ErrInvalidWorkflowInput = errors.New("invalid workflow input") )
Functions ¶
func DecodeDecomposition ¶
func DecodeDecomposition(b []byte) (goal.DecompositionContent, error)
func InputSchema ¶
func ResolveInputs ¶
func ValidatePlaceholders ¶
ValidatePlaceholders checks every {{inputs.name}} referenced by the given texts against the declared specs, so a typo or an undeclared input fails at save time instead of on every run.
func ValidateSpecs ¶
ValidateSpecs rejects at save time input specs that could never resolve: a name outside the placeholder charset is unreferencable by {{inputs.name}}, so the workflow would fail on every instantiation.
Types ¶
type Access ¶
type Access struct {
// contains filtered or unexported fields
}
Access captures one validated authority for a Workflow use case. Workflow owns the direct rules; transports pass a trusted Authority, never a scoped query.
func (*Access) Delete ¶
Delete authorizes deleting a workflow, then removes it (blocked when runs or enabled scheduler jobs reference it — those domain errors surface unchanged).
func (*Access) Instantiate ¶
func (a *Access) Instantiate(ctx context.Context, id string, inputs map[string]string, idempotencyKey string) (Run, bool, error)
Instantiate claims a run and materializes the workflow's goal tree. It checks both the loaded durable workflow and its persisted target agent before claim or materialization; neither request fields nor a stale route can widen access.
func (*Access) List ¶
List lists the caller's workflows and filters every durable row through the same direct read rule. A user actor may narrow the query to one agent; a delegated agent is always confined to its own bound agent regardless of the filter. The query remains owner-scoped even for admins by established contract.
func (*Access) ListRuns ¶
func (a *Access) ListRuns(ctx context.Context, id string, limit, offset int) ([]RunListItem, int64, error)
ListRuns authorizes reading a workflow, then returns its run page.
func (*Access) SaveGoalAsWorkflow ¶
SaveGoalAsWorkflow freezes an accepted goal tree into a workflow. The source Goal owns its read decision; its persisted agent determines the workflow's target, and Agent owns the target execute decision.
type FrozenNode ¶
type FrozenNode struct {
Child goal.ProposedChild `json:"child"`
Plan *FrozenPlan `json:"plan,omitempty"`
}
type FrozenPlan ¶
type FrozenPlan struct {
Children []FrozenNode `json:"children"`
Edges []goal.ProposedEdge `json:"edges"`
}
func DecodeFrozenPlan ¶
func DecodeFrozenPlan(b []byte) (FrozenPlan, error)
func SubstituteInputs ¶
func SubstituteInputs(plan FrozenPlan, inputs map[string]string) (FrozenPlan, error)
func (FrozenPlan) FullyFrozen ¶
func (p FrozenPlan) FullyFrozen() bool
func (FrozenPlan) Hash ¶
func (p FrozenPlan) Hash() string
func (FrozenPlan) Validate ¶
func (p FrozenPlan) Validate() error
func (FrozenPlan) ValidateMaxDepth ¶
func (p FrozenPlan) ValidateMaxDepth(maxDepth int) error
type GoalWriter ¶
type GoalWriter interface {
CreateRoot(ctx context.Context, in goal.CreateInput) (goal.CreatedGoal, error)
MaterializeFrozenLayer(ctx context.Context, parentID string, content goal.DecompositionContent, frozen goal.FrozenStamp) error
ActivateFrozenComposite(ctx context.Context, id string) error
Authorize(ctx context.Context, authority authz.Authority, goalID string, action authz.Action) (goal.AuthorizedGoal, error)
}
GoalWriter is the workflow domain's narrow port into Goal: frozen-tree writes plus Goal's direct source-read authorization. The port is consumer-owned here so no goal→workflow cycle forms; Goal exposes a narrow adapter that satisfies it.
type InstantiateInput ¶
type Run ¶
type Run struct {
ID string
WorkflowID string
WorkflowVersion int32
IdempotencyKey string
RootGoalID *string
Status string
Inputs map[string]string
PlanHash string
CreatedAt time.Time
UpdatedAt time.Time
}
Run is one instantiation of a workflow.
type RunListItem ¶
type RunListItem struct {
Run
RootLifecycle *string
RootBlockReason *string
RootDoneReason *string
}
RunListItem is a run row for the list view, joined with its root goal's outcome fields (a claimed run with no root goal yet leaves them nil).
type RunState ¶
type RunState struct {
Found bool
Status string
IdempotencyKey string
RootGoalID string
RootGoalTerminal bool
}
RunState is the latest-run snapshot the scheduler adapter needs to decide whether a workflow run is in flight or has reached a terminal root goal.
type ScheduledWorkflow ¶
ScheduledWorkflow is the narrow immutable workflow fact the scheduler needs while validating a job. The scheduler has already established the durable owner and agent values it supplies to this worker-adapter port.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func New ¶
func New(db *pgxpool.Pool, goalSvc GoalWriter, agents *agentaccess.Service) *Service
New constructs the Workflow application service. Goal and Agent are the domain-owned ports used by the Authority-based Access boundary.
func (*Service) Authorize ¶
func (s *Service) Authorize(ctx context.Context, authority authz.Authority, workflowID string, action authz.Action) error
Authorize is Workflow's narrow direct port for another domain. It loads the durable row before applying the same fixed rules as Access; ownership and executor facts cannot be supplied by the caller. A missing or denied workflow is opaque to the caller through authz.ErrNotFound.
func (*Service) InstantiateAs ¶
func (s *Service) InstantiateAs(ctx context.Context, authority authz.Authority, id string, inputs map[string]string, idempotencyKey string) (Run, bool, error)
InstantiateAs authorizes and instantiates a workflow under authority. It is the narrow cross-domain entry point used by scheduler dispatch; request fields never establish ownership or the executor.
func (*Service) LatestRunState ¶
LatestRunState returns the state of the most recent run for a workflow. Found is false when the workflow has no runs yet.
func (*Service) ValidateScheduledWorkflow ¶
func (s *Service) ValidateScheduledWorkflow(ctx context.Context, userID, agentID, workflowID string) (ScheduledWorkflow, error)
ValidateScheduledWorkflow returns only the durable workflow facts needed to validate a scheduler-owned workflow job.
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
func (*Tool) Definition ¶
func (t *Tool) Definition() tools.Definition
type ToolSaveInput ¶
type Workflow ¶
type Workflow struct {
ID string
OwnerKind string
UserID *string
AgentID *string
Name string
Version int32
Intent string
AcceptanceContract json.RawMessage
ConvergencePolicy json.RawMessage
Inputs []InputSpec
PayloadFormat string
Payload json.RawMessage
FullyFrozen bool
SourceGoalID *string
CreatedAt time.Time
UpdatedAt time.Time
}
Workflow is the frozen definition of a reusable goal template.