janito 3.14.2__py3-none-any.whl → 3.15.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. janito/platform_discovery.py +1 -8
  2. janito/plugins/tools/local/adapter.py +3 -2
  3. janito/plugins/tools/local/ask_user.py +111 -112
  4. janito/plugins/tools/local/copy_file.py +86 -87
  5. janito/plugins/tools/local/create_directory.py +111 -112
  6. janito/plugins/tools/local/create_file.py +0 -1
  7. janito/plugins/tools/local/delete_text_in_file.py +133 -134
  8. janito/plugins/tools/local/fetch_url.py +465 -466
  9. janito/plugins/tools/local/find_files.py +142 -143
  10. janito/plugins/tools/local/markdown_view.py +0 -1
  11. janito/plugins/tools/local/move_file.py +130 -131
  12. janito/plugins/tools/local/open_html_in_browser.py +50 -51
  13. janito/plugins/tools/local/open_url.py +36 -37
  14. janito/plugins/tools/local/python_code_run.py +171 -172
  15. janito/plugins/tools/local/python_command_run.py +170 -171
  16. janito/plugins/tools/local/python_file_run.py +171 -172
  17. janito/plugins/tools/local/read_chart.py +258 -259
  18. janito/plugins/tools/local/read_files.py +57 -58
  19. janito/plugins/tools/local/remove_directory.py +54 -55
  20. janito/plugins/tools/local/remove_file.py +57 -58
  21. janito/plugins/tools/local/replace_text_in_file.py +275 -276
  22. janito/plugins/tools/local/run_bash_command.py +182 -183
  23. janito/plugins/tools/local/run_powershell_command.py +217 -218
  24. janito/plugins/tools/local/show_image.py +0 -1
  25. janito/plugins/tools/local/show_image_grid.py +0 -1
  26. janito/plugins/tools/local/view_file.py +0 -1
  27. janito/providers/alibaba/model_info.py +2 -2
  28. janito/providers/alibaba/provider.py +1 -1
  29. janito/tools/base.py +19 -12
  30. janito/tools/tool_base.py +122 -121
  31. janito/tools/tools_schema.py +104 -104
  32. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/METADATA +9 -29
  33. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/RECORD +37 -37
  34. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/WHEEL +0 -0
  35. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/entry_points.txt +0 -0
  36. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/licenses/LICENSE +0 -0
  37. {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/top_level.txt +0 -0
@@ -1,143 +1,142 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from janito.plugins.tools.local.adapter import register_local_tool
4
- from janito.tools.tool_utils import pluralize, 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
1
+ from janito.tools.tool_base import ToolBase, ToolPermissions
2
+ from janito.report_events import ReportAction
3
+ from janito.plugins.tools.local.adapter import register_local_tool
4
+ from janito.tools.tool_utils import pluralize, 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
+
34
+ def _match_directories(self, root, dirs, pat):
35
+ dir_output = set()
36
+ dir_pat = pat.rstrip("/\\")
37
+ for d in dirs:
38
+ if fnmatch.fnmatch(d, dir_pat):
39
+ dir_output.add(os.path.join(root, d) + os.sep)
40
+ return dir_output
41
+
42
+ def _match_files(self, root, files, pat):
43
+ file_output = set()
44
+ for filename in fnmatch.filter(files, pat):
45
+ file_output.add(os.path.join(root, filename))
46
+ return file_output
47
+
48
+ def _match_dirs_without_slash(self, root, dirs, pat):
49
+ dir_output = set()
50
+ for d in fnmatch.filter(dirs, pat):
51
+ dir_output.add(os.path.join(root, d))
52
+ return dir_output
53
+
54
+ def _handle_path(self, directory, patterns):
55
+ dir_output = set()
56
+ filename = os.path.basename(directory)
57
+ for pat in patterns:
58
+ # Only match files, not directories, for file paths
59
+ if not (pat.endswith("/") or pat.endswith("\\")):
60
+ if fnmatch.fnmatch(filename, pat):
61
+ dir_output.add(directory)
62
+ break
63
+ return dir_output
64
+
65
+ def _handle_directory_path(
66
+ self, directory, patterns, max_depth, include_gitignored
67
+ ):
68
+ dir_output = set()
69
+ for root, dirs, files in walk_dir_with_gitignore(
70
+ directory,
71
+ max_depth=max_depth,
72
+ include_gitignored=include_gitignored,
73
+ ):
74
+ for pat in patterns:
75
+ if pat.endswith("/") or pat.endswith("\\"):
76
+ dir_output.update(self._match_directories(root, dirs, pat))
77
+ else:
78
+ dir_output.update(self._match_files(root, files, pat))
79
+ dir_output.update(self._match_dirs_without_slash(root, dirs, pat))
80
+ return dir_output
81
+
82
+ def _report_search(self, pattern, disp_path, depth_msg):
83
+ self.report_action(
84
+ tr(
85
+ "🔍 Search for files '{pattern}' in '{disp_path}'{depth_msg} ...",
86
+ pattern=pattern,
87
+ disp_path=disp_path,
88
+ depth_msg=depth_msg,
89
+ ),
90
+ ReportAction.READ,
91
+ )
92
+
93
+ def _report_success(self, count):
94
+ self.report_success(
95
+ tr(
96
+ " ✅ {count} {file_word}",
97
+ count=count,
98
+ file_word=pluralize("file", count),
99
+ ),
100
+ ReportAction.READ,
101
+ )
102
+
103
+ def _format_output(self, directory, dir_output):
104
+ if directory.strip() == ".":
105
+ dir_output = {
106
+ p[2:] if (p.startswith("./") or p.startswith(".\\")) else p
107
+ for p in dir_output
108
+ }
109
+ return sorted(dir_output)
110
+
111
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
112
+ def run(
113
+ self,
114
+ paths: str,
115
+ pattern: str,
116
+ max_depth: int = None,
117
+ include_gitignored: bool = False,
118
+ ) -> str:
119
+ if not pattern:
120
+ self.report_warning(tr("ℹ️ Empty file pattern provided."), ReportAction.READ)
121
+ return tr("Warning: Empty file pattern provided. Operation skipped.")
122
+ patterns = pattern.split()
123
+ results = []
124
+ for directory in [expand_path(p) for p in paths.split()]:
125
+ disp_path = display_path(directory)
126
+ depth_msg = (
127
+ tr(" (max depth: {max_depth})", max_depth=max_depth)
128
+ if max_depth is not None and max_depth > 0
129
+ else ""
130
+ )
131
+ self._report_search(pattern, disp_path, depth_msg)
132
+ dir_output = set()
133
+ if os.path.isfile(directory):
134
+ dir_output = self._handle_path(directory, patterns)
135
+ elif os.path.isdir(directory):
136
+ dir_output = self._handle_directory_path(
137
+ directory, patterns, max_depth, include_gitignored
138
+ )
139
+ self._report_success(len(dir_output))
140
+ results.extend(self._format_output(directory, dir_output))
141
+ result = "\n".join(results)
142
+ return result
@@ -21,7 +21,6 @@ class MarkdownViewTool(ToolBase):
21
21
  """
22
22
 
23
23
  permissions = ToolPermissions(read=True)
24
- tool_name = "markdown_view"
25
24
 
26
25
  @protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
27
26
  def run(self, path: str, width: int = 80, theme: str = "github") -> str:
@@ -1,131 +1,130 @@
1
- import os
2
- from janito.tools.path_utils import expand_path
3
- import shutil
4
- from janito.plugins.tools.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
1
+ import os
2
+ from janito.tools.path_utils import expand_path
3
+ import shutil
4
+ from janito.plugins.tools.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
+
27
+ def run(
28
+ self,
29
+ src_path: str,
30
+ dest_path: str,
31
+ overwrite: bool = False,
32
+ backup: bool = False,
33
+ ) -> str:
34
+ src = expand_path(src_path)
35
+ dest = expand_path(dest_path)
36
+ original_src = src_path
37
+ original_dest = dest_path
38
+ disp_src = display_path(original_src)
39
+ disp_dest = display_path(original_dest)
40
+ backup_path = None
41
+
42
+ valid, is_src_file, is_src_dir, err_msg = self._validate_source(src, disp_src)
43
+ if not valid:
44
+ return err_msg
45
+
46
+ dest_result = self._handle_destination(dest, disp_dest, overwrite, backup)
47
+ if dest_result is not None:
48
+ backup_path, err_msg = dest_result
49
+ if err_msg:
50
+ return err_msg
51
+
52
+ try:
53
+ self.report_action(
54
+ tr(
55
+ "📝 Moving from '{disp_src}' to '{disp_dest}' ...",
56
+ disp_src=disp_src,
57
+ disp_dest=disp_dest,
58
+ ),
59
+ ReportAction.UPDATE,
60
+ )
61
+ shutil.move(src, dest)
62
+ self.report_success(tr("✅ Move complete."))
63
+ msg = tr("✅ Move complete.")
64
+
65
+ return msg
66
+ except Exception as e:
67
+ self.report_error(tr("❌ Error moving: {error}", error=e))
68
+ return tr("❌ Error moving: {error}", error=e)
69
+
70
+ def _validate_source(self, src, disp_src):
71
+ if not os.path.exists(src):
72
+ self.report_error(
73
+ tr("❌ Source '{disp_src}' does not exist.", disp_src=disp_src)
74
+ )
75
+ return (
76
+ False,
77
+ False,
78
+ False,
79
+ tr("❌ Source '{disp_src}' does not exist.", disp_src=disp_src),
80
+ )
81
+ is_src_file = os.path.isfile(src)
82
+ is_src_dir = os.path.isdir(src)
83
+ if not (is_src_file or is_src_dir):
84
+ self.report_error(
85
+ tr(
86
+ "❌ Source path '{disp_src}' is neither a file nor a directory.",
87
+ disp_src=disp_src,
88
+ )
89
+ )
90
+ return (
91
+ False,
92
+ False,
93
+ False,
94
+ tr(
95
+ "❌ Source path '{disp_src}' is neither a file nor a directory.",
96
+ disp_src=disp_src,
97
+ ),
98
+ )
99
+ return True, is_src_file, is_src_dir, None
100
+
101
+ def _handle_destination(self, dest, disp_dest, overwrite, backup):
102
+ backup_path = None
103
+ if os.path.exists(dest):
104
+ if not overwrite:
105
+ self.report_error(
106
+ tr(
107
+ "❗ Destination '{disp_dest}' exists and overwrite is False.",
108
+ disp_dest=disp_dest,
109
+ ),
110
+ ReportAction.UPDATE,
111
+ )
112
+ return None, tr(
113
+ "❗ Destination '{disp_dest}' already exists and overwrite is False.",
114
+ disp_dest=disp_dest,
115
+ )
116
+
117
+ try:
118
+ if os.path.isfile(dest):
119
+ os.remove(dest)
120
+ elif os.path.isdir(dest):
121
+ shutil.rmtree(dest)
122
+ except Exception as e:
123
+ self.report_error(
124
+ tr("❌ Error removing destination before move: {error}", error=e),
125
+ ReportAction.UPDATE,
126
+ )
127
+ return None, tr(
128
+ "❌ Error removing destination before move: {error}", error=e
129
+ )
130
+ return backup_path, None