mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-12 14:22:00 -07:00
feat(core): overhaul system prompt for rigor, integrity, and intent alignment (#17263)
This commit is contained in:
@@ -49,11 +49,10 @@ describe('getDirectoryContextString', () => {
|
||||
|
||||
it('should return context string for a single directory', async () => {
|
||||
const contextString = await getDirectoryContextString(mockConfig as Config);
|
||||
expect(contextString).toContain('- **Workspace Directories:**');
|
||||
expect(contextString).toContain(' - /test/dir');
|
||||
expect(contextString).toContain(
|
||||
"I'm currently working in the directory: /test/dir",
|
||||
);
|
||||
expect(contextString).toContain(
|
||||
'Here is the folder structure of the current working directories:\n\nMock Folder Structure',
|
||||
'- **Directory Structure:**\n\nMock Folder Structure',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -66,11 +65,11 @@ describe('getDirectoryContextString', () => {
|
||||
.mockResolvedValueOnce('Structure 2');
|
||||
|
||||
const contextString = await getDirectoryContextString(mockConfig as Config);
|
||||
expect(contextString).toContain('- **Workspace Directories:**');
|
||||
expect(contextString).toContain(' - /test/dir1');
|
||||
expect(contextString).toContain(' - /test/dir2');
|
||||
expect(contextString).toContain(
|
||||
"I'm currently working in the following directories:\n - /test/dir1\n - /test/dir2",
|
||||
);
|
||||
expect(contextString).toContain(
|
||||
'Here is the folder structure of the current working directories:\n\nStructure 1\nStructure 2',
|
||||
'- **Directory Structure:**\n\nStructure 1\nStructure 2',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -80,9 +79,6 @@ describe('getEnvironmentContext', () => {
|
||||
let mockToolRegistry: { getTool: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date('2025-08-05T12:00:00Z'));
|
||||
|
||||
mockToolRegistry = {
|
||||
getTool: vi.fn(),
|
||||
};
|
||||
@@ -104,7 +100,6 @@ describe('getEnvironmentContext', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
@@ -114,16 +109,14 @@ describe('getEnvironmentContext', () => {
|
||||
expect(parts.length).toBe(1);
|
||||
const context = parts[0].text;
|
||||
|
||||
expect(context).toContain("Today's date is");
|
||||
expect(context).toContain("(formatted according to the user's locale)");
|
||||
expect(context).toContain(`My operating system is: ${process.platform}`);
|
||||
expect(context).toContain('<session_context>');
|
||||
expect(context).toContain('- **Workspace Directories:**');
|
||||
expect(context).toContain(' - /test/dir');
|
||||
expect(context).toContain(
|
||||
"I'm currently working in the directory: /test/dir",
|
||||
);
|
||||
expect(context).toContain(
|
||||
'Here is the folder structure of the current working directories:\n\nMock Folder Structure',
|
||||
'- **Directory Structure:**\n\nMock Folder Structure',
|
||||
);
|
||||
expect(context).toContain('Mock Environment Memory');
|
||||
expect(context).toContain('</session_context>');
|
||||
expect(getFolderStructure).toHaveBeenCalledWith('/test/dir', {
|
||||
fileService: undefined,
|
||||
});
|
||||
@@ -142,12 +135,14 @@ describe('getEnvironmentContext', () => {
|
||||
expect(parts.length).toBe(1);
|
||||
const context = parts[0].text;
|
||||
|
||||
expect(context).toContain('<session_context>');
|
||||
expect(context).toContain('- **Workspace Directories:**');
|
||||
expect(context).toContain(' - /test/dir1');
|
||||
expect(context).toContain(' - /test/dir2');
|
||||
expect(context).toContain(
|
||||
"I'm currently working in the following directories:\n - /test/dir1\n - /test/dir2",
|
||||
);
|
||||
expect(context).toContain(
|
||||
'Here is the folder structure of the current working directories:\n\nStructure 1\nStructure 2',
|
||||
'- **Directory Structure:**\n\nStructure 1\nStructure 2',
|
||||
);
|
||||
expect(context).toContain('</session_context>');
|
||||
expect(getFolderStructure).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -30,17 +30,10 @@ export async function getDirectoryContextString(
|
||||
);
|
||||
|
||||
const folderStructure = folderStructures.join('\n');
|
||||
const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
|
||||
|
||||
let workingDirPreamble: string;
|
||||
if (workspaceDirectories.length === 1) {
|
||||
workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
|
||||
} else {
|
||||
const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
|
||||
workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
|
||||
}
|
||||
|
||||
return `${workingDirPreamble}
|
||||
Here is the folder structure of the current working directories:
|
||||
return `- **Workspace Directories:**\n${dirList}
|
||||
- **Directory Structure:**
|
||||
|
||||
${folderStructure}`;
|
||||
}
|
||||
@@ -65,6 +58,7 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
|
||||
const environmentMemory = config.getEnvironmentMemory();
|
||||
|
||||
const context = `
|
||||
<session_context>
|
||||
This is the Gemini CLI. We are setting up the context for our chat.
|
||||
Today's date is ${today} (formatted according to the user's locale).
|
||||
My operating system is: ${platform}
|
||||
@@ -72,7 +66,7 @@ The project's temporary directory is: ${tempDir}
|
||||
${directoryContext}
|
||||
|
||||
${environmentMemory}
|
||||
`.trim();
|
||||
</session_context>`.trim();
|
||||
|
||||
const initialParts: Part[] = [{ text: context }];
|
||||
|
||||
@@ -86,18 +80,10 @@ export async function getInitialChatHistory(
|
||||
const envParts = await getEnvironmentContext(config);
|
||||
const envContextString = envParts.map((part) => part.text || '').join('\n\n');
|
||||
|
||||
const allSetupText = `
|
||||
${envContextString}
|
||||
|
||||
Reminder: Do not return an empty response when a tool call is required.
|
||||
|
||||
My setup is complete. I will provide my first command in the next turn.
|
||||
`.trim();
|
||||
|
||||
return [
|
||||
{
|
||||
role: 'user',
|
||||
parts: [{ text: allSetupText }],
|
||||
parts: [{ text: envContextString }],
|
||||
},
|
||||
...(extraHistory ?? []),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user