code-puppy 0.0.169__py3-none-any.whl → 0.0.366__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.
- code_puppy/__init__.py +7 -1
- code_puppy/agents/__init__.py +8 -8
- code_puppy/agents/agent_c_reviewer.py +155 -0
- code_puppy/agents/agent_code_puppy.py +9 -2
- code_puppy/agents/agent_code_reviewer.py +90 -0
- code_puppy/agents/agent_cpp_reviewer.py +132 -0
- code_puppy/agents/agent_creator_agent.py +48 -9
- code_puppy/agents/agent_golang_reviewer.py +151 -0
- code_puppy/agents/agent_javascript_reviewer.py +160 -0
- code_puppy/agents/agent_manager.py +146 -199
- code_puppy/agents/agent_pack_leader.py +383 -0
- code_puppy/agents/agent_planning.py +163 -0
- code_puppy/agents/agent_python_programmer.py +165 -0
- code_puppy/agents/agent_python_reviewer.py +90 -0
- code_puppy/agents/agent_qa_expert.py +163 -0
- code_puppy/agents/agent_qa_kitten.py +208 -0
- code_puppy/agents/agent_security_auditor.py +181 -0
- code_puppy/agents/agent_terminal_qa.py +323 -0
- code_puppy/agents/agent_typescript_reviewer.py +166 -0
- code_puppy/agents/base_agent.py +1713 -1
- code_puppy/agents/event_stream_handler.py +350 -0
- code_puppy/agents/json_agent.py +12 -1
- code_puppy/agents/pack/__init__.py +34 -0
- code_puppy/agents/pack/bloodhound.py +304 -0
- code_puppy/agents/pack/husky.py +321 -0
- code_puppy/agents/pack/retriever.py +393 -0
- code_puppy/agents/pack/shepherd.py +348 -0
- code_puppy/agents/pack/terrier.py +287 -0
- code_puppy/agents/pack/watchdog.py +367 -0
- code_puppy/agents/prompt_reviewer.py +145 -0
- code_puppy/agents/subagent_stream_handler.py +276 -0
- code_puppy/api/__init__.py +13 -0
- code_puppy/api/app.py +169 -0
- code_puppy/api/main.py +21 -0
- code_puppy/api/pty_manager.py +446 -0
- code_puppy/api/routers/__init__.py +12 -0
- code_puppy/api/routers/agents.py +36 -0
- code_puppy/api/routers/commands.py +217 -0
- code_puppy/api/routers/config.py +74 -0
- code_puppy/api/routers/sessions.py +232 -0
- code_puppy/api/templates/terminal.html +361 -0
- code_puppy/api/websocket.py +154 -0
- code_puppy/callbacks.py +174 -4
- code_puppy/chatgpt_codex_client.py +283 -0
- code_puppy/claude_cache_client.py +586 -0
- code_puppy/cli_runner.py +916 -0
- code_puppy/command_line/add_model_menu.py +1079 -0
- code_puppy/command_line/agent_menu.py +395 -0
- code_puppy/command_line/attachments.py +395 -0
- code_puppy/command_line/autosave_menu.py +605 -0
- code_puppy/command_line/clipboard.py +527 -0
- code_puppy/command_line/colors_menu.py +520 -0
- code_puppy/command_line/command_handler.py +233 -627
- code_puppy/command_line/command_registry.py +150 -0
- code_puppy/command_line/config_commands.py +715 -0
- code_puppy/command_line/core_commands.py +792 -0
- code_puppy/command_line/diff_menu.py +863 -0
- code_puppy/command_line/load_context_completion.py +15 -22
- code_puppy/command_line/mcp/base.py +1 -4
- code_puppy/command_line/mcp/catalog_server_installer.py +175 -0
- code_puppy/command_line/mcp/custom_server_form.py +688 -0
- code_puppy/command_line/mcp/custom_server_installer.py +195 -0
- code_puppy/command_line/mcp/edit_command.py +148 -0
- code_puppy/command_line/mcp/handler.py +9 -4
- code_puppy/command_line/mcp/help_command.py +6 -5
- code_puppy/command_line/mcp/install_command.py +16 -27
- code_puppy/command_line/mcp/install_menu.py +685 -0
- code_puppy/command_line/mcp/list_command.py +3 -3
- code_puppy/command_line/mcp/logs_command.py +174 -65
- code_puppy/command_line/mcp/remove_command.py +2 -2
- code_puppy/command_line/mcp/restart_command.py +12 -4
- code_puppy/command_line/mcp/search_command.py +17 -11
- code_puppy/command_line/mcp/start_all_command.py +22 -13
- code_puppy/command_line/mcp/start_command.py +50 -31
- code_puppy/command_line/mcp/status_command.py +6 -7
- code_puppy/command_line/mcp/stop_all_command.py +11 -8
- code_puppy/command_line/mcp/stop_command.py +11 -10
- code_puppy/command_line/mcp/test_command.py +2 -2
- code_puppy/command_line/mcp/utils.py +1 -1
- code_puppy/command_line/mcp/wizard_utils.py +22 -18
- code_puppy/command_line/mcp_completion.py +174 -0
- code_puppy/command_line/model_picker_completion.py +89 -30
- code_puppy/command_line/model_settings_menu.py +884 -0
- code_puppy/command_line/motd.py +14 -8
- code_puppy/command_line/onboarding_slides.py +179 -0
- code_puppy/command_line/onboarding_wizard.py +340 -0
- code_puppy/command_line/pin_command_completion.py +329 -0
- code_puppy/command_line/prompt_toolkit_completion.py +626 -75
- code_puppy/command_line/session_commands.py +296 -0
- code_puppy/command_line/utils.py +54 -0
- code_puppy/config.py +1181 -51
- code_puppy/error_logging.py +118 -0
- code_puppy/gemini_code_assist.py +385 -0
- code_puppy/gemini_model.py +602 -0
- code_puppy/http_utils.py +220 -104
- code_puppy/keymap.py +128 -0
- code_puppy/main.py +5 -594
- code_puppy/{mcp → mcp_}/__init__.py +17 -0
- code_puppy/{mcp → mcp_}/async_lifecycle.py +35 -4
- code_puppy/{mcp → mcp_}/blocking_startup.py +70 -43
- code_puppy/{mcp → mcp_}/captured_stdio_server.py +2 -2
- code_puppy/{mcp → mcp_}/config_wizard.py +5 -5
- code_puppy/{mcp → mcp_}/dashboard.py +15 -6
- code_puppy/{mcp → mcp_}/examples/retry_example.py +4 -1
- code_puppy/{mcp → mcp_}/managed_server.py +66 -39
- code_puppy/{mcp → mcp_}/manager.py +146 -52
- code_puppy/mcp_/mcp_logs.py +224 -0
- code_puppy/{mcp → mcp_}/registry.py +6 -6
- code_puppy/{mcp → mcp_}/server_registry_catalog.py +25 -8
- code_puppy/messaging/__init__.py +199 -2
- code_puppy/messaging/bus.py +610 -0
- code_puppy/messaging/commands.py +167 -0
- code_puppy/messaging/markdown_patches.py +57 -0
- code_puppy/messaging/message_queue.py +17 -48
- code_puppy/messaging/messages.py +500 -0
- code_puppy/messaging/queue_console.py +1 -24
- code_puppy/messaging/renderers.py +43 -146
- code_puppy/messaging/rich_renderer.py +1027 -0
- code_puppy/messaging/spinner/__init__.py +33 -5
- code_puppy/messaging/spinner/console_spinner.py +92 -52
- code_puppy/messaging/spinner/spinner_base.py +29 -0
- code_puppy/messaging/subagent_console.py +461 -0
- code_puppy/model_factory.py +686 -80
- code_puppy/model_utils.py +167 -0
- code_puppy/models.json +86 -104
- code_puppy/models_dev_api.json +1 -0
- code_puppy/models_dev_parser.py +592 -0
- code_puppy/plugins/__init__.py +164 -10
- code_puppy/plugins/antigravity_oauth/__init__.py +10 -0
- code_puppy/plugins/antigravity_oauth/accounts.py +406 -0
- code_puppy/plugins/antigravity_oauth/antigravity_model.py +704 -0
- code_puppy/plugins/antigravity_oauth/config.py +42 -0
- code_puppy/plugins/antigravity_oauth/constants.py +136 -0
- code_puppy/plugins/antigravity_oauth/oauth.py +478 -0
- code_puppy/plugins/antigravity_oauth/register_callbacks.py +406 -0
- code_puppy/plugins/antigravity_oauth/storage.py +271 -0
- code_puppy/plugins/antigravity_oauth/test_plugin.py +319 -0
- code_puppy/plugins/antigravity_oauth/token.py +167 -0
- code_puppy/plugins/antigravity_oauth/transport.py +767 -0
- code_puppy/plugins/antigravity_oauth/utils.py +169 -0
- code_puppy/plugins/chatgpt_oauth/__init__.py +8 -0
- code_puppy/plugins/chatgpt_oauth/config.py +52 -0
- code_puppy/plugins/chatgpt_oauth/oauth_flow.py +328 -0
- code_puppy/plugins/chatgpt_oauth/register_callbacks.py +94 -0
- code_puppy/plugins/chatgpt_oauth/test_plugin.py +293 -0
- code_puppy/plugins/chatgpt_oauth/utils.py +489 -0
- code_puppy/plugins/claude_code_oauth/README.md +167 -0
- code_puppy/plugins/claude_code_oauth/SETUP.md +93 -0
- code_puppy/plugins/claude_code_oauth/__init__.py +6 -0
- code_puppy/plugins/claude_code_oauth/config.py +50 -0
- code_puppy/plugins/claude_code_oauth/register_callbacks.py +308 -0
- code_puppy/plugins/claude_code_oauth/test_plugin.py +283 -0
- code_puppy/plugins/claude_code_oauth/utils.py +518 -0
- code_puppy/plugins/customizable_commands/__init__.py +0 -0
- code_puppy/plugins/customizable_commands/register_callbacks.py +169 -0
- code_puppy/plugins/example_custom_command/README.md +280 -0
- code_puppy/plugins/example_custom_command/register_callbacks.py +51 -0
- code_puppy/plugins/file_permission_handler/__init__.py +4 -0
- code_puppy/plugins/file_permission_handler/register_callbacks.py +523 -0
- code_puppy/plugins/frontend_emitter/__init__.py +25 -0
- code_puppy/plugins/frontend_emitter/emitter.py +121 -0
- code_puppy/plugins/frontend_emitter/register_callbacks.py +261 -0
- code_puppy/plugins/oauth_puppy_html.py +228 -0
- code_puppy/plugins/shell_safety/__init__.py +6 -0
- code_puppy/plugins/shell_safety/agent_shell_safety.py +69 -0
- code_puppy/plugins/shell_safety/command_cache.py +156 -0
- code_puppy/plugins/shell_safety/register_callbacks.py +202 -0
- code_puppy/prompts/antigravity_system_prompt.md +1 -0
- code_puppy/prompts/codex_system_prompt.md +310 -0
- code_puppy/pydantic_patches.py +131 -0
- code_puppy/reopenable_async_client.py +8 -8
- code_puppy/round_robin_model.py +10 -15
- code_puppy/session_storage.py +294 -0
- code_puppy/status_display.py +21 -4
- code_puppy/summarization_agent.py +52 -14
- code_puppy/terminal_utils.py +418 -0
- code_puppy/tools/__init__.py +139 -6
- code_puppy/tools/agent_tools.py +548 -49
- code_puppy/tools/browser/__init__.py +37 -0
- code_puppy/tools/browser/browser_control.py +289 -0
- code_puppy/tools/browser/browser_interactions.py +545 -0
- code_puppy/tools/browser/browser_locators.py +640 -0
- code_puppy/tools/browser/browser_manager.py +316 -0
- code_puppy/tools/browser/browser_navigation.py +251 -0
- code_puppy/tools/browser/browser_screenshot.py +179 -0
- code_puppy/tools/browser/browser_scripts.py +462 -0
- code_puppy/tools/browser/browser_workflows.py +221 -0
- code_puppy/tools/browser/chromium_terminal_manager.py +259 -0
- code_puppy/tools/browser/terminal_command_tools.py +521 -0
- code_puppy/tools/browser/terminal_screenshot_tools.py +556 -0
- code_puppy/tools/browser/terminal_tools.py +525 -0
- code_puppy/tools/command_runner.py +941 -153
- code_puppy/tools/common.py +1146 -6
- code_puppy/tools/display.py +84 -0
- code_puppy/tools/file_modifications.py +288 -89
- code_puppy/tools/file_operations.py +352 -266
- code_puppy/tools/subagent_context.py +158 -0
- code_puppy/uvx_detection.py +242 -0
- code_puppy/version_checker.py +30 -11
- code_puppy-0.0.366.data/data/code_puppy/models.json +110 -0
- code_puppy-0.0.366.data/data/code_puppy/models_dev_api.json +1 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/METADATA +184 -67
- code_puppy-0.0.366.dist-info/RECORD +217 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/WHEEL +1 -1
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/entry_points.txt +1 -0
- code_puppy/agent.py +0 -231
- code_puppy/agents/agent_orchestrator.json +0 -26
- code_puppy/agents/runtime_manager.py +0 -272
- code_puppy/command_line/mcp/add_command.py +0 -183
- code_puppy/command_line/meta_command_handler.py +0 -153
- code_puppy/message_history_processor.py +0 -490
- code_puppy/messaging/spinner/textual_spinner.py +0 -101
- code_puppy/state_management.py +0 -200
- code_puppy/tui/__init__.py +0 -10
- code_puppy/tui/app.py +0 -986
- code_puppy/tui/components/__init__.py +0 -21
- code_puppy/tui/components/chat_view.py +0 -550
- code_puppy/tui/components/command_history_modal.py +0 -218
- code_puppy/tui/components/copy_button.py +0 -139
- code_puppy/tui/components/custom_widgets.py +0 -63
- code_puppy/tui/components/human_input_modal.py +0 -175
- code_puppy/tui/components/input_area.py +0 -167
- code_puppy/tui/components/sidebar.py +0 -309
- code_puppy/tui/components/status_bar.py +0 -182
- code_puppy/tui/messages.py +0 -27
- code_puppy/tui/models/__init__.py +0 -8
- code_puppy/tui/models/chat_message.py +0 -25
- code_puppy/tui/models/command_history.py +0 -89
- code_puppy/tui/models/enums.py +0 -24
- code_puppy/tui/screens/__init__.py +0 -15
- code_puppy/tui/screens/help.py +0 -130
- code_puppy/tui/screens/mcp_install_wizard.py +0 -803
- code_puppy/tui/screens/settings.py +0 -290
- code_puppy/tui/screens/tools.py +0 -74
- code_puppy-0.0.169.data/data/code_puppy/models.json +0 -128
- code_puppy-0.0.169.dist-info/RECORD +0 -112
- /code_puppy/{mcp → mcp_}/circuit_breaker.py +0 -0
- /code_puppy/{mcp → mcp_}/error_isolation.py +0 -0
- /code_puppy/{mcp → mcp_}/health_monitor.py +0 -0
- /code_puppy/{mcp → mcp_}/retry_manager.py +0 -0
- /code_puppy/{mcp → mcp_}/status_tracker.py +0 -0
- /code_puppy/{mcp → mcp_}/system_tools.py +0 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Caching layer for shell command safety assessments.
|
|
2
|
+
|
|
3
|
+
This module provides an LRU cache for recently assessed commands to avoid redundant API calls.
|
|
4
|
+
|
|
5
|
+
The approach is simple and secure: let the LLM assess ALL commands and cache
|
|
6
|
+
those assessments. This eliminates the security risks of pre-defined whitelists
|
|
7
|
+
while providing the performance benefits of caching.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from collections import OrderedDict
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Optional, Tuple
|
|
13
|
+
|
|
14
|
+
# Maximum number of cached assessments (LRU eviction after this)
|
|
15
|
+
MAX_CACHE_SIZE = 200
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class CachedAssessment:
|
|
20
|
+
"""A cached safety assessment result."""
|
|
21
|
+
|
|
22
|
+
risk: str
|
|
23
|
+
reasoning: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CommandSafetyCache:
|
|
27
|
+
"""LRU cache for shell command safety assessments.
|
|
28
|
+
|
|
29
|
+
This cache stores previous LLM assessments to avoid redundant API calls.
|
|
30
|
+
It uses an OrderedDict for O(1) LRU eviction.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, max_size: int = MAX_CACHE_SIZE):
|
|
34
|
+
self._cache: OrderedDict[Tuple[str, Optional[str]], CachedAssessment] = (
|
|
35
|
+
OrderedDict()
|
|
36
|
+
)
|
|
37
|
+
self._max_size = max_size
|
|
38
|
+
self._hits = 0
|
|
39
|
+
self._misses = 0
|
|
40
|
+
|
|
41
|
+
def _make_key(self, command: str, cwd: Optional[str]) -> Tuple[str, Optional[str]]:
|
|
42
|
+
"""Create a cache key from command and cwd."""
|
|
43
|
+
# Normalize command (strip whitespace)
|
|
44
|
+
return (command.strip(), cwd)
|
|
45
|
+
|
|
46
|
+
def get(
|
|
47
|
+
self, command: str, cwd: Optional[str] = None
|
|
48
|
+
) -> Optional[CachedAssessment]:
|
|
49
|
+
"""Get a cached assessment if it exists.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
command: The shell command
|
|
53
|
+
cwd: Optional working directory
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
CachedAssessment if found, None otherwise
|
|
57
|
+
"""
|
|
58
|
+
key = self._make_key(command, cwd)
|
|
59
|
+
if key in self._cache:
|
|
60
|
+
# Move to end (most recently used)
|
|
61
|
+
self._cache.move_to_end(key)
|
|
62
|
+
self._hits += 1
|
|
63
|
+
return self._cache[key]
|
|
64
|
+
self._misses += 1
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
def put(
|
|
68
|
+
self, command: str, cwd: Optional[str], assessment: CachedAssessment
|
|
69
|
+
) -> None:
|
|
70
|
+
"""Store an assessment in the cache.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
command: The shell command
|
|
74
|
+
cwd: Optional working directory
|
|
75
|
+
assessment: The assessment result to cache
|
|
76
|
+
"""
|
|
77
|
+
key = self._make_key(command, cwd)
|
|
78
|
+
|
|
79
|
+
# If already exists, update and move to end
|
|
80
|
+
if key in self._cache:
|
|
81
|
+
self._cache.move_to_end(key)
|
|
82
|
+
self._cache[key] = assessment
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
# Evict oldest if at capacity
|
|
86
|
+
while len(self._cache) >= self._max_size:
|
|
87
|
+
self._cache.popitem(last=False)
|
|
88
|
+
|
|
89
|
+
self._cache[key] = assessment
|
|
90
|
+
|
|
91
|
+
def clear(self) -> None:
|
|
92
|
+
"""Clear all cached assessments."""
|
|
93
|
+
self._cache.clear()
|
|
94
|
+
self._hits = 0
|
|
95
|
+
self._misses = 0
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def stats(self) -> dict:
|
|
99
|
+
"""Get cache statistics."""
|
|
100
|
+
total = self._hits + self._misses
|
|
101
|
+
hit_rate = (self._hits / total * 100) if total > 0 else 0
|
|
102
|
+
return {
|
|
103
|
+
"size": len(self._cache),
|
|
104
|
+
"max_size": self._max_size,
|
|
105
|
+
"hits": self._hits,
|
|
106
|
+
"misses": self._misses,
|
|
107
|
+
"hit_rate": f"{hit_rate:.1f}%",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# Global cache instance (singleton for the session)
|
|
112
|
+
_cache = CommandSafetyCache()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def get_cache_stats() -> dict:
|
|
116
|
+
"""Get statistics about the cache performance."""
|
|
117
|
+
return _cache.stats
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def get_cached_assessment(
|
|
121
|
+
command: str, cwd: Optional[str] = None
|
|
122
|
+
) -> Optional[CachedAssessment]:
|
|
123
|
+
"""Get a cached command safety assessment.
|
|
124
|
+
|
|
125
|
+
Cache-only approach: use the LLM cache for speed, but let the LLM
|
|
126
|
+
determine safety for all commands. No pre-defined whitelists.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
command: The shell command to check
|
|
130
|
+
cwd: Optional working directory
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
CachedAssessment if found in cache, None if needs LLM assessment
|
|
134
|
+
"""
|
|
135
|
+
return _cache.get(command, cwd)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def cache_assessment(
|
|
139
|
+
command: str, cwd: Optional[str], risk: str, reasoning: str
|
|
140
|
+
) -> None:
|
|
141
|
+
"""Cache an LLM assessment result.
|
|
142
|
+
|
|
143
|
+
Cache all LLM assessments since the same command should get
|
|
144
|
+
the same assessment, providing both security and performance.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
command: The shell command
|
|
148
|
+
cwd: Optional working directory
|
|
149
|
+
risk: The assessed risk level
|
|
150
|
+
reasoning: The assessment reasoning
|
|
151
|
+
"""
|
|
152
|
+
assessment = CachedAssessment(
|
|
153
|
+
risk=risk,
|
|
154
|
+
reasoning=reasoning,
|
|
155
|
+
)
|
|
156
|
+
_cache.put(command, cwd, assessment)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Callback registration for shell command safety checking.
|
|
2
|
+
|
|
3
|
+
This module registers a callback that intercepts shell commands in yolo_mode
|
|
4
|
+
and assesses their safety risk before execution.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
|
|
9
|
+
from code_puppy.callbacks import register_callback
|
|
10
|
+
from code_puppy.config import (
|
|
11
|
+
get_global_model_name,
|
|
12
|
+
get_safety_permission_level,
|
|
13
|
+
get_yolo_mode,
|
|
14
|
+
)
|
|
15
|
+
from code_puppy.messaging import emit_info
|
|
16
|
+
from code_puppy.plugins.shell_safety.command_cache import (
|
|
17
|
+
cache_assessment,
|
|
18
|
+
get_cached_assessment,
|
|
19
|
+
)
|
|
20
|
+
from code_puppy.tools.command_runner import ShellSafetyAssessment
|
|
21
|
+
|
|
22
|
+
# OAuth model prefixes - these models have their own safety mechanisms
|
|
23
|
+
OAUTH_MODEL_PREFIXES = (
|
|
24
|
+
"claude-code-", # Anthropic OAuth
|
|
25
|
+
"chatgpt-", # OpenAI OAuth
|
|
26
|
+
"gemini-oauth", # Google OAuth
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_oauth_model(model_name: str | None) -> bool:
|
|
31
|
+
"""Check if the model is an OAuth model that should skip safety checks.
|
|
32
|
+
|
|
33
|
+
OAuth models have their own built-in safety mechanisms, so we skip
|
|
34
|
+
the shell safety callback to avoid redundant checks and potential bugs.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
model_name: The name of the current model
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
True if the model is an OAuth model, False otherwise
|
|
41
|
+
"""
|
|
42
|
+
if not model_name:
|
|
43
|
+
return False
|
|
44
|
+
return model_name.startswith(OAUTH_MODEL_PREFIXES)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Risk level hierarchy for numeric comparison
|
|
48
|
+
# Lower numbers = safer commands, higher numbers = more dangerous
|
|
49
|
+
# This mapping allows us to compare risk levels as integers
|
|
50
|
+
RISK_LEVELS: Dict[str, int] = {
|
|
51
|
+
"none": 0,
|
|
52
|
+
"low": 1,
|
|
53
|
+
"medium": 2,
|
|
54
|
+
"high": 3,
|
|
55
|
+
"critical": 4,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def compare_risk_levels(assessed_risk: Optional[str], threshold: str) -> bool:
|
|
60
|
+
"""Compare assessed risk against threshold.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
assessed_risk: The risk level from the agent (can be None)
|
|
64
|
+
threshold: The configured risk threshold
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
True if the command should be blocked (risk exceeds threshold)
|
|
68
|
+
False if the command is acceptable
|
|
69
|
+
"""
|
|
70
|
+
# If assessment failed (None), treat as high risk (fail-safe behavior)
|
|
71
|
+
if assessed_risk is None:
|
|
72
|
+
assessed_risk = "high"
|
|
73
|
+
|
|
74
|
+
# Convert risk levels to numeric values for comparison
|
|
75
|
+
assessed_level = RISK_LEVELS.get(assessed_risk, 4) # Default to critical if unknown
|
|
76
|
+
threshold_level = RISK_LEVELS.get(threshold, 2) # Default to medium if unknown
|
|
77
|
+
|
|
78
|
+
# Block if assessed risk is GREATER than threshold
|
|
79
|
+
# Note: Commands AT the threshold level are allowed (>, not >=)
|
|
80
|
+
return assessed_level > threshold_level
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def shell_safety_callback(
|
|
84
|
+
context: Any, command: str, cwd: Optional[str] = None, timeout: int = 60
|
|
85
|
+
) -> Optional[Dict[str, Any]]:
|
|
86
|
+
"""Callback to assess shell command safety before execution.
|
|
87
|
+
|
|
88
|
+
This callback is only active when yolo_mode is True. When yolo_mode is False,
|
|
89
|
+
the user manually reviews every command, so we don't need the agent.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
context: The execution context
|
|
93
|
+
command: The shell command to execute
|
|
94
|
+
cwd: Optional working directory
|
|
95
|
+
timeout: Command timeout (unused here)
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
None if command is safe to proceed
|
|
99
|
+
Dict with rejection info if command should be blocked
|
|
100
|
+
"""
|
|
101
|
+
# Skip safety checks for OAuth models - they have their own safety mechanisms
|
|
102
|
+
current_model = get_global_model_name()
|
|
103
|
+
if is_oauth_model(current_model):
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
# Only check safety in yolo_mode - otherwise user is reviewing manually
|
|
107
|
+
yolo_mode = get_yolo_mode()
|
|
108
|
+
if not yolo_mode:
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
# Get configured risk threshold
|
|
112
|
+
threshold = get_safety_permission_level()
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
# Check cache first (fast path - no LLM call)
|
|
116
|
+
cached = get_cached_assessment(command, cwd)
|
|
117
|
+
|
|
118
|
+
if cached:
|
|
119
|
+
# Got a cached result - check against threshold
|
|
120
|
+
if compare_risk_levels(cached.risk, threshold):
|
|
121
|
+
# Cached result says it's too risky
|
|
122
|
+
risk_display = cached.risk or "unknown"
|
|
123
|
+
concise_reason = cached.reasoning or "No reasoning provided"
|
|
124
|
+
error_msg = (
|
|
125
|
+
f"🛑 Command blocked (risk {risk_display.upper()} > permission {threshold.upper()}).\n"
|
|
126
|
+
f"Reason: {concise_reason}\n"
|
|
127
|
+
f"Override: /set yolo_mode true or /set safety_permission_level {risk_display}"
|
|
128
|
+
)
|
|
129
|
+
emit_info(error_msg)
|
|
130
|
+
return {
|
|
131
|
+
"blocked": True,
|
|
132
|
+
"risk": cached.risk,
|
|
133
|
+
"reasoning": cached.reasoning,
|
|
134
|
+
"error_message": error_msg,
|
|
135
|
+
}
|
|
136
|
+
# Cached result is within threshold - allow silently
|
|
137
|
+
return None
|
|
138
|
+
|
|
139
|
+
# Cache miss - need LLM assessment
|
|
140
|
+
# Import here to avoid circular imports
|
|
141
|
+
from code_puppy.plugins.shell_safety.agent_shell_safety import ShellSafetyAgent
|
|
142
|
+
|
|
143
|
+
# Create agent and assess command
|
|
144
|
+
agent = ShellSafetyAgent()
|
|
145
|
+
|
|
146
|
+
# Build the assessment prompt with optional cwd context
|
|
147
|
+
prompt = f"Assess this shell command:\n\nCommand: {command}"
|
|
148
|
+
if cwd:
|
|
149
|
+
prompt += f"\nWorking directory: {cwd}"
|
|
150
|
+
|
|
151
|
+
# Run async assessment with structured output type
|
|
152
|
+
result = await agent.run_with_mcp(prompt, output_type=ShellSafetyAssessment)
|
|
153
|
+
assessment = result.output
|
|
154
|
+
|
|
155
|
+
# Cache the result for future use, but only if it's not a fallback assessment
|
|
156
|
+
if not getattr(assessment, "is_fallback", False):
|
|
157
|
+
cache_assessment(command, cwd, assessment.risk, assessment.reasoning)
|
|
158
|
+
|
|
159
|
+
# Check if risk exceeds threshold (commands at threshold are allowed)
|
|
160
|
+
if compare_risk_levels(assessment.risk, threshold):
|
|
161
|
+
risk_display = assessment.risk or "unknown"
|
|
162
|
+
concise_reason = assessment.reasoning or "No reasoning provided"
|
|
163
|
+
error_msg = (
|
|
164
|
+
f"🛑 Command blocked (risk {risk_display.upper()} > permission {threshold.upper()}).\n"
|
|
165
|
+
f"Reason: {concise_reason}\n"
|
|
166
|
+
f"Override: /set yolo_mode true or /set safety_permission_level {risk_display}"
|
|
167
|
+
)
|
|
168
|
+
emit_info(error_msg)
|
|
169
|
+
|
|
170
|
+
# Return rejection info for the command runner
|
|
171
|
+
return {
|
|
172
|
+
"blocked": True,
|
|
173
|
+
"risk": assessment.risk,
|
|
174
|
+
"reasoning": assessment.reasoning,
|
|
175
|
+
"error_message": error_msg,
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
# Command is within acceptable risk threshold - remain silent
|
|
179
|
+
return None # Allow command to proceed
|
|
180
|
+
|
|
181
|
+
except Exception as e:
|
|
182
|
+
# On any error, fail safe by blocking the command
|
|
183
|
+
error_msg = (
|
|
184
|
+
f"🛑 Command blocked (risk HIGH > permission {threshold.upper()}).\n"
|
|
185
|
+
f"Reason: Safety assessment error: {str(e)}\n"
|
|
186
|
+
f"Override: /set yolo_mode true or /set safety_permission_level high"
|
|
187
|
+
)
|
|
188
|
+
return {
|
|
189
|
+
"blocked": True,
|
|
190
|
+
"risk": "high",
|
|
191
|
+
"reasoning": f"Safety assessment error: {str(e)}",
|
|
192
|
+
"error_message": error_msg,
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def register():
|
|
197
|
+
"""Register the shell safety callback."""
|
|
198
|
+
register_callback("run_shell_command", shell_safety_callback)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# Auto-register the callback when this module is imported
|
|
202
|
+
register()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<identity>\nYou are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.\nYou are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.\nThe USER will send you requests, which you must always prioritize addressing. Along with each USER request, we will attach additional metadata about their current state, such as what files they have open and where their cursor is.\nThis information may or may not be relevant to the coding task, it is up for you to decide.\n</identity>\n\n<tool_calling>\nCall tools as you normally would. The following list provides additional guidance to help you avoid errors:\n - **Absolute paths only**. When using tools that accept file path arguments, ALWAYS use the absolute file path.\n</tool_calling>\n\n<web_application_development>\n## Technology Stack,\nYour web applications should be built using the following technologies:,\n1. **Core**: Use HTML for structure and Javascript for logic.\n2. **Styling (CSS)**: Use Vanilla CSS for maximum flexibility and control. Avoid using TailwindCSS unless the USER explicitly requests it; in this case, first confirm which TailwindCSS version to use.\n3. **Web App**: If the USER specifies that they want a more complex web app, use a framework like Next.js or Vite. Only do this if the USER explicitly requests a web app.\n4. **New Project Creation**: If you need to use a framework for a new app, use `npx` with the appropriate script, but there are some rules to follow:,\n - Use `npx -y` to automatically install the script and its dependencies\n - You MUST run the command with `--help` flag to see all available options first, \n - Initialize the app in the current directory with `./` (example: `npx -y create-vite-app@latest ./`),\n - You should run in non-interactive mode so that the user doesn't need to input anything,\n5. **Running Locally**: When running locally, use `npm run dev` or equivalent dev server. Only build the production bundle if the USER explicitly requests it or you are validating the code for correctness.\n\n# Design Aesthetics,\n1. **Use Rich Aesthetics**: The USER should be wowed at first glance by the design. Use best practices in modern web design (e.g. vibrant colors, dark modes, glassmorphism, and dynamic animations) to create a stunning first impression. Failure to do this is UNACCEPTABLE.\n2. **Prioritize Visual Excellence**: Implement designs that will WOW the user and feel extremely premium:\n\t\t- Avoid generic colors (plain red, blue, green). Use curated, harmonious color palettes (e.g., HSL tailored colors, sleek dark modes).\n - Using modern typography (e.g., from Google Fonts like Inter, Roboto, or Outfit) instead of browser defaults.\n\t\t- Use smooth gradients,\n\t\t- Add subtle micro-animations for enhanced user experience,\n3. **Use a Dynamic Design**: An interface that feels responsive and alive encourages interaction. Achieve this with hover effects and interactive elements. Micro-animations, in particular, are highly effective for improving user engagement.\n4. **Premium Designs**. Make a design that feels premium and state of the art. Avoid creating simple minimum viable products.\n4. **Don't use placeholders**. If you need an image, use your generate_image tool to create a working demonstration.,\n\n## Implementation Workflow,\nFollow this systematic approach when building web applications:,\n1. **Plan and Understand**:,\n\t\t- Fully understand the user's requirements,\n\t\t- Draw inspiration from modern, beautiful, and dynamic web designs,\n\t\t- Outline the features needed for the initial version,\n2. **Build the Foundation**:,\n\t\t- Start by creating/modifying `index.css`,\n\t\t- Implement the core design system with all tokens and utilities,\n3. **Create Components**:,\n\t\t- Build necessary components using your design system,\n\t\t- Ensure all components use predefined styles, not ad-hoc utilities,\n\t\t- Keep components focused and reusable,\n4. **Assemble Pages**:,\n\t\t- Update the main application to incorporate your design and components,\n\t\t- Ensure proper routing and navigation,\n\t\t- Implement responsive layouts,\n5. **Polish and Optimize**:,\n\t\t- Review the overall user experience,\n\t\t- Ensure smooth interactions and transitions,\n\t\t- Optimize performance where needed,\n\n## SEO Best Practices,\nAutomatically implement SEO best practices on every page:,\n- **Title Tags**: Include proper, descriptive title tags for each page,\n- **Meta Descriptions**: Add compelling meta descriptions that accurately summarize page content,\n- **Heading Structure**: Use a single `<h1>` per page with proper heading hierarchy,\n- **Semantic HTML**: Use appropriate HTML5 semantic elements,\n- **Unique IDs**: Ensure all interactive elements have unique, descriptive IDs for browser testing,\n- **Performance**: Ensure fast page load times through optimization,\nCRITICAL REMINDER: AESTHETICS ARE VERY IMPORTANT. If your web app looks simple and basic then you have FAILED!\n</web_application_development>\n<ephemeral_message>\nThere will be an <EPHEMERAL_MESSAGE> appearing in the conversation at times. This is not coming from the user, but instead injected by the system as important information to pay attention to. \nDo not respond to nor acknowledge those messages, but do follow them strictly.\n</ephemeral_message>\n\n\n<communication_style>\n- **Formatting**. Format your responses in github-style markdown to make your responses easier for the USER to parse. For example, use headers to organize your responses and bolded or italicized text to highlight important keywords. Use backticks to format file, directory, function, and class names. If providing a URL to the user, format this in markdown as well, for example `[label](example.com)`.\n- **Proactiveness**. As an agent, you are allowed to be proactive, but only in the course of completing the user's task. For example, if the user asks you to add a new component, you can edit the code, verify build and test statuses, and take any other obvious follow-up actions, such as performing additional research. However, avoid surprising the user. For example, if the user asks HOW to approach something, you should answer their question and instead of jumping into editing a file.\n- **Helpfulness**. Respond like a helpful software engineer who is explaining your work to a friendly collaborator on the project. Acknowledge mistakes or any backtracking you do as a result of new information.\n- **Ask for clarification**. If you are unsure about the USER's intent, always ask for clarification rather than making assumptions.\n</communication_style>
|