Skip to content
Open
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
85 changes: 4 additions & 81 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,83 +1,6 @@
# ───────────────────────────────────────────
# Python
# ───────────────────────────────────────────
__pycache__/
*.py[cod]
*$py.class
*.pyc
*.pyo
*.pyd
.Python
.venv/
venv/
env/
ENV/
*.egg
*.egg-info/
dist/
build/
.eggs/
pip-wheel-metadata/
.mypy_cache/
.ruff_cache/
.pytest_cache/
htmlcov/
.coverage
.coverage.*
coverage.xml
*.cover

# ───────────────────────────────────────────
# Node / Frontend
# ───────────────────────────────────────────
node_modules/
dist/
.next/
out/
.vite/
*.local

# ───────────────────────────────────────────
# Environment & secrets
# ───────────────────────────────────────────
.env
.env.*
!.env.example
*.pem
*.key
*.p12

# ───────────────────────────────────────────
# ML model artifacts
# ───────────────────────────────────────────
*.pkl
*.pt
*.pth
*.onnx
*.safetensors
*.bin
backend/app/ml/models/

# ───────────────────────────────────────────
# PatchPilot runtime artifacts
# ───────────────────────────────────────────
backend/jobs/
backend/*.db
backend/*.sqlite
backend/*.sqlite3

# ───────────────────────────────────────────
# OS & editor
# ───────────────────────────────────────────
.DS_Store
Thumbs.db
.idea/
.vscode/
*.swp
*.swo
*~

# ───────────────────────────────────────────
# Logs
# ───────────────────────────────────────────
*.log
logs/
pytest.ini
*.notepad
*.pychache
45 changes: 45 additions & 0 deletions backend/app/remediation/patch_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Patch generation for remediation engine."""

import difflib
from pathlib import Path
from typing import Optional


class PatchGenerator:
"""Generate unified diff patches for security remediations."""

def __init__(self, repo_dir: Path):
self.repo_dir = repo_dir

def generate_dependency_patch(
self,
package_name: str,
current_version: str,
fixed_version: str,
) -> Optional[str]:
manifest_path = self.repo_dir / "requirements.txt"
if not manifest_path.exists():
return None

original_content = manifest_path.read_text()
new_content = original_content.replace(current_version, fixed_version)

if new_content == original_content:
return None

return self._generate_unified_diff(manifest_path, original_content, new_content)

def _generate_unified_diff(self, file_path: Path, original: str, new: str) -> str:
original_lines = original.splitlines(keepends=True)
new_lines = new.splitlines(keepends=True)

diff = difflib.unified_diff(
original_lines,
new_lines,
fromfile=f"a/{file_path}",
tofile=f"b/{file_path}",
)
return "".join(diff)

def supports_patch(self, finding_id: str) -> bool:
return finding_id.startswith("osv:")
Loading