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(setup): resolve agent binaries outside PATH
cyhda1221fba2e8
diff --git a/tests/test_ui_api.py b/tests/test_ui_api.pyindex b691eb941..d95c1673f 100644--- a/tests/test_ui_api.py+++ b/tests/test_ui_api.py@@ -1,5 +1,3 @@-import json-from vibe import api@@ -13,3 +11,98 @@ def test_detect_cli_prefers_claude_local(monkeypatch, tmp_path):result = api.detect_cli("claude")assert result["found"] is Trueassert result["path"] == str(claude_path)+++def test_detect_cli_finds_opencode_installed_outside_path(monkeypatch, tmp_path):+ opencode_path = tmp_path / ".opencode" / "bin" / "opencode"+ opencode_path.parent.mkdir(parents=True, exist_ok=True)+ opencode_path.write_text("#!/bin/sh\n")+ opencode_path.chmod(0o755)++ monkeypatch.setattr(api.Path, "home", lambda: tmp_path)+ monkeypatch.setattr(api.shutil, "which", lambda binary: None)++ result = api.detect_cli("opencode")++ assert result["found"] is True+ assert result["path"] == str(opencode_path)+++def test_detect_cli_supports_explicit_path(monkeypatch, tmp_path):+ binary_path = tmp_path / "bin" / "custom-opencode"+ binary_path.parent.mkdir(parents=True, exist_ok=True)+ binary_path.write_text("#!/bin/sh\n")+ binary_path.chmod(0o755)++ monkeypatch.setattr(api.shutil, "which", lambda binary: None)++ result = api.detect_cli(str(binary_path))++ assert result["found"] is True+ assert result["path"] == str(binary_path)+++def test_detect_cli_finds_npm_in_nvm(monkeypatch, tmp_path):+ npm_path = tmp_path / ".nvm" / "versions" / "node" / "v22.18.0" / "bin" / "npm"+ npm_path.parent.mkdir(parents=True, exist_ok=True)+ npm_path.write_text("#!/bin/sh\n")+ npm_path.chmod(0o755)++ monkeypatch.setattr(api.Path, "home", lambda: tmp_path)+ monkeypatch.setattr(api.shutil, "which", lambda binary: None)++ result = api.detect_cli("npm")++ assert result["found"] is True+ assert result["path"] == str(npm_path)+++def test_install_agent_returns_resolved_path(monkeypatch):+ class CompletedProcess:+ returncode = 0+ stdout = "installed"+ stderr = ""++ monkeypatch.setattr(+ api.shutil,+ "which",+ lambda binary: f"/usr/bin/{binary}" if binary in {"curl", "bash"} else None,+ )+ monkeypatch.setattr(api.subprocess, "run", lambda *args, **kwargs: CompletedProcess())+ monkeypatch.setattr(api, "resolve_cli_path", lambda binary: "/Users/test/.opencode/bin/opencode")++ result = api.install_agent("opencode")++ assert result["ok"] is True+ assert result["path"] == "/Users/test/.opencode/bin/opencode"+++def test_install_codex_uses_resolved_npm(monkeypatch):+ calls = []++ class CompletedProcess:+ returncode = 0+ stdout = "installed"+ stderr = ""++ def fake_run(cmd, **kwargs):+ calls.append((cmd, kwargs.get("env", {})))+ return CompletedProcess()++ def fake_resolve(binary):+ if binary == "npm":+ return "/Users/test/.nvm/versions/node/v22.18.0/bin/npm"+ if binary == "codex":+ return "/Users/test/.nvm/versions/node/v22.18.0/bin/codex"+ return None++ monkeypatch.setattr(api.subprocess, "run", fake_run)+ monkeypatch.setattr(api, "resolve_cli_path", fake_resolve)++ result = api.install_agent("codex")++ assert result["ok"] is True+ assert len(calls) == 1+ assert calls[0][0] == ["/Users/test/.nvm/versions/node/v22.18.0/bin/npm", "install", "-g", "@openai/codex"]+ assert calls[0][1]["PATH"].split(api.os.pathsep)[0] == "/Users/test/.nvm/versions/node/v22.18.0/bin"+ assert result["path"] == "/Users/test/.nvm/versions/node/v22.18.0/bin/codex"diff --git a/ui/src/components/steps/AgentDetection.tsx b/ui/src/components/steps/AgentDetection.tsxindex 209574d96..089fa8d67 100644--- a/ui/src/components/steps/AgentDetection.tsx+++ b/ui/src/components/steps/AgentDetection.tsx@@ -45,11 +45,11 @@ export const AgentDetection: React.FC<AgentDetectionProps> = ({ data, onNext, ondetectAll();}, []);- const detect = async (name: string) => {+ const detect = async (name: string, binary?: string) => {setChecking(true);try {let result;- result = await api.detectCli(name);+ result = await api.detectCli(binary || name);setAgents((prev) => ({...prev,@@ -65,7 +65,7 @@ export const AgentDetection: React.FC<AgentDetectionProps> = ({ data, onNext, on};const detectAll = async () => {- await Promise.all(Object.keys(agents).map((name) => detect(name)));+ await Promise.all(Object.entries(agents).map(([name, agent]) => detect(name, agent.cli_path)));};const toggle = (name: string, enabled: boolean) => {@@ -102,13 +102,23 @@ export const AgentDetection: React.FC<AgentDetectionProps> = ({ data, onNext, ontry {const result = await api.installAgent(name);+ const installedPath = typeof result.path === 'string' && result.path ? result.path : null;setInstallResults((prev) => ({...prev,[name]: { ok: result.ok, message: result.message, output: result.output },}));if (result.ok) {+ if (installedPath) {+ setAgents((prev) => ({+ ...prev,+ [name]: {+ ...prev[name],+ cli_path: installedPath,+ },+ }));+ }// Re-detect after successful installation- await detect(name);+ await detect(name, installedPath || agents[name]?.cli_path || name);}} catch (e) {setInstallResults((prev) => ({@@ -207,11 +217,11 @@ export const AgentDetection: React.FC<AgentDetectionProps> = ({ data, onNext, onplaceholder={t('agentDetection.cliPathPlaceholder', { name })}className="flex-1 bg-bg border border-border rounded px-3 py-2 text-sm focus:outline-none focus:border-accent font-mono text-text"/>- <button- onClick={() => detect(name)}+ <button+ onClick={() => detect(name, agent.cli_path)}disabled={checking}className="px-3 py-2 bg-neutral-100 hover:bg-neutral-200 rounded text-sm text-muted hover:text-text font-medium transition-colors border border-border"- >+ >{checking ? <RefreshCw size={14} className="animate-spin" /> : t('common.detect')}</button></div>diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsxindex 66ccc25bb..068209644 100644--- a/ui/src/context/ApiContext.tsx+++ b/ui/src/context/ApiContext.tsx@@ -63,6 +63,7 @@ export type InstallResult = {ok: boolean;message: string;output: string | null;+ path?: string | null;};const ApiContext = createContext<ApiContextType | undefined>(undefined);diff --git a/vibe/api.py b/vibe/api.pyindex a907511c4..77ecba900 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -29,6 +29,84 @@ _OPENCODE_OPTIONS_CACHE: dict[str, dict] = {}_OPENCODE_OPTIONS_TTL_SECONDS = 30.0+def _is_executable_file(path: Path) -> bool:+ return path.exists() and path.is_file() and os.access(path, os.X_OK)+++def _nvm_binary_candidates(binary: str) -> list[Path]:+ versions_dir = Path.home() / ".nvm" / "versions" / "node"+ if not versions_dir.exists():+ return []++ def _version_sort_key(path: Path) -> tuple:+ parts = str(path.name).lstrip("v").split(".")+ key: list[int | str] = []+ for part in parts:+ key.append(int(part) if part.isdigit() else part)+ return tuple(key)++ candidates: list[Path] = []+ for version_dir in sorted(versions_dir.glob("*"), key=_version_sort_key, reverse=True):+ candidate = version_dir / "bin" / binary+ if candidate not in candidates:+ candidates.append(candidate)+ return candidates+++def _candidate_cli_paths(binary: str) -> list[Path]:+ if not binary:+ return []++ expanded = Path(os.path.expanduser(binary))+ has_path_separator = os.sep in binary or (os.altsep is not None and os.altsep in binary)+ if expanded.is_absolute() or has_path_separator:+ return [expanded]++ home = Path.home()+ candidates: list[Path] = []+ if binary == "claude":+ candidates.append(home / ".claude" / "local" / "claude")+ elif binary == "opencode":+ candidates.extend(+ [+ home / ".opencode" / "bin" / "opencode",+ home / ".local" / "bin" / "opencode",+ ]+ )++ common_candidates = [+ home / ".local" / "bin" / binary,+ home / ".bun" / "bin" / binary,+ Path("/opt/homebrew/bin") / binary,+ Path("/usr/local/bin") / binary,+ ]+ for candidate in common_candidates + _nvm_binary_candidates(binary):+ if candidate not in candidates:+ candidates.append(candidate)++ return candidates+++def resolve_cli_path(binary: str) -> str | None:+ for candidate in _candidate_cli_paths(binary):+ if _is_executable_file(candidate):+ return str(candidate)++ path = shutil.which(os.path.expanduser(binary)) if binary else None+ return path or None+++def _command_env_for(binary_path: str | None) -> dict[str, str]:+ env = {**os.environ, "PATH": os.environ.get("PATH", "")}+ if not binary_path:+ return env++ binary_dir = str(Path(binary_path).expanduser().resolve().parent)+ path_entries = [entry for entry in env.get("PATH", "").split(os.pathsep) if entry and entry != binary_dir]+ env["PATH"] = os.pathsep.join([binary_dir, *path_entries])+ return env++def browse_directory(path: str, show_hidden: bool = False) -> dict:"""List sub-directories of *path* for the directory browser UI.@@ -164,11 +242,7 @@ def init_sessions() -> None:def detect_cli(binary: str) -> dict:- if binary == "claude":- preferred = Path.home() / ".claude" / "local" / "claude"- if preferred.exists() and os.access(preferred, os.X_OK):- return {"found": True, "path": str(preferred)}- path = shutil.which(binary)+ path = resolve_cli_path(binary)if not path:return {"found": False, "path": None}return {"found": True, "path": path}@@ -904,7 +978,7 @@ def install_agent(name: str) -> dict:def _check_binary(binary: str) -> str | None:"""Check if a binary exists in PATH. Returns error message if not found."""- if shutil.which(binary) is None:+ if resolve_cli_path(binary) is None:return f"{binary} is required but not found. Please install it first."return None@@ -946,12 +1020,12 @@ def install_agent(name: str) -> dict:cmd = ["bash", "-c", "set -euo pipefail; curl -fsSL https://claude.ai/install.sh | bash"]elif name == "codex":# Codex: prefer npm, fallback to brew on macOS- npm_path = shutil.which("npm")+ npm_path = resolve_cli_path("npm")if npm_path:cmd = [npm_path, "install", "-g", "@openai/codex"]elif system == "darwin":# macOS: try brew cask- brew_path = shutil.which("brew")+ brew_path = resolve_cli_path("brew")if brew_path:cmd = [brew_path, "install", "--cask", "codex"]else:@@ -971,20 +1045,23 @@ def install_agent(name: str) -> dict:try:logger.info("Installing agent %s with command: %s", name, cmd)+ command_env = _command_env_for(cmd[0] if cmd and os.path.isabs(cmd[0]) else None)result = subprocess.run(cmd,capture_output=True,text=True,timeout=300, # 5 minute timeout for installation- env={**os.environ, "PATH": os.environ.get("PATH", "")},+ env=command_env,)output = result.stdout + ("\n" + result.stderr if result.stderr else "")output = _truncate_output(output.strip())if result.returncode == 0:logger.info("Agent %s installed successfully", name)+ installed_path = resolve_cli_path(name)return {"ok": True,"message": f"{name} installed successfully",+ "path": installed_path,"output": output,}else:diff --git a/vibe/cli.py b/vibe/cli.pyindex d4ad3a227..b548f8bad 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -20,7 +20,7 @@ from config.v2_config import (SlackConfig,V2Config,)-from vibe import __version__, runtime+from vibe import __version__, api, runtimelogger = logging.getLogger(__name__)@@ -288,9 +288,7 @@ def _doctor():# OpenCodeif config.agents.opencode.enabled:cli_path = config.agents.opencode.cli_path- import shutil-- found_path = shutil.which(cli_path) if cli_path else None+ found_path = api.detect_cli(cli_path).get("path") if cli_path else Noneif found_path:agent_items.append({@@ -320,14 +318,7 @@ def _doctor():# Claudeif config.agents.claude.enabled:cli_path = config.agents.claude.cli_path- import shutil-- # Check preferred location first- preferred = Path.home() / ".claude" / "local" / "claude"- if preferred.exists() and os.access(preferred, os.X_OK):- found_path = str(preferred)- else:- found_path = shutil.which(cli_path) if cli_path else None+ found_path = api.detect_cli(cli_path).get("path") if cli_path else Noneif found_path:agent_items.append(@@ -358,9 +349,7 @@ def _doctor():# Codexif config.agents.codex.enabled:cli_path = config.agents.codex.cli_path- import shutil-- found_path = shutil.which(cli_path) if cli_path else None+ found_path = api.detect_cli(cli_path).get("path") if cli_path else Noneif found_path:agent_items.append({