tui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 30 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 tui is kairo's terminal UI (ADR 0010), shaped as claude's: what is done is written into the terminal's flow (it stays in the scrollback), and under it stay the reply being written, the input box and a status line. It is an ACP client's face: it holds what it shows and what the user types, and nothing that must outlive it (the session and its waits are in the daemon).

Index

Constants

View Source
const (
	StatePending = ""        // not yet: ○ grey
	StateRunning = "running" // ⏺ kairo's yellow
	StateDone    = "done"    // ✓ green
	StateFailed  = "failed"  // ✗ red
	StateWaiting = "waiting" // ⏸ orange: waits for the user
)

States of a box of a flow's chart.

View Source
const (
	NotifyUnfocused = "unfocused" // while the terminal is not in focus (default)
	NotifyAlways    = "always"
	NotifyNever     = "never"
)

Notify modes, "notify" in the user's kairocode.json.

Variables

This section is empty.

Functions

func AskTrust

func AskTrust(ctx context.Context, in io.Reader, out io.Writer, dir string) (bool, error)

AskTrust asks whether the files in dir are trusted (ADR 0010), before anything in it is read. It is a program of its own, on the alternate screen: the question goes away once answered.

func Chart

func Chart(c *flowchart.Chart, width int, state func(flowchart.Node) string) string

Chart draws a flow's chart in at most width columns, top to bottom as Dify draws a workflow: each step a box, branches and agents at once side by side, loops framed. state gives each box its state ("" for none yet). What does not fit is drawn as a tree.

func ChartLive

func ChartLive(v *flowchart.View, width int, live *Live) string

ChartLive draws a run of a flow as it goes: a box that runs turns, says how long it has run, and, the one box that runs, what its agent writes and runs now. With live nil, it is ChartOf.

func ChartOf

func ChartOf(v *flowchart.View, width int) string

ChartOf draws a run of a flow: its chart with its calls' states, and how often each was made when more than once (×N).

func FlowGraph

func FlowGraph(dir, name string, width int) (string, error)

FlowGraph draws the flow name of the project in dir (.kairocode/workflows), with nothing run yet.

func IsImage

func IsImage(path string) bool

IsImage says whether path is a file sent as an image.

func Mentioned

func Mentioned(dir, text string) []string

Mentioned are the files and folders of dir that text points to (@path).

Types

type Agent

type Agent interface {
	NewSession(ctx context.Context, cwd string) (string, error)
	LoadSession(ctx context.Context, session, cwd string) error
	// ListSessions are the sessions of cwd, the latest used first.
	ListSessions(ctx context.Context, cwd string) ([]acp.SessionInfo, error)
	// Prompt sends text, with the files it points to (@path).
	Prompt(ctx context.Context, session, text string, files ...string) (string, error)
	// Cancel asks for the turn under way to stop (ADR 0011).
	Cancel(session string) error
	// SetConfigOption sets one of the session's settings: its provider or
	// model (ADR 0014).
	SetConfigOption(ctx context.Context, session, id, value string) error
	// InstallProvider installs an agent of ACP's registry (ADR 0015).
	InstallProvider(ctx context.Context, id, version string) error
	// Models are a provider's models (ADR 0014).
	Models(ctx context.Context, provider string) ([]string, error)
	// LoginMethods and Login sign in to a provider (ADR 0015).
	LoginMethods(ctx context.Context, provider string) ([]acp.LoginMethod, error)
	Login(ctx context.Context, provider, method string, done bool) error
	// SetMode sets the session's mode (ADR 0016).
	SetMode(ctx context.Context, session, mode string) error
	// Plugins and PluginChange are /plugin's screen (ADR 0027).
	Plugins(ctx context.Context, session string) (acp.PluginsView, error)
	PluginChange(ctx context.Context, args ...string) (string, error)
	// FlowRuns and FlowRun are /flow runs' screen (ADR 0029).
	FlowRuns(ctx context.Context, dir, flow, only string, n int) ([]api.FlowRun, error)
	FlowRun(ctx context.Context, id string) (api.FlowRun, error)
	// GoOn goes on from a session that failed, in a new one forked from its
	// last finished turn (ADR 0021).
	GoOn(ctx context.Context, session string) (string, int, error)
}

Agent is what the UI needs of the ACP client.

type Live

type Live struct {
	Since map[string]time.Time
	Now   time.Time
	Start time.Time // when the run began (zero: not known)
	Text  string    // the last of what the agent writes
	Tool  string    // the call it makes now
}

Live is what a running flow is doing now: when each box that runs began (by its key), the time, and what its agent says and runs last.

type Options

type Options struct {
	// Dir is the working directory (absolute), Session one to take up again
	// ("" starts one).
	Dir, Session string
	// Version, Engine and Model are shown in the header and status line.
	Version, Engine, Model string
	// Usage is the tokens the session's model calls used, if known.
	Usage func(ctx context.Context, session string) (int64, error)
	// Resume: the sessions of Dir are offered to take up first (kairo
	// -resume); esc starts a new one.
	Resume bool
	// Plugin is how to run kairocode plugin (its argv up to the verb), for
	// /plugin connect and disconnect, which ask for credentials here.
	Plugin []string
	// Data is the data directory: images pasted from the clipboard are
	// kept in its pasted/ until sent (ADR 0026).
	Data string
}

Options are what the UI shows and does around the conversation.

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI is a running terminal UI.

func New

func New(ctx context.Context, in io.Reader, out io.Writer, o Options) *UI

New makes the UI. Its Update and Permission are the ACP client's handler; Run gives it the client.

func (*UI) Permission

func (u *UI) Permission(ctx context.Context, req acp.PermissionRequest) acp.PermissionAnswer

Permission asks the user, and waits for the answer or for ctx to end (the request withdrawn: answered elsewhere).

func (*UI) Run

func (u *UI) Run(a Agent) (string, error)

Run runs the UI on agent until the user leaves. It returns the session ("" if none was started).

func (*UI) Update

func (u *UI) Update(up acp.Update)

Update gives the UI an ACP update.

Directories

Path Synopsis
Package screen draws the terminal UI's area below the conversation, and writes the conversation above it, as Codex's TUI does (ADR 0033).
Package screen draws the terminal UI's area below the conversation, and writes the conversation above it, as Codex's TUI does (ADR 0033).
vtest
Package vtest is a small terminal for tests of what internal/tui/screen writes (ADR 0033).
Package vtest is a small terminal for tests of what internal/tui/screen writes (ADR 0033).

Jump to

Keyboard shortcuts

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