Engine: check stages, harness-agnostic delivery, read-only enforcement, complete captures

- 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>
This commit is contained in:
2026-12-03 12:52:16 +00:00
parent c4de1de27b
commit 87016ef5dc
47 changed files with 2674 additions and 129 deletions
+89
View File
@@ -0,0 +1,89 @@
package pipeline
import (
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/stage"
)
func checkStageSource(key, commands, configs, edges string) string {
return "# stage " + key + "\n\n```configs\ntype=check\n" + configs + "\n```\n\n```commands\n" + commands + "\n```\n\n```edges\n" + edges + "\n```\n"
}
// A check stage sits between implement and review: a red tree goes back to
// the implementer with the failing output, never to the reviewer.
func TestParseCheckStageBeforeReview(t *testing.T) {
source := lintSource(
modelStage("implement", "Make the change.", "read\nedit\nshell", "success -> verify\nerror -> #failure", "```checks\nnone: the verify stage runs the suite\n```"),
checkStageSource("verify", "go vet ./...\ngo test ./...", "command_timeout=15m", "pass -> review\nfail -> implement"),
modelStage("review", "Review the diff.", "read\nglob\ngrep", "success -> #success\nerror -> #failure", ""),
)
g, err := ParseDefinition(source)
if err != nil {
t.Fatal(err)
}
verify := g.Stages[1]
if verify.Type != stage.CheckType || verify.Blocks["commands"] != "go vet ./...\ngo test ./..." || verify.Configs["command_timeout"] != "15m" {
t.Fatalf("parsed %+v", verify)
}
if verify.Edges["error"] != "#failure" || !verify.FallbackError {
t.Fatal("check stage error edge", verify.Edges)
}
def := StageDefinition(verify)
if _, err := stage.CheckStageSpec(def); err != nil {
t.Fatal("stored definition no longer validates:", err)
}
errs, _ := Lint(g)
var rules []string
for _, finding := range errs {
rules = append(rules, finding.String())
}
// fail -> implement loops back: the existing loop rule asks for a limit.
if len(errs) != 1 || errs[0].Rule != "limits" {
t.Fatalf("lint %v", rules)
}
limited := strings.Replace(source, "```configs\ntype=check", "```limits\n{\"max_visits\":3}\n```\n\n```configs\ntype=check", 1)
if g, err = ParseDefinition(limited); err != nil {
t.Fatal(err)
}
if errs, _ := Lint(g); len(errs) != 0 {
t.Fatal(errs)
}
}
func TestCheckStageRejectsModelBlocksAndSilentGuards(t *testing.T) {
if _, err := ParseDefinition(checkStageSource("verify", "go test ./...", "model=x", "pass -> #success\nfail -> #failure")); err == nil {
t.Fatal("model config accepted on a check stage")
}
if _, err := ParseDefinition(checkStageSource("verify", "", "", "pass -> #success\nfail -> #failure")); err == nil {
t.Fatal("empty commands accepted")
}
g, err := ParseDefinition(checkStageSource("verify", "ruff check . || true", "", "pass -> #success\nfail -> #failure"))
if err != nil {
t.Fatal(err)
}
errs, _ := Lint(g)
if len(errs) != 1 || errs[0].Rule != "commands" {
t.Fatal(errs)
}
}
// A delivery check stage is the landing gate: its commands are the checks the
// server runs on the committed candidate before fast-forwarding main.
func TestCheckStageAsLandingGateSatisfiesDeliveryLint(t *testing.T) {
source := lintSource(
modelStage("implement", "Make the change; the delivery gate lands it.", "read\nedit\nshell", "success -> land\nerror -> #failure", "```checks\nnone: the land gate runs the suite\n```"),
checkStageSource("land", "go test ./...", "delivery=true", "pass -> #success\nfail -> #failure"),
)
g, err := ParseDefinition(source)
if err != nil {
t.Fatal(err)
}
if errs, _ := Lint(g); len(errs) != 0 {
t.Fatal(errs)
}
if enabled, err := stage.DeliveryEnabled(StageDefinition(g.Stages[1])); err != nil || !enabled {
t.Fatal(enabled, err)
}
}
+7
View File
@@ -90,6 +90,13 @@ func Lint(g Graph) (errs, warnings []LintFinding) {
}
}
}
if stage.EffectiveType(s.Type) == stage.CheckType {
for _, line := range strings.Split(s.Blocks["commands"], "\n") {
if guard := silentGuard(line); guard != "" {
add(&errs, s, "commands", "command %q can pass without running anything (%s); a missing tool must fail the check, so remove the guard", strings.TrimSpace(line), guard)
}
}
}
if stage.EffectiveType(s.Type) == stage.HumanType {
continue // a person bounds a human stage's loop
}