tui

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 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, bus ...*eventbus.Bus[agent.Event]) error

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, bus ...*eventbus.Bus[agent.Event]) error

func WebMenuSpecs added in v0.3.0

func WebMenuSpecs(cmds []Command) []webproto.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 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, bus ...*eventbus.Bus[agent.Event]) *AgentConsole

func NewAgentConsoleWithTerminal

func NewAgentConsoleWithTerminal(ctx context.Context, option *cfg.Option, appInfo AppInfo, session *agent.Agent, output *AgentOutput, t *rlterm.Terminal, bus ...*eventbus.Bus[agent.Event]) *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, bus ...*eventbus.Bus[agent.Event]) *AgentConsole

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

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) 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) 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 agent.Event)

func (*AgentOutput) Markdown added in v0.2.7

func (o *AgentOutput) Markdown() bool

Markdown returns whether markdown rendering is enabled.

func (*AgentOutput) Queued

func (o *AgentOutput) Queued(text string)

func (*AgentOutput) SetInteractiveInputActive added in v0.3.0

func (o *AgentOutput) SetInteractiveInputActive(active bool)

func (*AgentOutput) SetSplitMode added in v0.3.0

func (o *AgentOutput) SetSplitMode(st *SplitTerminal)

SetSplitMode redirects all output through the split terminal's scroll region and wires the live status into the fixed status bar.

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

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
	Bus      *eventbus.Bus[agent.Event]
	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(agent.Event) string) *LiveStatus

func (*LiveStatus) BeginTurn added in v0.2.7

func (l *LiveStatus) BeginTurn()

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() []agent.Event

func (*LiveStatus) FinishAgent added in v0.2.7

func (l *LiveStatus) FinishAgent(event agent.Event)

func (*LiveStatus) FinishTurn added in v0.2.7

func (l *LiveStatus) FinishTurn(event agent.Event)

func (*LiveStatus) HasTools added in v0.2.7

func (l *LiveStatus) HasTools() bool

func (*LiveStatus) MessageUpdate added in v0.2.7

func (l *LiveStatus) MessageUpdate(event agent.Event, contentDelta bool)

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) ShowEvalRound added in v0.2.7

func (l *LiveStatus) ShowEvalRound(round int)

func (*LiveStatus) StartTool added in v0.2.7

func (l *LiveStatus) StartTool(event agent.Event)

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() []agent.Event

func (*LiveStatus) UpdateTool added in v0.2.7

func (l *LiveStatus) UpdateTool(event agent.Event) (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 a transient, animated region on the terminal. Lines containing spinnerSentinel get the current animation frame injected on each tick. Stop erases the region cleanly.

When split is non-nil the view renders into the split terminal's status bar instead of using inline cursor-up/erase tricks.

func NewLiveView added in v0.2.7

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

func (*LiveView) SetSplitTerminal added in v0.3.0

func (v *LiveView) SetSplitTerminal(st *SplitTerminal)

SetSplitTerminal puts the view into split mode: status is rendered to the split terminal's fixed status bar instead of inline. Must be called before Start and never changed afterwards.

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) 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 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 SplitTerminal added in v0.3.0

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

SplitTerminal divides the terminal into three areas:

rows 1..scrollEnd   - scroll region for agent output
row  statusRow      - fixed status bar (thinking/tooling/talking)
rows inputRow..rows - fixed input area for readline

The status bar always sits immediately above the fixed input viewport.

func NewSplitTerminal added in v0.3.0

func NewSplitTerminal(raw io.Writer, fd int) *SplitTerminal

func (*SplitTerminal) Active added in v0.3.0

func (st *SplitTerminal) Active() bool

Active reports whether the split layout is set up.

func (*SplitTerminal) ClearStatus added in v0.3.0

func (st *SplitTerminal) ClearStatus()

ClearStatus resets the status bar to the default separator.

func (*SplitTerminal) InputWriter added in v0.3.0

func (st *SplitTerminal) InputWriter() io.Writer

InputWriter returns a writer for readline that serializes with output writes and clips terminal control sequences to the input area.

func (*SplitTerminal) OutputWriter added in v0.3.0

func (st *SplitTerminal) OutputWriter() io.Writer

OutputWriter returns a writer that routes output into the scroll region.

func (*SplitTerminal) PrepareInputArea added in v0.3.0

func (st *SplitTerminal) PrepareInputArea()

PrepareInputArea resets the input area to its default height and clears it for a new readline prompt.

func (*SplitTerminal) Setup added in v0.3.0

func (st *SplitTerminal) Setup()

func (*SplitTerminal) Teardown added in v0.3.0

func (st *SplitTerminal) Teardown()

func (*SplitTerminal) UpdateStatus added in v0.3.0

func (st *SplitTerminal) UpdateStatus(text string)

UpdateStatus replaces the status bar content.

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, verbosity int) *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) 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