How satty-br/loki works
Project type and purpose
• LOKI is a Python CLI tool whose purpose is to automatically inject realistic security vulnerabilities into target repos and open a PR on GitHub.
• It leverages an LLM (OpenAI or local) plus GitHub APIs to analyze, plan, inject, and push changes.
File structure
• Only five top-level files: .gitignore, LICENSE, README.md, main.py, requirements.txt.
• All core logic lives in main.py.
• Dependencies listed in requirements include GitPython, PyYAML, GitHub API client, OpenAI SDK or another LLM client.
Key components
a. CLI & Config Parser
• Parses command-line args (--llm-endpoint, --model-name, --github-token, etc.).
b. Repository Manager
• Clones target repo into clone_dir using GitPython.
c. Static & Dependency Analyzer
• Scans files, languages, dependency manifests (requirements.txt, package.json, etc.).
d. Vulnerability Planner (AI Module)
• Sends repo context to LLM endpoint; receives a plan of what vulnerabilities to inject.
e. Injection Engine
• Applies code changes (e.g., hardcoded secrets, unsafe evals) and updates dependency versions.
f. Git Commit & Brancher
• Creates a new branch, stages and commits injected changes.
g. Pull Request Creator
• Uses GitHub API client to push branch and open a PR with descriptive details.
h. Temporary Storage
• Local filesystem path (./temp_repo) holds the cloned repo and modified files.
i. External Services
• LLM Endpoint (OpenAI or local)
• GitHub API
Architectural patterns & design principles
• Modular monolith: Single script logically separated into distinct components.
• Command-Query Separation: Analysis/planning is separate from injection/commit steps.
• Externalization of AI: LLM is a remote service, decoupled via endpoint interface.
• Ephemeral state: All repo changes occur in a transient temp_repo.