janito 3.3.0__py3-none-any.whl → 3.4.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 (214) hide show
  1. janito/cli/cli_commands/list_plugins.py +48 -52
  2. janito/cli/core/getters.py +0 -3
  3. janito/cli/main_cli.py +12 -9
  4. janito/drivers/openai/driver.py +0 -1
  5. janito/drivers/zai/driver.py +0 -1
  6. janito/hello.txt +0 -0
  7. janito/llm/auth_utils.py +5 -14
  8. janito/plugins/__init__.py +7 -18
  9. janito/{plugins_backup_20250825_070018 → plugins}/auto_loader_fixed.py +11 -12
  10. janito/plugins/base.py +152 -57
  11. janito/plugins/builtin.py +1 -15
  12. janito/{plugins_backup_20250825_070018 → plugins}/core_adapter.py +9 -11
  13. janito/plugins/core_loader.py +34 -58
  14. janito/{plugin_system_backup_20250825_070018/core_loader.py → plugins/core_loader_fixed.py} +26 -45
  15. janito/plugins/discovery.py +3 -3
  16. janito/tools/__init__.py +7 -31
  17. janito/tools/adapters/__init__.py +1 -6
  18. janito/tools/adapters/local/__init__.py +70 -7
  19. janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/ask_user.py +3 -3
  20. janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/create_file.py +4 -4
  21. janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -1
  22. janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/fetch_url.py +3 -3
  23. janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/replace_text_in_file.py +4 -4
  24. janito/{plugins_backup_20250825_070018/tools → tools/adapters/local}/show_image.py +6 -15
  25. janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
  26. janito/tools/base.py +1 -31
  27. janito/tools/function_adapter.py +16 -127
  28. janito/tools/tool_base.py +114 -142
  29. janito/tools/tools_schema.py +6 -12
  30. {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/METADATA +2 -1
  31. janito-3.4.0.dist-info/RECORD +264 -0
  32. janito/cli/cli_commands/check_tools.py +0 -212
  33. janito/plugin_system_backup_20250825_070018/__init__.py +0 -10
  34. janito/plugin_system_backup_20250825_070018/base.py +0 -155
  35. janito/plugin_system_backup_20250825_070018/core_loader_fixed.py +0 -149
  36. janito/plugins/__main__.py +0 -85
  37. janito/plugins/core/__init__.py +0 -7
  38. janito/plugins/core/codeanalyzer/__init__.py +0 -43
  39. janito/plugins/core/filemanager/__init__.py +0 -124
  40. janito/plugins/core/filemanager/tools/copy_file.py +0 -111
  41. janito/plugins/core/filemanager/tools/create_directory.py +0 -97
  42. janito/plugins/core/filemanager/tools/create_file.py +0 -111
  43. janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
  44. janito/plugins/core/imagedisplay/__init__.py +0 -14
  45. janito/plugins/core/imagedisplay/plugin.py +0 -51
  46. janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
  47. janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
  48. janito/plugins/core/system/__init__.py +0 -23
  49. janito/plugins/dev/__init__.py +0 -7
  50. janito/plugins/dev/pythondev/__init__.py +0 -37
  51. janito/plugins/dev/visualization/__init__.py +0 -23
  52. janito/plugins/example_plugin.py +0 -108
  53. janito/plugins/ui/__init__.py +0 -7
  54. janito/plugins/ui/userinterface/__init__.py +0 -16
  55. janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
  56. janito/plugins/web/__init__.py +0 -7
  57. janito/plugins/web/webtools/__init__.py +0 -33
  58. janito/plugins/web/webtools/tools/fetch_url.py +0 -458
  59. janito/plugins_backup_20250825_070018/__init__.py +0 -36
  60. janito/plugins_backup_20250825_070018/builtin.py +0 -102
  61. janito/plugins_backup_20250825_070018/config.py +0 -84
  62. janito/plugins_backup_20250825_070018/core/__init__.py +0 -7
  63. janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +0 -43
  64. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +0 -1
  65. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +0 -122
  66. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/java_outline.py +0 -47
  67. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/markdown_outline.py +0 -14
  68. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/python_outline.py +0 -303
  69. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/search_outline.py +0 -36
  70. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +0 -1
  71. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +0 -205
  72. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/match_lines.py +0 -67
  73. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/pattern_utils.py +0 -73
  74. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/traverse_directory.py +0 -145
  75. janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +0 -124
  76. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +0 -87
  77. janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +0 -135
  78. janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +0 -143
  79. janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +0 -131
  80. janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +0 -58
  81. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +0 -55
  82. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +0 -58
  83. janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +0 -270
  84. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +0 -1
  85. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +0 -114
  86. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/css_validator.py +0 -35
  87. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/html_validator.py +0 -100
  88. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/jinja2_validator.py +0 -50
  89. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/js_validator.py +0 -27
  90. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/json_validator.py +0 -6
  91. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/markdown_validator.py +0 -109
  92. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/ps1_validator.py +0 -32
  93. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/python_validator.py +0 -5
  94. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/xml_validator.py +0 -11
  95. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/yaml_validator.py +0 -6
  96. janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +0 -172
  97. janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +0 -14
  98. janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +0 -51
  99. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +0 -1
  100. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +0 -83
  101. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +0 -84
  102. janito/plugins_backup_20250825_070018/core/system/__init__.py +0 -23
  103. janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +0 -183
  104. janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +0 -218
  105. janito/plugins_backup_20250825_070018/dev/__init__.py +0 -7
  106. janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +0 -37
  107. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +0 -172
  108. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +0 -171
  109. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +0 -172
  110. janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +0 -23
  111. janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +0 -259
  112. janito/plugins_backup_20250825_070018/discovery.py +0 -289
  113. janito/plugins_backup_20250825_070018/example_plugin.py +0 -108
  114. janito/plugins_backup_20250825_070018/manager.py +0 -243
  115. janito/plugins_backup_20250825_070018/tools/__init__.py +0 -10
  116. janito/plugins_backup_20250825_070018/tools/copy_file.py +0 -87
  117. janito/plugins_backup_20250825_070018/tools/core_tools_plugin.py +0 -88
  118. janito/plugins_backup_20250825_070018/tools/create_directory.py +0 -70
  119. janito/plugins_backup_20250825_070018/tools/decorators.py +0 -19
  120. janito/plugins_backup_20250825_070018/tools/delete_text_in_file.py +0 -135
  121. janito/plugins_backup_20250825_070018/tools/find_files.py +0 -143
  122. janito/plugins_backup_20250825_070018/tools/get_file_outline/__init__.py +0 -7
  123. janito/plugins_backup_20250825_070018/tools/get_file_outline/core.py +0 -122
  124. janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +0 -47
  125. janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +0 -14
  126. janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +0 -303
  127. janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +0 -36
  128. janito/plugins_backup_20250825_070018/tools/move_file.py +0 -131
  129. janito/plugins_backup_20250825_070018/tools/open_html_in_browser.py +0 -51
  130. janito/plugins_backup_20250825_070018/tools/open_url.py +0 -37
  131. janito/plugins_backup_20250825_070018/tools/python_code_run.py +0 -172
  132. janito/plugins_backup_20250825_070018/tools/python_command_run.py +0 -171
  133. janito/plugins_backup_20250825_070018/tools/python_file_run.py +0 -172
  134. janito/plugins_backup_20250825_070018/tools/read_chart.py +0 -259
  135. janito/plugins_backup_20250825_070018/tools/read_files.py +0 -58
  136. janito/plugins_backup_20250825_070018/tools/remove_directory.py +0 -55
  137. janito/plugins_backup_20250825_070018/tools/remove_file.py +0 -58
  138. janito/plugins_backup_20250825_070018/tools/run_bash_command.py +0 -183
  139. janito/plugins_backup_20250825_070018/tools/run_powershell_command.py +0 -218
  140. janito/plugins_backup_20250825_070018/tools/search_text/__init__.py +0 -7
  141. janito/plugins_backup_20250825_070018/tools/search_text/core.py +0 -205
  142. janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +0 -67
  143. janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +0 -73
  144. janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +0 -145
  145. janito/plugins_backup_20250825_070018/tools/show_image_grid.py +0 -85
  146. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/__init__.py +0 -7
  147. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/core.py +0 -114
  148. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +0 -35
  149. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +0 -100
  150. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +0 -50
  151. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +0 -27
  152. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +0 -6
  153. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +0 -109
  154. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +0 -32
  155. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +0 -5
  156. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +0 -11
  157. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +0 -6
  158. janito/plugins_backup_20250825_070018/tools/view_file.py +0 -172
  159. janito/plugins_backup_20250825_070018/ui/__init__.py +0 -7
  160. janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +0 -16
  161. janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +0 -110
  162. janito/plugins_backup_20250825_070018/web/__init__.py +0 -7
  163. janito/plugins_backup_20250825_070018/web/webtools/__init__.py +0 -33
  164. janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +0 -458
  165. janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +0 -51
  166. janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +0 -37
  167. janito/tools/cli_initializer.py +0 -88
  168. janito/tools/initialize.py +0 -70
  169. janito-3.3.0.dist-info/RECORD +0 -400
  170. /janito/{plugins_backup_20250825_070018 → plugins}/auto_loader.py +0 -0
  171. /janito/{plugins_backup_20250825_070018 → plugins}/discovery_core.py +0 -0
  172. /janito/{plugins_backup_20250825_070018/core/filemanager/tools → tools/adapters/local}/copy_file.py +0 -0
  173. /janito/{plugins_backup_20250825_070018/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
  174. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
  175. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
  176. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
  177. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
  178. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
  179. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
  180. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
  181. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/move_file.py +0 -0
  182. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
  183. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
  184. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_code_run.py +0 -0
  185. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_command_run.py +0 -0
  186. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_file_run.py +0 -0
  187. /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
  188. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
  189. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
  190. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_file.py +0 -0
  191. /janito/{plugins/core/system/tools → tools/adapters/local}/run_bash_command.py +0 -0
  192. /janito/{plugins/core/system/tools → tools/adapters/local}/run_powershell_command.py +0 -0
  193. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
  194. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
  195. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
  196. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
  197. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
  198. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
  199. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
  200. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
  201. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
  202. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
  203. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
  204. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
  205. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
  206. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
  207. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
  208. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
  209. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
  210. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/view_file.py +0 -0
  211. {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/WHEEL +0 -0
  212. {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/entry_points.txt +0 -0
  213. {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/licenses/LICENSE +0 -0
  214. {janito-3.3.0.dist-info → janito-3.4.0.dist-info}/top_level.txt +0 -0
@@ -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.tools.adapters.local.adapter import register_local_tool as register_tool
15
-
16
-
17
- @register_tool
18
- class SearchTextTool(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)
@@ -1,67 +0,0 @@
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
@@ -1,73 +0,0 @@
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
@@ -1,145 +0,0 @@
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,124 +0,0 @@
1
- """
2
- File Manager Plugin
3
-
4
- Core file and directory operations for managing project files.
5
- """
6
-
7
- from typing import List, Optional
8
- import os
9
-
10
-
11
- def create_file(path: str, content: str = "", overwrite: bool = False) -> str:
12
- """Create a new file with content"""
13
- return f"create_file(path='{path}', content='{len(content)} chars', overwrite={overwrite})"
14
-
15
-
16
- create_file.tool_name = "create_file"
17
-
18
-
19
- def read_files(paths: List[str]) -> str:
20
- """Read multiple files at once"""
21
- return f"read_files(paths={paths})"
22
-
23
-
24
- read_files.tool_name = "read_files"
25
-
26
-
27
- def view_file(
28
- path: str, from_line: Optional[int] = None, to_line: Optional[int] = None
29
- ) -> str:
30
- """Read specific lines or entire files"""
31
- range_str = f"{from_line}-{to_line}" if from_line or to_line else "all"
32
- return f"view_file(path='{path}', range='{range_str}')"
33
-
34
-
35
- view_file.tool_name = "view_file"
36
-
37
-
38
- def replace_text_in_file(
39
- path: str, search_text: str, replacement_text: str, replace_all: bool = True
40
- ) -> str:
41
- """Find and replace text in files"""
42
- return f"replace_text_in_file(path='{path}', search='{search_text[:20]}...', replace='{replacement_text[:20]}...')"
43
-
44
-
45
- replace_text_in_file.tool_name = "replace_text_in_file"
46
-
47
-
48
- def validate_file_syntax(path: str) -> str:
49
- """Check file syntax (Python/Markdown)"""
50
- return f"validate_file_syntax(path='{path}')"
51
-
52
-
53
- validate_file_syntax.tool_name = "validate_file_syntax"
54
-
55
-
56
- def create_directory(path: str) -> str:
57
- """Create new directories"""
58
- return f"create_directory(path='{path}')"
59
-
60
-
61
- create_directory.tool_name = "create_directory"
62
-
63
-
64
- def remove_directory(path: str, recursive: bool = False) -> str:
65
- """Remove directories (recursive option)"""
66
- return f"remove_directory(path='{path}', recursive={recursive})"
67
-
68
-
69
- remove_directory.tool_name = "remove_directory"
70
-
71
-
72
- def remove_file(path: str) -> str:
73
- """Delete single files"""
74
- return f"remove_file(path='{path}')"
75
-
76
-
77
- remove_file.tool_name = "remove_file"
78
-
79
-
80
- def copy_file(sources: str, target: str, overwrite: bool = False) -> str:
81
- """Copy files or directories"""
82
- return f"copy_file(sources='{sources}', target='{target}', overwrite={overwrite})"
83
-
84
-
85
- copy_file.tool_name = "copy_file"
86
-
87
-
88
- def move_file(src_path: str, dest_path: str, overwrite: bool = False) -> str:
89
- """Move/rename files or directories"""
90
- return f"move_file(src='{src_path}', dest='{dest_path}', overwrite={overwrite})"
91
-
92
-
93
- move_file.tool_name = "move_file"
94
-
95
-
96
- def find_files(
97
- paths: str,
98
- pattern: str,
99
- max_depth: Optional[int] = None,
100
- include_gitignored: bool = False,
101
- ) -> str:
102
- """Search for files by pattern (respects .gitignore)"""
103
- return f"find_files(paths='{paths}', pattern='{pattern}', max_depth={max_depth})"
104
-
105
-
106
- find_files.tool_name = "find_files"
107
-
108
-
109
- # Plugin metadata
110
- __plugin_name__ = "core.filemanager"
111
- __plugin_description__ = "Core file and directory operations"
112
- __plugin_tools__ = [
113
- create_file,
114
- read_files,
115
- view_file,
116
- replace_text_in_file,
117
- validate_file_syntax,
118
- create_directory,
119
- remove_directory,
120
- remove_file,
121
- copy_file,
122
- move_file,
123
- find_files,
124
- ]
@@ -1,87 +0,0 @@
1
- import os
2
- from janito.tools.path_utils import expand_path
3
- from janito.tools.adapters.local.adapter import register_local_tool
4
-
5
- from janito.tools.tool_utils import display_path
6
- from janito.tools.tool_base import ToolBase, ToolPermissions
7
- from janito.report_events import ReportAction
8
- from janito.i18n import tr
9
- from janito.tools.loop_protection_decorator import protect_against_loops
10
-
11
- from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
12
-
13
-
14
- @register_local_tool
15
- class CreateFileTool(ToolBase):
16
- """
17
- Create a new file with the given content.
18
-
19
- Args:
20
- path (str): Path to the file to create.
21
- content (str): Content to write to the file.
22
- overwrite (bool, optional): Overwrite existing file if True. Default: False. Recommended only after reading the file to be overwritten.
23
- Returns:
24
- str: Status message indicating the result. Example:
25
- - "✅ Successfully created the file at ..."
26
-
27
- Note: Syntax validation is automatically performed after this operation.
28
-
29
- Security: This tool includes loop protection to prevent excessive file creation operations.
30
- Maximum 5 calls per 10 seconds for the same file path.
31
- """
32
-
33
- permissions = ToolPermissions(write=True)
34
- tool_name = "create_file"
35
-
36
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
37
- def run(self, path: str, content: str, overwrite: bool = False) -> str:
38
- path = expand_path(path)
39
- disp_path = display_path(path)
40
- if os.path.exists(path) and not overwrite:
41
- try:
42
- with open(path, "r", encoding="utf-8", errors="replace") as f:
43
- existing_content = f.read()
44
- except Exception as e:
45
- existing_content = f"[Error reading file: {e}]"
46
- return tr(
47
- "❗ Cannot create file: file already exists at '{disp_path}'.\n--- Current file content ---\n{existing_content}",
48
- disp_path=disp_path,
49
- existing_content=existing_content,
50
- )
51
- # Determine if we are overwriting an existing file
52
- is_overwrite = os.path.exists(path) and overwrite
53
- if is_overwrite:
54
- # Overwrite branch: log only overwrite warning (no create message)
55
- self.report_action(
56
- tr("⚠️ Overwriting file '{disp_path}'", disp_path=disp_path),
57
- ReportAction.CREATE,
58
- )
59
- dir_name = os.path.dirname(path)
60
- if dir_name:
61
- os.makedirs(dir_name, exist_ok=True)
62
- if not is_overwrite:
63
- # Create branch: log file creation message
64
- self.report_action(
65
- tr("📝 Create file '{disp_path}' ...", disp_path=disp_path),
66
- ReportAction.CREATE,
67
- )
68
- with open(path, "w", encoding="utf-8", errors="replace") as f:
69
- f.write(content)
70
- new_lines = content.count("\n") + 1 if content else 0
71
- self.report_success(
72
- tr("✅ {new_lines} lines", new_lines=new_lines), ReportAction.CREATE
73
- )
74
- # Perform syntax validation and append result
75
- validation_result = validate_file_syntax(path)
76
- if is_overwrite:
77
- # Overwrite branch: return minimal overwrite info to user
78
- return (
79
- tr("✅ {new_lines} lines", new_lines=new_lines)
80
- + f"\n{validation_result}"
81
- )
82
- else:
83
- # Create branch: return detailed create success to user
84
- return (
85
- tr("✅ Created file {new_lines} lines.", new_lines=new_lines)
86
- + f"\n{validation_result}"
87
- )