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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. janito/__init__.py +6 -6
  2. janito/cli/chat_mode/shell/autocomplete.py +21 -21
  3. janito/cli/chat_mode/shell/commands/clear.py +12 -12
  4. janito/cli/chat_mode/shell/commands/multi.py +51 -51
  5. janito/cli/chat_mode/shell/input_history.py +62 -62
  6. janito/cli/cli_commands/list_models.py +35 -35
  7. janito/cli/cli_commands/list_providers.py +9 -9
  8. janito/cli/cli_commands/list_tools.py +53 -53
  9. janito/cli/cli_commands/model_selection.py +50 -50
  10. janito/cli/cli_commands/model_utils.py +95 -95
  11. janito/cli/cli_commands/set_api_key.py +19 -19
  12. janito/cli/cli_commands/show_config.py +51 -51
  13. janito/cli/cli_commands/show_system_prompt.py +62 -62
  14. janito/cli/core/__init__.py +4 -4
  15. janito/cli/core/event_logger.py +59 -59
  16. janito/cli/core/getters.py +33 -33
  17. janito/cli/core/unsetters.py +54 -54
  18. janito/cli/single_shot_mode/__init__.py +6 -6
  19. janito/config.py +5 -5
  20. janito/config_manager.py +112 -112
  21. janito/drivers/anthropic/driver.py +113 -113
  22. janito/formatting_token.py +54 -54
  23. janito/i18n/__init__.py +35 -35
  24. janito/i18n/messages.py +23 -23
  25. janito/i18n/pt.py +47 -47
  26. janito/llm/__init__.py +5 -5
  27. janito/llm/agent.py +443 -443
  28. janito/llm/auth.py +63 -63
  29. janito/llm/driver_config_builder.py +34 -34
  30. janito/llm/driver_input.py +12 -12
  31. janito/llm/message_parts.py +60 -60
  32. janito/llm/model.py +38 -38
  33. janito/llm/provider.py +196 -196
  34. janito/provider_registry.py +176 -176
  35. janito/providers/anthropic/model_info.py +22 -22
  36. janito/providers/anthropic/provider.py +2 -0
  37. janito/providers/azure_openai/model_info.py +16 -16
  38. janito/providers/azure_openai/provider.py +3 -0
  39. janito/providers/deepseek/__init__.py +1 -1
  40. janito/providers/deepseek/model_info.py +16 -16
  41. janito/providers/deepseek/provider.py +94 -91
  42. janito/providers/google/provider.py +3 -0
  43. janito/providers/mistralai/provider.py +3 -0
  44. janito/providers/openai/provider.py +4 -0
  45. janito/tools/adapters/__init__.py +1 -1
  46. janito/tools/adapters/local/ask_user.py +102 -102
  47. janito/tools/adapters/local/copy_file.py +84 -84
  48. janito/tools/adapters/local/create_directory.py +69 -69
  49. janito/tools/adapters/local/create_file.py +82 -82
  50. janito/tools/adapters/local/fetch_url.py +97 -97
  51. janito/tools/adapters/local/find_files.py +138 -138
  52. janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
  53. janito/tools/adapters/local/get_file_outline/core.py +117 -117
  54. janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
  55. janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
  56. janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
  57. janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
  58. janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
  59. janito/tools/adapters/local/python_code_run.py +166 -166
  60. janito/tools/adapters/local/python_command_run.py +164 -164
  61. janito/tools/adapters/local/python_file_run.py +163 -163
  62. janito/tools/adapters/local/run_bash_command.py +176 -176
  63. janito/tools/adapters/local/run_powershell_command.py +219 -219
  64. janito/tools/adapters/local/search_text/__init__.py +1 -1
  65. janito/tools/adapters/local/search_text/core.py +201 -201
  66. janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
  67. janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
  68. janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
  69. janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
  70. janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
  71. janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
  72. janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
  73. janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
  74. janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
  75. janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
  76. janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
  77. janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
  78. janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
  79. janito/tools/adapters/local/view_file.py +167 -167
  80. janito/tools/inspect_registry.py +17 -17
  81. janito/tools/tool_base.py +105 -105
  82. janito/tools/tool_events.py +58 -58
  83. janito/tools/tool_run_exception.py +12 -12
  84. janito/tools/tool_use_tracker.py +81 -81
  85. janito/tools/tool_utils.py +45 -45
  86. janito/tools/tools_schema.py +104 -104
  87. janito/version.py +4 -4
  88. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/METADATA +390 -388
  89. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/RECORD +93 -93
  90. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/WHEEL +0 -0
  91. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/entry_points.txt +0 -0
  92. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/licenses/LICENSE +0 -0
  93. {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/top_level.txt +0 -0
@@ -1,219 +1,219 @@
1
- from janito.tools.tool_base import ToolBase
2
- from janito.report_events import ReportAction
3
- from janito.tools.adapters.local.adapter import register_local_tool
4
- from janito.i18n import tr
5
- import subprocess
6
- import os
7
- import tempfile
8
- import threading
9
-
10
-
11
- @register_local_tool
12
- class RunPowershellCommandTool(ToolBase):
13
- """
14
- Execute a non-interactive command using the PowerShell shell and capture live output.
15
- This tool explicitly invokes 'powershell.exe' (on Windows) or 'pwsh' (on other platforms if available).
16
- All commands are automatically prepended with UTF-8 output encoding:
17
- $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
18
- For file output, it is recommended to use -Encoding utf8 in your PowerShell commands (e.g., Out-File -Encoding utf8) to ensure correct file encoding.
19
-
20
- Parameters:
21
- command (str): The PowerShell command to execute. This string is passed directly to PowerShell using the --Command argument (not as a script file).
22
- timeout (int): Timeout in seconds for the command. Defaults to 60.
23
- require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
24
- requires_user_input (bool): If True, warns that the command may require user input and might hang. Defaults to False. Non-interactive commands are preferred for automation and reliability.
25
-
26
- Returns:
27
- str: Output and status message, or file paths/line counts if output is large.
28
- """
29
- provides_execution = True
30
- tool_name = "run_powershell_command"
31
-
32
- def _confirm_and_warn(self, command, require_confirmation, requires_user_input):
33
- if requires_user_input:
34
- self.report_warning(
35
- tr(
36
- "⚠️ Warning: This command might be interactive, require user input, and might hang."
37
- ),
38
- ReportAction.EXECUTE,
39
- )
40
- if require_confirmation:
41
- confirmed = self.ask_user_confirmation(
42
- tr(
43
- "About to run PowerShell command: {command}\nContinue?",
44
- command=command,
45
- )
46
- )
47
- if not confirmed:
48
- self.report_warning(
49
- tr("⚠️ Execution cancelled by user."), ReportAction.EXECUTE
50
- )
51
- return False
52
- return True
53
-
54
- def _launch_process(self, shell_exe, command_with_encoding):
55
- env = os.environ.copy()
56
- env["PYTHONIOENCODING"] = "utf-8"
57
- return subprocess.Popen(
58
- [
59
- shell_exe,
60
- "-NoProfile",
61
- "-ExecutionPolicy",
62
- "Bypass",
63
- "-Command",
64
- command_with_encoding,
65
- ],
66
- stdout=subprocess.PIPE,
67
- stderr=subprocess.PIPE,
68
- text=True,
69
- bufsize=1,
70
- universal_newlines=True,
71
- encoding="utf-8",
72
- env=env,
73
- )
74
-
75
- def _stream_output(self, stream, file_obj, report_func, count_func, counter):
76
- for line in stream:
77
- file_obj.write(line)
78
- file_obj.flush()
79
- report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
80
- if count_func == "stdout":
81
- counter["stdout"] += 1
82
- else:
83
- counter["stderr"] += 1
84
-
85
- def _format_result(
86
- self, requires_user_input, return_code, stdout_file, stderr_file, max_lines=100
87
- ):
88
- warning_msg = ""
89
- if requires_user_input:
90
- warning_msg = tr(
91
- "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
92
- )
93
- with open(stdout_file.name, "r", encoding="utf-8", errors="replace") as out_f:
94
- stdout_content = out_f.read()
95
- with open(stderr_file.name, "r", encoding="utf-8", errors="replace") as err_f:
96
- stderr_content = err_f.read()
97
- stdout_lines = stdout_content.count("\n")
98
- stderr_lines = stderr_content.count("\n")
99
- if stdout_lines <= max_lines and stderr_lines <= max_lines:
100
- result = warning_msg + tr(
101
- "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
102
- return_code=return_code,
103
- stdout_content=stdout_content,
104
- )
105
- if stderr_content.strip():
106
- result += tr(
107
- "\n--- STDERR ---\n{stderr_content}",
108
- stderr_content=stderr_content,
109
- )
110
- return result
111
- else:
112
- result = warning_msg + tr(
113
- "stdout_file: {stdout_file} (lines: {stdout_lines})\n",
114
- stdout_file=stdout_file.name,
115
- stdout_lines=stdout_lines,
116
- )
117
- if stderr_lines > 0 and stderr_content.strip():
118
- result += tr(
119
- "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
120
- stderr_file=stderr_file.name,
121
- stderr_lines=stderr_lines,
122
- )
123
- result += tr(
124
- "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
125
- return_code=return_code,
126
- )
127
- return result
128
-
129
- def run(
130
- self,
131
- command: str,
132
- timeout: int = 60,
133
- require_confirmation: bool = False,
134
- requires_user_input: bool = False,
135
- ) -> str:
136
- if not command.strip():
137
- self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
138
- return tr("Warning: Empty command provided. Operation skipped.")
139
- encoding_prefix = "$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
140
- command_with_encoding = encoding_prefix + command
141
- self.report_action(
142
- tr("🖥️ Running PowerShell command: {command} ...\n", command=command),
143
- ReportAction.EXECUTE,
144
- )
145
- if not self._confirm_and_warn(
146
- command, require_confirmation, requires_user_input
147
- ):
148
- return tr("❌ Command execution cancelled by user.")
149
- from janito.platform_discovery import PlatformDiscovery
150
-
151
- pd = PlatformDiscovery()
152
- shell_exe = "powershell.exe" if pd.is_windows() else "pwsh"
153
- try:
154
- with (
155
- tempfile.NamedTemporaryFile(
156
- mode="w+",
157
- prefix="run_powershell_stdout_",
158
- delete=False,
159
- encoding="utf-8",
160
- ) as stdout_file,
161
- tempfile.NamedTemporaryFile(
162
- mode="w+",
163
- prefix="run_powershell_stderr_",
164
- delete=False,
165
- encoding="utf-8",
166
- ) as stderr_file,
167
- ):
168
- process = self._launch_process(shell_exe, command_with_encoding)
169
- counter = {"stdout": 0, "stderr": 0}
170
- stdout_thread = threading.Thread(
171
- target=self._stream_output,
172
- args=(
173
- process.stdout,
174
- stdout_file,
175
- self.report_stdout,
176
- "stdout",
177
- counter,
178
- ),
179
- )
180
- stderr_thread = threading.Thread(
181
- target=self._stream_output,
182
- args=(
183
- process.stderr,
184
- stderr_file,
185
- self.report_stderr,
186
- "stderr",
187
- counter,
188
- ),
189
- )
190
- stdout_thread.start()
191
- stderr_thread.start()
192
- try:
193
- return_code = process.wait(timeout=timeout)
194
- except subprocess.TimeoutExpired:
195
- process.kill()
196
- self.report_error(
197
- tr(
198
- " ❌ Timed out after {timeout} seconds.",
199
- timeout=timeout,
200
- ),
201
- ReportAction.EXECUTE,
202
- )
203
- return tr(
204
- "Command timed out after {timeout} seconds.", timeout=timeout
205
- )
206
- stdout_thread.join()
207
- stderr_thread.join()
208
- stdout_file.flush()
209
- stderr_file.flush()
210
- self.report_success(
211
- tr(" ✅ return code {return_code}", return_code=return_code),
212
- ReportAction.EXECUTE,
213
- )
214
- return self._format_result(
215
- requires_user_input, return_code, stdout_file, stderr_file
216
- )
217
- except Exception as e:
218
- self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
219
- return tr("Error running command: {error}", error=e)
1
+ from janito.tools.tool_base import ToolBase
2
+ from janito.report_events import ReportAction
3
+ from janito.tools.adapters.local.adapter import register_local_tool
4
+ from janito.i18n import tr
5
+ import subprocess
6
+ import os
7
+ import tempfile
8
+ import threading
9
+
10
+
11
+ @register_local_tool
12
+ class RunPowershellCommandTool(ToolBase):
13
+ """
14
+ Execute a non-interactive command using the PowerShell shell and capture live output.
15
+ This tool explicitly invokes 'powershell.exe' (on Windows) or 'pwsh' (on other platforms if available).
16
+ All commands are automatically prepended with UTF-8 output encoding:
17
+ $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
18
+ For file output, it is recommended to use -Encoding utf8 in your PowerShell commands (e.g., Out-File -Encoding utf8) to ensure correct file encoding.
19
+
20
+ Parameters:
21
+ command (str): The PowerShell command to execute. This string is passed directly to PowerShell using the --Command argument (not as a script file).
22
+ timeout (int): Timeout in seconds for the command. Defaults to 60.
23
+ require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
24
+ requires_user_input (bool): If True, warns that the command may require user input and might hang. Defaults to False. Non-interactive commands are preferred for automation and reliability.
25
+
26
+ Returns:
27
+ str: Output and status message, or file paths/line counts if output is large.
28
+ """
29
+ provides_execution = True
30
+ tool_name = "run_powershell_command"
31
+
32
+ def _confirm_and_warn(self, command, require_confirmation, requires_user_input):
33
+ if requires_user_input:
34
+ self.report_warning(
35
+ tr(
36
+ "⚠️ Warning: This command might be interactive, require user input, and might hang."
37
+ ),
38
+ ReportAction.EXECUTE,
39
+ )
40
+ if require_confirmation:
41
+ confirmed = self.ask_user_confirmation(
42
+ tr(
43
+ "About to run PowerShell command: {command}\nContinue?",
44
+ command=command,
45
+ )
46
+ )
47
+ if not confirmed:
48
+ self.report_warning(
49
+ tr("⚠️ Execution cancelled by user."), ReportAction.EXECUTE
50
+ )
51
+ return False
52
+ return True
53
+
54
+ def _launch_process(self, shell_exe, command_with_encoding):
55
+ env = os.environ.copy()
56
+ env["PYTHONIOENCODING"] = "utf-8"
57
+ return subprocess.Popen(
58
+ [
59
+ shell_exe,
60
+ "-NoProfile",
61
+ "-ExecutionPolicy",
62
+ "Bypass",
63
+ "-Command",
64
+ command_with_encoding,
65
+ ],
66
+ stdout=subprocess.PIPE,
67
+ stderr=subprocess.PIPE,
68
+ text=True,
69
+ bufsize=1,
70
+ universal_newlines=True,
71
+ encoding="utf-8",
72
+ env=env,
73
+ )
74
+
75
+ def _stream_output(self, stream, file_obj, report_func, count_func, counter):
76
+ for line in stream:
77
+ file_obj.write(line)
78
+ file_obj.flush()
79
+ report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
80
+ if count_func == "stdout":
81
+ counter["stdout"] += 1
82
+ else:
83
+ counter["stderr"] += 1
84
+
85
+ def _format_result(
86
+ self, requires_user_input, return_code, stdout_file, stderr_file, max_lines=100
87
+ ):
88
+ warning_msg = ""
89
+ if requires_user_input:
90
+ warning_msg = tr(
91
+ "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
92
+ )
93
+ with open(stdout_file.name, "r", encoding="utf-8", errors="replace") as out_f:
94
+ stdout_content = out_f.read()
95
+ with open(stderr_file.name, "r", encoding="utf-8", errors="replace") as err_f:
96
+ stderr_content = err_f.read()
97
+ stdout_lines = stdout_content.count("\n")
98
+ stderr_lines = stderr_content.count("\n")
99
+ if stdout_lines <= max_lines and stderr_lines <= max_lines:
100
+ result = warning_msg + tr(
101
+ "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
102
+ return_code=return_code,
103
+ stdout_content=stdout_content,
104
+ )
105
+ if stderr_content.strip():
106
+ result += tr(
107
+ "\n--- STDERR ---\n{stderr_content}",
108
+ stderr_content=stderr_content,
109
+ )
110
+ return result
111
+ else:
112
+ result = warning_msg + tr(
113
+ "stdout_file: {stdout_file} (lines: {stdout_lines})\n",
114
+ stdout_file=stdout_file.name,
115
+ stdout_lines=stdout_lines,
116
+ )
117
+ if stderr_lines > 0 and stderr_content.strip():
118
+ result += tr(
119
+ "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
120
+ stderr_file=stderr_file.name,
121
+ stderr_lines=stderr_lines,
122
+ )
123
+ result += tr(
124
+ "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
125
+ return_code=return_code,
126
+ )
127
+ return result
128
+
129
+ def run(
130
+ self,
131
+ command: str,
132
+ timeout: int = 60,
133
+ require_confirmation: bool = False,
134
+ requires_user_input: bool = False,
135
+ ) -> str:
136
+ if not command.strip():
137
+ self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
138
+ return tr("Warning: Empty command provided. Operation skipped.")
139
+ encoding_prefix = "$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
140
+ command_with_encoding = encoding_prefix + command
141
+ self.report_action(
142
+ tr("🖥️ Running PowerShell command: {command} ...\n", command=command),
143
+ ReportAction.EXECUTE,
144
+ )
145
+ if not self._confirm_and_warn(
146
+ command, require_confirmation, requires_user_input
147
+ ):
148
+ return tr("❌ Command execution cancelled by user.")
149
+ from janito.platform_discovery import PlatformDiscovery
150
+
151
+ pd = PlatformDiscovery()
152
+ shell_exe = "powershell.exe" if pd.is_windows() else "pwsh"
153
+ try:
154
+ with (
155
+ tempfile.NamedTemporaryFile(
156
+ mode="w+",
157
+ prefix="run_powershell_stdout_",
158
+ delete=False,
159
+ encoding="utf-8",
160
+ ) as stdout_file,
161
+ tempfile.NamedTemporaryFile(
162
+ mode="w+",
163
+ prefix="run_powershell_stderr_",
164
+ delete=False,
165
+ encoding="utf-8",
166
+ ) as stderr_file,
167
+ ):
168
+ process = self._launch_process(shell_exe, command_with_encoding)
169
+ counter = {"stdout": 0, "stderr": 0}
170
+ stdout_thread = threading.Thread(
171
+ target=self._stream_output,
172
+ args=(
173
+ process.stdout,
174
+ stdout_file,
175
+ self.report_stdout,
176
+ "stdout",
177
+ counter,
178
+ ),
179
+ )
180
+ stderr_thread = threading.Thread(
181
+ target=self._stream_output,
182
+ args=(
183
+ process.stderr,
184
+ stderr_file,
185
+ self.report_stderr,
186
+ "stderr",
187
+ counter,
188
+ ),
189
+ )
190
+ stdout_thread.start()
191
+ stderr_thread.start()
192
+ try:
193
+ return_code = process.wait(timeout=timeout)
194
+ except subprocess.TimeoutExpired:
195
+ process.kill()
196
+ self.report_error(
197
+ tr(
198
+ " ❌ Timed out after {timeout} seconds.",
199
+ timeout=timeout,
200
+ ),
201
+ ReportAction.EXECUTE,
202
+ )
203
+ return tr(
204
+ "Command timed out after {timeout} seconds.", timeout=timeout
205
+ )
206
+ stdout_thread.join()
207
+ stderr_thread.join()
208
+ stdout_file.flush()
209
+ stderr_file.flush()
210
+ self.report_success(
211
+ tr(" ✅ return code {return_code}", return_code=return_code),
212
+ ReportAction.EXECUTE,
213
+ )
214
+ return self._format_result(
215
+ requires_user_input, return_code, stdout_file, stderr_file
216
+ )
217
+ except Exception as e:
218
+ self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
219
+ return tr("Error running command: {error}", error=e)
@@ -1 +1 @@
1
- from .core import SearchTextTool
1
+ from .core import SearchTextTool