Files
archie/internal/domain/workflow/vocabulary.go
T
sam 6a25153659 docs(vale): reject em dashes, and remove the ones on the tree (#2149)
AGENTS.md forbids em dashes in prose, comments and user-facing strings, and
nothing checked it: Google.EmDash only flags a dash with a space on both sides,
so a bare U+2014 passed.

Archie.EmDash rejects U+2014 for Markdown, templates and Go, with a message
naming the alternatives. The 40 occurrences it finds are rewritten as a comma,
a colon, brackets or a second sentence, and scratch trees are out of scope so a
run over the repository reports on what the repository holds.
2026-11-27 19:33:06 +11:00

121 lines
4.3 KiB
Go

package workflow
import (
"errors"
"fmt"
"maps"
"sync"
"github.com/samcharles93/archie-core/internal/domain/lifecycle"
"github.com/samcharles93/archie-core/internal/platform/stableid"
)
// StepType is one named workflow step type: the vocabulary word a YAML
// workflow names, plus the factory that builds its stage.
type StepType struct {
Name string
// Title is the human name editors show for the step type.
Title string
Factory StepFactory
// Settings is a zero value of the step's settings type, from which the
// control plane derives the settings schema editors build forms from.
// Nil means the step takes no settings.
Settings any
}
// StepTypeProvider is the typed extension point through which a plugin
// contributes workflow step types. StepTypes is the capability-specific
// operation: a provider exposing identity metadata alone would be a metadata
// entry, not a step-type provider, and it is the only method the family calls.
type StepTypeProvider interface {
// Name identifies the provider in registration diagnostics.
Name() string
// StepTypes returns every step type this provider contributes. The
// manager validates the whole contribution before applying any of it.
StepTypes() []StepType
}
// Manager owns registration and resolution of workflow step types. Each
// process builds one from the shared provider set and injects it. Register
// every provider before the first resolution.
type Manager struct {
mu sync.Mutex
registry StepRegistry
// owners maps each step type to the provider that registered it.
owners map[string]string
// types holds each registered step type's descriptor, for the control plane.
types map[string]StepType
}
// NewManager builds an empty family manager. It holds no vocabulary of its own:
// the shipped stages are a provider like any other, registered by the process's
// composition root, so the vocabulary every side resolves is the one that was
// actually registered.
func NewManager() *Manager {
return &Manager{registry: StepRegistry{}, owners: map[string]string{}, types: map[string]StepType{}}
}
// Register validates a provider's whole contribution and applies all of it or
// none. It refuses nil or unnamed providers, bad identifiers, missing
// factories or titles, duplicates and types another provider already owns.
func (m *Manager) Register(provider StepTypeProvider) error {
if lifecycle.IsNil(provider) {
return errors.New("workflow step type provider is nil")
}
name := provider.Name()
if !stableid.Valid(name) {
return fmt.Errorf("workflow step type provider name %q is not a stable identifier", name)
}
contributed := provider.StepTypes()
pending := make(map[string]StepType, len(contributed))
order := make([]string, 0, len(contributed))
for _, stepType := range contributed {
switch {
case !stableid.Valid(stepType.Name):
return fmt.Errorf("workflow step type provider %q: step type %q is not a stable identifier", name, stepType.Name)
case stepType.Factory == nil:
return fmt.Errorf("workflow step type provider %q: step type %q has no factory", name, stepType.Name)
case stepType.Title == "":
return fmt.Errorf("workflow step type provider %q: step type %q has no title", name, stepType.Name)
}
if _, declared := pending[stepType.Name]; declared {
return fmt.Errorf("workflow step type provider %q declares step type %q twice", name, stepType.Name)
}
pending[stepType.Name] = stepType
order = append(order, stepType.Name)
}
m.mu.Lock()
defer m.mu.Unlock()
for _, stepType := range order {
if owner, claimed := m.owners[stepType]; claimed {
return fmt.Errorf("workflow step type %q is already claimed by provider %q", stepType, owner)
}
}
for _, stepType := range order {
m.registry[stepType] = pending[stepType].Factory
m.types[stepType] = pending[stepType]
m.owners[stepType] = name
}
return nil
}
// Registry returns the assembled vocabulary for the parser and compiler entry
// points. It is a copy: the closed set is a property of the manager, not
// something a consumer can widen.
func (m *Manager) Registry() StepRegistry {
m.mu.Lock()
defer m.mu.Unlock()
registry := make(StepRegistry, len(m.registry))
maps.Copy(registry, m.registry)
return registry
}
// Types returns each registered step type's descriptor, keyed by type name.
func (m *Manager) Types() map[string]StepType {
m.mu.Lock()
defer m.mu.Unlock()
return maps.Clone(m.types)
}