@walkhi/code-relax 0.1.0-beta.65 → 0.1.0-beta.68
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/dist/bin/codex-remote.mjs +4 -2
- package/dist/bin/manage-relay-admin.mjs +20 -20
- package/dist/bin/migrate-relay-db.mjs +109 -109
- package/dist/bin/publish-harmony-release.mjs +46 -46
- package/dist/bin/self-relay-admin.mjs +8 -8
- package/dist/bin/self-relay-demo.mjs +33 -33
- package/dist/bin/self-relay-server.mjs +66 -66
- package/dist/bin/set-relay-admin-password.mjs +11 -11
- package/dist/build-platform.json +1 -1
- package/dist/get-lan-networks.ps1 +40 -40
- package/dist/shared/app-server-events.cjs +511 -511
- package/dist/shared/p2p-data-channel.cjs +72 -72
- package/dist/shared/p2p-diagnostics.cjs +28 -28
- package/dist/shared/p2p-ice-policy.cjs +22 -22
- package/dist/shared/plan-pricing.cjs +32 -32
- package/dist/shared/question-attention.cjs +69 -69
- package/dist/shared/release-version.cjs +31 -31
- package/dist/src/archived-threads.mjs +22 -22
- package/dist/src/background-process.mjs +18 -18
- package/dist/src/code-browser.mjs +100 -100
- package/dist/src/desktop-launcher.mjs +62 -62
- package/dist/src/dots-task-files.mjs +52 -52
- package/dist/src/execution-health.mjs +26 -26
- package/dist/src/message-images.mjs +9 -9
- package/dist/src/plan-pricing.mjs +47 -47
- package/dist/src/platform/codex-runtime.mjs +3 -3
- package/dist/src/platform/credential-store.mjs +19 -19
- package/dist/src/platform/desktop-host.mjs +3 -3
- package/dist/src/platform/desktop-permission-mode.mjs +17 -17
- package/dist/src/platform/desktop-project-registration.mjs +3 -3
- package/dist/src/platform/file-opener.mjs +9 -9
- package/dist/src/platform/linux/README.md +3 -3
- package/dist/src/platform/linux/codex-runtime.mjs +56 -56
- package/dist/src/platform/linux/desktop-installation.mjs +36 -36
- package/dist/src/platform/linux/desktop-project-registration.mjs +11 -11
- package/dist/src/platform/linux/network-info.mjs +11 -11
- package/dist/src/platform/linux/project-locations.mjs +17 -17
- package/dist/src/platform/linux/resident-startup.mjs +52 -52
- package/dist/src/platform/linux/retained-runtime.mjs +76 -76
- package/dist/src/platform/linux/service-host.mjs +18 -18
- package/dist/src/platform/macos/README.md +3 -3
- package/dist/src/platform/macos/codex-runtime.mjs +0 -4
- package/dist/src/platform/macos/desktop-project-registration.mjs +11 -11
- package/dist/src/platform/macos/network-info.mjs +8 -8
- package/dist/src/platform/macos/project-locations.mjs +8 -8
- package/dist/src/platform/macos/resident-startup.mjs +84 -84
- package/dist/src/platform/macos/retained-runtime.mjs +127 -127
- package/dist/src/platform/macos/service-host.mjs +18 -18
- package/dist/src/platform/macos/system.mjs +29 -29
- package/dist/src/platform/network-info.mjs +3 -3
- package/dist/src/platform/path-identity.mjs +5 -5
- package/dist/src/platform/posix/network-candidates.mjs +23 -23
- package/dist/src/platform/posix/runtime-paths.mjs +25 -25
- package/dist/src/platform/power-inhibitor.mjs +22 -22
- package/dist/src/platform/project-locations.mjs +3 -3
- package/dist/src/platform/runtime-paths.mjs +8 -8
- package/dist/src/platform/select.mjs +5 -5
- package/dist/src/platform/service-host.mjs +3 -3
- package/dist/src/platform/user-environment.mjs +3 -3
- package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
- package/dist/src/platform/windows/background-process.mjs +30 -30
- package/dist/src/platform/windows/desktop-helper.mjs +179 -179
- package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
- package/dist/src/platform/windows/desktop-shortcuts.ps1 +7 -7
- package/dist/src/platform/windows/keep-awake.ps1 +20 -20
- package/dist/src/platform/windows/network-info.mjs +34 -34
- package/dist/src/platform/windows/resident-start.js +20 -20
- package/dist/src/platform/windows/resident-start.ps1 +7 -7
- package/dist/src/platform/windows/resident-startup.ps1 +83 -83
- package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
- package/dist/src/platform/windows/runtime-paths.mjs +20 -20
- package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
- package/dist/src/platform/windows/start-hidden-console.ps1 +58 -58
- package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
- package/dist/src/platform/windows/user-environment.ps1 +41 -41
- package/dist/src/project-create.mjs +121 -121
- package/dist/src/project-management.mjs +1 -1
- package/dist/src/project-remove.mjs +55 -55
- package/dist/src/project-update.mjs +59 -59
- package/dist/src/relay-config-import.mjs +45 -45
- package/dist/src/self-relay/account-connections.mjs +52 -52
- package/dist/src/self-relay/admin-auth.mjs +59 -59
- package/dist/src/self-relay/admin-cloud.mjs +101 -101
- package/dist/src/self-relay/admin-login-page.mjs +7 -7
- package/dist/src/self-relay/admin-server.mjs +105 -105
- package/dist/src/self-relay/admin-state.mjs +127 -127
- package/dist/src/self-relay/admin-workstations-page.mjs +95 -95
- package/dist/src/self-relay/admin-workstations.mjs +143 -143
- package/dist/src/self-relay/android-releases.mjs +61 -61
- package/dist/src/self-relay/client.mjs +61 -61
- package/dist/src/self-relay/connection-reporting.mjs +38 -38
- package/dist/src/self-relay/debug-allowlist.mjs +33 -33
- package/dist/src/self-relay/demo.mjs +6 -6
- package/dist/src/self-relay/device-info.mjs +27 -27
- package/dist/src/self-relay/device-store.mjs +92 -92
- package/dist/src/self-relay/lan-authorizations.mjs +71 -71
- package/dist/src/self-relay/lifecycle.mjs +278 -278
- package/dist/src/self-relay/long-pairing.mjs +40 -40
- package/dist/src/self-relay/mysql-state.mjs +118 -118
- package/dist/src/self-relay/phone-connections.mjs +55 -55
- package/dist/src/self-relay/server.mjs +1066 -1066
- package/dist/src/self-relay/usage-daily.mjs +55 -55
- package/dist/src/self-relay/windows-route-helper.mjs +75 -75
- package/dist/src/self-relay/wire.mjs +36 -36
- package/dist/src/server.mjs +1947 -1947
- package/dist/src/service-control.mjs +82 -82
- package/dist/src/service-health.mjs +33 -33
- package/dist/src/service-power.mjs +58 -58
- package/dist/src/service-restart.mjs +81 -81
- package/dist/src/service-update-worker.mjs +42 -42
- package/dist/src/service-update.mjs +80 -80
- package/dist/src/shared-recovery.mjs +152 -152
- package/dist/src/skill-install.mjs +51 -51
- package/dist/src/thread-title-generation.mjs +150 -150
- package/dist/src/turn-model-history.mjs +47 -47
- package/dist/tools/rtc-route-helper.ps1 +99 -99
- package/dist/tools/start-rtc-route-helper.ps1 +15 -15
- package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
- package/dist/web/vendor/markdown-it.umd.min.js +13 -13
- package/package.json +4 -4
- package/tools/postinstall.mjs +1 -1
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import net from 'node:net';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
7
|
-
import { brotliDecompressSync } from 'node:zlib';
|
|
8
|
-
|
|
9
|
-
export const RUSTDESK_PROBE_HOST_SHA256 = '8555777215510d83d2d61c9dc984e4fcc838bd7e79f9d18a42585431f5e8bb47';
|
|
10
|
-
const leaseMs = 60_000;
|
|
11
|
-
const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
12
|
-
const failure = code => Object.assign(new Error('桌面视频测试尚未就绪'), { code, statusCode: 503 });
|
|
13
|
-
|
|
14
|
-
// The official EXE is a launcher. Extract its verified Brotli payload into our
|
|
15
|
-
// own runtime directory and launch the actual process, so leases own its PID.
|
|
16
|
-
export function prepareRustDeskProbeHost(root) {
|
|
17
|
-
const bytes = fs.readFileSync(path.join(root, 'rustdesk-1.5.0-x86_64.exe'));
|
|
18
|
-
if (crypto.createHash('sha256').update(bytes).digest('hex') !== RUSTDESK_PROBE_HOST_SHA256) throw failure('desktop_video_host_hash');
|
|
19
|
-
const magic = Buffer.from('rustdesk'), decoder = new TextDecoder('utf-8', { fatal: true });
|
|
20
|
-
let search = 0, entries;
|
|
21
|
-
while (search < bytes.length) {
|
|
22
|
-
const at = bytes.indexOf(magic, search); if (at < 0) break; search = at + magic.length;
|
|
23
|
-
try {
|
|
24
|
-
let offset = at + magic.length; const files = [];
|
|
25
|
-
while (!bytes.subarray(offset, offset + magic.length).equals(magic)) {
|
|
26
|
-
const length = bytes.readUInt32BE(offset); offset += 4;
|
|
27
|
-
if (length < 1 || length > 512) throw new Error('payload');
|
|
28
|
-
const name = decoder.decode(bytes.subarray(offset, offset + length)).replaceAll('\\', '/'); offset += length;
|
|
29
|
-
if (/[\x00-\x1f]/.test(name) || path.posix.isAbsolute(name) || name.includes(':') || name.split('/').includes('..')) throw new Error('payload_path');
|
|
30
|
-
const size = bytes.readUInt32BE(offset); offset += 4;
|
|
31
|
-
if (size < 1 || offset + size + 32 > bytes.length) throw new Error('payload');
|
|
32
|
-
const data = bytes.subarray(offset, offset + size); offset += size;
|
|
33
|
-
const md5 = bytes.subarray(offset, offset + 32).toString(); offset += 32;
|
|
34
|
-
if (!/^[a-f0-9]{32}$/.test(md5)) throw new Error('payload');
|
|
35
|
-
files.push({ name: path.posix.normalize(name), data, md5 });
|
|
36
|
-
if (files.length > 5000) throw new Error('payload');
|
|
37
|
-
}
|
|
38
|
-
if (files.length !== 104 || !files.some(file => file.name === 'rustdesk.exe')) continue;
|
|
39
|
-
const suffix = Buffer.from('.\\rustdesk.exe');
|
|
40
|
-
if (!bytes.subarray(offset + 8, offset + 8 + suffix.length).equals(suffix)) continue;
|
|
41
|
-
entries = files; break;
|
|
42
|
-
} catch { /* Non-payload occurrences of the ASCII magic are expected in PE strings. */ }
|
|
43
|
-
}
|
|
44
|
-
if (!entries) throw failure('desktop_video_host_payload');
|
|
45
|
-
const runtime = path.resolve(root, 'runtime');
|
|
46
|
-
for (const file of entries) {
|
|
47
|
-
const target = path.resolve(runtime, file.name);
|
|
48
|
-
if (!target.startsWith(runtime + path.sep)) throw failure('desktop_video_host_path');
|
|
49
|
-
let existing;
|
|
50
|
-
try { existing = crypto.createHash('md5').update(fs.readFileSync(target)).digest('hex'); } catch {}
|
|
51
|
-
if (existing === file.md5) continue;
|
|
52
|
-
const data = brotliDecompressSync(file.data, { maxOutputLength: 128 * 1024 * 1024 });
|
|
53
|
-
if (crypto.createHash('md5').update(data).digest('hex') !== file.md5) throw failure('desktop_video_host_payload');
|
|
54
|
-
fs.mkdirSync(path.dirname(target), { recursive: true }); fs.writeFileSync(target, data);
|
|
55
|
-
}
|
|
56
|
-
return path.join(runtime, 'rustdesk.exe');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// A read-only, LAN-only prototype. The normal desktop helper and input path are independent.
|
|
60
|
-
export class RustDeskVideoProbe {
|
|
61
|
-
constructor({ stateRoot, appData = process.env.APPDATA, platform = process.platform } = {}) {
|
|
62
|
-
this.platform = platform;
|
|
63
|
-
this.root = path.join(stateRoot, 'desktop-video-probe');
|
|
64
|
-
this.configRoot = path.join(appData || os.tmpdir(), 'RustDesk', 'config');
|
|
65
|
-
this.process = null; this.lease = null; this.timer = null; this.starting = false; this.stopped = Promise.resolve(); this.preparedExecutable = null;
|
|
66
|
-
}
|
|
67
|
-
configuration(port, password) {
|
|
68
|
-
const options = {
|
|
69
|
-
'direct-server': 'Y', 'direct-access-port': String(port),
|
|
70
|
-
'custom-rendezvous-server': '127.0.0.1:9', 'relay-server': '127.0.0.1:9', 'api-server': 'http://127.0.0.1:9',
|
|
71
|
-
'enable-hwcodec': 'N', 'access-mode': 'view', 'approve-mode': 'password', 'verification-method': 'use-permanent-password',
|
|
72
|
-
'enable-keyboard': 'N', 'enable-clipboard': 'N', 'enable-file-transfer': 'N', 'enable-audio': 'N',
|
|
73
|
-
'enable-tunnel': 'N', 'enable-terminal': 'N', 'enable-record-session': 'N',
|
|
74
|
-
'allow-auto-record-incoming': 'N', 'allow-auto-record-outgoing': 'N'
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
main: `password = '${password}'\nsalt = '${crypto.randomBytes(16).toString('hex')}'\n`,
|
|
78
|
-
secondary: "rendezvous_server = '127.0.0.1:9'\n\n[options]\n" + Object.entries(options).map(([key, value]) => `${key} = '${value}'`).join('\n') + '\n'
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async begin() {
|
|
82
|
-
if (this.platform !== 'win32') throw failure('desktop_video_platform');
|
|
83
|
-
if (this.starting || this.lease) throw failure('desktop_video_busy');
|
|
84
|
-
this.starting = true;
|
|
85
|
-
try {
|
|
86
|
-
await this.stopped;
|
|
87
|
-
const executable = path.join(this.root, 'rustdesk-1.5.0-x86_64.exe');
|
|
88
|
-
let binary;
|
|
89
|
-
try { binary = fs.readFileSync(executable); } catch { throw failure('desktop_video_host_missing'); }
|
|
90
|
-
if (crypto.createHash('sha256').update(binary).digest('hex') !== RUSTDESK_PROBE_HOST_SHA256) throw failure('desktop_video_host_hash');
|
|
91
|
-
const ownerFile = path.join(this.root, 'config-owner.json');
|
|
92
|
-
let owner;
|
|
93
|
-
try { owner = JSON.parse(fs.readFileSync(ownerFile, 'utf8')); } catch {}
|
|
94
|
-
const entries = fs.existsSync(this.configRoot) ? fs.readdirSync(this.configRoot) : [];
|
|
95
|
-
if (entries.length && (owner?.configRoot !== this.configRoot || !owner.hashes
|
|
96
|
-
|| JSON.stringify(owner.hashes) !== JSON.stringify(this.configHashes()))) throw failure('desktop_video_existing_rustdesk');
|
|
97
|
-
const port = await new Promise((resolve, reject) => {
|
|
98
|
-
const server = net.createServer(); server.once('error', reject);
|
|
99
|
-
server.listen(0, '127.0.0.1', () => { const port = server.address().port; server.close(error => error ? reject(error) : resolve(port)); });
|
|
100
|
-
});
|
|
101
|
-
const actualExecutable = this.preparedExecutable ||= prepareRustDeskProbeHost(this.root);
|
|
102
|
-
const password = crypto.randomBytes(24).toString('hex'), leaseId = crypto.randomBytes(16).toString('hex');
|
|
103
|
-
const config = this.configuration(port, password);
|
|
104
|
-
fs.mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
105
|
-
fs.mkdirSync(this.configRoot, { recursive: true, mode: 0o700 });
|
|
106
|
-
fs.writeFileSync(path.join(this.configRoot, 'RustDesk.toml'), config.main, { mode: 0o600 });
|
|
107
|
-
fs.writeFileSync(path.join(this.configRoot, 'RustDesk2.toml'), config.secondary, { mode: 0o600 });
|
|
108
|
-
this.saveOwner();
|
|
109
|
-
this.process = spawn(actualExecutable, ['--server'], { cwd: path.dirname(actualExecutable),
|
|
110
|
-
env: { ...process.env, RUSTDESK_APPNAME: 'rustdesk-1.5.0-x86_64.exe' }, windowsHide: true, stdio: 'ignore' });
|
|
111
|
-
const child = this.process; let launchError = false;
|
|
112
|
-
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'spawn', pid: child.pid }));
|
|
113
|
-
this.stopped = new Promise(resolve => {
|
|
114
|
-
let ended = false;
|
|
115
|
-
const finished = () => {
|
|
116
|
-
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'exit', pid: child.pid, code: child.exitCode }));
|
|
117
|
-
if (ended) return; ended = true;
|
|
118
|
-
try { this.saveOwner(); } catch { console.error(JSON.stringify({ event: 'desktop-video-owner', state: 'failed' })); }
|
|
119
|
-
if (this.process === child) { clearTimeout(this.timer); this.process = null; this.lease = null; }
|
|
120
|
-
resolve();
|
|
121
|
-
};
|
|
122
|
-
child.once('error', () => { launchError = true; finished(); });
|
|
123
|
-
child.once('exit', finished);
|
|
124
|
-
});
|
|
125
|
-
const deadline = Date.now() + 8_000;
|
|
126
|
-
let ready = false;
|
|
127
|
-
while (Date.now() < deadline && child.exitCode === null && !launchError) {
|
|
128
|
-
ready = await new Promise(resolve => {
|
|
129
|
-
const socket = net.connect({ host: '127.0.0.1', port });
|
|
130
|
-
let settled = false;
|
|
131
|
-
const finish = value => { if (settled) return; settled = true; socket.destroy(); resolve(value); };
|
|
132
|
-
socket.once('connect', () => finish(true)); socket.once('error', () => finish(false)); socket.setTimeout(300, () => finish(false));
|
|
133
|
-
});
|
|
134
|
-
if (ready) break;
|
|
135
|
-
await pause(150);
|
|
136
|
-
}
|
|
137
|
-
if (!ready) throw failure('desktop_video_host_start');
|
|
138
|
-
this.lease = { leaseId, password, port, codec: 'vp9', fps: 5, viewOnly: true };
|
|
139
|
-
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'ready', pid: child.pid }));
|
|
140
|
-
this.renew(leaseId);
|
|
141
|
-
return { ...this.lease, engine: 'rustdesk-probe', expiresInMs: leaseMs };
|
|
142
|
-
} catch (error) { this.stop(); throw error; }
|
|
143
|
-
finally { this.starting = false; }
|
|
144
|
-
}
|
|
145
|
-
configHashes() {
|
|
146
|
-
return ['RustDesk.toml', 'RustDesk2.toml'].map(name => {
|
|
147
|
-
try { return crypto.createHash('sha256').update(fs.readFileSync(path.join(this.configRoot, name))).digest('hex'); }
|
|
148
|
-
catch { return ''; }
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
saveOwner() {
|
|
152
|
-
fs.writeFileSync(path.join(this.root, 'config-owner.json'), JSON.stringify({ configRoot: this.configRoot, hashes: this.configHashes() }), { mode: 0o600 });
|
|
153
|
-
}
|
|
154
|
-
renew(leaseId) {
|
|
155
|
-
if (!this.lease || leaseId !== this.lease.leaseId) throw failure('desktop_video_lease');
|
|
156
|
-
clearTimeout(this.timer); this.timer = setTimeout(() => this.stop(), leaseMs); this.timer.unref();
|
|
157
|
-
return { active: true, expiresInMs: leaseMs };
|
|
158
|
-
}
|
|
159
|
-
release(leaseId) {
|
|
160
|
-
if (this.lease?.leaseId === leaseId) this.stop();
|
|
161
|
-
return { released: true };
|
|
162
|
-
}
|
|
163
|
-
stop() {
|
|
164
|
-
clearTimeout(this.timer); this.timer = null;
|
|
165
|
-
const child = this.process; this.process = null; this.lease = null;
|
|
166
|
-
if (child && child.exitCode === null) child.kill();
|
|
167
|
-
}
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { brotliDecompressSync } from 'node:zlib';
|
|
8
|
+
|
|
9
|
+
export const RUSTDESK_PROBE_HOST_SHA256 = '8555777215510d83d2d61c9dc984e4fcc838bd7e79f9d18a42585431f5e8bb47';
|
|
10
|
+
const leaseMs = 60_000;
|
|
11
|
+
const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
12
|
+
const failure = code => Object.assign(new Error('桌面视频测试尚未就绪'), { code, statusCode: 503 });
|
|
13
|
+
|
|
14
|
+
// The official EXE is a launcher. Extract its verified Brotli payload into our
|
|
15
|
+
// own runtime directory and launch the actual process, so leases own its PID.
|
|
16
|
+
export function prepareRustDeskProbeHost(root) {
|
|
17
|
+
const bytes = fs.readFileSync(path.join(root, 'rustdesk-1.5.0-x86_64.exe'));
|
|
18
|
+
if (crypto.createHash('sha256').update(bytes).digest('hex') !== RUSTDESK_PROBE_HOST_SHA256) throw failure('desktop_video_host_hash');
|
|
19
|
+
const magic = Buffer.from('rustdesk'), decoder = new TextDecoder('utf-8', { fatal: true });
|
|
20
|
+
let search = 0, entries;
|
|
21
|
+
while (search < bytes.length) {
|
|
22
|
+
const at = bytes.indexOf(magic, search); if (at < 0) break; search = at + magic.length;
|
|
23
|
+
try {
|
|
24
|
+
let offset = at + magic.length; const files = [];
|
|
25
|
+
while (!bytes.subarray(offset, offset + magic.length).equals(magic)) {
|
|
26
|
+
const length = bytes.readUInt32BE(offset); offset += 4;
|
|
27
|
+
if (length < 1 || length > 512) throw new Error('payload');
|
|
28
|
+
const name = decoder.decode(bytes.subarray(offset, offset + length)).replaceAll('\\', '/'); offset += length;
|
|
29
|
+
if (/[\x00-\x1f]/.test(name) || path.posix.isAbsolute(name) || name.includes(':') || name.split('/').includes('..')) throw new Error('payload_path');
|
|
30
|
+
const size = bytes.readUInt32BE(offset); offset += 4;
|
|
31
|
+
if (size < 1 || offset + size + 32 > bytes.length) throw new Error('payload');
|
|
32
|
+
const data = bytes.subarray(offset, offset + size); offset += size;
|
|
33
|
+
const md5 = bytes.subarray(offset, offset + 32).toString(); offset += 32;
|
|
34
|
+
if (!/^[a-f0-9]{32}$/.test(md5)) throw new Error('payload');
|
|
35
|
+
files.push({ name: path.posix.normalize(name), data, md5 });
|
|
36
|
+
if (files.length > 5000) throw new Error('payload');
|
|
37
|
+
}
|
|
38
|
+
if (files.length !== 104 || !files.some(file => file.name === 'rustdesk.exe')) continue;
|
|
39
|
+
const suffix = Buffer.from('.\\rustdesk.exe');
|
|
40
|
+
if (!bytes.subarray(offset + 8, offset + 8 + suffix.length).equals(suffix)) continue;
|
|
41
|
+
entries = files; break;
|
|
42
|
+
} catch { /* Non-payload occurrences of the ASCII magic are expected in PE strings. */ }
|
|
43
|
+
}
|
|
44
|
+
if (!entries) throw failure('desktop_video_host_payload');
|
|
45
|
+
const runtime = path.resolve(root, 'runtime');
|
|
46
|
+
for (const file of entries) {
|
|
47
|
+
const target = path.resolve(runtime, file.name);
|
|
48
|
+
if (!target.startsWith(runtime + path.sep)) throw failure('desktop_video_host_path');
|
|
49
|
+
let existing;
|
|
50
|
+
try { existing = crypto.createHash('md5').update(fs.readFileSync(target)).digest('hex'); } catch {}
|
|
51
|
+
if (existing === file.md5) continue;
|
|
52
|
+
const data = brotliDecompressSync(file.data, { maxOutputLength: 128 * 1024 * 1024 });
|
|
53
|
+
if (crypto.createHash('md5').update(data).digest('hex') !== file.md5) throw failure('desktop_video_host_payload');
|
|
54
|
+
fs.mkdirSync(path.dirname(target), { recursive: true }); fs.writeFileSync(target, data);
|
|
55
|
+
}
|
|
56
|
+
return path.join(runtime, 'rustdesk.exe');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// A read-only, LAN-only prototype. The normal desktop helper and input path are independent.
|
|
60
|
+
export class RustDeskVideoProbe {
|
|
61
|
+
constructor({ stateRoot, appData = process.env.APPDATA, platform = process.platform } = {}) {
|
|
62
|
+
this.platform = platform;
|
|
63
|
+
this.root = path.join(stateRoot, 'desktop-video-probe');
|
|
64
|
+
this.configRoot = path.join(appData || os.tmpdir(), 'RustDesk', 'config');
|
|
65
|
+
this.process = null; this.lease = null; this.timer = null; this.starting = false; this.stopped = Promise.resolve(); this.preparedExecutable = null;
|
|
66
|
+
}
|
|
67
|
+
configuration(port, password) {
|
|
68
|
+
const options = {
|
|
69
|
+
'direct-server': 'Y', 'direct-access-port': String(port),
|
|
70
|
+
'custom-rendezvous-server': '127.0.0.1:9', 'relay-server': '127.0.0.1:9', 'api-server': 'http://127.0.0.1:9',
|
|
71
|
+
'enable-hwcodec': 'N', 'access-mode': 'view', 'approve-mode': 'password', 'verification-method': 'use-permanent-password',
|
|
72
|
+
'enable-keyboard': 'N', 'enable-clipboard': 'N', 'enable-file-transfer': 'N', 'enable-audio': 'N',
|
|
73
|
+
'enable-tunnel': 'N', 'enable-terminal': 'N', 'enable-record-session': 'N',
|
|
74
|
+
'allow-auto-record-incoming': 'N', 'allow-auto-record-outgoing': 'N'
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
main: `password = '${password}'\nsalt = '${crypto.randomBytes(16).toString('hex')}'\n`,
|
|
78
|
+
secondary: "rendezvous_server = '127.0.0.1:9'\n\n[options]\n" + Object.entries(options).map(([key, value]) => `${key} = '${value}'`).join('\n') + '\n'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async begin() {
|
|
82
|
+
if (this.platform !== 'win32') throw failure('desktop_video_platform');
|
|
83
|
+
if (this.starting || this.lease) throw failure('desktop_video_busy');
|
|
84
|
+
this.starting = true;
|
|
85
|
+
try {
|
|
86
|
+
await this.stopped;
|
|
87
|
+
const executable = path.join(this.root, 'rustdesk-1.5.0-x86_64.exe');
|
|
88
|
+
let binary;
|
|
89
|
+
try { binary = fs.readFileSync(executable); } catch { throw failure('desktop_video_host_missing'); }
|
|
90
|
+
if (crypto.createHash('sha256').update(binary).digest('hex') !== RUSTDESK_PROBE_HOST_SHA256) throw failure('desktop_video_host_hash');
|
|
91
|
+
const ownerFile = path.join(this.root, 'config-owner.json');
|
|
92
|
+
let owner;
|
|
93
|
+
try { owner = JSON.parse(fs.readFileSync(ownerFile, 'utf8')); } catch {}
|
|
94
|
+
const entries = fs.existsSync(this.configRoot) ? fs.readdirSync(this.configRoot) : [];
|
|
95
|
+
if (entries.length && (owner?.configRoot !== this.configRoot || !owner.hashes
|
|
96
|
+
|| JSON.stringify(owner.hashes) !== JSON.stringify(this.configHashes()))) throw failure('desktop_video_existing_rustdesk');
|
|
97
|
+
const port = await new Promise((resolve, reject) => {
|
|
98
|
+
const server = net.createServer(); server.once('error', reject);
|
|
99
|
+
server.listen(0, '127.0.0.1', () => { const port = server.address().port; server.close(error => error ? reject(error) : resolve(port)); });
|
|
100
|
+
});
|
|
101
|
+
const actualExecutable = this.preparedExecutable ||= prepareRustDeskProbeHost(this.root);
|
|
102
|
+
const password = crypto.randomBytes(24).toString('hex'), leaseId = crypto.randomBytes(16).toString('hex');
|
|
103
|
+
const config = this.configuration(port, password);
|
|
104
|
+
fs.mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
105
|
+
fs.mkdirSync(this.configRoot, { recursive: true, mode: 0o700 });
|
|
106
|
+
fs.writeFileSync(path.join(this.configRoot, 'RustDesk.toml'), config.main, { mode: 0o600 });
|
|
107
|
+
fs.writeFileSync(path.join(this.configRoot, 'RustDesk2.toml'), config.secondary, { mode: 0o600 });
|
|
108
|
+
this.saveOwner();
|
|
109
|
+
this.process = spawn(actualExecutable, ['--server'], { cwd: path.dirname(actualExecutable),
|
|
110
|
+
env: { ...process.env, RUSTDESK_APPNAME: 'rustdesk-1.5.0-x86_64.exe' }, windowsHide: true, stdio: 'ignore' });
|
|
111
|
+
const child = this.process; let launchError = false;
|
|
112
|
+
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'spawn', pid: child.pid }));
|
|
113
|
+
this.stopped = new Promise(resolve => {
|
|
114
|
+
let ended = false;
|
|
115
|
+
const finished = () => {
|
|
116
|
+
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'exit', pid: child.pid, code: child.exitCode }));
|
|
117
|
+
if (ended) return; ended = true;
|
|
118
|
+
try { this.saveOwner(); } catch { console.error(JSON.stringify({ event: 'desktop-video-owner', state: 'failed' })); }
|
|
119
|
+
if (this.process === child) { clearTimeout(this.timer); this.process = null; this.lease = null; }
|
|
120
|
+
resolve();
|
|
121
|
+
};
|
|
122
|
+
child.once('error', () => { launchError = true; finished(); });
|
|
123
|
+
child.once('exit', finished);
|
|
124
|
+
});
|
|
125
|
+
const deadline = Date.now() + 8_000;
|
|
126
|
+
let ready = false;
|
|
127
|
+
while (Date.now() < deadline && child.exitCode === null && !launchError) {
|
|
128
|
+
ready = await new Promise(resolve => {
|
|
129
|
+
const socket = net.connect({ host: '127.0.0.1', port });
|
|
130
|
+
let settled = false;
|
|
131
|
+
const finish = value => { if (settled) return; settled = true; socket.destroy(); resolve(value); };
|
|
132
|
+
socket.once('connect', () => finish(true)); socket.once('error', () => finish(false)); socket.setTimeout(300, () => finish(false));
|
|
133
|
+
});
|
|
134
|
+
if (ready) break;
|
|
135
|
+
await pause(150);
|
|
136
|
+
}
|
|
137
|
+
if (!ready) throw failure('desktop_video_host_start');
|
|
138
|
+
this.lease = { leaseId, password, port, codec: 'vp9', fps: 5, viewOnly: true };
|
|
139
|
+
console.info(JSON.stringify({ event: 'desktop-video-host', stage: 'ready', pid: child.pid }));
|
|
140
|
+
this.renew(leaseId);
|
|
141
|
+
return { ...this.lease, engine: 'rustdesk-probe', expiresInMs: leaseMs };
|
|
142
|
+
} catch (error) { this.stop(); throw error; }
|
|
143
|
+
finally { this.starting = false; }
|
|
144
|
+
}
|
|
145
|
+
configHashes() {
|
|
146
|
+
return ['RustDesk.toml', 'RustDesk2.toml'].map(name => {
|
|
147
|
+
try { return crypto.createHash('sha256').update(fs.readFileSync(path.join(this.configRoot, name))).digest('hex'); }
|
|
148
|
+
catch { return ''; }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
saveOwner() {
|
|
152
|
+
fs.writeFileSync(path.join(this.root, 'config-owner.json'), JSON.stringify({ configRoot: this.configRoot, hashes: this.configHashes() }), { mode: 0o600 });
|
|
153
|
+
}
|
|
154
|
+
renew(leaseId) {
|
|
155
|
+
if (!this.lease || leaseId !== this.lease.leaseId) throw failure('desktop_video_lease');
|
|
156
|
+
clearTimeout(this.timer); this.timer = setTimeout(() => this.stop(), leaseMs); this.timer.unref();
|
|
157
|
+
return { active: true, expiresInMs: leaseMs };
|
|
158
|
+
}
|
|
159
|
+
release(leaseId) {
|
|
160
|
+
if (this.lease?.leaseId === leaseId) this.stop();
|
|
161
|
+
return { released: true };
|
|
162
|
+
}
|
|
163
|
+
stop() {
|
|
164
|
+
clearTimeout(this.timer); this.timer = null;
|
|
165
|
+
const child = this.process; this.process = null; this.lease = null;
|
|
166
|
+
if (child && child.exitCode === null) child.kill();
|
|
167
|
+
}
|
|
168
168
|
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
$ErrorActionPreference = 'Stop'
|
|
2
|
-
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
3
|
-
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
4
|
-
$brokerStarted = $false
|
|
5
|
-
try {
|
|
6
|
-
$spec = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
7
|
-
# WMI owns this launch, not the caller's kill-on-close Desktop job hierarchy.
|
|
8
|
-
$instance = [Guid]::NewGuid().ToString()
|
|
9
|
-
$launchRoot = [IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA 'CodexRemote\process-launch'))
|
|
10
|
-
New-Item -ItemType Directory -Path $launchRoot -Force | Out-Null
|
|
11
|
-
Add-Type -Path (Join-Path $PSScriptRoot 'IsolatedProcess.cs')
|
|
12
|
-
$launchRoot = [IsolatedProcess]::ResolvePath($launchRoot)
|
|
13
|
-
$ready = Join-Path $launchRoot ($instance + '.json')
|
|
14
|
-
$request = Join-Path $launchRoot ($instance + '.request.json')
|
|
15
|
-
$diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
|
|
16
|
-
$spec | Add-Member -NotePropertyName instance -NotePropertyValue $instance
|
|
17
|
-
$requestTemporary = $request + '.tmp'
|
|
18
|
-
[IO.File]::WriteAllText($requestTemporary, ($spec | ConvertTo-Json -Compress -Depth 10), (New-Object Text.UTF8Encoding($false)))
|
|
19
|
-
[IO.File]::Move($requestTemporary, $request)
|
|
20
|
-
# MSIX can redirect a newly written file even when its existing parent
|
|
21
|
-
# resolves outside the package. Resolve the file handle, not just the folder.
|
|
22
|
-
$request = [IsolatedProcess]::ResolvePath($request)
|
|
23
|
-
$launchRoot = [IO.Path]::GetDirectoryName($request)
|
|
24
|
-
$ready = Join-Path $launchRoot ($instance + '.json')
|
|
25
|
-
$diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
|
|
26
|
-
$startup = New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{
|
|
27
|
-
ShowWindow=[uint16]0; CreateFlags=[uint32]0x1000010
|
|
28
|
-
}
|
|
29
|
-
$worker = Join-Path $PSScriptRoot 'launch-worker.mjs'
|
|
30
|
-
$command = '"' + [string]$spec.brokerExecutable + '" "' + $worker + '" "' + $request + '" "' + $ready + '" "' + $instance + '" "' + $diagnostic + '"'
|
|
31
|
-
$broker = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
|
|
32
|
-
CommandLine=$command; CurrentDirectory=$env:USERPROFILE; ProcessStartupInformation=$startup
|
|
33
|
-
}
|
|
34
|
-
if ($broker.ReturnValue -ne 0) { throw ('Windows process broker failed: ' + $broker.ReturnValue) }
|
|
35
|
-
$brokerStarted = $true
|
|
36
|
-
$deadline = [DateTime]::UtcNow.AddSeconds(30)
|
|
37
|
-
while (-not (Test-Path -LiteralPath $ready)) {
|
|
38
|
-
if ([DateTime]::UtcNow -gt $deadline) {
|
|
39
|
-
$detail = if (Test-Path -LiteralPath $diagnostic) { (Get-Content -LiteralPath $diagnostic -Raw -Encoding UTF8).Trim() } else { 'broker did not create a diagnostic log' }
|
|
40
|
-
throw ('Windows process broker handoff timed out (broker PID ' + $broker.ProcessId + '): ' + $detail)
|
|
41
|
-
}
|
|
42
|
-
Start-Sleep -Milliseconds 50
|
|
43
|
-
}
|
|
44
|
-
$result = Get-Content -LiteralPath $ready -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
45
|
-
Remove-Item -LiteralPath $ready
|
|
46
|
-
if ($result.instance -ne $instance -or $result.brokerPid -ne $broker.ProcessId) { throw 'Windows process broker identity mismatch.' }
|
|
47
|
-
if ($result.error) { throw [string]$result.error }
|
|
48
|
-
if (Test-Path -LiteralPath $diagnostic) { Remove-Item -LiteralPath $diagnostic -Force }
|
|
49
|
-
[Console]::WriteLine([int]$result.pid)
|
|
50
|
-
} catch {
|
|
51
|
-
[Console]::Error.WriteLine($_.Exception.Message)
|
|
52
|
-
exit 1
|
|
53
|
-
} finally {
|
|
54
|
-
# Once launched, the worker owns consumption. A slow broker must not lose
|
|
55
|
-
# its request merely because this caller timed out; never launch a retry.
|
|
56
|
-
if (-not $brokerStarted -and $request -and (Test-Path -LiteralPath $request)) { Remove-Item -LiteralPath $request -Force }
|
|
57
|
-
if ($requestTemporary -and (Test-Path -LiteralPath $requestTemporary)) { Remove-Item -LiteralPath $requestTemporary -Force }
|
|
58
|
-
}
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
3
|
+
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
4
|
+
$brokerStarted = $false
|
|
5
|
+
try {
|
|
6
|
+
$spec = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
7
|
+
# WMI owns this launch, not the caller's kill-on-close Desktop job hierarchy.
|
|
8
|
+
$instance = [Guid]::NewGuid().ToString()
|
|
9
|
+
$launchRoot = [IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA 'CodexRemote\process-launch'))
|
|
10
|
+
New-Item -ItemType Directory -Path $launchRoot -Force | Out-Null
|
|
11
|
+
Add-Type -Path (Join-Path $PSScriptRoot 'IsolatedProcess.cs')
|
|
12
|
+
$launchRoot = [IsolatedProcess]::ResolvePath($launchRoot)
|
|
13
|
+
$ready = Join-Path $launchRoot ($instance + '.json')
|
|
14
|
+
$request = Join-Path $launchRoot ($instance + '.request.json')
|
|
15
|
+
$diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
|
|
16
|
+
$spec | Add-Member -NotePropertyName instance -NotePropertyValue $instance
|
|
17
|
+
$requestTemporary = $request + '.tmp'
|
|
18
|
+
[IO.File]::WriteAllText($requestTemporary, ($spec | ConvertTo-Json -Compress -Depth 10), (New-Object Text.UTF8Encoding($false)))
|
|
19
|
+
[IO.File]::Move($requestTemporary, $request)
|
|
20
|
+
# MSIX can redirect a newly written file even when its existing parent
|
|
21
|
+
# resolves outside the package. Resolve the file handle, not just the folder.
|
|
22
|
+
$request = [IsolatedProcess]::ResolvePath($request)
|
|
23
|
+
$launchRoot = [IO.Path]::GetDirectoryName($request)
|
|
24
|
+
$ready = Join-Path $launchRoot ($instance + '.json')
|
|
25
|
+
$diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
|
|
26
|
+
$startup = New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{
|
|
27
|
+
ShowWindow=[uint16]0; CreateFlags=[uint32]0x1000010
|
|
28
|
+
}
|
|
29
|
+
$worker = Join-Path $PSScriptRoot 'launch-worker.mjs'
|
|
30
|
+
$command = '"' + [string]$spec.brokerExecutable + '" "' + $worker + '" "' + $request + '" "' + $ready + '" "' + $instance + '" "' + $diagnostic + '"'
|
|
31
|
+
$broker = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
|
|
32
|
+
CommandLine=$command; CurrentDirectory=$env:USERPROFILE; ProcessStartupInformation=$startup
|
|
33
|
+
}
|
|
34
|
+
if ($broker.ReturnValue -ne 0) { throw ('Windows process broker failed: ' + $broker.ReturnValue) }
|
|
35
|
+
$brokerStarted = $true
|
|
36
|
+
$deadline = [DateTime]::UtcNow.AddSeconds(30)
|
|
37
|
+
while (-not (Test-Path -LiteralPath $ready)) {
|
|
38
|
+
if ([DateTime]::UtcNow -gt $deadline) {
|
|
39
|
+
$detail = if (Test-Path -LiteralPath $diagnostic) { (Get-Content -LiteralPath $diagnostic -Raw -Encoding UTF8).Trim() } else { 'broker did not create a diagnostic log' }
|
|
40
|
+
throw ('Windows process broker handoff timed out (broker PID ' + $broker.ProcessId + '): ' + $detail)
|
|
41
|
+
}
|
|
42
|
+
Start-Sleep -Milliseconds 50
|
|
43
|
+
}
|
|
44
|
+
$result = Get-Content -LiteralPath $ready -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
45
|
+
Remove-Item -LiteralPath $ready
|
|
46
|
+
if ($result.instance -ne $instance -or $result.brokerPid -ne $broker.ProcessId) { throw 'Windows process broker identity mismatch.' }
|
|
47
|
+
if ($result.error) { throw [string]$result.error }
|
|
48
|
+
if (Test-Path -LiteralPath $diagnostic) { Remove-Item -LiteralPath $diagnostic -Force }
|
|
49
|
+
[Console]::WriteLine([int]$result.pid)
|
|
50
|
+
} catch {
|
|
51
|
+
[Console]::Error.WriteLine($_.Exception.Message)
|
|
52
|
+
exit 1
|
|
53
|
+
} finally {
|
|
54
|
+
# Once launched, the worker owns consumption. A slow broker must not lose
|
|
55
|
+
# its request merely because this caller timed out; never launch a retry.
|
|
56
|
+
if (-not $brokerStarted -and $request -and (Test-Path -LiteralPath $request)) { Remove-Item -LiteralPath $request -Force }
|
|
57
|
+
if ($requestTemporary -and (Test-Path -LiteralPath $requestTemporary)) { Remove-Item -LiteralPath $requestTemporary -Force }
|
|
58
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
param([Parameter(Mandatory=$true)][string]$Executable)
|
|
2
|
-
$ErrorActionPreference = 'Stop'
|
|
3
|
-
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
4
|
-
$package = Get-AppxPackage OpenAI.Codex | Select-Object -First 1
|
|
5
|
-
if (-not $package -or $Executable -ne (Join-Path $package.InstallLocation 'app/ChatGPT.exe')) {
|
|
6
|
-
throw 'Desktop executable identity changed; recovery stopped.'
|
|
7
|
-
}
|
|
8
|
-
# Never kill another user's Desktop or an app-server process tree. The independent
|
|
9
|
-
# installer/recovery worker must survive and relaunch only in this interactive session.
|
|
10
|
-
$currentSessionId = (Get-Process -Id $PID -ErrorAction Stop).SessionId
|
|
11
|
-
$workers = @(Get-CimInstance Win32_Process -Filter "Name='ChatGPT.exe'" | Where-Object {
|
|
12
|
-
$_.ExecutablePath -eq $Executable -and $_.SessionId -eq $currentSessionId
|
|
13
|
-
})
|
|
14
|
-
foreach ($worker in $workers) {
|
|
15
|
-
$actual = Get-CimInstance Win32_Process -Filter "ProcessId=$($worker.ProcessId)"
|
|
16
|
-
if ($actual -and $actual.ExecutablePath -eq $worker.ExecutablePath -and $actual.CreationDate -eq $worker.CreationDate) {
|
|
17
|
-
Stop-Process -Id $worker.ProcessId -Force -ErrorAction Stop
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (Get-Process ChatGPT -ErrorAction SilentlyContinue | Where-Object { $_.Path -eq $Executable -and $_.SessionId -eq $currentSessionId }) {
|
|
21
|
-
throw 'Desktop did not exit; recovery stopped.'
|
|
22
|
-
}
|
|
1
|
+
param([Parameter(Mandatory=$true)][string]$Executable)
|
|
2
|
+
$ErrorActionPreference = 'Stop'
|
|
3
|
+
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
4
|
+
$package = Get-AppxPackage OpenAI.Codex | Select-Object -First 1
|
|
5
|
+
if (-not $package -or $Executable -ne (Join-Path $package.InstallLocation 'app/ChatGPT.exe')) {
|
|
6
|
+
throw 'Desktop executable identity changed; recovery stopped.'
|
|
7
|
+
}
|
|
8
|
+
# Never kill another user's Desktop or an app-server process tree. The independent
|
|
9
|
+
# installer/recovery worker must survive and relaunch only in this interactive session.
|
|
10
|
+
$currentSessionId = (Get-Process -Id $PID -ErrorAction Stop).SessionId
|
|
11
|
+
$workers = @(Get-CimInstance Win32_Process -Filter "Name='ChatGPT.exe'" | Where-Object {
|
|
12
|
+
$_.ExecutablePath -eq $Executable -and $_.SessionId -eq $currentSessionId
|
|
13
|
+
})
|
|
14
|
+
foreach ($worker in $workers) {
|
|
15
|
+
$actual = Get-CimInstance Win32_Process -Filter "ProcessId=$($worker.ProcessId)"
|
|
16
|
+
if ($actual -and $actual.ExecutablePath -eq $worker.ExecutablePath -and $actual.CreationDate -eq $worker.CreationDate) {
|
|
17
|
+
Stop-Process -Id $worker.ProcessId -Force -ErrorAction Stop
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (Get-Process ChatGPT -ErrorAction SilentlyContinue | Where-Object { $_.Path -eq $Executable -and $_.SessionId -eq $currentSessionId }) {
|
|
21
|
+
throw 'Desktop did not exit; recovery stopped.'
|
|
22
|
+
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
param(
|
|
2
|
-
[ValidateSet('Read', 'Set', 'Clear')][string]$Action = 'Read',
|
|
3
|
-
[string]$Value = ''
|
|
4
|
-
)
|
|
5
|
-
$ErrorActionPreference = 'Stop'
|
|
6
|
-
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
7
|
-
$name = 'CODEX_APP_SERVER_WS_URL'
|
|
8
|
-
|
|
9
|
-
function Broadcast-EnvironmentChange {
|
|
10
|
-
if (-not ('CodeRelax.EnvironmentBroadcast' -as [type])) {
|
|
11
|
-
Add-Type -Namespace CodeRelax -Name EnvironmentBroadcast -MemberDefinition @'
|
|
12
|
-
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
|
|
13
|
-
public static extern System.IntPtr SendMessageTimeout(
|
|
14
|
-
System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam,
|
|
15
|
-
uint flags, uint timeout, out System.UIntPtr result);
|
|
16
|
-
'@
|
|
17
|
-
}
|
|
18
|
-
[UIntPtr]$result = [UIntPtr]::Zero
|
|
19
|
-
[void][CodeRelax.EnvironmentBroadcast]::SendMessageTimeout(
|
|
20
|
-
[IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, 'Environment', 0x0002, 5000, [ref]$result)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if ($Action -eq 'Set') {
|
|
24
|
-
if ([string]::IsNullOrWhiteSpace($Value)) { throw 'Environment value is required.' }
|
|
25
|
-
[Environment]::SetEnvironmentVariable($name, $Value, 'User')
|
|
26
|
-
Broadcast-EnvironmentChange
|
|
27
|
-
} elseif ($Action -eq 'Clear') {
|
|
28
|
-
[Environment]::SetEnvironmentVariable($name, $null, 'User')
|
|
29
|
-
Broadcast-EnvironmentChange
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
$userValue = [Environment]::GetEnvironmentVariable($name, 'User')
|
|
33
|
-
$result = @{
|
|
34
|
-
userValue = $userValue
|
|
35
|
-
machineValue = [Environment]::GetEnvironmentVariable($name, 'Machine')
|
|
36
|
-
forceCliUser = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'User')
|
|
37
|
-
forceCliMachine = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'Machine')
|
|
38
|
-
}
|
|
39
|
-
if ($Action -eq 'Set' -and $userValue -ne $Value) { throw 'Environment value verification failed.' }
|
|
40
|
-
if ($Action -eq 'Clear' -and -not [string]::IsNullOrEmpty($userValue)) { throw 'Environment removal verification failed.' }
|
|
41
|
-
$result | ConvertTo-Json -Compress
|
|
1
|
+
param(
|
|
2
|
+
[ValidateSet('Read', 'Set', 'Clear')][string]$Action = 'Read',
|
|
3
|
+
[string]$Value = ''
|
|
4
|
+
)
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
7
|
+
$name = 'CODEX_APP_SERVER_WS_URL'
|
|
8
|
+
|
|
9
|
+
function Broadcast-EnvironmentChange {
|
|
10
|
+
if (-not ('CodeRelax.EnvironmentBroadcast' -as [type])) {
|
|
11
|
+
Add-Type -Namespace CodeRelax -Name EnvironmentBroadcast -MemberDefinition @'
|
|
12
|
+
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
|
|
13
|
+
public static extern System.IntPtr SendMessageTimeout(
|
|
14
|
+
System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam,
|
|
15
|
+
uint flags, uint timeout, out System.UIntPtr result);
|
|
16
|
+
'@
|
|
17
|
+
}
|
|
18
|
+
[UIntPtr]$result = [UIntPtr]::Zero
|
|
19
|
+
[void][CodeRelax.EnvironmentBroadcast]::SendMessageTimeout(
|
|
20
|
+
[IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, 'Environment', 0x0002, 5000, [ref]$result)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ($Action -eq 'Set') {
|
|
24
|
+
if ([string]::IsNullOrWhiteSpace($Value)) { throw 'Environment value is required.' }
|
|
25
|
+
[Environment]::SetEnvironmentVariable($name, $Value, 'User')
|
|
26
|
+
Broadcast-EnvironmentChange
|
|
27
|
+
} elseif ($Action -eq 'Clear') {
|
|
28
|
+
[Environment]::SetEnvironmentVariable($name, $null, 'User')
|
|
29
|
+
Broadcast-EnvironmentChange
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
$userValue = [Environment]::GetEnvironmentVariable($name, 'User')
|
|
33
|
+
$result = @{
|
|
34
|
+
userValue = $userValue
|
|
35
|
+
machineValue = [Environment]::GetEnvironmentVariable($name, 'Machine')
|
|
36
|
+
forceCliUser = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'User')
|
|
37
|
+
forceCliMachine = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'Machine')
|
|
38
|
+
}
|
|
39
|
+
if ($Action -eq 'Set' -and $userValue -ne $Value) { throw 'Environment value verification failed.' }
|
|
40
|
+
if ($Action -eq 'Clear' -and -not [string]::IsNullOrEmpty($userValue)) { throw 'Environment removal verification failed.' }
|
|
41
|
+
$result | ConvertTo-Json -Compress
|