From 06708a3c4a69c16691ea0a137f840e0fb153cced Mon Sep 17 00:00:00 2001 From: Swaroop Manchala Date: Sun, 21 Dec 2025 17:53:56 +0530 Subject: [PATCH 1/5] fix: handle system object from detect_hardware in config wizard --- cortex/cli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cortex/cli.py b/cortex/cli.py index c808d5e4..0a3ec03b 100644 --- a/cortex/cli.py +++ b/cortex/cli.py @@ -180,6 +180,29 @@ def demo(self): """ return run_demo() + def config(self): + from cortex.hardware_detection import detect_hardware + + print("\n🧠 CORTEX INTERACTIVE SETUP") + print("=" * 32) + + print("\nšŸ” Detecting hardware...") + hw = detect_hardware() + + if getattr(hw, "gpu", None): + print(f"āœ” GPU detected: {hw.gpu}") + else: + print("āš ļø No GPU detected (CPU mode)") + + if getattr(hw, "cpu", None): + print(f"āœ” CPU: {hw.cpu}") + + if getattr(hw, "memory_gb", None): + print(f"āœ” RAM: {hw.memory_gb} GB") + + print("\nHardware detection complete.\n") + return 0 + def stack(self, args: argparse.Namespace) -> int: """Handle `cortex stack` commands (list/describe/install/dry-run).""" try: @@ -824,6 +847,9 @@ def main(): # Wizard command wizard_parser = subparsers.add_parser("wizard", help="Configure API key interactively") + #config command + config_parser = subparsers.add_parser("config", help="Interactive setup wizard for Contex Configuration") + # Status command status_parser = subparsers.add_parser("status", help="Show system status") @@ -910,6 +936,8 @@ def main(): return cli.demo() elif args.command == "wizard": return cli.wizard() + elif args.command == "config": + return cli.config() elif args.command == "status": return cli.status() elif args.command == "install": From 7ca3251b39309401c4e842c61a9552c6378c41d1 Mon Sep 17 00:00:00 2001 From: Swaroop Manchala Date: Sun, 21 Dec 2025 18:05:18 +0530 Subject: [PATCH 2/5] feat: prompt and validate API keys in config wizard --- cortex/cli.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/cortex/cli.py b/cortex/cli.py index 0a3ec03b..7af8c100 100644 --- a/cortex/cli.py +++ b/cortex/cli.py @@ -186,13 +186,16 @@ def config(self): print("\n🧠 CORTEX INTERACTIVE SETUP") print("=" * 32) + # 1ļøāƒ£ Detect hardware first print("\nšŸ” Detecting hardware...") hw = detect_hardware() if getattr(hw, "gpu", None): print(f"āœ” GPU detected: {hw.gpu}") + has_gpu = True else: print("āš ļø No GPU detected (CPU mode)") + has_gpu = False if getattr(hw, "cpu", None): print(f"āœ” CPU: {hw.cpu}") @@ -200,7 +203,50 @@ def config(self): if getattr(hw, "memory_gb", None): print(f"āœ” RAM: {hw.memory_gb} GB") - print("\nHardware detection complete.\n") + # 2ļøāƒ£ Provider selection + print("\nšŸ¤– Select default LLM provider:\n") + + print("[1] Anthropic Claude (cloud)") + print("[2] OpenAI GPT (cloud)") + if has_gpu: + print("[3] Ollama (local) - recommended for your hardware") + else: + print("[3] Ollama (local)") + + choice = input("\nChoice (1/2/3): ").strip() + + provider_map = { + "1": "anthropic", + "2": "openai", + "3": "ollama", + } + + provider = provider_map.get(choice) + + if not provider: + print("āŒ Invalid choice. Please re-run `cortex config`.") + return 1 + + print(f"\nāœ” Selected provider: {provider}\n") + # 3ļøāƒ£ API key configuration (if required) + api_key = None + + if provider in ("anthropic", "openai"): + env_var = "ANTHROPIC_API_KEY" if provider == "anthropic" else "OPENAI_API_KEY" + print(f"šŸ”‘ Enter your {env_var}:") + + api_key = input("> ").strip() + + # Very light validation + if len(api_key) < 10: + print("āŒ API key looks invalid. Please re-run `cortex config`.") + return 1 + + print("āœ” API key accepted\n") + else: + print("ā„¹ļø Ollama selected — no API key required\n") + + print("Setup step complete.\n") return 0 def stack(self, args: argparse.Namespace) -> int: From 32b0219e212563ffdc5c630911cc3acaa74e386e Mon Sep 17 00:00:00 2001 From: Swaroop Manchala Date: Sun, 21 Dec 2025 19:19:10 +0530 Subject: [PATCH 3/5] feat: save cortex config to ~/.cortex/config.yaml --- cortex/cli.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cortex/cli.py b/cortex/cli.py index 7af8c100..36b5962d 100644 --- a/cortex/cli.py +++ b/cortex/cli.py @@ -247,6 +247,33 @@ def config(self): print("ā„¹ļø Ollama selected — no API key required\n") print("Setup step complete.\n") + # 4ļøāƒ£ Save configuration to ~/.cortex/config.yaml + from pathlib import Path + + import yaml + + config_dir = Path.home() / ".cortex" + config_dir.mkdir(exist_ok=True) + + config_path = config_dir / "config.yaml" + + config_data = { + "provider": provider, + "hardware": { + "gpu": getattr(hw, "gpu", None), + "cpu": str(getattr(hw, "cpu", None)), + "memory_gb": getattr(hw, "memory_gb", None), + }, + "preferences": { + "verbose": False, + "dry_run_default": False, + }, + } + + with open(config_path, "w") as f: + yaml.safe_dump(config_data, f) + + print(f"šŸ’¾ Configuration saved to {config_path}") return 0 def stack(self, args: argparse.Namespace) -> int: @@ -893,8 +920,10 @@ def main(): # Wizard command wizard_parser = subparsers.add_parser("wizard", help="Configure API key interactively") - #config command - config_parser = subparsers.add_parser("config", help="Interactive setup wizard for Contex Configuration") + # config command + config_parser = subparsers.add_parser( + "config", help="Interactive setup wizard for Contex Configuration" + ) # Status command status_parser = subparsers.add_parser("status", help="Show system status") From 9f8842c340e9551869c4e56980e1b93741492451 Mon Sep 17 00:00:00 2001 From: Swaroop Manchala Date: Mon, 22 Dec 2025 00:07:08 +0530 Subject: [PATCH 4/5] fix: improve hardware display in config wizard --- cortex/cli.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cortex/cli.py b/cortex/cli.py index 36b5962d..2d7ffd3f 100644 --- a/cortex/cli.py +++ b/cortex/cli.py @@ -197,11 +197,21 @@ def config(self): print("āš ļø No GPU detected (CPU mode)") has_gpu = False - if getattr(hw, "cpu", None): - print(f"āœ” CPU: {hw.cpu}") + cpu_model = getattr(hw.cpu, "model", None) if hw.cpu else None + if cpu_model: + print(f"āœ” CPU: {cpu_model}") + else: + print("āœ” CPU detected") - if getattr(hw, "memory_gb", None): - print(f"āœ” RAM: {hw.memory_gb} GB") + # RAM (safe detection, same logic as demo) + if hasattr(hw, "memory") and hw.memory: + ram_gb = getattr(hw.memory, "total_gb", None) + if ram_gb: + print(f"āœ” RAM: {ram_gb} GB") + else: + print("āœ” RAM detected") + else: + print("āœ” RAM: Unknown") # 2ļøāƒ£ Provider selection print("\nšŸ¤– Select default LLM provider:\n") From 1530f554bb70db6ce5b1e1f51d0150935d4c4c9a Mon Sep 17 00:00:00 2001 From: Swaroop Manchala Date: Tue, 23 Dec 2025 14:18:50 +0530 Subject: [PATCH 5/5] fix: complete and stabilize cortex config setup wizard --- cortex/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cortex/cli.py b/cortex/cli.py index 2d7ffd3f..f944da41 100644 --- a/cortex/cli.py +++ b/cortex/cli.py @@ -190,8 +190,10 @@ def config(self): print("\nšŸ” Detecting hardware...") hw = detect_hardware() + gpu_info = None if getattr(hw, "gpu", None): print(f"āœ” GPU detected: {hw.gpu}") + gpu_info = str(hw.gpu) has_gpu = True else: print("āš ļø No GPU detected (CPU mode)") @@ -270,7 +272,7 @@ def config(self): config_data = { "provider": provider, "hardware": { - "gpu": getattr(hw, "gpu", None), + "gpu": gpu_info, "cpu": str(getattr(hw, "cpu", None)), "memory_gb": getattr(hw, "memory_gb", None), },