summaryrefslogtreecommitdiff
path: root/packages/server/src/core/prompts.ts
diff options
context:
space:
mode:
authorOlcan <[email protected]>2025-05-19 11:03:04 -0700
committerGitHub <[email protected]>2025-05-19 11:03:04 -0700
commit750649eb64f247df925e2236c2595f12d88f7584 (patch)
tree109325b5ab4521bab2eaa6fc199b7e7cd41e671d /packages/server/src/core/prompts.ts
parent2a3c3d00ea99f73a99bd188e0ff547d11727f3a5 (diff)
indicate system prompt override on bottom right; require GEMINI_SYSTEM_MD to make it more explicit; allow custom paths for read/write (#427)
Diffstat (limited to 'packages/server/src/core/prompts.ts')
-rw-r--r--packages/server/src/core/prompts.ts30
1 files changed, 24 insertions, 6 deletions
diff --git a/packages/server/src/core/prompts.ts b/packages/server/src/core/prompts.ts
index 05200cea..94195255 100644
--- a/packages/server/src/core/prompts.ts
+++ b/packages/server/src/core/prompts.ts
@@ -21,9 +21,22 @@ import { MemoryTool, GEMINI_CONFIG_DIR } from '../tools/memoryTool.js';
const contactEmail = '[email protected]';
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 =