gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

feat(core): Implement JIT context memory loading and UI sync

Open SandyTao520 opened this issue 3 weeks ago • 2 comments

TLDR

Refactors memory loading to support the Experimental JIT Context feature. It introduces a unified refresh() method in ContextManager for JIT mode, ensures the UI receives updates via events, and properly includes environment memory (and MCP instructions) in the system context.

Dive Deeper

  • ContextManager Refactor: Introduced a refresh() method to unify memory reloading (Global + Environment) and event emission. Removed legacy loadGlobalMemory calls from Config initialization.
  • Config Delegation: Config delegates memory state retrieval (file count, paths) to ContextManager when JIT is enabled.
  • Event Optimization: Simplified MemoryChanged event to only emit fileCount, as content and paths are pulled from Config on demand or not required for simple UI updates.
  • Memory Refresh: Updated /memory refresh command to use ContextManager.refresh() when JIT is enabled.
  • System Context: getEnvironmentContext now includes the content of loaded environment memory files. MCP instructions are appended to environment memory in JIT mode.

Reviewer Test Plan

  1. Enable JIT: Set experimental.jitContext: true in settings.
  2. Startup: Launch the CLI. Verify that the "Using: X GEMINI.md files" indicator appears and shows the correct count.
  3. Context: Run /reset and start a chat. Verify (via debug logs or model response) that the system instruction includes content from your GEMINI.md files AND any active MCP server instructions.
  4. Refresh: Modify a GEMINI.md file and run /memory refresh. Verify the count updates and the model sees the new content.
  5. Legacy: Disable JIT. Verify that memory loading works as before (using the CLI-side loader).

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

SandyTao520 avatar Dec 03 '25 21:12 SandyTao520