Documentation
¶
Overview ¶
Package ui is the Bubble Tea application: root model, tab/status bar, responsive layout system, and (from later milestones) the per-tab views.
Index ¶
- type AgentView
- func (v AgentView) ApplyConfig(cfg config.Config, c *ollama.Client, reload bool) (AgentView, tea.Cmd)
- func (v AgentView) CloseRecorder() error
- func (v AgentView) CloseUndo() error
- func (v AgentView) Init() tea.Cmd
- func (v AgentView) ModalOpen() bool
- func (v AgentView) Update(msg tea.Msg) (AgentView, tea.Cmd)
- func (v AgentView) View() string
- func (v AgentView) WithLogger(l *log.Logger) AgentView
- func (v AgentView) WithSessionDir(dir, host string) AgentView
- func (v AgentView) WithUndoDir(dir string) AgentView
- type App
- type Breakpoint
- type ModelsLayout
- type ModelsView
- type SettingsView
- type StatusBar
- type Styles
- type TabBar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentView ¶
type AgentView struct {
// contains filtered or unexported fields
}
AgentView is the Agent tab (PLAN.md §7): a streaming transcript rendered with glamour markdown (syntax-highlighted code blocks), a multi-line input, model selector (m), graceful errors, and cancellation (esc). M3a probes read-only tool support and explicitly falls back to plain chat when a model rejects tools or returns no tool call.
func NewAgentView ¶
func NewAgentView(client *ollama.Client, styles Styles, theme, defaultModel string, agentCfg config.AgentConfig) AgentView
NewAgentView builds the Agent tab using the current directory as its workspace, with a background parent context and workspace tools DISABLED (the default: no tool definitions reach the model until the user opts in via cfg.ToolsEnabled — production wiring through NewWithContext). It remains a compatibility constructor for tests and legacy callers.
func NewAgentViewWithWorkspace ¶
func NewAgentViewWithWorkspace(client *ollama.Client, styles Styles, theme, defaultModel, workspaceRoot string, agentCfg config.AgentConfig) AgentView
NewAgentViewWithWorkspace builds the Agent tab with the configured project root and system prompt (background parent context; tools disabled — see NewAgentView).
func (AgentView) ApplyConfig ¶
func (v AgentView) ApplyConfig(cfg config.Config, c *ollama.Client, reload bool) (AgentView, tea.Cmd)
ApplyConfig applies a successful settings save in-session: scalar chat parameters, the default model, the workspace tool trust switch, and the host take effect for the next send, and the runner is rebuilt so a new workspace root, system prompt, iteration cap, tools state, and client apply. An in-flight turn keeps the runner it started with (startChat copies the pointer before the goroutine runs), so swapping here is safe mid-stream. reload=true (host/token change) clears the selector models and refetches from the new host.
func (AgentView) CloseRecorder ¶
CloseRecorder flushes every committed turn and stops the transcript recorder's worker. It is the normal-shutdown lifecycle boundary (main calls it after the tea program exits); a nil recorder (recording disabled or no turn yet) is a no-op, and Close is idempotent.
func (AgentView) CloseUndo ¶ added in v0.4.0
CloseUndo is the clean-exit lifecycle boundary for the undo journal: it GCs the crash-artifact blobs (session stacks die with the process anyway).
func (AgentView) ModalOpen ¶
ModalOpen reports whether the Agent tab is showing a modal. The root App uses it so the 1/2/3 tab-jump keys cannot steal from an approval dialog, a confirmation, or the help overlay.
func (AgentView) View ¶
View renders transcript + hint + input per the current geometry. A modal (model selector, mutation approval, write_files batch review, /help, /clear, /undo confirm) replaces the body with a centered overlay; the slash-command menu (M7-A) floats between the transcript and the input while a "/" draft is being composed.
func (AgentView) WithLogger ¶
WithLogger attaches the shared debug logger (N5): the current runner is re-armed immediately, and ApplyConfig keeps it across runner rebuilds so the drawer follows the loop across settings saves. Nil clears the trace.
func (AgentView) WithSessionDir ¶
WithSessionDir enables transcript persistence under dir with host recorded in the file header (the composition root — main via App — wires it once at startup; empty dir disables). The concrete recorder is constructed here, not lazily on the update loop: a committed turn only ever enqueues work onto the existing dependency. Re-wiring closes the previous recorder first (Close is idempotent), so repeated calls never strand a worker.
func (AgentView) WithUndoDir ¶ added in v0.4.0
WithUndoDir attaches the crash-artifact directory for this session's undo journal (V2e §4.3): entries die with the process, but their fsynced pre-image blobs live under dir for crash recovery and are GC'd at clean exit (Close). An empty dir keeps the journal memory-only (tests, hosts without a state home). Re-wiring replaces the journal and re-attaches it to the current runner.
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the root Bubble Tea model: owns tab state, geometry, and the responsive shell. Each tab's view lives in its own file (models_view.go since M1a, agent_view.go since M2, settings_view.go since M4).
func New ¶
New builds the root model with a background parent context. It is the compatibility entry point (tests, legacy callers): main wires the real signal-derived context through NewWithContext so every Models/Agent operation derives from the process root. client is the Ollama connection shared by the Models and Agent tabs; cfg is the live session config (settings edits and env/flag overrides all resolve onto it).
func NewWithContext ¶
func NewWithContext(ctx context.Context, cfg *config.Config, styles Styles, client *ollama.Client) App
NewWithContext builds the root model exactly like New but binds the parent context: every operation the Models and Agent tabs start (list/show/delete fetches, chat and pull streams) derives from ctx, so canceling the process root aborts in-flight background work. A nil ctx is treated as a background root (see normalizeCtx).
func (App) CloseSession ¶
CloseSession is the normal-shutdown lifecycle boundary for chat-transcript persistence and the V2e undo journal: it flushes every committed turn to the transcript, stops the recorder worker, and GCs the undo journal's crash artifacts (session stacks die with the process) so nothing is stranded when the process returns (main calls it on the final model returned by Program.Run). A disabled or silent session is a no-op; the underlying closes are idempotent.
func (App) Update ¶
Update handles window geometry, navigation keys, tab keys, async results, and settings persistence / live-apply messages.
func (App) View ¶
View renders header + active body + status bar. The command palette replaces the active tab's body; the transient note is shown in the status bar's left cell (see Update: every keypress clears it). Below the minimum window geometry the whole shell is replaced by the bounded small-terminal message.
func (App) WithLog ¶
WithLog attaches the shared debug logger and sink (PLAN.md §12 N5): the logger reaches the Ollama client and the agent runner for transport and loop traces, the sink feeds the logs drawer. Nil (compat constructors, tests) leaves the shell drawerless and ctrl+o inert.
func (App) WithSessionDir ¶
WithSessionDir enables Agent chat transcript persistence under dir (the resolved state dir; empty disables). Called by main after New; the host is recorded in each transcript's header.
func (App) WithUndoDir ¶ added in v0.4.0
WithUndoDir attaches the V2e undo journal's crash-artifact dir (the resolved state dir; empty keeps it memory-only). Called by main after New; a prior journal is closed and replaced so the crash artifacts land under the configured root.
type Breakpoint ¶
type Breakpoint int
Breakpoint classifies a width for layout selection.
const ( Compact Breakpoint = iota // ≤ compactMax: stacked, foldable Medium // compactMax+1..mediumMax: split, still narrow Wide // ≥ mediumMax+1: full side-by-side panels )
func (Breakpoint) String ¶
func (b Breakpoint) String() string
Breakpoint names for display/status (and golden tests later).
type ModelsLayout ¶
type ModelsLayout struct {
// SideBySide is true when list and detail sit side by side (Wide, and
// Medium when the pane fits); false → stacked, detail toggled.
SideBySide bool
// ListWidth is the list pane width when SideBySide.
ListWidth int
}
ModelsLayout describes how the Models view arranges its two panes (list + detail) for a given width. Other views get their own helpers as they land (M1+). This is the M0 responsive-shell proof that geometry adapts without touching theme objects.
func ForModels ¶
func ForModels(width int) ModelsLayout
ForModels returns the Models geometry for a width.
func (ModelsLayout) DetailWidth ¶
func (m ModelsLayout) DetailWidth(total int) int
DetailWidth returns the detail pane width for a side-by-side layout (the remaining space); 0 when stacked.
type ModelsView ¶
type ModelsView struct {
// contains filtered or unexported fields
}
ModelsView is the Models tab (PLAN.md §7): a selectable model list plus an inspect pane fed by POST /api/show. M1a delivered list + inspect; M1b adds delete (x → confirm → y/esc) and streaming pull (p → name → spinner + progress, esc cancels). Layout (side-by-side vs stacked) comes from the shared breakpoint system; theme comes from the shared Styles.
func NewModelsView ¶
func NewModelsView(client *ollama.Client, styles Styles, theme string) ModelsView
NewModelsView builds the Models tab with a background parent context. It is the compatibility constructor for tests and callers that predate root-context wiring; new code should go through the App's NewWithContext (or newModelsView with the real parent) so operations cancel with the process.
func (ModelsView) ApplyClient ¶
func (v ModelsView) ApplyClient(c *ollama.Client) (ModelsView, tea.Cmd)
ApplyClient points the tab at a new Ollama client after a settings save that changed host or token; the stale list/detail are dropped and reloaded from the new host via the returned non-blocking load cmd.
func (ModelsView) Init ¶
func (v ModelsView) Init() tea.Cmd
Init starts the first list fetch. Called once from the root App.
func (ModelsView) ModalOpen ¶
func (v ModelsView) ModalOpen() bool
ModalOpen reports whether the Models tab is showing a modal (confirm / name input / pull). The root App uses it so global keys (1/2/3 tab jump) cannot steal characters typed into a dialog.
func (ModelsView) Update ¶
func (v ModelsView) Update(msg tea.Msg) (ModelsView, tea.Cmd)
Update handles messages aimed at the Models tab. The root App forwards keys only when this tab is active; async results are forwarded always.
func (ModelsView) View ¶
func (v ModelsView) View() string
View renders list + inspect per the breakpoint layout. A modal state (confirm / input / pull / deleting) replaces the whole body with a centered dialog.
type SettingsView ¶
type SettingsView struct {
// contains filtered or unexported fields
}
func NewSettingsView ¶
func NewSettingsView(cfg *config.Config, styles Styles) SettingsView
NewSettingsView builds the Settings tab. cfg is the live session config the form edits; nothing is written until a form submission.
func (SettingsView) Begin ¶
func (s SettingsView) Begin() SettingsView
Begin (re)builds the editing form from the current session config. Called every time the user enters the Settings tab, so a result panel is never carried into a new editing session.
func (SettingsView) Editing ¶
func (s SettingsView) Editing() bool
Editing reports whether the Settings tab currently owns an active form. The root App uses it to swallow global keys while settings are open.
func (SettingsView) Update ¶
func (s SettingsView) Update(msg tea.Msg) (SettingsView, tea.Cmd)
func (SettingsView) View ¶
func (s SettingsView) View() string
type Styles ¶
type Styles struct {
// composed styles
Tab lipgloss.Style
TabActive lipgloss.Style
Status lipgloss.Style
Body lipgloss.Style
Placeholder lipgloss.Style
Pane lipgloss.Style
Error lipgloss.Style
// contains filtered or unexported fields
}
Styles is the centralized theme (PLAN.md §7): one palette, shared by every view. Only layout geometry differs by breakpoint, never the theme objects.