import os
import subprocess

# Create a node.cmd shim in the npm-global dir
# This shim calls the real node.exe with full quoted path
shim_path = r'E:\.antigravity_cache\npm-global\node.cmd'
shim_content = '@"C:\\Program Files\\nodejs\\node.exe" %*\r\n'

with open(shim_path, 'w', encoding='ascii') as f:
    f.write(shim_content)

print(f"Created shim at: {shim_path}")
print(f"Content: {repr(shim_content)}")

# Verify it works
env = os.environ.copy()
r = subprocess.run(
    ['cmd.exe', '/c', shim_path, '--version'],
    capture_output=True, text=True, timeout=10
)
print(f"Shim test rc={r.returncode} out={r.stdout.strip()} err={r.stderr.strip()}")

with open(r'E:\genesis-system\node_shim_test.txt', 'w') as f:
    f.write(f"Shim path: {shim_path}\n")
    f.write(f"rc={r.returncode}\nout={r.stdout}\nerr={r.stderr}\n")
