Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151package tui
import ( "albedo/cli/internal/daemon" "errors" "fmt"
tea "charm.land/bubbletea/v2")
func contextSnapshot() *daemon.ContextSnapshot { window := 200000 return &daemon.ContextSnapshot{ State: "ready", Provider: "claude", Model: "claude-sonnet", Protocol: "messages", ContextWindowTokens: &window, Sections: []daemon.ContextSection{ {ID: "system", Label: "System instructions", Kind: "system", Source: "AGENTS.md + workspace", ItemCount: 3, ByteCount: 9120, Pages: 1, Preview: "You are albedo, a coding agent..."}, {ID: "tools", Label: "Tool definitions", Kind: "tools", Source: "extensions", ItemCount: 14, ByteCount: 22040, Pages: 2}, {ID: "history", Label: "Conversation history", Kind: "history", Source: "transcript", ItemCount: 58, ByteCount: 184320, Pages: 9, Preview: "user: add a retry to the webhook sender"}, {ID: "input", Label: "Current input", Kind: "input", Source: "this turn", ItemCount: 1, ByteCount: 212}, }, }}
// contextModel is the inspector with a ready snapshot, sized to the shot.func contextModel(width, height int) ContextInspectorModel { m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(contextSnapshotLoadedMsg{Gen: m.Generation, Snapshot: contextSnapshot()}) return m}
func contextShot(keys ...tea.Msg) func(width, height int) string { return func(width, height int) string { m := contextModel(width, height) for _, key := range keys { m, _ = m.Update(key) } return m.View() }}
// contextReader opens the history section with its first page loaded.func contextReader(width, height int, page daemon.ContextPage) ContextInspectorModel { m := contextModel(width, height) m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDown}) m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) m, _ = m.Update(contextPageLoadedMsg{Gen: m.Generation, SectionID: "history", Data: &page}) return m}
func historyPage() daemon.ContextPage { content := "user: add a retry to the webhook sender\n" for range 40 { content += "assistant: looked at internal/hooks/sender.go and the queue it drains into\n" } return daemon.ContextPage{Content: content, Pages: 9}}
func init() { enter := tea.KeyPressMsg{Code: tea.KeyEnter} down := tea.KeyPressMsg{Code: tea.KeyDown} registerShots("context", shotState{"list", contextShot(down, down)}, shotState{"no-content", contextShot(down, down, down)}, shotState{"filtering", contextShot(shotTyped("hist")...)}, shotState{"no-match", contextShot(shotTyped("zzz")...)}, shotState{"reader", func(width, height int) string { return contextReader(width, height, historyPage()).View() }}, shotState{"reader-scrolled", func(width, height int) string { m := contextReader(width, height, historyPage()) m.View() for range 12 { m, _ = m.Update(down) } return m.View() }}, shotState{"reader-loading", func(width, height int) string { m := contextModel(width, height) m, _ = m.Update(down) m, _ = m.Update(down) m, _ = m.Update(enter) return m.View() }}, shotState{"reader-failed", func(width, height int) string { m := contextModel(width, height) m, _ = m.Update(down) m, _ = m.Update(down) m, _ = m.Update(enter) m, _ = m.Update(contextPageLoadedMsg{Gen: m.Generation, SectionID: "history", Err: errors.New("page 1 is no longer available")}) return m.View() }}, shotState{"reader-omitted", func(width, height int) string { page := historyPage() page.Omitted = "earlier turns were dropped from this request" return contextReader(width, height, page).View() }}, shotState{"long-list", func(width, height int) string { snapshot := contextSnapshot() history := snapshot.Sections[2] snapshot.Sections = snapshot.Sections[:2] for turn := range 14 { section := history section.ID, section.Label = fmt.Sprintf("turn-%d", turn), fmt.Sprintf("Turn %d", turn+1) section.ItemCount, section.ByteCount, section.Pages = 4, 13000, 1 snapshot.Sections = append(snapshot.Sections, section) } m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(contextSnapshotLoadedMsg{Gen: m.Generation, Snapshot: snapshot}) for range 12 { m, _ = m.Update(down) } return m.View() }}, shotState{"reader-next-page", func(width, height int) string { m := contextReader(width, height, historyPage()) m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyRight}) page := historyPage() page.Page = 1 m, _ = m.Update(contextPageLoadedMsg{Gen: m.Generation, SectionID: "history", Page: 1, Data: &page}) return m.View() }}, shotState{"pending", func(width, height int) string { m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(contextSnapshotLoadedMsg{Gen: m.Generation, Snapshot: &daemon.ContextSnapshot{State: "pending", Reason: "the session has not sent a request yet"}}) return m.View() }}, shotState{"empty", func(width, height int) string { m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(contextSnapshotLoadedMsg{Gen: m.Generation, Snapshot: &daemon.ContextSnapshot{State: "ready", Provider: "claude", Model: "claude-sonnet"}}) return m.View() }}, shotState{"loading", func(width, height int) string { m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) return m.View() }}, shotState{"load-failed", func(width, height int) string { m := NewContextInspectorModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(contextSnapshotLoadedMsg{Gen: m.Generation, Err: errors.New("daemon connection unavailable")}) return m.View() }}, )}