Skip to content

The agent that grows with you

fix(desktop): preserve Windows SSH probe input encoding

thegreatesthoneybee25d7de6fadf9
diff --git a/apps/desktop/electron/windows-remote-lifecycle.test.ts b/apps/desktop/electron/windows-remote-lifecycle.test.ts
index a6a3bed83e9..64eaefc9c75 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.test.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.test.ts
@@ -136,7 +136,11 @@ type SshExecOptions = { stdinData?: string | Buffer }
function scriptFromInvocation(command: string, options: SshExecOptions = {}) {
const encoded = command.match(/-EncodedCommand\s+([^\s]+)$/)?.[1]
- return encoded ? Buffer.from(encoded, 'base64').toString('utf16le') : String(options.stdinData || '')
+ if (encoded) {
+ return Buffer.from(encoded, 'base64').toString('utf16le')
+ }
+
+ return Buffer.from(String(options.stdinData || '').trim(), 'base64').toString('utf16le')
}
test('PowerShell transport uses UTF-16LE encoded commands and literal escaping', () => {
@@ -329,18 +333,9 @@ test('Windows probe validates Hermes and Python topology before selection', asyn
assert.ok(pythonCheck < output)
})
-import { mkdtemp, readFile, rm } from 'node:fs/promises'
-import os from 'node:os'
-import path from 'node:path'
-import { promisify } from 'node:util'
- }
-})
-
-import { spawn } from 'node:child_process'
-import fs from 'node:fs'
-import os from 'node:os'
-import path from 'node:path'
- }
+import { exec as execCallback, spawn } from 'node:child_process'
+import crypto from 'node:crypto'
+import { mkdtemp, readFile, rm } from 'node:fs/promises' }
})
test('platform detection preserves POSIX and falls back to Windows PowerShell', async () => {
diff --git a/apps/desktop/electron/windows-remote-lifecycle.ts b/apps/desktop/electron/windows-remote-lifecycle.ts
index 4d3b023e5c5..2f70cdfaf1c 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.ts
@@ -40,7 +40,7 @@ function stripPowerShellNoise(stdout) {
// command shell is commonly cmd.exe, whose command-line limit is 8191 chars.
// SshConnection.exec already supports streaming stdin to the remote command.
function powerShellStdinCommand() {
- return 'powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command [ScriptBlock]::Create([Console]::In.ReadToEnd()).Invoke()'
+ return 'powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command [ScriptBlock]::Create([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String([Console]::In.ReadToEnd()))).Invoke()'
}
}
@@ -102,9 +102,8 @@ async function probeWindowsRemote(ssh, explicitHermesPath = '') {
// (module auto-load racing the exec read). stripPowerShellNoise drops every
// block; the JSON is the last meaningful line.
const lines = stripPowerShellNoise(
- await ssh.exec(powerShellStdinCommand(), { stdinData: `${script}\r\n` })
+ await ssh.exec(powerShellStdinCommand(), { stdinData: `${encodedPowerShell(script)}\r\n` })
)
-
const parsed = JSON.parse(lines[lines.length - 1] || 'null')
if (!parsed?.os || !parsed?.arch) {