mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
fix(trust): Respect folder trust setting when reading GEMINI.md (#7409)
This commit is contained in:
@@ -9,14 +9,12 @@ import * as fsSync from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
import { bfsFileSearch } from './bfsFileSearch.js';
|
||||
import {
|
||||
GEMINI_CONFIG_DIR,
|
||||
getAllGeminiMdFilenames,
|
||||
} from '../tools/memoryTool.js';
|
||||
import { getAllGeminiMdFilenames } from '../tools/memoryTool.js';
|
||||
import type { FileDiscoveryService } from '../services/fileDiscoveryService.js';
|
||||
import { processImports } from './memoryImportProcessor.js';
|
||||
import type { FileFilteringOptions } from '../config/config.js';
|
||||
import { DEFAULT_MEMORY_FILE_FILTERING_OPTIONS } from '../config/config.js';
|
||||
import { GEMINI_DIR } from './paths.js';
|
||||
|
||||
// Simple console logger, similar to the one previously in CLI's config.ts
|
||||
// TODO: Integrate with a more robust server-side logger if available/appropriate.
|
||||
@@ -87,6 +85,7 @@ async function getGeminiMdFilePathsInternal(
|
||||
debugMode: boolean,
|
||||
fileService: FileDiscoveryService,
|
||||
extensionContextFilePaths: string[] = [],
|
||||
folderTrust: boolean,
|
||||
fileFilteringOptions: FileFilteringOptions,
|
||||
maxDirs: number,
|
||||
): Promise<string[]> {
|
||||
@@ -109,6 +108,7 @@ async function getGeminiMdFilePathsInternal(
|
||||
debugMode,
|
||||
fileService,
|
||||
extensionContextFilePaths,
|
||||
folderTrust,
|
||||
fileFilteringOptions,
|
||||
maxDirs,
|
||||
),
|
||||
@@ -138,6 +138,7 @@ async function getGeminiMdFilePathsInternalForEachDir(
|
||||
debugMode: boolean,
|
||||
fileService: FileDiscoveryService,
|
||||
extensionContextFilePaths: string[] = [],
|
||||
folderTrust: boolean,
|
||||
fileFilteringOptions: FileFilteringOptions,
|
||||
maxDirs: number,
|
||||
): Promise<string[]> {
|
||||
@@ -148,7 +149,7 @@ async function getGeminiMdFilePathsInternalForEachDir(
|
||||
const resolvedHome = path.resolve(userHomePath);
|
||||
const globalMemoryPath = path.join(
|
||||
resolvedHome,
|
||||
GEMINI_CONFIG_DIR,
|
||||
GEMINI_DIR,
|
||||
geminiMdFilename,
|
||||
);
|
||||
|
||||
@@ -166,7 +167,7 @@ async function getGeminiMdFilePathsInternalForEachDir(
|
||||
|
||||
// FIX: Only perform the workspace search (upward and downward scans)
|
||||
// if a valid currentWorkingDirectory is provided.
|
||||
if (dir) {
|
||||
if (dir && folderTrust) {
|
||||
const resolvedCwd = path.resolve(dir);
|
||||
if (debugMode)
|
||||
logger.debug(
|
||||
@@ -184,7 +185,7 @@ async function getGeminiMdFilePathsInternalForEachDir(
|
||||
: path.dirname(resolvedHome);
|
||||
|
||||
while (currentDir && currentDir !== path.dirname(currentDir)) {
|
||||
if (currentDir === path.join(resolvedHome, GEMINI_CONFIG_DIR)) {
|
||||
if (currentDir === path.join(resolvedHome, GEMINI_DIR)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ async function getGeminiMdFilePathsInternalForEachDir(
|
||||
}
|
||||
upwardPaths.forEach((p) => allPaths.add(p));
|
||||
|
||||
const mergedOptions = {
|
||||
const mergedOptions: FileFilteringOptions = {
|
||||
...DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
|
||||
...fileFilteringOptions,
|
||||
};
|
||||
@@ -327,6 +328,11 @@ function concatenateInstructions(
|
||||
.join('\n\n');
|
||||
}
|
||||
|
||||
export interface LoadServerHierarchicalMemoryResponse {
|
||||
memoryContent: string;
|
||||
fileCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads hierarchical GEMINI.md files and concatenates their content.
|
||||
* This function is intended for use by the server.
|
||||
@@ -337,10 +343,11 @@ export async function loadServerHierarchicalMemory(
|
||||
debugMode: boolean,
|
||||
fileService: FileDiscoveryService,
|
||||
extensionContextFilePaths: string[] = [],
|
||||
folderTrust: boolean,
|
||||
importFormat: 'flat' | 'tree' = 'tree',
|
||||
fileFilteringOptions?: FileFilteringOptions,
|
||||
maxDirs: number = 200,
|
||||
): Promise<{ memoryContent: string; fileCount: number }> {
|
||||
): Promise<LoadServerHierarchicalMemoryResponse> {
|
||||
if (debugMode)
|
||||
logger.debug(
|
||||
`Loading server hierarchical memory for CWD: ${currentWorkingDirectory} (importFormat: ${importFormat})`,
|
||||
@@ -356,6 +363,7 @@ export async function loadServerHierarchicalMemory(
|
||||
debugMode,
|
||||
fileService,
|
||||
extensionContextFilePaths,
|
||||
folderTrust,
|
||||
fileFilteringOptions || DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
|
||||
maxDirs,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user