janito 3.2.0__py3-none-any.whl → 3.4.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 (160) hide show
  1. janito/README.md +0 -3
  2. janito/cli/chat_mode/bindings.py +0 -26
  3. janito/cli/chat_mode/session.py +1 -12
  4. janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
  5. janito/cli/cli_commands/list_plugins.py +43 -52
  6. janito/cli/core/getters.py +0 -3
  7. janito/cli/core/model_guesser.py +24 -40
  8. janito/cli/main_cli.py +12 -9
  9. janito/cli/prompt_core.py +9 -20
  10. janito/drivers/openai/driver.py +0 -1
  11. janito/drivers/zai/driver.py +0 -1
  12. janito/hello.txt +0 -0
  13. janito/i18n/it.py +46 -46
  14. janito/llm/agent.py +16 -32
  15. janito/llm/auth_utils.py +5 -14
  16. janito/llm/driver.py +0 -8
  17. janito/plugins/__init__.py +12 -31
  18. janito/plugins/auto_loader.py +11 -12
  19. janito/plugins/auto_loader_fixed.py +11 -12
  20. janito/{plugin_system → plugins}/base.py +2 -5
  21. janito/plugins/builtin.py +1 -15
  22. janito/plugins/core_adapter.py +11 -89
  23. janito/plugins/core_loader.py +120 -0
  24. janito/plugins/core_loader_fixed.py +125 -0
  25. janito/plugins/discovery.py +5 -5
  26. janito/plugins/discovery_core.py +9 -14
  27. janito/plugins/manager.py +1 -1
  28. janito/providers/__init__.py +0 -1
  29. janito/tools/__init__.py +7 -31
  30. janito/tools/adapters/__init__.py +1 -6
  31. janito/tools/adapters/local/__init__.py +70 -7
  32. janito/{plugins/tools → tools/adapters/local}/ask_user.py +3 -3
  33. janito/{plugins/tools → tools/adapters/local}/create_file.py +6 -6
  34. janito/{plugins/tools → tools/adapters/local}/fetch_url.py +3 -3
  35. janito/{plugins/tools → tools/adapters/local}/replace_text_in_file.py +4 -4
  36. janito/{plugins/tools → tools/adapters/local}/show_image.py +6 -15
  37. janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
  38. janito/tools/function_adapter.py +65 -0
  39. janito/tools/loop_protection_decorator.py +117 -114
  40. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/METADATA +2 -1
  41. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/RECORD +85 -156
  42. janito/cli/cli_commands/check_tools.py +0 -212
  43. janito/llm/cancellation_manager.py +0 -63
  44. janito/llm/enter_cancellation.py +0 -107
  45. janito/plugin_system/__init__.py +0 -10
  46. janito/plugin_system/core_loader.py +0 -217
  47. janito/plugin_system/core_loader_fixed.py +0 -225
  48. janito/plugins/core/__init__.py +0 -7
  49. janito/plugins/core/codeanalyzer/__init__.py +0 -43
  50. janito/plugins/core/filemanager/__init__.py +0 -124
  51. janito/plugins/core/filemanager/tools/create_file.py +0 -87
  52. janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
  53. janito/plugins/core/imagedisplay/__init__.py +0 -14
  54. janito/plugins/core/imagedisplay/plugin.py +0 -51
  55. janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
  56. janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
  57. janito/plugins/core/system/__init__.py +0 -23
  58. janito/plugins/dev/__init__.py +0 -7
  59. janito/plugins/dev/pythondev/__init__.py +0 -37
  60. janito/plugins/dev/visualization/__init__.py +0 -23
  61. janito/plugins/example_plugin.py +0 -108
  62. janito/plugins/tools/__init__.py +0 -10
  63. janito/plugins/tools/copy_file.py +0 -87
  64. janito/plugins/tools/core_tools_plugin.py +0 -87
  65. janito/plugins/tools/create_directory.py +0 -70
  66. janito/plugins/tools/decorators.py +0 -19
  67. janito/plugins/tools/delete_text_in_file.py +0 -134
  68. janito/plugins/tools/find_files.py +0 -143
  69. janito/plugins/tools/get_file_outline/__init__.py +0 -7
  70. janito/plugins/tools/get_file_outline/core.py +0 -122
  71. janito/plugins/tools/get_file_outline/java_outline.py +0 -47
  72. janito/plugins/tools/get_file_outline/markdown_outline.py +0 -14
  73. janito/plugins/tools/get_file_outline/python_outline.py +0 -303
  74. janito/plugins/tools/get_file_outline/search_outline.py +0 -36
  75. janito/plugins/tools/move_file.py +0 -131
  76. janito/plugins/tools/open_html_in_browser.py +0 -51
  77. janito/plugins/tools/open_url.py +0 -37
  78. janito/plugins/tools/python_code_run.py +0 -172
  79. janito/plugins/tools/python_command_run.py +0 -171
  80. janito/plugins/tools/python_file_run.py +0 -172
  81. janito/plugins/tools/read_chart.py +0 -259
  82. janito/plugins/tools/read_files.py +0 -58
  83. janito/plugins/tools/remove_directory.py +0 -55
  84. janito/plugins/tools/remove_file.py +0 -58
  85. janito/plugins/tools/run_bash_command.py +0 -183
  86. janito/plugins/tools/run_powershell_command.py +0 -218
  87. janito/plugins/tools/search_text/__init__.py +0 -7
  88. janito/plugins/tools/search_text/core.py +0 -205
  89. janito/plugins/tools/search_text/match_lines.py +0 -67
  90. janito/plugins/tools/search_text/pattern_utils.py +0 -73
  91. janito/plugins/tools/search_text/traverse_directory.py +0 -145
  92. janito/plugins/tools/show_image_grid.py +0 -85
  93. janito/plugins/tools/validate_file_syntax/__init__.py +0 -7
  94. janito/plugins/tools/validate_file_syntax/core.py +0 -114
  95. janito/plugins/tools/validate_file_syntax/css_validator.py +0 -35
  96. janito/plugins/tools/validate_file_syntax/html_validator.py +0 -100
  97. janito/plugins/tools/validate_file_syntax/jinja2_validator.py +0 -50
  98. janito/plugins/tools/validate_file_syntax/js_validator.py +0 -27
  99. janito/plugins/tools/validate_file_syntax/json_validator.py +0 -6
  100. janito/plugins/tools/validate_file_syntax/markdown_validator.py +0 -109
  101. janito/plugins/tools/validate_file_syntax/ps1_validator.py +0 -32
  102. janito/plugins/tools/validate_file_syntax/python_validator.py +0 -5
  103. janito/plugins/tools/validate_file_syntax/xml_validator.py +0 -11
  104. janito/plugins/tools/validate_file_syntax/yaml_validator.py +0 -6
  105. janito/plugins/tools/view_file.py +0 -172
  106. janito/plugins/ui/__init__.py +0 -7
  107. janito/plugins/ui/userinterface/__init__.py +0 -16
  108. janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
  109. janito/plugins/web/__init__.py +0 -7
  110. janito/plugins/web/webtools/__init__.py +0 -33
  111. janito/plugins/web/webtools/tools/fetch_url.py +0 -458
  112. janito/providers/together/__init__.py +0 -1
  113. janito/providers/together/model_info.py +0 -69
  114. janito/providers/together/provider.py +0 -108
  115. janito/tools/cli_initializer.py +0 -88
  116. janito/tools/initialize.py +0 -70
  117. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/copy_file.py +0 -0
  118. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
  119. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
  120. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
  121. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
  122. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
  123. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
  124. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
  125. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
  126. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
  127. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/move_file.py +0 -0
  128. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
  129. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
  130. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_code_run.py +0 -0
  131. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_command_run.py +0 -0
  132. /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_file_run.py +0 -0
  133. /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
  134. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
  135. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
  136. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_file.py +0 -0
  137. /janito/{plugins/core/system/tools → tools/adapters/local}/run_bash_command.py +0 -0
  138. /janito/{plugins/core/system/tools → tools/adapters/local}/run_powershell_command.py +0 -0
  139. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
  140. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
  141. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
  142. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
  143. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
  144. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
  145. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
  146. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
  147. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
  148. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
  149. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
  150. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
  151. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
  152. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
  153. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
  154. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
  155. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
  156. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/view_file.py +0 -0
  157. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/WHEEL +0 -0
  158. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/entry_points.txt +0 -0
  159. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/licenses/LICENSE +0 -0
  160. {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/top_level.txt +0 -0
@@ -1,225 +0,0 @@
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,7 +0,0 @@
1
- """
2
- Core Plugin Package
3
-
4
- Contains essential system and file management plugins.
5
- """
6
-
7
- __all__ = ["filemanager", "codeanalyzer", "system"]
@@ -1,43 +0,0 @@
1
- """
2
- Code Analyzer Plugin
3
-
4
- Tools for understanding and searching code structure.
5
- """
6
-
7
- from typing import List, Optional
8
-
9
-
10
- def get_file_outline(path: str) -> str:
11
- """Get file structure (classes, functions, etc.)"""
12
- return f"get_file_outline(path='{path}')"
13
-
14
-
15
- get_file_outline.tool_name = "get_file_outline"
16
-
17
-
18
- def search_outline(path: str) -> str:
19
- """Search within file outlines"""
20
- return f"search_outline(path='{path}')"
21
-
22
-
23
- search_outline.tool_name = "search_outline"
24
-
25
-
26
- def search_text(
27
- paths: str,
28
- query: str,
29
- use_regex: bool = False,
30
- case_sensitive: bool = True,
31
- max_depth: Optional[int] = None,
32
- ) -> str:
33
- """Full-text search across files with regex support"""
34
- return f"search_text(paths='{paths}', query='{query}', regex={use_regex})"
35
-
36
-
37
- search_text.tool_name = "search_text"
38
-
39
-
40
- # Plugin metadata
41
- __plugin_name__ = "core.codeanalyzer"
42
- __plugin_description__ = "Code analysis and structure understanding"
43
- __plugin_tools__ = [get_file_outline, search_outline, search_text]
@@ -1,124 +0,0 @@
1
- """
2
- File Manager Plugin
3
-
4
- Core file and directory operations for managing project files.
5
- """
6
-
7
- from typing import List, Optional
8
- import os
9
-
10
-
11
- def create_file(path: str, content: str = "", overwrite: bool = False) -> str:
12
- """Create a new file with content"""
13
- return f"create_file(path='{path}', content='{len(content)} chars', overwrite={overwrite})"
14
-
15
-
16
- create_file.tool_name = "create_file"
17
-
18
-
19
- def read_files(paths: List[str]) -> str:
20
- """Read multiple files at once"""
21
- return f"read_files(paths={paths})"
22
-
23
-
24
- read_files.tool_name = "read_files"
25
-
26
-
27
- def view_file(
28
- path: str, from_line: Optional[int] = None, to_line: Optional[int] = None
29
- ) -> str:
30
- """Read specific lines or entire files"""
31
- range_str = f"{from_line}-{to_line}" if from_line or to_line else "all"
32
- return f"view_file(path='{path}', range='{range_str}')"
33
-
34
-
35
- view_file.tool_name = "view_file"
36
-
37
-
38
- def replace_text_in_file(
39
- path: str, search_text: str, replacement_text: str, replace_all: bool = True
40
- ) -> str:
41
- """Find and replace text in files"""
42
- return f"replace_text_in_file(path='{path}', search='{search_text[:20]}...', replace='{replacement_text[:20]}...')"
43
-
44
-
45
- replace_text_in_file.tool_name = "replace_text_in_file"
46
-
47
-
48
- def validate_file_syntax(path: str) -> str:
49
- """Check file syntax (Python/Markdown)"""
50
- return f"validate_file_syntax(path='{path}')"
51
-
52
-
53
- validate_file_syntax.tool_name = "validate_file_syntax"
54
-
55
-
56
- def create_directory(path: str) -> str:
57
- """Create new directories"""
58
- return f"create_directory(path='{path}')"
59
-
60
-
61
- create_directory.tool_name = "create_directory"
62
-
63
-
64
- def remove_directory(path: str, recursive: bool = False) -> str:
65
- """Remove directories (recursive option)"""
66
- return f"remove_directory(path='{path}', recursive={recursive})"
67
-
68
-
69
- remove_directory.tool_name = "remove_directory"
70
-
71
-
72
- def remove_file(path: str) -> str:
73
- """Delete single files"""
74
- return f"remove_file(path='{path}')"
75
-
76
-
77
- remove_file.tool_name = "remove_file"
78
-
79
-
80
- def copy_file(sources: str, target: str, overwrite: bool = False) -> str:
81
- """Copy files or directories"""
82
- return f"copy_file(sources='{sources}', target='{target}', overwrite={overwrite})"
83
-
84
-
85
- copy_file.tool_name = "copy_file"
86
-
87
-
88
- def move_file(src_path: str, dest_path: str, overwrite: bool = False) -> str:
89
- """Move/rename files or directories"""
90
- return f"move_file(src='{src_path}', dest='{dest_path}', overwrite={overwrite})"
91
-
92
-
93
- move_file.tool_name = "move_file"
94
-
95
-
96
- def find_files(
97
- paths: str,
98
- pattern: str,
99
- max_depth: Optional[int] = None,
100
- include_gitignored: bool = False,
101
- ) -> str:
102
- """Search for files by pattern (respects .gitignore)"""
103
- return f"find_files(paths='{paths}', pattern='{pattern}', max_depth={max_depth})"
104
-
105
-
106
- find_files.tool_name = "find_files"
107
-
108
-
109
- # Plugin metadata
110
- __plugin_name__ = "core.filemanager"
111
- __plugin_description__ = "Core file and directory operations"
112
- __plugin_tools__ = [
113
- create_file,
114
- read_files,
115
- view_file,
116
- replace_text_in_file,
117
- validate_file_syntax,
118
- create_directory,
119
- remove_directory,
120
- remove_file,
121
- copy_file,
122
- move_file,
123
- find_files,
124
- ]
@@ -1,87 +0,0 @@
1
- import os
2
- from janito.tools.path_utils import expand_path
3
- from janito.tools.adapters.local.adapter import register_local_tool
4
-
5
- from janito.tools.tool_utils import display_path
6
- from janito.tools.tool_base import ToolBase, ToolPermissions
7
- from janito.report_events import ReportAction
8
- from janito.i18n import tr
9
- from janito.tools.loop_protection_decorator import protect_against_loops
10
-
11
- from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
12
-
13
-
14
- @register_local_tool
15
- class CreateFileTool(ToolBase):
16
- """
17
- Create a new file with the given content.
18
-
19
- Args:
20
- path (str): Path to the file to create.
21
- content (str): Content to write to the file.
22
- overwrite (bool, optional): Overwrite existing file if True. Default: False. Recommended only after reading the file to be overwritten.
23
- Returns:
24
- str: Status message indicating the result. Example:
25
- - "✅ Successfully created the file at ..."
26
-
27
- Note: Syntax validation is automatically performed after this operation.
28
-
29
- Security: This tool includes loop protection to prevent excessive file creation operations.
30
- Protection: Prevents repeated create calls for the same file path within a short window (1 allowed per 10 seconds).
31
- """
32
-
33
- permissions = ToolPermissions(write=True)
34
- tool_name = "create_file"
35
-
36
- @protect_against_loops(max_calls=1, time_window=10.0, key_field="path")
37
- def run(self, path: str, content: str, overwrite: bool = False) -> str:
38
- path = expand_path(path)
39
- disp_path = display_path(path)
40
- if os.path.exists(path) and not overwrite:
41
- try:
42
- with open(path, "r", encoding="utf-8", errors="replace") as f:
43
- existing_content = f.read()
44
- except Exception as e:
45
- existing_content = f"[Error reading file: {e}]"
46
- return tr(
47
- "❗ Cannot create file: file already exists at '{disp_path}'.\n--- Current file content ---\n{existing_content}",
48
- disp_path=disp_path,
49
- existing_content=existing_content,
50
- )
51
- # Determine if we are overwriting an existing file
52
- is_overwrite = os.path.exists(path) and overwrite
53
- if is_overwrite:
54
- # Overwrite branch: log only overwrite warning (no create message)
55
- self.report_action(
56
- tr("⚠️ Overwriting file '{disp_path}'", disp_path=disp_path),
57
- ReportAction.CREATE,
58
- )
59
- dir_name = os.path.dirname(path)
60
- if dir_name:
61
- os.makedirs(dir_name, exist_ok=True)
62
- if not is_overwrite:
63
- # Create branch: log file creation message
64
- self.report_action(
65
- tr("📝 Create file '{disp_path}' ...", disp_path=disp_path),
66
- ReportAction.CREATE,
67
- )
68
- with open(path, "w", encoding="utf-8", errors="replace") as f:
69
- f.write(content)
70
- new_lines = content.count("\n") + 1 if content else 0
71
- self.report_success(
72
- tr("✅ {new_lines} lines", new_lines=new_lines), ReportAction.CREATE
73
- )
74
- # Perform syntax validation and append result
75
- validation_result = validate_file_syntax(path)
76
- if is_overwrite:
77
- # Overwrite branch: return minimal overwrite info to user
78
- return (
79
- tr("✅ {new_lines} lines", new_lines=new_lines)
80
- + f"\n{validation_result}"
81
- )
82
- else:
83
- # Create branch: return detailed create success to user
84
- return (
85
- tr("✅ Created file {new_lines} lines.", new_lines=new_lines)
86
- + f"\n{validation_result}"
87
- )