janito 2.33.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/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/{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.0.0.dist-info}/METADATA +1 -2
- {janito-2.33.0.dist-info → janito-3.0.0.dist-info}/RECORD +139 -71
- 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.0.0.dist-info}/WHEEL +0 -0
- {janito-2.33.0.dist-info → janito-3.0.0.dist-info}/entry_points.txt +0 -0
- {janito-2.33.0.dist-info → janito-3.0.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.33.0.dist-info → janito-3.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
"""
|
2
|
+
Fixed core plugin loader.
|
3
|
+
|
4
|
+
This module provides a working implementation to load core plugins
|
5
|
+
by directly using the Plugin base class properly.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import importlib.util
|
9
|
+
import sys
|
10
|
+
from pathlib import Path
|
11
|
+
from typing import Optional, List, Type
|
12
|
+
|
13
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
14
|
+
from janito.tools.function_adapter import create_function_tool
|
15
|
+
from janito.tools.tool_base import ToolBase
|
16
|
+
|
17
|
+
|
18
|
+
class CorePlugin(Plugin):
|
19
|
+
"""Working core plugin implementation."""
|
20
|
+
|
21
|
+
def __init__(self, name: str, description: str, tools: list):
|
22
|
+
self._plugin_name = name
|
23
|
+
self._description = description
|
24
|
+
self._tools = tools
|
25
|
+
self._tool_classes = []
|
26
|
+
super().__init__() # Call super after setting attributes
|
27
|
+
|
28
|
+
def get_metadata(self) -> PluginMetadata:
|
29
|
+
return PluginMetadata(
|
30
|
+
name=self._plugin_name,
|
31
|
+
version="1.0.0",
|
32
|
+
description=self._description,
|
33
|
+
author="Janito",
|
34
|
+
license="MIT",
|
35
|
+
)
|
36
|
+
|
37
|
+
def get_tools(self) -> List[Type[ToolBase]]:
|
38
|
+
return self._tool_classes
|
39
|
+
|
40
|
+
def initialize(self):
|
41
|
+
"""Initialize by creating tool classes."""
|
42
|
+
self._tool_classes = []
|
43
|
+
for tool_func in self._tools:
|
44
|
+
if callable(tool_func):
|
45
|
+
tool_class = create_function_tool(tool_func)
|
46
|
+
self._tool_classes.append(tool_class)
|
47
|
+
|
48
|
+
|
49
|
+
def load_core_plugin(plugin_name: str) -> Optional[Plugin]:
|
50
|
+
"""
|
51
|
+
Load a core plugin by name.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
plugin_name: Name of the plugin (e.g., 'core.filemanager')
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
Plugin instance if loaded successfully
|
58
|
+
"""
|
59
|
+
try:
|
60
|
+
# Parse plugin name
|
61
|
+
if "." not in plugin_name:
|
62
|
+
return None
|
63
|
+
|
64
|
+
parts = plugin_name.split(".")
|
65
|
+
if len(parts) != 2:
|
66
|
+
return None
|
67
|
+
|
68
|
+
package_name, submodule_name = parts
|
69
|
+
|
70
|
+
# Handle imagedisplay specially
|
71
|
+
if plugin_name == "core.imagedisplay":
|
72
|
+
# Import the actual plugin class
|
73
|
+
try:
|
74
|
+
from janito.plugins.core.imagedisplay.plugin import ImageDisplayPlugin
|
75
|
+
|
76
|
+
return ImageDisplayPlugin()
|
77
|
+
except ImportError as e:
|
78
|
+
print(f"Failed to load imagedisplay: {e}")
|
79
|
+
return None
|
80
|
+
|
81
|
+
# Build path to plugin
|
82
|
+
plugin_path = (
|
83
|
+
Path("janito/plugins") / package_name / submodule_name / "__init__.py"
|
84
|
+
)
|
85
|
+
if not plugin_path.exists():
|
86
|
+
return None
|
87
|
+
|
88
|
+
# Load the module
|
89
|
+
spec = importlib.util.spec_from_file_location(plugin_name, plugin_path)
|
90
|
+
if spec is None or spec.loader is None:
|
91
|
+
return None
|
92
|
+
|
93
|
+
module = importlib.util.module_from_spec(spec)
|
94
|
+
|
95
|
+
# Add module to sys.modules to prevent circular imports
|
96
|
+
sys.modules[plugin_name] = module
|
97
|
+
|
98
|
+
try:
|
99
|
+
# Read and execute the module content
|
100
|
+
with open(plugin_path, "r", encoding="utf-8") as f:
|
101
|
+
code = f.read()
|
102
|
+
|
103
|
+
# Execute in module's namespace
|
104
|
+
exec(code, module.__dict__)
|
105
|
+
|
106
|
+
# Get plugin info
|
107
|
+
name = module.__dict__.get("__plugin_name__", plugin_name)
|
108
|
+
description = module.__dict__.get(
|
109
|
+
"__plugin_description__", f"Core plugin: {plugin_name}"
|
110
|
+
)
|
111
|
+
tools = module.__dict__.get("__plugin_tools__", [])
|
112
|
+
|
113
|
+
if not tools:
|
114
|
+
return None
|
115
|
+
|
116
|
+
# Ensure all tools have tool_name attribute
|
117
|
+
for tool in tools:
|
118
|
+
if tool is not None and not hasattr(tool, "tool_name"):
|
119
|
+
tool.tool_name = tool.__name__
|
120
|
+
|
121
|
+
# Create plugin
|
122
|
+
plugin = CorePlugin(name, description, tools)
|
123
|
+
plugin.initialize()
|
124
|
+
return plugin
|
125
|
+
finally:
|
126
|
+
# Clean up sys.modules
|
127
|
+
if plugin_name in sys.modules:
|
128
|
+
del sys.modules[plugin_name]
|
129
|
+
|
130
|
+
except Exception as e:
|
131
|
+
print(f"Error loading core plugin {plugin_name}: {e}")
|
132
|
+
return None
|
133
|
+
|
134
|
+
|
135
|
+
def get_core_plugins() -> list:
|
136
|
+
"""Get list of all available core plugins."""
|
137
|
+
core_plugins = [
|
138
|
+
"core.filemanager",
|
139
|
+
"core.codeanalyzer",
|
140
|
+
"core.system",
|
141
|
+
"core.imagedisplay",
|
142
|
+
"dev.pythondev",
|
143
|
+
"dev.visualization",
|
144
|
+
"ui.userinterface",
|
145
|
+
"web.webtools",
|
146
|
+
]
|
147
|
+
|
148
|
+
# All core plugins are always available
|
149
|
+
return core_plugins
|
janito/plugins/__init__.py
CHANGED
@@ -1,17 +1,36 @@
|
|
1
1
|
"""
|
2
|
-
Plugin
|
2
|
+
Plugin System for Development Tools
|
3
3
|
|
4
|
-
This package
|
5
|
-
|
4
|
+
This package organizes all available tools into logical plugin groups
|
5
|
+
for easier discovery and usage.
|
6
6
|
"""
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
from .discovery import discover_plugins
|
8
|
+
__version__ = "1.0.0"
|
9
|
+
__author__ = "Development Assistant"
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
from .core import filemanager, codeanalyzer, system, imagedisplay
|
12
|
+
from .web import webtools
|
13
|
+
from .dev import pythondev, visualization
|
14
|
+
from .ui import userinterface
|
15
|
+
|
16
|
+
# Plugin registry
|
17
|
+
PLUGINS = {
|
18
|
+
"core.filemanager": filemanager,
|
19
|
+
"core.codeanalyzer": codeanalyzer,
|
20
|
+
"core.system": system,
|
21
|
+
"core.imagedisplay": imagedisplay,
|
22
|
+
"web.webtools": webtools,
|
23
|
+
"dev.pythondev": pythondev,
|
24
|
+
"dev.visualization": visualization,
|
25
|
+
"ui.userinterface": userinterface,
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
def list_plugins():
|
30
|
+
"""Return all available plugins"""
|
31
|
+
return list(PLUGINS.keys())
|
32
|
+
|
33
|
+
|
34
|
+
def get_plugin(name):
|
35
|
+
"""Get a specific plugin by name"""
|
36
|
+
return PLUGINS.get(name)
|
@@ -9,12 +9,12 @@ import os
|
|
9
9
|
from pathlib import Path
|
10
10
|
from typing import List
|
11
11
|
from janito.plugins.manager import PluginManager
|
12
|
-
from janito.
|
12
|
+
from janito.plugin_system.core_loader_fixed import load_core_plugin, get_core_plugins
|
13
13
|
|
14
14
|
# List of core plugins that should be enabled by default
|
15
15
|
CORE_PLUGINS = [
|
16
16
|
"core.filemanager",
|
17
|
-
"core.codeanalyzer",
|
17
|
+
"core.codeanalyzer",
|
18
18
|
"core.system",
|
19
19
|
"core.imagedisplay",
|
20
20
|
"dev.pythondev",
|
@@ -27,18 +27,18 @@ CORE_PLUGINS = [
|
|
27
27
|
def load_core_plugins(pm: PluginManager = None) -> List[str]:
|
28
28
|
"""
|
29
29
|
Load all core plugins.
|
30
|
-
|
30
|
+
|
31
31
|
Args:
|
32
32
|
pm: PluginManager instance. If None, creates a new one.
|
33
|
-
|
33
|
+
|
34
34
|
Returns:
|
35
35
|
List of successfully loaded plugin names
|
36
36
|
"""
|
37
37
|
if pm is None:
|
38
38
|
pm = PluginManager()
|
39
|
-
|
39
|
+
|
40
40
|
loaded = []
|
41
|
-
|
41
|
+
|
42
42
|
# Load core plugins
|
43
43
|
for plugin_name in CORE_PLUGINS:
|
44
44
|
try:
|
@@ -49,14 +49,14 @@ def load_core_plugins(pm: PluginManager = None) -> List[str]:
|
|
49
49
|
loaded.append(plugin_name)
|
50
50
|
except Exception as e:
|
51
51
|
print(f"Warning: Failed to load core plugin {plugin_name}: {e}")
|
52
|
-
|
52
|
+
|
53
53
|
return loaded
|
54
54
|
|
55
55
|
|
56
56
|
def get_loaded_core_plugins() -> List[str]:
|
57
57
|
"""
|
58
58
|
Get list of currently loaded core plugins.
|
59
|
-
|
59
|
+
|
60
60
|
Returns:
|
61
61
|
List of loaded core plugin names
|
62
62
|
"""
|
@@ -68,10 +68,10 @@ def get_loaded_core_plugins() -> List[str]:
|
|
68
68
|
def is_core_plugin(plugin_name: str) -> bool:
|
69
69
|
"""
|
70
70
|
Check if a plugin is a core plugin.
|
71
|
-
|
71
|
+
|
72
72
|
Args:
|
73
73
|
plugin_name: Name of the plugin to check
|
74
|
-
|
74
|
+
|
75
75
|
Returns:
|
76
76
|
True if it's a core plugin
|
77
77
|
"""
|
@@ -81,10 +81,11 @@ def is_core_plugin(plugin_name: str) -> bool:
|
|
81
81
|
# Auto-load core plugins when module is imported
|
82
82
|
_plugin_manager = None
|
83
83
|
|
84
|
+
|
84
85
|
def get_plugin_manager() -> PluginManager:
|
85
86
|
"""Get the global plugin manager with core plugins loaded."""
|
86
87
|
global _plugin_manager
|
87
88
|
if _plugin_manager is None:
|
88
89
|
_plugin_manager = PluginManager()
|
89
90
|
load_core_plugins(_plugin_manager)
|
90
|
-
return _plugin_manager
|
91
|
+
return _plugin_manager
|
janito/plugins/builtin.py
CHANGED
@@ -7,7 +7,7 @@ with janito and available by default without requiring external installation.
|
|
7
7
|
|
8
8
|
import importlib
|
9
9
|
from typing import Dict, List, Optional, Type
|
10
|
-
from janito.
|
10
|
+
from janito.plugin_system.base import Plugin
|
11
11
|
|
12
12
|
|
13
13
|
class BuiltinPluginRegistry:
|
@@ -83,6 +83,20 @@ try:
|
|
83
83
|
"documentation_generator", DocumentationGeneratorPlugin
|
84
84
|
)
|
85
85
|
|
86
|
+
# Register core tools plugin
|
87
|
+
from janito.plugins.tools import CoreToolsPlugin
|
88
|
+
|
89
|
+
BuiltinPluginRegistry.register("core_tools", CoreToolsPlugin)
|
90
|
+
|
86
91
|
except ImportError:
|
87
92
|
# janito-coder not available, skip registration
|
88
93
|
pass
|
94
|
+
|
95
|
+
# Register core tools plugin (always available)
|
96
|
+
try:
|
97
|
+
from janito.plugins.tools import CoreToolsPlugin
|
98
|
+
|
99
|
+
BuiltinPluginRegistry.register("core_tools", CoreToolsPlugin)
|
100
|
+
except ImportError:
|
101
|
+
# Should not happen, but handle gracefully
|
102
|
+
pass
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"""
|
2
|
+
Code Analyzer Plugin
|
3
|
+
|
4
|
+
Tools for understanding and searching code structure.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from typing import List, Optional
|
8
|
+
|
9
|
+
|
10
|
+
def get_file_outline(path: str) -> str:
|
11
|
+
"""Get file structure (classes, functions, etc.)"""
|
12
|
+
return f"get_file_outline(path='{path}')"
|
13
|
+
|
14
|
+
|
15
|
+
get_file_outline.tool_name = "get_file_outline"
|
16
|
+
|
17
|
+
|
18
|
+
def search_outline(path: str) -> str:
|
19
|
+
"""Search within file outlines"""
|
20
|
+
return f"search_outline(path='{path}')"
|
21
|
+
|
22
|
+
|
23
|
+
search_outline.tool_name = "search_outline"
|
24
|
+
|
25
|
+
|
26
|
+
def search_text(
|
27
|
+
paths: str,
|
28
|
+
query: str,
|
29
|
+
use_regex: bool = False,
|
30
|
+
case_sensitive: bool = True,
|
31
|
+
max_depth: Optional[int] = None,
|
32
|
+
) -> str:
|
33
|
+
"""Full-text search across files with regex support"""
|
34
|
+
return f"search_text(paths='{paths}', query='{query}', regex={use_regex})"
|
35
|
+
|
36
|
+
|
37
|
+
search_text.tool_name = "search_text"
|
38
|
+
|
39
|
+
|
40
|
+
# Plugin metadata
|
41
|
+
__plugin_name__ = "core.codeanalyzer"
|
42
|
+
__plugin_description__ = "Code analysis and structure understanding"
|
43
|
+
__plugin_tools__ = [get_file_outline, search_outline, search_text]
|
@@ -0,0 +1,124 @@
|
|
1
|
+
"""
|
2
|
+
File Manager Plugin
|
3
|
+
|
4
|
+
Core file and directory operations for managing project files.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from typing import List, Optional
|
8
|
+
import os
|
9
|
+
|
10
|
+
|
11
|
+
def create_file(path: str, content: str = "", overwrite: bool = False) -> str:
|
12
|
+
"""Create a new file with content"""
|
13
|
+
return f"create_file(path='{path}', content='{len(content)} chars', overwrite={overwrite})"
|
14
|
+
|
15
|
+
|
16
|
+
create_file.tool_name = "create_file"
|
17
|
+
|
18
|
+
|
19
|
+
def read_files(paths: List[str]) -> str:
|
20
|
+
"""Read multiple files at once"""
|
21
|
+
return f"read_files(paths={paths})"
|
22
|
+
|
23
|
+
|
24
|
+
read_files.tool_name = "read_files"
|
25
|
+
|
26
|
+
|
27
|
+
def view_file(
|
28
|
+
path: str, from_line: Optional[int] = None, to_line: Optional[int] = None
|
29
|
+
) -> str:
|
30
|
+
"""Read specific lines or entire files"""
|
31
|
+
range_str = f"{from_line}-{to_line}" if from_line or to_line else "all"
|
32
|
+
return f"view_file(path='{path}', range='{range_str}')"
|
33
|
+
|
34
|
+
|
35
|
+
view_file.tool_name = "view_file"
|
36
|
+
|
37
|
+
|
38
|
+
def replace_text_in_file(
|
39
|
+
path: str, search_text: str, replacement_text: str, replace_all: bool = True
|
40
|
+
) -> str:
|
41
|
+
"""Find and replace text in files"""
|
42
|
+
return f"replace_text_in_file(path='{path}', search='{search_text[:20]}...', replace='{replacement_text[:20]}...')"
|
43
|
+
|
44
|
+
|
45
|
+
replace_text_in_file.tool_name = "replace_text_in_file"
|
46
|
+
|
47
|
+
|
48
|
+
def validate_file_syntax(path: str) -> str:
|
49
|
+
"""Check file syntax (Python/Markdown)"""
|
50
|
+
return f"validate_file_syntax(path='{path}')"
|
51
|
+
|
52
|
+
|
53
|
+
validate_file_syntax.tool_name = "validate_file_syntax"
|
54
|
+
|
55
|
+
|
56
|
+
def create_directory(path: str) -> str:
|
57
|
+
"""Create new directories"""
|
58
|
+
return f"create_directory(path='{path}')"
|
59
|
+
|
60
|
+
|
61
|
+
create_directory.tool_name = "create_directory"
|
62
|
+
|
63
|
+
|
64
|
+
def remove_directory(path: str, recursive: bool = False) -> str:
|
65
|
+
"""Remove directories (recursive option)"""
|
66
|
+
return f"remove_directory(path='{path}', recursive={recursive})"
|
67
|
+
|
68
|
+
|
69
|
+
remove_directory.tool_name = "remove_directory"
|
70
|
+
|
71
|
+
|
72
|
+
def remove_file(path: str) -> str:
|
73
|
+
"""Delete single files"""
|
74
|
+
return f"remove_file(path='{path}')"
|
75
|
+
|
76
|
+
|
77
|
+
remove_file.tool_name = "remove_file"
|
78
|
+
|
79
|
+
|
80
|
+
def copy_file(sources: str, target: str, overwrite: bool = False) -> str:
|
81
|
+
"""Copy files or directories"""
|
82
|
+
return f"copy_file(sources='{sources}', target='{target}', overwrite={overwrite})"
|
83
|
+
|
84
|
+
|
85
|
+
copy_file.tool_name = "copy_file"
|
86
|
+
|
87
|
+
|
88
|
+
def move_file(src_path: str, dest_path: str, overwrite: bool = False) -> str:
|
89
|
+
"""Move/rename files or directories"""
|
90
|
+
return f"move_file(src='{src_path}', dest='{dest_path}', overwrite={overwrite})"
|
91
|
+
|
92
|
+
|
93
|
+
move_file.tool_name = "move_file"
|
94
|
+
|
95
|
+
|
96
|
+
def find_files(
|
97
|
+
paths: str,
|
98
|
+
pattern: str,
|
99
|
+
max_depth: Optional[int] = None,
|
100
|
+
include_gitignored: bool = False,
|
101
|
+
) -> str:
|
102
|
+
"""Search for files by pattern (respects .gitignore)"""
|
103
|
+
return f"find_files(paths='{paths}', pattern='{pattern}', max_depth={max_depth})"
|
104
|
+
|
105
|
+
|
106
|
+
find_files.tool_name = "find_files"
|
107
|
+
|
108
|
+
|
109
|
+
# Plugin metadata
|
110
|
+
__plugin_name__ = "core.filemanager"
|
111
|
+
__plugin_description__ = "Core file and directory operations"
|
112
|
+
__plugin_tools__ = [
|
113
|
+
create_file,
|
114
|
+
read_files,
|
115
|
+
view_file,
|
116
|
+
replace_text_in_file,
|
117
|
+
validate_file_syntax,
|
118
|
+
create_directory,
|
119
|
+
remove_directory,
|
120
|
+
remove_file,
|
121
|
+
copy_file,
|
122
|
+
move_file,
|
123
|
+
find_files,
|
124
|
+
]
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import os
|
2
|
+
from janito.tools.path_utils import expand_path
|
3
|
+
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
+
|
5
|
+
from janito.tools.tool_utils import display_path
|
6
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
|
+
from janito.report_events import ReportAction
|
8
|
+
from janito.i18n import tr
|
9
|
+
from janito.tools.loop_protection_decorator import protect_against_loops
|
10
|
+
|
11
|
+
from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
|
12
|
+
|
13
|
+
|
14
|
+
@register_local_tool
|
15
|
+
class CreateFileTool(ToolBase):
|
16
|
+
"""
|
17
|
+
Create a new file with the given content.
|
18
|
+
|
19
|
+
Args:
|
20
|
+
path (str): Path to the file to create.
|
21
|
+
content (str): Content to write to the file.
|
22
|
+
overwrite (bool, optional): Overwrite existing file if True. Default: False. Recommended only after reading the file to be overwritten.
|
23
|
+
Returns:
|
24
|
+
str: Status message indicating the result. Example:
|
25
|
+
- "✅ Successfully created the file at ..."
|
26
|
+
|
27
|
+
Note: Syntax validation is automatically performed after this operation.
|
28
|
+
|
29
|
+
Security: This tool includes loop protection to prevent excessive file creation operations.
|
30
|
+
Maximum 5 calls per 10 seconds for the same file path.
|
31
|
+
"""
|
32
|
+
|
33
|
+
permissions = ToolPermissions(write=True)
|
34
|
+
tool_name = "create_file"
|
35
|
+
|
36
|
+
@protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
|
37
|
+
def run(self, path: str, content: str, overwrite: bool = False) -> str:
|
38
|
+
path = expand_path(path)
|
39
|
+
disp_path = display_path(path)
|
40
|
+
if os.path.exists(path) and not overwrite:
|
41
|
+
try:
|
42
|
+
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
43
|
+
existing_content = f.read()
|
44
|
+
except Exception as e:
|
45
|
+
existing_content = f"[Error reading file: {e}]"
|
46
|
+
return tr(
|
47
|
+
"❗ Cannot create file: file already exists at '{disp_path}'.\n--- Current file content ---\n{existing_content}",
|
48
|
+
disp_path=disp_path,
|
49
|
+
existing_content=existing_content,
|
50
|
+
)
|
51
|
+
# Determine if we are overwriting an existing file
|
52
|
+
is_overwrite = os.path.exists(path) and overwrite
|
53
|
+
if is_overwrite:
|
54
|
+
# Overwrite branch: log only overwrite warning (no create message)
|
55
|
+
self.report_action(
|
56
|
+
tr("⚠️ Overwriting file '{disp_path}'", disp_path=disp_path),
|
57
|
+
ReportAction.CREATE,
|
58
|
+
)
|
59
|
+
dir_name = os.path.dirname(path)
|
60
|
+
if dir_name:
|
61
|
+
os.makedirs(dir_name, exist_ok=True)
|
62
|
+
if not is_overwrite:
|
63
|
+
# Create branch: log file creation message
|
64
|
+
self.report_action(
|
65
|
+
tr("📝 Create file '{disp_path}' ...", disp_path=disp_path),
|
66
|
+
ReportAction.CREATE,
|
67
|
+
)
|
68
|
+
with open(path, "w", encoding="utf-8", errors="replace") as f:
|
69
|
+
f.write(content)
|
70
|
+
new_lines = content.count("\n") + 1 if content else 0
|
71
|
+
self.report_success(
|
72
|
+
tr("✅ {new_lines} lines", new_lines=new_lines), ReportAction.CREATE
|
73
|
+
)
|
74
|
+
# Perform syntax validation and append result
|
75
|
+
validation_result = validate_file_syntax(path)
|
76
|
+
if is_overwrite:
|
77
|
+
# Overwrite branch: return minimal overwrite info to user
|
78
|
+
return (
|
79
|
+
tr("✅ {new_lines} lines", new_lines=new_lines)
|
80
|
+
+ f"\n{validation_result}"
|
81
|
+
)
|
82
|
+
else:
|
83
|
+
# Create branch: return detailed create success to user
|
84
|
+
return (
|
85
|
+
tr("✅ Created file {new_lines} lines.", new_lines=new_lines)
|
86
|
+
+ f"\n{validation_result}"
|
87
|
+
)
|