Revert "[ide-mode] Thread active file through to system prompt" (#4308)

This commit is contained in:
christine betts 2025-07-16 16:22:29 +00:00 committed by GitHub
parent ddcac4201d
commit 34c1b5811a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 56 deletions

View File

@ -346,7 +346,7 @@ describe('Gemini Client (client.ts)', () => {
model: 'test-model',
config: {
abortSignal,
systemInstruction: getCoreSystemPrompt(client['config'], ''),
systemInstruction: getCoreSystemPrompt(''),
temperature: 0.5,
topP: 1,
},
@ -374,7 +374,7 @@ describe('Gemini Client (client.ts)', () => {
model: 'test-model', // Should use current model from config
config: {
abortSignal,
systemInstruction: getCoreSystemPrompt(client['config'], ''),
systemInstruction: getCoreSystemPrompt(''),
temperature: 0,
topP: 1,
responseSchema: schema,
@ -409,7 +409,7 @@ describe('Gemini Client (client.ts)', () => {
model: customModel,
config: {
abortSignal,
systemInstruction: getCoreSystemPrompt(client['config'], ''),
systemInstruction: getCoreSystemPrompt(''),
temperature: 0.9,
topP: 1, // from default
topK: 20,

View File

@ -238,7 +238,7 @@ export class GeminiClient {
];
try {
const userMemory = this.config.getUserMemory();
const systemInstruction = getCoreSystemPrompt(this.config, userMemory);
const systemInstruction = getCoreSystemPrompt(userMemory);
const generateContentConfigWithThinking = isThinkingSupported(
this.config.getModel(),
)
@ -354,7 +354,7 @@ export class GeminiClient {
model || this.config.getModel() || DEFAULT_GEMINI_FLASH_MODEL;
try {
const userMemory = this.config.getUserMemory();
const systemInstruction = getCoreSystemPrompt(this.config, userMemory);
const systemInstruction = getCoreSystemPrompt(userMemory);
const requestConfig = {
abortSignal,
...this.generateContentConfig,
@ -447,7 +447,7 @@ export class GeminiClient {
try {
const userMemory = this.config.getUserMemory();
const systemInstruction = getCoreSystemPrompt(this.config, userMemory);
const systemInstruction = getCoreSystemPrompt(userMemory);
const requestConfig = {
abortSignal,

View File

@ -4,10 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { describe, it, expect, vi } from 'vitest';
import { getCoreSystemPrompt } from './prompts.js';
import { isGitRepository } from '../utils/gitUtils.js';
import { Config } from '../config/config.js';
// Mock tool names if they are dynamically generated or complex
vi.mock('../tools/ls', () => ({ LSTool: { Name: 'list_directory' } }));
@ -27,25 +26,11 @@ vi.mock('../tools/write-file', () => ({
vi.mock('../utils/gitUtils', () => ({
isGitRepository: vi.fn(),
}));
vi.mock('../config/config.js');
describe('Core System Prompt (prompts.ts)', () => {
let mockConfig: Config;
beforeEach(() => {
const MockedConfig = vi.mocked(Config, true);
MockedConfig.mockImplementation(() => {
const mock = {
getIdeMode: vi.fn().mockReturnValue(false),
};
return mock as unknown as Config;
});
mockConfig = new Config({} as never);
});
it('should return the base prompt when no userMemory is provided', () => {
vi.stubEnv('SANDBOX', undefined);
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).not.toContain('---\n\n'); // Separator should not be present
expect(prompt).toContain('You are an interactive CLI agent'); // Check for core content
expect(prompt).toMatchSnapshot(); // Use snapshot for base prompt structure
@ -53,7 +38,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should return the base prompt when userMemory is empty string', () => {
vi.stubEnv('SANDBOX', undefined);
const prompt = getCoreSystemPrompt(mockConfig, '');
const prompt = getCoreSystemPrompt('');
expect(prompt).not.toContain('---\n\n');
expect(prompt).toContain('You are an interactive CLI agent');
expect(prompt).toMatchSnapshot();
@ -61,7 +46,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should return the base prompt when userMemory is whitespace only', () => {
vi.stubEnv('SANDBOX', undefined);
const prompt = getCoreSystemPrompt(mockConfig, ' \n \t ');
const prompt = getCoreSystemPrompt(' \n \t ');
expect(prompt).not.toContain('---\n\n');
expect(prompt).toContain('You are an interactive CLI agent');
expect(prompt).toMatchSnapshot();
@ -71,7 +56,7 @@ describe('Core System Prompt (prompts.ts)', () => {
vi.stubEnv('SANDBOX', undefined);
const memory = 'This is custom user memory.\nBe extra polite.';
const expectedSuffix = `\n\n---\n\n${memory}`;
const prompt = getCoreSystemPrompt(mockConfig, memory);
const prompt = getCoreSystemPrompt(memory);
expect(prompt.endsWith(expectedSuffix)).toBe(true);
expect(prompt).toContain('You are an interactive CLI agent'); // Ensure base prompt follows
@ -80,7 +65,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should include sandbox-specific instructions when SANDBOX env var is set', () => {
vi.stubEnv('SANDBOX', 'true'); // Generic sandbox value
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).toContain('# Sandbox');
expect(prompt).not.toContain('# MacOS Seatbelt');
expect(prompt).not.toContain('# Outside of Sandbox');
@ -89,7 +74,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should include seatbelt-specific instructions when SANDBOX env var is "sandbox-exec"', () => {
vi.stubEnv('SANDBOX', 'sandbox-exec');
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).toContain('# MacOS Seatbelt');
expect(prompt).not.toContain('# Sandbox');
expect(prompt).not.toContain('# Outside of Sandbox');
@ -98,7 +83,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should include non-sandbox instructions when SANDBOX env var is not set', () => {
vi.stubEnv('SANDBOX', undefined); // Ensure it's not set
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).toContain('# Outside of Sandbox');
expect(prompt).not.toContain('# Sandbox');
expect(prompt).not.toContain('# MacOS Seatbelt');
@ -108,7 +93,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should include git instructions when in a git repo', () => {
vi.stubEnv('SANDBOX', undefined);
vi.mocked(isGitRepository).mockReturnValue(true);
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).toContain('# Git Repository');
expect(prompt).toMatchSnapshot();
});
@ -116,7 +101,7 @@ describe('Core System Prompt (prompts.ts)', () => {
it('should not include git instructions when not in a git repo', () => {
vi.stubEnv('SANDBOX', undefined);
vi.mocked(isGitRepository).mockReturnValue(false);
const prompt = getCoreSystemPrompt(mockConfig);
const prompt = getCoreSystemPrompt();
expect(prompt).not.toContain('# Git Repository');
expect(prompt).toMatchSnapshot();
});

View File

@ -17,13 +17,8 @@ import { WriteFileTool } from '../tools/write-file.js';
import process from 'node:process';
import { isGitRepository } from '../utils/gitUtils.js';
import { MemoryTool, GEMINI_CONFIG_DIR } from '../tools/memoryTool.js';
import { Config } from '../config/config.js';
import { ideContext } from '../services/ideContext.js';
export function getCoreSystemPrompt(
config: Config,
userMemory?: string,
): string {
export function getCoreSystemPrompt(userMemory?: string): string {
// if GEMINI_SYSTEM_MD is set (and not 0|false), override system prompt from file
// default path is .gemini/system.md but can be modified via custom path in GEMINI_SYSTEM_MD
let systemMdEnabled = false;
@ -158,25 +153,7 @@ ${(function () {
}
return '';
})()}
${(function () {
if (config.getIdeMode()) {
const activeFile = ideContext.getActiveFileContext();
if (activeFile?.filePath) {
let prompt = `
# IDE Mode
You are running in IDE mode. The user has the following file open:
- Path: ${activeFile.filePath}`;
if (activeFile.cursor) {
prompt += `
- Cursor Position: Line ${activeFile.cursor.line}, Character ${activeFile.cursor.character}`;
}
prompt += `
Focus on providing contextually relevant assistance for this file.`;
return prompt;
}
}
return '';
})()}
# Examples (Illustrating Tone and Workflow)
<example>
user: 1 + 2