1@echo off2setlocal3rem Impeccable launcher (Windows). Runs bin\windows-<arch>\impeccable.exe next4rem to this file, else a cached or freshly downloaded engine binary.5rem6rem Structure notes (this file is exercised by dry parsing and string-level7rem tests, not yet on a real Windows machine):8rem - No multi-line parenthesized blocks: cmd expands %var% at block parse9rem time, which made the old download path read back empty %url%/%cached%.10rem Linear goto flow keeps every expansion on its own line, and avoids11rem delayed expansion eating ! characters in user arguments.12rem - The unversioned user binary and the PATH candidate are validated with13rem the engine-probe handshake (see :probe) so the retired 3.x npm CLI,14rem whose bin is also named impeccable, is never exec'd. IMPECCABLE_BIN,15rem the sibling binary, and the version-pinned cache stay trusted.16rem - Downloads are verified against the .sha256 sidecar via certutil and
129echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
130exit /b 127
131
132:check_download
133set "download_file=%~1"
134if not defined download_file set "download_file=%cached%.part"
135if not exist "%download_file%" goto download_missing
136for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
137exit /b 0
138
139:download_missing
140del "%cached%.sha256" >nul 2>nul
141echo impeccable: download completed but the file was removed before execution: %url%; check your antivirus quarantine or logs. Refusing to continue; do not disable protection. 1>&2
142exit /b 127
143
144:download_empty
145del "%download_file%" >nul 2>nul
146del "%cached%.sha256" >nul 2>nul
147echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
148exit /b 127
149
150:place
151call :check_download
152if errorlevel 1 exit /b 127
153move /y "%cached%.part" "%cached%" >nul 2>nul
154if errorlevel 1 goto place_failed
155call :check_download "%cached%"
156if errorlevel 1 exit /b 127
157set "run=%cached%"
158goto run
159
160:place_failed
161call :check_download
162if errorlevel 1 exit /b 127
163del "%cached%.part" >nul 2>nul
164echo impeccable: could not cache the verified download: %url% 1>&2
165exit /b 127
166
167:run
168"%run%" %*
169exit /b
170
171:probe
172rem Sets probe_ok=1 when %1 answers the engine handshake: prints
173rem "impeccable-engine <version>" and exits 0. The 3.x npm CLI answers any
174rem unknown verb with "Unknown command", exit 1, so it never passes.
189echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
190goto setup_failed
191
192:cache_write_failed
193echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
194goto setup_failed
195
196:curl_missing
197echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
198goto setup_failed
199
200:download_failed
201del "%cached%.part" >nul 2>nul
202echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
203
204:setup_failed
205echo Engine %version% setup needs network access and write permission to "%IMPECCABLE_HOME%\bin\%version%". 1>&2
206echo Run this launcher ("%~f0") with engine-probe in a terminal that has those permissions, then retry the original command. 1>&2
207echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCABLE_BIN to a preinstalled engine binary. 1>&2
208exit /b 127
209
210:fail
211del "%cached%.part" >nul 2>nul
212echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
213echo Download impeccable-windows-%arch%.exe from https://github.com/pbakaus/impeccable/releases (tag engine-v%version%) and save it as %cached%, or set IMPECCABLE_BIN to a preinstalled engine binary. Docs: https://impeccable.style 1>&2