agent_core/tui/commands/
mod.rs

1//! Slash command system for the TUI.
2//!
3//! This module provides a trait-based command system that allows:
4//! - Framework-provided standard commands (clear, help, themes, etc.)
5//! - Custom commands via closures or trait implementations
6//! - Agent-specific context data accessible to commands
7//!
8//! # Quick Start
9//!
10//! Use the default commands:
11//!
12//! ```ignore
13//! use agent_core::tui::commands::CommandRegistry;
14//!
15//! // Use all default commands
16//! let commands = CommandRegistry::with_defaults().build();
17//! agent.set_commands(commands);
18//! ```
19//!
20//! # Custom Commands
21//!
22//! Add custom commands alongside defaults:
23//!
24//! ```ignore
25//! use agent_core::tui::commands::{CommandRegistry, CustomCommand, CommandResult};
26//!
27//! let commands = CommandRegistry::with_defaults()
28//!     .add(CustomCommand::new("deploy", "Deploy the application", |args, ctx| {
29//!         CommandResult::Message(format!("Deploying to {}...", args))
30//!     }))
31//!     .remove("quit")  // Optionally remove commands
32//!     .build();
33//! ```
34//!
35//! # Extension Context
36//!
37//! Provide agent-specific data to commands:
38//!
39//! ```ignore
40//! struct MyAgentContext {
41//!     api_key: String,
42//!     environments: Vec<String>,
43//! }
44//!
45//! agent.set_command_extension(MyAgentContext {
46//!     api_key: "secret".into(),
47//!     environments: vec!["staging".into(), "prod".into()],
48//! });
49//!
50//! // In command:
51//! CustomCommand::new("deploy", "Deploy app", |args, ctx| {
52//!     let my_ctx = ctx.extension::<MyAgentContext>().expect("context required");
53//!     if my_ctx.environments.contains(&args.to_string()) {
54//!         CommandResult::Message(format!("Deploying to {}...", args))
55//!     } else {
56//!         CommandResult::Error(format!("Unknown environment: {}", args))
57//!     }
58//! })
59//! ```
60
61mod context;
62mod custom;
63mod helpers;
64mod registry;
65mod result;
66mod standard;
67mod traits;
68
69// Re-export main types
70pub use context::{CommandContext, PendingAction};
71pub use custom::CustomCommand;
72pub use helpers::{filter_commands, generate_help_message, get_command_by_name, is_slash_command, parse_command};
73pub use registry::CommandRegistry;
74pub use result::CommandResult;
75pub use traits::SlashCommand;
76
77// Re-export standard commands
78pub use standard::{
79    default_commands, ClearCommand, CompactCommand, HelpCommand, NewSessionCommand, QuitCommand,
80    SessionsCommand, StatusCommand, ThemesCommand, VersionCommand,
81};