janito 3.6.1__py3-none-any.whl → 3.8.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 (172) hide show
  1. janito/README.md +4 -7
  2. janito/cli/chat_mode/bindings.py +0 -50
  3. janito/cli/chat_mode/session.py +1 -12
  4. janito/cli/chat_mode/shell/commands/multi.py +0 -5
  5. janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
  6. janito/cli/cli_commands/list_plugins.py +43 -52
  7. janito/cli/cli_commands/list_tools.py +1 -6
  8. janito/cli/core/getters.py +0 -3
  9. janito/cli/core/model_guesser.py +24 -40
  10. janito/cli/main_cli.py +13 -10
  11. janito/cli/prompt_core.py +9 -47
  12. janito/cli/rich_terminal_reporter.py +4 -4
  13. janito/docs/GETTING_STARTED.md +9 -8
  14. janito/drivers/openai/driver.py +0 -1
  15. janito/drivers/zai/driver.py +0 -1
  16. janito/i18n/it.py +46 -46
  17. janito/llm/agent.py +16 -32
  18. janito/llm/auth_utils.py +5 -14
  19. janito/llm/driver.py +0 -8
  20. janito/plugins/__init__.py +12 -31
  21. janito/plugins/auto_loader.py +11 -12
  22. janito/plugins/auto_loader_fixed.py +11 -12
  23. janito/{plugin_system → plugins}/base.py +2 -5
  24. janito/plugins/builtin.py +1 -15
  25. janito/plugins/core_adapter.py +11 -89
  26. janito/plugins/core_loader.py +120 -0
  27. janito/plugins/core_loader_fixed.py +125 -0
  28. janito/plugins/discovery.py +5 -5
  29. janito/plugins/discovery_core.py +9 -14
  30. janito/plugins/manager.py +1 -1
  31. janito/providers/__init__.py +0 -1
  32. janito/providers/alibaba/model_info.py +10 -0
  33. janito/providers/alibaba/provider.py +1 -3
  34. janito/providers/moonshot/model_info.py +7 -7
  35. janito/providers/moonshot/provider.py +1 -1
  36. janito/tools/__init__.py +7 -41
  37. janito/tools/adapters/__init__.py +1 -6
  38. janito/tools/adapters/local/__init__.py +70 -7
  39. janito/{plugins/tools/core → tools/adapters/local}/ask_user.py +3 -3
  40. janito/tools/adapters/local/copy_file.py +87 -0
  41. janito/tools/adapters/local/create_file.py +138 -0
  42. janito/{plugins/tools/core → tools/adapters/local}/fetch_url.py +23 -20
  43. janito/tools/adapters/local/move_file.py +131 -0
  44. janito/{plugins/tools/core → tools/adapters/local}/python_code_run.py +7 -23
  45. janito/{plugins/tools/core → tools/adapters/local}/python_command_run.py +5 -21
  46. janito/{plugins/tools/core → tools/adapters/local}/python_file_run.py +5 -21
  47. janito/tools/adapters/local/remove_file.py +58 -0
  48. janito/{plugins/tools/core → tools/adapters/local}/replace_text_in_file.py +4 -4
  49. janito/{plugins/tools/core → tools/adapters/local}/run_bash_command.py +3 -3
  50. janito/{plugins/tools/core → tools/adapters/local}/run_powershell_command.py +3 -3
  51. janito/{plugins/tools/core → tools/adapters/local}/show_image.py +6 -15
  52. janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
  53. janito/tools/adapters/local/view_file.py +172 -0
  54. janito/tools/function_adapter.py +65 -0
  55. janito/tools/loop_protection_decorator.py +117 -114
  56. janito-3.8.0.dist-info/METADATA +84 -0
  57. janito-3.8.0.dist-info/RECORD +264 -0
  58. janito/cli/cli_commands/check_tools.py +0 -212
  59. janito/data/blocked.txt +0 -96
  60. janito/llm/cancellation_manager.py +0 -63
  61. janito/llm/enter_cancellation.py +0 -107
  62. janito/plugin_system/__init__.py +0 -10
  63. janito/plugin_system/core_loader.py +0 -217
  64. janito/plugin_system/core_loader_fixed.py +0 -225
  65. janito/plugins/core/__init__.py +0 -7
  66. janito/plugins/core/codeanalyzer/__init__.py +0 -43
  67. janito/plugins/core/filemanager/__init__.py +0 -124
  68. janito/plugins/core/filemanager/tools/copy_file.py +0 -87
  69. janito/plugins/core/filemanager/tools/create_file.py +0 -87
  70. janito/plugins/core/filemanager/tools/move_file.py +0 -131
  71. janito/plugins/core/filemanager/tools/remove_file.py +0 -58
  72. janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
  73. janito/plugins/core/filemanager/tools/view_file.py +0 -172
  74. janito/plugins/core/imagedisplay/__init__.py +0 -14
  75. janito/plugins/core/imagedisplay/plugin.py +0 -51
  76. janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
  77. janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
  78. janito/plugins/core/system/__init__.py +0 -23
  79. janito/plugins/core/system/tools/run_bash_command.py +0 -204
  80. janito/plugins/core/system/tools/run_powershell_command.py +0 -234
  81. janito/plugins/dev/__init__.py +0 -7
  82. janito/plugins/dev/pythondev/__init__.py +0 -37
  83. janito/plugins/dev/visualization/__init__.py +0 -23
  84. janito/plugins/example_plugin.py +0 -108
  85. janito/plugins/tools/__init__.py +0 -39
  86. janito/plugins/tools/core/__init__.py +0 -65
  87. janito/plugins/tools/core/copy_file.py +0 -87
  88. janito/plugins/tools/core/create_directory.py +0 -70
  89. janito/plugins/tools/core/create_file.py +0 -138
  90. janito/plugins/tools/core/decorators.py +0 -19
  91. janito/plugins/tools/core/delete_text_in_file.py +0 -134
  92. janito/plugins/tools/core/find_files.py +0 -143
  93. janito/plugins/tools/core/get_file_outline/__init__.py +0 -7
  94. janito/plugins/tools/core/get_file_outline/core.py +0 -122
  95. janito/plugins/tools/core/get_file_outline/java_outline.py +0 -47
  96. janito/plugins/tools/core/get_file_outline/markdown_outline.py +0 -14
  97. janito/plugins/tools/core/get_file_outline/python_outline.py +0 -303
  98. janito/plugins/tools/core/get_file_outline/search_outline.py +0 -36
  99. janito/plugins/tools/core/move_file.py +0 -131
  100. janito/plugins/tools/core/open_html_in_browser.py +0 -51
  101. janito/plugins/tools/core/open_url.py +0 -37
  102. janito/plugins/tools/core/read_chart.py +0 -259
  103. janito/plugins/tools/core/read_files.py +0 -58
  104. janito/plugins/tools/core/remove_directory.py +0 -55
  105. janito/plugins/tools/core/remove_file.py +0 -58
  106. janito/plugins/tools/core/search_text/__init__.py +0 -7
  107. janito/plugins/tools/core/search_text/core.py +0 -205
  108. janito/plugins/tools/core/search_text/match_lines.py +0 -67
  109. janito/plugins/tools/core/search_text/pattern_utils.py +0 -73
  110. janito/plugins/tools/core/search_text/traverse_directory.py +0 -145
  111. janito/plugins/tools/core/show_image_grid.py +0 -85
  112. janito/plugins/tools/core/validate_file_syntax/__init__.py +0 -7
  113. janito/plugins/tools/core/validate_file_syntax/core.py +0 -114
  114. janito/plugins/tools/core/validate_file_syntax/css_validator.py +0 -35
  115. janito/plugins/tools/core/validate_file_syntax/html_validator.py +0 -100
  116. janito/plugins/tools/core/validate_file_syntax/jinja2_validator.py +0 -50
  117. janito/plugins/tools/core/validate_file_syntax/js_validator.py +0 -27
  118. janito/plugins/tools/core/validate_file_syntax/json_validator.py +0 -6
  119. janito/plugins/tools/core/validate_file_syntax/markdown_validator.py +0 -109
  120. janito/plugins/tools/core/validate_file_syntax/ps1_validator.py +0 -32
  121. janito/plugins/tools/core/validate_file_syntax/python_validator.py +0 -5
  122. janito/plugins/tools/core/validate_file_syntax/xml_validator.py +0 -11
  123. janito/plugins/tools/core/validate_file_syntax/yaml_validator.py +0 -6
  124. janito/plugins/tools/core/view_file.py +0 -172
  125. janito/plugins/ui/__init__.py +0 -7
  126. janito/plugins/ui/userinterface/__init__.py +0 -16
  127. janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
  128. janito/plugins/web/__init__.py +0 -7
  129. janito/plugins/web/webtools/__init__.py +0 -23
  130. janito/providers/together/__init__.py +0 -1
  131. janito/providers/together/model_info.py +0 -69
  132. janito/providers/together/provider.py +0 -108
  133. janito/tools/blocked_sites.py +0 -74
  134. janito/tools/cli_initializer.py +0 -88
  135. janito/tools/initialize.py +0 -70
  136. janito-3.6.1.dist-info/METADATA +0 -228
  137. janito-3.6.1.dist-info/RECORD +0 -339
  138. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
  139. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
  140. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
  141. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
  142. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
  143. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
  144. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
  145. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
  146. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
  147. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
  148. /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
  149. /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
  150. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
  151. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
  152. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
  153. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
  154. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
  155. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
  156. /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
  157. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
  158. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
  159. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
  160. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
  161. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
  162. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
  163. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
  164. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
  165. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
  166. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
  167. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
  168. /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
  169. {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/WHEEL +0 -0
  170. {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/entry_points.txt +0 -0
  171. {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/licenses/LICENSE +0 -0
  172. {janito-3.6.1.dist-info → janito-3.8.0.dist-info}/top_level.txt +0 -0
@@ -1,35 +0,0 @@
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"
@@ -1,100 +0,0 @@
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"
@@ -1,50 +0,0 @@
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))
@@ -1,27 +0,0 @@
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"
@@ -1,6 +0,0 @@
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"
@@ -1,109 +0,0 @@
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"
@@ -1,32 +0,0 @@
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"
@@ -1,5 +0,0 @@
1
- def validate_python(path: str) -> str:
2
- import py_compile
3
-
4
- py_compile.compile(path, doraise=True)
5
- return "✅ OK"
@@ -1,11 +0,0 @@
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"
@@ -1,6 +0,0 @@
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"
@@ -1,172 +0,0 @@
1
- from janito.tools.tool_base import ToolBase, ToolPermissions
2
- from janito.report_events import ReportAction
3
- from .decorators import register_core_tool
4
- from janito.tools.tool_utils import pluralize
5
- from janito.i18n import tr
6
- from janito.tools.loop_protection_decorator import protect_against_loops
7
-
8
-
9
- @register_core_tool
10
- class ViewFile(ToolBase):
11
- """
12
- Read lines from a file. You can specify a line range, or read the entire file by simply omitting the from_line and to_line parameters.
13
-
14
- Args:
15
- path (str): Path to the file to read lines from.
16
- from_line (int, optional): Starting line number (1-based). Omit to start from the first line.
17
- to_line (int, optional): Ending line number (1-based). Omit to read to the end of the file.
18
-
19
- To read the full file, just provide path and leave from_line and to_line unset.
20
-
21
- Returns:
22
- str: File content with a header indicating the file name and line range. Example:
23
- - "---\nFile: /path/to/file.py | Lines: 1-10 (of 100)\n---\n<lines...>"
24
- - "---\nFile: /path/to/file.py | All lines (total: 100 (all))\n---\n<all lines...>"
25
- - "Error reading file: <error message>"
26
- - "❗ not found"
27
- """
28
-
29
- permissions = ToolPermissions(read=True)
30
- tool_name = "view_file"
31
-
32
- @protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
33
- def run(self, path: str, from_line: int = None, to_line: int = None) -> str:
34
- import os
35
- from janito.tools.tool_utils import display_path
36
- from janito.tools.path_utils import expand_path
37
-
38
- path = expand_path(path)
39
- disp_path = display_path(path)
40
- self.report_action(
41
- tr("📖 View '{disp_path}'", disp_path=disp_path),
42
- ReportAction.READ,
43
- )
44
- try:
45
- if os.path.isdir(path):
46
- return self._list_directory(path, disp_path)
47
- lines = self._read_file_lines(path)
48
- selected, selected_len, total_lines = self._select_lines(
49
- lines, from_line, to_line
50
- )
51
- self._report_success(selected_len, from_line, to_line, total_lines)
52
- header = self._format_header(
53
- disp_path, from_line, to_line, selected_len, total_lines
54
- )
55
- return header + "".join(selected)
56
- except FileNotFoundError as e:
57
- self.report_warning(tr("❗ not found"))
58
- return f"Error reading file: {e}"
59
- except Exception as e:
60
- self.report_error(tr(" ❌ Error: {error}", error=e))
61
- return tr("Error reading file: {error}", error=e)
62
-
63
- def _list_directory(self, path, disp_path):
64
- import os
65
-
66
- try:
67
- entries = os.listdir(path)
68
- entries.sort()
69
- # Suffix subdirectories with '/'
70
- formatted_entries = []
71
- for entry in entries:
72
- full_path = os.path.join(path, entry)
73
- if os.path.isdir(full_path):
74
- formatted_entries.append(entry + "/")
75
- else:
76
- formatted_entries.append(entry)
77
- header = (
78
- f"--- view_file: {disp_path} [directory, {len(entries)} entries] ---\n"
79
- )
80
- listing = "\n".join(formatted_entries)
81
- self.report_success(tr("📁 Directory ({count} items)", count=len(entries)))
82
- return header + listing + "\n"
83
- except Exception as e:
84
- self.report_error(tr(" ❌ Error listing directory: {error}", error=e))
85
- return tr("Error listing directory: {error}", error=e)
86
-
87
- def _read_file_lines(self, path):
88
- """Read all lines from the file."""
89
- with open(path, "r", encoding="utf-8", errors="replace") as f:
90
- return f.readlines()
91
-
92
- def _select_lines(self, lines, from_line, to_line):
93
- """Select the requested lines and return them with their count and total lines."""
94
- selected = lines[
95
- (from_line - 1 if from_line else 0) : (to_line if to_line else None)
96
- ]
97
- selected_len = len(selected)
98
- total_lines = len(lines)
99
- return selected, selected_len, total_lines
100
-
101
- def _report_success(self, selected_len, from_line, to_line, total_lines):
102
- """Report the success message after reading lines."""
103
- if from_line and to_line:
104
- requested = to_line - from_line + 1
105
- at_end = to_line >= total_lines or selected_len < requested
106
- if at_end:
107
- self.report_success(
108
- tr(
109
- " ✅ {selected_len} {line_word} (end)",
110
- selected_len=selected_len,
111
- line_word=pluralize("line", selected_len),
112
- )
113
- )
114
- elif to_line < total_lines:
115
- self.report_success(
116
- tr(
117
- " ✅ {selected_len} {line_word} ({remaining} to end)",
118
- selected_len=selected_len,
119
- line_word=pluralize("line", selected_len),
120
- remaining=total_lines - to_line,
121
- )
122
- )
123
- else:
124
- self.report_success(
125
- tr(
126
- " ✅ {selected_len} {line_word} (all)",
127
- selected_len=selected_len,
128
- line_word=pluralize("line", selected_len),
129
- )
130
- )
131
-
132
- def _format_header(self, disp_path, from_line, to_line, selected_len, total_lines):
133
- """Format the header for the output."""
134
- if from_line and to_line:
135
- requested = to_line - from_line + 1
136
- at_end = selected_len < requested or to_line >= total_lines
137
- if at_end:
138
- return tr(
139
- "---\n{disp_path} {from_line}-{to_line} (end)\n---\n",
140
- disp_path=disp_path,
141
- from_line=from_line,
142
- to_line=to_line,
143
- )
144
- else:
145
- return tr(
146
- "---\n{disp_path} {from_line}-{to_line} (of {total_lines})\n---\n",
147
- disp_path=disp_path,
148
- from_line=from_line,
149
- to_line=to_line,
150
- total_lines=total_lines,
151
- )
152
- elif from_line:
153
- return tr(
154
- "---\n{disp_path} {from_line}-END (of {total_lines})\n---\n",
155
- disp_path=disp_path,
156
- from_line=from_line,
157
- total_lines=total_lines,
158
- )
159
- else:
160
- return tr(
161
- "---\n{disp_path} All lines (total: {total_lines} (all))\n---\n",
162
- disp_path=disp_path,
163
- total_lines=total_lines,
164
- )
165
-
166
- def _handle_read_error(self, e):
167
- """Handle file read errors and report appropriately."""
168
- if isinstance(e, FileNotFoundError):
169
- self.report_error(tr("❗ not found"), ReportAction.READ)
170
- return tr("❗ not found")
171
- self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.READ)
172
- return tr("Error reading file: {error}", error=e)
@@ -1,7 +0,0 @@
1
- """
2
- User Interface Plugin Package
3
-
4
- Contains user interaction and interface tools.
5
- """
6
-
7
- __all__ = ["userinterface"]
@@ -1,16 +0,0 @@
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]