Compare commits

..

3 Commits

Author SHA1 Message Date
Ralph Khreish
17ef607c41 chore: add prettier package 2025-04-09 00:26:56 +02:00
Ralph Khreish
d95aaf5316 chore: run npm run format 2025-04-09 00:25:27 +02:00
Ralph Khreish
8a3841e195 chore: add prettier config 2025-04-09 00:23:09 +02:00
94 changed files with 2429 additions and 5218 deletions

View File

@@ -0,0 +1,5 @@
---
"task-master-ai": patch
---
Add CI for testing

View File

@@ -0,0 +1,5 @@
---
"task-master-ai": patch
---
Fix github actions creating npm releases on next branch push

View File

@@ -0,0 +1,302 @@
---
"task-master-ai": patch
---
- Adjusts the MCP server invokation in the mcp.json we ship with `task-master init`. Fully functional now.
- Rename the npx -y command. It's now `npx -y task-master-ai task-master-mcp`
- Add additional binary alias: `task-master-mcp-server` pointing to the same MCP server script
- **Significant improvements to model configuration:**
- Increase context window from 64k to 128k tokens (MAX_TOKENS=128000) for handling larger codebases
- Reduce temperature from 0.4 to 0.2 for more consistent, deterministic outputs
- Set default model to "claude-3-7-sonnet-20250219" in configuration
- Update Perplexity model to "sonar-pro" for research operations
- Increase default subtasks generation from 4 to 5 for more granular task breakdown
- Set consistent default priority to "medium" for all new tasks
- **Clarify environment configuration approaches:**
- For direct MCP usage: Configure API keys directly in `.cursor/mcp.json`
- For npm package usage: Configure API keys in `.env` file
- Update templates with clearer placeholder values and formatting
- Provide explicit documentation about configuration methods in both environments
- Use consistent placeholder format "YOUR_ANTHROPIC_API_KEY_HERE" in mcp.json
- Rename MCP tools to better align with API conventions and natural language in client chat:
- Rename `list-tasks` to `get-tasks` for more intuitive client requests like "get my tasks"
- Rename `show-task` to `get-task` for consistency with GET-based API naming conventions
- **Refine AI-based MCP tool implementation patterns:**
- Establish clear responsibilities for direct functions vs MCP tools when handling AI operations
- Update MCP direct function signatures to expect `context = { session }` for AI-based tools, without `reportProgress`
- Clarify that AI client initialization, API calls, and response parsing should be handled within the direct function
- Define standard error codes for AI operations (`AI_CLIENT_ERROR`, `RESPONSE_PARSING_ERROR`, etc.)
- Document that `reportProgress` should not be used within direct functions due to client validation issues
- Establish that progress indication within direct functions should use standard logging (`log.info()`)
- Clarify that `AsyncOperationManager` should manage progress reporting at the MCP tool layer, not in direct functions
- Update `mcp.mdc` rule to reflect the refined patterns for AI-based MCP tools
- **Document and implement the Logger Wrapper Pattern:**
- Add comprehensive documentation in `mcp.mdc` and `utilities.mdc` on the Logger Wrapper Pattern
- Explain the dual purpose of the wrapper: preventing runtime errors and controlling output format
- Include implementation examples with detailed explanations of why and when to use this pattern
- Clearly document that this pattern has proven successful in resolving issues in multiple MCP tools
- Cross-reference between rule files to ensure consistent guidance
- **Fix critical issue in `analyze-project-complexity` MCP tool:**
- Implement proper logger wrapper in `analyzeTaskComplexityDirect` to fix `mcpLog[level] is not a function` errors
- Update direct function to handle both Perplexity and Claude AI properly for research-backed analysis
- Improve silent mode handling with proper wasSilent state tracking
- Add comprehensive error handling for AI client errors and report file parsing
- Ensure proper report format detection and analysis with fallbacks
- Fix variable name conflicts between the `report` logging function and data structures in `analyzeTaskComplexity`
- **Fix critical issue in `update-task` MCP tool:**
- Implement proper logger wrapper in `updateTaskByIdDirect` to ensure mcpLog[level] calls work correctly
- Update Zod schema in `update-task.js` to accept both string and number type IDs
- Fix silent mode implementation with proper try/finally blocks
- Add comprehensive error handling for missing parameters, invalid task IDs, and failed updates
- **Refactor `update-subtask` MCP tool to follow established patterns:**
- Update `updateSubtaskByIdDirect` function to accept `context = { session }` parameter
- Add proper AI client initialization with error handling for both Anthropic and Perplexity
- Implement the Logger Wrapper Pattern to prevent mcpLog[level] errors
- Support both string and number subtask IDs with appropriate validation
- Update MCP tool to pass session to direct function but not reportProgress
- Remove commented-out calls to reportProgress for cleaner code
- Add comprehensive error handling for various failure scenarios
- Implement proper silent mode with try/finally blocks
- Ensure detailed successful update response information
- **Fix issues in `set-task-status` MCP tool:**
- Remove reportProgress parameter as it's not needed
- Improve project root handling for better session awareness
- Reorganize function call arguments for setTaskStatusDirect
- Add proper silent mode handling with try/catch/finally blocks
- Enhance logging for both success and error cases
- **Refactor `update` MCP tool to follow established patterns:**
- Update `updateTasksDirect` function to accept `context = { session }` parameter
- Add proper AI client initialization with error handling
- Update MCP tool to pass session to direct function but not reportProgress
- Simplify parameter validation using string type for 'from' parameter
- Improve error handling for AI client errors
- Implement proper silent mode handling with try/finally blocks
- Use `isSilentMode()` function instead of accessing global variables directly
- **Refactor `expand-task` MCP tool to follow established patterns:**
- Update `expandTaskDirect` function to accept `context = { session }` parameter
- Add proper AI client initialization with error handling
- Update MCP tool to pass session to direct function but not reportProgress
- Add comprehensive tests for the refactored implementation
- Improve error handling for AI client errors
- Remove non-existent 'force' parameter from direct function implementation
- Ensure direct function parameters match core function parameters
- Implement proper silent mode handling with try/finally blocks
- Use `isSilentMode()` function instead of accessing global variables directly
- **Refactor `parse-prd` MCP tool to follow established patterns:**
- Update `parsePRDDirect` function to accept `context = { session }` parameter for proper AI initialization
- Implement AI client initialization with proper error handling using `getAnthropicClientForMCP`
- Add the Logger Wrapper Pattern to ensure proper logging via `mcpLog`
- Update the core `parsePRD` function to accept an AI client parameter
- Implement proper silent mode handling with try/finally blocks
- Remove `reportProgress` usage from MCP tool for better client compatibility
- Fix console output that was breaking the JSON response format
- Improve error handling with specific error codes
- Pass session object to the direct function correctly
- Update task-manager-core.js to export AI client utilities for better organization
- Ensure proper option passing between functions to maintain logging context
- **Update MCP Logger to respect silent mode:**
- Import and check `isSilentMode()` function in logger implementation
- Skip all logging when silent mode is enabled
- Prevent console output from interfering with JSON responses
- Fix "Unexpected token 'I', "[INFO] Gene"... is not valid JSON" errors by suppressing log output during silent mode
- **Refactor `expand-all` MCP tool to follow established patterns:**
- Update `expandAllTasksDirect` function to accept `context = { session }` parameter
- Add proper AI client initialization with error handling for research-backed expansion
- Pass session to direct function but not reportProgress in the MCP tool
- Implement directory switching to work around core function limitations
- Add comprehensive error handling with specific error codes
- Ensure proper restoration of working directory after execution
- Use try/finally pattern for both silent mode and directory management
- Add comprehensive tests for the refactored implementation
- **Standardize and improve silent mode implementation across MCP direct functions:**
- Add proper import of all silent mode utilities: `import { enableSilentMode, disableSilentMode, isSilentMode } from 'utils.js'`
- Replace direct access to global silentMode variable with `isSilentMode()` function calls
- Implement consistent try/finally pattern to ensure silent mode is always properly disabled
- Add error handling with finally blocks to prevent silent mode from remaining enabled after errors
- Create proper mixed parameter/global silent mode check pattern: `const isSilent = options.silentMode || (typeof options.silentMode === 'undefined' && isSilentMode())`
- Update all direct functions to follow the new implementation pattern
- Fix issues with silent mode not being properly disabled when errors occur
- **Improve parameter handling between direct functions and core functions:**
- Verify direct function parameters match core function signatures
- Remove extraction and use of parameters that don't exist in core functions (e.g., 'force')
- Implement appropriate type conversion for parameters (e.g., `parseInt(args.id, 10)`)
- Set defaults that match core function expectations
- Add detailed documentation on parameter matching in guidelines
- Add explicit examples of correct parameter handling patterns
- **Create standardized MCP direct function implementation checklist:**
- Comprehensive imports and dependencies section
- Parameter validation and matching guidelines
- Silent mode implementation best practices
- Error handling and response format patterns
- Path resolution and core function call guidelines
- Function export and testing verification steps
- Specific issues to watch for related to silent mode, parameters, and error cases
- Add checklist to subtasks for uniform implementation across all direct functions
- **Implement centralized AI client utilities for MCP tools:**
- Create new `ai-client-utils.js` module with standardized client initialization functions
- Implement session-aware AI client initialization for both Anthropic and Perplexity
- Add comprehensive error handling with user-friendly error messages
- Create intelligent AI model selection based on task requirements
- Implement model configuration utilities that respect session environment variables
- Add extensive unit tests for all utility functions
- Significantly improve MCP tool reliability for AI operations
- **Specific implementations include:**
- `getAnthropicClientForMCP`: Initializes Anthropic client with session environment variables
- `getPerplexityClientForMCP`: Initializes Perplexity client with session environment variables
- `getModelConfig`: Retrieves model parameters from session or fallbacks to defaults
- `getBestAvailableAIModel`: Selects the best available model based on requirements
- `handleClaudeError`: Processes Claude API errors into user-friendly messages
- **Updated direct functions to use centralized AI utilities:**
- Refactored `addTaskDirect` to use the new AI client utilities with proper AsyncOperationManager integration
- Implemented comprehensive error handling for API key validation, AI processing, and response parsing
- Added session-aware parameter handling with proper propagation of context to AI streaming functions
- Ensured proper fallback to process.env when session variables aren't available
- **Refine AI services for reusable operations:**
- Refactor `ai-services.js` to support consistent AI operations across CLI and MCP
- Implement shared helpers for streaming responses, prompt building, and response parsing
- Standardize client initialization patterns with proper session parameter handling
- Enhance error handling and loading indicator management
- Fix process exit issues to prevent MCP server termination on API errors
- Ensure proper resource cleanup in all execution paths
- Add comprehensive test coverage for AI service functions
- **Key improvements include:**
- Stream processing safety with explicit completion detection
- Standardized function parameter patterns
- Session-aware parameter extraction with sensible defaults
- Proper cleanup using try/catch/finally patterns
- **Optimize MCP response payloads:**
- Add custom `processTaskResponse` function to `get-task` MCP tool to filter out unnecessary `allTasks` array data
- Significantly reduce response size by returning only the specific requested task instead of all tasks
- Preserve dependency status relationships for the UI/CLI while keeping MCP responses lean and efficient
- **Implement complete remove-task functionality:**
- Add `removeTask` core function to permanently delete tasks or subtasks from tasks.json
- Implement CLI command `remove-task` with confirmation prompt and force flag support
- Create MCP `remove_task` tool for AI-assisted task removal
- Automatically handle dependency cleanup by removing references to deleted tasks
- Update task files after removal to maintain consistency
- Provide robust error handling and detailed feedback messages
- **Update Cursor rules and documentation:**
- Enhance `new_features.mdc` with comprehensive guidelines for implementing removal commands
- Update `commands.mdc` with best practices for confirmation flows and cleanup procedures
- Expand `mcp.mdc` with detailed instructions for MCP tool implementation patterns
- Add examples of proper error handling and parameter validation to all relevant rules
- Include new sections about handling dependencies during task removal operations
- Document naming conventions and implementation patterns for destructive operations
- Update silent mode implementation documentation with proper examples
- Add parameter handling guidelines emphasizing matching with core functions
- Update architecture documentation with dedicated section on silent mode implementation
- **Implement silent mode across all direct functions:**
- Add `enableSilentMode` and `disableSilentMode` utility imports to all direct function files
- Wrap all core function calls with silent mode to prevent console logs from interfering with JSON responses
- Add comprehensive error handling to ensure silent mode is disabled even when errors occur
- Fix "Unexpected token 'I', "[INFO] Gene"... is not valid JSON" errors by suppressing log output
- Apply consistent silent mode pattern across all MCP direct functions
- Maintain clean JSON responses for better integration with client tools
- **Implement AsyncOperationManager for background task processing:**
- Add new `async-manager.js` module to handle long-running operations asynchronously
- Support background execution of computationally intensive tasks like expansion and analysis
- Implement unique operation IDs with UUID generation for reliable tracking
- Add operation status tracking (pending, running, completed, failed)
- Create `get_operation_status` MCP tool to check on background task progress
- Forward progress reporting from background tasks to the client
- Implement operation history with automatic cleanup of completed operations
- Support proper error handling in background tasks with detailed status reporting
- Maintain context (log, session) for background operations ensuring consistent behavior
- **Implement initialize_project command:**
- Add new MCP tool to allow project setup via integrated MCP clients
- Create `initialize_project` direct function with proper parameter handling
- Improve onboarding experience by adding to mcp.json configuration
- Support project-specific metadata like name, description, and version
- Handle shell alias creation with proper confirmation
- Improve first-time user experience in AI environments
- **Refactor project root handling for MCP Server:**
- **Prioritize Session Roots**: MCP tools now extract the project root path directly from `session.roots[0].uri` provided by the client (e.g., Cursor).
- **New Utility `getProjectRootFromSession`**: Added to `mcp-server/src/tools/utils.js` to encapsulate session root extraction and decoding. **Further refined for more reliable detection, especially in integrated environments, including deriving root from script path and avoiding fallback to '/'.**
- **Simplify `findTasksJsonPath`**: The core path finding utility in `mcp-server/src/core/utils/path-utils.js` now prioritizes the `projectRoot` passed in `args` (originating from the session). Removed checks for `TASK_MASTER_PROJECT_ROOT` env var (we do not use this anymore) and package directory fallback. **Enhanced error handling to include detailed debug information (paths searched, CWD, server dir, etc.) and clearer potential solutions when `tasks.json` is not found.**
- **Retain CLI Fallbacks**: Kept `lastFoundProjectRoot` cache check and CWD search in `findTasksJsonPath` for compatibility with direct CLI usage.
- Updated all MCP tools to use the new project root handling:
- Tools now call `getProjectRootFromSession` to determine the root.
- This root is passed explicitly as `projectRoot` in the `args` object to the corresponding `*Direct` function.
- Direct functions continue to use the (now simplified) `findTasksJsonPath` to locate `tasks.json` within the provided root.
- This ensures tools work reliably in integrated environments without requiring the user to specify `--project-root`.
- Add comprehensive PROJECT_MARKERS array for detecting common project files (used in CLI fallback logic).
- Improved error messages with specific troubleshooting guidance.
- **Enhanced logging:**
- Indicate the source of project root selection more clearly.
- **Add verbose logging in `get-task.js` to trace session object content and resolved project root path, aiding debugging.**
- DRY refactoring by centralizing path utilities in `core/utils/path-utils.js` and session handling in `tools/utils.js`.
- Keep caching of `lastFoundProjectRoot` for CLI performance.
- Split monolithic task-master-core.js into separate function files within direct-functions directory.
- Implement update-task MCP command for updating a single task by ID.
- Implement update-subtask MCP command for appending information to specific subtasks.
- Implement generate MCP command for creating individual task files from tasks.json.
- Implement set-status MCP command for updating task status.
- Implement get-task MCP command for displaying detailed task information (renamed from show-task).
- Implement next-task MCP command for finding the next task to work on.
- Implement expand-task MCP command for breaking down tasks into subtasks.
- Implement add-task MCP command for creating new tasks using AI assistance.
- Implement add-subtask MCP command for adding subtasks to existing tasks.
- Implement remove-subtask MCP command for removing subtasks from parent tasks.
- Implement expand-all MCP command for expanding all tasks into subtasks.
- Implement analyze-complexity MCP command for analyzing task complexity.
- Implement clear-subtasks MCP command for clearing subtasks from parent tasks.
- Implement remove-dependency MCP command for removing dependencies from tasks.
- Implement validate-dependencies MCP command for checking validity of task dependencies.
- Implement fix-dependencies MCP command for automatically fixing invalid dependencies.
- Implement complexity-report MCP command for displaying task complexity analysis reports.
- Implement add-dependency MCP command for creating dependency relationships between tasks.
- Implement get-tasks MCP command for listing all tasks (renamed from list-tasks).
- Implement `initialize_project` MCP tool to allow project setup via MCP client and radically improve and simplify onboarding by adding to mcp.json (e.g., Cursor).
- Enhance documentation and tool descriptions:
- Create new `taskmaster.mdc` Cursor rule for comprehensive MCP tool and CLI command reference.
- Bundle taskmaster.mdc with npm package and include in project initialization.
- Add detailed descriptions for each tool's purpose, parameters, and common use cases.
- Include natural language patterns and keywords for better intent recognition.
- Document parameter descriptions with clear examples and default values.
- Add usage examples and context for each command/tool.
- **Update documentation (`mcp.mdc`, `utilities.mdc`, `architecture.mdc`, `new_features.mdc`, `commands.mdc`) to reflect the new session-based project root handling and the preferred MCP vs. CLI interaction model.**
- Improve clarity around project root auto-detection in tool documentation.
- Update tool descriptions to better reflect their actual behavior and capabilities.
- Add cross-references between related tools and commands.
- Include troubleshooting guidance in tool descriptions.
- **Add default values for `DEFAULT_SUBTASKS` and `DEFAULT_PRIORITY` to the example `.cursor/mcp.json` configuration.**
- Document MCP server naming conventions in architecture.mdc and mcp.mdc files (file names use kebab-case, direct functions use camelCase with Direct suffix, tool registration functions use camelCase with Tool suffix, and MCP tool names use snake_case).
- Update MCP tool naming to follow more intuitive conventions that better align with natural language requests in client chat applications.
- Enhance task show view with a color-coded progress bar for visualizing subtask completion percentage.
- Add "cancelled" status to UI module status configurations for marking tasks as cancelled without deletion.
- Improve MCP server resource documentation with comprehensive implementation examples and best practices.
- Enhance progress bars with status breakdown visualization showing proportional sections for different task statuses.
- Add improved status tracking for both tasks and subtasks with detailed counts by status.
- Optimize progress bar display with width constraints to prevent UI overflow on smaller terminals.
- Improve status counts display with clear text labels beside status icons for better readability.
- Treat deferred and cancelled tasks as effectively complete for progress calculation while maintaining visual distinction.
- **Fix `reportProgress` calls** to use the correct `{ progress, total? }` format.
- **Standardize logging in core task-manager functions (`expandTask`, `expandAllTasks`, `updateTasks`, `updateTaskById`, `updateSubtaskById`, `parsePRD`, `analyzeTaskComplexity`):**
- Implement a local `report` function in each to handle context-aware logging.
- Use `report` to choose between `mcpLog` (if available) and global `log` (from `utils.js`).
- Only call global `log` when `outputFormat` is 'text' and silent mode is off.
- Wrap CLI UI elements (tables, boxes, spinners) in `outputFormat === 'text'` checks.

View File

@@ -8,7 +8,7 @@
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE", "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
"MODEL": "claude-3-7-sonnet-20250219", "MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro", "PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000, "MAX_TOKENS": 128000,
"TEMPERATURE": 0.2, "TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5, "DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium" "DEFAULT_PRIORITY": "medium"

View File

@@ -14,13 +14,13 @@ alwaysApply: false
- **Purpose**: Defines and registers all CLI commands using Commander.js. - **Purpose**: Defines and registers all CLI commands using Commander.js.
- **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)): - **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)):
- Parses command-line arguments and options. - Parses command-line arguments and options.
- Invokes appropriate functions from other modules to execute commands (e.g., calls `initializeProject` from `init.js` for the `init` command). - Invokes appropriate functions from other modules to execute commands.
- Handles user input and output related to command execution. - Handles user input and output related to command execution.
- Implements input validation and error handling for CLI commands. - Implements input validation and error handling for CLI commands.
- **Key Components**: - **Key Components**:
- `programInstance` (Commander.js `Command` instance): Manages command definitions. - `programInstance` (Commander.js `Command` instance): Manages command definitions.
- `registerCommands(programInstance)`: Function to register all application commands. - `registerCommands(programInstance)`: Function to register all application commands.
- Command action handlers: Functions executed when a specific command is invoked, delegating to core modules. - Command action handlers: Functions executed when a specific command is invoked.
- **[`task-manager.js`](mdc:scripts/modules/task-manager.js): Task Data Management** - **[`task-manager.js`](mdc:scripts/modules/task-manager.js): Task Data Management**
- **Purpose**: Manages task data, including loading, saving, creating, updating, deleting, and querying tasks. - **Purpose**: Manages task data, including loading, saving, creating, updating, deleting, and querying tasks.
@@ -148,23 +148,10 @@ alwaysApply: false
- Robust error handling for background tasks - Robust error handling for background tasks
- **Usage**: Used for CPU-intensive operations like task expansion and PRD parsing - **Usage**: Used for CPU-intensive operations like task expansion and PRD parsing
- **[`init.js`](mdc:scripts/init.js): Project Initialization Logic**
- **Purpose**: Contains the core logic for setting up a new Task Master project structure.
- **Responsibilities**:
- Creates necessary directories (`.cursor/rules`, `scripts`, `tasks`).
- Copies template files (`.env.example`, `.gitignore`, rule files, `dev.js`, etc.).
- Creates or merges `package.json` with required dependencies and scripts.
- Sets up MCP configuration (`.cursor/mcp.json`).
- Optionally initializes a git repository and installs dependencies.
- Handles user prompts for project details *if* called without skip flags (`-y`).
- **Key Function**:
- `initializeProject(options)`: The main function exported and called by the `init` command's action handler in [`commands.js`](mdc:scripts/modules/commands.js). It receives parsed options directly.
- **Note**: This script is used as a module and no longer handles its own argument parsing or direct execution via a separate `bin` file.
- **Data Flow and Module Dependencies**: - **Data Flow and Module Dependencies**:
- **Commands Initiate Actions**: User commands entered via the CLI (parsed by `commander` based on definitions in [`commands.js`](mdc:scripts/modules/commands.js)) are the entry points for most operations. - **Commands Initiate Actions**: User commands entered via the CLI (handled by [`commands.js`](mdc:scripts/modules/commands.js)) are the entry points for most operations.
- **Command Handlers Delegate to Core Logic**: Action handlers within [`commands.js`](mdc:scripts/modules/commands.js) call functions in core modules like [`task-manager.js`](mdc:scripts/modules/task-manager.js), [`dependency-manager.js`](mdc:scripts/modules/dependency-manager.js), and [`init.js`](mdc:scripts/init.js) (for the `init` command) to perform the actual work. - **Command Handlers Delegate to Managers**: Command handlers in [`commands.js`](mdc:scripts/modules/commands.js) call functions in [`task-manager.js`](mdc:scripts/modules/task-manager.js) and [`dependency-manager.js`](mdc:scripts/modules/dependency-manager.js) to perform core task and dependency management logic.
- **UI for Presentation**: [`ui.js`](mdc:scripts/modules/ui.js) is used by command handlers and task/dependency managers to display information to the user. UI functions primarily consume data and format it for output, without modifying core application state. - **UI for Presentation**: [`ui.js`](mdc:scripts/modules/ui.js) is used by command handlers and task/dependency managers to display information to the user. UI functions primarily consume data and format it for output, without modifying core application state.
- **Utilities for Common Tasks**: [`utils.js`](mdc:scripts/modules/utils.js) provides helper functions used by all other modules for configuration, logging, file operations, and common data manipulations. - **Utilities for Common Tasks**: [`utils.js`](mdc:scripts/modules/utils.js) provides helper functions used by all other modules for configuration, logging, file operations, and common data manipulations.
- **AI Services Integration**: AI functionalities (complexity analysis, task expansion, PRD parsing) are invoked from [`task-manager.js`](mdc:scripts/modules/task-manager.js) and potentially [`commands.js`](mdc:scripts/modules/commands.js), likely using functions that would reside in a dedicated `ai-services.js` module or be integrated within `utils.js` or `task-manager.js`. - **AI Services Integration**: AI functionalities (complexity analysis, task expansion, PRD parsing) are invoked from [`task-manager.js`](mdc:scripts/modules/task-manager.js) and potentially [`commands.js`](mdc:scripts/modules/commands.js), likely using functions that would reside in a dedicated `ai-services.js` module or be integrated within `utils.js` or `task-manager.js`.

View File

@@ -24,7 +24,7 @@ While this document details the implementation of Task Master's **CLI commands**
programInstance programInstance
.command('command-name') .command('command-name')
.description('Clear, concise description of what the command does') .description('Clear, concise description of what the command does')
.option('-o, --option <value>', 'Option description', 'default value') .option('-s, --short-option <value>', 'Option description', 'default value')
.option('--long-option <value>', 'Option description') .option('--long-option <value>', 'Option description')
.action(async (options) => { .action(async (options) => {
// Command implementation // Command implementation
@@ -34,8 +34,7 @@ While this document details the implementation of Task Master's **CLI commands**
- **Command Handler Organization**: - **Command Handler Organization**:
- ✅ DO: Keep action handlers concise and focused - ✅ DO: Keep action handlers concise and focused
- ✅ DO: Extract core functionality to appropriate modules - ✅ DO: Extract core functionality to appropriate modules
- ✅ DO: Have the action handler import and call the relevant function(s) from core modules (e.g., `task-manager.js`, `init.js`), passing the parsed `options`. - ✅ DO: Include validation for required parameters
- ✅ DO: Perform basic parameter validation (e.g., checking for required options) within the action handler or at the start of the called core function.
- ❌ DON'T: Implement business logic in command handlers - ❌ DON'T: Implement business logic in command handlers
## Best Practices for Removal/Delete Commands ## Best Practices for Removal/Delete Commands

View File

@@ -37,7 +37,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
* `addAliases`: `Add shell aliases (tm, taskmaster) (default: false).` (CLI: `--aliases`) * `addAliases`: `Add shell aliases (tm, taskmaster) (default: false).` (CLI: `--aliases`)
* `yes`: `Skip prompts and use defaults/provided arguments (default: false).` (CLI: `-y, --yes`) * `yes`: `Skip prompts and use defaults/provided arguments (default: false).` (CLI: `-y, --yes`)
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server. * **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
* **Important:** Once complete, you *MUST* parse a prd in order to generate tasks. There will be no tasks files until then. The next step after initializing should be to create a PRD using the example PRD in scripts/example_prd.txt.
### 2. Parse PRD (`parse_prd`) ### 2. Parse PRD (`parse_prd`)
@@ -51,7 +51,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
* `force`: `Use this to allow Taskmaster to overwrite an existing 'tasks.json' without asking for confirmation.` (CLI: `-f, --force`) * `force`: `Use this to allow Taskmaster to overwrite an existing 'tasks.json' without asking for confirmation.` (CLI: `-f, --force`)
* **Usage:** Useful for bootstrapping a project from an existing requirements document. * **Usage:** Useful for bootstrapping a project from an existing requirements document.
* **Notes:** Task Master will strictly adhere to any specific requirements mentioned in the PRD (libraries, database schemas, frameworks, tech stacks, etc.) while filling in any gaps where the PRD isn't fully specified. Tasks are designed to provide the most direct implementation path while avoiding over-engineering. * **Notes:** Task Master will strictly adhere to any specific requirements mentioned in the PRD (libraries, database schemas, frameworks, tech stacks, etc.) while filling in any gaps where the PRD isn't fully specified. Tasks are designed to provide the most direct implementation path while avoiding over-engineering.
* **Important:** This MCP tool makes AI calls and can take up to a minute to complete. Please inform users to hang tight while the operation is in progress. If the user does not have a PRD, suggest discussing their idea and then use the example PRD in scripts/example_prd.txt as a template for creating the PRD based on their idea, for use with parse-prd. * **Important:** This MCP tool makes AI calls and can take up to a minute to complete. Please inform users to hang tight while the operation is in progress.
--- ---

View File

@@ -5,8 +5,6 @@ globs: "**/*.test.js,tests/**/*"
# Testing Guidelines for Task Master CLI # Testing Guidelines for Task Master CLI
*Note:* Never use asynchronous operations in tests. Always mock tests properly based on the way the tested functions are defined and used. Do not arbitrarily create tests. Based them on the low-level details and execution of the underlying code being tested.
## Test Organization Structure ## Test Organization Structure
- **Unit Tests** (See [`architecture.mdc`](mdc:.cursor/rules/architecture.mdc) for module breakdown) - **Unit Tests** (See [`architecture.mdc`](mdc:.cursor/rules/architecture.mdc) for module breakdown)
@@ -90,122 +88,6 @@ describe('Feature or Function Name', () => {
}); });
``` ```
## Commander.js Command Testing Best Practices
When testing CLI commands built with Commander.js, several special considerations must be made to avoid common pitfalls:
- **Direct Action Handler Testing**
- ✅ **DO**: Test the command action handlers directly rather than trying to mock the entire Commander.js chain
- ✅ **DO**: Create simplified test-specific implementations of command handlers that match the original behavior
- ✅ **DO**: Explicitly handle all options, including defaults and shorthand flags (e.g., `-p` for `--prompt`)
- ✅ **DO**: Include null/undefined checks in test implementations for parameters that might be optional
- ✅ **DO**: Use fixtures from `tests/fixtures/` for consistent sample data across tests
```javascript
// ✅ DO: Create a simplified test version of the command handler
const testAddTaskAction = async (options) => {
options = options || {}; // Ensure options aren't undefined
// Validate parameters
const isManualCreation = options.title && options.description;
const prompt = options.prompt || options.p; // Handle shorthand flags
if (!prompt && !isManualCreation) {
throw new Error('Expected error message');
}
// Call the mocked task manager
return mockTaskManager.addTask(/* parameters */);
};
test('should handle required parameters correctly', async () => {
// Call the test implementation directly
await expect(async () => {
await testAddTaskAction({ file: 'tasks.json' });
}).rejects.toThrow('Expected error message');
});
```
- **Commander Chain Mocking (If Necessary)**
- ✅ **DO**: Mock ALL chainable methods (`option`, `argument`, `action`, `on`, etc.)
- ✅ **DO**: Return `this` (or the mock object) from all chainable method mocks
- ✅ **DO**: Remember to mock not only the initial object but also all objects returned by methods
- ✅ **DO**: Implement a mechanism to capture the action handler for direct testing
```javascript
// If you must mock the Commander.js chain:
const mockCommand = {
command: jest.fn().mockReturnThis(),
description: jest.fn().mockReturnThis(),
option: jest.fn().mockReturnThis(),
argument: jest.fn().mockReturnThis(), // Don't forget this one
action: jest.fn(fn => {
actionHandler = fn; // Capture the handler for testing
return mockCommand;
}),
on: jest.fn().mockReturnThis() // Don't forget this one
};
```
- **Parameter Handling**
- ✅ **DO**: Check for both main flag and shorthand flags (e.g., `prompt` and `p`)
- ✅ **DO**: Handle parameters like Commander would (comma-separated lists, etc.)
- ✅ **DO**: Set proper default values as defined in the command
- ✅ **DO**: Validate that required parameters are actually required in tests
```javascript
// Parse dependencies like Commander would
const dependencies = options.dependencies
? options.dependencies.split(',').map(id => id.trim())
: [];
```
- **Environment and Session Handling**
- ✅ **DO**: Properly mock session objects when required by functions
- ✅ **DO**: Reset environment variables between tests if modified
- ✅ **DO**: Use a consistent pattern for environment-dependent tests
```javascript
// Session parameter mock pattern
const sessionMock = { session: process.env };
// In test:
expect(mockAddTask).toHaveBeenCalledWith(
expect.any(String),
'Test prompt',
[],
'medium',
sessionMock,
false,
null,
null
);
```
- **Common Pitfalls to Avoid**
- ❌ **DON'T**: Try to use the real action implementation without proper mocking
- ❌ **DON'T**: Mock Commander partially - either mock it completely or test the action directly
- ❌ **DON'T**: Forget to handle optional parameters that may be undefined
- ❌ **DON'T**: Neglect to test shorthand flag functionality (e.g., `-p`, `-r`)
- ❌ **DON'T**: Create circular dependencies in your test mocks
- ❌ **DON'T**: Access variables before initialization in your test implementations
- ❌ **DON'T**: Include actual command execution in unit tests
- ❌ **DON'T**: Overwrite the same file path in multiple tests
```javascript
// ❌ DON'T: Create circular references in mocks
const badMock = {
method: jest.fn().mockImplementation(() => badMock.method())
};
// ❌ DON'T: Access uninitialized variables
const badImplementation = () => {
const result = uninitialized;
let uninitialized = 'value';
return result;
};
```
## Jest Module Mocking Best Practices ## Jest Module Mocking Best Practices
- **Mock Hoisting Behavior** - **Mock Hoisting Behavior**
@@ -670,102 +552,6 @@ npm test -- -t "pattern to match"
}); });
``` ```
## Testing AI Service Integrations
- **DO NOT import real AI service clients**
- ❌ DON'T: Import actual AI clients from their libraries
- ✅ DO: Create fully mocked versions that return predictable responses
```javascript
// ❌ DON'T: Import and instantiate real AI clients
import { Anthropic } from '@anthropic-ai/sdk';
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
// ✅ DO: Mock the entire module with controlled behavior
jest.mock('@anthropic-ai/sdk', () => ({
Anthropic: jest.fn().mockImplementation(() => ({
messages: {
create: jest.fn().mockResolvedValue({
content: [{ type: 'text', text: 'Mocked AI response' }]
})
}
}))
}));
```
- **DO NOT rely on environment variables for API keys**
- ❌ DON'T: Assume environment variables are set in tests
- ✅ DO: Set mock environment variables in test setup
```javascript
// In tests/setup.js or at the top of test file
process.env.ANTHROPIC_API_KEY = 'test-mock-api-key-for-tests';
process.env.PERPLEXITY_API_KEY = 'test-mock-perplexity-key-for-tests';
```
- **DO NOT use real AI client initialization logic**
- ❌ DON'T: Use code that attempts to initialize or validate real AI clients
- ✅ DO: Create test-specific paths that bypass client initialization
```javascript
// ❌ DON'T: Test functions that require valid AI client initialization
// This will fail without proper API keys or network access
test('should use AI client', async () => {
const result = await functionThatInitializesAIClient();
expect(result).toBeDefined();
});
// ✅ DO: Test with bypassed initialization or manual task paths
test('should handle manual task creation without AI', () => {
// Using a path that doesn't require AI client initialization
const result = addTaskDirect({
title: 'Manual Task',
description: 'Test Description'
}, mockLogger);
expect(result.success).toBe(true);
});
```
## Testing Asynchronous Code
- **DO NOT rely on asynchronous operations in tests**
- ❌ DON'T: Use real async/await or Promise resolution in tests
- ✅ DO: Make all mocks return synchronous values when possible
```javascript
// ❌ DON'T: Use real async functions that might fail unpredictably
test('should handle async operation', async () => {
const result = await realAsyncFunction(); // Can time out or fail for external reasons
expect(result).toBe(expectedValue);
});
// ✅ DO: Make async operations synchronous in tests
test('should handle operation', () => {
mockAsyncFunction.mockReturnValue({ success: true, data: 'test' });
const result = functionUnderTest();
expect(result).toEqual({ success: true, data: 'test' });
});
```
- **DO NOT test exact error messages**
- ❌ DON'T: Assert on exact error message text that might change
- ✅ DO: Test for error presence and general properties
```javascript
// ❌ DON'T: Test for exact error message text
expect(result.error).toBe('Could not connect to API: Network error');
// ✅ DO: Test for general error properties or message patterns
expect(result.success).toBe(false);
expect(result.error).toContain('Could not connect');
// Or even better:
expect(result).toMatchObject({
success: false,
error: expect.stringContaining('connect')
});
```
## Reliable Testing Techniques ## Reliable Testing Techniques
- **Create Simplified Test Functions** - **Create Simplified Test Functions**
@@ -778,125 +564,99 @@ npm test -- -t "pattern to match"
const setTaskStatus = async (taskId, newStatus) => { const setTaskStatus = async (taskId, newStatus) => {
const tasksPath = 'tasks/tasks.json'; const tasksPath = 'tasks/tasks.json';
const data = await readJSON(tasksPath); const data = await readJSON(tasksPath);
// [implementation] // Update task status logic
await writeJSON(tasksPath, data); await writeJSON(tasksPath, data);
return { success: true }; return data;
}; };
// Test-friendly version (easier to test) // Test-friendly simplified function (easy to test)
const updateTaskStatus = (tasks, taskId, newStatus) => { const testSetTaskStatus = (tasksData, taskIdInput, newStatus) => {
// Pure logic without side effects // Same core logic without file operations
const updatedTasks = [...tasks]; // Update task status logic on provided tasksData object
const taskIndex = findTaskById(updatedTasks, taskId); return tasksData; // Return updated data for assertions
if (taskIndex === -1) return { success: false, error: 'Task not found' };
updatedTasks[taskIndex].status = newStatus;
return { success: true, tasks: updatedTasks };
}; };
``` ```
- **Avoid Real File System Operations**
- Never write to real files during tests
- Create test-specific versions of file operation functions
- Mock all file system operations including read, write, exists, etc.
- Verify function behavior using the in-memory data structures
```javascript
// Mock file operations
const mockReadJSON = jest.fn();
const mockWriteJSON = jest.fn();
jest.mock('../../scripts/modules/utils.js', () => ({
readJSON: mockReadJSON,
writeJSON: mockWriteJSON,
}));
test('should update task status correctly', () => {
// Setup mock data
const testData = JSON.parse(JSON.stringify(sampleTasks));
mockReadJSON.mockReturnValue(testData);
// Call the function that would normally modify files
const result = testSetTaskStatus(testData, '1', 'done');
// Assert on the in-memory data structure
expect(result.tasks[0].status).toBe('done');
});
```
- **Data Isolation Between Tests**
- Always create fresh copies of test data for each test
- Use `JSON.parse(JSON.stringify(original))` for deep cloning
- Reset all mocks before each test with `jest.clearAllMocks()`
- Avoid state that persists between tests
```javascript
beforeEach(() => {
jest.clearAllMocks();
// Deep clone the test data
testTasksData = JSON.parse(JSON.stringify(sampleTasks));
});
```
- **Test All Path Variations**
- Regular tasks and subtasks
- Single items and multiple items
- Success paths and error paths
- Edge cases (empty data, invalid inputs, etc.)
```javascript
// Multiple test cases covering different scenarios
test('should update regular task status', () => {
/* test implementation */
});
test('should update subtask status', () => {
/* test implementation */
});
test('should update multiple tasks when given comma-separated IDs', () => {
/* test implementation */
});
test('should throw error for non-existent task ID', () => {
/* test implementation */
});
```
- **Stabilize Tests With Predictable Input/Output**
- Use consistent, predictable test fixtures
- Avoid random values or time-dependent data
- Make tests deterministic for reliable CI/CD
- Control all variables that might affect test outcomes
```javascript
// Use a specific known date instead of current date
const fixedDate = new Date('2023-01-01T12:00:00Z');
jest.spyOn(global, 'Date').mockImplementation(() => fixedDate);
```
See [tests/README.md](mdc:tests/README.md) for more details on the testing approach. See [tests/README.md](mdc:tests/README.md) for more details on the testing approach.
Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options. Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options.
## Variable Hoisting and Module Initialization Issues
When testing ES modules or working with complex module imports, you may encounter variable hoisting and initialization issues. These can be particularly tricky to debug and often appear as "Cannot access 'X' before initialization" errors.
- **Understanding Module Initialization Order**
- ✅ **DO**: Declare and initialize global variables at the top of modules
- ✅ **DO**: Use proper function declarations to avoid hoisting issues
- ✅ **DO**: Initialize variables before they are referenced, especially in imported modules
- ✅ **DO**: Be aware that imports are hoisted to the top of the file
```javascript
// ✅ DO: Define global state variables at the top of the module
let silentMode = false; // Declare and initialize first
const CONFIG = { /* configuration */ };
function isSilentMode() {
return silentMode; // Reference variable after it's initialized
}
function log(level, message) {
if (isSilentMode()) return; // Use the function instead of accessing variable directly
// ...
}
```
- **Testing Modules with Initialization-Dependent Functions**
- ✅ **DO**: Create test-specific implementations that initialize all variables correctly
- ✅ **DO**: Use factory functions in mocks to ensure proper initialization order
- ✅ **DO**: Be careful with how you mock or stub functions that depend on module state
```javascript
// ✅ DO: Test-specific implementation that avoids initialization issues
const testLog = (level, ...args) => {
// Local implementation with proper initialization
const isSilent = false; // Explicit initialization
if (isSilent) return;
// Test implementation...
};
```
- **Common Hoisting-Related Errors to Avoid**
- ❌ **DON'T**: Reference variables before their declaration in module scope
- ❌ **DON'T**: Create circular dependencies between modules
- ❌ **DON'T**: Rely on variable initialization order across module boundaries
- ❌ **DON'T**: Define functions that use hoisted variables before they're initialized
```javascript
// ❌ DON'T: Create reference-before-initialization patterns
function badFunction() {
if (silentMode) { /* ... */ } // ReferenceError if silentMode is declared later
}
let silentMode = false;
// ❌ DON'T: Create cross-module references that depend on initialization order
// module-a.js
import { getSetting } from './module-b.js';
export const config = { value: getSetting() };
// module-b.js
import { config } from './module-a.js';
export function getSetting() {
return config.value; // Circular dependency causing initialization issues
}
```
- **Dynamic Imports as a Solution**
- ✅ **DO**: Use dynamic imports (`import()`) to avoid initialization order issues
- ✅ **DO**: Structure modules to avoid circular dependencies that cause initialization issues
- ✅ **DO**: Consider factory functions for modules with complex state
```javascript
// ✅ DO: Use dynamic imports to avoid initialization issues
async function getTaskManager() {
return import('./task-manager.js');
}
async function someFunction() {
const taskManager = await getTaskManager();
return taskManager.someMethod();
}
```
- **Testing Approach for Modules with Initialization Issues**
- ✅ **DO**: Create self-contained test implementations rather than using real implementations
- ✅ **DO**: Mock dependencies at module boundaries instead of trying to mock deep dependencies
- ✅ **DO**: Isolate module-specific state in tests
```javascript
// ✅ DO: Create isolated test implementation instead of reusing module code
test('should log messages when not in silent mode', () => {
// Local test implementation instead of importing from module
const testLog = (level, message) => {
if (false) return; // Always non-silent for this test
mockConsole(level, message);
};
testLog('info', 'test message');
expect(mockConsole).toHaveBeenCalledWith('info', 'test message');
});
```

View File

@@ -5,7 +5,7 @@ PERPLEXITY_API_KEY=your_perplexity_api_key_here # Format: pplx-...
# Model Configuration # Model Configuration
MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229 MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229
PERPLEXITY_MODEL=sonar-pro # Perplexity model for research-backed subtasks PERPLEXITY_MODEL=sonar-pro # Perplexity model for research-backed subtasks
MAX_TOKENS=64000 # Maximum tokens for model responses MAX_TOKENS=128000 # Maximum tokens for model responses
TEMPERATURE=0.2 # Temperature for model responses (0.0-1.0) TEMPERATURE=0.2 # Temperature for model responses (0.0-1.0)
# Logging Configuration # Logging Configuration

View File

@@ -1,39 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: 'bug: '
labels: bug
assignees: ''
---
### Description
Detailed description of the problem, including steps to reproduce the issue.
### Steps to Reproduce
1. Step-by-step instructions to reproduce the issue
2. Include command examples or UI interactions
### Expected Behavior
Describe clearly what the expected outcome or behavior should be.
### Actual Behavior
Describe clearly what the actual outcome or behavior is.
### Screenshots or Logs
Provide screenshots, logs, or error messages if applicable.
### Environment
- Task Master version:
- Node.js version:
- Operating system:
- IDE (if applicable):
### Additional Context
Any additional information or context that might help diagnose the issue.

View File

@@ -1,51 +0,0 @@
---
name: Enhancements & feature requests
about: Suggest an idea for this project
title: 'feat: '
labels: enhancement
assignees: ''
---
> "Direct quote or clear summary of user request or need or user story."
### Motivation
Detailed explanation of why this feature is important. Describe the problem it solves or the benefit it provides.
### Proposed Solution
Clearly describe the proposed feature, including:
- High-level overview of the feature
- Relevant technologies or integrations
- How it fits into the existing workflow or architecture
### High-Level Workflow
1. Step-by-step description of how the feature will be implemented
2. Include necessary intermediate milestones
### Key Elements
- Bullet-point list of technical or UX/UI enhancements
- Mention specific integrations or APIs
- Highlight changes needed in existing data models or commands
### Example Workflow
Provide a clear, concrete example demonstrating the feature:
```shell
$ task-master [action]
→ Expected response/output
```
### Implementation Considerations
- Dependencies on external components or APIs
- Backward compatibility requirements
- Potential performance impacts or resource usage
### Out of Scope (Future Considerations)
Clearly list any features or improvements not included but relevant for future iterations.

View File

@@ -1,31 +0,0 @@
---
name: Feedback
about: Give us specific feedback on the product/approach/tech
title: 'feedback: '
labels: feedback
assignees: ''
---
### Feedback Summary
Provide a clear summary or direct quote from user feedback.
### User Context
Explain the user's context or scenario in which this feedback was provided.
### User Impact
Describe how this feedback affects the user experience or workflow.
### Suggestions
Provide any initial thoughts, potential solutions, or improvements based on the feedback.
### Relevant Screenshots or Examples
Attach screenshots, logs, or examples that illustrate the feedback.
### Additional Notes
Any additional context or related information.

View File

@@ -4,4 +4,3 @@ coverage
.changeset .changeset
tasks tasks
package-lock.json package-lock.json
tests/fixture/*.json

View File

@@ -1,3 +0,0 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}

View File

@@ -1,68 +1,5 @@
# task-master-ai # task-master-ai
## 0.11.0
### Minor Changes
- [#71](https://github.com/eyaltoledano/claude-task-master/pull/71) [`7141062`](https://github.com/eyaltoledano/claude-task-master/commit/71410629ba187776d92a31ea0729b2ff341b5e38) Thanks [@eyaltoledano](https://github.com/eyaltoledano)! - - **Easier Ways to Use Taskmaster (CLI & MCP):**
- You can now use Taskmaster either by installing it as a standard command-line tool (`task-master`) or as an MCP server directly within integrated development tools like Cursor (using its built-in features). **This makes Taskmaster accessible regardless of your preferred workflow.**
- Setting up a new project is simpler in integrated tools, thanks to the new `initialize_project` capability.
- **Complete MCP Implementation:**
- NOTE: Many MCP clients charge on a per tool basis. In that regard, the most cost-efficient way to use Taskmaster is through the CLI directly. Otherwise, the MCP offers the smoothest and most recommended user experience.
- All MCP tools now follow a standardized output format that mimicks RESTful API responses. They are lean JSON responses that are context-efficient. This is a net improvement over the last version which sent the whole CLI output directly, which needlessly wasted tokens.
- Added a `remove-task` command to permanently delete tasks you no longer need.
- Many new MCP tools are available for managing tasks (updating details, adding/removing subtasks, generating task files, setting status, finding the next task, breaking down complex tasks, handling dependencies, analyzing complexity, etc.), usable both from the command line and integrated tools. **(See the `taskmaster.mdc` reference guide and improved readme for a full list).**
- **Better Task Tracking:**
- Added a "cancelled" status option for tasks, providing more ways to categorize work.
- **Smoother Experience in Integrated Tools:**
- Long-running operations (like breaking down tasks or analysis) now run in the background **via an Async Operation Manager** with progress updates, so you know what's happening without waiting and can check status later.
- **Improved Documentation:**
- Added a comprehensive reference guide (`taskmaster.mdc`) detailing all commands and tools with examples, usage tips, and troubleshooting info. This is mostly for use by the AI but can be useful for human users as well.
- Updated the main README with clearer instructions and added a new tutorial/examples guide.
- Added documentation listing supported integrated tools (like Cursor).
- **Increased Stability & Reliability:**
- Using Taskmaster within integrated tools (like Cursor) is now **more stable and the recommended approach.**
- Added automated testing (CI) to catch issues earlier, leading to a more reliable tool.
- Fixed release process issues to ensure users get the correct package versions when installing or updating via npm.
- **Better Command-Line Experience:**
- Fixed bugs in the `expand-all` command that could cause **NaN errors or JSON formatting issues (especially when using `--research`).**
- Fixed issues with parameter validation in the `analyze-complexity` command (specifically related to the `threshold` parameter).
- Made the `add-task` command more consistent by adding standard flags like `--title`, `--description` for manual task creation so you don't have to use `--prompt` and can quickly drop new ideas and stay in your flow.
- Improved error messages for incorrect commands or flags, making them easier to understand.
- Added confirmation warnings before permanently deleting tasks (`remove-task`) to prevent mistakes. There's a known bug for deleting multiple tasks with comma-separated values. It'll be fixed next release.
- Renamed some background tool names used by integrated tools (e.g., `list-tasks` is now `get_tasks`) to be more intuitive if seen in logs or AI interactions.
- Smoother project start: **Improved the guidance provided to AI assistants immediately after setup** (related to `init` and `parse-prd` steps). This ensures the AI doesn't go on a tangent deciding its own workflow, and follows the exact process outlined in the Taskmaster workflow.
- **Clearer Error Messages:**
- When generating subtasks fails, error messages are now clearer, **including specific task IDs and potential suggestions.**
- AI fallback from Claude to Perplexity now also works the other way around. If Perplexity is down, will switch to Claude.
- **Simplified Setup & Configuration:**
- Made it clearer how to configure API keys depending on whether you're using the command-line tool (`.env` file) or an integrated tool (`.cursor/mcp.json` file).
- Taskmaster is now better at automatically finding your project files, especially in integrated tools, reducing the need for manual path settings.
- Fixed an issue that could prevent Taskmaster from working correctly immediately after initialization in integrated tools (related to how the MCP server was invoked). This should solve the issue most users were experiencing with the last release (0.10.x)
- Updated setup templates with clearer examples for API keys.
- \*\*For advanced users setting up the MCP server manually, the command is now `npx -y task-master-ai task-master-mcp`.
- **Enhanced Performance & AI:**
- Updated underlying AI model settings:
- **Increased Context Window:** Can now handle larger projects/tasks due to an increased Claude context window (64k -> 128k tokens).
- **Reduced AI randomness:** More consistent and predictable AI outputs (temperature 0.4 -> 0.2).
- **Updated default AI models:** Uses newer models like `claude-3-7-sonnet-20250219` and Perplexity `sonar-pro` by default.
- **More granular breakdown:** Increased the default number of subtasks generated by `expand` to 5 (from 4).
- **Consistent defaults:** Set the default priority for new tasks consistently to "medium".
- Improved performance when viewing task details in integrated tools by sending less redundant data.
- **Documentation Clarity:**
- Clarified in documentation that Markdown files (`.md`) can be used for Product Requirements Documents (`parse_prd`).
- Improved the description for the `numTasks` option in `parse_prd` for better guidance.
- **Improved Visuals (CLI):**
- Enhanced the look and feel of progress bars and status updates in the command line.
- Added a helpful color-coded progress bar to the task details view (`show` command) to visualize subtask completion.
- Made progress bars show a breakdown of task statuses (e.g., how many are pending vs. done).
- Made status counts clearer with text labels next to icons.
- Prevented progress bars from messing up the display on smaller terminal windows.
- Adjusted how progress is calculated for 'deferred' and 'cancelled' tasks in the progress bar, while still showing their distinct status visually.
- **Fixes for Integrated Tools:**
- Fixed how progress updates are sent to integrated tools, ensuring they display correctly.
- Fixed internal issues that could cause errors or invalid JSON responses when using Taskmaster with integrated tools.
## 0.10.1 ## 0.10.1
### Patch Changes ### Patch Changes

90
LICENSE.md Normal file
View File

@@ -0,0 +1,90 @@
# Dual License
This project is licensed under two separate licenses:
1. [Business Source License 1.1](#business-source-license-11) (BSL 1.1) for commercial use of Task Master itself
2. [Apache License 2.0](#apache-license-20) for all other uses
## Business Source License 1.1
Terms: https://mariadb.com/bsl11/
Licensed Work: Task Master AI
Additional Use Grant: You may use Task Master AI to create and commercialize your own projects and products.
Change Date: 2025-03-30
Change License: None
The Licensed Work is subject to the Business Source License 1.1. If you are interested in using the Licensed Work in a way that competes directly with Task Master, please contact the licensors.
### Licensor
- Eyal Toledano (GitHub: @eyaltoledano)
- Ralph (GitHub: @Crunchyman-ralph)
### Commercial Use Restrictions
This license explicitly restricts certain commercial uses of Task Master AI to the Licensors listed above. Restricted commercial uses include:
1. Creating commercial products or services that directly compete with Task Master AI
2. Selling Task Master AI itself as a service
3. Offering Task Master AI's functionality as a commercial managed service
4. Reselling or redistributing Task Master AI for a fee
### Explicitly Permitted Uses
The following uses are explicitly allowed under this license:
1. Using Task Master AI to create and commercialize your own projects
2. Using Task Master AI in commercial environments for internal development
3. Building and selling products or services that were created using Task Master AI
4. Using Task Master AI for commercial development as long as you're not selling Task Master AI itself
### Additional Terms
1. The right to commercialize Task Master AI itself is exclusively reserved for the Licensors
2. No party may create commercial products that directly compete with Task Master AI without explicit written permission
3. Forks of this repository are subject to the same restrictions regarding direct competition
4. Contributors agree that their contributions will be subject to this same dual licensing structure
## Apache License 2.0
For all uses other than those restricted above. See [APACHE-LICENSE](./APACHE-LICENSE) for the full license text.
### Permitted Use Definition
You may use Task Master AI for any purpose, including commercial purposes, as long as you are not:
1. Creating a direct competitor to Task Master AI
2. Selling Task Master AI itself as a service
3. Redistributing Task Master AI for a fee
### Requirements for Use
1. You must include appropriate copyright notices
2. You must state significant changes made to the software
3. You must preserve all license notices
## Questions and Commercial Licensing
For questions about licensing or to inquire about commercial use that may compete with Task Master, please contact:
- Eyal Toledano (GitHub: @eyaltoledano)
- Ralph (GitHub: @Crunchyman-ralph)
## Examples
### ✅ Allowed Uses
- Using Task Master to create a commercial SaaS product
- Using Task Master in your company for development
- Creating and selling products that were built using Task Master
- Using Task Master to generate code for commercial projects
- Offering consulting services where you use Task Master
### ❌ Restricted Uses
- Creating a competing AI task management tool
- Selling access to Task Master as a service
- Creating a hosted version of Task Master
- Reselling Task Master's functionality

View File

@@ -146,7 +146,7 @@ To enable enhanced task management capabilities directly within Cursor using the
4. Configure with the following details: 4. Configure with the following details:
- Name: "Task Master" - Name: "Task Master"
- Type: "Command" - Type: "Command"
- Command: "npx -y task-master-mcp" - Command: "npx -y --package task-master-ai task-master-mcp"
5. Save the settings 5. Save the settings
Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience. Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience.

View File

@@ -1,6 +1,8 @@
# Task Master [![GitHub stars](https://img.shields.io/github/stars/eyaltoledano/claude-task-master?style=social)](https://github.com/eyaltoledano/claude-task-master/stargazers) # Task Master [![GitHub stars](https://img.shields.io/github/stars/eyaltoledano/claude-task-master?style=social)](https://github.com/eyaltoledano/claude-task-master/stargazers)
[![CI](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml/badge.svg)](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml) [![npm version](https://badge.fury.io/js/task-master-ai.svg)](https://badge.fury.io/js/task-master-ai) ![Discord Follow](https://dcbadge.limes.pink/api/server/https://discord.gg/2ms58QJjqp?style=flat) [![License: MIT with Commons Clause](https://img.shields.io/badge/license-MIT%20with%20Commons%20Clause-blue.svg)](LICENSE) [![CI](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml/badge.svg)](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml) [![npm version](https://badge.fury.io/js/task-master-ai.svg)](https://badge.fury.io/js/task-master-ai)
![Discord Follow](https://dcbadge.limes.pink/api/server/https://discord.gg/2ms58QJjqp?style=flat) [![License: MIT with Commons Clause](https://img.shields.io/badge/license-MIT%20with%20Commons%20Clause-blue.svg)](LICENSE)
### By [@eyaltoledano](https://x.com/eyaltoledano) & [@RalphEcom](https://x.com/RalphEcom) ### By [@eyaltoledano](https://x.com/eyaltoledano) & [@RalphEcom](https://x.com/RalphEcom)
@@ -27,13 +29,13 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
"mcpServers": { "mcpServers": {
"taskmaster-ai": { "taskmaster-ai": {
"command": "npx", "command": "npx",
"args": ["-y", "task-master-mcp"], "args": ["-y", "task-master-ai", "mcp-server"],
"env": { "env": {
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE", "ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE", "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
"MODEL": "claude-3-7-sonnet-20250219", "MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro", "PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000, "MAX_TOKENS": 128000,
"TEMPERATURE": 0.2, "TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5, "DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium" "DEFAULT_PRIORITY": "medium"
@@ -131,12 +133,6 @@ cd claude-task-master
node scripts/init.js node scripts/init.js
``` ```
## Contributors
<a href="https://github.com/eyaltoledano/claude-task-master/graphs/contributors">
<img src="https://contrib.rocks/image?repo=eyaltoledano/claude-task-master" alt="Task Master project contributors" />
</a>
## Star History ## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=eyaltoledano/claude-task-master&type=Timeline)](https://www.star-history.com/#eyaltoledano/claude-task-master&Timeline) [![Star History Chart](https://api.star-history.com/svg?repos=eyaltoledano/claude-task-master&type=Timeline)](https://www.star-history.com/#eyaltoledano/claude-task-master&Timeline)

30
bin/task-master-init.js Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env node
/**
* Claude Task Master Init
* Direct executable for the init command
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Get the path to the init script
const initScriptPath = resolve(__dirname, '../scripts/init.js');
// Pass through all arguments
const args = process.argv.slice(2);
// Spawn the init script with all arguments
const child = spawn('node', [initScriptPath, ...args], {
stdio: 'inherit',
cwd: process.cwd()
});
// Handle exit
child.on('close', (code) => {
process.exit(code);
});

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env node --trace-deprecation #!/usr/bin/env node
/** /**
* Task Master * Task Master
@@ -225,47 +225,47 @@ function createDevScriptAction(commandName) {
}; };
} }
// // Special case for the 'init' command which uses a different script // Special case for the 'init' command which uses a different script
// function registerInitCommand(program) { function registerInitCommand(program) {
// program program
// .command('init') .command('init')
// .description('Initialize a new project') .description('Initialize a new project')
// .option('-y, --yes', 'Skip prompts and use default values') .option('-y, --yes', 'Skip prompts and use default values')
// .option('-n, --name <name>', 'Project name') .option('-n, --name <name>', 'Project name')
// .option('-d, --description <description>', 'Project description') .option('-d, --description <description>', 'Project description')
// .option('-v, --version <version>', 'Project version') .option('-v, --version <version>', 'Project version')
// .option('-a, --author <author>', 'Author name') .option('-a, --author <author>', 'Author name')
// .option('--skip-install', 'Skip installing dependencies') .option('--skip-install', 'Skip installing dependencies')
// .option('--dry-run', 'Show what would be done without making changes') .option('--dry-run', 'Show what would be done without making changes')
// .action((options) => { .action((options) => {
// // Pass through any options to the init script // Pass through any options to the init script
// const args = [ const args = [
// '--yes', '--yes',
// 'name', 'name',
// 'description', 'description',
// 'version', 'version',
// 'author', 'author',
// 'skip-install', 'skip-install',
// 'dry-run' 'dry-run'
// ] ]
// .filter((opt) => options[opt]) .filter((opt) => options[opt])
// .map((opt) => { .map((opt) => {
// if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') { if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
// return `--${opt}`; return `--${opt}`;
// } }
// return `--${opt}=${options[opt]}`; return `--${opt}=${options[opt]}`;
// }); });
// const child = spawn('node', [initScriptPath, ...args], { const child = spawn('node', [initScriptPath, ...args], {
// stdio: 'inherit', stdio: 'inherit',
// cwd: process.cwd() cwd: process.cwd()
// }); });
// child.on('close', (code) => { child.on('close', (code) => {
// process.exit(code); process.exit(code);
// }); });
// }); });
// } }
// Set up the command-line interface // Set up the command-line interface
const program = new Command(); const program = new Command();
@@ -286,8 +286,8 @@ program.on('--help', () => {
displayHelp(); displayHelp();
}); });
// // Add special case commands // Add special case commands
// registerInitCommand(program); registerInitCommand(program);
program program
.command('dev') .command('dev')
@@ -303,7 +303,7 @@ registerCommands(tempProgram);
// For each command in the temp instance, add a modified version to our actual program // For each command in the temp instance, add a modified version to our actual program
tempProgram.commands.forEach((cmd) => { tempProgram.commands.forEach((cmd) => {
if (['dev'].includes(cmd.name())) { if (['init', 'dev'].includes(cmd.name())) {
// Skip commands we've already defined specially // Skip commands we've already defined specially
return; return;
} }

View File

@@ -17,13 +17,13 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
"mcpServers": { "mcpServers": {
"taskmaster-ai": { "taskmaster-ai": {
"command": "npx", "command": "npx",
"args": ["-y", "task-master-mcp"], "args": ["-y", "task-master-ai", "mcp-server"],
"env": { "env": {
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE", "ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE", "PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
"MODEL": "claude-3-7-sonnet-20250219", "MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro", "PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000, "MAX_TOKENS": 128000,
"TEMPERATURE": 0.2, "TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5, "DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium" "DEFAULT_PRIORITY": "medium"
@@ -132,7 +132,7 @@ You can also set up the MCP server in Cursor settings:
4. Configure with the following details: 4. Configure with the following details:
- Name: "Task Master" - Name: "Task Master"
- Type: "Command" - Type: "Command"
- Command: "npx -y task-master-mcp" - Command: "npx -y --package task-master-ai task-master-mcp"
5. Save the settings 5. Save the settings
Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience. Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience.

View File

@@ -4,6 +4,7 @@
*/ */
import { addDependency } from '../../../../scripts/modules/dependency-manager.js'; import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -13,32 +14,19 @@ import {
* Direct function wrapper for addDependency with error handling. * Direct function wrapper for addDependency with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string|number} args.id - Task ID to add dependency to * @param {string|number} args.id - Task ID to add dependency to
* @param {string|number} args.dependsOn - Task ID that will become a dependency * @param {string|number} args.dependsOn - Task ID that will become a dependency
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Result object with success status and data/error information * @returns {Promise<Object>} - Result object with success status and data/error information
*/ */
export async function addDependencyDirect(args, log) { export async function addDependencyDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, dependsOn } = args;
try { try {
log.info(`Adding dependency with args: ${JSON.stringify(args)}`); log.info(`Adding dependency with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('addDependencyDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Validate required parameters // Validate required parameters
if (!id) { if (!args.id) {
return { return {
success: false, success: false,
error: { error: {
@@ -48,7 +36,7 @@ export async function addDependencyDirect(args, log) {
}; };
} }
if (!dependsOn) { if (!args.dependsOn) {
return { return {
success: false, success: false,
error: { error: {
@@ -58,16 +46,18 @@ export async function addDependencyDirect(args, log) {
}; };
} }
// Use provided path // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Format IDs for the core function // Format IDs for the core function
const taskId = const taskId =
id && id.includes && id.includes('.') ? id : parseInt(id, 10); args.id.includes && args.id.includes('.')
? args.id
: parseInt(args.id, 10);
const dependencyId = const dependencyId =
dependsOn && dependsOn.includes && dependsOn.includes('.') args.dependsOn.includes && args.dependsOn.includes('.')
? dependsOn ? args.dependsOn
: parseInt(dependsOn, 10); : parseInt(args.dependsOn, 10);
log.info( log.info(
`Adding dependency: task ${taskId} will depend on ${dependencyId}` `Adding dependency: task ${taskId} will depend on ${dependencyId}`
@@ -76,7 +66,7 @@ export async function addDependencyDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Call the core function using the provided path // Call the core function
await addDependency(tasksPath, taskId, dependencyId); await addDependency(tasksPath, taskId, dependencyId);
// Restore normal logging // Restore normal logging

View File

@@ -3,6 +3,7 @@
*/ */
import { addSubtask } from '../../../../scripts/modules/task-manager.js'; import { addSubtask } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -11,7 +12,6 @@ import {
/** /**
* Add a subtask to an existing task * Add a subtask to an existing task
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - Parent task ID * @param {string} args.id - Parent task ID
* @param {string} [args.taskId] - Existing task ID to convert to subtask (optional) * @param {string} [args.taskId] - Existing task ID to convert to subtask (optional)
* @param {string} [args.title] - Title for new subtask (when creating a new subtask) * @param {string} [args.title] - Title for new subtask (when creating a new subtask)
@@ -19,39 +19,17 @@ import {
* @param {string} [args.details] - Implementation details for new subtask * @param {string} [args.details] - Implementation details for new subtask
* @param {string} [args.status] - Status for new subtask (default: 'pending') * @param {string} [args.status] - Status for new subtask (default: 'pending')
* @param {string} [args.dependencies] - Comma-separated list of dependency IDs * @param {string} [args.dependencies] - Comma-separated list of dependency IDs
* @param {string} [args.file] - Path to the tasks file
* @param {boolean} [args.skipGenerate] - Skip regenerating task files * @param {boolean} [args.skipGenerate] - Skip regenerating task files
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: string}>} * @returns {Promise<{success: boolean, data?: Object, error?: string}>}
*/ */
export async function addSubtaskDirect(args, log) { export async function addSubtaskDirect(args, log) {
// Destructure expected args
const {
tasksJsonPath,
id,
taskId,
title,
description,
details,
status,
dependencies: dependenciesStr,
skipGenerate
} = args;
try { try {
log.info(`Adding subtask with args: ${JSON.stringify(args)}`); log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided if (!args.id) {
if (!tasksJsonPath) {
log.error('addSubtaskDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
if (!id) {
return { return {
success: false, success: false,
error: { error: {
@@ -62,7 +40,7 @@ export async function addSubtaskDirect(args, log) {
} }
// Either taskId or title must be provided // Either taskId or title must be provided
if (!taskId && !title) { if (!args.taskId && !args.title) {
return { return {
success: false, success: false,
error: { error: {
@@ -72,26 +50,26 @@ export async function addSubtaskDirect(args, log) {
}; };
} }
// Use provided path // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Parse dependencies if provided // Parse dependencies if provided
let dependencies = []; let dependencies = [];
if (dependenciesStr) { if (args.dependencies) {
dependencies = dependenciesStr.split(',').map((depId) => { dependencies = args.dependencies.split(',').map((id) => {
// Handle both regular IDs and dot notation // Handle both regular IDs and dot notation
return depId.includes('.') ? depId.trim() : parseInt(depId.trim(), 10); return id.includes('.') ? id.trim() : parseInt(id.trim(), 10);
}); });
} }
// Convert existingTaskId to a number if provided // Convert existingTaskId to a number if provided
const existingTaskId = taskId ? parseInt(taskId, 10) : null; const existingTaskId = args.taskId ? parseInt(args.taskId, 10) : null;
// Convert parent ID to a number // Convert parent ID to a number
const parentId = parseInt(id, 10); const parentId = parseInt(args.id, 10);
// Determine if we should generate files // Determine if we should generate files
const generateFiles = !skipGenerate; const generateFiles = !args.skipGenerate;
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
@@ -123,10 +101,10 @@ export async function addSubtaskDirect(args, log) {
log.info(`Creating new subtask for parent task ${parentId}`); log.info(`Creating new subtask for parent task ${parentId}`);
const newSubtaskData = { const newSubtaskData = {
title: title, title: args.title,
description: description || '', description: args.description || '',
details: details || '', details: args.details || '',
status: status || 'pending', status: args.status || 'pending',
dependencies: dependencies dependencies: dependencies
}; };

View File

@@ -4,6 +4,7 @@
*/ */
import { addTask } from '../../../../scripts/modules/task-manager.js'; import { addTask } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -22,121 +23,56 @@ import {
* Direct function wrapper for adding a new task with error handling. * Direct function wrapper for adding a new task with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} [args.prompt] - Description of the task to add (required if not using manual fields) * @param {string} args.prompt - Description of the task to add
* @param {string} [args.title] - Task title (for manual task creation) * @param {Array<number>} [args.dependencies=[]] - Task dependencies as array of IDs
* @param {string} [args.description] - Task description (for manual task creation)
* @param {string} [args.details] - Implementation details (for manual task creation)
* @param {string} [args.testStrategy] - Test strategy (for manual task creation)
* @param {string} [args.dependencies] - Comma-separated list of task IDs this task depends on
* @param {string} [args.priority='medium'] - Task priority (high, medium, low) * @param {string} [args.priority='medium'] - Task priority (high, medium, low)
* @param {string} [args.file='tasks/tasks.json'] - Path to the tasks file * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory * @param {string} [args.projectRoot] - Project root directory
* @param {boolean} [args.research=false] - Whether to use research capabilities for task creation * @param {boolean} [args.research] - Whether to use research capabilities for task creation
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Additional context (reportProgress, session) * @param {Object} context - Additional context (reportProgress, session)
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } } * @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
*/ */
export async function addTaskDirect(args, log, context = {}) { export async function addTaskDirect(args, log, context = {}) {
// Destructure expected args
const { tasksJsonPath, prompt, dependencies, priority, research } = args;
try { try {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Check if tasksJsonPath was provided // Find the tasks.json path
if (!tasksJsonPath) { const tasksPath = findTasksJsonPath(args, log);
log.error('addTaskDirect called without tasksJsonPath');
disableSilentMode(); // Disable before returning
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Check if this is manual task creation or AI-driven task creation
const isManualCreation = args.title && args.description;
// Check required parameters // Check required parameters
if (!args.prompt && !isManualCreation) { if (!args.prompt) {
log.error( log.error('Missing required parameter: prompt');
'Missing required parameters: either prompt or title+description must be provided'
);
disableSilentMode(); disableSilentMode();
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_PARAMETER', code: 'MISSING_PARAMETER',
message: message: 'The prompt parameter is required for adding a task'
'Either the prompt parameter or both title and description parameters are required for adding a task'
} }
}; };
} }
// Extract and prepare parameters // Extract and prepare parameters
const taskPrompt = prompt; const prompt = args.prompt;
const taskDependencies = Array.isArray(dependencies) const dependencies = Array.isArray(args.dependencies)
? dependencies ? args.dependencies
: dependencies : args.dependencies
? String(dependencies) ? String(args.dependencies)
.split(',') .split(',')
.map((id) => parseInt(id.trim(), 10)) .map((id) => parseInt(id.trim(), 10))
: []; : [];
const taskPriority = priority || 'medium'; const priority = args.priority || 'medium';
log.info(
`Adding new task with prompt: "${prompt}", dependencies: [${dependencies.join(', ')}], priority: ${priority}`
);
// Extract context parameters for advanced functionality // Extract context parameters for advanced functionality
const { session } = context; // Commenting out reportProgress extraction
// const { reportProgress, session } = context;
let manualTaskData = null; const { session } = context; // Keep session
if (isManualCreation) {
// Create manual task data object
manualTaskData = {
title: args.title,
description: args.description,
details: args.details || '',
testStrategy: args.testStrategy || ''
};
log.info(
`Adding new task manually with title: "${args.title}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}`
);
// Call the addTask function with manual task data
const newTaskId = await addTask(
tasksPath,
null, // No prompt needed for manual creation
taskDependencies,
priority,
{
mcpLog: log,
session
},
'json', // Use JSON output format to prevent console output
null, // No custom environment
manualTaskData // Pass the manual task data
);
// Restore normal logging
disableSilentMode();
return {
success: true,
data: {
taskId: newTaskId,
message: `Successfully added new task #${newTaskId}`
}
};
} else {
// AI-driven task creation
log.info(
`Adding new task with prompt: "${prompt}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}`
);
// Initialize AI client with session environment // Initialize AI client with session environment
let localAnthropic; let localAnthropic;
@@ -186,6 +122,7 @@ export async function addTaskDirect(args, log, context = {}) {
system: systemPrompt system: systemPrompt
}, },
{ {
// reportProgress: context.reportProgress, // Commented out to prevent Cursor stroking out
mcpLog: log mcpLog: log
} }
); );
@@ -221,15 +158,15 @@ export async function addTaskDirect(args, log, context = {}) {
const newTaskId = await addTask( const newTaskId = await addTask(
tasksPath, tasksPath,
prompt, prompt,
taskDependencies, dependencies,
priority, priority,
{ {
// reportProgress, // Commented out
mcpLog: log, mcpLog: log,
session session,
taskDataFromAI // Pass the parsed AI result
}, },
'json', 'json'
null,
taskDataFromAI // Pass the parsed AI result as the manual task data
); );
// Restore normal logging // Restore normal logging
@@ -242,7 +179,6 @@ export async function addTaskDirect(args, log, context = {}) {
message: `Successfully added new task #${newTaskId}` message: `Successfully added new task #${newTaskId}`
} }
}; };
}
} catch (error) { } catch (error) {
// Make sure to restore normal logging even if there's an error // Make sure to restore normal logging even if there's an error
disableSilentMode(); disableSilentMode();

View File

@@ -3,6 +3,7 @@
*/ */
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js'; import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode, disableSilentMode,
@@ -15,60 +16,45 @@ import path from 'path';
/** /**
* Analyze task complexity and generate recommendations * Analyze task complexity and generate recommendations
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} args.outputPath - Explicit absolute path to save the report. * @param {string} [args.output] - Output file path for the report
* @param {string} [args.model] - LLM model to use for analysis * @param {string} [args.model] - LLM model to use for analysis
* @param {string|number} [args.threshold] - Minimum complexity score to recommend expansion (1-10) * @param {string|number} [args.threshold] - Minimum complexity score to recommend expansion (1-10)
* @param {boolean} [args.research] - Use Perplexity AI for research-backed complexity analysis * @param {boolean} [args.research] - Use Perplexity AI for research-backed complexity analysis
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} [context={}] - Context object containing session data * @param {Object} [context={}] - Context object containing session data
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function analyzeTaskComplexityDirect(args, log, context = {}) { export async function analyzeTaskComplexityDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, outputPath, model, threshold, research } = args;
try { try {
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`); log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
// Check if required paths were provided // Find the tasks.json path
if (!tasksJsonPath) { const tasksPath = findTasksJsonPath(args, log);
log.error('analyzeTaskComplexityDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
if (!outputPath) {
log.error('analyzeTaskComplexityDirect called without outputPath');
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: 'outputPath is required' }
};
}
// Use the provided paths // Determine output path
const tasksPath = tasksJsonPath; let outputPath = args.output || 'scripts/task-complexity-report.json';
const resolvedOutputPath = outputPath; if (!path.isAbsolute(outputPath) && args.projectRoot) {
outputPath = path.join(args.projectRoot, outputPath);
}
log.info(`Analyzing task complexity from: ${tasksPath}`); log.info(`Analyzing task complexity from: ${tasksPath}`);
log.info(`Output report will be saved to: ${resolvedOutputPath}`); log.info(`Output report will be saved to: ${outputPath}`);
if (research) { if (args.research) {
log.info('Using Perplexity AI for research-backed complexity analysis'); log.info('Using Perplexity AI for research-backed complexity analysis');
} }
// Create options object for analyzeTaskComplexity using provided paths // Create options object for analyzeTaskComplexity
const options = { const options = {
file: tasksPath, file: tasksPath,
output: resolvedOutputPath, output: outputPath,
model: model, model: args.model,
threshold: threshold, threshold: args.threshold,
research: research === true research: args.research === true
}; };
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
@@ -109,7 +95,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
} }
// Verify the report file was created // Verify the report file was created
if (!fs.existsSync(resolvedOutputPath)) { if (!fs.existsSync(outputPath)) {
return { return {
success: false, success: false,
error: { error: {
@@ -122,7 +108,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
// Read the report file // Read the report file
let report; let report;
try { try {
report = JSON.parse(fs.readFileSync(resolvedOutputPath, 'utf8')); report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
// Important: Handle different report formats // Important: Handle different report formats
// The core function might return an array or an object with a complexityAnalysis property // The core function might return an array or an object with a complexityAnalysis property
@@ -144,8 +130,8 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
return { return {
success: true, success: true,
data: { data: {
message: `Task complexity analysis complete. Report saved to ${resolvedOutputPath}`, message: `Task complexity analysis complete. Report saved to ${outputPath}`,
reportPath: resolvedOutputPath, reportPath: outputPath,
reportSummary: { reportSummary: {
taskCount: analysisArray.length, taskCount: analysisArray.length,
highComplexityTasks, highComplexityTasks,

View File

@@ -3,6 +3,7 @@
*/ */
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js'; import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -12,32 +13,19 @@ import fs from 'fs';
/** /**
* Clear subtasks from specified tasks * Clear subtasks from specified tasks
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from * @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from
* @param {boolean} [args.all] - Clear subtasks from all tasks * @param {boolean} [args.all] - Clear subtasks from all tasks
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function clearSubtasksDirect(args, log) { export async function clearSubtasksDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, all } = args;
try { try {
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`); log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('clearSubtasksDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Either id or all must be provided // Either id or all must be provided
if (!id && !all) { if (!args.id && !args.all) {
return { return {
success: false, success: false,
error: { error: {
@@ -48,8 +36,8 @@ export async function clearSubtasksDirect(args, log) {
}; };
} }
// Use provided path // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Check if tasks.json exists // Check if tasks.json exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -65,7 +53,7 @@ export async function clearSubtasksDirect(args, log) {
let taskIds; let taskIds;
// If all is specified, get all task IDs // If all is specified, get all task IDs
if (all) { if (args.all) {
log.info('Clearing subtasks from all tasks'); log.info('Clearing subtasks from all tasks');
const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8')); const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
if (!data || !data.tasks || data.tasks.length === 0) { if (!data || !data.tasks || data.tasks.length === 0) {
@@ -80,7 +68,7 @@ export async function clearSubtasksDirect(args, log) {
taskIds = data.tasks.map((t) => t.id).join(','); taskIds = data.tasks.map((t) => t.id).join(',');
} else { } else {
// Use the provided task IDs // Use the provided task IDs
taskIds = id; taskIds = args.id;
} }
log.info(`Clearing subtasks from tasks: ${taskIds}`); log.info(`Clearing subtasks from tasks: ${taskIds}`);

View File

@@ -8,34 +8,37 @@ import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import path from 'path'; import path from 'path';
/** /**
* Direct function wrapper for displaying the complexity report with error handling and caching. * Direct function wrapper for displaying the complexity report with error handling and caching.
* *
* @param {Object} args - Command arguments containing reportPath. * @param {Object} args - Command arguments containing file path option
* @param {string} args.reportPath - Explicit path to the complexity report file.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Result object with success status and data/error information * @returns {Promise<Object>} - Result object with success status and data/error information
*/ */
export async function complexityReportDirect(args, log) { export async function complexityReportDirect(args, log) {
// Destructure expected args
const { reportPath } = args;
try { try {
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`); log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
// Check if reportPath was provided // Get tasks file path to determine project root for the default report location
if (!reportPath) { let tasksPath;
log.error('complexityReportDirect called without reportPath'); try {
return { tasksPath = findTasksJsonPath(args, log);
success: false, } catch (error) {
error: { code: 'MISSING_ARGUMENT', message: 'reportPath is required' }, log.warn(
fromCache: false `Tasks file not found, using current directory: ${error.message}`
}; );
// Continue with default or specified report path
} }
// Use the provided report path // Get report file path from args or use default
const reportPath =
args.file ||
path.join(process.cwd(), 'scripts', 'task-complexity-report.json');
log.info(`Looking for complexity report at: ${reportPath}`); log.info(`Looking for complexity report at: ${reportPath}`);
// Generate cache key based on report path // Generate cache key based on report path

View File

@@ -8,6 +8,7 @@ import {
disableSilentMode, disableSilentMode,
isSilentMode isSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js'; import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
@@ -15,51 +16,34 @@ import fs from 'fs';
/** /**
* Expand all pending tasks with subtasks * Expand all pending tasks with subtasks
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {number|string} [args.num] - Number of subtasks to generate * @param {number|string} [args.num] - Number of subtasks to generate
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation * @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation
* @param {string} [args.prompt] - Additional context to guide subtask generation * @param {string} [args.prompt] - Additional context to guide subtask generation
* @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them * @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Context object containing session * @param {Object} context - Context object containing session
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function expandAllTasksDirect(args, log, context = {}) { export async function expandAllTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, num, research, prompt, force } = args;
try { try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`); log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('expandAllTasksDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Enable silent mode early to prevent any console output // Enable silent mode early to prevent any console output
enableSilentMode(); enableSilentMode();
try { try {
// Remove internal path finding // Find the tasks.json path
/*
const tasksPath = findTasksJsonPath(args, log); const tasksPath = findTasksJsonPath(args, log);
*/
// Use provided path
const tasksPath = tasksJsonPath;
// Parse parameters // Parse parameters
const numSubtasks = num ? parseInt(num, 10) : undefined; const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = research === true; const useResearch = args.research === true;
const additionalContext = prompt || ''; const additionalContext = args.prompt || '';
const forceFlag = force === true; const forceFlag = args.force === true;
log.info( log.info(
`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...` `Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`

View File

@@ -11,6 +11,7 @@ import {
disableSilentMode, disableSilentMode,
isSilentMode isSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
getAnthropicClientForMCP, getAnthropicClientForMCP,
getModelConfig getModelConfig
@@ -22,20 +23,12 @@ import fs from 'fs';
* Direct function wrapper for expanding a task into subtasks with error handling. * Direct function wrapper for expanding a task into subtasks with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task to expand.
* @param {number|string} [args.num] - Number of subtasks to generate.
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation.
* @param {string} [args.prompt] - Additional context to guide subtask generation.
* @param {boolean} [args.force] - Force expansion even if subtasks exist.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Context object containing session and reportProgress * @param {Object} context - Context object containing session and reportProgress
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function expandTaskDirect(args, log, context = {}) { export async function expandTaskDirect(args, log, context = {}) {
const { session } = context; const { session } = context;
// Destructure expected args
const { tasksJsonPath, id, num, research, prompt, force } = args;
// Log session root data for debugging // Log session root data for debugging
log.info( log.info(
@@ -47,26 +40,48 @@ export async function expandTaskDirect(args, log, context = {}) {
})}` })}`
); );
// Check if tasksJsonPath was provided let tasksPath;
if (!tasksJsonPath) { try {
log.error('expandTaskDirect called without tasksJsonPath'); // If a direct file path is provided, use it directly
if (args.file && fs.existsSync(args.file)) {
log.info(
`[expandTaskDirect] Using explicitly provided tasks file: ${args.file}`
);
tasksPath = args.file;
} else {
// Find the tasks path through standard logic
log.info(
`[expandTaskDirect] No direct file path provided or file not found at ${args.file}, searching using findTasksJsonPath`
);
tasksPath = findTasksJsonPath(args, log);
}
} catch (error) {
log.error(
`[expandTaskDirect] Error during tasksPath determination: ${error.message}`
);
// Include session roots information in error
const sessionRootsInfo = session
? `\nSession.roots: ${JSON.stringify(session.roots)}\n` +
`Current Working Directory: ${process.cwd()}\n` +
`Args.projectRoot: ${args.projectRoot}\n` +
`Args.file: ${args.file}\n`
: '\nSession object not available';
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_ARGUMENT', code: 'FILE_NOT_FOUND_ERROR',
message: 'tasksJsonPath is required' message: `Error determining tasksPath: ${error.message}${sessionRootsInfo}`
}, },
fromCache: false fromCache: false
}; };
} }
// Use provided path log.info(`[expandTaskDirect] Determined tasksPath: ${tasksPath}`);
const tasksPath = tasksJsonPath;
log.info(`[expandTaskDirect] Using tasksPath: ${tasksPath}`);
// Validate task ID // Validate task ID
const taskId = id ? parseInt(id, 10) : null; const taskId = args.id ? parseInt(args.id, 10) : null;
if (!taskId) { if (!taskId) {
log.error('Task ID is required'); log.error('Task ID is required');
return { return {
@@ -80,10 +95,9 @@ export async function expandTaskDirect(args, log, context = {}) {
} }
// Process other parameters // Process other parameters
const numSubtasks = num ? parseInt(num, 10) : undefined; const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = research === true; const useResearch = args.research === true;
const additionalContext = prompt || ''; const additionalContext = args.prompt || '';
const forceFlag = force === true;
// Initialize AI client if needed (for expandTask function) // Initialize AI client if needed (for expandTask function)
try { try {
@@ -158,16 +172,15 @@ export async function expandTaskDirect(args, log, context = {}) {
}; };
} }
// Check for existing subtasks and force flag // Check for existing subtasks
const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0; const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0;
if (hasExistingSubtasks && !forceFlag) {
log.info( // If the task already has subtasks, just return it (matching core behavior)
`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.` if (hasExistingSubtasks) {
); log.info(`Task ${taskId} already has ${task.subtasks.length} subtasks`);
return { return {
success: true, success: true,
data: { data: {
message: `Task ${taskId} already has subtasks. Expansion skipped.`,
task, task,
subtasksAdded: 0, subtasksAdded: 0,
hasExistingSubtasks hasExistingSubtasks
@@ -176,14 +189,6 @@ export async function expandTaskDirect(args, log, context = {}) {
}; };
} }
// If force flag is set, clear existing subtasks
if (hasExistingSubtasks && forceFlag) {
log.info(
`Force flag set. Clearing existing subtasks for task ${taskId}.`
);
task.subtasks = [];
}
// Keep a copy of the task before modification // Keep a copy of the task before modification
const originalTask = JSON.parse(JSON.stringify(task)); const originalTask = JSON.parse(JSON.stringify(task));

View File

@@ -3,6 +3,7 @@
*/ */
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js'; import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -12,30 +13,17 @@ import fs from 'fs';
/** /**
* Fix invalid dependencies in tasks.json automatically * Fix invalid dependencies in tasks.json automatically
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function fixDependenciesDirect(args, log) { export async function fixDependenciesDirect(args, log) {
// Destructure expected args
const { tasksJsonPath } = args;
try { try {
log.info(`Fixing invalid dependencies in tasks: ${tasksJsonPath}`); log.info(`Fixing invalid dependencies in tasks...`);
// Check if tasksJsonPath was provided // Find the tasks.json path
if (!tasksJsonPath) { const tasksPath = findTasksJsonPath(args, log);
log.error('fixDependenciesDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Verify the file exists // Verify the file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -51,7 +39,7 @@ export async function fixDependenciesDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Call the original command function using the provided path // Call the original command function
await fixDependenciesCommand(tasksPath); await fixDependenciesCommand(tasksPath);
// Restore normal logging // Restore normal logging

View File

@@ -8,46 +8,40 @@ import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import path from 'path'; import path from 'path';
/** /**
* Direct function wrapper for generateTaskFiles with error handling. * Direct function wrapper for generateTaskFiles with error handling.
* *
* @param {Object} args - Command arguments containing tasksJsonPath and outputDir. * @param {Object} args - Command arguments containing file and output path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function generateTaskFilesDirect(args, log) { export async function generateTaskFilesDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, outputDir } = args;
try { try {
log.info(`Generating task files with args: ${JSON.stringify(args)}`); log.info(`Generating task files with args: ${JSON.stringify(args)}`);
// Check if paths were provided // Get tasks file path
if (!tasksJsonPath) { let tasksPath;
const errorMessage = 'tasksJsonPath is required but was not provided.'; try {
log.error(errorMessage); tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Error finding tasks file: ${error.message}`);
return { return {
success: false, success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false fromCache: false
}; };
} }
// Get output directory (defaults to the same directory as the tasks file)
let outputDir = args.output;
if (!outputDir) { if (!outputDir) {
const errorMessage = 'outputDir is required but was not provided.'; outputDir = path.dirname(tasksPath);
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
} }
// Use the provided paths log.info(`Generating task files from ${tasksPath} to ${outputDir}`);
const tasksPath = tasksJsonPath;
const resolvedOutputDir = outputDir;
log.info(`Generating task files from ${tasksPath} to ${resolvedOutputDir}`);
// Execute core generateTaskFiles function in a separate try/catch // Execute core generateTaskFiles function in a separate try/catch
try { try {
@@ -55,7 +49,7 @@ export async function generateTaskFilesDirect(args, log) {
enableSilentMode(); enableSilentMode();
// The function is synchronous despite being awaited elsewhere // The function is synchronous despite being awaited elsewhere
generateTaskFiles(tasksPath, resolvedOutputDir); generateTaskFiles(tasksPath, outputDir);
// Restore normal logging after task generation // Restore normal logging after task generation
disableSilentMode(); disableSilentMode();
@@ -76,8 +70,8 @@ export async function generateTaskFilesDirect(args, log) {
success: true, success: true,
data: { data: {
message: `Successfully generated task files`, message: `Successfully generated task files`,
tasksPath: tasksPath, tasksPath,
outputDir: resolvedOutputDir, outputDir,
taskFiles: taskFiles:
'Individual task files have been generated in the output directory' 'Individual task files have been generated in the output directory'
}, },

View File

@@ -1,138 +0,0 @@
import { initializeProject } from '../../../../scripts/init.js'; // Import core function and its logger if needed separately
import {
enableSilentMode,
disableSilentMode
// isSilentMode // Not used directly here
} from '../../../../scripts/modules/utils.js';
import { getProjectRootFromSession } from '../../tools/utils.js'; // Adjust path if necessary
import os from 'os'; // Import os module for home directory check
/**
* Direct function wrapper for initializing a project.
* Derives target directory from session, sets CWD, and calls core init logic.
* @param {object} args - Arguments containing project details and options (projectName, projectDescription, yes, etc.)
* @param {object} log - The FastMCP logger instance.
* @param {object} context - The context object, must contain { session }.
* @returns {Promise<{success: boolean, data?: any, error?: {code: string, message: string}}>} - Standard result object.
*/
export async function initializeProjectDirect(args, log, context = {}) {
const { session } = context;
const homeDir = os.homedir();
let targetDirectory = null;
log.info(
`CONTEXT received in direct function: ${context ? JSON.stringify(Object.keys(context)) : 'MISSING or Falsy'}`
);
log.info(
`SESSION extracted in direct function: ${session ? 'Exists' : 'MISSING or Falsy'}`
);
log.info(`Args received in direct function: ${JSON.stringify(args)}`);
// --- Determine Target Directory ---
// 1. Prioritize projectRoot passed directly in args
// Ensure it's not null, '/', or the home directory
if (
args.projectRoot &&
args.projectRoot !== '/' &&
args.projectRoot !== homeDir
) {
log.info(`Using projectRoot directly from args: ${args.projectRoot}`);
targetDirectory = args.projectRoot;
} else {
// 2. If args.projectRoot is missing or invalid, THEN try session (as a fallback)
log.warn(
`args.projectRoot ('${args.projectRoot}') is missing or invalid. Attempting to derive from session.`
);
const sessionDerivedPath = getProjectRootFromSession(session, log);
// Validate the session-derived path as well
if (
sessionDerivedPath &&
sessionDerivedPath !== '/' &&
sessionDerivedPath !== homeDir
) {
log.info(
`Using project root derived from session: ${sessionDerivedPath}`
);
targetDirectory = sessionDerivedPath;
} else {
log.error(
`Could not determine a valid project root. args.projectRoot='${args.projectRoot}', sessionDerivedPath='${sessionDerivedPath}'`
);
}
}
// 3. Validate the final targetDirectory
if (!targetDirectory) {
// This error now covers cases where neither args.projectRoot nor session provided a valid path
return {
success: false,
error: {
code: 'INVALID_TARGET_DIRECTORY',
message: `Cannot initialize project: Could not determine a valid target directory. Please ensure a workspace/folder is open or specify projectRoot.`,
details: `Attempted args.projectRoot: ${args.projectRoot}`
},
fromCache: false
};
}
// --- Proceed with validated targetDirectory ---
log.info(`Validated target directory for initialization: ${targetDirectory}`);
const originalCwd = process.cwd();
let resultData;
let success = false;
let errorResult = null;
log.info(
`Temporarily changing CWD to ${targetDirectory} for initialization.`
);
process.chdir(targetDirectory); // Change CWD to the *validated* targetDirectory
enableSilentMode(); // Enable silent mode BEFORE calling the core function
try {
// Always force yes: true when called via MCP to avoid interactive prompts
const options = {
name: args.projectName,
description: args.projectDescription,
version: args.projectVersion,
author: args.authorName,
skipInstall: args.skipInstall,
aliases: args.addAliases,
yes: true // Force yes mode
};
log.info(`Initializing project with options: ${JSON.stringify(options)}`);
const result = await initializeProject(options); // Call core logic
// Format success result for handleApiResult
resultData = {
message: 'Project initialized successfully.',
next_step:
'Now that the project is initialized, the next step is to create the tasks by parsing a PRD. This will create the tasks folder and the initial task files (tasks folder will be created when parse-prd is run). The parse-prd tool will require a prd.txt file as input (typically found in the project root directory, scripts/ directory). You can create a prd.txt file by asking the user about their idea, and then using the scripts/example_prd.txt file as a template to genrate a prd.txt file in scripts/. You may skip all of this if the user already has a prd.txt file. You can THEN use the parse-prd tool to create the tasks. So: step 1 after initialization is to create a prd.txt file in scripts/prd.txt or confirm the user already has one. Step 2 is to use the parse-prd tool to create the tasks. Do not bother looking for tasks after initialization, just use the parse-prd tool to create the tasks after creating a prd.txt from which to parse the tasks. You do NOT need to reinitialize the project to parse-prd.',
...result // Include details returned by initializeProject
};
success = true;
log.info(
`Project initialization completed successfully in ${targetDirectory}.`
);
} catch (error) {
log.error(`Core initializeProject failed: ${error.message}`);
errorResult = {
code: 'INITIALIZATION_FAILED',
message: `Core project initialization failed: ${error.message}`,
details: error.stack
};
success = false;
} finally {
disableSilentMode(); // ALWAYS disable silent mode in finally
log.info(`Restoring original CWD: ${originalCwd}`);
process.chdir(originalCwd); // Change back to original CWD
}
// Return in format expected by handleApiResult
if (success) {
return { success: true, data: resultData, fromCache: false };
} else {
return { success: false, error: errorResult, fromCache: false };
}
}

View File

@@ -5,6 +5,7 @@
import { listTasks } from '../../../../scripts/modules/task-manager.js'; import { listTasks } from '../../../../scripts/modules/task-manager.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -13,30 +14,38 @@ import {
/** /**
* Direct function wrapper for listTasks with error handling and caching. * Direct function wrapper for listTasks with error handling and caching.
* *
* @param {Object} args - Command arguments (now expecting tasksJsonPath explicitly). * @param {Object} args - Command arguments (projectRoot is expected to be resolved).
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }. * @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
*/ */
export async function listTasksDirect(args, log) { export async function listTasksDirect(args, log) {
// Destructure the explicit tasksJsonPath from args let tasksPath;
const { tasksJsonPath, status, withSubtasks } = args; try {
// Find the tasks path first - needed for cache key and execution
if (!tasksJsonPath) { tasksPath = findTasksJsonPath(args, log);
log.error('listTasksDirect called without tasksJsonPath'); } catch (error) {
if (error.code === 'TASKS_FILE_NOT_FOUND') {
log.error(`Tasks file not found: ${error.message}`);
// Return the error structure expected by the calling tool/handler
return { return {
success: false, success: false,
error: { error: { code: error.code, message: error.message },
code: 'MISSING_ARGUMENT', fromCache: false
message: 'tasksJsonPath is required' };
}, }
log.error(`Unexpected error finding tasks file: ${error.message}`);
// Re-throw for outer catch or return structured error
return {
success: false,
error: { code: 'FIND_TASKS_PATH_ERROR', message: error.message },
fromCache: false fromCache: false
}; };
} }
// Use the explicit tasksJsonPath for cache key // Generate cache key *after* finding tasksPath
const statusFilter = status || 'all'; const statusFilter = args.status || 'all';
const withSubtasksFilter = withSubtasks || false; const withSubtasks = args.withSubtasks || false;
const cacheKey = `listTasks:${tasksJsonPath}:${statusFilter}:${withSubtasksFilter}`; const cacheKey = `listTasks:${tasksPath}:${statusFilter}:${withSubtasks}`;
// Define the action function to be executed on cache miss // Define the action function to be executed on cache miss
const coreListTasksAction = async () => { const coreListTasksAction = async () => {
@@ -45,13 +54,12 @@ export async function listTasksDirect(args, log) {
enableSilentMode(); enableSilentMode();
log.info( log.info(
`Executing core listTasks function for path: ${tasksJsonPath}, filter: ${statusFilter}, subtasks: ${withSubtasksFilter}` `Executing core listTasks function for path: ${tasksPath}, filter: ${statusFilter}, subtasks: ${withSubtasks}`
); );
// Pass the explicit tasksJsonPath to the core function
const resultData = listTasks( const resultData = listTasks(
tasksJsonPath, tasksPath,
statusFilter, statusFilter,
withSubtasksFilter, withSubtasks,
'json' 'json'
); );

View File

@@ -6,6 +6,7 @@
import { findNextTask } from '../../../../scripts/modules/task-manager.js'; import { findNextTask } from '../../../../scripts/modules/task-manager.js';
import { readJSON } from '../../../../scripts/modules/utils.js'; import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -15,28 +16,28 @@ import {
* Direct function wrapper for finding the next task to work on with error handling and caching. * Direct function wrapper for finding the next task to work on with error handling and caching.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function nextTaskDirect(args, log) { export async function nextTaskDirect(args, log) {
// Destructure expected args let tasksPath;
const { tasksJsonPath } = args; try {
// Find the tasks path first - needed for cache key and execution
if (!tasksJsonPath) { tasksPath = findTasksJsonPath(args, log);
log.error('nextTaskDirect called without tasksJsonPath'); } catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_ARGUMENT', code: 'FILE_NOT_FOUND_ERROR',
message: 'tasksJsonPath is required' message: error.message
}, },
fromCache: false fromCache: false
}; };
} }
// Generate cache key using the provided task path // Generate cache key using task path
const cacheKey = `nextTask:${tasksJsonPath}`; const cacheKey = `nextTask:${tasksPath}`;
// Define the action function to be executed on cache miss // Define the action function to be executed on cache miss
const coreNextTaskAction = async () => { const coreNextTaskAction = async () => {
@@ -44,17 +45,16 @@ export async function nextTaskDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
log.info(`Finding next task from ${tasksJsonPath}`); log.info(`Finding next task from ${tasksPath}`);
// Read tasks data using the provided path // Read tasks data
const data = readJSON(tasksJsonPath); const data = readJSON(tasksPath);
if (!data || !data.tasks) { if (!data || !data.tasks) {
disableSilentMode(); // Disable before return
return { return {
success: false, success: false,
error: { error: {
code: 'INVALID_TASKS_FILE', code: 'INVALID_TASKS_FILE',
message: `No valid tasks found in ${tasksJsonPath}` message: `No valid tasks found in ${tasksPath}`
} }
}; };
} }

View File

@@ -5,7 +5,6 @@
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import os from 'os'; // Import os module for home directory check
import { parsePRD } from '../../../../scripts/modules/task-manager.js'; import { parsePRD } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js'; import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
@@ -47,70 +46,46 @@ export async function parsePRDDirect(args, log, context = {}) {
}; };
} }
// Validate required parameters // Parameter validation and path resolution
if (!args.projectRoot) {
const errorMessage = 'Project root is required for parsePRDDirect';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_PROJECT_ROOT', message: errorMessage },
fromCache: false
};
}
if (!args.input) { if (!args.input) {
const errorMessage = 'Input file path is required for parsePRDDirect'; const errorMessage =
'No input file specified. Please provide an input PRD document path.';
log.error(errorMessage); log.error(errorMessage);
return { return {
success: false, success: false,
error: { code: 'MISSING_INPUT_PATH', message: errorMessage }, error: { code: 'MISSING_INPUT_FILE', message: errorMessage },
fromCache: false fromCache: false
}; };
} }
if (!args.output) { // Resolve input path (relative to project root if provided)
const errorMessage = 'Output file path is required for parsePRDDirect'; const projectRoot = args.projectRoot || process.cwd();
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_OUTPUT_PATH', message: errorMessage },
fromCache: false
};
}
// Resolve input path (expecting absolute path or path relative to project root)
const projectRoot = args.projectRoot;
const inputPath = path.isAbsolute(args.input) const inputPath = path.isAbsolute(args.input)
? args.input ? args.input
: path.resolve(projectRoot, args.input); : path.resolve(projectRoot, args.input);
// Determine output path
let outputPath;
if (args.output) {
outputPath = path.isAbsolute(args.output)
? args.output
: path.resolve(projectRoot, args.output);
} else {
// Default to tasks/tasks.json in the project root
outputPath = path.resolve(projectRoot, 'tasks', 'tasks.json');
}
// Verify input file exists // Verify input file exists
if (!fs.existsSync(inputPath)) { if (!fs.existsSync(inputPath)) {
const errorMessage = `Input file not found: ${inputPath}`; const errorMessage = `Input file not found: ${inputPath}`;
log.error(errorMessage); log.error(errorMessage);
return { return {
success: false, success: false,
error: { error: { code: 'INPUT_FILE_NOT_FOUND', message: errorMessage },
code: 'INPUT_FILE_NOT_FOUND',
message: errorMessage,
details: `Checked path: ${inputPath}\nProject root: ${projectRoot}\nInput argument: ${args.input}`
},
fromCache: false fromCache: false
}; };
} }
// Resolve output path (expecting absolute path or path relative to project root)
const outputPath = path.isAbsolute(args.output)
? args.output
: path.resolve(projectRoot, args.output);
// Ensure output directory exists
const outputDir = path.dirname(outputPath);
if (!fs.existsSync(outputDir)) {
log.info(`Creating output directory: ${outputDir}`);
fs.mkdirSync(outputDir, { recursive: true });
}
// Parse number of tasks - handle both string and number values // Parse number of tasks - handle both string and number values
let numTasks = 10; // Default let numTasks = 10; // Default
if (args.numTasks) { if (args.numTasks) {
@@ -143,13 +118,6 @@ export async function parsePRDDirect(args, log, context = {}) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
try { try {
// Make sure the output directory exists
const outputDir = path.dirname(outputPath);
if (!fs.existsSync(outputDir)) {
log.info(`Creating output directory: ${outputDir}`);
fs.mkdirSync(outputDir, { recursive: true });
}
// Execute core parsePRD function with AI client // Execute core parsePRD function with AI client
await parsePRD( await parsePRD(
inputPath, inputPath,

View File

@@ -3,6 +3,7 @@
*/ */
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js'; import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -11,32 +12,19 @@ import {
/** /**
* Remove a dependency from a task * Remove a dependency from a task
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string|number} args.id - Task ID to remove dependency from * @param {string|number} args.id - Task ID to remove dependency from
* @param {string|number} args.dependsOn - Task ID to remove as a dependency * @param {string|number} args.dependsOn - Task ID to remove as a dependency
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function removeDependencyDirect(args, log) { export async function removeDependencyDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, dependsOn } = args;
try { try {
log.info(`Removing dependency with args: ${JSON.stringify(args)}`); log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('removeDependencyDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Validate required parameters // Validate required parameters
if (!id) { if (!args.id) {
return { return {
success: false, success: false,
error: { error: {
@@ -46,7 +34,7 @@ export async function removeDependencyDirect(args, log) {
}; };
} }
if (!dependsOn) { if (!args.dependsOn) {
return { return {
success: false, success: false,
error: { error: {
@@ -56,16 +44,18 @@ export async function removeDependencyDirect(args, log) {
}; };
} }
// Use provided path // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Format IDs for the core function // Format IDs for the core function
const taskId = const taskId =
id && id.includes && id.includes('.') ? id : parseInt(id, 10); args.id.includes && args.id.includes('.')
? args.id
: parseInt(args.id, 10);
const dependencyId = const dependencyId =
dependsOn && dependsOn.includes && dependsOn.includes('.') args.dependsOn.includes && args.dependsOn.includes('.')
? dependsOn ? args.dependsOn
: parseInt(dependsOn, 10); : parseInt(args.dependsOn, 10);
log.info( log.info(
`Removing dependency: task ${taskId} no longer depends on ${dependencyId}` `Removing dependency: task ${taskId} no longer depends on ${dependencyId}`
@@ -74,7 +64,7 @@ export async function removeDependencyDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Call the core function using the provided tasksPath // Call the core function
await removeDependency(tasksPath, taskId, dependencyId); await removeDependency(tasksPath, taskId, dependencyId);
// Restore normal logging // Restore normal logging

View File

@@ -3,6 +3,7 @@
*/ */
import { removeSubtask } from '../../../../scripts/modules/task-manager.js'; import { removeSubtask } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -11,37 +12,22 @@ import {
/** /**
* Remove a subtask from its parent task * Remove a subtask from its parent task
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - Subtask ID in format "parentId.subtaskId" (required) * @param {string} args.id - Subtask ID in format "parentId.subtaskId" (required)
* @param {boolean} [args.convert] - Whether to convert the subtask to a standalone task * @param {boolean} [args.convert] - Whether to convert the subtask to a standalone task
* @param {string} [args.file] - Path to the tasks file
* @param {boolean} [args.skipGenerate] - Skip regenerating task files * @param {boolean} [args.skipGenerate] - Skip regenerating task files
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function removeSubtaskDirect(args, log) { export async function removeSubtaskDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, convert, skipGenerate } = args;
try { try {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
log.info(`Removing subtask with args: ${JSON.stringify(args)}`); log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided if (!args.id) {
if (!tasksJsonPath) {
log.error('removeSubtaskDirect called without tasksJsonPath');
disableSilentMode(); // Disable before returning
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
if (!id) {
disableSilentMode(); // Disable before returning
return { return {
success: false, success: false,
error: { error: {
@@ -53,34 +39,32 @@ export async function removeSubtaskDirect(args, log) {
} }
// Validate subtask ID format // Validate subtask ID format
if (!id.includes('.')) { if (!args.id.includes('.')) {
disableSilentMode(); // Disable before returning
return { return {
success: false, success: false,
error: { error: {
code: 'INPUT_VALIDATION_ERROR', code: 'INPUT_VALIDATION_ERROR',
message: `Invalid subtask ID format: ${id}. Expected format: "parentId.subtaskId"` message: `Invalid subtask ID format: ${args.id}. Expected format: "parentId.subtaskId"`
} }
}; };
} }
// Use provided path // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Convert convertToTask to a boolean // Convert convertToTask to a boolean
const convertToTask = convert === true; const convertToTask = args.convert === true;
// Determine if we should generate files // Determine if we should generate files
const generateFiles = !skipGenerate; const generateFiles = !args.skipGenerate;
log.info( log.info(
`Removing subtask ${id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})` `Removing subtask ${args.id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})`
); );
// Use the provided tasksPath
const result = await removeSubtask( const result = await removeSubtask(
tasksPath, tasksPath,
id, args.id,
convertToTask, convertToTask,
generateFiles generateFiles
); );
@@ -93,7 +77,7 @@ export async function removeSubtaskDirect(args, log) {
return { return {
success: true, success: true,
data: { data: {
message: `Subtask ${id} successfully converted to task #${result.id}`, message: `Subtask ${args.id} successfully converted to task #${result.id}`,
task: result task: result
} }
}; };
@@ -102,7 +86,7 @@ export async function removeSubtaskDirect(args, log) {
return { return {
success: true, success: true,
data: { data: {
message: `Subtask ${id} successfully removed` message: `Subtask ${args.id} successfully removed`
} }
}; };
} }

View File

@@ -8,35 +8,35 @@ import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
/** /**
* Direct function wrapper for removeTask with error handling. * Direct function wrapper for removeTask with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task or subtask to remove.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false } * @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false }
*/ */
export async function removeTaskDirect(args, log) { export async function removeTaskDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id } = args;
try { try {
// Check if tasksJsonPath was provided // Find the tasks path first
if (!tasksJsonPath) { let tasksPath;
log.error('removeTaskDirect called without tasksJsonPath'); try {
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_ARGUMENT', code: 'FILE_NOT_FOUND_ERROR',
message: 'tasksJsonPath is required' message: error.message
}, },
fromCache: false fromCache: false
}; };
} }
// Validate task ID parameter // Validate task ID parameter
const taskId = id; const taskId = args.id;
if (!taskId) { if (!taskId) {
log.error('Task ID is required'); log.error('Task ID is required');
return { return {
@@ -50,14 +50,14 @@ export async function removeTaskDirect(args, log) {
} }
// Skip confirmation in the direct function since it's handled by the client // Skip confirmation in the direct function since it's handled by the client
log.info(`Removing task with ID: ${taskId} from ${tasksJsonPath}`); log.info(`Removing task with ID: ${taskId} from ${tasksPath}`);
try { try {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Call the core removeTask function using the provided path // Call the core removeTask function
const result = await removeTask(tasksJsonPath, taskId); const result = await removeTask(tasksPath, taskId);
// Restore normal logging // Restore normal logging
disableSilentMode(); disableSilentMode();
@@ -70,7 +70,7 @@ export async function removeTaskDirect(args, log) {
data: { data: {
message: result.message, message: result.message,
taskId: taskId, taskId: taskId,
tasksPath: tasksJsonPath, tasksPath: tasksPath,
removedTask: result.removedTask removedTask: result.removedTask
}, },
fromCache: false fromCache: false

View File

@@ -4,6 +4,7 @@
*/ */
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js'; import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode, disableSilentMode,
@@ -13,29 +14,16 @@ import {
/** /**
* Direct function wrapper for setTaskStatus with error handling. * Direct function wrapper for setTaskStatus with error handling.
* *
* @param {Object} args - Command arguments containing id, status and tasksJsonPath. * @param {Object} args - Command arguments containing id, status and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function setTaskStatusDirect(args, log) { export async function setTaskStatusDirect(args, log) {
// Destructure expected args, including the resolved tasksJsonPath
const { tasksJsonPath, id, status } = args;
try { try {
log.info(`Setting task status with args: ${JSON.stringify(args)}`); log.info(`Setting task status with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided // Check required parameters
if (!tasksJsonPath) { if (!args.id) {
const errorMessage = 'tasksJsonPath is required but was not provided.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
}
// Check required parameters (id and status)
if (!id) {
const errorMessage = const errorMessage =
'No task ID specified. Please provide a task ID to update.'; 'No task ID specified. Please provide a task ID to update.';
log.error(errorMessage); log.error(errorMessage);
@@ -46,7 +34,7 @@ export async function setTaskStatusDirect(args, log) {
}; };
} }
if (!status) { if (!args.status) {
const errorMessage = const errorMessage =
'No status specified. Please provide a new status value.'; 'No status specified. Please provide a new status value.';
log.error(errorMessage); log.error(errorMessage);
@@ -57,16 +45,32 @@ export async function setTaskStatusDirect(args, log) {
}; };
} }
// Use the provided path // Get tasks file path
const tasksPath = tasksJsonPath; let tasksPath;
try {
// The enhanced findTasksJsonPath will now search in parent directories if needed
tasksPath = findTasksJsonPath(args, log);
log.info(`Found tasks file at: ${tasksPath}`);
} catch (error) {
log.error(`Error finding tasks file: ${error.message}`);
return {
success: false,
error: {
code: 'TASKS_FILE_ERROR',
message: `${error.message}\n\nPlease ensure you are in a Task Master project directory or use the --project-root parameter to specify the path to your project.`
},
fromCache: false
};
}
// Execute core setTaskStatus function // Execute core setTaskStatus function
const taskId = id; const taskId = args.id;
const newStatus = status; const newStatus = args.status;
log.info(`Setting task ${taskId} status to "${newStatus}"`); log.info(`Setting task ${taskId} status to "${newStatus}"`);
// Call the core function with proper silent mode handling // Call the core function with proper silent mode handling
let result;
enableSilentMode(); // Enable silent mode before calling core function enableSilentMode(); // Enable silent mode before calling core function
try { try {
// Call the core function // Call the core function
@@ -75,20 +79,19 @@ export async function setTaskStatusDirect(args, log) {
log.info(`Successfully set task ${taskId} status to ${newStatus}`); log.info(`Successfully set task ${taskId} status to ${newStatus}`);
// Return success data // Return success data
const result = { result = {
success: true, success: true,
data: { data: {
message: `Successfully updated task ${taskId} status to "${newStatus}"`, message: `Successfully updated task ${taskId} status to "${newStatus}"`,
taskId, taskId,
status: newStatus, status: newStatus,
tasksPath: tasksPath // Return the path used tasksPath
}, },
fromCache: false // This operation always modifies state and should never be cached fromCache: false // This operation always modifies state and should never be cached
}; };
return result;
} catch (error) { } catch (error) {
log.error(`Error setting task status: ${error.message}`); log.error(`Error setting task status: ${error.message}`);
return { result = {
success: false, success: false,
error: { error: {
code: 'SET_STATUS_ERROR', code: 'SET_STATUS_ERROR',
@@ -100,6 +103,8 @@ export async function setTaskStatusDirect(args, log) {
// ALWAYS restore normal logging in finally block // ALWAYS restore normal logging in finally block
disableSilentMode(); disableSilentMode();
} }
return result;
} catch (error) { } catch (error) {
// Ensure silent mode is disabled if there was an uncaught error in the outer try block // Ensure silent mode is disabled if there was an uncaught error in the outer try block
if (isSilentMode()) { if (isSilentMode()) {

View File

@@ -6,6 +6,7 @@
import { findTaskById } from '../../../../scripts/modules/utils.js'; import { findTaskById } from '../../../../scripts/modules/utils.js';
import { readJSON } from '../../../../scripts/modules/utils.js'; import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -15,29 +16,28 @@ import {
* Direct function wrapper for showing task details with error handling and caching. * Direct function wrapper for showing task details with error handling and caching.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task or subtask to show.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function showTaskDirect(args, log) { export async function showTaskDirect(args, log) {
// Destructure expected args let tasksPath;
const { tasksJsonPath, id } = args; try {
// Find the tasks path first - needed for cache key and execution
if (!tasksJsonPath) { tasksPath = findTasksJsonPath(args, log);
log.error('showTaskDirect called without tasksJsonPath'); } catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_ARGUMENT', code: 'FILE_NOT_FOUND_ERROR',
message: 'tasksJsonPath is required' message: error.message
}, },
fromCache: false fromCache: false
}; };
} }
// Validate task ID // Validate task ID
const taskId = id; const taskId = args.id;
if (!taskId) { if (!taskId) {
log.error('Task ID is required'); log.error('Task ID is required');
return { return {
@@ -50,8 +50,8 @@ export async function showTaskDirect(args, log) {
}; };
} }
// Generate cache key using the provided task path and ID // Generate cache key using task path and ID
const cacheKey = `showTask:${tasksJsonPath}:${taskId}`; const cacheKey = `showTask:${tasksPath}:${taskId}`;
// Define the action function to be executed on cache miss // Define the action function to be executed on cache miss
const coreShowTaskAction = async () => { const coreShowTaskAction = async () => {
@@ -59,19 +59,16 @@ export async function showTaskDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
log.info( log.info(`Retrieving task details for ID: ${taskId} from ${tasksPath}`);
`Retrieving task details for ID: ${taskId} from ${tasksJsonPath}`
);
// Read tasks data using the provided path // Read tasks data
const data = readJSON(tasksJsonPath); const data = readJSON(tasksPath);
if (!data || !data.tasks) { if (!data || !data.tasks) {
disableSilentMode(); // Disable before returning
return { return {
success: false, success: false,
error: { error: {
code: 'INVALID_TASKS_FILE', code: 'INVALID_TASKS_FILE',
message: `No valid tasks found in ${tasksJsonPath}` message: `No valid tasks found in ${tasksPath}`
} }
}; };
} }
@@ -80,7 +77,6 @@ export async function showTaskDirect(args, log) {
const task = findTaskById(data.tasks, taskId); const task = findTaskById(data.tasks, taskId);
if (!task) { if (!task) {
disableSilentMode(); // Disable before returning
return { return {
success: false, success: false,
error: { error: {

View File

@@ -8,6 +8,7 @@ import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
getAnthropicClientForMCP, getAnthropicClientForMCP,
getPerplexityClientForMCP getPerplexityClientForMCP
@@ -16,31 +17,19 @@ import {
/** /**
* Direct function wrapper for updateSubtaskById with error handling. * Direct function wrapper for updateSubtaskById with error handling.
* *
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateSubtaskByIdDirect(args, log, context = {}) { export async function updateSubtaskByIdDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, id, prompt, research } = args;
try { try {
log.info(`Updating subtask with args: ${JSON.stringify(args)}`); log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided // Check required parameters
if (!tasksJsonPath) { if (!args.id) {
const errorMessage = 'tasksJsonPath is required but was not provided.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
}
// Check required parameters (id and prompt)
if (!id) {
const errorMessage = const errorMessage =
'No subtask ID specified. Please provide a subtask ID to update.'; 'No subtask ID specified. Please provide a subtask ID to update.';
log.error(errorMessage); log.error(errorMessage);
@@ -51,7 +40,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
}; };
} }
if (!prompt) { if (!args.prompt) {
const errorMessage = const errorMessage =
'No prompt specified. Please provide a prompt with information to add to the subtask.'; 'No prompt specified. Please provide a prompt with information to add to the subtask.';
log.error(errorMessage); log.error(errorMessage);
@@ -63,7 +52,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
} }
// Validate subtask ID format // Validate subtask ID format
const subtaskId = id; const subtaskId = args.id;
if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') { if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') {
const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`; const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`;
log.error(errorMessage); log.error(errorMessage);
@@ -85,14 +74,24 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
}; };
} }
// Use the provided path // Get tasks file path
const tasksPath = tasksJsonPath; let tasksPath;
try {
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Error finding tasks file: ${error.message}`);
return {
success: false,
error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false
};
}
// Get research flag // Get research flag
const useResearch = research === true; const useResearch = args.research === true;
log.info( log.info(
`Updating subtask with ID ${subtaskIdStr} with prompt "${prompt}" and research: ${useResearch}` `Updating subtask with ID ${subtaskIdStr} with prompt "${args.prompt}" and research: ${useResearch}`
); );
// Initialize the appropriate AI client based on research flag // Initialize the appropriate AI client based on research flag
@@ -135,7 +134,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
const updatedSubtask = await updateSubtaskById( const updatedSubtask = await updateSubtaskById(
tasksPath, tasksPath,
subtaskIdStr, subtaskIdStr,
prompt, args.prompt,
useResearch, useResearch,
{ {
session, session,

View File

@@ -4,6 +4,7 @@
*/ */
import { updateTaskById } from '../../../../scripts/modules/task-manager.js'; import { updateTaskById } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -16,32 +17,19 @@ import {
/** /**
* Direct function wrapper for updateTaskById with error handling. * Direct function wrapper for updateTaskById with error handling.
* *
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateTaskByIdDirect(args, log, context = {}) { export async function updateTaskByIdDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args, including the resolved tasksJsonPath
const { tasksJsonPath, id, prompt, research } = args;
try { try {
log.info(`Updating task with args: ${JSON.stringify(args)}`); log.info(`Updating task with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided // Check required parameters
if (!tasksJsonPath) { if (!args.id) {
const errorMessage = 'tasksJsonPath is required but was not provided.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
}
// Check required parameters (id and prompt)
if (!id) {
const errorMessage = const errorMessage =
'No task ID specified. Please provide a task ID to update.'; 'No task ID specified. Please provide a task ID to update.';
log.error(errorMessage); log.error(errorMessage);
@@ -52,7 +40,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
}; };
} }
if (!prompt) { if (!args.prompt) {
const errorMessage = const errorMessage =
'No prompt specified. Please provide a prompt with new information for the task update.'; 'No prompt specified. Please provide a prompt with new information for the task update.';
log.error(errorMessage); log.error(errorMessage);
@@ -65,15 +53,15 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
// Parse taskId - handle both string and number values // Parse taskId - handle both string and number values
let taskId; let taskId;
if (typeof id === 'string') { if (typeof args.id === 'string') {
// Handle subtask IDs (e.g., "5.2") // Handle subtask IDs (e.g., "5.2")
if (id.includes('.')) { if (args.id.includes('.')) {
taskId = id; // Keep as string for subtask IDs taskId = args.id; // Keep as string for subtask IDs
} else { } else {
// Parse as integer for main task IDs // Parse as integer for main task IDs
taskId = parseInt(id, 10); taskId = parseInt(args.id, 10);
if (isNaN(taskId)) { if (isNaN(taskId)) {
const errorMessage = `Invalid task ID: ${id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`; const errorMessage = `Invalid task ID: ${args.id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`;
log.error(errorMessage); log.error(errorMessage);
return { return {
success: false, success: false,
@@ -83,14 +71,24 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
} }
} }
} else { } else {
taskId = id; taskId = args.id;
} }
// Use the provided path // Get tasks file path
const tasksPath = tasksJsonPath; let tasksPath;
try {
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Error finding tasks file: ${error.message}`);
return {
success: false,
error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false
};
}
// Get research flag // Get research flag
const useResearch = research === true; const useResearch = args.research === true;
// Initialize appropriate AI client based on research flag // Initialize appropriate AI client based on research flag
let aiClient; let aiClient;
@@ -115,7 +113,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
} }
log.info( log.info(
`Updating task with ID ${taskId} with prompt "${prompt}" and research: ${useResearch}` `Updating task with ID ${taskId} with prompt "${args.prompt}" and research: ${useResearch}`
); );
try { try {
@@ -135,7 +133,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
await updateTaskById( await updateTaskById(
tasksPath, tasksPath,
taskId, taskId,
prompt, args.prompt,
useResearch, useResearch,
{ {
mcpLog: logWrapper, // Use our wrapper object that has the expected method structure mcpLog: logWrapper, // Use our wrapper object that has the expected method structure
@@ -151,7 +149,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
data: { data: {
message: `Successfully updated task with ID ${taskId} based on the prompt`, message: `Successfully updated task with ID ${taskId} based on the prompt`,
taskId, taskId,
tasksPath: tasksPath, // Return the used path tasksPath,
useResearch useResearch
}, },
fromCache: false // This operation always modifies state and should never be cached fromCache: false // This operation always modifies state and should never be cached

View File

@@ -8,6 +8,7 @@ import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
} from '../../../../scripts/modules/utils.js'; } from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
getAnthropicClientForMCP, getAnthropicClientForMCP,
getPerplexityClientForMCP getPerplexityClientForMCP
@@ -16,31 +17,19 @@ import {
/** /**
* Direct function wrapper for updating tasks based on new context/prompt. * Direct function wrapper for updating tasks based on new context/prompt.
* *
* @param {Object} args - Command arguments containing fromId, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing fromId, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateTasksDirect(args, log, context = {}) { export async function updateTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, from, prompt, research } = args;
try { try {
log.info(`Updating tasks with args: ${JSON.stringify(args)}`); log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
const errorMessage = 'tasksJsonPath is required but was not provided.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
}
// Check for the common mistake of using 'id' instead of 'from' // Check for the common mistake of using 'id' instead of 'from'
if (args.id !== undefined && from === undefined) { if (args.id !== undefined && args.from === undefined) {
const errorMessage = const errorMessage =
"You specified 'id' parameter but 'update' requires 'from' parameter. Use 'from' for this tool or use 'update_task' tool if you want to update a single task."; "You specified 'id' parameter but 'update' requires 'from' parameter. Use 'from' for this tool or use 'update_task' tool if you want to update a single task.";
log.error(errorMessage); log.error(errorMessage);
@@ -57,7 +46,7 @@ export async function updateTasksDirect(args, log, context = {}) {
} }
// Check required parameters // Check required parameters
if (!from) { if (!args.from) {
const errorMessage = const errorMessage =
'No from ID specified. Please provide a task ID to start updating from.'; 'No from ID specified. Please provide a task ID to start updating from.';
log.error(errorMessage); log.error(errorMessage);
@@ -68,7 +57,7 @@ export async function updateTasksDirect(args, log, context = {}) {
}; };
} }
if (!prompt) { if (!args.prompt) {
const errorMessage = const errorMessage =
'No prompt specified. Please provide a prompt with new context for task updates.'; 'No prompt specified. Please provide a prompt with new context for task updates.';
log.error(errorMessage); log.error(errorMessage);
@@ -81,10 +70,10 @@ export async function updateTasksDirect(args, log, context = {}) {
// Parse fromId - handle both string and number values // Parse fromId - handle both string and number values
let fromId; let fromId;
if (typeof from === 'string') { if (typeof args.from === 'string') {
fromId = parseInt(from, 10); fromId = parseInt(args.from, 10);
if (isNaN(fromId)) { if (isNaN(fromId)) {
const errorMessage = `Invalid from ID: ${from}. Task ID must be a positive integer.`; const errorMessage = `Invalid from ID: ${args.from}. Task ID must be a positive integer.`;
log.error(errorMessage); log.error(errorMessage);
return { return {
success: false, success: false,
@@ -93,11 +82,24 @@ export async function updateTasksDirect(args, log, context = {}) {
}; };
} }
} else { } else {
fromId = from; fromId = args.from;
}
// Get tasks file path
let tasksPath;
try {
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Error finding tasks file: ${error.message}`);
return {
success: false,
error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false
};
} }
// Get research flag // Get research flag
const useResearch = research === true; const useResearch = args.research === true;
// Initialize appropriate AI client based on research flag // Initialize appropriate AI client based on research flag
let aiClient; let aiClient;
@@ -122,25 +124,16 @@ export async function updateTasksDirect(args, log, context = {}) {
} }
log.info( log.info(
`Updating tasks from ID ${fromId} with prompt "${prompt}" and research: ${useResearch}` `Updating tasks from ID ${fromId} with prompt "${args.prompt}" and research: ${useResearch}`
); );
// Create the logger wrapper to ensure compatibility with core functions
const logWrapper = {
info: (message, ...args) => log.info(message, ...args),
warn: (message, ...args) => log.warn(message, ...args),
error: (message, ...args) => log.error(message, ...args),
debug: (message, ...args) => log.debug && log.debug(message, ...args), // Handle optional debug
success: (message, ...args) => log.info(message, ...args) // Map success to info if needed
};
try { try {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Execute core updateTasks function, passing the AI client and session // Execute core updateTasks function, passing the AI client and session
await updateTasks(tasksJsonPath, fromId, prompt, useResearch, { await updateTasks(tasksPath, fromId, args.prompt, useResearch, {
mcpLog: logWrapper, // Pass the wrapper instead of the raw log object mcpLog: log,
session session
}); });
@@ -151,7 +144,7 @@ export async function updateTasksDirect(args, log, context = {}) {
data: { data: {
message: `Successfully updated tasks from ID ${fromId} based on the prompt`, message: `Successfully updated tasks from ID ${fromId} based on the prompt`,
fromId, fromId,
tasksPath: tasksJsonPath, tasksPath,
useResearch useResearch
}, },
fromCache: false // This operation always modifies state and should never be cached fromCache: false // This operation always modifies state and should never be cached

View File

@@ -3,6 +3,7 @@
*/ */
import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js'; import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { import {
enableSilentMode, enableSilentMode,
disableSilentMode disableSilentMode
@@ -12,30 +13,17 @@ import fs from 'fs';
/** /**
* Validate dependencies in tasks.json * Validate dependencies in tasks.json
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function validateDependenciesDirect(args, log) { export async function validateDependenciesDirect(args, log) {
// Destructure the explicit tasksJsonPath
const { tasksJsonPath } = args;
if (!tasksJsonPath) {
log.error('validateDependenciesDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
try { try {
log.info(`Validating dependencies in tasks: ${tasksJsonPath}`); log.info(`Validating dependencies in tasks...`);
// Use the provided tasksJsonPath // Find the tasks.json path
const tasksPath = tasksJsonPath; const tasksPath = findTasksJsonPath(args, log);
// Verify the file exists // Verify the file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -51,7 +39,7 @@ export async function validateDependenciesDirect(args, log) {
// Enable silent mode to prevent console logs from interfering with JSON response // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); enableSilentMode();
// Call the original command function using the provided tasksPath // Call the original command function
await validateDependenciesCommand(tasksPath); await validateDependenciesCommand(tasksPath);
// Restore normal logging // Restore normal logging

View File

@@ -28,7 +28,6 @@ import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
import { complexityReportDirect } from './direct-functions/complexity-report.js'; import { complexityReportDirect } from './direct-functions/complexity-report.js';
import { addDependencyDirect } from './direct-functions/add-dependency.js'; import { addDependencyDirect } from './direct-functions/add-dependency.js';
import { removeTaskDirect } from './direct-functions/remove-task.js'; import { removeTaskDirect } from './direct-functions/remove-task.js';
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
// Re-export utility functions // Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js'; export { findTasksJsonPath } from './utils/path-utils.js';
@@ -93,6 +92,5 @@ export {
fixDependenciesDirect, fixDependenciesDirect,
complexityReportDirect, complexityReportDirect,
addDependencyDirect, addDependencyDirect,
removeTaskDirect, removeTaskDirect
initializeProjectDirect
}; };

View File

@@ -291,103 +291,3 @@ function findTasksWithNpmConsideration(startDir, log) {
} }
} }
} }
/**
* Finds potential PRD document files based on common naming patterns
* @param {string} projectRoot - The project root directory
* @param {string|null} explicitPath - Optional explicit path provided by the user
* @param {Object} log - Logger object
* @returns {string|null} - The path to the first found PRD file, or null if none found
*/
export function findPRDDocumentPath(projectRoot, explicitPath, log) {
// If explicit path is provided, check if it exists
if (explicitPath) {
const fullPath = path.isAbsolute(explicitPath)
? explicitPath
: path.resolve(projectRoot, explicitPath);
if (fs.existsSync(fullPath)) {
log.info(`Using provided PRD document path: ${fullPath}`);
return fullPath;
} else {
log.warn(
`Provided PRD document path not found: ${fullPath}, will search for alternatives`
);
}
}
// Common locations and file patterns for PRD documents
const commonLocations = [
'', // Project root
'scripts/'
];
const commonFileNames = ['PRD.md', 'prd.md', 'PRD.txt', 'prd.txt'];
// Check all possible combinations
for (const location of commonLocations) {
for (const fileName of commonFileNames) {
const potentialPath = path.join(projectRoot, location, fileName);
if (fs.existsSync(potentialPath)) {
log.info(`Found PRD document at: ${potentialPath}`);
return potentialPath;
}
}
}
log.warn(`No PRD document found in common locations within ${projectRoot}`);
return null;
}
/**
* Resolves the tasks output directory path
* @param {string} projectRoot - The project root directory
* @param {string|null} explicitPath - Optional explicit output path provided by the user
* @param {Object} log - Logger object
* @returns {string} - The resolved tasks directory path
*/
export function resolveTasksOutputPath(projectRoot, explicitPath, log) {
// If explicit path is provided, use it
if (explicitPath) {
const outputPath = path.isAbsolute(explicitPath)
? explicitPath
: path.resolve(projectRoot, explicitPath);
log.info(`Using provided tasks output path: ${outputPath}`);
return outputPath;
}
// Default output path: tasks/tasks.json in the project root
const defaultPath = path.resolve(projectRoot, 'tasks', 'tasks.json');
log.info(`Using default tasks output path: ${defaultPath}`);
// Ensure the directory exists
const outputDir = path.dirname(defaultPath);
if (!fs.existsSync(outputDir)) {
log.info(`Creating tasks directory: ${outputDir}`);
fs.mkdirSync(outputDir, { recursive: true });
}
return defaultPath;
}
/**
* Resolves various file paths needed for MCP operations based on project root
* @param {string} projectRoot - The project root directory
* @param {Object} args - Command arguments that may contain explicit paths
* @param {Object} log - Logger object
* @returns {Object} - An object containing resolved paths
*/
export function resolveProjectPaths(projectRoot, args, log) {
const prdPath = findPRDDocumentPath(projectRoot, args.input, log);
const tasksJsonPath = resolveTasksOutputPath(projectRoot, args.output, log);
// You can add more path resolutions here as needed
return {
projectRoot,
prdPath,
tasksJsonPath
// Add additional path properties as needed
};
}

View File

@@ -0,0 +1 @@

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { addDependencyDirect } from '../core/task-master-core.js'; import { addDependencyDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addDependency tool with the MCP server * Register the addDependency tool with the MCP server
@@ -28,57 +27,42 @@ export function registerAddDependencyTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info( log.info(
`Adding dependency for task ${args.id} to depend on ${args.dependsOn}` `Adding dependency for task ${args.id} to depend on ${args.dependsOn}`
); );
reportProgress({ progress: 0 });
// Get project root from args or session // Get project root using the utility function
const rootFolder = let rootFolder = getProjectRootFromSession(session, log);
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined // Fallback to args.projectRoot if session didn't provide one
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
} }
// Resolve the path to tasks.json // Call the direct function with the resolved rootFolder
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
// Call the direct function with the resolved path
const result = await addDependencyDirect( const result = await addDependencyDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
dependsOn: args.dependsOn
}, },
log log,
// Remove context object { reportProgress, mcpLog: log, session }
); );
reportProgress({ progress: 100 });
// Log result // Log result
if (result.success) { if (result.success) {
log.info(`Successfully added dependency: ${result.data.message}`); log.info(`Successfully added dependency: ${result.data.message}`);

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { addSubtaskDirect } from '../core/task-master-core.js'; import { addSubtaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addSubtask tool with the MCP server * Register the addSubtask tool with the MCP server
@@ -49,57 +48,36 @@ export function registerAddSubtaskTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
skipGenerate: z skipGenerate: z
.boolean() .boolean()
.optional() .optional()
.describe('Skip regenerating task files'), .describe('Skip regenerating task files'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Adding subtask with args: ${JSON.stringify(args)}`); log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
}
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await addSubtaskDirect( const result = await addSubtaskDirect(
{ {
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder,
id: args.id, ...args
taskId: args.taskId,
title: args.title,
description: args.description,
details: args.details,
status: args.status,
dependencies: args.dependencies,
skipGenerate: args.skipGenerate
}, },
log log,
{ reportProgress, mcpLog: log, session }
); );
if (result.success) { if (result.success) {

View File

@@ -12,7 +12,6 @@ import {
handleApiResult handleApiResult
} from './utils.js'; } from './utils.js';
import { addTaskDirect } from '../core/task-master-core.js'; import { addTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addTask tool with the MCP server * Register the addTask tool with the MCP server
@@ -23,28 +22,7 @@ export function registerAddTaskTool(server) {
name: 'add_task', name: 'add_task',
description: 'Add a new task using AI', description: 'Add a new task using AI',
parameters: z.object({ parameters: z.object({
prompt: z prompt: z.string().describe('Description of the task to add'),
.string()
.optional()
.describe(
'Description of the task to add (required if not using manual fields)'
),
title: z
.string()
.optional()
.describe('Task title (for manual task creation)'),
description: z
.string()
.optional()
.describe('Task description (for manual task creation)'),
details: z
.string()
.optional()
.describe('Implementation details (for manual task creation)'),
testStrategy: z
.string()
.optional()
.describe('Test strategy (for manual task creation)'),
dependencies: z dependencies: z
.string() .string()
.optional() .optional()
@@ -53,60 +31,36 @@ export function registerAddTaskTool(server) {
.string() .string()
.optional() .optional()
.describe('Task priority (high, medium, low)'), .describe('Task priority (high, medium, low)'),
file: z file: z.string().optional().describe('Path to the tasks file'),
.string()
.optional()
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.'), .optional()
.describe('Root directory of the project'),
research: z research: z
.boolean() .boolean()
.optional() .optional()
.describe('Whether to use research capabilities for task creation') .describe('Whether to use research capabilities for task creation')
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, reportProgress, session }) => {
try { try {
log.info(`Starting add-task with args: ${JSON.stringify(args)}`); log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
// Get project root from args or session // Get project root from session
const rootFolder = let rootFolder = getProjectRootFromSession(session, log);
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
// Call the direct function // Call the direct function
const result = await addTaskDirect( const result = await addTaskDirect(
{ {
// Pass the explicitly resolved path ...args,
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder
// Pass other relevant args
prompt: args.prompt,
dependencies: args.dependencies,
priority: args.priority,
research: args.research
}, },
log, log,
{ session } { reportProgress, session }
); );
// Return the result // Return the result

View File

@@ -10,8 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { analyzeTaskComplexityDirect } from '../core/task-master-core.js'; import { analyzeTaskComplexityDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import path from 'path';
/** /**
* Register the analyze tool with the MCP server * Register the analyze tool with the MCP server
@@ -35,10 +33,8 @@ export function registerAnalyzeTool(server) {
.describe( .describe(
'LLM model to use for analysis (defaults to configured model)' 'LLM model to use for analysis (defaults to configured model)'
), ),
threshold: z.coerce threshold: z
.number() .union([z.number(), z.string()])
.min(1)
.max(10)
.optional() .optional()
.describe( .describe(
'Minimum complexity score to recommend expansion (1-10) (default: 5)' 'Minimum complexity score to recommend expansion (1-10) (default: 5)'
@@ -46,16 +42,17 @@ export function registerAnalyzeTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
research: z research: z
.boolean() .boolean()
.optional() .optional()
.describe('Use Perplexity AI for research-backed complexity analysis'), .describe('Use Perplexity AI for research-backed complexity analysis'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
@@ -63,40 +60,17 @@ export function registerAnalyzeTool(server) {
`Analyzing task complexity with args: ${JSON.stringify(args)}` `Analyzing task complexity with args: ${JSON.stringify(args)}`
); );
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
} }
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
const outputPath = args.output
? path.resolve(rootFolder, args.output)
: path.resolve(rootFolder, 'scripts', 'task-complexity-report.json');
const result = await analyzeTaskComplexityDirect( const result = await analyzeTaskComplexityDirect(
{ {
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder,
outputPath: outputPath, ...args
model: args.model,
threshold: args.threshold,
research: args.research
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { clearSubtasksDirect } from '../core/task-master-core.js'; import { clearSubtasksDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the clearSubtasks tool with the MCP server * Register the clearSubtasks tool with the MCP server
@@ -30,58 +29,41 @@ export function registerClearSubtasksTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}) })
.refine((data) => data.id || data.all, { .refine((data) => data.id || data.all, {
message: "Either 'id' or 'all' parameter must be provided", message: "Either 'id' or 'all' parameter must be provided",
path: ['id', 'all'] path: ['id', 'all']
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`); log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await clearSubtasksDirect( const result = await clearSubtasksDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
all: args.all
}, },
log log,
// Remove context object as clearSubtasksDirect likely doesn't need session/reportProgress { reportProgress, mcpLog: log, session }
); );
reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info(`Subtasks cleared successfully: ${result.data.message}`); log.info(`Subtasks cleared successfully: ${result.data.message}`);
} else { } else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { complexityReportDirect } from '../core/task-master-core.js'; import { complexityReportDirect } from '../core/task-master-core.js';
import path from 'path';
/** /**
* Register the complexityReport tool with the MCP server * Register the complexityReport tool with the MCP server
@@ -29,40 +28,35 @@ export function registerComplexityReportTool(server) {
), ),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info( log.info(
`Getting complexity report with args: ${JSON.stringify(args)}` `Getting complexity report with args: ${JSON.stringify(args)}`
); );
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
} }
// Resolve the path to the complexity report file
// Default to scripts/task-complexity-report.json relative to root
const reportPath = args.file
? path.resolve(rootFolder, args.file)
: path.resolve(rootFolder, 'scripts', 'task-complexity-report.json');
const result = await complexityReportDirect( const result = await complexityReportDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
reportPath: reportPath ...args
// No other args specific to this tool
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info( log.info(
`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}` `Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { expandAllTasksDirect } from '../core/task-master-core.js'; import { expandAllTasksDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the expandAll tool with the MCP server * Register the expandAll tool with the MCP server
@@ -44,51 +43,29 @@ export function registerExpandAllTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`); log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await expandAllTasksDirect( const result = await expandAllTasksDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
num: args.num,
research: args.research,
prompt: args.prompt,
force: args.force
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { expandTaskDirect } from '../core/task-master-core.js'; import { expandTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
@@ -24,7 +23,10 @@ export function registerExpandTaskTool(server) {
description: 'Expand a task into subtasks for detailed implementation', description: 'Expand a task into subtasks for detailed implementation',
parameters: z.object({ parameters: z.object({
id: z.string().describe('ID of task to expand'), id: z.string().describe('ID of task to expand'),
num: z.string().optional().describe('Number of subtasks to generate'), num: z
.union([z.string(), z.number()])
.optional()
.describe('Number of subtasks to generate'),
research: z research: z
.boolean() .boolean()
.optional() .optional()
@@ -33,55 +35,45 @@ export function registerExpandTaskTool(server) {
.string() .string()
.optional() .optional()
.describe('Additional context for subtask generation'), .describe('Additional context for subtask generation'),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.'), .optional()
force: z.boolean().optional().describe('Force the expansion') .describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, reportProgress, session }) => {
try { try {
log.info(`Starting expand-task with args: ${JSON.stringify(args)}`); log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
// Get project root from args or session // Get project root from session
const rootFolder = let rootFolder = getProjectRootFromSession(session, log);
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
} }
log.info(`Project root resolved to: ${rootFolder}`); log.info(`Project root resolved to: ${rootFolder}`);
// Resolve the path to tasks.json using the utility // Check for tasks.json in the standard locations
let tasksJsonPath; const tasksJsonPath = path.join(rootFolder, 'tasks', 'tasks.json');
try {
tasksJsonPath = findTasksJsonPath( if (fs.existsSync(tasksJsonPath)) {
{ projectRoot: rootFolder, file: args.file }, log.info(`Found tasks.json at ${tasksJsonPath}`);
log // Add the file parameter directly to args
); args.file = tasksJsonPath;
} catch (error) { } else {
log.error(`Error finding tasks.json: ${error.message}`); log.warn(`Could not find tasks.json at ${tasksJsonPath}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
// Call direct function with only session in the context, not reportProgress // Call direct function with only session in the context, not reportProgress
// Use the pattern recommended in the MCP guidelines // Use the pattern recommended in the MCP guidelines
const result = await expandTaskDirect( const result = await expandTaskDirect(
{ {
// Pass the explicitly resolved path ...args,
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder
// Pass other relevant args
id: args.id,
num: args.num,
research: args.research,
prompt: args.prompt,
force: args.force // Need to add force to parameters
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { fixDependenciesDirect } from '../core/task-master-core.js'; import { fixDependenciesDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the fixDependencies tool with the MCP server * Register the fixDependencies tool with the MCP server
@@ -21,45 +20,37 @@ export function registerFixDependenciesTool(server) {
name: 'fix_dependencies', name: 'fix_dependencies',
description: 'Fix invalid dependencies in tasks automatically', description: 'Fix invalid dependencies in tasks automatically',
parameters: z.object({ parameters: z.object({
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Fixing dependencies with args: ${JSON.stringify(args)}`); log.info(`Fixing dependencies with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
}
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await fixDependenciesDirect( const result = await fixDependenciesDirect(
{ {
tasksJsonPath: tasksJsonPath projectRoot: rootFolder,
...args
}, },
log log,
{ reportProgress, mcpLog: log, session }
); );
await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info(`Successfully fixed dependencies: ${result.data.message}`); log.info(`Successfully fixed dependencies: ${result.data.message}`);
} else { } else {

View File

@@ -10,8 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { generateTaskFilesDirect } from '../core/task-master-core.js'; import { generateTaskFilesDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import path from 'path';
/** /**
* Register the generate tool with the MCP server * Register the generate tool with the MCP server
@@ -23,59 +21,40 @@ export function registerGenerateTool(server) {
description: description:
'Generates individual task files in tasks/ directory based on tasks.json', 'Generates individual task files in tasks/ directory based on tasks.json',
parameters: z.object({ parameters: z.object({
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
output: z output: z
.string() .string()
.optional() .optional()
.describe('Output directory (default: same directory as tasks file)'), .describe('Output directory (default: same directory as tasks file)'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Generating task files with args: ${JSON.stringify(args)}`); log.info(`Generating task files with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
} }
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
// Determine output directory: use explicit arg or default to tasks.json directory
const outputDir = args.output
? path.resolve(rootFolder, args.output) // Resolve relative to root if needed
: path.dirname(tasksJsonPath);
const result = await generateTaskFilesDirect( const result = await generateTaskFilesDirect(
{ {
// Pass the explicitly resolved paths projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
outputDir: outputDir
// No other args specific to this tool
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info(`Successfully generated task files: ${result.data.message}`); log.info(`Successfully generated task files: ${result.data.message}`);
} else { } else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { showTaskDirect } from '../core/task-master-core.js'; import { showTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Custom processor function that removes allTasks from the response * Custom processor function that removes allTasks from the response
@@ -40,12 +39,15 @@ export function registerShowTaskTool(server) {
description: 'Get detailed information about a specific task', description: 'Get detailed information about a specific task',
parameters: z.object({ parameters: z.object({
id: z.string().describe('Task ID to get'), id: z.string().describe('Task ID to get'),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
// Log the session right at the start of execute // Log the session right at the start of execute
log.info( log.info(
`Session object received in execute: ${JSON.stringify(session)}` `Session object received in execute: ${JSON.stringify(session)}`
@@ -58,43 +60,26 @@ export function registerShowTaskTool(server) {
`Session object received in execute: ${JSON.stringify(session)}` `Session object received in execute: ${JSON.stringify(session)}`
); // Use JSON.stringify for better visibility ); // Use JSON.stringify for better visibility
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' } else if (!rootFolder) {
// Ensure we always have *some* root, even if session failed and args didn't provide one
rootFolder = process.cwd();
log.warn(
`Session and args failed to provide root, using CWD: ${rootFolder}`
); );
} }
log.info(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root log.info(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root
log.info(`Root folder: ${rootFolder}`); // Log the final resolved root log.info(`Root folder: ${rootFolder}`); // Log the final resolved root
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
log.info(`Attempting to use tasks file path: ${tasksJsonPath}`);
const result = await showTaskDirect( const result = await showTaskDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id
}, },
log log
); );

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { listTasksDirect } from '../core/task-master-core.js'; import { listTasksDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the getTasks tool with the MCP server * Register the getTasks tool with the MCP server
@@ -40,47 +39,33 @@ export function registerListTasksTool(server) {
), ),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: automatically detected from session or CWD)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Getting tasks with filters: ${JSON.stringify(args)}`); log.info(`Getting tasks with filters: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
// Use the error message from findTasksJsonPath for better context
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await listTasksDirect( const result = await listTasksDirect(
{ {
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder,
status: args.status, ...args
withSubtasks: args.withSubtasks
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
log.info( log.info(
`Retrieved ${result.success ? result.data?.tasks?.length || 0 : 0} tasks${result.fromCache ? ' (from cache)' : ''}` `Retrieved ${result.success ? result.data?.tasks?.length || 0 : 0} tasks${result.fromCache ? ' (from cache)' : ''}`
); );

View File

@@ -64,6 +64,8 @@ export function registerTaskMasterTools(server, asyncManager) {
logger.error(`Error registering Task Master tools: ${error.message}`); logger.error(`Error registering Task Master tools: ${error.message}`);
throw error; throw error;
} }
logger.info('Registered Task Master MCP tools');
} }
export default { export default {

View File

@@ -1,93 +1,98 @@
import { z } from 'zod'; import { z } from 'zod';
import { import { execSync } from 'child_process';
createContentResponse, import { createContentResponse, createErrorResponse } from './utils.js'; // Only need response creators
createErrorResponse,
handleApiResult
} from './utils.js';
import { initializeProjectDirect } from '../core/task-master-core.js';
export function registerInitializeProjectTool(server) { export function registerInitializeProjectTool(server) {
server.addTool({ server.addTool({
name: 'initialize_project', name: 'initialize_project', // snake_case for tool name
description: description:
"Initializes a new Task Master project structure by calling the core initialization logic. Derives target directory from client session. If project details (name, description, author) are not provided, prompts the user or skips if 'yes' flag is true. DO NOT run without parameters.", "Initializes a new Task Master project structure in the current working directory by running 'task-master init'.",
parameters: z.object({ parameters: z.object({
projectName: z projectName: z
.string() .string()
.optional() .optional()
.describe( .describe('The name for the new project.'),
'The name for the new project. If not provided, prompt the user for it.'
),
projectDescription: z projectDescription: z
.string() .string()
.optional() .optional()
.describe( .describe('A brief description for the project.'),
'A brief description for the project. If not provided, prompt the user for it.'
),
projectVersion: z projectVersion: z
.string() .string()
.optional() .optional()
.describe( .describe("The initial version for the project (e.g., '0.1.0')."),
"The initial version for the project (e.g., '0.1.0'). User input not needed unless user requests to override." authorName: z.string().optional().describe("The author's name."),
),
authorName: z
.string()
.optional()
.describe(
"The author's name. User input not needed unless user requests to override."
),
skipInstall: z skipInstall: z
.boolean() .boolean()
.optional() .optional()
.default(false) .default(false)
.describe( .describe('Skip installing dependencies automatically.'),
'Skip installing dependencies automatically. Never do this unless you are sure the project is already installed.'
),
addAliases: z addAliases: z
.boolean() .boolean()
.optional() .optional()
.default(false) .default(false)
.describe( .describe('Add shell aliases (tm, taskmaster) to shell config file.'),
'Add shell aliases (tm, taskmaster) to shell config file. User input not needed.'
),
yes: z yes: z
.boolean() .boolean()
.optional() .optional()
.default(false) .default(false)
.describe( .describe('Skip prompts and use default values or provided arguments.')
"Skip prompts and use default values or provided arguments. Use true if you wish to skip details like the project name, etc. If the project information required for the initialization is not available or provided by the user, prompt if the user wishes to provide them (name, description, author) or skip them. If the user wishes to skip, set the 'yes' flag to true and do not set any other parameters." // projectRoot is not needed here as 'init' works on the current directory
),
projectRoot: z
.string()
.describe(
'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.'
)
}), }),
execute: async (args, context) => { execute: async (args, { log }) => {
const { log } = context; // Destructure context to get log
const session = context.session;
log.info(
'>>> Full Context Received by Tool:',
JSON.stringify(context, null, 2)
);
log.info(`Context received in tool function: ${context}`);
log.info(
`Session received in tool function: ${session ? session : 'undefined'}`
);
try { try {
log.info( log.info(
`Executing initialize_project tool with args: ${JSON.stringify(args)}` `Executing initialize_project with args: ${JSON.stringify(args)}`
); );
const result = await initializeProjectDirect(args, log, { session }); // Construct the command arguments carefully
// Using npx ensures it uses the locally installed version if available, or fetches it
let command = 'npx task-master init';
const cliArgs = [];
if (args.projectName)
cliArgs.push(`--name "${args.projectName.replace(/"/g, '\\"')}"`); // Escape quotes
if (args.projectDescription)
cliArgs.push(
`--description "${args.projectDescription.replace(/"/g, '\\"')}"`
);
if (args.projectVersion)
cliArgs.push(
`--version "${args.projectVersion.replace(/"/g, '\\"')}"`
);
if (args.authorName)
cliArgs.push(`--author "${args.authorName.replace(/"/g, '\\"')}"`);
if (args.skipInstall) cliArgs.push('--skip-install');
if (args.addAliases) cliArgs.push('--aliases');
if (args.yes) cliArgs.push('--yes');
return handleApiResult(result, log, 'Initialization failed'); command += ' ' + cliArgs.join(' ');
log.info(`Constructed command: ${command}`);
// Execute the command in the current working directory of the server process
// Capture stdout/stderr. Use a reasonable timeout (e.g., 5 minutes)
const output = execSync(command, {
encoding: 'utf8',
stdio: 'pipe',
timeout: 300000
});
log.info(`Initialization output:\n${output}`);
// Return a standard success response manually
return createContentResponse(
'Project initialized successfully.',
{ output: output } // Include output in the data payload
);
} catch (error) { } catch (error) {
const errorMessage = `Project initialization tool failed: ${error.message || 'Unknown error'}`; // Catch errors from execSync or timeouts
log.error(errorMessage, error); const errorMessage = `Project initialization failed: ${error.message}`;
return createErrorResponse(errorMessage, { details: error.stack }); const errorDetails =
error.stderr?.toString() || error.stdout?.toString() || error.message; // Provide stderr/stdout if available
log.error(`${errorMessage}\nDetails: ${errorDetails}`);
// Return a standard error response manually
return createErrorResponse(errorMessage, { details: errorDetails });
} }
} }
}); });

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { nextTaskDirect } from '../core/task-master-core.js'; import { nextTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the next-task tool with the MCP server * Register the next-task tool with the MCP server
@@ -22,49 +21,36 @@ export function registerNextTaskTool(server) {
description: description:
'Find the next task to work on based on dependencies and status', 'Find the next task to work on based on dependencies and status',
parameters: z.object({ parameters: z.object({
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Finding next task with args: ${JSON.stringify(args)}`); log.info(`Finding next task with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await nextTaskDirect( const result = await nextTaskDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath ...args
// No other args specific to this tool
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info( log.info(
`Successfully found next task: ${result.data?.task?.id || 'No available tasks'}` `Successfully found next task: ${result.data?.task?.id || 'No available tasks'}`

View File

@@ -5,16 +5,11 @@
import { z } from 'zod'; import { z } from 'zod';
import { import {
getProjectRootFromSession,
handleApiResult, handleApiResult,
createErrorResponse createErrorResponse,
getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { parsePRDDirect } from '../core/task-master-core.js'; import { parsePRDDirect } from '../core/task-master-core.js';
import {
resolveProjectPaths,
findPRDDocumentPath,
resolveTasksOutputPath
} from '../core/utils/path-utils.js';
/** /**
* Register the parsePRD tool with the MCP server * Register the parsePRD tool with the MCP server
@@ -24,24 +19,25 @@ export function registerParsePRDTool(server) {
server.addTool({ server.addTool({
name: 'parse_prd', name: 'parse_prd',
description: description:
"Parse a Product Requirements Document (PRD) text file to automatically generate initial tasks. Reinitializing the project is not necessary to run this tool. It is recommended to run parse-prd after initializing the project and creating/importing a prd.txt file in the project root's scripts/ directory.", 'Parse a Product Requirements Document (PRD) or text file to automatically generate initial tasks.',
parameters: z.object({ parameters: z.object({
input: z input: z
.string() .string()
.optional() .default('tasks/tasks.json')
.default('scripts/prd.txt') .describe(
.describe('Absolute path to the PRD document file (.txt, .md, etc.)'), 'Path to the PRD document file (relative to project root or absolute)'
),
numTasks: z numTasks: z
.string() .string()
.optional() .optional()
.describe( .describe(
'Approximate number of top-level tasks to generate (default: 10). As the agent, if you have enough information, ensure to enter a number of tasks that would logically scale with project complexity. Avoid entering numbers above 50 due to context window limitations.' 'Approximate number of top-level tasks to generate (default: 10)'
), ),
output: z output: z
.string() .string()
.optional() .optional()
.describe( .describe(
'Output path for tasks.json file (default: tasks/tasks.json)' 'Output path for tasks.json file (relative to project root or absolute, default: tasks/tasks.json)'
), ),
force: z force: z
.boolean() .boolean()
@@ -49,44 +45,26 @@ export function registerParsePRDTool(server) {
.describe('Allow overwriting an existing tasks.json file.'), .describe('Allow overwriting an existing tasks.json file.'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be absolute path.') .optional()
.describe(
'Root directory of the project (default: automatically detected from session or CWD)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`); log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
} }
// Resolve input (PRD) and output (tasks.json) paths using the utility
const { projectRoot, prdPath, tasksJsonPath } = resolveProjectPaths(
rootFolder,
args,
log
);
// Check if PRD path was found (resolveProjectPaths returns null if not found and not provided)
if (!prdPath) {
return createErrorResponse(
'No PRD document found or provided. Please ensure a PRD file exists (e.g., PRD.md) or provide a valid input file path.'
);
}
// Call the direct function with fully resolved paths
const result = await parsePRDDirect( const result = await parsePRDDirect(
{ {
projectRoot: projectRoot, projectRoot: rootFolder,
input: prdPath, ...args
output: tasksJsonPath,
numTasks: args.numTasks,
force: args.force
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { removeDependencyDirect } from '../core/task-master-core.js'; import { removeDependencyDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the removeDependency tool with the MCP server * Register the removeDependency tool with the MCP server
@@ -26,55 +25,38 @@ export function registerRemoveDependencyTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info( log.info(
`Removing dependency for task ${args.id} from ${args.dependsOn} with args: ${JSON.stringify(args)}` `Removing dependency for task ${args.id} from ${args.dependsOn} with args: ${JSON.stringify(args)}`
); );
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await removeDependencyDirect( const result = await removeDependencyDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
dependsOn: args.dependsOn
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info(`Successfully removed dependency: ${result.data.message}`); log.info(`Successfully removed dependency: ${result.data.message}`);
} else { } else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { removeSubtaskDirect } from '../core/task-master-core.js'; import { removeSubtaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the removeSubtask tool with the MCP server * Register the removeSubtask tool with the MCP server
@@ -35,58 +34,40 @@ export function registerRemoveSubtaskTool(server) {
file: z file: z
.string() .string()
.optional() .optional()
.describe( .describe('Path to the tasks file (default: tasks/tasks.json)'),
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
skipGenerate: z skipGenerate: z
.boolean() .boolean()
.optional() .optional()
.describe('Skip regenerating task files'), .describe('Skip regenerating task files'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Removing subtask with args: ${JSON.stringify(args)}`); log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await removeSubtaskDirect( const result = await removeSubtaskDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
convert: args.convert,
skipGenerate: args.skipGenerate
}, },
log log /*, { reportProgress, mcpLog: log, session}*/
); );
// await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info(`Subtask removed successfully: ${result.data.message}`); log.info(`Subtask removed successfully: ${result.data.message}`);
} else { } else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { removeTaskDirect } from '../core/task-master-core.js'; import { removeTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the remove-task tool with the MCP server * Register the remove-task tool with the MCP server
@@ -24,10 +23,13 @@ export function registerRemoveTaskTool(server) {
id: z id: z
.string() .string()
.describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"), .describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.'), .optional()
.describe(
'Root directory of the project (default: current working directory)'
),
confirm: z confirm: z
.boolean() .boolean()
.optional() .optional()
@@ -37,40 +39,28 @@ export function registerRemoveTaskTool(server) {
try { try {
log.info(`Removing task with ID: ${args.id}`); log.info(`Removing task with ID: ${args.id}`);
// Get project root from args or session // Get project root from session
const rootFolder = let rootFolder = getProjectRootFromSession(session, log);
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' } else if (!rootFolder) {
// Ensure we have a default if nothing else works
rootFolder = process.cwd();
log.warn(
`Session and args failed to provide root, using CWD: ${rootFolder}`
); );
} }
log.info(`Using project root: ${rootFolder}`); log.info(`Using project root: ${rootFolder}`);
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
log.info(`Using tasks file path: ${tasksJsonPath}`);
// Assume client has already handled confirmation if needed // Assume client has already handled confirmation if needed
const result = await removeTaskDirect( const result = await removeTaskDirect(
{ {
tasksJsonPath: tasksJsonPath, id: args.id,
id: args.id file: args.file,
projectRoot: rootFolder
}, },
log log
); );

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { setTaskStatusDirect } from '../core/task-master-core.js'; import { setTaskStatusDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the setTaskStatus tool with the MCP server * Register the setTaskStatus tool with the MCP server
@@ -31,48 +30,31 @@ export function registerSetTaskStatusTool(server) {
.describe( .describe(
"New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'." "New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."
), ),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: automatically detected)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Setting status of task(s) ${args.id} to: ${args.status}`); log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
// Get project root from args or session // Get project root from session
const rootFolder = let rootFolder = getProjectRootFromSession(session, log);
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
} }
// Resolve the path to tasks.json // Call the direct function with the project root
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
// Call the direct function with the resolved path
const result = await setTaskStatusDirect( const result = await setTaskStatusDirect(
{ {
// Pass the explicitly resolved path ...args,
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder
// Pass other relevant args
id: args.id,
status: args.status
}, },
log log
); );

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { updateSubtaskByIdDirect } from '../core/task-master-core.js'; import { updateSubtaskByIdDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update-subtask tool with the MCP server * Register the update-subtask tool with the MCP server
@@ -32,48 +31,29 @@ export function registerUpdateSubtaskTool(server) {
.boolean() .boolean()
.optional() .optional()
.describe('Use Perplexity AI for research-backed updates'), .describe('Use Perplexity AI for research-backed updates'),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Updating subtask with args: ${JSON.stringify(args)}`); log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await updateSubtaskByIdDirect( const result = await updateSubtaskByIdDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { updateTaskByIdDirect } from '../core/task-master-core.js'; import { updateTaskByIdDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update-task tool with the MCP server * Register the update-task tool with the MCP server
@@ -32,48 +31,29 @@ export function registerUpdateTaskTool(server) {
.boolean() .boolean()
.optional() .optional()
.describe('Use Perplexity AI for research-backed updates'), .describe('Use Perplexity AI for research-backed updates'),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Updating task with args: ${JSON.stringify(args)}`); log.info(`Updating task with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await updateTaskByIdDirect( const result = await updateTaskByIdDirect(
{ {
// Pass the explicitly resolved path projectRoot: rootFolder,
tasksJsonPath: tasksJsonPath, ...args
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { updateTasksDirect } from '../core/task-master-core.js'; import { updateTasksDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update tool with the MCP server * Register the update tool with the MCP server
@@ -34,46 +33,29 @@ export function registerUpdateTool(server) {
.boolean() .boolean()
.optional() .optional()
.describe('Use Perplexity AI for research-backed updates'), .describe('Use Perplexity AI for research-backed updates'),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session }) => {
try { try {
log.info(`Updating tasks with args: ${JSON.stringify(args)}`); log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined if (!rootFolder && args.projectRoot) {
if (!rootFolder) { rootFolder = args.projectRoot;
return createErrorResponse( log.info(`Using project root from args as fallback: ${rootFolder}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// Resolve the path to tasks.json
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await updateTasksDirect( const result = await updateTasksDirect(
{ {
tasksJsonPath: tasksJsonPath, projectRoot: rootFolder,
from: args.from, ...args
prompt: args.prompt,
research: args.research
}, },
log, log,
{ session } { session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from './utils.js';
import { validateDependenciesDirect } from '../core/task-master-core.js'; import { validateDependenciesDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the validateDependencies tool with the MCP server * Register the validateDependencies tool with the MCP server
@@ -22,45 +21,37 @@ export function registerValidateDependenciesTool(server) {
description: description:
'Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.', 'Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.',
parameters: z.object({ parameters: z.object({
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
.describe(
'Root directory of the project (default: current working directory)'
)
}), }),
execute: async (args, { log, session }) => { execute: async (args, { log, session, reportProgress }) => {
try { try {
log.info(`Validating dependencies with args: ${JSON.stringify(args)}`); log.info(`Validating dependencies with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
if (!rootFolder) { if (!rootFolder && args.projectRoot) {
return createErrorResponse( rootFolder = args.projectRoot;
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Using project root from args as fallback: ${rootFolder}`);
);
}
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
} }
const result = await validateDependenciesDirect( const result = await validateDependenciesDirect(
{ {
tasksJsonPath: tasksJsonPath projectRoot: rootFolder,
...args
}, },
log log,
{ reportProgress, mcpLog: log, session }
); );
await reportProgress({ progress: 100 });
if (result.success) { if (result.success) {
log.info( log.info(
`Successfully validated dependencies: ${result.data.message}` `Successfully validated dependencies: ${result.data.message}`

4
package-lock.json generated
View File

@@ -31,7 +31,9 @@
}, },
"bin": { "bin": {
"task-master": "bin/task-master.js", "task-master": "bin/task-master.js",
"task-master-mcp": "mcp-server/server.js" "task-master-init": "bin/task-master-init.js",
"task-master-mcp": "mcp-server/server.js",
"task-master-mcp-server": "mcp-server/server.js"
}, },
"devDependencies": { "devDependencies": {
"@changesets/changelog-github": "^0.5.1", "@changesets/changelog-github": "^0.5.1",

View File

@@ -1,12 +1,14 @@
{ {
"name": "task-master-ai", "name": "task-master-ai",
"version": "0.11.0", "version": "0.10.1",
"description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.", "description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"bin": { "bin": {
"task-master": "bin/task-master.js", "task-master": "bin/task-master.js",
"task-master-mcp": "mcp-server/server.js" "task-master-init": "bin/task-master-init.js",
"task-master-mcp": "mcp-server/server.js",
"task-master-mcp-server": "mcp-server/server.js"
}, },
"scripts": { "scripts": {
"test": "node --experimental-vm-modules node_modules/.bin/jest", "test": "node --experimental-vm-modules node_modules/.bin/jest",
@@ -15,10 +17,10 @@
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage", "test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
"prepare-package": "node scripts/prepare-package.js", "prepare-package": "node scripts/prepare-package.js",
"prepublishOnly": "npm run prepare-package", "prepublishOnly": "npm run prepare-package",
"prepare": "chmod +x bin/task-master.js mcp-server/server.js", "prepare": "chmod +x bin/task-master.js bin/task-master-init.js mcp-server/server.js",
"changeset": "changeset", "changeset": "changeset",
"release": "changeset publish", "release": "changeset publish",
"inspector": "npx @modelcontextprotocol/inspector node mcp-server/server.js", "inspector": "CLIENT_PORT=8888 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node mcp-server/server.js",
"mcp-server": "node mcp-server/server.js", "mcp-server": "node mcp-server/server.js",
"format-check": "prettier --check .", "format-check": "prettier --check .",
"format": "prettier --write ." "format": "prettier --write ."

View File

@@ -1,3 +1,5 @@
#!/usr/bin/env node
/** /**
* Task Master * Task Master
* Copyright (c) 2025 Eyal Toledano, Ralph Khreish * Copyright (c) 2025 Eyal Toledano, Ralph Khreish
@@ -13,6 +15,8 @@
* For the full license text, see the LICENSE file in the root directory. * For the full license text, see the LICENSE file in the root directory.
*/ */
console.log('Starting task-master-ai...');
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
@@ -23,11 +27,52 @@ import chalk from 'chalk';
import figlet from 'figlet'; import figlet from 'figlet';
import boxen from 'boxen'; import boxen from 'boxen';
import gradient from 'gradient-string'; import gradient from 'gradient-string';
import { isSilentMode } from './modules/utils.js'; import { Command } from 'commander';
// Debug information
console.log('Node version:', process.version);
console.log('Current directory:', process.cwd());
console.log('Script path:', import.meta.url);
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
// Configure the CLI program
const program = new Command();
program
.name('task-master-init')
.description('Initialize a new Claude Task Master project')
.version('1.0.0') // Will be replaced by prepare-package script
.option('-y, --yes', 'Skip prompts and use default values')
.option('-n, --name <name>', 'Project name')
.option('-my_name <name>', 'Project name (alias for --name)')
.option('-d, --description <description>', 'Project description')
.option(
'-my_description <description>',
'Project description (alias for --description)'
)
.option('-v, --version <version>', 'Project version')
.option('-my_version <version>', 'Project version (alias for --version)')
.option('--my_name <name>', 'Project name (alias for --name)')
.option('-a, --author <author>', 'Author name')
.option('--skip-install', 'Skip installing dependencies')
.option('--dry-run', 'Show what would be done without making changes')
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
.parse(process.argv);
const options = program.opts();
// Map custom aliases to standard options
if (options.my_name && !options.name) {
options.name = options.my_name;
}
if (options.my_description && !options.description) {
options.description = options.my_description;
}
if (options.my_version && !options.version) {
options.version = options.my_version;
}
// Define log levels // Define log levels
const LOG_LEVELS = { const LOG_LEVELS = {
debug: 0, debug: 0,
@@ -48,8 +93,6 @@ const warmGradient = gradient(['#fb8b24', '#e36414', '#9a031e']);
// Display a fancy banner // Display a fancy banner
function displayBanner() { function displayBanner() {
if (isSilentMode()) return;
console.clear(); console.clear();
const bannerText = figlet.textSync('Task Master AI', { const bannerText = figlet.textSync('Task Master AI', {
font: 'Standard', font: 'Standard',
@@ -87,8 +130,6 @@ function log(level, ...args) {
if (LOG_LEVELS[level] >= LOG_LEVEL) { if (LOG_LEVELS[level] >= LOG_LEVEL) {
const icon = icons[level] || ''; const icon = icons[level] || '';
// Only output to console if not in silent mode
if (!isSilentMode()) {
if (level === 'error') { if (level === 'error') {
console.error(icon, chalk.red(...args)); console.error(icon, chalk.red(...args));
} else if (level === 'warn') { } else if (level === 'warn') {
@@ -101,7 +142,6 @@ function log(level, ...args) {
console.log(icon, ...args); console.log(icon, ...args);
} }
} }
}
// Write to debug log if DEBUG=true // Write to debug log if DEBUG=true
if (process.env.DEBUG === 'true') { if (process.env.DEBUG === 'true') {
@@ -379,43 +419,20 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
log('info', `Created file: ${targetPath}`); log('info', `Created file: ${targetPath}`);
} }
// Main function to initialize a new project (Now relies solely on passed options) // Main function to initialize a new project
async function initializeProject(options = {}) { async function initializeProject(options = {}) {
// Receives options as argument // Display the banner
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner(); displayBanner();
}
// Debug logging only if not in silent mode // If options are provided, use them directly without prompting
if (!isSilentMode()) { if (options.projectName && options.projectDescription) {
console.log('===== DEBUG: INITIALIZE PROJECT OPTIONS RECEIVED ====='); const projectName = options.projectName;
console.log('Full options object:', JSON.stringify(options)); const projectDescription = options.projectDescription;
console.log('options.yes:', options.yes); const projectVersion = options.projectVersion || '1.0.0';
console.log('options.name:', options.name); const authorName = options.authorName || '';
console.log('==================================================');
}
// Determine if we should skip prompts based on the passed options
const skipPrompts = options.yes || (options.name && options.description);
if (!isSilentMode()) {
console.log('Skip prompts determined:', skipPrompts);
}
if (skipPrompts) {
if (!isSilentMode()) {
console.log('SKIPPING PROMPTS - Using defaults or provided values');
}
// Use provided options or defaults
const projectName = options.name || 'task-master-project';
const projectDescription =
options.description || 'A project managed with Task Master AI';
const projectVersion = options.version || '0.1.0'; // Default from commands.js or here
const authorName = options.author || 'Vibe coder'; // Default if not provided
const dryRun = options.dryRun || false; const dryRun = options.dryRun || false;
const skipInstall = options.skipInstall || false; const skipInstall = options.skipInstall || false;
const addAliases = options.aliases || false; const addAliases = options.addAliases || false;
if (dryRun) { if (dryRun) {
log('info', 'DRY RUN MODE: No files will be modified'); log('info', 'DRY RUN MODE: No files will be modified');
@@ -441,7 +458,6 @@ async function initializeProject(options = {}) {
}; };
} }
// Create structure using determined values
createProjectStructure( createProjectStructure(
projectName, projectName,
projectDescription, projectDescription,
@@ -450,16 +466,22 @@ async function initializeProject(options = {}) {
skipInstall, skipInstall,
addAliases addAliases
); );
} else { return {
// Prompting logic (only runs if skipPrompts is false) projectName,
log('info', 'Required options not provided, proceeding with prompts.'); projectDescription,
projectVersion,
authorName
};
}
// Otherwise, prompt the user for input
// Create readline interface only when needed
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout
}); });
try { try {
// Prompt user for input...
const projectName = await promptQuestion( const projectName = await promptQuestion(
rl, rl,
chalk.cyan('Enter project name: ') chalk.cyan('Enter project name: ')
@@ -471,21 +493,25 @@ async function initializeProject(options = {}) {
const projectVersionInput = await promptQuestion( const projectVersionInput = await promptQuestion(
rl, rl,
chalk.cyan('Enter project version (default: 1.0.0): ') chalk.cyan('Enter project version (default: 1.0.0): ')
); // Use a default for prompt );
const authorName = await promptQuestion( const authorName = await promptQuestion(
rl, rl,
chalk.cyan('Enter your name: ') chalk.cyan('Enter your name: ')
); );
// Ask about shell aliases
const addAliasesInput = await promptQuestion( const addAliasesInput = await promptQuestion(
rl, rl,
chalk.cyan('Add shell aliases for task-master? (Y/n): ') chalk.cyan('Add shell aliases for task-master? (Y/n): ')
); );
const addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n'; const addAliases = addAliasesInput.trim().toLowerCase() !== 'n';
// Set default version if not provided
const projectVersion = projectVersionInput.trim() const projectVersion = projectVersionInput.trim()
? projectVersionInput ? projectVersionInput
: '1.0.0'; : '1.0.0';
// Confirm settings... // Confirm settings
console.log('\nProject settings:'); console.log('\nProject settings:');
console.log(chalk.blue('Name:'), chalk.white(projectName)); console.log(chalk.blue('Name:'), chalk.white(projectName));
console.log(chalk.blue('Description:'), chalk.white(projectDescription)); console.log(chalk.blue('Description:'), chalk.white(projectDescription));
@@ -495,10 +521,8 @@ async function initializeProject(options = {}) {
chalk.white(authorName || 'Not specified') chalk.white(authorName || 'Not specified')
); );
console.log( console.log(
chalk.blue( chalk.blue('Add shell aliases:'),
'Add shell aliases (so you can use "tm" instead of "task-master"):' chalk.white(addAliases ? 'Yes' : 'No')
),
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
); );
const confirmInput = await promptQuestion( const confirmInput = await promptQuestion(
@@ -506,28 +530,22 @@ async function initializeProject(options = {}) {
chalk.yellow('\nDo you want to continue with these settings? (Y/n): ') chalk.yellow('\nDo you want to continue with these settings? (Y/n): ')
); );
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n'; const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
// Close the readline interface
rl.close(); rl.close();
if (!shouldContinue) { if (!shouldContinue) {
log('info', 'Project initialization cancelled by user'); log('info', 'Project initialization cancelled by user');
process.exit(0); // Exit if cancelled return null;
return; // Added return for clarity
} }
// Still respect dryRun/skipInstall if passed initially even when prompting
const dryRun = options.dryRun || false; const dryRun = options.dryRun || false;
const skipInstall = options.skipInstall || false; const skipInstall = options.skipInstall || false;
if (dryRun) { if (dryRun) {
log('info', 'DRY RUN MODE: No files will be modified'); log('info', 'DRY RUN MODE: No files will be modified');
log(
'info',
`Would initialize project: ${projectName} (${projectVersion})`
);
log('info', `Description: ${projectDescription}`);
log('info', `Author: ${authorName || 'Not specified'}`);
log('info', 'Would create/update necessary project files'); log('info', 'Would create/update necessary project files');
if (addAliasesPrompted) { if (addAliases) {
log('info', 'Would add shell aliases for task-master'); log('info', 'Would add shell aliases for task-master');
} }
if (!skipInstall) { if (!skipInstall) {
@@ -542,20 +560,26 @@ async function initializeProject(options = {}) {
}; };
} }
// Create structure using prompted values, respecting initial options where relevant // Create the project structure
createProjectStructure( createProjectStructure(
projectName, projectName,
projectDescription, projectDescription,
projectVersion, projectVersion,
authorName, authorName,
skipInstall, // Use value from initial options skipInstall,
addAliasesPrompted // Use value from prompt addAliases
); );
return {
projectName,
projectDescription,
projectVersion,
authorName
};
} catch (error) { } catch (error) {
// Make sure to close readline on error
rl.close(); rl.close();
log('error', `Error during prompting: ${error.message}`); // Use log function throw error;
process.exit(1); // Exit on error during prompts
}
} }
} }
@@ -616,7 +640,8 @@ function createProjectStructure(
jsonwebtoken: '^9.0.2', jsonwebtoken: '^9.0.2',
'lru-cache': '^10.2.0', 'lru-cache': '^10.2.0',
openai: '^4.89.0', openai: '^4.89.0',
ora: '^8.2.0' ora: '^8.2.0',
'task-master-ai': '^0.9.31'
} }
}; };
@@ -765,7 +790,6 @@ function createProjectStructure(
} }
// Run npm install automatically // Run npm install automatically
if (!isSilentMode()) {
console.log( console.log(
boxen(chalk.cyan('Installing dependencies...'), { boxen(chalk.cyan('Installing dependencies...'), {
padding: 0.5, padding: 0.5,
@@ -774,7 +798,6 @@ function createProjectStructure(
borderColor: 'blue' borderColor: 'blue'
}) })
); );
}
try { try {
if (!skipInstall) { if (!skipInstall) {
@@ -789,7 +812,6 @@ function createProjectStructure(
} }
// Display success message // Display success message
if (!isSilentMode()) {
console.log( console.log(
boxen( boxen(
warmGradient.multiline( warmGradient.multiline(
@@ -805,7 +827,6 @@ function createProjectStructure(
} }
) )
); );
}
// Add shell aliases if requested // Add shell aliases if requested
if (addAliases) { if (addAliases) {
@@ -813,7 +834,6 @@ function createProjectStructure(
} }
// Display next steps in a nice box // Display next steps in a nice box
if (!isSilentMode()) {
console.log( console.log(
boxen( boxen(
chalk.cyan.bold('Things you can now do:') + chalk.cyan.bold('Things you can now do:') +
@@ -876,7 +896,6 @@ function createProjectStructure(
} }
) )
); );
}
} }
// Function to setup MCP configuration for Cursor integration // Function to setup MCP configuration for Cursor integration
@@ -893,14 +912,14 @@ function setupMCPConfiguration(targetDir, projectName) {
const newMCPServer = { const newMCPServer = {
'task-master-ai': { 'task-master-ai': {
command: 'npx', command: 'npx',
args: ['-y', 'task-master-mcp'], args: ['-y', 'task-master-mcp-server'],
env: { env: {
ANTHROPIC_API_KEY: 'YOUR_ANTHROPIC_API_KEY', ANTHROPIC_API_KEY: '%ANTHROPIC_API_KEY%',
PERPLEXITY_API_KEY: 'YOUR_PERPLEXITY_API_KEY', PERPLEXITY_API_KEY: '%PERPLEXITY_API_KEY%',
MODEL: 'claude-3-7-sonnet-20250219', MODEL: 'claude-3-7-sonnet-20250219',
PERPLEXITY_MODEL: 'sonar-pro', PERPLEXITY_MODEL: 'sonar-pro',
MAX_TOKENS: 64000, MAX_TOKENS: 64000,
TEMPERATURE: 0.2, TEMPERATURE: 0.3,
DEFAULT_SUBTASKS: 5, DEFAULT_SUBTASKS: 5,
DEFAULT_PRIORITY: 'medium' DEFAULT_PRIORITY: 'medium'
} }
@@ -909,10 +928,7 @@ function setupMCPConfiguration(targetDir, projectName) {
// Check if mcp.json already exists // Check if mcp.json already exists
if (fs.existsSync(mcpJsonPath)) { if (fs.existsSync(mcpJsonPath)) {
log( log('info', 'MCP configuration file already exists, updating...');
'info',
'MCP configuration file already exists, checking for existing task-master-mcp...'
);
try { try {
// Read existing config // Read existing config
const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8')); const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8'));
@@ -922,23 +938,6 @@ function setupMCPConfiguration(targetDir, projectName) {
mcpConfig.mcpServers = {}; mcpConfig.mcpServers = {};
} }
// Check if any existing server configuration already has task-master-mcp in its args
const hasMCPString = Object.values(mcpConfig.mcpServers).some(
(server) =>
server.args &&
server.args.some(
(arg) => typeof arg === 'string' && arg.includes('task-master-mcp')
)
);
if (hasMCPString) {
log(
'info',
'Found existing task-master-mcp configuration in mcp.json, leaving untouched'
);
return; // Exit early, don't modify the existing configuration
}
// Add the task-master-ai server if it doesn't exist // Add the task-master-ai server if it doesn't exist
if (!mcpConfig.mcpServers['task-master-ai']) { if (!mcpConfig.mcpServers['task-master-ai']) {
mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai']; mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];
@@ -987,5 +986,51 @@ function setupMCPConfiguration(targetDir, projectName) {
log('info', 'MCP server will use the installed task-master-ai package'); log('info', 'MCP server will use the installed task-master-ai package');
} }
// Ensure necessary functions are exported // Run the initialization if this script is executed directly
export { initializeProject, log }; // Only export what's needed by commands.js // The original check doesn't work with npx and global commands
// if (process.argv[1] === fileURLToPath(import.meta.url)) {
// Instead, we'll always run the initialization if this file is the main module
console.log('Checking if script should run initialization...');
console.log('import.meta.url:', import.meta.url);
console.log('process.argv:', process.argv);
// Always run initialization when this file is loaded directly
// This works with both direct node execution and npx/global commands
(async function main() {
try {
console.log('Starting initialization...');
// Check if we should use the CLI options or prompt for input
if (options.yes || (options.name && options.description)) {
// When using --yes flag or providing name and description, use CLI options
await initializeProject({
projectName: options.name || 'task-master-project',
projectDescription:
options.description ||
'A task management system for AI-driven development',
projectVersion: options.version || '1.0.0',
authorName: options.author || '',
dryRun: options.dryRun || false,
skipInstall: options.skipInstall || false,
addAliases: options.aliases || false
});
} else {
// Otherwise, prompt for input normally
await initializeProject({
dryRun: options.dryRun || false,
skipInstall: options.skipInstall || false
});
}
// Process should exit naturally after completion
console.log('Initialization completed, exiting...');
process.exit(0);
} catch (error) {
console.error('Failed to initialize project:', error);
log('error', 'Failed to initialize project:', error);
process.exit(1);
}
})();
// Export functions for programmatic use
export { initializeProject, createProjectStructure, log };

View File

@@ -873,23 +873,13 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
* @param {number} expectedCount - Expected number of subtasks * @param {number} expectedCount - Expected number of subtasks
* @param {number} parentTaskId - Parent task ID * @param {number} parentTaskId - Parent task ID
* @returns {Array} Parsed subtasks * @returns {Array} Parsed subtasks
* @throws {Error} If parsing fails or JSON is invalid
*/ */
function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) { function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
// Set default values for optional parameters try {
startId = startId || 1;
expectedCount = expectedCount || 2; // Default to 2 subtasks if not specified
// Handle empty text case
if (!text || text.trim() === '') {
throw new Error('Empty text provided, cannot parse subtasks');
}
// Locate JSON array in the text // Locate JSON array in the text
const jsonStartIndex = text.indexOf('['); const jsonStartIndex = text.indexOf('[');
const jsonEndIndex = text.lastIndexOf(']'); const jsonEndIndex = text.lastIndexOf(']');
// If no valid JSON array found, throw error
if ( if (
jsonStartIndex === -1 || jsonStartIndex === -1 ||
jsonEndIndex === -1 || jsonEndIndex === -1 ||
@@ -900,21 +890,15 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
// Extract and parse the JSON // Extract and parse the JSON
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1); const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
let subtasks; let subtasks = JSON.parse(jsonText);
try { // Validate
subtasks = JSON.parse(jsonText);
} catch (parseError) {
throw new Error(`Failed to parse JSON: ${parseError.message}`);
}
// Validate array
if (!Array.isArray(subtasks)) { if (!Array.isArray(subtasks)) {
throw new Error('Parsed content is not an array'); throw new Error('Parsed content is not an array');
} }
// Log warning if count doesn't match expected // Log warning if count doesn't match expected
if (expectedCount && subtasks.length !== expectedCount) { if (subtasks.length !== expectedCount) {
log( log(
'warn', 'warn',
`Expected ${expectedCount} subtasks, but parsed ${subtasks.length}` `Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`
@@ -924,10 +908,10 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
// Normalize subtask IDs if they don't match // Normalize subtask IDs if they don't match
subtasks = subtasks.map((subtask, index) => { subtasks = subtasks.map((subtask, index) => {
// Assign the correct ID if it doesn't match // Assign the correct ID if it doesn't match
if (!subtask.id || subtask.id !== startId + index) { if (subtask.id !== startId + index) {
log( log(
'warn', 'warn',
`Correcting subtask ID from ${subtask.id || 'undefined'} to ${startId + index}` `Correcting subtask ID from ${subtask.id} to ${startId + index}`
); );
subtask.id = startId + index; subtask.id = startId + index;
} }
@@ -944,15 +928,36 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
// Ensure status is 'pending' // Ensure status is 'pending'
subtask.status = 'pending'; subtask.status = 'pending';
// Add parentTaskId if provided // Add parentTaskId
if (parentTaskId) {
subtask.parentTaskId = parentTaskId; subtask.parentTaskId = parentTaskId;
}
return subtask; return subtask;
}); });
return subtasks; return subtasks;
} catch (error) {
log('error', `Error parsing subtasks: ${error.message}`);
// Create a fallback array of empty subtasks if parsing fails
log('warn', 'Creating fallback subtasks');
const fallbackSubtasks = [];
for (let i = 0; i < expectedCount; i++) {
fallbackSubtasks.push({
id: startId + i,
title: `Subtask ${startId + i}`,
description: 'Auto-generated fallback subtask',
dependencies: [],
details:
'This is a fallback subtask created because parsing failed. Please update with real details.',
status: 'pending',
parentTaskId: parentTaskId
});
}
return fallbackSubtasks;
}
} }
/** /**

View File

@@ -10,9 +10,8 @@ import boxen from 'boxen';
import fs from 'fs'; import fs from 'fs';
import https from 'https'; import https from 'https';
import inquirer from 'inquirer'; import inquirer from 'inquirer';
import ora from 'ora';
import { CONFIG, log, readJSON, writeJSON } from './utils.js'; import { CONFIG, log, readJSON } from './utils.js';
import { import {
parsePRD, parsePRD,
updateTasks, updateTasks,
@@ -52,8 +51,6 @@ import {
stopLoadingIndicator stopLoadingIndicator
} from './ui.js'; } from './ui.js';
import { initializeProject } from '../init.js';
/** /**
* Configure and register CLI commands * Configure and register CLI commands
* @param {Object} program - Commander program instance * @param {Object} program - Commander program instance
@@ -792,27 +789,11 @@ function registerCommands(programInstance) {
// add-task command // add-task command
programInstance programInstance
.command('add-task') .command('add-task')
.description('Add a new task using AI or manual input') .description('Add a new task using AI')
.option('-f, --file <file>', 'Path to the tasks file', 'tasks/tasks.json') .option('-f, --file <file>', 'Path to the tasks file', 'tasks/tasks.json')
.option('-p, --prompt <text>', 'Description of the task to add (required)')
.option( .option(
'-p, --prompt <prompt>', '-d, --dependencies <ids>',
'Description of the task to add (required if not using manual fields)'
)
.option('-t, --title <title>', 'Task title (for manual task creation)')
.option(
'-d, --description <description>',
'Task description (for manual task creation)'
)
.option(
'--details <details>',
'Implementation details (for manual task creation)'
)
.option(
'--test-strategy <testStrategy>',
'Test strategy (for manual task creation)'
)
.option(
'--dependencies <dependencies>',
'Comma-separated list of task IDs this task depends on' 'Comma-separated list of task IDs this task depends on'
) )
.option( .option(
@@ -820,91 +801,32 @@ function registerCommands(programInstance) {
'Task priority (high, medium, low)', 'Task priority (high, medium, low)',
'medium' 'medium'
) )
.option(
'-r, --research',
'Whether to use research capabilities for task creation'
)
.action(async (options) => { .action(async (options) => {
const isManualCreation = options.title && options.description; const tasksPath = options.file;
const prompt = options.prompt;
const dependencies = options.dependencies
? options.dependencies.split(',').map((id) => parseInt(id.trim(), 10))
: [];
const priority = options.priority;
// Validate that either prompt or title+description are provided if (!prompt) {
if (!options.prompt && !isManualCreation) {
console.error( console.error(
chalk.red( chalk.red(
'Error: Either --prompt or both --title and --description must be provided' 'Error: --prompt parameter is required. Please provide a task description.'
) )
); );
process.exit(1); process.exit(1);
} }
try { console.log(chalk.blue(`Adding new task with description: "${prompt}"`));
// Prepare dependencies if provided
let dependencies = [];
if (options.dependencies) {
dependencies = options.dependencies
.split(',')
.map((id) => parseInt(id.trim(), 10));
}
// Create manual task data if title and description are provided
let manualTaskData = null;
if (isManualCreation) {
manualTaskData = {
title: options.title,
description: options.description,
details: options.details || '',
testStrategy: options.testStrategy || ''
};
console.log(
chalk.blue(`Creating task manually with title: "${options.title}"`)
);
if (dependencies.length > 0) {
console.log(
chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)
);
}
if (options.priority) {
console.log(chalk.blue(`Priority: ${options.priority}`));
}
} else {
console.log( console.log(
chalk.blue( chalk.blue(
`Creating task with AI using prompt: "${options.prompt}"` `Dependencies: ${dependencies.length > 0 ? dependencies.join(', ') : 'None'}`
) )
); );
if (dependencies.length > 0) { console.log(chalk.blue(`Priority: ${priority}`));
console.log(
chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)
);
}
if (options.priority) {
console.log(chalk.blue(`Priority: ${options.priority}`));
}
}
const newTaskId = await addTask( await addTask(tasksPath, prompt, dependencies, priority);
options.file,
options.prompt,
dependencies,
options.priority,
{
session: process.env
},
options.research || false,
null,
manualTaskData
);
console.log(chalk.green(`✓ Added new task #${newTaskId}`));
console.log(chalk.gray('Next: Complete this task or add more tasks'));
} catch (error) {
console.error(chalk.red(`Error adding task: ${error.message}`));
if (error.stack && CONFIG.debug) {
console.error(error.stack);
}
process.exit(1);
}
}); });
// next command // next command
@@ -1371,6 +1293,44 @@ function registerCommands(programInstance) {
); );
} }
// init command (documentation only, implementation is in init.js)
programInstance
.command('init')
.description('Initialize a new project with Task Master structure')
.option('-n, --name <name>', 'Project name')
.option('-my_name <name>', 'Project name (alias for --name)')
.option('--my_name <name>', 'Project name (alias for --name)')
.option('-d, --description <description>', 'Project description')
.option(
'-my_description <description>',
'Project description (alias for --description)'
)
.option('-v, --version <version>', 'Project version')
.option('-my_version <version>', 'Project version (alias for --version)')
.option('-a, --author <author>', 'Author name')
.option('-y, --yes', 'Skip prompts and use default values')
.option('--skip-install', 'Skip installing dependencies')
.action(() => {
console.log(
chalk.yellow(
'The init command must be run as a standalone command: task-master init'
)
);
console.log(chalk.cyan('Example usage:'));
console.log(
chalk.white(
' task-master init -n "My Project" -d "Project description"'
)
);
console.log(
chalk.white(
' task-master init -my_name "My Project" -my_description "Project description"'
)
);
console.log(chalk.white(' task-master init -y'));
process.exit(0);
});
// remove-task command // remove-task command
programInstance programInstance
.command('remove-task') .command('remove-task')
@@ -1517,37 +1477,6 @@ function registerCommands(programInstance) {
} }
}); });
// init command (Directly calls the implementation from init.js)
programInstance
.command('init')
.description('Initialize a new project with Task Master structure')
.option('-y, --yes', 'Skip prompts and use default values')
.option('-n, --name <name>', 'Project name')
.option('-d, --description <description>', 'Project description')
.option('-v, --version <version>', 'Project version', '0.1.0') // Set default here
.option('-a, --author <author>', 'Author name')
.option('--skip-install', 'Skip installing dependencies')
.option('--dry-run', 'Show what would be done without making changes')
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
.action(async (cmdOptions) => {
// cmdOptions contains parsed arguments
try {
console.log('DEBUG: Running init command action in commands.js');
console.log(
'DEBUG: Options received by action:',
JSON.stringify(cmdOptions)
);
// Directly call the initializeProject function, passing the parsed options
await initializeProject(cmdOptions);
// initializeProject handles its own flow, including potential process.exit()
} catch (error) {
console.error(
chalk.red(`Error during initialization: ${error.message}`)
);
process.exit(1);
}
});
// Add more commands as needed... // Add more commands as needed...
return programInstance; return programInstance;

View File

@@ -14,8 +14,7 @@ import {
writeJSON, writeJSON,
taskExists, taskExists,
formatTaskId, formatTaskId,
findCycles, findCycles
isSilentMode
} from './utils.js'; } from './utils.js';
import { displayBanner } from './ui.js'; import { displayBanner } from './ui.js';
@@ -321,7 +320,6 @@ async function removeDependency(tasksPath, taskId, dependencyId) {
`Removed dependency: Task ${formattedTaskId} no longer depends on ${formattedDependencyId}` `Removed dependency: Task ${formattedTaskId} no longer depends on ${formattedDependencyId}`
); );
if (!isSilentMode()) {
// Display a more visually appealing success message // Display a more visually appealing success message
console.log( console.log(
boxen( boxen(
@@ -335,7 +333,6 @@ async function removeDependency(tasksPath, taskId, dependencyId) {
} }
) )
); );
}
// Regenerate task files // Regenerate task files
await generateTaskFiles(tasksPath, 'tasks'); await generateTaskFiles(tasksPath, 'tasks');
@@ -556,11 +553,8 @@ function cleanupSubtaskDependencies(tasksData) {
* Validate dependencies in task files * Validate dependencies in task files
* @param {string} tasksPath - Path to tasks.json * @param {string} tasksPath - Path to tasks.json
*/ */
async function validateDependenciesCommand(tasksPath, options = {}) { async function validateDependenciesCommand(tasksPath) {
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner(); displayBanner();
}
log('info', 'Checking for invalid dependencies in task files...'); log('info', 'Checking for invalid dependencies in task files...');
@@ -665,8 +659,7 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
if (changesDetected) { if (changesDetected) {
log('success', 'Invalid dependencies were removed from tasks.json'); log('success', 'Invalid dependencies were removed from tasks.json');
// Show detailed stats in a nice box - only if not in silent mode // Show detailed stats in a nice box
if (!isSilentMode()) {
console.log( console.log(
boxen( boxen(
chalk.green(`Dependency Validation Results:\n\n`) + chalk.green(`Dependency Validation Results:\n\n`) +
@@ -692,7 +685,6 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
console.log(` ${warning}`); console.log(` ${warning}`);
}); });
} }
}
// Regenerate task files to reflect the changes // Regenerate task files to reflect the changes
await generateTaskFiles(tasksPath, path.dirname(tasksPath)); await generateTaskFiles(tasksPath, path.dirname(tasksPath));
@@ -703,8 +695,7 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
'No invalid dependencies found - all dependencies are valid' 'No invalid dependencies found - all dependencies are valid'
); );
// Show validation summary - only if not in silent mode // Show validation summary
if (!isSilentMode()) {
console.log( console.log(
boxen( boxen(
chalk.green(`All Dependencies Are Valid\n\n`) + chalk.green(`All Dependencies Are Valid\n\n`) +
@@ -720,7 +711,6 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
) )
); );
} }
}
} catch (error) { } catch (error) {
log('error', 'Error validating dependencies:', error); log('error', 'Error validating dependencies:', error);
process.exit(1); process.exit(1);
@@ -757,13 +747,9 @@ function countAllDependencies(tasks) {
/** /**
* Fixes invalid dependencies in tasks.json * Fixes invalid dependencies in tasks.json
* @param {string} tasksPath - Path to tasks.json * @param {string} tasksPath - Path to tasks.json
* @param {Object} options - Options object
*/ */
async function fixDependenciesCommand(tasksPath, options = {}) { async function fixDependenciesCommand(tasksPath) {
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner(); displayBanner();
}
log('info', 'Checking for and fixing invalid dependencies in tasks.json...'); log('info', 'Checking for and fixing invalid dependencies in tasks.json...');
@@ -1100,7 +1086,6 @@ async function fixDependenciesCommand(tasksPath, options = {}) {
stats.duplicateDependenciesRemoved + stats.duplicateDependenciesRemoved +
stats.circularDependenciesFixed; stats.circularDependenciesFixed;
if (!isSilentMode()) {
if (totalFixedAll > 0) { if (totalFixedAll > 0) {
log('success', `Fixed ${totalFixedAll} dependency issues in total!`); log('success', `Fixed ${totalFixedAll} dependency issues in total!`);
@@ -1122,10 +1107,7 @@ async function fixDependenciesCommand(tasksPath, options = {}) {
) )
); );
} else { } else {
log( log('success', 'No dependency issues found - all dependencies are valid');
'success',
'No dependency issues found - all dependencies are valid'
);
console.log( console.log(
boxen( boxen(
@@ -1141,7 +1123,6 @@ async function fixDependenciesCommand(tasksPath, options = {}) {
) )
); );
} }
}
} catch (error) { } catch (error) {
log('error', 'Error in fix-dependencies command:', error); log('error', 'Error in fix-dependencies command:', error);
process.exit(1); process.exit(1);

View File

@@ -2711,9 +2711,6 @@ async function expandAllTasks(
} }
report(`Expanding all pending tasks with ${numSubtasks} subtasks each...`); report(`Expanding all pending tasks with ${numSubtasks} subtasks each...`);
if (useResearch) {
report('Using research-backed AI for more detailed subtasks');
}
// Load tasks // Load tasks
let data; let data;
@@ -2775,7 +2772,6 @@ async function expandAllTasks(
} }
let expandedCount = 0; let expandedCount = 0;
let expansionErrors = 0;
try { try {
// Sort tasks by complexity if report exists, otherwise by ID // Sort tasks by complexity if report exists, otherwise by ID
if (complexityReport && complexityReport.complexityAnalysis) { if (complexityReport && complexityReport.complexityAnalysis) {
@@ -2856,17 +2852,12 @@ async function expandAllTasks(
mcpLog mcpLog
); );
if ( if (aiResponse && aiResponse.subtasks) {
aiResponse &&
aiResponse.subtasks &&
Array.isArray(aiResponse.subtasks) &&
aiResponse.subtasks.length > 0
) {
// Process and add the subtasks to the task // Process and add the subtasks to the task
task.subtasks = aiResponse.subtasks.map((subtask, index) => ({ task.subtasks = aiResponse.subtasks.map((subtask, index) => ({
id: index + 1, id: index + 1,
title: subtask.title || `Subtask ${index + 1}`, title: subtask.title,
description: subtask.description || 'No description provided', description: subtask.description,
status: 'pending', status: 'pending',
dependencies: subtask.dependencies || [], dependencies: subtask.dependencies || [],
details: subtask.details || '' details: subtask.details || ''
@@ -2874,27 +2865,11 @@ async function expandAllTasks(
report(`Added ${task.subtasks.length} subtasks to task ${task.id}`); report(`Added ${task.subtasks.length} subtasks to task ${task.id}`);
expandedCount++; expandedCount++;
} else if (aiResponse && aiResponse.error) {
// Handle error response
const errorMsg = `Failed to generate subtasks for task ${task.id}: ${aiResponse.error}`;
report(errorMsg, 'error');
// Add task ID to error info and provide actionable guidance
const suggestion = aiResponse.suggestion.replace('<id>', task.id);
report(`Suggestion: ${suggestion}`, 'info');
expansionErrors++;
} else { } else {
report(`Failed to generate subtasks for task ${task.id}`, 'error'); report(`Failed to generate subtasks for task ${task.id}`, 'error');
report(
`Suggestion: Run 'task-master update-task --id=${task.id} --prompt="Generate subtasks for this task"' to manually create subtasks.`,
'info'
);
expansionErrors++;
} }
} catch (error) { } catch (error) {
report(`Error expanding task ${task.id}: ${error.message}`, 'error'); report(`Error expanding task ${task.id}: ${error.message}`, 'error');
expansionErrors++;
} }
// Small delay to prevent rate limiting // Small delay to prevent rate limiting
@@ -2916,8 +2891,7 @@ async function expandAllTasks(
success: true, success: true,
expandedCount, expandedCount,
tasksToExpand: tasksToExpand.length, tasksToExpand: tasksToExpand.length,
expansionErrors, message: `Successfully expanded ${expandedCount} out of ${tasksToExpand.length} tasks`
message: `Successfully expanded ${expandedCount} out of ${tasksToExpand.length} tasks${expansionErrors > 0 ? ` (${expansionErrors} errors)` : ''}`
}; };
} catch (error) { } catch (error) {
report(`Error expanding tasks: ${error.message}`, 'error'); report(`Error expanding tasks: ${error.message}`, 'error');
@@ -3120,7 +3094,7 @@ function clearSubtasks(tasksPath, taskIds) {
/** /**
* Add a new task using AI * Add a new task using AI
* @param {string} tasksPath - Path to the tasks.json file * @param {string} tasksPath - Path to the tasks.json file
* @param {string} prompt - Description of the task to add (required for AI-driven creation) * @param {string} prompt - Description of the task to add
* @param {Array} dependencies - Task dependencies * @param {Array} dependencies - Task dependencies
* @param {string} priority - Task priority * @param {string} priority - Task priority
* @param {function} reportProgress - Function to report progress to MCP server (optional) * @param {function} reportProgress - Function to report progress to MCP server (optional)
@@ -3128,7 +3102,6 @@ function clearSubtasks(tasksPath, taskIds) {
* @param {Object} session - Session object from MCP server (optional) * @param {Object} session - Session object from MCP server (optional)
* @param {string} outputFormat - Output format (text or json) * @param {string} outputFormat - Output format (text or json)
* @param {Object} customEnv - Custom environment variables (optional) * @param {Object} customEnv - Custom environment variables (optional)
* @param {Object} manualTaskData - Manual task data (optional, for direct task creation without AI)
* @returns {number} The new task ID * @returns {number} The new task ID
*/ */
async function addTask( async function addTask(
@@ -3138,8 +3111,7 @@ async function addTask(
priority = 'medium', priority = 'medium',
{ reportProgress, mcpLog, session } = {}, { reportProgress, mcpLog, session } = {},
outputFormat = 'text', outputFormat = 'text',
customEnv = null, customEnv = null
manualTaskData = null
) { ) {
let loadingIndicator = null; // Keep indicator variable accessible let loadingIndicator = null; // Keep indicator variable accessible
@@ -3197,15 +3169,6 @@ async function addTask(
); );
} }
let taskData;
// Check if manual task data is provided
if (manualTaskData) {
// Use manual task data directly
log('info', 'Using manually provided task data');
taskData = manualTaskData;
} else {
// Use AI to generate task data
// Create context string for task creation prompt // Create context string for task creation prompt
let contextTasks = ''; let contextTasks = '';
if (dependencies.length > 0) { if (dependencies.length > 0) {
@@ -3246,10 +3209,10 @@ async function addTask(
let claudeOverloaded = false; let claudeOverloaded = false;
let modelAttempts = 0; let modelAttempts = 0;
const maxModelAttempts = 2; // Try up to 2 models before giving up const maxModelAttempts = 2; // Try up to 2 models before giving up
let aiGeneratedTaskData = null; let taskData = null;
// Loop through model attempts // Loop through model attempts
while (modelAttempts < maxModelAttempts && !aiGeneratedTaskData) { while (modelAttempts < maxModelAttempts && !taskData) {
modelAttempts++; // Increment attempt counter modelAttempts++; // Increment attempt counter
const isLastAttempt = modelAttempts >= maxModelAttempts; const isLastAttempt = modelAttempts >= maxModelAttempts;
let modelType = null; // Track which model we're using let modelType = null; // Track which model we're using
@@ -3310,7 +3273,7 @@ async function addTask(
}); });
const responseText = response.choices[0].message.content; const responseText = response.choices[0].message.content;
aiGeneratedTaskData = parseTaskJsonResponse(responseText); taskData = parseTaskJsonResponse(responseText);
} else { } else {
// Use Claude (default) // Use Claude (default)
// Prepare API parameters // Prepare API parameters
@@ -3346,7 +3309,7 @@ async function addTask(
); );
// Parse the response using our helper // Parse the response using our helper
aiGeneratedTaskData = parseTaskJsonResponse(fullResponse); taskData = parseTaskJsonResponse(fullResponse);
} catch (streamError) { } catch (streamError) {
// Process stream errors explicitly // Process stream errors explicitly
log('error', `Stream error: ${streamError.message}`); log('error', `Stream error: ${streamError.message}`);
@@ -3391,7 +3354,7 @@ async function addTask(
} }
// If we got here without errors and have task data, we're done // If we got here without errors and have task data, we're done
if (aiGeneratedTaskData) { if (taskData) {
log( log(
'info', 'info',
`Successfully generated task data using ${modelType} on attempt ${modelAttempts}` `Successfully generated task data using ${modelType} on attempt ${modelAttempts}`
@@ -3429,122 +3392,105 @@ async function addTask(
} }
// If we don't have task data after all attempts, throw an error // If we don't have task data after all attempts, throw an error
if (!aiGeneratedTaskData) { if (!taskData) {
throw new Error( throw new Error(
'Failed to generate task data after all model attempts' 'Failed to generate task data after all model attempts'
); );
} }
// Set the AI-generated task data
taskData = aiGeneratedTaskData;
} catch (error) {
// Handle AI errors
log('error', `Error generating task with AI: ${error.message}`);
// Stop any loading indicator
if (outputFormat === 'text' && loadingIndicator) {
stopLoadingIndicator(loadingIndicator);
}
throw error;
}
}
// Create the new task object // Create the new task object
const newTask = { const newTask = {
id: newTaskId, id: newTaskId,
title: taskData.title, title: taskData.title,
description: taskData.description, description: taskData.description,
details: taskData.details || '',
testStrategy: taskData.testStrategy || '',
status: 'pending', status: 'pending',
dependencies: dependencies, dependencies: dependencies,
priority: priority priority: priority,
details: taskData.details || '',
testStrategy:
taskData.testStrategy ||
'Manually verify the implementation works as expected.'
}; };
// Add the task to the tasks array // Add the new task to the tasks array
data.tasks.push(newTask); data.tasks.push(newTask);
// Write the updated tasks to the file // Validate dependencies in the entire task set
log('info', 'Validating dependencies after adding new task...');
validateAndFixDependencies(data, null);
// Write the updated tasks back to the file
writeJSON(tasksPath, data); writeJSON(tasksPath, data);
// Generate markdown task files // Only show success messages for text mode (CLI)
log('info', 'Generating task files...');
await generateTaskFiles(tasksPath, path.dirname(tasksPath));
// Stop the loading indicator if it's still running
if (outputFormat === 'text' && loadingIndicator) {
stopLoadingIndicator(loadingIndicator);
}
// Show success message - only for text output (CLI)
if (outputFormat === 'text') { if (outputFormat === 'text') {
const table = new Table({
head: [
chalk.cyan.bold('ID'),
chalk.cyan.bold('Title'),
chalk.cyan.bold('Description')
],
colWidths: [5, 30, 50]
});
table.push([
newTask.id,
truncate(newTask.title, 27),
truncate(newTask.description, 47)
]);
console.log(chalk.green('✅ New task created successfully:'));
console.log(table.toString());
// Show success message // Show success message
const successBox = boxen(
chalk.green(`Successfully added new task #${newTaskId}:\n`) +
chalk.white.bold(newTask.title) +
'\n\n' +
chalk.white(newTask.description),
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1 }
}
);
console.log(successBox);
// Next steps suggestion
console.log( console.log(
boxen( boxen(
chalk.white.bold(`Task ${newTaskId} Created Successfully`) +
'\n\n' +
chalk.white(`Title: ${newTask.title}`) +
'\n' +
chalk.white(`Status: ${getStatusWithColor(newTask.status)}`) +
'\n' +
chalk.white(
`Priority: ${chalk.keyword(getPriorityColor(newTask.priority))(newTask.priority)}`
) +
'\n' +
(dependencies.length > 0
? chalk.white(`Dependencies: ${dependencies.join(', ')}`) + '\n'
: '') +
'\n' +
chalk.white.bold('Next Steps:') + chalk.white.bold('Next Steps:') +
'\n' + '\n\n' +
chalk.cyan( `${chalk.cyan('1.')} Run ${chalk.yellow('task-master generate')} to update task files\n` +
`1. Run ${chalk.yellow(`task-master show ${newTaskId}`)} to see complete task details` `${chalk.cyan('2.')} Run ${chalk.yellow('task-master expand --id=' + newTaskId)} to break it down into subtasks\n` +
) + `${chalk.cyan('3.')} Run ${chalk.yellow('task-master list --with-subtasks')} to see all tasks`,
'\n' + {
chalk.cyan( padding: 1,
`2. Run ${chalk.yellow(`task-master set-status --id=${newTaskId} --status=in-progress`)} to start working on it` borderColor: 'cyan',
) + borderStyle: 'round',
'\n' + margin: { top: 1 }
chalk.cyan( }
`3. Run ${chalk.yellow(`task-master expand --id=${newTaskId}`)} to break it down into subtasks`
),
{ padding: 1, borderColor: 'green', borderStyle: 'round' }
) )
); );
} }
// Return the new task ID
return newTaskId; return newTaskId;
} catch (error) { } catch (error) {
// Stop any loading indicator // Log the specific error during generation/processing
if (outputFormat === 'text' && loadingIndicator) { log('error', 'Error generating or processing task:', error.message);
stopLoadingIndicator(loadingIndicator); // Re-throw the error to be caught by the outer catch block
}
log('error', `Error adding task: ${error.message}`);
if (outputFormat === 'text') {
console.error(chalk.red(`Error: ${error.message}`));
}
throw error; throw error;
} finally {
// **** THIS IS THE KEY CHANGE ****
// Ensure the loading indicator is stopped if it was started
if (loadingIndicator) {
stopLoadingIndicator(loadingIndicator);
// Optional: Clear the line in CLI mode for a cleaner output
if (outputFormat === 'text' && process.stdout.isTTY) {
try {
// Use dynamic import for readline as it might not always be needed
const readline = await import('readline');
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
} catch (readlineError) {
log(
'debug',
'Could not clear readline for indicator cleanup:',
readlineError.message
);
}
}
loadingIndicator = null; // Reset indicator variable
}
}
} catch (error) {
// General error handling for the whole function
// The finally block above already handled the indicator if it was started
log('error', 'Error adding task:', error.message);
throw error; // Throw error instead of exiting the process
} }
} }
@@ -5663,8 +5609,6 @@ async function getSubtasksFromAI(
mcpLog.info('Calling AI to generate subtasks'); mcpLog.info('Calling AI to generate subtasks');
} }
let responseText;
// Call the AI - with research if requested // Call the AI - with research if requested
if (useResearch && perplexity) { if (useResearch && perplexity) {
if (mcpLog) { if (mcpLog) {
@@ -5689,7 +5633,8 @@ async function getSubtasksFromAI(
max_tokens: session?.env?.MAX_TOKENS || CONFIG.maxTokens max_tokens: session?.env?.MAX_TOKENS || CONFIG.maxTokens
}); });
responseText = result.choices[0].message.content; const responseText = result.choices[0].message.content;
return parseSubtasksFromText(responseText);
} else { } else {
// Use regular Claude // Use regular Claude
if (mcpLog) { if (mcpLog) {
@@ -5697,46 +5642,14 @@ async function getSubtasksFromAI(
} }
// Call the streaming API // Call the streaming API
responseText = await _handleAnthropicStream( const responseText = await _handleAnthropicStream(
client, client,
apiParams, apiParams,
{ mcpLog, silentMode: isSilentMode() }, { mcpLog, silentMode: isSilentMode() },
!isSilentMode() !isSilentMode()
); );
}
// Ensure we have a valid response return parseSubtasksFromText(responseText);
if (!responseText) {
throw new Error('Empty response from AI');
}
// Try to parse the subtasks
try {
const parsedSubtasks = parseSubtasksFromText(responseText);
if (
!parsedSubtasks ||
!Array.isArray(parsedSubtasks) ||
parsedSubtasks.length === 0
) {
throw new Error(
'Failed to parse valid subtasks array from AI response'
);
}
return { subtasks: parsedSubtasks };
} catch (parseError) {
if (mcpLog) {
mcpLog.error(`Error parsing subtasks: ${parseError.message}`);
mcpLog.error(`Response start: ${responseText.substring(0, 200)}...`);
} else {
log('error', `Error parsing subtasks: ${parseError.message}`);
}
// Return error information instead of fallback subtasks
return {
error: parseError.message,
taskId: null, // This will be filled in by the calling function
suggestion:
'Use \'task-master update-task --id=<id> --prompt="Generate subtasks for this task"\' to manually create subtasks.'
};
} }
} catch (error) { } catch (error) {
if (mcpLog) { if (mcpLog) {
@@ -5744,13 +5657,7 @@ async function getSubtasksFromAI(
} else { } else {
log('error', `Error generating subtasks: ${error.message}`); log('error', `Error generating subtasks: ${error.message}`);
} }
// Return error information instead of fallback subtasks throw error;
return {
error: error.message,
taskId: null, // This will be filled in by the calling function
suggestion:
'Use \'task-master update-task --id=<id> --prompt="Generate subtasks for this task"\' to manually create subtasks.'
};
} }
} }

View File

@@ -7,9 +7,6 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import chalk from 'chalk'; import chalk from 'chalk';
// Global silent mode flag
let silentMode = false;
// Configuration and constants // Configuration and constants
const CONFIG = { const CONFIG = {
model: process.env.MODEL || 'claude-3-7-sonnet-20250219', model: process.env.MODEL || 'claude-3-7-sonnet-20250219',
@@ -23,6 +20,9 @@ const CONFIG = {
projectVersion: '1.5.0' // Hardcoded version - ALWAYS use this value, ignore environment variable projectVersion: '1.5.0' // Hardcoded version - ALWAYS use this value, ignore environment variable
}; };
// Global silent mode flag
let silentMode = false;
// Set up logging based on log level // Set up logging based on log level
const LOG_LEVELS = { const LOG_LEVELS = {
debug: 0, debug: 0,
@@ -32,14 +32,6 @@ const LOG_LEVELS = {
success: 1 // Treat success like info level success: 1 // Treat success like info level
}; };
/**
* Returns the task manager module
* @returns {Promise<Object>} The task manager module object
*/
async function getTaskManager() {
return import('./task-manager.js');
}
/** /**
* Enable silent logging mode * Enable silent logging mode
*/ */
@@ -69,7 +61,7 @@ function isSilentMode() {
*/ */
function log(level, ...args) { function log(level, ...args) {
// Immediately return if silentMode is enabled // Immediately return if silentMode is enabled
if (isSilentMode()) { if (silentMode) {
return; return;
} }
@@ -416,6 +408,5 @@ export {
detectCamelCaseFlags, detectCamelCaseFlags,
enableSilentMode, enableSilentMode,
disableSilentMode, disableSilentMode,
isSilentMode, isSilentMode
getTaskManager
}; };

View File

@@ -1,32 +0,0 @@
# Task ID: 56
# Title: Refactor Task-Master Files into Node Module Structure
# Status: pending
# Dependencies: None
# Priority: medium
# Description: Restructure the task-master files by moving them from the project root into a proper node module structure to improve organization and maintainability.
# Details:
This task involves a significant refactoring of the task-master system to follow better Node.js module practices. Currently, task-master files are located in the project root, which creates clutter and doesn't follow best practices for Node.js applications. The refactoring should:
1. Create a dedicated directory structure within node_modules or as a local package
2. Update all import/require paths throughout the codebase to reference the new module location
3. Reorganize the files into a logical structure (lib/, utils/, commands/, etc.)
4. Ensure the module has a proper package.json with dependencies and exports
5. Update any build processes, scripts, or configuration files to reflect the new structure
6. Maintain backward compatibility where possible to minimize disruption
7. Document the new structure and any changes to usage patterns
This is a high-risk refactoring as it touches many parts of the system, so it should be approached methodically with frequent testing. Consider using a feature branch and implementing the changes incrementally rather than all at once.
# Test Strategy:
Testing for this refactoring should be comprehensive to ensure nothing breaks during the restructuring:
1. Create a complete inventory of existing functionality through automated tests before starting
2. Implement unit tests for each module to verify they function correctly in the new structure
3. Create integration tests that verify the interactions between modules work as expected
4. Test all CLI commands to ensure they continue to function with the new module structure
5. Verify that all import/require statements resolve correctly
6. Test on different environments (development, staging) to ensure compatibility
7. Perform regression testing on all features that depend on task-master functionality
8. Create a rollback plan and test it to ensure we can revert changes if critical issues arise
9. Conduct performance testing to ensure the refactoring doesn't introduce overhead
10. Have multiple developers test the changes on their local environments before merging

View File

@@ -1,67 +0,0 @@
# Task ID: 57
# Title: Enhance Task-Master CLI User Experience and Interface
# Status: pending
# Dependencies: None
# Priority: medium
# Description: Improve the Task-Master CLI's user experience by refining the interface, reducing verbose logging, and adding visual polish to create a more professional and intuitive tool.
# Details:
The current Task-Master CLI interface is functional but lacks polish and produces excessive log output. This task involves several key improvements:
1. Log Management:
- Implement log levels (ERROR, WARN, INFO, DEBUG, TRACE)
- Only show INFO and above by default
- Add a --verbose flag to show all logs
- Create a dedicated log file for detailed logs
2. Visual Enhancements:
- Add a clean, branded header when the tool starts
- Implement color-coding for different types of messages (success in green, errors in red, etc.)
- Use spinners or progress indicators for operations that take time
- Add clear visual separation between command input and output
3. Interactive Elements:
- Add loading animations for longer operations
- Implement interactive prompts for complex inputs instead of requiring all parameters upfront
- Add confirmation dialogs for destructive operations
4. Output Formatting:
- Format task listings in tables with consistent spacing
- Implement a compact mode and a detailed mode for viewing tasks
- Add visual indicators for task status (icons or colors)
5. Help and Documentation:
- Enhance help text with examples and clearer descriptions
- Add contextual hints for common next steps after commands
Use libraries like chalk, ora, inquirer, and boxen to implement these improvements. Ensure the interface remains functional in CI/CD environments where interactive elements might not be supported.
# Test Strategy:
Testing should verify both functionality and user experience improvements:
1. Automated Tests:
- Create unit tests for log level filtering functionality
- Test that all commands still function correctly with the new UI
- Verify that non-interactive mode works in CI environments
- Test that verbose and quiet modes function as expected
2. User Experience Testing:
- Create a test script that runs through common user flows
- Capture before/after screenshots for visual comparison
- Measure and compare the number of lines output for common operations
3. Usability Testing:
- Have 3-5 team members perform specific tasks using the new interface
- Collect feedback on clarity, ease of use, and visual appeal
- Identify any confusion points or areas for improvement
4. Edge Case Testing:
- Test in terminals with different color schemes and sizes
- Verify functionality in environments without color support
- Test with very large task lists to ensure formatting remains clean
Acceptance Criteria:
- Log output is reduced by at least 50% in normal operation
- All commands provide clear visual feedback about their progress and completion
- Help text is comprehensive and includes examples
- Interface is visually consistent across all commands
- Tool remains fully functional in non-interactive environments

View File

@@ -1,63 +0,0 @@
# Task ID: 58
# Title: Implement Elegant Package Update Mechanism for Task-Master
# Status: pending
# Dependencies: None
# Priority: medium
# Description: Create a robust update mechanism that handles package updates gracefully, ensuring all necessary files are updated when the global package is upgraded.
# Details:
Develop a comprehensive update system with these components:
1. **Update Detection**: When task-master runs, check if the current version matches the installed version. If not, notify the user an update is available.
2. **Update Command**: Implement a dedicated `task-master update` command that:
- Updates the global package (`npm -g task-master-ai@latest`)
- Automatically runs necessary initialization steps
- Preserves user configurations while updating system files
3. **Smart File Management**:
- Create a manifest of core files with checksums
- During updates, compare existing files with the manifest
- Only overwrite files that have changed in the update
- Preserve user-modified files with an option to merge changes
4. **Configuration Versioning**:
- Add version tracking to configuration files
- Implement migration paths for configuration changes between versions
- Provide backward compatibility for older configurations
5. **Update Notifications**:
- Add a non-intrusive notification when updates are available
- Include a changelog summary of what's new
This system should work seamlessly with the existing `task-master init` command but provide a more automated and user-friendly update experience.
# Test Strategy:
Test the update mechanism with these specific scenarios:
1. **Version Detection Test**:
- Install an older version, then verify the system correctly detects when a newer version is available
- Test with minor and major version changes
2. **Update Command Test**:
- Verify `task-master update` successfully updates the global package
- Confirm all necessary files are updated correctly
- Test with and without user-modified files present
3. **File Preservation Test**:
- Modify configuration files, then update
- Verify user changes are preserved while system files are updated
- Test with conflicts between user changes and system updates
4. **Rollback Test**:
- Implement and test a rollback mechanism if updates fail
- Verify system returns to previous working state
5. **Integration Test**:
- Create a test project with the current version
- Run through the update process
- Verify all functionality continues to work after update
6. **Edge Case Tests**:
- Test updating with insufficient permissions
- Test updating with network interruptions
- Test updating from very old versions to latest

View File

@@ -1,30 +0,0 @@
# Task ID: 59
# Title: Remove Manual Package.json Modifications and Implement Automatic Dependency Management
# Status: pending
# Dependencies: None
# Priority: medium
# Description: Eliminate code that manually modifies users' package.json files and implement proper npm dependency management that automatically handles package requirements when users install task-master-ai.
# Details:
Currently, the application is attempting to manually modify users' package.json files, which is not the recommended approach for npm packages. Instead:
1. Review all code that directly manipulates package.json files in users' projects
2. Remove these manual modifications
3. Properly define all dependencies in the package.json of task-master-ai itself
4. Ensure all peer dependencies are correctly specified
5. For any scripts that need to be available to users, use proper npm bin linking or npx commands
6. Update the installation process to leverage npm's built-in dependency management
7. If configuration is needed in users' projects, implement a proper initialization command that creates config files rather than modifying package.json
8. Document the new approach in the README and any other relevant documentation
This change will make the package more reliable, follow npm best practices, and prevent potential conflicts or errors when modifying users' project files.
# Test Strategy:
1. Create a fresh test project directory
2. Install the updated task-master-ai package using npm install task-master-ai
3. Verify that no code attempts to modify the test project's package.json
4. Confirm all dependencies are properly installed in node_modules
5. Test all commands to ensure they work without the previous manual package.json modifications
6. Try installing in projects with various existing configurations to ensure no conflicts occur
7. Test the uninstall process to verify it cleanly removes the package without leaving unwanted modifications
8. Verify the package works in different npm environments (npm 6, 7, 8) and with different Node.js versions
9. Create an integration test that simulates a real user workflow from installation through usage

View File

@@ -1,73 +0,0 @@
# Task ID: 60
# Title: Implement Mentor System with Round-Table Discussion Feature
# Status: pending
# Dependencies: None
# Priority: medium
# Description: Create a mentor system that allows users to add simulated mentors to their projects and facilitate round-table discussions between these mentors to gain diverse perspectives and insights on tasks.
# Details:
Implement a comprehensive mentor system with the following features:
1. **Mentor Management**:
- Create a `mentors.json` file to store mentor data including name, personality, expertise, and other relevant attributes
- Implement `add-mentor` command that accepts a name and prompt describing the mentor's characteristics
- Implement `remove-mentor` command to delete mentors from the system
- Implement `list-mentors` command to display all configured mentors and their details
- Set a recommended maximum of 5 mentors with appropriate warnings
2. **Round-Table Discussion**:
- Create a `round-table` command with the following parameters:
- `--prompt`: Optional text prompt to guide the discussion
- `--id`: Optional task/subtask ID(s) to provide context (support comma-separated values)
- `--turns`: Number of discussion rounds (each mentor speaks once per turn)
- `--output`: Optional flag to export results to a file
- Implement an interactive CLI experience using inquirer for the round-table
- Generate a simulated discussion where each mentor speaks in turn based on their personality
- After all turns complete, generate insights, recommendations, and a summary
- Display results in the CLI
- When `--output` is specified, create a `round-table.txt` file containing:
- Initial prompt
- Target task ID(s)
- Full round-table discussion transcript
- Recommendations and insights section
3. **Integration with Task System**:
- Enhance `update`, `update-task`, and `update-subtask` commands to accept a round-table.txt file
- Use the round-table output as input for updating tasks or subtasks
- Allow appending round-table insights to subtasks
4. **LLM Integration**:
- Configure the system to effectively simulate different personalities using LLM
- Ensure mentors maintain consistent personalities across different round-tables
- Implement proper context handling to ensure relevant task information is included
Ensure all commands have proper help text and error handling for cases like no mentors configured, invalid task IDs, etc.
# Test Strategy:
1. **Unit Tests**:
- Test mentor data structure creation and validation
- Test mentor addition with various input formats
- Test mentor removal functionality
- Test listing of mentors with different configurations
- Test round-table parameter parsing and validation
2. **Integration Tests**:
- Test the complete flow of adding mentors and running a round-table
- Test round-table with different numbers of turns
- Test round-table with task context vs. custom prompt
- Test output file generation and format
- Test using round-table output to update tasks and subtasks
3. **Edge Cases**:
- Test behavior when no mentors are configured but round-table is called
- Test with invalid task IDs in the --id parameter
- Test with extremely long discussions (many turns)
- Test with mentors that have similar personalities
- Test removing a mentor that doesn't exist
- Test adding more than the recommended 5 mentors
4. **Manual Testing Scenarios**:
- Create mentors with distinct personalities (e.g., Vitalik Buterin, Steve Jobs, etc.)
- Run a round-table on a complex task and verify the insights are helpful
- Verify the personality simulation is consistent and believable
- Test the round-table output file readability and usefulness
- Verify that using round-table output to update tasks produces meaningful improvements

View File

@@ -2726,16 +2726,6 @@
"priority": "medium", "priority": "medium",
"details": "Currently, the application is attempting to manually modify users' package.json files, which is not the recommended approach for npm packages. Instead:\n\n1. Review all code that directly manipulates package.json files in users' projects\n2. Remove these manual modifications\n3. Properly define all dependencies in the package.json of task-master-ai itself\n4. Ensure all peer dependencies are correctly specified\n5. For any scripts that need to be available to users, use proper npm bin linking or npx commands\n6. Update the installation process to leverage npm's built-in dependency management\n7. If configuration is needed in users' projects, implement a proper initialization command that creates config files rather than modifying package.json\n8. Document the new approach in the README and any other relevant documentation\n\nThis change will make the package more reliable, follow npm best practices, and prevent potential conflicts or errors when modifying users' project files.", "details": "Currently, the application is attempting to manually modify users' package.json files, which is not the recommended approach for npm packages. Instead:\n\n1. Review all code that directly manipulates package.json files in users' projects\n2. Remove these manual modifications\n3. Properly define all dependencies in the package.json of task-master-ai itself\n4. Ensure all peer dependencies are correctly specified\n5. For any scripts that need to be available to users, use proper npm bin linking or npx commands\n6. Update the installation process to leverage npm's built-in dependency management\n7. If configuration is needed in users' projects, implement a proper initialization command that creates config files rather than modifying package.json\n8. Document the new approach in the README and any other relevant documentation\n\nThis change will make the package more reliable, follow npm best practices, and prevent potential conflicts or errors when modifying users' project files.",
"testStrategy": "1. Create a fresh test project directory\n2. Install the updated task-master-ai package using npm install task-master-ai\n3. Verify that no code attempts to modify the test project's package.json\n4. Confirm all dependencies are properly installed in node_modules\n5. Test all commands to ensure they work without the previous manual package.json modifications\n6. Try installing in projects with various existing configurations to ensure no conflicts occur\n7. Test the uninstall process to verify it cleanly removes the package without leaving unwanted modifications\n8. Verify the package works in different npm environments (npm 6, 7, 8) and with different Node.js versions\n9. Create an integration test that simulates a real user workflow from installation through usage" "testStrategy": "1. Create a fresh test project directory\n2. Install the updated task-master-ai package using npm install task-master-ai\n3. Verify that no code attempts to modify the test project's package.json\n4. Confirm all dependencies are properly installed in node_modules\n5. Test all commands to ensure they work without the previous manual package.json modifications\n6. Try installing in projects with various existing configurations to ensure no conflicts occur\n7. Test the uninstall process to verify it cleanly removes the package without leaving unwanted modifications\n8. Verify the package works in different npm environments (npm 6, 7, 8) and with different Node.js versions\n9. Create an integration test that simulates a real user workflow from installation through usage"
},
{
"id": 60,
"title": "Implement Mentor System with Round-Table Discussion Feature",
"description": "Create a mentor system that allows users to add simulated mentors to their projects and facilitate round-table discussions between these mentors to gain diverse perspectives and insights on tasks.",
"details": "Implement a comprehensive mentor system with the following features:\n\n1. **Mentor Management**:\n - Create a `mentors.json` file to store mentor data including name, personality, expertise, and other relevant attributes\n - Implement `add-mentor` command that accepts a name and prompt describing the mentor's characteristics\n - Implement `remove-mentor` command to delete mentors from the system\n - Implement `list-mentors` command to display all configured mentors and their details\n - Set a recommended maximum of 5 mentors with appropriate warnings\n\n2. **Round-Table Discussion**:\n - Create a `round-table` command with the following parameters:\n - `--prompt`: Optional text prompt to guide the discussion\n - `--id`: Optional task/subtask ID(s) to provide context (support comma-separated values)\n - `--turns`: Number of discussion rounds (each mentor speaks once per turn)\n - `--output`: Optional flag to export results to a file\n - Implement an interactive CLI experience using inquirer for the round-table\n - Generate a simulated discussion where each mentor speaks in turn based on their personality\n - After all turns complete, generate insights, recommendations, and a summary\n - Display results in the CLI\n - When `--output` is specified, create a `round-table.txt` file containing:\n - Initial prompt\n - Target task ID(s)\n - Full round-table discussion transcript\n - Recommendations and insights section\n\n3. **Integration with Task System**:\n - Enhance `update`, `update-task`, and `update-subtask` commands to accept a round-table.txt file\n - Use the round-table output as input for updating tasks or subtasks\n - Allow appending round-table insights to subtasks\n\n4. **LLM Integration**:\n - Configure the system to effectively simulate different personalities using LLM\n - Ensure mentors maintain consistent personalities across different round-tables\n - Implement proper context handling to ensure relevant task information is included\n\nEnsure all commands have proper help text and error handling for cases like no mentors configured, invalid task IDs, etc.",
"testStrategy": "1. **Unit Tests**:\n - Test mentor data structure creation and validation\n - Test mentor addition with various input formats\n - Test mentor removal functionality\n - Test listing of mentors with different configurations\n - Test round-table parameter parsing and validation\n\n2. **Integration Tests**:\n - Test the complete flow of adding mentors and running a round-table\n - Test round-table with different numbers of turns\n - Test round-table with task context vs. custom prompt\n - Test output file generation and format\n - Test using round-table output to update tasks and subtasks\n\n3. **Edge Cases**:\n - Test behavior when no mentors are configured but round-table is called\n - Test with invalid task IDs in the --id parameter\n - Test with extremely long discussions (many turns)\n - Test with mentors that have similar personalities\n - Test removing a mentor that doesn't exist\n - Test adding more than the recommended 5 mentors\n\n4. **Manual Testing Scenarios**:\n - Create mentors with distinct personalities (e.g., Vitalik Buterin, Steve Jobs, etc.)\n - Run a round-table on a complex task and verify the insights are helpful\n - Verify the personality simulation is consistent and believable\n - Test the round-table output file readability and usefulness\n - Verify that using round-table output to update tasks produces meaningful improvements",
"status": "pending",
"dependencies": [],
"priority": "medium"
} }
] ]
} }

View File

@@ -131,7 +131,7 @@ jest.mock('../../../scripts/modules/utils.js', () => ({
enableSilentMode: mockEnableSilentMode, enableSilentMode: mockEnableSilentMode,
disableSilentMode: mockDisableSilentMode, disableSilentMode: mockDisableSilentMode,
CONFIG: { CONFIG: {
model: 'claude-3-7-sonnet-20250219', model: 'claude-3-sonnet-20240229',
maxTokens: 64000, maxTokens: 64000,
temperature: 0.2, temperature: 0.2,
defaultSubtasks: 5 defaultSubtasks: 5

View File

@@ -7,16 +7,13 @@
// Mock environment variables // Mock environment variables
process.env.MODEL = 'sonar-pro'; process.env.MODEL = 'sonar-pro';
process.env.MAX_TOKENS = '64000'; process.env.MAX_TOKENS = '64000';
process.env.TEMPERATURE = '0.2'; process.env.TEMPERATURE = '0.4';
process.env.DEBUG = 'false'; process.env.DEBUG = 'false';
process.env.LOG_LEVEL = 'error'; // Set to error to reduce noise in tests process.env.LOG_LEVEL = 'error'; // Set to error to reduce noise in tests
process.env.DEFAULT_SUBTASKS = '5'; process.env.DEFAULT_SUBTASKS = '3';
process.env.DEFAULT_PRIORITY = 'medium'; process.env.DEFAULT_PRIORITY = 'medium';
process.env.PROJECT_NAME = 'Test Project'; process.env.PROJECT_NAME = 'Test Project';
process.env.PROJECT_VERSION = '1.0.0'; process.env.PROJECT_VERSION = '1.0.0';
// Ensure tests don't make real API calls by setting mock API keys
process.env.ANTHROPIC_API_KEY = 'test-mock-api-key-for-tests';
process.env.PERPLEXITY_API_KEY = 'test-mock-perplexity-key-for-tests';
// Add global test helpers if needed // Add global test helpers if needed
global.wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); global.wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

View File

@@ -196,12 +196,29 @@ These subtasks will help you implement the parent task efficiently.`;
expect(result[2].dependencies).toEqual([1, 2]); expect(result[2].dependencies).toEqual([1, 2]);
}); });
test('should throw an error for empty text', () => { test('should create fallback subtasks for empty text', () => {
const emptyText = ''; const emptyText = '';
expect(() => parseSubtasksFromText(emptyText, 1, 2, 5)).toThrow( const result = parseSubtasksFromText(emptyText, 1, 2, 5);
'Empty text provided, cannot parse subtasks'
); // Verify fallback subtasks structure
expect(result).toHaveLength(2);
expect(result[0]).toMatchObject({
id: 1,
title: 'Subtask 1',
description: 'Auto-generated fallback subtask',
status: 'pending',
dependencies: [],
parentTaskId: 5
});
expect(result[1]).toMatchObject({
id: 2,
title: 'Subtask 2',
description: 'Auto-generated fallback subtask',
status: 'pending',
dependencies: [],
parentTaskId: 5
});
}); });
test('should normalize subtask IDs', () => { test('should normalize subtask IDs', () => {
@@ -255,12 +272,29 @@ These subtasks will help you implement the parent task efficiently.`;
expect(typeof result[1].dependencies[0]).toBe('number'); expect(typeof result[1].dependencies[0]).toBe('number');
}); });
test('should throw an error for invalid JSON', () => { test('should create fallback subtasks for invalid JSON', () => {
const text = `This is not valid JSON and cannot be parsed`; const text = `This is not valid JSON and cannot be parsed`;
expect(() => parseSubtasksFromText(text, 1, 2, 5)).toThrow( const result = parseSubtasksFromText(text, 1, 2, 5);
'Could not locate valid JSON array in the response'
); // Verify fallback subtasks structure
expect(result).toHaveLength(2);
expect(result[0]).toMatchObject({
id: 1,
title: 'Subtask 1',
description: 'Auto-generated fallback subtask',
status: 'pending',
dependencies: [],
parentTaskId: 5
});
expect(result[1]).toMatchObject({
id: 2,
title: 'Subtask 2',
description: 'Auto-generated fallback subtask',
status: 'pending',
dependencies: [],
parentTaskId: 5
});
}); });
}); });

View File

@@ -3,10 +3,6 @@
*/ */
import { jest } from '@jest/globals'; import { jest } from '@jest/globals';
import {
sampleTasks,
emptySampleTasks
} from '../../tests/fixtures/sample-tasks.js';
// Mock functions that need jest.fn methods // Mock functions that need jest.fn methods
const mockParsePRD = jest.fn().mockResolvedValue(undefined); const mockParsePRD = jest.fn().mockResolvedValue(undefined);
@@ -643,240 +639,6 @@ describe('Commands Module', () => {
expect(mockExit).toHaveBeenCalledWith(1); expect(mockExit).toHaveBeenCalledWith(1);
}); });
}); });
// Add test for add-task command
describe('add-task command', () => {
let mockTaskManager;
let addTaskCommand;
let addTaskAction;
let mockFs;
// Import the sample tasks fixtures
beforeEach(async () => {
// Mock fs module to return sample tasks
mockFs = {
existsSync: jest.fn().mockReturnValue(true),
readFileSync: jest.fn().mockReturnValue(JSON.stringify(sampleTasks))
};
// Create a mock task manager with an addTask function that resolves to taskId 5
mockTaskManager = {
addTask: jest
.fn()
.mockImplementation(
(
file,
prompt,
dependencies,
priority,
session,
research,
generateFiles,
manualTaskData
) => {
// Return the next ID after the last one in sample tasks
const newId = sampleTasks.tasks.length + 1;
return Promise.resolve(newId.toString());
}
)
};
// Create a simplified version of the add-task action function for testing
addTaskAction = async (cmd, options) => {
options = options || {}; // Ensure options is not undefined
const isManualCreation = options.title && options.description;
// Get prompt directly or from p shorthand
const prompt = options.prompt || options.p;
// Validate that either prompt or title+description are provided
if (!prompt && !isManualCreation) {
throw new Error(
'Either --prompt or both --title and --description must be provided'
);
}
// Prepare dependencies if provided
let dependencies = [];
if (options.dependencies) {
dependencies = options.dependencies.split(',').map((id) => id.trim());
}
// Create manual task data if title and description are provided
let manualTaskData = null;
if (isManualCreation) {
manualTaskData = {
title: options.title,
description: options.description,
details: options.details || '',
testStrategy: options.testStrategy || ''
};
}
// Call addTask with the right parameters
return await mockTaskManager.addTask(
options.file || 'tasks/tasks.json',
prompt,
dependencies,
options.priority || 'medium',
{ session: process.env },
options.research || options.r || false,
null,
manualTaskData
);
};
});
test('should throw error if no prompt or manual task data provided', async () => {
// Call without required params
const options = { file: 'tasks/tasks.json' };
await expect(async () => {
await addTaskAction(undefined, options);
}).rejects.toThrow(
'Either --prompt or both --title and --description must be provided'
);
});
test('should handle short-hand flag -p for prompt', async () => {
// Use -p as prompt short-hand
const options = {
p: 'Create a login component',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct arguments
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String), // File path
'Create a login component', // Prompt
[], // Dependencies
'medium', // Default priority
{ session: process.env },
false, // Research flag
null, // Generate files parameter
null // Manual task data
);
});
test('should handle short-hand flag -r for research', async () => {
const options = {
prompt: 'Create authentication system',
r: true,
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct research flag
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String),
'Create authentication system',
[],
'medium',
{ session: process.env },
true, // Research flag should be true
null, // Generate files parameter
null // Manual task data
);
});
test('should handle manual task creation with title and description', async () => {
const options = {
title: 'Login Component',
description: 'Create a reusable login form',
details: 'Implementation details here',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct manual task data
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String),
undefined, // No prompt for manual creation
[],
'medium',
{ session: process.env },
false,
null, // Generate files parameter
{
// Manual task data
title: 'Login Component',
description: 'Create a reusable login form',
details: 'Implementation details here',
testStrategy: ''
}
);
});
test('should handle dependencies parameter', async () => {
const options = {
prompt: 'Create user settings page',
dependencies: '1, 3, 5', // Dependencies with spaces
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that dependencies are parsed correctly
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String),
'Create user settings page',
['1', '3', '5'], // Should trim whitespace from dependencies
'medium',
{ session: process.env },
false,
null, // Generate files parameter
null // Manual task data
);
});
test('should handle priority parameter', async () => {
const options = {
prompt: 'Create navigation menu',
priority: 'high',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that priority is passed correctly
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String),
'Create navigation menu',
[],
'high', // Should use the provided priority
{ session: process.env },
false,
null, // Generate files parameter
null // Manual task data
);
});
test('should use default values for optional parameters', async () => {
const options = {
prompt: 'Basic task',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that default values are used
expect(mockTaskManager.addTask).toHaveBeenCalledWith(
expect.any(String),
'Basic task',
[], // Empty dependencies array by default
'medium', // Default priority is medium
{ session: process.env },
false, // Research is false by default
null, // Generate files parameter
null // Manual task data
);
});
});
}); });
// Test the version comparison utility // Test the version comparison utility

View File

@@ -1,345 +0,0 @@
/**
* Tests for the add-task MCP tool
*
* Note: This test does NOT test the actual implementation. It tests that:
* 1. The tool is registered correctly with the correct parameters
* 2. Arguments are passed correctly to addTaskDirect
* 3. Error handling works as expected
*
* We do NOT import the real implementation - everything is mocked
*/
import { jest } from '@jest/globals';
import {
sampleTasks,
emptySampleTasks
} from '../../../fixtures/sample-tasks.js';
// Mock EVERYTHING
const mockAddTaskDirect = jest.fn();
jest.mock('../../../../mcp-server/src/core/task-master-core.js', () => ({
addTaskDirect: mockAddTaskDirect
}));
const mockHandleApiResult = jest.fn((result) => result);
const mockGetProjectRootFromSession = jest.fn(() => '/mock/project/root');
const mockCreateErrorResponse = jest.fn((msg) => ({
success: false,
error: { code: 'ERROR', message: msg }
}));
jest.mock('../../../../mcp-server/src/tools/utils.js', () => ({
getProjectRootFromSession: mockGetProjectRootFromSession,
handleApiResult: mockHandleApiResult,
createErrorResponse: mockCreateErrorResponse,
createContentResponse: jest.fn((content) => ({
success: true,
data: content
})),
executeTaskMasterCommand: jest.fn()
}));
// Mock the z object from zod
const mockZod = {
object: jest.fn(() => mockZod),
string: jest.fn(() => mockZod),
boolean: jest.fn(() => mockZod),
optional: jest.fn(() => mockZod),
describe: jest.fn(() => mockZod),
_def: {
shape: () => ({
prompt: {},
dependencies: {},
priority: {},
research: {},
file: {},
projectRoot: {}
})
}
};
jest.mock('zod', () => ({
z: mockZod
}));
// DO NOT import the real module - create a fake implementation
// This is the fake implementation of registerAddTaskTool
const registerAddTaskTool = (server) => {
// Create simplified version of the tool config
const toolConfig = {
name: 'add_task',
description: 'Add a new task using AI',
parameters: mockZod,
// Create a simplified mock of the execute function
execute: (args, context) => {
const { log, reportProgress, session } = context;
try {
log.info &&
log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
// Get project root
const rootFolder = mockGetProjectRootFromSession(session, log);
// Call addTaskDirect
const result = mockAddTaskDirect(
{
...args,
projectRoot: rootFolder
},
log,
{ reportProgress, session }
);
// Handle result
return mockHandleApiResult(result, log);
} catch (error) {
log.error && log.error(`Error in add-task tool: ${error.message}`);
return mockCreateErrorResponse(error.message);
}
}
};
// Register the tool with the server
server.addTool(toolConfig);
};
describe('MCP Tool: add-task', () => {
// Create mock server
let mockServer;
let executeFunction;
// Create mock logger
const mockLogger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn()
};
// Test data
const validArgs = {
prompt: 'Create a new task',
dependencies: '1,2',
priority: 'high',
research: true
};
// Standard responses
const successResponse = {
success: true,
data: {
taskId: '5',
message: 'Successfully added new task #5'
}
};
const errorResponse = {
success: false,
error: {
code: 'ADD_TASK_ERROR',
message: 'Failed to add task'
}
};
beforeEach(() => {
// Reset all mocks
jest.clearAllMocks();
// Create mock server
mockServer = {
addTool: jest.fn((config) => {
executeFunction = config.execute;
})
};
// Setup default successful response
mockAddTaskDirect.mockReturnValue(successResponse);
// Register the tool
registerAddTaskTool(mockServer);
});
test('should register the tool correctly', () => {
// Verify tool was registered
expect(mockServer.addTool).toHaveBeenCalledWith(
expect.objectContaining({
name: 'add_task',
description: 'Add a new task using AI',
parameters: expect.any(Object),
execute: expect.any(Function)
})
);
// Verify the tool config was passed
const toolConfig = mockServer.addTool.mock.calls[0][0];
expect(toolConfig).toHaveProperty('parameters');
expect(toolConfig).toHaveProperty('execute');
});
test('should execute the tool with valid parameters', () => {
// Setup context
const mockContext = {
log: mockLogger,
reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' }
};
// Execute the function
executeFunction(validArgs, mockContext);
// Verify getProjectRootFromSession was called
expect(mockGetProjectRootFromSession).toHaveBeenCalledWith(
mockContext.session,
mockLogger
);
// Verify addTaskDirect was called with correct arguments
expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({
...validArgs,
projectRoot: '/mock/project/root'
}),
mockLogger,
{
reportProgress: mockContext.reportProgress,
session: mockContext.session
}
);
// Verify handleApiResult was called
expect(mockHandleApiResult).toHaveBeenCalledWith(
successResponse,
mockLogger
);
});
test('should handle errors from addTaskDirect', () => {
// Setup error response
mockAddTaskDirect.mockReturnValueOnce(errorResponse);
// Setup context
const mockContext = {
log: mockLogger,
reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' }
};
// Execute the function
executeFunction(validArgs, mockContext);
// Verify addTaskDirect was called
expect(mockAddTaskDirect).toHaveBeenCalled();
// Verify handleApiResult was called with error response
expect(mockHandleApiResult).toHaveBeenCalledWith(errorResponse, mockLogger);
});
test('should handle unexpected errors', () => {
// Setup error
const testError = new Error('Unexpected error');
mockAddTaskDirect.mockImplementationOnce(() => {
throw testError;
});
// Setup context
const mockContext = {
log: mockLogger,
reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' }
};
// Execute the function
executeFunction(validArgs, mockContext);
// Verify error was logged
expect(mockLogger.error).toHaveBeenCalledWith(
'Error in add-task tool: Unexpected error'
);
// Verify error response was created
expect(mockCreateErrorResponse).toHaveBeenCalledWith('Unexpected error');
});
test('should pass research parameter correctly', () => {
// Setup context
const mockContext = {
log: mockLogger,
reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' }
};
// Test with research=true
executeFunction(
{
...validArgs,
research: true
},
mockContext
);
// Verify addTaskDirect was called with research=true
expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({
research: true
}),
expect.any(Object),
expect.any(Object)
);
// Reset mocks
jest.clearAllMocks();
// Test with research=false
executeFunction(
{
...validArgs,
research: false
},
mockContext
);
// Verify addTaskDirect was called with research=false
expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({
research: false
}),
expect.any(Object),
expect.any(Object)
);
});
test('should pass priority parameter correctly', () => {
// Setup context
const mockContext = {
log: mockLogger,
reportProgress: jest.fn(),
session: { workingDirectory: '/mock/dir' }
};
// Test different priority values
['high', 'medium', 'low'].forEach((priority) => {
// Reset mocks
jest.clearAllMocks();
// Execute with specific priority
executeFunction(
{
...validArgs,
priority
},
mockContext
);
// Verify addTaskDirect was called with correct priority
expect(mockAddTaskDirect).toHaveBeenCalledWith(
expect.objectContaining({
priority
}),
expect.any(Object),
expect.any(Object)
);
});
});
});

View File

@@ -1,468 +0,0 @@
/**
* Tests for the analyze_project_complexity MCP tool
*
* Note: This test does NOT test the actual implementation. It tests that:
* 1. The tool is registered correctly with the correct parameters
* 2. Arguments are passed correctly to analyzeTaskComplexityDirect
* 3. The threshold parameter is properly validated
* 4. Error handling works as expected
*
* We do NOT import the real implementation - everything is mocked
*/
import { jest } from '@jest/globals';
// Mock EVERYTHING
const mockAnalyzeTaskComplexityDirect = jest.fn();
jest.mock('../../../../mcp-server/src/core/task-master-core.js', () => ({
analyzeTaskComplexityDirect: mockAnalyzeTaskComplexityDirect
}));
const mockHandleApiResult = jest.fn((result) => result);
const mockGetProjectRootFromSession = jest.fn(() => '/mock/project/root');
const mockCreateErrorResponse = jest.fn((msg) => ({
success: false,
error: { code: 'ERROR', message: msg }
}));
jest.mock('../../../../mcp-server/src/tools/utils.js', () => ({
getProjectRootFromSession: mockGetProjectRootFromSession,
handleApiResult: mockHandleApiResult,
createErrorResponse: mockCreateErrorResponse,
createContentResponse: jest.fn((content) => ({
success: true,
data: content
})),
executeTaskMasterCommand: jest.fn()
}));
// This is a more complex mock of Zod to test actual validation
const createZodMock = () => {
// Storage for validation rules
const validationRules = {
threshold: {
type: 'coerce.number',
min: 1,
max: 10,
optional: true
}
};
// Create validator functions
const validateThreshold = (value) => {
if (value === undefined && validationRules.threshold.optional) {
return true;
}
// Attempt to coerce to number (if string)
const numValue = typeof value === 'string' ? Number(value) : value;
// Check if it's a valid number
if (isNaN(numValue)) {
throw new Error(`Invalid type for parameter 'threshold'`);
}
// Check min/max constraints
if (numValue < validationRules.threshold.min) {
throw new Error(
`Threshold must be at least ${validationRules.threshold.min}`
);
}
if (numValue > validationRules.threshold.max) {
throw new Error(
`Threshold must be at most ${validationRules.threshold.max}`
);
}
return true;
};
// Create actual validators for parameters
const validators = {
threshold: validateThreshold
};
// Main validation function for the entire object
const validateObject = (obj) => {
// Validate each field
if (obj.threshold !== undefined) {
validators.threshold(obj.threshold);
}
// If we get here, all validations passed
return obj;
};
// Base object with chainable methods
const zodBase = {
optional: () => {
return zodBase;
},
describe: (desc) => {
return zodBase;
}
};
// Number-specific methods
const zodNumber = {
...zodBase,
min: (value) => {
return zodNumber;
},
max: (value) => {
return zodNumber;
}
};
// Main mock implementation
const mockZod = {
object: () => ({
...zodBase,
// This parse method will be called by the tool execution
parse: validateObject
}),
string: () => zodBase,
boolean: () => zodBase,
number: () => zodNumber,
coerce: {
number: () => zodNumber
},
union: (schemas) => zodBase,
_def: {
shape: () => ({
output: {},
model: {},
threshold: {},
file: {},
research: {},
projectRoot: {}
})
}
};
return mockZod;
};
// Create our Zod mock
const mockZod = createZodMock();
jest.mock('zod', () => ({
z: mockZod
}));
// DO NOT import the real module - create a fake implementation
// This is the fake implementation of registerAnalyzeTool
const registerAnalyzeTool = (server) => {
// Create simplified version of the tool config
const toolConfig = {
name: 'analyze_project_complexity',
description:
'Analyze task complexity and generate expansion recommendations',
parameters: mockZod.object(),
// Create a simplified mock of the execute function
execute: (args, context) => {
const { log, session } = context;
try {
log.info &&
log.info(
`Analyzing task complexity with args: ${JSON.stringify(args)}`
);
// Get project root
const rootFolder = mockGetProjectRootFromSession(session, log);
// Call analyzeTaskComplexityDirect
const result = mockAnalyzeTaskComplexityDirect(
{
...args,
projectRoot: rootFolder
},
log,
{ session }
);
// Handle result
return mockHandleApiResult(result, log);
} catch (error) {
log.error && log.error(`Error in analyze tool: ${error.message}`);
return mockCreateErrorResponse(error.message);
}
}
};
// Register the tool with the server
server.addTool(toolConfig);
};
describe('MCP Tool: analyze_project_complexity', () => {
// Create mock server
let mockServer;
let executeFunction;
// Create mock logger
const mockLogger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn()
};
// Test data
const validArgs = {
output: 'output/path/report.json',
model: 'claude-3-opus-20240229',
threshold: 5,
research: true
};
// Standard responses
const successResponse = {
success: true,
data: {
message: 'Task complexity analysis complete',
reportPath: '/mock/project/root/output/path/report.json',
reportSummary: {
taskCount: 10,
highComplexityTasks: 3,
mediumComplexityTasks: 5,
lowComplexityTasks: 2
}
}
};
const errorResponse = {
success: false,
error: {
code: 'ANALYZE_ERROR',
message: 'Failed to analyze task complexity'
}
};
beforeEach(() => {
// Reset all mocks
jest.clearAllMocks();
// Create mock server
mockServer = {
addTool: jest.fn((config) => {
executeFunction = config.execute;
})
};
// Setup default successful response
mockAnalyzeTaskComplexityDirect.mockReturnValue(successResponse);
// Register the tool
registerAnalyzeTool(mockServer);
});
test('should register the tool correctly', () => {
// Verify tool was registered
expect(mockServer.addTool).toHaveBeenCalledWith(
expect.objectContaining({
name: 'analyze_project_complexity',
description:
'Analyze task complexity and generate expansion recommendations',
parameters: expect.any(Object),
execute: expect.any(Function)
})
);
// Verify the tool config was passed
const toolConfig = mockServer.addTool.mock.calls[0][0];
expect(toolConfig).toHaveProperty('parameters');
expect(toolConfig).toHaveProperty('execute');
});
test('should execute the tool with valid threshold as number', () => {
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Test with valid numeric threshold
const args = { ...validArgs, threshold: 7 };
executeFunction(args, mockContext);
// Verify analyzeTaskComplexityDirect was called with correct arguments
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
threshold: 7,
projectRoot: '/mock/project/root'
}),
mockLogger,
{ session: mockContext.session }
);
// Verify handleApiResult was called
expect(mockHandleApiResult).toHaveBeenCalledWith(
successResponse,
mockLogger
);
});
test('should execute the tool with valid threshold as string', () => {
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Test with valid string threshold
const args = { ...validArgs, threshold: '7' };
executeFunction(args, mockContext);
// The mock doesn't actually coerce the string, just verify that the string is passed correctly
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
threshold: '7', // Expect string value, not coerced to number in our mock
projectRoot: '/mock/project/root'
}),
mockLogger,
{ session: mockContext.session }
);
});
test('should execute the tool with decimal threshold', () => {
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Test with decimal threshold
const args = { ...validArgs, threshold: 6.5 };
executeFunction(args, mockContext);
// Verify it was passed correctly
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
threshold: 6.5,
projectRoot: '/mock/project/root'
}),
mockLogger,
{ session: mockContext.session }
);
});
test('should execute the tool without threshold parameter', () => {
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Test without threshold (should use default)
const { threshold, ...argsWithoutThreshold } = validArgs;
executeFunction(argsWithoutThreshold, mockContext);
// Verify threshold is undefined
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
projectRoot: '/mock/project/root'
}),
mockLogger,
{ session: mockContext.session }
);
// Check threshold is not included
const callArgs = mockAnalyzeTaskComplexityDirect.mock.calls[0][0];
expect(callArgs).not.toHaveProperty('threshold');
});
test('should handle errors from analyzeTaskComplexityDirect', () => {
// Setup error response
mockAnalyzeTaskComplexityDirect.mockReturnValueOnce(errorResponse);
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Execute the function
executeFunction(validArgs, mockContext);
// Verify analyzeTaskComplexityDirect was called
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalled();
// Verify handleApiResult was called with error response
expect(mockHandleApiResult).toHaveBeenCalledWith(errorResponse, mockLogger);
});
test('should handle unexpected errors', () => {
// Setup error
const testError = new Error('Unexpected error');
mockAnalyzeTaskComplexityDirect.mockImplementationOnce(() => {
throw testError;
});
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Execute the function
executeFunction(validArgs, mockContext);
// Verify error was logged
expect(mockLogger.error).toHaveBeenCalledWith(
'Error in analyze tool: Unexpected error'
);
// Verify error response was created
expect(mockCreateErrorResponse).toHaveBeenCalledWith('Unexpected error');
});
test('should verify research parameter is correctly passed', () => {
// Setup context
const mockContext = {
log: mockLogger,
session: { workingDirectory: '/mock/dir' }
};
// Test with research=true
executeFunction(
{
...validArgs,
research: true
},
mockContext
);
// Verify analyzeTaskComplexityDirect was called with research=true
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
research: true
}),
expect.any(Object),
expect.any(Object)
);
// Reset mocks
jest.clearAllMocks();
// Test with research=false
executeFunction(
{
...validArgs,
research: false
},
mockContext
);
// Verify analyzeTaskComplexityDirect was called with research=false
expect(mockAnalyzeTaskComplexityDirect).toHaveBeenCalledWith(
expect.objectContaining({
research: false
}),
expect.any(Object),
expect.any(Object)
);
});
});

View File

@@ -1,342 +0,0 @@
/**
* Tests for the initialize-project MCP tool
*
* Note: This test does NOT test the actual implementation. It tests that:
* 1. The tool is registered correctly with the correct parameters
* 2. Command construction works correctly with various arguments
* 3. Error handling works as expected
* 4. Response formatting is correct
*
* We do NOT import the real implementation - everything is mocked
*/
import { jest } from '@jest/globals';
// Mock child_process.execSync
const mockExecSync = jest.fn();
jest.mock('child_process', () => ({
execSync: mockExecSync
}));
// Mock the utility functions
const mockCreateContentResponse = jest.fn((content) => ({
content
}));
const mockCreateErrorResponse = jest.fn((message, details) => ({
error: { message, details }
}));
jest.mock('../../../../mcp-server/src/tools/utils.js', () => ({
createContentResponse: mockCreateContentResponse,
createErrorResponse: mockCreateErrorResponse
}));
// Mock the z object from zod
const mockZod = {
object: jest.fn(() => mockZod),
string: jest.fn(() => mockZod),
boolean: jest.fn(() => mockZod),
optional: jest.fn(() => mockZod),
default: jest.fn(() => mockZod),
describe: jest.fn(() => mockZod),
_def: {
shape: () => ({
projectName: {},
projectDescription: {},
projectVersion: {},
authorName: {},
skipInstall: {},
addAliases: {},
yes: {}
})
}
};
jest.mock('zod', () => ({
z: mockZod
}));
// Create our own simplified version of the registerInitializeProjectTool function
const registerInitializeProjectTool = (server) => {
server.addTool({
name: 'initialize_project',
description:
"Initializes a new Task Master project structure in the current working directory by running 'task-master init'.",
parameters: mockZod,
execute: async (args, { log }) => {
try {
log.info(
`Executing initialize_project with args: ${JSON.stringify(args)}`
);
// Construct the command arguments
let command = 'npx task-master init';
const cliArgs = [];
if (args.projectName) {
cliArgs.push(`--name "${args.projectName.replace(/"/g, '\\"')}"`);
}
if (args.projectDescription) {
cliArgs.push(
`--description "${args.projectDescription.replace(/"/g, '\\"')}"`
);
}
if (args.projectVersion) {
cliArgs.push(
`--version "${args.projectVersion.replace(/"/g, '\\"')}"`
);
}
if (args.authorName) {
cliArgs.push(`--author "${args.authorName.replace(/"/g, '\\"')}"`);
}
if (args.skipInstall) cliArgs.push('--skip-install');
if (args.addAliases) cliArgs.push('--aliases');
if (args.yes) cliArgs.push('--yes');
command += ' ' + cliArgs.join(' ');
log.info(`Constructed command: ${command}`);
// Execute the command
const output = mockExecSync(command, {
encoding: 'utf8',
stdio: 'pipe',
timeout: 300000
});
log.info(`Initialization output:\n${output}`);
// Return success response
return mockCreateContentResponse({
message: 'Project initialized successfully.',
next_step:
'Now that the project is initialized, the next step is to create the tasks by parsing a PRD. This will create the tasks folder and the initial task files. The parse-prd tool will required a PRD file',
output: output
});
} catch (error) {
// Catch errors
const errorMessage = `Project initialization failed: ${error.message}`;
const errorDetails =
error.stderr?.toString() || error.stdout?.toString() || error.message;
log.error(`${errorMessage}\nDetails: ${errorDetails}`);
// Return error response
return mockCreateErrorResponse(errorMessage, { details: errorDetails });
}
}
});
};
describe('Initialize Project MCP Tool', () => {
// Mock server and logger
let mockServer;
let executeFunction;
const mockLogger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn()
};
beforeEach(() => {
// Clear all mocks before each test
jest.clearAllMocks();
// Create mock server
mockServer = {
addTool: jest.fn((config) => {
executeFunction = config.execute;
})
};
// Default mock behavior
mockExecSync.mockReturnValue('Project initialized successfully.');
// Register the tool to capture the tool definition
registerInitializeProjectTool(mockServer);
});
test('registers the tool with correct name and parameters', () => {
// Check that addTool was called
expect(mockServer.addTool).toHaveBeenCalledTimes(1);
// Extract the tool definition from the mock call
const toolDefinition = mockServer.addTool.mock.calls[0][0];
// Verify tool properties
expect(toolDefinition.name).toBe('initialize_project');
expect(toolDefinition.description).toContain(
'Initializes a new Task Master project'
);
expect(toolDefinition).toHaveProperty('parameters');
expect(toolDefinition).toHaveProperty('execute');
});
test('constructs command with proper arguments', async () => {
// Create arguments with all parameters
const args = {
projectName: 'Test Project',
projectDescription: 'A project for testing',
projectVersion: '1.0.0',
authorName: 'Test Author',
skipInstall: true,
addAliases: true,
yes: true
};
// Execute the tool
await executeFunction(args, { log: mockLogger });
// Verify execSync was called with the expected command
expect(mockExecSync).toHaveBeenCalledTimes(1);
const command = mockExecSync.mock.calls[0][0];
// Check that the command includes npx task-master init
expect(command).toContain('npx task-master init');
// Verify each argument is correctly formatted in the command
expect(command).toContain('--name "Test Project"');
expect(command).toContain('--description "A project for testing"');
expect(command).toContain('--version "1.0.0"');
expect(command).toContain('--author "Test Author"');
expect(command).toContain('--skip-install');
expect(command).toContain('--aliases');
expect(command).toContain('--yes');
});
test('properly escapes special characters in arguments', async () => {
// Create arguments with special characters
const args = {
projectName: 'Test "Quoted" Project',
projectDescription: 'A "special" project for testing'
};
// Execute the tool
await executeFunction(args, { log: mockLogger });
// Get the command that was executed
const command = mockExecSync.mock.calls[0][0];
// Verify quotes were properly escaped
expect(command).toContain('--name "Test \\"Quoted\\" Project"');
expect(command).toContain(
'--description "A \\"special\\" project for testing"'
);
});
test('returns success response when command succeeds', async () => {
// Set up the mock to return specific output
const outputMessage = 'Project initialized successfully.';
mockExecSync.mockReturnValueOnce(outputMessage);
// Execute the tool
const result = await executeFunction({}, { log: mockLogger });
// Verify createContentResponse was called with the right arguments
expect(mockCreateContentResponse).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Project initialized successfully.',
next_step: expect.any(String),
output: outputMessage
})
);
// Verify the returned result has the expected structure
expect(result).toHaveProperty('content');
expect(result.content).toHaveProperty('message');
expect(result.content).toHaveProperty('next_step');
expect(result.content).toHaveProperty('output');
expect(result.content.output).toBe(outputMessage);
});
test('returns error response when command fails', async () => {
// Create an error to be thrown
const error = new Error('Command failed');
error.stdout = 'Some standard output';
error.stderr = 'Some error output';
// Make the mock throw the error
mockExecSync.mockImplementationOnce(() => {
throw error;
});
// Execute the tool
const result = await executeFunction({}, { log: mockLogger });
// Verify createErrorResponse was called with the right arguments
expect(mockCreateErrorResponse).toHaveBeenCalledWith(
'Project initialization failed: Command failed',
expect.objectContaining({
details: 'Some error output'
})
);
// Verify the returned result has the expected structure
expect(result).toHaveProperty('error');
expect(result.error).toHaveProperty('message');
expect(result.error.message).toContain('Project initialization failed');
});
test('logs information about the execution', async () => {
// Execute the tool
await executeFunction({}, { log: mockLogger });
// Verify that logging occurred
expect(mockLogger.info).toHaveBeenCalledWith(
expect.stringContaining('Executing initialize_project')
);
expect(mockLogger.info).toHaveBeenCalledWith(
expect.stringContaining('Constructed command')
);
expect(mockLogger.info).toHaveBeenCalledWith(
expect.stringContaining('Initialization output')
);
});
test('uses fallback to stdout if stderr is not available in error', async () => {
// Create an error with only stdout
const error = new Error('Command failed');
error.stdout = 'Some standard output with error details';
// No stderr property
// Make the mock throw the error
mockExecSync.mockImplementationOnce(() => {
throw error;
});
// Execute the tool
await executeFunction({}, { log: mockLogger });
// Verify createErrorResponse was called with stdout as details
expect(mockCreateErrorResponse).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
details: 'Some standard output with error details'
})
);
});
test('logs error details when command fails', async () => {
// Create an error
const error = new Error('Command failed');
error.stderr = 'Some detailed error message';
// Make the mock throw the error
mockExecSync.mockImplementationOnce(() => {
throw error;
});
// Execute the tool
await executeFunction({}, { log: mockLogger });
// Verify error logging
expect(mockLogger.error).toHaveBeenCalledWith(
expect.stringContaining('Project initialization failed')
);
expect(mockLogger.error).toHaveBeenCalledWith(
expect.stringContaining('Some detailed error message')
);
});
});

View File

@@ -1,68 +0,0 @@
// In tests/unit/parse-prd.test.js
// Testing that parse-prd.js handles both .txt and .md files the same way
import { jest } from '@jest/globals';
describe('parse-prd file extension compatibility', () => {
// Test directly that the parse-prd functionality works with different extensions
// by examining the parameter handling in mcp-server/src/tools/parse-prd.js
test('Parameter description mentions support for .md files', () => {
// The parameter description for 'input' in parse-prd.js includes .md files
const description =
'Absolute path to the PRD document file (.txt, .md, etc.)';
// Verify the description explicitly mentions .md files
expect(description).toContain('.md');
});
test('File extension validation is not restricted to .txt files', () => {
// Check for absence of extension validation
const fileValidator = (filePath) => {
// Return a boolean value to ensure the test passes
if (!filePath || filePath.length === 0) {
return false;
}
return true;
};
// Test with different extensions
expect(fileValidator('/path/to/prd.txt')).toBe(true);
expect(fileValidator('/path/to/prd.md')).toBe(true);
// Invalid cases should still fail regardless of extension
expect(fileValidator('')).toBe(false);
});
test('Implementation handles all file types the same way', () => {
// This test confirms that the implementation treats all file types equally
// by simulating the core functionality
const mockImplementation = (filePath) => {
// The parse-prd.js implementation only checks file existence,
// not the file extension, which is what we want to verify
if (!filePath) {
return { success: false, error: { code: 'MISSING_INPUT_FILE' } };
}
// In the real implementation, this would check if the file exists
// But for our test, we're verifying that the same logic applies
// regardless of file extension
// No special handling for different extensions
return { success: true };
};
// Verify same behavior for different extensions
const txtResult = mockImplementation('/path/to/prd.txt');
const mdResult = mockImplementation('/path/to/prd.md');
// Both should succeed since there's no extension-specific logic
expect(txtResult.success).toBe(true);
expect(mdResult.success).toBe(true);
// Both should have the same structure
expect(Object.keys(txtResult)).toEqual(Object.keys(mdResult));
});
});

View File

@@ -455,7 +455,7 @@ describe('Task Manager Module', () => {
}); });
}); });
describe('analyzeTaskComplexity function', () => { describe.skip('analyzeTaskComplexity function', () => {
// Setup common test variables // Setup common test variables
const tasksPath = 'tasks/tasks.json'; const tasksPath = 'tasks/tasks.json';
const reportPath = 'scripts/task-complexity-report.json'; const reportPath = 'scripts/task-complexity-report.json';
@@ -502,7 +502,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: false }; const options = { ...baseOptions, research: false };
// Act // Act
await testAnalyzeTaskComplexity(options); await taskManager.analyzeTaskComplexity(options);
// Assert // Assert
expect(mockCallClaude).toHaveBeenCalled(); expect(mockCallClaude).toHaveBeenCalled();
@@ -518,7 +518,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: true }; const options = { ...baseOptions, research: true };
// Act // Act
await testAnalyzeTaskComplexity(options); await taskManager.analyzeTaskComplexity(options);
// Assert // Assert
expect(mockCallPerplexity).toHaveBeenCalled(); expect(mockCallPerplexity).toHaveBeenCalled();
@@ -534,7 +534,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: false }; const options = { ...baseOptions, research: false };
// Act // Act
await testAnalyzeTaskComplexity(options); await taskManager.analyzeTaskComplexity(options);
// Assert // Assert
expect(mockReadJSON).toHaveBeenCalledWith(tasksPath); expect(mockReadJSON).toHaveBeenCalledWith(tasksPath);
@@ -543,9 +543,7 @@ describe('Task Manager Module', () => {
expect(mockWriteJSON).toHaveBeenCalledWith( expect(mockWriteJSON).toHaveBeenCalledWith(
reportPath, reportPath,
expect.objectContaining({ expect.objectContaining({
complexityAnalysis: expect.arrayContaining([ tasks: expect.arrayContaining([expect.objectContaining({ id: 1 })])
expect.objectContaining({ taskId: 1 })
])
}) })
); );
expect(mockLog).toHaveBeenCalledWith( expect(mockLog).toHaveBeenCalledWith(
@@ -556,71 +554,50 @@ describe('Task Manager Module', () => {
test('should handle and fix malformed JSON string response (Claude)', async () => { test('should handle and fix malformed JSON string response (Claude)', async () => {
// Arrange // Arrange
const malformedJsonResponse = { const malformedJsonResponse = `{"tasks": [{"id": 1, "complexity": 3, "subtaskCount: 2}]}`;
tasks: [{ id: 1, complexity: 3 }]
};
mockCallClaude.mockResolvedValueOnce(malformedJsonResponse); mockCallClaude.mockResolvedValueOnce(malformedJsonResponse);
const options = { ...baseOptions, research: false }; const options = { ...baseOptions, research: false };
// Act // Act
await testAnalyzeTaskComplexity(options); await taskManager.analyzeTaskComplexity(options);
// Assert // Assert
expect(mockCallClaude).toHaveBeenCalled(); expect(mockCallClaude).toHaveBeenCalled();
expect(mockCallPerplexity).not.toHaveBeenCalled(); expect(mockCallPerplexity).not.toHaveBeenCalled();
expect(mockWriteJSON).toHaveBeenCalled(); expect(mockWriteJSON).toHaveBeenCalled();
expect(mockLog).toHaveBeenCalledWith(
'warn',
expect.stringContaining('Malformed JSON')
);
}); });
test('should handle missing tasks in the response (Claude)', async () => { test('should handle missing tasks in the response (Claude)', async () => {
// Arrange // Arrange
const incompleteResponse = { tasks: [sampleApiResponse.tasks[0]] }; const incompleteResponse = { tasks: [sampleApiResponse.tasks[0]] };
mockCallClaude.mockResolvedValueOnce(incompleteResponse); mockCallClaude.mockResolvedValueOnce(incompleteResponse);
const missingTaskResponse = {
tasks: [sampleApiResponse.tasks[1], sampleApiResponse.tasks[2]]
};
mockCallClaude.mockResolvedValueOnce(missingTaskResponse);
const options = { ...baseOptions, research: false }; const options = { ...baseOptions, research: false };
// Act // Act
await testAnalyzeTaskComplexity(options); await taskManager.analyzeTaskComplexity(options);
// Assert // Assert
expect(mockCallClaude).toHaveBeenCalled(); expect(mockCallClaude).toHaveBeenCalledTimes(2);
expect(mockCallPerplexity).not.toHaveBeenCalled(); expect(mockCallPerplexity).not.toHaveBeenCalled();
expect(mockWriteJSON).toHaveBeenCalled(); expect(mockWriteJSON).toHaveBeenCalledWith(
}); reportPath,
expect.objectContaining({
// Add a new test specifically for threshold handling tasks: expect.arrayContaining([
test('should handle different threshold parameter types correctly', async () => { expect.objectContaining({ id: 1 }),
// Test with string threshold expect.objectContaining({ id: 2 }),
let options = { ...baseOptions, threshold: '7' }; expect.objectContaining({ id: 3 })
const report1 = await testAnalyzeTaskComplexity(options); ])
expect(report1.meta.thresholdScore).toBe(7); })
expect(mockCallClaude).toHaveBeenCalled(); );
// Reset mocks
jest.clearAllMocks();
// Test with number threshold
options = { ...baseOptions, threshold: 8 };
const report2 = await testAnalyzeTaskComplexity(options);
expect(report2.meta.thresholdScore).toBe(8);
expect(mockCallClaude).toHaveBeenCalled();
// Reset mocks
jest.clearAllMocks();
// Test with float threshold
options = { ...baseOptions, threshold: 6.5 };
const report3 = await testAnalyzeTaskComplexity(options);
expect(report3.meta.thresholdScore).toBe(6.5);
expect(mockCallClaude).toHaveBeenCalled();
// Reset mocks
jest.clearAllMocks();
// Test with undefined threshold (should use default)
const { threshold, ...optionsWithoutThreshold } = baseOptions;
const report4 = await testAnalyzeTaskComplexity(optionsWithoutThreshold);
expect(report4.meta.thresholdScore).toBe(5); // Default value from the function
expect(mockCallClaude).toHaveBeenCalled();
}); });
}); });
@@ -3101,68 +3078,3 @@ describe.skip('updateSubtaskById function', () => {
// More tests will go here... // More tests will go here...
}); });
// Add this test-specific implementation after the other test functions like testParsePRD
const testAnalyzeTaskComplexity = async (options) => {
try {
// Get base options or use defaults
const thresholdScore = parseFloat(options.threshold || '5');
const useResearch = options.research === true;
const tasksPath = options.file || 'tasks/tasks.json';
const reportPath = options.output || 'scripts/task-complexity-report.json';
const modelName = options.model || 'mock-claude-model';
// Read tasks file
const tasksData = mockReadJSON(tasksPath);
if (!tasksData || !Array.isArray(tasksData.tasks)) {
throw new Error(`No valid tasks found in ${tasksPath}`);
}
// Filter tasks for analysis (non-completed)
const activeTasks = tasksData.tasks.filter(
(task) => task.status !== 'done' && task.status !== 'completed'
);
// Call the appropriate mock API based on research flag
let apiResponse;
if (useResearch) {
apiResponse = await mockCallPerplexity();
} else {
apiResponse = await mockCallClaude();
}
// Format report with threshold check
const report = {
meta: {
generatedAt: new Date().toISOString(),
tasksAnalyzed: activeTasks.length,
thresholdScore: thresholdScore,
projectName: tasksData.meta?.projectName || 'Test Project',
usedResearch: useResearch,
model: modelName
},
complexityAnalysis:
apiResponse.tasks?.map((task) => ({
taskId: task.id,
complexityScore: task.complexity || 5,
recommendedSubtasks: task.subtaskCount || 3,
expansionPrompt: `Generate ${task.subtaskCount || 3} subtasks`,
reasoning: 'Mock reasoning for testing'
})) || []
};
// Write the report
mockWriteJSON(reportPath, report);
// Log success
mockLog(
'info',
`Successfully analyzed ${activeTasks.length} tasks with threshold ${thresholdScore}`
);
return report;
} catch (error) {
mockLog('error', `Error during complexity analysis: ${error.message}`);
throw error;
}
};