ripperdoc 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ripperdoc/__init__.py +3 -0
- ripperdoc/__main__.py +20 -0
- ripperdoc/cli/__init__.py +1 -0
- ripperdoc/cli/cli.py +405 -0
- ripperdoc/cli/commands/__init__.py +82 -0
- ripperdoc/cli/commands/agents_cmd.py +263 -0
- ripperdoc/cli/commands/base.py +19 -0
- ripperdoc/cli/commands/clear_cmd.py +18 -0
- ripperdoc/cli/commands/compact_cmd.py +23 -0
- ripperdoc/cli/commands/config_cmd.py +31 -0
- ripperdoc/cli/commands/context_cmd.py +144 -0
- ripperdoc/cli/commands/cost_cmd.py +82 -0
- ripperdoc/cli/commands/doctor_cmd.py +221 -0
- ripperdoc/cli/commands/exit_cmd.py +19 -0
- ripperdoc/cli/commands/help_cmd.py +20 -0
- ripperdoc/cli/commands/mcp_cmd.py +70 -0
- ripperdoc/cli/commands/memory_cmd.py +202 -0
- ripperdoc/cli/commands/models_cmd.py +413 -0
- ripperdoc/cli/commands/permissions_cmd.py +302 -0
- ripperdoc/cli/commands/resume_cmd.py +98 -0
- ripperdoc/cli/commands/status_cmd.py +167 -0
- ripperdoc/cli/commands/tasks_cmd.py +278 -0
- ripperdoc/cli/commands/todos_cmd.py +69 -0
- ripperdoc/cli/commands/tools_cmd.py +19 -0
- ripperdoc/cli/ui/__init__.py +1 -0
- ripperdoc/cli/ui/context_display.py +298 -0
- ripperdoc/cli/ui/helpers.py +22 -0
- ripperdoc/cli/ui/rich_ui.py +1557 -0
- ripperdoc/cli/ui/spinner.py +49 -0
- ripperdoc/cli/ui/thinking_spinner.py +128 -0
- ripperdoc/cli/ui/tool_renderers.py +298 -0
- ripperdoc/core/__init__.py +1 -0
- ripperdoc/core/agents.py +486 -0
- ripperdoc/core/commands.py +33 -0
- ripperdoc/core/config.py +559 -0
- ripperdoc/core/default_tools.py +88 -0
- ripperdoc/core/permissions.py +252 -0
- ripperdoc/core/providers/__init__.py +47 -0
- ripperdoc/core/providers/anthropic.py +250 -0
- ripperdoc/core/providers/base.py +265 -0
- ripperdoc/core/providers/gemini.py +615 -0
- ripperdoc/core/providers/openai.py +487 -0
- ripperdoc/core/query.py +1058 -0
- ripperdoc/core/query_utils.py +622 -0
- ripperdoc/core/skills.py +295 -0
- ripperdoc/core/system_prompt.py +431 -0
- ripperdoc/core/tool.py +240 -0
- ripperdoc/sdk/__init__.py +9 -0
- ripperdoc/sdk/client.py +333 -0
- ripperdoc/tools/__init__.py +1 -0
- ripperdoc/tools/ask_user_question_tool.py +431 -0
- ripperdoc/tools/background_shell.py +389 -0
- ripperdoc/tools/bash_output_tool.py +98 -0
- ripperdoc/tools/bash_tool.py +1016 -0
- ripperdoc/tools/dynamic_mcp_tool.py +428 -0
- ripperdoc/tools/enter_plan_mode_tool.py +226 -0
- ripperdoc/tools/exit_plan_mode_tool.py +153 -0
- ripperdoc/tools/file_edit_tool.py +346 -0
- ripperdoc/tools/file_read_tool.py +203 -0
- ripperdoc/tools/file_write_tool.py +205 -0
- ripperdoc/tools/glob_tool.py +179 -0
- ripperdoc/tools/grep_tool.py +370 -0
- ripperdoc/tools/kill_bash_tool.py +136 -0
- ripperdoc/tools/ls_tool.py +471 -0
- ripperdoc/tools/mcp_tools.py +591 -0
- ripperdoc/tools/multi_edit_tool.py +456 -0
- ripperdoc/tools/notebook_edit_tool.py +386 -0
- ripperdoc/tools/skill_tool.py +205 -0
- ripperdoc/tools/task_tool.py +379 -0
- ripperdoc/tools/todo_tool.py +494 -0
- ripperdoc/tools/tool_search_tool.py +380 -0
- ripperdoc/utils/__init__.py +1 -0
- ripperdoc/utils/bash_constants.py +51 -0
- ripperdoc/utils/bash_output_utils.py +43 -0
- ripperdoc/utils/coerce.py +34 -0
- ripperdoc/utils/context_length_errors.py +252 -0
- ripperdoc/utils/exit_code_handlers.py +241 -0
- ripperdoc/utils/file_watch.py +135 -0
- ripperdoc/utils/git_utils.py +274 -0
- ripperdoc/utils/json_utils.py +27 -0
- ripperdoc/utils/log.py +176 -0
- ripperdoc/utils/mcp.py +560 -0
- ripperdoc/utils/memory.py +253 -0
- ripperdoc/utils/message_compaction.py +676 -0
- ripperdoc/utils/messages.py +519 -0
- ripperdoc/utils/output_utils.py +258 -0
- ripperdoc/utils/path_ignore.py +677 -0
- ripperdoc/utils/path_utils.py +46 -0
- ripperdoc/utils/permissions/__init__.py +27 -0
- ripperdoc/utils/permissions/path_validation_utils.py +174 -0
- ripperdoc/utils/permissions/shell_command_validation.py +552 -0
- ripperdoc/utils/permissions/tool_permission_utils.py +279 -0
- ripperdoc/utils/prompt.py +17 -0
- ripperdoc/utils/safe_get_cwd.py +31 -0
- ripperdoc/utils/sandbox_utils.py +38 -0
- ripperdoc/utils/session_history.py +260 -0
- ripperdoc/utils/session_usage.py +117 -0
- ripperdoc/utils/shell_token_utils.py +95 -0
- ripperdoc/utils/shell_utils.py +159 -0
- ripperdoc/utils/todo.py +203 -0
- ripperdoc/utils/token_estimation.py +34 -0
- ripperdoc-0.2.6.dist-info/METADATA +193 -0
- ripperdoc-0.2.6.dist-info/RECORD +107 -0
- ripperdoc-0.2.6.dist-info/WHEEL +5 -0
- ripperdoc-0.2.6.dist-info/entry_points.txt +3 -0
- ripperdoc-0.2.6.dist-info/licenses/LICENSE +53 -0
- ripperdoc-0.2.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
"""Todo management tools."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import AsyncGenerator, List, Optional
|
|
6
|
+
from textwrap import dedent
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
from ripperdoc.core.tool import (
|
|
10
|
+
Tool,
|
|
11
|
+
ToolUseContext,
|
|
12
|
+
ToolResult,
|
|
13
|
+
ToolOutput,
|
|
14
|
+
ToolUseExample,
|
|
15
|
+
ValidationResult,
|
|
16
|
+
)
|
|
17
|
+
from ripperdoc.utils.log import get_logger
|
|
18
|
+
from ripperdoc.utils.todo import (
|
|
19
|
+
TodoItem,
|
|
20
|
+
TodoPriority,
|
|
21
|
+
TodoStatus,
|
|
22
|
+
format_todo_lines,
|
|
23
|
+
format_todo_summary,
|
|
24
|
+
get_next_actionable,
|
|
25
|
+
load_todos,
|
|
26
|
+
set_todos,
|
|
27
|
+
summarize_todos,
|
|
28
|
+
validate_todos,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
logger = get_logger()
|
|
32
|
+
|
|
33
|
+
DEFAULT_ACTION = "Edit"
|
|
34
|
+
|
|
35
|
+
TODO_WRITE_PROMPT = dedent(
|
|
36
|
+
f"""\
|
|
37
|
+
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.
|
|
38
|
+
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
39
|
+
|
|
40
|
+
## When to Use This Tool
|
|
41
|
+
Use this tool proactively in these scenarios:
|
|
42
|
+
|
|
43
|
+
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
44
|
+
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
45
|
+
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
46
|
+
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
47
|
+
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
48
|
+
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
49
|
+
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
50
|
+
|
|
51
|
+
## When NOT to Use This Tool
|
|
52
|
+
|
|
53
|
+
Skip using this tool when:
|
|
54
|
+
1. There is only a single, straightforward task
|
|
55
|
+
2. The task is trivial and tracking it provides no organizational benefit
|
|
56
|
+
3. The task can be completed in less than 3 trivial steps
|
|
57
|
+
4. The task is purely conversational or informational
|
|
58
|
+
|
|
59
|
+
NOTE that you 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.
|
|
60
|
+
|
|
61
|
+
## Examples of When to Use the Todo List
|
|
62
|
+
|
|
63
|
+
<example>
|
|
64
|
+
User: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!
|
|
65
|
+
Assistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.
|
|
66
|
+
*Creates todo list with the following items:*
|
|
67
|
+
1. Create dark mode toggle component in Settings page
|
|
68
|
+
2. Add dark mode state management (context/store)
|
|
69
|
+
3. Implement CSS-in-JS styles for dark theme
|
|
70
|
+
4. Update existing components to support theme switching
|
|
71
|
+
5. Run tests and build process, addressing any failures or errors that occur
|
|
72
|
+
*Begins working on the first task*
|
|
73
|
+
|
|
74
|
+
<reasoning>
|
|
75
|
+
The assistant used the todo list because:
|
|
76
|
+
1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes
|
|
77
|
+
2. The user explicitly requested tests and build be run afterward
|
|
78
|
+
3. The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as the final task
|
|
79
|
+
</reasoning>
|
|
80
|
+
</example>
|
|
81
|
+
|
|
82
|
+
<example>
|
|
83
|
+
User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
|
|
84
|
+
Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
|
|
85
|
+
*Uses grep or search tools to locate all instances of getCwd in the codebase*
|
|
86
|
+
Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
|
|
87
|
+
*Creates todo list with specific items for each file that needs updating*
|
|
88
|
+
|
|
89
|
+
<reasoning>
|
|
90
|
+
The assistant used the todo list because:
|
|
91
|
+
1. First, the assistant searched to understand the scope of the task
|
|
92
|
+
2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
|
|
93
|
+
3. The todo list helps ensure every instance is tracked and updated systematically
|
|
94
|
+
4. This approach prevents missing any occurrences and maintains code consistency
|
|
95
|
+
</reasoning>
|
|
96
|
+
</example>
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
<example>
|
|
100
|
+
User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
|
|
101
|
+
Assistant: I'll help implement these features. First, let's add all the features to the todo list.
|
|
102
|
+
*Creates a todo list breaking down each feature into specific tasks based on the project architecture*
|
|
103
|
+
Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
|
|
104
|
+
|
|
105
|
+
<reasoning>
|
|
106
|
+
The assistant used the todo list because:
|
|
107
|
+
1. The user provided multiple complex features to implement in a comma separated list
|
|
108
|
+
2. The todo list helps organize these large features into manageable tasks
|
|
109
|
+
3. This approach allows for tracking progress across the entire implementation
|
|
110
|
+
</reasoning>
|
|
111
|
+
</example>
|
|
112
|
+
|
|
113
|
+
<example>
|
|
114
|
+
User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
|
|
115
|
+
Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
|
|
116
|
+
*Reviews component structure, render patterns, state management, and data fetching*
|
|
117
|
+
Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
|
|
118
|
+
*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*
|
|
119
|
+
Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
|
|
120
|
+
|
|
121
|
+
<reasoning>
|
|
122
|
+
The assistant used the todo list because:
|
|
123
|
+
1. First, the assistant examined the codebase to identify specific performance issues
|
|
124
|
+
2. Based on this analysis, it identified multiple optimization opportunities
|
|
125
|
+
3. Performance optimization is a non-trivial task requiring multiple steps
|
|
126
|
+
4. The todo list helps methodically track improvements across different components
|
|
127
|
+
5. This systematic approach ensures all performance bottlenecks are addressed
|
|
128
|
+
</reasoning>
|
|
129
|
+
</example>
|
|
130
|
+
|
|
131
|
+
## Examples of When NOT to Use the Todo List
|
|
132
|
+
|
|
133
|
+
<example>
|
|
134
|
+
User: How do I print 'Hello World' in Python?
|
|
135
|
+
Assistant: In Python, you can print "Hello World" with this simple code:
|
|
136
|
+
|
|
137
|
+
python
|
|
138
|
+
print("Hello World")
|
|
139
|
+
|
|
140
|
+
This will output the text "Hello World" to the console when executed.</assistant>
|
|
141
|
+
|
|
142
|
+
<reasoning>
|
|
143
|
+
The 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.
|
|
144
|
+
</reasoning>
|
|
145
|
+
</example>
|
|
146
|
+
|
|
147
|
+
<example>
|
|
148
|
+
User: What does the git status command do?
|
|
149
|
+
Assistant: 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.
|
|
150
|
+
|
|
151
|
+
<reasoning>
|
|
152
|
+
The 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.
|
|
153
|
+
</reasoning>
|
|
154
|
+
</example>
|
|
155
|
+
|
|
156
|
+
<example>
|
|
157
|
+
User: Can you add a comment to the calculateTotal function to explain what it does?
|
|
158
|
+
Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
|
|
159
|
+
* Uses the ${DEFAULT_ACTION} tool to add a comment to the calculateTotal function *
|
|
160
|
+
|
|
161
|
+
<reasoning>
|
|
162
|
+
The 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.
|
|
163
|
+
</reasoning>
|
|
164
|
+
</example>
|
|
165
|
+
|
|
166
|
+
<example>
|
|
167
|
+
User: Run npm install for me and tell me what happens.
|
|
168
|
+
Assistant: I'll run the npm install command for you.
|
|
169
|
+
|
|
170
|
+
*Executes: npm install*
|
|
171
|
+
|
|
172
|
+
The command completed successfully. Here's the output:
|
|
173
|
+
[Output of npm install command]
|
|
174
|
+
|
|
175
|
+
All dependencies have been installed according to your package.json file.
|
|
176
|
+
|
|
177
|
+
<reasoning>
|
|
178
|
+
The 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.
|
|
179
|
+
</reasoning>
|
|
180
|
+
</example>
|
|
181
|
+
|
|
182
|
+
## Task States and Management
|
|
183
|
+
|
|
184
|
+
1. **Task States**: Use these states to track progress:
|
|
185
|
+
- pending: Task not yet started
|
|
186
|
+
- in_progress: Currently working on (limit to ONE task at a time)
|
|
187
|
+
- completed: Task finished successfully
|
|
188
|
+
|
|
189
|
+
2. **Task Management**:
|
|
190
|
+
- Update task status in real-time as you work
|
|
191
|
+
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
192
|
+
- Only have ONE task in_progress at any time
|
|
193
|
+
- Complete current tasks before starting new ones
|
|
194
|
+
- Remove tasks that are no longer relevant from the list entirely
|
|
195
|
+
|
|
196
|
+
3. **Task Completion Requirements**:
|
|
197
|
+
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
198
|
+
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
199
|
+
- When blocked, create a new task describing what needs to be resolved
|
|
200
|
+
- Never mark a task as completed if:
|
|
201
|
+
- Tests are failing
|
|
202
|
+
- Implementation is partial
|
|
203
|
+
- You encountered unresolved errors
|
|
204
|
+
- You couldn't find necessary files or dependencies
|
|
205
|
+
|
|
206
|
+
4. **Task Breakdown**:
|
|
207
|
+
- Create specific, actionable items
|
|
208
|
+
- Break complex tasks into smaller, manageable steps
|
|
209
|
+
- Use clear, descriptive task names
|
|
210
|
+
|
|
211
|
+
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
|
|
212
|
+
"""
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class TodoInputItem(BaseModel):
|
|
217
|
+
"""Single todo input payload."""
|
|
218
|
+
|
|
219
|
+
content: str = Field(description="Task description")
|
|
220
|
+
status: TodoStatus = Field(default="pending", description="pending|in_progress|completed")
|
|
221
|
+
priority: TodoPriority = Field(default="medium", description="high|medium|low")
|
|
222
|
+
id: str = Field(description="Unique identifier for the task")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class TodoWriteToolInput(BaseModel):
|
|
226
|
+
"""Input for updating the todo list."""
|
|
227
|
+
|
|
228
|
+
todos: list[TodoInputItem] = Field(description="Complete todo list to persist")
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class TodoReadToolInput(BaseModel):
|
|
232
|
+
"""Input for reading the todo list."""
|
|
233
|
+
|
|
234
|
+
status: Optional[list[TodoStatus]] = Field(
|
|
235
|
+
default=None, description="Filter by status; omit for all todos"
|
|
236
|
+
)
|
|
237
|
+
limit: int = Field(
|
|
238
|
+
default=0,
|
|
239
|
+
description="Optional limit for the number of todos to return; 0 returns all matches",
|
|
240
|
+
)
|
|
241
|
+
next_only: bool = Field(
|
|
242
|
+
default=False,
|
|
243
|
+
description="Return only the next actionable todo (in_progress first, then pending)",
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class TodoToolOutput(BaseModel):
|
|
248
|
+
"""Common output for todo operations."""
|
|
249
|
+
|
|
250
|
+
todos: list[TodoItem]
|
|
251
|
+
summary: str
|
|
252
|
+
stats: dict
|
|
253
|
+
next_todo: Optional[TodoItem] = None
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class TodoWriteTool(Tool[TodoWriteToolInput, TodoToolOutput]):
|
|
257
|
+
"""Create or update the todo list."""
|
|
258
|
+
|
|
259
|
+
@property
|
|
260
|
+
def name(self) -> str:
|
|
261
|
+
return "TodoWrite"
|
|
262
|
+
|
|
263
|
+
async def description(self) -> str:
|
|
264
|
+
return "Update the todo list for the current session. To be used proactively and often to track progress and pending tasks."
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def input_schema(self) -> type[TodoWriteToolInput]:
|
|
268
|
+
return TodoWriteToolInput
|
|
269
|
+
|
|
270
|
+
def input_examples(self) -> List[ToolUseExample]:
|
|
271
|
+
return [
|
|
272
|
+
ToolUseExample(
|
|
273
|
+
description="Seed a three-step plan",
|
|
274
|
+
example={
|
|
275
|
+
"todos": [
|
|
276
|
+
{
|
|
277
|
+
"id": "plan",
|
|
278
|
+
"content": "Review existing API docs",
|
|
279
|
+
"status": "pending",
|
|
280
|
+
"priority": "medium",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"id": "impl",
|
|
284
|
+
"content": "Implement new endpoint",
|
|
285
|
+
"status": "pending",
|
|
286
|
+
"priority": "high",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"id": "tests",
|
|
290
|
+
"content": "Add integration tests",
|
|
291
|
+
"status": "pending",
|
|
292
|
+
"priority": "high",
|
|
293
|
+
},
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
),
|
|
297
|
+
ToolUseExample(
|
|
298
|
+
description="Update a single task already in progress",
|
|
299
|
+
example={
|
|
300
|
+
"todos": [
|
|
301
|
+
{
|
|
302
|
+
"id": "bugfix-123",
|
|
303
|
+
"content": "Fix login redirect loop",
|
|
304
|
+
"status": "in_progress",
|
|
305
|
+
"priority": "high",
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
),
|
|
310
|
+
]
|
|
311
|
+
|
|
312
|
+
async def prompt(self, _safe_mode: bool = False) -> str:
|
|
313
|
+
return TODO_WRITE_PROMPT
|
|
314
|
+
|
|
315
|
+
def is_read_only(self) -> bool:
|
|
316
|
+
return False
|
|
317
|
+
|
|
318
|
+
def is_concurrency_safe(self) -> bool:
|
|
319
|
+
return False
|
|
320
|
+
|
|
321
|
+
def needs_permissions(self, _input_data: Optional[TodoWriteToolInput] = None) -> bool:
|
|
322
|
+
return False
|
|
323
|
+
|
|
324
|
+
async def validate_input(
|
|
325
|
+
self,
|
|
326
|
+
input_data: TodoWriteToolInput,
|
|
327
|
+
_context: Optional[ToolUseContext] = None,
|
|
328
|
+
) -> ValidationResult:
|
|
329
|
+
todos = [TodoItem(**todo.model_dump()) for todo in input_data.todos]
|
|
330
|
+
ok, message = validate_todos(todos)
|
|
331
|
+
if not ok:
|
|
332
|
+
return ValidationResult(result=False, message=message)
|
|
333
|
+
return ValidationResult(result=True)
|
|
334
|
+
|
|
335
|
+
def render_result_for_assistant(self, output: TodoToolOutput) -> str:
|
|
336
|
+
return output.summary
|
|
337
|
+
|
|
338
|
+
def render_tool_use_message(
|
|
339
|
+
self,
|
|
340
|
+
input_data: TodoWriteToolInput,
|
|
341
|
+
_verbose: bool = False,
|
|
342
|
+
) -> str:
|
|
343
|
+
return f"Updating todo list with {len(input_data.todos)} item(s)"
|
|
344
|
+
|
|
345
|
+
async def call(
|
|
346
|
+
self,
|
|
347
|
+
input_data: TodoWriteToolInput,
|
|
348
|
+
_context: ToolUseContext,
|
|
349
|
+
) -> AsyncGenerator[ToolOutput, None]:
|
|
350
|
+
try:
|
|
351
|
+
todos = [TodoItem(**todo.model_dump()) for todo in input_data.todos]
|
|
352
|
+
updated = set_todos(todos)
|
|
353
|
+
summary = format_todo_summary(updated)
|
|
354
|
+
lines = format_todo_lines(updated)
|
|
355
|
+
result_text = "\n".join([summary, *lines]) if lines else summary
|
|
356
|
+
output = TodoToolOutput(
|
|
357
|
+
todos=updated,
|
|
358
|
+
summary=summary,
|
|
359
|
+
stats=summarize_todos(updated),
|
|
360
|
+
next_todo=get_next_actionable(updated),
|
|
361
|
+
)
|
|
362
|
+
yield ToolResult(data=output, result_for_assistant=result_text)
|
|
363
|
+
except (OSError, ValueError, KeyError, TypeError) as exc:
|
|
364
|
+
logger.warning("[todo_tool] Error updating todos: %s: %s", type(exc).__name__, exc)
|
|
365
|
+
error = f"Error updating todos: {exc}"
|
|
366
|
+
yield ToolResult(
|
|
367
|
+
data=TodoToolOutput(
|
|
368
|
+
todos=[],
|
|
369
|
+
summary=error,
|
|
370
|
+
stats={"total": 0, "by_status": {}, "by_priority": {}},
|
|
371
|
+
next_todo=None,
|
|
372
|
+
),
|
|
373
|
+
result_for_assistant=error,
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
class TodoReadTool(Tool[TodoReadToolInput, TodoToolOutput]):
|
|
378
|
+
"""Read the todo list and pick the next task."""
|
|
379
|
+
|
|
380
|
+
@property
|
|
381
|
+
def name(self) -> str:
|
|
382
|
+
return "TodoRead"
|
|
383
|
+
|
|
384
|
+
async def description(self) -> str:
|
|
385
|
+
return (
|
|
386
|
+
"Reads the stored todo list for this project so you can review tasks, "
|
|
387
|
+
"pick the next item to execute, and update progress."
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
@property
|
|
391
|
+
def input_schema(self) -> type[TodoReadToolInput]:
|
|
392
|
+
return TodoReadToolInput
|
|
393
|
+
|
|
394
|
+
def input_examples(self) -> List[ToolUseExample]:
|
|
395
|
+
return [
|
|
396
|
+
ToolUseExample(
|
|
397
|
+
description="Get only the next actionable todo",
|
|
398
|
+
example={"next_only": True},
|
|
399
|
+
),
|
|
400
|
+
ToolUseExample(
|
|
401
|
+
description="List recent completed tasks with a limit",
|
|
402
|
+
example={"status": ["completed"], "limit": 5},
|
|
403
|
+
),
|
|
404
|
+
]
|
|
405
|
+
|
|
406
|
+
async def prompt(self, _safe_mode: bool = False) -> str:
|
|
407
|
+
return (
|
|
408
|
+
"Use TodoRead to fetch the current todo list before making progress or when you need "
|
|
409
|
+
"to confirm the next action. You can request only the next actionable item or filter "
|
|
410
|
+
"by status."
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
def is_read_only(self) -> bool:
|
|
414
|
+
return True
|
|
415
|
+
|
|
416
|
+
def is_concurrency_safe(self) -> bool:
|
|
417
|
+
return True
|
|
418
|
+
|
|
419
|
+
def needs_permissions(self, _input_data: Optional[TodoReadToolInput] = None) -> bool:
|
|
420
|
+
return False
|
|
421
|
+
|
|
422
|
+
async def validate_input(
|
|
423
|
+
self,
|
|
424
|
+
input_data: TodoReadToolInput,
|
|
425
|
+
_context: Optional[ToolUseContext] = None,
|
|
426
|
+
) -> ValidationResult:
|
|
427
|
+
if input_data.limit < 0:
|
|
428
|
+
return ValidationResult(result=False, message="limit cannot be negative")
|
|
429
|
+
if input_data.status:
|
|
430
|
+
invalid = [
|
|
431
|
+
status
|
|
432
|
+
for status in input_data.status
|
|
433
|
+
if status not in ("pending", "in_progress", "completed")
|
|
434
|
+
]
|
|
435
|
+
if invalid:
|
|
436
|
+
return ValidationResult(
|
|
437
|
+
result=False,
|
|
438
|
+
message=f"Invalid status values: {', '.join(invalid)}",
|
|
439
|
+
)
|
|
440
|
+
return ValidationResult(result=True)
|
|
441
|
+
|
|
442
|
+
def render_result_for_assistant(self, output: TodoToolOutput) -> str:
|
|
443
|
+
return output.summary
|
|
444
|
+
|
|
445
|
+
def render_tool_use_message(
|
|
446
|
+
self,
|
|
447
|
+
input_data: TodoReadToolInput,
|
|
448
|
+
_verbose: bool = False,
|
|
449
|
+
) -> str:
|
|
450
|
+
if input_data.next_only:
|
|
451
|
+
return "Reading next actionable todo"
|
|
452
|
+
return "Reading todo list"
|
|
453
|
+
|
|
454
|
+
async def call(
|
|
455
|
+
self,
|
|
456
|
+
input_data: TodoReadToolInput,
|
|
457
|
+
_context: ToolUseContext,
|
|
458
|
+
) -> AsyncGenerator[ToolOutput, None]:
|
|
459
|
+
all_todos = load_todos()
|
|
460
|
+
filtered = all_todos
|
|
461
|
+
|
|
462
|
+
if input_data.status:
|
|
463
|
+
allowed = set(input_data.status)
|
|
464
|
+
filtered = [todo for todo in all_todos if todo.status in allowed]
|
|
465
|
+
|
|
466
|
+
display = filtered
|
|
467
|
+
next_todo = get_next_actionable(filtered)
|
|
468
|
+
|
|
469
|
+
if input_data.next_only:
|
|
470
|
+
display = [next_todo] if next_todo else []
|
|
471
|
+
|
|
472
|
+
if input_data.limit and input_data.limit > 0:
|
|
473
|
+
display = display[: input_data.limit]
|
|
474
|
+
|
|
475
|
+
if not all_todos:
|
|
476
|
+
summary = "No todos stored yet."
|
|
477
|
+
elif input_data.next_only:
|
|
478
|
+
summary = (
|
|
479
|
+
f"Next actionable todo: {next_todo.content} (id: {next_todo.id}, status: {next_todo.status})."
|
|
480
|
+
if next_todo
|
|
481
|
+
else "No actionable todos (none pending or in_progress)."
|
|
482
|
+
)
|
|
483
|
+
else:
|
|
484
|
+
summary = format_todo_summary(filtered)
|
|
485
|
+
|
|
486
|
+
lines = format_todo_lines(display)
|
|
487
|
+
result_text = "\n".join([summary, *lines]) if lines else summary
|
|
488
|
+
output = TodoToolOutput(
|
|
489
|
+
todos=display,
|
|
490
|
+
summary=summary,
|
|
491
|
+
stats=summarize_todos(filtered),
|
|
492
|
+
next_todo=next_todo,
|
|
493
|
+
)
|
|
494
|
+
yield ToolResult(data=output, result_for_assistant=result_text)
|