implementation SessionStart and SessionEnd hook

This commit is contained in:
DennisYu07 2026-03-03 23:39:57 -08:00
parent 7cde98e238
commit f0cc28f80f
11 changed files with 2099 additions and 7 deletions

View file

@ -14,6 +14,12 @@ import type { HookRegistryEntry } from './hookRegistry.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import type { DefaultHookOutput } from './types.js';
import { createHookOutput } from './types.js';
import type {
SessionStartSource,
SessionEndReason,
PermissionMode,
AgentType,
} from './types.js';
const debugLogger = createDebugLogger('TRUSTED_HOOKS');
@ -100,4 +106,30 @@ export class HookSystem {
? createHookOutput('Stop', result.finalOutput)
: undefined;
}
async fireSessionStartEvent(
source: SessionStartSource,
model: string,
permissionMode?: PermissionMode,
agentType?: AgentType,
): Promise<DefaultHookOutput | undefined> {
const result = await this.hookEventHandler.fireSessionStartEvent(
source,
model,
permissionMode,
agentType,
);
return result.finalOutput
? createHookOutput('SessionStart', result.finalOutput)
: undefined;
}
async fireSessionEndEvent(
reason: SessionEndReason,
): Promise<DefaultHookOutput | undefined> {
const result = await this.hookEventHandler.fireSessionEndEvent(reason);
return result.finalOutput
? createHookOutput('SessionEnd', result.finalOutput)
: undefined;
}
}