Skip to content

Commit 4ad4877

Browse files
fix: Add uv tool bin to PATH after installation
On fresh machines, after 'uv tool install amplifier' succeeds, the amplifier binary may not be in the current shell's PATH. This caused the confusing output: '✓ Amplifier CLI installed' 'Failed to install Amplifier CLI' The fix ensures ~/.local/bin (uv's default tool location) is added to the current process's PATH before checking if amplifier exists. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <[email protected]>
1 parent f4d21ca commit 4ad4877

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/amplihack/launcher/amplifier.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,42 @@
1010
from pathlib import Path
1111

1212

13+
def get_uv_tool_bin_dir() -> Path | None:
14+
"""Get the uv tool bin directory."""
15+
# Try common locations
16+
candidates = [
17+
Path.home() / ".local" / "bin", # Linux/macOS default
18+
Path.home() / ".cargo" / "bin", # Alternative location
19+
]
20+
21+
# Also check UV_TOOL_BIN_DIR environment variable
22+
if env_dir := os.environ.get("UV_TOOL_BIN_DIR"):
23+
candidates.insert(0, Path(env_dir))
24+
25+
for candidate in candidates:
26+
if candidate.exists() and (candidate / "amplifier").exists():
27+
return candidate
28+
29+
# Return first candidate even if amplifier not there yet (for post-install)
30+
for candidate in candidates:
31+
if candidate.exists():
32+
return candidate
33+
34+
return None
35+
36+
37+
def ensure_uv_bin_in_path() -> None:
38+
"""Ensure uv tool bin directory is in PATH for current process."""
39+
bin_dir = get_uv_tool_bin_dir()
40+
if bin_dir and str(bin_dir) not in os.environ.get("PATH", ""):
41+
os.environ["PATH"] = f"{bin_dir}:{os.environ.get('PATH', '')}"
42+
43+
1344
def check_amplifier() -> bool:
1445
"""Check if Amplifier CLI is installed."""
46+
# Ensure uv bin dir is in PATH
47+
ensure_uv_bin_in_path()
48+
1549
try:
1650
result = subprocess.run(
1751
["amplifier", "--version"], capture_output=True, timeout=5, check=False

0 commit comments

Comments
 (0)