janito 0.4.0__py3-none-any.whl → 0.6.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 (104) hide show
  1. janito/__init__.py +1 -1
  2. janito/__main__.py +102 -326
  3. janito/agents/__init__.py +16 -0
  4. janito/agents/agent.py +21 -0
  5. janito/{claude.py → agents/claudeai.py} +13 -17
  6. janito/agents/openai.py +53 -0
  7. janito/agents/test.py +34 -0
  8. janito/change/__init__.py +32 -0
  9. janito/change/__main__.py +0 -0
  10. janito/change/analysis/__init__.py +23 -0
  11. janito/change/analysis/__main__.py +7 -0
  12. janito/change/analysis/analyze.py +61 -0
  13. janito/change/analysis/formatting.py +78 -0
  14. janito/change/analysis/options.py +81 -0
  15. janito/change/analysis/prompts.py +98 -0
  16. janito/change/analysis/view/__init__.py +9 -0
  17. janito/change/analysis/view/terminal.py +171 -0
  18. janito/change/applier/__init__.py +5 -0
  19. janito/change/applier/file.py +58 -0
  20. janito/change/applier/main.py +156 -0
  21. janito/change/applier/text.py +245 -0
  22. janito/change/applier/workspace_dir.py +58 -0
  23. janito/change/core.py +131 -0
  24. janito/change/history.py +44 -0
  25. janito/change/operations.py +7 -0
  26. janito/change/parser.py +289 -0
  27. janito/change/play.py +54 -0
  28. janito/change/preview.py +82 -0
  29. janito/change/prompts.py +126 -0
  30. janito/change/test.py +0 -0
  31. janito/change/validator.py +251 -0
  32. janito/change/viewer/__init__.py +11 -0
  33. janito/change/viewer/content.py +66 -0
  34. janito/change/viewer/diff.py +43 -0
  35. janito/change/viewer/pager.py +56 -0
  36. janito/change/viewer/panels.py +555 -0
  37. janito/change/viewer/styling.py +103 -0
  38. janito/change/viewer/themes.py +55 -0
  39. janito/clear_statement_parser/clear_statement_format.txt +328 -0
  40. janito/clear_statement_parser/examples.txt +326 -0
  41. janito/clear_statement_parser/models.py +104 -0
  42. janito/clear_statement_parser/parser.py +496 -0
  43. janito/cli/__init__.py +2 -0
  44. janito/cli/base.py +30 -0
  45. janito/cli/commands.py +45 -0
  46. janito/cli/functions.py +111 -0
  47. janito/cli/handlers/ask.py +22 -0
  48. janito/cli/handlers/demo.py +22 -0
  49. janito/cli/handlers/request.py +24 -0
  50. janito/cli/handlers/scan.py +9 -0
  51. janito/cli/history.py +61 -0
  52. janito/cli/registry.py +26 -0
  53. janito/common.py +41 -10
  54. janito/config.py +71 -6
  55. janito/demo/__init__.py +4 -0
  56. janito/demo/data.py +13 -0
  57. janito/demo/mock_data.py +20 -0
  58. janito/demo/operations.py +45 -0
  59. janito/demo/runner.py +59 -0
  60. janito/demo/scenarios.py +32 -0
  61. janito/prompts.py +1 -65
  62. janito/qa.py +8 -5
  63. janito/review.py +13 -0
  64. janito/search_replace/README.md +146 -0
  65. janito/search_replace/__init__.py +6 -0
  66. janito/search_replace/__main__.py +21 -0
  67. janito/search_replace/core.py +119 -0
  68. janito/search_replace/parser.py +52 -0
  69. janito/search_replace/play.py +61 -0
  70. janito/search_replace/replacer.py +36 -0
  71. janito/search_replace/searcher.py +299 -0
  72. janito/shell/__init__.py +39 -0
  73. janito/shell/bus.py +31 -0
  74. janito/shell/commands.py +195 -0
  75. janito/shell/handlers.py +122 -0
  76. janito/shell/history.py +20 -0
  77. janito/shell/processor.py +52 -0
  78. janito/tui/__init__.py +21 -0
  79. janito/tui/base.py +22 -0
  80. janito/tui/flows/__init__.py +5 -0
  81. janito/tui/flows/changes.py +65 -0
  82. janito/tui/flows/content.py +128 -0
  83. janito/tui/flows/selection.py +117 -0
  84. janito/tui/screens/__init__.py +3 -0
  85. janito/tui/screens/app.py +1 -0
  86. janito/workspace/__init__.py +7 -0
  87. janito/workspace/analysis.py +121 -0
  88. janito/workspace/manager.py +48 -0
  89. janito/workspace/scan.py +232 -0
  90. janito-0.6.0.dist-info/METADATA +185 -0
  91. janito-0.6.0.dist-info/RECORD +95 -0
  92. {janito-0.4.0.dist-info → janito-0.6.0.dist-info}/WHEEL +1 -1
  93. janito/analysis.py +0 -281
  94. janito/changeapplier.py +0 -436
  95. janito/changeviewer.py +0 -350
  96. janito/console.py +0 -330
  97. janito/contentchange.py +0 -84
  98. janito/contextparser.py +0 -113
  99. janito/fileparser.py +0 -125
  100. janito/scan.py +0 -137
  101. janito-0.4.0.dist-info/METADATA +0 -164
  102. janito-0.4.0.dist-info/RECORD +0 -21
  103. {janito-0.4.0.dist-info → janito-0.6.0.dist-info}/entry_points.txt +0 -0
  104. {janito-0.4.0.dist-info → janito-0.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,251 @@
1
+ import ast
2
+ # ...existing code...
3
+ # Remove the process_change_request function if it exists in this file
4
+ # Keep all other existing code
5
+ from pathlib import Path
6
+ from typing import Optional, Tuple, Optional, List, Set
7
+ from rich.console import Console
8
+ from rich.prompt import Confirm
9
+ from rich.panel import Panel
10
+ from rich.columns import Columns
11
+ from rich import box
12
+
13
+ from janito.common import progress_send_message
14
+ from janito.change.history import save_changes_to_history
15
+ from janito.config import config
16
+ from janito.workspace.scan import collect_files_content
17
+ from .viewer import preview_all_changes
18
+ from janito.workspace.analysis import analyze_workspace_content as show_content_stats
19
+ from .parser import FileChange
20
+
21
+ from .analysis import analyze_request
22
+
23
+ def validate_file_operations(changes: List[FileChange], collected_files: Set[Path]) -> Tuple[bool, str]:
24
+ """Validate file operations against current filesystem state.
25
+
26
+ Validates:
27
+ - Path conflicts:
28
+ - Parent directory exists and is a directory
29
+ - No Python module name conflicts (dir vs file)
30
+ - Text modifications:
31
+ - Search content required for non-append modifications
32
+ - Replace content required for append operations
33
+
34
+ Args:
35
+ changes: List of file changes to validate
36
+ collected_files: Set of files that were found during scanning
37
+
38
+ Returns:
39
+ Tuple[bool, str]: (is_valid, error_message)
40
+ """
41
+ for change in changes:
42
+ # For modify operations, validate text changes
43
+ if change.operation == ChangeOperation.MODIFY_FILE:
44
+ for mod in change.text_changes:
45
+ if not mod.is_delete and not mod.is_append:
46
+ if not mod.search_content:
47
+ return False, f"Search content required for modification in {change.name}"
48
+
49
+ if mod.is_append and not mod.replace_content:
50
+ return False, f"Replace content required for append operation in {change.name}"
51
+
52
+ # Check for directory/file conflicts
53
+ if change.operation == ChangeOperation.CREATE_FILE:
54
+ parent = change.name.parent
55
+ if parent.exists() and not parent.is_dir():
56
+ return False, f"Cannot create file - parent path exists as file: {parent}"
57
+
58
+ # Check for Python module conflicts
59
+ if change.name.suffix == '.py':
60
+ module_dir = change.name.with_suffix('')
61
+ if module_dir.exists() and module_dir.is_dir():
62
+ return False, f"Cannot create Python file - directory with same name exists: {module_dir}"
63
+
64
+ # Basic rename validation (without existence checks)
65
+ if change.operation == ChangeOperation.RENAME_FILE:
66
+ if not change.source or not change.target:
67
+ return False, "Rename operation requires both source and target paths"
68
+
69
+ return True, ""
70
+ from pathlib import Path
71
+ from typing import Tuple, List, Set, Optional
72
+ from .parser import FileChange, ChangeOperation
73
+
74
+ def validate_python_syntax(code: str, filepath: Path | str) -> Tuple[bool, str]:
75
+ """Validate Python code syntax using ast parser.
76
+
77
+ Args:
78
+ code: Python source code to validate
79
+ filepath: Path or string of the file (used for error messages)
80
+
81
+ Returns:
82
+ Tuple of (is_valid, error_message)
83
+ - is_valid: True if syntax is valid
84
+ - error_message: Empty string if valid, error details if invalid
85
+ """
86
+ try:
87
+ ast.parse(code)
88
+ return True, ""
89
+ except SyntaxError as e:
90
+ # Get detailed error information
91
+ line_num = e.lineno if e.lineno is not None else 0
92
+ col_num = e.offset if e.offset is not None else 0
93
+ line = e.text or ""
94
+
95
+ # Build error message with line pointer
96
+ pointer = " " * (col_num - 1) + "^" if col_num > 0 else ""
97
+ error_msg = (
98
+ f"Syntax error at {filepath}:{line_num}:{col_num}\n"
99
+ f"{line}\n"
100
+ f"{pointer}\n"
101
+ f"Error: {str(e)}"
102
+ )
103
+ return False, error_msg
104
+ except Exception as e:
105
+ return False, f"Parsing error in {filepath}: {str(e)}"
106
+
107
+ def validate_change(change: FileChange) -> Tuple[bool, Optional[str]]:
108
+ """Validate a single FileChange object for structural correctness.
109
+
110
+ Validates:
111
+ - Required fields (name, operation type)
112
+ - Operation-specific requirements:
113
+ - Create/Replace: content is required
114
+ - Rename: target path is required
115
+ - Modify: at least one text change required
116
+ - Text change validations:
117
+ - Append: replace_content is required
118
+ - Delete: search_content is required
119
+ - Replace: both search_content and replace_content required
120
+ - Prevents duplicate search patterns
121
+
122
+ Args:
123
+ change: FileChange object to validate
124
+
125
+ Returns:
126
+ Tuple[bool, Optional[str]]: (is_valid, error_message)
127
+ """
128
+ if not change.name:
129
+ return False, "File name is required"
130
+
131
+ operation = change.operation.name.title().lower()
132
+ if operation not in ['create_file', 'replace_file', 'remove_file', 'rename_file', 'modify_file', 'move_file']:
133
+ return False, f"Invalid file operation: {change.operation}"
134
+
135
+ if operation in ['rename_file', 'move_file'] and not change.target:
136
+ return False, "Target file path is required for rename/move operation"
137
+
138
+ if operation in ['create_file', 'replace_file']:
139
+ if not change.content:
140
+ return False, f"Content is required for {change.operation} operation"
141
+
142
+ if operation == 'modify_file':
143
+ if not change.text_changes:
144
+ return False, "At least one modification is required for modify operation"
145
+
146
+ # Track search texts to avoid duplicates
147
+ seen_search_texts = set()
148
+ for mod in change.text_changes:
149
+ # Validate append operations
150
+ if mod.is_append:
151
+ if not mod.replace_content:
152
+ return False, "Replace content required for append operation"
153
+ # Validate other operations
154
+ elif not mod.is_delete:
155
+ if not mod.search_content:
156
+ return False, "Search content required for non-append modification"
157
+
158
+ if mod.search_content:
159
+ seen_search_texts.add(mod.search_content)
160
+
161
+ return True, None
162
+
163
+ def validate_all_changes(changes: List[FileChange], collected_files: Set[Path]) -> Tuple[bool, Optional[str]]:
164
+ """Validates all aspects of the requested changes.
165
+
166
+ Performs complete validation in two phases:
167
+ 1. Individual change validation:
168
+ - Structure and content requirements
169
+ - Operation-specific validations
170
+ - Text modification validations
171
+ 2. Filesystem state validation:
172
+ - File existence checks
173
+ - Path conflict checks
174
+ - Python module conflict checks
175
+
176
+ Args:
177
+ changes: List of changes to validate
178
+ collected_files: Set of files found during scanning
179
+
180
+ Returns:
181
+ Tuple[bool, Optional[str]]: (is_valid, error_message)
182
+ - If valid, error_message will be None
183
+ - If invalid, error_message will describe the validation failure
184
+ """
185
+ # First validate individual changes
186
+ for change in changes:
187
+ is_valid, error = validate_change(change)
188
+ if not is_valid:
189
+ return False, f"Invalid change for {change.name}: {error}"
190
+
191
+ # Then validate file operations against filesystem
192
+ is_valid, error = validate_file_operations(changes, collected_files)
193
+ if not is_valid:
194
+ return False, error
195
+
196
+ return True, None
197
+
198
+ def validate_file_operations(changes: List[FileChange], collected_files: Set[Path]) -> Tuple[bool, str]:
199
+ """Validate file operations against current filesystem state.
200
+
201
+ Validates:
202
+ - File existence for operations that require it:
203
+ - Modify: file must exist in collected files
204
+ - Replace: file must exist in collected files
205
+ - Remove: file must exist in collected files
206
+ - File non-existence for operations that require it:
207
+ - Create: file must not exist (unless marked as new)
208
+ - Rename target: target must not exist
209
+ - Path conflicts:
210
+ - Parent directory exists and is a directory
211
+ - No Python module name conflicts (dir vs file)
212
+ - Text modifications:
213
+ - Search content required for non-append modifications
214
+ - Replace content required for append operations
215
+
216
+ Args:
217
+ changes: List of file changes to validate
218
+ collected_files: Set of files that were found during scanning, includes state metadata
219
+
220
+ Returns:
221
+ Tuple[bool, str]: (is_valid, error_message)
222
+ """
223
+ for change in changes:
224
+ # For modify operations, validate text changes
225
+ if change.operation == ChangeOperation.MODIFY_FILE:
226
+ for mod in change.text_changes:
227
+ if not mod.is_delete and not mod.is_append:
228
+ if not mod.search_content:
229
+ return False, f"Search content required for modification in {change.name}"
230
+
231
+ if mod.is_append and not mod.replace_content:
232
+ return False, f"Replace content required for append operation in {change.name}"
233
+
234
+ # Get file state if available
235
+ file_state = change.name.name.split(' (')[-1].rstrip(')') if ' (' in str(change.name) else None
236
+ is_new_file = file_state == 'new' if file_state else False
237
+
238
+ # Validate file exists for operations requiring it
239
+ if change.operation in (ChangeOperation.MODIFY_FILE, ChangeOperation.REPLACE_FILE, ChangeOperation.REMOVE_FILE):
240
+ if change.name not in collected_files and not is_new_file:
241
+ return False, f"File not found in scanned files: {change.name}"
242
+
243
+
244
+ # Validate rename/move operations
245
+ if change.operation in (ChangeOperation.RENAME_FILE, ChangeOperation.MOVE_FILE):
246
+ if not change.source or not change.target:
247
+ return False, "Rename/move operation requires both source and target paths"
248
+ if change.source not in collected_files and not is_new_file:
249
+ return False, f"Source file not found for rename/move: {change.source}"
250
+
251
+ return True, ""
@@ -0,0 +1,11 @@
1
+ from .styling import set_theme
2
+ from .themes import ColorTheme, ThemeType, get_theme_by_type
3
+ from .panels import preview_all_changes
4
+
5
+ __all__ = [
6
+ 'set_theme',
7
+ 'ColorTheme',
8
+ 'ThemeType',
9
+ 'get_theme_by_type',
10
+ 'preview_all_changes'
11
+ ]
@@ -0,0 +1,66 @@
1
+ from typing import Optional
2
+ from pathlib import Path
3
+ from rich.syntax import Syntax
4
+ from rich.panel import Panel
5
+ from rich.console import Console
6
+
7
+ def get_file_syntax(filepath: Path) -> Optional[str]:
8
+ """Get syntax lexer name based on file extension"""
9
+ ext_map = {
10
+ '.py': 'python',
11
+ '.js': 'javascript',
12
+ '.ts': 'typescript',
13
+ '.html': 'html',
14
+ '.css': 'css',
15
+ '.json': 'json',
16
+ '.md': 'markdown',
17
+ '.yaml': 'yaml',
18
+ '.yml': 'yaml',
19
+ '.sh': 'bash',
20
+ '.bash': 'bash',
21
+ '.sql': 'sql',
22
+ '.xml': 'xml',
23
+ }
24
+ return ext_map.get(filepath.suffix.lower())
25
+
26
+ def create_content_preview(filepath: Path, content: str, is_new: bool = False) -> Panel:
27
+ """Create a preview panel with syntax highlighting and metadata"""
28
+ syntax_type = get_file_syntax(filepath)
29
+ file_size = len(content.encode('utf-8'))
30
+ line_count = len(content.splitlines())
31
+
32
+ # Format file metadata
33
+ size_str = f"{file_size:,} bytes"
34
+ stats = f"[dim]{line_count:,} lines | {size_str}[/dim]"
35
+
36
+ if syntax_type:
37
+ # Use syntax highlighting for known file types
38
+ syntax = Syntax(
39
+ content,
40
+ syntax_type,
41
+ theme="monokai",
42
+ line_numbers=True,
43
+ word_wrap=True,
44
+ code_width=100,
45
+ tab_size=4
46
+ )
47
+ preview = syntax
48
+ file_type = f"[blue]{syntax_type}[/blue]"
49
+ else:
50
+ # Fallback to plain text for unknown types
51
+ preview = content
52
+ file_type = "[yellow]plain text[/yellow]"
53
+
54
+ # Adjust title based on whether it's a new file
55
+ title_prefix = "[green]New File[/green]: " if is_new else "Content Preview: "
56
+ title = f"{title_prefix}[green]{filepath.name}[/green] ({file_type})"
57
+
58
+ return Panel(
59
+ preview,
60
+ title=title,
61
+ title_align="left",
62
+ subtitle=stats,
63
+ subtitle_align="right",
64
+ border_style="green" if is_new else "cyan",
65
+ padding=(1, 2)
66
+ )
@@ -0,0 +1,43 @@
1
+ from typing import List, Tuple
2
+ from difflib import SequenceMatcher
3
+
4
+ def find_common_sections(search_lines: List[str], replace_lines: List[str]) -> Tuple[List[str], List[str], List[str], List[str], List[str]]:
5
+ """Find common sections between search and replace content"""
6
+ # Find common lines from top
7
+ common_top = []
8
+ for s, r in zip(search_lines, replace_lines):
9
+ if s == r:
10
+ common_top.append(s)
11
+ else:
12
+ break
13
+
14
+ # Find common lines from bottom
15
+ search_remaining = search_lines[len(common_top):]
16
+ replace_remaining = replace_lines[len(common_top):]
17
+
18
+ common_bottom = []
19
+ for s, r in zip(reversed(search_remaining), reversed(replace_remaining)):
20
+ if s == r:
21
+ common_bottom.insert(0, s)
22
+ else:
23
+ break
24
+
25
+ # Get the unique middle sections
26
+ search_middle = search_remaining[:-len(common_bottom)] if common_bottom else search_remaining
27
+ replace_middle = replace_remaining[:-len(common_bottom)] if common_bottom else replace_remaining
28
+
29
+ return common_top, search_middle, replace_middle, common_bottom, search_lines
30
+
31
+ def get_line_similarity(line1: str, line2: str) -> float:
32
+ """Calculate similarity ratio between two lines"""
33
+ return SequenceMatcher(None, line1, line2).ratio()
34
+
35
+ def find_similar_lines(deleted_lines: List[str], added_lines: List[str], similarity_threshold: float = 0.5) -> List[Tuple[int, int, float]]:
36
+ """Find similar lines between deleted and added content"""
37
+ similar_pairs = []
38
+ for i, del_line in enumerate(deleted_lines):
39
+ for j, add_line in enumerate(added_lines):
40
+ similarity = get_line_similarity(del_line, add_line)
41
+ if similarity >= similarity_threshold:
42
+ similar_pairs.append((i, j, similarity))
43
+ return similar_pairs
@@ -0,0 +1,56 @@
1
+ from rich.console import Console
2
+ import shutil
3
+ from typing import Optional
4
+
5
+ def wait_for_enter(console: Console):
6
+ """Wait for ENTER key press to continue with progress indicator"""
7
+ console.print("\n[yellow]More content to show[/yellow]")
8
+ console.print("[dim]Press ENTER to continue...[/dim]", end="")
9
+ try:
10
+ input()
11
+ console.print() # Just add a newline
12
+ except KeyboardInterrupt:
13
+ console.print() # Just add a newline
14
+ raise KeyboardInterrupt
15
+
16
+ # Track current file being displayed
17
+ _current_file = None
18
+
19
+ def set_current_file(filename: str) -> None:
20
+ """Set the current file being displayed"""
21
+ global _current_file
22
+ _current_file = filename
23
+
24
+ def get_current_file() -> Optional[str]:
25
+ """Get the current file being displayed"""
26
+ return _current_file
27
+
28
+ def check_pager(console: Console, height: int, content_height: Optional[int] = None) -> int:
29
+ """Check if we need to pause and wait for user input
30
+
31
+ Args:
32
+ console: Rich console instance
33
+ height: Current accumulated height
34
+ content_height: Optional height of content to be displayed next
35
+
36
+ Returns:
37
+ New accumulated height
38
+ """
39
+ # Get current file being displayed
40
+ current_file = get_current_file()
41
+ if not current_file:
42
+ return height
43
+
44
+ term_height = shutil.get_terminal_size().lines
45
+ margin = 5 # Add margin to prevent too early paging
46
+ available_height = term_height - margin
47
+
48
+ # Calculate total height including upcoming content
49
+ total_height = height + (content_height or 0)
50
+
51
+ # Only page if we're at a file boundary or content won't fit
52
+ if total_height > available_height:
53
+ wait_for_enter(console)
54
+ return 0
55
+
56
+ return height