janito 1.14.3__py3-none-any.whl → 2.0.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 (283) hide show
  1. janito/__init__.py +6 -1
  2. janito/__main__.py +1 -1
  3. janito/agent/setup_agent.py +139 -0
  4. janito/agent/templates/profiles/{system_prompt_template_base.txt.j2 → system_prompt_template_main.txt.j2} +1 -1
  5. janito/cli/__init__.py +9 -0
  6. janito/cli/chat_mode/bindings.py +37 -0
  7. janito/cli/chat_mode/chat_entry.py +23 -0
  8. janito/cli/chat_mode/prompt_style.py +19 -0
  9. janito/cli/chat_mode/session.py +272 -0
  10. janito/{shell/prompt/completer.py → cli/chat_mode/shell/autocomplete.py} +7 -6
  11. janito/cli/chat_mode/shell/commands/__init__.py +55 -0
  12. janito/cli/chat_mode/shell/commands/base.py +9 -0
  13. janito/cli/chat_mode/shell/commands/clear.py +12 -0
  14. janito/{shell → cli/chat_mode/shell}/commands/conversation_restart.py +34 -30
  15. janito/cli/chat_mode/shell/commands/edit.py +25 -0
  16. janito/cli/chat_mode/shell/commands/help.py +16 -0
  17. janito/cli/chat_mode/shell/commands/history_view.py +93 -0
  18. janito/cli/chat_mode/shell/commands/lang.py +25 -0
  19. janito/cli/chat_mode/shell/commands/last.py +137 -0
  20. janito/cli/chat_mode/shell/commands/livelogs.py +49 -0
  21. janito/cli/chat_mode/shell/commands/multi.py +51 -0
  22. janito/cli/chat_mode/shell/commands/prompt.py +64 -0
  23. janito/cli/chat_mode/shell/commands/role.py +36 -0
  24. janito/cli/chat_mode/shell/commands/session.py +40 -0
  25. janito/{shell → cli/chat_mode/shell}/commands/session_control.py +2 -2
  26. janito/cli/chat_mode/shell/commands/termweb_log.py +92 -0
  27. janito/cli/chat_mode/shell/commands/tools.py +32 -0
  28. janito/{shell → cli/chat_mode/shell}/commands/utility.py +4 -7
  29. janito/{shell → cli/chat_mode/shell}/commands/verbose.py +5 -5
  30. janito/cli/chat_mode/shell/session/__init__.py +1 -0
  31. janito/{shell → cli/chat_mode/shell}/session/manager.py +9 -1
  32. janito/cli/chat_mode/toolbar.py +90 -0
  33. janito/cli/cli_commands/list_models.py +35 -0
  34. janito/cli/cli_commands/list_providers.py +9 -0
  35. janito/cli/cli_commands/list_tools.py +53 -0
  36. janito/cli/cli_commands/model_selection.py +50 -0
  37. janito/cli/cli_commands/model_utils.py +84 -0
  38. janito/cli/cli_commands/set_api_key.py +19 -0
  39. janito/cli/cli_commands/show_config.py +51 -0
  40. janito/cli/cli_commands/show_system_prompt.py +62 -0
  41. janito/cli/config.py +28 -0
  42. janito/cli/console.py +3 -0
  43. janito/cli/core/__init__.py +4 -0
  44. janito/cli/core/event_logger.py +59 -0
  45. janito/cli/core/getters.py +31 -0
  46. janito/cli/core/runner.py +141 -0
  47. janito/cli/core/setters.py +174 -0
  48. janito/cli/core/unsetters.py +54 -0
  49. janito/cli/main.py +8 -196
  50. janito/cli/main_cli.py +312 -0
  51. janito/cli/prompt_core.py +230 -0
  52. janito/cli/prompt_handler.py +6 -0
  53. janito/cli/rich_terminal_reporter.py +101 -0
  54. janito/cli/single_shot_mode/__init__.py +6 -0
  55. janito/cli/single_shot_mode/handler.py +137 -0
  56. janito/cli/termweb_starter.py +73 -24
  57. janito/cli/utils.py +25 -0
  58. janito/cli/verbose_output.py +196 -0
  59. janito/config.py +5 -0
  60. janito/config_manager.py +110 -0
  61. janito/conversation_history.py +30 -0
  62. janito/{agent/tools_utils/dir_walk_utils.py → dir_walk_utils.py} +3 -2
  63. janito/driver_events.py +98 -0
  64. janito/drivers/anthropic/driver.py +113 -0
  65. janito/drivers/azure_openai/driver.py +36 -0
  66. janito/drivers/driver_registry.py +33 -0
  67. janito/drivers/google_genai/driver.py +54 -0
  68. janito/drivers/google_genai/schema_generator.py +67 -0
  69. janito/drivers/mistralai/driver.py +41 -0
  70. janito/drivers/openai/driver.py +334 -0
  71. janito/event_bus/__init__.py +2 -0
  72. janito/event_bus/bus.py +68 -0
  73. janito/event_bus/event.py +15 -0
  74. janito/event_bus/handler.py +31 -0
  75. janito/event_bus/queue_bus.py +57 -0
  76. janito/exceptions.py +23 -0
  77. janito/formatting_token.py +54 -0
  78. janito/i18n/pt.py +1 -0
  79. janito/llm/__init__.py +5 -0
  80. janito/llm/agent.py +443 -0
  81. janito/llm/auth.py +62 -0
  82. janito/llm/driver.py +239 -0
  83. janito/llm/driver_config.py +34 -0
  84. janito/llm/driver_config_builder.py +34 -0
  85. janito/llm/driver_input.py +12 -0
  86. janito/llm/message_parts.py +60 -0
  87. janito/llm/model.py +38 -0
  88. janito/llm/provider.py +187 -0
  89. janito/perf_singleton.py +3 -0
  90. janito/performance_collector.py +167 -0
  91. janito/provider_config.py +98 -0
  92. janito/provider_registry.py +152 -0
  93. janito/providers/__init__.py +7 -0
  94. janito/providers/anthropic/model_info.py +22 -0
  95. janito/providers/anthropic/provider.py +65 -0
  96. janito/providers/azure_openai/model_info.py +15 -0
  97. janito/providers/azure_openai/provider.py +72 -0
  98. janito/providers/deepseek/__init__.py +1 -0
  99. janito/providers/deepseek/model_info.py +16 -0
  100. janito/providers/deepseek/provider.py +91 -0
  101. janito/providers/google/__init__.py +1 -0
  102. janito/providers/google/model_info.py +40 -0
  103. janito/providers/google/provider.py +69 -0
  104. janito/providers/mistralai/model_info.py +37 -0
  105. janito/providers/mistralai/provider.py +69 -0
  106. janito/providers/openai/__init__.py +1 -0
  107. janito/providers/openai/model_info.py +137 -0
  108. janito/providers/openai/provider.py +107 -0
  109. janito/providers/openai/schema_generator.py +63 -0
  110. janito/providers/provider_static_info.py +21 -0
  111. janito/providers/registry.py +26 -0
  112. janito/report_events.py +38 -0
  113. janito/termweb/app.py +1 -1
  114. janito/tools/__init__.py +16 -0
  115. janito/tools/adapters/__init__.py +1 -0
  116. janito/tools/adapters/local/__init__.py +54 -0
  117. janito/tools/adapters/local/adapter.py +92 -0
  118. janito/{agent/tools → tools/adapters/local}/ask_user.py +30 -13
  119. janito/tools/adapters/local/copy_file.py +84 -0
  120. janito/{agent/tools → tools/adapters/local}/create_directory.py +11 -10
  121. janito/tools/adapters/local/create_file.py +82 -0
  122. janito/tools/adapters/local/delete_text_in_file.py +136 -0
  123. janito/{agent/tools → tools/adapters/local}/fetch_url.py +18 -19
  124. janito/tools/adapters/local/find_files.py +140 -0
  125. janito/tools/adapters/local/get_file_outline/core.py +151 -0
  126. janito/{agent/tools → tools/adapters/local}/get_file_outline/python_outline.py +125 -0
  127. janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -0
  128. janito/{agent/tools → tools/adapters/local}/get_file_outline/search_outline.py +12 -7
  129. janito/{agent/tools → tools/adapters/local}/move_file.py +13 -9
  130. janito/tools/adapters/local/open_html_in_browser.py +34 -0
  131. janito/{agent/tools → tools/adapters/local}/open_url.py +7 -5
  132. janito/tools/adapters/local/python_code_run.py +165 -0
  133. janito/tools/adapters/local/python_command_run.py +163 -0
  134. janito/tools/adapters/local/python_file_run.py +162 -0
  135. janito/{agent/tools → tools/adapters/local}/remove_directory.py +15 -9
  136. janito/{agent/tools → tools/adapters/local}/remove_file.py +17 -14
  137. janito/{agent/tools → tools/adapters/local}/replace_text_in_file.py +27 -22
  138. janito/tools/adapters/local/run_bash_command.py +176 -0
  139. janito/tools/adapters/local/run_powershell_command.py +219 -0
  140. janito/{agent/tools → tools/adapters/local}/search_text/core.py +32 -12
  141. janito/{agent/tools → tools/adapters/local}/search_text/match_lines.py +13 -4
  142. janito/{agent/tools → tools/adapters/local}/search_text/pattern_utils.py +12 -4
  143. janito/{agent/tools → tools/adapters/local}/search_text/traverse_directory.py +15 -2
  144. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/core.py +12 -11
  145. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +1 -1
  146. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +1 -1
  147. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +1 -1
  148. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +1 -1
  149. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +1 -1
  150. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +1 -1
  151. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +1 -1
  152. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +1 -1
  153. janito/{agent/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +1 -1
  154. janito/{agent/tools/get_lines.py → tools/adapters/local/view_file.py} +45 -27
  155. janito/tools/inspect_registry.py +17 -0
  156. janito/tools/tool_base.py +105 -0
  157. janito/tools/tool_events.py +58 -0
  158. janito/tools/tool_run_exception.py +12 -0
  159. janito/{agent → tools}/tool_use_tracker.py +2 -4
  160. janito/{agent/tools_utils/utils.py → tools/tool_utils.py} +18 -9
  161. janito/tools/tools_adapter.py +207 -0
  162. janito/tools/tools_schema.py +104 -0
  163. janito/utils.py +11 -0
  164. janito/version.py +4 -0
  165. janito-2.0.1.dist-info/METADATA +232 -0
  166. janito-2.0.1.dist-info/RECORD +181 -0
  167. janito/agent/__init__.py +0 -0
  168. janito/agent/api_exceptions.py +0 -4
  169. janito/agent/config.py +0 -147
  170. janito/agent/config_defaults.py +0 -12
  171. janito/agent/config_utils.py +0 -0
  172. janito/agent/content_handler.py +0 -0
  173. janito/agent/conversation.py +0 -238
  174. janito/agent/conversation_api.py +0 -306
  175. janito/agent/conversation_exceptions.py +0 -18
  176. janito/agent/conversation_tool_calls.py +0 -39
  177. janito/agent/conversation_ui.py +0 -17
  178. janito/agent/event.py +0 -24
  179. janito/agent/event_dispatcher.py +0 -24
  180. janito/agent/event_handler_protocol.py +0 -5
  181. janito/agent/event_system.py +0 -15
  182. janito/agent/llm_conversation_history.py +0 -82
  183. janito/agent/message_handler.py +0 -20
  184. janito/agent/message_handler_protocol.py +0 -5
  185. janito/agent/openai_client.py +0 -149
  186. janito/agent/openai_schema_generator.py +0 -187
  187. janito/agent/profile_manager.py +0 -96
  188. janito/agent/queued_message_handler.py +0 -50
  189. janito/agent/rich_live.py +0 -32
  190. janito/agent/rich_message_handler.py +0 -115
  191. janito/agent/runtime_config.py +0 -36
  192. janito/agent/test_handler_protocols.py +0 -47
  193. janito/agent/test_openai_schema_generator.py +0 -93
  194. janito/agent/tests/__init__.py +0 -1
  195. janito/agent/tool_base.py +0 -63
  196. janito/agent/tool_executor.py +0 -122
  197. janito/agent/tool_registry.py +0 -49
  198. janito/agent/tools/__init__.py +0 -47
  199. janito/agent/tools/create_file.py +0 -59
  200. janito/agent/tools/delete_text_in_file.py +0 -97
  201. janito/agent/tools/find_files.py +0 -106
  202. janito/agent/tools/get_file_outline/core.py +0 -81
  203. janito/agent/tools/present_choices.py +0 -64
  204. janito/agent/tools/python_command_runner.py +0 -201
  205. janito/agent/tools/python_file_runner.py +0 -199
  206. janito/agent/tools/python_stdin_runner.py +0 -208
  207. janito/agent/tools/replace_file.py +0 -72
  208. janito/agent/tools/run_bash_command.py +0 -218
  209. janito/agent/tools/run_powershell_command.py +0 -251
  210. janito/agent/tools_utils/__init__.py +0 -1
  211. janito/agent/tools_utils/action_type.py +0 -7
  212. janito/agent/tools_utils/test_gitignore_utils.py +0 -46
  213. janito/cli/_livereload_log_utils.py +0 -13
  214. janito/cli/_print_config.py +0 -96
  215. janito/cli/_termweb_log_utils.py +0 -17
  216. janito/cli/_utils.py +0 -9
  217. janito/cli/arg_parser.py +0 -272
  218. janito/cli/cli_main.py +0 -281
  219. janito/cli/config_commands.py +0 -211
  220. janito/cli/config_runner.py +0 -35
  221. janito/cli/formatting_runner.py +0 -12
  222. janito/cli/livereload_starter.py +0 -60
  223. janito/cli/logging_setup.py +0 -38
  224. janito/cli/one_shot.py +0 -80
  225. janito/livereload/app.py +0 -25
  226. janito/rich_utils.py +0 -59
  227. janito/shell/__init__.py +0 -0
  228. janito/shell/commands/__init__.py +0 -61
  229. janito/shell/commands/config.py +0 -22
  230. janito/shell/commands/edit.py +0 -24
  231. janito/shell/commands/history_view.py +0 -18
  232. janito/shell/commands/lang.py +0 -19
  233. janito/shell/commands/livelogs.py +0 -42
  234. janito/shell/commands/prompt.py +0 -62
  235. janito/shell/commands/termweb_log.py +0 -94
  236. janito/shell/commands/tools.py +0 -26
  237. janito/shell/commands/track.py +0 -36
  238. janito/shell/main.py +0 -326
  239. janito/shell/prompt/load_prompt.py +0 -57
  240. janito/shell/prompt/session_setup.py +0 -57
  241. janito/shell/session/config.py +0 -109
  242. janito/shell/session/history.py +0 -0
  243. janito/shell/ui/interactive.py +0 -226
  244. janito/termweb/static/editor.css +0 -158
  245. janito/termweb/static/editor.css.bak +0 -145
  246. janito/termweb/static/editor.html +0 -46
  247. janito/termweb/static/editor.html.bak +0 -46
  248. janito/termweb/static/editor.js +0 -265
  249. janito/termweb/static/editor.js.bak +0 -259
  250. janito/termweb/static/explorer.html.bak +0 -59
  251. janito/termweb/static/favicon.ico +0 -0
  252. janito/termweb/static/favicon.ico.bak +0 -0
  253. janito/termweb/static/index.html +0 -53
  254. janito/termweb/static/index.html.bak +0 -54
  255. janito/termweb/static/index.html.bak.bak +0 -175
  256. janito/termweb/static/landing.html.bak +0 -36
  257. janito/termweb/static/termicon.svg +0 -1
  258. janito/termweb/static/termweb.css +0 -214
  259. janito/termweb/static/termweb.css.bak +0 -237
  260. janito/termweb/static/termweb.js +0 -162
  261. janito/termweb/static/termweb.js.bak +0 -168
  262. janito/termweb/static/termweb.js.bak.bak +0 -157
  263. janito/termweb/static/termweb_quickopen.js +0 -135
  264. janito/termweb/static/termweb_quickopen.js.bak +0 -125
  265. janito/tests/test_rich_utils.py +0 -44
  266. janito/web/__init__.py +0 -0
  267. janito/web/__main__.py +0 -25
  268. janito/web/app.py +0 -145
  269. janito-1.14.3.dist-info/METADATA +0 -313
  270. janito-1.14.3.dist-info/RECORD +0 -162
  271. janito-1.14.3.dist-info/licenses/LICENSE +0 -21
  272. /janito/{shell → cli/chat_mode/shell}/input_history.py +0 -0
  273. /janito/{shell/commands/session.py → cli/chat_mode/shell/session/history.py} +0 -0
  274. /janito/{agent/tools_utils/formatting.py → formatting.py} +0 -0
  275. /janito/{agent/tools_utils/gitignore_utils.py → gitignore_utils.py} +0 -0
  276. /janito/{agent/platform_discovery.py → platform_discovery.py} +0 -0
  277. /janito/{agent/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
  278. /janito/{agent/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
  279. /janito/{agent/tools → tools/adapters/local}/search_text/__init__.py +0 -0
  280. /janito/{agent/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
  281. {janito-1.14.3.dist-info → janito-2.0.1.dist-info}/WHEEL +0 -0
  282. {janito-1.14.3.dist-info → janito-2.0.1.dist-info}/entry_points.txt +0 -0
  283. {janito-1.14.3.dist-info → janito-2.0.1.dist-info}/top_level.txt +0 -0
janito/cli/arg_parser.py DELETED
@@ -1,272 +0,0 @@
1
- import argparse
2
-
3
-
4
- def create_parser():
5
- # Adiciona --list-tools para listar ferramentas registradas
6
- # (adição incremental segura)
7
-
8
- parser = argparse.ArgumentParser(
9
- description="OpenRouter API call using OpenAI Python SDK"
10
- )
11
- # The positional argument is interpreted as either a prompt or session_id depending on context
12
- parser.add_argument(
13
- "input_arg",
14
- type=str,
15
- nargs="?",
16
- help="Prompt to send to the model, or session ID if --continue is used.",
17
- )
18
-
19
- parser.add_argument(
20
- "--list",
21
- nargs="?",
22
- type=int,
23
- const=10,
24
- default=None,
25
- help="List the last N sessions (default: 10) and exit.",
26
- )
27
- parser.add_argument(
28
- "--view",
29
- type=str,
30
- default=None,
31
- help="View the content of a conversation history by session id and exit.",
32
- )
33
- parser.add_argument(
34
- "--set-provider-config",
35
- nargs=3,
36
- metavar=("NAME", "KEY", "VALUE"),
37
- help="Set a provider config parameter (e.g., --set-provider-config openai api_key sk-xxx).",
38
- )
39
- parser.add_argument(
40
- "--lang",
41
- type=str,
42
- default=None,
43
- help="Language for interface messages (e.g., en, pt). Overrides config if set.",
44
- )
45
-
46
- parser.add_argument(
47
- "--app-shell",
48
- action="store_true",
49
- help="Use the new prompt_toolkit Application-based chat shell (experimental)",
50
- )
51
- parser.add_argument(
52
- "--max-tokens",
53
- type=int,
54
- default=None,
55
- help="Maximum tokens for model response (overrides config, default: 32000)",
56
- )
57
- parser.add_argument(
58
- "--max-tools",
59
- type=int,
60
- default=None,
61
- help="Maximum number of tool calls allowed within a chat session (default: unlimited)",
62
- )
63
- parser.add_argument(
64
- "--model",
65
- "-m",
66
- type=str,
67
- default=None,
68
- help="Model name to use for this session (overrides config, does not persist)",
69
- )
70
- parser.add_argument(
71
- "--max-rounds",
72
- type=int,
73
- default=None,
74
- help="Maximum number of agent rounds per prompt (overrides config, default: 50)",
75
- )
76
-
77
- # Mutually exclusive group for system prompt options
78
- group = parser.add_mutually_exclusive_group()
79
- group.add_argument(
80
- "-s",
81
- "--system",
82
- type=str,
83
- default=None,
84
- help="Optional system prompt as a raw string.",
85
- )
86
- group.add_argument(
87
- "--system-file",
88
- type=str,
89
- default=None,
90
- help="Path to a plain text file to use as the system prompt (no template rendering, takes precedence over --system-prompt)",
91
- )
92
-
93
- parser.add_argument(
94
- "-r",
95
- "--role",
96
- type=str,
97
- default=None,
98
- help="Role description for the default system prompt",
99
- )
100
- parser.add_argument(
101
- "-t",
102
- "--temperature",
103
- type=float,
104
- default=None,
105
- help="Sampling temperature (e.g., 0.0 - 2.0)",
106
- )
107
- parser.add_argument(
108
- "--verbose-http", action="store_true", help="Enable verbose HTTP logging"
109
- )
110
- parser.add_argument(
111
- "--verbose-http-raw",
112
- action="store_true",
113
- help="Enable raw HTTP wire-level logging",
114
- )
115
- parser.add_argument(
116
- "--verbose-response",
117
- action="store_true",
118
- help="Pretty print the full response object",
119
- )
120
- parser.add_argument(
121
- "--list-tools",
122
- action="store_true",
123
- help="Lista todas as ferramentas registradas e sai.",
124
- )
125
- parser.add_argument(
126
- "--show-system",
127
- action="store_true",
128
- help="Show model, parameters, system prompt, and tool definitions, then exit",
129
- )
130
- parser.add_argument(
131
- "--verbose-reason",
132
- action="store_true",
133
- help="Print the tool call reason whenever a tool is invoked (for debugging)",
134
- )
135
- parser.add_argument(
136
- "--verbose-tools",
137
- action="store_true",
138
- help="Print tool call parameters and results",
139
- )
140
- parser.add_argument(
141
- "-n",
142
- "--no-tools",
143
- action="store_true",
144
- default=False,
145
- help="Disable tool use (default: enabled)",
146
- )
147
- parser.add_argument(
148
- "--set-local-config",
149
- type=str,
150
- default=None,
151
- help='Set a local config key-value pair, format "key=val"',
152
- )
153
- parser.add_argument(
154
- "--set-global-config",
155
- type=str,
156
- default=None,
157
- help='Set a global config key-value pair, format "key=val"',
158
- )
159
- parser.add_argument(
160
- "--run-config",
161
- type=str,
162
- action="append",
163
- default=None,
164
- help='Set a runtime (in-memory only) config key-value pair, format "key=val". Can be repeated.',
165
- )
166
- parser.add_argument(
167
- "--show-config",
168
- action="store_true",
169
- help="Show effective configuration and exit",
170
- )
171
- parser.add_argument(
172
- "--set-api-key",
173
- type=str,
174
- default=None,
175
- help="Set and save the API key globally",
176
- )
177
- parser.add_argument(
178
- "--version", action="store_true", help="Show program's version number and exit"
179
- )
180
- parser.add_argument(
181
- "--help-config",
182
- action="store_true",
183
- help="Show all configuration options and exit",
184
- )
185
- parser.add_argument(
186
- "--continue-session",
187
- "--continue",
188
- action="store_true",
189
- default=False,
190
- help="Continue from a saved conversation. Uses the session ID from the positional argument if provided, otherwise resumes the most recent session.",
191
- )
192
- parser.add_argument(
193
- "--web", action="store_true", help="Launch the Janito web server instead of CLI"
194
- )
195
- parser.add_argument(
196
- "--live",
197
- action="store_true",
198
- help="Launch the Janito live reload server for web development",
199
- )
200
- parser.add_argument(
201
- "--config-reset-local",
202
- action="store_true",
203
- help="Remove the local config file (~/.janito/config.json)",
204
- )
205
- parser.add_argument(
206
- "--config-reset-global",
207
- action="store_true",
208
- help="Remove the global config file (~/.janito/config.json)",
209
- )
210
- parser.add_argument(
211
- "--verbose-events",
212
- action="store_true",
213
- help="Print all agent events before dispatching to the message handler (for debugging)",
214
- )
215
- parser.add_argument(
216
- "--verbose-messages",
217
- action="store_true",
218
- help="Print every new message added to the conversation history with a colored background.",
219
- )
220
- parser.add_argument(
221
- "-V",
222
- "--vanilla",
223
- action="store_true",
224
- default=False,
225
- help="Vanilla mode: disables tools, system prompt, and temperature (unless -t is set)",
226
- )
227
- parser.add_argument(
228
- "-T",
229
- "--trust-tools",
230
- action="store_true",
231
- help="Suppress all tool output (trusted tools mode: only shows output file locations)",
232
- )
233
- parser.add_argument(
234
- "--profile",
235
- type=str,
236
- default=None,
237
- help="Agent Profile name (only 'base' is supported)",
238
- )
239
- parser.add_argument(
240
- "--no-termweb",
241
- action="store_true",
242
- help="Disable the built-in lightweight web file viewer for terminal links (enabled by default)",
243
- )
244
- parser.add_argument(
245
- "--termweb-port",
246
- type=int,
247
- default=8088,
248
- help="Port for the termweb server (default: 8088)",
249
- )
250
- parser.add_argument(
251
- "-i",
252
- "--info",
253
- action="store_true",
254
- help="Show basic program info and exit (useful for one-shot shell execution)",
255
- )
256
- parser.add_argument(
257
- "--ntt",
258
- action="store_true",
259
- help="Disable tool call reason tracking (no tools tracking)",
260
- )
261
- parser.add_argument(
262
- "--all-out",
263
- action="store_true",
264
- help="Stream all output live to both the model and the screen, and do not store output in files. (use --all-out)",
265
- )
266
- parser.add_argument(
267
- "--tool-user",
268
- action="store_true",
269
- default=False,
270
- help="When set, tool responses will use role 'user' instead of 'tool' in the conversation history.",
271
- )
272
- return parser
janito/cli/cli_main.py DELETED
@@ -1,281 +0,0 @@
1
- import sys
2
- from janito.agent.llm_conversation_history import LLMConversationHistory
3
- import socket
4
- from janito.agent.profile_manager import AgentProfileManager
5
- from janito.agent.runtime_config import unified_config, runtime_config
6
- from janito.agent.config import get_api_key
7
- from janito import __version__
8
- from janito.agent.conversation_exceptions import (
9
- MaxRoundsExceededError,
10
- EmptyResponseError,
11
- ProviderError,
12
- )
13
- from janito.shell.main import start_chat_shell
14
-
15
-
16
- def is_port_free(port):
17
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
18
- return s.connect_ex(("localhost", port)) != 0
19
-
20
-
21
- def _set_runtime_flags(args, flags):
22
- for flag in flags:
23
- if hasattr(args, flag):
24
- runtime_config.set(flag, getattr(args, flag, False))
25
-
26
-
27
- def _set_runtime_if_present(args, attr, config_key=None):
28
- if getattr(args, attr, None) is not None:
29
- runtime_config.set(config_key or attr, getattr(args, attr))
30
-
31
-
32
- def normalize_args(args):
33
- if getattr(args, "vanilla", False):
34
- runtime_config.set("vanilla_mode", True)
35
- if getattr(args, "ntt", False):
36
- runtime_config.set("no_tools_tracking", True)
37
- if getattr(args, "all_out", False):
38
- runtime_config.set("all_out", True)
39
- _set_runtime_flags(
40
- args,
41
- [
42
- "verbose_http",
43
- "verbose_http_raw",
44
- "verbose_response",
45
- "verbose_reason",
46
- "verbose_tools",
47
- "verbose_events",
48
- "verbose_messages",
49
- ],
50
- )
51
- if getattr(args, "trust_tools", False):
52
- runtime_config.set("trust_tools", True)
53
- _set_runtime_if_present(args, "model")
54
- _set_runtime_if_present(args, "max_tools")
55
- if getattr(args, "verbose_reason", False):
56
- runtime_config.set("verbose_reason", True)
57
- _set_runtime_if_present(args, "max_tokens")
58
-
59
-
60
- def setup_profile_manager(args, role, interaction_mode, profile, lang):
61
- return AgentProfileManager(
62
- api_key=get_api_key(),
63
- model=unified_config.get("model"),
64
- role=role,
65
- profile_name=profile,
66
- interaction_mode=interaction_mode,
67
- verbose_tools=args.verbose_tools,
68
- base_url=unified_config.get("base_url", ""),
69
- azure_openai_api_version=unified_config.get(
70
- "azure_openai_api_version", "2023-05-15"
71
- ),
72
- use_azure_openai=unified_config.get("use_azure_openai", False),
73
- lang=lang,
74
- )
75
-
76
-
77
- def handle_termweb(args, interaction_mode):
78
- termweb_proc = None
79
- selected_port = None
80
- termweb_stdout_path = None
81
- termweb_stderr_path = None
82
- if (
83
- not getattr(args, "no_termweb", False)
84
- and interaction_mode == "chat"
85
- and not runtime_config.get("vanilla_mode", False)
86
- and not getattr(args, "input_arg", None)
87
- ):
88
- default_port = 8088
89
- max_port = 8100
90
- requested_port = args.termweb_port
91
- if requested_port == default_port:
92
- for port in range(default_port, max_port + 1):
93
- if is_port_free(port):
94
- selected_port = port
95
- break
96
- if selected_port is None:
97
- from rich.console import Console
98
-
99
- console = Console()
100
- console.print(
101
- f"[red]No free port found for termweb in range {default_port}-{max_port}.[/red]"
102
- )
103
- sys.exit(1)
104
- else:
105
- if not is_port_free(requested_port):
106
- from rich.console import Console
107
-
108
- console = Console()
109
- console.print(
110
- f"[red]Port {requested_port} is not available for termweb.[/red]"
111
- )
112
- sys.exit(1)
113
- selected_port = requested_port
114
- runtime_config.set("termweb_port", selected_port)
115
- from janito.cli.termweb_starter import start_termweb
116
-
117
- termweb_proc, started, termweb_stdout_path, termweb_stderr_path = start_termweb(
118
- selected_port
119
- )
120
- if started:
121
- from janito.agent.config import local_config
122
-
123
- local_config.set("termweb_last_running_port", selected_port)
124
- local_config.save()
125
- return termweb_proc, termweb_stdout_path, termweb_stderr_path
126
-
127
-
128
- def handle_continue_session(args):
129
- continue_session = False
130
- session_id = None
131
- if getattr(args, "input_arg", None) or getattr(args, "continue_session", False):
132
- _cont = getattr(args, "continue_session", False)
133
- if _cont:
134
- continue_session = True
135
- session_id = getattr(args, "input_arg", None)
136
- if session_id is None:
137
- import os
138
- import glob
139
-
140
- chat_hist_dir = (
141
- os.path.join(os.path.expanduser("~"), ".janito", "chat_history")
142
- if not os.path.isabs(".janito")
143
- else os.path.join(".janito", "chat_history")
144
- )
145
- if not os.path.exists(chat_hist_dir):
146
- session_id = None
147
- else:
148
- files = glob.glob(os.path.join(chat_hist_dir, "*.json"))
149
- if files:
150
- latest = max(files, key=os.path.getmtime)
151
- session_id = os.path.splitext(os.path.basename(latest))[0]
152
- else:
153
- session_id = None
154
- else:
155
- continue_session = False
156
- session_id = None
157
- return continue_session, session_id
158
-
159
-
160
- def handle_prompt_mode(args, profile_manager):
161
- prompt = getattr(args, "input_arg", None)
162
- from rich.console import Console
163
- from janito.agent.rich_message_handler import RichMessageHandler
164
-
165
- console = Console()
166
- message_handler = RichMessageHandler()
167
- messages = []
168
- system_prompt_override = runtime_config.get("system_prompt_template")
169
- if system_prompt_override:
170
- if not runtime_config.get("vanilla_mode", False) or getattr(
171
- args, "system", None
172
- ):
173
- messages.append({"role": "system", "content": system_prompt_override})
174
- elif profile_manager.system_prompt_template and not runtime_config.get(
175
- "vanilla_mode", False
176
- ):
177
- messages.append(
178
- {"role": "system", "content": profile_manager.system_prompt_template}
179
- )
180
- messages.append({"role": "user", "content": prompt})
181
- import time
182
-
183
- info_start_time = None
184
- if getattr(args, "info", False):
185
- info_start_time = time.time()
186
- try:
187
- max_rounds = 100
188
- result = profile_manager.agent.chat(
189
- LLMConversationHistory(messages),
190
- message_handler=message_handler,
191
- spinner=True,
192
- max_rounds=max_rounds,
193
- tool_user=getattr(args, "tool_user", False),
194
- )
195
- if (
196
- getattr(args, "info", False)
197
- and info_start_time is not None
198
- and result is not None
199
- ):
200
- usage_info = result.get("usage")
201
- total_tokens = usage_info.get("total_tokens") if usage_info else None
202
- prompt_tokens = usage_info.get("prompt_tokens") if usage_info else None
203
- completion_tokens = (
204
- usage_info.get("completion_tokens") if usage_info else None
205
- )
206
- elapsed = time.time() - info_start_time
207
- console.print(
208
- f"[bold green]Total tokens:[/] [yellow]{total_tokens}[/yellow] [bold green]| Input:[/] [cyan]{prompt_tokens}[/cyan] [bold green]| Output:[/] [magenta]{completion_tokens}[/magenta] [bold green]| Elapsed:[/] [yellow]{elapsed:.2f}s[/yellow]",
209
- style="dim",
210
- )
211
- except MaxRoundsExceededError:
212
- console.print("[red]Max conversation rounds exceeded.[/red]")
213
- except ProviderError as e:
214
- console.print(f"[red]Provider error:[/red] {e}")
215
- except EmptyResponseError as e:
216
- console.print(f"[red]Error:[/red] {e}")
217
-
218
-
219
- def run_cli(args):
220
- if args.version:
221
- print(f"janito version {__version__}")
222
- sys.exit(0)
223
- normalize_args(args)
224
- role = args.role or unified_config.get("role", "software engineer")
225
- if args.role:
226
- runtime_config.set("role", args.role)
227
- interaction_mode = "chat" if not getattr(args, "prompt", None) else "prompt"
228
- profile = "base"
229
- lang = getattr(args, "lang", None) or runtime_config.get("lang", "en")
230
- profile_manager = setup_profile_manager(args, role, interaction_mode, profile, lang)
231
- profile_manager.refresh_prompt()
232
- if getattr(args, "show_system", False):
233
- print(profile_manager.render_prompt())
234
- sys.exit(0)
235
- termweb_proc, termweb_stdout_path, termweb_stderr_path = handle_termweb(
236
- args, interaction_mode
237
- )
238
- try:
239
- continue_session, session_id = handle_continue_session(args)
240
- if getattr(args, "input_arg", None):
241
- from janito.cli.one_shot import run_oneshot_mode
242
-
243
- run_oneshot_mode(args, profile_manager, runtime_config)
244
- return
245
- import time
246
-
247
- info_start_time = None
248
- if getattr(args, "info", False):
249
- info_start_time = time.time()
250
- usage_info = start_chat_shell(
251
- profile_manager,
252
- continue_session=continue_session,
253
- session_id=session_id,
254
- termweb_stdout_path=termweb_stdout_path,
255
- termweb_stderr_path=termweb_stderr_path,
256
- livereload_stdout_path=None,
257
- livereload_stderr_path=None,
258
- )
259
- if (
260
- getattr(args, "info", False)
261
- and usage_info is not None
262
- and info_start_time is not None
263
- ):
264
- elapsed = time.time() - info_start_time
265
- from rich.console import Console
266
-
267
- total_tokens = usage_info.get("total_tokens")
268
- console = Console()
269
- console.print(
270
- f"[bold green]Total tokens used:[/] [yellow]{total_tokens}[/yellow] [bold green]| Elapsed time:[/] [yellow]{elapsed:.2f}s[/yellow]"
271
- )
272
- sys.exit(0)
273
- except KeyboardInterrupt:
274
- from rich.console import Console
275
-
276
- console = Console()
277
- console.print("[yellow]Interrupted by user.[/yellow]")
278
- finally:
279
- if termweb_proc:
280
- termweb_proc.terminate()
281
- termweb_proc.wait()