indicate system prompt override on bottom right; require GEMINI_SYSTEM_MD to make it more explicit; allow custom paths for read/write (#427)

This commit is contained in:
Olcan 2025-05-19 11:03:04 -07:00 committed by GitHub
parent 2a3c3d00ea
commit 750649eb64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View File

@ -74,6 +74,9 @@ export const Footer: React.FC<FooterProps> = ({
<Text color={Colors.AccentRed}> </Text>
</Text>
)}
{process.env.GEMINI_SYSTEM_MD && (
<Text color={Colors.AccentRed}>|_|</Text>
)}
</Box>
</Box>
);

View File

@ -21,9 +21,22 @@ import { MemoryTool, GEMINI_CONFIG_DIR } from '../tools/memoryTool.js';
const contactEmail = 'gemini-code-dev@google.com';
export function getCoreSystemPrompt(userMemory?: string): string {
// replace base prompt with system.md if it exists under GEMINI_CONFIG_DIR
const systemMdPath = path.join(GEMINI_CONFIG_DIR, 'system.md');
const basePrompt = fs.existsSync(systemMdPath)
// 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;
let systemMdPath = path.join(GEMINI_CONFIG_DIR, 'system.md');
const systemMdVar = process.env.GEMINI_SYSTEM_MD?.toLowerCase();
if (systemMdVar && !['0', 'false'].includes(systemMdVar)) {
systemMdEnabled = true; // enable system prompt override
if (!['1', 'true'].includes(systemMdVar)) {
systemMdPath = systemMdVar; // use custom path from GEMINI_SYSTEM_MD
}
// require file to exist when override is enabled
if (!fs.existsSync(systemMdPath)) {
throw new Error(`missing system prompt file '${systemMdPath}'`);
}
}
const basePrompt = systemMdEnabled
? fs.readFileSync(systemMdPath, 'utf8')
: `
You are an interactive CLI agent specializing in software engineering tasks. Your primary goal is to help users safely and efficiently, adhering strictly to the following instructions and utilizing your available tools.
@ -198,9 +211,14 @@ assistant: I can run \`rm -rf ./temp\`. This will permanently delete the directo
Your core function is efficient and safe assistance. Balance extreme conciseness with the crucial need for clarity, especially regarding safety and potential system modifications. Always prioritize user control and project conventions. Never make assumptions on the contents of files; instead use '${ReadFileTool.Name}' or '${ReadManyFilesTool.Name}' to ensure you aren't making broad assumptions. Finally, you are an agent - please keep going until the user's query is completely resolved.
`.trim();
// if GEMINI_WRITE_SYSTEM_MD is set, write base prompt to systemMdPath
if (process.env.GEMINI_WRITE_SYSTEM_MD) {
fs.writeFileSync(systemMdPath, basePrompt);
// if GEMINI_WRITE_SYSTEM_MD is set (and not 0|false), write base system prompt to file
const writeSystemMdVar = process.env.GEMINI_WRITE_SYSTEM_MD?.toLowerCase();
if (writeSystemMdVar && !['0', 'false'].includes(writeSystemMdVar)) {
if (['1', 'true'].includes(writeSystemMdVar)) {
fs.writeFileSync(systemMdPath, basePrompt); // write to default path, can be modified via GEMINI_SYSTEM_MD
} else {
fs.writeFileSync(writeSystemMdVar, basePrompt); // write to custom path from GEMINI_WRITE_SYSTEM_MD
}
}
const memorySuffix =