Files
archie/internal/infrastructure/workflowsteps/workflowsteps.go
T
sam 56f7295a3c feat(workflow): own the step vocabulary in a family manager registered at each composition root
archie-core-fwmp. Every call site hardcoded workflow.BuiltinStepRegistry(), so
the step vocabulary a workflow definition may name was closed to the six shipped
workflows and archie-agent could compile only what the control plane happened to
validate against the same literal.

internal/domain/workflow.Manager is the family owner (ARCHITECTURE.md#plugin-
engine-rule-strict invariant 2): a constructed, injected value with no
package-level registry and no init()-time registration. Register validates at
the producer and atomically -- nil or unnamed provider, malformed provider or
step-type identifier, a step type with no factory, a duplicate claim, a provider
declaring one type twice, and a contribution shadowing a shipped stage are each
refused, and a refused contribution applies nothing. Registry() hands back a
copy, so the closed set is a property of the manager rather than a convention.

internal/infrastructure/workflowsteps is the one package both composition roots
import: it holds the compiled-in provider set and builds the manager. archied
registers it in RunStateStore (the validating side) and in openStateStoreAdapter
(the daemon's client), archie-agent in productionWorkerDependencies (the
executing side), and archie-messaging at its own root, each before the first
resolution.

The five hardcoded sites now resolve the injected manager instead: the State
Store's workflow-definitions validate closure and encodeWorkflowDefinitions, the
control-plane client's read and write paths, and CompilePinnedWorkflow's shipped
-definition and pinned compiles (one resolution per package).

step_vocabulary_agreement_test.go registers a provider through the production
Manager and drives all three sides with it; breaking any one of the six
resolution points back to the builtin registry fails that side's assertion.
2026-09-21 19:42:24 +10:00

62 lines
2.6 KiB
Go

// Package workflowsteps is the compiled-in workflow step-type provider set:
// the one place a step type is bundled into every Archie binary.
//
// Both composition roots import it — internal/app/archied (which serves the
// State Store's validating side) and internal/app/agentworker (the executing
// side) — so the two sides register the same vocabulary by construction rather
// than by convention. Neither root keeps a package-level registry of its own.
package workflowsteps
import (
"fmt"
"maps"
"slices"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// shippedStages is the provider that contributes every stage of the shipped
// workflows (bootstrap, implement, tdd, feasibility, triage, remediate) as a
// workflow step type. It is what makes the shipped vocabulary arrive by
// registration rather than by the manager implying it, so the vocabulary a
// process resolves is always the vocabulary a provider set claimed.
type shippedStages struct{}
func (shippedStages) Name() string { return "shipped" }
func (shippedStages) StepTypes() []workflow.StepType {
registry := workflow.BuiltinStepRegistry()
stepTypes := make([]workflow.StepType, 0, len(registry))
for _, name := range slices.Sorted(maps.Keys(registry)) {
stepTypes = append(stepTypes, workflow.StepType{Name: name, Factory: registry[name]})
}
return stepTypes
}
// Providers returns the provider set every Archie process registers at its
// composition root, before the first resolution. A step type added here becomes
// reachable from the validating side and the executing side at once.
//
// The set is a compiled-in constant rather than a directory scan: a step type
// is a Go factory, and the Yaegi-interpreted plugins internal/plugin loads
// satisfy plugin.Plugin's metadata contract but cannot hand the host a working
// workflow.StepFactory. archie-agent links its own binary in any case.
func Providers() []workflow.StepTypeProvider {
return []workflow.StepTypeProvider{shippedStages{}}
}
// NewManager builds this process's workflow step-type manager by registering
// the provider set. Every call constructs an independent manager: there is no
// package-level registry and nothing registers at init(), so building the
// vocabulary twice in one process — as `-count=2` does — cannot collide with
// the first build.
func NewManager() (*workflow.Manager, error) {
manager := workflow.NewManager()
for _, provider := range Providers() {
if err := manager.Register(provider); err != nil {
return nil, fmt.Errorf("register workflow step type provider %q: %w", provider.Name(), err)
}
}
return manager, nil
}