@walkhi/code-relax 0.1.0-beta.30 → 0.1.0-beta.31

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.
Files changed (185) hide show
  1. package/README.md +95 -89
  2. package/dist/bin/cleanup-accounts.mjs +63 -63
  3. package/dist/bin/codex-remote.mjs +374 -367
  4. package/dist/bin/manage-relay-admin.mjs +20 -20
  5. package/dist/bin/migrate-relay-db.mjs +109 -109
  6. package/dist/bin/publish-android-release.mjs +62 -58
  7. package/dist/bin/self-relay-admin.mjs +8 -8
  8. package/dist/bin/self-relay-demo.mjs +33 -33
  9. package/dist/bin/self-relay-server.mjs +66 -66
  10. package/dist/build-platform.json +1 -1
  11. package/dist/get-lan-networks.ps1 +40 -40
  12. package/dist/get-shared-service-url.ps1 +6 -6
  13. package/dist/shared/app-server-events.cjs +422 -412
  14. package/dist/shared/code-browser.cjs +159 -159
  15. package/dist/shared/file-changes.cjs +31 -31
  16. package/dist/shared/file-citations.cjs +117 -117
  17. package/dist/shared/file-mentions.cjs +92 -92
  18. package/dist/shared/message-delivery.cjs +54 -54
  19. package/dist/shared/p2p-data-channel.cjs +72 -72
  20. package/dist/shared/p2p-diagnostics.cjs +28 -28
  21. package/dist/shared/p2p-file-channel.cjs +74 -74
  22. package/dist/shared/plan-pricing.cjs +32 -32
  23. package/dist/shared/question-attention.cjs +40 -0
  24. package/dist/shared/server-requests.cjs +219 -219
  25. package/dist/shared/timeline-sync.cjs +173 -173
  26. package/dist/skills/code-relax/SKILL.md +22 -22
  27. package/dist/src/archived-threads.mjs +22 -0
  28. package/dist/src/background-process.mjs +18 -18
  29. package/dist/src/bounded-process-log.mjs +63 -63
  30. package/dist/src/celsius-client.mjs +107 -107
  31. package/dist/src/code-browser.mjs +100 -100
  32. package/dist/src/desktop-launcher.mjs +46 -46
  33. package/dist/src/dots-approval-timeline.mjs +99 -99
  34. package/dist/src/dots-avatar.mjs +42 -42
  35. package/dist/src/dots-chat-projection.mjs +50 -50
  36. package/dist/src/dots-chat-server.mjs +461 -461
  37. package/dist/src/dots-message-images.mjs +319 -319
  38. package/dist/src/dots-profile.mjs +77 -77
  39. package/dist/src/dots-room-activity.mjs +94 -94
  40. package/dist/src/dots-room-client.mjs +135 -135
  41. package/dist/src/dots-room-projection.mjs +94 -94
  42. package/dist/src/dots-schedules.mjs +66 -66
  43. package/dist/src/dots-summary-tasks.mjs +32 -32
  44. package/dist/src/dots-task-catalog.mjs +430 -430
  45. package/dist/src/dots-task-files.mjs +52 -52
  46. package/dist/src/execution-health.mjs +26 -26
  47. package/dist/src/file-transfer-range.mjs +22 -22
  48. package/dist/src/file-upload-session.mjs +130 -130
  49. package/dist/src/hosted-history-app-server.mjs +103 -103
  50. package/dist/src/hosted-history-cache.mjs +113 -113
  51. package/dist/src/lan-socket-server.mjs +265 -263
  52. package/dist/src/managed-app-server.mjs +244 -244
  53. package/dist/src/message-images.mjs +9 -9
  54. package/dist/src/message-upload-files.mjs +74 -74
  55. package/dist/src/onboarding.mjs +12 -12
  56. package/dist/src/plan-pricing.mjs +47 -47
  57. package/dist/src/platform/README.md +12 -12
  58. package/dist/src/platform/codex-protocol.mjs +46 -46
  59. package/dist/src/platform/codex-runtime.mjs +3 -3
  60. package/dist/src/platform/credential-store.mjs +3 -3
  61. package/dist/src/platform/desktop-host.mjs +3 -3
  62. package/dist/src/platform/desktop-project-registration.mjs +3 -3
  63. package/dist/src/platform/desktop-project-store.mjs +208 -149
  64. package/dist/src/platform/file-opener.mjs +9 -0
  65. package/dist/src/platform/linux/README.md +3 -3
  66. package/dist/src/platform/linux/codex-runtime.mjs +56 -0
  67. package/dist/src/platform/linux/credential-store.mjs +28 -0
  68. package/dist/src/platform/linux/desktop-host.mjs +83 -0
  69. package/dist/src/platform/linux/desktop-installation.mjs +36 -0
  70. package/dist/src/platform/linux/desktop-project-registration.mjs +11 -0
  71. package/dist/src/platform/linux/network-info.mjs +11 -0
  72. package/dist/src/platform/linux/process.mjs +42 -0
  73. package/dist/src/platform/linux/project-locations.mjs +17 -0
  74. package/dist/src/platform/linux/resident-startup.mjs +52 -0
  75. package/dist/src/platform/linux/retained-runtime.mjs +76 -0
  76. package/dist/src/platform/linux/service-host.mjs +18 -0
  77. package/dist/src/platform/linux/system.mjs +49 -0
  78. package/dist/src/platform/linux/user-environment.mjs +7 -0
  79. package/dist/src/platform/macos/README.md +3 -3
  80. package/dist/src/platform/macos/codex-runtime.mjs +125 -125
  81. package/dist/src/platform/macos/credential-store.mjs +10 -10
  82. package/dist/src/platform/macos/desktop-host.mjs +82 -82
  83. package/dist/src/platform/macos/desktop-project-registration.mjs +11 -10
  84. package/dist/src/platform/macos/network-info.mjs +8 -28
  85. package/dist/src/platform/macos/project-locations.mjs +8 -8
  86. package/dist/src/platform/macos/resident-startup.mjs +84 -84
  87. package/dist/src/platform/macos/retained-runtime.mjs +127 -127
  88. package/dist/src/platform/macos/service-host.mjs +18 -18
  89. package/dist/src/platform/macos/system.mjs +29 -29
  90. package/dist/src/platform/macos/user-environment.mjs +7 -7
  91. package/dist/src/platform/native-package.mjs +58 -46
  92. package/dist/src/platform/network-info.mjs +3 -3
  93. package/dist/src/platform/path-identity.mjs +5 -5
  94. package/dist/src/platform/posix/network-candidates.mjs +23 -0
  95. package/dist/src/platform/posix/runtime-paths.mjs +25 -25
  96. package/dist/src/platform/project-locations.mjs +3 -3
  97. package/dist/src/platform/runtime-paths.mjs +8 -8
  98. package/dist/src/platform/select.mjs +5 -5
  99. package/dist/src/platform/service-host.mjs +3 -3
  100. package/dist/src/platform/user-environment.mjs +3 -3
  101. package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
  102. package/dist/src/platform/windows/activate-desktop.ps1 +48 -48
  103. package/dist/src/platform/windows/background-process.mjs +30 -30
  104. package/dist/src/platform/windows/codex-runtime.mjs +215 -215
  105. package/dist/src/platform/windows/credential-store.mjs +27 -27
  106. package/dist/src/platform/windows/credential-store.ps1 +49 -49
  107. package/dist/src/platform/windows/desktop-helper.mjs +179 -179
  108. package/dist/src/platform/windows/desktop-host.mjs +58 -58
  109. package/dist/src/platform/windows/desktop-info.ps1 +14 -14
  110. package/dist/src/platform/windows/desktop-project-registration.mjs +4 -4
  111. package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
  112. package/dist/src/platform/windows/desktop-shortcuts.ps1 +21 -21
  113. package/dist/src/platform/windows/dots-profile.mjs +49 -49
  114. package/dist/src/platform/windows/launch-worker.mjs +41 -41
  115. package/dist/src/platform/windows/network-info.mjs +34 -34
  116. package/dist/src/platform/windows/project-locations.mjs +16 -16
  117. package/dist/src/platform/windows/resident-start.js +20 -20
  118. package/dist/src/platform/windows/resident-start.ps1 +7 -7
  119. package/dist/src/platform/windows/resident-startup.ps1 +83 -83
  120. package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
  121. package/dist/src/platform/windows/runtime-paths.mjs +20 -20
  122. package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
  123. package/dist/src/platform/windows/service-host.mjs +31 -31
  124. package/dist/src/platform/windows/start-hidden-console.ps1 +49 -49
  125. package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
  126. package/dist/src/platform/windows/user-environment.mjs +50 -50
  127. package/dist/src/platform/windows/user-environment.ps1 +41 -41
  128. package/dist/src/project-archive.mjs +30 -0
  129. package/dist/src/project-create.mjs +121 -119
  130. package/dist/src/project-management.mjs +59 -69
  131. package/dist/src/project-remove.mjs +55 -0
  132. package/dist/src/project-update.mjs +56 -0
  133. package/dist/src/runtime-discovery.mjs +47 -47
  134. package/dist/src/self-relay/account-cleanup.mjs +30 -30
  135. package/dist/src/self-relay/account-connections.mjs +52 -52
  136. package/dist/src/self-relay/admin-cloud.mjs +101 -101
  137. package/dist/src/self-relay/admin-page.mjs +80 -80
  138. package/dist/src/self-relay/admin-server.mjs +74 -74
  139. package/dist/src/self-relay/admin-state.mjs +127 -127
  140. package/dist/src/self-relay/admin-style.mjs +14 -14
  141. package/dist/src/self-relay/android-releases.mjs +61 -61
  142. package/dist/src/self-relay/client.mjs +61 -61
  143. package/dist/src/self-relay/connector.mjs +439 -438
  144. package/dist/src/self-relay/debug-allowlist.mjs +33 -33
  145. package/dist/src/self-relay/demo.mjs +37 -37
  146. package/dist/src/self-relay/device-info.mjs +27 -0
  147. package/dist/src/self-relay/device-store.mjs +92 -84
  148. package/dist/src/self-relay/diagnostics.mjs +54 -54
  149. package/dist/src/self-relay/email-accounts.mjs +183 -183
  150. package/dist/src/self-relay/file-wire.mjs +13 -13
  151. package/dist/src/self-relay/lan-authorizations.mjs +71 -42
  152. package/dist/src/self-relay/lifecycle.mjs +264 -250
  153. package/dist/src/self-relay/long-pairing.mjs +40 -40
  154. package/dist/src/self-relay/mysql-state.mjs +118 -105
  155. package/dist/src/self-relay/p2p-probe.mjs +159 -159
  156. package/dist/src/self-relay/privacy-page.mjs +26 -26
  157. package/dist/src/self-relay/public-releases.mjs +34 -0
  158. package/dist/src/self-relay/rtc-file-bridge.mjs +41 -41
  159. package/dist/src/self-relay/server.mjs +1006 -932
  160. package/dist/src/self-relay/usage-daily.mjs +55 -55
  161. package/dist/src/self-relay/usage-meter.mjs +141 -141
  162. package/dist/src/self-relay/windows-route-helper.mjs +75 -75
  163. package/dist/src/self-relay/wire.mjs +36 -36
  164. package/dist/src/server.mjs +1861 -1778
  165. package/dist/src/service-control.mjs +82 -82
  166. package/dist/src/service-doctor.mjs +110 -110
  167. package/dist/src/service-health.mjs +33 -33
  168. package/dist/src/service-install.mjs +91 -91
  169. package/dist/src/service-lifecycle.mjs +138 -138
  170. package/dist/src/service-restart.mjs +81 -81
  171. package/dist/src/shared-app-server.mjs +615 -611
  172. package/dist/src/shared-catalog.mjs +132 -132
  173. package/dist/src/shared-recovery.mjs +146 -146
  174. package/dist/src/shared-thread-stream.mjs +164 -164
  175. package/dist/src/skill-install.mjs +51 -51
  176. package/dist/src/thread-title-generation.mjs +150 -150
  177. package/dist/src/turn-model-history.mjs +47 -47
  178. package/dist/src/usage-reset.mjs +17 -17
  179. package/dist/src/workstation-downloads.mjs +120 -120
  180. package/dist/tools/rtc-route-helper.ps1 +99 -99
  181. package/dist/tools/start-rtc-route-helper.ps1 +15 -15
  182. package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
  183. package/dist/web/vendor/markdown-it.umd.min.js +13 -13
  184. package/package.json +7 -6
  185. package/tools/postinstall.mjs +127 -127
@@ -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,31 +1,31 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import fs from 'node:fs';
6
- import { runtimePaths } from './runtime-paths.mjs';
7
- import { readRecord } from '../../service-lifecycle.mjs';
8
- import { lanNetworks } from './network-info.mjs';
9
-
10
- const exec = promisify(execFile);
11
- const bridgeRoot = fileURLToPath(new URL('../../../', import.meta.url));
12
- async function detect(script) {
13
- const executable = path.join(process.env.SystemRoot, 'System32/WindowsPowerShell/v1.0/powershell.exe');
14
- const { stdout } = await exec(executable, ['-NoProfile', '-NonInteractive', '-File',
15
- path.join(bridgeRoot, script)], { windowsHide: true, encoding: 'utf8' });
16
- return stdout.trim();
17
- }
18
-
19
- // Windows-only network metadata stays here, outside the lifecycle implementation.
20
- export const sharedServiceUrl = () => detect('get-shared-service-url.ps1');
21
- export const lanAddress = async () => (await lanNetworks())[0]?.address || '';
22
- export { lanNetworks };
23
- export async function bridgeEnvironment() {
24
- const environment = { ...process.env };
25
- const installation = readRecord(path.join(runtimePaths(environment).serviceRoot, 'installation.json'));
26
- const executable = installation?.nodeExecutable;
27
- if (!executable || !fs.existsSync(executable)) throw new Error('安装时选用的 Node 不存在,请重新安装 Code Relax。');
28
- environment.CODEX_MCP_NODE_PATH = executable;
29
- delete environment.CODEX_APP_TOOLS_PIPE_PATH;
30
- return { executable, environment };
31
- }
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import fs from 'node:fs';
6
+ import { runtimePaths } from './runtime-paths.mjs';
7
+ import { readRecord } from '../../service-lifecycle.mjs';
8
+ import { lanNetworks } from './network-info.mjs';
9
+
10
+ const exec = promisify(execFile);
11
+ const bridgeRoot = fileURLToPath(new URL('../../../', import.meta.url));
12
+ async function detect(script) {
13
+ const executable = path.join(process.env.SystemRoot, 'System32/WindowsPowerShell/v1.0/powershell.exe');
14
+ const { stdout } = await exec(executable, ['-NoProfile', '-NonInteractive', '-File',
15
+ path.join(bridgeRoot, script)], { windowsHide: true, encoding: 'utf8' });
16
+ return stdout.trim();
17
+ }
18
+
19
+ // Windows-only network metadata stays here, outside the lifecycle implementation.
20
+ export const sharedServiceUrl = () => detect('get-shared-service-url.ps1');
21
+ export const lanAddress = async () => (await lanNetworks())[0]?.address || '';
22
+ export { lanNetworks };
23
+ export async function bridgeEnvironment() {
24
+ const environment = { ...process.env };
25
+ const installation = readRecord(path.join(runtimePaths(environment).serviceRoot, 'installation.json'));
26
+ const executable = installation?.nodeExecutable;
27
+ if (!executable || !fs.existsSync(executable)) throw new Error('安装时选用的 Node 不存在,请重新安装 Code Relax。');
28
+ environment.CODEX_MCP_NODE_PATH = executable;
29
+ delete environment.CODEX_APP_TOOLS_PIPE_PATH;
30
+ return { executable, environment };
31
+ }
@@ -1,49 +1,49 @@
1
- $ErrorActionPreference = 'Stop'
2
- [Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
3
- [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
4
- try {
5
- $spec = [Console]::In.ReadToEnd() | ConvertFrom-Json
6
- # WMI owns this launch, not the caller's kill-on-close Desktop job hierarchy.
7
- $instance = [Guid]::NewGuid().ToString()
8
- $launchRoot = [IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA 'CodexRemote\process-launch'))
9
- New-Item -ItemType Directory -Path $launchRoot -Force | Out-Null
10
- Add-Type -Path (Join-Path $PSScriptRoot 'IsolatedProcess.cs')
11
- $launchRoot = [IsolatedProcess]::ResolvePath($launchRoot)
12
- $ready = Join-Path $launchRoot ($instance + '.json')
13
- $request = Join-Path $launchRoot ($instance + '.request.json')
14
- $diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
15
- $spec | Add-Member -NotePropertyName instance -NotePropertyValue $instance
16
- $spec | Add-Member -NotePropertyName diagnostic -NotePropertyValue $diagnostic
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
- $startup = New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{
21
- ShowWindow=[uint16]0; CreateFlags=[uint32]0x1000010
22
- }
23
- $worker = Join-Path $PSScriptRoot 'launch-worker.mjs'
24
- $command = '"' + [string]$spec.brokerExecutable + '" "' + $worker + '" "' + $request + '" "' + $ready + '" "' + $instance + '" "' + $diagnostic + '"'
25
- $broker = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
26
- CommandLine=$command; CurrentDirectory=$env:USERPROFILE; ProcessStartupInformation=$startup
27
- }
28
- if ($broker.ReturnValue -ne 0) { throw ('Windows process broker failed: ' + $broker.ReturnValue) }
29
- $deadline = [DateTime]::UtcNow.AddSeconds(30)
30
- while (-not (Test-Path -LiteralPath $ready)) {
31
- if ([DateTime]::UtcNow -gt $deadline) {
32
- $detail = if (Test-Path -LiteralPath $diagnostic) { (Get-Content -LiteralPath $diagnostic -Raw -Encoding UTF8).Trim() } else { 'broker did not create a diagnostic log' }
33
- throw ('Windows process broker handoff timed out (broker PID ' + $broker.ProcessId + '): ' + $detail)
34
- }
35
- Start-Sleep -Milliseconds 50
36
- }
37
- $result = Get-Content -LiteralPath $ready -Raw -Encoding UTF8 | ConvertFrom-Json
38
- Remove-Item -LiteralPath $ready
39
- if ($result.instance -ne $instance -or $result.brokerPid -ne $broker.ProcessId) { throw 'Windows process broker identity mismatch.' }
40
- if ($result.error) { throw [string]$result.error }
41
- if (Test-Path -LiteralPath $diagnostic) { Remove-Item -LiteralPath $diagnostic -Force }
42
- [Console]::WriteLine([int]$result.pid)
43
- } catch {
44
- [Console]::Error.WriteLine($_.Exception.Message)
45
- exit 1
46
- } finally {
47
- if ($request -and (Test-Path -LiteralPath $request)) { Remove-Item -LiteralPath $request -Force }
48
- if ($requestTemporary -and (Test-Path -LiteralPath $requestTemporary)) { Remove-Item -LiteralPath $requestTemporary -Force }
49
- }
1
+ $ErrorActionPreference = 'Stop'
2
+ [Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
3
+ [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
4
+ try {
5
+ $spec = [Console]::In.ReadToEnd() | ConvertFrom-Json
6
+ # WMI owns this launch, not the caller's kill-on-close Desktop job hierarchy.
7
+ $instance = [Guid]::NewGuid().ToString()
8
+ $launchRoot = [IO.Path]::GetFullPath((Join-Path $env:LOCALAPPDATA 'CodexRemote\process-launch'))
9
+ New-Item -ItemType Directory -Path $launchRoot -Force | Out-Null
10
+ Add-Type -Path (Join-Path $PSScriptRoot 'IsolatedProcess.cs')
11
+ $launchRoot = [IsolatedProcess]::ResolvePath($launchRoot)
12
+ $ready = Join-Path $launchRoot ($instance + '.json')
13
+ $request = Join-Path $launchRoot ($instance + '.request.json')
14
+ $diagnostic = Join-Path $launchRoot ($instance + '.broker.log')
15
+ $spec | Add-Member -NotePropertyName instance -NotePropertyValue $instance
16
+ $spec | Add-Member -NotePropertyName diagnostic -NotePropertyValue $diagnostic
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
+ $startup = New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{
21
+ ShowWindow=[uint16]0; CreateFlags=[uint32]0x1000010
22
+ }
23
+ $worker = Join-Path $PSScriptRoot 'launch-worker.mjs'
24
+ $command = '"' + [string]$spec.brokerExecutable + '" "' + $worker + '" "' + $request + '" "' + $ready + '" "' + $instance + '" "' + $diagnostic + '"'
25
+ $broker = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
26
+ CommandLine=$command; CurrentDirectory=$env:USERPROFILE; ProcessStartupInformation=$startup
27
+ }
28
+ if ($broker.ReturnValue -ne 0) { throw ('Windows process broker failed: ' + $broker.ReturnValue) }
29
+ $deadline = [DateTime]::UtcNow.AddSeconds(30)
30
+ while (-not (Test-Path -LiteralPath $ready)) {
31
+ if ([DateTime]::UtcNow -gt $deadline) {
32
+ $detail = if (Test-Path -LiteralPath $diagnostic) { (Get-Content -LiteralPath $diagnostic -Raw -Encoding UTF8).Trim() } else { 'broker did not create a diagnostic log' }
33
+ throw ('Windows process broker handoff timed out (broker PID ' + $broker.ProcessId + '): ' + $detail)
34
+ }
35
+ Start-Sleep -Milliseconds 50
36
+ }
37
+ $result = Get-Content -LiteralPath $ready -Raw -Encoding UTF8 | ConvertFrom-Json
38
+ Remove-Item -LiteralPath $ready
39
+ if ($result.instance -ne $instance -or $result.brokerPid -ne $broker.ProcessId) { throw 'Windows process broker identity mismatch.' }
40
+ if ($result.error) { throw [string]$result.error }
41
+ if (Test-Path -LiteralPath $diagnostic) { Remove-Item -LiteralPath $diagnostic -Force }
42
+ [Console]::WriteLine([int]$result.pid)
43
+ } catch {
44
+ [Console]::Error.WriteLine($_.Exception.Message)
45
+ exit 1
46
+ } finally {
47
+ if ($request -and (Test-Path -LiteralPath $request)) { Remove-Item -LiteralPath $request -Force }
48
+ if ($requestTemporary -and (Test-Path -LiteralPath $requestTemporary)) { Remove-Item -LiteralPath $requestTemporary -Force }
49
+ }
@@ -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
+ }