janito 2.2.0__py3-none-any.whl → 2.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/__init__.py +6 -6
- janito/agent/setup_agent.py +14 -5
- janito/agent/templates/profiles/system_prompt_template_main.txt.j2 +3 -1
- janito/cli/chat_mode/bindings.py +6 -0
- janito/cli/chat_mode/session.py +16 -0
- janito/cli/chat_mode/shell/autocomplete.py +21 -21
- janito/cli/chat_mode/shell/commands/__init__.py +3 -0
- janito/cli/chat_mode/shell/commands/clear.py +12 -12
- janito/cli/chat_mode/shell/commands/exec.py +27 -0
- janito/cli/chat_mode/shell/commands/multi.py +51 -51
- janito/cli/chat_mode/shell/commands/tools.py +17 -6
- janito/cli/chat_mode/shell/input_history.py +62 -62
- janito/cli/chat_mode/shell/session/manager.py +1 -0
- janito/cli/chat_mode/toolbar.py +1 -0
- janito/cli/cli_commands/list_models.py +35 -35
- janito/cli/cli_commands/list_providers.py +9 -9
- janito/cli/cli_commands/list_tools.py +53 -53
- janito/cli/cli_commands/model_selection.py +50 -50
- janito/cli/cli_commands/model_utils.py +13 -2
- janito/cli/cli_commands/set_api_key.py +19 -19
- janito/cli/cli_commands/show_config.py +51 -51
- janito/cli/cli_commands/show_system_prompt.py +62 -62
- janito/cli/config.py +2 -1
- janito/cli/core/__init__.py +4 -4
- janito/cli/core/event_logger.py +59 -59
- janito/cli/core/getters.py +3 -1
- janito/cli/core/runner.py +165 -148
- janito/cli/core/setters.py +5 -1
- janito/cli/core/unsetters.py +54 -54
- janito/cli/main_cli.py +12 -1
- janito/cli/prompt_core.py +5 -2
- janito/cli/rich_terminal_reporter.py +22 -3
- janito/cli/single_shot_mode/__init__.py +6 -6
- janito/cli/single_shot_mode/handler.py +11 -1
- janito/cli/verbose_output.py +1 -1
- janito/config.py +5 -5
- janito/config_manager.py +2 -0
- janito/driver_events.py +14 -0
- janito/drivers/anthropic/driver.py +113 -113
- janito/drivers/azure_openai/driver.py +38 -3
- janito/drivers/driver_registry.py +0 -2
- janito/drivers/openai/driver.py +196 -36
- janito/formatting_token.py +54 -54
- janito/i18n/__init__.py +35 -35
- janito/i18n/messages.py +23 -23
- janito/i18n/pt.py +47 -47
- janito/llm/__init__.py +5 -5
- janito/llm/agent.py +443 -443
- janito/llm/auth.py +1 -0
- janito/llm/driver.py +7 -1
- janito/llm/driver_config.py +1 -0
- janito/llm/driver_config_builder.py +34 -34
- janito/llm/driver_input.py +12 -12
- janito/llm/message_parts.py +60 -60
- janito/llm/model.py +38 -38
- janito/llm/provider.py +196 -196
- janito/provider_config.py +7 -3
- janito/provider_registry.py +176 -158
- janito/providers/__init__.py +1 -0
- janito/providers/anthropic/model_info.py +22 -22
- janito/providers/anthropic/provider.py +2 -2
- janito/providers/azure_openai/model_info.py +7 -6
- janito/providers/azure_openai/provider.py +30 -2
- janito/providers/deepseek/__init__.py +1 -1
- janito/providers/deepseek/model_info.py +16 -16
- janito/providers/deepseek/provider.py +91 -91
- janito/providers/google/model_info.py +21 -29
- janito/providers/google/provider.py +49 -38
- janito/providers/mistralai/provider.py +2 -2
- janito/providers/provider_static_info.py +2 -3
- janito/tools/adapters/__init__.py +1 -1
- janito/tools/adapters/local/adapter.py +33 -11
- janito/tools/adapters/local/ask_user.py +102 -102
- janito/tools/adapters/local/copy_file.py +84 -84
- janito/tools/adapters/local/create_directory.py +69 -69
- janito/tools/adapters/local/create_file.py +82 -82
- janito/tools/adapters/local/delete_text_in_file.py +4 -7
- janito/tools/adapters/local/fetch_url.py +97 -97
- janito/tools/adapters/local/find_files.py +138 -138
- janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
- janito/tools/adapters/local/get_file_outline/core.py +117 -117
- janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
- janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
- janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
- janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
- janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
- janito/tools/adapters/local/move_file.py +3 -13
- janito/tools/adapters/local/python_code_run.py +166 -166
- janito/tools/adapters/local/python_command_run.py +164 -164
- janito/tools/adapters/local/python_file_run.py +163 -163
- janito/tools/adapters/local/remove_directory.py +6 -17
- janito/tools/adapters/local/remove_file.py +4 -10
- janito/tools/adapters/local/replace_text_in_file.py +6 -9
- janito/tools/adapters/local/run_bash_command.py +176 -176
- janito/tools/adapters/local/run_powershell_command.py +219 -219
- janito/tools/adapters/local/search_text/__init__.py +1 -1
- janito/tools/adapters/local/search_text/core.py +201 -201
- janito/tools/adapters/local/search_text/match_lines.py +1 -1
- janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
- janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
- janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
- janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
- janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
- janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
- janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
- janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
- janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
- janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
- janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
- janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
- janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
- janito/tools/adapters/local/view_file.py +167 -167
- janito/tools/inspect_registry.py +17 -17
- janito/tools/tool_base.py +105 -105
- janito/tools/tool_events.py +58 -58
- janito/tools/tool_run_exception.py +12 -12
- janito/tools/tool_use_tracker.py +81 -81
- janito/tools/tool_utils.py +45 -45
- janito/tools/tools_adapter.py +78 -6
- janito/tools/tools_schema.py +104 -104
- janito/version.py +4 -4
- {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/METADATA +388 -251
- janito-2.3.0.dist-info/RECORD +181 -0
- janito/drivers/google_genai/driver.py +0 -54
- janito/drivers/google_genai/schema_generator.py +0 -67
- janito-2.2.0.dist-info/RECORD +0 -182
- {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/WHEEL +0 -0
- {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/entry_points.txt +0 -0
- {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/top_level.txt +0 -0
@@ -1,138 +1,138 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase
|
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
|
-
|
10
|
-
|
11
|
-
@register_local_tool
|
12
|
-
class FindFilesTool(ToolBase):
|
13
|
-
"""
|
14
|
-
Find files or directories in one or more directories matching a pattern. Respects .gitignore.
|
15
|
-
|
16
|
-
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.
|
17
|
-
|
18
|
-
Args:
|
19
|
-
paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
|
20
|
-
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'.
|
21
|
-
- 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.
|
22
|
-
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').
|
23
|
-
include_gitignored (bool, optional): If True, includes files/directories ignored by .gitignore. Defaults to False.
|
24
|
-
Returns:
|
25
|
-
str: Newline-separated list of matching file paths. Example:
|
26
|
-
"/path/to/file1.py\n/path/to/file2.py"
|
27
|
-
"Warning: Empty file pattern provided. Operation skipped."
|
28
|
-
"""
|
29
|
-
|
30
|
-
tool_name = "find_files"
|
31
|
-
|
32
|
-
def _match_directories(self, root, dirs, pat):
|
33
|
-
dir_output = set()
|
34
|
-
dir_pat = pat.rstrip("/\\")
|
35
|
-
for d in dirs:
|
36
|
-
if fnmatch.fnmatch(d, dir_pat):
|
37
|
-
dir_output.add(os.path.join(root, d) + os.sep)
|
38
|
-
return dir_output
|
39
|
-
|
40
|
-
def _match_files(self, root, files, pat):
|
41
|
-
file_output = set()
|
42
|
-
for filename in fnmatch.filter(files, pat):
|
43
|
-
file_output.add(os.path.join(root, filename))
|
44
|
-
return file_output
|
45
|
-
|
46
|
-
def _match_dirs_without_slash(self, root, dirs, pat):
|
47
|
-
dir_output = set()
|
48
|
-
for d in fnmatch.filter(dirs, pat):
|
49
|
-
dir_output.add(os.path.join(root, d))
|
50
|
-
return dir_output
|
51
|
-
|
52
|
-
def _handle_file_path(self, directory, patterns):
|
53
|
-
dir_output = set()
|
54
|
-
filename = os.path.basename(directory)
|
55
|
-
for pat in patterns:
|
56
|
-
# Only match files, not directories, for file paths
|
57
|
-
if not (pat.endswith("/") or pat.endswith("\\")):
|
58
|
-
if fnmatch.fnmatch(filename, pat):
|
59
|
-
dir_output.add(directory)
|
60
|
-
break
|
61
|
-
return dir_output
|
62
|
-
|
63
|
-
def _handle_directory_path(self, directory, patterns, max_depth, include_gitignored):
|
64
|
-
dir_output = set()
|
65
|
-
for root, dirs, files in walk_dir_with_gitignore(
|
66
|
-
directory,
|
67
|
-
max_depth=max_depth,
|
68
|
-
include_gitignored=include_gitignored,
|
69
|
-
):
|
70
|
-
for pat in patterns:
|
71
|
-
if pat.endswith("/") or pat.endswith("\\"):
|
72
|
-
dir_output.update(self._match_directories(root, dirs, pat))
|
73
|
-
else:
|
74
|
-
dir_output.update(self._match_files(root, files, pat))
|
75
|
-
dir_output.update(
|
76
|
-
self._match_dirs_without_slash(root, dirs, pat)
|
77
|
-
)
|
78
|
-
return dir_output
|
79
|
-
|
80
|
-
def _report_search(self, pattern, disp_path, depth_msg):
|
81
|
-
self.report_action(
|
82
|
-
tr(
|
83
|
-
"🔍 Search for files '{pattern}' in '{disp_path}'{depth_msg} ...",
|
84
|
-
pattern=pattern,
|
85
|
-
disp_path=disp_path,
|
86
|
-
depth_msg=depth_msg,
|
87
|
-
),
|
88
|
-
ReportAction.READ,
|
89
|
-
)
|
90
|
-
|
91
|
-
def _report_success(self, count):
|
92
|
-
self.report_success(
|
93
|
-
tr(
|
94
|
-
" ✅ {count} {file_word}",
|
95
|
-
count=count,
|
96
|
-
file_word=pluralize("file", count),
|
97
|
-
),
|
98
|
-
ReportAction.READ,
|
99
|
-
)
|
100
|
-
|
101
|
-
def _format_output(self, directory, dir_output):
|
102
|
-
if directory.strip() == ".":
|
103
|
-
dir_output = {
|
104
|
-
p[2:] if (p.startswith("./") or p.startswith(".\\")) else p
|
105
|
-
for p in dir_output
|
106
|
-
}
|
107
|
-
return sorted(dir_output)
|
108
|
-
|
109
|
-
def run(
|
110
|
-
self,
|
111
|
-
paths: str,
|
112
|
-
pattern: str,
|
113
|
-
max_depth: int = None,
|
114
|
-
include_gitignored: bool = False,
|
115
|
-
) -> str:
|
116
|
-
if not pattern:
|
117
|
-
self.report_warning(tr("ℹ️ Empty file pattern provided."), ReportAction.READ)
|
118
|
-
return tr("Warning: Empty file pattern provided. Operation skipped.")
|
119
|
-
patterns = pattern.split()
|
120
|
-
results = []
|
121
|
-
for directory in paths.split():
|
122
|
-
disp_path = display_path(directory)
|
123
|
-
depth_msg = (
|
124
|
-
tr(" (max depth: {max_depth})", max_depth=max_depth)
|
125
|
-
if max_depth is not None and max_depth > 0
|
126
|
-
else ""
|
127
|
-
)
|
128
|
-
self._report_search(pattern, disp_path, depth_msg)
|
129
|
-
dir_output = set()
|
130
|
-
if os.path.isfile(directory):
|
131
|
-
dir_output = self._handle_file_path(directory, patterns)
|
132
|
-
elif os.path.isdir(directory):
|
133
|
-
dir_output = self._handle_directory_path(directory, patterns, max_depth, include_gitignored)
|
134
|
-
self._report_success(len(dir_output))
|
135
|
-
results.extend(self._format_output(directory, dir_output))
|
136
|
-
result = "\n".join(results)
|
137
|
-
return result
|
138
|
-
|
1
|
+
from janito.tools.tool_base import ToolBase
|
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
|
+
|
10
|
+
|
11
|
+
@register_local_tool
|
12
|
+
class FindFilesTool(ToolBase):
|
13
|
+
"""
|
14
|
+
Find files or directories in one or more directories matching a pattern. Respects .gitignore.
|
15
|
+
|
16
|
+
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.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
paths (str): String of one or more paths (space-separated) to search in. Each path can be a directory or a file.
|
20
|
+
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'.
|
21
|
+
- 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.
|
22
|
+
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').
|
23
|
+
include_gitignored (bool, optional): If True, includes files/directories ignored by .gitignore. Defaults to False.
|
24
|
+
Returns:
|
25
|
+
str: Newline-separated list of matching file paths. Example:
|
26
|
+
"/path/to/file1.py\n/path/to/file2.py"
|
27
|
+
"Warning: Empty file pattern provided. Operation skipped."
|
28
|
+
"""
|
29
|
+
|
30
|
+
tool_name = "find_files"
|
31
|
+
|
32
|
+
def _match_directories(self, root, dirs, pat):
|
33
|
+
dir_output = set()
|
34
|
+
dir_pat = pat.rstrip("/\\")
|
35
|
+
for d in dirs:
|
36
|
+
if fnmatch.fnmatch(d, dir_pat):
|
37
|
+
dir_output.add(os.path.join(root, d) + os.sep)
|
38
|
+
return dir_output
|
39
|
+
|
40
|
+
def _match_files(self, root, files, pat):
|
41
|
+
file_output = set()
|
42
|
+
for filename in fnmatch.filter(files, pat):
|
43
|
+
file_output.add(os.path.join(root, filename))
|
44
|
+
return file_output
|
45
|
+
|
46
|
+
def _match_dirs_without_slash(self, root, dirs, pat):
|
47
|
+
dir_output = set()
|
48
|
+
for d in fnmatch.filter(dirs, pat):
|
49
|
+
dir_output.add(os.path.join(root, d))
|
50
|
+
return dir_output
|
51
|
+
|
52
|
+
def _handle_file_path(self, directory, patterns):
|
53
|
+
dir_output = set()
|
54
|
+
filename = os.path.basename(directory)
|
55
|
+
for pat in patterns:
|
56
|
+
# Only match files, not directories, for file paths
|
57
|
+
if not (pat.endswith("/") or pat.endswith("\\")):
|
58
|
+
if fnmatch.fnmatch(filename, pat):
|
59
|
+
dir_output.add(directory)
|
60
|
+
break
|
61
|
+
return dir_output
|
62
|
+
|
63
|
+
def _handle_directory_path(self, directory, patterns, max_depth, include_gitignored):
|
64
|
+
dir_output = set()
|
65
|
+
for root, dirs, files in walk_dir_with_gitignore(
|
66
|
+
directory,
|
67
|
+
max_depth=max_depth,
|
68
|
+
include_gitignored=include_gitignored,
|
69
|
+
):
|
70
|
+
for pat in patterns:
|
71
|
+
if pat.endswith("/") or pat.endswith("\\"):
|
72
|
+
dir_output.update(self._match_directories(root, dirs, pat))
|
73
|
+
else:
|
74
|
+
dir_output.update(self._match_files(root, files, pat))
|
75
|
+
dir_output.update(
|
76
|
+
self._match_dirs_without_slash(root, dirs, pat)
|
77
|
+
)
|
78
|
+
return dir_output
|
79
|
+
|
80
|
+
def _report_search(self, pattern, disp_path, depth_msg):
|
81
|
+
self.report_action(
|
82
|
+
tr(
|
83
|
+
"🔍 Search for files '{pattern}' in '{disp_path}'{depth_msg} ...",
|
84
|
+
pattern=pattern,
|
85
|
+
disp_path=disp_path,
|
86
|
+
depth_msg=depth_msg,
|
87
|
+
),
|
88
|
+
ReportAction.READ,
|
89
|
+
)
|
90
|
+
|
91
|
+
def _report_success(self, count):
|
92
|
+
self.report_success(
|
93
|
+
tr(
|
94
|
+
" ✅ {count} {file_word}",
|
95
|
+
count=count,
|
96
|
+
file_word=pluralize("file", count),
|
97
|
+
),
|
98
|
+
ReportAction.READ,
|
99
|
+
)
|
100
|
+
|
101
|
+
def _format_output(self, directory, dir_output):
|
102
|
+
if directory.strip() == ".":
|
103
|
+
dir_output = {
|
104
|
+
p[2:] if (p.startswith("./") or p.startswith(".\\")) else p
|
105
|
+
for p in dir_output
|
106
|
+
}
|
107
|
+
return sorted(dir_output)
|
108
|
+
|
109
|
+
def run(
|
110
|
+
self,
|
111
|
+
paths: str,
|
112
|
+
pattern: str,
|
113
|
+
max_depth: int = None,
|
114
|
+
include_gitignored: bool = False,
|
115
|
+
) -> str:
|
116
|
+
if not pattern:
|
117
|
+
self.report_warning(tr("ℹ️ Empty file pattern provided."), ReportAction.READ)
|
118
|
+
return tr("Warning: Empty file pattern provided. Operation skipped.")
|
119
|
+
patterns = pattern.split()
|
120
|
+
results = []
|
121
|
+
for directory in paths.split():
|
122
|
+
disp_path = display_path(directory)
|
123
|
+
depth_msg = (
|
124
|
+
tr(" (max depth: {max_depth})", max_depth=max_depth)
|
125
|
+
if max_depth is not None and max_depth > 0
|
126
|
+
else ""
|
127
|
+
)
|
128
|
+
self._report_search(pattern, disp_path, depth_msg)
|
129
|
+
dir_output = set()
|
130
|
+
if os.path.isfile(directory):
|
131
|
+
dir_output = self._handle_file_path(directory, patterns)
|
132
|
+
elif os.path.isdir(directory):
|
133
|
+
dir_output = self._handle_directory_path(directory, patterns, max_depth, include_gitignored)
|
134
|
+
self._report_success(len(dir_output))
|
135
|
+
results.extend(self._format_output(directory, dir_output))
|
136
|
+
result = "\n".join(results)
|
137
|
+
return result
|
138
|
+
|
@@ -1 +1 @@
|
|
1
|
-
# Outline tools and parsers package
|
1
|
+
# Outline tools and parsers package
|
@@ -1,117 +1,117 @@
|
|
1
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
2
|
-
from .python_outline import parse_python_outline
|
3
|
-
from .markdown_outline import parse_markdown_outline
|
4
|
-
from janito.formatting import OutlineFormatter
|
5
|
-
from .java_outline import parse_java_outline
|
6
|
-
import os
|
7
|
-
from janito.tools.tool_base import ToolBase
|
8
|
-
from janito.report_events import ReportAction
|
9
|
-
from janito.tools.tool_utils import display_path, pluralize
|
10
|
-
from janito.i18n import tr
|
11
|
-
|
12
|
-
from janito.tools.adapters.local.adapter import register_local_tool as register_tool
|
13
|
-
|
14
|
-
|
15
|
-
@register_tool
|
16
|
-
class GetFileOutlineTool(ToolBase):
|
17
|
-
"""
|
18
|
-
Get an outline of a file's structure. Supports Python and Markdown files.
|
19
|
-
|
20
|
-
Args:
|
21
|
-
file_path (str): Path to the file to outline.
|
22
|
-
"""
|
23
|
-
|
24
|
-
tool_name = "get_file_outline"
|
25
|
-
|
26
|
-
def run(self, file_path: str) -> str:
|
27
|
-
try:
|
28
|
-
self.report_action(
|
29
|
-
tr(
|
30
|
-
"📄 Outline file '{disp_path}' ...",
|
31
|
-
disp_path=display_path(file_path),
|
32
|
-
),
|
33
|
-
ReportAction.READ,
|
34
|
-
)
|
35
|
-
ext = os.path.splitext(file_path)[1].lower()
|
36
|
-
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
37
|
-
lines = f.readlines()
|
38
|
-
return self._outline_by_extension(ext, lines)
|
39
|
-
except Exception as e:
|
40
|
-
self.report_error(
|
41
|
-
tr("❌ Error reading file: {error}", error=e),
|
42
|
-
ReportAction.READ,
|
43
|
-
)
|
44
|
-
return tr("Error reading file: {error}", error=e)
|
45
|
-
|
46
|
-
def _outline_by_extension(self, ext, lines):
|
47
|
-
if ext == ".py":
|
48
|
-
outline_items = parse_python_outline(lines)
|
49
|
-
outline_type = "python"
|
50
|
-
table = OutlineFormatter.format_outline_table(outline_items)
|
51
|
-
self.report_success(
|
52
|
-
tr(
|
53
|
-
"✅ Outlined {count} {item_word}",
|
54
|
-
count=len(outline_items),
|
55
|
-
item_word=pluralize("item", len(outline_items)),
|
56
|
-
),
|
57
|
-
ReportAction.READ,
|
58
|
-
)
|
59
|
-
return (
|
60
|
-
tr(
|
61
|
-
"Outline: {count} items ({outline_type})\n",
|
62
|
-
count=len(outline_items),
|
63
|
-
outline_type=outline_type,
|
64
|
-
)
|
65
|
-
+ table
|
66
|
-
)
|
67
|
-
elif ext == ".md":
|
68
|
-
outline_items = parse_markdown_outline(lines)
|
69
|
-
outline_type = "markdown"
|
70
|
-
table = OutlineFormatter.format_markdown_outline_table(outline_items)
|
71
|
-
self.report_success(
|
72
|
-
tr(
|
73
|
-
"✅ Outlined {count} {item_word}",
|
74
|
-
count=len(outline_items),
|
75
|
-
item_word=pluralize("item", len(outline_items)),
|
76
|
-
),
|
77
|
-
ReportAction.READ,
|
78
|
-
)
|
79
|
-
return (
|
80
|
-
tr(
|
81
|
-
"Outline: {count} items ({outline_type})\n",
|
82
|
-
count=len(outline_items),
|
83
|
-
outline_type=outline_type,
|
84
|
-
)
|
85
|
-
+ table
|
86
|
-
)
|
87
|
-
elif ext == ".java":
|
88
|
-
outline_items = parse_java_outline(lines)
|
89
|
-
outline_type = "java"
|
90
|
-
table = OutlineFormatter.format_outline_table(outline_items)
|
91
|
-
self.report_success(
|
92
|
-
tr(
|
93
|
-
"✅ Outlined {count} {item_word}",
|
94
|
-
count=len(outline_items),
|
95
|
-
item_word=pluralize("item", len(outline_items)),
|
96
|
-
),
|
97
|
-
ReportAction.READ,
|
98
|
-
)
|
99
|
-
return (
|
100
|
-
tr(
|
101
|
-
"Outline: {count} items ({outline_type})\n",
|
102
|
-
count=len(outline_items),
|
103
|
-
outline_type=outline_type,
|
104
|
-
)
|
105
|
-
+ table
|
106
|
-
)
|
107
|
-
else:
|
108
|
-
outline_type = "default"
|
109
|
-
self.report_success(
|
110
|
-
tr("✅ Outlined {count} items", count=len(lines)),
|
111
|
-
ReportAction.READ,
|
112
|
-
)
|
113
|
-
return tr(
|
114
|
-
"Outline: {count} lines ({outline_type})\nFile has {count} lines.",
|
115
|
-
count=len(lines),
|
116
|
-
outline_type=outline_type,
|
117
|
-
)
|
1
|
+
from janito.tools.adapters.local.adapter import register_local_tool
|
2
|
+
from .python_outline import parse_python_outline
|
3
|
+
from .markdown_outline import parse_markdown_outline
|
4
|
+
from janito.formatting import OutlineFormatter
|
5
|
+
from .java_outline import parse_java_outline
|
6
|
+
import os
|
7
|
+
from janito.tools.tool_base import ToolBase
|
8
|
+
from janito.report_events import ReportAction
|
9
|
+
from janito.tools.tool_utils import display_path, pluralize
|
10
|
+
from janito.i18n import tr
|
11
|
+
|
12
|
+
from janito.tools.adapters.local.adapter import register_local_tool as register_tool
|
13
|
+
|
14
|
+
|
15
|
+
@register_tool
|
16
|
+
class GetFileOutlineTool(ToolBase):
|
17
|
+
"""
|
18
|
+
Get an outline of a file's structure. Supports Python and Markdown files.
|
19
|
+
|
20
|
+
Args:
|
21
|
+
file_path (str): Path to the file to outline.
|
22
|
+
"""
|
23
|
+
|
24
|
+
tool_name = "get_file_outline"
|
25
|
+
|
26
|
+
def run(self, file_path: str) -> str:
|
27
|
+
try:
|
28
|
+
self.report_action(
|
29
|
+
tr(
|
30
|
+
"📄 Outline file '{disp_path}' ...",
|
31
|
+
disp_path=display_path(file_path),
|
32
|
+
),
|
33
|
+
ReportAction.READ,
|
34
|
+
)
|
35
|
+
ext = os.path.splitext(file_path)[1].lower()
|
36
|
+
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
37
|
+
lines = f.readlines()
|
38
|
+
return self._outline_by_extension(ext, lines)
|
39
|
+
except Exception as e:
|
40
|
+
self.report_error(
|
41
|
+
tr("❌ Error reading file: {error}", error=e),
|
42
|
+
ReportAction.READ,
|
43
|
+
)
|
44
|
+
return tr("Error reading file: {error}", error=e)
|
45
|
+
|
46
|
+
def _outline_by_extension(self, ext, lines):
|
47
|
+
if ext == ".py":
|
48
|
+
outline_items = parse_python_outline(lines)
|
49
|
+
outline_type = "python"
|
50
|
+
table = OutlineFormatter.format_outline_table(outline_items)
|
51
|
+
self.report_success(
|
52
|
+
tr(
|
53
|
+
"✅ Outlined {count} {item_word}",
|
54
|
+
count=len(outline_items),
|
55
|
+
item_word=pluralize("item", len(outline_items)),
|
56
|
+
),
|
57
|
+
ReportAction.READ,
|
58
|
+
)
|
59
|
+
return (
|
60
|
+
tr(
|
61
|
+
"Outline: {count} items ({outline_type})\n",
|
62
|
+
count=len(outline_items),
|
63
|
+
outline_type=outline_type,
|
64
|
+
)
|
65
|
+
+ table
|
66
|
+
)
|
67
|
+
elif ext == ".md":
|
68
|
+
outline_items = parse_markdown_outline(lines)
|
69
|
+
outline_type = "markdown"
|
70
|
+
table = OutlineFormatter.format_markdown_outline_table(outline_items)
|
71
|
+
self.report_success(
|
72
|
+
tr(
|
73
|
+
"✅ Outlined {count} {item_word}",
|
74
|
+
count=len(outline_items),
|
75
|
+
item_word=pluralize("item", len(outline_items)),
|
76
|
+
),
|
77
|
+
ReportAction.READ,
|
78
|
+
)
|
79
|
+
return (
|
80
|
+
tr(
|
81
|
+
"Outline: {count} items ({outline_type})\n",
|
82
|
+
count=len(outline_items),
|
83
|
+
outline_type=outline_type,
|
84
|
+
)
|
85
|
+
+ table
|
86
|
+
)
|
87
|
+
elif ext == ".java":
|
88
|
+
outline_items = parse_java_outline(lines)
|
89
|
+
outline_type = "java"
|
90
|
+
table = OutlineFormatter.format_outline_table(outline_items)
|
91
|
+
self.report_success(
|
92
|
+
tr(
|
93
|
+
"✅ Outlined {count} {item_word}",
|
94
|
+
count=len(outline_items),
|
95
|
+
item_word=pluralize("item", len(outline_items)),
|
96
|
+
),
|
97
|
+
ReportAction.READ,
|
98
|
+
)
|
99
|
+
return (
|
100
|
+
tr(
|
101
|
+
"Outline: {count} items ({outline_type})\n",
|
102
|
+
count=len(outline_items),
|
103
|
+
outline_type=outline_type,
|
104
|
+
)
|
105
|
+
+ table
|
106
|
+
)
|
107
|
+
else:
|
108
|
+
outline_type = "default"
|
109
|
+
self.report_success(
|
110
|
+
tr("✅ Outlined {count} items", count=len(lines)),
|
111
|
+
ReportAction.READ,
|
112
|
+
)
|
113
|
+
return tr(
|
114
|
+
"Outline: {count} lines ({outline_type})\nFile has {count} lines.",
|
115
|
+
count=len(lines),
|
116
|
+
outline_type=outline_type,
|
117
|
+
)
|
@@ -1,40 +1,40 @@
|
|
1
|
-
import re
|
2
|
-
from typing import List, Dict
|
3
|
-
|
4
|
-
def parse_java_outline(lines: List[str]) -> List[Dict]:
|
5
|
-
"""
|
6
|
-
Parses Java source code lines and extracts classes and methods with their signatures.
|
7
|
-
Returns a list of outline items: {type, name, return_type, parameters, generics, line}
|
8
|
-
"""
|
9
|
-
outline = []
|
10
|
-
class_pattern = re.compile(r"\bclass\s+(\w+)(\s*<[^>]+>)?")
|
11
|
-
# Match methods with or without visibility modifiers (including package-private)
|
12
|
-
method_pattern = re.compile(r"^(?:\s*(public|protected|private)\s+)?(?:static\s+)?([\w<>\[\]]+)\s+(\w+)\s*\(([^)]*)\)")
|
13
|
-
current_class = None
|
14
|
-
for idx, line in enumerate(lines, 1):
|
15
|
-
class_match = class_pattern.search(line)
|
16
|
-
if class_match:
|
17
|
-
class_name = class_match.group(1)
|
18
|
-
generics = class_match.group(2) or ""
|
19
|
-
outline.append({
|
20
|
-
"type": "class",
|
21
|
-
"name": class_name,
|
22
|
-
"generics": generics.strip("<>") if generics else None,
|
23
|
-
"line": idx
|
24
|
-
})
|
25
|
-
current_class = class_name
|
26
|
-
else:
|
27
|
-
method_match = method_pattern.search(line)
|
28
|
-
if method_match:
|
29
|
-
return_type = method_match.group(2)
|
30
|
-
method_name = method_match.group(3)
|
31
|
-
params = method_match.group(4)
|
32
|
-
outline.append({
|
33
|
-
"type": "method",
|
34
|
-
"class": current_class,
|
35
|
-
"name": method_name,
|
36
|
-
"return_type": return_type,
|
37
|
-
"parameters": params.strip(),
|
38
|
-
"line": idx
|
39
|
-
})
|
40
|
-
return outline
|
1
|
+
import re
|
2
|
+
from typing import List, Dict
|
3
|
+
|
4
|
+
def parse_java_outline(lines: List[str]) -> List[Dict]:
|
5
|
+
"""
|
6
|
+
Parses Java source code lines and extracts classes and methods with their signatures.
|
7
|
+
Returns a list of outline items: {type, name, return_type, parameters, generics, line}
|
8
|
+
"""
|
9
|
+
outline = []
|
10
|
+
class_pattern = re.compile(r"\bclass\s+(\w+)(\s*<[^>]+>)?")
|
11
|
+
# Match methods with or without visibility modifiers (including package-private)
|
12
|
+
method_pattern = re.compile(r"^(?:\s*(public|protected|private)\s+)?(?:static\s+)?([\w<>\[\]]+)\s+(\w+)\s*\(([^)]*)\)")
|
13
|
+
current_class = None
|
14
|
+
for idx, line in enumerate(lines, 1):
|
15
|
+
class_match = class_pattern.search(line)
|
16
|
+
if class_match:
|
17
|
+
class_name = class_match.group(1)
|
18
|
+
generics = class_match.group(2) or ""
|
19
|
+
outline.append({
|
20
|
+
"type": "class",
|
21
|
+
"name": class_name,
|
22
|
+
"generics": generics.strip("<>") if generics else None,
|
23
|
+
"line": idx
|
24
|
+
})
|
25
|
+
current_class = class_name
|
26
|
+
else:
|
27
|
+
method_match = method_pattern.search(line)
|
28
|
+
if method_match:
|
29
|
+
return_type = method_match.group(2)
|
30
|
+
method_name = method_match.group(3)
|
31
|
+
params = method_match.group(4)
|
32
|
+
outline.append({
|
33
|
+
"type": "method",
|
34
|
+
"class": current_class,
|
35
|
+
"name": method_name,
|
36
|
+
"return_type": return_type,
|
37
|
+
"parameters": params.strip(),
|
38
|
+
"line": idx
|
39
|
+
})
|
40
|
+
return outline
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import re
|
2
|
-
from typing import List
|
3
|
-
|
4
|
-
|
5
|
-
def parse_markdown_outline(lines: List[str]):
|
6
|
-
header_pat = re.compile(r"^(#+)\s+(.*)")
|
7
|
-
outline = []
|
8
|
-
for idx, line in enumerate(lines):
|
9
|
-
match = header_pat.match(line)
|
10
|
-
if match:
|
11
|
-
level = len(match.group(1))
|
12
|
-
title = match.group(2).strip()
|
13
|
-
outline.append({"level": level, "title": title, "line": idx + 1})
|
14
|
-
return outline
|
1
|
+
import re
|
2
|
+
from typing import List
|
3
|
+
|
4
|
+
|
5
|
+
def parse_markdown_outline(lines: List[str]):
|
6
|
+
header_pat = re.compile(r"^(#+)\s+(.*)")
|
7
|
+
outline = []
|
8
|
+
for idx, line in enumerate(lines):
|
9
|
+
match = header_pat.match(line)
|
10
|
+
if match:
|
11
|
+
level = len(match.group(1))
|
12
|
+
title = match.group(2).strip()
|
13
|
+
outline.append({"level": level, "title": title, "line": idx + 1})
|
14
|
+
return outline
|