The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve injected Python through PowerShell 5.1 native argv
Luo, Yiliangbe3b57d57b22
diff --git a/apps/desktop/electron/windows-remote-inventory.test.ts b/apps/desktop/electron/windows-remote-inventory.test.tsindex 657ce27dc2d..5ea50d6fa91 100644--- a/apps/desktop/electron/windows-remote-inventory.test.ts+++ b/apps/desktop/electron/windows-remote-inventory.test.ts@@ -34,6 +34,21 @@ test('the canonical runtime prefix is actually executed, including bootstrap andassert.throws(() => windowsRuntimeProgramArgv({ ...runtime, runtimeCommand: [python, '-c', 'print(0)'] }, 'pass'), (e: any) => e.kind === 'update-required')})+test('injected Python program survives the observed PowerShell 5.1 double-quote loss', () => {+ const program = `import json; print(json.dumps({'marker': '用户/quote"path'}, ensure_ascii=False))`+ const argv = windowsRuntimeProgramArgv(selected, program)+ const tail = argv.at(-1)!++ assert.match(tail, /exec\(bytes\.fromhex\('[0-9a-f]+'\)\.decode\('utf-8'\)\)$/)+ assert.equal(tail.startsWith(bootstrap.split('runpy.run_module')[0]), true)+ // The transport failure was observed on real Windows by Polaris; this is its loss-channel regression,+ // not a claim to execute PowerShell 5.1 on a Mac.+ const result = spawnSync(argv[0], [...argv.slice(1, -1), tail.replace(/"/g, '')], { encoding: 'utf8' })++ assert.equal(result.status, 0, result.stderr)+ assert.deepEqual(JSON.parse(result.stdout), { marker: '用户/quote"path' })+})+test('PATH bin launcher is resolved independently of its absent sibling Python, after the marker gate', async () => {const calls: string[] = []diff --git a/apps/desktop/electron/windows-runtime-command.ts b/apps/desktop/electron/windows-runtime-command.tsindex 7dbe00970a7..478daaa86a3 100644--- a/apps/desktop/electron/windows-runtime-command.ts+++ b/apps/desktop/electron/windows-runtime-command.ts@@ -16,7 +16,10 @@ export function windowsRuntimeProgramArgv(runtime: WindowsRuntime, program: striconst entry = /runpy\.run_module\((['"])hermes_cli\.main\1,\s*run_name=(['"])__main__\2,\s*alter_sys=True\)\s*$/if (codeIndex >= 1 && codeIndex === command.length - 2 && entry.test(command[codeIndex + 1])) {- command[codeIndex + 1] = command[codeIndex + 1].replace(entry, () => `exec(${JSON.stringify(program)})`)+ // PowerShell 5.1 strips embedded double quotes when forming native argv.+ // ASCII hex carries the program losslessly without changing the launcher bootstrap.+ const encodedProgram = Buffer.from(program, 'utf8').toString('hex')+ command[codeIndex + 1] = command[codeIndex + 1].replace(entry, () => `exec(bytes.fromhex('${encodedProgram}').decode('utf-8'))`)return command}