pub struct ShellExecutor { /* private fields */ }Expand description
Bash block extraction and execution via tokio::process::Command.
Parses ```bash fenced blocks from LLM responses (legacy path) and handles
structured bash tool calls (modern path). Use ShellExecutor::new with a
ShellConfig and chain optional builder methods to attach audit logging,
event streaming, permission policies, and cancellation.
§Example
use zeph_tools::{ShellExecutor, ToolExecutor, config::ShellConfig};
let executor = ShellExecutor::new(&ShellConfig::default());
// Execute a fenced bash block.
let response = "```bash\npwd\n```";
if let Ok(Some(output)) = executor.execute(response).await {
println!("{}", output.summary);
}Implementations§
Source§impl ShellExecutor
impl ShellExecutor
Sourcepub fn new(config: &ShellConfig) -> Self
pub fn new(config: &ShellConfig) -> Self
Create a new ShellExecutor from configuration.
Merges the built-in DEFAULT_BLOCKED_COMMANDS with any additional blocked
commands from config, then subtracts any explicitly allowed commands.
No subprocess is spawned at construction time.
Sourcepub fn set_skill_env(&self, env: Option<HashMap<String, String>>)
pub fn set_skill_env(&self, env: Option<HashMap<String, String>>)
Set environment variables to inject when executing the active skill’s bash blocks.
Sourcepub fn with_audit(self, logger: Arc<AuditLogger>) -> Self
pub fn with_audit(self, logger: Arc<AuditLogger>) -> Self
Attach an audit logger. Each shell invocation will emit an AuditEntry.
Sourcepub fn with_tool_event_tx(self, tx: ToolEventTx) -> Self
pub fn with_tool_event_tx(self, tx: ToolEventTx) -> Self
Attach a tool-event sender for streaming output to the TUI or channel adapter.
When set, ToolEvent::Started, ToolEvent::OutputChunk, and
ToolEvent::Completed events are sent on tx during execution.
Sourcepub fn with_permissions(self, policy: PermissionPolicy) -> Self
pub fn with_permissions(self, policy: PermissionPolicy) -> Self
Attach a permission policy for confirmation-gate enforcement.
Commands matching the policy’s rules may require user approval before execution proceeds.
Sourcepub fn with_cancel_token(self, token: CancellationToken) -> Self
pub fn with_cancel_token(self, token: CancellationToken) -> Self
Attach a cancellation token. When the token is cancelled, the running subprocess
is killed and the executor returns ToolError::Cancelled.
Sourcepub fn with_output_filters(self, registry: OutputFilterRegistry) -> Self
pub fn with_output_filters(self, registry: OutputFilterRegistry) -> Self
Attach an output filter registry. Filters are applied to stdout+stderr before
the summary is stored in ToolOutput and sent to the LLM.
Sourcepub async fn execute_confirmed(
&self,
response: &str,
) -> Result<Option<ToolOutput>, ToolError>
pub async fn execute_confirmed( &self, response: &str, ) -> Result<Option<ToolOutput>, ToolError>
Execute a bash block bypassing the confirmation check (called after user confirms).
§Errors
Returns ToolError on blocked commands, sandbox violations, or execution failures.
Trait Implementations§
Source§impl Debug for ShellExecutor
impl Debug for ShellExecutor
Source§impl ToolExecutor for ShellExecutor
impl ToolExecutor for ShellExecutor
Source§async fn execute(&self, response: &str) -> Result<Option<ToolOutput>, ToolError>
async fn execute(&self, response: &str) -> Result<Option<ToolOutput>, ToolError>
response for fenced tool blocks and execute them. Read more