GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(tui): richer /resume session browser (#1047) · Twigpine/zero@2f53117

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal/tui
    • command_center.go
    • model_test.go
    • mouse.go
    • picker.go
    • rendering_lime_test.go
    • session.go
    • session_test.go
    • view.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/tui/command_center.go‎

Copy file name to clipboardExpand all lines: internal/tui/command_center.go
+29-10Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strconv"
99
"strings"
1010
"time"
11+
"unicode"
1112

1213
tea "charm.land/bubbletea/v2"
1314

@@ -365,17 +366,30 @@ func (defaultModelSwitchCompactionPolicy) BeforeModelSwitch(request modelSwitchC
365366

366367
var modelSwitchCompactionGuard modelSwitchCompactionPolicy = defaultModelSwitchCompactionPolicy{}
367368

368-
// sanitizeCardField strips the card protocol's separator bytes from
369-
// user-controlled values (titles can legally contain anything --session-title
370-
// was given), so a hostile or accidental \x1f / newline cannot shift fields
371-
// or leak control characters into the transcript.
369+
// sanitizeCardField strips the card protocol's separator byte and every
370+
// control rune from user-controlled values (titles can legally contain
371+
// anything --session-title was given, and a directory name can legally
372+
// contain an ESC byte on Unix). Line separators and tabs become spaces so
373+
// words stay apart; the remaining controls — ESC/CSI/OSC initiators, BEL, BS,
374+
// VT, NEL, NUL — are dropped outright, since any of them can repaint the
375+
// terminal or shift cells when the value lands in a rendered row.
372376
func sanitizeCardField(value string) string {
373-
value = strings.ReplaceAll(value, sessionsCardFieldSep, " ")
374-
value = strings.ReplaceAll(value, "\n", " ")
375-
return strings.ReplaceAll(value, "\x00", "")
377+
var out strings.Builder
378+
for _, r := range value {
379+
switch {
380+
case r == '\x1f' || r == '\n' || r == '\r' || r == '\t':
381+
out.WriteRune(' ')
382+
case unicode.IsControl(r):
383+
default:
384+
out.WriteRune(r)
385+
}
386+
}
387+
return out.String()
376388
}
377389

378-
// relativeAge renders an RFC3339 timestamp as a short age ("2h ago"); ""
390+
// relativeAge renders an RFC3339 timestamp as a short age ("2h ago"), falling
391+
// back to the month/day this year and the bare date for sessions older than a
392+
// month, so deep history reads as a calendar date rather than "400d ago"; ""
379393
// when the timestamp does not parse, so the card simply omits it.
380394
func relativeAge(timestamp string, now time.Time) string {
381395
parsed, err := time.Parse(time.RFC3339, strings.TrimSpace(timestamp))
@@ -385,14 +399,19 @@ func relativeAge(timestamp string, now time.Time) string {
385399
age := now.Sub(parsed)
386400
switch {
387401
case age < time.Minute:
388-
return "just now"
402+
return "now"
389403
case age < time.Hour:
390404
return fmt.Sprintf("%dm ago", int(age.Minutes()))
391405
case age < 24*time.Hour:
392406
return fmt.Sprintf("%dh ago", int(age.Hours()))
393-
default:
407+
case age <= 30*24*time.Hour:
394408
return fmt.Sprintf("%dd ago", int(age.Hours()/24))
395409
}
410+
parsed, now = parsed.Local(), now.Local()
411+
if parsed.Year() == now.Year() {
412+
return parsed.Format("Jan _2")
413+
}
414+
return parsed.Format("2006-01-02")
396415
}
397416

398417
// handleModelCommand applies a model switch against the ACTIVE provider (the
Collapse file

‎internal/tui/model_test.go‎

Copy file name to clipboardExpand all lines: internal/tui/model_test.go
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,16 +1087,16 @@ func TestResumeCommandListsRecentSessions(t *testing.T) {
10871087
}
10881088

10891089
func TestSessionPickerLabelAlignsTitles(t *testing.T) {
1090-
today := sessionPickerLabel("20:47:50", "Today title")
1091-
older := sessionPickerLabel("Jul 24 10:47", "Older title")
1090+
recent := sessionPickerLabel("2h ago", "Recent title")
1091+
older := sessionPickerLabel("2006-01-02", "Older title")
10921092

1093-
todayColumn := strings.Index(today, "Today title")
1093+
recentColumn := strings.Index(recent, "Recent title")
10941094
olderColumn := strings.Index(older, "Older title")
1095-
if todayColumn < 0 || olderColumn < 0 {
1096-
t.Fatalf("sessionPickerLabel omitted a title: today=%q older=%q", today, older)
1095+
if recentColumn < 0 || olderColumn < 0 {
1096+
t.Fatalf("sessionPickerLabel omitted a title: recent=%q older=%q", recent, older)
10971097
}
1098-
if todayColumn != olderColumn {
1099-
t.Fatalf("title columns differ: today=%d (%q), older=%d (%q)", todayColumn, today, olderColumn, older)
1098+
if recentColumn != olderColumn {
1099+
t.Fatalf("title columns differ: recent=%d (%q), older=%d (%q)", recentColumn, recent, olderColumn, older)
11001100
}
11011101
}
11021102

Collapse file

‎internal/tui/mouse.go‎

Copy file name to clipboardExpand all lines: internal/tui/mouse.go
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,11 @@ func (m *model) selectGenericPickerAtMouse(msg tea.MouseMsg) (mouseSelectionTarg
513513
return mouseSelectionTarget{}, false
514514
}
515515
}
516-
maxVisible := minInt(pickerOverlayMaxVisible, len(m.picker.items))
516+
maxVisible := pickerMaxVisible(m.picker, width)
517517
selected := clampInt(m.picker.selected, 0, len(m.picker.items)-1)
518518
start := selectableListStart(len(m.picker.items), maxVisible, selected)
519519
visible := m.picker.items[start : start+maxVisible]
520+
details := pickerShowsDetails(m.picker, width)
520521
// y=0 titled top border, y=1 search line, y=2 separator; rows begin at y=3.
521522
line := 3
522523
lastGroup := ""
@@ -528,12 +529,18 @@ func (m *model) selectGenericPickerAtMouse(msg tea.MouseMsg) (mouseSelectionTarg
528529
line++
529530
lastGroup = item.Group
530531
}
531-
if hit.y == line {
532+
// A rendered detail line belongs to its item: a click anywhere on the
533+
// two-line block selects the same row.
534+
rowLines := 1
535+
if details && item.Detail != "" {
536+
rowLines = 2
537+
}
538+
if hit.y >= line && hit.y < line+rowLines {
532539
index := start + offset
533540
m.picker.selected = index
534541
return mouseSelectionTarget{Scope: "picker", Kind: int(m.picker.kind), Value: item.Value, Index: index}, true
535542
}
536-
line++
543+
line += rowLines
537544
}
538545
return mouseSelectionTarget{}, false
539546
}
Collapse file

‎internal/tui/picker.go‎

Copy file name to clipboardExpand all lines: internal/tui/picker.go
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ const (
3434
// pickerItem is one selectable row: Label is shown, Value is passed to the
3535
// underlying command handler when chosen. Meta is the optional right-aligned
3636
// readout (ctx window · capabilities); the dot flags mark provider locality
37-
// for model rows (accent = remote, blue = local).
37+
// for model rows (accent = remote, blue = local). Detail is an optional faint
38+
// second line under the row (project · model · size for sessions), rendered
39+
// only on medium-and-wider tiers where the extra line reads cleanly.
3840
type pickerItem struct {
3941
Group string
4042
Label string
4143
Value string
4244
Meta string
45+
Detail string
4346
Provider string // display tag (catalog id / locality)
4447
// OwnerProvider is the saved provider profile name a model belongs to, so the
4548
// /model picker can switch providers when a model from a non-active provider is
@@ -167,7 +170,7 @@ func (p *commandPicker) applyQuery() {
167170
// the joined haystack, and a fuzzy subsequence is the last-resort match.
168171
func scorePickerItem(item pickerItem, query string) (int, bool) {
169172
label := strings.ToLower(item.Label)
170-
hay := strings.ToLower(strings.Join([]string{item.Group, item.Label, item.Value, item.Meta}, " "))
173+
hay := strings.ToLower(strings.Join([]string{item.Group, item.Label, item.Value, item.Meta, item.Detail}, " "))
171174
switch {
172175
case label == query:
173176
return 0, true
Collapse file

‎internal/tui/rendering_lime_test.go‎

Copy file name to clipboardExpand all lines: internal/tui/rendering_lime_test.go
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88
"time"
9+
"unicode"
910

1011
"charm.land/lipgloss/v2"
1112
"github.com/charmbracelet/colorprofile"
@@ -1973,8 +1974,27 @@ func TestPermissionCollapseIsRunScoped(t *testing.T) {
19731974
}
19741975

19751976
func TestSessionsCardFieldsAreSanitized(t *testing.T) {
1976-
if got := sanitizeCardField("evil\x1ftitle\nwith\x00bytes"); strings.ContainsAny(got, "\x1f\n\x00") {
1977-
t.Fatalf("sanitizeCardField left separator bytes: %q", got)
1977+
inputs := []string{
1978+
"evil\x1ftitle",
1979+
"line\nbreak",
1980+
"line\rbreak",
1981+
"nul\x00byte",
1982+
"esc\x1b[31mred",
1983+
"csi\x1b[2J\x1b[H",
1984+
"osc\x1b]0;pwned\a",
1985+
"bell\aring",
1986+
"back\bspace",
1987+
"tab\there",
1988+
"vert\vtab",
1989+
"nel\u0085here",
1990+
}
1991+
for _, input := range inputs {
1992+
got := sanitizeCardField(input)
1993+
for _, r := range got {
1994+
if unicode.IsControl(r) {
1995+
t.Fatalf("sanitizeCardField(%q) left control rune %q in %q", input, r, got)
1996+
}
1997+
}
19781998
}
19791999
}
19802000

Collapse file

‎internal/tui/session.go‎

Copy file name to clipboardExpand all lines: internal/tui/session.go
+45-27Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"runtime"
1010
"strings"
11-
"time"
1211

1312
"github.com/Gitlawb/zero/internal/agent"
1413
"github.com/Gitlawb/zero/internal/execution"
@@ -360,28 +359,10 @@ func (m model) formatResumeSummary(session sessions.Metadata, eventCount int) st
360359
})
361360
}
362361

363-
// sessionWhen formats a session's RFC3339 timestamp for the picker: a precise
364-
// clock time (with seconds) for today so same-minute sessions stay distinct, the
365-
// month/day and time earlier this year, else the date. Empty on a parse error.
366-
func sessionWhen(timestamp string, now time.Time) string {
367-
parsed, err := time.Parse(time.RFC3339, strings.TrimSpace(timestamp))
368-
if err != nil {
369-
return ""
370-
}
371-
parsed, now = parsed.Local(), now.Local()
372-
switch {
373-
case parsed.Year() == now.Year() && parsed.YearDay() == now.YearDay():
374-
return parsed.Format("15:04:05")
375-
case parsed.Year() == now.Year():
376-
return parsed.Format("Jan _2 15:04")
377-
default:
378-
return parsed.Format("2006-01-02")
379-
}
380-
}
381-
382362
// newSessionPicker builds the interactive /resume picker (mirrors /model & /provider):
383-
// one row per resumable session — title (Label) + id and relative age (Meta). Returns
384-
// nil when there are no resumable sessions so the caller falls back to the text path.
363+
// one row per resumable session — age + title (Label), session id (Value), and a
364+
// project/model/size line (Detail). Returns nil when there are no resumable
365+
// sessions so the caller falls back to the text path.
385366
func (m model) newSessionPicker() *commandPicker {
386367
if m.sessionStore == nil {
387368
return nil
@@ -414,13 +395,17 @@ func (m model) newSessionPicker() *commandPicker {
414395
// Lead with a fixed-width timestamp so titles form one scannable column.
415396
// The raw id remains the selection/search value but stays out of the row:
416397
// rendering it consumed half the picker and truncated the useful title.
417-
label := displayValue(meta.Title, "untitled")
418-
if when := sessionWhen(meta.UpdatedAt, now); when != "" {
398+
// Session metadata is persisted, user-controlled text — a title from
399+
// --session-title or /rename can legally contain newlines, which would
400+
// break the picker's fixed row geometry.
401+
label := displayValue(sanitizeCardField(meta.Title), "untitled")
402+
if when := relativeAge(meta.UpdatedAt, now); when != "" {
419403
label = sessionPickerLabel(when, label)
420404
}
421405
items = append(items, pickerItem{
422-
Label: label,
423-
Value: meta.SessionID,
406+
Label: label,
407+
Value: meta.SessionID,
408+
Detail: m.sessionPickerDetail(meta),
424409
})
425410
}
426411
if len(items) == 0 {
@@ -435,12 +420,45 @@ func (m model) newSessionPicker() *commandPicker {
435420
}
436421
}
437422

438-
const sessionPickerTimeWidth = len("Jan 02 15:04")
423+
const sessionPickerTimeWidth = len("2006-01-02")
439424

440425
func sessionPickerLabel(when, title string) string {
441426
return fmt.Sprintf("%-*s %s", sessionPickerTimeWidth, when, title)
442427
}
443428

429+
// sessionPickerDetail composes the faint second line under a /resume row:
430+
// the session's project directory (~/-contracted), the model it ran on, and a
431+
// short status chip when the session is not a plain mainline run (forks,
432+
// tagged sessions such as btw side-chats). Missing fields are simply omitted —
433+
// the picker is workspace-scoped, so the project column is a confirmation,
434+
// not a disambiguator.
435+
func (m model) sessionPickerDetail(meta sessions.Metadata) string {
436+
parts := make([]string, 0, 3)
437+
if project := displayPath(m.cwd, meta.Cwd); project != "" {
438+
parts = append(parts, project)
439+
}
440+
if modelID := strings.TrimSpace(meta.ModelID); modelID != "" {
441+
parts = append(parts, modelID)
442+
}
443+
if status := sessionPickerStatus(meta); status != "" {
444+
parts = append(parts, status)
445+
}
446+
return sanitizeCardField(strings.Join(parts, " · "))
447+
}
448+
449+
// sessionPickerStatus is the concise status chip for a /resume row: an
450+
// explicit tag when the session carries one, otherwise a marker for forked
451+
// sessions. Plain mainline sessions get none — their shape is the default.
452+
func sessionPickerStatus(meta sessions.Metadata) string {
453+
if tag := strings.TrimSpace(meta.Tag); tag != "" {
454+
return tag
455+
}
456+
if meta.SessionKind == sessions.SessionKindFork {
457+
return "fork"
458+
}
459+
return ""
460+
}
461+
444462
// sessionHasResumableContent reports whether a session has anything worth
445463
// resuming: a tool call/result, or a non-user message with real content (not the
446464
// no-output guardrail stop). Empty/failed runs return false and are hidden from

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.