package tui import ( "fmt" "time" "albedo/cli/internal/daemon" "albedo/cli/internal/daemon/protocol" ) func init() { registerShots("chat", shotState{name: "generating-titled", view: func(w, h int) string { return renderLiveChatShot(&daemon.ToolProgress{ CallID: "p1", Name: "python", Phase: "generating", Title: "find which go files label python cells", Code: &daemon.ToolCodePreview{Text: "# find which go files label python cells\nprint(1)"}, }, w, h) }}, shotState{name: "generating-untitled", view: func(w, h int) string { return renderLiveChatShot(&daemon.ToolProgress{ CallID: "p2", Name: "python", Phase: "generating", Code: &daemon.ToolCodePreview{Text: "import os\nprint(os.getcwd())"}, }, w, h) }}, shotState{name: "running-titled", view: func(w, h int) string { return renderLiveChatShot(&daemon.ToolProgress{ CallID: "p3", Name: "python", Phase: "running", Title: "find which go files label python cells", Code: &daemon.ToolCodePreview{Text: "print(1)"}, }, w, h) }}, shotState{name: "running-cjk", view: func(w, h int) string { return renderLiveChatShot(&daemon.ToolProgress{ CallID: "p4", Name: "python", Phase: "running", Title: "東京e\u0301界のファイルを検索する", }, w, h) }}, shotState{name: "settled-titled", view: func(w, h int) string { return renderSettledChatShot("find which go files label python cells", "# find which go files label python cells\nprint(1)", w, h) }}, shotState{name: "settled-no-title", view: func(w, h int) string { return renderSettledChatShot("", "import os\nprint(os.getcwd())", w, h) }}, shotState{name: "settled-long-title", view: func(w, h int) string { return renderSettledChatShot("examine and categorize all repository files across multiple nested directory structures to compute statistics", "# examine and categorize all repository files across multiple nested directory structures to compute statistics\nx = 1", w, h) }}, 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: "usage-cost", view: func(w, h int) string { return renderUsageChatShot(daemon.Usage{ Model: "claude-haiku-5.5", PromptTokens: new(int(396_000)), CachedPromptTokens: new(int(392_000)), CompletionTokens: new(int(1_100)), Spent: &daemon.Cost{Usd: 0.4213, Basis: daemon.BasisCounted}, }, w, h) }}, shotState{name: "usage-cost-below-a-cent", view: func(w, h int) string { return renderUsageChatShot(daemon.Usage{ Model: "claude-haiku-5.5", PromptTokens: new(int(1_200)), CachedPromptTokens: new(int(0)), Spent: &daemon.Cost{Usd: 0.0018, Basis: daemon.BasisCharged}, }, w, h) }}, shotState{name: "usage-no-charge", view: func(w, h int) string { return renderUsageChatShot(daemon.Usage{ Model: "deepseek-v4.1-flash", PromptTokens: new(int(32_000)), CachedPromptTokens: new(int(24_000)), }, w, h) }}, shotState{name: "usage-cost-after-model-switch", view: func(w, h int) string { // The last call used the old model. The spend belongs to the session, // so it still shows. return renderUsageChatShotForModel(daemon.Usage{ Model: "claude-haiku-5.5", PromptTokens: new(int(396_000)), CachedPromptTokens: new(int(392_000)), Spent: &daemon.Cost{Usd: 0.4213, Basis: daemon.BasisCounted}, }, "deepseek-v4.1-flash", 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}, shotState{name: "inline-skill", view: func(w, h int) string { return renderCommandMenuChatShot("Review this patch with $baby", w, h) }}, shotState{name: "command-argument-choices", view: func(w, h int) string { return renderCommandMenuChatShot("/reload ", w, h) }}, shotState{name: "command-argument-filtered", view: func(w, h int) string { return renderCommandMenuChatShot("/reload m", w, h) }}, shotState{name: "shell-running", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-1", Command: "printf output", Status: "running", Output: "first\nsecond\nthird\nfourth\nfifth\nsixth\n", OutputBytes: 38}, false, w, h) }}, shotState{name: "shell-collapsed", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-2", Command: "echo foobar", Status: "completed", ExitCode: new(int64(0)), Output: "foobar\nsecond\nthird\nfourth\nfifth\nsixth\n", OutputBytes: 39}, false, w, h) }}, shotState{name: "shell-queued-for-agent", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-queued", Command: "echo foobar", Status: "completed", Delivery: "pending", Output: "foobar\n"}, false, w, h) }}, shotState{name: "shell-sent-to-agent", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-sent", Command: "echo foobar", Status: "completed", Delivery: "delivered", Output: "foobar\n"}, false, w, h) }}, shotState{name: "shell-legacy-unknown", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-legacy", Command: "echo foobar", Status: "completed", Delivery: "unknown", Output: "foobar\n"}, false, w, h) }}, shotState{name: "shell-running-pending", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-running-pending", Command: "echo foobar", Status: "running", Delivery: "pending", Output: ""}, false, w, h) }}, shotState{name: "shell-expanded", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-3", Command: "cat report.txt", Status: "completed", ExitCode: new(int64(0)), Output: "row 1\nrow 2\nrow 3\nrow 4\nrow 5\nrow 6\nrow 7\nrow 8\n", OutputBytes: 48}, true, w, h) }}, shotState{name: "shell-empty", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-4", Command: "true", Status: "completed", ExitCode: new(int64(0))}, false, w, h) }}, shotState{name: "shell-error", view: func(w, h int) string { msg := "permission denied" return renderShellChatShot(daemon.ShellCommand{ID: "shell-5", Command: "./deploy.sh", Status: "failed", Error: &msg, Output: "could not execute command\n", OutputBytes: 23}, false, w, h) }}, shotState{name: "shell-cancelled", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-6", Command: "sleep 60", Status: "cancelled", Output: "stopped after 3 seconds\n", OutputBytes: 24}, false, w, h) }}, ) for index, animation := range fastAnimations { for tick := range animation { shotScreens["chat"] = append(shotScreens["chat"], shotState{ name: fmt.Sprintf("fast-faces-%d-frame-%d", index, tick), view: func(w, h int) string { return renderFastFaceShot(index, tick, w, h) }, }) } } } func renderLiveChatShot(progress *daemon.ToolProgress, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} client := daemon.NewChatClient(conn, session.ID) m := NewChatModel(session, client) m.handleStreamEvent(daemon.StreamEvent{ Type: daemon.EventToolProgress, Progress: progress, }) m.SetSize(width, height) m.refreshViewportContent() return m.View() } func renderSettledChatShot(title, code string, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} client := daemon.NewChatClient(conn, session.ID) m := NewChatModel(session, client) m.handleStreamEvent(daemon.StreamEvent{ Type: daemon.EventTool, ToolName: "python", ToolTitle: title, ToolArgs: map[string]any{"code": code}, ToolResult: `{"status":"ok","output":"done"}`, }) m.SetSize(width, height) m.refreshViewportContent() 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} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) m.Status.Running = true phase := daemon.PhasePreparing m.Status.Phase = &phase m.SetSize(width, height) m.ProgressFrame = tick for m.moodSeed = 0; m.phaseMood().pick(m.moodSeed, len(fastAnimations)) != index; m.moodSeed++ { } return m.View() } // renderUsageChatShot renders a settled chat. Its footer shows the cache share // of the last call and the total spend of the session. func renderUsageChatShot(usage daemon.Usage, width, height int) string { return renderUsageChatShotForModel(usage, usage.Model, width, height) } // renderUsageChatShotForModel renders the same footer as renderUsageChatShot, // for a session whose current model is not the model of the usage. func renderUsageChatShotForModel(usage daemon.Usage, model string, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: model, Provider: "github-copilot"} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) m.Usage = &usage window, windowModel := 400_000, usage.Model m.window, m.windowModel = &window, &windowModel m.SetSize(width, height) return m.View() } func renderFastChatShot(fast bool, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/work", Model: "claude-opus-5-5", Effort: "high", Fast: fast} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) m.SetSize(width, height) return m.View() } func renderShellChatShot(command daemon.ShellCommand, expanded bool, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) entry := shellEntry(command) entry.ShellOutputLoaded = expanded if expanded { entry.ShellExpandedOutput = command.Output } m.History.Append(entry) if expanded { m.Renderer.Open = map[string]bool{entryKey(entry): true} } m.SetSize(width, height) m.refreshViewportContent() return m.View() } func renderCommandMenuChatShot(input string, width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) m.CommandMenu.Catalog = []daemon.SessionCommand{{ Name: "/reload", Arguments: []daemon.CommandArgument{{Name: "target", Description: "reload target", Choices: []string{"session", "models", "both"}}}, }} m.CommandMenu.Catalog = append(m.CommandMenu.Catalog, daemon.SessionCommand{Name: "/babysit-pr", SkillName: "babysit-pr", Description: "Monitor a pull request through review and CI until the outstanding checks and comments are resolved."}) m.TextArea.SetValue(input) m.SetSize(width, height) return m.View() } // renderDirenvChatShot is a fresh chat whose folder's .envrc direnv blocks. func renderDirenvChatShot(width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) m.SetSize(width, height) m, _ = m.Update(ChatDirenvMsg{SessionID: session.ID, Generation: m.Generation, Workspace: session.Workspace, Envrc: session.Workspace + "/.envrc"}) m.refreshViewportContent() return m.View() }