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
+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