From f9e1a152680a2142ca4d29fade35b8a41b036fd9 Mon Sep 17 00:00:00 2001 From: rarebuffalo Date: Mon, 15 Jun 2026 00:42:06 +0530 Subject: [PATCH] allow local model support and fall back to offline mode when api key is missing --- cli/securelens/cli.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/securelens/cli.py b/cli/securelens/cli.py index fcbe06c..beb0db3 100644 --- a/cli/securelens/cli.py +++ b/cli/securelens/cli.py @@ -30,8 +30,8 @@ def _run(coro): def _require_config(cfg): - """Exit early with a friendly message if no API key is set.""" - if not cfg.api_key: + """Exit early with a friendly message if no API key is set and not using a local model.""" + if not cfg.api_key and not cfg.default_model.startswith("ollama/"): console.print( "\n[bold yellow]⚠ No API key configured.[/bold yellow]\n" " Run [bold cyan]securelens configure[/bold cyan] to set one up.\n" @@ -158,7 +158,15 @@ async def _scan_async(path, model, output, max_files, ci, fail_on, no_ai, sync): cfg.max_files_to_scan = max_files if not no_ai: - _require_config(cfg) + if not cfg.api_key and not cfg.default_model.startswith("ollama/"): + console.print( + "\n[bold yellow]⚠ No API key configured.[/bold yellow] Automatically falling back to [bold cyan]offline pattern-based mode[/bold cyan].\n" + " To use AI capabilities, run [bold cyan]securelens configure[/bold cyan] to set an API key,\n" + " or set the [dim]SECURELENS_API_KEY[/dim] environment variable.\n" + ) + no_ai = True + else: + _require_config(cfg) root = Path(path).resolve()