Files
pipelines/internal/protocol/runs.go
T
alan f3e0593f4d 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.
2026-10-16 13:36:48 +01:00

154 lines
5.9 KiB
Go

package protocol
import "strings"
const (
RunPipeline = "run_pipeline"
RunStarted = "run_started"
ListRuns = "list_runs"
Runs = "runs"
GetRun = "get_run"
Run = "run"
CancelRun = "cancel_run"
RetryRun = "retry_run"
SetRunTitle = "set_run_title"
GetRunEvidence = "get_run_evidence"
RunEvidence = "run_evidence"
)
type SessionEvidence struct {
Sequence int `json:"sequence"`
SessionID string `json:"session_id"`
Backend string `json:"backend"`
Directory string `json:"directory"`
Data string `json:"data,omitempty"`
Diagnostic string `json:"diagnostic,omitempty"`
}
type RunSummary struct {
ID int64 `json:"id"`
PipelineID int64 `json:"pipeline_id"`
Name string `json:"name"`
// Title is the operator-facing, bounded single-line description of what the
// run is for, generated from its prompt. It is never empty for a new run;
// historical rows predating the title column may omit it.
Title string `json:"title,omitempty"`
Version int `json:"version"`
ContentHash string `json:"content_hash"`
Status string `json:"status"`
Executing bool `json:"executing"`
Outcome string `json:"outcome"`
CurrentStage string `json:"current_stage"`
Workspace string `json:"workspace,omitempty"`
CreatedAt string `json:"created_at"`
FinishedAt string `json:"finished_at"`
Diagnostic string `json:"diagnostic"`
ResultPreview string `json:"result_preview,omitempty"`
CompletedSteps int `json:"completed_steps"`
}
// Label is the operator-facing name of a run: the generated Title when the
// server stored one, otherwise the pipeline Name (historical rows predate
// titles). It is the single definition shared by the CLI and TUI.
func (r RunSummary) Label() string {
if title := strings.TrimSpace(r.Title); title != "" {
return title
}
return r.Name
}
type RunStep struct {
Control *ControlEvidence `json:"control,omitempty"`
FileChanges *StageFileChanges `json:"file_changes,omitempty"`
Notifications []NotificationReceipt `json:"notifications,omitempty"`
Artifacts []StageArtifact `json:"artifacts,omitempty"`
Sequence int `json:"sequence"`
Stage string `json:"stage"`
Status string `json:"status"`
Outcome string `json:"outcome"`
Target string `json:"target"`
Input map[string]any `json:"input"`
Output map[string]any `json:"output"`
Diagnostic string `json:"diagnostic"`
SessionID string `json:"session_id"`
AgentActive bool `json:"agent_active"`
Transcript string `json:"transcript"`
// ArtifactsSkipped and ArtifactsTruncated count files excluded from the
// bounded per-step scan (over the file/size cap) and by the total budget.
ArtifactsSkipped int `json:"artifacts_skipped,omitempty"`
ArtifactsTruncated int `json:"artifacts_truncated,omitempty"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
}
// StageArtifact is one file a stage left in its artifacts directory. It is
// observed server-side evidence, not a model's claim. An empty Artifacts slice
// means no files were recorded (including historical steps).
type StageArtifact struct {
Name string `json:"name"`
SizeBytes int64 `json:"size_bytes"`
ContentType string `json:"content_type"`
URL string `json:"url"`
}
type MemoryRead struct {
Source string `json:"source"`
Sequence int `json:"sequence"` // zero denotes original run input
}
type ControlEvidence struct {
Visit int `json:"visit"`
MaxVisits int `json:"max_visits"`
LimitReached bool `json:"limit_reached,omitempty"`
ModelTarget string `json:"model_target,omitempty"`
Memory map[string]MemoryRead `json:"memory,omitempty"`
}
// StageFileChanges is observed workspace evidence, not a model's claim of authorship.
// Nil means no capture was retained (including historical steps).
type StageFileChanges struct {
Omitted int `json:"omitted,omitempty"`
Scope string `json:"scope,omitempty"`
Status string `json:"status"` // complete, partial, unavailable
Files []FileChange `json:"files"`
Skipped int `json:"skipped"`
Diagnostic string `json:"diagnostic,omitempty"`
}
type FileChange struct {
Path string `json:"path"`
Kind string `json:"kind"` // added, modified, deleted
Patch string `json:"patch,omitempty"`
Binary bool `json:"binary,omitempty"`
Truncated bool `json:"truncated,omitempty"`
BeforeMode string `json:"before_mode,omitempty"`
AfterMode string `json:"after_mode,omitempty"`
}
type NotificationReceipt struct {
Destination string `json:"destination"`
Status string `json:"status"`
Filename string `json:"filename,omitempty"`
MessageID string `json:"message_id,omitempty"`
AttachmentURL string `json:"attachment_url,omitempty"`
Diagnostic string `json:"diagnostic,omitempty"`
}
type RunDetail struct {
RunSummary
Graph Graph `json:"graph"`
RetryOf int64 `json:"retry_of,omitempty"`
Workspace string `json:"workspace"`
AllowTools bool `json:"allow_tools"`
WritePaths []string `json:"write_paths"`
Input map[string]any `json:"input"`
Output map[string]any `json:"output"`
Steps []RunStep `json:"steps"`
// TitleSource is "model" when Title came from the shared summariser or
// "fallback" when it was derived from the prompt; TitleModel names the model
// that produced a model title. They are retained so a diagnosis can tell the
// two apart and see which model was used.
TitleSource string `json:"title_source,omitempty"`
TitleModel string `json:"title_model,omitempty"`
}