Skip to main content

opendev_tools_impl/
list_todos.rs

1//! list_todos tool — display the current todo list.
2
3use std::collections::HashMap;
4use std::sync::{Arc, Mutex};
5
6use opendev_runtime::TodoManager;
7use opendev_tools_core::{BaseTool, ToolContext, ToolResult};
8
9/// Tool that lists all todo items sorted by status.
10#[derive(Debug)]
11pub struct ListTodosTool {
12    manager: Arc<Mutex<TodoManager>>,
13}
14
15impl ListTodosTool {
16    pub fn new(manager: Arc<Mutex<TodoManager>>) -> Self {
17        Self { manager }
18    }
19}
20
21#[async_trait::async_trait]
22impl BaseTool for ListTodosTool {
23    fn name(&self) -> &str {
24        "list_todos"
25    }
26
27    fn description(&self) -> &str {
28        "List all todo items sorted by status (doing → todo → done)."
29    }
30
31    fn parameter_schema(&self) -> serde_json::Value {
32        serde_json::json!({
33            "type": "object",
34            "properties": {},
35            "required": []
36        })
37    }
38
39    async fn execute(
40        &self,
41        _args: HashMap<String, serde_json::Value>,
42        _ctx: &ToolContext,
43    ) -> ToolResult {
44        let mgr = match self.manager.lock() {
45            Ok(m) => m,
46            Err(e) => return ToolResult::fail(format!("Lock error: {e}")),
47        };
48
49        if !mgr.has_todos() {
50            return ToolResult::ok("No todos.");
51        }
52
53        ToolResult::ok(mgr.format_status_sorted())
54    }
55}
56
57#[cfg(test)]
58#[path = "list_todos_tests.rs"]
59mod tests;