strix-agent 0.4.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.
- strix/__init__.py +0 -0
- strix/agents/StrixAgent/__init__.py +4 -0
- strix/agents/StrixAgent/strix_agent.py +89 -0
- strix/agents/StrixAgent/system_prompt.jinja +404 -0
- strix/agents/__init__.py +10 -0
- strix/agents/base_agent.py +518 -0
- strix/agents/state.py +163 -0
- strix/interface/__init__.py +4 -0
- strix/interface/assets/tui_styles.tcss +694 -0
- strix/interface/cli.py +230 -0
- strix/interface/main.py +500 -0
- strix/interface/tool_components/__init__.py +39 -0
- strix/interface/tool_components/agents_graph_renderer.py +123 -0
- strix/interface/tool_components/base_renderer.py +62 -0
- strix/interface/tool_components/browser_renderer.py +120 -0
- strix/interface/tool_components/file_edit_renderer.py +99 -0
- strix/interface/tool_components/finish_renderer.py +31 -0
- strix/interface/tool_components/notes_renderer.py +108 -0
- strix/interface/tool_components/proxy_renderer.py +255 -0
- strix/interface/tool_components/python_renderer.py +34 -0
- strix/interface/tool_components/registry.py +72 -0
- strix/interface/tool_components/reporting_renderer.py +53 -0
- strix/interface/tool_components/scan_info_renderer.py +64 -0
- strix/interface/tool_components/terminal_renderer.py +131 -0
- strix/interface/tool_components/thinking_renderer.py +29 -0
- strix/interface/tool_components/user_message_renderer.py +43 -0
- strix/interface/tool_components/web_search_renderer.py +28 -0
- strix/interface/tui.py +1274 -0
- strix/interface/utils.py +559 -0
- strix/llm/__init__.py +15 -0
- strix/llm/config.py +20 -0
- strix/llm/llm.py +465 -0
- strix/llm/memory_compressor.py +212 -0
- strix/llm/request_queue.py +87 -0
- strix/llm/utils.py +87 -0
- strix/prompts/README.md +64 -0
- strix/prompts/__init__.py +109 -0
- strix/prompts/cloud/.gitkeep +0 -0
- strix/prompts/coordination/root_agent.jinja +41 -0
- strix/prompts/custom/.gitkeep +0 -0
- strix/prompts/frameworks/fastapi.jinja +142 -0
- strix/prompts/frameworks/nextjs.jinja +126 -0
- strix/prompts/protocols/graphql.jinja +215 -0
- strix/prompts/reconnaissance/.gitkeep +0 -0
- strix/prompts/technologies/firebase_firestore.jinja +177 -0
- strix/prompts/technologies/supabase.jinja +189 -0
- strix/prompts/vulnerabilities/authentication_jwt.jinja +147 -0
- strix/prompts/vulnerabilities/broken_function_level_authorization.jinja +146 -0
- strix/prompts/vulnerabilities/business_logic.jinja +171 -0
- strix/prompts/vulnerabilities/csrf.jinja +174 -0
- strix/prompts/vulnerabilities/idor.jinja +195 -0
- strix/prompts/vulnerabilities/information_disclosure.jinja +222 -0
- strix/prompts/vulnerabilities/insecure_file_uploads.jinja +188 -0
- strix/prompts/vulnerabilities/mass_assignment.jinja +141 -0
- strix/prompts/vulnerabilities/open_redirect.jinja +177 -0
- strix/prompts/vulnerabilities/path_traversal_lfi_rfi.jinja +142 -0
- strix/prompts/vulnerabilities/race_conditions.jinja +164 -0
- strix/prompts/vulnerabilities/rce.jinja +154 -0
- strix/prompts/vulnerabilities/sql_injection.jinja +151 -0
- strix/prompts/vulnerabilities/ssrf.jinja +135 -0
- strix/prompts/vulnerabilities/subdomain_takeover.jinja +155 -0
- strix/prompts/vulnerabilities/xss.jinja +169 -0
- strix/prompts/vulnerabilities/xxe.jinja +184 -0
- strix/runtime/__init__.py +19 -0
- strix/runtime/docker_runtime.py +399 -0
- strix/runtime/runtime.py +29 -0
- strix/runtime/tool_server.py +205 -0
- strix/telemetry/__init__.py +4 -0
- strix/telemetry/tracer.py +337 -0
- strix/tools/__init__.py +64 -0
- strix/tools/agents_graph/__init__.py +16 -0
- strix/tools/agents_graph/agents_graph_actions.py +621 -0
- strix/tools/agents_graph/agents_graph_actions_schema.xml +226 -0
- strix/tools/argument_parser.py +121 -0
- strix/tools/browser/__init__.py +4 -0
- strix/tools/browser/browser_actions.py +236 -0
- strix/tools/browser/browser_actions_schema.xml +183 -0
- strix/tools/browser/browser_instance.py +533 -0
- strix/tools/browser/tab_manager.py +342 -0
- strix/tools/executor.py +305 -0
- strix/tools/file_edit/__init__.py +4 -0
- strix/tools/file_edit/file_edit_actions.py +141 -0
- strix/tools/file_edit/file_edit_actions_schema.xml +128 -0
- strix/tools/finish/__init__.py +4 -0
- strix/tools/finish/finish_actions.py +174 -0
- strix/tools/finish/finish_actions_schema.xml +45 -0
- strix/tools/notes/__init__.py +14 -0
- strix/tools/notes/notes_actions.py +191 -0
- strix/tools/notes/notes_actions_schema.xml +150 -0
- strix/tools/proxy/__init__.py +20 -0
- strix/tools/proxy/proxy_actions.py +101 -0
- strix/tools/proxy/proxy_actions_schema.xml +267 -0
- strix/tools/proxy/proxy_manager.py +785 -0
- strix/tools/python/__init__.py +4 -0
- strix/tools/python/python_actions.py +47 -0
- strix/tools/python/python_actions_schema.xml +131 -0
- strix/tools/python/python_instance.py +172 -0
- strix/tools/python/python_manager.py +131 -0
- strix/tools/registry.py +196 -0
- strix/tools/reporting/__init__.py +6 -0
- strix/tools/reporting/reporting_actions.py +63 -0
- strix/tools/reporting/reporting_actions_schema.xml +30 -0
- strix/tools/terminal/__init__.py +4 -0
- strix/tools/terminal/terminal_actions.py +35 -0
- strix/tools/terminal/terminal_actions_schema.xml +146 -0
- strix/tools/terminal/terminal_manager.py +151 -0
- strix/tools/terminal/terminal_session.py +447 -0
- strix/tools/thinking/__init__.py +4 -0
- strix/tools/thinking/thinking_actions.py +18 -0
- strix/tools/thinking/thinking_actions_schema.xml +52 -0
- strix/tools/web_search/__init__.py +4 -0
- strix/tools/web_search/web_search_actions.py +80 -0
- strix/tools/web_search/web_search_actions_schema.xml +83 -0
- strix_agent-0.4.0.dist-info/LICENSE +201 -0
- strix_agent-0.4.0.dist-info/METADATA +282 -0
- strix_agent-0.4.0.dist-info/RECORD +118 -0
- strix_agent-0.4.0.dist-info/WHEEL +4 -0
- strix_agent-0.4.0.dist-info/entry_points.txt +3 -0
strix/interface/utils.py
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
import ipaddress
|
|
2
|
+
import re
|
|
3
|
+
import secrets
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import urlparse
|
|
11
|
+
|
|
12
|
+
import docker
|
|
13
|
+
from docker.errors import DockerException, ImageNotFound
|
|
14
|
+
from rich.console import Console
|
|
15
|
+
from rich.panel import Panel
|
|
16
|
+
from rich.text import Text
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Token formatting utilities
|
|
20
|
+
def format_token_count(count: float) -> str:
|
|
21
|
+
count = int(count)
|
|
22
|
+
if count >= 1_000_000:
|
|
23
|
+
return f"{count / 1_000_000:.1f}M"
|
|
24
|
+
if count >= 1_000:
|
|
25
|
+
return f"{count / 1_000:.1f}K"
|
|
26
|
+
return str(count)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Display utilities
|
|
30
|
+
def get_severity_color(severity: str) -> str:
|
|
31
|
+
severity_colors = {
|
|
32
|
+
"critical": "#dc2626",
|
|
33
|
+
"high": "#ea580c",
|
|
34
|
+
"medium": "#d97706",
|
|
35
|
+
"low": "#65a30d",
|
|
36
|
+
"info": "#0284c7",
|
|
37
|
+
}
|
|
38
|
+
return severity_colors.get(severity, "#6b7280")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _build_vulnerability_stats(stats_text: Text, tracer: Any) -> None:
|
|
42
|
+
"""Build vulnerability section of stats text."""
|
|
43
|
+
vuln_count = len(tracer.vulnerability_reports)
|
|
44
|
+
|
|
45
|
+
if vuln_count > 0:
|
|
46
|
+
severity_counts = {"critical": 0, "high": 0, "medium": 0, "low": 0, "info": 0}
|
|
47
|
+
for report in tracer.vulnerability_reports:
|
|
48
|
+
severity = report.get("severity", "").lower()
|
|
49
|
+
if severity in severity_counts:
|
|
50
|
+
severity_counts[severity] += 1
|
|
51
|
+
|
|
52
|
+
stats_text.append("🔍 Vulnerabilities Found: ", style="bold red")
|
|
53
|
+
|
|
54
|
+
severity_parts = []
|
|
55
|
+
for severity in ["critical", "high", "medium", "low", "info"]:
|
|
56
|
+
count = severity_counts[severity]
|
|
57
|
+
if count > 0:
|
|
58
|
+
severity_color = get_severity_color(severity)
|
|
59
|
+
severity_text = Text()
|
|
60
|
+
severity_text.append(f"{severity.upper()}: ", style=severity_color)
|
|
61
|
+
severity_text.append(str(count), style=f"bold {severity_color}")
|
|
62
|
+
severity_parts.append(severity_text)
|
|
63
|
+
|
|
64
|
+
for i, part in enumerate(severity_parts):
|
|
65
|
+
stats_text.append(part)
|
|
66
|
+
if i < len(severity_parts) - 1:
|
|
67
|
+
stats_text.append(" | ", style="dim white")
|
|
68
|
+
|
|
69
|
+
stats_text.append(" (Total: ", style="dim white")
|
|
70
|
+
stats_text.append(str(vuln_count), style="bold yellow")
|
|
71
|
+
stats_text.append(")", style="dim white")
|
|
72
|
+
stats_text.append("\n")
|
|
73
|
+
else:
|
|
74
|
+
stats_text.append("🔍 Vulnerabilities Found: ", style="bold green")
|
|
75
|
+
stats_text.append("0", style="bold white")
|
|
76
|
+
stats_text.append(" (No exploitable vulnerabilities detected)", style="dim green")
|
|
77
|
+
stats_text.append("\n")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _build_llm_stats(stats_text: Text, total_stats: dict[str, Any]) -> None:
|
|
81
|
+
"""Build LLM usage section of stats text."""
|
|
82
|
+
if total_stats["requests"] > 0:
|
|
83
|
+
stats_text.append("\n")
|
|
84
|
+
stats_text.append("📥 Input Tokens: ", style="bold cyan")
|
|
85
|
+
stats_text.append(format_token_count(total_stats["input_tokens"]), style="bold white")
|
|
86
|
+
|
|
87
|
+
if total_stats["cached_tokens"] > 0:
|
|
88
|
+
stats_text.append(" • ", style="dim white")
|
|
89
|
+
stats_text.append("⚡ Cached Tokens: ", style="bold green")
|
|
90
|
+
stats_text.append(format_token_count(total_stats["cached_tokens"]), style="bold white")
|
|
91
|
+
|
|
92
|
+
stats_text.append(" • ", style="dim white")
|
|
93
|
+
stats_text.append("📤 Output Tokens: ", style="bold cyan")
|
|
94
|
+
stats_text.append(format_token_count(total_stats["output_tokens"]), style="bold white")
|
|
95
|
+
|
|
96
|
+
if total_stats["cost"] > 0:
|
|
97
|
+
stats_text.append(" • ", style="dim white")
|
|
98
|
+
stats_text.append("💰 Total Cost: ", style="bold cyan")
|
|
99
|
+
stats_text.append(f"${total_stats['cost']:.4f}", style="bold yellow")
|
|
100
|
+
else:
|
|
101
|
+
stats_text.append("\n")
|
|
102
|
+
stats_text.append("💰 Total Cost: ", style="bold cyan")
|
|
103
|
+
stats_text.append("$0.0000 ", style="bold yellow")
|
|
104
|
+
stats_text.append("• ", style="bold white")
|
|
105
|
+
stats_text.append("📊 Tokens: ", style="bold cyan")
|
|
106
|
+
stats_text.append("0", style="bold white")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def build_final_stats_text(tracer: Any) -> Text:
|
|
110
|
+
"""Build stats text for final output with detailed messages and LLM usage."""
|
|
111
|
+
stats_text = Text()
|
|
112
|
+
if not tracer:
|
|
113
|
+
return stats_text
|
|
114
|
+
|
|
115
|
+
_build_vulnerability_stats(stats_text, tracer)
|
|
116
|
+
|
|
117
|
+
tool_count = tracer.get_real_tool_count()
|
|
118
|
+
agent_count = len(tracer.agents)
|
|
119
|
+
|
|
120
|
+
stats_text.append("🤖 Agents Used: ", style="bold cyan")
|
|
121
|
+
stats_text.append(str(agent_count), style="bold white")
|
|
122
|
+
stats_text.append(" • ", style="dim white")
|
|
123
|
+
stats_text.append("🛠️ Tools Called: ", style="bold cyan")
|
|
124
|
+
stats_text.append(str(tool_count), style="bold white")
|
|
125
|
+
|
|
126
|
+
llm_stats = tracer.get_total_llm_stats()
|
|
127
|
+
_build_llm_stats(stats_text, llm_stats["total"])
|
|
128
|
+
|
|
129
|
+
return stats_text
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def build_live_stats_text(tracer: Any) -> Text:
|
|
133
|
+
stats_text = Text()
|
|
134
|
+
if not tracer:
|
|
135
|
+
return stats_text
|
|
136
|
+
|
|
137
|
+
vuln_count = len(tracer.vulnerability_reports)
|
|
138
|
+
tool_count = tracer.get_real_tool_count()
|
|
139
|
+
agent_count = len(tracer.agents)
|
|
140
|
+
|
|
141
|
+
stats_text.append("🔍 Vulnerabilities: ", style="bold white")
|
|
142
|
+
stats_text.append(f"{vuln_count}", style="dim white")
|
|
143
|
+
stats_text.append("\n")
|
|
144
|
+
if vuln_count > 0:
|
|
145
|
+
severity_counts = {"critical": 0, "high": 0, "medium": 0, "low": 0, "info": 0}
|
|
146
|
+
for report in tracer.vulnerability_reports:
|
|
147
|
+
severity = report.get("severity", "").lower()
|
|
148
|
+
if severity in severity_counts:
|
|
149
|
+
severity_counts[severity] += 1
|
|
150
|
+
|
|
151
|
+
severity_parts = []
|
|
152
|
+
for severity in ["critical", "high", "medium", "low", "info"]:
|
|
153
|
+
count = severity_counts[severity]
|
|
154
|
+
if count > 0:
|
|
155
|
+
severity_color = get_severity_color(severity)
|
|
156
|
+
severity_text = Text()
|
|
157
|
+
severity_text.append(f"{severity.upper()}: ", style=severity_color)
|
|
158
|
+
severity_text.append(str(count), style=f"bold {severity_color}")
|
|
159
|
+
severity_parts.append(severity_text)
|
|
160
|
+
|
|
161
|
+
for i, part in enumerate(severity_parts):
|
|
162
|
+
stats_text.append(part)
|
|
163
|
+
if i < len(severity_parts) - 1:
|
|
164
|
+
stats_text.append(" | ", style="dim white")
|
|
165
|
+
|
|
166
|
+
stats_text.append("\n")
|
|
167
|
+
|
|
168
|
+
stats_text.append("🤖 Agents: ", style="bold white")
|
|
169
|
+
stats_text.append(str(agent_count), style="dim white")
|
|
170
|
+
stats_text.append(" • ", style="dim white")
|
|
171
|
+
stats_text.append("🛠️ Tools: ", style="bold white")
|
|
172
|
+
stats_text.append(str(tool_count), style="dim white")
|
|
173
|
+
|
|
174
|
+
llm_stats = tracer.get_total_llm_stats()
|
|
175
|
+
total_stats = llm_stats["total"]
|
|
176
|
+
|
|
177
|
+
stats_text.append("\n")
|
|
178
|
+
|
|
179
|
+
stats_text.append("📥 Input: ", style="bold white")
|
|
180
|
+
stats_text.append(format_token_count(total_stats["input_tokens"]), style="dim white")
|
|
181
|
+
|
|
182
|
+
stats_text.append(" • ", style="dim white")
|
|
183
|
+
stats_text.append("⚡ ", style="bold white")
|
|
184
|
+
stats_text.append("Cached: ", style="bold white")
|
|
185
|
+
stats_text.append(format_token_count(total_stats["cached_tokens"]), style="dim white")
|
|
186
|
+
|
|
187
|
+
stats_text.append("\n")
|
|
188
|
+
|
|
189
|
+
stats_text.append("📤 Output: ", style="bold white")
|
|
190
|
+
stats_text.append(format_token_count(total_stats["output_tokens"]), style="dim white")
|
|
191
|
+
|
|
192
|
+
stats_text.append(" • ", style="dim white")
|
|
193
|
+
stats_text.append("💰 Cost: ", style="bold white")
|
|
194
|
+
stats_text.append(f"${total_stats['cost']:.4f}", style="dim white")
|
|
195
|
+
|
|
196
|
+
return stats_text
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# Name generation utilities
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _slugify_for_run_name(text: str, max_length: int = 32) -> str:
|
|
203
|
+
text = text.lower().strip()
|
|
204
|
+
text = re.sub(r"[^a-z0-9]+", "-", text)
|
|
205
|
+
text = text.strip("-")
|
|
206
|
+
if len(text) > max_length:
|
|
207
|
+
text = text[:max_length].rstrip("-")
|
|
208
|
+
return text or "pentest"
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _derive_target_label_for_run_name(targets_info: list[dict[str, Any]] | None) -> str: # noqa: PLR0911
|
|
212
|
+
if not targets_info:
|
|
213
|
+
return "pentest"
|
|
214
|
+
|
|
215
|
+
first = targets_info[0]
|
|
216
|
+
target_type = first.get("type")
|
|
217
|
+
details = first.get("details", {}) or {}
|
|
218
|
+
original = first.get("original", "") or ""
|
|
219
|
+
|
|
220
|
+
if target_type == "web_application":
|
|
221
|
+
url = details.get("target_url", original)
|
|
222
|
+
try:
|
|
223
|
+
parsed = urlparse(url)
|
|
224
|
+
return str(parsed.netloc or parsed.path or url)
|
|
225
|
+
except Exception: # noqa: BLE001
|
|
226
|
+
return str(url)
|
|
227
|
+
|
|
228
|
+
if target_type == "repository":
|
|
229
|
+
repo = details.get("target_repo", original)
|
|
230
|
+
parsed = urlparse(repo)
|
|
231
|
+
path = parsed.path or repo
|
|
232
|
+
name = path.rstrip("/").split("/")[-1] or path
|
|
233
|
+
if name.endswith(".git"):
|
|
234
|
+
name = name[:-4]
|
|
235
|
+
return str(name)
|
|
236
|
+
|
|
237
|
+
if target_type == "local_code":
|
|
238
|
+
path_str = details.get("target_path", original)
|
|
239
|
+
try:
|
|
240
|
+
return str(Path(path_str).name or path_str)
|
|
241
|
+
except Exception: # noqa: BLE001
|
|
242
|
+
return str(path_str)
|
|
243
|
+
|
|
244
|
+
if target_type == "ip_address":
|
|
245
|
+
return str(details.get("target_ip", original) or original)
|
|
246
|
+
|
|
247
|
+
return str(original or "pentest")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def generate_run_name(targets_info: list[dict[str, Any]] | None = None) -> str:
|
|
251
|
+
base_label = _derive_target_label_for_run_name(targets_info)
|
|
252
|
+
slug = _slugify_for_run_name(base_label)
|
|
253
|
+
|
|
254
|
+
random_suffix = secrets.token_hex(2)
|
|
255
|
+
|
|
256
|
+
return f"{slug}_{random_suffix}"
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
# Target processing utilities
|
|
260
|
+
def infer_target_type(target: str) -> tuple[str, dict[str, str]]: # noqa: PLR0911
|
|
261
|
+
if not target or not isinstance(target, str):
|
|
262
|
+
raise ValueError("Target must be a non-empty string")
|
|
263
|
+
|
|
264
|
+
target = target.strip()
|
|
265
|
+
|
|
266
|
+
lower_target = target.lower()
|
|
267
|
+
bare_repo_prefixes = (
|
|
268
|
+
"github.com/",
|
|
269
|
+
"www.github.com/",
|
|
270
|
+
"gitlab.com/",
|
|
271
|
+
"www.gitlab.com/",
|
|
272
|
+
"bitbucket.org/",
|
|
273
|
+
"www.bitbucket.org/",
|
|
274
|
+
)
|
|
275
|
+
if any(lower_target.startswith(p) for p in bare_repo_prefixes):
|
|
276
|
+
return "repository", {"target_repo": f"https://{target}"}
|
|
277
|
+
|
|
278
|
+
parsed = urlparse(target)
|
|
279
|
+
if parsed.scheme in ("http", "https"):
|
|
280
|
+
if any(
|
|
281
|
+
host in parsed.netloc.lower() for host in ["github.com", "gitlab.com", "bitbucket.org"]
|
|
282
|
+
):
|
|
283
|
+
return "repository", {"target_repo": target}
|
|
284
|
+
return "web_application", {"target_url": target}
|
|
285
|
+
|
|
286
|
+
try:
|
|
287
|
+
ip_obj = ipaddress.ip_address(target)
|
|
288
|
+
except ValueError:
|
|
289
|
+
pass
|
|
290
|
+
else:
|
|
291
|
+
return "ip_address", {"target_ip": str(ip_obj)}
|
|
292
|
+
|
|
293
|
+
path = Path(target).expanduser()
|
|
294
|
+
try:
|
|
295
|
+
if path.exists():
|
|
296
|
+
if path.is_dir():
|
|
297
|
+
resolved = path.resolve()
|
|
298
|
+
return "local_code", {"target_path": str(resolved)}
|
|
299
|
+
raise ValueError(f"Path exists but is not a directory: {target}")
|
|
300
|
+
except (OSError, RuntimeError) as e:
|
|
301
|
+
raise ValueError(f"Invalid path: {target} - {e!s}") from e
|
|
302
|
+
|
|
303
|
+
if target.startswith("git@") or target.endswith(".git"):
|
|
304
|
+
return "repository", {"target_repo": target}
|
|
305
|
+
|
|
306
|
+
if "." in target and "/" not in target and not target.startswith("."):
|
|
307
|
+
parts = target.split(".")
|
|
308
|
+
if len(parts) >= 2 and all(p and p.strip() for p in parts):
|
|
309
|
+
return "web_application", {"target_url": f"https://{target}"}
|
|
310
|
+
|
|
311
|
+
raise ValueError(
|
|
312
|
+
f"Invalid target: {target}\n"
|
|
313
|
+
"Target must be one of:\n"
|
|
314
|
+
"- A valid URL (http:// or https://)\n"
|
|
315
|
+
"- A Git repository URL (https://github.com/... or git@github.com:...)\n"
|
|
316
|
+
"- A local directory path\n"
|
|
317
|
+
"- A domain name (e.g., example.com)\n"
|
|
318
|
+
"- An IP address (e.g., 192.168.1.10)"
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def sanitize_name(name: str) -> str:
|
|
323
|
+
sanitized = re.sub(r"[^A-Za-z0-9._-]", "-", name.strip())
|
|
324
|
+
return sanitized or "target"
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def derive_repo_base_name(repo_url: str) -> str:
|
|
328
|
+
if repo_url.endswith("/"):
|
|
329
|
+
repo_url = repo_url[:-1]
|
|
330
|
+
|
|
331
|
+
if ":" in repo_url and repo_url.startswith("git@"):
|
|
332
|
+
path_part = repo_url.split(":", 1)[1]
|
|
333
|
+
else:
|
|
334
|
+
path_part = urlparse(repo_url).path or repo_url
|
|
335
|
+
|
|
336
|
+
candidate = path_part.split("/")[-1]
|
|
337
|
+
if candidate.endswith(".git"):
|
|
338
|
+
candidate = candidate[:-4]
|
|
339
|
+
|
|
340
|
+
return sanitize_name(candidate or "repository")
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def derive_local_base_name(path_str: str) -> str:
|
|
344
|
+
try:
|
|
345
|
+
base = Path(path_str).resolve().name
|
|
346
|
+
except (OSError, RuntimeError):
|
|
347
|
+
base = Path(path_str).name
|
|
348
|
+
return sanitize_name(base or "workspace")
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def assign_workspace_subdirs(targets_info: list[dict[str, Any]]) -> None:
|
|
352
|
+
name_counts: dict[str, int] = {}
|
|
353
|
+
|
|
354
|
+
for target in targets_info:
|
|
355
|
+
target_type = target["type"]
|
|
356
|
+
details = target["details"]
|
|
357
|
+
|
|
358
|
+
base_name: str | None = None
|
|
359
|
+
if target_type == "repository":
|
|
360
|
+
base_name = derive_repo_base_name(details["target_repo"])
|
|
361
|
+
elif target_type == "local_code":
|
|
362
|
+
base_name = derive_local_base_name(details.get("target_path", "local"))
|
|
363
|
+
|
|
364
|
+
if base_name is None:
|
|
365
|
+
continue
|
|
366
|
+
|
|
367
|
+
count = name_counts.get(base_name, 0) + 1
|
|
368
|
+
name_counts[base_name] = count
|
|
369
|
+
|
|
370
|
+
workspace_subdir = base_name if count == 1 else f"{base_name}-{count}"
|
|
371
|
+
|
|
372
|
+
details["workspace_subdir"] = workspace_subdir
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def collect_local_sources(targets_info: list[dict[str, Any]]) -> list[dict[str, str]]:
|
|
376
|
+
local_sources: list[dict[str, str]] = []
|
|
377
|
+
|
|
378
|
+
for target_info in targets_info:
|
|
379
|
+
details = target_info["details"]
|
|
380
|
+
workspace_subdir = details.get("workspace_subdir")
|
|
381
|
+
|
|
382
|
+
if target_info["type"] == "local_code" and "target_path" in details:
|
|
383
|
+
local_sources.append(
|
|
384
|
+
{
|
|
385
|
+
"source_path": details["target_path"],
|
|
386
|
+
"workspace_subdir": workspace_subdir,
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
elif target_info["type"] == "repository" and "cloned_repo_path" in details:
|
|
391
|
+
local_sources.append(
|
|
392
|
+
{
|
|
393
|
+
"source_path": details["cloned_repo_path"],
|
|
394
|
+
"workspace_subdir": workspace_subdir,
|
|
395
|
+
}
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
return local_sources
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
# Repository utilities
|
|
402
|
+
def clone_repository(repo_url: str, run_name: str, dest_name: str | None = None) -> str:
|
|
403
|
+
console = Console()
|
|
404
|
+
|
|
405
|
+
git_executable = shutil.which("git")
|
|
406
|
+
if git_executable is None:
|
|
407
|
+
raise FileNotFoundError("Git executable not found in PATH")
|
|
408
|
+
|
|
409
|
+
temp_dir = Path(tempfile.gettempdir()) / "strix_repos" / run_name
|
|
410
|
+
temp_dir.mkdir(parents=True, exist_ok=True)
|
|
411
|
+
|
|
412
|
+
if dest_name:
|
|
413
|
+
repo_name = dest_name
|
|
414
|
+
else:
|
|
415
|
+
repo_name = Path(repo_url).stem if repo_url.endswith(".git") else Path(repo_url).name
|
|
416
|
+
|
|
417
|
+
clone_path = temp_dir / repo_name
|
|
418
|
+
|
|
419
|
+
if clone_path.exists():
|
|
420
|
+
shutil.rmtree(clone_path)
|
|
421
|
+
|
|
422
|
+
try:
|
|
423
|
+
with console.status(f"[bold cyan]Cloning repository {repo_url}...", spinner="dots"):
|
|
424
|
+
subprocess.run( # noqa: S603
|
|
425
|
+
[
|
|
426
|
+
git_executable,
|
|
427
|
+
"clone",
|
|
428
|
+
repo_url,
|
|
429
|
+
str(clone_path),
|
|
430
|
+
],
|
|
431
|
+
capture_output=True,
|
|
432
|
+
text=True,
|
|
433
|
+
check=True,
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
return str(clone_path.absolute())
|
|
437
|
+
|
|
438
|
+
except subprocess.CalledProcessError as e:
|
|
439
|
+
error_text = Text()
|
|
440
|
+
error_text.append("❌ ", style="bold red")
|
|
441
|
+
error_text.append("REPOSITORY CLONE FAILED", style="bold red")
|
|
442
|
+
error_text.append("\n\n", style="white")
|
|
443
|
+
error_text.append(f"Could not clone repository: {repo_url}\n", style="white")
|
|
444
|
+
error_text.append(
|
|
445
|
+
f"Error: {e.stderr if hasattr(e, 'stderr') and e.stderr else str(e)}", style="dim red"
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
panel = Panel(
|
|
449
|
+
error_text,
|
|
450
|
+
title="[bold red]🛡️ STRIX CLONE ERROR",
|
|
451
|
+
title_align="center",
|
|
452
|
+
border_style="red",
|
|
453
|
+
padding=(1, 2),
|
|
454
|
+
)
|
|
455
|
+
console.print("\n")
|
|
456
|
+
console.print(panel)
|
|
457
|
+
console.print()
|
|
458
|
+
sys.exit(1)
|
|
459
|
+
except FileNotFoundError:
|
|
460
|
+
error_text = Text()
|
|
461
|
+
error_text.append("❌ ", style="bold red")
|
|
462
|
+
error_text.append("GIT NOT FOUND", style="bold red")
|
|
463
|
+
error_text.append("\n\n", style="white")
|
|
464
|
+
error_text.append("Git is not installed or not available in PATH.\n", style="white")
|
|
465
|
+
error_text.append("Please install Git to clone repositories.\n", style="white")
|
|
466
|
+
|
|
467
|
+
panel = Panel(
|
|
468
|
+
error_text,
|
|
469
|
+
title="[bold red]🛡️ STRIX CLONE ERROR",
|
|
470
|
+
title_align="center",
|
|
471
|
+
border_style="red",
|
|
472
|
+
padding=(1, 2),
|
|
473
|
+
)
|
|
474
|
+
console.print("\n")
|
|
475
|
+
console.print(panel)
|
|
476
|
+
console.print()
|
|
477
|
+
sys.exit(1)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
# Docker utilities
|
|
481
|
+
def check_docker_connection() -> Any:
|
|
482
|
+
try:
|
|
483
|
+
return docker.from_env()
|
|
484
|
+
except DockerException:
|
|
485
|
+
console = Console()
|
|
486
|
+
error_text = Text()
|
|
487
|
+
error_text.append("❌ ", style="bold red")
|
|
488
|
+
error_text.append("DOCKER NOT AVAILABLE", style="bold red")
|
|
489
|
+
error_text.append("\n\n", style="white")
|
|
490
|
+
error_text.append("Cannot connect to Docker daemon.\n", style="white")
|
|
491
|
+
error_text.append("Please ensure Docker is installed and running.\n\n", style="white")
|
|
492
|
+
error_text.append("Try running: ", style="dim white")
|
|
493
|
+
error_text.append("sudo systemctl start docker", style="dim cyan")
|
|
494
|
+
|
|
495
|
+
panel = Panel(
|
|
496
|
+
error_text,
|
|
497
|
+
title="[bold red]🛡️ STRIX STARTUP ERROR",
|
|
498
|
+
title_align="center",
|
|
499
|
+
border_style="red",
|
|
500
|
+
padding=(1, 2),
|
|
501
|
+
)
|
|
502
|
+
console.print("\n", panel, "\n")
|
|
503
|
+
raise RuntimeError("Docker not available") from None
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def image_exists(client: Any, image_name: str) -> bool:
|
|
507
|
+
try:
|
|
508
|
+
client.images.get(image_name)
|
|
509
|
+
except ImageNotFound:
|
|
510
|
+
return False
|
|
511
|
+
else:
|
|
512
|
+
return True
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def update_layer_status(layers_info: dict[str, str], layer_id: str, layer_status: str) -> None:
|
|
516
|
+
if "Pull complete" in layer_status or "Already exists" in layer_status:
|
|
517
|
+
layers_info[layer_id] = "✓"
|
|
518
|
+
elif "Downloading" in layer_status:
|
|
519
|
+
layers_info[layer_id] = "↓"
|
|
520
|
+
elif "Extracting" in layer_status:
|
|
521
|
+
layers_info[layer_id] = "📦"
|
|
522
|
+
elif "Waiting" in layer_status:
|
|
523
|
+
layers_info[layer_id] = "⏳"
|
|
524
|
+
else:
|
|
525
|
+
layers_info[layer_id] = "•"
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def process_pull_line(
|
|
529
|
+
line: dict[str, Any], layers_info: dict[str, str], status: Any, last_update: str
|
|
530
|
+
) -> str:
|
|
531
|
+
if "id" in line and "status" in line:
|
|
532
|
+
layer_id = line["id"]
|
|
533
|
+
update_layer_status(layers_info, layer_id, line["status"])
|
|
534
|
+
|
|
535
|
+
completed = sum(1 for v in layers_info.values() if v == "✓")
|
|
536
|
+
total = len(layers_info)
|
|
537
|
+
|
|
538
|
+
if total > 0:
|
|
539
|
+
update_msg = f"[bold cyan]Progress: {completed}/{total} layers complete"
|
|
540
|
+
if update_msg != last_update:
|
|
541
|
+
status.update(update_msg)
|
|
542
|
+
return update_msg
|
|
543
|
+
|
|
544
|
+
elif "status" in line and "id" not in line:
|
|
545
|
+
global_status = line["status"]
|
|
546
|
+
if "Pulling from" in global_status:
|
|
547
|
+
status.update("[bold cyan]Fetching image manifest...")
|
|
548
|
+
elif "Digest:" in global_status:
|
|
549
|
+
status.update("[bold cyan]Verifying image...")
|
|
550
|
+
elif "Status:" in global_status:
|
|
551
|
+
status.update("[bold cyan]Finalizing...")
|
|
552
|
+
|
|
553
|
+
return last_update
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
# LLM utilities
|
|
557
|
+
def validate_llm_response(response: Any) -> None:
|
|
558
|
+
if not response or not response.choices or not response.choices[0].message.content:
|
|
559
|
+
raise RuntimeError("Invalid response from LLM")
|
strix/llm/__init__.py
ADDED
strix/llm/config.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LLMConfig:
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
model_name: str | None = None,
|
|
8
|
+
enable_prompt_caching: bool = True,
|
|
9
|
+
prompt_modules: list[str] | None = None,
|
|
10
|
+
timeout: int | None = None,
|
|
11
|
+
):
|
|
12
|
+
self.model_name = model_name or os.getenv("STRIX_LLM", "openai/gpt-5")
|
|
13
|
+
|
|
14
|
+
if not self.model_name:
|
|
15
|
+
raise ValueError("STRIX_LLM environment variable must be set and not empty")
|
|
16
|
+
|
|
17
|
+
self.enable_prompt_caching = enable_prompt_caching
|
|
18
|
+
self.prompt_modules = prompt_modules or []
|
|
19
|
+
|
|
20
|
+
self.timeout = timeout or int(os.getenv("LLM_TIMEOUT", "600"))
|