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++
Models move: remember an unfinished move in the old folder; strata models move --resume/--leave/--status; one-line notice at strata launch
Niko12210a35538b745a
diff --git a/strata_cli/cli.py b/strata_cli/cli.pyindex 94863cb0a..97b8554ab 100644--- a/strata_cli/cli.py+++ b/strata_cli/cli.py@@ -160,7 +160,10 @@ def parser() -> argparse.ArgumentParser:help="inspect only; adoption requires a qualified model workflow")models_import.add_argument("--output", choices=("human", "json"), default="human")models_move = models_sp.add_parser("move", help="move the model files (models, packs, mtp) to another folder: copied, checked, then the old copies removed")- models_move.add_argument("to", metavar="NEW_FOLDER")+ models_move.add_argument("to", metavar="NEW_FOLDER", nargs="?", help="not needed with --resume, --leave or --status")+ models_move.add_argument("--resume", action="store_true", help="finish a move that was interrupted")+ models_move.add_argument("--leave", action="store_true", help="give up an interrupted move: keep the old folder and remove the partial copies")+ models_move.add_argument("--status", action="store_true", help="say whether a move was interrupted (changes nothing)")models_move.add_argument("--from", dest="source", metavar="OLD_FOLDER", help="the folder the models are in now (default: the data folder in use)")models_move.add_argument("--install-dir", help="absolute path to a Strata installation whose run configs should follow the files")models_move.add_argument("--plan", action="store_true", help="say what would happen and change nothing")@@ -613,6 +616,11 @@ def _models_move(a: argparse.Namespace) -> int:from strata_control import discovery, models, models_move as mmmachine = a.output in ("json", "jsonl")old = Path(a.source) if a.source else discovery.data_dir(Path.home() / "Strata")[0]+ if a.status or a.resume or a.leave:+ return _models_move_unfinished(a, old)+ if not a.to:+ print("strata: name the new folder, or use --resume / --leave / --status for an interrupted move.", file=sys.stderr)+ return 2new = Path(a.to).expanduser()if a.plan:result = mm.plan(old, new)@@ -650,6 +658,51 @@ def _models_move(a: argparse.Namespace) -> int:return 0 if summary["done"] else 6+def _interrupted_words(st: dict) -> str:+ return (f"A move of your models was interrupted. They are in {st['from']} and {st['to']}. "+ "Finish it: strata models move --resume. Leave it (keep the models in the first folder): strata models move --leave.")+++def _models_move_unfinished(a: argparse.Namespace, old: Path) -> int:+ """`strata models move --status | --resume | --leave`: the move the last run left unfinished (A move was interrupted. Finish it or leave it)."""+ from strata_control import models, models_move as mm+ machine = a.output in ("json", "jsonl")+ st = mm.interrupted(old)+ if a.status:+ if machine:+ print(json.dumps({"schema_version": 1, "ok": True, "interrupted": st}, ensure_ascii=False, allow_nan=False))+ else:+ print(_interrupted_words(st) if st else "No move was interrupted.")+ return 0+ if not st:+ if machine:+ print(json.dumps({"schema_version": 1, "ok": False, "error": {"code": "nothing", "message": "No move was interrupted.", "details": ""}}))+ else:+ print("strata: no move was interrupted.", file=sys.stderr)+ return 5+ try:+ installs = [models.resolve_install(a.install_dir)[0]] if a.install_dir else [p for p, _s in models.all_installs()]+ except Exception:+ installs = []+ configs = [c for i in installs for c in mm.config_files(i)]+ if a.leave:+ try:+ result = mm.leave(Path(st["from"]), Path(st["to"]), configs=configs)+ except mm.MoveError as e:+ if machine:+ print(json.dumps({"schema_version": 1, "ok": False, "error": {"code": e.code, "message": str(e), "details": e.details}}, ensure_ascii=False))+ else:+ print(f"strata: {e} {e.details}".rstrip(), file=sys.stderr)+ return 5+ if machine:+ print(json.dumps({"schema_version": 1, "ok": True, "event": "result", "left": True, **result}, ensure_ascii=False))+ else:+ print(f"Done. Your models stay in {st['from']}; the partial copies in {st['to']} were removed.")+ return 0+ a.to, a.source, a.resume, a.status, a.leave = st["to"], st["from"], False, False, False+ return _models_move(a)++def _import_words(plan: dict) -> str:"""The plain-words result of `strata models import --plan`: what the files are, what is already set up, what changes (nothing)."""cand = plan.get("candidate_selection") or {}diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.pyindex 62807cf79..bd401cd3f 100644--- a/strata_cli/launch/cmd.py+++ b/strata_cli/launch/cmd.py@@ -317,6 +317,17 @@ def _say(line: str = "") -> None:sys.stdout.flush()+def _interrupted_move_notice() -> None:+ """One line when a move of the models folder was left unfinished (never blocks the launch)."""+ try:+ from strata_control import discovery, models_move+ st = models_move.interrupted(discovery.data_dir(Path.home() / "Strata")[0])+ except Exception:+ return+ if st:+ _say("A move of your models was interrupted. Finish it with `strata models move --resume`, or keep them where they are with `strata models move --leave`.")++def _printer(quiet: bool = False):"""An emit callback that prints readable lines: new text once, progress in steps of 10% when not on a terminal."""state = {"last": None, "pct": -10, "stage": None}@@ -547,6 +558,8 @@ def run_launch(a: argparse.Namespace) -> int:if a.model or a.model_path:return fail(str(e), 5)s, notices = settings_from_args(a, catalog)+ if not machine:+ _interrupted_move_notice()have_choices = bool(a.preset or a.model or a.model_path or a.context or a.vision or a.parallel or a.access or a.tune)interactive = sys.stdin.isatty() and sys.stdout.isatty() and not a.no_tui and not machine and not a.planplain_questions = Falsediff --git a/strata_control/models_move.py b/strata_control/models_move.pyindex e42a4b8da..8929ab9b1 100644--- a/strata_control/models_move.py+++ b/strata_control/models_move.py@@ -272,12 +272,6 @@ def _read_state(new: Path) -> dict:return {}-def interrupted(data: Path) -> dict | None:- """The unfinished move recorded in a data folder (``models-move.json``), for 'A move was interrupted'."""- st = _read_state(data)- return st if st.get("state") == "running" else None--def _write_state(new: Path, **fields) -> None:try:tmp = new / (STATE_FILE + ".tmp")@@ -287,6 +281,50 @@ def _write_state(new: Path, **fields) -> None:pass+def _save_state(old: Path, new: Path, **fields) -> None:+ """The state goes in the new folder and, as a pointer, in the old one: the old folder stays the data folder until the move is done,+ so that is where the next start looks."""+ _write_state(new, **fields)+ _write_state(old, **fields)+++def _clear_state(*folders: Path) -> None:+ for f in folders:+ _quiet_remove(Path(f) / STATE_FILE)+++def _same_path(a, b) -> bool:+ try:+ return _same(Path(a), Path(b))+ except (OSError, ValueError, TypeError):+ return False+++def interrupted(data: Path) -> dict | None:+ """The unfinished move recorded in the data folder (``models-move.json``), for 'A move was interrupted. Finish it or leave it'.++ A move that is running right now (its process is alive) is not interrupted. A stopped or failed move that left files in both folders is.+ Returns ``{state, from, to, bytes}`` or None.+ """+ data = Path(data)+ st = _read_state(data)+ if st.get("state") not in ("running", "stopped", "failed") or not st.get("from") or not st.get("to"):+ return None+ if not _same_path(st["from"], data): # a pointer left in some other folder is not ours+ return None+ if not Path(st["from"]).is_dir():+ return None+ pid, token = st.get("pid"), st.get("token")+ if st["state"] == "running" and isinstance(pid, int) and token and pid != os.getpid():+ try:+ from strata_control import procs+ if procs.start_token(pid) == token:+ return None+ except Exception:+ pass+ return st++def repoint_config(cfg_file: Path, old: Path, new: Path) -> bool:"""A run config whose model files moved from ``old`` to ``new`` names them there (each path only when its file is now there and no longerat the old place). Same rule as setup.py repoint_config. Returns whether the file changed."""@@ -366,8 +404,17 @@ def move(old: Path, new: Path, *, on_progress: Callable[[dict], None] | None = Ntodo[e.group].append(e)left = {g: len(v) for g, v in todo.items()}moved_groups: list[str] = []- state = {"state": "running", "from": str(old), "to": str(new), "started": now(), "bytes": total}- _write_state(new, **state)+ before = _read_state(old)+ if not (_same_path(before.get("from", ""), old) and _same_path(before.get("to", ""), new)):+ before = {}+ try:+ from strata_control import procs+ token = procs.start_token(os.getpid())+ except Exception:+ token = None+ state = {"state": "running", "from": str(old), "to": str(new), "started": now(), "bytes": total, "pid": os.getpid(), "token": token,+ "files": sorted({e.rel for e in entries} | set(before.get("files") or []))}+ _save_state(old, new, **state)done_bytes = 0files_moved = 0last_emit = [0.0]@@ -459,22 +506,68 @@ def move(old: Path, new: Path, *, on_progress: Callable[[dict], None] | None = Nrepoint()repoint()state.update(state="done", finished=now())- _write_state(new, **state)- _quiet_remove(new / STATE_FILE)+ _clear_state(old, new)return {"done": True, "stopped": False, "moved": moved_groups, "remaining": [], "bytes_moved": done_bytes, "total_bytes": total,"files_moved": files_moved, "same_drive": same}except Stopped:repoint()state.update(state="stopped")- _write_state(new, **state)- _quiet_remove(new / STATE_FILE) if not moved_groups and not files_moved else None+ if files_moved:+ _save_state(old, new, **state)+ else:+ _clear_state(old, new)remaining = [g for g, n in left.items() if n > 0]return {"done": False, "stopped": True, "moved": moved_groups, "remaining": remaining, "bytes_moved": done_bytes, "total_bytes": total,"files_moved": files_moved, "same_drive": same}except MoveError as err:repoint()state.update(state="failed", error=err.code)- _write_state(new, **state)+ if files_moved:+ _save_state(old, new, **state)+ else:+ _clear_state(old, new)err.summary = {"moved": moved_groups, "remaining": [g for g, n in left.items() if n > 0], "bytes_moved": done_bytes, "total_bytes": total,"files_moved": files_moved}raise+++def leave(old: Path, new: Path, *, configs: list[Path] | None = None) -> dict:+ """'Leave it': give up an unfinished move and keep the old folder as the complete one.++ Only the files the move itself listed are touched. A copy in the new folder whose original is still in the old one is removed; a file+ that exists only in the new folder (its original went after a checked copy) is put back in the old folder, so nothing is lost.+ ``.part`` files are removed and the run configs point at the old folder again. Returns ``{removed, restored, bytes_removed}``.+ """+ old, new = Path(old), Path(new)+ st = _read_state(old) or _read_state(new)+ rels = [r for r in (st.get("files") or []) if isinstance(r, str) and r and ".." not in Path(r).parts and not Path(r).is_absolute()]+ removed = restored = bytes_removed = 0+ for rel in rels:+ src, dst = old / rel, new / rel+ _quiet_remove(Path(str(dst) + ".part"))+ if not dst.exists():+ continue+ try:+ size = dst.stat().st_size+ if src.exists():+ os.remove(dst)+ removed += 1+ bytes_removed += size+ else:+ src.parent.mkdir(parents=True, exist_ok=True)+ if same_drive(old, new):+ os.replace(dst, src)+ else:+ _copy_verified(dst, src, size, lambda: False, lambda n: None)+ os.remove(dst)+ restored += 1+ except OSError as e:+ raise MoveError("io", f"Strata could not clean up {dst.name}.", f"{type(e).__name__}: {e}") from e+ _prune(dst.parent, new)+ for cfg in (configs or []):+ try:+ repoint_config(cfg, new, old)+ except OSError:+ pass+ _clear_state(old, new)+ return {"removed": removed, "restored": restored, "bytes_removed": bytes_removed}diff --git a/tests/terminal/test_models_move.py b/tests/terminal/test_models_move.pyindex 80a1408b0..b11fec0b4 100644--- a/tests/terminal/test_models_move.py+++ b/tests/terminal/test_models_move.py@@ -52,6 +52,22 @@ class MoveCase(unittest.TestCase):"""Another drive: the files are copied, whatever this machine's volumes are."""return mock.patch.object(mm, "same_drive", return_value=False)+ def break_after(self, n):+ """A copy that works n times, then fails: a move cut off part way."""+ real, calls = mm._copy_verified, [0]++ def flaky(*args, **kw):+ calls[0] += 1+ if calls[0] > n:+ raise mm.MoveError("io", "cut off")+ return real(*args, **kw)+ return mock.patch.object(mm, "_copy_verified", side_effect=flaky)++ def cut_off(self, n=1):+ with self.copy_mode(), self.break_after(n):+ with self.assertRaises(mm.MoveError):+ self.run_move()+def run_move(self, **kw):events = []summary = mm.move(self.old, self.new, on_progress=events.append, configs=[self.config], **kw)@@ -222,13 +238,68 @@ class MoveTests(MoveCase):self.check_whole()def test_an_interrupted_move_is_remembered(self):+ self.cut_off(1)+ st = mm.interrupted(self.old) # the old folder is still the data folder: it holds the pointer+ self.assertEqual(st["to"], str(self.new))+ self.assertEqual(st["state"], "failed")+ self.assertEqual(mm.interrupted(self.base / "elsewhere"), None)+ mm._write_state(self.old, state="running", pid=os.getpid() + 7, token=None, **{"from": str(self.old), "to": str(self.new)})+ self.assertEqual(mm.interrupted(self.old)["state"], "running")++ def test_a_move_that_is_running_now_is_not_interrupted(self):+ from strata_control import procs+ mm._write_state(self.old, state="running", pid=os.getpid() + 7, token="t", **{"from": str(self.old), "to": str(self.new)})+ with mock.patch.object(procs, "start_token", return_value="t"):+ self.assertIsNone(mm.interrupted(self.old))+ with mock.patch.object(procs, "start_token", return_value=None):+ self.assertIsNotNone(mm.interrupted(self.old))++ def test_nothing_moved_leaves_nothing_to_ask_about(self):+ self.cut_off(0)+ self.assertIsNone(mm.interrupted(self.old))+ self.assertFalse((self.new / mm.STATE_FILE).exists())++ def test_finish_resumes_the_move(self):+ self.cut_off(1)+ st = mm.interrupted(self.old)with self.copy_mode():- with self.assertRaises(mm.MoveError):- with mock.patch.object(mm, "_copy_verified", side_effect=mm.MoveError("io", "x")):- self.run_move()- self.assertEqual(mm.interrupted(self.new), None) # failed is not "running"- mm._write_state(self.new, state="running", **{"from": str(self.old), "to": str(self.new)})- self.assertEqual(mm.interrupted(self.new)["from"], str(self.old))+ summary = mm.move(Path(st["from"]), Path(st["to"]), configs=[self.config])+ self.assertTrue(summary["done"])+ self.check_whole()+ self.assertIsNone(mm.interrupted(self.old))+ self.assertFalse((self.old / mm.STATE_FILE).exists() or (self.new / mm.STATE_FILE).exists())++ def test_leave_keeps_the_old_folder_complete(self):+ self.cut_off(1)+ (self.new / "models/stray.gguf.part").write_bytes(b"x") # not listed by the move, but a .part of ours is+ (self.new / "models/gyro-s").mkdir(parents=True, exist_ok=True)+ (self.new / "models/gyro-s/a.gguf.part").write_bytes(b"cut")+ theirs = self.new / "models/own/mine.gguf" # a file of the person's, not part of the move+ theirs.parent.mkdir(parents=True)+ theirs.write_bytes(b"mine")+ st = mm.interrupted(self.old)+ with self.copy_mode():+ result = mm.leave(Path(st["from"]), Path(st["to"]), configs=[self.config])+ self.assertGreaterEqual(result["restored"] + result["removed"], 1)+ for rel, data in self.files.items():+ self.assertEqual((self.old / rel).read_bytes(), data, rel)+ self.assertFalse((self.new / rel).exists(), rel)+ self.assertEqual(list(self.new.rglob("*.part")), [(self.new / "models/stray.gguf.part")])+ self.assertTrue(theirs.exists())+ self.assertIsNone(mm.interrupted(self.old))+ self.assertFalse((self.new / mm.STATE_FILE).exists())+ cfg = json.loads(self.config.read_text())+ self.assertTrue(all(str(self.new) not in str(v) for v in cfg.values()))+ self.assertIn(str(self.old / "models/gyro-s/a.gguf"), cfg["args"])++ def test_leave_after_a_crash_removes_the_duplicate(self):+ self.cut_off(1)+ dup = self.new / "models/coder/c.gguf" # copied and renamed, original not yet removed+ dup.parent.mkdir(parents=True, exist_ok=True)+ dup.write_bytes(self.files["models/coder/c.gguf"])+ mm.leave(self.old, self.new)+ self.assertFalse(dup.exists())+ self.assertTrue((self.old / "models/coder/c.gguf").exists())def test_configs_are_rewritten_only_for_files_that_are_there(self):self.config.write_text(json.dumps({"args": ["--native", str(self.old / "models/gone.gguf")]}))@@ -265,6 +336,52 @@ class CommandLineTests(MoveCase):self.assertTrue(lines[-1]["done"])self.assertTrue((self.new / "models/coder/c.gguf").exists())+ def run_cli(self, *argv):+ from strata_cli import cli+ from strata_control import discovery+ import contextlib+ import io+ out = io.StringIO()+ with contextlib.redirect_stdout(out), self.copy_mode(), mock.patch.object(discovery, "data_dir", return_value=(self.old, "settings")):+ code = cli.main(["models", "move", *argv])+ return code, out.getvalue()++ def test_status_resume_and_leave(self):+ code, text = self.run_cli("--status", "--output", "json")+ self.assertEqual((code, json.loads(text)["interrupted"]), (0, None))+ self.assertEqual(self.run_cli("--resume", "--output", "json")[0], 5)+ self.cut_off(1)+ code, text = self.run_cli("--status", "--output", "json")+ self.assertEqual(json.loads(text)["interrupted"]["to"], str(self.new))+ self.assertIn("--resume", self.run_cli("--status")[1])+ code, text = self.run_cli("--leave", "--install-dir", str(self.install), "--output", "json")+ self.assertEqual(code, 0, text)+ self.assertTrue((self.old / "models/coder/c.gguf").exists())+ self.cut_off(1)+ code, text = self.run_cli("--resume", "--install-dir", str(self.install), "--output", "jsonl")+ self.assertEqual(code, 0, text)+ self.assertTrue([json.loads(l) for l in text.splitlines() if l.startswith("{")][-1]["done"])+ self.assertTrue((self.new / "models/coder/c.gguf").exists())+ self.assertFalse((self.old / "models/coder/c.gguf").exists())++ def test_launch_says_it_in_one_line(self):+ from strata_cli.launch import cmd+ from strata_control import discovery+ import contextlib+ import io+ self.cut_off(1)+ with mock.patch.object(discovery, "data_dir", return_value=(self.old, "settings")):+ out = io.StringIO()+ with contextlib.redirect_stdout(out):+ cmd._interrupted_move_notice()+ self.assertEqual(len(out.getvalue().strip().splitlines()), 1)+ self.assertIn("models move --resume", out.getvalue())+ mm.leave(self.old, self.new)+ out = io.StringIO()+ with contextlib.redirect_stdout(out):+ cmd._interrupted_move_notice()+ self.assertEqual(out.getvalue(), "")+def test_the_cancel_file_stops_the_run(self):from strata_cli import cliimport contextlib