janito 3.3.0__py3-none-any.whl → 3.5.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 +3 -0
- janito/cli/chat_mode/bindings.py +50 -0
- janito/cli/chat_mode/session.py +12 -1
- janito/cli/chat_mode/shell/commands/multi.py +5 -0
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +47 -33
- janito/cli/cli_commands/list_plugins.py +13 -8
- janito/cli/core/model_guesser.py +40 -24
- janito/cli/prompt_core.py +47 -9
- janito/cli/rich_terminal_reporter.py +2 -2
- janito/hello.txt +0 -0
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +32 -16
- janito/llm/cancellation_manager.py +63 -0
- janito/llm/driver.py +8 -0
- janito/llm/enter_cancellation.py +107 -0
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader.py +76 -3
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader_fixed.py +79 -3
- janito/plugins/__init__.py +29 -21
- janito/{plugins_backup_20250825_070018 → plugins}/auto_loader.py +12 -11
- janito/plugins/builtin.py +1 -1
- janito/plugins/core/filemanager/tools/copy_file.py +1 -25
- janito/plugins/core/filemanager/tools/create_directory.py +1 -28
- janito/plugins/core/filemanager/tools/create_file.py +3 -27
- janito/plugins/core/filemanager/tools/delete_text_in_file.py +0 -1
- janito/plugins/core/imagedisplay/plugin.py +1 -1
- janito/plugins/core_adapter.py +131 -0
- janito/plugins/discovery.py +3 -3
- janito/{plugins_backup_20250825_070018 → plugins}/discovery_core.py +14 -9
- janito/plugins/example_plugin.py +1 -1
- janito/plugins/manager.py +1 -1
- janito/{plugins_backup_20250825_070018 → plugins}/tools/core_tools_plugin.py +9 -10
- janito/{plugins_backup_20250825_070018 → plugins}/tools/create_file.py +2 -2
- janito/{plugins_backup_20250825_070018 → plugins}/tools/delete_text_in_file.py +0 -1
- janito/providers/__init__.py +1 -0
- janito/providers/together/__init__.py +1 -0
- janito/providers/together/model_info.py +69 -0
- janito/providers/together/provider.py +108 -0
- janito/tools/base.py +1 -31
- janito/tools/cli_initializer.py +1 -1
- janito/tools/initialize.py +1 -1
- janito/tools/loop_protection_decorator.py +114 -117
- janito/tools/tool_base.py +114 -142
- janito/tools/tools_schema.py +6 -12
- janito-3.5.0.dist-info/METADATA +229 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/RECORD +98 -162
- janito/plugins/__main__.py +0 -85
- janito/plugins/base.py +0 -57
- janito/plugins/core_loader.py +0 -144
- janito/plugins_backup_20250825_070018/__init__.py +0 -36
- janito/plugins_backup_20250825_070018/builtin.py +0 -102
- janito/plugins_backup_20250825_070018/config.py +0 -84
- janito/plugins_backup_20250825_070018/core/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +0 -43
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +0 -122
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +0 -205
- janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +0 -124
- janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +0 -70
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +0 -135
- janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +0 -143
- janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +0 -131
- janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +0 -55
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +0 -114
- janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +0 -172
- janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +0 -14
- janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +0 -51
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +0 -84
- janito/plugins_backup_20250825_070018/core/system/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +0 -183
- janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +0 -218
- janito/plugins_backup_20250825_070018/core_adapter.py +0 -55
- janito/plugins_backup_20250825_070018/dev/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +0 -37
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +0 -171
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +0 -259
- janito/plugins_backup_20250825_070018/discovery.py +0 -289
- janito/plugins_backup_20250825_070018/example_plugin.py +0 -108
- janito/plugins_backup_20250825_070018/manager.py +0 -243
- janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +0 -67
- janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +0 -73
- janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +0 -145
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins_backup_20250825_070018/ui/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +0 -16
- janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins_backup_20250825_070018/web/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/web/webtools/__init__.py +0 -33
- janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +0 -458
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +0 -51
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +0 -37
- janito/tools/function_adapter.py +0 -176
- janito-3.3.0.dist-info/METADATA +0 -83
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/__init__.py +0 -0
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/base.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/auto_loader_fixed.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/ask_user.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/copy_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/create_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/decorators.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/fetch_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/find_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/java_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/python_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/search_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/move_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_html_in_browser.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_code_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_command_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_file_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_chart.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/replace_text_in_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_bash_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_powershell_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/match_lines.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/pattern_utils.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/traverse_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image_grid.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/view_file.py +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/WHEEL +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/entry_points.txt +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/top_level.txt +0 -0
@@ -1,83 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.i18n import tr
|
4
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
5
|
-
|
6
|
-
|
7
|
-
class ShowImageTool(ToolBase):
|
8
|
-
"""Display an image inline in the terminal using the rich library.
|
9
|
-
|
10
|
-
Args:
|
11
|
-
path (str): Path to the image file.
|
12
|
-
width (int, optional): Target width in terminal cells. If unset, auto-fit.
|
13
|
-
height (int, optional): Target height in terminal rows. If unset, auto-fit.
|
14
|
-
preserve_aspect (bool, optional): Preserve aspect ratio. Default: True.
|
15
|
-
|
16
|
-
Returns:
|
17
|
-
str: Status message indicating display result or error details.
|
18
|
-
"""
|
19
|
-
|
20
|
-
permissions = ToolPermissions(read=True)
|
21
|
-
tool_name = "show_image"
|
22
|
-
|
23
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
|
24
|
-
def run(
|
25
|
-
self,
|
26
|
-
path: str,
|
27
|
-
width: int | None = None,
|
28
|
-
height: int | None = None,
|
29
|
-
preserve_aspect: bool = True,
|
30
|
-
) -> str:
|
31
|
-
from janito.tools.tool_utils import display_path
|
32
|
-
from janito.tools.path_utils import expand_path
|
33
|
-
import os
|
34
|
-
|
35
|
-
# Defer heavy imports to runtime
|
36
|
-
try:
|
37
|
-
from rich.console import Console
|
38
|
-
from PIL import Image as PILImage
|
39
|
-
except Exception as e:
|
40
|
-
msg = tr("⚠️ Missing dependency: PIL/Pillow ({error})", error=e)
|
41
|
-
self.report_error(msg)
|
42
|
-
return msg
|
43
|
-
|
44
|
-
path = expand_path(path)
|
45
|
-
disp_path = display_path(path)
|
46
|
-
self.report_action(
|
47
|
-
tr("🖼️ Show image '{disp_path}'", disp_path=disp_path), ReportAction.READ
|
48
|
-
)
|
49
|
-
|
50
|
-
if not os.path.exists(path):
|
51
|
-
msg = tr("❗ not found")
|
52
|
-
self.report_warning(msg)
|
53
|
-
return tr("Error: file not found: {path}", path=disp_path)
|
54
|
-
|
55
|
-
try:
|
56
|
-
console = Console()
|
57
|
-
# rich.image.Image handles inline terminal display of common formats
|
58
|
-
from rich.console import Console
|
59
|
-
from rich.text import Text
|
60
|
-
|
61
|
-
console = Console()
|
62
|
-
img = PILImage.open(path)
|
63
|
-
console.print(
|
64
|
-
Text(
|
65
|
-
f"Image: {disp_path} ({img.width}x{img.height})", style="bold green"
|
66
|
-
)
|
67
|
-
)
|
68
|
-
console.print(img)
|
69
|
-
self.report_success(tr("✅ Displayed"))
|
70
|
-
details = []
|
71
|
-
if width:
|
72
|
-
details.append(f"width={width}")
|
73
|
-
if height:
|
74
|
-
details.append(f"height={height}")
|
75
|
-
if not preserve_aspect:
|
76
|
-
details.append("preserve_aspect=False")
|
77
|
-
info = ("; ".join(details)) if details else "auto-fit"
|
78
|
-
return tr(
|
79
|
-
"Image displayed: {disp_path} ({info})", disp_path=disp_path, info=info
|
80
|
-
)
|
81
|
-
except Exception as e:
|
82
|
-
self.report_error(tr(" ❌ Error: {error}", error=e))
|
83
|
-
return tr("Error displaying image: {error}", error=e)
|
@@ -1,84 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.i18n import tr
|
4
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
5
|
-
from typing import Sequence
|
6
|
-
|
7
|
-
|
8
|
-
class ShowImageGridTool(ToolBase):
|
9
|
-
"""Display multiple images in a grid inline in the terminal using rich.
|
10
|
-
|
11
|
-
Args:
|
12
|
-
paths (list[str]): List of image file paths.
|
13
|
-
columns (int, optional): Number of columns in the grid. Default: 2.
|
14
|
-
width (int, optional): Max width for each image cell. Default: None (auto).
|
15
|
-
height (int, optional): Max height for each image cell. Default: None (auto).
|
16
|
-
preserve_aspect (bool, optional): Preserve aspect ratio. Default: True.
|
17
|
-
|
18
|
-
Returns:
|
19
|
-
str: Status string summarizing the grid display.
|
20
|
-
"""
|
21
|
-
|
22
|
-
permissions = ToolPermissions(read=True)
|
23
|
-
tool_name = "show_image_grid"
|
24
|
-
|
25
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
|
26
|
-
def run(
|
27
|
-
self,
|
28
|
-
paths: Sequence[str],
|
29
|
-
columns: int = 2,
|
30
|
-
width: int | None = None,
|
31
|
-
height: int | None = None,
|
32
|
-
preserve_aspect: bool = True,
|
33
|
-
) -> str:
|
34
|
-
from janito.tools.path_utils import expand_path
|
35
|
-
from janito.tools.tool_utils import display_path
|
36
|
-
import os
|
37
|
-
|
38
|
-
try:
|
39
|
-
from rich.console import Console
|
40
|
-
from rich.columns import Columns
|
41
|
-
from PIL import Image as PILImage
|
42
|
-
from rich.panel import Panel
|
43
|
-
except Exception as e:
|
44
|
-
msg = tr("⚠️ Missing dependency: PIL/Pillow ({error})", error=e)
|
45
|
-
self.report_error(msg)
|
46
|
-
return msg
|
47
|
-
|
48
|
-
if not paths:
|
49
|
-
return tr("No images provided")
|
50
|
-
|
51
|
-
self.report_action(
|
52
|
-
tr("🖼️ Show image grid ({n} images)", n=len(paths)), ReportAction.READ
|
53
|
-
)
|
54
|
-
|
55
|
-
console = Console()
|
56
|
-
images = []
|
57
|
-
shown = 0
|
58
|
-
for p in paths:
|
59
|
-
fp = expand_path(p)
|
60
|
-
if not os.path.exists(fp):
|
61
|
-
self.report_warning(tr("❗ not found: {p}", p=display_path(fp)))
|
62
|
-
continue
|
63
|
-
try:
|
64
|
-
img = PILImage.open(fp)
|
65
|
-
title = f"{display_path(fp)} ({img.width}x{img.height})"
|
66
|
-
images.append(
|
67
|
-
Panel.fit(title, title=display_path(fp), border_style="dim")
|
68
|
-
)
|
69
|
-
shown += 1
|
70
|
-
except Exception as e:
|
71
|
-
self.report_warning(tr("⚠️ Skipped {p}: {e}", p=display_path(fp), e=e))
|
72
|
-
|
73
|
-
if not images:
|
74
|
-
return tr("No images could be displayed")
|
75
|
-
|
76
|
-
# Render in columns (grid-like)
|
77
|
-
console.print(Columns(images, equal=True, expand=True, columns=columns))
|
78
|
-
self.report_success(tr("✅ Displayed {n} images", n=shown))
|
79
|
-
return tr(
|
80
|
-
"Displayed {shown}/{total} images in a {cols}x? grid",
|
81
|
-
shown=shown,
|
82
|
-
total=len(paths),
|
83
|
-
cols=columns,
|
84
|
-
)
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
System Tools Plugin
|
3
|
-
|
4
|
-
System-level operations and shell access.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Optional
|
8
|
-
|
9
|
-
|
10
|
-
def run_powershell_command(
|
11
|
-
command: str, timeout: int = 60, require_confirmation: bool = False
|
12
|
-
) -> str:
|
13
|
-
"""Execute PowerShell commands"""
|
14
|
-
return f"run_powershell_command(command='{command[:50]}...', timeout={timeout})"
|
15
|
-
|
16
|
-
|
17
|
-
run_powershell_command.tool_name = "run_powershell_command"
|
18
|
-
|
19
|
-
|
20
|
-
# Plugin metadata
|
21
|
-
__plugin_name__ = "core.system"
|
22
|
-
__plugin_description__ = "System-level operations and shell access"
|
23
|
-
__plugin_tools__ = [run_powershell_command]
|
@@ -1,183 +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
|
-
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,218 +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
|
-
file_obj.write(line)
|
75
|
-
file_obj.flush()
|
76
|
-
report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
|
77
|
-
if count_func == "stdout":
|
78
|
-
counter["stdout"] += 1
|
79
|
-
else:
|
80
|
-
counter["stderr"] += 1
|
81
|
-
|
82
|
-
def _format_result(
|
83
|
-
self, requires_user_input, return_code, stdout_file, stderr_file, max_lines=100
|
84
|
-
):
|
85
|
-
warning_msg = ""
|
86
|
-
if requires_user_input:
|
87
|
-
warning_msg = tr(
|
88
|
-
"⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
|
89
|
-
)
|
90
|
-
with open(stdout_file.name, "r", encoding="utf-8", errors="replace") as out_f:
|
91
|
-
stdout_content = out_f.read()
|
92
|
-
with open(stderr_file.name, "r", encoding="utf-8", errors="replace") as err_f:
|
93
|
-
stderr_content = err_f.read()
|
94
|
-
stdout_lines = stdout_content.count("\n")
|
95
|
-
stderr_lines = stderr_content.count("\n")
|
96
|
-
if stdout_lines <= max_lines and stderr_lines <= max_lines:
|
97
|
-
result = warning_msg + tr(
|
98
|
-
"Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
|
99
|
-
return_code=return_code,
|
100
|
-
stdout_content=stdout_content,
|
101
|
-
)
|
102
|
-
if stderr_content.strip():
|
103
|
-
result += tr(
|
104
|
-
"\n--- STDERR ---\n{stderr_content}",
|
105
|
-
stderr_content=stderr_content,
|
106
|
-
)
|
107
|
-
return result
|
108
|
-
else:
|
109
|
-
result = warning_msg + tr(
|
110
|
-
"stdout_file: {stdout_file} (lines: {stdout_lines})\n",
|
111
|
-
stdout_file=stdout_file.name,
|
112
|
-
stdout_lines=stdout_lines,
|
113
|
-
)
|
114
|
-
if stderr_lines > 0 and stderr_content.strip():
|
115
|
-
result += tr(
|
116
|
-
"stderr_file: {stderr_file} (lines: {stderr_lines})\n",
|
117
|
-
stderr_file=stderr_file.name,
|
118
|
-
stderr_lines=stderr_lines,
|
119
|
-
)
|
120
|
-
result += tr(
|
121
|
-
"returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
|
122
|
-
return_code=return_code,
|
123
|
-
)
|
124
|
-
return result
|
125
|
-
|
126
|
-
def run(
|
127
|
-
self,
|
128
|
-
command: str,
|
129
|
-
timeout: int = 60,
|
130
|
-
require_confirmation: bool = False,
|
131
|
-
requires_user_input: bool = False,
|
132
|
-
silent: bool = False,
|
133
|
-
) -> str:
|
134
|
-
if not command.strip():
|
135
|
-
self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
|
136
|
-
return tr("Warning: Empty command provided. Operation skipped.")
|
137
|
-
encoding_prefix = "$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
|
138
|
-
command_with_encoding = encoding_prefix + command
|
139
|
-
if not silent:
|
140
|
-
self.report_action(
|
141
|
-
tr("🖥️ Running PowerShell command: {command} ...\n", command=command),
|
142
|
-
ReportAction.EXECUTE,
|
143
|
-
)
|
144
|
-
else:
|
145
|
-
self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
|
146
|
-
self._confirm_and_warn(command, require_confirmation, requires_user_input)
|
147
|
-
from janito.platform_discovery import PlatformDiscovery
|
148
|
-
|
149
|
-
pd = PlatformDiscovery()
|
150
|
-
shell_exe = "powershell.exe" if pd.is_windows() else "pwsh"
|
151
|
-
try:
|
152
|
-
with (
|
153
|
-
tempfile.NamedTemporaryFile(
|
154
|
-
mode="w+",
|
155
|
-
prefix="run_powershell_stdout_",
|
156
|
-
delete=False,
|
157
|
-
encoding="utf-8",
|
158
|
-
) as stdout_file,
|
159
|
-
tempfile.NamedTemporaryFile(
|
160
|
-
mode="w+",
|
161
|
-
prefix="run_powershell_stderr_",
|
162
|
-
delete=False,
|
163
|
-
encoding="utf-8",
|
164
|
-
) as stderr_file,
|
165
|
-
):
|
166
|
-
process = self._launch_process(shell_exe, command_with_encoding)
|
167
|
-
counter = {"stdout": 0, "stderr": 0}
|
168
|
-
stdout_thread = threading.Thread(
|
169
|
-
target=self._stream_output,
|
170
|
-
args=(
|
171
|
-
process.stdout,
|
172
|
-
stdout_file,
|
173
|
-
self.report_stdout,
|
174
|
-
"stdout",
|
175
|
-
counter,
|
176
|
-
),
|
177
|
-
)
|
178
|
-
stderr_thread = threading.Thread(
|
179
|
-
target=self._stream_output,
|
180
|
-
args=(
|
181
|
-
process.stderr,
|
182
|
-
stderr_file,
|
183
|
-
self.report_stderr,
|
184
|
-
"stderr",
|
185
|
-
counter,
|
186
|
-
),
|
187
|
-
)
|
188
|
-
stdout_thread.start()
|
189
|
-
stderr_thread.start()
|
190
|
-
try:
|
191
|
-
return_code = process.wait(timeout=timeout)
|
192
|
-
except subprocess.TimeoutExpired:
|
193
|
-
process.kill()
|
194
|
-
self.report_error(
|
195
|
-
tr(
|
196
|
-
" ❌ Timed out after {timeout} seconds.",
|
197
|
-
timeout=timeout,
|
198
|
-
),
|
199
|
-
ReportAction.EXECUTE,
|
200
|
-
)
|
201
|
-
return tr(
|
202
|
-
"Command timed out after {timeout} seconds.", timeout=timeout
|
203
|
-
)
|
204
|
-
stdout_thread.join()
|
205
|
-
stderr_thread.join()
|
206
|
-
stdout_file.flush()
|
207
|
-
stderr_file.flush()
|
208
|
-
if not silent:
|
209
|
-
self.report_success(
|
210
|
-
tr(" ✅ return code {return_code}", return_code=return_code),
|
211
|
-
ReportAction.EXECUTE,
|
212
|
-
)
|
213
|
-
return self._format_result(
|
214
|
-
requires_user_input, return_code, stdout_file, stderr_file
|
215
|
-
)
|
216
|
-
except Exception as e:
|
217
|
-
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
|
218
|
-
return tr("Error running command: {error}", error=e)
|
@@ -1,55 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Core plugin adapter for legacy plugin system.
|
3
|
-
|
4
|
-
This module provides proper Plugin class implementations for core plugins
|
5
|
-
that use the function-based approach instead of class-based.
|
6
|
-
"""
|
7
|
-
|
8
|
-
from janito.plugin_system.base import Plugin, PluginMetadata
|
9
|
-
from typing import List, Type
|
10
|
-
from janito.tools.tool_base import ToolBase
|
11
|
-
from janito.tools.function_adapter import create_function_tool
|
12
|
-
|
13
|
-
|
14
|
-
class CorePluginAdapter(Plugin):
|
15
|
-
"""Adapter for core plugins using function-based tools."""
|
16
|
-
|
17
|
-
def __init__(self, plugin_name: str, description: str, tools_module):
|
18
|
-
super().__init__()
|
19
|
-
self._plugin_name = plugin_name
|
20
|
-
self._description = description
|
21
|
-
self._tools_module = tools_module
|
22
|
-
self._tool_classes = []
|
23
|
-
|
24
|
-
# Set the metadata attribute that Plugin expects
|
25
|
-
self.metadata = self.get_metadata()
|
26
|
-
|
27
|
-
def get_metadata(self) -> PluginMetadata:
|
28
|
-
return PluginMetadata(
|
29
|
-
name=self._plugin_name,
|
30
|
-
version="1.0.0",
|
31
|
-
description=self._description,
|
32
|
-
author="Janito",
|
33
|
-
license="MIT",
|
34
|
-
)
|
35
|
-
|
36
|
-
def get_tools(self) -> List[Type[ToolBase]]:
|
37
|
-
return self._tool_classes
|
38
|
-
|
39
|
-
def initialize(self):
|
40
|
-
"""Initialize the plugin by creating tool classes."""
|
41
|
-
# Get tools from the module
|
42
|
-
tools = getattr(self._tools_module, "__plugin_tools__", [])
|
43
|
-
|
44
|
-
self._tool_classes = []
|
45
|
-
for tool_func in tools:
|
46
|
-
if callable(tool_func):
|
47
|
-
tool_class = create_function_tool(tool_func)
|
48
|
-
self._tool_classes.append(tool_class)
|
49
|
-
|
50
|
-
|
51
|
-
def create_core_plugin(
|
52
|
-
plugin_name: str, description: str, tools_module
|
53
|
-
) -> CorePluginAdapter:
|
54
|
-
"""Create a core plugin adapter."""
|
55
|
-
return CorePluginAdapter(plugin_name, description, tools_module)
|