janito 2.3.0__py3-none-any.whl → 2.3.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.
- janito/__init__.py +6 -6
- janito/cli/chat_mode/shell/autocomplete.py +21 -21
- janito/cli/chat_mode/shell/commands/clear.py +12 -12
- janito/cli/chat_mode/shell/commands/multi.py +51 -51
- janito/cli/chat_mode/shell/input_history.py +62 -62
- janito/cli/cli_commands/list_models.py +35 -35
- janito/cli/cli_commands/list_providers.py +9 -9
- janito/cli/cli_commands/list_tools.py +53 -53
- janito/cli/cli_commands/model_selection.py +50 -50
- janito/cli/cli_commands/model_utils.py +95 -95
- janito/cli/cli_commands/set_api_key.py +19 -19
- janito/cli/cli_commands/show_config.py +51 -51
- janito/cli/cli_commands/show_system_prompt.py +62 -62
- janito/cli/core/__init__.py +4 -4
- janito/cli/core/event_logger.py +59 -59
- janito/cli/core/getters.py +33 -33
- janito/cli/core/unsetters.py +54 -54
- janito/cli/single_shot_mode/__init__.py +6 -6
- janito/config.py +5 -5
- janito/config_manager.py +112 -112
- janito/drivers/anthropic/driver.py +113 -113
- janito/formatting_token.py +54 -54
- janito/i18n/__init__.py +35 -35
- janito/i18n/messages.py +23 -23
- janito/i18n/pt.py +47 -47
- janito/llm/__init__.py +5 -5
- janito/llm/agent.py +443 -443
- janito/llm/auth.py +63 -63
- janito/llm/driver_config_builder.py +34 -34
- janito/llm/driver_input.py +12 -12
- janito/llm/message_parts.py +60 -60
- janito/llm/model.py +38 -38
- janito/llm/provider.py +196 -196
- janito/provider_registry.py +176 -176
- janito/providers/anthropic/model_info.py +22 -22
- janito/providers/anthropic/provider.py +2 -0
- janito/providers/azure_openai/model_info.py +16 -16
- janito/providers/azure_openai/provider.py +3 -0
- janito/providers/deepseek/__init__.py +1 -1
- janito/providers/deepseek/model_info.py +16 -16
- janito/providers/deepseek/provider.py +94 -91
- janito/providers/google/provider.py +3 -0
- janito/providers/mistralai/provider.py +3 -0
- janito/providers/openai/provider.py +4 -0
- janito/tools/adapters/__init__.py +1 -1
- janito/tools/adapters/local/ask_user.py +102 -102
- janito/tools/adapters/local/copy_file.py +84 -84
- janito/tools/adapters/local/create_directory.py +69 -69
- janito/tools/adapters/local/create_file.py +82 -82
- janito/tools/adapters/local/fetch_url.py +97 -97
- janito/tools/adapters/local/find_files.py +138 -138
- janito/tools/adapters/local/get_file_outline/__init__.py +1 -1
- janito/tools/adapters/local/get_file_outline/core.py +117 -117
- janito/tools/adapters/local/get_file_outline/java_outline.py +40 -40
- janito/tools/adapters/local/get_file_outline/markdown_outline.py +14 -14
- janito/tools/adapters/local/get_file_outline/python_outline.py +303 -303
- janito/tools/adapters/local/get_file_outline/python_outline_v2.py +156 -156
- janito/tools/adapters/local/get_file_outline/search_outline.py +33 -33
- janito/tools/adapters/local/python_code_run.py +166 -166
- janito/tools/adapters/local/python_command_run.py +164 -164
- janito/tools/adapters/local/python_file_run.py +163 -163
- janito/tools/adapters/local/run_bash_command.py +176 -176
- janito/tools/adapters/local/run_powershell_command.py +219 -219
- janito/tools/adapters/local/search_text/__init__.py +1 -1
- janito/tools/adapters/local/search_text/core.py +201 -201
- janito/tools/adapters/local/search_text/pattern_utils.py +73 -73
- janito/tools/adapters/local/search_text/traverse_directory.py +145 -145
- janito/tools/adapters/local/validate_file_syntax/__init__.py +1 -1
- janito/tools/adapters/local/validate_file_syntax/core.py +106 -106
- janito/tools/adapters/local/validate_file_syntax/css_validator.py +35 -35
- janito/tools/adapters/local/validate_file_syntax/html_validator.py +93 -93
- janito/tools/adapters/local/validate_file_syntax/js_validator.py +27 -27
- janito/tools/adapters/local/validate_file_syntax/json_validator.py +6 -6
- janito/tools/adapters/local/validate_file_syntax/markdown_validator.py +109 -109
- janito/tools/adapters/local/validate_file_syntax/ps1_validator.py +32 -32
- janito/tools/adapters/local/validate_file_syntax/python_validator.py +5 -5
- janito/tools/adapters/local/validate_file_syntax/xml_validator.py +11 -11
- janito/tools/adapters/local/validate_file_syntax/yaml_validator.py +6 -6
- janito/tools/adapters/local/view_file.py +167 -167
- janito/tools/inspect_registry.py +17 -17
- janito/tools/tool_base.py +105 -105
- janito/tools/tool_events.py +58 -58
- janito/tools/tool_run_exception.py +12 -12
- janito/tools/tool_use_tracker.py +81 -81
- janito/tools/tool_utils.py +45 -45
- janito/tools/tools_schema.py +104 -104
- janito/version.py +4 -4
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/METADATA +390 -388
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/RECORD +93 -93
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/WHEEL +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/entry_points.txt +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/licenses/LICENSE +0 -0
- {janito-2.3.0.dist-info → janito-2.3.1.dist-info}/top_level.txt +0 -0
@@ -1,95 +1,95 @@
|
|
1
|
-
"""
|
2
|
-
Utilities for model-related CLI output
|
3
|
-
"""
|
4
|
-
|
5
|
-
|
6
|
-
def _print_models_table(models, provider_name):
|
7
|
-
from rich.table import Table
|
8
|
-
from rich.console import Console
|
9
|
-
|
10
|
-
headers = [
|
11
|
-
"name",
|
12
|
-
"open",
|
13
|
-
"context",
|
14
|
-
"max_input",
|
15
|
-
"max_cot",
|
16
|
-
"max_response",
|
17
|
-
"thinking_supported",
|
18
|
-
"driver",
|
19
|
-
]
|
20
|
-
display_headers = [
|
21
|
-
"Model Name",
|
22
|
-
"Vendor",
|
23
|
-
"context",
|
24
|
-
"max_input",
|
25
|
-
"max_cot",
|
26
|
-
"max_response",
|
27
|
-
"Thinking",
|
28
|
-
"Driver",
|
29
|
-
]
|
30
|
-
table = Table(title=f"Supported models for provider '{provider_name}'")
|
31
|
-
_add_table_columns(table, display_headers)
|
32
|
-
num_fields = {"context", "max_input", "max_cot", "max_response"}
|
33
|
-
for m in models:
|
34
|
-
row = [str(m.get("name", ""))]
|
35
|
-
row.extend(_build_model_row(m, headers, num_fields))
|
36
|
-
table.add_row(*row)
|
37
|
-
import sys
|
38
|
-
if sys.stdout.isatty():
|
39
|
-
from rich.console import Console
|
40
|
-
Console().print(table)
|
41
|
-
else:
|
42
|
-
# ASCII-friendly fallback table when output is redirected
|
43
|
-
print(f"Supported models for provider '{provider_name}'")
|
44
|
-
headers_fallback = [h for h in display_headers]
|
45
|
-
print(' | '.join(headers_fallback))
|
46
|
-
for m in models:
|
47
|
-
row = [str(m.get('name', ''))]
|
48
|
-
row.extend(_build_model_row(m, headers, num_fields))
|
49
|
-
print(' | '.join(row))
|
50
|
-
|
51
|
-
|
52
|
-
def _add_table_columns(table, display_headers):
|
53
|
-
for i, h in enumerate(display_headers):
|
54
|
-
justify = "right" if i == 0 else "center"
|
55
|
-
table.add_column(h, style="bold", justify=justify)
|
56
|
-
|
57
|
-
|
58
|
-
def _format_k(val):
|
59
|
-
try:
|
60
|
-
n = int(val)
|
61
|
-
if n >= 1000:
|
62
|
-
return f"{n // 1000}k"
|
63
|
-
return str(n)
|
64
|
-
except Exception:
|
65
|
-
return str(val)
|
66
|
-
|
67
|
-
|
68
|
-
def _build_model_row(m, headers, num_fields):
|
69
|
-
def format_driver(val):
|
70
|
-
if isinstance(val, (list, tuple)):
|
71
|
-
return ", ".join(val)
|
72
|
-
val_str = str(val)
|
73
|
-
return val_str.removesuffix("ModelDriver").strip()
|
74
|
-
|
75
|
-
row = []
|
76
|
-
for h in headers[1:]:
|
77
|
-
v = m.get(h, "")
|
78
|
-
if h in num_fields and v not in ("", "N/A"):
|
79
|
-
if (
|
80
|
-
h in ("context", "max_input")
|
81
|
-
and isinstance(v, (list, tuple))
|
82
|
-
and len(v) == 2
|
83
|
-
):
|
84
|
-
row.append(f"{_format_k(v[0])} / {_format_k(v[1])}")
|
85
|
-
else:
|
86
|
-
row.append(_format_k(v))
|
87
|
-
elif h == "open":
|
88
|
-
row.append("Open" if v is True or v == "Open" else "Locked")
|
89
|
-
elif h == "thinking_supported":
|
90
|
-
row.append("📖" if v is True or v == "True" else "")
|
91
|
-
elif h == "driver":
|
92
|
-
row.append(format_driver(v))
|
93
|
-
else:
|
94
|
-
row.append(str(v))
|
95
|
-
return row
|
1
|
+
"""
|
2
|
+
Utilities for model-related CLI output
|
3
|
+
"""
|
4
|
+
|
5
|
+
|
6
|
+
def _print_models_table(models, provider_name):
|
7
|
+
from rich.table import Table
|
8
|
+
from rich.console import Console
|
9
|
+
|
10
|
+
headers = [
|
11
|
+
"name",
|
12
|
+
"open",
|
13
|
+
"context",
|
14
|
+
"max_input",
|
15
|
+
"max_cot",
|
16
|
+
"max_response",
|
17
|
+
"thinking_supported",
|
18
|
+
"driver",
|
19
|
+
]
|
20
|
+
display_headers = [
|
21
|
+
"Model Name",
|
22
|
+
"Vendor",
|
23
|
+
"context",
|
24
|
+
"max_input",
|
25
|
+
"max_cot",
|
26
|
+
"max_response",
|
27
|
+
"Thinking",
|
28
|
+
"Driver",
|
29
|
+
]
|
30
|
+
table = Table(title=f"Supported models for provider '{provider_name}'")
|
31
|
+
_add_table_columns(table, display_headers)
|
32
|
+
num_fields = {"context", "max_input", "max_cot", "max_response"}
|
33
|
+
for m in models:
|
34
|
+
row = [str(m.get("name", ""))]
|
35
|
+
row.extend(_build_model_row(m, headers, num_fields))
|
36
|
+
table.add_row(*row)
|
37
|
+
import sys
|
38
|
+
if sys.stdout.isatty():
|
39
|
+
from rich.console import Console
|
40
|
+
Console().print(table)
|
41
|
+
else:
|
42
|
+
# ASCII-friendly fallback table when output is redirected
|
43
|
+
print(f"Supported models for provider '{provider_name}'")
|
44
|
+
headers_fallback = [h for h in display_headers]
|
45
|
+
print(' | '.join(headers_fallback))
|
46
|
+
for m in models:
|
47
|
+
row = [str(m.get('name', ''))]
|
48
|
+
row.extend(_build_model_row(m, headers, num_fields))
|
49
|
+
print(' | '.join(row))
|
50
|
+
|
51
|
+
|
52
|
+
def _add_table_columns(table, display_headers):
|
53
|
+
for i, h in enumerate(display_headers):
|
54
|
+
justify = "right" if i == 0 else "center"
|
55
|
+
table.add_column(h, style="bold", justify=justify)
|
56
|
+
|
57
|
+
|
58
|
+
def _format_k(val):
|
59
|
+
try:
|
60
|
+
n = int(val)
|
61
|
+
if n >= 1000:
|
62
|
+
return f"{n // 1000}k"
|
63
|
+
return str(n)
|
64
|
+
except Exception:
|
65
|
+
return str(val)
|
66
|
+
|
67
|
+
|
68
|
+
def _build_model_row(m, headers, num_fields):
|
69
|
+
def format_driver(val):
|
70
|
+
if isinstance(val, (list, tuple)):
|
71
|
+
return ", ".join(val)
|
72
|
+
val_str = str(val)
|
73
|
+
return val_str.removesuffix("ModelDriver").strip()
|
74
|
+
|
75
|
+
row = []
|
76
|
+
for h in headers[1:]:
|
77
|
+
v = m.get(h, "")
|
78
|
+
if h in num_fields and v not in ("", "N/A"):
|
79
|
+
if (
|
80
|
+
h in ("context", "max_input")
|
81
|
+
and isinstance(v, (list, tuple))
|
82
|
+
and len(v) == 2
|
83
|
+
):
|
84
|
+
row.append(f"{_format_k(v[0])} / {_format_k(v[1])}")
|
85
|
+
else:
|
86
|
+
row.append(_format_k(v))
|
87
|
+
elif h == "open":
|
88
|
+
row.append("Open" if v is True or v == "Open" else "Locked")
|
89
|
+
elif h == "thinking_supported":
|
90
|
+
row.append("📖" if v is True or v == "True" else "")
|
91
|
+
elif h == "driver":
|
92
|
+
row.append(format_driver(v))
|
93
|
+
else:
|
94
|
+
row.append(str(v))
|
95
|
+
return row
|
@@ -1,19 +1,19 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: Set API key for the current or selected provider
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.provider_config import set_api_key
|
6
|
-
from janito.llm.auth import LLMAuthManager
|
7
|
-
|
8
|
-
|
9
|
-
def handle_set_api_key(args):
|
10
|
-
api_key = getattr(args, "set_api_key", None)
|
11
|
-
provider = getattr(args, "provider", None)
|
12
|
-
if not provider:
|
13
|
-
print("Error: --set-api-key requires -p/--provider to be specified.")
|
14
|
-
return
|
15
|
-
set_api_key(provider, api_key)
|
16
|
-
auth_manager = LLMAuthManager()
|
17
|
-
print(
|
18
|
-
f"API key set for provider '{provider}'. Auth file updated: {auth_manager._auth_file}"
|
19
|
-
)
|
1
|
+
"""
|
2
|
+
CLI Command: Set API key for the current or selected provider
|
3
|
+
"""
|
4
|
+
|
5
|
+
from janito.provider_config import set_api_key
|
6
|
+
from janito.llm.auth import LLMAuthManager
|
7
|
+
|
8
|
+
|
9
|
+
def handle_set_api_key(args):
|
10
|
+
api_key = getattr(args, "set_api_key", None)
|
11
|
+
provider = getattr(args, "provider", None)
|
12
|
+
if not provider:
|
13
|
+
print("Error: --set-api-key requires -p/--provider to be specified.")
|
14
|
+
return
|
15
|
+
set_api_key(provider, api_key)
|
16
|
+
auth_manager = LLMAuthManager()
|
17
|
+
print(
|
18
|
+
f"API key set for provider '{provider}'. Auth file updated: {auth_manager._auth_file}"
|
19
|
+
)
|
@@ -1,51 +1,51 @@
|
|
1
|
-
from rich.console import Console
|
2
|
-
from rich.pretty import Pretty
|
3
|
-
|
4
|
-
from janito.config import config
|
5
|
-
from janito.cli.config import CONFIG_OPTIONS
|
6
|
-
|
7
|
-
|
8
|
-
def resolve_effective_model(provider_name):
|
9
|
-
# Try provider-specific model, then global model, then provider default
|
10
|
-
provider_cfg = config.get_provider_config(provider_name)
|
11
|
-
model = provider_cfg.get("model") if provider_cfg else None
|
12
|
-
if not model:
|
13
|
-
model = config.get("model")
|
14
|
-
if not model:
|
15
|
-
try:
|
16
|
-
from janito.provider_registry import ProviderRegistry
|
17
|
-
|
18
|
-
provider_class = ProviderRegistry().get_provider(provider_name)
|
19
|
-
model = getattr(provider_class, "DEFAULT_MODEL", None)
|
20
|
-
except Exception:
|
21
|
-
model = None
|
22
|
-
return model
|
23
|
-
|
24
|
-
|
25
|
-
def handle_show_config(args):
|
26
|
-
console = Console()
|
27
|
-
provider = config.get("provider")
|
28
|
-
model = config.get("model")
|
29
|
-
# Show all providers with their effective model
|
30
|
-
from janito.provider_registry import ProviderRegistry
|
31
|
-
|
32
|
-
provider_names = []
|
33
|
-
try:
|
34
|
-
provider_names = ProviderRegistry()._get_provider_names()
|
35
|
-
except Exception:
|
36
|
-
pass
|
37
|
-
console.print("[bold green]Current configuration:[/bold green]")
|
38
|
-
console.print(f"[bold yellow]Current provider:[/bold yellow] {provider!r}\n")
|
39
|
-
if model is not None:
|
40
|
-
console.print(f"[bold yellow]Global model:[/bold yellow] {model!r}\n")
|
41
|
-
if provider_names:
|
42
|
-
console.print("[bold cyan]Provider specific default models:[/bold cyan]")
|
43
|
-
for pname in provider_names:
|
44
|
-
eff_model = resolve_effective_model(pname)
|
45
|
-
prov_cfg = config.get_provider_config(pname)
|
46
|
-
prov_model = prov_cfg.get("model") if prov_cfg else None
|
47
|
-
extra = f" (override)" if prov_model else ""
|
48
|
-
sel = "[default]" if pname == provider else ""
|
49
|
-
console.print(
|
50
|
-
f" [bold]{pname}[/bold]{' '+sel if sel else ''}: model = [magenta]{eff_model}[/magenta]{extra}"
|
51
|
-
)
|
1
|
+
from rich.console import Console
|
2
|
+
from rich.pretty import Pretty
|
3
|
+
|
4
|
+
from janito.config import config
|
5
|
+
from janito.cli.config import CONFIG_OPTIONS
|
6
|
+
|
7
|
+
|
8
|
+
def resolve_effective_model(provider_name):
|
9
|
+
# Try provider-specific model, then global model, then provider default
|
10
|
+
provider_cfg = config.get_provider_config(provider_name)
|
11
|
+
model = provider_cfg.get("model") if provider_cfg else None
|
12
|
+
if not model:
|
13
|
+
model = config.get("model")
|
14
|
+
if not model:
|
15
|
+
try:
|
16
|
+
from janito.provider_registry import ProviderRegistry
|
17
|
+
|
18
|
+
provider_class = ProviderRegistry().get_provider(provider_name)
|
19
|
+
model = getattr(provider_class, "DEFAULT_MODEL", None)
|
20
|
+
except Exception:
|
21
|
+
model = None
|
22
|
+
return model
|
23
|
+
|
24
|
+
|
25
|
+
def handle_show_config(args):
|
26
|
+
console = Console()
|
27
|
+
provider = config.get("provider")
|
28
|
+
model = config.get("model")
|
29
|
+
# Show all providers with their effective model
|
30
|
+
from janito.provider_registry import ProviderRegistry
|
31
|
+
|
32
|
+
provider_names = []
|
33
|
+
try:
|
34
|
+
provider_names = ProviderRegistry()._get_provider_names()
|
35
|
+
except Exception:
|
36
|
+
pass
|
37
|
+
console.print("[bold green]Current configuration:[/bold green]")
|
38
|
+
console.print(f"[bold yellow]Current provider:[/bold yellow] {provider!r}\n")
|
39
|
+
if model is not None:
|
40
|
+
console.print(f"[bold yellow]Global model:[/bold yellow] {model!r}\n")
|
41
|
+
if provider_names:
|
42
|
+
console.print("[bold cyan]Provider specific default models:[/bold cyan]")
|
43
|
+
for pname in provider_names:
|
44
|
+
eff_model = resolve_effective_model(pname)
|
45
|
+
prov_cfg = config.get_provider_config(pname)
|
46
|
+
prov_model = prov_cfg.get("model") if prov_cfg else None
|
47
|
+
extra = f" (override)" if prov_model else ""
|
48
|
+
sel = "[default]" if pname == provider else ""
|
49
|
+
console.print(
|
50
|
+
f" [bold]{pname}[/bold]{' '+sel if sel else ''}: model = [magenta]{eff_model}[/magenta]{extra}"
|
51
|
+
)
|
@@ -1,62 +1,62 @@
|
|
1
|
-
"""
|
2
|
-
CLI Command: Show the resolved system prompt for the main agent (single-shot mode)
|
3
|
-
"""
|
4
|
-
|
5
|
-
from janito.cli.core.runner import prepare_llm_driver_config
|
6
|
-
from janito.platform_discovery import PlatformDiscovery
|
7
|
-
from pathlib import Path
|
8
|
-
from jinja2 import Template
|
9
|
-
import importlib.resources
|
10
|
-
|
11
|
-
|
12
|
-
def handle_show_system_prompt(args):
|
13
|
-
# Collect modifiers as in JanitoCLI
|
14
|
-
from janito.cli.main_cli import MODIFIER_KEYS
|
15
|
-
|
16
|
-
modifiers = {
|
17
|
-
k: getattr(args, k) for k in MODIFIER_KEYS if getattr(args, k, None) is not None
|
18
|
-
}
|
19
|
-
provider, llm_driver_config, agent_role = prepare_llm_driver_config(args, modifiers)
|
20
|
-
if provider is None or llm_driver_config is None:
|
21
|
-
print("Error: Could not resolve provider or LLM driver config.")
|
22
|
-
return
|
23
|
-
|
24
|
-
# Prepare context for Jinja2 rendering
|
25
|
-
context = {}
|
26
|
-
context["role"] = agent_role or "software developer"
|
27
|
-
pd = PlatformDiscovery()
|
28
|
-
context["platform"] = pd.get_platform_name()
|
29
|
-
context["python_version"] = pd.get_python_version()
|
30
|
-
context["shell_info"] = pd.detect_shell()
|
31
|
-
|
32
|
-
# Locate and load the system prompt template
|
33
|
-
templates_dir = (
|
34
|
-
Path(__file__).parent.parent.parent / "agent" / "templates" / "profiles"
|
35
|
-
)
|
36
|
-
template_path = templates_dir / "system_prompt_template_main.txt.j2"
|
37
|
-
template_content = None
|
38
|
-
if template_path.exists():
|
39
|
-
with open(template_path, "r", encoding="utf-8") as file:
|
40
|
-
template_content = file.read()
|
41
|
-
else:
|
42
|
-
# Try package import fallback
|
43
|
-
try:
|
44
|
-
with importlib.resources.files("janito.agent.templates.profiles").joinpath(
|
45
|
-
"system_prompt_template_main.txt.j2"
|
46
|
-
).open("r", encoding="utf-8") as file:
|
47
|
-
template_content = file.read()
|
48
|
-
except (FileNotFoundError, ModuleNotFoundError, AttributeError):
|
49
|
-
print(
|
50
|
-
f"[janito] Could not find system_prompt_template_main.txt.j2 in {template_path} nor in janito.agent.templates.profiles package."
|
51
|
-
)
|
52
|
-
print("No system prompt is set or resolved for this configuration.")
|
53
|
-
return
|
54
|
-
|
55
|
-
template = Template(template_content)
|
56
|
-
system_prompt = template.render(**context)
|
57
|
-
|
58
|
-
print("\n--- System Prompt (resolved) ---\n")
|
59
|
-
print(system_prompt)
|
60
|
-
print("\n-------------------------------\n")
|
61
|
-
if agent_role:
|
62
|
-
print(f"[Role: {agent_role}]")
|
1
|
+
"""
|
2
|
+
CLI Command: Show the resolved system prompt for the main agent (single-shot mode)
|
3
|
+
"""
|
4
|
+
|
5
|
+
from janito.cli.core.runner import prepare_llm_driver_config
|
6
|
+
from janito.platform_discovery import PlatformDiscovery
|
7
|
+
from pathlib import Path
|
8
|
+
from jinja2 import Template
|
9
|
+
import importlib.resources
|
10
|
+
|
11
|
+
|
12
|
+
def handle_show_system_prompt(args):
|
13
|
+
# Collect modifiers as in JanitoCLI
|
14
|
+
from janito.cli.main_cli import MODIFIER_KEYS
|
15
|
+
|
16
|
+
modifiers = {
|
17
|
+
k: getattr(args, k) for k in MODIFIER_KEYS if getattr(args, k, None) is not None
|
18
|
+
}
|
19
|
+
provider, llm_driver_config, agent_role = prepare_llm_driver_config(args, modifiers)
|
20
|
+
if provider is None or llm_driver_config is None:
|
21
|
+
print("Error: Could not resolve provider or LLM driver config.")
|
22
|
+
return
|
23
|
+
|
24
|
+
# Prepare context for Jinja2 rendering
|
25
|
+
context = {}
|
26
|
+
context["role"] = agent_role or "software developer"
|
27
|
+
pd = PlatformDiscovery()
|
28
|
+
context["platform"] = pd.get_platform_name()
|
29
|
+
context["python_version"] = pd.get_python_version()
|
30
|
+
context["shell_info"] = pd.detect_shell()
|
31
|
+
|
32
|
+
# Locate and load the system prompt template
|
33
|
+
templates_dir = (
|
34
|
+
Path(__file__).parent.parent.parent / "agent" / "templates" / "profiles"
|
35
|
+
)
|
36
|
+
template_path = templates_dir / "system_prompt_template_main.txt.j2"
|
37
|
+
template_content = None
|
38
|
+
if template_path.exists():
|
39
|
+
with open(template_path, "r", encoding="utf-8") as file:
|
40
|
+
template_content = file.read()
|
41
|
+
else:
|
42
|
+
# Try package import fallback
|
43
|
+
try:
|
44
|
+
with importlib.resources.files("janito.agent.templates.profiles").joinpath(
|
45
|
+
"system_prompt_template_main.txt.j2"
|
46
|
+
).open("r", encoding="utf-8") as file:
|
47
|
+
template_content = file.read()
|
48
|
+
except (FileNotFoundError, ModuleNotFoundError, AttributeError):
|
49
|
+
print(
|
50
|
+
f"[janito] Could not find system_prompt_template_main.txt.j2 in {template_path} nor in janito.agent.templates.profiles package."
|
51
|
+
)
|
52
|
+
print("No system prompt is set or resolved for this configuration.")
|
53
|
+
return
|
54
|
+
|
55
|
+
template = Template(template_content)
|
56
|
+
system_prompt = template.render(**context)
|
57
|
+
|
58
|
+
print("\n--- System Prompt (resolved) ---\n")
|
59
|
+
print(system_prompt)
|
60
|
+
print("\n-------------------------------\n")
|
61
|
+
if agent_role:
|
62
|
+
print(f"[Role: {agent_role}]")
|
janito/cli/core/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
2
|
-
Core logic, handler classes, and utilities for the main Janito CLI orchestration and sub-command processing.
|
3
|
-
Contains modules for setters, getters, event logger, and runner pipelines.
|
4
|
-
"""
|
1
|
+
"""
|
2
|
+
Core logic, handler classes, and utilities for the main Janito CLI orchestration and sub-command processing.
|
3
|
+
Contains modules for setters, getters, event logger, and runner pipelines.
|
4
|
+
"""
|
janito/cli/core/event_logger.py
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
"""Stub implementation of EventLogger for the CLI event logging system."""
|
2
|
-
|
3
|
-
|
4
|
-
class EventLogger:
|
5
|
-
def __init__(self, debug=False):
|
6
|
-
self.debug = debug
|
7
|
-
|
8
|
-
def subscribe(self, event_name, callback):
|
9
|
-
if self.debug:
|
10
|
-
pass # Add debug subscribe output if needed
|
11
|
-
# No real subscription logic
|
12
|
-
|
13
|
-
def submit(self, event_name, payload=None):
|
14
|
-
if self.debug:
|
15
|
-
pass # Add debug submit output if needed
|
16
|
-
# No real submission logic
|
17
|
-
|
18
|
-
|
19
|
-
def setup_event_logger(args):
|
20
|
-
debug = getattr(args, "event_debug", False)
|
21
|
-
event_logger = EventLogger(debug=debug)
|
22
|
-
print("[EventLog] Event logger is now active (stub implementation)")
|
23
|
-
return event_logger
|
24
|
-
|
25
|
-
|
26
|
-
def setup_event_logger_if_needed(args):
|
27
|
-
if getattr(args, "event_log", False):
|
28
|
-
print("[EventLog] Setting up event logger with system bus...")
|
29
|
-
event_logger = setup_event_logger(args)
|
30
|
-
from janito.event_bus import event_bus
|
31
|
-
|
32
|
-
def event_logger_handler(event):
|
33
|
-
from janito.cli.console import shared_console
|
34
|
-
from rich.pretty import Pretty
|
35
|
-
from datetime import datetime
|
36
|
-
|
37
|
-
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
38
|
-
shared_console.print(
|
39
|
-
f"[EventLog] [dim]{timestamp}[/] [bold green]{event.__class__.__name__}[/] | [cyan]{getattr(event, 'category', '')}[/]"
|
40
|
-
)
|
41
|
-
shared_console.print(Pretty(event, expand_all=True))
|
42
|
-
shared_console.file.flush()
|
43
|
-
|
44
|
-
from janito.event_bus.event import Event
|
45
|
-
|
46
|
-
event_bus.subscribe(Event, event_logger_handler)
|
47
|
-
|
48
|
-
|
49
|
-
def inject_debug_event_bus_if_needed(args):
|
50
|
-
if getattr(args, "event_debug", False):
|
51
|
-
from janito.event_bus import event_bus
|
52
|
-
|
53
|
-
orig_publish = event_bus.publish
|
54
|
-
|
55
|
-
def debug_publish(event):
|
56
|
-
# You can enrich here if needed
|
57
|
-
return orig_publish(event)
|
58
|
-
|
59
|
-
event_bus.publish = debug_publish
|
1
|
+
"""Stub implementation of EventLogger for the CLI event logging system."""
|
2
|
+
|
3
|
+
|
4
|
+
class EventLogger:
|
5
|
+
def __init__(self, debug=False):
|
6
|
+
self.debug = debug
|
7
|
+
|
8
|
+
def subscribe(self, event_name, callback):
|
9
|
+
if self.debug:
|
10
|
+
pass # Add debug subscribe output if needed
|
11
|
+
# No real subscription logic
|
12
|
+
|
13
|
+
def submit(self, event_name, payload=None):
|
14
|
+
if self.debug:
|
15
|
+
pass # Add debug submit output if needed
|
16
|
+
# No real submission logic
|
17
|
+
|
18
|
+
|
19
|
+
def setup_event_logger(args):
|
20
|
+
debug = getattr(args, "event_debug", False)
|
21
|
+
event_logger = EventLogger(debug=debug)
|
22
|
+
print("[EventLog] Event logger is now active (stub implementation)")
|
23
|
+
return event_logger
|
24
|
+
|
25
|
+
|
26
|
+
def setup_event_logger_if_needed(args):
|
27
|
+
if getattr(args, "event_log", False):
|
28
|
+
print("[EventLog] Setting up event logger with system bus...")
|
29
|
+
event_logger = setup_event_logger(args)
|
30
|
+
from janito.event_bus import event_bus
|
31
|
+
|
32
|
+
def event_logger_handler(event):
|
33
|
+
from janito.cli.console import shared_console
|
34
|
+
from rich.pretty import Pretty
|
35
|
+
from datetime import datetime
|
36
|
+
|
37
|
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
38
|
+
shared_console.print(
|
39
|
+
f"[EventLog] [dim]{timestamp}[/] [bold green]{event.__class__.__name__}[/] | [cyan]{getattr(event, 'category', '')}[/]"
|
40
|
+
)
|
41
|
+
shared_console.print(Pretty(event, expand_all=True))
|
42
|
+
shared_console.file.flush()
|
43
|
+
|
44
|
+
from janito.event_bus.event import Event
|
45
|
+
|
46
|
+
event_bus.subscribe(Event, event_logger_handler)
|
47
|
+
|
48
|
+
|
49
|
+
def inject_debug_event_bus_if_needed(args):
|
50
|
+
if getattr(args, "event_debug", False):
|
51
|
+
from janito.event_bus import event_bus
|
52
|
+
|
53
|
+
orig_publish = event_bus.publish
|
54
|
+
|
55
|
+
def debug_publish(event):
|
56
|
+
# You can enrich here if needed
|
57
|
+
return orig_publish(event)
|
58
|
+
|
59
|
+
event_bus.publish = debug_publish
|
janito/cli/core/getters.py
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
"""Handlers for get-type CLI commands (show_config, list_providers, models, tools)."""
|
2
|
-
import sys
|
3
|
-
|
4
|
-
from janito.cli.cli_commands.list_providers import handle_list_providers
|
5
|
-
from janito.cli.cli_commands.list_models import handle_list_models
|
6
|
-
from janito.cli.cli_commands.list_tools import handle_list_tools
|
7
|
-
from janito.cli.cli_commands.show_config import handle_show_config
|
8
|
-
from functools import partial
|
9
|
-
from janito.provider_registry import ProviderRegistry
|
10
|
-
|
11
|
-
GETTER_KEYS = ["show_config", "list_providers", "list_models", "list_tools"]
|
12
|
-
|
13
|
-
|
14
|
-
def handle_getter(args, config_mgr=None):
|
15
|
-
provider_instance = None
|
16
|
-
if getattr(args, "list_models", False):
|
17
|
-
provider = getattr(args, "provider", None)
|
18
|
-
if not provider:
|
19
|
-
import sys
|
20
|
-
print(
|
21
|
-
"Error: No provider selected. Please set a provider using '-p PROVIDER', '--set provider=name', or configure a provider."
|
22
|
-
)
|
23
|
-
sys.exit(1)
|
24
|
-
provider_instance = ProviderRegistry().get_instance(provider)
|
25
|
-
GETTER_DISPATCH = {
|
26
|
-
"list_providers": partial(handle_list_providers, args),
|
27
|
-
"list_models": partial(handle_list_models, args, provider_instance),
|
28
|
-
"list_tools": partial(handle_list_tools, args),
|
29
|
-
"show_config": partial(handle_show_config, args),
|
30
|
-
}
|
31
|
-
for arg in GETTER_KEYS:
|
32
|
-
if getattr(args, arg, False) and arg in GETTER_DISPATCH:
|
33
|
-
return GETTER_DISPATCH[arg]()
|
1
|
+
"""Handlers for get-type CLI commands (show_config, list_providers, models, tools)."""
|
2
|
+
import sys
|
3
|
+
|
4
|
+
from janito.cli.cli_commands.list_providers import handle_list_providers
|
5
|
+
from janito.cli.cli_commands.list_models import handle_list_models
|
6
|
+
from janito.cli.cli_commands.list_tools import handle_list_tools
|
7
|
+
from janito.cli.cli_commands.show_config import handle_show_config
|
8
|
+
from functools import partial
|
9
|
+
from janito.provider_registry import ProviderRegistry
|
10
|
+
|
11
|
+
GETTER_KEYS = ["show_config", "list_providers", "list_models", "list_tools"]
|
12
|
+
|
13
|
+
|
14
|
+
def handle_getter(args, config_mgr=None):
|
15
|
+
provider_instance = None
|
16
|
+
if getattr(args, "list_models", False):
|
17
|
+
provider = getattr(args, "provider", None)
|
18
|
+
if not provider:
|
19
|
+
import sys
|
20
|
+
print(
|
21
|
+
"Error: No provider selected. Please set a provider using '-p PROVIDER', '--set provider=name', or configure a provider."
|
22
|
+
)
|
23
|
+
sys.exit(1)
|
24
|
+
provider_instance = ProviderRegistry().get_instance(provider)
|
25
|
+
GETTER_DISPATCH = {
|
26
|
+
"list_providers": partial(handle_list_providers, args),
|
27
|
+
"list_models": partial(handle_list_models, args, provider_instance),
|
28
|
+
"list_tools": partial(handle_list_tools, args),
|
29
|
+
"show_config": partial(handle_show_config, args),
|
30
|
+
}
|
31
|
+
for arg in GETTER_KEYS:
|
32
|
+
if getattr(args, arg, False) and arg in GETTER_DISPATCH:
|
33
|
+
return GETTER_DISPATCH[arg]()
|