cli

package
v0.2.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Overview

Package cli: root and subcommands for the BuildMax CLI.

Index

Constants

View Source
const (
	ExitOK            = 0
	ExitGeneric       = 1
	ExitUsage         = 2 // bad flag, missing config (e.g. no model configured)
	ExitPolicyDenied  = 3 // tool blocked by configured policy
	ExitModelError    = 4 // LLM/agent runtime error
	ExitToolError     = 5 // reserved
	ExitUserCancelled = 6 // SIGINT / ctx cancelled
	// ExitIterationCap is a run that reached agent.max_iterations. It is
	// separate from ExitModelError because the two ask different things of a
	// caller: a model error is a fault to retry, while an exhausted budget is
	// an answer — the run stopped where it was told to, and whatever it wrote
	// is real. A harness that retried this would pay for the same cap again.
	ExitIterationCap = 7
)

Exit codes for the CLI. Stable contract for shell scripts wrapping `buildmax -p`. Documented for users in docs/reference/cli.md.

View Source
const APIKeyPlaceholder = "REPLACE_WITH_YOUR_API_KEY"

APIKeyPlaceholder is what `buildmax init` writes when the user did not pass --api-key. checkModelConfig recognizes it, so a run that would otherwise fail inside the LLM client with a provider authentication error stops with an instruction instead.

Variables

This section is empty.

Functions

func ExitCodeFor

func ExitCodeFor(err error) int

ExitCodeFor returns the exit code embedded in err, or ExitGeneric when err is non-nil but not an ExitError, or ExitOK when err is nil.

func NewRootCommand

func NewRootCommand() *cobra.Command

NewRootCommand creates and returns the root cobra command for BuildMax.

Types

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError wraps an exit code so cobra's RunE can return it and main can surface it as the process exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type InputBlock

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

InputBlock groups input state for the textarea at the bottom.

func NewInputBlock

func NewInputBlock() InputBlock

NewInputBlock returns an InputBlock with textarea configured (prompt, placeholder, initial height/width, focused).

func (*InputBlock) Blur

func (ib *InputBlock) Blur()

Blur blurs the textarea.

func (*InputBlock) CanScroll

func (ib *InputBlock) CanScroll() bool

CanScroll reports whether the textarea has hidden wrapped lines above or below.

func (*InputBlock) Focus

func (ib *InputBlock) Focus() tea.Cmd

Focus focuses the textarea and returns its command (for tea.Batch in Init).

func (*InputBlock) Ghost

func (ib *InputBlock) Ghost() string

Ghost returns the suggestion currently on offer, or "" when there is none. It is on offer only while the input is empty: once the user has typed, the suggestion is not what they are about to send.

func (*InputBlock) Height

func (ib *InputBlock) Height() int

Height returns the textarea height in lines.

func (*InputBlock) Reset

func (ib *InputBlock) Reset()

Reset clears the textarea value.

func (*InputBlock) ScrollDown

func (ib *InputBlock) ScrollDown(lines int) tea.Cmd

ScrollDown moves the textarea viewport/cursor downward by the requested number of lines.

func (*InputBlock) ScrollUp

func (ib *InputBlock) ScrollUp(lines int) tea.Cmd

ScrollUp moves the textarea viewport/cursor upward by the requested number of lines.

func (*InputBlock) SetGhost

func (ib *InputBlock) SetGhost(s string)

SetGhost offers text as the ghost suggestion, or clears it when s is empty.

func (*InputBlock) SetValue

func (ib *InputBlock) SetValue(v string)

SetValue replaces the textarea content.

func (*InputBlock) SetWidth

func (ib *InputBlock) SetWidth(w int)

SetWidth sets the textarea width.

func (*InputBlock) SyncHeight

func (ib *InputBlock) SyncHeight()

SyncHeight sets the textarea height to match wrapped content (1 to inputMaxLines).

An empty input is measured against the ghost suggestion instead: the textarea renders the placeholder over its own height, so a two-line suggestion in a one-line box would be silently cut in half.

func (*InputBlock) Update

func (ib *InputBlock) Update(msg tea.Msg) tea.Cmd

Update forwards the message to the textarea and returns its command.

func (*InputBlock) Value

func (ib *InputBlock) Value() string

Value returns the textarea value.

func (*InputBlock) View

func (ib *InputBlock) View() string

View returns the textarea's rendered content.

type Model

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

Model is the root Bubble Tea model in transcript mode. Chat history lives in the terminal scrollback; this model only manages the bottom live strip: streaming preview, input, slash panels, approval, and footer.

func NewModel

func NewModel(opts TUIOpts) *Model

NewModel builds a TUI model with input block and stored opts.

func (*Model) Close

func (m *Model) Close()

Close stops foreground runs and releases background-job subscriptions before the AgentApp they use is closed.

func (*Model) CurrentSession

func (m *Model) CurrentSession() *agentapp.SessionContext

CurrentSession is the session the model is holding now, which is not always the one it started with: /fork switches to the child it creates. Whoever releases the session at exit has to ask, rather than remember.

func (*Model) FocusInput

func (m *Model) FocusInput() bool

FocusInput returns true when the input has focus (used by tests).

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init runs when the program starts; focuses input and starts cursor blink.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages: keys (quit, submit, focus toggle), resize, agent events.

func (*Model) View

func (m *Model) View() tea.View

View renders only the bottom live strip: streaming preview, slash panels, approval, input, footer. Chat history lives in the terminal scrollback and is not rendered here.

type OutputFormat

type OutputFormat string

OutputFormat is the print-mode output format selected by --output.

const (
	OutputText  OutputFormat = "text"
	OutputJSON  OutputFormat = "json"
	OutputJSONL OutputFormat = "jsonl"
)

type TUIApprovalHandler

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

TUIApprovalHandler implements agent.ApprovalHandler for the Bubble Tea TUI. Create it before the program, wire the program in after tea.NewProgram.

func NewTUIApprovalHandler

func NewTUIApprovalHandler() *TUIApprovalHandler

func (*TUIApprovalHandler) RequestApproval

func (h *TUIApprovalHandler) RequestApproval(ctx context.Context, name string, args map[string]any) agent.ApprovalDecision

RequestApproval sends an approval request to the TUI and blocks until the user answers: y (once), a (session), or n/Esc (deny).

func (*TUIApprovalHandler) SetProgram

func (h *TUIApprovalHandler) SetProgram(p *tea.Program)

type TUIOpts

type TUIOpts struct {
	App          *agentapp.AgentApp
	Session      *agentapp.SessionContext
	ModelName    string
	Workspace    util.Workspace
	SessionsDir  string
	Approval     agent.ApprovalHandler
	GlamourStyle string // "dark" or "light", detected once before the program starts
	RunStatus    agentapp.RunUsage
}

TUIOpts holds dependencies and display config for the TUI (agent, session, model name, paths).

Jump to

Keyboard shortcuts

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