Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(runtime): clean every managed runtime consumer (#1722)
Call White361fc7ba3510
diff --git a/tests/test_show_runtime_archive_cleanup.py b/tests/test_show_runtime_archive_cleanup.pyindex 2560d0adc..6890d544e 100644--- a/tests/test_show_runtime_archive_cleanup.py+++ b/tests/test_show_runtime_archive_cleanup.py@@ -574,7 +574,7 @@ def test_partial_removal_reports_removed_and_failed_counts(monkeypatch, capsys)lambda *, keep_previous, dry_run=False: {"ok": True, "removed": []},)- assert vibe_cli.cmd_runtime(args) == 0+ assert vibe_cli.cmd_runtime(args) == 1captured = capsys.readouterr()assert "2" in captured.out # successful removal total still reportedassert "1" in captured.err # failed count reported as a warning@@ -798,7 +798,7 @@ def test_skipped_archives_do_not_hide_other_cleanup_results(monkeypatch, capsys)lambda *, keep_previous, dry_run=False: {"ok": True, "removed": ["git-old"]},)- assert vibe_cli.cmd_runtime(args) == 0+ assert vibe_cli.cmd_runtime(args) == 1captured = capsys.readouterr()assert "runtime_install_already_running" in captured.err # archive skip reason surfacedassert "1" in captured.out # Show Runtime install result still reported@@ -915,7 +915,7 @@ def test_cli_clean_reports_skipped_archives_without_zero_counts(monkeypatch, caplambda *, keep_previous, dry_run=False: {"ok": True, "removed": []},)- assert vibe_cli.cmd_runtime(args) == 0+ assert vibe_cli.cmd_runtime(args) == 1captured = capsys.readouterr()assert "runtime_install_already_running" in captured.err# The archive skip is reported as a warning; Show/Git results still renderdiff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex 79a9f50ab..a8f91beba 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -1,4 +1,5 @@import asyncio+import hashlibimport jsonimport osimport pytest@@ -2728,6 +2729,410 @@ def test_runtime_prepare_force_does_not_report_explicit_command_as_replaced(monkassert "VIBE_SHOW_RUNTIME_BIN" in captured.err[email protected]("consumer", ["memory", "model-hub"])+def test_runtime_clean_reclaims_each_shared_consumer_in_preview_and_real_run(+ monkeypatch,+ capsys,+ tmp_path,+ consumer,+):+ if consumer == "memory":+ from core.memory.artifact import MemoryArtifactManager++ manager = MemoryArtifactManager(+ runtime_dir=tmp_path / "memory-runtime",+ provider_root=tmp_path / "memory-provider",+ offline=True,+ )+ else:+ from vibe.model_hub_runtime.installer import EngineRuntimeManager++ manager = EngineRuntimeManager(+ runtime_dir=tmp_path / "model-hub-runtime",+ offline=True,+ )++ from core.managed_runtime import runtime_platform_tag++ versions_dir = manager.runtime_dir / "versions"+ current_install = versions_dir / "current"+ stale_install = versions_dir / "stale"+ current_install.mkdir(parents=True)+ stale_install.mkdir()+ manifest_sha = "a" * 64+ current_archive_sha = "b" * 64+ stale_archive_sha = "c" * 64+ binary_sha = hashlib.sha256(b"fixture").hexdigest()+ for install_dir, version, archive_sha in (+ (current_install, "current", current_archive_sha),+ (stale_install, "stale", stale_archive_sha),+ ):+ binary = install_dir / manager.spec.default_bin_path+ binary.parent.mkdir(parents=True, exist_ok=True)+ binary.write_text("fixture", encoding="utf-8")+ binary.chmod(0o755)+ (install_dir / manager.spec.metadata_filename).write_text(+ json.dumps(+ {+ "provider": "manifest",+ "runtime_id": manager.spec.runtime_id,+ "runtime_version": version,+ "platform": runtime_platform_tag(),+ "manifest_sha256": manifest_sha,+ "manifest_source": "package:tests/runtime-manifest.json",+ "archive_name": f"fixture-{version}.tar.gz",+ "archive_sha256": archive_sha,+ "binary_sha256": binary_sha,+ "bin_path": manager.spec.default_bin_path,+ }+ ),+ encoding="utf-8",+ )+ (manager.runtime_dir / "current.json").write_text(+ json.dumps(+ {+ "provider": "manifest",+ "runtime_id": manager.spec.runtime_id,+ "runtime_version": "current",+ "platform": runtime_platform_tag(),+ "install_dir": str(current_install),+ "manifest_sha256": manifest_sha,+ "archive_sha256": current_archive_sha,+ "bin_path": manager.spec.default_bin_path,+ }+ ),+ encoding="utf-8",+ )++ class FakeShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {+ "ok": True,+ "removed": [],+ "archives": {"removed_count": 0, "candidate_count": 0},+ }++ def clean_consumer(*, keep_previous, dry_run):+ assert keep_previous == 0+ return manager.clean(keep_previous=keep_previous, dry_run=dry_run)++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FakeShowRuntimeManager())+ monkeypatch.setattr(+ cli,+ "_managed_runtime_cleaners",+ lambda: ((manager.spec.runtime_id, clean_consumer),),+ )+ parser = cli.build_parser()++ preview_args = parser.parse_args(+ ["runtime", "clean", "--keep-previous", "0", "--dry-run", "--json"]+ )+ assert cli.cmd_runtime(preview_args) == 0+ preview = json.loads(capsys.readouterr().out)+ assert str(stale_install) in preview[manager.spec.runtime_id]["removed"]+ assert current_install.is_dir()+ assert stale_install.is_dir()++ real_args = parser.parse_args(+ ["runtime", "clean", "--keep-previous", "0", "--json"]+ )+ assert cli.cmd_runtime(real_args) == 0+ cleaned = json.loads(capsys.readouterr().out)+ assert str(stale_install) in cleaned[manager.spec.runtime_id]["removed"]+ assert current_install.is_dir()+ assert not stale_install.exists()+++def test_runtime_clean_registry_invokes_every_current_shared_consumer(monkeypatch):+ from core.memory import artifact as memory_artifact+ from vibe.model_hub_runtime import installer as model_hub_installer++ calls = []++ def clean_git(*, keep_previous, dry_run):+ calls.append(("git", keep_previous, dry_run))+ return {"ok": True, "removed": []}++ class FakeManager:+ def __init__(self, runtime_id):+ self.runtime_id = runtime_id++ def clean(self, *, keep_previous, dry_run):+ calls.append((self.runtime_id, keep_previous, dry_run))+ return {"ok": True, "removed": []}++ monkeypatch.setattr(cli, "_clean_git_runtime", clean_git)+ monkeypatch.setattr(+ memory_artifact,+ "get_memory_artifact_manager",+ lambda: FakeManager("memory-runtime"),+ )+ monkeypatch.setattr(+ model_hub_installer,+ "EngineRuntimeManager",+ lambda: FakeManager("model_hub_engine"),+ )++ results = cli._clean_managed_runtime_consumers(keep_previous=2, dry_run=True)++ assert list(results) == [+ "git",+ "memory-runtime",+ "model_hub_engine",+ ]+ assert calls == [+ ("git", 2, True),+ ("memory-runtime", 2, True),+ ("model_hub_engine", 2, True),+ ]+++def test_runtime_clean_returns_nonzero_and_reports_git_exception_reason(monkeypatch, capsys):+ from core import git_runtime++ class FakeShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": [], "archives": {"removed_count": 0}}++ def fail_git_manager():+ raise OSError("git runtime directory unreadable")++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FakeShowRuntimeManager())+ monkeypatch.setattr(git_runtime, "get_git_runtime_manager", fail_git_manager)+ monkeypatch.setattr(cli, "_managed_runtime_cleaners", lambda: (("git", cli._clean_git_runtime),))+ args = cli.build_parser().parse_args(["runtime", "clean"])++ assert cli.cmd_runtime(args) == 1+ captured = capsys.readouterr()+ assert "git_clean_failed" in captured.err+ assert "Git Runtime" in captured.err+++def test_runtime_clean_returns_nonzero_for_show_failure_without_false_archive_success(monkeypatch, capsys):+ class FailingShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {+ "ok": False,+ "removed": [],+ "archives": {+ "outcome": "skipped",+ "skipped_reason": "archive_inspection_failed",+ },+ }++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FailingShowRuntimeManager())+ monkeypatch.setattr(cli, "_managed_runtime_cleaners", lambda: ())+ args = cli.build_parser().parse_args(["runtime", "clean"])++ assert cli.cmd_runtime(args) == 1+ captured = capsys.readouterr()+ assert "archive_inspection_failed" in captured.err+ assert "unknown" not in captured.err+ assert "downloaded Show Runtime archive" not in captured.out+++ ("archives", "expected_reason", "prints_partial_summary"),+ [+ (+ {+ "outcome": "skipped",+ "skipped_reason": "archive_inspection_failed",+ "failed_count": 0,+ },+ "archive_inspection_failed",+ False,+ ),+ ({"outcome": "skipped", "failed_count": 1}, "archive_removal_failed", False),+ ({"outcome": "partial", "failed_count": 0}, "archive_removal_failed", True),+ ],+)+def test_runtime_clean_nested_show_archive_failure_controls_output_and_exit(+ monkeypatch,+ capsys,+ archives,+ expected_reason,+ prints_partial_summary,+):+ class ShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": [], "archives": archives}++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: ShowRuntimeManager())+ monkeypatch.setattr(cli, "_managed_runtime_cleaners", lambda: ())+ args = cli.build_parser().parse_args(["runtime", "clean"])++ assert cli.cmd_runtime(args) == 1+ captured = capsys.readouterr()+ assert expected_reason in captured.err+ if prints_partial_summary:+ assert "archive(s) could not be removed" in captured.err+ else:+ assert "downloaded Show Runtime archive(s) (0 B)" not in captured.out+++def test_runtime_clean_dry_run_partial_archive_preview_is_success(monkeypatch, capsys):+ class ShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {+ "ok": True,+ "removed": [],+ "archives": {+ "outcome": "partial",+ "candidate_count": 1,+ "candidate_bytes": 1024,+ "failed_count": 0,+ },+ }++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: ShowRuntimeManager())+ monkeypatch.setattr(cli, "_managed_runtime_cleaners", lambda: ())+ args = cli.build_parser().parse_args(["runtime", "clean", "--dry-run"])++ assert cli.cmd_runtime(args) == 0+ captured = capsys.readouterr()+ assert "Would remove 1 downloaded Show Runtime archive(s) (1.0 KiB)." in captured.out+ assert captured.err == ""+++def test_runtime_clean_json_keeps_nested_failure_payload_and_exits_nonzero(monkeypatch, capsys):+ archives = {+ "outcome": "skipped",+ "skipped_reason": "archive_inspection_failed",+ "failed_count": 0,+ }++ class ShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": [], "archives": archives}++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: ShowRuntimeManager())+ monkeypatch.setattr(cli, "_managed_runtime_cleaners", lambda: ())+ args = cli.build_parser().parse_args(["runtime", "clean", "--json"])++ assert cli.cmd_runtime(args) == 1+ captured = capsys.readouterr()+ assert json.loads(captured.out)["archives"] == archives+ assert captured.err == ""+++def test_runtime_clean_success_reports_every_consumer_and_exits_zero(monkeypatch, capsys):+ class FakeShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": ["show-old"], "archives": {"removed_count": 0}}++ def cleaner(count):+ return lambda **_kwargs: {"ok": True, "removed": [f"old-{index}" for index in range(count)]}++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FakeShowRuntimeManager())+ monkeypatch.setattr(+ cli,+ "_managed_runtime_cleaners",+ lambda: (+ ("git", cleaner(1)),+ ("memory-runtime", cleaner(2)),+ ("model_hub_engine", cleaner(3)),+ ),+ )+ args = cli.build_parser().parse_args(["runtime", "clean"])++ assert cli.cmd_runtime(args) == 0+ captured = capsys.readouterr()+ assert "Removed 1 Git Runtime cache item(s)." in captured.out+ assert "Removed 2 Memory Runtime cache item(s)." in captured.out+ assert "Removed 3 Model Hub Runtime cache item(s)." in captured.out+ assert captured.err == ""+++def test_runtime_clean_previews_shared_consumer_archive_candidates(monkeypatch, capsys):+ class FakeShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": [], "archives": {"candidate_count": 0}}++ def clean_memory(**_kwargs):+ return {+ "ok": True,+ "removed": [],+ "archives": {+ "candidate_count": 2,+ "candidate_bytes": 2048,+ },+ }++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FakeShowRuntimeManager())+ monkeypatch.setattr(+ cli,+ "_managed_runtime_cleaners",+ lambda: (("memory-runtime", clean_memory),),+ )+ args = cli.build_parser().parse_args(["runtime", "clean", "--dry-run"])++ assert cli.cmd_runtime(args) == 0+ captured = capsys.readouterr()+ assert "Would remove 2 downloaded Memory Runtime archive(s) (2.0 KiB)." in captured.out+ assert captured.err == ""+++def test_runtime_clean_does_not_render_shared_archive_failure_as_zero_success(monkeypatch, capsys):+ class FakeShowRuntimeManager:+ def clean(self, *, keep_previous=1, dry_run=False):+ return {"ok": True, "removed": [], "archives": {"removed_count": 0}}++ def clean_memory(**_kwargs):+ return {+ "ok": True,+ "removed": [],+ "archives": {+ "outcome": "skipped",+ "skipped_reason": "archive_inspection_failed",+ },+ }++ monkeypatch.setattr(cli, "_show_runtime_manager_from_args", lambda _args: FakeShowRuntimeManager())+ monkeypatch.setattr(+ cli,+ "_managed_runtime_cleaners",+ lambda: (("memory-runtime", clean_memory),),+ )+ args = cli.build_parser().parse_args(["runtime", "clean"])++ assert cli.cmd_runtime(args) == 1+ captured = capsys.readouterr()+ assert "Memory Runtime cleanup failed (archive_inspection_failed)" in captured.err+ assert "archive_inspection_failed" in captured.err+ assert "downloaded Memory Runtime archive" not in captured.out++[email protected]("help_args", [("runtime", "--help"), ("runtime", "clean", "--help")])+ ("language", "consumer_scope", "failure_contract"),+ [+ ("en", "Show, Git, Memory, and Model Hub", "exit nonzero if any cleanup fails"),+ ("zh", "Show、Git、Memory 和 Model Hub", "任一清理失败时以非零状态退出"),+ ],+)+def test_runtime_clean_help_names_consumers_and_failure_exit(+ monkeypatch,+ capsys,+ help_args,+ language,+ consumer_scope,+ failure_contract,+):+ monkeypatch.setenv("COLUMNS", "240")+ monkeypatch.setattr(cli, "_configured_cli_language", lambda: language)+ parser = cli.build_parser()++ with pytest.raises(SystemExit) as exc_info:+ parser.parse_args(help_args)++ assert exc_info.value.code == 0+ output = capsys.readouterr().out+ assert cli.i18n_t("runtime.clean.commandHelp", language) in output+ assert consumer_scope in output+ assert failure_contract in output++@pytest.mark.parametrize("legacy_source", ["github", "github-source", "GitHub-Source"])def test_runtime_manager_migrates_legacy_source_to_packaged_manifest(monkeypatch,diff --git a/vibe/cli.py b/vibe/cli.pyindex bd15b5ae6..2d3a1c9cf 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -14589,25 +14589,42 @@ def cmd_runtime(args) -> int:return 1 if getattr(args, "strict", False) and not strict_ok else 0if command == "clean":dry_run = bool(getattr(args, "dry_run", False))+ keep_previous = getattr(args, "keep_previous", 1)payload = manager.clean(- keep_previous=getattr(args, "keep_previous", 1),+ keep_previous=keep_previous,dry_run=dry_run,)- git = _clean_git_runtime(keep_previous=getattr(args, "keep_previous", 1), dry_run=dry_run)- payload["git"] = git+ managed_runtimes = _clean_managed_runtime_consumers(+ keep_previous=keep_previous,+ dry_run=dry_run,+ )+ payload.update(managed_runtimes)+ show_verdict = _runtime_clean_verdict(payload, dry_run=dry_run)+ managed_verdicts = {+ runtime_id: _runtime_clean_verdict(result, dry_run=dry_run)+ for runtime_id, result in managed_runtimes.items()+ }if getattr(args, "json", False):print(json.dumps(payload, indent=2))else:language = _configured_cli_language()- archives = payload.get("archives") or {}+ archives_value = payload.get("archives")+ archives = archives_value if isinstance(archives_value, Mapping) else {}skipped_reason = str(archives.get("skipped_reason") or "")outcome = str(archives.get("outcome") or "")- # Show/Git results are reported independently of the archive+ # Consumer results are reported independently of the Show archive# outcome: a skipped archive pass must not hide what the rest of# the cleanup actually reclaimed (or would reclaim).prefix_key = "runtime.clean.wouldRemove" if dry_run else "runtime.clean.removed"removed = payload.get("removed") or []print(i18n_t(f"{prefix_key}Items", language, count=len(removed)))+ if show_verdict.failed:+ _print_runtime_clean_failure(+ consumer="Show Runtime",+ reason=show_verdict.reason,+ dry_run=dry_run,+ language=language,+ )is_partial_run = outcome == "partial" and not dry_runif is_partial_run:print(@@ -14642,7 +14659,7 @@ def cmd_runtime(args) -> int:else "runtime.clean.skipped")print(i18n_t(skip_key, language, reason=skipped_reason), file=sys.stderr)- else:+ elif not show_verdict.archives_failed and (archives or not show_verdict.failed):archive_count = int(archives.get("candidate_count") or 0) if dry_run else int(archives.get("removed_count") or 0)archive_bytes = int(archives.get("candidate_bytes") or 0) if dry_run else int(archives.get("removed_bytes") or 0)print(@@ -14653,12 +14670,16 @@ def cmd_runtime(args) -> int:size=_format_byte_size(archive_bytes),))- if git.get("ok") is False and git.get("reason"):- git_skip_key = "runtime.clean.gitSkippedPreview" if dry_run else "runtime.clean.gitSkipped"- print(i18n_t(git_skip_key, language, reason=git["reason"]), file=sys.stderr)- else:- print(i18n_t(f"{prefix_key}Git", language, count=len(git.get("removed") or [])))- return 0+ for runtime_id, result in managed_runtimes.items():+ _print_managed_runtime_clean_result(+ runtime_id=runtime_id,+ result=result,+ dry_run=dry_run,+ language=language,+ verdict=managed_verdicts[runtime_id],+ )+ failed = show_verdict.failed or any(verdict.failed for verdict in managed_verdicts.values())+ return 1 if failed else 0raise TaskCliError("runtime command is required", code="invalid_arguments", help_command="vibe runtime --help")@@ -14798,13 +14819,198 @@ def _format_byte_size(size: int) -> str:return f"{size:.1f} PiB"+def _managed_runtime_cleaners() -> tuple[tuple[str, Callable[..., dict[str, Any]]], ...]:+ """Return the shared-runtime cleanup passes in stable output order."""++ from core.memory.artifact import get_memory_artifact_manager+ from vibe.model_hub_runtime.installer import EngineRuntimeManager++ def clean_memory(*, keep_previous: int, dry_run: bool) -> dict[str, Any]:+ return get_memory_artifact_manager().clean(+ keep_previous=keep_previous,+ dry_run=dry_run,+ )++ def clean_model_hub(*, keep_previous: int, dry_run: bool) -> dict[str, Any]:+ return EngineRuntimeManager().clean(+ keep_previous=keep_previous,+ dry_run=dry_run,+ )++ return (+ ("git", _clean_git_runtime),+ ("memory-runtime", clean_memory),+ ("model_hub_engine", clean_model_hub),+ )+++def _clean_managed_runtime_consumers(*, keep_previous: int, dry_run: bool = False) -> dict[str, dict[str, Any]]:+ results: dict[str, dict[str, Any]] = {}+ for runtime_id, cleaner in _managed_runtime_cleaners():+ try:+ result = cleaner(keep_previous=keep_previous, dry_run=dry_run)+ if not isinstance(result, Mapping):+ raise TypeError("runtime cleanup returned a non-mapping result")+ results[runtime_id] = dict(result)+ except Exception as exc: # noqa: BLE001+ results[runtime_id] = {+ "ok": False,+ "removed": [],+ "reason": f"{runtime_id}_clean_failed",+ "message": str(exc),+ }+ return results+++@dataclass(frozen=True)+class _RuntimeCleanVerdict:+ reason: str | None+ archives_failed: bool++ @property+ def failed(self) -> bool:+ return self.reason is not None+++def _runtime_clean_verdict(result: Mapping[str, Any], *, dry_run: bool) -> _RuntimeCleanVerdict:+ archives_value = result.get("archives")+ archives = archives_value if isinstance(archives_value, Mapping) else {}+ archive_reason = archives.get("skipped_reason")+ failed_count = archives.get("failed_count")+ archives_failed = bool(archive_reason) or (+ not dry_run+ and (+ archives.get("outcome") == "partial"+ or (isinstance(failed_count, (int, float)) and failed_count > 0)+ )+ )+ nested_reason = archive_reason or ("archive_removal_failed" if archives_failed else None)+ ok = result.get("ok")+ reason = result.get("reason")+ top_level_failed = ok is False or (ok is not True and bool(reason))+ if not top_level_failed and not archives_failed:+ return _RuntimeCleanVerdict(reason=None, archives_failed=False)+ return _RuntimeCleanVerdict(+ reason=str(reason or nested_reason or "unknown"),+ archives_failed=archives_failed,+ )+++def _managed_runtime_label(runtime_id: str) -> str:+ labels = {+ "git": "Git Runtime",+ "memory-runtime": "Memory Runtime",+ "model_hub_engine": "Model Hub Runtime",+ }+ return labels.get(runtime_id, runtime_id.replace("-", " ").replace("_", " ").title())+++def _print_runtime_clean_failure(+ *,+ consumer: str,+ reason: str | None,+ dry_run: bool,+ language: str,+) -> None:+ key = "runtime.clean.consumerPreviewFailed" if dry_run else "runtime.clean.consumerFailed"+ print(+ i18n_t(+ key,+ language,+ consumer=consumer,+ reason=reason or "unknown",+ ),+ file=sys.stderr,+ )+++def _print_managed_runtime_clean_result(+ *,+ runtime_id: str,+ result: Mapping[str, Any],+ dry_run: bool,+ language: str,+ verdict: _RuntimeCleanVerdict,+) -> None:+ consumer = _managed_runtime_label(runtime_id)+ prefix_key = "runtime.clean.consumerWouldRemove" if dry_run else "runtime.clean.consumerRemoved"+ removed = result.get("removed")+ removed_count = len(removed) if isinstance(removed, list) else 0+ print(i18n_t(f"{prefix_key}Items", language, consumer=consumer, count=removed_count))++ if verdict.failed:+ _print_runtime_clean_failure(+ consumer=consumer,+ reason=verdict.reason,+ dry_run=dry_run,+ language=language,+ )++ archives_value = result.get("archives")+ if not isinstance(archives_value, Mapping) or not archives_value:+ return+ archives = archives_value+ skipped_reason = str(archives.get("skipped_reason") or "")+ outcome = str(archives.get("outcome") or "")+ if outcome == "partial" and not dry_run:+ print(+ i18n_t(+ "runtime.clean.consumerRemovedArchives",+ language,+ consumer=consumer,+ count=int(archives.get("removed_count") or 0),+ size=_format_byte_size(int(archives.get("removed_bytes") or 0)),+ )+ )+ print(+ i18n_t(+ "runtime.clean.consumerArchivesPartial",+ language,+ consumer=consumer,+ reason=skipped_reason or "archive_removal_failed",+ failed=int(archives.get("failed_count") or 0),+ ),+ file=sys.stderr,+ )+ return+ if skipped_reason:+ print(+ i18n_t(+ "runtime.clean.consumerArchivesSkipped",+ language,+ consumer=consumer,+ reason=skipped_reason,+ ),+ file=sys.stderr,+ )+ return+ if verdict.archives_failed:+ return+ count_key = "candidate_count" if dry_run else "removed_count"+ bytes_key = "candidate_bytes" if dry_run else "removed_bytes"+ print(+ i18n_t(+ f"{prefix_key}Archives",+ language,+ consumer=consumer,+ count=int(archives.get(count_key) or 0),+ size=_format_byte_size(int(archives.get(bytes_key) or 0)),+ )+ )++def _clean_git_runtime(*, keep_previous: int, dry_run: bool = False) -> dict:try:from core.git_runtime import get_git_runtime_managerreturn get_git_runtime_manager().clean(keep_previous=keep_previous, dry_run=dry_run)except Exception as exc: # noqa: BLE001- return {"ok": False, "removed": [], "message": str(exc)}+ return {+ "ok": False,+ "removed": [],+ "reason": "git_clean_failed",+ "message": str(exc),+ }def _ensure_avault_during_prepare(offline: bool = False, force: bool = False) -> dict:@@ -15060,12 +15266,18 @@ def build_parser():runtime_prepare_parser.add_argument("--strict", action="store_true", help="Return a non-zero exit code when preparation fails.")runtime_prepare_parser.add_argument("--json", action="store_true", help="Print machine-readable state.")- runtime_clean_parser = runtime_subparsers.add_parser("clean", help="Clean stale managed runtime cache entries")+ runtime_clean_language = _configured_cli_language()+ runtime_clean_help = i18n_t("runtime.clean.commandHelp", runtime_clean_language)+ runtime_clean_parser = runtime_subparsers.add_parser(+ "clean",+ help=runtime_clean_help,+ description=runtime_clean_help,+ )runtime_clean_parser.add_argument("--keep-previous", type=int, default=1, help="Number of previous runtime versions to keep.")runtime_clean_parser.add_argument("--dry-run",action="store_true",- help=i18n_t("runtime.clean.dryRunHelp", _configured_cli_language()),+ help=i18n_t("runtime.clean.dryRunHelp", runtime_clean_language),)runtime_clean_parser.add_argument("--json", action="store_true", help="Print machine-readable state.")remote_parser = subparsers.add_parser(diff --git a/vibe/i18n/en.json b/vibe/i18n/en.jsonindex 618720757..de396ced1 100644--- a/vibe/i18n/en.json+++ b/vibe/i18n/en.json@@ -973,19 +973,24 @@"unsupportedSource": "Show Runtime preparation failed: {reason}. Remove VIBE_SHOW_RUNTIME_SOURCE and use the packaged runtime, or set VIBE_SHOW_RUNTIME_BIN to a runtime you built."},"clean": {+ "commandHelp": "Remove stale Show, Git, Memory, and Model Hub runtime installs and archives; exit nonzero if any cleanup fails.","dryRunHelp": "Report stale archives and cache entries without removing anything.","wouldRemoveItems": "Would remove {count} Show Runtime cache item(s).","wouldRemoveArchives": "Would remove {count} downloaded Show Runtime archive(s) ({size}).",- "wouldRemoveGit": "Would remove {count} Git Runtime cache item(s).",+ "consumerWouldRemoveItems": "Would remove {count} {consumer} cache item(s).",+ "consumerWouldRemoveArchives": "Would remove {count} downloaded {consumer} archive(s) ({size}).","removedItems": "Removed {count} Show Runtime cache item(s).","removedArchives": "Removed {count} downloaded Show Runtime archive(s) ({size}).",- "removedGit": "Removed {count} Git Runtime cache item(s).",+ "consumerRemovedItems": "Removed {count} {consumer} cache item(s).",+ "consumerRemovedArchives": "Removed {count} downloaded {consumer} archive(s) ({size}).",+ "consumerPreviewFailed": "{consumer} cache preview failed ({reason}); stale entries may remain.",+ "consumerFailed": "{consumer} cleanup failed ({reason}); stale entries remain.",+ "consumerArchivesPartial": "{consumer} archive cleanup was partial ({reason}); {failed} archive(s) could not be removed.",+ "consumerArchivesSkipped": "{consumer} archive cleanup skipped ({reason}); stale archives may remain.","partiallyRemoved": " {failed} archive(s) could not be removed; check permissions and the Avibe log.","skipped": "Archive cleanup skipped ({reason}); stale archives may remain. Try again after the running install or cleanup finishes.","removalFailed": "{failed} archive(s) could not be removed; stale archives remain. Check runtime directory permissions and the Avibe log.",- "skippedInspection": "Archive cleanup could not inspect the cache ({reason}); stale archives may remain. Check runtime directory permissions and the Avibe log.",- "gitSkipped": "Git Runtime cleanup skipped ({reason}); stale entries remain.",- "gitSkippedPreview": "Git Runtime cache preview skipped ({reason}); stale entries may remain."+ "skippedInspection": "Archive cleanup could not inspect the cache ({reason}); stale archives may remain. Check runtime directory permissions and the Avibe log."},"doctor": {"archiveCacheReclaimable": "Show Runtime archive cache holds {count} reclaimable archive(s) ({size}); the current and rollback archives are kept.",diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.jsonindex 7bfd181d6..ae2c0b8e9 100644--- a/vibe/i18n/zh.json+++ b/vibe/i18n/zh.json@@ -973,19 +973,24 @@"unsupportedSource": "Show Runtime 准备失败:{reason}。请移除 VIBE_SHOW_RUNTIME_SOURCE 以使用随 Avibe 发布的运行时,或将 VIBE_SHOW_RUNTIME_BIN 指向你自行构建的运行时。"},"clean": {+ "commandHelp": "清理过期的 Show、Git、Memory 和 Model Hub 运行时安装与归档;任一清理失败时以非零状态退出。","dryRunHelp": "\u4ec5\u62a5\u544a\u53ef\u6e05\u7406\u7684\u5f52\u6863\u4e0e\u7f13\u5b58\u6761\u76ee\uff0c\u4e0d\u5220\u9664\u4efb\u4f55\u5185\u5bb9\u3002","wouldRemoveItems": "\u5c06\u6e05\u7406 {count} \u9879 Show Runtime \u7f13\u5b58\u3002","wouldRemoveArchives": "\u5c06\u6e05\u7406 {count} \u4e2a\u5df2\u4e0b\u8f7d\u7684 Show Runtime \u5f52\u6863\uff08{size}\uff09\u3002",- "wouldRemoveGit": "\u5c06\u6e05\u7406 {count} \u9879 Git Runtime \u7f13\u5b58\u3002",+ "consumerWouldRemoveItems": "将清理 {count} 项 {consumer} 缓存。",+ "consumerWouldRemoveArchives": "将清理 {count} 个已下载的 {consumer} 归档({size})。","removedItems": "\u5df2\u6e05\u7406 {count} \u9879 Show Runtime \u7f13\u5b58\u3002","removedArchives": "\u5df2\u6e05\u7406 {count} \u4e2a\u5df2\u4e0b\u8f7d\u7684 Show Runtime \u5f52\u6863\uff08{size}\uff09\u3002",- "removedGit": "\u5df2\u6e05\u7406 {count} \u9879 Git Runtime \u7f13\u5b58\u3002",+ "consumerRemovedItems": "已清理 {count} 项 {consumer} 缓存。",+ "consumerRemovedArchives": "已清理 {count} 个已下载的 {consumer} 归档({size})。",+ "consumerPreviewFailed": "{consumer} 缓存预览失败({reason});可能仍有过期条目。",+ "consumerFailed": "{consumer} 清理失败({reason});过期条目仍保留。",+ "consumerArchivesPartial": "{consumer} 归档清理仅部分完成({reason});有 {failed} 个归档无法清理。",+ "consumerArchivesSkipped": "{consumer} 归档清理已跳过({reason});可能仍有过期归档。","partiallyRemoved": " \u6709 {failed} \u4e2a\u5f52\u6863\u65e0\u6cd5\u5220\u9664\uff1b\u8bf7\u68c0\u67e5\u6743\u9650\u4e0e Avibe \u65e5\u5fd7\u3002","skipped": "\u5f52\u6863\u6e05\u7406\u5df2\u8df3\u8fc7\uff08{reason}\uff09\uff1b\u53ef\u80fd\u4ecd\u6709\u8fc7\u671f\u5f52\u6863\u3002\u8bf7\u5728\u6b63\u5728\u8fd0\u884c\u7684\u5b89\u88c5\u6216\u6e05\u7406\u7ed3\u675f\u540e\u91cd\u8bd5\u3002","removalFailed": "\u6709 {failed} \u4e2a\u5f52\u6863\u65e0\u6cd5\u5220\u9664\uff1b\u8fc7\u671f\u5f52\u6863\u4ecd\u4fdd\u7559\u3002\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u4e0e Avibe \u65e5\u5fd7\u3002",- "skippedInspection": "\u5f52\u6863\u6e05\u7406\u65e0\u6cd5\u68c0\u67e5\u7f13\u5b58\uff08{reason}\uff09\uff1b\u53ef\u80fd\u4ecd\u6709\u8fc7\u671f\u5f52\u6863\u3002\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u4e0e Avibe \u65e5\u5fd7\u3002",- "gitSkipped": "Git Runtime \u6e05\u7406\u5df2\u8df3\u8fc7\uff08{reason}\uff09\uff1b\u8fc7\u671f\u6761\u76ee\u4ecd\u4fdd\u7559\u3002",- "gitSkippedPreview": "Git Runtime \u7f13\u5b58\u9884\u89c8\u5df2\u8df3\u8fc7\uff08{reason}\uff09\uff1b\u53ef\u80fd\u4ecd\u6709\u8fc7\u671f\u6761\u76ee\u3002"+ "skippedInspection": "\u5f52\u6863\u6e05\u7406\u65e0\u6cd5\u68c0\u67e5\u7f13\u5b58\uff08{reason}\uff09\uff1b\u53ef\u80fd\u4ecd\u6709\u8fc7\u671f\u5f52\u6863\u3002\u8bf7\u68c0\u67e5\u8fd0\u884c\u76ee\u5f55\u6743\u9650\u4e0e Avibe \u65e5\u5fd7\u3002"},"doctor": {"archiveCacheReclaimable": "Show Runtime \u5f52\u6863\u7f13\u5b58\u4e2d\u6709 {count} \u4e2a\u53ef\u56de\u6536\u5f52\u6863\uff08{size}\uff09\uff1b\u5f53\u524d\u4e0e\u56de\u6eda\u5f52\u6863\u4f1a\u88ab\u4fdd\u7559\u3002",