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/main.py CHANGED
@@ -1,202 +1,14 @@
1
- """Main CLI entry point for Janito."""
1
+ # Ensure all output is written before the program exits, especially when output is piped or buffered.
2
+ from janito.cli.main_cli import JanitoCLI
3
+ import atexit, sys
2
4
 
3
- from janito.cli.arg_parser import create_parser
4
- from janito.cli.config_commands import handle_config_commands
5
- from janito.cli.logging_setup import setup_verbose_logging
6
- from janito.cli.cli_main import run_cli
7
- from janito.agent.runtime_config import unified_config
8
- from janito.cli.livereload_starter import start_livereload
9
-
10
- # Ensure all tools are registered at startup
11
- import janito.agent.tools # noqa: F401
12
- from janito.i18n import tr
13
-
14
-
15
- def handle_list_sessions(args):
16
- import os
17
- import glob
18
-
19
- n = args.list if args.list is not None else 10
20
- history_dir = os.path.join(os.path.expanduser(".janito"), "chat_history")
21
- if not os.path.exists(history_dir):
22
- print("No session history found.")
23
- return True
24
- files = glob.glob(os.path.join(history_dir, "*.json"))
25
- files = sorted(files, key=os.path.getmtime, reverse=True)
26
- print(f"Last {n} sessions:")
27
- for f in files[:n]:
28
- session_id = os.path.splitext(os.path.basename(f))[0]
29
- print(session_id)
30
- return True
31
-
32
-
33
- def handle_view_session(args):
34
- import os
35
- import json
36
-
37
- history_dir = os.path.join(os.path.expanduser(".janito"), "chat_history")
38
- session_file = os.path.join(history_dir, f"{args.view}.json")
39
- if not os.path.exists(session_file):
40
- print(f"Session '{args.view}' not found.")
41
- return 1
42
- with open(session_file, "r", encoding="utf-8") as f:
43
- try:
44
- messages = json.load(f)
45
- except Exception as e:
46
- print(f"Failed to load session: {e}")
47
- return 1
48
- print(f"Conversation history for session '{args.view}':\n")
49
- for i, msg in enumerate(messages, 1):
50
- role = msg.get("role", "?")
51
- content = msg.get("content", "")
52
- print(f"[{i}] {role}: {content}\n")
53
- return 0
54
-
55
-
56
- def handle_lang_selection(args):
57
- import janito.i18n as i18n
58
- from janito.agent.runtime_config import runtime_config
59
-
60
- lang = getattr(args, "lang", None) or unified_config.get("lang", None) or "en"
61
- runtime_config.set("lang", lang)
62
- i18n.set_locale(lang)
63
-
64
-
65
- def handle_help_config(args):
66
- from janito.agent.config import CONFIG_OPTIONS
67
- from janito.agent.config_defaults import CONFIG_DEFAULTS
68
-
69
- print(tr("Available configuration options:\n"))
70
- for key, desc in CONFIG_OPTIONS.items():
71
- default = CONFIG_DEFAULTS.get(key, None)
72
- print(
73
- tr(
74
- "{key:15} {desc} (default: {default})",
75
- key=key,
76
- desc=desc,
77
- default=default,
78
- )
79
- )
80
-
81
-
82
- def handle_list_tools(args):
83
- from janito.agent.tool_registry import get_tool_schemas
84
- from rich.console import Console
85
- from rich.table import Table
86
-
87
- console = Console()
88
- table = Table(
89
- title="Ferramentas Registradas", show_lines=True, style="bold magenta"
90
- )
91
- table.add_column("Gnome", style="cyan", no_wrap=True)
92
- table.add_column("Descrição", style="green")
93
- table.add_column("Parâmetros", style="yellow")
94
- for schema in get_tool_schemas():
95
- fn = schema["function"]
96
- params = "\n".join(
97
- [
98
- f"[bold]{k}[/]: {v['type']}"
99
- for k, v in fn["parameters"].get("properties", {}).items()
100
- ]
101
- )
102
- table.add_row(f"[b]{fn['name']}[/b]", fn["description"], params or "-")
103
- console.print(table)
104
-
105
-
106
- def handle_info(args):
107
- from janito import __version__
108
- from rich.console import Console
109
- from rich.text import Text
110
- from janito.agent.runtime_config import runtime_config
111
-
112
- model = unified_config.get("model")
113
- temperature = unified_config.get("temperature")
114
- max_tokens = unified_config.get("max_tokens")
115
- system_prompt_val = None
116
- if getattr(args, "system_file", None):
117
- try:
118
- with open(args.system_file, "r", encoding="utf-8") as f:
119
- system_prompt_val = f.read().strip()
120
- runtime_config.set("system_prompt_template", system_prompt_val)
121
- except Exception as e:
122
- system_prompt_val = f"(error reading system-file: {e})"
123
- elif getattr(args, "system", None):
124
- system_prompt_val = args.system
125
- runtime_config.set("system_prompt_template", system_prompt_val)
126
- else:
127
- system_prompt_val = runtime_config.get("system_prompt_template")
128
- if not system_prompt_val:
129
- try:
130
- from janito.agent.profile_manager import AgentProfileManager
131
- from janito.agent.config import get_api_key
132
-
133
- role = args.role or unified_config.get("role", "software engineer")
134
- interaction_mode = "chat" if not getattr(args, "prompt", None) else "prompt"
135
- profile = "base"
136
- profile_manager = AgentProfileManager(
137
- api_key=get_api_key(),
138
- model=unified_config.get("model"),
139
- )
140
- system_prompt_val = profile_manager.get_system_prompt(
141
- role, interaction_mode, profile
142
- )
143
- except Exception as e:
144
- system_prompt_val = f"(error: {e})"
145
- console = Console()
146
- info_text = Text()
147
- info_text.append(f"Janito v{__version__}", style="bold cyan")
148
- info_text.append(" | model: ", style="white")
149
- info_text.append(str(model), style="green")
150
- info_text.append(" | temp: ", style="white")
151
- info_text.append(str(temperature), style="yellow")
152
- info_text.append(" | max_tokens: ", style="white")
153
- info_text.append(str(max_tokens), style="magenta")
154
- info_text.append(" | system: ", style="white")
155
- info_text.append(str(system_prompt_val), style="bold blue")
156
- console.print(info_text, style="dim")
5
+ atexit.register(lambda: sys.stdout.flush())
157
6
 
158
7
 
159
8
  def main():
160
- """Unified entry point for the Janito CLI and web server."""
161
- import sys
162
- from janito.agent.config import local_config, global_config
9
+ cli = JanitoCLI()
10
+ cli.run()
163
11
 
164
- local_config.load()
165
- global_config.load()
166
- parser = create_parser()
167
- args = parser.parse_args()
168
- # Handle --list [n] before anything else
169
- if getattr(args, "list", None) is not None:
170
- if handle_list_sessions(args):
171
- sys.exit(0)
172
- # Handle --view <id> to print conversation history
173
- if getattr(args, "view", None) is not None:
174
- sys.exit(handle_view_session(args))
175
- handle_lang_selection(args)
176
- if getattr(args, "help_config", False):
177
- handle_help_config(args)
178
- sys.exit(0)
179
- if getattr(args, "list_tools", False):
180
- handle_list_tools(args)
181
- sys.exit(0)
182
- if getattr(args, "info", False):
183
- handle_info(args)
184
- handle_config_commands(args)
185
- setup_verbose_logging(args)
186
- if getattr(args, "web", False):
187
- import subprocess
188
12
 
189
- subprocess.run([sys.executable, "-m", "janito.web"])
190
- elif getattr(args, "live", False):
191
- port = 35729
192
- livereload_proc, started, livereload_stdout_path, livereload_stderr_path = (
193
- start_livereload(port)
194
- )
195
- try:
196
- run_cli(args)
197
- finally:
198
- if livereload_proc:
199
- livereload_proc.terminate()
200
- livereload_proc.wait()
201
- else:
202
- run_cli(args)
13
+ if __name__ == "__main__":
14
+ main()
janito/cli/main_cli.py ADDED
@@ -0,0 +1,312 @@
1
+ import argparse
2
+ import enum
3
+ from janito.cli.core.setters import handle_api_key_set, handle_set
4
+ from janito.cli.core.getters import handle_getter
5
+ from janito.cli.core.runner import (
6
+ prepare_llm_driver_config,
7
+ handle_runner,
8
+ get_prompt_mode,
9
+ )
10
+ from janito.cli.core.event_logger import (
11
+ setup_event_logger_if_needed,
12
+ inject_debug_event_bus_if_needed,
13
+ )
14
+
15
+ definition = [
16
+ (
17
+ ["--verbose-api"],
18
+ {
19
+ "action": "store_true",
20
+ "help": "Print API calls and responses of LLM driver APIs for debugging/tracing.",
21
+ },
22
+ ),
23
+ (
24
+ ["--verbose-tools"],
25
+ {
26
+ "action": "store_true",
27
+ "help": "Print info messages for tool execution in tools adapter.",
28
+ },
29
+ ),
30
+ (
31
+ ["--verbose-agent"],
32
+ {
33
+ "action": "store_true",
34
+ "help": "Print info messages for agent event and message part handling.",
35
+ },
36
+ ),
37
+ (
38
+ ["-z", "--zero"],
39
+ {
40
+ "action": "store_true",
41
+ "help": "IDE zero mode: disables system prompt & all tools for raw LLM interaction",
42
+ },
43
+ ),
44
+ (
45
+ ["-x", "--exec"],
46
+ {
47
+ "action": "store_true",
48
+ "help": "Enable execution/run tools (allows running code or shell tools from the CLI)",
49
+ },
50
+ ),
51
+ (["--unset"], {"metavar": "KEY", "help": "Unset (remove) a config key"}),
52
+ (["--version"], {"action": "version", "version": None}),
53
+ (["--list-tools"], {"action": "store_true", "help": "List all registered tools"}),
54
+ (["--show-config"], {"action": "store_true", "help": "Show the current config"}),
55
+ (
56
+ ["--list-providers"],
57
+ {"action": "store_true", "help": "List supported LLM providers"},
58
+ ),
59
+ (
60
+ ["-l", "--list-models"],
61
+ {"action": "store_true", "help": "List all supported models"},
62
+ ),
63
+ (
64
+ ["--set-api-key"],
65
+ {
66
+ "metavar": "API_KEY",
67
+ "help": "Set API key for the provider (requires -p PROVIDER)",
68
+ },
69
+ ),
70
+ (["--set"], {"metavar": "[PROVIDER_NAME.]KEY=VALUE", "help": "Set a config key"}),
71
+ (["-s", "--system"], {"metavar": "SYSTEM_PROMPT", "help": "Set a system prompt"}),
72
+ (
73
+ ["-S", "--show-system"],
74
+ {
75
+ "action": "store_true",
76
+ "help": "Show the resolved system prompt for the main agent",
77
+ },
78
+ ),
79
+ (["-r", "--role"], {"metavar": "ROLE", "help": "Set the role for the agent"}),
80
+ (["-p", "--provider"], {"metavar": "PROVIDER", "help": "Select the provider"}),
81
+ (["-m", "--model"], {"metavar": "MODEL", "help": "Select the model"}),
82
+ (
83
+ ["-t", "--temperature"],
84
+ {"type": float, "default": None, "help": "Set the temperature"},
85
+ ),
86
+ (
87
+ ["-v", "--verbose"],
88
+ {"action": "store_true", "help": "Print extra information before answering"},
89
+ ),
90
+ (
91
+ ["-R", "--raw"],
92
+ {
93
+ "action": "store_true",
94
+ "help": "Print the raw JSON response from the OpenAI API (if applicable)",
95
+ },
96
+ ),
97
+ (
98
+ ["-w", "--web"],
99
+ {
100
+ "action": "store_true",
101
+ "default": False,
102
+ "help": "Enable the builtin lightweight web file viewer for terminal links (disabled by default)",
103
+ },
104
+ ),
105
+ (
106
+ ["--termweb-port"],
107
+ {
108
+ "type": int,
109
+ "default": 8088,
110
+ "help": "Port for the termweb server (default: 8088)",
111
+ },
112
+ ),
113
+ (["user_prompt"], {"nargs": argparse.REMAINDER, "help": "Prompt to submit"}),
114
+ (
115
+ ["-e", "--event-log"],
116
+ {"action": "store_true", "help": "Enable event logging to the system bus"},
117
+ ),
118
+ (
119
+ ["--event-debug"],
120
+ {
121
+ "action": "store_true",
122
+ "help": "Print debug info on event subscribe/submit methods",
123
+ },
124
+ ),
125
+ ]
126
+
127
+ MODIFIER_KEYS = [
128
+ "provider",
129
+ "model",
130
+ "role",
131
+ "system",
132
+ "temperature",
133
+ "verbose",
134
+ "raw",
135
+ "web",
136
+ "termweb_port",
137
+ "verbose_api",
138
+ "verbose_tools",
139
+ "exec",
140
+ ]
141
+ SETTER_KEYS = ["set", "set_provider", "set_api_key", "unset"]
142
+ GETTER_KEYS = ["show_config", "list_providers", "list_models", "list_tools"]
143
+
144
+
145
+ class RunMode(enum.Enum):
146
+ GET = "get"
147
+ SET = "set"
148
+ RUN = "run"
149
+
150
+
151
+ class JanitoCLI:
152
+ def __init__(self):
153
+ import janito.tools
154
+
155
+ self.parser = argparse.ArgumentParser(
156
+ description="Janito CLI - A tool for running LLM-powered workflows from the command line."
157
+ "\n\nExample usage: janito -p openai -m gpt-3.5-turbo 'Your prompt here'\n\n"
158
+ "Use -m or --model to set the model for the session."
159
+ )
160
+ self._define_args()
161
+ self.args = self.parser.parse_args()
162
+ self._set_all_arg_defaults()
163
+ from janito.cli.rich_terminal_reporter import RichTerminalReporter
164
+
165
+ self.rich_reporter = RichTerminalReporter(raw_mode=self.args.raw)
166
+
167
+ def _define_args(self):
168
+ for argnames, argkwargs in definition:
169
+ # Patch version argument dynamically with real version
170
+ if "--version" in argnames:
171
+ from janito import __version__ as janito_version
172
+
173
+ argkwargs["version"] = f"Janito {janito_version}"
174
+ self.parser.add_argument(*argnames, **argkwargs)
175
+
176
+ def _set_all_arg_defaults(self):
177
+ # Gather all possible keys from definition, MODIFIER_KEYS, SETTER_KEYS, GETTER_KEYS
178
+ all_keys = set()
179
+ for argnames, argkwargs in definition:
180
+ for name in argnames:
181
+ key = name.lstrip("-").replace("-", "_")
182
+ all_keys.add(key)
183
+ all_keys.update(MODIFIER_KEYS)
184
+ all_keys.update(SETTER_KEYS)
185
+ all_keys.update(GETTER_KEYS)
186
+ # Set defaults for all keys if not present
187
+ for key in all_keys:
188
+ if not hasattr(self.args, key):
189
+ setattr(self.args, key, None)
190
+
191
+ def collect_modifiers(self):
192
+ return {
193
+ k: getattr(self.args, k)
194
+ for k in MODIFIER_KEYS
195
+ if getattr(self.args, k, None) is not None
196
+ }
197
+
198
+ def exec_enabled(self):
199
+ return getattr(self.args, "exec", False)
200
+
201
+ def classify(self):
202
+ if any(getattr(self.args, k, None) for k in SETTER_KEYS):
203
+ return RunMode.SET
204
+ if any(getattr(self.args, k, None) for k in GETTER_KEYS):
205
+ return RunMode.GET
206
+ return RunMode.RUN
207
+
208
+ def run(self):
209
+ # Handle --show-system/-S before anything else
210
+ if getattr(self.args, "show_system", False):
211
+ from janito.cli.cli_commands.show_system_prompt import (
212
+ handle_show_system_prompt,
213
+ )
214
+
215
+ handle_show_system_prompt(self.args)
216
+ return
217
+ run_mode = self.classify()
218
+ if run_mode == RunMode.SET:
219
+ if self._run_set_mode():
220
+ return
221
+ # Special handling: provider is not required for list_providers, list_tools, show_config
222
+ if run_mode == RunMode.GET and (
223
+ self.args.list_providers or self.args.list_tools or self.args.show_config
224
+ ):
225
+ self._maybe_print_verbose_provider_model()
226
+ handle_getter(self.args)
227
+ return
228
+ provider = self._get_provider_or_default()
229
+ if provider is None:
230
+ print(
231
+ "Error: No provider selected and no provider found in config. Please set a provider using '-p PROVIDER', '--set provider=name', or configure a provider."
232
+ )
233
+ return
234
+ modifiers = self.collect_modifiers()
235
+ self._maybe_print_verbose_modifiers(modifiers)
236
+ setup_event_logger_if_needed(self.args)
237
+ inject_debug_event_bus_if_needed(self.args)
238
+ provider, llm_driver_config, agent_role = prepare_llm_driver_config(
239
+ self.args, modifiers
240
+ )
241
+ if provider is None or llm_driver_config is None:
242
+ return
243
+ self._maybe_print_verbose_llm_config(llm_driver_config, run_mode)
244
+ if run_mode == RunMode.RUN:
245
+ self._maybe_print_verbose_run_mode()
246
+ handle_runner(
247
+ self.args,
248
+ provider,
249
+ llm_driver_config,
250
+ agent_role,
251
+ verbose_tools=self.args.verbose_tools,
252
+ exec_enabled=self.exec_enabled(),
253
+ )
254
+ elif run_mode == RunMode.GET:
255
+ handle_getter(self.args)
256
+
257
+ def _run_set_mode(self):
258
+ if handle_api_key_set(self.args):
259
+ return True
260
+ if handle_set(self.args):
261
+ return True
262
+ from janito.cli.core.unsetters import handle_unset
263
+
264
+ if handle_unset(self.args):
265
+ return True
266
+ return False
267
+
268
+ def _get_provider_or_default(self):
269
+ provider = self.args.provider
270
+ if provider is None:
271
+ from janito.provider_config import get_config_provider
272
+
273
+ provider = get_config_provider()
274
+ return provider
275
+
276
+ def _maybe_print_verbose_modifiers(self, modifiers):
277
+ if self.args.verbose:
278
+ from janito.cli.verbose_output import print_verbose_info
279
+
280
+ print_verbose_info("Modifiers collected", modifiers, style="blue")
281
+
282
+ def _maybe_print_verbose_provider_model(self):
283
+ if self.args.verbose:
284
+ from janito.cli.verbose_output import print_verbose_info
285
+
286
+ print_verbose_info(
287
+ "Validated provider/model",
288
+ f"Provider: {self.args.provider} | Model: {self.args.model}",
289
+ style="blue",
290
+ )
291
+
292
+ def _maybe_print_verbose_llm_config(self, llm_driver_config, run_mode):
293
+ if self.args.verbose:
294
+ from janito.cli.verbose_output import print_verbose_info
295
+
296
+ print_verbose_info("LLMDriverConfig", llm_driver_config, style="cyan")
297
+ print_verbose_info(
298
+ "Dispatch branch", run_mode, style="cyan", align_content=True
299
+ )
300
+
301
+ def _maybe_print_verbose_run_mode(self):
302
+ if self.args.verbose:
303
+ from janito.cli.verbose_output import print_verbose_info
304
+
305
+ print_verbose_info(
306
+ "Run mode", get_prompt_mode(self.args), style="cyan", align_content=True
307
+ )
308
+
309
+
310
+ if __name__ == "__main__":
311
+ cli = JanitoCLI()
312
+ cli.run()