fix return type of fireSessionStartEvent to defaultHookOutput (#16833)

This commit is contained in:
Vedant Mahajan
2026-01-20 08:55:43 +05:30
committed by GitHub
parent 05c0a8eac3
commit 155d9aafe2
4 changed files with 32 additions and 23 deletions

View File

@@ -648,18 +648,22 @@ export async function main() {
const sessionStartSource = resumedSessionData
? SessionStartSource.Resume
: SessionStartSource.Startup;
const result = await config
.getHookSystem()
?.fireSessionStartEvent(sessionStartSource);
if (result?.finalOutput) {
if (result.finalOutput.systemMessage) {
writeToStderr(result.finalOutput.systemMessage + '\n');
}
const additionalContext = result.finalOutput.getAdditionalContext();
if (additionalContext) {
// Prepend context to input (System Context -> Stdin -> Question)
input = input ? `${additionalContext}\n\n${input}` : additionalContext;
const hookSystem = config?.getHookSystem();
if (hookSystem) {
const result = await hookSystem.fireSessionStartEvent(sessionStartSource);
if (result) {
if (result.systemMessage) {
writeToStderr(result.systemMessage + '\n');
}
const additionalContext = result.getAdditionalContext();
if (additionalContext) {
// Prepend context to input (System Context -> Stdin -> Question)
input = input
? `${additionalContext}\n\n${input}`
: additionalContext;
}
}
}

View File

@@ -300,18 +300,18 @@ export const AppContainer = (props: AppContainerProps) => {
.getHookSystem()
?.fireSessionStartEvent(sessionStartSource);
if (result?.finalOutput) {
if (result.finalOutput?.systemMessage) {
if (result) {
if (result.systemMessage) {
historyManager.addItem(
{
type: MessageType.INFO,
text: result.finalOutput.systemMessage,
text: result.systemMessage,
},
Date.now(),
);
}
const additionalContext = result.finalOutput.getAdditionalContext();
const additionalContext = result.getAdditionalContext();
const geminiClient = config.getGeminiClient();
if (additionalContext && geminiClient) {
await geminiClient.addHistory({

View File

@@ -29,7 +29,10 @@ export const clearCommand: SlashCommand = {
.getChatRecordingService();
// Fire SessionEnd hook before clearing
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);
const hookSystem = config?.getHookSystem();
if (hookSystem) {
await hookSystem.fireSessionEndEvent(SessionEndReason.Clear);
}
if (geminiClient) {
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
@@ -48,9 +51,10 @@ export const clearCommand: SlashCommand = {
}
// Fire SessionStart hook after clearing
const result = await config
?.getHookSystem()
?.fireSessionStartEvent(SessionStartSource.Clear);
let result;
if (hookSystem) {
result = await hookSystem.fireSessionStartEvent(SessionStartSource.Clear);
}
// Give the event loop a chance to process any pending telemetry operations
// This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor
@@ -65,11 +69,11 @@ export const clearCommand: SlashCommand = {
uiTelemetryService.setLastPromptTokenCount(0);
context.ui.clear();
if (result?.finalOutput?.systemMessage) {
if (result?.systemMessage) {
context.ui.addItem(
{
type: MessageType.INFO,
text: result.finalOutput.systemMessage,
text: result.systemMessage,
},
Date.now(),
);

View File

@@ -94,11 +94,12 @@ export class HookSystem {
*/
async fireSessionStartEvent(
source: SessionStartSource,
): Promise<AggregatedHookResult | undefined> {
): Promise<DefaultHookOutput | undefined> {
if (!this.config.getEnableHooks()) {
return undefined;
}
return this.hookEventHandler.fireSessionStartEvent(source);
const result = await this.hookEventHandler.fireSessionStartEvent(source);
return result.finalOutput;
}
async fireSessionEndEvent(