janito 3.5.0__py3-none-any.whl → 3.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. janito/README.md +4 -4
  2. janito/cli/cli_commands/list_tools.py +6 -1
  3. janito/cli/main_cli.py +1 -1
  4. janito/cli/rich_terminal_reporter.py +2 -2
  5. janito/data/blocked.txt +96 -0
  6. janito/docs/GETTING_STARTED.md +8 -9
  7. janito/plugins/core/system/tools/run_bash_command.py +23 -2
  8. janito/plugins/core/system/tools/run_powershell_command.py +16 -0
  9. janito/plugins/tools/__init__.py +34 -5
  10. janito/plugins/tools/core/__init__.py +65 -0
  11. janito/plugins/tools/{ask_user.py → core/ask_user.py} +1 -1
  12. janito/plugins/tools/{copy_file.py → core/copy_file.py} +1 -1
  13. janito/plugins/tools/{create_directory.py → core/create_directory.py} +1 -1
  14. janito/plugins/tools/{create_file.py → core/create_file.py} +2 -2
  15. janito/plugins/tools/{delete_text_in_file.py → core/delete_text_in_file.py} +2 -2
  16. janito/plugins/tools/{fetch_url.py → core/fetch_url.py} +18 -21
  17. janito/plugins/tools/{find_files.py → core/find_files.py} +1 -1
  18. janito/plugins/tools/{get_file_outline → core/get_file_outline}/core.py +1 -1
  19. janito/plugins/tools/{move_file.py → core/move_file.py} +1 -1
  20. janito/plugins/tools/{open_html_in_browser.py → core/open_html_in_browser.py} +1 -1
  21. janito/plugins/tools/{open_url.py → core/open_url.py} +1 -1
  22. janito/plugins/tools/{python_code_run.py → core/python_code_run.py} +21 -5
  23. janito/plugins/tools/{python_command_run.py → core/python_command_run.py} +19 -3
  24. janito/plugins/tools/{python_file_run.py → core/python_file_run.py} +19 -3
  25. janito/plugins/tools/{read_chart.py → core/read_chart.py} +1 -1
  26. janito/plugins/tools/{read_files.py → core/read_files.py} +1 -1
  27. janito/plugins/tools/{remove_directory.py → core/remove_directory.py} +1 -1
  28. janito/plugins/tools/{remove_file.py → core/remove_file.py} +1 -1
  29. janito/plugins/tools/{replace_text_in_file.py → core/replace_text_in_file.py} +2 -2
  30. janito/plugins/tools/{run_bash_command.py → core/run_bash_command.py} +1 -1
  31. janito/plugins/tools/{run_powershell_command.py → core/run_powershell_command.py} +1 -1
  32. janito/plugins/tools/{search_text → core/search_text}/core.py +1 -1
  33. janito/plugins/tools/{show_image.py → core/show_image.py} +1 -1
  34. janito/plugins/tools/{show_image_grid.py → core/show_image_grid.py} +1 -1
  35. janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/core.py +1 -1
  36. janito/plugins/tools/{view_file.py → core/view_file.py} +1 -1
  37. janito/plugins/web/webtools/__init__.py +1 -11
  38. janito/providers/moonshot/model_info.py +15 -4
  39. janito/providers/moonshot/provider.py +1 -1
  40. janito/tools/__init__.py +14 -4
  41. janito/tools/adapters/local/copy_file.py +0 -0
  42. janito/tools/adapters/local/create_file.py +0 -0
  43. janito/tools/adapters/local/move_file.py +0 -0
  44. janito/tools/adapters/local/remove_file.py +0 -0
  45. janito/tools/adapters/local/view_file.py +0 -0
  46. janito/tools/blocked_sites.py +74 -0
  47. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/METADATA +7 -8
  48. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/RECORD +73 -70
  49. janito/plugins/dev/pythondev/tools/python_code_run.py +0 -172
  50. janito/plugins/dev/pythondev/tools/python_command_run.py +0 -171
  51. janito/plugins/dev/pythondev/tools/python_file_run.py +0 -172
  52. janito/plugins/tools/core_tools_plugin.py +0 -87
  53. janito/plugins/web/webtools/tools/fetch_url.py +0 -458
  54. /janito/plugins/tools/{decorators.py → core/decorators.py} +0 -0
  55. /janito/plugins/tools/{get_file_outline → core/get_file_outline}/__init__.py +0 -0
  56. /janito/plugins/tools/{get_file_outline → core/get_file_outline}/java_outline.py +0 -0
  57. /janito/plugins/tools/{get_file_outline → core/get_file_outline}/markdown_outline.py +0 -0
  58. /janito/plugins/tools/{get_file_outline → core/get_file_outline}/python_outline.py +0 -0
  59. /janito/plugins/tools/{get_file_outline → core/get_file_outline}/search_outline.py +0 -0
  60. /janito/plugins/tools/{search_text → core/search_text}/__init__.py +0 -0
  61. /janito/plugins/tools/{search_text → core/search_text}/match_lines.py +0 -0
  62. /janito/plugins/tools/{search_text → core/search_text}/pattern_utils.py +0 -0
  63. /janito/plugins/tools/{search_text → core/search_text}/traverse_directory.py +0 -0
  64. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/__init__.py +0 -0
  65. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/css_validator.py +0 -0
  66. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/html_validator.py +0 -0
  67. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/jinja2_validator.py +0 -0
  68. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/js_validator.py +0 -0
  69. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/json_validator.py +0 -0
  70. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/markdown_validator.py +0 -0
  71. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/ps1_validator.py +0 -0
  72. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/python_validator.py +0 -0
  73. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/xml_validator.py +0 -0
  74. /janito/plugins/tools/{validate_file_syntax → core/validate_file_syntax}/yaml_validator.py +0 -0
  75. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/WHEEL +0 -0
  76. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/entry_points.txt +0 -0
  77. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/licenses/LICENSE +0 -0
  78. {janito-3.5.0.dist-info → janito-3.6.1.dist-info}/top_level.txt +0 -0
@@ -1,172 +0,0 @@
1
- import subprocess
2
- import os
3
- import sys
4
- import tempfile
5
- import threading
6
- from janito.tools.tool_base import ToolBase, ToolPermissions
7
- from janito.report_events import ReportAction
8
- from janito.tools.adapters.local.adapter import register_local_tool
9
- from janito.i18n import tr
10
-
11
-
12
- @register_local_tool
13
- class PythonFileRunTool(ToolBase):
14
- """
15
- Tool to execute a specified Python script file.
16
-
17
- Args:
18
- path (str): Path to the Python script file to execute.
19
- timeout (int): Timeout in seconds for the command. Defaults to 60.
20
- silent (bool): If True, suppresses progress and status messages. Defaults to False.
21
-
22
- Returns:
23
- str: Output and status message, or file paths/line counts if output is large.
24
- """
25
-
26
- permissions = ToolPermissions(execute=True)
27
- tool_name = "python_file_run"
28
-
29
- def run(self, path: str, timeout: int = 60, silent: bool = False) -> str:
30
- from janito.tools.path_utils import expand_path
31
-
32
- path = expand_path(path)
33
- if not silent:
34
- self.report_action(
35
- tr("🚀 Running: python {path}", path=path),
36
- ReportAction.EXECUTE,
37
- )
38
- self.report_stdout("\n")
39
- else:
40
- self.report_action(tr("⚡ Executing..."), ReportAction.EXECUTE)
41
- try:
42
- with (
43
- tempfile.NamedTemporaryFile(
44
- mode="w+",
45
- prefix="python_file_stdout_",
46
- delete=False,
47
- encoding="utf-8",
48
- ) as stdout_file,
49
- tempfile.NamedTemporaryFile(
50
- mode="w+",
51
- prefix="python_file_stderr_",
52
- delete=False,
53
- encoding="utf-8",
54
- ) as stderr_file,
55
- ):
56
- process = subprocess.Popen(
57
- [sys.executable, path],
58
- stdout=subprocess.PIPE,
59
- stderr=subprocess.PIPE,
60
- text=True,
61
- bufsize=1,
62
- universal_newlines=True,
63
- encoding="utf-8",
64
- env={**os.environ, "PYTHONIOENCODING": "utf-8"},
65
- )
66
- stdout_lines, stderr_lines = self._stream_process_output(
67
- process, stdout_file, stderr_file
68
- )
69
- return_code = self._wait_for_process(process, timeout)
70
- if return_code is None:
71
- return tr(
72
- "Code timed out after {timeout} seconds.", timeout=timeout
73
- )
74
- stdout_file.flush()
75
- stderr_file.flush()
76
- if not silent:
77
- self.report_success(
78
- tr("✅ Return code {return_code}", return_code=return_code),
79
- ReportAction.EXECUTE,
80
- )
81
- return self._format_result(
82
- stdout_file.name, stderr_file.name, return_code
83
- )
84
- except Exception as e:
85
- self.report_error(tr("❌ Error: {error}", error=e), ReportAction.EXECUTE)
86
- return tr("Error running file: {error}", error=e)
87
-
88
- def _stream_process_output(self, process, stdout_file, stderr_file):
89
- stdout_lines = 0
90
- stderr_lines = 0
91
-
92
- def stream_output(stream, file_obj, report_func, count_func):
93
- nonlocal stdout_lines, stderr_lines
94
- for line in stream:
95
- file_obj.write(line)
96
- file_obj.flush()
97
- # Always supply a default action for stdout/stderr reporting
98
- from janito.report_events import ReportAction
99
-
100
- report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
101
- if count_func == "stdout":
102
- stdout_lines += 1
103
- else:
104
- stderr_lines += 1
105
-
106
- stdout_thread = threading.Thread(
107
- target=stream_output,
108
- args=(process.stdout, stdout_file, self.report_stdout, "stdout"),
109
- )
110
- stderr_thread = threading.Thread(
111
- target=stream_output,
112
- args=(process.stderr, stderr_file, self.report_stderr, "stderr"),
113
- )
114
- stdout_thread.start()
115
- stderr_thread.start()
116
- stdout_thread.join()
117
- stderr_thread.join()
118
- return stdout_lines, stderr_lines
119
-
120
- def _wait_for_process(self, process, timeout):
121
- try:
122
- return process.wait(timeout=timeout)
123
- except subprocess.TimeoutExpired:
124
- process.kill()
125
- self.report_error(
126
- tr("❌ Timed out after {timeout} seconds.", timeout=timeout),
127
- ReportAction.EXECUTE,
128
- )
129
- return None
130
-
131
- def _format_result(self, stdout_file_name, stderr_file_name, return_code):
132
- with open(stdout_file_name, "r", encoding="utf-8", errors="replace") as out_f:
133
- stdout_content = out_f.read()
134
- with open(stderr_file_name, "r", encoding="utf-8", errors="replace") as err_f:
135
- stderr_content = err_f.read()
136
- max_lines = 100
137
- stdout_lines = stdout_content.count("\n")
138
- stderr_lines = stderr_content.count("\n")
139
-
140
- def head_tail(text, n=10):
141
- lines = text.splitlines()
142
- if len(lines) <= 2 * n:
143
- return "\n".join(lines)
144
- return "\n".join(
145
- lines[:n]
146
- + ["... ({} lines omitted) ...".format(len(lines) - 2 * n)]
147
- + lines[-n:]
148
- )
149
-
150
- if stdout_lines <= max_lines and stderr_lines <= max_lines:
151
- result = f"Return code: {return_code}\n--- python_file_run: STDOUT ---\n{stdout_content}"
152
- if stderr_content.strip():
153
- result += f"\n--- python_file_run: STDERR ---\n{stderr_content}"
154
- return result
155
- else:
156
- result = f"stdout_file: {stdout_file_name} (lines: {stdout_lines})\n"
157
- if stderr_lines > 0 and stderr_content.strip():
158
- result += f"stderr_file: {stderr_file_name} (lines: {stderr_lines})\n"
159
- result += f"returncode: {return_code}\n"
160
- result += (
161
- "--- python_file_run: STDOUT (head/tail) ---\n"
162
- + head_tail(stdout_content)
163
- + "\n"
164
- )
165
- if stderr_content.strip():
166
- result += (
167
- "--- python_file_run: STDERR (head/tail) ---\n"
168
- + head_tail(stderr_content)
169
- + "\n"
170
- )
171
- result += "Use the view_file tool to inspect the contents of these files when needed."
172
- return result
@@ -1,87 +0,0 @@
1
- """
2
- Core tools plugin implementation.
3
- """
4
-
5
- from functools import wraps
6
- from typing import Type
7
- from janito.plugin_system.base import Plugin, PluginMetadata
8
-
9
- from .ask_user import AskUser
10
- from .copy_file import CopyFile
11
- from .create_directory import CreateDirectory
12
- from .create_file import CreateFile
13
- from .delete_text_in_file import DeleteTextInFile
14
- from .fetch_url import FetchUrl
15
- from .find_files import FindFiles
16
- from .move_file import MoveFile
17
- from .open_html_in_browser import OpenHtmlInBrowser
18
- from .open_url import OpenUrl
19
- from .python_code_run import PythonCodeRun
20
- from .python_command_run import PythonCommandRun
21
- from .python_file_run import PythonFileRun
22
- from .read_chart import ReadChart
23
- from .read_files import ReadFiles
24
- from .remove_directory import RemoveDirectory
25
- from .remove_file import RemoveFile
26
- from .replace_text_in_file import ReplaceTextInFile
27
- from .run_bash_command import RunBashCommand
28
- from .run_powershell_command import RunPowershellCommand
29
- from .show_image import ShowImage
30
- from .show_image_grid import ShowImageGrid
31
- from .view_file import ViewFile
32
- from .validate_file_syntax.core import ValidateFileSyntax
33
- from .get_file_outline.core import GetFileOutline
34
- from .search_text.core import SearchText
35
- from .decorators import get_core_tools
36
-
37
- # Registry for core tools
38
- _core_tools_registry = []
39
-
40
-
41
- def register_core_tool(cls: Type):
42
- """Decorator to register a core tool."""
43
- _core_tools_registry.append(cls)
44
- return cls
45
-
46
-
47
- class CoreToolsPlugin(Plugin):
48
- """Core tools plugin providing essential janito functionality."""
49
-
50
- def get_metadata(self):
51
- return PluginMetadata(
52
- name="core_tools",
53
- version="1.0.0",
54
- description="Core tools for file operations, code execution, and system interactions",
55
- author="janito team",
56
- license="MIT",
57
- )
58
-
59
- def get_tools(self):
60
- return [
61
- AskUser,
62
- CopyFile,
63
- CreateDirectory,
64
- CreateFile,
65
- DeleteTextInFile,
66
- FetchUrl,
67
- FindFiles,
68
- MoveFile,
69
- OpenHtmlInBrowser,
70
- OpenUrl,
71
- PythonCodeRun,
72
- PythonCommandRun,
73
- PythonFileRun,
74
- ReadChart,
75
- ReadFiles,
76
- RemoveDirectory,
77
- RemoveFile,
78
- ReplaceTextInFile,
79
- RunBashCommand,
80
- RunPowershellCommand,
81
- ShowImage,
82
- ShowImageGrid,
83
- ViewFile,
84
- ValidateFileSyntax,
85
- GetFileOutline,
86
- SearchText,
87
- ] + get_core_tools()