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

fix(cli): Always process @file references in interactive mode

Open edlsh opened this issue 1 week ago • 1 comments

Summary

Fixes #14919

When users create prompts using the external editor (Ctrl+X), @file references were not being automatically loaded. Instead, the LLM had to initiate file reads itself, wasting tokens.

Root Cause

Interactive mode used isAtCommand() as a guard before calling handleAtCommand(). This heuristic (query.startsWith('@') || /\s@/.test(query)) failed in certain cases—especially for multi-line prompts from the external editor where @file might not be at the start or preceded by whitespace.

Non-interactive mode already calls handleAtCommand() unconditionally, so the fix is to match that behavior.

Changes

  1. useGeminiStream.ts: Remove the isAtCommand() conditional guard—now always calls handleAtCommand() to match non-interactive behavior
  2. atCommandProcessor.ts: Add a fast-path early exit (if (!query.includes('@'))) to avoid unnecessary parsing when no @ symbol exists
  3. atCommandProcessor.test.ts: Add 3 new tests for edge cases:
    • Prompts without @ symbol (verifies fast path)
    • Email addresses (verifies they don't trigger file loading)
    • Multi-line prompts with @file on non-first line

Testing

  • All 47 tests in atCommandProcessor.test.ts pass
  • Full npm run preflight passes (build, typecheck, tests)
  • Manual verification recommended with external editor workflow

edlsh avatar Dec 11 '25 18:12 edlsh