janito 2.2.0__py3-none-any.whl → 2.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 (130) hide show
  1. janito/__init__.py +6 -6
  2. janito/agent/setup_agent.py +14 -5
  3. janito/agent/templates/profiles/system_prompt_template_main.txt.j2 +3 -1
  4. janito/cli/chat_mode/bindings.py +6 -0
  5. janito/cli/chat_mode/session.py +16 -0
  6. janito/cli/chat_mode/shell/autocomplete.py +21 -21
  7. janito/cli/chat_mode/shell/commands/__init__.py +3 -0
  8. janito/cli/chat_mode/shell/commands/clear.py +12 -12
  9. janito/cli/chat_mode/shell/commands/exec.py +27 -0
  10. janito/cli/chat_mode/shell/commands/multi.py +51 -51
  11. janito/cli/chat_mode/shell/commands/tools.py +17 -6
  12. janito/cli/chat_mode/shell/input_history.py +62 -62
  13. janito/cli/chat_mode/shell/session/manager.py +1 -0
  14. janito/cli/chat_mode/toolbar.py +1 -0
  15. janito/cli/cli_commands/list_models.py +35 -35
  16. janito/cli/cli_commands/list_providers.py +9 -9
  17. janito/cli/cli_commands/list_tools.py +53 -53
  18. janito/cli/cli_commands/model_selection.py +50 -50
  19. janito/cli/cli_commands/model_utils.py +13 -2
  20. janito/cli/cli_commands/set_api_key.py +19 -19
  21. janito/cli/cli_commands/show_config.py +51 -51
  22. janito/cli/cli_commands/show_system_prompt.py +62 -62
  23. janito/cli/config.py +2 -1
  24. janito/cli/core/__init__.py +4 -4
  25. janito/cli/core/event_logger.py +59 -59
  26. janito/cli/core/getters.py +3 -1
  27. janito/cli/core/runner.py +165 -148
  28. janito/cli/core/setters.py +5 -1
  29. janito/cli/core/unsetters.py +54 -54
  30. janito/cli/main_cli.py +12 -1
  31. janito/cli/prompt_core.py +5 -2
  32. janito/cli/rich_terminal_reporter.py +22 -3
  33. janito/cli/single_shot_mode/__init__.py +6 -6
  34. janito/cli/single_shot_mode/handler.py +11 -1
  35. janito/cli/verbose_output.py +1 -1
  36. janito/config.py +5 -5
  37. janito/config_manager.py +2 -0
  38. janito/driver_events.py +14 -0
  39. janito/drivers/anthropic/driver.py +113 -113
  40. janito/drivers/azure_openai/driver.py +38 -3
  41. janito/drivers/driver_registry.py +0 -2
  42. janito/drivers/openai/driver.py +196 -36
  43. janito/formatting_token.py +54 -54
  44. janito/i18n/__init__.py +35 -35
  45. janito/i18n/messages.py +23 -23
  46. janito/i18n/pt.py +47 -47
  47. janito/llm/__init__.py +5 -5
  48. janito/llm/agent.py +443 -443
  49. janito/llm/auth.py +1 -0
  50. janito/llm/driver.py +7 -1
  51. janito/llm/driver_config.py +1 -0
  52. janito/llm/driver_config_builder.py +34 -34
  53. janito/llm/driver_input.py +12 -12
  54. janito/llm/message_parts.py +60 -60
  55. janito/llm/model.py +38 -38
  56. janito/llm/provider.py +196 -196
  57. janito/provider_config.py +7 -3
  58. janito/provider_registry.py +176 -158
  59. janito/providers/__init__.py +1 -0
  60. janito/providers/anthropic/model_info.py +22 -22
  61. janito/providers/anthropic/provider.py +2 -2
  62. janito/providers/azure_openai/model_info.py +7 -6
  63. janito/providers/azure_openai/provider.py +30 -2
  64. janito/providers/deepseek/__init__.py +1 -1
  65. janito/providers/deepseek/model_info.py +16 -16
  66. janito/providers/deepseek/provider.py +91 -91
  67. janito/providers/google/model_info.py +21 -29
  68. janito/providers/google/provider.py +49 -38
  69. janito/providers/mistralai/provider.py +2 -2
  70. janito/providers/provider_static_info.py +2 -3
  71. janito/tools/adapters/__init__.py +1 -1
  72. janito/tools/adapters/local/adapter.py +33 -11
  73. janito/tools/adapters/local/ask_user.py +102 -102
  74. janito/tools/adapters/local/copy_file.py +84 -84
  75. janito/tools/adapters/local/create_directory.py +69 -69
  76. janito/tools/adapters/local/create_file.py +82 -82
  77. janito/tools/adapters/local/delete_text_in_file.py +4 -7
  78. janito/tools/adapters/local/fetch_url.py +97 -97
  79. janito/tools/adapters/local/find_files.py +138 -138
  80. janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
  81. janito/tools/adapters/local/get_file_outline/core.py +117 -117
  82. janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
  83. janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
  84. janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
  85. janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
  86. janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
  87. janito/tools/adapters/local/move_file.py +3 -13
  88. janito/tools/adapters/local/python_code_run.py +166 -166
  89. janito/tools/adapters/local/python_command_run.py +164 -164
  90. janito/tools/adapters/local/python_file_run.py +163 -163
  91. janito/tools/adapters/local/remove_directory.py +6 -17
  92. janito/tools/adapters/local/remove_file.py +4 -10
  93. janito/tools/adapters/local/replace_text_in_file.py +6 -9
  94. janito/tools/adapters/local/run_bash_command.py +176 -176
  95. janito/tools/adapters/local/run_powershell_command.py +219 -219
  96. janito/tools/adapters/local/search_text/__init__.py +1 -1
  97. janito/tools/adapters/local/search_text/core.py +201 -201
  98. janito/tools/adapters/local/search_text/match_lines.py +1 -1
  99. janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
  100. janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
  101. janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
  102. janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
  103. janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
  104. janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
  105. janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
  106. janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
  107. janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
  108. janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
  109. janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
  110. janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
  111. janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
  112. janito/tools/adapters/local/view_file.py +167 -167
  113. janito/tools/inspect_registry.py +17 -17
  114. janito/tools/tool_base.py +105 -105
  115. janito/tools/tool_events.py +58 -58
  116. janito/tools/tool_run_exception.py +12 -12
  117. janito/tools/tool_use_tracker.py +81 -81
  118. janito/tools/tool_utils.py +45 -45
  119. janito/tools/tools_adapter.py +78 -6
  120. janito/tools/tools_schema.py +104 -104
  121. janito/version.py +4 -4
  122. {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/METADATA +388 -251
  123. janito-2.3.0.dist-info/RECORD +181 -0
  124. janito/drivers/google_genai/driver.py +0 -54
  125. janito/drivers/google_genai/schema_generator.py +0 -67
  126. janito-2.2.0.dist-info/RECORD +0 -182
  127. {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/WHEEL +0 -0
  128. {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/entry_points.txt +0 -0
  129. {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/licenses/LICENSE +0 -0
  130. {janito-2.2.0.dist-info → janito-2.3.0.dist-info}/top_level.txt +0 -0
@@ -1,176 +1,176 @@
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 tempfile
7
- import sys
8
- import os
9
- import threading
10
-
11
-
12
- @register_local_tool
13
- class RunBashCommandTool(ToolBase):
14
- """
15
- Execute a non-interactive command using the bash shell and capture live output.
16
- This tool explicitly invokes the 'bash' shell (not just the system default shell), so it requires bash to be installed and available in the system PATH. On Windows, this will only work if bash is available (e.g., via WSL, Git Bash, or similar).
17
-
18
- Parameters:
19
- command (str): The bash command to execute.
20
- timeout (int): Timeout in seconds for the command. Defaults to 60.
21
- require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
22
- 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.
23
-
24
- Returns:
25
- str: File paths and line counts for stdout and stderr.
26
- """
27
- provides_execution = True
28
- tool_name = "run_bash_command"
29
-
30
- def _stream_output(self, stream, file_obj, report_func, count_func, counter):
31
- for line in stream:
32
- file_obj.write(line)
33
- file_obj.flush()
34
- report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
35
- if count_func == "stdout":
36
- counter["stdout"] += 1
37
- else:
38
- counter["stderr"] += 1
39
-
40
- def run(
41
- self,
42
- command: str,
43
- timeout: int = 60,
44
- require_confirmation: bool = False,
45
- requires_user_input: bool = False,
46
- ) -> str:
47
- if not command.strip():
48
- self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
49
- return tr("Warning: Empty command provided. Operation skipped.")
50
- self.report_action(
51
- tr("🖥️ Run bash command: {command} ...\n", command=command),
52
- ReportAction.EXECUTE,
53
- )
54
- if requires_user_input:
55
- self.report_warning(
56
- tr(
57
- "⚠️ Warning: This command might be interactive, require user input, and might hang."
58
- ),
59
- ReportAction.EXECUTE,
60
- )
61
- sys.stdout.flush()
62
- try:
63
- with (
64
- tempfile.NamedTemporaryFile(
65
- mode="w+", prefix="run_bash_stdout_", delete=False, encoding="utf-8"
66
- ) as stdout_file,
67
- tempfile.NamedTemporaryFile(
68
- mode="w+", prefix="run_bash_stderr_", delete=False, encoding="utf-8"
69
- ) as stderr_file,
70
- ):
71
- env = os.environ.copy()
72
- env["PYTHONIOENCODING"] = "utf-8"
73
- env["LC_ALL"] = "C.UTF-8"
74
- env["LANG"] = "C.UTF-8"
75
- process = subprocess.Popen(
76
- ["bash", "-c", command],
77
- stdout=subprocess.PIPE,
78
- stderr=subprocess.PIPE,
79
- text=True,
80
- encoding="utf-8",
81
- bufsize=1,
82
- env=env,
83
- )
84
- counter = {"stdout": 0, "stderr": 0}
85
- stdout_thread = threading.Thread(
86
- target=self._stream_output,
87
- args=(
88
- process.stdout,
89
- stdout_file,
90
- self.report_stdout,
91
- "stdout",
92
- counter,
93
- ),
94
- )
95
- stderr_thread = threading.Thread(
96
- target=self._stream_output,
97
- args=(
98
- process.stderr,
99
- stderr_file,
100
- self.report_stderr,
101
- "stderr",
102
- counter,
103
- ),
104
- )
105
- stdout_thread.start()
106
- stderr_thread.start()
107
- try:
108
- return_code = process.wait(timeout=timeout)
109
- except subprocess.TimeoutExpired:
110
- process.kill()
111
- self.report_error(
112
- tr(
113
- " ❌ Timed out after {timeout} seconds.",
114
- timeout=timeout,
115
- ),
116
- ReportAction.EXECUTE,
117
- )
118
- return tr(
119
- "Command timed out after {timeout} seconds.", timeout=timeout
120
- )
121
- stdout_thread.join()
122
- stderr_thread.join()
123
- stdout_file.flush()
124
- stderr_file.flush()
125
- self.report_success(
126
- tr(
127
- " ✅ return code {return_code}",
128
- return_code=return_code,
129
- ),
130
- ReportAction.EXECUTE,
131
- )
132
- max_lines = 100
133
- # Read back the output for summary
134
- stdout_file.seek(0)
135
- stderr_file.seek(0)
136
- stdout_content = stdout_file.read()
137
- stderr_content = stderr_file.read()
138
- stdout_lines = counter["stdout"]
139
- stderr_lines = counter["stderr"]
140
- warning_msg = ""
141
- if requires_user_input:
142
- warning_msg = tr(
143
- "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
144
- )
145
- if stdout_lines <= max_lines and stderr_lines <= max_lines:
146
- result = warning_msg + tr(
147
- "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
148
- return_code=return_code,
149
- stdout_content=stdout_content,
150
- )
151
- if stderr_content.strip():
152
- result += tr(
153
- "\n--- STDERR ---\n{stderr_content}",
154
- stderr_content=stderr_content,
155
- )
156
- return result
157
- else:
158
- result = warning_msg + tr(
159
- "[LARGE OUTPUT]\nstdout_file: {stdout_file} (lines: {stdout_lines})\n",
160
- stdout_file=stdout_file.name,
161
- stdout_lines=stdout_lines,
162
- )
163
- if stderr_lines > 0:
164
- result += tr(
165
- "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
166
- stderr_file=stderr_file.name,
167
- stderr_lines=stderr_lines,
168
- )
169
- result += tr(
170
- "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
171
- return_code=return_code,
172
- )
173
- return result
174
- except Exception as e:
175
- self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
176
- 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 tempfile
7
+ import sys
8
+ import os
9
+ import threading
10
+
11
+
12
+ @register_local_tool
13
+ class RunBashCommandTool(ToolBase):
14
+ """
15
+ Execute a non-interactive command using the bash shell and capture live output.
16
+ This tool explicitly invokes the 'bash' shell (not just the system default shell), so it requires bash to be installed and available in the system PATH. On Windows, this will only work if bash is available (e.g., via WSL, Git Bash, or similar).
17
+
18
+ Parameters:
19
+ command (str): The bash command to execute.
20
+ timeout (int): Timeout in seconds for the command. Defaults to 60.
21
+ require_confirmation (bool): If True, require user confirmation before running. Defaults to False.
22
+ 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.
23
+
24
+ Returns:
25
+ str: File paths and line counts for stdout and stderr.
26
+ """
27
+ provides_execution = True
28
+ tool_name = "run_bash_command"
29
+
30
+ def _stream_output(self, stream, file_obj, report_func, count_func, counter):
31
+ for line in stream:
32
+ file_obj.write(line)
33
+ file_obj.flush()
34
+ report_func(line.rstrip("\r\n"), ReportAction.EXECUTE)
35
+ if count_func == "stdout":
36
+ counter["stdout"] += 1
37
+ else:
38
+ counter["stderr"] += 1
39
+
40
+ def run(
41
+ self,
42
+ command: str,
43
+ timeout: int = 60,
44
+ require_confirmation: bool = False,
45
+ requires_user_input: bool = False,
46
+ ) -> str:
47
+ if not command.strip():
48
+ self.report_warning(tr("ℹ️ Empty command provided."), ReportAction.EXECUTE)
49
+ return tr("Warning: Empty command provided. Operation skipped.")
50
+ self.report_action(
51
+ tr("🖥️ Run bash command: {command} ...\n", command=command),
52
+ ReportAction.EXECUTE,
53
+ )
54
+ if requires_user_input:
55
+ self.report_warning(
56
+ tr(
57
+ "⚠️ Warning: This command might be interactive, require user input, and might hang."
58
+ ),
59
+ ReportAction.EXECUTE,
60
+ )
61
+ sys.stdout.flush()
62
+ try:
63
+ with (
64
+ tempfile.NamedTemporaryFile(
65
+ mode="w+", prefix="run_bash_stdout_", delete=False, encoding="utf-8"
66
+ ) as stdout_file,
67
+ tempfile.NamedTemporaryFile(
68
+ mode="w+", prefix="run_bash_stderr_", delete=False, encoding="utf-8"
69
+ ) as stderr_file,
70
+ ):
71
+ env = os.environ.copy()
72
+ env["PYTHONIOENCODING"] = "utf-8"
73
+ env["LC_ALL"] = "C.UTF-8"
74
+ env["LANG"] = "C.UTF-8"
75
+ process = subprocess.Popen(
76
+ ["bash", "-c", command],
77
+ stdout=subprocess.PIPE,
78
+ stderr=subprocess.PIPE,
79
+ text=True,
80
+ encoding="utf-8",
81
+ bufsize=1,
82
+ env=env,
83
+ )
84
+ counter = {"stdout": 0, "stderr": 0}
85
+ stdout_thread = threading.Thread(
86
+ target=self._stream_output,
87
+ args=(
88
+ process.stdout,
89
+ stdout_file,
90
+ self.report_stdout,
91
+ "stdout",
92
+ counter,
93
+ ),
94
+ )
95
+ stderr_thread = threading.Thread(
96
+ target=self._stream_output,
97
+ args=(
98
+ process.stderr,
99
+ stderr_file,
100
+ self.report_stderr,
101
+ "stderr",
102
+ counter,
103
+ ),
104
+ )
105
+ stdout_thread.start()
106
+ stderr_thread.start()
107
+ try:
108
+ return_code = process.wait(timeout=timeout)
109
+ except subprocess.TimeoutExpired:
110
+ process.kill()
111
+ self.report_error(
112
+ tr(
113
+ " ❌ Timed out after {timeout} seconds.",
114
+ timeout=timeout,
115
+ ),
116
+ ReportAction.EXECUTE,
117
+ )
118
+ return tr(
119
+ "Command timed out after {timeout} seconds.", timeout=timeout
120
+ )
121
+ stdout_thread.join()
122
+ stderr_thread.join()
123
+ stdout_file.flush()
124
+ stderr_file.flush()
125
+ self.report_success(
126
+ tr(
127
+ " ✅ return code {return_code}",
128
+ return_code=return_code,
129
+ ),
130
+ ReportAction.EXECUTE,
131
+ )
132
+ max_lines = 100
133
+ # Read back the output for summary
134
+ stdout_file.seek(0)
135
+ stderr_file.seek(0)
136
+ stdout_content = stdout_file.read()
137
+ stderr_content = stderr_file.read()
138
+ stdout_lines = counter["stdout"]
139
+ stderr_lines = counter["stderr"]
140
+ warning_msg = ""
141
+ if requires_user_input:
142
+ warning_msg = tr(
143
+ "⚠️ Warning: This command might be interactive, require user input, and might hang.\n"
144
+ )
145
+ if stdout_lines <= max_lines and stderr_lines <= max_lines:
146
+ result = warning_msg + tr(
147
+ "Return code: {return_code}\n--- STDOUT ---\n{stdout_content}",
148
+ return_code=return_code,
149
+ stdout_content=stdout_content,
150
+ )
151
+ if stderr_content.strip():
152
+ result += tr(
153
+ "\n--- STDERR ---\n{stderr_content}",
154
+ stderr_content=stderr_content,
155
+ )
156
+ return result
157
+ else:
158
+ result = warning_msg + tr(
159
+ "[LARGE OUTPUT]\nstdout_file: {stdout_file} (lines: {stdout_lines})\n",
160
+ stdout_file=stdout_file.name,
161
+ stdout_lines=stdout_lines,
162
+ )
163
+ if stderr_lines > 0:
164
+ result += tr(
165
+ "stderr_file: {stderr_file} (lines: {stderr_lines})\n",
166
+ stderr_file=stderr_file.name,
167
+ stderr_lines=stderr_lines,
168
+ )
169
+ result += tr(
170
+ "returncode: {return_code}\nUse the view_file tool to inspect the contents of these files when needed.",
171
+ return_code=return_code,
172
+ )
173
+ return result
174
+ except Exception as e:
175
+ self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.EXECUTE)
176
+ return tr("Error running command: {error}", error=e)