mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-11 18:40:57 -07:00
Support context injection via SessionStart hook. (#15746)
This commit is contained in:
committed by
GitHub
parent
4f26766dd1
commit
4581b1869f
@@ -634,6 +634,16 @@ export async function main() {
|
||||
await config.initialize();
|
||||
startupProfiler.flush(config);
|
||||
|
||||
// If not a TTY, read from stdin
|
||||
// This is for cases where the user pipes input directly into the command
|
||||
let stdinData: string | undefined = undefined;
|
||||
if (!process.stdin.isTTY) {
|
||||
stdinData = await readStdin();
|
||||
if (stdinData) {
|
||||
input = input ? `${stdinData}\n\n${input}` : stdinData;
|
||||
}
|
||||
}
|
||||
|
||||
// Fire SessionStart hook through MessageBus (only if hooks are enabled)
|
||||
// Must be called AFTER config.initialize() to ensure HookRegistry is loaded
|
||||
const hooksEnabled = config.getEnableHooks();
|
||||
@@ -642,7 +652,23 @@ export async function main() {
|
||||
const sessionStartSource = resumedSessionData
|
||||
? SessionStartSource.Resume
|
||||
: SessionStartSource.Startup;
|
||||
await fireSessionStartHook(hookMessageBus, sessionStartSource);
|
||||
const result = await fireSessionStartHook(
|
||||
hookMessageBus,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Register SessionEnd hook for graceful exit
|
||||
registerCleanup(async () => {
|
||||
@@ -650,14 +676,6 @@ export async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
// If not a TTY, read from stdin
|
||||
// This is for cases where the user pipes input directly into the command
|
||||
if (!process.stdin.isTTY) {
|
||||
const stdinData = await readStdin();
|
||||
if (stdinData) {
|
||||
input = `${stdinData}\n\n${input}`;
|
||||
}
|
||||
}
|
||||
if (!input) {
|
||||
debugLogger.error(
|
||||
`No input provided via stdin. Input can be provided by piping data into gemini or using the --prompt option.`,
|
||||
|
||||
Reference in New Issue
Block a user