@karoy/dsh-wsl-desktop 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * wsl-remote.cjs — bring up (or reuse) the DSH Host inside WSL and return its
3
+ * tokenized launch URL. Loaded from the patched Desktop shell via
4
+ * `createRequire`; runs synchronously on the Electron main thread.
5
+ *
6
+ * Environment: DSH_WSL_PORT (default 3080), DSH_WSL_DISTRO (default: WSL default
7
+ * distro), DSH_WSL_VERSION (default 0.2.2-rc.5), DSH_WSL_AUTOINSTALL (default 1).
8
+ */
9
+ const { execFileSync } = require('node:child_process')
10
+
11
+ const NODE_VERSION = 'v24.21.0'
12
+ const ALLOW_SCRIPTS = '@deepseek-ai/dsh-subprocess-local,koffi,node-pty,@google/genai,protobufjs'
13
+ const PORT = Number(process.env.DSH_WSL_PORT || 3080)
14
+ const DISTRO = (process.env.DSH_WSL_DISTRO || '').trim()
15
+ const VERSION = process.env.DSH_WSL_VERSION || '0.2.2-rc.5'
16
+ const AUTO_INSTALL = process.env.DSH_WSL_AUTOINSTALL !== '0'
17
+
18
+ const PREFACE = [
19
+ 'set -u',
20
+ 'if [ -x $HOME/.local/node/bin/node ]; then NODE=$HOME/.local/node/bin/node; elif command -v node >/dev/null 2>&1; then NODE=$(command -v node); fi',
21
+ 'DSH_JS=$HOME/.local/dsh/lib/node_modules/@deepseek-ai/dsh/lib/bin.js',
22
+ ].join('; ')
23
+
24
+ function wsl(script, timeoutMs) {
25
+ const args = DISTRO === '' ? ['--', 'bash', '-s'] : ['-d', DISTRO, '--', 'bash', '-s']
26
+ const output = execFileSync('wsl.exe', args, {
27
+ input: script,
28
+ encoding: 'utf8',
29
+ timeout: timeoutMs,
30
+ maxBuffer: 16 * 1024 * 1024,
31
+ windowsHide: true,
32
+ stdio: ['pipe', 'pipe', 'pipe'],
33
+ })
34
+ return String(output ?? '')
35
+ }
36
+
37
+ function ensureRuntime(preamble) {
38
+ const script = `${preamble}
39
+ need=0
40
+ if [ -z "$NODE" ] || ! "$NODE" -e 'process.exit(+process.versions.node.split(".")[0] >= 24 ? 0 : 1)' 2>/dev/null; then need=1; fi
41
+ if [ "$need" = 1 ]; then
42
+ if [ "${AUTO_INSTALL ? '1' : '0'}" != "1" ]; then echo WSL_DESKTOP_RUNTIME_MISSING; exit 3; fi
43
+ arch=$(uname -m)
44
+ case "$arch" in
45
+ x86_64|amd64) a=x64 ;;
46
+ aarch64|arm64) a=arm64 ;;
47
+ *) echo WSL_DESKTOP_ARCH_UNSUPPORTED; exit 3 ;;
48
+ esac
49
+ mkdir -p $HOME/.local/node /tmp/dsh-wsl-desktop
50
+ curl -fL --retry 3 https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-$a.tar.xz -o /tmp/dsh-wsl-desktop/node.tar.xz || exit 3
51
+ tar -xJf /tmp/dsh-wsl-desktop/node.tar.xz -C $HOME/.local/node --strip-components=1 || exit 3
52
+ NODE=$HOME/.local/node/bin/node
53
+ export PATH=$(dirname "$NODE"):$PATH
54
+ fi
55
+ if [ ! -f "$DSH_JS" ]; then
56
+ if [ "${AUTO_INSTALL ? '1' : '0'}" != "1" ]; then echo WSL_DESKTOP_DSH_MISSING; exit 3; fi
57
+ export PATH=$(dirname "$NODE"):$PATH
58
+ npm i -g --prefix $HOME/.local/dsh @deepseek-ai/dsh@${VERSION} --no-audit --no-fund --allow-scripts=${ALLOW_SCRIPTS} || exit 3
59
+ fi
60
+ echo WSL_DESKTOP_RUNTIME_READY
61
+ `
62
+ return wsl(script, 600000)
63
+ }
64
+
65
+ function startOrReuse(preamble) {
66
+ const script = `${preamble}
67
+ cd ~
68
+ PID=$HOME/dsh-wsl-host.pid
69
+ LOG=$HOME/dsh-wsl-host.log
70
+ port=${PORT}
71
+ if [ -f $PID ] && kill -0 "$(cat $PID)" 2>/dev/null; then
72
+ :
73
+ else
74
+ i=0
75
+ while [ "$i" -lt 20 ]; do
76
+ if ! ss -ltn 2>/dev/null | awk '{print $4}' | grep -q ":$port$"; then break; fi
77
+ port=$((port+1)); i=$((i+1))
78
+ done
79
+ setsid nohup "$NODE" "$DSH_JS" --profile web --no-open --port "$port" > "$LOG" 2>&1 < /dev/null &
80
+ echo $! > $PID
81
+ fi
82
+ for i in $(seq 1 60); do
83
+ grep -q '^dsh web:' "$LOG" 2>/dev/null && break
84
+ sleep 1
85
+ done
86
+ grep -m1 '^dsh web:' "$LOG" 2>/dev/null || true
87
+ `
88
+ return wsl(script, 120000)
89
+ }
90
+
91
+ /** @returns the WSL Host's tokenized URL, or null when unavailable. */
92
+ function remoteUrl() {
93
+ try {
94
+ ensureRuntime(PREFACE)
95
+ const out = startOrReuse(PREFACE)
96
+ const match = /dsh web:\s*(\S+)/.exec(out)
97
+ return match === null ? null : match[1]
98
+ } catch (error) {
99
+ throw new Error('wsl-desktop: failed to bring up the WSL Host: ' + (error instanceof Error ? error.message : String(error)))
100
+ }
101
+ }
102
+
103
+ module.exports = { remoteUrl }
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@karoy/dsh-wsl-desktop",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Install and launch a DSH Desktop copy whose Electron shell proxies its Host connection to a DSH Host running inside WSL",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "wsl",
10
+ "desktop",
11
+ "proxy",
12
+ "windows"
13
+ ],
14
+ "private": false,
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/lunnlew/dsh-wsl-desktop.git"
20
+ },
21
+ "homepage": "https://github.com/lunnlew/dsh-wsl-desktop#readme",
22
+ "bugs": {
23
+ "url": "https://github.com/lunnlew/dsh-wsl-desktop/issues"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "exports": {
29
+ ".": "./index.js",
30
+ "./client": "./client.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "index.js",
35
+ "client.js",
36
+ "cordis.patch.yml",
37
+ "lib",
38
+ "bin",
39
+ "README.md"
40
+ ],
41
+ "dsh": {
42
+ "bundle": {
43
+ "patch": "./cordis.patch.yml"
44
+ },
45
+ "client": {
46
+ "platform": "web",
47
+ "immediately": true,
48
+ "inject": []
49
+ }
50
+ },
51
+ "engines": {
52
+ "node": ">=22",
53
+ "dsh": ">=0.2.2-rc.5"
54
+ },
55
+ "scripts": {
56
+ "test": "node scripts/ci.mjs",
57
+ "ci": "node scripts/ci.mjs",
58
+ "prepack": "node scripts/ci.mjs"
59
+ },
60
+ "peerDependencies": {
61
+ "@deepseek-ai/cordis": "*"
62
+ }
6
63
  }