This commit is contained in:
2026-01-09 22:19:03 -08:00
parent be93d73938
commit a13dd9fd26
2 changed files with 36 additions and 43 deletions

View File

@@ -4,7 +4,7 @@
When running `bootstrap.py` on another machine, the installation completes successfully with messages about creating `mm.bat`, but the `mm` command is not recognized when executed.
**Root Cause:** Windows terminal sessions cache the PATH environment variable. When registry changes are made, existing terminal sessions don't automatically reload the new PATH. The batch shim is created correctly, but it isn't discoverable until either the current session reloads PATH or a new terminal is opened.
**Root Cause:** Windows terminal sessions cache the PATH environment variable. When registry changes are made, existing terminal sessions don't automatically reload the new PATH. The PowerShell shim is created correctly, but it isn't discoverable until either the current session reloads PATH or a new terminal is opened.
## Solution
@@ -36,7 +36,7 @@ python scripts/bootstrap.py --check-install
```
This will check:
-Batch shim exists (`mm.bat`)
-PowerShell shim exists (`mm.ps1`)
- ✓ Shim content is valid and points at the local venv
- ✓ PATH environment variable is configured
- ✓ Registry PATH was updated
@@ -48,7 +48,7 @@ This will check:
Checking 'mm' command installation...
Checking for shim files:
mm.bat: ✓ (C:\Users\Admin\bin\mm.bat)
mm.ps1: ✓ (C:\Users\Admin\bin\mm.ps1)
Checking PATH environment variable:
C:\Users\Admin\bin in current session PATH: ✗

View File

@@ -551,18 +551,18 @@ def main() -> int:
if system == "windows":
user_bin = Path(os.environ.get("USERPROFILE", str(home))) / "bin"
mm_bat = user_bin / "mm.bat"
mm_ps1 = user_bin / "mm.ps1"
print(f"Checking for shim files:")
print(f" mm.bat: {'' if mm_bat.exists() else ''} ({mm_bat})")
print(f" mm.ps1: {'' if mm_ps1.exists() else ''} ({mm_ps1})")
print()
if mm_bat.exists():
bat_content = mm_bat.read_text(encoding="utf-8")
if "REPO=" in bat_content or "PY=" in bat_content:
print(f" mm.bat content looks valid ({len(bat_content)} bytes)")
if mm_ps1.exists():
ps1_content = mm_ps1.read_text(encoding="utf-8")
if "$repo =" in ps1_content or "$py =" in ps1_content:
print(f" mm.ps1 content looks valid ({len(ps1_content)} bytes)")
else:
print(f" ⚠️ mm.bat content may be corrupted")
print(f" ⚠️ mm.ps1 content may be corrupted")
print()
# Check PATH
@@ -992,42 +992,35 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
if not (repo / "scripts").exists():
print(f"WARNING: scripts folder not found at {repo}/scripts - mm command may not work", file=sys.stderr)
# Write mm.bat (CMD shim for all shells; avoids PowerShell execution policy issues)
mm_bat = user_bin / "mm.bat"
repo_bat_str = str(repo)
bat_text = (
"@echo off\n"
"setlocal enabledelayedexpansion\n"
f'set "REPO={repo_bat_str}"\n'
"set \"VENV=!REPO!\\.venv\"\n"
"set \"PY=!VENV!\\Scripts\\python.exe\"\n"
"set \"ENTRY=!REPO!\\scripts\\cli_entry.py\"\n"
"if exist \"!PY!\" (\n"
" if defined MM_DEBUG (\n"
" echo MM_DEBUG: using venv python at !PY!\n"
" \"!PY!\" -c \"import sys; print('sys.executable:', sys.executable); print('sys.path:', sys.path[:5])\"\n"
" )\n"
" \"!PY!\" \"!ENTRY!\" %*\n"
" exit /b !ERRORLEVEL!\n"
")\n"
"echo MM: venv python not found at !PY!\n"
"if defined MM_DEBUG echo MM_DEBUG: venv python not found, trying system python\n"
"python \"!ENTRY!\" %*\n"
"exit /b !ERRORLEVEL!\n"
)
if mm_bat.exists():
bak = mm_bat.with_suffix(f".bak{int(time.time())}")
mm_bat.replace(bak)
mm_bat.write_text(bat_text, encoding="utf-8")
# Write mm.ps1 (PowerShell shim for global command)
mm_ps1 = user_bin / "mm.ps1"
repo_ps1_str = str(repo).replace("\\", "\\\\")
ps1_text = (
"$repo = '{repo}'\n"
"$venv = Join-Path $repo '.venv'\n"
"$py = Join-Path $venv 'Scripts' 'python.exe'\n"
"$entry = Join-Path $repo 'scripts' 'cli_entry.py'\n"
"if (Test-Path $py) {{\n"
" & $py $entry $args\n"
" exit $LASTEXITCODE\n"
"}}\n"
"Write-Host 'MM: venv python not found at '$py\n"
"python $entry $args\n"
"exit $LASTEXITCODE\n"
).format(repo=repo_ps1_str)
if mm_ps1.exists():
bak = mm_ps1.with_suffix(f".bak{int(time.time())}")
mm_ps1.replace(bak)
mm_ps1.write_text(ps1_text, encoding="utf-8")
# Validate that the batch shim was created correctly
bat_ok = mm_bat.exists() and len(mm_bat.read_text(encoding="utf-8")) > 0
if not bat_ok:
raise RuntimeError("Failed to create mm.bat shim")
# Validate that the PowerShell shim was created correctly
ps1_ok = mm_ps1.exists() and len(mm_ps1.read_text(encoding="utf-8")) > 0
if not ps1_ok:
raise RuntimeError("Failed to create mm.ps1 shim")
if args.debug:
print(f"DEBUG: Created mm.bat ({len(bat_text)} bytes)")
print(f"DEBUG: Repo path embedded in shims: {repo}")
print(f"DEBUG: Created mm.ps1 ({len(ps1_text)} bytes)")
print(f"DEBUG: Repo path embedded in shim: {repo}")
print(f"DEBUG: Venv location: {repo}/.venv")
print(f"DEBUG: Shim directory: {user_bin}")