janito 3.14.1__py3-none-any.whl → 3.15.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.
- janito/platform_discovery.py +1 -8
- janito/plugins/tools/local/adapter.py +3 -2
- janito/plugins/tools/local/ask_user.py +111 -112
- janito/plugins/tools/local/copy_file.py +86 -87
- janito/plugins/tools/local/create_directory.py +111 -112
- janito/plugins/tools/local/create_file.py +0 -1
- janito/plugins/tools/local/delete_text_in_file.py +133 -134
- janito/plugins/tools/local/fetch_url.py +465 -466
- janito/plugins/tools/local/find_files.py +142 -143
- janito/plugins/tools/local/markdown_view.py +0 -1
- janito/plugins/tools/local/move_file.py +130 -131
- janito/plugins/tools/local/open_html_in_browser.py +50 -51
- janito/plugins/tools/local/open_url.py +36 -37
- janito/plugins/tools/local/python_code_run.py +171 -172
- janito/plugins/tools/local/python_command_run.py +170 -171
- janito/plugins/tools/local/python_file_run.py +171 -172
- janito/plugins/tools/local/read_chart.py +258 -259
- janito/plugins/tools/local/read_files.py +57 -58
- janito/plugins/tools/local/remove_directory.py +54 -55
- janito/plugins/tools/local/remove_file.py +57 -58
- janito/plugins/tools/local/replace_text_in_file.py +275 -276
- janito/plugins/tools/local/run_bash_command.py +182 -183
- janito/plugins/tools/local/run_powershell_command.py +217 -218
- janito/plugins/tools/local/show_image.py +0 -1
- janito/plugins/tools/local/show_image_grid.py +0 -1
- janito/plugins/tools/local/view_file.py +0 -1
- janito/providers/alibaba/provider.py +1 -1
- janito/providers/deepseek/model_info.py +16 -37
- janito/providers/deepseek/provider.py +4 -3
- janito/tools/base.py +19 -12
- janito/tools/tool_base.py +122 -121
- janito/tools/tools_schema.py +104 -104
- {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/METADATA +9 -32
- {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/RECORD +38 -38
- {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/WHEEL +0 -0
- {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/entry_points.txt +0 -0
- {janito-3.14.1.dist-info → janito-3.15.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.14.1.dist-info → janito-3.15.0.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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
dir_output.update(self.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
)
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
self.
|
141
|
-
|
142
|
-
result
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
dest_result
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
False,
|
78
|
-
False,
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
False,
|
93
|
-
False,
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|