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,87 +0,0 @@
1
- import os
2
- from janito.tools.path_utils import expand_path
3
- import shutil
4
- from typing import List, Union
5
- from janito.plugins.tools.decorators import register_core_tool
6
- from janito.tools.tool_base import ToolBase, ToolPermissions
7
- from janito.tools.tool_utils import display_path
8
- from janito.report_events import ReportAction
9
- from janito.i18n import tr
10
-
11
-
12
- @register_core_tool
13
- class CopyFile(ToolBase):
14
- """
15
- Copy one or more files to a target directory, or copy a single file to a new file.
16
- Args:
17
- sources (str): Space-separated path(s) to the file(s) to copy.
18
- For multiple sources, provide a single string with paths separated by spaces.
19
- target (str): Destination path. If copying multiple sources, this must be an existing directory.
20
- overwrite (bool, optional): Overwrite existing files. Default: False.
21
- Recommended only after reading the file to be overwritten.
22
- Returns:
23
- str: Status string for each copy operation.
24
- """
25
-
26
- permissions = ToolPermissions(read=True, write=True)
27
- tool_name = "copy_file"
28
-
29
- def run(self, sources: str, target: str, overwrite: bool = False) -> str:
30
- source_list = [expand_path(src) for src in sources.split() if src]
31
- target = expand_path(target)
32
- messages = []
33
- if len(source_list) > 1:
34
- if not os.path.isdir(target):
35
- return tr(
36
- "❗ Target must be an existing directory when copying multiple files: '{target}'",
37
- target=display_path(target),
38
- )
39
- for src in source_list:
40
- if not os.path.isfile(src):
41
- messages.append(
42
- tr(
43
- "❗ Source file does not exist: '{src}'",
44
- src=display_path(src),
45
- )
46
- )
47
- continue
48
- dst = os.path.join(target, os.path.basename(src))
49
- messages.append(self._copy_one(src, dst, overwrite=overwrite))
50
- else:
51
- src = source_list[0]
52
- if os.path.isdir(target):
53
- dst = os.path.join(target, os.path.basename(src))
54
- else:
55
- dst = target
56
- messages.append(self._copy_one(src, dst, overwrite=overwrite))
57
- return "\n".join(messages)
58
-
59
- def _copy_one(self, src, dst, overwrite=False) -> str:
60
- disp_src = display_path(src)
61
- disp_dst = display_path(dst)
62
- if not os.path.isfile(src):
63
- return tr("❗ Source file does not exist: '{src}'", src=disp_src)
64
- if os.path.exists(dst) and not overwrite:
65
- return tr(
66
- "❗ Target already exists: '{dst}'. Set overwrite=True to replace.",
67
- dst=disp_dst,
68
- )
69
- try:
70
- os.makedirs(os.path.dirname(dst), exist_ok=True)
71
- shutil.copy2(src, dst)
72
- note = (
73
- "\n⚠️ Overwrote existing file. (recommended only after reading the file to be overwritten)"
74
- if (os.path.exists(dst) and overwrite)
75
- else ""
76
- )
77
- self.report_success(
78
- tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst)
79
- )
80
- return tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst) + note
81
- except Exception as e:
82
- return tr(
83
- "❗ Copy failed from '{src}' to '{dst}': {err}",
84
- src=disp_src,
85
- dst=disp_dst,
86
- err=str(e),
87
- )
@@ -1,88 +0,0 @@
1
- """
2
- Core tools plugin implementation.
3
- """
4
-
5
- from functools import wraps
6
- from typing import Type
7
- from janito.plugin_system.base import Plugin, PluginMetadata
8
-
9
- # Registry for core tools
10
- _core_tools_registry = []
11
-
12
-
13
- def register_core_tool(cls: Type):
14
- """Decorator to register a core tool."""
15
- _core_tools_registry.append(cls)
16
- return cls
17
-
18
-
19
- from .ask_user import AskUser
20
- from .copy_file import CopyFile
21
- from .create_directory import CreateDirectory
22
- from .create_file import CreateFile
23
- from .delete_text_in_file import DeleteTextInFile
24
- from .fetch_url import FetchUrl
25
- from .find_files import FindFiles
26
- from .move_file import MoveFile
27
- from .open_html_in_browser import OpenHtmlInBrowser
28
- from .open_url import OpenUrl
29
- from .python_code_run import PythonCodeRun
30
- from .python_command_run import PythonCommandRun
31
- from .python_file_run import PythonFileRun
32
- from .read_chart import ReadChart
33
- from .read_files import ReadFiles
34
- from .remove_directory import RemoveDirectory
35
- from .remove_file import RemoveFile
36
- from .replace_text_in_file import ReplaceTextInFile
37
- from .run_bash_command import RunBashCommand
38
- from .run_powershell_command import RunPowershellCommand
39
- from .show_image import ShowImage
40
- from .show_image_grid import ShowImageGrid
41
- from .view_file import ViewFile
42
- from .validate_file_syntax.core import ValidateFileSyntax
43
- from .get_file_outline.core import GetFileOutline
44
- from .search_text.core import SearchText
45
- from .decorators import get_core_tools
46
-
47
-
48
- class CoreToolsPlugin(Plugin):
49
- """Core tools plugin providing essential janito functionality."""
50
-
51
- def get_metadata(self):
52
- return PluginMetadata(
53
- name="core_tools",
54
- version="1.0.0",
55
- description="Core tools for file operations, code execution, and system interactions",
56
- author="janito team",
57
- license="MIT",
58
- )
59
-
60
- def get_tools(self):
61
- return [
62
- AskUser,
63
- CopyFile,
64
- CreateDirectory,
65
- CreateFile,
66
- DeleteTextInFile,
67
- FetchUrl,
68
- FindFiles,
69
- MoveFile,
70
- OpenHtmlInBrowser,
71
- OpenUrl,
72
- PythonCodeRun,
73
- PythonCommandRun,
74
- PythonFileRun,
75
- ReadChart,
76
- ReadFiles,
77
- RemoveDirectory,
78
- RemoveFile,
79
- ReplaceTextInFile,
80
- RunBashCommand,
81
- RunPowershellCommand,
82
- ShowImage,
83
- ShowImageGrid,
84
- ViewFile,
85
- ValidateFileSyntax,
86
- GetFileOutline,
87
- SearchText,
88
- ] + get_core_tools()
@@ -1,70 +0,0 @@
1
- from janito.plugins.tools.decorators import register_core_tool
2
-
3
- from janito.tools.tool_utils import display_path
4
- from janito.tools.tool_base import ToolBase, ToolPermissions
5
- from janito.report_events import ReportAction
6
- from janito.i18n import tr
7
- import os
8
- from janito.tools.path_utils import expand_path
9
-
10
-
11
- @register_core_tool
12
- class CreateDirectory(ToolBase):
13
- """
14
- Create a new directory at the specified path.
15
- Args:
16
- path (str): Path for the new directory.
17
- Returns:
18
- str: Status message indicating the result. Example:
19
- - "5c5 Successfully created the directory at ..."
20
- - "5d7 Cannot create directory: ..."
21
- """
22
-
23
- permissions = ToolPermissions(write=True)
24
- tool_name = "create_directory"
25
-
26
- def run(self, path: str) -> str:
27
- path = expand_path(path)
28
- disp_path = display_path(path)
29
- self.report_action(
30
- tr("📁 Create directory '{disp_path}' ...", disp_path=disp_path),
31
- ReportAction.CREATE,
32
- )
33
- try:
34
- if os.path.exists(path):
35
- if not os.path.isdir(path):
36
- self.report_error(
37
- tr(
38
- "❌ Path '{disp_path}' exists and is not a directory.",
39
- disp_path=disp_path,
40
- )
41
- )
42
- return tr(
43
- "❌ Path '{disp_path}' exists and is not a directory.",
44
- disp_path=disp_path,
45
- )
46
- self.report_error(
47
- tr(
48
- "❗ Directory '{disp_path}' already exists.",
49
- disp_path=disp_path,
50
- )
51
- )
52
- return tr(
53
- "❗ Cannot create directory: '{disp_path}' already exists.",
54
- disp_path=disp_path,
55
- )
56
- os.makedirs(path, exist_ok=True)
57
- self.report_success(tr("✅ Directory created"))
58
- return tr(
59
- "✅ Successfully created the directory at '{disp_path}'.",
60
- disp_path=disp_path,
61
- )
62
- except Exception as e:
63
- self.report_error(
64
- tr(
65
- "❌ Error creating directory '{disp_path}': {error}",
66
- disp_path=disp_path,
67
- error=e,
68
- )
69
- )
70
- return tr("❌ Cannot create directory: {error}", error=e)
@@ -1,19 +0,0 @@
1
- """
2
- Decorators for core tools registration.
3
- """
4
-
5
- from typing import Type
6
-
7
- # Registry for core tools
8
- _core_tools_registry = []
9
-
10
-
11
- def register_core_tool(cls: Type):
12
- """Decorator to register a core tool."""
13
- _core_tools_registry.append(cls)
14
- return cls
15
-
16
-
17
- def get_core_tools():
18
- """Get all registered core tools."""
19
- return list(_core_tools_registry)
@@ -1,135 +0,0 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from janito.plugins.tools.decorators import register_core_tool
4
- from janito.i18n import tr
5
- import shutil
6
- from janito.plugins.tools.validate_file_syntax.core import validate_file_syntax
7
-
8
-
9
- @register_core_tool
10
- class DeleteTextInFile(ToolBase):
11
- """
12
- Delete all occurrences of text between start_marker and end_marker (inclusive) in a file, using exact string markers.
13
-
14
- Args:
15
- path (str): Path to the file to modify.
16
- start_marker (str): The starting delimiter string.
17
- end_marker (str): The ending delimiter string.
18
- backup (bool, optional): Deprecated. No backups are created anymore and this flag is ignored. Defaults to False.
19
-
20
- Returns:
21
- str: Status message indicating the result.
22
- """
23
-
24
- permissions = ToolPermissions(read=True, write=True)
25
- tool_name = "delete_text_in_file"
26
-
27
- def run(
28
- self,
29
- path: str,
30
- start_marker: str,
31
- end_marker: str,
32
- backup: bool = False,
33
- ) -> str:
34
- from janito.tools.tool_utils import display_path
35
-
36
- disp_path = display_path(path)
37
- info_msg = tr(
38
- "📝 Delete text in {disp_path} between markers: '{start_marker}' ... '{end_marker}'",
39
- disp_path=disp_path,
40
- start_marker=start_marker,
41
- end_marker=end_marker,
42
- )
43
- self.report_action(info_msg, ReportAction.CREATE)
44
- try:
45
- content = self._read_file_content(path)
46
- occurrences, match_lines = self._find_marker_blocks(
47
- content, start_marker, end_marker
48
- )
49
- if occurrences == 0:
50
- self.report_warning(
51
- tr(" ℹ️ No blocks found between markers."), ReportAction.CREATE
52
- )
53
- return tr(
54
- "No blocks found between markers in {path}.",
55
- path=path,
56
- )
57
-
58
- new_content, deleted_blocks = self._delete_blocks(
59
- content, start_marker, end_marker
60
- )
61
- self._write_file_content(path, new_content)
62
- validation_result = validate_file_syntax(path)
63
- self._report_success(match_lines)
64
- return tr(
65
- "Deleted {count} block(s) between markers in {path}. ",
66
- count=deleted_blocks,
67
- path=path,
68
- ) + (f"\n{validation_result}" if validation_result else "")
69
- except Exception as e:
70
- self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.REPLACE)
71
- return tr("Error deleting text: {error}", error=e)
72
-
73
- def _read_file_content(self, path):
74
- with open(path, "r", encoding="utf-8", errors="replace") as f:
75
- return f.read()
76
-
77
- def _find_marker_blocks(self, content, start_marker, end_marker):
78
- """Find all blocks between start_marker and end_marker, return count and starting line numbers."""
79
- lines = content.splitlines(keepends=True)
80
- joined = "".join(lines)
81
- match_lines = []
82
- idx = 0
83
- occurrences = 0
84
- while True:
85
- start_idx = joined.find(start_marker, idx)
86
- if start_idx == -1:
87
- break
88
- end_idx = joined.find(end_marker, start_idx + len(start_marker))
89
- if end_idx == -1:
90
- break
91
- upto = joined[:start_idx]
92
- line_no = upto.count("\n") + 1
93
- match_lines.append(line_no)
94
- idx = end_idx + len(end_marker)
95
- occurrences += 1
96
- return occurrences, match_lines
97
-
98
- def _delete_blocks(self, content, start_marker, end_marker):
99
- """Delete all blocks between start_marker and end_marker (inclusive)."""
100
- count = 0
101
- new_content = content
102
- while True:
103
- start_idx = new_content.find(start_marker)
104
- if start_idx == -1:
105
- break
106
- end_idx = new_content.find(end_marker, start_idx + len(start_marker))
107
- if end_idx == -1:
108
- break
109
- new_content = (
110
- new_content[:start_idx] + new_content[end_idx + len(end_marker) :]
111
- )
112
- count += 1
113
- return new_content, count
114
-
115
- def _backup_file(self, path, backup_path):
116
- shutil.copy2(path, backup_path)
117
-
118
- def _write_file_content(self, path, content):
119
- with open(path, "w", encoding="utf-8", errors="replace") as f:
120
- f.write(content)
121
-
122
- def _report_success(self, match_lines):
123
- if match_lines:
124
- lines_str = ", ".join(str(line_no) for line_no in match_lines)
125
- self.report_success(
126
- tr(
127
- " ✅ deleted block(s) starting at line(s): {lines_str}",
128
- lines_str=lines_str,
129
- ),
130
- ReportAction.CREATE,
131
- )
132
- else:
133
- self.report_success(
134
- tr(" ✅ deleted block(s) (lines unknown)"), ReportAction.CREATE
135
- )
@@ -1,143 +0,0 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from janito.plugins.tools.decorators import register_core_tool
4
- from janito.tools.tool_utils import pluralize, display_path
5
- from janito.dir_walk_utils import walk_dir_with_gitignore
6
- from janito.i18n import tr
7
- import fnmatch
8
- import os
9
- from janito.tools.path_utils import expand_path
10
- from janito.tools.loop_protection_decorator import protect_against_loops
11
-
12
-
13
- @register_core_tool
14
- class FindFiles(ToolBase):
15
- """
16
- Find files or directories in one or more directories matching a pattern. Respects .gitignore.
17
-
18
- If a path is an existing file, it is checked against the provided pattern(s) and included in the results if it matches. This allows find_files to be used to look for a specific set of filenames in a single call, as well as searching directories.
19
-
20
- Args:
21
- paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
22
- pattern (str): File pattern(s) to match. Multiple patterns can be separated by spaces. Uses Unix shell-style wildcards (fnmatch), e.g. '*.py', 'data_??.csv', '[a-z]*.txt'.
23
- - If the pattern ends with '/' or '\', only matching directory names (with trailing slash) are returned, not the files within those directories. For example, pattern '*/' will return only directories at the specified depth.
24
- max_depth (int, optional): Maximum directory depth to search. If None, unlimited recursion. If 0, only the top-level directory. If 1, only the root directory (matches 'find . -maxdepth 1').
25
- include_gitignored (bool, optional): If True, includes files/directories ignored by .gitignore. Defaults to False.
26
- Returns:
27
- str: Newline-separated list of matching file paths. Example:
28
- "/path/to/file1.py\n/path/to/file2.py"
29
- "Warning: Empty file pattern provided. Operation skipped."
30
- """
31
-
32
- permissions = ToolPermissions(read=True)
33
- tool_name = "find_files"
34
-
35
- def _match_directories(self, root, dirs, pat):
36
- dir_output = set()
37
- dir_pat = pat.rstrip("/\\")
38
- for d in dirs:
39
- if fnmatch.fnmatch(d, dir_pat):
40
- dir_output.add(os.path.join(root, d) + os.sep)
41
- return dir_output
42
-
43
- def _match_files(self, root, files, pat):
44
- file_output = set()
45
- for filename in fnmatch.filter(files, pat):
46
- file_output.add(os.path.join(root, filename))
47
- return file_output
48
-
49
- def _match_dirs_without_slash(self, root, dirs, pat):
50
- dir_output = set()
51
- for d in fnmatch.filter(dirs, pat):
52
- dir_output.add(os.path.join(root, d))
53
- return dir_output
54
-
55
- def _handle_path(self, directory, patterns):
56
- dir_output = set()
57
- filename = os.path.basename(directory)
58
- for pat in patterns:
59
- # Only match files, not directories, for file paths
60
- if not (pat.endswith("/") or pat.endswith("\\")):
61
- if fnmatch.fnmatch(filename, pat):
62
- dir_output.add(directory)
63
- break
64
- return dir_output
65
-
66
- def _handle_directory_path(
67
- self, directory, patterns, max_depth, include_gitignored
68
- ):
69
- dir_output = set()
70
- for root, dirs, files in walk_dir_with_gitignore(
71
- directory,
72
- max_depth=max_depth,
73
- include_gitignored=include_gitignored,
74
- ):
75
- for pat in patterns:
76
- if pat.endswith("/") or pat.endswith("\\"):
77
- dir_output.update(self._match_directories(root, dirs, pat))
78
- else:
79
- dir_output.update(self._match_files(root, files, pat))
80
- dir_output.update(self._match_dirs_without_slash(root, dirs, pat))
81
- return dir_output
82
-
83
- def _report_search(self, pattern, disp_path, depth_msg):
84
- self.report_action(
85
- tr(
86
- "🔍 Search for files '{pattern}' in '{disp_path}'{depth_msg} ...",
87
- pattern=pattern,
88
- disp_path=disp_path,
89
- depth_msg=depth_msg,
90
- ),
91
- ReportAction.READ,
92
- )
93
-
94
- def _report_success(self, count):
95
- self.report_success(
96
- tr(
97
- " ✅ {count} {file_word}",
98
- count=count,
99
- file_word=pluralize("file", count),
100
- ),
101
- ReportAction.READ,
102
- )
103
-
104
- def _format_output(self, directory, dir_output):
105
- if directory.strip() == ".":
106
- dir_output = {
107
- p[2:] if (p.startswith("./") or p.startswith(".\\")) else p
108
- for p in dir_output
109
- }
110
- return sorted(dir_output)
111
-
112
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
113
- def run(
114
- self,
115
- paths: str,
116
- pattern: str,
117
- max_depth: int = None,
118
- include_gitignored: bool = False,
119
- ) -> str:
120
- if not pattern:
121
- self.report_warning(tr("ℹ️ Empty file pattern provided."), ReportAction.READ)
122
- return tr("Warning: Empty file pattern provided. Operation skipped.")
123
- patterns = pattern.split()
124
- results = []
125
- for directory in [expand_path(p) for p in paths.split()]:
126
- disp_path = display_path(directory)
127
- depth_msg = (
128
- tr(" (max depth: {max_depth})", max_depth=max_depth)
129
- if max_depth is not None and max_depth > 0
130
- else ""
131
- )
132
- self._report_search(pattern, disp_path, depth_msg)
133
- dir_output = set()
134
- if os.path.isfile(directory):
135
- dir_output = self._handle_path(directory, patterns)
136
- elif os.path.isdir(directory):
137
- dir_output = self._handle_directory_path(
138
- directory, patterns, max_depth, include_gitignored
139
- )
140
- self._report_success(len(dir_output))
141
- results.extend(self._format_output(directory, dir_output))
142
- result = "\n".join(results)
143
- return result
@@ -1,7 +0,0 @@
1
- """
2
- File outline tools for janito.
3
- """
4
-
5
- from .core import GetFileOutline
6
-
7
- __all__ = ["GetFileOutline"]
@@ -1,122 +0,0 @@
1
- from janito.tools.adapters.local.adapter import register_local_tool
2
- from .python_outline import parse_python_outline
3
- from .markdown_outline import parse_markdown_outline
4
- from janito.formatting import OutlineFormatter
5
- from .java_outline import parse_java_outline
6
- import os
7
- from janito.tools.path_utils import expand_path
8
- from janito.tools.tool_base import ToolBase, ToolPermissions
9
- from janito.report_events import ReportAction
10
- from janito.tools.tool_utils import display_path, pluralize
11
- from janito.i18n import tr
12
-
13
- from janito.plugins.tools.decorators import register_core_tool
14
- from janito.tools.loop_protection_decorator import protect_against_loops
15
-
16
-
17
- @register_core_tool
18
- class GetFileOutline(ToolBase):
19
- """
20
- Get an outline of a file's structure. Supports Python and Markdown files.
21
-
22
- Args:
23
- path (str): Path to the file to outline.
24
- """
25
-
26
- permissions = ToolPermissions(read=True)
27
- tool_name = "get_file_outline"
28
-
29
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
30
- def run(self, path: str) -> str:
31
- try:
32
- path = expand_path(path)
33
- self.report_action(
34
- tr(
35
- "📄 Outline file '{disp_path}' ...",
36
- disp_path=display_path(path),
37
- ),
38
- ReportAction.READ,
39
- )
40
- ext = os.path.splitext(path)[1].lower()
41
- with open(path, "r", encoding="utf-8", errors="replace") as f:
42
- lines = f.readlines()
43
- return self._outline_by_extension(ext, lines)
44
- except Exception as e:
45
- self.report_error(
46
- tr("❌ Error reading file: {error}", error=e),
47
- ReportAction.READ,
48
- )
49
- return tr("Error reading file: {error}", error=e)
50
-
51
- def _outline_by_extension(self, ext, lines):
52
- if ext == ".py":
53
- outline_items = parse_python_outline(lines)
54
- outline_type = "python"
55
- table = OutlineFormatter.format_outline_table(outline_items)
56
- self.report_success(
57
- tr(
58
- "✅ Outlined {count} {item_word}",
59
- count=len(outline_items),
60
- item_word=pluralize("item", len(outline_items)),
61
- ),
62
- ReportAction.READ,
63
- )
64
- return (
65
- tr(
66
- "Outline: {count} items ({outline_type})\n",
67
- count=len(outline_items),
68
- outline_type=outline_type,
69
- )
70
- + table
71
- )
72
- elif ext == ".md":
73
- outline_items = parse_markdown_outline(lines)
74
- outline_type = "markdown"
75
- table = OutlineFormatter.format_markdown_outline_table(outline_items)
76
- self.report_success(
77
- tr(
78
- "✅ Outlined {count} {item_word}",
79
- count=len(outline_items),
80
- item_word=pluralize("item", len(outline_items)),
81
- ),
82
- ReportAction.READ,
83
- )
84
- return (
85
- tr(
86
- "Outline: {count} items ({outline_type})\n",
87
- count=len(outline_items),
88
- outline_type=outline_type,
89
- )
90
- + table
91
- )
92
- elif ext == ".java":
93
- outline_items = parse_java_outline(lines)
94
- outline_type = "java"
95
- table = OutlineFormatter.format_outline_table(outline_items)
96
- self.report_success(
97
- tr(
98
- "✅ Outlined {count} {item_word}",
99
- count=len(outline_items),
100
- item_word=pluralize("item", len(outline_items)),
101
- ),
102
- ReportAction.READ,
103
- )
104
- return (
105
- tr(
106
- "Outline: {count} items ({outline_type})\n",
107
- count=len(outline_items),
108
- outline_type=outline_type,
109
- )
110
- + table
111
- )
112
- else:
113
- outline_type = "default"
114
- self.report_success(
115
- tr("✅ Outlined {count} items", count=len(lines)),
116
- ReportAction.READ,
117
- )
118
- return tr(
119
- "Outline: {count} lines ({outline_type})\nFile has {count} lines.",
120
- count=len(lines),
121
- outline_type=outline_type,
122
- )