janito 3.1.0__py3-none-any.whl → 3.3.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 (156) hide show
  1. janito/cli/chat_mode/bindings.py +0 -26
  2. janito/cli/chat_mode/session.py +1 -7
  3. janito/cli/cli_commands/list_plugins.py +8 -13
  4. janito/cli/prompt_core.py +9 -19
  5. janito/llm/agent.py +17 -30
  6. janito/llm/driver.py +0 -7
  7. janito/plugins/__init__.py +21 -29
  8. janito/plugins/__main__.py +85 -0
  9. janito/plugins/base.py +57 -0
  10. janito/plugins/builtin.py +1 -1
  11. janito/plugins/core/filemanager/tools/copy_file.py +25 -1
  12. janito/plugins/core/filemanager/tools/create_directory.py +28 -1
  13. janito/plugins/core/filemanager/tools/create_file.py +25 -1
  14. janito/plugins/core/filemanager/tools/delete_text_in_file.py +1 -0
  15. janito/plugins/core/imagedisplay/plugin.py +1 -1
  16. janito/plugins/core_loader.py +144 -0
  17. janito/plugins/discovery.py +3 -3
  18. janito/plugins/example_plugin.py +1 -1
  19. janito/plugins/manager.py +1 -1
  20. janito/plugins_backup_20250825_070018/__init__.py +36 -0
  21. janito/plugins_backup_20250825_070018/builtin.py +102 -0
  22. janito/plugins_backup_20250825_070018/config.py +84 -0
  23. janito/plugins_backup_20250825_070018/core/__init__.py +7 -0
  24. janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +43 -0
  25. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +1 -0
  26. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +122 -0
  27. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +1 -0
  28. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +205 -0
  29. janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +124 -0
  30. janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +87 -0
  31. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +70 -0
  32. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +87 -0
  33. janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +135 -0
  34. janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +143 -0
  35. janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +131 -0
  36. janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +58 -0
  37. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +55 -0
  38. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +58 -0
  39. janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +270 -0
  40. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +1 -0
  41. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +114 -0
  42. janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +172 -0
  43. janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +14 -0
  44. janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +51 -0
  45. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +1 -0
  46. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +83 -0
  47. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +84 -0
  48. janito/plugins_backup_20250825_070018/core/system/__init__.py +23 -0
  49. janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +183 -0
  50. janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +218 -0
  51. janito/plugins_backup_20250825_070018/dev/__init__.py +7 -0
  52. janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +37 -0
  53. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +172 -0
  54. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +171 -0
  55. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +172 -0
  56. janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +23 -0
  57. janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +259 -0
  58. janito/plugins_backup_20250825_070018/discovery.py +289 -0
  59. janito/plugins_backup_20250825_070018/example_plugin.py +108 -0
  60. janito/plugins_backup_20250825_070018/manager.py +243 -0
  61. janito/{plugins → plugins_backup_20250825_070018}/tools/delete_text_in_file.py +1 -0
  62. janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +47 -0
  63. janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +14 -0
  64. janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +303 -0
  65. janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +36 -0
  66. janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +67 -0
  67. janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +73 -0
  68. janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +145 -0
  69. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +35 -0
  70. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +100 -0
  71. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +50 -0
  72. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +27 -0
  73. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +6 -0
  74. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +109 -0
  75. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +32 -0
  76. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +5 -0
  77. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +11 -0
  78. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +6 -0
  79. janito/plugins_backup_20250825_070018/ui/__init__.py +7 -0
  80. janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +16 -0
  81. janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +110 -0
  82. janito/plugins_backup_20250825_070018/web/__init__.py +7 -0
  83. janito/plugins_backup_20250825_070018/web/webtools/__init__.py +33 -0
  84. janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +458 -0
  85. janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +51 -0
  86. janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +37 -0
  87. janito/tools/base.py +31 -1
  88. janito/tools/cli_initializer.py +1 -1
  89. janito/tools/function_adapter.py +35 -1
  90. janito/tools/initialize.py +1 -1
  91. janito/tools/tool_base.py +142 -114
  92. janito/tools/tools_schema.py +12 -6
  93. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/METADATA +1 -1
  94. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/RECORD +154 -87
  95. janito/llm/cancellation_manager.py +0 -62
  96. janito/llm/enter_cancellation.py +0 -93
  97. /janito/{plugin_system → plugin_system_backup_20250825_070018}/__init__.py +0 -0
  98. /janito/{plugin_system → plugin_system_backup_20250825_070018}/base.py +0 -0
  99. /janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader.py +0 -0
  100. /janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader_fixed.py +0 -0
  101. /janito/{plugins → plugins_backup_20250825_070018}/auto_loader.py +0 -0
  102. /janito/{plugins → plugins_backup_20250825_070018}/auto_loader_fixed.py +0 -0
  103. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/java_outline.py +0 -0
  104. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/markdown_outline.py +0 -0
  105. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/python_outline.py +0 -0
  106. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/search_outline.py +0 -0
  107. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/match_lines.py +0 -0
  108. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/pattern_utils.py +0 -0
  109. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/traverse_directory.py +0 -0
  110. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/css_validator.py +0 -0
  111. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/html_validator.py +0 -0
  112. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/jinja2_validator.py +0 -0
  113. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/js_validator.py +0 -0
  114. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/json_validator.py +0 -0
  115. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/markdown_validator.py +0 -0
  116. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/ps1_validator.py +0 -0
  117. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/python_validator.py +0 -0
  118. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/xml_validator.py +0 -0
  119. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/yaml_validator.py +0 -0
  120. /janito/{plugins → plugins_backup_20250825_070018}/core_adapter.py +0 -0
  121. /janito/{plugins → plugins_backup_20250825_070018}/discovery_core.py +0 -0
  122. /janito/{plugins → plugins_backup_20250825_070018}/tools/__init__.py +0 -0
  123. /janito/{plugins → plugins_backup_20250825_070018}/tools/ask_user.py +0 -0
  124. /janito/{plugins → plugins_backup_20250825_070018}/tools/copy_file.py +0 -0
  125. /janito/{plugins → plugins_backup_20250825_070018}/tools/core_tools_plugin.py +0 -0
  126. /janito/{plugins → plugins_backup_20250825_070018}/tools/create_directory.py +0 -0
  127. /janito/{plugins → plugins_backup_20250825_070018}/tools/create_file.py +0 -0
  128. /janito/{plugins → plugins_backup_20250825_070018}/tools/decorators.py +0 -0
  129. /janito/{plugins → plugins_backup_20250825_070018}/tools/fetch_url.py +0 -0
  130. /janito/{plugins → plugins_backup_20250825_070018}/tools/find_files.py +0 -0
  131. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/__init__.py +0 -0
  132. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/core.py +0 -0
  133. /janito/{plugins → plugins_backup_20250825_070018}/tools/move_file.py +0 -0
  134. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_html_in_browser.py +0 -0
  135. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_url.py +0 -0
  136. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_code_run.py +0 -0
  137. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_command_run.py +0 -0
  138. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_file_run.py +0 -0
  139. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_chart.py +0 -0
  140. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_files.py +0 -0
  141. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_directory.py +0 -0
  142. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_file.py +0 -0
  143. /janito/{plugins → plugins_backup_20250825_070018}/tools/replace_text_in_file.py +0 -0
  144. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_bash_command.py +0 -0
  145. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_powershell_command.py +0 -0
  146. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/__init__.py +0 -0
  147. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/core.py +0 -0
  148. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image.py +0 -0
  149. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image_grid.py +0 -0
  150. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/__init__.py +0 -0
  151. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/core.py +0 -0
  152. /janito/{plugins → plugins_backup_20250825_070018}/tools/view_file.py +0 -0
  153. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/WHEEL +0 -0
  154. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/entry_points.txt +0 -0
  155. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/licenses/LICENSE +0 -0
  156. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,135 @@
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.i18n import tr
5
+ import shutil
6
+ from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
7
+
8
+
9
+ @register_local_tool
10
+ class DeleteTextInFileTool(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
+ )
@@ -0,0 +1,143 @@
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.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_local_tool
14
+ class FindFilesTool(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
@@ -0,0 +1,131 @@
1
+ import os
2
+ from janito.tools.path_utils import expand_path
3
+ import shutil
4
+ from janito.tools.adapters.local.adapter import register_local_tool
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
+
10
+
11
+ @register_local_tool
12
+ class MoveFileTool(ToolBase):
13
+ """
14
+ Move a file or directory from src_path to dest_path.
15
+
16
+ Args:
17
+ src_path (str): Source file or directory path.
18
+ dest_path (str): Destination file or directory path.
19
+ overwrite (bool, optional): Whether to overwrite if the destination exists. Defaults to False.
20
+ backup (bool, optional): Deprecated. No backups are created anymore. This flag is ignored. Defaults to False.
21
+ Returns:
22
+ str: Status message indicating the result.
23
+ """
24
+
25
+ permissions = ToolPermissions(read=True, write=True)
26
+ tool_name = "move_file"
27
+
28
+ def run(
29
+ self,
30
+ src_path: str,
31
+ dest_path: str,
32
+ overwrite: bool = False,
33
+ backup: bool = False,
34
+ ) -> str:
35
+ src = expand_path(src_path)
36
+ dest = expand_path(dest_path)
37
+ original_src = src_path
38
+ original_dest = dest_path
39
+ disp_src = display_path(original_src)
40
+ disp_dest = display_path(original_dest)
41
+ backup_path = None
42
+
43
+ valid, is_src_file, is_src_dir, err_msg = self._validate_source(src, disp_src)
44
+ if not valid:
45
+ return err_msg
46
+
47
+ dest_result = self._handle_destination(dest, disp_dest, overwrite, backup)
48
+ if dest_result is not None:
49
+ backup_path, err_msg = dest_result
50
+ if err_msg:
51
+ return err_msg
52
+
53
+ try:
54
+ self.report_action(
55
+ tr(
56
+ "📝 Moving from '{disp_src}' to '{disp_dest}' ...",
57
+ disp_src=disp_src,
58
+ disp_dest=disp_dest,
59
+ ),
60
+ ReportAction.UPDATE,
61
+ )
62
+ shutil.move(src, dest)
63
+ self.report_success(tr("✅ Move complete."))
64
+ msg = tr("✅ Move complete.")
65
+
66
+ return msg
67
+ except Exception as e:
68
+ self.report_error(tr("❌ Error moving: {error}", error=e))
69
+ return tr("❌ Error moving: {error}", error=e)
70
+
71
+ def _validate_source(self, src, disp_src):
72
+ if not os.path.exists(src):
73
+ self.report_error(
74
+ tr("❌ Source '{disp_src}' does not exist.", disp_src=disp_src)
75
+ )
76
+ return (
77
+ False,
78
+ False,
79
+ False,
80
+ tr("❌ Source '{disp_src}' does not exist.", disp_src=disp_src),
81
+ )
82
+ is_src_file = os.path.isfile(src)
83
+ is_src_dir = os.path.isdir(src)
84
+ if not (is_src_file or is_src_dir):
85
+ self.report_error(
86
+ tr(
87
+ "❌ Source path '{disp_src}' is neither a file nor a directory.",
88
+ disp_src=disp_src,
89
+ )
90
+ )
91
+ return (
92
+ False,
93
+ False,
94
+ False,
95
+ tr(
96
+ "❌ Source path '{disp_src}' is neither a file nor a directory.",
97
+ disp_src=disp_src,
98
+ ),
99
+ )
100
+ return True, is_src_file, is_src_dir, None
101
+
102
+ def _handle_destination(self, dest, disp_dest, overwrite, backup):
103
+ backup_path = None
104
+ if os.path.exists(dest):
105
+ if not overwrite:
106
+ self.report_error(
107
+ tr(
108
+ "❗ Destination '{disp_dest}' exists and overwrite is False.",
109
+ disp_dest=disp_dest,
110
+ ),
111
+ ReportAction.UPDATE,
112
+ )
113
+ return None, tr(
114
+ "❗ Destination '{disp_dest}' already exists and overwrite is False.",
115
+ disp_dest=disp_dest,
116
+ )
117
+
118
+ try:
119
+ if os.path.isfile(dest):
120
+ os.remove(dest)
121
+ elif os.path.isdir(dest):
122
+ shutil.rmtree(dest)
123
+ except Exception as e:
124
+ self.report_error(
125
+ tr("❌ Error removing destination before move: {error}", error=e),
126
+ ReportAction.UPDATE,
127
+ )
128
+ return None, tr(
129
+ "❌ Error removing destination before move: {error}", error=e
130
+ )
131
+ return backup_path, None
@@ -0,0 +1,58 @@
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
5
+ from janito.i18n import tr
6
+ from janito.tools.loop_protection_decorator import protect_against_loops
7
+
8
+
9
+ @register_local_tool
10
+ class ReadFilesTool(ToolBase):
11
+ """
12
+ Read all text content from multiple files.
13
+
14
+ Args:
15
+ paths (list[str]): List of file paths to read.
16
+
17
+ Returns:
18
+ str: Concatenated content of all files, each prefixed by a header with the file name. If a file cannot be read, an error message is included for that file.
19
+ """
20
+
21
+ permissions = ToolPermissions(read=True)
22
+ tool_name = "read_files"
23
+
24
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
25
+ def run(self, paths: list[str]) -> str:
26
+ from janito.tools.tool_utils import display_path
27
+ import os
28
+ from janito.tools.path_utils import expand_path
29
+
30
+ results = []
31
+ for path in [expand_path(p) for p in paths]:
32
+ disp_path = display_path(path)
33
+ self.report_action(
34
+ tr("📖 Read '{disp_path}'", disp_path=disp_path), ReportAction.READ
35
+ )
36
+ if not os.path.isfile(path):
37
+ self.report_warning(
38
+ tr("❗ not found: {disp_path}", disp_path=disp_path)
39
+ )
40
+ results.append(f"--- File: {disp_path} (not found) ---\n")
41
+ continue
42
+ try:
43
+ with open(path, "r", encoding="utf-8", errors="replace") as f:
44
+ content = f.read()
45
+ results.append(f"--- File: {disp_path} ---\n{content}\n")
46
+ self.report_success(tr("✅ Read {disp_path}", disp_path=disp_path))
47
+ except Exception as e:
48
+ self.report_error(
49
+ tr(
50
+ " ❌ Error reading {disp_path}: {error}",
51
+ disp_path=disp_path,
52
+ error=e,
53
+ )
54
+ )
55
+ results.append(
56
+ f"--- File: {disp_path} (error) ---\nError reading file: {e}\n"
57
+ )
58
+ return "\n".join(results)
@@ -0,0 +1,55 @@
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 shutil
7
+ import os
8
+ import zipfile
9
+ from janito.tools.path_utils import expand_path
10
+
11
+
12
+ @register_local_tool
13
+ class RemoveDirectoryTool(ToolBase):
14
+ """
15
+ Remove a directory.
16
+
17
+ Args:
18
+ path (str): Path to the directory to remove.
19
+ recursive (bool, optional): If True, remove non-empty directories recursively (with backup). If False, only remove empty directories. Defaults to False.
20
+ Returns:
21
+ str: Status message indicating result. Example:
22
+ - "Directory removed: /path/to/dir"
23
+ - "Error removing directory: <error message>"
24
+ """
25
+
26
+ permissions = ToolPermissions(write=True)
27
+ tool_name = "remove_directory"
28
+
29
+ def run(self, path: str, recursive: bool = False) -> str:
30
+ path = expand_path(path)
31
+ disp_path = display_path(path)
32
+ self.report_action(
33
+ tr("🗃️ Remove directory '{disp_path}' ...", disp_path=disp_path),
34
+ ReportAction.DELETE,
35
+ )
36
+
37
+ try:
38
+ if recursive:
39
+
40
+ shutil.rmtree(path)
41
+ else:
42
+ os.rmdir(path)
43
+ self.report_success(
44
+ tr("✅ 1 {dir_word}", dir_word=pluralize("directory", 1)),
45
+ ReportAction.DELETE,
46
+ )
47
+ msg = tr("Directory removed: {disp_path}", disp_path=disp_path)
48
+
49
+ return msg
50
+ except Exception as e:
51
+ self.report_error(
52
+ tr(" ❌ Error removing directory: {error}", error=e),
53
+ ReportAction.DELETE,
54
+ )
55
+ return tr("Error removing directory: {error}", error=e)
@@ -0,0 +1,58 @@
1
+ import os
2
+ from janito.tools.path_utils import expand_path
3
+ import shutil
4
+ from janito.tools.adapters.local.adapter import register_local_tool
5
+
6
+ from janito.tools.tool_utils import display_path
7
+ from janito.tools.tool_base import ToolBase, ToolPermissions
8
+ from janito.report_events import ReportAction
9
+ from janito.i18n import tr
10
+
11
+
12
+ @register_local_tool
13
+ class RemoveFileTool(ToolBase):
14
+ """
15
+ Remove a file at the specified path.
16
+
17
+ Args:
18
+ path (str): Path to the file to remove.
19
+ backup (bool, optional): Deprecated. Backups are no longer created. Flag ignored.
20
+ Returns:
21
+ str: Status message indicating the result. Example:
22
+ - " Successfully removed the file at ..."
23
+ - " Cannot remove file: ..."
24
+ """
25
+
26
+ permissions = ToolPermissions(write=True)
27
+ tool_name = "remove_file"
28
+
29
+ def run(self, path: str, backup: bool = False) -> str:
30
+ path = expand_path(path)
31
+ disp_path = display_path(path)
32
+
33
+ # Report initial info about what is going to be removed
34
+ self.report_action(
35
+ tr("🗑️ Remove file '{disp_path}' ...", disp_path=disp_path),
36
+ ReportAction.DELETE,
37
+ )
38
+ if not os.path.exists(path):
39
+ self.report_error(tr("❌ File does not exist."), ReportAction.DELETE)
40
+ return tr("❌ File does not exist.")
41
+ if not os.path.isfile(path):
42
+ self.report_error(tr("❌ Path is not a file."), ReportAction.DELETE)
43
+ return tr("❌ Path is not a file.")
44
+ try:
45
+
46
+ os.remove(path)
47
+ self.report_success(tr("✅ File removed"), ReportAction.DELETE)
48
+ msg = tr(
49
+ "✅ Successfully removed the file at '{disp_path}'.",
50
+ disp_path=disp_path,
51
+ )
52
+
53
+ return msg
54
+ except Exception as e:
55
+ self.report_error(
56
+ tr("❌ Error removing file: {error}", error=e), ReportAction.DELETE
57
+ )
58
+ return tr("❌ Error removing file: {error}", error=e)