Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
unsloth start opencode: detect OpenCode V2 installed as plain opencode (#13550)
Daniel Hand127a5c2b12d
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex b5d723e9aca..04a2f2a10ae 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -451,11 +451,31 @@ _OPENCODE_GLOBAL_VALUE_OPTIONS = frozenset(_OPENCODE_NATIVE_AUTO_MIN_VERSION = (1, 17, 12)+def _opencode_version(executable: str) -> Optional[tuple[int, int, int]]:+ try:+ output = subprocess.check_output(+ [executable, "--version"],+ text = True,+ encoding = "utf-8",+ errors = "replace",+ timeout = 10,+ stderr = subprocess.DEVNULL,+ env = _probe_env(),+ )+ except Exception:+ return None+ match = re.search(r"(\d+)\.(\d+)\.(\d+)", output)+ return tuple(int(part) for part in match.groups()) if match else None++def _opencode_command() -> tuple[str, bool]:resolved_v2 = _which_with_install_dirs("opencode2")if resolved_v2:return resolved_v2, True- return "opencode", False+ # Distro packages (Arch extra, opencode-beta) ship V2 as plain `opencode`, which rejects V1's --model flag.+ resolved = _which_with_install_dirs("opencode")+ version = _opencode_version(resolved) if resolved else None+ return "opencode", bool(version) and version[0] >= 2def _opencode_supports_native_auto(command: str = "opencode") -> bool:@@ -465,22 +485,8 @@ def _opencode_supports_native_auto(command: str = "opencode") -> bool:if executable is None:# No local binary: a --no-launch recipe may run elsewhere, and _run installs the current release on launch, so either way assume native --auto is available.return True- try:- output = subprocess.check_output(- [executable, "--version"],- text = True,- encoding = "utf-8",- errors = "replace",- timeout = 10,- stderr = subprocess.DEVNULL,- env = _probe_env(),- )- except Exception:- return False- match = re.search(r"(\d+)\.(\d+)\.(\d+)", output)- return bool(match) and tuple(int(part) for part in match.groups()) >= (- _OPENCODE_NATIVE_AUTO_MIN_VERSION- )+ version = _opencode_version(executable)+ return bool(version) and version >= _OPENCODE_NATIVE_AUTO_MIN_VERSIONdef _opencode_subcommand(args: list[str]) -> tuple[Optional[str], Optional[int]]:@@ -6767,7 +6773,9 @@ def opencode(subagent_model = {**entry, "id": subagent_id}# Stay append-safe for a bare no-launch recipe: a later `run <prompt>` would make `opencode --auto run ...` parse as the TUI, so keep yolo in the inline fallback.route_native_auto = (- yolo and _opencode_supports_native_auto(command_name) and (launch or bool(ctx.args))+ yolo+ and (opencode_v2 or _opencode_supports_native_auto(command_name))+ and (launch or bool(ctx.args)))opencode_args = list(ctx.args)if opencode_v2:@@ -6819,7 +6827,7 @@ def opencode(opencode_model = f"{_OPENCODE_PROVIDER}/{entry['id']}"# The inline OPENCODE_CONFIG_CONTENT below pins the model in the highest-priority layer, so the session model is forced without a --model flag. Only add --model for an interactive bare launch, as a convenience so the TUI opens on our model: it is omitted for passthrough, where inserting it before a subcommand can be misparsed, and for --no-launch, where the printed command is consumed by drivers that append a subcommand such as `run <prompt>` and a leading --model would land before it. Those paths rely on the inline pin instead.native_auto = False- route_native_auto = yolo and _opencode_supports_native_auto(command_name)+ route_native_auto = yolo and (opencode_v2 or _opencode_supports_native_auto(command_name))if ctx.args:opencode_args = list(ctx.args)if opencode_v2:diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.pyindex 60288cd1466..7fb4824b7d4 100644--- a/unsloth_cli/tests/test_start.py+++ b/unsloth_cli/tests/test_start.py@@ -783,6 +783,44 @@ def test_opencode_command_falls_back_to_v1(monkeypatch):assert start._opencode_command() == ("opencode", False)+ "version_output, v2",+ [("opencode v2.0.27\n", True), ("1.19.0\n", False), (OSError("probe failed"), False)],+)+def test_opencode_command_detects_v2_installed_as_opencode(monkeypatch, version_output, v2):+ # Arch's opencode package ships V2 as plain `opencode` (#13476).+ monkeypatch.setattr(+ start,+ "_which_with_install_dirs",+ lambda name: "/usr/bin/opencode" if name == "opencode" else None,+ )++ def check_output(argv, **_):+ assert argv == ["/usr/bin/opencode", "--version"]+ if isinstance(version_output, Exception):+ raise version_output+ return version_output++ monkeypatch.setattr(start.subprocess, "check_output", check_output)+ assert start._opencode_command() == ("opencode", v2)+++def test_opencode_command_probes_real_v2_binary_named_opencode(monkeypatch, tmp_path):+ bin_dir = tmp_path / "bin"+ bin_dir.mkdir()+ if os.name == "nt":+ (bin_dir / "opencode.cmd").write_text("@echo opencode v2.0.27\r\n")+ else:+ script = bin_dir / "opencode"+ script.write_text("#!/bin/sh\necho opencode v2.0.27\n")+ script.chmod(0o755)+ monkeypatch.setattr(start.Path, "home", lambda: tmp_path)+ monkeypatch.setenv("APPDATA", str(tmp_path / "no-appdata"))+ monkeypatch.setenv("PATH", str(bin_dir))++ assert start._opencode_command() == ("opencode", True)++def test_opencode_command_finds_official_v2_install_dir(monkeypatch, tmp_path):install_dir = tmp_path / ".opencode" / "bin"install_dir.mkdir(parents = True)@@ -6018,6 +6056,17 @@ def test_connect_opencode_v2_no_launch_uses_private_server(fake_studio, monkeypaassert f"provider policies must allow '{start._OPENCODE_PROVIDER}'" in result.output+def test_connect_opencode_v2_named_opencode_launches_without_model_flag(fake_studio, monkeypatch):+ monkeypatch.setattr(start, "_opencode_command", lambda *_: ("opencode", True))+ launched = []+ monkeypatch.setattr(start, "_run", lambda *a, **k: launched.append(a[3]))++ result = CliRunner().invoke(start.start_app, ["opencode", "--yolo"])++ assert result.exit_code == 0, result.output+ assert launched == [["opencode", "--standalone", "--auto"]]++def test_connect_opencode_v2_no_launch_uses_resolved_off_path_binary(fake_studio, monkeypatch, tmp_path):