mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-12 11:00:51 -07:00
feat(context): persist context engine snapshots across sessions
This commit implements an opaque state export/import pattern for the ContextManager to ensure expensive LLM-derived snapshots are properly rehydrated upon session resume. The ContextManager now exposes `exportState` and `restoreState` methods, delegating structural validation to the `SnapshotStateHelper`. During active chat, the GeminiClient routinely passes the finalized context state down to the ChatRecordingService, which seamlessly embeds it into the existing JSONL metadata payload. Upon resume, the saved snapshot is re-published as a draft to the LiveInbox, allowing the synchronous pipeline to automatically and deterministically splice it back into the raw graph without an additional LLM call.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { createStateSnapshotHydrationProcessor } from '../processors/stateSnapshotHydrationProcessor.js';
|
||||
import type {
|
||||
AsyncPipelineDef,
|
||||
ContextManagementConfig,
|
||||
@@ -88,6 +89,29 @@ export const generalistProfile: ContextProfile = {
|
||||
): PipelineDef[] =>
|
||||
// Helper to merge default options with dynamically loaded processorOptions by ID
|
||||
[
|
||||
{
|
||||
name: 'Initialization Hydration',
|
||||
triggers: ['initialization'],
|
||||
processors: [
|
||||
createStateSnapshotHydrationProcessor('StateSnapshotHydration', env, {
|
||||
target: (() => {
|
||||
const res = resolveProcessorOptions(config, 'StateSnapshotSync', {
|
||||
target: 'max',
|
||||
maxStateTokens: 4000,
|
||||
maxSummaryTurns: 5,
|
||||
}).target;
|
||||
if (
|
||||
res === 'incremental' ||
|
||||
res === 'freeNTokens' ||
|
||||
res === 'max'
|
||||
) {
|
||||
return res;
|
||||
}
|
||||
return undefined;
|
||||
})(),
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Immediate Sanitization',
|
||||
triggers: ['new_message'],
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import type { ContextProcessor, AsyncContextProcessor } from '../pipeline.js';
|
||||
|
||||
export type PipelineTrigger =
|
||||
| 'initialization'
|
||||
| 'new_message'
|
||||
| 'retained_exceeded'
|
||||
| 'gc_backstop'
|
||||
|
||||
Reference in New Issue
Block a user