consortium
Version:
Remote control and session sharing CLI for AI coding agents
52 lines (44 loc) • 1.59 kB
JavaScript
import { execFileSync } from 'child_process';
import { fileURLToPath } from 'url';
import { join, dirname } from 'path';
// Filter env vars to avoid leaking secrets to the bridge subprocess
const ENV_ALLOWLIST = new Set([
'PATH', 'HOME', 'USER', 'SHELL', 'TERM', 'LANG', 'LC_ALL', 'NODE_ENV',
'OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_MODEL', 'OPENAI_ORG_ID',
'CONSORTIUM_HTTP_MCP_URL',
]);
const ENV_PREFIX_ALLOWLIST = ['CODEX_'];
function filterEnv(env) {
const filtered = {};
for (const key of Object.keys(env)) {
if (typeof env[key] !== 'string') continue;
if (ENV_ALLOWLIST.has(key) || ENV_PREFIX_ALLOWLIST.some(p => key.startsWith(p))) {
filtered[key] = env[key];
}
}
return filtered;
}
// Ensure Node flags to reduce noisy warnings on stdout (which could interfere with MCP)
const hasNoWarnings = process.execArgv.includes('--no-warnings');
const hasNoDeprecation = process.execArgv.includes('--no-deprecation');
if (!hasNoWarnings || !hasNoDeprecation) {
const projectRoot = dirname(dirname(fileURLToPath(import.meta.url)));
const entrypoint = join(projectRoot, 'dist', 'codex', 'consortiumMcpStdioBridge.mjs');
try {
execFileSync(process.execPath, [
'--no-warnings',
'--no-deprecation',
entrypoint,
...process.argv.slice(2)
], {
stdio: 'inherit',
env: filterEnv(process.env)
});
} catch (error) {
process.exit(error.status || 1);
}
} else {
// Already have desired flags; import module directly
import('../dist/codex/consortiumMcpStdioBridge.mjs');
}