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
Add the Unsloth provider to OpenClaw’s selected configuration (#15028)
Nilay9a72a04df586
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex 1a350ef5964..6a0dd5f668b 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -266,6 +266,7 @@ _CODEX_ENV_UNSET = ("OPENAI_API_KEY", "CODEX_API_KEY", "CODEX_ACCESS_TOKEN")# via OpenAI. CODEX_ACCESS_TOKEN is not a provider candidate but its host exec tool inherits it# (it is absent from host-env-security-policy.json), and the codex CLI on PATH logs in with it._OPENCLAW_ENV_UNSET = ("OPENAI_API_KEY", "CODEX_API_KEY", "CODEX_ACCESS_TOKEN")+_OPENCLAW_PROFILE_RE = re.compile(r"[a-z0-9][a-z0-9_-]{0,63}", re.IGNORECASE)# Shared by every agent command; only the config/env/command differ. Help is grouped into rich panels so `--help` reads as Model / Server / Session instead of one long unaligned list._PANEL_MODEL = "Model"@@ -6804,8 +6805,51 @@ def _openclaw_app_updates(return changes+def _openclaw_config_file() -> Optional[str]:+ executable = _which_with_install_dirs("openclaw")+ if executable is None:+ return None+ try:+ output = subprocess.check_output(+ [executable, "config", "file"],+ text = True,+ encoding = "utf-8",+ errors = "replace",+ timeout = 60,+ stderr = subprocess.DEVNULL,+ env = _probe_env(),+ )+ except Exception:+ return None+ lines = [line.strip() for line in output.splitlines() if line.strip()]+ return lines[-1] if lines and os.path.isabs(lines[-1]) else None++def _openclaw_app_target(max_tokens: Optional[int] = None) -> _AppTarget:- path = Path.home() / ".openclaw" / "openclaw.json"+ home = Path.home()++ def user_path(value: str) -> Path:+ # Only a leading ~ expands (against OPENCLAW_HOME); abspath keeps symlinks for _read_app_file to refuse.+ if value == "~":+ value = str(home)+ elif value.startswith(("~/", "~\\")):+ value = os.path.join(str(home), value[2:])+ return Path(os.path.abspath(value))++ override = os.environ.get("OPENCLAW_HOME", "").strip()+ if override and override not in ("null", "undefined"):+ home = user_path(override)+ if override := os.environ.get("OPENCLAW_CONFIG_PATH", "").strip():+ path = user_path(override)+ elif override := os.environ.get("OPENCLAW_STATE_DIR", "").strip():+ path = user_path(override) / "openclaw.json"+ else:+ path = home / ".openclaw" / "openclaw.json"+ profile = os.environ.get("OPENCLAW_PROFILE", "").strip()+ # Whether a named profile alone moves the config depends on the build (openclaw#133252, after 2026.10.10-beta.3), so ask OpenClaw.+ if _OPENCLAW_PROFILE_RE.fullmatch(profile) and profile.lower() != "default":+ if (active := _openclaw_config_file()) is not None:+ path = Path(active)updates = functools.partial(_openclaw_app_updates, max_tokens = max_tokens)return _AppTarget("openclaw", "OpenClaw app", path, updates)diff --git a/unsloth_cli/tests/test_start_app.py b/unsloth_cli/tests/test_start_app.pyindex 6aecf17da34..104d8580d5e 100644--- a/unsloth_cli/tests/test_start_app.py+++ b/unsloth_cli/tests/test_start_app.py@@ -43,6 +43,8 @@ def studio(tmp_path, monkeypatch):monkeypatch.setenv("LOCALAPPDATA", str(home / "AppData" / "Local"))monkeypatch.delenv("CODEX_HOME", raising = False)monkeypatch.delenv("UNSLOTH_API_KEY", raising = False)+ for name in ("OPENCLAW_CONFIG_PATH", "OPENCLAW_STATE_DIR", "OPENCLAW_HOME", "OPENCLAW_PROFILE"):+ monkeypatch.delenv(name, raising = False)server = {"calls": [], "keys": {CLI_KEY, APP_KEY}, "minted": 0}def http_json(@@ -376,6 +378,104 @@ def test_openclaw_app_adds_unsloth_and_joins_an_existing_allowlist(studio):assert data["models"]["providers"]["unsloth"]["baseUrl"] == f"{BASE}/v1"[email protected]("selector", ["config", "state", "both", "home", "profile"])+def test_openclaw_app_updates_selected_config_only(studio, monkeypatch, tmp_path, selector):+ default = studio["home"] / ".openclaw" / "openclaw.json"+ default.parent.mkdir()+ default.write_text('{"marker": "unrelated default"}\n')+ if selector == "home":+ monkeypatch.setenv("OPENCLAW_HOME", str(tmp_path / "relocated-home"))+ selected = tmp_path / "relocated-home" / ".openclaw" / "openclaw.json"+ elif selector == "profile":+ monkeypatch.setenv("OPENCLAW_PROFILE", "work")+ selected = studio["home"] / ".openclaw-work" / "openclaw.json"+ monkeypatch.setenv("OPENCLAW_STATE_DIR", str(selected.parent))+ monkeypatch.setenv("OPENCLAW_CONFIG_PATH", str(selected))+ else:+ selected = tmp_path / "selected" / "openclaw.json"+ if selector in ("config", "both"):+ monkeypatch.setenv("OPENCLAW_CONFIG_PATH", str(selected))+ if selector in ("state", "both"):+ # An explicit file wins over a different state directory.+ state = selected.parent if selector == "state" else tmp_path / "other-state"+ monkeypatch.setenv("OPENCLAW_STATE_DIR", str(state))+ selected.parent.mkdir(parents = True)+ original = '{"marker": "selected", "agents": {"defaults": {}}}\n'+ selected.write_text(original)++ result = CliRunner().invoke(start.start_app, ["openclaw", "--app"])++ assert result.exit_code == 0, result.output+ data = json.loads(selected.read_text())+ assert data["marker"] == "selected"+ assert data["models"]["providers"]["unsloth"]["apiKey"] == APP_KEY+ assert selected.with_name("openclaw.json.unsloth-backup").read_text() == original+ assert default.read_text() == '{"marker": "unrelated default"}\n'+ state = json.loads(start._app_state_path("openclaw", selected).read_text())+ assert state["path"] == str(selected)++[email protected]("override", ["~/custom/openclaw.json", "relative/openclaw.json"])+def test_openclaw_app_resolves_user_paths(studio, monkeypatch, tmp_path, override):+ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv("OPENCLAW_CONFIG_PATH", " " + override + " ")+ expected = (+ studio["home"] / "custom/openclaw.json" if override.startswith("~") else tmp_path / override+ )+ assert start._openclaw_app_target().path == expected+++def test_openclaw_app_expands_tilde_against_selected_home(studio, monkeypatch, tmp_path):+ monkeypatch.setenv("OPENCLAW_HOME", str(tmp_path / "selected-home"))+ monkeypatch.setenv("OPENCLAW_CONFIG_PATH", "~/custom.json")+ assert start._openclaw_app_target().path == tmp_path / "selected-home" / "custom.json"+++ "reported, profile, selected",+ [+ ("{home}/.openclaw/openclaw.json", "work", ".openclaw"),+ ("{home}/.openclaw-work/openclaw.json", "work", ".openclaw-work"),+ (None, "work", ".openclaw"),+ ("not a path", "work", ".openclaw"),+ ("{home}/.openclaw-work/openclaw.json", "Default", ".openclaw"),+ ("{home}/.openclaw-work/openclaw.json", "bad/name", ".openclaw"),+ ],+)+def test_openclaw_profile_environment_alone(studio, monkeypatch, reported, profile, selected):+ home = studio["home"]+ asked = []++ def check_output(command, **kwargs):+ asked.append(command[1:])+ if reported is None:+ raise start.subprocess.CalledProcessError(1, command)+ return "[plugins] ready\n" + reported.format(home = home) + "\n"++ monkeypatch.setattr(start, "_which_with_install_dirs", lambda name: "/bin/" + name)+ monkeypatch.setattr(start.subprocess, "check_output", check_output)+ monkeypatch.setenv("OPENCLAW_PROFILE", profile)+ config = home / selected / "openclaw.json"+ config.parent.mkdir()+ config.write_text('{"marker": "active"}\n')++ result = CliRunner().invoke(start.start_app, ["openclaw", "--app"])++ assert result.exit_code == 0, result.output+ data = json.loads(config.read_text())+ assert data["models"]["providers"]["unsloth"]["apiKey"] == APP_KEY+ assert data["marker"] == "active"+ other = ".openclaw-work" if selected == ".openclaw" else ".openclaw"+ assert not (home / other / "openclaw.json").exists()+ assert asked == ([] if profile != "work" else [["config", "file"]])++[email protected]("sentinel", ["null", " undefined "])+def test_openclaw_home_sentinel_is_unset(studio, monkeypatch, sentinel):+ monkeypatch.setenv("OPENCLAW_HOME", sentinel)+ assert start._openclaw_app_target().path == studio["home"] / ".openclaw" / "openclaw.json"++def test_openclaw_app_creates_no_allowlist(studio):config = studio["home"] / ".openclaw" / "openclaw.json"config.parent.mkdir()