shotgun-sh 0.3.3.dev1__py3-none-any.whl → 0.4.0.dev1__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.
- shotgun/agents/agent_manager.py +191 -23
- shotgun/agents/common.py +78 -77
- shotgun/agents/config/manager.py +42 -1
- shotgun/agents/config/models.py +16 -0
- shotgun/agents/conversation/history/file_content_deduplication.py +66 -43
- shotgun/agents/export.py +12 -13
- shotgun/agents/models.py +66 -1
- shotgun/agents/plan.py +12 -13
- shotgun/agents/research.py +13 -10
- shotgun/agents/router/__init__.py +47 -0
- shotgun/agents/router/models.py +376 -0
- shotgun/agents/router/router.py +185 -0
- shotgun/agents/router/tools/__init__.py +18 -0
- shotgun/agents/router/tools/delegation_tools.py +503 -0
- shotgun/agents/router/tools/plan_tools.py +322 -0
- shotgun/agents/specify.py +12 -13
- shotgun/agents/tasks.py +12 -13
- shotgun/agents/tools/file_management.py +49 -1
- shotgun/agents/tools/registry.py +2 -0
- shotgun/agents/tools/web_search/__init__.py +1 -2
- shotgun/agents/tools/web_search/gemini.py +1 -3
- shotgun/codebase/core/change_detector.py +1 -1
- shotgun/codebase/core/ingestor.py +1 -1
- shotgun/codebase/core/manager.py +1 -1
- shotgun/prompts/agents/export.j2 +2 -0
- shotgun/prompts/agents/partials/common_agent_system_prompt.j2 +5 -10
- shotgun/prompts/agents/partials/router_delegation_mode.j2 +36 -0
- shotgun/prompts/agents/plan.j2 +24 -12
- shotgun/prompts/agents/research.j2 +70 -31
- shotgun/prompts/agents/router.j2 +440 -0
- shotgun/prompts/agents/specify.j2 +39 -16
- shotgun/prompts/agents/state/system_state.j2 +15 -6
- shotgun/prompts/agents/tasks.j2 +58 -34
- shotgun/tui/app.py +5 -6
- shotgun/tui/components/mode_indicator.py +120 -25
- shotgun/tui/components/status_bar.py +2 -2
- shotgun/tui/dependencies.py +64 -9
- shotgun/tui/protocols.py +37 -0
- shotgun/tui/screens/chat/chat.tcss +9 -1
- shotgun/tui/screens/chat/chat_screen.py +643 -11
- shotgun/tui/screens/chat_screen/command_providers.py +0 -87
- shotgun/tui/screens/chat_screen/history/agent_response.py +7 -3
- shotgun/tui/screens/chat_screen/history/chat_history.py +12 -0
- shotgun/tui/screens/chat_screen/history/formatters.py +53 -15
- shotgun/tui/screens/chat_screen/history/partial_response.py +11 -1
- shotgun/tui/screens/chat_screen/messages.py +219 -0
- shotgun/tui/screens/onboarding.py +30 -26
- shotgun/tui/utils/mode_progress.py +20 -86
- shotgun/tui/widgets/__init__.py +2 -1
- shotgun/tui/widgets/approval_widget.py +152 -0
- shotgun/tui/widgets/cascade_confirmation_widget.py +203 -0
- shotgun/tui/widgets/plan_panel.py +129 -0
- shotgun/tui/widgets/step_checkpoint_widget.py +180 -0
- {shotgun_sh-0.3.3.dev1.dist-info → shotgun_sh-0.4.0.dev1.dist-info}/METADATA +3 -3
- {shotgun_sh-0.3.3.dev1.dist-info → shotgun_sh-0.4.0.dev1.dist-info}/RECORD +58 -45
- {shotgun_sh-0.3.3.dev1.dist-info → shotgun_sh-0.4.0.dev1.dist-info}/WHEEL +0 -0
- {shotgun_sh-0.3.3.dev1.dist-info → shotgun_sh-0.4.0.dev1.dist-info}/entry_points.txt +0 -0
- {shotgun_sh-0.3.3.dev1.dist-info → shotgun_sh-0.4.0.dev1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"""Plan management tools for the Router agent.
|
|
2
|
+
|
|
3
|
+
These tools allow the router to create and manage execution plans.
|
|
4
|
+
All tools use Pydantic models for inputs and outputs.
|
|
5
|
+
|
|
6
|
+
IMPORTANT: There is NO get_plan() tool - the plan is shown in the system
|
|
7
|
+
status message every turn so the router always has visibility into it.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pydantic_ai import RunContext
|
|
11
|
+
|
|
12
|
+
from shotgun.agents.router.models import (
|
|
13
|
+
AddStepInput,
|
|
14
|
+
CreatePlanInput,
|
|
15
|
+
ExecutionPlan,
|
|
16
|
+
ExecutionStep,
|
|
17
|
+
MarkStepDoneInput,
|
|
18
|
+
PendingApproval,
|
|
19
|
+
PendingCheckpoint,
|
|
20
|
+
PlanApprovalStatus,
|
|
21
|
+
RemoveStepInput,
|
|
22
|
+
RouterDeps,
|
|
23
|
+
RouterMode,
|
|
24
|
+
ToolResult,
|
|
25
|
+
)
|
|
26
|
+
from shotgun.agents.tools.registry import ToolCategory, register_tool
|
|
27
|
+
from shotgun.logging_config import get_logger
|
|
28
|
+
|
|
29
|
+
logger = get_logger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _notify_plan_changed(deps: RouterDeps) -> None:
|
|
33
|
+
"""Notify TUI of plan changes via callback if registered.
|
|
34
|
+
|
|
35
|
+
This helper is called after any plan modification to update the
|
|
36
|
+
Plan Panel widget in the TUI.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
deps: RouterDeps containing the on_plan_changed callback.
|
|
40
|
+
"""
|
|
41
|
+
if deps.on_plan_changed:
|
|
42
|
+
deps.on_plan_changed(deps.current_plan)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@register_tool(
|
|
46
|
+
category=ToolCategory.PLANNING,
|
|
47
|
+
display_text="Creating execution plan",
|
|
48
|
+
key_arg="input",
|
|
49
|
+
)
|
|
50
|
+
async def create_plan(
|
|
51
|
+
ctx: RunContext[RouterDeps], input: CreatePlanInput
|
|
52
|
+
) -> ToolResult:
|
|
53
|
+
"""Create a new execution plan for the current task.
|
|
54
|
+
|
|
55
|
+
This replaces any existing plan. The plan is stored in-memory in RouterDeps,
|
|
56
|
+
NOT in a file. It will be shown in the system status message.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
ctx: RunContext with RouterDeps
|
|
60
|
+
input: CreatePlanInput with goal and steps
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
ToolResult indicating success or failure
|
|
64
|
+
"""
|
|
65
|
+
logger.debug("Creating execution plan with goal: %s", input.goal)
|
|
66
|
+
|
|
67
|
+
# Convert step inputs to ExecutionStep objects
|
|
68
|
+
steps = [
|
|
69
|
+
ExecutionStep(
|
|
70
|
+
id=step_input.id,
|
|
71
|
+
title=step_input.title,
|
|
72
|
+
objective=step_input.objective,
|
|
73
|
+
done=False,
|
|
74
|
+
)
|
|
75
|
+
for step_input in input.steps
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
# Create and store the plan
|
|
79
|
+
plan = ExecutionPlan(
|
|
80
|
+
goal=input.goal,
|
|
81
|
+
steps=steps,
|
|
82
|
+
current_step_index=0,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
ctx.deps.current_plan = plan
|
|
86
|
+
|
|
87
|
+
# Set pending approval for multi-step plans in Planning mode
|
|
88
|
+
# The TUI will detect this and show the PlanApprovalWidget
|
|
89
|
+
if ctx.deps.router_mode == RouterMode.PLANNING and plan.needs_approval():
|
|
90
|
+
ctx.deps.pending_approval = PendingApproval(plan=plan)
|
|
91
|
+
ctx.deps.approval_status = PlanApprovalStatus.PENDING
|
|
92
|
+
# Plan is NOT executing yet - user must approve first
|
|
93
|
+
ctx.deps.is_executing = False
|
|
94
|
+
logger.debug(
|
|
95
|
+
"Set pending approval for plan with %d steps",
|
|
96
|
+
len(steps),
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
# Single-step plans or Drafting mode - skip approval and start executing
|
|
100
|
+
ctx.deps.approval_status = PlanApprovalStatus.SKIPPED
|
|
101
|
+
ctx.deps.is_executing = True
|
|
102
|
+
logger.debug("Plan approved automatically, is_executing=True")
|
|
103
|
+
|
|
104
|
+
logger.info(
|
|
105
|
+
"Created execution plan with %d steps: %s",
|
|
106
|
+
len(steps),
|
|
107
|
+
input.goal,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
_notify_plan_changed(ctx.deps)
|
|
111
|
+
|
|
112
|
+
# Return different message based on whether approval is needed
|
|
113
|
+
if ctx.deps.pending_approval is not None:
|
|
114
|
+
return ToolResult(
|
|
115
|
+
success=True,
|
|
116
|
+
message=f"Created plan with {len(steps)} steps. Goal: {input.goal}\n\n"
|
|
117
|
+
"IMPORTANT: This plan requires user approval before execution. "
|
|
118
|
+
"You MUST call final_result NOW to present this plan to the user. "
|
|
119
|
+
"Do NOT attempt to delegate or execute any steps yet.",
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
return ToolResult(
|
|
123
|
+
success=True,
|
|
124
|
+
message=f"Created plan with {len(steps)} steps. Goal: {input.goal}",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@register_tool(
|
|
129
|
+
category=ToolCategory.PLANNING,
|
|
130
|
+
display_text="Marking step complete",
|
|
131
|
+
key_arg="input",
|
|
132
|
+
)
|
|
133
|
+
async def mark_step_done(
|
|
134
|
+
ctx: RunContext[RouterDeps], input: MarkStepDoneInput
|
|
135
|
+
) -> ToolResult:
|
|
136
|
+
"""Mark a step in the execution plan as complete.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
ctx: RunContext with RouterDeps
|
|
140
|
+
input: MarkStepDoneInput with step_id
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
ToolResult indicating success or failure
|
|
144
|
+
"""
|
|
145
|
+
plan = ctx.deps.current_plan
|
|
146
|
+
|
|
147
|
+
if plan is None:
|
|
148
|
+
return ToolResult(
|
|
149
|
+
success=False,
|
|
150
|
+
message="No execution plan exists. Create a plan first.",
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Find the step by ID
|
|
154
|
+
for _i, step in enumerate(plan.steps):
|
|
155
|
+
if step.id == input.step_id:
|
|
156
|
+
step.done = True
|
|
157
|
+
logger.info("Marked step '%s' as done", input.step_id)
|
|
158
|
+
|
|
159
|
+
# Advance current_step_index to next incomplete step
|
|
160
|
+
while (
|
|
161
|
+
plan.current_step_index < len(plan.steps)
|
|
162
|
+
and plan.steps[plan.current_step_index].done
|
|
163
|
+
):
|
|
164
|
+
plan.current_step_index += 1
|
|
165
|
+
|
|
166
|
+
# Check if plan is complete
|
|
167
|
+
if plan.is_complete():
|
|
168
|
+
ctx.deps.is_executing = False
|
|
169
|
+
logger.debug("Plan complete, is_executing=False")
|
|
170
|
+
# Set pending checkpoint for Planning mode
|
|
171
|
+
# The TUI will detect this and show the StepCheckpointWidget
|
|
172
|
+
elif ctx.deps.router_mode == RouterMode.PLANNING:
|
|
173
|
+
# Use current_step() since the while loop above already advanced
|
|
174
|
+
# current_step_index to the next incomplete step
|
|
175
|
+
next_step = plan.current_step()
|
|
176
|
+
ctx.deps.pending_checkpoint = PendingCheckpoint(
|
|
177
|
+
completed_step=step, next_step=next_step
|
|
178
|
+
)
|
|
179
|
+
logger.debug(
|
|
180
|
+
"Set pending checkpoint: completed='%s', next='%s'",
|
|
181
|
+
step.title,
|
|
182
|
+
next_step.title if next_step else None,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
_notify_plan_changed(ctx.deps)
|
|
186
|
+
|
|
187
|
+
return ToolResult(
|
|
188
|
+
success=True,
|
|
189
|
+
message=f"Marked step '{step.title}' as complete.",
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
return ToolResult(
|
|
193
|
+
success=False,
|
|
194
|
+
message=f"Step with ID '{input.step_id}' not found in plan.",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@register_tool(
|
|
199
|
+
category=ToolCategory.PLANNING,
|
|
200
|
+
display_text="Adding step to plan",
|
|
201
|
+
key_arg="input",
|
|
202
|
+
)
|
|
203
|
+
async def add_step(ctx: RunContext[RouterDeps], input: AddStepInput) -> ToolResult:
|
|
204
|
+
"""Add a new step to the execution plan.
|
|
205
|
+
|
|
206
|
+
The step can be inserted after a specific step (by ID) or appended to the end.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
ctx: RunContext with RouterDeps
|
|
210
|
+
input: AddStepInput with step details and optional after_step_id
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
ToolResult indicating success or failure
|
|
214
|
+
"""
|
|
215
|
+
plan = ctx.deps.current_plan
|
|
216
|
+
|
|
217
|
+
if plan is None:
|
|
218
|
+
return ToolResult(
|
|
219
|
+
success=False,
|
|
220
|
+
message="No execution plan exists. Create a plan first.",
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
# Check for duplicate ID
|
|
224
|
+
existing_ids = {step.id for step in plan.steps}
|
|
225
|
+
if input.step.id in existing_ids:
|
|
226
|
+
return ToolResult(
|
|
227
|
+
success=False,
|
|
228
|
+
message=f"Step with ID '{input.step.id}' already exists in plan.",
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# Create the new step
|
|
232
|
+
new_step = ExecutionStep(
|
|
233
|
+
id=input.step.id,
|
|
234
|
+
title=input.step.title,
|
|
235
|
+
objective=input.step.objective,
|
|
236
|
+
done=False,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
# Insert at the specified position
|
|
240
|
+
if input.after_step_id is None:
|
|
241
|
+
# Append to end
|
|
242
|
+
plan.steps.append(new_step)
|
|
243
|
+
logger.info("Appended step '%s' to end of plan", input.step.id)
|
|
244
|
+
|
|
245
|
+
_notify_plan_changed(ctx.deps)
|
|
246
|
+
|
|
247
|
+
return ToolResult(
|
|
248
|
+
success=True,
|
|
249
|
+
message=f"Added step '{new_step.title}' at end of plan.",
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# Find the position to insert after
|
|
253
|
+
for i, step in enumerate(plan.steps):
|
|
254
|
+
if step.id == input.after_step_id:
|
|
255
|
+
plan.steps.insert(i + 1, new_step)
|
|
256
|
+
logger.info(
|
|
257
|
+
"Inserted step '%s' after '%s'",
|
|
258
|
+
input.step.id,
|
|
259
|
+
input.after_step_id,
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
_notify_plan_changed(ctx.deps)
|
|
263
|
+
|
|
264
|
+
return ToolResult(
|
|
265
|
+
success=True,
|
|
266
|
+
message=f"Added step '{new_step.title}' after '{step.title}'.",
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
return ToolResult(
|
|
270
|
+
success=False,
|
|
271
|
+
message=f"Step with ID '{input.after_step_id}' not found in plan.",
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@register_tool(
|
|
276
|
+
category=ToolCategory.PLANNING,
|
|
277
|
+
display_text="Removing step from plan",
|
|
278
|
+
key_arg="input",
|
|
279
|
+
)
|
|
280
|
+
async def remove_step(
|
|
281
|
+
ctx: RunContext[RouterDeps], input: RemoveStepInput
|
|
282
|
+
) -> ToolResult:
|
|
283
|
+
"""Remove a step from the execution plan.
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
ctx: RunContext with RouterDeps
|
|
287
|
+
input: RemoveStepInput with step_id
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
ToolResult indicating success or failure
|
|
291
|
+
"""
|
|
292
|
+
plan = ctx.deps.current_plan
|
|
293
|
+
|
|
294
|
+
if plan is None:
|
|
295
|
+
return ToolResult(
|
|
296
|
+
success=False,
|
|
297
|
+
message="No execution plan exists. Create a plan first.",
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
# Find and remove the step
|
|
301
|
+
for i, step in enumerate(plan.steps):
|
|
302
|
+
if step.id == input.step_id:
|
|
303
|
+
removed_step = plan.steps.pop(i)
|
|
304
|
+
logger.info("Removed step '%s' from plan", input.step_id)
|
|
305
|
+
|
|
306
|
+
# Adjust current_step_index if needed
|
|
307
|
+
if plan.current_step_index > i:
|
|
308
|
+
plan.current_step_index -= 1
|
|
309
|
+
elif plan.current_step_index >= len(plan.steps):
|
|
310
|
+
plan.current_step_index = max(0, len(plan.steps) - 1)
|
|
311
|
+
|
|
312
|
+
_notify_plan_changed(ctx.deps)
|
|
313
|
+
|
|
314
|
+
return ToolResult(
|
|
315
|
+
success=True,
|
|
316
|
+
message=f"Removed step '{removed_step.title}' from plan.",
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
return ToolResult(
|
|
320
|
+
success=False,
|
|
321
|
+
message=f"Step with ID '{input.step_id}' not found in plan.",
|
|
322
|
+
)
|
shotgun/agents/specify.py
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from functools import partial
|
|
4
4
|
|
|
5
|
-
from pydantic_ai import (
|
|
6
|
-
Agent,
|
|
7
|
-
)
|
|
8
5
|
from pydantic_ai.agent import AgentRunResult
|
|
9
6
|
from pydantic_ai.messages import ModelMessage
|
|
10
7
|
|
|
11
8
|
from shotgun.agents.config import ProviderType
|
|
9
|
+
from shotgun.agents.models import ShotgunAgent
|
|
12
10
|
from shotgun.logging_config import get_logger
|
|
13
11
|
|
|
14
12
|
from .common import (
|
|
13
|
+
EventStreamHandler,
|
|
15
14
|
add_system_status_message,
|
|
16
15
|
build_agent_system_prompt,
|
|
17
16
|
create_base_agent,
|
|
@@ -25,7 +24,7 @@ logger = get_logger(__name__)
|
|
|
25
24
|
|
|
26
25
|
async def create_specify_agent(
|
|
27
26
|
agent_runtime_options: AgentRuntimeOptions, provider: ProviderType | None = None
|
|
28
|
-
) -> tuple[
|
|
27
|
+
) -> tuple[ShotgunAgent, AgentDeps]:
|
|
29
28
|
"""Create a specify agent with artifact management capabilities.
|
|
30
29
|
|
|
31
30
|
Args:
|
|
@@ -51,26 +50,25 @@ async def create_specify_agent(
|
|
|
51
50
|
|
|
52
51
|
|
|
53
52
|
async def run_specify_agent(
|
|
54
|
-
agent:
|
|
55
|
-
|
|
53
|
+
agent: ShotgunAgent,
|
|
54
|
+
prompt: str,
|
|
56
55
|
deps: AgentDeps,
|
|
57
56
|
message_history: list[ModelMessage] | None = None,
|
|
57
|
+
event_stream_handler: EventStreamHandler | None = None,
|
|
58
58
|
) -> AgentRunResult[AgentResponse]:
|
|
59
|
-
"""Create or update specifications based on the given
|
|
59
|
+
"""Create or update specifications based on the given prompt.
|
|
60
60
|
|
|
61
61
|
Args:
|
|
62
62
|
agent: The configured specify agent
|
|
63
|
-
|
|
63
|
+
prompt: The specification prompt or instruction
|
|
64
64
|
deps: Agent dependencies
|
|
65
65
|
message_history: Optional message history for conversation continuity
|
|
66
|
+
event_stream_handler: Optional callback for streaming events
|
|
66
67
|
|
|
67
68
|
Returns:
|
|
68
69
|
AgentRunResult containing the specification process output
|
|
69
70
|
"""
|
|
70
|
-
logger.debug("📋 Starting specification for
|
|
71
|
-
|
|
72
|
-
# Simple prompt - the agent system prompt has all the artifact instructions
|
|
73
|
-
full_prompt = f"Create a comprehensive specification for: {requirement}"
|
|
71
|
+
logger.debug("📋 Starting specification for prompt: %s", prompt)
|
|
74
72
|
|
|
75
73
|
try:
|
|
76
74
|
# Create usage limits for responsible API usage
|
|
@@ -80,10 +78,11 @@ async def run_specify_agent(
|
|
|
80
78
|
|
|
81
79
|
result = await run_agent(
|
|
82
80
|
agent=agent,
|
|
83
|
-
prompt=
|
|
81
|
+
prompt=prompt,
|
|
84
82
|
deps=deps,
|
|
85
83
|
message_history=message_history,
|
|
86
84
|
usage_limits=usage_limits,
|
|
85
|
+
event_stream_handler=event_stream_handler,
|
|
87
86
|
)
|
|
88
87
|
|
|
89
88
|
logger.debug("✅ Specification completed successfully")
|
shotgun/agents/tasks.py
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from functools import partial
|
|
4
4
|
|
|
5
|
-
from pydantic_ai import (
|
|
6
|
-
Agent,
|
|
7
|
-
)
|
|
8
5
|
from pydantic_ai.agent import AgentRunResult
|
|
9
6
|
from pydantic_ai.messages import ModelMessage
|
|
10
7
|
|
|
11
8
|
from shotgun.agents.config import ProviderType
|
|
9
|
+
from shotgun.agents.models import ShotgunAgent
|
|
12
10
|
from shotgun.logging_config import get_logger
|
|
13
11
|
|
|
14
12
|
from .common import (
|
|
13
|
+
EventStreamHandler,
|
|
15
14
|
add_system_status_message,
|
|
16
15
|
build_agent_system_prompt,
|
|
17
16
|
create_base_agent,
|
|
@@ -25,7 +24,7 @@ logger = get_logger(__name__)
|
|
|
25
24
|
|
|
26
25
|
async def create_tasks_agent(
|
|
27
26
|
agent_runtime_options: AgentRuntimeOptions, provider: ProviderType | None = None
|
|
28
|
-
) -> tuple[
|
|
27
|
+
) -> tuple[ShotgunAgent, AgentDeps]:
|
|
29
28
|
"""Create a tasks agent with file management capabilities.
|
|
30
29
|
|
|
31
30
|
Args:
|
|
@@ -49,39 +48,39 @@ async def create_tasks_agent(
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
async def run_tasks_agent(
|
|
52
|
-
agent:
|
|
53
|
-
|
|
51
|
+
agent: ShotgunAgent,
|
|
52
|
+
prompt: str,
|
|
54
53
|
deps: AgentDeps,
|
|
55
54
|
message_history: list[ModelMessage] | None = None,
|
|
55
|
+
event_stream_handler: EventStreamHandler | None = None,
|
|
56
56
|
) -> AgentRunResult[AgentResponse]:
|
|
57
|
-
"""Create or update tasks based on the given
|
|
57
|
+
"""Create or update tasks based on the given prompt.
|
|
58
58
|
|
|
59
59
|
Args:
|
|
60
60
|
agent: The configured tasks agent
|
|
61
|
-
|
|
61
|
+
prompt: The task creation/update prompt
|
|
62
62
|
deps: Agent dependencies
|
|
63
63
|
message_history: Optional message history for conversation continuity
|
|
64
|
+
event_stream_handler: Optional callback for streaming events
|
|
64
65
|
|
|
65
66
|
Returns:
|
|
66
67
|
AgentRunResult containing the task creation process output
|
|
67
68
|
"""
|
|
68
|
-
logger.debug("📋 Starting task creation for
|
|
69
|
+
logger.debug("📋 Starting task creation for prompt: %s", prompt)
|
|
69
70
|
|
|
70
71
|
message_history = await add_system_status_message(deps, message_history)
|
|
71
72
|
|
|
72
|
-
# Let the agent use its tools to read existing tasks, plan, and research
|
|
73
|
-
full_prompt = f"Create or update tasks based on: {instruction}"
|
|
74
|
-
|
|
75
73
|
try:
|
|
76
74
|
# Create usage limits for responsible API usage
|
|
77
75
|
usage_limits = create_usage_limits()
|
|
78
76
|
|
|
79
77
|
result = await run_agent(
|
|
80
78
|
agent=agent,
|
|
81
|
-
prompt=
|
|
79
|
+
prompt=prompt,
|
|
82
80
|
deps=deps,
|
|
83
81
|
message_history=message_history,
|
|
84
82
|
usage_limits=usage_limits,
|
|
83
|
+
event_stream_handler=event_stream_handler,
|
|
85
84
|
)
|
|
86
85
|
|
|
87
86
|
logger.debug("✅ Task creation completed successfully")
|
|
@@ -23,7 +23,10 @@ logger = get_logger(__name__)
|
|
|
23
23
|
# - A list of Paths: multiple allowed files/directories (e.g., [Path("specification.md"), Path("contracts")])
|
|
24
24
|
# - "*": any file except protected files (for export agent)
|
|
25
25
|
AGENT_DIRECTORIES: dict[AgentType, str | Path | list[Path]] = {
|
|
26
|
-
AgentType.RESEARCH:
|
|
26
|
+
AgentType.RESEARCH: [
|
|
27
|
+
Path("research.md"),
|
|
28
|
+
Path("research"),
|
|
29
|
+
], # Research can write main file and research folder
|
|
27
30
|
AgentType.SPECIFY: [
|
|
28
31
|
Path("specification.md"),
|
|
29
32
|
Path("contracts"),
|
|
@@ -282,3 +285,48 @@ async def append_file(ctx: RunContext[AgentDeps], filename: str, content: str) -
|
|
|
282
285
|
Success message or error message
|
|
283
286
|
"""
|
|
284
287
|
return await write_file(ctx, filename, content, mode="a")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@register_tool(
|
|
291
|
+
category=ToolCategory.ARTIFACT_MANAGEMENT,
|
|
292
|
+
display_text="Deleting file",
|
|
293
|
+
key_arg="filename",
|
|
294
|
+
)
|
|
295
|
+
async def delete_file(ctx: RunContext[AgentDeps], filename: str) -> str:
|
|
296
|
+
"""Delete a file from the .shotgun directory.
|
|
297
|
+
|
|
298
|
+
Uses the same permission model as write_file - agents can only delete
|
|
299
|
+
files they have permission to write to.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
filename: Relative path to file within .shotgun directory
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
Success message or error message
|
|
306
|
+
|
|
307
|
+
Raises:
|
|
308
|
+
ValueError: If path is outside .shotgun directory or agent lacks permission
|
|
309
|
+
FileNotFoundError: If file does not exist
|
|
310
|
+
"""
|
|
311
|
+
logger.debug("🔧 Deleting file: %s", filename)
|
|
312
|
+
|
|
313
|
+
try:
|
|
314
|
+
# Use agent-scoped validation (same as write_file)
|
|
315
|
+
file_path = _validate_agent_scoped_path(filename, ctx.deps.agent_mode)
|
|
316
|
+
|
|
317
|
+
if not await aiofiles.os.path.exists(file_path):
|
|
318
|
+
raise FileNotFoundError(f"File not found: {filename}")
|
|
319
|
+
|
|
320
|
+
# Delete the file
|
|
321
|
+
await aiofiles.os.remove(file_path)
|
|
322
|
+
logger.debug("🗑️ Deleted file: %s", filename)
|
|
323
|
+
|
|
324
|
+
# Track the file operation
|
|
325
|
+
ctx.deps.file_tracker.add_operation(file_path, FileOperationType.DELETED)
|
|
326
|
+
|
|
327
|
+
return f"Successfully deleted {filename}"
|
|
328
|
+
|
|
329
|
+
except Exception as e:
|
|
330
|
+
error_msg = f"Error deleting file '{filename}': {str(e)}"
|
|
331
|
+
logger.error("❌ File delete failed: %s", error_msg)
|
|
332
|
+
return error_msg
|
shotgun/agents/tools/registry.py
CHANGED
|
@@ -44,9 +44,8 @@ async def get_available_web_search_tools() -> list[WebSearchTool]:
|
|
|
44
44
|
# Check if using Shotgun Account
|
|
45
45
|
config_manager = get_config_manager()
|
|
46
46
|
config = await config_manager.load()
|
|
47
|
-
has_shotgun_key = config.shotgun.api_key is not None
|
|
48
47
|
|
|
49
|
-
if
|
|
48
|
+
if config.shotgun.has_valid_account:
|
|
50
49
|
logger.debug("🔑 Shotgun Account - only Gemini web search available")
|
|
51
50
|
|
|
52
51
|
# Gemini: Only search tool available for Shotgun Account
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Gemini web search tool implementation."""
|
|
2
2
|
|
|
3
3
|
from opentelemetry import trace
|
|
4
|
-
from pydantic_ai.messages import ModelMessage, ModelRequest
|
|
4
|
+
from pydantic_ai.messages import ModelMessage, ModelRequest, TextPart
|
|
5
5
|
from pydantic_ai.settings import ModelSettings
|
|
6
6
|
|
|
7
7
|
from shotgun.agents.config import get_provider_model
|
|
@@ -82,8 +82,6 @@ async def gemini_web_search_tool(query: str) -> str:
|
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
# Extract text from response
|
|
85
|
-
from pydantic_ai.messages import TextPart
|
|
86
|
-
|
|
87
85
|
result_text = "No content returned from search"
|
|
88
86
|
if response.parts:
|
|
89
87
|
for part in response.parts:
|
|
@@ -11,7 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
13
|
import aiofiles
|
|
14
|
-
import kuzu
|
|
14
|
+
import real_ladybug as kuzu
|
|
15
15
|
from tree_sitter import Node, Parser, QueryCursor
|
|
16
16
|
|
|
17
17
|
from shotgun.codebase.core.language_config import LANGUAGE_CONFIGS, get_language_config
|
shotgun/codebase/core/manager.py
CHANGED
shotgun/prompts/agents/export.j2
CHANGED
|
@@ -10,6 +10,8 @@ Your primary job is to generate Agents.md or CLAUDE.md files following the https
|
|
|
10
10
|
|
|
11
11
|
{% include 'agents/partials/common_agent_system_prompt.j2' %}
|
|
12
12
|
|
|
13
|
+
{% include 'agents/partials/router_delegation_mode.j2' %}
|
|
14
|
+
|
|
13
15
|
## MEMORY MANAGEMENT PROTOCOL
|
|
14
16
|
|
|
15
17
|
- You can write to ANY file EXCEPT protected files
|
|
@@ -17,17 +17,12 @@ Your extensive expertise spans, among other things:
|
|
|
17
17
|
|
|
18
18
|
## AGENT FILE PERMISSIONS
|
|
19
19
|
|
|
20
|
-
There are four agents in the pipeline, and each agent can ONLY write to specific files
|
|
20
|
+
There are four agents in the pipeline, and each agent can ONLY write to specific files:
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
The **Plan agent** can only write to `plan.md`. If the user asks about research, specifications, or tasks, tell them which agent handles that file.
|
|
27
|
-
|
|
28
|
-
The **Tasks agent** can only write to `tasks.md`. If the user asks about research, specifications, or plans, tell them which agent handles that file.
|
|
29
|
-
|
|
30
|
-
When a user asks you to edit a file you cannot write to, you MUST tell them which agent can help and how to switch: "I can't edit [filename] - that's handled by the [agent name] agent. Use **Shift+Tab** to switch to that agent and it can edit that file for you."
|
|
22
|
+
- **Research agent**: `research.md` and `.shotgun/research/`
|
|
23
|
+
- **Specification agent**: `specification.md` and `.shotgun/contracts/`
|
|
24
|
+
- **Plan agent**: `plan.md`
|
|
25
|
+
- **Tasks agent**: `tasks.md`
|
|
31
26
|
|
|
32
27
|
## KEY RULES
|
|
33
28
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{% if sub_agent_context and sub_agent_context.is_router_delegated %}
|
|
2
|
+
## ROUTER DELEGATION MODE
|
|
3
|
+
|
|
4
|
+
You are being orchestrated by the Router agent.
|
|
5
|
+
|
|
6
|
+
**Current Task Context:**
|
|
7
|
+
{% if sub_agent_context.plan_goal %}
|
|
8
|
+
- Plan Goal: {{ sub_agent_context.plan_goal }}
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% if sub_agent_context.current_step_title %}
|
|
11
|
+
- Current Step: {{ sub_agent_context.current_step_title }}
|
|
12
|
+
{% endif %}
|
|
13
|
+
|
|
14
|
+
**CRITICAL BEHAVIORAL OVERRIDES** (these override ALL other instructions):
|
|
15
|
+
|
|
16
|
+
1. **DO THE WORK FIRST**: Use tools (read_file, write_file, query_graph, web_search, etc.) to COMPLETE the task BEFORE calling final_result
|
|
17
|
+
2. **NO ANNOUNCEMENTS**: Do NOT announce what you're going to do - just DO IT immediately
|
|
18
|
+
3. **NO "PLEASE WAIT" MESSAGES**: Do NOT tell the user to "be patient" or that "this will take a few minutes"
|
|
19
|
+
4. **final_result IS FOR RESULTS ONLY**: Only call final_result AFTER you have completed actual work (written files, done research, etc.)
|
|
20
|
+
5. **SKIP GREETINGS**: No greetings, pleasantries, or preamble - start working immediately
|
|
21
|
+
6. **BE CONCISE**: The Router handles user communication - just return structured results
|
|
22
|
+
|
|
23
|
+
**WRONG behavior:**
|
|
24
|
+
```
|
|
25
|
+
1. Call final_result with "I'll research this, please be patient..."
|
|
26
|
+
2. Exit without doing any work
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**CORRECT behavior:**
|
|
30
|
+
```
|
|
31
|
+
1. Call read_file to check existing research
|
|
32
|
+
2. Call query_graph or web_search to gather information
|
|
33
|
+
3. Call write_file to save research findings
|
|
34
|
+
4. Call final_result with "Research complete. Updated research.md with findings on X and Y."
|
|
35
|
+
```
|
|
36
|
+
{% endif %}
|