diff options
| -rw-r--r-- | packages/cli/src/config/config.ts | 11 | ||||
| -rw-r--r-- | packages/server/src/config/config.ts | 10 | ||||
| -rw-r--r-- | packages/server/src/core/client.ts | 47 |
3 files changed, 63 insertions, 5 deletions
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 40a5dfd1..0db07d2b 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -20,6 +20,7 @@ interface CliArgs { model: string | undefined; debug_mode: boolean | undefined; question: string | undefined; + full_context: boolean | undefined; } function parseArguments(): CliArgs { @@ -42,6 +43,13 @@ function parseArguments(): CliArgs { description: 'The question to pass to the command when using piped input.', }) + .option('full_context', { + alias: 'f', + type: 'boolean', + description: + 'Recursively include all files within the current directory as context.', + default: false, + }) .help() .alias('h', 'help') .strict().argv; @@ -72,6 +80,7 @@ export function loadCliConfig(): Config { process.cwd(), argv.debug_mode || false, argv.question || '', - // TODO: load passthroughCommands from .env file + undefined, // TODO: load passthroughCommands from .env file + argv.full_context || false, ); } diff --git a/packages/server/src/config/config.ts b/packages/server/src/config/config.ts index d24fad4e..06092b84 100644 --- a/packages/server/src/config/config.ts +++ b/packages/server/src/config/config.ts @@ -29,6 +29,7 @@ export class Config { private debugMode: boolean; private question: string | undefined; private passthroughCommands: string[]; + private fullContext: boolean; constructor( apiKey: string, @@ -37,6 +38,7 @@ export class Config { debugMode: boolean, question: string, passthroughCommands?: string[], + fullContext?: boolean, ) { this.apiKey = apiKey; this.model = model; @@ -45,6 +47,7 @@ export class Config { this.question = question; this.passthroughCommands = passthroughCommands || DEFAULT_PASSTHROUGH_COMMANDS; + this.fullContext = fullContext || false; this.toolRegistry = createToolRegistry(this); } @@ -75,6 +78,11 @@ export class Config { getPassthroughCommands(): string[] { return this.passthroughCommands; } + + getFullContext(): boolean { + // Added getter for fullContext + return this.fullContext; + } } function findEnvFile(startDir: string): string | null { @@ -107,6 +115,7 @@ export function createServerConfig( debugMode: boolean, question: string, passthroughCommands?: string[], + fullContext?: boolean, ): Config { return new Config( apiKey, @@ -115,6 +124,7 @@ export function createServerConfig( debugMode, question, passthroughCommands, + fullContext, ); } diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts index fa4d23a8..01f48e72 100644 --- a/packages/server/src/core/client.ts +++ b/packages/server/src/core/client.ts @@ -19,6 +19,7 @@ import { getFolderStructure } from '../utils/getFolderStructure.js'; import { Turn, ServerGeminiStreamEvent } from './turn.js'; import { Config } from '../config/config.js'; import { getCoreSystemPrompt } from './prompts.js'; +import { ReadManyFilesTool } from '../tools/read-many-files.js'; // Import ReadManyFilesTool export class GeminiClient { private config: Config; @@ -36,7 +37,7 @@ export class GeminiClient { this.model = config.getModel(); } - private async getEnvironment(): Promise<Part> { + private async getEnvironment(): Promise<Part[]> { const cwd = process.cwd(); const today = new Date().toLocaleDateString(undefined, { weekday: 'long', @@ -53,11 +54,49 @@ export class GeminiClient { I'm currently working in the directory: ${cwd} ${folderStructure} `.trim(); - return { text: context }; + + const initialParts: Part[] = [{ text: context }]; + + // Add full file context if the flag is set + if (this.config.getFullContext()) { + try { + const readManyFilesTool = this.config + .getToolRegistry() + .getTool('read_many_files') as ReadManyFilesTool; + if (readManyFilesTool) { + // Read all files in the target directory + const result = await readManyFilesTool.execute({ + paths: ['**/*'], // Read everything recursively + useDefaultExcludes: true, // Use default excludes + }); + if (result.llmContent) { + initialParts.push({ + text: `\n--- Full File Context ---\n${result.llmContent}`, + }); + } else { + console.warn( + 'Full context requested, but read_many_files returned no content.', + ); + } + } else { + console.warn( + 'Full context requested, but read_many_files tool not found.', + ); + } + } catch (error) { + console.error('Error reading full file context:', error); + // Optionally add an error message part to the context + initialParts.push({ + text: '\n--- Error reading full file context ---', + }); + } + } + + return initialParts; } async startChat(): Promise<Chat> { - const envPart = await this.getEnvironment(); + const envParts = await this.getEnvironment(); const toolDeclarations = this.config .getToolRegistry() .getFunctionDeclarations(); @@ -73,7 +112,7 @@ export class GeminiClient { history: [ { role: 'user', - parts: [envPart], + parts: envParts, }, { role: 'model', |
