console

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package console runs the terminal client over a client.Backend. It is the one call an embedding program makes: build a backend (package native for an agentturn.Agent, package kitbackend for an agentkit.Kit), then Run.

be, err := kitbackend.New(kit)
if err != nil {
	return err
}
defer be.Close()
return console.Run(ctx, be)

Run owns the terminal for as long as it runs and does what the agentconsole binary does: it follows the backend's record and live streams into the view, turns an interrupt signal into the same thing ctrl+c is in raw mode (abort a run, quit when idle), and, once the program ends, aborts a run that is still going and waits for it to write its end before it returns, so the store can be closed behind it.

Index

Constants

View Source
const DefaultDrainTimeout = 3 * time.Second

DefaultDrainTimeout bounds the wait for an aborted run to write its end, unless WithDrainTimeout says otherwise.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, be client.Backend, opts ...Option) error

Run runs the terminal client over be until the user quits, ctx is done, or the program fails, and returns the program's error.

The backend's Record must be one the client can follow and read, and its Live must subscribe when called (the contract says so): Run attaches before it starts the program, so no event of the first run is missed. Run does not close anything it did not open. The backend, its store and the agent's recorder are the caller's, and are safe to close once Run returns: the run it was driving has ended or the drain timeout passed.

A canceled ctx ends the program with an error, as bubbletea's WithContext does.

Types

type Option

type Option func(*config)

Option configures Run.

func WithCost

func WithCost(fn client.Cost) Option

WithCost prices one model call, showing the followed session's cost in the session pane. fn returns a call's cost in US dollars, and reports false for a model it has no price for.

func WithDrainTimeout

func WithDrainTimeout(d time.Duration) Option

WithDrainTimeout bounds how long Run waits, after the program ends, for a run it aborted to write its end. The default is DefaultDrainTimeout. Run waits twice: once for the abort to land, and once more after it cancels the context the run used as the last resort.

func WithInput

func WithInput(r io.Reader) Option

WithInput reads the terminal's input from r instead of the process's standard input. A reader that is not a terminal runs the program without raw mode, which is how a test drives it.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput renders to w instead of the process's standard output.

func WithWarn

func WithWarn(fn func(string)) Option

WithWarn sends the one warning Run has, that a run did not end within the drain timeout and the session is closed as it is, to fn instead of to standard error.

func WithWindowSize

func WithWindowSize(width, height int) Option

WithWindowSize tells the program its terminal's size, as the terminal would, for a run whose input and output are not a terminal and report none (the program draws nothing until it knows its size). A terminal reports its own size and overrides it.

func WithoutSignalHandler

func WithoutSignalHandler() Option

WithoutSignalHandler leaves SIGINT and SIGTERM to the embedder. By default Run turns either into an interrupt of the client (the same as ctrl+c); without the handler the embedder's own handling applies, and the program ends only when the user quits or ctx is done.

Jump to

Keyboard shortcuts

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