Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

feat: github modules

tanayvaswanie86bacf93a49
diff --git a/deepteam/code_scanner/__init__.py b/deepteam/code_scanner/__init__.py
index d035d4e4..9f6bea8f 100644
--- a/deepteam/code_scanner/__init__.py
+++ b/deepteam/code_scanner/__init__.py
@@ -23,7 +23,7 @@ from .engines import (
resolve_provider,
)
from .collect import collect_files, collect_changed_files
-from .github_report import post_pr_comments
+from .github import post_pr_comments
from .config import (
CONFIG_FILENAMES,
CodeScanConfig,
diff --git a/deepteam/code_scanner/engines/base.py b/deepteam/code_scanner/engines/base.py
index 39058cbc..703676e0 100644
--- a/deepteam/code_scanner/engines/base.py
+++ b/deepteam/code_scanner/engines/base.py
@@ -1,21 +1,9 @@
-"""
-Base types and shared helpers for code-scan engines.
-
-An engine turns a scan prompt into a CodeFindingsList. The default is deepeval's
-own judge (represented by a `None` engine in CodeScanner); the optional harness
-engines (Codex, Claude, Cursor) live in sibling modules and delegate to that
-vendor's SDK using its API key. Each SDK is imported lazily so a bare
-`pip install deepteam` never requires any of them.
-"""
-
import json
import re
from typing import Optional, Protocol
from ..schema import CodeFindingsList
-# Harness providers that delegate scanning to an agentic SDK. "deepeval" is the
-# built-in (non-harness) judge and is represented by a `None` engine.
HARNESS_PROVIDERS = ("codex", "claude", "cursor")
PROVIDERS = ("deepeval",) + HARNESS_PROVIDERS
@@ -35,9 +23,7 @@ ENV_KEY = {
"cursor": "CURSOR_API_KEY",
}
-# Appended to the scan prompt for harness engines, which (unlike deepeval's
-# native structured output) return free-form text. Constrains the agent to the
-# inline code and to a single JSON object we can parse into CodeFindingsList.
+
OUTPUT_FORMAT_INSTRUCTION = """
Analyze ONLY the code provided above. Do not access the filesystem, run \
@@ -67,7 +53,9 @@ If there are no vulnerabilities, respond with {"findings": []}.
class ScanEngine(Protocol):
- """Turns a scan prompt into a CodeFindingsList."""
+ """
+ Turns a scan prompt into a CodeFindingsList.
+ """
def generate_findings(self, prompt: str) -> CodeFindingsList: ...
@@ -84,7 +72,9 @@ def missing_sdk(provider: str) -> ImportError:
def extract_findings(text: Optional[str]) -> CodeFindingsList:
- """Parse a harness's free-form text answer into CodeFindingsList."""
+ """
+ Parse a harness's free-form text answer into CodeFindingsList.
+ """
if not text or not text.strip():
return CodeFindingsList(findings=[])
diff --git a/deepteam/code_scanner/engines/claude.py b/deepteam/code_scanner/engines/claude.py
index 3f42e991..781c1db4 100644
--- a/deepteam/code_scanner/engines/claude.py
+++ b/deepteam/code_scanner/engines/claude.py
@@ -1,5 +1,3 @@
-"""Claude scan engine (uses ANTHROPIC_API_KEY). Requires the claude-agent-sdk."""
-
import asyncio
import importlib.util
from typing import Optional
@@ -9,7 +7,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdk
class ClaudeAgentEngine:
- """Delegates scanning to the Claude Agent SDK (uses ANTHROPIC_API_KEY)."""
+ """
+ Delegates scanning to the Claude Agent SDK (uses ANTHROPIC_API_KEY).
+ """
def __init__(self, model: Optional[str] = None):
if importlib.util.find_spec("claude_agent_sdk") is None:
@@ -19,7 +19,6 @@ class ClaudeAgentEngine:
async def a_generate_findings(self, prompt: str) -> CodeFindingsList:
from claude_agent_sdk import query, ClaudeAgentOptions
- # No tools: the code is inline in the prompt, so the agent only answers.
options_kwargs = {"allowed_tools": []}
if self.model:
options_kwargs["model"] = self.model
diff --git a/deepteam/code_scanner/engines/codex.py b/deepteam/code_scanner/engines/codex.py
index 30c0146b..bd878cdc 100644
--- a/deepteam/code_scanner/engines/codex.py
+++ b/deepteam/code_scanner/engines/codex.py
@@ -1,5 +1,3 @@
-"""Codex scan engine (uses OPENAI_API_KEY). Requires the openai-codex SDK."""
-
import importlib.util
from typing import Optional
@@ -8,7 +6,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdk
class CodexEngine:
- """Delegates scanning to the Codex SDK (uses OPENAI_API_KEY)."""
+ """
+ Delegates scanning to the Codex SDK (uses OPENAI_API_KEY).
+ """
def __init__(self, model: Optional[str] = None):
if importlib.util.find_spec("openai_codex") is None:
diff --git a/deepteam/code_scanner/engines/cursor.py b/deepteam/code_scanner/engines/cursor.py
index 0f92bf0d..66b853e4 100644
--- a/deepteam/code_scanner/engines/cursor.py
+++ b/deepteam/code_scanner/engines/cursor.py
@@ -1,5 +1,3 @@
-"""Cursor scan engine (uses CURSOR_API_KEY). Requires the cursor-sdk."""
-
import asyncio
import importlib.util
import os
@@ -10,7 +8,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdk
class CursorEngine:
- """Delegates scanning to the Cursor SDK (uses CURSOR_API_KEY)."""
+ """
+ Delegates scanning to the Cursor SDK (uses CURSOR_API_KEY).
+ """
def __init__(self, model: Optional[str] = None):
if importlib.util.find_spec("cursor_sdk") is None:
@@ -20,8 +20,6 @@ class CursorEngine:
def generate_findings(self, prompt: str) -> CodeFindingsList:
from cursor_sdk import Agent
- # Cursor exposes no read-only sandbox; we pass code inline and never ask
- # it to edit, so it has no reason to touch the filesystem.
options = {"local": {"cwd": os.getcwd()}}
if self.model:
options["model"] = self.model
diff --git a/deepteam/code_scanner/github/__init__.py b/deepteam/code_scanner/github/__init__.py
new file mode 100644
index 00000000..ed8c52bc
--- /dev/null
+++ b/deepteam/code_scanner/github/__init__.py
@@ -0,0 +1,5 @@
+"""GitHub integration for code scanning (PR comments via deepteam[bot])."""
+
+from .report import post_pr_comments
+
+__all__ = ["post_pr_comments"]
diff --git a/deepteam/code_scanner/github_report.py b/deepteam/code_scanner/github/report.py
similarity index 94%
rename from deepteam/code_scanner/github_report.py
rename to deepteam/code_scanner/github/report.py
index 914d45a8..505076b1 100644
--- a/deepteam/code_scanner/github_report.py
+++ b/deepteam/code_scanner/github/report.py
@@ -5,7 +5,7 @@ from typing import List, Optional
import requests
from deepeval.confident.api import get_base_api_url
-from .schema import CodeFinding
+from ..schema import CodeFinding
PR_COMMENTS_ENDPOINT = "/v1/github-app/code-scan/comments"
_OIDC_AUDIENCE = "confident-code-scan"
@@ -85,7 +85,10 @@ def post_pr_comments(
"repo": repo,
"pr": pr_number,
"oidc": oidc,
- "findings": [f.model_dump(exclude_none=True) for f in findings],
+ "findings": [
+ finding.model_dump(exclude_none=True)
+ for finding in findings
+ ],
}
resp = requests.post(
f"{base}{PR_COMMENTS_ENDPOINT}", json=payload, timeout=30
diff --git a/tests/test_core/test_code_scanner/test_github_report.py b/tests/test_core/test_code_scanner/test_github_report.py
index 6be8a65b..ebea3472 100644
--- a/tests/test_core/test_code_scanner/test_github_report.py
+++ b/tests/test_core/test_code_scanner/test_github_report.py
@@ -2,7 +2,7 @@ import json
import pytest
-import deepteam.code_scanner.github_report as gr
+import deepteam.code_scanner.github.report as gr
from deepteam.code_scanner import CodeFinding