workers

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package workers defines worker executor interfaces and implementations for script and model-based workers.

Index

Constants

View Source
const (
	// RedactedCommandEnvValue is written when an environment key looks sensitive.
	RedactedCommandEnvValue = "<redacted>"
	// MetadataOnlyCommandEnvValue is written when only the key's presence is safe to preserve.
	MetadataOnlyCommandEnvValue = "<metadata-only>"
)
View Source
const (
	WorkLogEventWorkerPoolSubmitted         = workerexecutor.WorkLogEventWorkerPoolSubmitted
	WorkLogEventWorkerPoolExecutorEntered   = workerexecutor.WorkLogEventWorkerPoolExecutorEntered
	WorkLogEventWorkerPoolResponseSubmitted = workerexecutor.WorkLogEventWorkerPoolResponseSubmitted
	WorkLogEventCommandRunnerRequested      = workerexecutor.WorkLogEventCommandRunnerRequested
	WorkLogEventCommandRunnerCompleted      = workerexecutor.WorkLogEventCommandRunnerCompleted
	WorkLogEventCommandRunnerRequestDetails = workerexecutor.WorkLogEventCommandRunnerRequestDetails
	WorkLogEventCommandRunnerOutputDetails  = workerexecutor.WorkLogEventCommandRunnerOutputDetails
)
View Source
const (
	PromptTemplateDiagnosticKindSyntaxError         = workerprompting.PromptTemplateDiagnosticKindSyntaxError
	PromptTemplateDiagnosticKindInvalidVariable     = workerprompting.PromptTemplateDiagnosticKindInvalidVariable
	PromptTemplateDiagnosticKindUnavailableVariable = workerprompting.PromptTemplateDiagnosticKindUnavailableVariable
)

Variables

This section is empty.

Functions

func InputTokens

func InputTokens(tokens ...interfaces.Token) []any

InputTokens converts typed petri tokens into the shared dispatch representation.

func PanicAsFailedResult

func PanicAsFailedResult(dispatch interfaces.WorkDispatch, recovered any, duration time.Duration) interfaces.WorkResult

func ValidateBuiltInRunnerPrerequisites added in v0.0.5

func ValidateBuiltInRunnerPrerequisites(id string) error

ValidateBuiltInRunnerPrerequisites checks PATH-visible prerequisites for one built-in runner before the runtime attempts dispatch.

func WorkDispatchInputTokens

func WorkDispatchInputTokens(dispatch interfaces.WorkDispatch) []interfaces.Token

WorkDispatchInputTokens returns the token payload as typed petri tokens.

func WorkLogFields

func WorkLogFields(metadata interfaces.ExecutionMetadata, keysAndValues ...any) []any

Types

type AgentContext

type AgentContext = workerexecutor.AgentContext

type AgentExecutor

type AgentExecutor = workerexecutor.AgentExecutor

type AgentExecutorOption

type AgentExecutorOption = workerexecutor.AgentExecutorOption

type CommandEnvClassification

type CommandEnvClassification string

CommandEnvClassification describes how a command environment entry may be represented in persisted diagnostics.

const (
	CommandEnvClassificationSafe         CommandEnvClassification = "safe"
	CommandEnvClassificationRedacted     CommandEnvClassification = "redacted"
	CommandEnvClassificationMetadataOnly CommandEnvClassification = "metadata_only"
)

func ClassifyCommandEnvKey

func ClassifyCommandEnvKey(name string) CommandEnvClassification

ClassifyCommandEnvKey returns the diagnostic exposure class for one command environment key. Sensitive-looking names are always redacted, even when they also appear in the safe allowlist.

type CommandEnvDiagnosticProjection

type CommandEnvDiagnosticProjection struct {
	Count  int               `json:"count"`
	Keys   []string          `json:"keys,omitempty"`
	Values map[string]string `json:"values,omitempty"`
}

CommandEnvDiagnosticProjection is the safe diagnostic view of a subprocess environment. Values contains only allowlisted raw values or explicit markers.

func ProjectCommandEnvForDiagnostics

func ProjectCommandEnvForDiagnostics(env []string) CommandEnvDiagnosticProjection

ProjectCommandEnvForDiagnostics converts subprocess environment entries into the shared safe diagnostic representation used before replay persistence.

type CommandRequest

type CommandRequest = workerprocess.CommandRequest

type CommandResult

type CommandResult = workerprocess.CommandResult

type CommandRunner

type CommandRunner = workerprocess.CommandRunner

type CronWorkstationType

type CronWorkstationType struct{}

CronWorkstationType identifies service-triggered cron workstations. Cron ticks submit through the service ingress; once dispatched, results advance through the normal arc sets.

func (*CronWorkstationType) HandleResult

HandleResult routes cron execution results through normal arc handling.

func (*CronWorkstationType) Kind

Kind returns WorkstationKindCron.

type Dispatcher

type Dispatcher interface {
	// Dispatch executes a work dispatch synchronously, blocking until the
	// result is available.
	Dispatch(ctx context.Context, dispatch *interfaces.WorkDispatch) (interfaces.WorkResult, error)
	// WorkerState returns a point-in-time snapshot of the dispatcher state.
	WorkerState() interfaces.WorkerState
	// Tick processes all currently queued dispatches synchronously, blocking
	// until each submitted element completes.
	Tick()
	// Run starts the goroutine-based async dispatch loop (existing behaviour).
	Run()
}

Dispatcher manages worker execution. It supports two execution modes:

  • Synchronous (via Tick): all queued dispatches are executed inline; used by test harnesses to control execution step-by-step.
  • Asynchronous (via Run): dispatches are executed in goroutines; used in production.

type ExecCommandRunner

type ExecCommandRunner = workerprocess.ExecCommandRunner

type InferenceEventRecorder

type InferenceEventRecorder = workerprovider.InferenceEventRecorder

type LoggingCommandRunner

type LoggingCommandRunner = workerprocess.LoggingCommandRunner

type MockWorkerCommandRunner

type MockWorkerCommandRunner = mockworker.MockWorkerCommandRunner

type NoopExecutor

type NoopExecutor = workerexecutor.NoopExecutor

type OutputParser

type OutputParser = workerexecutor.OutputParser

type PollerWorkstationType added in v0.0.5

type PollerWorkstationType struct{}

PollerWorkstationType identifies service-supervised ingress pollers. Until poller-specific lifecycle orchestration runs, completed dispatches still route through the normal arc handling.

func (*PollerWorkstationType) HandleResult added in v0.0.5

HandleResult routes poller execution results through normal arc handling.

func (*PollerWorkstationType) Kind added in v0.0.5

Kind returns WorkstationKindPoller.

type PostResultAction

type PostResultAction string

PostResultAction determines what the engine should do after processing a work result.

const (
	// ActionAdvance routes tokens normally via the appropriate arc set (output/rejection/failure).
	// This is the behavior of the "standard" workstation type.
	ActionAdvance PostResultAction = "advance"
	// ActionRepeat keeps the token in its input place and re-fires the transition
	// on the next tick. Used by the "repeater" workstation type.
	ActionRepeat PostResultAction = "repeat"
)

type PromptContext

type PromptContext = workerprompting.PromptContext

type PromptData

type PromptData = workerprompting.PromptData

type PromptHistory

type PromptHistory = workerprompting.PromptHistory

type PromptRenderer

type PromptRenderer = workerprompting.PromptRenderer

type PromptTemplateContract added in v0.0.5

type PromptTemplateContract = workerprompting.PromptTemplateContract

type PromptTemplateDiagnostic added in v0.0.5

type PromptTemplateDiagnostic = workerprompting.PromptTemplateDiagnostic

type PromptTemplateDiagnosticKind added in v0.0.5

type PromptTemplateDiagnosticKind = workerprompting.PromptTemplateDiagnosticKind

type PromptTemplateUnavailableAccessPattern added in v0.0.5

type PromptTemplateUnavailableAccessPattern = workerprompting.PromptTemplateUnavailableAccessPattern

type PromptTemplateValidationResult added in v0.0.5

type PromptTemplateValidationResult = workerprompting.PromptTemplateValidationResult

type PromptTemplateVariableCategory added in v0.0.5

type PromptTemplateVariableCategory = workerprompting.PromptTemplateVariableCategory

type PromptTemplateVariableReference added in v0.0.5

type PromptTemplateVariableReference = workerprompting.PromptTemplateVariableReference

type Provider

type Provider = workerprovider.Provider

type ProviderError

type ProviderError = workerprovider.ProviderError

func NewProviderError

func NewProviderError(errorType interfaces.ProviderErrorType, message string, cause error) *ProviderError

func NewProviderErrorWithSession

func NewProviderErrorWithSession(errorType interfaces.ProviderErrorType, message string, cause error, session *interfaces.ProviderSessionMetadata) *ProviderError

type ProviderErrorCorpus

type ProviderErrorCorpus = workerprovider.ProviderErrorCorpus

type RecordingProvider

type RecordingProvider = workerprovider.RecordingProvider

type RepeaterWorkstationType

type RepeaterWorkstationType struct{}

RepeaterWorkstationType re-fires a transition after a non-terminal result. CONTINUE outcomes keep the token in its input place (ActionRepeat) so the worker is invoked again on the next tick. ACCEPTED, REJECTED, and FAILED outcomes advance normally via the appropriate arc set.

func (*RepeaterWorkstationType) HandleResult

HandleResult returns ActionRepeat for CONTINUE outcomes (the worker signals "not done yet") and ActionAdvance for ACCEPTED, REJECTED, or FAILED.

func (*RepeaterWorkstationType) Kind

Kind returns WorkstationKindRepeater.

type ResolvedFields

type ResolvedFields = workerprompting.ResolvedFields

func ResolveTemplateFields

func ResolveTemplateFields(
	workingDirTemplate string,
	envTemplates map[string]string,
	tokens []interfaces.Token,
	wfCtx *factory_context.FactoryContext,
	worktreeTemplate string,
) (*ResolvedFields, error)

type Runner added in v0.0.5

type Runner interface {
	Execute(ctx context.Context, request interfaces.RunnerExecutionRequest) (interfaces.RunnerExecutionResult, error)
}

Runner executes one shared runner request and returns the normalized runner result used by standard orchestration flows.

func RunnerFromProvider added in v0.0.5

func RunnerFromProvider(provider Provider) Runner

type RunnerStatus added in v0.0.5

type RunnerStatus struct {
	Metadata          interfaces.RunnerMetadata
	Available         bool
	UnavailableReason string
}

RunnerStatus reports whether a built-in runner can be selected safely in the current build before dispatch starts.

func BuiltInRunnerStatus added in v0.0.5

func BuiltInRunnerStatus(id string) (RunnerStatus, bool)

BuiltInRunnerStatus reports the build-local availability of one stable runner registration.

type ScriptEventRecorder

type ScriptEventRecorder = workerexecutor.ScriptEventRecorder

type ScriptExecutor

type ScriptExecutor = workerexecutor.ScriptExecutor

type ScriptExecutorOption

type ScriptExecutorOption = workerexecutor.ScriptExecutorOption

type ScriptWrapProvider

type ScriptWrapProvider = workerprovider.ScriptWrapProvider

type StandardWorkstationType

type StandardWorkstationType struct{}

StandardWorkstationType implements the default fire-once behavior. Tokens are always routed via the appropriate arc set regardless of outcome.

func (*StandardWorkstationType) HandleResult

HandleResult always returns ActionAdvance — standard workstations route every result.

func (*StandardWorkstationType) Kind

Kind returns WorkstationKindStandard.

type TokenData

type TokenData = workerprompting.TokenData

type Tool

type Tool = workerexecutor.Tool

type WorkerExecutor

type WorkerExecutor interface {
	Execute(ctx context.Context, dispatch interfaces.WorkDispatch) (interfaces.WorkResult, error)
}

WorkerExecutor is the side-effect interface — what actually happens when a transition fires. This is the only place where external I/O occurs. Everything else in the factory is pure CPN state manipulation.

type WorkerPool

type WorkerPool = workerexecutor.WorkerPool

func NewWorkerPool

func NewWorkerPool(logger logging.Logger) *WorkerPool

type WorkerRunner

type WorkerRunner = workerexecutor.WorkerRunner

type WorkstationExecutor

type WorkstationExecutor = workerexecutor.WorkstationExecutor

type WorkstationRequestExecutor

type WorkstationRequestExecutor interface {
	Execute(ctx context.Context, request interfaces.WorkstationExecutionRequest) (interfaces.WorkResult, error)
}

WorkstationRequestExecutor handles worker-owned execution requests after the dispatch-owned contract has been resolved for one workstation invocation.

type WorkstationTypeRegistry

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

WorkstationTypeRegistry maps workstation kinds to their strategy implementations. The registry is pre-populated with the "standard" type and can be extended with additional types via Register.

func NewWorkstationTypeRegistry

func NewWorkstationTypeRegistry() *WorkstationTypeRegistry

NewWorkstationTypeRegistry creates a registry pre-populated with the "standard" "repeater", "cron", and "poller" types.

func (*WorkstationTypeRegistry) Get

Get returns the strategy for the given kind, or (nil, false) if not registered.

func (*WorkstationTypeRegistry) IsValid

IsValid returns true if the given kind is registered.

func (*WorkstationTypeRegistry) Kinds

Kinds returns all registered workstation kind names.

func (*WorkstationTypeRegistry) Register

Register adds a workstation type strategy to the registry.

type WorkstationTypeStrategy

type WorkstationTypeStrategy interface {
	// Kind returns the workstation kind this strategy handles.
	Kind() interfaces.WorkstationKind

	// HandleResult examines a work result and returns the action the engine
	// should take. For "standard" workstations this always returns ActionAdvance.
	HandleResult(result interfaces.WorkResult) PostResultAction
}

WorkstationTypeStrategy defines the execution semantics for a workstation type. Implementations determine how results are routed after a worker completes.

Adding a new workstation type requires:

  1. Implementing this interface
  2. Registering the implementation with NewWorkstationTypeRegistry or Registry.Register

No engine internals need to be modified.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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