Documentation
¶
Overview ¶
Package commands implements a slash-command registry for the bee TUI.
A Command is registered by name (without the leading "/"). When the user types a line that begins with "/", the TUI parses out "<name> [args...]", looks up the command, and calls Run. Each Run either:
- returns text (non-empty) — TUI prints it as if assistant said it,
- returns "" — Run already performed a side effect via Side.
Side decouples commands from TUI/Engine internals: the TUI provides the concrete implementation that wires through to its own state.
Index ¶
Constants ¶
const InitPrompt = `` /* 1091-byte string literal not displayed */
InitPrompt is the user-turn body /init submits. The TUI (app_slash.go) special-cases /init to feed this to the engine so the model scans the repo with its own file/shell tools and writes AGENTS.md. Run here is the headless fallback only.
Variables ¶
This section is empty.
Functions ¶
func RegisterBuiltins ¶
func RegisterBuiltins(r *Registry)
RegisterBuiltins adds the default /compact /model /resume /new /copy /quit /help commands.
func RunModelCommand ¶
RunModelCommand implements /model. Used by the main TUI registry and any lighter UI that wants identical /model semantics.
Types ¶
type Command ¶
type Command struct {
Name string
Description string
// AllowDuringRun marks a command as safe to dispatch while the engine is
// mid-stream. Read-only commands (pickers, /help, /cost, /tree) and
// out-of-band ones (/agent, /attach) set this true so the user isn't
// gated behind a long-running turn.
AllowDuringRun bool
// Run returns text to display as assistant output (non-empty) or
// empty if the command performed a side effect via Side.
Run func(ctx context.Context, args []string, side Side) (string, error)
}
Command is a /name entry.
type ProviderAuth ¶
type ProviderAuth struct {
Name string // provider id (e.g., "anthropic")
HasOAuth bool // [providers.<n>.oauth] is configured
EnvKey string // env var that supplies a static key (e.g., OPENAI_API_KEY)
EnvSet bool // EnvKey is set in the current environment
TokenSaved bool // ~/.bee/auth/<n>.json exists
KeySaved bool // ~/.bee/auth/<n>.key exists (set via /login)
KeyOptional bool // provider runs unauthenticated if no key set (e.g. omlx)
IsDefault bool // matches Cfg.DefaultProvider
}
ProviderAuth summarizes one provider's auth posture for /login UX.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps name -> Command. Safe for concurrent reads/writes.
type Side ¶
type Side interface {
// Compact summarizes older turns to free context window space.
Compact(ctx context.Context) error
// SwitchModel changes the active model id.
SwitchModel(name string) error
// SwitchProviderModel sets both provider and model in one call.
// Empty model is allowed (provider-only switch); empty provider is rejected.
SwitchProviderModel(provider, model string) error
// OpenPicker asks the TUI to display the provider+model picker.
// Returns nil when the modal was scheduled; non-nil signals headless
// fallback so the slash command can hint usage instead.
OpenPicker() error
// OpenHandoff arms /handoff: opens the provider+model picker and routes the
// pick into the stuck-agent handoff flow (summarize → switch → continue)
// instead of a plain model swap. Returns an error in headless contexts.
OpenHandoff() error
// ListSessions returns recent session ids, newest first.
ListSessions() ([]string, error)
// OpenSession loads a previously-recorded session by id.
OpenSession(id string) error
// NewSession clears scrollback and starts a fresh session.
NewSession() error
// CopyLast copies the last assistant message to the system clipboard.
CopyLast() error
// Quit signals the TUI to exit.
Quit()
// OpenTree opens the session tree modal.
OpenTree() error
// OpenResume opens the interactive session-resume picker. Returns an
// error in headless contexts so the caller can fall back to a text list.
OpenResume() error
// OpenCost opens the cost monitor modal.
OpenCost() error
// OpenUsage opens the historical usage-overview modal. Returns an error in
// headless contexts so the command falls back to UsageText.
OpenUsage() error
// UsageText renders the usage overview as compact plain text (the headless
// fallback when no pane is available).
UsageText() string
// ForkSession forks a new session at fromMsgID (or entire session if empty).
ForkSession(fromMsgID string) error
// CloneSession clones the entire current session into a new one.
CloneSession() error
// OpenRewind opens the interactive rewind picker. Returns an error in
// headless contexts so the caller can fall back to a hint.
OpenRewind() error
// SaveCheckpoint snapshots the working tree now under an optional label and
// returns the short sha. Errors when checkpoints are disabled.
SaveCheckpoint(label string) (string, error)
// Login runs the OAuth PKCE flow for a provider and persists the token.
Login(ctx context.Context, provider string) error
// Logout removes the stored OAuth token AND any stored api key file for
// a provider. Treated as "forget everything I saved" by the UI.
Logout(provider string) error
// SaveAPIKey persists a static api key for a non-oauth provider to
// ~/.bee/auth/<provider>.key (0600). The next config load picks it up
// in resolveAPIKey when the EnvKey env var is unset.
SaveAPIKey(provider, key string) error
// LoginStatus reports the auth state of every configured provider,
// sorted alphabetically. Used by /login (no args) to guide the user.
LoginStatus() []ProviderAuth
// OpenLogin asks the TUI to display the interactive login pane.
// Returns nil error when the pane was scheduled; non-nil signals the
// caller (slash command) to fall back to rendered text — useful for
// headless contexts where no pane exists.
OpenLogin() error
// OpenTutorial asks the TUI to replay the interactive first-run
// walkthrough. Returns an error in headless contexts.
OpenTutorial() error
// SetRole switches the active agent role (worker|scout|queen). Unknown
// values are rejected.
SetRole(role string) error
// GetRole returns the active role string.
GetRole() string
// SetYolo flips the auto-approve toggle.
SetYolo(on bool) error
// GetYolo reports whether auto-approve is armed.
GetYolo() bool
// OpenRolePicker asks the TUI to display the role picker modal.
// Returns nil when the modal was scheduled; non-nil signals headless.
OpenRolePicker() error
// SetThinking pins the reasoning budget live (off|low|medium|high|max|auto),
// overriding the role-baked default until changed. Unknown values rejected.
SetThinking(level string) error
// GetThinking returns the active reasoning budget string.
GetThinking() string
// OpenEffortPicker asks the TUI to display the reasoning-effort picker modal.
// Returns nil when scheduled; non-nil signals headless.
OpenEffortPicker() error
// SetMaxIterations changes the per-Run tool-use iteration cap live and
// persists it. 0 = unlimited (loop until a token-budget or stall guard
// fires). Negatives are clamped to 0.
SetMaxIterations(n int) error
// GetMaxIterations returns the current per-Run iteration cap (0 = unlimited).
GetMaxIterations() int
// SetVerbose mutates the verbose tool-output flag. Persists to config.
SetVerbose(v bool) error
// GetVerbose returns the current verbose flag.
GetVerbose() bool
// SetShowThoughts mutates the show-agent-thoughts flag. Persists to config.
SetShowThoughts(v bool) error
// GetShowThoughts returns the current show-thoughts flag.
GetShowThoughts() bool
// SetShowNudges toggles the visibility of synthetic `[nudge]` recovery
// turns the loop injects. Persists to config. Render-only — the loop
// continues to inject these messages regardless.
SetShowNudges(v bool) error
// GetShowNudges returns the current show-nudges flag.
GetShowNudges() bool
// SetShowRecap toggles post-turn one-line side-LLM recap generation.
// Persists to config. Off = no side call.
SetShowRecap(v bool) error
// GetShowRecap returns the current show-recap flag.
GetShowRecap() bool
// SetCompact toggles compact TUI mode (no gutter/spacing/tint). Persists to config.
SetCompact(v bool) error
// GetCompact returns the current compact flag.
GetCompact() bool
// SetShowContextBar toggles the bottom context-fill strip. Persists to config.
SetShowContextBar(v bool) error
// GetShowContextBar returns the current show-context-bar flag.
GetShowContextBar() bool
// SetHighlight toggles chroma syntax-highlighting across diff/file/bash
// previews. Persists to config.
SetHighlight(v bool) error
// GetHighlight returns the current highlight flag.
GetHighlight() bool
// SetShellBangSilent flips the default behavior of `!cmd`. true = run
// locally without forwarding; false = legacy forward-to-LLM. `!!` always
// inverts. Persists to config.
SetShellBangSilent(v bool) error
// GetShellBangSilent returns the current bang-silent flag.
GetShellBangSilent() bool
// Top-bar chrome toggles. Each persists to config; flipping all five off
// collapses the entire status row.
SetShowBee(v bool) error
GetShowBee() bool
SetShowContextPct(v bool) error
GetShowContextPct() bool
SetShowModel(v bool) error
GetShowModel() bool
SetShowCwd(v bool) error
GetShowCwd() bool
SetShowEffort(v bool) error
GetShowEffort() bool
SetShowTurnTimer(v bool) error
GetShowTurnTimer() bool
SetShowGitBranch(v bool) error
GetShowGitBranch() bool
SetShowTotalTokens(v bool) error
GetShowTotalTokens() bool
// SetShowBanner toggles the startup intro animation + bee logo. Persists.
// Takes effect on next launch (intro is one-shot).
SetShowBanner(v bool) error
GetShowBanner() bool
// SetShowLoader toggles the streaming "generating" animation live + persists.
SetShowLoader(v bool) error
GetShowLoader() bool
// OpenSettings asks the TUI to display the settings pane. Returns an
// error in headless contexts so the slash command can fall back to text.
OpenSettings() error
// OpenAgentView opens the bgreg-backed multi-bee pane (Left arrow).
// Returns an error in headless contexts.
OpenAgentView() error
// ListTools reports every known tool with its enabled state and source
// (builtin vs user). Sorted by name. Used by /tools (no args).
ListTools() []ToolInfo
// SetToolDisabled adds or removes name from cfg.DisabledTools and
// persists. The filter applies on the next turn (live).
SetToolDisabled(name string, disabled bool) error
// AddUserTool persists a new [[user_tools]] entry and registers it live.
// Errors if name collides with an existing tool.
AddUserTool(name, command, description string) error
// RemoveUserTool drops a [[user_tools]] entry by name and unregisters it.
// Errors if the name is not a user tool.
RemoveUserTool(name string) error
// OpenToolsPane asks the TUI to display the tools toggle pane. Returns
// an error in headless contexts.
OpenToolsPane() error
// SetBrowserEnabled turns the native browser tools on or off for the
// current session only (no config persist) and rebuilds the tool
// registry so the change takes effect immediately. Returns a status
// string for the user. Errors when turning on with no Chrome found.
SetBrowserEnabled(on bool) (string, error)
// VisionFallback configures the session's fallback vision model used when
// the main model can't see images (no config persist). Empty model reports
// current status instead of changing anything. Returns a status string.
VisionFallback(model, endpoint, api string) (string, error)
}
Side is the surface a command uses to affect the TUI/engine without hard-depending on either package. Implementations live in the TUI.
Source Files
¶
- builtins.go
- builtins_bg.go
- builtins_browser.go
- builtins_external.go
- builtins_goal.go
- builtins_handoff.go
- builtins_init.go
- builtins_login.go
- builtins_model.go
- builtins_remote.go
- builtins_session.go
- builtins_settings.go
- builtins_stop.go
- builtins_tools.go
- builtins_tutorial.go
- builtins_vision.go
- builtins_watchdog.go
- registry.go