This guide covers local development setup, debugging, contributing code, and running tests for BugTraceAI-CLI.
- Python 3.10+
- Docker (for GoSpider, SQLMap, Nuclei integration)
- Git
# Clone repository
git clone https://github.com/BugTraceAI/BugTraceAI-CLI.git
cd BugTraceAI-CLI
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies (dev mode)
pip install -e ".[dev]"
pip install pytest pytest-asyncio pytest-cov black isort flake8
# Install Playwright browsers
playwright install chromium
# Copy env template and configure
cp .env.example .env
# Edit .env and add your OPENROUTER_API_KEY
nano .envVerify setup:
python -m bugtrace --help
python3 -c "from bugtrace import __version__; print(f'✓ Version: {__version__}')"Recommended Extensions:
ms-python.python # Python
ms-python.vscode-pylance # Type checking
ms-python.black-formatter # Code formatting
charliermarsh.ruff # Linting
eamodio.gitlens # Git history
Workspace Settings (.vscode/settings.json):
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.formatting.provider": "black",
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}Format code (Black):
black bugtrace tests --line-length 120Sort imports (isort):
isort bugtrace testsLint (Flake8):
flake8 bugtrace --max-line-length=120 --ignore=E501,W503All-in-one (recommended):
black bugtrace tests && isort bugtrace tests && flake8 bugtrace# Activate venv
source .venv/bin/activate
# Scan a target (hunter phase only)
python -m bugtrace scan https://example.com
# Full scan (hunter + auditor)
python -m bugtrace full https://example.com
# XSS-focused mode
python -m bugtrace scan https://example.com --xss
# With URL list
python -m bugtrace scan --url-list-file urls.txt
# Resume previous scan
python -m bugtrace scan https://example.com --resume
# Clean previous state and restart
python -m bugtrace scan https://example.com --clean# Start API on http://localhost:8000
python -m bugtrace serve --host 127.0.0.1 --port 8000
# Auto-reload on code changes (development)
python -m bugtrace serve --reload
# Bind to all interfaces (LAN access)
python -m bugtrace serve --host 0.0.0.0 --port 8000
# Access SwaggerUI
open http://localhost:8000/docs
# Access ReDoc
open http://localhost:8000/redoc# STDIO transport (local Claude/Cursor only)
python -m bugtrace mcp
# SSE transport (remote AI clients, network access)
python -m bugtrace mcp --sse --host 0.0.0.0 --port 8001# Launch TUI without target
python -m bugtrace tui
# Launch TUI and start scanning
python -m bugtrace tui https://example.com
# Demo mode (animated fake data for testing UI)
python -m bugtrace tui --demo# Set DEBUG=true in .env or export
export BUGTRACE_DEBUG=1
python -m bugtrace scan https://example.com
# Or modify .env
echo "DEBUG=true" >> .env# CLI logs
tail -f logs/cli.log
# API logs
tail -f logs/api.log
# All agent activity
tail -f logs/agents.log
# Database operations
tail -f logs/database.logAdd breakpoint in code:
# In bugtrace/agents/xss_agent.py
def analyze_url(self, url):
breakpoint() # Execution will pause here
# ... rest of functionRun with debugger:
python -m bugtrace scan https://example.com
# At breakpoint, use:
# n (next line)
# s (step into)
# c (continue)
# p variable_name (print)
# l (list code)# Connect to SQLite database
sqlite3 bugtrace.db
# List tables
.tables
# Inspect scans
SELECT id, status, target, created_at FROM scan ORDER BY id DESC LIMIT 5;
# View findings for a scan
SELECT scan_id, url, vuln_type, severity FROM finding WHERE scan_id=1;
# Export findings as CSV
.mode csv
.output findings.csv
SELECT * FROM finding;
.quit# Monitor real-time events via WebSocket
wscat -c ws://localhost:8000/ws/global
# Test specific endpoint with curl
curl -X POST http://localhost:8000/api/scans \
-H "Content-Type: application/json" \
-d '{"target_url":"https://example.com"}' | jq .
# Check API health
curl http://localhost:8000/health | jq .
# Get scan status
curl http://localhost:8000/api/scans/1/status | jq .# All tests
pytest tests/ -v
# Specific test file
pytest tests/test_bugtrace_sanity.py -v
# Specific test function
pytest tests/test_xss_agent.py::TestXSSAgent::test_payload_execution -v
# With coverage report
pytest tests/ --cov=bugtrace --cov-report=html
# Fast tests only (skip integration)
pytest tests/ -m "not integration" -v
# Test a specific agent
pytest tests/ -k "xss" -vUnit tests (fast, no external deps):
pytest tests/unit/ -vIntegration tests (require Docker, full setup):
pytest tests/integration/ -vAgent-specific smoke tests:
pytest tests/test_integration_new_agents.py -vTemplate for agent tests:
# tests/test_my_agent.py
import pytest
from bugtrace.agents.my_agent import MyAgent
from bugtrace.services.event_bus import ServiceEventBus
@pytest.fixture
def agent():
event_bus = ServiceEventBus()
return MyAgent(event_bus=event_bus)
def test_agent_initialization(agent):
assert agent.name == "MyAgent"
assert agent.event_bus is not None
@pytest.mark.asyncio
async def test_agent_analyze(agent):
result = await agent.analyze(url="https://example.com", param="test")
assert result is not NoneRun your new test:
pytest tests/test_my_agent.py -v# Update main
git checkout main
git pull origin main
# Create feature branch
git checkout -b feature/my-feature
# Make changes and commit
git add bugtrace/agents/my_agent.py
git commit -m "feat(agents): add MyAgent for new vulnerability type"
# Push and create PR
git push origin feature/my-featureFormat: <type>(<scope>): <subject>
Types:
feat:New feature or agentfix:Bug fixrefactor:Code restructuring (no functional change)docs:Documentationtest:New testschore:Dependencies, CI/CD setup
Examples:
feat(agents): add JWTAgent for JWT vulnerabilities
fix(api): handle concurrent scan limit correctly
refactor(core): improve queue performance
docs(setup): add local development guide
test(xss): add edge case payloads
Before submitting PR:
- Code passes linting:
black bugtrace && isort bugtrace && flake8 bugtrace - Tests pass:
pytest tests/ -q - New code is tested (add corresponding test file)
- Commit messages follow format
- README/DEVELOPMENT.md updated if needed
- No API keys or secrets in commits (use .env)
# Clear Python cache
find . -type d -name __pycache__ -exec rm -r {} + 2>/dev/null
find . -type f -name "*.pyc" -delete
# Reinstall in dev mode
pip install -e .# Reinstall Playwright
python -m pip uninstall playwright
playwright install chromium
playwright install-deps chromium# Find process on port 8000
lsof -i :8000
# Kill the process
kill -9 <PID>
# Or use different port
python -m bugtrace serve --port 8001# Remove stale database
rm bugtrace.db bugtrace.db-shm bugtrace.db-wal
# Restart
python -m bugtrace scan https://example.comCheck for parallelization:
# In bugtrace/core/config.py
WORKER_POOL_DEFAULT_SIZE: int = 5 # Increase for more parallelism
MAX_CONCURRENT_SPECIALISTS: int = 10 # Adjust concurrencyProfile execution:
python -m cProfile -s cumtime -m bugtrace scan https://example.com 2>&1 | head -20# Verify API key
python -c "from bugtrace.core.config import settings; \
print(f'Provider: {settings.PROVIDER}'); \
print(f'API Key set: {bool(settings.OPENROUTER_API_KEY)}')"
# Test connectivity
python -c "from bugtrace.core.llm_client import llm_client; \
import asyncio; \
asyncio.run(llm_client.verify_connectivity())"- API Docs: http://localhost:8000/docs (when API running)
- OpenAPI Spec: openapi.yaml
- Configuration: bugtrace/core/config.py
- Architecture: BugTraceAI/README.md
- Issues: GitHub Issues
- Check existing issues: https://github.com/BugTraceAI/BugTraceAI-CLI/issues
- Review logs:
tail -f logs/*.log - Test setup:
python -m pytest tests/test_bugtrace_sanity.py -v
Happy hacking! 🔓