claude_rust_tools/infrastructure/
task_get_tool.rs1use 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 TaskGetTool {
10 manager: Arc<dyn TaskManager>,
11}
12
13impl TaskGetTool {
14 pub fn new(manager: Arc<dyn TaskManager>) -> Self {
15 Self { manager }
16 }
17}
18
19#[async_trait::async_trait]
20impl Tool for TaskGetTool {
21 fn name(&self) -> &str {
22 "task_get"
23 }
24
25 fn description(&self) -> &str {
26 "Get detailed information about a specific 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 retrieve"
36 }
37 },
38 "required": ["task_id"]
39 })
40 }
41
42 fn permission_level(&self) -> PermissionLevel {
43 PermissionLevel::ReadOnly
44 }
45
46 fn is_read_only(&self, _input: &Value) -> bool { true }
47 fn is_concurrent_safe(&self, _input: &Value) -> bool { true }
48
49 async fn execute(&self, input: Value) -> AppResult<String> {
50 let task_id = input
51 .get("task_id")
52 .and_then(|v| v.as_str())
53 .ok_or_else(|| AppError::Tool("missing 'task_id' field".into()))?;
54
55 let task = self.manager.get(task_id).await?;
56
57 serde_json::to_string_pretty(&task)
58 .map_err(|e| AppError::Tool(format!("failed to serialize task: {e}")))
59 }
60}