feat(coding-agent): add startup profiling scripts for tui/rpc (#2497)
This commit is contained in:
@@ -754,6 +754,11 @@ export async function main(args: string[]) {
|
||||
stdinContent,
|
||||
);
|
||||
const isInteractive = !parsed.print && parsed.mode === undefined;
|
||||
const startupBenchmark = isTruthyEnvFlag(process.env.PI_STARTUP_BENCHMARK);
|
||||
if (startupBenchmark && !isInteractive) {
|
||||
console.error(chalk.red("Error: PI_STARTUP_BENCHMARK only supports interactive mode"));
|
||||
process.exit(1);
|
||||
}
|
||||
const mode = parsed.mode || "text";
|
||||
initTheme(settingsManager.getTheme(), isInteractive);
|
||||
|
||||
@@ -848,8 +853,7 @@ export async function main(args: string[]) {
|
||||
console.log(chalk.dim(`Model scope: ${modelList} ${chalk.gray("(Ctrl+P to cycle)")}`));
|
||||
}
|
||||
|
||||
printTimings();
|
||||
const mode = new InteractiveMode(session, {
|
||||
const interactiveMode = new InteractiveMode(session, {
|
||||
migratedProviders,
|
||||
modelFallbackMessage,
|
||||
initialMessage,
|
||||
@@ -857,7 +861,21 @@ export async function main(args: string[]) {
|
||||
initialMessages: parsed.messages,
|
||||
verbose: parsed.verbose,
|
||||
});
|
||||
await mode.run();
|
||||
if (startupBenchmark) {
|
||||
await interactiveMode.init();
|
||||
interactiveMode.stop();
|
||||
stopThemeWatcher();
|
||||
if (process.stdout.writableLength > 0) {
|
||||
await new Promise<void>((resolve) => process.stdout.once("drain", resolve));
|
||||
}
|
||||
if (process.stderr.writableLength > 0) {
|
||||
await new Promise<void>((resolve) => process.stderr.once("drain", resolve));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
printTimings();
|
||||
await interactiveMode.run();
|
||||
} else {
|
||||
await runPrintMode(session, {
|
||||
mode,
|
||||
|
||||
@@ -596,9 +596,7 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
||||
*/
|
||||
let detachInput = () => {};
|
||||
|
||||
async function checkShutdownRequested(): Promise<void> {
|
||||
if (!shutdownRequested) return;
|
||||
|
||||
async function shutdown(): Promise<never> {
|
||||
const currentRunner = session.extensionRunner;
|
||||
if (currentRunner?.hasHandlers("session_shutdown")) {
|
||||
await currentRunner.emit({ type: "session_shutdown" });
|
||||
@@ -609,6 +607,11 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function checkShutdownRequested(): Promise<void> {
|
||||
if (!shutdownRequested) return;
|
||||
await shutdown();
|
||||
}
|
||||
|
||||
const handleInputLine = async (line: string) => {
|
||||
try {
|
||||
const parsed = JSON.parse(line);
|
||||
@@ -636,9 +639,20 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
||||
}
|
||||
};
|
||||
|
||||
detachInput = attachJsonlLineReader(process.stdin, (line) => {
|
||||
void handleInputLine(line);
|
||||
});
|
||||
const onInputEnd = () => {
|
||||
void shutdown();
|
||||
};
|
||||
process.stdin.on("end", onInputEnd);
|
||||
|
||||
detachInput = (() => {
|
||||
const detachJsonl = attachJsonlLineReader(process.stdin, (line) => {
|
||||
void handleInputLine(line);
|
||||
});
|
||||
return () => {
|
||||
detachJsonl();
|
||||
process.stdin.off("end", onInputEnd);
|
||||
};
|
||||
})();
|
||||
|
||||
// Keep process alive forever
|
||||
return new Promise(() => {});
|
||||
|
||||
Reference in New Issue
Block a user