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,37 @@
1
+ """
2
+ Python Development Plugin
3
+
4
+ Python development and execution tools.
5
+ """
6
+
7
+ from typing import Optional
8
+
9
+
10
+ def python_code_run(code: str, timeout: int = 60) -> str:
11
+ """Execute Python code via stdin"""
12
+ return f"python_code_run(code='{len(code)} chars', timeout={timeout})"
13
+
14
+
15
+ python_code_run.tool_name = "python_code_run"
16
+
17
+
18
+ def python_command_run(code: str, timeout: int = 60) -> str:
19
+ """Execute Python with -c flag"""
20
+ return f"python_command_run(code='{len(code)} chars', timeout={timeout})"
21
+
22
+
23
+ python_command_run.tool_name = "python_command_run"
24
+
25
+
26
+ def python_file_run(path: str, timeout: int = 60) -> str:
27
+ """Run Python script files"""
28
+ return f"python_file_run(path='{path}', timeout={timeout})"
29
+
30
+
31
+ python_file_run.tool_name = "python_file_run"
32
+
33
+
34
+ # Plugin metadata
35
+ __plugin_name__ = "dev.pythondev"
36
+ __plugin_description__ = "Python development and execution"
37
+ __plugin_tools__ = [python_code_run, python_command_run, python_file_run]
@@ -0,0 +1,23 @@
1
+ """
2
+ Visualization Plugin
3
+
4
+ Data visualization and charting tools.
5
+ """
6
+
7
+ from typing import Dict, Any
8
+
9
+
10
+ def read_chart(
11
+ data: Dict[str, Any], title: str = "Chart", width: int = 80, height: int = 20
12
+ ) -> str:
13
+ """Display charts in terminal (bar, line, pie, table)"""
14
+ return f"read_chart(type='{data.get('type')}', title='{title}')"
15
+
16
+
17
+ read_chart.tool_name = "read_chart"
18
+
19
+
20
+ # Plugin metadata
21
+ __plugin_name__ = "dev.visualization"
22
+ __plugin_description__ = "Data visualization and charts"
23
+ __plugin_tools__ = [read_chart]
@@ -31,9 +31,9 @@ from pathlib import Path
31
31
  from typing import Optional, List
32
32
  import logging
33
33
 
34
- from .base import Plugin
34
+ from janito.plugin_system.base import Plugin
35
35
  from .builtin import load_builtin_plugin, BuiltinPluginRegistry
36
- from .core_loader import load_core_plugin
36
+ from janito.plugin_system.core_loader import load_core_plugin
37
37
 
38
38
  logger = logging.getLogger(__name__)
39
39
 
@@ -75,13 +75,13 @@ def discover_plugins(
75
75
  parts = plugin_name.split(".")
76
76
  if len(parts) == 2:
77
77
  package_name, submodule_name = parts
78
-
78
+
79
79
  # Handle core plugins with dedicated loader
80
80
  if plugin_name.startswith(("core.", "dev.", "ui.", "web.")):
81
81
  plugin = load_core_plugin(plugin_name)
82
82
  if plugin:
83
83
  return plugin
84
-
84
+
85
85
  for base_path in all_paths:
86
86
  package_path = base_path / package_name / submodule_name / "__init__.py"
87
87
  if package_path.exists():
@@ -157,7 +157,7 @@ def _load_plugin_from_file(
157
157
 
158
158
  # Check for package-based plugin with __plugin_name__ metadata
159
159
  if hasattr(module, "__plugin_name__"):
160
- from janito.plugins.base import PluginMetadata
160
+ from janito.plugin_system.base import PluginMetadata
161
161
 
162
162
  # Create a dynamic plugin class
163
163
  class PackagePlugin(Plugin):
@@ -17,11 +17,11 @@ from .core_adapter import CorePluginAdapter
17
17
  def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
18
18
  """
19
19
  Load a core plugin from a package directory.
20
-
20
+
21
21
  Args:
22
22
  package_path: Path to the __init__.py file
23
23
  plugin_name: Full plugin name (e.g., core.filemanager)
24
-
24
+
25
25
  Returns:
26
26
  Plugin instance if loaded successfully
27
27
  """
@@ -30,20 +30,25 @@ def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
30
30
  spec = importlib.util.spec_from_file_location(plugin_name, package_path)
31
31
  if spec is None or spec.loader is None:
32
32
  return None
33
-
33
+
34
34
  module = importlib.util.module_from_spec(spec)
35
35
  spec.loader.exec_module(module)
36
-
36
+
37
37
  # Get plugin metadata
38
38
  plugin_name_attr = getattr(module, "__plugin_name__", plugin_name)
39
- description = getattr(module, "__plugin_description__", f"Core plugin: {plugin_name}")
40
-
39
+ description = getattr(
40
+ module, "__plugin_description__", f"Core plugin: {plugin_name}"
41
+ )
42
+
41
43
  # Create and return the core plugin adapter
42
44
  plugin = CorePluginAdapter(plugin_name_attr, description, module)
43
45
  plugin.initialize() # Initialize to set up tools
44
46
  return plugin
45
-
47
+
46
48
  except Exception as e:
47
49
  import logging
48
- logging.getLogger(__name__).error(f"Failed to load core plugin {plugin_name}: {e}")
49
- return None
50
+
51
+ logging.getLogger(__name__).error(
52
+ f"Failed to load core plugin {plugin_name}: {e}"
53
+ )
54
+ return None
@@ -0,0 +1,108 @@
1
+ """
2
+ Example plugin demonstrating the plugin system.
3
+ """
4
+
5
+ from janito.plugin_system.base import Plugin, PluginMetadata, PluginResource
6
+ from janito.tools.tool_base import ToolBase, ToolPermissions
7
+ from typing import Dict, Any
8
+
9
+
10
+ class HelloWorldTool(ToolBase):
11
+ """A simple tool that says hello."""
12
+
13
+ tool_name = "hello_world"
14
+ permissions = ToolPermissions(read=True, write=False, execute=True)
15
+
16
+ def run(self, name: str = "World") -> str:
17
+ """
18
+ Say hello to someone.
19
+
20
+ Args:
21
+ name: Name of the person to greet
22
+
23
+ Returns:
24
+ Greeting message
25
+ """
26
+ self.report_action(f"Saying hello to {name}", "greet")
27
+ return f"Hello, {name}!"
28
+
29
+
30
+ class CalculatorTool(ToolBase):
31
+ """A simple calculator tool."""
32
+
33
+ tool_name = "calculator"
34
+ permissions = ToolPermissions(read=True, write=False, execute=True)
35
+
36
+ def run(self, operation: str, a: float, b: float) -> str:
37
+ """
38
+ Perform basic calculations.
39
+
40
+ Args:
41
+ operation: Operation to perform (add, subtract, multiply, divide)
42
+ a: First number
43
+ b: Second number
44
+
45
+ Returns:
46
+ Result as string
47
+ """
48
+ self.report_action(f"Calculating {a} {operation} {b}", "calculate")
49
+
50
+ if operation == "add":
51
+ result = a + b
52
+ elif operation == "subtract":
53
+ result = a - b
54
+ elif operation == "multiply":
55
+ result = a * b
56
+ elif operation == "divide":
57
+ if b == 0:
58
+ return "Error: Division by zero"
59
+ result = a / b
60
+ else:
61
+ return f"Error: Unknown operation '{operation}'"
62
+
63
+ return str(result)
64
+
65
+
66
+ class ExamplePlugin(Plugin):
67
+ """Example plugin providing basic tools."""
68
+
69
+ def get_metadata(self) -> PluginMetadata:
70
+ return PluginMetadata(
71
+ name="example",
72
+ version="1.0.0",
73
+ description="Example plugin with basic tools",
74
+ author="Janito Team",
75
+ license="MIT",
76
+ homepage="https://github.com/janito/example-plugin",
77
+ )
78
+
79
+ def get_tools(self):
80
+ return [HelloWorldTool, CalculatorTool]
81
+
82
+ def initialize(self):
83
+ print("Example plugin initialized!")
84
+
85
+ def cleanup(self):
86
+ print("Example plugin cleaned up!")
87
+
88
+ def get_config_schema(self) -> Dict[str, Any]:
89
+ """Return JSON schema for plugin configuration."""
90
+ return {
91
+ "type": "object",
92
+ "properties": {
93
+ "greeting_prefix": {
94
+ "type": "string",
95
+ "description": "Custom greeting prefix for hello_world tool",
96
+ "default": "Hello",
97
+ },
98
+ "max_calculation": {
99
+ "type": "number",
100
+ "description": "Maximum allowed calculation result",
101
+ "default": 1000000,
102
+ },
103
+ },
104
+ }
105
+
106
+
107
+ # This makes the plugin discoverable
108
+ PLUGIN_CLASS = ExamplePlugin
janito/plugins/manager.py CHANGED
@@ -10,7 +10,7 @@ from pathlib import Path
10
10
  from typing import Dict, List, Optional, Any
11
11
  import logging
12
12
 
13
- from .base import Plugin, PluginMetadata
13
+ from janito.plugin_system.base import Plugin, PluginMetadata
14
14
  from .discovery import discover_plugins
15
15
  from .config import load_plugins_config, get_user_plugins_dir
16
16
  from .builtin import BuiltinPluginRegistry, load_builtin_plugin
@@ -0,0 +1,10 @@
1
+ """
2
+ Core tools plugin for janito.
3
+
4
+ This plugin provides the essential tools for file operations, code execution,
5
+ and system interactions that are core to janito's functionality.
6
+ """
7
+
8
+ from .core_tools_plugin import CoreToolsPlugin
9
+
10
+ __all__ = ["CoreToolsPlugin"]
@@ -1,5 +1,5 @@
1
1
  from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.tools.adapters.local.adapter import register_local_tool
2
+ from janito.plugins.tools.decorators import register_core_tool
3
3
  from janito.tools.loop_protection_decorator import protect_against_loops
4
4
 
5
5
  from rich import print as rich_print
@@ -16,8 +16,8 @@ from prompt_toolkit.styles import Style
16
16
  toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
17
17
 
18
18
 
19
- @register_local_tool
20
- class AskUserTool(ToolBase):
19
+ @register_core_tool
20
+ class AskUser(ToolBase):
21
21
  """
22
22
  Prompts the user for clarification or input with a question.
23
23
 
@@ -0,0 +1,87 @@
1
+ import os
2
+ from janito.tools.path_utils import expand_path
3
+ import shutil
4
+ from typing import List, Union
5
+ from janito.plugins.tools.decorators import register_core_tool
6
+ from janito.tools.tool_base import ToolBase, ToolPermissions
7
+ from janito.tools.tool_utils import display_path
8
+ from janito.report_events import ReportAction
9
+ from janito.i18n import tr
10
+
11
+
12
+ @register_core_tool
13
+ class CopyFile(ToolBase):
14
+ """
15
+ Copy one or more files to a target directory, or copy a single file to a new file.
16
+ Args:
17
+ sources (str): Space-separated path(s) to the file(s) to copy.
18
+ For multiple sources, provide a single string with paths separated by spaces.
19
+ target (str): Destination path. If copying multiple sources, this must be an existing directory.
20
+ overwrite (bool, optional): Overwrite existing files. Default: False.
21
+ Recommended only after reading the file to be overwritten.
22
+ Returns:
23
+ str: Status string for each copy operation.
24
+ """
25
+
26
+ permissions = ToolPermissions(read=True, write=True)
27
+ tool_name = "copy_file"
28
+
29
+ def run(self, sources: str, target: str, overwrite: bool = False) -> str:
30
+ source_list = [expand_path(src) for src in sources.split() if src]
31
+ target = expand_path(target)
32
+ messages = []
33
+ if len(source_list) > 1:
34
+ if not os.path.isdir(target):
35
+ return tr(
36
+ "❗ Target must be an existing directory when copying multiple files: '{target}'",
37
+ target=display_path(target),
38
+ )
39
+ for src in source_list:
40
+ if not os.path.isfile(src):
41
+ messages.append(
42
+ tr(
43
+ "❗ Source file does not exist: '{src}'",
44
+ src=display_path(src),
45
+ )
46
+ )
47
+ continue
48
+ dst = os.path.join(target, os.path.basename(src))
49
+ messages.append(self._copy_one(src, dst, overwrite=overwrite))
50
+ else:
51
+ src = source_list[0]
52
+ if os.path.isdir(target):
53
+ dst = os.path.join(target, os.path.basename(src))
54
+ else:
55
+ dst = target
56
+ messages.append(self._copy_one(src, dst, overwrite=overwrite))
57
+ return "\n".join(messages)
58
+
59
+ def _copy_one(self, src, dst, overwrite=False) -> str:
60
+ disp_src = display_path(src)
61
+ disp_dst = display_path(dst)
62
+ if not os.path.isfile(src):
63
+ return tr("❗ Source file does not exist: '{src}'", src=disp_src)
64
+ if os.path.exists(dst) and not overwrite:
65
+ return tr(
66
+ "❗ Target already exists: '{dst}'. Set overwrite=True to replace.",
67
+ dst=disp_dst,
68
+ )
69
+ try:
70
+ os.makedirs(os.path.dirname(dst), exist_ok=True)
71
+ shutil.copy2(src, dst)
72
+ note = (
73
+ "\n⚠️ Overwrote existing file. (recommended only after reading the file to be overwritten)"
74
+ if (os.path.exists(dst) and overwrite)
75
+ else ""
76
+ )
77
+ self.report_success(
78
+ tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst)
79
+ )
80
+ return tr("✅ Copied '{src}' to '{dst}'", src=disp_src, dst=disp_dst) + note
81
+ except Exception as e:
82
+ return tr(
83
+ "❗ Copy failed from '{src}' to '{dst}': {err}",
84
+ src=disp_src,
85
+ dst=disp_dst,
86
+ err=str(e),
87
+ )
@@ -0,0 +1,87 @@
1
+ """
2
+ Core tools plugin implementation.
3
+ """
4
+
5
+ from functools import wraps
6
+ from typing import Type
7
+ from janito.plugin_system.base import Plugin, PluginMetadata
8
+
9
+ from .ask_user import AskUser
10
+ from .copy_file import CopyFile
11
+ from .create_directory import CreateDirectory
12
+ from .create_file import CreateFile
13
+ from .delete_text_in_file import DeleteTextInFile
14
+ from .fetch_url import FetchUrl
15
+ from .find_files import FindFiles
16
+ from .move_file import MoveFile
17
+ from .open_html_in_browser import OpenHtmlInBrowser
18
+ from .open_url import OpenUrl
19
+ from .python_code_run import PythonCodeRun
20
+ from .python_command_run import PythonCommandRun
21
+ from .python_file_run import PythonFileRun
22
+ from .read_chart import ReadChart
23
+ from .read_files import ReadFiles
24
+ from .remove_directory import RemoveDirectory
25
+ from .remove_file import RemoveFile
26
+ from .replace_text_in_file import ReplaceTextInFile
27
+ from .run_bash_command import RunBashCommand
28
+ from .run_powershell_command import RunPowershellCommand
29
+ from .show_image import ShowImage
30
+ from .show_image_grid import ShowImageGrid
31
+ from .view_file import ViewFile
32
+ from .validate_file_syntax.core import ValidateFileSyntax
33
+ from .get_file_outline.core import GetFileOutline
34
+ from .search_text.core import SearchText
35
+ from .decorators import get_core_tools
36
+
37
+ # Registry for core tools
38
+ _core_tools_registry = []
39
+
40
+
41
+ def register_core_tool(cls: Type):
42
+ """Decorator to register a core tool."""
43
+ _core_tools_registry.append(cls)
44
+ return cls
45
+
46
+
47
+ class CoreToolsPlugin(Plugin):
48
+ """Core tools plugin providing essential janito functionality."""
49
+
50
+ def get_metadata(self):
51
+ return PluginMetadata(
52
+ name="core_tools",
53
+ version="1.0.0",
54
+ description="Core tools for file operations, code execution, and system interactions",
55
+ author="janito team",
56
+ license="MIT",
57
+ )
58
+
59
+ def get_tools(self):
60
+ return [
61
+ AskUser,
62
+ CopyFile,
63
+ CreateDirectory,
64
+ CreateFile,
65
+ DeleteTextInFile,
66
+ FetchUrl,
67
+ FindFiles,
68
+ MoveFile,
69
+ OpenHtmlInBrowser,
70
+ OpenUrl,
71
+ PythonCodeRun,
72
+ PythonCommandRun,
73
+ PythonFileRun,
74
+ ReadChart,
75
+ ReadFiles,
76
+ RemoveDirectory,
77
+ RemoveFile,
78
+ ReplaceTextInFile,
79
+ RunBashCommand,
80
+ RunPowershellCommand,
81
+ ShowImage,
82
+ ShowImageGrid,
83
+ ViewFile,
84
+ ValidateFileSyntax,
85
+ GetFileOutline,
86
+ SearchText,
87
+ ] + get_core_tools()
@@ -0,0 +1,70 @@
1
+ from janito.plugins.tools.decorators import register_core_tool
2
+
3
+ from janito.tools.tool_utils import display_path
4
+ from janito.tools.tool_base import ToolBase, ToolPermissions
5
+ from janito.report_events import ReportAction
6
+ from janito.i18n import tr
7
+ import os
8
+ from janito.tools.path_utils import expand_path
9
+
10
+
11
+ @register_core_tool
12
+ class CreateDirectory(ToolBase):
13
+ """
14
+ Create a new directory at the specified path.
15
+ Args:
16
+ path (str): Path for the new directory.
17
+ Returns:
18
+ str: Status message indicating the result. Example:
19
+ - "5c5 Successfully created the directory at ..."
20
+ - "5d7 Cannot create directory: ..."
21
+ """
22
+
23
+ permissions = ToolPermissions(write=True)
24
+ tool_name = "create_directory"
25
+
26
+ def run(self, path: str) -> str:
27
+ path = expand_path(path)
28
+ disp_path = display_path(path)
29
+ self.report_action(
30
+ tr("📁 Create directory '{disp_path}' ...", disp_path=disp_path),
31
+ ReportAction.CREATE,
32
+ )
33
+ try:
34
+ if os.path.exists(path):
35
+ if not os.path.isdir(path):
36
+ self.report_error(
37
+ tr(
38
+ "❌ Path '{disp_path}' exists and is not a directory.",
39
+ disp_path=disp_path,
40
+ )
41
+ )
42
+ return tr(
43
+ "❌ Path '{disp_path}' exists and is not a directory.",
44
+ disp_path=disp_path,
45
+ )
46
+ self.report_error(
47
+ tr(
48
+ "❗ Directory '{disp_path}' already exists.",
49
+ disp_path=disp_path,
50
+ )
51
+ )
52
+ return tr(
53
+ "❗ Cannot create directory: '{disp_path}' already exists.",
54
+ disp_path=disp_path,
55
+ )
56
+ os.makedirs(path, exist_ok=True)
57
+ self.report_success(tr("✅ Directory created"))
58
+ return tr(
59
+ "✅ Successfully created the directory at '{disp_path}'.",
60
+ disp_path=disp_path,
61
+ )
62
+ except Exception as e:
63
+ self.report_error(
64
+ tr(
65
+ "❌ Error creating directory '{disp_path}': {error}",
66
+ disp_path=disp_path,
67
+ error=e,
68
+ )
69
+ )
70
+ return tr("❌ Cannot create directory: {error}", error=e)
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  from janito.tools.path_utils import expand_path
3
- from janito.tools.adapters.local.adapter import register_local_tool
3
+ from janito.plugins.tools.decorators import register_core_tool
4
4
 
5
5
  from janito.tools.tool_utils import display_path
6
6
  from janito.tools.tool_base import ToolBase, ToolPermissions
@@ -8,11 +8,11 @@ from janito.report_events import ReportAction
8
8
  from janito.i18n import tr
9
9
  from janito.tools.loop_protection_decorator import protect_against_loops
10
10
 
11
- from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
11
+ from janito.plugins.tools.validate_file_syntax.core import validate_file_syntax
12
12
 
13
13
 
14
- @register_local_tool
15
- class CreateFileTool(ToolBase):
14
+ @register_core_tool
15
+ class CreateFile(ToolBase):
16
16
  """
17
17
  Create a new file with specified content at the given path.
18
18
 
@@ -55,7 +55,7 @@ class CreateFileTool(ToolBase):
55
55
  or file exists (when overwrite=False).
56
56
 
57
57
  Security Features:
58
- - Loop protection: Maximum 5 calls per 10 seconds for the same file path
58
+ - Loop protection: Prevents repeated create calls for the same file path within a short window (1 allowed per 10 seconds)
59
59
  - Path traversal prevention: Validates and sanitizes file paths
60
60
  - Permission checking: Respects file system permissions
61
61
  - Atomic writes: Prevents partial file creation on errors
@@ -84,7 +84,7 @@ class CreateFileTool(ToolBase):
84
84
  permissions = ToolPermissions(write=True)
85
85
  tool_name = "create_file"
86
86
 
87
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
87
+ @protect_against_loops(max_calls=1, time_window=3600.0, key_field="path")
88
88
  def run(self, path: str, content: str, overwrite: bool = False) -> str:
89
89
  path = expand_path(path)
90
90
  disp_path = display_path(path)
@@ -0,0 +1,19 @@
1
+ """
2
+ Decorators for core tools registration.
3
+ """
4
+
5
+ from typing import Type
6
+
7
+ # Registry for core tools
8
+ _core_tools_registry = []
9
+
10
+
11
+ def register_core_tool(cls: Type):
12
+ """Decorator to register a core tool."""
13
+ _core_tools_registry.append(cls)
14
+ return cls
15
+
16
+
17
+ def get_core_tools():
18
+ """Get all registered core tools."""
19
+ return list(_core_tools_registry)