Skip to main content

synaps_cli/tools/shell/
end.rs

1//! `shell_end` tool — close an interactive shell session.
2
3use serde_json::{json, Value};
4use crate::{Result, RuntimeError};
5use crate::tools::{Tool, ToolContext};
6
7pub struct ShellEndTool;
8
9#[async_trait::async_trait]
10impl Tool for ShellEndTool {
11    fn name(&self) -> &str { "shell_end" }
12
13    fn description(&self) -> &str {
14        "Close an interactive shell session and clean up resources. Returns the final output if any."
15    }
16
17    fn parameters(&self) -> Value {
18        json!({
19            "type": "object",
20            "properties": {
21                "session_id": {
22                    "type": "string",
23                    "description": "Session ID to close"
24                }
25            },
26            "required": ["session_id"]
27        })
28    }
29
30    async fn execute(&self, params: Value, ctx: ToolContext) -> Result<String> {
31        let mgr = ctx.capabilities.session_manager.as_ref()
32            .ok_or_else(|| RuntimeError::Tool("Shell sessions not available".into()))?;
33        
34        let session_id = params["session_id"].as_str()
35            .ok_or_else(|| RuntimeError::Tool("Missing session_id parameter".into()))?;
36        
37        let output = mgr.close_session(session_id).await?;
38        
39        if output.is_empty() {
40            Ok(format!("[Session {} closed]", session_id))
41        } else {
42            Ok(format!("{}\n[Session {} closed]", output, session_id))
43        }
44    }
45}