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:
+116
-22
@@ -9,10 +9,14 @@
|
||||
// the NoSummary sentinel instead of failing, stalling or delaying a stage or a
|
||||
// run. It never runs tools, never writes files and never propagates an error.
|
||||
//
|
||||
// Obvious future call sites (not wired here): protocol.OutputPreview in
|
||||
// internal/protocol/result.go and the notification summary in
|
||||
// internal/server/notify.go. Changing a user-visible title/verdict later also
|
||||
// requires updating the relevant internal/author/skill/references/*.md.
|
||||
// Title/GenerateTitle build on Summarise to give every run a bounded, never
|
||||
// empty operator-facing title: the model line when it succeeds and the prompt's
|
||||
// first line otherwise. The server wires GenerateTitle at run creation; the
|
||||
// store persists it with its source/model provenance. Obvious future call sites
|
||||
// (not wired here): protocol.OutputPreview in internal/protocol/result.go and the
|
||||
// notification summary in internal/server/notify.go. Changing a user-visible
|
||||
// title/verdict later also requires updating the relevant
|
||||
// internal/author/skill/references/*.md.
|
||||
package summarise
|
||||
|
||||
import (
|
||||
@@ -42,6 +46,31 @@ const InputCap = 8 << 10
|
||||
// are trimmed, never streamed onward.
|
||||
const OutputCap = 200
|
||||
|
||||
// TitleCap bounds an operator-facing run title (in runes) whether it came from
|
||||
// the model or the fallback, so a stored title stays a short single line.
|
||||
const TitleCap = 80
|
||||
|
||||
// FallbackTitle is the last-resort title used when a prompt has no usable line,
|
||||
// so a stored title is never empty.
|
||||
const FallbackTitle = "Untitled run"
|
||||
|
||||
// Title provenance recorded beside a stored run title so a diagnosis can tell a
|
||||
// model title from the derived fallback.
|
||||
const (
|
||||
SourceModel = "model"
|
||||
SourceFallback = "fallback"
|
||||
SourceExplicit = "explicit"
|
||||
)
|
||||
|
||||
// Title is a bounded, single-line operator-facing run title plus how it was
|
||||
// produced: SourceModel with the generating Model, SourceFallback, or
|
||||
// SourceExplicit when the operator typed it (--title or a rename).
|
||||
type Title struct {
|
||||
Text string
|
||||
Source string
|
||||
Model string
|
||||
}
|
||||
|
||||
// DefaultTimeout is the hard per-call budget: one generation must finish within
|
||||
// a few seconds even when the caller passes a longer or absent deadline.
|
||||
const DefaultTimeout = 5 * time.Second
|
||||
@@ -59,6 +88,10 @@ const quoteCutset = "\"'`\u2018\u2019\u201c\u201d"
|
||||
// punctCutset is the set of trailing punctuation stripped from a summary line.
|
||||
const punctCutset = ".!?,;:\u2026\u3002\uff01\uff1f\uff0c\uff1b\uff1a"
|
||||
|
||||
// markCutset is the set of leading markdown markers (headings, quotes, list and
|
||||
// emphasis tokens) stripped from a cleaned line so a title carries no markdown.
|
||||
const markCutset = "#>*_`-+"
|
||||
|
||||
// Selection is the resolved harness configuration the summariser generates with.
|
||||
// Harness, Executable and Model come from the configured default harness profile
|
||||
// (its interactive Model, never its PipelineModel); none of them are constants.
|
||||
@@ -105,20 +138,28 @@ type Summariser struct {
|
||||
// records at most one bounded OperationEvidence when a call fails and Operations
|
||||
// is configured. It never propagates an error and never runs tools.
|
||||
func (s Summariser) Summarise(ctx context.Context, source string) string {
|
||||
line, _ := s.summarise(ctx, source)
|
||||
return line
|
||||
}
|
||||
|
||||
// summarise is the single implementation behind Summarise and Title. It returns
|
||||
// the bounded line (or NoSummary) and the resolved selection, so a caller can
|
||||
// record which model produced it without resolving the harness twice.
|
||||
func (s Summariser) summarise(ctx context.Context, source string) (string, Selection) {
|
||||
selection, err := s.resolve()
|
||||
if err != nil {
|
||||
s.log(Selection{}, true, err)
|
||||
return NoSummary
|
||||
return NoSummary, Selection{}
|
||||
}
|
||||
if strings.TrimSpace(source) == "" {
|
||||
s.log(selection, false, nil)
|
||||
return NoSummary
|
||||
return NoSummary, selection
|
||||
}
|
||||
generator, err := s.generator(selection)
|
||||
if err != nil {
|
||||
s.record(selection, err)
|
||||
s.log(selection, true, err)
|
||||
return NoSummary
|
||||
return NoSummary, selection
|
||||
}
|
||||
timeout := s.Timeout
|
||||
if timeout <= 0 {
|
||||
@@ -141,17 +182,62 @@ func (s Summariser) Summarise(ctx context.Context, source string) string {
|
||||
if err != nil {
|
||||
s.record(selection, err)
|
||||
s.log(selection, true, err)
|
||||
return NoSummary
|
||||
return NoSummary, selection
|
||||
}
|
||||
line := oneLine(text)
|
||||
if line == "" {
|
||||
err = fmt.Errorf("model returned no usable one-line summary")
|
||||
s.record(selection, err)
|
||||
s.log(selection, true, err)
|
||||
return NoSummary
|
||||
return NoSummary, selection
|
||||
}
|
||||
s.log(selection, false, nil)
|
||||
return line
|
||||
return line, selection
|
||||
}
|
||||
|
||||
// Title returns a bounded, single-line operator-facing title for a run created
|
||||
// from prompt. It asks the shared summariser for one bounded line and, when that
|
||||
// fails or times out, falls back to the prompt's first usable line. It never
|
||||
// returns an empty title, never propagates an error and never exceeds the
|
||||
// summariser's hard timeout, so run creation always starts with a usable title.
|
||||
func (s Summariser) Title(ctx context.Context, prompt string) Title {
|
||||
line, selection := s.summarise(ctx, prompt)
|
||||
if line != NoSummary {
|
||||
if text := capRunes(line, TitleCap); text != "" {
|
||||
return Title{Text: text, Source: SourceModel, Model: selection.Model}
|
||||
}
|
||||
}
|
||||
return Title{Text: DeriveTitle(prompt), Source: SourceFallback}
|
||||
}
|
||||
|
||||
// GenerateTitle is the package entry point that derives a run title from the
|
||||
// configured default harness, so a caller need not construct a Summariser. It is
|
||||
// bounded and never blocks past the summariser's hard timeout.
|
||||
func GenerateTitle(ctx context.Context, prompt string) Title { return Summariser{}.Title(ctx, prompt) }
|
||||
|
||||
// DeriveTitle is the bounded fallback title for a run prompt: its first usable
|
||||
// line, cleaned the same way a model reply is and capped to TitleCap runes. It is
|
||||
// never empty.
|
||||
func DeriveTitle(prompt string) string {
|
||||
for _, raw := range strings.Split(prompt, "\n") {
|
||||
if line := cleanLine(raw); line != "" {
|
||||
return capRunes(line, TitleCap)
|
||||
}
|
||||
}
|
||||
return FallbackTitle
|
||||
}
|
||||
|
||||
// ExplicitTitle normalises an operator-supplied run title (--title or a rename)
|
||||
// to a bounded single line and reports whether it carried usable text. Unlike a
|
||||
// derived title it preserves the operator's wording and punctuation, only
|
||||
// collapsing whitespace and controlling characters; it is never generated or
|
||||
// model-cleaned.
|
||||
func ExplicitTitle(raw string) (Title, bool) {
|
||||
text := capRunes(protocol.NormalizeText(raw), TitleCap)
|
||||
if text == "" {
|
||||
return Title{}, false
|
||||
}
|
||||
return Title{Text: text, Source: SourceExplicit}, true
|
||||
}
|
||||
|
||||
func (s Summariser) resolve() (Selection, error) {
|
||||
@@ -208,23 +294,31 @@ func truncateSource(source string) string {
|
||||
// punctuation, and caps the result to OutputCap runes.
|
||||
func oneLine(text string) string {
|
||||
for _, raw := range strings.Split(text, "\n") {
|
||||
line := strings.TrimSpace(raw)
|
||||
if line == "" || isFenceLine(line) {
|
||||
continue
|
||||
if line := cleanLine(raw); line != "" {
|
||||
return capRunes(line, OutputCap)
|
||||
}
|
||||
line = strings.TrimSpace(protocol.NormalizeText(line))
|
||||
line = strings.Trim(line, quoteCutset)
|
||||
line = strings.TrimSpace(line)
|
||||
line = strings.TrimRight(line, punctCutset)
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
return capRunes(line, OutputCap)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// cleanLine reduces one raw line to plain single-line text, or "" when it carries
|
||||
// no usable content (empty, whitespace or a bare code fence). It collapses
|
||||
// whitespace/control characters, strips surrounding quotes, leading markdown
|
||||
// markers and trailing punctuation. It is the shared primitive behind a summary
|
||||
// line and a derived run title.
|
||||
func cleanLine(raw string) string {
|
||||
line := strings.TrimSpace(raw)
|
||||
if line == "" || isFenceLine(line) {
|
||||
return ""
|
||||
}
|
||||
line = strings.TrimSpace(protocol.NormalizeText(line))
|
||||
line = strings.TrimSpace(strings.TrimLeft(line, markCutset))
|
||||
line = strings.Trim(line, quoteCutset)
|
||||
line = strings.TrimSpace(line)
|
||||
line = strings.TrimRight(line, punctCutset)
|
||||
return strings.TrimSpace(line)
|
||||
}
|
||||
|
||||
// isFenceLine reports whether a trimmed line is a markdown code-fence delimiter
|
||||
// (an optional language token after a run of backticks/tildes, but no content).
|
||||
// "```Summary```" is not a fence line: it carries content and is cleaned instead.
|
||||
|
||||
@@ -267,6 +267,87 @@ func TestSummariseDiagnostics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitleUsesModelLineAndRecordsSource(t *testing.T) {
|
||||
s := Summariser{
|
||||
Selection: selection(),
|
||||
Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) {
|
||||
return `## "Fix the flaky login test."`, nil
|
||||
}),
|
||||
}
|
||||
got := s.Title(context.Background(), "prompt text")
|
||||
if got.Text != "Fix the flaky login test" {
|
||||
t.Fatalf("got %q, want the cleaned model title", got.Text)
|
||||
}
|
||||
if got.Source != SourceModel || got.Model != "p/open" {
|
||||
t.Fatalf("title provenance = %+v, want model p/open", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitleFallsBackToBoundedPromptLine(t *testing.T) {
|
||||
long := strings.Repeat("é", TitleCap*2)
|
||||
s := Summariser{
|
||||
Selection: selection(),
|
||||
Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) {
|
||||
return "", errors.New("transport down")
|
||||
}),
|
||||
}
|
||||
for _, prompt := range []string{"First line\nthen ignored", " \n Fix the widget \nmore", "- bullet task here\nrest", long} {
|
||||
got := s.Title(context.Background(), prompt)
|
||||
if got.Text == "" || got.Text == NoSummary || got.Text == FallbackTitle {
|
||||
t.Fatalf("prompt %q produced unusable title %+v", prompt, got)
|
||||
}
|
||||
if got.Source != SourceFallback || got.Model != "" {
|
||||
t.Fatalf("prompt %q provenance = %+v, want fallback with no model", prompt, got)
|
||||
}
|
||||
if len([]rune(got.Text)) > TitleCap {
|
||||
t.Fatalf("prompt %q title has %d runes, want <= %d", prompt, len([]rune(got.Text)), TitleCap)
|
||||
}
|
||||
if strings.ContainsAny(got.Text, "\r\n") {
|
||||
t.Fatalf("prompt %q title %q is not a single line", prompt, got.Text)
|
||||
}
|
||||
}
|
||||
if got := s.Title(context.Background(), "First line\nthen ignored"); got.Text != "First line" {
|
||||
t.Fatalf("fallback title = %q, want the prompt's first line", got.Text)
|
||||
}
|
||||
if got := s.Title(context.Background(), "- bullet task here\nrest"); got.Text != "bullet task here" {
|
||||
t.Fatalf("fallback stripped markdown = %q, want the leading marker removed", got.Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitleNeverEmptyForBlankPrompt(t *testing.T) {
|
||||
s := Summariser{
|
||||
Selection: selection(),
|
||||
Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) {
|
||||
return "", nil
|
||||
}),
|
||||
}
|
||||
got := s.Title(context.Background(), " \n\t")
|
||||
if got.Text != FallbackTitle || got.Source != SourceFallback {
|
||||
t.Fatalf("blank prompt title = %+v, want %q fallback", got, FallbackTitle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplicitTitleNormalisesAndBounds(t *testing.T) {
|
||||
got, ok := ExplicitTitle(" Fix the\nflaky login test ")
|
||||
if !ok || got.Text != "Fix the flaky login test" || got.Source != SourceExplicit || got.Model != "" {
|
||||
t.Fatalf("explicit title = %+v, %t; want collapsed explicit text", got, ok)
|
||||
}
|
||||
// The operator's punctuation and wording are preserved, unlike a cleaned
|
||||
// model line.
|
||||
if got, ok := ExplicitTitle("Ship v2.0!"); !ok || got.Text != "Ship v2.0!" {
|
||||
t.Fatalf("explicit title altered the operator's text: %+v %t", got, ok)
|
||||
}
|
||||
long := strings.Repeat("é", TitleCap*2)
|
||||
if got, ok := ExplicitTitle(long); !ok || len([]rune(got.Text)) != TitleCap {
|
||||
t.Fatalf("explicit title not capped to %d runes: %d", TitleCap, len([]rune(got.Text)))
|
||||
}
|
||||
for _, blank := range []string{"", " ", "\n\t", "\x00\x01"} {
|
||||
if got, ok := ExplicitTitle(blank); ok {
|
||||
t.Fatalf("blank explicit title %q accepted as %+v", blank, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummariseSuccessLogsAndRecordsNoFailure(t *testing.T) {
|
||||
var logs []string
|
||||
operations := &stage.OperationLog{}
|
||||
|
||||
Reference in New Issue
Block a user