Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 409b5c6

Browse files
committed
Fix types.
1 parent 0f68904 commit 409b5c6

File tree

6 files changed

+78
-76
lines changed

6 files changed

+78
-76
lines changed

src/cli/pentest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def main(
183183
return 1
184184

185185
# Check model availability
186-
backend_type = client.get_backend_type() if hasattr(client, 'get_backend_type') else "Ollama"
186+
backend_type = client.get_backend_type() if hasattr(client, "get_backend_type") else "Ollama"
187187
click.echo(f"🔍 Checking {backend_type} model availability...")
188188
if not client.is_available():
189189
click.echo(f"❌ Model {client.get_model_name()} not available.")
@@ -193,7 +193,7 @@ def main(
193193
click.echo(f"✅ {backend_type} model {client.get_model_name()} ready")
194194

195195
# Check if backend is busy before starting tests (Ollama only)
196-
if not skip_busy_check and hasattr(client, 'check_status'):
196+
if not skip_busy_check and hasattr(client, "check_status"):
197197
click.echo(f"🔍 Checking {backend_type} status...")
198198
try:
199199
status = client.check_status()
@@ -214,7 +214,9 @@ def main(
214214
)
215215
return 1
216216
else:
217-
click.echo(f"🚫 {backend_type} is busy. Use --skip-busy-check to proceed anyway.")
217+
click.echo(
218+
f"🚫 {backend_type} is busy. Use --skip-busy-check to proceed anyway."
219+
)
218220
return 1
219221
else:
220222
click.echo(f"✅ {backend_type} status: Available")
@@ -223,7 +225,9 @@ def main(
223225
except Exception as e:
224226
click.echo(f"⚠️ Could not check {backend_type} status: {e}")
225227
if not quiet and not skip_busy_check:
226-
if click.confirm(f"\nCould not determine if {backend_type} is busy. Continue anyway?"):
228+
if click.confirm(
229+
f"\nCould not determine if {backend_type} is busy. Continue anyway?"
230+
):
227231
click.echo("⚡ Proceeding with tests...")
228232
else:
229233
click.echo("🚫 Aborted. Use --skip-busy-check to proceed anyway.")

src/cli/setup.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def interactive_backend_setup() -> bool:
5959
click.echo("Choose your preferred LLM backend:")
6060
click.echo("1. Ollama (local models)")
6161
click.echo("2. OpenRouter (cloud models)")
62-
62+
6363
while True:
6464
try:
6565
choice = click.prompt("Select backend (1-2)", type=int)
@@ -71,7 +71,7 @@ def interactive_backend_setup() -> bool:
7171
return False
7272
except (ValueError, TypeError):
7373
click.echo("❌ Invalid input. Please enter 1 or 2.")
74-
74+
7575
if choice == 1:
7676
return setup_ollama_backend()
7777
else:
@@ -81,21 +81,21 @@ def interactive_backend_setup() -> bool:
8181
def setup_ollama_backend() -> bool:
8282
"""Setup Ollama backend configuration."""
8383
click.echo("\n🦙 Configuring Ollama Backend")
84-
84+
8585
# Create default settings.yaml if it doesn't exist
8686
if not Path("settings.yaml").exists():
8787
settings_manager.create_default_settings()
88-
88+
8989
host = click.prompt("Ollama host", default="localhost")
9090
port = click.prompt("Ollama port", default=11434, type=int)
9191
model = click.prompt("Model name", default="gpt-oss:20b")
92-
92+
9393
# Save settings
9494
settings_manager.set("backend.provider", "ollama")
9595
settings_manager.set("ollama.host", host)
9696
settings_manager.set("ollama.port", port)
9797
settings_manager.set("ollama.model", model)
98-
98+
9999
click.echo("✅ Ollama backend configured")
100100
return True
101101

@@ -104,16 +104,16 @@ def setup_openrouter_backend() -> bool:
104104
"""Setup OpenRouter backend configuration."""
105105
click.echo("\n🌐 Configuring OpenRouter Backend")
106106
click.echo("You'll need an OpenRouter API key from: https://openrouter.ai/keys")
107-
107+
108108
# Create default settings.yaml if it doesn't exist
109109
if not Path("settings.yaml").exists():
110110
settings_manager.create_default_settings()
111-
111+
112112
api_key = click.prompt("OpenRouter API key", hide_input=True)
113113
if not api_key.strip():
114114
click.echo("❌ API key is required for OpenRouter")
115115
return False
116-
116+
117117
# Show popular models
118118
click.echo("\nPopular models:")
119119
models = [
@@ -124,30 +124,27 @@ def setup_openrouter_backend() -> bool:
124124
"google/gemini-pro-1.5",
125125
"mistral/mistral-large",
126126
]
127-
127+
128128
for i, model in enumerate(models, 1):
129129
click.echo(f"{i}. {model}")
130-
130+
131131
try:
132132
choice = click.prompt("Select model (1-5, or enter custom)", default="1")
133-
if choice.isdigit() and 1 <= int(choice) <= 5:
134-
model = models[int(choice) - 1]
135-
else:
136-
model = choice
133+
model = models[int(choice) - 1] if choice.isdigit() and 1 <= int(choice) <= 5 else choice
137134
except (ValueError, IndexError):
138135
model = "openai/gpt-oss-20b"
139-
136+
140137
site_name = click.prompt("Site name (optional)", default="Red Team Testbed")
141138
site_url = click.prompt("Site URL (optional)", default="")
142-
139+
143140
# Save settings
144141
settings_manager.set("backend.provider", "openrouter")
145142
settings_manager.set("openrouter.api_key", api_key)
146143
settings_manager.set("openrouter.model", model)
147144
settings_manager.set("openrouter.site_name", site_name)
148145
if site_url:
149146
settings_manager.set("openrouter.site_url", site_url)
150-
147+
151148
click.echo("✅ OpenRouter backend configured")
152149
return True
153150

@@ -159,32 +156,33 @@ def test_connection(config: dict[str, Any], verbose: bool = False) -> bool:
159156
if Path("settings.yaml").exists():
160157
settings = settings_manager.load_settings()
161158
backend = create_backend(settings)
162-
provider = settings['backend']['provider']
159+
provider = settings["backend"]["provider"]
163160
click.echo(f"🔗 Testing {provider} connection...")
164161
else:
165162
# Fallback to default Ollama configuration
166163
from src.utils.model_client import OllamaClient
164+
167165
backend = OllamaClient() # Uses default localhost:11434, gpt-oss:20b
168166
provider = "ollama"
169167
click.echo("🔗 Testing default Ollama connection...")
170-
171-
if provider == 'ollama':
168+
169+
if provider == "ollama":
172170
return test_ollama_connection(backend, verbose)
173171
else:
174172
return test_openrouter_connection(backend, verbose)
175-
173+
176174
except Exception as e:
177175
click.echo(f"❌ Backend setup failed: {e}")
178176
return False
179177

180178

181-
def test_ollama_connection(backend, verbose: bool = False) -> bool:
179+
def test_ollama_connection(backend: object, verbose: bool = False) -> bool:
182180
"""Test connection to Ollama backend."""
183181
# Check if Ollama is busy before testing
184182
click.echo("🔍 Checking Ollama status...")
185183
try:
186184
# Handle both OllamaBackend and OllamaClient
187-
if hasattr(backend, 'check_status'):
185+
if hasattr(backend, "check_status"):
188186
status = backend.check_status()
189187
else:
190188
status = backend.check_ollama_status()
@@ -207,7 +205,7 @@ def test_ollama_connection(backend, verbose: bool = False) -> bool:
207205

208206
try:
209207
# Handle both interfaces for availability check
210-
if hasattr(backend, 'is_available'):
208+
if hasattr(backend, "is_available"):
211209
model_available = backend.is_available()
212210
model_name = backend.get_model_name()
213211
else:
@@ -242,7 +240,7 @@ def test_ollama_connection(backend, verbose: bool = False) -> bool:
242240
return False
243241

244242

245-
def test_openrouter_connection(backend, verbose: bool = False) -> bool:
243+
def test_openrouter_connection(backend: object, verbose: bool = False) -> bool:
246244
"""Test connection to OpenRouter backend."""
247245
try:
248246
if not backend.is_available():
@@ -282,7 +280,7 @@ def main(config: str, verbose: bool, configure: bool) -> int | None:
282280
This command will:
283281
284282
\b
285-
- Configure LLM backend (Ollama or OpenRouter)
283+
- Configure LLM backend (Ollama or OpenRouter)
286284
- Load and validate configuration
287285
- Set up logging and directories
288286
- Test backend connection and model availability
@@ -298,7 +296,7 @@ def main(config: str, verbose: bool, configure: bool) -> int | None:
298296
if not interactive_backend_setup():
299297
return 1
300298
click.echo("")
301-
299+
302300
# Check if settings.yaml exists
303301
if not Path("settings.yaml").exists():
304302
if configure:
@@ -307,7 +305,7 @@ def main(config: str, verbose: bool, configure: bool) -> int | None:
307305
else:
308306
click.echo("💡 No settings.yaml found, using default Ollama configuration")
309307
click.echo(" Run 'uv run setup --configure' to configure different backends")
310-
308+
311309
# Load configuration (fallback compatibility)
312310
click.echo("📋 Loading configuration...")
313311
try:
@@ -317,7 +315,7 @@ def main(config: str, verbose: bool, configure: bool) -> int | None:
317315
# Use minimal config if config.yaml doesn't exist
318316
config_data = {
319317
"output": {"results_dir": "results", "findings_dir": "findings"},
320-
"logging": {"level": "INFO", "file": "testbed.log"}
318+
"logging": {"level": "INFO", "file": "testbed.log"},
321319
}
322320

323321
# Setup logging
@@ -358,4 +356,4 @@ def main(config: str, verbose: bool, configure: bool) -> int | None:
358356

359357

360358
if __name__ == "__main__":
361-
main()
359+
main()

src/utils/llm_backend.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_model_name(self) -> str:
4545
"""Get the current model name."""
4646
pass
4747

48-
@abstractmethod
48+
@abstractmethod
4949
def get_backend_type(self) -> str:
5050
"""Get the backend type identifier."""
5151
pass
@@ -115,7 +115,7 @@ def get_backend_type(self) -> str:
115115
"""Get the backend type identifier."""
116116
return "Ollama"
117117

118-
def check_status(self) -> Any:
118+
def check_status(self) -> object:
119119
"""Check Ollama status."""
120120
return self.client.check_ollama_status()
121121

@@ -130,6 +130,7 @@ class OpenRouterBackend(LLMBackend):
130130
def __init__(self, config: dict[str, Any]) -> None:
131131
super().__init__(config)
132132
import logging
133+
133134
import openai
134135

135136
# Suppress noisy httpx logs from OpenAI client
@@ -181,13 +182,13 @@ def generate(
181182
)
182183

183184
response_time = time.time() - start_time
184-
185+
185186
choice = response.choices[0]
186187
content = choice.message.content or ""
187-
188+
188189
# Extract thinking if available (for models that support it)
189190
thinking = None
190-
if hasattr(choice.message, 'reasoning') and choice.message.reasoning:
191+
if hasattr(choice.message, "reasoning") and choice.message.reasoning:
191192
thinking = choice.message.reasoning
192193

193194
return ModelResponse(
@@ -235,10 +236,10 @@ def chat(
235236

236237
choice = response.choices[0]
237238
content = choice.message.content or ""
238-
239+
239240
# Extract thinking if available (for models that support it)
240241
thinking = None
241-
if hasattr(choice.message, 'reasoning') and choice.message.reasoning:
242+
if hasattr(choice.message, "reasoning") and choice.message.reasoning:
242243
thinking = choice.message.reasoning
243244

244245
return ModelResponse(
@@ -301,4 +302,4 @@ def create_backend(settings: dict[str, Any]) -> LLMBackend:
301302
openrouter_config = settings.get("openrouter", {})
302303
return OpenRouterBackend(openrouter_config)
303304
else:
304-
raise ValueError(f"Unsupported backend provider: {provider}")
305+
raise ValueError(f"Unsupported backend provider: {provider}")

src/utils/model_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from src.utils.settings_manager import settings_manager
1212

1313

14-
def get_client():
14+
def get_client() -> object:
1515
"""Factory function to get the configured LLM client."""
1616
try:
1717
settings = settings_manager.load_settings()

0 commit comments

Comments
 (0)