Skip to main content

claude_rust_tools/infrastructure/
task_stop_tool.rs

1use std::sync::Arc;
2
3use claude_rust_errors::{AppError, AppResult};
4use claude_rust_types::{PermissionLevel, Tool};
5use serde_json::{Value, json};
6
7use super::task_manager::TaskManager;
8
9pub struct TaskStopTool {
10    manager: Arc<dyn TaskManager>,
11}
12
13impl TaskStopTool {
14    pub fn new(manager: Arc<dyn TaskManager>) -> Self {
15        Self { manager }
16    }
17}
18
19#[async_trait::async_trait]
20impl Tool for TaskStopTool {
21    fn name(&self) -> &str {
22        "task_stop"
23    }
24
25    fn description(&self) -> &str {
26        "Stop and delete a running task by its ID."
27    }
28
29    fn input_schema(&self) -> Value {
30        json!({
31            "type": "object",
32            "properties": {
33                "task_id": {
34                    "type": "string",
35                    "description": "The ID of the task to stop"
36                }
37            },
38            "required": ["task_id"]
39        })
40    }
41
42    fn permission_level(&self) -> PermissionLevel {
43        PermissionLevel::Dangerous
44    }
45
46    async fn execute(&self, input: Value) -> AppResult<String> {
47        let task_id = input
48            .get("task_id")
49            .and_then(|v| v.as_str())
50            .ok_or_else(|| AppError::Tool("missing 'task_id' field".into()))?;
51
52        self.manager.stop(task_id).await?;
53
54        Ok(format!("Task {task_id} stopped"))
55    }
56}