mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-22 15:51:18 -07:00
feat(memory): persist auto-memory scratchpad for skill extraction (#25873)
This commit is contained in:
@@ -112,6 +112,7 @@ export async function loadConversationRecord(
|
||||
userMessageCount?: number;
|
||||
firstUserMessage?: string;
|
||||
hasUserOrAssistantMessage?: boolean;
|
||||
memoryScratchpadIsStale?: boolean;
|
||||
})
|
||||
| null
|
||||
> {
|
||||
@@ -133,6 +134,8 @@ export async function loadConversationRecord(
|
||||
string,
|
||||
{ isUser: boolean; isUserOrAssistant: boolean }
|
||||
>();
|
||||
let isTrackingMemoryScratchpadFreshness = false;
|
||||
let memoryScratchpadIsStale = false;
|
||||
let firstUserMessageStr: string | undefined;
|
||||
|
||||
for await (const line of rl) {
|
||||
@@ -140,6 +143,9 @@ export async function loadConversationRecord(
|
||||
try {
|
||||
const record = JSON.parse(line) as unknown;
|
||||
if (isRewindRecord(record)) {
|
||||
if (isTrackingMemoryScratchpadFreshness) {
|
||||
memoryScratchpadIsStale = true;
|
||||
}
|
||||
const rewindId = record.$rewindTo;
|
||||
if (options?.metadataOnly) {
|
||||
const idx = messageIds.indexOf(rewindId);
|
||||
@@ -168,6 +174,9 @@ export async function loadConversationRecord(
|
||||
}
|
||||
}
|
||||
} else if (isMessageRecord(record)) {
|
||||
if (isTrackingMemoryScratchpadFreshness) {
|
||||
memoryScratchpadIsStale = true;
|
||||
}
|
||||
const id = record.id;
|
||||
const isUser = hasProperty(record, 'type') && record.type === 'user';
|
||||
const isUserOrAssistant =
|
||||
@@ -206,6 +215,12 @@ export async function loadConversationRecord(
|
||||
}
|
||||
}
|
||||
} else if (isMetadataUpdateRecord(record)) {
|
||||
if (hasProperty(record.$set, 'memoryScratchpad')) {
|
||||
isTrackingMemoryScratchpadFreshness = Boolean(
|
||||
record.$set.memoryScratchpad,
|
||||
);
|
||||
memoryScratchpadIsStale = false;
|
||||
}
|
||||
// Metadata update
|
||||
metadata = {
|
||||
...metadata,
|
||||
@@ -257,6 +272,7 @@ export async function loadConversationRecord(
|
||||
startTime: metadata.startTime || new Date().toISOString(),
|
||||
lastUpdated: metadata.lastUpdated || new Date().toISOString(),
|
||||
summary: metadata.summary,
|
||||
memoryScratchpad: metadata.memoryScratchpad,
|
||||
directories: metadata.directories,
|
||||
kind: metadata.kind,
|
||||
messages: options?.metadataOnly ? [] : loadedMessages,
|
||||
@@ -267,6 +283,9 @@ export async function loadConversationRecord(
|
||||
options?.metadataOnly && metadataMessages.length > 0
|
||||
? metadataMessages.filter((m) => m.type === 'user').length
|
||||
: userMessageCount,
|
||||
memoryScratchpadIsStale: isTrackingMemoryScratchpadFreshness
|
||||
? memoryScratchpadIsStale
|
||||
: undefined,
|
||||
firstUserMessage: fallbackFirstUserMessage,
|
||||
hasUserOrAssistantMessage:
|
||||
options?.metadataOnly && metadataMessages.length > 0
|
||||
@@ -332,6 +351,13 @@ export class ChatRecordingService {
|
||||
for (const msg of this.cachedConversation.messages) {
|
||||
this.appendRecord(msg);
|
||||
}
|
||||
if (this.cachedConversation.memoryScratchpad) {
|
||||
this.appendRecord({
|
||||
$set: {
|
||||
memoryScratchpad: this.cachedConversation.memoryScratchpad,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Update the session ID in the existing file
|
||||
|
||||
Reference in New Issue
Block a user