Replace starters with four graded examples seeded into new databases

The template catalog is now Example 1-4: one stage, two stages (handoff),
feedback loop (runner-owned limits, retries, timeout) and human decision
(type=human approve/revise/abort with notify hooks). All read-only or leave
changes uncommitted; none commits, pushes or deploys.

A brand-new database (schema created by this Open) gets the examples once at
server start, bound to the configured default model and harness. A
server_settings marker records the decision, so removed examples never come
back and existing installs are marked without any pipeline being added or
rewritten.
This commit is contained in:
2026-11-03 19:35:47 +00:00
parent fa6c0864db
commit a48e4a5b6a
38 changed files with 711 additions and 929 deletions
+18 -1
View File
@@ -1,8 +1,12 @@
package server
import (
"git.a-wan.net/alan/pipelines/internal/harness"
"context"
"os"
"git.a-wan.net/alan/pipelines/examples"
"git.a-wan.net/alan/pipelines/internal/harness"
"git.a-wan.net/alan/pipelines/internal/pipeline"
)
func starterDefaults() (string, string) {
@@ -13,3 +17,16 @@ func starterDefaults() (string, string) {
}
return model, backend
}
// SeedExamples adds the bundled example pipelines to a brand-new database, bound
// to the server's configured default model and harness exactly as the template
// picker binds them. It is a no-op for an existing or already-seeded database
// (see pipeline.Store.SeedExamples) and returns the number created.
func SeedExamples(ctx context.Context, store *pipeline.Store) (int, error) {
model, backend := starterDefaults()
items := examples.Catalog()
for i := range items {
items[i].Source = pipeline.WithDefaults(items[i].Source, model, backend)
}
return store.SeedExamples(ctx, items)
}
+13 -12
View File
@@ -105,9 +105,10 @@ func TestStageNotificationEventsAndArtifactAudit(t *testing.T) {
}
}
// Regress the exact research -> report terminal-path recipe from the authoring guide.
// Regress the terminal-path recipe from the authoring guide (research -> report
// there) on the bundled two-stage example's draft -> check.
// A completion-alert request must not require native delivery or change run routing.
func TestResearchTerminalNotificationRecipe(t *testing.T) {
func TestTerminalNotificationRecipe(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "recipe.db"))
@@ -117,15 +118,15 @@ func TestResearchTerminalNotificationRecipe(t *testing.T) {
defer store.Close()
var source string
for _, template := range examples.Catalog() {
if template.Key == "research" {
if template.Key == "two-stages" {
source = template.Source
}
}
if source == "" {
t.Fatal("research template missing")
t.Fatal("two-stages template missing")
}
source = strings.Replace(source, "# stage research", "# stage research\n```notify\non=failure\n```", 1)
source = strings.Replace(source, "# stage report", "# stage report\n```notify\non=success,failure\n```", 1)
source = strings.Replace(source, "# stage draft", "# stage draft\n```notify\non=failure\n```", 1)
source = strings.Replace(source, "# stage check", "# stage check\n```notify\non=success,failure\n```", 1)
if _, err = store.Submit(ctx, "research notification recipe", source); err != nil {
t.Fatal(err)
}
@@ -159,12 +160,12 @@ func TestResearchTerminalNotificationRecipe(t *testing.T) {
name, stage, outcome, status string
executionError, deliveryError bool
}{
{"success", "report", "success", "succeeded", false, false},
{"research blocked", "research", "blocked", "failed", false, false},
{"research execution error", "research", "error", "failed", true, false},
{"report blocked", "report", "blocked", "failed", false, false},
{"report execution error", "report", "error", "failed", true, false},
{"delivery error preserves success", "report", "success", "succeeded", false, true},
{"success", "check", "success", "succeeded", false, false},
{"draft blocked", "draft", "blocked", "failed", false, false},
{"draft execution error", "draft", "error", "failed", true, false},
{"check blocked", "check", "blocked", "failed", false, false},
{"check execution error", "check", "error", "failed", true, false},
{"delivery error preserves success", "check", "success", "succeeded", false, true},
} {
t.Run(test.name, func(t *testing.T) {
deliveryFailure.Store(test.deliveryError)
+42 -1
View File
@@ -57,7 +57,7 @@ func TestTemplatesDoNotSeedDatabaseAndCreateOnlyPreservesExisting(t *testing.T)
t.Fatal("invalid template returned to web/CLI", item.Key, err)
}
for _, s := range graph.Stages {
if s.Configs["provider"] != "test-provider" || s.Configs["model"] != "test-model" || s.Configs["harness"] != "opencode" {
if s.Type == "model" && (s.Configs["provider"] != "test-provider" || s.Configs["model"] != "test-model" || s.Configs["harness"] != "opencode") {
t.Fatal("template did not inherit configured defaults", item.Key, s.Configs)
}
}
@@ -87,3 +87,44 @@ func TestTemplatesDoNotSeedDatabaseAndCreateOnlyPreservesExisting(t *testing.T)
t.Fatal("immutable source changed")
}
}
// A brand-new database gets the bundled examples once, bound to the configured
// defaults like the template picker; they are ordinary editable pipelines.
func TestSeedExamplesBindsDefaultsOnABrandNewDatabase(t *testing.T) {
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(t.TempDir(), "harnesses.json"))
t.Setenv("PIPELINES_DEFAULT_MODEL", "test-provider/test-model")
t.Setenv("PIPELINES_DEFAULT_HARNESS", "opencode")
ctx := context.Background()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "fresh.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
catalog := examples.Catalog()
seeded, err := SeedExamples(ctx, store)
if err != nil || seeded != len(catalog) {
t.Fatal("examples not seeded", seeded, err)
}
items, err := store.List(ctx)
if err != nil || len(items) != len(catalog) {
t.Fatal("seeded pipelines missing", items, err)
}
for _, item := range items {
detail, err := store.Get(ctx, item.ID, 0)
if err != nil || detail.Version != 1 {
t.Fatal(item.Name, err)
}
for _, s := range detail.Graph.Stages {
if s.Type == "model" && (s.Configs["provider"] != "test-provider" || s.Configs["model"] != "test-model" || s.Configs["harness"] != "opencode") {
t.Fatal("seeded example did not bind configured defaults", item.Name, s.Key, s.Configs)
}
}
// Editing a seeded example is an ordinary new version.
if _, err := store.Submit(ctx, item.Name, detail.Source+"\n"); err != nil {
t.Fatal("seeded example not editable", item.Name, err)
}
}
if seeded, err = SeedExamples(ctx, store); err != nil || seeded != 0 {
t.Fatal("examples seeded twice", seeded, err)
}
}