janito 3.14.2__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/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.0.dist-info}/METADATA +9 -29
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/RECORD +36 -36
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/WHEEL +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/entry_points.txt +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.14.2.dist-info → janito-3.15.0.dist-info}/top_level.txt +0 -0
@@ -1,218 +1,217 @@
|
|
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 os
|
7
|
-
from janito.tools.path_utils import expand_path
|
8
|
-
import tempfile
|
9
|
-
import threading
|
10
|
-
|
11
|
-
|
12
|
-
@register_local_tool
|
13
|
-
class RunPowershellCommandTool(ToolBase):
|
14
|
-
"""
|
15
|
-
Execute a non-interactive command using the PowerShell shell and capture live output.
|
16
|
-
This tool explicitly invokes 'powershell.exe' (on Windows) or 'pwsh' (on other platforms if available).
|
17
|
-
All commands are automatically prepended with UTF-8 output encoding:
|
18
|
-
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
|
19
|
-
For file output, it is recommended to use -Encoding utf8 in your PowerShell commands (e.g., Out-File -Encoding utf8) to ensure correct file encoding.
|
20
|
-
|
21
|
-
Args:
|
22
|
-
command (str): The PowerShell command to execute. This string is passed directly to PowerShell using the --Command argument (not as a script file).
|
23
|
-
timeout (int): Timeout in seconds for the command. Defaults to 60.
|
24
|
-
require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
|
25
|
-
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.
|
26
|
-
silent (bool): If True, suppresses progress and status messages. Defaults to False.
|
27
|
-
|
28
|
-
Returns:
|
29
|
-
str: Output and status message, or file paths/line counts if output is large.
|
30
|
-
"""
|
31
|
-
|
32
|
-
permissions = ToolPermissions(execute=True)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
env =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"-
|
58
|
-
"
|
59
|
-
"
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
file_obj.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
stderr_lines
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
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 os
|
7
|
+
from janito.tools.path_utils import expand_path
|
8
|
+
import tempfile
|
9
|
+
import threading
|
10
|
+
|
11
|
+
|
12
|
+
@register_local_tool
|
13
|
+
class RunPowershellCommandTool(ToolBase):
|
14
|
+
"""
|
15
|
+
Execute a non-interactive command using the PowerShell shell and capture live output.
|
16
|
+
This tool explicitly invokes 'powershell.exe' (on Windows) or 'pwsh' (on other platforms if available).
|
17
|
+
All commands are automatically prepended with UTF-8 output encoding:
|
18
|
+
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
|
19
|
+
For file output, it is recommended to use -Encoding utf8 in your PowerShell commands (e.g., Out-File -Encoding utf8) to ensure correct file encoding.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
command (str): The PowerShell command to execute. This string is passed directly to PowerShell using the --Command argument (not as a script file).
|
23
|
+
timeout (int): Timeout in seconds for the command. Defaults to 60.
|
24
|
+
require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
|
25
|
+
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.
|
26
|
+
silent (bool): If True, suppresses progress and status messages. Defaults to False.
|
27
|
+
|
28
|
+
Returns:
|
29
|
+
str: Output and status message, or file paths/line counts if output is large.
|
30
|
+
"""
|
31
|
+
|
32
|
+
permissions = ToolPermissions(execute=True)
|
33
|
+
|
34
|
+
def _confirm_and_warn(self, command, require_confirmation, requires_user_input):
|
35
|
+
if requires_user_input:
|
36
|
+
self.report_warning(
|
37
|
+
tr(
|
38
|
+
"⚠️ Warning: This command might be interactive, require user input, and might hang."
|
39
|
+
),
|
40
|
+
ReportAction.EXECUTE,
|
41
|
+
)
|
42
|
+
if require_confirmation:
|
43
|
+
self.report_warning(
|
44
|
+
tr("⚠️ Confirmation requested, but no handler (auto-confirmed)."),
|
45
|
+
ReportAction.EXECUTE,
|
46
|
+
)
|
47
|
+
return True # Auto-confirm for now
|
48
|
+
return True
|
49
|
+
|
50
|
+
def _launch_process(self, shell_exe, command_with_encoding):
|
51
|
+
env = os.environ.copy()
|
52
|
+
env["PYTHONIOENCODING"] = "utf-8"
|
53
|
+
return subprocess.Popen(
|
54
|
+
[
|
55
|
+
shell_exe,
|
56
|
+
"-NoProfile",
|
57
|
+
"-ExecutionPolicy",
|
58
|
+
"Bypass",
|
59
|
+
"-Command",
|
60
|
+
command_with_encoding,
|
61
|
+
],
|
62
|
+
stdout=subprocess.PIPE,
|
63
|
+
stderr=subprocess.PIPE,
|
64
|
+
text=True,
|
65
|
+
bufsize=1,
|
66
|
+
universal_newlines=True,
|
67
|
+
encoding="utf-8",
|
68
|
+
env=env,
|
69
|
+
)
|
70
|
+
|
71
|
+
def _stream_output(self, stream, file_obj, report_func, count_func, counter):
|
72
|
+
for line in stream:
|
73
|
+
file_obj.write(line)
|
74
|
+
file_obj.flush()
|
75
|
+
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
76
|
+
if count_func == "stdout":
|
77
|
+
counter["stdout"] += 1
|
78
|
+
else:
|
79
|
+
counter["stderr"] += 1
|
80
|
+
|
81
|
+
def _format_result(
|
82
|
+
self, requires_user_input, return_code, stdout_file, stderr_file, max_lines=100
|
83
|
+
):
|
84
|
+
warning_msg = ""
|
85
|
+
if requires_user_input:
|
86
|
+
warning_msg = tr(
|
87
|
+
"⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
|
88
|
+
)
|
89
|
+
with open(stdout_file.name, "r", encoding="utf-8", errors="replace") as out_f:
|
90
|
+
stdout_content = out_f.read()
|
91
|
+
with open(stderr_file.name, "r", encoding="utf-8", errors="replace") as err_f:
|
92
|
+
stderr_content = err_f.read()
|
93
|
+
stdout_lines = stdout_content.count("\n")
|
94
|
+
stderr_lines = stderr_content.count("\n")
|
95
|
+
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
96
|
+
result = warning_msg + tr(
|
97
|
+
"Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
|
98
|
+
return_code=return_code,
|
99
|
+
stdout_content=stdout_content,
|
100
|
+
)
|
101
|
+
if stderr_content.strip():
|
102
|
+
result += tr(
|
103
|
+
"\n--- STDERR ---\n{stderr_content}",
|
104
|
+
stderr_content=stderr_content,
|
105
|
+
)
|
106
|
+
return result
|
107
|
+
else:
|
108
|
+
result = warning_msg + tr(
|
109
|
+
"stdout_file: {stdout_file} (lines: {stdout_lines})\n",
|
110
|
+
stdout_file=stdout_file.name,
|
111
|
+
stdout_lines=stdout_lines,
|
112
|
+
)
|
113
|
+
if stderr_lines > 0 and stderr_content.strip():
|
114
|
+
result += tr(
|
115
|
+
"stderr_file: {stderr_file} (lines: {stderr_lines})\n",
|
116
|
+
stderr_file=stderr_file.name,
|
117
|
+
stderr_lines=stderr_lines,
|
118
|
+
)
|
119
|
+
result += tr(
|
120
|
+
"returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
|
121
|
+
return_code=return_code,
|
122
|
+
)
|
123
|
+
return result
|
124
|
+
|
125
|
+
def run(
|
126
|
+
self,
|
127
|
+
command: str,
|
128
|
+
timeout: int = 60,
|
129
|
+
require_confirmation: bool = False,
|
130
|
+
requires_user_input: bool = False,
|
131
|
+
silent: bool = False,
|
132
|
+
) -> str:
|
133
|
+
if not command.strip():
|
134
|
+
self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
|
135
|
+
return tr("Warning: Empty command provided. Operation skipped.")
|
136
|
+
encoding_prefix = "$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
|
137
|
+
command_with_encoding = encoding_prefix + command
|
138
|
+
if not silent:
|
139
|
+
self.report_action(
|
140
|
+
tr("🖥️ Running PowerShell command: {command} ...\n", command=command),
|
141
|
+
ReportAction.EXECUTE,
|
142
|
+
)
|
143
|
+
else:
|
144
|
+
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
145
|
+
self._confirm_and_warn(command, require_confirmation, requires_user_input)
|
146
|
+
from janito.platform_discovery import PlatformDiscovery
|
147
|
+
|
148
|
+
pd = PlatformDiscovery()
|
149
|
+
shell_exe = "powershell.exe" if pd.is_windows() else "pwsh"
|
150
|
+
try:
|
151
|
+
with (
|
152
|
+
tempfile.NamedTemporaryFile(
|
153
|
+
mode="w+",
|
154
|
+
prefix="run_powershell_stdout_",
|
155
|
+
delete=False,
|
156
|
+
encoding="utf-8",
|
157
|
+
) as stdout_file,
|
158
|
+
tempfile.NamedTemporaryFile(
|
159
|
+
mode="w+",
|
160
|
+
prefix="run_powershell_stderr_",
|
161
|
+
delete=False,
|
162
|
+
encoding="utf-8",
|
163
|
+
) as stderr_file,
|
164
|
+
):
|
165
|
+
process = self._launch_process(shell_exe, command_with_encoding)
|
166
|
+
counter = {"stdout": 0, "stderr": 0}
|
167
|
+
stdout_thread = threading.Thread(
|
168
|
+
target=self._stream_output,
|
169
|
+
args=(
|
170
|
+
process.stdout,
|
171
|
+
stdout_file,
|
172
|
+
self.report_stdout,
|
173
|
+
"stdout",
|
174
|
+
counter,
|
175
|
+
),
|
176
|
+
)
|
177
|
+
stderr_thread = threading.Thread(
|
178
|
+
target=self._stream_output,
|
179
|
+
args=(
|
180
|
+
process.stderr,
|
181
|
+
stderr_file,
|
182
|
+
self.report_stderr,
|
183
|
+
"stderr",
|
184
|
+
counter,
|
185
|
+
),
|
186
|
+
)
|
187
|
+
stdout_thread.start()
|
188
|
+
stderr_thread.start()
|
189
|
+
try:
|
190
|
+
return_code = process.wait(timeout=timeout)
|
191
|
+
except subprocess.TimeoutExpired:
|
192
|
+
process.kill()
|
193
|
+
self.report_error(
|
194
|
+
tr(
|
195
|
+
" ❌ Timed out after {timeout} seconds.",
|
196
|
+
timeout=timeout,
|
197
|
+
),
|
198
|
+
ReportAction.EXECUTE,
|
199
|
+
)
|
200
|
+
return tr(
|
201
|
+
"Command timed out after {timeout} seconds.", timeout=timeout
|
202
|
+
)
|
203
|
+
stdout_thread.join()
|
204
|
+
stderr_thread.join()
|
205
|
+
stdout_file.flush()
|
206
|
+
stderr_file.flush()
|
207
|
+
if not silent:
|
208
|
+
self.report_success(
|
209
|
+
tr(" ✅ return code {return_code}", return_code=return_code),
|
210
|
+
ReportAction.EXECUTE,
|
211
|
+
)
|
212
|
+
return self._format_result(
|
213
|
+
requires_user_input, return_code, stdout_file, stderr_file
|
214
|
+
)
|
215
|
+
except Exception as e:
|
216
|
+
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
217
|
+
return tr("Error running command: {error}", error=e)
|
@@ -29,7 +29,6 @@ class ViewFileTool(ToolBase):
|
|
29
29
|
"""
|
30
30
|
|
31
31
|
permissions = ToolPermissions(read=True)
|
32
|
-
tool_name = "view_file"
|
33
32
|
|
34
33
|
@protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
|
35
34
|
def run(self, path: str, from_line: int = None, to_line: int = None, as_base64: bool = False) -> str:
|
@@ -19,7 +19,7 @@ class AlibabaProvider(LLMProvider):
|
|
19
19
|
NAME = "alibaba" # For backward compatibility
|
20
20
|
MAINTAINER = "João Pinto <janito@ikignosis.org>"
|
21
21
|
MODEL_SPECS = MODEL_SPECS
|
22
|
-
DEFAULT_MODEL = "qwen3-
|
22
|
+
DEFAULT_MODEL = "qwen3-max-preview" # 256k context, Qwen3 Max Preview standard model
|
23
23
|
available = OpenAIModelDriver.available
|
24
24
|
unavailable_reason = OpenAIModelDriver.unavailable_reason
|
25
25
|
|
janito/tools/base.py
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
-
class BaseTool:
|
2
|
-
"""Base class for all tools."""
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
if
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
class BaseTool:
|
2
|
+
"""Base class for all tools."""
|
3
|
+
|
4
|
+
@property
|
5
|
+
def tool_name(self) -> str:
|
6
|
+
"""Derive tool name from class name by convention."""
|
7
|
+
# Convert class name to snake_case and remove 'tool' suffix if present
|
8
|
+
class_name = self.__class__.__name__
|
9
|
+
if class_name.endswith('Tool'):
|
10
|
+
class_name = class_name[:-4]
|
11
|
+
|
12
|
+
# Convert CamelCase to snake_case
|
13
|
+
import re
|
14
|
+
name = re.sub(r'(?<!^)(?=[A-Z])', '_', class_name).lower()
|
15
|
+
return name
|
16
|
+
|
17
|
+
def run(self, *args, **kwargs) -> str:
|
18
|
+
"""Execute the tool."""
|
19
|
+
raise NotImplementedError
|