Compare commits

..

1 Commits

Author SHA1 Message Date
Eyal Toledano
f4641cff82 fix: Remove task-master-ai as a dependency from the package.json generated during init 2025-04-09 10:01:05 +02:00
93 changed files with 2334 additions and 5216 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",
"MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000,
"MAX_TOKENS": 128000,
"TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium"

View File

@@ -14,13 +14,13 @@ alwaysApply: false
- **Purpose**: Defines and registers all CLI commands using Commander.js.
- **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)):
- 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.
- Implements input validation and error handling for CLI commands.
- **Key Components**:
- `programInstance` (Commander.js `Command` instance): Manages command definitions.
- `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**
- **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
- **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**:
- **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.
- **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.
- **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 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.
- **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`.

View File

@@ -24,7 +24,7 @@ While this document details the implementation of Task Master's **CLI commands**
programInstance
.command('command-name')
.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')
.action(async (options) => {
// Command implementation
@@ -34,8 +34,7 @@ While this document details the implementation of Task Master's **CLI commands**
- **Command Handler Organization**:
- ✅ DO: Keep action handlers concise and focused
- ✅ 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: Perform basic parameter validation (e.g., checking for required options) within the action handler or at the start of the called core function.
- ✅ DO: Include validation for required parameters
- ❌ DON'T: Implement business logic in command handlers
## Best Practices for Removal/Delete Commands

View File

@@ -36,8 +36,8 @@ This document provides a detailed reference for interacting with Taskmaster, cov
* `skipInstall`: `Skip installing dependencies (default: false).` (CLI: `--skip-install`)
* `addAliases`: `Add shell aliases (tm, taskmaster) (default: false).` (CLI: `--aliases`)
* `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.
* **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.
* **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.
### 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`)
* **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.
* **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
*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
- **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
- **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
- **Create Simplified Test Functions**
@@ -778,125 +564,99 @@ npm test -- -t "pattern to match"
const setTaskStatus = async (taskId, newStatus) => {
const tasksPath = 'tasks/tasks.json';
const data = await readJSON(tasksPath);
// [implementation]
// Update task status logic
await writeJSON(tasksPath, data);
return { success: true };
return data;
};
// Test-friendly version (easier to test)
const updateTaskStatus = (tasks, taskId, newStatus) => {
// Pure logic without side effects
const updatedTasks = [...tasks];
const taskIndex = findTaskById(updatedTasks, taskId);
if (taskIndex === -1) return { success: false, error: 'Task not found' };
updatedTasks[taskIndex].status = newStatus;
return { success: true, tasks: updatedTasks };
// Test-friendly simplified function (easy to test)
const testSetTaskStatus = (tasksData, taskIdInput, newStatus) => {
// Same core logic without file operations
// Update task status logic on provided tasksData object
return tasksData; // Return updated data for assertions
};
```
- **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.
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');
});
```
Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options.

View File

@@ -5,7 +5,7 @@ PERPLEXITY_API_KEY=your_perplexity_api_key_here # Format: pplx-...
# Model Configuration
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
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)
# 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
tasks
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
## 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
### Patch Changes

View File

@@ -146,7 +146,7 @@ To enable enhanced task management capabilities directly within Cursor using the
4. Configure with the following details:
- Name: "Task Master"
- Type: "Command"
- Command: "npx -y task-master-mcp"
- Command: "npx -y --package task-master-ai task-master-mcp"
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.

View File

@@ -27,13 +27,13 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
"mcpServers": {
"taskmaster-ai": {
"command": "npx",
"args": ["-y", "task-master-mcp"],
"args": ["-y", "task-master-ai", "mcp-server"],
"env": {
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
"MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000,
"MAX_TOKENS": 128000,
"TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium"
@@ -131,12 +131,6 @@ cd claude-task-master
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 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
@@ -225,47 +225,47 @@ function createDevScriptAction(commandName) {
};
}
// // Special case for the 'init' command which uses a different script
// function registerInitCommand(program) {
// program
// .command('init')
// .description('Initialize a new project')
// .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')
// .option('-a, --author <author>', 'Author name')
// .option('--skip-install', 'Skip installing dependencies')
// .option('--dry-run', 'Show what would be done without making changes')
// .action((options) => {
// // Pass through any options to the init script
// const args = [
// '--yes',
// 'name',
// 'description',
// 'version',
// 'author',
// 'skip-install',
// 'dry-run'
// ]
// .filter((opt) => options[opt])
// .map((opt) => {
// if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
// return `--${opt}`;
// }
// return `--${opt}=${options[opt]}`;
// });
// Special case for the 'init' command which uses a different script
function registerInitCommand(program) {
program
.command('init')
.description('Initialize a new project')
.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')
.option('-a, --author <author>', 'Author name')
.option('--skip-install', 'Skip installing dependencies')
.option('--dry-run', 'Show what would be done without making changes')
.action((options) => {
// Pass through any options to the init script
const args = [
'--yes',
'name',
'description',
'version',
'author',
'skip-install',
'dry-run'
]
.filter((opt) => options[opt])
.map((opt) => {
if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
return `--${opt}`;
}
return `--${opt}=${options[opt]}`;
});
// const child = spawn('node', [initScriptPath, ...args], {
// stdio: 'inherit',
// cwd: process.cwd()
// });
const child = spawn('node', [initScriptPath, ...args], {
stdio: 'inherit',
cwd: process.cwd()
});
// child.on('close', (code) => {
// process.exit(code);
// });
// });
// }
child.on('close', (code) => {
process.exit(code);
});
});
}
// Set up the command-line interface
const program = new Command();
@@ -286,8 +286,8 @@ program.on('--help', () => {
displayHelp();
});
// // Add special case commands
// registerInitCommand(program);
// Add special case commands
registerInitCommand(program);
program
.command('dev')
@@ -303,7 +303,7 @@ registerCommands(tempProgram);
// For each command in the temp instance, add a modified version to our actual program
tempProgram.commands.forEach((cmd) => {
if (['dev'].includes(cmd.name())) {
if (['init', 'dev'].includes(cmd.name())) {
// Skip commands we've already defined specially
return;
}

View File

@@ -17,13 +17,13 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
"mcpServers": {
"taskmaster-ai": {
"command": "npx",
"args": ["-y", "task-master-mcp"],
"args": ["-y", "task-master-ai", "mcp-server"],
"env": {
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
"MODEL": "claude-3-7-sonnet-20250219",
"PERPLEXITY_MODEL": "sonar-pro",
"MAX_TOKENS": 64000,
"MAX_TOKENS": 128000,
"TEMPERATURE": 0.2,
"DEFAULT_SUBTASKS": 5,
"DEFAULT_PRIORITY": "medium"
@@ -132,7 +132,7 @@ You can also set up the MCP server in Cursor settings:
4. Configure with the following details:
- Name: "Task Master"
- Type: "Command"
- Command: "npx -y task-master-mcp"
- Command: "npx -y --package task-master-ai task-master-mcp"
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.

View File

@@ -4,6 +4,7 @@
*/
import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -13,32 +14,19 @@ import {
* Direct function wrapper for addDependency with error handling.
*
* @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.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
* @returns {Promise<Object>} - Result object with success status and data/error information
*/
export async function addDependencyDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, dependsOn } = args;
try {
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
if (!id) {
if (!args.id) {
return {
success: false,
error: {
@@ -48,7 +36,7 @@ export async function addDependencyDirect(args, log) {
};
}
if (!dependsOn) {
if (!args.dependsOn) {
return {
success: false,
error: {
@@ -58,16 +46,18 @@ export async function addDependencyDirect(args, log) {
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Format IDs for the core function
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 =
dependsOn && dependsOn.includes && dependsOn.includes('.')
? dependsOn
: parseInt(dependsOn, 10);
args.dependsOn.includes && args.dependsOn.includes('.')
? args.dependsOn
: parseInt(args.dependsOn, 10);
log.info(
`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
enableSilentMode();
// Call the core function using the provided path
// Call the core function
await addDependency(tasksPath, taskId, dependencyId);
// Restore normal logging

View File

@@ -3,6 +3,7 @@
*/
import { addSubtask } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -11,7 +12,6 @@ import {
/**
* Add a subtask to an existing task
* @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.taskId] - Existing task ID to convert to subtask (optional)
* @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.status] - Status for new subtask (default: 'pending')
* @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 {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: string}>}
*/
export async function addSubtaskDirect(args, log) {
// Destructure expected args
const {
tasksJsonPath,
id,
taskId,
title,
description,
details,
status,
dependencies: dependenciesStr,
skipGenerate
} = args;
try {
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('addSubtaskDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
if (!id) {
if (!args.id) {
return {
success: false,
error: {
@@ -62,7 +40,7 @@ export async function addSubtaskDirect(args, log) {
}
// Either taskId or title must be provided
if (!taskId && !title) {
if (!args.taskId && !args.title) {
return {
success: false,
error: {
@@ -72,26 +50,26 @@ export async function addSubtaskDirect(args, log) {
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Parse dependencies if provided
let dependencies = [];
if (dependenciesStr) {
dependencies = dependenciesStr.split(',').map((depId) => {
if (args.dependencies) {
dependencies = args.dependencies.split(',').map((id) => {
// 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
const existingTaskId = taskId ? parseInt(taskId, 10) : null;
const existingTaskId = args.taskId ? parseInt(args.taskId, 10) : null;
// Convert parent ID to a number
const parentId = parseInt(id, 10);
const parentId = parseInt(args.id, 10);
// 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
enableSilentMode();
@@ -123,10 +101,10 @@ export async function addSubtaskDirect(args, log) {
log.info(`Creating new subtask for parent task ${parentId}`);
const newSubtaskData = {
title: title,
description: description || '',
details: details || '',
status: status || 'pending',
title: args.title,
description: args.description || '',
details: args.details || '',
status: args.status || 'pending',
dependencies: dependencies
};

View File

@@ -4,6 +4,7 @@
*/
import { addTask } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -22,227 +23,162 @@ import {
* Direct function wrapper for adding a new task with error handling.
*
* @param {Object} args - Command arguments
* @param {string} [args.prompt] - Description of the task to add (required if not using manual fields)
* @param {string} [args.title] - Task title (for manual task creation)
* @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.prompt - Description of the task to add
* @param {Array<number>} [args.dependencies=[]] - Task dependencies as array of IDs
* @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 {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} context - Additional context (reportProgress, session)
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
*/
export async function addTaskDirect(args, log, context = {}) {
// Destructure expected args
const { tasksJsonPath, prompt, dependencies, priority, research } = args;
try {
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode();
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
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;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Check required parameters
if (!args.prompt && !isManualCreation) {
log.error(
'Missing required parameters: either prompt or title+description must be provided'
);
if (!args.prompt) {
log.error('Missing required parameter: prompt');
disableSilentMode();
return {
success: false,
error: {
code: 'MISSING_PARAMETER',
message:
'Either the prompt parameter or both title and description parameters are required for adding a task'
message: 'The prompt parameter is required for adding a task'
}
};
}
// Extract and prepare parameters
const taskPrompt = prompt;
const taskDependencies = Array.isArray(dependencies)
? dependencies
: dependencies
? String(dependencies)
const prompt = args.prompt;
const dependencies = Array.isArray(args.dependencies)
? args.dependencies
: args.dependencies
? String(args.dependencies)
.split(',')
.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
const { session } = context;
// Commenting out reportProgress extraction
// const { reportProgress, session } = context;
const { session } = context; // Keep session
let manualTaskData = null;
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
// Initialize AI client with session environment
let localAnthropic;
try {
localAnthropic = getAnthropicClientForMCP(session, log);
} catch (error) {
log.error(`Failed to initialize Anthropic client: ${error.message}`);
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
let localAnthropic;
try {
localAnthropic = getAnthropicClientForMCP(session, log);
} catch (error) {
log.error(`Failed to initialize Anthropic client: ${error.message}`);
disableSilentMode();
return {
success: false,
error: {
code: 'AI_CLIENT_ERROR',
message: `Cannot initialize AI client: ${error.message}`
}
};
}
// Get model configuration from session
const modelConfig = getModelConfig(session);
// Read existing tasks to provide context
let tasksData;
try {
const fs = await import('fs');
tasksData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
} catch (error) {
log.warn(`Could not read existing tasks for context: ${error.message}`);
tasksData = { tasks: [] };
}
// Build prompts for AI
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(
prompt,
tasksData.tasks
);
// Make the AI call using the streaming helper
let responseText;
try {
responseText = await _handleAnthropicStream(
localAnthropic,
{
model: modelConfig.model,
max_tokens: modelConfig.maxTokens,
temperature: modelConfig.temperature,
messages: [{ role: 'user', content: userPrompt }],
system: systemPrompt
},
{
mcpLog: log
}
);
} catch (error) {
log.error(`AI processing failed: ${error.message}`);
disableSilentMode();
return {
success: false,
error: {
code: 'AI_PROCESSING_ERROR',
message: `Failed to generate task with AI: ${error.message}`
}
};
}
// Parse the AI response
let taskDataFromAI;
try {
taskDataFromAI = parseTaskJsonResponse(responseText);
} catch (error) {
log.error(`Failed to parse AI response: ${error.message}`);
disableSilentMode();
return {
success: false,
error: {
code: 'RESPONSE_PARSING_ERROR',
message: `Failed to parse AI response: ${error.message}`
}
};
}
// Call the addTask function with 'json' outputFormat to prevent console output when called via MCP
const newTaskId = await addTask(
tasksPath,
prompt,
taskDependencies,
priority,
{
mcpLog: log,
session
},
'json',
null,
taskDataFromAI // Pass the parsed AI result as the manual task data
);
// Restore normal logging
disableSilentMode();
return {
success: true,
data: {
taskId: newTaskId,
message: `Successfully added new task #${newTaskId}`
success: false,
error: {
code: 'AI_CLIENT_ERROR',
message: `Cannot initialize AI client: ${error.message}`
}
};
}
// Get model configuration from session
const modelConfig = getModelConfig(session);
// Read existing tasks to provide context
let tasksData;
try {
const fs = await import('fs');
tasksData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
} catch (error) {
log.warn(`Could not read existing tasks for context: ${error.message}`);
tasksData = { tasks: [] };
}
// Build prompts for AI
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(
prompt,
tasksData.tasks
);
// Make the AI call using the streaming helper
let responseText;
try {
responseText = await _handleAnthropicStream(
localAnthropic,
{
model: modelConfig.model,
max_tokens: modelConfig.maxTokens,
temperature: modelConfig.temperature,
messages: [{ role: 'user', content: userPrompt }],
system: systemPrompt
},
{
// reportProgress: context.reportProgress, // Commented out to prevent Cursor stroking out
mcpLog: log
}
);
} catch (error) {
log.error(`AI processing failed: ${error.message}`);
disableSilentMode();
return {
success: false,
error: {
code: 'AI_PROCESSING_ERROR',
message: `Failed to generate task with AI: ${error.message}`
}
};
}
// Parse the AI response
let taskDataFromAI;
try {
taskDataFromAI = parseTaskJsonResponse(responseText);
} catch (error) {
log.error(`Failed to parse AI response: ${error.message}`);
disableSilentMode();
return {
success: false,
error: {
code: 'RESPONSE_PARSING_ERROR',
message: `Failed to parse AI response: ${error.message}`
}
};
}
// Call the addTask function with 'json' outputFormat to prevent console output when called via MCP
const newTaskId = await addTask(
tasksPath,
prompt,
dependencies,
priority,
{
// reportProgress, // Commented out
mcpLog: log,
session,
taskDataFromAI // Pass the parsed AI result
},
'json'
);
// Restore normal logging
disableSilentMode();
return {
success: true,
data: {
taskId: newTaskId,
message: `Successfully added new task #${newTaskId}`
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();

View File

@@ -3,6 +3,7 @@
*/
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode,
@@ -15,60 +16,45 @@ import path from 'path';
/**
* Analyze task complexity and generate recommendations
* @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.outputPath - Explicit absolute path to save the report.
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.output] - Output file path for the report
* @param {string} [args.model] - LLM model to use for analysis
* @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 {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object
* @param {Object} [context={}] - Context object containing session data
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function analyzeTaskComplexityDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, outputPath, model, threshold, research } = args;
try {
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
// Check if required paths were provided
if (!tasksJsonPath) {
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' }
};
}
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Use the provided paths
const tasksPath = tasksJsonPath;
const resolvedOutputPath = outputPath;
// Determine output path
let outputPath = args.output || 'scripts/task-complexity-report.json';
if (!path.isAbsolute(outputPath) && args.projectRoot) {
outputPath = path.join(args.projectRoot, outputPath);
}
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');
}
// Create options object for analyzeTaskComplexity using provided paths
// Create options object for analyzeTaskComplexity
const options = {
file: tasksPath,
output: resolvedOutputPath,
model: model,
threshold: threshold,
research: research === true
output: outputPath,
model: args.model,
threshold: args.threshold,
research: args.research === true
};
// 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
if (!fs.existsSync(resolvedOutputPath)) {
if (!fs.existsSync(outputPath)) {
return {
success: false,
error: {
@@ -122,7 +108,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
// Read the report file
let report;
try {
report = JSON.parse(fs.readFileSync(resolvedOutputPath, 'utf8'));
report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
// Important: Handle different report formats
// 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 {
success: true,
data: {
message: `Task complexity analysis complete. Report saved to ${resolvedOutputPath}`,
reportPath: resolvedOutputPath,
message: `Task complexity analysis complete. Report saved to ${outputPath}`,
reportPath: outputPath,
reportSummary: {
taskCount: analysisArray.length,
highComplexityTasks,

View File

@@ -3,6 +3,7 @@
*/
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -12,32 +13,19 @@ import fs from 'fs';
/**
* Clear subtasks from specified tasks
* @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 {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
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function clearSubtasksDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, all } = args;
try {
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
if (!id && !all) {
if (!args.id && !args.all) {
return {
success: false,
error: {
@@ -48,8 +36,8 @@ export async function clearSubtasksDirect(args, log) {
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Check if tasks.json exists
if (!fs.existsSync(tasksPath)) {
@@ -65,7 +53,7 @@ export async function clearSubtasksDirect(args, log) {
let taskIds;
// If all is specified, get all task IDs
if (all) {
if (args.all) {
log.info('Clearing subtasks from all tasks');
const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
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(',');
} else {
// Use the provided task IDs
taskIds = id;
taskIds = args.id;
}
log.info(`Clearing subtasks from tasks: ${taskIds}`);

View File

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

View File

@@ -8,6 +8,7 @@ import {
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
import path from 'path';
import fs from 'fs';
@@ -15,51 +16,34 @@ import fs from 'fs';
/**
* Expand all pending tasks with subtasks
* @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 {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 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} context - Context object containing session
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function expandAllTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, num, research, prompt, force } = args;
try {
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
enableSilentMode();
try {
// Remove internal path finding
/*
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
*/
// Use provided path
const tasksPath = tasksJsonPath;
// Parse parameters
const numSubtasks = num ? parseInt(num, 10) : undefined;
const useResearch = research === true;
const additionalContext = prompt || '';
const forceFlag = force === true;
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = args.research === true;
const additionalContext = args.prompt || '';
const forceFlag = args.force === true;
log.info(
`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`

View File

@@ -11,6 +11,7 @@ import {
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
getAnthropicClientForMCP,
getModelConfig
@@ -22,20 +23,12 @@ import fs from 'fs';
* Direct function wrapper for expanding a task into subtasks with error handling.
*
* @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} context - Context object containing session and reportProgress
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/
export async function expandTaskDirect(args, log, context = {}) {
const { session } = context;
// Destructure expected args
const { tasksJsonPath, id, num, research, prompt, force } = args;
// Log session root data for debugging
log.info(
@@ -47,26 +40,48 @@ export async function expandTaskDirect(args, log, context = {}) {
})}`
);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('expandTaskDirect called without tasksJsonPath');
let tasksPath;
try {
// 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 {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
code: 'FILE_NOT_FOUND_ERROR',
message: `Error determining tasksPath: ${error.message}${sessionRootsInfo}`
},
fromCache: false
};
}
// Use provided path
const tasksPath = tasksJsonPath;
log.info(`[expandTaskDirect] Using tasksPath: ${tasksPath}`);
log.info(`[expandTaskDirect] Determined tasksPath: ${tasksPath}`);
// Validate task ID
const taskId = id ? parseInt(id, 10) : null;
const taskId = args.id ? parseInt(args.id, 10) : null;
if (!taskId) {
log.error('Task ID is required');
return {
@@ -80,10 +95,9 @@ export async function expandTaskDirect(args, log, context = {}) {
}
// Process other parameters
const numSubtasks = num ? parseInt(num, 10) : undefined;
const useResearch = research === true;
const additionalContext = prompt || '';
const forceFlag = force === true;
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = args.research === true;
const additionalContext = args.prompt || '';
// Initialize AI client if needed (for expandTask function)
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;
if (hasExistingSubtasks && !forceFlag) {
log.info(
`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.`
);
// If the task already has subtasks, just return it (matching core behavior)
if (hasExistingSubtasks) {
log.info(`Task ${taskId} already has ${task.subtasks.length} subtasks`);
return {
success: true,
data: {
message: `Task ${taskId} already has subtasks. Expansion skipped.`,
task,
subtasksAdded: 0,
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
const originalTask = JSON.parse(JSON.stringify(task));

View File

@@ -3,6 +3,7 @@
*/
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -12,30 +13,17 @@ import fs from 'fs';
/**
* Fix invalid dependencies in tasks.json automatically
* @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
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function fixDependenciesDirect(args, log) {
// Destructure expected args
const { tasksJsonPath } = args;
try {
log.info(`Fixing invalid dependencies in tasks: ${tasksJsonPath}`);
log.info(`Fixing invalid dependencies in tasks...`);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('fixDependenciesDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
}
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Verify the file exists
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
enableSilentMode();
// Call the original command function using the provided path
// Call the original command function
await fixDependenciesCommand(tasksPath);
// Restore normal logging

View File

@@ -8,46 +8,40 @@ import {
enableSilentMode,
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import path from 'path';
/**
* 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.
* @returns {Promise<Object>} - Result object with success status and data/error information.
*/
export async function generateTaskFilesDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, outputDir } = args;
try {
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
// Check if paths were provided
if (!tasksJsonPath) {
const errorMessage = 'tasksJsonPath is required but was not provided.';
log.error(errorMessage);
// 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: 'MISSING_ARGUMENT', message: errorMessage },
error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false
};
}
// Get output directory (defaults to the same directory as the tasks file)
let outputDir = args.output;
if (!outputDir) {
const errorMessage = 'outputDir is required but was not provided.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
fromCache: false
};
outputDir = path.dirname(tasksPath);
}
// Use the provided paths
const tasksPath = tasksJsonPath;
const resolvedOutputDir = outputDir;
log.info(`Generating task files from ${tasksPath} to ${resolvedOutputDir}`);
log.info(`Generating task files from ${tasksPath} to ${outputDir}`);
// Execute core generateTaskFiles function in a separate try/catch
try {
@@ -55,7 +49,7 @@ export async function generateTaskFilesDirect(args, log) {
enableSilentMode();
// The function is synchronous despite being awaited elsewhere
generateTaskFiles(tasksPath, resolvedOutputDir);
generateTaskFiles(tasksPath, outputDir);
// Restore normal logging after task generation
disableSilentMode();
@@ -76,8 +70,8 @@ export async function generateTaskFilesDirect(args, log) {
success: true,
data: {
message: `Successfully generated task files`,
tasksPath: tasksPath,
outputDir: resolvedOutputDir,
tasksPath,
outputDir,
taskFiles:
'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 { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -13,30 +14,38 @@ import {
/**
* 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.
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
*/
export async function listTasksDirect(args, log) {
// Destructure the explicit tasksJsonPath from args
const { tasksJsonPath, status, withSubtasks } = args;
if (!tasksJsonPath) {
log.error('listTasksDirect called without tasksJsonPath');
let tasksPath;
try {
// Find the tasks path first - needed for cache key and execution
tasksPath = findTasksJsonPath(args, log);
} 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 {
success: false,
error: { code: error.code, message: error.message },
fromCache: false
};
}
log.error(`Unexpected error finding tasks file: ${error.message}`);
// Re-throw for outer catch or return structured error
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
},
error: { code: 'FIND_TASKS_PATH_ERROR', message: error.message },
fromCache: false
};
}
// Use the explicit tasksJsonPath for cache key
const statusFilter = status || 'all';
const withSubtasksFilter = withSubtasks || false;
const cacheKey = `listTasks:${tasksJsonPath}:${statusFilter}:${withSubtasksFilter}`;
// Generate cache key *after* finding tasksPath
const statusFilter = args.status || 'all';
const withSubtasks = args.withSubtasks || false;
const cacheKey = `listTasks:${tasksPath}:${statusFilter}:${withSubtasks}`;
// Define the action function to be executed on cache miss
const coreListTasksAction = async () => {
@@ -45,13 +54,12 @@ export async function listTasksDirect(args, log) {
enableSilentMode();
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(
tasksJsonPath,
tasksPath,
statusFilter,
withSubtasksFilter,
withSubtasks,
'json'
);

View File

@@ -6,6 +6,7 @@
import { findNextTask } from '../../../../scripts/modules/task-manager.js';
import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -15,28 +16,28 @@ import {
* Direct function wrapper for finding the next task to work on with error handling and caching.
*
* @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {Object} log - Logger object
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/
export async function nextTaskDirect(args, log) {
// Destructure expected args
const { tasksJsonPath } = args;
if (!tasksJsonPath) {
log.error('nextTaskDirect called without tasksJsonPath');
let tasksPath;
try {
// Find the tasks path first - needed for cache key and execution
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
code: 'FILE_NOT_FOUND_ERROR',
message: error.message
},
fromCache: false
};
}
// Generate cache key using the provided task path
const cacheKey = `nextTask:${tasksJsonPath}`;
// Generate cache key using task path
const cacheKey = `nextTask:${tasksPath}`;
// Define the action function to be executed on cache miss
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
enableSilentMode();
log.info(`Finding next task from ${tasksJsonPath}`);
log.info(`Finding next task from ${tasksPath}`);
// Read tasks data using the provided path
const data = readJSON(tasksJsonPath);
// Read tasks data
const data = readJSON(tasksPath);
if (!data || !data.tasks) {
disableSilentMode(); // Disable before return
return {
success: false,
error: {
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 fs from 'fs';
import os from 'os'; // Import os module for home directory check
import { parsePRD } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
@@ -47,70 +46,46 @@ export async function parsePRDDirect(args, log, context = {}) {
};
}
// Validate required parameters
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
};
}
// Parameter validation and path resolution
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);
return {
success: false,
error: { code: 'MISSING_INPUT_PATH', message: errorMessage },
error: { code: 'MISSING_INPUT_FILE', message: errorMessage },
fromCache: false
};
}
if (!args.output) {
const errorMessage = 'Output file path is required for parsePRDDirect';
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;
// Resolve input path (relative to project root if provided)
const projectRoot = args.projectRoot || process.cwd();
const inputPath = path.isAbsolute(args.input)
? 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
if (!fs.existsSync(inputPath)) {
const errorMessage = `Input file not found: ${inputPath}`;
log.error(errorMessage);
return {
success: false,
error: {
code: 'INPUT_FILE_NOT_FOUND',
message: errorMessage,
details: `Checked path: ${inputPath}\nProject root: ${projectRoot}\nInput argument: ${args.input}`
},
error: { code: 'INPUT_FILE_NOT_FOUND', message: errorMessage },
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
let numTasks = 10; // Default
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
enableSilentMode();
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
await parsePRD(
inputPath,

View File

@@ -3,6 +3,7 @@
*/
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -11,32 +12,19 @@ import {
/**
* Remove a dependency from a task
* @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.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
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function removeDependencyDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id, dependsOn } = args;
try {
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
if (!id) {
if (!args.id) {
return {
success: false,
error: {
@@ -46,7 +34,7 @@ export async function removeDependencyDirect(args, log) {
};
}
if (!dependsOn) {
if (!args.dependsOn) {
return {
success: false,
error: {
@@ -56,16 +44,18 @@ export async function removeDependencyDirect(args, log) {
};
}
// Use provided path
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Format IDs for the core function
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 =
dependsOn && dependsOn.includes && dependsOn.includes('.')
? dependsOn
: parseInt(dependsOn, 10);
args.dependsOn.includes && args.dependsOn.includes('.')
? args.dependsOn
: parseInt(args.dependsOn, 10);
log.info(
`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
enableSilentMode();
// Call the core function using the provided tasksPath
// Call the core function
await removeDependency(tasksPath, taskId, dependencyId);
// Restore normal logging

View File

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

View File

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

View File

@@ -4,6 +4,7 @@
*/
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode,
@@ -13,29 +14,16 @@ import {
/**
* 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.
* @returns {Promise<Object>} - Result object with success status and data/error information.
*/
export async function setTaskStatusDirect(args, log) {
// Destructure expected args, including the resolved tasksJsonPath
const { tasksJsonPath, id, status } = args;
try {
log.info(`Setting task status 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 required parameters (id and status)
if (!id) {
// Check required parameters
if (!args.id) {
const errorMessage =
'No task ID specified. Please provide a task ID to update.';
log.error(errorMessage);
@@ -46,7 +34,7 @@ export async function setTaskStatusDirect(args, log) {
};
}
if (!status) {
if (!args.status) {
const errorMessage =
'No status specified. Please provide a new status value.';
log.error(errorMessage);
@@ -57,16 +45,32 @@ export async function setTaskStatusDirect(args, log) {
};
}
// Use the provided path
const tasksPath = tasksJsonPath;
// Get tasks file path
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
const taskId = id;
const newStatus = status;
const taskId = args.id;
const newStatus = args.status;
log.info(`Setting task ${taskId} status to "${newStatus}"`);
// Call the core function with proper silent mode handling
let result;
enableSilentMode(); // Enable silent mode before calling core function
try {
// Call the core function
@@ -75,20 +79,19 @@ export async function setTaskStatusDirect(args, log) {
log.info(`Successfully set task ${taskId} status to ${newStatus}`);
// Return success data
const result = {
result = {
success: true,
data: {
message: `Successfully updated task ${taskId} status to "${newStatus}"`,
taskId,
status: newStatus,
tasksPath: tasksPath // Return the path used
tasksPath
},
fromCache: false // This operation always modifies state and should never be cached
};
return result;
} catch (error) {
log.error(`Error setting task status: ${error.message}`);
return {
result = {
success: false,
error: {
code: 'SET_STATUS_ERROR',
@@ -100,6 +103,8 @@ export async function setTaskStatusDirect(args, log) {
// ALWAYS restore normal logging in finally block
disableSilentMode();
}
return result;
} catch (error) {
// Ensure silent mode is disabled if there was an uncaught error in the outer try block
if (isSilentMode()) {

View File

@@ -6,6 +6,7 @@
import { findTaskById } from '../../../../scripts/modules/utils.js';
import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -15,29 +16,28 @@ import {
* Direct function wrapper for showing task details with error handling and caching.
*
* @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
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/
export async function showTaskDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id } = args;
if (!tasksJsonPath) {
log.error('showTaskDirect called without tasksJsonPath');
let tasksPath;
try {
// Find the tasks path first - needed for cache key and execution
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
code: 'FILE_NOT_FOUND_ERROR',
message: error.message
},
fromCache: false
};
}
// Validate task ID
const taskId = id;
const taskId = args.id;
if (!taskId) {
log.error('Task ID is required');
return {
@@ -50,8 +50,8 @@ export async function showTaskDirect(args, log) {
};
}
// Generate cache key using the provided task path and ID
const cacheKey = `showTask:${tasksJsonPath}:${taskId}`;
// Generate cache key using task path and ID
const cacheKey = `showTask:${tasksPath}:${taskId}`;
// Define the action function to be executed on cache miss
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
enableSilentMode();
log.info(
`Retrieving task details for ID: ${taskId} from ${tasksJsonPath}`
);
log.info(`Retrieving task details for ID: ${taskId} from ${tasksPath}`);
// Read tasks data using the provided path
const data = readJSON(tasksJsonPath);
// Read tasks data
const data = readJSON(tasksPath);
if (!data || !data.tasks) {
disableSilentMode(); // Disable before returning
return {
success: false,
error: {
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);
if (!task) {
disableSilentMode(); // Disable before returning
return {
success: false,
error: {

View File

@@ -8,6 +8,7 @@ import {
enableSilentMode,
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
getAnthropicClientForMCP,
getPerplexityClientForMCP
@@ -16,31 +17,19 @@ import {
/**
* 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} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information.
*/
export async function updateSubtaskByIdDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, id, prompt, research } = args;
try {
log.info(`Updating subtask 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 required parameters (id and prompt)
if (!id) {
// Check required parameters
if (!args.id) {
const errorMessage =
'No subtask ID specified. Please provide a subtask ID to update.';
log.error(errorMessage);
@@ -51,7 +40,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
};
}
if (!prompt) {
if (!args.prompt) {
const errorMessage =
'No prompt specified. Please provide a prompt with information to add to the subtask.';
log.error(errorMessage);
@@ -63,7 +52,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
}
// Validate subtask ID format
const subtaskId = id;
const subtaskId = args.id;
if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') {
const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`;
log.error(errorMessage);
@@ -85,14 +74,24 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
};
}
// Use the provided path
const tasksPath = tasksJsonPath;
// 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
const useResearch = research === true;
const useResearch = args.research === true;
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
@@ -135,7 +134,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
const updatedSubtask = await updateSubtaskById(
tasksPath,
subtaskIdStr,
prompt,
args.prompt,
useResearch,
{
session,

View File

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

View File

@@ -8,6 +8,7 @@ import {
enableSilentMode,
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
getAnthropicClientForMCP,
getPerplexityClientForMCP
@@ -16,31 +17,19 @@ import {
/**
* 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} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information.
*/
export async function updateTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, from, prompt, research } = args;
try {
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'
if (args.id !== undefined && from === undefined) {
if (args.id !== undefined && args.from === undefined) {
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.";
log.error(errorMessage);
@@ -57,7 +46,7 @@ export async function updateTasksDirect(args, log, context = {}) {
}
// Check required parameters
if (!from) {
if (!args.from) {
const errorMessage =
'No from ID specified. Please provide a task ID to start updating from.';
log.error(errorMessage);
@@ -68,7 +57,7 @@ export async function updateTasksDirect(args, log, context = {}) {
};
}
if (!prompt) {
if (!args.prompt) {
const errorMessage =
'No prompt specified. Please provide a prompt with new context for task updates.';
log.error(errorMessage);
@@ -81,10 +70,10 @@ export async function updateTasksDirect(args, log, context = {}) {
// Parse fromId - handle both string and number values
let fromId;
if (typeof from === 'string') {
fromId = parseInt(from, 10);
if (typeof args.from === 'string') {
fromId = parseInt(args.from, 10);
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);
return {
success: false,
@@ -93,11 +82,24 @@ export async function updateTasksDirect(args, log, context = {}) {
};
}
} 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
const useResearch = research === true;
const useResearch = args.research === true;
// Initialize appropriate AI client based on research flag
let aiClient;
@@ -122,25 +124,16 @@ export async function updateTasksDirect(args, log, context = {}) {
}
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 {
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode();
// Execute core updateTasks function, passing the AI client and session
await updateTasks(tasksJsonPath, fromId, prompt, useResearch, {
mcpLog: logWrapper, // Pass the wrapper instead of the raw log object
await updateTasks(tasksPath, fromId, args.prompt, useResearch, {
mcpLog: log,
session
});
@@ -151,7 +144,7 @@ export async function updateTasksDirect(args, log, context = {}) {
data: {
message: `Successfully updated tasks from ID ${fromId} based on the prompt`,
fromId,
tasksPath: tasksJsonPath,
tasksPath,
useResearch
},
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 { findTasksJsonPath } from '../utils/path-utils.js';
import {
enableSilentMode,
disableSilentMode
@@ -12,30 +13,17 @@ import fs from 'fs';
/**
* Validate dependencies in tasks.json
* @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
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
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 {
log.info(`Validating dependencies in tasks: ${tasksJsonPath}`);
log.info(`Validating dependencies in tasks...`);
// Use the provided tasksJsonPath
const tasksPath = tasksJsonPath;
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Verify the file exists
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
enableSilentMode();
// Call the original command function using the provided tasksPath
// Call the original command function
await validateDependenciesCommand(tasksPath);
// 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 { addDependencyDirect } from './direct-functions/add-dependency.js';
import { removeTaskDirect } from './direct-functions/remove-task.js';
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -93,6 +92,5 @@ export {
fixDependenciesDirect,
complexityReportDirect,
addDependencyDirect,
removeTaskDirect,
initializeProjectDirect
removeTaskDirect
};

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
} from './utils.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
@@ -28,57 +27,42 @@ export function registerAddDependencyTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z
.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 {
log.info(
`Adding dependency for task ${args.id} to depend on ${args.dependsOn}`
);
reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Get project root using the utility function
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
// Fallback to args.projectRoot if session didn't provide one
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${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}`
);
}
// Call the direct function with the resolved path
// Call the direct function with the resolved rootFolder
const result = await addDependencyDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
dependsOn: args.dependsOn
projectRoot: rootFolder,
...args
},
log
// Remove context object
log,
{ reportProgress, mcpLog: log, session }
);
reportProgress({ progress: 100 });
// Log result
if (result.success) {
log.info(`Successfully added dependency: ${result.data.message}`);

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -49,57 +48,36 @@ export function registerAddSubtaskTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
skipGenerate: z
.boolean()
.optional()
.describe('Skip regenerating task files'),
projectRoot: z
.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 {
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await addSubtaskDirect(
{
tasksJsonPath: tasksJsonPath,
id: args.id,
taskId: args.taskId,
title: args.title,
description: args.description,
details: args.details,
status: args.status,
dependencies: args.dependencies,
skipGenerate: args.skipGenerate
projectRoot: rootFolder,
...args
},
log
log,
{ reportProgress, mcpLog: log, session }
);
if (result.success) {

View File

@@ -12,7 +12,6 @@ import {
handleApiResult
} from './utils.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
@@ -23,28 +22,7 @@ export function registerAddTaskTool(server) {
name: 'add_task',
description: 'Add a new task using AI',
parameters: z.object({
prompt: z
.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)'),
prompt: z.string().describe('Description of the task to add'),
dependencies: z
.string()
.optional()
@@ -53,60 +31,36 @@ export function registerAddTaskTool(server) {
.string()
.optional()
.describe('Task priority (high, medium, low)'),
file: z
.string()
.optional()
.describe('Path to the tasks file (default: tasks/tasks.json)'),
file: z.string().optional().describe('Path to the tasks file'),
projectRoot: z
.string()
.describe('The directory of the project. Must be an absolute path.'),
.optional()
.describe('Root directory of the project'),
research: z
.boolean()
.optional()
.describe('Whether to use research capabilities for task creation')
}),
execute: async (args, { log, session }) => {
execute: async (args, { log, reportProgress, session }) => {
try {
log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Get project root from session
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
// Call the direct function
const result = await addTaskDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
prompt: args.prompt,
dependencies: args.dependencies,
priority: args.priority,
research: args.research
...args,
projectRoot: rootFolder
},
log,
{ session }
{ reportProgress, session }
);
// Return the result

View File

@@ -10,8 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -35,10 +33,8 @@ export function registerAnalyzeTool(server) {
.describe(
'LLM model to use for analysis (defaults to configured model)'
),
threshold: z.coerce
.number()
.min(1)
.max(10)
threshold: z
.union([z.number(), z.string()])
.optional()
.describe(
'Minimum complexity score to recommend expansion (1-10) (default: 5)'
@@ -46,16 +42,17 @@ export function registerAnalyzeTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
research: z
.boolean()
.optional()
.describe('Use Perplexity AI for research-backed complexity analysis'),
projectRoot: z
.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 }) => {
try {
@@ -63,40 +60,17 @@ export function registerAnalyzeTool(server) {
`Analyzing task complexity with args: ${JSON.stringify(args)}`
);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
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(
{
tasksJsonPath: tasksJsonPath,
outputPath: outputPath,
model: args.model,
threshold: args.threshold,
research: args.research
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -30,58 +29,41 @@ export function registerClearSubtasksTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z
.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, {
message: "Either 'id' or 'all' parameter must be provided",
path: ['id', 'all']
}),
execute: async (args, { log, session }) => {
execute: async (args, { log, session, reportProgress }) => {
try {
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await clearSubtasksDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
all: args.all
projectRoot: rootFolder,
...args
},
log
// Remove context object as clearSubtasksDirect likely doesn't need session/reportProgress
log,
{ reportProgress, mcpLog: log, session }
);
reportProgress({ progress: 100 });
if (result.success) {
log.info(`Subtasks cleared successfully: ${result.data.message}`);
} else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.js';
import { complexityReportDirect } from '../core/task-master-core.js';
import path from 'path';
/**
* Register the complexityReport tool with the MCP server
@@ -29,40 +28,35 @@ export function registerComplexityReportTool(server) {
),
projectRoot: z
.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 {
log.info(
`Getting complexity report with args: ${JSON.stringify(args)}`
);
// await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
// 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(
{
// Pass the explicitly resolved path
reportPath: reportPath
// No other args specific to this tool
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
if (result.success) {
log.info(
`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -44,51 +43,29 @@ export function registerExpandAllTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z
.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 }) => {
try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await expandAllTasksDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
num: args.num,
research: args.research,
prompt: args.prompt,
force: args.force
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

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

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -21,45 +20,37 @@ export function registerFixDependenciesTool(server) {
name: 'fix_dependencies',
description: 'Fix invalid dependencies in tasks automatically',
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
.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 {
log.info(`Fixing dependencies with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await fixDependenciesDirect(
{
tasksJsonPath: tasksJsonPath
projectRoot: rootFolder,
...args
},
log
log,
{ reportProgress, mcpLog: log, session }
);
await reportProgress({ progress: 100 });
if (result.success) {
log.info(`Successfully fixed dependencies: ${result.data.message}`);
} else {

View File

@@ -10,8 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -23,59 +21,40 @@ export function registerGenerateTool(server) {
description:
'Generates individual task files in tasks/ directory based on tasks.json',
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
.string()
.optional()
.describe('Output directory (default: same directory as tasks file)'),
projectRoot: z
.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 {
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${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}`
);
}
// 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(
{
// Pass the explicitly resolved paths
tasksJsonPath: tasksJsonPath,
outputDir: outputDir
// No other args specific to this tool
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
if (result.success) {
log.info(`Successfully generated task files: ${result.data.message}`);
} else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -40,12 +39,15 @@ export function registerShowTaskTool(server) {
description: 'Get detailed information about a specific task',
parameters: z.object({
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
.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.info(
`Session object received in execute: ${JSON.stringify(session)}`
@@ -58,43 +60,26 @@ export function registerShowTaskTool(server) {
`Session object received in execute: ${JSON.stringify(session)}`
); // Use JSON.stringify for better visibility
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
} 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(`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(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id
projectRoot: rootFolder,
...args
},
log
);

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -40,47 +39,33 @@ export function registerListTasksTool(server) {
),
projectRoot: z
.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 {
log.info(`Getting tasks with filters: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await listTasksDirect(
{
tasksJsonPath: tasksJsonPath,
status: args.status,
withSubtasks: args.withSubtasks
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
log.info(
`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}`);
throw error;
}
logger.info('Registered Task Master MCP tools');
}
export default {

View File

@@ -1,93 +1,98 @@
import { z } from 'zod';
import {
createContentResponse,
createErrorResponse,
handleApiResult
} from './utils.js';
import { initializeProjectDirect } from '../core/task-master-core.js';
import { execSync } from 'child_process';
import { createContentResponse, createErrorResponse } from './utils.js'; // Only need response creators
export function registerInitializeProjectTool(server) {
server.addTool({
name: 'initialize_project',
name: 'initialize_project', // snake_case for tool name
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({
projectName: z
.string()
.optional()
.describe(
'The name for the new project. If not provided, prompt the user for it.'
),
.describe('The name for the new project.'),
projectDescription: z
.string()
.optional()
.describe(
'A brief description for the project. If not provided, prompt the user for it.'
),
.describe('A brief description for the project.'),
projectVersion: z
.string()
.optional()
.describe(
"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. User input not needed unless user requests to override."
),
.describe("The initial version for the project (e.g., '0.1.0')."),
authorName: z.string().optional().describe("The author's name."),
skipInstall: z
.boolean()
.optional()
.default(false)
.describe(
'Skip installing dependencies automatically. Never do this unless you are sure the project is already installed.'
),
.describe('Skip installing dependencies automatically.'),
addAliases: z
.boolean()
.optional()
.default(false)
.describe(
'Add shell aliases (tm, taskmaster) to shell config file. User input not needed.'
),
.describe('Add shell aliases (tm, taskmaster) to shell config file.'),
yes: z
.boolean()
.optional()
.default(false)
.describe(
"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: 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.'
)
.describe('Skip prompts and use default values or provided arguments.')
// projectRoot is not needed here as 'init' works on the current directory
}),
execute: async (args, context) => {
const { log } = context;
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'}`
);
execute: async (args, { log }) => {
// Destructure context to get log
try {
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) {
const errorMessage = `Project initialization tool failed: ${error.message || 'Unknown error'}`;
log.error(errorMessage, error);
return createErrorResponse(errorMessage, { details: error.stack });
// Catch errors from execSync or timeouts
const errorMessage = `Project initialization failed: ${error.message}`;
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
} from './utils.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
@@ -22,49 +21,36 @@ export function registerNextTaskTool(server) {
description:
'Find the next task to work on based on dependencies and status',
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
.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 {
log.info(`Finding next task with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await nextTaskDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath
// No other args specific to this tool
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
if (result.success) {
log.info(
`Successfully found next task: ${result.data?.task?.id || 'No available tasks'}`

View File

@@ -5,16 +5,11 @@
import { z } from 'zod';
import {
getProjectRootFromSession,
handleApiResult,
createErrorResponse
createErrorResponse,
getProjectRootFromSession
} from './utils.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
@@ -24,24 +19,25 @@ export function registerParsePRDTool(server) {
server.addTool({
name: 'parse_prd',
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({
input: z
.string()
.optional()
.default('scripts/prd.txt')
.describe('Absolute path to the PRD document file (.txt, .md, etc.)'),
.default('tasks/tasks.json')
.describe(
'Path to the PRD document file (relative to project root or absolute)'
),
numTasks: z
.string()
.optional()
.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
.string()
.optional()
.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
.boolean()
@@ -49,44 +45,26 @@ export function registerParsePRDTool(server) {
.describe('Allow overwriting an existing tasks.json file.'),
projectRoot: z
.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 }) => {
try {
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
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(
{
projectRoot: projectRoot,
input: prdPath,
output: tasksJsonPath,
numTasks: args.numTasks,
force: args.force
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -26,55 +25,38 @@ export function registerRemoveDependencyTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
projectRoot: z
.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 {
log.info(
`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
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await removeDependencyDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
dependsOn: args.dependsOn
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
if (result.success) {
log.info(`Successfully removed dependency: ${result.data.message}`);
} else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -35,58 +34,40 @@ export function registerRemoveSubtaskTool(server) {
file: z
.string()
.optional()
.describe(
'Absolute path to the tasks file (default: tasks/tasks.json)'
),
.describe('Path to the tasks file (default: tasks/tasks.json)'),
skipGenerate: z
.boolean()
.optional()
.describe('Skip regenerating task files'),
projectRoot: z
.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 {
log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
// await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await removeSubtaskDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
convert: args.convert,
skipGenerate: args.skipGenerate
projectRoot: rootFolder,
...args
},
log
log /*, { reportProgress, mcpLog: log, session}*/
);
// await reportProgress({ progress: 100 });
if (result.success) {
log.info(`Subtask removed successfully: ${result.data.message}`);
} else {

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -24,10 +23,13 @@ export function registerRemoveTaskTool(server) {
id: z
.string()
.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
.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
.boolean()
.optional()
@@ -37,40 +39,28 @@ export function registerRemoveTaskTool(server) {
try {
log.info(`Removing task with ID: ${args.id}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Get project root from session
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
} 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}`);
// 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
const result = await removeTaskDirect(
{
tasksJsonPath: tasksJsonPath,
id: args.id
id: args.id,
file: args.file,
projectRoot: rootFolder
},
log
);

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -31,48 +30,31 @@ export function registerSetTaskStatusTool(server) {
.describe(
"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
.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 }) => {
try {
log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Get project root from session
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${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}`
);
}
// Call the direct function with the resolved path
// Call the direct function with the project root
const result = await setTaskStatusDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
status: args.status
...args,
projectRoot: rootFolder
},
log
);

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -32,48 +31,29 @@ export function registerUpdateSubtaskTool(server) {
.boolean()
.optional()
.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
.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 }) => {
try {
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await updateSubtaskByIdDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -32,48 +31,29 @@ export function registerUpdateTaskTool(server) {
.boolean()
.optional()
.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
.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 }) => {
try {
log.info(`Updating task with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await updateTaskByIdDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -34,46 +33,29 @@ export function registerUpdateTool(server) {
.boolean()
.optional()
.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
.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 }) => {
try {
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
// Ensure project root was determined
if (!rootFolder) {
return createErrorResponse(
'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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await updateTasksDirect(
{
tasksJsonPath: tasksJsonPath,
from: args.from,
prompt: args.prompt,
research: args.research
projectRoot: rootFolder,
...args
},
log,
{ session }

View File

@@ -10,7 +10,6 @@ import {
getProjectRootFromSession
} from './utils.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
@@ -22,45 +21,37 @@ export function registerValidateDependenciesTool(server) {
description:
'Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.',
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
.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 {
log.info(`Validating dependencies with args: ${JSON.stringify(args)}`);
await reportProgress({ progress: 0 });
// Get project root from args or session
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
let rootFolder = getProjectRootFromSession(session, log);
if (!rootFolder) {
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
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}`
);
if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
}
const result = await validateDependenciesDirect(
{
tasksJsonPath: tasksJsonPath
projectRoot: rootFolder,
...args
},
log
log,
{ reportProgress, mcpLog: log, session }
);
await reportProgress({ progress: 100 });
if (result.success) {
log.info(
`Successfully validated dependencies: ${result.data.message}`

4
package-lock.json generated
View File

@@ -31,7 +31,9 @@
},
"bin": {
"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": {
"@changesets/changelog-github": "^0.5.1",

View File

@@ -1,12 +1,14 @@
{
"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.",
"main": "index.js",
"type": "module",
"bin": {
"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": {
"test": "node --experimental-vm-modules node_modules/.bin/jest",
@@ -15,10 +17,10 @@
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
"prepare-package": "node scripts/prepare-package.js",
"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",
"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",
"format-check": "prettier --check .",
"format": "prettier --write ."

View File

@@ -1,3 +1,5 @@
#!/usr/bin/env node
/**
* Task Master
* Copyright (c) 2025 Eyal Toledano, Ralph Khreish
@@ -13,6 +15,8 @@
* For the full license text, see the LICENSE file in the root directory.
*/
console.log('Starting task-master-ai...');
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
@@ -23,11 +27,52 @@ import chalk from 'chalk';
import figlet from 'figlet';
import boxen from 'boxen';
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 __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
const LOG_LEVELS = {
debug: 0,
@@ -48,8 +93,6 @@ const warmGradient = gradient(['#fb8b24', '#e36414', '#9a031e']);
// Display a fancy banner
function displayBanner() {
if (isSilentMode()) return;
console.clear();
const bannerText = figlet.textSync('Task Master AI', {
font: 'Standard',
@@ -87,19 +130,16 @@ function log(level, ...args) {
if (LOG_LEVELS[level] >= LOG_LEVEL) {
const icon = icons[level] || '';
// Only output to console if not in silent mode
if (!isSilentMode()) {
if (level === 'error') {
console.error(icon, chalk.red(...args));
} else if (level === 'warn') {
console.warn(icon, chalk.yellow(...args));
} else if (level === 'success') {
console.log(icon, chalk.green(...args));
} else if (level === 'info') {
console.log(icon, chalk.blue(...args));
} else {
console.log(icon, ...args);
}
if (level === 'error') {
console.error(icon, chalk.red(...args));
} else if (level === 'warn') {
console.warn(icon, chalk.yellow(...args));
} else if (level === 'success') {
console.log(icon, chalk.green(...args));
} else if (level === 'info') {
console.log(icon, chalk.blue(...args));
} else {
console.log(icon, ...args);
}
}
@@ -379,43 +419,20 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
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 = {}) {
// Receives options as argument
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner();
}
// Display the banner
displayBanner();
// Debug logging only if not in silent mode
if (!isSilentMode()) {
console.log('===== DEBUG: INITIALIZE PROJECT OPTIONS RECEIVED =====');
console.log('Full options object:', JSON.stringify(options));
console.log('options.yes:', options.yes);
console.log('options.name:', options.name);
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
// If options are provided, use them directly without prompting
if (options.projectName && options.projectDescription) {
const projectName = options.projectName;
const projectDescription = options.projectDescription;
const projectVersion = options.projectVersion || '1.0.0';
const authorName = options.authorName || '';
const dryRun = options.dryRun || false;
const skipInstall = options.skipInstall || false;
const addAliases = options.aliases || false;
const addAliases = options.addAliases || false;
if (dryRun) {
log('info', 'DRY RUN MODE: No files will be modified');
@@ -441,7 +458,6 @@ async function initializeProject(options = {}) {
};
}
// Create structure using determined values
createProjectStructure(
projectName,
projectDescription,
@@ -450,112 +466,120 @@ async function initializeProject(options = {}) {
skipInstall,
addAliases
);
} else {
// Prompting logic (only runs if skipPrompts is false)
log('info', 'Required options not provided, proceeding with prompts.');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
return {
projectName,
projectDescription,
projectVersion,
authorName
};
}
try {
// Prompt user for input...
const projectName = await promptQuestion(
rl,
chalk.cyan('Enter project name: ')
);
const projectDescription = await promptQuestion(
rl,
chalk.cyan('Enter project description: ')
);
const projectVersionInput = await promptQuestion(
rl,
chalk.cyan('Enter project version (default: 1.0.0): ')
); // Use a default for prompt
const authorName = await promptQuestion(
rl,
chalk.cyan('Enter your name: ')
);
const addAliasesInput = await promptQuestion(
rl,
chalk.cyan('Add shell aliases for task-master? (Y/n): ')
);
const addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n';
const projectVersion = projectVersionInput.trim()
? projectVersionInput
: '1.0.0';
// Otherwise, prompt the user for input
// Create readline interface only when needed
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Confirm settings...
console.log('\nProject settings:');
console.log(chalk.blue('Name:'), chalk.white(projectName));
console.log(chalk.blue('Description:'), chalk.white(projectDescription));
console.log(chalk.blue('Version:'), chalk.white(projectVersion));
console.log(
chalk.blue('Author:'),
chalk.white(authorName || 'Not specified')
);
console.log(
chalk.blue(
'Add shell aliases (so you can use "tm" instead of "task-master"):'
),
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
);
try {
const projectName = await promptQuestion(
rl,
chalk.cyan('Enter project name: ')
);
const projectDescription = await promptQuestion(
rl,
chalk.cyan('Enter project description: ')
);
const projectVersionInput = await promptQuestion(
rl,
chalk.cyan('Enter project version (default: 1.0.0): ')
);
const authorName = await promptQuestion(
rl,
chalk.cyan('Enter your name: ')
);
const confirmInput = await promptQuestion(
rl,
chalk.yellow('\nDo you want to continue with these settings? (Y/n): ')
);
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
rl.close();
// Ask about shell aliases
const addAliasesInput = await promptQuestion(
rl,
chalk.cyan('Add shell aliases for task-master? (Y/n): ')
);
const addAliases = addAliasesInput.trim().toLowerCase() !== 'n';
if (!shouldContinue) {
log('info', 'Project initialization cancelled by user');
process.exit(0); // Exit if cancelled
return; // Added return for clarity
// Set default version if not provided
const projectVersion = projectVersionInput.trim()
? projectVersionInput
: '1.0.0';
// Confirm settings
console.log('\nProject settings:');
console.log(chalk.blue('Name:'), chalk.white(projectName));
console.log(chalk.blue('Description:'), chalk.white(projectDescription));
console.log(chalk.blue('Version:'), chalk.white(projectVersion));
console.log(
chalk.blue('Author:'),
chalk.white(authorName || 'Not specified')
);
console.log(
chalk.blue('Add shell aliases:'),
chalk.white(addAliases ? 'Yes' : 'No')
);
const confirmInput = await promptQuestion(
rl,
chalk.yellow('\nDo you want to continue with these settings? (Y/n): ')
);
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
// Close the readline interface
rl.close();
if (!shouldContinue) {
log('info', 'Project initialization cancelled by user');
return null;
}
const dryRun = options.dryRun || false;
const skipInstall = options.skipInstall || false;
if (dryRun) {
log('info', 'DRY RUN MODE: No files will be modified');
log('info', 'Would create/update necessary project files');
if (addAliases) {
log('info', 'Would add shell aliases for task-master');
}
// Still respect dryRun/skipInstall if passed initially even when prompting
const dryRun = options.dryRun || false;
const skipInstall = options.skipInstall || false;
if (dryRun) {
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');
if (addAliasesPrompted) {
log('info', 'Would add shell aliases for task-master');
}
if (!skipInstall) {
log('info', 'Would install dependencies');
}
return {
projectName,
projectDescription,
projectVersion,
authorName,
dryRun: true
};
if (!skipInstall) {
log('info', 'Would install dependencies');
}
// Create structure using prompted values, respecting initial options where relevant
createProjectStructure(
return {
projectName,
projectDescription,
projectVersion,
authorName,
skipInstall, // Use value from initial options
addAliasesPrompted // Use value from prompt
);
} catch (error) {
rl.close();
log('error', `Error during prompting: ${error.message}`); // Use log function
process.exit(1); // Exit on error during prompts
dryRun: true
};
}
// Create the project structure
createProjectStructure(
projectName,
projectDescription,
projectVersion,
authorName,
skipInstall,
addAliases
);
return {
projectName,
projectDescription,
projectVersion,
authorName
};
} catch (error) {
// Make sure to close readline on error
rl.close();
throw error;
}
}
@@ -765,16 +789,14 @@ function createProjectStructure(
}
// Run npm install automatically
if (!isSilentMode()) {
console.log(
boxen(chalk.cyan('Installing dependencies...'), {
padding: 0.5,
margin: 0.5,
borderStyle: 'round',
borderColor: 'blue'
})
);
}
console.log(
boxen(chalk.cyan('Installing dependencies...'), {
padding: 0.5,
margin: 0.5,
borderStyle: 'round',
borderColor: 'blue'
})
);
try {
if (!skipInstall) {
@@ -789,23 +811,21 @@ function createProjectStructure(
}
// Display success message
if (!isSilentMode()) {
console.log(
boxen(
warmGradient.multiline(
figlet.textSync('Success!', { font: 'Standard' })
) +
'\n' +
chalk.green('Project initialized successfully!'),
{
padding: 1,
margin: 1,
borderStyle: 'double',
borderColor: 'green'
}
)
);
}
console.log(
boxen(
warmGradient.multiline(
figlet.textSync('Success!', { font: 'Standard' })
) +
'\n' +
chalk.green('Project initialized successfully!'),
{
padding: 1,
margin: 1,
borderStyle: 'double',
borderColor: 'green'
}
)
);
// Add shell aliases if requested
if (addAliases) {
@@ -813,70 +833,68 @@ function createProjectStructure(
}
// Display next steps in a nice box
if (!isSilentMode()) {
console.log(
boxen(
chalk.cyan.bold('Things you can now do:') +
'\n\n' +
chalk.white('1. ') +
chalk.yellow(
'Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY'
) +
'\n' +
chalk.white('2. ') +
chalk.yellow(
'Discuss your idea with AI, and once ready ask for a PRD using the example_prd.txt file, and save what you get to scripts/PRD.txt'
) +
'\n' +
chalk.white('3. ') +
chalk.yellow(
'Ask Cursor Agent to parse your PRD.txt and generate tasks'
) +
'\n' +
chalk.white(' └─ ') +
chalk.dim('You can also run ') +
chalk.cyan('task-master parse-prd <your-prd-file.txt>') +
'\n' +
chalk.white('4. ') +
chalk.yellow('Ask Cursor to analyze the complexity of your tasks') +
'\n' +
chalk.white('5. ') +
chalk.yellow(
'Ask Cursor which task is next to determine where to start'
) +
'\n' +
chalk.white('6. ') +
chalk.yellow(
'Ask Cursor to expand any complex tasks that are too large or complex.'
) +
'\n' +
chalk.white('7. ') +
chalk.yellow(
'Ask Cursor to set the status of a task, or multiple tasks. Use the task id from the task lists.'
) +
'\n' +
chalk.white('8. ') +
chalk.yellow(
'Ask Cursor to update all tasks from a specific task id based on new learnings or pivots in your project.'
) +
'\n' +
chalk.white('9. ') +
chalk.green.bold('Ship it!') +
'\n\n' +
chalk.dim(
'* Review the README.md file to learn how to use other commands via Cursor Agent.'
),
{
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: 'yellow',
title: 'Getting Started',
titleAlignment: 'center'
}
)
);
}
console.log(
boxen(
chalk.cyan.bold('Things you can now do:') +
'\n\n' +
chalk.white('1. ') +
chalk.yellow(
'Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY'
) +
'\n' +
chalk.white('2. ') +
chalk.yellow(
'Discuss your idea with AI, and once ready ask for a PRD using the example_prd.txt file, and save what you get to scripts/PRD.txt'
) +
'\n' +
chalk.white('3. ') +
chalk.yellow(
'Ask Cursor Agent to parse your PRD.txt and generate tasks'
) +
'\n' +
chalk.white(' └─ ') +
chalk.dim('You can also run ') +
chalk.cyan('task-master parse-prd <your-prd-file.txt>') +
'\n' +
chalk.white('4. ') +
chalk.yellow('Ask Cursor to analyze the complexity of your tasks') +
'\n' +
chalk.white('5. ') +
chalk.yellow(
'Ask Cursor which task is next to determine where to start'
) +
'\n' +
chalk.white('6. ') +
chalk.yellow(
'Ask Cursor to expand any complex tasks that are too large or complex.'
) +
'\n' +
chalk.white('7. ') +
chalk.yellow(
'Ask Cursor to set the status of a task, or multiple tasks. Use the task id from the task lists.'
) +
'\n' +
chalk.white('8. ') +
chalk.yellow(
'Ask Cursor to update all tasks from a specific task id based on new learnings or pivots in your project.'
) +
'\n' +
chalk.white('9. ') +
chalk.green.bold('Ship it!') +
'\n\n' +
chalk.dim(
'* Review the README.md file to learn how to use other commands via Cursor Agent.'
),
{
padding: 1,
margin: 1,
borderStyle: 'round',
borderColor: 'yellow',
title: 'Getting Started',
titleAlignment: 'center'
}
)
);
}
// Function to setup MCP configuration for Cursor integration
@@ -893,14 +911,14 @@ function setupMCPConfiguration(targetDir, projectName) {
const newMCPServer = {
'task-master-ai': {
command: 'npx',
args: ['-y', 'task-master-mcp'],
args: ['-y', 'task-master-mcp-server'],
env: {
ANTHROPIC_API_KEY: 'YOUR_ANTHROPIC_API_KEY',
PERPLEXITY_API_KEY: 'YOUR_PERPLEXITY_API_KEY',
ANTHROPIC_API_KEY: '%ANTHROPIC_API_KEY%',
PERPLEXITY_API_KEY: '%PERPLEXITY_API_KEY%',
MODEL: 'claude-3-7-sonnet-20250219',
PERPLEXITY_MODEL: 'sonar-pro',
MAX_TOKENS: 64000,
TEMPERATURE: 0.2,
TEMPERATURE: 0.3,
DEFAULT_SUBTASKS: 5,
DEFAULT_PRIORITY: 'medium'
}
@@ -909,10 +927,7 @@ function setupMCPConfiguration(targetDir, projectName) {
// Check if mcp.json already exists
if (fs.existsSync(mcpJsonPath)) {
log(
'info',
'MCP configuration file already exists, checking for existing task-master-mcp...'
);
log('info', 'MCP configuration file already exists, updating...');
try {
// Read existing config
const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8'));
@@ -922,23 +937,6 @@ function setupMCPConfiguration(targetDir, projectName) {
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
if (!mcpConfig.mcpServers['task-master-ai']) {
mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];
@@ -987,5 +985,51 @@ function setupMCPConfiguration(targetDir, projectName) {
log('info', 'MCP server will use the installed task-master-ai package');
}
// Ensure necessary functions are exported
export { initializeProject, log }; // Only export what's needed by commands.js
// Run the initialization if this script is executed directly
// 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,86 +873,91 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
* @param {number} expectedCount - Expected number of subtasks
* @param {number} parentTaskId - Parent task ID
* @returns {Array} Parsed subtasks
* @throws {Error} If parsing fails or JSON is invalid
*/
function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
// Set default values for optional parameters
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
const jsonStartIndex = text.indexOf('[');
const jsonEndIndex = text.lastIndexOf(']');
// If no valid JSON array found, throw error
if (
jsonStartIndex === -1 ||
jsonEndIndex === -1 ||
jsonEndIndex < jsonStartIndex
) {
throw new Error('Could not locate valid JSON array in the response');
}
// Extract and parse the JSON
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
let subtasks;
try {
subtasks = JSON.parse(jsonText);
} catch (parseError) {
throw new Error(`Failed to parse JSON: ${parseError.message}`);
}
// Locate JSON array in the text
const jsonStartIndex = text.indexOf('[');
const jsonEndIndex = text.lastIndexOf(']');
// Validate array
if (!Array.isArray(subtasks)) {
throw new Error('Parsed content is not an array');
}
if (
jsonStartIndex === -1 ||
jsonEndIndex === -1 ||
jsonEndIndex < jsonStartIndex
) {
throw new Error('Could not locate valid JSON array in the response');
}
// Log warning if count doesn't match expected
if (expectedCount && subtasks.length !== expectedCount) {
log(
'warn',
`Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`
);
}
// Extract and parse the JSON
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
let subtasks = JSON.parse(jsonText);
// Normalize subtask IDs if they don't match
subtasks = subtasks.map((subtask, index) => {
// Assign the correct ID if it doesn't match
if (!subtask.id || subtask.id !== startId + index) {
// Validate
if (!Array.isArray(subtasks)) {
throw new Error('Parsed content is not an array');
}
// Log warning if count doesn't match expected
if (subtasks.length !== expectedCount) {
log(
'warn',
`Correcting subtask ID from ${subtask.id || 'undefined'} to ${startId + index}`
`Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`
);
subtask.id = startId + index;
}
// Convert dependencies to numbers if they are strings
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
subtask.dependencies = subtask.dependencies.map((dep) => {
return typeof dep === 'string' ? parseInt(dep, 10) : dep;
});
} else {
subtask.dependencies = [];
}
// Normalize subtask IDs if they don't match
subtasks = subtasks.map((subtask, index) => {
// Assign the correct ID if it doesn't match
if (subtask.id !== startId + index) {
log(
'warn',
`Correcting subtask ID from ${subtask.id} to ${startId + index}`
);
subtask.id = startId + index;
}
// Ensure status is 'pending'
subtask.status = 'pending';
// Convert dependencies to numbers if they are strings
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
subtask.dependencies = subtask.dependencies.map((dep) => {
return typeof dep === 'string' ? parseInt(dep, 10) : dep;
});
} else {
subtask.dependencies = [];
}
// Add parentTaskId if provided
if (parentTaskId) {
// Ensure status is 'pending'
subtask.status = 'pending';
// Add parentTaskId
subtask.parentTaskId = parentTaskId;
return subtask;
});
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 subtask;
});
return subtasks;
return fallbackSubtasks;
}
}
/**

View File

@@ -10,9 +10,8 @@ import boxen from 'boxen';
import fs from 'fs';
import https from 'https';
import inquirer from 'inquirer';
import ora from 'ora';
import { CONFIG, log, readJSON, writeJSON } from './utils.js';
import { CONFIG, log, readJSON } from './utils.js';
import {
parsePRD,
updateTasks,
@@ -52,8 +51,6 @@ import {
stopLoadingIndicator
} from './ui.js';
import { initializeProject } from '../init.js';
/**
* Configure and register CLI commands
* @param {Object} program - Commander program instance
@@ -792,27 +789,11 @@ function registerCommands(programInstance) {
// add-task command
programInstance
.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('-p, --prompt <text>', 'Description of the task to add (required)')
.option(
'-p, --prompt <prompt>',
'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>',
'-d, --dependencies <ids>',
'Comma-separated list of task IDs this task depends on'
)
.option(
@@ -820,91 +801,32 @@ function registerCommands(programInstance) {
'Task priority (high, medium, low)',
'medium'
)
.option(
'-r, --research',
'Whether to use research capabilities for task creation'
)
.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 (!options.prompt && !isManualCreation) {
if (!prompt) {
console.error(
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);
}
try {
// Prepare dependencies if provided
let dependencies = [];
if (options.dependencies) {
dependencies = options.dependencies
.split(',')
.map((id) => parseInt(id.trim(), 10));
}
console.log(chalk.blue(`Adding new task with description: "${prompt}"`));
console.log(
chalk.blue(
`Dependencies: ${dependencies.length > 0 ? dependencies.join(', ') : 'None'}`
)
);
console.log(chalk.blue(`Priority: ${priority}`));
// 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(
chalk.blue(
`Creating task with AI using prompt: "${options.prompt}"`
)
);
if (dependencies.length > 0) {
console.log(
chalk.blue(`Dependencies: [${dependencies.join(', ')}]`)
);
}
if (options.priority) {
console.log(chalk.blue(`Priority: ${options.priority}`));
}
}
const newTaskId = await addTask(
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);
}
await addTask(tasksPath, prompt, dependencies, priority);
});
// 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
programInstance
.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...
return programInstance;

View File

@@ -14,8 +14,7 @@ import {
writeJSON,
taskExists,
formatTaskId,
findCycles,
isSilentMode
findCycles
} from './utils.js';
import { displayBanner } from './ui.js';
@@ -321,21 +320,19 @@ async function removeDependency(tasksPath, taskId, dependencyId) {
`Removed dependency: Task ${formattedTaskId} no longer depends on ${formattedDependencyId}`
);
if (!isSilentMode()) {
// Display a more visually appealing success message
console.log(
boxen(
chalk.green(`Successfully removed dependency:\n\n`) +
`Task ${chalk.bold(formattedTaskId)} no longer depends on ${chalk.bold(formattedDependencyId)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1 }
}
)
);
}
// Display a more visually appealing success message
console.log(
boxen(
chalk.green(`Successfully removed dependency:\n\n`) +
`Task ${chalk.bold(formattedTaskId)} no longer depends on ${chalk.bold(formattedDependencyId)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1 }
}
)
);
// Regenerate task files
await generateTaskFiles(tasksPath, 'tasks');
@@ -556,11 +553,8 @@ function cleanupSubtaskDependencies(tasksData) {
* Validate dependencies in task files
* @param {string} tasksPath - Path to tasks.json
*/
async function validateDependenciesCommand(tasksPath, options = {}) {
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner();
}
async function validateDependenciesCommand(tasksPath) {
displayBanner();
log('info', 'Checking for invalid dependencies in task files...');
@@ -665,33 +659,31 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
if (changesDetected) {
log('success', 'Invalid dependencies were removed from tasks.json');
// Show detailed stats in a nice box - only if not in silent mode
if (!isSilentMode()) {
console.log(
boxen(
chalk.green(`Dependency Validation Results:\n\n`) +
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
`${chalk.cyan('Non-existent dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
// Show detailed stats in a nice box
console.log(
boxen(
chalk.green(`Dependency Validation Results:\n\n`) +
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
`${chalk.cyan('Non-existent dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
// Show all warnings in a collapsible list if there are many
if (warnings.length > 0) {
console.log(chalk.yellow('\nDetailed fixes:'));
warnings.forEach((warning) => {
console.log(` ${warning}`);
});
}
// Show all warnings in a collapsible list if there are many
if (warnings.length > 0) {
console.log(chalk.yellow('\nDetailed fixes:'));
warnings.forEach((warning) => {
console.log(` ${warning}`);
});
}
// Regenerate task files to reflect the changes
@@ -703,23 +695,21 @@ async function validateDependenciesCommand(tasksPath, options = {}) {
'No invalid dependencies found - all dependencies are valid'
);
// Show validation summary - only if not in silent mode
if (!isSilentMode()) {
console.log(
boxen(
chalk.green(`All Dependencies Are Valid\n\n`) +
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
}
// Show validation summary
console.log(
boxen(
chalk.green(`All Dependencies Are Valid\n\n`) +
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
}
} catch (error) {
log('error', 'Error validating dependencies:', error);
@@ -757,13 +747,9 @@ function countAllDependencies(tasks) {
/**
* Fixes invalid dependencies in tasks.json
* @param {string} tasksPath - Path to tasks.json
* @param {Object} options - Options object
*/
async function fixDependenciesCommand(tasksPath, options = {}) {
// Only display banner if not in silent mode
if (!isSilentMode()) {
displayBanner();
}
async function fixDependenciesCommand(tasksPath) {
displayBanner();
log('info', 'Checking for and fixing invalid dependencies in tasks.json...');
@@ -1100,47 +1086,42 @@ async function fixDependenciesCommand(tasksPath, options = {}) {
stats.duplicateDependenciesRemoved +
stats.circularDependenciesFixed;
if (!isSilentMode()) {
if (totalFixedAll > 0) {
log('success', `Fixed ${totalFixedAll} dependency issues in total!`);
if (totalFixedAll > 0) {
log('success', `Fixed ${totalFixedAll} dependency issues in total!`);
console.log(
boxen(
chalk.green(`Dependency Fixes Summary:\n\n`) +
`${chalk.cyan('Invalid dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
`${chalk.cyan('Duplicate dependencies removed:')} ${stats.duplicateDependenciesRemoved}\n` +
`${chalk.cyan('Circular dependencies fixed:')} ${stats.circularDependenciesFixed}\n\n` +
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}\n`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
} else {
log(
'success',
'No dependency issues found - all dependencies are valid'
);
console.log(
boxen(
chalk.green(`Dependency Fixes Summary:\n\n`) +
`${chalk.cyan('Invalid dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
`${chalk.cyan('Duplicate dependencies removed:')} ${stats.duplicateDependenciesRemoved}\n` +
`${chalk.cyan('Circular dependencies fixed:')} ${stats.circularDependenciesFixed}\n\n` +
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}\n`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
} else {
log('success', 'No dependency issues found - all dependencies are valid');
console.log(
boxen(
chalk.green(`All Dependencies Are Valid\n\n`) +
`${chalk.cyan('Tasks checked:')} ${data.tasks.length}\n` +
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
}
console.log(
boxen(
chalk.green(`All Dependencies Are Valid\n\n`) +
`${chalk.cyan('Tasks checked:')} ${data.tasks.length}\n` +
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
margin: { top: 1, bottom: 1 }
}
)
);
}
} catch (error) {
log('error', 'Error in fix-dependencies command:', error);

View File

@@ -2711,9 +2711,6 @@ async function expandAllTasks(
}
report(`Expanding all pending tasks with ${numSubtasks} subtasks each...`);
if (useResearch) {
report('Using research-backed AI for more detailed subtasks');
}
// Load tasks
let data;
@@ -2775,7 +2772,6 @@ async function expandAllTasks(
}
let expandedCount = 0;
let expansionErrors = 0;
try {
// Sort tasks by complexity if report exists, otherwise by ID
if (complexityReport && complexityReport.complexityAnalysis) {
@@ -2856,17 +2852,12 @@ async function expandAllTasks(
mcpLog
);
if (
aiResponse &&
aiResponse.subtasks &&
Array.isArray(aiResponse.subtasks) &&
aiResponse.subtasks.length > 0
) {
if (aiResponse && aiResponse.subtasks) {
// Process and add the subtasks to the task
task.subtasks = aiResponse.subtasks.map((subtask, index) => ({
id: index + 1,
title: subtask.title || `Subtask ${index + 1}`,
description: subtask.description || 'No description provided',
title: subtask.title,
description: subtask.description,
status: 'pending',
dependencies: subtask.dependencies || [],
details: subtask.details || ''
@@ -2874,27 +2865,11 @@ async function expandAllTasks(
report(`Added ${task.subtasks.length} subtasks to task ${task.id}`);
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 {
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) {
report(`Error expanding task ${task.id}: ${error.message}`, 'error');
expansionErrors++;
}
// Small delay to prevent rate limiting
@@ -2916,8 +2891,7 @@ async function expandAllTasks(
success: true,
expandedCount,
tasksToExpand: tasksToExpand.length,
expansionErrors,
message: `Successfully expanded ${expandedCount} out of ${tasksToExpand.length} tasks${expansionErrors > 0 ? ` (${expansionErrors} errors)` : ''}`
message: `Successfully expanded ${expandedCount} out of ${tasksToExpand.length} tasks`
};
} catch (error) {
report(`Error expanding tasks: ${error.message}`, 'error');
@@ -3120,7 +3094,7 @@ function clearSubtasks(tasksPath, taskIds) {
/**
* Add a new task using AI
* @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 {string} priority - Task priority
* @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 {string} outputFormat - Output format (text or json)
* @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
*/
async function addTask(
@@ -3138,8 +3111,7 @@ async function addTask(
priority = 'medium',
{ reportProgress, mcpLog, session } = {},
outputFormat = 'text',
customEnv = null,
manualTaskData = null
customEnv = null
) {
let loadingIndicator = null; // Keep indicator variable accessible
@@ -3197,354 +3169,328 @@ 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;
// Create context string for task creation prompt
let contextTasks = '';
if (dependencies.length > 0) {
// Provide context for the dependent tasks
const dependentTasks = data.tasks.filter((t) =>
dependencies.includes(t.id)
);
contextTasks = `\nThis task depends on the following tasks:\n${dependentTasks
.map((t) => `- Task ${t.id}: ${t.title} - ${t.description}`)
.join('\n')}`;
} else {
// Use AI to generate task data
// Create context string for task creation prompt
let contextTasks = '';
if (dependencies.length > 0) {
// Provide context for the dependent tasks
const dependentTasks = data.tasks.filter((t) =>
dependencies.includes(t.id)
);
contextTasks = `\nThis task depends on the following tasks:\n${dependentTasks
.map((t) => `- Task ${t.id}: ${t.title} - ${t.description}`)
.join('\n')}`;
} else {
// Provide a few recent tasks as context
const recentTasks = [...data.tasks]
.sort((a, b) => b.id - a.id)
.slice(0, 3);
contextTasks = `\nRecent tasks in the project:\n${recentTasks
.map((t) => `- Task ${t.id}: ${t.title} - ${t.description}`)
.join('\n')}`;
}
// Start the loading indicator - only for text mode
if (outputFormat === 'text') {
loadingIndicator = startLoadingIndicator(
'Generating new task with Claude AI...'
);
}
try {
// Import the AI services - explicitly importing here to avoid circular dependencies
const {
_handleAnthropicStream,
_buildAddTaskPrompt,
parseTaskJsonResponse,
getAvailableAIModel
} = await import('./ai-services.js');
// Initialize model state variables
let claudeOverloaded = false;
let modelAttempts = 0;
const maxModelAttempts = 2; // Try up to 2 models before giving up
let aiGeneratedTaskData = null;
// Loop through model attempts
while (modelAttempts < maxModelAttempts && !aiGeneratedTaskData) {
modelAttempts++; // Increment attempt counter
const isLastAttempt = modelAttempts >= maxModelAttempts;
let modelType = null; // Track which model we're using
try {
// Get the best available model based on our current state
const result = getAvailableAIModel({
claudeOverloaded,
requiresResearch: false // We're not using the research flag here
});
modelType = result.type;
const client = result.client;
log(
'info',
`Attempt ${modelAttempts}/${maxModelAttempts}: Generating task using ${modelType}`
);
// Update loading indicator text - only for text output
if (outputFormat === 'text') {
if (loadingIndicator) {
stopLoadingIndicator(loadingIndicator); // Stop previous indicator
}
loadingIndicator = startLoadingIndicator(
`Attempt ${modelAttempts}: Using ${modelType.toUpperCase()}...`
);
}
// Build the prompts using the helper
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(
prompt,
contextTasks,
{ newTaskId }
);
if (modelType === 'perplexity') {
// Use Perplexity AI
const perplexityModel =
process.env.PERPLEXITY_MODEL ||
session?.env?.PERPLEXITY_MODEL ||
'sonar-pro';
const response = await client.chat.completions.create({
model: perplexityModel,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
],
temperature: parseFloat(
process.env.TEMPERATURE ||
session?.env?.TEMPERATURE ||
CONFIG.temperature
),
max_tokens: parseInt(
process.env.MAX_TOKENS ||
session?.env?.MAX_TOKENS ||
CONFIG.maxTokens
)
});
const responseText = response.choices[0].message.content;
aiGeneratedTaskData = parseTaskJsonResponse(responseText);
} else {
// Use Claude (default)
// Prepare API parameters
const apiParams = {
model:
session?.env?.ANTHROPIC_MODEL ||
CONFIG.model ||
customEnv?.ANTHROPIC_MODEL,
max_tokens:
session?.env?.MAX_TOKENS ||
CONFIG.maxTokens ||
customEnv?.MAX_TOKENS,
temperature:
session?.env?.TEMPERATURE ||
CONFIG.temperature ||
customEnv?.TEMPERATURE,
system: systemPrompt,
messages: [{ role: 'user', content: userPrompt }]
};
// Call the streaming API using our helper
try {
const fullResponse = await _handleAnthropicStream(
client,
apiParams,
{ reportProgress, mcpLog },
outputFormat === 'text' // CLI mode flag
);
log(
'debug',
`Streaming response length: ${fullResponse.length} characters`
);
// Parse the response using our helper
aiGeneratedTaskData = parseTaskJsonResponse(fullResponse);
} catch (streamError) {
// Process stream errors explicitly
log('error', `Stream error: ${streamError.message}`);
// Check if this is an overload error
let isOverload = false;
// Check 1: SDK specific property
if (streamError.type === 'overloaded_error') {
isOverload = true;
}
// Check 2: Check nested error property
else if (streamError.error?.type === 'overloaded_error') {
isOverload = true;
}
// Check 3: Check status code
else if (
streamError.status === 429 ||
streamError.status === 529
) {
isOverload = true;
}
// Check 4: Check message string
else if (
streamError.message?.toLowerCase().includes('overloaded')
) {
isOverload = true;
}
if (isOverload) {
claudeOverloaded = true;
log(
'warn',
'Claude overloaded. Will attempt fallback model if available.'
);
// Throw to continue to next model attempt
throw new Error('Claude overloaded');
} else {
// Re-throw non-overload errors
throw streamError;
}
}
}
// If we got here without errors and have task data, we're done
if (aiGeneratedTaskData) {
log(
'info',
`Successfully generated task data using ${modelType} on attempt ${modelAttempts}`
);
break;
}
} catch (modelError) {
const failedModel = modelType || 'unknown model';
log(
'warn',
`Attempt ${modelAttempts} failed using ${failedModel}: ${modelError.message}`
);
// Continue to next attempt if we have more attempts and this was specifically an overload error
const wasOverload = modelError.message
?.toLowerCase()
.includes('overload');
if (wasOverload && !isLastAttempt) {
if (modelType === 'claude') {
claudeOverloaded = true;
log('info', 'Will attempt with Perplexity AI next');
}
continue; // Continue to next attempt
} else if (isLastAttempt) {
log(
'error',
`Final attempt (${modelAttempts}/${maxModelAttempts}) failed. No fallback possible.`
);
throw modelError; // Re-throw on last attempt
} else {
throw modelError; // Re-throw for non-overload errors
}
}
}
// If we don't have task data after all attempts, throw an error
if (!aiGeneratedTaskData) {
throw new Error(
'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;
}
// Provide a few recent tasks as context
const recentTasks = [...data.tasks]
.sort((a, b) => b.id - a.id)
.slice(0, 3);
contextTasks = `\nRecent tasks in the project:\n${recentTasks
.map((t) => `- Task ${t.id}: ${t.title} - ${t.description}`)
.join('\n')}`;
}
// Create the new task object
const newTask = {
id: newTaskId,
title: taskData.title,
description: taskData.description,
details: taskData.details || '',
testStrategy: taskData.testStrategy || '',
status: 'pending',
dependencies: dependencies,
priority: priority
};
// Add the task to the tasks array
data.tasks.push(newTask);
// Write the updated tasks to the file
writeJSON(tasksPath, data);
// Generate markdown task files
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)
// Start the loading indicator - only for text mode
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
console.log(
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:') +
'\n' +
chalk.cyan(
`1. Run ${chalk.yellow(`task-master show ${newTaskId}`)} to see complete task details`
) +
'\n' +
chalk.cyan(
`2. Run ${chalk.yellow(`task-master set-status --id=${newTaskId} --status=in-progress`)} to start working on it`
) +
'\n' +
chalk.cyan(
`3. Run ${chalk.yellow(`task-master expand --id=${newTaskId}`)} to break it down into subtasks`
),
{ padding: 1, borderColor: 'green', borderStyle: 'round' }
)
loadingIndicator = startLoadingIndicator(
'Generating new task with Claude AI...'
);
}
// Return the new task ID
return newTaskId;
} catch (error) {
// Stop any loading indicator
if (outputFormat === 'text' && loadingIndicator) {
stopLoadingIndicator(loadingIndicator);
}
try {
// Import the AI services - explicitly importing here to avoid circular dependencies
const {
_handleAnthropicStream,
_buildAddTaskPrompt,
parseTaskJsonResponse,
getAvailableAIModel
} = await import('./ai-services.js');
log('error', `Error adding task: ${error.message}`);
if (outputFormat === 'text') {
console.error(chalk.red(`Error: ${error.message}`));
// Initialize model state variables
let claudeOverloaded = false;
let modelAttempts = 0;
const maxModelAttempts = 2; // Try up to 2 models before giving up
let taskData = null;
// Loop through model attempts
while (modelAttempts < maxModelAttempts && !taskData) {
modelAttempts++; // Increment attempt counter
const isLastAttempt = modelAttempts >= maxModelAttempts;
let modelType = null; // Track which model we're using
try {
// Get the best available model based on our current state
const result = getAvailableAIModel({
claudeOverloaded,
requiresResearch: false // We're not using the research flag here
});
modelType = result.type;
const client = result.client;
log(
'info',
`Attempt ${modelAttempts}/${maxModelAttempts}: Generating task using ${modelType}`
);
// Update loading indicator text - only for text output
if (outputFormat === 'text') {
if (loadingIndicator) {
stopLoadingIndicator(loadingIndicator); // Stop previous indicator
}
loadingIndicator = startLoadingIndicator(
`Attempt ${modelAttempts}: Using ${modelType.toUpperCase()}...`
);
}
// Build the prompts using the helper
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(
prompt,
contextTasks,
{ newTaskId }
);
if (modelType === 'perplexity') {
// Use Perplexity AI
const perplexityModel =
process.env.PERPLEXITY_MODEL ||
session?.env?.PERPLEXITY_MODEL ||
'sonar-pro';
const response = await client.chat.completions.create({
model: perplexityModel,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
],
temperature: parseFloat(
process.env.TEMPERATURE ||
session?.env?.TEMPERATURE ||
CONFIG.temperature
),
max_tokens: parseInt(
process.env.MAX_TOKENS ||
session?.env?.MAX_TOKENS ||
CONFIG.maxTokens
)
});
const responseText = response.choices[0].message.content;
taskData = parseTaskJsonResponse(responseText);
} else {
// Use Claude (default)
// Prepare API parameters
const apiParams = {
model:
session?.env?.ANTHROPIC_MODEL ||
CONFIG.model ||
customEnv?.ANTHROPIC_MODEL,
max_tokens:
session?.env?.MAX_TOKENS ||
CONFIG.maxTokens ||
customEnv?.MAX_TOKENS,
temperature:
session?.env?.TEMPERATURE ||
CONFIG.temperature ||
customEnv?.TEMPERATURE,
system: systemPrompt,
messages: [{ role: 'user', content: userPrompt }]
};
// Call the streaming API using our helper
try {
const fullResponse = await _handleAnthropicStream(
client,
apiParams,
{ reportProgress, mcpLog },
outputFormat === 'text' // CLI mode flag
);
log(
'debug',
`Streaming response length: ${fullResponse.length} characters`
);
// Parse the response using our helper
taskData = parseTaskJsonResponse(fullResponse);
} catch (streamError) {
// Process stream errors explicitly
log('error', `Stream error: ${streamError.message}`);
// Check if this is an overload error
let isOverload = false;
// Check 1: SDK specific property
if (streamError.type === 'overloaded_error') {
isOverload = true;
}
// Check 2: Check nested error property
else if (streamError.error?.type === 'overloaded_error') {
isOverload = true;
}
// Check 3: Check status code
else if (
streamError.status === 429 ||
streamError.status === 529
) {
isOverload = true;
}
// Check 4: Check message string
else if (
streamError.message?.toLowerCase().includes('overloaded')
) {
isOverload = true;
}
if (isOverload) {
claudeOverloaded = true;
log(
'warn',
'Claude overloaded. Will attempt fallback model if available.'
);
// Throw to continue to next model attempt
throw new Error('Claude overloaded');
} else {
// Re-throw non-overload errors
throw streamError;
}
}
}
// If we got here without errors and have task data, we're done
if (taskData) {
log(
'info',
`Successfully generated task data using ${modelType} on attempt ${modelAttempts}`
);
break;
}
} catch (modelError) {
const failedModel = modelType || 'unknown model';
log(
'warn',
`Attempt ${modelAttempts} failed using ${failedModel}: ${modelError.message}`
);
// Continue to next attempt if we have more attempts and this was specifically an overload error
const wasOverload = modelError.message
?.toLowerCase()
.includes('overload');
if (wasOverload && !isLastAttempt) {
if (modelType === 'claude') {
claudeOverloaded = true;
log('info', 'Will attempt with Perplexity AI next');
}
continue; // Continue to next attempt
} else if (isLastAttempt) {
log(
'error',
`Final attempt (${modelAttempts}/${maxModelAttempts}) failed. No fallback possible.`
);
throw modelError; // Re-throw on last attempt
} else {
throw modelError; // Re-throw for non-overload errors
}
}
}
// If we don't have task data after all attempts, throw an error
if (!taskData) {
throw new Error(
'Failed to generate task data after all model attempts'
);
}
// Create the new task object
const newTask = {
id: newTaskId,
title: taskData.title,
description: taskData.description,
status: 'pending',
dependencies: dependencies,
priority: priority,
details: taskData.details || '',
testStrategy:
taskData.testStrategy ||
'Manually verify the implementation works as expected.'
};
// Add the new task to the tasks array
data.tasks.push(newTask);
// 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);
// Only show success messages for text mode (CLI)
if (outputFormat === 'text') {
// 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(
boxen(
chalk.white.bold('Next Steps:') +
'\n\n' +
`${chalk.cyan('1.')} Run ${chalk.yellow('task-master generate')} to update task files\n` +
`${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`,
{
padding: 1,
borderColor: 'cyan',
borderStyle: 'round',
margin: { top: 1 }
}
)
);
}
return newTaskId;
} catch (error) {
// Log the specific error during generation/processing
log('error', 'Error generating or processing task:', error.message);
// Re-throw the error to be caught by the outer catch block
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
}
}
throw error;
} 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');
}
let responseText;
// Call the AI - with research if requested
if (useResearch && perplexity) {
if (mcpLog) {
@@ -5689,7 +5633,8 @@ async function getSubtasksFromAI(
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 {
// Use regular Claude
if (mcpLog) {
@@ -5697,46 +5642,14 @@ async function getSubtasksFromAI(
}
// Call the streaming API
responseText = await _handleAnthropicStream(
const responseText = await _handleAnthropicStream(
client,
apiParams,
{ mcpLog, silentMode: isSilentMode() },
!isSilentMode()
);
}
// Ensure we have a valid response
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.'
};
return parseSubtasksFromText(responseText);
}
} catch (error) {
if (mcpLog) {
@@ -5744,13 +5657,7 @@ async function getSubtasksFromAI(
} else {
log('error', `Error generating subtasks: ${error.message}`);
}
// Return error information instead of fallback subtasks
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.'
};
throw error;
}
}

View File

@@ -7,9 +7,6 @@ import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
// Global silent mode flag
let silentMode = false;
// Configuration and constants
const CONFIG = {
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
};
// Global silent mode flag
let silentMode = false;
// Set up logging based on log level
const LOG_LEVELS = {
debug: 0,
@@ -32,14 +32,6 @@ const LOG_LEVELS = {
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
*/
@@ -69,7 +61,7 @@ function isSilentMode() {
*/
function log(level, ...args) {
// Immediately return if silentMode is enabled
if (isSilentMode()) {
if (silentMode) {
return;
}
@@ -416,6 +408,5 @@ export {
detectCamelCaseFlags,
enableSilentMode,
disableSilentMode,
isSilentMode,
getTaskManager
isSilentMode
};

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",
"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"
},
{
"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,
disableSilentMode: mockDisableSilentMode,
CONFIG: {
model: 'claude-3-7-sonnet-20250219',
model: 'claude-3-sonnet-20240229',
maxTokens: 64000,
temperature: 0.2,
defaultSubtasks: 5

View File

@@ -7,16 +7,13 @@
// Mock environment variables
process.env.MODEL = 'sonar-pro';
process.env.MAX_TOKENS = '64000';
process.env.TEMPERATURE = '0.2';
process.env.TEMPERATURE = '0.4';
process.env.DEBUG = 'false';
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.PROJECT_NAME = 'Test Project';
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
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]);
});
test('should throw an error for empty text', () => {
test('should create fallback subtasks for empty text', () => {
const emptyText = '';
expect(() => parseSubtasksFromText(emptyText, 1, 2, 5)).toThrow(
'Empty text provided, cannot parse subtasks'
);
const result = parseSubtasksFromText(emptyText, 1, 2, 5);
// 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', () => {
@@ -255,12 +272,29 @@ These subtasks will help you implement the parent task efficiently.`;
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`;
expect(() => parseSubtasksFromText(text, 1, 2, 5)).toThrow(
'Could not locate valid JSON array in the response'
);
const result = parseSubtasksFromText(text, 1, 2, 5);
// 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 {
sampleTasks,
emptySampleTasks
} from '../../tests/fixtures/sample-tasks.js';
// Mock functions that need jest.fn methods
const mockParsePRD = jest.fn().mockResolvedValue(undefined);
@@ -643,240 +639,6 @@ describe('Commands Module', () => {
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

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
const tasksPath = 'tasks/tasks.json';
const reportPath = 'scripts/task-complexity-report.json';
@@ -502,7 +502,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: false };
// Act
await testAnalyzeTaskComplexity(options);
await taskManager.analyzeTaskComplexity(options);
// Assert
expect(mockCallClaude).toHaveBeenCalled();
@@ -518,7 +518,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: true };
// Act
await testAnalyzeTaskComplexity(options);
await taskManager.analyzeTaskComplexity(options);
// Assert
expect(mockCallPerplexity).toHaveBeenCalled();
@@ -534,7 +534,7 @@ describe('Task Manager Module', () => {
const options = { ...baseOptions, research: false };
// Act
await testAnalyzeTaskComplexity(options);
await taskManager.analyzeTaskComplexity(options);
// Assert
expect(mockReadJSON).toHaveBeenCalledWith(tasksPath);
@@ -543,9 +543,7 @@ describe('Task Manager Module', () => {
expect(mockWriteJSON).toHaveBeenCalledWith(
reportPath,
expect.objectContaining({
complexityAnalysis: expect.arrayContaining([
expect.objectContaining({ taskId: 1 })
])
tasks: expect.arrayContaining([expect.objectContaining({ id: 1 })])
})
);
expect(mockLog).toHaveBeenCalledWith(
@@ -556,71 +554,50 @@ describe('Task Manager Module', () => {
test('should handle and fix malformed JSON string response (Claude)', async () => {
// Arrange
const malformedJsonResponse = {
tasks: [{ id: 1, complexity: 3 }]
};
const malformedJsonResponse = `{"tasks": [{"id": 1, "complexity": 3, "subtaskCount: 2}]}`;
mockCallClaude.mockResolvedValueOnce(malformedJsonResponse);
const options = { ...baseOptions, research: false };
// Act
await testAnalyzeTaskComplexity(options);
await taskManager.analyzeTaskComplexity(options);
// Assert
expect(mockCallClaude).toHaveBeenCalled();
expect(mockCallPerplexity).not.toHaveBeenCalled();
expect(mockWriteJSON).toHaveBeenCalled();
expect(mockLog).toHaveBeenCalledWith(
'warn',
expect.stringContaining('Malformed JSON')
);
});
test('should handle missing tasks in the response (Claude)', async () => {
// Arrange
const incompleteResponse = { tasks: [sampleApiResponse.tasks[0]] };
mockCallClaude.mockResolvedValueOnce(incompleteResponse);
const missingTaskResponse = {
tasks: [sampleApiResponse.tasks[1], sampleApiResponse.tasks[2]]
};
mockCallClaude.mockResolvedValueOnce(missingTaskResponse);
const options = { ...baseOptions, research: false };
// Act
await testAnalyzeTaskComplexity(options);
await taskManager.analyzeTaskComplexity(options);
// Assert
expect(mockCallClaude).toHaveBeenCalled();
expect(mockCallClaude).toHaveBeenCalledTimes(2);
expect(mockCallPerplexity).not.toHaveBeenCalled();
expect(mockWriteJSON).toHaveBeenCalled();
});
// Add a new test specifically for threshold handling
test('should handle different threshold parameter types correctly', async () => {
// Test with string threshold
let options = { ...baseOptions, threshold: '7' };
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();
expect(mockWriteJSON).toHaveBeenCalledWith(
reportPath,
expect.objectContaining({
tasks: expect.arrayContaining([
expect.objectContaining({ id: 1 }),
expect.objectContaining({ id: 2 }),
expect.objectContaining({ id: 3 })
])
})
);
});
});
@@ -3101,68 +3078,3 @@ describe.skip('updateSubtaskById function', () => {
// 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;
}
};