code-puppy 0.0.171__py3-none-any.whl → 0.0.172__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.
Files changed (65) hide show
  1. code_puppy/agent.py +3 -3
  2. code_puppy/agents/agent_creator_agent.py +0 -3
  3. code_puppy/agents/agent_qa_kitten.py +203 -0
  4. code_puppy/agents/base_agent.py +9 -0
  5. code_puppy/command_line/command_handler.py +68 -28
  6. code_puppy/command_line/mcp/add_command.py +1 -1
  7. code_puppy/command_line/mcp/base.py +1 -1
  8. code_puppy/command_line/mcp/install_command.py +1 -1
  9. code_puppy/command_line/mcp/list_command.py +1 -1
  10. code_puppy/command_line/mcp/search_command.py +1 -1
  11. code_puppy/command_line/mcp/start_all_command.py +1 -1
  12. code_puppy/command_line/mcp/status_command.py +2 -2
  13. code_puppy/command_line/mcp/stop_all_command.py +1 -1
  14. code_puppy/command_line/mcp/utils.py +1 -1
  15. code_puppy/command_line/mcp/wizard_utils.py +2 -2
  16. code_puppy/config.py +142 -12
  17. code_puppy/http_utils.py +50 -24
  18. code_puppy/{mcp → mcp_}/config_wizard.py +1 -1
  19. code_puppy/{mcp → mcp_}/examples/retry_example.py +1 -1
  20. code_puppy/{mcp → mcp_}/managed_server.py +1 -1
  21. code_puppy/{mcp → mcp_}/server_registry_catalog.py +1 -3
  22. code_puppy/message_history_processor.py +1 -61
  23. code_puppy/state_management.py +4 -2
  24. code_puppy/tools/__init__.py +103 -6
  25. code_puppy/tools/browser/__init__.py +0 -0
  26. code_puppy/tools/browser/browser_control.py +293 -0
  27. code_puppy/tools/browser/browser_interactions.py +552 -0
  28. code_puppy/tools/browser/browser_locators.py +642 -0
  29. code_puppy/tools/browser/browser_navigation.py +251 -0
  30. code_puppy/tools/browser/browser_screenshot.py +242 -0
  31. code_puppy/tools/browser/browser_scripts.py +478 -0
  32. code_puppy/tools/browser/browser_workflows.py +196 -0
  33. code_puppy/tools/browser/camoufox_manager.py +194 -0
  34. code_puppy/tools/browser/vqa_agent.py +66 -0
  35. code_puppy/tools/browser_control.py +293 -0
  36. code_puppy/tools/browser_interactions.py +552 -0
  37. code_puppy/tools/browser_locators.py +642 -0
  38. code_puppy/tools/browser_navigation.py +251 -0
  39. code_puppy/tools/browser_screenshot.py +278 -0
  40. code_puppy/tools/browser_scripts.py +478 -0
  41. code_puppy/tools/browser_workflows.py +215 -0
  42. code_puppy/tools/camoufox_manager.py +150 -0
  43. code_puppy/tools/command_runner.py +12 -7
  44. code_puppy/tools/file_operations.py +7 -7
  45. code_puppy/tui/components/custom_widgets.py +1 -1
  46. code_puppy/tui/screens/mcp_install_wizard.py +8 -8
  47. {code_puppy-0.0.171.dist-info → code_puppy-0.0.172.dist-info}/METADATA +3 -1
  48. {code_puppy-0.0.171.dist-info → code_puppy-0.0.172.dist-info}/RECORD +65 -46
  49. /code_puppy/{mcp → mcp_}/__init__.py +0 -0
  50. /code_puppy/{mcp → mcp_}/async_lifecycle.py +0 -0
  51. /code_puppy/{mcp → mcp_}/blocking_startup.py +0 -0
  52. /code_puppy/{mcp → mcp_}/captured_stdio_server.py +0 -0
  53. /code_puppy/{mcp → mcp_}/circuit_breaker.py +0 -0
  54. /code_puppy/{mcp → mcp_}/dashboard.py +0 -0
  55. /code_puppy/{mcp → mcp_}/error_isolation.py +0 -0
  56. /code_puppy/{mcp → mcp_}/health_monitor.py +0 -0
  57. /code_puppy/{mcp → mcp_}/manager.py +0 -0
  58. /code_puppy/{mcp → mcp_}/registry.py +0 -0
  59. /code_puppy/{mcp → mcp_}/retry_manager.py +0 -0
  60. /code_puppy/{mcp → mcp_}/status_tracker.py +0 -0
  61. /code_puppy/{mcp → mcp_}/system_tools.py +0 -0
  62. {code_puppy-0.0.171.data → code_puppy-0.0.172.data}/data/code_puppy/models.json +0 -0
  63. {code_puppy-0.0.171.dist-info → code_puppy-0.0.172.dist-info}/WHEEL +0 -0
  64. {code_puppy-0.0.171.dist-info → code_puppy-0.0.172.dist-info}/entry_points.txt +0 -0
  65. {code_puppy-0.0.171.dist-info → code_puppy-0.0.172.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,293 @@
1
+ """Browser initialization and control tools."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ from pydantic_ai import RunContext
6
+
7
+ from code_puppy.messaging import emit_info
8
+ from code_puppy.tools.common import generate_group_id
9
+
10
+ from .camoufox_manager import get_camoufox_manager
11
+
12
+
13
+ async def initialize_browser(
14
+ headless: bool = False,
15
+ browser_type: str = "chromium",
16
+ homepage: str = "https://www.google.com",
17
+ ) -> Dict[str, Any]:
18
+ """Initialize the browser with specified settings."""
19
+ group_id = generate_group_id("browser_initialize", f"{browser_type}_{homepage}")
20
+ emit_info(
21
+ f"[bold white on blue] BROWSER INITIALIZE [/bold white on blue] 🌐 {browser_type} → {homepage}",
22
+ message_group=group_id,
23
+ )
24
+ try:
25
+ browser_manager = get_camoufox_manager()
26
+
27
+ # Configure browser settings
28
+ browser_manager.headless = headless
29
+ browser_manager.browser_type = browser_type
30
+ browser_manager.homepage = homepage
31
+
32
+ # Initialize browser
33
+ await browser_manager.async_initialize()
34
+
35
+ # Get page info
36
+ page = await browser_manager.get_current_page()
37
+ if page:
38
+ url = page.url
39
+ title = await page.title()
40
+ else:
41
+ url = "Unknown"
42
+ title = "Unknown"
43
+
44
+ emit_info(
45
+ "[green]Browser initialized successfully[/green]", message_group=group_id
46
+ )
47
+
48
+ return {
49
+ "success": True,
50
+ "browser_type": browser_type,
51
+ "headless": headless,
52
+ "homepage": homepage,
53
+ "current_url": url,
54
+ "current_title": title,
55
+ }
56
+
57
+ except Exception as e:
58
+ emit_info(
59
+ f"[red]Browser initialization failed: {str(e)}[/red]",
60
+ message_group=group_id,
61
+ )
62
+ return {
63
+ "success": False,
64
+ "error": str(e),
65
+ "browser_type": browser_type,
66
+ "headless": headless,
67
+ }
68
+
69
+
70
+ async def close_browser() -> Dict[str, Any]:
71
+ """Close the browser and clean up resources."""
72
+ group_id = generate_group_id("browser_close")
73
+ emit_info(
74
+ "[bold white on blue] BROWSER CLOSE [/bold white on blue] 🔒",
75
+ message_group=group_id,
76
+ )
77
+ try:
78
+ browser_manager = get_camoufox_manager()
79
+ await browser_manager.close()
80
+
81
+ emit_info(
82
+ "[yellow]Browser closed successfully[/yellow]", message_group=group_id
83
+ )
84
+
85
+ return {"success": True, "message": "Browser closed"}
86
+
87
+ except Exception as e:
88
+ return {"success": False, "error": str(e)}
89
+
90
+
91
+ async def get_browser_status() -> Dict[str, Any]:
92
+ """Get current browser status and information."""
93
+ group_id = generate_group_id("browser_status")
94
+ emit_info(
95
+ "[bold white on blue] BROWSER STATUS [/bold white on blue] 📊",
96
+ message_group=group_id,
97
+ )
98
+ try:
99
+ browser_manager = get_camoufox_manager()
100
+
101
+ if not browser_manager._initialized:
102
+ return {
103
+ "success": True,
104
+ "status": "not_initialized",
105
+ "browser_type": browser_manager.browser_type,
106
+ "headless": browser_manager.headless,
107
+ }
108
+
109
+ page = await browser_manager.get_current_page()
110
+ if page:
111
+ url = page.url
112
+ title = await page.title()
113
+
114
+ # Get all pages
115
+ all_pages = await browser_manager.get_all_pages()
116
+ page_count = len(all_pages)
117
+ else:
118
+ url = None
119
+ title = None
120
+ page_count = 0
121
+
122
+ return {
123
+ "success": True,
124
+ "status": "initialized",
125
+ "browser_type": browser_manager.browser_type,
126
+ "headless": browser_manager.headless,
127
+ "current_url": url,
128
+ "current_title": title,
129
+ "page_count": page_count,
130
+ }
131
+
132
+ except Exception as e:
133
+ return {"success": False, "error": str(e)}
134
+
135
+
136
+ async def create_new_page(url: Optional[str] = None) -> Dict[str, Any]:
137
+ """Create a new browser page/tab."""
138
+ group_id = generate_group_id("browser_new_page", url or "blank")
139
+ emit_info(
140
+ f"[bold white on blue] BROWSER NEW PAGE [/bold white on blue] 📄 {url or 'blank page'}",
141
+ message_group=group_id,
142
+ )
143
+ try:
144
+ browser_manager = get_camoufox_manager()
145
+
146
+ if not browser_manager._initialized:
147
+ return {
148
+ "success": False,
149
+ "error": "Browser not initialized. Use browser_initialize first.",
150
+ }
151
+
152
+ page = await browser_manager.new_page(url)
153
+
154
+ final_url = page.url
155
+ title = await page.title()
156
+
157
+ emit_info(
158
+ f"[green]Created new page: {final_url}[/green]", message_group=group_id
159
+ )
160
+
161
+ return {"success": True, "url": final_url, "title": title, "requested_url": url}
162
+
163
+ except Exception as e:
164
+ return {"success": False, "error": str(e), "url": url}
165
+
166
+
167
+ async def list_pages() -> Dict[str, Any]:
168
+ """List all open browser pages/tabs."""
169
+ group_id = generate_group_id("browser_list_pages")
170
+ emit_info(
171
+ "[bold white on blue] BROWSER LIST PAGES [/bold white on blue] 📋",
172
+ message_group=group_id,
173
+ )
174
+ try:
175
+ browser_manager = get_camoufox_manager()
176
+
177
+ if not browser_manager._initialized:
178
+ return {"success": False, "error": "Browser not initialized"}
179
+
180
+ all_pages = await browser_manager.get_all_pages()
181
+
182
+ pages_info = []
183
+ for i, page in enumerate(all_pages):
184
+ try:
185
+ url = page.url
186
+ title = await page.title()
187
+ is_closed = page.is_closed()
188
+
189
+ pages_info.append(
190
+ {"index": i, "url": url, "title": title, "closed": is_closed}
191
+ )
192
+ except Exception as e:
193
+ pages_info.append(
194
+ {
195
+ "index": i,
196
+ "url": "Error",
197
+ "title": "Error",
198
+ "error": str(e),
199
+ "closed": True,
200
+ }
201
+ )
202
+
203
+ return {"success": True, "page_count": len(all_pages), "pages": pages_info}
204
+
205
+ except Exception as e:
206
+ return {"success": False, "error": str(e)}
207
+
208
+
209
+ # Tool registration functions
210
+ def register_initialize_browser(agent):
211
+ """Register the browser initialization tool."""
212
+
213
+ @agent.tool
214
+ async def browser_initialize(
215
+ context: RunContext,
216
+ headless: bool = False,
217
+ browser_type: str = "chromium",
218
+ homepage: str = "https://www.google.com",
219
+ ) -> Dict[str, Any]:
220
+ """
221
+ Initialize the browser with specified settings. Must be called before using other browser tools.
222
+
223
+ Args:
224
+ headless: Run browser in headless mode (no GUI)
225
+ browser_type: Browser engine (chromium, firefox, webkit)
226
+ homepage: Initial page to load
227
+
228
+ Returns:
229
+ Dict with initialization results
230
+ """
231
+ return await initialize_browser(headless, browser_type, homepage)
232
+
233
+
234
+ def register_close_browser(agent):
235
+ """Register the browser close tool."""
236
+
237
+ @agent.tool
238
+ async def browser_close(context: RunContext) -> Dict[str, Any]:
239
+ """
240
+ Close the browser and clean up all resources.
241
+
242
+ Returns:
243
+ Dict with close results
244
+ """
245
+ return await close_browser()
246
+
247
+
248
+ def register_get_browser_status(agent):
249
+ """Register the browser status tool."""
250
+
251
+ @agent.tool
252
+ async def browser_status(context: RunContext) -> Dict[str, Any]:
253
+ """
254
+ Get current browser status and information.
255
+
256
+ Returns:
257
+ Dict with browser status and metadata
258
+ """
259
+ return await get_browser_status()
260
+
261
+
262
+ def register_create_new_page(agent):
263
+ """Register the new page creation tool."""
264
+
265
+ @agent.tool
266
+ async def browser_new_page(
267
+ context: RunContext,
268
+ url: Optional[str] = None,
269
+ ) -> Dict[str, Any]:
270
+ """
271
+ Create a new browser page/tab.
272
+
273
+ Args:
274
+ url: Optional URL to navigate to in the new page
275
+
276
+ Returns:
277
+ Dict with new page results
278
+ """
279
+ return await create_new_page(url)
280
+
281
+
282
+ def register_list_pages(agent):
283
+ """Register the list pages tool."""
284
+
285
+ @agent.tool
286
+ async def browser_list_pages(context: RunContext) -> Dict[str, Any]:
287
+ """
288
+ List all open browser pages/tabs.
289
+
290
+ Returns:
291
+ Dict with information about all open pages
292
+ """
293
+ return await list_pages()