commands

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package commands implements the slash-command registry for conduit.

Mirrors src/commands/ from the TS source. Each command is a function that receives the argument string and returns a Result. The TUI dispatches slash commands before sending to the agent loop.

Package commands — status output styling helpers.

Slash commands return Result{Type: "text"} and the TUI renders the text as a system message. To make labeled status output readable on dark backgrounds we embed ANSI escape sequences directly. The TUI render layer renders the "· " prefix dim and lets these escapes show through.

All ANSI escape constants derive from theme.Active() and rebuild on theme switch via theme.OnChange.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAccountCommand

func RegisterAccountCommand(r *Registry)

RegisterAccountCommand adds the /account slash command.

func RegisterBuddyCommand

func RegisterBuddyCommand(r *Registry, getUserID func() string)

RegisterBuddyCommand adds /buddy to display and manage the companion.

func RegisterBuiltins

func RegisterBuiltins(r *Registry)

RegisterBuiltins adds the standard slash commands to r. compact and model commands that need external state are wired in the TUI.

func RegisterBundledSkillCommands

func RegisterBundledSkillCommands(r *Registry)

RegisterBundledSkillCommands registers slash commands for built-in skills (/simplify, /remember, etc.). These run the skill body as a user prompt, same flow as plugin slash commands.

func RegisterCompactCommand

func RegisterCompactCommand(r *Registry)

RegisterCompactCommand adds /compact that callers implement by returning Type=="compact".

func RegisterCoordinatorCommand

func RegisterCoordinatorCommand(r *Registry)

RegisterCoordinatorCommand adds /coordinator that toggles coordinator mode on/off. When active, the agent acts as an orchestrator managing sub-agent workers.

func RegisterHooksCommand

func RegisterHooksCommand(r *Registry, hooksConfig *settings.HooksSettings)

RegisterHooksCommand adds /hooks showing configured hook matchers.

func RegisterMCPApproveCommand

func RegisterMCPApproveCommand(r *Registry, manager *mcp.Manager, cwd string)

RegisterMCPApproveCommand registers /mcp-approve, the back-end for the startup approval picker. Args: "<server-name> <yes|yes_all|no>". Persists the choice to user settings then triggers a reconnect for "yes"/"yes_all".

func RegisterMCPCommand

func RegisterMCPCommand(r *Registry, manager *mcp.Manager)

RegisterMCPCommand registers /mcp — interactive MCP server browser.

func RegisterMiscCommands

func RegisterMiscCommands(r *Registry)

RegisterMiscCommands adds miscellaneous slash commands.

func RegisterModelCommand

func RegisterModelCommand(r *Registry, getModel func() string, setModel func(string))

RegisterModelCommand adds /model with the current model name and a setter.

func RegisterOutputStyleCommand

func RegisterOutputStyleCommand(r *Registry, cwd string)

RegisterOutputStyleCommand adds /output-style to list and activate output styles.

func RegisterPermissionsCommand

func RegisterPermissionsCommand(r *Registry, gate *permissions.Gate)

RegisterPermissionsCommand adds /permissions showing current mode and allow/deny/ask lists.

func RegisterPluginBrowserCommand

func RegisterPluginBrowserCommand(r *Registry, ps []*plugins.Plugin)

RegisterPluginBrowserCommand registers /plugin and its subcommands.

func RegisterPluginCommands

func RegisterPluginCommands(r *Registry, ps []*plugins.Plugin)

RegisterPluginCommands registers slash commands for all loaded plugins.

func RegisterPromptCommands

func RegisterPromptCommands(r *Registry)

RegisterPromptCommands registers slash commands that inject a canned prompt into the agent as a user turn. Mirrors the "type: prompt" commands in src/commands/ of the TS source.

func RegisterRTKCommands

func RegisterRTKCommands(r *Registry)

RegisterRTKCommands adds /rtk gain and /rtk discover slash commands.

func RegisterRecordingCommand

func RegisterRecordingCommand(r *Registry)

RegisterRecordingCommand registers the /record slash command.

Usage:

/record            — toggle: start if not recording, stop if recording
/record start      — start recording
/record stop       — stop recording

The recording is written to ~/.claude/recordings/<timestamp>.cast in asciicast v2 format, readable by asciinema play.

func RegisterSessionCommands

func RegisterSessionCommands(r *Registry, state *SessionState)

RegisterSessionCommands registers all session-dependent slash commands.

func RegisterSkillsCommand

func RegisterSkillsCommand(r *Registry, ps []*plugins.Plugin)

RegisterSkillsCommand registers /skills — lists available skills from installed plugins.

func RegisterTerminalSetupCommand

func RegisterTerminalSetupCommand(r *Registry)

RegisterTerminalSetupCommand adds /terminalSetup, which detects the user's terminal via TERM_PROGRAM and prints either:

  • "no setup needed" for native CSI-u terminals, or
  • the exact manual recipe for terminals that need configuration (Apple Terminal, VSCode, Cursor, Windsurf, Alacritty, Zed).

Mirrors src/commands/terminalSetup/terminalSetup.tsx — currently info-only (the user runs the recipe themselves). The plist/keybindings. json automation in CC's source is a future commit; doing it info-only first keeps user dotfiles untouched until we ship a tested backup/restore path.

Types

type Command

type Command struct {
	Name        string
	Description string
	Handler     Handler
}

Command describes one slash command.

type Handler

type Handler func(args string) Result

Handler is a slash command implementation.

type PickerOption

type PickerOption struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

PickerOption is one row in the small generic picker overlay used by /theme, /model, and /output-style. Exported because the TUI parses these via JSON (see model.go renderPicker).

type PluginPanelData

type PluginPanelData struct {
	Installed    []PluginPanelInstalledEntry `json:"installed"`
	Marketplaces []PluginPanelMarketplaceRow `json:"marketplaces"`
	Errors       []string                    `json:"errors"`
}

PluginPanelData is the JSON payload sent via "plugin-panel" result.

type PluginPanelInstalledEntry

type PluginPanelInstalledEntry struct {
	ID          string `json:"id"` // "name@marketplace"
	Name        string `json:"name"`
	Marketplace string `json:"marketplace"`
	Version     string `json:"version"`
	Scope       string `json:"scope"`
	Enabled     bool   `json:"enabled"`
	InstallPath string `json:"installPath"`
}

PluginPanelInstalledEntry is one installed plugin entry for the panel.

type PluginPanelMarketplaceRow

type PluginPanelMarketplaceRow struct {
	Name        string `json:"name"`
	Source      string `json:"source"` // human-readable source string
	LastUpdated string `json:"lastUpdated"`
	PluginCount int    `json:"pluginCount"` // from marketplace.json, 0 if unavailable
}

PluginPanelMarketplaceRow is one marketplace row for the panel.

type Registry

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

Registry holds all registered slash commands.

func New

func New() *Registry

New returns an empty Registry.

func (*Registry) All

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

All returns all commands sorted by name.

func (*Registry) Dispatch

func (r *Registry) Dispatch(input string) (Result, bool)

Dispatch runs the command for input (which may or may not start with "/"). Returns (result, true) if the command was found, (zero, false) otherwise.

func (*Registry) Register

func (r *Registry) Register(cmd Command)

Register adds a command. Overwrites any existing command with the same name.

type Result

type Result struct {
	// Type is "text", "clear", "model", "compact", "prompt", "error", etc.
	Type string
	// Text is the message to display or the prompt to inject (for Type=="prompt").
	Text string
	// Model is the new model name (for Type=="model").
	Model string
}

Result is what a command returns to the TUI.

type SessionState

type SessionState struct {
	GetCost    func() string
	GetVimMode func() bool
	SetVimMode func(bool)
	GetEffort  func() string
	SetEffort  func(string)
	GetFast    func() bool
	SetFast    func(bool)
	Logout     func() error
	GetHistory func() []string // message contents for /files, /context
	GetCwd     func() string
	// Rewind removes the last n conversation turns from in-memory history.
	// Returns the number of turns actually removed.
	Rewind func(n int) int
	// SearchTranscript searches all session transcripts for cwd and returns results.
	SearchTranscript func(term string) string
	// GetTokens returns current (inputTokens, outputTokens, costUSD) from LiveState.
	GetTokens func() (int, int, float64)
	// GetTurnCosts returns the per-turn cost deltas for the current session.
	GetTurnCosts func() []float64
	// GetStatus returns a one-line status string (model, mode, session ID, cost, context %).
	GetStatus func() string
	// GetTasks returns a formatted list of active TaskTool tasks.
	GetTasks func() string
	// GetAgents returns a formatted list of active sub-agents.
	GetAgents func() string
	// GetLastThinking returns the last assistant thinking blocks as text.
	GetLastThinking func() string
	// GetColor returns the current ANSI color toggle state.
	GetColor func() bool
	// SetColor sets the ANSI color toggle.
	SetColor func(bool)
	// CopyLastResponse copies the last assistant response to clipboard.
	// Returns "" on success, error message otherwise.
	CopyLast func() string
	// RenameSession sets the title of the current session.
	RenameSession func(title string) error
	// TagSession assigns a tag label to the current session. Empty clears.
	TagSession func(tag string) error
	// GetSessionTag returns the active tag for the current session ("" if none).
	GetSessionTag func() string
	// GetSessionFiles returns (reads, writes) file paths from session JSONL.
	GetSessionFiles func() (reads, writes []string)
	// GetRateLimitWarning returns the current rate limit warning string (empty if none).
	GetRateLimitWarning func() string
	// CheckAuth returns nil if the current bearer token is valid, error otherwise.
	CheckAuth func() error
	// ExtractMemory triggers the memory extraction sub-agent over the recent
	// conversation. Returns a brief status string (or error). Wired in run.go
	// because the sub-agent runner lives on the agent.Loop.
	ExtractMemory func() (string, error)
	// GetSessionInfo returns session ID, file path, message count, and start time.
	GetSessionInfo func() (id, path string, messages int, startedAt time.Time)
	// GetSessionActivity returns last-activity time for idle reporting in /session.
	GetSessionActivity func() time.Time
	// GetKeybindings returns the flat binding list from the active resolver so
	// /keybindings can show actual (including user-customized) bindings.
	GetKeybindings func() []keybindings.Binding
}

SessionState holds mutable session state that slash commands can read/modify.

Jump to

Keyboard shortcuts

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