Compare commits

..

1 Commits

Author SHA1 Message Date
Ralph Khreish
641a43c7bc chore: revamp README 2025-04-09 00:15:57 +02:00
139 changed files with 35733 additions and 40115 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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -14,7 +14,7 @@ permissions:
contents: read contents: read
jobs: jobs:
setup: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -24,55 +24,21 @@ jobs:
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'npm' cache: "npm"
- name: Install Dependencies
id: install
run: npm ci
timeout-minutes: 2
- name: Cache node_modules - name: Cache node_modules
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: node_modules path: |
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }} node_modules
*/*/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
format-check: - name: Install Dependencies
needs: setup run: npm ci
runs-on: ubuntu-latest timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Restore node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Format Check
run: npm run format-check
env:
FORCE_COLOR: 1
test:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Restore node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Run Tests - name: Run Tests
run: | run: |
@@ -81,13 +47,13 @@ jobs:
NODE_ENV: test NODE_ENV: test
CI: true CI: true
FORCE_COLOR: 1 FORCE_COLOR: 1
timeout-minutes: 10 timeout-minutes: 15
- name: Upload Test Results - name: Upload Test Results
if: always() if: always()
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: test-results name: test-results-node
path: | path: |
test-results test-results
coverage coverage

View File

@@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'npm' cache: "npm"
- name: Cache node_modules - name: Cache node_modules
uses: actions/cache@v4 uses: actions/cache@v4

View File

@@ -1,7 +0,0 @@
# Ignore artifacts:
build
coverage
.changeset
tasks
package-lock.json
tests/fixture/*.json

View File

@@ -1,11 +0,0 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}

View File

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

View File

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

90
LICENSE.md Normal file
View File

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

View File

@@ -58,7 +58,6 @@ This will prompt you for project details and set up a new project with the neces
### Important Notes ### Important Notes
1. **ES Modules Configuration:** 1. **ES Modules Configuration:**
- This project uses ES Modules (ESM) instead of CommonJS. - This project uses ES Modules (ESM) instead of CommonJS.
- This is set via `"type": "module"` in your package.json. - This is set via `"type": "module"` in your package.json.
- Use `import/export` syntax instead of `require()`. - Use `import/export` syntax instead of `require()`.
@@ -146,7 +145,7 @@ To enable enhanced task management capabilities directly within Cursor using the
4. Configure with the following details: 4. Configure with the following details:
- Name: "Task Master" - Name: "Task Master"
- Type: "Command" - Type: "Command"
- Command: "npx -y task-master-ai" - Command: "npx -y --package task-master-ai task-master-mcp"
5. Save the settings 5. Save the settings
Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience. Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience.

View File

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

View File

@@ -21,11 +21,9 @@ In an AI-driven development process—particularly with tools like [Cursor](http
The script can be configured through environment variables in a `.env` file at the root of the project: The script can be configured through environment variables in a `.env` file at the root of the project:
### Required Configuration ### Required Configuration
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude - `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
### Optional Configuration ### Optional Configuration
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219") - `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000) - `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
- `TEMPERATURE`: Temperature for model responses (default: 0.7) - `TEMPERATURE`: Temperature for model responses (default: 0.7)
@@ -40,10 +38,9 @@ The script can be configured through environment variables in a `.env` file at t
## How It Works ## How It Works
1. **`tasks.json`**: 1. **`tasks.json`**:
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.). - The `meta` field can store additional info like the project's name, version, or reference to the PRD.
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
- Tasks can have `subtasks` for more detailed implementation steps. - Tasks can have `subtasks` for more detailed implementation steps.
- Dependencies are displayed with status indicators (✅ for completed, ⏱️ for pending) to easily track progress. - Dependencies are displayed with status indicators (✅ for completed, ⏱️ for pending) to easily track progress.
@@ -53,7 +50,7 @@ The script can be configured through environment variables in a `.env` file at t
```bash ```bash
# If installed globally # If installed globally
task-master [command] [options] task-master [command] [options]
# If using locally within the project # If using locally within the project
node scripts/dev.js [command] [options] node scripts/dev.js [command] [options]
``` ```
@@ -114,7 +111,6 @@ task-master update --file=custom-tasks.json --from=5 --prompt="Change database f
``` ```
Notes: Notes:
- The `--prompt` parameter is required and should explain the changes or new context - The `--prompt` parameter is required and should explain the changes or new context
- Only tasks that aren't marked as 'done' will be updated - Only tasks that aren't marked as 'done' will be updated
- Tasks with ID >= the specified --from value will be updated - Tasks with ID >= the specified --from value will be updated
@@ -138,7 +134,6 @@ task-master set-status --id=1,2,3 --status=done
``` ```
Notes: Notes:
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well - When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted - Common status values are 'done', 'pending', and 'deferred', but any string is accepted
- You can specify multiple task IDs by separating them with commas - You can specify multiple task IDs by separating them with commas
@@ -188,7 +183,6 @@ task-master clear-subtasks --all
``` ```
Notes: Notes:
- After clearing subtasks, task files are automatically regenerated - After clearing subtasks, task files are automatically regenerated
- This is useful when you want to regenerate subtasks with a different approach - This is useful when you want to regenerate subtasks with a different approach
- Can be combined with the `expand` command to immediately generate new subtasks - Can be combined with the `expand` command to immediately generate new subtasks
@@ -204,7 +198,6 @@ The script integrates with two AI services:
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude. The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
To use the Perplexity integration: To use the Perplexity integration:
1. Obtain a Perplexity API key 1. Obtain a Perplexity API key
2. Add `PERPLEXITY_API_KEY` to your `.env` file 2. Add `PERPLEXITY_API_KEY` to your `.env` file
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online") 3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
@@ -213,7 +206,6 @@ To use the Perplexity integration:
## Logging ## Logging
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable: The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
- `debug`: Detailed information, typically useful for troubleshooting - `debug`: Detailed information, typically useful for troubleshooting
- `info`: Confirmation that things are working as expected (default) - `info`: Confirmation that things are working as expected (default)
- `warn`: Warning messages that don't prevent execution - `warn`: Warning messages that don't prevent execution
@@ -236,20 +228,17 @@ task-master remove-dependency --id=<id> --depends-on=<id>
These commands: These commands:
1. **Allow precise dependency management**: 1. **Allow precise dependency management**:
- Add dependencies between tasks with automatic validation - Add dependencies between tasks with automatic validation
- Remove dependencies when they're no longer needed - Remove dependencies when they're no longer needed
- Update task files automatically after changes - Update task files automatically after changes
2. **Include validation checks**: 2. **Include validation checks**:
- Prevent circular dependencies (a task depending on itself) - Prevent circular dependencies (a task depending on itself)
- Prevent duplicate dependencies - Prevent duplicate dependencies
- Verify that both tasks exist before adding/removing dependencies - Verify that both tasks exist before adding/removing dependencies
- Check if dependencies exist before attempting to remove them - Check if dependencies exist before attempting to remove them
3. **Provide clear feedback**: 3. **Provide clear feedback**:
- Success messages confirm when dependencies are added/removed - Success messages confirm when dependencies are added/removed
- Error messages explain why operations failed (if applicable) - Error messages explain why operations failed (if applicable)
@@ -274,7 +263,6 @@ task-master validate-dependencies --file=custom-tasks.json
``` ```
This command: This command:
- Scans all tasks and subtasks for non-existent dependencies - Scans all tasks and subtasks for non-existent dependencies
- Identifies potential self-dependencies (tasks referencing themselves) - Identifies potential self-dependencies (tasks referencing themselves)
- Reports all found issues without modifying files - Reports all found issues without modifying files
@@ -296,7 +284,6 @@ task-master fix-dependencies --file=custom-tasks.json
``` ```
This command: This command:
1. **Validates all dependencies** across tasks and subtasks 1. **Validates all dependencies** across tasks and subtasks
2. **Automatically removes**: 2. **Automatically removes**:
- References to non-existent tasks and subtasks - References to non-existent tasks and subtasks
@@ -334,7 +321,6 @@ task-master analyze-complexity --research
``` ```
Notes: Notes:
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag) - The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
- Tasks are scored on a scale of 1-10 - Tasks are scored on a scale of 1-10
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration - Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
@@ -359,35 +345,33 @@ task-master expand --id=8 --num=5 --prompt="Custom prompt"
``` ```
When a complexity report exists: When a complexity report exists:
- The `expand` command will use the recommended subtask count from the report (unless overridden) - The `expand` command will use the recommended subtask count from the report (unless overridden)
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided) - It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
- When using `--all`, tasks are sorted by complexity score (highest first) - When using `--all`, tasks are sorted by complexity score (highest first)
- The `--research` flag is preserved from the complexity analysis to expansion - The `--research` flag is preserved from the complexity analysis to expansion
The output report structure is: The output report structure is:
```json ```json
{ {
"meta": { "meta": {
"generatedAt": "2023-06-15T12:34:56.789Z", "generatedAt": "2023-06-15T12:34:56.789Z",
"tasksAnalyzed": 20, "tasksAnalyzed": 20,
"thresholdScore": 5, "thresholdScore": 5,
"projectName": "Your Project Name", "projectName": "Your Project Name",
"usedResearch": true "usedResearch": true
}, },
"complexityAnalysis": [ "complexityAnalysis": [
{ {
"taskId": 8, "taskId": 8,
"taskTitle": "Develop Implementation Drift Handling", "taskTitle": "Develop Implementation Drift Handling",
"complexityScore": 9.5, "complexityScore": 9.5,
"recommendedSubtasks": 6, "recommendedSubtasks": 6,
"expansionPrompt": "Create subtasks that handle detecting...", "expansionPrompt": "Create subtasks that handle detecting...",
"reasoning": "This task requires sophisticated logic...", "reasoning": "This task requires sophisticated logic...",
"expansionCommand": "task-master expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research" "expansionCommand": "task-master expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
} },
// More tasks sorted by complexity score (highest first) // More tasks sorted by complexity score (highest first)
] ]
} }
``` ```
@@ -454,4 +438,4 @@ This command:
- Commands for working with subtasks - Commands for working with subtasks
- For subtasks, provides a link to view the parent task - For subtasks, provides a link to view the parent task
This command is particularly useful when you need to examine a specific task in detail before implementing it or when you want to check the status and details of a particular task. This command is particularly useful when you need to examine a specific task in detail before implementing it or when you want to check the status and details of a particular task.

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

@@ -44,36 +44,30 @@ const initScriptPath = resolve(__dirname, '../scripts/init.js');
// Helper function to run dev.js with arguments // Helper function to run dev.js with arguments
function runDevScript(args) { function runDevScript(args) {
// Debug: Show the transformed arguments when DEBUG=1 is set // Debug: Show the transformed arguments when DEBUG=1 is set
if (process.env.DEBUG === '1') { if (process.env.DEBUG === '1') {
console.error('\nDEBUG - CLI Wrapper Analysis:'); console.error('\nDEBUG - CLI Wrapper Analysis:');
console.error('- Original command: ' + process.argv.join(' ')); console.error('- Original command: ' + process.argv.join(' '));
console.error('- Transformed args: ' + args.join(' ')); console.error('- Transformed args: ' + args.join(' '));
console.error( console.error('- dev.js will receive: node ' + devScriptPath + ' ' + args.join(' ') + '\n');
'- dev.js will receive: node ' + }
devScriptPath +
' ' + // For testing: If TEST_MODE is set, just print args and exit
args.join(' ') + if (process.env.TEST_MODE === '1') {
'\n' console.log('Would execute:');
); console.log(`node ${devScriptPath} ${args.join(' ')}`);
} process.exit(0);
return;
// For testing: If TEST_MODE is set, just print args and exit }
if (process.env.TEST_MODE === '1') {
console.log('Would execute:'); const child = spawn('node', [devScriptPath, ...args], {
console.log(`node ${devScriptPath} ${args.join(' ')}`); stdio: 'inherit',
process.exit(0); cwd: process.cwd()
return; });
}
child.on('close', (code) => {
const child = spawn('node', [devScriptPath, ...args], { process.exit(code);
stdio: 'inherit', });
cwd: process.cwd()
});
child.on('close', (code) => {
process.exit(code);
});
} }
// Helper function to detect camelCase and convert to kebab-case // Helper function to detect camelCase and convert to kebab-case
@@ -85,239 +79,228 @@ const toKebabCase = (str) => str.replace(/([A-Z])/g, '-$1').toLowerCase();
* @returns {Function} Wrapper action function * @returns {Function} Wrapper action function
*/ */
function createDevScriptAction(commandName) { function createDevScriptAction(commandName) {
return (options, cmd) => { return (options, cmd) => {
// Check for camelCase flags and error out with helpful message // Check for camelCase flags and error out with helpful message
const camelCaseFlags = detectCamelCaseFlags(process.argv); const camelCaseFlags = detectCamelCaseFlags(process.argv);
// If camelCase flags were found, show error and exit
if (camelCaseFlags.length > 0) {
console.error('\nError: Please use kebab-case for CLI flags:');
camelCaseFlags.forEach(flag => {
console.error(` Instead of: --${flag.original}`);
console.error(` Use: --${flag.kebabCase}`);
});
console.error('\nExample: task-master parse-prd --num-tasks=5 instead of --numTasks=5\n');
process.exit(1);
}
// Since we've ensured no camelCase flags, we can now just:
// 1. Start with the command name
const args = [commandName];
// 3. Get positional arguments and explicit flags from the command line
const commandArgs = [];
const positionals = new Set(); // Track positional args we've seen
// Find the command in raw process.argv to extract args
const commandIndex = process.argv.indexOf(commandName);
if (commandIndex !== -1) {
// Process all args after the command name
for (let i = commandIndex + 1; i < process.argv.length; i++) {
const arg = process.argv[i];
if (arg.startsWith('--')) {
// It's a flag - pass through as is
commandArgs.push(arg);
// Skip the next arg if this is a flag with a value (not --flag=value format)
if (!arg.includes('=') &&
i + 1 < process.argv.length &&
!process.argv[i+1].startsWith('--')) {
commandArgs.push(process.argv[++i]);
}
} else if (!positionals.has(arg)) {
// It's a positional argument we haven't seen
commandArgs.push(arg);
positionals.add(arg);
}
}
}
// Add all command line args we collected
args.push(...commandArgs);
// 4. Add default options from Commander if not specified on command line
// Track which options we've seen on the command line
const userOptions = new Set();
for (const arg of commandArgs) {
if (arg.startsWith('--')) {
// Extract option name (without -- and value)
const name = arg.split('=')[0].slice(2);
userOptions.add(name);
// Add the kebab-case version too, to prevent duplicates
const kebabName = name.replace(/([A-Z])/g, '-$1').toLowerCase();
userOptions.add(kebabName);
// Add the camelCase version as well
const camelName = kebabName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
userOptions.add(camelName);
}
}
// Add Commander-provided defaults for options not specified by user
Object.entries(options).forEach(([key, value]) => {
// Debug output to see what keys we're getting
if (process.env.DEBUG === '1') {
console.error(`DEBUG - Processing option: ${key} = ${value}`);
}
// If camelCase flags were found, show error and exit // Special case for numTasks > num-tasks (a known problem case)
if (camelCaseFlags.length > 0) { if (key === 'numTasks') {
console.error('\nError: Please use kebab-case for CLI flags:'); if (process.env.DEBUG === '1') {
camelCaseFlags.forEach((flag) => { console.error('DEBUG - Converting numTasks to num-tasks');
console.error(` Instead of: --${flag.original}`); }
console.error(` Use: --${flag.kebabCase}`); if (!userOptions.has('num-tasks') && !userOptions.has('numTasks')) {
}); args.push(`--num-tasks=${value}`);
console.error( }
'\nExample: task-master parse-prd --num-tasks=5 instead of --numTasks=5\n' return;
); }
process.exit(1);
} // Skip built-in Commander properties and options the user provided
if (['parent', 'commands', 'options', 'rawArgs'].includes(key) || userOptions.has(key)) {
// Since we've ensured no camelCase flags, we can now just: return;
// 1. Start with the command name }
const args = [commandName];
// Also check the kebab-case version of this key
// 3. Get positional arguments and explicit flags from the command line const kebabKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
const commandArgs = []; if (userOptions.has(kebabKey)) {
const positionals = new Set(); // Track positional args we've seen return;
}
// Find the command in raw process.argv to extract args
const commandIndex = process.argv.indexOf(commandName); // Add default values, using kebab-case for the parameter name
if (commandIndex !== -1) { if (value !== undefined) {
// Process all args after the command name if (typeof value === 'boolean') {
for (let i = commandIndex + 1; i < process.argv.length; i++) { if (value === true) {
const arg = process.argv[i]; args.push(`--${kebabKey}`);
} else if (value === false && key === 'generate') {
if (arg.startsWith('--')) { args.push('--skip-generate');
// It's a flag - pass through as is }
commandArgs.push(arg); } else {
// Skip the next arg if this is a flag with a value (not --flag=value format) // Always use kebab-case for option names
if ( args.push(`--${kebabKey}=${value}`);
!arg.includes('=') && }
i + 1 < process.argv.length && }
!process.argv[i + 1].startsWith('--') });
) {
commandArgs.push(process.argv[++i]); // Special handling for parent parameter (uses -p)
} if (options.parent && !args.includes('-p') && !userOptions.has('parent')) {
} else if (!positionals.has(arg)) { args.push('-p', options.parent);
// It's a positional argument we haven't seen }
commandArgs.push(arg);
positionals.add(arg); // Debug output for troubleshooting
} if (process.env.DEBUG === '1') {
} console.error('DEBUG - Command args:', commandArgs);
} console.error('DEBUG - User options:', Array.from(userOptions));
console.error('DEBUG - Commander options:', options);
// Add all command line args we collected console.error('DEBUG - Final args:', args);
args.push(...commandArgs); }
// 4. Add default options from Commander if not specified on command line // Run the script with our processed args
// Track which options we've seen on the command line runDevScript(args);
const userOptions = new Set(); };
for (const arg of commandArgs) {
if (arg.startsWith('--')) {
// Extract option name (without -- and value)
const name = arg.split('=')[0].slice(2);
userOptions.add(name);
// Add the kebab-case version too, to prevent duplicates
const kebabName = name.replace(/([A-Z])/g, '-$1').toLowerCase();
userOptions.add(kebabName);
// Add the camelCase version as well
const camelName = kebabName.replace(/-([a-z])/g, (_, letter) =>
letter.toUpperCase()
);
userOptions.add(camelName);
}
}
// Add Commander-provided defaults for options not specified by user
Object.entries(options).forEach(([key, value]) => {
// Debug output to see what keys we're getting
if (process.env.DEBUG === '1') {
console.error(`DEBUG - Processing option: ${key} = ${value}`);
}
// Special case for numTasks > num-tasks (a known problem case)
if (key === 'numTasks') {
if (process.env.DEBUG === '1') {
console.error('DEBUG - Converting numTasks to num-tasks');
}
if (!userOptions.has('num-tasks') && !userOptions.has('numTasks')) {
args.push(`--num-tasks=${value}`);
}
return;
}
// Skip built-in Commander properties and options the user provided
if (
['parent', 'commands', 'options', 'rawArgs'].includes(key) ||
userOptions.has(key)
) {
return;
}
// Also check the kebab-case version of this key
const kebabKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
if (userOptions.has(kebabKey)) {
return;
}
// Add default values, using kebab-case for the parameter name
if (value !== undefined) {
if (typeof value === 'boolean') {
if (value === true) {
args.push(`--${kebabKey}`);
} else if (value === false && key === 'generate') {
args.push('--skip-generate');
}
} else {
// Always use kebab-case for option names
args.push(`--${kebabKey}=${value}`);
}
}
});
// Special handling for parent parameter (uses -p)
if (options.parent && !args.includes('-p') && !userOptions.has('parent')) {
args.push('-p', options.parent);
}
// Debug output for troubleshooting
if (process.env.DEBUG === '1') {
console.error('DEBUG - Command args:', commandArgs);
console.error('DEBUG - User options:', Array.from(userOptions));
console.error('DEBUG - Commander options:', options);
console.error('DEBUG - Final args:', args);
}
// Run the script with our processed args
runDevScript(args);
};
} }
// // Special case for the 'init' command which uses a different script // Special case for the 'init' command which uses a different script
// function registerInitCommand(program) { function registerInitCommand(program) {
// program program
// .command('init') .command('init')
// .description('Initialize a new project') .description('Initialize a new project')
// .option('-y, --yes', 'Skip prompts and use default values') .option('-y, --yes', 'Skip prompts and use default values')
// .option('-n, --name <name>', 'Project name') .option('-n, --name <name>', 'Project name')
// .option('-d, --description <description>', 'Project description') .option('-d, --description <description>', 'Project description')
// .option('-v, --version <version>', 'Project version') .option('-v, --version <version>', 'Project version')
// .option('-a, --author <author>', 'Author name') .option('-a, --author <author>', 'Author name')
// .option('--skip-install', 'Skip installing dependencies') .option('--skip-install', 'Skip installing dependencies')
// .option('--dry-run', 'Show what would be done without making changes') .option('--dry-run', 'Show what would be done without making changes')
// .action((options) => { .action((options) => {
// // Pass through any options to the init script // Pass through any options to the init script
// const args = [ const args = ['--yes', 'name', 'description', 'version', 'author', 'skip-install', 'dry-run']
// '--yes', .filter(opt => options[opt])
// 'name', .map(opt => {
// 'description', if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
// 'version', return `--${opt}`;
// 'author', }
// 'skip-install', return `--${opt}=${options[opt]}`;
// 'dry-run' });
// ]
// .filter((opt) => options[opt]) const child = spawn('node', [initScriptPath, ...args], {
// .map((opt) => { stdio: 'inherit',
// if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') { cwd: process.cwd()
// return `--${opt}`; });
// }
// return `--${opt}=${options[opt]}`; child.on('close', (code) => {
// }); process.exit(code);
});
// const child = spawn('node', [initScriptPath, ...args], { });
// stdio: 'inherit', }
// cwd: process.cwd()
// });
// child.on('close', (code) => {
// process.exit(code);
// });
// });
// }
// Set up the command-line interface // Set up the command-line interface
const program = new Command(); const program = new Command();
program program
.name('task-master') .name('task-master')
.description('Claude Task Master CLI') .description('Claude Task Master CLI')
.version(version) .version(version)
.addHelpText('afterAll', () => { .addHelpText('afterAll', () => {
// Use the same help display function as dev.js for consistency // Use the same help display function as dev.js for consistency
displayHelp(); displayHelp();
return ''; // Return empty string to prevent commander's default help return ''; // Return empty string to prevent commander's default help
}); });
// Add custom help option to directly call our help display // Add custom help option to directly call our help display
program.helpOption('-h, --help', 'Display help information'); program.helpOption('-h, --help', 'Display help information');
program.on('--help', () => { program.on('--help', () => {
displayHelp(); displayHelp();
}); });
// // Add special case commands // Add special case commands
// registerInitCommand(program); registerInitCommand(program);
program program
.command('dev') .command('dev')
.description('Run the dev.js script') .description('Run the dev.js script')
.action(() => { .action(() => {
const args = process.argv.slice(process.argv.indexOf('dev') + 1); const args = process.argv.slice(process.argv.indexOf('dev') + 1);
runDevScript(args); runDevScript(args);
}); });
// Use a temporary Command instance to get all command definitions // Use a temporary Command instance to get all command definitions
const tempProgram = new Command(); const tempProgram = new Command();
registerCommands(tempProgram); registerCommands(tempProgram);
// For each command in the temp instance, add a modified version to our actual program // For each command in the temp instance, add a modified version to our actual program
tempProgram.commands.forEach((cmd) => { tempProgram.commands.forEach(cmd => {
if (['dev'].includes(cmd.name())) { if (['init', 'dev'].includes(cmd.name())) {
// Skip commands we've already defined specially // Skip commands we've already defined specially
return; return;
} }
// Create a new command with the same name and description // Create a new command with the same name and description
const newCmd = program.command(cmd.name()).description(cmd.description()); const newCmd = program
.command(cmd.name())
// Copy all options .description(cmd.description());
cmd.options.forEach((opt) => {
newCmd.option(opt.flags, opt.description, opt.defaultValue); // Copy all options
}); cmd.options.forEach(opt => {
newCmd.option(
// Set the action to proxy to dev.js opt.flags,
newCmd.action(createDevScriptAction(cmd.name())); opt.description,
opt.defaultValue
);
});
// Set the action to proxy to dev.js
newCmd.action(createDevScriptAction(cmd.name()));
}); });
// Parse the command line arguments // Parse the command line arguments
@@ -325,56 +308,47 @@ program.parse(process.argv);
// Add global error handling for unknown commands and options // Add global error handling for unknown commands and options
process.on('uncaughtException', (err) => { process.on('uncaughtException', (err) => {
// Check if this is a commander.js unknown option error // Check if this is a commander.js unknown option error
if (err.code === 'commander.unknownOption') { if (err.code === 'commander.unknownOption') {
const option = err.message.match(/'([^']+)'/)?.[1]; const option = err.message.match(/'([^']+)'/)?.[1];
const commandArg = process.argv.find( const commandArg = process.argv.find(arg => !arg.startsWith('-') &&
(arg) => arg !== 'task-master' &&
!arg.startsWith('-') && !arg.includes('/') &&
arg !== 'task-master' && arg !== 'node');
!arg.includes('/') && const command = commandArg || 'unknown';
arg !== 'node'
); console.error(chalk.red(`Error: Unknown option '${option}'`));
const command = commandArg || 'unknown'; console.error(chalk.yellow(`Run 'task-master ${command} --help' to see available options for this command`));
process.exit(1);
console.error(chalk.red(`Error: Unknown option '${option}'`)); }
console.error(
chalk.yellow( // Check if this is a commander.js unknown command error
`Run 'task-master ${command} --help' to see available options for this command` if (err.code === 'commander.unknownCommand') {
) const command = err.message.match(/'([^']+)'/)?.[1];
);
process.exit(1); console.error(chalk.red(`Error: Unknown command '${command}'`));
} console.error(chalk.yellow(`Run 'task-master --help' to see available commands`));
process.exit(1);
// Check if this is a commander.js unknown command error }
if (err.code === 'commander.unknownCommand') {
const command = err.message.match(/'([^']+)'/)?.[1]; // Handle other uncaught exceptions
console.error(chalk.red(`Error: ${err.message}`));
console.error(chalk.red(`Error: Unknown command '${command}'`)); if (process.env.DEBUG === '1') {
console.error( console.error(err);
chalk.yellow(`Run 'task-master --help' to see available commands`) }
); process.exit(1);
process.exit(1);
}
// Handle other uncaught exceptions
console.error(chalk.red(`Error: ${err.message}`));
if (process.env.DEBUG === '1') {
console.error(err);
}
process.exit(1);
}); });
// Show help if no command was provided (just 'task-master' with no args) // Show help if no command was provided (just 'task-master' with no args)
if (process.argv.length <= 2) { if (process.argv.length <= 2) {
displayBanner(); displayBanner();
displayHelp(); displayHelp();
process.exit(0); process.exit(0);
} }
// Add exports at the end of the file // Add exports at the end of the file
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
module.exports = { module.exports = {
detectCamelCaseFlags detectCamelCaseFlags
}; };
} }

View File

@@ -41,39 +41,39 @@ Core functions should follow this pattern to support both CLI and MCP use:
* @returns {Object|undefined} - Returns data when source is 'mcp' * @returns {Object|undefined} - Returns data when source is 'mcp'
*/ */
function exampleFunction(param1, param2, options = {}) { function exampleFunction(param1, param2, options = {}) {
try { try {
// Skip UI for MCP // Skip UI for MCP
if (options.source !== 'mcp') { if (options.source !== 'mcp') {
displayBanner(); displayBanner();
console.log(chalk.blue('Processing operation...')); console.log(chalk.blue('Processing operation...'));
} }
// Do the core business logic // Do the core business logic
const result = doSomething(param1, param2); const result = doSomething(param1, param2);
// For MCP, return structured data // For MCP, return structured data
if (options.source === 'mcp') { if (options.source === 'mcp') {
return { return {
success: true, success: true,
data: result data: result
}; };
} }
// For CLI, display output // For CLI, display output
console.log(chalk.green('Operation completed successfully!')); console.log(chalk.green('Operation completed successfully!'));
} catch (error) { } catch (error) {
// Handle errors based on source // Handle errors based on source
if (options.source === 'mcp') { if (options.source === 'mcp') {
return { return {
success: false, success: false,
error: error.message error: error.message
}; };
} }
// CLI error handling // CLI error handling
console.error(chalk.red(`Error: ${error.message}`)); console.error(chalk.red(`Error: ${error.message}`));
process.exit(1); process.exit(1);
} }
} }
``` ```
@@ -89,17 +89,17 @@ export const simpleFunction = adaptForMcp(originalFunction);
// Split implementation - completely different code paths for CLI vs MCP // Split implementation - completely different code paths for CLI vs MCP
export const complexFunction = sourceSplitFunction( export const complexFunction = sourceSplitFunction(
// CLI version with UI // CLI version with UI
function (param1, param2) { function(param1, param2) {
displayBanner(); displayBanner();
console.log(`Processing ${param1}...`); console.log(`Processing ${param1}...`);
// ... CLI implementation // ... CLI implementation
}, },
// MCP version with structured return // MCP version with structured return
function (param1, param2, options = {}) { function(param1, param2, options = {}) {
// ... MCP implementation // ... MCP implementation
return { success: true, data }; return { success: true, data };
} }
); );
``` ```
@@ -110,7 +110,7 @@ When adding new features, follow these steps to ensure CLI and MCP compatibility
1. **Implement Core Logic** in the appropriate module file 1. **Implement Core Logic** in the appropriate module file
2. **Add Source Parameter Support** using the pattern above 2. **Add Source Parameter Support** using the pattern above
3. **Add to task-master-core.js** to make it available for direct import 3. **Add to task-master-core.js** to make it available for direct import
4. **Update Command Map** in `mcp-server/src/tools/utils.js` 4. **Update Command Map** in `mcp-server/src/tools/utils.js`
5. **Create Tool Implementation** in `mcp-server/src/tools/` 5. **Create Tool Implementation** in `mcp-server/src/tools/`
6. **Register the Tool** in `mcp-server/src/tools/index.js` 6. **Register the Tool** in `mcp-server/src/tools/index.js`
@@ -119,39 +119,39 @@ When adding new features, follow these steps to ensure CLI and MCP compatibility
```javascript ```javascript
// In scripts/modules/task-manager.js // In scripts/modules/task-manager.js
export async function newFeature(param1, param2, options = {}) { export async function newFeature(param1, param2, options = {}) {
try { try {
// Source-specific UI // Source-specific UI
if (options.source !== 'mcp') { if (options.source !== 'mcp') {
displayBanner(); displayBanner();
console.log(chalk.blue('Running new feature...')); console.log(chalk.blue('Running new feature...'));
} }
// Shared core logic // Shared core logic
const result = processFeature(param1, param2); const result = processFeature(param1, param2);
// Source-specific return handling // Source-specific return handling
if (options.source === 'mcp') { if (options.source === 'mcp') {
return { return {
success: true, success: true,
data: result data: result
}; };
} }
// CLI output // CLI output
console.log(chalk.green('Feature completed successfully!')); console.log(chalk.green('Feature completed successfully!'));
displayOutput(result); displayOutput(result);
} catch (error) { } catch (error) {
// Error handling based on source // Error handling based on source
if (options.source === 'mcp') { if (options.source === 'mcp') {
return { return {
success: false, success: false,
error: error.message error: error.message
}; };
} }
console.error(chalk.red(`Error: ${error.message}`)); console.error(chalk.red(`Error: ${error.message}`));
process.exit(1); process.exit(1);
} }
} }
``` ```
@@ -163,12 +163,12 @@ import { newFeature } from '../../../scripts/modules/task-manager.js';
// Add to exports // Add to exports
export default { export default {
// ... existing functions // ... existing functions
async newFeature(args = {}, options = {}) { async newFeature(args = {}, options = {}) {
const { param1, param2 } = args; const { param1, param2 } = args;
return executeFunction(newFeature, [param1, param2], options); return executeFunction(newFeature, [param1, param2], options);
} }
}; };
``` ```
@@ -177,8 +177,8 @@ export default {
```javascript ```javascript
// In mcp-server/src/tools/utils.js // In mcp-server/src/tools/utils.js
const commandMap = { const commandMap = {
// ... existing mappings // ... existing mappings
'new-feature': 'newFeature' 'new-feature': 'newFeature'
}; };
``` ```
@@ -186,53 +186,53 @@ const commandMap = {
```javascript ```javascript
// In mcp-server/src/tools/newFeature.js // In mcp-server/src/tools/newFeature.js
import { z } from 'zod'; import { z } from "zod";
import { import {
executeTaskMasterCommand, executeTaskMasterCommand,
createContentResponse, createContentResponse,
createErrorResponse createErrorResponse,
} from './utils.js'; } from "./utils.js";
export function registerNewFeatureTool(server) { export function registerNewFeatureTool(server) {
server.addTool({ server.addTool({
name: 'newFeature', name: "newFeature",
description: 'Run the new feature', description: "Run the new feature",
parameters: z.object({ parameters: z.object({
param1: z.string().describe('First parameter'), param1: z.string().describe("First parameter"),
param2: z.number().optional().describe('Second parameter'), param2: z.number().optional().describe("Second parameter"),
file: z.string().optional().describe('Path to the tasks file'), file: z.string().optional().describe("Path to the tasks file"),
projectRoot: z.string().describe('Root directory of the project') projectRoot: z.string().describe("Root directory of the project")
}), }),
execute: async (args, { log }) => { execute: async (args, { log }) => {
try { try {
log.info(`Running new feature with args: ${JSON.stringify(args)}`); log.info(`Running new feature with args: ${JSON.stringify(args)}`);
const cmdArgs = []; const cmdArgs = [];
if (args.param1) cmdArgs.push(`--param1=${args.param1}`); if (args.param1) cmdArgs.push(`--param1=${args.param1}`);
if (args.param2) cmdArgs.push(`--param2=${args.param2}`); if (args.param2) cmdArgs.push(`--param2=${args.param2}`);
if (args.file) cmdArgs.push(`--file=${args.file}`); if (args.file) cmdArgs.push(`--file=${args.file}`);
const projectRoot = args.projectRoot; const projectRoot = args.projectRoot;
// Execute the command // Execute the command
const result = await executeTaskMasterCommand( const result = await executeTaskMasterCommand(
'new-feature', "new-feature",
log, log,
cmdArgs, cmdArgs,
projectRoot projectRoot
); );
if (!result.success) { if (!result.success) {
throw new Error(result.error); throw new Error(result.error);
} }
return createContentResponse(result.stdout); return createContentResponse(result.stdout);
} catch (error) { } catch (error) {
log.error(`Error in new feature: ${error.message}`); log.error(`Error in new feature: ${error.message}`);
return createErrorResponse(`Error in new feature: ${error.message}`); return createErrorResponse(`Error in new feature: ${error.message}`);
} }
} },
}); });
} }
``` ```
@@ -240,11 +240,11 @@ export function registerNewFeatureTool(server) {
```javascript ```javascript
// In mcp-server/src/tools/index.js // In mcp-server/src/tools/index.js
import { registerNewFeatureTool } from './newFeature.js'; import { registerNewFeatureTool } from "./newFeature.js";
export function registerTaskMasterTools(server) { export function registerTaskMasterTools(server) {
// ... existing registrations // ... existing registrations
registerNewFeatureTool(server); registerNewFeatureTool(server);
} }
``` ```
@@ -266,4 +266,4 @@ node mcp-server/tests/test-command.js newFeature
2. **Structured Data for MCP** - Return clean JSON objects from MCP source functions 2. **Structured Data for MCP** - Return clean JSON objects from MCP source functions
3. **Consistent Error Handling** - Standardize error formats for both interfaces 3. **Consistent Error Handling** - Standardize error formats for both interfaces
4. **Documentation** - Update MCP tool documentation when adding new features 4. **Documentation** - Update MCP tool documentation when adding new features
5. **Testing** - Test both CLI and MCP interfaces for any new or modified feature 5. **Testing** - Test both CLI and MCP interfaces for any new or modified feature

File diff suppressed because it is too large Load Diff

View File

@@ -6,55 +6,57 @@ This document provides examples of how to use the new AI client utilities with A
```javascript ```javascript
// In your direct function implementation: // In your direct function implementation:
import { import {
getAnthropicClientForMCP, getAnthropicClientForMCP,
getModelConfig, getModelConfig,
handleClaudeError handleClaudeError
} from '../utils/ai-client-utils.js'; } from '../utils/ai-client-utils.js';
export async function someAiOperationDirect(args, log, context) { export async function someAiOperationDirect(args, log, context) {
try { try {
// Initialize Anthropic client with session from context // Initialize Anthropic client with session from context
const client = getAnthropicClientForMCP(context.session, log); const client = getAnthropicClientForMCP(context.session, log);
// Get model configuration with defaults or session overrides // Get model configuration with defaults or session overrides
const modelConfig = getModelConfig(context.session); const modelConfig = getModelConfig(context.session);
// Make API call with proper error handling // Make API call with proper error handling
try { try {
const response = await client.messages.create({ const response = await client.messages.create({
model: modelConfig.model, model: modelConfig.model,
max_tokens: modelConfig.maxTokens, max_tokens: modelConfig.maxTokens,
temperature: modelConfig.temperature, temperature: modelConfig.temperature,
messages: [{ role: 'user', content: 'Your prompt here' }] messages: [
}); { role: 'user', content: 'Your prompt here' }
]
return { });
success: true,
data: response return {
}; success: true,
} catch (apiError) { data: response
// Use helper to get user-friendly error message };
const friendlyMessage = handleClaudeError(apiError); } catch (apiError) {
// Use helper to get user-friendly error message
return { const friendlyMessage = handleClaudeError(apiError);
success: false,
error: { return {
code: 'AI_API_ERROR', success: false,
message: friendlyMessage error: {
} code: 'AI_API_ERROR',
}; message: friendlyMessage
} }
} catch (error) { };
// Handle client initialization errors }
return { } catch (error) {
success: false, // Handle client initialization errors
error: { return {
code: 'AI_CLIENT_ERROR', success: false,
message: error.message error: {
} code: 'AI_CLIENT_ERROR',
}; message: error.message
} }
};
}
} }
``` ```
@@ -62,85 +64,86 @@ export async function someAiOperationDirect(args, log, context) {
```javascript ```javascript
// In your MCP tool implementation: // In your MCP tool implementation:
import { import { AsyncOperationManager, StatusCodes } from '../../utils/async-operation-manager.js';
AsyncOperationManager,
StatusCodes
} from '../../utils/async-operation-manager.js';
import { someAiOperationDirect } from '../../core/direct-functions/some-ai-operation.js'; import { someAiOperationDirect } from '../../core/direct-functions/some-ai-operation.js';
export async function someAiOperation(args, context) { export async function someAiOperation(args, context) {
const { session, mcpLog } = context; const { session, mcpLog } = context;
const log = mcpLog || console; const log = mcpLog || console;
try { try {
// Create operation description // Create operation description
const operationDescription = `AI operation: ${args.someParam}`; const operationDescription = `AI operation: ${args.someParam}`;
// Start async operation // Start async operation
const operation = AsyncOperationManager.createOperation( const operation = AsyncOperationManager.createOperation(
operationDescription, operationDescription,
async (reportProgress) => { async (reportProgress) => {
try { try {
// Initial progress report // Initial progress report
reportProgress({ reportProgress({
progress: 0, progress: 0,
status: 'Starting AI operation...' status: 'Starting AI operation...'
}); });
// Call direct function with session and progress reporting // Call direct function with session and progress reporting
const result = await someAiOperationDirect(args, log, { const result = await someAiOperationDirect(
reportProgress, args,
mcpLog: log, log,
session {
}); reportProgress,
mcpLog: log,
// Final progress update session
reportProgress({ }
progress: 100, );
status: result.success ? 'Operation completed' : 'Operation failed',
result: result.data, // Final progress update
error: result.error reportProgress({
}); progress: 100,
status: result.success ? 'Operation completed' : 'Operation failed',
return result; result: result.data,
} catch (error) { error: result.error
// Handle errors in the operation });
reportProgress({
progress: 100, return result;
status: 'Operation failed', } catch (error) {
error: { // Handle errors in the operation
message: error.message, reportProgress({
code: error.code || 'OPERATION_FAILED' progress: 100,
} status: 'Operation failed',
}); error: {
throw error; message: error.message,
} code: error.code || 'OPERATION_FAILED'
} }
); });
throw error;
// Return immediate response with operation ID }
return { }
status: StatusCodes.ACCEPTED, );
body: {
success: true, // Return immediate response with operation ID
message: 'Operation started', return {
operationId: operation.id status: StatusCodes.ACCEPTED,
} body: {
}; success: true,
} catch (error) { message: 'Operation started',
// Handle errors in the MCP tool operationId: operation.id
log.error(`Error in someAiOperation: ${error.message}`); }
return { };
status: StatusCodes.INTERNAL_SERVER_ERROR, } catch (error) {
body: { // Handle errors in the MCP tool
success: false, log.error(`Error in someAiOperation: ${error.message}`);
error: { return {
code: 'OPERATION_FAILED', status: StatusCodes.INTERNAL_SERVER_ERROR,
message: error.message body: {
} success: false,
} error: {
}; code: 'OPERATION_FAILED',
} message: error.message
}
}
};
}
} }
``` ```
@@ -148,56 +151,58 @@ export async function someAiOperation(args, context) {
```javascript ```javascript
// In your direct function: // In your direct function:
import { import {
getPerplexityClientForMCP, getPerplexityClientForMCP,
getBestAvailableAIModel getBestAvailableAIModel
} from '../utils/ai-client-utils.js'; } from '../utils/ai-client-utils.js';
export async function researchOperationDirect(args, log, context) { export async function researchOperationDirect(args, log, context) {
try { try {
// Get the best AI model for this operation based on needs // Get the best AI model for this operation based on needs
const { type, client } = await getBestAvailableAIModel( const { type, client } = await getBestAvailableAIModel(
context.session, context.session,
{ requiresResearch: true }, { requiresResearch: true },
log log
); );
// Report which model we're using // Report which model we're using
if (context.reportProgress) { if (context.reportProgress) {
await context.reportProgress({ await context.reportProgress({
progress: 10, progress: 10,
status: `Using ${type} model for research...` status: `Using ${type} model for research...`
}); });
} }
// Make API call based on the model type // Make API call based on the model type
if (type === 'perplexity') { if (type === 'perplexity') {
// Call Perplexity // Call Perplexity
const response = await client.chat.completions.create({ const response = await client.chat.completions.create({
model: context.session?.env?.PERPLEXITY_MODEL || 'sonar-medium-online', model: context.session?.env?.PERPLEXITY_MODEL || 'sonar-medium-online',
messages: [{ role: 'user', content: args.researchQuery }], messages: [
temperature: 0.1 { role: 'user', content: args.researchQuery }
}); ],
temperature: 0.1
return { });
success: true,
data: response.choices[0].message.content return {
}; success: true,
} else { data: response.choices[0].message.content
// Call Claude as fallback };
// (Implementation depends on specific needs) } else {
// ... // Call Claude as fallback
} // (Implementation depends on specific needs)
} catch (error) { // ...
// Handle errors }
return { } catch (error) {
success: false, // Handle errors
error: { return {
code: 'RESEARCH_ERROR', success: false,
message: error.message error: {
} code: 'RESEARCH_ERROR',
}; message: error.message
} }
};
}
} }
``` ```
@@ -209,9 +214,9 @@ import { getModelConfig } from '../utils/ai-client-utils.js';
// Using custom defaults for a specific operation // Using custom defaults for a specific operation
const operationDefaults = { const operationDefaults = {
model: 'claude-3-haiku-20240307', // Faster, smaller model model: 'claude-3-haiku-20240307', // Faster, smaller model
maxTokens: 1000, // Lower token limit maxTokens: 1000, // Lower token limit
temperature: 0.2 // Lower temperature for more deterministic output temperature: 0.2 // Lower temperature for more deterministic output
}; };
// Get model config with operation-specific defaults // Get model config with operation-specific defaults
@@ -219,34 +224,30 @@ const modelConfig = getModelConfig(context.session, operationDefaults);
// Now use modelConfig in your API calls // Now use modelConfig in your API calls
const response = await client.messages.create({ const response = await client.messages.create({
model: modelConfig.model, model: modelConfig.model,
max_tokens: modelConfig.maxTokens, max_tokens: modelConfig.maxTokens,
temperature: modelConfig.temperature temperature: modelConfig.temperature,
// Other parameters... // Other parameters...
}); });
``` ```
## Best Practices ## Best Practices
1. **Error Handling**: 1. **Error Handling**:
- Always use try/catch blocks around both client initialization and API calls - Always use try/catch blocks around both client initialization and API calls
- Use `handleClaudeError` to provide user-friendly error messages - Use `handleClaudeError` to provide user-friendly error messages
- Return standardized error objects with code and message - Return standardized error objects with code and message
2. **Progress Reporting**: 2. **Progress Reporting**:
- Report progress at key points (starting, processing, completing) - Report progress at key points (starting, processing, completing)
- Include meaningful status messages - Include meaningful status messages
- Include error details in progress reports when failures occur - Include error details in progress reports when failures occur
3. **Session Handling**: 3. **Session Handling**:
- Always pass the session from the context to the AI client getters - Always pass the session from the context to the AI client getters
- Use `getModelConfig` to respect user settings from session - Use `getModelConfig` to respect user settings from session
4. **Model Selection**: 4. **Model Selection**:
- Use `getBestAvailableAIModel` when you need to select between different models - Use `getBestAvailableAIModel` when you need to select between different models
- Set `requiresResearch: true` when you need Perplexity capabilities - Set `requiresResearch: true` when you need Perplexity capabilities
@@ -254,4 +255,4 @@ const response = await client.messages.create({
- Create descriptive operation names - Create descriptive operation names
- Handle all errors within the operation function - Handle all errors within the operation function
- Return standardized results from direct functions - Return standardized results from direct functions
- Return immediate responses with operation IDs - Return immediate responses with operation IDs

View File

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

41
entries.json Normal file
View File

@@ -0,0 +1,41 @@
import os
import json
# Path to Cursor's history folder
history_path = os.path.expanduser('~/Library/Application Support/Cursor/User/History')
# File to search for
target_file = 'tasks/tasks.json'
# Function to search through all entries.json files
def search_entries_for_file(history_path, target_file):
matching_folders = []
for folder in os.listdir(history_path):
folder_path = os.path.join(history_path, folder)
if not os.path.isdir(folder_path):
continue
# Look for entries.json
entries_file = os.path.join(folder_path, 'entries.json')
if not os.path.exists(entries_file):
continue
# Parse entries.json to find the resource key
with open(entries_file, 'r') as f:
data = json.load(f)
resource = data.get('resource', None)
if resource and target_file in resource:
matching_folders.append(folder_path)
return matching_folders
# Search for the target file
matching_folders = search_entries_for_file(history_path, target_file)
# Output the matching folders
if matching_folders:
print(f"Found {target_file} in the following folders:")
for folder in matching_folders:
print(folder)
else:
print(f"No matches found for {target_file}.")

198
index.js
View File

@@ -41,23 +41,27 @@ export const devScriptPath = resolve(__dirname, './scripts/dev.js');
// Export a function to initialize a new project programmatically // Export a function to initialize a new project programmatically
export const initProject = async (options = {}) => { export const initProject = async (options = {}) => {
const init = await import('./scripts/init.js'); const init = await import('./scripts/init.js');
return init.initializeProject(options); return init.initializeProject(options);
}; };
// Export a function to run init as a CLI command // Export a function to run init as a CLI command
export const runInitCLI = async (options = {}) => { export const runInitCLI = async () => {
try { // Using spawn to ensure proper handling of stdio and process exit
const init = await import('./scripts/init.js'); const child = spawn('node', [resolve(__dirname, './scripts/init.js')], {
const result = await init.initializeProject(options); stdio: 'inherit',
return result; cwd: process.cwd()
} catch (error) { });
console.error('Initialization failed:', error.message);
if (process.env.DEBUG === 'true') { return new Promise((resolve, reject) => {
console.error('Debug stack trace:', error.stack); child.on('close', (code) => {
} if (code === 0) {
throw error; // Re-throw to be handled by the command handler resolve();
} } else {
reject(new Error(`Init script exited with code ${code}`));
}
});
});
}; };
// Export version information // Export version information
@@ -65,91 +69,81 @@ export const version = packageJson.version;
// CLI implementation // CLI implementation
if (import.meta.url === `file://${process.argv[1]}`) { if (import.meta.url === `file://${process.argv[1]}`) {
const program = new Command(); const program = new Command();
program program
.name('task-master') .name('task-master')
.description('Claude Task Master CLI') .description('Claude Task Master CLI')
.version(version); .version(version);
program program
.command('init') .command('init')
.description('Initialize a new project') .description('Initialize a new project')
.option('-y, --yes', 'Skip prompts and use default values') .action(() => {
.option('-n, --name <n>', 'Project name') runInitCLI().catch(err => {
.option('-d, --description <description>', 'Project description') console.error('Init failed:', err.message);
.option('-v, --version <version>', 'Project version', '0.1.0') process.exit(1);
.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)') program
.action(async (cmdOptions) => { .command('dev')
try { .description('Run the dev.js script')
await runInitCLI(cmdOptions); .allowUnknownOption(true)
} catch (err) { .action(() => {
console.error('Init failed:', err.message); const args = process.argv.slice(process.argv.indexOf('dev') + 1);
process.exit(1); const child = spawn('node', [devScriptPath, ...args], {
} stdio: 'inherit',
}); cwd: process.cwd()
});
program
.command('dev') child.on('close', (code) => {
.description('Run the dev.js script') process.exit(code);
.allowUnknownOption(true) });
.action(() => { });
const args = process.argv.slice(process.argv.indexOf('dev') + 1);
const child = spawn('node', [devScriptPath, ...args], { // Add shortcuts for common dev.js commands
stdio: 'inherit', program
cwd: process.cwd() .command('list')
}); .description('List all tasks')
.action(() => {
child.on('close', (code) => { const child = spawn('node', [devScriptPath, 'list'], {
process.exit(code); stdio: 'inherit',
}); cwd: process.cwd()
}); });
// Add shortcuts for common dev.js commands child.on('close', (code) => {
program process.exit(code);
.command('list') });
.description('List all tasks') });
.action(() => {
const child = spawn('node', [devScriptPath, 'list'], { program
stdio: 'inherit', .command('next')
cwd: process.cwd() .description('Show the next task to work on')
}); .action(() => {
const child = spawn('node', [devScriptPath, 'next'], {
child.on('close', (code) => { stdio: 'inherit',
process.exit(code); cwd: process.cwd()
}); });
});
child.on('close', (code) => {
program process.exit(code);
.command('next') });
.description('Show the next task to work on') });
.action(() => {
const child = spawn('node', [devScriptPath, 'next'], { program
stdio: 'inherit', .command('generate')
cwd: process.cwd() .description('Generate task files')
}); .action(() => {
const child = spawn('node', [devScriptPath, 'generate'], {
child.on('close', (code) => { stdio: 'inherit',
process.exit(code); cwd: process.cwd()
}); });
});
child.on('close', (code) => {
program process.exit(code);
.command('generate') });
.description('Generate task files') });
.action(() => {
const child = spawn('node', [devScriptPath, 'generate'], { program.parse(process.argv);
stdio: 'inherit', }
cwd: process.cwd()
});
child.on('close', (code) => {
process.exit(code);
});
});
program.parse(process.argv);
}

View File

@@ -1,56 +1,56 @@
export default { export default {
// Use Node.js environment for testing // Use Node.js environment for testing
testEnvironment: 'node', testEnvironment: 'node',
// Automatically clear mock calls between every test // Automatically clear mock calls between every test
clearMocks: true, clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test // Indicates whether the coverage information should be collected while executing the test
collectCoverage: false, collectCoverage: false,
// The directory where Jest should output its coverage files // The directory where Jest should output its coverage files
coverageDirectory: 'coverage', coverageDirectory: 'coverage',
// A list of paths to directories that Jest should use to search for files in // A list of paths to directories that Jest should use to search for files in
roots: ['<rootDir>/tests'], roots: ['<rootDir>/tests'],
// The glob patterns Jest uses to detect test files // The glob patterns Jest uses to detect test files
testMatch: [ testMatch: [
'**/__tests__/**/*.js', '**/__tests__/**/*.js',
'**/?(*.)+(spec|test).js', '**/?(*.)+(spec|test).js',
'**/tests/*.test.js' '**/tests/*.test.js'
], ],
// Transform files // Transform files
transform: {}, transform: {},
// Disable transformations for node_modules // Disable transformations for node_modules
transformIgnorePatterns: ['/node_modules/'], transformIgnorePatterns: ['/node_modules/'],
// Set moduleNameMapper for absolute paths // Set moduleNameMapper for absolute paths
moduleNameMapper: { moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1' '^@/(.*)$': '<rootDir>/$1'
}, },
// Setup module aliases // Setup module aliases
moduleDirectories: ['node_modules', '<rootDir>'], moduleDirectories: ['node_modules', '<rootDir>'],
// Configure test coverage thresholds // Configure test coverage thresholds
coverageThreshold: { coverageThreshold: {
global: { global: {
branches: 80, branches: 80,
functions: 80, functions: 80,
lines: 80, lines: 80,
statements: 80 statements: 80
} }
}, },
// Generate coverage report in these formats // Generate coverage report in these formats
coverageReporters: ['text', 'lcov'], coverageReporters: ['text', 'lcov'],
// Verbose output // Verbose output
verbose: true, verbose: true,
// Setup file // Setup file
setupFilesAfterEnv: ['<rootDir>/tests/setup.js'] setupFilesAfterEnv: ['<rootDir>/tests/setup.js']
}; };

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
import TaskMasterMCPServer from './src/index.js'; import TaskMasterMCPServer from "./src/index.js";
import dotenv from 'dotenv'; import dotenv from "dotenv";
import logger from './src/logger.js'; import logger from "./src/logger.js";
// Load environment variables // Load environment variables
dotenv.config(); dotenv.config();
@@ -11,25 +11,25 @@ dotenv.config();
* Start the MCP server * Start the MCP server
*/ */
async function startServer() { async function startServer() {
const server = new TaskMasterMCPServer(); const server = new TaskMasterMCPServer();
// Handle graceful shutdown // Handle graceful shutdown
process.on('SIGINT', async () => { process.on("SIGINT", async () => {
await server.stop(); await server.stop();
process.exit(0); process.exit(0);
}); });
process.on('SIGTERM', async () => { process.on("SIGTERM", async () => {
await server.stop(); await server.stop();
process.exit(0); process.exit(0);
}); });
try { try {
await server.start(); await server.start();
} catch (error) { } catch (error) {
logger.error(`Failed to start MCP server: ${error.message}`); logger.error(`Failed to start MCP server: ${error.message}`);
process.exit(1); process.exit(1);
} }
} }
// Start the server // Start the server

View File

@@ -2,90 +2,84 @@ import { jest } from '@jest/globals';
import { ContextManager } from '../context-manager.js'; import { ContextManager } from '../context-manager.js';
describe('ContextManager', () => { describe('ContextManager', () => {
let contextManager; let contextManager;
beforeEach(() => { beforeEach(() => {
contextManager = new ContextManager({ contextManager = new ContextManager({
maxCacheSize: 10, maxCacheSize: 10,
ttl: 1000, // 1 second for testing ttl: 1000, // 1 second for testing
maxContextSize: 1000 maxContextSize: 1000
}); });
}); });
describe('getContext', () => { describe('getContext', () => {
it('should create a new context when not in cache', async () => { it('should create a new context when not in cache', async () => {
const context = await contextManager.getContext('test-id', { const context = await contextManager.getContext('test-id', { test: true });
test: true expect(context.id).toBe('test-id');
}); expect(context.metadata.test).toBe(true);
expect(context.id).toBe('test-id'); expect(contextManager.stats.misses).toBe(1);
expect(context.metadata.test).toBe(true); expect(contextManager.stats.hits).toBe(0);
expect(contextManager.stats.misses).toBe(1); });
expect(contextManager.stats.hits).toBe(0);
});
it('should return cached context when available', async () => { it('should return cached context when available', async () => {
// First call creates the context // First call creates the context
await contextManager.getContext('test-id', { test: true }); await contextManager.getContext('test-id', { test: true });
// Second call should hit cache
const context = await contextManager.getContext('test-id', { test: true });
expect(context.id).toBe('test-id');
expect(context.metadata.test).toBe(true);
expect(contextManager.stats.hits).toBe(1);
expect(contextManager.stats.misses).toBe(1);
});
// Second call should hit cache it('should respect TTL settings', async () => {
const context = await contextManager.getContext('test-id', { // Create context
test: true await contextManager.getContext('test-id', { test: true });
});
expect(context.id).toBe('test-id'); // Wait for TTL to expire
expect(context.metadata.test).toBe(true); await new Promise(resolve => setTimeout(resolve, 1100));
expect(contextManager.stats.hits).toBe(1);
expect(contextManager.stats.misses).toBe(1); // Should create new context
}); await contextManager.getContext('test-id', { test: true });
expect(contextManager.stats.misses).toBe(2);
expect(contextManager.stats.hits).toBe(0);
});
});
it('should respect TTL settings', async () => { describe('updateContext', () => {
// Create context it('should update existing context metadata', async () => {
await contextManager.getContext('test-id', { test: true }); await contextManager.getContext('test-id', { initial: true });
const updated = await contextManager.updateContext('test-id', { updated: true });
expect(updated.metadata.initial).toBe(true);
expect(updated.metadata.updated).toBe(true);
});
});
// Wait for TTL to expire describe('invalidateContext', () => {
await new Promise((resolve) => setTimeout(resolve, 1100)); it('should remove context from cache', async () => {
await contextManager.getContext('test-id', { test: true });
contextManager.invalidateContext('test-id', { test: true });
// Should be a cache miss
await contextManager.getContext('test-id', { test: true });
expect(contextManager.stats.invalidations).toBe(1);
expect(contextManager.stats.misses).toBe(2);
});
});
// Should create new context describe('getStats', () => {
await contextManager.getContext('test-id', { test: true }); it('should return current cache statistics', async () => {
expect(contextManager.stats.misses).toBe(2); await contextManager.getContext('test-id', { test: true });
expect(contextManager.stats.hits).toBe(0); const stats = contextManager.getStats();
});
}); expect(stats.hits).toBe(0);
expect(stats.misses).toBe(1);
describe('updateContext', () => { expect(stats.invalidations).toBe(0);
it('should update existing context metadata', async () => { expect(stats.size).toBe(1);
await contextManager.getContext('test-id', { initial: true }); expect(stats.maxSize).toBe(10);
const updated = await contextManager.updateContext('test-id', { expect(stats.ttl).toBe(1000);
updated: true });
}); });
});
expect(updated.metadata.initial).toBe(true);
expect(updated.metadata.updated).toBe(true);
});
});
describe('invalidateContext', () => {
it('should remove context from cache', async () => {
await contextManager.getContext('test-id', { test: true });
contextManager.invalidateContext('test-id', { test: true });
// Should be a cache miss
await contextManager.getContext('test-id', { test: true });
expect(contextManager.stats.invalidations).toBe(1);
expect(contextManager.stats.misses).toBe(2);
});
});
describe('getStats', () => {
it('should return current cache statistics', async () => {
await contextManager.getContext('test-id', { test: true });
const stats = contextManager.getStats();
expect(stats.hits).toBe(0);
expect(stats.misses).toBe(1);
expect(stats.invalidations).toBe(0);
expect(stats.size).toBe(1);
expect(stats.maxSize).toBe(10);
expect(stats.ttl).toBe(1000);
});
});
});

View File

@@ -15,157 +15,156 @@ import { LRUCache } from 'lru-cache';
*/ */
export class ContextManager { export class ContextManager {
/** /**
* Create a new ContextManager instance * Create a new ContextManager instance
* @param {ContextManagerConfig} config - Configuration options * @param {ContextManagerConfig} config - Configuration options
*/ */
constructor(config = {}) { constructor(config = {}) {
this.config = { this.config = {
maxCacheSize: config.maxCacheSize || 1000, maxCacheSize: config.maxCacheSize || 1000,
ttl: config.ttl || 1000 * 60 * 5, // 5 minutes default ttl: config.ttl || 1000 * 60 * 5, // 5 minutes default
maxContextSize: config.maxContextSize || 4000 maxContextSize: config.maxContextSize || 4000
}; };
// Initialize LRU cache for context data // Initialize LRU cache for context data
this.cache = new LRUCache({ this.cache = new LRUCache({
max: this.config.maxCacheSize, max: this.config.maxCacheSize,
ttl: this.config.ttl, ttl: this.config.ttl,
updateAgeOnGet: true updateAgeOnGet: true
}); });
// Cache statistics // Cache statistics
this.stats = { this.stats = {
hits: 0, hits: 0,
misses: 0, misses: 0,
invalidations: 0 invalidations: 0
}; };
} }
/** /**
* Create a new context or retrieve from cache * Create a new context or retrieve from cache
* @param {string} contextId - Unique identifier for the context * @param {string} contextId - Unique identifier for the context
* @param {Object} metadata - Additional metadata for the context * @param {Object} metadata - Additional metadata for the context
* @returns {Object} Context object with metadata * @returns {Object} Context object with metadata
*/ */
async getContext(contextId, metadata = {}) { async getContext(contextId, metadata = {}) {
const cacheKey = this._getCacheKey(contextId, metadata); const cacheKey = this._getCacheKey(contextId, metadata);
// Try to get from cache first
const cached = this.cache.get(cacheKey);
if (cached) {
this.stats.hits++;
return cached;
}
// Try to get from cache first this.stats.misses++;
const cached = this.cache.get(cacheKey);
if (cached) { // Create new context if not in cache
this.stats.hits++; const context = {
return cached; id: contextId,
} metadata: {
...metadata,
created: new Date().toISOString()
}
};
this.stats.misses++; // Cache the new context
this.cache.set(cacheKey, context);
return context;
}
// Create new context if not in cache /**
const context = { * Update an existing context
id: contextId, * @param {string} contextId - Context identifier
metadata: { * @param {Object} updates - Updates to apply to the context
...metadata, * @returns {Object} Updated context
created: new Date().toISOString() */
} async updateContext(contextId, updates) {
}; const context = await this.getContext(contextId);
// Apply updates to context
Object.assign(context.metadata, updates);
// Update cache
const cacheKey = this._getCacheKey(contextId, context.metadata);
this.cache.set(cacheKey, context);
return context;
}
// Cache the new context /**
this.cache.set(cacheKey, context); * Invalidate a context in the cache
* @param {string} contextId - Context identifier
* @param {Object} metadata - Metadata used in the cache key
*/
invalidateContext(contextId, metadata = {}) {
const cacheKey = this._getCacheKey(contextId, metadata);
this.cache.delete(cacheKey);
this.stats.invalidations++;
}
return context; /**
} * Get cached data associated with a specific key.
* Increments cache hit stats if found.
* @param {string} key - The cache key.
* @returns {any | undefined} The cached data or undefined if not found/expired.
*/
getCachedData(key) {
const cached = this.cache.get(key);
if (cached !== undefined) { // Check for undefined specifically, as null/false might be valid cached values
this.stats.hits++;
return cached;
}
this.stats.misses++;
return undefined;
}
/** /**
* Update an existing context * Set data in the cache with a specific key.
* @param {string} contextId - Context identifier * @param {string} key - The cache key.
* @param {Object} updates - Updates to apply to the context * @param {any} data - The data to cache.
* @returns {Object} Updated context */
*/ setCachedData(key, data) {
async updateContext(contextId, updates) { this.cache.set(key, data);
const context = await this.getContext(contextId); }
// Apply updates to context /**
Object.assign(context.metadata, updates); * Invalidate a specific cache key.
* Increments invalidation stats.
* @param {string} key - The cache key to invalidate.
*/
invalidateCacheKey(key) {
this.cache.delete(key);
this.stats.invalidations++;
}
// Update cache /**
const cacheKey = this._getCacheKey(contextId, context.metadata); * Get cache statistics
this.cache.set(cacheKey, context); * @returns {Object} Cache statistics
*/
getStats() {
return {
hits: this.stats.hits,
misses: this.stats.misses,
invalidations: this.stats.invalidations,
size: this.cache.size,
maxSize: this.config.maxCacheSize,
ttl: this.config.ttl
};
}
return context; /**
} * Generate a cache key from context ID and metadata
* @private
/** * @deprecated No longer used for direct cache key generation outside the manager.
* Invalidate a context in the cache * Prefer generating specific keys in calling functions.
* @param {string} contextId - Context identifier */
* @param {Object} metadata - Metadata used in the cache key _getCacheKey(contextId, metadata) {
*/ // Kept for potential backward compatibility or internal use if needed later.
invalidateContext(contextId, metadata = {}) { return `${contextId}:${JSON.stringify(metadata)}`;
const cacheKey = this._getCacheKey(contextId, metadata); }
this.cache.delete(cacheKey);
this.stats.invalidations++;
}
/**
* Get cached data associated with a specific key.
* Increments cache hit stats if found.
* @param {string} key - The cache key.
* @returns {any | undefined} The cached data or undefined if not found/expired.
*/
getCachedData(key) {
const cached = this.cache.get(key);
if (cached !== undefined) {
// Check for undefined specifically, as null/false might be valid cached values
this.stats.hits++;
return cached;
}
this.stats.misses++;
return undefined;
}
/**
* Set data in the cache with a specific key.
* @param {string} key - The cache key.
* @param {any} data - The data to cache.
*/
setCachedData(key, data) {
this.cache.set(key, data);
}
/**
* Invalidate a specific cache key.
* Increments invalidation stats.
* @param {string} key - The cache key to invalidate.
*/
invalidateCacheKey(key) {
this.cache.delete(key);
this.stats.invalidations++;
}
/**
* Get cache statistics
* @returns {Object} Cache statistics
*/
getStats() {
return {
hits: this.stats.hits,
misses: this.stats.misses,
invalidations: this.stats.invalidations,
size: this.cache.size,
maxSize: this.config.maxCacheSize,
ttl: this.config.ttl
};
}
/**
* Generate a cache key from context ID and metadata
* @private
* @deprecated No longer used for direct cache key generation outside the manager.
* Prefer generating specific keys in calling functions.
*/
_getCacheKey(contextId, metadata) {
// Kept for potential backward compatibility or internal use if needed later.
return `${contextId}:${JSON.stringify(metadata)}`;
}
} }
// Export a singleton instance with default config // Export a singleton instance with default config
export const contextManager = new ContextManager(); export const contextManager = new ContextManager();

View File

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

View File

@@ -3,15 +3,12 @@
*/ */
import { addSubtask } from '../../../../scripts/modules/task-manager.js'; import { addSubtask } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
/** /**
* Add a subtask to an existing task * Add a subtask to an existing task
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - Parent task ID * @param {string} args.id - Parent task ID
* @param {string} [args.taskId] - Existing task ID to convert to subtask (optional) * @param {string} [args.taskId] - Existing task ID to convert to subtask (optional)
* @param {string} [args.title] - Title for new subtask (when creating a new subtask) * @param {string} [args.title] - Title for new subtask (when creating a new subtask)
@@ -19,147 +16,113 @@ import {
* @param {string} [args.details] - Implementation details for new subtask * @param {string} [args.details] - Implementation details for new subtask
* @param {string} [args.status] - Status for new subtask (default: 'pending') * @param {string} [args.status] - Status for new subtask (default: 'pending')
* @param {string} [args.dependencies] - Comma-separated list of dependency IDs * @param {string} [args.dependencies] - Comma-separated list of dependency IDs
* @param {string} [args.file] - Path to the tasks file
* @param {boolean} [args.skipGenerate] - Skip regenerating task files * @param {boolean} [args.skipGenerate] - Skip regenerating task files
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: string}>} * @returns {Promise<{success: boolean, data?: Object, error?: string}>}
*/ */
export async function addSubtaskDirect(args, log) { export async function addSubtaskDirect(args, log) {
// Destructure expected args try {
const { log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
tasksJsonPath,
id, if (!args.id) {
taskId, return {
title, success: false,
description, error: {
details, code: 'INPUT_VALIDATION_ERROR',
status, message: 'Parent task ID is required'
dependencies: dependenciesStr, }
skipGenerate };
} = args; }
try {
log.info(`Adding subtask with args: ${JSON.stringify(args)}`); // Either taskId or title must be provided
if (!args.taskId && !args.title) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Either taskId or title must be provided'
}
};
}
// Check if tasksJsonPath was provided // Find the tasks.json path
if (!tasksJsonPath) { const tasksPath = findTasksJsonPath(args, log);
log.error('addSubtaskDirect called without tasksJsonPath');
return { // Parse dependencies if provided
success: false, let dependencies = [];
error: { if (args.dependencies) {
code: 'MISSING_ARGUMENT', dependencies = args.dependencies.split(',').map(id => {
message: 'tasksJsonPath is required' // Handle both regular IDs and dot notation
} return id.includes('.') ? id.trim() : parseInt(id.trim(), 10);
}; });
} }
if (!id) { // Convert existingTaskId to a number if provided
return { const existingTaskId = args.taskId ? parseInt(args.taskId, 10) : null;
success: false,
error: { // Convert parent ID to a number
code: 'INPUT_VALIDATION_ERROR', const parentId = parseInt(args.id, 10);
message: 'Parent task ID is required'
} // Determine if we should generate files
}; const generateFiles = !args.skipGenerate;
}
// Enable silent mode to prevent console logs from interfering with JSON response
// Either taskId or title must be provided enableSilentMode();
if (!taskId && !title) {
return { // Case 1: Convert existing task to subtask
success: false, if (existingTaskId) {
error: { log.info(`Converting task ${existingTaskId} to a subtask of ${parentId}`);
code: 'INPUT_VALIDATION_ERROR', const result = await addSubtask(tasksPath, parentId, existingTaskId, null, generateFiles);
message: 'Either taskId or title must be provided'
} // Restore normal logging
}; disableSilentMode();
}
return {
// Use provided path success: true,
const tasksPath = tasksJsonPath; data: {
message: `Task ${existingTaskId} successfully converted to a subtask of task ${parentId}`,
// Parse dependencies if provided subtask: result
let dependencies = []; }
if (dependenciesStr) { };
dependencies = dependenciesStr.split(',').map((depId) => { }
// Handle both regular IDs and dot notation // Case 2: Create new subtask
return depId.includes('.') ? depId.trim() : parseInt(depId.trim(), 10); else {
}); log.info(`Creating new subtask for parent task ${parentId}`);
}
const newSubtaskData = {
// Convert existingTaskId to a number if provided title: args.title,
const existingTaskId = taskId ? parseInt(taskId, 10) : null; description: args.description || '',
details: args.details || '',
// Convert parent ID to a number status: args.status || 'pending',
const parentId = parseInt(id, 10); dependencies: dependencies
};
// Determine if we should generate files
const generateFiles = !skipGenerate; const result = await addSubtask(tasksPath, parentId, null, newSubtaskData, generateFiles);
// Enable silent mode to prevent console logs from interfering with JSON response // Restore normal logging
enableSilentMode(); disableSilentMode();
// Case 1: Convert existing task to subtask return {
if (existingTaskId) { success: true,
log.info(`Converting task ${existingTaskId} to a subtask of ${parentId}`); data: {
const result = await addSubtask( message: `New subtask ${parentId}.${result.id} successfully created`,
tasksPath, subtask: result
parentId, }
existingTaskId, };
null, }
generateFiles } catch (error) {
); // Make sure to restore normal logging even if there's an error
disableSilentMode();
// Restore normal logging
disableSilentMode(); log.error(`Error in addSubtaskDirect: ${error.message}`);
return {
return { success: false,
success: true, error: {
data: { code: 'CORE_FUNCTION_ERROR',
message: `Task ${existingTaskId} successfully converted to a subtask of task ${parentId}`, message: error.message
subtask: result }
} };
}; }
} }
// Case 2: Create new subtask
else {
log.info(`Creating new subtask for parent task ${parentId}`);
const newSubtaskData = {
title: title,
description: description || '',
details: details || '',
status: status || 'pending',
dependencies: dependencies
};
const result = await addSubtask(
tasksPath,
parentId,
null,
newSubtaskData,
generateFiles
);
// Restore normal logging
disableSilentMode();
return {
success: true,
data: {
message: `New subtask ${parentId}.${result.id} successfully created`,
subtask: result
}
};
}
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error in addSubtaskDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -4,256 +4,173 @@
*/ */
import { addTask } from '../../../../scripts/modules/task-manager.js'; import { addTask } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
} from '../../../../scripts/modules/utils.js'; import { _buildAddTaskPrompt, parseTaskJsonResponse, _handleAnthropicStream } from '../../../../scripts/modules/ai-services.js';
import {
getAnthropicClientForMCP,
getModelConfig
} from '../utils/ai-client-utils.js';
import {
_buildAddTaskPrompt,
parseTaskJsonResponse,
_handleAnthropicStream
} from '../../../../scripts/modules/ai-services.js';
/** /**
* Direct function wrapper for adding a new task with error handling. * Direct function wrapper for adding a new task with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} [args.prompt] - Description of the task to add (required if not using manual fields) * @param {string} args.prompt - Description of the task to add
* @param {string} [args.title] - Task title (for manual task creation) * @param {Array<number>} [args.dependencies=[]] - Task dependencies as array of IDs
* @param {string} [args.description] - Task description (for manual task creation)
* @param {string} [args.details] - Implementation details (for manual task creation)
* @param {string} [args.testStrategy] - Test strategy (for manual task creation)
* @param {string} [args.dependencies] - Comma-separated list of task IDs this task depends on
* @param {string} [args.priority='medium'] - Task priority (high, medium, low) * @param {string} [args.priority='medium'] - Task priority (high, medium, low)
* @param {string} [args.file='tasks/tasks.json'] - Path to the tasks file * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory * @param {string} [args.projectRoot] - Project root directory
* @param {boolean} [args.research=false] - Whether to use research capabilities for task creation * @param {boolean} [args.research] - Whether to use research capabilities for task creation
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Additional context (reportProgress, session) * @param {Object} context - Additional context (reportProgress, session)
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } } * @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
*/ */
export async function addTaskDirect(args, log, context = {}) { export async function addTaskDirect(args, log, context = {}) {
// Destructure expected args try {
const { tasksJsonPath, prompt, dependencies, priority, research } = args; // Enable silent mode to prevent console logs from interfering with JSON response
try { enableSilentMode();
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); // Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Check required parameters
if (!args.prompt) {
log.error('Missing required parameter: prompt');
disableSilentMode();
return {
success: false,
error: {
code: 'MISSING_PARAMETER',
message: 'The prompt parameter is required for adding a task'
}
};
}
// Extract and prepare parameters
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 priority = args.priority || 'medium';
log.info(`Adding new task with prompt: "${prompt}", dependencies: [${dependencies.join(', ')}], priority: ${priority}`);
// Extract context parameters for advanced functionality
// Commenting out reportProgress extraction
// const { reportProgress, session } = context;
const { session } = context; // Keep session
// Check if tasksJsonPath was provided // Initialize AI client with session environment
if (!tasksJsonPath) { let localAnthropic;
log.error('addTaskDirect called without tasksJsonPath'); try {
disableSilentMode(); // Disable before returning localAnthropic = getAnthropicClientForMCP(session, log);
return { } catch (error) {
success: false, log.error(`Failed to initialize Anthropic client: ${error.message}`);
error: { disableSilentMode();
code: 'MISSING_ARGUMENT', return {
message: 'tasksJsonPath is required' success: false,
} error: {
}; code: 'AI_CLIENT_ERROR',
} message: `Cannot initialize AI client: ${error.message}`
}
};
}
// Use provided path // Get model configuration from session
const tasksPath = tasksJsonPath; const modelConfig = getModelConfig(session);
// Check if this is manual task creation or AI-driven task creation // Read existing tasks to provide context
const isManualCreation = args.title && args.description; 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: [] };
}
// Check required parameters // Build prompts for AI
if (!args.prompt && !isManualCreation) { const { systemPrompt, userPrompt } = _buildAddTaskPrompt(prompt, tasksData.tasks);
log.error(
'Missing required parameters: either prompt or title+description must be provided'
);
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'
}
};
}
// Extract and prepare parameters // Make the AI call using the streaming helper
const taskPrompt = prompt; let responseText;
const taskDependencies = Array.isArray(dependencies) try {
? dependencies responseText = await _handleAnthropicStream(
: dependencies localAnthropic,
? String(dependencies) {
.split(',') model: modelConfig.model,
.map((id) => parseInt(id.trim(), 10)) max_tokens: modelConfig.maxTokens,
: []; temperature: modelConfig.temperature,
const taskPriority = priority || 'medium'; 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}`
}
};
}
// Extract context parameters for advanced functionality // Parse the AI response
const { session } = context; let taskDataFromAI;
try {
let manualTaskData = null; taskDataFromAI = parseTaskJsonResponse(responseText);
} catch (error) {
if (isManualCreation) { log.error(`Failed to parse AI response: ${error.message}`);
// Create manual task data object disableSilentMode();
manualTaskData = { return {
title: args.title, success: false,
description: args.description, error: {
details: args.details || '', code: 'RESPONSE_PARSING_ERROR',
testStrategy: args.testStrategy || '' message: `Failed to parse AI response: ${error.message}`
}; }
};
log.info( }
`Adding new task manually with title: "${args.title}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}`
); // Call the addTask function with 'json' outputFormat to prevent console output when called via MCP
const newTaskId = await addTask(
// Call the addTask function with manual task data tasksPath,
const newTaskId = await addTask( prompt,
tasksPath, dependencies,
null, // No prompt needed for manual creation priority,
taskDependencies, {
priority, // reportProgress, // Commented out
{ mcpLog: log,
mcpLog: log, session,
session taskDataFromAI // Pass the parsed AI result
}, },
'json', // Use JSON output format to prevent console output 'json'
null, // No custom environment );
manualTaskData // Pass the manual task data
); // Restore normal logging
disableSilentMode();
// Restore normal logging
disableSilentMode(); return {
success: true,
return { data: {
success: true, taskId: newTaskId,
data: { message: `Successfully added new task #${newTaskId}`
taskId: newTaskId, }
message: `Successfully added new task #${newTaskId}` };
} } catch (error) {
}; // Make sure to restore normal logging even if there's an error
} else { disableSilentMode();
// AI-driven task creation
log.info( log.error(`Error in addTaskDirect: ${error.message}`);
`Adding new task with prompt: "${prompt}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}` return {
); success: false,
error: {
// Initialize AI client with session environment code: 'ADD_TASK_ERROR',
let localAnthropic; message: error.message
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}`
}
};
}
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error in addTaskDirect: ${error.message}`);
return {
success: false,
error: {
code: 'ADD_TASK_ERROR',
message: error.message
}
};
}
}

View File

@@ -3,180 +3,154 @@
*/ */
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js'; import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode, isSilentMode, readJSON } from '../../../../scripts/modules/utils.js';
disableSilentMode,
isSilentMode,
readJSON
} from '../../../../scripts/modules/utils.js';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
/** /**
* Analyze task complexity and generate recommendations * Analyze task complexity and generate recommendations
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} args.outputPath - Explicit absolute path to save the report. * @param {string} [args.output] - Output file path for the report
* @param {string} [args.model] - LLM model to use for analysis * @param {string} [args.model] - LLM model to use for analysis
* @param {string|number} [args.threshold] - Minimum complexity score to recommend expansion (1-10) * @param {string|number} [args.threshold] - Minimum complexity score to recommend expansion (1-10)
* @param {boolean} [args.research] - Use Perplexity AI for research-backed complexity analysis * @param {boolean} [args.research] - Use Perplexity AI for research-backed complexity analysis
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} [context={}] - Context object containing session data * @param {Object} [context={}] - Context object containing session data
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function analyzeTaskComplexityDirect(args, log, context = {}) { export async function analyzeTaskComplexityDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, outputPath, model, threshold, research } = args; try {
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
try {
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`); // Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Check if required paths were provided
if (!tasksJsonPath) { // Determine output path
log.error('analyzeTaskComplexityDirect called without tasksJsonPath'); let outputPath = args.output || 'scripts/task-complexity-report.json';
return { if (!path.isAbsolute(outputPath) && args.projectRoot) {
success: false, outputPath = path.join(args.projectRoot, outputPath);
error: { }
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required' log.info(`Analyzing task complexity from: ${tasksPath}`);
} log.info(`Output report will be saved to: ${outputPath}`);
};
} if (args.research) {
if (!outputPath) { log.info('Using Perplexity AI for research-backed complexity analysis');
log.error('analyzeTaskComplexityDirect called without outputPath'); }
return {
success: false, // Create options object for analyzeTaskComplexity
error: { code: 'MISSING_ARGUMENT', message: 'outputPath is required' } const options = {
}; file: tasksPath,
} output: outputPath,
model: args.model,
// Use the provided paths threshold: args.threshold,
const tasksPath = tasksJsonPath; research: args.research === true
const resolvedOutputPath = outputPath; };
log.info(`Analyzing task complexity from: ${tasksPath}`); // Enable silent mode to prevent console logs from interfering with JSON response
log.info(`Output report will be saved to: ${resolvedOutputPath}`); const wasSilent = isSilentMode();
if (!wasSilent) {
if (research) { enableSilentMode();
log.info('Using Perplexity AI for research-backed complexity analysis'); }
}
// Create a logWrapper that matches the expected mcpLog interface as specified in utilities.mdc
// Create options object for analyzeTaskComplexity using provided paths const logWrapper = {
const options = { info: (message, ...args) => log.info(message, ...args),
file: tasksPath, warn: (message, ...args) => log.warn(message, ...args),
output: resolvedOutputPath, error: (message, ...args) => log.error(message, ...args),
model: model, debug: (message, ...args) => log.debug && log.debug(message, ...args),
threshold: threshold, success: (message, ...args) => log.info(message, ...args) // Map success to info
research: research === true };
};
try {
// Enable silent mode to prevent console logs from interfering with JSON response // Call the core function with session and logWrapper as mcpLog
const wasSilent = isSilentMode(); await analyzeTaskComplexity(options, {
if (!wasSilent) { session,
enableSilentMode(); mcpLog: logWrapper // Use the wrapper instead of passing log directly
} });
} catch (error) {
// Create a logWrapper that matches the expected mcpLog interface as specified in utilities.mdc log.error(`Error in analyzeTaskComplexity: ${error.message}`);
const logWrapper = { return {
info: (message, ...args) => log.info(message, ...args), success: false,
warn: (message, ...args) => log.warn(message, ...args), error: {
error: (message, ...args) => log.error(message, ...args), code: 'ANALYZE_ERROR',
debug: (message, ...args) => log.debug && log.debug(message, ...args), message: `Error running complexity analysis: ${error.message}`
success: (message, ...args) => log.info(message, ...args) // Map success to info }
}; };
} finally {
try { // Always restore normal logging in finally block, but only if we enabled it
// Call the core function with session and logWrapper as mcpLog if (!wasSilent) {
await analyzeTaskComplexity(options, { disableSilentMode();
session, }
mcpLog: logWrapper // Use the wrapper instead of passing log directly }
});
} catch (error) { // Verify the report file was created
log.error(`Error in analyzeTaskComplexity: ${error.message}`); if (!fs.existsSync(outputPath)) {
return { return {
success: false, success: false,
error: { error: {
code: 'ANALYZE_ERROR', code: 'ANALYZE_ERROR',
message: `Error running complexity analysis: ${error.message}` message: 'Analysis completed but no report file was created'
} }
}; };
} finally { }
// Always restore normal logging in finally block, but only if we enabled it
if (!wasSilent) { // Read the report file
disableSilentMode(); let report;
} try {
} report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
// Verify the report file was created // Important: Handle different report formats
if (!fs.existsSync(resolvedOutputPath)) { // The core function might return an array or an object with a complexityAnalysis property
return { const analysisArray = Array.isArray(report) ? report :
success: false, (report.complexityAnalysis || []);
error: {
code: 'ANALYZE_ERROR', // Count tasks by complexity
message: 'Analysis completed but no report file was created' const highComplexityTasks = analysisArray.filter(t => t.complexityScore >= 8).length;
} const mediumComplexityTasks = analysisArray.filter(t => t.complexityScore >= 5 && t.complexityScore < 8).length;
}; const lowComplexityTasks = analysisArray.filter(t => t.complexityScore < 5).length;
}
return {
// Read the report file success: true,
let report; data: {
try { message: `Task complexity analysis complete. Report saved to ${outputPath}`,
report = JSON.parse(fs.readFileSync(resolvedOutputPath, 'utf8')); reportPath: outputPath,
reportSummary: {
// Important: Handle different report formats taskCount: analysisArray.length,
// The core function might return an array or an object with a complexityAnalysis property highComplexityTasks,
const analysisArray = Array.isArray(report) mediumComplexityTasks,
? report lowComplexityTasks
: report.complexityAnalysis || []; }
}
// Count tasks by complexity };
const highComplexityTasks = analysisArray.filter( } catch (parseError) {
(t) => t.complexityScore >= 8 log.error(`Error parsing report file: ${parseError.message}`);
).length; return {
const mediumComplexityTasks = analysisArray.filter( success: false,
(t) => t.complexityScore >= 5 && t.complexityScore < 8 error: {
).length; code: 'REPORT_PARSE_ERROR',
const lowComplexityTasks = analysisArray.filter( message: `Error parsing complexity report: ${parseError.message}`
(t) => t.complexityScore < 5 }
).length; };
}
return { } catch (error) {
success: true, // Make sure to restore normal logging even if there's an error
data: { if (isSilentMode()) {
message: `Task complexity analysis complete. Report saved to ${resolvedOutputPath}`, disableSilentMode();
reportPath: resolvedOutputPath, }
reportSummary: {
taskCount: analysisArray.length, log.error(`Error in analyzeTaskComplexityDirect: ${error.message}`);
highComplexityTasks, return {
mediumComplexityTasks, success: false,
lowComplexityTasks error: {
} code: 'CORE_FUNCTION_ERROR',
} message: error.message
}; }
} catch (parseError) { };
log.error(`Error parsing report file: ${parseError.message}`); }
return { }
success: false,
error: {
code: 'REPORT_PARSE_ERROR',
message: `Error parsing complexity report: ${parseError.message}`
}
};
}
} catch (error) {
// Make sure to restore normal logging even if there's an error
if (isSilentMode()) {
disableSilentMode();
}
log.error(`Error in analyzeTaskComplexityDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -12,21 +12,21 @@ import { contextManager } from '../context-manager.js';
* @returns {Object} - Cache statistics * @returns {Object} - Cache statistics
*/ */
export async function getCacheStatsDirect(args, log) { export async function getCacheStatsDirect(args, log) {
try { try {
log.info('Retrieving cache statistics'); log.info('Retrieving cache statistics');
const stats = contextManager.getStats(); const stats = contextManager.getStats();
return { return {
success: true, success: true,
data: stats data: stats
}; };
} catch (error) { } catch (error) {
log.error(`Error getting cache stats: ${error.message}`); log.error(`Error getting cache stats: ${error.message}`);
return { return {
success: false, success: false,
error: { error: {
code: 'CACHE_STATS_ERROR', code: 'CACHE_STATS_ERROR',
message: error.message || 'Unknown error occurred' message: error.message || 'Unknown error occurred'
} }
}; };
} }
} }

View File

@@ -3,126 +3,110 @@
*/ */
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js'; import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import fs from 'fs'; import fs from 'fs';
/** /**
* Clear subtasks from specified tasks * Clear subtasks from specified tasks
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from * @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from
* @param {boolean} [args.all] - Clear subtasks from all tasks * @param {boolean} [args.all] - Clear subtasks from all tasks
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function clearSubtasksDirect(args, log) { export async function clearSubtasksDirect(args, log) {
// Destructure expected args try {
const { tasksJsonPath, id, all } = args; log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
try {
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`); // Either id or all must be provided
if (!args.id && !args.all) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Either task IDs with id parameter or all parameter must be provided'
}
};
}
// Check if tasksJsonPath was provided // Find the tasks.json path
if (!tasksJsonPath) { const tasksPath = findTasksJsonPath(args, log);
log.error('clearSubtasksDirect called without tasksJsonPath');
return { // Check if tasks.json exists
success: false, if (!fs.existsSync(tasksPath)) {
error: { return {
code: 'MISSING_ARGUMENT', success: false,
message: 'tasksJsonPath is required' error: {
} code: 'FILE_NOT_FOUND_ERROR',
}; message: `Tasks file not found at ${tasksPath}`
} }
};
// Either id or all must be provided }
if (!id && !all) {
return { let taskIds;
success: false,
error: { // If all is specified, get all task IDs
code: 'INPUT_VALIDATION_ERROR', if (args.all) {
message: log.info('Clearing subtasks from all tasks');
'Either task IDs with id parameter or all parameter must be provided' const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
} if (!data || !data.tasks || data.tasks.length === 0) {
}; return {
} success: false,
error: {
// Use provided path code: 'INPUT_VALIDATION_ERROR',
const tasksPath = tasksJsonPath; message: 'No valid tasks found in the tasks file'
}
// Check if tasks.json exists };
if (!fs.existsSync(tasksPath)) { }
return { taskIds = data.tasks.map(t => t.id).join(',');
success: false, } else {
error: { // Use the provided task IDs
code: 'FILE_NOT_FOUND_ERROR', taskIds = args.id;
message: `Tasks file not found at ${tasksPath}` }
}
}; log.info(`Clearing subtasks from tasks: ${taskIds}`);
}
// Enable silent mode to prevent console logs from interfering with JSON response
let taskIds; enableSilentMode();
// If all is specified, get all task IDs // Call the core function
if (all) { clearSubtasks(tasksPath, taskIds);
log.info('Clearing subtasks from all tasks');
const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8')); // Restore normal logging
if (!data || !data.tasks || data.tasks.length === 0) { disableSilentMode();
return {
success: false, // Read the updated data to provide a summary
error: { const updatedData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
code: 'INPUT_VALIDATION_ERROR', const taskIdArray = taskIds.split(',').map(id => parseInt(id.trim(), 10));
message: 'No valid tasks found in the tasks file'
} // Build a summary of what was done
}; const clearedTasksCount = taskIdArray.length;
} const taskSummary = taskIdArray.map(id => {
taskIds = data.tasks.map((t) => t.id).join(','); const task = updatedData.tasks.find(t => t.id === id);
} else { return task ? { id, title: task.title } : { id, title: 'Task not found' };
// Use the provided task IDs });
taskIds = id;
} return {
success: true,
log.info(`Clearing subtasks from tasks: ${taskIds}`); data: {
message: `Successfully cleared subtasks from ${clearedTasksCount} task(s)`,
// Enable silent mode to prevent console logs from interfering with JSON response tasksCleared: taskSummary
enableSilentMode(); }
};
// Call the core function } catch (error) {
clearSubtasks(tasksPath, taskIds); // Make sure to restore normal logging even if there's an error
disableSilentMode();
// Restore normal logging
disableSilentMode(); log.error(`Error in clearSubtasksDirect: ${error.message}`);
return {
// Read the updated data to provide a summary success: false,
const updatedData = JSON.parse(fs.readFileSync(tasksPath, 'utf8')); error: {
const taskIdArray = taskIds.split(',').map((id) => parseInt(id.trim(), 10)); code: 'CORE_FUNCTION_ERROR',
message: error.message
// Build a summary of what was done }
const clearedTasksCount = taskIdArray.length; };
const taskSummary = taskIdArray.map((id) => { }
const task = updatedData.tasks.find((t) => t.id === id); }
return task ? { id, title: task.title } : { id, title: 'Task not found' };
});
return {
success: true,
data: {
message: `Successfully cleared subtasks from ${clearedTasksCount} task(s)`,
tasksCleared: taskSummary
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error in clearSubtasksDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -3,128 +3,119 @@
* Direct function implementation for displaying complexity analysis report * Direct function implementation for displaying complexity analysis report
*/ */
import { import { readComplexityReport, enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
readComplexityReport, import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode,
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import path from 'path'; import path from 'path';
/** /**
* Direct function wrapper for displaying the complexity report with error handling and caching. * Direct function wrapper for displaying the complexity report with error handling and caching.
* *
* @param {Object} args - Command arguments containing reportPath. * @param {Object} args - Command arguments containing file path option
* @param {string} args.reportPath - Explicit path to the complexity report file.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Result object with success status and data/error information * @returns {Promise<Object>} - Result object with success status and data/error information
*/ */
export async function complexityReportDirect(args, log) { export async function complexityReportDirect(args, log) {
// Destructure expected args try {
const { reportPath } = args; log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
try {
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`); // 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
}
// Check if reportPath was provided // Get report file path from args or use default
if (!reportPath) { const reportPath = args.file || path.join(process.cwd(), 'scripts', 'task-complexity-report.json');
log.error('complexityReportDirect called without reportPath');
return { log.info(`Looking for complexity report at: ${reportPath}`);
success: false,
error: { code: 'MISSING_ARGUMENT', message: 'reportPath is required' }, // Generate cache key based on report path
fromCache: false const cacheKey = `complexityReport:${reportPath}`;
};
} // Define the core action function to read the report
const coreActionFn = async () => {
try {
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode();
const report = readComplexityReport(reportPath);
// Restore normal logging
disableSilentMode();
if (!report) {
log.warn(`No complexity report found at ${reportPath}`);
return {
success: false,
error: {
code: 'FILE_NOT_FOUND_ERROR',
message: `No complexity report found at ${reportPath}. Run 'analyze-complexity' first.`
}
};
}
return {
success: true,
data: {
report,
reportPath
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error reading complexity report: ${error.message}`);
return {
success: false,
error: {
code: 'READ_ERROR',
message: error.message
}
};
}
};
// Use the provided report path // Use the caching utility
log.info(`Looking for complexity report at: ${reportPath}`); try {
const result = await getCachedOrExecute({
// Generate cache key based on report path cacheKey,
const cacheKey = `complexityReport:${reportPath}`; actionFn: coreActionFn,
log
// Define the core action function to read the report });
const coreActionFn = async () => { log.info(`complexityReportDirect completed. From cache: ${result.fromCache}`);
try { return result; // Returns { success, data/error, fromCache }
// Enable silent mode to prevent console logs from interfering with JSON response } catch (error) {
enableSilentMode(); // Catch unexpected errors from getCachedOrExecute itself
// Ensure silent mode is disabled
const report = readComplexityReport(reportPath); disableSilentMode();
// Restore normal logging log.error(`Unexpected error during getCachedOrExecute for complexityReport: ${error.message}`);
disableSilentMode(); return {
success: false,
if (!report) { error: {
log.warn(`No complexity report found at ${reportPath}`); code: 'UNEXPECTED_ERROR',
return { message: error.message
success: false, },
error: { fromCache: false
code: 'FILE_NOT_FOUND_ERROR', };
message: `No complexity report found at ${reportPath}. Run 'analyze-complexity' first.` }
} } catch (error) {
}; // Ensure silent mode is disabled if an outer error occurs
} disableSilentMode();
return { log.error(`Error in complexityReportDirect: ${error.message}`);
success: true, return {
data: { success: false,
report, error: {
reportPath code: 'UNEXPECTED_ERROR',
} message: error.message
}; },
} catch (error) { fromCache: false
// Make sure to restore normal logging even if there's an error };
disableSilentMode(); }
}
log.error(`Error reading complexity report: ${error.message}`);
return {
success: false,
error: {
code: 'READ_ERROR',
message: error.message
}
};
}
};
// Use the caching utility
try {
const result = await getCachedOrExecute({
cacheKey,
actionFn: coreActionFn,
log
});
log.info(
`complexityReportDirect completed. From cache: ${result.fromCache}`
);
return result; // Returns { success, data/error, fromCache }
} catch (error) {
// Catch unexpected errors from getCachedOrExecute itself
// Ensure silent mode is disabled
disableSilentMode();
log.error(
`Unexpected error during getCachedOrExecute for complexityReport: ${error.message}`
);
return {
success: false,
error: {
code: 'UNEXPECTED_ERROR',
message: error.message
},
fromCache: false
};
}
} catch (error) {
// Ensure silent mode is disabled if an outer error occurs
disableSilentMode();
log.error(`Error in complexityReportDirect: ${error.message}`);
return {
success: false,
error: {
code: 'UNEXPECTED_ERROR',
message: error.message
},
fromCache: false
};
}
}

View File

@@ -3,11 +3,8 @@
*/ */
import { expandAllTasks } from '../../../../scripts/modules/task-manager.js'; import { expandAllTasks } from '../../../../scripts/modules/task-manager.js';
import { import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
enableSilentMode, import { findTasksJsonPath } from '../utils/path-utils.js';
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js'; import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
@@ -15,128 +12,109 @@ import fs from 'fs';
/** /**
* Expand all pending tasks with subtasks * Expand all pending tasks with subtasks
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {number|string} [args.num] - Number of subtasks to generate * @param {number|string} [args.num] - Number of subtasks to generate
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation * @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation
* @param {string} [args.prompt] - Additional context to guide subtask generation * @param {string} [args.prompt] - Additional context to guide subtask generation
* @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them * @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Context object containing session * @param {Object} context - Context object containing session
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function expandAllTasksDirect(args, log, context = {}) { export async function expandAllTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args
const { tasksJsonPath, num, research, prompt, force } = args; try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`); // Enable silent mode early to prevent any console output
enableSilentMode();
// Check if tasksJsonPath was provided
if (!tasksJsonPath) { try {
log.error('expandAllTasksDirect called without tasksJsonPath'); // Find the tasks.json path
return { const tasksPath = findTasksJsonPath(args, log);
success: false,
error: { // Parse parameters
code: 'MISSING_ARGUMENT', const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
message: 'tasksJsonPath is required' const useResearch = args.research === true;
} const additionalContext = args.prompt || '';
}; const forceFlag = args.force === true;
}
log.info(`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`);
// Enable silent mode early to prevent any console output
enableSilentMode(); if (useResearch) {
log.info('Using Perplexity AI for research-backed subtask generation');
try {
// Remove internal path finding // Initialize AI client for research-backed expansion
/* try {
const tasksPath = findTasksJsonPath(args, log); await getAnthropicClientForMCP(session, log);
*/ } catch (error) {
// Use provided path // Ensure silent mode is disabled before returning error
const tasksPath = tasksJsonPath; disableSilentMode();
// Parse parameters log.error(`Failed to initialize AI client: ${error.message}`);
const numSubtasks = num ? parseInt(num, 10) : undefined; return {
const useResearch = research === true; success: false,
const additionalContext = prompt || ''; error: {
const forceFlag = force === true; code: 'AI_CLIENT_ERROR',
message: `Cannot initialize AI client: ${error.message}`
log.info( }
`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...` };
); }
}
if (useResearch) {
log.info('Using Perplexity AI for research-backed subtask generation'); if (additionalContext) {
log.info(`Additional context: "${additionalContext}"`);
// Initialize AI client for research-backed expansion }
try { if (forceFlag) {
await getAnthropicClientForMCP(session, log); log.info('Force regeneration of subtasks is enabled');
} catch (error) { }
// Ensure silent mode is disabled before returning error
disableSilentMode(); // Call the core function with session context for AI operations
// and outputFormat as 'json' to prevent UI elements
log.error(`Failed to initialize AI client: ${error.message}`); const result = await expandAllTasks(
return { tasksPath,
success: false, numSubtasks,
error: { useResearch,
code: 'AI_CLIENT_ERROR', additionalContext,
message: `Cannot initialize AI client: ${error.message}` forceFlag,
} { mcpLog: log, session },
}; 'json' // Use JSON output format to prevent UI elements
} );
}
// The expandAllTasks function now returns a result object
if (additionalContext) { return {
log.info(`Additional context: "${additionalContext}"`); success: true,
} data: {
if (forceFlag) { message: "Successfully expanded all pending tasks with subtasks",
log.info('Force regeneration of subtasks is enabled'); details: {
} numSubtasks: numSubtasks,
research: useResearch,
// Call the core function with session context for AI operations prompt: additionalContext,
// and outputFormat as 'json' to prevent UI elements force: forceFlag,
const result = await expandAllTasks( tasksExpanded: result.expandedCount,
tasksPath, totalEligibleTasks: result.tasksToExpand
numSubtasks, }
useResearch, }
additionalContext, };
forceFlag, } finally {
{ mcpLog: log, session }, // Restore normal logging in finally block to ensure it runs even if there's an error
'json' // Use JSON output format to prevent UI elements disableSilentMode();
); }
} catch (error) {
// The expandAllTasks function now returns a result object // Ensure silent mode is disabled if an error occurs
return { if (isSilentMode()) {
success: true, disableSilentMode();
data: { }
message: 'Successfully expanded all pending tasks with subtasks',
details: { log.error(`Error in expandAllTasksDirect: ${error.message}`);
numSubtasks: numSubtasks, return {
research: useResearch, success: false,
prompt: additionalContext, error: {
force: forceFlag, code: 'CORE_FUNCTION_ERROR',
tasksExpanded: result.expandedCount, message: error.message
totalEligibleTasks: result.tasksToExpand }
} };
} }
}; }
} finally {
// Restore normal logging in finally block to ensure it runs even if there's an error
disableSilentMode();
}
} catch (error) {
// Ensure silent mode is disabled if an error occurs
if (isSilentMode()) {
disableSilentMode();
}
log.error(`Error in expandAllTasksDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -4,17 +4,9 @@
*/ */
import { expandTask } from '../../../../scripts/modules/task-manager.js'; import { expandTask } from '../../../../scripts/modules/task-manager.js';
import { import { readJSON, writeJSON, enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
readJSON, import { findTasksJsonPath } from '../utils/path-utils.js';
writeJSON, import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
enableSilentMode,
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
import {
getAnthropicClientForMCP,
getModelConfig
} from '../utils/ai-client-utils.js';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
@@ -22,249 +14,236 @@ import fs from 'fs';
* Direct function wrapper for expanding a task into subtasks with error handling. * Direct function wrapper for expanding a task into subtasks with error handling.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task to expand.
* @param {number|string} [args.num] - Number of subtasks to generate.
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation.
* @param {string} [args.prompt] - Additional context to guide subtask generation.
* @param {boolean} [args.force] - Force expansion even if subtasks exist.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @param {Object} context - Context object containing session and reportProgress * @param {Object} context - Context object containing session and reportProgress
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function expandTaskDirect(args, log, context = {}) { export async function expandTaskDirect(args, log, context = {}) {
const { session } = context; const { session } = context;
// Destructure expected args
const { tasksJsonPath, id, num, research, prompt, force } = args; // Log session root data for debugging
log.info(`Session data in expandTaskDirect: ${JSON.stringify({
hasSession: !!session,
sessionKeys: session ? Object.keys(session) : [],
roots: session?.roots,
rootsStr: JSON.stringify(session?.roots)
})}`);
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: 'FILE_NOT_FOUND_ERROR',
message: `Error determining tasksPath: ${error.message}${sessionRootsInfo}`
},
fromCache: false
};
}
// Log session root data for debugging log.info(`[expandTaskDirect] Determined tasksPath: ${tasksPath}`);
log.info(
`Session data in expandTaskDirect: ${JSON.stringify({
hasSession: !!session,
sessionKeys: session ? Object.keys(session) : [],
roots: session?.roots,
rootsStr: JSON.stringify(session?.roots)
})}`
);
// Check if tasksJsonPath was provided // Validate task ID
if (!tasksJsonPath) { const taskId = args.id ? parseInt(args.id, 10) : null;
log.error('expandTaskDirect called without tasksJsonPath'); if (!taskId) {
return { log.error('Task ID is required');
success: false, return {
error: { success: false,
code: 'MISSING_ARGUMENT', error: {
message: 'tasksJsonPath is required' code: 'INPUT_VALIDATION_ERROR',
}, message: 'Task ID is required'
fromCache: false },
}; fromCache: false
} };
}
// Use provided path // Process other parameters
const tasksPath = tasksJsonPath; const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = args.research === true;
const additionalContext = args.prompt || '';
log.info(`[expandTaskDirect] Using tasksPath: ${tasksPath}`); // Initialize AI client if needed (for expandTask function)
try {
// This ensures the AI client is available by checking it
if (useResearch) {
log.info('Verifying AI client for research-backed expansion');
await getAnthropicClientForMCP(session, log);
}
} catch (error) {
log.error(`Failed to initialize AI client: ${error.message}`);
return {
success: false,
error: {
code: 'AI_CLIENT_ERROR',
message: `Cannot initialize AI client: ${error.message}`
},
fromCache: false
};
}
// Validate task ID try {
const taskId = id ? parseInt(id, 10) : null; log.info(`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}`);
if (!taskId) {
log.error('Task ID is required'); // Read tasks data
return { log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);
success: false, const data = readJSON(tasksPath);
error: { log.info(`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}`);
code: 'INPUT_VALIDATION_ERROR',
message: 'Task ID is required'
},
fromCache: false
};
}
// Process other parameters if (!data || !data.tasks) {
const numSubtasks = num ? parseInt(num, 10) : undefined; log.error(`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`);
const useResearch = research === true; return {
const additionalContext = prompt || ''; success: false,
const forceFlag = force === true; error: {
code: 'INVALID_TASKS_FILE',
// Initialize AI client if needed (for expandTask function) message: `No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}`
try { },
// This ensures the AI client is available by checking it fromCache: false
if (useResearch) { };
log.info('Verifying AI client for research-backed expansion'); }
await getAnthropicClientForMCP(session, log);
} // Find the specific task
} catch (error) { log.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);
log.error(`Failed to initialize AI client: ${error.message}`); const task = data.tasks.find(t => t.id === taskId);
return { log.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);
success: false,
error: { if (!task) {
code: 'AI_CLIENT_ERROR', return {
message: `Cannot initialize AI client: ${error.message}` success: false,
}, error: {
fromCache: false code: 'TASK_NOT_FOUND',
}; message: `Task with ID ${taskId} not found`
} },
fromCache: false
try { };
log.info( }
`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}`
); // Check if task is completed
if (task.status === 'done' || task.status === 'completed') {
// Read tasks data return {
log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`); success: false,
const data = readJSON(tasksPath); error: {
log.info( code: 'TASK_COMPLETED',
`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}` message: `Task ${taskId} is already marked as ${task.status} and cannot be expanded`
); },
fromCache: false
if (!data || !data.tasks) { };
log.error( }
`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`
); // Check for existing subtasks
return { const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0;
success: false,
error: { // If the task already has subtasks, just return it (matching core behavior)
code: 'INVALID_TASKS_FILE', if (hasExistingSubtasks) {
message: `No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}` log.info(`Task ${taskId} already has ${task.subtasks.length} subtasks`);
}, return {
fromCache: false success: true,
}; data: {
} task,
subtasksAdded: 0,
// Find the specific task hasExistingSubtasks
log.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`); },
const task = data.tasks.find((t) => t.id === taskId); fromCache: false
log.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`); };
}
if (!task) {
return { // Keep a copy of the task before modification
success: false, const originalTask = JSON.parse(JSON.stringify(task));
error: {
code: 'TASK_NOT_FOUND', // Tracking subtasks count before expansion
message: `Task with ID ${taskId} not found` const subtasksCountBefore = task.subtasks ? task.subtasks.length : 0;
},
fromCache: false // Create a backup of the tasks.json file
}; const backupPath = path.join(path.dirname(tasksPath), 'tasks.json.bak');
} fs.copyFileSync(tasksPath, backupPath);
// Check if task is completed // Directly modify the data instead of calling the CLI function
if (task.status === 'done' || task.status === 'completed') { if (!task.subtasks) {
return { task.subtasks = [];
success: false, }
error: {
code: 'TASK_COMPLETED', // Save tasks.json with potentially empty subtasks array
message: `Task ${taskId} is already marked as ${task.status} and cannot be expanded` writeJSON(tasksPath, data);
},
fromCache: false // Process the request
}; try {
} // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode();
// Check for existing subtasks and force flag
const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0; // Call expandTask with session context to ensure AI client is properly initialized
if (hasExistingSubtasks && !forceFlag) { const result = await expandTask(
log.info( tasksPath,
`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.` taskId,
); numSubtasks,
return { useResearch,
success: true, additionalContext,
data: { { mcpLog: log, session } // Only pass mcpLog and session, NOT reportProgress
message: `Task ${taskId} already has subtasks. Expansion skipped.`, );
task,
subtasksAdded: 0, // Restore normal logging
hasExistingSubtasks disableSilentMode();
},
fromCache: false // Read the updated data
}; const updatedData = readJSON(tasksPath);
} const updatedTask = updatedData.tasks.find(t => t.id === taskId);
// If force flag is set, clear existing subtasks // Calculate how many subtasks were added
if (hasExistingSubtasks && forceFlag) { const subtasksAdded = updatedTask.subtasks ?
log.info( updatedTask.subtasks.length - subtasksCountBefore : 0;
`Force flag set. Clearing existing subtasks for task ${taskId}.`
); // Return the result
task.subtasks = []; log.info(`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`);
} return {
success: true,
// Keep a copy of the task before modification data: {
const originalTask = JSON.parse(JSON.stringify(task)); task: updatedTask,
subtasksAdded,
// Tracking subtasks count before expansion hasExistingSubtasks
const subtasksCountBefore = task.subtasks ? task.subtasks.length : 0; },
fromCache: false
// Create a backup of the tasks.json file };
const backupPath = path.join(path.dirname(tasksPath), 'tasks.json.bak'); } catch (error) {
fs.copyFileSync(tasksPath, backupPath); // Make sure to restore normal logging even if there's an error
disableSilentMode();
// Directly modify the data instead of calling the CLI function
if (!task.subtasks) { log.error(`Error expanding task: ${error.message}`);
task.subtasks = []; return {
} success: false,
error: {
// Save tasks.json with potentially empty subtasks array code: 'CORE_FUNCTION_ERROR',
writeJSON(tasksPath, data); message: error.message || 'Failed to expand task'
},
// Process the request fromCache: false
try { };
// Enable silent mode to prevent console logs from interfering with JSON response }
enableSilentMode(); } catch (error) {
log.error(`Error expanding task: ${error.message}`);
// Call expandTask with session context to ensure AI client is properly initialized return {
const result = await expandTask( success: false,
tasksPath, error: {
taskId, code: 'CORE_FUNCTION_ERROR',
numSubtasks, message: error.message || 'Failed to expand task'
useResearch, },
additionalContext, fromCache: false
{ mcpLog: log, session } // Only pass mcpLog and session, NOT reportProgress };
); }
}
// Restore normal logging
disableSilentMode();
// Read the updated data
const updatedData = readJSON(tasksPath);
const updatedTask = updatedData.tasks.find((t) => t.id === taskId);
// Calculate how many subtasks were added
const subtasksAdded = updatedTask.subtasks
? updatedTask.subtasks.length - subtasksCountBefore
: 0;
// Return the result
log.info(
`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`
);
return {
success: true,
data: {
task: updatedTask,
subtasksAdded,
hasExistingSubtasks
},
fromCache: false
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error expanding task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to expand task'
},
fromCache: false
};
}
} catch (error) {
log.error(`Error expanding task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to expand task'
},
fromCache: false
};
}
}

View File

@@ -3,78 +3,63 @@
*/ */
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js'; import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import fs from 'fs'; import fs from 'fs';
/** /**
* Fix invalid dependencies in tasks.json automatically * Fix invalid dependencies in tasks.json automatically
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function fixDependenciesDirect(args, log) { export async function fixDependenciesDirect(args, log) {
// Destructure expected args try {
const { tasksJsonPath } = args; log.info(`Fixing invalid dependencies in tasks...`);
try {
log.info(`Fixing invalid dependencies in tasks: ${tasksJsonPath}`); // Find the tasks.json path
const tasksPath = findTasksJsonPath(args, log);
// Check if tasksJsonPath was provided
if (!tasksJsonPath) { // Verify the file exists
log.error('fixDependenciesDirect called without tasksJsonPath'); if (!fs.existsSync(tasksPath)) {
return { return {
success: false, success: false,
error: { error: {
code: 'MISSING_ARGUMENT', code: 'FILE_NOT_FOUND',
message: 'tasksJsonPath is required' message: `Tasks file not found at ${tasksPath}`
} }
}; };
} }
// Use provided path // Enable silent mode to prevent console logs from interfering with JSON response
const tasksPath = tasksJsonPath; enableSilentMode();
// Verify the file exists // Call the original command function
if (!fs.existsSync(tasksPath)) { await fixDependenciesCommand(tasksPath);
return {
success: false, // Restore normal logging
error: { disableSilentMode();
code: 'FILE_NOT_FOUND',
message: `Tasks file not found at ${tasksPath}` return {
} success: true,
}; data: {
} message: 'Dependencies fixed successfully',
tasksPath
// Enable silent mode to prevent console logs from interfering with JSON response }
enableSilentMode(); };
} catch (error) {
// Call the original command function using the provided path // Make sure to restore normal logging even if there's an error
await fixDependenciesCommand(tasksPath); disableSilentMode();
// Restore normal logging log.error(`Error fixing dependencies: ${error.message}`);
disableSilentMode(); return {
success: false,
return { error: {
success: true, code: 'FIX_DEPENDENCIES_ERROR',
data: { message: error.message
message: 'Dependencies fixed successfully', }
tasksPath };
} }
}; }
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error fixing dependencies: ${error.message}`);
return {
success: false,
error: {
code: 'FIX_DEPENDENCIES_ERROR',
message: error.message
}
};
}
}

View File

@@ -4,97 +4,84 @@
*/ */
import { generateTaskFiles } from '../../../../scripts/modules/task-manager.js'; import { generateTaskFiles } from '../../../../scripts/modules/task-manager.js';
import { import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
enableSilentMode, import { findTasksJsonPath } from '../utils/path-utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import path from 'path'; import path from 'path';
/** /**
* Direct function wrapper for generateTaskFiles with error handling. * Direct function wrapper for generateTaskFiles with error handling.
* *
* @param {Object} args - Command arguments containing tasksJsonPath and outputDir. * @param {Object} args - Command arguments containing file and output path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function generateTaskFilesDirect(args, log) { export async function generateTaskFilesDirect(args, log) {
// Destructure expected args try {
const { tasksJsonPath, outputDir } = args; log.info(`Generating task files with args: ${JSON.stringify(args)}`);
try {
log.info(`Generating task files with args: ${JSON.stringify(args)}`); // Get tasks file path
let tasksPath;
// Check if paths were provided try {
if (!tasksJsonPath) { tasksPath = findTasksJsonPath(args, log);
const errorMessage = 'tasksJsonPath is required but was not provided.'; } catch (error) {
log.error(errorMessage); log.error(`Error finding tasks file: ${error.message}`);
return { return {
success: false, success: false,
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false fromCache: false
}; };
} }
if (!outputDir) {
const errorMessage = 'outputDir is required but was not provided.'; // Get output directory (defaults to the same directory as the tasks file)
log.error(errorMessage); let outputDir = args.output;
return { if (!outputDir) {
success: false, outputDir = path.dirname(tasksPath);
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, }
fromCache: false
}; log.info(`Generating task files from ${tasksPath} to ${outputDir}`);
}
// Execute core generateTaskFiles function in a separate try/catch
// Use the provided paths try {
const tasksPath = tasksJsonPath; // Enable silent mode to prevent logs from being written to stdout
const resolvedOutputDir = outputDir; enableSilentMode();
log.info(`Generating task files from ${tasksPath} to ${resolvedOutputDir}`); // The function is synchronous despite being awaited elsewhere
generateTaskFiles(tasksPath, outputDir);
// Execute core generateTaskFiles function in a separate try/catch
try { // Restore normal logging after task generation
// Enable silent mode to prevent logs from being written to stdout disableSilentMode();
enableSilentMode(); } catch (genError) {
// Make sure to restore normal logging even if there's an error
// The function is synchronous despite being awaited elsewhere disableSilentMode();
generateTaskFiles(tasksPath, resolvedOutputDir);
log.error(`Error in generateTaskFiles: ${genError.message}`);
// Restore normal logging after task generation return {
disableSilentMode(); success: false,
} catch (genError) { error: { code: 'GENERATE_FILES_ERROR', message: genError.message },
// Make sure to restore normal logging even if there's an error fromCache: false
disableSilentMode(); };
}
log.error(`Error in generateTaskFiles: ${genError.message}`);
return { // Return success with file paths
success: false, return {
error: { code: 'GENERATE_FILES_ERROR', message: genError.message }, success: true,
fromCache: false data: {
}; message: `Successfully generated task files`,
} tasksPath,
outputDir,
// Return success with file paths taskFiles: 'Individual task files have been generated in the output directory'
return { },
success: true, fromCache: false // This operation always modifies state and should never be cached
data: { };
message: `Successfully generated task files`, } catch (error) {
tasksPath: tasksPath, // Make sure to restore normal logging if an outer error occurs
outputDir: resolvedOutputDir, disableSilentMode();
taskFiles:
'Individual task files have been generated in the output directory' log.error(`Error generating task files: ${error.message}`);
}, return {
fromCache: false // This operation always modifies state and should never be cached success: false,
}; error: { code: 'GENERATE_TASKS_ERROR', message: error.message || 'Unknown error generating task files' },
} catch (error) { fromCache: false
// Make sure to restore normal logging if an outer error occurs };
disableSilentMode(); }
}
log.error(`Error generating task files: ${error.message}`);
return {
success: false,
error: {
code: 'GENERATE_TASKS_ERROR',
message: error.message || 'Unknown error generating task files'
},
fromCache: false
};
}
}

View File

@@ -1,134 +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 initialization options (addAliases, skipInstall, yes, projectRoot)
* @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 = {
aliases: args.addAliases,
skipInstall: args.skipInstall,
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,108 +5,79 @@
import { listTasks } from '../../../../scripts/modules/task-manager.js'; import { listTasks } from '../../../../scripts/modules/task-manager.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
/** /**
* Direct function wrapper for listTasks with error handling and caching. * Direct function wrapper for listTasks with error handling and caching.
* *
* @param {Object} args - Command arguments (now expecting tasksJsonPath explicitly). * @param {Object} args - Command arguments (projectRoot is expected to be resolved).
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }. * @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
*/ */
export async function listTasksDirect(args, log) { export async function listTasksDirect(args, log) {
// Destructure the explicit tasksJsonPath from args let tasksPath;
const { tasksJsonPath, status, withSubtasks } = args; try {
// Find the tasks path first - needed for cache key and execution
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: 'FIND_TASKS_PATH_ERROR', message: error.message }, fromCache: false };
}
if (!tasksJsonPath) { // Generate cache key *after* finding tasksPath
log.error('listTasksDirect called without tasksJsonPath'); const statusFilter = args.status || 'all';
return { const withSubtasks = args.withSubtasks || false;
success: false, const cacheKey = `listTasks:${tasksPath}:${statusFilter}:${withSubtasks}`;
error: {
code: 'MISSING_ARGUMENT', // Define the action function to be executed on cache miss
message: 'tasksJsonPath is required' const coreListTasksAction = async () => {
}, try {
fromCache: false // Enable silent mode to prevent console logs from interfering with JSON response
}; enableSilentMode();
}
log.info(`Executing core listTasks function for path: ${tasksPath}, filter: ${statusFilter}, subtasks: ${withSubtasks}`);
const resultData = listTasks(tasksPath, statusFilter, withSubtasks, 'json');
// Use the explicit tasksJsonPath for cache key if (!resultData || !resultData.tasks) {
const statusFilter = status || 'all'; log.error('Invalid or empty response from listTasks core function');
const withSubtasksFilter = withSubtasks || false; return { success: false, error: { code: 'INVALID_CORE_RESPONSE', message: 'Invalid or empty response from listTasks core function' } };
const cacheKey = `listTasks:${tasksJsonPath}:${statusFilter}:${withSubtasksFilter}`; }
log.info(`Core listTasks function retrieved ${resultData.tasks.length} tasks`);
// Restore normal logging
disableSilentMode();
return { success: true, data: resultData };
// Define the action function to be executed on cache miss } catch (error) {
const coreListTasksAction = async () => { // Make sure to restore normal logging even if there's an error
try { disableSilentMode();
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); log.error(`Core listTasks function failed: ${error.message}`);
return { success: false, error: { code: 'LIST_TASKS_CORE_ERROR', message: error.message || 'Failed to list tasks' } };
}
};
log.info( // Use the caching utility
`Executing core listTasks function for path: ${tasksJsonPath}, filter: ${statusFilter}, subtasks: ${withSubtasksFilter}` try {
); const result = await getCachedOrExecute({
// Pass the explicit tasksJsonPath to the core function cacheKey,
const resultData = listTasks( actionFn: coreListTasksAction,
tasksJsonPath, log
statusFilter, });
withSubtasksFilter, log.info(`listTasksDirect completed. From cache: ${result.fromCache}`);
'json' return result; // Returns { success, data/error, fromCache }
); } catch(error) {
// Catch unexpected errors from getCachedOrExecute itself (though unlikely)
if (!resultData || !resultData.tasks) { log.error(`Unexpected error during getCachedOrExecute for listTasks: ${error.message}`);
log.error('Invalid or empty response from listTasks core function'); console.error(error.stack);
return { return { success: false, error: { code: 'CACHE_UTIL_ERROR', message: error.message }, fromCache: false };
success: false, }
error: { }
code: 'INVALID_CORE_RESPONSE',
message: 'Invalid or empty response from listTasks core function'
}
};
}
log.info(
`Core listTasks function retrieved ${resultData.tasks.length} tasks`
);
// Restore normal logging
disableSilentMode();
return { success: true, data: resultData };
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Core listTasks function failed: ${error.message}`);
return {
success: false,
error: {
code: 'LIST_TASKS_CORE_ERROR',
message: error.message || 'Failed to list tasks'
}
};
}
};
// Use the caching utility
try {
const result = await getCachedOrExecute({
cacheKey,
actionFn: coreListTasksAction,
log
});
log.info(`listTasksDirect completed. From cache: ${result.fromCache}`);
return result; // Returns { success, data/error, fromCache }
} catch (error) {
// Catch unexpected errors from getCachedOrExecute itself (though unlikely)
log.error(
`Unexpected error during getCachedOrExecute for listTasks: ${error.message}`
);
console.error(error.stack);
return {
success: false,
error: { code: 'CACHE_UTIL_ERROR', message: error.message },
fromCache: false
};
}
}

View File

@@ -6,127 +6,117 @@
import { findNextTask } from '../../../../scripts/modules/task-manager.js'; import { findNextTask } from '../../../../scripts/modules/task-manager.js';
import { readJSON } from '../../../../scripts/modules/utils.js'; import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
/** /**
* Direct function wrapper for finding the next task to work on with error handling and caching. * Direct function wrapper for finding the next task to work on with error handling and caching.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function nextTaskDirect(args, log) { export async function nextTaskDirect(args, log) {
// Destructure expected args let tasksPath;
const { tasksJsonPath } = args; try {
// Find the tasks path first - needed for cache key and execution
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return {
success: false,
error: {
code: 'FILE_NOT_FOUND_ERROR',
message: error.message
},
fromCache: false
};
}
if (!tasksJsonPath) { // Generate cache key using task path
log.error('nextTaskDirect called without tasksJsonPath'); const cacheKey = `nextTask:${tasksPath}`;
return {
success: false, // Define the action function to be executed on cache miss
error: { const coreNextTaskAction = async () => {
code: 'MISSING_ARGUMENT', try {
message: 'tasksJsonPath is required' // Enable silent mode to prevent console logs from interfering with JSON response
}, enableSilentMode();
fromCache: false
}; log.info(`Finding next task from ${tasksPath}`);
}
// Read tasks data
const data = readJSON(tasksPath);
if (!data || !data.tasks) {
return {
success: false,
error: {
code: 'INVALID_TASKS_FILE',
message: `No valid tasks found in ${tasksPath}`
}
};
}
// Find the next task
const nextTask = findNextTask(data.tasks);
if (!nextTask) {
log.info('No eligible next task found. All tasks are either completed or have unsatisfied dependencies');
return {
success: true,
data: {
message: 'No eligible next task found. All tasks are either completed or have unsatisfied dependencies',
nextTask: null,
allTasks: data.tasks
}
};
}
// Restore normal logging
disableSilentMode();
// Return the next task data with the full tasks array for reference
log.info(`Successfully found next task ${nextTask.id}: ${nextTask.title}`);
return {
success: true,
data: {
nextTask,
allTasks: data.tasks
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error finding next task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to find next task'
}
};
}
};
// Generate cache key using the provided task path // Use the caching utility
const cacheKey = `nextTask:${tasksJsonPath}`; try {
const result = await getCachedOrExecute({
// Define the action function to be executed on cache miss cacheKey,
const coreNextTaskAction = async () => { actionFn: coreNextTaskAction,
try { log
// Enable silent mode to prevent console logs from interfering with JSON response });
enableSilentMode(); log.info(`nextTaskDirect completed. From cache: ${result.fromCache}`);
return result; // Returns { success, data/error, fromCache }
log.info(`Finding next task from ${tasksJsonPath}`); } catch (error) {
// Catch unexpected errors from getCachedOrExecute itself
// Read tasks data using the provided path log.error(`Unexpected error during getCachedOrExecute for nextTask: ${error.message}`);
const data = readJSON(tasksJsonPath); return {
if (!data || !data.tasks) { success: false,
disableSilentMode(); // Disable before return error: {
return { code: 'UNEXPECTED_ERROR',
success: false, message: error.message
error: { },
code: 'INVALID_TASKS_FILE', fromCache: false
message: `No valid tasks found in ${tasksJsonPath}` };
} }
}; }
}
// Find the next task
const nextTask = findNextTask(data.tasks);
if (!nextTask) {
log.info(
'No eligible next task found. All tasks are either completed or have unsatisfied dependencies'
);
return {
success: true,
data: {
message:
'No eligible next task found. All tasks are either completed or have unsatisfied dependencies',
nextTask: null,
allTasks: data.tasks
}
};
}
// Restore normal logging
disableSilentMode();
// Return the next task data with the full tasks array for reference
log.info(
`Successfully found next task ${nextTask.id}: ${nextTask.title}`
);
return {
success: true,
data: {
nextTask,
allTasks: data.tasks
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error finding next task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to find next task'
}
};
}
};
// Use the caching utility
try {
const result = await getCachedOrExecute({
cacheKey,
actionFn: coreNextTaskAction,
log
});
log.info(`nextTaskDirect completed. From cache: ${result.fromCache}`);
return result; // Returns { success, data/error, fromCache }
} catch (error) {
// Catch unexpected errors from getCachedOrExecute itself
log.error(
`Unexpected error during getCachedOrExecute for nextTask: ${error.message}`
);
return {
success: false,
error: {
code: 'UNEXPECTED_ERROR',
message: error.message
},
fromCache: false
};
}
}

View File

@@ -6,210 +6,145 @@
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import { parsePRD } from '../../../../scripts/modules/task-manager.js'; import { parsePRD } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
} from '../../../../scripts/modules/utils.js';
import {
getAnthropicClientForMCP,
getModelConfig
} from '../utils/ai-client-utils.js';
/** /**
* Direct function wrapper for parsing PRD documents and generating tasks. * Direct function wrapper for parsing PRD documents and generating tasks.
* *
* @param {Object} args - Command arguments containing input, numTasks or tasks, and output options. * @param {Object} args - Command arguments containing input, numTasks or tasks, and output options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function parsePRDDirect(args, log, context = {}) { export async function parsePRDDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
try {
log.info(`Parsing PRD document with args: ${JSON.stringify(args)}`);
// Initialize AI client for PRD parsing
let aiClient;
try {
aiClient = getAnthropicClientForMCP(session, log);
} catch (error) {
log.error(`Failed to initialize AI client: ${error.message}`);
return {
success: false,
error: {
code: 'AI_CLIENT_ERROR',
message: `Cannot initialize AI client: ${error.message}`
},
fromCache: false
};
}
// Parameter validation and path resolution
if (!args.input) {
const errorMessage = 'No input file specified. Please provide an input PRD document path.';
log.error(errorMessage);
return {
success: false,
error: { code: 'MISSING_INPUT_FILE', message: errorMessage },
fromCache: false
};
}
// 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 },
fromCache: false
};
}
// Parse number of tasks - handle both string and number values
let numTasks = 10; // Default
if (args.numTasks) {
numTasks = typeof args.numTasks === 'string' ? parseInt(args.numTasks, 10) : args.numTasks;
if (isNaN(numTasks)) {
numTasks = 10; // Fallback to default if parsing fails
log.warn(`Invalid numTasks value: ${args.numTasks}. Using default: 10`);
}
}
log.info(`Preparing to parse PRD from ${inputPath} and output to ${outputPath} with ${numTasks} tasks`);
// Create the logger wrapper for proper logging in the core function
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),
success: (message, ...args) => log.info(message, ...args) // Map success to info
};
try { // Get model config from session
log.info(`Parsing PRD document with args: ${JSON.stringify(args)}`); const modelConfig = getModelConfig(session);
// Initialize AI client for PRD parsing // Enable silent mode to prevent console logs from interfering with JSON response
let aiClient; enableSilentMode();
try { try {
aiClient = getAnthropicClientForMCP(session, log); // Execute core parsePRD function with AI client
} catch (error) { await parsePRD(inputPath, outputPath, numTasks, {
log.error(`Failed to initialize AI client: ${error.message}`); mcpLog: logWrapper,
return { session
success: false, }, aiClient, modelConfig);
error: {
code: 'AI_CLIENT_ERROR', // Since parsePRD doesn't return a value but writes to a file, we'll read the result
message: `Cannot initialize AI client: ${error.message}` // to return it to the caller
}, if (fs.existsSync(outputPath)) {
fromCache: false const tasksData = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
}; log.info(`Successfully parsed PRD and generated ${tasksData.tasks?.length || 0} tasks`);
}
return {
// Validate required parameters success: true,
if (!args.projectRoot) { data: {
const errorMessage = 'Project root is required for parsePRDDirect'; message: `Successfully generated ${tasksData.tasks?.length || 0} tasks from PRD`,
log.error(errorMessage); taskCount: tasksData.tasks?.length || 0,
return { outputPath
success: false, },
error: { code: 'MISSING_PROJECT_ROOT', message: errorMessage }, fromCache: false // This operation always modifies state and should never be cached
fromCache: false };
}; } else {
} const errorMessage = `Tasks file was not created at ${outputPath}`;
log.error(errorMessage);
if (!args.input) { return {
const errorMessage = 'Input file path is required for parsePRDDirect'; success: false,
log.error(errorMessage); error: { code: 'OUTPUT_FILE_NOT_CREATED', message: errorMessage },
return { fromCache: false
success: false, };
error: { code: 'MISSING_INPUT_PATH', message: errorMessage }, }
fromCache: false } finally {
}; // Always restore normal logging
} disableSilentMode();
}
if (!args.output) { } catch (error) {
const errorMessage = 'Output file path is required for parsePRDDirect'; // Make sure to restore normal logging even if there's an error
log.error(errorMessage); disableSilentMode();
return {
success: false, log.error(`Error parsing PRD: ${error.message}`);
error: { code: 'MISSING_OUTPUT_PATH', message: errorMessage }, return {
fromCache: false success: false,
}; error: { code: 'PARSE_PRD_ERROR', message: error.message || 'Unknown error parsing PRD' },
} fromCache: false
};
// Resolve input path (expecting absolute path or path relative to project root) }
const projectRoot = args.projectRoot; }
const inputPath = path.isAbsolute(args.input)
? args.input
: path.resolve(projectRoot, args.input);
// 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}`
},
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) {
numTasks =
typeof args.numTasks === 'string'
? parseInt(args.numTasks, 10)
: args.numTasks;
if (isNaN(numTasks)) {
numTasks = 10; // Fallback to default if parsing fails
log.warn(`Invalid numTasks value: ${args.numTasks}. Using default: 10`);
}
}
// Extract the append flag from args
const append = Boolean(args.append) === true;
// Log key parameters including append flag
log.info(
`Preparing to parse PRD from ${inputPath} and output to ${outputPath} with ${numTasks} tasks, append mode: ${append}`
);
// Create the logger wrapper for proper logging in the core function
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),
success: (message, ...args) => log.info(message, ...args) // Map success to info
};
// Get model config from session
const modelConfig = getModelConfig(session);
// 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,
outputPath,
numTasks,
{
mcpLog: logWrapper,
session,
append
},
aiClient,
modelConfig
);
// Since parsePRD doesn't return a value but writes to a file, we'll read the result
// to return it to the caller
if (fs.existsSync(outputPath)) {
const tasksData = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
const actionVerb = append ? 'appended' : 'generated';
const message = `Successfully ${actionVerb} ${tasksData.tasks?.length || 0} tasks from PRD`;
log.info(message);
return {
success: true,
data: {
message,
taskCount: tasksData.tasks?.length || 0,
outputPath,
appended: append
},
fromCache: false // This operation always modifies state and should never be cached
};
} else {
const errorMessage = `Tasks file was not created at ${outputPath}`;
log.error(errorMessage);
return {
success: false,
error: { code: 'OUTPUT_FILE_NOT_CREATED', message: errorMessage },
fromCache: false
};
}
} finally {
// Always restore normal logging
disableSilentMode();
}
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error parsing PRD: ${error.message}`);
return {
success: false,
error: {
code: 'PARSE_PRD_ERROR',
message: error.message || 'Unknown error parsing PRD'
},
fromCache: false
};
}
}

View File

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

View File

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

View File

@@ -3,166 +3,102 @@
* Direct function implementation for removing a task * Direct function implementation for removing a task
*/ */
import { import { removeTask } from '../../../../scripts/modules/task-manager.js';
removeTask, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
taskExists import { findTasksJsonPath } from '../utils/path-utils.js';
} from '../../../../scripts/modules/task-manager.js';
import {
enableSilentMode,
disableSilentMode,
readJSON
} from '../../../../scripts/modules/utils.js';
/** /**
* Direct function wrapper for removeTask with error handling. * Direct function wrapper for removeTask with error handling.
* Supports removing multiple tasks at once with comma-separated IDs.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID(s) of the task(s) or subtask(s) to remove (comma-separated for multiple).
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false } * @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false }
*/ */
export async function removeTaskDirect(args, log) { export async function removeTaskDirect(args, log) {
// Destructure expected args try {
const { tasksJsonPath, id } = args; // Find the tasks path first
try { let tasksPath;
// Check if tasksJsonPath was provided try {
if (!tasksJsonPath) { tasksPath = findTasksJsonPath(args, log);
log.error('removeTaskDirect called without tasksJsonPath'); } catch (error) {
return { log.error(`Tasks file not found: ${error.message}`);
success: false, return {
error: { success: false,
code: 'MISSING_ARGUMENT', error: {
message: 'tasksJsonPath is required' code: 'FILE_NOT_FOUND_ERROR',
}, message: error.message
fromCache: false },
}; fromCache: false
} };
}
// Validate task ID parameter
if (!id) { // Validate task ID parameter
log.error('Task ID is required'); const taskId = args.id;
return { if (!taskId) {
success: false, log.error('Task ID is required');
error: { return {
code: 'INPUT_VALIDATION_ERROR', success: false,
message: 'Task ID is required' error: {
}, code: 'INPUT_VALIDATION_ERROR',
fromCache: false message: 'Task ID is required'
}; },
} fromCache: false
};
// Split task IDs if comma-separated }
const taskIdArray = id.split(',').map((taskId) => taskId.trim());
// Skip confirmation in the direct function since it's handled by the client
log.info( log.info(`Removing task with ID: ${taskId} from ${tasksPath}`);
`Removing ${taskIdArray.length} task(s) with ID(s): ${taskIdArray.join(', ')} from ${tasksJsonPath}`
); try {
// Enable silent mode to prevent console logs from interfering with JSON response
// Validate all task IDs exist before proceeding enableSilentMode();
const data = readJSON(tasksJsonPath);
if (!data || !data.tasks) { // Call the core removeTask function
return { const result = await removeTask(tasksPath, taskId);
success: false,
error: { // Restore normal logging
code: 'INVALID_TASKS_FILE', disableSilentMode();
message: `No valid tasks found in ${tasksJsonPath}`
}, log.info(`Successfully removed task: ${taskId}`);
fromCache: false
}; // Return the result
} return {
success: true,
const invalidTasks = taskIdArray.filter( data: {
(taskId) => !taskExists(data.tasks, taskId) message: result.message,
); taskId: taskId,
tasksPath: tasksPath,
if (invalidTasks.length > 0) { removedTask: result.removedTask
return { },
success: false, fromCache: false
error: { };
code: 'INVALID_TASK_ID', } catch (error) {
message: `The following tasks were not found: ${invalidTasks.join(', ')}` // Make sure to restore normal logging even if there's an error
}, disableSilentMode();
fromCache: false
}; log.error(`Error removing task: ${error.message}`);
} return {
success: false,
// Remove tasks one by one error: {
const results = []; code: error.code || 'REMOVE_TASK_ERROR',
message: error.message || 'Failed to remove task'
// Enable silent mode to prevent console logs from interfering with JSON response },
enableSilentMode(); fromCache: false
};
try { }
for (const taskId of taskIdArray) { } catch (error) {
try { // Ensure silent mode is disabled even if an outer error occurs
const result = await removeTask(tasksJsonPath, taskId); disableSilentMode();
results.push({
taskId, // Catch any unexpected errors
success: true, log.error(`Unexpected error in removeTaskDirect: ${error.message}`);
message: result.message, return {
removedTask: result.removedTask success: false,
}); error: {
log.info(`Successfully removed task: ${taskId}`); code: 'UNEXPECTED_ERROR',
} catch (error) { message: error.message
results.push({ },
taskId, fromCache: false
success: false, };
error: error.message }
}); }
log.error(`Error removing task ${taskId}: ${error.message}`);
}
}
} finally {
// Restore normal logging
disableSilentMode();
}
// Check if all tasks were successfully removed
const successfulRemovals = results.filter((r) => r.success);
const failedRemovals = results.filter((r) => !r.success);
if (successfulRemovals.length === 0) {
// All removals failed
return {
success: false,
error: {
code: 'REMOVE_TASK_ERROR',
message: 'Failed to remove any tasks',
details: failedRemovals
.map((r) => `${r.taskId}: ${r.error}`)
.join('; ')
},
fromCache: false
};
}
// At least some tasks were removed successfully
return {
success: true,
data: {
totalTasks: taskIdArray.length,
successful: successfulRemovals.length,
failed: failedRemovals.length,
results: results,
tasksPath: tasksJsonPath
},
fromCache: false
};
} catch (error) {
// Ensure silent mode is disabled even if an outer error occurs
disableSilentMode();
// Catch any unexpected errors
log.error(`Unexpected error in removeTaskDirect: ${error.message}`);
return {
success: false,
error: {
code: 'UNEXPECTED_ERROR',
message: error.message
},
fromCache: false
};
}
}

View File

@@ -4,116 +4,109 @@
*/ */
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js'; import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
/** /**
* Direct function wrapper for setTaskStatus with error handling. * Direct function wrapper for setTaskStatus with error handling.
* *
* @param {Object} args - Command arguments containing id, status and tasksJsonPath. * @param {Object} args - Command arguments containing id, status and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function setTaskStatusDirect(args, log) { export async function setTaskStatusDirect(args, log) {
// Destructure expected args, including the resolved tasksJsonPath try {
const { tasksJsonPath, id, status } = args; log.info(`Setting task status with args: ${JSON.stringify(args)}`);
try {
log.info(`Setting task status with args: ${JSON.stringify(args)}`); // Check required parameters
if (!args.id) {
// Check if tasksJsonPath was provided const errorMessage = 'No task ID specified. Please provide a task ID to update.';
if (!tasksJsonPath) { log.error(errorMessage);
const errorMessage = 'tasksJsonPath is required but was not provided.'; return {
log.error(errorMessage); success: false,
return { error: { code: 'MISSING_TASK_ID', message: errorMessage },
success: false, fromCache: false
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, };
fromCache: false }
};
} if (!args.status) {
const errorMessage = 'No status specified. Please provide a new status value.';
// Check required parameters (id and status) log.error(errorMessage);
if (!id) { return {
const errorMessage = success: false,
'No task ID specified. Please provide a task ID to update.'; error: { code: 'MISSING_STATUS', message: errorMessage },
log.error(errorMessage); fromCache: false
return { };
success: false, }
error: { code: 'MISSING_TASK_ID', message: errorMessage },
fromCache: false // Get tasks file path
}; let tasksPath;
} try {
// The enhanced findTasksJsonPath will now search in parent directories if needed
if (!status) { tasksPath = findTasksJsonPath(args, log);
const errorMessage = log.info(`Found tasks file at: ${tasksPath}`);
'No status specified. Please provide a new status value.'; } catch (error) {
log.error(errorMessage); log.error(`Error finding tasks file: ${error.message}`);
return { return {
success: false, success: false,
error: { code: 'MISSING_STATUS', message: errorMessage }, error: {
fromCache: false 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
// Use the provided path };
const tasksPath = tasksJsonPath; }
// Execute core setTaskStatus function // Execute core setTaskStatus function
const taskId = id; const taskId = args.id;
const newStatus = status; const newStatus = args.status;
log.info(`Setting task ${taskId} status to "${newStatus}"`); log.info(`Setting task ${taskId} status to "${newStatus}"`);
// Call the core function with proper silent mode handling // Call the core function with proper silent mode handling
enableSilentMode(); // Enable silent mode before calling core function let result;
try { enableSilentMode(); // Enable silent mode before calling core function
// Call the core function try {
await setTaskStatus(tasksPath, taskId, newStatus, { mcpLog: log }); // Call the core function
await setTaskStatus(tasksPath, taskId, newStatus, { mcpLog: log });
log.info(`Successfully set task ${taskId} status to ${newStatus}`);
log.info(`Successfully set task ${taskId} status to ${newStatus}`);
// Return success data
const result = { // Return success data
success: true, result = {
data: { success: true,
message: `Successfully updated task ${taskId} status to "${newStatus}"`, data: {
taskId, message: `Successfully updated task ${taskId} status to "${newStatus}"`,
status: newStatus, taskId,
tasksPath: tasksPath // Return the path used status: newStatus,
}, tasksPath
fromCache: false // This operation always modifies state and should never be cached },
}; fromCache: false // This operation always modifies state and should never be cached
return result; };
} catch (error) { } catch (error) {
log.error(`Error setting task status: ${error.message}`); log.error(`Error setting task status: ${error.message}`);
return { result = {
success: false, success: false,
error: { error: { code: 'SET_STATUS_ERROR', message: error.message || 'Unknown error setting task status' },
code: 'SET_STATUS_ERROR', fromCache: false
message: error.message || 'Unknown error setting task status' };
}, } finally {
fromCache: false // ALWAYS restore normal logging in finally block
}; disableSilentMode();
} finally { }
// ALWAYS restore normal logging in finally block
disableSilentMode(); return result;
} } catch (error) {
} catch (error) { // Ensure silent mode is disabled if there was an uncaught error in the outer try block
// Ensure silent mode is disabled if there was an uncaught error in the outer try block if (isSilentMode()) {
if (isSilentMode()) { disableSilentMode();
disableSilentMode(); }
}
log.error(`Error setting task status: ${error.message}`);
log.error(`Error setting task status: ${error.message}`); return {
return { success: false,
success: false, error: { code: 'SET_STATUS_ERROR', message: error.message || 'Unknown error setting task status' },
error: { fromCache: false
code: 'SET_STATUS_ERROR', };
message: error.message || 'Unknown error setting task status' }
}, }
fromCache: false
};
}
}

View File

@@ -6,140 +6,131 @@
import { findTaskById } from '../../../../scripts/modules/utils.js'; import { findTaskById } from '../../../../scripts/modules/utils.js';
import { readJSON } from '../../../../scripts/modules/utils.js'; import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js'; import { getCachedOrExecute } from '../../tools/utils.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
/** /**
* Direct function wrapper for showing task details with error handling and caching. * Direct function wrapper for showing task details with error handling and caching.
* *
* @param {Object} args - Command arguments * @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task or subtask to show.
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
export async function showTaskDirect(args, log) { export async function showTaskDirect(args, log) {
// Destructure expected args let tasksPath;
const { tasksJsonPath, id } = args; try {
// Find the tasks path first - needed for cache key and execution
tasksPath = findTasksJsonPath(args, log);
} catch (error) {
log.error(`Tasks file not found: ${error.message}`);
return {
success: false,
error: {
code: 'FILE_NOT_FOUND_ERROR',
message: error.message
},
fromCache: false
};
}
if (!tasksJsonPath) { // Validate task ID
log.error('showTaskDirect called without tasksJsonPath'); const taskId = args.id;
return { if (!taskId) {
success: false, log.error('Task ID is required');
error: { return {
code: 'MISSING_ARGUMENT', success: false,
message: 'tasksJsonPath is required' error: {
}, code: 'INPUT_VALIDATION_ERROR',
fromCache: false message: 'Task ID is required'
}; },
} fromCache: false
};
}
// Validate task ID // Generate cache key using task path and ID
const taskId = id; const cacheKey = `showTask:${tasksPath}:${taskId}`;
if (!taskId) {
log.error('Task ID is required'); // Define the action function to be executed on cache miss
return { const coreShowTaskAction = async () => {
success: false, try {
error: { // Enable silent mode to prevent console logs from interfering with JSON response
code: 'INPUT_VALIDATION_ERROR', enableSilentMode();
message: 'Task ID is required'
}, log.info(`Retrieving task details for ID: ${taskId} from ${tasksPath}`);
fromCache: false
}; // Read tasks data
} const data = readJSON(tasksPath);
if (!data || !data.tasks) {
return {
success: false,
error: {
code: 'INVALID_TASKS_FILE',
message: `No valid tasks found in ${tasksPath}`
}
};
}
// Find the specific task
const task = findTaskById(data.tasks, taskId);
if (!task) {
return {
success: false,
error: {
code: 'TASK_NOT_FOUND',
message: `Task with ID ${taskId} not found`
}
};
}
// Restore normal logging
disableSilentMode();
// Return the task data with the full tasks array for reference
// (needed for formatDependenciesWithStatus function in UI)
log.info(`Successfully found task ${taskId}`);
return {
success: true,
data: {
task,
allTasks: data.tasks
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error showing task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to show task details'
}
};
}
};
// Generate cache key using the provided task path and ID // Use the caching utility
const cacheKey = `showTask:${tasksJsonPath}:${taskId}`; try {
const result = await getCachedOrExecute({
// Define the action function to be executed on cache miss cacheKey,
const coreShowTaskAction = async () => { actionFn: coreShowTaskAction,
try { log
// Enable silent mode to prevent console logs from interfering with JSON response });
enableSilentMode(); log.info(`showTaskDirect completed. From cache: ${result.fromCache}`);
return result; // Returns { success, data/error, fromCache }
log.info( } catch (error) {
`Retrieving task details for ID: ${taskId} from ${tasksJsonPath}` // Catch unexpected errors from getCachedOrExecute itself
); disableSilentMode();
log.error(`Unexpected error during getCachedOrExecute for showTask: ${error.message}`);
// Read tasks data using the provided path return {
const data = readJSON(tasksJsonPath); success: false,
if (!data || !data.tasks) { error: {
disableSilentMode(); // Disable before returning code: 'UNEXPECTED_ERROR',
return { message: error.message
success: false, },
error: { fromCache: false
code: 'INVALID_TASKS_FILE', };
message: `No valid tasks found in ${tasksJsonPath}` }
} }
};
}
// Find the specific task
const task = findTaskById(data.tasks, taskId);
if (!task) {
disableSilentMode(); // Disable before returning
return {
success: false,
error: {
code: 'TASK_NOT_FOUND',
message: `Task with ID ${taskId} not found`
}
};
}
// Restore normal logging
disableSilentMode();
// Return the task data with the full tasks array for reference
// (needed for formatDependenciesWithStatus function in UI)
log.info(`Successfully found task ${taskId}`);
return {
success: true,
data: {
task,
allTasks: data.tasks
}
};
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error showing task: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message || 'Failed to show task details'
}
};
}
};
// Use the caching utility
try {
const result = await getCachedOrExecute({
cacheKey,
actionFn: coreShowTaskAction,
log
});
log.info(`showTaskDirect completed. From cache: ${result.fromCache}`);
return result; // Returns { success, data/error, fromCache }
} catch (error) {
// Catch unexpected errors from getCachedOrExecute itself
disableSilentMode();
log.error(
`Unexpected error during getCachedOrExecute for showTask: ${error.message}`
);
return {
success: false,
error: {
code: 'UNEXPECTED_ERROR',
message: error.message
},
fromCache: false
};
}
}

View File

@@ -4,191 +4,167 @@
*/ */
import { updateSubtaskById } from '../../../../scripts/modules/task-manager.js'; import { updateSubtaskById } from '../../../../scripts/modules/task-manager.js';
import { import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
enableSilentMode, import { findTasksJsonPath } from '../utils/path-utils.js';
disableSilentMode import { getAnthropicClientForMCP, getPerplexityClientForMCP } from '../utils/ai-client-utils.js';
} from '../../../../scripts/modules/utils.js';
import {
getAnthropicClientForMCP,
getPerplexityClientForMCP
} from '../utils/ai-client-utils.js';
/** /**
* Direct function wrapper for updateSubtaskById with error handling. * Direct function wrapper for updateSubtaskById with error handling.
* *
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateSubtaskByIdDirect(args, log, context = {}) { export async function updateSubtaskByIdDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, id, prompt, research } = args;
try {
try { log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
// Check required parameters
// Check if tasksJsonPath was provided if (!args.id) {
if (!tasksJsonPath) { const errorMessage = 'No subtask ID specified. Please provide a subtask ID to update.';
const errorMessage = 'tasksJsonPath is required but was not provided.'; log.error(errorMessage);
log.error(errorMessage); return {
return { success: false,
success: false, error: { code: 'MISSING_SUBTASK_ID', message: errorMessage },
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, fromCache: false
fromCache: false };
}; }
}
if (!args.prompt) {
// Check required parameters (id and prompt) const errorMessage = 'No prompt specified. Please provide a prompt with information to add to the subtask.';
if (!id) { log.error(errorMessage);
const errorMessage = return {
'No subtask ID specified. Please provide a subtask ID to update.'; success: false,
log.error(errorMessage); error: { code: 'MISSING_PROMPT', message: errorMessage },
return { fromCache: false
success: false, };
error: { code: 'MISSING_SUBTASK_ID', message: errorMessage }, }
fromCache: false
}; // Validate subtask ID format
} const subtaskId = args.id;
if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') {
if (!prompt) { const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`;
const errorMessage = log.error(errorMessage);
'No prompt specified. Please provide a prompt with information to add to the subtask.'; return {
log.error(errorMessage); success: false,
return { error: { code: 'INVALID_SUBTASK_ID_TYPE', message: errorMessage },
success: false, fromCache: false
error: { code: 'MISSING_PROMPT', message: errorMessage }, };
fromCache: false }
};
} const subtaskIdStr = String(subtaskId);
if (!subtaskIdStr.includes('.')) {
// Validate subtask ID format const errorMessage = `Invalid subtask ID format: ${subtaskIdStr}. Subtask ID must be in format "parentId.subtaskId" (e.g., "5.2").`;
const subtaskId = id; log.error(errorMessage);
if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') { return {
const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`; success: false,
log.error(errorMessage); error: { code: 'INVALID_SUBTASK_ID_FORMAT', message: errorMessage },
return { fromCache: false
success: false, };
error: { code: 'INVALID_SUBTASK_ID_TYPE', message: errorMessage }, }
fromCache: false
}; // Get tasks file path
} let tasksPath;
try {
const subtaskIdStr = String(subtaskId); tasksPath = findTasksJsonPath(args, log);
if (!subtaskIdStr.includes('.')) { } catch (error) {
const errorMessage = `Invalid subtask ID format: ${subtaskIdStr}. Subtask ID must be in format "parentId.subtaskId" (e.g., "5.2").`; log.error(`Error finding tasks file: ${error.message}`);
log.error(errorMessage); return {
return { success: false,
success: false, error: { code: 'TASKS_FILE_ERROR', message: error.message },
error: { code: 'INVALID_SUBTASK_ID_FORMAT', message: errorMessage }, fromCache: false
fromCache: false };
}; }
}
// Get research flag
// Use the provided path const useResearch = args.research === true;
const tasksPath = tasksJsonPath;
log.info(`Updating subtask with ID ${subtaskIdStr} with prompt "${args.prompt}" and research: ${useResearch}`);
// Get research flag
const useResearch = research === true; // Initialize the appropriate AI client based on research flag
try {
log.info( if (useResearch) {
`Updating subtask with ID ${subtaskIdStr} with prompt "${prompt}" and research: ${useResearch}` // Initialize Perplexity client
); await getPerplexityClientForMCP(session);
} else {
// Initialize the appropriate AI client based on research flag // Initialize Anthropic client
try { await getAnthropicClientForMCP(session);
if (useResearch) { }
// Initialize Perplexity client } catch (error) {
await getPerplexityClientForMCP(session); log.error(`AI client initialization error: ${error.message}`);
} else { return {
// Initialize Anthropic client success: false,
await getAnthropicClientForMCP(session); error: { code: 'AI_CLIENT_ERROR', message: error.message || 'Failed to initialize AI client' },
} fromCache: false
} catch (error) { };
log.error(`AI client initialization error: ${error.message}`); }
return {
success: false, try {
error: { // Enable silent mode to prevent console logs from interfering with JSON response
code: 'AI_CLIENT_ERROR', enableSilentMode();
message: error.message || 'Failed to initialize AI client'
}, // Create a logger wrapper object to handle logging without breaking the mcpLog[level] calls
fromCache: false // This ensures outputFormat is set to 'json' while still supporting proper logging
}; const logWrapper = {
} info: (message) => log.info(message),
warn: (message) => log.warn(message),
try { error: (message) => log.error(message),
// Enable silent mode to prevent console logs from interfering with JSON response debug: (message) => log.debug && log.debug(message),
enableSilentMode(); success: (message) => log.info(message) // Map success to info if needed
};
// Create a logger wrapper object to handle logging without breaking the mcpLog[level] calls
// This ensures outputFormat is set to 'json' while still supporting proper logging // Execute core updateSubtaskById function
const logWrapper = { // Pass both session and logWrapper as mcpLog to ensure outputFormat is 'json'
info: (message) => log.info(message), const updatedSubtask = await updateSubtaskById(tasksPath, subtaskIdStr, args.prompt, useResearch, {
warn: (message) => log.warn(message), session,
error: (message) => log.error(message), mcpLog: logWrapper
debug: (message) => log.debug && log.debug(message), });
success: (message) => log.info(message) // Map success to info if needed
}; // Restore normal logging
disableSilentMode();
// Execute core updateSubtaskById function
// Pass both session and logWrapper as mcpLog to ensure outputFormat is 'json' // Handle the case where the subtask couldn't be updated (e.g., already marked as done)
const updatedSubtask = await updateSubtaskById( if (!updatedSubtask) {
tasksPath, return {
subtaskIdStr, success: false,
prompt, error: {
useResearch, code: 'SUBTASK_UPDATE_FAILED',
{ message: 'Failed to update subtask. It may be marked as completed, or another error occurred.'
session, },
mcpLog: logWrapper fromCache: false
} };
); }
// Restore normal logging // Return the updated subtask information
disableSilentMode(); return {
success: true,
// Handle the case where the subtask couldn't be updated (e.g., already marked as done) data: {
if (!updatedSubtask) { message: `Successfully updated subtask with ID ${subtaskIdStr}`,
return { subtaskId: subtaskIdStr,
success: false, parentId: subtaskIdStr.split('.')[0],
error: { subtask: updatedSubtask,
code: 'SUBTASK_UPDATE_FAILED', tasksPath,
message: useResearch
'Failed to update subtask. It may be marked as completed, or another error occurred.' },
}, fromCache: false // This operation always modifies state and should never be cached
fromCache: false };
}; } catch (error) {
} // Make sure to restore normal logging even if there's an error
disableSilentMode();
// Return the updated subtask information throw error; // Rethrow to be caught by outer catch block
return { }
success: true, } catch (error) {
data: { // Ensure silent mode is disabled
message: `Successfully updated subtask with ID ${subtaskIdStr}`, disableSilentMode();
subtaskId: subtaskIdStr,
parentId: subtaskIdStr.split('.')[0], log.error(`Error updating subtask by ID: ${error.message}`);
subtask: updatedSubtask, return {
tasksPath, success: false,
useResearch error: { code: 'UPDATE_SUBTASK_ERROR', message: error.message || 'Unknown error updating subtask' },
}, fromCache: false
fromCache: false // This operation always modifies state and should never be cached };
}; }
} catch (error) { }
// Make sure to restore normal logging even if there's an error
disableSilentMode();
throw error; // Rethrow to be caught by outer catch block
}
} catch (error) {
// Ensure silent mode is disabled
disableSilentMode();
log.error(`Error updating subtask by ID: ${error.message}`);
return {
success: false,
error: {
code: 'UPDATE_SUBTASK_ERROR',
message: error.message || 'Unknown error updating subtask'
},
fromCache: false
};
}
}

View File

@@ -4,184 +4,169 @@
*/ */
import { updateTaskById } from '../../../../scripts/modules/task-manager.js'; import { updateTaskById } from '../../../../scripts/modules/task-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode import {
} from '../../../../scripts/modules/utils.js'; getAnthropicClientForMCP,
import { getPerplexityClientForMCP
getAnthropicClientForMCP,
getPerplexityClientForMCP
} from '../utils/ai-client-utils.js'; } from '../utils/ai-client-utils.js';
/** /**
* Direct function wrapper for updateTaskById with error handling. * Direct function wrapper for updateTaskById with error handling.
* *
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateTaskByIdDirect(args, log, context = {}) { export async function updateTaskByIdDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
// Destructure expected args, including the resolved tasksJsonPath
const { tasksJsonPath, id, prompt, research } = args; try {
log.info(`Updating task with args: ${JSON.stringify(args)}`);
try {
log.info(`Updating task with args: ${JSON.stringify(args)}`); // Check required parameters
if (!args.id) {
// Check if tasksJsonPath was provided const errorMessage = 'No task ID specified. Please provide a task ID to update.';
if (!tasksJsonPath) { log.error(errorMessage);
const errorMessage = 'tasksJsonPath is required but was not provided.'; return {
log.error(errorMessage); success: false,
return { error: { code: 'MISSING_TASK_ID', message: errorMessage },
success: false, fromCache: false
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, };
fromCache: false }
};
} if (!args.prompt) {
const errorMessage = 'No prompt specified. Please provide a prompt with new information for the task update.';
// Check required parameters (id and prompt) log.error(errorMessage);
if (!id) { return {
const errorMessage = success: false,
'No task ID specified. Please provide a task ID to update.'; error: { code: 'MISSING_PROMPT', message: errorMessage },
log.error(errorMessage); fromCache: false
return { };
success: false, }
error: { code: 'MISSING_TASK_ID', message: errorMessage },
fromCache: false // Parse taskId - handle both string and number values
}; let taskId;
} if (typeof args.id === 'string') {
// Handle subtask IDs (e.g., "5.2")
if (!prompt) { if (args.id.includes('.')) {
const errorMessage = taskId = args.id; // Keep as string for subtask IDs
'No prompt specified. Please provide a prompt with new information for the task update.'; } else {
log.error(errorMessage); // Parse as integer for main task IDs
return { taskId = parseInt(args.id, 10);
success: false, if (isNaN(taskId)) {
error: { code: 'MISSING_PROMPT', message: errorMessage }, const errorMessage = `Invalid task ID: ${args.id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`;
fromCache: false log.error(errorMessage);
}; return {
} success: false,
error: { code: 'INVALID_TASK_ID', message: errorMessage },
// Parse taskId - handle both string and number values fromCache: false
let taskId; };
if (typeof id === 'string') { }
// Handle subtask IDs (e.g., "5.2") }
if (id.includes('.')) { } else {
taskId = id; // Keep as string for subtask IDs taskId = args.id;
} else { }
// Parse as integer for main task IDs
taskId = parseInt(id, 10); // Get tasks file path
if (isNaN(taskId)) { let tasksPath;
const errorMessage = `Invalid task ID: ${id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`; try {
log.error(errorMessage); tasksPath = findTasksJsonPath(args, log);
return { } catch (error) {
success: false, log.error(`Error finding tasks file: ${error.message}`);
error: { code: 'INVALID_TASK_ID', message: errorMessage }, return {
fromCache: false success: false,
}; error: { code: 'TASKS_FILE_ERROR', message: error.message },
} fromCache: false
} };
} else { }
taskId = id;
} // Get research flag
const useResearch = args.research === true;
// Use the provided path
const tasksPath = tasksJsonPath; // Initialize appropriate AI client based on research flag
let aiClient;
// Get research flag try {
const useResearch = research === true; if (useResearch) {
log.info('Using Perplexity AI for research-backed task update');
// Initialize appropriate AI client based on research flag aiClient = await getPerplexityClientForMCP(session, log);
let aiClient; } else {
try { log.info('Using Claude AI for task update');
if (useResearch) { aiClient = getAnthropicClientForMCP(session, log);
log.info('Using Perplexity AI for research-backed task update'); }
aiClient = await getPerplexityClientForMCP(session, log); } catch (error) {
} else { log.error(`Failed to initialize AI client: ${error.message}`);
log.info('Using Claude AI for task update'); return {
aiClient = getAnthropicClientForMCP(session, log); success: false,
} error: {
} catch (error) { code: 'AI_CLIENT_ERROR',
log.error(`Failed to initialize AI client: ${error.message}`); message: `Cannot initialize AI client: ${error.message}`
return { },
success: false, fromCache: false
error: { };
code: 'AI_CLIENT_ERROR', }
message: `Cannot initialize AI client: ${error.message}`
}, log.info(`Updating task with ID ${taskId} with prompt "${args.prompt}" and research: ${useResearch}`);
fromCache: false
}; try {
} // Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode();
log.info(
`Updating task with ID ${taskId} with prompt "${prompt}" and research: ${useResearch}` // Create a logger wrapper that matches what updateTaskById expects
); const logWrapper = {
info: (message) => log.info(message),
try { warn: (message) => log.warn(message),
// Enable silent mode to prevent console logs from interfering with JSON response error: (message) => log.error(message),
enableSilentMode(); debug: (message) => log.debug && log.debug(message),
success: (message) => log.info(message) // Map success to info since many loggers don't have success
// Create a logger wrapper that matches what updateTaskById expects };
const logWrapper = {
info: (message) => log.info(message), // Execute core updateTaskById function with proper parameters
warn: (message) => log.warn(message), await updateTaskById(
error: (message) => log.error(message), tasksPath,
debug: (message) => log.debug && log.debug(message), taskId,
success: (message) => log.info(message) // Map success to info since many loggers don't have success args.prompt,
}; useResearch,
{
// Execute core updateTaskById function with proper parameters mcpLog: logWrapper, // Use our wrapper object that has the expected method structure
await updateTaskById( session
tasksPath, },
taskId, 'json'
prompt, );
useResearch,
{ // Since updateTaskById doesn't return a value but modifies the tasks file,
mcpLog: logWrapper, // Use our wrapper object that has the expected method structure // we'll return a success message
session return {
}, success: true,
'json' data: {
); message: `Successfully updated task with ID ${taskId} based on the prompt`,
taskId,
// Since updateTaskById doesn't return a value but modifies the tasks file, tasksPath,
// we'll return a success message useResearch
return { },
success: true, fromCache: false // This operation always modifies state and should never be cached
data: { };
message: `Successfully updated task with ID ${taskId} based on the prompt`, } catch (error) {
taskId, log.error(`Error updating task by ID: ${error.message}`);
tasksPath: tasksPath, // Return the used path return {
useResearch success: false,
}, error: { code: 'UPDATE_TASK_ERROR', message: error.message || 'Unknown error updating task' },
fromCache: false // This operation always modifies state and should never be cached fromCache: false
}; };
} catch (error) { } finally {
log.error(`Error updating task by ID: ${error.message}`); // Make sure to restore normal logging even if there's an error
return { disableSilentMode();
success: false, }
error: { } catch (error) {
code: 'UPDATE_TASK_ERROR', // Ensure silent mode is disabled
message: error.message || 'Unknown error updating task' disableSilentMode();
},
fromCache: false log.error(`Error updating task by ID: ${error.message}`);
}; return {
} finally { success: false,
// Make sure to restore normal logging even if there's an error error: { code: 'UPDATE_TASK_ERROR', message: error.message || 'Unknown error updating task' },
disableSilentMode(); fromCache: false
} };
} catch (error) { }
// Ensure silent mode is disabled }
disableSilentMode();
log.error(`Error updating task by ID: ${error.message}`);
return {
success: false,
error: {
code: 'UPDATE_TASK_ERROR',
message: error.message || 'Unknown error updating task'
},
fromCache: false
};
}
}

View File

@@ -4,184 +4,168 @@
*/ */
import { updateTasks } from '../../../../scripts/modules/task-manager.js'; import { updateTasks } from '../../../../scripts/modules/task-manager.js';
import { import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
enableSilentMode, import { findTasksJsonPath } from '../utils/path-utils.js';
disableSilentMode import {
} from '../../../../scripts/modules/utils.js'; getAnthropicClientForMCP,
import { getPerplexityClientForMCP
getAnthropicClientForMCP,
getPerplexityClientForMCP
} from '../utils/ai-client-utils.js'; } from '../utils/ai-client-utils.js';
/** /**
* Direct function wrapper for updating tasks based on new context/prompt. * Direct function wrapper for updating tasks based on new context/prompt.
* *
* @param {Object} args - Command arguments containing fromId, prompt, useResearch and tasksJsonPath. * @param {Object} args - Command arguments containing fromId, prompt, useResearch and file path options.
* @param {Object} log - Logger object. * @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data. * @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information. * @returns {Promise<Object>} - Result object with success status and data/error information.
*/ */
export async function updateTasksDirect(args, log, context = {}) { export async function updateTasksDirect(args, log, context = {}) {
const { session } = context; // Only extract session, not reportProgress const { session } = context; // Only extract session, not reportProgress
const { tasksJsonPath, from, prompt, research } = args;
try {
try { log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
// Check for the common mistake of using 'id' instead of 'from'
// Check if tasksJsonPath was provided if (args.id !== undefined && args.from === undefined) {
if (!tasksJsonPath) { 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.";
const errorMessage = 'tasksJsonPath is required but was not provided.'; log.error(errorMessage);
log.error(errorMessage); return {
return { success: false,
success: false, error: {
error: { code: 'MISSING_ARGUMENT', message: errorMessage }, code: 'PARAMETER_MISMATCH',
fromCache: false message: errorMessage,
}; suggestion: "Use 'from' parameter instead of 'id', or use the 'update_task' tool for single task updates"
} },
fromCache: false
// Check for the common mistake of using 'id' instead of 'from' };
if (args.id !== undefined && 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."; // Check required parameters
log.error(errorMessage); if (!args.from) {
return { const errorMessage = 'No from ID specified. Please provide a task ID to start updating from.';
success: false, log.error(errorMessage);
error: { return {
code: 'PARAMETER_MISMATCH', success: false,
message: errorMessage, error: { code: 'MISSING_FROM_ID', message: errorMessage },
suggestion: fromCache: false
"Use 'from' parameter instead of 'id', or use the 'update_task' tool for single task updates" };
}, }
fromCache: false
}; if (!args.prompt) {
} const errorMessage = 'No prompt specified. Please provide a prompt with new context for task updates.';
log.error(errorMessage);
// Check required parameters return {
if (!from) { success: false,
const errorMessage = error: { code: 'MISSING_PROMPT', message: errorMessage },
'No from ID specified. Please provide a task ID to start updating from.'; fromCache: false
log.error(errorMessage); };
return { }
success: false,
error: { code: 'MISSING_FROM_ID', message: errorMessage }, // Parse fromId - handle both string and number values
fromCache: false let fromId;
}; if (typeof args.from === 'string') {
} fromId = parseInt(args.from, 10);
if (isNaN(fromId)) {
if (!prompt) { const errorMessage = `Invalid from ID: ${args.from}. Task ID must be a positive integer.`;
const errorMessage = log.error(errorMessage);
'No prompt specified. Please provide a prompt with new context for task updates.'; return {
log.error(errorMessage); success: false,
return { error: { code: 'INVALID_FROM_ID', message: errorMessage },
success: false, fromCache: false
error: { code: 'MISSING_PROMPT', message: errorMessage }, };
fromCache: false }
}; } else {
} fromId = args.from;
}
// Parse fromId - handle both string and number values
let fromId; // Get tasks file path
if (typeof from === 'string') { let tasksPath;
fromId = parseInt(from, 10); try {
if (isNaN(fromId)) { tasksPath = findTasksJsonPath(args, log);
const errorMessage = `Invalid from ID: ${from}. Task ID must be a positive integer.`; } catch (error) {
log.error(errorMessage); log.error(`Error finding tasks file: ${error.message}`);
return { return {
success: false, success: false,
error: { code: 'INVALID_FROM_ID', message: errorMessage }, error: { code: 'TASKS_FILE_ERROR', message: error.message },
fromCache: false fromCache: false
}; };
} }
} else {
fromId = from; // Get research flag
} const useResearch = args.research === true;
// Get research flag // Initialize appropriate AI client based on research flag
const useResearch = research === true; let aiClient;
try {
// Initialize appropriate AI client based on research flag if (useResearch) {
let aiClient; log.info('Using Perplexity AI for research-backed task updates');
try { aiClient = await getPerplexityClientForMCP(session, log);
if (useResearch) { } else {
log.info('Using Perplexity AI for research-backed task updates'); log.info('Using Claude AI for task updates');
aiClient = await getPerplexityClientForMCP(session, log); aiClient = getAnthropicClientForMCP(session, log);
} else { }
log.info('Using Claude AI for task updates'); } catch (error) {
aiClient = getAnthropicClientForMCP(session, log); log.error(`Failed to initialize AI client: ${error.message}`);
} return {
} catch (error) { success: false,
log.error(`Failed to initialize AI client: ${error.message}`); error: {
return { code: 'AI_CLIENT_ERROR',
success: false, message: `Cannot initialize AI client: ${error.message}`
error: { },
code: 'AI_CLIENT_ERROR', fromCache: false
message: `Cannot initialize AI client: ${error.message}` };
}, }
fromCache: false
}; log.info(`Updating tasks from ID ${fromId} with prompt "${args.prompt}" and research: ${useResearch}`);
}
try {
log.info( // Enable silent mode to prevent console logs from interfering with JSON response
`Updating tasks from ID ${fromId} with prompt "${prompt}" and research: ${useResearch}` enableSilentMode();
);
// Execute core updateTasks function, passing the AI client and session
// Create the logger wrapper to ensure compatibility with core functions await updateTasks(
const logWrapper = { tasksPath,
info: (message, ...args) => log.info(message, ...args), fromId,
warn: (message, ...args) => log.warn(message, ...args), args.prompt,
error: (message, ...args) => log.error(message, ...args), useResearch,
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 mcpLog: log,
}; session
}
try { );
// Enable silent mode to prevent console logs from interfering with JSON response
enableSilentMode(); // Since updateTasks doesn't return a value but modifies the tasks file,
// we'll return a success message
// Execute core updateTasks function, passing the AI client and session return {
await updateTasks(tasksJsonPath, fromId, prompt, useResearch, { success: true,
mcpLog: logWrapper, // Pass the wrapper instead of the raw log object data: {
session message: `Successfully updated tasks from ID ${fromId} based on the prompt`,
}); fromId,
tasksPath,
// Since updateTasks doesn't return a value but modifies the tasks file, useResearch
// we'll return a success message },
return { fromCache: false // This operation always modifies state and should never be cached
success: true, };
data: { } catch (error) {
message: `Successfully updated tasks from ID ${fromId} based on the prompt`, log.error(`Error updating tasks: ${error.message}`);
fromId, return {
tasksPath: tasksJsonPath, success: false,
useResearch error: { code: 'UPDATE_TASKS_ERROR', message: error.message || 'Unknown error updating tasks' },
}, fromCache: false
fromCache: false // This operation always modifies state and should never be cached };
}; } finally {
} catch (error) { // Make sure to restore normal logging even if there's an error
log.error(`Error updating tasks: ${error.message}`); disableSilentMode();
return { }
success: false, } catch (error) {
error: { // Ensure silent mode is disabled
code: 'UPDATE_TASKS_ERROR', disableSilentMode();
message: error.message || 'Unknown error updating tasks'
}, log.error(`Error updating tasks: ${error.message}`);
fromCache: false return {
}; success: false,
} finally { error: { code: 'UPDATE_TASKS_ERROR', message: error.message || 'Unknown error updating tasks' },
// Make sure to restore normal logging even if there's an error fromCache: false
disableSilentMode(); };
} }
} catch (error) { }
// Ensure silent mode is disabled
disableSilentMode();
log.error(`Error updating tasks: ${error.message}`);
return {
success: false,
error: {
code: 'UPDATE_TASKS_ERROR',
message: error.message || 'Unknown error updating tasks'
},
fromCache: false
};
}
}

View File

@@ -3,78 +3,63 @@
*/ */
import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js'; import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { import { findTasksJsonPath } from '../utils/path-utils.js';
enableSilentMode, import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
disableSilentMode
} from '../../../../scripts/modules/utils.js';
import fs from 'fs'; import fs from 'fs';
/** /**
* Validate dependencies in tasks.json * Validate dependencies in tasks.json
* @param {Object} args - Function arguments * @param {Object} args - Function arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file. * @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>} * @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/ */
export async function validateDependenciesDirect(args, log) { export async function validateDependenciesDirect(args, log) {
// Destructure the explicit tasksJsonPath try {
const { tasksJsonPath } = args; log.info(`Validating dependencies in tasks...`);
if (!tasksJsonPath) { // Find the tasks.json path
log.error('validateDependenciesDirect called without tasksJsonPath'); const tasksPath = findTasksJsonPath(args, log);
return {
success: false, // Verify the file exists
error: { if (!fs.existsSync(tasksPath)) {
code: 'MISSING_ARGUMENT', return {
message: 'tasksJsonPath is required' success: false,
} error: {
}; code: 'FILE_NOT_FOUND',
} message: `Tasks file not found at ${tasksPath}`
}
try { };
log.info(`Validating dependencies in tasks: ${tasksJsonPath}`); }
// Use the provided tasksJsonPath // Enable silent mode to prevent console logs from interfering with JSON response
const tasksPath = tasksJsonPath; enableSilentMode();
// Verify the file exists // Call the original command function
if (!fs.existsSync(tasksPath)) { await validateDependenciesCommand(tasksPath);
return {
success: false, // Restore normal logging
error: { disableSilentMode();
code: 'FILE_NOT_FOUND',
message: `Tasks file not found at ${tasksPath}` return {
} success: true,
}; data: {
} message: 'Dependencies validated successfully',
tasksPath
// Enable silent mode to prevent console logs from interfering with JSON response }
enableSilentMode(); };
} catch (error) {
// Call the original command function using the provided tasksPath // Make sure to restore normal logging even if there's an error
await validateDependenciesCommand(tasksPath); disableSilentMode();
// Restore normal logging log.error(`Error validating dependencies: ${error.message}`);
disableSilentMode(); return {
success: false,
return { error: {
success: true, code: 'VALIDATION_ERROR',
data: { message: error.message
message: 'Dependencies validated successfully', }
tasksPath };
} }
}; }
} catch (error) {
// Make sure to restore normal logging even if there's an error
disableSilentMode();
log.error(`Error validating dependencies: ${error.message}`);
return {
success: false,
error: {
code: 'VALIDATION_ERROR',
message: error.message
}
};
}
}

View File

@@ -28,71 +28,69 @@ import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
import { complexityReportDirect } from './direct-functions/complexity-report.js'; import { complexityReportDirect } from './direct-functions/complexity-report.js';
import { addDependencyDirect } from './direct-functions/add-dependency.js'; import { addDependencyDirect } from './direct-functions/add-dependency.js';
import { removeTaskDirect } from './direct-functions/remove-task.js'; import { removeTaskDirect } from './direct-functions/remove-task.js';
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
// Re-export utility functions // Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js'; export { findTasksJsonPath } from './utils/path-utils.js';
// Re-export AI client utilities // Re-export AI client utilities
export { export {
getAnthropicClientForMCP, getAnthropicClientForMCP,
getPerplexityClientForMCP, getPerplexityClientForMCP,
getModelConfig, getModelConfig,
getBestAvailableAIModel, getBestAvailableAIModel,
handleClaudeError handleClaudeError
} from './utils/ai-client-utils.js'; } from './utils/ai-client-utils.js';
// Use Map for potential future enhancements like introspection or dynamic dispatch // Use Map for potential future enhancements like introspection or dynamic dispatch
export const directFunctions = new Map([ export const directFunctions = new Map([
['listTasksDirect', listTasksDirect], ['listTasksDirect', listTasksDirect],
['getCacheStatsDirect', getCacheStatsDirect], ['getCacheStatsDirect', getCacheStatsDirect],
['parsePRDDirect', parsePRDDirect], ['parsePRDDirect', parsePRDDirect],
['updateTasksDirect', updateTasksDirect], ['updateTasksDirect', updateTasksDirect],
['updateTaskByIdDirect', updateTaskByIdDirect], ['updateTaskByIdDirect', updateTaskByIdDirect],
['updateSubtaskByIdDirect', updateSubtaskByIdDirect], ['updateSubtaskByIdDirect', updateSubtaskByIdDirect],
['generateTaskFilesDirect', generateTaskFilesDirect], ['generateTaskFilesDirect', generateTaskFilesDirect],
['setTaskStatusDirect', setTaskStatusDirect], ['setTaskStatusDirect', setTaskStatusDirect],
['showTaskDirect', showTaskDirect], ['showTaskDirect', showTaskDirect],
['nextTaskDirect', nextTaskDirect], ['nextTaskDirect', nextTaskDirect],
['expandTaskDirect', expandTaskDirect], ['expandTaskDirect', expandTaskDirect],
['addTaskDirect', addTaskDirect], ['addTaskDirect', addTaskDirect],
['addSubtaskDirect', addSubtaskDirect], ['addSubtaskDirect', addSubtaskDirect],
['removeSubtaskDirect', removeSubtaskDirect], ['removeSubtaskDirect', removeSubtaskDirect],
['analyzeTaskComplexityDirect', analyzeTaskComplexityDirect], ['analyzeTaskComplexityDirect', analyzeTaskComplexityDirect],
['clearSubtasksDirect', clearSubtasksDirect], ['clearSubtasksDirect', clearSubtasksDirect],
['expandAllTasksDirect', expandAllTasksDirect], ['expandAllTasksDirect', expandAllTasksDirect],
['removeDependencyDirect', removeDependencyDirect], ['removeDependencyDirect', removeDependencyDirect],
['validateDependenciesDirect', validateDependenciesDirect], ['validateDependenciesDirect', validateDependenciesDirect],
['fixDependenciesDirect', fixDependenciesDirect], ['fixDependenciesDirect', fixDependenciesDirect],
['complexityReportDirect', complexityReportDirect], ['complexityReportDirect', complexityReportDirect],
['addDependencyDirect', addDependencyDirect], ['addDependencyDirect', addDependencyDirect],
['removeTaskDirect', removeTaskDirect] ['removeTaskDirect', removeTaskDirect]
]); ]);
// Re-export all direct function implementations // Re-export all direct function implementations
export { export {
listTasksDirect, listTasksDirect,
getCacheStatsDirect, getCacheStatsDirect,
parsePRDDirect, parsePRDDirect,
updateTasksDirect, updateTasksDirect,
updateTaskByIdDirect, updateTaskByIdDirect,
updateSubtaskByIdDirect, updateSubtaskByIdDirect,
generateTaskFilesDirect, generateTaskFilesDirect,
setTaskStatusDirect, setTaskStatusDirect,
showTaskDirect, showTaskDirect,
nextTaskDirect, nextTaskDirect,
expandTaskDirect, expandTaskDirect,
addTaskDirect, addTaskDirect,
addSubtaskDirect, addSubtaskDirect,
removeSubtaskDirect, removeSubtaskDirect,
analyzeTaskComplexityDirect, analyzeTaskComplexityDirect,
clearSubtasksDirect, clearSubtasksDirect,
expandAllTasksDirect, expandAllTasksDirect,
removeDependencyDirect, removeDependencyDirect,
validateDependenciesDirect, validateDependenciesDirect,
fixDependenciesDirect, fixDependenciesDirect,
complexityReportDirect, complexityReportDirect,
addDependencyDirect, addDependencyDirect,
removeTaskDirect, removeTaskDirect
initializeProjectDirect };
};

View File

@@ -11,9 +11,9 @@ dotenv.config();
// Default model configuration from CLI environment // Default model configuration from CLI environment
const DEFAULT_MODEL_CONFIG = { const DEFAULT_MODEL_CONFIG = {
model: 'claude-3-7-sonnet-20250219', model: 'claude-3-7-sonnet-20250219',
maxTokens: 64000, maxTokens: 64000,
temperature: 0.2 temperature: 0.2
}; };
/** /**
@@ -24,28 +24,25 @@ const DEFAULT_MODEL_CONFIG = {
* @throws {Error} If API key is missing * @throws {Error} If API key is missing
*/ */
export function getAnthropicClientForMCP(session, log = console) { export function getAnthropicClientForMCP(session, log = console) {
try { try {
// Extract API key from session.env or fall back to environment variables // Extract API key from session.env or fall back to environment variables
const apiKey = const apiKey = session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
if (!apiKey) {
if (!apiKey) { throw new Error('ANTHROPIC_API_KEY not found in session environment or process.env');
throw new Error( }
'ANTHROPIC_API_KEY not found in session environment or process.env'
); // Initialize and return a new Anthropic client
} return new Anthropic({
apiKey,
// Initialize and return a new Anthropic client defaultHeaders: {
return new Anthropic({ 'anthropic-beta': 'output-128k-2025-02-19' // Include header for increased token limit
apiKey, }
defaultHeaders: { });
'anthropic-beta': 'output-128k-2025-02-19' // Include header for increased token limit } catch (error) {
} log.error(`Failed to initialize Anthropic client: ${error.message}`);
}); throw error;
} catch (error) { }
log.error(`Failed to initialize Anthropic client: ${error.message}`);
throw error;
}
} }
/** /**
@@ -56,29 +53,26 @@ export function getAnthropicClientForMCP(session, log = console) {
* @throws {Error} If API key is missing or OpenAI package can't be imported * @throws {Error} If API key is missing or OpenAI package can't be imported
*/ */
export async function getPerplexityClientForMCP(session, log = console) { export async function getPerplexityClientForMCP(session, log = console) {
try { try {
// Extract API key from session.env or fall back to environment variables // Extract API key from session.env or fall back to environment variables
const apiKey = const apiKey = session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
if (!apiKey) {
if (!apiKey) { throw new Error('PERPLEXITY_API_KEY not found in session environment or process.env');
throw new Error( }
'PERPLEXITY_API_KEY not found in session environment or process.env'
); // Dynamically import OpenAI (it may not be used in all contexts)
} const { default: OpenAI } = await import('openai');
// Dynamically import OpenAI (it may not be used in all contexts) // Initialize and return a new OpenAI client configured for Perplexity
const { default: OpenAI } = await import('openai'); return new OpenAI({
apiKey,
// Initialize and return a new OpenAI client configured for Perplexity baseURL: 'https://api.perplexity.ai'
return new OpenAI({ });
apiKey, } catch (error) {
baseURL: 'https://api.perplexity.ai' log.error(`Failed to initialize Perplexity client: ${error.message}`);
}); throw error;
} catch (error) { }
log.error(`Failed to initialize Perplexity client: ${error.message}`);
throw error;
}
} }
/** /**
@@ -88,12 +82,12 @@ export async function getPerplexityClientForMCP(session, log = console) {
* @returns {Object} Model configuration with model, maxTokens, and temperature * @returns {Object} Model configuration with model, maxTokens, and temperature
*/ */
export function getModelConfig(session, defaults = DEFAULT_MODEL_CONFIG) { export function getModelConfig(session, defaults = DEFAULT_MODEL_CONFIG) {
// Get values from session or fall back to defaults // Get values from session or fall back to defaults
return { return {
model: session?.env?.MODEL || defaults.model, model: session?.env?.MODEL || defaults.model,
maxTokens: parseInt(session?.env?.MAX_TOKENS || defaults.maxTokens), maxTokens: parseInt(session?.env?.MAX_TOKENS || defaults.maxTokens),
temperature: parseFloat(session?.env?.TEMPERATURE || defaults.temperature) temperature: parseFloat(session?.env?.TEMPERATURE || defaults.temperature)
}; };
} }
/** /**
@@ -106,78 +100,59 @@ export function getModelConfig(session, defaults = DEFAULT_MODEL_CONFIG) {
* @returns {Promise<Object>} Selected model info with type and client * @returns {Promise<Object>} Selected model info with type and client
* @throws {Error} If no AI models are available * @throws {Error} If no AI models are available
*/ */
export async function getBestAvailableAIModel( export async function getBestAvailableAIModel(session, options = {}, log = console) {
session, const { requiresResearch = false, claudeOverloaded = false } = options;
options = {},
log = console // Test case: When research is needed but no Perplexity, use Claude
) { if (requiresResearch &&
const { requiresResearch = false, claudeOverloaded = false } = options; !(session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY) &&
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
// Test case: When research is needed but no Perplexity, use Claude try {
if ( log.warn('Perplexity not available for research, using Claude');
requiresResearch && const client = getAnthropicClientForMCP(session, log);
!(session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY) && return { type: 'claude', client };
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY) } catch (error) {
) { log.error(`Claude not available: ${error.message}`);
try { throw new Error('No AI models available for research');
log.warn('Perplexity not available for research, using Claude'); }
const client = getAnthropicClientForMCP(session, log); }
return { type: 'claude', client };
} catch (error) { // Regular path: Perplexity for research when available
log.error(`Claude not available: ${error.message}`); if (requiresResearch && (session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY)) {
throw new Error('No AI models available for research'); try {
} const client = await getPerplexityClientForMCP(session, log);
} return { type: 'perplexity', client };
} catch (error) {
// Regular path: Perplexity for research when available log.warn(`Perplexity not available: ${error.message}`);
if ( // Fall through to Claude as backup
requiresResearch && }
(session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY) }
) {
try { // Test case: Claude for overloaded scenario
const client = await getPerplexityClientForMCP(session, log); if (claudeOverloaded && (session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
return { type: 'perplexity', client }; try {
} catch (error) { log.warn('Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.');
log.warn(`Perplexity not available: ${error.message}`); const client = getAnthropicClientForMCP(session, log);
// Fall through to Claude as backup return { type: 'claude', client };
} } catch (error) {
} log.error(`Claude not available despite being overloaded: ${error.message}`);
throw new Error('No AI models available');
// Test case: Claude for overloaded scenario }
if ( }
claudeOverloaded &&
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY) // Default case: Use Claude when available and not overloaded
) { if (!claudeOverloaded && (session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
try { try {
log.warn( const client = getAnthropicClientForMCP(session, log);
'Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.' return { type: 'claude', client };
); } catch (error) {
const client = getAnthropicClientForMCP(session, log); log.warn(`Claude not available: ${error.message}`);
return { type: 'claude', client }; // Fall through to error if no other options
} catch (error) { }
log.error( }
`Claude not available despite being overloaded: ${error.message}`
); // If we got here, no models were successfully initialized
throw new Error('No AI models available'); throw new Error('No AI models available. Please check your API keys.');
}
}
// Default case: Use Claude when available and not overloaded
if (
!claudeOverloaded &&
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)
) {
try {
const client = getAnthropicClientForMCP(session, log);
return { type: 'claude', client };
} catch (error) {
log.warn(`Claude not available: ${error.message}`);
// Fall through to error if no other options
}
}
// If we got here, no models were successfully initialized
throw new Error('No AI models available. Please check your API keys.');
} }
/** /**
@@ -186,28 +161,28 @@ export async function getBestAvailableAIModel(
* @returns {string} User-friendly error message * @returns {string} User-friendly error message
*/ */
export function handleClaudeError(error) { export function handleClaudeError(error) {
// Check if it's a structured error response // Check if it's a structured error response
if (error.type === 'error' && error.error) { if (error.type === 'error' && error.error) {
switch (error.error.type) { switch (error.error.type) {
case 'overloaded_error': case 'overloaded_error':
return 'Claude is currently experiencing high demand and is overloaded. Please wait a few minutes and try again.'; return 'Claude is currently experiencing high demand and is overloaded. Please wait a few minutes and try again.';
case 'rate_limit_error': case 'rate_limit_error':
return 'You have exceeded the rate limit. Please wait a few minutes before making more requests.'; return 'You have exceeded the rate limit. Please wait a few minutes before making more requests.';
case 'invalid_request_error': case 'invalid_request_error':
return 'There was an issue with the request format. If this persists, please report it as a bug.'; return 'There was an issue with the request format. If this persists, please report it as a bug.';
default: default:
return `Claude API error: ${error.error.message}`; return `Claude API error: ${error.error.message}`;
} }
} }
// Check for network/timeout errors // Check for network/timeout errors
if (error.message?.toLowerCase().includes('timeout')) { if (error.message?.toLowerCase().includes('timeout')) {
return 'The request to Claude timed out. Please try again.'; return 'The request to Claude timed out. Please try again.';
} }
if (error.message?.toLowerCase().includes('network')) { if (error.message?.toLowerCase().includes('network')) {
return 'There was a network error connecting to Claude. Please check your internet connection and try again.'; return 'There was a network error connecting to Claude. Please check your internet connection and try again.';
} }
// Default error message // Default error message
return `Error communicating with Claude: ${error.message}`; return `Error communicating with Claude: ${error.message}`;
} }

View File

@@ -1,247 +1,213 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
class AsyncOperationManager { class AsyncOperationManager {
constructor() { constructor() {
this.operations = new Map(); // Stores active operation state this.operations = new Map(); // Stores active operation state
this.completedOperations = new Map(); // Stores completed operations this.completedOperations = new Map(); // Stores completed operations
this.maxCompletedOperations = 100; // Maximum number of completed operations to store this.maxCompletedOperations = 100; // Maximum number of completed operations to store
this.listeners = new Map(); // For potential future notifications this.listeners = new Map(); // For potential future notifications
} }
/** /**
* Adds an operation to be executed asynchronously. * Adds an operation to be executed asynchronously.
* @param {Function} operationFn - The async function to execute (e.g., a Direct function). * @param {Function} operationFn - The async function to execute (e.g., a Direct function).
* @param {Object} args - Arguments to pass to the operationFn. * @param {Object} args - Arguments to pass to the operationFn.
* @param {Object} context - The MCP tool context { log, reportProgress, session }. * @param {Object} context - The MCP tool context { log, reportProgress, session }.
* @returns {string} The unique ID assigned to this operation. * @returns {string} The unique ID assigned to this operation.
*/ */
addOperation(operationFn, args, context) { addOperation(operationFn, args, context) {
const operationId = `op-${uuidv4()}`; const operationId = `op-${uuidv4()}`;
const operation = { const operation = {
id: operationId, id: operationId,
status: 'pending', status: 'pending',
startTime: Date.now(), startTime: Date.now(),
endTime: null, endTime: null,
result: null, result: null,
error: null, error: null,
// Store necessary parts of context, especially log for background execution // Store necessary parts of context, especially log for background execution
log: context.log, log: context.log,
reportProgress: context.reportProgress, // Pass reportProgress through reportProgress: context.reportProgress, // Pass reportProgress through
session: context.session // Pass session through if needed by the operationFn session: context.session // Pass session through if needed by the operationFn
}; };
this.operations.set(operationId, operation); this.operations.set(operationId, operation);
this.log(operationId, 'info', `Operation added.`); this.log(operationId, 'info', `Operation added.`);
// Start execution in the background (don't await here) // Start execution in the background (don't await here)
this._runOperation(operationId, operationFn, args, context).catch((err) => { this._runOperation(operationId, operationFn, args, context).catch(err => {
// Catch unexpected errors during the async execution setup itself // Catch unexpected errors during the async execution setup itself
this.log( this.log(operationId, 'error', `Critical error starting operation: ${err.message}`, { stack: err.stack });
operationId, operation.status = 'failed';
'error', operation.error = { code: 'MANAGER_EXECUTION_ERROR', message: err.message };
`Critical error starting operation: ${err.message}`, operation.endTime = Date.now();
{ stack: err.stack }
); // Move to completed operations
operation.status = 'failed'; this._moveToCompleted(operationId);
operation.error = { });
code: 'MANAGER_EXECUTION_ERROR',
message: err.message
};
operation.endTime = Date.now();
// Move to completed operations return operationId;
this._moveToCompleted(operationId); }
});
return operationId; /**
} * Internal function to execute the operation.
* @param {string} operationId - The ID of the operation.
* @param {Function} operationFn - The async function to execute.
* @param {Object} args - Arguments for the function.
* @param {Object} context - The original MCP tool context.
*/
async _runOperation(operationId, operationFn, args, context) {
const operation = this.operations.get(operationId);
if (!operation) return; // Should not happen
/** operation.status = 'running';
* Internal function to execute the operation. this.log(operationId, 'info', `Operation running.`);
* @param {string} operationId - The ID of the operation. this.emit('statusChanged', { operationId, status: 'running' });
* @param {Function} operationFn - The async function to execute.
* @param {Object} args - Arguments for the function.
* @param {Object} context - The original MCP tool context.
*/
async _runOperation(operationId, operationFn, args, context) {
const operation = this.operations.get(operationId);
if (!operation) return; // Should not happen
operation.status = 'running'; try {
this.log(operationId, 'info', `Operation running.`); // Pass the necessary context parts to the direct function
this.emit('statusChanged', { operationId, status: 'running' }); // The direct function needs to be adapted if it needs reportProgress
// We pass the original context's log, plus our wrapped reportProgress
const result = await operationFn(args, operation.log, {
reportProgress: (progress) => this._handleProgress(operationId, progress),
mcpLog: operation.log, // Pass log as mcpLog if direct fn expects it
session: operation.session
});
operation.status = result.success ? 'completed' : 'failed';
operation.result = result.success ? result.data : null;
operation.error = result.success ? null : result.error;
this.log(operationId, 'info', `Operation finished with status: ${operation.status}`);
try { } catch (error) {
// Pass the necessary context parts to the direct function this.log(operationId, 'error', `Operation failed with error: ${error.message}`, { stack: error.stack });
// The direct function needs to be adapted if it needs reportProgress operation.status = 'failed';
// We pass the original context's log, plus our wrapped reportProgress operation.error = { code: 'OPERATION_EXECUTION_ERROR', message: error.message };
const result = await operationFn(args, operation.log, { } finally {
reportProgress: (progress) => operation.endTime = Date.now();
this._handleProgress(operationId, progress), this.emit('statusChanged', { operationId, status: operation.status, result: operation.result, error: operation.error });
mcpLog: operation.log, // Pass log as mcpLog if direct fn expects it
session: operation.session // Move to completed operations if done or failed
}); if (operation.status === 'completed' || operation.status === 'failed') {
this._moveToCompleted(operationId);
}
}
}
/**
* Move an operation from active operations to completed operations history.
* @param {string} operationId - The ID of the operation to move.
* @private
*/
_moveToCompleted(operationId) {
const operation = this.operations.get(operationId);
if (!operation) return;
// Store only the necessary data in completed operations
const completedData = {
id: operation.id,
status: operation.status,
startTime: operation.startTime,
endTime: operation.endTime,
result: operation.result,
error: operation.error,
};
this.completedOperations.set(operationId, completedData);
this.operations.delete(operationId);
// Trim completed operations if exceeding maximum
if (this.completedOperations.size > this.maxCompletedOperations) {
// Get the oldest operation (sorted by endTime)
const oldest = [...this.completedOperations.entries()]
.sort((a, b) => a[1].endTime - b[1].endTime)[0];
if (oldest) {
this.completedOperations.delete(oldest[0]);
}
}
}
/**
* Handles progress updates from the running operation and forwards them.
* @param {string} operationId - The ID of the operation reporting progress.
* @param {Object} progress - The progress object { progress, total? }.
*/
_handleProgress(operationId, progress) {
const operation = this.operations.get(operationId);
if (operation && operation.reportProgress) {
try {
// Use the reportProgress function captured from the original context
operation.reportProgress(progress);
this.log(operationId, 'debug', `Reported progress: ${JSON.stringify(progress)}`);
} catch(err) {
this.log(operationId, 'warn', `Failed to report progress: ${err.message}`);
// Don't stop the operation, just log the reporting failure
}
}
}
operation.status = result.success ? 'completed' : 'failed'; /**
operation.result = result.success ? result.data : null; * Retrieves the status and result/error of an operation.
operation.error = result.success ? null : result.error; * @param {string} operationId - The ID of the operation.
this.log( * @returns {Object | null} The operation details or null if not found.
operationId, */
'info', getStatus(operationId) {
`Operation finished with status: ${operation.status}` // First check active operations
); const operation = this.operations.get(operationId);
} catch (error) { if (operation) {
this.log( return {
operationId, id: operation.id,
'error', status: operation.status,
`Operation failed with error: ${error.message}`, startTime: operation.startTime,
{ stack: error.stack } endTime: operation.endTime,
); result: operation.result,
operation.status = 'failed'; error: operation.error,
operation.error = { };
code: 'OPERATION_EXECUTION_ERROR', }
message: error.message
}; // Then check completed operations
} finally { const completedOperation = this.completedOperations.get(operationId);
operation.endTime = Date.now(); if (completedOperation) {
this.emit('statusChanged', { return completedOperation;
operationId, }
status: operation.status,
result: operation.result, // Operation not found in either active or completed
error: operation.error return {
}); error: {
code: 'OPERATION_NOT_FOUND',
message: `Operation ID ${operationId} not found. It may have been completed and removed from history, or the ID may be invalid.`
},
status: 'not_found'
};
}
/**
* Internal logging helper to prefix logs with the operation ID.
* @param {string} operationId - The ID of the operation.
* @param {'info'|'warn'|'error'|'debug'} level - Log level.
* @param {string} message - Log message.
* @param {Object} [meta] - Additional metadata.
*/
log(operationId, level, message, meta = {}) {
const operation = this.operations.get(operationId);
// Use the logger instance associated with the operation if available, otherwise console
const logger = operation?.log || console;
const logFn = logger[level] || logger.log || console.log; // Fallback
logFn(`[AsyncOp ${operationId}] ${message}`, meta);
}
// Move to completed operations if done or failed // --- Basic Event Emitter ---
if (operation.status === 'completed' || operation.status === 'failed') { on(eventName, listener) {
this._moveToCompleted(operationId); if (!this.listeners.has(eventName)) {
} this.listeners.set(eventName, []);
} }
} this.listeners.get(eventName).push(listener);
}
/** emit(eventName, data) {
* Move an operation from active operations to completed operations history. if (this.listeners.has(eventName)) {
* @param {string} operationId - The ID of the operation to move. this.listeners.get(eventName).forEach(listener => listener(data));
* @private }
*/ }
_moveToCompleted(operationId) {
const operation = this.operations.get(operationId);
if (!operation) return;
// Store only the necessary data in completed operations
const completedData = {
id: operation.id,
status: operation.status,
startTime: operation.startTime,
endTime: operation.endTime,
result: operation.result,
error: operation.error
};
this.completedOperations.set(operationId, completedData);
this.operations.delete(operationId);
// Trim completed operations if exceeding maximum
if (this.completedOperations.size > this.maxCompletedOperations) {
// Get the oldest operation (sorted by endTime)
const oldest = [...this.completedOperations.entries()].sort(
(a, b) => a[1].endTime - b[1].endTime
)[0];
if (oldest) {
this.completedOperations.delete(oldest[0]);
}
}
}
/**
* Handles progress updates from the running operation and forwards them.
* @param {string} operationId - The ID of the operation reporting progress.
* @param {Object} progress - The progress object { progress, total? }.
*/
_handleProgress(operationId, progress) {
const operation = this.operations.get(operationId);
if (operation && operation.reportProgress) {
try {
// Use the reportProgress function captured from the original context
operation.reportProgress(progress);
this.log(
operationId,
'debug',
`Reported progress: ${JSON.stringify(progress)}`
);
} catch (err) {
this.log(
operationId,
'warn',
`Failed to report progress: ${err.message}`
);
// Don't stop the operation, just log the reporting failure
}
}
}
/**
* Retrieves the status and result/error of an operation.
* @param {string} operationId - The ID of the operation.
* @returns {Object | null} The operation details or null if not found.
*/
getStatus(operationId) {
// First check active operations
const operation = this.operations.get(operationId);
if (operation) {
return {
id: operation.id,
status: operation.status,
startTime: operation.startTime,
endTime: operation.endTime,
result: operation.result,
error: operation.error
};
}
// Then check completed operations
const completedOperation = this.completedOperations.get(operationId);
if (completedOperation) {
return completedOperation;
}
// Operation not found in either active or completed
return {
error: {
code: 'OPERATION_NOT_FOUND',
message: `Operation ID ${operationId} not found. It may have been completed and removed from history, or the ID may be invalid.`
},
status: 'not_found'
};
}
/**
* Internal logging helper to prefix logs with the operation ID.
* @param {string} operationId - The ID of the operation.
* @param {'info'|'warn'|'error'|'debug'} level - Log level.
* @param {string} message - Log message.
* @param {Object} [meta] - Additional metadata.
*/
log(operationId, level, message, meta = {}) {
const operation = this.operations.get(operationId);
// Use the logger instance associated with the operation if available, otherwise console
const logger = operation?.log || console;
const logFn = logger[level] || logger.log || console.log; // Fallback
logFn(`[AsyncOp ${operationId}] ${message}`, meta);
}
// --- Basic Event Emitter ---
on(eventName, listener) {
if (!this.listeners.has(eventName)) {
this.listeners.set(eventName, []);
}
this.listeners.get(eventName).push(listener);
}
emit(eventName, data) {
if (this.listeners.has(eventName)) {
this.listeners.get(eventName).forEach((listener) => listener(data));
}
}
} }
// Export a singleton instance // Export a singleton instance

View File

@@ -6,42 +6,38 @@
* @returns {Promise<any>} The result of the actionFn. * @returns {Promise<any>} The result of the actionFn.
*/ */
export async function withSessionEnv(sessionEnv, actionFn) { export async function withSessionEnv(sessionEnv, actionFn) {
if ( if (!sessionEnv || typeof sessionEnv !== 'object' || Object.keys(sessionEnv).length === 0) {
!sessionEnv || // If no sessionEnv is provided, just run the action directly
typeof sessionEnv !== 'object' || return await actionFn();
Object.keys(sessionEnv).length === 0 }
) {
// If no sessionEnv is provided, just run the action directly const originalEnv = {};
return await actionFn(); const keysToRestore = [];
}
// Set environment variables from sessionEnv
const originalEnv = {}; for (const key in sessionEnv) {
const keysToRestore = []; if (Object.prototype.hasOwnProperty.call(sessionEnv, key)) {
// Store original value if it exists, otherwise mark for deletion
// Set environment variables from sessionEnv if (process.env[key] !== undefined) {
for (const key in sessionEnv) { originalEnv[key] = process.env[key];
if (Object.prototype.hasOwnProperty.call(sessionEnv, key)) { }
// Store original value if it exists, otherwise mark for deletion keysToRestore.push(key);
if (process.env[key] !== undefined) { process.env[key] = sessionEnv[key];
originalEnv[key] = process.env[key]; }
} }
keysToRestore.push(key);
process.env[key] = sessionEnv[key]; try {
} // Execute the provided action function
} return await actionFn();
} finally {
try { // Restore original environment variables
// Execute the provided action function for (const key of keysToRestore) {
return await actionFn(); if (Object.prototype.hasOwnProperty.call(originalEnv, key)) {
} finally { process.env[key] = originalEnv[key];
// Restore original environment variables } else {
for (const key of keysToRestore) { // If the key didn't exist originally, delete it
if (Object.prototype.hasOwnProperty.call(originalEnv, key)) { delete process.env[key];
process.env[key] = originalEnv[key]; }
} else { }
// If the key didn't exist originally, delete it }
delete process.env[key]; }
}
}
}
}

View File

@@ -1,9 +1,9 @@
/** /**
* path-utils.js * path-utils.js
* Utility functions for file path operations in Task Master * Utility functions for file path operations in Task Master
* *
* This module provides robust path resolution for both: * This module provides robust path resolution for both:
* 1. PACKAGE PATH: Where task-master code is installed * 1. PACKAGE PATH: Where task-master code is installed
* (global node_modules OR local ./node_modules/task-master OR direct from repo) * (global node_modules OR local ./node_modules/task-master OR direct from repo)
* 2. PROJECT PATH: Where user's tasks.json resides (typically user's project root) * 2. PROJECT PATH: Where user's tasks.json resides (typically user's project root)
*/ */
@@ -18,43 +18,43 @@ export let lastFoundProjectRoot = null;
// Project marker files that indicate a potential project root // Project marker files that indicate a potential project root
export const PROJECT_MARKERS = [ export const PROJECT_MARKERS = [
// Task Master specific // Task Master specific
'tasks.json', 'tasks.json',
'tasks/tasks.json', 'tasks/tasks.json',
// Common version control // Common version control
'.git', '.git',
'.svn', '.svn',
// Common package files // Common package files
'package.json', 'package.json',
'pyproject.toml', 'pyproject.toml',
'Gemfile', 'Gemfile',
'go.mod', 'go.mod',
'Cargo.toml', 'Cargo.toml',
// Common IDE/editor folders // Common IDE/editor folders
'.cursor', '.cursor',
'.vscode', '.vscode',
'.idea', '.idea',
// Common dependency directories (check if directory) // Common dependency directories (check if directory)
'node_modules', 'node_modules',
'venv', 'venv',
'.venv', '.venv',
// Common config files // Common config files
'.env', '.env',
'.eslintrc', '.eslintrc',
'tsconfig.json', 'tsconfig.json',
'babel.config.js', 'babel.config.js',
'jest.config.js', 'jest.config.js',
'webpack.config.js', 'webpack.config.js',
// Common CI/CD files // Common CI/CD files
'.github/workflows', '.github/workflows',
'.gitlab-ci.yml', '.gitlab-ci.yml',
'.circleci/config.yml' '.circleci/config.yml'
]; ];
/** /**
@@ -63,15 +63,15 @@ export const PROJECT_MARKERS = [
* @returns {string} - Absolute path to the package installation directory * @returns {string} - Absolute path to the package installation directory
*/ */
export function getPackagePath() { export function getPackagePath() {
// When running from source, __dirname is the directory containing this file // When running from source, __dirname is the directory containing this file
// When running from npm, we need to find the package root // When running from npm, we need to find the package root
const thisFilePath = fileURLToPath(import.meta.url); const thisFilePath = fileURLToPath(import.meta.url);
const thisFileDir = path.dirname(thisFilePath); const thisFileDir = path.dirname(thisFilePath);
// Navigate from core/utils up to the package root // Navigate from core/utils up to the package root
// In dev: /path/to/task-master/mcp-server/src/core/utils -> /path/to/task-master // In dev: /path/to/task-master/mcp-server/src/core/utils -> /path/to/task-master
// In npm: /path/to/node_modules/task-master/mcp-server/src/core/utils -> /path/to/node_modules/task-master // In npm: /path/to/node_modules/task-master/mcp-server/src/core/utils -> /path/to/node_modules/task-master
return path.resolve(thisFileDir, '../../../../'); return path.resolve(thisFileDir, '../../../../');
} }
/** /**
@@ -82,73 +82,62 @@ export function getPackagePath() {
* @throws {Error} - If tasks.json cannot be found. * @throws {Error} - If tasks.json cannot be found.
*/ */
export function findTasksJsonPath(args, log) { export function findTasksJsonPath(args, log) {
// PRECEDENCE ORDER for finding tasks.json: // PRECEDENCE ORDER for finding tasks.json:
// 1. Explicitly provided `projectRoot` in args (Highest priority, expected in MCP context) // 1. Explicitly provided `projectRoot` in args (Highest priority, expected in MCP context)
// 2. Previously found/cached `lastFoundProjectRoot` (primarily for CLI performance) // 2. Previously found/cached `lastFoundProjectRoot` (primarily for CLI performance)
// 3. Search upwards from current working directory (`process.cwd()`) - CLI usage // 3. Search upwards from current working directory (`process.cwd()`) - CLI usage
// 1. If project root is explicitly provided (e.g., from MCP session), use it directly
if (args.projectRoot) {
const projectRoot = args.projectRoot;
log.info(`Using explicitly provided project root: ${projectRoot}`);
try {
// This will throw if tasks.json isn't found within this root
return findTasksJsonInDirectory(projectRoot, args.file, log);
} catch (error) {
// Include debug info in error
const debugInfo = {
projectRoot,
currentDir: process.cwd(),
serverDir: path.dirname(process.argv[1]),
possibleProjectRoot: path.resolve(path.dirname(process.argv[1]), '../..'),
lastFoundProjectRoot,
searchedPaths: error.message
};
error.message = `Tasks file not found in any of the expected locations relative to project root "${projectRoot}" (from session).\nDebug Info: ${JSON.stringify(debugInfo, null, 2)}`;
throw error;
}
}
// --- Fallback logic primarily for CLI or when projectRoot isn't passed ---
// 1. If project root is explicitly provided (e.g., from MCP session), use it directly // 2. If we have a last known project root that worked, try it first
if (args.projectRoot) { if (lastFoundProjectRoot) {
const projectRoot = args.projectRoot; log.info(`Trying last known project root: ${lastFoundProjectRoot}`);
log.info(`Using explicitly provided project root: ${projectRoot}`); try {
try { // Use the cached root
// This will throw if tasks.json isn't found within this root const tasksPath = findTasksJsonInDirectory(lastFoundProjectRoot, args.file, log);
return findTasksJsonInDirectory(projectRoot, args.file, log); return tasksPath; // Return if found in cached root
} catch (error) { } catch (error) {
// Include debug info in error log.info(`Task file not found in last known project root, continuing search.`);
const debugInfo = { // Continue with search if not found in cache
projectRoot, }
currentDir: process.cwd(), }
serverDir: path.dirname(process.argv[1]),
possibleProjectRoot: path.resolve( // 3. Start search from current directory (most common CLI scenario)
path.dirname(process.argv[1]), const startDir = process.cwd();
'../..' log.info(`Searching for tasks.json starting from current directory: ${startDir}`);
),
lastFoundProjectRoot, // Try to find tasks.json by walking up the directory tree from cwd
searchedPaths: error.message try {
}; // This will throw if not found in the CWD tree
return findTasksJsonWithParentSearch(startDir, args.file, log);
error.message = `Tasks file not found in any of the expected locations relative to project root "${projectRoot}" (from session).\nDebug Info: ${JSON.stringify(debugInfo, null, 2)}`; } catch (error) {
throw error; // If all attempts fail, augment and throw the original error from CWD search
} error.message = `${error.message}\n\nPossible solutions:\n1. Run the command from your project directory containing tasks.json\n2. Use --project-root=/path/to/project to specify the project location (if using CLI)\n3. Ensure the project root is correctly passed from the client (if using MCP)\n\nCurrent working directory: ${startDir}\nLast known project root: ${lastFoundProjectRoot}\nProject root from args: ${args.projectRoot}`;
} throw error;
}
// --- Fallback logic primarily for CLI or when projectRoot isn't passed ---
// 2. If we have a last known project root that worked, try it first
if (lastFoundProjectRoot) {
log.info(`Trying last known project root: ${lastFoundProjectRoot}`);
try {
// Use the cached root
const tasksPath = findTasksJsonInDirectory(
lastFoundProjectRoot,
args.file,
log
);
return tasksPath; // Return if found in cached root
} catch (error) {
log.info(
`Task file not found in last known project root, continuing search.`
);
// Continue with search if not found in cache
}
}
// 3. Start search from current directory (most common CLI scenario)
const startDir = process.cwd();
log.info(
`Searching for tasks.json starting from current directory: ${startDir}`
);
// Try to find tasks.json by walking up the directory tree from cwd
try {
// This will throw if not found in the CWD tree
return findTasksJsonWithParentSearch(startDir, args.file, log);
} catch (error) {
// If all attempts fail, augment and throw the original error from CWD search
error.message = `${error.message}\n\nPossible solutions:\n1. Run the command from your project directory containing tasks.json\n2. Use --project-root=/path/to/project to specify the project location (if using CLI)\n3. Ensure the project root is correctly passed from the client (if using MCP)\n\nCurrent working directory: ${startDir}\nLast known project root: ${lastFoundProjectRoot}\nProject root from args: ${args.projectRoot}`;
throw error;
}
} }
/** /**
@@ -157,11 +146,11 @@ export function findTasksJsonPath(args, log) {
* @returns {boolean} - True if the directory contains any project markers * @returns {boolean} - True if the directory contains any project markers
*/ */
function hasProjectMarkers(dirPath) { function hasProjectMarkers(dirPath) {
return PROJECT_MARKERS.some((marker) => { return PROJECT_MARKERS.some(marker => {
const markerPath = path.join(dirPath, marker); const markerPath = path.join(dirPath, marker);
// Check if the marker exists as either a file or directory // Check if the marker exists as either a file or directory
return fs.existsSync(markerPath); return fs.existsSync(markerPath);
}); });
} }
/** /**
@@ -173,41 +162,39 @@ function hasProjectMarkers(dirPath) {
* @throws {Error} - If tasks.json cannot be found * @throws {Error} - If tasks.json cannot be found
*/ */
function findTasksJsonInDirectory(dirPath, explicitFilePath, log) { function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
const possiblePaths = []; const possiblePaths = [];
// 1. If a file is explicitly provided relative to dirPath // 1. If a file is explicitly provided relative to dirPath
if (explicitFilePath) { if (explicitFilePath) {
possiblePaths.push(path.resolve(dirPath, explicitFilePath)); possiblePaths.push(path.resolve(dirPath, explicitFilePath));
} }
// 2. Check the standard locations relative to dirPath // 2. Check the standard locations relative to dirPath
possiblePaths.push( possiblePaths.push(
path.join(dirPath, 'tasks.json'), path.join(dirPath, 'tasks.json'),
path.join(dirPath, 'tasks', 'tasks.json') path.join(dirPath, 'tasks', 'tasks.json')
); );
log.info(`Checking potential task file paths: ${possiblePaths.join(', ')}`); log.info(`Checking potential task file paths: ${possiblePaths.join(', ')}`);
// Find the first existing path // Find the first existing path
for (const p of possiblePaths) { for (const p of possiblePaths) {
log.info(`Checking if exists: ${p}`); log.info(`Checking if exists: ${p}`);
const exists = fs.existsSync(p); const exists = fs.existsSync(p);
log.info(`Path ${p} exists: ${exists}`); log.info(`Path ${p} exists: ${exists}`);
if (exists) {
log.info(`Found tasks file at: ${p}`);
// Store the project root for future use
lastFoundProjectRoot = dirPath;
return p;
}
}
if (exists) { // If no file was found, throw an error
log.info(`Found tasks file at: ${p}`); const error = new Error(`Tasks file not found in any of the expected locations relative to ${dirPath}: ${possiblePaths.join(', ')}`);
// Store the project root for future use error.code = 'TASKS_FILE_NOT_FOUND';
lastFoundProjectRoot = dirPath; throw error;
return p;
}
}
// If no file was found, throw an error
const error = new Error(
`Tasks file not found in any of the expected locations relative to ${dirPath}: ${possiblePaths.join(', ')}`
);
error.code = 'TASKS_FILE_NOT_FOUND';
throw error;
} }
/** /**
@@ -220,174 +207,66 @@ function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
* @throws {Error} - If tasks.json cannot be found in any parent directory * @throws {Error} - If tasks.json cannot be found in any parent directory
*/ */
function findTasksJsonWithParentSearch(startDir, explicitFilePath, log) { function findTasksJsonWithParentSearch(startDir, explicitFilePath, log) {
let currentDir = startDir; let currentDir = startDir;
const rootDir = path.parse(currentDir).root; const rootDir = path.parse(currentDir).root;
// Keep traversing up until we hit the root directory // Keep traversing up until we hit the root directory
while (currentDir !== rootDir) { while (currentDir !== rootDir) {
// First check for tasks.json directly // First check for tasks.json directly
try { try {
return findTasksJsonInDirectory(currentDir, explicitFilePath, log); return findTasksJsonInDirectory(currentDir, explicitFilePath, log);
} catch (error) { } catch (error) {
// If tasks.json not found but the directory has project markers, // If tasks.json not found but the directory has project markers,
// log it as a potential project root (helpful for debugging) // log it as a potential project root (helpful for debugging)
if (hasProjectMarkers(currentDir)) { if (hasProjectMarkers(currentDir)) {
log.info(`Found project markers in ${currentDir}, but no tasks.json`); log.info(`Found project markers in ${currentDir}, but no tasks.json`);
} }
// Move up to parent directory // Move up to parent directory
const parentDir = path.dirname(currentDir); const parentDir = path.dirname(currentDir);
// Check if we've reached the root // Check if we've reached the root
if (parentDir === currentDir) { if (parentDir === currentDir) {
break; break;
} }
log.info( log.info(`Tasks file not found in ${currentDir}, searching in parent directory: ${parentDir}`);
`Tasks file not found in ${currentDir}, searching in parent directory: ${parentDir}` currentDir = parentDir;
); }
currentDir = parentDir; }
}
} // If we've searched all the way to the root and found nothing
const error = new Error(`Tasks file not found in ${startDir} or any parent directory.`);
// If we've searched all the way to the root and found nothing error.code = 'TASKS_FILE_NOT_FOUND';
const error = new Error( throw error;
`Tasks file not found in ${startDir} or any parent directory.`
);
error.code = 'TASKS_FILE_NOT_FOUND';
throw error;
} }
// Note: findTasksWithNpmConsideration is not used by findTasksJsonPath and might be legacy or used elsewhere. // Note: findTasksWithNpmConsideration is not used by findTasksJsonPath and might be legacy or used elsewhere.
// If confirmed unused, it could potentially be removed in a separate cleanup. // If confirmed unused, it could potentially be removed in a separate cleanup.
function findTasksWithNpmConsideration(startDir, log) { function findTasksWithNpmConsideration(startDir, log) {
// First try our recursive parent search from cwd // First try our recursive parent search from cwd
try { try {
return findTasksJsonWithParentSearch(startDir, null, log); return findTasksJsonWithParentSearch(startDir, null, log);
} catch (error) { } catch (error) {
// If that fails, try looking relative to the executable location // If that fails, try looking relative to the executable location
const execPath = process.argv[1]; const execPath = process.argv[1];
const execDir = path.dirname(execPath); const execDir = path.dirname(execPath);
log.info(`Looking for tasks file relative to executable at: ${execDir}`); log.info(`Looking for tasks file relative to executable at: ${execDir}`);
try { try {
return findTasksJsonWithParentSearch(execDir, null, log); return findTasksJsonWithParentSearch(execDir, null, log);
} catch (secondError) { } catch (secondError) {
// If that also fails, check standard locations in user's home directory // If that also fails, check standard locations in user's home directory
const homeDir = os.homedir(); const homeDir = os.homedir();
log.info(`Looking for tasks file in home directory: ${homeDir}`); log.info(`Looking for tasks file in home directory: ${homeDir}`);
try { try {
// Check standard locations in home dir // Check standard locations in home dir
return findTasksJsonInDirectory( return findTasksJsonInDirectory(path.join(homeDir, '.task-master'), null, log);
path.join(homeDir, '.task-master'), } catch (thirdError) {
null, // If all approaches fail, throw the original error
log throw error;
); }
} catch (thirdError) { }
// If all approaches fail, throw the original error }
throw error; }
}
}
}
}
/**
* 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

@@ -1,10 +1,10 @@
import { FastMCP } from 'fastmcp'; import { FastMCP } from "fastmcp";
import path from 'path'; import path from "path";
import dotenv from 'dotenv'; import dotenv from "dotenv";
import { fileURLToPath } from 'url'; import { fileURLToPath } from "url";
import fs from 'fs'; import fs from "fs";
import logger from './logger.js'; import logger from "./logger.js";
import { registerTaskMasterTools } from './tools/index.js'; import { registerTaskMasterTools } from "./tools/index.js";
import { asyncOperationManager } from './core/utils/async-manager.js'; import { asyncOperationManager } from './core/utils/async-manager.js';
// Load environment variables // Load environment variables
@@ -18,74 +18,74 @@ const __dirname = path.dirname(__filename);
* Main MCP server class that integrates with Task Master * Main MCP server class that integrates with Task Master
*/ */
class TaskMasterMCPServer { class TaskMasterMCPServer {
constructor() { constructor() {
// Get version from package.json using synchronous fs // Get version from package.json using synchronous fs
const packagePath = path.join(__dirname, '../../package.json'); const packagePath = path.join(__dirname, "../../package.json");
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
this.options = { this.options = {
name: 'Task Master MCP Server', name: "Task Master MCP Server",
version: packageJson.version version: packageJson.version,
}; };
this.server = new FastMCP(this.options); this.server = new FastMCP(this.options);
this.initialized = false; this.initialized = false;
this.server.addResource({}); this.server.addResource({});
this.server.addResourceTemplate({}); this.server.addResourceTemplate({});
// Make the manager accessible (e.g., pass it to tool registration) // Make the manager accessible (e.g., pass it to tool registration)
this.asyncManager = asyncOperationManager; this.asyncManager = asyncOperationManager;
// Bind methods // Bind methods
this.init = this.init.bind(this); this.init = this.init.bind(this);
this.start = this.start.bind(this); this.start = this.start.bind(this);
this.stop = this.stop.bind(this); this.stop = this.stop.bind(this);
// Setup logging // Setup logging
this.logger = logger; this.logger = logger;
} }
/** /**
* Initialize the MCP server with necessary tools and routes * Initialize the MCP server with necessary tools and routes
*/ */
async init() { async init() {
if (this.initialized) return; if (this.initialized) return;
// Pass the manager instance to the tool registration function // Pass the manager instance to the tool registration function
registerTaskMasterTools(this.server, this.asyncManager); registerTaskMasterTools(this.server, this.asyncManager);
this.initialized = true; this.initialized = true;
return this; return this;
} }
/** /**
* Start the MCP server * Start the MCP server
*/ */
async start() { async start() {
if (!this.initialized) { if (!this.initialized) {
await this.init(); await this.init();
} }
// Start the FastMCP server with increased timeout // Start the FastMCP server with increased timeout
await this.server.start({ await this.server.start({
transportType: 'stdio', transportType: "stdio",
timeout: 120000 // 2 minutes timeout (in milliseconds) timeout: 120000 // 2 minutes timeout (in milliseconds)
}); });
return this; return this;
} }
/** /**
* Stop the MCP server * Stop the MCP server
*/ */
async stop() { async stop() {
if (this.server) { if (this.server) {
await this.server.stop(); await this.server.stop();
} }
} }
} }
// Export the manager from here as well, if needed elsewhere // Export the manager from here as well, if needed elsewhere

View File

@@ -1,19 +1,19 @@
import chalk from 'chalk'; import chalk from "chalk";
import { isSilentMode } from '../../scripts/modules/utils.js'; import { isSilentMode } from "../../scripts/modules/utils.js";
// Define log levels // Define log levels
const LOG_LEVELS = { const LOG_LEVELS = {
debug: 0, debug: 0,
info: 1, info: 1,
warn: 2, warn: 2,
error: 3, error: 3,
success: 4 success: 4,
}; };
// Get log level from environment or default to info // Get log level from environment or default to info
const LOG_LEVEL = process.env.LOG_LEVEL const LOG_LEVEL = process.env.LOG_LEVEL
? (LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()] ?? LOG_LEVELS.info) ? LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()] ?? LOG_LEVELS.info
: LOG_LEVELS.info; : LOG_LEVELS.info;
/** /**
* Logs a message with the specified level * Logs a message with the specified level
@@ -21,66 +21,56 @@ const LOG_LEVEL = process.env.LOG_LEVEL
* @param {...any} args - Arguments to log * @param {...any} args - Arguments to log
*/ */
function log(level, ...args) { function log(level, ...args) {
// Skip logging if silent mode is enabled // Skip logging if silent mode is enabled
if (isSilentMode()) { if (isSilentMode()) {
return; return;
} }
// Use text prefixes instead of emojis // Use text prefixes instead of emojis
const prefixes = { const prefixes = {
debug: chalk.gray('[DEBUG]'), debug: chalk.gray("[DEBUG]"),
info: chalk.blue('[INFO]'), info: chalk.blue("[INFO]"),
warn: chalk.yellow('[WARN]'), warn: chalk.yellow("[WARN]"),
error: chalk.red('[ERROR]'), error: chalk.red("[ERROR]"),
success: chalk.green('[SUCCESS]') success: chalk.green("[SUCCESS]"),
}; };
if (LOG_LEVELS[level] !== undefined && LOG_LEVELS[level] >= LOG_LEVEL) { if (LOG_LEVELS[level] !== undefined && LOG_LEVELS[level] >= LOG_LEVEL) {
const prefix = prefixes[level] || ''; const prefix = prefixes[level] || "";
let coloredArgs = args; let coloredArgs = args;
try { try {
switch (level) { switch(level) {
case 'error': case "error":
coloredArgs = args.map((arg) => coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.red(arg) : arg);
typeof arg === 'string' ? chalk.red(arg) : arg break;
); case "warn":
break; coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.yellow(arg) : arg);
case 'warn': break;
coloredArgs = args.map((arg) => case "success":
typeof arg === 'string' ? chalk.yellow(arg) : arg coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.green(arg) : arg);
); break;
break; case "info":
case 'success': coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.blue(arg) : arg);
coloredArgs = args.map((arg) => break;
typeof arg === 'string' ? chalk.green(arg) : arg case "debug":
); coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.gray(arg) : arg);
break; break;
case 'info': // default: use original args (no color)
coloredArgs = args.map((arg) => }
typeof arg === 'string' ? chalk.blue(arg) : arg } catch (colorError) {
); // Fallback if chalk fails on an argument
break; // Use console.error here for internal logger errors, separate from normal logging
case 'debug': console.error("Internal Logger Error applying chalk color:", colorError);
coloredArgs = args.map((arg) => coloredArgs = args;
typeof arg === 'string' ? chalk.gray(arg) : arg }
);
break;
// default: use original args (no color)
}
} catch (colorError) {
// Fallback if chalk fails on an argument
// Use console.error here for internal logger errors, separate from normal logging
console.error('Internal Logger Error applying chalk color:', colorError);
coloredArgs = args;
}
// Revert to console.log - FastMCP's context logger (context.log) // Revert to console.log - FastMCP's context logger (context.log)
// is responsible for directing logs correctly (e.g., to stderr) // is responsible for directing logs correctly (e.g., to stderr)
// during tool execution without upsetting the client connection. // during tool execution without upsetting the client connection.
// Logs outside of tool execution (like startup) will go to stdout. // Logs outside of tool execution (like startup) will go to stdout.
console.log(prefix, ...coloredArgs); console.log(prefix, ...coloredArgs);
} }
} }
/** /**
@@ -88,19 +78,16 @@ function log(level, ...args) {
* @returns {Object} Logger object with info, error, debug, warn, and success methods * @returns {Object} Logger object with info, error, debug, warn, and success methods
*/ */
export function createLogger() { export function createLogger() {
const createLogMethod = const createLogMethod = (level) => (...args) => log(level, ...args);
(level) =>
(...args) =>
log(level, ...args);
return { return {
debug: createLogMethod('debug'), debug: createLogMethod("debug"),
info: createLogMethod('info'), info: createLogMethod("info"),
warn: createLogMethod('warn'), warn: createLogMethod("warn"),
error: createLogMethod('error'), error: createLogMethod("error"),
success: createLogMethod('success'), success: createLogMethod("success"),
log: log // Also expose the raw log function log: log, // Also expose the raw log function
}; };
} }
// Export a default logger instance // Export a default logger instance

View File

@@ -0,0 +1 @@

View File

@@ -3,95 +3,63 @@
* Tool for adding a dependency to a task * Tool for adding a dependency to a task
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { addDependencyDirect } from '../core/task-master-core.js'; import { addDependencyDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addDependency tool with the MCP server * Register the addDependency tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerAddDependencyTool(server) { export function registerAddDependencyTool(server) {
server.addTool({ server.addTool({
name: 'add_dependency', name: "add_dependency",
description: 'Add a dependency relationship between two tasks', description: "Add a dependency relationship between two tasks",
parameters: z.object({ parameters: z.object({
id: z.string().describe('ID of task that will depend on another task'), id: z.string().describe("ID of task that will depend on another task"),
dependsOn: z dependsOn: z.string().describe("ID of task that will become a dependency"),
.string() file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
.describe('ID of task that will become a dependency'), projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
file: z }),
.string() execute: async (args, { log, session, reportProgress }) => {
.optional() try {
.describe( log.info(`Adding dependency for task ${args.id} to depend on ${args.dependsOn}`);
'Absolute path to the tasks file (default: tasks/tasks.json)' reportProgress({ progress: 0 });
),
projectRoot: z // Get project root using the utility function
.string() let rootFolder = getProjectRootFromSession(session, log);
.describe('The directory of the project. Must be an absolute path.')
}), // Fallback to args.projectRoot if session didn't provide one
execute: async (args, { log, session }) => { if (!rootFolder && args.projectRoot) {
try { rootFolder = args.projectRoot;
log.info( log.info(`Using project root from args as fallback: ${rootFolder}`);
`Adding dependency for task ${args.id} to depend on ${args.dependsOn}` }
);
// Call the direct function with the resolved rootFolder
const result = await addDependencyDirect({
projectRoot: rootFolder,
...args
}, log, { reportProgress, mcpLog: log, session});
// Get project root from args or session reportProgress({ progress: 100 });
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log); // Log result
if (result.success) {
// Ensure project root was determined log.info(`Successfully added dependency: ${result.data.message}`);
if (!rootFolder) { } else {
return createErrorResponse( log.error(`Failed to add dependency: ${result.error.message}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' }
);
} // Use handleApiResult to format the response
return handleApiResult(result, log, 'Error adding dependency');
// Resolve the path to tasks.json } catch (error) {
let tasksJsonPath; log.error(`Error in addDependency tool: ${error.message}`);
try { return createErrorResponse(error.message);
tasksJsonPath = findTasksJsonPath( }
{ projectRoot: rootFolder, file: args.file }, },
log });
); }
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
// Call the direct function with the resolved path
const result = await addDependencyDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
dependsOn: args.dependsOn
},
log
// Remove context object
);
// Log result
if (result.success) {
log.info(`Successfully added dependency: ${result.data.message}`);
} else {
log.error(`Failed to add dependency: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error adding dependency');
} catch (error) {
log.error(`Error in addDependency tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,116 +3,61 @@
* Tool for adding subtasks to existing tasks * Tool for adding subtasks to existing tasks
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { addSubtaskDirect } from '../core/task-master-core.js'; import { addSubtaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addSubtask tool with the MCP server * Register the addSubtask tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerAddSubtaskTool(server) { export function registerAddSubtaskTool(server) {
server.addTool({ server.addTool({
name: 'add_subtask', name: "add_subtask",
description: 'Add a subtask to an existing task', description: "Add a subtask to an existing task",
parameters: z.object({ parameters: z.object({
id: z.string().describe('Parent task ID (required)'), id: z.string().describe("Parent task ID (required)"),
taskId: z taskId: z.string().optional().describe("Existing task ID to convert to subtask"),
.string() title: z.string().optional().describe("Title for the new subtask (when creating a new subtask)"),
.optional() description: z.string().optional().describe("Description for the new subtask"),
.describe('Existing task ID to convert to subtask'), details: z.string().optional().describe("Implementation details for the new subtask"),
title: z status: z.string().optional().describe("Status for the new subtask (default: 'pending')"),
.string() dependencies: z.string().optional().describe("Comma-separated list of dependency IDs for the new subtask"),
.optional() file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
.describe('Title for the new subtask (when creating a new subtask)'), skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
description: z projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
.string() }),
.optional() execute: async (args, { log, session, reportProgress }) => {
.describe('Description for the new subtask'), try {
details: z log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
.string()
.optional() let rootFolder = getProjectRootFromSession(session, log);
.describe('Implementation details for the new subtask'),
status: z if (!rootFolder && args.projectRoot) {
.string() rootFolder = args.projectRoot;
.optional() log.info(`Using project root from args as fallback: ${rootFolder}`);
.describe("Status for the new subtask (default: 'pending')"), }
dependencies: z
.string() const result = await addSubtaskDirect({
.optional() projectRoot: rootFolder,
.describe('Comma-separated list of dependency IDs for the new subtask'), ...args
file: z }, log, { reportProgress, mcpLog: log, session});
.string()
.optional() if (result.success) {
.describe( log.info(`Subtask added successfully: ${result.data.message}`);
'Absolute path to the tasks file (default: tasks/tasks.json)' } else {
), log.error(`Failed to add subtask: ${result.error.message}`);
skipGenerate: z }
.boolean()
.optional() return handleApiResult(result, log, 'Error adding subtask');
.describe('Skip regenerating task files'), } catch (error) {
projectRoot: z log.error(`Error in addSubtask tool: ${error.message}`);
.string() return createErrorResponse(error.message);
.describe('The directory of the project. Must be an absolute path.') }
}), },
execute: async (args, { log, session }) => { });
try { }
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
// Get project root from args or session
const rootFolder =
args.projectRoot || 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}`
);
}
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
},
log
);
if (result.success) {
log.info(`Subtask added successfully: ${result.data.message}`);
} else {
log.error(`Failed to add subtask: ${result.error.message}`);
}
return handleApiResult(result, log, 'Error adding subtask');
} catch (error) {
log.error(`Error in addSubtask tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,118 +3,56 @@
* Tool to add a new task using AI * Tool to add a new task using AI
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
createErrorResponse, createErrorResponse,
createContentResponse, createContentResponse,
getProjectRootFromSession, getProjectRootFromSession,
executeTaskMasterCommand, executeTaskMasterCommand,
handleApiResult handleApiResult
} from './utils.js'; } from "./utils.js";
import { addTaskDirect } from '../core/task-master-core.js'; import { addTaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the addTask tool with the MCP server * Register the addTask tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerAddTaskTool(server) { export function registerAddTaskTool(server) {
server.addTool({ server.addTool({
name: 'add_task', name: "add_task",
description: 'Add a new task using AI', description: "Add a new task using AI",
parameters: z.object({ parameters: z.object({
prompt: z prompt: z.string().describe("Description of the task to add"),
.string() dependencies: z.string().optional().describe("Comma-separated list of task IDs this task depends on"),
.optional() priority: z.string().optional().describe("Task priority (high, medium, low)"),
.describe( file: z.string().optional().describe("Path to the tasks file"),
'Description of the task to add (required if not using manual fields)' projectRoot: z.string().optional().describe("Root directory of the project"),
), research: z.boolean().optional().describe("Whether to use research capabilities for task creation")
title: z }),
.string() execute: async (args, { log, reportProgress, session }) => {
.optional() try {
.describe('Task title (for manual task creation)'), log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
description: z
.string() // Get project root from session
.optional() let rootFolder = getProjectRootFromSession(session, log);
.describe('Task description (for manual task creation)'),
details: z if (!rootFolder && args.projectRoot) {
.string() rootFolder = args.projectRoot;
.optional() log.info(`Using project root from args as fallback: ${rootFolder}`);
.describe('Implementation details (for manual task creation)'), }
testStrategy: z
.string() // Call the direct function
.optional() const result = await addTaskDirect({
.describe('Test strategy (for manual task creation)'), ...args,
dependencies: z projectRoot: rootFolder
.string() }, log, { reportProgress, session });
.optional()
.describe('Comma-separated list of task IDs this task depends on'), // Return the result
priority: z return handleApiResult(result, log);
.string() } catch (error) {
.optional() log.error(`Error in add-task tool: ${error.message}`);
.describe('Task priority (high, medium, low)'), return createErrorResponse(error.message);
file: z }
.string() }
.optional() });
.describe('Path to the tasks file (default: tasks/tasks.json)'), }
projectRoot: z
.string()
.describe('The directory of the project. Must be an absolute path.'),
research: z
.boolean()
.optional()
.describe('Whether to use research capabilities for task creation')
}),
execute: async (args, { log, 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);
// 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}`
);
}
// 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
},
log,
{ session }
);
// Return the result
return handleApiResult(result, log);
} catch (error) {
log.error(`Error in add-task tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,121 +3,58 @@
* Tool for analyzing task complexity and generating recommendations * Tool for analyzing task complexity and generating recommendations
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { analyzeTaskComplexityDirect } from '../core/task-master-core.js'; import { analyzeTaskComplexityDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import path from 'path';
/** /**
* Register the analyze tool with the MCP server * Register the analyze tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerAnalyzeTool(server) { export function registerAnalyzeTool(server) {
server.addTool({ server.addTool({
name: 'analyze_project_complexity', name: "analyze_project_complexity",
description: description: "Analyze task complexity and generate expansion recommendations",
'Analyze task complexity and generate expansion recommendations', parameters: z.object({
parameters: z.object({ output: z.string().optional().describe("Output file path for the report (default: scripts/task-complexity-report.json)"),
output: z model: z.string().optional().describe("LLM model to use for analysis (defaults to configured model)"),
.string() threshold: z.union([z.number(), z.string()]).optional().describe("Minimum complexity score to recommend expansion (1-10) (default: 5)"),
.optional() file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
.describe( research: z.boolean().optional().describe("Use Perplexity AI for research-backed complexity analysis"),
'Output file path for the report (default: scripts/task-complexity-report.json)' projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
), }),
model: z execute: async (args, { log, session }) => {
.string() try {
.optional() log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
.describe(
'LLM model to use for analysis (defaults to configured model)' let rootFolder = getProjectRootFromSession(session, log);
),
threshold: z.coerce if (!rootFolder && args.projectRoot) {
.number() rootFolder = args.projectRoot;
.min(1) log.info(`Using project root from args as fallback: ${rootFolder}`);
.max(10) }
.optional()
.describe( const result = await analyzeTaskComplexityDirect({
'Minimum complexity score to recommend expansion (1-10) (default: 5)' projectRoot: rootFolder,
), ...args
file: z }, log, { session });
.string()
.optional() if (result.success) {
.describe( log.info(`Task complexity analysis complete: ${result.data.message}`);
'Absolute path to the tasks file (default: tasks/tasks.json)' log.info(`Report summary: ${JSON.stringify(result.data.reportSummary)}`);
), } else {
research: z log.error(`Failed to analyze task complexity: ${result.error.message}`);
.boolean() }
.optional()
.describe('Use Perplexity AI for research-backed complexity analysis'), return handleApiResult(result, log, 'Error analyzing task complexity');
projectRoot: z } catch (error) {
.string() log.error(`Error in analyze tool: ${error.message}`);
.describe('The directory of the project. Must be an absolute path.') return createErrorResponse(error.message);
}), }
execute: async (args, { log, session }) => { },
try { });
log.info( }
`Analyzing task complexity with args: ${JSON.stringify(args)}`
);
// Get project root from args or session
const rootFolder =
args.projectRoot || 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}`
);
}
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
},
log,
{ session }
);
if (result.success) {
log.info(`Task complexity analysis complete: ${result.data.message}`);
log.info(
`Report summary: ${JSON.stringify(result.data.reportSummary)}`
);
} else {
log.error(
`Failed to analyze task complexity: ${result.error.message}`
);
}
return handleApiResult(result, log, 'Error analyzing task complexity');
} catch (error) {
log.error(`Error in analyze tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

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

View File

@@ -3,87 +3,56 @@
* Tool for displaying the complexity analysis report * Tool for displaying the complexity analysis report
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { complexityReportDirect } from '../core/task-master-core.js'; import { complexityReportDirect } from "../core/task-master-core.js";
import path from 'path';
/** /**
* Register the complexityReport tool with the MCP server * Register the complexityReport tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerComplexityReportTool(server) { export function registerComplexityReportTool(server) {
server.addTool({ server.addTool({
name: 'complexity_report', name: "complexity_report",
description: 'Display the complexity analysis report in a readable format', description: "Display the complexity analysis report in a readable format",
parameters: z.object({ parameters: z.object({
file: z file: z.string().optional().describe("Path to the report file (default: scripts/task-complexity-report.json)"),
.string() projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
.optional() }),
.describe( execute: async (args, { log, session, reportProgress }) => {
'Path to the report file (default: scripts/task-complexity-report.json)' try {
), log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
projectRoot: z // await reportProgress({ progress: 0 });
.string()
.describe('The directory of the project. Must be an absolute path.') let rootFolder = getProjectRootFromSession(session, log);
}),
execute: async (args, { log, session }) => { if (!rootFolder && args.projectRoot) {
try { rootFolder = args.projectRoot;
log.info( log.info(`Using project root from args as fallback: ${rootFolder}`);
`Getting complexity report with args: ${JSON.stringify(args)}` }
);
const result = await complexityReportDirect({
// Get project root from args or session projectRoot: rootFolder,
const rootFolder = ...args
args.projectRoot || getProjectRootFromSession(session, log); }, log/*, { reportProgress, mcpLog: log, session}*/);
// Ensure project root was determined // await reportProgress({ progress: 100 });
if (!rootFolder) {
return createErrorResponse( if (result.success) {
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`);
); } else {
} log.error(`Failed to retrieve complexity report: ${result.error.message}`);
}
// Resolve the path to the complexity report file
// Default to scripts/task-complexity-report.json relative to root return handleApiResult(result, log, 'Error retrieving complexity report');
const reportPath = args.file } catch (error) {
? path.resolve(rootFolder, args.file) log.error(`Error in complexity-report tool: ${error.message}`);
: path.resolve(rootFolder, 'scripts', 'task-complexity-report.json'); return createErrorResponse(`Failed to retrieve complexity report: ${error.message}`);
}
const result = await complexityReportDirect( },
{ });
// Pass the explicitly resolved path }
reportPath: reportPath
// No other args specific to this tool
},
log
);
if (result.success) {
log.info(
`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`
);
} else {
log.error(
`Failed to retrieve complexity report: ${result.error.message}`
);
}
return handleApiResult(
result,
log,
'Error retrieving complexity report'
);
} catch (error) {
log.error(`Error in complexity-report tool: ${error.message}`);
return createErrorResponse(
`Failed to retrieve complexity report: ${error.message}`
);
}
}
});
}

View File

@@ -3,110 +3,57 @@
* Tool for expanding all pending tasks with subtasks * Tool for expanding all pending tasks with subtasks
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { expandAllTasksDirect } from '../core/task-master-core.js'; import { expandAllTasksDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the expandAll tool with the MCP server * Register the expandAll tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerExpandAllTool(server) { export function registerExpandAllTool(server) {
server.addTool({ server.addTool({
name: 'expand_all', name: "expand_all",
description: 'Expand all pending tasks into subtasks', description: "Expand all pending tasks into subtasks",
parameters: z.object({ parameters: z.object({
num: z num: z.string().optional().describe("Number of subtasks to generate for each task"),
.string() research: z.boolean().optional().describe("Enable Perplexity AI for research-backed subtask generation"),
.optional() prompt: z.string().optional().describe("Additional context to guide subtask generation"),
.describe('Number of subtasks to generate for each task'), force: z.boolean().optional().describe("Force regeneration of subtasks for tasks that already have them"),
research: z file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
.boolean() projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
.optional() }),
.describe( execute: async (args, { log, session }) => {
'Enable Perplexity AI for research-backed subtask generation' try {
), log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
prompt: z
.string() let rootFolder = getProjectRootFromSession(session, log);
.optional()
.describe('Additional context to guide subtask generation'), if (!rootFolder && args.projectRoot) {
force: z rootFolder = args.projectRoot;
.boolean() log.info(`Using project root from args as fallback: ${rootFolder}`);
.optional() }
.describe(
'Force regeneration of subtasks for tasks that already have them' const result = await expandAllTasksDirect({
), projectRoot: rootFolder,
file: z ...args
.string() }, log, { session });
.optional()
.describe( if (result.success) {
'Absolute path to the tasks file (default: tasks/tasks.json)' log.info(`Successfully expanded all tasks: ${result.data.message}`);
), } else {
projectRoot: z log.error(`Failed to expand all tasks: ${result.error?.message || 'Unknown error'}`);
.string() }
.describe('The directory of the project. Must be an absolute path.')
}), return handleApiResult(result, log, 'Error expanding all tasks');
execute: async (args, { log, session }) => { } catch (error) {
try { log.error(`Error in expand-all tool: ${error.message}`);
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`); return createErrorResponse(error.message);
}
// Get project root from args or session },
const rootFolder = });
args.projectRoot || 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}`
);
}
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
},
log,
{ session }
);
if (result.success) {
log.info(`Successfully expanded all tasks: ${result.data.message}`);
} else {
log.error(
`Failed to expand all tasks: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error expanding all tasks');
} catch (error) {
log.error(`Error in expand-all tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,96 +3,75 @@
* Tool to expand a task into subtasks * Tool to expand a task into subtasks
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { expandTaskDirect } from '../core/task-master-core.js'; import { expandTaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js'; import fs from "fs";
import fs from 'fs'; import path from "path";
import path from 'path';
/** /**
* Register the expand-task tool with the MCP server * Register the expand-task tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerExpandTaskTool(server) { export function registerExpandTaskTool(server) {
server.addTool({ server.addTool({
name: 'expand_task', name: "expand_task",
description: 'Expand a task into subtasks for detailed implementation', description: "Expand a task into subtasks for detailed implementation",
parameters: z.object({ parameters: z.object({
id: z.string().describe('ID of task to expand'), id: z.string().describe("ID of task to expand"),
num: z.string().optional().describe('Number of subtasks to generate'), num: z.union([z.string(), z.number()]).optional().describe("Number of subtasks to generate"),
research: z research: z.boolean().optional().describe("Use Perplexity AI for research-backed generation"),
.boolean() prompt: z.string().optional().describe("Additional context for subtask generation"),
.optional() file: z.string().optional().describe("Path to the tasks file"),
.describe('Use Perplexity AI for research-backed generation'), projectRoot: z
prompt: z .string()
.string() .optional()
.optional() .describe(
.describe('Additional context for subtask generation'), "Root directory of the project (default: current working directory)"
file: z.string().optional().describe('Absolute path to the tasks file'), ),
projectRoot: z }),
.string() execute: async (args, { log, reportProgress, session }) => {
.describe('The directory of the project. Must be an absolute path.'), try {
force: z.boolean().optional().describe('Force the expansion') log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
}),
execute: async (args, { log, session }) => { // Get project root from session
try { let rootFolder = getProjectRootFromSession(session, log);
log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
if (!rootFolder && args.projectRoot) {
// Get project root from args or session rootFolder = args.projectRoot;
const rootFolder = log.info(`Using project root from args as fallback: ${rootFolder}`);
args.projectRoot || getProjectRootFromSession(session, log); }
// Ensure project root was determined log.info(`Project root resolved to: ${rootFolder}`);
if (!rootFolder) {
return createErrorResponse( // Check for tasks.json in the standard locations
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' const tasksJsonPath = path.join(rootFolder, 'tasks', 'tasks.json');
);
} if (fs.existsSync(tasksJsonPath)) {
log.info(`Found tasks.json at ${tasksJsonPath}`);
log.info(`Project root resolved to: ${rootFolder}`); // Add the file parameter directly to args
args.file = tasksJsonPath;
// Resolve the path to tasks.json using the utility } else {
let tasksJsonPath; log.warn(`Could not find tasks.json at ${tasksJsonPath}`);
try { }
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file }, // Call direct function with only session in the context, not reportProgress
log // Use the pattern recommended in the MCP guidelines
); const result = await expandTaskDirect({
} catch (error) { ...args,
log.error(`Error finding tasks.json: ${error.message}`); projectRoot: rootFolder
return createErrorResponse( }, log, { session }); // Only pass session, NOT reportProgress
`Failed to find tasks.json: ${error.message}`
); // Return the result
} return handleApiResult(result, log, 'Error expanding task');
} catch (error) {
// Call direct function with only session in the context, not reportProgress log.error(`Error in expand task tool: ${error.message}`);
// Use the pattern recommended in the MCP guidelines return createErrorResponse(error.message);
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
},
log,
{ session }
); // Only pass session, NOT reportProgress
// Return the result
return handleApiResult(result, log, 'Error expanding task');
} catch (error) {
log.error(`Error in expand task tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

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

View File

@@ -3,92 +3,62 @@
* Tool to generate individual task files from tasks.json * Tool to generate individual task files from tasks.json
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { generateTaskFilesDirect } from '../core/task-master-core.js'; import { generateTaskFilesDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import path from 'path';
/** /**
* Register the generate tool with the MCP server * Register the generate tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerGenerateTool(server) { export function registerGenerateTool(server) {
server.addTool({ server.addTool({
name: 'generate', name: "generate",
description: description: "Generates individual task files in tasks/ directory based on tasks.json",
'Generates individual task files in tasks/ directory based on tasks.json', parameters: z.object({
parameters: z.object({ file: z.string().optional().describe("Path to the tasks file"),
file: z.string().optional().describe('Absolute path to the tasks file'), output: z.string().optional().describe("Output directory (default: same directory as tasks file)"),
output: z projectRoot: z
.string() .string()
.optional() .optional()
.describe('Output directory (default: same directory as tasks file)'), .describe(
projectRoot: z "Root directory of the project (default: current working directory)"
.string() ),
.describe('The directory of the project. Must be an absolute path.') }),
}), execute: async (args, { log, session, reportProgress }) => {
execute: async (args, { log, session }) => { try {
try { log.info(`Generating task files with args: ${JSON.stringify(args)}`);
log.info(`Generating task files with args: ${JSON.stringify(args)}`); // await reportProgress({ progress: 0 });
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log); if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
// Ensure project root was determined log.info(`Using project root from args as fallback: ${rootFolder}`);
if (!rootFolder) { }
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' const result = await generateTaskFilesDirect({
); projectRoot: rootFolder,
} ...args
}, log/*, { reportProgress, mcpLog: log, session}*/);
// Resolve the path to tasks.json
let tasksJsonPath; // await reportProgress({ progress: 100 });
try {
tasksJsonPath = findTasksJsonPath( if (result.success) {
{ projectRoot: rootFolder, file: args.file }, log.info(`Successfully generated task files: ${result.data.message}`);
log } else {
); log.error(`Failed to generate task files: ${result.error?.message || 'Unknown error'}`);
} catch (error) { }
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse( return handleApiResult(result, log, 'Error generating task files');
`Failed to find tasks.json: ${error.message}` } catch (error) {
); log.error(`Error in generate tool: ${error.message}`);
} return createErrorResponse(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
},
log
);
if (result.success) {
log.info(`Successfully generated task files: ${result.data.message}`);
} else {
log.error(
`Failed to generate task files: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error generating task files');
} catch (error) {
log.error(`Error in generate tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -8,40 +8,35 @@ import { createErrorResponse, createContentResponse } from './utils.js'; // Assu
* @param {AsyncOperationManager} asyncManager - The async operation manager. * @param {AsyncOperationManager} asyncManager - The async operation manager.
*/ */
export function registerGetOperationStatusTool(server, asyncManager) { export function registerGetOperationStatusTool(server, asyncManager) {
server.addTool({ server.addTool({
name: 'get_operation_status', name: 'get_operation_status',
description: description: 'Retrieves the status and result/error of a background operation.',
'Retrieves the status and result/error of a background operation.', parameters: z.object({
parameters: z.object({ operationId: z.string().describe('The ID of the operation to check.'),
operationId: z.string().describe('The ID of the operation to check.') }),
}), execute: async (args, { log }) => {
execute: async (args, { log }) => { try {
try { const { operationId } = args;
const { operationId } = args; log.info(`Checking status for operation ID: ${operationId}`);
log.info(`Checking status for operation ID: ${operationId}`);
const status = asyncManager.getStatus(operationId); const status = asyncManager.getStatus(operationId);
// Status will now always return an object, but it might have status='not_found' // Status will now always return an object, but it might have status='not_found'
if (status.status === 'not_found') { if (status.status === 'not_found') {
log.warn(`Operation ID not found: ${operationId}`); log.warn(`Operation ID not found: ${operationId}`);
return createErrorResponse( return createErrorResponse(
status.error?.message || `Operation ID not found: ${operationId}`, status.error?.message || `Operation ID not found: ${operationId}`,
status.error?.code || 'OPERATION_NOT_FOUND' status.error?.code || 'OPERATION_NOT_FOUND'
); );
} }
log.info(`Status for ${operationId}: ${status.status}`); log.info(`Status for ${operationId}: ${status.status}`);
return createContentResponse(status); return createContentResponse(status);
} catch (error) {
log.error(`Error in get_operation_status tool: ${error.message}`, { } catch (error) {
stack: error.stack log.error(`Error in get_operation_status tool: ${error.message}`, { stack: error.stack });
}); return createErrorResponse(`Failed to get operation status: ${error.message}`, 'GET_STATUS_ERROR');
return createErrorResponse( }
`Failed to get operation status: ${error.message}`, },
'GET_STATUS_ERROR' });
); }
}
}
});
}

View File

@@ -3,14 +3,13 @@
* Tool to get task details by ID * Tool to get task details by ID
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { showTaskDirect } from '../core/task-master-core.js'; import { showTaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Custom processor function that removes allTasks from the response * Custom processor function that removes allTasks from the response
@@ -18,16 +17,16 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
* @returns {Object} - The processed data with allTasks removed * @returns {Object} - The processed data with allTasks removed
*/ */
function processTaskResponse(data) { function processTaskResponse(data) {
if (!data) return data; if (!data) return data;
// If we have the expected structure with task and allTasks // If we have the expected structure with task and allTasks
if (data.task) { if (data.task) {
// Return only the task object, removing the allTasks array // Return only the task object, removing the allTasks array
return data.task; return data.task;
} }
// If structure is unexpected, return as is // If structure is unexpected, return as is
return data; return data;
} }
/** /**
@@ -35,89 +34,59 @@ function processTaskResponse(data) {
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerShowTaskTool(server) { export function registerShowTaskTool(server) {
server.addTool({ server.addTool({
name: 'get_task', name: "get_task",
description: 'Get detailed information about a specific task', description: "Get detailed information about a specific task",
parameters: z.object({ parameters: z.object({
id: z.string().describe('Task ID to get'), id: z.string().describe("Task ID to get"),
file: z.string().optional().describe('Absolute path to the tasks file'), file: z.string().optional().describe("Path to the tasks file"),
projectRoot: z projectRoot: z
.string() .string()
.describe('The directory of the project. Must be an absolute path.') .optional()
}), .describe(
execute: async (args, { log, session }) => { "Root directory of the project (default: current working directory)"
// Log the session right at the start of execute ),
log.info( }),
`Session object received in execute: ${JSON.stringify(session)}` execute: async (args, { log, session, reportProgress }) => {
); // Use JSON.stringify for better visibility // Log the session right at the start of execute
log.info(`Session object received in execute: ${JSON.stringify(session)}`); // Use JSON.stringify for better visibility
try { try {
log.info(`Getting task details for ID: ${args.id}`); log.info(`Getting task details for ID: ${args.id}`);
log.info( log.info(`Session object received in execute: ${JSON.stringify(session)}`); // Use JSON.stringify for better visibility
`Session object received in execute: ${JSON.stringify(session)}`
); // Use JSON.stringify for better visibility let rootFolder = getProjectRootFromSession(session, log);
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}`);
}
// Get project root from args or session log.info(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log);
// Ensure project root was determined log.info(`Root folder: ${rootFolder}`); // Log the final resolved root
if (!rootFolder) { const result = await showTaskDirect({
return createErrorResponse( projectRoot: rootFolder,
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' ...args
); }, log);
}
if (result.success) {
log.info(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root log.info(`Successfully retrieved task details for ID: ${args.id}${result.fromCache ? ' (from cache)' : ''}`);
} else {
log.info(`Root folder: ${rootFolder}`); // Log the final resolved root log.error(`Failed to get task: ${result.error.message}`);
}
// Resolve the path to tasks.json
let tasksJsonPath; // Use our custom processor function to remove allTasks from the response
try { return handleApiResult(result, log, 'Error retrieving task details', processTaskResponse);
tasksJsonPath = findTasksJsonPath( } catch (error) {
{ projectRoot: rootFolder, file: args.file }, log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
log return createErrorResponse(`Failed to get task: ${error.message}`);
); }
} 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
},
log
);
if (result.success) {
log.info(
`Successfully retrieved task details for ID: ${args.id}${result.fromCache ? ' (from cache)' : ''}`
);
} else {
log.error(`Failed to get task: ${result.error.message}`);
}
// Use our custom processor function to remove allTasks from the response
return handleApiResult(
result,
log,
'Error retrieving task details',
processTaskResponse
);
} catch (error) {
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
return createErrorResponse(`Failed to get task: ${error.message}`);
}
}
});
}

View File

@@ -3,94 +3,63 @@
* Tool to get all tasks from Task Master * Tool to get all tasks from Task Master
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
createErrorResponse, createErrorResponse,
handleApiResult, handleApiResult,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { listTasksDirect } from '../core/task-master-core.js'; import { listTasksDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the getTasks tool with the MCP server * Register the getTasks tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerListTasksTool(server) { export function registerListTasksTool(server) {
server.addTool({ server.addTool({
name: 'get_tasks', name: "get_tasks",
description: description: "Get all tasks from Task Master, optionally filtering by status and including subtasks.",
'Get all tasks from Task Master, optionally filtering by status and including subtasks.', parameters: z.object({
parameters: z.object({ status: z.string().optional().describe("Filter tasks by status (e.g., 'pending', 'done')"),
status: z withSubtasks: z
.string() .boolean()
.optional() .optional()
.describe("Filter tasks by status (e.g., 'pending', 'done')"), .describe("Include subtasks nested within their parent tasks in the response"),
withSubtasks: z file: z.string().optional().describe("Path to the tasks file (relative to project root or absolute)"),
.boolean() projectRoot: z
.optional() .string()
.describe( .optional()
'Include subtasks nested within their parent tasks in the response' .describe(
), "Root directory of the project (default: automatically detected from session or CWD)"
file: z ),
.string() }),
.optional() execute: async (args, { log, session, reportProgress }) => {
.describe( try {
'Path to the tasks file (relative to project root or absolute)' log.info(`Getting tasks with filters: ${JSON.stringify(args)}`);
), // await reportProgress({ progress: 0 });
projectRoot: z
.string() let rootFolder = getProjectRootFromSession(session, log);
.describe('The directory of the project. Must be an absolute path.')
}), if (!rootFolder && args.projectRoot) {
execute: async (args, { log, session }) => { rootFolder = args.projectRoot;
try { log.info(`Using project root from args as fallback: ${rootFolder}`);
log.info(`Getting tasks with filters: ${JSON.stringify(args)}`); }
// Get project root from args or session const result = await listTasksDirect({
const rootFolder = projectRoot: rootFolder,
args.projectRoot || getProjectRootFromSession(session, log); ...args
}, log/*, { reportProgress, mcpLog: log, session}*/);
// Ensure project root was determined
if (!rootFolder) { // await reportProgress({ progress: 100 });
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' log.info(`Retrieved ${result.success ? (result.data?.tasks?.length || 0) : 0} tasks${result.fromCache ? ' (from cache)' : ''}`);
); return handleApiResult(result, log, 'Error getting tasks');
} } catch (error) {
log.error(`Error getting tasks: ${error.message}`);
// Resolve the path to tasks.json return createErrorResponse(error.message);
let tasksJsonPath; }
try { },
tasksJsonPath = findTasksJsonPath( });
{ projectRoot: rootFolder, file: args.file },
log
);
} catch (error) {
log.error(`Error finding tasks.json: ${error.message}`);
// Use the error message from findTasksJsonPath for better context
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
const result = await listTasksDirect(
{
tasksJsonPath: tasksJsonPath,
status: args.status,
withSubtasks: args.withSubtasks
},
log
);
log.info(
`Retrieved ${result.success ? result.data?.tasks?.length || 0 : 0} tasks${result.fromCache ? ' (from cache)' : ''}`
);
return handleApiResult(result, log, 'Error getting tasks');
} catch (error) {
log.error(`Error getting tasks: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
} }
// We no longer need the formatTasksResponse function as we're returning raw JSON data // We no longer need the formatTasksResponse function as we're returning raw JSON data

View File

@@ -3,28 +3,28 @@
* Export all Task Master CLI tools for MCP server * Export all Task Master CLI tools for MCP server
*/ */
import { registerListTasksTool } from './get-tasks.js'; import { registerListTasksTool } from "./get-tasks.js";
import logger from '../logger.js'; import logger from "../logger.js";
import { registerSetTaskStatusTool } from './set-task-status.js'; import { registerSetTaskStatusTool } from "./set-task-status.js";
import { registerParsePRDTool } from './parse-prd.js'; import { registerParsePRDTool } from "./parse-prd.js";
import { registerUpdateTool } from './update.js'; import { registerUpdateTool } from "./update.js";
import { registerUpdateTaskTool } from './update-task.js'; import { registerUpdateTaskTool } from "./update-task.js";
import { registerUpdateSubtaskTool } from './update-subtask.js'; import { registerUpdateSubtaskTool } from "./update-subtask.js";
import { registerGenerateTool } from './generate.js'; import { registerGenerateTool } from "./generate.js";
import { registerShowTaskTool } from './get-task.js'; import { registerShowTaskTool } from "./get-task.js";
import { registerNextTaskTool } from './next-task.js'; import { registerNextTaskTool } from "./next-task.js";
import { registerExpandTaskTool } from './expand-task.js'; import { registerExpandTaskTool } from "./expand-task.js";
import { registerAddTaskTool } from './add-task.js'; import { registerAddTaskTool } from "./add-task.js";
import { registerAddSubtaskTool } from './add-subtask.js'; import { registerAddSubtaskTool } from "./add-subtask.js";
import { registerRemoveSubtaskTool } from './remove-subtask.js'; import { registerRemoveSubtaskTool } from "./remove-subtask.js";
import { registerAnalyzeTool } from './analyze.js'; import { registerAnalyzeTool } from "./analyze.js";
import { registerClearSubtasksTool } from './clear-subtasks.js'; import { registerClearSubtasksTool } from "./clear-subtasks.js";
import { registerExpandAllTool } from './expand-all.js'; import { registerExpandAllTool } from "./expand-all.js";
import { registerRemoveDependencyTool } from './remove-dependency.js'; import { registerRemoveDependencyTool } from "./remove-dependency.js";
import { registerValidateDependenciesTool } from './validate-dependencies.js'; import { registerValidateDependenciesTool } from "./validate-dependencies.js";
import { registerFixDependenciesTool } from './fix-dependencies.js'; import { registerFixDependenciesTool } from "./fix-dependencies.js";
import { registerComplexityReportTool } from './complexity-report.js'; import { registerComplexityReportTool } from "./complexity-report.js";
import { registerAddDependencyTool } from './add-dependency.js'; import { registerAddDependencyTool } from "./add-dependency.js";
import { registerRemoveTaskTool } from './remove-task.js'; import { registerRemoveTaskTool } from './remove-task.js';
import { registerInitializeProjectTool } from './initialize-project.js'; import { registerInitializeProjectTool } from './initialize-project.js';
import { asyncOperationManager } from '../core/utils/async-manager.js'; import { asyncOperationManager } from '../core/utils/async-manager.js';
@@ -34,38 +34,40 @@ import { asyncOperationManager } from '../core/utils/async-manager.js';
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
* @param {asyncOperationManager} asyncManager - The async operation manager instance * @param {asyncOperationManager} asyncManager - The async operation manager instance
*/ */
export function registerTaskMasterTools(server, asyncManager) { export function registerTaskMasterTools(server, asyncManager) {
try { try {
// Register each tool // Register each tool
registerListTasksTool(server); registerListTasksTool(server);
registerSetTaskStatusTool(server); registerSetTaskStatusTool(server);
registerParsePRDTool(server); registerParsePRDTool(server);
registerUpdateTool(server); registerUpdateTool(server);
registerUpdateTaskTool(server); registerUpdateTaskTool(server);
registerUpdateSubtaskTool(server); registerUpdateSubtaskTool(server);
registerGenerateTool(server); registerGenerateTool(server);
registerShowTaskTool(server); registerShowTaskTool(server);
registerNextTaskTool(server); registerNextTaskTool(server);
registerExpandTaskTool(server); registerExpandTaskTool(server);
registerAddTaskTool(server, asyncManager); registerAddTaskTool(server, asyncManager);
registerAddSubtaskTool(server); registerAddSubtaskTool(server);
registerRemoveSubtaskTool(server); registerRemoveSubtaskTool(server);
registerAnalyzeTool(server); registerAnalyzeTool(server);
registerClearSubtasksTool(server); registerClearSubtasksTool(server);
registerExpandAllTool(server); registerExpandAllTool(server);
registerRemoveDependencyTool(server); registerRemoveDependencyTool(server);
registerValidateDependenciesTool(server); registerValidateDependenciesTool(server);
registerFixDependenciesTool(server); registerFixDependenciesTool(server);
registerComplexityReportTool(server); registerComplexityReportTool(server);
registerAddDependencyTool(server); registerAddDependencyTool(server);
registerRemoveTaskTool(server); registerRemoveTaskTool(server);
registerInitializeProjectTool(server); registerInitializeProjectTool(server);
} catch (error) { } catch (error) {
logger.error(`Error registering Task Master tools: ${error.message}`); logger.error(`Error registering Task Master tools: ${error.message}`);
throw error; throw error;
} }
logger.info('Registered Task Master MCP tools');
} }
export default { export default {
registerTaskMasterTools registerTaskMasterTools,
}; };

View File

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

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

View File

@@ -3,115 +3,61 @@
* Tool to parse PRD document and generate tasks * Tool to parse PRD document and generate tasks
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
getProjectRootFromSession, handleApiResult,
handleApiResult, createErrorResponse,
createErrorResponse getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { parsePRDDirect } from '../core/task-master-core.js'; import { parsePRDDirect } from "../core/task-master-core.js";
import {
resolveProjectPaths,
findPRDDocumentPath,
resolveTasksOutputPath
} from '../core/utils/path-utils.js';
/** /**
* Register the parsePRD tool with the MCP server * Register the parsePRD tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerParsePRDTool(server) { export function registerParsePRDTool(server) {
server.addTool({ server.addTool({
name: 'parse_prd', name: "parse_prd",
description: description: "Parse a Product Requirements Document (PRD) or text file to automatically generate initial tasks.",
"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.", parameters: z.object({
parameters: z.object({ input: z.string().default("tasks/tasks.json").describe("Path to the PRD document file (relative to project root or absolute)"),
input: z numTasks: z.string().optional().describe("Approximate number of top-level tasks to generate (default: 10)"),
.string() output: z.string().optional().describe("Output path for tasks.json file (relative to project root or absolute, default: tasks/tasks.json)"),
.optional() force: z.boolean().optional().describe("Allow overwriting an existing tasks.json file."),
.default('scripts/prd.txt') projectRoot: z
.describe('Absolute path to the PRD document file (.txt, .md, etc.)'), .string()
numTasks: z .optional()
.string() .describe(
.optional() "Root directory of the project (default: automatically detected from session or CWD)"
.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.' }),
), execute: async (args, { log, session }) => {
output: z try {
.string() log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
.optional()
.describe( let rootFolder = getProjectRootFromSession(session, log);
'Output path for tasks.json file (default: tasks/tasks.json)'
), if (!rootFolder && args.projectRoot) {
force: z rootFolder = args.projectRoot;
.boolean() log.info(`Using project root from args as fallback: ${rootFolder}`);
.optional() }
.describe('Allow overwriting an existing tasks.json file.'),
append: z const result = await parsePRDDirect({
.boolean() projectRoot: rootFolder,
.optional() ...args
.describe( }, log, { session });
'Append new tasks to existing tasks.json instead of overwriting'
), if (result.success) {
projectRoot: z log.info(`Successfully parsed PRD: ${result.data.message}`);
.string() } else {
.describe('The directory of the project. Must be absolute path.') log.error(`Failed to parse PRD: ${result.error?.message || 'Unknown error'}`);
}), }
execute: async (args, { log, session }) => {
try { return handleApiResult(result, log, 'Error parsing PRD');
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`); } catch (error) {
log.error(`Error in parse-prd tool: ${error.message}`);
// Get project root from args or session return createErrorResponse(error.message);
const rootFolder = }
args.projectRoot || getProjectRootFromSession(session, log); },
});
if (!rootFolder) { }
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
);
}
// 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,
append: args.append
},
log,
{ session }
);
if (result.success) {
log.info(`Successfully parsed PRD: ${result.data.message}`);
} else {
log.error(
`Failed to parse PRD: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error parsing PRD');
} catch (error) {
log.error(`Error in parse-prd tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

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

View File

@@ -3,101 +3,59 @@
* Tool for removing subtasks from parent tasks * Tool for removing subtasks from parent tasks
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { removeSubtaskDirect } from '../core/task-master-core.js'; import { removeSubtaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the removeSubtask tool with the MCP server * Register the removeSubtask tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerRemoveSubtaskTool(server) { export function registerRemoveSubtaskTool(server) {
server.addTool({ server.addTool({
name: 'remove_subtask', name: "remove_subtask",
description: 'Remove a subtask from its parent task', description: "Remove a subtask from its parent task",
parameters: z.object({ parameters: z.object({
id: z id: z.string().describe("Subtask ID to remove in format 'parentId.subtaskId' (required)"),
.string() convert: z.boolean().optional().describe("Convert the subtask to a standalone task instead of deleting it"),
.describe( file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
"Subtask ID to remove in format 'parentId.subtaskId' (required)" skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
), projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
convert: z }),
.boolean() execute: async (args, { log, session, reportProgress }) => {
.optional() try {
.describe( log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
'Convert the subtask to a standalone task instead of deleting it' // await reportProgress({ progress: 0 });
),
file: z let rootFolder = getProjectRootFromSession(session, log);
.string()
.optional() if (!rootFolder && args.projectRoot) {
.describe( rootFolder = args.projectRoot;
'Absolute path to the tasks file (default: tasks/tasks.json)' log.info(`Using project root from args as fallback: ${rootFolder}`);
), }
skipGenerate: z
.boolean() const result = await removeSubtaskDirect({
.optional() projectRoot: rootFolder,
.describe('Skip regenerating task files'), ...args
projectRoot: z }, log/*, { reportProgress, mcpLog: log, session}*/);
.string()
.describe('The directory of the project. Must be an absolute path.') // await reportProgress({ progress: 100 });
}),
execute: async (args, { log, session }) => { if (result.success) {
try { log.info(`Subtask removed successfully: ${result.data.message}`);
log.info(`Removing subtask with args: ${JSON.stringify(args)}`); } else {
log.error(`Failed to remove subtask: ${result.error.message}`);
// Get project root from args or session }
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log); return handleApiResult(result, log, 'Error removing subtask');
} catch (error) {
// Ensure project root was determined log.error(`Error in removeSubtask tool: ${error.message}`);
if (!rootFolder) { return createErrorResponse(error.message);
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}`
);
}
const result = await removeSubtaskDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
convert: args.convert,
skipGenerate: args.skipGenerate
},
log
);
if (result.success) {
log.info(`Subtask removed successfully: ${result.data.message}`);
} else {
log.error(`Failed to remove subtask: ${result.error.message}`);
}
return handleApiResult(result, log, 'Error removing subtask');
} catch (error) {
log.error(`Error in removeSubtask tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,91 +3,69 @@
* Tool to remove a task by ID * Tool to remove a task by ID
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { removeTaskDirect } from '../core/task-master-core.js'; import { removeTaskDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the remove-task tool with the MCP server * Register the remove-task tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerRemoveTaskTool(server) { export function registerRemoveTaskTool(server) {
server.addTool({ server.addTool({
name: 'remove_task', name: "remove_task",
description: 'Remove a task or subtask permanently from the tasks list', description: "Remove a task or subtask permanently from the tasks list",
parameters: z.object({ parameters: z.object({
id: z id: z.string().describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"),
.string() file: z.string().optional().describe("Path to the tasks file"),
.describe( projectRoot: z
"ID(s) of the task(s) or subtask(s) to remove (e.g., '5' or '5.2' or '5,6,7')" .string()
), .optional()
file: z.string().optional().describe('Absolute path to the tasks file'), .describe(
projectRoot: z "Root directory of the project (default: current working directory)"
.string() ),
.describe('The directory of the project. Must be an absolute path.'), confirm: z.boolean().optional().describe("Whether to skip confirmation prompt (default: false)")
confirm: z }),
.boolean() execute: async (args, { log, session }) => {
.optional() try {
.describe('Whether to skip confirmation prompt (default: false)') log.info(`Removing task with ID: ${args.id}`);
}),
execute: async (args, { log, session }) => { // Get project root from session
try { let rootFolder = getProjectRootFromSession(session, log);
log.info(`Removing task(s) with ID(s): ${args.id}`);
if (!rootFolder && args.projectRoot) {
// Get project root from args or session rootFolder = args.projectRoot;
const rootFolder = log.info(`Using project root from args as fallback: ${rootFolder}`);
args.projectRoot || getProjectRootFromSession(session, log); } else if (!rootFolder) {
// Ensure we have a default if nothing else works
// Ensure project root was determined rootFolder = process.cwd();
if (!rootFolder) { log.warn(`Session and args failed to provide root, using CWD: ${rootFolder}`);
return createErrorResponse( }
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
); log.info(`Using project root: ${rootFolder}`);
}
// Assume client has already handled confirmation if needed
log.info(`Using project root: ${rootFolder}`); const result = await removeTaskDirect({
id: args.id,
// Resolve the path to tasks.json file: args.file,
let tasksJsonPath; projectRoot: rootFolder
try { }, log);
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file }, if (result.success) {
log log.info(`Successfully removed task: ${args.id}`);
); } else {
} catch (error) { log.error(`Failed to remove task: ${result.error.message}`);
log.error(`Error finding tasks.json: ${error.message}`); }
return createErrorResponse(
`Failed to find tasks.json: ${error.message}` return handleApiResult(result, log, 'Error removing task');
); } catch (error) {
} log.error(`Error in remove-task tool: ${error.message}`);
return createErrorResponse(`Failed to remove task: ${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
},
log
);
if (result.success) {
log.info(`Successfully removed task: ${args.id}`);
} else {
log.error(`Failed to remove task: ${result.error.message}`);
}
return handleApiResult(result, log, 'Error removing task');
} catch (error) {
log.error(`Error in remove-task tool: ${error.message}`);
return createErrorResponse(`Failed to remove task: ${error.message}`);
}
}
});
}

View File

@@ -3,99 +3,68 @@
* Tool to set the status of a task * Tool to set the status of a task
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { setTaskStatusDirect } from '../core/task-master-core.js'; import { setTaskStatusDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the setTaskStatus tool with the MCP server * Register the setTaskStatus tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerSetTaskStatusTool(server) { export function registerSetTaskStatusTool(server) {
server.addTool({ server.addTool({
name: 'set_task_status', name: "set_task_status",
description: 'Set the status of one or more tasks or subtasks.', description: "Set the status of one or more tasks or subtasks.",
parameters: z.object({ parameters: z.object({
id: z id: z
.string() .string()
.describe( .describe("Task ID or subtask ID (e.g., '15', '15.2'). Can be comma-separated for multiple updates."),
"Task ID or subtask ID (e.g., '15', '15.2'). Can be comma-separated for multiple updates." status: z
), .string()
status: z .describe("New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."),
.string() file: z.string().optional().describe("Path to the tasks file"),
.describe( projectRoot: z
"New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'." .string()
), .optional()
file: z.string().optional().describe('Absolute path to the tasks file'), .describe(
projectRoot: z "Root directory of the project (default: automatically detected)"
.string() ),
.describe('The directory of the project. Must be an absolute path.') }),
}), execute: async (args, { log, session }) => {
execute: async (args, { log, session }) => { try {
try { log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
// Get project root from session
// Get project root from args or session let rootFolder = getProjectRootFromSession(session, log);
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log); if (!rootFolder && args.projectRoot) {
rootFolder = args.projectRoot;
// Ensure project root was determined log.info(`Using project root from args as fallback: ${rootFolder}`);
if (!rootFolder) { }
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' // Call the direct function with the project root
); const result = await setTaskStatusDirect({
} ...args,
projectRoot: rootFolder
// Resolve the path to tasks.json }, log);
let tasksJsonPath;
try { // Log the result
tasksJsonPath = findTasksJsonPath( if (result.success) {
{ projectRoot: rootFolder, file: args.file }, log.info(`Successfully updated status for task(s) ${args.id} to "${args.status}": ${result.data.message}`);
log } else {
); log.error(`Failed to update task status: ${result.error?.message || 'Unknown error'}`);
} catch (error) { }
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse( // Format and return the result
`Failed to find tasks.json: ${error.message}` return handleApiResult(result, log, 'Error setting task status');
); } catch (error) {
} log.error(`Error in setTaskStatus tool: ${error.message}`);
return createErrorResponse(`Error setting task status: ${error.message}`);
// Call the direct function with the resolved path }
const result = await setTaskStatusDirect( },
{ });
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
status: args.status
},
log
);
// Log the result
if (result.success) {
log.info(
`Successfully updated status for task(s) ${args.id} to "${args.status}": ${result.data.message}`
);
} else {
log.error(
`Failed to update task status: ${result.error?.message || 'Unknown error'}`
);
}
// Format and return the result
return handleApiResult(result, log, 'Error setting task status');
} catch (error) {
log.error(`Error in setTaskStatus tool: ${error.message}`);
return createErrorResponse(
`Error setting task status: ${error.message}`
);
}
}
});
} }

View File

@@ -3,95 +3,61 @@
* Tool to append additional information to a specific subtask * Tool to append additional information to a specific subtask
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { updateSubtaskByIdDirect } from '../core/task-master-core.js'; import { updateSubtaskByIdDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update-subtask tool with the MCP server * Register the update-subtask tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerUpdateSubtaskTool(server) { export function registerUpdateSubtaskTool(server) {
server.addTool({ server.addTool({
name: 'update_subtask', name: "update_subtask",
description: description: "Appends additional information to a specific subtask without replacing existing content",
'Appends timestamped information to a specific subtask without replacing existing content', parameters: z.object({
parameters: z.object({ id: z.string().describe("ID of the subtask to update in format \"parentId.subtaskId\" (e.g., \"5.2\")"),
id: z prompt: z.string().describe("Information to add to the subtask"),
.string() research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
.describe( file: z.string().optional().describe("Path to the tasks file"),
'ID of the subtask to update in format "parentId.subtaskId" (e.g., "5.2"). Parent ID is the ID of the task that contains the subtask.' projectRoot: z
), .string()
prompt: z.string().describe('Information to add to the subtask'), .optional()
research: z .describe(
.boolean() "Root directory of the project (default: current working directory)"
.optional() ),
.describe('Use Perplexity AI for research-backed updates'), }),
file: z.string().optional().describe('Absolute path to the tasks file'), execute: async (args, { log, session }) => {
projectRoot: z try {
.string() log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
.describe('The directory of the project. Must be an absolute path.')
}), let rootFolder = getProjectRootFromSession(session, log);
execute: async (args, { log, session }) => {
try { if (!rootFolder && args.projectRoot) {
log.info(`Updating subtask with args: ${JSON.stringify(args)}`); rootFolder = args.projectRoot;
log.info(`Using project root from args as fallback: ${rootFolder}`);
// Get project root from args or session }
const rootFolder =
args.projectRoot || getProjectRootFromSession(session, log); const result = await updateSubtaskByIdDirect({
projectRoot: rootFolder,
// Ensure project root was determined ...args
if (!rootFolder) { }, log, { session });
return createErrorResponse(
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' if (result.success) {
); log.info(`Successfully updated subtask with ID ${args.id}`);
} } else {
log.error(`Failed to update subtask: ${result.error?.message || 'Unknown error'}`);
// Resolve the path to tasks.json }
let tasksJsonPath;
try { return handleApiResult(result, log, 'Error updating subtask');
tasksJsonPath = findTasksJsonPath( } catch (error) {
{ projectRoot: rootFolder, file: args.file }, log.error(`Error in update_subtask tool: ${error.message}`);
log return createErrorResponse(error.message);
); }
} catch (error) { },
log.error(`Error finding tasks.json: ${error.message}`); });
return createErrorResponse( }
`Failed to find tasks.json: ${error.message}`
);
}
const result = await updateSubtaskByIdDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
},
log,
{ session }
);
if (result.success) {
log.info(`Successfully updated subtask with ID ${args.id}`);
} else {
log.error(
`Failed to update subtask: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error updating subtask');
} catch (error) {
log.error(`Error in update_subtask tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,97 +3,61 @@
* Tool to update a single task by ID with new information * Tool to update a single task by ID with new information
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { updateTaskByIdDirect } from '../core/task-master-core.js'; import { updateTaskByIdDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update-task tool with the MCP server * Register the update-task tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerUpdateTaskTool(server) { export function registerUpdateTaskTool(server) {
server.addTool({ server.addTool({
name: 'update_task', name: "update_task",
description: description: "Updates a single task by ID with new information or context provided in the prompt.",
'Updates a single task by ID with new information or context provided in the prompt.', parameters: z.object({
parameters: z.object({ id: z.string().describe("ID of the task or subtask (e.g., '15', '15.2') to update"),
id: z prompt: z.string().describe("New information or context to incorporate into the task"),
.string() research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
.describe( file: z.string().optional().describe("Path to the tasks file"),
"ID of the task (e.g., '15') to update. Subtasks are supported using the update-subtask tool." projectRoot: z
), .string()
prompt: z .optional()
.string() .describe(
.describe('New information or context to incorporate into the task'), "Root directory of the project (default: current working directory)"
research: z ),
.boolean() }),
.optional() execute: async (args, { log, session }) => {
.describe('Use Perplexity AI for research-backed updates'), try {
file: z.string().optional().describe('Absolute path to the tasks file'), log.info(`Updating task with args: ${JSON.stringify(args)}`);
projectRoot: z
.string() let rootFolder = getProjectRootFromSession(session, log);
.describe('The directory of the project. Must be an absolute path.')
}), if (!rootFolder && args.projectRoot) {
execute: async (args, { log, session }) => { rootFolder = args.projectRoot;
try { log.info(`Using project root from args as fallback: ${rootFolder}`);
log.info(`Updating task with args: ${JSON.stringify(args)}`); }
// Get project root from args or session const result = await updateTaskByIdDirect({
const rootFolder = projectRoot: rootFolder,
args.projectRoot || getProjectRootFromSession(session, log); ...args
}, log, { session });
// Ensure project root was determined
if (!rootFolder) { if (result.success) {
return createErrorResponse( log.info(`Successfully updated task with ID ${args.id}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' } else {
); log.error(`Failed to update task: ${result.error?.message || 'Unknown error'}`);
} }
// Resolve the path to tasks.json return handleApiResult(result, log, 'Error updating task');
let tasksJsonPath; } catch (error) {
try { log.error(`Error in update_task tool: ${error.message}`);
tasksJsonPath = findTasksJsonPath( return createErrorResponse(error.message);
{ projectRoot: rootFolder, file: args.file }, }
log },
); });
} catch (error) { }
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
const result = await updateTaskByIdDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
// Pass other relevant args
id: args.id,
prompt: args.prompt,
research: args.research
},
log,
{ session }
);
if (result.success) {
log.info(`Successfully updated task with ID ${args.id}`);
} else {
log.error(
`Failed to update task: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error updating task');
} catch (error) {
log.error(`Error in update_task tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,97 +3,61 @@
* Tool to update tasks based on new context/prompt * Tool to update tasks based on new context/prompt
*/ */
import { z } from 'zod'; import { z } from "zod";
import { import {
handleApiResult, handleApiResult,
createErrorResponse, createErrorResponse,
getProjectRootFromSession getProjectRootFromSession
} from './utils.js'; } from "./utils.js";
import { updateTasksDirect } from '../core/task-master-core.js'; import { updateTasksDirect } from "../core/task-master-core.js";
import { findTasksJsonPath } from '../core/utils/path-utils.js';
/** /**
* Register the update tool with the MCP server * Register the update tool with the MCP server
* @param {Object} server - FastMCP server instance * @param {Object} server - FastMCP server instance
*/ */
export function registerUpdateTool(server) { export function registerUpdateTool(server) {
server.addTool({ server.addTool({
name: 'update', name: "update",
description: description: "Update multiple upcoming tasks (with ID >= 'from' ID) based on new context or changes provided in the prompt. Use 'update_task' instead for a single specific task.",
"Update multiple upcoming tasks (with ID >= 'from' ID) based on new context or changes provided in the prompt. Use 'update_task' instead for a single specific task or 'update_subtask' for subtasks.", parameters: z.object({
parameters: z.object({ from: z.string().describe("Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'"),
from: z prompt: z.string().describe("Explanation of changes or new context to apply"),
.string() research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
.describe( file: z.string().optional().describe("Path to the tasks file"),
"Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'" projectRoot: z
), .string()
prompt: z .optional()
.string() .describe(
.describe('Explanation of changes or new context to apply'), "Root directory of the project (default: current working directory)"
research: z ),
.boolean() }),
.optional() execute: async (args, { log, session }) => {
.describe('Use Perplexity AI for research-backed updates'), try {
file: z.string().optional().describe('Absolute path to the tasks file'), log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
projectRoot: z
.string() let rootFolder = getProjectRootFromSession(session, log);
.describe('The directory of the project. Must be an absolute path.')
}), if (!rootFolder && args.projectRoot) {
execute: async (args, { log, session }) => { rootFolder = args.projectRoot;
try { log.info(`Using project root from args as fallback: ${rootFolder}`);
log.info(`Updating tasks with args: ${JSON.stringify(args)}`); }
// Get project root from args or session const result = await updateTasksDirect({
const rootFolder = projectRoot: rootFolder,
args.projectRoot || getProjectRootFromSession(session, log); ...args
}, log, { session });
// Ensure project root was determined
if (!rootFolder) { if (result.success) {
return createErrorResponse( log.info(`Successfully updated tasks from ID ${args.from}: ${result.data.message}`);
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.' } else {
); log.error(`Failed to update tasks: ${result.error?.message || 'Unknown error'}`);
} }
// Resolve the path to tasks.json return handleApiResult(result, log, 'Error updating tasks');
let tasksJsonPath; } catch (error) {
try { log.error(`Error in update tool: ${error.message}`);
tasksJsonPath = findTasksJsonPath( return createErrorResponse(error.message);
{ projectRoot: rootFolder, file: args.file }, }
log },
); });
} catch (error) { }
log.error(`Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json: ${error.message}`
);
}
const result = await updateTasksDirect(
{
tasksJsonPath: tasksJsonPath,
from: args.from,
prompt: args.prompt,
research: args.research
},
log,
{ session }
);
if (result.success) {
log.info(
`Successfully updated tasks from ID ${args.from}: ${result.data.message}`
);
} else {
log.error(
`Failed to update tasks: ${result.error?.message || 'Unknown error'}`
);
}
return handleApiResult(result, log, 'Error updating tasks');
} catch (error) {
log.error(`Error in update tool: ${error.message}`);
return createErrorResponse(error.message);
}
}
});
}

View File

@@ -3,83 +3,68 @@
* Utility functions for Task Master CLI integration * Utility functions for Task Master CLI integration
*/ */
import { spawnSync } from 'child_process'; import { spawnSync } from "child_process";
import path from 'path'; import path from "path";
import fs from 'fs'; import fs from 'fs';
import { contextManager } from '../core/context-manager.js'; // Import the singleton import { contextManager } from '../core/context-manager.js'; // Import the singleton
// Import path utilities to ensure consistent path resolution // Import path utilities to ensure consistent path resolution
import { import { lastFoundProjectRoot, PROJECT_MARKERS } from '../core/utils/path-utils.js';
lastFoundProjectRoot,
PROJECT_MARKERS
} from '../core/utils/path-utils.js';
/** /**
* Get normalized project root path * Get normalized project root path
* @param {string|undefined} projectRootRaw - Raw project root from arguments * @param {string|undefined} projectRootRaw - Raw project root from arguments
* @param {Object} log - Logger object * @param {Object} log - Logger object
* @returns {string} - Normalized absolute path to project root * @returns {string} - Normalized absolute path to project root
*/ */
function getProjectRoot(projectRootRaw, log) { function getProjectRoot(projectRootRaw, log) {
// PRECEDENCE ORDER: // PRECEDENCE ORDER:
// 1. Environment variable override // 1. Environment variable override
// 2. Explicitly provided projectRoot in args // 2. Explicitly provided projectRoot in args
// 3. Previously found/cached project root // 3. Previously found/cached project root
// 4. Current directory if it has project markers // 4. Current directory if it has project markers
// 5. Current directory with warning // 5. Current directory with warning
// 1. Check for environment variable override
if (process.env.TASK_MASTER_PROJECT_ROOT) {
const envRoot = process.env.TASK_MASTER_PROJECT_ROOT;
const absolutePath = path.isAbsolute(envRoot)
? envRoot
: path.resolve(process.cwd(), envRoot);
log.info(`Using project root from TASK_MASTER_PROJECT_ROOT environment variable: ${absolutePath}`);
return absolutePath;
}
// 1. Check for environment variable override // 2. If project root is explicitly provided, use it
if (process.env.TASK_MASTER_PROJECT_ROOT) { if (projectRootRaw) {
const envRoot = process.env.TASK_MASTER_PROJECT_ROOT; const absolutePath = path.isAbsolute(projectRootRaw)
const absolutePath = path.isAbsolute(envRoot) ? projectRootRaw
? envRoot : path.resolve(process.cwd(), projectRootRaw);
: path.resolve(process.cwd(), envRoot);
log.info( log.info(`Using explicitly provided project root: ${absolutePath}`);
`Using project root from TASK_MASTER_PROJECT_ROOT environment variable: ${absolutePath}` return absolutePath;
); }
return absolutePath;
} // 3. If we have a last found project root from a tasks.json search, use that for consistency
if (lastFoundProjectRoot) {
// 2. If project root is explicitly provided, use it log.info(`Using last known project root where tasks.json was found: ${lastFoundProjectRoot}`);
if (projectRootRaw) { return lastFoundProjectRoot;
const absolutePath = path.isAbsolute(projectRootRaw) }
? projectRootRaw
: path.resolve(process.cwd(), projectRootRaw); // 4. Check if the current directory has any indicators of being a task-master project
const currentDir = process.cwd();
log.info(`Using explicitly provided project root: ${absolutePath}`); if (PROJECT_MARKERS.some(marker => {
return absolutePath; const markerPath = path.join(currentDir, marker);
} return fs.existsSync(markerPath);
})) {
// 3. If we have a last found project root from a tasks.json search, use that for consistency log.info(`Using current directory as project root (found project markers): ${currentDir}`);
if (lastFoundProjectRoot) { return currentDir;
log.info( }
`Using last known project root where tasks.json was found: ${lastFoundProjectRoot}`
); // 5. Default to current working directory but warn the user
return lastFoundProjectRoot; log.warn(`No task-master project detected in current directory. Using ${currentDir} as project root.`);
} log.warn('Consider using --project-root to specify the correct project location or set TASK_MASTER_PROJECT_ROOT environment variable.');
return currentDir;
// 4. Check if the current directory has any indicators of being a task-master project
const currentDir = process.cwd();
if (
PROJECT_MARKERS.some((marker) => {
const markerPath = path.join(currentDir, marker);
return fs.existsSync(markerPath);
})
) {
log.info(
`Using current directory as project root (found project markers): ${currentDir}`
);
return currentDir;
}
// 5. Default to current working directory but warn the user
log.warn(
`No task-master project detected in current directory. Using ${currentDir} as project root.`
);
log.warn(
'Consider using --project-root to specify the correct project location or set TASK_MASTER_PROJECT_ROOT environment variable.'
);
return currentDir;
} }
/** /**
@@ -89,87 +74,81 @@ function getProjectRoot(projectRootRaw, log) {
* @returns {string|null} - The absolute path to the project root, or null if not found. * @returns {string|null} - The absolute path to the project root, or null if not found.
*/ */
function getProjectRootFromSession(session, log) { function getProjectRootFromSession(session, log) {
try { try {
// Add detailed logging of session structure // Add detailed logging of session structure
log.info( log.info(`Session object: ${JSON.stringify({
`Session object: ${JSON.stringify({ hasSession: !!session,
hasSession: !!session, hasRoots: !!session?.roots,
hasRoots: !!session?.roots, rootsType: typeof session?.roots,
rootsType: typeof session?.roots, isRootsArray: Array.isArray(session?.roots),
isRootsArray: Array.isArray(session?.roots), rootsLength: session?.roots?.length,
rootsLength: session?.roots?.length, firstRoot: session?.roots?.[0],
firstRoot: session?.roots?.[0], hasRootsRoots: !!session?.roots?.roots,
hasRootsRoots: !!session?.roots?.roots, rootsRootsType: typeof session?.roots?.roots,
rootsRootsType: typeof session?.roots?.roots, isRootsRootsArray: Array.isArray(session?.roots?.roots),
isRootsRootsArray: Array.isArray(session?.roots?.roots), rootsRootsLength: session?.roots?.roots?.length,
rootsRootsLength: session?.roots?.roots?.length, firstRootsRoot: session?.roots?.roots?.[0]
firstRootsRoot: session?.roots?.roots?.[0] })}`);
})}`
); // ALWAYS ensure we return a valid path for project root
const cwd = process.cwd();
// If we have a session with roots array
if (session?.roots?.[0]?.uri) {
const rootUri = session.roots[0].uri;
log.info(`Found rootUri in session.roots[0].uri: ${rootUri}`);
const rootPath = rootUri.startsWith('file://')
? decodeURIComponent(rootUri.slice(7))
: rootUri;
log.info(`Decoded rootPath: ${rootPath}`);
return rootPath;
}
// If we have a session with roots.roots array (different structure)
if (session?.roots?.roots?.[0]?.uri) {
const rootUri = session.roots.roots[0].uri;
log.info(`Found rootUri in session.roots.roots[0].uri: ${rootUri}`);
const rootPath = rootUri.startsWith('file://')
? decodeURIComponent(rootUri.slice(7))
: rootUri;
log.info(`Decoded rootPath: ${rootPath}`);
return rootPath;
}
// ALWAYS ensure we return a valid path for project root // Get the server's location and try to find project root -- this is a fallback necessary in Cursor IDE
const cwd = process.cwd(); const serverPath = process.argv[1]; // This should be the path to server.js, which is in mcp-server/
if (serverPath && serverPath.includes('mcp-server')) {
// Find the mcp-server directory first
const mcpServerIndex = serverPath.indexOf('mcp-server');
if (mcpServerIndex !== -1) {
// Get the path up to mcp-server, which should be the project root
const projectRoot = serverPath.substring(0, mcpServerIndex - 1); // -1 to remove trailing slash
// Verify this looks like our project root by checking for key files/directories
if (fs.existsSync(path.join(projectRoot, '.cursor')) ||
fs.existsSync(path.join(projectRoot, 'mcp-server')) ||
fs.existsSync(path.join(projectRoot, 'package.json'))) {
log.info(`Found project root from server path: ${projectRoot}`);
return projectRoot;
}
}
}
// If we have a session with roots array // ALWAYS ensure we return a valid path as a last resort
if (session?.roots?.[0]?.uri) { log.info(`Using current working directory as ultimate fallback: ${cwd}`);
const rootUri = session.roots[0].uri; return cwd;
log.info(`Found rootUri in session.roots[0].uri: ${rootUri}`); } catch (e) {
const rootPath = rootUri.startsWith('file://') // If we have a server path, use it as a basis for project root
? decodeURIComponent(rootUri.slice(7)) const serverPath = process.argv[1];
: rootUri; if (serverPath && serverPath.includes('mcp-server')) {
log.info(`Decoded rootPath: ${rootPath}`); const mcpServerIndex = serverPath.indexOf('mcp-server');
return rootPath; return mcpServerIndex !== -1 ? serverPath.substring(0, mcpServerIndex - 1) : process.cwd();
} }
// If we have a session with roots.roots array (different structure) // Only use cwd if it's not "/"
if (session?.roots?.roots?.[0]?.uri) { const cwd = process.cwd();
const rootUri = session.roots.roots[0].uri; return cwd !== '/' ? cwd : '/';
log.info(`Found rootUri in session.roots.roots[0].uri: ${rootUri}`); }
const rootPath = rootUri.startsWith('file://')
? decodeURIComponent(rootUri.slice(7))
: rootUri;
log.info(`Decoded rootPath: ${rootPath}`);
return rootPath;
}
// Get the server's location and try to find project root -- this is a fallback necessary in Cursor IDE
const serverPath = process.argv[1]; // This should be the path to server.js, which is in mcp-server/
if (serverPath && serverPath.includes('mcp-server')) {
// Find the mcp-server directory first
const mcpServerIndex = serverPath.indexOf('mcp-server');
if (mcpServerIndex !== -1) {
// Get the path up to mcp-server, which should be the project root
const projectRoot = serverPath.substring(0, mcpServerIndex - 1); // -1 to remove trailing slash
// Verify this looks like our project root by checking for key files/directories
if (
fs.existsSync(path.join(projectRoot, '.cursor')) ||
fs.existsSync(path.join(projectRoot, 'mcp-server')) ||
fs.existsSync(path.join(projectRoot, 'package.json'))
) {
log.info(`Found project root from server path: ${projectRoot}`);
return projectRoot;
}
}
}
// ALWAYS ensure we return a valid path as a last resort
log.info(`Using current working directory as ultimate fallback: ${cwd}`);
return cwd;
} catch (e) {
// If we have a server path, use it as a basis for project root
const serverPath = process.argv[1];
if (serverPath && serverPath.includes('mcp-server')) {
const mcpServerIndex = serverPath.indexOf('mcp-server');
return mcpServerIndex !== -1
? serverPath.substring(0, mcpServerIndex - 1)
: process.cwd();
}
// Only use cwd if it's not "/"
const cwd = process.cwd();
return cwd !== '/' ? cwd : '/';
}
} }
/** /**
@@ -180,35 +159,28 @@ function getProjectRootFromSession(session, log) {
* @param {Function} processFunction - Optional function to process successful result data * @param {Function} processFunction - Optional function to process successful result data
* @returns {Object} - Standardized MCP response object * @returns {Object} - Standardized MCP response object
*/ */
function handleApiResult( function handleApiResult(result, log, errorPrefix = 'API error', processFunction = processMCPResponseData) {
result, if (!result.success) {
log, const errorMsg = result.error?.message || `Unknown ${errorPrefix}`;
errorPrefix = 'API error', // Include cache status in error logs
processFunction = processMCPResponseData log.error(`${errorPrefix}: ${errorMsg}. From cache: ${result.fromCache}`); // Keep logging cache status on error
) { return createErrorResponse(errorMsg);
if (!result.success) { }
const errorMsg = result.error?.message || `Unknown ${errorPrefix}`;
// Include cache status in error logs // Process the result data if needed
log.error(`${errorPrefix}: ${errorMsg}. From cache: ${result.fromCache}`); // Keep logging cache status on error const processedData = processFunction ? processFunction(result.data) : result.data;
return createErrorResponse(errorMsg);
} // Log success including cache status
log.info(`Successfully completed operation. From cache: ${result.fromCache}`); // Add success log with cache status
// Process the result data if needed // Create the response payload including the fromCache flag
const processedData = processFunction const responsePayload = {
? processFunction(result.data) fromCache: result.fromCache, // Get the flag from the original 'result'
: result.data; data: processedData // Nest the processed data under a 'data' key
};
// Log success including cache status
log.info(`Successfully completed operation. From cache: ${result.fromCache}`); // Add success log with cache status // Pass this combined payload to createContentResponse
return createContentResponse(responsePayload);
// Create the response payload including the fromCache flag
const responsePayload = {
fromCache: result.fromCache, // Get the flag from the original 'result'
data: processedData // Nest the processed data under a 'data' key
};
// Pass this combined payload to createContentResponse
return createContentResponse(responsePayload);
} }
/** /**
@@ -221,75 +193,75 @@ function handleApiResult(
* @returns {Object} - The result of the command execution * @returns {Object} - The result of the command execution
*/ */
function executeTaskMasterCommand( function executeTaskMasterCommand(
command, command,
log, log,
args = [], args = [],
projectRootRaw = null, projectRootRaw = null,
customEnv = null // Changed from session to customEnv customEnv = null // Changed from session to customEnv
) { ) {
try { try {
// Normalize project root internally using the getProjectRoot utility // Normalize project root internally using the getProjectRoot utility
const cwd = getProjectRoot(projectRootRaw, log); const cwd = getProjectRoot(projectRootRaw, log);
log.info( log.info(
`Executing task-master ${command} with args: ${JSON.stringify( `Executing task-master ${command} with args: ${JSON.stringify(
args args
)} in directory: ${cwd}` )} in directory: ${cwd}`
); );
// Prepare full arguments array // Prepare full arguments array
const fullArgs = [command, ...args]; const fullArgs = [command, ...args];
// Common options for spawn // Common options for spawn
const spawnOptions = { const spawnOptions = {
encoding: 'utf8', encoding: "utf8",
cwd: cwd, cwd: cwd,
// Merge process.env with customEnv, giving precedence to customEnv // Merge process.env with customEnv, giving precedence to customEnv
env: { ...process.env, ...(customEnv || {}) } env: { ...process.env, ...(customEnv || {}) }
}; };
// Log the environment being passed (optional, for debugging) // Log the environment being passed (optional, for debugging)
// log.info(`Spawn options env: ${JSON.stringify(spawnOptions.env)}`); // log.info(`Spawn options env: ${JSON.stringify(spawnOptions.env)}`);
// Execute the command using the global task-master CLI or local script // Execute the command using the global task-master CLI or local script
// Try the global CLI first // Try the global CLI first
let result = spawnSync('task-master', fullArgs, spawnOptions); let result = spawnSync("task-master", fullArgs, spawnOptions);
// If global CLI is not available, try fallback to the local script // If global CLI is not available, try fallback to the local script
if (result.error && result.error.code === 'ENOENT') { if (result.error && result.error.code === "ENOENT") {
log.info('Global task-master not found, falling back to local script'); log.info("Global task-master not found, falling back to local script");
// Pass the same spawnOptions (including env) to the fallback // Pass the same spawnOptions (including env) to the fallback
result = spawnSync('node', ['scripts/dev.js', ...fullArgs], spawnOptions); result = spawnSync("node", ["scripts/dev.js", ...fullArgs], spawnOptions);
} }
if (result.error) { if (result.error) {
throw new Error(`Command execution error: ${result.error.message}`); throw new Error(`Command execution error: ${result.error.message}`);
} }
if (result.status !== 0) { if (result.status !== 0) {
// Improve error handling by combining stderr and stdout if stderr is empty // Improve error handling by combining stderr and stdout if stderr is empty
const errorOutput = result.stderr const errorOutput = result.stderr
? result.stderr.trim() ? result.stderr.trim()
: result.stdout : result.stdout
? result.stdout.trim() ? result.stdout.trim()
: 'Unknown error'; : "Unknown error";
throw new Error( throw new Error(
`Command failed with exit code ${result.status}: ${errorOutput}` `Command failed with exit code ${result.status}: ${errorOutput}`
); );
} }
return { return {
success: true, success: true,
stdout: result.stdout, stdout: result.stdout,
stderr: result.stderr stderr: result.stderr,
}; };
} catch (error) { } catch (error) {
log.error(`Error executing task-master command: ${error.message}`); log.error(`Error executing task-master command: ${error.message}`);
return { return {
success: false, success: false,
error: error.message error: error.message,
}; };
} }
} }
/** /**
@@ -305,44 +277,40 @@ function executeTaskMasterCommand(
* Format: { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } * Format: { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/ */
async function getCachedOrExecute({ cacheKey, actionFn, log }) { async function getCachedOrExecute({ cacheKey, actionFn, log }) {
// Check cache first // Check cache first
const cachedResult = contextManager.getCachedData(cacheKey); const cachedResult = contextManager.getCachedData(cacheKey);
if (cachedResult !== undefined) {
log.info(`Cache hit for key: ${cacheKey}`);
// Return the cached data in the same structure as a fresh result
return {
...cachedResult, // Spread the cached result to maintain its structure
fromCache: true // Just add the fromCache flag
};
}
if (cachedResult !== undefined) { log.info(`Cache miss for key: ${cacheKey}. Executing action function.`);
log.info(`Cache hit for key: ${cacheKey}`);
// Return the cached data in the same structure as a fresh result // Execute the action function if cache missed
return { const result = await actionFn();
...cachedResult, // Spread the cached result to maintain its structure
fromCache: true // Just add the fromCache flag // If the action was successful, cache the result (but without fromCache flag)
}; if (result.success && result.data !== undefined) {
} log.info(`Action successful. Caching result for key: ${cacheKey}`);
// Cache the entire result structure (minus the fromCache flag)
log.info(`Cache miss for key: ${cacheKey}. Executing action function.`); const { fromCache, ...resultToCache } = result;
contextManager.setCachedData(cacheKey, resultToCache);
// Execute the action function if cache missed } else if (!result.success) {
const result = await actionFn(); log.warn(`Action failed for cache key ${cacheKey}. Result not cached. Error: ${result.error?.message}`);
} else {
// If the action was successful, cache the result (but without fromCache flag) log.warn(`Action for cache key ${cacheKey} succeeded but returned no data. Result not cached.`);
if (result.success && result.data !== undefined) { }
log.info(`Action successful. Caching result for key: ${cacheKey}`);
// Cache the entire result structure (minus the fromCache flag) // Return the fresh result, indicating it wasn't from cache
const { fromCache, ...resultToCache } = result; return {
contextManager.setCachedData(cacheKey, resultToCache); ...result,
} else if (!result.success) { fromCache: false
log.warn( };
`Action failed for cache key ${cacheKey}. Result not cached. Error: ${result.error?.message}`
);
} else {
log.warn(
`Action for cache key ${cacheKey} succeeded but returned no data. Result not cached.`
);
}
// Return the fresh result, indicating it wasn't from cache
return {
...result,
fromCache: false
};
} }
/** /**
@@ -352,68 +320,56 @@ async function getCachedOrExecute({ cacheKey, actionFn, log }) {
* @param {string[]} fieldsToRemove - An array of field names to remove. * @param {string[]} fieldsToRemove - An array of field names to remove.
* @returns {Object|Array} - The processed data with specified fields removed. * @returns {Object|Array} - The processed data with specified fields removed.
*/ */
function processMCPResponseData( function processMCPResponseData(taskOrData, fieldsToRemove = ['details', 'testStrategy']) {
taskOrData, if (!taskOrData) {
fieldsToRemove = ['details', 'testStrategy'] return taskOrData;
) { }
if (!taskOrData) {
return taskOrData;
}
// Helper function to process a single task object // Helper function to process a single task object
const processSingleTask = (task) => { const processSingleTask = (task) => {
if (typeof task !== 'object' || task === null) { if (typeof task !== 'object' || task === null) {
return task; return task;
} }
const processedTask = { ...task };
// Remove specified fields from the task
fieldsToRemove.forEach(field => {
delete processedTask[field];
});
const processedTask = { ...task }; // Recursively process subtasks if they exist and are an array
if (processedTask.subtasks && Array.isArray(processedTask.subtasks)) {
// Use processArrayOfTasks to handle the subtasks array
processedTask.subtasks = processArrayOfTasks(processedTask.subtasks);
}
return processedTask;
};
// Helper function to process an array of tasks
const processArrayOfTasks = (tasks) => {
return tasks.map(processSingleTask);
};
// Remove specified fields from the task // Check if the input is a data structure containing a 'tasks' array (like from listTasks)
fieldsToRemove.forEach((field) => { if (typeof taskOrData === 'object' && taskOrData !== null && Array.isArray(taskOrData.tasks)) {
delete processedTask[field]; return {
}); ...taskOrData, // Keep other potential fields like 'stats', 'filter'
tasks: processArrayOfTasks(taskOrData.tasks),
// Recursively process subtasks if they exist and are an array };
if (processedTask.subtasks && Array.isArray(processedTask.subtasks)) { }
// Use processArrayOfTasks to handle the subtasks array // Check if the input is likely a single task object (add more checks if needed)
processedTask.subtasks = processArrayOfTasks(processedTask.subtasks); else if (typeof taskOrData === 'object' && taskOrData !== null && 'id' in taskOrData && 'title' in taskOrData) {
} return processSingleTask(taskOrData);
}
return processedTask; // Check if the input is an array of tasks directly (less common but possible)
}; else if (Array.isArray(taskOrData)) {
return processArrayOfTasks(taskOrData);
// Helper function to process an array of tasks }
const processArrayOfTasks = (tasks) => {
return tasks.map(processSingleTask); // If it doesn't match known task structures, return it as is
}; return taskOrData;
// Check if the input is a data structure containing a 'tasks' array (like from listTasks)
if (
typeof taskOrData === 'object' &&
taskOrData !== null &&
Array.isArray(taskOrData.tasks)
) {
return {
...taskOrData, // Keep other potential fields like 'stats', 'filter'
tasks: processArrayOfTasks(taskOrData.tasks)
};
}
// Check if the input is likely a single task object (add more checks if needed)
else if (
typeof taskOrData === 'object' &&
taskOrData !== null &&
'id' in taskOrData &&
'title' in taskOrData
) {
return processSingleTask(taskOrData);
}
// Check if the input is an array of tasks directly (less common but possible)
else if (Array.isArray(taskOrData)) {
return processArrayOfTasks(taskOrData);
}
// If it doesn't match known task structures, return it as is
return taskOrData;
} }
/** /**
@@ -422,20 +378,19 @@ function processMCPResponseData(
* @returns {Object} - Content response object in FastMCP format * @returns {Object} - Content response object in FastMCP format
*/ */
function createContentResponse(content) { function createContentResponse(content) {
// FastMCP requires text type, so we format objects as JSON strings // FastMCP requires text type, so we format objects as JSON strings
return { return {
content: [ content: [
{ {
type: 'text', type: "text",
text: text: typeof content === 'object' ?
typeof content === 'object' // Format JSON nicely with indentation
? // Format JSON nicely with indentation JSON.stringify(content, null, 2) :
JSON.stringify(content, null, 2) // Keep other content types as-is
: // Keep other content types as-is String(content)
String(content) }
} ]
] };
};
} }
/** /**
@@ -444,24 +399,24 @@ function createContentResponse(content) {
* @returns {Object} - Error content response object in FastMCP format * @returns {Object} - Error content response object in FastMCP format
*/ */
export function createErrorResponse(errorMessage) { export function createErrorResponse(errorMessage) {
return { return {
content: [ content: [
{ {
type: 'text', type: "text",
text: `Error: ${errorMessage}` text: `Error: ${errorMessage}`
} }
], ],
isError: true isError: true
}; };
} }
// Ensure all functions are exported // Ensure all functions are exported
export { export {
getProjectRoot, getProjectRoot,
getProjectRootFromSession, getProjectRootFromSession,
handleApiResult, handleApiResult,
executeTaskMasterCommand, executeTaskMasterCommand,
getCachedOrExecute, getCachedOrExecute,
processMCPResponseData, processMCPResponseData,
createContentResponse createContentResponse,
}; };

View File

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

View File

@@ -8,68 +8,64 @@ import fs from 'fs';
console.error(`Current working directory: ${process.cwd()}`); console.error(`Current working directory: ${process.cwd()}`);
try { try {
console.error('Attempting to load FastMCP Config...'); console.error('Attempting to load FastMCP Config...');
// Check if .cursor/mcp.json exists // Check if .cursor/mcp.json exists
const mcpPath = path.join(process.cwd(), '.cursor', 'mcp.json'); const mcpPath = path.join(process.cwd(), '.cursor', 'mcp.json');
console.error(`Checking if mcp.json exists at: ${mcpPath}`); console.error(`Checking if mcp.json exists at: ${mcpPath}`);
if (fs.existsSync(mcpPath)) { if (fs.existsSync(mcpPath)) {
console.error('mcp.json file found'); console.error('mcp.json file found');
console.error( console.error(`File content: ${JSON.stringify(JSON.parse(fs.readFileSync(mcpPath, 'utf8')), null, 2)}`);
`File content: ${JSON.stringify(JSON.parse(fs.readFileSync(mcpPath, 'utf8')), null, 2)}` } else {
); console.error('mcp.json file not found');
} else { }
console.error('mcp.json file not found');
} // Try to create Config
const config = new Config();
// Try to create Config console.error('Config created successfully');
const config = new Config();
console.error('Config created successfully'); // Check if env property exists
if (config.env) {
// Check if env property exists console.error(`Config.env exists with keys: ${Object.keys(config.env).join(', ')}`);
if (config.env) {
console.error( // Print each env var value (careful with sensitive values)
`Config.env exists with keys: ${Object.keys(config.env).join(', ')}` for (const [key, value] of Object.entries(config.env)) {
); if (key.includes('KEY')) {
console.error(`${key}: [value hidden]`);
// Print each env var value (careful with sensitive values) } else {
for (const [key, value] of Object.entries(config.env)) { console.error(`${key}: ${value}`);
if (key.includes('KEY')) { }
console.error(`${key}: [value hidden]`); }
} else { } else {
console.error(`${key}: ${value}`); console.error('Config.env does not exist');
} }
}
} else {
console.error('Config.env does not exist');
}
} catch (error) { } catch (error) {
console.error(`Error loading Config: ${error.message}`); console.error(`Error loading Config: ${error.message}`);
console.error(`Stack trace: ${error.stack}`); console.error(`Stack trace: ${error.stack}`);
} }
// Log process.env to see if values from mcp.json were loaded automatically // Log process.env to see if values from mcp.json were loaded automatically
console.error('\nChecking if process.env already has values from mcp.json:'); console.error('\nChecking if process.env already has values from mcp.json:');
const envVars = [ const envVars = [
'ANTHROPIC_API_KEY', 'ANTHROPIC_API_KEY',
'PERPLEXITY_API_KEY', 'PERPLEXITY_API_KEY',
'MODEL', 'MODEL',
'PERPLEXITY_MODEL', 'PERPLEXITY_MODEL',
'MAX_TOKENS', 'MAX_TOKENS',
'TEMPERATURE', 'TEMPERATURE',
'DEFAULT_SUBTASKS', 'DEFAULT_SUBTASKS',
'DEFAULT_PRIORITY' 'DEFAULT_PRIORITY'
]; ];
for (const varName of envVars) { for (const varName of envVars) {
if (process.env[varName]) { if (process.env[varName]) {
if (varName.includes('KEY')) { if (varName.includes('KEY')) {
console.error(`${varName}: [value hidden]`); console.error(`${varName}: [value hidden]`);
} else { } else {
console.error(`${varName}: ${process.env[varName]}`); console.error(`${varName}: ${process.env[varName]}`);
} }
} else { } else {
console.error(`${varName}: not set`); console.error(`${varName}: not set`);
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"key": "value", "key": "value",
"nested": { "nested": {
"prop": true "prop": true
} }
} }

16082
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,98 +1,96 @@
{ {
"name": "task-master-ai", "name": "task-master-ai",
"version": "0.12.0", "version": "0.10.1",
"description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.", "description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"bin": { "bin": {
"task-master": "bin/task-master.js", "task-master": "bin/task-master.js",
"task-master-mcp": "mcp-server/server.js", "task-master-init": "bin/task-master-init.js",
"task-master-ai": "mcp-server/server.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", "scripts": {
"test:fails": "node --experimental-vm-modules node_modules/.bin/jest --onlyFailures", "test": "node --experimental-vm-modules node_modules/.bin/jest",
"test:watch": "node --experimental-vm-modules node_modules/.bin/jest --watch", "test:fails": "node --experimental-vm-modules node_modules/.bin/jest --onlyFailures",
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage", "test:watch": "node --experimental-vm-modules node_modules/.bin/jest --watch",
"prepare-package": "node scripts/prepare-package.js", "test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
"prepublishOnly": "npm run prepare-package", "prepare-package": "node scripts/prepare-package.js",
"prepare": "chmod +x bin/task-master.js mcp-server/server.js", "prepublishOnly": "npm run prepare-package",
"changeset": "changeset", "prepare": "chmod +x bin/task-master.js bin/task-master-init.js mcp-server/server.js",
"release": "changeset publish", "changeset": "changeset",
"inspector": "npx @modelcontextprotocol/inspector node mcp-server/server.js", "release": "changeset publish",
"mcp-server": "node mcp-server/server.js", "inspector": "CLIENT_PORT=8888 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node mcp-server/server.js",
"format-check": "prettier --check .", "mcp-server": "node mcp-server/server.js"
"format": "prettier --write ." },
}, "keywords": [
"keywords": [ "claude",
"claude", "task",
"task", "management",
"management", "ai",
"ai", "development",
"development", "cursor",
"cursor", "anthropic",
"anthropic", "llm",
"llm", "mcp",
"mcp", "context"
"context" ],
], "author": "Eyal Toledano",
"author": "Eyal Toledano", "license": "MIT WITH Commons-Clause",
"license": "MIT WITH Commons-Clause", "dependencies": {
"dependencies": { "@anthropic-ai/sdk": "^0.39.0",
"@anthropic-ai/sdk": "^0.39.0", "boxen": "^8.0.1",
"boxen": "^8.0.1", "chalk": "^4.1.2",
"chalk": "^4.1.2", "cli-table3": "^0.6.5",
"cli-table3": "^0.6.5", "commander": "^11.1.0",
"commander": "^11.1.0", "cors": "^2.8.5",
"cors": "^2.8.5", "dotenv": "^16.3.1",
"dotenv": "^16.3.1", "express": "^4.21.2",
"express": "^4.21.2", "fastmcp": "^1.20.5",
"fastmcp": "^1.20.5", "figlet": "^1.8.0",
"figlet": "^1.8.0", "fuse.js": "^7.0.0",
"fuse.js": "^7.0.0", "gradient-string": "^3.0.0",
"gradient-string": "^3.0.0", "helmet": "^8.1.0",
"helmet": "^8.1.0", "inquirer": "^12.5.0",
"inquirer": "^12.5.0", "jsonwebtoken": "^9.0.2",
"jsonwebtoken": "^9.0.2", "lru-cache": "^10.2.0",
"lru-cache": "^10.2.0", "openai": "^4.89.0",
"openai": "^4.89.0", "ora": "^8.2.0",
"ora": "^8.2.0", "uuid": "^11.1.0"
"uuid": "^11.1.0" },
}, "engines": {
"engines": { "node": ">=14.0.0"
"node": ">=14.0.0" },
}, "repository": {
"repository": { "type": "git",
"type": "git", "url": "git+https://github.com/eyaltoledano/claude-task-master.git"
"url": "git+https://github.com/eyaltoledano/claude-task-master.git" },
}, "homepage": "https://github.com/eyaltoledano/claude-task-master#readme",
"homepage": "https://github.com/eyaltoledano/claude-task-master#readme", "bugs": {
"bugs": { "url": "https://github.com/eyaltoledano/claude-task-master/issues"
"url": "https://github.com/eyaltoledano/claude-task-master/issues" },
}, "files": [
"files": [ "scripts/init.js",
"scripts/init.js", "scripts/dev.js",
"scripts/dev.js", "scripts/modules/**",
"scripts/modules/**", "assets/**",
"assets/**", ".cursor/**",
".cursor/**", "README-task-master.md",
"README-task-master.md", "index.js",
"index.js", "bin/**",
"bin/**", "mcp-server/**"
"mcp-server/**" ],
], "overrides": {
"overrides": { "node-fetch": "^3.3.2",
"node-fetch": "^3.3.2", "whatwg-url": "^11.0.0"
"whatwg-url": "^11.0.0" },
}, "devDependencies": {
"devDependencies": { "@changesets/changelog-github": "^0.5.1",
"@changesets/changelog-github": "^0.5.1", "@changesets/cli": "^2.28.1",
"@changesets/cli": "^2.28.1", "@types/jest": "^29.5.14",
"@types/jest": "^29.5.14", "jest": "^29.7.0",
"jest": "^29.7.0", "jest-environment-node": "^29.7.0",
"jest-environment-node": "^29.7.0", "mock-fs": "^5.5.0",
"mock-fs": "^5.5.0", "supertest": "^7.1.0"
"prettier": "^3.5.3", }
"supertest": "^7.1.0"
}
} }

View File

@@ -21,11 +21,9 @@ In an AI-driven development process—particularly with tools like [Cursor](http
The script can be configured through environment variables in a `.env` file at the root of the project: The script can be configured through environment variables in a `.env` file at the root of the project:
### Required Configuration ### Required Configuration
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude - `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
### Optional Configuration ### Optional Configuration
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219") - `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000) - `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
- `TEMPERATURE`: Temperature for model responses (default: 0.7) - `TEMPERATURE`: Temperature for model responses (default: 0.7)
@@ -40,10 +38,9 @@ The script can be configured through environment variables in a `.env` file at t
## How It Works ## How It Works
1. **`tasks.json`**: 1. **`tasks.json`**:
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.). - The `meta` field can store additional info like the project's name, version, or reference to the PRD.
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
- Tasks can have `subtasks` for more detailed implementation steps. - Tasks can have `subtasks` for more detailed implementation steps.
- Dependencies are displayed with status indicators (✅ for completed, ⏱️ for pending) to easily track progress. - Dependencies are displayed with status indicators (✅ for completed, ⏱️ for pending) to easily track progress.
@@ -105,7 +102,6 @@ node scripts/dev.js update --file=custom-tasks.json --from=5 --prompt="Change da
``` ```
Notes: Notes:
- The `--prompt` parameter is required and should explain the changes or new context - The `--prompt` parameter is required and should explain the changes or new context
- Only tasks that aren't marked as 'done' will be updated - Only tasks that aren't marked as 'done' will be updated
- Tasks with ID >= the specified --from value will be updated - Tasks with ID >= the specified --from value will be updated
@@ -124,7 +120,6 @@ node scripts/dev.js update-task --id=4 --prompt="Use JWT for authentication" --r
``` ```
This command: This command:
- Updates only the specified task rather than a range of tasks - Updates only the specified task rather than a range of tasks
- Provides detailed validation with helpful error messages - Provides detailed validation with helpful error messages
- Checks for required API keys when using research mode - Checks for required API keys when using research mode
@@ -151,7 +146,6 @@ node scripts/dev.js set-status --id=1,2,3 --status=done
``` ```
Notes: Notes:
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well - When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted - Common status values are 'done', 'pending', and 'deferred', but any string is accepted
- You can specify multiple task IDs by separating them with commas - You can specify multiple task IDs by separating them with commas
@@ -201,7 +195,6 @@ node scripts/dev.js clear-subtasks --all
``` ```
Notes: Notes:
- After clearing subtasks, task files are automatically regenerated - After clearing subtasks, task files are automatically regenerated
- This is useful when you want to regenerate subtasks with a different approach - This is useful when you want to regenerate subtasks with a different approach
- Can be combined with the `expand` command to immediately generate new subtasks - Can be combined with the `expand` command to immediately generate new subtasks
@@ -217,7 +210,6 @@ The script integrates with two AI services:
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude. The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
To use the Perplexity integration: To use the Perplexity integration:
1. Obtain a Perplexity API key 1. Obtain a Perplexity API key
2. Add `PERPLEXITY_API_KEY` to your `.env` file 2. Add `PERPLEXITY_API_KEY` to your `.env` file
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online") 3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
@@ -226,7 +218,6 @@ To use the Perplexity integration:
## Logging ## Logging
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable: The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
- `debug`: Detailed information, typically useful for troubleshooting - `debug`: Detailed information, typically useful for troubleshooting
- `info`: Confirmation that things are working as expected (default) - `info`: Confirmation that things are working as expected (default)
- `warn`: Warning messages that don't prevent execution - `warn`: Warning messages that don't prevent execution
@@ -249,20 +240,17 @@ node scripts/dev.js remove-dependency --id=<id> --depends-on=<id>
These commands: These commands:
1. **Allow precise dependency management**: 1. **Allow precise dependency management**:
- Add dependencies between tasks with automatic validation - Add dependencies between tasks with automatic validation
- Remove dependencies when they're no longer needed - Remove dependencies when they're no longer needed
- Update task files automatically after changes - Update task files automatically after changes
2. **Include validation checks**: 2. **Include validation checks**:
- Prevent circular dependencies (a task depending on itself) - Prevent circular dependencies (a task depending on itself)
- Prevent duplicate dependencies - Prevent duplicate dependencies
- Verify that both tasks exist before adding/removing dependencies - Verify that both tasks exist before adding/removing dependencies
- Check if dependencies exist before attempting to remove them - Check if dependencies exist before attempting to remove them
3. **Provide clear feedback**: 3. **Provide clear feedback**:
- Success messages confirm when dependencies are added/removed - Success messages confirm when dependencies are added/removed
- Error messages explain why operations failed (if applicable) - Error messages explain why operations failed (if applicable)
@@ -287,7 +275,6 @@ node scripts/dev.js validate-dependencies --file=custom-tasks.json
``` ```
This command: This command:
- Scans all tasks and subtasks for non-existent dependencies - Scans all tasks and subtasks for non-existent dependencies
- Identifies potential self-dependencies (tasks referencing themselves) - Identifies potential self-dependencies (tasks referencing themselves)
- Reports all found issues without modifying files - Reports all found issues without modifying files
@@ -309,7 +296,6 @@ node scripts/dev.js fix-dependencies --file=custom-tasks.json
``` ```
This command: This command:
1. **Validates all dependencies** across tasks and subtasks 1. **Validates all dependencies** across tasks and subtasks
2. **Automatically removes**: 2. **Automatically removes**:
- References to non-existent tasks and subtasks - References to non-existent tasks and subtasks
@@ -347,7 +333,6 @@ node scripts/dev.js analyze-complexity --research
``` ```
Notes: Notes:
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag) - The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
- Tasks are scored on a scale of 1-10 - Tasks are scored on a scale of 1-10
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration - Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
@@ -372,35 +357,33 @@ node scripts/dev.js expand --id=8 --num=5 --prompt="Custom prompt"
``` ```
When a complexity report exists: When a complexity report exists:
- The `expand` command will use the recommended subtask count from the report (unless overridden) - The `expand` command will use the recommended subtask count from the report (unless overridden)
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided) - It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
- When using `--all`, tasks are sorted by complexity score (highest first) - When using `--all`, tasks are sorted by complexity score (highest first)
- The `--research` flag is preserved from the complexity analysis to expansion - The `--research` flag is preserved from the complexity analysis to expansion
The output report structure is: The output report structure is:
```json ```json
{ {
"meta": { "meta": {
"generatedAt": "2023-06-15T12:34:56.789Z", "generatedAt": "2023-06-15T12:34:56.789Z",
"tasksAnalyzed": 20, "tasksAnalyzed": 20,
"thresholdScore": 5, "thresholdScore": 5,
"projectName": "Your Project Name", "projectName": "Your Project Name",
"usedResearch": true "usedResearch": true
}, },
"complexityAnalysis": [ "complexityAnalysis": [
{ {
"taskId": 8, "taskId": 8,
"taskTitle": "Develop Implementation Drift Handling", "taskTitle": "Develop Implementation Drift Handling",
"complexityScore": 9.5, "complexityScore": 9.5,
"recommendedSubtasks": 6, "recommendedSubtasks": 6,
"expansionPrompt": "Create subtasks that handle detecting...", "expansionPrompt": "Create subtasks that handle detecting...",
"reasoning": "This task requires sophisticated logic...", "reasoning": "This task requires sophisticated logic...",
"expansionCommand": "node scripts/dev.js expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research" "expansionCommand": "node scripts/dev.js expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
} },
// More tasks sorted by complexity score (highest first) // More tasks sorted by complexity score (highest first)
] ]
} }
``` ```
@@ -474,19 +457,16 @@ This command is particularly useful when you need to examine a specific task in
The script now includes improved error handling throughout all commands: The script now includes improved error handling throughout all commands:
1. **Detailed Validation**: 1. **Detailed Validation**:
- Required parameters (like task IDs and prompts) are validated early - Required parameters (like task IDs and prompts) are validated early
- File existence is checked with customized errors for common scenarios - File existence is checked with customized errors for common scenarios
- Parameter type conversion is handled with clear error messages - Parameter type conversion is handled with clear error messages
2. **Contextual Error Messages**: 2. **Contextual Error Messages**:
- Task not found errors include suggestions to run the list command - Task not found errors include suggestions to run the list command
- API key errors include reminders to check environment variables - API key errors include reminders to check environment variables
- Invalid ID format errors show the expected format - Invalid ID format errors show the expected format
3. **Command-Specific Help Displays**: 3. **Command-Specific Help Displays**:
- When validation fails, detailed help for the specific command is shown - When validation fails, detailed help for the specific command is shown
- Help displays include usage examples and parameter descriptions - Help displays include usage examples and parameter descriptions
- Formatted in clear, color-coded boxes with examples - Formatted in clear, color-coded boxes with examples
@@ -501,13 +481,11 @@ The script now includes improved error handling throughout all commands:
The script now automatically checks for updates without slowing down execution: The script now automatically checks for updates without slowing down execution:
1. **Background Version Checking**: 1. **Background Version Checking**:
- Non-blocking version checks run in the background while commands execute - Non-blocking version checks run in the background while commands execute
- Actual command execution isn't delayed by version checking - Actual command execution isn't delayed by version checking
- Update notifications appear after command completion - Update notifications appear after command completion
2. **Update Notifications**: 2. **Update Notifications**:
- When a newer version is available, a notification is displayed - When a newer version is available, a notification is displayed
- Notifications include current version, latest version, and update command - Notifications include current version, latest version, and update command
- Formatted in an attention-grabbing box with clear instructions - Formatted in an attention-grabbing box with clear instructions
@@ -538,7 +516,6 @@ node scripts/dev.js add-subtask --parent=5 --title="Login API route" --skip-gene
``` ```
Key features: Key features:
- Create new subtasks with detailed properties or convert existing tasks - Create new subtasks with detailed properties or convert existing tasks
- Define dependencies between subtasks - Define dependencies between subtasks
- Set custom status for new subtasks - Set custom status for new subtasks
@@ -561,8 +538,7 @@ node scripts/dev.js remove-subtask --id=5.2 --skip-generate
``` ```
Key features: Key features:
- Remove subtasks individually or in batches - Remove subtasks individually or in batches
- Optionally convert subtasks to standalone tasks - Optionally convert subtasks to standalone tasks
- Control whether task files are regenerated - Control whether task files are regenerated
- Provides detailed success messages and next steps - Provides detailed success messages and next steps

View File

@@ -3,17 +3,17 @@
/** /**
* dev.js * dev.js
* Task Master CLI - AI-driven development task management * Task Master CLI - AI-driven development task management
* *
* This is the refactored entry point that uses the modular architecture. * This is the refactored entry point that uses the modular architecture.
* It imports functionality from the modules directory and provides a CLI. * It imports functionality from the modules directory and provides a CLI.
*/ */
// Add at the very beginning of the file // Add at the very beginning of the file
if (process.env.DEBUG === '1') { if (process.env.DEBUG === '1') {
console.error('DEBUG - dev.js received args:', process.argv.slice(2)); console.error('DEBUG - dev.js received args:', process.argv.slice(2));
} }
import { runCLI } from './modules/commands.js'; import { runCLI } from './modules/commands.js';
// Run the CLI with the process arguments // Run the CLI with the process arguments
runCLI(process.argv); runCLI(process.argv);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More