janito 3.4.0__py3-none-any.whl → 3.5.1__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 (159) 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/system/tools/run_bash_command.py +204 -0
  41. janito/plugins/core/system/tools/run_powershell_command.py +234 -0
  42. janito/plugins/core_adapter.py +89 -11
  43. janito/plugins/dev/__init__.py +7 -0
  44. janito/plugins/dev/pythondev/__init__.py +37 -0
  45. janito/plugins/dev/visualization/__init__.py +23 -0
  46. janito/plugins/discovery.py +5 -5
  47. janito/plugins/discovery_core.py +14 -9
  48. janito/plugins/example_plugin.py +108 -0
  49. janito/plugins/manager.py +1 -1
  50. janito/plugins/tools/__init__.py +10 -0
  51. janito/{tools/adapters/local → plugins/tools}/ask_user.py +3 -3
  52. janito/plugins/tools/copy_file.py +87 -0
  53. janito/plugins/tools/core_tools_plugin.py +87 -0
  54. janito/plugins/tools/create_directory.py +70 -0
  55. janito/{tools/adapters/local → plugins/tools}/create_file.py +6 -6
  56. janito/plugins/tools/decorators.py +19 -0
  57. janito/plugins/tools/delete_text_in_file.py +134 -0
  58. janito/{tools/adapters/local → plugins/tools}/fetch_url.py +3 -3
  59. janito/plugins/tools/find_files.py +143 -0
  60. janito/plugins/tools/get_file_outline/__init__.py +7 -0
  61. janito/plugins/tools/get_file_outline/core.py +122 -0
  62. janito/plugins/tools/get_file_outline/java_outline.py +47 -0
  63. janito/plugins/tools/get_file_outline/markdown_outline.py +14 -0
  64. janito/plugins/tools/get_file_outline/python_outline.py +303 -0
  65. janito/plugins/tools/get_file_outline/search_outline.py +36 -0
  66. janito/plugins/tools/move_file.py +131 -0
  67. janito/plugins/tools/open_html_in_browser.py +51 -0
  68. janito/plugins/tools/open_url.py +37 -0
  69. janito/{tools/adapters/local → plugins/tools}/python_code_run.py +23 -7
  70. janito/{tools/adapters/local → plugins/tools}/python_command_run.py +21 -5
  71. janito/{tools/adapters/local → plugins/tools}/python_file_run.py +21 -5
  72. janito/plugins/tools/read_chart.py +259 -0
  73. janito/plugins/tools/read_files.py +58 -0
  74. janito/plugins/tools/remove_directory.py +55 -0
  75. janito/plugins/tools/remove_file.py +58 -0
  76. janito/{tools/adapters/local → plugins/tools}/replace_text_in_file.py +4 -4
  77. janito/{tools/adapters/local → plugins/tools}/run_bash_command.py +3 -3
  78. janito/{tools/adapters/local → plugins/tools}/run_powershell_command.py +3 -3
  79. janito/plugins/tools/search_text/__init__.py +7 -0
  80. janito/plugins/tools/search_text/core.py +205 -0
  81. janito/plugins/tools/search_text/match_lines.py +67 -0
  82. janito/plugins/tools/search_text/pattern_utils.py +73 -0
  83. janito/plugins/tools/search_text/traverse_directory.py +145 -0
  84. janito/{tools/adapters/local → plugins/tools}/show_image.py +15 -6
  85. janito/plugins/tools/show_image_grid.py +85 -0
  86. janito/plugins/tools/validate_file_syntax/__init__.py +7 -0
  87. janito/plugins/tools/validate_file_syntax/core.py +114 -0
  88. janito/plugins/tools/validate_file_syntax/css_validator.py +35 -0
  89. janito/plugins/tools/validate_file_syntax/html_validator.py +100 -0
  90. janito/plugins/tools/validate_file_syntax/jinja2_validator.py +50 -0
  91. janito/plugins/tools/validate_file_syntax/js_validator.py +27 -0
  92. janito/plugins/tools/validate_file_syntax/json_validator.py +6 -0
  93. janito/plugins/tools/validate_file_syntax/markdown_validator.py +109 -0
  94. janito/plugins/tools/validate_file_syntax/ps1_validator.py +32 -0
  95. janito/plugins/tools/validate_file_syntax/python_validator.py +5 -0
  96. janito/plugins/tools/validate_file_syntax/xml_validator.py +11 -0
  97. janito/plugins/tools/validate_file_syntax/yaml_validator.py +6 -0
  98. janito/plugins/tools/view_file.py +172 -0
  99. janito/plugins/ui/__init__.py +7 -0
  100. janito/plugins/ui/userinterface/__init__.py +16 -0
  101. janito/plugins/ui/userinterface/tools/ask_user.py +110 -0
  102. janito/plugins/web/__init__.py +7 -0
  103. janito/plugins/web/webtools/__init__.py +33 -0
  104. janito/plugins/web/webtools/tools/fetch_url.py +458 -0
  105. janito/providers/__init__.py +1 -0
  106. janito/providers/together/__init__.py +1 -0
  107. janito/providers/together/model_info.py +69 -0
  108. janito/providers/together/provider.py +108 -0
  109. janito/tools/__init__.py +31 -7
  110. janito/tools/adapters/__init__.py +6 -1
  111. janito/tools/adapters/local/__init__.py +7 -70
  112. janito/tools/cli_initializer.py +88 -0
  113. janito/tools/initialize.py +70 -0
  114. janito/tools/loop_protection_decorator.py +114 -117
  115. janito-3.5.1.dist-info/METADATA +229 -0
  116. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/RECORD +155 -86
  117. janito/plugins/core_loader.py +0 -120
  118. janito/plugins/core_loader_fixed.py +0 -125
  119. janito/tools/function_adapter.py +0 -65
  120. janito-3.4.0.dist-info/METADATA +0 -84
  121. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/__init__.py +0 -0
  122. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/core.py +0 -0
  123. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/java_outline.py +0 -0
  124. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/markdown_outline.py +0 -0
  125. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/python_outline.py +0 -0
  126. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/get_file_outline/search_outline.py +0 -0
  127. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/__init__.py +0 -0
  128. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/core.py +0 -0
  129. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/match_lines.py +0 -0
  130. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/pattern_utils.py +0 -0
  131. /janito/{tools/adapters/local → plugins/core/codeanalyzer/tools}/search_text/traverse_directory.py +0 -0
  132. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/copy_file.py +0 -0
  133. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/create_directory.py +0 -0
  134. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/delete_text_in_file.py +0 -0
  135. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/find_files.py +0 -0
  136. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/move_file.py +0 -0
  137. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/read_files.py +0 -0
  138. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_directory.py +0 -0
  139. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/remove_file.py +0 -0
  140. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/__init__.py +0 -0
  141. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/core.py +0 -0
  142. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/css_validator.py +0 -0
  143. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/html_validator.py +0 -0
  144. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/jinja2_validator.py +0 -0
  145. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/js_validator.py +0 -0
  146. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/json_validator.py +0 -0
  147. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/markdown_validator.py +0 -0
  148. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/ps1_validator.py +0 -0
  149. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/python_validator.py +0 -0
  150. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/xml_validator.py +0 -0
  151. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/validate_file_syntax/yaml_validator.py +0 -0
  152. /janito/{tools/adapters/local → plugins/core/filemanager/tools}/view_file.py +0 -0
  153. /janito/{tools/adapters/local → plugins/dev/visualization/tools}/read_chart.py +0 -0
  154. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_html_in_browser.py +0 -0
  155. /janito/{tools/adapters/local → plugins/web/webtools/tools}/open_url.py +0 -0
  156. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/WHEEL +0 -0
  157. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/entry_points.txt +0 -0
  158. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/licenses/LICENSE +0 -0
  159. {janito-3.4.0.dist-info → janito-3.5.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,69 @@
1
+ """
2
+ Model specifications for Together AI provider.
3
+ """
4
+
5
+ MODEL_SPECS = {
6
+ "allenai/OLMo-2-0325-32B-Instruct": {
7
+ "max_tokens": 32768,
8
+ "max_input_tokens": 32768,
9
+ "max_output_tokens": 32768,
10
+ "description": "OLMo 2 32B Instruct - Fully open language model from AllenAI",
11
+ "supports_tools": True,
12
+ "supports_system_prompt": True,
13
+ "supports_streaming": True,
14
+ },
15
+ "allenai/OLMo-2-1124-7B-Instruct": {
16
+ "max_tokens": 32768,
17
+ "max_input_tokens": 32768,
18
+ "max_output_tokens": 32768,
19
+ "description": "OLMo 2 7B Instruct - Fully open language model from AllenAI",
20
+ "supports_tools": True,
21
+ "supports_system_prompt": True,
22
+ "supports_streaming": True,
23
+ },
24
+ "allenai/OLMo-2-0425-1B": {
25
+ "max_tokens": 32768,
26
+ "max_input_tokens": 32768,
27
+ "max_output_tokens": 32768,
28
+ "description": "OLMo 2 1B - Fully open language model from AllenAI",
29
+ "supports_tools": True,
30
+ "supports_system_prompt": True,
31
+ "supports_streaming": True,
32
+ },
33
+ "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": {
34
+ "max_tokens": 8192,
35
+ "max_input_tokens": 128000,
36
+ "max_output_tokens": 8192,
37
+ "description": "Llama 3.1 8B Instruct Turbo",
38
+ "supports_tools": True,
39
+ "supports_system_prompt": True,
40
+ "supports_streaming": True,
41
+ },
42
+ "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": {
43
+ "max_tokens": 8192,
44
+ "max_input_tokens": 128000,
45
+ "max_output_tokens": 8192,
46
+ "description": "Llama 3.1 70B Instruct Turbo",
47
+ "supports_tools": True,
48
+ "supports_system_prompt": True,
49
+ "supports_streaming": True,
50
+ },
51
+ "mistralai/Mixtral-8x7B-Instruct-v0.1": {
52
+ "max_tokens": 32768,
53
+ "max_input_tokens": 32768,
54
+ "max_output_tokens": 32768,
55
+ "description": "Mixtral 8x7B Instruct",
56
+ "supports_tools": True,
57
+ "supports_system_prompt": True,
58
+ "supports_streaming": True,
59
+ },
60
+ "deepseek-ai/deepseek-llm-67b-chat": {
61
+ "max_tokens": 4096,
62
+ "max_input_tokens": 4096,
63
+ "max_output_tokens": 4096,
64
+ "description": "DeepSeek LLM 67B Chat",
65
+ "supports_tools": True,
66
+ "supports_system_prompt": True,
67
+ "supports_streaming": True,
68
+ },
69
+ }
@@ -0,0 +1,108 @@
1
+ from janito.llm.provider import LLMProvider
2
+ from janito.llm.model import LLMModelInfo
3
+ from janito.llm.auth import LLMAuthManager
4
+ from janito.llm.driver_config import LLMDriverConfig
5
+ from janito.drivers.openai.driver import OpenAIModelDriver
6
+ from janito.tools import get_local_tools_adapter
7
+ from janito.providers.registry import LLMProviderRegistry
8
+ from .model_info import MODEL_SPECS
9
+ from queue import Queue
10
+
11
+ available = OpenAIModelDriver.available
12
+ unavailable_reason = OpenAIModelDriver.unavailable_reason
13
+
14
+
15
+ class TogetherProvider(LLMProvider):
16
+ name = 'together'
17
+ NAME = 'together'
18
+ MAINTAINER = 'Janito Team'
19
+ MODEL_SPECS = MODEL_SPECS
20
+ DEFAULT_MODEL = 'allenai/OLMo-2-0325-32B-Instruct'
21
+
22
+ def __init__(
23
+ self, auth_manager: LLMAuthManager = None, config: LLMDriverConfig = None
24
+ ):
25
+ self._tools_adapter = get_local_tools_adapter()
26
+ self._driver = None
27
+
28
+ if not self.available:
29
+ return
30
+
31
+ self._initialize_config(auth_manager, config)
32
+ self._setup_model_config()
33
+
34
+ def _initialize_config(self, auth_manager, config):
35
+ self.auth_manager = auth_manager or LLMAuthManager()
36
+ self._api_key = self.auth_manager.get_credentials(type(self).NAME)
37
+ if not self._api_key:
38
+ from janito.llm.auth_utils import handle_missing_api_key
39
+ handle_missing_api_key(self.name, 'TOGETHER_API_KEY')
40
+
41
+ self._driver_config = config or LLMDriverConfig(model=None)
42
+ if not self._driver_config.model:
43
+ self._driver_config.model = self.DEFAULT_MODEL
44
+ if not self._driver_config.api_key:
45
+ self._driver_config.api_key = self._api_key
46
+
47
+ self._driver_config.base_url = 'https://api.together.xyz/v1'
48
+
49
+ def _setup_model_config(self):
50
+ model_name = self._driver_config.model
51
+ model_spec = self.MODEL_SPECS.get(model_name)
52
+
53
+ if hasattr(self._driver_config, 'max_tokens'):
54
+ self._driver_config.max_tokens = None
55
+ if hasattr(self._driver_config, 'max_completion_tokens'):
56
+ self._driver_config.max_completion_tokens = None
57
+
58
+ if model_spec:
59
+ max_tokens = getattr(model_spec, 'max_tokens', None)
60
+ if max_tokens and max_tokens != 'N/A':
61
+ self._driver_config.max_tokens = int(max_tokens)
62
+
63
+ self.fill_missing_device_info(self._driver_config)
64
+
65
+ @property
66
+ def driver(self) -> OpenAIModelDriver:
67
+ if not self.available:
68
+ raise ImportError(f'TogetherProvider unavailable: {self.unavailable_reason}')
69
+ return self._driver
70
+
71
+ @property
72
+ def available(self):
73
+ return available
74
+
75
+ @property
76
+ def unavailable_reason(self):
77
+ return unavailable_reason
78
+
79
+ def create_driver(self):
80
+ driver = OpenAIModelDriver(
81
+ tools_adapter=self._tools_adapter, provider_name=self.NAME
82
+ )
83
+ driver.config = self._driver_config
84
+ return driver
85
+
86
+ def create_agent(self, tools_adapter=None, agent_name: str = None, **kwargs):
87
+ from janito.llm.agent import LLMAgent
88
+ if tools_adapter is None:
89
+ tools_adapter = get_local_tools_adapter()
90
+ raise NotImplementedError(
91
+ 'create_agent must be constructed via new factory using input/output queues and config.'
92
+ )
93
+
94
+ @property
95
+ def model_name(self):
96
+ return self._driver_config.model
97
+
98
+ @property
99
+ def driver_config(self):
100
+ return self._driver_config
101
+
102
+ def execute_tool(self, tool_name: str, event_bus, *args, **kwargs):
103
+ self._tools_adapter.event_bus = event_bus
104
+ return self._tools_adapter.execute_by_name(tool_name, *args, **kwargs)
105
+
106
+
107
+ LLMProviderRegistry.register(TogetherProvider.NAME, TogetherProvider)
108
+
janito/tools/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
- from janito.tools.adapters.local import (
2
- local_tools_adapter as _internal_local_tools_adapter,
3
- LocalToolsAdapter,
1
+ from janito.tools.adapters.local import LocalToolsAdapter
2
+ from janito.tools.adapters.local.adapter import (
3
+ LocalToolsAdapter as _internal_local_tools_adapter,
4
4
  )
5
5
 
6
6
 
@@ -11,8 +11,10 @@ def get_local_tools_adapter(workdir=None, allowed_permissions=None):
11
11
  if workdir is not None and not os.path.exists(workdir):
12
12
  os.makedirs(workdir, exist_ok=True)
13
13
  # Permissions are now managed globally; ignore allowed_permissions argument except for backward compatibility
14
- # Reuse the singleton adapter defined in janito.tools.adapters.local to maintain tool registrations
15
- registry = _internal_local_tools_adapter
14
+ # Create and initialize adapter
15
+ from janito.tools.initialize import initialize_tools
16
+
17
+ registry = initialize_tools(LocalToolsAdapter(workdir=workdir))
16
18
  # Change workdir if requested
17
19
  if workdir is not None:
18
20
  try:
@@ -27,10 +29,32 @@ def get_local_tools_adapter(workdir=None, allowed_permissions=None):
27
29
  return registry
28
30
 
29
31
 
30
- local_tools_adapter = _internal_local_tools_adapter
32
+ # Initialize the global adapter - defer import to avoid circular dependencies
33
+ local_tools_adapter = None
34
+
35
+
36
+ def get_local_tools_adapter(workdir=None, allowed_permissions=None):
37
+ """Get the global tools adapter, initializing on first use."""
38
+ global local_tools_adapter
39
+ if local_tools_adapter is None:
40
+ from janito.tools.initialize import initialize_tools
41
+
42
+ adapter = LocalToolsAdapter(workdir=workdir)
43
+ local_tools_adapter = initialize_tools(adapter)
44
+
45
+ # Handle workdir if provided
46
+ if workdir is not None and local_tools_adapter is not None:
47
+ import os
48
+
49
+ if not os.path.exists(workdir):
50
+ os.makedirs(workdir, exist_ok=True)
51
+ os.chdir(workdir)
52
+ local_tools_adapter.workdir = workdir
53
+
54
+ return local_tools_adapter
55
+
31
56
 
32
57
  __all__ = [
33
58
  "LocalToolsAdapter",
34
59
  "get_local_tools_adapter",
35
- "local_tools_adapter",
36
60
  ]
@@ -1 +1,6 @@
1
- # Tools providers package: for plug-and-play tool collections, integrations, and adapters.
1
+ """
2
+ Tools providers package: for plug-and-play tool collections, integrations, and adapters.
3
+
4
+ This package contains the core adapter infrastructure for managing tools,
5
+ while the actual tool implementations have been moved to the plugins system.
6
+ """
@@ -1,73 +1,10 @@
1
- from .adapter import LocalToolsAdapter
2
-
3
- from .ask_user import AskUserTool
4
- from .copy_file import CopyFileTool
5
- from .create_directory import CreateDirectoryTool
6
- from .create_file import CreateFileTool
7
- from .fetch_url import FetchUrlTool
8
- from .find_files import FindFilesTool
9
- from .view_file import ViewFileTool
10
- from .read_files import ReadFilesTool
11
- from .move_file import MoveFileTool
12
- from .open_url import OpenUrlTool
13
- from .open_html_in_browser import OpenHtmlInBrowserTool
14
- from .python_code_run import PythonCodeRunTool
15
- from .python_command_run import PythonCommandRunTool
16
- from .python_file_run import PythonFileRunTool
17
- from .remove_directory import RemoveDirectoryTool
18
- from .remove_file import RemoveFileTool
19
- from .replace_text_in_file import ReplaceTextInFileTool
20
- from .run_bash_command import RunBashCommandTool
21
- from .run_powershell_command import RunPowershellCommandTool
22
- from .get_file_outline.core import GetFileOutlineTool
23
- from .get_file_outline.search_outline import SearchOutlineTool
24
- from .search_text.core import SearchTextTool
25
- from .validate_file_syntax.core import ValidateFileSyntaxTool
26
- from .read_chart import ReadChartTool
27
- from .show_image import ShowImageTool
28
- from .show_image_grid import ShowImageGridTool
29
-
30
- from janito.tools.tool_base import ToolPermissions
31
- import os
32
- from janito.tools.permissions import get_global_allowed_permissions
33
-
34
- # Singleton tools adapter with all standard tools registered
35
- local_tools_adapter = LocalToolsAdapter(workdir=os.getcwd())
1
+ """
2
+ Local tools adapter for janito.
36
3
 
4
+ This package provides the LocalToolsAdapter class which manages tool registration
5
+ and execution for local, in-process tools.
6
+ """
37
7
 
38
- def get_local_tools_adapter(workdir=None):
39
- return LocalToolsAdapter(workdir=workdir or os.getcwd())
40
-
41
-
42
- # Register tools
43
- for tool_class in [
44
- AskUserTool,
45
- CopyFileTool,
46
- CreateDirectoryTool,
47
- CreateFileTool,
48
- FetchUrlTool,
49
- FindFilesTool,
50
- ViewFileTool,
51
- ReadFilesTool,
52
- MoveFileTool,
53
- OpenUrlTool,
54
- OpenHtmlInBrowserTool,
55
- PythonCodeRunTool,
56
- PythonCommandRunTool,
57
- PythonFileRunTool,
58
- RemoveDirectoryTool,
59
- RemoveFileTool,
60
- ReplaceTextInFileTool,
61
- RunBashCommandTool,
62
- RunPowershellCommandTool,
63
- GetFileOutlineTool,
64
- SearchOutlineTool,
65
- SearchTextTool,
66
- ValidateFileSyntaxTool,
67
- ReadChartTool,
68
- ShowImageTool,
69
- ShowImageGridTool,
70
- ]:
71
- local_tools_adapter.register_tool(tool_class)
8
+ from .adapter import LocalToolsAdapter
72
9
 
73
- # DEBUG: Print registered tools at startup
10
+ __all__ = ["LocalToolsAdapter"]
@@ -0,0 +1,88 @@
1
+ """
2
+ CLI-specific tool initialization for janito.
3
+
4
+ This module provides functions to initialize tools specifically for CLI usage,
5
+ handling circular imports and ensuring proper registration.
6
+ """
7
+
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import List, Optional
11
+
12
+ # Ensure current directory is in path
13
+ sys.path.insert(0, str(Path.cwd()))
14
+
15
+
16
+ def initialize_cli_tools():
17
+ """Initialize tools for CLI usage, avoiding circular imports."""
18
+ try:
19
+ from janito.tools.adapters.local.adapter import LocalToolsAdapter
20
+ from janito.plugin_system.core_loader_fixed import load_core_plugin
21
+ from janito.tools.permissions import set_global_allowed_permissions
22
+ from janito.tools.tool_base import ToolPermissions
23
+
24
+ # Create adapter
25
+ adapter = LocalToolsAdapter()
26
+
27
+ # Set permissions for CLI
28
+ set_global_allowed_permissions(
29
+ ToolPermissions(read=True, write=True, execute=True)
30
+ )
31
+
32
+ # Core plugins to load
33
+ core_plugins = [
34
+ "core.filemanager",
35
+ "core.codeanalyzer",
36
+ "core.system",
37
+ "core.imagedisplay",
38
+ "dev.pythondev",
39
+ "dev.visualization",
40
+ ]
41
+
42
+ loaded_count = 0
43
+ for plugin_name in core_plugins:
44
+ plugin = load_core_plugin(plugin_name)
45
+ if plugin:
46
+ tools = plugin.get_tools()
47
+ for tool_class in tools:
48
+ try:
49
+ adapter.register_tool(tool_class)
50
+ loaded_count += 1
51
+ except ValueError:
52
+ # Tool already registered, skip
53
+ pass
54
+
55
+ return adapter, loaded_count
56
+
57
+ except Exception as e:
58
+ print(f"Error initializing CLI tools: {e}", file=sys.stderr)
59
+ return None, 0
60
+
61
+
62
+ def get_cli_tools_adapter():
63
+ """Get a CLI-initialized tools adapter."""
64
+ adapter, count = initialize_cli_tools()
65
+ if adapter and count > 0:
66
+ return adapter
67
+ return None
68
+
69
+
70
+ def list_cli_tools():
71
+ """List all available CLI tools."""
72
+ adapter = get_cli_tools_adapter()
73
+ if not adapter:
74
+ return []
75
+
76
+ return adapter.list_tools()
77
+
78
+
79
+ if __name__ == "__main__":
80
+ adapter, count = initialize_cli_tools()
81
+ if adapter:
82
+ tools = adapter.list_tools()
83
+ print(f"CLI initialized {count} tools")
84
+ print(f"Available tools: {len(tools)}")
85
+ for tool in sorted(tools):
86
+ print(f" - {tool}")
87
+ else:
88
+ print("Failed to initialize CLI tools")
@@ -0,0 +1,70 @@
1
+ """
2
+ Initialize janito tools for CLI and programmatic usage.
3
+
4
+ This module provides functions to load core plugins and register their tools
5
+ with the local tools adapter.
6
+ """
7
+
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import List, Optional
11
+
12
+ from janito.plugin_system.core_loader_fixed import load_core_plugin
13
+ from janito.tools.adapters.local.adapter import LocalToolsAdapter
14
+
15
+
16
+ def initialize_tools(adapter: Optional[LocalToolsAdapter] = None) -> LocalToolsAdapter:
17
+ """
18
+ Initialize all janito tools by loading core plugins and registering tools.
19
+
20
+ Args:
21
+ adapter: LocalToolsAdapter instance to register tools with.
22
+ If None, creates a new instance.
23
+
24
+ Returns:
25
+ LocalToolsAdapter with all tools registered.
26
+ """
27
+ if adapter is None:
28
+ adapter = LocalToolsAdapter()
29
+
30
+ # Core plugins to load
31
+ core_plugins = [
32
+ "core.filemanager",
33
+ "core.codeanalyzer",
34
+ "core.system",
35
+ "core.imagedisplay",
36
+ "dev.pythondev",
37
+ "dev.visualization",
38
+ ]
39
+
40
+ loaded_count = 0
41
+ for plugin_name in core_plugins:
42
+ plugin = load_core_plugin(plugin_name)
43
+ if plugin:
44
+ tools = plugin.get_tools()
45
+ for tool_class in tools:
46
+ adapter.register_tool(tool_class)
47
+ loaded_count += 1
48
+
49
+ return adapter
50
+
51
+
52
+ def get_initialized_adapter() -> LocalToolsAdapter:
53
+ """Get a pre-initialized LocalToolsAdapter with all tools registered."""
54
+ return initialize_tools()
55
+
56
+
57
+ def list_available_tools() -> List[str]:
58
+ """Get a list of all available tool names."""
59
+ adapter = get_initialized_adapter()
60
+ return sorted(list(adapter._tools.keys()))
61
+
62
+
63
+ if __name__ == "__main__":
64
+ adapter = initialize_tools()
65
+ tools = sorted(list(adapter._tools.keys()))
66
+
67
+ print(f"Initialized {len(tools)} tools")
68
+ print("Available tools:")
69
+ for tool_name in tools:
70
+ print(f" - {tool_name}")