ripperdoc 0.2.3__py3-none-any.whl → 0.2.4__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/commands/context_cmd.py +3 -3
- ripperdoc/cli/ui/rich_ui.py +35 -2
- ripperdoc/core/agents.py +160 -0
- ripperdoc/core/default_tools.py +6 -0
- ripperdoc/core/providers/__init__.py +31 -15
- ripperdoc/core/providers/anthropic.py +15 -4
- ripperdoc/core/providers/base.py +63 -14
- ripperdoc/core/providers/gemini.py +415 -91
- ripperdoc/core/providers/openai.py +125 -14
- ripperdoc/core/query.py +7 -1
- ripperdoc/core/query_utils.py +1 -1
- ripperdoc/core/system_prompt.py +67 -61
- ripperdoc/core/tool.py +7 -0
- ripperdoc/tools/ask_user_question_tool.py +433 -0
- ripperdoc/tools/background_shell.py +70 -20
- ripperdoc/tools/enter_plan_mode_tool.py +223 -0
- ripperdoc/tools/exit_plan_mode_tool.py +150 -0
- ripperdoc/tools/mcp_tools.py +113 -4
- ripperdoc/tools/task_tool.py +88 -5
- ripperdoc/utils/mcp.py +49 -10
- ripperdoc/utils/message_compaction.py +3 -5
- ripperdoc/utils/token_estimation.py +33 -0
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/METADATA +3 -1
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/RECORD +29 -25
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/WHEEL +0 -0
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/entry_points.txt +0 -0
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {ripperdoc-0.2.3.dist-info → ripperdoc-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import asyncio
|
|
5
6
|
import time
|
|
6
7
|
from typing import Any, Dict, List, Optional, cast
|
|
8
|
+
from uuid import uuid4
|
|
7
9
|
|
|
8
10
|
from openai import AsyncOpenAI
|
|
9
11
|
|
|
@@ -13,12 +15,14 @@ from ripperdoc.core.providers.base import (
|
|
|
13
15
|
ProviderClient,
|
|
14
16
|
ProviderResponse,
|
|
15
17
|
call_with_timeout_and_retries,
|
|
18
|
+
iter_with_timeout,
|
|
16
19
|
sanitize_tool_history,
|
|
17
20
|
)
|
|
18
21
|
from ripperdoc.core.query_utils import (
|
|
19
22
|
build_openai_tool_schemas,
|
|
20
23
|
content_blocks_from_openai_choice,
|
|
21
24
|
estimate_cost_usd,
|
|
25
|
+
_normalize_tool_args,
|
|
22
26
|
openai_usage_tokens,
|
|
23
27
|
)
|
|
24
28
|
from ripperdoc.core.tool import Tool
|
|
@@ -50,26 +54,46 @@ class OpenAIClient(ProviderClient):
|
|
|
50
54
|
{"role": "system", "content": system_prompt}
|
|
51
55
|
] + sanitize_tool_history(list(normalized_messages))
|
|
52
56
|
collected_text: List[str] = []
|
|
57
|
+
streamed_tool_calls: Dict[int, Dict[str, Optional[str]]] = {}
|
|
58
|
+
streamed_tool_text: List[str] = []
|
|
59
|
+
streamed_usage: Dict[str, int] = {}
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
can_stream_text = stream and tool_mode == "text" and not openai_tools
|
|
62
|
+
can_stream_tools = stream and tool_mode != "text" and bool(openai_tools)
|
|
63
|
+
can_stream = can_stream_text or can_stream_tools
|
|
55
64
|
|
|
56
65
|
async with AsyncOpenAI(
|
|
57
66
|
api_key=model_profile.api_key, base_url=model_profile.api_base
|
|
58
67
|
) as client:
|
|
59
68
|
|
|
60
69
|
async def _stream_request() -> Dict[str, Dict[str, int]]:
|
|
61
|
-
|
|
70
|
+
announced_tool_indexes: set[int] = set()
|
|
71
|
+
stream_coro = client.chat.completions.create( # type: ignore[call-overload]
|
|
62
72
|
model=model_profile.model,
|
|
63
73
|
messages=cast(Any, openai_messages),
|
|
64
|
-
tools=None,
|
|
74
|
+
tools=openai_tools if can_stream_tools else None,
|
|
65
75
|
temperature=model_profile.temperature,
|
|
66
76
|
max_tokens=model_profile.max_tokens,
|
|
67
77
|
stream=True,
|
|
78
|
+
stream_options={"include_usage": True},
|
|
68
79
|
)
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
stream_resp = (
|
|
81
|
+
await asyncio.wait_for(stream_coro, timeout=request_timeout)
|
|
82
|
+
if request_timeout and request_timeout > 0
|
|
83
|
+
else await stream_coro
|
|
84
|
+
)
|
|
85
|
+
async for chunk in iter_with_timeout(stream_resp, request_timeout):
|
|
86
|
+
if getattr(chunk, "usage", None):
|
|
87
|
+
streamed_usage.update(openai_usage_tokens(chunk.usage))
|
|
88
|
+
|
|
89
|
+
if not getattr(chunk, "choices", None):
|
|
90
|
+
continue
|
|
71
91
|
delta = getattr(chunk.choices[0], "delta", None)
|
|
72
|
-
|
|
92
|
+
if not delta:
|
|
93
|
+
continue
|
|
94
|
+
|
|
95
|
+
# Text deltas (rare in native tool mode but supported)
|
|
96
|
+
delta_content = getattr(delta, "content", None)
|
|
73
97
|
text_delta = ""
|
|
74
98
|
if delta_content:
|
|
75
99
|
if isinstance(delta_content, list):
|
|
@@ -82,15 +106,50 @@ class OpenAIClient(ProviderClient):
|
|
|
82
106
|
elif isinstance(delta_content, str):
|
|
83
107
|
text_delta += delta_content
|
|
84
108
|
if text_delta:
|
|
85
|
-
collected_text
|
|
109
|
+
target_collector = streamed_tool_text if can_stream_tools else collected_text
|
|
110
|
+
target_collector.append(text_delta)
|
|
86
111
|
if progress_callback:
|
|
87
112
|
try:
|
|
88
113
|
await progress_callback(text_delta)
|
|
89
114
|
except Exception:
|
|
90
115
|
logger.exception("[openai_client] Stream callback failed")
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
|
|
117
|
+
# Tool call deltas for native tool mode
|
|
118
|
+
if not can_stream_tools:
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
for tool_delta in getattr(delta, "tool_calls", []) or []:
|
|
122
|
+
idx = getattr(tool_delta, "index", 0) or 0
|
|
123
|
+
state = streamed_tool_calls.get(idx, {"id": None, "name": None, "arguments": ""})
|
|
124
|
+
|
|
125
|
+
if getattr(tool_delta, "id", None):
|
|
126
|
+
state["id"] = tool_delta.id
|
|
127
|
+
|
|
128
|
+
function_delta = getattr(tool_delta, "function", None)
|
|
129
|
+
if function_delta:
|
|
130
|
+
fn_name = getattr(function_delta, "name", None)
|
|
131
|
+
if fn_name:
|
|
132
|
+
state["name"] = fn_name
|
|
133
|
+
args_delta = getattr(function_delta, "arguments", None)
|
|
134
|
+
if args_delta:
|
|
135
|
+
state["arguments"] = (state.get("arguments") or "") + args_delta
|
|
136
|
+
if progress_callback:
|
|
137
|
+
try:
|
|
138
|
+
await progress_callback(args_delta)
|
|
139
|
+
except Exception:
|
|
140
|
+
logger.exception("[openai_client] Stream callback failed")
|
|
141
|
+
|
|
142
|
+
if idx not in announced_tool_indexes and state.get("name"):
|
|
143
|
+
announced_tool_indexes.add(idx)
|
|
144
|
+
if progress_callback:
|
|
145
|
+
try:
|
|
146
|
+
await progress_callback(f"[tool:{state['name']}]")
|
|
147
|
+
except Exception:
|
|
148
|
+
logger.exception("[openai_client] Stream callback failed")
|
|
149
|
+
|
|
150
|
+
streamed_tool_calls[idx] = state
|
|
151
|
+
|
|
152
|
+
return {"usage": streamed_usage}
|
|
94
153
|
|
|
95
154
|
async def _non_stream_request() -> Any:
|
|
96
155
|
return await client.chat.completions.create( # type: ignore[call-overload]
|
|
@@ -101,23 +160,75 @@ class OpenAIClient(ProviderClient):
|
|
|
101
160
|
max_tokens=model_profile.max_tokens,
|
|
102
161
|
)
|
|
103
162
|
|
|
163
|
+
timeout_for_call = None if can_stream else request_timeout
|
|
104
164
|
openai_response: Any = await call_with_timeout_and_retries(
|
|
105
165
|
_stream_request if can_stream else _non_stream_request,
|
|
106
|
-
|
|
166
|
+
timeout_for_call,
|
|
107
167
|
max_retries,
|
|
108
168
|
)
|
|
109
169
|
|
|
170
|
+
if (
|
|
171
|
+
can_stream_text
|
|
172
|
+
and not collected_text
|
|
173
|
+
and not streamed_tool_calls
|
|
174
|
+
and not streamed_tool_text
|
|
175
|
+
):
|
|
176
|
+
logger.debug(
|
|
177
|
+
"[openai_client] Streaming returned no content; retrying without stream",
|
|
178
|
+
extra={"model": model_profile.model},
|
|
179
|
+
)
|
|
180
|
+
can_stream = False
|
|
181
|
+
can_stream_text = False
|
|
182
|
+
can_stream_tools = False
|
|
183
|
+
openai_response = await call_with_timeout_and_retries(
|
|
184
|
+
_non_stream_request, request_timeout, max_retries
|
|
185
|
+
)
|
|
186
|
+
|
|
110
187
|
duration_ms = (time.time() - start_time) * 1000
|
|
111
|
-
usage_tokens = openai_usage_tokens(
|
|
188
|
+
usage_tokens = streamed_usage if can_stream else openai_usage_tokens(
|
|
189
|
+
getattr(openai_response, "usage", None)
|
|
190
|
+
)
|
|
112
191
|
cost_usd = estimate_cost_usd(model_profile, usage_tokens)
|
|
113
192
|
record_usage(
|
|
114
193
|
model_profile.model, duration_ms=duration_ms, cost_usd=cost_usd, **usage_tokens
|
|
115
194
|
)
|
|
116
195
|
|
|
117
|
-
|
|
118
|
-
|
|
196
|
+
if not can_stream and (not openai_response or not getattr(openai_response, "choices", None)):
|
|
197
|
+
logger.warning(
|
|
198
|
+
"[openai_client] No choices returned from OpenAI response",
|
|
199
|
+
extra={"model": model_profile.model},
|
|
200
|
+
)
|
|
201
|
+
empty_text = "Model returned no content."
|
|
202
|
+
return ProviderResponse(
|
|
203
|
+
content_blocks=[{"type": "text", "text": empty_text}],
|
|
204
|
+
usage_tokens=usage_tokens,
|
|
205
|
+
cost_usd=cost_usd,
|
|
206
|
+
duration_ms=duration_ms,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
content_blocks: List[Dict[str, Any]] = []
|
|
210
|
+
finish_reason: Optional[str] = None
|
|
211
|
+
if can_stream_text:
|
|
119
212
|
content_blocks = [{"type": "text", "text": "".join(collected_text)}]
|
|
120
213
|
finish_reason = "stream"
|
|
214
|
+
elif can_stream_tools:
|
|
215
|
+
if streamed_tool_text:
|
|
216
|
+
content_blocks.append({"type": "text", "text": "".join(streamed_tool_text)})
|
|
217
|
+
for idx in sorted(streamed_tool_calls.keys()):
|
|
218
|
+
call = streamed_tool_calls[idx]
|
|
219
|
+
name = call.get("name")
|
|
220
|
+
if not name:
|
|
221
|
+
continue
|
|
222
|
+
tool_use_id = call.get("id") or str(uuid4())
|
|
223
|
+
content_blocks.append(
|
|
224
|
+
{
|
|
225
|
+
"type": "tool_use",
|
|
226
|
+
"tool_use_id": tool_use_id,
|
|
227
|
+
"name": name,
|
|
228
|
+
"input": _normalize_tool_args(call.get("arguments")),
|
|
229
|
+
}
|
|
230
|
+
)
|
|
231
|
+
finish_reason = "stream"
|
|
121
232
|
else:
|
|
122
233
|
choice = openai_response.choices[0]
|
|
123
234
|
content_blocks = content_blocks_from_openai_choice(choice, tool_mode)
|
ripperdoc/core/query.py
CHANGED
|
@@ -58,7 +58,7 @@ from ripperdoc.utils.messages import (
|
|
|
58
58
|
logger = get_logger()
|
|
59
59
|
|
|
60
60
|
DEFAULT_REQUEST_TIMEOUT_SEC = float(os.getenv("RIPPERDOC_API_TIMEOUT", "120"))
|
|
61
|
-
MAX_LLM_RETRIES =
|
|
61
|
+
MAX_LLM_RETRIES = int(os.getenv("RIPPERDOC_MAX_RETRIES", "10"))
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
def _resolve_tool(
|
|
@@ -377,6 +377,8 @@ class QueryContext:
|
|
|
377
377
|
safe_mode: bool = False,
|
|
378
378
|
model: str = "main",
|
|
379
379
|
verbose: bool = False,
|
|
380
|
+
pause_ui: Optional[Callable[[], None]] = None,
|
|
381
|
+
resume_ui: Optional[Callable[[], None]] = None,
|
|
380
382
|
) -> None:
|
|
381
383
|
self.tool_registry = ToolRegistry(tools)
|
|
382
384
|
self.max_thinking_tokens = max_thinking_tokens
|
|
@@ -385,6 +387,8 @@ class QueryContext:
|
|
|
385
387
|
self.verbose = verbose
|
|
386
388
|
self.abort_controller = asyncio.Event()
|
|
387
389
|
self.file_state_cache: Dict[str, FileSnapshot] = {}
|
|
390
|
+
self.pause_ui = pause_ui
|
|
391
|
+
self.resume_ui = resume_ui
|
|
388
392
|
|
|
389
393
|
@property
|
|
390
394
|
def tools(self) -> List[Tool[Any, Any]]:
|
|
@@ -714,6 +718,8 @@ async def query(
|
|
|
714
718
|
tool_registry=query_context.tool_registry,
|
|
715
719
|
file_state_cache=query_context.file_state_cache,
|
|
716
720
|
abort_signal=query_context.abort_controller,
|
|
721
|
+
pause_ui=query_context.pause_ui,
|
|
722
|
+
resume_ui=query_context.resume_ui,
|
|
717
723
|
)
|
|
718
724
|
|
|
719
725
|
validation = await tool.validate_input(parsed_input, tool_context)
|
ripperdoc/core/query_utils.py
CHANGED
|
@@ -7,7 +7,7 @@ import re
|
|
|
7
7
|
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
8
8
|
from uuid import uuid4
|
|
9
9
|
|
|
10
|
-
from json_repair import repair_json
|
|
10
|
+
from json_repair import repair_json # type: ignore[import-not-found]
|
|
11
11
|
from pydantic import ValidationError
|
|
12
12
|
|
|
13
13
|
from ripperdoc.core.config import ModelProfile, ProviderType, get_global_config
|
ripperdoc/core/system_prompt.py
CHANGED
|
@@ -8,7 +8,19 @@ from pathlib import Path
|
|
|
8
8
|
from textwrap import dedent
|
|
9
9
|
from typing import Any, Dict, Iterable, List, Optional
|
|
10
10
|
|
|
11
|
-
from ripperdoc.core.agents import
|
|
11
|
+
from ripperdoc.core.agents import (
|
|
12
|
+
ASK_USER_QUESTION_TOOL_NAME,
|
|
13
|
+
BASH_TOOL_NAME,
|
|
14
|
+
FILE_EDIT_TOOL_NAME,
|
|
15
|
+
FILE_WRITE_TOOL_NAME,
|
|
16
|
+
TASK_TOOL_NAME,
|
|
17
|
+
TODO_WRITE_TOOL_NAME,
|
|
18
|
+
TOOL_SEARCH_TOOL_NAME,
|
|
19
|
+
VIEW_TOOL_NAME,
|
|
20
|
+
clear_agent_cache,
|
|
21
|
+
load_agent_definitions,
|
|
22
|
+
summarize_agent,
|
|
23
|
+
)
|
|
12
24
|
from ripperdoc.core.tool import Tool
|
|
13
25
|
from ripperdoc.utils.log import get_logger
|
|
14
26
|
|
|
@@ -174,10 +186,18 @@ def build_system_prompt(
|
|
|
174
186
|
) -> str:
|
|
175
187
|
_ = user_prompt, context
|
|
176
188
|
tool_names = {tool.name for tool in tools}
|
|
177
|
-
todo_tool_name =
|
|
189
|
+
todo_tool_name = TODO_WRITE_TOOL_NAME
|
|
178
190
|
todo_available = todo_tool_name in tool_names
|
|
179
|
-
task_available =
|
|
180
|
-
|
|
191
|
+
task_available = TASK_TOOL_NAME in tool_names
|
|
192
|
+
ask_tool_name = ASK_USER_QUESTION_TOOL_NAME
|
|
193
|
+
ask_available = ask_tool_name in tool_names
|
|
194
|
+
view_tool_name = VIEW_TOOL_NAME
|
|
195
|
+
file_edit_tool_name = FILE_EDIT_TOOL_NAME
|
|
196
|
+
file_write_tool_name = FILE_WRITE_TOOL_NAME
|
|
197
|
+
shell_tool_name = next(
|
|
198
|
+
(tool.name for tool in tools if tool.name.lower() == BASH_TOOL_NAME.lower()),
|
|
199
|
+
BASH_TOOL_NAME,
|
|
200
|
+
)
|
|
181
201
|
|
|
182
202
|
main_prompt = dedent(
|
|
183
203
|
f"""\
|
|
@@ -190,61 +210,25 @@ def build_system_prompt(
|
|
|
190
210
|
- /help: Get help with using {APP_NAME}
|
|
191
211
|
- To give feedback, users should report the issue at {FEEDBACK_URL}
|
|
192
212
|
|
|
193
|
-
#
|
|
194
|
-
|
|
195
|
-
You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail.
|
|
196
|
-
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
|
|
197
|
-
IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
|
|
198
|
-
Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did.
|
|
199
|
-
Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". Here are some examples to demonstrate appropriate verbosity:
|
|
200
|
-
<example>
|
|
201
|
-
user: 2 + 2
|
|
202
|
-
assistant: 4
|
|
203
|
-
</example>
|
|
204
|
-
|
|
205
|
-
<example>
|
|
206
|
-
user: what is 2+2?
|
|
207
|
-
assistant: 4
|
|
208
|
-
</example>
|
|
209
|
-
|
|
210
|
-
<example>
|
|
211
|
-
user: is 11 a prime number?
|
|
212
|
-
assistant: Yes
|
|
213
|
-
</example>
|
|
214
|
-
|
|
215
|
-
<example>
|
|
216
|
-
user: what command should I run to list files in the current directory?
|
|
217
|
-
assistant: ls
|
|
218
|
-
</example>
|
|
213
|
+
# Looking up your own documentation
|
|
214
|
+
When the user asks what {APP_NAME} can do, how to use it (hooks, slash commands, MCP, SDKs), or requests SDK code samples, use the {TASK_TOOL_NAME} tool with a documentation-focused subagent (for example, subagent_type="docs") if available to consult official docs before answering.
|
|
219
215
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
user
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
assistant: [runs ls and sees foo.c, bar.c, baz.c]
|
|
234
|
-
user: which file contains the implementation of foo?
|
|
235
|
-
assistant: src/foo.c
|
|
236
|
-
</example>
|
|
237
|
-
|
|
238
|
-
<example>
|
|
239
|
-
user: write tests for new feature
|
|
240
|
-
assistant: [uses grep and glob search tools to find where similar tests are defined, uses concurrent read file tool use blocks in one tool call to read relevant files at the same time, uses edit file tool to write new tests]
|
|
241
|
-
</example>
|
|
216
|
+
# Tone and style
|
|
217
|
+
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
218
|
+
- Your output will be displayed on a command line interface. Your responses should be short and concise. You can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
219
|
+
- Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like {BASH_TOOL_NAME} or code comments as means to communicate with the user during the session.
|
|
220
|
+
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. This includes markdown files.
|
|
221
|
+
|
|
222
|
+
# Professional objectivity
|
|
223
|
+
Prioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving, providing direct, objective technical info without any unnecessary superlatives, praise, or emotional validation. It is best for the user if Claude honestly applies the same rigorous standards to all ideas and disagrees when necessary, even if it may not be what the user wants to hear. Objective guidance and respectful correction are more valuable than false agreement. Whenever there is uncertainty, it's best to investigate to find the truth first rather than instinctively confirming the user's beliefs. Avoid using over-the-top validation or excessive praise when responding to users such as "You're absolutely right" or similar phrases.
|
|
224
|
+
|
|
225
|
+
# Planning without timelines
|
|
226
|
+
When planning tasks, provide concrete implementation steps without time estimates. Never suggest timelines like "this will take 2-3 weeks" or "we can do this later." Focus on what needs to be done, not when. Break work into actionable steps and let users decide scheduling.
|
|
227
|
+
|
|
228
|
+
# Explain Your Code: Bash Command Transparency
|
|
242
229
|
When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).
|
|
243
230
|
Remember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
244
|
-
Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like {shell_tool_name} or code comments as means to communicate with the user during the session.
|
|
245
231
|
If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
|
|
246
|
-
Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
247
|
-
IMPORTANT: Keep your responses short, since they will be displayed on a command line interface.
|
|
248
232
|
|
|
249
233
|
# Proactiveness
|
|
250
234
|
You are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:
|
|
@@ -260,7 +244,7 @@ def build_system_prompt(
|
|
|
260
244
|
- Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.
|
|
261
245
|
|
|
262
246
|
# Code style
|
|
263
|
-
-
|
|
247
|
+
- Only add comments when the logic is not self-evident and within code you changed. Do not add docstrings, comments, or type annotations to code you did not modify."""
|
|
264
248
|
).strip()
|
|
265
249
|
|
|
266
250
|
if mcp_instructions:
|
|
@@ -318,6 +302,15 @@ def build_system_prompt(
|
|
|
318
302
|
</example>"""
|
|
319
303
|
).strip()
|
|
320
304
|
|
|
305
|
+
ask_questions_section = ""
|
|
306
|
+
if ask_available:
|
|
307
|
+
ask_questions_section = dedent(
|
|
308
|
+
f"""\
|
|
309
|
+
# Asking questions as you work
|
|
310
|
+
|
|
311
|
+
You have access to the {ask_tool_name} tool to ask the user questions when you need clarification, want to validate assumptions, or need to make a decision you're unsure about. When presenting options or plans, do not include time estimates—focus on what each option involves."""
|
|
312
|
+
).strip()
|
|
313
|
+
|
|
321
314
|
hooks_section = dedent(
|
|
322
315
|
"""\
|
|
323
316
|
Users may configure 'hooks', shell commands that execute in response to events like tool calls, in settings. Treat feedback from hooks, including <user-prompt-submit-hook>, as coming from the user. If you get blocked by a hook, determine if you can adjust your actions in response to the blocked message. If not, ask the user to check their hooks configuration."""
|
|
@@ -329,15 +322,26 @@ def build_system_prompt(
|
|
|
329
322
|
]
|
|
330
323
|
if todo_available:
|
|
331
324
|
doing_tasks_lines.append(f"- Use the {todo_tool_name} tool to plan the task if required")
|
|
325
|
+
if ask_available:
|
|
326
|
+
doing_tasks_lines.append(
|
|
327
|
+
f"- Use the {ask_tool_name} tool to ask questions, clarify, and gather information as needed."
|
|
328
|
+
)
|
|
332
329
|
doing_tasks_lines.extend(
|
|
333
330
|
[
|
|
331
|
+
"- NEVER propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first.",
|
|
334
332
|
"- Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.",
|
|
335
|
-
"-
|
|
333
|
+
"- When exploring the codebase beyond a needle query, prefer using the Task tool with an exploration subagent if available instead of running raw search commands directly.",
|
|
334
|
+
"- Implement the solution using all tools available to you.",
|
|
335
|
+
"- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it.",
|
|
336
|
+
"- Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.",
|
|
337
|
+
" - Don't add features, refactor code, or make improvements beyond what was asked. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.",
|
|
338
|
+
" - Don't add error handling, fallbacks, or validation for scenarios that can't happen. Validate only at system boundaries (user input, external APIs).",
|
|
339
|
+
" - Don't create helpers, utilities, or abstractions for one-time operations. Avoid feature flags or backwards-compatibility shims when a direct change is sufficient. If something is unused, delete it completely.",
|
|
336
340
|
"- Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.",
|
|
337
341
|
f"- VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with {shell_tool_name} if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to AGENTS.md so that you will know to run it next time.",
|
|
338
342
|
"NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.",
|
|
339
|
-
"",
|
|
340
343
|
"- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.",
|
|
344
|
+
"- The conversation has unlimited context through automatic summarization. Complete tasks fully; do not stop mid-task or claim context limits.",
|
|
341
345
|
]
|
|
342
346
|
)
|
|
343
347
|
doing_tasks_section = "\n".join(doing_tasks_lines)
|
|
@@ -345,7 +349,8 @@ def build_system_prompt(
|
|
|
345
349
|
tool_usage_lines = [
|
|
346
350
|
"# Tool usage policy",
|
|
347
351
|
'- You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.',
|
|
348
|
-
"",
|
|
352
|
+
"- If the user asks to run tools in parallel and there are no dependencies, include multiple tool calls in a single message; sequence dependent calls instead of guessing values.",
|
|
353
|
+
f"- Use specialized tools instead of bash when possible: use {view_tool_name} for reading files, {file_edit_tool_name} for editing, and {file_write_tool_name} for creating files. Do not use bash echo or other command-line tools to communicate with the user; reply in text.",
|
|
349
354
|
"You MUST answer concisely with fewer than 4 lines of text (not including tool use or code generation), unless user asks for detail.",
|
|
350
355
|
]
|
|
351
356
|
if task_available:
|
|
@@ -353,7 +358,7 @@ def build_system_prompt(
|
|
|
353
358
|
1,
|
|
354
359
|
"- Use the Task tool with configured subagents when the task matches an agent's description. Always set subagent_type.",
|
|
355
360
|
)
|
|
356
|
-
if
|
|
361
|
+
if TOOL_SEARCH_TOOL_NAME in tool_names:
|
|
357
362
|
tool_usage_lines.insert(
|
|
358
363
|
1,
|
|
359
364
|
"- Use the ToolSearch tool to discover and activate deferred or MCP tools. Keep searches focused and load only 3-5 relevant tools.",
|
|
@@ -402,6 +407,7 @@ def build_system_prompt(
|
|
|
402
407
|
sections: List[str] = [
|
|
403
408
|
main_prompt,
|
|
404
409
|
task_management_section,
|
|
410
|
+
ask_questions_section,
|
|
405
411
|
hooks_section,
|
|
406
412
|
doing_tasks_section,
|
|
407
413
|
tool_usage_section,
|
|
@@ -409,7 +415,7 @@ def build_system_prompt(
|
|
|
409
415
|
build_environment_prompt(),
|
|
410
416
|
DEFENSIVE_SECURITY_GUIDELINE,
|
|
411
417
|
always_use_todo,
|
|
412
|
-
build_commit_workflow_prompt(shell_tool_name, todo_tool_name,
|
|
418
|
+
build_commit_workflow_prompt(shell_tool_name, todo_tool_name, TASK_TOOL_NAME),
|
|
413
419
|
code_references,
|
|
414
420
|
]
|
|
415
421
|
|
ripperdoc/core/tool.py
CHANGED
|
@@ -44,6 +44,13 @@ class ToolUseContext(BaseModel):
|
|
|
44
44
|
file_state_cache: Dict[str, "FileSnapshot"] = Field(default_factory=dict)
|
|
45
45
|
tool_registry: Optional[Any] = None
|
|
46
46
|
abort_signal: Optional[Any] = None
|
|
47
|
+
# UI control callbacks for tools that need user interaction
|
|
48
|
+
pause_ui: Optional[Any] = Field(default=None, description="Callback to pause UI spinner")
|
|
49
|
+
resume_ui: Optional[Any] = Field(default=None, description="Callback to resume UI spinner")
|
|
50
|
+
# Plan mode control callback
|
|
51
|
+
on_exit_plan_mode: Optional[Any] = Field(
|
|
52
|
+
default=None, description="Callback invoked when exiting plan mode"
|
|
53
|
+
)
|
|
47
54
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
48
55
|
|
|
49
56
|
|