janito 2.6.0__py3-none-any.whl → 2.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- janito/__init__.py +1 -0
- janito/__main__.py +1 -0
- janito/_version.py +1 -0
- janito/agent/setup_agent.py +240 -230
- janito/agent/templates/profiles/{system_prompt_template_software_developer.txt.j2 → system_prompt_template_plain_software_developer.txt.j2} +39 -39
- janito/cli/__init__.py +1 -0
- janito/cli/chat_mode/bindings.py +1 -0
- janito/cli/chat_mode/chat_entry.py +1 -0
- janito/cli/chat_mode/prompt_style.py +1 -0
- janito/cli/chat_mode/script_runner.py +1 -0
- janito/cli/chat_mode/session.py +282 -282
- janito/cli/chat_mode/session_profile_select.py +5 -5
- janito/cli/single_shot_mode/handler.py +95 -95
- janito/drivers/driver_registry.py +27 -27
- janito/drivers/openai/driver.py +435 -435
- janito/provider_registry.py +178 -178
- janito/providers/__init__.py +1 -0
- janito/providers/anthropic/model_info.py +41 -41
- janito/providers/anthropic/provider.py +80 -80
- janito/providers/moonshotai/__init__.py +1 -0
- janito/providers/moonshotai/model_info.py +15 -0
- janito/providers/moonshotai/provider.py +82 -0
- janito/providers/openai/model_info.py +1 -0
- janito/providers/provider_static_info.py +21 -18
- janito/tools/adapters/local/__init__.py +66 -66
- janito/tools/adapters/local/move_file.py +3 -3
- janito/tools/adapters/local/read_files.py +40 -40
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/METADATA +419 -412
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/RECORD +33 -30
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/WHEEL +0 -0
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/entry_points.txt +0 -0
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.6.0.dist-info → janito-2.7.0.dist-info}/top_level.txt +0 -0
janito/cli/chat_mode/session.py
CHANGED
@@ -1,282 +1,282 @@
|
|
1
|
-
"""
|
2
|
-
Session management for Janito Chat CLI.
|
3
|
-
Defines ChatSession and ChatShellState classes.
|
4
|
-
"""
|
5
|
-
|
6
|
-
from __future__ import annotations
|
7
|
-
|
8
|
-
import types
|
9
|
-
from rich.console import Console
|
10
|
-
from rich.rule import Rule
|
11
|
-
from prompt_toolkit.history import InMemoryHistory
|
12
|
-
from janito.cli.chat_mode.shell.input_history import UserInputHistory
|
13
|
-
from prompt_toolkit.formatted_text import HTML
|
14
|
-
from prompt_toolkit import PromptSession
|
15
|
-
from janito.cli.chat_mode.toolbar import get_toolbar_func
|
16
|
-
from prompt_toolkit.enums import EditingMode
|
17
|
-
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
18
|
-
from janito.cli.chat_mode.bindings import KeyBindingsFactory
|
19
|
-
from janito.cli.chat_mode.shell.commands import handle_command
|
20
|
-
from janito.cli.chat_mode.shell.autocomplete import ShellCommandCompleter
|
21
|
-
import time
|
22
|
-
|
23
|
-
# Shared prompt/agent factory
|
24
|
-
from janito.cli.prompt_setup import setup_agent_and_prompt_handler
|
25
|
-
|
26
|
-
import time
|
27
|
-
|
28
|
-
class ChatShellState:
|
29
|
-
def __init__(self, mem_history, conversation_history):
|
30
|
-
self.mem_history = mem_history
|
31
|
-
self.conversation_history = conversation_history
|
32
|
-
self.paste_mode = False
|
33
|
-
self._port = None
|
34
|
-
self._pid = None
|
35
|
-
self._stdout_path = None
|
36
|
-
self._stderr_path = None
|
37
|
-
self.livereload_stderr_path = None
|
38
|
-
self._status = "starting" # Tracks the current status (updated by background thread/UI)
|
39
|
-
|
40
|
-
self.last_usage_info = {}
|
41
|
-
self.last_elapsed = None
|
42
|
-
self.main_agent = {}
|
43
|
-
self.mode = None
|
44
|
-
self.agent = None
|
45
|
-
self.main_agent = None
|
46
|
-
self.main_enabled = False
|
47
|
-
|
48
|
-
class ChatSession:
|
49
|
-
def __init__(
|
50
|
-
self,
|
51
|
-
console,
|
52
|
-
provider_instance=None,
|
53
|
-
llm_driver_config=None,
|
54
|
-
role=None,
|
55
|
-
args=None,
|
56
|
-
verbose_tools=False,
|
57
|
-
verbose_agent=False,
|
58
|
-
allowed_permissions=None,
|
59
|
-
):
|
60
|
-
self.console = console
|
61
|
-
self.user_input_history = UserInputHistory()
|
62
|
-
self.input_dicts = self.user_input_history.load()
|
63
|
-
self.mem_history = InMemoryHistory()
|
64
|
-
for item in self.input_dicts:
|
65
|
-
if isinstance(item, dict) and "input" in item:
|
66
|
-
self.mem_history.append_string(item["input"])
|
67
|
-
self.provider_instance = provider_instance
|
68
|
-
self.llm_driver_config = llm_driver_config
|
69
|
-
|
70
|
-
profile, role, profile_system_prompt = self._select_profile_and_role(args, role)
|
71
|
-
conversation_history = self._create_conversation_history()
|
72
|
-
self.agent, self._prompt_handler = self._setup_agent_and_prompt_handler(
|
73
|
-
args, provider_instance, llm_driver_config, role, verbose_tools, verbose_agent, allowed_permissions, profile, profile_system_prompt, conversation_history
|
74
|
-
)
|
75
|
-
self.shell_state = ChatShellState(self.mem_history, conversation_history)
|
76
|
-
self.shell_state.agent = self.agent
|
77
|
-
self._filter_execution_tools()
|
78
|
-
from janito.perf_singleton import performance_collector
|
79
|
-
self.performance_collector = performance_collector
|
80
|
-
self.key_bindings = KeyBindingsFactory.create()
|
81
|
-
self._prompt_handler.agent = self.agent
|
82
|
-
self._prompt_handler.conversation_history = self.shell_state.conversation_history
|
83
|
-
self._support = False
|
84
|
-
self._maybe_enable_web_support(args)
|
85
|
-
|
86
|
-
def _select_profile_and_role(self, args, role):
|
87
|
-
profile = getattr(args, "profile", None) if args is not None else None
|
88
|
-
role_arg = getattr(args, "role", None) if args is not None else None
|
89
|
-
profile_system_prompt = None
|
90
|
-
if profile is None and role_arg is None:
|
91
|
-
try:
|
92
|
-
from janito.cli.chat_mode.session_profile_select import select_profile
|
93
|
-
result = select_profile()
|
94
|
-
if isinstance(result, dict):
|
95
|
-
profile = result.get("profile")
|
96
|
-
profile_system_prompt = result.get("profile_system_prompt")
|
97
|
-
elif isinstance(result, str) and result.startswith("role:"):
|
98
|
-
role = result[len("role:") :].strip()
|
99
|
-
profile = "developer"
|
100
|
-
else:
|
101
|
-
profile = (
|
102
|
-
"developer" if result == "
|
103
|
-
)
|
104
|
-
except ImportError:
|
105
|
-
profile = "helpful assistant"
|
106
|
-
if role_arg is not None:
|
107
|
-
role = role_arg
|
108
|
-
if profile is None:
|
109
|
-
profile = "developer"
|
110
|
-
return profile, role, profile_system_prompt
|
111
|
-
|
112
|
-
def _create_conversation_history(self):
|
113
|
-
from janito.conversation_history import LLMConversationHistory
|
114
|
-
return LLMConversationHistory()
|
115
|
-
|
116
|
-
def _setup_agent_and_prompt_handler(self, args, provider_instance, llm_driver_config, role, verbose_tools, verbose_agent, allowed_permissions, profile, profile_system_prompt, conversation_history):
|
117
|
-
return setup_agent_and_prompt_handler(
|
118
|
-
args=args,
|
119
|
-
provider_instance=provider_instance,
|
120
|
-
llm_driver_config=llm_driver_config,
|
121
|
-
role=role,
|
122
|
-
verbose_tools=verbose_tools,
|
123
|
-
verbose_agent=verbose_agent,
|
124
|
-
allowed_permissions=allowed_permissions,
|
125
|
-
profile=profile,
|
126
|
-
profile_system_prompt=profile_system_prompt,
|
127
|
-
conversation_history=conversation_history,
|
128
|
-
)
|
129
|
-
|
130
|
-
def _filter_execution_tools(self):
|
131
|
-
try:
|
132
|
-
getattr(__import__('janito.tools', fromlist=['get_local_tools_adapter']), 'get_local_tools_adapter')()
|
133
|
-
except Exception as e:
|
134
|
-
self.console.print(f"[yellow]Warning: Could not filter execution tools at startup: {e}[/yellow]")
|
135
|
-
|
136
|
-
def _maybe_enable_web_support(self, args):
|
137
|
-
if args and getattr(args, "web", False):
|
138
|
-
self._support = True
|
139
|
-
self.shell_state._support = self._support
|
140
|
-
from janito.cli._starter import _start_and_watch
|
141
|
-
from janito.cli.config import get__port
|
142
|
-
import threading
|
143
|
-
from rich.console import Console
|
144
|
-
Console().print("[yellow]Starting in background...[/yellow]")
|
145
|
-
self._lock = threading.Lock()
|
146
|
-
_thread = _start_and_watch(
|
147
|
-
self.shell_state, self._lock, get__port()
|
148
|
-
)
|
149
|
-
self._thread = _thread
|
150
|
-
else:
|
151
|
-
self.shell_state._support = False
|
152
|
-
self.shell_state._status = "offline"
|
153
|
-
|
154
|
-
def run(self):
|
155
|
-
self.console.clear()
|
156
|
-
from janito import __version__
|
157
|
-
self.console.print(
|
158
|
-
f"[bold green]Janito Chat Mode v{__version__}[/bold green]"
|
159
|
-
)
|
160
|
-
self.console.print("[green]/help for commands /exit or Ctrl+C to quit[/green]")
|
161
|
-
import os
|
162
|
-
cwd = os.getcwd()
|
163
|
-
home = os.path.expanduser('~')
|
164
|
-
if cwd.startswith(home):
|
165
|
-
cwd_display = '~' + cwd[len(home):]
|
166
|
-
else:
|
167
|
-
cwd_display = cwd
|
168
|
-
self.console.print(f"[green]Working Dir:[/green] {cwd_display}")
|
169
|
-
|
170
|
-
from janito.cli.chat_mode.shell.commands._priv_check import user_has_any_privileges
|
171
|
-
if not user_has_any_privileges():
|
172
|
-
self.console.print("[yellow]Note: You currently have no privileges enabled. If you need to interact with files or the system, enable permissions using /read on, /write on, or /execute on.[/yellow]")
|
173
|
-
|
174
|
-
session = self._create_prompt_session()
|
175
|
-
self._chat_loop(session)
|
176
|
-
|
177
|
-
def _chat_loop(self, session):
|
178
|
-
self.msg_count = 0
|
179
|
-
timer_started = False
|
180
|
-
while True:
|
181
|
-
if not timer_started:
|
182
|
-
timer_started = True
|
183
|
-
cmd_input = self._handle_input(session)
|
184
|
-
if cmd_input is None:
|
185
|
-
break
|
186
|
-
if not cmd_input:
|
187
|
-
continue
|
188
|
-
if self._handle_exit_conditions(cmd_input):
|
189
|
-
break
|
190
|
-
if self._handle_command_input(cmd_input):
|
191
|
-
continue
|
192
|
-
self.user_input_history.append(cmd_input)
|
193
|
-
self._process_prompt(cmd_input)
|
194
|
-
|
195
|
-
def _handle_command_input(self, cmd_input):
|
196
|
-
if cmd_input.startswith("/"):
|
197
|
-
handle_command(cmd_input, shell_state=self.shell_state)
|
198
|
-
return True
|
199
|
-
if cmd_input.startswith("!"):
|
200
|
-
handle_command(f"! {cmd_input[1:]}", shell_state=self.shell_state)
|
201
|
-
return True
|
202
|
-
return False
|
203
|
-
|
204
|
-
def _process_prompt(self, cmd_input):
|
205
|
-
try:
|
206
|
-
import time
|
207
|
-
final_event = (
|
208
|
-
self._prompt_handler.agent.last_event
|
209
|
-
if hasattr(self._prompt_handler.agent, "last_event")
|
210
|
-
else None
|
211
|
-
)
|
212
|
-
start_time = time.time()
|
213
|
-
self._prompt_handler.run_prompt(cmd_input)
|
214
|
-
end_time = time.time()
|
215
|
-
elapsed = end_time - start_time
|
216
|
-
self.msg_count += 1
|
217
|
-
from janito.formatting_token import print_token_message_summary
|
218
|
-
usage = self.performance_collector.get_last_request_usage()
|
219
|
-
print_token_message_summary(self.console, self.msg_count, usage, elapsed=elapsed)
|
220
|
-
if final_event and hasattr(final_event, "metadata"):
|
221
|
-
exit_reason = (
|
222
|
-
final_event.metadata.get("exit_reason")
|
223
|
-
if hasattr(final_event, "metadata")
|
224
|
-
else None
|
225
|
-
)
|
226
|
-
if exit_reason:
|
227
|
-
self.console.print(
|
228
|
-
f"[bold yellow]Exit reason: {exit_reason}[/bold yellow]"
|
229
|
-
)
|
230
|
-
except Exception as exc:
|
231
|
-
self.console.print(f"[red]Exception in agent: {exc}[/red]")
|
232
|
-
import traceback
|
233
|
-
self.console.print(traceback.format_exc())
|
234
|
-
|
235
|
-
def _create_prompt_session(self):
|
236
|
-
return PromptSession(
|
237
|
-
style=chat_shell_style,
|
238
|
-
completer=ShellCommandCompleter(),
|
239
|
-
history=self.mem_history,
|
240
|
-
editing_mode=EditingMode.EMACS,
|
241
|
-
key_bindings=self.key_bindings,
|
242
|
-
bottom_toolbar=lambda: get_toolbar_func(
|
243
|
-
self.performance_collector, 0, self.shell_state
|
244
|
-
)(),
|
245
|
-
)
|
246
|
-
|
247
|
-
def _handle_input(self, session):
|
248
|
-
injected = getattr(self.shell_state, "injected_input", None)
|
249
|
-
if injected is not None:
|
250
|
-
cmd_input = injected
|
251
|
-
self.shell_state.injected_input = None
|
252
|
-
else:
|
253
|
-
try:
|
254
|
-
cmd_input = session.prompt(HTML("<inputline>💬 </inputline>"))
|
255
|
-
except (KeyboardInterrupt, EOFError):
|
256
|
-
self._handle_exit()
|
257
|
-
return None
|
258
|
-
sanitized = cmd_input.strip()
|
259
|
-
try:
|
260
|
-
sanitized.encode("utf-8")
|
261
|
-
except UnicodeEncodeError:
|
262
|
-
sanitized = sanitized.encode("utf-8", errors="replace").decode("utf-8")
|
263
|
-
self.console.print(
|
264
|
-
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
265
|
-
)
|
266
|
-
return sanitized
|
267
|
-
|
268
|
-
def _handle_exit(self):
|
269
|
-
self.console.print("[bold yellow]Exiting chat. Goodbye![/bold yellow]")
|
270
|
-
if hasattr(self, "agent") and hasattr(self.agent, "join_driver"):
|
271
|
-
if (
|
272
|
-
hasattr(self.agent, "input_queue")
|
273
|
-
and self.agent.input_queue is not None
|
274
|
-
):
|
275
|
-
self.agent.input_queue.put(None)
|
276
|
-
self.agent.join_driver()
|
277
|
-
|
278
|
-
def _handle_exit_conditions(self, cmd_input):
|
279
|
-
if cmd_input.lower() in ("/exit", ":q", ":quit"):
|
280
|
-
self._handle_exit()
|
281
|
-
return True
|
282
|
-
return False
|
1
|
+
"""
|
2
|
+
Session management for Janito Chat CLI.
|
3
|
+
Defines ChatSession and ChatShellState classes.
|
4
|
+
"""
|
5
|
+
|
6
|
+
from __future__ import annotations
|
7
|
+
|
8
|
+
import types
|
9
|
+
from rich.console import Console
|
10
|
+
from rich.rule import Rule
|
11
|
+
from prompt_toolkit.history import InMemoryHistory
|
12
|
+
from janito.cli.chat_mode.shell.input_history import UserInputHistory
|
13
|
+
from prompt_toolkit.formatted_text import HTML
|
14
|
+
from prompt_toolkit import PromptSession
|
15
|
+
from janito.cli.chat_mode.toolbar import get_toolbar_func
|
16
|
+
from prompt_toolkit.enums import EditingMode
|
17
|
+
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
18
|
+
from janito.cli.chat_mode.bindings import KeyBindingsFactory
|
19
|
+
from janito.cli.chat_mode.shell.commands import handle_command
|
20
|
+
from janito.cli.chat_mode.shell.autocomplete import ShellCommandCompleter
|
21
|
+
import time
|
22
|
+
|
23
|
+
# Shared prompt/agent factory
|
24
|
+
from janito.cli.prompt_setup import setup_agent_and_prompt_handler
|
25
|
+
|
26
|
+
import time
|
27
|
+
|
28
|
+
class ChatShellState:
|
29
|
+
def __init__(self, mem_history, conversation_history):
|
30
|
+
self.mem_history = mem_history
|
31
|
+
self.conversation_history = conversation_history
|
32
|
+
self.paste_mode = False
|
33
|
+
self._port = None
|
34
|
+
self._pid = None
|
35
|
+
self._stdout_path = None
|
36
|
+
self._stderr_path = None
|
37
|
+
self.livereload_stderr_path = None
|
38
|
+
self._status = "starting" # Tracks the current status (updated by background thread/UI)
|
39
|
+
|
40
|
+
self.last_usage_info = {}
|
41
|
+
self.last_elapsed = None
|
42
|
+
self.main_agent = {}
|
43
|
+
self.mode = None
|
44
|
+
self.agent = None
|
45
|
+
self.main_agent = None
|
46
|
+
self.main_enabled = False
|
47
|
+
|
48
|
+
class ChatSession:
|
49
|
+
def __init__(
|
50
|
+
self,
|
51
|
+
console,
|
52
|
+
provider_instance=None,
|
53
|
+
llm_driver_config=None,
|
54
|
+
role=None,
|
55
|
+
args=None,
|
56
|
+
verbose_tools=False,
|
57
|
+
verbose_agent=False,
|
58
|
+
allowed_permissions=None,
|
59
|
+
):
|
60
|
+
self.console = console
|
61
|
+
self.user_input_history = UserInputHistory()
|
62
|
+
self.input_dicts = self.user_input_history.load()
|
63
|
+
self.mem_history = InMemoryHistory()
|
64
|
+
for item in self.input_dicts:
|
65
|
+
if isinstance(item, dict) and "input" in item:
|
66
|
+
self.mem_history.append_string(item["input"])
|
67
|
+
self.provider_instance = provider_instance
|
68
|
+
self.llm_driver_config = llm_driver_config
|
69
|
+
|
70
|
+
profile, role, profile_system_prompt = self._select_profile_and_role(args, role)
|
71
|
+
conversation_history = self._create_conversation_history()
|
72
|
+
self.agent, self._prompt_handler = self._setup_agent_and_prompt_handler(
|
73
|
+
args, provider_instance, llm_driver_config, role, verbose_tools, verbose_agent, allowed_permissions, profile, profile_system_prompt, conversation_history
|
74
|
+
)
|
75
|
+
self.shell_state = ChatShellState(self.mem_history, conversation_history)
|
76
|
+
self.shell_state.agent = self.agent
|
77
|
+
self._filter_execution_tools()
|
78
|
+
from janito.perf_singleton import performance_collector
|
79
|
+
self.performance_collector = performance_collector
|
80
|
+
self.key_bindings = KeyBindingsFactory.create()
|
81
|
+
self._prompt_handler.agent = self.agent
|
82
|
+
self._prompt_handler.conversation_history = self.shell_state.conversation_history
|
83
|
+
self._support = False
|
84
|
+
self._maybe_enable_web_support(args)
|
85
|
+
|
86
|
+
def _select_profile_and_role(self, args, role):
|
87
|
+
profile = getattr(args, "profile", None) if args is not None else None
|
88
|
+
role_arg = getattr(args, "role", None) if args is not None else None
|
89
|
+
profile_system_prompt = None
|
90
|
+
if profile is None and role_arg is None:
|
91
|
+
try:
|
92
|
+
from janito.cli.chat_mode.session_profile_select import select_profile
|
93
|
+
result = select_profile()
|
94
|
+
if isinstance(result, dict):
|
95
|
+
profile = result.get("profile")
|
96
|
+
profile_system_prompt = result.get("profile_system_prompt")
|
97
|
+
elif isinstance(result, str) and result.startswith("role:"):
|
98
|
+
role = result[len("role:") :].strip()
|
99
|
+
profile = "developer"
|
100
|
+
else:
|
101
|
+
profile = (
|
102
|
+
"developer" if result == "plain_software_developer" else result
|
103
|
+
)
|
104
|
+
except ImportError:
|
105
|
+
profile = "helpful assistant"
|
106
|
+
if role_arg is not None:
|
107
|
+
role = role_arg
|
108
|
+
if profile is None:
|
109
|
+
profile = "developer"
|
110
|
+
return profile, role, profile_system_prompt
|
111
|
+
|
112
|
+
def _create_conversation_history(self):
|
113
|
+
from janito.conversation_history import LLMConversationHistory
|
114
|
+
return LLMConversationHistory()
|
115
|
+
|
116
|
+
def _setup_agent_and_prompt_handler(self, args, provider_instance, llm_driver_config, role, verbose_tools, verbose_agent, allowed_permissions, profile, profile_system_prompt, conversation_history):
|
117
|
+
return setup_agent_and_prompt_handler(
|
118
|
+
args=args,
|
119
|
+
provider_instance=provider_instance,
|
120
|
+
llm_driver_config=llm_driver_config,
|
121
|
+
role=role,
|
122
|
+
verbose_tools=verbose_tools,
|
123
|
+
verbose_agent=verbose_agent,
|
124
|
+
allowed_permissions=allowed_permissions,
|
125
|
+
profile=profile,
|
126
|
+
profile_system_prompt=profile_system_prompt,
|
127
|
+
conversation_history=conversation_history,
|
128
|
+
)
|
129
|
+
|
130
|
+
def _filter_execution_tools(self):
|
131
|
+
try:
|
132
|
+
getattr(__import__('janito.tools', fromlist=['get_local_tools_adapter']), 'get_local_tools_adapter')()
|
133
|
+
except Exception as e:
|
134
|
+
self.console.print(f"[yellow]Warning: Could not filter execution tools at startup: {e}[/yellow]")
|
135
|
+
|
136
|
+
def _maybe_enable_web_support(self, args):
|
137
|
+
if args and getattr(args, "web", False):
|
138
|
+
self._support = True
|
139
|
+
self.shell_state._support = self._support
|
140
|
+
from janito.cli._starter import _start_and_watch
|
141
|
+
from janito.cli.config import get__port
|
142
|
+
import threading
|
143
|
+
from rich.console import Console
|
144
|
+
Console().print("[yellow]Starting in background...[/yellow]")
|
145
|
+
self._lock = threading.Lock()
|
146
|
+
_thread = _start_and_watch(
|
147
|
+
self.shell_state, self._lock, get__port()
|
148
|
+
)
|
149
|
+
self._thread = _thread
|
150
|
+
else:
|
151
|
+
self.shell_state._support = False
|
152
|
+
self.shell_state._status = "offline"
|
153
|
+
|
154
|
+
def run(self):
|
155
|
+
self.console.clear()
|
156
|
+
from janito import __version__
|
157
|
+
self.console.print(
|
158
|
+
f"[bold green]Janito Chat Mode v{__version__}[/bold green]"
|
159
|
+
)
|
160
|
+
self.console.print("[green]/help for commands /exit or Ctrl+C to quit[/green]")
|
161
|
+
import os
|
162
|
+
cwd = os.getcwd()
|
163
|
+
home = os.path.expanduser('~')
|
164
|
+
if cwd.startswith(home):
|
165
|
+
cwd_display = '~' + cwd[len(home):]
|
166
|
+
else:
|
167
|
+
cwd_display = cwd
|
168
|
+
self.console.print(f"[green]Working Dir:[/green] {cwd_display}")
|
169
|
+
|
170
|
+
from janito.cli.chat_mode.shell.commands._priv_check import user_has_any_privileges
|
171
|
+
if not user_has_any_privileges():
|
172
|
+
self.console.print("[yellow]Note: You currently have no privileges enabled. If you need to interact with files or the system, enable permissions using /read on, /write on, or /execute on.[/yellow]")
|
173
|
+
|
174
|
+
session = self._create_prompt_session()
|
175
|
+
self._chat_loop(session)
|
176
|
+
|
177
|
+
def _chat_loop(self, session):
|
178
|
+
self.msg_count = 0
|
179
|
+
timer_started = False
|
180
|
+
while True:
|
181
|
+
if not timer_started:
|
182
|
+
timer_started = True
|
183
|
+
cmd_input = self._handle_input(session)
|
184
|
+
if cmd_input is None:
|
185
|
+
break
|
186
|
+
if not cmd_input:
|
187
|
+
continue
|
188
|
+
if self._handle_exit_conditions(cmd_input):
|
189
|
+
break
|
190
|
+
if self._handle_command_input(cmd_input):
|
191
|
+
continue
|
192
|
+
self.user_input_history.append(cmd_input)
|
193
|
+
self._process_prompt(cmd_input)
|
194
|
+
|
195
|
+
def _handle_command_input(self, cmd_input):
|
196
|
+
if cmd_input.startswith("/"):
|
197
|
+
handle_command(cmd_input, shell_state=self.shell_state)
|
198
|
+
return True
|
199
|
+
if cmd_input.startswith("!"):
|
200
|
+
handle_command(f"! {cmd_input[1:]}", shell_state=self.shell_state)
|
201
|
+
return True
|
202
|
+
return False
|
203
|
+
|
204
|
+
def _process_prompt(self, cmd_input):
|
205
|
+
try:
|
206
|
+
import time
|
207
|
+
final_event = (
|
208
|
+
self._prompt_handler.agent.last_event
|
209
|
+
if hasattr(self._prompt_handler.agent, "last_event")
|
210
|
+
else None
|
211
|
+
)
|
212
|
+
start_time = time.time()
|
213
|
+
self._prompt_handler.run_prompt(cmd_input)
|
214
|
+
end_time = time.time()
|
215
|
+
elapsed = end_time - start_time
|
216
|
+
self.msg_count += 1
|
217
|
+
from janito.formatting_token import print_token_message_summary
|
218
|
+
usage = self.performance_collector.get_last_request_usage()
|
219
|
+
print_token_message_summary(self.console, self.msg_count, usage, elapsed=elapsed)
|
220
|
+
if final_event and hasattr(final_event, "metadata"):
|
221
|
+
exit_reason = (
|
222
|
+
final_event.metadata.get("exit_reason")
|
223
|
+
if hasattr(final_event, "metadata")
|
224
|
+
else None
|
225
|
+
)
|
226
|
+
if exit_reason:
|
227
|
+
self.console.print(
|
228
|
+
f"[bold yellow]Exit reason: {exit_reason}[/bold yellow]"
|
229
|
+
)
|
230
|
+
except Exception as exc:
|
231
|
+
self.console.print(f"[red]Exception in agent: {exc}[/red]")
|
232
|
+
import traceback
|
233
|
+
self.console.print(traceback.format_exc())
|
234
|
+
|
235
|
+
def _create_prompt_session(self):
|
236
|
+
return PromptSession(
|
237
|
+
style=chat_shell_style,
|
238
|
+
completer=ShellCommandCompleter(),
|
239
|
+
history=self.mem_history,
|
240
|
+
editing_mode=EditingMode.EMACS,
|
241
|
+
key_bindings=self.key_bindings,
|
242
|
+
bottom_toolbar=lambda: get_toolbar_func(
|
243
|
+
self.performance_collector, 0, self.shell_state
|
244
|
+
)(),
|
245
|
+
)
|
246
|
+
|
247
|
+
def _handle_input(self, session):
|
248
|
+
injected = getattr(self.shell_state, "injected_input", None)
|
249
|
+
if injected is not None:
|
250
|
+
cmd_input = injected
|
251
|
+
self.shell_state.injected_input = None
|
252
|
+
else:
|
253
|
+
try:
|
254
|
+
cmd_input = session.prompt(HTML("<inputline>💬 </inputline>"))
|
255
|
+
except (KeyboardInterrupt, EOFError):
|
256
|
+
self._handle_exit()
|
257
|
+
return None
|
258
|
+
sanitized = cmd_input.strip()
|
259
|
+
try:
|
260
|
+
sanitized.encode("utf-8")
|
261
|
+
except UnicodeEncodeError:
|
262
|
+
sanitized = sanitized.encode("utf-8", errors="replace").decode("utf-8")
|
263
|
+
self.console.print(
|
264
|
+
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
265
|
+
)
|
266
|
+
return sanitized
|
267
|
+
|
268
|
+
def _handle_exit(self):
|
269
|
+
self.console.print("[bold yellow]Exiting chat. Goodbye![/bold yellow]")
|
270
|
+
if hasattr(self, "agent") and hasattr(self.agent, "join_driver"):
|
271
|
+
if (
|
272
|
+
hasattr(self.agent, "input_queue")
|
273
|
+
and self.agent.input_queue is not None
|
274
|
+
):
|
275
|
+
self.agent.input_queue.put(None)
|
276
|
+
self.agent.join_driver()
|
277
|
+
|
278
|
+
def _handle_exit_conditions(self, cmd_input):
|
279
|
+
if cmd_input.lower() in ("/exit", ":q", ":quit"):
|
280
|
+
self._handle_exit()
|
281
|
+
return True
|
282
|
+
return False
|
@@ -90,7 +90,7 @@ def select_profile():
|
|
90
90
|
choices = [
|
91
91
|
"helpful assistant",
|
92
92
|
"developer",
|
93
|
-
"
|
93
|
+
"plain_software_developer",
|
94
94
|
"using role...",
|
95
95
|
"full custom system prompt..."
|
96
96
|
]
|
@@ -118,11 +118,11 @@ def select_profile():
|
|
118
118
|
elif answer in user_profiles:
|
119
119
|
# Return the content of the user profile as a custom system prompt
|
120
120
|
return {"profile": None, "profile_system_prompt": user_profiles[answer]}
|
121
|
-
elif answer == "
|
122
|
-
# Return the content of the built-in
|
123
|
-
with open("./janito/agent/templates/profiles/
|
121
|
+
elif answer == "plain_software_developer":
|
122
|
+
# Return the content of the built-in plain_software_developer profile prompt
|
123
|
+
with open("./janito/agent/templates/profiles/system_prompt_template_plain_software_developer.txt.j2", "r", encoding="utf-8") as f:
|
124
124
|
prompt = f.read().strip()
|
125
|
-
return {"profile": "
|
125
|
+
return {"profile": "plain_software_developer", "profile_system_prompt": prompt}
|
126
126
|
return answer
|
127
127
|
|
128
128
|
choices = [
|