janito 2.33.0__py3-none-any.whl → 3.1.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/cli/chat_mode/bindings.py +26 -0
- janito/cli/chat_mode/session.py +7 -1
- janito/cli/cli_commands/check_tools.py +212 -0
- janito/cli/cli_commands/list_plugins.py +52 -43
- janito/cli/core/getters.py +3 -0
- janito/cli/main_cli.py +9 -12
- janito/cli/prompt_core.py +19 -9
- janito/drivers/openai/driver.py +1 -0
- janito/drivers/zai/driver.py +1 -0
- janito/llm/agent.py +30 -17
- janito/llm/auth_utils.py +14 -5
- janito/llm/cancellation_manager.py +62 -0
- janito/llm/driver.py +7 -0
- janito/llm/enter_cancellation.py +93 -0
- janito/plugin_system/__init__.py +10 -0
- janito/{plugins → plugin_system}/base.py +5 -2
- janito/{plugins/core_loader_fixed.py → plugin_system/core_loader.py} +45 -26
- janito/plugin_system/core_loader_fixed.py +149 -0
- janito/plugins/__init__.py +31 -12
- janito/plugins/auto_loader_fixed.py +12 -11
- janito/plugins/builtin.py +15 -1
- janito/plugins/core/__init__.py +7 -0
- janito/plugins/core/codeanalyzer/__init__.py +43 -0
- janito/plugins/core/filemanager/__init__.py +124 -0
- janito/plugins/core/filemanager/tools/create_file.py +87 -0
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +270 -0
- janito/plugins/core/imagedisplay/__init__.py +14 -0
- janito/plugins/core/imagedisplay/plugin.py +51 -0
- janito/plugins/core/imagedisplay/tools/__init__.py +1 -0
- janito/plugins/core/imagedisplay/tools/show_image.py +83 -0
- janito/{tools/adapters/local → plugins/core/imagedisplay/tools}/show_image_grid.py +13 -5
- janito/plugins/core/system/__init__.py +23 -0
- janito/plugins/core_adapter.py +11 -9
- janito/plugins/dev/__init__.py +7 -0
- janito/plugins/dev/pythondev/__init__.py +37 -0
- janito/plugins/dev/visualization/__init__.py +23 -0
- janito/plugins/discovery.py +5 -5
- janito/plugins/example_plugin.py +108 -0
- janito/plugins/manager.py +1 -1
- janito/plugins/tools/__init__.py +10 -0
- janito/{tools/adapters/local → plugins/tools}/ask_user.py +3 -3
- janito/plugins/tools/copy_file.py +87 -0
- janito/plugins/tools/core_tools_plugin.py +88 -0
- janito/plugins/tools/create_directory.py +70 -0
- janito/{tools/adapters/local → plugins/tools}/create_file.py +4 -4
- janito/plugins/tools/decorators.py +19 -0
- janito/plugins/tools/delete_text_in_file.py +134 -0
- janito/{tools/adapters/local → plugins/tools}/fetch_url.py +3 -3
- janito/plugins/tools/find_files.py +143 -0
- janito/plugins/tools/get_file_outline/__init__.py +7 -0
- janito/plugins/tools/get_file_outline/core.py +122 -0
- janito/plugins/tools/get_file_outline/java_outline.py +47 -0
- janito/plugins/tools/get_file_outline/markdown_outline.py +14 -0
- janito/plugins/tools/get_file_outline/python_outline.py +303 -0
- janito/plugins/tools/get_file_outline/search_outline.py +36 -0
- janito/plugins/tools/move_file.py +131 -0
- janito/plugins/tools/open_html_in_browser.py +51 -0
- janito/plugins/tools/open_url.py +37 -0
- janito/plugins/tools/python_code_run.py +172 -0
- janito/plugins/tools/python_command_run.py +171 -0
- janito/plugins/tools/python_file_run.py +172 -0
- janito/plugins/tools/read_chart.py +259 -0
- janito/plugins/tools/read_files.py +58 -0
- janito/plugins/tools/remove_directory.py +55 -0
- janito/plugins/tools/remove_file.py +58 -0
- janito/{tools/adapters/local → plugins/tools}/replace_text_in_file.py +4 -4
- janito/plugins/tools/run_bash_command.py +183 -0
- janito/plugins/tools/run_powershell_command.py +218 -0
- janito/plugins/tools/search_text/__init__.py +7 -0
- janito/plugins/tools/search_text/core.py +205 -0
- janito/plugins/tools/search_text/match_lines.py +67 -0
- janito/plugins/tools/search_text/pattern_utils.py +73 -0
- janito/plugins/tools/search_text/traverse_directory.py +145 -0
- janito/{tools/adapters/local → plugins/tools}/show_image.py +15 -6
- janito/plugins/tools/show_image_grid.py +85 -0
- janito/plugins/tools/validate_file_syntax/__init__.py +7 -0
- janito/plugins/tools/validate_file_syntax/core.py +114 -0
- janito/plugins/tools/validate_file_syntax/css_validator.py +35 -0
- janito/plugins/tools/validate_file_syntax/html_validator.py +100 -0
- janito/plugins/tools/validate_file_syntax/jinja2_validator.py +50 -0
- janito/plugins/tools/validate_file_syntax/js_validator.py +27 -0
- janito/plugins/tools/validate_file_syntax/json_validator.py +6 -0
- janito/plugins/tools/validate_file_syntax/markdown_validator.py +109 -0
- janito/plugins/tools/validate_file_syntax/ps1_validator.py +32 -0
- janito/plugins/tools/validate_file_syntax/python_validator.py +5 -0
- janito/plugins/tools/validate_file_syntax/xml_validator.py +11 -0
- janito/plugins/tools/validate_file_syntax/yaml_validator.py +6 -0
- janito/plugins/tools/view_file.py +172 -0
- janito/plugins/ui/__init__.py +7 -0
- janito/plugins/ui/userinterface/__init__.py +16 -0
- janito/plugins/ui/userinterface/tools/ask_user.py +110 -0
- janito/plugins/web/__init__.py +7 -0
- janito/plugins/web/webtools/__init__.py +33 -0
- janito/plugins/web/webtools/tools/fetch_url.py +458 -0
- janito/tools/__init__.py +31 -7
- janito/tools/adapters/__init__.py +6 -1
- janito/tools/adapters/local/__init__.py +7 -70
- janito/tools/cli_initializer.py +88 -0
- janito/tools/function_adapter.py +93 -16
- janito/tools/initialize.py +70 -0
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/METADATA +1 -2
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/RECORD +146 -76
- janito/plugins/core_loader.py +0 -120
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/__init__.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/core.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/java_outline.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/markdown_outline.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/python_outline.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/search_outline.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/__init__.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/core.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/match_lines.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/pattern_utils.py +0 -0
- /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/traverse_directory.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/copy_file.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/create_directory.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/delete_text_in_file.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/find_files.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/move_file.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/read_files.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_directory.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_file.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/__init__.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/core.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/css_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/html_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/js_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/json_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/python_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{tools/adapters/local → plugins/core/filemanager/tools}/view_file.py +0 -0
- /janito/{tools/adapters/local → plugins/core/system/tools}/run_bash_command.py +0 -0
- /janito/{tools/adapters/local → plugins/core/system/tools}/run_powershell_command.py +0 -0
- /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_code_run.py +0 -0
- /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_command_run.py +0 -0
- /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_file_run.py +0 -0
- /janito/{tools/adapters/local → plugins/dev/visualization/tools}/read_chart.py +0 -0
- /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_html_in_browser.py +0 -0
- /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_url.py +0 -0
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/WHEEL +0 -0
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/entry_points.txt +0 -0
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/top_level.txt +0 -0
@@ -1,12 +1,10 @@
|
|
1
1
|
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
2
|
from janito.report_events import ReportAction
|
3
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
4
3
|
from janito.i18n import tr
|
5
4
|
from janito.tools.loop_protection_decorator import protect_against_loops
|
6
5
|
from typing import Sequence
|
7
6
|
|
8
7
|
|
9
|
-
@register_local_tool
|
10
8
|
class ShowImageGridTool(ToolBase):
|
11
9
|
"""Display multiple images in a grid inline in the terminal using rich.
|
12
10
|
|
@@ -50,7 +48,9 @@ class ShowImageGridTool(ToolBase):
|
|
50
48
|
if not paths:
|
51
49
|
return tr("No images provided")
|
52
50
|
|
53
|
-
self.report_action(
|
51
|
+
self.report_action(
|
52
|
+
tr("🖼️ Show image grid ({n} images)", n=len(paths)), ReportAction.READ
|
53
|
+
)
|
54
54
|
|
55
55
|
console = Console()
|
56
56
|
images = []
|
@@ -63,7 +63,9 @@ class ShowImageGridTool(ToolBase):
|
|
63
63
|
try:
|
64
64
|
img = PILImage.open(fp)
|
65
65
|
title = f"{display_path(fp)} ({img.width}x{img.height})"
|
66
|
-
images.append(
|
66
|
+
images.append(
|
67
|
+
Panel.fit(title, title=display_path(fp), border_style="dim")
|
68
|
+
)
|
67
69
|
shown += 1
|
68
70
|
except Exception as e:
|
69
71
|
self.report_warning(tr("⚠️ Skipped {p}: {e}", p=display_path(fp), e=e))
|
@@ -71,6 +73,12 @@ class ShowImageGridTool(ToolBase):
|
|
71
73
|
if not images:
|
72
74
|
return tr("No images could be displayed")
|
73
75
|
|
76
|
+
# Render in columns (grid-like)
|
74
77
|
console.print(Columns(images, equal=True, expand=True, columns=columns))
|
75
78
|
self.report_success(tr("✅ Displayed {n} images", n=shown))
|
76
|
-
return tr(
|
79
|
+
return tr(
|
80
|
+
"Displayed {shown}/{total} images in a {cols}x? grid",
|
81
|
+
shown=shown,
|
82
|
+
total=len(paths),
|
83
|
+
cols=columns,
|
84
|
+
)
|
@@ -0,0 +1,23 @@
|
|
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]
|
janito/plugins/core_adapter.py
CHANGED
@@ -5,7 +5,7 @@ This module provides proper Plugin class implementations for core plugins
|
|
5
5
|
that use the function-based approach instead of class-based.
|
6
6
|
"""
|
7
7
|
|
8
|
-
from janito.
|
8
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
9
9
|
from typing import List, Type
|
10
10
|
from janito.tools.tool_base import ToolBase
|
11
11
|
from janito.tools.function_adapter import create_function_tool
|
@@ -13,17 +13,17 @@ from janito.tools.function_adapter import create_function_tool
|
|
13
13
|
|
14
14
|
class CorePluginAdapter(Plugin):
|
15
15
|
"""Adapter for core plugins using function-based tools."""
|
16
|
-
|
16
|
+
|
17
17
|
def __init__(self, plugin_name: str, description: str, tools_module):
|
18
18
|
super().__init__()
|
19
19
|
self._plugin_name = plugin_name
|
20
20
|
self._description = description
|
21
21
|
self._tools_module = tools_module
|
22
22
|
self._tool_classes = []
|
23
|
-
|
23
|
+
|
24
24
|
# Set the metadata attribute that Plugin expects
|
25
25
|
self.metadata = self.get_metadata()
|
26
|
-
|
26
|
+
|
27
27
|
def get_metadata(self) -> PluginMetadata:
|
28
28
|
return PluginMetadata(
|
29
29
|
name=self._plugin_name,
|
@@ -32,15 +32,15 @@ class CorePluginAdapter(Plugin):
|
|
32
32
|
author="Janito",
|
33
33
|
license="MIT",
|
34
34
|
)
|
35
|
-
|
35
|
+
|
36
36
|
def get_tools(self) -> List[Type[ToolBase]]:
|
37
37
|
return self._tool_classes
|
38
|
-
|
38
|
+
|
39
39
|
def initialize(self):
|
40
40
|
"""Initialize the plugin by creating tool classes."""
|
41
41
|
# Get tools from the module
|
42
42
|
tools = getattr(self._tools_module, "__plugin_tools__", [])
|
43
|
-
|
43
|
+
|
44
44
|
self._tool_classes = []
|
45
45
|
for tool_func in tools:
|
46
46
|
if callable(tool_func):
|
@@ -48,6 +48,8 @@ class CorePluginAdapter(Plugin):
|
|
48
48
|
self._tool_classes.append(tool_class)
|
49
49
|
|
50
50
|
|
51
|
-
def create_core_plugin(
|
51
|
+
def create_core_plugin(
|
52
|
+
plugin_name: str, description: str, tools_module
|
53
|
+
) -> CorePluginAdapter:
|
52
54
|
"""Create a core plugin adapter."""
|
53
|
-
return CorePluginAdapter(plugin_name, description, tools_module)
|
55
|
+
return CorePluginAdapter(plugin_name, description, tools_module)
|
@@ -0,0 +1,37 @@
|
|
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]
|
@@ -0,0 +1,23 @@
|
|
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/discovery.py
CHANGED
@@ -31,9 +31,9 @@ from pathlib import Path
|
|
31
31
|
from typing import Optional, List
|
32
32
|
import logging
|
33
33
|
|
34
|
-
from .base import Plugin
|
34
|
+
from janito.plugin_system.base import Plugin
|
35
35
|
from .builtin import load_builtin_plugin, BuiltinPluginRegistry
|
36
|
-
from .core_loader import load_core_plugin
|
36
|
+
from janito.plugin_system.core_loader import load_core_plugin
|
37
37
|
|
38
38
|
logger = logging.getLogger(__name__)
|
39
39
|
|
@@ -75,13 +75,13 @@ def discover_plugins(
|
|
75
75
|
parts = plugin_name.split(".")
|
76
76
|
if len(parts) == 2:
|
77
77
|
package_name, submodule_name = parts
|
78
|
-
|
78
|
+
|
79
79
|
# Handle core plugins with dedicated loader
|
80
80
|
if plugin_name.startswith(("core.", "dev.", "ui.", "web.")):
|
81
81
|
plugin = load_core_plugin(plugin_name)
|
82
82
|
if plugin:
|
83
83
|
return plugin
|
84
|
-
|
84
|
+
|
85
85
|
for base_path in all_paths:
|
86
86
|
package_path = base_path / package_name / submodule_name / "__init__.py"
|
87
87
|
if package_path.exists():
|
@@ -157,7 +157,7 @@ def _load_plugin_from_file(
|
|
157
157
|
|
158
158
|
# Check for package-based plugin with __plugin_name__ metadata
|
159
159
|
if hasattr(module, "__plugin_name__"):
|
160
|
-
from janito.
|
160
|
+
from janito.plugin_system.base import PluginMetadata
|
161
161
|
|
162
162
|
# Create a dynamic plugin class
|
163
163
|
class PackagePlugin(Plugin):
|
@@ -0,0 +1,108 @@
|
|
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/manager.py
CHANGED
@@ -10,7 +10,7 @@ from pathlib import Path
|
|
10
10
|
from typing import Dict, List, Optional, Any
|
11
11
|
import logging
|
12
12
|
|
13
|
-
from .base import Plugin, PluginMetadata
|
13
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
14
14
|
from .discovery import discover_plugins
|
15
15
|
from .config import load_plugins_config, get_user_plugins_dir
|
16
16
|
from .builtin import BuiltinPluginRegistry, load_builtin_plugin
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"""
|
2
|
+
Core tools plugin for janito.
|
3
|
+
|
4
|
+
This plugin provides the essential tools for file operations, code execution,
|
5
|
+
and system interactions that are core to janito's functionality.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from .core_tools_plugin import CoreToolsPlugin
|
9
|
+
|
10
|
+
__all__ = ["CoreToolsPlugin"]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.tools.
|
2
|
+
from janito.plugins.tools.decorators import register_core_tool
|
3
3
|
from janito.tools.loop_protection_decorator import protect_against_loops
|
4
4
|
|
5
5
|
from rich import print as rich_print
|
@@ -16,8 +16,8 @@ from prompt_toolkit.styles import Style
|
|
16
16
|
toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
|
17
17
|
|
18
18
|
|
19
|
-
@
|
20
|
-
class
|
19
|
+
@register_core_tool
|
20
|
+
class AskUser(ToolBase):
|
21
21
|
"""
|
22
22
|
Prompts the user for clarification or input with a question.
|
23
23
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import os
|
2
|
+
from janito.tools.path_utils import expand_path
|
3
|
+
import shutil
|
4
|
+
from typing import List, Union
|
5
|
+
from janito.plugins.tools.decorators import register_core_tool
|
6
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
+
from janito.tools.tool_utils import display_path
|
8
|
+
from janito.report_events import ReportAction
|
9
|
+
from janito.i18n import tr
|
10
|
+
|
11
|
+
|
12
|
+
@register_core_tool
|
13
|
+
class CopyFile(ToolBase):
|
14
|
+
"""
|
15
|
+
Copy one or more files to a target directory, or copy a single file to a new file.
|
16
|
+
Args:
|
17
|
+
sources (str): Space-separated path(s) to the file(s) to copy.
|
18
|
+
For multiple sources, provide a single string with paths separated by spaces.
|
19
|
+
target (str): Destination path. If copying multiple sources, this must be an existing directory.
|
20
|
+
overwrite (bool, optional): Overwrite existing files. Default: False.
|
21
|
+
Recommended only after reading the file to be overwritten.
|
22
|
+
Returns:
|
23
|
+
str: Status string for each copy operation.
|
24
|
+
"""
|
25
|
+
|
26
|
+
permissions = ToolPermissions(read=True, write=True)
|
27
|
+
tool_name = "copy_file"
|
28
|
+
|
29
|
+
def run(self, sources: str, target: str, overwrite: bool = False) -> str:
|
30
|
+
source_list = [expand_path(src) for src in sources.split() if src]
|
31
|
+
target = expand_path(target)
|
32
|
+
messages = []
|
33
|
+
if len(source_list) > 1:
|
34
|
+
if not os.path.isdir(target):
|
35
|
+
return tr(
|
36
|
+
"❗ Target must be an existing directory when copying multiple files: '{target}'",
|
37
|
+
target=display_path(target),
|
38
|
+
)
|
39
|
+
for src in source_list:
|
40
|
+
if not os.path.isfile(src):
|
41
|
+
messages.append(
|
42
|
+
tr(
|
43
|
+
"❗ Source file does not exist: '{src}'",
|
44
|
+
src=display_path(src),
|
45
|
+
)
|
46
|
+
)
|
47
|
+
continue
|
48
|
+
dst = os.path.join(target, os.path.basename(src))
|
49
|
+
messages.append(self._copy_one(src, dst, overwrite=overwrite))
|
50
|
+
else:
|
51
|
+
src = source_list[0]
|
52
|
+
if os.path.isdir(target):
|
53
|
+
dst = os.path.join(target, os.path.basename(src))
|
54
|
+
else:
|
55
|
+
dst = target
|
56
|
+
messages.append(self._copy_one(src, dst, overwrite=overwrite))
|
57
|
+
return "\n".join(messages)
|
58
|
+
|
59
|
+
def _copy_one(self, src, dst, overwrite=False) -> str:
|
60
|
+
disp_src = display_path(src)
|
61
|
+
disp_dst = display_path(dst)
|
62
|
+
if not os.path.isfile(src):
|
63
|
+
return tr("❗ Source file does not exist: '{src}'", src=disp_src)
|
64
|
+
if os.path.exists(dst) and not overwrite:
|
65
|
+
return tr(
|
66
|
+
"❗ Target already exists: '{dst}'. Set overwrite=True to replace.",
|
67
|
+
dst=disp_dst,
|
68
|
+
)
|
69
|
+
try:
|
70
|
+
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
71
|
+
shutil.copy2(src, dst)
|
72
|
+
note = (
|
73
|
+
"\n⚠️ Overwrote existing file. (recommended only after reading the file to be overwritten)"
|
74
|
+
if (os.path.exists(dst) and overwrite)
|
75
|
+
else ""
|
76
|
+
)
|
77
|
+
self.report_success(
|
78
|
+
tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst)
|
79
|
+
)
|
80
|
+
return tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst) + note
|
81
|
+
except Exception as e:
|
82
|
+
return tr(
|
83
|
+
"❗ Copy failed from '{src}' to '{dst}': {err}",
|
84
|
+
src=disp_src,
|
85
|
+
dst=disp_dst,
|
86
|
+
err=str(e),
|
87
|
+
)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"""
|
2
|
+
Core tools plugin implementation.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from functools import wraps
|
6
|
+
from typing import Type
|
7
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
8
|
+
|
9
|
+
# Registry for core tools
|
10
|
+
_core_tools_registry = []
|
11
|
+
|
12
|
+
|
13
|
+
def register_core_tool(cls: Type):
|
14
|
+
"""Decorator to register a core tool."""
|
15
|
+
_core_tools_registry.append(cls)
|
16
|
+
return cls
|
17
|
+
|
18
|
+
|
19
|
+
from .ask_user import AskUser
|
20
|
+
from .copy_file import CopyFile
|
21
|
+
from .create_directory import CreateDirectory
|
22
|
+
from .create_file import CreateFile
|
23
|
+
from .delete_text_in_file import DeleteTextInFile
|
24
|
+
from .fetch_url import FetchUrl
|
25
|
+
from .find_files import FindFiles
|
26
|
+
from .move_file import MoveFile
|
27
|
+
from .open_html_in_browser import OpenHtmlInBrowser
|
28
|
+
from .open_url import OpenUrl
|
29
|
+
from .python_code_run import PythonCodeRun
|
30
|
+
from .python_command_run import PythonCommandRun
|
31
|
+
from .python_file_run import PythonFileRun
|
32
|
+
from .read_chart import ReadChart
|
33
|
+
from .read_files import ReadFiles
|
34
|
+
from .remove_directory import RemoveDirectory
|
35
|
+
from .remove_file import RemoveFile
|
36
|
+
from .replace_text_in_file import ReplaceTextInFile
|
37
|
+
from .run_bash_command import RunBashCommand
|
38
|
+
from .run_powershell_command import RunPowershellCommand
|
39
|
+
from .show_image import ShowImage
|
40
|
+
from .show_image_grid import ShowImageGrid
|
41
|
+
from .view_file import ViewFile
|
42
|
+
from .validate_file_syntax.core import ValidateFileSyntax
|
43
|
+
from .get_file_outline.core import GetFileOutline
|
44
|
+
from .search_text.core import SearchText
|
45
|
+
from .decorators import get_core_tools
|
46
|
+
|
47
|
+
|
48
|
+
class CoreToolsPlugin(Plugin):
|
49
|
+
"""Core tools plugin providing essential janito functionality."""
|
50
|
+
|
51
|
+
def get_metadata(self):
|
52
|
+
return PluginMetadata(
|
53
|
+
name="core_tools",
|
54
|
+
version="1.0.0",
|
55
|
+
description="Core tools for file operations, code execution, and system interactions",
|
56
|
+
author="janito team",
|
57
|
+
license="MIT",
|
58
|
+
)
|
59
|
+
|
60
|
+
def get_tools(self):
|
61
|
+
return [
|
62
|
+
AskUser,
|
63
|
+
CopyFile,
|
64
|
+
CreateDirectory,
|
65
|
+
CreateFile,
|
66
|
+
DeleteTextInFile,
|
67
|
+
FetchUrl,
|
68
|
+
FindFiles,
|
69
|
+
MoveFile,
|
70
|
+
OpenHtmlInBrowser,
|
71
|
+
OpenUrl,
|
72
|
+
PythonCodeRun,
|
73
|
+
PythonCommandRun,
|
74
|
+
PythonFileRun,
|
75
|
+
ReadChart,
|
76
|
+
ReadFiles,
|
77
|
+
RemoveDirectory,
|
78
|
+
RemoveFile,
|
79
|
+
ReplaceTextInFile,
|
80
|
+
RunBashCommand,
|
81
|
+
RunPowershellCommand,
|
82
|
+
ShowImage,
|
83
|
+
ShowImageGrid,
|
84
|
+
ViewFile,
|
85
|
+
ValidateFileSyntax,
|
86
|
+
GetFileOutline,
|
87
|
+
SearchText,
|
88
|
+
] + get_core_tools()
|
@@ -0,0 +1,70 @@
|
|
1
|
+
from janito.plugins.tools.decorators import register_core_tool
|
2
|
+
|
3
|
+
from janito.tools.tool_utils import display_path
|
4
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
5
|
+
from janito.report_events import ReportAction
|
6
|
+
from janito.i18n import tr
|
7
|
+
import os
|
8
|
+
from janito.tools.path_utils import expand_path
|
9
|
+
|
10
|
+
|
11
|
+
@register_core_tool
|
12
|
+
class CreateDirectory(ToolBase):
|
13
|
+
"""
|
14
|
+
Create a new directory at the specified path.
|
15
|
+
Args:
|
16
|
+
path (str): Path for the new directory.
|
17
|
+
Returns:
|
18
|
+
str: Status message indicating the result. Example:
|
19
|
+
- "5c5 Successfully created the directory at ..."
|
20
|
+
- "5d7 Cannot create directory: ..."
|
21
|
+
"""
|
22
|
+
|
23
|
+
permissions = ToolPermissions(write=True)
|
24
|
+
tool_name = "create_directory"
|
25
|
+
|
26
|
+
def run(self, path: str) -> str:
|
27
|
+
path = expand_path(path)
|
28
|
+
disp_path = display_path(path)
|
29
|
+
self.report_action(
|
30
|
+
tr("📁 Create directory '{disp_path}' ...", disp_path=disp_path),
|
31
|
+
ReportAction.CREATE,
|
32
|
+
)
|
33
|
+
try:
|
34
|
+
if os.path.exists(path):
|
35
|
+
if not os.path.isdir(path):
|
36
|
+
self.report_error(
|
37
|
+
tr(
|
38
|
+
"❌ Path '{disp_path}' exists and is not a directory.",
|
39
|
+
disp_path=disp_path,
|
40
|
+
)
|
41
|
+
)
|
42
|
+
return tr(
|
43
|
+
"❌ Path '{disp_path}' exists and is not a directory.",
|
44
|
+
disp_path=disp_path,
|
45
|
+
)
|
46
|
+
self.report_error(
|
47
|
+
tr(
|
48
|
+
"❗ Directory '{disp_path}' already exists.",
|
49
|
+
disp_path=disp_path,
|
50
|
+
)
|
51
|
+
)
|
52
|
+
return tr(
|
53
|
+
"❗ Cannot create directory: '{disp_path}' already exists.",
|
54
|
+
disp_path=disp_path,
|
55
|
+
)
|
56
|
+
os.makedirs(path, exist_ok=True)
|
57
|
+
self.report_success(tr("✅ Directory created"))
|
58
|
+
return tr(
|
59
|
+
"✅ Successfully created the directory at '{disp_path}'.",
|
60
|
+
disp_path=disp_path,
|
61
|
+
)
|
62
|
+
except Exception as e:
|
63
|
+
self.report_error(
|
64
|
+
tr(
|
65
|
+
"❌ Error creating directory '{disp_path}': {error}",
|
66
|
+
disp_path=disp_path,
|
67
|
+
error=e,
|
68
|
+
)
|
69
|
+
)
|
70
|
+
return tr("❌ Cannot create directory: {error}", error=e)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
from janito.tools.path_utils import expand_path
|
3
|
-
from janito.tools.
|
3
|
+
from janito.plugins.tools.decorators import register_core_tool
|
4
4
|
|
5
5
|
from janito.tools.tool_utils import display_path
|
6
6
|
from janito.tools.tool_base import ToolBase, ToolPermissions
|
@@ -8,11 +8,11 @@ from janito.report_events import ReportAction
|
|
8
8
|
from janito.i18n import tr
|
9
9
|
from janito.tools.loop_protection_decorator import protect_against_loops
|
10
10
|
|
11
|
-
from janito.tools.
|
11
|
+
from janito.plugins.tools.validate_file_syntax.core import validate_file_syntax
|
12
12
|
|
13
13
|
|
14
|
-
@
|
15
|
-
class
|
14
|
+
@register_core_tool
|
15
|
+
class CreateFile(ToolBase):
|
16
16
|
"""
|
17
17
|
Create a new file with specified content at the given path.
|
18
18
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"""
|
2
|
+
Decorators for core tools registration.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from typing import Type
|
6
|
+
|
7
|
+
# Registry for core tools
|
8
|
+
_core_tools_registry = []
|
9
|
+
|
10
|
+
|
11
|
+
def register_core_tool(cls: Type):
|
12
|
+
"""Decorator to register a core tool."""
|
13
|
+
_core_tools_registry.append(cls)
|
14
|
+
return cls
|
15
|
+
|
16
|
+
|
17
|
+
def get_core_tools():
|
18
|
+
"""Get all registered core tools."""
|
19
|
+
return list(_core_tools_registry)
|