Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript

fix(desktop): preserve Unicode CLI paths on Windows

bingqilinweimaotai6845fd295008
diff --git a/electron/cli-path.cjs b/electron/cli-path.cjs
new file mode 100644
index 0000000..be648da
--- /dev/null
+++ b/electron/cli-path.cjs
@@ -0,0 +1,31 @@
+const fs = require('node:fs')
+const path = require('node:path')
+
+const DEFAULT_WINDOWS_PATHEXT = '.COM;.EXE;.BAT;.CMD'
+
+/** Resolve a command without parsing `where.exe` output. `where` writes paths
+ * in the active Windows code page, which corrupts non-ASCII directories when
+ * Electron decodes stdout as UTF-8. Node's filesystem APIs preserve Unicode. */
+async function findWindowsCommand(bin, envPath, pathExt = process.env.PATHEXT ?? DEFAULT_WINDOWS_PATHEXT) {
+ const extensions = (pathExt || DEFAULT_WINDOWS_PATHEXT)
+ .split(';')
+ .map((ext) => ext.trim())
+ .filter(Boolean)
+ .map((ext) => ext.startsWith('.') ? ext : `.${ext}`)
+ const names = path.extname(bin) ? [bin] : [bin, ...extensions.map((ext) => `${bin}${ext}`)]
+
+ for (const rawDir of envPath.split(path.delimiter)) {
+ const trimmed = rawDir.trim()
+ const dir = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed
+ if (!dir) continue
+ for (const name of names) {
+ const candidate = path.join(dir, name)
+ try {
+ if ((await fs.promises.stat(candidate)).isFile()) return candidate
+ } catch { /* next candidate */ }
+ }
+ }
+ return null
+}
+
+module.exports = { findWindowsCommand }
diff --git a/electron/main.cjs b/electron/main.cjs
index db91307..33bc859 100644
--- a/electron/main.cjs
+++ b/electron/main.cjs
@@ -8,6 +8,7 @@ const http = require('node:http')
const crypto = require('node:crypto')
const { pathToFileURL } = require('node:url')
const autoUpdater = require('./autoUpdater.cjs')
+const { findWindowsCommand } = require('./cli-path.cjs')
const isDev = !app.isPackaged
const DEV_URL = process.env.ELECTRON_RENDERER_URL || 'http://localhost:5180'
@@ -1439,9 +1440,13 @@ function spawnText(cmd, args, envPath) {
}
async function resolveCliPath(bin, envPath) {
- const whichCmd = process.platform === 'win32' ? 'where' : 'which'
- const fromWhich = (await spawnText(whichCmd, [bin], envPath)).split(/\r?\n/)[0]?.trim()
- if (fromWhich) return fromWhich
+ if (process.platform === 'win32') {
+ const fromPath = await findWindowsCommand(bin, envPath ?? process.env.PATH ?? '')
+ if (fromPath) return fromPath
+ } else {
+ const fromWhich = (await spawnText('which', [bin], envPath)).split(/\r?\n/)[0]?.trim()
+ if (fromWhich) return fromWhich
+ }
const home = os.homedir()
const names = process.platform === 'win32' ? [bin, `${bin}.cmd`, `${bin}.exe`] : [bin]
const dirs = [
diff --git a/server/src/__tests__/electron-cli-path.test.ts b/server/src/__tests__/electron-cli-path.test.ts
new file mode 100644
index 0000000..c98df89
--- /dev/null
+++ b/server/src/__tests__/electron-cli-path.test.ts
@@ -0,0 +1,28 @@
+import assert from 'node:assert/strict'
+import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
+import { createRequire } from 'node:module'
+import { tmpdir } from 'node:os'
+import { delimiter, join } from 'node:path'
+import { test } from 'node:test'
+
+const require = createRequire(import.meta.url)
+const { findWindowsCommand } = require('../../../electron/cli-path.cjs') as {
+ findWindowsCommand: (bin: string, envPath: string, pathExt?: string) => Promise<string | null>
+}
+
+test('Windows CLI lookup preserves a Unicode PATH entry', async () => {
+ const root = await mkdtemp(join(tmpdir(), 'cumora-cli-path-'))
+ try {
+ const unicodeDir = join(root, '工具目录')
+ const otherDir = join(root, 'other')
+ await mkdir(unicodeDir)
+ await mkdir(otherDir)
+ const command = join(unicodeDir, 'qwen.CMD')
+ await writeFile(command, '@echo off\r\n')
+
+ const envPath = [otherDir, `"${unicodeDir}"`].join(delimiter)
+ assert.equal(await findWindowsCommand('qwen', envPath, '.CMD;.EXE'), command)
+ } finally {
+ await rm(root, { recursive: true, force: true })
+ }
+})