Module commands

Module commands 

Source
Expand description

Slash command system. Slash command system for the TUI.

This module provides a trait-based command system that allows:

  • Framework-provided standard commands (clear, help, themes, etc.)
  • Custom commands via closures or trait implementations
  • Agent-specific context data accessible to commands

§Quick Start

Use the default commands:

use agent_core::tui::commands::CommandRegistry;

// Use all default commands
let commands = CommandRegistry::with_defaults().build();
agent.set_commands(commands);

§Custom Commands

Add custom commands alongside defaults:

use agent_core::tui::commands::{CommandRegistry, CustomCommand, CommandResult};

let commands = CommandRegistry::with_defaults()
    .add(CustomCommand::new("deploy", "Deploy the application", |args, ctx| {
        CommandResult::Message(format!("Deploying to {}...", args))
    }))
    .remove("quit")  // Optionally remove commands
    .build();

§Extension Context

Provide agent-specific data to commands:

struct MyAgentContext {
    api_key: String,
    environments: Vec<String>,
}

agent.set_command_extension(MyAgentContext {
    api_key: "secret".into(),
    environments: vec!["staging".into(), "prod".into()],
});

// In command:
CustomCommand::new("deploy", "Deploy app", |args, ctx| {
    let my_ctx = ctx.extension::<MyAgentContext>().expect("context required");
    if my_ctx.environments.contains(&args.to_string()) {
        CommandResult::Message(format!("Deploying to {}...", args))
    } else {
        CommandResult::Error(format!("Unknown environment: {}", args))
    }
})

Structs§

ClearCommand
Clear the conversation history.
CommandContext
Context provided to commands during execution.
CommandRegistry
Registry of slash commands for an agent.
CompactCommand
Compact the conversation history.
CustomCommand
A simple custom command using a closure.
HelpCommand
Show available commands and usage.
NewSessionCommand
Create a new LLM session.
QuitCommand
Exit the application.
SessionsCommand
View and switch between sessions.
StatusCommand
Show current session status.
ThemesCommand
Open the theme picker to change colors.
VersionCommand
Show application version.

Enums§

CommandResult
Result of executing a slash command.
PendingAction
Actions that require App-level handling after command returns.

Traits§

SlashCommand
Trait for slash commands.

Functions§

default_commands
Returns the standard set of commands most agents will want.
filter_commands
Filter commands that match the given input prefix.
generate_help_message
Generate help message listing all available commands.
get_command_by_name
Get a command by its exact name.
is_slash_command
Check if input starts with a slash command.
parse_command
Parse slash command from input, returning (command_name, args).