// The /cd question box and the moved session's banner and list row in every // state a person sees, for the shot gallery. package tui import ( "errors" "time" "albedo/cli/internal/daemon" tea "charm.land/bubbletea/v2" ) const cdShotTarget = "vassago:/home/ana/fleet" func init() { bytes := int64(48_600_000) ready := daemon.TransferPreflight{Available: true, Host: "vassago", Home: "/home/ana/.albedo", Bytes: &bytes, Sessions: []string{"a", "b"}} refused := daemon.TransferPreflight{Reason: "vassago runs transfer protocol 1, this daemon 2; update albedo on vassago", Host: "vassago"} pickOne := cdShotPicks(bytes, 1) pickTwo := cdShotPicks(bytes, 2) noProfile := daemon.TransferPreflight{Reason: "vassago has no claude profile: sign in there first", Host: "vassago", Sessions: []string{"a"}, RunsThere: []daemon.RunsThere{{SessionID: "a", Name: "fleet rollout", Profile: "claude", Model: "claude-opus-5-5", Reason: "vassago has no claude profile: sign in there first"}}} registerShots("cd", shotState{"checking", cdShot(func(q *cdQuestion) {})}, shotState{"available", cdShot(func(q *cdQuestion) { q.checked(ready, nil) })}, shotState{"available-no", cdShot(func(q *cdQuestion) { q.checked(ready, nil) q.key(tea.KeyPressMsg{Code: tea.KeyDown}) })}, shotState{"unavailable", cdShot(func(q *cdQuestion) { q.checked(refused, nil) })}, shotState{"pick-one", cdShot(func(q *cdQuestion) { q.checked(pickOne, nil) })}, shotState{"pick-one-second", cdShot(func(q *cdQuestion) { q.checked(pickOne, nil) q.key(keyDown) q.key(keyDown) q.key(keyEnter) })}, shotState{"pick-two", cdShot(func(q *cdQuestion) { q.checked(pickTwo, nil) q.key(keyUp) q.key(keyUp) })}, shotState{"pick-none-available", cdShot(func(q *cdQuestion) { q.checked(noProfile, nil) })}, shotState{"unreachable", cdShot(func(q *cdQuestion) { q.checked(daemon.TransferPreflight{}, errors.New("could not check vassago: ssh: connect to host vassago port 22: Operation timed out")) })}, shotState{"moving", cdShot(func(q *cdQuestion) { q.checked(ready, nil) q.phase, q.move = cdMoving, daemon.Move{State: "copying", BytesDone: 20_100_000, BytesTotal: bytes} })}, shotState{"attaching", cdShot(func(q *cdQuestion) { q.checked(ready, nil) q.phase = cdAttaching })}, shotState{"failed", cdShot(func(q *cdQuestion) { q.checked(ready, nil) q.phase, q.failure = cdFailed, "vassago refused the copy: 507 transfer_space, needs 1.1 GiB, has 400 MiB" })}, shotState{"hidden-progress", cdShot(func(q *cdQuestion) { q.checked(ready, nil) q.phase, q.hidden, q.move = cdMoving, true, daemon.Move{State: "copying", BytesDone: 20_100_000, BytesTotal: bytes} })}, shotState{"moved-banner", movedChatShot("", false)}, shotState{"moved-attaching", movedChatShot("opening it on vassago…", false)}, shotState{"moved-attach-failed", movedChatShot("could not open it on vassago (albedo home /home/ana/.albedo): the daemon on vassago did not answer: connection refused", true)}, shotState{"moved-in-list", movedListShot}, shotState{"checklist", cdShot(func(q *cdQuestion) { checklistShot(q, cdShotBindings()) })}, shotState{"checklist-later", cdShot(func(q *cdQuestion) { checklistShot(q, cdShotBindings()) q.key(tea.KeyPressMsg{Code: tea.KeyDown}) })}, shotState{"checklist-empty", cdShot(func(q *cdQuestion) { checklistShot(q, nil) })}, shotState{"checklist-reading", cdShot(func(q *cdQuestion) { q.transferID, q.phase, q.listed = "t", cdMoving, true })}, shotState{"finishing", cdShot(func(q *cdQuestion) { checklistShot(q, cdShotBindings()) q.phase = cdFinishing })}, shotState{"finish-partial", cdShot(func(q *cdQuestion) { bindings := cdShotBindings() for i, status := range []string{"disarmed", "disarmed", "failed", "pending"} { bindings[i].Status = status } bindings[2].Error = "the webhook could not be disabled: database is locked" checklistShot(q, bindings) q.move.Error = "1 of 4 could not be disarmed; the move waits in its checklist" })}, shotState{"pending-banner", pendingChatShot}, shotState{"pending-in-list", pendingListShot(1)}, shotState{"pending-in-list-unselected", pendingListShot(0)}, ) } // cdShotPicks is an available move of n sessions, each of which vassago can // run only on another profile than its own, beside one it runs as it is. func cdShotPicks(bytes int64, n int) daemon.TransferPreflight { p := daemon.TransferPreflight{Available: true, Host: "vassago", Home: "/home/ana/.albedo", Bytes: &bytes, Sessions: []string{"a", "b", "c"}} p.RunsThere = []daemon.RunsThere{ {SessionID: "a", Name: "fleet rollout", Profile: "claude", Model: "claude-opus-5-5", Reason: "vassago has no claude profile: sign in there first", Alternatives: []string{"bedrock", "vertex"}}, {SessionID: "b", Name: "scout", Profile: "codex", Model: "gpt-5.6-luna", OK: true}, {SessionID: "c", Name: "reviewer", Profile: "openrouter", Model: "kimi-k3", Reason: "vassago's openrouter profile does not list kimi-k3", Alternatives: []string{"opencode-zen"}}, } if n == 1 { p.RunsThere = p.RunsThere[:2] p.Sessions = p.Sessions[:2] } return p } // cdShotBindings are one binding of every kind a checklist lists. func cdShotBindings() []daemon.MoveBinding { return []daemon.MoveBinding{ {Kind: "schedule", ID: "s1", Label: "morning fleet report", Detail: "every 24h · summarise last night's rollouts and post the failures", Status: "pending"}, {Kind: "heartbeat", ID: "h1", Label: "deploy queue", Detail: "every 15m · check the deploy queue", Status: "pending"}, {Kind: "webhook", ID: "w1", Label: "github pushes", Detail: "github pushes", OldURL: "https://valefar.tail0a1b.ts.net:8790/hooks/wh_3f9a2c", NewURL: "https://vassago.tail0a1b.ts.net:8790/hooks/wh_3f9a2c", Status: "pending"}, {Kind: "discord", ID: "d1", Label: "albedo#4471", Detail: "#fleet, #deploys and DMs from ana", Status: "pending"}, } } func checklistShot(q *cdQuestion, bindings []daemon.MoveBinding) { q.transferID, q.phase, q.listed = "t", cdChecklist, true q.move = daemon.Move{State: "checklist", Target: cdShotTarget, Bindings: bindings} } func cdShotSession() daemon.Session { return daemon.Session{ID: "a", Title: "fleet rollout", Workspace: shotHere, Model: "claude-opus-5-5", Provider: "claude"} } // cdShot draws the chat with the question over it, set up by setup. func cdShot(setup func(*cdQuestion)) func(width, height int) string { return func(width, height int) string { session := cdShotSession() app := NewAppModel(daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil), Bootstrap{Sessions: []daemon.Session{session}}, &session, shotHere, false, nil) defer app.Chat.Close() app.Update(tea.WindowSizeMsg{Width: width, Height: height}) // A live chat has had its first status by the time anyone types /cd. app.Chat.Status.Idle = true app.cd = newCDQuestion(session.ID, cdShotTarget, nil) setup(app.cd) app.syncMoveStatus() return app.View().Content } } func movedChatShot(note string, failed bool) func(width, height int) string { return func(width, height int) string { session := cdShotSession() session.Moved = &daemon.SessionMoved{Host: "vassago", Workspace: cdShotTarget, TransferID: "t", At: time.Now()} m := NewChatModel(&session, daemon.NewChatClient(daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil), session.ID)) defer m.Close() m.Status.Idle = true m.SetSize(width, height) if note != "" { m.attaching(note, failed) } m.refreshViewportContent() return m.View() } } func movedListShot(width, height int) string { moved := cdShotSession() moved.Moved = &daemon.SessionMoved{Host: "vassago", Workspace: cdShotTarget, TransferID: "t", At: time.Now()} other := daemon.Session{ID: "b", Title: "nix shim carry fix", Workspace: shotHere, Model: "claude-opus-5-5"} app := NewAppModel(daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil), Bootstrap{Sessions: []daemon.Session{moved, other}}, nil, shotHere, false, nil) app.Update(tea.WindowSizeMsg{Width: width, Height: height}) app.SessionPicker.Init() return app.View().Content } func pendingChatShot(width, height int) string { session := cdShotSession() session.MovePending = &daemon.SessionMovePending{TransferID: "t", Host: "vassago"} m := NewChatModel(&session, daemon.NewChatClient(daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil), session.ID)) defer m.Close() m.Status.Idle = true m.SetSize(width, height) m.refreshViewportContent() return m.View() } // pendingListShot lists a session whose move waits in its checklist beside // a moved one, so the two can be told apart, the highlight down rows from // the first. func pendingListShot(down int) func(width, height int) string { return func(width, height int) string { other := daemon.Session{ID: "b", Title: "nix shim carry fix", Workspace: shotHere, Model: "claude-opus-5-5"} pending := cdShotSession() pending.MovePending = &daemon.SessionMovePending{TransferID: "t", Host: "vassago"} moved := daemon.Session{ID: "c", Title: "bonsai cache tuning", Workspace: shotHere, Model: "claude-opus-5-5"} moved.Moved = &daemon.SessionMoved{Host: "vassago", Workspace: cdShotTarget, TransferID: "u", At: time.Now()} app := NewAppModel(daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil), Bootstrap{Sessions: []daemon.Session{other, pending, moved}}, nil, shotHere, false, nil) app.Update(tea.WindowSizeMsg{Width: width, Height: height}) app.SessionPicker.Init() for range down { app.Update(tea.KeyPressMsg{Code: tea.KeyDown}) } return app.View().Content } }