Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
with:
python-version: "3.11"

- name: Install formatters
- name: Install dependencies
run: |
python -m pip install -U pip
pip install ruff black isort
pip install -e ".[dev]"
- name: Fix with ruff
run: ruff check . --fix || true
Expand Down
99 changes: 0 additions & 99 deletions .github/workflows/automation.yml

This file was deleted.

16 changes: 7 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
with:
python-version: "3.11"

- name: Install linting tools
- name: Install dependencies
run: |
python -m pip install -U pip
pip install ruff black mypy
pip install -e ".[dev]"

- name: Lint with ruff
run: ruff check . --output-format=github
Expand Down Expand Up @@ -104,18 +104,16 @@ jobs:
with:
python-version: "3.11"

- name: Install security tools
- name: Install dependencies
run: |
python -m pip install -U pip
pip install bandit safety
pip install -e ".[security]"

- name: Run bandit security scan
run: bandit -r cortex -ll -ii --format json --output bandit-report.json || true

- name: Check for known vulnerabilities
run: |
pip install -e .
safety check --json --output safety-report.json || true
run: safety check --json --output safety-report.json || true
continue-on-error: true

- name: Upload security reports
Expand All @@ -140,10 +138,10 @@ jobs:
with:
python-version: "3.11"

- name: Install build tools
- name: Install dependencies
run: |
python -m pip install -U pip
pip install build twine
pip install -e ".[dev]" twine

- name: Build package
run: python -m build
Expand Down
48 changes: 16 additions & 32 deletions cortex/context_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def _init_database(self):
cursor = conn.cursor()

# Memory entries table
cursor.execute(
"""
cursor.execute("""
CREATE TABLE IF NOT EXISTS memory_entries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
Expand All @@ -112,12 +111,10 @@ def _init_database(self):
metadata TEXT,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
)
"""
)
""")

# Patterns table
cursor.execute(
"""
cursor.execute("""
CREATE TABLE IF NOT EXISTS patterns (
pattern_id TEXT PRIMARY KEY,
pattern_type TEXT NOT NULL,
Expand All @@ -129,12 +126,10 @@ def _init_database(self):
context TEXT,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
)
"""
)
""")

# Suggestions table
cursor.execute(
"""
cursor.execute("""
CREATE TABLE IF NOT EXISTS suggestions (
suggestion_id TEXT PRIMARY KEY,
suggestion_type TEXT NOT NULL,
Expand All @@ -145,20 +140,17 @@ def _init_database(self):
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
dismissed BOOLEAN DEFAULT 0
)
"""
)
""")

# User preferences table
cursor.execute(
"""
cursor.execute("""
CREATE TABLE IF NOT EXISTS preferences (
key TEXT PRIMARY KEY,
value TEXT,
category TEXT,
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
)
"""
)
""")

# Create indexes for performance
cursor.execute(
Expand Down Expand Up @@ -408,14 +400,12 @@ def generate_suggestions(self, context: str = None) -> list[Suggestion]:
with self._pool.get_connection() as conn:
cursor = conn.cursor()

cursor.execute(
"""
cursor.execute("""
SELECT * FROM memory_entries
WHERE timestamp > datetime('now', '-7 days')
ORDER BY timestamp DESC
LIMIT 50
"""
)
""")

recent_entries = [self._row_to_memory_entry(row) for row in cursor.fetchall()]

Expand Down Expand Up @@ -632,23 +622,19 @@ def get_statistics(self) -> dict[str, Any]:
stats["total_entries"] = cursor.fetchone()[0]

# Entries by category
cursor.execute(
"""
cursor.execute("""
SELECT category, COUNT(*)
FROM memory_entries
GROUP BY category
"""
)
""")
stats["by_category"] = dict(cursor.fetchall())

# Success rate
cursor.execute(
"""
cursor.execute("""
SELECT
SUM(CASE WHEN success = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(*) as success_rate
FROM memory_entries
"""
)
""")
stats["success_rate"] = (
round(cursor.fetchone()[0], 2) if stats["total_entries"] > 0 else 0
)
Expand All @@ -662,12 +648,10 @@ def get_statistics(self) -> dict[str, Any]:
stats["active_suggestions"] = cursor.fetchone()[0]

# Recent activity
cursor.execute(
"""
cursor.execute("""
SELECT COUNT(*) FROM memory_entries
WHERE timestamp > datetime('now', '-7 days')
"""
)
""")
stats["recent_activity"] = cursor.fetchone()[0]

return stats
Expand Down
18 changes: 6 additions & 12 deletions cortex/first_run_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ def _step_welcome(self) -> StepResult:
self._clear_screen()
self._print_banner()

print(
"""
print("""
Welcome to Cortex Linux! 🚀

Cortex is an AI-powered package manager that understands natural language.
Expand All @@ -249,8 +248,7 @@ def _step_welcome(self) -> StepResult:
$ cortex remove unused packages

This wizard will help you set up Cortex in just a few minutes.
"""
)
""")

if self.interactive:
response = self._prompt("Press Enter to continue (or 'q' to quit): ")
Expand All @@ -264,16 +262,14 @@ def _step_api_setup(self) -> StepResult:
self._clear_screen()
self._print_header("Step 1: API Configuration")

print(
"""
print("""
Cortex uses AI to understand your commands. You can use:

1. Claude API (Anthropic) - Recommended
2. OpenAI API
3. Local LLM (Ollama) - Free, runs on your machine
4. Skip for now (limited functionality)
"""
)
""")

# Check for existing API keys
existing_claude = os.environ.get("ANTHROPIC_API_KEY")
Expand Down Expand Up @@ -708,8 +704,7 @@ def _step_complete(self) -> StepResult:
# Save all config
self.save_config()

print(
"""
print("""
Cortex is ready to use! Here are some things to try:

📦 Install packages:
Expand All @@ -729,8 +724,7 @@ def _step_complete(self) -> StepResult:
📖 Get help:
cortex help

"""
)
""")

# Show configuration summary
print("Configuration Summary:")
Expand Down
12 changes: 4 additions & 8 deletions cortex/graceful_degradation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def _init_db(self):
"""Initialize the cache database."""
self._pool = get_connection_pool(str(self.db_path), pool_size=5)
with self._pool.get_connection() as conn:
conn.execute(
"""
conn.execute("""
CREATE TABLE IF NOT EXISTS response_cache (
query_hash TEXT PRIMARY KEY,
query TEXT NOT NULL,
Expand All @@ -91,14 +90,11 @@ def _init_db(self):
hit_count INTEGER DEFAULT 0,
last_used TIMESTAMP
)
"""
)
conn.execute(
"""
""")
conn.execute("""
CREATE INDEX IF NOT EXISTS idx_last_used
ON response_cache(last_used)
"""
)
""")
conn.commit()

def _hash_query(self, query: str) -> str:
Expand Down
Loading