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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147package tui
import ( "errors"
"albedo/cli/internal/daemon"
tea "charm.land/bubbletea/v2")
// agentsShotModel is agentsFixture's tree without a *testing.T, for the gallery.func agentsShotModel(width, height int) AgentsViewModel { m := NewAgentsViewModel(nil, "lead") m.Gen = 1 m.streamReady = true m.SetSize(width, height) lead, coder := "lead", "coder" m, _ = m.Update(agentsSnapshotMsg{Gen: 1, Root: "lead", Nodes: []daemon.AgentNode{ {Session: daemon.Session{ID: "lead", Title: "lead", Model: "gpt-6-luna"}, Name: "lead", Running: true}, {Session: daemon.Session{ID: "scout", Model: "gpt-6-luna"}, Parent: &lead, Name: "scout", Depth: 1}, {Session: daemon.Session{ID: "coder", Model: "gpt-6-luna"}, Parent: &lead, Name: "coder", Depth: 1, Running: true}, {Session: daemon.Session{ID: "tests", Model: "gpt-6-luna"}, Parent: &coder, Name: "tests", Depth: 2}, }}) return m}
// agentsFamilyShot is a family with working, idle and closed agents: four// closed leaves under lead and two under coder fold, then keys are pressed.func agentsFamilyShot(selected string, keys ...tea.KeyPressMsg) func(width, height int) string { return func(width, height int) string { m := NewAgentsViewModel(nil, "lead") m.Gen = 1 m.streamReady = true m.SetSize(width, height) at := func(minute int) *int64 { ms := int64(1_792_000_000_000 + minute*60_000) return &ms } node := func(id, parent string, minute int, running, closed bool) daemon.AgentNode { n := daemon.AgentNode{Session: daemon.Session{ID: id, Model: "gpt-5.6-luna", CreatedAt: at(minute), ActivityAt: at(minute + 5)}, Name: id, Depth: 1, Running: running, Closed: closed} switch parent { case "": n.Depth = 0 case "coder": n.Depth = 2 } if parent != "" { n.Parent = &parent } return n } m, _ = m.Update(agentsSnapshotMsg{Gen: 1, Root: "lead", Nodes: []daemon.AgentNode{ node("lead", "", 0, true, false), node("scout", "lead", 1, false, false), node("coder", "lead", 2, true, false), node("review", "lead", 3, false, false), node("audit", "lead", 4, false, true), node("bench", "lead", 5, false, true), node("docs", "lead", 6, false, true), node("lint", "lead", 7, false, true), node("tests", "coder", 8, true, false), node("fixture", "coder", 9, false, true), node("probe", "coder", 10, false, true), }}) m.selected = selected for _, key := range keys { m, _ = m.Update(key) } return m.View() }}
// findKeys opens the find and types text.func findKeys(text string) []tea.KeyPressMsg { keys := []tea.KeyPressMsg{{Code: 'f', Mod: tea.ModCtrl}} for _, r := range text { keys = append(keys, tea.KeyPressMsg{Code: r, Text: string(r)}) } return keys}
// agentsDeleteShot opens the delete question on an agent, then presses keys.func agentsDeleteShot(id string, keys ...tea.KeyPressMsg) func(width, height int) string { return func(width, height int) string { m := agentsShotModel(width, height) m.selected = id m, _ = m.key(tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl}) for _, key := range keys { m, _ = m.key(key) } return m.View() }}
// agentsShot draws the tree after setup.func agentsShot(setup func(*AgentsViewModel)) func(width, height int) string { return func(width, height int) string { m := agentsShotModel(width, height) setup(&m) return m.View() }}
// agentsBare is the view before its first snapshot, after msgs.func agentsBare(msgs ...tea.Msg) func(width, height int) string { return func(width, height int) string { m := NewAgentsViewModel(nil, "lead") m.Gen = 1 m.streamReady = true m.SetSize(width, height) for _, msg := range msgs { m, _ = m.Update(msg) } return m.View() }}
func init() { enter := tea.KeyPressMsg{Code: tea.KeyEnter} registerShots("agents", shotState{"graph", agentsShot(func(m *AgentsViewModel) { m.selected = "coder" })}, shotState{"family-folded", agentsFamilyShot("coder")}, shotState{"fold-selected", agentsFamilyShot(agentsFoldPrefix + "lead")}, shotState{"fold-expanded", agentsFamilyShot(agentsFoldPrefix+"lead", tea.KeyPressMsg{Code: tea.KeyRight})}, shotState{"find-folded", agentsFamilyShot("coder", findKeys("bench")...)}, shotState{"find-none", agentsFamilyShot("coder", findKeys("zzz")...)}, shotState{"root-selected", agentsShot(func(m *AgentsViewModel) { m.selected = "lead" })}, shotState{"no-agents", agentsBare(agentsSnapshotMsg{Gen: 1, Root: "lead", Nodes: []daemon.AgentNode{ {Session: daemon.Session{ID: "lead", Title: "lead", Model: "gpt-6-luna"}, Name: "lead"}, }})}, shotState{"loading", agentsBare()}, shotState{"load-failed", agentsBare(agentsSnapshotMsg{Gen: 1, Err: errors.New("daemon connection unavailable")})}, shotState{"delete-confirm", agentsDeleteShot("coder")}, shotState{"delete-leaf-confirm", agentsDeleteShot("scout")}, shotState{"delete-kept", agentsDeleteShot("coder", tea.KeyPressMsg{Code: tea.KeyEscape})}, shotState{"deleting", agentsDeleteShot("coder", enter)}, shotState{"delete-failed", func(width, height int) string { m := agentsShotModel(width, height) m.selected = "coder" m, _ = m.key(tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl}) m, _ = m.key(enter) m, _ = m.Update(agentsSentMsg{Gen: m.viewGen, Action: "delete coder", Err: errors.New("coder changed since the view loaded it")}) return m.View() }}, )}