commands

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package commands holds the slash-command implementations and the abstractions required to register them with the host UI.

Design: each command declares its dependencies explicitly — either via a New* constructor's parameters, or as exported fields on a command struct constructed with a literal at registration. There is no shared "Deps" interface — the registration site doubles as the dependency graph.

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 FormatBool

func FormatBool(v bool) string

FormatBool maps a boolean to a human-readable yes/no for status panels.

func FormatCompactionCounts

func FormatCompactionCounts(counts map[agent.CompactionKind]int) string

FormatCompactionCounts renders compaction kind tallies.

func FormatCompactionSavings

func FormatCompactionSavings(savings map[agent.CompactionKind]int) string

FormatCompactionSavings renders the per-kind token savings totals.

func FormatContextRewriteDetails

func FormatContextRewriteDetails(snapshot *agentcore.ContextSnapshot) string

FormatContextRewriteDetails describes the last context rewrite metadata.

func FormatContextScope

func FormatContextScope(scope string) string

FormatContextScope translates a snapshot scope token into a human label.

func FormatErrorCounts

func FormatErrorCounts(counts map[diag.Category]int) string

FormatErrorCounts renders error category tallies in a stable order.

func FormatLastCompaction

func FormatLastCompaction(snapshot agent.CompactionSnapshot, ok bool) string

FormatLastCompaction renders the most recent compaction snapshot.

func FormatLastReminder

func FormatLastReminder(snapshot agent.ReminderSnapshot, ok bool) string

FormatLastReminder renders the most recent runtime reminder snapshot.

func FormatRecentErrors

func FormatRecentErrors(errors []agent.ErrorSnapshot) []string

FormatRecentErrors renders recent error snapshots one per line.

func FormatRecentToolCalls

func FormatRecentToolCalls(calls []agent.ToolCallSnapshot) []string

FormatRecentToolCalls renders recent tool call snapshots one per line.

func FormatReminderCounts

func FormatReminderCounts(counts map[agent.RuntimeReminderKind]int) string

FormatReminderCounts renders runtime reminder counts in a stable order.

func FormatRunSummary

func FormatRunSummary(summary agentcore.RunSummary, ok bool) string

FormatRunSummary renders the most recent agentcore run summary.

func OpenEditor

func OpenEditor(path, successText string, onReload func()) tea.Cmd

OpenEditor launches $EDITOR (or vi as fallback) on path and runs onReload after the editor exits. Shared by /memory and /plan open.

func ParseArgs

func ParseArgs(s string) []string

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

func PrettyCompactionStrategy

func PrettyCompactionStrategy(name string) string

PrettyCompactionStrategy maps an internal compaction strategy id to a human-readable label, returning empty when no mapping is registered.

Types

type BtwCommand

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

BtwCommand drives /btw — an ephemeral side-chain Q&A that consults the current conversation context but never mutates history or invokes tools. It is exported so the host can route the async tui.BtwResultMsg back to the active overlay via SetResult.

func Btw

func Btw(session *agent.Session, overlay OverlayController) *BtwCommand

Btw constructs the /btw command. overlay is used to install and dismiss the question/answer modal.

func (*BtwCommand) Active

func (c *BtwCommand) Active() bool

func (*BtwCommand) Dismiss

func (c *BtwCommand) Dismiss()

func (*BtwCommand) HandleKey

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

func (*BtwCommand) IsModal

func (c *BtwCommand) IsModal() bool

func (*BtwCommand) Run

func (c *BtwCommand) Run(inv Invocation) tea.Cmd

func (*BtwCommand) SetResult

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

SetResult updates the overlay with the side question response. The host invokes this from its OnBtwResult hook.

func (*BtwCommand) Spec

func (c *BtwCommand) Spec() Spec

func (*BtwCommand) View

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

type Command

type Command interface {
	Spec() Spec
	Run(inv Invocation) tea.Cmd
}

Command is the unified abstraction for all slash commands.

func Clear

func Clear(session *agent.Session, resetPlanState func()) Command

Clear constructs the /clear command which wipes the in-memory conversation (session history on disk is preserved). resetPlanState is invoked so any pending plan-mode UI state is dropped at the same time.

func Compact

func Compact(session *agent.Session) Command

Compact constructs the /compact command which collapses old conversation history into a summary to free up the context window.

func Copy

func Copy(session *agent.Session) Command

Copy constructs the /copy command which writes the last assistant response to the system clipboard.

func Dream added in v0.3.0

func Dream(d *dream.Dreamer) Command

Dream constructs the /dream command: trigger a memory consolidation now, skipping the auto-trigger's time and session gates. The run happens in the background; /tasks shows progress and can kill it.

func Exit

func Exit() Command

Exit constructs the /exit command. Aliased as /quit and /q.

func Loop

func Loop(store *cron.Store) Command

Loop constructs the /loop command which schedules recurring prompts via the session-scoped cron store. With no args it prints usage; subcommands list/ stop manage existing jobs.

func MCP

func MCP(manager *mcpclient.Manager) Command

MCP constructs the /mcp command which lists configured MCP servers and their connection / tool counts.

func Memory

func Memory(cwd string, reloadSession func()) Command

Memory constructs the /memory command. With no args it prints the memory directory status; with `edit` it opens MEMORY.md in $EDITOR and reloads the session afterwards via the supplied callback.

func New

func New(session *agent.Session, resetPlanState func()) Command

New constructs the /new command which abandons the current session and starts a fresh one. Plan-mode UI state is reset alongside.

func NewSimple

func NewSimple(spec Spec, run func(inv Invocation) tea.Cmd) Command

NewSimple wraps a Spec and a run function as a Command. Used by commands whose entire behavior fits in a single function; complex commands (those that own modal state, interactive overlays, or multi-step dispatchers) implement Command/InteractiveCommand directly with their own struct.

func Reload

func Reload(reload func() (ReloadResult, error)) Command

Reload constructs the /reload command which rebuilds the plugin/skill/MCP runtime from disk. The host provides the reload callback returning the outcome counts (or an error to render).

type ContextCommand

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

ContextCommand drives /context — a tabbed modal overlay reporting current context window usage, message composition, and runtime suggestions.

func Context

func Context(session *agent.Session, overlay OverlayController) *ContextCommand

Context constructs the /context command.

func (*ContextCommand) Active

func (c *ContextCommand) Active() bool

func (*ContextCommand) Dismiss

func (c *ContextCommand) Dismiss()

func (*ContextCommand) HandleKey

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

func (*ContextCommand) IsModal

func (c *ContextCommand) IsModal() bool

func (*ContextCommand) Run

func (c *ContextCommand) Run(_ Invocation) tea.Cmd

func (*ContextCommand) Spec

func (c *ContextCommand) Spec() Spec

func (*ContextCommand) View

func (c *ContextCommand) View(width, height int) string

type DebugHarnessCommand

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

DebugHarnessCommand drives /debug-harness — a tabbed modal overlay surfacing harness runtime diagnostics (last turn, recent activity, metrics, context).

func DebugHarness

func DebugHarness(session *agent.Session, overlay OverlayController) *DebugHarnessCommand

DebugHarness constructs the /debug-harness command.

func (*DebugHarnessCommand) Active

func (c *DebugHarnessCommand) Active() bool

func (*DebugHarnessCommand) Dismiss

func (c *DebugHarnessCommand) Dismiss()

func (*DebugHarnessCommand) HandleKey

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

func (*DebugHarnessCommand) IsModal

func (c *DebugHarnessCommand) IsModal() bool

func (*DebugHarnessCommand) Run

func (*DebugHarnessCommand) Spec

func (c *DebugHarnessCommand) Spec() Spec

func (*DebugHarnessCommand) View

func (c *DebugHarnessCommand) View(width, height int) string

type DiffCommand added in v0.2.0

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

DiffCommand drives /diff — an interactive overlay listing the files the last turn changed (what /undo would roll back), with per-file added/removed counts.

func Diff added in v0.2.0

func Diff(session *agent.Session, overlay OverlayController) *DiffCommand

Diff constructs the /diff command.

func (*DiffCommand) Active added in v0.2.0

func (c *DiffCommand) Active() bool

func (*DiffCommand) Dismiss added in v0.2.0

func (c *DiffCommand) Dismiss()

func (*DiffCommand) HandleKey added in v0.2.0

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

func (*DiffCommand) IsModal added in v0.2.0

func (c *DiffCommand) IsModal() bool

func (*DiffCommand) Run added in v0.2.0

func (c *DiffCommand) Run(_ Invocation) tea.Cmd

func (*DiffCommand) Spec added in v0.2.0

func (c *DiffCommand) Spec() Spec

func (*DiffCommand) View added in v0.2.0

func (c *DiffCommand) View(width, height int) string

type GoalCommand added in v0.2.2

type GoalCommand struct {
	Create func(objective string, tokenBudget int) tea.Cmd
	Status func() tea.Cmd
	Pause  func() tea.Cmd
	Resume func(tokenBudget int) tea.Cmd
	Clear  func() tea.Cmd
}

func (*GoalCommand) Run added in v0.2.2

func (c *GoalCommand) Run(inv Invocation) tea.Cmd

func (*GoalCommand) Spec added in v0.2.2

func (c *GoalCommand) Spec() Spec

type HelpCommand

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

HelpCommand drives /help — a tabbed modal overlay listing general intro, built-in commands, custom (file/plugin) commands, and skills.

func Help

func Help(registry Registry) *HelpCommand

Help constructs the /help command. The registry is consumed both for listing peer commands and for installing the modal overlay.

func (*HelpCommand) Active

func (c *HelpCommand) Active() bool

func (*HelpCommand) Dismiss

func (c *HelpCommand) Dismiss()

func (*HelpCommand) HandleKey

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

func (*HelpCommand) IsModal

func (c *HelpCommand) IsModal() bool

func (*HelpCommand) Run

func (c *HelpCommand) Run(_ Invocation) tea.Cmd

func (*HelpCommand) Spec

func (c *HelpCommand) Spec() Spec

func (*HelpCommand) View

func (c *HelpCommand) View(width, height int) string

type InteractiveCommand

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

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

Implementations are modal by default — see ModalOverlay below for opting out.

View receives the available width AND height of the terminal viewport so implementations can clip or paginate their content. A height of 0 means "unconstrained" (legacy callers); implementations should treat any positive value as a hard upper bound to avoid having their headers scroll out of view.

type Invocation

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

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

func ParseInvocation

func ParseInvocation(input string) (Invocation, bool)

ParseInvocation parses a slash-command input like "/foo bar baz" into an Invocation. Returns ok=false for non-command input (empty, no leading "/", or only "/").

type Kind

type Kind string

Kind classifies how a command was contributed.

const (
	KindBuiltin Kind = "builtin"
	KindCustom  Kind = "custom"
	KindSkill   Kind = "skill"
)

type MCPReloadResult

type MCPReloadResult struct {
	Connected int
	Failed    int
	Tools     int
	Errors    []string
}

MCPReloadResult is the subset of MCP runtime status that plugin mutations surface back to the user. The host fills it in after rebuilding the MCP pool following a plugin enable/disable/trust/install/remove.

type ModalOverlay

type ModalOverlay interface {
	IsModal() bool
}

ModalOverlay is an optional interface used by overlays that want to opt out of the modal default. Overlays that intercept keyboard input (the typical case) replace the input area, so they don't need to implement this. Non-modal overlays — autocomplete-style hint panels that coexist with the input — must implement this and return false.

type ModelCommand

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

ModelCommand drives /model — an interactive selector that switches the current chat model and persists the choice to whichever settings file already owns the model setting (project if present, otherwise global).

func Model

func Model(session *agent.Session, overlay OverlayController, cwd string) *ModelCommand

Model constructs the /model command.

func (*ModelCommand) Active

func (c *ModelCommand) Active() bool

func (*ModelCommand) Dismiss

func (c *ModelCommand) Dismiss()

func (*ModelCommand) HandleKey

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

func (*ModelCommand) IsModal

func (c *ModelCommand) IsModal() bool

func (*ModelCommand) Run

func (c *ModelCommand) Run(_ Invocation) tea.Cmd

func (*ModelCommand) Spec

func (c *ModelCommand) Spec() Spec

func (*ModelCommand) View

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

type OverlayController

type OverlayController interface {
	SetOverlay(InteractiveCommand)
	ClearOverlay()
}

OverlayController is the surface needed to install or dismiss the active modal overlay. Most interactive commands (/btw, /context, /tasks, ...) take this directly because they never enumerate peers.

type PlanCommand

type PlanCommand struct {
	Phase  func() plan.Phase
	Enter  func() tea.Cmd
	Show   func() tea.Cmd
	Cancel func() tea.Cmd
	Open   func() tea.Cmd
}

PlanCommand drives /plan — entering plan mode or managing the active plan. The plan state machine (review modal, key handling, agentcore event hooks) stays in the ui package because it spans multiple TUI subsystems; this command only routes the slash-command surface into it via the callbacks below.

func (*PlanCommand) Run

func (c *PlanCommand) Run(inv Invocation) tea.Cmd

func (*PlanCommand) Spec

func (c *PlanCommand) Spec() Spec

type PluginsCommand

type PluginsCommand struct {
	Catalog        *plugin.Catalog
	Session        *agent.Session
	Cwd            string
	ReloadState    func() error
	RefreshRuntime func() (MCPReloadResult, error)
}

PluginsCommand drives /plugins — a multi-subcommand entry that inspects and mutates the plugin catalog. The fields below are the host hooks the mutating paths need; construct with a struct literal at registration time.

func (*PluginsCommand) Run

func (p *PluginsCommand) Run(inv Invocation) tea.Cmd

func (*PluginsCommand) Spec

func (p *PluginsCommand) Spec() Spec

type RedoCommand added in v0.2.0

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

RedoCommand drives /redo — it re-applies the file changes undone by the last /undo, returning the workspace to the state just before that undo. A new turn (fresh edits) clears the redo branch.

func Redo added in v0.2.0

func Redo(session *agent.Session) *RedoCommand

Redo constructs the /redo command.

func (*RedoCommand) Run added in v0.2.0

func (c *RedoCommand) Run(_ Invocation) tea.Cmd

func (*RedoCommand) Spec added in v0.2.0

func (c *RedoCommand) Spec() Spec

type Registry

type Registry interface {
	OverlayController
	All() []Command
	EffectiveSpec(cmd Command) Spec
}

Registry extends OverlayController with peer-enumeration methods used by /help. ui.Registry is the only implementation; everywhere except /help takes OverlayController directly so its dependency surface stays narrow.

type ReloadResult

type ReloadResult struct {
	Commands     int
	Skills       int
	MCPTools     int
	MCPConnected int
	MCPFailed    int
}

ReloadResult summarises the outcome of a /reload run, used to render the terminal feedback line. The host App fills in the counts after reloading plugin / skill / MCP state.

type ResumeCommand

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

ResumeCommand drives /resume — an interactive overlay listing recent sessions and switching to the chosen one.

func Resume

func Resume(session *agent.Session, overlay OverlayController, resetPlan func(), afterSwitch func() error) *ResumeCommand

Resume constructs the /resume command. resetPlan tears down any active plan-mode UI when switching sessions, mirroring /clear and /new.

func (*ResumeCommand) Active

func (c *ResumeCommand) Active() bool

func (*ResumeCommand) Dismiss

func (c *ResumeCommand) Dismiss()

func (*ResumeCommand) HandleKey

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

func (*ResumeCommand) IsModal

func (c *ResumeCommand) IsModal() bool

func (*ResumeCommand) Run

func (c *ResumeCommand) Run(_ Invocation) tea.Cmd

func (*ResumeCommand) Spec

func (c *ResumeCommand) Spec() Spec

func (*ResumeCommand) View

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

type SettingsCommand

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

SettingsCommand drives /settings — a tabbed modal overlay reporting the current general / runtime / providers configuration.

func Settings

func Settings(session *agent.Session, overlay OverlayController, approvalEngine *approval.Engine, cwd string) *SettingsCommand

Settings constructs the /settings command.

func (*SettingsCommand) Active

func (c *SettingsCommand) Active() bool

func (*SettingsCommand) Dismiss

func (c *SettingsCommand) Dismiss()

func (*SettingsCommand) HandleKey

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

func (*SettingsCommand) IsModal

func (c *SettingsCommand) IsModal() bool

func (*SettingsCommand) Run

func (c *SettingsCommand) Run(_ Invocation) tea.Cmd

func (*SettingsCommand) Spec

func (c *SettingsCommand) Spec() Spec

func (*SettingsCommand) View

func (c *SettingsCommand) View(width, height int) string

type Spec

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

Spec describes command metadata used by the registry, palette, and help command.

type StatusCommand

type StatusCommand struct {
	Session   *agent.Session
	Overlay   OverlayController
	Approval  *approval.Engine
	Plugins   *plugin.Catalog
	MCP       *mcpclient.Manager
	Cron      *cron.Store
	PlanPhase func() plan.Phase

	Cwd       string
	GitBranch string
	Version   string

	// SkillCount / CommandCount are read on every render so /reload-driven
	// changes are reflected without re-registering the command.
	SkillCount   func() int
	CommandCount func() int
	// contains filtered or unexported fields
}

StatusCommand drives /status — a tabbed modal overlay reporting the live runtime snapshot of the current session: who you are, what you're running, what you've spent, and what's plugged in.

/status answers "what does the agent look like *right now*". /settings is the static config side of the same coin; /debug-harness is the internal observability side. The three should never duplicate each other.

func (*StatusCommand) Active

func (c *StatusCommand) Active() bool

func (*StatusCommand) Dismiss

func (c *StatusCommand) Dismiss()

func (*StatusCommand) HandleKey

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

func (*StatusCommand) IsModal

func (c *StatusCommand) IsModal() bool

func (*StatusCommand) Run

func (c *StatusCommand) Run(_ Invocation) tea.Cmd

func (*StatusCommand) Spec

func (c *StatusCommand) Spec() Spec

func (*StatusCommand) View

func (c *StatusCommand) View(width, height int) string

type TasksCommand

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

TasksCommand drives /tasks — an interactive overlay listing background shells and forked sub-agents, with detail and stop controls.

func Tasks

func Tasks(runtime *task.Runtime, overlay OverlayController) *TasksCommand

Tasks constructs the /tasks command.

func (*TasksCommand) Active

func (c *TasksCommand) Active() bool

func (*TasksCommand) Dismiss

func (c *TasksCommand) Dismiss()

func (*TasksCommand) HandleKey

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

func (*TasksCommand) IsModal

func (c *TasksCommand) IsModal() bool

func (*TasksCommand) Run

func (c *TasksCommand) Run(_ Invocation) tea.Cmd

func (*TasksCommand) Spec

func (c *TasksCommand) Spec() Spec

func (*TasksCommand) View

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

type UndoCommand added in v0.2.0

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

UndoCommand drives /undo — it reverts workspace files to the start of the most recent turn, undoing the agent's last round of edits. Conversation history is left untouched.

func Undo added in v0.2.0

func Undo(session *agent.Session) *UndoCommand

Undo constructs the /undo command.

func (*UndoCommand) Run added in v0.2.0

func (c *UndoCommand) Run(_ Invocation) tea.Cmd

func (*UndoCommand) Spec added in v0.2.0

func (c *UndoCommand) Spec() Spec

type WorktreeCommand added in v0.3.0

type WorktreeCommand struct {
	Enter  func(name string) (string, error)
	Exit   func(discard bool) (string, error)
	Active func() bool
}

WorktreeCommand drives /worktree — an isolated git-worktree sandbox the session works in, reviewed and merged or discarded on exit.

/worktree <name>   create a sandbox and move the session into it
/worktree exit     return to the main workspace, keeping changes for review
/worktree discard  return to the main workspace, discarding the sandbox

Enter/Exit are wired to the runtime and return a ready-to-display message. They are nil outside the interactive TUI, where the command is unavailable.

func (*WorktreeCommand) Run added in v0.3.0

func (c *WorktreeCommand) Run(inv Invocation) tea.Cmd

func (*WorktreeCommand) Spec added in v0.3.0

func (c *WorktreeCommand) Spec() Spec

Jump to

Keyboard shortcuts

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