diff --git a/docs/agents.md b/docs/agents.md index 25122c6..d48c781 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -18,7 +18,7 @@ brackets indicate optional arguments. All CLI processes run in `WORKDIR`. | `copilot` | The adapter identifies the npm package as `@github/copilot`; install and authentication commands are unverified. `copilot [--model MODEL] --output-format json --allow-all-tools` (prompt on stdin). Tools, including writes, are auto-approved: read-only behavior relies on review instructions, not a sandbox. | | `droid` | Install command unverified. Set `FACTORY_API_KEY` for noninteractive use. `droid exec [-m MODEL] --output-format json --cwd WORKDIR -- PROMPT`. Droid defaults to read-only; a full authenticated secfoo run was not verified in the adapter. | | `devin` | The adapter identifies the official Homebrew cask as `devin-cli`; install command unverified. Authenticate beforehand with `devin auth login`; credential reuse for headless runs is unverified. `devin -p PROMPT --respect-workspace-trust false --permission-mode auto`. The combined command and an authenticated end-to-end run are unverified; `auto` is documented by the CLI as approving read-only tools. | -| `api` | No agent binary is invoked. If dependencies are missing, run `pip install "secfoo[api]"`. Set `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GEMINI_API_KEY`. Source files are included in the API prompt. Model selection uses the configured model, then `SECFOO_API_MODEL`, then `openai/gpt-4.1-mini`. | +| `api` | No agent binary is invoked. `litellm` and `langgraph` are installed with secfoo; if importing them fails, reinstall secfoo the way you installed it (`pipx reinstall secfoo` or `pip install --force-reinstall secfoo`). Set `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GEMINI_API_KEY`. Source files are included in the API prompt. Model selection uses the configured model, then `SECFOO_API_MODEL`, then `openai/gpt-4.1-mini`. | `agy` and `devin` do not support adapter model selection; secfoo warns and ignores a requested model. Other CLI model flags are shown above. @@ -44,8 +44,8 @@ ignores a requested model. Other CLI model flags are shown above. try another agent if it remains unreliable. Claude can put an error reason in stdout JSON even when stderr is empty; secfoo extracts it. - API `not_configured`: `No API key set. Set one of: OPENAI_API_KEY, - ANTHROPIC_API_KEY, GEMINI_API_KEY`. Missing LiteLLM/LangGraph dependencies - produce `failed` with the install command above. + ANTHROPIC_API_KEY, GEMINI_API_KEY`. If LiteLLM or LangGraph cannot be imported, + the run is `failed` and the error says to reinstall secfoo. For a run failure, see `~/.secfoo/reports//stderr.log`; see [Reporting bugs](../CONTRIBUTING.md#reporting-bugs) for what to include diff --git a/pyproject.toml b/pyproject.toml index d76fa48..6045df8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,10 +69,9 @@ dependencies = [ [project.optional-dependencies] dev = ["jsonschema>=4.26.0", "pytest>=9.2.0", "pytest-cov>=7.1.0", "hypothesis>=6.168.5", "httpx>=0.28.1", "ruff>=0.17.5", "bandit>=1.9.4", "pip-audit>=2.10.1", "langgraph>=1.2.21"] build = ["pyinstaller>=6.22.3"] -# The `api` agent (secfoo/agents/api.py): a LangGraph workflow that calls OpenAI/Anthropic/Gemini -# through LiteLLM with an API key instead of driving an installed agent CLI. -# (dev includes langgraph so the real graph runs in tests; litellm is faked.) -api = ["litellm>=1.109.1", "langgraph>=1.2.21"] +# The `api` agent (secfoo/agents/api.py) needs litellm and langgraph, which are regular +# dependencies above, so there is no separate `api` extra to install. +# (dev lists langgraph too so the real graph runs in tests; litellm is faked.) [project.urls] Homepage = "https://secfoo.com" diff --git a/src/secfoo/agents/api.py b/src/secfoo/agents/api.py index ddae6ab..4ac27ae 100644 --- a/src/secfoo/agents/api.py +++ b/src/secfoo/agents/api.py @@ -322,9 +322,17 @@ def run(self, prompt: str, *, workdir: Path, timeout: int | None = None, prev_co try: import litellm from langgraph.graph import END, START, StateGraph - except ImportError: + except ImportError as exc: + # litellm and langgraph are regular dependencies of secfoo, so a failed + # import means a broken or partial install, not a missing extra. return self._result( - "failed", started, stderr='litellm/langgraph are not installed. Run: pip install "secfoo[api]"' + "failed", + started, + stderr=( + f"litellm/langgraph could not be imported ({exc}). Both are installed with secfoo, " + "so reinstall it the way you installed it: pipx reinstall secfoo, " + "or pip install --force-reinstall secfoo" + ), ) try: final = build_graph(litellm, StateGraph, START, END).invoke({ diff --git a/tests/test_agents/test_api.py b/tests/test_agents/test_api.py index acaa786..7cca3d3 100644 --- a/tests/test_agents/test_api.py +++ b/tests/test_agents/test_api.py @@ -234,14 +234,19 @@ def test_run_strips_a_trailing_newline_from_the_key(tmp_path, monkeypatch): assert api.os.environ["OPENAI_API_KEY"] == "sk-test" -def test_run_without_litellm_installed_says_how_to_install_it(tmp_path, monkeypatch): +def test_run_without_litellm_installed_says_to_reinstall_secfoo(tmp_path, monkeypatch): monkeypatch.setenv("OPENAI_API_KEY", "sk-test") monkeypatch.setitem(sys.modules, "litellm", None) # makes `import litellm` raise ImportError result = ApiAdapter().run("prompt", workdir=tmp_path) assert result.status == "failed" - assert "secfoo[api]" in result.stderr + # litellm/langgraph are base dependencies; there is no `secfoo[api]` extra to point at. + assert "secfoo[api]" not in result.stderr + assert "litellm" in result.stderr + # README's first install channel is pipx, where `pip install` would hit the wrong environment. + assert "pipx reinstall secfoo" in result.stderr + assert "pip install --force-reinstall secfoo" in result.stderr def test_incomplete_report_is_reformatted_once_without_resending_source(tmp_path, monkeypatch): diff --git a/tests/test_docs_consistency.py b/tests/test_docs_consistency.py index e7256ce..4a7247f 100644 --- a/tests/test_docs_consistency.py +++ b/tests/test_docs_consistency.py @@ -55,3 +55,23 @@ def test_the_on_block_parser_sees_triggers_after_a_blank_line() -> None: assert _has_push_trigger(_top_level_on_block('"on": [push, workflow_dispatch]\njobs: {}\n')) commented = "on:\n workflow_dispatch:\n\n# the GHCR push needs packages: write\njobs: {}\n" assert not _has_push_trigger(_top_level_on_block(commented)) + + +def test_no_obsolete_api_extra() -> None: + """litellm and langgraph are base dependencies, so `secfoo[api]` must not come back.""" + try: + import tomllib + except ModuleNotFoundError: # Python 3.10 + import tomli as tomllib + + project = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["project"] + assert "api" not in project.get("optional-dependencies", {}) + base = {re.split(r"[\s<>=!~;\[]", dep, maxsplit=1)[0].lower() for dep in project["dependencies"]} + assert {"litellm", "langgraph"} <= base + + files = [ROOT / "README.md", ROOT / "CONTRIBUTING.md", ROOT / "action.yml", ROOT / "Dockerfile", + *sorted((ROOT / "docs").rglob("*.md")), *sorted((ROOT / "src").rglob("*.py")), + *sorted((ROOT / "npm").rglob("*.md")), *sorted((ROOT / "examples").rglob("*.yml"))] + files = [path for path in files if path.is_file()] + offenders = [str(path.relative_to(ROOT)) for path in files if "secfoo[api]" in path.read_text(encoding="utf-8")] + assert offenders == []