shotgun-sh 0.2.8.dev2__py3-none-any.whl → 0.3.3.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.
Files changed (175) hide show
  1. shotgun/agents/agent_manager.py +382 -60
  2. shotgun/agents/common.py +15 -9
  3. shotgun/agents/config/README.md +89 -0
  4. shotgun/agents/config/__init__.py +10 -1
  5. shotgun/agents/config/constants.py +0 -6
  6. shotgun/agents/config/manager.py +383 -82
  7. shotgun/agents/config/models.py +122 -18
  8. shotgun/agents/config/provider.py +81 -15
  9. shotgun/agents/config/streaming_test.py +119 -0
  10. shotgun/agents/context_analyzer/__init__.py +28 -0
  11. shotgun/agents/context_analyzer/analyzer.py +475 -0
  12. shotgun/agents/context_analyzer/constants.py +9 -0
  13. shotgun/agents/context_analyzer/formatter.py +115 -0
  14. shotgun/agents/context_analyzer/models.py +212 -0
  15. shotgun/agents/conversation/__init__.py +18 -0
  16. shotgun/agents/conversation/filters.py +164 -0
  17. shotgun/agents/conversation/history/chunking.py +278 -0
  18. shotgun/agents/{history → conversation/history}/compaction.py +36 -5
  19. shotgun/agents/{history → conversation/history}/constants.py +5 -0
  20. shotgun/agents/conversation/history/file_content_deduplication.py +216 -0
  21. shotgun/agents/{history → conversation/history}/history_processors.py +380 -8
  22. shotgun/agents/{history → conversation/history}/token_counting/anthropic.py +25 -1
  23. shotgun/agents/{history → conversation/history}/token_counting/base.py +14 -3
  24. shotgun/agents/{history → conversation/history}/token_counting/openai.py +11 -1
  25. shotgun/agents/{history → conversation/history}/token_counting/sentencepiece_counter.py +8 -0
  26. shotgun/agents/{history → conversation/history}/token_counting/tokenizer_cache.py +3 -1
  27. shotgun/agents/{history → conversation/history}/token_counting/utils.py +0 -3
  28. shotgun/agents/{conversation_manager.py → conversation/manager.py} +36 -20
  29. shotgun/agents/{conversation_history.py → conversation/models.py} +8 -92
  30. shotgun/agents/error/__init__.py +11 -0
  31. shotgun/agents/error/models.py +19 -0
  32. shotgun/agents/export.py +2 -2
  33. shotgun/agents/plan.py +2 -2
  34. shotgun/agents/research.py +3 -3
  35. shotgun/agents/runner.py +230 -0
  36. shotgun/agents/specify.py +2 -2
  37. shotgun/agents/tasks.py +2 -2
  38. shotgun/agents/tools/codebase/codebase_shell.py +6 -0
  39. shotgun/agents/tools/codebase/directory_lister.py +6 -0
  40. shotgun/agents/tools/codebase/file_read.py +11 -2
  41. shotgun/agents/tools/codebase/query_graph.py +6 -0
  42. shotgun/agents/tools/codebase/retrieve_code.py +6 -0
  43. shotgun/agents/tools/file_management.py +27 -7
  44. shotgun/agents/tools/registry.py +217 -0
  45. shotgun/agents/tools/web_search/__init__.py +8 -8
  46. shotgun/agents/tools/web_search/anthropic.py +8 -2
  47. shotgun/agents/tools/web_search/gemini.py +7 -1
  48. shotgun/agents/tools/web_search/openai.py +8 -2
  49. shotgun/agents/tools/web_search/utils.py +2 -2
  50. shotgun/agents/usage_manager.py +16 -11
  51. shotgun/api_endpoints.py +7 -3
  52. shotgun/build_constants.py +2 -2
  53. shotgun/cli/clear.py +53 -0
  54. shotgun/cli/compact.py +188 -0
  55. shotgun/cli/config.py +8 -5
  56. shotgun/cli/context.py +154 -0
  57. shotgun/cli/error_handler.py +24 -0
  58. shotgun/cli/export.py +34 -34
  59. shotgun/cli/feedback.py +4 -2
  60. shotgun/cli/models.py +1 -0
  61. shotgun/cli/plan.py +34 -34
  62. shotgun/cli/research.py +18 -10
  63. shotgun/cli/spec/__init__.py +5 -0
  64. shotgun/cli/spec/backup.py +81 -0
  65. shotgun/cli/spec/commands.py +132 -0
  66. shotgun/cli/spec/models.py +48 -0
  67. shotgun/cli/spec/pull_service.py +219 -0
  68. shotgun/cli/specify.py +20 -19
  69. shotgun/cli/tasks.py +34 -34
  70. shotgun/cli/update.py +16 -2
  71. shotgun/codebase/core/change_detector.py +5 -3
  72. shotgun/codebase/core/code_retrieval.py +4 -2
  73. shotgun/codebase/core/ingestor.py +163 -15
  74. shotgun/codebase/core/manager.py +13 -4
  75. shotgun/codebase/core/nl_query.py +1 -1
  76. shotgun/codebase/models.py +2 -0
  77. shotgun/exceptions.py +357 -0
  78. shotgun/llm_proxy/__init__.py +17 -0
  79. shotgun/llm_proxy/client.py +215 -0
  80. shotgun/llm_proxy/models.py +137 -0
  81. shotgun/logging_config.py +60 -27
  82. shotgun/main.py +77 -11
  83. shotgun/posthog_telemetry.py +38 -29
  84. shotgun/prompts/agents/partials/common_agent_system_prompt.j2 +28 -2
  85. shotgun/prompts/agents/partials/interactive_mode.j2 +3 -3
  86. shotgun/prompts/agents/plan.j2 +16 -0
  87. shotgun/prompts/agents/research.j2 +16 -3
  88. shotgun/prompts/agents/specify.j2 +54 -1
  89. shotgun/prompts/agents/state/system_state.j2 +0 -2
  90. shotgun/prompts/agents/tasks.j2 +16 -0
  91. shotgun/prompts/history/chunk_summarization.j2 +34 -0
  92. shotgun/prompts/history/combine_summaries.j2 +53 -0
  93. shotgun/sdk/codebase.py +14 -3
  94. shotgun/sentry_telemetry.py +163 -16
  95. shotgun/settings.py +243 -0
  96. shotgun/shotgun_web/__init__.py +67 -1
  97. shotgun/shotgun_web/client.py +42 -1
  98. shotgun/shotgun_web/constants.py +46 -0
  99. shotgun/shotgun_web/exceptions.py +29 -0
  100. shotgun/shotgun_web/models.py +390 -0
  101. shotgun/shotgun_web/shared_specs/__init__.py +32 -0
  102. shotgun/shotgun_web/shared_specs/file_scanner.py +175 -0
  103. shotgun/shotgun_web/shared_specs/hasher.py +83 -0
  104. shotgun/shotgun_web/shared_specs/models.py +71 -0
  105. shotgun/shotgun_web/shared_specs/upload_pipeline.py +329 -0
  106. shotgun/shotgun_web/shared_specs/utils.py +34 -0
  107. shotgun/shotgun_web/specs_client.py +703 -0
  108. shotgun/shotgun_web/supabase_client.py +31 -0
  109. shotgun/telemetry.py +10 -33
  110. shotgun/tui/app.py +310 -46
  111. shotgun/tui/commands/__init__.py +1 -1
  112. shotgun/tui/components/context_indicator.py +179 -0
  113. shotgun/tui/components/mode_indicator.py +70 -0
  114. shotgun/tui/components/status_bar.py +48 -0
  115. shotgun/tui/containers.py +91 -0
  116. shotgun/tui/dependencies.py +39 -0
  117. shotgun/tui/layout.py +5 -0
  118. shotgun/tui/protocols.py +45 -0
  119. shotgun/tui/screens/chat/__init__.py +5 -0
  120. shotgun/tui/screens/chat/chat.tcss +54 -0
  121. shotgun/tui/screens/chat/chat_screen.py +1531 -0
  122. shotgun/tui/screens/chat/codebase_index_prompt_screen.py +243 -0
  123. shotgun/tui/screens/chat/codebase_index_selection.py +12 -0
  124. shotgun/tui/screens/chat/help_text.py +40 -0
  125. shotgun/tui/screens/chat/prompt_history.py +48 -0
  126. shotgun/tui/screens/chat.tcss +11 -0
  127. shotgun/tui/screens/chat_screen/command_providers.py +91 -4
  128. shotgun/tui/screens/chat_screen/hint_message.py +76 -1
  129. shotgun/tui/screens/chat_screen/history/__init__.py +22 -0
  130. shotgun/tui/screens/chat_screen/history/agent_response.py +66 -0
  131. shotgun/tui/screens/chat_screen/history/chat_history.py +115 -0
  132. shotgun/tui/screens/chat_screen/history/formatters.py +115 -0
  133. shotgun/tui/screens/chat_screen/history/partial_response.py +43 -0
  134. shotgun/tui/screens/chat_screen/history/user_question.py +42 -0
  135. shotgun/tui/screens/confirmation_dialog.py +191 -0
  136. shotgun/tui/screens/directory_setup.py +45 -41
  137. shotgun/tui/screens/feedback.py +14 -7
  138. shotgun/tui/screens/github_issue.py +111 -0
  139. shotgun/tui/screens/model_picker.py +77 -32
  140. shotgun/tui/screens/onboarding.py +580 -0
  141. shotgun/tui/screens/pipx_migration.py +205 -0
  142. shotgun/tui/screens/provider_config.py +116 -35
  143. shotgun/tui/screens/shared_specs/__init__.py +21 -0
  144. shotgun/tui/screens/shared_specs/create_spec_dialog.py +273 -0
  145. shotgun/tui/screens/shared_specs/models.py +56 -0
  146. shotgun/tui/screens/shared_specs/share_specs_dialog.py +390 -0
  147. shotgun/tui/screens/shared_specs/upload_progress_screen.py +452 -0
  148. shotgun/tui/screens/shotgun_auth.py +112 -18
  149. shotgun/tui/screens/spec_pull.py +288 -0
  150. shotgun/tui/screens/welcome.py +137 -11
  151. shotgun/tui/services/__init__.py +5 -0
  152. shotgun/tui/services/conversation_service.py +187 -0
  153. shotgun/tui/state/__init__.py +7 -0
  154. shotgun/tui/state/processing_state.py +185 -0
  155. shotgun/tui/utils/mode_progress.py +14 -7
  156. shotgun/tui/widgets/__init__.py +5 -0
  157. shotgun/tui/widgets/widget_coordinator.py +263 -0
  158. shotgun/utils/file_system_utils.py +22 -2
  159. shotgun/utils/marketing.py +110 -0
  160. shotgun/utils/update_checker.py +69 -14
  161. shotgun_sh-0.3.3.dev1.dist-info/METADATA +472 -0
  162. shotgun_sh-0.3.3.dev1.dist-info/RECORD +229 -0
  163. {shotgun_sh-0.2.8.dev2.dist-info → shotgun_sh-0.3.3.dev1.dist-info}/WHEEL +1 -1
  164. {shotgun_sh-0.2.8.dev2.dist-info → shotgun_sh-0.3.3.dev1.dist-info}/entry_points.txt +1 -0
  165. {shotgun_sh-0.2.8.dev2.dist-info → shotgun_sh-0.3.3.dev1.dist-info}/licenses/LICENSE +1 -1
  166. shotgun/tui/screens/chat.py +0 -996
  167. shotgun/tui/screens/chat_screen/history.py +0 -335
  168. shotgun_sh-0.2.8.dev2.dist-info/METADATA +0 -126
  169. shotgun_sh-0.2.8.dev2.dist-info/RECORD +0 -155
  170. /shotgun/agents/{history → conversation/history}/__init__.py +0 -0
  171. /shotgun/agents/{history → conversation/history}/context_extraction.py +0 -0
  172. /shotgun/agents/{history → conversation/history}/history_building.py +0 -0
  173. /shotgun/agents/{history → conversation/history}/message_utils.py +0 -0
  174. /shotgun/agents/{history → conversation/history}/token_counting/__init__.py +0 -0
  175. /shotgun/agents/{history → conversation/history}/token_estimation.py +0 -0
@@ -0,0 +1,263 @@
1
+ # mypy: disable-error-code="import-not-found"
2
+ """Widget coordinator to centralize widget queries and updates.
3
+
4
+ This module eliminates scattered `query_one()` calls throughout ChatScreen
5
+ by providing a single place for all widget updates. This improves:
6
+ - Testability (can test update logic in isolation)
7
+ - Maintainability (clear update contracts)
8
+ - Performance (can batch updates if needed)
9
+ """
10
+
11
+ import logging
12
+ from typing import TYPE_CHECKING
13
+
14
+ from pydantic_ai.messages import ModelMessage
15
+
16
+ from shotgun.agents.config.models import ModelName
17
+ from shotgun.agents.models import AgentType
18
+ from shotgun.tui.components.context_indicator import ContextIndicator
19
+ from shotgun.tui.components.mode_indicator import ModeIndicator
20
+ from shotgun.tui.components.prompt_input import PromptInput
21
+ from shotgun.tui.components.spinner import Spinner
22
+ from shotgun.tui.components.status_bar import StatusBar
23
+ from shotgun.tui.screens.chat_screen.history.chat_history import ChatHistory
24
+
25
+ if TYPE_CHECKING:
26
+ from shotgun.agents.context_analyzer.models import ContextAnalysis
27
+ from shotgun.tui.screens.chat import ChatScreen
28
+ from shotgun.tui.screens.chat_screen.hint_message import HintMessage
29
+
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class WidgetCoordinator:
34
+ """Coordinates updates to all widgets in ChatScreen.
35
+
36
+ This class centralizes all `query_one()` calls and widget manipulations,
37
+ providing clear update methods instead of scattered direct queries.
38
+
39
+ Benefits:
40
+ - Single place for all widget updates
41
+ - Testable without full TUI
42
+ - Clear update contracts
43
+ - Can add batching/debouncing easily
44
+ """
45
+
46
+ def __init__(self, screen: "ChatScreen"):
47
+ """Initialize the coordinator with a reference to the screen.
48
+
49
+ Args:
50
+ screen: The ChatScreen instance containing the widgets.
51
+ """
52
+ self.screen = screen
53
+
54
+ def update_for_mode_change(
55
+ self, new_mode: AgentType, placeholder: str | None = None
56
+ ) -> None:
57
+ """Update all widgets when agent mode changes.
58
+
59
+ Args:
60
+ new_mode: The new agent mode.
61
+ placeholder: Optional placeholder text for input. If not provided,
62
+ will use the screen's _placeholder_for_mode method.
63
+ """
64
+ if not self.screen.is_mounted:
65
+ return
66
+
67
+ # Update mode indicator
68
+ try:
69
+ mode_indicator = self.screen.query_one(ModeIndicator)
70
+ mode_indicator.mode = new_mode
71
+ mode_indicator.refresh()
72
+ except Exception as e:
73
+ logger.exception(f"Failed to update mode indicator: {e}")
74
+
75
+ # Update prompt input placeholder
76
+ try:
77
+ prompt_input = self.screen.query_one(PromptInput)
78
+ if placeholder is None:
79
+ placeholder = self.screen._placeholder_for_mode(
80
+ new_mode, force_new=True
81
+ )
82
+ prompt_input.placeholder = placeholder
83
+ prompt_input.refresh()
84
+ except Exception as e:
85
+ logger.exception(f"Failed to update prompt input: {e}")
86
+
87
+ def update_for_processing_state(
88
+ self, is_processing: bool, spinner_text: str | None = None
89
+ ) -> None:
90
+ """Update widgets when processing state changes.
91
+
92
+ Args:
93
+ is_processing: Whether processing is active.
94
+ spinner_text: Optional text to display in spinner.
95
+ """
96
+ if not self.screen.is_mounted:
97
+ return
98
+
99
+ # Update spinner visibility
100
+ try:
101
+ spinner = self.screen.query_one("#spinner", Spinner)
102
+ spinner.set_classes("" if is_processing else "hidden")
103
+ spinner.display = is_processing
104
+ if spinner_text and is_processing:
105
+ spinner.text = spinner_text
106
+ except Exception as e:
107
+ logger.exception(f"Failed to update spinner: {e}")
108
+
109
+ # Update status bar
110
+ try:
111
+ status_bar = self.screen.query_one(StatusBar)
112
+ status_bar.working = is_processing
113
+ status_bar.refresh()
114
+ except Exception as e:
115
+ logger.exception(f"Failed to update status bar: {e}")
116
+
117
+ def update_for_qa_mode(self, qa_mode_active: bool) -> None:
118
+ """Update widgets when Q&A mode changes.
119
+
120
+ Args:
121
+ qa_mode_active: Whether Q&A mode is active.
122
+ """
123
+ if not self.screen.is_mounted:
124
+ return
125
+
126
+ # Update status bar
127
+ try:
128
+ status_bar = self.screen.query_one(StatusBar)
129
+ status_bar.refresh()
130
+ except Exception as e:
131
+ logger.exception(f"Failed to update status bar for Q&A: {e}")
132
+
133
+ # Update mode indicator
134
+ try:
135
+ mode_indicator = self.screen.query_one(ModeIndicator)
136
+ mode_indicator.refresh()
137
+ except Exception as e:
138
+ logger.exception(f"Failed to update mode indicator for Q&A: {e}")
139
+
140
+ def update_messages(self, messages: list[ModelMessage | "HintMessage"]) -> None:
141
+ """Update chat history with new messages.
142
+
143
+ Args:
144
+ messages: The messages to display.
145
+ """
146
+ if not self.screen.is_mounted:
147
+ return
148
+
149
+ try:
150
+ chat_history = self.screen.query_one(ChatHistory)
151
+ chat_history.update_messages(messages)
152
+ except Exception as e:
153
+ logger.exception(f"Failed to update messages: {e}")
154
+
155
+ def set_partial_response(
156
+ self, message: ModelMessage | None, messages: list[ModelMessage | "HintMessage"]
157
+ ) -> None:
158
+ """Update chat history with partial streaming response.
159
+
160
+ Args:
161
+ message: The partial message being streamed.
162
+ messages: The full message history.
163
+ """
164
+ if not self.screen.is_mounted:
165
+ return
166
+
167
+ try:
168
+ chat_history = self.screen.query_one(ChatHistory)
169
+ # Set the reactive attribute to trigger the PartialResponseWidget update
170
+ chat_history.partial_response = message
171
+ # Also update the full message list
172
+ chat_history.update_messages(messages)
173
+ except Exception as e:
174
+ logger.exception(f"Failed to set partial response: {e}")
175
+
176
+ def update_context_indicator(
177
+ self, analysis: "ContextAnalysis | None", model_name: str
178
+ ) -> None:
179
+ """Update context indicator with new analysis.
180
+
181
+ Args:
182
+ analysis: The context analysis results.
183
+ model_name: The current model name.
184
+ """
185
+ if not self.screen.is_mounted:
186
+ return
187
+
188
+ try:
189
+ context_indicator = self.screen.query_one(ContextIndicator)
190
+ # Cast the string model name to ModelName type
191
+ model = ModelName(model_name) if model_name else None
192
+ context_indicator.update_context(analysis, model)
193
+ except Exception as e:
194
+ logger.exception(f"Failed to update context indicator: {e}")
195
+
196
+ def update_prompt_input(
197
+ self,
198
+ placeholder: str | None = None,
199
+ clear: bool = False,
200
+ focus: bool = False,
201
+ ) -> None:
202
+ """Update prompt input widget.
203
+
204
+ Args:
205
+ placeholder: New placeholder text.
206
+ clear: Whether to clear the input.
207
+ focus: Whether to focus the input.
208
+ """
209
+ if not self.screen.is_mounted:
210
+ return
211
+
212
+ try:
213
+ prompt_input = self.screen.query_one(PromptInput)
214
+ if placeholder is not None:
215
+ prompt_input.placeholder = placeholder
216
+ if clear:
217
+ prompt_input.clear()
218
+ if focus:
219
+ prompt_input.focus()
220
+ except Exception as e:
221
+ logger.exception(f"Failed to update prompt input: {e}")
222
+
223
+ def refresh_mode_indicator(self) -> None:
224
+ """Refresh mode indicator without changing mode."""
225
+ if not self.screen.is_mounted:
226
+ return
227
+
228
+ try:
229
+ mode_indicator = self.screen.query_one(ModeIndicator)
230
+ mode_indicator.refresh()
231
+ except Exception as e:
232
+ logger.exception(f"Failed to refresh mode indicator: {e}")
233
+
234
+ def update_spinner_text(self, text: str) -> None:
235
+ """Update spinner text without changing visibility.
236
+
237
+ Args:
238
+ text: The new spinner text.
239
+ """
240
+ if not self.screen.is_mounted:
241
+ return
242
+
243
+ try:
244
+ spinner = self.screen.query_one("#spinner", Spinner)
245
+ if spinner.display: # Only update if visible
246
+ spinner.text = text
247
+ except Exception as e:
248
+ logger.exception(f"Failed to update spinner text: {e}")
249
+
250
+ def set_context_streaming(self, streaming: bool) -> None:
251
+ """Enable or disable context indicator streaming animation.
252
+
253
+ Args:
254
+ streaming: Whether to show streaming animation.
255
+ """
256
+ if not self.screen.is_mounted:
257
+ return
258
+
259
+ try:
260
+ context_indicator = self.screen.query_one(ContextIndicator)
261
+ context_indicator.set_streaming(streaming)
262
+ except Exception as e:
263
+ logger.exception(f"Failed to set context streaming: {e}")
@@ -1,8 +1,11 @@
1
1
  """File system utility functions."""
2
2
 
3
- import os
4
3
  from pathlib import Path
5
4
 
5
+ import aiofiles
6
+
7
+ from shotgun.settings import settings
8
+
6
9
 
7
10
  def get_shotgun_base_path() -> Path:
8
11
  """Get the absolute path to the .shotgun directory."""
@@ -18,7 +21,7 @@ def get_shotgun_home() -> Path:
18
21
  Path to shotgun home directory (default: ~/.shotgun-sh/)
19
22
  """
20
23
  # Allow override via environment variable (useful for testing)
21
- if custom_home := os.environ.get("SHOTGUN_HOME"):
24
+ if custom_home := settings.dev.home:
22
25
  return Path(custom_home)
23
26
 
24
27
  return Path.home() / ".shotgun-sh"
@@ -34,3 +37,20 @@ def ensure_shotgun_directory_exists() -> Path:
34
37
  shotgun_dir.mkdir(exist_ok=True)
35
38
  # Note: Removed logger to avoid circular dependency with logging_config
36
39
  return shotgun_dir
40
+
41
+
42
+ async def async_copy_file(src: Path, dst: Path) -> None:
43
+ """Asynchronously copy a file from src to dst.
44
+
45
+ Args:
46
+ src: Source file path
47
+ dst: Destination file path
48
+
49
+ Raises:
50
+ FileNotFoundError: If source file doesn't exist
51
+ OSError: If copy operation fails
52
+ """
53
+ async with aiofiles.open(src, "rb") as src_file:
54
+ content = await src_file.read()
55
+ async with aiofiles.open(dst, "wb") as dst_file:
56
+ await dst_file.write(content)
@@ -0,0 +1,110 @@
1
+ """Marketing message management for Shotgun CLI."""
2
+
3
+ from collections.abc import Callable
4
+ from datetime import datetime, timezone
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING
7
+
8
+ from shotgun.agents.config.models import MarketingConfig, MarketingMessageRecord
9
+ from shotgun.agents.models import FileOperation
10
+
11
+ if TYPE_CHECKING:
12
+ from shotgun.agents.config.manager import ConfigManager
13
+
14
+ # Marketing message IDs
15
+ GITHUB_STAR_MESSAGE_ID = "github_star_v1"
16
+
17
+ # Spec files that trigger the GitHub star message
18
+ SPEC_FILES = {"research.md", "specification.md", "plan.md", "tasks.md"}
19
+
20
+
21
+ class MarketingManager:
22
+ """Manages marketing messages shown to users."""
23
+
24
+ @staticmethod
25
+ def should_show_github_star_message(
26
+ marketing_config: MarketingConfig, file_operations: list[FileOperation]
27
+ ) -> bool:
28
+ """
29
+ Check if the GitHub star message should be shown.
30
+
31
+ Args:
32
+ marketing_config: Current marketing configuration
33
+ file_operations: List of file operations from the current agent run
34
+
35
+ Returns:
36
+ True if message should be shown, False otherwise
37
+ """
38
+ # Check if message has already been shown
39
+ if GITHUB_STAR_MESSAGE_ID in marketing_config.messages:
40
+ return False
41
+
42
+ # Check if any spec file was written
43
+ for operation in file_operations:
44
+ # operation.file_path is a string, so we convert to Path to get the filename
45
+ file_name = Path(operation.file_path).name
46
+ if file_name in SPEC_FILES:
47
+ return True
48
+
49
+ return False
50
+
51
+ @staticmethod
52
+ def mark_message_shown(
53
+ marketing_config: MarketingConfig, message_id: str
54
+ ) -> MarketingConfig:
55
+ """
56
+ Mark a marketing message as shown.
57
+
58
+ Args:
59
+ marketing_config: Current marketing configuration
60
+ message_id: ID of the message to mark as shown
61
+
62
+ Returns:
63
+ Updated marketing configuration
64
+ """
65
+ # Create a new record with current timestamp
66
+ record = MarketingMessageRecord(shown_at=datetime.now(timezone.utc))
67
+
68
+ # Update the messages dict
69
+ marketing_config.messages[message_id] = record
70
+
71
+ return marketing_config
72
+
73
+ @staticmethod
74
+ def get_github_star_message() -> str:
75
+ """Get the GitHub star marketing message text."""
76
+ return "⭐ Enjoying Shotgun? Star us on GitHub: https://github.com/shotgun-sh/shotgun"
77
+
78
+ @staticmethod
79
+ async def check_and_display_messages(
80
+ config_manager: "ConfigManager",
81
+ file_operations: list[FileOperation],
82
+ display_callback: Callable[[str], None],
83
+ ) -> None:
84
+ """
85
+ Check if any marketing messages should be shown and display them.
86
+
87
+ This is the main entry point for marketing message handling. It checks
88
+ all configured messages, displays them if appropriate, and updates the
89
+ config to mark them as shown.
90
+
91
+ Args:
92
+ config_manager: Config manager to load/save configuration
93
+ file_operations: List of file operations from the current agent run
94
+ display_callback: Callback function to display messages to the user
95
+ """
96
+ config = await config_manager.load()
97
+
98
+ # Check GitHub star message
99
+ if MarketingManager.should_show_github_star_message(
100
+ config.marketing, file_operations
101
+ ):
102
+ # Display the message
103
+ message = MarketingManager.get_github_star_message()
104
+ display_callback(message)
105
+
106
+ # Mark as shown and save
107
+ MarketingManager.mark_message_shown(
108
+ config.marketing, GITHUB_STAR_MESSAGE_ID
109
+ )
110
+ await config_manager.save(config)
@@ -10,6 +10,7 @@ from packaging import version
10
10
 
11
11
  from shotgun import __version__
12
12
  from shotgun.logging_config import get_logger
13
+ from shotgun.settings import settings
13
14
 
14
15
  logger = get_logger(__name__)
15
16
 
@@ -18,8 +19,34 @@ def detect_installation_method() -> str:
18
19
  """Detect how shotgun-sh was installed.
19
20
 
20
21
  Returns:
21
- Installation method: 'pipx', 'pip', 'venv', or 'unknown'.
22
+ Installation method: 'uvx', 'uv-tool', 'pipx', 'pip', 'venv', or 'unknown'.
22
23
  """
24
+ # Check for simulation environment variable (for testing)
25
+ if settings.dev.pipx_simulate:
26
+ logger.debug("SHOTGUN_PIPX_SIMULATE enabled, simulating pipx installation")
27
+ return "pipx"
28
+
29
+ # Check for uvx (ephemeral execution) by looking at executable path
30
+ # uvx runs from a temporary cache directory
31
+ executable = Path(sys.executable)
32
+ if ".cache/uv" in str(executable) or "uv/cache" in str(executable):
33
+ logger.debug("Detected uvx (ephemeral) execution")
34
+ return "uvx"
35
+
36
+ # Check for uv tool installation
37
+ try:
38
+ result = subprocess.run(
39
+ ["uv", "tool", "list"], # noqa: S607, S603
40
+ capture_output=True,
41
+ text=True,
42
+ timeout=5,
43
+ )
44
+ if result.returncode == 0 and "shotgun-sh" in result.stdout:
45
+ logger.debug("Detected uv tool installation")
46
+ return "uv-tool"
47
+ except (subprocess.SubprocessError, FileNotFoundError):
48
+ pass
49
+
23
50
  # Check for pipx installation
24
51
  try:
25
52
  result = subprocess.run(
@@ -59,7 +86,7 @@ def detect_installation_method() -> str:
59
86
 
60
87
 
61
88
  def perform_auto_update(no_update_check: bool = False) -> None:
62
- """Perform automatic update if installed via pipx.
89
+ """Perform automatic update if installed via pipx or uv tool.
63
90
 
64
91
  Args:
65
92
  no_update_check: If True, skip the update.
@@ -68,23 +95,40 @@ def perform_auto_update(no_update_check: bool = False) -> None:
68
95
  return
69
96
 
70
97
  try:
71
- # Only auto-update for pipx installations
72
- if detect_installation_method() != "pipx":
73
- logger.debug("Not a pipx installation, skipping auto-update")
98
+ method = detect_installation_method()
99
+
100
+ # Skip auto-update for ephemeral uvx executions
101
+ if method == "uvx":
102
+ logger.debug("uvx (ephemeral) execution, skipping auto-update")
74
103
  return
75
104
 
76
- # Run pipx upgrade quietly
77
- logger.debug("Running pipx upgrade shotgun-sh --quiet")
78
- result = subprocess.run(
79
- ["pipx", "upgrade", "shotgun-sh", "--quiet"], # noqa: S607, S603
105
+ # Only auto-update for pipx and uv-tool installations
106
+ if method not in ["pipx", "uv-tool"]:
107
+ logger.debug(f"Installation method '{method}', skipping auto-update")
108
+ return
109
+
110
+ # Determine the appropriate upgrade command
111
+ if method == "pipx":
112
+ command = ["pipx", "upgrade", "shotgun-sh", "--quiet"]
113
+ logger.debug("Running pipx upgrade shotgun-sh --quiet")
114
+ elif method == "uv-tool":
115
+ command = ["uv", "tool", "upgrade", "shotgun-sh"]
116
+ logger.debug("Running uv tool upgrade shotgun-sh")
117
+ else:
118
+ return
119
+
120
+ # Run upgrade command
121
+ result = subprocess.run( # noqa: S603, S607
122
+ command,
80
123
  capture_output=True,
81
124
  text=True,
82
125
  timeout=30,
83
126
  )
84
127
 
85
128
  if result.returncode == 0:
86
- # Check if there was an actual update (pipx shows output even with --quiet for actual updates)
87
- if result.stdout and "upgraded" in result.stdout.lower():
129
+ # Check if there was an actual update
130
+ output = result.stdout.lower()
131
+ if "upgraded" in output or "updated" in output:
88
132
  logger.info("Shotgun-sh has been updated to the latest version")
89
133
  else:
90
134
  # Only log errors at debug level to not annoy users
@@ -166,16 +210,18 @@ def compare_versions(current: str, latest: str) -> bool:
166
210
  return False
167
211
 
168
212
 
169
- def get_update_command(method: str) -> list[str]:
213
+ def get_update_command(method: str) -> list[str] | None:
170
214
  """Get the appropriate update command based on installation method.
171
215
 
172
216
  Args:
173
- method: Installation method ('pipx', 'pip', 'venv', or 'unknown').
217
+ method: Installation method ('uvx', 'uv-tool', 'pipx', 'pip', 'venv', or 'unknown').
174
218
 
175
219
  Returns:
176
- Command list to execute for updating.
220
+ Command list to execute for updating, or None for uvx (ephemeral).
177
221
  """
178
222
  commands = {
223
+ "uvx": None, # uvx is ephemeral, no update command
224
+ "uv-tool": ["uv", "tool", "upgrade", "shotgun-sh"],
179
225
  "pipx": ["pipx", "upgrade", "shotgun-sh"],
180
226
  "pip": [sys.executable, "-m", "pip", "install", "--upgrade", "shotgun-sh"],
181
227
  "venv": [sys.executable, "-m", "pip", "install", "--upgrade", "shotgun-sh"],
@@ -210,6 +256,15 @@ def perform_update(force: bool = False) -> tuple[bool, str]:
210
256
  method = detect_installation_method()
211
257
  command = get_update_command(method)
212
258
 
259
+ # Handle uvx (ephemeral) installations
260
+ if method == "uvx" or command is None:
261
+ return (
262
+ False,
263
+ "You're running shotgun-sh via uvx (ephemeral mode). "
264
+ "To get the latest version, simply run 'uvx shotgun-sh' again, "
265
+ "or install permanently with 'uv tool install shotgun-sh'.",
266
+ )
267
+
213
268
  # Perform update
214
269
  try:
215
270
  logger.info(f"Updating shotgun-sh using {method}...")