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(upgrade): track stable launcher paths

cyhf4cdceaa3c40
diff --git a/install.sh b/install.sh
index 3f4e40865..e8875b699 100755
--- a/install.sh
+++ b/install.sh
@@ -93,13 +93,31 @@ is_absolute_dir() {
esac
}
+is_transient_bin_dir() {
+ local dir="$1"
+
+ case "$dir" in
+ */.venv/bin|*/venv/bin|*/env/bin) return 0 ;;
+ esac
+
+ if [ -n "${VIRTUAL_ENV:-}" ] && [ "$dir" = "${VIRTUAL_ENV%/}/bin" ]; then
+ return 0
+ fi
+
+ if [ -n "${CONDA_PREFIX:-}" ] && [ "$dir" = "${CONDA_PREFIX%/}/bin" ]; then
+ return 0
+ fi
+
+ return 1
+}
+
choose_tool_bin_dir() {
local dir
local old_ifs="$IFS"
IFS=":"
for dir in $ORIGINAL_PATH; do
- if [ -n "$dir" ] && is_absolute_dir "$dir" && ensure_writable_dir "$dir"; then
+ if [ -n "$dir" ] && is_absolute_dir "$dir" && ! is_transient_bin_dir "$dir" && ensure_writable_dir "$dir"; then
IFS="$old_ifs"
echo "$dir"
return 0
diff --git a/tests/e2e/test_upgrade_command.py b/tests/e2e/test_upgrade_command.py
index 5fd84d30d..91508ed33 100644
--- a/tests/e2e/test_upgrade_command.py
+++ b/tests/e2e/test_upgrade_command.py
@@ -73,11 +73,12 @@ def test_upgrade_command_uses_built_release_artifact():
f"VIBE_UPGRADE_PACKAGE_SPEC=/fixtures/{wheel_path.name} vibe check-update",
"VIBE_UPDATE_METADATA_URL=file:///fixtures/metadata.json "
f"VIBE_UPGRADE_PACKAGE_SPEC=/fixtures/{wheel_path.name} vibe upgrade",
- "vibe version",
- "VIBE_UPDATE_METADATA_URL=file:///fixtures/metadata.json vibe check-update",
- "vibe",
+ 'TOOL_PY="$(uv tool dir)/vibe-remote/bin/python"',
+ '"$TOOL_PY" -c "from vibe.cli import main; main()" version',
+ 'VIBE_UPDATE_METADATA_URL=file:///fixtures/metadata.json "$TOOL_PY" -c "from vibe.cli import main; main()" check-update',
+ '"$TOOL_PY" -c "from vibe.cli import main; main()"',
"sleep 2",
- "vibe status",
+ '"$TOOL_PY" -c "from vibe.cli import main; main()" status',
]
)
diff --git a/tests/test_install_script.py b/tests/test_install_script.py
index 421404784..dabb3e075 100644
--- a/tests/test_install_script.py
+++ b/tests/test_install_script.py
@@ -165,6 +165,29 @@ def test_install_script_skips_relative_path_entries_for_tool_bin(tmp_path):
assert not (relative_bin / "vibe").exists()
+def test_install_script_skips_virtualenv_bin_dirs(tmp_path):
+ home_dir = tmp_path / "home"
+ home_dir.mkdir()
+ venv_bin = tmp_path / ".venv" / "bin"
+ venv_bin.mkdir(parents=True)
+ stable_bin = tmp_path / "stable-bin"
+ stable_bin.mkdir()
+ uv_log = tmp_path / "uv-tool-bin-dir.txt"
+
+ _write_fake_uv(stable_bin / "uv", uv_log)
+
+ env = os.environ.copy()
+ env["HOME"] = str(home_dir)
+ env["PATH"] = os.pathsep.join([str(venv_bin), str(stable_bin), "/usr/bin", "/bin"])
+ env["VIRTUAL_ENV"] = str(tmp_path / ".venv")
+
+ install_result = _install(env, cwd=tmp_path)
+
+ assert install_result.returncode == 0, install_result.stdout + install_result.stderr
+ assert uv_log.read_text(encoding="utf-8") == str(stable_bin)
+ assert not (venv_bin / "vibe").exists()
+
+
def test_install_script_requires_path_export_when_install_dir_not_on_original_path(tmp_path):
home_dir = tmp_path / "home"
home_dir.mkdir()
diff --git a/tests/test_upgrade_flow.py b/tests/test_upgrade_flow.py
index 995a4a3ba..a03507866 100644
--- a/tests/test_upgrade_flow.py
+++ b/tests/test_upgrade_flow.py
@@ -8,7 +8,13 @@ from typing import Any
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from vibe import api, cli
-from vibe.upgrade import UpgradePlan, build_upgrade_plan, get_latest_version_info
+from vibe.upgrade import (
+ UpgradePlan,
+ build_upgrade_plan,
+ get_latest_version_info,
+ get_restart_command,
+ get_running_vibe_path,
+)
def test_build_upgrade_plan_uses_uv_and_preserves_tool_bin_dir():
@@ -55,6 +61,7 @@ def test_build_upgrade_plan_uses_env_package_spec(monkeypatch):
"install",
"/tmp/vibe_remote-9999.0.0-py3-none-any.whl",
"--upgrade",
+ "--force",
]
@@ -68,6 +75,24 @@ def test_get_latest_version_info_uses_override_metadata_url(monkeypatch, tmp_pat
assert info == {"current": "2.2.0", "latest": "9999.0.0", "has_update": True, "error": None}
+def test_get_running_vibe_path_prefers_cached_launcher(monkeypatch):
+ monkeypatch.setenv("VIBE_CURRENT_EXECUTABLE", "/custom/bin/vibe")
+ monkeypatch.setattr("vibe.upgrade.shutil.which", lambda *args, **kwargs: "/other/bin/vibe")
+
+ resolved = get_running_vibe_path(argv0="vibe")
+
+ assert resolved == "/custom/bin/vibe"
+
+
+def test_get_restart_command_falls_back_to_python_module(monkeypatch):
+ monkeypatch.delenv("VIBE_CURRENT_EXECUTABLE", raising=False)
+ monkeypatch.setattr("vibe.upgrade.shutil.which", lambda *args, **kwargs: None)
+
+ command = get_restart_command(python_executable="/usr/bin/python3", argv0="python")
+
+ assert command == ["/usr/bin/python3", "-c", "from vibe.cli import main; main()"]
+
+
def test_do_upgrade_uses_upgrade_plan_env_and_restarts(monkeypatch):
plan = UpgradePlan(
command=["/usr/local/bin/uv", "tool", "install", "vibe-remote", "--upgrade"],
@@ -76,7 +101,9 @@ def test_do_upgrade_uses_upgrade_plan_env_and_restarts(monkeypatch):
)
calls: dict[str, Any] = {}
- monkeypatch.setattr(api, "build_upgrade_plan", lambda: plan)
+ monkeypatch.setattr(api, "build_upgrade_plan", lambda **kwargs: plan)
+ monkeypatch.setattr(api, "get_running_vibe_path", lambda: "/custom/bin/vibe")
+ monkeypatch.setattr(api, "get_restart_shell_command", lambda **kwargs: "/custom/bin/vibe")
def fake_run(cmd, **kwargs):
calls["run_cmd"] = cmd
@@ -94,8 +121,6 @@ def test_do_upgrade_uses_upgrade_plan_env_and_restarts(monkeypatch):
monkeypatch.setattr(api.subprocess, "run", fake_run)
monkeypatch.setattr(api.subprocess, "Popen", fake_popen)
- monkeypatch.setattr(api.shutil, "which", lambda name: "/custom/bin/vibe" if name == "vibe" else None)
-
result = api.do_upgrade(auto_restart=True)
assert result["ok"] is True
@@ -121,7 +146,8 @@ def test_cmd_upgrade_uses_upgrade_plan_env(monkeypatch):
calls: dict[str, Any] = {}
monkeypatch.setattr(cli, "get_latest_version", lambda: {"error": None, "has_update": True, "latest": "2.2.0"})
- monkeypatch.setattr(cli, "build_upgrade_plan", lambda: plan)
+ monkeypatch.setattr(cli, "cache_running_vibe_path", lambda: "/custom/bin/vibe")
+ monkeypatch.setattr(cli, "build_upgrade_plan", lambda **kwargs: plan)
def fake_run(cmd, **kwargs):
calls["cmd"] = cmd
diff --git a/vibe/api.py b/vibe/api.py
index 654c293bd..3e72dbecd 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -21,7 +21,7 @@ from config.v2_settings import (
_routing_to_dict,
)
from config.v2_sessions import SessionsStore
-from vibe.upgrade import build_upgrade_plan, get_latest_version_info
+from vibe.upgrade import build_upgrade_plan, get_latest_version_info, get_restart_shell_command, get_running_vibe_path
logger = logging.getLogger(__name__)
@@ -643,7 +643,8 @@ def do_upgrade(auto_restart: bool = True) -> dict:
Returns:
{"ok": bool, "message": str, "output": str | None, "restarting": bool}
"""
- plan = build_upgrade_plan()
+ current_vibe_path = get_running_vibe_path()
+ plan = build_upgrade_plan(vibe_path=current_vibe_path)
try:
result = subprocess.run(
@@ -656,20 +657,15 @@ def do_upgrade(auto_restart: bool = True) -> dict:
if result.returncode == 0:
restarting = False
if auto_restart:
- # Schedule restart in background after response is sent
- # Use 'vibe' command which will restart both service and UI
- vibe_path = shutil.which("vibe")
- if vibe_path:
- # Start restart process detached, with delay to allow response to be sent
- restart_cmd = f"sleep 2 && {vibe_path}"
- subprocess.Popen(
- restart_cmd,
- shell=True,
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- start_new_session=True,
- )
- restarting = True
+ restart_cmd = f"sleep 2 && {get_restart_shell_command(vibe_path=current_vibe_path)}"
+ subprocess.Popen(
+ restart_cmd,
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ start_new_session=True,
+ )
+ restarting = True
return {
"ok": True,
diff --git a/vibe/cli.py b/vibe/cli.py
index c6f70982e..cde1d2c74 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -20,7 +20,7 @@ from config.v2_config import (
V2Config,
)
from vibe import __version__, api, runtime
-from vibe.upgrade import build_upgrade_plan, get_latest_version_info
+from vibe.upgrade import build_upgrade_plan, cache_running_vibe_path, get_latest_version_info
logger = logging.getLogger(__name__)
@@ -648,7 +648,8 @@ def cmd_upgrade():
print("\nUpgrading...")
- plan = build_upgrade_plan()
+ current_vibe_path = cache_running_vibe_path()
+ plan = build_upgrade_plan(vibe_path=current_vibe_path)
print(f"Using {plan.method}: {' '.join(plan.command)}")
try:
@@ -690,6 +691,7 @@ def build_parser():
def main():
+ cache_running_vibe_path()
parser = build_parser()
args = parser.parse_args()
diff --git a/vibe/upgrade.py b/vibe/upgrade.py
index cf439ea67..049352677 100644
--- a/vibe/upgrade.py
+++ b/vibe/upgrade.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import json
import os
+import shlex
import shutil
import sys
import urllib.request
@@ -11,6 +12,7 @@ from pathlib import Path
PACKAGE_NAME = "vibe-remote"
DEFAULT_UPDATE_METADATA_URL = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
+CURRENT_VIBE_EXECUTABLE_ENV = "VIBE_CURRENT_EXECUTABLE"
@dataclass(frozen=True)
@@ -20,6 +22,81 @@ class UpgradePlan:
method: str
+def resolve_command_path(command: str | None, search_path: str | None = None) -> str | None:
+ if not command:
+ return None
+
+ expanded = Path(command).expanduser()
+ if expanded.is_absolute():
+ return str(expanded.resolve())
+
+ if any(sep in command for sep in (os.sep, "/")):
+ return str((Path.cwd() / expanded).resolve())
+
+ resolved = shutil.which(command, path=search_path)
+ if not resolved:
+ return None
+ return str(Path(resolved).expanduser().resolve())
+
+
+def get_running_vibe_path(
+ *,
+ vibe_path: str | None = None,
+ argv0: str | None = None,
+ search_path: str | None = None,
+) -> str | None:
+ resolved = resolve_command_path(vibe_path, search_path=search_path)
+ if resolved:
+ return resolved
+
+ env_path = resolve_command_path(os.environ.get(CURRENT_VIBE_EXECUTABLE_ENV), search_path=search_path)
+ if env_path:
+ return env_path
+
+ argv_path = resolve_command_path(argv0 or sys.argv[0], search_path=search_path)
+ if argv_path and Path(argv_path).name.startswith("vibe"):
+ return argv_path
+
+ return resolve_command_path("vibe", search_path=search_path)
+
+
+def cache_running_vibe_path(vibe_path: str | None = None) -> str | None:
+ resolved = get_running_vibe_path(vibe_path=vibe_path)
+ if resolved:
+ os.environ[CURRENT_VIBE_EXECUTABLE_ENV] = resolved
+ return resolved
+
+
+def get_restart_command(
+ *,
+ vibe_path: str | None = None,
+ python_executable: str | None = None,
+ argv0: str | None = None,
+ search_path: str | None = None,
+) -> list[str]:
+ resolved = get_running_vibe_path(vibe_path=vibe_path, argv0=argv0, search_path=search_path)
+ if resolved:
+ return [resolved]
+ return [python_executable or sys.executable, "-c", "from vibe.cli import main; main()"]
+
+
+def get_restart_shell_command(
+ *,
+ vibe_path: str | None = None,
+ python_executable: str | None = None,
+ argv0: str | None = None,
+ search_path: str | None = None,
+) -> str:
+ return shlex.join(
+ get_restart_command(
+ vibe_path=vibe_path,
+ python_executable=python_executable,
+ argv0=argv0,
+ search_path=search_path,
+ )
+ )
+
+
def get_update_metadata_url() -> str:
return os.environ.get("VIBE_UPDATE_METADATA_URL", DEFAULT_UPDATE_METADATA_URL)
@@ -59,7 +136,7 @@ def is_uv_tool_install(python_executable: str | None = None) -> bool:
def get_current_vibe_bin_dir(vibe_path: str | None = None) -> str | None:
- current_vibe = vibe_path if vibe_path is not None else shutil.which("vibe")
+ current_vibe = get_running_vibe_path(vibe_path=vibe_path)
if not current_vibe:
return None
return str(Path(current_vibe).expanduser().parent)
@@ -81,8 +158,11 @@ def build_upgrade_plan(
vibe_bin_dir = get_current_vibe_bin_dir(vibe_path)
if vibe_bin_dir:
env["UV_TOOL_BIN_DIR"] = vibe_bin_dir
+ command = [uv_binary, "tool", "install", package_spec, "--upgrade"]
+ if package_spec != PACKAGE_NAME:
+ command.append("--force")
return UpgradePlan(
- command=[uv_binary, "tool", "install", package_spec, "--upgrade"],
+ command=command,
env=env,
method="uv",
)