janito 3.4.0__py3-none-any.whl → 3.5.1__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 (159) hide show
  1. janito/README.md +3 -0
  2. janito/cli/chat_mode/bindings.py +50 -0
  3. janito/cli/chat_mode/session.py +12 -1
  4. janito/cli/chat_mode/shell/commands/multi.py +5 -0
  5. janito/cli/chat_mode/shell/commands/security/allowed_sites.py +47 -33
  6. janito/cli/cli_commands/check_tools.py +212 -0
  7. janito/cli/cli_commands/list_plugins.py +52 -43
  8. janito/cli/core/getters.py +3 -0
  9. janito/cli/core/model_guesser.py +40 -24
  10. janito/cli/main_cli.py +9 -12
  11. janito/cli/prompt_core.py +47 -9
  12. janito/cli/rich_terminal_reporter.py +2 -2
  13. janito/drivers/openai/driver.py +1 -0
  14. janito/drivers/zai/driver.py +1 -0
  15. janito/i18n/it.py +46 -46
  16. janito/llm/agent.py +32 -16
  17. janito/llm/auth_utils.py +14 -5
  18. janito/llm/cancellation_manager.py +63 -0
  19. janito/llm/driver.py +8 -0
  20. janito/llm/enter_cancellation.py +107 -0
  21. janito/plugin_system/__init__.py +10 -0
  22. janito/{plugins → plugin_system}/base.py +5 -2
  23. janito/plugin_system/core_loader.py +217 -0
  24. janito/plugin_system/core_loader_fixed.py +225 -0
  25. janito/plugins/__init__.py +31 -12
  26. janito/plugins/auto_loader.py +12 -11
  27. janito/plugins/auto_loader_fixed.py +12 -11
  28. janito/plugins/builtin.py +15 -1
  29. janito/plugins/core/__init__.py +7 -0
  30. janito/plugins/core/codeanalyzer/__init__.py +43 -0
  31. janito/plugins/core/filemanager/__init__.py +124 -0
  32. janito/plugins/core/filemanager/tools/create_file.py +87 -0
  33. janito/plugins/core/filemanager/tools/replace_text_in_file.py +270 -0
  34. janito/plugins/core/imagedisplay/__init__.py +14 -0
  35. janito/plugins/core/imagedisplay/plugin.py +51 -0
  36. janito/plugins/core/imagedisplay/tools/__init__.py +1 -0
  37. janito/plugins/core/imagedisplay/tools/show_image.py +83 -0
  38. janito/{tools/adapters/local → plugins/core/imagedisplay/tools}/show_image_grid.py +13 -5
  39. janito/plugins/core/system/__init__.py +23 -0
  40. janito/plugins/core/system/tools/run_bash_command.py +204 -0
  41. janito/plugins/core/system/tools/run_powershell_command.py +234 -0
  42. janito/plugins/core_adapter.py +89 -11
  43. janito/plugins/dev/__init__.py +7 -0
  44. janito/plugins/dev/pythondev/__init__.py +37 -0
  45. janito/plugins/dev/visualization/__init__.py +23 -0
  46. janito/plugins/discovery.py +5 -5
  47. janito/plugins/discovery_core.py +14 -9
  48. janito/plugins/example_plugin.py +108 -0
  49. janito/plugins/manager.py +1 -1
  50. janito/plugins/tools/__init__.py +10 -0
  51. janito/{tools/adapters/local → plugins/tools}/ask_user.py +3 -3
  52. janito/plugins/tools/copy_file.py +87 -0
  53. janito/plugins/tools/core_tools_plugin.py +87 -0
  54. janito/plugins/tools/create_directory.py +70 -0
  55. janito/{tools/adapters/local → plugins/tools}/create_file.py +6 -6
  56. janito/plugins/tools/decorators.py +19 -0
  57. janito/plugins/tools/delete_text_in_file.py +134 -0
  58. janito/{tools/adapters/local → plugins/tools}/fetch_url.py +3 -3
  59. janito/plugins/tools/find_files.py +143 -0
  60. janito/plugins/tools/get_file_outline/__init__.py +7 -0
  61. janito/plugins/tools/get_file_outline/core.py +122 -0
  62. janito/plugins/tools/get_file_outline/java_outline.py +47 -0
  63. janito/plugins/tools/get_file_outline/markdown_outline.py +14 -0
  64. janito/plugins/tools/get_file_outline/python_outline.py +303 -0
  65. janito/plugins/tools/get_file_outline/search_outline.py +36 -0
  66. janito/plugins/tools/move_file.py +131 -0
  67. janito/plugins/tools/open_html_in_browser.py +51 -0
  68. janito/plugins/tools/open_url.py +37 -0
  69. janito/{tools/adapters/local → plugins/tools}/python_code_run.py +23 -7
  70. janito/{tools/adapters/local → plugins/tools}/python_command_run.py +21 -5
  71. janito/{tools/adapters/local → plugins/tools}/python_file_run.py +21 -5
  72. janito/plugins/tools/read_chart.py +259 -0
  73. janito/plugins/tools/read_files.py +58 -0
  74. janito/plugins/tools/remove_directory.py +55 -0
  75. janito/plugins/tools/remove_file.py +58 -0
  76. janito/{tools/adapters/local → plugins/tools}/replace_text_in_file.py +4 -4
  77. janito/{tools/adapters/local → plugins/tools}/run_bash_command.py +3 -3
  78. janito/{tools/adapters/local → plugins/tools}/run_powershell_command.py +3 -3
  79. janito/plugins/tools/search_text/__init__.py +7 -0
  80. janito/plugins/tools/search_text/core.py +205 -0
  81. janito/plugins/tools/search_text/match_lines.py +67 -0
  82. janito/plugins/tools/search_text/pattern_utils.py +73 -0
  83. janito/plugins/tools/search_text/traverse_directory.py +145 -0
  84. janito/{tools/adapters/local → plugins/tools}/show_image.py +15 -6
  85. janito/plugins/tools/show_image_grid.py +85 -0
  86. janito/plugins/tools/validate_file_syntax/__init__.py +7 -0
  87. janito/plugins/tools/validate_file_syntax/core.py +114 -0
  88. janito/plugins/tools/validate_file_syntax/css_validator.py +35 -0
  89. janito/plugins/tools/validate_file_syntax/html_validator.py +100 -0
  90. janito/plugins/tools/validate_file_syntax/jinja2_validator.py +50 -0
  91. janito/plugins/tools/validate_file_syntax/js_validator.py +27 -0
  92. janito/plugins/tools/validate_file_syntax/json_validator.py +6 -0
  93. janito/plugins/tools/validate_file_syntax/markdown_validator.py +109 -0
  94. janito/plugins/tools/validate_file_syntax/ps1_validator.py +32 -0
  95. janito/plugins/tools/validate_file_syntax/python_validator.py +5 -0
  96. janito/plugins/tools/validate_file_syntax/xml_validator.py +11 -0
  97. janito/plugins/tools/validate_file_syntax/yaml_validator.py +6 -0
  98. janito/plugins/tools/view_file.py +172 -0
  99. janito/plugins/ui/__init__.py +7 -0
  100. janito/plugins/ui/userinterface/__init__.py +16 -0
  101. janito/plugins/ui/userinterface/tools/ask_user.py +110 -0
  102. janito/plugins/web/__init__.py +7 -0
  103. janito/plugins/web/webtools/__init__.py +33 -0
  104. janito/plugins/web/webtools/tools/fetch_url.py +458 -0
  105. janito/providers/__init__.py +1 -0
  106. janito/providers/together/__init__.py +1 -0
  107. janito/providers/together/model_info.py +69 -0
  108. janito/providers/together/provider.py +108 -0
  109. janito/tools/__init__.py +31 -7
  110. janito/tools/adapters/__init__.py +6 -1
  111. janito/tools/adapters/local/__init__.py +7 -70
  112. janito/tools/cli_initializer.py +88 -0
  113. janito/tools/initialize.py +70 -0
  114. janito/tools/loop_protection_decorator.py +114 -117
  115. janito-3.5.1.dist-info/METADATA +229 -0
  116. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/RECORD +155 -86
  117. janito/plugins/core_loader.py +0 -120
  118. janito/plugins/core_loader_fixed.py +0 -125
  119. janito/tools/function_adapter.py +0 -65
  120. janito-3.4.0.dist-info/METADATA +0 -84
  121. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/__init__.py +0 -0
  122. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/core.py +0 -0
  123. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/java_outline.py +0 -0
  124. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/markdown_outline.py +0 -0
  125. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/python_outline.py +0 -0
  126. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/search_outline.py +0 -0
  127. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/__init__.py +0 -0
  128. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/core.py +0 -0
  129. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/match_lines.py +0 -0
  130. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/pattern_utils.py +0 -0
  131. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/traverse_directory.py +0 -0
  132. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/copy_file.py +0 -0
  133. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/create_directory.py +0 -0
  134. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/delete_text_in_file.py +0 -0
  135. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/find_files.py +0 -0
  136. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/move_file.py +0 -0
  137. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/read_files.py +0 -0
  138. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_directory.py +0 -0
  139. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_file.py +0 -0
  140. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/__init__.py +0 -0
  141. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/core.py +0 -0
  142. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/css_validator.py +0 -0
  143. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/html_validator.py +0 -0
  144. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/jinja2_validator.py +0 -0
  145. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/js_validator.py +0 -0
  146. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/json_validator.py +0 -0
  147. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/markdown_validator.py +0 -0
  148. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/ps1_validator.py +0 -0
  149. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/python_validator.py +0 -0
  150. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/xml_validator.py +0 -0
  151. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/yaml_validator.py +0 -0
  152. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/view_file.py +0 -0
  153. /janito/{tools/adapters/local → plugins/dev/visualization/tools}/read_chart.py +0 -0
  154. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_html_in_browser.py +0 -0
  155. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_url.py +0 -0
  156. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/WHEEL +0 -0
  157. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/entry_points.txt +0 -0
  158. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/licenses/LICENSE +0 -0
  159. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,205 @@
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)
@@ -0,0 +1,67 @@
1
+ import re
2
+ from janito.gitignore_utils import GitignoreFilter
3
+ import os
4
+
5
+
6
+ def is_binary_file(path, blocksize=1024):
7
+ try:
8
+ with open(path, "rb") as f:
9
+ chunk = f.read(blocksize)
10
+ if b"\0" in chunk:
11
+ return True
12
+ text_characters = bytearray(
13
+ {7, 8, 9, 10, 12, 13, 27} | set(range(0x20, 0x100))
14
+ )
15
+ nontext = chunk.translate(None, text_characters)
16
+ if len(nontext) / max(1, len(chunk)) > 0.3:
17
+ return True
18
+ except Exception:
19
+ return True
20
+ return False
21
+
22
+
23
+ def match_line(line, query, regex, use_regex, case_sensitive):
24
+ if use_regex:
25
+ return regex and regex.search(line)
26
+ if not case_sensitive:
27
+ return query.lower() in line.lower()
28
+ return query in line
29
+
30
+
31
+ def should_limit(max_results, total_results, match_count, count_only, dir_output):
32
+ if max_results > 0:
33
+ current_count = total_results + (match_count if count_only else len(dir_output))
34
+ return current_count >= max_results
35
+ return False
36
+
37
+
38
+ def read_file_lines(
39
+ path,
40
+ query,
41
+ regex,
42
+ use_regex,
43
+ case_sensitive,
44
+ count_only,
45
+ max_results,
46
+ total_results,
47
+ ):
48
+ dir_output = []
49
+ dir_limit_reached = False
50
+ match_count = 0
51
+ if not is_binary_file(path):
52
+ try:
53
+ open_kwargs = {"mode": "r", "encoding": "utf-8"}
54
+ with open(path, **open_kwargs) as f:
55
+ for lineno, line in enumerate(f, 1):
56
+ if match_line(line, query, regex, use_regex, case_sensitive):
57
+ match_count += 1
58
+ if not count_only:
59
+ dir_output.append(f"{path}:{lineno}: {line.rstrip()}")
60
+ if should_limit(
61
+ max_results, total_results, match_count, count_only, dir_output
62
+ ):
63
+ dir_limit_reached = True
64
+ break
65
+ except Exception:
66
+ pass
67
+ return match_count, dir_limit_reached, dir_output
@@ -0,0 +1,73 @@
1
+ import re
2
+ from janito.i18n import tr
3
+ from janito.tools.tool_utils import pluralize
4
+
5
+
6
+ def prepare_pattern(pattern, is_regex, case_sensitive, report_error, report_warning):
7
+ if not pattern:
8
+ report_error(
9
+ tr("Error: Empty search pattern provided. Operation aborted."),
10
+ ReportAction.SEARCH,
11
+ )
12
+ return (
13
+ None,
14
+ False,
15
+ tr("Error: Empty search pattern provided. Operation aborted."),
16
+ )
17
+ regex = None
18
+ use_regex = False
19
+ if is_regex:
20
+ try:
21
+ flags = 0
22
+ if not case_sensitive:
23
+ flags |= re.IGNORECASE
24
+ regex = re.compile(pattern, flags=flags)
25
+ use_regex = True
26
+ except re.error as e:
27
+ report_warning(tr("⚠️ Invalid regex pattern."))
28
+ return (
29
+ None,
30
+ False,
31
+ tr(
32
+ "Error: Invalid regex pattern: {error}. Operation aborted.", error=e
33
+ ),
34
+ )
35
+ else:
36
+ # Do not compile as regex if is_regex is False; treat as plain text
37
+ regex = None
38
+ use_regex = False
39
+ if not case_sensitive:
40
+ pattern = pattern.lower()
41
+ return regex, use_regex, None
42
+
43
+
44
+ def format_result(
45
+ query, use_regex, output, limit_reached, count_only=False, per_file_counts=None
46
+ ):
47
+ # Ensure output is always a list for joining
48
+ if output is None or not isinstance(output, (list, tuple)):
49
+ output = []
50
+ if count_only:
51
+ lines = []
52
+ total = 0
53
+ if per_file_counts:
54
+ for path, count in per_file_counts:
55
+ lines.append(f"{path}: {count}")
56
+ total += count
57
+ lines.append(f"Total matches: {total}")
58
+ if limit_reached:
59
+ lines.append(tr("[Max results reached. Output truncated.]"))
60
+ return "\n".join(lines)
61
+ else:
62
+ if not output:
63
+ return tr("No matches found.")
64
+ result = "\n".join(output)
65
+ if limit_reached:
66
+ result += tr("\n[Max results reached. Output truncated.]")
67
+ return result
68
+
69
+
70
+ def summarize_total(all_per_file_counts):
71
+ total = sum(count for _, count in all_per_file_counts)
72
+ summary = f"\nGrand total matches: {total}"
73
+ return summary
@@ -0,0 +1,145 @@
1
+ import os
2
+ from janito.gitignore_utils import GitignoreFilter
3
+ from .match_lines import match_line, should_limit, read_file_lines
4
+
5
+
6
+ def walk_directory(search_path, max_depth):
7
+ if max_depth == 1:
8
+ walk_result = next(os.walk(search_path), None)
9
+ if walk_result is None:
10
+ return [(search_path, [], [])]
11
+ else:
12
+ return [walk_result]
13
+ else:
14
+ return os.walk(search_path)
15
+
16
+
17
+ def filter_dirs(dirs, root, gitignore_filter):
18
+ # Always exclude directories named .git, regardless of gitignore
19
+ return [
20
+ d
21
+ for d in dirs
22
+ if d != ".git" and not gitignore_filter.is_ignored(os.path.join(root, d))
23
+ ]
24
+
25
+
26
+ def process_file_count_only(
27
+ path,
28
+ per_file_counts,
29
+ query,
30
+ regex,
31
+ use_regex,
32
+ case_sensitive,
33
+ max_results,
34
+ total_results,
35
+ ):
36
+ match_count, file_limit_reached, _ = read_file_lines(
37
+ path,
38
+ query,
39
+ regex,
40
+ use_regex,
41
+ case_sensitive,
42
+ True,
43
+ max_results,
44
+ total_results + sum(count for _, count in per_file_counts),
45
+ )
46
+ if match_count > 0:
47
+ per_file_counts.append((path, match_count))
48
+ return file_limit_reached
49
+
50
+
51
+ def process_file_collect(
52
+ path,
53
+ dir_output,
54
+ per_file_counts,
55
+ query,
56
+ regex,
57
+ use_regex,
58
+ case_sensitive,
59
+ max_results,
60
+ total_results,
61
+ ):
62
+ actual_match_count, file_limit_reached, file_lines_output = read_file_lines(
63
+ path,
64
+ query,
65
+ regex,
66
+ use_regex,
67
+ case_sensitive,
68
+ False,
69
+ max_results,
70
+ total_results + len(dir_output),
71
+ )
72
+ dir_output.extend(file_lines_output)
73
+ if actual_match_count > 0:
74
+ per_file_counts.append((path, actual_match_count))
75
+ return file_limit_reached
76
+
77
+
78
+ def should_limit_depth(root, search_path, max_depth, dirs):
79
+ if max_depth > 0:
80
+ rel_root = os.path.relpath(root, search_path)
81
+ if rel_root != ".":
82
+ depth = rel_root.count(os.sep) + 1
83
+ if depth >= max_depth:
84
+ del dirs[:]
85
+
86
+
87
+ def traverse_directory(
88
+ search_path,
89
+ query,
90
+ regex,
91
+ use_regex,
92
+ case_sensitive,
93
+ max_depth,
94
+ max_results,
95
+ total_results,
96
+ count_only,
97
+ ):
98
+ dir_output = []
99
+ dir_limit_reached = False
100
+ per_file_counts = []
101
+ walker = walk_directory(search_path, max_depth)
102
+ gitignore_filter = GitignoreFilter(search_path)
103
+
104
+ for root, dirs, files in walker:
105
+ dirs[:] = filter_dirs(dirs, root, gitignore_filter)
106
+ for file in files:
107
+ path = os.path.join(root, file)
108
+ if gitignore_filter.is_ignored(path):
109
+ continue
110
+ if count_only:
111
+ file_limit_reached = process_file_count_only(
112
+ path,
113
+ per_file_counts,
114
+ query,
115
+ regex,
116
+ use_regex,
117
+ case_sensitive,
118
+ max_results,
119
+ total_results,
120
+ )
121
+ if file_limit_reached:
122
+ dir_limit_reached = True
123
+ break
124
+ else:
125
+ file_limit_reached = process_file_collect(
126
+ path,
127
+ dir_output,
128
+ per_file_counts,
129
+ query,
130
+ regex,
131
+ use_regex,
132
+ case_sensitive,
133
+ max_results,
134
+ total_results,
135
+ )
136
+ if file_limit_reached:
137
+ dir_limit_reached = True
138
+ break
139
+ if dir_limit_reached:
140
+ break
141
+ should_limit_depth(root, search_path, max_depth, dirs)
142
+ if count_only:
143
+ return per_file_counts, dir_limit_reached, []
144
+ else:
145
+ return dir_output, dir_limit_reached, per_file_counts
@@ -1,12 +1,12 @@
1
1
  from janito.tools.tool_base import ToolBase, ToolPermissions
2
2
  from janito.report_events import ReportAction
3
- from janito.tools.adapters.local.adapter import register_local_tool
3
+ from janito.plugins.tools.decorators import register_core_tool
4
4
  from janito.i18n import tr
5
5
  from janito.tools.loop_protection_decorator import protect_against_loops
6
6
 
7
7
 
8
- @register_local_tool
9
- class ShowImageTool(ToolBase):
8
+ @register_core_tool
9
+ class ShowImage(ToolBase):
10
10
  """Display an image inline in the terminal using the rich library.
11
11
 
12
12
  Args:
@@ -44,7 +44,9 @@ class ShowImageTool(ToolBase):
44
44
 
45
45
  path = expand_path(path)
46
46
  disp_path = display_path(path)
47
- self.report_action(tr("🖼️ Show image '{disp_path}'", disp_path=disp_path), ReportAction.READ)
47
+ self.report_action(
48
+ tr("🖼️ Show image '{disp_path}'", disp_path=disp_path), ReportAction.READ
49
+ )
48
50
 
49
51
  if not os.path.exists(path):
50
52
  msg = tr("❗ not found")
@@ -55,9 +57,14 @@ class ShowImageTool(ToolBase):
55
57
  console = Console()
56
58
  from rich.console import Console
57
59
  from rich.text import Text
60
+
58
61
  console = Console()
59
62
  img = PILImage.open(path)
60
- console.print(Text(f"Image: {disp_path} ({img.width}x{img.height})", style="bold green"))
63
+ console.print(
64
+ Text(
65
+ f"Image: {disp_path} ({img.width}x{img.height})", style="bold green"
66
+ )
67
+ )
61
68
  console.print(img)
62
69
  self.report_success(tr("✅ Displayed"))
63
70
  details = []
@@ -68,7 +75,9 @@ class ShowImageTool(ToolBase):
68
75
  if not preserve_aspect:
69
76
  details.append("preserve_aspect=False")
70
77
  info = ("; ".join(details)) if details else "auto-fit"
71
- return tr("Image displayed: {disp_path} ({info})", disp_path=disp_path, info=info)
78
+ return tr(
79
+ "Image displayed: {disp_path} ({info})", disp_path=disp_path, info=info
80
+ )
72
81
  except Exception as e:
73
82
  self.report_error(tr(" ❌ Error: {error}", error=e))
74
83
  return tr("Error displaying image: {error}", error=e)
@@ -0,0 +1,85 @@
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.i18n import tr
5
+ from janito.tools.loop_protection_decorator import protect_against_loops
6
+ from typing import Sequence
7
+
8
+
9
+ @register_core_tool
10
+ class ShowImageGrid(ToolBase):
11
+ """Display multiple images in a grid inline in the terminal using rich.
12
+
13
+ Args:
14
+ paths (list[str]): List of image file paths.
15
+ columns (int, optional): Number of columns in the grid. Default: 2.
16
+ width (int, optional): Max width for each image cell. Default: None (auto).
17
+ height (int, optional): Max height for each image cell. Default: None (auto).
18
+ preserve_aspect (bool, optional): Preserve aspect ratio. Default: True.
19
+
20
+ Returns:
21
+ str: Status string summarizing the grid display.
22
+ """
23
+
24
+ permissions = ToolPermissions(read=True)
25
+ tool_name = "show_image_grid"
26
+
27
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
28
+ def run(
29
+ self,
30
+ paths: Sequence[str],
31
+ columns: int = 2,
32
+ width: int | None = None,
33
+ height: int | None = None,
34
+ preserve_aspect: bool = True,
35
+ ) -> str:
36
+ from janito.tools.path_utils import expand_path
37
+ from janito.tools.tool_utils import display_path
38
+ import os
39
+
40
+ try:
41
+ from rich.console import Console
42
+ from rich.columns import Columns
43
+ from PIL import Image as PILImage
44
+ from rich.panel import Panel
45
+ except Exception as e:
46
+ msg = tr("⚠️ Missing dependency: PIL/Pillow ({error})", error=e)
47
+ self.report_error(msg)
48
+ return msg
49
+
50
+ if not paths:
51
+ return tr("No images provided")
52
+
53
+ self.report_action(
54
+ tr("🖼️ Show image grid ({n} images)", n=len(paths)), ReportAction.READ
55
+ )
56
+
57
+ console = Console()
58
+ images = []
59
+ shown = 0
60
+ for p in paths:
61
+ fp = expand_path(p)
62
+ if not os.path.exists(fp):
63
+ self.report_warning(tr("❗ not found: {p}", p=display_path(fp)))
64
+ continue
65
+ try:
66
+ img = PILImage.open(fp)
67
+ title = f"{display_path(fp)} ({img.width}x{img.height})"
68
+ images.append(
69
+ Panel.fit(title, title=display_path(fp), border_style="dim")
70
+ )
71
+ shown += 1
72
+ except Exception as e:
73
+ self.report_warning(tr("⚠️ Skipped {p}: {e}", p=display_path(fp), e=e))
74
+
75
+ if not images:
76
+ return tr("No images could be displayed")
77
+
78
+ console.print(Columns(images, equal=True, expand=True, columns=columns))
79
+ self.report_success(tr("✅ Displayed {n} images", n=shown))
80
+ return tr(
81
+ "Displayed {shown}/{total} images in a {cols}x? grid",
82
+ shown=shown,
83
+ total=len(paths),
84
+ cols=columns,
85
+ )
@@ -0,0 +1,7 @@
1
+ """
2
+ File syntax validation tools for janito.
3
+ """
4
+
5
+ from .core import ValidateFileSyntax
6
+
7
+ __all__ = ["ValidateFileSyntax"]