Artifacts: runner-internal turn files move to a Debugging files group

Each recorded artifact now carries a server group (deliverable or debug).
public/ files are deliverables; input/memory/history/output.md, session
exports and private/ scratch are debugging files. The app's Artifacts tab
lists deliverables and the Debug toggle reveals a separate Debugging files
group (older servers fall back to the filename rule); the TUI lists
deliverables first and marks debug rows; artifact search excludes debug
files unless include_debug / --debug-files is set.
This commit is contained in:
2026-11-04 17:43:47 +00:00
parent b5927505cc
commit 57f5219628
24 changed files with 541 additions and 30 deletions
+3 -1
View File
@@ -50,6 +50,7 @@ type options struct {
keep int
keepSet bool
all bool
debugFiles bool
json, source, noOpen, yes, allow, createOnly, force, wait bool
version, expected, limit, retryVisit int
timeout, waitTimeout time.Duration
@@ -166,6 +167,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
case "search":
f.StringVar(&o.kind, "type", "", "Narrow to one kind: "+strings.Join(protocol.SearchKinds, ", "))
f.IntVar(&o.limit, "limit", 0, "Maximum results (default 50, max 200)")
f.BoolVar(&o.debugFiles, "debug-files", false, "Also match runner-internal debugging artifacts (turn files, private/ scratch)")
case "retry":
f.BoolVar(&o.yes, "yes", false, "Confirm retry without an interactive prompt")
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
@@ -853,7 +855,7 @@ func (a App) Run(ctx context.Context, args []string) error {
if strings.TrimSpace(query) == "" {
return fmt.Errorf("search requires a query; use pipelines help search")
}
r, err := call(protocol.Message{Type: protocol.Search, Search: &protocol.SearchRequest{Query: query, Kind: o.kind, Limit: o.limit}})
r, err := call(protocol.Message{Type: protocol.Search, Search: &protocol.SearchRequest{Query: query, Kind: o.kind, Limit: o.limit, IncludeDebug: o.debugFiles}})
if err != nil {
return err
}
+2 -2
View File
@@ -11,7 +11,7 @@ var usage = map[string]string{
"validate": "validate <draft.md> [--json]",
"submit": "submit <draft.md> [--name NAME] [--create-only] [--yes] [--json]",
"list": "list [--json]",
"search": "search QUERY [--type KIND] [--limit N] [--json]",
"search": "search QUERY [--type KIND] [--limit N] [--debug-files] [--json]",
"show": "show <name|id> [--version N] [--json]",
"versions": "versions <name|id> [--json]",
"export": "export [name|id ...] [--output FILE.zip] [--all] [--version N]",
@@ -60,7 +60,7 @@ var notes = map[string]string{
"rpc": "Accepts a JSON protocol envelope; '-' reads stdin. Every TUI server operation is available here too. Mutating commands are not dry runs. The omni-search command is `search` (fields query, optional kind and limit) and answers with ranked `search_results`.",
"chat-adopt": "Adopt a session that already exists on a chat harness (an OpenCode session, or a Claude Code or Codex session by its id) so it appears in chat_sessions and can be continued from any client. Without --harness each available harness is asked in turn. The directory and title come from the harness's own record (never guessed; --title names a chat whose harness records none), and a missing id records nothing. Do not keep using the session elsewhere once it is continued here.",
"retention": "Local, explicit run-history retention; never automatic and never a side effect of another command. `report` is strictly read-only and prints what a policy would remove; `apply` removes it after approval (--yes for scripted use). Policy: --older-than DURATION selects runs created before now minus that rolling UTC duration (Go durations plus d/w; not a calendar boundary), --keep N keeps the newest N runs by run id and selects older ranks (--keep 0 keeps none). Both together are the conservative intersection; at least one is required. Protected and never removed: queued/running runs, runs waiting on a person (waiting run or step), runs with an active cleanup agent, and any run referenced by a retained run's retry provenance (transitively). A run that becomes protected before deletion aborts the whole apply. Artifacts at <root>/<run> are removed with their run and kept with protected/retained runs; the database is VACUUMed and its WAL checkpointed, with measured reclaimed bytes. Definitions and versions are immutable and never touched. --db must name an existing database (default: the standard data directory); --artifacts defaults to artifacts/ beside --db. Works without a running server.",
"search": "One read-only query over pipelines, versions, runs, steps, field text and artifacts. QUERY is free text, a bare status word (queued, running, succeeded, failed, canceled, interrupted) selecting those runs, or a lone date expression (today, yesterday, this week [Monday 00:00 local], or YYYY-MM-DD) selecting the runs created in that window. --type is the only narrowing mechanism and takes one kind: pipeline, version, run, step, field or artifact; an unknown kind is an error. Ranking: an exact name match (3) beats a name substring (2) beats a body-text match (1); equal tiers break by recency, then a stable kind/target tie-break, and every hit reports score, matched_field and recency so a client can re-rank. Bounds: the result cap defaults to 50 and clamps to 200 (0 = default); every kind scans at most 2000 rows and field-text scanning is additionally capped at 2000 steps / 1 MiB; Truncated plus scanned_steps, scanned_bytes and scan_bound_bytes report when a bound applied. Targets are stable: pipeline:<id>, pipeline:<id>:v<version>, run:<id>, run:<id>:<sequence>, run:<id>:<sequence>:<field>, or an artifact URL.",
"search": "One read-only query over pipelines, versions, runs, steps, field text and artifacts. QUERY is free text, a bare status word (queued, running, succeeded, failed, canceled, interrupted) selecting those runs, or a lone date expression (today, yesterday, this week [Monday 00:00 local], or YYYY-MM-DD) selecting the runs created in that window. --type is the only narrowing mechanism and takes one kind: pipeline, version, run, step, field or artifact; an unknown kind is an error. Ranking: an exact name match (3) beats a name substring (2) beats a body-text match (1); equal tiers break by recency, then a stable kind/target tie-break, and every hit reports score, matched_field and recency so a client can re-rank. Bounds: the result cap defaults to 50 and clamps to 200 (0 = default); every kind scans at most 2000 rows and field-text scanning is additionally capped at 2000 steps / 1 MiB; Truncated plus scanned_steps, scanned_bytes and scan_bound_bytes report when a bound applied. Targets are stable: pipeline:<id>, pipeline:<id>:v<version>, run:<id>, run:<id>:<sequence>, run:<id>:<sequence>:<field>, or an artifact URL. Artifact hits are deliverables only; runner-internal debugging files (input.md, memory.md, history.md, output.md, session.html, private/ scratch) are matched only with --debug-files.",
}
var serviceHelp = map[string]string{
+1 -1
View File
@@ -214,7 +214,7 @@ strftime('%Y-%m-%dT%H:%M:%SZ',started_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ'
rows.Close()
return nil, err
}
step.Artifacts = evidence.Files
step.Artifacts = protocol.ClassifyArtifacts(evidence.Files)
step.ArtifactsSkipped = evidence.Skipped
step.ArtifactsTruncated = evidence.Truncated
}
+17 -9
View File
@@ -37,6 +37,7 @@ func (s *Store) Search(ctx context.Context, req protocol.SearchRequest, now time
}
terms := parseSearchTerms(req.Query, now)
terms.Browse = browse
terms.IncludeDebug = req.IncludeDebug
terms.Limit = response.Cap
// A bare status word or date selects runs; it is never treated as body text.
selectorOnly := terms.Text == "" && !browse
@@ -129,13 +130,15 @@ func searchLimit(limit int) int {
// searchTerms is the parsed query. Text carries free text; Status and the
// From/To window carry a bare status word or a date expression that selects runs.
type searchTerms struct {
Browse bool
Limit int
Text string
Status string
HasDate bool
From time.Time
To time.Time
Browse bool
// IncludeDebug keeps runner-internal debugging artifacts in artifact hits.
IncludeDebug bool
Limit int
Text string
Status string
HasDate bool
From time.Time
To time.Time
}
// parseSearchTerms recognises a lone status word and a lone date expression and
@@ -625,7 +628,12 @@ ORDER BY r.created_at DESC,r.id DESC,a.sequence DESC LIMIT ?`
if err := json.Unmarshal([]byte(artifacts), &evidence); err != nil {
continue
}
for _, file := range evidence.Files {
// Debugging files (turn files, private/ scratch) are internal to the
// runner and stay out of results unless explicitly requested.
for _, file := range protocol.ClassifyArtifacts(evidence.Files) {
if file.IsDebug() && !terms.IncludeDebug {
continue
}
score, matched := 1, "content_type"
if terms.Browse {
score, matched = 0, ""
@@ -637,7 +645,7 @@ ORDER BY r.created_at DESC,r.id DESC,a.sequence DESC LIMIT ?`
results = append(results, protocol.SearchResult{
Kind: protocol.SearchKindArtifact, Target: file.URL,
Score: score, MatchedField: matched, Recency: recency,
Artifact: &protocol.SearchArtifact{RunID: runID, Sequence: sequence, Name: file.Name, ContentType: file.ContentType, SizeBytes: file.SizeBytes, URL: file.URL},
Artifact: &protocol.SearchArtifact{RunID: runID, Sequence: sequence, Name: file.Name, ContentType: file.ContentType, SizeBytes: file.SizeBytes, URL: file.URL, Group: file.Group},
})
}
}
+85
View File
@@ -0,0 +1,85 @@
package pipeline
import (
"context"
"path/filepath"
"sort"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// Artifact search returns only deliverables unless debugging files are asked
// for, and the step read path classifies stored records that carry no group.
func TestSearchArtifactsExcludeDebugFilesByDefault(t *testing.T) {
ctx := context.Background()
store, err := Open(filepath.Join(t.TempDir(), "search-debug.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { store.Close() })
if _, err := store.Submit(ctx, "Quartz", Template([]string{"quartz"}, true)); err != nil {
t.Fatal(err)
}
items, err := store.List(ctx)
if err != nil {
t.Fatal(err)
}
definition, err := store.Get(ctx, items[0].ID, 1)
if err != nil {
t.Fatal(err)
}
run, _, err := store.CreateRun(ctx, definition, "quartz-key", "/work/q", false, nil, map[string]any{"prompt": "task"})
if err != nil {
t.Fatal(err)
}
if err := store.BeginStep(ctx, run, 1, "quartz", map[string]any{"prompt": "task"}); err != nil {
t.Fatal(err)
}
// Stored without a group, as a server before the field recorded them.
files := []protocol.StageArtifact{
{Name: "input.md", ContentType: "text/markdown", URL: "/a/input.md"},
{Name: "history.md", ContentType: "text/markdown", URL: "/a/history.md"},
{Name: "private/qz-shot.png", ContentType: "image/png", URL: "/a/private/qz-shot.png"},
{Name: "public/qz-report.md", ContentType: "text/markdown", URL: "/a/public/qz-report.md"},
}
if err := store.FinishStep(ctx, run, protocol.RunStep{Sequence: 1, Status: "completed", Outcome: "success", Target: protocol.SuccessEnd, Artifacts: files}); err != nil {
t.Fatal(err)
}
names := func(req protocol.SearchRequest) []string {
t.Helper()
req.Kind = protocol.SearchKindArtifact
response, err := store.Search(ctx, req, time.Now())
if err != nil {
t.Fatal(err)
}
var got []string
for _, hit := range response.Results {
got = append(got, hit.Artifact.Name+"="+hit.Artifact.Group)
}
sort.Strings(got)
return got
}
if got := names(protocol.SearchRequest{Query: "md"}); len(got) != 1 || got[0] != "public/qz-report.md=deliverable" {
t.Fatalf("default search = %v, want only the public deliverable", got)
}
if got := names(protocol.SearchRequest{Query: "history"}); len(got) != 0 {
t.Fatalf("history.md surfaced by default: %v", got)
}
if got := names(protocol.SearchRequest{Query: "qz", IncludeDebug: true}); len(got) != 2 || got[0] != "private/qz-shot.png=debug" {
t.Fatalf("include_debug search = %v", got)
}
detail, err := store.GetRun(ctx, run)
if err != nil {
t.Fatal(err)
}
groups := map[string]string{}
for _, file := range detail.Steps[0].Artifacts {
groups[file.Name] = file.Group
}
if groups["history.md"] != protocol.ArtifactGroupDebug || groups["private/qz-shot.png"] != protocol.ArtifactGroupDebug || groups["public/qz-report.md"] != protocol.ArtifactGroupDeliverable {
t.Fatalf("read path groups = %v", groups)
}
}
+62
View File
@@ -0,0 +1,62 @@
package protocol
import "strings"
// Artifact presentation groups. A deliverable is a file the stage published to
// the run's public/ directory (or, for a visit recorded before the turn layout,
// any file it left). A debug file is one of the runner's own turn files or the
// visit's private/ scratch: evidence for debugging a stage, not its output.
const (
ArtifactGroupDeliverable = "deliverable"
ArtifactGroupDebug = "debug"
)
// TurnArtifactNames are the files the server itself writes into a model visit's
// turn directory. They are always debugging files.
var TurnArtifactNames = []string{"input.md", "memory.md", "history.md", "output.md", "session.html"}
// IsDebug reports whether the artifact is a runner-internal debugging file.
func (a StageArtifact) IsDebug() bool { return a.Group == ArtifactGroupDebug }
func isTurnArtifactName(name string) bool {
for _, turn := range TurnArtifactNames {
if name == turn {
return true
}
}
return name == LegacySessionMarkdownArtifact || strings.HasPrefix(name, "session-repair-")
}
// ClassifyArtifacts returns one visit's artifacts with Group set. public/ files
// are deliverables. Turn files, session exports and their repairs, and private/
// scratch are debug files; so is every other unprefixed file of a turn-layout
// visit (one that recorded any turn file), because a stage publishes only
// through public/. A visit recorded before the turn layout keeps its other
// files as deliverables. The rule uses only the recorded names, so runs stored
// before the field existed classify identically on read. It never mutates the
// input. Pure, O(artifacts).
func ClassifyArtifacts(files []StageArtifact) []StageArtifact {
if len(files) == 0 {
return files
}
turnVisit := false
for _, file := range files {
if isTurnArtifactName(file.Name) {
turnVisit = true
break
}
}
classified := make([]StageArtifact, len(files))
for i, file := range files {
switch {
case strings.HasPrefix(file.Name, "public/"):
file.Group = ArtifactGroupDeliverable
case turnVisit, isTurnArtifactName(file.Name), strings.HasPrefix(file.Name, "private/"):
file.Group = ArtifactGroupDebug
default:
file.Group = ArtifactGroupDeliverable
}
classified[i] = file
}
return classified
}
+49
View File
@@ -0,0 +1,49 @@
package protocol
import "testing"
func groupsByName(files []StageArtifact) map[string]string {
groups := map[string]string{}
for _, file := range files {
groups[file.Name] = file.Group
}
return groups
}
func TestClassifyArtifactsTurnVisit(t *testing.T) {
input := []StageArtifact{
{Name: "input.md"}, {Name: "memory.md"}, {Name: "history.md"}, {Name: "output.md"},
{Name: "session.html"}, {Name: "session-repair-1.html"}, {Name: "private/shot.png"},
{Name: "notes.txt"}, {Name: "public/report.html"}, {Name: "public/history.md"},
}
got := groupsByName(ClassifyArtifacts(input))
want := map[string]string{
"input.md": ArtifactGroupDebug, "memory.md": ArtifactGroupDebug, "history.md": ArtifactGroupDebug,
"output.md": ArtifactGroupDebug, "session.html": ArtifactGroupDebug, "session-repair-1.html": ArtifactGroupDebug,
"private/shot.png": ArtifactGroupDebug, "notes.txt": ArtifactGroupDebug,
"public/report.html": ArtifactGroupDeliverable, "public/history.md": ArtifactGroupDeliverable,
}
for name, group := range want {
if got[name] != group {
t.Errorf("%s: group %q, want %q", name, got[name], group)
}
}
for _, file := range input {
if file.Group != "" {
t.Fatalf("ClassifyArtifacts mutated its input: %+v", file)
}
}
}
func TestClassifyArtifactsLegacyVisitKeepsFilesAsDeliverables(t *testing.T) {
got := groupsByName(ClassifyArtifacts([]StageArtifact{{Name: "report.png"}, {Name: "private/scratch.txt"}}))
if got["report.png"] != ArtifactGroupDeliverable {
t.Errorf("legacy file group %q, want deliverable", got["report.png"])
}
if got["private/scratch.txt"] != ArtifactGroupDebug {
t.Errorf("private file group %q, want debug", got["private/scratch.txt"])
}
if ClassifyArtifacts(nil) != nil {
t.Error("nil input must stay nil")
}
}
+5
View File
@@ -278,6 +278,11 @@ type StageArtifact struct {
SizeBytes int64 `json:"size_bytes"`
ContentType string `json:"content_type"`
URL string `json:"url"`
// Group is the server's presentation classification (ArtifactGroupDeliverable
// or ArtifactGroupDebug, see ClassifyArtifacts). Every listing the server
// returns sets it; an older server omits it, so clients keep a filename
// fallback.
Group string `json:"group,omitempty"`
}
// LegacySessionMarkdownArtifact is the retired markdown session export file name.
+6
View File
@@ -80,6 +80,10 @@ type SearchRequest struct {
Query string `json:"query"`
Kind string `json:"kind,omitempty"`
Limit int `json:"limit,omitempty"`
// IncludeDebug also returns runner-internal debugging artifacts (turn files
// and private/ scratch, see ClassifyArtifacts). Off by default: artifact
// search surfaces only deliverables.
IncludeDebug bool `json:"include_debug,omitempty"`
}
// SearchResponse is the bounded set of matches. Results are ordered by recency
@@ -181,6 +185,8 @@ type SearchArtifact struct {
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
URL string `json:"url"`
// Group is the artifact's presentation group (see StageArtifact.Group).
Group string `json:"group,omitempty"`
}
// SearchChat is an operator chat session hit: its registry facts and, for a
+1 -1
View File
@@ -138,7 +138,7 @@ func (r *runner) scanArtifacts(runID int64, sequence int, directory string, publ
if len(files) == 0 {
files = nil
}
return files, skipped, truncated
return protocol.ClassifyArtifacts(files), skipped, truncated
}
// artifactRel returns the slash path of directory below the artifacts root. A
+10
View File
@@ -55,6 +55,13 @@ func TestSessionEvidenceIsInventoriedBeforeLargeCaptureDirectories(t *testing.T)
t.Fatalf("mandatory runtime file %s hidden by user captures", name)
}
}
// The recorded inventory carries the server's classification: turn files and
// private captures are debugging files.
for _, file := range files {
if file.Group != protocol.ArtifactGroupDebug {
t.Fatalf("%s group %q, want debug", file.Name, file.Group)
}
}
}
func TestArtifactsScanRecordsSizesTypesAndSkips(t *testing.T) {
@@ -396,6 +403,9 @@ func TestArtifactHTTPGetPublicSharedFile(t *testing.T) {
if shared.URL == "" {
t.Fatalf("public artifact missing: %+v", step.Artifacts)
}
if shared.Group != protocol.ArtifactGroupDeliverable {
t.Fatalf("public artifact group %q, want deliverable", shared.Group)
}
srv := httptest.NewServer(handler)
defer srv.Close()
resp, err := http.Get(srv.URL + shared.URL)
+26 -2
View File
@@ -57,12 +57,34 @@ func runArtifactVisits(steps []protocol.RunStep) []artifactVisit {
if step.Control != nil && step.Control.Visit > 0 {
visit = step.Control.Visit
}
visits = append(visits, artifactVisit{stage: stage, visit: visit, step: step, artifacts: step.PresentedArtifacts()})
visits = append(visits, artifactVisit{stage: stage, visit: visit, step: step, artifacts: deliverablesFirst(step.PresentedArtifacts())})
}
}
return visits
}
// deliverablesFirst orders a visit's artifacts with the stage's deliverables
// ahead of the runner-internal debugging files (marked [dbg] in each row), so
// the files a stage published lead and turn files never crowd them out. The
// order within each group is the recorded order.
func deliverablesFirst(artifacts []protocol.StageArtifact) []protocol.StageArtifact {
ordered := make([]protocol.StageArtifact, 0, len(artifacts))
for _, artifact := range artifacts {
if !artifact.IsDebug() {
ordered = append(ordered, artifact)
}
}
for _, artifact := range artifacts {
if artifact.IsDebug() {
ordered = append(ordered, artifact)
}
}
if len(ordered) == 0 {
return nil
}
return ordered
}
// artifactRef addresses one artifact row in the flat selection order the view
// uses (group order, then recorded order within the group).
type artifactRef struct {
@@ -170,7 +192,9 @@ func artifactRowText(artifact protocol.StageArtifact, widths artifactWidths, wid
// decision depends only on width, so every row's columns stay aligned
// whether or not the marker is shown.
if width >= artifactCursorWidth+artifactMarkerWidth+1+artifactMinName {
if isImageContentType(artifact.ContentType) {
if artifact.IsDebug() {
prefix += "[dbg] "
} else if isImageContentType(artifact.ContentType) {
prefix += "[img] "
} else {
prefix += strings.Repeat(" ", artifactMarkerWidth) + " "
+27
View File
@@ -0,0 +1,27 @@
package tui
import (
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func TestArtifactsDeliverablesLeadAndDebugFilesAreMarked(t *testing.T) {
artifacts := []protocol.StageArtifact{
{Name: "input.md", ContentType: "text/markdown", Group: protocol.ArtifactGroupDebug},
{Name: "history.md", ContentType: "text/markdown", Group: protocol.ArtifactGroupDebug},
{Name: "public/report.png", ContentType: "image/png", Group: protocol.ArtifactGroupDeliverable},
}
ordered := deliverablesFirst(artifacts)
if ordered[0].Name != "public/report.png" || ordered[1].Name != "input.md" || ordered[2].Name != "history.md" {
t.Fatalf("order = %+v", ordered)
}
widths := artifactWidthsFor([]artifactVisit{{artifacts: ordered}})
if row := artifactRowText(ordered[1], widths, 100, false); !strings.Contains(row, "[dbg] input.md") {
t.Fatalf("debug row not marked: %q", row)
}
if row := artifactRowText(ordered[0], widths, 100, false); !strings.Contains(row, "[img] public/report.png") {
t.Fatalf("deliverable row: %q", row)
}
}