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,183 +1,182 @@
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 subprocess
6
- import tempfile
7
- import sys
8
- import os
9
- import threading
10
-
11
-
12
- @register_local_tool
13
- class RunBashCommandTool(ToolBase):
14
- """
15
- Execute a non-interactive command using the bash shell and capture live output.
16
- This tool explicitly invokes the 'bash' shell (not just the system default shell), so it requires bash to be installed and available in the system PATH. On Windows, this will only work if bash is available (e.g., via WSL, Git Bash, or similar).
17
-
18
- Args:
19
- command (str): The bash command to execute.
20
- timeout (int): Timeout in seconds for the command. Defaults to 60.
21
- require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
22
- requires_user_input (bool): If True, warns that the command may require user input and might hang. Defaults to False. Non-interactive commands are preferred for automation and reliability.
23
- silent (bool): If True, suppresses progress and status messages. Defaults to False.
24
-
25
- Returns:
26
- str: File paths and line counts for stdout and stderr.
27
- """
28
-
29
- permissions = ToolPermissions(execute=True)
30
- tool_name = "run_bash_command"
31
-
32
- def _stream_output(self, stream, file_obj, report_func, count_func, counter):
33
- for line in stream:
34
- file_obj.write(line)
35
- file_obj.flush()
36
- report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
37
- if count_func == "stdout":
38
- counter["stdout"] += 1
39
- else:
40
- counter["stderr"] += 1
41
-
42
- def run(
43
- self,
44
- command: str,
45
- timeout: int = 60,
46
- require_confirmation: bool = False,
47
- requires_user_input: bool = False,
48
- silent: bool = False,
49
- ) -> str:
50
- if not command.strip():
51
- self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
52
- return tr("Warning: Empty command provided. Operation skipped.")
53
- if not silent:
54
- self.report_action(
55
- tr("🖥️ Run bash command: {command} ...\n", command=command),
56
- ReportAction.EXECUTE,
57
- )
58
- else:
59
- self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
60
- if requires_user_input and not silent:
61
- self.report_warning(
62
- tr(
63
- "⚠️ Warning: This command might be interactive, require user input, and might hang."
64
- ),
65
- ReportAction.EXECUTE,
66
- )
67
- sys.stdout.flush()
68
- try:
69
- with (
70
- tempfile.NamedTemporaryFile(
71
- mode="w+", prefix="run_bash_stdout_", delete=False, encoding="utf-8"
72
- ) as stdout_file,
73
- tempfile.NamedTemporaryFile(
74
- mode="w+", prefix="run_bash_stderr_", delete=False, encoding="utf-8"
75
- ) as stderr_file,
76
- ):
77
- env = os.environ.copy()
78
- env["PYTHONIOENCODING"] = "utf-8"
79
- env["LC_ALL"] = "C.UTF-8"
80
- env["LANG"] = "C.UTF-8"
81
- process = subprocess.Popen(
82
- ["bash", "-c", command],
83
- stdout=subprocess.PIPE,
84
- stderr=subprocess.PIPE,
85
- text=True,
86
- encoding="utf-8",
87
- bufsize=1,
88
- env=env,
89
- )
90
- counter = {"stdout": 0, "stderr": 0}
91
- stdout_thread = threading.Thread(
92
- target=self._stream_output,
93
- args=(
94
- process.stdout,
95
- stdout_file,
96
- self.report_stdout,
97
- "stdout",
98
- counter,
99
- ),
100
- )
101
- stderr_thread = threading.Thread(
102
- target=self._stream_output,
103
- args=(
104
- process.stderr,
105
- stderr_file,
106
- self.report_stderr,
107
- "stderr",
108
- counter,
109
- ),
110
- )
111
- stdout_thread.start()
112
- stderr_thread.start()
113
- try:
114
- return_code = process.wait(timeout=timeout)
115
- except subprocess.TimeoutExpired:
116
- process.kill()
117
- self.report_error(
118
- tr(
119
- " ❌ Timed out after {timeout} seconds.",
120
- timeout=timeout,
121
- ),
122
- ReportAction.EXECUTE,
123
- )
124
- return tr(
125
- "Command timed out after {timeout} seconds.", timeout=timeout
126
- )
127
- stdout_thread.join()
128
- stderr_thread.join()
129
- stdout_file.flush()
130
- stderr_file.flush()
131
- if not silent:
132
- self.report_success(
133
- tr(
134
- " ✅ return code {return_code}",
135
- return_code=return_code,
136
- ),
137
- ReportAction.EXECUTE,
138
- )
139
- max_lines = 100
140
- # Read back the output for summary
141
- stdout_file.seek(0)
142
- stderr_file.seek(0)
143
- stdout_content = stdout_file.read()
144
- stderr_content = stderr_file.read()
145
- stdout_lines = counter["stdout"]
146
- stderr_lines = counter["stderr"]
147
- warning_msg = ""
148
- if requires_user_input:
149
- warning_msg = tr(
150
- "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
151
- )
152
- if stdout_lines <= max_lines and stderr_lines <= max_lines:
153
- result = warning_msg + tr(
154
- "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
155
- return_code=return_code,
156
- stdout_content=stdout_content,
157
- )
158
- if stderr_content.strip():
159
- result += tr(
160
- "\n--- STDERR ---\n{stderr_content}",
161
- stderr_content=stderr_content,
162
- )
163
- return result
164
- else:
165
- result = warning_msg + tr(
166
- "[LARGE OUTPUT]\nstdout_file: {stdout_file} (lines: {stdout_lines})\n",
167
- stdout_file=stdout_file.name,
168
- stdout_lines=stdout_lines,
169
- )
170
- if stderr_lines > 0:
171
- result += tr(
172
- "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
173
- stderr_file=stderr_file.name,
174
- stderr_lines=stderr_lines,
175
- )
176
- result += tr(
177
- "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
178
- return_code=return_code,
179
- )
180
- return result
181
- except Exception as e:
182
- self.report_error(tr(" Error: {error}", error=e), ReportAction.EXECUTE)
183
- return tr("Error running command: {error}", error=e)
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 subprocess
6
+ import tempfile
7
+ import sys
8
+ import os
9
+ import threading
10
+
11
+
12
+ @register_local_tool
13
+ class RunBashCommandTool(ToolBase):
14
+ """
15
+ Execute a non-interactive command using the bash shell and capture live output.
16
+ This tool explicitly invokes the 'bash' shell (not just the system default shell), so it requires bash to be installed and available in the system PATH. On Windows, this will only work if bash is available (e.g., via WSL, Git Bash, or similar).
17
+
18
+ Args:
19
+ command (str): The bash command to execute.
20
+ timeout (int): Timeout in seconds for the command. Defaults to 60.
21
+ require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
22
+ requires_user_input (bool): If True, warns that the command may require user input and might hang. Defaults to False. Non-interactive commands are preferred for automation and reliability.
23
+ silent (bool): If True, suppresses progress and status messages. Defaults to False.
24
+
25
+ Returns:
26
+ str: File paths and line counts for stdout and stderr.
27
+ """
28
+
29
+ permissions = ToolPermissions(execute=True)
30
+
31
+ def _stream_output(self, stream, file_obj, report_func, count_func, counter):
32
+ for line in stream:
33
+ file_obj.write(line)
34
+ file_obj.flush()
35
+ report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
36
+ if count_func == "stdout":
37
+ counter["stdout"] += 1
38
+ else:
39
+ counter["stderr"] += 1
40
+
41
+ def run(
42
+ self,
43
+ command: str,
44
+ timeout: int = 60,
45
+ require_confirmation: bool = False,
46
+ requires_user_input: bool = False,
47
+ silent: bool = False,
48
+ ) -> str:
49
+ if not command.strip():
50
+ self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
51
+ return tr("Warning: Empty command provided. Operation skipped.")
52
+ if not silent:
53
+ self.report_action(
54
+ tr("🖥️ Run bash command: {command} ...\n", command=command),
55
+ ReportAction.EXECUTE,
56
+ )
57
+ else:
58
+ self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
59
+ if requires_user_input and not silent:
60
+ self.report_warning(
61
+ tr(
62
+ "⚠️ Warning: This command might be interactive, require user input, and might hang."
63
+ ),
64
+ ReportAction.EXECUTE,
65
+ )
66
+ sys.stdout.flush()
67
+ try:
68
+ with (
69
+ tempfile.NamedTemporaryFile(
70
+ mode="w+", prefix="run_bash_stdout_", delete=False, encoding="utf-8"
71
+ ) as stdout_file,
72
+ tempfile.NamedTemporaryFile(
73
+ mode="w+", prefix="run_bash_stderr_", delete=False, encoding="utf-8"
74
+ ) as stderr_file,
75
+ ):
76
+ env = os.environ.copy()
77
+ env["PYTHONIOENCODING"] = "utf-8"
78
+ env["LC_ALL"] = "C.UTF-8"
79
+ env["LANG"] = "C.UTF-8"
80
+ process = subprocess.Popen(
81
+ ["bash", "-c", command],
82
+ stdout=subprocess.PIPE,
83
+ stderr=subprocess.PIPE,
84
+ text=True,
85
+ encoding="utf-8",
86
+ bufsize=1,
87
+ env=env,
88
+ )
89
+ counter = {"stdout": 0, "stderr": 0}
90
+ stdout_thread = threading.Thread(
91
+ target=self._stream_output,
92
+ args=(
93
+ process.stdout,
94
+ stdout_file,
95
+ self.report_stdout,
96
+ "stdout",
97
+ counter,
98
+ ),
99
+ )
100
+ stderr_thread = threading.Thread(
101
+ target=self._stream_output,
102
+ args=(
103
+ process.stderr,
104
+ stderr_file,
105
+ self.report_stderr,
106
+ "stderr",
107
+ counter,
108
+ ),
109
+ )
110
+ stdout_thread.start()
111
+ stderr_thread.start()
112
+ try:
113
+ return_code = process.wait(timeout=timeout)
114
+ except subprocess.TimeoutExpired:
115
+ process.kill()
116
+ self.report_error(
117
+ tr(
118
+ " ❌ Timed out after {timeout} seconds.",
119
+ timeout=timeout,
120
+ ),
121
+ ReportAction.EXECUTE,
122
+ )
123
+ return tr(
124
+ "Command timed out after {timeout} seconds.", timeout=timeout
125
+ )
126
+ stdout_thread.join()
127
+ stderr_thread.join()
128
+ stdout_file.flush()
129
+ stderr_file.flush()
130
+ if not silent:
131
+ self.report_success(
132
+ tr(
133
+ " ✅ return code {return_code}",
134
+ return_code=return_code,
135
+ ),
136
+ ReportAction.EXECUTE,
137
+ )
138
+ max_lines = 100
139
+ # Read back the output for summary
140
+ stdout_file.seek(0)
141
+ stderr_file.seek(0)
142
+ stdout_content = stdout_file.read()
143
+ stderr_content = stderr_file.read()
144
+ stdout_lines = counter["stdout"]
145
+ stderr_lines = counter["stderr"]
146
+ warning_msg = ""
147
+ if requires_user_input:
148
+ warning_msg = tr(
149
+ "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
150
+ )
151
+ if stdout_lines <= max_lines and stderr_lines <= max_lines:
152
+ result = warning_msg + tr(
153
+ "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
154
+ return_code=return_code,
155
+ stdout_content=stdout_content,
156
+ )
157
+ if stderr_content.strip():
158
+ result += tr(
159
+ "\n--- STDERR ---\n{stderr_content}",
160
+ stderr_content=stderr_content,
161
+ )
162
+ return result
163
+ else:
164
+ result = warning_msg + tr(
165
+ "[LARGE OUTPUT]\nstdout_file: {stdout_file} (lines: {stdout_lines})\n",
166
+ stdout_file=stdout_file.name,
167
+ stdout_lines=stdout_lines,
168
+ )
169
+ if stderr_lines > 0:
170
+ result += tr(
171
+ "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
172
+ stderr_file=stderr_file.name,
173
+ stderr_lines=stderr_lines,
174
+ )
175
+ result += tr(
176
+ "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
177
+ return_code=return_code,
178
+ )
179
+ return result
180
+ except Exception as e:
181
+ self.report_error(tr(" Error: {error}", error=e), ReportAction.EXECUTE)
182
+ return tr("Error running command: {error}", error=e)