janito 3.2.0__py3-none-any.whl → 3.3.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.
- janito/README.md +0 -3
- janito/cli/chat_mode/bindings.py +0 -26
- janito/cli/chat_mode/session.py +1 -12
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
- janito/cli/cli_commands/list_plugins.py +8 -13
- janito/cli/core/model_guesser.py +24 -40
- janito/cli/prompt_core.py +9 -20
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +16 -32
- janito/llm/driver.py +0 -8
- janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader.py +3 -76
- janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader_fixed.py +3 -79
- janito/plugins/__init__.py +21 -29
- janito/plugins/__main__.py +85 -0
- janito/plugins/base.py +57 -0
- janito/plugins/builtin.py +1 -1
- janito/plugins/core/filemanager/tools/copy_file.py +25 -1
- janito/plugins/core/filemanager/tools/create_directory.py +28 -1
- janito/plugins/core/filemanager/tools/create_file.py +27 -3
- janito/plugins/core/filemanager/tools/delete_text_in_file.py +1 -0
- janito/plugins/core/imagedisplay/plugin.py +1 -1
- janito/plugins/core_loader.py +144 -0
- janito/plugins/discovery.py +3 -3
- janito/plugins/example_plugin.py +1 -1
- janito/plugins/manager.py +1 -1
- janito/plugins_backup_20250825_070018/__init__.py +36 -0
- janito/{plugins → plugins_backup_20250825_070018}/auto_loader.py +11 -12
- janito/plugins_backup_20250825_070018/builtin.py +102 -0
- janito/plugins_backup_20250825_070018/config.py +84 -0
- janito/plugins_backup_20250825_070018/core/__init__.py +7 -0
- janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +43 -0
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +1 -0
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +122 -0
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +1 -0
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +205 -0
- janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +124 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +87 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +70 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +87 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +135 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +143 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +131 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +58 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +55 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +58 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +270 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +1 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +114 -0
- janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +172 -0
- janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +14 -0
- janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +51 -0
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +1 -0
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +83 -0
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +84 -0
- janito/plugins_backup_20250825_070018/core/system/__init__.py +23 -0
- janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +183 -0
- janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +218 -0
- janito/plugins_backup_20250825_070018/core_adapter.py +55 -0
- janito/plugins_backup_20250825_070018/dev/__init__.py +7 -0
- janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +37 -0
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +172 -0
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +171 -0
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +172 -0
- janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +23 -0
- janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +259 -0
- janito/plugins_backup_20250825_070018/discovery.py +289 -0
- janito/{plugins → plugins_backup_20250825_070018}/discovery_core.py +9 -14
- janito/plugins_backup_20250825_070018/example_plugin.py +108 -0
- janito/plugins_backup_20250825_070018/manager.py +243 -0
- janito/{plugins → plugins_backup_20250825_070018}/tools/core_tools_plugin.py +10 -9
- janito/{plugins → plugins_backup_20250825_070018}/tools/create_file.py +2 -2
- janito/{plugins → plugins_backup_20250825_070018}/tools/delete_text_in_file.py +1 -0
- janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +47 -0
- janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +14 -0
- janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +303 -0
- janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +36 -0
- janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +67 -0
- janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +73 -0
- janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +145 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +35 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +100 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +50 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +27 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +6 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +109 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +32 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +5 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +11 -0
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +6 -0
- janito/plugins_backup_20250825_070018/ui/__init__.py +7 -0
- janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +16 -0
- janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +110 -0
- janito/plugins_backup_20250825_070018/web/__init__.py +7 -0
- janito/plugins_backup_20250825_070018/web/webtools/__init__.py +33 -0
- janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +458 -0
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +51 -0
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +37 -0
- janito/providers/__init__.py +0 -1
- janito/tools/base.py +31 -1
- janito/tools/cli_initializer.py +1 -1
- janito/tools/function_adapter.py +176 -0
- janito/tools/initialize.py +1 -1
- janito/tools/loop_protection_decorator.py +117 -114
- janito/tools/tool_base.py +142 -114
- janito/tools/tools_schema.py +12 -6
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/METADATA +1 -1
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/RECORD +160 -95
- janito/llm/cancellation_manager.py +0 -63
- janito/llm/enter_cancellation.py +0 -107
- janito/plugins/core_adapter.py +0 -131
- janito/providers/together/__init__.py +0 -1
- janito/providers/together/model_info.py +0 -69
- janito/providers/together/provider.py +0 -108
- /janito/{plugin_system → plugin_system_backup_20250825_070018}/__init__.py +0 -0
- /janito/{plugin_system → plugin_system_backup_20250825_070018}/base.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/auto_loader_fixed.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/java_outline.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/python_outline.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/search_outline.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/match_lines.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/pattern_utils.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/traverse_directory.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/__init__.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/ask_user.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/copy_file.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/create_directory.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/decorators.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/fetch_url.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/find_files.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/__init__.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/core.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/move_file.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/open_html_in_browser.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/open_url.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/python_code_run.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/python_command_run.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/python_file_run.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/read_chart.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/read_files.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_directory.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_file.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/replace_text_in_file.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/run_bash_command.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/run_powershell_command.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/__init__.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/core.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image_grid.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/core.py +0 -0
- /janito/{plugins → plugins_backup_20250825_070018}/tools/view_file.py +0 -0
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/WHEEL +0 -0
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/entry_points.txt +0 -0
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,124 @@
|
|
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
|
+
]
|
@@ -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.tools.adapters.local.adapter import register_local_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_local_tool
|
13
|
+
class CopyFileTool(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,70 @@
|
|
1
|
+
from janito.tools.adapters.local.adapter import register_local_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_local_tool
|
12
|
+
class CreateDirectoryTool(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)
|
@@ -0,0 +1,87 @@
|
|
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
|
+
Maximum 5 calls per 10 seconds for the same file path.
|
31
|
+
"""
|
32
|
+
|
33
|
+
permissions = ToolPermissions(write=True)
|
34
|
+
tool_name = "create_file"
|
35
|
+
|
36
|
+
@protect_against_loops(max_calls=5, 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
|
+
)
|
@@ -0,0 +1,135 @@
|
|
1
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
+
from janito.report_events import ReportAction
|
3
|
+
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
+
from janito.i18n import tr
|
5
|
+
import shutil
|
6
|
+
from janito.tools.adapters.local.validate_file_syntax.core import validate_file_syntax
|
7
|
+
|
8
|
+
|
9
|
+
@register_local_tool
|
10
|
+
class DeleteTextInFileTool(ToolBase):
|
11
|
+
"""
|
12
|
+
Delete all occurrences of text between start_marker and end_marker (inclusive) in a file, using exact string markers.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
path (str): Path to the file to modify.
|
16
|
+
start_marker (str): The starting delimiter string.
|
17
|
+
end_marker (str): The ending delimiter string.
|
18
|
+
backup (bool, optional): Deprecated. No backups are created anymore and this flag is ignored. Defaults to False.
|
19
|
+
|
20
|
+
Returns:
|
21
|
+
str: Status message indicating the result.
|
22
|
+
"""
|
23
|
+
|
24
|
+
permissions = ToolPermissions(read=True, write=True)
|
25
|
+
tool_name = "delete_text_in_file"
|
26
|
+
|
27
|
+
def run(
|
28
|
+
self,
|
29
|
+
path: str,
|
30
|
+
start_marker: str,
|
31
|
+
end_marker: str,
|
32
|
+
backup: bool = False,
|
33
|
+
) -> str:
|
34
|
+
from janito.tools.tool_utils import display_path
|
35
|
+
|
36
|
+
disp_path = display_path(path)
|
37
|
+
info_msg = tr(
|
38
|
+
"📝 Delete text in {disp_path} between markers: '{start_marker}' ... '{end_marker}'",
|
39
|
+
disp_path=disp_path,
|
40
|
+
start_marker=start_marker,
|
41
|
+
end_marker=end_marker,
|
42
|
+
)
|
43
|
+
self.report_action(info_msg, ReportAction.CREATE)
|
44
|
+
try:
|
45
|
+
content = self._read_file_content(path)
|
46
|
+
occurrences, match_lines = self._find_marker_blocks(
|
47
|
+
content, start_marker, end_marker
|
48
|
+
)
|
49
|
+
if occurrences == 0:
|
50
|
+
self.report_warning(
|
51
|
+
tr(" ℹ️ No blocks found between markers."), ReportAction.CREATE
|
52
|
+
)
|
53
|
+
return tr(
|
54
|
+
"No blocks found between markers in {path}.",
|
55
|
+
path=path,
|
56
|
+
)
|
57
|
+
|
58
|
+
new_content, deleted_blocks = self._delete_blocks(
|
59
|
+
content, start_marker, end_marker
|
60
|
+
)
|
61
|
+
self._write_file_content(path, new_content)
|
62
|
+
validation_result = validate_file_syntax(path)
|
63
|
+
self._report_success(match_lines)
|
64
|
+
return tr(
|
65
|
+
"Deleted {count} block(s) between markers in {path}. ",
|
66
|
+
count=deleted_blocks,
|
67
|
+
path=path,
|
68
|
+
) + (f"\n{validation_result}" if validation_result else "")
|
69
|
+
except Exception as e:
|
70
|
+
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.REPLACE)
|
71
|
+
return tr("Error deleting text: {error}", error=e)
|
72
|
+
|
73
|
+
def _read_file_content(self, path):
|
74
|
+
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
75
|
+
return f.read()
|
76
|
+
|
77
|
+
def _find_marker_blocks(self, content, start_marker, end_marker):
|
78
|
+
"""Find all blocks between start_marker and end_marker, return count and starting line numbers."""
|
79
|
+
lines = content.splitlines(keepends=True)
|
80
|
+
joined = "".join(lines)
|
81
|
+
match_lines = []
|
82
|
+
idx = 0
|
83
|
+
occurrences = 0
|
84
|
+
while True:
|
85
|
+
start_idx = joined.find(start_marker, idx)
|
86
|
+
if start_idx == -1:
|
87
|
+
break
|
88
|
+
end_idx = joined.find(end_marker, start_idx + len(start_marker))
|
89
|
+
if end_idx == -1:
|
90
|
+
break
|
91
|
+
upto = joined[:start_idx]
|
92
|
+
line_no = upto.count("\n") + 1
|
93
|
+
match_lines.append(line_no)
|
94
|
+
idx = end_idx + len(end_marker)
|
95
|
+
occurrences += 1
|
96
|
+
return occurrences, match_lines
|
97
|
+
|
98
|
+
def _delete_blocks(self, content, start_marker, end_marker):
|
99
|
+
"""Delete all blocks between start_marker and end_marker (inclusive)."""
|
100
|
+
count = 0
|
101
|
+
new_content = content
|
102
|
+
while True:
|
103
|
+
start_idx = new_content.find(start_marker)
|
104
|
+
if start_idx == -1:
|
105
|
+
break
|
106
|
+
end_idx = new_content.find(end_marker, start_idx + len(start_marker))
|
107
|
+
if end_idx == -1:
|
108
|
+
break
|
109
|
+
new_content = (
|
110
|
+
new_content[:start_idx] + new_content[end_idx + len(end_marker) :]
|
111
|
+
)
|
112
|
+
count += 1
|
113
|
+
return new_content, count
|
114
|
+
|
115
|
+
def _backup_file(self, path, backup_path):
|
116
|
+
shutil.copy2(path, backup_path)
|
117
|
+
|
118
|
+
def _write_file_content(self, path, content):
|
119
|
+
with open(path, "w", encoding="utf-8", errors="replace") as f:
|
120
|
+
f.write(content)
|
121
|
+
|
122
|
+
def _report_success(self, match_lines):
|
123
|
+
if match_lines:
|
124
|
+
lines_str = ", ".join(str(line_no) for line_no in match_lines)
|
125
|
+
self.report_success(
|
126
|
+
tr(
|
127
|
+
" ✅ deleted block(s) starting at line(s): {lines_str}",
|
128
|
+
lines_str=lines_str,
|
129
|
+
),
|
130
|
+
ReportAction.CREATE,
|
131
|
+
)
|
132
|
+
else:
|
133
|
+
self.report_success(
|
134
|
+
tr(" ✅ deleted block(s) (lines unknown)"), ReportAction.CREATE
|
135
|
+
)
|
@@ -0,0 +1,143 @@
|
|
1
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
+
from janito.report_events import ReportAction
|
3
|
+
from janito.tools.adapters.local.adapter import register_local_tool
|
4
|
+
from janito.tools.tool_utils import pluralize, display_path
|
5
|
+
from janito.dir_walk_utils import walk_dir_with_gitignore
|
6
|
+
from janito.i18n import tr
|
7
|
+
import fnmatch
|
8
|
+
import os
|
9
|
+
from janito.tools.path_utils import expand_path
|
10
|
+
from janito.tools.loop_protection_decorator import protect_against_loops
|
11
|
+
|
12
|
+
|
13
|
+
@register_local_tool
|
14
|
+
class FindFilesTool(ToolBase):
|
15
|
+
"""
|
16
|
+
Find files or directories in one or more directories matching a pattern. Respects .gitignore.
|
17
|
+
|
18
|
+
If a path is an existing file, it is checked against the provided pattern(s) and included in the results if it matches. This allows find_files to be used to look for a specific set of filenames in a single call, as well as searching directories.
|
19
|
+
|
20
|
+
Args:
|
21
|
+
paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
|
22
|
+
pattern (str): File pattern(s) to match. Multiple patterns can be separated by spaces. Uses Unix shell-style wildcards (fnmatch), e.g. '*.py', 'data_??.csv', '[a-z]*.txt'.
|
23
|
+
- If the pattern ends with '/' or '\', only matching directory names (with trailing slash) are returned, not the files within those directories. For example, pattern '*/' will return only directories at the specified depth.
|
24
|
+
max_depth (int, optional): Maximum directory depth to search. If None, unlimited recursion. If 0, only the top-level directory. If 1, only the root directory (matches 'find . -maxdepth 1').
|
25
|
+
include_gitignored (bool, optional): If True, includes files/directories ignored by .gitignore. Defaults to False.
|
26
|
+
Returns:
|
27
|
+
str: Newline-separated list of matching file paths. Example:
|
28
|
+
"/path/to/file1.py\n/path/to/file2.py"
|
29
|
+
"Warning: Empty file pattern provided. Operation skipped."
|
30
|
+
"""
|
31
|
+
|
32
|
+
permissions = ToolPermissions(read=True)
|
33
|
+
tool_name = "find_files"
|
34
|
+
|
35
|
+
def _match_directories(self, root, dirs, pat):
|
36
|
+
dir_output = set()
|
37
|
+
dir_pat = pat.rstrip("/\\")
|
38
|
+
for d in dirs:
|
39
|
+
if fnmatch.fnmatch(d, dir_pat):
|
40
|
+
dir_output.add(os.path.join(root, d) + os.sep)
|
41
|
+
return dir_output
|
42
|
+
|
43
|
+
def _match_files(self, root, files, pat):
|
44
|
+
file_output = set()
|
45
|
+
for filename in fnmatch.filter(files, pat):
|
46
|
+
file_output.add(os.path.join(root, filename))
|
47
|
+
return file_output
|
48
|
+
|
49
|
+
def _match_dirs_without_slash(self, root, dirs, pat):
|
50
|
+
dir_output = set()
|
51
|
+
for d in fnmatch.filter(dirs, pat):
|
52
|
+
dir_output.add(os.path.join(root, d))
|
53
|
+
return dir_output
|
54
|
+
|
55
|
+
def _handle_path(self, directory, patterns):
|
56
|
+
dir_output = set()
|
57
|
+
filename = os.path.basename(directory)
|
58
|
+
for pat in patterns:
|
59
|
+
# Only match files, not directories, for file paths
|
60
|
+
if not (pat.endswith("/") or pat.endswith("\\")):
|
61
|
+
if fnmatch.fnmatch(filename, pat):
|
62
|
+
dir_output.add(directory)
|
63
|
+
break
|
64
|
+
return dir_output
|
65
|
+
|
66
|
+
def _handle_directory_path(
|
67
|
+
self, directory, patterns, max_depth, include_gitignored
|
68
|
+
):
|
69
|
+
dir_output = set()
|
70
|
+
for root, dirs, files in walk_dir_with_gitignore(
|
71
|
+
directory,
|
72
|
+
max_depth=max_depth,
|
73
|
+
include_gitignored=include_gitignored,
|
74
|
+
):
|
75
|
+
for pat in patterns:
|
76
|
+
if pat.endswith("/") or pat.endswith("\\"):
|
77
|
+
dir_output.update(self._match_directories(root, dirs, pat))
|
78
|
+
else:
|
79
|
+
dir_output.update(self._match_files(root, files, pat))
|
80
|
+
dir_output.update(self._match_dirs_without_slash(root, dirs, pat))
|
81
|
+
return dir_output
|
82
|
+
|
83
|
+
def _report_search(self, pattern, disp_path, depth_msg):
|
84
|
+
self.report_action(
|
85
|
+
tr(
|
86
|
+
"🔍 Search for files '{pattern}' in '{disp_path}'{depth_msg} ...",
|
87
|
+
pattern=pattern,
|
88
|
+
disp_path=disp_path,
|
89
|
+
depth_msg=depth_msg,
|
90
|
+
),
|
91
|
+
ReportAction.READ,
|
92
|
+
)
|
93
|
+
|
94
|
+
def _report_success(self, count):
|
95
|
+
self.report_success(
|
96
|
+
tr(
|
97
|
+
" ✅ {count} {file_word}",
|
98
|
+
count=count,
|
99
|
+
file_word=pluralize("file", count),
|
100
|
+
),
|
101
|
+
ReportAction.READ,
|
102
|
+
)
|
103
|
+
|
104
|
+
def _format_output(self, directory, dir_output):
|
105
|
+
if directory.strip() == ".":
|
106
|
+
dir_output = {
|
107
|
+
p[2:] if (p.startswith("./") or p.startswith(".\\")) else p
|
108
|
+
for p in dir_output
|
109
|
+
}
|
110
|
+
return sorted(dir_output)
|
111
|
+
|
112
|
+
@protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
|
113
|
+
def run(
|
114
|
+
self,
|
115
|
+
paths: str,
|
116
|
+
pattern: str,
|
117
|
+
max_depth: int = None,
|
118
|
+
include_gitignored: bool = False,
|
119
|
+
) -> str:
|
120
|
+
if not pattern:
|
121
|
+
self.report_warning(tr("ℹ️ Empty file pattern provided."), ReportAction.READ)
|
122
|
+
return tr("Warning: Empty file pattern provided. Operation skipped.")
|
123
|
+
patterns = pattern.split()
|
124
|
+
results = []
|
125
|
+
for directory in [expand_path(p) for p in paths.split()]:
|
126
|
+
disp_path = display_path(directory)
|
127
|
+
depth_msg = (
|
128
|
+
tr(" (max depth: {max_depth})", max_depth=max_depth)
|
129
|
+
if max_depth is not None and max_depth > 0
|
130
|
+
else ""
|
131
|
+
)
|
132
|
+
self._report_search(pattern, disp_path, depth_msg)
|
133
|
+
dir_output = set()
|
134
|
+
if os.path.isfile(directory):
|
135
|
+
dir_output = self._handle_path(directory, patterns)
|
136
|
+
elif os.path.isdir(directory):
|
137
|
+
dir_output = self._handle_directory_path(
|
138
|
+
directory, patterns, max_depth, include_gitignored
|
139
|
+
)
|
140
|
+
self._report_success(len(dir_output))
|
141
|
+
results.extend(self._format_output(directory, dir_output))
|
142
|
+
result = "\n".join(results)
|
143
|
+
return result
|