From e687f0e4baa9f043d50a212f357087aa306b3fc5 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 5 Jul 2026 23:43:37 -0500 Subject: [PATCH] refac --- cptr/utils/agents/detection.py | 34 ++++++++++++++++++++++++++++++++++ cptr/utils/agents/models.py | 17 +++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/cptr/utils/agents/detection.py b/cptr/utils/agents/detection.py index 364273a..672424d 100644 --- a/cptr/utils/agents/detection.py +++ b/cptr/utils/agents/detection.py @@ -158,6 +158,18 @@ async def detect_profile(profile: dict[str, Any]) -> AgentDetection: ) return AgentDetection("ready", command, version, None, models) + if profile.get("agent") == "cline": + models = await _probe_cline_models(command, profile) + if not models: + return AgentDetection( + "auth_unknown", + command, + version, + "Could not discover Cline models. Check `cline auth` or add models manually.", + [], + ) + return AgentDetection("ready", command, version, None, models) + return AgentDetection("error", command, version, "Unknown agent") @@ -387,6 +399,28 @@ async def _probe_opencode_models(command: str, profile: dict[str, Any]) -> list[ await proc.wait() +async def _probe_cline_models(command: str, profile: dict[str, Any]) -> list[str] | None: + from cptr.utils.agents.acp import AcpClient, acp_models_from_setup + + env = os.environ.copy() + if profile.get("home"): + env["HOME"] = os.path.expanduser(str(profile["home"])) + client = AcpClient( + command=command, + args=["--acp"], + cwd=os.getcwd(), + env=env, + auth_method_id=None, + ) + try: + await asyncio.wait_for(client.start(), timeout=10) + return acp_models_from_setup(client.setup_result) or None + except Exception: + return None + finally: + await client.close() + + def _free_port() -> int: with socket.socket() as sock: sock.bind(("127.0.0.1", 0)) diff --git a/cptr/utils/agents/models.py b/cptr/utils/agents/models.py index 4fba931..f2acf66 100644 --- a/cptr/utils/agents/models.py +++ b/cptr/utils/agents/models.py @@ -70,10 +70,20 @@ DEFAULT_AGENT_PROFILES: list[dict[str, Any]] = [ "server_url": "", "server_password": "", }, + { + "id": "cline", + "agent": "cline", + "name": "Cline", + "mode": "auto", + "command": "cline", + "home": None, + "models": [], + "default_model": "", + }, ] _PROFILE_ID_RE = re.compile(r"^[a-z][a-z0-9_-]{0,63}$") -_VALID_AGENTS = {"codex", "claude_code", "cursor", "grok", "opencode"} +_VALID_AGENTS = {"codex", "claude_code", "cursor", "grok", "opencode", "cline"} _VALID_MODES = {"auto", "enabled", "disabled"} _VALID_CODEX_APPROVAL = {"ask", "auto", "full"} _VALID_CODEX_SANDBOX = {"read-only", "workspace-write", "danger-full-access"} @@ -92,6 +102,7 @@ _AGENT_DEFAULTS: dict[str, dict[str, str]] = { }, "grok": {"name": "Grok", "command": "grok", "model": ""}, "opencode": {"name": "OpenCode", "command": "opencode", "model": ""}, + "cline": {"name": "Cline", "command": "cline", "model": ""}, } @@ -107,7 +118,9 @@ def normalize_agent_profile(raw: dict[str, Any]) -> dict[str, Any]: agent = str(profile.get("agent") or "").strip() if agent not in _VALID_AGENTS: - raise HTTPException(400, "agent must be codex, claude_code, cursor, grok, or opencode") + raise HTTPException( + 400, "agent must be codex, claude_code, cursor, grok, opencode, or cline" + ) defaults = _AGENT_DEFAULTS[agent] mode = str(profile.get("mode") or "auto").strip()