Files
archie/internal/infrastructure/workflowsteps/workflowsteps.go
T
sam e94db30c60 feat(workflow): register gate.diff-rules as the .archie/gate.go replacement
steps.go's StageYaegiGate tells the operator to migrate the deleted
.archie/gate.go hook to a registered YAML workflow step, and
BuiltinStepRegistry() exposed only the six shipped workflows' own stages,
so there was nothing to migrate to. What that hook did, from 02720c8e
which deleted it: it read the worktree's repository-authored Go,
exporting Check(GateContext{Diff, ChangedFiles, Dir, BaseRef, Repo})
[]Finding, where each Finding carried a level ("error" blocked the run,
"warn" was advisory) and an optional file and line, and it inspected the
committed diff.

gate.diff-rules is that behaviour as a typed step: operator-written rules
in a stored definition -- per-rule level, RE2 pattern, optional path and
exclude_path scope, message -- matched against the ADDED lines of the
diff against the base branch, reported with their new-file line numbers.
An error-level finding parks the run with the findings in the park
reason; a warn-level finding is logged and nothing else. Unlike the hook
it replaces, no code is read out of the repository being worked on, and
the rules are versioned and audited with the definition they live in.

The settings are validated at the factory, which runs where a definition
is validated and again where it is compiled: a missing level, pattern or
message, an unknown level or settings key, and an expression that is not
a RE2 all refuse the definition rather than load and check nothing.

It arrives through the extension point archie-core-fwmp landed: a
repo-hooks provider in internal/infrastructure/workflowsteps, so both
roots that resolve a step type (the State Store's validating side and the
daemon's workflow-definitions client) register it at once.

Deliberately not landed: a step type for .archie/stages/*.go, whose
faithful equivalent is running a configured command. That would make the
stored workflow-definitions resource a command-execution surface on the
agent host, which is a maintainer's trust decision, not this lane's; it
is escalated, so steps.go's repo-stages error stays as it is.
2026-09-21 20:33:47 +10:00

91 lines
4.1 KiB
Go

// Package workflowsteps is the compiled-in workflow step-type provider set:
// the one place a step type is bundled into the Archie binaries that resolve
// one, so no such binary can keep a provider set of its own.
//
// Two composition roots register it, both of them roots that resolve a step
// type: archied's RunStateStore (the State Store's validating side) and
// archied's daemon root (openDaemonWorkflowDefinitions, the executing side's
// workflow-definitions client, alongside agentworker's
// productionWorkerDependencies). Sharing one package is what keeps them
// registering the same vocabulary. Processes that resolve no step type do not
// import it and register nothing: archie-gateway, archie-messaging,
// archie-playbooks and archie-ui.
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
}
// repoHooks is the provider that contributes the step types replacing the
// repository-authored hooks that were deleted with the interpreted workflow
// engine -- .archie/gate.go, whose rules now arrive as settings on
// workflow.DiffRulesStepName instead of as Go read out of the worktree being
// worked on.
//
// It is a provider of its own rather than part of shippedStages, which is
// scoped to the stages of the shipped workflows: a repository's migration target
// is not part of any shipped workflow, and a root that bundles one set should be
// able to tell which set a step type came from.
type repoHooks struct{}
func (repoHooks) Name() string { return "repo-hooks" }
func (repoHooks) StepTypes() []workflow.StepType {
return []workflow.StepType{workflow.DiffRulesStepType()}
}
// Providers returns the provider set the roots that resolve a workflow step
// type register at their composition root, before the first resolution: it is
// what NewManager registers, and what the roots' guards read to hold a
// registered vocabulary to the set it came from. 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 no bridge has been built from the Yaegi-interpreted
// plugins internal/plugin loads to workflow.StepFactory -- those plugins
// satisfy plugin.Plugin's metadata contract only. Such a bridge is possible:
// internal/secret/secretextract wraps an interpreted Engine into the typed
// contract secret.Registry.LoadDir registers (internal/app/archied/
// provider_secrets.go). Until one exists for step types, adding a step type
// means adding a provider here.
func Providers() []workflow.StepTypeProvider {
return []workflow.StepTypeProvider{shippedStages{}, repoHooks{}}
}
// 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
}