janito 0.7.0__py3-none-any.whl → 0.8.0__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 (112) hide show
  1. janito/__main__.py +127 -141
  2. janito/agents/__init__.py +22 -22
  3. janito/agents/agent.py +24 -27
  4. janito/agents/claudeai.py +41 -45
  5. janito/agents/deepseekai.py +47 -0
  6. janito/change/applied_blocks.py +34 -0
  7. janito/change/applier.py +167 -0
  8. janito/change/edit_blocks.py +148 -0
  9. janito/change/finder.py +72 -0
  10. janito/change/request.py +144 -0
  11. janito/change/validator.py +87 -269
  12. janito/change/view/content.py +63 -0
  13. janito/change/{viewer → view}/diff.py +44 -43
  14. janito/change/view/panels.py +201 -0
  15. janito/change/view/sections.py +69 -0
  16. janito/change/view/styling.py +140 -0
  17. janito/change/view/summary.py +37 -0
  18. janito/change/{viewer → view}/themes.py +62 -55
  19. janito/change/view/viewer.py +59 -0
  20. janito/cli/__init__.py +1 -1
  21. janito/cli/commands.py +68 -88
  22. janito/cli/functions.py +66 -111
  23. janito/common.py +132 -79
  24. janito/config.py +99 -101
  25. janito/data/change_prompt.txt +81 -0
  26. janito/data/system_prompt.txt +3 -0
  27. janito/qa.py +56 -57
  28. janito/version.py +22 -22
  29. janito/workspace/__init__.py +8 -6
  30. janito/workspace/analysis.py +120 -120
  31. janito/workspace/{types.py → models.py} +97 -98
  32. janito/workspace/show.py +115 -141
  33. janito/workspace/stats.py +42 -43
  34. janito/workspace/workset.py +135 -108
  35. janito/workspace/workspace.py +335 -114
  36. janito-0.8.0.dist-info/METADATA +106 -0
  37. janito-0.8.0.dist-info/RECORD +40 -0
  38. {janito-0.7.0.dist-info → janito-0.8.0.dist-info}/licenses/LICENSE +20 -20
  39. janito/__init__.py +0 -2
  40. janito/agents/openai.py +0 -57
  41. janito/agents/test.py +0 -34
  42. janito/change/__init__.py +0 -32
  43. janito/change/__main__.py +0 -0
  44. janito/change/analysis/__init__.py +0 -23
  45. janito/change/analysis/__main__.py +0 -7
  46. janito/change/analysis/analyze.py +0 -62
  47. janito/change/analysis/formatting.py +0 -78
  48. janito/change/analysis/options.py +0 -81
  49. janito/change/analysis/prompts.py +0 -90
  50. janito/change/analysis/view/__init__.py +0 -9
  51. janito/change/analysis/view/terminal.py +0 -181
  52. janito/change/applier/__init__.py +0 -5
  53. janito/change/applier/file.py +0 -58
  54. janito/change/applier/main.py +0 -156
  55. janito/change/applier/text.py +0 -247
  56. janito/change/applier/workspace_dir.py +0 -58
  57. janito/change/core.py +0 -124
  58. janito/change/history.py +0 -44
  59. janito/change/operations.py +0 -7
  60. janito/change/parser.py +0 -287
  61. janito/change/play.py +0 -54
  62. janito/change/preview.py +0 -82
  63. janito/change/prompts.py +0 -121
  64. janito/change/test.py +0 -0
  65. janito/change/viewer/__init__.py +0 -11
  66. janito/change/viewer/content.py +0 -66
  67. janito/change/viewer/panels.py +0 -533
  68. janito/change/viewer/styling.py +0 -114
  69. janito/clear_statement_parser/clear_statement_format.txt +0 -328
  70. janito/clear_statement_parser/examples.txt +0 -326
  71. janito/clear_statement_parser/models.py +0 -104
  72. janito/clear_statement_parser/parser.py +0 -496
  73. janito/cli/base.py +0 -30
  74. janito/cli/history.py +0 -61
  75. janito/cli/registry.py +0 -26
  76. janito/demo/__init__.py +0 -4
  77. janito/demo/data.py +0 -13
  78. janito/demo/mock_data.py +0 -20
  79. janito/demo/operations.py +0 -45
  80. janito/demo/runner.py +0 -59
  81. janito/demo/scenarios.py +0 -32
  82. janito/prompt.py +0 -36
  83. janito/review.py +0 -13
  84. janito/search_replace/README.md +0 -192
  85. janito/search_replace/__init__.py +0 -7
  86. janito/search_replace/__main__.py +0 -21
  87. janito/search_replace/core.py +0 -120
  88. janito/search_replace/logger.py +0 -35
  89. janito/search_replace/parser.py +0 -52
  90. janito/search_replace/play.py +0 -61
  91. janito/search_replace/replacer.py +0 -36
  92. janito/search_replace/searcher.py +0 -411
  93. janito/search_replace/strategy_result.py +0 -10
  94. janito/shell/__init__.py +0 -38
  95. janito/shell/bus.py +0 -31
  96. janito/shell/commands.py +0 -136
  97. janito/shell/history.py +0 -20
  98. janito/shell/processor.py +0 -32
  99. janito/shell/prompt.py +0 -48
  100. janito/shell/registry.py +0 -60
  101. janito/tui/__init__.py +0 -21
  102. janito/tui/base.py +0 -22
  103. janito/tui/flows/__init__.py +0 -5
  104. janito/tui/flows/changes.py +0 -65
  105. janito/tui/flows/content.py +0 -128
  106. janito/tui/flows/selection.py +0 -117
  107. janito/tui/screens/__init__.py +0 -3
  108. janito/tui/screens/app.py +0 -1
  109. janito-0.7.0.dist-info/METADATA +0 -167
  110. janito-0.7.0.dist-info/RECORD +0 -96
  111. {janito-0.7.0.dist-info → janito-0.8.0.dist-info}/WHEEL +0 -0
  112. {janito-0.7.0.dist-info → janito-0.8.0.dist-info}/entry_points.txt +0 -0
janito/agents/openai.py DELETED
@@ -1,57 +0,0 @@
1
- import openai # updated import
2
- import os
3
- from typing import Optional
4
- from threading import Event
5
- from .agent import Agent
6
-
7
- class OpenAIAgent(Agent):
8
- """[DEPRECATED] Handles interaction with OpenAI API, including message handling.
9
-
10
- This backend is no longer actively maintained. Please use the Claude AI backend instead.
11
- The code is kept for backward compatibility but may be removed in future versions.
12
- """
13
- DEFAULT_MODEL = "o1-mini-2024-09-12"
14
-
15
- def __init__(self, api_key: Optional[str] = None, system_prompt: str = None):
16
- super().__init__(api_key, system_prompt)
17
- if not system_prompt:
18
- raise ValueError("system_prompt is required")
19
- self.api_key = api_key or os.getenv('OPENAI_API_KEY')
20
- if not self.api_key:
21
- raise ValueError("OPENAI_API_KEY environment variable is required")
22
- openai.api_key = self.api_key
23
- openai.organization = os.getenv("OPENAI_ORG")
24
- self.client = openai.Client() # initialized client
25
- self.model = os.getenv('OPENAI_MODEL', "o1-mini-2024-09-12") # reverted to original default model
26
-
27
- def send_message(self, message: str, stop_event: Event = None) -> str:
28
- """Send message to OpenAI API and return response"""
29
- self.messages_history.append(("user", message))
30
- self.last_full_message = message
31
-
32
- try:
33
- if stop_event and stop_event.is_set():
34
- return ""
35
-
36
- #messages = [{"role": "system", "content": self.system_message}]
37
- messages = [{"role": "user", "content": message}]
38
-
39
- response = self.client.chat.completions.create(
40
- model=self.model,
41
- messages=messages,
42
- max_completion_tokens=4000,
43
- temperature=1,
44
- )
45
-
46
- response_text = response.choices[0].message.content
47
-
48
- if not (stop_event and stop_event.is_set()):
49
- self.last_response = response_text
50
- self.messages_history.append(("assistant", response_text))
51
-
52
- return response_text
53
-
54
- except KeyboardInterrupt:
55
- if stop_event:
56
- stop_event.set()
57
- return ""
janito/agents/test.py DELETED
@@ -1,34 +0,0 @@
1
- import unittest
2
- import os
3
- from unittest.mock import patch, MagicMock
4
- from .openai import OpenAIAgent
5
- from .claudeai import AIAgent
6
-
7
- class TestAIAgents(unittest.TestCase):
8
- def setUp(self):
9
- self.system_prompt = "You are a helpful assistant."
10
- self.test_message = "Hello, how are you?"
11
-
12
- def test_openai_agent_initialization(self):
13
- with patch.dict(os.environ, {'OPENAI_API_KEY': 'test_key'}):
14
- agent = OpenAIAgent(system_prompt=self.system_prompt)
15
-
16
- def test_claudeai_agent_initialization(self):
17
- with patch.dict(os.environ, {'ANTHROPIC_API_KEY': 'test_key'}):
18
- agent = AIAgent(system_prompt=self.system_prompt)
19
-
20
- def test_openai_agent_send_message(self):
21
- with patch('openai.OpenAI.chat.completions.create') as mock_create:
22
- mock_response = MagicMock()
23
- mock_response.choices[0].message.content = "I'm good, thank you!"
24
- mock_create.return_value = mock_response
25
- response = self.openai_agent.send_message(self.test_message)
26
- self.assertEqual(response, "I'm good, thank you!")
27
-
28
- def test_claudeai_agent_send_message(self):
29
- with patch('anthropic.Client.messages.create') as mock_create:
30
- mock_response = MagicMock()
31
- mock_response.content[0].text = "I'm Claude, how can I assist you?"
32
- mock_create.return_value = mock_response
33
- response = self.claudeai_agent.send_message(self.test_message)
34
- self.assertEqual(response, "I'm Claude, how can I assist you?")
janito/change/__init__.py DELETED
@@ -1,32 +0,0 @@
1
- """
2
- This package provides the following change flow steps:
3
-
4
- - Create a preview directory
5
- - Build change request prompt
6
- - Send change request to AI agent
7
- - Parse the response into changes
8
- - Save response to history file
9
- - Preview the changes (applying them to the preview directory)
10
- - Validate the changes
11
- - Run tests if specified
12
- - Show the change view (using janito.changeviewer)
13
- - Prompt the user to apply the changes to the working directory
14
- - Apply the changes
15
- """
16
-
17
- from typing import Tuple
18
- from pathlib import Path
19
- from ..agents import agent # Updated import to use singleton directly
20
- from .parser import build_change_request_prompt, parse_response
21
- from .preview import setup_workspace_dir_preview
22
- from .applier.main import ChangeApplier
23
-
24
- __all__ = [
25
- 'build_change_request_prompt',
26
- 'get_change_response',
27
- 'parse_response',
28
- 'setup_workspace_dir_preview',
29
- 'parse_change_response',
30
- 'save_change_response',
31
- 'ChangeApplier'
32
- ]
janito/change/__main__.py DELETED
File without changes
@@ -1,23 +0,0 @@
1
- """Analysis module for Janito.
2
-
3
- This module provides functionality for analyzing and displaying code changes.
4
- """
5
-
6
- from .options import AnalysisOption, parse_analysis_options
7
- from .view import format_analysis, prompt_user, get_option_selection
8
- from .prompts import (
9
- build_request_analysis_prompt,
10
- validate_option_letter
11
- )
12
- from .analyze import analyze_request
13
-
14
- __all__ = [
15
- 'AnalysisOption',
16
- 'parse_analysis_options',
17
- 'format_analysis',
18
- 'build_request_analysis_prompt',
19
- 'get_option_selection',
20
- 'prompt_user',
21
- 'validate_option_letter',
22
- 'analyze_request'
23
- ]
@@ -1,7 +0,0 @@
1
- """Main entry point for the analysis module."""
2
-
3
- from .analyze import analyze_request
4
- from janito.config import config
5
- from janito.workspace import collect_files_content
6
- from pathlib import Path
7
-
@@ -1,62 +0,0 @@
1
- """Core analysis functionality."""
2
-
3
- from typing import Optional
4
- from janito.agents import agent
5
- from janito.common import progress_send_message
6
- from janito.config import config
7
- from janito.workspace.workset import Workset
8
- from .view import format_analysis
9
- from .options import AnalysisOption, parse_analysis_options
10
- from .prompts import (
11
- build_request_analysis_prompt,
12
- get_option_selection,
13
- validate_option_letter
14
- )
15
-
16
- def analyze_request(
17
- request: str,
18
- pre_select: str = ""
19
- ) -> Optional[AnalysisOption]:
20
- """
21
- Analyze changes and get user selection.
22
-
23
- Args:
24
- request: User's change request
25
- files_content_xml: Optional content of files to analyze
26
- pre_select: Optional pre-selected option letter
27
-
28
- Returns:
29
- Selected AnalysisOption or None if modified
30
- """
31
- workset = Workset() # Create workset instance
32
-
33
- # Build and send prompt using workset content directly
34
- prompt = build_request_analysis_prompt(request)
35
- response = progress_send_message(prompt)
36
-
37
- # Parse and handle options
38
- options = parse_analysis_options(response)
39
- if not options:
40
- return None
41
-
42
- if pre_select:
43
- return options.get(pre_select.upper())
44
-
45
- if config.tui:
46
- from janito.tui import TuiApp
47
- app = TuiApp(options=options)
48
- app.run()
49
- return app.selected_option
50
-
51
- # Display formatted analysis in terminal mode
52
- format_analysis(response, config.raw)
53
-
54
- # Get user selection
55
- while True:
56
- selection = get_option_selection()
57
-
58
- if selection == 'M':
59
- return None
60
-
61
- if validate_option_letter(selection, options):
62
- return options[selection.upper()]
@@ -1,78 +0,0 @@
1
- """Centralized formatting utilities for analysis display."""
2
-
3
- from typing import Dict, List, Text
4
- from rich.text import Text
5
- from rich.columns import Columns
6
- from rich.padding import Padding
7
- from pathlib import Path
8
-
9
- # Layout constants
10
- COLUMN_SPACING = 6 # Increased spacing between columns
11
- MIN_PANEL_WIDTH = 45 # Wider minimum width for better readability
12
- SECTION_PADDING = (2, 0) # More vertical padding
13
-
14
- # Color scheme constants
15
- STATUS_COLORS = {
16
- 'new': 'bright_green',
17
- 'modified': 'yellow',
18
- 'removed': 'red',
19
- 'default': 'white'
20
- }
21
-
22
- STRUCTURAL_COLORS = {
23
- 'directory': 'dim',
24
- 'separator': 'blue dim',
25
- 'repeat': 'bright_magenta bold'
26
- }
27
-
28
- def create_header(text: str, style: str = "bold cyan") -> Text:
29
- """Create formatted header with separator."""
30
- content = Text()
31
- content.append(text, style=style)
32
- content.append("\n")
33
- content.append("═" * len(text), style="cyan")
34
- return content
35
-
36
- def create_section_header(text: str, width: int = 20) -> Text:
37
- """Create centered section header with separator."""
38
- content = Text()
39
- padding = (width - len(text)) // 2
40
- content.append(" " * padding + text, style="bold cyan")
41
- content.append("\n")
42
- content.append("─" * width, style="cyan")
43
- return content
44
-
45
- def format_file_path(path: str, status: str, max_dir_length: int = 0, is_repeated: bool = False) -> Text:
46
- """Format file path with status indicators and consistent alignment.
47
-
48
- Args:
49
- path: File path to format
50
- status: File status (Modified, New, Removed)
51
- max_dir_length: Maximum directory name length for padding
52
- is_repeated: Whether this directory was seen before
53
- """
54
- content = Text()
55
- style = STATUS_COLORS.get(status.lower(), STATUS_COLORS['default'])
56
-
57
- parts = Path(path).parts
58
- parent_dir = str(Path(path).parent)
59
-
60
- if parent_dir != '.':
61
- # Add 4 spaces for consistent base padding
62
- base_padding = 4
63
- dir_padding = max_dir_length + base_padding
64
-
65
- if is_repeated:
66
- # Add arrow with consistent spacing
67
- content.append(" " * base_padding)
68
- content.append("↑ ", style="magenta")
69
- content.append(" " * (dir_padding - base_padding - 2))
70
- else:
71
- # Left-align directory name with consistent padding
72
- content.append(" " * base_padding)
73
- content.append(parent_dir, style="dim")
74
- content.append(" " * (dir_padding - len(parent_dir) - base_padding))
75
-
76
- # Add filename with consistent spacing
77
- content.append(parts[-1], style=style)
78
- return content
@@ -1,81 +0,0 @@
1
- from dataclasses import dataclass, field
2
- from typing import Dict, List
3
- from pathlib import Path
4
-
5
- @dataclass
6
- class AnalysisOption:
7
- """Represents an analysis option with letter identifier and details"""
8
- letter: str
9
- summary: str
10
- description_items: List[str] = field(default_factory=list)
11
- affected_files: List[str] = field(default_factory=list)
12
-
13
- def format_option_text(self) -> str:
14
- """Format option details as text for change core"""
15
- text = f"Option {self.letter} - {self.summary}\n"
16
- text += "=" * len(f"Option {self.letter} - {self.summary}") + "\n\n"
17
-
18
- if self.description_items:
19
- text += "Description:\n"
20
- for item in self.description_items:
21
- text += f"- {item}\n"
22
- text += "\n"
23
-
24
- if self.affected_files:
25
- text += "Affected files:\n"
26
- for file in self.affected_files:
27
- text += f"- {file}\n"
28
-
29
- return text
30
-
31
- def is_new_directory(self, file_path: str) -> bool:
32
- """Check if file path represents the first occurrence of a directory"""
33
- parent = str(Path(file_path).parent)
34
- return parent != '.' and not any(
35
- parent in self.get_clean_path(file)
36
- for file in self.affected_files
37
- if self.get_clean_path(file) != file_path
38
- )
39
-
40
- def get_clean_path(self, file_path: str) -> str:
41
- """Remove status markers from file path"""
42
- return file_path.split(' (')[0].strip()
43
-
44
- def parse_analysis_options(content: str) -> Dict[str, AnalysisOption]:
45
- """Parse analysis options from formatted text file"""
46
- options = {}
47
- current_option = None
48
- current_section = None
49
-
50
- for line in content.splitlines():
51
- line = line.strip()
52
-
53
- # Skip empty lines and section separators
54
- if not line or line.startswith('---') or line == 'END_OF_OPTIONS':
55
- continue
56
-
57
- # New option starts with a letter and period
58
- if line[0].isalpha() and line[1:3] == '. ':
59
- letter, summary = line.split('. ', 1)
60
- current_option = AnalysisOption(letter=letter.upper(), summary=summary)
61
- options[letter.upper()] = current_option
62
- current_section = None
63
- continue
64
-
65
- # Section headers
66
- if line.lower() == 'description:':
67
- current_section = 'description'
68
- continue
69
- elif line.lower() == 'affected files:':
70
- current_section = 'files'
71
- continue
72
-
73
- # Add items to current section
74
- if current_option and line.startswith('- '):
75
- content = line[2:].strip()
76
- if current_section == 'description':
77
- current_option.description_items.append(content)
78
- elif current_section == 'files':
79
- current_option.affected_files.append(content)
80
-
81
- return options
@@ -1,90 +0,0 @@
1
- """User prompts and input handling for analysis."""
2
-
3
- from typing import List, Dict
4
- from rich.console import Console
5
- from rich.panel import Panel
6
- from rich.rule import Rule
7
- from rich.prompt import Prompt
8
- from rich import box
9
-
10
-
11
- from .options import AnalysisOption
12
-
13
- # Keep only prompt-related functionality
14
- CHANGE_ANALYSIS_PROMPT = """
15
-
16
-
17
- Considering the above workset content, provide 3 sections, each identified by a keyword and representing an option.
18
- Each option should include a concise description and a list of affected files.
19
- 1st option should be basic style change, 2nd organized style, 3rd exntensible style.
20
- Do not use style as keyword, instead focus on the changes summary.
21
-
22
- Use the following format:
23
-
24
- A. Keyword summary of the change
25
- -----------------
26
- Description:
27
- - Concise description of the change
28
-
29
- Affected files:
30
- - path/file1.py (new)
31
- - path/file2.py (modified)
32
- - path/file3.py (removed)
33
-
34
- END_OF_OPTIONS (mandatory marker)
35
-
36
- RULES:
37
- - do NOT provide the content of the files
38
- - do NOT offer to implement the changes
39
- - description items should be 80 chars or less
40
-
41
- Request:
42
- {request}
43
- """
44
-
45
- def prompt_user(message: str, choices: List[str] = None) -> str:
46
- """Display a prominent user prompt with optional choices"""
47
- console = Console()
48
- term_width = console.width or 80
49
- console.print()
50
- console.print(Rule(" User Input Required ", style="bold cyan", align="center"))
51
-
52
- if choices:
53
- choice_text = f"[cyan]Options: {', '.join(choices)}[/cyan]"
54
- console.print(Panel(choice_text, box=box.ROUNDED, justify="center"))
55
-
56
- # Center the prompt with padding
57
- padding = (term_width - len(message)) // 2
58
- padded_message = " " * padding + message
59
- return Prompt.ask(f"[bold cyan]{padded_message}[/bold cyan]")
60
-
61
- def validate_option_letter(letter: str, options: Dict[str, AnalysisOption]) -> bool:
62
- """Validate if the given letter is a valid option or 'M' for modify"""
63
- if letter.upper() == 'M':
64
- return True
65
- return letter.upper() in options
66
-
67
- def get_option_selection() -> str:
68
- """Get user input for option selection with modify option"""
69
- console = Console()
70
- term_width = console.width or 80
71
- message = "Enter option letter or 'M' to modify request"
72
- padding = (term_width - len(message)) // 2
73
- padded_message = " " * padding + message
74
-
75
- console.print(f"\n[cyan]{padded_message}[/cyan]")
76
- while True:
77
- letter = prompt_user("Select option").strip().upper()
78
- if letter == 'M' or (letter.isalpha() and len(letter) == 1):
79
- return letter
80
-
81
- error_msg = "Please enter a valid letter or 'M'"
82
- error_padding = (term_width - len(error_msg)) // 2
83
- padded_error = " " * error_padding + error_msg
84
- console.print(f"[red]{padded_error}[/red]")
85
-
86
- def build_request_analysis_prompt(request: str) -> str:
87
- """Build prompt for information requests"""
88
- return CHANGE_ANALYSIS_PROMPT.format(
89
- request=request
90
- )
@@ -1,9 +0,0 @@
1
- """View package for analysis UI components."""
2
-
3
- from .terminal import format_analysis, prompt_user, get_option_selection
4
-
5
- __all__ = [
6
- 'format_analysis',
7
- 'prompt_user',
8
- 'get_option_selection'
9
- ]
@@ -1,181 +0,0 @@
1
- """Terminal UI components for analysis display."""
2
-
3
- from typing import Dict, List, Optional
4
- from rich.console import Console
5
- from rich.columns import Columns
6
- from rich.text import Text
7
- from rich.panel import Panel
8
- from rich.rule import Rule
9
- from rich.padding import Padding
10
- from rich.prompt import Prompt
11
- from rich import box
12
- from rich.style import Style
13
- from rich.segment import Segment
14
- from rich.containers import Renderables
15
- from pathlib import Path
16
-
17
- from ..options import AnalysisOption
18
- from ..formatting import (
19
- COLUMN_SPACING,
20
- MIN_PANEL_WIDTH,
21
- SECTION_PADDING,
22
- STATUS_COLORS,
23
- STRUCTURAL_COLORS,
24
- create_header,
25
- create_section_header,
26
- format_file_path
27
- )
28
-
29
- def prompt_user(message: str, choices: List[str] = None) -> str:
30
- """Display a prominent user prompt with optional choices"""
31
- console = Console()
32
- term_width = console.width or 80
33
- console.print()
34
- console.print(Rule(" User Input Required ", style="bold cyan", align="center"))
35
-
36
- if choices:
37
- choice_text = f"[cyan]Options: {', '.join(choices)}[/cyan]"
38
- console.print(Panel(choice_text, box=box.ROUNDED, justify="center"))
39
-
40
- message_text = Text(message, style="bold cyan")
41
- padded_message = Padding(message_text, pad=(0, "center"))
42
- console.print(padded_message)
43
- return Prompt.ask("")
44
-
45
- def get_option_selection() -> str:
46
- """Get user input for option selection with modify option"""
47
- console = Console()
48
- term_width = console.width or 80
49
- message = "Enter option letter or 'M' to modify request"
50
- padding = (term_width - len(message)) // 2
51
- padded_message = " " * padding + message
52
-
53
- console.print(f"\n[cyan]{padded_message}[/cyan]")
54
- while True:
55
- letter = prompt_user("Select option").strip().upper()
56
- if letter == 'M' or (letter.isalpha() and len(letter) == 1):
57
- return letter
58
-
59
- error_msg = "Please enter a valid letter or 'M'"
60
- error_text = Text(error_msg, style="red")
61
- padded_error = Padding(error_text, pad=(0, "center"))
62
- console.print(padded_error)
63
-
64
- def _create_option_content(option: AnalysisOption) -> Text:
65
- """Create rich formatted content for a single option."""
66
- content = Text()
67
- content.append("\n")
68
-
69
- header = create_header(f"Option {option.letter} - {option.summary}")
70
- content.append(header)
71
- content.append("\n")
72
-
73
- if option.description_items:
74
- for item in option.description_items:
75
- content.append("• ", style="cyan")
76
- content.append(f"{item}\n")
77
- content.append("\n")
78
-
79
- # Add consistent padding before file list
80
- content.append("\n" * 2)
81
-
82
- if option.affected_files:
83
- files = {status: [] for status in ['New', 'Modified', 'Removed']}
84
- for file in option.affected_files:
85
- if '(new)' in file.lower():
86
- files['New'].append(file)
87
- elif '(removed)' in file.lower():
88
- files['Removed'].append(file)
89
- else:
90
- files['Modified'].append(file)
91
-
92
- for status, status_files in files.items():
93
- if status_files:
94
- content.append(create_section_header(f"{status} Files"))
95
- content.append("\n")
96
- sorted_files = sorted(status_files)
97
- prev_path = None
98
- seen_dirs = {}
99
- for file in sorted_files:
100
- path = option.get_clean_path(file)
101
- current_parts = Path(path).parts
102
- parent_dir = str(Path(path).parent)
103
-
104
- if parent_dir != '.':
105
- is_repeated = parent_dir in seen_dirs
106
- if not is_repeated:
107
- content.append(parent_dir, style=STRUCTURAL_COLORS['directory'])
108
- content.append("/", style=STRUCTURAL_COLORS['separator'])
109
- seen_dirs[parent_dir] = True
110
- else:
111
- dir_width = len(parent_dir)
112
- # Calculate padding to match full directory width
113
- arrow = "↑"
114
- total_padding = dir_width - len(arrow)
115
- left_padding = total_padding // 2
116
- right_padding = total_padding - left_padding
117
- content.append(" " * left_padding + arrow + " " * right_padding,
118
- style=STRUCTURAL_COLORS['repeat'])
119
- content.append("/", style=STRUCTURAL_COLORS['separator'])
120
- content.append(current_parts[-1], style=STATUS_COLORS[status.lower()])
121
- else:
122
- content.append(current_parts[-1], style=STATUS_COLORS[status.lower()])
123
- content.append("\n")
124
- content.append("\n")
125
-
126
- content.append("\n")
127
-
128
- return content
129
-
130
- def create_columns_layout(options_content: List[Text], term_width: int) -> Columns:
131
- """Create a columns layout with consistent spacing."""
132
- num_columns = len(options_content)
133
- spacing = COLUMN_SPACING * (num_columns - 1)
134
- safety_margin = 4 + 2
135
-
136
- usable_width = term_width - spacing - safety_margin
137
- column_width = max((usable_width // num_columns), MIN_PANEL_WIDTH)
138
-
139
- # Create padded content items
140
- rendered_items: List[Renderables] = [
141
- Padding(content, (0, COLUMN_SPACING // 2))
142
- for content in options_content
143
- ]
144
-
145
- return Columns(
146
- rendered_items,
147
- equal=True,
148
- expand=True,
149
- width=column_width,
150
- align="left",
151
- padding=(0, 0),
152
- )
153
-
154
- def format_analysis(analysis: str, raw: bool = False) -> None:
155
- """Format and display the analysis output."""
156
- from ..options import parse_analysis_options
157
-
158
- console = Console()
159
- term_width = console.width or 100
160
-
161
- if raw:
162
- console.print(analysis)
163
- return
164
-
165
- options = parse_analysis_options(analysis)
166
- if not options:
167
- console.print("\n[yellow]Warning: No valid options found in response.[/yellow]\n")
168
- console.print(analysis)
169
- return
170
-
171
- columns_content = [_create_option_content(options[letter])
172
- for letter in sorted(options.keys())]
173
-
174
- columns = create_columns_layout(columns_content, term_width)
175
-
176
- console.print("\n")
177
- console.print(Text("Analysis Options", style="bold cyan"))
178
- console.print(Text("─" * term_width, style="cyan dim"))
179
- console.print(columns)
180
- console.print(Text("─" * term_width, style="cyan dim"))
181
- console.print("\n")
@@ -1,5 +0,0 @@
1
- from .file import FileChangeApplier
2
- from .text import TextChangeApplier
3
- from .workspace_dir import apply_changes
4
-
5
- __all__ = ['FileChangeApplier', 'TextChangeApplier', 'apply_changes']