refactor(core): move background completion consumption from UI to agent loop

The agent loop in local-executor now listens via onInjection (all sources)
instead of onUserHint (steering only), picking up background completions
between turns. This removes the separate bg completion useEffect, refs,
state, and callback from AppContainer entirely.
This commit is contained in:
Adam Weidman
2026-03-15 15:43:34 -04:00
parent 8b7321ea8d
commit f46a1c7e8b
2 changed files with 26 additions and 61 deletions
+5 -55
View File
@@ -85,7 +85,6 @@ import {
buildUserSteeringHintPrompt,
logBillingEvent,
ApiKeyUpdatedEvent,
type InjectionSource,
} from '@google/gemini-cli-core';
import { validateAuthMethod } from '../config/auth.js';
import process from 'node:process';
@@ -1078,8 +1077,6 @@ Logging in with Google... Restarting Gemini CLI to continue.
const pendingHintsRef = useRef<string[]>([]);
const [pendingHintCount, setPendingHintCount] = useState(0);
const pendingBackgroundCompletionsRef = useRef<string[]>([]);
const [pendingBgCompletionCount, setPendingBgCompletionCount] = useState(0);
const consumePendingHints = useCallback(() => {
if (pendingHintsRef.current.length === 0) {
@@ -1091,29 +1088,14 @@ Logging in with Google... Restarting Gemini CLI to continue.
return hint;
}, []);
const consumePendingBackgroundCompletions = useCallback(() => {
if (pendingBackgroundCompletionsRef.current.length === 0) {
return null;
}
const output = pendingBackgroundCompletionsRef.current.join('\n');
pendingBackgroundCompletionsRef.current = [];
setPendingBgCompletionCount(0);
return output;
}, []);
useEffect(() => {
const injectionListener = (text: string, source: InjectionSource) => {
if (source === 'user_steering') {
pendingHintsRef.current.push(text);
setPendingHintCount((prev) => prev + 1);
} else if (source === 'background_completion') {
pendingBackgroundCompletionsRef.current.push(text);
setPendingBgCompletionCount((prev) => prev + 1);
}
const hintListener = (hint: string) => {
pendingHintsRef.current.push(hint);
setPendingHintCount((prev) => prev + 1);
};
config.injectionService.onInjection(injectionListener);
config.injectionService.onUserHint(hintListener);
return () => {
config.injectionService.offInjection(injectionListener);
config.injectionService.offUserHint(hintListener);
};
}, [config]);
@@ -2148,38 +2130,6 @@ Logging in with Google... Restarting Gemini CLI to continue.
pendingHintCount,
]);
// Reinject completed background execution output into the model conversation.
// Unlike user steering hints, this is NOT gated on model steering being enabled.
useEffect(() => {
if (
!isConfigInitialized ||
streamingState !== StreamingState.Idle ||
!isMcpReady ||
isToolAwaitingConfirmation(pendingHistoryItems)
) {
return;
}
const bgOutput = consumePendingBackgroundCompletions();
if (!bgOutput) {
return;
}
void submitQuery([
{
text: `Background execution update:\n${bgOutput}\n\nThe above background execution has completed. Review the output and continue your work accordingly.`,
},
]);
}, [
isConfigInitialized,
isMcpReady,
streamingState,
submitQuery,
consumePendingBackgroundCompletions,
pendingHistoryItems,
pendingBgCompletionCount,
]);
const allToolCalls = useMemo(
() =>
pendingHistoryItems