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: Install and Sign in open their window on Windows (#117)

WEBGRS73b8eb1fdcfe
diff --git a/.changeset/windows-terminal-window.md b/.changeset/windows-terminal-window.md
new file mode 100644
index 0000000..21a5ba6
--- /dev/null
+++ b/.changeset/windows-terminal-window.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+Desktop: on Windows, Install and Sign in open their PowerShell window again; before, the window never appeared and the installer or sign-in never ran.
diff --git a/apps/desktop/src/agents.mjs b/apps/desktop/src/agents.mjs
index 76bf9ca..17e0594 100644
--- a/apps/desktop/src/agents.mjs
+++ b/apps/desktop/src/agents.mjs
@@ -28,7 +28,7 @@ import { execFile, spawn } from 'node:child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { arch, homedir, release, tmpdir } from 'node:os';
import { createRequire } from 'node:module';
-import { dirname, isAbsolute, join } from 'node:path';
+import { dirname, isAbsolute, join, win32 } from 'node:path';
import { Readable, Writable } from 'node:stream';
import { fileURLToPath } from 'node:url';
import * as acp from '@agentclientprotocol/sdk';
@@ -463,6 +463,18 @@ export function powerShellLine(title, line) {
}
const psq = (s) => `'${String(s).replace(/'/g, "''")}'`;
+/**
+ * How a PowerShell window of its own is opened on Windows for a script file: through cmd.exe's `start`, which gives
+ * it a console. Started straight from the app, `detached` makes it a DETACHED_PROCESS with no console at all, and
+ * PowerShell quits at once without running the script.
+ */
+export function powerShellWindowLaunch(file, { comSpec = process.env.ComSpec || 'cmd.exe', systemRoot = process.env.SystemRoot ?? 'C:\\Windows' } = {}) {
+ /* a Windows path wherever it is worked out (the tests run on every system) */
+ const powershell = win32.join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
+ const line = ['start', '""', ...[powershell, '-NoLogo', '-NoExit', '-ExecutionPolicy', 'Bypass', '-File', file].map(winArg)].join(' ');
+ return { cmd: comSpec, args: ['/d', '/s', '/c', `"${line}"`], options: { windowsVerbatimArguments: true, windowsHide: true } };
+}
+
/**
* A PowerShell window of its own running a script (a sign-in, an installer), left open so what it says can be read
* and answered.
@@ -472,10 +484,8 @@ async function powerShellWindow(name, script, env) {
mkdirSync(dir, { recursive: true });
const file = join(dir, name);
writeFileSync(file, script, 'utf8');
- const powershell = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
- const child = spawn(powershell, ['-NoLogo', '-NoExit', '-ExecutionPolicy', 'Bypass', '-File', file], {
- cwd: dir, detached: true, stdio: 'ignore', windowsHide: false, env,
- });
+ const how = powerShellWindowLaunch(file);
+ const child = spawn(how.cmd, how.args, { cwd: dir, detached: true, stdio: 'ignore', env, ...how.options });
await new Promise((done, fail) => { child.once('spawn', done); child.once('error', fail); });
child.unref();
}
diff --git a/apps/desktop/src/agents.test.mjs b/apps/desktop/src/agents.test.mjs
index a505dfe..902dd12 100644
--- a/apps/desktop/src/agents.test.mjs
+++ b/apps/desktop/src/agents.test.mjs
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { AgentSession, CLIENT_CAPABILITIES, agentDefaults, closeEverySession, planProblem, probeFolder, CODEX_UTF8_CMD, agentShell, allowOption, codexDeveloperInstructions, codexLaunchEnv, distinctOptions, errorCause, legacyOptions, powerShellScript, powerShellLine, terminalScript, checkAgentProgram, readAgentStatus, setChosenPaths, signInScript, turnError, signInError, codexTooOld, AGENTS, ownSignIn, codexServiceError, codexRefusal, codexNotice, explainFailure, stderrReason } from './agents.mjs';
+import { AgentSession, CLIENT_CAPABILITIES, agentDefaults, closeEverySession, planProblem, probeFolder, CODEX_UTF8_CMD, agentShell, allowOption, codexDeveloperInstructions, codexLaunchEnv, distinctOptions, errorCause, legacyOptions, powerShellScript, powerShellLine, powerShellWindowLaunch, terminalScript, checkAgentProgram, readAgentStatus, setChosenPaths, signInScript, turnError, signInError, codexTooOld, AGENTS, ownSignIn, codexServiceError, codexRefusal, codexNotice, explainFailure, stderrReason } from './agents.mjs';
test('an agent that asks: yes for good where it offers that, else yes this once; nothing to say yes with is null', () => {
const options = [
@@ -407,6 +407,33 @@ test('an installer runs as its maker wrote it: in Terminal on a Mac, in a PowerS
assert.deepEqual(lines.slice(0, 2), ["$Host.UI.RawUI.WindowTitle = 'Cursor install'", "irm 'https://cursor.com/install?win32=true' | iex"]);
});
+test("a Windows sign-in or installer window is opened through cmd.exe's start, each path whole", () => {
+ const how = powerShellWindowLaunch('C:\\Users\\someone\\AppData\\Local\\Temp\\open film\\qwen.ps1',
+ { comSpec: 'C:\\WINDOWS\\system32\\cmd.exe', systemRoot: 'C:\\WINDOWS' });
+ assert.equal(how.cmd, 'C:\\WINDOWS\\system32\\cmd.exe');
+ assert.deepEqual(how.args, ['/d', '/s', '/c', '"start "" C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoLogo -NoExit '
+ + '-ExecutionPolicy Bypass -File "C:\\Users\\someone\\AppData\\Local\\Temp\\open film\\qwen.ps1""']);
+ assert.deepEqual(how.options, { windowsVerbatimArguments: true, windowsHide: true });
+});
+
+test('on Windows, the window opened for a sign-in or an installer runs its script', async () => {
+ if (process.platform !== 'win32') return;
+ const { spawn } = await import('node:child_process');
+ const { existsSync, mkdtempSync, writeFileSync } = await import('node:fs');
+ const { tmpdir } = await import('node:os');
+ const { join } = await import('node:path');
+ const dir = mkdtempSync(join(tmpdir(), 'of-window '));
+ const mark = join(dir, 'ran.txt');
+ const file = join(dir, 'probe.ps1');
+ /* leaves a mark, then closes its own window */
+ writeFileSync(file, `\ufeffSet-Content -LiteralPath '${mark.replace(/'/g, "''")}' -Value ran\r\n[Environment]::Exit(0)\r\n`, 'utf8');
+ const how = powerShellWindowLaunch(file);
+ const child = spawn(how.cmd, how.args, { cwd: dir, detached: true, stdio: 'ignore', ...how.options });
+ child.unref();
+ for (let i = 0; i < 100 && !existsSync(mark); i += 1) await new Promise((r) => setTimeout(r, 100));
+ assert.ok(existsSync(mark), 'the script ran');
+});
+
test('a program chosen that is an editor, or not Cursor\'s own agent, is refused without being started', async () => {
if (process.platform === 'win32') return;
const { mkdtempSync, mkdirSync, writeFileSync } = await import('node:fs');