fix: enhance findProjectRoot to traverse parent directories #11

Closed
opened 2025-10-14 15:38:11 -06:00 by navan · 0 comments
Owner

Originally created by @bjcoombs on 10/13/2025

Description

Fixes #1301

Enhances the findProjectRoot() function to correctly traverse parent directories when running task-master commands from subdirectories, enabling Task Master to work seamlessly in multi-repo projects and deep directory structures.

Changes Made

Core Improvements

  1. Enhanced Error Handling

    • Added try-catch around fs.existsSync() to gracefully handle permission errors
    • Allows traversal to continue even if some directories are inaccessible
  2. Improved Root Detection

    • Added safety check for when path.dirname() returns the same path
    • Prevents infinite loops when reaching filesystem root
  3. Better Project Marker Ordering

    • Prioritized Task Master-specific markers (.taskmaster, config files)
    • Ensures Task Master projects are detected before generic markers
  4. Expanded Project Support

    • Added markers for: Rust (Cargo.toml), Go (go.mod), Python (pyproject.toml, requirements.txt), Ruby (Gemfile), PHP (composer.json)
    • Improves cross-platform and multi-language project compatibility
  5. Enhanced Documentation

    • Improved code comments and function documentation
    • Clarified traversal logic and fallback behavior

Testing

  • Added comprehensive unit tests in tests/unit/path-utils-find-project-root.test.js
  • 12 test cases covering:
    • Parent directory traversal for various markers
    • Multi-level directory traversal
    • Permission error handling
    • Filesystem root detection
    • Edge cases (empty paths, relative paths, max depth)
  • All tests passing

Before This Fix

cd /project/subdirectory
task-master list
# Output: Listing tasks from: /project/subdirectory/.taskmaster/tasks/tasks.json
# ⚠ No tasks found

After This Fix

cd /project/subdirectory
task-master list
# Output: Listing tasks from: /project/.taskmaster/tasks/tasks.json
# [Shows tasks from parent project]

Use Cases Enabled

  • Multi-repo monorepos: Global Task Master configuration at root coordinating work across multiple repositories
  • Deep directory structures: Developers can run commands from any subdirectory
  • Microservices architectures: Single Task Master instance managing multiple service repositories
  • Team workflows: Consistent experience regardless of current working directory

Testing Instructions

  1. Initialize Task Master in a project root:

    task-master init
    
  2. Navigate to a subdirectory:

    cd some/deep/subdirectory
    
  3. Run any task-master command:

    task-master list
    
  4. Verify it finds the parent .taskmaster directory

Checklist

  • Code changes implemented
  • Unit tests added
  • All tests passing
  • Documentation updated (code comments)
  • No breaking changes
  • Maintains backward compatibility

Closes #1301

Summary by CodeRabbit

  • Bug Fixes

    • More reliable project root detection from nested directories with broader marker support.
    • Graceful handling of permission errors and safe traversal with depth limits and root detection.
    • Consistent fallback to the current directory when no markers are found.
  • Documentation

    • Updated changelogs, including 0.29.0 notes and migration guidance.
  • Chores

    • Version bumps (core app to 0.29.0, extension to 0.25.6, docs to 0.0.6); added plugin changelog entries.
  • Tests

    • Added comprehensive unit tests covering traversal, marker precedence, errors, and edge cases.
*Originally created by @bjcoombs on 10/13/2025* ## Description Fixes #1301 Enhances the `findProjectRoot()` function to correctly traverse parent directories when running task-master commands from subdirectories, enabling Task Master to work seamlessly in multi-repo projects and deep directory structures. ## Changes Made ### Core Improvements 1. **Enhanced Error Handling** - Added try-catch around `fs.existsSync()` to gracefully handle permission errors - Allows traversal to continue even if some directories are inaccessible 2. **Improved Root Detection** - Added safety check for when `path.dirname()` returns the same path - Prevents infinite loops when reaching filesystem root 3. **Better Project Marker Ordering** - Prioritized Task Master-specific markers (`.taskmaster`, config files) - Ensures Task Master projects are detected before generic markers 4. **Expanded Project Support** - Added markers for: Rust (`Cargo.toml`), Go (`go.mod`), Python (`pyproject.toml`, `requirements.txt`), Ruby (`Gemfile`), PHP (`composer.json`) - Improves cross-platform and multi-language project compatibility 5. **Enhanced Documentation** - Improved code comments and function documentation - Clarified traversal logic and fallback behavior ### Testing - Added comprehensive unit tests in `tests/unit/path-utils-find-project-root.test.js` - 12 test cases covering: - Parent directory traversal for various markers - Multi-level directory traversal - Permission error handling - Filesystem root detection - Edge cases (empty paths, relative paths, max depth) - All tests passing ✅ ## Before This Fix ```bash cd /project/subdirectory task-master list # Output: Listing tasks from: /project/subdirectory/.taskmaster/tasks/tasks.json # ⚠ No tasks found ``` ## After This Fix ```bash cd /project/subdirectory task-master list # Output: Listing tasks from: /project/.taskmaster/tasks/tasks.json # [Shows tasks from parent project] ``` ## Use Cases Enabled - **Multi-repo monorepos**: Global Task Master configuration at root coordinating work across multiple repositories - **Deep directory structures**: Developers can run commands from any subdirectory - **Microservices architectures**: Single Task Master instance managing multiple service repositories - **Team workflows**: Consistent experience regardless of current working directory ## Testing Instructions 1. Initialize Task Master in a project root: ```bash task-master init ``` 2. Navigate to a subdirectory: ```bash cd some/deep/subdirectory ``` 3. Run any task-master command: ```bash task-master list ``` 4. Verify it finds the parent `.taskmaster` directory ## Checklist - [x] Code changes implemented - [x] Unit tests added - [x] All tests passing - [x] Documentation updated (code comments) - [x] No breaking changes - [x] Maintains backward compatibility ## Related Issues Closes #1301 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Bug Fixes - More reliable project root detection from nested directories with broader marker support. - Graceful handling of permission errors and safe traversal with depth limits and root detection. - Consistent fallback to the current directory when no markers are found. - Documentation - Updated changelogs, including 0.29.0 notes and migration guidance. - Chores - Version bumps (core app to 0.29.0, extension to 0.25.6, docs to 0.0.6); added plugin changelog entries. - Tests - Added comprehensive unit tests covering traversal, marker precedence, errors, and edge cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
navan closed this issue 2025-10-14 15:38:11 -06:00
Sign in to join this conversation.
No labels
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:installation
area:installation
area:installation
area:installation
area:installation
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:vscode-extension
area:vscode-extension
area:vscode-extension
area:vscode-extension
area:vscode-extension
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
help wanted
help wanted
help wanted
help wanted
help wanted
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
integration request
integration request
integration request
integration request
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
low-priority
low-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
provider:anthropic
provider:anthropic
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:gemini-cli
provider:openai
provider:perplexity
question
question
question
question
question
question
question
question
question
question
question
question
question
question
refactor
refactor
wontfix
wontfix
wontfix
wontfix
wontfix
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/claude-task-master#11
No description provided.