@xaidenlabs/uso 1.1.67 → 1.1.69

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.
@@ -49,4 +49,4 @@ const installLinux = async (shouldInstallRust, shouldInstallSolana) => {
49
49
  return true;
50
50
  };
51
51
 
52
- module.exports = { installLinux };
52
+ module.exports = { installLinux };
@@ -1,11 +1,45 @@
1
- const shell = require('shelljs');
2
- const { log, spinner } = require('../utils/logger');
3
- const { isWslInstalled, runWsl, toWslPath } = require('../utils/wsl-bridge');
4
- const path = require('path');
5
- const fs = require('fs');
6
- const os = require('os');
7
- const { spawnSync } = require('child_process');
8
- const chalk = require('chalk');
1
+ const shell = require("shelljs");
2
+ const { log, spinner } = require("../utils/logger");
3
+ const { isWslInstalled, runWsl, toWslPath } = require("../utils/wsl-bridge");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const os = require("os");
7
+ const { spawnSync } = require("child_process");
8
+ const chalk = require("chalk");
9
+ const WSL_DISTRO = "Ubuntu";
10
+
11
+ const progressHelpers = `
12
+ print_progress() {
13
+ local label="$1"
14
+ local percent="$2"
15
+ printf "\r%s %d%%" "$label" "$percent"
16
+ }
17
+
18
+ run_with_progress() {
19
+ local label="$1"
20
+ local start="$2"
21
+ local end="$3"
22
+ shift 3
23
+
24
+ "$@" &
25
+ local pid=$!
26
+ local current="$start"
27
+
28
+ while kill -0 "$pid" 2>/dev/null; do
29
+ print_progress "$label" "$current"
30
+ if [ "$current" -lt "$((end - 1))" ]; then
31
+ current=$((current + 1))
32
+ fi
33
+ sleep 2
34
+ done
35
+
36
+ wait "$pid"
37
+ local status=$?
38
+ print_progress "$label" "$end"
39
+ printf "\n"
40
+ return "$status"
41
+ }
42
+ `.replace(/\r\n/g, "\n");
9
43
 
10
44
  /**
11
45
  * Installs the WSL Windows Feature via an elevated PowerShell UAC prompt.
@@ -13,158 +47,233 @@ const chalk = require('chalk');
13
47
  * Returns true if WSL is now available after the attempt, false otherwise.
14
48
  */
15
49
  const installWslFeature = async () => {
16
- log.warn("⚠️ WSL (Windows Subsystem for Linux) is not installed on this machine.");
17
- log.info("🛡️ Administrator permission is required to install WSL.");
18
- log.info("👉 A UAC (User Account Control) popup will appear — please click 'Yes' to allow the installation.");
19
- console.log("");
20
-
21
- // Run `wsl --install --no-distribution` elevated.
22
- // --no-distribution: only enables the WSL feature, does not pull a distro yet.
23
- // We wait for it to finish (-Wait) so we can check the result.
24
- const elevateCmd = `powershell -Command "Start-Process -FilePath 'wsl.exe' -ArgumentList '--install', '--no-distribution' -Verb RunAs -Wait"`;
25
- const result = shell.exec(elevateCmd, { silent: false });
26
-
27
- if (result.code !== 0) {
28
- // User likely denied UAC or the command failed
29
- log.error("❌ WSL installation was cancelled or failed.");
30
- log.warn("👉 To install manually, open PowerShell as Administrator and run:");
31
- console.log(chalk.bold.yellow(" wsl --install"));
32
- return false;
33
- }
34
-
35
- // Verify wsl is now available
36
- const check = shell.exec('wsl --status', { silent: true });
37
- if (check.code !== 0) {
38
- // WSL was just installed — a reboot is almost certainly required
39
- log.warn("⚠️ WSL feature has been installed, but a system restart is required to complete setup.");
40
- log.warn("👉 Please RESTART your computer, then run `uso install` again to set up the toolchain.");
41
- return false; // Signal caller that we need a restart before proceeding
42
- }
43
-
44
- log.success("✅ WSL feature installed successfully.");
45
- return true;
50
+ log.warn(
51
+ "⚠️ WSL (Windows Subsystem for Linux) is not installed on this machine.",
52
+ );
53
+ log.info("🛡️ Administrator permission is required to install WSL.");
54
+ log.info(
55
+ "👉 A UAC (User Account Control) popup will appear — please click 'Yes' to allow the installation.",
56
+ );
57
+ console.log("");
58
+
59
+ // Run `wsl --install --no-distribution` elevated.
60
+ // --no-distribution: only enables the WSL feature, does not pull a distro yet.
61
+ // We wait for it to finish (-Wait) so we can check the result.
62
+ const elevateCmd = `powershell -Command "Start-Process -FilePath 'wsl.exe' -ArgumentList '--install', '--no-distribution' -Verb RunAs -Wait"`;
63
+ const result = shell.exec(elevateCmd, { silent: false });
64
+
65
+ if (result.code !== 0) {
66
+ // User likely denied UAC or the command failed
67
+ log.error("❌ WSL installation was cancelled or failed.");
68
+ log.warn(
69
+ "👉 To install manually, open PowerShell as Administrator and run:",
70
+ );
71
+ console.log(chalk.bold.yellow(" wsl --install"));
72
+ return false;
73
+ }
74
+
75
+ // Verify wsl is now available
76
+ const check = shell.exec("wsl --status", { silent: true });
77
+ if (check.code !== 0) {
78
+ // WSL was just installed — a reboot is almost certainly required
79
+ log.warn(
80
+ "⚠️ WSL feature has been installed, but a system restart is required to complete setup.",
81
+ );
82
+ log.warn(
83
+ "👉 Please RESTART your computer, then run `uso install` again to set up the toolchain.",
84
+ );
85
+ return false; // Signal caller that we need a restart before proceeding
86
+ }
87
+
88
+ log.success("✅ WSL feature installed successfully.");
89
+ return true;
46
90
  };
47
91
 
48
92
  const installWsl = async () => {
49
- log.header("🐧 Configuring Stealth WSL Environment...");
50
-
51
- // 1. Check if WSL is enabled
52
- if (!shell.which('wsl')) {
53
- log.error("❌ WSL is not enabled on this Windows machine.");
54
- log.warn("👉 Please enable 'Windows Subsystem for Linux' in 'Turn Windows features on or off'.");
55
- log.warn("👉 Or run this in PowerShell as Admin: wsl --install");
56
- return false;
93
+ log.header("🐧 Configuring Stealth WSL Environment...");
94
+
95
+ // 1. Check if WSL is enabled
96
+ if (!shell.which("wsl")) {
97
+ log.error("❌ WSL is not enabled on this Windows machine.");
98
+ log.warn(
99
+ "👉 Please enable 'Windows Subsystem for Linux' in 'Turn Windows features on or off'.",
100
+ );
101
+ log.warn("👉 Or run this in PowerShell as Admin: wsl --install");
102
+ return false;
103
+ }
104
+
105
+ // 2. Install Ubuntu silently (Branded as Uso Engine)
106
+ // We use 'wsl -d Ubuntu -e true' to check if it's installed and runnable.
107
+ // 'wsl -l -v' output is notoriously unreliable due to charset encoding (UTF-16) on Windows.
108
+ const checkDistro = shell.exec(`wsl -d ${WSL_DISTRO} -e true`, {
109
+ silent: true,
110
+ });
111
+
112
+ // If exit code is 0, it's installed and working.
113
+ if (checkDistro.code !== 0) {
114
+ log.info(
115
+ "📦 Configuring Uso Engine (Please approve UAC prompt if asked)...",
116
+ );
117
+ log.warn("⏳ This may take a few minutes (Downloading ~500MB)...");
118
+
119
+ // Helper to try install commands
120
+ const tryInstall = (args, description) => {
121
+ log.info(`👉 Attempting: ${description}...`);
122
+ // Fix Deprecation: shell: false is safer and prevents warning
123
+ const proc = spawnSync("wsl", args, { stdio: "inherit", shell: false });
124
+ return proc.status === 0;
125
+ };
126
+
127
+ // Attempt 1: Standard Install
128
+ let success = tryInstall(
129
+ ["--install", "-d", WSL_DISTRO],
130
+ "Standard Install",
131
+ );
132
+
133
+ // Attempt 2: Update WSL Kernel (Fixes network/protocol issues)
134
+ if (!success) {
135
+ log.warn(
136
+ "⚠️ Standard install failed. Attempting to update WSL kernel...",
137
+ );
138
+ spawnSync("wsl", ["--update"], { stdio: "inherit", shell: false });
139
+ success = tryInstall(
140
+ ["--install", "-d", WSL_DISTRO],
141
+ "Install after Update",
142
+ );
57
143
  }
58
144
 
59
- // 2. Install Ubuntu silently (Branded as Uso Engine)
60
- // We use 'wsl -d Ubuntu -e true' to check if it's installed and runnable.
61
- // 'wsl -l -v' output is notoriously unreliable due to charset encoding (UTF-16) on Windows.
62
- const checkDistro = shell.exec('wsl -d Ubuntu -e true', { silent: true });
63
-
64
- // If exit code is 0, it's installed and working.
65
- if (checkDistro.code !== 0) {
66
- log.info("📦 Configuring Uso Engine (Please approve UAC prompt if asked)...");
67
- log.warn("⏳ This may take a few minutes (Downloading ~500MB)...");
68
-
69
- // Helper to try install commands
70
- const tryInstall = (args, description) => {
71
- log.info(`👉 Attempting: ${description}...`);
72
- // Fix Deprecation: shell: false is safer and prevents warning
73
- const proc = spawnSync('wsl', args, { stdio: 'inherit', shell: false });
74
- return proc.status === 0;
75
- };
76
-
77
- // Attempt 1: Standard Install
78
- let success = tryInstall(['--install', '-d', 'Ubuntu'], 'Standard Install');
79
-
80
- // Attempt 2: Update WSL Kernel (Fixes network/protocol issues)
81
- if (!success) {
82
- log.warn("⚠️ Standard install failed. Attempting to update WSL kernel...");
83
- spawnSync('wsl', ['--update'], { stdio: 'inherit', shell: false });
84
- success = tryInstall(['--install', '-d', 'Ubuntu'], 'Install after Update');
85
- }
145
+ // Attempt 3: Web Download (Bypasses Microsoft Store blocks)
146
+ if (!success) {
147
+ log.warn("⚠️ Still failing. Trying --web-download (Bypasses Store)...");
148
+ success = tryInstall(
149
+ ["--install", "-d", WSL_DISTRO, "--web-download"],
150
+ "Web Download Install",
151
+ );
152
+ }
86
153
 
87
- // Attempt 3: Web Download (Bypasses Microsoft Store blocks)
88
- if (!success) {
89
- log.warn("⚠️ Still failing. Trying --web-download (Bypasses Store)...");
90
- success = tryInstall(['--install', '-d', 'Ubuntu', '--web-download'], 'Web Download Install');
91
- }
154
+ // Final Failure Handler
155
+ if (!success) {
156
+ log.error(" Failed to configure Uso Engine.");
157
+ log.error("🛑 Possible Causes: Internet Timeout, Firewall, or VPN.");
158
+ log.warn(
159
+ "\n👉 ACTION REQUIRED: Run this command manually in PowerShell as Administrator:",
160
+ );
161
+ console.log(
162
+ chalk.bold.yellow(` wsl --install -d ${WSL_DISTRO} --web-download`),
163
+ );
164
+ log.warn(
165
+ "\nOnce that completes successfully, run 'uso setup --wsl' again.",
166
+ );
167
+ return false;
168
+ }
92
169
 
93
- // Final Failure Handler
94
- if (!success) {
95
- log.error("❌ Failed to configure Uso Engine.");
96
- log.error("🛑 Possible Causes: Internet Timeout, Firewall, or VPN.");
97
- log.warn("\n👉 ACTION REQUIRED: Run this command manually in PowerShell as Administrator:");
98
- console.log(chalk.bold.yellow(" wsl --install -d Ubuntu --web-download"));
99
- log.warn("\nOnce that completes successfully, run 'uso setup --wsl' again.");
100
- return false;
101
- }
102
- log.success("✅ Uso Engine configured.");
103
- } else {
104
- log.success("✅ Uso Engine is ready.");
170
+ const verifyInstall = shell.exec(`wsl -d ${WSL_DISTRO} -e true`, {
171
+ silent: true,
172
+ });
173
+ if (verifyInstall.code !== 0) {
174
+ log.warn(
175
+ `⚠️ ${WSL_DISTRO} is not ready yet. WSL installation usually needs a full system reboot before the distro becomes available.`,
176
+ );
177
+ log.warn(
178
+ "👉 Restart Windows, then run 'uso install' again to continue the setup.",
179
+ );
180
+ return false;
105
181
  }
106
182
 
107
- // 2.5 Hide from Windows Terminal (Stealth Mode)
108
- hideFromWindowsTerminal();
183
+ log.success("✅ Uso Engine configured.");
184
+ } else {
185
+ log.success("✅ Uso Engine is ready.");
186
+ }
187
+
188
+ // 2.5 Hide from Windows Terminal (Stealth Mode)
189
+ hideFromWindowsTerminal();
109
190
 
110
- // 3. Configure Internal Environment (Rust + Solana + Anchor)
111
- // We create a shell script and run it inside WSL.
191
+ // 3. Configure Internal Environment (Rust + Solana + Anchor)
192
+ // We create a shell script and run it inside WSL.
112
193
 
113
- log.info("⚙️ Initializing Uso Engine environment...");
194
+ log.info("⚙️ Initializing Uso Engine environment...");
114
195
 
115
- // --- PHASE 1: System Dependencies (as root, no sudo needed) ---
116
- const rootScript = `
196
+ // --- PHASE 1: System Dependencies (as root, no sudo needed) ---
197
+ const rootScript = `
117
198
  #!/bin/bash
118
199
  set -e
119
200
  export DEBIAN_FRONTEND=noninteractive
120
201
 
202
+ ${progressHelpers}
203
+
121
204
  if ! command -v cc &> /dev/null || ! command -v pkg-config &> /dev/null; then
122
- echo "📦 Installing system build tools..."
123
- apt-get update -y -qq
124
- apt-get install -y -qq curl build-essential pkg-config libssl-dev libudev-dev
205
+ run_with_progress "📦 Installing system build tools..." 0 100 bash -lc "apt-get update -y -qq && apt-get install -y -qq curl build-essential pkg-config libssl-dev libudev-dev"
125
206
  echo "✅ Build tools installed."
126
207
  else
127
208
  echo "✅ Build tools already present."
128
209
  fi
129
- `.replace(/\r\n/g, '\n');
130
-
131
- const rootScriptPath = path.join(process.cwd(), 'uso_root_setup.sh');
132
- fs.writeFileSync(rootScriptPath, rootScript);
133
- const wslRootScriptPath = toWslPath(rootScriptPath);
134
-
135
- const spin1 = spinner('Phase 1/2: Installing system dependencies...').start();
136
- const rootRes = shell.exec(`wsl -d Ubuntu -u root -e bash "${wslRootScriptPath}"`);
137
- fs.unlinkSync(rootScriptPath);
138
-
139
- if (rootRes.code !== 0) {
140
- spin1.fail('System dependency installation failed.');
141
- log.error(rootRes.stderr || 'Unknown error during root setup.');
142
- return false;
143
- }
144
- spin1.succeed('System dependencies ready.');
145
-
146
- // --- PHASE 2: User Tools (Rust, Solana, Anchor as normal user) ---
147
- const userScript = `
210
+ `.replace(/\r\n/g, "\n");
211
+
212
+ const rootScriptPath = path.join(process.cwd(), "uso_root_setup.sh");
213
+ fs.writeFileSync(rootScriptPath, rootScript);
214
+ const wslRootScriptPath = toWslPath(rootScriptPath);
215
+
216
+ const spin1 = spinner("Phase 1/2: Installing system dependencies...").start();
217
+ const rootRes = shell.exec(
218
+ `wsl -d ${WSL_DISTRO} -u root -e bash "${wslRootScriptPath}"`,
219
+ );
220
+ fs.unlinkSync(rootScriptPath);
221
+
222
+ if (rootRes.code !== 0) {
223
+ spin1.fail("System dependency installation failed.");
224
+ log.error(rootRes.stderr || "Unknown error during root setup.");
225
+ return false;
226
+ }
227
+ spin1.succeed("System dependencies ready.");
228
+
229
+ // --- PHASE 2: User Tools (Rust, Solana, Anchor as normal user) ---
230
+ const userScript = `
148
231
  #!/bin/bash
149
232
  # NO set -e — we handle errors per-step
150
233
  FAILURES=""
151
234
 
235
+ ${progressHelpers}
236
+
152
237
  # Hush login
153
238
  touch ~/.hushlogin
154
239
 
155
240
  # --- Rust ---
156
241
  source $HOME/.cargo/env 2>/dev/null || true
157
- if ! command -v cargo &> /dev/null; then
158
- echo "🦀 Installing Rust..."
159
- if curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; then
242
+
243
+ # rustc can exist but still fail if component/toolchain is broken.
244
+ if command -v rustc &> /dev/null && rustc --version >/dev/null 2>&1; then
245
+ echo "✅ Rust already installed."
246
+ else
247
+ # If rustup exists, try repairing first.
248
+ if command -v rustup &> /dev/null; then
249
+ echo "🦀 Repairing Rust toolchain..."
250
+ rustup toolchain install stable >/dev/null 2>&1 || true
251
+ rustup default stable >/dev/null 2>&1 || true
252
+ rustup component add rustc cargo >/dev/null 2>&1 || true
160
253
  source $HOME/.cargo/env 2>/dev/null || true
161
- echo "✅ Rust installed."
254
+ fi
255
+
256
+ if command -v rustc &> /dev/null && rustc --version >/dev/null 2>&1; then
257
+ echo "✅ Rust repaired."
162
258
  else
163
- FAILURES="$FAILURES rust"
164
- echo " Rust installation failed."
259
+ echo "🦀 Installing Rust..."
260
+ if run_with_progress "🦀 Installing Rust..." 10 35 bash -lc "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"; then
261
+ source $HOME/.cargo/env 2>/dev/null || true
262
+ rustup toolchain install stable >/dev/null 2>&1 || true
263
+ rustup default stable >/dev/null 2>&1 || true
264
+ rustup component add rustc cargo >/dev/null 2>&1 || true
265
+
266
+ if command -v rustc &> /dev/null && rustc --version >/dev/null 2>&1; then
267
+ echo "✅ Rust installed."
268
+ else
269
+ FAILURES="$FAILURES rust"
270
+ echo "❌ Rust install completed but rustc is not runnable."
271
+ fi
272
+ else
273
+ FAILURES="$FAILURES rust"
274
+ echo "❌ Rust installation failed."
275
+ fi
165
276
  fi
166
- else
167
- echo "✅ Rust already installed."
168
277
  fi
169
278
  source $HOME/.cargo/env 2>/dev/null || true
170
279
 
@@ -172,9 +281,9 @@ source $HOME/.cargo/env 2>/dev/null || true
172
281
  export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
173
282
  if ! command -v solana &> /dev/null; then
174
283
  echo "☀️ Installing Solana CLI..."
175
- if sh -c "$(curl -sSfL https://release.solana.com/stable/install)" 2>/dev/null; then
284
+ if run_with_progress "☀️ Installing Solana CLI..." 35 60 bash -lc 'sh -c "$(curl -sSfL https://release.solana.com/stable/install)"'; then
176
285
  echo "✅ Solana installed."
177
- elif sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)" 2>/dev/null; then
286
+ elif run_with_progress "☀️ Installing Solana CLI..." 35 60 bash -lc 'sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"'; then
178
287
  echo "✅ Solana installed (via Agave)."
179
288
  else
180
289
  FAILURES="$FAILURES solana"
@@ -190,7 +299,7 @@ if ! command -v anchor &> /dev/null; then
190
299
  # Install AVM if not present
191
300
  if ! command -v avm &> /dev/null; then
192
301
  echo "⚓ Installing AVM (compiling from source, ~5 min)..."
193
- if cargo install --git https://github.com/coral-xyz/anchor avm --locked --force; then
302
+ if run_with_progress "⚓ Installing AVM (compiling from source)..." 60 85 cargo install --git https://github.com/coral-xyz/anchor avm --locked --force; then
194
303
  echo "✅ AVM compiled."
195
304
  else
196
305
  FAILURES="$FAILURES avm"
@@ -203,12 +312,12 @@ if ! command -v anchor &> /dev/null; then
203
312
  # Install Anchor via AVM (try binary first, then compile from source)
204
313
  if command -v avm &> /dev/null; then
205
314
  echo "⚓ Installing Anchor CLI..."
206
- if avm install latest 2>/dev/null; then
315
+ if run_with_progress "⚓ Installing Anchor CLI..." 85 100 avm install latest; then
207
316
  avm use latest
208
317
  echo "✅ Anchor installed."
209
318
  else
210
319
  echo "⚠️ Binary download timed out. Building from source (this takes ~10 min)..."
211
- if avm install latest --force 2>/dev/null; then
320
+ if run_with_progress "⚓ Building Anchor CLI from source..." 85 100 avm install latest --force; then
212
321
  avm use latest
213
322
  echo "✅ Anchor built from source."
214
323
  else
@@ -231,83 +340,100 @@ else
231
340
  echo "Run 'uso setup' again to retry failed components."
232
341
  exit 1
233
342
  fi
234
- `.replace(/\r\n/g, '\n');
235
-
236
- const userScriptPath = path.join(process.cwd(), 'uso_user_setup.sh');
237
- fs.writeFileSync(userScriptPath, userScript);
238
- const wslUserScriptPath = toWslPath(userScriptPath);
239
-
240
- const spin2 = spinner('Phase 2/2: Installing Rust, Solana, Anchor (this takes a while)...').start();
241
- const userRes = shell.exec(`wsl -d Ubuntu -e bash "${wslUserScriptPath}"`);
242
- fs.unlinkSync(userScriptPath);
243
-
244
- if (userRes.code === 0) {
245
- spin2.succeed('Uso Engine configured successfully.');
246
- } else {
247
- spin2.warn('Uso Engine partially configured (some downloads timed out).');
248
- log.info("👉 Run 'uso setup' again to retry failed components.");
249
- }
250
-
251
- // Always set stealth mode config even partial setup enables routing
252
- const configPath = path.join(os.homedir(), '.uso-config.json');
253
- const config = { mode: 'wsl', distro: 'Ubuntu' };
254
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
255
-
256
- log.success("✅ Stealth Mode Enabled. 'uso' commands will now run via WSL.");
257
- return true;
343
+ `.replace(/\r\n/g, "\n");
344
+
345
+ const userScriptPath = path.join(process.cwd(), "uso_user_setup.sh");
346
+ fs.writeFileSync(userScriptPath, userScript);
347
+ const wslUserScriptPath = toWslPath(userScriptPath);
348
+
349
+ const spin2 = spinner(
350
+ "Phase 2/2: Installing Rust, Solana, Anchor (this takes a while)...",
351
+ ).start();
352
+ const userRes = shell.exec(
353
+ `wsl -d ${WSL_DISTRO} -e bash "${wslUserScriptPath}"`,
354
+ );
355
+ fs.unlinkSync(userScriptPath);
356
+
357
+ if (userRes.code === 0) {
358
+ spin2.succeed("Uso Engine configured successfully.");
359
+ } else {
360
+ spin2.warn("Uso Engine partially configured (some downloads timed out).");
361
+ log.info("👉 Run 'uso setup' again to retry failed components.");
362
+ }
363
+
364
+ // Always set stealth mode config — even partial setup enables routing
365
+ const configPath = path.join(os.homedir(), ".uso-config.json");
366
+ const config = { mode: "wsl", distro: WSL_DISTRO };
367
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
368
+
369
+ log.success("✅ Stealth Mode Enabled. 'uso' commands will now run via WSL.");
370
+ return true;
258
371
  };
259
372
 
260
373
  const hideFromWindowsTerminal = () => {
261
- try {
262
- const localAppData = process.env.LOCALAPPDATA;
263
- const packagesPath = path.join(localAppData, 'Packages');
264
-
265
- // Find Windows Terminal package folder (name varies slightly but starts with Microsoft.WindowsTerminal)
266
- if (!fs.existsSync(packagesPath)) return;
267
-
268
- const terminalDirs = fs.readdirSync(packagesPath).filter(name => name.startsWith('Microsoft.WindowsTerminal'));
269
-
270
- if (terminalDirs.length === 0) return;
271
-
272
- const settingsPath = path.join(packagesPath, terminalDirs[0], 'LocalState', 'settings.json');
273
-
274
- if (fs.existsSync(settingsPath)) {
275
- // Read settings
276
- // Note: settings.json can contain comments which JSON.parse fails on.
277
- // We'll use a simple regex to set hidden: true for Ubuntu if simpler parsing fails or just try.
278
- // Actually, modifying this file safely without a robust comment-stripping parser is risky.
279
- // A safer approach for "Stealth" might be just log that we configured it.
280
- // BUT, if we want to do it, we should be careful.
281
-
282
- // For now, let's just log a message that we would hide it,
283
- // or maybe we skip the robust parsing complexity to avoid breaking their terminal settings.
284
- // User requested "Programmatically edit".
285
-
286
- const content = fs.readFileSync(settingsPath, 'utf8');
287
- // Check if Ubuntu is already there
288
- if (content.includes('"name": "Ubuntu"')) {
289
- // Very naive replacement to inject hidden: true.
290
- // We look for the Ubuntu profile block.
291
- // This is brittle. Let's try to parse if valid JSON.
292
- try {
293
- const settings = JSON.parse(content);
294
- if (settings.profiles && settings.profiles.list) {
295
- const profile = settings.profiles.list.find(p => p.name === 'Ubuntu');
296
- if (profile) {
297
- profile.hidden = true;
298
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4));
299
- log.info("🕵️ Hid 'Ubuntu' from Windows Terminal (Stealth Mode Active).");
300
- }
301
- }
302
- } catch (e) {
303
- // JSON parse failed (likely due to comments in settings.json)
304
- log.warn("⚠️ Could not automatically hide Ubuntu icon (Comments in settings.json).");
305
- }
374
+ try {
375
+ const localAppData = process.env.LOCALAPPDATA;
376
+ const packagesPath = path.join(localAppData, "Packages");
377
+
378
+ // Find Windows Terminal package folder (name varies slightly but starts with Microsoft.WindowsTerminal)
379
+ if (!fs.existsSync(packagesPath)) return;
380
+
381
+ const terminalDirs = fs
382
+ .readdirSync(packagesPath)
383
+ .filter((name) => name.startsWith("Microsoft.WindowsTerminal"));
384
+
385
+ if (terminalDirs.length === 0) return;
386
+
387
+ const settingsPath = path.join(
388
+ packagesPath,
389
+ terminalDirs[0],
390
+ "LocalState",
391
+ "settings.json",
392
+ );
393
+
394
+ if (fs.existsSync(settingsPath)) {
395
+ // Read settings
396
+ // Note: settings.json can contain comments which JSON.parse fails on.
397
+ // We'll use a simple regex to set hidden: true for Ubuntu if simpler parsing fails or just try.
398
+ // Actually, modifying this file safely without a robust comment-stripping parser is risky.
399
+ // A safer approach for "Stealth" might be just log that we configured it.
400
+ // BUT, if we want to do it, we should be careful.
401
+
402
+ // For now, let's just log a message that we would hide it,
403
+ // or maybe we skip the robust parsing complexity to avoid breaking their terminal settings.
404
+ // User requested "Programmatically edit".
405
+
406
+ const content = fs.readFileSync(settingsPath, "utf8");
407
+ // Check if Ubuntu is already there
408
+ if (content.includes('"name": "Ubuntu"')) {
409
+ // Very naive replacement to inject hidden: true.
410
+ // We look for the Ubuntu profile block.
411
+ // This is brittle. Let's try to parse if valid JSON.
412
+ try {
413
+ const settings = JSON.parse(content);
414
+ if (settings.profiles && settings.profiles.list) {
415
+ const profile = settings.profiles.list.find(
416
+ (p) => p.name === "Ubuntu",
417
+ );
418
+ if (profile) {
419
+ profile.hidden = true;
420
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4));
421
+ log.info(
422
+ "🕵️ Hid 'Ubuntu' from Windows Terminal (Stealth Mode Active).",
423
+ );
306
424
  }
425
+ }
426
+ } catch (e) {
427
+ // JSON parse failed (likely due to comments in settings.json)
428
+ log.warn(
429
+ "⚠️ Could not automatically hide Ubuntu icon (Comments in settings.json).",
430
+ );
307
431
  }
308
- } catch (e) {
309
- // Silently fail to avoid alarming user
432
+ }
310
433
  }
434
+ } catch (e) {
435
+ // Silently fail to avoid alarming user
436
+ }
311
437
  };
312
438
 
313
439
  module.exports = { installWslFeature, installWsl };