@iasiv5/dsh-skills 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,18 +32,23 @@ probe_ok() {
32
32
  return 1
33
33
  }
34
34
  probing=${IMPECCABLE_LAUNCHER_PROBE:-}
35
+ # Space, tab and CR, made once: hooks run this launcher on every edit and turn
36
+ # end, and every process it starts before the engine costs real time on a busy
37
+ # Windows machine (#1237), so the hot path below sticks to shell builtins.
38
+ ws=$(printf ' \t\r')
35
39
 
36
- # Prints the digest engine-checksums.txt records for engine version $1 and
37
- # asset $2 (lines are "<version> <asset> <sha256>"), nothing when there is none.
40
+ # Sets $digest_out to the digest engine-checksums.txt records for engine
41
+ # version $1 and asset $2 (lines are "<version> <asset> <sha256>"), empty when
42
+ # there is none.
38
43
  # A CR is a separator too (CRLF checkouts), and a last line with no newline
39
44
  # still counts.
40
45
  manifest_digest() {
46
+ digest_out=""
41
47
  [ -f "$manifest" ] || return 0
42
- sep=$(printf ' \t\r')
43
- while IFS="$sep" read -r m_version m_asset m_sum _ || [ -n "$m_version" ]; do
48
+ while IFS="$ws" read -r m_version m_asset m_sum _ || [ -n "$m_version" ]; do
44
49
  case "$m_version" in ''|'#'*) continue ;; esac
45
50
  if [ "$m_version" = "$1" ] && [ "$m_asset" = "$2" ]; then
46
- printf '%s' "$m_sum"
51
+ digest_out=$m_sum
47
52
  return 0
48
53
  fi
49
54
  done < "$manifest"
@@ -52,10 +57,12 @@ manifest_digest() {
52
57
  # Sets $expected (and, on Windows on ARM, which runs x64 binaries,
53
58
  # $expected_x64) from engine-checksums.txt.
54
59
  read_expected() {
55
- expected=$(manifest_digest "$version" "$asset")
60
+ manifest_digest "$version" "$asset"
61
+ expected=$digest_out
56
62
  expected_x64=""
57
63
  if [ "$os" = windows ] && [ "$arch" = arm64 ]; then
58
- expected_x64=$(manifest_digest "$version" impeccable-windows-x64.exe)
64
+ manifest_digest "$version" impeccable-windows-x64.exe
65
+ expected_x64=$digest_out
59
66
  fi
60
67
  }
61
68
  # Sets $size to the byte count of the cached binary (BSD wc pads it).
@@ -73,7 +80,19 @@ hash_file() {
73
80
  fi
74
81
  }
75
82
 
76
- dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
83
+ # This script's directory without dirname or a subshell: what dirname "$0"
84
+ # gives, made absolute by a cd there and back.
85
+ case $0 in
86
+ */*) dir=${0%/*} ;;
87
+ *) dir=. ;;
88
+ esac
89
+ [ -n "$dir" ] || dir=/
90
+ caller_pwd=$PWD
91
+ CDPATH= cd -- "$dir" || { echo "impeccable: cannot enter the launcher directory $dir" >&2; exit 127; }
92
+ dir=$PWD
93
+ skill_dir=${dir%/*}
94
+ [ -n "$skill_dir" ] || skill_dir=/
95
+ cd -- "$caller_pwd" || { echo "impeccable: cannot return to $caller_pwd" >&2; exit 127; }
77
96
  # VS Code syncs a plugin without the executable bit. Its hooks run this through
78
97
  # sh, so restore the bit for the commands the skill runs directly (#1249).
79
98
  [ -x "$0" ] || chmod +x "$0" 2>/dev/null || :
@@ -86,7 +105,7 @@ manifest="$dir/engine-checksums.txt"
86
105
  # cannot find reference/*.md (so native platform refs never inline) or read its
87
106
  # own version (so UPDATE_AVAILABLE never fires). Setting it here covers every
88
107
  # candidate the launcher can exec.
89
- : "${IMPECCABLE_SKILL_DIR:=$(CDPATH= cd -- "$dir/.." && pwd)}"
108
+ : "${IMPECCABLE_SKILL_DIR:=$skill_dir}"
90
109
  : "${IMPECCABLE_SELF:=$0}"
91
110
  export IMPECCABLE_SKILL_DIR IMPECCABLE_SELF
92
111
 
@@ -94,20 +113,29 @@ if [ -n "${IMPECCABLE_BIN:-}" ] && [ -x "${IMPECCABLE_BIN}" ]; then
94
113
  exec "${IMPECCABLE_BIN}" "$@"
95
114
  fi
96
115
 
97
- case "$(uname -s 2>/dev/null || echo unknown)" in
116
+ # Windows names itself in the environment, which saves a process there; one
117
+ # uname covers the rest. PROCESSOR_ARCHITECTURE is what impeccable.cmd reads,
118
+ # so both launchers pick the same cached engine (AMD64 under x64 Git Bash on
119
+ # ARM64, as uname -m reported before).
120
+ if [ "${OS:-}" = Windows_NT ]; then
121
+ sys="Windows_NT ${PROCESSOR_ARCHITECTURE:-unknown}"
122
+ else
123
+ sys=$(uname -sm 2>/dev/null) || sys="unknown unknown"
124
+ fi
125
+ case "${sys%% *}" in
98
126
  Darwin) os=darwin ;;
99
127
  Linux) os=linux ;;
100
128
  MINGW*|MSYS*|CYGWIN*|Windows_NT) os=windows ;;
101
129
  *) os=unknown ;;
102
130
  esac
103
- case "$(uname -m 2>/dev/null || echo unknown)" in
104
- arm64|aarch64) arch=arm64 ;;
105
- x86_64|amd64) arch=x64 ;;
131
+ case "${sys##* }" in
132
+ arm64|aarch64|ARM64) arch=arm64 ;;
133
+ x86_64|amd64|AMD64) arch=x64 ;;
106
134
  *) arch=unknown ;;
107
135
  esac
108
136
 
109
137
  version=""
110
- [ -f "$dir/VERSION" ] && version=$(tr -d '[:space:]' < "$dir/VERSION")
138
+ [ -f "$dir/VERSION" ] && { IFS="$ws" read -r version _ < "$dir/VERSION" || :; }
111
139
  bin="$dir/bin/$os-$arch/impeccable"
112
140
  [ "$os" = windows ] && bin="$bin.exe"
113
141
 
@@ -136,7 +164,7 @@ if [ -n "$version" ] && [ -x "$cached" ]; then
136
164
  cached_size
137
165
  stamp=""
138
166
  stamp_size=""
139
- { IFS="$(printf ' \t\r')" read -r stamp stamp_size _ < "$cached.verified"; } 2>/dev/null || :
167
+ { IFS="$ws" read -r stamp stamp_size _ < "$cached.verified"; } 2>/dev/null || :
140
168
  if [ -n "$stamp" ] && [ "$stamp_size" = "$size" ] && { [ "$stamp" = "$expected" ] || [ "$stamp" = "$expected_x64" ]; } && [ ! "$cached" -nt "$cached.verified" ]; then
141
169
  exec "$cached" "$@"
142
170
  fi
@@ -93,11 +93,26 @@ goto run
93
93
  :no_cache
94
94
 
95
95
  if defined IMPECCABLE_LAUNCHER_PROBE goto download
96
- where impeccable >nul 2>nul
97
- if errorlevel 1 goto download
98
- call :probe impeccable
96
+ rem The first impeccable on PATH, resolved once so the probe and the run see
97
+ rem the same file. A batch shim (npm writes impeccable.cmd) must run under
98
+ rem call to return here (#1240), and call expands % in the arguments a second
99
+ rem time; a real binary runs directly so a target such as a%20b reaches it intact.
100
+ set "path_bin="
101
+ rem where also lists npm's extensionless POSIX shim, which cmd cannot run:
102
+ rem take the first match with a runnable extension.
103
+ rem Loop letters c and k are not path modifiers, so %%~xc reads as the
104
+ rem extension of c and never as a loop variable followed by text.
105
+ for /f "delims=" %%c in ('where impeccable 2^>nul') do if not defined path_bin for %%k in (.exe .com .cmd .bat) do if /I "%%~xc"=="%%k" set "path_bin=%%c"
106
+ if not defined path_bin goto download
107
+ call :probe "%path_bin%"
99
108
  if not "%probe_ok%"=="1" goto download
100
- impeccable %*
109
+ for %%k in ("%path_bin%") do set "path_ext=%%~xk"
110
+ if /I "%path_ext%"==".cmd" goto path_shim
111
+ if /I "%path_ext%"==".bat" goto path_shim
112
+ "%path_bin%" %*
113
+ exit /b %errorlevel%
114
+ :path_shim
115
+ call "%path_bin%" %*
101
116
  exit /b %errorlevel%
102
117
 
103
118
  :download
@@ -274,11 +289,13 @@ rem Sets probe_ok=1 when %1 answers the engine handshake: prints
274
289
  rem "impeccable-engine <version>" and exits 0, and probe_version to that
275
290
  rem version. The 3.x npm CLI answers any unknown verb with "Unknown command",
276
291
  rem exit 1, so it never passes.
292
+ rem The candidate runs under call: an npm .cmd shim run without it takes
293
+ rem over this script and never returns (#1240).
277
294
  set "probe_ok="
278
295
  set "probe_version="
279
296
  set "probe_tmp=%TEMP%\impeccable-probe-%RANDOM%%RANDOM%.txt"
280
297
  set "IMPECCABLE_LAUNCHER_PROBE=1"
281
- "%~1" engine-probe >"%probe_tmp%" 2>nul
298
+ call "%~1" engine-probe >"%probe_tmp%" 2>nul
282
299
  set "probe_err=%ERRORLEVEL%"
283
300
  set "IMPECCABLE_LAUNCHER_PROBE="
284
301
  if not "%probe_err%"=="0" goto probe_done