janito 3.3.0__py3-none-any.whl → 3.5.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 +3 -0
- janito/cli/chat_mode/bindings.py +50 -0
- janito/cli/chat_mode/session.py +12 -1
- janito/cli/chat_mode/shell/commands/multi.py +5 -0
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +47 -33
- janito/cli/cli_commands/list_plugins.py +13 -8
- janito/cli/core/model_guesser.py +40 -24
- janito/cli/prompt_core.py +47 -9
- janito/cli/rich_terminal_reporter.py +2 -2
- janito/hello.txt +0 -0
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +32 -16
- janito/llm/cancellation_manager.py +63 -0
- janito/llm/driver.py +8 -0
- janito/llm/enter_cancellation.py +107 -0
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader.py +76 -3
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader_fixed.py +79 -3
- janito/plugins/__init__.py +29 -21
- janito/{plugins_backup_20250825_070018 → plugins}/auto_loader.py +12 -11
- janito/plugins/builtin.py +1 -1
- janito/plugins/core/filemanager/tools/copy_file.py +1 -25
- janito/plugins/core/filemanager/tools/create_directory.py +1 -28
- janito/plugins/core/filemanager/tools/create_file.py +3 -27
- janito/plugins/core/filemanager/tools/delete_text_in_file.py +0 -1
- janito/plugins/core/imagedisplay/plugin.py +1 -1
- janito/plugins/core_adapter.py +131 -0
- janito/plugins/discovery.py +3 -3
- janito/{plugins_backup_20250825_070018 → plugins}/discovery_core.py +14 -9
- janito/plugins/example_plugin.py +1 -1
- janito/plugins/manager.py +1 -1
- janito/{plugins_backup_20250825_070018 → plugins}/tools/core_tools_plugin.py +9 -10
- janito/{plugins_backup_20250825_070018 → plugins}/tools/create_file.py +2 -2
- janito/{plugins_backup_20250825_070018 → plugins}/tools/delete_text_in_file.py +0 -1
- janito/providers/__init__.py +1 -0
- janito/providers/together/__init__.py +1 -0
- janito/providers/together/model_info.py +69 -0
- janito/providers/together/provider.py +108 -0
- janito/tools/base.py +1 -31
- janito/tools/cli_initializer.py +1 -1
- janito/tools/initialize.py +1 -1
- janito/tools/loop_protection_decorator.py +114 -117
- janito/tools/tool_base.py +114 -142
- janito/tools/tools_schema.py +6 -12
- janito-3.5.0.dist-info/METADATA +229 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/RECORD +98 -162
- janito/plugins/__main__.py +0 -85
- janito/plugins/base.py +0 -57
- janito/plugins/core_loader.py +0 -144
- janito/plugins_backup_20250825_070018/__init__.py +0 -36
- janito/plugins_backup_20250825_070018/builtin.py +0 -102
- janito/plugins_backup_20250825_070018/config.py +0 -84
- janito/plugins_backup_20250825_070018/core/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +0 -43
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +0 -122
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +0 -205
- janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +0 -124
- janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +0 -70
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +0 -135
- janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +0 -143
- janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +0 -131
- janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +0 -55
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +0 -114
- janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +0 -172
- janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +0 -14
- janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +0 -51
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +0 -84
- janito/plugins_backup_20250825_070018/core/system/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +0 -183
- janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +0 -218
- janito/plugins_backup_20250825_070018/core_adapter.py +0 -55
- janito/plugins_backup_20250825_070018/dev/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +0 -37
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +0 -171
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +0 -259
- janito/plugins_backup_20250825_070018/discovery.py +0 -289
- janito/plugins_backup_20250825_070018/example_plugin.py +0 -108
- janito/plugins_backup_20250825_070018/manager.py +0 -243
- janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +0 -67
- janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +0 -73
- janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +0 -145
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins_backup_20250825_070018/ui/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +0 -16
- janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins_backup_20250825_070018/web/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/web/webtools/__init__.py +0 -33
- janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +0 -458
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +0 -51
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +0 -37
- janito/tools/function_adapter.py +0 -176
- janito-3.3.0.dist-info/METADATA +0 -83
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/__init__.py +0 -0
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/base.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/auto_loader_fixed.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/ask_user.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/copy_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/create_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/decorators.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/fetch_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/find_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/java_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/python_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/search_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/move_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_html_in_browser.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_code_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_command_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_file_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_chart.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/replace_text_in_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_bash_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_powershell_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/match_lines.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/pattern_utils.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/traverse_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image_grid.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/view_file.py +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/WHEEL +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/entry_points.txt +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/top_level.txt +0 -0
@@ -1,205 +0,0 @@
|
|
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.i18n import tr
|
6
|
-
import os
|
7
|
-
from janito.tools.path_utils import expand_path
|
8
|
-
from .pattern_utils import prepare_pattern, format_result, summarize_total
|
9
|
-
from .match_lines import read_file_lines
|
10
|
-
from .traverse_directory import traverse_directory
|
11
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
12
|
-
|
13
|
-
|
14
|
-
from janito.tools.adapters.local.adapter import register_local_tool as register_tool
|
15
|
-
|
16
|
-
|
17
|
-
@register_tool
|
18
|
-
class SearchTextTool(ToolBase):
|
19
|
-
"""
|
20
|
-
Search for a text query in all files within one or more directories or file paths and return matching lines or counts. Respects .gitignore.
|
21
|
-
Args:
|
22
|
-
paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
|
23
|
-
query (str): Text or regular expression to search for in files. Must not be empty. When use_regex=True, this is treated as a regex pattern; otherwise as plain text.
|
24
|
-
use_regex (bool): If True, treat query as a regular expression. If False, treat as plain text (default).
|
25
|
-
case_sensitive (bool): If False, perform a case-insensitive search. Default is True (case sensitive).
|
26
|
-
max_depth (int, optional): Maximum directory depth to search. If 0 (default), search is recursive with no depth limit. If >0, limits recursion to that depth. Setting max_depth=1 disables recursion (only top-level directory). Ignored for file paths.
|
27
|
-
max_results (int, optional): Maximum number of results to return. Defaults to 100. 0 means no limit.
|
28
|
-
count_only (bool): If True, return only the count of matches per file and total, not the matching lines. Default is False.
|
29
|
-
Returns:
|
30
|
-
str: If count_only is False, matching lines from files as a newline-separated string, each formatted as 'filepath:lineno: line'.
|
31
|
-
If count_only is True, returns per-file and total match counts.
|
32
|
-
If max_results is reached, appends a note to the output.
|
33
|
-
"""
|
34
|
-
|
35
|
-
permissions = ToolPermissions(read=True)
|
36
|
-
tool_name = "search_text"
|
37
|
-
|
38
|
-
def _handle_file(
|
39
|
-
self,
|
40
|
-
search_path,
|
41
|
-
query,
|
42
|
-
regex,
|
43
|
-
use_regex,
|
44
|
-
case_sensitive,
|
45
|
-
max_results,
|
46
|
-
total_results,
|
47
|
-
count_only,
|
48
|
-
):
|
49
|
-
if count_only:
|
50
|
-
match_count, dir_limit_reached, _ = read_file_lines(
|
51
|
-
search_path,
|
52
|
-
query,
|
53
|
-
regex,
|
54
|
-
use_regex,
|
55
|
-
case_sensitive,
|
56
|
-
True,
|
57
|
-
max_results,
|
58
|
-
total_results,
|
59
|
-
)
|
60
|
-
per_file_counts = [(search_path, match_count)] if match_count > 0 else []
|
61
|
-
return [], dir_limit_reached, per_file_counts
|
62
|
-
else:
|
63
|
-
dir_output, dir_limit_reached, match_count_list = read_file_lines(
|
64
|
-
search_path,
|
65
|
-
query,
|
66
|
-
regex,
|
67
|
-
use_regex,
|
68
|
-
case_sensitive,
|
69
|
-
False,
|
70
|
-
max_results,
|
71
|
-
total_results,
|
72
|
-
)
|
73
|
-
per_file_counts = (
|
74
|
-
[(search_path, len(match_count_list))]
|
75
|
-
if match_count_list and len(match_count_list) > 0
|
76
|
-
else []
|
77
|
-
)
|
78
|
-
return dir_output, dir_limit_reached, per_file_counts
|
79
|
-
|
80
|
-
def _handle_path(
|
81
|
-
self,
|
82
|
-
search_path,
|
83
|
-
query,
|
84
|
-
regex,
|
85
|
-
use_regex,
|
86
|
-
case_sensitive,
|
87
|
-
max_depth,
|
88
|
-
max_results,
|
89
|
-
total_results,
|
90
|
-
count_only,
|
91
|
-
):
|
92
|
-
info_str = tr(
|
93
|
-
"🔍 Search {search_type} '{query}' in '{disp_path}'",
|
94
|
-
search_type=("regex" if use_regex else "text"),
|
95
|
-
query=query,
|
96
|
-
disp_path=display_path(search_path),
|
97
|
-
)
|
98
|
-
if max_depth > 0:
|
99
|
-
info_str += tr(" [max_depth={max_depth}]", max_depth=max_depth)
|
100
|
-
if count_only:
|
101
|
-
info_str += " [count]"
|
102
|
-
self.report_action(info_str, ReportAction.READ)
|
103
|
-
if os.path.isfile(search_path):
|
104
|
-
dir_output, dir_limit_reached, per_file_counts = self._handle_file(
|
105
|
-
search_path,
|
106
|
-
query,
|
107
|
-
regex,
|
108
|
-
use_regex,
|
109
|
-
case_sensitive,
|
110
|
-
max_results,
|
111
|
-
total_results,
|
112
|
-
count_only,
|
113
|
-
)
|
114
|
-
else:
|
115
|
-
if count_only:
|
116
|
-
per_file_counts, dir_limit_reached, _ = traverse_directory(
|
117
|
-
search_path,
|
118
|
-
query,
|
119
|
-
regex,
|
120
|
-
use_regex,
|
121
|
-
case_sensitive,
|
122
|
-
max_depth,
|
123
|
-
max_results,
|
124
|
-
total_results,
|
125
|
-
True,
|
126
|
-
)
|
127
|
-
dir_output = []
|
128
|
-
else:
|
129
|
-
dir_output, dir_limit_reached, per_file_counts = traverse_directory(
|
130
|
-
search_path,
|
131
|
-
query,
|
132
|
-
regex,
|
133
|
-
use_regex,
|
134
|
-
case_sensitive,
|
135
|
-
max_depth,
|
136
|
-
max_results,
|
137
|
-
total_results,
|
138
|
-
False,
|
139
|
-
)
|
140
|
-
count = sum(count for _, count in per_file_counts)
|
141
|
-
file_word = pluralize("match", count)
|
142
|
-
num_files = len(per_file_counts)
|
143
|
-
file_label = pluralize("file", num_files)
|
144
|
-
file_word_max = file_word + (" (max)" if dir_limit_reached else "")
|
145
|
-
self.report_success(
|
146
|
-
tr(
|
147
|
-
" ✅ {count} {file_word}/{num_files} {file_label}",
|
148
|
-
count=count,
|
149
|
-
file_word=file_word_max,
|
150
|
-
num_files=num_files,
|
151
|
-
file_label=file_label,
|
152
|
-
),
|
153
|
-
ReportAction.READ,
|
154
|
-
)
|
155
|
-
return info_str, dir_output, dir_limit_reached, per_file_counts
|
156
|
-
|
157
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="paths")
|
158
|
-
def run(
|
159
|
-
self,
|
160
|
-
paths: str,
|
161
|
-
query: str,
|
162
|
-
use_regex: bool = False,
|
163
|
-
case_sensitive: bool = False,
|
164
|
-
max_depth: int = 0,
|
165
|
-
max_results: int = 100,
|
166
|
-
count_only: bool = False,
|
167
|
-
) -> str:
|
168
|
-
regex, use_regex, error_msg = prepare_pattern(
|
169
|
-
query, use_regex, case_sensitive, self.report_error, self.report_warning
|
170
|
-
)
|
171
|
-
if error_msg:
|
172
|
-
return error_msg
|
173
|
-
paths_list = [expand_path(p) for p in paths.split()]
|
174
|
-
results = []
|
175
|
-
all_per_file_counts = []
|
176
|
-
for search_path in paths_list:
|
177
|
-
info_str, dir_output, dir_limit_reached, per_file_counts = (
|
178
|
-
self._handle_path(
|
179
|
-
search_path,
|
180
|
-
query,
|
181
|
-
regex,
|
182
|
-
use_regex,
|
183
|
-
case_sensitive,
|
184
|
-
max_depth,
|
185
|
-
max_results,
|
186
|
-
0,
|
187
|
-
count_only,
|
188
|
-
)
|
189
|
-
)
|
190
|
-
if count_only:
|
191
|
-
all_per_file_counts.extend(per_file_counts)
|
192
|
-
result_str = format_result(
|
193
|
-
query,
|
194
|
-
use_regex,
|
195
|
-
dir_output,
|
196
|
-
dir_limit_reached,
|
197
|
-
count_only,
|
198
|
-
per_file_counts,
|
199
|
-
)
|
200
|
-
results.append(info_str + "\n" + result_str)
|
201
|
-
if dir_limit_reached:
|
202
|
-
break
|
203
|
-
if count_only:
|
204
|
-
results.append(summarize_total(all_per_file_counts))
|
205
|
-
return "\n\n".join(results)
|
@@ -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
|
-
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
|
-
)
|
@@ -1,70 +0,0 @@
|
|
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)
|
@@ -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
|
-
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
|
-
)
|