ui

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func (v AgentView) CloseRecorder() error

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

func (v AgentView) CloseUndo() error

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) Init

func (v AgentView) Init() tea.Cmd

Init starts the model list fetch for the selector.

func (AgentView) ModalOpen

func (v AgentView) ModalOpen() bool

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) Update

func (v AgentView) Update(msg tea.Msg) (AgentView, tea.Cmd)

func (AgentView) View

func (v AgentView) View() string

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

func (v AgentView) WithLogger(l *log.Logger) AgentView

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

func (v AgentView) WithSessionDir(dir, host string) AgentView

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

func (v AgentView) WithUndoDir(dir string) AgentView

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

func New(cfg *config.Config, styles Styles, client *ollama.Client) App

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

func (a App) CloseSession() error

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) Init

func (a App) Init() tea.Cmd

Init starts the Models list and Agent model-list fetches.

func (App) Update

func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles window geometry, navigation keys, tab keys, async results, and settings persistence / live-apply messages.

func (App) View

func (a App) View() tea.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

func (a App) WithLog(l *log.Logger, sink *logsink.Sink) App

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

func (a App) WithSessionDir(dir, host string) App

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

func (a App) WithUndoDir(dir string) App

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 BreakpointFor

func BreakpointFor(width int) Breakpoint

BreakpointFor classifies width.

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 StatusBar

type StatusBar struct {
	Left, Right string
	Styles      Styles
	Width       int
}

StatusBar is the bottom info strip (left context, right geometry/state).

func (StatusBar) Render

func (s StatusBar) Render() string

Render lays out Left … Right with a gap, truncating Right to fit Width.

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.

func NewStyles

func NewStyles(theme string) Styles

NewStyles builds the theme for "dark" or "light" (any other value → dark).

type TabBar

type TabBar struct {
	Active int
	Styles Styles
	Width  int
}

TabBar renders the navigation tab row. Highlighting is purely presentational: the root model owns the active index (single source of truth). The row is one chip per tab and never wraps; Width is accepted from the shell but not used in rendering.

func (TabBar) Label

func (t TabBar) Label() string

Label returns the active tab label.

func (TabBar) Render

func (t TabBar) Render() string

Render draws the tab row (one chip per tab, active tab highlighted).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL