@xaidenlabs/uso 1.1.12 → 1.1.15
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/package.json +1 -1
- package/src/commands/workflow.js +55 -16
package/package.json
CHANGED
package/src/commands/workflow.js
CHANGED
|
@@ -55,20 +55,26 @@ const runProxyCommand = async (command, args = []) => {
|
|
|
55
55
|
* We rely on the user to see the output in the new window.
|
|
56
56
|
*/
|
|
57
57
|
const runElevatedWithProgress = (command, args = []) => {
|
|
58
|
-
return new Promise((resolve) => {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
59
|
const cwd = process.cwd().replace(/\\/g, '\\\\');
|
|
60
60
|
const cargoBin = path.join(os.homedir(), '.cargo', 'bin').replace(/\\/g, '\\\\');
|
|
61
|
+
const progressFile = path.join(process.cwd(), 'uso-elevation.log');
|
|
62
|
+
const progressFileEscaped = progressFile.replace(/\\/g, '\\\\');
|
|
63
|
+
|
|
64
|
+
// 1. Prepare progress file
|
|
65
|
+
try { fs.writeFileSync(progressFile, ''); } catch (e) { }
|
|
61
66
|
|
|
62
67
|
log.info("🚀 Spawning visible Administrator terminal...");
|
|
63
|
-
log.warn("👉
|
|
68
|
+
log.warn("👉 Output will be mirrored below. Keep the new window open!");
|
|
64
69
|
|
|
65
|
-
// Construct
|
|
66
|
-
// We keep the window open (-NoExit) so the user can read the error if it fails
|
|
67
|
-
// But we added ReadKey to allow clean exit on success
|
|
70
|
+
// 2. Construct Elevated Command
|
|
68
71
|
const innerCmd = `
|
|
72
|
+
$ErrorActionPreference = "Stop";
|
|
73
|
+
Start-Transcript -Path "${progressFileEscaped}" -Append -Force | Out-Null;
|
|
74
|
+
|
|
69
75
|
$env:PATH = "${cargoBin};" + [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User");
|
|
70
76
|
|
|
71
|
-
#
|
|
77
|
+
# Exclusions for Speed/Stability
|
|
72
78
|
Add-MpPreference -ExclusionProcess "cargo.exe" -ErrorAction SilentlyContinue;
|
|
73
79
|
Add-MpPreference -ExclusionProcess "rustc.exe" -ErrorAction SilentlyContinue;
|
|
74
80
|
Add-MpPreference -ExclusionProcess "anchor.exe" -ErrorAction SilentlyContinue;
|
|
@@ -76,33 +82,66 @@ const runElevatedWithProgress = (command, args = []) => {
|
|
|
76
82
|
Add-MpPreference -ExclusionProcess "node.exe" -ErrorAction SilentlyContinue;
|
|
77
83
|
|
|
78
84
|
Set-Location "${cwd}";
|
|
85
|
+
|
|
79
86
|
Write-Host "🔒 Running 'anchor ${command}' with Elevated Privileges..." -ForegroundColor Cyan;
|
|
87
|
+
|
|
80
88
|
try {
|
|
89
|
+
# Run command and let Transcript capture output
|
|
81
90
|
& anchor ${command} ${args.join(' ')};
|
|
91
|
+
|
|
82
92
|
if ($LASTEXITCODE -eq 0) {
|
|
83
|
-
|
|
93
|
+
Write-Host "✅ Success!" -ForegroundColor Green;
|
|
94
|
+
Write-Host "USO_AC_SUCCESS" -ForegroundColor Black; # Signal to Node
|
|
84
95
|
} else {
|
|
85
|
-
|
|
96
|
+
Write-Host "❌ Failed via elevated process." -ForegroundColor Red;
|
|
97
|
+
Write-Host "USO_AC_FAILURE" -ForegroundColor Black; # Signal to Node
|
|
86
98
|
}
|
|
87
99
|
} catch {
|
|
88
100
|
Write-Host "Error: $_" -ForegroundColor Red;
|
|
101
|
+
Write-Host "USO_AC_FAILURE" -ForegroundColor Black;
|
|
89
102
|
}
|
|
103
|
+
|
|
104
|
+
Stop-Transcript | Out-Null;
|
|
90
105
|
Write-Host "Press any key to close..." -ForegroundColor Gray;
|
|
91
106
|
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");
|
|
92
107
|
`.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
|
|
93
108
|
|
|
94
|
-
//
|
|
109
|
+
// 3. Spawn Window (-NoExit to prevent immediate close on crash)
|
|
95
110
|
const innerCmdBytes = Buffer.from(innerCmd, 'utf16le');
|
|
96
111
|
const innerCmdBase64 = innerCmdBytes.toString('base64');
|
|
97
|
-
|
|
98
|
-
// Spawn visible output window using EncodedCommand
|
|
99
|
-
const psCmd = `powershell -Command "Start-Process powershell -ArgumentList '-EncodedCommand', '${innerCmdBase64}' -Verb RunAs"`;
|
|
100
|
-
|
|
112
|
+
const psCmd = `powershell -Command "Start-Process powershell -ArgumentList '-NoExit', '-EncodedCommand', '${innerCmdBase64}' -Verb RunAs"`;
|
|
101
113
|
shell.exec(psCmd);
|
|
102
114
|
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
// 4. Stream Log to Main Console
|
|
116
|
+
let lastSize = 0;
|
|
117
|
+
const checkInterval = setInterval(() => {
|
|
118
|
+
try {
|
|
119
|
+
if (!fs.existsSync(progressFile)) return;
|
|
120
|
+
|
|
121
|
+
const stats = fs.statSync(progressFile);
|
|
122
|
+
if (stats.size > lastSize) {
|
|
123
|
+
const fd = fs.openSync(progressFile, 'r');
|
|
124
|
+
const buffer = Buffer.alloc(stats.size - lastSize);
|
|
125
|
+
fs.readSync(fd, buffer, 0, buffer.length, lastSize);
|
|
126
|
+
fs.closeSync(fd);
|
|
127
|
+
|
|
128
|
+
const newText = buffer.toString('utf8');
|
|
129
|
+
// Filter out transcript headers if desired, or just print
|
|
130
|
+
process.stdout.write(newText);
|
|
131
|
+
lastSize = stats.size;
|
|
132
|
+
|
|
133
|
+
if (newText.includes("USO_AC_SUCCESS")) {
|
|
134
|
+
clearInterval(checkInterval);
|
|
135
|
+
resolve();
|
|
136
|
+
} else if (newText.includes("USO_AC_FAILURE")) {
|
|
137
|
+
clearInterval(checkInterval);
|
|
138
|
+
resolve(); // Resolve to allow flow to finish (logs showed error)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
// Ignore busy/lock errors during polling
|
|
143
|
+
}
|
|
144
|
+
}, 500);
|
|
106
145
|
});
|
|
107
146
|
};
|
|
108
147
|
|