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