Let runs carry an operator title shown in the CLI and TUI

Add a bounded, never-empty title to every run. `pipelines run --title "..."`
sets it explicitly and skips model generation; otherwise the server generates
it from the prompt through the shared summariser and falls back to the prompt's
first line, recording title_source (model/fallback/explicit) and title_model.

- protocol/store: RunSummary.Title plus Label(), a set_run_title message, title
  columns with an idempotent migration, CreateRunTitled, and SetRunTitle renames.
- summarise: Title/GenerateTitle/DeriveTitle/ExplicitTitle bounded to TitleCap.
- runner: generate the title outside the admission lock and only for a request
  that starts a run; a replay reuses the stored title and an explicit title
  skips the model entirely.
- CLI: `--title` on run and a `title <run-id> "<title>"` rename command; human
  `runs` and `inspect` show the title beside the pipeline name and version.
- TUI: the run list row, run detail header, Home run cards and last-run line,
  and the pipeline Results line show the title via Label().

Tests cover storage/migration/fallback, explicit-title and rename, the
end-to-end CLI flow, and title rendering; CLI and operations docs updated.
This commit is contained in:
2026-10-16 13:35:43 +01:00
parent 0e6fbcc062
commit f3e0593f4d
23 changed files with 916 additions and 74 deletions
+102
View File
@@ -11,6 +11,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/runinspect"
"git.a-wan.net/alan/pipelines/internal/stage"
"git.a-wan.net/alan/pipelines/internal/summarise"
"net/http/httptest"
"os"
"path/filepath"
@@ -143,3 +144,104 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
t.Fatal("wait lost terminal state", output)
}
}
// TestCLIRunTitlesExplicitDerivedAndRename is the end-to-end title check: it
// drives the real CLI against the real websocket server and store, starts one
// run with --title and one without, and verifies the title is visible in the
// human `runs` list, in `inspect`, and after a `title` rename. Stage execution is
// stubbed because the environment must not call a model, so the without-flag run
// exercises the server-side prompt fallback rather than the shared summariser.
func TestCLIRunTitlesExplicitDerivedAndRename(t *testing.T) {
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(t.TempDir(), "harnesses.json"))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "cli-titles.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
if _, err := store.Submit(ctx, "workflow", pipeline.Template([]string{"worker"}, true)); err != nil {
t.Fatal(err)
}
handler := Handler(ctx, store)
r := handler.(*runHandler).runner
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "done"}}, nil
}
http := httptest.NewServer(handler)
defer http.Close()
defer func() { cancel(); WaitRuns(handler) }()
url := "ws" + strings.TrimPrefix(http.URL, "http") + "/connect"
run := func(args ...string) (string, error) {
var out bytes.Buffer
app := cli.App{Out: &out, Err: &out, In: strings.NewReader("")}
err := app.Run(ctx, append([]string{"--url", url}, args...))
return out.String(), err
}
output, err := run("run", "workflow", "first prompt line\nmore detail", "--title", "Operator chosen title", "--yes", "--json", "--wait")
if err != nil {
t.Fatal(err)
}
var started protocol.Message
if err := json.Unmarshal([]byte(output), &started); err != nil {
t.Fatal(err)
}
explicitID := started.RunDetail.ID
if started.RunDetail.Title != "Operator chosen title" || started.RunDetail.TitleSource != summarise.SourceExplicit {
t.Fatalf("explicit --title = %+v", started.RunDetail)
}
output, err = run("run", "workflow", "Derived title from prompt\nsecond line", "--yes", "--json", "--wait")
if err != nil {
t.Fatal(err)
}
if err := json.Unmarshal([]byte(output), &started); err != nil {
t.Fatal(err)
}
if started.RunDetail.Title != "Derived title from prompt" || started.RunDetail.TitleSource != summarise.SourceFallback {
t.Fatalf("derived title = %+v", started.RunDetail)
}
output, err = run("runs")
if err != nil {
t.Fatal(err)
}
t.Logf("pipelines runs:\n%s", output)
for _, want := range []string{
fmt.Sprintf("%d\t%s\t%s\tv1\t%s\n", explicitID, "Operator chosen title", "workflow", "succeeded"),
fmt.Sprintf("%d\t%s\t%s\tv1\t%s\n", started.RunDetail.ID, "Derived title from prompt", "workflow", "succeeded"),
} {
if !strings.Contains(output, want) {
t.Fatalf("runs output missing %q:\n%s", want, output)
}
}
output, err = run("inspect", fmt.Sprint(explicitID), "--json")
if err != nil {
t.Fatal(err)
}
var detail protocol.RunDetail
if err := json.Unmarshal([]byte(output), &detail); err != nil {
t.Fatal(err)
}
if detail.Title != "Operator chosen title" || detail.Name != "workflow" || detail.Version != 1 {
t.Fatalf("inspect omitted title/name/version: %+v", detail)
}
output, err = run("title", fmt.Sprint(explicitID), "Renamed after the fact")
if err != nil {
t.Fatal(err)
}
t.Logf("pipelines title: %s", strings.TrimSpace(output))
output, err = run("inspect", fmt.Sprint(explicitID), "--json")
if err != nil {
t.Fatal(err)
}
if err := json.Unmarshal([]byte(output), &detail); err != nil {
t.Fatal(err)
}
if detail.Title != "Renamed after the fact" || detail.TitleSource != summarise.SourceExplicit {
t.Fatalf("rename not visible in inspect: %+v", detail)
}
}