feat(core): overhaul system prompt for rigor, integrity, and intent alignment (#17263)

This commit is contained in:
N. Taylor Mullen
2026-02-06 19:13:07 -08:00
committed by GitHub
parent 19dc40825e
commit 9178b31629
10 changed files with 1256 additions and 426 deletions

View File

@@ -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);
});

View File

@@ -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 ?? []),
];