ripperdoc 0.1.0__py3-none-any.whl → 0.2.2__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 +1 -1
- ripperdoc/cli/cli.py +75 -15
- ripperdoc/cli/commands/__init__.py +4 -0
- ripperdoc/cli/commands/agents_cmd.py +23 -1
- ripperdoc/cli/commands/context_cmd.py +13 -3
- ripperdoc/cli/commands/cost_cmd.py +1 -1
- ripperdoc/cli/commands/doctor_cmd.py +200 -0
- ripperdoc/cli/commands/memory_cmd.py +209 -0
- ripperdoc/cli/commands/models_cmd.py +25 -0
- ripperdoc/cli/commands/resume_cmd.py +3 -3
- ripperdoc/cli/commands/status_cmd.py +5 -5
- ripperdoc/cli/commands/tasks_cmd.py +32 -5
- ripperdoc/cli/ui/context_display.py +4 -3
- ripperdoc/cli/ui/rich_ui.py +205 -43
- ripperdoc/cli/ui/spinner.py +3 -4
- ripperdoc/core/agents.py +10 -6
- ripperdoc/core/config.py +48 -3
- ripperdoc/core/default_tools.py +26 -6
- ripperdoc/core/permissions.py +19 -0
- ripperdoc/core/query.py +238 -302
- ripperdoc/core/query_utils.py +537 -0
- ripperdoc/core/system_prompt.py +2 -1
- ripperdoc/core/tool.py +14 -1
- ripperdoc/sdk/client.py +1 -1
- ripperdoc/tools/background_shell.py +9 -3
- ripperdoc/tools/bash_tool.py +19 -4
- ripperdoc/tools/file_edit_tool.py +9 -2
- ripperdoc/tools/file_read_tool.py +9 -2
- ripperdoc/tools/file_write_tool.py +15 -2
- ripperdoc/tools/glob_tool.py +57 -17
- ripperdoc/tools/grep_tool.py +9 -2
- ripperdoc/tools/ls_tool.py +244 -75
- ripperdoc/tools/mcp_tools.py +47 -19
- ripperdoc/tools/multi_edit_tool.py +13 -2
- ripperdoc/tools/notebook_edit_tool.py +9 -6
- ripperdoc/tools/task_tool.py +20 -5
- ripperdoc/tools/todo_tool.py +163 -29
- ripperdoc/tools/tool_search_tool.py +15 -4
- ripperdoc/utils/git_utils.py +276 -0
- ripperdoc/utils/json_utils.py +28 -0
- ripperdoc/utils/log.py +130 -29
- ripperdoc/utils/mcp.py +83 -10
- ripperdoc/utils/memory.py +14 -1
- ripperdoc/utils/message_compaction.py +51 -14
- ripperdoc/utils/messages.py +63 -4
- ripperdoc/utils/output_utils.py +36 -9
- ripperdoc/utils/permissions/path_validation_utils.py +6 -0
- ripperdoc/utils/safe_get_cwd.py +4 -0
- ripperdoc/utils/session_history.py +27 -9
- ripperdoc/utils/todo.py +2 -2
- {ripperdoc-0.1.0.dist-info → ripperdoc-0.2.2.dist-info}/METADATA +4 -2
- ripperdoc-0.2.2.dist-info/RECORD +86 -0
- ripperdoc-0.1.0.dist-info/RECORD +0 -81
- {ripperdoc-0.1.0.dist-info → ripperdoc-0.2.2.dist-info}/WHEEL +0 -0
- {ripperdoc-0.1.0.dist-info → ripperdoc-0.2.2.dist-info}/entry_points.txt +0 -0
- {ripperdoc-0.1.0.dist-info → ripperdoc-0.2.2.dist-info}/licenses/LICENSE +0 -0
- {ripperdoc-0.1.0.dist-info → ripperdoc-0.2.2.dist-info}/top_level.txt +0 -0
|
@@ -101,7 +101,7 @@ class NotebookEditTool(Tool[NotebookEditInput, NotebookEditOutput]):
|
|
|
101
101
|
return [
|
|
102
102
|
ToolUseExample(
|
|
103
103
|
description="Replace a markdown cell by id",
|
|
104
|
-
|
|
104
|
+
example={
|
|
105
105
|
"notebook_path": "/repo/notebooks/analysis.ipynb",
|
|
106
106
|
"cell_id": "abc123",
|
|
107
107
|
"new_source": "# Updated overview\\nThis notebook analyzes revenue.",
|
|
@@ -111,7 +111,7 @@ class NotebookEditTool(Tool[NotebookEditInput, NotebookEditOutput]):
|
|
|
111
111
|
),
|
|
112
112
|
ToolUseExample(
|
|
113
113
|
description="Insert a new code cell at the beginning",
|
|
114
|
-
|
|
114
|
+
example={
|
|
115
115
|
"notebook_path": "/repo/notebooks/analysis.ipynb",
|
|
116
116
|
"cell_type": "code",
|
|
117
117
|
"edit_mode": "insert",
|
|
@@ -165,8 +165,8 @@ class NotebookEditTool(Tool[NotebookEditInput, NotebookEditOutput]):
|
|
|
165
165
|
try:
|
|
166
166
|
raw = path.read_text(encoding="utf-8")
|
|
167
167
|
nb_json = json.loads(raw)
|
|
168
|
-
except Exception
|
|
169
|
-
logger.
|
|
168
|
+
except Exception:
|
|
169
|
+
logger.exception("Failed to parse notebook", extra={"path": str(path)})
|
|
170
170
|
return ValidationResult(
|
|
171
171
|
result=False, message="Notebook is not valid JSON.", error_code=6
|
|
172
172
|
)
|
|
@@ -246,7 +246,7 @@ class NotebookEditTool(Tool[NotebookEditInput, NotebookEditOutput]):
|
|
|
246
246
|
"id": new_id,
|
|
247
247
|
"source": new_source,
|
|
248
248
|
"metadata": {},
|
|
249
|
-
"execution_count":
|
|
249
|
+
"execution_count": None, # type: ignore[dict-item]
|
|
250
250
|
"outputs": [],
|
|
251
251
|
}
|
|
252
252
|
)
|
|
@@ -285,7 +285,10 @@ class NotebookEditTool(Tool[NotebookEditInput, NotebookEditOutput]):
|
|
|
285
285
|
data=output, result_for_assistant=self.render_result_for_assistant(output)
|
|
286
286
|
)
|
|
287
287
|
except Exception as exc: # pragma: no cover - error path
|
|
288
|
-
logger.
|
|
288
|
+
logger.exception(
|
|
289
|
+
"Error editing notebook",
|
|
290
|
+
extra={"path": input_data.notebook_path, "error": str(exc)},
|
|
291
|
+
)
|
|
289
292
|
output = NotebookEditOutput(
|
|
290
293
|
new_source=new_source,
|
|
291
294
|
cell_type=cell_type or "code",
|
ripperdoc/tools/task_tool.py
CHANGED
|
@@ -19,6 +19,9 @@ from ripperdoc.core.query import QueryContext, query
|
|
|
19
19
|
from ripperdoc.core.system_prompt import build_environment_prompt
|
|
20
20
|
from ripperdoc.core.tool import Tool, ToolOutput, ToolProgress, ToolResult, ToolUseContext
|
|
21
21
|
from ripperdoc.utils.messages import AssistantMessage, create_user_message
|
|
22
|
+
from ripperdoc.utils.log import get_logger
|
|
23
|
+
|
|
24
|
+
logger = get_logger()
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
class TaskToolInput(BaseModel):
|
|
@@ -85,7 +88,7 @@ class TaskTool(Tool[TaskToolInput, TaskToolOutput]):
|
|
|
85
88
|
details: List[str] = []
|
|
86
89
|
if output.tool_use_count:
|
|
87
90
|
details.append(f"{output.tool_use_count} tool uses")
|
|
88
|
-
details.append(f"{output.duration_ms/1000:.1f}s")
|
|
91
|
+
details.append(f"{output.duration_ms / 1000:.1f}s")
|
|
89
92
|
if output.missing_tools:
|
|
90
93
|
details.append(f"missing tools: {', '.join(output.missing_tools)}")
|
|
91
94
|
|
|
@@ -125,11 +128,18 @@ class TaskTool(Tool[TaskToolInput, TaskToolOutput]):
|
|
|
125
128
|
f"Missing or unknown tools: {', '.join(missing_tools) if missing_tools else 'none'}"
|
|
126
129
|
)
|
|
127
130
|
|
|
128
|
-
|
|
131
|
+
# Type conversion: List[object] -> List[Tool[Any, Any]]
|
|
132
|
+
from ripperdoc.core.tool import Tool
|
|
133
|
+
|
|
134
|
+
typed_agent_tools: List[Tool[Any, Any]] = [
|
|
135
|
+
tool for tool in agent_tools if isinstance(tool, Tool)
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
agent_system_prompt = self._build_agent_prompt(target_agent, typed_agent_tools)
|
|
129
139
|
subagent_messages = [create_user_message(input_data.prompt)]
|
|
130
140
|
|
|
131
141
|
subagent_context = QueryContext(
|
|
132
|
-
tools=
|
|
142
|
+
tools=typed_agent_tools,
|
|
133
143
|
safe_mode=context.safe_mode,
|
|
134
144
|
verbose=context.verbose,
|
|
135
145
|
model=target_agent.model or "task",
|
|
@@ -142,7 +152,7 @@ class TaskTool(Tool[TaskToolInput, TaskToolOutput]):
|
|
|
142
152
|
yield ToolProgress(content=f"Launching subagent '{target_agent.agent_type}'")
|
|
143
153
|
|
|
144
154
|
async for message in query(
|
|
145
|
-
subagent_messages,
|
|
155
|
+
subagent_messages, # type: ignore[arg-type]
|
|
146
156
|
agent_system_prompt,
|
|
147
157
|
{},
|
|
148
158
|
subagent_context,
|
|
@@ -183,7 +193,8 @@ class TaskTool(Tool[TaskToolInput, TaskToolOutput]):
|
|
|
183
193
|
)
|
|
184
194
|
yield ToolProgress(content=f"Subagent: {short}")
|
|
185
195
|
assistant_messages.append(message) # type: ignore[arg-type]
|
|
186
|
-
|
|
196
|
+
if isinstance(message, AssistantMessage):
|
|
197
|
+
tool_use_count += self._count_tool_uses(message)
|
|
187
198
|
|
|
188
199
|
duration_ms = (time.time() - start) * 1000
|
|
189
200
|
result_text = (
|
|
@@ -276,6 +287,10 @@ class TaskTool(Tool[TaskToolInput, TaskToolOutput]):
|
|
|
276
287
|
try:
|
|
277
288
|
serialized = json.dumps(inp, ensure_ascii=False)
|
|
278
289
|
except Exception:
|
|
290
|
+
logger.exception(
|
|
291
|
+
"[task_tool] Failed to serialize tool_use input",
|
|
292
|
+
extra={"tool_use_input": str(inp)},
|
|
293
|
+
)
|
|
279
294
|
serialized = str(inp)
|
|
280
295
|
return serialized if len(serialized) <= 120 else serialized[:117] + "..."
|
|
281
296
|
|
ripperdoc/tools/todo_tool.py
CHANGED
|
@@ -14,6 +14,7 @@ from ripperdoc.core.tool import (
|
|
|
14
14
|
ToolUseExample,
|
|
15
15
|
ValidationResult,
|
|
16
16
|
)
|
|
17
|
+
from ripperdoc.utils.log import get_logger
|
|
17
18
|
from ripperdoc.utils.todo import (
|
|
18
19
|
TodoItem,
|
|
19
20
|
TodoPriority,
|
|
@@ -27,9 +28,14 @@ from ripperdoc.utils.todo import (
|
|
|
27
28
|
validate_todos,
|
|
28
29
|
)
|
|
29
30
|
|
|
31
|
+
logger = get_logger()
|
|
32
|
+
|
|
33
|
+
DEFAULT_ACTION = "Edit"
|
|
34
|
+
|
|
30
35
|
TODO_WRITE_PROMPT = dedent(
|
|
31
|
-
"""\
|
|
32
|
-
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.
|
|
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.
|
|
33
39
|
|
|
34
40
|
## When to Use This Tool
|
|
35
41
|
Use this tool proactively in these scenarios:
|
|
@@ -52,30 +58,155 @@ TODO_WRITE_PROMPT = dedent(
|
|
|
52
58
|
|
|
53
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.
|
|
54
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
|
+
|
|
55
182
|
## Task States and Management
|
|
56
183
|
|
|
57
|
-
1. Task States:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
2. Task Management
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
3. Task Completion Requirements
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
79
210
|
|
|
80
211
|
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
|
|
81
212
|
"""
|
|
@@ -130,7 +261,7 @@ class TodoWriteTool(Tool[TodoWriteToolInput, TodoToolOutput]):
|
|
|
130
261
|
return "TodoWrite"
|
|
131
262
|
|
|
132
263
|
async def description(self) -> str:
|
|
133
|
-
return "
|
|
264
|
+
return "Update the todo list for the current session. To be used proactively and often to track progress and pending tasks."
|
|
134
265
|
|
|
135
266
|
@property
|
|
136
267
|
def input_schema(self) -> type[TodoWriteToolInput]:
|
|
@@ -140,7 +271,7 @@ class TodoWriteTool(Tool[TodoWriteToolInput, TodoToolOutput]):
|
|
|
140
271
|
return [
|
|
141
272
|
ToolUseExample(
|
|
142
273
|
description="Seed a three-step plan",
|
|
143
|
-
|
|
274
|
+
example={
|
|
144
275
|
"todos": [
|
|
145
276
|
{
|
|
146
277
|
"id": "plan",
|
|
@@ -165,7 +296,7 @@ class TodoWriteTool(Tool[TodoWriteToolInput, TodoToolOutput]):
|
|
|
165
296
|
),
|
|
166
297
|
ToolUseExample(
|
|
167
298
|
description="Update a single task already in progress",
|
|
168
|
-
|
|
299
|
+
example={
|
|
169
300
|
"todos": [
|
|
170
301
|
{
|
|
171
302
|
"id": "bugfix-123",
|
|
@@ -230,6 +361,9 @@ class TodoWriteTool(Tool[TodoWriteToolInput, TodoToolOutput]):
|
|
|
230
361
|
)
|
|
231
362
|
yield ToolResult(data=output, result_for_assistant=result_text)
|
|
232
363
|
except Exception as exc:
|
|
364
|
+
logger.exception(
|
|
365
|
+
"[todo_tool] Error updating todos", extra={"error": str(exc)}
|
|
366
|
+
)
|
|
233
367
|
error = f"Error updating todos: {exc}"
|
|
234
368
|
yield ToolResult(
|
|
235
369
|
data=TodoToolOutput(
|
|
@@ -263,11 +397,11 @@ class TodoReadTool(Tool[TodoReadToolInput, TodoToolOutput]):
|
|
|
263
397
|
return [
|
|
264
398
|
ToolUseExample(
|
|
265
399
|
description="Get only the next actionable todo",
|
|
266
|
-
|
|
400
|
+
example={"next_only": True},
|
|
267
401
|
),
|
|
268
402
|
ToolUseExample(
|
|
269
403
|
description="List recent completed tasks with a limit",
|
|
270
|
-
|
|
404
|
+
example={"status": ["completed"], "limit": 5},
|
|
271
405
|
),
|
|
272
406
|
]
|
|
273
407
|
|
|
@@ -19,6 +19,10 @@ from ripperdoc.core.tool import (
|
|
|
19
19
|
ValidationResult,
|
|
20
20
|
build_tool_description,
|
|
21
21
|
)
|
|
22
|
+
from ripperdoc.utils.log import get_logger
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
logger = get_logger()
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
class ToolSearchInput(BaseModel):
|
|
@@ -94,11 +98,11 @@ class ToolSearchTool(Tool[ToolSearchInput, ToolSearchOutput]):
|
|
|
94
98
|
return [
|
|
95
99
|
ToolUseExample(
|
|
96
100
|
description="Search for notebook-related tools and activate top results",
|
|
97
|
-
|
|
101
|
+
example={"query": "notebook", "max_results": 3},
|
|
98
102
|
),
|
|
99
103
|
ToolUseExample(
|
|
100
104
|
description="Activate a known tool by name",
|
|
101
|
-
|
|
105
|
+
example={"names": ["mcp__search__query"], "auto_activate": True},
|
|
102
106
|
),
|
|
103
107
|
]
|
|
104
108
|
|
|
@@ -119,7 +123,9 @@ class ToolSearchTool(Tool[ToolSearchInput, ToolSearchOutput]):
|
|
|
119
123
|
return False
|
|
120
124
|
|
|
121
125
|
async def validate_input(
|
|
122
|
-
self,
|
|
126
|
+
self,
|
|
127
|
+
input_data: ToolSearchInput,
|
|
128
|
+
context: Optional[ToolUseContext] = None, # noqa: ARG002
|
|
123
129
|
) -> ValidationResult:
|
|
124
130
|
if not (input_data.query or input_data.names):
|
|
125
131
|
return ValidationResult(
|
|
@@ -172,6 +178,7 @@ class ToolSearchTool(Tool[ToolSearchInput, ToolSearchOutput]):
|
|
|
172
178
|
regex = re.compile(normalized[1:-1], re.IGNORECASE)
|
|
173
179
|
except re.error:
|
|
174
180
|
regex = None
|
|
181
|
+
logger.exception("[tool_search] Invalid regex search query", extra={"query": query})
|
|
175
182
|
|
|
176
183
|
def _tokenize(text: str) -> List[str]:
|
|
177
184
|
return re.findall(r"[a-z0-9]+", text.lower())
|
|
@@ -184,6 +191,10 @@ class ToolSearchTool(Tool[ToolSearchInput, ToolSearchOutput]):
|
|
|
184
191
|
)
|
|
185
192
|
except Exception:
|
|
186
193
|
description = ""
|
|
194
|
+
logger.exception(
|
|
195
|
+
"[tool_search] Failed to build tool description",
|
|
196
|
+
extra={"tool_name": getattr(tool, "name", None)},
|
|
197
|
+
)
|
|
187
198
|
doc_text = " ".join([name, tool.user_facing_name(), description])
|
|
188
199
|
tokens = _tokenize(doc_text)
|
|
189
200
|
corpus.append((name, tool, tokens, len(tokens), description))
|
|
@@ -193,7 +204,7 @@ class ToolSearchTool(Tool[ToolSearchInput, ToolSearchOutput]):
|
|
|
193
204
|
|
|
194
205
|
avg_len = sum(doc_len for _, _, _, doc_len, _ in corpus) / len(corpus)
|
|
195
206
|
query_terms = _tokenize(normalized)
|
|
196
|
-
df = defaultdict(int)
|
|
207
|
+
df: Dict[str, int] = defaultdict(int)
|
|
197
208
|
for _, _, tokens, _, _ in corpus:
|
|
198
209
|
seen_terms = set(tokens)
|
|
199
210
|
for term in query_terms:
|