Skip to content

The design language that makes your AI harness better at design.

JavaScript

Sync generated provider output

github-actions[bot]eb0d8acd1cad
diff --git a/.agent/skills/impeccable/reference/live.md b/.agent/skills/impeccable/reference/live.md
index 1faa46b93..e0c585e28 100644
--- a/.agent/skills/impeccable/reference/live.md
+++ b/.agent/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.agent/skills/impeccable/scripts/impeccable.cmd b/.agent/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.agent/skills/impeccable/scripts/impeccable.cmd
+++ b/.agent/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.agent/skills/impeccable/scripts/live-browser.js b/.agent/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.agent/skills/impeccable/scripts/live-browser.js
+++ b/.agent/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.agents/skills/impeccable/reference/live.md b/.agents/skills/impeccable/reference/live.md
index fb85b3fdd..a042ed583 100644
--- a/.agents/skills/impeccable/reference/live.md
+++ b/.agents/skills/impeccable/reference/live.md
@@ -258,7 +258,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.agents/skills/impeccable/scripts/impeccable.cmd b/.agents/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.agents/skills/impeccable/scripts/impeccable.cmd
+++ b/.agents/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.agents/skills/impeccable/scripts/live-browser.js b/.agents/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.agents/skills/impeccable/scripts/live-browser.js
+++ b/.agents/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.claude/skills/impeccable/reference/live.md b/.claude/skills/impeccable/reference/live.md
index 4307a2121..bf38f83af 100644
--- a/.claude/skills/impeccable/reference/live.md
+++ b/.claude/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.claude/skills/impeccable/scripts/impeccable.cmd b/.claude/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.claude/skills/impeccable/scripts/impeccable.cmd
+++ b/.claude/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.claude/skills/impeccable/scripts/live-browser.js b/.claude/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.claude/skills/impeccable/scripts/live-browser.js
+++ b/.claude/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.cursor/skills/impeccable/reference/live.md b/.cursor/skills/impeccable/reference/live.md
index a25d87bfe..54d897491 100644
--- a/.cursor/skills/impeccable/reference/live.md
+++ b/.cursor/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.cursor/skills/impeccable/scripts/impeccable.cmd b/.cursor/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.cursor/skills/impeccable/scripts/impeccable.cmd
+++ b/.cursor/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.cursor/skills/impeccable/scripts/live-browser.js b/.cursor/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.cursor/skills/impeccable/scripts/live-browser.js
+++ b/.cursor/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.dsh/skills/impeccable/reference/live.md b/.dsh/skills/impeccable/reference/live.md
index b95da6b4e..2efb4469e 100644
--- a/.dsh/skills/impeccable/reference/live.md
+++ b/.dsh/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.dsh/skills/impeccable/scripts/impeccable.cmd b/.dsh/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.dsh/skills/impeccable/scripts/impeccable.cmd
+++ b/.dsh/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.dsh/skills/impeccable/scripts/live-browser.js b/.dsh/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.dsh/skills/impeccable/scripts/live-browser.js
+++ b/.dsh/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.gemini/skills/impeccable/reference/live.md b/.gemini/skills/impeccable/reference/live.md
index b6f93743b..d1fcdaeb8 100644
--- a/.gemini/skills/impeccable/reference/live.md
+++ b/.gemini/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.gemini/skills/impeccable/scripts/impeccable.cmd b/.gemini/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.gemini/skills/impeccable/scripts/impeccable.cmd
+++ b/.gemini/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.gemini/skills/impeccable/scripts/live-browser.js b/.gemini/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.gemini/skills/impeccable/scripts/live-browser.js
+++ b/.gemini/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.github/skills/impeccable/reference/live.md b/.github/skills/impeccable/reference/live.md
index bbd0639e3..90b74456a 100644
--- a/.github/skills/impeccable/reference/live.md
+++ b/.github/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.github/skills/impeccable/scripts/impeccable.cmd b/.github/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.github/skills/impeccable/scripts/impeccable.cmd
+++ b/.github/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.github/skills/impeccable/scripts/live-browser.js b/.github/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.github/skills/impeccable/scripts/live-browser.js
+++ b/.github/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.grok/skills/impeccable/reference/live.md b/.grok/skills/impeccable/reference/live.md
index 8905f0732..0a06a68fd 100644
--- a/.grok/skills/impeccable/reference/live.md
+++ b/.grok/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.grok/skills/impeccable/scripts/impeccable.cmd b/.grok/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.grok/skills/impeccable/scripts/impeccable.cmd
+++ b/.grok/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.grok/skills/impeccable/scripts/live-browser.js b/.grok/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.grok/skills/impeccable/scripts/live-browser.js
+++ b/.grok/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.hermes/skills/impeccable/reference/live.md b/.hermes/skills/impeccable/reference/live.md
index 87e3dc812..f61b75be5 100644
--- a/.hermes/skills/impeccable/reference/live.md
+++ b/.hermes/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.hermes/skills/impeccable/scripts/impeccable.cmd b/.hermes/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.hermes/skills/impeccable/scripts/impeccable.cmd
+++ b/.hermes/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.hermes/skills/impeccable/scripts/live-browser.js b/.hermes/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.hermes/skills/impeccable/scripts/live-browser.js
+++ b/.hermes/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.kiro/skills/impeccable/reference/live.md b/.kiro/skills/impeccable/reference/live.md
index 0b91c2113..ef342ab14 100644
--- a/.kiro/skills/impeccable/reference/live.md
+++ b/.kiro/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.kiro/skills/impeccable/scripts/impeccable.cmd b/.kiro/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.kiro/skills/impeccable/scripts/impeccable.cmd
+++ b/.kiro/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.kiro/skills/impeccable/scripts/live-browser.js b/.kiro/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.kiro/skills/impeccable/scripts/live-browser.js
+++ b/.kiro/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.omp/skills/impeccable/reference/live.md b/.omp/skills/impeccable/reference/live.md
index 925d5b1e1..b2f84fdab 100644
--- a/.omp/skills/impeccable/reference/live.md
+++ b/.omp/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.omp/skills/impeccable/scripts/impeccable.cmd b/.omp/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.omp/skills/impeccable/scripts/impeccable.cmd
+++ b/.omp/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.omp/skills/impeccable/scripts/live-browser.js b/.omp/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.omp/skills/impeccable/scripts/live-browser.js
+++ b/.omp/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.opencode/skills/impeccable/reference/live.md b/.opencode/skills/impeccable/reference/live.md
index 64f0e7931..8bbc0a772 100644
--- a/.opencode/skills/impeccable/reference/live.md
+++ b/.opencode/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.opencode/skills/impeccable/scripts/impeccable.cmd b/.opencode/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.opencode/skills/impeccable/scripts/impeccable.cmd
+++ b/.opencode/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.opencode/skills/impeccable/scripts/live-browser.js b/.opencode/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.opencode/skills/impeccable/scripts/live-browser.js
+++ b/.opencode/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.pi/skills/impeccable/reference/live.md b/.pi/skills/impeccable/reference/live.md
index c22aed17b..c322420e1 100644
--- a/.pi/skills/impeccable/reference/live.md
+++ b/.pi/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.pi/skills/impeccable/scripts/impeccable.cmd b/.pi/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.pi/skills/impeccable/scripts/impeccable.cmd
+++ b/.pi/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.pi/skills/impeccable/scripts/live-browser.js b/.pi/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.pi/skills/impeccable/scripts/live-browser.js
+++ b/.pi/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.qoder/skills/impeccable/reference/live.md b/.qoder/skills/impeccable/reference/live.md
index 8748426a6..1251f1ea9 100644
--- a/.qoder/skills/impeccable/reference/live.md
+++ b/.qoder/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.qoder/skills/impeccable/scripts/impeccable.cmd b/.qoder/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.qoder/skills/impeccable/scripts/impeccable.cmd
+++ b/.qoder/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.qoder/skills/impeccable/scripts/live-browser.js b/.qoder/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.qoder/skills/impeccable/scripts/live-browser.js
+++ b/.qoder/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.rovodev/skills/impeccable/reference/live.md b/.rovodev/skills/impeccable/reference/live.md
index 603448ff2..7a372e443 100644
--- a/.rovodev/skills/impeccable/reference/live.md
+++ b/.rovodev/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.rovodev/skills/impeccable/scripts/impeccable.cmd b/.rovodev/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.rovodev/skills/impeccable/scripts/impeccable.cmd
+++ b/.rovodev/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.rovodev/skills/impeccable/scripts/live-browser.js b/.rovodev/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.rovodev/skills/impeccable/scripts/live-browser.js
+++ b/.rovodev/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.trae-cn/skills/impeccable/reference/live.md b/.trae-cn/skills/impeccable/reference/live.md
index 799b869a0..785c494bf 100644
--- a/.trae-cn/skills/impeccable/reference/live.md
+++ b/.trae-cn/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.trae-cn/skills/impeccable/scripts/impeccable.cmd b/.trae-cn/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.trae-cn/skills/impeccable/scripts/impeccable.cmd
+++ b/.trae-cn/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.trae-cn/skills/impeccable/scripts/live-browser.js b/.trae-cn/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.trae-cn/skills/impeccable/scripts/live-browser.js
+++ b/.trae-cn/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.trae/skills/impeccable/reference/live.md b/.trae/skills/impeccable/reference/live.md
index 766ed2527..ace029f71 100644
--- a/.trae/skills/impeccable/reference/live.md
+++ b/.trae/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.trae/skills/impeccable/scripts/impeccable.cmd b/.trae/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.trae/skills/impeccable/scripts/impeccable.cmd
+++ b/.trae/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.trae/skills/impeccable/scripts/live-browser.js b/.trae/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.trae/skills/impeccable/scripts/live-browser.js
+++ b/.trae/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.veto/skills/impeccable/reference/live.md b/.veto/skills/impeccable/reference/live.md
index 0b0e9f162..15eec19ce 100644
--- a/.veto/skills/impeccable/reference/live.md
+++ b/.veto/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.veto/skills/impeccable/scripts/impeccable.cmd b/.veto/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.veto/skills/impeccable/scripts/impeccable.cmd
+++ b/.veto/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.veto/skills/impeccable/scripts/live-browser.js b/.veto/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.veto/skills/impeccable/scripts/live-browser.js
+++ b/.veto/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/.vibe/skills/impeccable/reference/live.md b/.vibe/skills/impeccable/reference/live.md
index 3f54c78df..a48437be7 100644
--- a/.vibe/skills/impeccable/reference/live.md
+++ b/.vibe/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/.vibe/skills/impeccable/scripts/impeccable.cmd b/.vibe/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/.vibe/skills/impeccable/scripts/impeccable.cmd
+++ b/.vibe/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/.vibe/skills/impeccable/scripts/live-browser.js b/.vibe/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/.vibe/skills/impeccable/scripts/live-browser.js
+++ b/.vibe/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/cursor-plugin/skills/impeccable/reference/live.md b/cursor-plugin/skills/impeccable/reference/live.md
index 0df66f1e0..ed02659a8 100644
--- a/cursor-plugin/skills/impeccable/reference/live.md
+++ b/cursor-plugin/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/cursor-plugin/skills/impeccable/scripts/impeccable.cmd b/cursor-plugin/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/cursor-plugin/skills/impeccable/scripts/impeccable.cmd
+++ b/cursor-plugin/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/cursor-plugin/skills/impeccable/scripts/live-browser.js b/cursor-plugin/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/cursor-plugin/skills/impeccable/scripts/live-browser.js
+++ b/cursor-plugin/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();
diff --git a/plugin/skills/impeccable/reference/live.md b/plugin/skills/impeccable/reference/live.md
index 0df66f1e0..ed02659a8 100644
--- a/plugin/skills/impeccable/reference/live.md
+++ b/plugin/skills/impeccable/reference/live.md
@@ -256,7 +256,7 @@ If wrap or generation fails after the browser flipped to GENERATING, tell the **
When wrap returns `fallback: "agent-driven"`, you pick the source file yourself; the goal is unchanged: three preview variants now, and the accepted one persisted where the next build cannot wipe it.
1. **Find where the element really lives** from the error payload: `element_not_in_source` + `generatedMatch` means the served HTML is generated, so find the generator's template or partial; `element_not_found` means runtime-injected, so find the rendering component or data source; `file_is_generated` resolves the same way. A purely visual change may belong in a shared stylesheet rather than a template.
-2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces (`<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents">…</div><!-- end -->`) into the file the browser actually loaded, insert your variant divs, `--reply EVENT_ID done --file <served file>`. This edit is temporary; a regen wiping it is fine.
+2. **Preview in the served file**: manually write the same wrapper scaffold `impeccable live-wrap` produces into the file the browser actually loaded, moving the element itself into the original slot: `<!-- impeccable-variants-start ID --><div data-impeccable-variants="ID" data-impeccable-variant-count="3" style="display: contents"><div data-impeccable-variant="original">THE ELEMENT, UNCHANGED</div><!-- Variants: insert below this line --></div><!-- impeccable-variants-end ID -->`. Insert your variant divs after the marker, then `--reply EVENT_ID done --file <served file>`. Never drop the original slot: discard restores the element from it and refuses a wrapper without one. This edit is temporary; a regen wiping it is fine.
3. **On accept, write to true source** (accept refuses generated files, so `_acceptResult.handled` is usually `false` here): structural change → template/component source; visual-only → the right stylesheet; content rendered from data → the data source or render logic. Then remove the temporary wrapper from the served file.
4. **On discard**, just remove the temporary wrapper.
diff --git a/plugin/skills/impeccable/scripts/impeccable.cmd b/plugin/skills/impeccable/scripts/impeccable.cmd
index dc0fd33e5..789a96f4c 100644
--- a/plugin/skills/impeccable/scripts/impeccable.cmd
+++ b/plugin/skills/impeccable/scripts/impeccable.cmd
@@ -74,20 +74,37 @@ if exist "%IMPECCABLE_HOME%\bin\%version%\" goto cache_ready
mkdir "%IMPECCABLE_HOME%\bin\%version%" >nul 2>nul
if errorlevel 1 goto cache_directory_failed
:cache_ready
-rem Check the staging file too: an existing directory may be read-only.
+rem Stage the download in a directory only this run owns, as the sh launcher
+rem does with .impeccable.part.$$: concurrent first runs (parallel hooks, two
+rem agents) must never write, hash or move each other's files. mkdir fails
+rem when the name exists, so it claims the name atomically. RANDOM alone is
+rem not enough because cmd seeds it from the clock in whole seconds; the
+rem timestamp and the retry on collision keep same-second runs apart. A cache
+rem directory that refuses every mkdir is reported as unwritable.
+set "attempt=0"
+:claim_staging
+set /a attempt+=1
+if %attempt% GTR 20 goto cache_write_failed
+set "stamp=%TIME: =0%"
+set "stamp=%stamp::=%"
+set "stamp=%stamp:.=%"
+set "stamp=%stamp:,=%"
+set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%RANDOM%"
+mkdir "%staging%" >nul 2>nul
+if errorlevel 1 goto claim_staging
+set "part=%staging%\impeccable.exe"
+set "sidecar=%staging%\impeccable.sha256"
rem Redirection failures do not reliably update ERRORLEVEL in cmd.exe;
-rem branch on the command's failure directly. Never treat a directory as a
-rem staging file (later del cleanup would prompt to delete its contents).
-if exist "%cached%.part\" goto cache_write_failed
-(type nul >"%cached%.part") 2>nul || goto cache_write_failed
+rem branch on the command's failure directly.
+(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
set "asset=impeccable-windows-x64.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
-curl.exe -fsSL -o "%cached%.part" "%url%" >nul 2>nul
+curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
:verify
@@ -97,61 +114,67 @@ rem Mirrors the sh launcher and fails closed: a freshly downloaded binary
rem runs only after verifying against its .sha256 sidecar. A sidecar that
rem cannot be fetched, or an empty certutil result, refuses the download
rem instead of running an unverified binary.
-curl.exe -fsSL -o "%cached%.sha256" "%url%.sha256" >nul 2>nul
+curl.exe -fsSL -o "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
-set /p expected=<"%cached%.sha256"
+set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
call :check_download
if errorlevel 1 exit /b 127
set "actual="
rem Reuse the sidecar staging file after reading expected. Check certutil's
rem status before parsing: its error text on stdout is not a digest.
-certutil -hashfile "%cached%.part" SHA256 >"%cached%.sha256" 2>nul
+certutil -hashfile "%part%" SHA256 >"%sidecar%" 2>nul
if errorlevel 1 goto verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-for /f "usebackq skip=1 delims=" %%h in ("%cached%.sha256") do if not defined actual set "actual=%%h"
-del "%cached%.sha256" >nul 2>nul
+for /f "usebackq skip=1 delims=" %%h in ("%sidecar%") do if not defined actual set "actual=%%h"
+del "%sidecar%" >nul 2>nul
if not defined expected goto verify_refuse
if not defined actual goto verify_refuse
set "actual=%actual: =%"
if /I "%actual%"=="%expected%" goto place
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
exit /b 127
:verify_refuse
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
exit /b 127
:check_download
set "download_file=%~1"
-if not defined download_file set "download_file=%cached%.part"
+if not defined download_file set "download_file=%part%"
if not exist "%download_file%" goto download_missing
for %%f in ("%download_file%") do if %%~zf==0 goto download_empty
exit /b 0
:download_missing
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo 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
exit /b 127
:download_empty
del "%download_file%" >nul 2>nul
-del "%cached%.sha256" >nul 2>nul
+call :discard_staging
echo impeccable: downloaded file is empty: %url%; refusing the unverified download 1>&2
exit /b 127
+:discard_staging
+rem Removes this run's staging directory and whatever is left in it. Never
+rem touches another run's staging directory or the cached binary.
+if defined staging rd /s /q "%staging%" >nul 2>nul
+exit /b 0
+
:place
call :check_download
if errorlevel 1 exit /b 127
-move /y "%cached%.part" "%cached%" >nul 2>nul
+move /y "%part%" "%cached%" >nul 2>nul
if errorlevel 1 goto place_failed
+call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
set "run=%cached%"
@@ -160,7 +183,7 @@ goto run
:place_failed
call :check_download
if errorlevel 1 exit /b 127
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not cache the verified download: %url% 1>&2
exit /b 127
@@ -189,6 +212,9 @@ exit /b 0
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
+:staging_write_failed
+call :discard_staging
+
:cache_write_failed
echo impeccable: engine %version% is not installed; cannot write to cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -198,7 +224,7 @@ echo impeccable: cannot download engine %version%; curl.exe is unavailable. 1>&2
goto setup_failed
:download_failed
-del "%cached%.part" >nul 2>nul
+call :discard_staging
echo impeccable: could not download engine %version% from %url%; check network access and the release URL. 1>&2
:setup_failed
@@ -208,7 +234,6 @@ echo Alternatively, set IMPECCABLE_HOME to a writable cache location, or IMPECCA
exit /b 127
:fail
-del "%cached%.part" >nul 2>nul
echo impeccable: no engine binary found (looked in %bin%, %cached%, PATH). 1>&2
echo 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
exit /b 127
diff --git a/plugin/skills/impeccable/scripts/live-browser.js b/plugin/skills/impeccable/scripts/live-browser.js
index c7eed77fb..f706898e4 100644
--- a/plugin/skills/impeccable/scripts/live-browser.js
+++ b/plugin/skills/impeccable/scripts/live-browser.js
@@ -7120,6 +7120,10 @@
//
function startScrollTracking() {
+ // Idempotent: callers overlap (showBar starts tracking, then the agent
+ // pick path starts it again), and a second loop would never be cancelled
+ // because scrollRaf only remembers the latest one (#1002).
+ stopScrollTracking();
function tick() {
if (state === 'CONFIGURING' || state === 'GENERATING' || state === 'CYCLING') {
if (isInsertGeneratingSession()) ensureInsertPlaceholder();