Files
alan a48e4a5b6a 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.
2026-11-03 19:35:47 +00:00

52 lines
1.8 KiB
Go

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
}