feat(core): add target parameter to save_memory for project-specific GEMINI.md routing#24070
feat(core): add target parameter to save_memory for project-specific GEMINI.md routing#24070SandyTao520 wants to merge 1 commit intomainfrom
Conversation
…GEMINI.md routing When memoryManager is disabled, save_memory was append-only to the global ~/.gemini/GEMINI.md. This adds an optional 'target' parameter accepting an absolute path to an existing GEMINI.md file, allowing project-specific or subdirectory-specific memories without enabling the full memory manager agent. Includes path validation (absolute, no traversal, must be GEMINI.md filename), file-existence check for non-global targets, prompt steering to prefer save_memory over write_file/replace for GEMINI.md edits, and tests.
|
Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
|
Size Change: +2.7 kB (+0.01%) Total Size: 26.5 MB
ℹ️ View Unchanged
|
Summary
Adds an optional
targetparameter to thesave_memorytool (non-memory-manager mode) so it can append memories to project-specific or subdirectory-specific GEMINI.md files, not just the global~/.gemini/GEMINI.md.Details
Previously, with
memoryManagerdisabled,save_memorywas strictly append-only to the global GEMINI.md. If a project or subdirectory already had its own GEMINI.md, there was no way to route memories there — the model would sometimes fall back towrite_fileorreplaceinstead.Changes:
gemini-3.ts,default-legacy.ts): Added optionaltargetstring parameter accepting an absolute path to an existing GEMINI.md file.memoryTool.ts):validateTargetPath()— rejects relative paths, non-GEMINI.md filenames, and..traversal.resolveMemoryFilePath()— returns global path when target is omitted, otherwise the normalized target.fs.access()for non-global targets before writing.snippets.ts): Updated non-memory-manager guidance to explaintargetusage and addedNEVER use write_file or replace to add memories to GEMINI.mdsteering (non-memory-manager branch only; memory manager agent is unchanged).Behavior:
targetvalue~/.gemini/GEMINI.md(unchanged)/abs/path/to/GEMINI.md../ wrong filenameRelated Issues
Related to #18007
How to Validate
Run unit tests:
Manual smoke test with
npm run start:save_memorywithtargetpointing to the project's existing GEMINI.md.targetand write to~/.gemini/GEMINI.md.Pre-Merge Checklist