From 86350f8a73617de9f6c08e3ef6bb228141b0bddd Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 26 Jul 2026 18:02:10 -0400 Subject: [PATCH] refac --- README.md | 8 +++++++ cptr/utils/agents/detection.py | 38 ++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a7302d..8f7c750 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,14 @@ The default image includes Git and GitHub CLI (`gh`). Use `ghcr.io/open-webui/co If you bind-mount a host directory to `/data`, make sure that directory is writable by the container user. SQLite needs to create and update `/data/app.db`, and host directory permissions take precedence over the image's built-in `/data` ownership. +To connect a host-running OpenCode server from Docker, start OpenCode on a host-reachable interface and set the OpenCode agent Server URL to the Docker host address: + +```bash +opencode serve --hostname 0.0.0.0 --port 4096 +``` + +Use `http://host.docker.internal:4096` on Docker Desktop. On Linux, add `--add-host=host.docker.internal:host-gateway` to `docker run` if that hostname is not already available. + The `:dev` image is also available and tracks the `main` branch. ## Air-gapped installation diff --git a/cptr/utils/agents/detection.py b/cptr/utils/agents/detection.py index 98dbb56..7d2be09 100644 --- a/cptr/utils/agents/detection.py +++ b/cptr/utils/agents/detection.py @@ -117,16 +117,49 @@ async def _run_probe( async def detect_profile(profile: dict[str, Any]) -> AgentDetection: raw_command = str(profile.get("command") or "").strip() command = _resolve_command(raw_command) - if command is None and profile.get("agent") == "claude_code" and raw_command == "claude": + default_claude_command = profile.get("agent") == "claude_code" and raw_command == "claude" + if profile.get("agent") == "opencode" and str(profile.get("server_url") or "").strip(): + version = None + if command is not None: + code, version_text = await _run_probe([command, "--version"]) + version = version_text.splitlines()[0] if code == 0 and version_text else None + models = await _probe_opencode_models(command or raw_command or "opencode", profile) + if not models: + return AgentDetection( + "auth_unknown", + command, + version, + "Could not discover OpenCode models. Check connected OpenCode providers.", + [], + ) + return AgentDetection("ready", command, version, None, models) + + if command is None and default_claude_command: command = _find_claude_desktop_command() if command is None: return AgentDetection("not_found", None, None, "Command not found") code, version_text = await _run_probe([command, "--version"]) + if code != 0 and default_claude_command: + desktop_command = _find_claude_desktop_command() + if desktop_command and desktop_command != command: + desktop_code, desktop_version_text = await _run_probe([desktop_command, "--version"]) + if desktop_code == 0: + command = desktop_command + code = desktop_code + version_text = desktop_version_text version = version_text.splitlines()[0] if code == 0 and version_text else None if profile.get("agent") == "claude_code": models = _claude_models_for_version(version) + if code != 0: + return AgentDetection( + "error", + command, + version, + version_text or "Failed to run Claude Code health check.", + models, + ) if importlib.util.find_spec("claude_agent_sdk") is None: return AgentDetection( "missing_dependency", @@ -585,10 +618,11 @@ async def get_agent_status(app_state=None, refresh: bool = False) -> dict[str, A and (mode != "auto" or detected.status == "ready") ) effective_profile = dict(profile) + resolved_profile_command = _resolve_command(str(profile.get("command") or "")) if ( detected.command and profile.get("agent") == "claude_code" - and _resolve_command(str(profile.get("command") or "")) is None + and detected.command != resolved_profile_command ): effective_profile["command"] = detected.command effective_profile["models"] = models