fix(core): resolve Issue #319 - path handling for multi-directory workspace access#13
Closed
BingqingLyu wants to merge 10 commits into
Closed
fix(core): resolve Issue #319 - path handling for multi-directory workspace access#13BingqingLyu wants to merge 10 commits into
BingqingLyu wants to merge 10 commits into
Conversation
- 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
Owner
Author
Conflict Group 3This PR shares modified functions with 1 other PR(s): #16. These PRs should be reviewed as a batch — merging one may affect the others.
graph LR
PR13["PR #13"]
FreadFullStructure_7180["readFullStructure<br>getFolderStructure.ts"]
PR13 -->|modifies| FreadFullStructure_7180
PR16["PR #16"]
PR16 -->|modifies| FreadFullStructure_7180
Posted by codegraph-ai conflict detection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
User Prompt:
Result - Application Crashed with Error:
Or Partial Processing Error:
Root Cause Analysis:
F:/qwencode/qwen-code)E:/filefolder, the system tried to calculate relative paths from the main directorypath.relative('F:/qwencode/qwen-code', 'E:/filefolder')generated invalid paths like../../E:/filefolderSolution Implementation:
Same User Configuration & Prompt - Now Working:
Technical Fixes Applied:
Key Changes Made:
Reviewer Test Plan
To validate this fix works correctly:
Setup Test Environment:
includeDirectoriesTest the Fix:
npm start"What's inside <external_directory>"Test Edge Cases:
Regression Testing:
Testing Matrix
Linked issues / bugs
Fixes QwenLM#319