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
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
func TestShowcaseDefinitions(t *testing.T) {
for _, name := range []string{"task", "review", "research", "three-stage"} {
for _, name := range []string{"one-stage", "two-stages", "feedback-loop", "human-decision"} {
t.Run(name, func(t *testing.T) {
source, err := os.ReadFile(filepath.Join("..", "..", "examples", name+".md"))
if err != nil {
+51
View File
@@ -0,0 +1,51 @@
package pipeline
import (
"context"
"database/sql"
"fmt"
"strconv"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// examplesSeededSetting is the server_settings key recording that the example
// pipelines were considered for this database. Once present, SeedExamples never
// adds anything again, so deleting the examples does not bring them back.
const examplesSeededSetting = "examples_seeded"
// SeedExamples publishes the given example definitions as ordinary pipelines,
// but only into a brand-new database: one whose schema this Open created, that
// has no pipelines and has never been seeded. Every call that gets past the
// marker check records the marker, so an existing install that upgrades is
// marked without gaining or rewriting anything, and a later start never seeds.
// Sources must already be bound to the server's default model and harness. It
// returns the number of pipelines created.
func (s *Store) SeedExamples(ctx context.Context, items []protocol.Template) (int, error) {
var marker string
err := s.db.QueryRowContext(ctx, `SELECT value FROM server_settings WHERE key=?`, examplesSeededSetting).Scan(&marker)
if err == nil {
return 0, nil
}
if err != sql.ErrNoRows {
return 0, err
}
seeded := 0
if s.created {
var count int
if err := s.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM pipelines`).Scan(&count); err != nil {
return 0, err
}
if count == 0 {
for _, item := range items {
// Create-only: a seed never replaces or versions an existing pipeline.
if _, err := s.Submit(ctx, item.Name, item.Source, true); err != nil {
return seeded, fmt.Errorf("seed example %q: %w", item.Name, err)
}
seeded++
}
}
}
_, err = s.db.ExecContext(ctx, `INSERT INTO server_settings(key,value) VALUES(?,?) ON CONFLICT(key) DO NOTHING`, examplesSeededSetting, strconv.Itoa(seeded))
return seeded, err
}
+94
View File
@@ -0,0 +1,94 @@
package pipeline
import (
"context"
"path/filepath"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func seedItems() []protocol.Template {
return []protocol.Template{
{Key: "a", Name: "Example: a", Source: Template([]string{"one"}, true)},
{Key: "b", Name: "Example: b", Source: Template([]string{"one", "two"}, true)},
}
}
func TestSeedExamplesOnlyIntoABrandNewDatabase(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "new.db")
store, err := Open(path)
if err != nil {
t.Fatal(err)
}
seeded, err := store.SeedExamples(ctx, seedItems())
if err != nil || seeded != 2 {
t.Fatal("brand-new database not seeded", seeded, err)
}
items, _ := store.List(ctx)
if len(items) != 2 || items[0].Name != "Example: a" || items[0].Version != 1 {
t.Fatal("examples are not ordinary version-1 pipelines", items)
}
// A second call in the same process is a no-op.
if seeded, err = store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
t.Fatal("seeded twice", seeded, err)
}
// Removing every example must not bring them back on the next start. There is
// no pipeline delete command yet, so remove the rows directly.
if _, err := store.db.Exec(`DELETE FROM submissions; DELETE FROM pipeline_versions; DELETE FROM pipelines`); err != nil {
t.Fatal(err)
}
store.Close()
store, err = Open(path)
if err != nil {
t.Fatal(err)
}
defer store.Close()
if seeded, err = store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
t.Fatal("deleted examples came back", seeded, err)
}
if items, _ = store.List(ctx); len(items) != 0 {
t.Fatal("deleted examples came back", items)
}
}
func TestSeedExamplesNeverChangesAnExistingInstall(t *testing.T) {
ctx := context.Background()
for _, name := range []string{"empty", "populated"} {
t.Run(name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "existing.db")
store, err := Open(path)
if err != nil {
t.Fatal(err)
}
if name == "populated" {
if _, err := store.Submit(ctx, "mine", Template([]string{"one"}, true)); err != nil {
t.Fatal(err)
}
}
// Simulate an install from before seeding existed: no marker.
store.Close()
store, err = Open(path)
if err != nil {
t.Fatal(err)
}
if seeded, err := store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
t.Fatal("upgrade seeded examples", seeded, err)
}
store.Close()
store, err = Open(path)
if err != nil {
t.Fatal(err)
}
defer store.Close()
if seeded, err := store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
t.Fatal("later start seeded examples", seeded, err)
}
items, _ := store.List(ctx)
if (name == "empty" && len(items) != 0) || (name == "populated" && (len(items) != 1 || items[0].Name != "mine" || items[0].Version != 1)) {
t.Fatal("upgrade changed pipelines", items)
}
})
}
}
+9 -1
View File
@@ -25,6 +25,9 @@ type Store struct {
runnerClaimed bool
done chan struct{}
closeOnce sync.Once
// created reports that this Open created the database schema, i.e. the
// database is brand new. Only then may SeedExamples add pipelines.
created bool
}
// openDB opens one SQLite connection pool for a DSN. Every open path shares it
@@ -44,6 +47,11 @@ func Open(path string) (*Store, error) {
if err != nil {
return nil, err
}
var existing int
if err := db.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='pipelines'`).Scan(&existing); err != nil {
db.Close()
return nil, err
}
_, err = db.Exec(`PRAGMA foreign_keys=ON; PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;
CREATE TABLE IF NOT EXISTS pipelines (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE, created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS pipeline_versions (id INTEGER PRIMARY KEY, pipeline_id INTEGER NOT NULL REFERENCES pipelines(id), version INTEGER NOT NULL, source TEXT NOT NULL, content_hash TEXT NOT NULL, graph_json TEXT NOT NULL, created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE(pipeline_id, version));
@@ -52,7 +60,7 @@ CREATE TABLE IF NOT EXISTS submissions (id INTEGER PRIMARY KEY, name TEXT NOT NU
db.Close()
return nil, err
}
s := &Store{db: db, dir: filepath.Dir(path), path: path, done: make(chan struct{})}
s := &Store{db: db, dir: filepath.Dir(path), path: path, done: make(chan struct{}), created: existing == 0}
if err := s.initRuns(); err != nil {
db.Close()
return nil, err