Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

terminal: an existing install is found through settings.json and used in place

Niko12213e5e0c73b2ec
diff --git a/strata_control/models.py b/strata_control/models.py
index c2dcb660a..30ef2d031 100644
--- a/strata_control/models.py
+++ b/strata_control/models.py
@@ -3,6 +3,12 @@
The setup installer writes strata-*.json beside setup.py. A configured model is
not automatically a compatible or loadable model: component presence and native
engine compatibility are reported separately.
+
+Finding an existing install: a terminal archive is a new folder with no run configs in it. The folders earlier
+Strata installs remembered in the user's settings file (``installs``, written by setup.py next to ``data_dir``) are
+searched for run configs, read-only, and the first that has any is used where it is. Nothing is copied or moved:
+the configs name their engine and model files by absolute path, so the old install and its data folder keep
+serving the models.
"""
from __future__ import annotations
@@ -30,14 +36,58 @@ SUPPORTED_SELECTIONS = frozenset({"qwen/Q2_0", "qwen/IQ2_XS", "qwen/IQ3_XXS", "q
"unsloth/UD-IQ4_XS", "unsloth/UD-Q4_K_XL"})
-def install_dir(override: str | None = None) -> Path:
+def settings_path() -> Path:
+ """The user's Strata settings file: the same place setup.py writes it (%APPDATA%\\Strata\\settings.json, or
+ $XDG_CONFIG_HOME/strata/settings.json)."""
+ if os.name == "nt":
+ return Path(os.environ.get("APPDATA") or Path.home() / "AppData" / "Roaming") / "Strata" / "settings.json"
+ return Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config") / "strata" / "settings.json"
+
+
+def remembered_installs() -> list[Path]:
+ """Earlier Strata folders recorded in the settings file, newest first. Read-only; a missing or unreadable file
+ is an empty list."""
+ try:
+ with settings_path().open("rb") as stream:
+ data = json.loads(stream.read(1024 * 1024).decode("utf-8-sig"))
+ except (OSError, UnicodeError, ValueError):
+ return []
+ items = data.get("installs") if isinstance(data, dict) else None
+ found: list[Path] = []
+ for raw in (items if isinstance(items, list) else [])[:20]:
+ if isinstance(raw, str) and raw:
+ path = Path(raw).expanduser()
+ if path.is_absolute() and path not in found:
+ found.append(path)
+ return found
+
+
+def _has_configs(directory: Path) -> bool:
+ try:
+ return directory.is_dir() and bool(_paths(directory))
+ except (ProfileError, OSError):
+ return False
+
+
+def resolve_install(override: str | None = None) -> tuple[Path, str]:
+ """(the install folder, how it was found): explicit (an argument or STRATA_INSTALL_DIR), here (this folder has run
+ configs), remembered (an earlier install from the settings file) or default (this folder, with none yet)."""
raw = override or os.environ.get("STRATA_INSTALL_DIR")
- if raw is None:
- return ROOT
- path = Path(raw).expanduser()
- if not path.is_absolute() or not path.is_dir():
- raise ProfileError("install directory must be an existing absolute directory", 5)
- return path.resolve()
+ if raw is not None:
+ path = Path(raw).expanduser()
+ if not path.is_absolute() or not path.is_dir():
+ raise ProfileError("install directory must be an existing absolute directory", 5)
+ return path.resolve(), "explicit"
+ if _has_configs(ROOT):
+ return ROOT, "here"
+ for earlier in remembered_installs():
+ if earlier != ROOT and _has_configs(earlier):
+ return earlier.resolve(), "remembered"
+ return ROOT, "default"
+
+
+def install_dir(override: str | None = None) -> Path:
+ return resolve_install(override)[0]
def _model_id(path: Path) -> str | None:
@@ -125,7 +175,7 @@ def _inspect_one(model_id: str, path: Path) -> tuple[dict, dict]:
def list_installed(override: str | None = None) -> dict:
- directory = install_dir(override)
+ directory, source = resolve_install(override)
models = []
for model_id, path in _paths(directory):
try:
@@ -134,7 +184,8 @@ def list_installed(override: str | None = None) -> dict:
summary = {"id": model_id, "source_config": str(path), "component_status": "invalid",
"error": str(exc), "execution_compatibility": "unverified"}
models.append(summary)
- return {"scope": "local_run_configs", "install_dir": str(directory), "models": models,
+ return {"scope": "local_run_configs", "install_dir": str(directory), "install_dir_source": source,
+ "models": models,
"model_count": len(models), "discovery_limit": MAX_CONFIGS}
diff --git a/tests/terminal/test_migration.py b/tests/terminal/test_migration.py
new file mode 100644
index 000000000..8587dd483
--- /dev/null
+++ b/tests/terminal/test_migration.py
@@ -0,0 +1,200 @@
+"""An install made by today's Strata is found and used in place by the terminal.
+
+The fixture is today's layout: a Strata folder with strata-<model>.json run configs (absolute paths into it and into
+the data folder), an engine/ folder, run-<model> scripts, a .venv, and a separate data folder (Strata-data) holding the
+GGUF files, prepared packs and the MTP layer; the user's settings.json remembers the data folder and the install. The
+terminal archive is a NEW folder. Nothing may be copied, moved, created or rewritten in the old layout, and the real
+settings file and model folders are never touched: everything lives in a temporary directory, the settings file
+location is redirected (conftest.py does the same for the whole session).
+"""
+
+import contextlib
+import hashlib
+import io
+import json
+import os
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+from unittest import mock
+
+import setup
+from strata_cli.cli import main
+from strata_control import models, profiles
+
+from tests.terminal.test_models import gguf_fixture
+
+
+def snapshot(base: Path) -> dict:
+ out = {}
+ for path in sorted(base.rglob("*")):
+ rel = path.relative_to(base).as_posix()
+ if path.is_dir():
+ out[rel] = ("dir",)
+ else:
+ out[rel] = ("file", path.stat().st_size, path.stat().st_mtime_ns,
+ hashlib.sha256(path.read_bytes()).hexdigest())
+ return out
+
+
+class ExistingInstallIsFoundInPlace(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+ base = Path(self.tmp.name)
+ self.appdata = base / "appdata"
+ self.old = base / "Strata" # today's install (a checkout or an unzipped release)
+ self.data = base / "Strata-data" # the data folder settings.json remembers
+ self.terminal = base / "Strata-terminal" # the new archive, extracted elsewhere
+ self.profiles = base / "profiles" # profile storage is outside both layouts
+ for d in (self.appdata, self.old, self.data, self.terminal):
+ d.mkdir()
+ env = mock.patch.dict(os.environ, {"APPDATA": str(self.appdata), "XDG_CONFIG_HOME": str(self.appdata),
+ "STRATA_PROFILE_DIR": str(self.profiles),
+ "STRATA_RUNTIME_DIR": str(base / "runtime")})
+ env.start()
+ self.addCleanup(env.stop)
+ os.environ.pop("STRATA_INSTALL_DIR", None)
+
+ exe_name = "strata.exe" if os.name == "nt" else "strata"
+ (self.old / "engine").mkdir()
+ (self.old / "engine" / exe_name).write_bytes(b"engine")
+ (self.old / "engine" / exe_name).chmod(0o700)
+ (self.old / "engine" / "BUILD.json").write_text(json.dumps({"version": "0.1.45", "source": "prebuilt"}))
+ (self.old / "setup.py").write_text("# the installer of the old folder\n")
+ (self.old / ".venv").mkdir()
+ (self.old / ".venv" / "pyvenv.cfg").write_text("home = elsewhere\n")
+ tok = self.data / "packs" / "tokenizer"
+ tok.mkdir(parents=True)
+ for name in ("vocab.json", "merges.txt", "token_type.json"):
+ (tok / name).write_bytes(b"placeholder")
+ self.models = []
+ for tag, ctx in (("q2_0", 32768), ("iq3_xxs", 65536)):
+ folder = self.data / "models" / tag.upper()
+ folder.mkdir(parents=True)
+ gguf = folder / f"Qwen3.8-Flash-Next-{tag}-00001-of-00001.gguf"
+ gguf.write_bytes(gguf_fixture())
+ pack = self.data / "packs" / tag
+ pack.mkdir()
+ (pack / "experts.bin").write_bytes(b"experts")
+ mtp = self.data / "mtp" / tag
+ mtp.mkdir(parents=True)
+ cfg = self.old / f"strata-{tag}.json"
+ cfg.write_text(json.dumps({
+ "exe": str(self.old / "engine" / exe_name), "tokenizer": str(tok), "cwd": str(self.old),
+ "args": ["--native", str(gguf), "--pack", str(pack), "--mtp", str(mtp), "--max-context", str(ctx)],
+ "backend": "cuda", "model_name": tag.upper(), "port": 8080, "log": str(self.old / f"{tag}.log")}),
+ encoding="utf-8")
+ (self.old / f"strata-{tag}.shared-settings.json").write_text("{}")
+ (self.old / (f"run-{tag}.bat" if os.name == "nt" else f"run-{tag}.sh")).write_text("run\n")
+ self.models.append(cfg)
+ (self.terminal / "VERSION").write_text("0.1.45\n")
+ # never the real settings file or model folders: everything below lives in the temporary directory
+ self.assertTrue(str(setup.settings_path()).startswith(str(base)), setup.settings_path())
+ setup.settings_path().parent.mkdir(parents=True)
+ setup.settings_path().write_text(json.dumps({"data_dir": str(self.data), "installs": [str(self.old)]}))
+ self.before = snapshot(base)
+ self.base = base
+ root = mock.patch.object(models, "ROOT", self.terminal)
+ root.start()
+ self.addCleanup(root.stop)
+
+ def cli(self, *args):
+ out = io.StringIO()
+ with contextlib.redirect_stdout(out):
+ code = main([*args, "--output", "json"])
+ return code, json.loads(out.getvalue())
+
+ def assertNothingChanged(self):
+ after = snapshot(self.base)
+ created = sorted(set(after) - set(self.before))
+ self.assertEqual([c for c in created if not c.startswith("profiles")], [])
+ for rel, was in self.before.items():
+ self.assertEqual(after.get(rel), was, rel)
+
+ def test_the_terminal_finds_the_old_install_through_settings_json(self):
+ self.assertEqual(models.resolve_install(), (self.old.resolve(), "remembered"))
+ code, listed = self.cli("models", "list", "--installed")
+ self.assertEqual(code, 0)
+ self.assertEqual(listed["install_dir"], str(self.old.resolve()))
+ self.assertEqual(listed["install_dir_source"], "remembered")
+ self.assertEqual([m["id"] for m in listed["models"]], ["iq3_xxs", "q2_0"])
+ self.assertEqual({m["component_status"] for m in listed["models"]}, {"present"})
+ self.assertEqual({m["context_tokens"] for m in listed["models"]}, {32768, 65536})
+ code, inspected = self.cli("models", "inspect", "q2_0")
+ self.assertEqual(code, 0)
+ self.assertTrue(inspected["components"]["ok"])
+ self.assertNothingChanged()
+
+ def test_a_profile_and_serve_plan_use_the_old_engine_and_models_where_they_are(self):
+ found = models.install_dir()
+ config = found / "strata-q2_0.json"
+ profiles.create("migrated", str(config))
+ code, planned = self.cli("serve", "--profile", "migrated", "--plan")
+ self.assertEqual(code, 0)
+ plan = planned["plan"]
+ self.assertEqual(Path(plan["source_config"]), config.resolve())
+ self.assertEqual(Path(plan["engine_exe"]).parent, self.old / "engine")
+ argv = plan["engine_argv"]
+ native = argv[argv.index("--native") + 1]
+ self.assertEqual(Path(native).parent.parent.parent, self.data) # Strata-data/models/Q2_0/<gguf>
+ self.assertNothingChanged()
+
+ def test_a_folder_with_its_own_configs_and_an_explicit_dir_win_over_the_remembered_install(self):
+ (self.terminal / "strata-local.json").write_bytes((self.old / "strata-q2_0.json").read_bytes())
+ self.assertEqual(models.resolve_install(), (self.terminal, "here"))
+ (self.terminal / "strata-local.json").unlink()
+ self.assertEqual(models.resolve_install(str(self.old)), (self.old.resolve(), "explicit"))
+ with mock.patch.dict(os.environ, {"STRATA_INSTALL_DIR": str(self.old)}):
+ self.assertEqual(models.resolve_install()[1], "explicit")
+
+ def test_nothing_remembered_means_this_folder_and_no_error(self):
+ setup.settings_path().unlink()
+ self.assertEqual(models.resolve_install(), (self.terminal, "default"))
+ setup.settings_path().write_text("not json")
+ self.assertEqual(models.resolve_install(), (self.terminal, "default"))
+ setup.settings_path().write_text(json.dumps({"installs": ["relative/path", 7, str(self.base / "gone")]}))
+ self.assertEqual(models.resolve_install(), (self.terminal, "default"))
+
+ def test_the_settings_path_is_the_one_setup_writes(self):
+ self.assertEqual(models.settings_path(), setup.settings_path())
+
+ def test_a_plain_start_from_the_old_folder_uses_the_remembered_data_folder_and_moves_nothing(self):
+ started = []
+ out = io.StringIO()
+ with mock.patch.object(setup, "ROOT", self.old), mock.patch.object(sys, "argv", ["setup.py", "--yes"]), \
+ mock.patch.object(setup, "gpus", lambda: []), \
+ mock.patch.object(setup.subprocess, "call", lambda cmd, *a, **k: started.append(cmd) or 0), \
+ contextlib.redirect_stdout(out):
+ self.assertEqual(setup.main(), 0, out.getvalue())
+ self.assertEqual(len(started), 1)
+ self.assertIn("server.py", " ".join(map(str, started[0])))
+ self.assertEqual(setup.data_folder_in_place(), (self.data, []))
+ # starting touches the most recently used config (its mtime) and nothing else
+ after = snapshot(self.base)
+ changed = [rel for rel in self.before if after.get(rel) != self.before[rel]]
+ self.assertEqual([c for c in changed if not c.startswith("Strata/strata-")], [])
+ self.assertEqual(sorted(set(after) - set(self.before)), [])
+
+ def test_setup_from_a_new_copy_reuses_the_data_folder_and_moves_no_model_file(self):
+ """The explicit setup path (which does gather files) finds the model files already in the data folder."""
+ new_copy = self.base / "Strata-new"
+ new_copy.mkdir()
+ (new_copy / "setup.py").write_text("# a new copy\n")
+ models_before = {k: v for k, v in self.before.items() if k.startswith("Strata-data/")}
+ with mock.patch.object(setup, "ROOT", new_copy), contextlib.redirect_stdout(io.StringIO()):
+ data, elsewhere = setup.data_folder(None)
+ self.assertTrue(data.samefile(self.data))
+ self.assertEqual(elsewhere, [])
+ after = snapshot(self.base)
+ self.assertEqual({k: v for k, v in after.items() if k.startswith("Strata-data/")}, models_before)
+ self.assertEqual({k: v for k, v in after.items() if k.startswith("Strata/")},
+ {k: v for k, v in self.before.items() if k.startswith("Strata/")})
+ saved = json.loads(setup.settings_path().read_text())
+ self.assertTrue(Path(saved["data_dir"]).samefile(self.data))
+ self.assertIn(str(self.old), saved["installs"]) # the old install stays remembered
+
+
+if __name__ == "__main__":
+ unittest.main()