janito 3.14.1__py3-none-any.whl → 3.15.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 (38) hide show
  1. janito/platform_discovery.py +1 -8
  2. janito/plugins/tools/local/adapter.py +3 -2
  3. janito/plugins/tools/local/ask_user.py +111 -112
  4. janito/plugins/tools/local/copy_file.py +86 -87
  5. janito/plugins/tools/local/create_directory.py +111 -112
  6. janito/plugins/tools/local/create_file.py +0 -1
  7. janito/plugins/tools/local/delete_text_in_file.py +133 -134
  8. janito/plugins/tools/local/fetch_url.py +465 -466
  9. janito/plugins/tools/local/find_files.py +142 -143
  10. janito/plugins/tools/local/markdown_view.py +0 -1
  11. janito/plugins/tools/local/move_file.py +130 -131
  12. janito/plugins/tools/local/open_html_in_browser.py +50 -51
  13. janito/plugins/tools/local/open_url.py +36 -37
  14. janito/plugins/tools/local/python_code_run.py +171 -172
  15. janito/plugins/tools/local/python_command_run.py +170 -171
  16. janito/plugins/tools/local/python_file_run.py +171 -172
  17. janito/plugins/tools/local/read_chart.py +258 -259
  18. janito/plugins/tools/local/read_files.py +57 -58
  19. janito/plugins/tools/local/remove_directory.py +54 -55
  20. janito/plugins/tools/local/remove_file.py +57 -58
  21. janito/plugins/tools/local/replace_text_in_file.py +275 -276
  22. janito/plugins/tools/local/run_bash_command.py +182 -183
  23. janito/plugins/tools/local/run_powershell_command.py +217 -218
  24. janito/plugins/tools/local/show_image.py +0 -1
  25. janito/plugins/tools/local/show_image_grid.py +0 -1
  26. janito/plugins/tools/local/view_file.py +0 -1
  27. janito/providers/alibaba/provider.py +1 -1
  28. janito/providers/deepseek/model_info.py +16 -37
  29. janito/providers/deepseek/provider.py +4 -3
  30. janito/tools/base.py +19 -12
  31. janito/tools/tool_base.py +122 -121
  32. janito/tools/tools_schema.py +104 -104
  33. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/METADATA +9 -32
  34. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/RECORD +38 -38
  35. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/WHEEL +0 -0
  36. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/entry_points.txt +0 -0
  37. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/licenses/LICENSE +0 -0
  38. {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/top_level.txt +0 -0
@@ -1,259 +1,258 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from janito.plugins.tools.local.adapter import register_local_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_local_tool
12
- class ReadChartTool(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
+ from janito.tools.tool_base import ToolBase, ToolPermissions
2
+ from janito.report_events import ReportAction
3
+ from janito.plugins.tools.local.adapter import register_local_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_local_tool
12
+ class ReadChartTool(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
+
28
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="data")
29
+ def run(
30
+ self, data: dict, title: str = "Chart", width: int = 80, height: int = 20
31
+ ) -> str:
32
+ try:
33
+ from rich.console import Console
34
+ from rich.table import Table
35
+ from rich.text import Text
36
+ from rich.layout import Layout
37
+ from rich.panel import Panel
38
+ from rich.columns import Columns
39
+ from rich import box
40
+
41
+ console = Console(width=width)
42
+
43
+ if not isinstance(data, dict):
44
+ return "❌ Error: Data must be a dictionary"
45
+
46
+ chart_type = data.get("type", "table").lower()
47
+ chart_data = data.get("data", [])
48
+
49
+ if not chart_data:
50
+ return "⚠️ Warning: No data provided for chart"
51
+
52
+ self.report_action(
53
+ tr(
54
+ "📊 Displaying {chart_type} chart: {title}",
55
+ chart_type=chart_type,
56
+ title=title,
57
+ ),
58
+ ReportAction.READ,
59
+ )
60
+
61
+ if chart_type == "table":
62
+ return self._display_table(console, chart_data, title, width)
63
+ elif chart_type == "bar":
64
+ return self._display_bar(console, chart_data, title, width, height)
65
+ elif chart_type == "line":
66
+ return self._display_line(console, chart_data, title, width, height)
67
+ elif chart_type == "pie":
68
+ return self._display_pie(console, chart_data, title, width)
69
+ else:
70
+ return f"❌ Error: Unsupported chart type '{chart_type}'. Use: table, bar, line, pie"
71
+
72
+ except ImportError:
73
+ return "❌ Error: rich library not available for chart display"
74
+ except Exception as e:
75
+ return f"❌ Error displaying chart: {e}"
76
+
77
+ def _display_table(self, console, data, title, width):
78
+ """Display data as a rich table."""
79
+ from rich.table import Table
80
+
81
+ if not data:
82
+ return "No data to display"
83
+
84
+ table = Table(title=title, show_header=True, header_style="bold magenta")
85
+
86
+ # Handle different data formats
87
+ if isinstance(data, dict):
88
+ # Dictionary format: key-value pairs
89
+ table.add_column("Key", style="cyan")
90
+ table.add_column("Value", style="green")
91
+ for key, value in data.items():
92
+ table.add_row(str(key), str(value))
93
+ elif isinstance(data, list):
94
+ if data and isinstance(data[0], dict):
95
+ # List of dictionaries (records)
96
+ headers = list(data[0].keys()) if data else []
97
+ for header in headers:
98
+ table.add_column(str(header).title(), style="cyan")
99
+ for row in data:
100
+ table.add_row(*[str(row.get(h, "")) for h in headers])
101
+ else:
102
+ # Simple list
103
+ table.add_column("Items", style="cyan")
104
+ for item in data:
105
+ table.add_row(str(item))
106
+
107
+ console.print(table)
108
+ return f"✅ Table chart displayed: {title}"
109
+
110
+ def _display_bar(self, console, data, title, width, height):
111
+ """Display data as a simple bar chart using unicode blocks."""
112
+ try:
113
+ if isinstance(data, dict):
114
+ items = list(data.items())
115
+ elif isinstance(data, list) and data and isinstance(data[0], dict):
116
+ # Assume first two keys are labels and values
117
+ keys = list(data[0].keys())
118
+ if len(keys) >= 2:
119
+ label_key, value_key = keys[0], keys[1]
120
+ items = [(item[label_key], item[value_key]) for item in data]
121
+ else:
122
+ items = [(str(i), v) for i, v in enumerate(data)]
123
+ else:
124
+ items = [(str(i), v) for i, v in enumerate(data)]
125
+
126
+ if not items:
127
+ return "No data to display"
128
+
129
+ # Convert values to numbers
130
+ numeric_items = []
131
+ for label, value in items:
132
+ try:
133
+ numeric_items.append((str(label), float(value)))
134
+ except (ValueError, TypeError):
135
+ numeric_items.append((str(label), 0.0))
136
+
137
+ if not numeric_items:
138
+ return "No valid numeric data to display"
139
+
140
+ max_val = max(val for _, val in numeric_items) if numeric_items else 1
141
+
142
+ console.print(f"\n[bold]{title}[/bold]")
143
+ console.print("=" * min(len(title), width))
144
+
145
+ for label, value in numeric_items:
146
+ bar_length = int((value / max_val) * (width - 20)) if max_val > 0 else 0
147
+ bar = "█" * bar_length
148
+ console.print(f"{label:<15} {bar} {value:.1f}")
149
+
150
+ return f"✅ Bar chart displayed: {title}"
151
+
152
+ except Exception as e:
153
+ return f"❌ Error displaying bar chart: {e}"
154
+
155
+ def _display_line(self, console, data, title, width, height):
156
+ """Display data as a simple line chart using unicode characters."""
157
+ try:
158
+ if isinstance(data, dict):
159
+ items = list(data.items())
160
+ elif isinstance(data, list):
161
+ if data and isinstance(data[0], dict):
162
+ keys = list(data[0].keys())
163
+ if len(keys) >= 2:
164
+ label_key, value_key = keys[0], keys[1]
165
+ items = [(item[label_key], item[value_key]) for item in data]
166
+ else:
167
+ items = [(str(i), v) for i, v in enumerate(data)]
168
+ else:
169
+ items = [(str(i), v) for i, v in enumerate(data)]
170
+ else:
171
+ return "Unsupported data format"
172
+
173
+ # Convert to numeric values
174
+ points = []
175
+ for x, y in items:
176
+ try:
177
+ points.append((float(x), float(y)))
178
+ except (ValueError, TypeError):
179
+ continue
180
+
181
+ if len(points) < 2:
182
+ return "Need at least 2 data points for line chart"
183
+
184
+ points.sort(key=lambda p: p[0])
185
+
186
+ # Simple ASCII line chart
187
+ min_x, max_x = min(p[0] for p in points), max(p[0] for p in points)
188
+ min_y, max_y = min(p[1] for p in points), max(p[1] for p in points)
189
+
190
+ if max_x == min_x or max_y == min_y:
191
+ return "Cannot display line chart: all values are the same"
192
+
193
+ console.print(f"\n[bold]{title}[/bold]")
194
+ console.print("=" * min(len(title), width))
195
+
196
+ # Simple representation
197
+ for x, y in points:
198
+ x_norm = int(((x - min_x) / (max_x - min_x)) * (width - 20))
199
+ y_norm = int(((y - min_y) / (max_y - min_y)) * 10)
200
+ line = " " * x_norm + "●" + " " * (width - 20 - x_norm)
201
+ console.print(f"{x:>8.1f}: {line} {y:.1f}")
202
+
203
+ return f"✅ Line chart displayed: {title}"
204
+
205
+ except Exception as e:
206
+ return f"❌ Error displaying line chart: {e}"
207
+
208
+ def _display_pie(self, console, data, title, width):
209
+ """Display data as a simple pie chart representation."""
210
+ try:
211
+ if isinstance(data, dict):
212
+ items = list(data.items())
213
+ elif isinstance(data, list) and data and isinstance(data[0], dict):
214
+ keys = list(data[0].keys())
215
+ if len(keys) >= 2:
216
+ label_key, value_key = keys[0], keys[1]
217
+ items = [(item[label_key], item[value_key]) for item in data]
218
+ else:
219
+ items = [(str(i), v) for i, v in enumerate(data)]
220
+ else:
221
+ items = [(str(i), v) for i, v in enumerate(data)]
222
+
223
+ # Convert to numeric values
224
+ values = []
225
+ for label, value in items:
226
+ try:
227
+ values.append((str(label), float(value)))
228
+ except (ValueError, TypeError):
229
+ continue
230
+
231
+ if not values:
232
+ return "No valid numeric data to display"
233
+
234
+ total = sum(val for _, val in values)
235
+ if total == 0:
236
+ return "Cannot display pie chart: total is zero"
237
+
238
+ console.print(f"\n[bold]{title}[/bold]")
239
+ console.print("=" * min(len(title), width))
240
+
241
+ # Unicode pie chart segments
242
+ segments = ["🟦", "🟥", "🟩", "🟨", "🟪", "🟧", "⬛", "⬜"]
243
+
244
+ for i, (label, value) in enumerate(values):
245
+ percentage = (value / total) * 100
246
+ segment = segments[i % len(segments)]
247
+ bar_length = int((value / total) * (width - 30))
248
+ bar = "█" * bar_length
249
+ console.print(
250
+ f"{segment} {label:<15} {bar} {percentage:5.1f}% ({value})"
251
+ )
252
+
253
+ console.print(f"\n[dim]Total: {total}[/dim]")
254
+
255
+ return f"✅ Pie chart displayed: {title}"
256
+
257
+ except Exception as e:
258
+ return f"❌ Error displaying pie chart: {e}"
@@ -1,58 +1,57 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from janito.plugins.tools.local.adapter import register_local_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_local_tool
10
- class ReadFilesTool(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=""))
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
+ from janito.tools.tool_base import ToolBase, ToolPermissions
2
+ from janito.report_events import ReportAction
3
+ from janito.plugins.tools.local.adapter import register_local_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_local_tool
10
+ class ReadFilesTool(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
+
23
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
24
+ def run(self, paths: list[str]) -> str:
25
+ from janito.tools.tool_utils import display_path
26
+ import os
27
+ from janito.tools.path_utils import expand_path
28
+
29
+ results = []
30
+ for path in [expand_path(p) for p in paths]:
31
+ disp_path = display_path(path)
32
+ self.report_action(
33
+ tr("📖 Read '{disp_path}'", disp_path=disp_path), ReportAction.READ
34
+ )
35
+ if not os.path.isfile(path):
36
+ self.report_warning(
37
+ tr("❗ not found: {disp_path}", disp_path=disp_path)
38
+ )
39
+ results.append(f"--- File: {disp_path} (not found) ---\n")
40
+ continue
41
+ try:
42
+ with open(path, "r", encoding="utf-8", errors="replace") as f:
43
+ content = f.read()
44
+ results.append(f"--- File: {disp_path} ---\n{content}\n")
45
+ self.report_success(tr(" Read {disp_path}", disp_path=""))
46
+ except Exception as e:
47
+ self.report_error(
48
+ tr(
49
+ " ❌ Error reading {disp_path}: {error}",
50
+ disp_path=disp_path,
51
+ error=e,
52
+ )
53
+ )
54
+ results.append(
55
+ f"--- File: {disp_path} (error) ---\nError reading file: {e}\n"
56
+ )
57
+ return "\n".join(results)