diff --git a/README.md b/README.md index 6768cb9..bd36b95 100644 --- a/README.md +++ b/README.md @@ -69,14 +69,10 @@ secfoo run --skill sast --agent api --target https://github.com/org/repo It suits small and medium repositories: the whole target has to fit in one request, and larger ones are rejected with a message suggesting `--exclude`. -(`--agent secfoo` is a minimal variant of the same LiteLLM path that sends -only the rendered prompt, without the target's source files, and reads -`SECFOO_MODEL` instead. Prefer `api` unless you have a reason not to.) - ### Tracking AI spend Every run records tokens and cost where the agent reports them (`api`, -`secfoo`, `claude`; `gemini` reports tokens only; `agent` and `agy` report +`claude`; `gemini` reports tokens only; `agent` and `agy` report neither and show as unpriced rather than $0). See it per run in `secfoo run`, `secfoo list`, the dashboard and the enterprise portal, or summarised: diff --git a/src/secfoo/agents/__init__.py b/src/secfoo/agents/__init__.py index 78f5203..0bf63df 100644 --- a/src/secfoo/agents/__init__.py +++ b/src/secfoo/agents/__init__.py @@ -1,5 +1,4 @@ from secfoo.agents.base import AgentAdapter, AgentResult from secfoo.agents.registry import ADAPTERS, get_adapter -from secfoo.agents.secfoo import SecFooAdapter -__all__ = ["AgentAdapter", "AgentResult", "SecFooAdapter", "ADAPTERS", "get_adapter"] +__all__ = ["AgentAdapter", "AgentResult", "ADAPTERS", "get_adapter"] diff --git a/src/secfoo/agents/registry.py b/src/secfoo/agents/registry.py index b759aa8..e1fddf3 100644 --- a/src/secfoo/agents/registry.py +++ b/src/secfoo/agents/registry.py @@ -8,7 +8,6 @@ from secfoo.agents.codex import CodexAdapter from secfoo.agents.cursor import CursorAdapter from secfoo.agents.gemini import GeminiAdapter -from secfoo.agents.secfoo import SecFooAdapter ADAPTERS: dict[str, type[AgentAdapter]] = { ClaudeAdapter.name: ClaudeAdapter, @@ -17,7 +16,6 @@ GeminiAdapter.name: GeminiAdapter, CopilotAdapter.name: CopilotAdapter, ApiAdapter.name: ApiAdapter, - SecFooAdapter.name: SecFooAdapter, CodexAdapter.name: CodexAdapter, } diff --git a/src/secfoo/agents/secfoo.py b/src/secfoo/agents/secfoo.py deleted file mode 100644 index 0c280d1..0000000 --- a/src/secfoo/agents/secfoo.py +++ /dev/null @@ -1,89 +0,0 @@ -"""The built-in LangGraph agent, with LiteLLM as its only model gateway.""" - -from __future__ import annotations - -import os -import time -from pathlib import Path -from typing import TypedDict - -from secfoo.agents.base import AgentAdapter, AgentResult - - -class _State(TypedDict): - prompt: str - report: str - cost_usd: float | None - - -def _cost(response: object) -> float | None: - try: - from litellm import completion_cost - - value = completion_cost(completion_response=response) - return float(value) if value is not None else None - except Exception: - return None - - -class SecFooAdapter(AgentAdapter): - name = "secfoo" - binary = "secfoo-agent" - default_timeout_seconds = 1800 - - def is_available(self) -> bool: - return bool( - os.getenv("OPENAI_API_KEY") - or os.getenv("ANTHROPIC_API_KEY") - or os.getenv("GEMINI_API_KEY") - ) - - def build_command(self, prompt: str, *, workdir: Path) -> list[str]: - raise NotImplementedError("the built-in agent runs in-process") - - def run(self, prompt: str, *, workdir: Path, timeout: int | None = None) -> AgentResult: - started = time.monotonic() - try: - from langgraph.graph import END, START, StateGraph - from litellm import completion - - model = os.getenv("SECFOO_MODEL", "openai/gpt-4o-mini") - effective_timeout = timeout or self.default_timeout_seconds - - def call_model(state: _State) -> _State: - response = completion( - model=model, - messages=[{"role": "user", "content": state["prompt"]}], - timeout=effective_timeout, - ) - content = response.choices[0].message.content or "" - return {"prompt": state["prompt"], "report": content, "cost_usd": _cost(response)} - - graph = StateGraph(_State) - graph.add_node("security_assessment", call_model) - graph.add_edge(START, "security_assessment") - graph.add_edge("security_assessment", END) - result = graph.compile().invoke({"prompt": prompt, "report": "", "cost_usd": None}) - report = result["report"] - return AgentResult( - agent=self.name, - exit_code=0, - stdout=report, - stderr="", - duration_seconds=time.monotonic() - started, - timed_out=False, - status="success", - raw_report=report, - cost_usd=result["cost_usd"], - ) - except Exception as exc: - return AgentResult( - agent=self.name, - exit_code=1, - stdout="", - stderr=str(exc), - duration_seconds=time.monotonic() - started, - timed_out=False, - status="failed", - raw_report="", - ) \ No newline at end of file diff --git a/src/secfoo/cli.py b/src/secfoo/cli.py index b3c0226..fcde912 100644 --- a/src/secfoo/cli.py +++ b/src/secfoo/cli.py @@ -97,7 +97,6 @@ class AgentId(str, Enum): GEMINI = "gemini" COPILOT = "copilot" API = "api" - SECFOO = "secfoo" CODEX = "codex" diff --git a/src/secfoo/config.example.toml b/src/secfoo/config.example.toml index 05315cd..10aef89 100644 --- a/src/secfoo/config.example.toml +++ b/src/secfoo/config.example.toml @@ -6,7 +6,7 @@ # Used whenever --agent / --depth / --timeout aren't passed on the command # line. CLI flags always win over these. # Agent CLIs: claude | agent (Cursor) | agy (Antigravity) | gemini | codex | copilot -# API-key agents (no CLI): api | secfoo +# API-key agent (no CLI): api agent = "claude" depth = "quick" # quick | standard # timeout = 1800 # seconds; omit to use each agent's own default diff --git a/tests/test_agents/test_secfoo.py b/tests/test_agents/test_secfoo.py deleted file mode 100644 index a5400de..0000000 --- a/tests/test_agents/test_secfoo.py +++ /dev/null @@ -1,74 +0,0 @@ -from __future__ import annotations - -import sys -import types - -from secfoo.agents.secfoo import SecFooAdapter - - -class _Response: - class _Choice: - class _Message: - content = "# Security report" - - message = _Message() - - choices = [_Choice()] - - -def test_secfoo_agent_uses_langgraph_and_litellm(monkeypatch, tmp_path): - calls = [] - - class _Graph: - def __init__(self, state_type): - self.node = None - - def add_node(self, name, node): - self.node = node - - def add_edge(self, *_args): - return None - - def compile(self): - return self - - def invoke(self, state): - return self.node(state) - - langgraph_graph = types.ModuleType("langgraph.graph") - langgraph_graph.END = "__end__" - langgraph_graph.START = "__start__" - langgraph_graph.StateGraph = _Graph - langgraph = types.ModuleType("langgraph") - langgraph.graph = langgraph_graph - - litellm = types.ModuleType("litellm") - - def completion(**kwargs): - calls.append(kwargs) - return _Response() - - litellm.completion = completion - litellm.completion_cost = lambda completion_response: 0.0123 - monkeypatch.setitem(sys.modules, "langgraph", langgraph) - monkeypatch.setitem(sys.modules, "langgraph.graph", langgraph_graph) - monkeypatch.setitem(sys.modules, "litellm", litellm) - monkeypatch.setenv("OPENAI_API_KEY", "test-key") - monkeypatch.setenv("SECFOO_MODEL", "openai/test-model") - - result = SecFooAdapter().run("review this target", workdir=tmp_path) - - assert result.status == "success" - assert result.raw_report == "# Security report" - assert result.cost_usd == 0.0123 - assert calls == [{ - "model": "openai/test-model", - "messages": [{"role": "user", "content": "review this target"}], - "timeout": 1800, - }] - - -def test_secfoo_agent_requires_provider_key(monkeypatch): - for name in ("OPENAI_API_KEY", "ANTHROPIC_API_KEY", "GEMINI_API_KEY"): - monkeypatch.delenv(name, raising=False) - assert not SecFooAdapter().is_available() diff --git a/tests/test_cli.py b/tests/test_cli.py index fc92acb..acdd913 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -206,7 +206,7 @@ def fake_execute_runs(**kwargs): def test_agents_command_lists_all_adapters(): result = runner.invoke(app, ["agents"]) assert result.exit_code == 0 - for agent_id in ["claude", "agent", "agy", "gemini", "secfoo", "codex"]: + for agent_id in ["claude", "agent", "agy", "gemini", "codex"]: assert agent_id in result.stdout