ui

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(template string, args []string) string

Expand substitutes placeholder patterns in template with the given args.

Supported patterns:

  • $1, $2, ... $N — positional args (1-based, out-of-range → "")
  • ${@:N} — all args from index N onward (1-based)
  • ${@:N:L} — L args starting at index N (1-based)
  • $@ / $ARGUMENTS — all args joined by space

Substitution is single-pass per pattern class (no recursive expansion).

func ParseArgs

func ParseArgs(s string) []string

ParseArgs splits a command argument string respecting double and single quotes. Empty quoted strings are skipped.

func ReadStdinPrompt

func ReadStdinPrompt() (string, error)

ReadStdinPrompt reads all of stdin as a prompt (for pipe usage).

func RunPrint

func RunPrint(sess *agent.Session, args []string, jsonMode bool) error

RunPrint executes non-interactive print/json mode.

func RunPrintMode

func RunPrintMode(sess *agent.Session, prompt string, jsonMode bool) error

RunPrintMode runs the agent in non-interactive mode. stdout receives assistant text (pipe-friendly), stderr receives tool/status info. When jsonMode is true, all events are streamed as JSONL to stdout.

func RunTUI

func RunTUI(sess *agent.Session, cwd, gitBranch, modelName, version string, approvalEngine *approval.Engine, mcpMgr *mcpclient.Manager, mcpServers map[string]mcpclient.ServerConfig, envHint string) error

RunTUI executes interactive TUI mode.

Types

type App

type App struct {
	Session   *agent.Session
	Cwd       string
	GitBranch string

	ApprovalEngine *approval.Engine

	// Commands are user-defined slash commands loaded from .md files.
	Commands []config.FileCommand

	// Skills are loaded skill definitions.
	Skills []config.Skill

	// MCPManager manages MCP server connections.
	MCPManager *mcpclient.Manager

	// CronStore holds session-scoped cron jobs for /loop command.
	CronStore *cron.Store

	// SubAgentTool provides access to background agent task registry for /tasks command.
	SubAgentTool *agentcore.SubAgentTool

	// BashTool provides access to background shell registry for /tasks command.
	BashTool *agentcoretools.BashTool

	// PlanStore persists plans to ~/.codebot/plans/.
	PlanStore *storage.PlanStore

	// History provides input history for Up/Down navigation.
	History *storage.History

	// CommandLoaders allow alternative command sources to be injected at app construction time.
	CommandLoaders []CommandLoader
	// contains filtered or unexported fields
}

App is the TUI adapter. Business logic lives in agent.Session.

func (*App) Config

func (a *App) Config() tui.Config

Config returns a tui.Config with all hooks wired to this App.

type BtwCommand added in v0.0.4

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

BtwCommand implements /btw — ephemeral side-chain Q&A that reads the full conversation context but never mutates history or invokes tools.

func NewBtwCommand added in v0.0.4

func NewBtwCommand(app *App) *BtwCommand

NewBtwCommand creates a /btw command bound to the given App.

func (*BtwCommand) Active added in v0.0.4

func (c *BtwCommand) Active() bool

func (*BtwCommand) Dismiss added in v0.0.4

func (c *BtwCommand) Dismiss()

func (*BtwCommand) HandleKey added in v0.0.4

func (c *BtwCommand) HandleKey(msg tea.KeyMsg) (bool, tea.Cmd)

func (*BtwCommand) IsModal added in v0.0.4

func (c *BtwCommand) IsModal() bool

func (*BtwCommand) Run added in v0.0.4

func (*BtwCommand) SetResult added in v0.0.4

func (c *BtwCommand) SetResult(msg tui.BtwResultMsg)

SetResult updates the overlay with the side question response.

func (*BtwCommand) Spec added in v0.0.4

func (c *BtwCommand) Spec() CommandSpec

func (*BtwCommand) View added in v0.0.4

func (c *BtwCommand) View(width int) string

type Command added in v0.0.2

type Command interface {
	Spec() CommandSpec
	Run(ctx *CommandContext, inv CommandInvocation) tea.Cmd
}

Command is the unified abstraction for all slash commands.

type CommandContext added in v0.0.2

type CommandContext struct {
	App *App
}

CommandContext provides runtime dependencies to commands.

type CommandInvocation added in v0.0.2

type CommandInvocation struct {
	Input   string
	Name    string
	RawArgs string
	Args    []string
}

CommandInvocation is the parsed slash-command input passed to command handlers.

type CommandKind added in v0.0.2

type CommandKind string
const (
	CommandKindBuiltin CommandKind = "builtin"
	CommandKindCustom  CommandKind = "custom"
	CommandKindSkill   CommandKind = "skill"
)

type CommandLoader added in v0.0.2

type CommandLoader interface {
	Load(app *App) []Command
}

CommandLoader discovers a family of commands and contributes them to the registry.

type CommandSpec added in v0.0.2

type CommandSpec struct {
	Name        string
	Aliases     []string
	Usage       string
	Description string
	Category    string
	NeedsIdle   bool
	Hidden      bool
	Kind        CommandKind
	Source      string
}

CommandSpec describes command metadata.

type FileCommandAdapter added in v0.0.2

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

func (*FileCommandAdapter) Run added in v0.0.2

func (*FileCommandAdapter) Spec added in v0.0.2

func (c *FileCommandAdapter) Spec() CommandSpec

type InteractiveCommand added in v0.0.2

type InteractiveCommand interface {
	Command
	Active() bool
	HandleKey(msg tea.KeyMsg) (handled bool, cmd tea.Cmd)
	View(width int) string
	Dismiss()
}

InteractiveCommand extends Command with modal keyboard interception and custom rendering. When Active() returns true the TUI routes all keyboard events through HandleKey and replaces the input area with View.

type ModalOverlay added in v0.0.4

type ModalOverlay interface {
	IsModal() bool
}

ModalOverlay is an optional interface for overlays that replace the input area.

type ModelCommand added in v0.0.2

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

ModelCommand implements InteractiveCommand for /model. Without arguments it opens an interactive selector overlay; with arguments it switches directly.

func NewModelCommand added in v0.0.2

func NewModelCommand(app *App) *ModelCommand

func (*ModelCommand) Active added in v0.0.2

func (c *ModelCommand) Active() bool

func (*ModelCommand) Dismiss added in v0.0.2

func (c *ModelCommand) Dismiss()

func (*ModelCommand) HandleKey added in v0.0.2

func (c *ModelCommand) HandleKey(msg tea.KeyMsg) (bool, tea.Cmd)

func (*ModelCommand) Run added in v0.0.2

func (*ModelCommand) Spec added in v0.0.2

func (c *ModelCommand) Spec() CommandSpec

func (*ModelCommand) View added in v0.0.2

func (c *ModelCommand) View(width int) string

type Registry added in v0.0.2

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

Registry manages command registration, lookup by name/alias, and the active interactive overlay.

func NewRegistry added in v0.0.2

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) All added in v0.0.2

func (r *Registry) All() []Command

All returns all registered commands sorted by kind and then by name.

func (*Registry) ClearOverlay added in v0.0.2

func (r *Registry) ClearOverlay()

ClearOverlay dismisses and clears the active overlay.

func (*Registry) EffectiveSpec added in v0.0.2

func (r *Registry) EffectiveSpec(cmd Command) CommandSpec

EffectiveSpec returns the command metadata with only active aliases included.

func (*Registry) Lookup added in v0.0.2

func (r *Registry) Lookup(name string) (Command, bool)

Lookup finds a command by name or alias (case-insensitive).

func (*Registry) Overlay added in v0.0.2

func (r *Registry) Overlay() InteractiveCommand

Overlay returns the currently active interactive command, or nil.

func (*Registry) Register added in v0.0.2

func (r *Registry) Register(cmd Command)

Register adds or replaces a command and its aliases in the registry.

func (*Registry) RegisterAll added in v0.0.2

func (r *Registry) RegisterAll(commands []Command)

RegisterAll adds a batch of commands to the registry.

func (*Registry) SetOverlay added in v0.0.2

func (r *Registry) SetOverlay(ic InteractiveCommand)

SetOverlay sets the active interactive overlay.

type ResumeCommand added in v0.0.2

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

ResumeCommand implements InteractiveCommand for /resume. Opens an interactive overlay to select and switch sessions.

func NewResumeCommand added in v0.0.2

func NewResumeCommand(app *App) *ResumeCommand

func (*ResumeCommand) Active added in v0.0.2

func (c *ResumeCommand) Active() bool

func (*ResumeCommand) Dismiss added in v0.0.2

func (c *ResumeCommand) Dismiss()

func (*ResumeCommand) HandleKey added in v0.0.2

func (c *ResumeCommand) HandleKey(msg tea.KeyMsg) (bool, tea.Cmd)

func (*ResumeCommand) Run added in v0.0.2

func (*ResumeCommand) Spec added in v0.0.2

func (c *ResumeCommand) Spec() CommandSpec

func (*ResumeCommand) View added in v0.0.2

func (c *ResumeCommand) View(width int) string

type SimpleCommand added in v0.0.2

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

SimpleCommand wraps a plain function as a Command.

func NewSimple added in v0.0.2

func NewSimple(spec CommandSpec, run func(*CommandContext, CommandInvocation) tea.Cmd) *SimpleCommand

NewSimple creates a SimpleCommand.

func (*SimpleCommand) Run added in v0.0.2

func (*SimpleCommand) Spec added in v0.0.2

func (c *SimpleCommand) Spec() CommandSpec

type SkillCommand added in v0.0.2

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

func (*SkillCommand) Run added in v0.0.2

func (*SkillCommand) Spec added in v0.0.2

func (c *SkillCommand) Spec() CommandSpec

type TasksCommand added in v0.0.3

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

TasksCommand implements InteractiveCommand for /tasks. Shows background bash commands and agent tasks in a grouped overlay.

func NewTasksCommand added in v0.0.3

func NewTasksCommand(app *App) *TasksCommand

func (*TasksCommand) Active added in v0.0.3

func (c *TasksCommand) Active() bool

func (*TasksCommand) Dismiss added in v0.0.3

func (c *TasksCommand) Dismiss()

func (*TasksCommand) HandleKey added in v0.0.3

func (c *TasksCommand) HandleKey(msg tea.KeyMsg) (bool, tea.Cmd)

func (*TasksCommand) Run added in v0.0.3

func (*TasksCommand) Spec added in v0.0.3

func (c *TasksCommand) Spec() CommandSpec

func (*TasksCommand) View added in v0.0.3

func (c *TasksCommand) View(width int) string

Directories

Path Synopsis
Package imageinput handles image input from clipboard paste and file drag-drop, converting raw data to agentcore ContentBlocks.
Package imageinput handles image input from clipboard paste and file drag-drop, converting raw data to agentcore ContentBlocks.
tui

Jump to

Keyboard shortcuts

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