claude_rust_tools/infrastructure/
task_update_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 TaskUpdateTool {
10 manager: Arc<dyn TaskManager>,
11}
12
13impl TaskUpdateTool {
14 pub fn new(manager: Arc<dyn TaskManager>) -> Self {
15 Self { manager }
16 }
17}
18
19#[async_trait::async_trait]
20impl Tool for TaskUpdateTool {
21 fn name(&self) -> &str {
22 "task_update"
23 }
24
25 fn description(&self) -> &str {
26 "Update an existing task. Can change status, subject, description, or owner."
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 update"
36 },
37 "status": {
38 "type": "string",
39 "enum": ["pending", "in_progress", "completed", "deleted"],
40 "description": "New status for the task"
41 },
42 "subject": {
43 "type": "string",
44 "description": "New subject line for the task"
45 },
46 "description": {
47 "type": "string",
48 "description": "New description for the task"
49 },
50 "owner": {
51 "type": "string",
52 "description": "New owner for the task"
53 }
54 },
55 "required": ["task_id"]
56 })
57 }
58
59 fn permission_level(&self) -> PermissionLevel {
60 PermissionLevel::Dangerous
61 }
62
63 async fn execute(&self, input: Value) -> AppResult<String> {
64 let task_id = input
65 .get("task_id")
66 .and_then(|v| v.as_str())
67 .ok_or_else(|| AppError::Tool("missing 'task_id' field".into()))?;
68
69 let mut updates = serde_json::Map::new();
70 if let Some(v) = input.get("status") {
71 updates.insert("status".into(), v.clone());
72 }
73 if let Some(v) = input.get("subject") {
74 updates.insert("subject".into(), v.clone());
75 }
76 if let Some(v) = input.get("description") {
77 updates.insert("description".into(), v.clone());
78 }
79 if let Some(v) = input.get("owner") {
80 updates.insert("owner".into(), v.clone());
81 }
82
83 let task = self.manager.update(task_id, Value::Object(updates)).await?;
84
85 serde_json::to_string_pretty(&task)
86 .map_err(|e| AppError::Tool(format!("failed to serialize task: {e}")))
87 }
88}