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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. janito/README.md +0 -3
  2. janito/cli/chat_mode/bindings.py +0 -26
  3. janito/cli/chat_mode/session.py +1 -12
  4. janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
  5. janito/cli/cli_commands/list_plugins.py +8 -13
  6. janito/cli/core/model_guesser.py +24 -40
  7. janito/cli/prompt_core.py +9 -20
  8. janito/i18n/it.py +46 -46
  9. janito/llm/agent.py +16 -32
  10. janito/llm/driver.py +0 -8
  11. janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader.py +3 -76
  12. janito/{plugin_system → plugin_system_backup_20250825_070018}/core_loader_fixed.py +3 -79
  13. janito/plugins/__init__.py +21 -29
  14. janito/plugins/__main__.py +85 -0
  15. janito/plugins/base.py +57 -0
  16. janito/plugins/builtin.py +1 -1
  17. janito/plugins/core/filemanager/tools/copy_file.py +25 -1
  18. janito/plugins/core/filemanager/tools/create_directory.py +28 -1
  19. janito/plugins/core/filemanager/tools/create_file.py +27 -3
  20. janito/plugins/core/filemanager/tools/delete_text_in_file.py +1 -0
  21. janito/plugins/core/imagedisplay/plugin.py +1 -1
  22. janito/plugins/core_loader.py +144 -0
  23. janito/plugins/discovery.py +3 -3
  24. janito/plugins/example_plugin.py +1 -1
  25. janito/plugins/manager.py +1 -1
  26. janito/plugins_backup_20250825_070018/__init__.py +36 -0
  27. janito/{plugins → plugins_backup_20250825_070018}/auto_loader.py +11 -12
  28. janito/plugins_backup_20250825_070018/builtin.py +102 -0
  29. janito/plugins_backup_20250825_070018/config.py +84 -0
  30. janito/plugins_backup_20250825_070018/core/__init__.py +7 -0
  31. janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +43 -0
  32. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +1 -0
  33. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +122 -0
  34. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +1 -0
  35. janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +205 -0
  36. janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +124 -0
  37. janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +87 -0
  38. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +70 -0
  39. janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +87 -0
  40. janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +135 -0
  41. janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +143 -0
  42. janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +131 -0
  43. janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +58 -0
  44. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +55 -0
  45. janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +58 -0
  46. janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +270 -0
  47. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +1 -0
  48. janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +114 -0
  49. janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +172 -0
  50. janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +14 -0
  51. janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +51 -0
  52. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +1 -0
  53. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +83 -0
  54. janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +84 -0
  55. janito/plugins_backup_20250825_070018/core/system/__init__.py +23 -0
  56. janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +183 -0
  57. janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +218 -0
  58. janito/plugins_backup_20250825_070018/core_adapter.py +55 -0
  59. janito/plugins_backup_20250825_070018/dev/__init__.py +7 -0
  60. janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +37 -0
  61. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +172 -0
  62. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +171 -0
  63. janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +172 -0
  64. janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +23 -0
  65. janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +259 -0
  66. janito/plugins_backup_20250825_070018/discovery.py +289 -0
  67. janito/{plugins → plugins_backup_20250825_070018}/discovery_core.py +9 -14
  68. janito/plugins_backup_20250825_070018/example_plugin.py +108 -0
  69. janito/plugins_backup_20250825_070018/manager.py +243 -0
  70. janito/{plugins → plugins_backup_20250825_070018}/tools/core_tools_plugin.py +10 -9
  71. janito/{plugins → plugins_backup_20250825_070018}/tools/create_file.py +2 -2
  72. janito/{plugins → plugins_backup_20250825_070018}/tools/delete_text_in_file.py +1 -0
  73. janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +47 -0
  74. janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +14 -0
  75. janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +303 -0
  76. janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +36 -0
  77. janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +67 -0
  78. janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +73 -0
  79. janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +145 -0
  80. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +35 -0
  81. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +100 -0
  82. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +50 -0
  83. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +27 -0
  84. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +6 -0
  85. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +109 -0
  86. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +32 -0
  87. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +5 -0
  88. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +11 -0
  89. janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +6 -0
  90. janito/plugins_backup_20250825_070018/ui/__init__.py +7 -0
  91. janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +16 -0
  92. janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +110 -0
  93. janito/plugins_backup_20250825_070018/web/__init__.py +7 -0
  94. janito/plugins_backup_20250825_070018/web/webtools/__init__.py +33 -0
  95. janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +458 -0
  96. janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +51 -0
  97. janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +37 -0
  98. janito/providers/__init__.py +0 -1
  99. janito/tools/base.py +31 -1
  100. janito/tools/cli_initializer.py +1 -1
  101. janito/tools/function_adapter.py +176 -0
  102. janito/tools/initialize.py +1 -1
  103. janito/tools/loop_protection_decorator.py +117 -114
  104. janito/tools/tool_base.py +142 -114
  105. janito/tools/tools_schema.py +12 -6
  106. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/METADATA +1 -1
  107. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/RECORD +160 -95
  108. janito/llm/cancellation_manager.py +0 -63
  109. janito/llm/enter_cancellation.py +0 -107
  110. janito/plugins/core_adapter.py +0 -131
  111. janito/providers/together/__init__.py +0 -1
  112. janito/providers/together/model_info.py +0 -69
  113. janito/providers/together/provider.py +0 -108
  114. /janito/{plugin_system → plugin_system_backup_20250825_070018}/__init__.py +0 -0
  115. /janito/{plugin_system → plugin_system_backup_20250825_070018}/base.py +0 -0
  116. /janito/{plugins → plugins_backup_20250825_070018}/auto_loader_fixed.py +0 -0
  117. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/java_outline.py +0 -0
  118. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/markdown_outline.py +0 -0
  119. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/python_outline.py +0 -0
  120. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/get_file_outline/search_outline.py +0 -0
  121. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/match_lines.py +0 -0
  122. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/pattern_utils.py +0 -0
  123. /janito/{plugins → plugins_backup_20250825_070018/core/codeanalyzer}/tools/search_text/traverse_directory.py +0 -0
  124. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/css_validator.py +0 -0
  125. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/html_validator.py +0 -0
  126. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/jinja2_validator.py +0 -0
  127. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/js_validator.py +0 -0
  128. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/json_validator.py +0 -0
  129. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/markdown_validator.py +0 -0
  130. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/ps1_validator.py +0 -0
  131. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/python_validator.py +0 -0
  132. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/xml_validator.py +0 -0
  133. /janito/{plugins → plugins_backup_20250825_070018/core/filemanager}/tools/validate_file_syntax/yaml_validator.py +0 -0
  134. /janito/{plugins → plugins_backup_20250825_070018}/tools/__init__.py +0 -0
  135. /janito/{plugins → plugins_backup_20250825_070018}/tools/ask_user.py +0 -0
  136. /janito/{plugins → plugins_backup_20250825_070018}/tools/copy_file.py +0 -0
  137. /janito/{plugins → plugins_backup_20250825_070018}/tools/create_directory.py +0 -0
  138. /janito/{plugins → plugins_backup_20250825_070018}/tools/decorators.py +0 -0
  139. /janito/{plugins → plugins_backup_20250825_070018}/tools/fetch_url.py +0 -0
  140. /janito/{plugins → plugins_backup_20250825_070018}/tools/find_files.py +0 -0
  141. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/__init__.py +0 -0
  142. /janito/{plugins → plugins_backup_20250825_070018}/tools/get_file_outline/core.py +0 -0
  143. /janito/{plugins → plugins_backup_20250825_070018}/tools/move_file.py +0 -0
  144. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_html_in_browser.py +0 -0
  145. /janito/{plugins → plugins_backup_20250825_070018}/tools/open_url.py +0 -0
  146. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_code_run.py +0 -0
  147. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_command_run.py +0 -0
  148. /janito/{plugins → plugins_backup_20250825_070018}/tools/python_file_run.py +0 -0
  149. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_chart.py +0 -0
  150. /janito/{plugins → plugins_backup_20250825_070018}/tools/read_files.py +0 -0
  151. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_directory.py +0 -0
  152. /janito/{plugins → plugins_backup_20250825_070018}/tools/remove_file.py +0 -0
  153. /janito/{plugins → plugins_backup_20250825_070018}/tools/replace_text_in_file.py +0 -0
  154. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_bash_command.py +0 -0
  155. /janito/{plugins → plugins_backup_20250825_070018}/tools/run_powershell_command.py +0 -0
  156. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/__init__.py +0 -0
  157. /janito/{plugins → plugins_backup_20250825_070018}/tools/search_text/core.py +0 -0
  158. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image.py +0 -0
  159. /janito/{plugins → plugins_backup_20250825_070018}/tools/show_image_grid.py +0 -0
  160. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/__init__.py +0 -0
  161. /janito/{plugins → plugins_backup_20250825_070018}/tools/validate_file_syntax/core.py +0 -0
  162. /janito/{plugins → plugins_backup_20250825_070018}/tools/view_file.py +0 -0
  163. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/WHEEL +0 -0
  164. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/entry_points.txt +0 -0
  165. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/licenses/LICENSE +0 -0
  166. {janito-3.2.0.dist-info → janito-3.3.0.dist-info}/top_level.txt +0 -0
@@ -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"]
@@ -0,0 +1,16 @@
1
+ """
2
+ User Interface Plugin
3
+
4
+ User interaction and input tools.
5
+ """
6
+
7
+
8
+ def ask_user(question: str) -> str:
9
+ """Prompt user for input/clarification"""
10
+ return f"ask_user(question='{question}')"
11
+
12
+
13
+ # Plugin metadata
14
+ __plugin_name__ = "ui.userinterface"
15
+ __plugin_description__ = "User interaction and input"
16
+ __plugin_tools__ = [ask_user]
@@ -0,0 +1,110 @@
1
+ from janito.tools.tool_base import ToolBase, ToolPermissions
2
+ from janito.tools.adapters.local.adapter import register_local_tool
3
+ from janito.tools.loop_protection_decorator import protect_against_loops
4
+
5
+ from rich import print as rich_print
6
+ from janito.i18n import tr
7
+ from rich.panel import Panel
8
+ from prompt_toolkit import PromptSession
9
+ from prompt_toolkit.key_binding import KeyBindings
10
+ from prompt_toolkit.enums import EditingMode
11
+ from prompt_toolkit.formatted_text import HTML
12
+ from janito.cli.chat_mode.prompt_style import chat_shell_style
13
+ from prompt_toolkit.styles import Style
14
+
15
+ toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
16
+
17
+
18
+ @register_local_tool
19
+ class AskUserTool(ToolBase):
20
+ """
21
+ Prompts the user for clarification or input with a question.
22
+
23
+ Args:
24
+ question (str): The question to ask the user. This parameter is required and should be a string containing the prompt or question to display to the user.
25
+ Returns:
26
+ str: The user's response as a string. Example:
27
+ - "Yes"
28
+ - "No"
29
+ - "Some detailed answer..."
30
+ """
31
+
32
+ permissions = ToolPermissions(read=True)
33
+ tool_name = "ask_user"
34
+
35
+ @protect_against_loops(max_calls=5, time_window=10.0, key_field="question")
36
+ def run(self, question: str) -> str:
37
+
38
+ print() # Print an empty line before the question panel
39
+ rich_print(Panel.fit(question, title=tr("Question"), style="cyan"))
40
+
41
+ bindings = KeyBindings()
42
+ mode = {"multiline": False}
43
+
44
+ @bindings.add("c-r")
45
+ def _(event):
46
+ pass
47
+
48
+ @bindings.add("f12")
49
+ def _(event):
50
+ buf = event.app.current_buffer
51
+ buf.text = "Do It"
52
+ buf.validate_and_handle()
53
+
54
+ @bindings.add("f2")
55
+ def _(event):
56
+ buf = event.app.current_buffer
57
+ buf.text = "F2"
58
+ buf.validate_and_handle()
59
+
60
+ # Use shared CLI styles
61
+
62
+ # prompt_style contains the prompt area and input background
63
+ # toolbar_style contains the bottom-toolbar styling
64
+
65
+ # Use the shared chat_shell_style for input styling only
66
+ style = chat_shell_style
67
+
68
+ def get_toolbar():
69
+ f12_hint = " F2: F2 | F12: Do It"
70
+ if mode["multiline"]:
71
+ return HTML(
72
+ f"<b>Multiline mode (Esc+Enter to submit). Type /single to switch.</b>{f12_hint}"
73
+ )
74
+ else:
75
+ return HTML(
76
+ f"<b>Single-line mode (Enter to submit). Type /multi for multiline.</b>{f12_hint}"
77
+ )
78
+
79
+ session = PromptSession(
80
+ multiline=False,
81
+ key_bindings=bindings,
82
+ editing_mode=EditingMode.EMACS,
83
+ bottom_toolbar=get_toolbar,
84
+ style=style,
85
+ )
86
+
87
+ prompt_icon = HTML("<inputline>💬 </inputline>")
88
+
89
+ while True:
90
+ response = session.prompt(prompt_icon)
91
+ if not mode["multiline"] and response.strip() == "/multi":
92
+ mode["multiline"] = True
93
+ session.multiline = True
94
+ continue
95
+ elif mode["multiline"] and response.strip() == "/single":
96
+ mode["multiline"] = False
97
+ session.multiline = False
98
+ continue
99
+ else:
100
+ sanitized = response.strip()
101
+ try:
102
+ sanitized.encode("utf-8")
103
+ except UnicodeEncodeError:
104
+ sanitized = sanitized.encode("utf-8", errors="replace").decode(
105
+ "utf-8"
106
+ )
107
+ rich_print(
108
+ "[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
109
+ )
110
+ return sanitized
@@ -0,0 +1,7 @@
1
+ """
2
+ Web Tools Plugin Package
3
+
4
+ Contains web scraping, browsing, and URL operations.
5
+ """
6
+
7
+ __all__ = ["webtools"]