Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions cortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@
is_valid, detected_provider, error = validate_api_key()
if not is_valid:
self._print_error(error)
cx_print("Run [bold]cortex wizard[/bold] to configure your API key.", "info")
cx_print("Or use [bold]CORTEX_PROVIDER=ollama[/bold] for offline mode.", "info")
cx_print(
"Run [bold]cortex wizard[/bold] to configure your API key.", "info"
)
cx_print(
"Or use [bold]CORTEX_PROVIDER=ollama[/bold] for offline mode.", "info"
)
return None
api_key = os.environ.get("ANTHROPIC_API_KEY") or os.environ.get("OPENAI_API_KEY")
return api_key
Expand Down Expand Up @@ -105,7 +109,9 @@
"""Handle notification commands"""
# Addressing CodeRabbit feedback: Handle missing subcommand gracefully
if not args.notify_action:
self._print_error("Please specify a subcommand (config/enable/disable/dnd/send)")
self._print_error(
"Please specify a subcommand (config/enable/disable/dnd/send)"
)
return 1

mgr = NotificationManager()
Expand Down Expand Up @@ -135,7 +141,9 @@
elif args.notify_action == "disable":
mgr.config["enabled"] = False
mgr._save_config()
cx_print("Notifications disabled (Critical alerts will still show)", "warning")
cx_print(
"Notifications disabled (Critical alerts will still show)", "warning"
)
return 0

elif args.notify_action == "dnd":
Expand Down Expand Up @@ -171,6 +179,13 @@

# -------------------------------

# Run system health checks
def doctor(self):
from cortex.doctor import SystemDoctor

doctor = SystemDoctor()
return doctor.run_checks()

def install(self, software: str, execute: bool = False, dry_run: bool = False):
# Validate input first
is_valid, error = validate_install_request(software)
Expand Down Expand Up @@ -261,7 +276,9 @@

# Record successful installation
if install_id:
history.update_installation(install_id, InstallationStatus.SUCCESS)
history.update_installation(
install_id, InstallationStatus.SUCCESS
)
print(f"\n📝 Installation recorded (ID: {install_id})")
print(f" To rollback: cortex rollback {install_id}")

Expand All @@ -275,7 +292,9 @@
)

if result.failed_step is not None:
self._print_error(f"Installation failed at step {result.failed_step + 1}")
self._print_error(
f"Installation failed at step {result.failed_step + 1}"
)
else:
self._print_error("Installation failed")
if result.error_message:
Expand All @@ -292,17 +311,23 @@

except ValueError as e:
if install_id:
history.update_installation(install_id, InstallationStatus.FAILED, str(e))
history.update_installation(
install_id, InstallationStatus.FAILED, str(e)
)
self._print_error(str(e))
return 1
except RuntimeError as e:
if install_id:
history.update_installation(install_id, InstallationStatus.FAILED, str(e))
history.update_installation(
install_id, InstallationStatus.FAILED, str(e)
)
self._print_error(f"API call failed: {str(e)}")
return 1
except Exception as e:
if install_id:
history.update_installation(install_id, InstallationStatus.FAILED, str(e))
history.update_installation(
install_id, InstallationStatus.FAILED, str(e)
)
self._print_error(f"Unexpected error: {str(e)}")
return 1

Expand Down Expand Up @@ -561,6 +586,7 @@
table.add_row("history", "View history")
table.add_row("rollback <id>", "Undo installation")
table.add_row("notify", "Manage desktop notifications") # Added this line
table.add_row("doctor", "System health check")
table.add_row("cache stats", "Show LLM cache statistics")

console.print(table)
Expand Down Expand Up @@ -592,28 +618,32 @@
)

# Global flags
parser.add_argument("--version", "-V", action="version", version=f"cortex {VERSION}")
parser.add_argument(
"--version", "-V", action="version", version=f"cortex {VERSION}"
)
parser.add_argument(
"--verbose", "-v", action="store_true", help="Show detailed output"
parser.add_argument("--verbose", "-v", action="store_true", help="Show detailed output")

Check failure on line 626 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:626:5: invalid-syntax: Expected `,`, found name
parser.add_argument(

Check failure on line 627 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:627:5: invalid-syntax: Expected `,`, found name
"--offline", action="store_true", help="Use cached responses only (no network calls)"
)

subparsers = parser.add_subparsers(dest="command", help="Available commands")

Check failure on line 631 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:631:5: invalid-syntax: Expected `,`, found name

# Demo command
demo_parser = subparsers.add_parser("demo", help="See Cortex in action")

Check failure on line 634 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:634:5: invalid-syntax: Expected `,`, found name

# Wizard command
wizard_parser = subparsers.add_parser("wizard", help="Configure API key interactively")

Check failure on line 637 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:637:5: invalid-syntax: Expected `,`, found name

# Status command
status_parser = subparsers.add_parser("status", help="Show system status")

Check failure on line 640 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:640:5: invalid-syntax: Expected `,`, found name

# Install command
install_parser = subparsers.add_parser("install", help="Install software")

Check failure on line 643 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:643:5: invalid-syntax: Expected `,`, found name
install_parser.add_argument("software", type=str, help="Software to install")

Check failure on line 644 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:644:5: invalid-syntax: Expected `,`, found name
install_parser.add_argument("--execute", action="store_true", help="Execute commands")

Check failure on line 645 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:645:5: invalid-syntax: Expected `,`, found name
install_parser.add_argument("--dry-run", action="store_true", help="Show commands only")

Check failure on line 646 in cortex/cli.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (invalid-syntax)

cortex/cli.py:646:5: invalid-syntax: Expected `,`, found name

# History command
history_parser = subparsers.add_parser("history", help="View history")
Expand Down Expand Up @@ -650,6 +680,13 @@
send_parser = notify_subs.add_parser("send", help="Send test notification")
send_parser.add_argument("message", help="Notification message")
send_parser.add_argument("--title", default="Cortex Notification")
send_parser.add_argument(
"--level", choices=["low", "normal", "critical"], default="normal"
)
send_parser.add_argument("--actions", nargs="*", help="Action buttons")
# --------------------------

doctor_parser = subparsers.add_parser("doctor", help="Run system health check")
send_parser.add_argument("--level", choices=["low", "normal", "critical"], default="normal")
send_parser.add_argument("--actions", nargs="*", help="Action buttons")
# --------------------------
Expand Down Expand Up @@ -688,6 +725,8 @@
# Handle the new notify command
elif args.command == "notify":
return cli.notify(args)
elif args.command == "doctor":
return cli.doctor()
elif args.command == "cache":
if getattr(args, "cache_action", None) == "stats":
return cli.cache_stats()
Expand Down
Loading
Loading