tui

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: AGPL-3.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentConsoleArgsForLine

func AgentConsoleArgsForLine(line string) ([]string, error)

func RunAgentConsoleWithTerminal

func RunAgentConsoleWithTerminal(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, terminal *rlterm.Terminal, subscribers ...AOPEventSubscriber) error

RunAgentConsoleWithTerminal creates the renderer and readline console for an explicit terminal. Local callers pass the process terminal directly so control sequences are never buffered and replayed through a PTY.

func RunIOAContext

func RunIOAContext(ctx context.Context, client *ioaclient.Client, option *cfg.Option, args cfg.IOAClientArgs, stdout, stderr io.Writer) error

func RunIOAMessages

func RunIOAMessages(ctx context.Context, client *ioaclient.Client, option *cfg.Option, args cfg.IOAClientArgs, stdout, stderr io.Writer) error

func RunIOANodes

func RunIOANodes(ctx context.Context, client *ioaclient.Client, option *cfg.Option, args cfg.IOAClientArgs, stdout, stderr io.Writer) error

func RunIOASpaces

func RunIOASpaces(ctx context.Context, client *ioaclient.Client, option *cfg.Option, stdout, stderr io.Writer) error

func RunPrompt

func RunPrompt(s *Session, label, input string) error

RunPrompt expands skills and submits a prompt to the controller.

func RunRemoteAgentConsoleWithControl

func RunRemoteAgentConsoleWithControl(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, input io.Reader, output io.Writer, control *rlterm.StreamControl, subscribers ...AOPEventSubscriber) error

RunRemoteAgentConsoleWithControl adapts a byte-stream terminal while keeping event rendering scoped to the attached agent session.

func WebMenuSpecs added in v0.3.0

func WebMenuSpecs(cmds []Command) []*types.CommandSpec

WebMenuSpecs extracts the web-visible command metadata from a Command list. Run-control commands (/stop, /followup, /eval, /loop, /exit) are excluded because the web expresses those through UI controls, not slash text.

Types

type AOPEventSubscriber added in v0.4.0

type AOPEventSubscriber func(func(*aop.Event)) func()

AOPEventSubscriber connects a console-local renderer to the runtime AOP bus and returns an unsubscribe function owned by that console attachment.

type AgentConsole

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

func NewAgentConsole

func NewAgentConsole(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, output *AgentOutput) *AgentConsole

func NewAgentConsoleWithTerminal

func NewAgentConsoleWithTerminal(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, output *AgentOutput, t *rlterm.Terminal) *AgentConsole

func NewAgentConsoleWithWriters added in v0.2.8

func NewAgentConsoleWithWriters(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, stdout, stderr io.Writer) *AgentConsole

NewAgentConsoleWithWriters builds a non-interactive console that executes individual REPL lines against the same command implementation as the TUI.

func (*AgentConsole) EvalCriteria added in v0.4.0

func (r *AgentConsole) EvalCriteria() string

func (*AgentConsole) ExecuteLineAndWait added in v0.2.8

func (r *AgentConsole) ExecuteLineAndWait(line string) (bool, error)

ExecuteLineAndWait runs one REPL input line and waits for any async agent run started by that line. It is used by the web chat bridge so slash and bang commands do not drift from the interactive console behavior.

func (*AgentConsole) InterruptCurrentRun

func (r *AgentConsole) InterruptCurrentRun() bool

InterruptCurrentRun stops the current agent run or direct command.

func (*AgentConsole) SetEvalCriteria added in v0.4.0

func (r *AgentConsole) SetEvalCriteria(criteria string)

func (*AgentConsole) SetOnExit added in v0.3.0

func (r *AgentConsole) SetOnExit(fn func())

func (*AgentConsole) Start

func (r *AgentConsole) Start() error

func (*AgentConsole) StaticCommands added in v0.3.0

func (r *AgentConsole) StaticCommands() []Command

StaticCommands returns the non-skill REPL commands (builtin + provider + IOA). Safe to call on a zero-value receiver — the returned Command.Run closures are unusable, but the metadata (Name, Aliases, Description, Hidden) is correct.

type AgentOutput

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

func NewAgentOutput

func NewAgentOutput(option *cfg.Option) *AgentOutput

func NewAgentOutputWithWriters

func NewAgentOutputWithWriters(option *cfg.Option, stdout, stderr io.Writer, terminal bool) *AgentOutput

func NewStaticAgentOutput added in v0.2.7

func NewStaticAgentOutput(option *cfg.Option) *AgentOutput

func NewStaticAgentOutputWithWriters added in v0.2.7

func NewStaticAgentOutputWithWriters(option *cfg.Option, stdout, stderr io.Writer, terminal bool) *AgentOutput

func (*AgentOutput) AbortCurrentRun

func (o *AgentOutput) AbortCurrentRun()

func (*AgentOutput) CycleOutputPreset added in v0.4.0

func (o *AgentOutput) CycleOutputPreset() string

func (*AgentOutput) Empty

func (o *AgentOutput) Empty()

func (*AgentOutput) EnsureStreamNewline

func (o *AgentOutput) EnsureStreamNewline()

func (*AgentOutput) Error

func (o *AgentOutput) Error(err error)

func (*AgentOutput) Final

func (o *AgentOutput) Final(content string)

func (*AgentOutput) HandleEvent

func (o *AgentOutput) HandleEvent(event *aop.Event)

func (*AgentOutput) Markdown added in v0.2.7

func (o *AgentOutput) Markdown() bool

Markdown returns whether markdown rendering is enabled.

func (*AgentOutput) SetContextWindow added in v0.4.0

func (o *AgentOutput) SetContextWindow(tokens int)

func (*AgentOutput) SetInbox added in v0.4.0

func (o *AgentOutput) SetInbox(items []string)

SetInbox updates the transient preview of prompts waiting behind the active run without stopping the live status.

func (*AgentOutput) SetInteractiveInputActive added in v0.3.0

func (o *AgentOutput) SetInteractiveInputActive(active bool)

func (*AgentOutput) SetReadlineMode added in v0.4.0

func (o *AgentOutput) SetReadlineMode(output io.Writer, status func(string))

SetReadlineMode commits finalized output above the current prompt and sends transient status frames through readline's composer. The terminal still owns scrollback; the 100ms animation only redraws the active composer.

func (*AgentOutput) SetVerbosity added in v0.2.7

func (o *AgentOutput) SetVerbosity(level int)

func (*AgentOutput) Start

func (o *AgentOutput) Start(label, text string)

func (*AgentOutput) Stderr added in v0.2.7

func (o *AgentOutput) Stderr() io.Writer

Stderr returns the stream writer's stderr for direct output.

func (*AgentOutput) Stdout added in v0.2.7

func (o *AgentOutput) Stdout() io.Writer

Stdout returns the stream writer's stdout.

func (*AgentOutput) Stopped

func (o *AgentOutput) Stopped()

func (*AgentOutput) Stopping

func (o *AgentOutput) Stopping()

func (*AgentOutput) VerbosityLabel added in v0.2.7

func (o *AgentOutput) VerbosityLabel() string

func (*AgentOutput) VerbosityLevel added in v0.2.7

func (o *AgentOutput) VerbosityLevel() int

type AppInfo

type AppInfo struct {
	Provider          agent.Provider
	ProviderConfig    agent.ProviderConfig
	ProviderFallbacks []agent.ProviderEntry
	Commands          *commands.CommandRegistry
	Skills            *skills.Store
	OnProviderChange  func(agent.Provider, agent.ProviderConfig)
	OnLoggerChange    func(telemetry.Logger)
	Run               func(context.Context, string, bool) (*agent.Result, error)
	Command           func(context.Context, string) error
	Resume            func(context.Context, string) (int, error)
	ListSessions      func() ([]SavedSession, error)
	ActiveAgent       func() *agent.Agent
	ActiveSessionID   func() string
}

AppInfo holds the subset of runtime state that tui commands need.

type ArgSpec

type ArgSpec int
const (
	ArgsNone ArgSpec = iota
	ArgsExact1
	ArgsOptional
)

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Args        ArgSpec
	Hidden      bool
	Run         func(ctx context.Context, s *Session, args []string) error
}

Command describes a REPL command independent of any UI framework.

func SkillCommands

func SkillCommands(s *Session) []Command

SkillCommands generates commands for each non-internal skill.

type Controller

type Controller interface {
	SubmitPrompt(label, displayText, prompt string) error
	Continue() error
	Stop() bool
	Running() bool
}

Controller is the async execution interface that tui implements.

type EvalSettings

type EvalSettings struct {
	Criteria string
	Model    string
	Provider agent.Provider
	Logger   telemetry.Logger
}

type LiveStatus added in v0.2.7

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

func NewLiveStatus added in v0.2.7

func NewLiveStatus(view *LiveView, dim func(string) string, renderToolLine func(*toolEvent) string) *LiveStatus

func (*LiveStatus) BeginTurn added in v0.2.7

func (l *LiveStatus) BeginTurn(turn int)

func (*LiveStatus) ContextUsage added in v0.2.7

func (l *LiveStatus) ContextUsage(tokens int) string

func (*LiveStatus) DrainTools added in v0.2.7

func (l *LiveStatus) DrainTools() []*toolEvent

func (*LiveStatus) FinishTurn added in v0.2.7

func (l *LiveStatus) FinishTurn(contextTokens int)

FinishTurn records the latest context size. Per-turn statistics remain in the transient status line and are intentionally not committed to history.

func (*LiveStatus) HasTools added in v0.2.7

func (l *LiveStatus) HasTools() bool

func (*LiveStatus) NoteDelta added in v0.4.0

func (l *LiveStatus) NoteDelta(textDelta bool)

NoteDelta switches the shared status row from thinking to talking once assistant response text begins. It remains the same transient composer row; response text itself is committed separately to terminal scrollback.

func (*LiveStatus) Render added in v0.2.7

func (l *LiveStatus) Render()

func (*LiveStatus) Reset added in v0.2.7

func (l *LiveStatus) Reset()

func (*LiveStatus) Running added in v0.2.7

func (l *LiveStatus) Running() bool

func (*LiveStatus) SetContextWindow added in v0.2.7

func (l *LiveStatus) SetContextWindow(tokens int)

func (*LiveStatus) SetInbox added in v0.4.0

func (l *LiveStatus) SetInbox(items []string, render bool)

SetInbox updates the pending user input preview. The inbox intentionally survives Reset so a queued run remains visible while the next run starts.

func (*LiveStatus) SetOutputEstimate added in v0.4.0

func (l *LiveStatus) SetOutputEstimate(tokens int)

func (*LiveStatus) SetTurnToolCalls added in v0.4.0

func (l *LiveStatus) SetTurnToolCalls(count int)

func (*LiveStatus) SetTurnUsage added in v0.4.0

func (l *LiveStatus) SetTurnUsage(usage *aop.TokenUsage)

func (*LiveStatus) SetUsageVisible added in v0.4.0

func (l *LiveStatus) SetUsageVisible(visible bool)

func (*LiveStatus) ShowEvalRound added in v0.2.7

func (l *LiveStatus) ShowEvalRound(round int)

func (*LiveStatus) StartTool added in v0.2.7

func (l *LiveStatus) StartTool(ev *toolEvent)

func (*LiveStatus) Status added in v0.2.7

func (l *LiveStatus) Status() string

func (*LiveStatus) Stop added in v0.2.7

func (l *LiveStatus) Stop()

func (*LiveStatus) StopAndDrainTools added in v0.2.7

func (l *LiveStatus) StopAndDrainTools() []*toolEvent

func (*LiveStatus) UpdateTool added in v0.2.7

func (l *LiveStatus) UpdateTool(ev *toolEvent) (tracked bool, done bool)

func (*LiveStatus) WithHidden added in v0.2.7

func (l *LiveStatus) WithHidden(fn func())

type LiveView added in v0.2.7

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

LiveView manages transient status output. Both direct terminal rendering and the readline composer animate on a timer; the composer redraw stays inside readline so it does not replace the terminal's native scrollback.

func NewLiveView added in v0.2.7

func NewLiveView(w io.Writer, accent string) *LiveView

func (*LiveView) EventDriven added in v0.4.0

func (v *LiveView) EventDriven() bool

EventDriven reports whether rendering is delegated to readline. This mode coalesces stream events and uses the dedicated composer refresh interval.

func (*LiveView) SetElapsedStart added in v0.4.0

func (v *LiveView) SetElapsedStart(start time.Time)

SetElapsedStart controls the live duration placeholder used by status lines.

func (*LiveView) SetStatusSink added in v0.4.0

func (v *LiveView) SetStatusSink(sink func(string))

SetStatusSink renders the live line through an external inline-composer footer instead of writing cursor-control sequences directly to the terminal.

func (*LiveView) Start added in v0.2.7

func (v *LiveView) Start()

func (*LiveView) Stop added in v0.2.7

func (v *LiveView) Stop()

func (*LiveView) Update added in v0.2.7

func (v *LiveView) Update(lines []string)

func (*LiveView) UpdateDeferred added in v0.4.0

func (v *LiveView) UpdateDeferred(lines []string)

UpdateDeferred replaces the next animation frame without forcing an immediate terminal redraw. Readline stream deltas use this to coalesce many token events into the composer's 100ms refresh cadence.

func (*LiveView) WithHidden added in v0.2.7

func (v *LiveView) WithHidden(fn func())

type ProviderInfo

type ProviderInfo struct {
	Name   string
	Model  string
	Active bool
}

StatusInfo collects current session state for display.

type RenderMode

type RenderMode int
const (
	ModeInteractive RenderMode = iota
	ModeStatic
	ModeForwarded
)

type SavedSession

type SavedSession struct {
	Path      string
	SessionID string
	Model     string
	Messages  int
	UpdatedAt time.Time
}

func (SavedSession) SortTime

func (s SavedSession) SortTime() time.Time

type Session

type Session struct {
	Ctx          context.Context
	Option       *cfg.Option
	AppInfo      AppInfo
	Agent        *agent.Agent
	Controller   Controller
	EvalCriteria string
	ResolveInput func(string) (displayText string, promptText string)
	OnEvalChange func(string)
}

Session holds the dependencies commands need to operate on.

type StatusInfo

type StatusInfo struct {
	Provider  string
	Model     string
	Providers []ProviderInfo
	Mode      string
	Task      string
	IOA       string
	History   string
	Skills    string
}

func CollectStatus

func CollectStatus(s *Session, mode, historyPath string) StatusInfo

type StreamWriter added in v0.2.7

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

StreamWriter manages token-by-token content streaming with paragraph-level markdown buffering and reasoning block tracking. It owns all cursor state for the stdout/stderr interleaving.

func NewStreamWriter added in v0.2.7

func NewStreamWriter(stdout, stderr io.Writer, enabled, markdown bool, color output.Color, reasoning bool) *StreamWriter

func (*StreamWriter) ContentPrinted added in v0.2.7

func (w *StreamWriter) ContentPrinted() int

ContentPrinted returns the number of content bytes already flushed.

func (*StreamWriter) Delta added in v0.2.7

func (w *StreamWriter) Delta(content, reasoning *string)

Delta processes a new token delta (content and/or reasoning).

func (*StreamWriter) EnsureLiveBoundary added in v0.2.7

func (w *StreamWriter) EnsureLiveBoundary()

func (*StreamWriter) EnsureNewline added in v0.2.7

func (w *StreamWriter) EnsureNewline()

EnsureNewline closes any mid-line stdout cursor.

func (*StreamWriter) Flush added in v0.2.7

func (w *StreamWriter) Flush()

Flush writes any buffered content and closes open reasoning blocks.

func (*StreamWriter) MarkStreamed added in v0.2.7

func (w *StreamWriter) MarkStreamed()

MarkStreamed marks the current content as rendered directly.

func (*StreamWriter) NewTurn added in v0.2.7

func (w *StreamWriter) NewTurn()

NewTurn resets per-turn counters (called at EventTurnStart).

func (*StreamWriter) ReasoningPrinted added in v0.2.7

func (w *StreamWriter) ReasoningPrinted() int

ReasoningPrinted returns the number of reasoning bytes already flushed.

func (*StreamWriter) Reset added in v0.2.7

func (w *StreamWriter) Reset()

Reset clears all state (called at run start).

func (*StreamWriter) SetReasoning added in v0.4.0

func (w *StreamWriter) SetReasoning(enabled bool)

func (*StreamWriter) Streamed added in v0.2.7

func (w *StreamWriter) Streamed() bool

Streamed returns true if any content was streamed this run.

func (*StreamWriter) WouldPrintContentDelta added in v0.2.7

func (w *StreamWriter) WouldPrintContentDelta(content *string) bool

func (*StreamWriter) WouldPrintDelta added in v0.2.7

func (w *StreamWriter) WouldPrintDelta(content, reasoning *string) bool

WouldPrintDelta reports whether Delta would emit visible output for this update. Role-only updates, hidden reasoning, and partial markdown chunks keep the live "thinking" view on screen.

Jump to

Keyboard shortcuts

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