janito 3.5.1__py3-none-any.whl → 3.7.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.
- janito/README.md +1 -4
- janito/cli/chat_mode/bindings.py +0 -50
- janito/cli/chat_mode/session.py +1 -12
- janito/cli/chat_mode/shell/commands/multi.py +0 -5
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
- janito/cli/cli_commands/list_plugins.py +43 -52
- janito/cli/core/getters.py +0 -3
- janito/cli/core/model_guesser.py +24 -40
- janito/cli/main_cli.py +12 -9
- janito/cli/prompt_core.py +9 -47
- janito/cli/rich_terminal_reporter.py +2 -2
- janito/docs/GETTING_STARTED.md +1 -1
- janito/drivers/openai/driver.py +0 -1
- janito/drivers/zai/driver.py +0 -1
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +16 -32
- janito/llm/auth_utils.py +5 -14
- janito/llm/driver.py +0 -8
- janito/plugins/__init__.py +12 -31
- janito/plugins/auto_loader.py +11 -12
- janito/plugins/auto_loader_fixed.py +11 -12
- janito/{plugin_system → plugins}/base.py +2 -5
- janito/plugins/builtin.py +1 -15
- janito/plugins/core_adapter.py +11 -89
- janito/plugins/core_loader.py +120 -0
- janito/plugins/core_loader_fixed.py +125 -0
- janito/plugins/discovery.py +5 -5
- janito/plugins/discovery_core.py +9 -14
- janito/plugins/manager.py +1 -1
- janito/providers/__init__.py +0 -1
- janito/providers/moonshot/model_info.py +11 -0
- janito/tools/__init__.py +7 -31
- janito/tools/adapters/__init__.py +1 -6
- janito/tools/adapters/local/__init__.py +70 -7
- janito/{plugins/tools → tools/adapters/local}/ask_user.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/create_file.py +6 -6
- janito/{plugins/tools → tools/adapters/local}/fetch_url.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/python_code_run.py +7 -23
- janito/{plugins/tools → tools/adapters/local}/python_command_run.py +5 -21
- janito/{plugins/tools → tools/adapters/local}/python_file_run.py +5 -21
- janito/{plugins/tools → tools/adapters/local}/replace_text_in_file.py +4 -4
- janito/{plugins/tools → tools/adapters/local}/run_bash_command.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/run_powershell_command.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/show_image.py +6 -15
- janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
- janito/tools/function_adapter.py +65 -0
- janito/tools/loop_protection_decorator.py +117 -114
- janito-3.7.0.dist-info/METADATA +84 -0
- {janito-3.5.1.dist-info → janito-3.7.0.dist-info}/RECORD +88 -157
- janito/cli/cli_commands/check_tools.py +0 -212
- janito/llm/cancellation_manager.py +0 -63
- janito/llm/enter_cancellation.py +0 -107
- janito/plugin_system/__init__.py +0 -10
- janito/plugin_system/core_loader.py +0 -217
- janito/plugin_system/core_loader_fixed.py +0 -225
- janito/plugins/core/__init__.py +0 -7
- janito/plugins/core/codeanalyzer/__init__.py +0 -43
- janito/plugins/core/filemanager/__init__.py +0 -124
- janito/plugins/core/filemanager/tools/create_file.py +0 -87
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins/core/imagedisplay/__init__.py +0 -14
- janito/plugins/core/imagedisplay/plugin.py +0 -51
- janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins/core/system/__init__.py +0 -23
- janito/plugins/core/system/tools/run_bash_command.py +0 -204
- janito/plugins/core/system/tools/run_powershell_command.py +0 -234
- janito/plugins/dev/__init__.py +0 -7
- janito/plugins/dev/pythondev/__init__.py +0 -37
- janito/plugins/dev/visualization/__init__.py +0 -23
- janito/plugins/example_plugin.py +0 -108
- janito/plugins/tools/__init__.py +0 -10
- janito/plugins/tools/copy_file.py +0 -87
- janito/plugins/tools/core_tools_plugin.py +0 -87
- janito/plugins/tools/create_directory.py +0 -70
- janito/plugins/tools/decorators.py +0 -19
- janito/plugins/tools/delete_text_in_file.py +0 -134
- janito/plugins/tools/find_files.py +0 -143
- janito/plugins/tools/get_file_outline/__init__.py +0 -7
- janito/plugins/tools/get_file_outline/core.py +0 -122
- janito/plugins/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins/tools/move_file.py +0 -131
- janito/plugins/tools/open_html_in_browser.py +0 -51
- janito/plugins/tools/open_url.py +0 -37
- janito/plugins/tools/read_chart.py +0 -259
- janito/plugins/tools/read_files.py +0 -58
- janito/plugins/tools/remove_directory.py +0 -55
- janito/plugins/tools/remove_file.py +0 -58
- janito/plugins/tools/search_text/__init__.py +0 -7
- janito/plugins/tools/search_text/core.py +0 -205
- janito/plugins/tools/search_text/match_lines.py +0 -67
- janito/plugins/tools/search_text/pattern_utils.py +0 -73
- janito/plugins/tools/search_text/traverse_directory.py +0 -145
- janito/plugins/tools/show_image_grid.py +0 -85
- janito/plugins/tools/validate_file_syntax/__init__.py +0 -7
- janito/plugins/tools/validate_file_syntax/core.py +0 -114
- janito/plugins/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins/tools/view_file.py +0 -172
- janito/plugins/ui/__init__.py +0 -7
- janito/plugins/ui/userinterface/__init__.py +0 -16
- janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins/web/__init__.py +0 -7
- janito/plugins/web/webtools/__init__.py +0 -33
- janito/plugins/web/webtools/tools/fetch_url.py +0 -458
- janito/providers/together/__init__.py +0 -1
- janito/providers/together/model_info.py +0 -69
- janito/providers/together/provider.py +0 -108
- janito/tools/cli_initializer.py +0 -88
- janito/tools/initialize.py +0 -70
- janito-3.5.1.dist-info/METADATA +0 -229
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/copy_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/move_file.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
- /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_file.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/view_file.py +0 -0
- {janito-3.5.1.dist-info → janito-3.7.0.dist-info}/WHEEL +0 -0
- {janito-3.5.1.dist-info → janito-3.7.0.dist-info}/entry_points.txt +0 -0
- {janito-3.5.1.dist-info → janito-3.7.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.5.1.dist-info → janito-3.7.0.dist-info}/top_level.txt +0 -0
@@ -1,259 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.plugins.tools.decorators import register_core_tool
|
4
|
-
from janito.tools.tool_utils import display_path
|
5
|
-
from janito.i18n import tr
|
6
|
-
import json
|
7
|
-
import os
|
8
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
9
|
-
|
10
|
-
|
11
|
-
@register_core_tool
|
12
|
-
class ReadChart(ToolBase):
|
13
|
-
"""
|
14
|
-
Display charts and data visualizations in the terminal using rich.
|
15
|
-
|
16
|
-
Args:
|
17
|
-
data (dict): Chart data in JSON format. Should contain 'type' (bar, line, pie, table) and 'data' keys.
|
18
|
-
title (str, optional): Chart title. Defaults to "Chart".
|
19
|
-
width (int, optional): Chart width. Defaults to 80.
|
20
|
-
height (int, optional): Chart height. Defaults to 20.
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
str: Formatted chart display in terminal or error message.
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(read=True)
|
27
|
-
tool_name = "read_chart"
|
28
|
-
|
29
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="data")
|
30
|
-
def run(
|
31
|
-
self, data: dict, title: str = "Chart", width: int = 80, height: int = 20
|
32
|
-
) -> str:
|
33
|
-
try:
|
34
|
-
from rich.console import Console
|
35
|
-
from rich.table import Table
|
36
|
-
from rich.text import Text
|
37
|
-
from rich.layout import Layout
|
38
|
-
from rich.panel import Panel
|
39
|
-
from rich.columns import Columns
|
40
|
-
from rich import box
|
41
|
-
|
42
|
-
console = Console(width=width)
|
43
|
-
|
44
|
-
if not isinstance(data, dict):
|
45
|
-
return "❌ Error: Data must be a dictionary"
|
46
|
-
|
47
|
-
chart_type = data.get("type", "table").lower()
|
48
|
-
chart_data = data.get("data", [])
|
49
|
-
|
50
|
-
if not chart_data:
|
51
|
-
return "⚠️ Warning: No data provided for chart"
|
52
|
-
|
53
|
-
self.report_action(
|
54
|
-
tr(
|
55
|
-
"📊 Displaying {chart_type} chart: {title}",
|
56
|
-
chart_type=chart_type,
|
57
|
-
title=title,
|
58
|
-
),
|
59
|
-
ReportAction.READ,
|
60
|
-
)
|
61
|
-
|
62
|
-
if chart_type == "table":
|
63
|
-
return self._display_table(console, chart_data, title, width)
|
64
|
-
elif chart_type == "bar":
|
65
|
-
return self._display_bar(console, chart_data, title, width, height)
|
66
|
-
elif chart_type == "line":
|
67
|
-
return self._display_line(console, chart_data, title, width, height)
|
68
|
-
elif chart_type == "pie":
|
69
|
-
return self._display_pie(console, chart_data, title, width)
|
70
|
-
else:
|
71
|
-
return f"❌ Error: Unsupported chart type '{chart_type}'. Use: table, bar, line, pie"
|
72
|
-
|
73
|
-
except ImportError:
|
74
|
-
return "❌ Error: rich library not available for chart display"
|
75
|
-
except Exception as e:
|
76
|
-
return f"❌ Error displaying chart: {e}"
|
77
|
-
|
78
|
-
def _display_table(self, console, data, title, width):
|
79
|
-
"""Display data as a rich table."""
|
80
|
-
from rich.table import Table
|
81
|
-
|
82
|
-
if not data:
|
83
|
-
return "No data to display"
|
84
|
-
|
85
|
-
table = Table(title=title, show_header=True, header_style="bold magenta")
|
86
|
-
|
87
|
-
# Handle different data formats
|
88
|
-
if isinstance(data, dict):
|
89
|
-
# Dictionary format: key-value pairs
|
90
|
-
table.add_column("Key", style="cyan")
|
91
|
-
table.add_column("Value", style="green")
|
92
|
-
for key, value in data.items():
|
93
|
-
table.add_row(str(key), str(value))
|
94
|
-
elif isinstance(data, list):
|
95
|
-
if data and isinstance(data[0], dict):
|
96
|
-
# List of dictionaries (records)
|
97
|
-
headers = list(data[0].keys()) if data else []
|
98
|
-
for header in headers:
|
99
|
-
table.add_column(str(header).title(), style="cyan")
|
100
|
-
for row in data:
|
101
|
-
table.add_row(*[str(row.get(h, "")) for h in headers])
|
102
|
-
else:
|
103
|
-
# Simple list
|
104
|
-
table.add_column("Items", style="cyan")
|
105
|
-
for item in data:
|
106
|
-
table.add_row(str(item))
|
107
|
-
|
108
|
-
console.print(table)
|
109
|
-
return f"✅ Table chart displayed: {title}"
|
110
|
-
|
111
|
-
def _display_bar(self, console, data, title, width, height):
|
112
|
-
"""Display data as a simple bar chart using unicode blocks."""
|
113
|
-
try:
|
114
|
-
if isinstance(data, dict):
|
115
|
-
items = list(data.items())
|
116
|
-
elif isinstance(data, list) and data and isinstance(data[0], dict):
|
117
|
-
# Assume first two keys are labels and values
|
118
|
-
keys = list(data[0].keys())
|
119
|
-
if len(keys) >= 2:
|
120
|
-
label_key, value_key = keys[0], keys[1]
|
121
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
122
|
-
else:
|
123
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
124
|
-
else:
|
125
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
126
|
-
|
127
|
-
if not items:
|
128
|
-
return "No data to display"
|
129
|
-
|
130
|
-
# Convert values to numbers
|
131
|
-
numeric_items = []
|
132
|
-
for label, value in items:
|
133
|
-
try:
|
134
|
-
numeric_items.append((str(label), float(value)))
|
135
|
-
except (ValueError, TypeError):
|
136
|
-
numeric_items.append((str(label), 0.0))
|
137
|
-
|
138
|
-
if not numeric_items:
|
139
|
-
return "No valid numeric data to display"
|
140
|
-
|
141
|
-
max_val = max(val for _, val in numeric_items) if numeric_items else 1
|
142
|
-
|
143
|
-
console.print(f"\n[bold]{title}[/bold]")
|
144
|
-
console.print("=" * min(len(title), width))
|
145
|
-
|
146
|
-
for label, value in numeric_items:
|
147
|
-
bar_length = int((value / max_val) * (width - 20)) if max_val > 0 else 0
|
148
|
-
bar = "█" * bar_length
|
149
|
-
console.print(f"{label:<15} {bar} {value:.1f}")
|
150
|
-
|
151
|
-
return f"✅ Bar chart displayed: {title}"
|
152
|
-
|
153
|
-
except Exception as e:
|
154
|
-
return f"❌ Error displaying bar chart: {e}"
|
155
|
-
|
156
|
-
def _display_line(self, console, data, title, width, height):
|
157
|
-
"""Display data as a simple line chart using unicode characters."""
|
158
|
-
try:
|
159
|
-
if isinstance(data, dict):
|
160
|
-
items = list(data.items())
|
161
|
-
elif isinstance(data, list):
|
162
|
-
if data and isinstance(data[0], dict):
|
163
|
-
keys = list(data[0].keys())
|
164
|
-
if len(keys) >= 2:
|
165
|
-
label_key, value_key = keys[0], keys[1]
|
166
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
167
|
-
else:
|
168
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
169
|
-
else:
|
170
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
171
|
-
else:
|
172
|
-
return "Unsupported data format"
|
173
|
-
|
174
|
-
# Convert to numeric values
|
175
|
-
points = []
|
176
|
-
for x, y in items:
|
177
|
-
try:
|
178
|
-
points.append((float(x), float(y)))
|
179
|
-
except (ValueError, TypeError):
|
180
|
-
continue
|
181
|
-
|
182
|
-
if len(points) < 2:
|
183
|
-
return "Need at least 2 data points for line chart"
|
184
|
-
|
185
|
-
points.sort(key=lambda p: p[0])
|
186
|
-
|
187
|
-
# Simple ASCII line chart
|
188
|
-
min_x, max_x = min(p[0] for p in points), max(p[0] for p in points)
|
189
|
-
min_y, max_y = min(p[1] for p in points), max(p[1] for p in points)
|
190
|
-
|
191
|
-
if max_x == min_x or max_y == min_y:
|
192
|
-
return "Cannot display line chart: all values are the same"
|
193
|
-
|
194
|
-
console.print(f"\n[bold]{title}[/bold]")
|
195
|
-
console.print("=" * min(len(title), width))
|
196
|
-
|
197
|
-
# Simple representation
|
198
|
-
for x, y in points:
|
199
|
-
x_norm = int(((x - min_x) / (max_x - min_x)) * (width - 20))
|
200
|
-
y_norm = int(((y - min_y) / (max_y - min_y)) * 10)
|
201
|
-
line = " " * x_norm + "●" + " " * (width - 20 - x_norm)
|
202
|
-
console.print(f"{x:>8.1f}: {line} {y:.1f}")
|
203
|
-
|
204
|
-
return f"✅ Line chart displayed: {title}"
|
205
|
-
|
206
|
-
except Exception as e:
|
207
|
-
return f"❌ Error displaying line chart: {e}"
|
208
|
-
|
209
|
-
def _display_pie(self, console, data, title, width):
|
210
|
-
"""Display data as a simple pie chart representation."""
|
211
|
-
try:
|
212
|
-
if isinstance(data, dict):
|
213
|
-
items = list(data.items())
|
214
|
-
elif isinstance(data, list) and data and isinstance(data[0], dict):
|
215
|
-
keys = list(data[0].keys())
|
216
|
-
if len(keys) >= 2:
|
217
|
-
label_key, value_key = keys[0], keys[1]
|
218
|
-
items = [(item[label_key], item[value_key]) for item in data]
|
219
|
-
else:
|
220
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
221
|
-
else:
|
222
|
-
items = [(str(i), v) for i, v in enumerate(data)]
|
223
|
-
|
224
|
-
# Convert to numeric values
|
225
|
-
values = []
|
226
|
-
for label, value in items:
|
227
|
-
try:
|
228
|
-
values.append((str(label), float(value)))
|
229
|
-
except (ValueError, TypeError):
|
230
|
-
continue
|
231
|
-
|
232
|
-
if not values:
|
233
|
-
return "No valid numeric data to display"
|
234
|
-
|
235
|
-
total = sum(val for _, val in values)
|
236
|
-
if total == 0:
|
237
|
-
return "Cannot display pie chart: total is zero"
|
238
|
-
|
239
|
-
console.print(f"\n[bold]{title}[/bold]")
|
240
|
-
console.print("=" * min(len(title), width))
|
241
|
-
|
242
|
-
# Unicode pie chart segments
|
243
|
-
segments = ["🟦", "🟥", "🟩", "🟨", "🟪", "🟧", "⬛", "⬜"]
|
244
|
-
|
245
|
-
for i, (label, value) in enumerate(values):
|
246
|
-
percentage = (value / total) * 100
|
247
|
-
segment = segments[i % len(segments)]
|
248
|
-
bar_length = int((value / total) * (width - 30))
|
249
|
-
bar = "█" * bar_length
|
250
|
-
console.print(
|
251
|
-
f"{segment} {label:<15} {bar} {percentage:5.1f}% ({value})"
|
252
|
-
)
|
253
|
-
|
254
|
-
console.print(f"\n[dim]Total: {total}[/dim]")
|
255
|
-
|
256
|
-
return f"✅ Pie chart displayed: {title}"
|
257
|
-
|
258
|
-
except Exception as e:
|
259
|
-
return f"❌ Error displaying pie chart: {e}"
|
@@ -1,58 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.plugins.tools.decorators import register_core_tool
|
4
|
-
from janito.tools.tool_utils import pluralize
|
5
|
-
from janito.i18n import tr
|
6
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
7
|
-
|
8
|
-
|
9
|
-
@register_core_tool
|
10
|
-
class ReadFiles(ToolBase):
|
11
|
-
"""
|
12
|
-
Read all text content from multiple files.
|
13
|
-
|
14
|
-
Args:
|
15
|
-
paths (list[str]): List of file paths to read.
|
16
|
-
|
17
|
-
Returns:
|
18
|
-
str: Concatenated content of all files, each prefixed by a header with the file name. If a file cannot be read, an error message is included for that file.
|
19
|
-
"""
|
20
|
-
|
21
|
-
permissions = ToolPermissions(read=True)
|
22
|
-
tool_name = "read_files"
|
23
|
-
|
24
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
|
25
|
-
def run(self, paths: list[str]) -> str:
|
26
|
-
from janito.tools.tool_utils import display_path
|
27
|
-
import os
|
28
|
-
from janito.tools.path_utils import expand_path
|
29
|
-
|
30
|
-
results = []
|
31
|
-
for path in [expand_path(p) for p in paths]:
|
32
|
-
disp_path = display_path(path)
|
33
|
-
self.report_action(
|
34
|
-
tr("📖 Read '{disp_path}'", disp_path=disp_path), ReportAction.READ
|
35
|
-
)
|
36
|
-
if not os.path.isfile(path):
|
37
|
-
self.report_warning(
|
38
|
-
tr("❗ not found: {disp_path}", disp_path=disp_path)
|
39
|
-
)
|
40
|
-
results.append(f"--- File: {disp_path} (not found) ---\n")
|
41
|
-
continue
|
42
|
-
try:
|
43
|
-
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
44
|
-
content = f.read()
|
45
|
-
results.append(f"--- File: {disp_path} ---\n{content}\n")
|
46
|
-
self.report_success(tr("✅ Read {disp_path}", disp_path=disp_path))
|
47
|
-
except Exception as e:
|
48
|
-
self.report_error(
|
49
|
-
tr(
|
50
|
-
" ❌ Error reading {disp_path}: {error}",
|
51
|
-
disp_path=disp_path,
|
52
|
-
error=e,
|
53
|
-
)
|
54
|
-
)
|
55
|
-
results.append(
|
56
|
-
f"--- File: {disp_path} (error) ---\nError reading file: {e}\n"
|
57
|
-
)
|
58
|
-
return "\n".join(results)
|
@@ -1,55 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.plugins.tools.decorators import register_core_tool
|
4
|
-
from janito.tools.tool_utils import pluralize, display_path
|
5
|
-
from janito.i18n import tr
|
6
|
-
import shutil
|
7
|
-
import os
|
8
|
-
import zipfile
|
9
|
-
from janito.tools.path_utils import expand_path
|
10
|
-
|
11
|
-
|
12
|
-
@register_core_tool
|
13
|
-
class RemoveDirectory(ToolBase):
|
14
|
-
"""
|
15
|
-
Remove a directory.
|
16
|
-
|
17
|
-
Args:
|
18
|
-
path (str): Path to the directory to remove.
|
19
|
-
recursive (bool, optional): If True, remove non-empty directories recursively (with backup). If False, only remove empty directories. Defaults to False.
|
20
|
-
Returns:
|
21
|
-
str: Status message indicating result. Example:
|
22
|
-
- "Directory removed: /path/to/dir"
|
23
|
-
- "Error removing directory: <error message>"
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(write=True)
|
27
|
-
tool_name = "remove_directory"
|
28
|
-
|
29
|
-
def run(self, path: str, recursive: bool = False) -> str:
|
30
|
-
path = expand_path(path)
|
31
|
-
disp_path = display_path(path)
|
32
|
-
self.report_action(
|
33
|
-
tr("🗃️ Remove directory '{disp_path}' ...", disp_path=disp_path),
|
34
|
-
ReportAction.DELETE,
|
35
|
-
)
|
36
|
-
|
37
|
-
try:
|
38
|
-
if recursive:
|
39
|
-
|
40
|
-
shutil.rmtree(path)
|
41
|
-
else:
|
42
|
-
os.rmdir(path)
|
43
|
-
self.report_success(
|
44
|
-
tr("✅ 1 {dir_word}", dir_word=pluralize("directory", 1)),
|
45
|
-
ReportAction.DELETE,
|
46
|
-
)
|
47
|
-
msg = tr("Directory removed: {disp_path}", disp_path=disp_path)
|
48
|
-
|
49
|
-
return msg
|
50
|
-
except Exception as e:
|
51
|
-
self.report_error(
|
52
|
-
tr(" ❌ Error removing directory: {error}", error=e),
|
53
|
-
ReportAction.DELETE,
|
54
|
-
)
|
55
|
-
return tr("Error removing directory: {error}", error=e)
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from janito.tools.path_utils import expand_path
|
3
|
-
import shutil
|
4
|
-
from janito.plugins.tools.decorators import register_core_tool
|
5
|
-
|
6
|
-
from janito.tools.tool_utils import display_path
|
7
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
8
|
-
from janito.report_events import ReportAction
|
9
|
-
from janito.i18n import tr
|
10
|
-
|
11
|
-
|
12
|
-
@register_core_tool
|
13
|
-
class RemoveFile(ToolBase):
|
14
|
-
"""
|
15
|
-
Remove a file at the specified path.
|
16
|
-
|
17
|
-
Args:
|
18
|
-
path (str): Path to the file to remove.
|
19
|
-
backup (bool, optional): Deprecated. Backups are no longer created. Flag ignored.
|
20
|
-
Returns:
|
21
|
-
str: Status message indicating the result. Example:
|
22
|
-
- " Successfully removed the file at ..."
|
23
|
-
- " Cannot remove file: ..."
|
24
|
-
"""
|
25
|
-
|
26
|
-
permissions = ToolPermissions(write=True)
|
27
|
-
tool_name = "remove_file"
|
28
|
-
|
29
|
-
def run(self, path: str, backup: bool = False) -> str:
|
30
|
-
path = expand_path(path)
|
31
|
-
disp_path = display_path(path)
|
32
|
-
|
33
|
-
# Report initial info about what is going to be removed
|
34
|
-
self.report_action(
|
35
|
-
tr("🗑️ Remove file '{disp_path}' ...", disp_path=disp_path),
|
36
|
-
ReportAction.DELETE,
|
37
|
-
)
|
38
|
-
if not os.path.exists(path):
|
39
|
-
self.report_error(tr("❌ File does not exist."), ReportAction.DELETE)
|
40
|
-
return tr("❌ File does not exist.")
|
41
|
-
if not os.path.isfile(path):
|
42
|
-
self.report_error(tr("❌ Path is not a file."), ReportAction.DELETE)
|
43
|
-
return tr("❌ Path is not a file.")
|
44
|
-
try:
|
45
|
-
|
46
|
-
os.remove(path)
|
47
|
-
self.report_success(tr("✅ File removed"), ReportAction.DELETE)
|
48
|
-
msg = tr(
|
49
|
-
"✅ Successfully removed the file at '{disp_path}'.",
|
50
|
-
disp_path=disp_path,
|
51
|
-
)
|
52
|
-
|
53
|
-
return msg
|
54
|
-
except Exception as e:
|
55
|
-
self.report_error(
|
56
|
-
tr("❌ Error removing file: {error}", error=e), ReportAction.DELETE
|
57
|
-
)
|
58
|
-
return tr("❌ Error removing file: {error}", error=e)
|
@@ -1,205 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
-
from janito.tools.tool_utils import pluralize, display_path
|
5
|
-
from janito.i18n import tr
|
6
|
-
import os
|
7
|
-
from janito.tools.path_utils import expand_path
|
8
|
-
from .pattern_utils import prepare_pattern, format_result, summarize_total
|
9
|
-
from .match_lines import read_file_lines
|
10
|
-
from .traverse_directory import traverse_directory
|
11
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
12
|
-
|
13
|
-
|
14
|
-
from janito.plugins.tools.decorators import register_core_tool
|
15
|
-
|
16
|
-
|
17
|
-
@register_core_tool
|
18
|
-
class SearchText(ToolBase):
|
19
|
-
"""
|
20
|
-
Search for a text query in all files within one or more directories or file paths and return matching lines or counts. Respects .gitignore.
|
21
|
-
Args:
|
22
|
-
paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
|
23
|
-
query (str): Text or regular expression to search for in files. Must not be empty. When use_regex=True, this is treated as a regex pattern; otherwise as plain text.
|
24
|
-
use_regex (bool): If True, treat query as a regular expression. If False, treat as plain text (default).
|
25
|
-
case_sensitive (bool): If False, perform a case-insensitive search. Default is True (case sensitive).
|
26
|
-
max_depth (int, optional): Maximum directory depth to search. If 0 (default), search is recursive with no depth limit. If >0, limits recursion to that depth. Setting max_depth=1 disables recursion (only top-level directory). Ignored for file paths.
|
27
|
-
max_results (int, optional): Maximum number of results to return. Defaults to 100. 0 means no limit.
|
28
|
-
count_only (bool): If True, return only the count of matches per file and total, not the matching lines. Default is False.
|
29
|
-
Returns:
|
30
|
-
str: If count_only is False, matching lines from files as a newline-separated string, each formatted as 'filepath:lineno: line'.
|
31
|
-
If count_only is True, returns per-file and total match counts.
|
32
|
-
If max_results is reached, appends a note to the output.
|
33
|
-
"""
|
34
|
-
|
35
|
-
permissions = ToolPermissions(read=True)
|
36
|
-
tool_name = "search_text"
|
37
|
-
|
38
|
-
def _handle_file(
|
39
|
-
self,
|
40
|
-
search_path,
|
41
|
-
query,
|
42
|
-
regex,
|
43
|
-
use_regex,
|
44
|
-
case_sensitive,
|
45
|
-
max_results,
|
46
|
-
total_results,
|
47
|
-
count_only,
|
48
|
-
):
|
49
|
-
if count_only:
|
50
|
-
match_count, dir_limit_reached, _ = read_file_lines(
|
51
|
-
search_path,
|
52
|
-
query,
|
53
|
-
regex,
|
54
|
-
use_regex,
|
55
|
-
case_sensitive,
|
56
|
-
True,
|
57
|
-
max_results,
|
58
|
-
total_results,
|
59
|
-
)
|
60
|
-
per_file_counts = [(search_path, match_count)] if match_count > 0 else []
|
61
|
-
return [], dir_limit_reached, per_file_counts
|
62
|
-
else:
|
63
|
-
dir_output, dir_limit_reached, match_count_list = read_file_lines(
|
64
|
-
search_path,
|
65
|
-
query,
|
66
|
-
regex,
|
67
|
-
use_regex,
|
68
|
-
case_sensitive,
|
69
|
-
False,
|
70
|
-
max_results,
|
71
|
-
total_results,
|
72
|
-
)
|
73
|
-
per_file_counts = (
|
74
|
-
[(search_path, len(match_count_list))]
|
75
|
-
if match_count_list and len(match_count_list) > 0
|
76
|
-
else []
|
77
|
-
)
|
78
|
-
return dir_output, dir_limit_reached, per_file_counts
|
79
|
-
|
80
|
-
def _handle_path(
|
81
|
-
self,
|
82
|
-
search_path,
|
83
|
-
query,
|
84
|
-
regex,
|
85
|
-
use_regex,
|
86
|
-
case_sensitive,
|
87
|
-
max_depth,
|
88
|
-
max_results,
|
89
|
-
total_results,
|
90
|
-
count_only,
|
91
|
-
):
|
92
|
-
info_str = tr(
|
93
|
-
"🔍 Search {search_type} '{query}' in '{disp_path}'",
|
94
|
-
search_type=("regex" if use_regex else "text"),
|
95
|
-
query=query,
|
96
|
-
disp_path=display_path(search_path),
|
97
|
-
)
|
98
|
-
if max_depth > 0:
|
99
|
-
info_str += tr(" [max_depth={max_depth}]", max_depth=max_depth)
|
100
|
-
if count_only:
|
101
|
-
info_str += " [count]"
|
102
|
-
self.report_action(info_str, ReportAction.READ)
|
103
|
-
if os.path.isfile(search_path):
|
104
|
-
dir_output, dir_limit_reached, per_file_counts = self._handle_file(
|
105
|
-
search_path,
|
106
|
-
query,
|
107
|
-
regex,
|
108
|
-
use_regex,
|
109
|
-
case_sensitive,
|
110
|
-
max_results,
|
111
|
-
total_results,
|
112
|
-
count_only,
|
113
|
-
)
|
114
|
-
else:
|
115
|
-
if count_only:
|
116
|
-
per_file_counts, dir_limit_reached, _ = traverse_directory(
|
117
|
-
search_path,
|
118
|
-
query,
|
119
|
-
regex,
|
120
|
-
use_regex,
|
121
|
-
case_sensitive,
|
122
|
-
max_depth,
|
123
|
-
max_results,
|
124
|
-
total_results,
|
125
|
-
True,
|
126
|
-
)
|
127
|
-
dir_output = []
|
128
|
-
else:
|
129
|
-
dir_output, dir_limit_reached, per_file_counts = traverse_directory(
|
130
|
-
search_path,
|
131
|
-
query,
|
132
|
-
regex,
|
133
|
-
use_regex,
|
134
|
-
case_sensitive,
|
135
|
-
max_depth,
|
136
|
-
max_results,
|
137
|
-
total_results,
|
138
|
-
False,
|
139
|
-
)
|
140
|
-
count = sum(count for _, count in per_file_counts)
|
141
|
-
file_word = pluralize("match", count)
|
142
|
-
num_files = len(per_file_counts)
|
143
|
-
file_label = pluralize("file", num_files)
|
144
|
-
file_word_max = file_word + (" (max)" if dir_limit_reached else "")
|
145
|
-
self.report_success(
|
146
|
-
tr(
|
147
|
-
" ✅ {count} {file_word}/{num_files} {file_label}",
|
148
|
-
count=count,
|
149
|
-
file_word=file_word_max,
|
150
|
-
num_files=num_files,
|
151
|
-
file_label=file_label,
|
152
|
-
),
|
153
|
-
ReportAction.READ,
|
154
|
-
)
|
155
|
-
return info_str, dir_output, dir_limit_reached, per_file_counts
|
156
|
-
|
157
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
|
158
|
-
def run(
|
159
|
-
self,
|
160
|
-
paths: str,
|
161
|
-
query: str,
|
162
|
-
use_regex: bool = False,
|
163
|
-
case_sensitive: bool = False,
|
164
|
-
max_depth: int = 0,
|
165
|
-
max_results: int = 100,
|
166
|
-
count_only: bool = False,
|
167
|
-
) -> str:
|
168
|
-
regex, use_regex, error_msg = prepare_pattern(
|
169
|
-
query, use_regex, case_sensitive, self.report_error, self.report_warning
|
170
|
-
)
|
171
|
-
if error_msg:
|
172
|
-
return error_msg
|
173
|
-
paths_list = [expand_path(p) for p in paths.split()]
|
174
|
-
results = []
|
175
|
-
all_per_file_counts = []
|
176
|
-
for search_path in paths_list:
|
177
|
-
info_str, dir_output, dir_limit_reached, per_file_counts = (
|
178
|
-
self._handle_path(
|
179
|
-
search_path,
|
180
|
-
query,
|
181
|
-
regex,
|
182
|
-
use_regex,
|
183
|
-
case_sensitive,
|
184
|
-
max_depth,
|
185
|
-
max_results,
|
186
|
-
0,
|
187
|
-
count_only,
|
188
|
-
)
|
189
|
-
)
|
190
|
-
if count_only:
|
191
|
-
all_per_file_counts.extend(per_file_counts)
|
192
|
-
result_str = format_result(
|
193
|
-
query,
|
194
|
-
use_regex,
|
195
|
-
dir_output,
|
196
|
-
dir_limit_reached,
|
197
|
-
count_only,
|
198
|
-
per_file_counts,
|
199
|
-
)
|
200
|
-
results.append(info_str + "\n" + result_str)
|
201
|
-
if dir_limit_reached:
|
202
|
-
break
|
203
|
-
if count_only:
|
204
|
-
results.append(summarize_total(all_per_file_counts))
|
205
|
-
return "\n\n".join(results)
|