mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Adding a full_context command line argument. (#158)
* Adding a full_context command line argument. * Update packages/cli/src/config/config.ts Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com> * lint fix. --------- Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
@@ -20,6 +20,7 @@ interface CliArgs {
|
|||||||
model: string | undefined;
|
model: string | undefined;
|
||||||
debug_mode: boolean | undefined;
|
debug_mode: boolean | undefined;
|
||||||
question: string | undefined;
|
question: string | undefined;
|
||||||
|
full_context: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseArguments(): CliArgs {
|
function parseArguments(): CliArgs {
|
||||||
@@ -42,6 +43,13 @@ function parseArguments(): CliArgs {
|
|||||||
description:
|
description:
|
||||||
'The question to pass to the command when using piped input.',
|
'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()
|
.help()
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.strict().argv;
|
.strict().argv;
|
||||||
@@ -72,6 +80,7 @@ export function loadCliConfig(): Config {
|
|||||||
process.cwd(),
|
process.cwd(),
|
||||||
argv.debug_mode || false,
|
argv.debug_mode || false,
|
||||||
argv.question || '',
|
argv.question || '',
|
||||||
// TODO: load passthroughCommands from .env file
|
undefined, // TODO: load passthroughCommands from .env file
|
||||||
|
argv.full_context || false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export class Config {
|
|||||||
private debugMode: boolean;
|
private debugMode: boolean;
|
||||||
private question: string | undefined;
|
private question: string | undefined;
|
||||||
private passthroughCommands: string[];
|
private passthroughCommands: string[];
|
||||||
|
private fullContext: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
apiKey: string,
|
apiKey: string,
|
||||||
@@ -37,6 +38,7 @@ export class Config {
|
|||||||
debugMode: boolean,
|
debugMode: boolean,
|
||||||
question: string,
|
question: string,
|
||||||
passthroughCommands?: string[],
|
passthroughCommands?: string[],
|
||||||
|
fullContext?: boolean,
|
||||||
) {
|
) {
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
@@ -45,6 +47,7 @@ export class Config {
|
|||||||
this.question = question;
|
this.question = question;
|
||||||
this.passthroughCommands =
|
this.passthroughCommands =
|
||||||
passthroughCommands || DEFAULT_PASSTHROUGH_COMMANDS;
|
passthroughCommands || DEFAULT_PASSTHROUGH_COMMANDS;
|
||||||
|
this.fullContext = fullContext || false;
|
||||||
|
|
||||||
this.toolRegistry = createToolRegistry(this);
|
this.toolRegistry = createToolRegistry(this);
|
||||||
}
|
}
|
||||||
@@ -75,6 +78,11 @@ export class Config {
|
|||||||
getPassthroughCommands(): string[] {
|
getPassthroughCommands(): string[] {
|
||||||
return this.passthroughCommands;
|
return this.passthroughCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFullContext(): boolean {
|
||||||
|
// Added getter for fullContext
|
||||||
|
return this.fullContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findEnvFile(startDir: string): string | null {
|
function findEnvFile(startDir: string): string | null {
|
||||||
@@ -107,6 +115,7 @@ export function createServerConfig(
|
|||||||
debugMode: boolean,
|
debugMode: boolean,
|
||||||
question: string,
|
question: string,
|
||||||
passthroughCommands?: string[],
|
passthroughCommands?: string[],
|
||||||
|
fullContext?: boolean,
|
||||||
): Config {
|
): Config {
|
||||||
return new Config(
|
return new Config(
|
||||||
apiKey,
|
apiKey,
|
||||||
@@ -115,6 +124,7 @@ export function createServerConfig(
|
|||||||
debugMode,
|
debugMode,
|
||||||
question,
|
question,
|
||||||
passthroughCommands,
|
passthroughCommands,
|
||||||
|
fullContext,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { getFolderStructure } from '../utils/getFolderStructure.js';
|
|||||||
import { Turn, ServerGeminiStreamEvent } from './turn.js';
|
import { Turn, ServerGeminiStreamEvent } from './turn.js';
|
||||||
import { Config } from '../config/config.js';
|
import { Config } from '../config/config.js';
|
||||||
import { getCoreSystemPrompt } from './prompts.js';
|
import { getCoreSystemPrompt } from './prompts.js';
|
||||||
|
import { ReadManyFilesTool } from '../tools/read-many-files.js'; // Import ReadManyFilesTool
|
||||||
|
|
||||||
export class GeminiClient {
|
export class GeminiClient {
|
||||||
private config: Config;
|
private config: Config;
|
||||||
@@ -36,7 +37,7 @@ export class GeminiClient {
|
|||||||
this.model = config.getModel();
|
this.model = config.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getEnvironment(): Promise<Part> {
|
private async getEnvironment(): Promise<Part[]> {
|
||||||
const cwd = process.cwd();
|
const cwd = process.cwd();
|
||||||
const today = new Date().toLocaleDateString(undefined, {
|
const today = new Date().toLocaleDateString(undefined, {
|
||||||
weekday: 'long',
|
weekday: 'long',
|
||||||
@@ -53,11 +54,49 @@ export class GeminiClient {
|
|||||||
I'm currently working in the directory: ${cwd}
|
I'm currently working in the directory: ${cwd}
|
||||||
${folderStructure}
|
${folderStructure}
|
||||||
`.trim();
|
`.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> {
|
async startChat(): Promise<Chat> {
|
||||||
const envPart = await this.getEnvironment();
|
const envParts = await this.getEnvironment();
|
||||||
const toolDeclarations = this.config
|
const toolDeclarations = this.config
|
||||||
.getToolRegistry()
|
.getToolRegistry()
|
||||||
.getFunctionDeclarations();
|
.getFunctionDeclarations();
|
||||||
@@ -73,7 +112,7 @@ export class GeminiClient {
|
|||||||
history: [
|
history: [
|
||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
parts: [envPart],
|
parts: envParts,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'model',
|
role: 'model',
|
||||||
|
|||||||
Reference in New Issue
Block a user