executor

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: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedactedCommandEnvValue     = redactedCommandEnvValue
	MetadataOnlyCommandEnvValue = metadataOnlyCommandEnvValue
)
View Source
const (
	WorkLogEventWorkerPoolSubmitted         = "worker_pool.submitted"
	WorkLogEventWorkerPoolExecutorEntered   = "worker_pool.executor_entered"
	WorkLogEventWorkerPoolResponseSubmitted = "worker_pool.response_submitted"
	WorkLogEventCommandRunnerRequested      = "command_runner.requested"
	WorkLogEventCommandRunnerCompleted      = "command_runner.completed"
	WorkLogEventCommandRunnerRequestDetails = "command_runner.request_details"
	WorkLogEventCommandRunnerOutputDetails  = "command_runner.output_details"
)

Variables

This section is empty.

Functions

func CommandRequestInputTokens

func CommandRequestInputTokens(request CommandRequest) []interfaces.Token

func InputTokens

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

func PanicAsFailedResult

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

func ResolveModelOperationBindings

func ResolveModelOperationBindings(
	workstationDef *interfaces.FactoryWorkstationConfig,
	workerDef *interfaces.WorkerConfig,
	inputTokens []interfaces.Token,
) ([]interfaces.ResolvedModelOperationBinding, error)

ResolveModelOperationBindings resolves one MODEL_INVOKE-style slot binding set against ordered runtime input content using the same rules as workstation execution.

func WorkDispatchInputTokens

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

func WorkLogFields

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

WorkLogFields returns stable structured log fields for work-scoped runtime records. Empty strings are intentional so unavailable IDs remain explicit.

Types

type AgentContext

type AgentContext struct {
	SystemPrompt string `json:"system_prompt"` // worker AGENTS.md body
	UserMessage  string `json:"user_message"`  // rendered workstation prompt
	Tools        []Tool `json:"tools,omitempty"`
	OutputSchema []byte `json:"output_schema,omitempty"`
}

AgentContext is the merged execution context assembled from worker AGENTS.md + workstation AGENTS.md at execution time.

type AgentExecutor

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

AgentExecutor implements WorkstationRequestExecutor for MODEL_WORKER types. It reads prompt/output inputs resolved by WorkstationExecutor, calls the configured Provider for inference, and maps the response to a WorkResult.

func NewAgentExecutor

func NewAgentExecutor(runtimeConfig interfaces.RuntimeDefinitionLookup, provider Provider, opts ...AgentExecutorOption) *AgentExecutor

NewAgentExecutor creates an AgentExecutor from runtime-loaded config and a Provider.

func NewAgentExecutorWithRunner

func NewAgentExecutorWithRunner(runtimeConfig interfaces.RuntimeDefinitionLookup, runner Runner, opts ...AgentExecutorOption) *AgentExecutor

NewAgentExecutorWithRunner creates an AgentExecutor from runtime-loaded config and the shared runner execution contract.

func (*AgentExecutor) Execute

Execute calls the Provider with one rendered workstation request, parses the response against OutputSchema if present, and returns a WorkResult.

type AgentExecutorOption

type AgentExecutorOption func(*AgentExecutor)

AgentExecutorOption configures an AgentExecutor.

func WithLogger

func WithLogger(logger logging.Logger) AgentExecutorOption

type CommandRequest

type CommandRequest = workerprocess.CommandRequest

type CommandResult

type CommandResult = workerprocess.CommandResult

type CommandRunner

type CommandRunner = workerprocess.CommandRunner

type ExecCommandRunner

type ExecCommandRunner = workerprocess.ExecCommandRunner

type LoggingCommandRunner

type LoggingCommandRunner = workerprocess.LoggingCommandRunner

type NoopExecutor

type NoopExecutor struct{}

NoopExecutor is a WorkerExecutor that always returns OutcomeAccepted without calling any LLM or script. It is used as a fallback when no AGENTS.md is configured for a worker, allowing tests to exercise the petri-net topology without providing real worker configuration.

func (*NoopExecutor) Execute

Execute implements WorkerExecutor. It propagates the first input token's color and returns OutcomeAccepted immediately.

type OutputParser

type OutputParser interface {
	ParseJSON(response string, schema []byte) ([]interfaces.TokenColor, error)
}

OutputParser parses structured output from a worker execution response.

type Provider

type Provider = workerprovider.Provider

type ProviderError

type ProviderError = workerprovider.ProviderError

type Runner

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

Runner executes one normalized runner request.

func RunnerFromProvider

func RunnerFromProvider(provider Provider) Runner

RunnerFromProvider adapts a legacy provider implementation onto the shared runner execution contract.

type ScriptEventRecorder

type ScriptEventRecorder func(factoryapi.FactoryEvent)

ScriptEventRecorder receives generated script-boundary events.

type ScriptExecutor

type ScriptExecutor struct {
	Command       string
	Args          []string
	FactoryDir    string
	CommandRunner CommandRunner
	Logger        logging.Logger
	// contains filtered or unexported fields
}

ScriptExecutor implements WorkstationRequestExecutor by running shell commands via os/exec. It supports template substitution in args using the PromptData model (e.g., {{ (index .Inputs 0).Name }}, {{ (index .Inputs 0).WorkID }}, {{ index (index .Inputs 0).Tags "key" }}, {{ .Context.WorkDir }}) and merges dispatch env vars into the process environment. TODO: consider names for various things.

func NewScriptExecutor

func NewScriptExecutor(def *interfaces.WorkerConfig, logger logging.Logger, opts ...ScriptExecutorOption) *ScriptExecutor

NewScriptExecutor creates a ScriptExecutor from a WorkerConfig.

func NewScriptExecutorWithRunner

func NewScriptExecutorWithRunner(def *interfaces.WorkerConfig, runner CommandRunner, logger logging.Logger, opts ...ScriptExecutorOption) *ScriptExecutor

NewScriptExecutorWithRunner creates a ScriptExecutor with a custom CommandRunner.

func (*ScriptExecutor) Execute

Execute runs the configured command with template-substituted args. Exit code 0 produces ACCEPTED with stdout in Output. Non-zero exit code produces FAILED with stderr as Error.

type ScriptExecutorOption

type ScriptExecutorOption func(*ScriptExecutor)

ScriptExecutorOption configures a ScriptExecutor.

func WithScriptClock

func WithScriptClock(now func() time.Time) ScriptExecutorOption

WithScriptClock sets the clock used for script event occurrence times and subprocess duration measurement.

func WithScriptEventRecorder

func WithScriptEventRecorder(recorder ScriptEventRecorder) ScriptExecutorOption

WithScriptEventRecorder records script-boundary events on the canonical event history owned by the runtime.

func WithScriptFactoryDir

func WithScriptFactoryDir(factoryDir string) ScriptExecutorOption

WithScriptFactoryDir resolves portable factory/scripts/... references against the active factory directory before subprocess execution.

type Tool

type Tool struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Tool describes a tool available to the agent during execution.

type WorkerExecutor

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

WorkerExecutor is the side-effect interface for one dispatched worker step.

type WorkerPool

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

WorkerPool manages WorkerRunners by worker type, providing a shared resultCh that the engine selects on to wake when workers complete.

func NewWorkerPool

func NewWorkerPool(logger logging.Logger) *WorkerPool

NewWorkerPool creates a WorkerPool with a shared result channel.

func (*WorkerPool) Dispatch

func (p *WorkerPool) Dispatch(workerType string, dispatch interfaces.WorkDispatch) bool

Dispatch sends a WorkDispatch to the appropriate runner's dispatch channel. Returns false if no runner is registered for the dispatch's worker type.

func (*WorkerPool) Register

func (p *WorkerPool) Register(workerType string, executor WorkerExecutor)

Register adds a WorkerRunner for the given worker type. If a runner already exists for this type, it is replaced (the old runner is not stopped).

func (*WorkerPool) ResultCh

func (p *WorkerPool) ResultCh() <-chan interfaces.WorkResult

ResultCh returns the shared result channel that the engine should select on.

func (*WorkerPool) Start

func (p *WorkerPool) Start()

Start launches all registered runners. Each runner starts its goroutine to process dispatches.

func (*WorkerPool) Stop

func (p *WorkerPool) Stop()

Stop signals all runners to shut down by closing their dispatch channels.

type WorkerRunner

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

WorkerRunner is an active goroutine that processes work for a specific worker type. It reads WorkDispatches from its dispatchCh, calls WorkerExecutor.Execute, and sends the WorkResult to the shared resultCh.

func NewWorkerRunner

func NewWorkerRunner(workerType string, executor WorkerExecutor, resultCh chan<- interfaces.WorkResult, logger logging.Logger) *WorkerRunner

NewWorkerRunner creates a runner for the given worker type. The runner reads dispatches from its own channel and sends results to the shared resultCh.

func (*WorkerRunner) Start

func (r *WorkerRunner) Start()

Start launches the runner's goroutine. It processes dispatches until the dispatch channel is closed.

func (*WorkerRunner) Stop

func (r *WorkerRunner) Stop()

Stop closes the dispatch channel, signaling the runner goroutine to exit.

type WorkstationExecutor

type WorkstationExecutor struct {
	RuntimeConfig   interfaces.RuntimeConfigLookup
	DefaultRunnerID string
	Executor        WorkstationRequestExecutor
	Renderer        workerprompting.PromptRenderer
	Parser          OutputParser
	Logger          logging.Logger        // optional; nil → noop
	GitCommander    worktree.GitCommander // optional; nil → ExecGitCommander
}

WorkstationExecutor wraps a WorkerExecutor with workstation-specific prompt rendering. This is what the Dispatcher actually calls.

For MODEL_WORKSTATION: render prompt → call executor → parse output → WorkResult For LOGICAL_MOVE: pass-through input colors → WorkResult (no worker call)

func (*WorkstationExecutor) Execute

Execute implements WorkerExecutor for WorkstationExecutor.

type WorkstationRequestExecutor

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

WorkstationRequestExecutor handles worker-owned execution after workstation prompt and runtime context resolution.

Jump to

Keyboard shortcuts

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