feat(coding-agent): add startup profiling scripts for tui/rpc (#2497)

This commit is contained in:
Duncan Ogilvie
2026-03-21 20:46:00 +01:00
committed by GitHub
parent f90647ea8e
commit 80f527ec22
5 changed files with 594 additions and 9 deletions

View File

@@ -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(() => {});