87016ef5dc
- New `type=check` stage: the server runs a `commands` block (sh -c, per command_timeout, workspace env) and routes on pass/fail; per-command status, exit code, duration and bounded output are recorded and the failing output is the handoff. With delivery=true it is the landing gate (commit leftovers, merge moved main, checks in a fresh candidate worktree, fast-forward main). Parser/registry, lint (silent guards), format docs, CLI inspect, app graph and run detail rendering. - delivery=true is accepted on every harness (and on check stages). - permissions.shell on claude stages maps to Bash(cmd) / Bash(prefix:*) rules instead of a bare Bash allow; stages without edit that change the workspace fail the visit with the changed files listed (allow_workspace_changes=true opts out; artifacts, public and harness state dirs are ignored). - File-change capture: symlinks compared by target, untouched protected files no longer make captures partial, untracked caches/dependency/build output left out, lockfiles listed without patch, huge files compared by metadata, raised patch/line limits. Outcome repair follow-ups are logged and counted on the step (control.outcome_repairs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
// Package stage owns type-specific validation and execution. Pipeline parsing,
|
|
// graph routing, persistence, and presentation belong to their respective layers.
|
|
package stage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// Values are runtime data, not the prose output contract in a definition.
|
|
type Values map[string]any
|
|
|
|
// TurnPaths is the runtime-provided file layout for one model visit. Memory is
|
|
// the short essential memory the prompt inlines; Input and History are the full
|
|
// previous output and run history, read only on demand (History is empty for
|
|
// callers that predate it). Output is written by the server from the model's
|
|
// returned markdown. Private belongs to this visit; Public is shared by every
|
|
// stage in the run.
|
|
type TurnPaths struct {
|
|
Dir string
|
|
Input string
|
|
Memory string
|
|
History string
|
|
Output string
|
|
Private string
|
|
Public string
|
|
}
|
|
|
|
type Definition struct {
|
|
ReportFileArtifacts bool
|
|
Key string
|
|
Type string
|
|
// ArtifactsDir is the per-run/step directory the runtime created for this
|
|
// visit; empty when the runner did not provide one (for example in tests).
|
|
ArtifactsDir string
|
|
// Workspace is the run directory (runtime-provided); a check stage runs
|
|
// its commands there.
|
|
Workspace string
|
|
Turn TurnPaths
|
|
// Skills is the visit's materialised skills block (runtime-provided, like
|
|
// ArtifactsDir); nil when the stage configures none or in tests.
|
|
Skills *SkillSet
|
|
Blocks map[string]string
|
|
Configs map[string]string
|
|
Edges map[string]string
|
|
}
|
|
|
|
// Result selects one declared outcome. The future graph runner owns resolving
|
|
// its destination and routing execution errors through the mandatory error edge.
|
|
type Result struct {
|
|
Outcome string `json:"outcome"`
|
|
Output Values `json:"output"`
|
|
}
|
|
|
|
// Stage implementations must be safe to share between concurrent runs. Definitions
|
|
// and input maps are caller-owned: validation and execution must not mutate them.
|
|
// Run returns an error for execution failures, not a fabricated success result.
|
|
type Stage interface {
|
|
Validate(Definition) error
|
|
Run(context.Context, Definition, Values) (Result, error)
|
|
}
|
|
|
|
// Registry is immutable after construction. Adding a type requires an implementation
|
|
// here, not another branch in the Markdown parser or graph validator.
|
|
type Registry struct {
|
|
types map[string]Stage
|
|
}
|
|
|
|
func NewRegistry(types map[string]Stage) *Registry {
|
|
copy := make(map[string]Stage, len(types))
|
|
for name, implementation := range types {
|
|
copy[name] = implementation
|
|
}
|
|
return &Registry{types: copy}
|
|
}
|
|
|
|
func DefaultRegistry() *Registry {
|
|
return NewRegistry(map[string]Stage{ModelType: ModelStage{}, NtfyType: NtfyStage{}, HumanType: HumanStage{}, CheckType: CheckStage{}})
|
|
}
|
|
|
|
func EffectiveType(name string) string {
|
|
if name == "" {
|
|
return ModelType
|
|
}
|
|
return name
|
|
}
|
|
|
|
func (r *Registry) Resolve(name string) (Stage, error) {
|
|
name = EffectiveType(name)
|
|
if r != nil {
|
|
if implementation := r.types[name]; implementation != nil {
|
|
return implementation, nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("unsupported stage type %q", name)
|
|
}
|
|
|
|
func (r *Registry) Validate(def Definition) error {
|
|
implementation, err := r.Resolve(def.Type)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return implementation.Validate(def)
|
|
}
|
|
|
|
func (r *Registry) Run(ctx context.Context, def Definition, input Values) (Result, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return Result{}, err
|
|
}
|
|
implementation, err := r.Resolve(def.Type)
|
|
if err != nil {
|
|
return Result{}, err
|
|
}
|
|
if err := implementation.Validate(def); err != nil {
|
|
return Result{}, err
|
|
}
|
|
return implementation.Run(ctx, def, input)
|
|
}
|