janito 3.6.1__py3-none-any.whl → 3.7.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/README.md +4 -7
- janito/cli/chat_mode/bindings.py +0 -50
- janito/cli/chat_mode/session.py +1 -12
- janito/cli/chat_mode/shell/commands/multi.py +0 -5
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
- janito/cli/cli_commands/list_plugins.py +43 -52
- janito/cli/cli_commands/list_tools.py +1 -6
- janito/cli/core/getters.py +0 -3
- janito/cli/core/model_guesser.py +24 -40
- janito/cli/main_cli.py +13 -10
- janito/cli/prompt_core.py +9 -47
- janito/cli/rich_terminal_reporter.py +4 -4
- janito/docs/GETTING_STARTED.md +9 -8
- janito/drivers/openai/driver.py +0 -1
- janito/drivers/zai/driver.py +0 -1
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +16 -32
- janito/llm/auth_utils.py +5 -14
- janito/llm/driver.py +0 -8
- janito/plugins/__init__.py +12 -31
- janito/plugins/auto_loader.py +11 -12
- janito/plugins/auto_loader_fixed.py +11 -12
- janito/{plugin_system → plugins}/base.py +2 -5
- janito/plugins/builtin.py +1 -15
- janito/plugins/core_adapter.py +11 -89
- janito/plugins/core_loader.py +120 -0
- janito/plugins/core_loader_fixed.py +125 -0
- janito/plugins/discovery.py +5 -5
- janito/plugins/discovery_core.py +9 -14
- janito/plugins/manager.py +1 -1
- janito/providers/__init__.py +0 -1
- janito/providers/moonshot/model_info.py +7 -7
- janito/providers/moonshot/provider.py +1 -1
- janito/tools/__init__.py +7 -41
- janito/tools/adapters/__init__.py +1 -6
- janito/tools/adapters/local/__init__.py +70 -7
- janito/{plugins/tools/core → tools/adapters/local}/ask_user.py +3 -3
- janito/tools/adapters/local/copy_file.py +87 -0
- janito/tools/adapters/local/create_file.py +138 -0
- janito/{plugins/tools/core → tools/adapters/local}/fetch_url.py +23 -20
- janito/tools/adapters/local/move_file.py +131 -0
- janito/{plugins/tools/core → tools/adapters/local}/python_code_run.py +7 -23
- janito/{plugins/tools/core → tools/adapters/local}/python_command_run.py +5 -21
- janito/{plugins/tools/core → tools/adapters/local}/python_file_run.py +5 -21
- janito/tools/adapters/local/remove_file.py +58 -0
- janito/{plugins/tools/core → tools/adapters/local}/replace_text_in_file.py +4 -4
- janito/{plugins/tools/core → tools/adapters/local}/run_bash_command.py +3 -3
- janito/{plugins/tools/core → tools/adapters/local}/run_powershell_command.py +3 -3
- janito/{plugins/tools/core → tools/adapters/local}/show_image.py +6 -15
- janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
- janito/tools/adapters/local/view_file.py +172 -0
- janito/tools/function_adapter.py +65 -0
- janito/tools/loop_protection_decorator.py +117 -114
- janito-3.7.0.dist-info/METADATA +84 -0
- janito-3.7.0.dist-info/RECORD +264 -0
- janito/cli/cli_commands/check_tools.py +0 -212
- janito/data/blocked.txt +0 -96
- janito/llm/cancellation_manager.py +0 -63
- janito/llm/enter_cancellation.py +0 -107
- janito/plugin_system/__init__.py +0 -10
- janito/plugin_system/core_loader.py +0 -217
- janito/plugin_system/core_loader_fixed.py +0 -225
- janito/plugins/core/__init__.py +0 -7
- janito/plugins/core/codeanalyzer/__init__.py +0 -43
- janito/plugins/core/filemanager/__init__.py +0 -124
- janito/plugins/core/filemanager/tools/copy_file.py +0 -87
- janito/plugins/core/filemanager/tools/create_file.py +0 -87
- janito/plugins/core/filemanager/tools/move_file.py +0 -131
- janito/plugins/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins/core/filemanager/tools/view_file.py +0 -172
- janito/plugins/core/imagedisplay/__init__.py +0 -14
- janito/plugins/core/imagedisplay/plugin.py +0 -51
- janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins/core/system/__init__.py +0 -23
- janito/plugins/core/system/tools/run_bash_command.py +0 -204
- janito/plugins/core/system/tools/run_powershell_command.py +0 -234
- janito/plugins/dev/__init__.py +0 -7
- janito/plugins/dev/pythondev/__init__.py +0 -37
- janito/plugins/dev/visualization/__init__.py +0 -23
- janito/plugins/example_plugin.py +0 -108
- janito/plugins/tools/__init__.py +0 -39
- janito/plugins/tools/core/__init__.py +0 -65
- janito/plugins/tools/core/copy_file.py +0 -87
- janito/plugins/tools/core/create_directory.py +0 -70
- janito/plugins/tools/core/create_file.py +0 -138
- janito/plugins/tools/core/decorators.py +0 -19
- janito/plugins/tools/core/delete_text_in_file.py +0 -134
- janito/plugins/tools/core/find_files.py +0 -143
- janito/plugins/tools/core/get_file_outline/__init__.py +0 -7
- janito/plugins/tools/core/get_file_outline/core.py +0 -122
- janito/plugins/tools/core/get_file_outline/java_outline.py +0 -47
- janito/plugins/tools/core/get_file_outline/markdown_outline.py +0 -14
- janito/plugins/tools/core/get_file_outline/python_outline.py +0 -303
- janito/plugins/tools/core/get_file_outline/search_outline.py +0 -36
- janito/plugins/tools/core/move_file.py +0 -131
- janito/plugins/tools/core/open_html_in_browser.py +0 -51
- janito/plugins/tools/core/open_url.py +0 -37
- janito/plugins/tools/core/read_chart.py +0 -259
- janito/plugins/tools/core/read_files.py +0 -58
- janito/plugins/tools/core/remove_directory.py +0 -55
- janito/plugins/tools/core/remove_file.py +0 -58
- janito/plugins/tools/core/search_text/__init__.py +0 -7
- janito/plugins/tools/core/search_text/core.py +0 -205
- janito/plugins/tools/core/search_text/match_lines.py +0 -67
- janito/plugins/tools/core/search_text/pattern_utils.py +0 -73
- janito/plugins/tools/core/search_text/traverse_directory.py +0 -145
- janito/plugins/tools/core/show_image_grid.py +0 -85
- janito/plugins/tools/core/validate_file_syntax/__init__.py +0 -7
- janito/plugins/tools/core/validate_file_syntax/core.py +0 -114
- janito/plugins/tools/core/validate_file_syntax/css_validator.py +0 -35
- janito/plugins/tools/core/validate_file_syntax/html_validator.py +0 -100
- janito/plugins/tools/core/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins/tools/core/validate_file_syntax/js_validator.py +0 -27
- janito/plugins/tools/core/validate_file_syntax/json_validator.py +0 -6
- janito/plugins/tools/core/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins/tools/core/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins/tools/core/validate_file_syntax/python_validator.py +0 -5
- janito/plugins/tools/core/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins/tools/core/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins/tools/core/view_file.py +0 -172
- janito/plugins/ui/__init__.py +0 -7
- janito/plugins/ui/userinterface/__init__.py +0 -16
- janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins/web/__init__.py +0 -7
- janito/plugins/web/webtools/__init__.py +0 -23
- janito/providers/together/__init__.py +0 -1
- janito/providers/together/model_info.py +0 -69
- janito/providers/together/provider.py +0 -108
- janito/tools/blocked_sites.py +0 -74
- janito/tools/cli_initializer.py +0 -88
- janito/tools/initialize.py +0 -70
- janito-3.6.1.dist-info/METADATA +0 -228
- janito-3.6.1.dist-info/RECORD +0 -339
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
- /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
- {janito-3.6.1.dist-info → janito-3.7.0.dist-info}/WHEEL +0 -0
- {janito-3.6.1.dist-info → janito-3.7.0.dist-info}/entry_points.txt +0 -0
- {janito-3.6.1.dist-info → janito-3.7.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.6.1.dist-info → janito-3.7.0.dist-info}/top_level.txt +0 -0
@@ -1,204 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.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
|
-
import threading
|
34
|
-
for line in stream:
|
35
|
-
# Check for cancellation
|
36
|
-
if hasattr(self, '_cancel_event') and self._cancel_event.is_set():
|
37
|
-
break
|
38
|
-
file_obj.write(line)
|
39
|
-
file_obj.flush()
|
40
|
-
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
41
|
-
if count_func == "stdout":
|
42
|
-
counter["stdout"] += 1
|
43
|
-
else:
|
44
|
-
counter["stderr"] += 1
|
45
|
-
|
46
|
-
def run(
|
47
|
-
self,
|
48
|
-
command: str,
|
49
|
-
timeout: int = 60,
|
50
|
-
require_confirmation: bool = False,
|
51
|
-
requires_user_input: bool = False,
|
52
|
-
silent: bool = False,
|
53
|
-
) -> str:
|
54
|
-
if not command.strip():
|
55
|
-
self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
|
56
|
-
return tr("Warning: Empty command provided. Operation skipped.")
|
57
|
-
if not silent:
|
58
|
-
self.report_action(
|
59
|
-
tr("🖥️ Run bash command: {command} ...\n", command=command),
|
60
|
-
ReportAction.EXECUTE,
|
61
|
-
)
|
62
|
-
else:
|
63
|
-
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
64
|
-
if requires_user_input and not silent:
|
65
|
-
self.report_warning(
|
66
|
-
tr(
|
67
|
-
"⚠️ Warning: This command might be interactive, require user input, and might hang."
|
68
|
-
),
|
69
|
-
ReportAction.EXECUTE,
|
70
|
-
)
|
71
|
-
sys.stdout.flush()
|
72
|
-
try:
|
73
|
-
with (
|
74
|
-
tempfile.NamedTemporaryFile(
|
75
|
-
mode="w+", prefix="run_bash_stdout_", delete=False, encoding="utf-8"
|
76
|
-
) as stdout_file,
|
77
|
-
tempfile.NamedTemporaryFile(
|
78
|
-
mode="w+", prefix="run_bash_stderr_", delete=False, encoding="utf-8"
|
79
|
-
) as stderr_file,
|
80
|
-
):
|
81
|
-
env = os.environ.copy()
|
82
|
-
env["PYTHONIOENCODING"] = "utf-8"
|
83
|
-
env["LC_ALL"] = "C.UTF-8"
|
84
|
-
env["LANG"] = "C.UTF-8"
|
85
|
-
process = subprocess.Popen(
|
86
|
-
["bash", "-c", command],
|
87
|
-
stdout=subprocess.PIPE,
|
88
|
-
stderr=subprocess.PIPE,
|
89
|
-
text=True,
|
90
|
-
encoding="utf-8",
|
91
|
-
bufsize=1,
|
92
|
-
env=env,
|
93
|
-
)
|
94
|
-
# Set up cancellation event
|
95
|
-
from janito.llm.cancellation_manager import get_cancellation_manager
|
96
|
-
cancel_manager = get_cancellation_manager()
|
97
|
-
self._cancel_event = cancel_manager.get_current_cancel_event()
|
98
|
-
|
99
|
-
counter = {"stdout": 0, "stderr": 0}
|
100
|
-
stdout_thread = threading.Thread(
|
101
|
-
target=self._stream_output,
|
102
|
-
args=(
|
103
|
-
process.stdout,
|
104
|
-
stdout_file,
|
105
|
-
self.report_stdout,
|
106
|
-
"stdout",
|
107
|
-
counter,
|
108
|
-
),
|
109
|
-
)
|
110
|
-
stderr_thread = threading.Thread(
|
111
|
-
target=self._stream_output,
|
112
|
-
args=(
|
113
|
-
process.stderr,
|
114
|
-
stderr_file,
|
115
|
-
self.report_stderr,
|
116
|
-
"stderr",
|
117
|
-
counter,
|
118
|
-
),
|
119
|
-
)
|
120
|
-
stdout_thread.start()
|
121
|
-
stderr_thread.start()
|
122
|
-
try:
|
123
|
-
return_code = process.wait(timeout=timeout)
|
124
|
-
# Check if cancelled
|
125
|
-
if self._cancel_event and self._cancel_event.is_set():
|
126
|
-
process.kill()
|
127
|
-
self.report_warning(
|
128
|
-
tr("Command cancelled by user"),
|
129
|
-
ReportAction.EXECUTE,
|
130
|
-
)
|
131
|
-
return tr("Command cancelled by user")
|
132
|
-
except subprocess.TimeoutExpired:
|
133
|
-
process.kill()
|
134
|
-
self.report_error(
|
135
|
-
tr(
|
136
|
-
" ❌ Timed out after {timeout} seconds.",
|
137
|
-
timeout=timeout,
|
138
|
-
),
|
139
|
-
ReportAction.EXECUTE,
|
140
|
-
)
|
141
|
-
return tr(
|
142
|
-
"Command timed out after {timeout} seconds.", timeout=timeout
|
143
|
-
)
|
144
|
-
finally:
|
145
|
-
# Ensure threads are stopped
|
146
|
-
if self._cancel_event:
|
147
|
-
self._cancel_event.set()
|
148
|
-
stdout_thread.join(timeout=0.1)
|
149
|
-
stderr_thread.join(timeout=0.1)
|
150
|
-
stdout_file.flush()
|
151
|
-
stderr_file.flush()
|
152
|
-
if not silent:
|
153
|
-
self.report_success(
|
154
|
-
tr(
|
155
|
-
" ✅ return code {return_code}",
|
156
|
-
return_code=return_code,
|
157
|
-
),
|
158
|
-
ReportAction.EXECUTE,
|
159
|
-
)
|
160
|
-
max_lines = 100
|
161
|
-
# Read back the output for summary
|
162
|
-
stdout_file.seek(0)
|
163
|
-
stderr_file.seek(0)
|
164
|
-
stdout_content = stdout_file.read()
|
165
|
-
stderr_content = stderr_file.read()
|
166
|
-
stdout_lines = counter["stdout"]
|
167
|
-
stderr_lines = counter["stderr"]
|
168
|
-
warning_msg = ""
|
169
|
-
if requires_user_input:
|
170
|
-
warning_msg = tr(
|
171
|
-
"⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
|
172
|
-
)
|
173
|
-
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
174
|
-
result = warning_msg + tr(
|
175
|
-
"Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
|
176
|
-
return_code=return_code,
|
177
|
-
stdout_content=stdout_content,
|
178
|
-
)
|
179
|
-
if stderr_content.strip():
|
180
|
-
result += tr(
|
181
|
-
"\n--- STDERR ---\n{stderr_content}",
|
182
|
-
stderr_content=stderr_content,
|
183
|
-
)
|
184
|
-
return result
|
185
|
-
else:
|
186
|
-
result = warning_msg + tr(
|
187
|
-
"[LARGE OUTPUT]\nstdout_file: {stdout_file} (lines: {stdout_lines})\n",
|
188
|
-
stdout_file=stdout_file.name,
|
189
|
-
stdout_lines=stdout_lines,
|
190
|
-
)
|
191
|
-
if stderr_lines > 0:
|
192
|
-
result += tr(
|
193
|
-
"stderr_file: {stderr_file} (lines: {stderr_lines})\n",
|
194
|
-
stderr_file=stderr_file.name,
|
195
|
-
stderr_lines=stderr_lines,
|
196
|
-
)
|
197
|
-
result += tr(
|
198
|
-
"returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
|
199
|
-
return_code=return_code,
|
200
|
-
)
|
201
|
-
return result
|
202
|
-
except Exception as e:
|
203
|
-
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
204
|
-
return tr("Error running command: {error}", error=e)
|
@@ -1,234 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.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
|
-
tool_name = "run_powershell_command"
|
34
|
-
|
35
|
-
def _confirm_and_warn(self, command, require_confirmation, requires_user_input):
|
36
|
-
if requires_user_input:
|
37
|
-
self.report_warning(
|
38
|
-
tr(
|
39
|
-
"⚠️ Warning: This command might be interactive, require user input, and might hang."
|
40
|
-
),
|
41
|
-
ReportAction.EXECUTE,
|
42
|
-
)
|
43
|
-
if require_confirmation:
|
44
|
-
self.report_warning(
|
45
|
-
tr("⚠️ Confirmation requested, but no handler (auto-confirmed)."),
|
46
|
-
ReportAction.EXECUTE,
|
47
|
-
)
|
48
|
-
return True # Auto-confirm for now
|
49
|
-
return True
|
50
|
-
|
51
|
-
def _launch_process(self, shell_exe, command_with_encoding):
|
52
|
-
env = os.environ.copy()
|
53
|
-
env["PYTHONIOENCODING"] = "utf-8"
|
54
|
-
return subprocess.Popen(
|
55
|
-
[
|
56
|
-
shell_exe,
|
57
|
-
"-NoProfile",
|
58
|
-
"-ExecutionPolicy",
|
59
|
-
"Bypass",
|
60
|
-
"-Command",
|
61
|
-
command_with_encoding,
|
62
|
-
],
|
63
|
-
stdout=subprocess.PIPE,
|
64
|
-
stderr=subprocess.PIPE,
|
65
|
-
text=True,
|
66
|
-
bufsize=1,
|
67
|
-
universal_newlines=True,
|
68
|
-
encoding="utf-8",
|
69
|
-
env=env,
|
70
|
-
)
|
71
|
-
|
72
|
-
def _stream_output(self, stream, file_obj, report_func, count_func, counter):
|
73
|
-
for line in stream:
|
74
|
-
# Check for cancellation
|
75
|
-
if hasattr(self, '_cancel_event') and self._cancel_event.is_set():
|
76
|
-
break
|
77
|
-
file_obj.write(line)
|
78
|
-
file_obj.flush()
|
79
|
-
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
80
|
-
if count_func == "stdout":
|
81
|
-
counter["stdout"] += 1
|
82
|
-
else:
|
83
|
-
counter["stderr"] += 1
|
84
|
-
|
85
|
-
def _format_result(
|
86
|
-
self, requires_user_input, return_code, stdout_file, stderr_file, max_lines=100
|
87
|
-
):
|
88
|
-
warning_msg = ""
|
89
|
-
if requires_user_input:
|
90
|
-
warning_msg = tr(
|
91
|
-
"⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
|
92
|
-
)
|
93
|
-
with open(stdout_file.name, "r", encoding="utf-8", errors="replace") as out_f:
|
94
|
-
stdout_content = out_f.read()
|
95
|
-
with open(stderr_file.name, "r", encoding="utf-8", errors="replace") as err_f:
|
96
|
-
stderr_content = err_f.read()
|
97
|
-
stdout_lines = stdout_content.count("\n")
|
98
|
-
stderr_lines = stderr_content.count("\n")
|
99
|
-
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
100
|
-
result = warning_msg + tr(
|
101
|
-
"Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
|
102
|
-
return_code=return_code,
|
103
|
-
stdout_content=stdout_content,
|
104
|
-
)
|
105
|
-
if stderr_content.strip():
|
106
|
-
result += tr(
|
107
|
-
"\n--- STDERR ---\n{stderr_content}",
|
108
|
-
stderr_content=stderr_content,
|
109
|
-
)
|
110
|
-
return result
|
111
|
-
else:
|
112
|
-
result = warning_msg + tr(
|
113
|
-
"stdout_file: {stdout_file} (lines: {stdout_lines})\n",
|
114
|
-
stdout_file=stdout_file.name,
|
115
|
-
stdout_lines=stdout_lines,
|
116
|
-
)
|
117
|
-
if stderr_lines > 0 and stderr_content.strip():
|
118
|
-
result += tr(
|
119
|
-
"stderr_file: {stderr_file} (lines: {stderr_lines})\n",
|
120
|
-
stderr_file=stderr_file.name,
|
121
|
-
stderr_lines=stderr_lines,
|
122
|
-
)
|
123
|
-
result += tr(
|
124
|
-
"returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
|
125
|
-
return_code=return_code,
|
126
|
-
)
|
127
|
-
return result
|
128
|
-
|
129
|
-
def run(
|
130
|
-
self,
|
131
|
-
command: str,
|
132
|
-
timeout: int = 60,
|
133
|
-
require_confirmation: bool = False,
|
134
|
-
requires_user_input: bool = False,
|
135
|
-
silent: bool = False,
|
136
|
-
) -> str:
|
137
|
-
if not command.strip():
|
138
|
-
self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
|
139
|
-
return tr("Warning: Empty command provided. Operation skipped.")
|
140
|
-
encoding_prefix = "$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
|
141
|
-
command_with_encoding = encoding_prefix + command
|
142
|
-
if not silent:
|
143
|
-
self.report_action(
|
144
|
-
tr("🖥️ Running PowerShell command: {command} ...\n", command=command),
|
145
|
-
ReportAction.EXECUTE,
|
146
|
-
)
|
147
|
-
else:
|
148
|
-
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
149
|
-
self._confirm_and_warn(command, require_confirmation, requires_user_input)
|
150
|
-
from janito.platform_discovery import PlatformDiscovery
|
151
|
-
|
152
|
-
pd = PlatformDiscovery()
|
153
|
-
shell_exe = "powershell.exe" if pd.is_windows() else "pwsh"
|
154
|
-
try:
|
155
|
-
with (
|
156
|
-
tempfile.NamedTemporaryFile(
|
157
|
-
mode="w+",
|
158
|
-
prefix="run_powershell_stdout_",
|
159
|
-
delete=False,
|
160
|
-
encoding="utf-8",
|
161
|
-
) as stdout_file,
|
162
|
-
tempfile.NamedTemporaryFile(
|
163
|
-
mode="w+",
|
164
|
-
prefix="run_powershell_stderr_",
|
165
|
-
delete=False,
|
166
|
-
encoding="utf-8",
|
167
|
-
) as stderr_file,
|
168
|
-
):
|
169
|
-
# Set up cancellation event
|
170
|
-
from janito.llm.cancellation_manager import get_cancellation_manager
|
171
|
-
cancel_manager = get_cancellation_manager()
|
172
|
-
self._cancel_event = cancel_manager.get_current_cancel_event()
|
173
|
-
|
174
|
-
process = self._launch_process(shell_exe, command_with_encoding)
|
175
|
-
counter = {"stdout": 0, "stderr": 0}
|
176
|
-
stdout_thread = threading.Thread(
|
177
|
-
target=self._stream_output,
|
178
|
-
args=(
|
179
|
-
process.stdout,
|
180
|
-
stdout_file,
|
181
|
-
self.report_stdout,
|
182
|
-
"stdout",
|
183
|
-
counter,
|
184
|
-
),
|
185
|
-
)
|
186
|
-
stderr_thread = threading.Thread(
|
187
|
-
target=self._stream_output,
|
188
|
-
args=(
|
189
|
-
process.stderr,
|
190
|
-
stderr_file,
|
191
|
-
self.report_stderr,
|
192
|
-
"stderr",
|
193
|
-
counter,
|
194
|
-
),
|
195
|
-
)
|
196
|
-
stdout_thread.start()
|
197
|
-
stderr_thread.start()
|
198
|
-
try:
|
199
|
-
return_code = process.wait(timeout=timeout)
|
200
|
-
# Check if cancelled
|
201
|
-
if self._cancel_event and self._cancel_event.is_set():
|
202
|
-
process.kill()
|
203
|
-
self.report_warning(
|
204
|
-
tr("Command cancelled by user"),
|
205
|
-
ReportAction.EXECUTE,
|
206
|
-
)
|
207
|
-
return tr("Command cancelled by user")
|
208
|
-
except subprocess.TimeoutExpired:
|
209
|
-
process.kill()
|
210
|
-
self.report_error(
|
211
|
-
tr(
|
212
|
-
" ❌ Timed out after {timeout} seconds.",
|
213
|
-
timeout=timeout,
|
214
|
-
),
|
215
|
-
ReportAction.EXECUTE,
|
216
|
-
)
|
217
|
-
return tr(
|
218
|
-
"Command timed out after {timeout} seconds.", timeout=timeout
|
219
|
-
)
|
220
|
-
stdout_thread.join()
|
221
|
-
stderr_thread.join()
|
222
|
-
stdout_file.flush()
|
223
|
-
stderr_file.flush()
|
224
|
-
if not silent:
|
225
|
-
self.report_success(
|
226
|
-
tr(" ✅ return code {return_code}", return_code=return_code),
|
227
|
-
ReportAction.EXECUTE,
|
228
|
-
)
|
229
|
-
return self._format_result(
|
230
|
-
requires_user_input, return_code, stdout_file, stderr_file
|
231
|
-
)
|
232
|
-
except Exception as e:
|
233
|
-
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
234
|
-
return tr("Error running command: {error}", error=e)
|
janito/plugins/dev/__init__.py
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Python Development Plugin
|
3
|
-
|
4
|
-
Python development and execution tools.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Optional
|
8
|
-
|
9
|
-
|
10
|
-
def python_code_run(code: str, timeout: int = 60) -> str:
|
11
|
-
"""Execute Python code via stdin"""
|
12
|
-
return f"python_code_run(code='{len(code)} chars', timeout={timeout})"
|
13
|
-
|
14
|
-
|
15
|
-
python_code_run.tool_name = "python_code_run"
|
16
|
-
|
17
|
-
|
18
|
-
def python_command_run(code: str, timeout: int = 60) -> str:
|
19
|
-
"""Execute Python with -c flag"""
|
20
|
-
return f"python_command_run(code='{len(code)} chars', timeout={timeout})"
|
21
|
-
|
22
|
-
|
23
|
-
python_command_run.tool_name = "python_command_run"
|
24
|
-
|
25
|
-
|
26
|
-
def python_file_run(path: str, timeout: int = 60) -> str:
|
27
|
-
"""Run Python script files"""
|
28
|
-
return f"python_file_run(path='{path}', timeout={timeout})"
|
29
|
-
|
30
|
-
|
31
|
-
python_file_run.tool_name = "python_file_run"
|
32
|
-
|
33
|
-
|
34
|
-
# Plugin metadata
|
35
|
-
__plugin_name__ = "dev.pythondev"
|
36
|
-
__plugin_description__ = "Python development and execution"
|
37
|
-
__plugin_tools__ = [python_code_run, python_command_run, python_file_run]
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Visualization Plugin
|
3
|
-
|
4
|
-
Data visualization and charting tools.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Dict, Any
|
8
|
-
|
9
|
-
|
10
|
-
def read_chart(
|
11
|
-
data: Dict[str, Any], title: str = "Chart", width: int = 80, height: int = 20
|
12
|
-
) -> str:
|
13
|
-
"""Display charts in terminal (bar, line, pie, table)"""
|
14
|
-
return f"read_chart(type='{data.get('type')}', title='{title}')"
|
15
|
-
|
16
|
-
|
17
|
-
read_chart.tool_name = "read_chart"
|
18
|
-
|
19
|
-
|
20
|
-
# Plugin metadata
|
21
|
-
__plugin_name__ = "dev.visualization"
|
22
|
-
__plugin_description__ = "Data visualization and charts"
|
23
|
-
__plugin_tools__ = [read_chart]
|
janito/plugins/example_plugin.py
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Example plugin demonstrating the plugin system.
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.plugin_system.base import Plugin, PluginMetadata, PluginResource
|
6
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
-
from typing import Dict, Any
|
8
|
-
|
9
|
-
|
10
|
-
class HelloWorldTool(ToolBase):
|
11
|
-
"""A simple tool that says hello."""
|
12
|
-
|
13
|
-
tool_name = "hello_world"
|
14
|
-
permissions = ToolPermissions(read=True, write=False, execute=True)
|
15
|
-
|
16
|
-
def run(self, name: str = "World") -> str:
|
17
|
-
"""
|
18
|
-
Say hello to someone.
|
19
|
-
|
20
|
-
Args:
|
21
|
-
name: Name of the person to greet
|
22
|
-
|
23
|
-
Returns:
|
24
|
-
Greeting message
|
25
|
-
"""
|
26
|
-
self.report_action(f"Saying hello to {name}", "greet")
|
27
|
-
return f"Hello, {name}!"
|
28
|
-
|
29
|
-
|
30
|
-
class CalculatorTool(ToolBase):
|
31
|
-
"""A simple calculator tool."""
|
32
|
-
|
33
|
-
tool_name = "calculator"
|
34
|
-
permissions = ToolPermissions(read=True, write=False, execute=True)
|
35
|
-
|
36
|
-
def run(self, operation: str, a: float, b: float) -> str:
|
37
|
-
"""
|
38
|
-
Perform basic calculations.
|
39
|
-
|
40
|
-
Args:
|
41
|
-
operation: Operation to perform (add, subtract, multiply, divide)
|
42
|
-
a: First number
|
43
|
-
b: Second number
|
44
|
-
|
45
|
-
Returns:
|
46
|
-
Result as string
|
47
|
-
"""
|
48
|
-
self.report_action(f"Calculating {a} {operation} {b}", "calculate")
|
49
|
-
|
50
|
-
if operation == "add":
|
51
|
-
result = a + b
|
52
|
-
elif operation == "subtract":
|
53
|
-
result = a - b
|
54
|
-
elif operation == "multiply":
|
55
|
-
result = a * b
|
56
|
-
elif operation == "divide":
|
57
|
-
if b == 0:
|
58
|
-
return "Error: Division by zero"
|
59
|
-
result = a / b
|
60
|
-
else:
|
61
|
-
return f"Error: Unknown operation '{operation}'"
|
62
|
-
|
63
|
-
return str(result)
|
64
|
-
|
65
|
-
|
66
|
-
class ExamplePlugin(Plugin):
|
67
|
-
"""Example plugin providing basic tools."""
|
68
|
-
|
69
|
-
def get_metadata(self) -> PluginMetadata:
|
70
|
-
return PluginMetadata(
|
71
|
-
name="example",
|
72
|
-
version="1.0.0",
|
73
|
-
description="Example plugin with basic tools",
|
74
|
-
author="Janito Team",
|
75
|
-
license="MIT",
|
76
|
-
homepage="https://github.com/janito/example-plugin",
|
77
|
-
)
|
78
|
-
|
79
|
-
def get_tools(self):
|
80
|
-
return [HelloWorldTool, CalculatorTool]
|
81
|
-
|
82
|
-
def initialize(self):
|
83
|
-
print("Example plugin initialized!")
|
84
|
-
|
85
|
-
def cleanup(self):
|
86
|
-
print("Example plugin cleaned up!")
|
87
|
-
|
88
|
-
def get_config_schema(self) -> Dict[str, Any]:
|
89
|
-
"""Return JSON schema for plugin configuration."""
|
90
|
-
return {
|
91
|
-
"type": "object",
|
92
|
-
"properties": {
|
93
|
-
"greeting_prefix": {
|
94
|
-
"type": "string",
|
95
|
-
"description": "Custom greeting prefix for hello_world tool",
|
96
|
-
"default": "Hello",
|
97
|
-
},
|
98
|
-
"max_calculation": {
|
99
|
-
"type": "number",
|
100
|
-
"description": "Maximum allowed calculation result",
|
101
|
-
"default": 1000000,
|
102
|
-
},
|
103
|
-
},
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
# This makes the plugin discoverable
|
108
|
-
PLUGIN_CLASS = ExamplePlugin
|
janito/plugins/tools/__init__.py
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Core tools package for janito.
|
3
|
-
|
4
|
-
This package contains the essential tools for file operations, code execution,
|
5
|
-
web scraping, and system interactions that are core to janito's functionality.
|
6
|
-
"""
|
7
|
-
|
8
|
-
from .core import *
|
9
|
-
|
10
|
-
__all__ = [
|
11
|
-
'FetchUrl',
|
12
|
-
'AskUser',
|
13
|
-
'CopyFile',
|
14
|
-
'CreateDirectory',
|
15
|
-
'CreateFile',
|
16
|
-
'DeleteTextInFile',
|
17
|
-
'FindFiles',
|
18
|
-
'MoveFile',
|
19
|
-
'OpenHtmlInBrowser',
|
20
|
-
'OpenUrl',
|
21
|
-
'PythonCodeRun',
|
22
|
-
'PythonCommandRun',
|
23
|
-
'PythonFileRun',
|
24
|
-
'ReadChart',
|
25
|
-
'ReadFiles',
|
26
|
-
'RemoveDirectory',
|
27
|
-
'RemoveFile',
|
28
|
-
'ReplaceTextInFile',
|
29
|
-
'RunBashCommand',
|
30
|
-
'RunPowershellCommand',
|
31
|
-
'ShowImage',
|
32
|
-
'ShowImageGrid',
|
33
|
-
'ViewFile',
|
34
|
-
'ValidateFileSyntax',
|
35
|
-
'GetFileOutline',
|
36
|
-
'SearchText',
|
37
|
-
'get_core_tools',
|
38
|
-
'register_core_tool',
|
39
|
-
]
|