Skip to content

feat(core): add target parameter to save_memory for project-specific GEMINI.md routing#24070

Closed
SandyTao520 wants to merge 1 commit intomainfrom
st/feat/save-memory-target-routing
Closed

feat(core): add target parameter to save_memory for project-specific GEMINI.md routing#24070
SandyTao520 wants to merge 1 commit intomainfrom
st/feat/save-memory-target-routing

Conversation

@SandyTao520
Copy link
Copy Markdown
Contributor

Summary

Adds an optional target parameter to the save_memory tool (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 memoryManager disabled, save_memory was 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 to write_file or replace instead.

Changes:

  • Tool schema (gemini-3.ts, default-legacy.ts): Added optional target string parameter accepting an absolute path to an existing GEMINI.md file.
  • Implementation (memoryTool.ts):
    • validateTargetPath() — rejects relative paths, non-GEMINI.md filenames, and .. traversal.
    • resolveMemoryFilePath() — returns global path when target is omitted, otherwise the normalized target.
    • File-existence check via fs.access() for non-global targets before writing.
    • Threaded resolved path through confirmation, execution, and modify flows.
  • Prompt steering (snippets.ts): Updated non-memory-manager guidance to explain target usage and added NEVER use write_file or replace to add memories to GEMINI.md steering (non-memory-manager branch only; memory manager agent is unchanged).
  • Tests: 8 new test cases covering validation, resolution, target file writing, and error handling.

Behavior:

target value Writes to
omitted ~/.gemini/GEMINI.md (unchanged)
/abs/path/to/GEMINI.md That file (must exist)
relative path / .. / wrong filename Validation error

Related Issues

Related to #18007

How to Validate

  1. Run unit tests:

    npm test -w @google/gemini-cli-core -- src/tools/memoryTool.test.ts
    npm test -w @google/gemini-cli-core -- src/prompts/snippets-memory-manager.test.ts
    npm test -w @google/gemini-cli-core -- src/tools/definitions/coreToolsModelSnapshots.test.ts
  2. Manual smoke test with npm run start:

    • Ask the CLI to "remember" a project-specific fact — it should use save_memory with target pointing to the project's existing GEMINI.md.
    • Ask it to remember a global preference — should omit target and write to ~/.gemini/GEMINI.md.
    • If the target file doesn't exist, the tool should return an error message.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

…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.
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Mar 27, 2026

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!

@github-actions
Copy link
Copy Markdown

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@gemini-cli gemini-cli Bot added the area/unknown Triage automation assigns this label to issues that it is unable to classify label Mar 27, 2026
@github-actions
Copy link
Copy Markdown

Size Change: +2.7 kB (+0.01%)

Total Size: 26.5 MB

Filename Size Change
./bundle/chunk-B6FXVWXA.js 0 B -3.77 MB (removed) 🏆
./bundle/chunk-SYROWLEA.js 0 B -14.7 MB (removed) 🏆
./bundle/chunk-TMYX6EC6.js 0 B -1.96 MB (removed) 🏆
./bundle/core-2QGNLFG4.js 0 B -44.1 kB (removed) 🏆
./bundle/devtoolsService-XJFJ22WN.js 0 B -28.4 kB (removed) 🏆
./bundle/interactiveCli-E54YNHRQ.js 0 B -1.63 MB (removed) 🏆
./bundle/oauth2-provider-UXOKBJ44.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-HOUH3W3A.js 14.7 MB +14.7 MB (new file) 🆕
./bundle/chunk-LHW24SIQ.js 1.96 MB +1.96 MB (new file) 🆕
./bundle/chunk-YU5JEBSW.js 3.77 MB +3.77 MB (new file) 🆕
./bundle/core-WEETXZGH.js 44.2 kB +44.2 kB (new file) 🆕
./bundle/devtoolsService-AVABFBVT.js 28.4 kB +28.4 kB (new file) 🆕
./bundle/interactiveCli-HX54HT4V.js 1.63 MB +1.63 MB (new file) 🆕
./bundle/oauth2-provider-I7EJZ6KP.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/chunk-U4FACSVX.js 1.13 kB 0 B
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-CLX3JQHP.js 418 B 0 B
./bundle/gemini.js 532 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-2BVFVYWL.js 0 B -922 B (removed) 🏆
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/memoryDiscovery-O4523IWU.js 922 B +922 B (new file) 🆕

compressed-size-action

@SandyTao520 SandyTao520 closed this Apr 2, 2026
@SandyTao520 SandyTao520 deleted the st/feat/save-memory-target-routing branch April 2, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/unknown Triage automation assigns this label to issues that it is unable to classify

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant