janito 3.12.0__py3-none-any.whl → 3.12.2__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.
@@ -1,166 +1,166 @@
1
- """
2
- CLI Command: Show the resolved system prompt for the main agent (single-shot mode)
3
-
4
- Supports --profile to select a profile-specific system prompt template.
5
- """
6
-
7
- from janito.cli.core.runner import prepare_llm_driver_config
8
- from janito.platform_discovery import PlatformDiscovery
9
- from pathlib import Path
10
- from jinja2 import Template
11
- import importlib.resources
12
- import importlib.resources as resources
13
- import re
14
-
15
-
16
- def _compute_permission_string(args):
17
- from janito.tools.tool_base import ToolPermissions
18
-
19
- read = getattr(args, "read", False)
20
- write = getattr(args, "write", False)
21
- execute = getattr(args, "exec", False)
22
- allowed = ToolPermissions(read=read, write=write, execute=execute)
23
- perm_str = ""
24
- if allowed.read:
25
- perm_str += "r"
26
- if allowed.write:
27
- perm_str += "w"
28
- if allowed.execute:
29
- perm_str += "x"
30
- return perm_str or None
31
-
32
-
33
- def _prepare_context(args, agent_role, allowed_permissions):
34
- context = {}
35
- context["role"] = agent_role or "developer"
36
- context["profile"] = getattr(args, "profile", None)
37
- context["allowed_permissions"] = allowed_permissions
38
- context["emoji_enabled"] = getattr(args, "emoji", False)
39
- if allowed_permissions and "x" in allowed_permissions:
40
- pd = PlatformDiscovery()
41
- context["platform"] = pd.get_platform_name()
42
- context["python_version"] = pd.get_python_version()
43
- context["shell_info"] = pd.detect_shell()
44
- return context
45
-
46
-
47
- def _load_template(profile, templates_dir):
48
- if profile:
49
- sanitized_profile = re.sub(r"\\s+", "_", profile.strip())
50
- template_filename = f"system_prompt_template_{sanitized_profile}.txt.j2"
51
- template_path = templates_dir / template_filename
52
- else:
53
- return None, None
54
- template_content = None
55
- if template_path and template_path.exists():
56
- with open(template_path, "r", encoding="utf-8") as file:
57
- template_content = file.read()
58
- else:
59
- try:
60
- with importlib.resources.files("janito.agent.templates.profiles").joinpath(
61
- template_filename
62
- ).open("r", encoding="utf-8") as file:
63
- template_content = file.read()
64
- except (FileNotFoundError, ModuleNotFoundError, AttributeError):
65
- # Also check user profiles directory
66
- from pathlib import Path
67
- import os
68
-
69
- user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
70
- user_template_path = user_profiles_dir / template_filename
71
- if user_template_path.exists():
72
- with open(user_template_path, "r", encoding="utf-8") as file:
73
- template_content = file.read()
74
- else:
75
- template_content = None
76
- return template_filename, template_content
77
- return template_filename, template_content
78
-
79
-
80
- def _print_debug_info(debug_flag, template_filename, allowed_permissions, context):
81
- if debug_flag:
82
- from rich import print as rich_print
83
-
84
- rich_print(
85
- f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_filename}[/cyan]' with allowed_permissions: [yellow]{allowed_permissions}[/yellow]"
86
- )
87
- rich_print(
88
- f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]"
89
- )
90
-
91
-
92
- def handle_show_system_prompt(args):
93
- from janito.cli.main_cli import MODIFIER_KEYS
94
-
95
- modifiers = {
96
- k: getattr(args, k) for k in MODIFIER_KEYS if getattr(args, k, None) is not None
97
- }
98
- provider, llm_driver_config, agent_role = prepare_llm_driver_config(args, modifiers)
99
- if provider is None or llm_driver_config is None:
100
- print("Error: Could not resolve provider or LLM driver config.")
101
- return
102
-
103
- allowed_permissions = _compute_permission_string(args)
104
- context = _prepare_context(args, agent_role, allowed_permissions)
105
-
106
- # Debug flag detection
107
- import sys
108
-
109
- debug_flag = False
110
- try:
111
- debug_flag = hasattr(sys, "argv") and (
112
- "--debug" in sys.argv or "--verbose" in sys.argv or "-v" in sys.argv
113
- )
114
- except Exception:
115
- pass
116
-
117
- templates_dir = (
118
- Path(__file__).parent.parent.parent / "agent" / "templates" / "profiles"
119
- )
120
- profile = getattr(args, "profile", None)
121
-
122
- # Handle --market flag mapping to Market Analyst profile
123
- if profile is None and getattr(args, "market", False):
124
- profile = "Market Analyst"
125
-
126
- # Handle --developer flag mapping to Developer With Python Tools profile
127
- if profile is None and getattr(args, "developer", False):
128
- profile = "Developer With Python Tools"
129
-
130
- if not profile:
131
- print(
132
- "[janito] No profile specified. The main agent runs without a system prompt template.\n"
133
- "Use --profile PROFILE to view a profile-specific system prompt."
134
- )
135
- return
136
-
137
- template_filename, template_content = _load_template(profile, templates_dir)
138
- _print_debug_info(debug_flag, template_filename, allowed_permissions, context)
139
-
140
- if not template_content:
141
- # Try to load directly from package resources as fallback
142
- try:
143
- template_content = (
144
- resources.files("janito.agent.templates.profiles")
145
- .joinpath(
146
- f"system_prompt_template_{profile.lower().replace(' ', '_')}.txt.j2"
147
- )
148
- .read_text(encoding="utf-8")
149
- )
150
- except (FileNotFoundError, ModuleNotFoundError, AttributeError):
151
- print(
152
- f"[janito] Could not find profile '{profile}'. This may be a configuration issue."
153
- )
154
- return
155
-
156
- template = Template(template_content)
157
- system_prompt = template.render(**context)
158
- system_prompt = re.sub(r"\n{3,}", "\n\n", system_prompt)
159
-
160
- # Use the actual profile name for display, not the resolved value
161
- display_profile = profile or "main"
162
- print(f"\n--- System Prompt (resolved, profile: {display_profile}) ---\n")
163
- print(system_prompt)
164
- print("\n-------------------------------\n")
165
- if agent_role:
166
- print(f"[Role: {agent_role}]")
1
+ """
2
+ CLI Command: Show the resolved system prompt for the main agent (single-shot mode)
3
+
4
+ Supports --profile to select a profile-specific system prompt template.
5
+ """
6
+
7
+ from janito.cli.core.runner import prepare_llm_driver_config
8
+ from janito.platform_discovery import PlatformDiscovery
9
+ from pathlib import Path
10
+ from jinja2 import Template
11
+ import importlib.resources
12
+ import importlib.resources as resources
13
+ import re
14
+
15
+
16
+ def _compute_permission_string(args):
17
+ from janito.tools.tool_base import ToolPermissions
18
+
19
+ read = getattr(args, "read", False)
20
+ write = getattr(args, "write", False)
21
+ execute = getattr(args, "exec", False)
22
+ allowed = ToolPermissions(read=read, write=write, execute=execute)
23
+ perm_str = ""
24
+ if allowed.read:
25
+ perm_str += "r"
26
+ if allowed.write:
27
+ perm_str += "w"
28
+ if allowed.execute:
29
+ perm_str += "x"
30
+ return perm_str or None
31
+
32
+
33
+ def _prepare_context(args, agent_role, allowed_permissions):
34
+ context = {}
35
+ context["role"] = agent_role or "developer"
36
+ context["profile"] = getattr(args, "profile", None)
37
+ context["allowed_permissions"] = allowed_permissions
38
+ context["emoji_enabled"] = getattr(args, "emoji", False)
39
+ if allowed_permissions and "x" in allowed_permissions:
40
+ pd = PlatformDiscovery()
41
+ context["platform"] = pd.get_platform_name()
42
+ context["python_version"] = pd.get_python_version()
43
+ context["shell_info"] = pd.detect_shell()
44
+ return context
45
+
46
+
47
+ def _load_template(profile, templates_dir):
48
+ if profile:
49
+ sanitized_profile = re.sub(r"\\s+", "_", profile.strip())
50
+ template_filename = f"system_prompt_template_{sanitized_profile}.txt.j2"
51
+ template_path = templates_dir / template_filename
52
+ else:
53
+ return None, None
54
+ template_content = None
55
+ if template_path and template_path.exists():
56
+ with open(template_path, "r", encoding="utf-8") as file:
57
+ template_content = file.read()
58
+ else:
59
+ try:
60
+ with importlib.resources.files("janito.agent.templates.profiles").joinpath(
61
+ template_filename
62
+ ).open("r", encoding="utf-8") as file:
63
+ template_content = file.read()
64
+ except (FileNotFoundError, ModuleNotFoundError, AttributeError):
65
+ # Also check user profiles directory
66
+ from pathlib import Path
67
+ import os
68
+
69
+ user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
70
+ user_template_path = user_profiles_dir / template_filename
71
+ if user_template_path.exists():
72
+ with open(user_template_path, "r", encoding="utf-8") as file:
73
+ template_content = file.read()
74
+ else:
75
+ template_content = None
76
+ return template_filename, template_content
77
+ return template_filename, template_content
78
+
79
+
80
+ def _print_debug_info(debug_flag, template_filename, allowed_permissions, context):
81
+ if debug_flag:
82
+ from rich import print as rich_print
83
+
84
+ rich_print(
85
+ f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_filename}[/cyan]' with allowed_permissions: [yellow]{allowed_permissions}[/yellow]"
86
+ )
87
+ rich_print(
88
+ f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]"
89
+ )
90
+
91
+
92
+ def handle_show_system_prompt(args):
93
+ from janito.cli.main_cli import MODIFIER_KEYS
94
+
95
+ modifiers = {
96
+ k: getattr(args, k) for k in MODIFIER_KEYS if getattr(args, k, None) is not None
97
+ }
98
+ provider, llm_driver_config, agent_role = prepare_llm_driver_config(args, modifiers)
99
+ if provider is None or llm_driver_config is None:
100
+ print("Error: Could not resolve provider or LLM driver config.")
101
+ return
102
+
103
+ allowed_permissions = _compute_permission_string(args)
104
+ context = _prepare_context(args, agent_role, allowed_permissions)
105
+
106
+ # Debug flag detection
107
+ import sys
108
+
109
+ debug_flag = False
110
+ try:
111
+ debug_flag = hasattr(sys, "argv") and (
112
+ "--debug" in sys.argv or "--verbose" in sys.argv or "-v" in sys.argv
113
+ )
114
+ except Exception:
115
+ pass
116
+
117
+ templates_dir = (
118
+ Path(__file__).parent.parent.parent / "agent" / "templates" / "profiles"
119
+ )
120
+ profile = getattr(args, "profile", None)
121
+
122
+ # Handle --market flag mapping to Market Analyst profile
123
+ if profile is None and getattr(args, "market", False):
124
+ profile = "Market Analyst"
125
+
126
+ # Handle --developer flag mapping to Developer profile
127
+ if profile is None and getattr(args, "developer", False):
128
+ profile = "Developer"
129
+
130
+ if not profile:
131
+ print(
132
+ "[janito] No profile specified. The main agent runs without a system prompt template.\n"
133
+ "Use --profile PROFILE to view a profile-specific system prompt."
134
+ )
135
+ return
136
+
137
+ template_filename, template_content = _load_template(profile, templates_dir)
138
+ _print_debug_info(debug_flag, template_filename, allowed_permissions, context)
139
+
140
+ if not template_content:
141
+ # Try to load directly from package resources as fallback
142
+ try:
143
+ template_content = (
144
+ resources.files("janito.agent.templates.profiles")
145
+ .joinpath(
146
+ f"system_prompt_template_{profile.lower().replace(' ', '_')}.txt.j2"
147
+ )
148
+ .read_text(encoding="utf-8")
149
+ )
150
+ except (FileNotFoundError, ModuleNotFoundError, AttributeError):
151
+ print(
152
+ f"[janito] Could not find profile '{profile}'. This may be a configuration issue."
153
+ )
154
+ return
155
+
156
+ template = Template(template_content)
157
+ system_prompt = template.render(**context)
158
+ system_prompt = re.sub(r"\n{3,}", "\n\n", system_prompt)
159
+
160
+ # Use the actual profile name for display, not the resolved value
161
+ display_profile = profile or "main"
162
+ print(f"\n--- System Prompt (resolved, profile: {display_profile}) ---\n")
163
+ print(system_prompt)
164
+ print("\n-------------------------------\n")
165
+ if agent_role:
166
+ print(f"[Role: {agent_role}]")
janito/cli/console.py CHANGED
@@ -1,3 +1,3 @@
1
- from rich.console import Console
2
-
3
- shared_console = Console()
1
+ from rich.console import Console
2
+
3
+ shared_console = Console(file=None)