This commit is contained in:
2026-01-09 17:06:48 -08:00
parent 1bd97b9665
commit 37afa15dfd
2 changed files with 31 additions and 93 deletions

View File

@@ -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