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.
- 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/model_info.py +2 -2
- janito/providers/alibaba/provider.py +1 -1
- janito/tools/base.py +19 -12
- janito/tools/tool_base.py +122 -121
- janito/tools/tools_schema.py +104 -104
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/METADATA +9 -29
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/RECORD +37 -37
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/WHEEL +0 -0
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/entry_points.txt +0 -0
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/licenses/LICENSE +0 -0
- {janito-3.14.2.dist-info → janito-3.15.1.dist-info}/top_level.txt +0 -0
@@ -1,113 +1,112 @@
|
|
1
|
-
from janito.plugins.tools.local.adapter import register_local_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
|
-
from pathlib import Path
|
10
|
-
|
11
|
-
|
12
|
-
@register_local_tool
|
13
|
-
class CreateDirectoryTool(ToolBase):
|
14
|
-
"""
|
15
|
-
Create a new directory at the specified path.
|
16
|
-
Args:
|
17
|
-
path (str): Path for the new directory.
|
18
|
-
Returns:
|
19
|
-
str: Status message indicating the result. Example:
|
20
|
-
- "5c5 Successfully created the directory at ..."
|
21
|
-
- "5d7 Cannot create directory: ..."
|
22
|
-
"""
|
23
|
-
|
24
|
-
permissions = ToolPermissions(write=True)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
path_obj
|
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
|
-
except Exception:
|
1
|
+
from janito.plugins.tools.local.adapter import register_local_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
|
+
from pathlib import Path
|
10
|
+
|
11
|
+
|
12
|
+
@register_local_tool
|
13
|
+
class CreateDirectoryTool(ToolBase):
|
14
|
+
"""
|
15
|
+
Create a new directory at the specified path.
|
16
|
+
Args:
|
17
|
+
path (str): Path for the new directory.
|
18
|
+
Returns:
|
19
|
+
str: Status message indicating the result. Example:
|
20
|
+
- "5c5 Successfully created the directory at ..."
|
21
|
+
- "5d7 Cannot create directory: ..."
|
22
|
+
"""
|
23
|
+
|
24
|
+
permissions = ToolPermissions(write=True)
|
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
|
+
# Generate content summary
|
47
|
+
content_summary = self._get_directory_summary(path)
|
48
|
+
self.report_error(
|
49
|
+
tr(
|
50
|
+
"❗ Directory '{disp_path}' already exists.",
|
51
|
+
disp_path=disp_path,
|
52
|
+
)
|
53
|
+
)
|
54
|
+
return tr(
|
55
|
+
"❗ Cannot create directory: '{disp_path}' already exists.\n{summary}",
|
56
|
+
disp_path=disp_path,
|
57
|
+
summary=content_summary,
|
58
|
+
)
|
59
|
+
os.makedirs(path, exist_ok=True)
|
60
|
+
self.report_success(tr("✅ Directory created"))
|
61
|
+
return tr(
|
62
|
+
"✅ Successfully created the directory at '{disp_path}'.",
|
63
|
+
disp_path=disp_path,
|
64
|
+
)
|
65
|
+
except Exception as e:
|
66
|
+
self.report_error(
|
67
|
+
tr(
|
68
|
+
"❌ Error creating directory '{disp_path}': {error}",
|
69
|
+
disp_path=disp_path,
|
70
|
+
error=e,
|
71
|
+
)
|
72
|
+
)
|
73
|
+
return tr("❌ Cannot create directory: {error}", error=e)
|
74
|
+
|
75
|
+
def _get_directory_summary(self, path: str) -> str:
|
76
|
+
"""Generate a summary of directory contents."""
|
77
|
+
try:
|
78
|
+
path_obj = Path(path)
|
79
|
+
if not path_obj.exists() or not path_obj.is_dir():
|
80
|
+
return ""
|
81
|
+
|
82
|
+
items = list(path_obj.iterdir())
|
83
|
+
if not items:
|
84
|
+
return "Directory is empty."
|
85
|
+
|
86
|
+
# Count files and directories
|
87
|
+
file_count = sum(1 for item in items if item.is_file())
|
88
|
+
dir_count = sum(1 for item in items if item.is_dir())
|
89
|
+
|
90
|
+
summary_parts = []
|
91
|
+
if file_count > 0:
|
92
|
+
summary_parts.append(f"{file_count} file{'s' if file_count != 1 else ''}")
|
93
|
+
if dir_count > 0:
|
94
|
+
summary_parts.append(f"{dir_count} subdirector{'y' if dir_count == 1 else 'ies'}")
|
95
|
+
|
96
|
+
# Show first few items as examples
|
97
|
+
examples = []
|
98
|
+
for item in sorted(items)[:3]: # Show up to 3 items
|
99
|
+
if item.is_dir():
|
100
|
+
examples.append(f"📁 {item.name}")
|
101
|
+
else:
|
102
|
+
examples.append(f"📄 {item.name}")
|
103
|
+
|
104
|
+
result = f"Contains: {', '.join(summary_parts)}."
|
105
|
+
if examples:
|
106
|
+
result += f"\nExamples: {', '.join(examples)}"
|
107
|
+
if len(items) > 3:
|
108
|
+
result += f" (and {len(items) - 3} more)"
|
109
|
+
|
110
|
+
return result
|
111
|
+
except Exception:
|
113
112
|
return "Unable to read directory contents."
|
@@ -95,7 +95,6 @@ class CreateFileTool(ToolBase):
|
|
95
95
|
"""
|
96
96
|
|
97
97
|
permissions = ToolPermissions(write=True)
|
98
|
-
tool_name = "create_file"
|
99
98
|
|
100
99
|
@protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
|
101
100
|
def run(self, path: str, content: str = "", overwrite: bool = False, is_base64: bool = False) -> str:
|
@@ -1,134 +1,133 @@
|
|
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.i18n import tr
|
5
|
-
import shutil
|
6
|
-
from janito.plugins.tools.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
|
-
|
19
|
-
Returns:
|
20
|
-
str: Status message indicating the result.
|
21
|
-
"""
|
22
|
-
|
23
|
-
permissions = ToolPermissions(read=True, write=True)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
start_idx
|
85
|
-
|
86
|
-
|
87
|
-
end_idx
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
start_idx
|
103
|
-
|
104
|
-
|
105
|
-
end_idx
|
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
|
-
)
|
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.i18n import tr
|
5
|
+
import shutil
|
6
|
+
from janito.plugins.tools.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
|
+
|
19
|
+
Returns:
|
20
|
+
str: Status message indicating the result.
|
21
|
+
"""
|
22
|
+
|
23
|
+
permissions = ToolPermissions(read=True, write=True)
|
24
|
+
|
25
|
+
def run(
|
26
|
+
self,
|
27
|
+
path: str,
|
28
|
+
start_marker: str,
|
29
|
+
end_marker: str,
|
30
|
+
backup: bool = False,
|
31
|
+
) -> str:
|
32
|
+
from janito.tools.tool_utils import display_path
|
33
|
+
|
34
|
+
disp_path = display_path(path)
|
35
|
+
info_msg = tr(
|
36
|
+
"📝 Delete text in {disp_path} between markers: '{start_marker}' ... '{end_marker}'",
|
37
|
+
disp_path=disp_path,
|
38
|
+
start_marker=start_marker,
|
39
|
+
end_marker=end_marker,
|
40
|
+
)
|
41
|
+
self.report_action(info_msg, ReportAction.CREATE)
|
42
|
+
try:
|
43
|
+
content = self._read_file_content(path)
|
44
|
+
occurrences, match_lines = self._find_marker_blocks(
|
45
|
+
content, start_marker, end_marker
|
46
|
+
)
|
47
|
+
if occurrences == 0:
|
48
|
+
self.report_warning(
|
49
|
+
tr(" ℹ️ No blocks found between markers."), ReportAction.CREATE
|
50
|
+
)
|
51
|
+
return tr(
|
52
|
+
"No blocks found between markers in {path}.",
|
53
|
+
path=path,
|
54
|
+
)
|
55
|
+
|
56
|
+
new_content, deleted_blocks = self._delete_blocks(
|
57
|
+
content, start_marker, end_marker
|
58
|
+
)
|
59
|
+
self._write_file_content(path, new_content)
|
60
|
+
validation_result = validate_file_syntax(path)
|
61
|
+
self._report_success(match_lines)
|
62
|
+
return tr(
|
63
|
+
"Deleted {count} block(s) between markers in {path}. ",
|
64
|
+
count=deleted_blocks,
|
65
|
+
path=path,
|
66
|
+
) + (f"\n{validation_result}" if validation_result else "")
|
67
|
+
except Exception as e:
|
68
|
+
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.REPLACE)
|
69
|
+
return tr("Error deleting text: {error}", error=e)
|
70
|
+
|
71
|
+
def _read_file_content(self, path):
|
72
|
+
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
73
|
+
return f.read()
|
74
|
+
|
75
|
+
def _find_marker_blocks(self, content, start_marker, end_marker):
|
76
|
+
"""Find all blocks between start_marker and end_marker, return count and starting line numbers."""
|
77
|
+
lines = content.splitlines(keepends=True)
|
78
|
+
joined = "".join(lines)
|
79
|
+
match_lines = []
|
80
|
+
idx = 0
|
81
|
+
occurrences = 0
|
82
|
+
while True:
|
83
|
+
start_idx = joined.find(start_marker, idx)
|
84
|
+
if start_idx == -1:
|
85
|
+
break
|
86
|
+
end_idx = joined.find(end_marker, start_idx + len(start_marker))
|
87
|
+
if end_idx == -1:
|
88
|
+
break
|
89
|
+
upto = joined[:start_idx]
|
90
|
+
line_no = upto.count("\n") + 1
|
91
|
+
match_lines.append(line_no)
|
92
|
+
idx = end_idx + len(end_marker)
|
93
|
+
occurrences += 1
|
94
|
+
return occurrences, match_lines
|
95
|
+
|
96
|
+
def _delete_blocks(self, content, start_marker, end_marker):
|
97
|
+
"""Delete all blocks between start_marker and end_marker (inclusive)."""
|
98
|
+
count = 0
|
99
|
+
new_content = content
|
100
|
+
while True:
|
101
|
+
start_idx = new_content.find(start_marker)
|
102
|
+
if start_idx == -1:
|
103
|
+
break
|
104
|
+
end_idx = new_content.find(end_marker, start_idx + len(start_marker))
|
105
|
+
if end_idx == -1:
|
106
|
+
break
|
107
|
+
new_content = (
|
108
|
+
new_content[:start_idx] + new_content[end_idx + len(end_marker) :]
|
109
|
+
)
|
110
|
+
count += 1
|
111
|
+
return new_content, count
|
112
|
+
|
113
|
+
def _backup_file(self, path, backup_path):
|
114
|
+
shutil.copy2(path, backup_path)
|
115
|
+
|
116
|
+
def _write_file_content(self, path, content):
|
117
|
+
with open(path, "w", encoding="utf-8", errors="replace") as f:
|
118
|
+
f.write(content)
|
119
|
+
|
120
|
+
def _report_success(self, match_lines):
|
121
|
+
if match_lines:
|
122
|
+
lines_str = ", ".join(str(line_no) for line_no in match_lines)
|
123
|
+
self.report_success(
|
124
|
+
tr(
|
125
|
+
" ✅ deleted block(s) starting at line(s): {lines_str}",
|
126
|
+
lines_str=lines_str,
|
127
|
+
),
|
128
|
+
ReportAction.CREATE,
|
129
|
+
)
|
130
|
+
else:
|
131
|
+
self.report_success(
|
132
|
+
tr(" ✅ deleted block(s) (lines unknown)"), ReportAction.CREATE
|
133
|
+
)
|