From b1bcf17c24612482bbfb493e07fdd27237aa52a4 Mon Sep 17 00:00:00 2001 From: Michal Jacovi Date: Fri, 20 Nov 2026 22:31:26 +0200 Subject: [PATCH 1/2] feat: Mark a session that is not recorded in agentop observe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A session that asked not to be recorded (#1923, X-Cortex-Record: off or agentop exec --no-record) now shows it, from the session list's noRecord field, live or archived: - Its title starts with "(not recorded) ", like the "(*) " of an imported session. It wins over the imported and child marks: it is the one that changes what is kept. - With no TITLE column, the SESSION cell has the short form "⊘ ", so the id after it still fits. - The session's header says " · not recorded", in full, at any width. Tests: the title prefix and its precedence, the narrow SESSION cell with the whole id after the mark, and the header at two widths. Part of #1923. Assisted-By: Claude (Anthropic AI) Signed-off-by: Michal Jacovi --- cmd/agentop/tui/app.go | 3 + cmd/agentop/tui/norecord_mark_test.go | 93 +++++++++++++++++++++++++++ cmd/agentop/tui/session_metadata.go | 11 ++++ cmd/agentop/tui/sessions_context.go | 9 +++ cmd/agentop/tui/sessions_pane.go | 33 +++++++--- 5 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 cmd/agentop/tui/norecord_mark_test.go 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..d0da8a5ee --- /dev/null +++ b/cmd/agentop/tui/norecord_mark_test.go @@ -0,0 +1,93 @@ +package tui + +import ( + "strings" + "testing" + + "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) + } + } +} + +// The session's header says it is not recorded, in full, also on a narrow terminal, where the +// list shows only the short mark; a recorded session's header does not. +func TestSessionHeader_SaysNotRecorded(t *testing.T) { + for _, width := range []int{200, 60} { + m := fitModel(t, paneSessions, width, 40, nil) + m.sessions = []session.SessionSummary{ + {ID: "off-1", Title: "fix the build", NoRecord: true}, + {ID: "live-1", Title: "fix the build"}, + } + 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..63be3779c 100644 --- a/cmd/agentop/tui/sessions_pane.go +++ b/cmd/agentop/tui/sessions_pane.go @@ -333,16 +333,17 @@ 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 — @@ -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,16 @@ func sessionMark(s session.SessionSummary) string { return "" } +// 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 +566,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)) } From 804234da63306d6236a9a48b06d6e62355263f95 Mon Sep 17 00:00:00 2001 From: Michal Jacovi Date: Sat, 21 Nov 2026 12:30:12 +0200 Subject: [PATCH 2/2] fix: Use the short not-recorded mark when TITLE is too narrow for the full one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the review of #2047: at TITLE's 11-column floor, "(not recorded) " is wider than the column, so the title vanished and the mark was cut. When the full mark would leave fewer than 4 title columns, the TITLE cell now uses the short "⊘ ", as the SESSION cell does. The search row keeps the full phrase. Tests: at the floor, the TITLE cell holds "⊘ " and then part of the title (without the fallback it fails); the header test uses a long title that has to be clipped at 60 columns. Part of #1923. Assisted-By: Claude (Anthropic AI) Signed-off-by: Michal Jacovi --- cmd/agentop/tui/norecord_mark_test.go | 43 +++++++++++++++++++++++++-- cmd/agentop/tui/sessions_pane.go | 20 +++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/cmd/agentop/tui/norecord_mark_test.go b/cmd/agentop/tui/norecord_mark_test.go index d0da8a5ee..3dabf7c2f 100644 --- a/cmd/agentop/tui/norecord_mark_test.go +++ b/cmd/agentop/tui/norecord_mark_test.go @@ -4,6 +4,8 @@ import ( "strings" "testing" + "github.com/charmbracelet/lipgloss" + "github.com/rossoctl/cortex/core/session" ) @@ -74,14 +76,49 @@ func TestSessionIDCell_NoRecordPrefixWithoutTitle(t *testing.T) { } } +// 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; a recorded session's header does not. +// 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: "fix the build", NoRecord: true}, - {ID: "live-1", Title: "fix the build"}, + {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) diff --git a/cmd/agentop/tui/sessions_pane.go b/cmd/agentop/tui/sessions_pane.go index 63be3779c..6f29dea96 100644 --- a/cmd/agentop/tui/sessions_pane.go +++ b/cmd/agentop/tui/sessions_pane.go @@ -339,7 +339,6 @@ func (m *model) rebuildSessionsTable() { // 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 idMark := sessionIDMark(s); showTitle || idMark == "" { b.cut(sessionIDCell(s.ID, idW), func() string { return sessionIDSearch(s.ID) }) } else { @@ -352,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) @@ -545,6 +545,22 @@ 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.