command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package command provides slash command implementations for the TUI. This file adds team-related slash commands for the Team collaboration mode.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrQuit signals the main loop to exit gracefully.
	ErrQuit = fmt.Errorf("quit")
)

sentinel errors used by the TUI main loop to detect special commands.

Functions

func RegisterBuiltins

func RegisterBuiltins(r *Registry)

RegisterBuiltins adds all built-in slash commands to the registry.

func RegisterTeamCommands

func RegisterTeamCommands(r *Registry)

RegisterTeamCommands registers all team-related slash commands.

Types

type Command

type Command interface {
	// Name returns the command name without the leading '/'
	Name() string

	// Aliases returns alternative names for the command.
	Aliases() []string

	// Description returns a short help string shown in /help and completion.
	Description() string

	// Execute runs the command. The args string contains everything
	// after the command name (trimmed).
	Execute(ctx context.Context, env *Env, args string) error
}

Command is the interface that all slash commands must implement.

type CreateTeamReq

type CreateTeamReq struct {
	TemplateID      string
	Name            string
	TaskDescription string
	Strategy        string
}

CreateTeamReq is the request for creating a team.

type Env

type Env struct {
	// Out is the output writer (usually os.Stdout).
	Out io.Writer

	// ClearHistory resets the conversation message history
	ClearHistory func()

	// Model returns the current the conversation message history
	Model func() string

	// SessionKey returns the current session identifier.
	SessionKey func() string

	// TeamState holds the current active team state (nil if no team).
	TeamState *TeamState

	// SetTeamState updates the TUI's team state (called by team commands).
	SetTeamState func(state *TeamState)

	// TeamAPI provides the backend API for team operations.
	TeamAPI TeamAPI
}

Env provides the runtime environment that commands can interact with. It is passed to every command's Execute method.

type Registry

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

Registry manages all registered slash commands.

It provides lookup by name or alias, prefix-based completion, and formatted help output.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty command registry.

func (*Registry) CommandInfos

func (r *Registry) CommandInfos() []input.CommandInfo

CommandInfos returns metadata for all commands, suitable for the input completer.

func (*Registry) Help

func (r *Registry) Help() string

Help returns a formatted help string listing all commands.

func (*Registry) Lookup

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

Lookup resolves user input to a Command and its argument string. The input should include the leading '/'. Returns (nil, "", false) if no match is found.

Example:

cmd, args, ok := registry.Lookup("/model gpt-4")
// cmd = *modelCmd, args = "gpt-4", ok = true

func (*Registry) Register

func (r *Registry) Register(cmd Command)

Register adds a command to the registry. It panics if the name or any alias conflicts with an existing entry.

type TeamAPI

type TeamAPI interface {
	// ListTemplates returns available team templates.
	ListTemplates(ctx context.Context) ([]TemplateInfo, error)

	// CreateTeam creates a team from a template or ad-hoc.
	CreateTeam(ctx context.Context, req CreateTeamReq) (*TeamState, error)

	// GetTeam returns the current team state.
	GetTeam(ctx context.Context, teamID string) (*TeamState, error)

	// DissolveTeam dissolves the current team.
	DissolveTeam(ctx context.Context, teamID string) error

	// SendMessage sends a message to a specific team member.
	SendMessage(ctx context.Context, teamID, recipientLabel, content string) error

	// Broadcast sends a message to all team members.
	Broadcast(ctx context.Context, teamID, content string) error
}

TeamAPI defines the interface the TUI needs for team operations. This decouples the TUI from the concrete HTTP client / server-side implementation.

type TeamMemberState

type TeamMemberState struct {
	ID        string
	SessionID string
	Label     string
	Role      string
	Status    string // idle, running, completed, failed
	Progress  string
	IsLeader  bool
	NodeID    string
}

TeamMemberState represents a team member's status for display.

func (*TeamMemberState) RoleIcon

func (m *TeamMemberState) RoleIcon() string

RoleIcon returns the appropriate icon for the member's role.

func (*TeamMemberState) StatusIcon

func (m *TeamMemberState) StatusIcon() string

StatusIcon returns the appropriate icon for the member's status.

type TeamState

type TeamState struct {
	// Enabled indicates whether a team is currently active.
	Enabled bool

	// ID is the current team's ID.
	ID string

	// Name is the current team's name.
	Name string

	// Strategy is the team's coordination strategy.
	Strategy string

	// Members lists the current team members and their states.
	Members []TeamMemberState

	// FocusIndex tracks which member is currently focused (-1 = none).
	FocusIndex int
}

TeamState holds the current team state exposed to commands. The TUI sets this on the Env before executing team commands.

type TemplateInfo

type TemplateInfo struct {
	ID          string
	Name        string
	Description string
	Strategy    string
	MemberCount int
}

TemplateInfo is a summary of a team template for display.

Jump to

Keyboard shortcuts

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