fix(coding-agent): add session_shutdown reasons closes #2863

This commit is contained in:
Mario Zechner
2026-04-20 23:10:49 +02:00
parent 1891b9ac01
commit 12d7161884
10 changed files with 75 additions and 30 deletions

View File

@@ -45,6 +45,7 @@ import type {
SessionBeforeForkResult,
SessionBeforeSwitchResult,
SessionBeforeTreeResult,
SessionShutdownEvent,
ToolCallEvent,
ToolCallEventResult,
ToolResultEvent,
@@ -168,11 +169,12 @@ export type ShutdownHandler = () => void;
* Helper function to emit session_shutdown event to extensions.
* Returns true if the event was emitted, false if there were no handlers.
*/
export async function emitSessionShutdownEvent(extensionRunner: ExtensionRunner): Promise<boolean> {
export async function emitSessionShutdownEvent(
extensionRunner: ExtensionRunner,
event: SessionShutdownEvent,
): Promise<boolean> {
if (extensionRunner.hasHandlers("session_shutdown")) {
await extensionRunner.emit({
type: "session_shutdown",
});
await extensionRunner.emit(event);
return true;
}
return false;

View File

@@ -512,9 +512,12 @@ export interface SessionCompactEvent {
fromExtension: boolean;
}
/** Fired on graceful process shutdown paths such as Ctrl+C, Ctrl+D, SIGHUP, and SIGTERM. */
/** Fired before an extension runtime is torn down due to quit, reload, or session replacement. */
export interface SessionShutdownEvent {
type: "session_shutdown";
reason: "quit" | "reload" | "new" | "resume" | "fork";
/** Destination session file when shutting down due to session replacement. */
targetSessionFile?: string;
}
/** Preparation data for tree navigation */