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                            "activeForm": {
48                                "type": "string",
49                                "description": "Present continuous form for spinner display (e.g., 'Implementing feature')"
50                            }
51                        },
52                        "required": ["id", "content", "status", "priority"]
53                    }
54                }
55            },
56            "required": ["todos"]
57        })
58    }
59
60    fn permission_level(&self) -> PermissionLevel {
61        PermissionLevel::ReadOnly
62    }
63
64    async fn execute(&self, input: Value) -> AppResult<String> {
65        let arr = input
66            .get("todos")
67            .and_then(|v| v.as_array())
68            .ok_or_else(|| AppError::Tool("missing 'todos' array".into()))?;
69
70        let todos: Vec<TodoItem> = arr
71            .iter()
72            .filter_map(|v| serde_json::from_value(v.clone()).ok())
73            .collect();
74
75        let count = todos.len();
76        write_todos(todos);
77        Ok(format!("Updated todo list ({count} items)"))
78    }
79}