janito 2.32.0__py3-none-any.whl → 3.0.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/agent/setup_agent.py +26 -0
- janito/agent/templates/profiles/system_prompt_template_Developer_with_Python_Tools.txt.j2 +2 -0
- janito/agent/templates/profiles/system_prompt_template_developer.txt.j2 +2 -0
- janito/agent/templates/profiles/system_prompt_template_market_analyst.txt.j2 +2 -0
- janito/agent/templates/profiles/system_prompt_template_model_conversation_without_tools_or_context.txt.j2 +2 -0
- 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/drivers/openai/driver.py +1 -0
- janito/drivers/zai/driver.py +1 -0
- janito/llm/auth_utils.py +14 -5
- 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/plugins/tools/fetch_url.py +466 -0
- 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/{tools/adapters/local → plugins/web/webtools/tools}/fetch_url.py +37 -27
- 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.32.0.dist-info → janito-3.0.0.dist-info}/METADATA +1 -2
- {janito-2.32.0.dist-info → janito-3.0.0.dist-info}/RECORD +144 -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.32.0.dist-info → janito-3.0.0.dist-info}/WHEEL +0 -0
- {janito-2.32.0.dist-info → janito-3.0.0.dist-info}/entry_points.txt +0 -0
- {janito-2.32.0.dist-info → janito-3.0.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.32.0.dist-info → janito-3.0.0.dist-info}/top_level.txt +0 -0
@@ -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)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
+
from janito.report_events import ReportAction
|
3
|
+
from janito.plugins.tools.decorators import register_core_tool
|
4
|
+
from janito.i18n import tr
|
5
|
+
import shutil
|
6
|
+
from janito.plugins.tools.validate_file_syntax.core import validate_file_syntax
|
7
|
+
|
8
|
+
|
9
|
+
@register_core_tool
|
10
|
+
class DeleteTextInFile(ToolBase):
|
11
|
+
"""
|
12
|
+
Delete all occurrences of text between start_marker and end_marker (inclusive) in a file, using exact string markers.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
path (str): Path to the file to modify.
|
16
|
+
start_marker (str): The starting delimiter string.
|
17
|
+
end_marker (str): The ending delimiter string.
|
18
|
+
|
19
|
+
Returns:
|
20
|
+
str: Status message indicating the result.
|
21
|
+
"""
|
22
|
+
|
23
|
+
permissions = ToolPermissions(read=True, write=True)
|
24
|
+
tool_name = "delete_text_in_file"
|
25
|
+
|
26
|
+
def run(
|
27
|
+
self,
|
28
|
+
path: str,
|
29
|
+
start_marker: str,
|
30
|
+
end_marker: str,
|
31
|
+
backup: bool = False,
|
32
|
+
) -> str:
|
33
|
+
from janito.tools.tool_utils import display_path
|
34
|
+
|
35
|
+
disp_path = display_path(path)
|
36
|
+
info_msg = tr(
|
37
|
+
"📝 Delete text in {disp_path} between markers: '{start_marker}' ... '{end_marker}'",
|
38
|
+
disp_path=disp_path,
|
39
|
+
start_marker=start_marker,
|
40
|
+
end_marker=end_marker,
|
41
|
+
)
|
42
|
+
self.report_action(info_msg, ReportAction.CREATE)
|
43
|
+
try:
|
44
|
+
content = self._read_file_content(path)
|
45
|
+
occurrences, match_lines = self._find_marker_blocks(
|
46
|
+
content, start_marker, end_marker
|
47
|
+
)
|
48
|
+
if occurrences == 0:
|
49
|
+
self.report_warning(
|
50
|
+
tr(" ℹ️ No blocks found between markers."), ReportAction.CREATE
|
51
|
+
)
|
52
|
+
return tr(
|
53
|
+
"No blocks found between markers in {path}.",
|
54
|
+
path=path,
|
55
|
+
)
|
56
|
+
|
57
|
+
new_content, deleted_blocks = self._delete_blocks(
|
58
|
+
content, start_marker, end_marker
|
59
|
+
)
|
60
|
+
self._write_file_content(path, new_content)
|
61
|
+
validation_result = validate_file_syntax(path)
|
62
|
+
self._report_success(match_lines)
|
63
|
+
return tr(
|
64
|
+
"Deleted {count} block(s) between markers in {path}. ",
|
65
|
+
count=deleted_blocks,
|
66
|
+
path=path,
|
67
|
+
) + (f"\n{validation_result}" if validation_result else "")
|
68
|
+
except Exception as e:
|
69
|
+
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.REPLACE)
|
70
|
+
return tr("Error deleting text: {error}", error=e)
|
71
|
+
|
72
|
+
def _read_file_content(self, path):
|
73
|
+
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
74
|
+
return f.read()
|
75
|
+
|
76
|
+
def _find_marker_blocks(self, content, start_marker, end_marker):
|
77
|
+
"""Find all blocks between start_marker and end_marker, return count and starting line numbers."""
|
78
|
+
lines = content.splitlines(keepends=True)
|
79
|
+
joined = "".join(lines)
|
80
|
+
match_lines = []
|
81
|
+
idx = 0
|
82
|
+
occurrences = 0
|
83
|
+
while True:
|
84
|
+
start_idx = joined.find(start_marker, idx)
|
85
|
+
if start_idx == -1:
|
86
|
+
break
|
87
|
+
end_idx = joined.find(end_marker, start_idx + len(start_marker))
|
88
|
+
if end_idx == -1:
|
89
|
+
break
|
90
|
+
upto = joined[:start_idx]
|
91
|
+
line_no = upto.count("\n") + 1
|
92
|
+
match_lines.append(line_no)
|
93
|
+
idx = end_idx + len(end_marker)
|
94
|
+
occurrences += 1
|
95
|
+
return occurrences, match_lines
|
96
|
+
|
97
|
+
def _delete_blocks(self, content, start_marker, end_marker):
|
98
|
+
"""Delete all blocks between start_marker and end_marker (inclusive)."""
|
99
|
+
count = 0
|
100
|
+
new_content = content
|
101
|
+
while True:
|
102
|
+
start_idx = new_content.find(start_marker)
|
103
|
+
if start_idx == -1:
|
104
|
+
break
|
105
|
+
end_idx = new_content.find(end_marker, start_idx + len(start_marker))
|
106
|
+
if end_idx == -1:
|
107
|
+
break
|
108
|
+
new_content = (
|
109
|
+
new_content[:start_idx] + new_content[end_idx + len(end_marker) :]
|
110
|
+
)
|
111
|
+
count += 1
|
112
|
+
return new_content, count
|
113
|
+
|
114
|
+
def _backup_file(self, path, backup_path):
|
115
|
+
shutil.copy2(path, backup_path)
|
116
|
+
|
117
|
+
def _write_file_content(self, path, content):
|
118
|
+
with open(path, "w", encoding="utf-8", errors="replace") as f:
|
119
|
+
f.write(content)
|
120
|
+
|
121
|
+
def _report_success(self, match_lines):
|
122
|
+
if match_lines:
|
123
|
+
lines_str = ", ".join(str(line_no) for line_no in match_lines)
|
124
|
+
self.report_success(
|
125
|
+
tr(
|
126
|
+
" ✅ deleted block(s) starting at line(s): {lines_str}",
|
127
|
+
lines_str=lines_str,
|
128
|
+
),
|
129
|
+
ReportAction.CREATE,
|
130
|
+
)
|
131
|
+
else:
|
132
|
+
self.report_success(
|
133
|
+
tr(" ✅ deleted block(s) (lines unknown)"), ReportAction.CREATE
|
134
|
+
)
|