diff --git a/cmd/agentop/tui/app.go b/cmd/agentop/tui/app.go index 97cb3e98a..3cc3df0cf 100644 --- a/cmd/agentop/tui/app.go +++ b/cmd/agentop/tui/app.go @@ -2846,6 +2846,9 @@ func (m *model) sessionHeader(id, suffix string) string { if p := m.parentSessionOf(id); p != "" { tail += " · under " + sessionIDCell(sanitizeLabel(p), noLimit) } + if m.sessionNoRecord(id) { + tail += " · not recorded" + } tail += m.scopeSuffix(m.agentScope, m.projectScope) // A floor of 12, so a very narrow terminal shows a stub of the label rather than dropping // it: the header is the only thing on screen naming which session these events belong to. diff --git a/cmd/agentop/tui/norecord_mark_test.go b/cmd/agentop/tui/norecord_mark_test.go new file mode 100644 index 000000000..3dabf7c2f --- /dev/null +++ b/cmd/agentop/tui/norecord_mark_test.go @@ -0,0 +1,130 @@ +package tui + +import ( + "strings" + "testing" + + "github.com/charmbracelet/lipgloss" + + "github.com/rossoctl/cortex/core/session" +) + +// A session that asked not to be recorded (#1923) has "(not recorded) " in front of its title, and +// it wins over the imported and child marks. A recorded session has no mark. +func TestSessionTitleCell_NoRecordPrefix(t *testing.T) { + m := fitModel(t, paneSessions, 200, 40, nil) + m.sessions = []session.SessionSummary{ + {ID: "off-1", Title: "fix the build", NoRecord: true}, + {ID: "off-2", Title: "fix the build", NoRecord: true, Source: importedSrc, ParentSession: "parent-123456789"}, + {ID: "live-1", Title: "fix the build"}, + } + m.rebuildSessionsTable() + rows := m.sessionsTbl.Rows() + if len(rows) != 3 { + t.Fatalf("got %d rows, want 3", len(rows)) + } + title := func(id string) string { + for _, r := range rows { + if strings.Contains(strings.Join(r, "|"), id) { + for _, c := range r { + if strings.Contains(c, "fix the build") { + return c + } + } + } + } + t.Fatalf("no row for %s in %q", id, rows) + return "" + } + for _, id := range []string{"off-1", "off-2"} { + if got := title(id); !strings.HasPrefix(got, noRecordMarker+"fix the build") { + t.Errorf("%s title = %q, want the prefix %q", id, got, noRecordMarker) + } + } + if got := title("live-1"); strings.Contains(got, noRecordMarker) { + t.Errorf("recorded title = %q, has the not-recorded mark", got) + } +} + +// With no TITLE column, the SESSION cell has the mark's short form, and the whole id still shows +// after it. +func TestSessionIDCell_NoRecordPrefixWithoutTitle(t *testing.T) { + m := fitModel(t, paneSessions, 60, 40, nil) + m.sessions = []session.SessionSummary{ + {ID: "off-1", Title: "fix the build", NoRecord: true}, + {ID: "live-1", Title: "fix the build"}, + } + m.rebuildSessionsTable() + rows := m.sessionsTbl.Rows() + if len(rows) != 2 { + t.Fatalf("got %d rows, want 2", len(rows)) + } + for _, r := range rows { + cell := r[0] + switch { + case strings.Contains(cell, "off-1"): + if !strings.HasPrefix(cell, noRecordIDMarker+"off-1") { + t.Errorf("not-recorded SESSION cell = %q, want %q then the id", cell, noRecordIDMarker) + } + case strings.Contains(cell, "live-1"): + if strings.Contains(cell, noRecordIDMarker) { + t.Errorf("recorded SESSION cell = %q, has the mark", cell) + } + default: + t.Errorf("SESSION cell %q names neither session in full", cell) + } + } +} + +// At TITLE's narrowest width the full mark leaves no room for the title, so the TITLE cell has +// the short mark and still some of the title. +func TestSessionTitleCell_NoRecordAtTheTitleFloor(t *testing.T) { + const title = "fix the build" + sessions := []session.SessionSummary{{ID: "off-1", Title: title, NoRecord: true}} + for width := 40; width <= 200; width++ { + m := fitModel(t, paneSessions, width, 40, nil) + m.sessions = sessions + m.rebuildSessionsTable() + rows := m.sessionsTbl.Rows() + if len(rows) != 1 { + t.Fatalf("width %d: got %d rows, want 1", width, len(rows)) + } + for _, c := range rows[0] { + if !strings.Contains(c, "fix") { + continue + } + // The first width that shows TITLE: the column is at its floor. + if lipgloss.Width(c) > sessionsTitleWidth { + t.Fatalf("width %d: TITLE cell %q wider than the floor %d", width, c, sessionsTitleWidth) + } + if !strings.HasPrefix(c, noRecordIDMarker+"fix") { + t.Fatalf("width %d: TITLE cell at the floor = %q, want %q and then some of the title", width, c, noRecordIDMarker) + } + return + } + } + t.Fatal("no width from 40 to 200 shows the TITLE column") +} + +// The session's header says it is not recorded, in full, also on a narrow terminal, where the +// list shows only the short mark and the header has to clip a long title; a recorded session's +// header does not. +func TestSessionHeader_SaysNotRecorded(t *testing.T) { + long := strings.Repeat("refactor the session archive writer ", 4) + for _, width := range []int{200, 60} { + m := fitModel(t, paneSessions, width, 40, nil) + m.sessions = []session.SessionSummary{ + {ID: "off-1", Title: long, NoRecord: true}, + {ID: "live-1", Title: long}, + } + if width == 60 && strings.Contains(m.sessionHeader("off-1", ""), strings.TrimSpace(long)) { + t.Fatalf("precondition: at %d columns the header should clip the title", width) + } + if got := m.sessionHeader("off-1", ""); !strings.Contains(got, "not recorded") { + t.Errorf("width %d: header = %q, want it to say not recorded", width, got) + } + if got := m.sessionHeader("live-1", ""); strings.Contains(got, "not recorded") { + t.Errorf("width %d: recorded session's header = %q, says not recorded", width, got) + } + } +} diff --git a/cmd/agentop/tui/session_metadata.go b/cmd/agentop/tui/session_metadata.go index aba47e6ff..d6cf25a33 100644 --- a/cmd/agentop/tui/session_metadata.go +++ b/cmd/agentop/tui/session_metadata.go @@ -184,6 +184,17 @@ func (m *model) parentSessionOf(id string) string { return "" } +// sessionNoRecord reports whether the server lists this session as not recorded (#1923). The +// same linear walk as servedTitle, for the same reason. +func (m *model) sessionNoRecord(id string) bool { + for _, s := range m.sessions { + if s.ID == id { + return s.NoRecord + } + } + return false +} + // HarvestFunc reads an agent's transcripts and returns what it learned, keyed by session id. // // A function on RunOptions rather than a direct call into core/observe/claude, so this diff --git a/cmd/agentop/tui/sessions_context.go b/cmd/agentop/tui/sessions_context.go index 1d21e985f..ad73e3248 100644 --- a/cmd/agentop/tui/sessions_context.go +++ b/cmd/agentop/tui/sessions_context.go @@ -158,3 +158,12 @@ const importedMarker = "(*) " // childMarker starts the TITLE cell of a session that another session started (#1991). const childMarker = "↳ " + +// noRecordMarker starts the TITLE cell of a session that asked not to be recorded (#1923): the +// archive keeps none of its events from then on. A phrase rather than a glyph, like cachedMarker, +// so it reads without a legend. +const noRecordMarker = "(not recorded) " + +// noRecordIDMarker is noRecordMarker's short form, for the SESSION cell when there is no TITLE +// column: the phrase would leave no room for the id. +const noRecordIDMarker = "⊘ " diff --git a/cmd/agentop/tui/sessions_pane.go b/cmd/agentop/tui/sessions_pane.go index d47d9d36a..6f29dea96 100644 --- a/cmd/agentop/tui/sessions_pane.go +++ b/cmd/agentop/tui/sessions_pane.go @@ -333,16 +333,16 @@ func (m *model) rebuildSessionsTable() { continue } b := newRowBuilder(q != "") - // An imported session's title starts with "(*) ", and a session that another session - // started with "↳ ". Plain text, not dim: the table cuts a cell by its bytes, and a - // style's escape bytes would mangle it (see cachedMarker). With no TITLE column, the - // SESSION cell has the mark. + // A session that asked not to be recorded starts with "(not recorded) ", an imported + // session's title with "(*) ", and a session that another session started with "↳ ". + // Plain text, not dim: the table cuts a cell by its bytes, and a style's escape bytes + // would mangle it (see cachedMarker). With no TITLE column, the SESSION cell has the + // mark, in its short form (sessionIDMark). mark := sessionMark(s) - markW := lipgloss.Width(mark) // columns, not bytes: "↳" is 3 bytes and 1 column - if showTitle || mark == "" { + if idMark := sessionIDMark(s); showTitle || idMark == "" { b.cut(sessionIDCell(s.ID, idW), func() string { return sessionIDSearch(s.ID) }) } else { - b.cut(mark+sessionIDCell(s.ID, idW-markW), func() string { return sessionIDSearch(s.ID) }) + b.cut(idMark+sessionIDCell(s.ID, idW-lipgloss.Width(idMark)), func() string { return sessionIDSearch(s.ID) }) } // s.Title straight off the summary, where sessionLabel reaches the same value by id // through m.servedTitle. Two routes, equal only because they read the same slice — @@ -351,7 +351,8 @@ func (m *model) rebuildSessionsTable() { // path has only an id and cannot avoid one. title := func() string { return mark + m.sessionTitleCell(s.ID, s.Title, noLimit) } if showTitle { - b.cut(mark+m.sessionTitleCell(s.ID, s.Title, titleW-markW), title) + cellMark := titleCellMark(s, titleW) + b.cut(cellMark+m.sessionTitleCell(s.ID, s.Title, titleW-lipgloss.Width(cellMark)), title) } else { // TITLE is the column a narrow terminal gives up; it is still searched. b.dropped(title) @@ -528,9 +529,13 @@ func (m *model) cachedOnlySessionIDs() []string { return out } -// sessionMark is the plain-text mark before a session's title: imported, or started by another -// session. With no TITLE column, the SESSION cell has it. +// sessionMark is the plain-text mark before a session's title: not recorded, imported, or started +// by another session, in that order: not recorded is the one that changes what is kept. With no +// TITLE column, the SESSION cell has it. func sessionMark(s session.SessionSummary) string { + if s.NoRecord { + return noRecordMarker + } if strings.HasPrefix(s.Source, coremodel.ImportedSourcePrefix) { return importedMarker } @@ -540,6 +545,32 @@ func sessionMark(s session.SessionSummary) string { return "" } +// titleRoomAfterMark is the fewest title columns a TITLE cell keeps after its mark. A TITLE +// column too narrow for the full mark and that many columns gets the short mark instead. +const titleRoomAfterMark = 4 + +// titleCellMark is the mark in a TITLE cell of titleW columns: sessionMark, or its short form +// (sessionIDMark) when the full mark would leave fewer than titleRoomAfterMark columns of title. +// At TITLE's floor, "(not recorded) " alone is wider than the column. Widths are in columns, +// not bytes: "↳" is 3 bytes and 1 column. +func titleCellMark(s session.SessionSummary, titleW int) string { + mark := sessionMark(s) + if titleW-lipgloss.Width(mark) < titleRoomAfterMark { + return sessionIDMark(s) + } + return mark +} + +// sessionIDMark is sessionMark in the SESSION cell, used when there is no TITLE column: the +// not-recorded mark is the short noRecordIDMarker there, so the id after it still fits. The +// session's header still says "not recorded" in full. +func sessionIDMark(s session.SessionSummary) string { + if s.NoRecord { + return noRecordIDMarker + } + return sessionMark(s) +} + // sessionsIDWidth is SESSION's width for the listed rows: the widest SESSION cell, an id counted // at sessionIDWidth, so a pending bucket's agent name is never cut (claude-code gives 11). It // reads the same filters as rebuildSessionsTable's two row loops. @@ -551,7 +582,7 @@ func (m *model) sessionsIDWidth(scope, project string, showTitle bool) int { } cell := sessionIDCell(s.ID, noLimit) if !showTitle { - cell = sessionMark(s) + cell + cell = sessionIDMark(s) + cell } w = max(w, lipgloss.Width(cell)) }