Update contextFileName to support an optional list of strings (#1001)

This commit is contained in:
Billy Biggs
2025-06-13 09:19:08 -07:00
committed by GitHub
parent 34e0d9c0b6
commit 2a1ad1f5d9
10 changed files with 176 additions and 117 deletions
@@ -9,6 +9,7 @@ import {
MemoryTool,
setGeminiMdFilename,
getCurrentGeminiMdFilename,
getAllGeminiMdFilenames,
DEFAULT_CONTEXT_FILENAME,
} from './memoryTool.js';
import * as fs from 'fs/promises';
@@ -74,6 +75,13 @@ describe('MemoryTool', () => {
setGeminiMdFilename('');
expect(getCurrentGeminiMdFilename()).toBe(initialName);
});
it('should handle an array of filenames', () => {
const newNames = ['CUSTOM_CONTEXT.md', 'ANOTHER_CONTEXT.md'];
setGeminiMdFilename(newNames);
expect(getCurrentGeminiMdFilename()).toBe('CUSTOM_CONTEXT.md');
expect(getAllGeminiMdFilenames()).toEqual(newNames);
});
});
describe('performAddMemoryEntry (static method)', () => {
+17 -3
View File
@@ -51,18 +51,32 @@ export const MEMORY_SECTION_HEADER = '## Gemini Added Memories';
// This variable will hold the currently configured filename for GEMINI.md context files.
// It defaults to DEFAULT_CONTEXT_FILENAME but can be overridden by setGeminiMdFilename.
let currentGeminiMdFilename = DEFAULT_CONTEXT_FILENAME;
let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAME;
export function setGeminiMdFilename(newFilename: string): void {
if (newFilename && newFilename.trim() !== '') {
export function setGeminiMdFilename(newFilename: string | string[]): void {
if (Array.isArray(newFilename)) {
if (newFilename.length > 0) {
currentGeminiMdFilename = newFilename.map((name) => name.trim());
}
} else if (newFilename && newFilename.trim() !== '') {
currentGeminiMdFilename = newFilename.trim();
}
}
export function getCurrentGeminiMdFilename(): string {
if (Array.isArray(currentGeminiMdFilename)) {
return currentGeminiMdFilename[0];
}
return currentGeminiMdFilename;
}
export function getAllGeminiMdFilenames(): string[] {
if (Array.isArray(currentGeminiMdFilename)) {
return currentGeminiMdFilename;
}
return [currentGeminiMdFilename];
}
interface SaveMemoryParams {
fact: string;
}