janito 2.5.1__py3-none-any.whl → 2.6.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 (68) hide show
  1. janito/__init__.py +7 -6
  2. janito/__main__.py +5 -4
  3. janito/_version.py +58 -57
  4. janito/agent/setup_agent.py +241 -223
  5. janito/agent/templates/profiles/system_prompt_template_software developer.txt.j2 +39 -0
  6. janito/cli/__init__.py +10 -9
  7. janito/cli/chat_mode/bindings.py +38 -62
  8. janito/cli/chat_mode/chat_entry.py +23 -22
  9. janito/cli/chat_mode/prompt_style.py +25 -24
  10. janito/cli/chat_mode/script_runner.py +154 -153
  11. janito/cli/chat_mode/session.py +32 -44
  12. janito/cli/chat_mode/session_profile_select.py +125 -55
  13. janito/cli/chat_mode/shell/commands/tools.py +51 -48
  14. janito/cli/chat_mode/toolbar.py +42 -68
  15. janito/cli/cli_commands/list_tools.py +41 -56
  16. janito/cli/cli_commands/show_system_prompt.py +70 -49
  17. janito/cli/core/runner.py +6 -1
  18. janito/cli/core/setters.py +43 -34
  19. janito/cli/main_cli.py +25 -1
  20. janito/cli/prompt_core.py +76 -69
  21. janito/cli/rich_terminal_reporter.py +22 -1
  22. janito/cli/single_shot_mode/handler.py +95 -94
  23. janito/drivers/driver_registry.py +27 -29
  24. janito/drivers/openai/driver.py +436 -494
  25. janito/llm/agent.py +54 -68
  26. janito/provider_registry.py +178 -178
  27. janito/providers/anthropic/model_info.py +41 -22
  28. janito/providers/anthropic/provider.py +80 -67
  29. janito/providers/provider_static_info.py +18 -17
  30. janito/tools/adapters/local/__init__.py +66 -65
  31. janito/tools/adapters/local/adapter.py +79 -18
  32. janito/tools/adapters/local/create_directory.py +9 -9
  33. janito/tools/adapters/local/create_file.py +12 -12
  34. janito/tools/adapters/local/delete_text_in_file.py +16 -16
  35. janito/tools/adapters/local/find_files.py +2 -2
  36. janito/tools/adapters/local/get_file_outline/core.py +5 -5
  37. janito/tools/adapters/local/get_file_outline/search_outline.py +4 -4
  38. janito/tools/adapters/local/open_html_in_browser.py +15 -15
  39. janito/tools/adapters/local/python_file_run.py +4 -4
  40. janito/tools/adapters/local/read_files.py +40 -0
  41. janito/tools/adapters/local/remove_directory.py +5 -5
  42. janito/tools/adapters/local/remove_file.py +4 -4
  43. janito/tools/adapters/local/replace_text_in_file.py +21 -21
  44. janito/tools/adapters/local/run_bash_command.py +1 -1
  45. janito/tools/adapters/local/search_text/pattern_utils.py +2 -2
  46. janito/tools/adapters/local/search_text/traverse_directory.py +10 -10
  47. janito/tools/adapters/local/validate_file_syntax/core.py +7 -7
  48. janito/tools/adapters/local/validate_file_syntax/css_validator.py +2 -2
  49. janito/tools/adapters/local/validate_file_syntax/html_validator.py +7 -7
  50. janito/tools/adapters/local/validate_file_syntax/js_validator.py +2 -2
  51. janito/tools/adapters/local/validate_file_syntax/json_validator.py +2 -2
  52. janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +2 -2
  53. janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +2 -2
  54. janito/tools/adapters/local/validate_file_syntax/python_validator.py +2 -2
  55. janito/tools/adapters/local/validate_file_syntax/xml_validator.py +2 -2
  56. janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +2 -2
  57. janito/tools/adapters/local/view_file.py +12 -12
  58. janito/tools/path_security.py +204 -0
  59. janito/tools/tool_use_tracker.py +12 -12
  60. janito/tools/tools_adapter.py +66 -34
  61. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/METADATA +417 -412
  62. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/RECORD +66 -65
  63. janito/drivers/anthropic/driver.py +0 -113
  64. janito/tools/adapters/local/get_file_outline/python_outline_v2.py +0 -156
  65. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/WHEEL +0 -0
  66. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/entry_points.txt +0 -0
  67. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/licenses/LICENSE +0 -0
  68. {janito-2.5.1.dist-info → janito-2.6.1.dist-info}/top_level.txt +0 -0
janito/__init__.py CHANGED
@@ -1,6 +1,7 @@
1
- """
2
- janito: A Python package for managing and interacting with Large Language Model (LLM) providers and their APIs.
3
- Provides a CLI for credential management and an extensible driver system for LLMs.
4
- """
5
-
6
- from ._version import __version__
1
+ """
2
+ janito: A Python package for managing and interacting with Large Language Model (LLM) providers and their APIs.
3
+ Provides a CLI for credential management and an extensible driver system for LLMs.
4
+ """
5
+
6
+ from ._version import __version__
7
+
janito/__main__.py CHANGED
@@ -1,4 +1,5 @@
1
- from .cli.main import main
2
-
3
- if __name__ == "__main__":
4
- main()
1
+ from .cli.main import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
5
+
janito/_version.py CHANGED
@@ -1,57 +1,58 @@
1
- """Version handling for Janito.
2
- Attempts to obtain the package version in the following order:
3
- 1. If a janito.version module exists (generated when the package is built with
4
- setuptools-scm), use the version attribute from that module.
5
- 2. Ask importlib.metadata for the installed distribution version – works for
6
- both regular and editable installs handled by pip.
7
- 3. Fall back to calling setuptools_scm.get_version() directly, using the git
8
- repository when running from source without an installed distribution.
9
- 4. If everything else fails, return the literal string ``"unknown"`` so that
10
- the application continues to work even when the version cannot be
11
- determined.
12
-
13
- This layered approach guarantees that a meaningful version string is returned
14
- in most development and production scenarios while keeping Janito free from
15
- hard-coded version numbers.
16
- """
17
-
18
- from __future__ import annotations
19
-
20
- import pathlib
21
- from importlib import metadata as importlib_metadata
22
-
23
- __all__ = ["__version__"]
24
-
25
-
26
- # 1. "janito.version" (generated at build time by setuptools-scm)
27
- try:
28
- from . import version as _generated_version # type: ignore
29
-
30
- __version__: str = _generated_version.version # pytype: disable=module-attr
31
- except ImportError: # pragma: no cover – not available in editable installs
32
-
33
- def _resolve_version() -> str:
34
- """Resolve the version string using several fallbacks."""
35
-
36
- # 2. importlib.metadata – works for both regular and `pip install -e`.
37
- try:
38
- return importlib_metadata.version("janito")
39
- except importlib_metadata.PackageNotFoundError:
40
- pass # Not installed – probably running from a source checkout.
41
-
42
- # 3. setuptools_scm – query the VCS metadata directly.
43
- try:
44
- from setuptools_scm import get_version # Imported lazily.
45
-
46
- package_root = pathlib.Path(__file__).resolve().parent.parent
47
- return get_version(root=str(package_root), relative_to=__file__)
48
- except Exception: # pragma: no cover – any failure here falls through
49
- # Either setuptools_scm is not available or this is not a git repo.
50
- pass
51
-
52
- # 4. Ultimate fallback – return a placeholder.
53
- return "unknown"
54
-
55
- __version__ = _resolve_version()
56
-
57
-
1
+ """Version handling for Janito.
2
+ Attempts to obtain the package version in the following order:
3
+ 1. If a janito.version module exists (generated when the package is built with
4
+ setuptools-scm), use the version attribute from that module.
5
+ 2. Ask importlib.metadata for the installed distribution version – works for
6
+ both regular and editable installs handled by pip.
7
+ 3. Fall back to calling setuptools_scm.get_version() directly, using the git
8
+ repository when running from source without an installed distribution.
9
+ 4. If everything else fails, return the literal string ``"unknown"`` so that
10
+ the application continues to work even when the version cannot be
11
+ determined.
12
+
13
+ This layered approach guarantees that a meaningful version string is returned
14
+ in most development and production scenarios while keeping Janito free from
15
+ hard-coded version numbers.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import pathlib
21
+ from importlib import metadata as importlib_metadata
22
+
23
+ __all__ = ["__version__"]
24
+
25
+
26
+ # 1. "janito.version" (generated at build time by setuptools-scm)
27
+ try:
28
+ from . import version as _generated_version # type: ignore
29
+
30
+ __version__: str = _generated_version.version # pytype: disable=module-attr
31
+ except ImportError: # pragma: no cover – not available in editable installs
32
+
33
+ def _resolve_version() -> str:
34
+ """Resolve the version string using several fallbacks."""
35
+
36
+ # 2. importlib.metadata – works for both regular and `pip install -e`.
37
+ try:
38
+ return importlib_metadata.version("janito")
39
+ except importlib_metadata.PackageNotFoundError:
40
+ pass # Not installed – probably running from a source checkout.
41
+
42
+ # 3. setuptools_scm – query the VCS metadata directly.
43
+ try:
44
+ from setuptools_scm import get_version # Imported lazily.
45
+
46
+ package_root = pathlib.Path(__file__).resolve().parent.parent
47
+ return get_version(root=str(package_root), relative_to=__file__)
48
+ except Exception: # pragma: no cover – any failure here falls through
49
+ # Either setuptools_scm is not available or this is not a git repo.
50
+ pass
51
+
52
+ # 4. Ultimate fallback – return a placeholder.
53
+ return "unknown"
54
+
55
+ __version__ = _resolve_version()
56
+
57
+
58
+
@@ -1,223 +1,241 @@
1
- from pathlib import Path
2
- from jinja2 import Template
3
- import importlib.resources
4
- import sys
5
- import warnings
6
- from janito.tools import get_local_tools_adapter
7
- from janito.llm.agent import LLMAgent
8
- from janito.drivers.driver_registry import get_driver_class
9
- from queue import Queue
10
- from janito.platform_discovery import PlatformDiscovery
11
-
12
-
13
- def setup_agent(
14
- provider_instance,
15
- llm_driver_config,
16
- role=None,
17
- templates_dir=None,
18
- zero_mode=False,
19
- input_queue=None,
20
- output_queue=None,
21
- verbose_tools=False,
22
- verbose_agent=False,
23
-
24
- allowed_permissions=None,
25
- profile=None,
26
- profile_system_prompt=None,
27
- ):
28
- """
29
- Creates an agent. A system prompt is rendered from a template only when a profile is specified.
30
- """
31
- tools_provider = get_local_tools_adapter()
32
- tools_provider.set_verbose_tools(verbose_tools)
33
-
34
- # If zero_mode is enabled or no profile is given we skip the system prompt.
35
- if zero_mode or (profile is None and profile_system_prompt is None):
36
- # Pass provider to agent, let agent create driver
37
- agent = LLMAgent(
38
- provider_instance,
39
- tools_provider,
40
- agent_name=role or "developer",
41
- system_prompt=None,
42
- input_queue=input_queue,
43
- output_queue=output_queue,
44
- verbose_agent=verbose_agent,
45
- )
46
- if role:
47
- agent.template_vars["role"] = role
48
- return agent
49
- # If profile_system_prompt is set, use it directly
50
- if profile_system_prompt is not None:
51
- agent = LLMAgent(
52
- provider_instance,
53
- tools_provider,
54
- agent_name=role or "developer",
55
- system_prompt=profile_system_prompt,
56
- input_queue=input_queue,
57
- output_queue=output_queue,
58
- verbose_agent=verbose_agent,
59
- )
60
- agent.template_vars["role"] = role or "developer"
61
- agent.template_vars["profile"] = None
62
- agent.template_vars["profile_system_prompt"] = profile_system_prompt
63
- return agent
64
- # Normal flow (profile-specific system prompt)
65
- if templates_dir is None:
66
- # Set default template directory
67
- templates_dir = Path(__file__).parent / "templates" / "profiles"
68
- template_filename = f"system_prompt_template_{profile}.txt.j2"
69
- template_path = templates_dir / template_filename
70
-
71
- template_content = None
72
- if template_path.exists():
73
- with open(template_path, "r", encoding="utf-8") as file:
74
- template_content = file.read()
75
- else:
76
- # Try package import fallback: janito.agent.templates.profiles.system_prompt_template_<profile>.txt.j2
77
- try:
78
- with importlib.resources.files("janito.agent.templates.profiles").joinpath(
79
- template_filename
80
- ).open("r", encoding="utf-8") as file:
81
- template_content = file.read()
82
- except (FileNotFoundError, ModuleNotFoundError, AttributeError):
83
- if profile:
84
- raise FileNotFoundError(
85
- f"[janito] Could not find profile-specific template '{template_filename}' in {template_path} nor in janito.agent.templates.profiles package."
86
- )
87
- else:
88
- warnings.warn(
89
- f"[janito] Could not find {template_filename} in {template_path} nor in janito.agent.templates.profiles package."
90
- )
91
- raise FileNotFoundError(
92
- f"Template file not found in either {template_path} or package resource."
93
- )
94
-
95
- import time
96
- template = Template(template_content)
97
- # Prepare context for Jinja2 rendering from llm_driver_config
98
- # Compose context for Jinja2 rendering without using to_dict or temperature
99
- context = {}
100
- context["role"] = role or "developer"
101
- context["profile"] = profile
102
- # Normalize and inject allowed tool permissions
103
- from janito.tools.tool_base import ToolPermissions
104
- from janito.tools.permissions import get_global_allowed_permissions
105
-
106
- if allowed_permissions is None:
107
- # Fallback to globally configured permissions if not explicitly provided
108
- allowed_permissions = get_global_allowed_permissions()
109
-
110
- # Convert ToolPermissions -> string like "rwx" so the Jinja template can use
111
- # membership checks such as `'r' in allowed_permissions`.
112
- if isinstance(allowed_permissions, ToolPermissions):
113
- perm_str = ""
114
- if allowed_permissions.read:
115
- perm_str += "r"
116
- if allowed_permissions.write:
117
- perm_str += "w"
118
- if allowed_permissions.execute:
119
- perm_str += "x"
120
- allowed_permissions = perm_str or None # None if empty
121
-
122
- context["allowed_permissions"] = allowed_permissions
123
-
124
- # Inject platform information only when execute permission is granted
125
- if allowed_permissions and 'x' in allowed_permissions:
126
- pd = PlatformDiscovery()
127
- context["platform"] = pd.get_platform_name()
128
- context["python_version"] = pd.get_python_version()
129
- context["shell_info"] = pd.detect_shell()
130
- # DEBUG: Show permissions passed to template
131
- from rich import print as rich_print
132
- debug_flag = False
133
- try:
134
- debug_flag = (hasattr(sys, 'argv') and ('--debug' in sys.argv or '--verbose' in sys.argv or '-v' in sys.argv))
135
- except Exception:
136
- pass
137
- if debug_flag:
138
- rich_print(f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_filename}[/cyan]' with allowed_permissions: [yellow]{allowed_permissions}[/yellow]")
139
- rich_print(f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]")
140
- start_render = time.time()
141
- rendered_prompt = template.render(**context)
142
- end_render = time.time()
143
-
144
- # Create the agent as before, now passing the explicit role
145
- # Do NOT pass temperature; do not depend on to_dict
146
- agent = LLMAgent(
147
- provider_instance,
148
- tools_provider,
149
- agent_name=role or "developer",
150
- system_prompt=rendered_prompt,
151
- input_queue=input_queue,
152
- output_queue=output_queue,
153
- verbose_agent=verbose_agent,
154
- )
155
- agent.template_vars["role"] = context["role"]
156
- agent.template_vars["profile"] = profile
157
- # Store template path and context for dynamic prompt refresh
158
- agent.system_prompt_template = str(template_path)
159
-
160
- agent._template_vars = context.copy()
161
- agent._original_template_vars = context.copy()
162
- return agent
163
-
164
-
165
- def create_configured_agent(
166
- *,
167
- provider_instance=None,
168
- llm_driver_config=None,
169
- role=None,
170
- verbose_tools=False,
171
- verbose_agent=False,
172
- templates_dir=None,
173
- zero_mode=False,
174
-
175
- allowed_permissions=None,
176
- profile=None,
177
- profile_system_prompt=None,
178
- ):
179
- """
180
- Normalizes agent setup for all CLI modes.
181
-
182
- Args:
183
- provider_instance: Provider instance for the agent
184
- llm_driver_config: LLM driver configuration
185
- role: Optional role string
186
- verbose_tools: Optional, default False
187
- verbose_agent: Optional, default False
188
- templates_dir: Optional
189
- zero_mode: Optional, default False
190
-
191
- Returns:
192
- Configured agent instance
193
- """
194
- # If provider_instance has create_driver, wire queues (single-shot mode)
195
- input_queue = None
196
- output_queue = None
197
- driver = None
198
- if hasattr(provider_instance, "create_driver"):
199
- driver = provider_instance.create_driver()
200
- driver.start() # Ensure the driver background thread is started
201
- input_queue = getattr(driver, "input_queue", None)
202
- output_queue = getattr(driver, "output_queue", None)
203
-
204
- # Automatically enable system prompt when a profile is specified
205
-
206
- agent = setup_agent(
207
- provider_instance=provider_instance,
208
- llm_driver_config=llm_driver_config,
209
- role=role,
210
- templates_dir=templates_dir,
211
- zero_mode=zero_mode,
212
- input_queue=input_queue,
213
- output_queue=output_queue,
214
- verbose_tools=verbose_tools,
215
- verbose_agent=verbose_agent,
216
-
217
- allowed_permissions=allowed_permissions,
218
- profile=profile,
219
- profile_system_prompt=profile_system_prompt,
220
- )
221
- if driver is not None:
222
- agent.driver = driver # Attach driver to agent for thread management
223
- return agent
1
+ import importlib.resources
2
+ import re
3
+ import os
4
+ import sys
5
+ import time
6
+ import warnings
7
+ import threading
8
+ from pathlib import Path
9
+ from jinja2 import Template
10
+ from pathlib import Path
11
+ from queue import Queue
12
+ from rich import print as rich_print
13
+ from janito.tools import get_local_tools_adapter
14
+ from janito.llm.agent import LLMAgent
15
+ from janito.drivers.driver_registry import get_driver_class
16
+ from janito.platform_discovery import PlatformDiscovery
17
+ from janito.tools.tool_base import ToolPermissions
18
+ from janito.tools.permissions import get_global_allowed_permissions
19
+
20
+ def _load_template_content(profile, templates_dir):
21
+ """
22
+ Loads the template content for the given profile from the specified directory or package resources.
23
+ If the profile template is not found in the default locations, tries to load from the user profiles directory ~/.janito/profiles.
24
+ """
25
+
26
+
27
+ template_filename = f"system_prompt_template_{profile}.txt.j2"
28
+ template_path = templates_dir / template_filename
29
+ if template_path.exists():
30
+ with open(template_path, "r", encoding="utf-8") as file:
31
+ return file.read(), template_path
32
+ # Try package import fallback
33
+ try:
34
+ with importlib.resources.files("janito.agent.templates.profiles").joinpath(
35
+ template_filename
36
+ ).open("r", encoding="utf-8") as file:
37
+ return file.read(), template_path
38
+ except (FileNotFoundError, ModuleNotFoundError, AttributeError):
39
+ # Try user profiles directory
40
+ user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
41
+ user_template_path = user_profiles_dir / profile
42
+ if user_template_path.exists():
43
+ with open(user_template_path, "r", encoding="utf-8") as file:
44
+ return file.read(), user_template_path
45
+ raise FileNotFoundError(
46
+ f"[janito] Could not find profile-specific template '{template_filename}' in {template_path} nor in janito.agent.templates.profiles package nor in user profiles directory {user_template_path}."
47
+ )
48
+
49
+
50
+ def _prepare_template_context(role, profile, allowed_permissions):
51
+ """
52
+ Prepares the context dictionary for Jinja2 template rendering.
53
+ """
54
+ context = {}
55
+ context["role"] = role or "developer"
56
+ context["profile"] = profile
57
+ if allowed_permissions is None:
58
+ allowed_permissions = get_global_allowed_permissions()
59
+ # Convert ToolPermissions -> string like "rwx"
60
+ if isinstance(allowed_permissions, ToolPermissions):
61
+ perm_str = ""
62
+ if allowed_permissions.read:
63
+ perm_str += "r"
64
+ if allowed_permissions.write:
65
+ perm_str += "w"
66
+ if allowed_permissions.execute:
67
+ perm_str += "x"
68
+ allowed_permissions = perm_str or None
69
+ context["allowed_permissions"] = allowed_permissions
70
+ # Inject platform info if execute permission is present
71
+ if allowed_permissions and 'x' in allowed_permissions:
72
+ pd = PlatformDiscovery()
73
+ context["platform"] = pd.get_platform_name()
74
+ context["python_version"] = pd.get_python_version()
75
+ context["shell_info"] = pd.detect_shell()
76
+ return context
77
+
78
+
79
+ def _create_agent(provider_instance, tools_provider, role, system_prompt, input_queue, output_queue, verbose_agent, context, template_path, profile):
80
+ """
81
+ Creates and returns an LLMAgent instance with the provided parameters.
82
+ """
83
+ agent = LLMAgent(
84
+ provider_instance,
85
+ tools_provider,
86
+ agent_name=role or "developer",
87
+ system_prompt=system_prompt,
88
+ input_queue=input_queue,
89
+ output_queue=output_queue,
90
+ verbose_agent=verbose_agent,
91
+ )
92
+ agent.template_vars["role"] = context["role"]
93
+ agent.template_vars["profile"] = profile
94
+ agent.system_prompt_template = str(template_path)
95
+ agent._template_vars = context.copy()
96
+ agent._original_template_vars = context.copy()
97
+ return agent
98
+
99
+
100
+ def setup_agent(
101
+ provider_instance,
102
+ llm_driver_config,
103
+ role=None,
104
+ templates_dir=None,
105
+ zero_mode=False,
106
+ input_queue=None,
107
+ output_queue=None,
108
+ verbose_tools=False,
109
+ verbose_agent=False,
110
+ allowed_permissions=None,
111
+ profile=None,
112
+ profile_system_prompt=None,
113
+ ):
114
+ """
115
+ Creates an agent. A system prompt is rendered from a template only when a profile is specified.
116
+ """
117
+ tools_provider = get_local_tools_adapter()
118
+ tools_provider.set_verbose_tools(verbose_tools)
119
+
120
+ # If zero_mode is enabled or no profile is given we skip the system prompt.
121
+ if zero_mode or (profile is None and profile_system_prompt is None):
122
+ agent = LLMAgent(
123
+ provider_instance,
124
+ tools_provider,
125
+ agent_name=role or "developer",
126
+ system_prompt=None,
127
+ input_queue=input_queue,
128
+ output_queue=output_queue,
129
+ verbose_agent=verbose_agent,
130
+ )
131
+ if role:
132
+ agent.template_vars["role"] = role
133
+ return agent
134
+
135
+ # If profile_system_prompt is set, use it directly
136
+ if profile_system_prompt is not None:
137
+ agent = LLMAgent(
138
+ provider_instance,
139
+ tools_provider,
140
+ agent_name=role or "developer",
141
+ system_prompt=profile_system_prompt,
142
+ input_queue=input_queue,
143
+ output_queue=output_queue,
144
+ verbose_agent=verbose_agent,
145
+ )
146
+ agent.template_vars["role"] = role or "developer"
147
+ agent.template_vars["profile"] = None
148
+ agent.template_vars["profile_system_prompt"] = profile_system_prompt
149
+ return agent
150
+
151
+ # Normal flow (profile-specific system prompt)
152
+ if templates_dir is None:
153
+ templates_dir = Path(__file__).parent / "templates" / "profiles"
154
+ template_content, template_path = _load_template_content(profile, templates_dir)
155
+
156
+ template = Template(template_content)
157
+ context = _prepare_template_context(role, profile, allowed_permissions)
158
+
159
+ # Debug output if requested
160
+ debug_flag = False
161
+ try:
162
+ debug_flag = (hasattr(sys, 'argv') and ('--debug' in sys.argv or '--verbose' in sys.argv or '-v' in sys.argv))
163
+ except Exception:
164
+ pass
165
+ if debug_flag:
166
+ rich_print(f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_path.name}[/cyan]' with allowed_permissions: [yellow]{context.get('allowed_permissions')}[/yellow]")
167
+ rich_print(f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]")
168
+ start_render = time.time()
169
+ rendered_prompt = template.render(**context)
170
+ end_render = time.time()
171
+ # Merge multiple empty lines into a single empty line
172
+ rendered_prompt = re.sub(r'\n{3,}', '\n\n', rendered_prompt)
173
+
174
+ return _create_agent(
175
+ provider_instance,
176
+ tools_provider,
177
+ role,
178
+ rendered_prompt,
179
+ input_queue,
180
+ output_queue,
181
+ verbose_agent,
182
+ context,
183
+ template_path,
184
+ profile,
185
+ )
186
+
187
+
188
+ def create_configured_agent(
189
+ *,
190
+ provider_instance=None,
191
+ llm_driver_config=None,
192
+ role=None,
193
+ verbose_tools=False,
194
+ verbose_agent=False,
195
+ templates_dir=None,
196
+ zero_mode=False,
197
+ allowed_permissions=None,
198
+ profile=None,
199
+ profile_system_prompt=None,
200
+ ):
201
+ """
202
+ Normalizes agent setup for all CLI modes.
203
+
204
+ Args:
205
+ provider_instance: Provider instance for the agent
206
+ llm_driver_config: LLM driver configuration
207
+ role: Optional role string
208
+ verbose_tools: Optional, default False
209
+ verbose_agent: Optional, default False
210
+ templates_dir: Optional
211
+ zero_mode: Optional, default False
212
+
213
+ Returns:
214
+ Configured agent instance
215
+ """
216
+ input_queue = None
217
+ output_queue = None
218
+ driver = None
219
+ if hasattr(provider_instance, "create_driver"):
220
+ driver = provider_instance.create_driver()
221
+ driver.start() # Ensure the driver background thread is started
222
+ input_queue = getattr(driver, "input_queue", None)
223
+ output_queue = getattr(driver, "output_queue", None)
224
+
225
+ agent = setup_agent(
226
+ provider_instance=provider_instance,
227
+ llm_driver_config=llm_driver_config,
228
+ role=role,
229
+ templates_dir=templates_dir,
230
+ zero_mode=zero_mode,
231
+ input_queue=input_queue,
232
+ output_queue=output_queue,
233
+ verbose_tools=verbose_tools,
234
+ verbose_agent=verbose_agent,
235
+ allowed_permissions=allowed_permissions,
236
+ profile=profile,
237
+ profile_system_prompt=profile_system_prompt,
238
+ )
239
+ if driver is not None:
240
+ agent.driver = driver # Attach driver to agent for thread management
241
+ return agent
@@ -0,0 +1,39 @@
1
+ You are: software developer
2
+
3
+ {# Improves tool selection and platform specific constrains, eg, path format, C:\ vs /path #}
4
+ {% if allowed_permissions and 'x' in allowed_permissions %}
5
+ You will be using the following environment:
6
+ Platform: {{ platform }}
7
+ Shell/Environment: {{ shell_info }}
8
+ {% endif %}
9
+
10
+
11
+ {% if allowed_permissions and 'r' in allowed_permissions %}
12
+ Before answering map the questions to artifacts found in the current directory - the current project.
13
+ {% endif %}
14
+
15
+ Respond according to the following guidelines:
16
+ {% if allowed_permissions %}
17
+ - Before using the namespace tools provide a short reason
18
+ {% endif %}
19
+ {% if allowed_permissions and 'r' in allowed_permissions %}
20
+ {# Exploratory hint #}
21
+ - Before answering to the user, explore the content related to the question
22
+ {# Reduces chunking roundtip #}
23
+ - When exploring full files content, provide empty range to read the entire files instead of chunked reads
24
+ {% endif %}
25
+ {% if allowed_permissions and 'w' in allowed_permissions %}
26
+ {# Reduce unrequest code verbosity overhead #}
27
+ - Use the namespace functions to deliver the code changes instead of showing the code.
28
+ {# Drive edit mode, place holders critical as shown to be crucial to avoid corruption with code placeholders #}
29
+ - Prefer making localized edits using string replacements. If the required change is extensive, replace the entire file instead, provide full content without placeholders.
30
+ {# Without this, the LLM choses to create files from a literal interpretation of the purpose and intention #}
31
+ - Before creating files search the code for the location related to the file purpose
32
+ {# This will trigger a search for the old names/locations to be updates #}
33
+ - After moving, removing or renaming functions or classes to different modules, update all imports, references, tests, and documentation to reflect the new locations, then verify functionality.
34
+ {# Keeping docstrings update is key to have semanatic match between prompts and code #}
35
+ - Once development or updates are finished, ensure that new or updated packages, modules, functions are properly documented.
36
+ {# Trying to prevent surrogates generation, found this frequently in gpt4.1/windows #}
37
+ - While writing code, if you need an emoji or special Unicode character in a string, then insert the actual character (e.g., 📖) directly instead of using surrogate pairs or escape sequences.
38
+ {% endif %}
39
+