The agent that turns websites into APIs!
revert: remove cursor_auth helper; rely on exported CURSOR_API_KEY
Cursor Agent5ff9e6eff3a2
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.pyindex 38672ce..e769d9d 100644--- a/src/reverse_api/cli.py+++ b/src/reverse_api/cli.py@@ -255,25 +255,6 @@ def _build_dry_run_payload("status": "error","message": f"unknown sdk {sdk!r}; expected 'claude', 'opencode', 'copilot', or 'cursor'",})- elif sdk == "cursor":- from .cursor_auth import get_cursor_api_key-- if get_cursor_api_key():- checks.append({- "name": f"sdk:{sdk}",- "status": "ok",- "message": "Cursor API key present (CURSOR_API_KEY or CURSOR_API_KEY_FILE)",- })- else:- checks.append({- "name": f"sdk:{sdk}",- "status": "warn",- "message": (- "CURSOR_API_KEY not in process environment and CURSOR_API_KEY_FILE "- "unset/invalid (use `export CURSOR_API_KEY=...` so Python can see it, "- "or set CURSOR_API_KEY_FILE to a file containing the key)"- ),- })elif not os.environ.get(sdk_env_var):checks.append({"name": f"sdk:{sdk}",diff --git a/src/reverse_api/cursor_auth.py b/src/reverse_api/cursor_auth.pydeleted file mode 100644index 7d2657d..0000000--- a/src/reverse_api/cursor_auth.py+++ /dev/null@@ -1,32 +0,0 @@-"""Resolve Cursor API keys for the Node bridge and Python checks."""--from __future__ import annotations--import os-from pathlib import Path---def get_cursor_api_key() -> str:- """Return the Cursor API key from the process environment or a key file.-- Only **exported** shell variables are visible here. If ``echo $CURSOR_API_KEY``- works but this returns empty, use ``export CURSOR_API_KEY=...`` or set- ``CURSOR_API_KEY_FILE`` to a file whose first non-comment line is the key.- """- v = (os.environ.get("CURSOR_API_KEY") or "").strip()- if v:- return v- path = (os.environ.get("CURSOR_API_KEY_FILE") or "").strip()- if not path:- return ""- try:- p = Path(path).expanduser()- if not p.is_file():- return ""- for line in p.read_text(encoding="utf-8", errors="replace").splitlines():- t = line.strip()- if t and not t.startswith("#"):- return t- except OSError:- return ""- return ""diff --git a/src/reverse_api/cursor_engineer.py b/src/reverse_api/cursor_engineer.pyindex bb7b34d..5e4e481 100644--- a/src/reverse_api/cursor_engineer.py+++ b/src/reverse_api/cursor_engineer.py@@ -11,7 +11,6 @@ from pathlib import Pathfrom typing import Anyfrom .base_engineer import BaseEngineer-from .cursor_auth import get_cursor_api_keyfrom .tui import ClaudeUI_BRIDGE_DIR = Path(__file__).resolve().parent / "cursor_bridge"@@ -182,7 +181,7 @@ class CursorEngineer(BaseEngineer):mcp_servers: dict[str, Any] | None,resume_agent_id: str | None,) -> dict[str, Any]:- api_key = get_cursor_api_key()+ api_key = os.environ.get("CURSOR_API_KEY", "")req: dict[str, Any] = {"cwd": self._workspace_cwd(),"modelId": self.cursor_model,@@ -345,18 +344,11 @@ class CursorEngineer(BaseEngineer):self.ui.console.print("\n[dim]Set CURSOR_API_KEY and ensure Node.js 18+ and npm are installed.[/dim]")return None- if not get_cursor_api_key():- msg = "CURSOR_API_KEY is not available to this process"+ if not os.environ.get("CURSOR_API_KEY"):+ msg = "CURSOR_API_KEY is not set"self.ui.error(msg)self.message_store.save_error(msg)- self.ui.console.print("\n[dim]Create a key: https://cursor.com/dashboard/integrations[/dim]")- self.ui.console.print(- "[dim]If `echo $CURSOR_API_KEY` works in your shell but this fails, "- "export it so subprocesses see it:[/dim] [white]export CURSOR_API_KEY='…'[/white]"- )- self.ui.console.print(- "[dim]Or set[/dim] [white]CURSOR_API_KEY_FILE[/white] [dim]to a file whose first line is the key.[/dim]"- )+ self.ui.console.print("\n[dim]Create an API key at https://cursor.com/dashboard/integrations[/dim]")return Nonesystem_prompt, user_message = self._build_prompts()@@ -484,18 +476,11 @@ class CursorAutoEngineer(CursorEngineer):self.message_store.save_error(dep_err)return None- if not get_cursor_api_key():- msg = "CURSOR_API_KEY is not available to this process"+ if not os.environ.get("CURSOR_API_KEY"):+ msg = "CURSOR_API_KEY is not set"self.ui.error(msg)self.message_store.save_error(msg)- self.ui.console.print("\n[dim]Create a key: https://cursor.com/dashboard/integrations[/dim]")- self.ui.console.print(- "[dim]If `echo $CURSOR_API_KEY` works in your shell but this fails, "- "export it so subprocesses see it:[/dim] [white]export CURSOR_API_KEY='…'[/white]"- )- self.ui.console.print(- "[dim]Or set[/dim] [white]CURSOR_API_KEY_FILE[/white] [dim]to a file whose first line is the key.[/dim]"- )+ self.ui.console.print("\n[dim]Create an API key at https://cursor.com/dashboard/integrations[/dim]")return Nonesystem_prompt, user_message = ClaudeAutoEngineer._build_auto_prompts(self)diff --git a/tests/test_cursor_auth.py b/tests/test_cursor_auth.pydeleted file mode 100644index 7306f4e..0000000--- a/tests/test_cursor_auth.py+++ /dev/null@@ -1,29 +0,0 @@-"""Tests for cursor_auth.get_cursor_api_key."""--from pathlib import Path--import pytest--from reverse_api.cursor_auth import get_cursor_api_key---def test_get_cursor_api_key_prefers_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.delenv("CURSOR_API_KEY_FILE", raising=False)- monkeypatch.setenv("CURSOR_API_KEY", " env-key ")- assert get_cursor_api_key() == "env-key"---def test_get_cursor_api_key_file_fallback(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.delenv("CURSOR_API_KEY", raising=False)- key_file = tmp_path / "key.txt"- key_file.write_text("# comment\n\nfile-key\n")- monkeypatch.setenv("CURSOR_API_KEY_FILE", str(key_file))- assert get_cursor_api_key() == "file-key"---def test_get_cursor_api_key_env_wins_over_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:- key_file = tmp_path / "key.txt"- key_file.write_text("from-file")- monkeypatch.setenv("CURSOR_API_KEY_FILE", str(key_file))- monkeypatch.setenv("CURSOR_API_KEY", "from-env")- assert get_cursor_api_key() == "from-env"