claude_rust_tools/infrastructure/
task_list_tool.rs1use std::sync::Arc;
2
3use claude_rust_errors::{AppError, AppResult};
4use claude_rust_types::{PermissionLevel, SearchReadInfo, Tool};
5use serde_json::{Value, json};
6
7use super::task_manager::TaskManager;
8
9pub struct TaskListTool {
10 manager: Arc<dyn TaskManager>,
11}
12
13impl TaskListTool {
14 pub fn new(manager: Arc<dyn TaskManager>) -> Self {
15 Self { manager }
16 }
17}
18
19#[async_trait::async_trait]
20impl Tool for TaskListTool {
21 fn name(&self) -> &str {
22 "task_list"
23 }
24
25 fn description(&self) -> &str {
26 "List all active (non-deleted) tasks. Returns a JSON array of task objects."
27 }
28
29 fn input_schema(&self) -> Value {
30 json!({
31 "type": "object",
32 "properties": {}
33 })
34 }
35
36 fn permission_level(&self) -> PermissionLevel {
37 PermissionLevel::ReadOnly
38 }
39
40 fn is_read_only(&self, _input: &Value) -> bool { true }
41 fn is_concurrent_safe(&self, _input: &Value) -> bool { true }
42
43 fn is_search_or_read_command(&self, _input: &Value) -> SearchReadInfo {
44 SearchReadInfo { is_search: false, is_read: false, is_list: true }
45 }
46
47 async fn execute(&self, _input: Value) -> AppResult<String> {
48 let tasks = self.manager.list().await?;
49
50 serde_json::to_string_pretty(&tasks)
51 .map_err(|e| AppError::Tool(format!("failed to serialize tasks: {e}")))
52 }
53}