chore: 将 Impeccable 更新到 4.8.0

This commit is contained in:
2026-10-29 17:42:50 +08:00
parent a53ada10de
commit 9f44082c8a
22 changed files with 313 additions and 113 deletions
+1 -1
View File
@@ -1 +1 @@
0.1.16
0.1.18
@@ -4,7 +4,7 @@
"argumentHint": "[feature description]"
},
"init": {
"description": "Sets up a project for impeccable. Runs a multi-round discovery interview when context is missing and writes PRODUCT.md (strategic: users, brand, principles); offers DESIGN.md (visual: colors, typography, components) when code exists; pre-configures live mode; then recommends the best commands to run next. Every other command reads these files before doing work. Use once per project.",
"description": "Sets up a project for impeccable. Runs a multi-round discovery interview when context is missing and writes PRODUCT.md (strategic: users, brand, principles); pre-configures live mode; then recommends the best commands to run next. Every other command reads these files before doing work. Use once per project.",
"argumentHint": ""
},
"document": {
@@ -88,7 +88,7 @@
"argumentHint": "[target]"
},
"shape": {
"description": "Plan UX and UI before code. Runs a required multi-round discovery interview, uses visual probes when available, and produces a user-confirmed design brief for implementation.",
"description": "Plan UX and UI before code. Runs a discovery interview (one round by default), uses visual probes when available, and produces a user-confirmed design brief for implementation.",
"argumentHint": "[feature to shape]"
},
"typeset": {
@@ -0,0 +1,9 @@
# Engine binary digests for the pinned ENGINE_VERSION: <engine-version> <asset> <sha256>.
# The launchers, the npm shim, `impeccable install` and scripts/fetch-engine.mjs verify
# every engine download against this file. Written by
# `node scripts/check-engine-release.mjs --record` after each engine release.
0.1.18 impeccable-darwin-arm64 543ee2f72036ad185dc9991ac3ba86b74d91f988f3d497776a088b8b65c8a9e1
0.1.18 impeccable-darwin-x64 1f1eee78c142f7e40e16f481aeeeb1fad1d8515d8a1ef033d7c6d133e52232b3
0.1.18 impeccable-linux-x64 736ed785e74ae2344d3036127f614ddde5ab520a527d8bc82a891612ef71f648
0.1.18 impeccable-linux-arm64 317cb18d64b0f7715681dd6e574ad64b2adb5a6caf8e7a1b3b57965f805404be
0.1.18 impeccable-windows-x64.exe 8f61e96b0c97001546a824d79b44f46b423b560f3eb1a0cc44a8695a1b395d9f
+70 -33
View File
@@ -8,7 +8,10 @@
# named `impeccable`, and exec'ing it would fail every verb with
# "Unknown command". Trusted candidates (IMPECCABLE_BIN, the sibling binary,
# the version-pinned cache) are exec'd without a probe: hooks run them on
# every edit and must stay fast.
# every edit and must stay fast. The version-pinned cache and the download are
# verified against engine-checksums.txt (next to this script), never against
# anything published beside the binary; a <binary>.verified stamp records that
# a cached binary passed, so only the first run hashes it.
set -eu
# True when the candidate answers the engine handshake (prints
@@ -18,14 +21,51 @@ set -eu
# then skips its own probes and refuses to download, so probing stays cheap
# and can never loop.
probe_ok() {
case "$(IMPECCABLE_LAUNCHER_PROBE=1 "$1" engine-probe 2>/dev/null || true)" in
probe_out=$(IMPECCABLE_LAUNCHER_PROBE=1 "$1" engine-probe 2>/dev/null) || return 1
case "$probe_out" in
impeccable-engine*) return 0 ;;
esac
return 1
}
probing=${IMPECCABLE_LAUNCHER_PROBE:-}
# Prints the digest engine-checksums.txt records for engine version $1 and
# asset $2 (lines are "<version> <asset> <sha256>"), nothing when there is none.
# A CR is a separator too (CRLF checkouts), and a last line with no newline
# still counts.
manifest_digest() {
[ -f "$manifest" ] || return 0
while IFS="$(printf ' \t\r')" read -r m_version m_asset m_sum _ || [ -n "$m_version" ]; do
case "$m_version" in ''|'#'*) continue ;; esac
if [ "$m_version" = "$1" ] && [ "$m_asset" = "$2" ]; then
printf '%s' "$m_sum"
return 0
fi
done < "$manifest"
return 0
}
# Sets $expected (and, on Windows on ARM, which runs x64 binaries,
# $expected_x64) from engine-checksums.txt. Only called off the stamped fast
# path: hooks run this launcher on every edit.
read_expected() {
expected=$(manifest_digest "$version" "$asset")
expected_x64=""
if [ "$os" = windows ] && [ "$arch" = arm64 ]; then
expected_x64=$(manifest_digest "$version" impeccable-windows-x64.exe)
fi
}
# Sets $actual to the sha256 of $1, empty when no hash tool works.
hash_file() {
actual=""
if command -v shasum >/dev/null 2>&1; then
if digest=$(shasum -a 256 "$1" 2>/dev/null); then actual=${digest%% *}; fi
elif command -v sha256sum >/dev/null 2>&1; then
if digest=$(sha256sum "$1" 2>/dev/null); then actual=${digest%% *}; fi
fi
}
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
manifest="$dir/engine-checksums.txt"
# What the binary needs to know about its home: the skill directory (for
# reference/*.md and command-metadata.json) and how to name itself in the
@@ -77,8 +117,19 @@ version=""
[ -f "$dir/VERSION" ] && version=$(tr -d '[:space:]' < "$dir/VERSION")
cache_root="${IMPECCABLE_HOME:-${HOME:-/nonexistent}/.impeccable}"
cached="$cache_root/bin/$version/impeccable$exe"
asset="impeccable-$os-$arch"
[ "$os" = windows ] && asset="$asset.exe"
if [ -n "$version" ] && [ -x "$cached" ]; then
exec "$cached" "$@"
if [ -f "$cached.verified" ]; then
exec "$cached" "$@"
fi
read_expected
hash_file "$cached"
if [ -n "$actual" ] && { [ "$actual" = "$expected" ] || [ "$actual" = "$expected_x64" ]; }; then
{ echo "$actual" > "$cached.verified"; } 2>/dev/null || :
exec "$cached" "$@"
fi
echo "impeccable: cannot verify the cached engine $cached against $manifest; not using it" >&2
fi
if [ -z "$probing" ] && command -v impeccable >/dev/null 2>&1 && probe_ok impeccable; then
exec impeccable "$@"
@@ -104,12 +155,11 @@ fetch_url() {
check_download() {
download_file=${1:-$tmp}
if [ ! -f "$download_file" ]; then
rm -f "$tmp.sha256"
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." >&2
exit 127
fi
if [ ! -s "$download_file" ]; then
rm -f "$download_file" "$tmp.sha256"
rm -f "$download_file"
echo "impeccable: downloaded file is empty: $url; refusing the unverified download" >&2
exit 127
fi
@@ -120,13 +170,17 @@ if [ -n "$probing" ]; then
fi
if [ -n "$version" ] && [ "$os" != unknown ] && [ "$arch" != unknown ]; then
base="${IMPECCABLE_DOWNLOAD_BASE:-https://github.com/pbakaus/impeccable/releases/download}"
asset="impeccable-$os-$arch"
[ "$os" = windows ] && asset="$asset.exe"
url="$base/engine-v$version/$asset"
read_expected
# Fail closed before any network traffic or cache write.
if [ -z "$expected" ] && [ -z "$expected_x64" ]; then
echo "impeccable: no checksum for engine $version ($asset) in $manifest; refusing the unverified download" >&2
exit 127
fi
tmp="$cache_root/bin/$version/.impeccable.part.$$"
# An interrupted download (Ctrl-C, a hook timeout) would otherwise leave the
# PID-named staging file behind for good. The handlers must exit explicitly.
cleanup() { rm -f "$tmp" "$tmp.sha256" 2>/dev/null || :; }
cleanup() { rm -f "$tmp" 2>/dev/null || :; }
trap 'cleanup; exit 129' HUP
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
@@ -143,40 +197,22 @@ if [ -n "$version" ] && [ "$os" != unknown ] && [ "$arch" != unknown ]; then
exit 127
fi
fetched=0
if fetch_url "$url"; then
if [ -n "$expected" ] && fetch_url "$url"; then
fetched=1
elif [ "$os" = windows ] && [ "$arch" = arm64 ]; then
elif [ -n "$expected_x64" ]; then
# Windows on ARM runs x64 binaries; fall back when no arm64 asset exists.
url="$base/engine-v$version/impeccable-windows-x64.exe"
expected=$expected_x64
fetch_url "$url" && fetched=1
fi
if [ "$fetched" = 1 ]; then
check_download
# Fail closed: a freshly downloaded binary runs only after verifying
# against its .sha256 sidecar. A sidecar that cannot be fetched, or a
# machine with no sha256 tool, refuses the download instead of exec'ing
# an unverified binary. (A binary already on PATH or in the cache that
# passes engine-probe is unaffected.)
sidecar_ok=0
if command -v curl >/dev/null 2>&1; then
curl -fsSL --retry 2 -o "$tmp.sha256" "$url.sha256" 2>/dev/null && sidecar_ok=1
elif command -v wget >/dev/null 2>&1; then
wget -q -O "$tmp.sha256" "$url.sha256" 2>/dev/null && sidecar_ok=1
fi
# No sha256 tool refuses the download too.
hash_file "$tmp"
check_download
expected=""
[ "$sidecar_ok" = 1 ] && expected=$(cut -d' ' -f1 < "$tmp.sha256")
actual=""
if command -v shasum >/dev/null 2>&1; then
if digest=$(shasum -a 256 "$tmp" 2>/dev/null); then actual=${digest%% *}; fi
elif command -v sha256sum >/dev/null 2>&1; then
if digest=$(sha256sum "$tmp" 2>/dev/null); then actual=${digest%% *}; fi
fi
check_download
rm -f "$tmp.sha256"
if [ -z "$expected" ] || [ -z "$actual" ]; then
if [ -z "$actual" ]; then
rm -f "$tmp"
echo "impeccable: cannot verify $url against $url.sha256 (sidecar unavailable or hashing failed); refusing the unverified download" >&2
echo "impeccable: cannot verify $url (no sha256 tool, or hashing failed); refusing the unverified download" >&2
exit 127
fi
if [ "$actual" != "$expected" ]; then
@@ -199,6 +235,7 @@ if [ -n "$version" ] && [ "$os" != unknown ] && [ "$arch" != unknown ]; then
exit 127
fi
check_download "$cached"
{ echo "$actual" > "$cached.verified"; } 2>/dev/null || :
exec "$cached" "$@"
fi
rm -f "$tmp" 2>/dev/null
@@ -13,10 +13,11 @@ rem - The unversioned user binary and the PATH candidate are validated with
rem the engine-probe handshake (see :probe) so the retired 3.x npm CLI,
rem whose bin is also named impeccable, is never exec'd. IMPECCABLE_BIN,
rem the sibling binary, and the version-pinned cache stay trusted.
rem - Downloads are verified against the .sha256 sidecar via certutil and
rem fail closed: a missing sidecar or hash tool refuses the download. On
rem ARM64 the arm64 asset is tried first and the x64 asset is the
rem fallback (Windows on ARM runs x64 binaries).
rem - Downloads and the version-pinned cache are verified via certutil
rem against engine-checksums.txt next to this file, and fail closed; a
rem .verified stamp lets later runs skip hashing the cache. On ARM64 the
rem arm64 asset is tried first and the x64 asset is the fallback (Windows on
rem ARM runs x64 binaries), each only when the manifest has a line for it.
if not defined IMPECCABLE_SKILL_DIR set "IMPECCABLE_SKILL_DIR=%~dp0.."
if not defined IMPECCABLE_SELF set "IMPECCABLE_SELF=%~f0"
set "arch=x64"
@@ -47,8 +48,22 @@ set "version="
if exist "%~dp0VERSION" set /p version=<"%~dp0VERSION"
if not defined IMPECCABLE_HOME set "IMPECCABLE_HOME=%USERPROFILE%\.impeccable"
set "cached=%IMPECCABLE_HOME%\bin\%version%\impeccable.exe"
set "asset=impeccable-windows-%arch%.exe"
set "manifest=%~dp0engine-checksums.txt"
if not defined version goto no_cache
if not exist "%cached%" goto no_cache
if exist "%cached%.verified" goto cache_trusted
call :read_expected
call :sha256 "%cached%" "%TEMP%\impeccable-hash-%RANDOM%%RANDOM%.txt"
if not defined actual goto cache_unverified
if /I "%actual%"=="%expected%" goto cache_verified
if /I "%actual%"=="%expected_x64%" goto cache_verified
:cache_unverified
echo impeccable: cannot verify the cached engine "%cached%" against "%manifest%"; not using it 1>&2
goto no_cache
:cache_verified
(>"%cached%.verified" echo %actual%) 2>nul
:cache_trusted
set "run=%cached%"
goto run
:no_cache
@@ -67,6 +82,8 @@ rem the version-pinned user cache, verify it, then run it. Never inside
rem another launcher's probe: fail fast and quiet instead.
if defined IMPECCABLE_LAUNCHER_PROBE exit /b 127
if not defined version goto fail
call :read_expected
if not defined expected if not defined expected_x64 goto no_checksum
where curl.exe >nul 2>nul
if errorlevel 1 goto curl_missing
if not defined IMPECCABLE_DOWNLOAD_BASE set "IMPECCABLE_DOWNLOAD_BASE=https://github.com/pbakaus/impeccable/releases/download"
@@ -93,16 +110,17 @@ set "staging=%IMPECCABLE_HOME%\bin\%version%\.impeccable.part.%stamp%-%RANDOM%%R
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.
(type nul >"%part%") 2>nul || goto staging_write_failed
set "asset=impeccable-windows-%arch%.exe"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
if not defined expected goto fetch_x64
curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if not errorlevel 1 goto verify
if not "%arch%"=="arm64" goto download_failed
:fetch_x64
if not defined expected_x64 goto download_failed
set "asset=impeccable-windows-x64.exe"
set "expected=%expected_x64%"
set "url=%IMPECCABLE_DOWNLOAD_BASE%/engine-v%version%/%asset%"
curl.exe -fsSL -o "%part%" "%url%" >nul 2>nul
if errorlevel 1 goto download_failed
@@ -111,28 +129,13 @@ if errorlevel 1 goto download_failed
call :check_download
if errorlevel 1 exit /b 127
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 "%sidecar%" "%url%.sha256" >nul 2>nul
if errorlevel 1 goto verify_refuse
set "expected="
set /p expected=<"%sidecar%"
for /f "tokens=1" %%h in ("%expected%") do set "expected=%%h"
rem runs only after its hash matches the digest read from engine-checksums.txt.
rem An empty certutil result refuses the download instead of running an
rem unverified binary.
call :sha256 "%part%" "%staging%\hash.txt"
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 "%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 ("%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
call :discard_staging
echo impeccable: checksum mismatch downloading %url% 1>&2
@@ -142,9 +145,40 @@ exit /b 127
call :check_download
if errorlevel 1 exit /b 127
call :discard_staging
echo impeccable: cannot verify %url% against %url%.sha256; refusing the unverified download 1>&2
echo impeccable: cannot verify %url% (certutil could not hash it); refusing the unverified download 1>&2
exit /b 127
:read_expected
rem Sets expected (and, on ARM64, expected_x64: Windows on ARM runs x64
rem binaries) from engine-checksums.txt. Only called off the stamped path:
rem hooks run this launcher on every edit.
call :manifest_digest "%asset%" expected
set "expected_x64="
if "%arch%"=="arm64" call :manifest_digest impeccable-windows-x64.exe expected_x64
exit /b 0
:manifest_digest
rem Sets the variable named %2 to the digest the first engine-checksums.txt
rem line for this version and asset %1 records, empty when there is none.
set "%~2="
if not exist "%manifest%" exit /b 0
for /f "usebackq tokens=1-3" %%a in ("%manifest%") do if "%%a"=="%version%" if /I "%%b"=="%~1" if not defined %~2 set "%~2=%%c"
exit /b 0
:sha256
rem Sets actual to the sha256 of %~1, empty when certutil fails. %~2 is the
rem scratch file for its output. Check certutil's status before parsing: its
rem error text on stdout is not a digest.
set "actual="
certutil -hashfile "%~1" SHA256 >"%~2" 2>nul
if errorlevel 1 goto sha256_done
for /f "usebackq skip=1 delims=" %%h in ("%~2") do if not defined actual set "actual=%%h"
if not defined actual goto sha256_done
set "actual=%actual: =%"
:sha256_done
del "%~2" >nul 2>nul
exit /b 0
:check_download
set "download_file=%~1"
if not defined download_file set "download_file=%part%"
@@ -177,6 +211,7 @@ if errorlevel 1 goto place_failed
call :discard_staging
call :check_download "%cached%"
if errorlevel 1 exit /b 127
(>"%cached%.verified" echo %actual%) 2>nul
set "run=%cached%"
goto run
@@ -208,6 +243,10 @@ if not errorlevel 1 set "probe_ok=1"
del "%probe_tmp%" >nul 2>nul
exit /b 0
:no_checksum
echo impeccable: no checksum for engine %version% (%asset%) in "%manifest%"; refusing the unverified download 1>&2
exit /b 127
:cache_directory_failed
echo impeccable: engine %version% is not installed; cannot create cache directory: "%IMPECCABLE_HOME%\bin\%version%" 1>&2
goto setup_failed
@@ -63,9 +63,13 @@
const c = glob[i];
if (c === '*') {
if (glob[i + 1] === '*') {
re += '.*';
i += 2;
if (glob[i] === '/') i += 1;
if (glob[i] === '/') {
re += '(?:.*/)?';
i += 1;
} else {
re += '.*';
}
} else {
re += '[^/]*';
i += 1;
@@ -42,7 +42,10 @@
function createLiveBrowserSessionState({ prefix, storage, idFactory }) {
if (!prefix) throw new Error('prefix required');
const store = storage || root.localStorage;
let store = storage;
if (!store) {
try { store = root.localStorage; } catch { store = null; /* storage denied */ }
}
const makeId = idFactory || function () { return randomId8(); };
const sessionKey = prefix + '-session';
const handledKey = sessionKey + '-handled';
+109 -21
View File
@@ -13,13 +13,17 @@
'use strict';
if (typeof window === 'undefined') return;
// Take the helper token out of the global before anything else, including
// on the double-init return below: each served copy re-prepends it.
const TOKEN = window.__IMPECCABLE_TOKEN__;
try { delete window.__IMPECCABLE_TOKEN__; } catch { /* non-configurable */ }
// Guard against double-init. Bun's HTML loader may process the <script> tag
// and create a bundled copy alongside the external load, or HMR may re-execute.
// Check BEFORE reading token/port to catch all cases.
// Check BEFORE reading port to catch all cases.
if (window.__IMPECCABLE_LIVE_INIT__) return;
window.__IMPECCABLE_LIVE_INIT__ = true;
const TOKEN = window.__IMPECCABLE_TOKEN__;
const PORT = window.__IMPECCABLE_PORT__;
const APP_ROOT = window.__IMPECCABLE_APP_ROOT__ || null;
if (!TOKEN || !PORT) {
@@ -63,11 +67,13 @@
const MANUAL_APPLY_STATE_TTL_MS = 15 * 60 * 1000;
// No idFactory: the session helper's default works on plain-HTTP origins,
// where the secure-context-only randomUUID does not exist (issue #1055).
let liveStorage = null;
try { liveStorage = window.localStorage; } catch { /* storage denied */ }
let sessionState = null;
try {
sessionState = window.__IMPECCABLE_LIVE_SESSION__?.createLiveBrowserSessionState({
prefix: PREFIX,
storage: localStorage,
storage: liveStorage,
});
} catch (err) {
console.error('[impeccable] Live mode could not create its session state.', err);
@@ -2512,7 +2518,7 @@
row.appendChild(buildConfigureTrailingCluster([action, count], voiceBtn, go));
syncConfigureInputChrome();
if (!controlsLocked) setTimeout(() => input.focus(), 60);
if (!controlsLocked && !touchPrimary()) setTimeout(() => input.focus(), 60);
return row;
}
@@ -2616,7 +2622,7 @@
row.appendChild(buildConfigureTrailingCluster([count], voiceBtn, create));
syncInsertCreateButton(create, input);
syncConfigureInputChrome();
if (!controlsLocked) setTimeout(() => input.focus(), 60);
if (!controlsLocked && !touchPrimary()) setTimeout(() => input.focus(), 60);
return row;
}
@@ -3124,6 +3130,11 @@
let paramsPanelBody = null; // grid holding the knob cells
let paramsCurrentValues = {}; // {paramId: value} - mirror of the visible variant's live values
let tuneOpen = false; // whether the Tune popover is open right now
// Tune values a saved session carried across a reload: {sessionId, variant,
// values}. Cycling refreshes of that session and variant restore them (a
// resume refreshes more than once); a refresh for any other variant, or a
// knob edit, drops them.
let restoredParamValues = null;
// Theme-aware Tune popover. Appears as a drawer that slides out from the
// contextual bar's bar-facing edge (below if the bar sits below the
@@ -3260,6 +3271,54 @@
}
}
function rememberSavedParamValues(saved) {
const values = saved.paramValues;
if (!values || typeof values !== 'object' || Array.isArray(values)) return;
if (Object.keys(values).length === 0) return;
const variant = Number(saved.visible != null ? saved.visible : saved.visibleVariant) || 0;
restoredParamValues = { sessionId: saved.id || null, variant, values: { ...values } };
}
function restoredParamValuesForVisibleVariant() {
const restored = restoredParamValues;
if (!restored) return null;
if (restored.sessionId === currentSessionId && restored.variant === visibleVariant) return restored.values;
restoredParamValues = null;
return null;
}
// The local save is what a reload resumes from, so an edit is saved there
// as well as checkpointed to the server.
function noteParamEdited() {
restoredParamValues = null;
saveSession();
queueCheckpoint('param_changed');
}
// A saved value comes from storage the page does not own, and the variant
// may have been regenerated since, so it must still fit the param it names.
function isValidSavedParamValue(p, value) {
if (p.kind === 'range') {
if (typeof value !== 'number' || !Number.isFinite(value)) return false;
const min = p.min != null ? Number(p.min) : 0;
const max = p.max != null ? Number(p.max) : 1;
return value >= min && value <= max;
}
if (p.kind === 'toggle') return typeof value === 'boolean';
if (p.kind === 'steps') {
return (p.options || []).some(o => (o && typeof o === 'object' ? o.value : o) === value);
}
return false;
}
function applySavedParamValues(variantEl, params, saved) {
for (const p of params) {
if (!Object.hasOwn(saved, p.id) || !isValidSavedParamValue(p, saved[p.id])) continue;
paramsCurrentValues[p.id] = saved[p.id];
applyParamValue(variantEl, p, saved[p.id]);
}
}
function formatRangeValue(input) {
const max = parseFloat(input.max), min = parseFloat(input.min);
const v = parseFloat(input.value);
@@ -3271,6 +3330,14 @@
const P = paramsPanelPalette || barPaletteForTheme(detectPageTheme());
paramsPanelBody.innerHTML = '';
for (const p of params) {
// A knob the panel shows must be in the live values and on the variant,
// or accept drops it and the preview ignores it. Seed only missing keys
// so a reopen keeps edits.
if (!Object.hasOwn(paramsCurrentValues, p.id)) {
paramsCurrentValues[p.id] = p.default;
applyParamValue(variantEl, p, p.default);
}
const value = paramsCurrentValues[p.id];
const row = el('div', { display: 'flex', flexDirection: 'column', gap: '6px' });
const labelRow = el('div', {
display: 'flex', justifyContent: 'space-between',
@@ -3295,7 +3362,7 @@
input.min = String(p.min != null ? p.min : 0);
input.max = String(p.max != null ? p.max : 1);
input.step = String(p.step != null ? p.step : 0.05);
input.value = String(p.default);
input.value = String(value);
Object.assign(input.style, {
width: '100%', accentColor: C.brand, cursor: 'pointer',
});
@@ -3306,11 +3373,11 @@
paramsCurrentValues[p.id] = v;
readout.textContent = formatRangeValue(input);
applyParamValue(variantEl, p, v);
queueCheckpoint('param_changed');
noteParamEdited();
});
row.appendChild(input);
} else if (p.kind === 'toggle') {
const initial = !!p.default;
const initial = !!value;
readout.textContent = initial ? 'On' : 'Off';
const track = el('button', {
position: 'relative', width: '36px', height: '20px',
@@ -3337,15 +3404,15 @@
knob.style.left = next ? '18px' : '2px';
readout.textContent = next ? 'On' : 'Off';
applyParamValue(variantEl, p, next);
queueCheckpoint('param_changed');
noteParamEdited();
});
row.appendChild(track);
} else if (p.kind === 'steps') {
const opts = (p.options || []).map(o =>
typeof o === 'string' ? { value: o, label: o } : o
);
const activeOpt = opts.find(o => o.value === p.default) || opts[0];
readout.textContent = activeOpt ? activeOpt.label : String(p.default);
const activeOpt = opts.find(o => o.value === value) || opts[0];
readout.textContent = activeOpt ? activeOpt.label : String(value);
const segRow = el('div', {
display: 'grid',
gridTemplateColumns: 'repeat(' + opts.length + ', 1fr)',
@@ -3354,7 +3421,7 @@
});
const segBtns = [];
opts.forEach(o => {
const active = o.value === p.default;
const active = o.value === value;
const b = el('button', {
padding: '5px 4px', border: 'none', borderRadius: '3px',
background: active ? C.brand : 'transparent',
@@ -3374,7 +3441,7 @@
btn.style.color = on ? C.ink : P.text;
});
applyParamValue(variantEl, p, o.value);
queueCheckpoint('param_changed');
noteParamEdited();
});
segRow.appendChild(b);
segBtns.push({ btn: b, val: o.value });
@@ -4923,6 +4990,9 @@
}
const variantEl = getVisibleVariantEl();
const params = parseVariantParams(variantEl);
// Values saved before a reload come back for the variant they were saved
// on; a switch to any other variant starts from its defaults.
const restored = restoredParamValuesForVisibleVariant();
if (!variantEl || params.length === 0) {
paramsCurrentValues = {};
tuneOpen = false;
@@ -4931,6 +5001,7 @@
return;
}
applyParamDefaults(variantEl, params);
if (restored) applySavedParamValues(variantEl, params, restored);
buildParamsPanel(variantEl, params);
if (tuneOpen) {
// If already visible (variant cycled while open), refresh in place
@@ -4988,8 +5059,8 @@
const variantEl = getVisibleVariantEl();
const params = parseVariantParams(variantEl);
if (!variantEl || params.length === 0) return;
// Build fresh to ensure the current variant's controls are shown.
applyParamDefaults(variantEl, params);
// Rebuild the controls from the current values. Defaults are applied
// when the variant is initialized, not when its Tune panel is reopened.
buildParamsPanel(variantEl, params);
tuneOpen = true;
showParamsPanel();
@@ -9517,6 +9588,7 @@ void main() {
if (saved.previewMode) currentPreviewMode = saved.previewMode;
if (saved.paramValues && typeof saved.paramValues === 'object') {
paramsCurrentValues = { ...saved.paramValues };
rememberSavedParamValues(saved);
}
if (saved.parameterState) parameterGenerationState = saved.parameterState;
sessionOrigin = saved.origin === 'agent' ? 'agent' : null;
@@ -10148,10 +10220,9 @@ void main() {
hideShaderOverlay();
if (isInsert) finalizeInsertSession();
disableInlineEdit();
// Build the params panel for the restored visible variant. Previously
// this was missed on page-reload resume: showVariantInDOM above fires
// refreshParamsPanel, but state was still IDLE at that moment so it
// hid. Now that state is CYCLING, re-fire.
// Build the params panel for the restored visible variant, with any
// Tune values saved before the reload (showVariantInDOM above may
// already have refreshed; a repeat for the same variant keeps them).
refreshParamsPanel();
}
saveSession();
@@ -10592,6 +10663,11 @@ void main() {
return true;
}
// Programmatic focus raises the soft keyboard on touch devices (#1067).
function touchPrimary() {
return !!window.matchMedia?.('(pointer: coarse)').matches;
}
function shouldSteerAutoFocus() {
return shouldFocusSteerChat()
&& !steerFocusSuspended
@@ -10800,6 +10876,7 @@ void main() {
function syncPageChatFocus(reason) {
steerFocusLog('syncPageChatFocus', { reason });
if (touchPrimary()) return;
if (state === 'CONFIGURING') focusConfigureInput(reason);
else if (shouldSteerAutoFocus()) focusSteerChat(reason);
}
@@ -10987,7 +11064,8 @@ void main() {
file: opts?.file || '',
});
}
if (keepExpanded) focusPageChatInput('steer-error-restore');
if (keepExpanded && touchPrimary()) preparePageChatInputForTyping();
else if (keepExpanded) focusPageChatInput('steer-error-restore');
else syncPageChatFocus('steer-unlock');
}
@@ -13454,7 +13532,9 @@ void main() {
// Code spans
s = s.replace(/`([^`]+)`/g, (_, code) => `<code>${code}</code>`);
// Links [text](url)
s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, t, u) => `<a href="${u}" target="_blank" rel="noopener noreferrer">${t}</a>`);
s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, t, u) => (
isSafeHref(u) ? `<a href="${u}" target="_blank" rel="noopener noreferrer">${t}</a>` : t
));
// Bold
s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
// Italic (only single *…*, skip if inside bold already handled)
@@ -13462,6 +13542,14 @@ void main() {
return s;
}
function isSafeHref(url) {
// Browsers drop ASCII whitespace and C0 controls inside a scheme, so
// "java\tscript:" still runs; strip them before reading the scheme.
const probe = String(url).replace(/[\u0000-\u0020\u007f]/g, '');
const scheme = probe.match(/^([a-z][a-z0-9+.-]*):/i);
return !scheme || ['http', 'https', 'mailto'].includes(scheme[1].toLowerCase());
}
function highlightBold(text) {
return inlineMd(text);
}