Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/codex-hook-trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export async function detectCodexHookTrustState(codexHome, cwd, timeoutMs = 1000
const child = spawn('codex', ['app-server'], {
env: { ...process.env, CODEX_HOME: codexHome },
stdio: ['pipe', 'pipe', 'ignore'],
windowsHide: true,
});
const rl = readline.createInterface({ input: child.stdout });
const pending = new Map();
Expand Down
6 changes: 4 additions & 2 deletions dist/summarizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ function readCommandOutput(command, args) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
env: getApiEnv(),
stdio: ['ignore', 'pipe', 'pipe']
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true
});
let output = '';
child.stdout.on('data', chunk => {
Expand Down Expand Up @@ -444,7 +445,8 @@ export async function runCodexCommand(command) {
return new Promise((resolve, reject) => {
const child = spawn(command.command, command.args, {
env: getApiEnv(),
stdio: ['pipe', 'pipe', 'pipe']
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true
});
let stderr = '';
let answer = '';
Expand Down
1 change: 1 addition & 0 deletions dist/sync-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ if (isBackground) {
...filteredArgs
], {
detached: true,
windowsHide: true,
stdio: ['ignore', logFd, logFd]
});
child.unref(); // Allow parent to exit
Expand Down
1 change: 1 addition & 0 deletions src/codex-hook-trust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function detectCodexHookTrustState(
const child = spawn('codex', ['app-server'], {
env: { ...process.env, CODEX_HOME: codexHome },
stdio: ['pipe', 'pipe', 'ignore'],
windowsHide: true,
});
const rl = readline.createInterface({ input: child.stdout });
const pending = new Map<number, {
Expand Down
6 changes: 4 additions & 2 deletions src/summarizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ function readCommandOutput(command: string, args: string[]): Promise<string> {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
env: getApiEnv(),
stdio: ['ignore', 'pipe', 'pipe']
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true
});
let output = '';

Expand Down Expand Up @@ -511,7 +512,8 @@ export async function runCodexCommand(command: CodexSummarizerCommand): Promise<
return new Promise((resolve, reject) => {
const child = spawn(command.command, command.args, {
env: getApiEnv(),
stdio: ['pipe', 'pipe', 'pipe']
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true
});

let stderr = '';
Expand Down
1 change: 1 addition & 0 deletions src/sync-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ if (isBackground) {
...filteredArgs
], {
detached: true,
windowsHide: true,
stdio: ['ignore', logFd, logFd]
});

Expand Down
48 changes: 48 additions & 0 deletions test/spawn-windows-hide.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, it, expect } from 'vitest';
import { readdirSync, readFileSync } from 'fs';
import { join } from 'path';

// On Windows, a console program started from a process with no console of its
// own (the detached background sync, the summarizer it runs) gets a brand-new
// console window unless the spawn passes `windowsHide: true`. Users saw a
// terminal window flash for every background sync and every `codex app-server`
// summarizer call. Every spawn in src/ must hide its window.
const SRC_DIR = join(__dirname, '..', 'src');

function spawnCallOptions(source: string): string[] {
const calls: string[] = [];
const pattern = /\bspawn\(/g;
let match: RegExpExecArray | null;
while ((match = pattern.exec(source)) !== null) {
let depth = 0;
let end = match.index + match[0].length - 1;
for (; end < source.length; end++) {
const ch = source[end];
if (ch === '(') depth++;
else if (ch === ')') {
depth--;
if (depth === 0) break;
}
}
calls.push(source.slice(match.index, end + 1));
}
return calls;
}

describe('child processes hide their console window on Windows', () => {
const files = readdirSync(SRC_DIR).filter(name => name.endsWith('.ts'));
const calls = files.flatMap(name =>
spawnCallOptions(readFileSync(join(SRC_DIR, name), 'utf8')).map(call => ({ name, call }))
);

it('finds the spawn calls it checks', () => {
expect(calls.length).toBeGreaterThanOrEqual(4);
});

it.each(calls.map(({ name, call }) => [name, call.split('\n')[0], call]))(
'%s: %s',
(_name, _firstLine, call) => {
expect(call).toMatch(/windowsHide:\s*true/);
}
);
});