janito 3.4.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/check_tools.py +212 -0
- janito/cli/cli_commands/list_plugins.py +52 -43
- janito/cli/core/getters.py +3 -0
- janito/cli/core/model_guesser.py +40 -24
- janito/cli/main_cli.py +9 -12
- janito/cli/prompt_core.py +47 -9
- janito/cli/rich_terminal_reporter.py +2 -2
- janito/drivers/openai/driver.py +1 -0
- janito/drivers/zai/driver.py +1 -0
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +32 -16
- janito/llm/auth_utils.py +14 -5
- janito/llm/cancellation_manager.py +63 -0
- janito/llm/driver.py +8 -0
- janito/llm/enter_cancellation.py +107 -0
- janito/plugin_system/__init__.py +10 -0
- janito/{plugins → plugin_system}/base.py +5 -2
- janito/plugin_system/core_loader.py +217 -0
- janito/plugin_system/core_loader_fixed.py +225 -0
- janito/plugins/__init__.py +31 -12
- janito/plugins/auto_loader.py +12 -11
- 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 +89 -11
- 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/discovery_core.py +14 -9
- 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 +87 -0
- janito/plugins/tools/create_directory.py +70 -0
- janito/{tools/adapters/local → plugins/tools}/create_file.py +6 -6
- 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/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/__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/initialize.py +70 -0
- janito/tools/loop_protection_decorator.py +114 -117
- janito-3.5.0.dist-info/METADATA +229 -0
- {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/RECORD +158 -86
- janito/plugins/core_loader.py +0 -120
- janito/plugins/core_loader_fixed.py +0 -125
- janito/tools/function_adapter.py +0 -65
- janito-3.4.0.dist-info/METADATA +0 -84
- /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-3.4.0.dist-info → janito-3.5.0.dist-info}/WHEEL +0 -0
- {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/entry_points.txt +0 -0
- {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.4.0.dist-info → janito-3.5.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,25 +5,24 @@ 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
|
-
from janito.tools.tool_base import ToolBase
|
11
|
-
from janito.tools.function_adapter import create_function_tool
|
10
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
12
11
|
|
13
12
|
|
14
13
|
class CorePluginAdapter(Plugin):
|
15
14
|
"""Adapter for core plugins using function-based tools."""
|
16
|
-
|
15
|
+
|
17
16
|
def __init__(self, plugin_name: str, description: str, tools_module):
|
18
17
|
super().__init__()
|
19
18
|
self._plugin_name = plugin_name
|
20
19
|
self._description = description
|
21
20
|
self._tools_module = tools_module
|
22
21
|
self._tool_classes = []
|
23
|
-
|
22
|
+
|
24
23
|
# Set the metadata attribute that Plugin expects
|
25
24
|
self.metadata = self.get_metadata()
|
26
|
-
|
25
|
+
|
27
26
|
def get_metadata(self) -> PluginMetadata:
|
28
27
|
return PluginMetadata(
|
29
28
|
name=self._plugin_name,
|
@@ -32,22 +31,101 @@ class CorePluginAdapter(Plugin):
|
|
32
31
|
author="Janito",
|
33
32
|
license="MIT",
|
34
33
|
)
|
35
|
-
|
34
|
+
|
36
35
|
def get_tools(self) -> List[Type[ToolBase]]:
|
37
36
|
return self._tool_classes
|
37
|
+
|
38
|
+
def _create_tool_class(self, func):
|
39
|
+
"""Create a ToolBase class from a function."""
|
40
|
+
resolved_tool_name = getattr(func, "tool_name", func.__name__)
|
41
|
+
|
42
|
+
# Create a proper tool class with explicit parameters and documentation
|
43
|
+
import inspect
|
44
|
+
from typing import get_type_hints
|
45
|
+
|
46
|
+
func_sig = inspect.signature(func)
|
47
|
+
type_hints = get_type_hints(func)
|
48
|
+
|
49
|
+
# Build parameter definitions for the run method
|
50
|
+
param_defs = []
|
51
|
+
param_docs = []
|
52
|
+
for name, param in func_sig.parameters.items():
|
53
|
+
type_hint = type_hints.get(name, str)
|
54
|
+
if param.default == inspect.Parameter.empty:
|
55
|
+
param_defs.append(f"{name}: {type_hint.__name__}")
|
56
|
+
else:
|
57
|
+
param_defs.append(f"{name}: {type_hint.__name__} = {repr(param.default)}")
|
58
|
+
|
59
|
+
# Add parameter documentation
|
60
|
+
param_docs.append(f" {name}: {type_hint.__name__} - Parameter {name}")
|
61
|
+
|
62
|
+
# Get function docstring or create one
|
63
|
+
func_doc = func.__doc__ or f"Execute {resolved_tool_name} tool"
|
64
|
+
|
65
|
+
# Create the tool class with proper signature and documentation
|
66
|
+
exec_globals = {
|
67
|
+
'ToolBase': ToolBase,
|
68
|
+
'ToolPermissions': ToolPermissions,
|
69
|
+
'func': func,
|
70
|
+
'inspect': inspect,
|
71
|
+
'str': str,
|
72
|
+
'List': list,
|
73
|
+
'Dict': dict,
|
74
|
+
'Optional': type(None),
|
75
|
+
}
|
76
|
+
|
77
|
+
param_docs_str = '\n'.join(param_docs)
|
78
|
+
|
79
|
+
class_def = f'''
|
80
|
+
class DynamicTool(ToolBase):
|
81
|
+
"""
|
82
|
+
{func_doc}
|
83
|
+
|
84
|
+
Parameters:
|
85
|
+
{param_docs_str}
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
str: Execution result
|
89
|
+
"""
|
90
|
+
tool_name = "{resolved_tool_name}"
|
91
|
+
permissions = ToolPermissions(read=True, write=True, execute=True)
|
38
92
|
|
93
|
+
def __init__(self):
|
94
|
+
super().__init__()
|
95
|
+
|
96
|
+
def run(self, {', '.join(param_defs)}) -> str:
|
97
|
+
kwargs = locals()
|
98
|
+
sig = inspect.signature(func)
|
99
|
+
|
100
|
+
# Filter kwargs to only include parameters the function accepts
|
101
|
+
filtered_kwargs = {{}}
|
102
|
+
for name, param in sig.parameters.items():
|
103
|
+
if name in kwargs and kwargs[name] is not None:
|
104
|
+
filtered_kwargs[name] = kwargs[name]
|
105
|
+
|
106
|
+
result = func(**filtered_kwargs)
|
107
|
+
return str(result) if result is not None else ""
|
108
|
+
'''
|
109
|
+
|
110
|
+
exec(class_def, exec_globals)
|
111
|
+
return exec_globals['DynamicTool']
|
112
|
+
|
113
|
+
return DynamicTool
|
114
|
+
|
39
115
|
def initialize(self):
|
40
116
|
"""Initialize the plugin by creating tool classes."""
|
41
117
|
# Get tools from the module
|
42
118
|
tools = getattr(self._tools_module, "__plugin_tools__", [])
|
43
|
-
|
119
|
+
|
44
120
|
self._tool_classes = []
|
45
121
|
for tool_func in tools:
|
46
122
|
if callable(tool_func):
|
47
|
-
tool_class =
|
123
|
+
tool_class = self._create_tool_class(tool_func)
|
48
124
|
self._tool_classes.append(tool_class)
|
49
125
|
|
50
126
|
|
51
|
-
def create_core_plugin(
|
127
|
+
def create_core_plugin(
|
128
|
+
plugin_name: str, description: str, tools_module
|
129
|
+
) -> CorePluginAdapter:
|
52
130
|
"""Create a core plugin adapter."""
|
53
|
-
return CorePluginAdapter(plugin_name, description, tools_module)
|
131
|
+
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):
|
janito/plugins/discovery_core.py
CHANGED
@@ -17,11 +17,11 @@ from .core_adapter import CorePluginAdapter
|
|
17
17
|
def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
|
18
18
|
"""
|
19
19
|
Load a core plugin from a package directory.
|
20
|
-
|
20
|
+
|
21
21
|
Args:
|
22
22
|
package_path: Path to the __init__.py file
|
23
23
|
plugin_name: Full plugin name (e.g., core.filemanager)
|
24
|
-
|
24
|
+
|
25
25
|
Returns:
|
26
26
|
Plugin instance if loaded successfully
|
27
27
|
"""
|
@@ -30,20 +30,25 @@ def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
|
|
30
30
|
spec = importlib.util.spec_from_file_location(plugin_name, package_path)
|
31
31
|
if spec is None or spec.loader is None:
|
32
32
|
return None
|
33
|
-
|
33
|
+
|
34
34
|
module = importlib.util.module_from_spec(spec)
|
35
35
|
spec.loader.exec_module(module)
|
36
|
-
|
36
|
+
|
37
37
|
# Get plugin metadata
|
38
38
|
plugin_name_attr = getattr(module, "__plugin_name__", plugin_name)
|
39
|
-
description = getattr(
|
40
|
-
|
39
|
+
description = getattr(
|
40
|
+
module, "__plugin_description__", f"Core plugin: {plugin_name}"
|
41
|
+
)
|
42
|
+
|
41
43
|
# Create and return the core plugin adapter
|
42
44
|
plugin = CorePluginAdapter(plugin_name_attr, description, module)
|
43
45
|
plugin.initialize() # Initialize to set up tools
|
44
46
|
return plugin
|
45
|
-
|
47
|
+
|
46
48
|
except Exception as e:
|
47
49
|
import logging
|
48
|
-
|
49
|
-
|
50
|
+
|
51
|
+
logging.getLogger(__name__).error(
|
52
|
+
f"Failed to load core plugin {plugin_name}: {e}"
|
53
|
+
)
|
54
|
+
return None
|
@@ -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
|
+
)
|