fix(terminal): unset NODE_CHANNEL_FD for PTY shells on every POSIX host
The PTY runtime exported an empty NODE_CHANNEL_FD to override the daemon's IPC descriptor, because bun-pty merges the native environ back into the child and a JS-only delete does not stick. Node CLIs launched from the shell (opencode, claude) then printed "warn: Failed to parse IPC channel number ''" on exit. The Linux-only env -u ARGV0 wrapper now applies on macOS and Linux and also unsets NODE_CHANNEL_FD, so the variable is gone instead of empty. Testing: runtime and inherited-env tests updated for the POSIX wrapper; verified in the running app that exiting opencode no longer prints the warning.
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
import { sanitizeTerminalHistoryChunk } from './history.js';
|
||||
import { consumeTerminalThemeQueries, terminalThemeModeReport } from './theme-response.js';
|
||||
import { buildTerminalShellLaunch, createTerminalShellResolver, normalizeTerminalShell } from './shells.js';
|
||||
import { stripAppImageArgv0Leak, resolveLinuxPtyLaunch } from '../inherited-env.js';
|
||||
import { stripAppImageArgv0Leak, resolvePosixPtyLaunch } from '../inherited-env.js';
|
||||
|
||||
const MAX_SESSIONS = 20;
|
||||
const MAX_HISTORY_BYTES = 512 * 1024;
|
||||
@@ -123,15 +123,16 @@ export function createTerminalRuntime({
|
||||
for (const executable of resolvedShell.executables) {
|
||||
try {
|
||||
const env = { ...process.env, PATH: buildAugmentedPath(), TERM: 'xterm-256color', COLORTERM: 'truecolor', COLORFGBG: themeMode === 'light' ? '0;15' : '15;0' };
|
||||
// The daemon's IPC fd is closed inside the PTY. An explicit override is
|
||||
// required because bun-pty also inherits Bun's native process environment.
|
||||
env.NODE_CHANNEL_FD = '';
|
||||
// The daemon's IPC fd is closed inside the PTY; an inherited NODE_CHANNEL_FD
|
||||
// (even an empty one) makes Node CLIs warn about an unparsable IPC channel.
|
||||
delete env.NODE_CHANNEL_FD;
|
||||
delete env.BASH_XTRACEFD; delete env.BASH_ENV; delete env.ENV; delete env.ELECTRON_RUN_AS_NODE;
|
||||
// AppImage exports ARGV0; zsh would otherwise rewrite argv[0] for every command (#2588).
|
||||
// bun-pty also merges the native OS environ, so wrap with `env -u ARGV0` on Linux.
|
||||
stripAppImageArgv0Leak(env);
|
||||
const shellLaunch = buildTerminalShellLaunch(executable, { mode, command, loginShell });
|
||||
const launch = resolveLinuxPtyLaunch(shellLaunch.executable, shellLaunch.args);
|
||||
// bun-pty merges the native OS environ back in, so the POSIX launch is
|
||||
// wrapped with `env -u` for the variables deleted above.
|
||||
const launch = resolvePosixPtyLaunch(shellLaunch.executable, shellLaunch.args);
|
||||
const options = { name: 'xterm-256color', cwd, cols, rows, env };
|
||||
if (process.platform === 'win32') options.useConpty = true;
|
||||
return { process: await provider.spawn(launch.executable, launch.args, options), backend: provider.backend, shell: resolvedShell.id, loginShell };
|
||||
|
||||
Reference in New Issue
Block a user