dsh-plugin-wsl-env 0.21.0 → 0.23.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.
- package/CHANGELOG.md +119 -0
- package/CONTRIBUTING.md +7 -3
- package/README.md +11 -9
- package/SUPPORT.md +1 -1
- package/client.js +153 -33
- package/cordis.patch.yml +13 -4
- package/docs/AGENT-PROTOCOL-V7.md +4 -4
- package/docs/API.md +12 -2
- package/docs/ARCHITECTURE.md +59 -19
- package/docs/CONFIGURATION.md +44 -13
- package/docs/CONFIGURATION.zh.md +44 -8
- package/docs/DIAGNOSTICS.md +41 -1
- package/docs/DIAGNOSTICS.zh.md +34 -2
- package/docs/LIMITATIONS.md +42 -17
- package/docs/LIMITATIONS.zh.md +47 -12
- package/docs/MIGRATION.md +1 -1
- package/docs/PEER-PARITY.md +8 -7
- package/docs/QUICKSTART.md +16 -8
- package/docs/QUICKSTART.zh.md +22 -4
- package/docs/README.zh.md +19 -10
- package/docs/RELEASING.md +8 -3
- package/docs/REQUIREMENTS.zh.md +11 -6
- package/docs/ROADMAP-1.0.md +12 -11
- package/docs/ROADMAP.md +10 -8
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +3 -2
- package/docs/UPSTREAM-FSIO-EXPORT.md +8 -9
- package/docs/UPSTREAM-SERVICE-SWAP.md +9 -5
- package/docs/UPSTREAM-TERMINAL-TITLE.md +9 -8
- package/docs/VALUE.zh.md +5 -5
- package/docs/root-fs-routing.md +26 -19
- package/lib/agent-confined.d.ts +2 -2
- package/lib/agent-confined.js +0 -1
- package/lib/agent-exec.d.ts +2 -11
- package/lib/agent-protocol.d.ts +6 -5
- package/lib/agent.d.ts +5 -5
- package/lib/auto-preset.d.ts +4 -3
- package/lib/bwrap.d.ts +2 -1
- package/lib/client-host.d.ts +1 -1
- package/lib/client-host.js +1 -1
- package/lib/cwd-prompt-tool.d.ts +4 -20
- package/lib/cwd-prompt.d.ts +11 -10
- package/lib/distro-route.d.ts +3 -2
- package/lib/doctor-live.d.ts +2 -1
- package/lib/fs-routing.d.ts +29 -1
- package/lib/fs-routing.js +30 -3
- package/lib/fs-substrate.d.ts +0 -1
- package/lib/fs-substrate.js +0 -1
- package/lib/fsio-agent.d.ts +3 -21
- package/lib/fsio-agent.js +2 -4
- package/lib/git-exec.d.ts +3 -2
- package/lib/git-route.d.ts +4 -2
- package/lib/git-route.js +4 -2
- package/lib/index.d.ts +20 -10
- package/lib/index.js +128 -12
- package/lib/listing.d.ts +2 -1
- package/lib/messages.d.ts +82 -1
- package/lib/messages.js +94 -1
- package/lib/native-agent.d.ts +3 -2
- package/lib/paths.d.ts +2 -1
- package/lib/picker.d.ts +1 -14
- package/lib/picker.js +1 -2
- package/lib/preflight.d.ts +5 -4
- package/lib/probe-cache.d.ts +2 -1
- package/lib/sandbox-core.d.ts +2 -11
- package/lib/sandbox-core.js +1 -1
- package/lib/sandbox.d.ts +0 -1
- package/lib/sandbox.js +0 -4
- package/lib/search-exec.d.ts +2 -1
- package/lib/session-runtime.d.ts +3 -2
- package/lib/shell-env.d.ts +3 -2
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- package/lib/subprocess.d.ts +1 -1
- package/lib/update-check.d.ts +3 -3
- package/lib/wsl-doctor-command.d.ts +133 -0
- package/lib/wsl-doctor-command.js +381 -0
- package/lib/wsl-doctor-tool.d.ts +101 -16
- package/lib/wsl-doctor-tool.js +290 -22
- package/lib/wsl.d.ts +3 -2
- package/locale/doctor/en.json +30 -0
- package/locale/doctor/zh.json +30 -0
- package/package.json +29 -31
- package/scripts/bootstrap-import.sh +189 -0
- package/scripts/doctor.mjs +569 -141
- package/scripts/open-wsl-vscode.ps1 +36 -0
- package/examples/preset-wsl-session-sandbox.cordis.patch.yml +0 -178
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Import a distro from a rootfs tarball and configure it for this plugin, in
|
|
3
|
+
# one pass — the compatibility-matrix run's import traps, automated
|
|
4
|
+
# (WSL-310; the traps are documented in docs/COMPATIBILITY.md).
|
|
5
|
+
#
|
|
6
|
+
# scripts/bootstrap-import.sh <tarball> <distro-name> [--user <name>] [--dir <windows dir>]
|
|
7
|
+
#
|
|
8
|
+
# What it does, in order, printing every config write before it applies it:
|
|
9
|
+
#
|
|
10
|
+
# 1. detect the tarball's architecture from an ELF header (x86_64/aarch64);
|
|
11
|
+
# 2. `wsl --import` into %USERPROFILE%\wsl\<name> (or --dir);
|
|
12
|
+
# 3. unstick the first launch: a wedged OOBE is terminated and bypassed by
|
|
13
|
+
# starting as root (the Debian 13.5 wedge from the matrix run);
|
|
14
|
+
# 4. write /etc/wsl.conf: [boot] systemd=true for systemd families, and
|
|
15
|
+
# [user] default=<name> — an imported default-root distro makes the
|
|
16
|
+
# agent run as root, whose 0600 files no user can read (the substrate
|
|
17
|
+
# probe's four failures);
|
|
18
|
+
# 5. create the user when the tarball has none;
|
|
19
|
+
# 6. install bubblewrap through the distro's own package manager;
|
|
20
|
+
# 7. enable Linger (systemd families only — OpenRC distros run the
|
|
21
|
+
# non-systemd path and sessionSandbox reports the narrower scope);
|
|
22
|
+
# 8. hand the result to `doctor <name> --read-only` for the final pass —
|
|
23
|
+
# the bootstrap does not grade itself.
|
|
24
|
+
#
|
|
25
|
+
# The script is idempotent per distro name: an existing distro of the same
|
|
26
|
+
# name is reported and left alone (wsl --import would refuse anyway).
|
|
27
|
+
|
|
28
|
+
set -euo pipefail
|
|
29
|
+
|
|
30
|
+
TARBALL="${1:-}"
|
|
31
|
+
NAME="${2:-}"
|
|
32
|
+
USER_NAME=""
|
|
33
|
+
INSTALL_DIR=""
|
|
34
|
+
shift 2 2>/dev/null || true
|
|
35
|
+
while [ $# -gt 0 ]; do
|
|
36
|
+
case "$1" in
|
|
37
|
+
--user) USER_NAME="${2:-}"; shift 2 ;;
|
|
38
|
+
--dir) INSTALL_DIR="${2:-}"; shift 2 ;;
|
|
39
|
+
*) echo "bootstrap-import: unknown argument $1" >&2; exit 1 ;;
|
|
40
|
+
esac
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
[ -n "$TARBALL" ] && [ -f "$TARBALL" ] || { echo "bootstrap-import: usage: $0 <tarball> <distro-name> [--user <name>] [--dir <dir>]" >&2; exit 1; }
|
|
44
|
+
[ -n "$NAME" ] || { echo "bootstrap-import: a distro name is required" >&2; exit 1; }
|
|
45
|
+
case "$NAME" in *[!a-zA-Z0-9._-]*) echo "bootstrap-import: invalid distro name '$NAME'" >&2; exit 1 ;; esac
|
|
46
|
+
|
|
47
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
48
|
+
|
|
49
|
+
step() { printf '\n== %s ==\n' "$1"; }
|
|
50
|
+
|
|
51
|
+
# ---- 1. architecture --------------------------------------------------------
|
|
52
|
+
step "1. tarball architecture"
|
|
53
|
+
# Docker export tars list top-level "bin/…", distro rootfs tars list
|
|
54
|
+
# "./usr/bin/…" — and some candidates are directories whose extraction yields
|
|
55
|
+
# no bytes, so walk the list until one produces an ELF header.
|
|
56
|
+
FIRST_BIN=""
|
|
57
|
+
for candidate in $(tar ${TOPT:-} -tf "$TARBALL" | grep -E '^\.{0,2}/?(usr/)?bin/[^/]+$' | head -10); do
|
|
58
|
+
# dd exits after two bytes, which SIGPIPEs tar — pipefail would kill this
|
|
59
|
+
# script for the expected behaviour, so the pipeline is tolerated and only
|
|
60
|
+
# a non-empty header counts.
|
|
61
|
+
header="$( { tar ${TOPT:-} -xOf "$TARBALL" "$candidate" 2>/dev/null || true; } | { dd bs=1 skip=18 count=2 2>/dev/null || true; } | od -An -tx1 | tr -d ' \n' || true)"
|
|
62
|
+
if [ -n "$header" ]; then FIRST_BIN="$candidate"; break; fi
|
|
63
|
+
done
|
|
64
|
+
# docker export produces an uncompressed tar; the cloud/rootfs images ship
|
|
65
|
+
# .gz and .xz. The compression flag follows the filename.
|
|
66
|
+
case "$TARBALL" in
|
|
67
|
+
*.gz|*.tgz) TOPT="-z" ;;
|
|
68
|
+
*.xz) TOPT="-J" ;;
|
|
69
|
+
*.bz2) TOPT="-j" ;;
|
|
70
|
+
*) TOPT="" ;;
|
|
71
|
+
esac
|
|
72
|
+
MACHINE="$header"
|
|
73
|
+
# e_machine is little-endian at offset 0x12: bytes "3e 00" = x86_64,
|
|
74
|
+
# "b7 00" = aarch64.
|
|
75
|
+
case "$MACHINE" in
|
|
76
|
+
3e00) ARCH="x86_64" ;;
|
|
77
|
+
b700) ARCH="aarch64" ;;
|
|
78
|
+
*) echo "bootstrap-import: unknown ELF machine '$MACHINE' — cannot pick the agent architecture" >&2; exit 1 ;;
|
|
79
|
+
esac
|
|
80
|
+
echo "arch: $ARCH"
|
|
81
|
+
|
|
82
|
+
# ---- 2. import --------------------------------------------------------------
|
|
83
|
+
step "2. import"
|
|
84
|
+
if [ -z "$INSTALL_DIR" ]; then
|
|
85
|
+
USERPROFILE_WIN="$(cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d '\r\n')"
|
|
86
|
+
case "$USERPROFILE_WIN" in "%"*) echo "bootstrap-import: cannot read %USERPROFILE% through interop; pass --dir" >&2; exit 1 ;; esac
|
|
87
|
+
INSTALL_DIR="$(wslpath -u "$USERPROFILE_WIN")/wsl/$NAME"
|
|
88
|
+
INSTALL_DIR_WIN="$(wslpath -w "$INSTALL_DIR")"
|
|
89
|
+
else
|
|
90
|
+
INSTALL_DIR_WIN="$(wslpath -w "$INSTALL_DIR")"
|
|
91
|
+
fi
|
|
92
|
+
mkdir -p "$INSTALL_DIR"
|
|
93
|
+
if wsl.exe -l -q 2>/dev/null | tr -d '\r\0' | grep -qx "$NAME"; then
|
|
94
|
+
echo "$NAME already exists — skipping the import, continuing with configuration"
|
|
95
|
+
else
|
|
96
|
+
echo "import: $TARBALL -> $NAME (base $INSTALL_DIR_WIN)"
|
|
97
|
+
timeout 300 wsl.exe --import "$NAME" "$INSTALL_DIR_WIN" "$(wslpath -w "$TARBALL")" >/dev/null
|
|
98
|
+
echo "imported."
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
# ---- 3. unstick the first launch --------------------------------------------
|
|
102
|
+
step "3. first launch"
|
|
103
|
+
unstick() {
|
|
104
|
+
local n
|
|
105
|
+
for n in 1 2; do
|
|
106
|
+
if timeout 30 wsl.exe -d "$NAME" -u root -- /bin/true >/dev/null 2>&1; then
|
|
107
|
+
echo "first launch ok (as root)"
|
|
108
|
+
return 0
|
|
109
|
+
fi
|
|
110
|
+
echo "launch attempt $n wedged — terminating and retrying"
|
|
111
|
+
timeout 30 wsl.exe --terminate "$NAME" >/dev/null 2>&1 || true
|
|
112
|
+
sleep 2
|
|
113
|
+
done
|
|
114
|
+
return 1
|
|
115
|
+
}
|
|
116
|
+
unstick || { echo "bootstrap-import: the distro does not answer even as root — see docs/COMPATIBILITY.md's Debian OOBE note" >&2; exit 1; }
|
|
117
|
+
|
|
118
|
+
# ---- 4./5. family, user, wsl.conf --------------------------------------------
|
|
119
|
+
step "4. package family and user"
|
|
120
|
+
FAMILY="$(wsl.exe -d "$NAME" -u root --exec sh -c 'for f in apt-get dnf pacman zypper apk; do command -v "$f" >/dev/null 2>&1 && { echo "$f"; exit 0; }; done; echo unknown' | tr -d '\r\n')"
|
|
121
|
+
echo "family: $FAMILY"
|
|
122
|
+
[ "$FAMILY" != "unknown" ] || { echo "bootstrap-import: no known package manager — cannot install bubblewrap" >&2; exit 1; }
|
|
123
|
+
|
|
124
|
+
if [ -z "$USER_NAME" ]; then
|
|
125
|
+
USER_NAME="$(printf '%s' "$(cmd.exe /c "echo %USERNAME%" 2>/dev/null | tr -d '\r\n')" | tr 'A-Z' 'a-z' | tr -cd 'a-z0-9_-' | cut -c1-24)"
|
|
126
|
+
[ -n "$USER_NAME" ] || USER_NAME="dsh-user"
|
|
127
|
+
fi
|
|
128
|
+
if ! wsl.exe -d "$NAME" -u root -- id "$USER_NAME" >/dev/null 2>&1; then
|
|
129
|
+
echo "creating user: $USER_NAME"
|
|
130
|
+
case "$FAMILY" in
|
|
131
|
+
apk) wsl.exe -d "$NAME" -u root -- sh -c "apk add -q shadow >/dev/null 2>&1; adduser -D -s /bin/ash '$USER_NAME'" ;;
|
|
132
|
+
*) wsl.exe -d "$NAME" -u root -- useradd -m -s /bin/bash "$USER_NAME" ;;
|
|
133
|
+
esac
|
|
134
|
+
fi
|
|
135
|
+
|
|
136
|
+
echo "writing /etc/wsl.conf:"
|
|
137
|
+
SYSTEMD="no"
|
|
138
|
+
case "$FAMILY" in
|
|
139
|
+
apk) echo " (OpenRC — no [boot] systemd line; sessionSandbox reports the narrower scope per WSL-201)" ;;
|
|
140
|
+
*) SYSTEMD="yes"; echo " [boot] systemd=true" ;;
|
|
141
|
+
esac
|
|
142
|
+
echo " [user] default=$USER_NAME"
|
|
143
|
+
echo " -> /etc/wsl.conf"
|
|
144
|
+
case "$SYSTEMD" in
|
|
145
|
+
yes) wsl.exe -d "$NAME" -u root -- sh -c '{ echo "[boot]"; echo "systemd=true"; echo "[user]"; echo "default='"$USER_NAME"'"; } > /etc/wsl.conf' ;;
|
|
146
|
+
*) wsl.exe -d "$NAME" -u root -- sh -c '{ echo "[user]"; echo "default='"$USER_NAME"'"; } > /etc/wsl.conf' ;;
|
|
147
|
+
esac
|
|
148
|
+
wsl.exe -d "$NAME" -u root -- cat /etc/wsl.conf
|
|
149
|
+
timeout 30 wsl.exe --terminate "$NAME" >/dev/null 2>&1 || true
|
|
150
|
+
sleep 2
|
|
151
|
+
echo ""
|
|
152
|
+
echo "NOTE: [boot] systemd=true takes effect only after a full \"wsl.exe --shutdown\""
|
|
153
|
+
echo "(exit everything, run it, then reopen) — the distro terminate above is not enough."
|
|
154
|
+
|
|
155
|
+
# ---- 6. bubblewrap ------------------------------------------------------------
|
|
156
|
+
step "6. bubblewrap"
|
|
157
|
+
# systemd rides the install for the families that ship it: docker-export
|
|
158
|
+
# tarballs strip it, and a written [boot] systemd=true without the package is
|
|
159
|
+
# a boot that never starts.
|
|
160
|
+
case "$FAMILY" in
|
|
161
|
+
apt-get) INSTALL_CMD="apt-get update -qq && apt-get install -y -qq --no-install-recommends bubblewrap git ripgrep inotify-tools systemd systemd-sysv" ;;
|
|
162
|
+
dnf) INSTALL_CMD="dnf install -y -q bubblewrap git ripgrep inotify-tools systemd" ;;
|
|
163
|
+
pacman) INSTALL_CMD="pacman -Sy --noconfirm --needed bubblewrap git ripgrep inotify-tools systemd" ;;
|
|
164
|
+
zypper) INSTALL_CMD="zypper --non-interactive install bubblewrap git ripgrep inotify-tools systemd" ;;
|
|
165
|
+
apk) INSTALL_CMD="apk add -q bubblewrap git coreutils" ;;
|
|
166
|
+
esac
|
|
167
|
+
wsl.exe -d "$NAME" -u root -- sh -c "$INSTALL_CMD"
|
|
168
|
+
wsl.exe -d "$NAME" --exec bwrap --version >/dev/null 2>&1 && echo "bwrap ok"
|
|
169
|
+
|
|
170
|
+
# ---- 7. Linger ----------------------------------------------------------------
|
|
171
|
+
step "7. Linger"
|
|
172
|
+
if [ "$SYSTEMD" = "yes" ]; then
|
|
173
|
+
# root runs it: the user manager may be up while enable-linger still asks
|
|
174
|
+
# for the polkit privilege the fresh user does not have.
|
|
175
|
+
wsl.exe -d "$NAME" -u root -- loginctl enable-linger "$USER_NAME" 2>/dev/null \
|
|
176
|
+
&& echo "Linger enabled for $USER_NAME" \
|
|
177
|
+
|| echo "Linger could not be enabled — the session runtime will degrade; run inside the distro: loginctl enable-linger $USER_NAME (as root)"
|
|
178
|
+
else
|
|
179
|
+
echo "skipped (no systemd)"
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
# ---- 8. doctor pass ------------------------------------------------------------
|
|
183
|
+
step "8. doctor --read-only"
|
|
184
|
+
echo "cd $(pwd) && node scripts/doctor.mjs $NAME --read-only"
|
|
185
|
+
node "$HERE/doctor.mjs" "$NAME" --read-only || {
|
|
186
|
+
echo "bootstrap-import: doctor reported failures — fix them, or file them if they are fresh-distro traps this script should self-heal" >&2
|
|
187
|
+
exit 1
|
|
188
|
+
}
|
|
189
|
+
echo "bootstrap-import: $NAME ready"
|