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__.pyindex 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_commentsfrom .config import (CONFIG_FILENAMES,CodeScanConfig,diff --git a/deepteam/code_scanner/engines/base.py b/deepteam/code_scanner/engines/base.pyindex 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 jsonimport refrom typing import Optional, Protocolfrom ..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.pyindex 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 asyncioimport importlib.utilfrom typing import Optional@@ -9,7 +7,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdkclass 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.modeldiff --git a/deepteam/code_scanner/engines/codex.py b/deepteam/code_scanner/engines/codex.pyindex 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.utilfrom typing import Optional@@ -8,7 +6,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdkclass 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.pyindex 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 asyncioimport importlib.utilimport os@@ -10,7 +8,9 @@ from .base import OUTPUT_FORMAT_INSTRUCTION, extract_findings, missing_sdkclass 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.modeldiff --git a/deepteam/code_scanner/github/__init__.py b/deepteam/code_scanner/github/__init__.pynew file mode 100644index 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.pysimilarity index 94%rename from deepteam/code_scanner/github_report.pyrename to deepteam/code_scanner/github/report.pyindex 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, Optionalimport requestsfrom deepeval.confident.api import get_base_api_url-from .schema import CodeFinding+from ..schema import CodeFindingPR_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=30diff --git a/tests/test_core/test_code_scanner/test_github_report.py b/tests/test_core/test_code_scanner/test_github_report.pyindex 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 jsonimport pytest-import deepteam.code_scanner.github_report as gr+import deepteam.code_scanner.github.report as grfrom deepteam.code_scanner import CodeFinding