Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop: read the registry's PATH as UTF-8, so folders named in Chinese are found (#204)

WEBGRS1d5b497d8dcd
diff --git a/.changeset/registry-path-encoding.md b/.changeset/registry-path-encoding.md
new file mode 100644
index 0000000..3e954af
--- /dev/null
+++ b/.changeset/registry-path-encoding.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+Windows: folders with Chinese (or other non-English) names on the PATH, and the other variables Windows keeps for the person, reach the agents as they are. On a Chinese Windows they came out garbled (`E:\软件安装` read as `E:\������װ`), so an agent installed into such a folder while the app ran was not found, and "Why isn't it found?" listed the garbled folder.
diff --git a/apps/desktop/src/environment.mjs b/apps/desktop/src/environment.mjs
index b90880c..1f5e9ab 100644
--- a/apps/desktop/src/environment.mjs
+++ b/apps/desktop/src/environment.mjs
@@ -190,10 +190,15 @@ export function windowsFreshPath({ machine = {}, user = {}, source = process.env
const REG_MACHINE = 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment';
const REG_USER = 'HKCU\\Environment';
-function regQuery(key, timeoutMs, types = undefined) {
+/**
+ * `reg query <key>`, read (parseRegQuery). reg writes in its console's code page, GBK on a Chinese Windows, where a
+ * folder named in Chinese came out as `E:\������װ`: the console is switched to UTF-8 first.
+ */
+export function regQuery(key, timeoutMs, types = undefined) {
return new Promise((resolve) => {
- const reg = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'reg.exe');
- execFile(reg, ['query', key], { timeout: timeoutMs, encoding: 'utf8', windowsHide: true }, (error, stdout) => {
+ const system = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32');
+ const command = `chcp 65001 >nul && "${join(system, 'reg.exe')}" query "${key}"`;
+ execFile(join(system, 'cmd.exe'), ['/d', '/s', '/c', command], { timeout: timeoutMs, encoding: 'utf8', windowsHide: true, windowsVerbatimArguments: true }, (error, stdout) => {
if (error) return resolve(null);
const expandable = new Set();
resolve({ values: parseRegQuery(stdout, expandable, types), expandable });
diff --git a/apps/desktop/src/environment.test.mjs b/apps/desktop/src/environment.test.mjs
index 26e802d..80a360a 100644
--- a/apps/desktop/src/environment.test.mjs
+++ b/apps/desktop/src/environment.test.mjs
@@ -4,7 +4,7 @@ import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import {
childEnvironment, environmentCache, expandWindowsVars, lastPathSource, loginShellVariables, macProxy, noProxyList, parseRegQuery,
- parseScutilProxy, proxyVariables, registryVariables, shellSubset, shellVariables, windowsFreshPath, windowsProxy, withSystemProxy,
+ parseScutilProxy, proxyVariables, regQuery, registryVariables, shellSubset, shellVariables, windowsFreshPath, windowsProxy, withSystemProxy,
} from './environment.mjs';
const PROFILE = ['C:', 'Users', 'someone'].join('\\');
@@ -87,6 +87,20 @@ test("on Windows, an agent given this machine's registry environment starts cmd.
assert.equal(r.stdout.trim(), 'ok');
});
+test("on Windows, a registry value naming folders in Chinese reads as it is, whatever the console's code page", { skip: process.platform !== 'win32' }, async () => {
+ const key = `HKCU\\Software\\OpenFilm test ${process.pid}`;
+ const path = 'E:\\软件安装;D:\\工具\\bin;C:\\plain';
+ const reg = (...args) => spawnSync('reg.exe', args, { windowsHide: true });
+ assert.equal(reg('add', key, '/v', 'Path', '/t', 'REG_EXPAND_SZ', '/d', path, '/f').status, 0);
+ try {
+ const read = await regQuery(key, 10_000);
+ assert.equal(read?.values.Path, path);
+ assert.ok(read?.expandable.has('Path'));
+ } finally {
+ reg('delete', key, '/f');
+ }
+});
+
test('the environment is read again once it is old, sooner when asked; a failed read keeps the last good one', async () => {
let clock = 0;
const reads = [];