janito 2.3.0__py3-none-any.whl → 2.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. janito/__init__.py +6 -6
  2. janito/cli/chat_mode/shell/autocomplete.py +21 -21
  3. janito/cli/chat_mode/shell/commands/clear.py +12 -12
  4. janito/cli/chat_mode/shell/commands/multi.py +51 -51
  5. janito/cli/chat_mode/shell/input_history.py +62 -62
  6. janito/cli/cli_commands/list_models.py +35 -35
  7. janito/cli/cli_commands/list_providers.py +9 -9
  8. janito/cli/cli_commands/list_tools.py +53 -53
  9. janito/cli/cli_commands/model_selection.py +50 -50
  10. janito/cli/cli_commands/model_utils.py +95 -95
  11. janito/cli/cli_commands/set_api_key.py +19 -19
  12. janito/cli/cli_commands/show_config.py +51 -51
  13. janito/cli/cli_commands/show_system_prompt.py +62 -62
  14. janito/cli/core/__init__.py +4 -4
  15. janito/cli/core/event_logger.py +59 -59
  16. janito/cli/core/getters.py +33 -33
  17. janito/cli/core/unsetters.py +54 -54
  18. janito/cli/single_shot_mode/__init__.py +6 -6
  19. janito/config.py +5 -5
  20. janito/config_manager.py +112 -112
  21. janito/drivers/anthropic/driver.py +113 -113
  22. janito/formatting_token.py +54 -54
  23. janito/i18n/__init__.py +35 -35
  24. janito/i18n/messages.py +23 -23
  25. janito/i18n/pt.py +47 -47
  26. janito/llm/__init__.py +5 -5
  27. janito/llm/agent.py +443 -443
  28. janito/llm/auth.py +63 -63
  29. janito/llm/driver_config_builder.py +34 -34
  30. janito/llm/driver_input.py +12 -12
  31. janito/llm/message_parts.py +60 -60
  32. janito/llm/model.py +38 -38
  33. janito/llm/provider.py +196 -196
  34. janito/provider_registry.py +176 -176
  35. janito/providers/anthropic/model_info.py +22 -22
  36. janito/providers/anthropic/provider.py +2 -0
  37. janito/providers/azure_openai/model_info.py +16 -16
  38. janito/providers/azure_openai/provider.py +3 -0
  39. janito/providers/deepseek/__init__.py +1 -1
  40. janito/providers/deepseek/model_info.py +16 -16
  41. janito/providers/deepseek/provider.py +94 -91
  42. janito/providers/google/provider.py +3 -0
  43. janito/providers/mistralai/provider.py +3 -0
  44. janito/providers/openai/provider.py +4 -0
  45. janito/tools/adapters/__init__.py +1 -1
  46. janito/tools/adapters/local/ask_user.py +102 -102
  47. janito/tools/adapters/local/copy_file.py +84 -84
  48. janito/tools/adapters/local/create_directory.py +69 -69
  49. janito/tools/adapters/local/create_file.py +82 -82
  50. janito/tools/adapters/local/fetch_url.py +97 -97
  51. janito/tools/adapters/local/find_files.py +138 -138
  52. janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
  53. janito/tools/adapters/local/get_file_outline/core.py +117 -117
  54. janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
  55. janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
  56. janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
  57. janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
  58. janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
  59. janito/tools/adapters/local/python_code_run.py +166 -166
  60. janito/tools/adapters/local/python_command_run.py +164 -164
  61. janito/tools/adapters/local/python_file_run.py +163 -163
  62. janito/tools/adapters/local/run_bash_command.py +176 -176
  63. janito/tools/adapters/local/run_powershell_command.py +219 -219
  64. janito/tools/adapters/local/search_text/__init__.py +1 -1
  65. janito/tools/adapters/local/search_text/core.py +201 -201
  66. janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
  67. janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
  68. janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
  69. janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
  70. janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
  71. janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
  72. janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
  73. janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
  74. janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
  75. janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
  76. janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
  77. janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
  78. janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
  79. janito/tools/adapters/local/view_file.py +167 -167
  80. janito/tools/inspect_registry.py +17 -17
  81. janito/tools/tool_base.py +105 -105
  82. janito/tools/tool_events.py +58 -58
  83. janito/tools/tool_run_exception.py +12 -12
  84. janito/tools/tool_use_tracker.py +81 -81
  85. janito/tools/tool_utils.py +45 -45
  86. janito/tools/tools_schema.py +104 -104
  87. janito/version.py +4 -4
  88. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/METADATA +390 -388
  89. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/RECORD +93 -93
  90. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/WHEEL +0 -0
  91. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/entry_points.txt +0 -0
  92. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/licenses/LICENSE +0 -0
  93. {janito-2.3.0.dist-info → janito-2.3.1.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