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.
Files changed (162) hide show
  1. janito/README.md +3 -0
  2. janito/cli/chat_mode/bindings.py +50 -0
  3. janito/cli/chat_mode/session.py +12 -1
  4. janito/cli/chat_mode/shell/commands/multi.py +5 -0
  5. janito/cli/chat_mode/shell/commands/security/allowed_sites.py +47 -33
  6. janito/cli/cli_commands/check_tools.py +212 -0
  7. janito/cli/cli_commands/list_plugins.py +52 -43
  8. janito/cli/core/getters.py +3 -0
  9. janito/cli/core/model_guesser.py +40 -24
  10. janito/cli/main_cli.py +9 -12
  11. janito/cli/prompt_core.py +47 -9
  12. janito/cli/rich_terminal_reporter.py +2 -2
  13. janito/drivers/openai/driver.py +1 -0
  14. janito/drivers/zai/driver.py +1 -0
  15. janito/i18n/it.py +46 -46
  16. janito/llm/agent.py +32 -16
  17. janito/llm/auth_utils.py +14 -5
  18. janito/llm/cancellation_manager.py +63 -0
  19. janito/llm/driver.py +8 -0
  20. janito/llm/enter_cancellation.py +107 -0
  21. janito/plugin_system/__init__.py +10 -0
  22. janito/{plugins → plugin_system}/base.py +5 -2
  23. janito/plugin_system/core_loader.py +217 -0
  24. janito/plugin_system/core_loader_fixed.py +225 -0
  25. janito/plugins/__init__.py +31 -12
  26. janito/plugins/auto_loader.py +12 -11
  27. janito/plugins/auto_loader_fixed.py +12 -11
  28. janito/plugins/builtin.py +15 -1
  29. janito/plugins/core/__init__.py +7 -0
  30. janito/plugins/core/codeanalyzer/__init__.py +43 -0
  31. janito/plugins/core/filemanager/__init__.py +124 -0
  32. janito/plugins/core/filemanager/tools/create_file.py +87 -0
  33. janito/plugins/core/filemanager/tools/replace_text_in_file.py +270 -0
  34. janito/plugins/core/imagedisplay/__init__.py +14 -0
  35. janito/plugins/core/imagedisplay/plugin.py +51 -0
  36. janito/plugins/core/imagedisplay/tools/__init__.py +1 -0
  37. janito/plugins/core/imagedisplay/tools/show_image.py +83 -0
  38. janito/{tools/adapters/local → plugins/core/imagedisplay/tools}/show_image_grid.py +13 -5
  39. janito/plugins/core/system/__init__.py +23 -0
  40. janito/plugins/core_adapter.py +89 -11
  41. janito/plugins/dev/__init__.py +7 -0
  42. janito/plugins/dev/pythondev/__init__.py +37 -0
  43. janito/plugins/dev/visualization/__init__.py +23 -0
  44. janito/plugins/discovery.py +5 -5
  45. janito/plugins/discovery_core.py +14 -9
  46. janito/plugins/example_plugin.py +108 -0
  47. janito/plugins/manager.py +1 -1
  48. janito/plugins/tools/__init__.py +10 -0
  49. janito/{tools/adapters/local → plugins/tools}/ask_user.py +3 -3
  50. janito/plugins/tools/copy_file.py +87 -0
  51. janito/plugins/tools/core_tools_plugin.py +87 -0
  52. janito/plugins/tools/create_directory.py +70 -0
  53. janito/{tools/adapters/local → plugins/tools}/create_file.py +6 -6
  54. janito/plugins/tools/decorators.py +19 -0
  55. janito/plugins/tools/delete_text_in_file.py +134 -0
  56. janito/{tools/adapters/local → plugins/tools}/fetch_url.py +3 -3
  57. janito/plugins/tools/find_files.py +143 -0
  58. janito/plugins/tools/get_file_outline/__init__.py +7 -0
  59. janito/plugins/tools/get_file_outline/core.py +122 -0
  60. janito/plugins/tools/get_file_outline/java_outline.py +47 -0
  61. janito/plugins/tools/get_file_outline/markdown_outline.py +14 -0
  62. janito/plugins/tools/get_file_outline/python_outline.py +303 -0
  63. janito/plugins/tools/get_file_outline/search_outline.py +36 -0
  64. janito/plugins/tools/move_file.py +131 -0
  65. janito/plugins/tools/open_html_in_browser.py +51 -0
  66. janito/plugins/tools/open_url.py +37 -0
  67. janito/plugins/tools/python_code_run.py +172 -0
  68. janito/plugins/tools/python_command_run.py +171 -0
  69. janito/plugins/tools/python_file_run.py +172 -0
  70. janito/plugins/tools/read_chart.py +259 -0
  71. janito/plugins/tools/read_files.py +58 -0
  72. janito/plugins/tools/remove_directory.py +55 -0
  73. janito/plugins/tools/remove_file.py +58 -0
  74. janito/{tools/adapters/local → plugins/tools}/replace_text_in_file.py +4 -4
  75. janito/plugins/tools/run_bash_command.py +183 -0
  76. janito/plugins/tools/run_powershell_command.py +218 -0
  77. janito/plugins/tools/search_text/__init__.py +7 -0
  78. janito/plugins/tools/search_text/core.py +205 -0
  79. janito/plugins/tools/search_text/match_lines.py +67 -0
  80. janito/plugins/tools/search_text/pattern_utils.py +73 -0
  81. janito/plugins/tools/search_text/traverse_directory.py +145 -0
  82. janito/{tools/adapters/local → plugins/tools}/show_image.py +15 -6
  83. janito/plugins/tools/show_image_grid.py +85 -0
  84. janito/plugins/tools/validate_file_syntax/__init__.py +7 -0
  85. janito/plugins/tools/validate_file_syntax/core.py +114 -0
  86. janito/plugins/tools/validate_file_syntax/css_validator.py +35 -0
  87. janito/plugins/tools/validate_file_syntax/html_validator.py +100 -0
  88. janito/plugins/tools/validate_file_syntax/jinja2_validator.py +50 -0
  89. janito/plugins/tools/validate_file_syntax/js_validator.py +27 -0
  90. janito/plugins/tools/validate_file_syntax/json_validator.py +6 -0
  91. janito/plugins/tools/validate_file_syntax/markdown_validator.py +109 -0
  92. janito/plugins/tools/validate_file_syntax/ps1_validator.py +32 -0
  93. janito/plugins/tools/validate_file_syntax/python_validator.py +5 -0
  94. janito/plugins/tools/validate_file_syntax/xml_validator.py +11 -0
  95. janito/plugins/tools/validate_file_syntax/yaml_validator.py +6 -0
  96. janito/plugins/tools/view_file.py +172 -0
  97. janito/plugins/ui/__init__.py +7 -0
  98. janito/plugins/ui/userinterface/__init__.py +16 -0
  99. janito/plugins/ui/userinterface/tools/ask_user.py +110 -0
  100. janito/plugins/web/__init__.py +7 -0
  101. janito/plugins/web/webtools/__init__.py +33 -0
  102. janito/plugins/web/webtools/tools/fetch_url.py +458 -0
  103. janito/providers/__init__.py +1 -0
  104. janito/providers/together/__init__.py +1 -0
  105. janito/providers/together/model_info.py +69 -0
  106. janito/providers/together/provider.py +108 -0
  107. janito/tools/__init__.py +31 -7
  108. janito/tools/adapters/__init__.py +6 -1
  109. janito/tools/adapters/local/__init__.py +7 -70
  110. janito/tools/cli_initializer.py +88 -0
  111. janito/tools/initialize.py +70 -0
  112. janito/tools/loop_protection_decorator.py +114 -117
  113. janito-3.5.0.dist-info/METADATA +229 -0
  114. {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/RECORD +158 -86
  115. janito/plugins/core_loader.py +0 -120
  116. janito/plugins/core_loader_fixed.py +0 -125
  117. janito/tools/function_adapter.py +0 -65
  118. janito-3.4.0.dist-info/METADATA +0 -84
  119. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/__init__.py +0 -0
  120. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/core.py +0 -0
  121. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/java_outline.py +0 -0
  122. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/markdown_outline.py +0 -0
  123. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/python_outline.py +0 -0
  124. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/search_outline.py +0 -0
  125. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/__init__.py +0 -0
  126. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/core.py +0 -0
  127. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/match_lines.py +0 -0
  128. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/pattern_utils.py +0 -0
  129. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/traverse_directory.py +0 -0
  130. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/copy_file.py +0 -0
  131. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/create_directory.py +0 -0
  132. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/delete_text_in_file.py +0 -0
  133. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/find_files.py +0 -0
  134. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/move_file.py +0 -0
  135. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/read_files.py +0 -0
  136. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_directory.py +0 -0
  137. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_file.py +0 -0
  138. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/__init__.py +0 -0
  139. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/core.py +0 -0
  140. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/css_validator.py +0 -0
  141. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/html_validator.py +0 -0
  142. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/jinja2_validator.py +0 -0
  143. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/js_validator.py +0 -0
  144. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/json_validator.py +0 -0
  145. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/markdown_validator.py +0 -0
  146. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/ps1_validator.py +0 -0
  147. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/python_validator.py +0 -0
  148. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/xml_validator.py +0 -0
  149. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/yaml_validator.py +0 -0
  150. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/view_file.py +0 -0
  151. /janito/{tools/adapters/local → plugins/core/system/tools}/run_bash_command.py +0 -0
  152. /janito/{tools/adapters/local → plugins/core/system/tools}/run_powershell_command.py +0 -0
  153. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_code_run.py +0 -0
  154. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_command_run.py +0 -0
  155. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_file_run.py +0 -0
  156. /janito/{tools/adapters/local → plugins/dev/visualization/tools}/read_chart.py +0 -0
  157. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_html_in_browser.py +0 -0
  158. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_url.py +0 -0
  159. {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/WHEEL +0 -0
  160. {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/entry_points.txt +0 -0
  161. {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/licenses/LICENSE +0 -0
  162. {janito-3.4.0.dist-info → janito-3.5.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,217 @@
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
9
+ import importlib.util
10
+ import sys
11
+ from pathlib import Path
12
+ from typing import Optional, List, Type
13
+
14
+ from janito.plugin_system.base import Plugin, PluginMetadata
15
+ from janito.tools.tool_base import ToolBase, ToolPermissions
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 _create_tool_class(self, func):
41
+ """Create a ToolBase class from a function."""
42
+ resolved_tool_name = getattr(func, "tool_name", func.__name__)
43
+
44
+ # Create a proper tool class with explicit parameters and documentation
45
+ import inspect
46
+ from typing import get_type_hints
47
+
48
+ func_sig = inspect.signature(func)
49
+ type_hints = get_type_hints(func)
50
+
51
+ # Build parameter definitions for the run method
52
+ param_defs = []
53
+ param_docs = []
54
+ for name, param in func_sig.parameters.items():
55
+ type_hint = type_hints.get(name, str)
56
+ if param.default == inspect.Parameter.empty:
57
+ param_defs.append(f"{name}: {type_hint.__name__}")
58
+ else:
59
+ param_defs.append(f"{name}: {type_hint.__name__} = {repr(param.default)}")
60
+
61
+ # Add parameter documentation
62
+ param_docs.append(f" {name}: {type_hint.__name__} - Parameter {name}")
63
+
64
+ # Get function docstring or create one
65
+ func_doc = func.__doc__ or f"Execute {resolved_tool_name} tool"
66
+
67
+ # Create the tool class with proper signature and documentation
68
+ exec_globals = {
69
+ 'ToolBase': ToolBase,
70
+ 'ToolPermissions': ToolPermissions,
71
+ 'func': func,
72
+ 'inspect': inspect,
73
+ 'str': str,
74
+ }
75
+
76
+ param_docs_str = '\n'.join(param_docs)
77
+
78
+ class_def = f'''
79
+ class DynamicTool(ToolBase):
80
+ """
81
+ {func_doc}
82
+
83
+ Parameters:
84
+ {param_docs_str}
85
+
86
+ Returns:
87
+ str: Execution result
88
+ """
89
+ tool_name = "{resolved_tool_name}"
90
+ permissions = ToolPermissions(read=True, write=True, execute=True)
91
+
92
+ def __init__(self):
93
+ super().__init__()
94
+
95
+ def run(self, {', '.join(param_defs)}) -> str:
96
+ kwargs = locals()
97
+ sig = inspect.signature(func)
98
+
99
+ # Filter kwargs to only include parameters the function accepts
100
+ filtered_kwargs = {{}}
101
+ for name, param in sig.parameters.items():
102
+ if name in kwargs and kwargs[name] is not None:
103
+ filtered_kwargs[name] = kwargs[name]
104
+
105
+ result = func(**filtered_kwargs)
106
+ return str(result) if result is not None else ""
107
+ '''
108
+
109
+ exec(class_def, exec_globals)
110
+ return exec_globals['DynamicTool']
111
+
112
+ return DynamicTool
113
+
114
+ def initialize(self):
115
+ """Initialize by creating tool classes."""
116
+ self._tool_classes = []
117
+ for tool_func in self._tools:
118
+ if callable(tool_func):
119
+ tool_class = self._create_tool_class(tool_func)
120
+ self._tool_classes.append(tool_class)
121
+
122
+
123
+ def load_core_plugin(plugin_name: str) -> Optional[Plugin]:
124
+ """
125
+ Load a core plugin by name.
126
+
127
+ Args:
128
+ plugin_name: Name of the plugin (e.g., 'core.filemanager')
129
+
130
+ Returns:
131
+ Plugin instance if loaded successfully
132
+ """
133
+ try:
134
+ # Parse plugin name
135
+ if "." not in plugin_name:
136
+ return None
137
+
138
+ parts = plugin_name.split(".")
139
+ if len(parts) != 2:
140
+ return None
141
+
142
+ package_name, submodule_name = parts
143
+
144
+ # Handle imagedisplay specially
145
+ if plugin_name == "core.imagedisplay":
146
+ # Import the actual plugin class
147
+ try:
148
+ # Use dynamic import to avoid circular dependency
149
+ plugin_module = importlib.import_module(
150
+ "janito.plugins.core.imagedisplay.plugin"
151
+ )
152
+ return plugin_module.ImageDisplayPlugin()
153
+ except ImportError as e:
154
+ print(f"Failed to load imagedisplay: {e}")
155
+ return None
156
+
157
+ # Build path to plugin
158
+ plugin_path = (
159
+ Path("janito/plugins") / package_name / submodule_name / "__init__.py"
160
+ )
161
+ if not plugin_path.exists():
162
+ return None
163
+
164
+ # Load the module
165
+ spec = importlib.util.spec_from_file_location(plugin_name, plugin_path)
166
+ if spec is None or spec.loader is None:
167
+ return None
168
+
169
+ module = importlib.util.module_from_spec(spec)
170
+ spec.loader.exec_module(module)
171
+
172
+ # Get plugin info
173
+ name = getattr(module, "__plugin_name__", plugin_name)
174
+ description = getattr(
175
+ module, "__plugin_description__", f"Core plugin: {plugin_name}"
176
+ )
177
+ tools = getattr(module, "__plugin_tools__", [])
178
+
179
+ if not tools:
180
+ return None
181
+
182
+ # Filter out None values and ensure all tools have tool_name
183
+ valid_tools = []
184
+ for tool in tools:
185
+ if tool is not None:
186
+ if not hasattr(tool, "tool_name"):
187
+ tool.tool_name = tool.__name__
188
+ valid_tools.append(tool)
189
+
190
+ if not valid_tools:
191
+ return None
192
+
193
+ # Create plugin
194
+ plugin = CorePlugin(name, description, valid_tools)
195
+ plugin.initialize()
196
+ return plugin
197
+
198
+ except Exception as e:
199
+ print(f"Error loading core plugin {plugin_name}: {e}")
200
+ return None
201
+
202
+
203
+ def get_core_plugins() -> list:
204
+ """Get list of all available core plugins."""
205
+ core_plugins = [
206
+ "core.filemanager",
207
+ "core.codeanalyzer",
208
+ "core.system",
209
+ "core.imagedisplay",
210
+ "dev.pythondev",
211
+ "dev.visualization",
212
+ "ui.userinterface",
213
+ "web.webtools",
214
+ ]
215
+
216
+ # All core plugins are always available
217
+ return core_plugins
@@ -0,0 +1,225 @@
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.tool_base import ToolBase, ToolPermissions
15
+
16
+
17
+ class CorePlugin(Plugin):
18
+ """Working core plugin implementation."""
19
+
20
+ def __init__(self, name: str, description: str, tools: list):
21
+ self._plugin_name = name
22
+ self._description = description
23
+ self._tools = tools
24
+ self._tool_classes = []
25
+ super().__init__() # Call super after setting attributes
26
+
27
+ def get_metadata(self) -> PluginMetadata:
28
+ return PluginMetadata(
29
+ name=self._plugin_name,
30
+ version="1.0.0",
31
+ description=self._description,
32
+ author="Janito",
33
+ license="MIT",
34
+ )
35
+
36
+ def get_tools(self) -> List[Type[ToolBase]]:
37
+ return self._tool_classes
38
+
39
+ def _create_tool_class(self, func):
40
+ """Create a ToolBase class from a function."""
41
+ resolved_tool_name = getattr(func, "tool_name", func.__name__)
42
+
43
+ # Create a proper tool class with explicit parameters and documentation
44
+ import inspect
45
+ from typing import get_type_hints
46
+
47
+ func_sig = inspect.signature(func)
48
+ type_hints = get_type_hints(func)
49
+
50
+ # Build parameter definitions for the run method
51
+ param_defs = []
52
+ param_docs = []
53
+ for name, param in func_sig.parameters.items():
54
+ type_hint = type_hints.get(name, str)
55
+ if param.default == inspect.Parameter.empty:
56
+ param_defs.append(f"{name}: {type_hint.__name__}")
57
+ else:
58
+ param_defs.append(f"{name}: {type_hint.__name__} = {repr(param.default)}")
59
+
60
+ # Add parameter documentation
61
+ param_docs.append(f" {name}: {type_hint.__name__} - Parameter {name}")
62
+
63
+ # Get function docstring or create one
64
+ func_doc = func.__doc__ or f"Execute {resolved_tool_name} tool"
65
+
66
+ # Create the tool class with proper signature and documentation
67
+ exec_globals = {
68
+ 'ToolBase': ToolBase,
69
+ 'ToolPermissions': ToolPermissions,
70
+ 'func': func,
71
+ 'inspect': inspect,
72
+ 'str': str,
73
+ 'List': list,
74
+ 'Dict': dict,
75
+ 'Optional': type(None),
76
+ }
77
+
78
+ param_docs_str = '\n'.join(param_docs)
79
+
80
+ class_def = f'''
81
+ class DynamicTool(ToolBase):
82
+ """
83
+ {func_doc}
84
+
85
+ Parameters:
86
+ {param_docs_str}
87
+
88
+ Returns:
89
+ str: Execution result
90
+ """
91
+ tool_name = "{resolved_tool_name}"
92
+ permissions = ToolPermissions(read=True, write=True, execute=True)
93
+
94
+ def __init__(self):
95
+ super().__init__()
96
+
97
+ def run(self, {', '.join(param_defs)}) -> str:
98
+ kwargs = locals()
99
+ sig = inspect.signature(func)
100
+
101
+ # Filter kwargs to only include parameters the function accepts
102
+ filtered_kwargs = {{}}
103
+ for name, param in sig.parameters.items():
104
+ if name in kwargs and kwargs[name] is not None:
105
+ filtered_kwargs[name] = kwargs[name]
106
+
107
+ result = func(**filtered_kwargs)
108
+ return str(result) if result is not None else ""
109
+ '''
110
+
111
+ exec(class_def, exec_globals)
112
+ return exec_globals['DynamicTool']
113
+
114
+ return DynamicTool
115
+
116
+ def initialize(self):
117
+ """Initialize by creating tool classes."""
118
+ self._tool_classes = []
119
+ for tool_func in self._tools:
120
+ if callable(tool_func):
121
+ tool_class = self._create_tool_class(tool_func)
122
+ self._tool_classes.append(tool_class)
123
+
124
+
125
+ def load_core_plugin(plugin_name: str) -> Optional[Plugin]:
126
+ """
127
+ Load a core plugin by name.
128
+
129
+ Args:
130
+ plugin_name: Name of the plugin (e.g., 'core.filemanager')
131
+
132
+ Returns:
133
+ Plugin instance if loaded successfully
134
+ """
135
+ try:
136
+ # Parse plugin name
137
+ if "." not in plugin_name:
138
+ return None
139
+
140
+ parts = plugin_name.split(".")
141
+ if len(parts) != 2:
142
+ return None
143
+
144
+ package_name, submodule_name = parts
145
+
146
+ # Handle imagedisplay specially
147
+ if plugin_name == "core.imagedisplay":
148
+ # Import the actual plugin class
149
+ try:
150
+ from janito.plugins.core.imagedisplay.plugin import ImageDisplayPlugin
151
+
152
+ return ImageDisplayPlugin()
153
+ except ImportError as e:
154
+ print(f"Failed to load imagedisplay: {e}")
155
+ return None
156
+
157
+ # Build path to plugin
158
+ plugin_path = (
159
+ Path("janito/plugins") / package_name / submodule_name / "__init__.py"
160
+ )
161
+ if not plugin_path.exists():
162
+ return None
163
+
164
+ # Load the module
165
+ spec = importlib.util.spec_from_file_location(plugin_name, plugin_path)
166
+ if spec is None or spec.loader is None:
167
+ return None
168
+
169
+ module = importlib.util.module_from_spec(spec)
170
+
171
+ # Add module to sys.modules to prevent circular imports
172
+ sys.modules[plugin_name] = module
173
+
174
+ try:
175
+ # Read and execute the module content
176
+ with open(plugin_path, "r", encoding="utf-8") as f:
177
+ code = f.read()
178
+
179
+ # Execute in module's namespace
180
+ exec(code, module.__dict__)
181
+
182
+ # Get plugin info
183
+ name = module.__dict__.get("__plugin_name__", plugin_name)
184
+ description = module.__dict__.get(
185
+ "__plugin_description__", f"Core plugin: {plugin_name}"
186
+ )
187
+ tools = module.__dict__.get("__plugin_tools__", [])
188
+
189
+ if not tools:
190
+ return None
191
+
192
+ # Ensure all tools have tool_name attribute
193
+ for tool in tools:
194
+ if tool is not None and not hasattr(tool, "tool_name"):
195
+ tool.tool_name = tool.__name__
196
+
197
+ # Create plugin
198
+ plugin = CorePlugin(name, description, tools)
199
+ plugin.initialize()
200
+ return plugin
201
+ finally:
202
+ # Clean up sys.modules
203
+ if plugin_name in sys.modules:
204
+ del sys.modules[plugin_name]
205
+
206
+ except Exception as e:
207
+ print(f"Error loading core plugin {plugin_name}: {e}")
208
+ return None
209
+
210
+
211
+ def get_core_plugins() -> list:
212
+ """Get list of all available core plugins."""
213
+ core_plugins = [
214
+ "core.filemanager",
215
+ "core.codeanalyzer",
216
+ "core.system",
217
+ "core.imagedisplay",
218
+ "dev.pythondev",
219
+ "dev.visualization",
220
+ "ui.userinterface",
221
+ "web.webtools",
222
+ ]
223
+
224
+ # All core plugins are always available
225
+ return core_plugins
@@ -1,17 +1,36 @@
1
1
  """
2
- Plugin system for janito.
2
+ Plugin System for Development Tools
3
3
 
4
- This package provides a flexible plugin system that allows extending
5
- janito's functionality with custom tools, commands, and features.
4
+ This package organizes all available tools into logical plugin groups
5
+ for easier discovery and usage.
6
6
  """
7
7
 
8
- from .manager import PluginManager
9
- from .base import Plugin, PluginMetadata
10
- from .discovery import discover_plugins
8
+ __version__ = "1.0.0"
9
+ __author__ = "Development Assistant"
11
10
 
12
- __all__ = [
13
- "PluginManager",
14
- "Plugin",
15
- "PluginMetadata",
16
- "discover_plugins",
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)
@@ -13,7 +13,7 @@ from janito.plugins.discovery import list_available_plugins
13
13
  # List of core plugins that should be enabled by default
14
14
  CORE_PLUGINS = [
15
15
  "core.filemanager",
16
- "core.codeanalyzer",
16
+ "core.codeanalyzer",
17
17
  "core.system",
18
18
  "core.imagedisplay",
19
19
  "dev.pythondev",
@@ -26,23 +26,23 @@ CORE_PLUGINS = [
26
26
  def load_core_plugins(pm: PluginManager = None) -> List[str]:
27
27
  """
28
28
  Load all core plugins.
29
-
29
+
30
30
  Args:
31
31
  pm: PluginManager instance. If None, creates a new one.
32
-
32
+
33
33
  Returns:
34
34
  List of successfully loaded plugin names
35
35
  """
36
36
  if pm is None:
37
37
  pm = PluginManager()
38
-
38
+
39
39
  # Ensure plugins directory is in search path
40
40
  plugins_dir = Path.cwd() / "plugins"
41
41
  if plugins_dir.exists():
42
42
  pm.add_plugin_path(str(plugins_dir))
43
-
43
+
44
44
  loaded = []
45
-
45
+
46
46
  # Load core plugins
47
47
  for plugin_name in CORE_PLUGINS:
48
48
  try:
@@ -50,14 +50,14 @@ def load_core_plugins(pm: PluginManager = None) -> List[str]:
50
50
  loaded.append(plugin_name)
51
51
  except Exception as e:
52
52
  print(f"Warning: Failed to load core plugin {plugin_name}: {e}")
53
-
53
+
54
54
  return loaded
55
55
 
56
56
 
57
57
  def get_loaded_core_plugins() -> List[str]:
58
58
  """
59
59
  Get list of currently loaded core plugins.
60
-
60
+
61
61
  Returns:
62
62
  List of loaded core plugin names
63
63
  """
@@ -69,10 +69,10 @@ def get_loaded_core_plugins() -> List[str]:
69
69
  def is_core_plugin(plugin_name: str) -> bool:
70
70
  """
71
71
  Check if a plugin is a core plugin.
72
-
72
+
73
73
  Args:
74
74
  plugin_name: Name of the plugin to check
75
-
75
+
76
76
  Returns:
77
77
  True if it's a core plugin
78
78
  """
@@ -82,10 +82,11 @@ def is_core_plugin(plugin_name: str) -> bool:
82
82
  # Auto-load core plugins when module is imported
83
83
  _plugin_manager = None
84
84
 
85
+
85
86
  def get_plugin_manager() -> PluginManager:
86
87
  """Get the global plugin manager with core plugins loaded."""
87
88
  global _plugin_manager
88
89
  if _plugin_manager is None:
89
90
  _plugin_manager = PluginManager()
90
91
  load_core_plugins(_plugin_manager)
91
- return _plugin_manager
92
+ return _plugin_manager
@@ -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.plugins.core_loader_fixed import load_core_plugin, get_core_plugins
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.plugins.base import Plugin
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,7 @@
1
+ """
2
+ Core Plugin Package
3
+
4
+ Contains essential system and file management plugins.
5
+ """
6
+
7
+ __all__ = ["filemanager", "codeanalyzer", "system"]