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§
- Clear
Command - Clear the conversation history.
- Command
Context - Context provided to commands during execution.
- Command
Registry - Registry of slash commands for an agent.
- Compact
Command - Compact the conversation history.
- Custom
Command - A simple custom command using a closure.
- Help
Command - Show available commands and usage.
- NewSession
Command - Create a new LLM session.
- Quit
Command - Exit the application.
- Sessions
Command - View and switch between sessions.
- Status
Command - Show current session status.
- Themes
Command - Open the theme picker to change colors.
- Version
Command - Show application version.
Enums§
- Command
Result - Result of executing a slash command.
- Pending
Action - Actions that require App-level handling after command returns.
Traits§
- Slash
Command - 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).