Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(show): refresh stale prebuilt runtime archive

cyha12a06eec25e
diff --git a/core/show_runtime.py b/core/show_runtime.py
index 8d355b0a3..b503629e6 100644
--- a/core/show_runtime.py
+++ b/core/show_runtime.py
@@ -2,7 +2,9 @@ from __future__ import annotations
import atexit
import asyncio
+import hashlib
import importlib.resources as package_resources
+import json
import logging
import os
import shlex
@@ -182,6 +184,12 @@ class ShowRuntimeManager:
self._install_reason = "runtime_command_missing"
return None
if self.runtime_source == _RUNTIME_SOURCE_ARCHIVE:
+ if self.auto_install and not self._install_attempted:
+ self._install_attempted = True
+ command = await asyncio.to_thread(self._install_managed_runtime)
+ if command:
+ self._managed_command = command
+ return command
command = self._installed_archive_runtime_command()
if command:
self._managed_command = command
@@ -238,6 +246,10 @@ class ShowRuntimeManager:
archive = self._resolve_prebuilt_archive()
if not archive:
return self._reuse_existing_archive_runtime(existing_command)
+ archive_digest = _file_sha256(archive)
+ if existing_command and self._archive_manifest_matches(archive_digest):
+ self._install_reason = None
+ return existing_command
tmp_dir = Path(tempfile.mkdtemp(prefix="prebuilt-", dir=self.runtime_dir))
try:
with tarfile.open(archive, "r:gz") as tar:
@@ -250,6 +262,7 @@ class ShowRuntimeManager:
shutil.rmtree(install_dir)
install_dir.parent.mkdir(parents=True, exist_ok=True)
shutil.move(str(tmp_dir), str(install_dir))
+ self._write_archive_manifest(archive_digest)
self._install_reason = None
return self._archive_runtime_command(install_dir, node)
except Exception:
@@ -302,6 +315,29 @@ class ShowRuntimeManager:
def _archive_install_dir(self) -> Path:
return self.runtime_dir / "prebuilt" / "current"
+ def _archive_manifest_path(self) -> Path:
+ return self._archive_install_dir() / ".vibe-show-runtime.json"
+
+ def _archive_manifest_matches(self, archive_digest: str) -> bool:
+ try:
+ payload = json.loads(self._archive_manifest_path().read_text(encoding="utf-8"))
+ except Exception:
+ return False
+ return payload.get("archive_name") == _runtime_archive_name() and payload.get("sha256") == archive_digest
+
+ def _write_archive_manifest(self, archive_digest: str) -> None:
+ self._archive_manifest_path().write_text(
+ json.dumps(
+ {
+ "archive_name": _runtime_archive_name(),
+ "sha256": archive_digest,
+ },
+ sort_keys=True,
+ )
+ + "\n",
+ encoding="utf-8",
+ )
+
def _archive_runtime_command(self, install_dir: Path, node: list[str]) -> list[str] | None:
cli_path = install_dir / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"
if not cli_path.exists():
@@ -512,6 +548,14 @@ def _safe_extract_tar(tar: tarfile.TarFile, destination: Path) -> None:
tar.extractall(destination)
+def _file_sha256(path: Path) -> str:
+ digest = hashlib.sha256()
+ with path.open("rb") as file:
+ for chunk in iter(lambda: file.read(1024 * 1024), b""):
+ digest.update(chunk)
+ return digest.hexdigest()
+
+
def _safe_path_part(value: str) -> str:
cleaned = "".join(ch if ch.isalnum() or ch in "._-" else "_" for ch in value.strip())
return cleaned or "main"
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index 39aedcb23..b7eb8fcf4 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -341,6 +341,31 @@ def test_show_runtime_manager_reuses_installed_prebuilt_runtime_without_archive(
assert manager._install_reason is None
+def test_show_runtime_manager_refreshes_stale_prebuilt_archive(monkeypatch, tmp_path):
+ runtime_dir = tmp_path / "runtime"
+ installed_cli = runtime_dir / "prebuilt" / "current" / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"
+ installed_cli.parent.mkdir(parents=True)
+ installed_cli.write_text("old runtime\n", encoding="utf-8")
+
+ archive_root = tmp_path / "archive-root"
+ archive_cli = archive_root / "node_modules" / "@avibe" / "show-runtime" / "dist" / "cli.js"
+ archive_cli.parent.mkdir(parents=True)
+ archive_cli.write_text("new runtime\n", encoding="utf-8")
+ archive_path = tmp_path / "vibe-show-runtime-node.tgz"
+ with tarfile.open(archive_path, "w:gz") as tar:
+ tar.add(archive_root / "node_modules", arcname="node_modules")
+
+ manager = ShowRuntimeManager(
+ workspace_root=tmp_path / "show",
+ runtime_dir=runtime_dir,
+ archive_path=archive_path,
+ )
+ monkeypatch.setattr("core.show_runtime._resolve_command", lambda command: ["/bin/node"] if command == "node" else None)
+
+ assert asyncio.run(manager._resolve_managed_command()) == ["/bin/node", str(installed_cli)]
+ assert installed_cli.read_text(encoding="utf-8") == "new runtime\n"
+
+
def test_show_runtime_manager_can_disable_auto_install(tmp_path):
manager = ShowRuntimeManager(
workspace_root=tmp_path / "show",