Skip to main content

elizaos_plugin_shell/
lib.rs

1#![allow(missing_docs)]
2
3use async_trait::async_trait;
4use serde_json::Value;
5
6mod error;
7mod path_utils;
8mod service;
9mod types;
10
11pub mod actions;
12pub mod providers;
13
14pub use error::{Result, ShellError};
15pub use path_utils::{
16    extract_base_command, is_forbidden_command, is_safe_command, validate_path,
17    DEFAULT_FORBIDDEN_COMMANDS,
18};
19pub use service::ShellService;
20pub use types::{
21    CommandHistoryEntry, CommandResult, FileOperation, FileOperationType, ShellConfig,
22    ShellConfigBuilder,
23};
24
25pub use actions::{get_shell_actions, ClearHistoryAction, ExecuteCommandAction};
26pub use providers::{get_shell_providers, ShellHistoryProvider};
27
28pub const PLUGIN_NAME: &str = "shell";
29pub const PLUGIN_DESCRIPTION: &str =
30    "Execute shell commands within a restricted directory with history tracking";
31pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");
32
33#[derive(Debug, Clone)]
34pub struct ActionExample {
35    pub user_message: String,
36    pub agent_response: String,
37}
38
39#[derive(Debug, Clone)]
40pub struct ActionResult {
41    pub success: bool,
42    pub text: String,
43    pub data: Option<Value>,
44    pub error: Option<String>,
45}
46
47#[derive(Debug, Clone)]
48pub struct ProviderResult {
49    pub values: Value,
50    pub text: String,
51    pub data: Value,
52}
53
54#[async_trait]
55pub trait Action: Send + Sync {
56    fn name(&self) -> &str;
57    fn similes(&self) -> Vec<&str>;
58    fn description(&self) -> &str;
59    async fn validate(&self, message: &Value, state: &Value) -> bool;
60    async fn handler(
61        &self,
62        message: &Value,
63        state: &Value,
64        service: Option<&mut ShellService>,
65    ) -> ActionResult;
66    fn examples(&self) -> Vec<ActionExample>;
67}
68
69#[async_trait]
70pub trait Provider: Send + Sync {
71    fn name(&self) -> &str;
72    fn description(&self) -> &str;
73    fn position(&self) -> i32;
74    async fn get(
75        &self,
76        message: &Value,
77        state: &Value,
78        service: Option<&ShellService>,
79    ) -> ProviderResult;
80}
81
82pub mod prelude {
83    pub use crate::actions::{ClearHistoryAction, ExecuteCommandAction};
84    pub use crate::error::{Result, ShellError};
85    pub use crate::providers::ShellHistoryProvider;
86    pub use crate::service::ShellService;
87    pub use crate::types::{CommandHistoryEntry, CommandResult, FileOperation, ShellConfig};
88    pub use crate::{Action, ActionExample, ActionResult, Provider, ProviderResult};
89}