Skip to content

Commit 3af0ea6

Browse files
author
jzhu
committed
fix: reorganize UI helper imports and maintain backward compatibility
1 parent 94dbedf commit 3af0ea6

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

code_assistant_manager/tools/__init__.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import subprocess
44
from pathlib import Path
5-
from typing import Dict, Type
5+
from typing import Dict, Optional, Tuple, Type
66

77
from ..config import ConfigManager
88
from ..endpoints import EndpointManager
@@ -36,6 +36,26 @@
3636
# Backwards-compat: expose UI helpers that used to be available from code_assistant_manager.tools
3737

3838
# Expose model selector functions
39+
from ..menu.menus import display_centered_menu, select_two_models # noqa: F401
40+
41+
42+
def select_model(
43+
models: list[str], prompt: str = "Select a model:"
44+
) -> Tuple[bool, Optional[str]]:
45+
"""Backward-compatible wrapper for model selection.
46+
47+
Args:
48+
models: List of available models
49+
prompt: Display prompt for selection
50+
51+
Returns:
52+
Tuple of (success, selected_model)
53+
"""
54+
success, idx = display_centered_menu(prompt, models, "Cancel")
55+
if success and idx is not None:
56+
return True, models[idx]
57+
return False, None
58+
3959

4060
# Backwards-compatible exports: expose tool classes at package level
4161
from .claude import ClaudeTool # noqa: F401
@@ -45,18 +65,18 @@
4565
from .crush import CrushTool # noqa: F401
4666
from .cursor import CursorTool # noqa: F401
4767
from .droid import DroidTool # noqa: F401
48-
from .gemini import GeminiTool # noqa: F401
49-
from .iflow import IfLowTool # noqa: F401
50-
from .neovate import NeovateTool # noqa: F401
51-
from .qodercli import QoderCLITool # noqa: F401
52-
from .qwen import QwenTool # noqa: F401
53-
from .zed import ZedTool # noqa: F401
5468

5569
# Expose endpoint display functions
5670
from .endpoint_display import ( # noqa: F401
5771
display_all_tool_endpoints,
5872
display_tool_endpoints,
5973
)
74+
from .gemini import GeminiTool # noqa: F401
75+
from .iflow import IfLowTool # noqa: F401
76+
from .neovate import NeovateTool # noqa: F401
77+
from .qodercli import QoderCLITool # noqa: F401
78+
from .qwen import QwenTool # noqa: F401
79+
from .zed import ZedTool # noqa: F401
6080

6181
# Backwards-compat: expose commonly patched names used in tests
6282
# so tests that patch code_assistant_manager.tools.<name> continue to work.

code_assistant_manager/ui.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import subprocess
66
from typing import Tuple
77

8+
from .menu.base import Colors
9+
from .menu.menus import display_centered_menu, select_two_models
10+
from .tools import select_model
11+
812

913
def get_terminal_size() -> Tuple[int, int]:
1014
"""Get terminal width and height."""

tests/test_ui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_display_centered_menu_many_items(self, mock_clear, mock_input):
153153
class TestSelectModel:
154154
"""Test select_model function."""
155155

156-
@patch("code_assistant_manager.menu.menus.display_centered_menu")
156+
@patch("code_assistant_manager.tools.display_centered_menu")
157157
def test_select_model_success(self, mock_menu):
158158
"""Test successful model selection."""
159159
mock_menu.return_value = (True, 1)
@@ -162,7 +162,7 @@ def test_select_model_success(self, mock_menu):
162162
assert success is True
163163
assert model == "gpt-3.5"
164164

165-
@patch("code_assistant_manager.menu.menus.display_centered_menu")
165+
@patch("code_assistant_manager.tools.display_centered_menu")
166166
def test_select_model_cancelled(self, mock_menu):
167167
"""Test cancelled model selection."""
168168
mock_menu.return_value = (False, None)
@@ -171,7 +171,7 @@ def test_select_model_cancelled(self, mock_menu):
171171
assert success is False
172172
assert model is None
173173

174-
@patch("code_assistant_manager.menu.menus.display_centered_menu")
174+
@patch("code_assistant_manager.tools.display_centered_menu")
175175
def test_select_model_custom_prompt(self, mock_menu):
176176
"""Test model selection with custom prompt."""
177177
mock_menu.return_value = (True, 0)

0 commit comments

Comments
 (0)