shotgun-sh 0.2.29.dev2__py3-none-any.whl → 0.6.1.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.
Potentially problematic release.
This version of shotgun-sh might be problematic. Click here for more details.
- shotgun/agents/agent_manager.py +497 -30
- shotgun/agents/cancellation.py +103 -0
- shotgun/agents/common.py +90 -77
- shotgun/agents/config/README.md +0 -1
- shotgun/agents/config/manager.py +52 -8
- shotgun/agents/config/models.py +48 -45
- shotgun/agents/config/provider.py +44 -29
- shotgun/agents/conversation/history/file_content_deduplication.py +66 -43
- shotgun/agents/conversation/history/token_counting/base.py +51 -9
- shotgun/agents/export.py +12 -13
- shotgun/agents/file_read.py +176 -0
- shotgun/agents/messages.py +15 -3
- shotgun/agents/models.py +90 -2
- shotgun/agents/plan.py +12 -13
- shotgun/agents/research.py +13 -10
- shotgun/agents/router/__init__.py +47 -0
- shotgun/agents/router/models.py +384 -0
- shotgun/agents/router/router.py +185 -0
- shotgun/agents/router/tools/__init__.py +18 -0
- shotgun/agents/router/tools/delegation_tools.py +557 -0
- shotgun/agents/router/tools/plan_tools.py +403 -0
- shotgun/agents/runner.py +17 -2
- shotgun/agents/specify.py +12 -13
- shotgun/agents/tasks.py +12 -13
- shotgun/agents/tools/__init__.py +8 -0
- shotgun/agents/tools/codebase/directory_lister.py +27 -39
- shotgun/agents/tools/codebase/file_read.py +26 -35
- shotgun/agents/tools/codebase/query_graph.py +9 -0
- shotgun/agents/tools/codebase/retrieve_code.py +9 -0
- shotgun/agents/tools/file_management.py +81 -3
- shotgun/agents/tools/file_read_tools/__init__.py +7 -0
- shotgun/agents/tools/file_read_tools/multimodal_file_read.py +167 -0
- shotgun/agents/tools/markdown_tools/__init__.py +62 -0
- shotgun/agents/tools/markdown_tools/insert_section.py +148 -0
- shotgun/agents/tools/markdown_tools/models.py +86 -0
- shotgun/agents/tools/markdown_tools/remove_section.py +114 -0
- shotgun/agents/tools/markdown_tools/replace_section.py +119 -0
- shotgun/agents/tools/markdown_tools/utils.py +453 -0
- shotgun/agents/tools/registry.py +41 -0
- shotgun/agents/tools/web_search/__init__.py +1 -2
- shotgun/agents/tools/web_search/gemini.py +1 -3
- shotgun/agents/tools/web_search/openai.py +42 -23
- shotgun/attachments/__init__.py +41 -0
- shotgun/attachments/errors.py +60 -0
- shotgun/attachments/models.py +107 -0
- shotgun/attachments/parser.py +257 -0
- shotgun/attachments/processor.py +193 -0
- shotgun/cli/clear.py +2 -2
- shotgun/cli/codebase/commands.py +181 -65
- shotgun/cli/compact.py +2 -2
- shotgun/cli/context.py +2 -2
- shotgun/cli/run.py +90 -0
- shotgun/cli/spec/backup.py +2 -1
- shotgun/cli/spec/commands.py +2 -0
- shotgun/cli/spec/models.py +18 -0
- shotgun/cli/spec/pull_service.py +122 -68
- shotgun/codebase/__init__.py +2 -0
- shotgun/codebase/benchmarks/__init__.py +35 -0
- shotgun/codebase/benchmarks/benchmark_runner.py +309 -0
- shotgun/codebase/benchmarks/exporters.py +119 -0
- shotgun/codebase/benchmarks/formatters/__init__.py +49 -0
- shotgun/codebase/benchmarks/formatters/base.py +34 -0
- shotgun/codebase/benchmarks/formatters/json_formatter.py +106 -0
- shotgun/codebase/benchmarks/formatters/markdown.py +136 -0
- shotgun/codebase/benchmarks/models.py +129 -0
- shotgun/codebase/core/__init__.py +4 -0
- shotgun/codebase/core/call_resolution.py +91 -0
- shotgun/codebase/core/change_detector.py +11 -6
- shotgun/codebase/core/errors.py +159 -0
- shotgun/codebase/core/extractors/__init__.py +23 -0
- shotgun/codebase/core/extractors/base.py +138 -0
- shotgun/codebase/core/extractors/factory.py +63 -0
- shotgun/codebase/core/extractors/go/__init__.py +7 -0
- shotgun/codebase/core/extractors/go/extractor.py +122 -0
- shotgun/codebase/core/extractors/javascript/__init__.py +7 -0
- shotgun/codebase/core/extractors/javascript/extractor.py +132 -0
- shotgun/codebase/core/extractors/protocol.py +109 -0
- shotgun/codebase/core/extractors/python/__init__.py +7 -0
- shotgun/codebase/core/extractors/python/extractor.py +141 -0
- shotgun/codebase/core/extractors/rust/__init__.py +7 -0
- shotgun/codebase/core/extractors/rust/extractor.py +139 -0
- shotgun/codebase/core/extractors/types.py +15 -0
- shotgun/codebase/core/extractors/typescript/__init__.py +7 -0
- shotgun/codebase/core/extractors/typescript/extractor.py +92 -0
- shotgun/codebase/core/gitignore.py +252 -0
- shotgun/codebase/core/ingestor.py +644 -354
- shotgun/codebase/core/kuzu_compat.py +119 -0
- shotgun/codebase/core/language_config.py +239 -0
- shotgun/codebase/core/manager.py +256 -46
- shotgun/codebase/core/metrics_collector.py +310 -0
- shotgun/codebase/core/metrics_types.py +347 -0
- shotgun/codebase/core/parallel_executor.py +424 -0
- shotgun/codebase/core/work_distributor.py +254 -0
- shotgun/codebase/core/worker.py +768 -0
- shotgun/codebase/indexing_state.py +86 -0
- shotgun/codebase/models.py +94 -0
- shotgun/codebase/service.py +13 -0
- shotgun/exceptions.py +1 -1
- shotgun/main.py +2 -10
- shotgun/prompts/agents/export.j2 +2 -0
- shotgun/prompts/agents/file_read.j2 +48 -0
- shotgun/prompts/agents/partials/common_agent_system_prompt.j2 +20 -28
- shotgun/prompts/agents/partials/content_formatting.j2 +12 -33
- shotgun/prompts/agents/partials/interactive_mode.j2 +9 -32
- shotgun/prompts/agents/partials/router_delegation_mode.j2 +35 -0
- shotgun/prompts/agents/plan.j2 +43 -1
- shotgun/prompts/agents/research.j2 +75 -20
- shotgun/prompts/agents/router.j2 +713 -0
- shotgun/prompts/agents/specify.j2 +94 -4
- shotgun/prompts/agents/state/codebase/codebase_graphs_available.j2 +14 -1
- shotgun/prompts/agents/state/system_state.j2 +24 -15
- shotgun/prompts/agents/tasks.j2 +77 -23
- shotgun/settings.py +44 -0
- shotgun/shotgun_web/shared_specs/upload_pipeline.py +38 -0
- shotgun/tui/app.py +90 -23
- shotgun/tui/commands/__init__.py +9 -1
- shotgun/tui/components/attachment_bar.py +87 -0
- shotgun/tui/components/mode_indicator.py +120 -25
- shotgun/tui/components/prompt_input.py +23 -28
- shotgun/tui/components/status_bar.py +5 -4
- shotgun/tui/dependencies.py +58 -8
- shotgun/tui/protocols.py +37 -0
- shotgun/tui/screens/chat/chat.tcss +24 -1
- shotgun/tui/screens/chat/chat_screen.py +1374 -211
- shotgun/tui/screens/chat/codebase_index_prompt_screen.py +8 -4
- shotgun/tui/screens/chat_screen/attachment_hint.py +40 -0
- shotgun/tui/screens/chat_screen/command_providers.py +0 -97
- shotgun/tui/screens/chat_screen/history/agent_response.py +7 -3
- shotgun/tui/screens/chat_screen/history/chat_history.py +49 -6
- shotgun/tui/screens/chat_screen/history/formatters.py +75 -15
- shotgun/tui/screens/chat_screen/history/partial_response.py +11 -1
- shotgun/tui/screens/chat_screen/history/user_question.py +25 -3
- shotgun/tui/screens/chat_screen/messages.py +219 -0
- shotgun/tui/screens/database_locked_dialog.py +219 -0
- shotgun/tui/screens/database_timeout_dialog.py +158 -0
- shotgun/tui/screens/kuzu_error_dialog.py +135 -0
- shotgun/tui/screens/model_picker.py +14 -9
- shotgun/tui/screens/models.py +11 -0
- shotgun/tui/screens/shotgun_auth.py +50 -0
- shotgun/tui/screens/spec_pull.py +2 -0
- shotgun/tui/state/processing_state.py +19 -0
- 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/tui/widgets/widget_coordinator.py +18 -0
- shotgun/utils/file_system_utils.py +4 -1
- {shotgun_sh-0.2.29.dev2.dist-info → shotgun_sh-0.6.1.dev1.dist-info}/METADATA +88 -34
- shotgun_sh-0.6.1.dev1.dist-info/RECORD +292 -0
- shotgun/cli/export.py +0 -81
- shotgun/cli/plan.py +0 -73
- shotgun/cli/research.py +0 -93
- shotgun/cli/specify.py +0 -70
- shotgun/cli/tasks.py +0 -78
- shotgun/tui/screens/onboarding.py +0 -580
- shotgun_sh-0.2.29.dev2.dist-info/RECORD +0 -229
- {shotgun_sh-0.2.29.dev2.dist-info → shotgun_sh-0.6.1.dev1.dist-info}/WHEEL +0 -0
- {shotgun_sh-0.2.29.dev2.dist-info → shotgun_sh-0.6.1.dev1.dist-info}/entry_points.txt +0 -0
- {shotgun_sh-0.2.29.dev2.dist-info → shotgun_sh-0.6.1.dev1.dist-info}/licenses/LICENSE +0 -0
shotgun/tui/app.py
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
import sys
|
|
1
6
|
from collections.abc import Iterable
|
|
2
|
-
from typing import Any
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from shotgun.codebase.core.errors import DatabaseIssue
|
|
3
11
|
|
|
4
12
|
from textual.app import App, SystemCommand
|
|
5
13
|
from textual.binding import Binding
|
|
@@ -13,6 +21,7 @@ from shotgun.agents.config import (
|
|
|
13
21
|
from shotgun.agents.models import AgentType
|
|
14
22
|
from shotgun.logging_config import get_logger
|
|
15
23
|
from shotgun.tui.containers import TUIContainer
|
|
24
|
+
from shotgun.tui.dependencies import create_default_router_deps
|
|
16
25
|
from shotgun.tui.screens.splash import SplashScreen
|
|
17
26
|
from shotgun.utils.file_system_utils import (
|
|
18
27
|
ensure_shotgun_directory_exists,
|
|
@@ -56,6 +65,7 @@ class ShotgunApp(App[None]):
|
|
|
56
65
|
force_reindex: bool = False,
|
|
57
66
|
show_pull_hint: bool = False,
|
|
58
67
|
pull_version_id: str | None = None,
|
|
68
|
+
pending_db_issues: list[DatabaseIssue] | None = None,
|
|
59
69
|
) -> None:
|
|
60
70
|
super().__init__()
|
|
61
71
|
self.config_manager: ConfigManager = get_config_manager()
|
|
@@ -64,6 +74,9 @@ class ShotgunApp(App[None]):
|
|
|
64
74
|
self.force_reindex = force_reindex
|
|
65
75
|
self.show_pull_hint = show_pull_hint
|
|
66
76
|
self.pull_version_id = pull_version_id
|
|
77
|
+
# Database issues detected at startup (locked, corrupted, timeout)
|
|
78
|
+
# These will be shown to the user via dialogs when ChatScreen mounts
|
|
79
|
+
self.pending_db_issues = pending_db_issues or []
|
|
67
80
|
|
|
68
81
|
# Initialize dependency injection container
|
|
69
82
|
self.container = TUIContainer()
|
|
@@ -166,13 +179,11 @@ class ShotgunApp(App[None]):
|
|
|
166
179
|
return
|
|
167
180
|
|
|
168
181
|
# Create ChatScreen with all dependencies injected from container
|
|
169
|
-
# Get the default agent mode (
|
|
170
|
-
agent_mode = AgentType.
|
|
182
|
+
# Get the default agent mode (ROUTER)
|
|
183
|
+
agent_mode = AgentType.ROUTER
|
|
171
184
|
|
|
172
|
-
# Create
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
agent_deps = await create_default_tui_deps()
|
|
185
|
+
# Create RouterDeps asynchronously (get_provider_model is now async)
|
|
186
|
+
agent_deps = await create_default_router_deps()
|
|
176
187
|
|
|
177
188
|
# Create AgentManager with async initialization
|
|
178
189
|
agent_manager = AgentManager(deps=agent_deps, initial_type=agent_mode)
|
|
@@ -250,6 +261,22 @@ class ShotgunApp(App[None]):
|
|
|
250
261
|
self.push_screen(GitHubIssueScreen())
|
|
251
262
|
|
|
252
263
|
|
|
264
|
+
def _log_startup_info() -> None:
|
|
265
|
+
"""Log startup information for debugging purposes."""
|
|
266
|
+
# Import here to avoid circular import (shotgun.__init__ imports from submodules)
|
|
267
|
+
from shotgun import __version__
|
|
268
|
+
|
|
269
|
+
logger.info("=" * 60)
|
|
270
|
+
logger.info("Shotgun TUI Starting")
|
|
271
|
+
logger.info("=" * 60)
|
|
272
|
+
logger.info(f" Version: {__version__}")
|
|
273
|
+
logger.info(f" Python: {sys.version.split()[0]}")
|
|
274
|
+
logger.info(f" Platform: {platform.system()} {platform.release()}")
|
|
275
|
+
logger.info(f" Architecture: {platform.machine()}")
|
|
276
|
+
logger.info(f" Working Directory: {os.getcwd()}")
|
|
277
|
+
logger.info("=" * 60)
|
|
278
|
+
|
|
279
|
+
|
|
253
280
|
def run(
|
|
254
281
|
no_update_check: bool = False,
|
|
255
282
|
continue_session: bool = False,
|
|
@@ -266,24 +293,54 @@ def run(
|
|
|
266
293
|
show_pull_hint: If True, show hint about recently pulled spec.
|
|
267
294
|
pull_version_id: If provided, pull this spec version before showing ChatScreen.
|
|
268
295
|
"""
|
|
269
|
-
#
|
|
270
|
-
|
|
296
|
+
# Log startup information
|
|
297
|
+
_log_startup_info()
|
|
298
|
+
|
|
299
|
+
# Detect database issues BEFORE starting the TUI (but don't auto-delete)
|
|
300
|
+
# Issues will be presented to the user via dialogs once the TUI is running
|
|
271
301
|
import asyncio
|
|
272
302
|
|
|
303
|
+
from shotgun.codebase.core.errors import KuzuErrorType
|
|
273
304
|
from shotgun.codebase.core.manager import CodebaseGraphManager
|
|
274
305
|
from shotgun.utils import get_shotgun_home
|
|
275
306
|
|
|
276
307
|
storage_dir = get_shotgun_home() / "codebases"
|
|
277
308
|
manager = CodebaseGraphManager(storage_dir)
|
|
278
309
|
|
|
310
|
+
pending_db_issues: list[DatabaseIssue] = []
|
|
279
311
|
try:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
312
|
+
# First pass: 10-second timeout
|
|
313
|
+
issues = asyncio.run(manager.detect_database_issues(timeout_seconds=10.0))
|
|
314
|
+
if issues:
|
|
315
|
+
# Categorize issues for logging
|
|
316
|
+
for issue in issues:
|
|
317
|
+
logger.info(
|
|
318
|
+
f"Detected database issue: {issue.graph_id} - "
|
|
319
|
+
f"{issue.error_type.value}: {issue.message}"
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
# Only pass issues that require user interaction to the TUI
|
|
323
|
+
# Schema issues (incomplete builds) can be auto-cleaned silently
|
|
324
|
+
user_facing_issues = [
|
|
325
|
+
i
|
|
326
|
+
for i in issues
|
|
327
|
+
if i.error_type
|
|
328
|
+
in (
|
|
329
|
+
KuzuErrorType.LOCKED,
|
|
330
|
+
KuzuErrorType.CORRUPTION,
|
|
331
|
+
KuzuErrorType.TIMEOUT,
|
|
332
|
+
)
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
# Auto-delete schema issues (incomplete builds) - safe to remove
|
|
336
|
+
schema_issues = [i for i in issues if i.error_type == KuzuErrorType.SCHEMA]
|
|
337
|
+
for issue in schema_issues:
|
|
338
|
+
asyncio.run(manager.delete_database(issue.graph_id))
|
|
339
|
+
logger.info(f"Auto-removed incomplete database: {issue.graph_id}")
|
|
340
|
+
|
|
341
|
+
pending_db_issues = user_facing_issues
|
|
285
342
|
except Exception as e:
|
|
286
|
-
logger.error(f"Failed to
|
|
343
|
+
logger.error(f"Failed to detect database issues: {e}")
|
|
287
344
|
# Continue anyway - the TUI can still function
|
|
288
345
|
|
|
289
346
|
app = ShotgunApp(
|
|
@@ -292,6 +349,7 @@ def run(
|
|
|
292
349
|
force_reindex=force_reindex,
|
|
293
350
|
show_pull_hint=show_pull_hint,
|
|
294
351
|
pull_version_id=pull_version_id,
|
|
352
|
+
pending_db_issues=pending_db_issues,
|
|
295
353
|
)
|
|
296
354
|
app.run(inline_no_clear=True)
|
|
297
355
|
|
|
@@ -314,12 +372,14 @@ def serve(
|
|
|
314
372
|
continue_session: If True, continue from previous conversation.
|
|
315
373
|
force_reindex: If True, force re-indexing of codebase (ignores existing index).
|
|
316
374
|
"""
|
|
317
|
-
#
|
|
318
|
-
#
|
|
375
|
+
# Detect database issues BEFORE starting the TUI
|
|
376
|
+
# Note: In serve mode, issues are logged but user interaction happens in
|
|
377
|
+
# the spawned process via run()
|
|
319
378
|
import asyncio
|
|
320
379
|
|
|
321
380
|
from textual_serve.server import Server
|
|
322
381
|
|
|
382
|
+
from shotgun.codebase.core.errors import KuzuErrorType
|
|
323
383
|
from shotgun.codebase.core.manager import CodebaseGraphManager
|
|
324
384
|
from shotgun.utils import get_shotgun_home
|
|
325
385
|
|
|
@@ -327,13 +387,20 @@ def serve(
|
|
|
327
387
|
manager = CodebaseGraphManager(storage_dir)
|
|
328
388
|
|
|
329
389
|
try:
|
|
330
|
-
|
|
331
|
-
if
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
390
|
+
issues = asyncio.run(manager.detect_database_issues(timeout_seconds=10.0))
|
|
391
|
+
if issues:
|
|
392
|
+
for issue in issues:
|
|
393
|
+
logger.info(
|
|
394
|
+
f"Detected database issue: {issue.graph_id} - "
|
|
395
|
+
f"{issue.error_type.value}: {issue.message}"
|
|
396
|
+
)
|
|
397
|
+
# Auto-delete only schema issues (incomplete builds)
|
|
398
|
+
schema_issues = [i for i in issues if i.error_type == KuzuErrorType.SCHEMA]
|
|
399
|
+
for issue in schema_issues:
|
|
400
|
+
asyncio.run(manager.delete_database(issue.graph_id))
|
|
401
|
+
logger.info(f"Auto-removed incomplete database: {issue.graph_id}")
|
|
335
402
|
except Exception as e:
|
|
336
|
-
logger.error(f"Failed to
|
|
403
|
+
logger.error(f"Failed to detect database issues: {e}")
|
|
337
404
|
# Continue anyway - the TUI can still function
|
|
338
405
|
|
|
339
406
|
# Create a new event loop after asyncio.run() closes the previous one
|
shotgun/tui/commands/__init__.py
CHANGED
|
@@ -54,10 +54,18 @@ class CommandHandler:
|
|
|
54
54
|
**Commands:**
|
|
55
55
|
• `/help` - Show this help message
|
|
56
56
|
|
|
57
|
+
**Shell Commands:**
|
|
58
|
+
• `!<command>` - Execute shell commands directly (e.g., `!ls`, `!git status`)
|
|
59
|
+
- Commands run in your current working directory
|
|
60
|
+
- Output is displayed in the chat (not sent to AI)
|
|
61
|
+
- Commands are NOT added to conversation history
|
|
62
|
+
- Leading whitespace is allowed: ` !echo hi` works
|
|
63
|
+
- Note: `!!` is treated as `!` (no history expansion in this version)
|
|
64
|
+
|
|
57
65
|
**Keyboard Shortcuts:**
|
|
58
66
|
|
|
59
67
|
* `Enter` - Send message
|
|
60
|
-
*
|
|
68
|
+
* `/` - Open command palette (for usage, context, and other commands)
|
|
61
69
|
* `Shift+Tab` - Cycle agent modes
|
|
62
70
|
* `Ctrl+C` - Quit application
|
|
63
71
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Attachment bar widget for showing pending file attachment."""
|
|
2
|
+
|
|
3
|
+
from textual.app import ComposeResult
|
|
4
|
+
from textual.css.query import NoMatches
|
|
5
|
+
from textual.reactive import reactive
|
|
6
|
+
from textual.widget import Widget
|
|
7
|
+
from textual.widgets import Static
|
|
8
|
+
|
|
9
|
+
from shotgun.attachments import (
|
|
10
|
+
AttachmentBarState,
|
|
11
|
+
FileAttachment,
|
|
12
|
+
format_file_size,
|
|
13
|
+
get_attachment_icon,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AttachmentBar(Widget):
|
|
18
|
+
"""Widget showing pending attachment above input.
|
|
19
|
+
|
|
20
|
+
Displays format: [icon filename.ext (size)]
|
|
21
|
+
Hidden when no attachment is pending.
|
|
22
|
+
|
|
23
|
+
Styles defined in chat.tcss.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
state: reactive[AttachmentBarState] = reactive(AttachmentBarState, init=False)
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
name: str | None = None,
|
|
32
|
+
id: str | None = None,
|
|
33
|
+
classes: str | None = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
"""Initialize the attachment bar.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
name: Optional widget name.
|
|
39
|
+
id: Optional widget ID.
|
|
40
|
+
classes: Optional CSS classes.
|
|
41
|
+
"""
|
|
42
|
+
super().__init__(name=name, id=id, classes=classes)
|
|
43
|
+
self.state = AttachmentBarState(attachment=None)
|
|
44
|
+
self.add_class("hidden")
|
|
45
|
+
|
|
46
|
+
def compose(self) -> ComposeResult:
|
|
47
|
+
"""Compose the attachment bar widget."""
|
|
48
|
+
yield Static("", id="attachment-display")
|
|
49
|
+
|
|
50
|
+
def update_attachment(self, attachment: FileAttachment | None) -> None:
|
|
51
|
+
"""Update the displayed attachment.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
attachment: FileAttachment to display, or None to hide bar.
|
|
55
|
+
"""
|
|
56
|
+
self.state = AttachmentBarState(attachment=attachment)
|
|
57
|
+
|
|
58
|
+
if attachment is None:
|
|
59
|
+
self.add_class("hidden")
|
|
60
|
+
else:
|
|
61
|
+
self.remove_class("hidden")
|
|
62
|
+
self._refresh_display()
|
|
63
|
+
|
|
64
|
+
def _refresh_display(self) -> None:
|
|
65
|
+
"""Refresh the attachment display text."""
|
|
66
|
+
attachment = self.state.attachment
|
|
67
|
+
if attachment is None:
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
icon = get_attachment_icon(attachment.file_type)
|
|
71
|
+
size_str = format_file_size(attachment.file_size_bytes)
|
|
72
|
+
display_text = f"[{icon} {attachment.file_name} ({size_str})]"
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
display_widget = self.query_one("#attachment-display", Static)
|
|
76
|
+
display_widget.update(display_text)
|
|
77
|
+
except NoMatches:
|
|
78
|
+
pass # Widget not mounted yet
|
|
79
|
+
|
|
80
|
+
def watch_state(self, new_state: AttachmentBarState) -> None:
|
|
81
|
+
"""React to state changes.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
new_state: The new attachment bar state.
|
|
85
|
+
"""
|
|
86
|
+
if new_state.attachment is not None:
|
|
87
|
+
self._refresh_display()
|
|
@@ -1,20 +1,68 @@
|
|
|
1
1
|
"""Widget to display the current agent mode."""
|
|
2
2
|
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
|
|
3
5
|
from textual.widget import Widget
|
|
4
6
|
|
|
5
7
|
from shotgun.agents.models import AgentType
|
|
6
|
-
from shotgun.
|
|
8
|
+
from shotgun.agents.router.models import RouterMode
|
|
9
|
+
from shotgun.tui.protocols import (
|
|
10
|
+
ActiveSubAgentProvider,
|
|
11
|
+
QAStateProvider,
|
|
12
|
+
RouterModeProvider,
|
|
13
|
+
)
|
|
7
14
|
from shotgun.tui.utils.mode_progress import PlaceholderHints
|
|
8
15
|
|
|
9
16
|
|
|
17
|
+
class RouterModeCssClass(StrEnum):
|
|
18
|
+
"""CSS class names for router mode styling."""
|
|
19
|
+
|
|
20
|
+
PLANNING = "mode-planning"
|
|
21
|
+
DRAFTING = "mode-drafting"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Shared display name mapping for agent types
|
|
25
|
+
AGENT_DISPLAY_NAMES: dict[AgentType, str] = {
|
|
26
|
+
AgentType.RESEARCH: "Research",
|
|
27
|
+
AgentType.SPECIFY: "Specify",
|
|
28
|
+
AgentType.PLAN: "Planning",
|
|
29
|
+
AgentType.TASKS: "Tasks",
|
|
30
|
+
AgentType.EXPORT: "Export",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Mode descriptions for legacy agent display
|
|
34
|
+
AGENT_DESCRIPTIONS: dict[AgentType, str] = {
|
|
35
|
+
AgentType.RESEARCH: "Research topics with web search and synthesize findings",
|
|
36
|
+
AgentType.PLAN: "Create comprehensive, actionable plans with milestones",
|
|
37
|
+
AgentType.TASKS: "Generate specific, actionable tasks from research and plans",
|
|
38
|
+
AgentType.SPECIFY: "Create detailed specifications and requirements documents",
|
|
39
|
+
AgentType.EXPORT: "Export artifacts and findings to various formats",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
10
43
|
class ModeIndicator(Widget):
|
|
11
|
-
"""Widget to display the current agent mode.
|
|
44
|
+
"""Widget to display the current agent mode.
|
|
45
|
+
|
|
46
|
+
For router mode, displays:
|
|
47
|
+
- Idle: "📋 Planning mode" or "✍️ Drafting mode"
|
|
48
|
+
- During execution: "📋 Planning → Research" format
|
|
49
|
+
|
|
50
|
+
For legacy agents, displays the agent name and description.
|
|
51
|
+
"""
|
|
12
52
|
|
|
13
53
|
DEFAULT_CSS = """
|
|
14
54
|
ModeIndicator {
|
|
15
55
|
text-wrap: wrap;
|
|
16
56
|
padding-left: 1;
|
|
17
57
|
}
|
|
58
|
+
|
|
59
|
+
ModeIndicator.mode-planning {
|
|
60
|
+
/* Planning mode styling - blue/cyan accent */
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ModeIndicator.mode-drafting {
|
|
64
|
+
/* Drafting mode styling - green accent */
|
|
65
|
+
}
|
|
18
66
|
"""
|
|
19
67
|
|
|
20
68
|
def __init__(self, mode: AgentType) -> None:
|
|
@@ -29,41 +77,88 @@ class ModeIndicator(Widget):
|
|
|
29
77
|
|
|
30
78
|
def render(self) -> str:
|
|
31
79
|
"""Render the mode indicator."""
|
|
32
|
-
# Check if in Q&A mode first
|
|
80
|
+
# Check if in Q&A mode first - takes priority
|
|
33
81
|
if isinstance(self.screen, QAStateProvider) and self.screen.qa_mode:
|
|
34
82
|
return (
|
|
35
83
|
"[bold $text-accent]Q&A mode[/]"
|
|
36
84
|
"[$foreground-muted] (Answer the clarifying questions or ESC to cancel)[/]"
|
|
37
85
|
)
|
|
38
86
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
AgentType.TASKS: "Tasks",
|
|
43
|
-
AgentType.SPECIFY: "Specify",
|
|
44
|
-
AgentType.EXPORT: "Export",
|
|
45
|
-
}
|
|
46
|
-
mode_description = {
|
|
47
|
-
AgentType.RESEARCH: (
|
|
48
|
-
"Research topics with web search and synthesize findings"
|
|
49
|
-
),
|
|
50
|
-
AgentType.PLAN: "Create comprehensive, actionable plans with milestones",
|
|
51
|
-
AgentType.TASKS: (
|
|
52
|
-
"Generate specific, actionable tasks from research and plans"
|
|
53
|
-
),
|
|
54
|
-
AgentType.SPECIFY: (
|
|
55
|
-
"Create detailed specifications and requirements documents"
|
|
56
|
-
),
|
|
57
|
-
AgentType.EXPORT: "Export artifacts and findings to various formats",
|
|
58
|
-
}
|
|
87
|
+
# Router mode display
|
|
88
|
+
if self.mode == AgentType.ROUTER:
|
|
89
|
+
return self._render_router_mode()
|
|
59
90
|
|
|
60
|
-
|
|
61
|
-
|
|
91
|
+
# Legacy agent mode display
|
|
92
|
+
return self._render_legacy_mode()
|
|
93
|
+
|
|
94
|
+
def _render_router_mode(self) -> str:
|
|
95
|
+
"""Render the router mode indicator.
|
|
96
|
+
|
|
97
|
+
Shows:
|
|
98
|
+
- "📋 Planning mode" or "✍️ Drafting mode" when idle
|
|
99
|
+
- "📋 Planning → Research" format when sub-agent is executing
|
|
100
|
+
"""
|
|
101
|
+
# Get router mode from screen
|
|
102
|
+
router_mode: str | None = None
|
|
103
|
+
if isinstance(self.screen, RouterModeProvider):
|
|
104
|
+
router_mode = self.screen.router_mode
|
|
105
|
+
|
|
106
|
+
# Get active sub-agent from screen
|
|
107
|
+
active_sub_agent: AgentType | None = None
|
|
108
|
+
if isinstance(self.screen, ActiveSubAgentProvider):
|
|
109
|
+
sub_agent_str = self.screen.active_sub_agent
|
|
110
|
+
if sub_agent_str:
|
|
111
|
+
# Convert string back to AgentType enum
|
|
112
|
+
try:
|
|
113
|
+
active_sub_agent = AgentType(sub_agent_str)
|
|
114
|
+
except ValueError:
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
# Determine mode display using RouterMode enum
|
|
118
|
+
if router_mode == RouterMode.DRAFTING.value:
|
|
119
|
+
icon = "✍️"
|
|
120
|
+
mode_name = "Drafting"
|
|
121
|
+
description = "Auto-execute without confirmation"
|
|
122
|
+
css_class = RouterModeCssClass.DRAFTING
|
|
123
|
+
else:
|
|
124
|
+
# Default to planning mode
|
|
125
|
+
icon = "📋"
|
|
126
|
+
mode_name = "Planning"
|
|
127
|
+
description = "Review plans before execution"
|
|
128
|
+
css_class = RouterModeCssClass.PLANNING
|
|
129
|
+
|
|
130
|
+
# Update CSS class for styling
|
|
131
|
+
self.set_classes(css_class)
|
|
132
|
+
|
|
133
|
+
# Add sub-agent suffix if executing
|
|
134
|
+
if active_sub_agent:
|
|
135
|
+
# Use shared display name mapping
|
|
136
|
+
sub_agent_name = AGENT_DISPLAY_NAMES.get(
|
|
137
|
+
active_sub_agent, active_sub_agent.value.title()
|
|
138
|
+
)
|
|
139
|
+
return f"[bold $text-accent]{icon} {mode_name} → {sub_agent_name}[/]"
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
f"[bold $text-accent]{icon} {mode_name} mode[/]"
|
|
143
|
+
f"[$foreground-muted] ({description})[/]"
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def _render_legacy_mode(self) -> str:
|
|
147
|
+
"""Render the legacy agent mode indicator.
|
|
148
|
+
|
|
149
|
+
Shows the agent name with description and content status.
|
|
150
|
+
"""
|
|
151
|
+
mode_title = AGENT_DISPLAY_NAMES.get(self.mode, self.mode.value.title())
|
|
152
|
+
description = AGENT_DESCRIPTIONS.get(self.mode, "")
|
|
62
153
|
|
|
63
154
|
# Check if mode has content
|
|
64
155
|
has_content = self.progress_checker.has_mode_content(self.mode)
|
|
65
156
|
status_icon = " ✓" if has_content else ""
|
|
66
157
|
|
|
158
|
+
# Clear any router mode CSS classes
|
|
159
|
+
self.remove_class(RouterModeCssClass.PLANNING)
|
|
160
|
+
self.remove_class(RouterModeCssClass.DRAFTING)
|
|
161
|
+
|
|
67
162
|
return (
|
|
68
163
|
f"[bold $text-accent]{mode_title}{status_icon} mode[/]"
|
|
69
164
|
f"[$foreground-muted] ({description})[/]"
|
|
@@ -27,43 +27,38 @@ class PromptInput(TextArea):
|
|
|
27
27
|
super().__init__()
|
|
28
28
|
self.text = text
|
|
29
29
|
|
|
30
|
+
class OpenCommandPalette(Message):
|
|
31
|
+
"""Request to open the command palette."""
|
|
32
|
+
|
|
30
33
|
def action_submit(self) -> None:
|
|
31
34
|
"""An action to submit the text."""
|
|
32
35
|
self.post_message(self.Submitted(self.text))
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
"""Handle key presses
|
|
36
|
-
|
|
37
|
-
# Don't handle Enter key here - let the binding handle it
|
|
37
|
+
def on_key(self, event: events.Key) -> None:
|
|
38
|
+
"""Handle key presses for special actions."""
|
|
39
|
+
# Submit on Enter
|
|
38
40
|
if event.key == "enter":
|
|
41
|
+
event.stop()
|
|
42
|
+
event.prevent_default()
|
|
39
43
|
self.action_submit()
|
|
40
|
-
|
|
41
|
-
self._restart_blink()
|
|
42
|
-
|
|
43
|
-
if self.read_only:
|
|
44
44
|
return
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
event.stop()
|
|
53
|
-
event.prevent_default()
|
|
54
|
-
self.screen.focus_next()
|
|
55
|
-
return
|
|
56
|
-
if self.indent_type == "tabs":
|
|
57
|
-
insert_values["tab"] = "\t"
|
|
58
|
-
else:
|
|
59
|
-
insert_values["tab"] = " " * self._find_columns_to_next_tab_stop()
|
|
46
|
+
# Detect "/" as first character to trigger command palette
|
|
47
|
+
if event.character == "/" and not self.text.strip():
|
|
48
|
+
event.stop()
|
|
49
|
+
event.prevent_default()
|
|
50
|
+
self.post_message(self.OpenCommandPalette())
|
|
51
|
+
return
|
|
60
52
|
|
|
61
|
-
|
|
53
|
+
# Handle ctrl+j for newline (since enter is for submit)
|
|
54
|
+
if event.key == "ctrl+j":
|
|
62
55
|
event.stop()
|
|
63
56
|
event.prevent_default()
|
|
64
|
-
insert = insert_values.get(key, event.character)
|
|
65
|
-
# `insert` is not None because event.character cannot be
|
|
66
|
-
# None because we've checked that it's printable.
|
|
67
|
-
assert insert is not None # noqa: S101
|
|
68
57
|
start, end = self.selection
|
|
69
|
-
self.
|
|
58
|
+
self.replace(
|
|
59
|
+
"\n",
|
|
60
|
+
start,
|
|
61
|
+
end,
|
|
62
|
+
maintain_selection_offset=False,
|
|
63
|
+
)
|
|
64
|
+
return
|
|
@@ -37,12 +37,13 @@ class StatusBar(Widget):
|
|
|
37
37
|
return (
|
|
38
38
|
"[$foreground-muted][bold $text]esc[/] to stop • "
|
|
39
39
|
"[bold $text]enter[/] to send • [bold $text]ctrl+j[/] for newline • "
|
|
40
|
-
"[bold $text]
|
|
41
|
-
"/
|
|
40
|
+
"[bold $text]/[/] command palette • "
|
|
41
|
+
"[bold $text]shift+tab[/] toggle mode[/]"
|
|
42
42
|
)
|
|
43
43
|
else:
|
|
44
44
|
return (
|
|
45
45
|
"[$foreground-muted][bold $text]enter[/] to send • "
|
|
46
|
-
"[bold $text]ctrl+j[/] for newline •
|
|
47
|
-
"[bold $text]
|
|
46
|
+
"[bold $text]ctrl+j[/] for newline • "
|
|
47
|
+
"[bold $text]/[/] command palette • "
|
|
48
|
+
"[bold $text]shift+tab[/] toggle mode[/]"
|
|
48
49
|
)
|
shotgun/tui/dependencies.py
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
1
|
"""Dependency creation utilities for TUI components."""
|
|
2
2
|
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
3
5
|
from pydantic_ai import RunContext
|
|
4
6
|
|
|
5
7
|
from shotgun.agents.config import get_provider_model
|
|
8
|
+
from shotgun.agents.config.models import ModelConfig
|
|
6
9
|
from shotgun.agents.models import AgentDeps
|
|
10
|
+
from shotgun.agents.router.models import RouterDeps, RouterMode
|
|
11
|
+
from shotgun.codebase.service import CodebaseService
|
|
7
12
|
from shotgun.tui.filtered_codebase_service import FilteredCodebaseService
|
|
8
13
|
from shotgun.utils import get_shotgun_home
|
|
9
14
|
|
|
10
15
|
|
|
16
|
+
async def _get_tui_config() -> tuple[ModelConfig, CodebaseService]:
|
|
17
|
+
"""Get common TUI configuration components.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Tuple of (model_config, codebase_service) for TUI deps.
|
|
21
|
+
"""
|
|
22
|
+
model_config = await get_provider_model()
|
|
23
|
+
storage_dir = get_shotgun_home() / "codebases"
|
|
24
|
+
codebase_service = FilteredCodebaseService(storage_dir)
|
|
25
|
+
return model_config, codebase_service
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _placeholder_system_prompt_fn(ctx: RunContext[Any]) -> str:
|
|
29
|
+
"""Placeholder system prompt that should never be called.
|
|
30
|
+
|
|
31
|
+
Agents provide their own system_prompt_fn via their create functions.
|
|
32
|
+
This placeholder exists only to satisfy the AgentDeps requirement.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
RuntimeError: Always, as this should never be invoked.
|
|
36
|
+
"""
|
|
37
|
+
raise RuntimeError(
|
|
38
|
+
"This should not be called - agents provide their own system_prompt_fn"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
11
42
|
async def create_default_tui_deps() -> AgentDeps:
|
|
12
43
|
"""Create default AgentDeps for TUI components.
|
|
13
44
|
|
|
@@ -21,14 +52,7 @@ async def create_default_tui_deps() -> AgentDeps:
|
|
|
21
52
|
Returns:
|
|
22
53
|
Configured AgentDeps instance ready for TUI use.
|
|
23
54
|
"""
|
|
24
|
-
model_config = await
|
|
25
|
-
storage_dir = get_shotgun_home() / "codebases"
|
|
26
|
-
codebase_service = FilteredCodebaseService(storage_dir)
|
|
27
|
-
|
|
28
|
-
def _placeholder_system_prompt_fn(ctx: RunContext[AgentDeps]) -> str:
|
|
29
|
-
raise RuntimeError(
|
|
30
|
-
"This should not be called - agents provide their own system_prompt_fn"
|
|
31
|
-
)
|
|
55
|
+
model_config, codebase_service = await _get_tui_config()
|
|
32
56
|
|
|
33
57
|
return AgentDeps(
|
|
34
58
|
interactive_mode=True,
|
|
@@ -37,3 +61,29 @@ async def create_default_tui_deps() -> AgentDeps:
|
|
|
37
61
|
codebase_service=codebase_service,
|
|
38
62
|
system_prompt_fn=_placeholder_system_prompt_fn,
|
|
39
63
|
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def create_default_router_deps() -> RouterDeps:
|
|
67
|
+
"""Create default RouterDeps for TUI components with router mode.
|
|
68
|
+
|
|
69
|
+
This creates a RouterDeps configuration suitable for interactive
|
|
70
|
+
TUI usage with:
|
|
71
|
+
- Router mode always starts in PLANNING (not persisted)
|
|
72
|
+
- Interactive mode enabled
|
|
73
|
+
- TUI context flag set
|
|
74
|
+
- Filtered codebase service (restricted to CWD)
|
|
75
|
+
- Placeholder system prompt (router provides its own)
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Configured RouterDeps instance ready for TUI use.
|
|
79
|
+
"""
|
|
80
|
+
model_config, codebase_service = await _get_tui_config()
|
|
81
|
+
|
|
82
|
+
return RouterDeps(
|
|
83
|
+
interactive_mode=True,
|
|
84
|
+
is_tui_context=True,
|
|
85
|
+
llm_model=model_config,
|
|
86
|
+
codebase_service=codebase_service,
|
|
87
|
+
system_prompt_fn=_placeholder_system_prompt_fn,
|
|
88
|
+
router_mode=RouterMode.PLANNING,
|
|
89
|
+
)
|