janito 3.1.0__py3-none-any.whl → 3.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. janito/cli/chat_mode/bindings.py +0 -26
  2. janito/cli/chat_mode/session.py +1 -7
  3. janito/cli/cli_commands/list_plugins.py +8 -13
  4. janito/cli/prompt_core.py +9 -19
  5. janito/llm/agent.py +17 -30
  6. janito/llm/driver.py +0 -7
  7. janito/plugins/__init__.py +21 -29
  8. janito/plugins/__main__.py +85 -0
  9. janito/plugins/base.py +57 -0
  10. janito/plugins/builtin.py +1 -1
  11. janito/plugins/core/filemanager/tools/copy_file.py +25 -1
  12. janito/plugins/core/filemanager/tools/create_directory.py +28 -1
  13. janito/plugins/core/filemanager/tools/create_file.py +25 -1
  14. janito/plugins/core/filemanager/tools/delete_text_in_file.py +1 -0
  15. janito/plugins/core/imagedisplay/plugin.py +1 -1
  16. janito/plugins/core_loader.py +144 -0
  17. janito/plugins/discovery.py +3 -3
  18. janito/plugins/example_plugin.py +1 -1
  19. janito/plugins/manager.py +1 -1
  20. janito/plugins_backup_20250825_070018/__init__.py +36 -0
  21. janito/plugins_backup_20250825_070018/builtin.py +102 -0
  22. janito/plugins_backup_20250825_070018/config.py +84 -0
  23. janito/plugins_backup_20250825_070018/core/__init__.py +7 -0
  24. janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +43 -0
  25. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +1 -0
  26. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +122 -0
  27. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +1 -0
  28. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +205 -0
  29. janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +124 -0
  30. janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +87 -0
  31. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +70 -0
  32. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +87 -0
  33. janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +135 -0
  34. janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +143 -0
  35. janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +131 -0
  36. janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +58 -0
  37. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +55 -0
  38. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +58 -0
  39. janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +270 -0
  40. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +1 -0
  41. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +114 -0
  42. janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +172 -0
  43. janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +14 -0
  44. janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +51 -0
  45. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +1 -0
  46. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +83 -0
  47. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +84 -0
  48. janito/plugins_backup_20250825_070018/core/system/__init__.py +23 -0
  49. janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +183 -0
  50. janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +218 -0
  51. janito/plugins_backup_20250825_070018/dev/__init__.py +7 -0
  52. janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +37 -0
  53. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +172 -0
  54. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +171 -0
  55. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +172 -0
  56. janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +23 -0
  57. janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +259 -0
  58. janito/plugins_backup_20250825_070018/discovery.py +289 -0
  59. janito/plugins_backup_20250825_070018/example_plugin.py +108 -0
  60. janito/plugins_backup_20250825_070018/manager.py +243 -0
  61. janito/{plugins → plugins_backup_20250825_070018}/tools/delete_text_in_file.py +1 -0
  62. janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +47 -0
  63. janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +14 -0
  64. janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +303 -0
  65. janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +36 -0
  66. janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +67 -0
  67. janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +73 -0
  68. janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +145 -0
  69. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +35 -0
  70. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +100 -0
  71. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +50 -0
  72. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +27 -0
  73. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +6 -0
  74. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +109 -0
  75. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +32 -0
  76. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +5 -0
  77. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +11 -0
  78. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +6 -0
  79. janito/plugins_backup_20250825_070018/ui/__init__.py +7 -0
  80. janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +16 -0
  81. janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +110 -0
  82. janito/plugins_backup_20250825_070018/web/__init__.py +7 -0
  83. janito/plugins_backup_20250825_070018/web/webtools/__init__.py +33 -0
  84. janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +458 -0
  85. janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +51 -0
  86. janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +37 -0
  87. janito/tools/base.py +31 -1
  88. janito/tools/cli_initializer.py +1 -1
  89. janito/tools/function_adapter.py +35 -1
  90. janito/tools/initialize.py +1 -1
  91. janito/tools/tool_base.py +142 -114
  92. janito/tools/tools_schema.py +12 -6
  93. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/METADATA +1 -1
  94. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/RECORD +154 -87
  95. janito/llm/cancellation_manager.py +0 -62
  96. janito/llm/enter_cancellation.py +0 -93
  97. /janito/{plugin_system → plugin_system_backup_20250825_070018}/__init__.py +0 -0
  98. /janito/{plugin_system → plugin_system_backup_20250825_070018}/base.py +0 -0
  99. /janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader.py +0 -0
  100. /janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader_fixed.py +0 -0
  101. /janito/{plugins → plugins_backup_20250825_070018}/auto_loader.py +0 -0
  102. /janito/{plugins → plugins_backup_20250825_070018}/auto_loader_fixed.py +0 -0
  103. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/java_outline.py +0 -0
  104. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/markdown_outline.py +0 -0
  105. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/python_outline.py +0 -0
  106. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/search_outline.py +0 -0
  107. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/match_lines.py +0 -0
  108. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/pattern_utils.py +0 -0
  109. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/traverse_directory.py +0 -0
  110. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/css_validator.py +0 -0
  111. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/html_validator.py +0 -0
  112. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/jinja2_validator.py +0 -0
  113. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/js_validator.py +0 -0
  114. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/json_validator.py +0 -0
  115. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/markdown_validator.py +0 -0
  116. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/ps1_validator.py +0 -0
  117. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/python_validator.py +0 -0
  118. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/xml_validator.py +0 -0
  119. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/yaml_validator.py +0 -0
  120. /janito/{plugins → plugins_backup_20250825_070018}/core_adapter.py +0 -0
  121. /janito/{plugins → plugins_backup_20250825_070018}/discovery_core.py +0 -0
  122. /janito/{plugins → plugins_backup_20250825_070018}/tools/__init__.py +0 -0
  123. /janito/{plugins → plugins_backup_20250825_070018}/tools/ask_user.py +0 -0
  124. /janito/{plugins → plugins_backup_20250825_070018}/tools/copy_file.py +0 -0
  125. /janito/{plugins → plugins_backup_20250825_070018}/tools/core_tools_plugin.py +0 -0
  126. /janito/{plugins → plugins_backup_20250825_070018}/tools/create_directory.py +0 -0
  127. /janito/{plugins → plugins_backup_20250825_070018}/tools/create_file.py +0 -0
  128. /janito/{plugins → plugins_backup_20250825_070018}/tools/decorators.py +0 -0
  129. /janito/{plugins → plugins_backup_20250825_070018}/tools/fetch_url.py +0 -0
  130. /janito/{plugins → plugins_backup_20250825_070018}/tools/find_files.py +0 -0
  131. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/__init__.py +0 -0
  132. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/core.py +0 -0
  133. /janito/{plugins → plugins_backup_20250825_070018}/tools/move_file.py +0 -0
  134. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_html_in_browser.py +0 -0
  135. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_url.py +0 -0
  136. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_code_run.py +0 -0
  137. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_command_run.py +0 -0
  138. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_file_run.py +0 -0
  139. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_chart.py +0 -0
  140. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_files.py +0 -0
  141. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_directory.py +0 -0
  142. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_file.py +0 -0
  143. /janito/{plugins → plugins_backup_20250825_070018}/tools/replace_text_in_file.py +0 -0
  144. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_bash_command.py +0 -0
  145. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_powershell_command.py +0 -0
  146. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/__init__.py +0 -0
  147. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/core.py +0 -0
  148. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image.py +0 -0
  149. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image_grid.py +0 -0
  150. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/__init__.py +0 -0
  151. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/core.py +0 -0
  152. /janito/{plugins → plugins_backup_20250825_070018}/tools/view_file.py +0 -0
  153. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/WHEEL +0 -0
  154. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/entry_points.txt +0 -0
  155. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/licenses/LICENSE +0 -0
  156. {janito-3.1.0.dist-info → janito-3.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,67 @@
1
+ import re
2
+ from janito.gitignore_utils import GitignoreFilter
3
+ import os
4
+
5
+
6
+ def is_binary_file(path, blocksize=1024):
7
+ try:
8
+ with open(path, "rb") as f:
9
+ chunk = f.read(blocksize)
10
+ if b"\0" in chunk:
11
+ return True
12
+ text_characters = bytearray(
13
+ {7, 8, 9, 10, 12, 13, 27} | set(range(0x20, 0x100))
14
+ )
15
+ nontext = chunk.translate(None, text_characters)
16
+ if len(nontext) / max(1, len(chunk)) > 0.3:
17
+ return True
18
+ except Exception:
19
+ return True
20
+ return False
21
+
22
+
23
+ def match_line(line, query, regex, use_regex, case_sensitive):
24
+ if use_regex:
25
+ return regex and regex.search(line)
26
+ if not case_sensitive:
27
+ return query.lower() in line.lower()
28
+ return query in line
29
+
30
+
31
+ def should_limit(max_results, total_results, match_count, count_only, dir_output):
32
+ if max_results > 0:
33
+ current_count = total_results + (match_count if count_only else len(dir_output))
34
+ return current_count >= max_results
35
+ return False
36
+
37
+
38
+ def read_file_lines(
39
+ path,
40
+ query,
41
+ regex,
42
+ use_regex,
43
+ case_sensitive,
44
+ count_only,
45
+ max_results,
46
+ total_results,
47
+ ):
48
+ dir_output = []
49
+ dir_limit_reached = False
50
+ match_count = 0
51
+ if not is_binary_file(path):
52
+ try:
53
+ open_kwargs = {"mode": "r", "encoding": "utf-8"}
54
+ with open(path, **open_kwargs) as f:
55
+ for lineno, line in enumerate(f, 1):
56
+ if match_line(line, query, regex, use_regex, case_sensitive):
57
+ match_count += 1
58
+ if not count_only:
59
+ dir_output.append(f"{path}:{lineno}: {line.rstrip()}")
60
+ if should_limit(
61
+ max_results, total_results, match_count, count_only, dir_output
62
+ ):
63
+ dir_limit_reached = True
64
+ break
65
+ except Exception:
66
+ pass
67
+ return match_count, dir_limit_reached, dir_output
@@ -0,0 +1,73 @@
1
+ import re
2
+ from janito.i18n import tr
3
+ from janito.tools.tool_utils import pluralize
4
+
5
+
6
+ def prepare_pattern(pattern, is_regex, case_sensitive, report_error, report_warning):
7
+ if not pattern:
8
+ report_error(
9
+ tr("Error: Empty search pattern provided. Operation aborted."),
10
+ ReportAction.SEARCH,
11
+ )
12
+ return (
13
+ None,
14
+ False,
15
+ tr("Error: Empty search pattern provided. Operation aborted."),
16
+ )
17
+ regex = None
18
+ use_regex = False
19
+ if is_regex:
20
+ try:
21
+ flags = 0
22
+ if not case_sensitive:
23
+ flags |= re.IGNORECASE
24
+ regex = re.compile(pattern, flags=flags)
25
+ use_regex = True
26
+ except re.error as e:
27
+ report_warning(tr("⚠️ Invalid regex pattern."))
28
+ return (
29
+ None,
30
+ False,
31
+ tr(
32
+ "Error: Invalid regex pattern: {error}. Operation aborted.", error=e
33
+ ),
34
+ )
35
+ else:
36
+ # Do not compile as regex if is_regex is False; treat as plain text
37
+ regex = None
38
+ use_regex = False
39
+ if not case_sensitive:
40
+ pattern = pattern.lower()
41
+ return regex, use_regex, None
42
+
43
+
44
+ def format_result(
45
+ query, use_regex, output, limit_reached, count_only=False, per_file_counts=None
46
+ ):
47
+ # Ensure output is always a list for joining
48
+ if output is None or not isinstance(output, (list, tuple)):
49
+ output = []
50
+ if count_only:
51
+ lines = []
52
+ total = 0
53
+ if per_file_counts:
54
+ for path, count in per_file_counts:
55
+ lines.append(f"{path}: {count}")
56
+ total += count
57
+ lines.append(f"Total matches: {total}")
58
+ if limit_reached:
59
+ lines.append(tr("[Max results reached. Output truncated.]"))
60
+ return "\n".join(lines)
61
+ else:
62
+ if not output:
63
+ return tr("No matches found.")
64
+ result = "\n".join(output)
65
+ if limit_reached:
66
+ result += tr("\n[Max results reached. Output truncated.]")
67
+ return result
68
+
69
+
70
+ def summarize_total(all_per_file_counts):
71
+ total = sum(count for _, count in all_per_file_counts)
72
+ summary = f"\nGrand total matches: {total}"
73
+ return summary
@@ -0,0 +1,145 @@
1
+ import os
2
+ from janito.gitignore_utils import GitignoreFilter
3
+ from .match_lines import match_line, should_limit, read_file_lines
4
+
5
+
6
+ def walk_directory(search_path, max_depth):
7
+ if max_depth == 1:
8
+ walk_result = next(os.walk(search_path), None)
9
+ if walk_result is None:
10
+ return [(search_path, [], [])]
11
+ else:
12
+ return [walk_result]
13
+ else:
14
+ return os.walk(search_path)
15
+
16
+
17
+ def filter_dirs(dirs, root, gitignore_filter):
18
+ # Always exclude directories named .git, regardless of gitignore
19
+ return [
20
+ d
21
+ for d in dirs
22
+ if d != ".git" and not gitignore_filter.is_ignored(os.path.join(root, d))
23
+ ]
24
+
25
+
26
+ def process_file_count_only(
27
+ path,
28
+ per_file_counts,
29
+ query,
30
+ regex,
31
+ use_regex,
32
+ case_sensitive,
33
+ max_results,
34
+ total_results,
35
+ ):
36
+ match_count, file_limit_reached, _ = read_file_lines(
37
+ path,
38
+ query,
39
+ regex,
40
+ use_regex,
41
+ case_sensitive,
42
+ True,
43
+ max_results,
44
+ total_results + sum(count for _, count in per_file_counts),
45
+ )
46
+ if match_count > 0:
47
+ per_file_counts.append((path, match_count))
48
+ return file_limit_reached
49
+
50
+
51
+ def process_file_collect(
52
+ path,
53
+ dir_output,
54
+ per_file_counts,
55
+ query,
56
+ regex,
57
+ use_regex,
58
+ case_sensitive,
59
+ max_results,
60
+ total_results,
61
+ ):
62
+ actual_match_count, file_limit_reached, file_lines_output = read_file_lines(
63
+ path,
64
+ query,
65
+ regex,
66
+ use_regex,
67
+ case_sensitive,
68
+ False,
69
+ max_results,
70
+ total_results + len(dir_output),
71
+ )
72
+ dir_output.extend(file_lines_output)
73
+ if actual_match_count > 0:
74
+ per_file_counts.append((path, actual_match_count))
75
+ return file_limit_reached
76
+
77
+
78
+ def should_limit_depth(root, search_path, max_depth, dirs):
79
+ if max_depth > 0:
80
+ rel_root = os.path.relpath(root, search_path)
81
+ if rel_root != ".":
82
+ depth = rel_root.count(os.sep) + 1
83
+ if depth >= max_depth:
84
+ del dirs[:]
85
+
86
+
87
+ def traverse_directory(
88
+ search_path,
89
+ query,
90
+ regex,
91
+ use_regex,
92
+ case_sensitive,
93
+ max_depth,
94
+ max_results,
95
+ total_results,
96
+ count_only,
97
+ ):
98
+ dir_output = []
99
+ dir_limit_reached = False
100
+ per_file_counts = []
101
+ walker = walk_directory(search_path, max_depth)
102
+ gitignore_filter = GitignoreFilter(search_path)
103
+
104
+ for root, dirs, files in walker:
105
+ dirs[:] = filter_dirs(dirs, root, gitignore_filter)
106
+ for file in files:
107
+ path = os.path.join(root, file)
108
+ if gitignore_filter.is_ignored(path):
109
+ continue
110
+ if count_only:
111
+ file_limit_reached = process_file_count_only(
112
+ path,
113
+ per_file_counts,
114
+ query,
115
+ regex,
116
+ use_regex,
117
+ case_sensitive,
118
+ max_results,
119
+ total_results,
120
+ )
121
+ if file_limit_reached:
122
+ dir_limit_reached = True
123
+ break
124
+ else:
125
+ file_limit_reached = process_file_collect(
126
+ path,
127
+ dir_output,
128
+ per_file_counts,
129
+ query,
130
+ regex,
131
+ use_regex,
132
+ case_sensitive,
133
+ max_results,
134
+ total_results,
135
+ )
136
+ if file_limit_reached:
137
+ dir_limit_reached = True
138
+ break
139
+ if dir_limit_reached:
140
+ break
141
+ should_limit_depth(root, search_path, max_depth, dirs)
142
+ if count_only:
143
+ return per_file_counts, dir_limit_reached, []
144
+ else:
145
+ return dir_output, dir_limit_reached, per_file_counts
@@ -0,0 +1,35 @@
1
+ from janito.i18n import tr
2
+ import re
3
+
4
+
5
+ def validate_css(path: str) -> str:
6
+ with open(path, "r", encoding="utf-8") as f:
7
+ content = f.read()
8
+ errors = []
9
+ # Check for unmatched curly braces
10
+ if content.count("{") != content.count("}"):
11
+ errors.append("Unmatched curly braces { }")
12
+ # Check for unclosed comments
13
+ if content.count("/*") != content.count("*/"):
14
+ errors.append("Unclosed comment (/* ... */)")
15
+ # Check for invalid property declarations (very basic)
16
+ for i, line in enumerate(content.splitlines(), 1):
17
+ # Ignore empty lines and comments
18
+ if not line.strip() or line.strip().startswith("/*"):
19
+ continue
20
+ # Match property: value; (allow whitespace)
21
+ if ":" in line and not re.search(r":.*;", line):
22
+ errors.append(
23
+ f"Line {i}: Missing semicolon after property value | {line.strip()}"
24
+ )
25
+ # Match lines with property but missing colon
26
+ if ";" in line and ":" not in line:
27
+ errors.append(
28
+ f"Line {i}: Missing colon in property declaration | {line.strip()}"
29
+ )
30
+ if errors:
31
+ msg = tr(
32
+ "⚠️ Warning: CSS syntax issues found:\n{errors}", errors="\n".join(errors)
33
+ )
34
+ return msg
35
+ return "✅ OK"
@@ -0,0 +1,100 @@
1
+ from janito.i18n import tr
2
+ import re
3
+
4
+ try:
5
+ from lxml import etree
6
+ except ImportError:
7
+ etree = None
8
+
9
+
10
+ def validate_html(path: str) -> str:
11
+ html_content = _read_html_content(path)
12
+ warnings = _find_js_outside_script(html_content)
13
+ lxml_error = _parse_html_and_collect_errors(path)
14
+ msg = _build_result_message(warnings, lxml_error)
15
+ return msg
16
+
17
+
18
+ def _read_html_content(path):
19
+ with open(path, "r", encoding="utf-8") as f:
20
+ return f.read()
21
+
22
+
23
+ def _find_js_outside_script(html_content):
24
+ script_blocks = [
25
+ m.span()
26
+ for m in re.finditer(
27
+ r"<script[\s\S]*?>[\s\S]*?<\/script>", html_content, re.IGNORECASE
28
+ )
29
+ ]
30
+ js_patterns = [
31
+ r"document\.addEventListener",
32
+ r"^\s*(var|let|const)\s+\w+\s*[=;]",
33
+ r"^\s*function\s+\w+\s*\(",
34
+ r"^\s*(const|let|var)\s+\w+\s*=\s*\(.*\)\s*=>",
35
+ r"^\s*window\.\w+\s*=",
36
+ r"^\s*\$\s*\(",
37
+ ]
38
+ warnings = []
39
+ for pat in js_patterns:
40
+ for m in re.finditer(pat, html_content):
41
+ in_script = False
42
+ for s_start, s_end in script_blocks:
43
+ if s_start <= m.start() < s_end:
44
+ in_script = True
45
+ break
46
+ if not in_script:
47
+ warnings.append(
48
+ f"Line {html_content.count(chr(10), 0, m.start())+1}: JavaScript code ('{pat}') found outside <script> tag."
49
+ )
50
+ return warnings
51
+
52
+
53
+ def _parse_html_and_collect_errors(path):
54
+ lxml_error = None
55
+ if etree is None:
56
+ lxml_error = tr("⚠️ lxml not installed. Cannot validate HTML.")
57
+ return lxml_error
58
+ try:
59
+ parser = etree.HTMLParser(recover=False)
60
+ with open(path, "rb") as f:
61
+ etree.parse(f, parser=parser)
62
+ error_log = parser.error_log
63
+ syntax_errors = []
64
+ for e in error_log:
65
+ if (
66
+ "mismatch" in e.message.lower()
67
+ or "tag not closed" in e.message.lower()
68
+ or "unexpected end tag" in e.message.lower()
69
+ or "expected" in e.message.lower()
70
+ ):
71
+ syntax_errors.append(str(e))
72
+ if syntax_errors:
73
+ lxml_error = tr("Syntax error: {error}", error="; ".join(syntax_errors))
74
+ elif error_log:
75
+ lxml_error = tr(
76
+ "HTML syntax errors found:\n{errors}",
77
+ errors="\n".join(str(e) for e in error_log),
78
+ )
79
+ except ImportError:
80
+ lxml_error = tr("⚠️ lxml not installed. Cannot validate HTML.")
81
+ except Exception as e:
82
+ lxml_error = tr("Syntax error: {error}", error=str(e))
83
+ return lxml_error
84
+
85
+
86
+ def _build_result_message(warnings, lxml_error):
87
+ msg = ""
88
+ if warnings:
89
+ msg += (
90
+ tr(
91
+ "⚠️ Warning: JavaScript code found outside <script> tags. This is invalid HTML and will not execute in browsers.\n"
92
+ + "\n".join(warnings)
93
+ )
94
+ + "\n"
95
+ )
96
+ if lxml_error:
97
+ msg += lxml_error
98
+ if msg:
99
+ return msg.strip()
100
+ return "✅ OK"
@@ -0,0 +1,50 @@
1
+ """Jinja2 template syntax validator."""
2
+
3
+ import os
4
+ from janito.i18n import tr
5
+
6
+
7
+ def validate_jinja2(path: str) -> str:
8
+ """Validate Jinja2 template syntax."""
9
+ try:
10
+ from jinja2 import Environment, TemplateSyntaxError
11
+
12
+ with open(path, "r", encoding="utf-8") as f:
13
+ content = f.read()
14
+
15
+ # Create a Jinja2 environment and try to parse the template
16
+ env = Environment()
17
+ try:
18
+ env.parse(content)
19
+ return tr("✅ Syntax OK")
20
+ except TemplateSyntaxError as e:
21
+ line_num = getattr(e, "lineno", 0)
22
+ return tr(
23
+ "⚠️ Warning: Syntax error: {error} at line {line}",
24
+ error=str(e),
25
+ line=line_num,
26
+ )
27
+ except Exception as e:
28
+ return tr("⚠️ Warning: Syntax error: {error}", error=str(e))
29
+
30
+ except ImportError:
31
+ # If jinja2 is not available, just check basic structure
32
+ try:
33
+ with open(path, "r", encoding="utf-8") as f:
34
+ content = f.read()
35
+
36
+ # Basic checks for common Jinja2 syntax issues
37
+ open_tags = content.count("{%")
38
+ close_tags = content.count("%}")
39
+ open_vars = content.count("{{")
40
+ close_vars = content.count("}}")
41
+
42
+ if open_tags != close_tags:
43
+ return tr("⚠️ Warning: Syntax error: Mismatched Jinja2 tags")
44
+ if open_vars != close_vars:
45
+ return tr("⚠️ Warning: Syntax error: Mismatched Jinja2 variables")
46
+
47
+ return tr("✅ Syntax OK (basic validation)")
48
+
49
+ except Exception as e:
50
+ return tr("⚠️ Warning: Syntax error: {error}", error=str(e))
@@ -0,0 +1,27 @@
1
+ from janito.i18n import tr
2
+ import re
3
+
4
+
5
+ def validate_js(path: str) -> str:
6
+ with open(path, "r", encoding="utf-8") as f:
7
+ content = f.read()
8
+ errors = []
9
+ if content.count("{") != content.count("}"):
10
+ errors.append("Unmatched curly braces { }")
11
+ if content.count("(") != content.count(")"):
12
+ errors.append("Unmatched parentheses ( )")
13
+ if content.count("[") != content.count("]"):
14
+ errors.append("Unmatched brackets [ ]")
15
+ for quote in ["'", '"', "`"]:
16
+ unescaped = re.findall(rf"(?<!\\){quote}", content)
17
+ if len(unescaped) % 2 != 0:
18
+ errors.append(f"Unclosed string literal ({quote}) detected")
19
+ if content.count("/*") != content.count("*/"):
20
+ errors.append("Unclosed block comment (/* ... */)")
21
+ if errors:
22
+ msg = tr(
23
+ "⚠️ Warning: JavaScript syntax issues found:\n{errors}",
24
+ errors="\n".join(errors),
25
+ )
26
+ return msg
27
+ return "✅ OK"
@@ -0,0 +1,6 @@
1
+ def validate_json(path: str) -> str:
2
+ import json
3
+
4
+ with open(path, "r", encoding="utf-8") as f:
5
+ json.load(f)
6
+ return "✅ OK"
@@ -0,0 +1,109 @@
1
+ from janito.i18n import tr
2
+ import re
3
+
4
+
5
+ def validate_markdown(path: str) -> str:
6
+ with open(path, "r", encoding="utf-8") as f:
7
+ content = f.read()
8
+ lines = content.splitlines()
9
+ errors = []
10
+ errors.extend(_check_header_space(lines))
11
+ errors.extend(_check_unclosed_code_block(content))
12
+ errors.extend(_check_unclosed_links_images(lines))
13
+ errors.extend(_check_list_formatting(lines))
14
+ errors.extend(_check_unclosed_inline_code(content))
15
+ return _build_markdown_result(errors)
16
+
17
+
18
+ def _check_header_space(lines):
19
+ errors = []
20
+ for i, line in enumerate(lines, 1):
21
+ if re.match(r"^#+[^ #]", line):
22
+ errors.append(f"Line {i}: Header missing space after # | {line.strip()}")
23
+ return errors
24
+
25
+
26
+ def _check_unclosed_code_block(content):
27
+ errors = []
28
+ if content.count("```") % 2 != 0:
29
+ errors.append("Unclosed code block (```) detected")
30
+ return errors
31
+
32
+
33
+ def _check_unclosed_links_images(lines):
34
+ errors = []
35
+ for i, line in enumerate(lines, 1):
36
+ if re.search(r"\[[^\]]*\]\([^)]+$", line):
37
+ errors.append(
38
+ f"Line {i}: Unclosed link or image (missing closing parenthesis) | {line.strip()}"
39
+ )
40
+ return errors
41
+
42
+
43
+ def _is_table_line(line):
44
+ return line.lstrip().startswith("|")
45
+
46
+
47
+ def _list_item_missing_space(line):
48
+ return re.match(r"^[-*+][^ \n]", line)
49
+
50
+
51
+ def _should_skip_list_item(line):
52
+ stripped = line.strip()
53
+ return stripped.startswith("*") and stripped.endswith("*") and len(stripped) > 2
54
+
55
+
56
+ def _needs_blank_line_before_bullet(lines, i):
57
+ if i <= 1:
58
+ return False
59
+ prev_line = lines[i - 2]
60
+ prev_is_list = bool(re.match(r"^\s*[-*+] ", prev_line))
61
+ return not prev_is_list and prev_line.strip() != ""
62
+
63
+
64
+ def _needs_blank_line_before_numbered(lines, i):
65
+ if i <= 1:
66
+ return False
67
+ prev_line = lines[i - 2]
68
+ prev_is_numbered_list = bool(re.match(r"^\s*\d+\. ", prev_line))
69
+ return not prev_is_numbered_list and prev_line.strip() != ""
70
+
71
+
72
+ def _check_list_formatting(lines):
73
+ errors = []
74
+ for i, line in enumerate(lines, 1):
75
+ if _is_table_line(line):
76
+ continue
77
+ if _list_item_missing_space(line):
78
+ if not _should_skip_list_item(line):
79
+ errors.append(
80
+ f"Line {i}: List item missing space after bullet | {line.strip()}"
81
+ )
82
+ if re.match(r"^\s*[-*+] ", line):
83
+ if _needs_blank_line_before_bullet(lines, i):
84
+ errors.append(
85
+ f"Line {i}: List should be preceded by a blank line for compatibility with MkDocs and other Markdown parsers | {line.strip()}"
86
+ )
87
+ if re.match(r"^\s*\d+\. ", line):
88
+ if _needs_blank_line_before_numbered(lines, i):
89
+ errors.append(
90
+ f"Line {i}: Numbered list should be preceded by a blank line for compatibility with MkDocs and other Markdown parsers | {line.strip()}"
91
+ )
92
+ return errors
93
+
94
+
95
+ def _check_unclosed_inline_code(content):
96
+ errors = []
97
+ if content.count("`") % 2 != 0:
98
+ errors.append("Unclosed inline code (`) detected")
99
+ return errors
100
+
101
+
102
+ def _build_markdown_result(errors):
103
+ if errors:
104
+ msg = tr(
105
+ "⚠️ Warning: Markdown syntax issues found:\n{errors}",
106
+ errors="\n".join(errors),
107
+ )
108
+ return msg
109
+ return "✅ OK"
@@ -0,0 +1,32 @@
1
+ from janito.i18n import tr
2
+ import re
3
+
4
+
5
+ def validate_ps1(path: str) -> str:
6
+ with open(path, "r", encoding="utf-8") as f:
7
+ content = f.read()
8
+ errors = []
9
+ # Unmatched curly braces
10
+ if content.count("{") != content.count("}"):
11
+ errors.append("Unmatched curly braces { }")
12
+ # Unmatched parentheses
13
+ if content.count("(") != content.count(")"):
14
+ errors.append("Unmatched parentheses ( )")
15
+ # Unmatched brackets
16
+ if content.count("[") != content.count("]"):
17
+ errors.append("Unmatched brackets [ ]")
18
+ # Unclosed string literals
19
+ for quote in ["'", '"']:
20
+ unescaped = re.findall(rf"(?<!\\){quote}", content)
21
+ if len(unescaped) % 2 != 0:
22
+ errors.append(f"Unclosed string literal ({quote}) detected")
23
+ # Unclosed block comments <# ... #>
24
+ if content.count("<#") != content.count("#>"):
25
+ errors.append("Unclosed block comment (<# ... #>)")
26
+ if errors:
27
+ msg = tr(
28
+ "⚠️ Warning: PowerShell syntax issues found:\n{errors}",
29
+ errors="\n".join(errors),
30
+ )
31
+ return msg
32
+ return "✅ OK"
@@ -0,0 +1,5 @@
1
+ def validate_python(path: str) -> str:
2
+ import py_compile
3
+
4
+ py_compile.compile(path, doraise=True)
5
+ return "✅ OK"
@@ -0,0 +1,11 @@
1
+ from janito.i18n import tr
2
+
3
+
4
+ def validate_xml(path: str) -> str:
5
+ try:
6
+ from lxml import etree
7
+ except ImportError:
8
+ return tr("⚠️ lxml not installed. Cannot validate XML.")
9
+ with open(path, "rb") as f:
10
+ etree.parse(f)
11
+ return "✅ OK"
@@ -0,0 +1,6 @@
1
+ def validate_yaml(path: str) -> str:
2
+ import yaml
3
+
4
+ with open(path, "r", encoding="utf-8") as f:
5
+ yaml.safe_load(f)
6
+ return "✅ OK"
@@ -0,0 +1,7 @@
1
+ """
2
+ User Interface Plugin Package
3
+
4
+ Contains user interaction and interface tools.
5
+ """
6
+
7
+ __all__ = ["userinterface"]