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++
the Folder step checks the path before going on, the Save summary shows the storage path, a denied folder is told in plain words (B05, B12)
Niko12211ed28f8863d0
diff --git a/setup.py b/setup.pyindex 2d24d2524..f97399e16 100644--- a/setup.py+++ b/setup.py@@ -5890,6 +5890,14 @@ def data_folder(requested: str | None, move: bool = False, yes: bool = True, setsettings = load_settings()remembered = Path(settings["data_dir"]) if settings.get("data_dir") else home().parent / "Strata-data"dest = Path(requested).expanduser().resolve() if requested else remembered+ from strata_control import folders+ bad = folders.problem(dest)+ if bad and requested:+ fail(folders.words(bad)[:400], "Nothing was downloaded or changed, and the folder was not saved as your data folder.")+ if bad and settings.get("data_dir"): # an unusable folder saved earlier: go back to the default and say so; never keep it+ warn(f"The data folder saved before cannot be used ({bad[0]}) Using {home().parent / 'Strata-data'} instead.")+ remembered = dest = home().parent / "Strata-data"+ settings = {k: v for k, v in settings.items() if k != "data_dir"}try:dest.mkdir(parents=True, exist_ok=True)except OSError as e: # e.g. no write access next to the Strata folder@@ -5976,6 +5984,9 @@ def data_folder_in_place() -> tuple:configs name their model files, so an install made by an earlier Strata starts from where it is."""settings = load_settings()dest = Path(settings["data_dir"]) if settings.get("data_dir") else home().parent / "Strata-data"+ from strata_control import folders+ if settings.get("data_dir") and folders.problem(dest): # a folder saved earlier that cannot be used: the default, and it is not kept+ dest = home().parent / "Strata-data"return dest, []diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.pyindex 92237f6df..9fec242ba 100644--- a/strata_cli/launch/cmd.py+++ b/strata_cli/launch/cmd.py@@ -212,6 +212,10 @@ def settings_from_args(a: argparse.Namespace, catalog=None) -> tuple[S.LaunchSetelif a.family and s.model:s.family = a.familyif a.data_dir:+ from strata_control import folders+ found = folders.problem(a.data_dir)+ if found:+ raise ValueError(folders.words(found)) # one plain line and a next step, before anything is written (B05)s.data_dir = a.data_dirif a.context:s.context = a.contextdiff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.pyindex e5ef15f7e..b7a9469aa 100644--- a/strata_cli/launch/runner.py+++ b/strata_cli/launch/runner.py@@ -98,6 +98,17 @@ def setup_failure(lines: list[str], err: str, hint: str, details: str | None, owif missing_file(crashed):return LaunchError(f"The model could not be installed. A file that setup needs is missing from this Strata install ({crashed}).","Update Strata (`strata update`) and run it again." + where, 6)+ if crashed.startswith("PermissionError"):+ folder = re.findall(r"'([^']+)'", crashed)+ shown = folder[-1] if folder else None+ try: # the folder Strata was told to use, not a file inside it+ shown = str(Path(shown).parent) if shown and Path(shown).name in ("models", "packs", "mtp") else shown+ except (OSError, ValueError):+ pass+ return LaunchError("The model could not be installed. " + (f"Windows would not let Strata write to {shown}" if shown else+ "Windows would not let Strata write to a folder") + " (access denied).",+ "Pick a folder you own for the model files (the Folder step, or --data-dir D:\\Strata-models) and start again. "+ "Nothing was downloaded." + where, 6)return LaunchError(f"The model could not be installed. Setup stopped with an error ({crashed}).", "Run it again." + where, 6)return LaunchError("The model could not be installed." + (f" {err}." if err else ""),(hint or ("Run it again: finished steps are skipped." if own_files elsediff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.pyindex 6eaad15ad..dcab4884e 100644--- a/strata_cli/launch/screens.py+++ b/strata_cli/launch/screens.py@@ -787,8 +787,20 @@ class FolderScreen(Base):"Press Enter to keep it, or type another folder (it is created if it does not exist). Models you already have stay where ""they are and stay usable; the new folder is for new downloads.", style=MUTE)+ def typed(self) -> str:+ return self.query_one("#folderpath", Input).value.strip().strip('"')++ def action_next(self) -> None:+ """The folder is checked before going on (B05): a path that cannot hold the models is said here, in plain words, and not saved."""+ from strata_control import folders+ found = folders.problem(self.typed())+ if found:+ self.say(folders.words(found), True)+ return+ super().action_next()+def commit(self) -> None:- value = self.query_one("#folderpath", Input).value.strip().strip('"')+ value = self.typed()default = str(self.ctx.default_folder())self.ctx.settings.data_dir = None if (not value or value == default) else value@@ -1439,7 +1451,7 @@ class SaveScreen(Base):("Parallel", f"{s.parallel} at a time" if s.parallel else f"fit to your card ({S.fit_parallel(self.ctx.computer.main_vram_gb)})"),("Tuning", {"quick": "quick (about 20 min)", "thorough": "thorough (up to 2 h)", "skip": "skipped"}[s.tune]),("Access", f"{S.ACCESS_WORDS[s.access]}, port {s.port}" + (", API key on" if s.api_key else ", no API key")),- ("Storage", s.data_dir or "Strata's data folder")]+ ("Storage", s.data_dir or str(self.ctx.default_folder()))]if s.extra:lines.append(("Advanced", ", ".join(f"{k}={v}" for k, v in s.extra.items())))return lines@@ -1461,7 +1473,7 @@ class SaveScreen(Base):model = dict(lines)["Model"].replace("Qwen3.8-Flash-Next ", "")rows = [f"{model} \u00b7 {S.context_label(s.context)} \u00b7 memory {s.kv or 'int8'}",f"Pictures {'on' if s.vision != 'off' else 'off'} \u00b7 Parallel {s.parallel or 'auto'} \u00b7 Tuning {s.tune}",- f"Access {s.access}, port {s.port}" + (f" \u00b7 Storage {s.data_dir}" if s.data_dir else "")]+ f"Access {s.access}, port {s.port}" + f" \u00b7 Storage {s.data_dir or self.ctx.default_folder()}"]t.append("Save, then launch name:\n" if tiny else "Save as preset, then launch name:\n", style=f"bold {ACCENT}")for ln in rows[:2 if tiny else 3]:t.append(" " + ln + "\n")diff --git a/strata_control/folders.py b/strata_control/folders.pynew file mode 100644index 000000000..940b2ee96--- /dev/null+++ b/strata_control/folders.py@@ -0,0 +1,104 @@+"""Is this a folder Strata can keep model files in? Said in plain words before anything is downloaded (the Folder step, --data-dir, setup).++`problem(path)` returns (what is wrong, what to do) or None. Nothing is created and nothing is left behind: a missing folder is judged by the+nearest folder above it that exists (can a file be made there, so the folder could be created), and "can be written" is tried by creating and+deleting a small file, never read from the permission bits.+"""++from __future__ import annotations++import os+import re+import uuid+from pathlib import Path++NEXT = "Pick another folder, for example one on a drive you own, like D:\\Strata-models. Nothing was downloaded or changed."+NEXT_POSIX = "Pick another folder you own, for example ~/strata-models. Nothing was downloaded or changed."++_WIN_BAD = re.compile(r'[<>"|?*\x00-\x1f]')+_POSIX_SYSTEM = ("/bin", "/boot", "/dev", "/etc", "/lib", "/lib32", "/lib64", "/proc", "/root", "/run", "/sbin", "/sys", "/usr", "/var/lib", "/System",+ "/Library", "/private/etc")+++def _next() -> str:+ return NEXT if os.name == "nt" else NEXT_POSIX+++def _system_roots() -> list[str]:+ if os.name != "nt":+ return list(_POSIX_SYSTEM)+ roots = []+ for var in ("SystemRoot", "windir", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"):+ value = os.environ.get(var)+ if value:+ roots.append(value)+ drive = os.environ.get("SystemDrive", "C:")+ roots += [drive + "\\Windows", drive + "\\Program Files", drive + "\\Program Files (x86)"]+ return roots+++def _norm(path: str) -> str:+ return os.path.normcase(os.path.normpath(path)).rstrip("\\/")+++def _inside(path: str, root: str) -> bool:+ p, r = _norm(path), _norm(root)+ return p == r or p.startswith(r + os.sep)+++def _can_write(folder: Path) -> bool:+ probe = folder / f".strata-write-test-{uuid.uuid4().hex[:8]}"+ try:+ with open(probe, "wb") as fh:+ fh.write(b"x")+ except OSError:+ return False+ try:+ probe.unlink()+ except OSError:+ pass+ return True+++def problem(raw: str | os.PathLike | None) -> tuple[str, str] | None:+ """(what is wrong, what to do) for a folder meant for model files, None when it is usable (or empty: the default folder is used)."""+ text = os.fspath(raw).strip().strip('"') if raw else ""+ if not text:+ return None+ if _WIN_BAD.search(text.replace("\\\\?\\", "", 1)) or (os.name == "nt" and ":" in text[2:] and not text.startswith("\\\\?\\")):+ return (f"This does not look like one folder path: {text}.",+ "Type one full path, like D:\\Strata-models, with nothing else in front of or behind it. Nothing was downloaded or changed."+ if os.name == "nt" else "Type one full path, like ~/strata-models. Nothing was downloaded or changed.")+ path = Path(text).expanduser()+ if not path.is_absolute():+ return (f"This is not a full path: {text}.",+ "Type the whole path, starting with the drive, like D:\\Strata-models. Nothing was downloaded or changed."+ if os.name == "nt" else "Type the whole path, starting with /, like /data/strata-models. Nothing was downloaded or changed.")+ full = os.path.abspath(path)+ for root in _system_roots():+ if _inside(full, root):+ return (f"{full} is a system folder, and Strata should not keep model files there.", _next())+ try:+ if path.exists():+ if not path.is_dir():+ return (f"{full} is a file, not a folder.", _next())+ if not _can_write(path):+ return (f"Strata cannot write to {full}: Windows or the folder's owner does not allow it." if os.name == "nt"+ else f"Strata cannot write to {full}: you do not have permission.", _next())+ return None+ above = path+ while not above.exists():+ if above.parent == above:+ return (f"The drive or folder for {full} is not there. Check the spelling, and that the drive is connected.", _next())+ above = above.parent+ if not above.is_dir():+ return (f"{above} is a file, so {full} cannot be created inside it.", _next())+ if not _can_write(above):+ return (f"{full} does not exist yet and cannot be created: Strata cannot write to {above}.", _next())+ except OSError as e:+ return (f"Strata cannot look at {full} ({type(e).__name__}).", _next())+ return None+++def words(problem_: tuple[str, str]) -> str:+ return f"{problem_[0]} {problem_[1]}".strip()diff --git a/tests/terminal/test_launch_tui.py b/tests/terminal/test_launch_tui.pyindex 9ed3d990f..7f07f777e 100644--- a/tests/terminal/test_launch_tui.py+++ b/tests/terminal/test_launch_tui.py@@ -319,10 +319,10 @@ class FolderStep(Base):self.assertIn("Free space in that folder's drive", t)f = app.screen.query_one("#folderpath")f.value = ""- await typed(pilot, "D:/Strata-data")- self.assertEqual(f.value, "D:/Strata-data")+ await typed(pilot, str(self.home.base / "Strata-data"))+ self.assertEqual(f.value, str(self.home.base / "Strata-data"))await press(pilot, "enter")- self.assertEqual(ctx.settings.data_dir, "D:/Strata-data")+ self.assertEqual(ctx.settings.data_dir, str(self.home.base / "Strata-data"))self.assertIn("How much text should it remember at once?", text_of(app))self.run_app(case)diff --git a/tests/terminal/test_tui_stress_screens.py b/tests/terminal/test_tui_stress_screens.pynew file mode 100644index 000000000..e5d8564ee--- /dev/null+++ b/tests/terminal/test_tui_stress_screens.py@@ -0,0 +1,224 @@+"""TUI stress test fixes on the screens: the Folder step (B05), the Save summary (B12), ctrl+c and Escape (B13), PermissionError words, setup guard."""++import contextlib+import io+import json+import os+import tempfile+import unittest+from pathlib import Path+from unittest import mock++import setup+from strata_control import folders+from strata_cli.launch import settings as S+from strata_cli.launch.runner import setup_failure+from tests.terminal.launch_support import run_cli+from tests.terminal.test_launch_tui import Base, FakeRunner, flat, press, text_of, typed+++class FolderRules(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.base = Path(self.tmp.name)++ def test_usable_folders_pass_and_nothing_is_left_behind(self):+ self.assertIsNone(folders.problem(""))+ self.assertIsNone(folders.problem(self.base))+ self.assertIsNone(folders.problem(self.base / "new" / "deeper")) # the parent exists and can be written: it can be created+ self.assertEqual(os.listdir(self.base), []) # nothing was created, the test file is gone++ def test_a_file_is_not_a_folder(self):+ f = self.base / "a.txt"+ f.write_text("x")+ what, nxt = folders.problem(f)+ self.assertIn("is a file", what)+ self.assertTrue(nxt)++ def test_a_missing_parent_that_cannot_be_created_is_refused(self):+ f = self.base / "a.txt"+ f.write_text("x")+ self.assertIn("is a file", folders.problem(f / "inside")[0])+ with mock.patch.object(folders, "_can_write", return_value=False):+ what, nxt = folders.problem(self.base / "x" / "y")+ self.assertIn("cannot be created", what)++ def test_a_folder_that_cannot_be_written_is_refused(self):+ with mock.patch.object(folders, "_can_write", return_value=False):+ what, nxt = folders.problem(self.base)+ self.assertIn("cannot write", what)+ self.assertIn("Pick another folder", nxt)++ def test_the_write_test_creates_and_deletes_a_file(self):+ seen = []+ real = open++ def spy(path, *a, **k):+ seen.append(str(path))+ return real(path, *a, **k)++ with mock.patch("builtins.open", spy):+ self.assertTrue(folders._can_write(self.base))+ self.assertTrue(any(".strata-write-test-" in s for s in seen))+ self.assertEqual(os.listdir(self.base), [])++ @unittest.skipUnless(os.name == "nt", "Windows system folders")+ def test_system_folders_are_refused(self):+ for p in (r"C:\Windows\System32", r"C:\Windows", r"C:\Program Files\Strata", r"C:\Program Files (x86)\x"):+ with self.subTest(p=p):+ what, nxt = folders.problem(p)+ self.assertIn("system folder", what)++ @unittest.skipUnless(os.name == "nt", "Windows path rules")+ def test_malformed_and_relative_paths_are_refused(self):+ for p in (r"C:\a C:\b", r"C:\models|x", r"D:\what?", "models", r"..\x"):+ with self.subTest(p=p):+ self.assertIsNotNone(folders.problem(p), p)++ def test_the_plain_words_carry_a_next_step(self):+ text = folders.words(("This is bad.", "Do that."))+ self.assertEqual(text, "This is bad. Do that.")+++class FolderScreen(Base):+ def test_a_bad_folder_stays_on_the_screen_with_one_plain_line_and_is_not_kept(self):+ async def case(app, pilot, ctx):+ await press(pilot, "enter", "enter")+ f = app.screen.query_one("#folderpath")+ f.value = ""+ await typed(pilot, str(self.home.base / "afile.txt"))+ (self.home.base / "afile.txt").write_text("x")+ await press(pilot, "enter")+ t = flat(app)+ self.assertIn("Where should the model files be stored?", t)+ self.assertIn("is a file, not a folder", t)+ self.assertIn("Pick another folder", t)+ self.assertIsNone(ctx.settings.data_dir)+ f.value = ""+ await typed(pilot, str(self.home.base / "good"))+ await press(pilot, "enter")+ self.assertIn("How much text should it remember at once?", text_of(app))+ self.assertEqual(ctx.settings.data_dir, str(self.home.base / "good"))+ self.run_app(case)++ def test_the_save_summary_shows_the_chosen_storage_path(self):+ async def case(app, pilot, ctx):+ await press(pilot, *("enter",) * 7, "n", "enter")+ t = flat(app)+ self.assertIn("Storage", t)+ self.assertIn(str(ctx.default_folder()), t)+ self.run_app(case)++ def test_the_save_summary_shows_a_typed_folder(self):+ async def case(app, pilot, ctx):+ await press(pilot, "enter", "enter")+ f = app.screen.query_one("#folderpath")+ f.value = ""+ await typed(pilot, str(self.home.base / "mine"))+ await press(pilot, *("enter",) * 5, "n", "enter")+ self.assertIn("Step 9 of 9", flat(app))+ self.assertIn("mine", flat(app))+ self.run_app(case)+++class QuitKeys(Base):+ def test_ctrl_c_quits_the_setup_screens_like_ctrl_q(self):+ for key in ("ctrl+c", "ctrl+q"):+ with self.subTest(key=key):+ async def case(app, pilot, ctx):+ await press(pilot, "enter") # the Model screen+ await press(pilot, key)+ await pilot.pause(0.3)+ self.assertTrue(app._exit) # the app is closing+ self.run_app(case)++ def test_ctrl_c_in_the_folder_field_still_quits(self):+ async def case(app, pilot, ctx):+ await press(pilot, "enter", "enter")+ await press(pilot, "ctrl+c")+ await pilot.pause(0.3)+ self.assertTrue(app._exit)+ self.run_app(case)++ def test_escape_in_the_stop_dialog_only_closes_it(self):+ from strata_cli.launch import store+ async def case(app, pilot, ctx):+ store.save(S.LaunchSettings(name="T", family="qwen", model="IQ3_XXS", context=32768))+ FakeRunner.behaviour = "wait"+ app.start_preset("T")+ await pilot.pause(0.4)+ await press(pilot, "ctrl+c") # work would be lost: the dialog stays+ self.assertIn("Stop now?", text_of(app))+ await press(pilot, "escape")+ self.assertNotIn("Stop now?", text_of(app))+ self.assertTrue(app.running) # still running, and no Back happened+ self.assertEqual(app.current, "run")+ app.cancel.set()+ await pilot.pause(0.5)+ self.run_app(case)+++class PermissionWords(unittest.TestCase):+ def test_a_permission_error_names_the_folder_and_what_to_do(self):+ lines = ["Traceback (most recent call last):", " f",+ r"PermissionError: [WinError 5] Access is denied: 'C:\Windows\System32\models'"]+ e = setup_failure(lines, "", "", r"C:\x\a.setup.log", False)+ self.assertIn(r"C:\Windows\System32", e.text)+ self.assertIn("access denied", e.text)+ self.assertNotIn("WinError", e.text + e.next)+ self.assertNotIn("Run it again", e.next)+ self.assertIn("--data-dir", e.next)++ def test_other_errors_keep_their_words(self):+ e = setup_failure(["Traceback (most recent call last):", " f", "KeyError: 'cuda'"], "", "", None, True)+ self.assertIn("KeyError", e.text)+++class SetupGuard(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.base = Path(self.tmp.name)+ self.root = self.base / "Strata"+ self.root.mkdir()+ env = mock.patch.dict(os.environ, {"APPDATA": str(self.base / "appdata"), "XDG_CONFIG_HOME": str(self.base / "appdata")})+ env.start()+ self.addCleanup(env.stop)+ os.environ.pop("STRATA_SETTINGS_FILE", None)+ for patcher in (mock.patch.object(setup, "ROOT", self.root), mock.patch.object(setup, "_CONTROL_HOME", None)):+ patcher.start()+ self.addCleanup(patcher.stop)+ setup.settings_path().parent.mkdir(parents=True, exist_ok=True)++ def test_a_bad_requested_folder_stops_with_plain_words_and_is_never_saved(self):+ setup.settings_path().write_text(json.dumps({"installs": []}), encoding="utf-8")+ afile = self.base / "afile"+ afile.write_text("x")+ with contextlib.redirect_stdout(io.StringIO()) as out, self.assertRaises(SystemExit):+ setup.data_folder(str(afile), yes=True)+ self.assertIn("is a file, not a folder", out.getvalue())+ self.assertNotIn("data_dir", json.loads(setup.settings_path().read_text(encoding="utf-8")))++ def test_a_bad_saved_folder_is_dropped_not_kept(self):+ afile = self.base / "afile"+ afile.write_text("x")+ setup.settings_path().write_text(json.dumps({"data_dir": str(afile), "installs": []}), encoding="utf-8")+ with contextlib.redirect_stdout(io.StringIO()):+ dest, _ = setup.data_folder(None, yes=True)+ self.assertNotEqual(str(dest.resolve()), str(afile.resolve()))+ self.assertNotEqual(json.loads(setup.settings_path().read_text(encoding="utf-8")).get("data_dir"), str(afile))+++class DataDirFlag(unittest.TestCase):+ def test_launch_data_dir_with_a_bad_path_refuses_before_anything(self):+ with tempfile.TemporaryDirectory() as tmp:+ afile = Path(tmp) / "afile"+ afile.write_text("x")+ code, out, err = run_cli(["launch", "--plan", "--model", "q2_0", "--data-dir", str(afile)])+ self.assertEqual(code, 2)+ self.assertIn("is a file, not a folder", err)+++if __name__ == "__main__":+ unittest.main()