janito 2.33.0__py3-none-any.whl → 3.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. janito/cli/chat_mode/bindings.py +26 -0
  2. janito/cli/chat_mode/session.py +7 -1
  3. janito/cli/cli_commands/check_tools.py +212 -0
  4. janito/cli/cli_commands/list_plugins.py +52 -43
  5. janito/cli/core/getters.py +3 -0
  6. janito/cli/main_cli.py +9 -12
  7. janito/cli/prompt_core.py +19 -9
  8. janito/drivers/openai/driver.py +1 -0
  9. janito/drivers/zai/driver.py +1 -0
  10. janito/llm/agent.py +30 -17
  11. janito/llm/auth_utils.py +14 -5
  12. janito/llm/cancellation_manager.py +62 -0
  13. janito/llm/driver.py +7 -0
  14. janito/llm/enter_cancellation.py +93 -0
  15. janito/plugin_system/__init__.py +10 -0
  16. janito/{plugins → plugin_system}/base.py +5 -2
  17. janito/{plugins/core_loader_fixed.py → plugin_system/core_loader.py} +45 -26
  18. janito/plugin_system/core_loader_fixed.py +149 -0
  19. janito/plugins/__init__.py +31 -12
  20. janito/plugins/auto_loader_fixed.py +12 -11
  21. janito/plugins/builtin.py +15 -1
  22. janito/plugins/core/__init__.py +7 -0
  23. janito/plugins/core/codeanalyzer/__init__.py +43 -0
  24. janito/plugins/core/filemanager/__init__.py +124 -0
  25. janito/plugins/core/filemanager/tools/create_file.py +87 -0
  26. janito/plugins/core/filemanager/tools/replace_text_in_file.py +270 -0
  27. janito/plugins/core/imagedisplay/__init__.py +14 -0
  28. janito/plugins/core/imagedisplay/plugin.py +51 -0
  29. janito/plugins/core/imagedisplay/tools/__init__.py +1 -0
  30. janito/plugins/core/imagedisplay/tools/show_image.py +83 -0
  31. janito/{tools/adapters/local → plugins/core/imagedisplay/tools}/show_image_grid.py +13 -5
  32. janito/plugins/core/system/__init__.py +23 -0
  33. janito/plugins/core_adapter.py +11 -9
  34. janito/plugins/dev/__init__.py +7 -0
  35. janito/plugins/dev/pythondev/__init__.py +37 -0
  36. janito/plugins/dev/visualization/__init__.py +23 -0
  37. janito/plugins/discovery.py +5 -5
  38. janito/plugins/example_plugin.py +108 -0
  39. janito/plugins/manager.py +1 -1
  40. janito/plugins/tools/__init__.py +10 -0
  41. janito/{tools/adapters/local → plugins/tools}/ask_user.py +3 -3
  42. janito/plugins/tools/copy_file.py +87 -0
  43. janito/plugins/tools/core_tools_plugin.py +88 -0
  44. janito/plugins/tools/create_directory.py +70 -0
  45. janito/{tools/adapters/local → plugins/tools}/create_file.py +4 -4
  46. janito/plugins/tools/decorators.py +19 -0
  47. janito/plugins/tools/delete_text_in_file.py +134 -0
  48. janito/{tools/adapters/local → plugins/tools}/fetch_url.py +3 -3
  49. janito/plugins/tools/find_files.py +143 -0
  50. janito/plugins/tools/get_file_outline/__init__.py +7 -0
  51. janito/plugins/tools/get_file_outline/core.py +122 -0
  52. janito/plugins/tools/get_file_outline/java_outline.py +47 -0
  53. janito/plugins/tools/get_file_outline/markdown_outline.py +14 -0
  54. janito/plugins/tools/get_file_outline/python_outline.py +303 -0
  55. janito/plugins/tools/get_file_outline/search_outline.py +36 -0
  56. janito/plugins/tools/move_file.py +131 -0
  57. janito/plugins/tools/open_html_in_browser.py +51 -0
  58. janito/plugins/tools/open_url.py +37 -0
  59. janito/plugins/tools/python_code_run.py +172 -0
  60. janito/plugins/tools/python_command_run.py +171 -0
  61. janito/plugins/tools/python_file_run.py +172 -0
  62. janito/plugins/tools/read_chart.py +259 -0
  63. janito/plugins/tools/read_files.py +58 -0
  64. janito/plugins/tools/remove_directory.py +55 -0
  65. janito/plugins/tools/remove_file.py +58 -0
  66. janito/{tools/adapters/local → plugins/tools}/replace_text_in_file.py +4 -4
  67. janito/plugins/tools/run_bash_command.py +183 -0
  68. janito/plugins/tools/run_powershell_command.py +218 -0
  69. janito/plugins/tools/search_text/__init__.py +7 -0
  70. janito/plugins/tools/search_text/core.py +205 -0
  71. janito/plugins/tools/search_text/match_lines.py +67 -0
  72. janito/plugins/tools/search_text/pattern_utils.py +73 -0
  73. janito/plugins/tools/search_text/traverse_directory.py +145 -0
  74. janito/{tools/adapters/local → plugins/tools}/show_image.py +15 -6
  75. janito/plugins/tools/show_image_grid.py +85 -0
  76. janito/plugins/tools/validate_file_syntax/__init__.py +7 -0
  77. janito/plugins/tools/validate_file_syntax/core.py +114 -0
  78. janito/plugins/tools/validate_file_syntax/css_validator.py +35 -0
  79. janito/plugins/tools/validate_file_syntax/html_validator.py +100 -0
  80. janito/plugins/tools/validate_file_syntax/jinja2_validator.py +50 -0
  81. janito/plugins/tools/validate_file_syntax/js_validator.py +27 -0
  82. janito/plugins/tools/validate_file_syntax/json_validator.py +6 -0
  83. janito/plugins/tools/validate_file_syntax/markdown_validator.py +109 -0
  84. janito/plugins/tools/validate_file_syntax/ps1_validator.py +32 -0
  85. janito/plugins/tools/validate_file_syntax/python_validator.py +5 -0
  86. janito/plugins/tools/validate_file_syntax/xml_validator.py +11 -0
  87. janito/plugins/tools/validate_file_syntax/yaml_validator.py +6 -0
  88. janito/plugins/tools/view_file.py +172 -0
  89. janito/plugins/ui/__init__.py +7 -0
  90. janito/plugins/ui/userinterface/__init__.py +16 -0
  91. janito/plugins/ui/userinterface/tools/ask_user.py +110 -0
  92. janito/plugins/web/__init__.py +7 -0
  93. janito/plugins/web/webtools/__init__.py +33 -0
  94. janito/plugins/web/webtools/tools/fetch_url.py +458 -0
  95. janito/tools/__init__.py +31 -7
  96. janito/tools/adapters/__init__.py +6 -1
  97. janito/tools/adapters/local/__init__.py +7 -70
  98. janito/tools/cli_initializer.py +88 -0
  99. janito/tools/function_adapter.py +93 -16
  100. janito/tools/initialize.py +70 -0
  101. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/METADATA +1 -2
  102. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/RECORD +146 -76
  103. janito/plugins/core_loader.py +0 -120
  104. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/__init__.py +0 -0
  105. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/core.py +0 -0
  106. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/java_outline.py +0 -0
  107. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/markdown_outline.py +0 -0
  108. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/python_outline.py +0 -0
  109. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/search_outline.py +0 -0
  110. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/__init__.py +0 -0
  111. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/core.py +0 -0
  112. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/match_lines.py +0 -0
  113. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/pattern_utils.py +0 -0
  114. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/traverse_directory.py +0 -0
  115. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/copy_file.py +0 -0
  116. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/create_directory.py +0 -0
  117. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/delete_text_in_file.py +0 -0
  118. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/find_files.py +0 -0
  119. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/move_file.py +0 -0
  120. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/read_files.py +0 -0
  121. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_directory.py +0 -0
  122. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_file.py +0 -0
  123. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/__init__.py +0 -0
  124. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/core.py +0 -0
  125. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/css_validator.py +0 -0
  126. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/html_validator.py +0 -0
  127. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/jinja2_validator.py +0 -0
  128. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/js_validator.py +0 -0
  129. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/json_validator.py +0 -0
  130. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/markdown_validator.py +0 -0
  131. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/ps1_validator.py +0 -0
  132. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/python_validator.py +0 -0
  133. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/xml_validator.py +0 -0
  134. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/yaml_validator.py +0 -0
  135. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/view_file.py +0 -0
  136. /janito/{tools/adapters/local → plugins/core/system/tools}/run_bash_command.py +0 -0
  137. /janito/{tools/adapters/local → plugins/core/system/tools}/run_powershell_command.py +0 -0
  138. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_code_run.py +0 -0
  139. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_command_run.py +0 -0
  140. /janito/{tools/adapters/local → plugins/dev/pythondev/tools}/python_file_run.py +0 -0
  141. /janito/{tools/adapters/local → plugins/dev/visualization/tools}/read_chart.py +0 -0
  142. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_html_in_browser.py +0 -0
  143. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_url.py +0 -0
  144. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/WHEEL +0 -0
  145. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/entry_points.txt +0 -0
  146. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/licenses/LICENSE +0 -0
  147. {janito-2.33.0.dist-info → janito-3.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,62 @@
1
+ """
2
+ Global cancellation manager for LLM requests.
3
+ Provides a centralized way to cancel ongoing requests.
4
+ """
5
+
6
+ import threading
7
+ from typing import Optional
8
+
9
+
10
+ class CancellationManager:
11
+ """Manages cancellation of LLM requests across the application."""
12
+
13
+ def __init__(self):
14
+ self._current_cancel_event: Optional[threading.Event] = None
15
+ self._lock = threading.Lock()
16
+ self._keyboard_cancellation = None
17
+
18
+ def start_new_request(self) -> threading.Event:
19
+ """Start a new request and return its cancellation event."""
20
+ with self._lock:
21
+ # Create new cancellation event for this request
22
+ self._current_cancel_event = threading.Event()
23
+
24
+ # Start keyboard monitoring
25
+ from janito.llm.enter_cancellation import get_enter_cancellation
26
+ self._keyboard_cancellation = get_enter_cancellation()
27
+ self._keyboard_cancellation.start_monitoring(self._current_cancel_event)
28
+
29
+ return self._current_cancel_event
30
+
31
+ def cancel_current_request(self) -> bool:
32
+ """Cancel the current request if one is active."""
33
+ with self._lock:
34
+ if self._current_cancel_event is not None:
35
+ self._current_cancel_event.set()
36
+ return True
37
+ return False
38
+
39
+ def get_current_cancel_event(self) -> Optional[threading.Event]:
40
+ """Get the current cancellation event."""
41
+ with self._lock:
42
+ return self._current_cancel_event
43
+
44
+ def clear_current_request(self):
45
+ """Clear the current request cancellation event."""
46
+ with self._lock:
47
+ if self._keyboard_cancellation:
48
+ self._keyboard_cancellation.stop_monitoring()
49
+ self._keyboard_cancellation = None
50
+ self._current_cancel_event = None
51
+
52
+
53
+ # Global cancellation manager instance
54
+ _global_manager = None
55
+
56
+
57
+ def get_cancellation_manager() -> CancellationManager:
58
+ """Get the global cancellation manager instance."""
59
+ global _global_manager
60
+ if _global_manager is None:
61
+ _global_manager = CancellationManager()
62
+ return _global_manager
janito/llm/driver.py CHANGED
@@ -252,3 +252,10 @@ class LLMDriver(ABC):
252
252
  def _get_message_from_result(self, result):
253
253
  """Extract the message object from the provider result. Subclasses must implement this."""
254
254
  raise NotImplementedError("Subclasses must implement _get_message_from_result.")
255
+
256
+ def cancel_current_request(self):
257
+ """Cancel the current request being processed."""
258
+ # Use global cancellation manager to cancel the current request
259
+ from janito.llm.cancellation_manager import get_cancellation_manager
260
+ cancel_manager = get_cancellation_manager()
261
+ cancel_manager.cancel_current_request()
@@ -0,0 +1,93 @@
1
+ """
2
+ Enter key cancellation for LLM requests.
3
+ Allows pressing Enter to cancel ongoing requests.
4
+ """
5
+
6
+ import threading
7
+ import sys
8
+ import time
9
+ from typing import Optional
10
+
11
+
12
+ class EnterCancellation:
13
+ """Handles Enter key cancellation of LLM requests."""
14
+
15
+ def __init__(self):
16
+ self._cancel_event: Optional[threading.Event] = None
17
+ self._listener_thread: Optional[threading.Thread] = None
18
+ self._listening = False
19
+
20
+ def start_monitoring(self, cancel_event: threading.Event):
21
+ """Start monitoring for Enter key to cancel the request."""
22
+ if self._listening:
23
+ return
24
+
25
+ self._cancel_event = cancel_event
26
+ self._listening = True
27
+
28
+ self._listener_thread = threading.Thread(
29
+ target=self._monitor_enter_key, daemon=True
30
+ )
31
+ self._listener_thread.start()
32
+
33
+ def stop_monitoring(self):
34
+ """Stop monitoring for keyboard input."""
35
+ self._listening = False
36
+ if self._listener_thread and self._listener_thread.is_alive():
37
+ self._listener_thread.join(timeout=0.1)
38
+
39
+ def _monitor_enter_key(self):
40
+ """Monitor for Enter key press."""
41
+ try:
42
+ import sys
43
+ import select
44
+ import msvcrt # Windows-specific keyboard input
45
+
46
+ # Monitor for Enter key (Windows-specific implementation)
47
+ while self._listening and self._cancel_event and not self._cancel_event.is_set():
48
+ try:
49
+ # Windows-specific: check if key is available
50
+ if msvcrt.kbhit():
51
+ char = msvcrt.getch()
52
+ # Check for Enter key (carriage return or newline)
53
+ if char in [b'\r', b'\n']:
54
+ if self._cancel_event:
55
+ self._cancel_event.set()
56
+ break
57
+ else:
58
+ # Discard any other input
59
+ pass
60
+ else:
61
+ # Small delay to prevent high CPU usage
62
+ time.sleep(0.05)
63
+
64
+ except (IOError, OSError):
65
+ break
66
+ except Exception:
67
+ # Fallback to select-based approach for non-Windows
68
+ try:
69
+ if sys.stdin in select.select([sys.stdin], [], [], 0.05)[0]:
70
+ char = sys.stdin.read(1)
71
+ if char in ['\r', '\n']: # Enter key
72
+ if self._cancel_event:
73
+ self._cancel_event.set()
74
+ break
75
+ except:
76
+ pass
77
+ time.sleep(0.05)
78
+
79
+ except Exception:
80
+ # Silently handle any errors
81
+ pass
82
+
83
+
84
+ # Global instance
85
+ _global_enter_cancellation = None
86
+
87
+
88
+ def get_enter_cancellation() -> EnterCancellation:
89
+ """Get the global Enter cancellation instance."""
90
+ global _global_enter_cancellation
91
+ if _global_enter_cancellation is None:
92
+ _global_enter_cancellation = EnterCancellation()
93
+ return _global_enter_cancellation
@@ -0,0 +1,10 @@
1
+ """
2
+ Plugin System Core Package
3
+
4
+ This package provides the foundational plugin system architecture.
5
+ It should not depend on any specific plugin implementations.
6
+ """
7
+
8
+ from .base import Plugin, PluginMetadata, PluginResource
9
+
10
+ __all__ = ["Plugin", "PluginMetadata", "PluginResource"]
@@ -5,7 +5,10 @@ Base classes for janito plugins.
5
5
  from abc import ABC, abstractmethod
6
6
  from dataclasses import dataclass
7
7
  from typing import Dict, Any, List, Optional, Type, Union
8
- from janito.tools.tool_base import ToolBase
8
+ from typing import TYPE_CHECKING
9
+
10
+ if TYPE_CHECKING:
11
+ from janito.tools.tool_base import ToolBase
9
12
 
10
13
 
11
14
  @dataclass
@@ -50,7 +53,7 @@ class Plugin(ABC):
50
53
  """Return metadata describing this plugin."""
51
54
  pass
52
55
 
53
- def get_tools(self) -> List[Type[ToolBase]]:
56
+ def get_tools(self) -> List[Type["ToolBase"]]:
54
57
  """
55
58
  Return a list of tool classes provided by this plugin.
56
59
 
@@ -5,26 +5,27 @@ This module provides a working implementation to load core plugins
5
5
  by directly using the Plugin base class properly.
6
6
  """
7
7
 
8
+ import importlib
8
9
  import importlib.util
9
10
  import sys
10
11
  from pathlib import Path
11
12
  from typing import Optional, List, Type
12
13
 
13
- from janito.plugins.base import Plugin, PluginMetadata
14
+ from janito.plugin_system.base import Plugin, PluginMetadata
14
15
  from janito.tools.function_adapter import create_function_tool
15
16
  from janito.tools.tool_base import ToolBase
16
17
 
17
18
 
18
19
  class CorePlugin(Plugin):
19
20
  """Working core plugin implementation."""
20
-
21
+
21
22
  def __init__(self, name: str, description: str, tools: list):
22
23
  self._plugin_name = name
23
24
  self._description = description
24
25
  self._tools = tools
25
26
  self._tool_classes = []
26
27
  super().__init__() # Call super after setting attributes
27
-
28
+
28
29
  def get_metadata(self) -> PluginMetadata:
29
30
  return PluginMetadata(
30
31
  name=self._plugin_name,
@@ -33,10 +34,10 @@ class CorePlugin(Plugin):
33
34
  author="Janito",
34
35
  license="MIT",
35
36
  )
36
-
37
+
37
38
  def get_tools(self) -> List[Type[ToolBase]]:
38
39
  return self._tool_classes
39
-
40
+
40
41
  def initialize(self):
41
42
  """Initialize by creating tool classes."""
42
43
  self._tool_classes = []
@@ -49,10 +50,10 @@ class CorePlugin(Plugin):
49
50
  def load_core_plugin(plugin_name: str) -> Optional[Plugin]:
50
51
  """
51
52
  Load a core plugin by name.
52
-
53
+
53
54
  Args:
54
55
  plugin_name: Name of the plugin (e.g., 'core.filemanager')
55
-
56
+
56
57
  Returns:
57
58
  Plugin instance if loaded successfully
58
59
  """
@@ -60,49 +61,67 @@ def load_core_plugin(plugin_name: str) -> Optional[Plugin]:
60
61
  # Parse plugin name
61
62
  if "." not in plugin_name:
62
63
  return None
63
-
64
+
64
65
  parts = plugin_name.split(".")
65
66
  if len(parts) != 2:
66
67
  return None
67
-
68
+
68
69
  package_name, submodule_name = parts
69
-
70
+
70
71
  # Handle imagedisplay specially
71
72
  if plugin_name == "core.imagedisplay":
72
73
  # Import the actual plugin class
73
74
  try:
74
- from plugins.core.imagedisplay.plugin import ImageDisplayPlugin
75
- return ImageDisplayPlugin()
76
- except ImportError:
77
- # If import fails, return None - don't return True
75
+ # Use dynamic import to avoid circular dependency
76
+ plugin_module = importlib.import_module(
77
+ "janito.plugins.core.imagedisplay.plugin"
78
+ )
79
+ return plugin_module.ImageDisplayPlugin()
80
+ except ImportError as e:
81
+ print(f"Failed to load imagedisplay: {e}")
78
82
  return None
79
-
83
+
80
84
  # Build path to plugin
81
- plugin_path = Path("plugins") / package_name / submodule_name / "__init__.py"
85
+ plugin_path = (
86
+ Path("janito/plugins") / package_name / submodule_name / "__init__.py"
87
+ )
82
88
  if not plugin_path.exists():
83
89
  return None
84
-
90
+
85
91
  # Load the module
86
92
  spec = importlib.util.spec_from_file_location(plugin_name, plugin_path)
87
93
  if spec is None or spec.loader is None:
88
94
  return None
89
-
95
+
90
96
  module = importlib.util.module_from_spec(spec)
91
97
  spec.loader.exec_module(module)
92
-
98
+
93
99
  # Get plugin info
94
100
  name = getattr(module, "__plugin_name__", plugin_name)
95
- description = getattr(module, "__plugin_description__", f"Core plugin: {plugin_name}")
101
+ description = getattr(
102
+ module, "__plugin_description__", f"Core plugin: {plugin_name}"
103
+ )
96
104
  tools = getattr(module, "__plugin_tools__", [])
97
-
105
+
98
106
  if not tools:
99
107
  return None
100
-
108
+
109
+ # Filter out None values and ensure all tools have tool_name
110
+ valid_tools = []
111
+ for tool in tools:
112
+ if tool is not None:
113
+ if not hasattr(tool, "tool_name"):
114
+ tool.tool_name = tool.__name__
115
+ valid_tools.append(tool)
116
+
117
+ if not valid_tools:
118
+ return None
119
+
101
120
  # Create plugin
102
- plugin = CorePlugin(name, description, tools)
121
+ plugin = CorePlugin(name, description, valid_tools)
103
122
  plugin.initialize()
104
123
  return plugin
105
-
124
+
106
125
  except Exception as e:
107
126
  print(f"Error loading core plugin {plugin_name}: {e}")
108
127
  return None
@@ -120,6 +139,6 @@ def get_core_plugins() -> list:
120
139
  "ui.userinterface",
121
140
  "web.webtools",
122
141
  ]
123
-
142
+
124
143
  # All core plugins are always available
125
- return core_plugins
144
+ return core_plugins
@@ -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
@@ -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)
@@ -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"]