qwen-code/scripts/cli-entry.js
jinye cf9be3bd81
perf(cli): skip spawnSync wrapper for qwen serve (#5874)
The daemon host process does not need --expose-gc (global.gc() is only
used by memoryPressureMonitor inside ACP children, which independently
add --expose-gc via spawnChannel.ts). Detect `serve` as the first
positional arg and import cli.js directly in-process, eliminating one
full Node process startup (~370ms on EDR-instrumented hosts).

Use pathToFileURL() for the dynamic import so Windows drive-letter
paths are not misinterpreted as URL schemes.
2026-06-25 23:59:07 +00:00

48 lines
1.3 KiB
JavaScript
Executable file

#!/usr/bin/env node
/**
* @license
* Copyright 2025 Qwen Code
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Production bin entry wrapper.
*
* For most commands: launches dist/cli.js with --expose-gc so that
* global.gc() is available for the memory-pressure monitor's critical-tier
* cleanup.
*
* For `qwen serve`: imports cli.js directly in-process, skipping the
* spawnSync overhead (~370ms on EDR-instrumented hosts). The daemon host
* process never calls global.gc() — only its ACP children do, and they
* independently add --expose-gc via spawnChannel.ts.
*/
import { spawnSync } from 'node:child_process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const cliPath = join(__dirname, '..', 'dist', 'cli.js');
function isServeCommand() {
return process.argv[2] === 'serve';
}
if (isServeCommand()) {
process.argv[1] = cliPath;
await import(pathToFileURL(cliPath).href);
} else {
const result = spawnSync(
process.execPath,
['--expose-gc', cliPath, ...process.argv.slice(2)],
{ stdio: 'inherit' },
);
if (result.signal) {
process.kill(process.pid, result.signal);
} else {
process.exit(result.status ?? 1);
}
}