1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::fs;
4use std::path::PathBuf;
5
6#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq, JsonSchema)]
8#[serde(rename_all = "snake_case")]
9pub enum TodoStatus {
10 Pending,
11 InProgress,
12 Completed,
13}
14
15#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, JsonSchema)]
17#[serde(rename_all = "snake_case")]
18pub enum TodoPriority {
19 High = 0,
20 Medium = 1,
21 Low = 2,
22}
23
24#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)]
26pub struct TodoItem {
27 pub content: String,
29 pub status: TodoStatus,
31 pub priority: TodoPriority,
33 pub id: String,
35}
36
37pub type TodoList = Vec<TodoItem>;
39
40fn get_todos_dir() -> Result<PathBuf, std::io::Error> {
42 let home_dir = dirs::home_dir().ok_or_else(|| {
43 std::io::Error::new(std::io::ErrorKind::NotFound, "Home directory not found")
44 })?;
45 let todos_dir = home_dir.join(".steer").join("todos");
46
47 if !todos_dir.exists() {
48 fs::create_dir_all(&todos_dir)?;
49 }
50
51 Ok(todos_dir)
52}
53
54fn get_todo_file_path() -> Result<PathBuf, std::io::Error> {
56 let workspace_id = match std::env::var("CONDUCTOR_WORKSPACE_ID") {
57 Ok(id) => id,
58 Err(_) => {
59 let current_dir = std::env::current_dir()?;
61 hex::encode(current_dir.to_string_lossy().as_bytes())
63 }
64 };
65 let dir = get_todos_dir()?;
66 Ok(dir.join(format!("{workspace_id}.json")))
67}
68
69fn read_todos() -> Result<TodoList, std::io::Error> {
71 let file_path = get_todo_file_path()?;
72
73 if !file_path.exists() {
74 return Ok(Vec::new());
75 }
76
77 let content = fs::read_to_string(&file_path)?;
78 serde_json::from_str(&content)
79 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
80}
81
82fn write_todos(todos: &TodoList) -> Result<(), std::io::Error> {
84 let file_path = get_todo_file_path()?;
85 let content = serde_json::to_string_pretty(todos)
86 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
87 fs::write(&file_path, content)
88}
89
90pub mod read {
91 use super::read_todos;
92 use super::{TodoPriority, TodoStatus};
93 use crate::result::{TodoItem as TodoItemResult, TodoListResult};
94 use crate::{ExecutionContext, ToolError};
95 use schemars::JsonSchema;
96 use serde::{Deserialize, Serialize};
97 use steer_macros::tool;
98
99 #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
100 pub struct TodoReadParams {
102 }
104
105 tool! {
106 TodoReadTool {
107 params: TodoReadParams,
108 output: TodoListResult,
109 variant: TodoRead,
110 description: r#"Use this tool to read the current to-do list for the session. This tool should be used proactively and frequently to ensure that you are aware of
111the status of the current task list. You should make use of this tool as often as possible, especially in the following situations:
112- At the beginning of conversations to see what's pending
113- Before starting new tasks to prioritize work
114- When the user asks about previous tasks or plans
115- Whenever you're uncertain about what to do next
116- After completing tasks to update your understanding of remaining work
117- After every few messages to ensure you're on track
118
119Usage:
120- This tool takes in no parameters. So leave the input blank or empty. DO NOT include a dummy object, placeholder string or a key like "input" or "empty". LEAVE IT BLANK.
121- Returns a list of todo items with their status, priority, and content
122- Use this information to track progress and plan next steps
123- If no todos exist yet, an empty list will be returned"#,
124 name: "TodoRead",
125 require_approval: false
126 }
127
128 async fn run(
129 _tool: &TodoReadTool,
130 _params: TodoReadParams,
131 context: &ExecutionContext,
132 ) -> Result<TodoListResult, ToolError> {
133 if context.cancellation_token.is_cancelled() {
135 return Err(ToolError::Cancelled(TODO_READ_TOOL_NAME.to_string()));
136 }
137
138 let todos = read_todos().map_err(|e| ToolError::io(TODO_READ_TOOL_NAME, e.to_string()))?;
140
141 let result_todos = todos.into_iter().map(|todo| TodoItemResult {
143 id: todo.id,
144 content: todo.content,
145 status: match todo.status {
146 TodoStatus::Pending => "pending".to_string(),
147 TodoStatus::InProgress => "in_progress".to_string(),
148 TodoStatus::Completed => "completed".to_string(),
149 },
150 priority: match todo.priority {
151 TodoPriority::High => "high".to_string(),
152 TodoPriority::Medium => "medium".to_string(),
153 TodoPriority::Low => "low".to_string(),
154 },
155 }).collect();
156
157 Ok(TodoListResult {
158 todos: result_todos,
159 })
160 }
161 }
162}
163
164pub mod write {
165 use super::{TodoList, TodoPriority, TodoStatus, write_todos};
166 use crate::result::{TodoItem as TodoItemResult, TodoWriteResult};
167 use crate::{ExecutionContext, ToolError};
168 use schemars::JsonSchema;
169 use serde::{Deserialize, Serialize};
170 use steer_macros::tool;
171
172 #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
173 pub struct TodoWriteParams {
174 pub todos: TodoList,
176 }
177
178 tool! {
179 TodoWriteTool {
180 params: TodoWriteParams,
181 output: TodoWriteResult,
182 variant: TodoWrite,
183 description: r#"Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
184It also helps the user understand the progress of the task and overall progress of their requests.
185
186## When to Use This Tool
187Use this tool proactively in these scenarios:
188
1891. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
1902. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
1913. User explicitly requests todo list - When the user directly asks you to use the todo list
1924. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
1935. After receiving new instructions - Immediately capture user requirements as todos
1946. After completing a task - Mark it complete and add any new follow-up tasks
1957. When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
196
197## When NOT to Use This Tool
198
199Skip using this tool when:
2001. There is only a single, straightforward task
2012. The task is trivial and tracking it provides no organizational benefit
2023. The task can be completed in less than 3 trivial steps
2034. The task is purely conversational or informational
204
205NOTE that you should use should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
206
207## Examples of When to Use the Todo List
208
209<example>
210User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
211Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
212*Uses grep or search tools to locate all instances of getCwd in the codebase*
213Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
214*Creates todo list with specific items for each file that needs updating*
215
216<reasoning>
217The assistant used the todo list because:
2181. First, the assistant searched to understand the scope of the task
2192. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
2203. The todo list helps ensure every instance is tracked and updated systematically
2214. This approach prevents missing any occurrences and maintains code consistency
222</reasoning>
223</example>
224
225
226<example>
227User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
228Assistant: I'll help implement these features. First, let's add all the features to the todo list.
229*Creates a todo list breaking down each feature into specific tasks based on the project architecture*
230Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
231
232<reasoning>
233The assistant used the todo list because:
2341. The user provided multiple complex features to implement in a comma separated list
2352. The todo list helps organize these large features into manageable tasks
2363. This approach allows for tracking progress across the entire implementation
237</reasoning>
238</example>
239
240<example>
241User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
242Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
243*Reviews component structure, render patterns, state management, and data fetching*
244Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
245*Creates todo list with items like: 1) Implement memoization for expensive calculations in ProductList, 2) Add virtualization for long lists in Dashboard, 3) Optimize image loading in Gallery component, 4) Fix state update loops in ShoppingCart, 5) Review bundle size and implement code splitting*
246Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
247
248<reasoning>
249The assistant used the todo list because:
2501. First, the assistant examined the codebase to identify specific performance issues
2512. Based on this analysis, it identified multiple optimization opportunities
2523. Performance optimization is a non-trivial task requiring multiple steps
2534. The todo list helps methodically track improvements across different components
2545. This systematic approach ensures all performance bottlenecks are addressed
255</reasoning>
256</example>
257
258## Examples of When NOT to Use the Todo List
259
260<example>
261User: How do I print 'Hello World' in Python?
262Assistant: In Python, you can print "Hello World" with this simple code:
263
264python
265print("Hello World")
266
267This will output the text "Hello World" to the console when executed.</assistant>
268
269<reasoning>
270The assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.
271</reasoning>
272</example>
273
274<example>
275User: What does the git status command do?
276Assistant: The git status command shows the current state of your working directory and staging area. It displays which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a fundamental command for understanding the current state of your repository before making commits.
277
278<reasoning>
279The assistant did not use the todo list because this is an informational request with no actual coding task to complete. The user is simply asking for an explanation, not for the assistant to perform multiple steps or tasks.
280</reasoning>
281</example>
282
283<example>
284User: Can you add a comment to the calculateTotal function to explain what it does?
285Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
286* Uses the edit_file tool to add a comment to the calculateTotal function *
287
288<reasoning>
289The assistant did not use the todo list because this is a single, straightforward task confined to one location in the code. Adding a comment doesn't require tracking multiple steps or systematic organization.
290</reasoning>
291</example>
292
293<example>
294User: Run npm install for me and tell me what happens.
295Assistant: I'll run the npm install command for you.
296
297*Executes: npm install*
298
299The command completed successfully. Here's the output:
300[Output of npm install command]
301
302All dependencies have been installed according to your package.json file.
303
304<reasoning>
305The assistant did not use the todo list because this is a single command execution with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward task.
306</reasoning>
307</example>
308
309## Task States and Management
310
3111. **Task States**: Use these states to track progress:
312 - pending: Task not yet started
313 - in_progress: Currently working on (limit to ONE task at a time)
314 - completed: Task finished successfully
315 - cancelled: Task no longer needed
316
3172. **Task Management**:
318 - Update task status in real-time as you work
319 - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
320 - Only have ONE task in_progress at any time
321 - Complete current tasks before starting new ones
322 - Cancel tasks that become irrelevant
323
3243. **Task Breakdown**:
325 - Create specific, actionable items
326 - Break complex tasks into smaller, manageable steps
327 - Use clear, descriptive task names
328
329When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully."#,
330 name: "TodoWrite",
331 require_approval: false
332 }
333
334 async fn run(
335 _tool: &TodoWriteTool,
336 params: TodoWriteParams,
337 context: &ExecutionContext,
338 ) -> Result<TodoWriteResult, ToolError> {
339 if context.cancellation_token.is_cancelled() {
341 return Err(ToolError::Cancelled(TODO_WRITE_TOOL_NAME.to_string()));
342 }
343
344 write_todos(¶ms.todos).map_err(|e| ToolError::io(TODO_WRITE_TOOL_NAME, e.to_string()))?;
346
347 let result_todos = params.todos.into_iter().map(|todo| TodoItemResult {
349 id: todo.id,
350 content: todo.content,
351 status: match todo.status {
352 TodoStatus::Pending => "pending".to_string(),
353 TodoStatus::InProgress => "in_progress".to_string(),
354 TodoStatus::Completed => "completed".to_string(),
355 },
356 priority: match todo.priority {
357 TodoPriority::High => "high".to_string(),
358 TodoPriority::Medium => "medium".to_string(),
359 TodoPriority::Low => "low".to_string(),
360 },
361 }).collect();
362
363 Ok(TodoWriteResult {
364 todos: result_todos,
365 operation: "modified".to_string(),
366 })
367 }
368 }
369}