Skip to content

fix(core): resolve Issue #319 - path handling for multi-directory workspace access#13

Closed
BingqingLyu wants to merge 10 commits into
mainfrom
fork-pr-352-fix-issue-319
Closed

fix(core): resolve Issue #319 - path handling for multi-directory workspace access#13
BingqingLyu wants to merge 10 commits into
mainfrom
fork-pr-352-fix-issue-319

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

TLDR

This PR resolves Issue QwenLM#319 by fixing path handling issues when accessing files across multiple workspace directories. The fix prevents application crashes when users include external directories in their includeDirectories settings or add directories dynamically (via /directory add path/to/directory) and also resolves the "I couldn't fully process the contents of /path/to/directory due to path formatting issue" error, enabling robust multi-directory workspace support.

Dive Deeper

Problem Analysis - The Error Scenario:

User Configuration in settings.json:

{
  "includeDirectories": [
    "F:/qwencode/qwen-code",
    "E:/filefolder"
  ]
}

Or If You Are In Window, this could be:

{
  "includeDirectories": [
    "F:\\qwencode\\qwen-code",
    "E:\\filefolder"
  ]
}

Or Adding Directory via Command:

/directory add E:/filefolder

User Prompt:

> What's inside E:/filefolder

Result - Application Crashed with Error:

Error: path should be a path.relative()d string
    at async Promise.all (index 1)
    at async GeminiClient.getEnvironment
    (file:///F:/qwencode/qwen-code/packages/core/dist/src/core/client.js:152:34)

Or Partial Processing Error:

I couldn't fully process the contents of E:/filefolder due to path formatting issue

Root Cause Analysis:

  1. FileDiscoveryService was only initialized with the main target directory (F:/qwencode/qwen-code)
  2. When user asked about E:/filefolder, the system tried to calculate relative paths from the main directory
  3. path.relative('F:/qwencode/qwen-code', 'E:/filefolder') generated invalid paths like ../../E:/filefolder
  4. The ignore file validation failed because it expected relative paths within the project root
  5. Promise.all crashed when any directory access failed, bringing down the entire application

Solution Implementation:

Same User Configuration & Prompt - Now Working:

✔ ReadFolder E:/filefolder

Listed 3 item(s).

The contents of E:/filefolder are:
- A directory named myfolder  
- Two files: computer.txt and test.txt

Technical Fixes Applied:

  1. Enhanced FileDiscoveryService: Now properly handles multiple workspace directories
  2. Smart Path Resolution: LSTool.execute() finds the appropriate workspace directory for each path
  3. Graceful Error Handling: Promise.allSettled replaces Promise.all, preventing crashes
  4. Skip External Validation: Ignore file validation is skipped for external directories
  5. Robust Directory Processing: Each directory is processed independently with proper error recovery

Key Changes Made:

  1. Fixed FileDiscoveryService initialization to use primary workspace directory
  2. Enhanced LSTool.execute() to properly calculate relative paths for files in multiple workspace directories
  3. Added skip logic for ignore file validation for external workspace directories to prevent path.relative() validation errors
  4. Replaced Promise.all with Promise.allSettled in getEnvironment() and getDirectoryContext() methods
  5. Added comprehensive error handling for ignore file checking operations

Reviewer Test Plan

To validate this fix works correctly:

  1. Setup Test Environment:

    • Create a settings.json with multiple directories in includeDirectories
    • Include at least one external directory (outside main project)
  2. Test the Fix:

    • Start the CLI: npm start
    • Try accessing external directory: "What's inside <external_directory>"
    • Verify it lists contents without crashing
  3. Test Edge Cases:

    • Try with non-existent directories
    • Test with directories that have permission issues
    • Verify main project directory still works normally
  4. Regression Testing:

    • Test single directory workspaces still work
    • Verify ignore files (.gitignore, .geminiignore) still function properly within main project

Testing Matrix

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

Linked issues / bugs

Fixes QwenLM#319

Mir and others added 10 commits August 29, 2025 12:44
- Fix FileDiscoveryService initialization to use primary workspace directory
- Update ls.ts tool to properly calculate relative paths for files in multiple workspace directories
- Resolves Issue QwenLM#319 where includeDirectories from settings.json caused path format errors
The issue was that FileDiscoveryService was only initialized with the main target directory,
but the ls tool needed to handle files across multiple workspace directories. This caused
relative path calculation failures when accessing files outside the main working directory.
Changes:
- Modified Config.getFileService() to use primary workspace directory
- Enhanced LSTool.execute() to find appropriate workspace directory for relative path calculation
- Maintains backward compatibility with single directory workspaces
…ries

- Skip .gitignore and .geminiignore validation for files outside main project directory
- Prevents path.relative() validation errors when accessing external workspace directories
- Maintains ignore file functionality for files within the main project directory
- Resolves remaining path format errors in Issue QwenLM#319
This addresses the core issue where FileDiscoveryService expected relative paths
from the main project root, but external directories like E:\filefolder would
generate invalid relative paths causing 'path should be a path.relative()d string' errors.
- Replace generic 'Failed to execute tool' error with descriptive message
- Clearly explain directory access restrictions and show allowed directories
- Improves user experience when attempting to access directories outside workspace
- Maintains security while providing helpful feedback to users
Now when users try to access unauthorized directories like E:\test, they get:
'Directory access restricted. I can only access files within the configured
workspace directories: [list]. The requested path is outside these allowed directories.'
- Fixed duplicate method definition that was causing compilation issues
- Maintained Windows path normalization for consistent workspace validation
- Ensures proper workspace directory validation across different path formats
…directories

- Replace Promise.all with Promise.allSettled in getEnvironment() and getDirectoryContext()
- Add proper error handling for individual directory access failures
- Prevents entire operation from failing when one workspace directory is inaccessible
- Maintains functionality while providing graceful degradation for problematic directories
- Fixes async Promise.all errors that could crash the application during initialization
…ructure

- Add try-catch blocks around fileService.shouldGitIgnoreFile() and shouldGeminiIgnoreFile() calls
- Prevents crashes when ignore file validation fails for external directories
- Gracefully handles path validation errors by logging warnings and continuing processing
- Ensures getFolderStructure continues working even when ignore file checks fail
- Fixes remaining async Promise.all errors at line 215 in getFolderStructure.js
- Add mnemonist dependency for clearcut-logger FixedDeque usage
- Add fzf dependency for fileSearch AsyncFzf functionality
- Resolves TypeScript compilation errors after upstream merge
- Fixed structural issues in LSToolInvocation class in ls.ts
- Removed duplicate variable declarations and malformed code
- Removed unused methods getDirectoryContext() and getEnvironment() from client.ts
- Removed unused imports (Part, getFolderStructure)
- All TypeScript compilation errors resolved
- Build process now completes successfully
- Add mnemonist dependency for clearcut-logger FixedDeque usage
- Add fzf dependency for fileSearch AsyncFzf functionality
- Resolves TypeScript compilation errors after upstream merge
@BingqingLyu BingqingLyu added conflicting-group-3 conflicting-group-3 Conflicting PR group 3 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs and removed conflicting-pr labels May 7, 2026
@BingqingLyu

BingqingLyu commented May 7, 2026

Copy link
Copy Markdown
Owner Author

Conflict Group 3

This PR shares modified functions with 1 other PR(s): #16.

These PRs should be reviewed as a batch — merging one may affect the others.

Function File Also modified by
readFullStructure getFolderStructure.ts #16
graph LR
    PR13["PR #13"]
    FreadFullStructure_7180["readFullStructure<br>getFolderStructure.ts"]
    PR13 -->|modifies| FreadFullStructure_7180
    PR16["PR #16"]
    PR16 -->|modifies| FreadFullStructure_7180
Loading

Posted by codegraph-ai conflict detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicting-group-3 Conflicting PR group 3 — review as a batch conflicting-pr Shares at least one cross-PR dependency with other PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

includeDirectories - Unable to Access Files Outside the Working Directory

2 participants