From 37afa15dfd931db656fcc3e628aee8e701d2612f Mon Sep 17 00:00:00 2001 From: Nose Date: Fri, 9 Jan 2026 17:06:48 -0800 Subject: [PATCH] f --- docs/BOOTSTRAP_TROUBLESHOOTING.md | 47 ++++++++----------- scripts/bootstrap.py | 77 +++++-------------------------- 2 files changed, 31 insertions(+), 93 deletions(-) diff --git a/docs/BOOTSTRAP_TROUBLESHOOTING.md b/docs/BOOTSTRAP_TROUBLESHOOTING.md index db5285c..ecdac77 100644 --- a/docs/BOOTSTRAP_TROUBLESHOOTING.md +++ b/docs/BOOTSTRAP_TROUBLESHOOTING.md @@ -2,9 +2,9 @@ ## Problem on "Other Computer" -When running `bootstrap.py` on another machine, the installation completes successfully with messages about creating `mm.ps1` and `mm.bat`, but the `mm` command is not recognized when executed. +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 shim files are created correctly, but they're not discoverable until PATH is reloaded. +**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. ## Solution @@ -25,13 +25,7 @@ $env:PATH = [Environment]::GetEnvironmentVariable('PATH', 'User') + ';' + [Envir mm --help ``` -Note: The bootstrap installation automatically attempts this, but it may not work if PowerShell was launched with a restricted execution policy. - -### Option 3: Manual PATH Reload (PowerShell) -```powershell -$env:Path = [Environment]::GetEnvironmentVariable('PATH', 'User') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'Machine') -mm --help -``` +Note: The bootstrap installation already attempts a reload for you, but it only affects new commands started after the update (or terminals that already inherit the updated PATH). ## Diagnostic Command @@ -42,8 +36,8 @@ python scripts/bootstrap.py --check-install ``` This will check: -- ✓ Shim files exist (`mm.ps1` and `mm.bat`) -- ✓ Shim files have valid content +- ✓ Batch shim exists (`mm.bat`) +- ✓ Shim content is valid and points at the local venv - ✓ PATH environment variable is configured - ✓ Registry PATH was updated - ✓ Test if `mm` command is accessible @@ -54,26 +48,25 @@ This will check: Checking 'mm' command installation... Checking for shim files: - mm.ps1: ✓ (C:\Users\Admin\bin\mm.ps1) - mm.bat: ✓ (C:\Users\Admin\bin\mm.bat) + mm.bat: ✓ (C:\Users\Admin\bin\mm.bat) Checking PATH environment variable: - C:\Users\Admin\bin in current session PATH: ✓ - C:\Users\Admin\bin in registry PATH: ✓ + C:\Users\Admin\bin in current session PATH: ✗ + C:\Users\Admin\bin in registry PATH: ✗ Testing 'mm' command... - ✗ 'mm' command not found in PATH - Shims exist but command is not accessible via PATH + ✗ 'mm' command not found in PATH + Shims exist but command is not accessible via PATH Attempting to call shim directly... - ✓ Direct shim call works! - The shim files are valid and functional. + ✓ Direct shim call works! + The shim files are valid and functional. -⚠️ 'mm' is not in PATH, but the shims are working correctly. +⚠️ 'mm' is not in PATH, but the shim is working correctly. Possible causes and fixes: - 1. Terminal needs restart: Close and reopen your terminal/PowerShell - 2. PATH reload: Run: . scripts\reload-path.ps1 - 3. Manual PATH: Add C:\Users\Admin\bin to your system PATH manually + 1. Terminal needs restart: Close and reopen your terminal/PowerShell + 2. PATH reload: Run: $env:Path = [Environment]::GetEnvironmentVariable('PATH', 'User') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'Machine') + 3. Manual PATH: Add C:\Users\Admin\bin to your system PATH manually ``` If the diagnostic shows: @@ -118,13 +111,11 @@ This shows: ## Shim File Locations -The installation creates Windows shim files in: +The installation creates a Windows shim in: - **User bin directory:** `C:\Users\\bin\` -- **Files created:** - - `mm.ps1` - PowerShell shim - - `mm.bat` - Command Prompt shim +- **File created:** `mm.bat` – a batch shim that both CMD and PowerShell can execute without changing the system execution policy. -These files contain the absolute path to your project and venv, so they work from any location. +The batch shim contains the absolute path to your project and venv, so it always runs the local CLI regardless of the current directory. ## Why This Happens diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 197db59..272c365 100644 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -551,21 +551,12 @@ def main() -> int: if system == "windows": user_bin = Path(os.environ.get("USERPROFILE", str(home))) / "bin" - mm_ps1 = user_bin / "mm.ps1" mm_bat = user_bin / "mm.bat" print(f"Checking for shim files:") - print(f" mm.ps1: {'✓' if mm_ps1.exists() else '✗'} ({mm_ps1})") print(f" mm.bat: {'✓' if mm_bat.exists() else '✗'} ({mm_bat})") print() - if mm_ps1.exists(): - ps1_content = mm_ps1.read_text(encoding="utf-8") - if "$repo" in ps1_content or "$REPO" in ps1_content: - print(f" mm.ps1 content looks valid ({len(ps1_content)} bytes)") - else: - print(f" ⚠️ mm.ps1 content may be corrupted") - if mm_bat.exists(): bat_content = mm_bat.read_text(encoding="utf-8") if "REPO=" in bat_content or "PY=" in bat_content: @@ -617,7 +608,7 @@ def main() -> int: print("Attempting to call shim directly...") try: result = subprocess.run( - ["powershell", "-NoProfile", "-Command", f"& '{mm_ps1}' --help"], + [str(mm_bat), "--help"], capture_output=True, text=True, timeout=5 ) if result.returncode == 0: @@ -629,7 +620,7 @@ def main() -> int: print("Possible causes and fixes:") print(f" 1. Terminal needs restart: Close and reopen your terminal/PowerShell") print(f" 2. PATH reload: Run: $env:Path = [Environment]::GetEnvironmentVariable('PATH', 'User') + ';' + [Environment]::GetEnvironmentVariable('PATH', 'Machine')") - print(f" 3. Manual PATH: Add C:\\Users\\Admin\\bin to your system PATH manually") + print(f" 3. Manual PATH: Add {user_bin} to your system PATH manually") else: print(f" ✗ Direct shim call failed") if result.stderr: @@ -1001,35 +992,7 @@ 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) - # Convert repo path to string with proper escaping - repo_str = str(repo).replace("\\", "\\\\") - - # Write mm.ps1 (PowerShell shim) - mm_ps1 = user_bin / "mm.ps1" - ps1_text = ( - "Param([Parameter(ValueFromRemainingArguments=$true)] $args)\n" - f'$repo = "{repo_str}"\n' - "$venv = Join-Path $repo '.venv'\n" - "$py = Join-Path $venv 'Scripts\\python.exe'\n" - "if (Test-Path $py) {\n" - " if ($env:MM_DEBUG) {\n" - ' Write-Host "MM_DEBUG: using venv python at $py" -ForegroundColor Yellow\n' - " & $py -c \"import sys; print('sys.executable:', sys.executable); print('sys.path:', sys.path[:5])\"\n" - " }\n" - " & $py -m scripts.cli_entry @args; exit $LASTEXITCODE\n" - "}\n" - "# Fallback to system python if venv doesn't exist\n" - "if ($env:MM_DEBUG) { Write-Host 'MM_DEBUG: venv python not found at' $py ', trying system python' -ForegroundColor Yellow }\n" - "python -m scripts.cli_entry @args\n" - ) - 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") - if not args.quiet: - print(f"Created {mm_ps1}") - - # Write mm.bat (CMD shim for better compatibility) + # 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 = ( @@ -1056,15 +1019,12 @@ if (Test-Path (Join-Path $repo 'CLI.py')) { mm_bat.replace(bak) mm_bat.write_text(bat_text, encoding="utf-8") - # Validate that shim files were created correctly - ps1_ok = mm_ps1.exists() and len(mm_ps1.read_text(encoding="utf-8")) > 0 + # 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 ps1_ok or not bat_ok: - raise RuntimeError(f"Failed to create shim files: mm.ps1={ps1_ok}, mm.bat={bat_ok}") + if not bat_ok: + raise RuntimeError("Failed to create mm.bat shim") if args.debug: - print(f"DEBUG: Created mm.ps1 ({len(ps1_text)} bytes)") print(f"DEBUG: Created mm.bat ({len(bat_text)} bytes)") print(f"DEBUG: Repo path embedded in shims: {repo}") print(f"DEBUG: Venv location: {repo}/.venv") @@ -1117,26 +1077,13 @@ if (Test-Path (Join-Path $repo 'CLI.py')) { print(f"DEBUG: Could not persist PATH to registry: {e}", file=sys.stderr) if not args.quiet: - print(f"Installed global launchers to: {user_bin}") - print(f"✓ mm.ps1 (PowerShell)") - print(f"✓ mm.bat (Command Prompt)") + print(f"Installed global launcher to: {user_bin}") + print(f"✓ mm.bat (Command Prompt and PowerShell)") print() - print("You can now run 'mm' from any shell to start the application.") - print() - print("📝 If 'mm' is not recognized, you may need to:") - print(f" 1. Restart your terminal") - print(f" 2. Or add '{user_bin}' manually to your PATH") - print() - print("🐛 Debug mode: Set MM_DEBUG=1 environment variable for detailed info:") - print(" PowerShell: $env:MM_DEBUG=1; mm --help") - print(" CMD: set MM_DEBUG=1 && mm --help") - - if not args.quiet: - print(f"\nInstalled global launchers to: {user_bin}") - print(f"✓ mm.ps1 (PowerShell)") - print(f"✓ mm.bat (Command Prompt)") - print(f"\nYou can now run 'mm' from any terminal window.") - print(f"To use in the current terminal, reload your profile or run: $env:PATH = '{str_bin};' + $env:PATH") + print("You can now run 'mm' from any terminal window.") + print(f"If 'mm' is not found, restart your terminal or reload PATH:") + print(" PowerShell: $env:PATH = [Environment]::GetEnvironmentVariable('PATH','User') + ';' + [Environment]::GetEnvironmentVariable('PATH','Machine')") + print(" CMD: path %PATH%") else: # POSIX