Files
pipelines/internal/pipeline/control.go
T
alan 05ae530442 Make Pipelines Docker-only with OpenCode and Pi
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers.

Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent.

Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
2026-10-11 23:00:25 +01:00

98 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package pipeline
import (
"encoding/json"
"fmt"
"io"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func decodeControl(text string, value any) error {
// Both control blocks are flat objects. Reject duplicate keys before decoding.
keys := json.NewDecoder(strings.NewReader(text))
if token, err := keys.Token(); err != nil || token != json.Delim('{') {
return fmt.Errorf("expected object")
}
seen := map[string]bool{}
for keys.More() {
token, err := keys.Token()
if err != nil {
return err
}
key, ok := token.(string)
if !ok || seen[key] {
return fmt.Errorf("duplicate key %v", token)
}
seen[key] = true
var raw json.RawMessage
if err := keys.Decode(&raw); err != nil {
return err
}
}
decoder := json.NewDecoder(strings.NewReader(text))
decoder.DisallowUnknownFields()
if err := decoder.Decode(value); err != nil {
return err
}
var extra any
if err := decoder.Decode(&extra); err != io.EOF {
return fmt.Errorf("expected one JSON value")
}
return nil
}
func parseControl(s *Stage, fields map[string]string) error {
if text, ok := fields["limits"]; ok {
if err := decodeControl(text, &s.Limits); err != nil || s.Limits == nil {
return fmt.Errorf("limits must be an object with max_visits and optional on outcomes")
}
if s.Limits.MaxVisits < 1 || s.Limits.MaxVisits > 5 {
return fmt.Errorf("max_visits must be from 1 to 5")
}
seen := map[string]bool{}
for _, outcome := range s.Limits.On {
if !identifier.MatchString(outcome) || seen[outcome] {
return fmt.Errorf("invalid/duplicate limit outcome %q", outcome)
}
seen[outcome] = true
}
delete(fields, "limits")
}
if text, ok := fields["memory"]; ok {
if err := decodeControl(text, &s.Memory); err != nil || len(s.Memory) == 0 || len(s.Memory) > 50 {
return fmt.Errorf("memory must map 1–50 input names to input.FIELD or STAGE.FIELD")
}
for alias, reference := range s.Memory {
owner, field, ok := strings.Cut(strings.TrimSuffix(reference, "?"), ".")
if !identifier.MatchString(alias) || !ok || !identifier.MatchString(owner) || !identifier.MatchString(field) {
return fmt.Errorf("invalid memory reference %q: %q", alias, reference)
}
}
delete(fields, "memory")
}
return nil
}
func validateControl(s Stage, stages map[string]bool) error {
if s.Limits != nil {
for _, outcome := range s.Limits.On {
target, exists := s.Edges[outcome]
if !exists || protocol.IsTerminal(target) {
return fmt.Errorf("stage %s: limit outcome %q must name a nonterminal edge", s.Key, outcome)
}
}
}
for _, ref := range s.Memory {
owner, _, _ := strings.Cut(ref, ".")
if owner != "input" && !stages[owner] {
return fmt.Errorf("stage %s: unknown memory source %s", s.Key, owner)
}
if owner == s.Key {
return fmt.Errorf("stage %s: self-memory is not allowed; use another stage's explicit handoff", s.Key)
}
}
return nil
}