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
@@ -1,57 +0,0 @@
1
- from janito.shell.ui.interactive import (
2
- print_welcome,
3
- get_toolbar_func,
4
- get_prompt_session,
5
- )
6
- from janito import __version__
7
- from janito.agent.config import effective_config
8
- from janito.agent.runtime_config import runtime_config
9
- from janito.shell.session.manager import get_session_id
10
-
11
-
12
- def setup_prompt_session(
13
- messages,
14
- last_usage_info_ref,
15
- last_elapsed,
16
- mem_history,
17
- profile_manager,
18
- agent,
19
- history_ref,
20
- ):
21
- model_name = getattr(agent, "model", None)
22
- session_id = get_session_id()
23
-
24
- def get_messages():
25
- return messages
26
-
27
- def get_usage():
28
- return last_usage_info_ref()
29
-
30
- def get_elapsed():
31
- return last_elapsed
32
-
33
- session = get_prompt_session(
34
- get_toolbar_func(
35
- get_messages,
36
- get_usage,
37
- get_elapsed,
38
- model_name=model_name,
39
- role_ref=lambda: (
40
- "*using custom system prompt*"
41
- if (
42
- runtime_config.get("system_prompt_template")
43
- or runtime_config.get("system_prompt_template_file")
44
- )
45
- else (runtime_config.get("role") or effective_config.get("role"))
46
- ),
47
- version=__version__,
48
- session_id=session_id,
49
- history_ref=history_ref,
50
- ),
51
- mem_history,
52
- )
53
- return session
54
-
55
-
56
- def print_welcome_message(console, continue_id=None):
57
- print_welcome(console, version=__version__, continue_id=continue_id)
@@ -1,109 +0,0 @@
1
- from janito.agent.config import local_config, global_config, CONFIG_OPTIONS
2
- from janito.agent.config_defaults import CONFIG_DEFAULTS
3
- from janito.agent.runtime_config import unified_config, runtime_config
4
-
5
-
6
- def handle_config_shell(console, *args, **kwargs):
7
- """
8
- /config show
9
- /config set local key=value
10
- /config set global key=value
11
- /config reset local
12
- /config reset global
13
- """
14
- if not args or args[0] not in ("show", "set", "reset"):
15
- _print_usage(console)
16
- return
17
- if args[0] == "show":
18
- _show_config(console)
19
- return
20
- if args[0] == "reset":
21
- _reset_config(console, args)
22
- return
23
- if args[0] == "set":
24
- _set_config(console, args)
25
- return
26
-
27
-
28
- def _print_usage(console):
29
- console.print(
30
- "[bold red]Usage:[/bold red] /config show | /config set local|global key=value | /config reset local|global"
31
- )
32
-
33
-
34
- def _show_config(console):
35
- from janito.cli._print_config import print_full_config
36
-
37
- print_full_config(
38
- local_config,
39
- global_config,
40
- unified_config,
41
- CONFIG_DEFAULTS,
42
- console=console,
43
- )
44
-
45
-
46
- def _reset_config(console, args):
47
- if len(args) < 2 or args[1] not in ("local", "global"):
48
- console.print("[bold red]Usage:[/bold red] /config reset local|global")
49
- return
50
- import os
51
- from pathlib import Path
52
-
53
- scope = args[1]
54
- if scope == "local":
55
- local_path = Path(".janito/config.json")
56
- if local_path.exists():
57
- os.remove(local_path)
58
- console.print(f"[green]Removed local config file:[/green] {local_path}")
59
- else:
60
- console.print(
61
- f"[yellow]Local config file does not exist:[/yellow] {local_path}"
62
- )
63
- elif scope == "global":
64
- global_path = Path.home() / ".janito/config.json"
65
- if global_path.exists():
66
- os.remove(global_path)
67
- console.print(f"[green]Removed global config file:[/green] {global_path}")
68
- else:
69
- console.print(
70
- f"[yellow]Global config file does not exist:[/yellow] {global_path}"
71
- )
72
- console.print(
73
- "[bold yellow]Please use /restart for changes to take full effect.[/bold yellow]"
74
- )
75
-
76
-
77
- def _set_config(console, args):
78
- if len(args) < 3 or args[1] not in ("local", "global"):
79
- console.print("[bold red]Usage:[/bold red] /config set local|global key=value")
80
- return
81
- scope = args[1]
82
- try:
83
- key, val = args[2].split("=", 1)
84
- except ValueError:
85
- console.print("[bold red]Invalid format, expected key=val[/bold red]")
86
- return
87
- key = key.strip()
88
- if key not in CONFIG_OPTIONS and not key.startswith("template."):
89
- console.print(
90
- f"[bold red]Invalid config key: '{key}'. Supported keys are: {', '.join(CONFIG_OPTIONS.keys())}"
91
- )
92
- return
93
- val = val.strip()
94
- if scope == "local":
95
- local_config.set(key, val)
96
- local_config.save()
97
- runtime_config.set(key, val)
98
- console.print(f"[green]Local config updated:[/green] {key} = {val}")
99
- console.print(
100
- "[bold yellow]Please use /restart for changes to take full effect.[/bold yellow]"
101
- )
102
- elif scope == "global":
103
- global_config.set(key, val)
104
- global_config.save()
105
- runtime_config.set(key, val)
106
- console.print(f"[green]Global config updated:[/green] {key} = {val}")
107
- console.print(
108
- "[bold yellow]Please use /restart for changes to take full effect.[/bold yellow]"
109
- )
File without changes
@@ -1,226 +0,0 @@
1
- from prompt_toolkit import PromptSession
2
- from prompt_toolkit.enums import EditingMode
3
- from prompt_toolkit.formatted_text import HTML
4
- from prompt_toolkit.styles import Style
5
- from prompt_toolkit.key_binding import KeyBindings
6
- from janito.agent.runtime_config import runtime_config
7
- from janito.i18n import tr
8
-
9
-
10
- def print_welcome(console, version=None, continue_id=None):
11
- version_str = f" (v{version})" if version else ""
12
- # DEBUG: Show continue_id/session_id at runtime
13
- if continue_id:
14
- console.print(
15
- f"[bold yellow]{tr('Resuming session')}[/bold yellow] [white on blue]{continue_id}[/white on blue]\n"
16
- )
17
- if runtime_config.get("vanilla_mode", False):
18
- console.print(
19
- f"[bold magenta]{tr('Welcome to Janito{version_str} in [white on magenta]VANILLA MODE[/white on magenta]! Tools, system prompt, and temperature are disabled unless overridden.', version_str=version_str)}[/bold magenta]\n"
20
- )
21
- else:
22
- console.print(
23
- f"[bold green]{tr('Welcome to Janito{version_str}! Entering chat mode. Type /exit to exit.', version_str=version_str)}[/bold green]\n"
24
- )
25
-
26
-
27
- def format_tokens(n, tag=None):
28
- if n is None:
29
- return "?"
30
- if n < 1000:
31
- val = str(n)
32
- elif n < 1000000:
33
- val = f"{n/1000:.1f}k"
34
- else:
35
- val = f"{n/1000000:.1f}M"
36
- return f"<{tag}>{val}</{tag}>" if tag else val
37
-
38
-
39
- def assemble_first_line(model_name, role_ref, style_ref, version=None):
40
- version_part = f" Janito v{version}" if version else ""
41
- model_part = f" {tr('Model')}: <model>{model_name}</model>" if model_name else ""
42
- role_part = ""
43
- vanilla_mode = runtime_config.get("vanilla_mode", False)
44
- if role_ref and not vanilla_mode:
45
- role = role_ref()
46
- if role:
47
- role_part = f"{tr('Role')}: <role>{role}</role>"
48
- style_part = ""
49
- if style_ref:
50
- style = style_ref()
51
- if style:
52
- style_part = f"{tr('Style')}: <b>{style}</b>"
53
- first_line_parts = []
54
- if version_part:
55
- first_line_parts.append(version_part)
56
- if model_part:
57
- first_line_parts.append(model_part)
58
- if role_part:
59
- first_line_parts.append(role_part)
60
- if style_part:
61
- first_line_parts.append(style_part)
62
- return " | ".join(first_line_parts)
63
-
64
-
65
- def assemble_second_line(
66
- width,
67
- last_usage_info_ref,
68
- history_ref,
69
- messages_ref,
70
- session_id,
71
- model_name,
72
- role_ref,
73
- style_ref,
74
- ):
75
- usage = last_usage_info_ref()
76
- prompt_tokens = usage.get("prompt_tokens") if usage else None
77
- completion_tokens = usage.get("completion_tokens") if usage else None
78
- total_tokens = usage.get("total_tokens") if usage else None
79
- msg_count = len(history_ref()) if history_ref else len(messages_ref())
80
- left = f" {tr('Messages')}: <msg_count>{msg_count}</msg_count>"
81
- tokens_part = ""
82
- if (
83
- prompt_tokens is not None
84
- or completion_tokens is not None
85
- or total_tokens is not None
86
- ):
87
- tokens_part = (
88
- f" | {tr('Tokens')} - {tr('Prompt')}: {format_tokens(prompt_tokens, 'tokens_in')}, "
89
- f"{tr('Completion')}: {format_tokens(completion_tokens, 'tokens_out')}, "
90
- f"{tr('Total')}: {format_tokens(total_tokens, 'tokens_total')}"
91
- )
92
- session_part = (
93
- f" | Session ID: <session_id>{session_id}</session_id>" if session_id else ""
94
- )
95
- second_line = f"{left}{tokens_part}{session_part}"
96
- total_len = len(left) + len(tokens_part) + len(session_part)
97
- first_line = assemble_first_line(model_name, role_ref, style_ref)
98
- if first_line:
99
- total_len += len(first_line) + 3
100
- if total_len < width:
101
- padding = " " * (width - total_len)
102
- second_line = f"{left}{tokens_part}{session_part}{padding}"
103
- return second_line
104
-
105
-
106
- def assemble_bindings_line():
107
- return (
108
- f" <b>F1</b>: {tr('Restart Conversation')} | "
109
- f"<b>F12</b>: {tr('Do It')} | "
110
- f"<b>Ctrl-Y</b>: {tr('Yes')} | "
111
- f"<b>Ctrl-N</b>: {tr('No')} | "
112
- f"<b>/help</b>: {tr('Help')}"
113
- )
114
-
115
-
116
- def get_toolbar_func(
117
- messages_ref,
118
- last_usage_info_ref,
119
- last_elapsed_ref,
120
- model_name=None,
121
- role_ref=None,
122
- style_ref=None,
123
- version=None,
124
- session_id=None,
125
- history_ref=None,
126
- ):
127
- from prompt_toolkit.application.current import get_app
128
-
129
- def get_toolbar():
130
- width = get_app().output.get_size().columns
131
- first_line = assemble_first_line(
132
- model_name, role_ref, style_ref, version=version
133
- )
134
- second_line = assemble_second_line(
135
- width,
136
- last_usage_info_ref,
137
- history_ref,
138
- messages_ref,
139
- session_id,
140
- model_name,
141
- role_ref,
142
- style_ref,
143
- )
144
- bindings_line = assemble_bindings_line()
145
- if first_line:
146
- toolbar_text = first_line + "\n" + second_line + "\n" + bindings_line
147
- else:
148
- toolbar_text = second_line + "\n" + bindings_line
149
- return HTML(toolbar_text)
150
-
151
- return get_toolbar
152
-
153
-
154
- def get_custom_key_bindings():
155
- """
156
- Returns prompt_toolkit KeyBindings for custom CLI shortcuts:
157
- - F12: Inserts 'Do It' and submits.
158
- - Ctrl-Y: Inserts 'Yes' and submits (for confirmation prompts).
159
- - Ctrl-N: Inserts 'No' and submits (for confirmation prompts).
160
- """
161
- bindings = KeyBindings()
162
-
163
- @bindings.add("f12")
164
- def _(event):
165
- buf = event.app.current_buffer
166
- buf.text = "Do It"
167
- buf.validate_and_handle()
168
-
169
- @bindings.add("c-y")
170
- def _(event):
171
- buf = event.app.current_buffer
172
- buf.text = "Yes"
173
- buf.validate_and_handle()
174
-
175
- @bindings.add("c-n")
176
- def _(event):
177
- buf = event.app.current_buffer
178
- buf.text = "No"
179
- buf.validate_and_handle()
180
-
181
- @bindings.add("f1")
182
- def _(event):
183
- buf = event.app.current_buffer
184
- buf.text = "/restart"
185
- buf.validate_and_handle()
186
-
187
- return bindings
188
-
189
-
190
- def get_prompt_session(get_toolbar_func, mem_history):
191
- style = Style.from_dict(
192
- {
193
- "bottom-toolbar": "bg:#333333 #ffffff",
194
- "model": "bold bg:#005f5f #ffffff",
195
- "role": "bold ansiyellow",
196
- "tokens_in": "ansicyan bold",
197
- "tokens_out": "ansigreen bold",
198
- "tokens_total": "ansiyellow bold",
199
- "msg_count": "bg:#333333 #ffff00 bold",
200
- "session_id": "bg:#005f00 #ffffff bold",
201
- "b": "bold",
202
- "prompt": "bg:#005f5f #ffffff", # (legacy, not used)
203
- # Style for prompt_toolkit input line:
204
- # - '': affects the actual user input area background (full line, most reliable)
205
- # - "input-field": also affects the input area in some prompt_toolkit versions
206
- # - <inputline> tag: only affects the prompt label, not the input area
207
- "": "bg:#005fdd #ffffff", # Blue background for the user input area (recommended)
208
- "input-field": "bg:#005fdd #ffffff", # Blue background for the user input area (optional)
209
- "inputline": "bg:#005fdd #ffffff", # Blue background for the prompt label (icon/text)
210
- }
211
- )
212
- from janito.shell.prompt.completer import ShellCommandCompleter
213
-
214
- completer = ShellCommandCompleter()
215
- return PromptSession(
216
- bottom_toolbar=get_toolbar_func,
217
- style=style,
218
- editing_mode=EditingMode.VI,
219
- key_bindings=get_custom_key_bindings(),
220
- history=mem_history,
221
- completer=completer,
222
- )
223
-
224
-
225
- def _(text):
226
- return text
@@ -1,158 +0,0 @@
1
- /* Highlight active line in CodeMirror */
2
- .CodeMirror-activeline-background {
3
- background: #353b45;
4
- }
5
- body.light-theme .CodeMirror-activeline-background {
6
- background: #e0eaff;
7
- }
8
- html, body {
9
- height: 100%;
10
- margin: 0;
11
- padding: 0;
12
- }
13
- body {
14
- display: flex;
15
- flex-direction: column;
16
- min-height: 100vh;
17
- background: #181a1b;
18
- color: #eee;
19
- transition: background 0.2s, color 0.2s;
20
- }
21
- body.light-theme {
22
- background: #f5f5f5;
23
- color: #222;
24
- }
25
- .main {
26
- flex: 1 1 auto;
27
- display: flex;
28
- flex-direction: column;
29
- justify-content: stretch;
30
- align-items: stretch;
31
- min-height: 0;
32
- padding: 0;
33
- margin: 0;
34
- }
35
- .editor-pane {
36
- flex: 1 1 auto;
37
- display: flex;
38
- flex-direction: column;
39
- min-height: 0;
40
- padding: 0;
41
- margin: 0;
42
- }
43
- /* Removed custom .CodeMirror background/color to use CodeMirror's theme defaults */
44
-
45
- /* Ensure editor fills available space */
46
- .editor-pane textarea, .editor-pane .CodeMirror {
47
- flex: 1 1 auto;
48
- width: 100%;
49
- height: 100%;
50
- min-height: 0;
51
- min-width: 0;
52
- box-sizing: border-box;
53
- resize: none;
54
- display: block;
55
- }
56
-
57
- .header {
58
- background: #222;
59
- color: #fff;
60
- padding: 4px 12px;
61
- font-size: 0.95em;
62
- font-weight: bold;
63
- position: relative;
64
- transition: background 0.2s, color 0.2s;
65
- display: flex;
66
- align-items: center;
67
- justify-content: flex-end;
68
- height: 36px;
69
- }
70
-
71
- .header-title {
72
- position: absolute;
73
- left: 50%;
74
- top: 50%;
75
- transform: translate(-50%, -50%);
76
- pointer-events: none;
77
- font-weight: bold;
78
- font-size: 1.05em;
79
- display: flex;
80
- align-items: center;
81
- gap: 0.5em;
82
- }
83
-
84
- .filename-display {
85
- font-weight: normal;
86
- font-size: 0.98em;
87
- color: #bbb;
88
- margin-left: 0.5em;
89
- pointer-events: auto;
90
- text-overflow: ellipsis;
91
- white-space: nowrap;
92
- overflow: hidden;
93
- max-width: 180px;
94
- }
95
- body.light-theme .filename-display {
96
- color: #666;
97
- }
98
-
99
- .footer {
100
- position: relative;
101
- flex-shrink: 0;
102
- width: 100%;
103
- background: #222;
104
- color: #fff;
105
- padding: 4px 12px;
106
- box-sizing: border-box;
107
- display: flex;
108
- align-items: center;
109
- justify-content: space-between;
110
- border-top: 1px solid #333;
111
- height: 36px;
112
- font-size: 0.95em;
113
- }
114
-
115
- .save-btn {
116
- /* No margin needed, align left in footer */
117
- }
118
-
119
- .theme-switcher {
120
- margin-left: auto;
121
- }
122
-
123
- .save-btn {
124
- background: #4caf50;
125
- color: #fff;
126
- border: none;
127
- border-radius: 4px;
128
- padding: 6px 14px;
129
- cursor: pointer;
130
- font-size: 1em;
131
- }
132
-
133
- .theme-switcher {
134
- display: flex;
135
- align-items: center;
136
- justify-content: center;
137
- height: 100%;
138
- aspect-ratio: 1/1;
139
- font-size: 1.3em;
140
- line-height: 1;
141
- padding: 0;
142
- background: #444;
143
- color: #fff;
144
- border: none;
145
- border-radius: 4px;
146
- cursor: pointer;
147
- transition: background 0.2s, color 0.2s;
148
- }
149
-
150
- body.light-theme .theme-switcher {
151
- background: #ddd;
152
- color: #222;
153
- }
154
-
155
- body.light-theme .header {
156
- background: #eaeaea;
157
- color: #222;
158
- }
@@ -1,145 +0,0 @@
1
- /* Highlight active line in CodeMirror */
2
- .CodeMirror-activeline-background {
3
- background: #353b45;
4
- }
5
- body.light-theme .CodeMirror-activeline-background {
6
- background: #e0eaff;
7
- }
8
- html, body {
9
- height: 100%;
10
- margin: 0;
11
- padding: 0;
12
- }
13
- body {
14
- display: flex;
15
- flex-direction: column;
16
- min-height: 100vh;
17
- background: #181a1b;
18
- color: #eee;
19
- transition: background 0.2s, color 0.2s;
20
- }
21
- body.light-theme {
22
- background: #f5f5f5;
23
- color: #222;
24
- }
25
- .main {
26
- flex: 1 1 auto;
27
- display: flex;
28
- flex-direction: column;
29
- justify-content: stretch;
30
- align-items: stretch;
31
- min-height: 0;
32
- padding: 0;
33
- margin: 0;
34
- height: 100%;
35
- }
36
- .editor-pane {
37
- flex: 1 1 auto;
38
- display: flex;
39
- flex-direction: column;
40
- height: 100%;
41
- min-height: 0;
42
- padding: 0;
43
- margin: 0;
44
- }
45
- /* Removed custom .CodeMirror background/color to use CodeMirror's theme defaults */
46
- .header {
47
- background: #222;
48
- color: #fff;
49
- padding: 4px 12px;
50
- font-size: 0.95em;
51
- font-weight: bold;
52
- position: relative;
53
- transition: background 0.2s, color 0.2s;
54
- display: flex;
55
- align-items: center;
56
- justify-content: flex-end;
57
- height: 36px;
58
- }
59
-
60
- .header-title {
61
- position: absolute;
62
- left: 50%;
63
- top: 50%;
64
- transform: translate(-50%, -50%);
65
- pointer-events: none;
66
- font-weight: bold;
67
- font-size: 1.05em;
68
- display: flex;
69
- align-items: center;
70
- gap: 0.5em;
71
- }
72
-
73
- .filename-display {
74
- font-weight: normal;
75
- font-size: 0.98em;
76
- color: #bbb;
77
- margin-left: 0.5em;
78
- pointer-events: auto;
79
- text-overflow: ellipsis;
80
- white-space: nowrap;
81
- overflow: hidden;
82
- max-width: 180px;
83
- }
84
- body.light-theme .filename-display {
85
- color: #666;
86
- }
87
-
88
- .footer {
89
- width: 100%;
90
- background: #23272b;
91
- color: #fff;
92
- padding: 4px 12px;
93
- box-sizing: border-box;
94
- display: flex;
95
- align-items: center;
96
- justify-content: flex-start;
97
- border-top: 1px solid #333;
98
- min-height: 28px;
99
- font-size: 0.95em;
100
- }
101
-
102
- .save-btn {
103
- /* No margin needed, align left in footer */
104
- }
105
-
106
- .theme-switcher {
107
- margin-left: auto;
108
- }
109
-
110
- .save-btn {
111
- background: #4caf50;
112
- color: #fff;
113
- border: none;
114
- border-radius: 4px;
115
- padding: 6px 14px;
116
- cursor: pointer;
117
- font-size: 1em;
118
- }
119
-
120
- .theme-switcher {
121
- display: flex;
122
- align-items: center;
123
- justify-content: center;
124
- width: 36px;
125
- height: 36px;
126
- font-size: 1.3em;
127
- line-height: 1;
128
- padding: 0;
129
- background: #444;
130
- color: #fff;
131
- border: none;
132
- border-radius: 4px;
133
- cursor: pointer;
134
- transition: background 0.2s, color 0.2s;
135
- }
136
-
137
- body.light-theme .theme-switcher {
138
- background: #ddd;
139
- color: #222;
140
- }
141
-
142
- body.light-theme .header {
143
- background: #eaeaea;
144
- color: #222;
145
- }