mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
Support context injection via SessionStart hook. (#15746)
This commit is contained in:
committed by
GitHub
parent
2da911e4a0
commit
6d1e27633a
@@ -300,7 +300,31 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||
const sessionStartSource = resumedSessionData
|
||||
? SessionStartSource.Resume
|
||||
: SessionStartSource.Startup;
|
||||
await fireSessionStartHook(hookMessageBus, sessionStartSource);
|
||||
const result = await fireSessionStartHook(
|
||||
hookMessageBus,
|
||||
sessionStartSource,
|
||||
);
|
||||
|
||||
if (result) {
|
||||
if (result.systemMessage) {
|
||||
historyManager.addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: result.systemMessage,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
}
|
||||
|
||||
const additionalContext = result.getAdditionalContext();
|
||||
const geminiClient = config.getGeminiClient();
|
||||
if (additionalContext && geminiClient) {
|
||||
await geminiClient.addHistory({
|
||||
role: 'user',
|
||||
parts: [{ text: additionalContext }],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fire-and-forget: generate summary for previous session in background
|
||||
@@ -321,6 +345,12 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||
await fireSessionEndHook(hookMessageBus, SessionEndReason.Exit);
|
||||
}
|
||||
});
|
||||
// Disable the dependencies check here. historyManager gets flagged
|
||||
// but we don't want to react to changes to it because each new history
|
||||
// item, including the ones from the start session hook will cause a
|
||||
// re-render and an error when we try to reload config.
|
||||
//
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [config, resumedSessionData]);
|
||||
|
||||
useEffect(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type { DefaultHookOutput } from '@google/gemini-cli-core';
|
||||
import {
|
||||
uiTelemetryService,
|
||||
fireSessionEndHook,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { SlashCommand } from './types.js';
|
||||
import { CommandKind } from './types.js';
|
||||
import { MessageType } from '../types.js';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
export const clearCommand: SlashCommand = {
|
||||
@@ -52,8 +54,9 @@ export const clearCommand: SlashCommand = {
|
||||
}
|
||||
|
||||
// Fire SessionStart hook after clearing
|
||||
let result: DefaultHookOutput | undefined;
|
||||
if (config?.getEnableHooks() && messageBus) {
|
||||
await fireSessionStartHook(messageBus, SessionStartSource.Clear);
|
||||
result = await fireSessionStartHook(messageBus, SessionStartSource.Clear);
|
||||
}
|
||||
|
||||
// Give the event loop a chance to process any pending telemetry operations
|
||||
@@ -68,5 +71,15 @@ export const clearCommand: SlashCommand = {
|
||||
|
||||
uiTelemetryService.setLastPromptTokenCount(0);
|
||||
context.ui.clear();
|
||||
|
||||
if (result?.systemMessage) {
|
||||
context.ui.addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: result.systemMessage,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user