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

bug(core): read_many_files skips explicitly requested binary assets in added workspace directories (regression from #30211)

Open halcyon-past opened this issue 3 weeks ago • 2 comments

What happened?

After #30211 (1930f2539), read_many_files skips explicitly requested non-text assets (images, PDFs, audio) whenever they live in a secondary workspace directory (added via --include-directories or /directory add), or when an absolute path is passed in include.

ReadManyFilesToolInvocation.execute (packages/core/src/tools/read-many-files.ts:246-281) globs include patterns against every directory in workspaceContext.getDirectories(). Then, at lines 344-360, it computes:

const relativePathForDisplay = path
  .relative(this.config.getTargetDir(), filePath)
  .replace(/\\/g, '/');

and passes relativePathForDisplay into isAssetExplicitlyRequested(include, relativePathForDisplay, filePath, matcherCache).

For a secondary workspace directory ws2 when targetDir is ws1, relativePathForDisplay is ../ws2/assets/logo.png:

  1. Path-qualified patterns like assets/logo.png or docs/*.pdf fail isMatchPath('../ws2/assets/logo.png'), and the basename fallback (!normalizedPattern.includes('/') at line 156) is skipped because the pattern contains /.
  2. Even passing the exact absolute path (/path/to/ws2/assets/logo.png) fails because isAssetExplicitlyRequested only matches against relativePath (never against normalizedFilePath), and normalizedPattern contains /.

Local Reproduction

Tested on main (e5d88fb2c / 0.70.0-nightly.20261110.g1603e9bab) with WorkspaceContext(ws1, [ws2]), ws1/assets/root-logo.png, ws2/assets/logo.png, and ws2/docs/manual.pdf:

  • include: ['assets/root-logo.png'] (primary workspace ws1):
    • Result: Read and returned inlineData (image/png).
  • include: ['assets/logo.png'] (secondary workspace ws2):
    • Result: isAssetExplicitlyRequested(['assets/logo.png'], '../ws2/assets/logo.png', logoPath) returns false.
    • Skipped: ../ws2/assets/logo.png (Reason: asset file (image/pdf/audio) was not explicitly requested by name or extension)
    • llmContent: ["No files matching the criteria were found or all were skipped."]
  • include: ['docs/*.pdf'] (secondary workspace ws2):
    • Skipped: ../ws2/docs/manual.pdf (Reason: asset file (image/pdf/audio) was not explicitly requested by name or extension)
  • include: ['<abs>/ws2/assets/logo.png'] (exact absolute path):
    • Skipped: ../ws2/assets/logo.png (Reason: asset file (image/pdf/audio) was not explicitly requested by name or extension)

What did you expect to happen?

Explicitly requested images, PDFs, and audio files in any configured workspace directory (or specified by absolute path) should be matched against each workspace directory's relative path (and the normalized absolute filePath), not solely against path.relative(targetDir, filePath)—while still rejecting generic wildcard globs like **/* or reports/**.

Client information

Client Information
  • Repository: google-gemini/gemini-cli (main at commit e5d88fb2c, package.json version 0.70.0-nightly.20261110.g1603e9bab)
  • Platform: macOS (darwin)
  • Node.js: v26.10.0
  • Reproduced locally via ReadManyFilesTool from @google/gemini-cli-core

Login information

N/A (reproduced directly against ReadManyFilesTool in @google/gemini-cli-core)

Anything else we need to know?

Regression introduced in #30211 (1930f2539), which fixed #29045. packages/core/src/tools/read-many-files.test.ts currently only tests isAssetExplicitlyRequested with primary-root relative paths (assets/logo.png) and tests multi-workspace reading with text files, so this case isn't covered yet.

halcyon-past avatar Nov 11 '26 15:11 halcyon-past

Hi maintainers, I reproduced this locally on main and would be happy to put together a small PR with unit tests for isAssetExplicitlyRequested and multi-workspace ReadManyFilesTool execution. If this looks good, could a maintainer please add the help wanted label and assign this issue to me? Thank you!

halcyon-past avatar Nov 11 '26 15:11 halcyon-past

Hi maintainers, I reproduced this regression locally on Windows and opened PR #30468 with a minimal fix and vitest regression tests covering added workspace directories, exact absolute paths, Windows path/drive handling, and symlinked workspace roots (with CLA signed and Gemini Code Assist review clean). Could a maintainer please review it or add the \help wanted\ label if appropriate? Thank you!

6Riemann9 avatar Nov 25 '26 05:11 6Riemann9