diff --git a/cli/internal/daemon/status.go b/cli/internal/daemon/status.go index 83d33921e..9d5a0b69a 100644 --- a/cli/internal/daemon/status.go +++ b/cli/internal/daemon/status.go @@ -22,6 +22,7 @@ const ( ) type AgentStatus struct { + Compaction *protocol.CompactionProgress Phase *AgentPhase RunID *string KernelJobs *int64 @@ -53,7 +54,7 @@ func statusValue(status protocol.SessionStatus, kernel protocol.Kernel) AgentSta case "compacting": phase = PhaseCompacting } - result := AgentStatus{Phase: &phase, Running: status.Phase != "idle", Idle: status.Phase == "idle", RunID: status.RunID} + result := AgentStatus{Phase: &phase, Running: status.Phase != "idle", Idle: status.Phase == "idle", RunID: status.RunID, Compaction: status.Compaction} result.ApplyKernel(kernel) return result } diff --git a/cli/internal/tui/chat_shell_test.go b/cli/internal/tui/chat_shell_test.go index 7773bd907..f08561527 100644 --- a/cli/internal/tui/chat_shell_test.go +++ b/cli/internal/tui/chat_shell_test.go @@ -4,13 +4,44 @@ import ( "errors" "strings" "testing" + "time" tea "charm.land/bubbletea/v2" "albedo/cli/internal/daemon" + "albedo/cli/internal/daemon/protocol" "github.com/charmbracelet/x/ansi" ) +func TestCompactionStatusShowsStageCountAndElapsed(t *testing.T) { + m := newTestChatModel(t, &daemon.Session{ID: "session", Workspace: "/work"}) + phase := daemon.PhaseCompacting + m.Status.Running, m.Status.Phase = true, &phase + total := int64(5) + m.Status.Compaction = &protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "summarizing", Completed: 2, Total: &total, StartedAt: time.Now().Add(-4 * time.Second).Format(time.RFC3339)} + got := m.statusLine() + if !strings.HasPrefix(got, "compacting · coding-lcm · summarizing chunks 2/5 · ") || !strings.HasSuffix(got, "s") { + t.Fatalf("status = %q", got) + } + m.Status.Compaction.Stage, m.Status.Compaction.Completed = "preparing", 0 + m.Status.Compaction.Total = nil + if got := m.statusLine(); strings.Contains(got, "0 completed") || !strings.Contains(got, "preparing history") { + t.Fatalf("preparing status = %q", got) + } + m.Status.Compaction.Stage, m.Status.Compaction.Completed, m.Status.Compaction.Total = "merging", 1, &total + if got := m.statusLine(); !strings.Contains(got, "combining summaries 1/5") { + t.Fatalf("merging status = %q", got) + } + m.Status.Compaction.Stage, m.Status.Compaction.Completed = "notes", 2 + if got := m.statusLine(); !strings.Contains(got, "rewriting notes 2/5") { + t.Fatalf("notes status = %q", got) + } + m.Status.Compaction = nil + if got := m.statusLine(); got != "compacting context" { + t.Fatalf("legacy status = %q", got) + } +} + func TestParseShellInputIsLiteralHumanPrefix(t *testing.T) { for _, tc := range []struct { input, command string diff --git a/cli/internal/tui/chat_view.go b/cli/internal/tui/chat_view.go index 817068bb1..384c50b9e 100644 --- a/cli/internal/tui/chat_view.go +++ b/cli/internal/tui/chat_view.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" @@ -136,6 +137,9 @@ func (m ChatModel) statusLine() string { if m.Stopping { return "stopping…" } + if m.Status.Running && m.Status.Phase != nil && *m.Status.Phase == daemon.PhaseCompacting { + return m.compactionStatusLine() + } // an idle session says nothing unless verbose: the transcript already // ends in the turn's signoff. if m.Stopped { @@ -201,6 +205,48 @@ func (m ChatModel) connecting() bool { return m.Status.Phase == nil && !m.Status.Running && !m.Status.Idle } +func (m ChatModel) compactionStatusLine() string { + progress := m.Status.Compaction + if progress == nil { + return "compacting context" + } + label := "compacting history" + shortStage := "history" + switch progress.Stage { + case "preparing": + label, shortStage = "preparing history", "preparing" + case "summarizing": + label, shortStage = "summarizing chunks", "summarizing" + case "merging": + label, shortStage = "combining summaries", "combining" + case "notes": + label, shortStage = "rewriting notes", "notes" + } + count := "" + if progress.Total != nil && (progress.Stage == "summarizing" || *progress.Total > 1) { + count = fmt.Sprintf("%d/%d", progress.Completed, *progress.Total) + } else if progress.Stage == "summarizing" && progress.Completed > 0 { + count = fmt.Sprintf("%d completed", progress.Completed) + } + if count != "" { + if m.Width > 0 && m.Width <= 80 { + label = shortStage + } + label += " " + count + } + if started, err := time.Parse(time.RFC3339, progress.StartedAt); err == nil { + elapsed := time.Since(started).Milliseconds() + if elapsed >= 0 { + label += " · " + formatElapsed(elapsed) + } + } + title := "compacting" + if progress.Strategy != "" { + title += " · " + progress.Strategy + } + return title + " · " + label +} + // phaseMood is the face class for the phase statusLine names. func (m ChatModel) phaseMood() mood { switch { @@ -395,17 +441,9 @@ func (m *ChatModel) View() string { // (header, status, chips, footer) is cheap enough to build every time, and // building it means it cannot go stale. type frameCache struct { - sidebar sidebarBlock - sidebarKey sidebarKey - sidebarReady bool - - body []string - bodyKey bodyKey - bodyReady bool - - composer []string - composerKey composerKey - composerReady bool + sidebar sidebarBlock + body []string + composer []string // rows is the padded frame as last drawn and content the string handed to // Bubble Tea, so a frame that changed nothing is not joined again. @@ -413,6 +451,12 @@ type frameCache struct { content string // scratch is the row slice the next frame is assembled into. scratch []string + + sidebarKey sidebarKey + bodyKey bodyKey + composerKey composerKey + + sidebarReady, bodyReady, composerReady bool } // sidebarBlock is the glance column: the rows it draws, the glances that did diff --git a/cli/internal/tui/shot_chat_test.go b/cli/internal/tui/shot_chat_test.go index 70bf5471a..5ab2b5301 100644 --- a/cli/internal/tui/shot_chat_test.go +++ b/cli/internal/tui/shot_chat_test.go @@ -3,8 +3,10 @@ package tui import ( "fmt" "testing" + "time" "albedo/cli/internal/daemon" + "albedo/cli/internal/daemon/protocol" ) func init() { @@ -55,6 +57,22 @@ func init() { shotState{name: "settled-cjk-title", view: func(w, h int) string { return renderSettledChatShot("東京e\u0301界のファイルを検索する", "# 東京e\u0301界のファイルを検索する\nprint('done')", w, h) }}, + shotState{name: "compaction-preparing", view: func(w, h int) string { + return renderCompactionChatShot(&protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "preparing"}, w, h) + }}, + shotState{name: "compaction-summarizing-start", view: func(w, h int) string { + return renderCompactionChatShot(&protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "summarizing", Total: new(int64(5))}, w, h) + }}, + shotState{name: "compaction-summarizing-partial", view: func(w, h int) string { + return renderCompactionChatShot(&protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "summarizing", Completed: 2, Total: new(int64(5))}, w, h) + }}, + shotState{name: "compaction-merging-partial", view: func(w, h int) string { + return renderCompactionChatShot(&protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "merging", Completed: 1, Total: new(int64(3))}, w, h) + }}, + shotState{name: "compaction-notes-partial", view: func(w, h int) string { + return renderCompactionChatShot(&protocol.CompactionProgress{Strategy: "coding-lcm", Stage: "notes", Completed: 1, Total: new(int64(2))}, w, h) + }}, + shotState{name: "compaction-legacy", view: func(w, h int) string { return renderCompactionChatShot(nil, w, h) }}, shotState{name: "fast-off", view: func(w, h int) string { return renderFastChatShot(false, w, h) }}, shotState{name: "fast-on", view: func(w, h int) string { return renderFastChatShot(true, w, h) }}, shotState{name: "direnv-blocked", view: renderDirenvChatShot}, @@ -137,6 +155,20 @@ func renderSettledChatShot(title, code string, width, height int) string { return m.View() } +func renderCompactionChatShot(progress *protocol.CompactionProgress, width, height int) string { + conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) + session := &daemon.Session{ID: "s", Workspace: "/work", Model: "claude-opus-5-5"} + m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) + phase := daemon.PhaseCompacting + m.Status.Running, m.Status.Phase = true, &phase + if progress != nil { + progress.StartedAt = time.Now().Add(-67 * time.Second).Format(time.RFC3339) + } + m.Status.Compaction = progress + m.SetSize(width, height) + return m.View() +} + func renderFastFaceShot(index, tick, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/work", Model: "claude-opus-5-5", Fast: true} diff --git a/robot-docs/tui.md b/robot-docs/tui.md index 5eb62ffd4..067a99da4 100644 --- a/robot-docs/tui.md +++ b/robot-docs/tui.md @@ -36,6 +36,10 @@ not on it, on purpose: the chat (a transcript is not a list) and the agents canv a screen keeps the data it draws rather than a copy of it. the session listing is one `[]daemon.Session` the root model owns (`AppModel.Sessions`); the sessions screen holds that slice by reference (`SessionViewer.raw`) and orders pointers into it (`order`), so no part of the client carries a second copy of the records. the rows the screen draws — the order, its picker items, the grouped ranges — are built by `SessionViewer.ensure` when the screen opens (`Init`) or is drawn (`View`, `Update`), so a listing refresh in a chat that never opens it costs one slice header. once the rows exist they are kept current across refreshes, and the highlight and the search survive them. `shot_sessions_test.go` renders every state, and its model opens the screen before a state pokes at it, the way the client does. +## live compaction status + +While the daemon reports live compaction progress, chat keeps its compacting phase visible through helper model calls and shows the current stage, that stage’s count when known, and elapsed time. Older daemons without progress retain the `compacting context` status. Progress is not added to the transcript. + ## window title the client can name its terminal window after the active session (`window_title.go`). it is off by default, since session names can be private and a title shows in taskbars, tmux status lines and screen shares. `ALBEDO_WINDOW_TITLE` is read once at startup, ignoring case and surrounding spaces: `name` (or `on`, `1`, `true`, `yes`) sets ` — albedo`, or `albedo` with no session or an unnamed one; `id` also appends ` []` so a window manager script can focus the window that already holds a session instead of opening another. anything else, or unset, leaves the title alone. Bubble Tea clears a title it set on exit. names are untrusted: escape sequences, control and format runes (bidi overrides included) are dropped and the name is capped at 120 runes; the id is never cut.