Skip to main content

claude_rust_tools/infrastructure/
todo_write_tool.rs

1use claude_rust_errors::{AppError, AppResult};
2use claude_rust_types::{PermissionLevel, Tool};
3use serde_json::{Value, json};
4
5use super::todo_store::{TodoItem, write_todos};
6
7pub struct TodoWriteTool;
8
9#[async_trait::async_trait]
10impl Tool for TodoWriteTool {
11    fn name(&self) -> &str {
12        "todo_write"
13    }
14
15    fn description(&self) -> &str {
16        "Create and manage a structured task list. Use to track tasks, their status, and priorities. Replaces the entire todo list with the provided items."
17    }
18
19    fn input_schema(&self) -> Value {
20        json!({
21            "type": "object",
22            "properties": {
23                "todos": {
24                    "type": "array",
25                    "description": "The complete list of todo items to store",
26                    "items": {
27                        "type": "object",
28                        "properties": {
29                            "id": {
30                                "type": "string",
31                                "description": "Unique identifier for the todo item"
32                            },
33                            "content": {
34                                "type": "string",
35                                "description": "Description of the task"
36                            },
37                            "status": {
38                                "type": "string",
39                                "enum": ["pending", "in_progress", "completed"],
40                                "description": "Current status of the task"
41                            },
42                            "priority": {
43                                "type": "string",
44                                "enum": ["high", "medium", "low"],
45                                "description": "Priority level of the task"
46                            }
47                        },
48                        "required": ["id", "content", "status", "priority"]
49                    }
50                }
51            },
52            "required": ["todos"]
53        })
54    }
55
56    fn permission_level(&self) -> PermissionLevel {
57        PermissionLevel::ReadOnly
58    }
59
60    async fn execute(&self, input: Value) -> AppResult<String> {
61        let arr = input
62            .get("todos")
63            .and_then(|v| v.as_array())
64            .ok_or_else(|| AppError::Tool("missing 'todos' array".into()))?;
65
66        let todos: Vec<TodoItem> = arr
67            .iter()
68            .filter_map(|v| serde_json::from_value(v.clone()).ok())
69            .collect();
70
71        let count = todos.len();
72        write_todos(todos);
73        Ok(format!("Updated todo list ({count} items)"))
74    }
75}