Compare commits
1 Commits
v0.12.1
...
crunchyman
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
641a43c7bc |
5
.changeset/fifty-squids-wear.md
Normal file
5
.changeset/fifty-squids-wear.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"task-master-ai": patch
|
||||
---
|
||||
|
||||
Add CI for testing
|
||||
5
.changeset/red-lights-mix.md
Normal file
5
.changeset/red-lights-mix.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"task-master-ai": patch
|
||||
---
|
||||
|
||||
Fix github actions creating npm releases on next branch push
|
||||
302
.changeset/two-bats-smoke.md
Normal file
302
.changeset/two-bats-smoke.md
Normal 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.
|
||||
@@ -2,13 +2,15 @@
|
||||
"mcpServers": {
|
||||
"taskmaster-ai": {
|
||||
"command": "node",
|
||||
"args": ["./mcp-server/server.js"],
|
||||
"args": [
|
||||
"./mcp-server/server.js"
|
||||
],
|
||||
"env": {
|
||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||
"MODEL": "claude-3-7-sonnet-20250219",
|
||||
"PERPLEXITY_MODEL": "sonar-pro",
|
||||
"MAX_TOKENS": 64000,
|
||||
"MAX_TOKENS": 128000,
|
||||
"TEMPERATURE": 0.2,
|
||||
"DEFAULT_SUBTASKS": 5,
|
||||
"DEFAULT_PRIORITY": "medium"
|
||||
|
||||
@@ -14,13 +14,13 @@ alwaysApply: false
|
||||
- **Purpose**: Defines and registers all CLI commands using Commander.js.
|
||||
- **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)):
|
||||
- Parses command-line arguments and options.
|
||||
- Invokes appropriate functions from other modules to execute commands (e.g., calls `initializeProject` from `init.js` for the `init` command).
|
||||
- Invokes appropriate functions from other modules to execute commands.
|
||||
- Handles user input and output related to command execution.
|
||||
- Implements input validation and error handling for CLI commands.
|
||||
- **Key Components**:
|
||||
- `programInstance` (Commander.js `Command` instance): Manages command definitions.
|
||||
- `registerCommands(programInstance)`: Function to register all application commands.
|
||||
- Command action handlers: Functions executed when a specific command is invoked, delegating to core modules.
|
||||
- Command action handlers: Functions executed when a specific command is invoked.
|
||||
|
||||
- **[`task-manager.js`](mdc:scripts/modules/task-manager.js): Task Data Management**
|
||||
- **Purpose**: Manages task data, including loading, saving, creating, updating, deleting, and querying tasks.
|
||||
@@ -148,23 +148,10 @@ alwaysApply: false
|
||||
- Robust error handling for background tasks
|
||||
- **Usage**: Used for CPU-intensive operations like task expansion and PRD parsing
|
||||
|
||||
- **[`init.js`](mdc:scripts/init.js): Project Initialization Logic**
|
||||
- **Purpose**: Contains the core logic for setting up a new Task Master project structure.
|
||||
- **Responsibilities**:
|
||||
- Creates necessary directories (`.cursor/rules`, `scripts`, `tasks`).
|
||||
- Copies template files (`.env.example`, `.gitignore`, rule files, `dev.js`, etc.).
|
||||
- Creates or merges `package.json` with required dependencies and scripts.
|
||||
- Sets up MCP configuration (`.cursor/mcp.json`).
|
||||
- Optionally initializes a git repository and installs dependencies.
|
||||
- Handles user prompts for project details *if* called without skip flags (`-y`).
|
||||
- **Key Function**:
|
||||
- `initializeProject(options)`: The main function exported and called by the `init` command's action handler in [`commands.js`](mdc:scripts/modules/commands.js). It receives parsed options directly.
|
||||
- **Note**: This script is used as a module and no longer handles its own argument parsing or direct execution via a separate `bin` file.
|
||||
|
||||
- **Data Flow and Module Dependencies**:
|
||||
|
||||
- **Commands Initiate Actions**: User commands entered via the CLI (parsed by `commander` based on definitions in [`commands.js`](mdc:scripts/modules/commands.js)) are the entry points for most operations.
|
||||
- **Command Handlers Delegate to Core Logic**: Action handlers within [`commands.js`](mdc:scripts/modules/commands.js) call functions in core modules like [`task-manager.js`](mdc:scripts/modules/task-manager.js), [`dependency-manager.js`](mdc:scripts/modules/dependency-manager.js), and [`init.js`](mdc:scripts/init.js) (for the `init` command) to perform the actual work.
|
||||
- **Commands Initiate Actions**: User commands entered via the CLI (handled by [`commands.js`](mdc:scripts/modules/commands.js)) are the entry points for most operations.
|
||||
- **Command Handlers Delegate to Managers**: Command handlers in [`commands.js`](mdc:scripts/modules/commands.js) call functions in [`task-manager.js`](mdc:scripts/modules/task-manager.js) and [`dependency-manager.js`](mdc:scripts/modules/dependency-manager.js) to perform core task and dependency management logic.
|
||||
- **UI for Presentation**: [`ui.js`](mdc:scripts/modules/ui.js) is used by command handlers and task/dependency managers to display information to the user. UI functions primarily consume data and format it for output, without modifying core application state.
|
||||
- **Utilities for Common Tasks**: [`utils.js`](mdc:scripts/modules/utils.js) provides helper functions used by all other modules for configuration, logging, file operations, and common data manipulations.
|
||||
- **AI Services Integration**: AI functionalities (complexity analysis, task expansion, PRD parsing) are invoked from [`task-manager.js`](mdc:scripts/modules/task-manager.js) and potentially [`commands.js`](mdc:scripts/modules/commands.js), likely using functions that would reside in a dedicated `ai-services.js` module or be integrated within `utils.js` or `task-manager.js`.
|
||||
|
||||
@@ -24,7 +24,7 @@ While this document details the implementation of Task Master's **CLI commands**
|
||||
programInstance
|
||||
.command('command-name')
|
||||
.description('Clear, concise description of what the command does')
|
||||
.option('-o, --option <value>', 'Option description', 'default value')
|
||||
.option('-s, --short-option <value>', 'Option description', 'default value')
|
||||
.option('--long-option <value>', 'Option description')
|
||||
.action(async (options) => {
|
||||
// Command implementation
|
||||
@@ -34,8 +34,7 @@ While this document details the implementation of Task Master's **CLI commands**
|
||||
- **Command Handler Organization**:
|
||||
- ✅ DO: Keep action handlers concise and focused
|
||||
- ✅ DO: Extract core functionality to appropriate modules
|
||||
- ✅ DO: Have the action handler import and call the relevant function(s) from core modules (e.g., `task-manager.js`, `init.js`), passing the parsed `options`.
|
||||
- ✅ DO: Perform basic parameter validation (e.g., checking for required options) within the action handler or at the start of the called core function.
|
||||
- ✅ DO: Include validation for required parameters
|
||||
- ❌ DON'T: Implement business logic in command handlers
|
||||
|
||||
## Best Practices for Removal/Delete Commands
|
||||
|
||||
@@ -37,7 +37,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
|
||||
* `addAliases`: `Add shell aliases (tm, taskmaster) (default: false).` (CLI: `--aliases`)
|
||||
* `yes`: `Skip prompts and use defaults/provided arguments (default: false).` (CLI: `-y, --yes`)
|
||||
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
|
||||
* **Important:** Once complete, you *MUST* parse a prd in order to generate tasks. There will be no tasks files until then. The next step after initializing should be to create a PRD using the example PRD in scripts/example_prd.txt.
|
||||
|
||||
|
||||
### 2. Parse PRD (`parse_prd`)
|
||||
|
||||
@@ -51,7 +51,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
|
||||
* `force`: `Use this to allow Taskmaster to overwrite an existing 'tasks.json' without asking for confirmation.` (CLI: `-f, --force`)
|
||||
* **Usage:** Useful for bootstrapping a project from an existing requirements document.
|
||||
* **Notes:** Task Master will strictly adhere to any specific requirements mentioned in the PRD (libraries, database schemas, frameworks, tech stacks, etc.) while filling in any gaps where the PRD isn't fully specified. Tasks are designed to provide the most direct implementation path while avoiding over-engineering.
|
||||
* **Important:** This MCP tool makes AI calls and can take up to a minute to complete. Please inform users to hang tight while the operation is in progress. If the user does not have a PRD, suggest discussing their idea and then use the example PRD in scripts/example_prd.txt as a template for creating the PRD based on their idea, for use with parse-prd.
|
||||
* **Important:** This MCP tool makes AI calls and can take up to a minute to complete. Please inform users to hang tight while the operation is in progress.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ globs: "**/*.test.js,tests/**/*"
|
||||
|
||||
# Testing Guidelines for Task Master CLI
|
||||
|
||||
*Note:* Never use asynchronous operations in tests. Always mock tests properly based on the way the tested functions are defined and used. Do not arbitrarily create tests. Based them on the low-level details and execution of the underlying code being tested.
|
||||
|
||||
## Test Organization Structure
|
||||
|
||||
- **Unit Tests** (See [`architecture.mdc`](mdc:.cursor/rules/architecture.mdc) for module breakdown)
|
||||
@@ -90,122 +88,6 @@ describe('Feature or Function Name', () => {
|
||||
});
|
||||
```
|
||||
|
||||
## Commander.js Command Testing Best Practices
|
||||
|
||||
When testing CLI commands built with Commander.js, several special considerations must be made to avoid common pitfalls:
|
||||
|
||||
- **Direct Action Handler Testing**
|
||||
- ✅ **DO**: Test the command action handlers directly rather than trying to mock the entire Commander.js chain
|
||||
- ✅ **DO**: Create simplified test-specific implementations of command handlers that match the original behavior
|
||||
- ✅ **DO**: Explicitly handle all options, including defaults and shorthand flags (e.g., `-p` for `--prompt`)
|
||||
- ✅ **DO**: Include null/undefined checks in test implementations for parameters that might be optional
|
||||
- ✅ **DO**: Use fixtures from `tests/fixtures/` for consistent sample data across tests
|
||||
|
||||
```javascript
|
||||
// ✅ DO: Create a simplified test version of the command handler
|
||||
const testAddTaskAction = async (options) => {
|
||||
options = options || {}; // Ensure options aren't undefined
|
||||
|
||||
// Validate parameters
|
||||
const isManualCreation = options.title && options.description;
|
||||
const prompt = options.prompt || options.p; // Handle shorthand flags
|
||||
|
||||
if (!prompt && !isManualCreation) {
|
||||
throw new Error('Expected error message');
|
||||
}
|
||||
|
||||
// Call the mocked task manager
|
||||
return mockTaskManager.addTask(/* parameters */);
|
||||
};
|
||||
|
||||
test('should handle required parameters correctly', async () => {
|
||||
// Call the test implementation directly
|
||||
await expect(async () => {
|
||||
await testAddTaskAction({ file: 'tasks.json' });
|
||||
}).rejects.toThrow('Expected error message');
|
||||
});
|
||||
```
|
||||
|
||||
- **Commander Chain Mocking (If Necessary)**
|
||||
- ✅ **DO**: Mock ALL chainable methods (`option`, `argument`, `action`, `on`, etc.)
|
||||
- ✅ **DO**: Return `this` (or the mock object) from all chainable method mocks
|
||||
- ✅ **DO**: Remember to mock not only the initial object but also all objects returned by methods
|
||||
- ✅ **DO**: Implement a mechanism to capture the action handler for direct testing
|
||||
|
||||
```javascript
|
||||
// If you must mock the Commander.js chain:
|
||||
const mockCommand = {
|
||||
command: jest.fn().mockReturnThis(),
|
||||
description: jest.fn().mockReturnThis(),
|
||||
option: jest.fn().mockReturnThis(),
|
||||
argument: jest.fn().mockReturnThis(), // Don't forget this one
|
||||
action: jest.fn(fn => {
|
||||
actionHandler = fn; // Capture the handler for testing
|
||||
return mockCommand;
|
||||
}),
|
||||
on: jest.fn().mockReturnThis() // Don't forget this one
|
||||
};
|
||||
```
|
||||
|
||||
- **Parameter Handling**
|
||||
- ✅ **DO**: Check for both main flag and shorthand flags (e.g., `prompt` and `p`)
|
||||
- ✅ **DO**: Handle parameters like Commander would (comma-separated lists, etc.)
|
||||
- ✅ **DO**: Set proper default values as defined in the command
|
||||
- ✅ **DO**: Validate that required parameters are actually required in tests
|
||||
|
||||
```javascript
|
||||
// Parse dependencies like Commander would
|
||||
const dependencies = options.dependencies
|
||||
? options.dependencies.split(',').map(id => id.trim())
|
||||
: [];
|
||||
```
|
||||
|
||||
- **Environment and Session Handling**
|
||||
- ✅ **DO**: Properly mock session objects when required by functions
|
||||
- ✅ **DO**: Reset environment variables between tests if modified
|
||||
- ✅ **DO**: Use a consistent pattern for environment-dependent tests
|
||||
|
||||
```javascript
|
||||
// Session parameter mock pattern
|
||||
const sessionMock = { session: process.env };
|
||||
|
||||
// In test:
|
||||
expect(mockAddTask).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
'Test prompt',
|
||||
[],
|
||||
'medium',
|
||||
sessionMock,
|
||||
false,
|
||||
null,
|
||||
null
|
||||
);
|
||||
```
|
||||
|
||||
- **Common Pitfalls to Avoid**
|
||||
- ❌ **DON'T**: Try to use the real action implementation without proper mocking
|
||||
- ❌ **DON'T**: Mock Commander partially - either mock it completely or test the action directly
|
||||
- ❌ **DON'T**: Forget to handle optional parameters that may be undefined
|
||||
- ❌ **DON'T**: Neglect to test shorthand flag functionality (e.g., `-p`, `-r`)
|
||||
- ❌ **DON'T**: Create circular dependencies in your test mocks
|
||||
- ❌ **DON'T**: Access variables before initialization in your test implementations
|
||||
- ❌ **DON'T**: Include actual command execution in unit tests
|
||||
- ❌ **DON'T**: Overwrite the same file path in multiple tests
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Create circular references in mocks
|
||||
const badMock = {
|
||||
method: jest.fn().mockImplementation(() => badMock.method())
|
||||
};
|
||||
|
||||
// ❌ DON'T: Access uninitialized variables
|
||||
const badImplementation = () => {
|
||||
const result = uninitialized;
|
||||
let uninitialized = 'value';
|
||||
return result;
|
||||
};
|
||||
```
|
||||
|
||||
## Jest Module Mocking Best Practices
|
||||
|
||||
- **Mock Hoisting Behavior**
|
||||
@@ -670,102 +552,6 @@ npm test -- -t "pattern to match"
|
||||
});
|
||||
```
|
||||
|
||||
## Testing AI Service Integrations
|
||||
|
||||
- **DO NOT import real AI service clients**
|
||||
- ❌ DON'T: Import actual AI clients from their libraries
|
||||
- ✅ DO: Create fully mocked versions that return predictable responses
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Import and instantiate real AI clients
|
||||
import { Anthropic } from '@anthropic-ai/sdk';
|
||||
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
||||
|
||||
// ✅ DO: Mock the entire module with controlled behavior
|
||||
jest.mock('@anthropic-ai/sdk', () => ({
|
||||
Anthropic: jest.fn().mockImplementation(() => ({
|
||||
messages: {
|
||||
create: jest.fn().mockResolvedValue({
|
||||
content: [{ type: 'text', text: 'Mocked AI response' }]
|
||||
})
|
||||
}
|
||||
}))
|
||||
}));
|
||||
```
|
||||
|
||||
- **DO NOT rely on environment variables for API keys**
|
||||
- ❌ DON'T: Assume environment variables are set in tests
|
||||
- ✅ DO: Set mock environment variables in test setup
|
||||
|
||||
```javascript
|
||||
// In tests/setup.js or at the top of test file
|
||||
process.env.ANTHROPIC_API_KEY = 'test-mock-api-key-for-tests';
|
||||
process.env.PERPLEXITY_API_KEY = 'test-mock-perplexity-key-for-tests';
|
||||
```
|
||||
|
||||
- **DO NOT use real AI client initialization logic**
|
||||
- ❌ DON'T: Use code that attempts to initialize or validate real AI clients
|
||||
- ✅ DO: Create test-specific paths that bypass client initialization
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Test functions that require valid AI client initialization
|
||||
// This will fail without proper API keys or network access
|
||||
test('should use AI client', async () => {
|
||||
const result = await functionThatInitializesAIClient();
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
// ✅ DO: Test with bypassed initialization or manual task paths
|
||||
test('should handle manual task creation without AI', () => {
|
||||
// Using a path that doesn't require AI client initialization
|
||||
const result = addTaskDirect({
|
||||
title: 'Manual Task',
|
||||
description: 'Test Description'
|
||||
}, mockLogger);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
```
|
||||
|
||||
## Testing Asynchronous Code
|
||||
|
||||
- **DO NOT rely on asynchronous operations in tests**
|
||||
- ❌ DON'T: Use real async/await or Promise resolution in tests
|
||||
- ✅ DO: Make all mocks return synchronous values when possible
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Use real async functions that might fail unpredictably
|
||||
test('should handle async operation', async () => {
|
||||
const result = await realAsyncFunction(); // Can time out or fail for external reasons
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
// ✅ DO: Make async operations synchronous in tests
|
||||
test('should handle operation', () => {
|
||||
mockAsyncFunction.mockReturnValue({ success: true, data: 'test' });
|
||||
const result = functionUnderTest();
|
||||
expect(result).toEqual({ success: true, data: 'test' });
|
||||
});
|
||||
```
|
||||
|
||||
- **DO NOT test exact error messages**
|
||||
- ❌ DON'T: Assert on exact error message text that might change
|
||||
- ✅ DO: Test for error presence and general properties
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Test for exact error message text
|
||||
expect(result.error).toBe('Could not connect to API: Network error');
|
||||
|
||||
// ✅ DO: Test for general error properties or message patterns
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('Could not connect');
|
||||
// Or even better:
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
error: expect.stringContaining('connect')
|
||||
});
|
||||
```
|
||||
|
||||
## Reliable Testing Techniques
|
||||
|
||||
- **Create Simplified Test Functions**
|
||||
@@ -778,125 +564,99 @@ npm test -- -t "pattern to match"
|
||||
const setTaskStatus = async (taskId, newStatus) => {
|
||||
const tasksPath = 'tasks/tasks.json';
|
||||
const data = await readJSON(tasksPath);
|
||||
// [implementation]
|
||||
// Update task status logic
|
||||
await writeJSON(tasksPath, data);
|
||||
return { success: true };
|
||||
return data;
|
||||
};
|
||||
|
||||
// Test-friendly version (easier to test)
|
||||
const updateTaskStatus = (tasks, taskId, newStatus) => {
|
||||
// Pure logic without side effects
|
||||
const updatedTasks = [...tasks];
|
||||
const taskIndex = findTaskById(updatedTasks, taskId);
|
||||
if (taskIndex === -1) return { success: false, error: 'Task not found' };
|
||||
updatedTasks[taskIndex].status = newStatus;
|
||||
return { success: true, tasks: updatedTasks };
|
||||
// Test-friendly simplified function (easy to test)
|
||||
const testSetTaskStatus = (tasksData, taskIdInput, newStatus) => {
|
||||
// Same core logic without file operations
|
||||
// Update task status logic on provided tasksData object
|
||||
return tasksData; // Return updated data for assertions
|
||||
};
|
||||
```
|
||||
|
||||
- **Avoid Real File System Operations**
|
||||
- Never write to real files during tests
|
||||
- Create test-specific versions of file operation functions
|
||||
- Mock all file system operations including read, write, exists, etc.
|
||||
- Verify function behavior using the in-memory data structures
|
||||
|
||||
```javascript
|
||||
// Mock file operations
|
||||
const mockReadJSON = jest.fn();
|
||||
const mockWriteJSON = jest.fn();
|
||||
|
||||
jest.mock('../../scripts/modules/utils.js', () => ({
|
||||
readJSON: mockReadJSON,
|
||||
writeJSON: mockWriteJSON,
|
||||
}));
|
||||
|
||||
test('should update task status correctly', () => {
|
||||
// Setup mock data
|
||||
const testData = JSON.parse(JSON.stringify(sampleTasks));
|
||||
mockReadJSON.mockReturnValue(testData);
|
||||
|
||||
// Call the function that would normally modify files
|
||||
const result = testSetTaskStatus(testData, '1', 'done');
|
||||
|
||||
// Assert on the in-memory data structure
|
||||
expect(result.tasks[0].status).toBe('done');
|
||||
});
|
||||
```
|
||||
|
||||
- **Data Isolation Between Tests**
|
||||
- Always create fresh copies of test data for each test
|
||||
- Use `JSON.parse(JSON.stringify(original))` for deep cloning
|
||||
- Reset all mocks before each test with `jest.clearAllMocks()`
|
||||
- Avoid state that persists between tests
|
||||
|
||||
```javascript
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Deep clone the test data
|
||||
testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
||||
});
|
||||
```
|
||||
|
||||
- **Test All Path Variations**
|
||||
- Regular tasks and subtasks
|
||||
- Single items and multiple items
|
||||
- Success paths and error paths
|
||||
- Edge cases (empty data, invalid inputs, etc.)
|
||||
|
||||
```javascript
|
||||
// Multiple test cases covering different scenarios
|
||||
test('should update regular task status', () => {
|
||||
/* test implementation */
|
||||
});
|
||||
|
||||
test('should update subtask status', () => {
|
||||
/* test implementation */
|
||||
});
|
||||
|
||||
test('should update multiple tasks when given comma-separated IDs', () => {
|
||||
/* test implementation */
|
||||
});
|
||||
|
||||
test('should throw error for non-existent task ID', () => {
|
||||
/* test implementation */
|
||||
});
|
||||
```
|
||||
|
||||
- **Stabilize Tests With Predictable Input/Output**
|
||||
- Use consistent, predictable test fixtures
|
||||
- Avoid random values or time-dependent data
|
||||
- Make tests deterministic for reliable CI/CD
|
||||
- Control all variables that might affect test outcomes
|
||||
|
||||
```javascript
|
||||
// Use a specific known date instead of current date
|
||||
const fixedDate = new Date('2023-01-01T12:00:00Z');
|
||||
jest.spyOn(global, 'Date').mockImplementation(() => fixedDate);
|
||||
```
|
||||
|
||||
See [tests/README.md](mdc:tests/README.md) for more details on the testing approach.
|
||||
|
||||
Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options.
|
||||
|
||||
## Variable Hoisting and Module Initialization Issues
|
||||
|
||||
When testing ES modules or working with complex module imports, you may encounter variable hoisting and initialization issues. These can be particularly tricky to debug and often appear as "Cannot access 'X' before initialization" errors.
|
||||
|
||||
- **Understanding Module Initialization Order**
|
||||
- ✅ **DO**: Declare and initialize global variables at the top of modules
|
||||
- ✅ **DO**: Use proper function declarations to avoid hoisting issues
|
||||
- ✅ **DO**: Initialize variables before they are referenced, especially in imported modules
|
||||
- ✅ **DO**: Be aware that imports are hoisted to the top of the file
|
||||
|
||||
```javascript
|
||||
// ✅ DO: Define global state variables at the top of the module
|
||||
let silentMode = false; // Declare and initialize first
|
||||
|
||||
const CONFIG = { /* configuration */ };
|
||||
|
||||
function isSilentMode() {
|
||||
return silentMode; // Reference variable after it's initialized
|
||||
}
|
||||
|
||||
function log(level, message) {
|
||||
if (isSilentMode()) return; // Use the function instead of accessing variable directly
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
- **Testing Modules with Initialization-Dependent Functions**
|
||||
- ✅ **DO**: Create test-specific implementations that initialize all variables correctly
|
||||
- ✅ **DO**: Use factory functions in mocks to ensure proper initialization order
|
||||
- ✅ **DO**: Be careful with how you mock or stub functions that depend on module state
|
||||
|
||||
```javascript
|
||||
// ✅ DO: Test-specific implementation that avoids initialization issues
|
||||
const testLog = (level, ...args) => {
|
||||
// Local implementation with proper initialization
|
||||
const isSilent = false; // Explicit initialization
|
||||
if (isSilent) return;
|
||||
// Test implementation...
|
||||
};
|
||||
```
|
||||
|
||||
- **Common Hoisting-Related Errors to Avoid**
|
||||
- ❌ **DON'T**: Reference variables before their declaration in module scope
|
||||
- ❌ **DON'T**: Create circular dependencies between modules
|
||||
- ❌ **DON'T**: Rely on variable initialization order across module boundaries
|
||||
- ❌ **DON'T**: Define functions that use hoisted variables before they're initialized
|
||||
|
||||
```javascript
|
||||
// ❌ DON'T: Create reference-before-initialization patterns
|
||||
function badFunction() {
|
||||
if (silentMode) { /* ... */ } // ReferenceError if silentMode is declared later
|
||||
}
|
||||
|
||||
let silentMode = false;
|
||||
|
||||
// ❌ DON'T: Create cross-module references that depend on initialization order
|
||||
// module-a.js
|
||||
import { getSetting } from './module-b.js';
|
||||
export const config = { value: getSetting() };
|
||||
|
||||
// module-b.js
|
||||
import { config } from './module-a.js';
|
||||
export function getSetting() {
|
||||
return config.value; // Circular dependency causing initialization issues
|
||||
}
|
||||
```
|
||||
|
||||
- **Dynamic Imports as a Solution**
|
||||
- ✅ **DO**: Use dynamic imports (`import()`) to avoid initialization order issues
|
||||
- ✅ **DO**: Structure modules to avoid circular dependencies that cause initialization issues
|
||||
- ✅ **DO**: Consider factory functions for modules with complex state
|
||||
|
||||
```javascript
|
||||
// ✅ DO: Use dynamic imports to avoid initialization issues
|
||||
async function getTaskManager() {
|
||||
return import('./task-manager.js');
|
||||
}
|
||||
|
||||
async function someFunction() {
|
||||
const taskManager = await getTaskManager();
|
||||
return taskManager.someMethod();
|
||||
}
|
||||
```
|
||||
|
||||
- **Testing Approach for Modules with Initialization Issues**
|
||||
- ✅ **DO**: Create self-contained test implementations rather than using real implementations
|
||||
- ✅ **DO**: Mock dependencies at module boundaries instead of trying to mock deep dependencies
|
||||
- ✅ **DO**: Isolate module-specific state in tests
|
||||
|
||||
```javascript
|
||||
// ✅ DO: Create isolated test implementation instead of reusing module code
|
||||
test('should log messages when not in silent mode', () => {
|
||||
// Local test implementation instead of importing from module
|
||||
const testLog = (level, message) => {
|
||||
if (false) return; // Always non-silent for this test
|
||||
mockConsole(level, message);
|
||||
};
|
||||
|
||||
testLog('info', 'test message');
|
||||
expect(mockConsole).toHaveBeenCalledWith('info', 'test message');
|
||||
});
|
||||
```
|
||||
@@ -5,7 +5,7 @@ PERPLEXITY_API_KEY=your_perplexity_api_key_here # Format: pplx-...
|
||||
# Model Configuration
|
||||
MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229
|
||||
PERPLEXITY_MODEL=sonar-pro # Perplexity model for research-backed subtasks
|
||||
MAX_TOKENS=64000 # Maximum tokens for model responses
|
||||
MAX_TOKENS=128000 # Maximum tokens for model responses
|
||||
TEMPERATURE=0.2 # Temperature for model responses (0.0-1.0)
|
||||
|
||||
# Logging Configuration
|
||||
|
||||
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -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.
|
||||
@@ -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.
|
||||
31
.github/ISSUE_TEMPLATE/feedback.md
vendored
31
.github/ISSUE_TEMPLATE/feedback.md
vendored
@@ -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.
|
||||
60
.github/workflows/ci.yml
vendored
60
.github/workflows/ci.yml
vendored
@@ -14,7 +14,7 @@ permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
setup:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -24,55 +24,21 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
id: install
|
||||
run: npm ci
|
||||
timeout-minutes: 2
|
||||
cache: "npm"
|
||||
|
||||
- name: Cache node_modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: node_modules
|
||||
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
|
||||
format-check:
|
||||
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: 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: Install Dependencies
|
||||
run: npm ci
|
||||
timeout-minutes: 2
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
@@ -81,13 +47,13 @@ jobs:
|
||||
NODE_ENV: test
|
||||
CI: true
|
||||
FORCE_COLOR: 1
|
||||
timeout-minutes: 10
|
||||
timeout-minutes: 15
|
||||
|
||||
- name: Upload Test Results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: test-results
|
||||
name: test-results-node
|
||||
path: |
|
||||
test-results
|
||||
coverage
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
cache: "npm"
|
||||
|
||||
- name: Cache node_modules
|
||||
uses: actions/cache@v4
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# Ignore artifacts:
|
||||
build
|
||||
coverage
|
||||
.changeset
|
||||
tasks
|
||||
package-lock.json
|
||||
tests/fixture/*.json
|
||||
11
.prettierrc
11
.prettierrc
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": true,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "always",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"recommendations": ["esbenp.prettier-vscode"]
|
||||
}
|
||||
93
CHANGELOG.md
93
CHANGELOG.md
@@ -1,98 +1,5 @@
|
||||
# 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
|
||||
|
||||
### Patch Changes
|
||||
|
||||
90
LICENSE.md
Normal file
90
LICENSE.md
Normal 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
|
||||
@@ -58,7 +58,6 @@ This will prompt you for project details and set up a new project with the neces
|
||||
### Important Notes
|
||||
|
||||
1. **ES Modules Configuration:**
|
||||
|
||||
- This project uses ES Modules (ESM) instead of CommonJS.
|
||||
- This is set via `"type": "module"` in your package.json.
|
||||
- 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:
|
||||
- Name: "Task Master"
|
||||
- Type: "Command"
|
||||
- Command: "npx -y task-master-ai"
|
||||
- Command: "npx -y --package task-master-ai task-master-mcp"
|
||||
5. Save the settings
|
||||
|
||||
Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience.
|
||||
|
||||
18
README.md
18
README.md
@@ -1,6 +1,8 @@
|
||||
# Task Master [](https://github.com/eyaltoledano/claude-task-master/stargazers)
|
||||
|
||||
[](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml) [](https://badge.fury.io/js/task-master-ai)  [](LICENSE)
|
||||
[](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml) [](https://badge.fury.io/js/task-master-ai)
|
||||
|
||||
 [](LICENSE)
|
||||
|
||||
### By [@eyaltoledano](https://x.com/eyaltoledano) & [@RalphEcom](https://x.com/RalphEcom)
|
||||
|
||||
@@ -27,15 +29,15 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
|
||||
"mcpServers": {
|
||||
"taskmaster-ai": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "task-master-ai"],
|
||||
"args": ["-y", "task-master-ai", "mcp-server"],
|
||||
"env": {
|
||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||
"MODEL": "claude-3-7-sonnet-20250219",
|
||||
"PERPLEXITY_MODEL": "sonar-pro",
|
||||
"MAX_TOKENS": "64000",
|
||||
"TEMPERATURE": "0.2",
|
||||
"DEFAULT_SUBTASKS": "5",
|
||||
"MAX_TOKENS": 128000,
|
||||
"TEMPERATURE": 0.2,
|
||||
"DEFAULT_SUBTASKS": 5,
|
||||
"DEFAULT_PRIORITY": "medium"
|
||||
}
|
||||
}
|
||||
@@ -131,12 +133,6 @@ cd claude-task-master
|
||||
node scripts/init.js
|
||||
```
|
||||
|
||||
## Contributors
|
||||
|
||||
<a href="https://github.com/eyaltoledano/claude-task-master/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=eyaltoledano/claude-task-master" alt="Task Master project contributors" />
|
||||
</a>
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://www.star-history.com/#eyaltoledano/claude-task-master&Timeline)
|
||||
|
||||
@@ -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:
|
||||
|
||||
### Required Configuration
|
||||
|
||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
||||
|
||||
### Optional Configuration
|
||||
|
||||
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
||||
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
||||
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
||||
@@ -41,7 +39,6 @@ The script can be configured through environment variables in a `.env` file at t
|
||||
## How It Works
|
||||
|
||||
1. **`tasks.json`**:
|
||||
|
||||
- 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.
|
||||
- Tasks can have `subtasks` for more detailed implementation steps.
|
||||
@@ -114,7 +111,6 @@ task-master update --file=custom-tasks.json --from=5 --prompt="Change database f
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- The `--prompt` parameter is required and should explain the changes or new context
|
||||
- Only tasks that aren't marked as 'done' 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:
|
||||
|
||||
- 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
|
||||
- You can specify multiple task IDs by separating them with commas
|
||||
@@ -188,7 +183,6 @@ task-master clear-subtasks --all
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- After clearing subtasks, task files are automatically regenerated
|
||||
- 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
|
||||
@@ -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.
|
||||
|
||||
To use the Perplexity integration:
|
||||
|
||||
1. Obtain a Perplexity API key
|
||||
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
||||
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
||||
@@ -213,7 +206,6 @@ To use the Perplexity integration:
|
||||
## Logging
|
||||
|
||||
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
||||
|
||||
- `debug`: Detailed information, typically useful for troubleshooting
|
||||
- `info`: Confirmation that things are working as expected (default)
|
||||
- `warn`: Warning messages that don't prevent execution
|
||||
@@ -236,20 +228,17 @@ task-master remove-dependency --id=<id> --depends-on=<id>
|
||||
These commands:
|
||||
|
||||
1. **Allow precise dependency management**:
|
||||
|
||||
- Add dependencies between tasks with automatic validation
|
||||
- Remove dependencies when they're no longer needed
|
||||
- Update task files automatically after changes
|
||||
|
||||
2. **Include validation checks**:
|
||||
|
||||
- Prevent circular dependencies (a task depending on itself)
|
||||
- Prevent duplicate dependencies
|
||||
- Verify that both tasks exist before adding/removing dependencies
|
||||
- Check if dependencies exist before attempting to remove them
|
||||
|
||||
3. **Provide clear feedback**:
|
||||
|
||||
- Success messages confirm when dependencies are added/removed
|
||||
- Error messages explain why operations failed (if applicable)
|
||||
|
||||
@@ -274,7 +263,6 @@ task-master validate-dependencies --file=custom-tasks.json
|
||||
```
|
||||
|
||||
This command:
|
||||
|
||||
- Scans all tasks and subtasks for non-existent dependencies
|
||||
- Identifies potential self-dependencies (tasks referencing themselves)
|
||||
- Reports all found issues without modifying files
|
||||
@@ -296,7 +284,6 @@ task-master fix-dependencies --file=custom-tasks.json
|
||||
```
|
||||
|
||||
This command:
|
||||
|
||||
1. **Validates all dependencies** across tasks and subtasks
|
||||
2. **Automatically removes**:
|
||||
- References to non-existent tasks and subtasks
|
||||
@@ -334,7 +321,6 @@ task-master analyze-complexity --research
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
||||
- Tasks are scored on a scale of 1-10
|
||||
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
||||
@@ -359,14 +345,12 @@ task-master expand --id=8 --num=5 --prompt="Custom prompt"
|
||||
```
|
||||
|
||||
When a complexity report exists:
|
||||
|
||||
- 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)
|
||||
- When using `--all`, tasks are sorted by complexity score (highest first)
|
||||
- The `--research` flag is preserved from the complexity analysis to expansion
|
||||
|
||||
The output report structure is:
|
||||
|
||||
```json
|
||||
{
|
||||
"meta": {
|
||||
@@ -385,7 +369,7 @@ The output report structure is:
|
||||
"expansionPrompt": "Create subtasks that handle detecting...",
|
||||
"reasoning": "This task requires sophisticated logic...",
|
||||
"expansionCommand": "task-master expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
||||
}
|
||||
},
|
||||
// More tasks sorted by complexity score (highest first)
|
||||
]
|
||||
}
|
||||
|
||||
30
bin/task-master-init.js
Executable file
30
bin/task-master-init.js
Executable 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);
|
||||
});
|
||||
@@ -49,13 +49,7 @@ function runDevScript(args) {
|
||||
console.error('\nDEBUG - CLI Wrapper Analysis:');
|
||||
console.error('- Original command: ' + process.argv.join(' '));
|
||||
console.error('- Transformed args: ' + args.join(' '));
|
||||
console.error(
|
||||
'- dev.js will receive: node ' +
|
||||
devScriptPath +
|
||||
' ' +
|
||||
args.join(' ') +
|
||||
'\n'
|
||||
);
|
||||
console.error('- dev.js will receive: node ' + devScriptPath + ' ' + args.join(' ') + '\n');
|
||||
}
|
||||
|
||||
// For testing: If TEST_MODE is set, just print args and exit
|
||||
@@ -92,13 +86,11 @@ function createDevScriptAction(commandName) {
|
||||
// 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) => {
|
||||
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'
|
||||
);
|
||||
console.error('\nExample: task-master parse-prd --num-tasks=5 instead of --numTasks=5\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -121,11 +113,9 @@ function createDevScriptAction(commandName) {
|
||||
// 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('=') &&
|
||||
if (!arg.includes('=') &&
|
||||
i + 1 < process.argv.length &&
|
||||
!process.argv[i + 1].startsWith('--')
|
||||
) {
|
||||
!process.argv[i+1].startsWith('--')) {
|
||||
commandArgs.push(process.argv[++i]);
|
||||
}
|
||||
} else if (!positionals.has(arg)) {
|
||||
@@ -153,9 +143,7 @@ function createDevScriptAction(commandName) {
|
||||
userOptions.add(kebabName);
|
||||
|
||||
// Add the camelCase version as well
|
||||
const camelName = kebabName.replace(/-([a-z])/g, (_, letter) =>
|
||||
letter.toUpperCase()
|
||||
);
|
||||
const camelName = kebabName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
||||
userOptions.add(camelName);
|
||||
}
|
||||
}
|
||||
@@ -179,10 +167,7 @@ function createDevScriptAction(commandName) {
|
||||
}
|
||||
|
||||
// Skip built-in Commander properties and options the user provided
|
||||
if (
|
||||
['parent', 'commands', 'options', 'rawArgs'].includes(key) ||
|
||||
userOptions.has(key)
|
||||
) {
|
||||
if (['parent', 'commands', 'options', 'rawArgs'].includes(key) || userOptions.has(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,47 +210,39 @@ function createDevScriptAction(commandName) {
|
||||
};
|
||||
}
|
||||
|
||||
// // Special case for the 'init' command which uses a different script
|
||||
// function registerInitCommand(program) {
|
||||
// program
|
||||
// .command('init')
|
||||
// .description('Initialize a new project')
|
||||
// .option('-y, --yes', 'Skip prompts and use default values')
|
||||
// .option('-n, --name <name>', 'Project name')
|
||||
// .option('-d, --description <description>', 'Project description')
|
||||
// .option('-v, --version <version>', 'Project version')
|
||||
// .option('-a, --author <author>', 'Author name')
|
||||
// .option('--skip-install', 'Skip installing dependencies')
|
||||
// .option('--dry-run', 'Show what would be done without making changes')
|
||||
// .action((options) => {
|
||||
// // Pass through any options to the init script
|
||||
// const args = [
|
||||
// '--yes',
|
||||
// 'name',
|
||||
// 'description',
|
||||
// 'version',
|
||||
// 'author',
|
||||
// 'skip-install',
|
||||
// 'dry-run'
|
||||
// ]
|
||||
// .filter((opt) => options[opt])
|
||||
// .map((opt) => {
|
||||
// if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
|
||||
// return `--${opt}`;
|
||||
// }
|
||||
// return `--${opt}=${options[opt]}`;
|
||||
// });
|
||||
// Special case for the 'init' command which uses a different script
|
||||
function registerInitCommand(program) {
|
||||
program
|
||||
.command('init')
|
||||
.description('Initialize a new project')
|
||||
.option('-y, --yes', 'Skip prompts and use default values')
|
||||
.option('-n, --name <name>', 'Project name')
|
||||
.option('-d, --description <description>', 'Project description')
|
||||
.option('-v, --version <version>', 'Project version')
|
||||
.option('-a, --author <author>', 'Author name')
|
||||
.option('--skip-install', 'Skip installing dependencies')
|
||||
.option('--dry-run', 'Show what would be done without making changes')
|
||||
.action((options) => {
|
||||
// Pass through any options to the init script
|
||||
const args = ['--yes', 'name', 'description', 'version', 'author', 'skip-install', 'dry-run']
|
||||
.filter(opt => options[opt])
|
||||
.map(opt => {
|
||||
if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
|
||||
return `--${opt}`;
|
||||
}
|
||||
return `--${opt}=${options[opt]}`;
|
||||
});
|
||||
|
||||
// const child = spawn('node', [initScriptPath, ...args], {
|
||||
// stdio: 'inherit',
|
||||
// cwd: process.cwd()
|
||||
// });
|
||||
const child = spawn('node', [initScriptPath, ...args], {
|
||||
stdio: 'inherit',
|
||||
cwd: process.cwd()
|
||||
});
|
||||
|
||||
// child.on('close', (code) => {
|
||||
// process.exit(code);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
child.on('close', (code) => {
|
||||
process.exit(code);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Set up the command-line interface
|
||||
const program = new Command();
|
||||
@@ -286,8 +263,8 @@ program.on('--help', () => {
|
||||
displayHelp();
|
||||
});
|
||||
|
||||
// // Add special case commands
|
||||
// registerInitCommand(program);
|
||||
// Add special case commands
|
||||
registerInitCommand(program);
|
||||
|
||||
program
|
||||
.command('dev')
|
||||
@@ -302,18 +279,24 @@ const tempProgram = new Command();
|
||||
registerCommands(tempProgram);
|
||||
|
||||
// For each command in the temp instance, add a modified version to our actual program
|
||||
tempProgram.commands.forEach((cmd) => {
|
||||
if (['dev'].includes(cmd.name())) {
|
||||
tempProgram.commands.forEach(cmd => {
|
||||
if (['init', 'dev'].includes(cmd.name())) {
|
||||
// Skip commands we've already defined specially
|
||||
return;
|
||||
}
|
||||
|
||||
// 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())
|
||||
.description(cmd.description());
|
||||
|
||||
// Copy all options
|
||||
cmd.options.forEach((opt) => {
|
||||
newCmd.option(opt.flags, opt.description, opt.defaultValue);
|
||||
cmd.options.forEach(opt => {
|
||||
newCmd.option(
|
||||
opt.flags,
|
||||
opt.description,
|
||||
opt.defaultValue
|
||||
);
|
||||
});
|
||||
|
||||
// Set the action to proxy to dev.js
|
||||
@@ -328,21 +311,14 @@ process.on('uncaughtException', (err) => {
|
||||
// Check if this is a commander.js unknown option error
|
||||
if (err.code === 'commander.unknownOption') {
|
||||
const option = err.message.match(/'([^']+)'/)?.[1];
|
||||
const commandArg = process.argv.find(
|
||||
(arg) =>
|
||||
!arg.startsWith('-') &&
|
||||
const commandArg = process.argv.find(arg => !arg.startsWith('-') &&
|
||||
arg !== 'task-master' &&
|
||||
!arg.includes('/') &&
|
||||
arg !== 'node'
|
||||
);
|
||||
arg !== 'node');
|
||||
const command = commandArg || 'unknown';
|
||||
|
||||
console.error(chalk.red(`Error: Unknown option '${option}'`));
|
||||
console.error(
|
||||
chalk.yellow(
|
||||
`Run 'task-master ${command} --help' to see available options for this command`
|
||||
)
|
||||
);
|
||||
console.error(chalk.yellow(`Run 'task-master ${command} --help' to see available options for this command`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -351,9 +327,7 @@ process.on('uncaughtException', (err) => {
|
||||
const command = err.message.match(/'([^']+)'/)?.[1];
|
||||
|
||||
console.error(chalk.red(`Error: Unknown command '${command}'`));
|
||||
console.error(
|
||||
chalk.yellow(`Run 'task-master --help' to see available commands`)
|
||||
);
|
||||
console.error(chalk.yellow(`Run 'task-master --help' to see available commands`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,13 +90,13 @@ export const simpleFunction = adaptForMcp(originalFunction);
|
||||
// Split implementation - completely different code paths for CLI vs MCP
|
||||
export const complexFunction = sourceSplitFunction(
|
||||
// CLI version with UI
|
||||
function (param1, param2) {
|
||||
function(param1, param2) {
|
||||
displayBanner();
|
||||
console.log(`Processing ${param1}...`);
|
||||
// ... CLI implementation
|
||||
},
|
||||
// MCP version with structured return
|
||||
function (param1, param2, options = {}) {
|
||||
function(param1, param2, options = {}) {
|
||||
// ... MCP implementation
|
||||
return { success: true, data };
|
||||
}
|
||||
@@ -186,22 +186,22 @@ const commandMap = {
|
||||
|
||||
```javascript
|
||||
// In mcp-server/src/tools/newFeature.js
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
executeTaskMasterCommand,
|
||||
createContentResponse,
|
||||
createErrorResponse
|
||||
} from './utils.js';
|
||||
createErrorResponse,
|
||||
} from "./utils.js";
|
||||
|
||||
export function registerNewFeatureTool(server) {
|
||||
server.addTool({
|
||||
name: 'newFeature',
|
||||
description: 'Run the new feature',
|
||||
name: "newFeature",
|
||||
description: "Run the new feature",
|
||||
parameters: z.object({
|
||||
param1: z.string().describe('First parameter'),
|
||||
param2: z.number().optional().describe('Second parameter'),
|
||||
file: z.string().optional().describe('Path to the tasks file'),
|
||||
projectRoot: z.string().describe('Root directory of the project')
|
||||
param1: z.string().describe("First parameter"),
|
||||
param2: z.number().optional().describe("Second parameter"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().describe("Root directory of the project")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
@@ -216,7 +216,7 @@ export function registerNewFeatureTool(server) {
|
||||
|
||||
// Execute the command
|
||||
const result = await executeTaskMasterCommand(
|
||||
'new-feature',
|
||||
"new-feature",
|
||||
log,
|
||||
cmdArgs,
|
||||
projectRoot
|
||||
@@ -231,7 +231,7 @@ export function registerNewFeatureTool(server) {
|
||||
log.error(`Error in new feature: ${error.message}`);
|
||||
return createErrorResponse(`Error in new feature: ${error.message}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
```
|
||||
@@ -240,7 +240,7 @@ export function registerNewFeatureTool(server) {
|
||||
|
||||
```javascript
|
||||
// In mcp-server/src/tools/index.js
|
||||
import { registerNewFeatureTool } from './newFeature.js';
|
||||
import { registerNewFeatureTool } from "./newFeature.js";
|
||||
|
||||
export function registerTaskMasterTools(server) {
|
||||
// ... existing registrations
|
||||
|
||||
@@ -41,7 +41,11 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["data", "mimeType", "type"],
|
||||
"required": [
|
||||
"data",
|
||||
"mimeType",
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"BlobResourceContents": {
|
||||
@@ -61,7 +65,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["blob", "uri"],
|
||||
"required": [
|
||||
"blob",
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CallToolRequest": {
|
||||
@@ -81,11 +88,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CallToolResult": {
|
||||
@@ -120,7 +132,9 @@
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["content"],
|
||||
"required": [
|
||||
"content"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CancelledNotification": {
|
||||
@@ -141,11 +155,16 @@
|
||||
"description": "The ID of the request to cancel.\n\nThis MUST correspond to the ID of a request previously issued in the same direction."
|
||||
}
|
||||
},
|
||||
"required": ["requestId"],
|
||||
"required": [
|
||||
"requestId"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ClientCapabilities": {
|
||||
@@ -269,7 +288,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "value"],
|
||||
"required": [
|
||||
"name",
|
||||
"value"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ref": {
|
||||
@@ -283,11 +305,17 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["argument", "ref"],
|
||||
"required": [
|
||||
"argument",
|
||||
"ref"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CompleteResult": {
|
||||
@@ -316,11 +344,15 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["values"],
|
||||
"required": [
|
||||
"values"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["completion"],
|
||||
"required": [
|
||||
"completion"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CreateMessageRequest": {
|
||||
@@ -334,7 +366,11 @@
|
||||
"properties": {
|
||||
"includeContext": {
|
||||
"description": "A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.",
|
||||
"enum": ["allServers", "none", "thisServer"],
|
||||
"enum": [
|
||||
"allServers",
|
||||
"none",
|
||||
"thisServer"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"maxTokens": {
|
||||
@@ -371,11 +407,17 @@
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": ["maxTokens", "messages"],
|
||||
"required": [
|
||||
"maxTokens",
|
||||
"messages"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CreateMessageResult": {
|
||||
@@ -411,7 +453,11 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["content", "model", "role"],
|
||||
"required": [
|
||||
"content",
|
||||
"model",
|
||||
"role"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Cursor": {
|
||||
@@ -440,7 +486,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["resource", "type"],
|
||||
"required": [
|
||||
"resource",
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"EmptyResult": {
|
||||
@@ -467,11 +516,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"GetPromptResult": {
|
||||
@@ -493,7 +547,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["messages"],
|
||||
"required": [
|
||||
"messages"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ImageContent": {
|
||||
@@ -517,7 +573,11 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["data", "mimeType", "type"],
|
||||
"required": [
|
||||
"data",
|
||||
"mimeType",
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Implementation": {
|
||||
@@ -530,7 +590,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "version"],
|
||||
"required": [
|
||||
"name",
|
||||
"version"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"InitializeRequest": {
|
||||
@@ -553,11 +616,18 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["capabilities", "clientInfo", "protocolVersion"],
|
||||
"required": [
|
||||
"capabilities",
|
||||
"clientInfo",
|
||||
"protocolVersion"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"InitializeResult": {
|
||||
@@ -583,7 +653,11 @@
|
||||
"$ref": "#/definitions/Implementation"
|
||||
}
|
||||
},
|
||||
"required": ["capabilities", "protocolVersion", "serverInfo"],
|
||||
"required": [
|
||||
"capabilities",
|
||||
"protocolVersion",
|
||||
"serverInfo"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"InitializedNotification": {
|
||||
@@ -605,7 +679,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"JSONRPCBatchRequest": {
|
||||
@@ -653,7 +729,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["code", "message"],
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"id": {
|
||||
@@ -664,7 +743,11 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["error", "id", "jsonrpc"],
|
||||
"required": [
|
||||
"error",
|
||||
"id",
|
||||
"jsonrpc"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"JSONRPCMessage": {
|
||||
@@ -734,7 +817,10 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["jsonrpc", "method"],
|
||||
"required": [
|
||||
"jsonrpc",
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"JSONRPCRequest": {
|
||||
@@ -766,7 +852,11 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["id", "jsonrpc", "method"],
|
||||
"required": [
|
||||
"id",
|
||||
"jsonrpc",
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"JSONRPCResponse": {
|
||||
@@ -783,7 +873,11 @@
|
||||
"$ref": "#/definitions/Result"
|
||||
}
|
||||
},
|
||||
"required": ["id", "jsonrpc", "result"],
|
||||
"required": [
|
||||
"id",
|
||||
"jsonrpc",
|
||||
"result"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListPromptsRequest": {
|
||||
@@ -803,7 +897,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListPromptsResult": {
|
||||
@@ -825,7 +921,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["prompts"],
|
||||
"required": [
|
||||
"prompts"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListResourceTemplatesRequest": {
|
||||
@@ -845,7 +943,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListResourceTemplatesResult": {
|
||||
@@ -867,7 +967,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["resourceTemplates"],
|
||||
"required": [
|
||||
"resourceTemplates"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListResourcesRequest": {
|
||||
@@ -887,7 +989,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListResourcesResult": {
|
||||
@@ -909,7 +1013,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["resources"],
|
||||
"required": [
|
||||
"resources"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListRootsRequest": {
|
||||
@@ -935,7 +1041,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListRootsResult": {
|
||||
@@ -953,7 +1061,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["roots"],
|
||||
"required": [
|
||||
"roots"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListToolsRequest": {
|
||||
@@ -973,7 +1083,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ListToolsResult": {
|
||||
@@ -995,7 +1107,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["tools"],
|
||||
"required": [
|
||||
"tools"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"LoggingLevel": {
|
||||
@@ -1033,11 +1147,17 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["data", "level"],
|
||||
"required": [
|
||||
"data",
|
||||
"level"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ModelHint": {
|
||||
@@ -1098,7 +1218,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PaginatedRequest": {
|
||||
@@ -1116,7 +1238,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PaginatedResult": {
|
||||
@@ -1156,7 +1280,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ProgressNotification": {
|
||||
@@ -1185,16 +1311,25 @@
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": ["progress", "progressToken"],
|
||||
"required": [
|
||||
"progress",
|
||||
"progressToken"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ProgressToken": {
|
||||
"description": "A progress token, used to associate progress notifications with the original request.",
|
||||
"type": ["string", "integer"]
|
||||
"type": [
|
||||
"string",
|
||||
"integer"
|
||||
]
|
||||
},
|
||||
"Prompt": {
|
||||
"description": "A prompt or prompt template that the server offers.",
|
||||
@@ -1215,7 +1350,9 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PromptArgument": {
|
||||
@@ -1234,7 +1371,9 @@
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PromptListChangedNotification": {
|
||||
@@ -1256,7 +1395,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PromptMessage": {
|
||||
@@ -1282,7 +1423,10 @@
|
||||
"$ref": "#/definitions/Role"
|
||||
}
|
||||
},
|
||||
"required": ["content", "role"],
|
||||
"required": [
|
||||
"content",
|
||||
"role"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PromptReference": {
|
||||
@@ -1297,7 +1441,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "type"],
|
||||
"required": [
|
||||
"name",
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ReadResourceRequest": {
|
||||
@@ -1315,11 +1462,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ReadResourceResult": {
|
||||
@@ -1344,7 +1496,9 @@
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": ["contents"],
|
||||
"required": [
|
||||
"contents"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Request": {
|
||||
@@ -1368,12 +1522,17 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"RequestId": {
|
||||
"description": "A uniquely identifying ID for a request in JSON-RPC.",
|
||||
"type": ["string", "integer"]
|
||||
"type": [
|
||||
"string",
|
||||
"integer"
|
||||
]
|
||||
},
|
||||
"Resource": {
|
||||
"description": "A known resource that the server is capable of reading.",
|
||||
@@ -1400,7 +1559,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "uri"],
|
||||
"required": [
|
||||
"name",
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ResourceContents": {
|
||||
@@ -1416,7 +1578,9 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ResourceListChangedNotification": {
|
||||
@@ -1438,7 +1602,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ResourceReference": {
|
||||
@@ -1454,7 +1620,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["type", "uri"],
|
||||
"required": [
|
||||
"type",
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ResourceTemplate": {
|
||||
@@ -1482,7 +1651,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["name", "uriTemplate"],
|
||||
"required": [
|
||||
"name",
|
||||
"uriTemplate"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ResourceUpdatedNotification": {
|
||||
@@ -1500,11 +1672,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Result": {
|
||||
@@ -1520,7 +1697,10 @@
|
||||
},
|
||||
"Role": {
|
||||
"description": "The sender or recipient of messages and data in a conversation.",
|
||||
"enum": ["assistant", "user"],
|
||||
"enum": [
|
||||
"assistant",
|
||||
"user"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"Root": {
|
||||
@@ -1536,7 +1716,9 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"RootsListChangedNotification": {
|
||||
@@ -1558,7 +1740,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"SamplingMessage": {
|
||||
@@ -1581,7 +1765,10 @@
|
||||
"$ref": "#/definitions/Role"
|
||||
}
|
||||
},
|
||||
"required": ["content", "role"],
|
||||
"required": [
|
||||
"content",
|
||||
"role"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ServerCapabilities": {
|
||||
@@ -1728,11 +1915,16 @@
|
||||
"description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message."
|
||||
}
|
||||
},
|
||||
"required": ["level"],
|
||||
"required": [
|
||||
"level"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"SubscribeRequest": {
|
||||
@@ -1750,11 +1942,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"TextContent": {
|
||||
@@ -1773,7 +1970,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["text", "type"],
|
||||
"required": [
|
||||
"text",
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"TextResourceContents": {
|
||||
@@ -1792,7 +1992,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["text", "uri"],
|
||||
"required": [
|
||||
"text",
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Tool": {
|
||||
@@ -1828,7 +2031,9 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["type"],
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"name": {
|
||||
@@ -1836,7 +2041,10 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["inputSchema", "name"],
|
||||
"required": [
|
||||
"inputSchema",
|
||||
"name"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ToolAnnotations": {
|
||||
@@ -1884,7 +2092,9 @@
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method"],
|
||||
"required": [
|
||||
"method"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"UnsubscribeRequest": {
|
||||
@@ -1902,11 +2112,16 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["uri"],
|
||||
"required": [
|
||||
"uri"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": ["method", "params"],
|
||||
"required": [
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ export async function someAiOperationDirect(args, log, context) {
|
||||
model: modelConfig.model,
|
||||
max_tokens: modelConfig.maxTokens,
|
||||
temperature: modelConfig.temperature,
|
||||
messages: [{ role: 'user', content: 'Your prompt here' }]
|
||||
messages: [
|
||||
{ role: 'user', content: 'Your prompt here' }
|
||||
]
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -62,10 +64,7 @@ export async function someAiOperationDirect(args, log, context) {
|
||||
|
||||
```javascript
|
||||
// In your MCP tool implementation:
|
||||
import {
|
||||
AsyncOperationManager,
|
||||
StatusCodes
|
||||
} from '../../utils/async-operation-manager.js';
|
||||
import { AsyncOperationManager, StatusCodes } from '../../utils/async-operation-manager.js';
|
||||
import { someAiOperationDirect } from '../../core/direct-functions/some-ai-operation.js';
|
||||
|
||||
export async function someAiOperation(args, context) {
|
||||
@@ -88,11 +87,15 @@ export async function someAiOperation(args, context) {
|
||||
});
|
||||
|
||||
// Call direct function with session and progress reporting
|
||||
const result = await someAiOperationDirect(args, log, {
|
||||
const result = await someAiOperationDirect(
|
||||
args,
|
||||
log,
|
||||
{
|
||||
reportProgress,
|
||||
mcpLog: log,
|
||||
session
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Final progress update
|
||||
reportProgress({
|
||||
@@ -175,7 +178,9 @@ export async function researchOperationDirect(args, log, context) {
|
||||
// Call Perplexity
|
||||
const response = await client.chat.completions.create({
|
||||
model: context.session?.env?.PERPLEXITY_MODEL || 'sonar-medium-online',
|
||||
messages: [{ role: 'user', content: args.researchQuery }],
|
||||
messages: [
|
||||
{ role: 'user', content: args.researchQuery }
|
||||
],
|
||||
temperature: 0.1
|
||||
});
|
||||
|
||||
@@ -221,7 +226,7 @@ const modelConfig = getModelConfig(context.session, operationDefaults);
|
||||
const response = await client.messages.create({
|
||||
model: modelConfig.model,
|
||||
max_tokens: modelConfig.maxTokens,
|
||||
temperature: modelConfig.temperature
|
||||
temperature: modelConfig.temperature,
|
||||
// Other parameters...
|
||||
});
|
||||
```
|
||||
@@ -229,24 +234,20 @@ const response = await client.messages.create({
|
||||
## Best Practices
|
||||
|
||||
1. **Error Handling**:
|
||||
|
||||
- Always use try/catch blocks around both client initialization and API calls
|
||||
- Use `handleClaudeError` to provide user-friendly error messages
|
||||
- Return standardized error objects with code and message
|
||||
|
||||
2. **Progress Reporting**:
|
||||
|
||||
- Report progress at key points (starting, processing, completing)
|
||||
- Include meaningful status messages
|
||||
- Include error details in progress reports when failures occur
|
||||
|
||||
3. **Session Handling**:
|
||||
|
||||
- Always pass the session from the context to the AI client getters
|
||||
- Use `getModelConfig` to respect user settings from session
|
||||
|
||||
4. **Model Selection**:
|
||||
|
||||
- Use `getBestAvailableAIModel` when you need to select between different models
|
||||
- Set `requiresResearch: true` when you need Perplexity capabilities
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
|
||||
"mcpServers": {
|
||||
"taskmaster-ai": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "task-master-ai"],
|
||||
"args": ["-y", "task-master-ai", "mcp-server"],
|
||||
"env": {
|
||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||
"MODEL": "claude-3-7-sonnet-20250219",
|
||||
"PERPLEXITY_MODEL": "sonar-pro",
|
||||
"MAX_TOKENS": 64000,
|
||||
"MAX_TOKENS": 128000,
|
||||
"TEMPERATURE": 0.2,
|
||||
"DEFAULT_SUBTASKS": 5,
|
||||
"DEFAULT_PRIORITY": "medium"
|
||||
@@ -132,7 +132,7 @@ You can also set up the MCP server in Cursor settings:
|
||||
4. Configure with the following details:
|
||||
- Name: "Task Master"
|
||||
- Type: "Command"
|
||||
- Command: "npx -y task-master-mcp"
|
||||
- Command: "npx -y --package task-master-ai task-master-mcp"
|
||||
5. Save the settings
|
||||
|
||||
Once configured, you can interact with Task Master's task management commands directly through Cursor's interface, providing a more integrated experience.
|
||||
|
||||
41
entries.json
Normal file
41
entries.json
Normal 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}.")
|
||||
42
index.js
42
index.js
@@ -46,18 +46,22 @@ export const initProject = async (options = {}) => {
|
||||
};
|
||||
|
||||
// Export a function to run init as a CLI command
|
||||
export const runInitCLI = async (options = {}) => {
|
||||
try {
|
||||
const init = await import('./scripts/init.js');
|
||||
const result = await init.initializeProject(options);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('Initialization failed:', error.message);
|
||||
if (process.env.DEBUG === 'true') {
|
||||
console.error('Debug stack trace:', error.stack);
|
||||
}
|
||||
throw error; // Re-throw to be handled by the command handler
|
||||
export const runInitCLI = async () => {
|
||||
// Using spawn to ensure proper handling of stdio and process exit
|
||||
const child = spawn('node', [resolve(__dirname, './scripts/init.js')], {
|
||||
stdio: 'inherit',
|
||||
cwd: process.cwd()
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
child.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Init script exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Export version information
|
||||
@@ -75,21 +79,11 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
program
|
||||
.command('init')
|
||||
.description('Initialize a new project')
|
||||
.option('-y, --yes', 'Skip prompts and use default values')
|
||||
.option('-n, --name <n>', 'Project name')
|
||||
.option('-d, --description <description>', 'Project description')
|
||||
.option('-v, --version <version>', 'Project version', '0.1.0')
|
||||
.option('-a, --author <author>', 'Author name')
|
||||
.option('--skip-install', 'Skip installing dependencies')
|
||||
.option('--dry-run', 'Show what would be done without making changes')
|
||||
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
||||
.action(async (cmdOptions) => {
|
||||
try {
|
||||
await runInitCLI(cmdOptions);
|
||||
} catch (err) {
|
||||
.action(() => {
|
||||
runInitCLI().catch(err => {
|
||||
console.error('Init failed:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import TaskMasterMCPServer from './src/index.js';
|
||||
import dotenv from 'dotenv';
|
||||
import logger from './src/logger.js';
|
||||
import TaskMasterMCPServer from "./src/index.js";
|
||||
import dotenv from "dotenv";
|
||||
import logger from "./src/logger.js";
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
@@ -14,12 +14,12 @@ async function startServer() {
|
||||
const server = new TaskMasterMCPServer();
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
process.on("SIGINT", async () => {
|
||||
await server.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
process.on("SIGTERM", async () => {
|
||||
await server.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -14,9 +14,7 @@ describe('ContextManager', () => {
|
||||
|
||||
describe('getContext', () => {
|
||||
it('should create a new context when not in cache', async () => {
|
||||
const context = await contextManager.getContext('test-id', {
|
||||
test: true
|
||||
});
|
||||
const context = await contextManager.getContext('test-id', { test: true });
|
||||
expect(context.id).toBe('test-id');
|
||||
expect(context.metadata.test).toBe(true);
|
||||
expect(contextManager.stats.misses).toBe(1);
|
||||
@@ -28,9 +26,7 @@ describe('ContextManager', () => {
|
||||
await contextManager.getContext('test-id', { test: true });
|
||||
|
||||
// Second call should hit cache
|
||||
const context = await contextManager.getContext('test-id', {
|
||||
test: true
|
||||
});
|
||||
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);
|
||||
@@ -42,7 +38,7 @@ describe('ContextManager', () => {
|
||||
await contextManager.getContext('test-id', { test: true });
|
||||
|
||||
// Wait for TTL to expire
|
||||
await new Promise((resolve) => setTimeout(resolve, 1100));
|
||||
await new Promise(resolve => setTimeout(resolve, 1100));
|
||||
|
||||
// Should create new context
|
||||
await contextManager.getContext('test-id', { test: true });
|
||||
@@ -54,9 +50,7 @@ describe('ContextManager', () => {
|
||||
describe('updateContext', () => {
|
||||
it('should update existing context metadata', async () => {
|
||||
await contextManager.getContext('test-id', { initial: true });
|
||||
const updated = await contextManager.updateContext('test-id', {
|
||||
updated: true
|
||||
});
|
||||
const updated = await contextManager.updateContext('test-id', { updated: true });
|
||||
|
||||
expect(updated.metadata.initial).toBe(true);
|
||||
expect(updated.metadata.updated).toBe(true);
|
||||
|
||||
@@ -112,8 +112,7 @@ export class ContextManager {
|
||||
*/
|
||||
getCachedData(key) {
|
||||
const cached = this.cache.get(key);
|
||||
if (cached !== undefined) {
|
||||
// Check for undefined specifically, as null/false might be valid cached values
|
||||
if (cached !== undefined) { // Check for undefined specifically, as null/false might be valid cached values
|
||||
this.stats.hits++;
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -4,41 +4,26 @@
|
||||
*/
|
||||
|
||||
import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for addDependency with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string|number} args.id - Task ID to add dependency to
|
||||
* @param {string|number} args.dependsOn - Task ID that will become a dependency
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information
|
||||
*/
|
||||
export async function addDependencyDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id, dependsOn } = args;
|
||||
try {
|
||||
log.info(`Adding dependency with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('addDependencyDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Validate required parameters
|
||||
if (!id) {
|
||||
if (!args.id) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -48,7 +33,7 @@ export async function addDependencyDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!dependsOn) {
|
||||
if (!args.dependsOn) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -58,25 +43,19 @@ export async function addDependencyDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Format IDs for the core function
|
||||
const taskId =
|
||||
id && id.includes && id.includes('.') ? id : parseInt(id, 10);
|
||||
const dependencyId =
|
||||
dependsOn && dependsOn.includes && dependsOn.includes('.')
|
||||
? dependsOn
|
||||
: parseInt(dependsOn, 10);
|
||||
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
|
||||
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
|
||||
|
||||
log.info(
|
||||
`Adding dependency: task ${taskId} will depend on ${dependencyId}`
|
||||
);
|
||||
log.info(`Adding dependency: task ${taskId} will depend on ${dependencyId}`);
|
||||
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Call the core function using the provided path
|
||||
// Call the core function
|
||||
await addDependency(tasksPath, taskId, dependencyId);
|
||||
|
||||
// Restore normal logging
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
*/
|
||||
|
||||
import { addSubtask } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Add a subtask to an existing task
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} args.id - Parent task ID
|
||||
* @param {string} [args.taskId] - Existing task ID to convert to subtask (optional)
|
||||
* @param {string} [args.title] - Title for new subtask (when creating a new subtask)
|
||||
@@ -19,39 +16,17 @@ import {
|
||||
* @param {string} [args.details] - Implementation details for new subtask
|
||||
* @param {string} [args.status] - Status for new subtask (default: 'pending')
|
||||
* @param {string} [args.dependencies] - Comma-separated list of dependency IDs
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {boolean} [args.skipGenerate] - Skip regenerating task files
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: string}>}
|
||||
*/
|
||||
export async function addSubtaskDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const {
|
||||
tasksJsonPath,
|
||||
id,
|
||||
taskId,
|
||||
title,
|
||||
description,
|
||||
details,
|
||||
status,
|
||||
dependencies: dependenciesStr,
|
||||
skipGenerate
|
||||
} = args;
|
||||
try {
|
||||
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('addSubtaskDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
if (!args.id) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -62,7 +37,7 @@ export async function addSubtaskDirect(args, log) {
|
||||
}
|
||||
|
||||
// Either taskId or title must be provided
|
||||
if (!taskId && !title) {
|
||||
if (!args.taskId && !args.title) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -72,26 +47,26 @@ export async function addSubtaskDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Parse dependencies if provided
|
||||
let dependencies = [];
|
||||
if (dependenciesStr) {
|
||||
dependencies = dependenciesStr.split(',').map((depId) => {
|
||||
if (args.dependencies) {
|
||||
dependencies = args.dependencies.split(',').map(id => {
|
||||
// Handle both regular IDs and dot notation
|
||||
return depId.includes('.') ? depId.trim() : parseInt(depId.trim(), 10);
|
||||
return id.includes('.') ? id.trim() : parseInt(id.trim(), 10);
|
||||
});
|
||||
}
|
||||
|
||||
// Convert existingTaskId to a number if provided
|
||||
const existingTaskId = taskId ? parseInt(taskId, 10) : null;
|
||||
const existingTaskId = args.taskId ? parseInt(args.taskId, 10) : null;
|
||||
|
||||
// Convert parent ID to a number
|
||||
const parentId = parseInt(id, 10);
|
||||
const parentId = parseInt(args.id, 10);
|
||||
|
||||
// Determine if we should generate files
|
||||
const generateFiles = !skipGenerate;
|
||||
const generateFiles = !args.skipGenerate;
|
||||
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
@@ -99,13 +74,7 @@ export async function addSubtaskDirect(args, log) {
|
||||
// Case 1: Convert existing task to subtask
|
||||
if (existingTaskId) {
|
||||
log.info(`Converting task ${existingTaskId} to a subtask of ${parentId}`);
|
||||
const result = await addSubtask(
|
||||
tasksPath,
|
||||
parentId,
|
||||
existingTaskId,
|
||||
null,
|
||||
generateFiles
|
||||
);
|
||||
const result = await addSubtask(tasksPath, parentId, existingTaskId, null, generateFiles);
|
||||
|
||||
// Restore normal logging
|
||||
disableSilentMode();
|
||||
@@ -123,20 +92,14 @@ export async function addSubtaskDirect(args, log) {
|
||||
log.info(`Creating new subtask for parent task ${parentId}`);
|
||||
|
||||
const newSubtaskData = {
|
||||
title: title,
|
||||
description: description || '',
|
||||
details: details || '',
|
||||
status: status || 'pending',
|
||||
title: args.title,
|
||||
description: args.description || '',
|
||||
details: args.details || '',
|
||||
status: args.status || 'pending',
|
||||
dependencies: dependencies
|
||||
};
|
||||
|
||||
const result = await addSubtask(
|
||||
tasksPath,
|
||||
parentId,
|
||||
null,
|
||||
newSubtaskData,
|
||||
generateFiles
|
||||
);
|
||||
const result = await addSubtask(tasksPath, parentId, null, newSubtaskData, generateFiles);
|
||||
|
||||
// Restore normal logging
|
||||
disableSilentMode();
|
||||
|
||||
@@ -4,139 +4,59 @@
|
||||
*/
|
||||
|
||||
import { addTask } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getModelConfig
|
||||
} from '../utils/ai-client-utils.js';
|
||||
import {
|
||||
_buildAddTaskPrompt,
|
||||
parseTaskJsonResponse,
|
||||
_handleAnthropicStream
|
||||
} from '../../../../scripts/modules/ai-services.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.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.
|
||||
*
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {string} [args.prompt] - Description of the task to add (required if not using manual fields)
|
||||
* @param {string} [args.title] - Task title (for manual task creation)
|
||||
* @param {string} [args.description] - Task description (for manual task creation)
|
||||
* @param {string} [args.details] - Implementation details (for manual task creation)
|
||||
* @param {string} [args.testStrategy] - Test strategy (for manual task creation)
|
||||
* @param {string} [args.dependencies] - Comma-separated list of task IDs this task depends on
|
||||
* @param {string} args.prompt - Description of the task to add
|
||||
* @param {Array<number>} [args.dependencies=[]] - Task dependencies as array of IDs
|
||||
* @param {string} [args.priority='medium'] - Task priority (high, medium, low)
|
||||
* @param {string} [args.file='tasks/tasks.json'] - Path to the tasks file
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {boolean} [args.research=false] - Whether to use research capabilities for task creation
|
||||
* @param {boolean} [args.research] - Whether to use research capabilities for task creation
|
||||
* @param {Object} log - Logger object
|
||||
* @param {Object} context - Additional context (reportProgress, session)
|
||||
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
|
||||
*/
|
||||
export async function addTaskDirect(args, log, context = {}) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, prompt, dependencies, priority, research } = args;
|
||||
try {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('addTaskDirect called without tasksJsonPath');
|
||||
disableSilentMode(); // Disable before returning
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
|
||||
// Check if this is manual task creation or AI-driven task creation
|
||||
const isManualCreation = args.title && args.description;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Check required parameters
|
||||
if (!args.prompt && !isManualCreation) {
|
||||
log.error(
|
||||
'Missing required parameters: either prompt or title+description must be provided'
|
||||
);
|
||||
if (!args.prompt) {
|
||||
log.error('Missing required parameter: prompt');
|
||||
disableSilentMode();
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_PARAMETER',
|
||||
message:
|
||||
'Either the prompt parameter or both title and description parameters are required for adding a task'
|
||||
message: 'The prompt parameter is required for adding a task'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Extract and prepare parameters
|
||||
const taskPrompt = prompt;
|
||||
const taskDependencies = Array.isArray(dependencies)
|
||||
? dependencies
|
||||
: dependencies
|
||||
? String(dependencies)
|
||||
.split(',')
|
||||
.map((id) => parseInt(id.trim(), 10))
|
||||
: [];
|
||||
const taskPriority = priority || 'medium';
|
||||
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
|
||||
const { session } = context;
|
||||
|
||||
let manualTaskData = null;
|
||||
|
||||
if (isManualCreation) {
|
||||
// Create manual task data object
|
||||
manualTaskData = {
|
||||
title: args.title,
|
||||
description: args.description,
|
||||
details: args.details || '',
|
||||
testStrategy: args.testStrategy || ''
|
||||
};
|
||||
|
||||
log.info(
|
||||
`Adding new task manually with title: "${args.title}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}`
|
||||
);
|
||||
|
||||
// Call the addTask function with manual task data
|
||||
const newTaskId = await addTask(
|
||||
tasksPath,
|
||||
null, // No prompt needed for manual creation
|
||||
taskDependencies,
|
||||
priority,
|
||||
{
|
||||
mcpLog: log,
|
||||
session
|
||||
},
|
||||
'json', // Use JSON output format to prevent console output
|
||||
null, // No custom environment
|
||||
manualTaskData // Pass the manual task data
|
||||
);
|
||||
|
||||
// Restore normal logging
|
||||
disableSilentMode();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
taskId: newTaskId,
|
||||
message: `Successfully added new task #${newTaskId}`
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// AI-driven task creation
|
||||
log.info(
|
||||
`Adding new task with prompt: "${prompt}", dependencies: [${taskDependencies.join(', ')}], priority: ${priority}`
|
||||
);
|
||||
// Commenting out reportProgress extraction
|
||||
// const { reportProgress, session } = context;
|
||||
const { session } = context; // Keep session
|
||||
|
||||
// Initialize AI client with session environment
|
||||
let localAnthropic;
|
||||
@@ -168,10 +88,7 @@ export async function addTaskDirect(args, log, context = {}) {
|
||||
}
|
||||
|
||||
// Build prompts for AI
|
||||
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(
|
||||
prompt,
|
||||
tasksData.tasks
|
||||
);
|
||||
const { systemPrompt, userPrompt } = _buildAddTaskPrompt(prompt, tasksData.tasks);
|
||||
|
||||
// Make the AI call using the streaming helper
|
||||
let responseText;
|
||||
@@ -182,10 +99,11 @@ export async function addTaskDirect(args, log, context = {}) {
|
||||
model: modelConfig.model,
|
||||
max_tokens: modelConfig.maxTokens,
|
||||
temperature: modelConfig.temperature,
|
||||
messages: [{ role: 'user', content: userPrompt }],
|
||||
messages: [{ role: "user", content: userPrompt }],
|
||||
system: systemPrompt
|
||||
},
|
||||
{
|
||||
// reportProgress: context.reportProgress, // Commented out to prevent Cursor stroking out
|
||||
mcpLog: log
|
||||
}
|
||||
);
|
||||
@@ -221,15 +139,15 @@ export async function addTaskDirect(args, log, context = {}) {
|
||||
const newTaskId = await addTask(
|
||||
tasksPath,
|
||||
prompt,
|
||||
taskDependencies,
|
||||
dependencies,
|
||||
priority,
|
||||
{
|
||||
// reportProgress, // Commented out
|
||||
mcpLog: log,
|
||||
session
|
||||
session,
|
||||
taskDataFromAI // Pass the parsed AI result
|
||||
},
|
||||
'json',
|
||||
null,
|
||||
taskDataFromAI // Pass the parsed AI result as the manual task data
|
||||
'json'
|
||||
);
|
||||
|
||||
// Restore normal logging
|
||||
@@ -242,7 +160,6 @@ export async function addTaskDirect(args, log, context = {}) {
|
||||
message: `Successfully added new task #${newTaskId}`
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
// Make sure to restore normal logging even if there's an error
|
||||
disableSilentMode();
|
||||
|
||||
@@ -3,72 +3,53 @@
|
||||
*/
|
||||
|
||||
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode,
|
||||
isSilentMode,
|
||||
readJSON
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode, isSilentMode, readJSON } from '../../../../scripts/modules/utils.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Analyze task complexity and generate recommendations
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} args.outputPath - Explicit absolute path to save the report.
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.output] - Output file path for the report
|
||||
* @param {string} [args.model] - LLM model to use for analysis
|
||||
* @param {string|number} [args.threshold] - Minimum complexity score to recommend expansion (1-10)
|
||||
* @param {boolean} [args.research] - Use Perplexity AI for research-backed complexity analysis
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @param {Object} [context={}] - Context object containing session data
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
||||
const { session } = context; // Only extract session, not reportProgress
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, outputPath, model, threshold, research } = args;
|
||||
|
||||
try {
|
||||
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if required paths were provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('analyzeTaskComplexityDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
if (!outputPath) {
|
||||
log.error('analyzeTaskComplexityDirect called without outputPath');
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: 'outputPath is required' }
|
||||
};
|
||||
}
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Use the provided paths
|
||||
const tasksPath = tasksJsonPath;
|
||||
const resolvedOutputPath = outputPath;
|
||||
// Determine output path
|
||||
let outputPath = args.output || 'scripts/task-complexity-report.json';
|
||||
if (!path.isAbsolute(outputPath) && args.projectRoot) {
|
||||
outputPath = path.join(args.projectRoot, outputPath);
|
||||
}
|
||||
|
||||
log.info(`Analyzing task complexity from: ${tasksPath}`);
|
||||
log.info(`Output report will be saved to: ${resolvedOutputPath}`);
|
||||
log.info(`Output report will be saved to: ${outputPath}`);
|
||||
|
||||
if (research) {
|
||||
if (args.research) {
|
||||
log.info('Using Perplexity AI for research-backed complexity analysis');
|
||||
}
|
||||
|
||||
// Create options object for analyzeTaskComplexity using provided paths
|
||||
// Create options object for analyzeTaskComplexity
|
||||
const options = {
|
||||
file: tasksPath,
|
||||
output: resolvedOutputPath,
|
||||
model: model,
|
||||
threshold: threshold,
|
||||
research: research === true
|
||||
output: outputPath,
|
||||
model: args.model,
|
||||
threshold: args.threshold,
|
||||
research: args.research === true
|
||||
};
|
||||
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
@@ -109,7 +90,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
||||
}
|
||||
|
||||
// Verify the report file was created
|
||||
if (!fs.existsSync(resolvedOutputPath)) {
|
||||
if (!fs.existsSync(outputPath)) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -122,30 +103,23 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
||||
// Read the report file
|
||||
let report;
|
||||
try {
|
||||
report = JSON.parse(fs.readFileSync(resolvedOutputPath, 'utf8'));
|
||||
report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||
|
||||
// Important: Handle different report formats
|
||||
// The core function might return an array or an object with a complexityAnalysis property
|
||||
const analysisArray = Array.isArray(report)
|
||||
? report
|
||||
: report.complexityAnalysis || [];
|
||||
const analysisArray = Array.isArray(report) ? report :
|
||||
(report.complexityAnalysis || []);
|
||||
|
||||
// Count tasks by complexity
|
||||
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;
|
||||
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 {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Task complexity analysis complete. Report saved to ${resolvedOutputPath}`,
|
||||
reportPath: resolvedOutputPath,
|
||||
message: `Task complexity analysis complete. Report saved to ${outputPath}`,
|
||||
reportPath: outputPath,
|
||||
reportSummary: {
|
||||
taskCount: analysisArray.length,
|
||||
highComplexityTasks,
|
||||
|
||||
@@ -3,53 +3,37 @@
|
||||
*/
|
||||
|
||||
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import fs from 'fs';
|
||||
|
||||
/**
|
||||
* Clear subtasks from specified tasks
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from
|
||||
* @param {boolean} [args.all] - Clear subtasks from all tasks
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function clearSubtasksDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id, all } = args;
|
||||
try {
|
||||
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('clearSubtasksDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Either id or all must be provided
|
||||
if (!id && !all) {
|
||||
if (!args.id && !args.all) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INPUT_VALIDATION_ERROR',
|
||||
message:
|
||||
'Either task IDs with id parameter or all parameter must be provided'
|
||||
message: 'Either task IDs with id parameter or all parameter must be provided'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Check if tasks.json exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
@@ -65,7 +49,7 @@ export async function clearSubtasksDirect(args, log) {
|
||||
let taskIds;
|
||||
|
||||
// If all is specified, get all task IDs
|
||||
if (all) {
|
||||
if (args.all) {
|
||||
log.info('Clearing subtasks from all tasks');
|
||||
const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
|
||||
if (!data || !data.tasks || data.tasks.length === 0) {
|
||||
@@ -77,10 +61,10 @@ export async function clearSubtasksDirect(args, log) {
|
||||
}
|
||||
};
|
||||
}
|
||||
taskIds = data.tasks.map((t) => t.id).join(',');
|
||||
taskIds = data.tasks.map(t => t.id).join(',');
|
||||
} else {
|
||||
// Use the provided task IDs
|
||||
taskIds = id;
|
||||
taskIds = args.id;
|
||||
}
|
||||
|
||||
log.info(`Clearing subtasks from tasks: ${taskIds}`);
|
||||
@@ -96,12 +80,12 @@ export async function clearSubtasksDirect(args, log) {
|
||||
|
||||
// Read the updated data to provide a summary
|
||||
const updatedData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
|
||||
const taskIdArray = taskIds.split(',').map((id) => parseInt(id.trim(), 10));
|
||||
const taskIdArray = taskIds.split(',').map(id => parseInt(id.trim(), 10));
|
||||
|
||||
// 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);
|
||||
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' };
|
||||
});
|
||||
|
||||
|
||||
@@ -3,39 +3,34 @@
|
||||
* Direct function implementation for displaying complexity analysis report
|
||||
*/
|
||||
|
||||
import {
|
||||
readComplexityReport,
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { readComplexityReport, enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for displaying the complexity report with error handling and caching.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing reportPath.
|
||||
* @param {string} args.reportPath - Explicit path to the complexity report file.
|
||||
* @param {Object} args - Command arguments containing file path option
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information
|
||||
*/
|
||||
export async function complexityReportDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { reportPath } = args;
|
||||
try {
|
||||
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if reportPath was provided
|
||||
if (!reportPath) {
|
||||
log.error('complexityReportDirect called without reportPath');
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: 'reportPath is required' },
|
||||
fromCache: false
|
||||
};
|
||||
// Get tasks file path to determine project root for the default report location
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.warn(`Tasks file not found, using current directory: ${error.message}`);
|
||||
// Continue with default or specified report path
|
||||
}
|
||||
|
||||
// Use the provided report path
|
||||
// Get report file path from args or use default
|
||||
const reportPath = args.file || path.join(process.cwd(), 'scripts', 'task-complexity-report.json');
|
||||
|
||||
log.info(`Looking for complexity report at: ${reportPath}`);
|
||||
|
||||
// Generate cache key based on report path
|
||||
@@ -92,18 +87,14 @@ export async function complexityReportDirect(args, log) {
|
||||
actionFn: coreActionFn,
|
||||
log
|
||||
});
|
||||
log.info(
|
||||
`complexityReportDirect completed. From cache: ${result.fromCache}`
|
||||
);
|
||||
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}`
|
||||
);
|
||||
log.error(`Unexpected error during getCachedOrExecute for complexityReport: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
*/
|
||||
|
||||
import { expandAllTasks } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode,
|
||||
isSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
@@ -15,55 +12,36 @@ import fs from 'fs';
|
||||
/**
|
||||
* Expand all pending tasks with subtasks
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {number|string} [args.num] - Number of subtasks to generate
|
||||
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation
|
||||
* @param {string} [args.prompt] - Additional context to guide subtask generation
|
||||
* @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @param {Object} context - Context object containing session
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function expandAllTasksDirect(args, log, context = {}) {
|
||||
const { session } = context; // Only extract session, not reportProgress
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, num, research, prompt, force } = args;
|
||||
|
||||
try {
|
||||
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('expandAllTasksDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Enable silent mode early to prevent any console output
|
||||
enableSilentMode();
|
||||
|
||||
try {
|
||||
// Remove internal path finding
|
||||
/*
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
*/
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
|
||||
// Parse parameters
|
||||
const numSubtasks = num ? parseInt(num, 10) : undefined;
|
||||
const useResearch = research === true;
|
||||
const additionalContext = prompt || '';
|
||||
const forceFlag = force === true;
|
||||
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
|
||||
const useResearch = args.research === true;
|
||||
const additionalContext = args.prompt || '';
|
||||
const forceFlag = args.force === true;
|
||||
|
||||
log.info(
|
||||
`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`
|
||||
);
|
||||
log.info(`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`);
|
||||
|
||||
if (useResearch) {
|
||||
log.info('Using Perplexity AI for research-backed subtask generation');
|
||||
@@ -109,7 +87,7 @@ export async function expandAllTasksDirect(args, log, context = {}) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
message: 'Successfully expanded all pending tasks with subtasks',
|
||||
message: "Successfully expanded all pending tasks with subtasks",
|
||||
details: {
|
||||
numSubtasks: numSubtasks,
|
||||
research: useResearch,
|
||||
|
||||
@@ -4,17 +4,9 @@
|
||||
*/
|
||||
|
||||
import { expandTask } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
readJSON,
|
||||
writeJSON,
|
||||
enableSilentMode,
|
||||
disableSilentMode,
|
||||
isSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getModelConfig
|
||||
} from '../utils/ai-client-utils.js';
|
||||
import { readJSON, writeJSON, enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
@@ -22,51 +14,57 @@ import fs from 'fs';
|
||||
* Direct function wrapper for expanding a task into subtasks with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} args.id - The ID of the task to expand.
|
||||
* @param {number|string} [args.num] - Number of subtasks to generate.
|
||||
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation.
|
||||
* @param {string} [args.prompt] - Additional context to guide subtask generation.
|
||||
* @param {boolean} [args.force] - Force expansion even if subtasks exist.
|
||||
* @param {Object} log - Logger object
|
||||
* @param {Object} context - Context object containing session and reportProgress
|
||||
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||
*/
|
||||
export async function expandTaskDirect(args, log, context = {}) {
|
||||
const { session } = context;
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id, num, research, prompt, force } = args;
|
||||
|
||||
// Log session root data for debugging
|
||||
log.info(
|
||||
`Session data in expandTaskDirect: ${JSON.stringify({
|
||||
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';
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('expandTaskDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
code: 'FILE_NOT_FOUND_ERROR',
|
||||
message: `Error determining tasksPath: ${error.message}${sessionRootsInfo}`
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
|
||||
log.info(`[expandTaskDirect] Using tasksPath: ${tasksPath}`);
|
||||
log.info(`[expandTaskDirect] Determined tasksPath: ${tasksPath}`);
|
||||
|
||||
// Validate task ID
|
||||
const taskId = id ? parseInt(id, 10) : null;
|
||||
const taskId = args.id ? parseInt(args.id, 10) : null;
|
||||
if (!taskId) {
|
||||
log.error('Task ID is required');
|
||||
return {
|
||||
@@ -80,10 +78,9 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
}
|
||||
|
||||
// Process other parameters
|
||||
const numSubtasks = num ? parseInt(num, 10) : undefined;
|
||||
const useResearch = research === true;
|
||||
const additionalContext = prompt || '';
|
||||
const forceFlag = force === true;
|
||||
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
|
||||
const useResearch = args.research === true;
|
||||
const additionalContext = args.prompt || '';
|
||||
|
||||
// Initialize AI client if needed (for expandTask function)
|
||||
try {
|
||||
@@ -105,21 +102,15 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
}
|
||||
|
||||
try {
|
||||
log.info(
|
||||
`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}`
|
||||
);
|
||||
log.info(`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}`);
|
||||
|
||||
// Read tasks data
|
||||
log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);
|
||||
const data = readJSON(tasksPath);
|
||||
log.info(
|
||||
`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}`
|
||||
);
|
||||
log.info(`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}`);
|
||||
|
||||
if (!data || !data.tasks) {
|
||||
log.error(
|
||||
`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`
|
||||
);
|
||||
log.error(`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -132,7 +123,7 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
|
||||
// Find the specific task
|
||||
log.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);
|
||||
const task = data.tasks.find((t) => t.id === taskId);
|
||||
const task = data.tasks.find(t => t.id === taskId);
|
||||
log.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);
|
||||
|
||||
if (!task) {
|
||||
@@ -158,16 +149,15 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
// Check for existing subtasks and force flag
|
||||
// Check for existing subtasks
|
||||
const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0;
|
||||
if (hasExistingSubtasks && !forceFlag) {
|
||||
log.info(
|
||||
`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.`
|
||||
);
|
||||
|
||||
// If the task already has subtasks, just return it (matching core behavior)
|
||||
if (hasExistingSubtasks) {
|
||||
log.info(`Task ${taskId} already has ${task.subtasks.length} subtasks`);
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Task ${taskId} already has subtasks. Expansion skipped.`,
|
||||
task,
|
||||
subtasksAdded: 0,
|
||||
hasExistingSubtasks
|
||||
@@ -176,14 +166,6 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
// If force flag is set, clear existing subtasks
|
||||
if (hasExistingSubtasks && forceFlag) {
|
||||
log.info(
|
||||
`Force flag set. Clearing existing subtasks for task ${taskId}.`
|
||||
);
|
||||
task.subtasks = [];
|
||||
}
|
||||
|
||||
// Keep a copy of the task before modification
|
||||
const originalTask = JSON.parse(JSON.stringify(task));
|
||||
|
||||
@@ -222,17 +204,14 @@ export async function expandTaskDirect(args, log, context = {}) {
|
||||
|
||||
// Read the updated data
|
||||
const updatedData = readJSON(tasksPath);
|
||||
const updatedTask = updatedData.tasks.find((t) => t.id === taskId);
|
||||
const updatedTask = updatedData.tasks.find(t => t.id === taskId);
|
||||
|
||||
// Calculate how many subtasks were added
|
||||
const subtasksAdded = updatedTask.subtasks
|
||||
? updatedTask.subtasks.length - subtasksCountBefore
|
||||
: 0;
|
||||
const subtasksAdded = updatedTask.subtasks ?
|
||||
updatedTask.subtasks.length - subtasksCountBefore : 0;
|
||||
|
||||
// Return the result
|
||||
log.info(
|
||||
`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`
|
||||
);
|
||||
log.info(`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`);
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
|
||||
@@ -3,39 +3,24 @@
|
||||
*/
|
||||
|
||||
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import fs from 'fs';
|
||||
|
||||
/**
|
||||
* Fix invalid dependencies in tasks.json automatically
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function fixDependenciesDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath } = args;
|
||||
try {
|
||||
log.info(`Fixing invalid dependencies in tasks: ${tasksJsonPath}`);
|
||||
log.info(`Fixing invalid dependencies in tasks...`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('fixDependenciesDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Verify the file exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
@@ -51,7 +36,7 @@ export async function fixDependenciesDirect(args, log) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Call the original command function using the provided path
|
||||
// Call the original command function
|
||||
await fixDependenciesCommand(tasksPath);
|
||||
|
||||
// Restore normal logging
|
||||
|
||||
@@ -4,50 +4,41 @@
|
||||
*/
|
||||
|
||||
import { generateTaskFiles } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for generateTaskFiles with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing tasksJsonPath and outputDir.
|
||||
* @param {Object} args - Command arguments containing file and output path options.
|
||||
* @param {Object} log - Logger object.
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||
*/
|
||||
export async function generateTaskFilesDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, outputDir } = args;
|
||||
try {
|
||||
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if paths were provided
|
||||
if (!tasksJsonPath) {
|
||||
const errorMessage = 'tasksJsonPath is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
// Get tasks file path
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks file: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
error: { code: 'TASKS_FILE_ERROR', message: error.message },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Get output directory (defaults to the same directory as the tasks file)
|
||||
let outputDir = args.output;
|
||||
if (!outputDir) {
|
||||
const errorMessage = 'outputDir is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
outputDir = path.dirname(tasksPath);
|
||||
}
|
||||
|
||||
// Use the provided paths
|
||||
const tasksPath = tasksJsonPath;
|
||||
const resolvedOutputDir = outputDir;
|
||||
|
||||
log.info(`Generating task files from ${tasksPath} to ${resolvedOutputDir}`);
|
||||
log.info(`Generating task files from ${tasksPath} to ${outputDir}`);
|
||||
|
||||
// Execute core generateTaskFiles function in a separate try/catch
|
||||
try {
|
||||
@@ -55,7 +46,7 @@ export async function generateTaskFilesDirect(args, log) {
|
||||
enableSilentMode();
|
||||
|
||||
// The function is synchronous despite being awaited elsewhere
|
||||
generateTaskFiles(tasksPath, resolvedOutputDir);
|
||||
generateTaskFiles(tasksPath, outputDir);
|
||||
|
||||
// Restore normal logging after task generation
|
||||
disableSilentMode();
|
||||
@@ -76,10 +67,9 @@ export async function generateTaskFilesDirect(args, log) {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Successfully generated task files`,
|
||||
tasksPath: tasksPath,
|
||||
outputDir: resolvedOutputDir,
|
||||
taskFiles:
|
||||
'Individual task files have been generated in the output directory'
|
||||
tasksPath,
|
||||
outputDir,
|
||||
taskFiles: 'Individual task files have been generated in the output directory'
|
||||
},
|
||||
fromCache: false // This operation always modifies state and should never be cached
|
||||
};
|
||||
@@ -90,10 +80,7 @@ export async function generateTaskFilesDirect(args, log) {
|
||||
log.error(`Error generating task files: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'GENERATE_TASKS_ERROR',
|
||||
message: error.message || 'Unknown error generating task files'
|
||||
},
|
||||
error: { code: 'GENERATE_TASKS_ERROR', message: error.message || 'Unknown error generating task files' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -5,38 +5,36 @@
|
||||
|
||||
import { listTasks } from '../../../../scripts/modules/task-manager.js';
|
||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for listTasks with error handling and caching.
|
||||
*
|
||||
* @param {Object} args - Command arguments (now expecting tasksJsonPath explicitly).
|
||||
* @param {Object} args - Command arguments (projectRoot is expected to be resolved).
|
||||
* @param {Object} log - Logger object.
|
||||
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
|
||||
*/
|
||||
export async function listTasksDirect(args, log) {
|
||||
// Destructure the explicit tasksJsonPath from args
|
||||
const { tasksJsonPath, status, withSubtasks } = args;
|
||||
|
||||
if (!tasksJsonPath) {
|
||||
log.error('listTasksDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
let tasksPath;
|
||||
try {
|
||||
// Find the tasks path first - needed for cache key and execution
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
if (error.code === 'TASKS_FILE_NOT_FOUND') {
|
||||
log.error(`Tasks file not found: ${error.message}`);
|
||||
// Return the error structure expected by the calling tool/handler
|
||||
return { success: false, error: { code: error.code, message: error.message }, fromCache: false };
|
||||
}
|
||||
log.error(`Unexpected error finding tasks file: ${error.message}`);
|
||||
// Re-throw for outer catch or return structured error
|
||||
return { success: false, error: { code: 'FIND_TASKS_PATH_ERROR', message: error.message }, fromCache: false };
|
||||
}
|
||||
|
||||
// Use the explicit tasksJsonPath for cache key
|
||||
const statusFilter = status || 'all';
|
||||
const withSubtasksFilter = withSubtasks || false;
|
||||
const cacheKey = `listTasks:${tasksJsonPath}:${statusFilter}:${withSubtasksFilter}`;
|
||||
// Generate cache key *after* finding tasksPath
|
||||
const statusFilter = args.status || 'all';
|
||||
const withSubtasks = args.withSubtasks || false;
|
||||
const cacheKey = `listTasks:${tasksPath}:${statusFilter}:${withSubtasks}`;
|
||||
|
||||
// Define the action function to be executed on cache miss
|
||||
const coreListTasksAction = async () => {
|
||||
@@ -44,47 +42,26 @@ export async function listTasksDirect(args, log) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
log.info(
|
||||
`Executing core listTasks function for path: ${tasksJsonPath}, filter: ${statusFilter}, subtasks: ${withSubtasksFilter}`
|
||||
);
|
||||
// Pass the explicit tasksJsonPath to the core function
|
||||
const resultData = listTasks(
|
||||
tasksJsonPath,
|
||||
statusFilter,
|
||||
withSubtasksFilter,
|
||||
'json'
|
||||
);
|
||||
log.info(`Executing core listTasks function for path: ${tasksPath}, filter: ${statusFilter}, subtasks: ${withSubtasks}`);
|
||||
const resultData = listTasks(tasksPath, statusFilter, withSubtasks, 'json');
|
||||
|
||||
if (!resultData || !resultData.tasks) {
|
||||
log.error('Invalid or empty response from listTasks core function');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INVALID_CORE_RESPONSE',
|
||||
message: 'Invalid or empty response from listTasks core function'
|
||||
return { 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`
|
||||
);
|
||||
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'
|
||||
}
|
||||
};
|
||||
return { success: false, error: { code: 'LIST_TASKS_CORE_ERROR', message: error.message || 'Failed to list tasks' } };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,16 +74,10 @@ export async function listTasksDirect(args, log) {
|
||||
});
|
||||
log.info(`listTasksDirect completed. From cache: ${result.fromCache}`);
|
||||
return result; // Returns { success, data/error, fromCache }
|
||||
} catch (error) {
|
||||
} catch(error) {
|
||||
// Catch unexpected errors from getCachedOrExecute itself (though unlikely)
|
||||
log.error(
|
||||
`Unexpected error during getCachedOrExecute for listTasks: ${error.message}`
|
||||
);
|
||||
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
|
||||
};
|
||||
return { success: false, error: { code: 'CACHE_UTIL_ERROR', message: error.message }, fromCache: false };
|
||||
}
|
||||
}
|
||||
@@ -6,37 +6,35 @@
|
||||
import { findNextTask } from '../../../../scripts/modules/task-manager.js';
|
||||
import { readJSON } from '../../../../scripts/modules/utils.js';
|
||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for finding the next task to work on with error handling and caching.
|
||||
*
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||
*/
|
||||
export async function nextTaskDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath } = args;
|
||||
|
||||
if (!tasksJsonPath) {
|
||||
log.error('nextTaskDirect called without tasksJsonPath');
|
||||
let tasksPath;
|
||||
try {
|
||||
// Find the tasks path first - needed for cache key and execution
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Tasks file not found: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
code: 'FILE_NOT_FOUND_ERROR',
|
||||
message: error.message
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Generate cache key using the provided task path
|
||||
const cacheKey = `nextTask:${tasksJsonPath}`;
|
||||
// Generate cache key using task path
|
||||
const cacheKey = `nextTask:${tasksPath}`;
|
||||
|
||||
// Define the action function to be executed on cache miss
|
||||
const coreNextTaskAction = async () => {
|
||||
@@ -44,17 +42,16 @@ export async function nextTaskDirect(args, log) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
log.info(`Finding next task from ${tasksJsonPath}`);
|
||||
log.info(`Finding next task from ${tasksPath}`);
|
||||
|
||||
// Read tasks data using the provided path
|
||||
const data = readJSON(tasksJsonPath);
|
||||
// Read tasks data
|
||||
const data = readJSON(tasksPath);
|
||||
if (!data || !data.tasks) {
|
||||
disableSilentMode(); // Disable before return
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INVALID_TASKS_FILE',
|
||||
message: `No valid tasks found in ${tasksJsonPath}`
|
||||
message: `No valid tasks found in ${tasksPath}`
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -63,14 +60,11 @@ export async function nextTaskDirect(args, log) {
|
||||
const nextTask = findNextTask(data.tasks);
|
||||
|
||||
if (!nextTask) {
|
||||
log.info(
|
||||
'No eligible next task found. All tasks are either completed or have unsatisfied dependencies'
|
||||
);
|
||||
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',
|
||||
message: 'No eligible next task found. All tasks are either completed or have unsatisfied dependencies',
|
||||
nextTask: null,
|
||||
allTasks: data.tasks
|
||||
}
|
||||
@@ -81,9 +75,7 @@ export async function nextTaskDirect(args, log) {
|
||||
disableSilentMode();
|
||||
|
||||
// Return the next task data with the full tasks array for reference
|
||||
log.info(
|
||||
`Successfully found next task ${nextTask.id}: ${nextTask.title}`
|
||||
);
|
||||
log.info(`Successfully found next task ${nextTask.id}: ${nextTask.title}`);
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
@@ -117,9 +109,7 @@ export async function nextTaskDirect(args, log) {
|
||||
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}`
|
||||
);
|
||||
log.error(`Unexpected error during getCachedOrExecute for nextTask: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
|
||||
@@ -6,14 +6,9 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { parsePRD } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getModelConfig
|
||||
} from '../utils/ai-client-utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for parsing PRD documents and generating tasks.
|
||||
@@ -45,42 +40,29 @@ export async function parsePRDDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
// Validate required parameters
|
||||
if (!args.projectRoot) {
|
||||
const errorMessage = 'Project root is required for parsePRDDirect';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_PROJECT_ROOT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Parameter validation and path resolution
|
||||
if (!args.input) {
|
||||
const errorMessage = 'Input file path is required for parsePRDDirect';
|
||||
const errorMessage = 'No input file specified. Please provide an input PRD document path.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_INPUT_PATH', message: errorMessage },
|
||||
error: { code: 'MISSING_INPUT_FILE', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
if (!args.output) {
|
||||
const errorMessage = 'Output file path is required for parsePRDDirect';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_OUTPUT_PATH', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
// Resolve input path (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);
|
||||
|
||||
// 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);
|
||||
// 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)) {
|
||||
@@ -88,47 +70,22 @@ export async function parsePRDDirect(args, log, context = {}) {
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INPUT_FILE_NOT_FOUND',
|
||||
message: errorMessage,
|
||||
details: `Checked path: ${inputPath}\nProject root: ${projectRoot}\nInput argument: ${args.input}`
|
||||
},
|
||||
error: { code: 'INPUT_FILE_NOT_FOUND', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Resolve output path (expecting absolute path or path relative to project root)
|
||||
const outputPath = path.isAbsolute(args.output)
|
||||
? args.output
|
||||
: path.resolve(projectRoot, args.output);
|
||||
|
||||
// Ensure output directory exists
|
||||
const outputDir = path.dirname(outputPath);
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
log.info(`Creating output directory: ${outputDir}`);
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Parse number of tasks - handle both string and number values
|
||||
let numTasks = 10; // Default
|
||||
if (args.numTasks) {
|
||||
numTasks =
|
||||
typeof args.numTasks === 'string'
|
||||
? parseInt(args.numTasks, 10)
|
||||
: 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}`
|
||||
);
|
||||
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 = {
|
||||
@@ -145,43 +102,24 @@ export async function parsePRDDirect(args, log, context = {}) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
try {
|
||||
// Make sure the output directory exists
|
||||
const outputDir = path.dirname(outputPath);
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
log.info(`Creating output directory: ${outputDir}`);
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Execute core parsePRD function with AI client
|
||||
await parsePRD(
|
||||
inputPath,
|
||||
outputPath,
|
||||
numTasks,
|
||||
{
|
||||
await parsePRD(inputPath, outputPath, numTasks, {
|
||||
mcpLog: logWrapper,
|
||||
session,
|
||||
append
|
||||
},
|
||||
aiClient,
|
||||
modelConfig
|
||||
);
|
||||
session
|
||||
}, 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);
|
||||
log.info(`Successfully parsed PRD and generated ${tasksData.tasks?.length || 0} tasks`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
message,
|
||||
message: `Successfully generated ${tasksData.tasks?.length || 0} tasks from PRD`,
|
||||
taskCount: tasksData.tasks?.length || 0,
|
||||
outputPath,
|
||||
appended: append
|
||||
outputPath
|
||||
},
|
||||
fromCache: false // This operation always modifies state and should never be cached
|
||||
};
|
||||
@@ -205,10 +143,7 @@ export async function parsePRDDirect(args, log, context = {}) {
|
||||
log.error(`Error parsing PRD: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'PARSE_PRD_ERROR',
|
||||
message: error.message || 'Unknown error parsing PRD'
|
||||
},
|
||||
error: { code: 'PARSE_PRD_ERROR', message: error.message || 'Unknown error parsing PRD' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,40 +3,25 @@
|
||||
*/
|
||||
|
||||
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Remove a dependency from a task
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string|number} args.id - Task ID to remove dependency from
|
||||
* @param {string|number} args.dependsOn - Task ID to remove as a dependency
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function removeDependencyDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id, dependsOn } = args;
|
||||
try {
|
||||
log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('removeDependencyDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Validate required parameters
|
||||
if (!id) {
|
||||
if (!args.id) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -46,7 +31,7 @@ export async function removeDependencyDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!dependsOn) {
|
||||
if (!args.dependsOn) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -56,25 +41,19 @@ export async function removeDependencyDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Format IDs for the core function
|
||||
const taskId =
|
||||
id && id.includes && id.includes('.') ? id : parseInt(id, 10);
|
||||
const dependencyId =
|
||||
dependsOn && dependsOn.includes && dependsOn.includes('.')
|
||||
? dependsOn
|
||||
: parseInt(dependsOn, 10);
|
||||
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
|
||||
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
|
||||
|
||||
log.info(
|
||||
`Removing dependency: task ${taskId} no longer depends on ${dependencyId}`
|
||||
);
|
||||
log.info(`Removing dependency: task ${taskId} no longer depends on ${dependencyId}`);
|
||||
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Call the core function using the provided tasksPath
|
||||
// Call the core function
|
||||
await removeDependency(tasksPath, taskId, dependencyId);
|
||||
|
||||
// Restore normal logging
|
||||
|
||||
@@ -3,87 +3,60 @@
|
||||
*/
|
||||
|
||||
import { removeSubtask } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Remove a subtask from its parent task
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} args.id - Subtask ID in format "parentId.subtaskId" (required)
|
||||
* @param {boolean} [args.convert] - Whether to convert the subtask to a standalone task
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {boolean} [args.skipGenerate] - Skip regenerating task files
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function removeSubtaskDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id, convert, skipGenerate } = args;
|
||||
try {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('removeSubtaskDirect called without tasksJsonPath');
|
||||
disableSilentMode(); // Disable before returning
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
disableSilentMode(); // Disable before returning
|
||||
if (!args.id) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INPUT_VALIDATION_ERROR',
|
||||
message:
|
||||
'Subtask ID is required and must be in format "parentId.subtaskId"'
|
||||
message: 'Subtask ID is required and must be in format "parentId.subtaskId"'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Validate subtask ID format
|
||||
if (!id.includes('.')) {
|
||||
disableSilentMode(); // Disable before returning
|
||||
if (!args.id.includes('.')) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INPUT_VALIDATION_ERROR',
|
||||
message: `Invalid subtask ID format: ${id}. Expected format: "parentId.subtaskId"`
|
||||
message: `Invalid subtask ID format: ${args.id}. Expected format: "parentId.subtaskId"`
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Use provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Convert convertToTask to a boolean
|
||||
const convertToTask = convert === true;
|
||||
const convertToTask = args.convert === true;
|
||||
|
||||
// Determine if we should generate files
|
||||
const generateFiles = !skipGenerate;
|
||||
const generateFiles = !args.skipGenerate;
|
||||
|
||||
log.info(
|
||||
`Removing subtask ${id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})`
|
||||
);
|
||||
log.info(`Removing subtask ${args.id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})`);
|
||||
|
||||
// Use the provided tasksPath
|
||||
const result = await removeSubtask(
|
||||
tasksPath,
|
||||
id,
|
||||
convertToTask,
|
||||
generateFiles
|
||||
);
|
||||
const result = await removeSubtask(tasksPath, args.id, convertToTask, generateFiles);
|
||||
|
||||
// Restore normal logging
|
||||
disableSilentMode();
|
||||
@@ -93,7 +66,7 @@ export async function removeSubtaskDirect(args, log) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Subtask ${id} successfully converted to task #${result.id}`,
|
||||
message: `Subtask ${args.id} successfully converted to task #${result.id}`,
|
||||
task: result
|
||||
}
|
||||
};
|
||||
@@ -102,7 +75,7 @@ export async function removeSubtaskDirect(args, log) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Subtask ${id} successfully removed`
|
||||
message: `Subtask ${args.id} successfully removed`
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,45 +3,38 @@
|
||||
* Direct function implementation for removing a task
|
||||
*/
|
||||
|
||||
import {
|
||||
removeTask,
|
||||
taskExists
|
||||
} from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode,
|
||||
readJSON
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { removeTask } from '../../../../scripts/modules/task-manager.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for removeTask with error handling.
|
||||
* Supports removing multiple tasks at once with comma-separated IDs.
|
||||
*
|
||||
* @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
|
||||
* @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false }
|
||||
*/
|
||||
export async function removeTaskDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id } = args;
|
||||
try {
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
log.error('removeTaskDirect called without tasksJsonPath');
|
||||
// Find the tasks path first
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Tasks file not found: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
code: 'FILE_NOT_FOUND_ERROR',
|
||||
message: error.message
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Validate task ID parameter
|
||||
if (!id) {
|
||||
const taskId = args.id;
|
||||
if (!taskId) {
|
||||
log.error('Task ID is required');
|
||||
return {
|
||||
success: false,
|
||||
@@ -53,103 +46,46 @@ export async function removeTaskDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Split task IDs if comma-separated
|
||||
const taskIdArray = id.split(',').map((taskId) => taskId.trim());
|
||||
|
||||
log.info(
|
||||
`Removing ${taskIdArray.length} task(s) with ID(s): ${taskIdArray.join(', ')} from ${tasksJsonPath}`
|
||||
);
|
||||
|
||||
// Validate all task IDs exist before proceeding
|
||||
const data = readJSON(tasksJsonPath);
|
||||
if (!data || !data.tasks) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INVALID_TASKS_FILE',
|
||||
message: `No valid tasks found in ${tasksJsonPath}`
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
const invalidTasks = taskIdArray.filter(
|
||||
(taskId) => !taskExists(data.tasks, taskId)
|
||||
);
|
||||
|
||||
if (invalidTasks.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INVALID_TASK_ID',
|
||||
message: `The following tasks were not found: ${invalidTasks.join(', ')}`
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Remove tasks one by one
|
||||
const results = [];
|
||||
// Skip confirmation in the direct function since it's handled by the client
|
||||
log.info(`Removing task with ID: ${taskId} from ${tasksPath}`);
|
||||
|
||||
try {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
try {
|
||||
for (const taskId of taskIdArray) {
|
||||
try {
|
||||
const result = await removeTask(tasksJsonPath, taskId);
|
||||
results.push({
|
||||
taskId,
|
||||
success: true,
|
||||
message: result.message,
|
||||
removedTask: result.removedTask
|
||||
});
|
||||
log.info(`Successfully removed task: ${taskId}`);
|
||||
} catch (error) {
|
||||
results.push({
|
||||
taskId,
|
||||
success: false,
|
||||
error: error.message
|
||||
});
|
||||
log.error(`Error removing task ${taskId}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Call the core removeTask function
|
||||
const result = await removeTask(tasksPath, taskId);
|
||||
|
||||
// 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);
|
||||
log.info(`Successfully removed task: ${taskId}`);
|
||||
|
||||
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 the result
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
totalTasks: taskIdArray.length,
|
||||
successful: successfulRemovals.length,
|
||||
failed: failedRemovals.length,
|
||||
results: results,
|
||||
tasksPath: tasksJsonPath
|
||||
message: result.message,
|
||||
taskId: taskId,
|
||||
tasksPath: tasksPath,
|
||||
removedTask: result.removedTask
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
} catch (error) {
|
||||
// Make sure to restore normal logging even if there's an error
|
||||
disableSilentMode();
|
||||
|
||||
log.error(`Error removing task: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: error.code || 'REMOVE_TASK_ERROR',
|
||||
message: error.message || 'Failed to remove task'
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
// Ensure silent mode is disabled even if an outer error occurs
|
||||
disableSilentMode();
|
||||
|
||||
@@ -4,40 +4,23 @@
|
||||
*/
|
||||
|
||||
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode,
|
||||
isSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for setTaskStatus with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing id, status and tasksJsonPath.
|
||||
* @param {Object} args - Command arguments containing id, status and file path options.
|
||||
* @param {Object} log - Logger object.
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||
*/
|
||||
export async function setTaskStatusDirect(args, log) {
|
||||
// Destructure expected args, including the resolved tasksJsonPath
|
||||
const { tasksJsonPath, id, status } = args;
|
||||
try {
|
||||
log.info(`Setting task status with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
const errorMessage = 'tasksJsonPath is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Check required parameters (id and status)
|
||||
if (!id) {
|
||||
const errorMessage =
|
||||
'No task ID specified. Please provide a task ID to update.';
|
||||
// Check required parameters
|
||||
if (!args.id) {
|
||||
const errorMessage = 'No task ID specified. Please provide a task ID to update.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -46,9 +29,8 @@ export async function setTaskStatusDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
const errorMessage =
|
||||
'No status specified. Please provide a new status value.';
|
||||
if (!args.status) {
|
||||
const errorMessage = 'No status specified. Please provide a new status value.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -57,16 +39,32 @@ export async function setTaskStatusDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Use the provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Get tasks file path
|
||||
let tasksPath;
|
||||
try {
|
||||
// The enhanced findTasksJsonPath will now search in parent directories if needed
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
log.info(`Found tasks file at: ${tasksPath}`);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks file: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'TASKS_FILE_ERROR',
|
||||
message: `${error.message}\n\nPlease ensure you are in a Task Master project directory or use the --project-root parameter to specify the path to your project.`
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Execute core setTaskStatus function
|
||||
const taskId = id;
|
||||
const newStatus = status;
|
||||
const taskId = args.id;
|
||||
const newStatus = args.status;
|
||||
|
||||
log.info(`Setting task ${taskId} status to "${newStatus}"`);
|
||||
|
||||
// Call the core function with proper silent mode handling
|
||||
let result;
|
||||
enableSilentMode(); // Enable silent mode before calling core function
|
||||
try {
|
||||
// Call the core function
|
||||
@@ -75,31 +73,29 @@ export async function setTaskStatusDirect(args, log) {
|
||||
log.info(`Successfully set task ${taskId} status to ${newStatus}`);
|
||||
|
||||
// Return success data
|
||||
const result = {
|
||||
result = {
|
||||
success: true,
|
||||
data: {
|
||||
message: `Successfully updated task ${taskId} status to "${newStatus}"`,
|
||||
taskId,
|
||||
status: newStatus,
|
||||
tasksPath: tasksPath // Return the path used
|
||||
tasksPath
|
||||
},
|
||||
fromCache: false // This operation always modifies state and should never be cached
|
||||
};
|
||||
return result;
|
||||
} catch (error) {
|
||||
log.error(`Error setting task status: ${error.message}`);
|
||||
return {
|
||||
result = {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'SET_STATUS_ERROR',
|
||||
message: error.message || 'Unknown error setting task status'
|
||||
},
|
||||
error: { code: 'SET_STATUS_ERROR', message: error.message || 'Unknown error setting task status' },
|
||||
fromCache: false
|
||||
};
|
||||
} finally {
|
||||
// ALWAYS restore normal logging in finally block
|
||||
disableSilentMode();
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
// Ensure silent mode is disabled if there was an uncaught error in the outer try block
|
||||
if (isSilentMode()) {
|
||||
@@ -109,10 +105,7 @@ export async function setTaskStatusDirect(args, log) {
|
||||
log.error(`Error setting task status: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'SET_STATUS_ERROR',
|
||||
message: error.message || 'Unknown error setting task status'
|
||||
},
|
||||
error: { code: 'SET_STATUS_ERROR', message: error.message || 'Unknown error setting task status' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,38 +6,35 @@
|
||||
import { findTaskById } from '../../../../scripts/modules/utils.js';
|
||||
import { readJSON } from '../../../../scripts/modules/utils.js';
|
||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for showing task details with error handling and caching.
|
||||
*
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} args.id - The ID of the task or subtask to show.
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||
*/
|
||||
export async function showTaskDirect(args, log) {
|
||||
// Destructure expected args
|
||||
const { tasksJsonPath, id } = args;
|
||||
|
||||
if (!tasksJsonPath) {
|
||||
log.error('showTaskDirect called without tasksJsonPath');
|
||||
let tasksPath;
|
||||
try {
|
||||
// Find the tasks path first - needed for cache key and execution
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Tasks file not found: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
code: 'FILE_NOT_FOUND_ERROR',
|
||||
message: error.message
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Validate task ID
|
||||
const taskId = id;
|
||||
const taskId = args.id;
|
||||
if (!taskId) {
|
||||
log.error('Task ID is required');
|
||||
return {
|
||||
@@ -50,8 +47,8 @@ export async function showTaskDirect(args, log) {
|
||||
};
|
||||
}
|
||||
|
||||
// Generate cache key using the provided task path and ID
|
||||
const cacheKey = `showTask:${tasksJsonPath}:${taskId}`;
|
||||
// Generate cache key using task path and ID
|
||||
const cacheKey = `showTask:${tasksPath}:${taskId}`;
|
||||
|
||||
// Define the action function to be executed on cache miss
|
||||
const coreShowTaskAction = async () => {
|
||||
@@ -59,19 +56,16 @@ export async function showTaskDirect(args, log) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
log.info(
|
||||
`Retrieving task details for ID: ${taskId} from ${tasksJsonPath}`
|
||||
);
|
||||
log.info(`Retrieving task details for ID: ${taskId} from ${tasksPath}`);
|
||||
|
||||
// Read tasks data using the provided path
|
||||
const data = readJSON(tasksJsonPath);
|
||||
// Read tasks data
|
||||
const data = readJSON(tasksPath);
|
||||
if (!data || !data.tasks) {
|
||||
disableSilentMode(); // Disable before returning
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'INVALID_TASKS_FILE',
|
||||
message: `No valid tasks found in ${tasksJsonPath}`
|
||||
message: `No valid tasks found in ${tasksPath}`
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -80,7 +74,6 @@ export async function showTaskDirect(args, log) {
|
||||
const task = findTaskById(data.tasks, taskId);
|
||||
|
||||
if (!task) {
|
||||
disableSilentMode(); // Disable before returning
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
@@ -130,9 +123,7 @@ export async function showTaskDirect(args, log) {
|
||||
} catch (error) {
|
||||
// Catch unexpected errors from getCachedOrExecute itself
|
||||
disableSilentMode();
|
||||
log.error(
|
||||
`Unexpected error during getCachedOrExecute for showTask: ${error.message}`
|
||||
);
|
||||
log.error(`Unexpected error during getCachedOrExecute for showTask: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
|
||||
@@ -4,45 +4,27 @@
|
||||
*/
|
||||
|
||||
import { updateSubtaskById } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getPerplexityClientForMCP
|
||||
} from '../utils/ai-client-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { getAnthropicClientForMCP, getPerplexityClientForMCP } from '../utils/ai-client-utils.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for updateSubtaskById with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath.
|
||||
* @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
|
||||
* @param {Object} log - Logger object.
|
||||
* @param {Object} context - Context object containing session data.
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||
*/
|
||||
export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
const { session } = context; // Only extract session, not reportProgress
|
||||
const { tasksJsonPath, id, prompt, research } = args;
|
||||
|
||||
try {
|
||||
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
const errorMessage = 'tasksJsonPath is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Check required parameters (id and prompt)
|
||||
if (!id) {
|
||||
const errorMessage =
|
||||
'No subtask ID specified. Please provide a subtask ID to update.';
|
||||
// Check required parameters
|
||||
if (!args.id) {
|
||||
const errorMessage = 'No subtask ID specified. Please provide a subtask ID to update.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -51,9 +33,8 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!prompt) {
|
||||
const errorMessage =
|
||||
'No prompt specified. Please provide a prompt with information to add to the subtask.';
|
||||
if (!args.prompt) {
|
||||
const errorMessage = 'No prompt specified. Please provide a prompt with information to add to the subtask.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -63,7 +44,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
}
|
||||
|
||||
// Validate subtask ID format
|
||||
const subtaskId = id;
|
||||
const subtaskId = args.id;
|
||||
if (typeof subtaskId !== 'string' && typeof subtaskId !== 'number') {
|
||||
const errorMessage = `Invalid subtask ID type: ${typeof subtaskId}. Subtask ID must be a string or number.`;
|
||||
log.error(errorMessage);
|
||||
@@ -85,15 +66,23 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
// Use the provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Get tasks file path
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks file: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'TASKS_FILE_ERROR', message: error.message },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Get research flag
|
||||
const useResearch = research === true;
|
||||
const useResearch = args.research === true;
|
||||
|
||||
log.info(
|
||||
`Updating subtask with ID ${subtaskIdStr} with prompt "${prompt}" and research: ${useResearch}`
|
||||
);
|
||||
log.info(`Updating subtask with ID ${subtaskIdStr} with prompt "${args.prompt}" and research: ${useResearch}`);
|
||||
|
||||
// Initialize the appropriate AI client based on research flag
|
||||
try {
|
||||
@@ -108,10 +97,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
log.error(`AI client initialization error: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'AI_CLIENT_ERROR',
|
||||
message: error.message || 'Failed to initialize AI client'
|
||||
},
|
||||
error: { code: 'AI_CLIENT_ERROR', message: error.message || 'Failed to initialize AI client' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
@@ -132,16 +118,10 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
|
||||
// Execute core updateSubtaskById function
|
||||
// Pass both session and logWrapper as mcpLog to ensure outputFormat is 'json'
|
||||
const updatedSubtask = await updateSubtaskById(
|
||||
tasksPath,
|
||||
subtaskIdStr,
|
||||
prompt,
|
||||
useResearch,
|
||||
{
|
||||
const updatedSubtask = await updateSubtaskById(tasksPath, subtaskIdStr, args.prompt, useResearch, {
|
||||
session,
|
||||
mcpLog: logWrapper
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Restore normal logging
|
||||
disableSilentMode();
|
||||
@@ -152,8 +132,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'SUBTASK_UPDATE_FAILED',
|
||||
message:
|
||||
'Failed to update subtask. It may be marked as completed, or another error occurred.'
|
||||
message: 'Failed to update subtask. It may be marked as completed, or another error occurred.'
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
@@ -184,10 +163,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
||||
log.error(`Error updating subtask by ID: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'UPDATE_SUBTASK_ERROR',
|
||||
message: error.message || 'Unknown error updating subtask'
|
||||
},
|
||||
error: { code: 'UPDATE_SUBTASK_ERROR', message: error.message || 'Unknown error updating subtask' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
*/
|
||||
|
||||
import { updateTaskById } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getPerplexityClientForMCP
|
||||
@@ -16,34 +14,20 @@ import {
|
||||
/**
|
||||
* Direct function wrapper for updateTaskById with error handling.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing id, prompt, useResearch and tasksJsonPath.
|
||||
* @param {Object} args - Command arguments containing id, prompt, useResearch and file path options.
|
||||
* @param {Object} log - Logger object.
|
||||
* @param {Object} context - Context object containing session data.
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||
*/
|
||||
export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
const { session } = context; // Only extract session, not reportProgress
|
||||
// Destructure expected args, including the resolved tasksJsonPath
|
||||
const { tasksJsonPath, id, prompt, research } = args;
|
||||
|
||||
try {
|
||||
log.info(`Updating task with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
const errorMessage = 'tasksJsonPath is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Check required parameters (id and prompt)
|
||||
if (!id) {
|
||||
const errorMessage =
|
||||
'No task ID specified. Please provide a task ID to update.';
|
||||
// Check required parameters
|
||||
if (!args.id) {
|
||||
const errorMessage = 'No task ID specified. Please provide a task ID to update.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -52,9 +36,8 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!prompt) {
|
||||
const errorMessage =
|
||||
'No prompt specified. Please provide a prompt with new information for the task update.';
|
||||
if (!args.prompt) {
|
||||
const errorMessage = 'No prompt specified. Please provide a prompt with new information for the task update.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -65,15 +48,15 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
|
||||
// Parse taskId - handle both string and number values
|
||||
let taskId;
|
||||
if (typeof id === 'string') {
|
||||
if (typeof args.id === 'string') {
|
||||
// Handle subtask IDs (e.g., "5.2")
|
||||
if (id.includes('.')) {
|
||||
taskId = id; // Keep as string for subtask IDs
|
||||
if (args.id.includes('.')) {
|
||||
taskId = args.id; // Keep as string for subtask IDs
|
||||
} else {
|
||||
// Parse as integer for main task IDs
|
||||
taskId = parseInt(id, 10);
|
||||
taskId = parseInt(args.id, 10);
|
||||
if (isNaN(taskId)) {
|
||||
const errorMessage = `Invalid task ID: ${id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`;
|
||||
const errorMessage = `Invalid task ID: ${args.id}. Task ID must be a positive integer or subtask ID (e.g., "5.2").`;
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -83,14 +66,24 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
taskId = id;
|
||||
taskId = args.id;
|
||||
}
|
||||
|
||||
// Use the provided path
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Get tasks file path
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks file: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'TASKS_FILE_ERROR', message: error.message },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Get research flag
|
||||
const useResearch = research === true;
|
||||
const useResearch = args.research === true;
|
||||
|
||||
// Initialize appropriate AI client based on research flag
|
||||
let aiClient;
|
||||
@@ -114,9 +107,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
log.info(
|
||||
`Updating task with ID ${taskId} with prompt "${prompt}" and research: ${useResearch}`
|
||||
);
|
||||
log.info(`Updating task with ID ${taskId} with prompt "${args.prompt}" and research: ${useResearch}`);
|
||||
|
||||
try {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
@@ -135,7 +126,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
await updateTaskById(
|
||||
tasksPath,
|
||||
taskId,
|
||||
prompt,
|
||||
args.prompt,
|
||||
useResearch,
|
||||
{
|
||||
mcpLog: logWrapper, // Use our wrapper object that has the expected method structure
|
||||
@@ -151,7 +142,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
data: {
|
||||
message: `Successfully updated task with ID ${taskId} based on the prompt`,
|
||||
taskId,
|
||||
tasksPath: tasksPath, // Return the used path
|
||||
tasksPath,
|
||||
useResearch
|
||||
},
|
||||
fromCache: false // This operation always modifies state and should never be cached
|
||||
@@ -160,10 +151,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
log.error(`Error updating task by ID: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'UPDATE_TASK_ERROR',
|
||||
message: error.message || 'Unknown error updating task'
|
||||
},
|
||||
error: { code: 'UPDATE_TASK_ERROR', message: error.message || 'Unknown error updating task' },
|
||||
fromCache: false
|
||||
};
|
||||
} finally {
|
||||
@@ -177,10 +165,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
||||
log.error(`Error updating task by ID: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'UPDATE_TASK_ERROR',
|
||||
message: error.message || 'Unknown error updating task'
|
||||
},
|
||||
error: { code: 'UPDATE_TASK_ERROR', message: error.message || 'Unknown error updating task' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
*/
|
||||
|
||||
import { updateTasks } from '../../../../scripts/modules/task-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import {
|
||||
getAnthropicClientForMCP,
|
||||
getPerplexityClientForMCP
|
||||
@@ -16,50 +14,35 @@ import {
|
||||
/**
|
||||
* Direct function wrapper for updating tasks based on new context/prompt.
|
||||
*
|
||||
* @param {Object} args - Command arguments containing fromId, prompt, useResearch and tasksJsonPath.
|
||||
* @param {Object} args - Command arguments containing fromId, prompt, useResearch and file path options.
|
||||
* @param {Object} log - Logger object.
|
||||
* @param {Object} context - Context object containing session data.
|
||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||
*/
|
||||
export async function updateTasksDirect(args, log, context = {}) {
|
||||
const { session } = context; // Only extract session, not reportProgress
|
||||
const { tasksJsonPath, from, prompt, research } = args;
|
||||
|
||||
try {
|
||||
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Check if tasksJsonPath was provided
|
||||
if (!tasksJsonPath) {
|
||||
const errorMessage = 'tasksJsonPath is required but was not provided.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'MISSING_ARGUMENT', message: errorMessage },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Check for the common mistake of using 'id' instead of 'from'
|
||||
if (args.id !== undefined && from === undefined) {
|
||||
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.";
|
||||
if (args.id !== undefined && args.from === undefined) {
|
||||
const errorMessage = "You specified 'id' parameter but 'update' requires 'from' parameter. Use 'from' for this tool or use 'update_task' tool if you want to update a single task.";
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'PARAMETER_MISMATCH',
|
||||
message: errorMessage,
|
||||
suggestion:
|
||||
"Use 'from' parameter instead of 'id', or use the 'update_task' tool for single task updates"
|
||||
suggestion: "Use 'from' parameter instead of 'id', or use the 'update_task' tool for single task updates"
|
||||
},
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Check required parameters
|
||||
if (!from) {
|
||||
const errorMessage =
|
||||
'No from ID specified. Please provide a task ID to start updating from.';
|
||||
if (!args.from) {
|
||||
const errorMessage = 'No from ID specified. Please provide a task ID to start updating from.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -68,9 +51,8 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!prompt) {
|
||||
const errorMessage =
|
||||
'No prompt specified. Please provide a prompt with new context for task updates.';
|
||||
if (!args.prompt) {
|
||||
const errorMessage = 'No prompt specified. Please provide a prompt with new context for task updates.';
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -81,10 +63,10 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
|
||||
// Parse fromId - handle both string and number values
|
||||
let fromId;
|
||||
if (typeof from === 'string') {
|
||||
fromId = parseInt(from, 10);
|
||||
if (typeof args.from === 'string') {
|
||||
fromId = parseInt(args.from, 10);
|
||||
if (isNaN(fromId)) {
|
||||
const errorMessage = `Invalid from ID: ${from}. Task ID must be a positive integer.`;
|
||||
const errorMessage = `Invalid from ID: ${args.from}. Task ID must be a positive integer.`;
|
||||
log.error(errorMessage);
|
||||
return {
|
||||
success: false,
|
||||
@@ -93,11 +75,24 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
} else {
|
||||
fromId = from;
|
||||
fromId = args.from;
|
||||
}
|
||||
|
||||
// Get tasks file path
|
||||
let tasksPath;
|
||||
try {
|
||||
tasksPath = findTasksJsonPath(args, log);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks file: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: { code: 'TASKS_FILE_ERROR', message: error.message },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
// Get research flag
|
||||
const useResearch = research === true;
|
||||
const useResearch = args.research === true;
|
||||
|
||||
// Initialize appropriate AI client based on research flag
|
||||
let aiClient;
|
||||
@@ -121,28 +116,23 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
log.info(
|
||||
`Updating tasks from ID ${fromId} with prompt "${prompt}" and research: ${useResearch}`
|
||||
);
|
||||
|
||||
// Create the logger wrapper to ensure compatibility with core functions
|
||||
const logWrapper = {
|
||||
info: (message, ...args) => log.info(message, ...args),
|
||||
warn: (message, ...args) => log.warn(message, ...args),
|
||||
error: (message, ...args) => log.error(message, ...args),
|
||||
debug: (message, ...args) => log.debug && log.debug(message, ...args), // Handle optional debug
|
||||
success: (message, ...args) => log.info(message, ...args) // Map success to info if needed
|
||||
};
|
||||
log.info(`Updating tasks from ID ${fromId} with prompt "${args.prompt}" and research: ${useResearch}`);
|
||||
|
||||
try {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Execute core updateTasks function, passing the AI client and session
|
||||
await updateTasks(tasksJsonPath, fromId, prompt, useResearch, {
|
||||
mcpLog: logWrapper, // Pass the wrapper instead of the raw log object
|
||||
await updateTasks(
|
||||
tasksPath,
|
||||
fromId,
|
||||
args.prompt,
|
||||
useResearch,
|
||||
{
|
||||
mcpLog: log,
|
||||
session
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Since updateTasks doesn't return a value but modifies the tasks file,
|
||||
// we'll return a success message
|
||||
@@ -151,7 +141,7 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
data: {
|
||||
message: `Successfully updated tasks from ID ${fromId} based on the prompt`,
|
||||
fromId,
|
||||
tasksPath: tasksJsonPath,
|
||||
tasksPath,
|
||||
useResearch
|
||||
},
|
||||
fromCache: false // This operation always modifies state and should never be cached
|
||||
@@ -160,10 +150,7 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
log.error(`Error updating tasks: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'UPDATE_TASKS_ERROR',
|
||||
message: error.message || 'Unknown error updating tasks'
|
||||
},
|
||||
error: { code: 'UPDATE_TASKS_ERROR', message: error.message || 'Unknown error updating tasks' },
|
||||
fromCache: false
|
||||
};
|
||||
} finally {
|
||||
@@ -177,10 +164,7 @@ export async function updateTasksDirect(args, log, context = {}) {
|
||||
log.error(`Error updating tasks: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'UPDATE_TASKS_ERROR',
|
||||
message: error.message || 'Unknown error updating tasks'
|
||||
},
|
||||
error: { code: 'UPDATE_TASKS_ERROR', message: error.message || 'Unknown error updating tasks' },
|
||||
fromCache: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,39 +3,24 @@
|
||||
*/
|
||||
|
||||
import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
||||
import {
|
||||
enableSilentMode,
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
||||
import fs from 'fs';
|
||||
|
||||
/**
|
||||
* Validate dependencies in tasks.json
|
||||
* @param {Object} args - Function arguments
|
||||
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
||||
* @param {string} [args.file] - Path to the tasks file
|
||||
* @param {string} [args.projectRoot] - Project root directory
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||
*/
|
||||
export async function validateDependenciesDirect(args, log) {
|
||||
// Destructure the explicit tasksJsonPath
|
||||
const { tasksJsonPath } = args;
|
||||
|
||||
if (!tasksJsonPath) {
|
||||
log.error('validateDependenciesDirect called without tasksJsonPath');
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'tasksJsonPath is required'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
log.info(`Validating dependencies in tasks: ${tasksJsonPath}`);
|
||||
log.info(`Validating dependencies in tasks...`);
|
||||
|
||||
// Use the provided tasksJsonPath
|
||||
const tasksPath = tasksJsonPath;
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Verify the file exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
@@ -51,7 +36,7 @@ export async function validateDependenciesDirect(args, log) {
|
||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||
enableSilentMode();
|
||||
|
||||
// Call the original command function using the provided tasksPath
|
||||
// Call the original command function
|
||||
await validateDependenciesCommand(tasksPath);
|
||||
|
||||
// Restore normal logging
|
||||
|
||||
@@ -28,7 +28,6 @@ import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
|
||||
import { complexityReportDirect } from './direct-functions/complexity-report.js';
|
||||
import { addDependencyDirect } from './direct-functions/add-dependency.js';
|
||||
import { removeTaskDirect } from './direct-functions/remove-task.js';
|
||||
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
|
||||
|
||||
// Re-export utility functions
|
||||
export { findTasksJsonPath } from './utils/path-utils.js';
|
||||
@@ -93,6 +92,5 @@ export {
|
||||
fixDependenciesDirect,
|
||||
complexityReportDirect,
|
||||
addDependencyDirect,
|
||||
removeTaskDirect,
|
||||
initializeProjectDirect
|
||||
removeTaskDirect
|
||||
};
|
||||
@@ -26,13 +26,10 @@ const DEFAULT_MODEL_CONFIG = {
|
||||
export function getAnthropicClientForMCP(session, log = console) {
|
||||
try {
|
||||
// Extract API key from session.env or fall back to environment variables
|
||||
const apiKey =
|
||||
session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
||||
const apiKey = session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
||||
|
||||
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
|
||||
@@ -58,13 +55,10 @@ export function getAnthropicClientForMCP(session, log = console) {
|
||||
export async function getPerplexityClientForMCP(session, log = console) {
|
||||
try {
|
||||
// Extract API key from session.env or fall back to environment variables
|
||||
const apiKey =
|
||||
session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
|
||||
const apiKey = session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
|
||||
|
||||
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)
|
||||
@@ -106,19 +100,13 @@ export function getModelConfig(session, defaults = DEFAULT_MODEL_CONFIG) {
|
||||
* @returns {Promise<Object>} Selected model info with type and client
|
||||
* @throws {Error} If no AI models are available
|
||||
*/
|
||||
export async function getBestAvailableAIModel(
|
||||
session,
|
||||
options = {},
|
||||
log = console
|
||||
) {
|
||||
export async function getBestAvailableAIModel(session, options = {}, log = console) {
|
||||
const { requiresResearch = false, claudeOverloaded = false } = options;
|
||||
|
||||
// Test case: When research is needed but no Perplexity, use Claude
|
||||
if (
|
||||
requiresResearch &&
|
||||
if (requiresResearch &&
|
||||
!(session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY) &&
|
||||
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)
|
||||
) {
|
||||
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
|
||||
try {
|
||||
log.warn('Perplexity not available for research, using Claude');
|
||||
const client = getAnthropicClientForMCP(session, log);
|
||||
@@ -130,10 +118,7 @@ export async function getBestAvailableAIModel(
|
||||
}
|
||||
|
||||
// Regular path: Perplexity for research when available
|
||||
if (
|
||||
requiresResearch &&
|
||||
(session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY)
|
||||
) {
|
||||
if (requiresResearch && (session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY)) {
|
||||
try {
|
||||
const client = await getPerplexityClientForMCP(session, log);
|
||||
return { type: 'perplexity', client };
|
||||
@@ -144,29 +129,19 @@ export async function getBestAvailableAIModel(
|
||||
}
|
||||
|
||||
// Test case: Claude for overloaded scenario
|
||||
if (
|
||||
claudeOverloaded &&
|
||||
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)
|
||||
) {
|
||||
if (claudeOverloaded && (session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
|
||||
try {
|
||||
log.warn(
|
||||
'Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.'
|
||||
);
|
||||
log.warn('Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.');
|
||||
const client = getAnthropicClientForMCP(session, log);
|
||||
return { type: 'claude', client };
|
||||
} catch (error) {
|
||||
log.error(
|
||||
`Claude not available despite being overloaded: ${error.message}`
|
||||
);
|
||||
log.error(`Claude not available despite being overloaded: ${error.message}`);
|
||||
throw new Error('No AI models available');
|
||||
}
|
||||
}
|
||||
|
||||
// Default case: Use Claude when available and not overloaded
|
||||
if (
|
||||
!claudeOverloaded &&
|
||||
(session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)
|
||||
) {
|
||||
if (!claudeOverloaded && (session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY)) {
|
||||
try {
|
||||
const client = getAnthropicClientForMCP(session, log);
|
||||
return { type: 'claude', client };
|
||||
|
||||
@@ -33,19 +33,11 @@ class AsyncOperationManager {
|
||||
this.log(operationId, 'info', `Operation added.`);
|
||||
|
||||
// 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
|
||||
this.log(
|
||||
operationId,
|
||||
'error',
|
||||
`Critical error starting operation: ${err.message}`,
|
||||
{ stack: err.stack }
|
||||
);
|
||||
this.log(operationId, 'error', `Critical error starting operation: ${err.message}`, { stack: err.stack });
|
||||
operation.status = 'failed';
|
||||
operation.error = {
|
||||
code: 'MANAGER_EXECUTION_ERROR',
|
||||
message: err.message
|
||||
};
|
||||
operation.error = { code: 'MANAGER_EXECUTION_ERROR', message: err.message };
|
||||
operation.endTime = Date.now();
|
||||
|
||||
// Move to completed operations
|
||||
@@ -75,8 +67,7 @@ class AsyncOperationManager {
|
||||
// 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),
|
||||
reportProgress: (progress) => this._handleProgress(operationId, progress),
|
||||
mcpLog: operation.log, // Pass log as mcpLog if direct fn expects it
|
||||
session: operation.session
|
||||
});
|
||||
@@ -84,31 +75,15 @@ class AsyncOperationManager {
|
||||
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}`
|
||||
);
|
||||
this.log(operationId, 'info', `Operation finished with status: ${operation.status}`);
|
||||
|
||||
} catch (error) {
|
||||
this.log(
|
||||
operationId,
|
||||
'error',
|
||||
`Operation failed with error: ${error.message}`,
|
||||
{ stack: error.stack }
|
||||
);
|
||||
this.log(operationId, 'error', `Operation failed with error: ${error.message}`, { stack: error.stack });
|
||||
operation.status = 'failed';
|
||||
operation.error = {
|
||||
code: 'OPERATION_EXECUTION_ERROR',
|
||||
message: error.message
|
||||
};
|
||||
operation.error = { code: 'OPERATION_EXECUTION_ERROR', message: error.message };
|
||||
} finally {
|
||||
operation.endTime = Date.now();
|
||||
this.emit('statusChanged', {
|
||||
operationId,
|
||||
status: operation.status,
|
||||
result: operation.result,
|
||||
error: operation.error
|
||||
});
|
||||
this.emit('statusChanged', { operationId, status: operation.status, result: operation.result, error: operation.error });
|
||||
|
||||
// Move to completed operations if done or failed
|
||||
if (operation.status === 'completed' || operation.status === 'failed') {
|
||||
@@ -133,7 +108,7 @@ class AsyncOperationManager {
|
||||
startTime: operation.startTime,
|
||||
endTime: operation.endTime,
|
||||
result: operation.result,
|
||||
error: operation.error
|
||||
error: operation.error,
|
||||
};
|
||||
|
||||
this.completedOperations.set(operationId, completedData);
|
||||
@@ -142,9 +117,8 @@ class AsyncOperationManager {
|
||||
// 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];
|
||||
const oldest = [...this.completedOperations.entries()]
|
||||
.sort((a, b) => a[1].endTime - b[1].endTime)[0];
|
||||
|
||||
if (oldest) {
|
||||
this.completedOperations.delete(oldest[0]);
|
||||
@@ -163,17 +137,9 @@ class AsyncOperationManager {
|
||||
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}`
|
||||
);
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -194,7 +160,7 @@ class AsyncOperationManager {
|
||||
startTime: operation.startTime,
|
||||
endTime: operation.endTime,
|
||||
result: operation.result,
|
||||
error: operation.error
|
||||
error: operation.error,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -239,7 +205,7 @@ class AsyncOperationManager {
|
||||
|
||||
emit(eventName, data) {
|
||||
if (this.listeners.has(eventName)) {
|
||||
this.listeners.get(eventName).forEach((listener) => listener(data));
|
||||
this.listeners.get(eventName).forEach(listener => listener(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,7 @@
|
||||
* @returns {Promise<any>} The result of the actionFn.
|
||||
*/
|
||||
export async function withSessionEnv(sessionEnv, actionFn) {
|
||||
if (
|
||||
!sessionEnv ||
|
||||
typeof sessionEnv !== 'object' ||
|
||||
Object.keys(sessionEnv).length === 0
|
||||
) {
|
||||
if (!sessionEnv || typeof sessionEnv !== 'object' || Object.keys(sessionEnv).length === 0) {
|
||||
// If no sessionEnv is provided, just run the action directly
|
||||
return await actionFn();
|
||||
}
|
||||
@@ -44,4 +40,4 @@ export async function withSessionEnv(sessionEnv, actionFn) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,10 +100,7 @@ export function findTasksJsonPath(args, log) {
|
||||
projectRoot,
|
||||
currentDir: process.cwd(),
|
||||
serverDir: path.dirname(process.argv[1]),
|
||||
possibleProjectRoot: path.resolve(
|
||||
path.dirname(process.argv[1]),
|
||||
'../..'
|
||||
),
|
||||
possibleProjectRoot: path.resolve(path.dirname(process.argv[1]), '../..'),
|
||||
lastFoundProjectRoot,
|
||||
searchedPaths: error.message
|
||||
};
|
||||
@@ -120,25 +117,17 @@ export function findTasksJsonPath(args, log) {
|
||||
log.info(`Trying last known project root: ${lastFoundProjectRoot}`);
|
||||
try {
|
||||
// Use the cached root
|
||||
const tasksPath = findTasksJsonInDirectory(
|
||||
lastFoundProjectRoot,
|
||||
args.file,
|
||||
log
|
||||
);
|
||||
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.`
|
||||
);
|
||||
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}`
|
||||
);
|
||||
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 {
|
||||
@@ -157,7 +146,7 @@ export function findTasksJsonPath(args, log) {
|
||||
* @returns {boolean} - True if the directory contains any project markers
|
||||
*/
|
||||
function hasProjectMarkers(dirPath) {
|
||||
return PROJECT_MARKERS.some((marker) => {
|
||||
return PROJECT_MARKERS.some(marker => {
|
||||
const markerPath = path.join(dirPath, marker);
|
||||
// Check if the marker exists as either a file or directory
|
||||
return fs.existsSync(markerPath);
|
||||
@@ -203,9 +192,7 @@ function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
|
||||
}
|
||||
|
||||
// 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(', ')}`
|
||||
);
|
||||
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;
|
||||
}
|
||||
@@ -243,17 +230,13 @@ function findTasksJsonWithParentSearch(startDir, explicitFilePath, log) {
|
||||
break;
|
||||
}
|
||||
|
||||
log.info(
|
||||
`Tasks file not found in ${currentDir}, searching in parent directory: ${parentDir}`
|
||||
);
|
||||
log.info(`Tasks file not found in ${currentDir}, searching in parent directory: ${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.`
|
||||
);
|
||||
const error = new Error(`Tasks file not found in ${startDir} or any parent directory.`);
|
||||
error.code = 'TASKS_FILE_NOT_FOUND';
|
||||
throw error;
|
||||
}
|
||||
@@ -279,11 +262,7 @@ function findTasksWithNpmConsideration(startDir, log) {
|
||||
|
||||
try {
|
||||
// Check standard locations in home dir
|
||||
return findTasksJsonInDirectory(
|
||||
path.join(homeDir, '.task-master'),
|
||||
null,
|
||||
log
|
||||
);
|
||||
return findTasksJsonInDirectory(path.join(homeDir, '.task-master'), null, log);
|
||||
} catch (thirdError) {
|
||||
// If all approaches fail, throw the original error
|
||||
throw error;
|
||||
@@ -291,103 +270,3 @@ function findTasksWithNpmConsideration(startDir, log) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds potential PRD document files based on common naming patterns
|
||||
* @param {string} projectRoot - The project root directory
|
||||
* @param {string|null} explicitPath - Optional explicit path provided by the user
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {string|null} - The path to the first found PRD file, or null if none found
|
||||
*/
|
||||
export function findPRDDocumentPath(projectRoot, explicitPath, log) {
|
||||
// If explicit path is provided, check if it exists
|
||||
if (explicitPath) {
|
||||
const fullPath = path.isAbsolute(explicitPath)
|
||||
? explicitPath
|
||||
: path.resolve(projectRoot, explicitPath);
|
||||
|
||||
if (fs.existsSync(fullPath)) {
|
||||
log.info(`Using provided PRD document path: ${fullPath}`);
|
||||
return fullPath;
|
||||
} else {
|
||||
log.warn(
|
||||
`Provided PRD document path not found: ${fullPath}, will search for alternatives`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Common locations and file patterns for PRD documents
|
||||
const commonLocations = [
|
||||
'', // Project root
|
||||
'scripts/'
|
||||
];
|
||||
|
||||
const commonFileNames = ['PRD.md', 'prd.md', 'PRD.txt', 'prd.txt'];
|
||||
|
||||
// Check all possible combinations
|
||||
for (const location of commonLocations) {
|
||||
for (const fileName of commonFileNames) {
|
||||
const potentialPath = path.join(projectRoot, location, fileName);
|
||||
if (fs.existsSync(potentialPath)) {
|
||||
log.info(`Found PRD document at: ${potentialPath}`);
|
||||
return potentialPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.warn(`No PRD document found in common locations within ${projectRoot}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the tasks output directory path
|
||||
* @param {string} projectRoot - The project root directory
|
||||
* @param {string|null} explicitPath - Optional explicit output path provided by the user
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {string} - The resolved tasks directory path
|
||||
*/
|
||||
export function resolveTasksOutputPath(projectRoot, explicitPath, log) {
|
||||
// If explicit path is provided, use it
|
||||
if (explicitPath) {
|
||||
const outputPath = path.isAbsolute(explicitPath)
|
||||
? explicitPath
|
||||
: path.resolve(projectRoot, explicitPath);
|
||||
|
||||
log.info(`Using provided tasks output path: ${outputPath}`);
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
// Default output path: tasks/tasks.json in the project root
|
||||
const defaultPath = path.resolve(projectRoot, 'tasks', 'tasks.json');
|
||||
log.info(`Using default tasks output path: ${defaultPath}`);
|
||||
|
||||
// Ensure the directory exists
|
||||
const outputDir = path.dirname(defaultPath);
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
log.info(`Creating tasks directory: ${outputDir}`);
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves various file paths needed for MCP operations based on project root
|
||||
* @param {string} projectRoot - The project root directory
|
||||
* @param {Object} args - Command arguments that may contain explicit paths
|
||||
* @param {Object} log - Logger object
|
||||
* @returns {Object} - An object containing resolved paths
|
||||
*/
|
||||
export function resolveProjectPaths(projectRoot, args, log) {
|
||||
const prdPath = findPRDDocumentPath(projectRoot, args.input, log);
|
||||
const tasksJsonPath = resolveTasksOutputPath(projectRoot, args.output, log);
|
||||
|
||||
// You can add more path resolutions here as needed
|
||||
|
||||
return {
|
||||
projectRoot,
|
||||
prdPath,
|
||||
tasksJsonPath
|
||||
// Add additional path properties as needed
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { FastMCP } from 'fastmcp';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import logger from './logger.js';
|
||||
import { registerTaskMasterTools } from './tools/index.js';
|
||||
import { FastMCP } from "fastmcp";
|
||||
import path from "path";
|
||||
import dotenv from "dotenv";
|
||||
import { fileURLToPath } from "url";
|
||||
import fs from "fs";
|
||||
import logger from "./logger.js";
|
||||
import { registerTaskMasterTools } from "./tools/index.js";
|
||||
import { asyncOperationManager } from './core/utils/async-manager.js';
|
||||
|
||||
// Load environment variables
|
||||
@@ -20,12 +20,12 @@ const __dirname = path.dirname(__filename);
|
||||
class TaskMasterMCPServer {
|
||||
constructor() {
|
||||
// Get version from package.json using synchronous fs
|
||||
const packagePath = path.join(__dirname, '../../package.json');
|
||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
||||
const packagePath = path.join(__dirname, "../../package.json");
|
||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
||||
|
||||
this.options = {
|
||||
name: 'Task Master MCP Server',
|
||||
version: packageJson.version
|
||||
name: "Task Master MCP Server",
|
||||
version: packageJson.version,
|
||||
};
|
||||
|
||||
this.server = new FastMCP(this.options);
|
||||
@@ -71,7 +71,7 @@ class TaskMasterMCPServer {
|
||||
|
||||
// Start the FastMCP server with increased timeout
|
||||
await this.server.start({
|
||||
transportType: 'stdio',
|
||||
transportType: "stdio",
|
||||
timeout: 120000 // 2 minutes timeout (in milliseconds)
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import chalk from 'chalk';
|
||||
import { isSilentMode } from '../../scripts/modules/utils.js';
|
||||
import chalk from "chalk";
|
||||
import { isSilentMode } from "../../scripts/modules/utils.js";
|
||||
|
||||
// Define log levels
|
||||
const LOG_LEVELS = {
|
||||
@@ -7,12 +7,12 @@ const LOG_LEVELS = {
|
||||
info: 1,
|
||||
warn: 2,
|
||||
error: 3,
|
||||
success: 4
|
||||
success: 4,
|
||||
};
|
||||
|
||||
// Get log level from environment or default to info
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -28,50 +28,40 @@ function log(level, ...args) {
|
||||
|
||||
// Use text prefixes instead of emojis
|
||||
const prefixes = {
|
||||
debug: chalk.gray('[DEBUG]'),
|
||||
info: chalk.blue('[INFO]'),
|
||||
warn: chalk.yellow('[WARN]'),
|
||||
error: chalk.red('[ERROR]'),
|
||||
success: chalk.green('[SUCCESS]')
|
||||
debug: chalk.gray("[DEBUG]"),
|
||||
info: chalk.blue("[INFO]"),
|
||||
warn: chalk.yellow("[WARN]"),
|
||||
error: chalk.red("[ERROR]"),
|
||||
success: chalk.green("[SUCCESS]"),
|
||||
};
|
||||
|
||||
if (LOG_LEVELS[level] !== undefined && LOG_LEVELS[level] >= LOG_LEVEL) {
|
||||
const prefix = prefixes[level] || '';
|
||||
const prefix = prefixes[level] || "";
|
||||
let coloredArgs = args;
|
||||
|
||||
try {
|
||||
switch (level) {
|
||||
case 'error':
|
||||
coloredArgs = args.map((arg) =>
|
||||
typeof arg === 'string' ? chalk.red(arg) : arg
|
||||
);
|
||||
switch(level) {
|
||||
case "error":
|
||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.red(arg) : arg);
|
||||
break;
|
||||
case 'warn':
|
||||
coloredArgs = args.map((arg) =>
|
||||
typeof arg === 'string' ? chalk.yellow(arg) : arg
|
||||
);
|
||||
case "warn":
|
||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.yellow(arg) : arg);
|
||||
break;
|
||||
case 'success':
|
||||
coloredArgs = args.map((arg) =>
|
||||
typeof arg === 'string' ? chalk.green(arg) : arg
|
||||
);
|
||||
case "success":
|
||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.green(arg) : arg);
|
||||
break;
|
||||
case 'info':
|
||||
coloredArgs = args.map((arg) =>
|
||||
typeof arg === 'string' ? chalk.blue(arg) : arg
|
||||
);
|
||||
case "info":
|
||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.blue(arg) : arg);
|
||||
break;
|
||||
case 'debug':
|
||||
coloredArgs = args.map((arg) =>
|
||||
typeof arg === 'string' ? chalk.gray(arg) : arg
|
||||
);
|
||||
case "debug":
|
||||
coloredArgs = args.map(arg => 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);
|
||||
console.error("Internal Logger Error applying chalk color:", colorError);
|
||||
coloredArgs = args;
|
||||
}
|
||||
|
||||
@@ -88,18 +78,15 @@ function log(level, ...args) {
|
||||
* @returns {Object} Logger object with info, error, debug, warn, and success methods
|
||||
*/
|
||||
export function createLogger() {
|
||||
const createLogMethod =
|
||||
(level) =>
|
||||
(...args) =>
|
||||
log(level, ...args);
|
||||
const createLogMethod = (level) => (...args) => log(level, ...args);
|
||||
|
||||
return {
|
||||
debug: createLogMethod('debug'),
|
||||
info: createLogMethod('info'),
|
||||
warn: createLogMethod('warn'),
|
||||
error: createLogMethod('error'),
|
||||
success: createLogMethod('success'),
|
||||
log: log // Also expose the raw log function
|
||||
debug: createLogMethod("debug"),
|
||||
info: createLogMethod("info"),
|
||||
warn: createLogMethod("warn"),
|
||||
error: createLogMethod("error"),
|
||||
success: createLogMethod("success"),
|
||||
log: log, // Also expose the raw log function
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
1
mcp-server/src/logger.js (lines 31-41)
Normal file
1
mcp-server/src/logger.js (lines 31-41)
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for adding a dependency to a task
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { addDependencyDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { addDependencyDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the addDependency tool with the MCP server
|
||||
@@ -18,66 +17,35 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerAddDependencyTool(server) {
|
||||
server.addTool({
|
||||
name: 'add_dependency',
|
||||
description: 'Add a dependency relationship between two tasks',
|
||||
name: "add_dependency",
|
||||
description: "Add a dependency relationship between two tasks",
|
||||
parameters: z.object({
|
||||
id: z.string().describe('ID of task that will depend on another task'),
|
||||
dependsOn: z
|
||||
.string()
|
||||
.describe('ID of task that will become a dependency'),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
id: z.string().describe("ID of task that will depend on another task"),
|
||||
dependsOn: z.string().describe("ID of task that will become a dependency"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(
|
||||
`Adding dependency for task ${args.id} to depend on ${args.dependsOn}`
|
||||
);
|
||||
log.info(`Adding dependency for task ${args.id} to depend on ${args.dependsOn}`);
|
||||
reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
// Get project root using the utility function
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
// Fallback to args.projectRoot if session didn't provide one
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
// Call the direct function with the resolved rootFolder
|
||||
const result = await addDependencyDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { reportProgress, mcpLog: log, session});
|
||||
|
||||
// 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
|
||||
);
|
||||
reportProgress({ progress: 100 });
|
||||
|
||||
// Log result
|
||||
if (result.success) {
|
||||
@@ -92,6 +60,6 @@ export function registerAddDependencyTool(server) {
|
||||
log.error(`Error in addDependency tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for adding subtasks to existing tasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { addSubtaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { addSubtaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the addSubtask tool with the MCP server
|
||||
@@ -18,89 +17,35 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerAddSubtaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'add_subtask',
|
||||
description: 'Add a subtask to an existing task',
|
||||
name: "add_subtask",
|
||||
description: "Add a subtask to an existing task",
|
||||
parameters: z.object({
|
||||
id: z.string().describe('Parent task ID (required)'),
|
||||
taskId: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Existing task ID to convert to subtask'),
|
||||
title: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Title for the new subtask (when creating a new subtask)'),
|
||||
description: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Description for the new subtask'),
|
||||
details: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Implementation details for the new subtask'),
|
||||
status: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Status for the new subtask (default: 'pending')"),
|
||||
dependencies: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Comma-separated list of dependency IDs for the new subtask'),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
skipGenerate: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Skip regenerating task files'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
id: z.string().describe("Parent task ID (required)"),
|
||||
taskId: z.string().optional().describe("Existing task ID to convert to subtask"),
|
||||
title: z.string().optional().describe("Title for the new subtask (when creating a new subtask)"),
|
||||
description: z.string().optional().describe("Description for the new subtask"),
|
||||
details: z.string().optional().describe("Implementation details for the new subtask"),
|
||||
status: z.string().optional().describe("Status for the new subtask (default: 'pending')"),
|
||||
dependencies: z.string().optional().describe("Comma-separated list of dependency IDs for the new subtask"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
const 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
|
||||
);
|
||||
const result = await addSubtaskDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { reportProgress, mcpLog: log, session});
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Subtask added successfully: ${result.data.message}`);
|
||||
@@ -113,6 +58,6 @@ export function registerAddSubtaskTool(server) {
|
||||
log.error(`Error in addSubtask tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
* Tool to add a new task using AI
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
createErrorResponse,
|
||||
createContentResponse,
|
||||
getProjectRootFromSession,
|
||||
executeTaskMasterCommand,
|
||||
handleApiResult
|
||||
} from './utils.js';
|
||||
import { addTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { addTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the addTask tool with the MCP server
|
||||
@@ -20,94 +19,33 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerAddTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'add_task',
|
||||
description: 'Add a new task using AI',
|
||||
name: "add_task",
|
||||
description: "Add a new task using AI",
|
||||
parameters: z.object({
|
||||
prompt: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Description of the task to add (required if not using manual fields)'
|
||||
),
|
||||
title: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Task title (for manual task creation)'),
|
||||
description: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Task description (for manual task creation)'),
|
||||
details: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Implementation details (for manual task creation)'),
|
||||
testStrategy: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Test strategy (for manual task creation)'),
|
||||
dependencies: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Comma-separated list of task IDs this task depends on'),
|
||||
priority: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Task priority (high, medium, low)'),
|
||||
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')
|
||||
prompt: z.string().describe("Description of the task to add"),
|
||||
dependencies: z.string().optional().describe("Comma-separated list of task IDs this task depends on"),
|
||||
priority: z.string().optional().describe("Task priority (high, medium, low)"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project"),
|
||||
research: z.boolean().optional().describe("Whether to use research capabilities for task creation")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, reportProgress, session }) => {
|
||||
try {
|
||||
log.info(`Starting add-task with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
// Get project root from session
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Call the direct function
|
||||
const result = await addTaskDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
// Pass other relevant args
|
||||
prompt: args.prompt,
|
||||
dependencies: args.dependencies,
|
||||
priority: args.priority,
|
||||
research: args.research
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
);
|
||||
const result = await addTaskDirect({
|
||||
...args,
|
||||
projectRoot: rootFolder
|
||||
}, log, { reportProgress, session });
|
||||
|
||||
// Return the result
|
||||
return handleApiResult(result, log);
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
* Tool for analyzing task complexity and generating recommendations
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { analyzeTaskComplexityDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
import path from 'path';
|
||||
} from "./utils.js";
|
||||
import { analyzeTaskComplexityDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the analyze tool with the MCP server
|
||||
@@ -19,98 +17,37 @@ import path from 'path';
|
||||
*/
|
||||
export function registerAnalyzeTool(server) {
|
||||
server.addTool({
|
||||
name: 'analyze_project_complexity',
|
||||
description:
|
||||
'Analyze task complexity and generate expansion recommendations',
|
||||
name: "analyze_project_complexity",
|
||||
description: "Analyze task complexity and generate expansion recommendations",
|
||||
parameters: z.object({
|
||||
output: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Output file path for the report (default: scripts/task-complexity-report.json)'
|
||||
),
|
||||
model: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'LLM model to use for analysis (defaults to configured model)'
|
||||
),
|
||||
threshold: z.coerce
|
||||
.number()
|
||||
.min(1)
|
||||
.max(10)
|
||||
.optional()
|
||||
.describe(
|
||||
'Minimum complexity score to recommend expansion (1-10) (default: 5)'
|
||||
),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Use Perplexity AI for research-backed complexity analysis'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
output: z.string().optional().describe("Output file path for the report (default: scripts/task-complexity-report.json)"),
|
||||
model: z.string().optional().describe("LLM model to use for analysis (defaults to configured model)"),
|
||||
threshold: z.union([z.number(), z.string()]).optional().describe("Minimum complexity score to recommend expansion (1-10) (default: 5)"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed complexity analysis"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(
|
||||
`Analyzing task complexity with args: ${JSON.stringify(args)}`
|
||||
);
|
||||
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
const outputPath = args.output
|
||||
? path.resolve(rootFolder, args.output)
|
||||
: path.resolve(rootFolder, 'scripts', 'task-complexity-report.json');
|
||||
|
||||
const result = await analyzeTaskComplexityDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
outputPath: outputPath,
|
||||
model: args.model,
|
||||
threshold: args.threshold,
|
||||
research: args.research
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
);
|
||||
const result = await analyzeTaskComplexityDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { session });
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Task complexity analysis complete: ${result.data.message}`);
|
||||
log.info(
|
||||
`Report summary: ${JSON.stringify(result.data.reportSummary)}`
|
||||
);
|
||||
log.info(`Report summary: ${JSON.stringify(result.data.reportSummary)}`);
|
||||
} else {
|
||||
log.error(
|
||||
`Failed to analyze task complexity: ${result.error.message}`
|
||||
);
|
||||
log.error(`Failed to analyze task complexity: ${result.error.message}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error analyzing task complexity');
|
||||
@@ -118,6 +55,6 @@ export function registerAnalyzeTool(server) {
|
||||
log.error(`Error in analyze tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for clearing subtasks from parent tasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { clearSubtasksDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { clearSubtasksDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the clearSubtasks tool with the MCP server
|
||||
@@ -18,69 +17,35 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerClearSubtasksTool(server) {
|
||||
server.addTool({
|
||||
name: 'clear_subtasks',
|
||||
description: 'Clear subtasks from specified tasks',
|
||||
parameters: z
|
||||
.object({
|
||||
id: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Task IDs (comma-separated) to clear subtasks from'),
|
||||
all: z.boolean().optional().describe('Clear subtasks from all tasks'),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
})
|
||||
.refine((data) => data.id || data.all, {
|
||||
name: "clear_subtasks",
|
||||
description: "Clear subtasks from specified tasks",
|
||||
parameters: z.object({
|
||||
id: z.string().optional().describe("Task IDs (comma-separated) to clear subtasks from"),
|
||||
all: z.boolean().optional().describe("Clear subtasks from all tasks"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}).refine(data => data.id || data.all, {
|
||||
message: "Either 'id' or 'all' parameter must be provided",
|
||||
path: ['id', 'all']
|
||||
path: ["id", "all"]
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
|
||||
await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await clearSubtasksDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { reportProgress, mcpLog: log, session});
|
||||
|
||||
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
|
||||
);
|
||||
reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Subtasks cleared successfully: ${result.data.message}`);
|
||||
@@ -93,6 +58,6 @@ export function registerClearSubtasksTool(server) {
|
||||
log.error(`Error in clearSubtasks tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for displaying the complexity analysis report
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { complexityReportDirect } from '../core/task-master-core.js';
|
||||
import path from 'path';
|
||||
} from "./utils.js";
|
||||
import { complexityReportDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the complexityReport tool with the MCP server
|
||||
@@ -18,72 +17,42 @@ import path from 'path';
|
||||
*/
|
||||
export function registerComplexityReportTool(server) {
|
||||
server.addTool({
|
||||
name: 'complexity_report',
|
||||
description: 'Display the complexity analysis report in a readable format',
|
||||
name: "complexity_report",
|
||||
description: "Display the complexity analysis report in a readable format",
|
||||
parameters: z.object({
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Path to the report file (default: scripts/task-complexity-report.json)'
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
file: z.string().optional().describe("Path to the report file (default: scripts/task-complexity-report.json)"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(
|
||||
`Getting complexity report with args: ${JSON.stringify(args)}`
|
||||
);
|
||||
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to the complexity report file
|
||||
// Default to scripts/task-complexity-report.json relative to root
|
||||
const reportPath = args.file
|
||||
? path.resolve(rootFolder, args.file)
|
||||
: path.resolve(rootFolder, 'scripts', 'task-complexity-report.json');
|
||||
const result = await complexityReportDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
const result = await complexityReportDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
reportPath: reportPath
|
||||
// No other args specific to this tool
|
||||
},
|
||||
log
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`
|
||||
);
|
||||
log.info(`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`);
|
||||
} else {
|
||||
log.error(
|
||||
`Failed to retrieve complexity report: ${result.error.message}`
|
||||
);
|
||||
log.error(`Failed to retrieve complexity report: ${result.error.message}`);
|
||||
}
|
||||
|
||||
return handleApiResult(
|
||||
result,
|
||||
log,
|
||||
'Error retrieving complexity report'
|
||||
);
|
||||
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}`
|
||||
);
|
||||
}
|
||||
return createErrorResponse(`Failed to retrieve complexity report: ${error.message}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for expanding all pending tasks with subtasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { expandAllTasksDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { expandAllTasksDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the expandAll tool with the MCP server
|
||||
@@ -18,88 +17,36 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerExpandAllTool(server) {
|
||||
server.addTool({
|
||||
name: 'expand_all',
|
||||
description: 'Expand all pending tasks into subtasks',
|
||||
name: "expand_all",
|
||||
description: "Expand all pending tasks into subtasks",
|
||||
parameters: z.object({
|
||||
num: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Number of subtasks to generate for each task'),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
'Enable Perplexity AI for research-backed subtask generation'
|
||||
),
|
||||
prompt: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Additional context to guide subtask generation'),
|
||||
force: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
'Force regeneration of subtasks for tasks that already have them'
|
||||
),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
num: z.string().optional().describe("Number of subtasks to generate for each task"),
|
||||
research: z.boolean().optional().describe("Enable Perplexity AI for research-backed subtask generation"),
|
||||
prompt: z.string().optional().describe("Additional context to guide subtask generation"),
|
||||
force: z.boolean().optional().describe("Force regeneration of subtasks for tasks that already have them"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
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 }
|
||||
);
|
||||
const result = await expandAllTasksDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, 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'}`
|
||||
);
|
||||
log.error(`Failed to expand all tasks: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error expanding all tasks');
|
||||
@@ -107,6 +54,6 @@ export function registerExpandAllTool(server) {
|
||||
log.error(`Error in expand-all tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
* Tool to expand a task into subtasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { expandTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
} from "./utils.js";
|
||||
import { expandTaskDirect } from "../core/task-master-core.js";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* Register the expand-task tool with the MCP server
|
||||
@@ -20,72 +19,52 @@ import path from 'path';
|
||||
*/
|
||||
export function registerExpandTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'expand_task',
|
||||
description: 'Expand a task into subtasks for detailed implementation',
|
||||
name: "expand_task",
|
||||
description: "Expand a task into subtasks for detailed implementation",
|
||||
parameters: z.object({
|
||||
id: z.string().describe('ID of task to expand'),
|
||||
num: z.string().optional().describe('Number of subtasks to generate'),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Use Perplexity AI for research-backed generation'),
|
||||
prompt: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Additional context for subtask generation'),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
id: z.string().describe("ID of task to expand"),
|
||||
num: z.union([z.string(), z.number()]).optional().describe("Number of subtasks to generate"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed generation"),
|
||||
prompt: z.string().optional().describe("Additional context for subtask generation"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.'),
|
||||
force: z.boolean().optional().describe('Force the expansion')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, reportProgress, session }) => {
|
||||
try {
|
||||
log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
// Get project root from session
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
log.info(`Project root resolved to: ${rootFolder}`);
|
||||
|
||||
// Resolve the path to tasks.json using the utility
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
// Check for tasks.json in the standard locations
|
||||
const tasksJsonPath = path.join(rootFolder, 'tasks', 'tasks.json');
|
||||
|
||||
if (fs.existsSync(tasksJsonPath)) {
|
||||
log.info(`Found tasks.json at ${tasksJsonPath}`);
|
||||
// Add the file parameter directly to args
|
||||
args.file = tasksJsonPath;
|
||||
} else {
|
||||
log.warn(`Could not find tasks.json at ${tasksJsonPath}`);
|
||||
}
|
||||
|
||||
// Call direct function with only session in the context, not reportProgress
|
||||
// Use the pattern recommended in the MCP guidelines
|
||||
const result = await expandTaskDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
// Pass other relevant args
|
||||
id: args.id,
|
||||
num: args.num,
|
||||
research: args.research,
|
||||
prompt: args.prompt,
|
||||
force: args.force // Need to add force to parameters
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
); // Only pass session, NOT reportProgress
|
||||
const result = await expandTaskDirect({
|
||||
...args,
|
||||
projectRoot: rootFolder
|
||||
}, log, { session }); // Only pass session, NOT reportProgress
|
||||
|
||||
// Return the result
|
||||
return handleApiResult(result, log, 'Error expanding task');
|
||||
@@ -93,6 +72,6 @@ export function registerExpandTaskTool(server) {
|
||||
log.error(`Error in expand task tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for automatically fixing invalid task dependencies
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { fixDependenciesDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { fixDependenciesDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the fixDependencies tool with the MCP server
|
||||
@@ -18,47 +17,30 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerFixDependenciesTool(server) {
|
||||
server.addTool({
|
||||
name: 'fix_dependencies',
|
||||
description: 'Fix invalid dependencies in tasks automatically',
|
||||
name: "fix_dependencies",
|
||||
description: "Fix invalid dependencies in tasks automatically",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Fixing dependencies with args: ${JSON.stringify(args)}`);
|
||||
await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await fixDependenciesDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { reportProgress, mcpLog: log, session});
|
||||
|
||||
const result = await fixDependenciesDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath
|
||||
},
|
||||
log
|
||||
);
|
||||
await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Successfully fixed dependencies: ${result.data.message}`);
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
* Tool to generate individual task files from tasks.json
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { generateTaskFilesDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
import path from 'path';
|
||||
} from "./utils.js";
|
||||
import { generateTaskFilesDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the generate tool with the MCP server
|
||||
@@ -19,69 +17,41 @@ import path from 'path';
|
||||
*/
|
||||
export function registerGenerateTool(server) {
|
||||
server.addTool({
|
||||
name: 'generate',
|
||||
description:
|
||||
'Generates individual task files in tasks/ directory based on tasks.json',
|
||||
name: "generate",
|
||||
description: "Generates individual task files in tasks/ directory based on tasks.json",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
output: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('Output directory (default: same directory as tasks file)'),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
output: z.string().optional().describe("Output directory (default: same directory as tasks file)"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await generateTaskFilesDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
// 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
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
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'}`
|
||||
);
|
||||
log.error(`Failed to generate task files: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error generating task files');
|
||||
@@ -89,6 +59,6 @@ export function registerGenerateTool(server) {
|
||||
log.error(`Error in generate tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -10,10 +10,9 @@ import { createErrorResponse, createContentResponse } from './utils.js'; // Assu
|
||||
export function registerGetOperationStatusTool(server, asyncManager) {
|
||||
server.addTool({
|
||||
name: 'get_operation_status',
|
||||
description:
|
||||
'Retrieves the status and result/error of a background operation.',
|
||||
description: 'Retrieves the status and result/error of a background operation.',
|
||||
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 }) => {
|
||||
try {
|
||||
@@ -33,15 +32,11 @@ export function registerGetOperationStatusTool(server, asyncManager) {
|
||||
|
||||
log.info(`Status for ${operationId}: ${status.status}`);
|
||||
return createContentResponse(status);
|
||||
|
||||
} catch (error) {
|
||||
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'
|
||||
);
|
||||
}
|
||||
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');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to get task details by ID
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { showTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { showTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Custom processor function that removes allTasks from the response
|
||||
@@ -36,88 +35,58 @@ function processTaskResponse(data) {
|
||||
*/
|
||||
export function registerShowTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'get_task',
|
||||
description: 'Get detailed information about a specific task',
|
||||
name: "get_task",
|
||||
description: "Get detailed information about a specific task",
|
||||
parameters: z.object({
|
||||
id: z.string().describe('Task ID to get'),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
id: z.string().describe("Task ID to get"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
// Log the session right at the start of execute
|
||||
log.info(
|
||||
`Session object received in execute: ${JSON.stringify(session)}`
|
||||
); // Use JSON.stringify for better visibility
|
||||
log.info(`Session object received in execute: ${JSON.stringify(session)}`); // Use JSON.stringify for better visibility
|
||||
|
||||
try {
|
||||
log.info(`Getting task details for ID: ${args.id}`);
|
||||
|
||||
log.info(
|
||||
`Session object received in execute: ${JSON.stringify(session)}`
|
||||
); // Use JSON.stringify for better visibility
|
||||
log.info(`Session object received in execute: ${JSON.stringify(session)}`); // Use JSON.stringify for better visibility
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
} else if (!rootFolder) {
|
||||
// Ensure we always have *some* root, even if session failed and args didn't provide one
|
||||
rootFolder = process.cwd();
|
||||
log.warn(`Session and args failed to provide root, using CWD: ${rootFolder}`);
|
||||
}
|
||||
|
||||
log.info(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root
|
||||
|
||||
log.info(`Root folder: ${rootFolder}`); // Log the final resolved root
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
log.info(`Attempting to use tasks file path: ${tasksJsonPath}`);
|
||||
|
||||
const result = await showTaskDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
// Pass other relevant args
|
||||
id: args.id
|
||||
},
|
||||
log
|
||||
);
|
||||
const result = await showTaskDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log);
|
||||
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully retrieved task details for ID: ${args.id}${result.fromCache ? ' (from cache)' : ''}`
|
||||
);
|
||||
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
|
||||
);
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to get all tasks from Task Master
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
createErrorResponse,
|
||||
handleApiResult,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { listTasksDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { listTasksDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the getTasks tool with the MCP server
|
||||
@@ -18,78 +17,48 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerListTasksTool(server) {
|
||||
server.addTool({
|
||||
name: 'get_tasks',
|
||||
description:
|
||||
'Get all tasks from Task Master, optionally filtering by status and including subtasks.',
|
||||
name: "get_tasks",
|
||||
description: "Get all tasks from Task Master, optionally filtering by status and including subtasks.",
|
||||
parameters: z.object({
|
||||
status: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Filter tasks by status (e.g., 'pending', 'done')"),
|
||||
status: z.string().optional().describe("Filter tasks by status (e.g., 'pending', 'done')"),
|
||||
withSubtasks: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
'Include subtasks nested within their parent tasks in the response'
|
||||
),
|
||||
file: z
|
||||
.describe("Include subtasks nested within their parent tasks in the response"),
|
||||
file: z.string().optional().describe("Path to the tasks file (relative to project root or absolute)"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Path to the tasks file (relative to project root or absolute)'
|
||||
"Root directory of the project (default: automatically detected from session or CWD)"
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Getting tasks with filters: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
// Use the error message from findTasksJsonPath for better context
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await listTasksDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
const result = await listTasksDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
status: args.status,
|
||||
withSubtasks: args.withSubtasks
|
||||
},
|
||||
log
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
log.info(
|
||||
`Retrieved ${result.success ? result.data?.tasks?.length || 0 : 0} tasks${result.fromCache ? ' (from cache)' : ''}`
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,28 +3,28 @@
|
||||
* Export all Task Master CLI tools for MCP server
|
||||
*/
|
||||
|
||||
import { registerListTasksTool } from './get-tasks.js';
|
||||
import logger from '../logger.js';
|
||||
import { registerSetTaskStatusTool } from './set-task-status.js';
|
||||
import { registerParsePRDTool } from './parse-prd.js';
|
||||
import { registerUpdateTool } from './update.js';
|
||||
import { registerUpdateTaskTool } from './update-task.js';
|
||||
import { registerUpdateSubtaskTool } from './update-subtask.js';
|
||||
import { registerGenerateTool } from './generate.js';
|
||||
import { registerShowTaskTool } from './get-task.js';
|
||||
import { registerNextTaskTool } from './next-task.js';
|
||||
import { registerExpandTaskTool } from './expand-task.js';
|
||||
import { registerAddTaskTool } from './add-task.js';
|
||||
import { registerAddSubtaskTool } from './add-subtask.js';
|
||||
import { registerRemoveSubtaskTool } from './remove-subtask.js';
|
||||
import { registerAnalyzeTool } from './analyze.js';
|
||||
import { registerClearSubtasksTool } from './clear-subtasks.js';
|
||||
import { registerExpandAllTool } from './expand-all.js';
|
||||
import { registerRemoveDependencyTool } from './remove-dependency.js';
|
||||
import { registerValidateDependenciesTool } from './validate-dependencies.js';
|
||||
import { registerFixDependenciesTool } from './fix-dependencies.js';
|
||||
import { registerComplexityReportTool } from './complexity-report.js';
|
||||
import { registerAddDependencyTool } from './add-dependency.js';
|
||||
import { registerListTasksTool } from "./get-tasks.js";
|
||||
import logger from "../logger.js";
|
||||
import { registerSetTaskStatusTool } from "./set-task-status.js";
|
||||
import { registerParsePRDTool } from "./parse-prd.js";
|
||||
import { registerUpdateTool } from "./update.js";
|
||||
import { registerUpdateTaskTool } from "./update-task.js";
|
||||
import { registerUpdateSubtaskTool } from "./update-subtask.js";
|
||||
import { registerGenerateTool } from "./generate.js";
|
||||
import { registerShowTaskTool } from "./get-task.js";
|
||||
import { registerNextTaskTool } from "./next-task.js";
|
||||
import { registerExpandTaskTool } from "./expand-task.js";
|
||||
import { registerAddTaskTool } from "./add-task.js";
|
||||
import { registerAddSubtaskTool } from "./add-subtask.js";
|
||||
import { registerRemoveSubtaskTool } from "./remove-subtask.js";
|
||||
import { registerAnalyzeTool } from "./analyze.js";
|
||||
import { registerClearSubtasksTool } from "./clear-subtasks.js";
|
||||
import { registerExpandAllTool } from "./expand-all.js";
|
||||
import { registerRemoveDependencyTool } from "./remove-dependency.js";
|
||||
import { registerValidateDependenciesTool } from "./validate-dependencies.js";
|
||||
import { registerFixDependenciesTool } from "./fix-dependencies.js";
|
||||
import { registerComplexityReportTool } from "./complexity-report.js";
|
||||
import { registerAddDependencyTool } from "./add-dependency.js";
|
||||
import { registerRemoveTaskTool } from './remove-task.js';
|
||||
import { registerInitializeProjectTool } from './initialize-project.js';
|
||||
import { asyncOperationManager } from '../core/utils/async-manager.js';
|
||||
@@ -64,8 +64,10 @@ export function registerTaskMasterTools(server, asyncManager) {
|
||||
logger.error(`Error registering Task Master tools: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
logger.info('Registered Task Master MCP tools');
|
||||
}
|
||||
|
||||
export default {
|
||||
registerTaskMasterTools
|
||||
registerTaskMasterTools,
|
||||
};
|
||||
@@ -1,67 +1,61 @@
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
createContentResponse,
|
||||
createErrorResponse,
|
||||
handleApiResult
|
||||
} from './utils.js';
|
||||
import { initializeProjectDirect } from '../core/task-master-core.js';
|
||||
import { z } from "zod";
|
||||
import { execSync } from 'child_process';
|
||||
import { createContentResponse, createErrorResponse } from "./utils.js"; // Only need response creators
|
||||
|
||||
export function registerInitializeProjectTool(server) {
|
||||
server.addTool({
|
||||
name: 'initialize_project',
|
||||
description:
|
||||
'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.',
|
||||
name: "initialize_project", // snake_case for tool name
|
||||
description: "Initializes a new Task Master project structure in the current working directory by running 'task-master init'.",
|
||||
parameters: z.object({
|
||||
skipInstall: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(false)
|
||||
.describe(
|
||||
'Skip installing dependencies automatically. Never do this unless you are sure the project is already installed.'
|
||||
),
|
||||
addAliases: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(false)
|
||||
.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.'
|
||||
)
|
||||
projectName: z.string().optional().describe("The name for the new project."),
|
||||
projectDescription: z.string().optional().describe("A brief description for the project."),
|
||||
projectVersion: z.string().optional().describe("The initial version for the project (e.g., '0.1.0')."),
|
||||
authorName: z.string().optional().describe("The author's name."),
|
||||
skipInstall: z.boolean().optional().default(false).describe("Skip installing dependencies automatically."),
|
||||
addAliases: z.boolean().optional().default(false).describe("Add shell aliases (tm, taskmaster) to shell config file."),
|
||||
yes: z.boolean().optional().default(false).describe("Skip prompts and use default values or provided arguments."),
|
||||
// projectRoot is not needed here as 'init' works on the current directory
|
||||
}),
|
||||
execute: async (args, context) => {
|
||||
const { log } = context;
|
||||
const session = context.session;
|
||||
|
||||
log.info(
|
||||
'>>> Full Context Received by Tool:',
|
||||
JSON.stringify(context, null, 2)
|
||||
);
|
||||
log.info(`Context received in tool function: ${context}`);
|
||||
log.info(
|
||||
`Session received in tool function: ${session ? session : 'undefined'}`
|
||||
);
|
||||
|
||||
execute: async (args, { log }) => { // Destructure context to get log
|
||||
try {
|
||||
log.info(
|
||||
`Executing initialize_project tool with args: ${JSON.stringify(args)}`
|
||||
log.info(`Executing initialize_project with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Construct the command arguments carefully
|
||||
// Using npx ensures it uses the locally installed version if available, or fetches it
|
||||
let command = 'npx task-master init';
|
||||
const cliArgs = [];
|
||||
if (args.projectName) cliArgs.push(`--name "${args.projectName.replace(/"/g, '\\"')}"`); // Escape quotes
|
||||
if (args.projectDescription) cliArgs.push(`--description "${args.projectDescription.replace(/"/g, '\\"')}"`);
|
||||
if (args.projectVersion) cliArgs.push(`--version "${args.projectVersion.replace(/"/g, '\\"')}"`);
|
||||
if (args.authorName) cliArgs.push(`--author "${args.authorName.replace(/"/g, '\\"')}"`);
|
||||
if (args.skipInstall) cliArgs.push('--skip-install');
|
||||
if (args.addAliases) cliArgs.push('--aliases');
|
||||
if (args.yes) cliArgs.push('--yes');
|
||||
|
||||
command += ' ' + cliArgs.join(' ');
|
||||
|
||||
log.info(`Constructed command: ${command}`);
|
||||
|
||||
// Execute the command in the current working directory of the server process
|
||||
// Capture stdout/stderr. Use a reasonable timeout (e.g., 5 minutes)
|
||||
const output = execSync(command, { encoding: 'utf8', stdio: 'pipe', timeout: 300000 });
|
||||
|
||||
log.info(`Initialization output:\n${output}`);
|
||||
|
||||
// Return a standard success response manually
|
||||
return createContentResponse(
|
||||
"Project initialized successfully.",
|
||||
{ output: output } // Include output in the data payload
|
||||
);
|
||||
|
||||
const result = await initializeProjectDirect(args, log, { session });
|
||||
|
||||
return handleApiResult(result, log, 'Initialization failed');
|
||||
} catch (error) {
|
||||
const errorMessage = `Project initialization tool failed: ${error.message || 'Unknown error'}`;
|
||||
log.error(errorMessage, error);
|
||||
return createErrorResponse(errorMessage, { details: error.stack });
|
||||
// Catch errors from execSync or timeouts
|
||||
const errorMessage = `Project initialization failed: ${error.message}`;
|
||||
const errorDetails = error.stderr?.toString() || error.stdout?.toString() || error.message; // Provide stderr/stdout if available
|
||||
log.error(`${errorMessage}\nDetails: ${errorDetails}`);
|
||||
|
||||
// Return a standard error response manually
|
||||
return createErrorResponse(errorMessage, { details: errorDetails });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to find the next task to work on
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { nextTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { nextTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the next-task tool with the MCP server
|
||||
@@ -18,61 +17,40 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerNextTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'next_task',
|
||||
description:
|
||||
'Find the next task to work on based on dependencies and status',
|
||||
name: "next_task",
|
||||
description: "Find the next task to work on based on dependencies and status",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Finding next task with args: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await nextTaskDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
const result = await nextTaskDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath
|
||||
// No other args specific to this tool
|
||||
},
|
||||
log
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully found next task: ${result.data?.task?.id || 'No available tasks'}`
|
||||
);
|
||||
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'}`
|
||||
);
|
||||
log.error(`Failed to find next task: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error finding next task');
|
||||
@@ -80,6 +58,6 @@ export function registerNextTaskTool(server) {
|
||||
log.error(`Error in nextTask tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,18 +3,13 @@
|
||||
* Tool to parse PRD document and generate tasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
getProjectRootFromSession,
|
||||
handleApiResult,
|
||||
createErrorResponse
|
||||
} from './utils.js';
|
||||
import { parsePRDDirect } from '../core/task-master-core.js';
|
||||
import {
|
||||
resolveProjectPaths,
|
||||
findPRDDocumentPath,
|
||||
resolveTasksOutputPath
|
||||
} from '../core/utils/path-utils.js';
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from "./utils.js";
|
||||
import { parsePRDDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the parsePRD tool with the MCP server
|
||||
@@ -22,89 +17,40 @@ import {
|
||||
*/
|
||||
export function registerParsePRDTool(server) {
|
||||
server.addTool({
|
||||
name: 'parse_prd',
|
||||
description:
|
||||
"Parse a Product Requirements Document (PRD) text file to automatically generate initial tasks. Reinitializing the project is not necessary to run this tool. It is recommended to run parse-prd after initializing the project and creating/importing a prd.txt file in the project root's scripts/ directory.",
|
||||
name: "parse_prd",
|
||||
description: "Parse a Product Requirements Document (PRD) or text file to automatically generate initial tasks.",
|
||||
parameters: z.object({
|
||||
input: z
|
||||
.string()
|
||||
.optional()
|
||||
.default('scripts/prd.txt')
|
||||
.describe('Absolute path to the PRD document file (.txt, .md, etc.)'),
|
||||
numTasks: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Approximate number of top-level tasks to generate (default: 10). As the agent, if you have enough information, ensure to enter a number of tasks that would logically scale with project complexity. Avoid entering numbers above 50 due to context window limitations.'
|
||||
),
|
||||
output: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Output path for tasks.json file (default: tasks/tasks.json)'
|
||||
),
|
||||
force: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Allow overwriting an existing tasks.json file.'),
|
||||
append: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
'Append new tasks to existing tasks.json instead of overwriting'
|
||||
),
|
||||
input: z.string().default("tasks/tasks.json").describe("Path to the PRD document file (relative to project root or absolute)"),
|
||||
numTasks: z.string().optional().describe("Approximate number of top-level tasks to generate (default: 10)"),
|
||||
output: z.string().optional().describe("Output path for tasks.json file (relative to project root or absolute, default: tasks/tasks.json)"),
|
||||
force: z.boolean().optional().describe("Allow overwriting an existing tasks.json file."),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: automatically detected from session or CWD)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve input (PRD) and output (tasks.json) paths using the utility
|
||||
const { projectRoot, prdPath, tasksJsonPath } = resolveProjectPaths(
|
||||
rootFolder,
|
||||
args,
|
||||
log
|
||||
);
|
||||
|
||||
// Check if PRD path was found (resolveProjectPaths returns null if not found and not provided)
|
||||
if (!prdPath) {
|
||||
return createErrorResponse(
|
||||
'No PRD document found or provided. Please ensure a PRD file exists (e.g., PRD.md) or provide a valid input file path.'
|
||||
);
|
||||
}
|
||||
|
||||
// Call the direct function with fully resolved paths
|
||||
const result = await parsePRDDirect(
|
||||
{
|
||||
projectRoot: projectRoot,
|
||||
input: prdPath,
|
||||
output: tasksJsonPath,
|
||||
numTasks: args.numTasks,
|
||||
force: args.force,
|
||||
append: args.append
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
);
|
||||
const result = await parsePRDDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, 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'}`
|
||||
);
|
||||
log.error(`Failed to parse PRD: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error parsing PRD');
|
||||
@@ -112,6 +58,6 @@ export function registerParsePRDTool(server) {
|
||||
log.error(`Error in parse-prd tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for removing a dependency from a task
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { removeDependencyDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { removeDependencyDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the removeDependency tool with the MCP server
|
||||
@@ -18,62 +17,32 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerRemoveDependencyTool(server) {
|
||||
server.addTool({
|
||||
name: 'remove_dependency',
|
||||
description: 'Remove a dependency from a task',
|
||||
name: "remove_dependency",
|
||||
description: "Remove a dependency from a task",
|
||||
parameters: z.object({
|
||||
id: z.string().describe('Task ID to remove dependency from'),
|
||||
dependsOn: z.string().describe('Task ID to remove as a dependency'),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
id: z.string().describe("Task ID to remove dependency from"),
|
||||
dependsOn: z.string().describe("Task ID to remove as a dependency"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(
|
||||
`Removing dependency for task ${args.id} from ${args.dependsOn} with args: ${JSON.stringify(args)}`
|
||||
);
|
||||
log.info(`Removing dependency for task ${args.id} from ${args.dependsOn} with args: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await removeDependencyDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
const result = await removeDependencyDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
// Pass other relevant args
|
||||
id: args.id,
|
||||
dependsOn: args.dependsOn
|
||||
},
|
||||
log
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Successfully removed dependency: ${result.data.message}`);
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for removing subtasks from parent tasks
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { removeSubtaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { removeSubtaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the removeSubtask tool with the MCP server
|
||||
@@ -18,74 +17,33 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerRemoveSubtaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'remove_subtask',
|
||||
description: 'Remove a subtask from its parent task',
|
||||
name: "remove_subtask",
|
||||
description: "Remove a subtask from its parent task",
|
||||
parameters: z.object({
|
||||
id: z
|
||||
.string()
|
||||
.describe(
|
||||
"Subtask ID to remove in format 'parentId.subtaskId' (required)"
|
||||
),
|
||||
convert: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe(
|
||||
'Convert the subtask to a standalone task instead of deleting it'
|
||||
),
|
||||
file: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the tasks file (default: tasks/tasks.json)'
|
||||
),
|
||||
skipGenerate: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Skip regenerating task files'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
id: z.string().describe("Subtask ID to remove in format 'parentId.subtaskId' (required)"),
|
||||
convert: z.boolean().optional().describe("Convert the subtask to a standalone task instead of deleting it"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Removing subtask with args: ${JSON.stringify(args)}`);
|
||||
// await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await removeSubtaskDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
||||
|
||||
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
|
||||
);
|
||||
// await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Subtask removed successfully: ${result.data.message}`);
|
||||
@@ -98,6 +56,6 @@ export function registerRemoveSubtaskTool(server) {
|
||||
log.error(`Error in removeSubtask tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to remove a task by ID
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { removeTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { removeTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the remove-task tool with the MCP server
|
||||
@@ -18,64 +17,43 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerRemoveTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'remove_task',
|
||||
description: 'Remove a task or subtask permanently from the tasks list',
|
||||
name: "remove_task",
|
||||
description: "Remove a task or subtask permanently from the tasks list",
|
||||
parameters: z.object({
|
||||
id: z
|
||||
.string()
|
||||
.describe(
|
||||
"ID(s) of the task(s) or subtask(s) to remove (e.g., '5' or '5.2' or '5,6,7')"
|
||||
),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
id: z.string().describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.'),
|
||||
confirm: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to skip confirmation prompt (default: false)')
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
confirm: z.boolean().optional().describe("Whether to skip confirmation prompt (default: false)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Removing task(s) with ID(s): ${args.id}`);
|
||||
log.info(`Removing task with ID: ${args.id}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
// Get project root from session
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
} else if (!rootFolder) {
|
||||
// Ensure we have a default if nothing else works
|
||||
rootFolder = process.cwd();
|
||||
log.warn(`Session and args failed to provide root, using CWD: ${rootFolder}`);
|
||||
}
|
||||
|
||||
log.info(`Using project root: ${rootFolder}`);
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
log.info(`Using tasks file path: ${tasksJsonPath}`);
|
||||
|
||||
// Assume client has already handled confirmation if needed
|
||||
const result = await removeTaskDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
id: args.id
|
||||
},
|
||||
log
|
||||
);
|
||||
const result = await removeTaskDirect({
|
||||
id: args.id,
|
||||
file: args.file,
|
||||
projectRoot: rootFolder
|
||||
}, log);
|
||||
|
||||
if (result.success) {
|
||||
log.info(`Successfully removed task: ${args.id}`);
|
||||
@@ -88,6 +66,6 @@ export function registerRemoveTaskTool(server) {
|
||||
log.error(`Error in remove-task tool: ${error.message}`);
|
||||
return createErrorResponse(`Failed to remove task: ${error.message}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to set the status of a task
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { setTaskStatusDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { setTaskStatusDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the setTaskStatus tool with the MCP server
|
||||
@@ -18,84 +17,54 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerSetTaskStatusTool(server) {
|
||||
server.addTool({
|
||||
name: 'set_task_status',
|
||||
description: 'Set the status of one or more tasks or subtasks.',
|
||||
name: "set_task_status",
|
||||
description: "Set the status of one or more tasks or subtasks.",
|
||||
parameters: z.object({
|
||||
id: z
|
||||
.string()
|
||||
.describe(
|
||||
"Task ID or subtask ID (e.g., '15', '15.2'). Can be comma-separated for multiple updates."
|
||||
),
|
||||
.describe("Task ID or subtask ID (e.g., '15', '15.2'). Can be comma-separated for multiple updates."),
|
||||
status: z
|
||||
.string()
|
||||
.describe(
|
||||
"New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."
|
||||
),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
.describe("New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: automatically detected)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
// Get project root from session
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
// Call the direct function with the resolved path
|
||||
const result = await setTaskStatusDirect(
|
||||
{
|
||||
// Pass the explicitly resolved path
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
// Pass other relevant args
|
||||
id: args.id,
|
||||
status: args.status
|
||||
},
|
||||
log
|
||||
);
|
||||
// Call the direct function with the project root
|
||||
const result = await setTaskStatusDirect({
|
||||
...args,
|
||||
projectRoot: rootFolder
|
||||
}, log);
|
||||
|
||||
// Log the result
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully updated status for task(s) ${args.id} to "${args.status}": ${result.data.message}`
|
||||
);
|
||||
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'}`
|
||||
);
|
||||
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}`
|
||||
);
|
||||
}
|
||||
return createErrorResponse(`Error setting task status: ${error.message}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to append additional information to a specific subtask
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { updateSubtaskByIdDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { updateSubtaskByIdDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the update-subtask tool with the MCP server
|
||||
@@ -18,73 +17,40 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerUpdateSubtaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'update_subtask',
|
||||
description:
|
||||
'Appends timestamped information to a specific subtask without replacing existing content',
|
||||
name: "update_subtask",
|
||||
description: "Appends additional information to a specific subtask without replacing existing content",
|
||||
parameters: z.object({
|
||||
id: z
|
||||
.string()
|
||||
.describe(
|
||||
'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.'
|
||||
),
|
||||
prompt: z.string().describe('Information to add to the subtask'),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Use Perplexity AI for research-backed updates'),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
id: z.string().describe("ID of the subtask to update in format \"parentId.subtaskId\" (e.g., \"5.2\")"),
|
||||
prompt: z.string().describe("Information to add to the subtask"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
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 }
|
||||
);
|
||||
const result = await updateSubtaskByIdDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, 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'}`
|
||||
);
|
||||
log.error(`Failed to update subtask: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error updating subtask');
|
||||
@@ -92,6 +58,6 @@ export function registerUpdateSubtaskTool(server) {
|
||||
log.error(`Error in update_subtask tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to update a single task by ID with new information
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { updateTaskByIdDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { updateTaskByIdDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the update-task tool with the MCP server
|
||||
@@ -18,75 +17,40 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerUpdateTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'update_task',
|
||||
description:
|
||||
'Updates a single task by ID with new information or context provided in the prompt.',
|
||||
name: "update_task",
|
||||
description: "Updates a single task by ID with new information or context provided in the prompt.",
|
||||
parameters: z.object({
|
||||
id: z
|
||||
.string()
|
||||
.describe(
|
||||
"ID of the task (e.g., '15') to update. Subtasks are supported using the update-subtask tool."
|
||||
),
|
||||
prompt: z
|
||||
.string()
|
||||
.describe('New information or context to incorporate into the task'),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Use Perplexity AI for research-backed updates'),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
id: z.string().describe("ID of the task or subtask (e.g., '15', '15.2') to update"),
|
||||
prompt: z.string().describe("New information or context to incorporate into the task"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Updating task with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
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 }
|
||||
);
|
||||
const result = await updateTaskByIdDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, 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'}`
|
||||
);
|
||||
log.error(`Failed to update task: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error updating task');
|
||||
@@ -94,6 +58,6 @@ export function registerUpdateTaskTool(server) {
|
||||
log.error(`Error in update_task tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool to update tasks based on new context/prompt
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { updateTasksDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { updateTasksDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the update tool with the MCP server
|
||||
@@ -18,75 +17,40 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerUpdateTool(server) {
|
||||
server.addTool({
|
||||
name: 'update',
|
||||
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 or 'update_subtask' for subtasks.",
|
||||
name: "update",
|
||||
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.",
|
||||
parameters: z.object({
|
||||
from: z
|
||||
.string()
|
||||
.describe(
|
||||
"Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'"
|
||||
),
|
||||
prompt: z
|
||||
.string()
|
||||
.describe('Explanation of changes or new context to apply'),
|
||||
research: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Use Perplexity AI for research-backed updates'),
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
from: z.string().describe("Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'"),
|
||||
prompt: z.string().describe("Explanation of changes or new context to apply"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
.optional()
|
||||
.describe(
|
||||
"Root directory of the project (default: current working directory)"
|
||||
),
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
// Ensure project root was determined
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
// Resolve the path to tasks.json
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
const result = await updateTasksDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath,
|
||||
from: args.from,
|
||||
prompt: args.prompt,
|
||||
research: args.research
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
);
|
||||
const result = await updateTasksDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { session });
|
||||
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully updated tasks from ID ${args.from}: ${result.data.message}`
|
||||
);
|
||||
log.info(`Successfully updated tasks from ID ${args.from}: ${result.data.message}`);
|
||||
} else {
|
||||
log.error(
|
||||
`Failed to update tasks: ${result.error?.message || 'Unknown error'}`
|
||||
);
|
||||
log.error(`Failed to update tasks: ${result.error?.message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return handleApiResult(result, log, 'Error updating tasks');
|
||||
@@ -94,6 +58,6 @@ export function registerUpdateTool(server) {
|
||||
log.error(`Error in update tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -3,16 +3,13 @@
|
||||
* Utility functions for Task Master CLI integration
|
||||
*/
|
||||
|
||||
import { spawnSync } from 'child_process';
|
||||
import path from 'path';
|
||||
import { spawnSync } from "child_process";
|
||||
import path from "path";
|
||||
import fs from 'fs';
|
||||
import { contextManager } from '../core/context-manager.js'; // Import the singleton
|
||||
|
||||
// Import path utilities to ensure consistent path resolution
|
||||
import {
|
||||
lastFoundProjectRoot,
|
||||
PROJECT_MARKERS
|
||||
} from '../core/utils/path-utils.js';
|
||||
import { lastFoundProjectRoot, PROJECT_MARKERS } from '../core/utils/path-utils.js';
|
||||
|
||||
/**
|
||||
* Get normalized project root path
|
||||
@@ -34,9 +31,7 @@ function getProjectRoot(projectRootRaw, log) {
|
||||
const absolutePath = path.isAbsolute(envRoot)
|
||||
? envRoot
|
||||
: path.resolve(process.cwd(), envRoot);
|
||||
log.info(
|
||||
`Using project root from TASK_MASTER_PROJECT_ROOT environment variable: ${absolutePath}`
|
||||
);
|
||||
log.info(`Using project root from TASK_MASTER_PROJECT_ROOT environment variable: ${absolutePath}`);
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
@@ -52,33 +47,23 @@ function getProjectRoot(projectRootRaw, log) {
|
||||
|
||||
// 3. If we have a last found project root from a tasks.json search, use that for consistency
|
||||
if (lastFoundProjectRoot) {
|
||||
log.info(
|
||||
`Using last known project root where tasks.json was found: ${lastFoundProjectRoot}`
|
||||
);
|
||||
log.info(`Using last known project root where tasks.json was found: ${lastFoundProjectRoot}`);
|
||||
return lastFoundProjectRoot;
|
||||
}
|
||||
|
||||
// 4. Check if the current directory has any indicators of being a task-master project
|
||||
const currentDir = process.cwd();
|
||||
if (
|
||||
PROJECT_MARKERS.some((marker) => {
|
||||
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}`
|
||||
);
|
||||
})) {
|
||||
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.'
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -91,8 +76,7 @@ function getProjectRoot(projectRootRaw, log) {
|
||||
function getProjectRootFromSession(session, log) {
|
||||
try {
|
||||
// Add detailed logging of session structure
|
||||
log.info(
|
||||
`Session object: ${JSON.stringify({
|
||||
log.info(`Session object: ${JSON.stringify({
|
||||
hasSession: !!session,
|
||||
hasRoots: !!session?.roots,
|
||||
rootsType: typeof session?.roots,
|
||||
@@ -104,8 +88,7 @@ function getProjectRootFromSession(session, log) {
|
||||
isRootsRootsArray: Array.isArray(session?.roots?.roots),
|
||||
rootsRootsLength: session?.roots?.roots?.length,
|
||||
firstRootsRoot: session?.roots?.roots?.[0]
|
||||
})}`
|
||||
);
|
||||
})}`);
|
||||
|
||||
// ALWAYS ensure we return a valid path for project root
|
||||
const cwd = process.cwd();
|
||||
@@ -142,11 +125,9 @@ function getProjectRootFromSession(session, log) {
|
||||
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')) ||
|
||||
if (fs.existsSync(path.join(projectRoot, '.cursor')) ||
|
||||
fs.existsSync(path.join(projectRoot, 'mcp-server')) ||
|
||||
fs.existsSync(path.join(projectRoot, 'package.json'))
|
||||
) {
|
||||
fs.existsSync(path.join(projectRoot, 'package.json'))) {
|
||||
log.info(`Found project root from server path: ${projectRoot}`);
|
||||
return projectRoot;
|
||||
}
|
||||
@@ -161,9 +142,7 @@ function getProjectRootFromSession(session, log) {
|
||||
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();
|
||||
return mcpServerIndex !== -1 ? serverPath.substring(0, mcpServerIndex - 1) : process.cwd();
|
||||
}
|
||||
|
||||
// Only use cwd if it's not "/"
|
||||
@@ -180,12 +159,7 @@ function getProjectRootFromSession(session, log) {
|
||||
* @param {Function} processFunction - Optional function to process successful result data
|
||||
* @returns {Object} - Standardized MCP response object
|
||||
*/
|
||||
function handleApiResult(
|
||||
result,
|
||||
log,
|
||||
errorPrefix = 'API error',
|
||||
processFunction = processMCPResponseData
|
||||
) {
|
||||
function handleApiResult(result, log, errorPrefix = 'API error', processFunction = processMCPResponseData) {
|
||||
if (!result.success) {
|
||||
const errorMsg = result.error?.message || `Unknown ${errorPrefix}`;
|
||||
// Include cache status in error logs
|
||||
@@ -194,9 +168,7 @@ function handleApiResult(
|
||||
}
|
||||
|
||||
// Process the result data if needed
|
||||
const processedData = processFunction
|
||||
? processFunction(result.data)
|
||||
: result.data;
|
||||
const processedData = processFunction ? processFunction(result.data) : result.data;
|
||||
|
||||
// Log success including cache status
|
||||
log.info(`Successfully completed operation. From cache: ${result.fromCache}`); // Add success log with cache status
|
||||
@@ -242,7 +214,7 @@ function executeTaskMasterCommand(
|
||||
|
||||
// Common options for spawn
|
||||
const spawnOptions = {
|
||||
encoding: 'utf8',
|
||||
encoding: "utf8",
|
||||
cwd: cwd,
|
||||
// Merge process.env with customEnv, giving precedence to customEnv
|
||||
env: { ...process.env, ...(customEnv || {}) }
|
||||
@@ -253,13 +225,13 @@ function executeTaskMasterCommand(
|
||||
|
||||
// Execute the command using the global task-master CLI or local script
|
||||
// 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 (result.error && result.error.code === 'ENOENT') {
|
||||
log.info('Global task-master not found, falling back to local script');
|
||||
if (result.error && result.error.code === "ENOENT") {
|
||||
log.info("Global task-master not found, falling back to local script");
|
||||
// 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) {
|
||||
@@ -272,7 +244,7 @@ function executeTaskMasterCommand(
|
||||
? result.stderr.trim()
|
||||
: result.stdout
|
||||
? result.stdout.trim()
|
||||
: 'Unknown error';
|
||||
: "Unknown error";
|
||||
throw new Error(
|
||||
`Command failed with exit code ${result.status}: ${errorOutput}`
|
||||
);
|
||||
@@ -281,13 +253,13 @@ function executeTaskMasterCommand(
|
||||
return {
|
||||
success: true,
|
||||
stdout: result.stdout,
|
||||
stderr: result.stderr
|
||||
stderr: result.stderr,
|
||||
};
|
||||
} catch (error) {
|
||||
log.error(`Error executing task-master command: ${error.message}`);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -329,13 +301,9 @@ async function getCachedOrExecute({ cacheKey, actionFn, log }) {
|
||||
const { fromCache, ...resultToCache } = result;
|
||||
contextManager.setCachedData(cacheKey, resultToCache);
|
||||
} else if (!result.success) {
|
||||
log.warn(
|
||||
`Action failed for cache key ${cacheKey}. Result not cached. Error: ${result.error?.message}`
|
||||
);
|
||||
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.`
|
||||
);
|
||||
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
|
||||
@@ -352,10 +320,7 @@ async function getCachedOrExecute({ cacheKey, actionFn, log }) {
|
||||
* @param {string[]} fieldsToRemove - An array of field names to remove.
|
||||
* @returns {Object|Array} - The processed data with specified fields removed.
|
||||
*/
|
||||
function processMCPResponseData(
|
||||
taskOrData,
|
||||
fieldsToRemove = ['details', 'testStrategy']
|
||||
) {
|
||||
function processMCPResponseData(taskOrData, fieldsToRemove = ['details', 'testStrategy']) {
|
||||
if (!taskOrData) {
|
||||
return taskOrData;
|
||||
}
|
||||
@@ -369,7 +334,7 @@ function processMCPResponseData(
|
||||
const processedTask = { ...task };
|
||||
|
||||
// Remove specified fields from the task
|
||||
fieldsToRemove.forEach((field) => {
|
||||
fieldsToRemove.forEach(field => {
|
||||
delete processedTask[field];
|
||||
});
|
||||
|
||||
@@ -388,23 +353,14 @@ function processMCPResponseData(
|
||||
};
|
||||
|
||||
// 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)
|
||||
) {
|
||||
if (typeof taskOrData === 'object' && taskOrData !== null && Array.isArray(taskOrData.tasks)) {
|
||||
return {
|
||||
...taskOrData, // Keep other potential fields like 'stats', 'filter'
|
||||
tasks: processArrayOfTasks(taskOrData.tasks)
|
||||
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
|
||||
) {
|
||||
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)
|
||||
@@ -426,12 +382,11 @@ function createContentResponse(content) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text:
|
||||
typeof content === 'object'
|
||||
? // Format JSON nicely with indentation
|
||||
JSON.stringify(content, null, 2)
|
||||
: // Keep other content types as-is
|
||||
type: "text",
|
||||
text: typeof content === 'object' ?
|
||||
// Format JSON nicely with indentation
|
||||
JSON.stringify(content, null, 2) :
|
||||
// Keep other content types as-is
|
||||
String(content)
|
||||
}
|
||||
]
|
||||
@@ -447,7 +402,7 @@ export function createErrorResponse(errorMessage) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
type: "text",
|
||||
text: `Error: ${errorMessage}`
|
||||
}
|
||||
],
|
||||
@@ -463,5 +418,5 @@ export {
|
||||
executeTaskMasterCommand,
|
||||
getCachedOrExecute,
|
||||
processMCPResponseData,
|
||||
createContentResponse
|
||||
createContentResponse,
|
||||
};
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Tool for validating task dependencies
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
getProjectRootFromSession
|
||||
} from './utils.js';
|
||||
import { validateDependenciesDirect } from '../core/task-master-core.js';
|
||||
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
} from "./utils.js";
|
||||
import { validateDependenciesDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the validateDependencies tool with the MCP server
|
||||
@@ -18,53 +17,33 @@ import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerValidateDependenciesTool(server) {
|
||||
server.addTool({
|
||||
name: 'validate_dependencies',
|
||||
description:
|
||||
'Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.',
|
||||
name: "validate_dependencies",
|
||||
description: "Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe('The directory of the project. Must be an absolute path.')
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
execute: async (args, { log, session, reportProgress }) => {
|
||||
try {
|
||||
log.info(`Validating dependencies with args: ${JSON.stringify(args)}`);
|
||||
await reportProgress({ progress: 0 });
|
||||
|
||||
// Get project root from args or session
|
||||
const rootFolder =
|
||||
args.projectRoot || getProjectRootFromSession(session, log);
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
return createErrorResponse(
|
||||
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
||||
);
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
}
|
||||
|
||||
let tasksJsonPath;
|
||||
try {
|
||||
tasksJsonPath = findTasksJsonPath(
|
||||
{ projectRoot: rootFolder, file: args.file },
|
||||
log
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(`Error finding tasks.json: ${error.message}`);
|
||||
return createErrorResponse(
|
||||
`Failed to find tasks.json: ${error.message}`
|
||||
);
|
||||
}
|
||||
const result = await validateDependenciesDirect({
|
||||
projectRoot: rootFolder,
|
||||
...args
|
||||
}, log, { reportProgress, mcpLog: log, session});
|
||||
|
||||
const result = await validateDependenciesDirect(
|
||||
{
|
||||
tasksJsonPath: tasksJsonPath
|
||||
},
|
||||
log
|
||||
);
|
||||
await reportProgress({ progress: 100 });
|
||||
|
||||
if (result.success) {
|
||||
log.info(
|
||||
`Successfully validated dependencies: ${result.data.message}`
|
||||
);
|
||||
log.info(`Successfully validated dependencies: ${result.data.message}`);
|
||||
} else {
|
||||
log.error(`Failed to validate dependencies: ${result.error.message}`);
|
||||
}
|
||||
@@ -74,6 +53,6 @@ export function registerValidateDependenciesTool(server) {
|
||||
log.error(`Error in validateDependencies tool: ${error.message}`);
|
||||
return createErrorResponse(error.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -16,9 +16,7 @@ try {
|
||||
|
||||
if (fs.existsSync(mcpPath)) {
|
||||
console.error('mcp.json file found');
|
||||
console.error(
|
||||
`File content: ${JSON.stringify(JSON.parse(fs.readFileSync(mcpPath, 'utf8')), null, 2)}`
|
||||
);
|
||||
console.error(`File content: ${JSON.stringify(JSON.parse(fs.readFileSync(mcpPath, 'utf8')), null, 2)}`);
|
||||
} else {
|
||||
console.error('mcp.json file not found');
|
||||
}
|
||||
@@ -29,9 +27,7 @@ try {
|
||||
|
||||
// Check if env property exists
|
||||
if (config.env) {
|
||||
console.error(
|
||||
`Config.env exists with keys: ${Object.keys(config.env).join(', ')}`
|
||||
);
|
||||
console.error(`Config.env exists with keys: ${Object.keys(config.env).join(', ')}`);
|
||||
|
||||
// Print each env var value (careful with sensitive values)
|
||||
for (const [key, value] of Object.entries(config.env)) {
|
||||
|
||||
52
package-lock.json
generated
52
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "task-master-ai",
|
||||
"version": "0.11.1",
|
||||
"version": "0.10.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "task-master-ai",
|
||||
"version": "0.11.1",
|
||||
"version": "0.10.0",
|
||||
"license": "MIT WITH Commons-Clause",
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.39.0",
|
||||
@@ -31,8 +31,9 @@
|
||||
},
|
||||
"bin": {
|
||||
"task-master": "bin/task-master.js",
|
||||
"task-master-ai": "mcp-server/server.js",
|
||||
"task-master-mcp": "mcp-server/server.js"
|
||||
"task-master-init": "bin/task-master-init.js",
|
||||
"task-master-mcp": "mcp-server/server.js",
|
||||
"task-master-mcp-server": "mcp-server/server.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.5.1",
|
||||
@@ -41,7 +42,6 @@
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-node": "^29.7.0",
|
||||
"mock-fs": "^5.5.0",
|
||||
"prettier": "^3.5.3",
|
||||
"supertest": "^7.1.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -608,22 +608,6 @@
|
||||
"semver": "^7.5.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@changesets/apply-release-plan/node_modules/prettier": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@changesets/apply-release-plan/node_modules/semver": {
|
||||
"version": "7.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||
@@ -946,22 +930,6 @@
|
||||
"prettier": "^2.7.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@changesets/write/node_modules/prettier": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@colors/colors": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz",
|
||||
@@ -6654,16 +6622,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.5.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz",
|
||||
"integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
|
||||
14
package.json
14
package.json
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"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.",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"task-master": "bin/task-master.js",
|
||||
"task-master-init": "bin/task-master-init.js",
|
||||
"task-master-mcp": "mcp-server/server.js",
|
||||
"task-master-ai": "mcp-server/server.js"
|
||||
"task-master-mcp-server": "mcp-server/server.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
||||
@@ -16,13 +17,11 @@
|
||||
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
|
||||
"prepare-package": "node scripts/prepare-package.js",
|
||||
"prepublishOnly": "npm run prepare-package",
|
||||
"prepare": "chmod +x bin/task-master.js mcp-server/server.js",
|
||||
"prepare": "chmod +x bin/task-master.js bin/task-master-init.js mcp-server/server.js",
|
||||
"changeset": "changeset",
|
||||
"release": "changeset publish",
|
||||
"inspector": "npx @modelcontextprotocol/inspector node mcp-server/server.js",
|
||||
"mcp-server": "node mcp-server/server.js",
|
||||
"format-check": "prettier --check .",
|
||||
"format": "prettier --write ."
|
||||
"inspector": "CLIENT_PORT=8888 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node mcp-server/server.js",
|
||||
"mcp-server": "node mcp-server/server.js"
|
||||
},
|
||||
"keywords": [
|
||||
"claude",
|
||||
@@ -92,7 +91,6 @@
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-node": "^29.7.0",
|
||||
"mock-fs": "^5.5.0",
|
||||
"prettier": "^3.5.3",
|
||||
"supertest": "^7.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
### Required Configuration
|
||||
|
||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
||||
|
||||
### Optional Configuration
|
||||
|
||||
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
||||
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
||||
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
||||
@@ -41,7 +39,6 @@ The script can be configured through environment variables in a `.env` file at t
|
||||
## How It Works
|
||||
|
||||
1. **`tasks.json`**:
|
||||
|
||||
- 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.
|
||||
- Tasks can have `subtasks` for more detailed implementation steps.
|
||||
@@ -105,7 +102,6 @@ node scripts/dev.js update --file=custom-tasks.json --from=5 --prompt="Change da
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- The `--prompt` parameter is required and should explain the changes or new context
|
||||
- Only tasks that aren't marked as 'done' 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:
|
||||
|
||||
- Updates only the specified task rather than a range of tasks
|
||||
- Provides detailed validation with helpful error messages
|
||||
- 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:
|
||||
|
||||
- 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
|
||||
- You can specify multiple task IDs by separating them with commas
|
||||
@@ -201,7 +195,6 @@ node scripts/dev.js clear-subtasks --all
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- After clearing subtasks, task files are automatically regenerated
|
||||
- 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
|
||||
@@ -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.
|
||||
|
||||
To use the Perplexity integration:
|
||||
|
||||
1. Obtain a Perplexity API key
|
||||
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
||||
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
||||
@@ -226,7 +218,6 @@ To use the Perplexity integration:
|
||||
## Logging
|
||||
|
||||
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
||||
|
||||
- `debug`: Detailed information, typically useful for troubleshooting
|
||||
- `info`: Confirmation that things are working as expected (default)
|
||||
- `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:
|
||||
|
||||
1. **Allow precise dependency management**:
|
||||
|
||||
- Add dependencies between tasks with automatic validation
|
||||
- Remove dependencies when they're no longer needed
|
||||
- Update task files automatically after changes
|
||||
|
||||
2. **Include validation checks**:
|
||||
|
||||
- Prevent circular dependencies (a task depending on itself)
|
||||
- Prevent duplicate dependencies
|
||||
- Verify that both tasks exist before adding/removing dependencies
|
||||
- Check if dependencies exist before attempting to remove them
|
||||
|
||||
3. **Provide clear feedback**:
|
||||
|
||||
- Success messages confirm when dependencies are added/removed
|
||||
- Error messages explain why operations failed (if applicable)
|
||||
|
||||
@@ -287,7 +275,6 @@ node scripts/dev.js validate-dependencies --file=custom-tasks.json
|
||||
```
|
||||
|
||||
This command:
|
||||
|
||||
- Scans all tasks and subtasks for non-existent dependencies
|
||||
- Identifies potential self-dependencies (tasks referencing themselves)
|
||||
- Reports all found issues without modifying files
|
||||
@@ -309,7 +296,6 @@ node scripts/dev.js fix-dependencies --file=custom-tasks.json
|
||||
```
|
||||
|
||||
This command:
|
||||
|
||||
1. **Validates all dependencies** across tasks and subtasks
|
||||
2. **Automatically removes**:
|
||||
- References to non-existent tasks and subtasks
|
||||
@@ -347,7 +333,6 @@ node scripts/dev.js analyze-complexity --research
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
||||
- Tasks are scored on a scale of 1-10
|
||||
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
||||
@@ -372,14 +357,12 @@ node scripts/dev.js expand --id=8 --num=5 --prompt="Custom prompt"
|
||||
```
|
||||
|
||||
When a complexity report exists:
|
||||
|
||||
- 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)
|
||||
- When using `--all`, tasks are sorted by complexity score (highest first)
|
||||
- The `--research` flag is preserved from the complexity analysis to expansion
|
||||
|
||||
The output report structure is:
|
||||
|
||||
```json
|
||||
{
|
||||
"meta": {
|
||||
@@ -398,7 +381,7 @@ The output report structure is:
|
||||
"expansionPrompt": "Create subtasks that handle detecting...",
|
||||
"reasoning": "This task requires sophisticated logic...",
|
||||
"expansionCommand": "node scripts/dev.js expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
||||
}
|
||||
},
|
||||
// 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:
|
||||
|
||||
1. **Detailed Validation**:
|
||||
|
||||
- Required parameters (like task IDs and prompts) are validated early
|
||||
- File existence is checked with customized errors for common scenarios
|
||||
- Parameter type conversion is handled with clear error messages
|
||||
|
||||
2. **Contextual Error Messages**:
|
||||
|
||||
- Task not found errors include suggestions to run the list command
|
||||
- API key errors include reminders to check environment variables
|
||||
- Invalid ID format errors show the expected format
|
||||
|
||||
3. **Command-Specific Help Displays**:
|
||||
|
||||
- When validation fails, detailed help for the specific command is shown
|
||||
- Help displays include usage examples and parameter descriptions
|
||||
- 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:
|
||||
|
||||
1. **Background Version Checking**:
|
||||
|
||||
- Non-blocking version checks run in the background while commands execute
|
||||
- Actual command execution isn't delayed by version checking
|
||||
- Update notifications appear after command completion
|
||||
|
||||
2. **Update Notifications**:
|
||||
|
||||
- When a newer version is available, a notification is displayed
|
||||
- Notifications include current version, latest version, and update command
|
||||
- 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:
|
||||
|
||||
- Create new subtasks with detailed properties or convert existing tasks
|
||||
- Define dependencies between subtasks
|
||||
- Set custom status for new subtasks
|
||||
@@ -561,7 +538,6 @@ node scripts/dev.js remove-subtask --id=5.2 --skip-generate
|
||||
```
|
||||
|
||||
Key features:
|
||||
|
||||
- Remove subtasks individually or in batches
|
||||
- Optionally convert subtasks to standalone tasks
|
||||
- Control whether task files are regenerated
|
||||
|
||||
710
scripts/init.js
710
scripts/init.js
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Task Master
|
||||
* Copyright (c) 2025 Eyal Toledano, Ralph Khreish
|
||||
@@ -13,8 +15,11 @@
|
||||
* For the full license text, see the LICENSE file in the root directory.
|
||||
*/
|
||||
|
||||
console.log('Starting task-master-ai...');
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import readline from 'readline';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
@@ -22,11 +27,49 @@ import chalk from 'chalk';
|
||||
import figlet from 'figlet';
|
||||
import boxen from 'boxen';
|
||||
import gradient from 'gradient-string';
|
||||
import { isSilentMode } from './modules/utils.js';
|
||||
import { Command } from 'commander';
|
||||
|
||||
// Debug information
|
||||
console.log('Node version:', process.version);
|
||||
console.log('Current directory:', process.cwd());
|
||||
console.log('Script path:', import.meta.url);
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Configure the CLI program
|
||||
const program = new Command();
|
||||
program
|
||||
.name('task-master-init')
|
||||
.description('Initialize a new Claude Task Master project')
|
||||
.version('1.0.0') // Will be replaced by prepare-package script
|
||||
.option('-y, --yes', 'Skip prompts and use default values')
|
||||
.option('-n, --name <name>', 'Project name')
|
||||
.option('-my_name <name>', 'Project name (alias for --name)')
|
||||
.option('-d, --description <description>', 'Project description')
|
||||
.option('-my_description <description>', 'Project description (alias for --description)')
|
||||
.option('-v, --version <version>', 'Project version')
|
||||
.option('-my_version <version>', 'Project version (alias for --version)')
|
||||
.option('--my_name <name>', 'Project name (alias for --name)')
|
||||
.option('-a, --author <author>', 'Author name')
|
||||
.option('--skip-install', 'Skip installing dependencies')
|
||||
.option('--dry-run', 'Show what would be done without making changes')
|
||||
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
||||
.parse(process.argv);
|
||||
|
||||
const options = program.opts();
|
||||
|
||||
// Map custom aliases to standard options
|
||||
if (options.my_name && !options.name) {
|
||||
options.name = options.my_name;
|
||||
}
|
||||
if (options.my_description && !options.description) {
|
||||
options.description = options.my_description;
|
||||
}
|
||||
if (options.my_version && !options.version) {
|
||||
options.version = options.my_version;
|
||||
}
|
||||
|
||||
// Define log levels
|
||||
const LOG_LEVELS = {
|
||||
debug: 0,
|
||||
@@ -37,9 +80,7 @@ const LOG_LEVELS = {
|
||||
};
|
||||
|
||||
// Get log level from environment or default to info
|
||||
const LOG_LEVEL = process.env.LOG_LEVEL
|
||||
? LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()]
|
||||
: LOG_LEVELS.info;
|
||||
const LOG_LEVEL = process.env.LOG_LEVEL ? LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()] : LOG_LEVELS.info;
|
||||
|
||||
// Create a color gradient for the banner
|
||||
const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']);
|
||||
@@ -47,8 +88,6 @@ const warmGradient = gradient(['#fb8b24', '#e36414', '#9a031e']);
|
||||
|
||||
// Display a fancy banner
|
||||
function displayBanner() {
|
||||
if (isSilentMode()) return;
|
||||
|
||||
console.clear();
|
||||
const bannerText = figlet.textSync('Task Master AI', {
|
||||
font: 'Standard',
|
||||
@@ -59,18 +98,14 @@ function displayBanner() {
|
||||
console.log(coolGradient(bannerText));
|
||||
|
||||
// Add creator credit line below the banner
|
||||
console.log(
|
||||
chalk.dim('by ') + chalk.cyan.underline('https://x.com/eyaltoledano')
|
||||
);
|
||||
console.log(chalk.dim('by ') + chalk.cyan.underline('https://x.com/eyaltoledano'));
|
||||
|
||||
console.log(
|
||||
boxen(chalk.white(`${chalk.bold('Initializing')} your new project`), {
|
||||
console.log(boxen(chalk.white(`${chalk.bold('Initializing')} your new project`), {
|
||||
padding: 1,
|
||||
margin: { top: 0, bottom: 1 },
|
||||
borderStyle: 'round',
|
||||
borderColor: 'cyan'
|
||||
})
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
// Logging function with icons and colors
|
||||
@@ -86,8 +121,6 @@ function log(level, ...args) {
|
||||
if (LOG_LEVELS[level] >= LOG_LEVEL) {
|
||||
const icon = icons[level] || '';
|
||||
|
||||
// Only output to console if not in silent mode
|
||||
if (!isSilentMode()) {
|
||||
if (level === 'error') {
|
||||
console.error(icon, chalk.red(...args));
|
||||
} else if (level === 'warn') {
|
||||
@@ -100,7 +133,6 @@ function log(level, ...args) {
|
||||
console.log(icon, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write to debug log if DEBUG=true
|
||||
if (process.env.DEBUG === 'true') {
|
||||
@@ -135,16 +167,13 @@ function addShellAliases() {
|
||||
try {
|
||||
// Check if file exists
|
||||
if (!fs.existsSync(shellConfigFile)) {
|
||||
log(
|
||||
'warn',
|
||||
`Shell config file ${shellConfigFile} not found. Aliases not added.`
|
||||
);
|
||||
log('warn', `Shell config file ${shellConfigFile} not found. Aliases not added.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if aliases already exist
|
||||
const configContent = fs.readFileSync(shellConfigFile, 'utf8');
|
||||
if (configContent.includes("alias tm='task-master'")) {
|
||||
if (configContent.includes('alias tm=\'task-master\'')) {
|
||||
log('info', 'Task Master aliases already exist in shell config.');
|
||||
return true;
|
||||
}
|
||||
@@ -158,11 +187,7 @@ alias taskmaster='task-master'
|
||||
|
||||
fs.appendFileSync(shellConfigFile, aliasBlock);
|
||||
log('success', `Added Task Master aliases to ${shellConfigFile}`);
|
||||
log(
|
||||
'info',
|
||||
'To use the aliases in your current terminal, run: source ' +
|
||||
shellConfigFile
|
||||
);
|
||||
log('info', 'To use the aliases in your current terminal, run: source ' + shellConfigFile);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -177,45 +202,24 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
||||
let sourcePath;
|
||||
|
||||
// Map template names to their actual source paths
|
||||
switch (templateName) {
|
||||
switch(templateName) {
|
||||
case 'dev.js':
|
||||
sourcePath = path.join(__dirname, 'dev.js');
|
||||
break;
|
||||
case 'scripts_README.md':
|
||||
sourcePath = path.join(__dirname, '..', 'assets', 'scripts_README.md');
|
||||
break;
|
||||
case 'dev_workflow.mdc':
|
||||
sourcePath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'.cursor',
|
||||
'rules',
|
||||
'dev_workflow.mdc'
|
||||
);
|
||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'dev_workflow.mdc');
|
||||
break;
|
||||
case 'taskmaster.mdc':
|
||||
sourcePath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'.cursor',
|
||||
'rules',
|
||||
'taskmaster.mdc'
|
||||
);
|
||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'taskmaster.mdc');
|
||||
break;
|
||||
case 'cursor_rules.mdc':
|
||||
sourcePath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'.cursor',
|
||||
'rules',
|
||||
'cursor_rules.mdc'
|
||||
);
|
||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'cursor_rules.mdc');
|
||||
break;
|
||||
case 'self_improve.mdc':
|
||||
sourcePath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'.cursor',
|
||||
'rules',
|
||||
'self_improve.mdc'
|
||||
);
|
||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'self_improve.mdc');
|
||||
break;
|
||||
case 'README-task-master.md':
|
||||
sourcePath = path.join(__dirname, '..', 'README-task-master.md');
|
||||
@@ -254,17 +258,12 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
||||
if (filename === '.gitignore') {
|
||||
log('info', `${targetPath} already exists, merging content...`);
|
||||
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
||||
const existingLines = new Set(
|
||||
existingContent.split('\n').map((line) => line.trim())
|
||||
);
|
||||
const newLines = content
|
||||
.split('\n')
|
||||
.filter((line) => !existingLines.has(line.trim()));
|
||||
const existingLines = new Set(existingContent.split('\n').map(line => line.trim()));
|
||||
const newLines = content.split('\n').filter(line => !existingLines.has(line.trim()));
|
||||
|
||||
if (newLines.length > 0) {
|
||||
// Add a comment to separate the original content from our additions
|
||||
const updatedContent =
|
||||
existingContent.trim() +
|
||||
const updatedContent = existingContent.trim() +
|
||||
'\n\n# Added by Claude Task Master\n' +
|
||||
newLines.join('\n');
|
||||
fs.writeFileSync(targetPath, updatedContent);
|
||||
@@ -277,15 +276,11 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
||||
|
||||
// Handle .windsurfrules - append the entire content
|
||||
if (filename === '.windsurfrules') {
|
||||
log(
|
||||
'info',
|
||||
`${targetPath} already exists, appending content instead of overwriting...`
|
||||
);
|
||||
log('info', `${targetPath} already exists, appending content instead of overwriting...`);
|
||||
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
||||
|
||||
// Add a separator comment before appending our content
|
||||
const updatedContent =
|
||||
existingContent.trim() +
|
||||
const updatedContent = existingContent.trim() +
|
||||
'\n\n# Added by Task Master - Development Workflow Rules\n\n' +
|
||||
content;
|
||||
fs.writeFileSync(targetPath, updatedContent);
|
||||
@@ -293,27 +288,62 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle package.json - merge dependencies
|
||||
if (filename === 'package.json') {
|
||||
log('info', `${targetPath} already exists, merging dependencies...`);
|
||||
try {
|
||||
const existingPackageJson = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
|
||||
const newPackageJson = JSON.parse(content);
|
||||
|
||||
// Merge dependencies, preferring existing versions in case of conflicts
|
||||
existingPackageJson.dependencies = {
|
||||
...newPackageJson.dependencies,
|
||||
...existingPackageJson.dependencies
|
||||
};
|
||||
|
||||
// Add our scripts if they don't already exist
|
||||
existingPackageJson.scripts = {
|
||||
...existingPackageJson.scripts,
|
||||
...Object.fromEntries(
|
||||
Object.entries(newPackageJson.scripts)
|
||||
.filter(([key]) => !existingPackageJson.scripts[key])
|
||||
)
|
||||
};
|
||||
|
||||
// Preserve existing type if present
|
||||
if (!existingPackageJson.type && newPackageJson.type) {
|
||||
existingPackageJson.type = newPackageJson.type;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
targetPath,
|
||||
JSON.stringify(existingPackageJson, null, 2)
|
||||
);
|
||||
log('success', `Updated ${targetPath} with required dependencies and scripts`);
|
||||
} catch (error) {
|
||||
log('error', `Failed to merge package.json: ${error.message}`);
|
||||
// Fallback to writing a backup of the existing file and creating a new one
|
||||
const backupPath = `${targetPath}.backup-${Date.now()}`;
|
||||
fs.copyFileSync(targetPath, backupPath);
|
||||
log('info', `Created backup of existing package.json at ${backupPath}`);
|
||||
fs.writeFileSync(targetPath, content);
|
||||
log('warn', `Replaced ${targetPath} with new content (due to JSON parsing error)`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle README.md - offer to preserve or create a different file
|
||||
if (filename === 'README-task-master.md') {
|
||||
if (filename === 'README.md') {
|
||||
log('info', `${targetPath} already exists`);
|
||||
// Create a separate README file specifically for this project
|
||||
const taskMasterReadmePath = path.join(
|
||||
path.dirname(targetPath),
|
||||
'README-task-master.md'
|
||||
);
|
||||
const taskMasterReadmePath = path.join(path.dirname(targetPath), 'README-task-master.md');
|
||||
fs.writeFileSync(taskMasterReadmePath, content);
|
||||
log(
|
||||
'success',
|
||||
`Created ${taskMasterReadmePath} (preserved original README-task-master.md)`
|
||||
);
|
||||
log('success', `Created ${taskMasterReadmePath} (preserved original README.md)`);
|
||||
return;
|
||||
}
|
||||
|
||||
// For other files, warn and prompt before overwriting
|
||||
log(
|
||||
'warn',
|
||||
`${targetPath} already exists. Skipping file creation to avoid overwriting existing content.`
|
||||
);
|
||||
log('warn', `${targetPath} already exists. Skipping file creation to avoid overwriting existing content.`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -322,113 +352,124 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
||||
log('info', `Created file: ${targetPath}`);
|
||||
}
|
||||
|
||||
// Main function to initialize a new project (Now relies solely on passed options)
|
||||
// Main function to initialize a new project
|
||||
async function initializeProject(options = {}) {
|
||||
// Receives options as argument
|
||||
// Only display banner if not in silent mode
|
||||
if (!isSilentMode()) {
|
||||
// Display the banner
|
||||
displayBanner();
|
||||
}
|
||||
|
||||
// Debug logging only if not in silent mode
|
||||
if (!isSilentMode()) {
|
||||
console.log('===== DEBUG: INITIALIZE PROJECT OPTIONS RECEIVED =====');
|
||||
console.log('Full options object:', JSON.stringify(options));
|
||||
console.log('options.yes:', options.yes);
|
||||
console.log('==================================================');
|
||||
}
|
||||
|
||||
// Determine if we should skip prompts based on the passed options
|
||||
const skipPrompts = options.yes;
|
||||
if (!isSilentMode()) {
|
||||
console.log('Skip prompts determined:', skipPrompts);
|
||||
}
|
||||
|
||||
if (skipPrompts) {
|
||||
if (!isSilentMode()) {
|
||||
console.log('SKIPPING PROMPTS - Using defaults or provided values');
|
||||
}
|
||||
|
||||
// We no longer need these variables
|
||||
// If options are provided, use them directly without prompting
|
||||
if (options.projectName && options.projectDescription) {
|
||||
const projectName = options.projectName;
|
||||
const projectDescription = options.projectDescription;
|
||||
const projectVersion = options.projectVersion || '1.0.0';
|
||||
const authorName = options.authorName || '';
|
||||
const dryRun = options.dryRun || false;
|
||||
const addAliases = options.aliases || false;
|
||||
const skipInstall = options.skipInstall || false;
|
||||
const addAliases = options.addAliases || false;
|
||||
|
||||
if (dryRun) {
|
||||
log('info', 'DRY RUN MODE: No files will be modified');
|
||||
log('info', 'Would initialize Task Master project');
|
||||
log('info', `Would initialize project: ${projectName} (${projectVersion})`);
|
||||
log('info', `Description: ${projectDescription}`);
|
||||
log('info', `Author: ${authorName || 'Not specified'}`);
|
||||
log('info', 'Would create/update necessary project files');
|
||||
if (addAliases) {
|
||||
log('info', 'Would add shell aliases for task-master');
|
||||
}
|
||||
if (!skipInstall) {
|
||||
log('info', 'Would install dependencies');
|
||||
}
|
||||
return {
|
||||
projectName,
|
||||
projectDescription,
|
||||
projectVersion,
|
||||
authorName,
|
||||
dryRun: true
|
||||
};
|
||||
}
|
||||
|
||||
// Create structure using only necessary values
|
||||
createProjectStructure(addAliases);
|
||||
} else {
|
||||
// Prompting logic (only runs if skipPrompts is false)
|
||||
log('info', 'Required options not provided, proceeding with prompts.');
|
||||
createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases);
|
||||
return {
|
||||
projectName,
|
||||
projectDescription,
|
||||
projectVersion,
|
||||
authorName
|
||||
};
|
||||
}
|
||||
|
||||
// Otherwise, prompt the user for input
|
||||
// Create readline interface only when needed
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
try {
|
||||
// Only prompt for shell aliases
|
||||
const addAliasesInput = await promptQuestion(
|
||||
rl,
|
||||
chalk.cyan(
|
||||
'Add shell aliases for task-master? This lets you type "tm" instead of "task-master" (Y/n): '
|
||||
)
|
||||
);
|
||||
const addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n';
|
||||
const projectName = await promptQuestion(rl, chalk.cyan('Enter project name: '));
|
||||
const projectDescription = await promptQuestion(rl, chalk.cyan('Enter project description: '));
|
||||
const projectVersionInput = await promptQuestion(rl, chalk.cyan('Enter project version (default: 1.0.0): '));
|
||||
const authorName = await promptQuestion(rl, chalk.cyan('Enter your name: '));
|
||||
|
||||
// Confirm settings...
|
||||
console.log('\nTask Master Project settings:');
|
||||
console.log(
|
||||
chalk.blue(
|
||||
'Add shell aliases (so you can use "tm" instead of "task-master"):'
|
||||
),
|
||||
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
|
||||
);
|
||||
// Ask about shell aliases
|
||||
const addAliasesInput = await promptQuestion(rl, chalk.cyan('Add shell aliases for task-master? (Y/n): '));
|
||||
const addAliases = addAliasesInput.trim().toLowerCase() !== 'n';
|
||||
|
||||
const confirmInput = await promptQuestion(
|
||||
rl,
|
||||
chalk.yellow('\nDo you want to continue with these settings? (Y/n): ')
|
||||
);
|
||||
// Set default version if not provided
|
||||
const projectVersion = projectVersionInput.trim() ? projectVersionInput : '1.0.0';
|
||||
|
||||
// Confirm settings
|
||||
console.log('\nProject settings:');
|
||||
console.log(chalk.blue('Name:'), chalk.white(projectName));
|
||||
console.log(chalk.blue('Description:'), chalk.white(projectDescription));
|
||||
console.log(chalk.blue('Version:'), chalk.white(projectVersion));
|
||||
console.log(chalk.blue('Author:'), chalk.white(authorName || 'Not specified'));
|
||||
console.log(chalk.blue('Add shell aliases:'), chalk.white(addAliases ? 'Yes' : 'No'));
|
||||
|
||||
const confirmInput = await promptQuestion(rl, chalk.yellow('\nDo you want to continue with these settings? (Y/n): '));
|
||||
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
|
||||
|
||||
// Close the readline interface
|
||||
rl.close();
|
||||
|
||||
if (!shouldContinue) {
|
||||
log('info', 'Project initialization cancelled by user');
|
||||
process.exit(0); // Exit if cancelled
|
||||
return; // Added return for clarity
|
||||
return null;
|
||||
}
|
||||
|
||||
// Still respect dryRun if passed initially even when prompting
|
||||
const dryRun = options.dryRun || false;
|
||||
const skipInstall = options.skipInstall || false;
|
||||
|
||||
if (dryRun) {
|
||||
log('info', 'DRY RUN MODE: No files will be modified');
|
||||
log('info', 'Would initialize Task Master project');
|
||||
log('info', 'Would create/update necessary project files');
|
||||
if (addAliasesPrompted) {
|
||||
if (addAliases) {
|
||||
log('info', 'Would add shell aliases for task-master');
|
||||
}
|
||||
if (!skipInstall) {
|
||||
log('info', 'Would install dependencies');
|
||||
}
|
||||
return {
|
||||
projectName,
|
||||
projectDescription,
|
||||
projectVersion,
|
||||
authorName,
|
||||
dryRun: true
|
||||
};
|
||||
}
|
||||
|
||||
// Create structure using only necessary values
|
||||
createProjectStructure(addAliasesPrompted);
|
||||
// Create the project structure
|
||||
createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases);
|
||||
|
||||
return {
|
||||
projectName,
|
||||
projectDescription,
|
||||
projectVersion,
|
||||
authorName
|
||||
};
|
||||
} catch (error) {
|
||||
// Make sure to close readline on error
|
||||
rl.close();
|
||||
log('error', `Error during prompting: ${error.message}`); // Use log function
|
||||
process.exit(1); // Exit on error during prompts
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,7 +483,7 @@ function promptQuestion(rl, question) {
|
||||
}
|
||||
|
||||
// Function to create the project structure
|
||||
function createProjectStructure(addAliases) {
|
||||
function createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases) {
|
||||
const targetDir = process.cwd();
|
||||
log('info', `Initializing project in ${targetDir}`);
|
||||
|
||||
@@ -451,142 +492,197 @@ function createProjectStructure(addAliases) {
|
||||
ensureDirectoryExists(path.join(targetDir, 'scripts'));
|
||||
ensureDirectoryExists(path.join(targetDir, 'tasks'));
|
||||
|
||||
// Define our package.json content
|
||||
const packageJson = {
|
||||
name: projectName.toLowerCase().replace(/\s+/g, '-'),
|
||||
version: projectVersion,
|
||||
description: projectDescription,
|
||||
author: authorName,
|
||||
type: "module",
|
||||
scripts: {
|
||||
"dev": "node scripts/dev.js",
|
||||
"list": "node scripts/dev.js list",
|
||||
"generate": "node scripts/dev.js generate",
|
||||
"parse-prd": "node scripts/dev.js parse-prd"
|
||||
},
|
||||
dependencies: {
|
||||
"@anthropic-ai/sdk": "^0.39.0",
|
||||
"boxen": "^8.0.1",
|
||||
"chalk": "^4.1.2",
|
||||
"commander": "^11.1.0",
|
||||
"cli-table3": "^0.6.5",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.21.2",
|
||||
"fastmcp": "^1.20.5",
|
||||
"figlet": "^1.8.0",
|
||||
"fuse.js": "^7.0.0",
|
||||
"gradient-string": "^3.0.0",
|
||||
"helmet": "^8.1.0",
|
||||
"inquirer": "^12.5.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lru-cache": "^10.2.0",
|
||||
"openai": "^4.89.0",
|
||||
"ora": "^8.2.0",
|
||||
"task-master-ai": "^0.9.31"
|
||||
}
|
||||
};
|
||||
|
||||
// Check if package.json exists and merge if it does
|
||||
const packageJsonPath = path.join(targetDir, 'package.json');
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
log('info', 'package.json already exists, merging content...');
|
||||
try {
|
||||
const existingPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
|
||||
// Preserve existing fields but add our required ones
|
||||
const mergedPackageJson = {
|
||||
...existingPackageJson,
|
||||
scripts: {
|
||||
...existingPackageJson.scripts,
|
||||
...Object.fromEntries(
|
||||
Object.entries(packageJson.scripts)
|
||||
.filter(([key]) => !existingPackageJson.scripts || !existingPackageJson.scripts[key])
|
||||
)
|
||||
},
|
||||
dependencies: {
|
||||
...existingPackageJson.dependencies || {},
|
||||
...Object.fromEntries(
|
||||
Object.entries(packageJson.dependencies)
|
||||
.filter(([key]) => !existingPackageJson.dependencies || !existingPackageJson.dependencies[key])
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
// Ensure type is set if not already present
|
||||
if (!mergedPackageJson.type && packageJson.type) {
|
||||
mergedPackageJson.type = packageJson.type;
|
||||
}
|
||||
|
||||
fs.writeFileSync(packageJsonPath, JSON.stringify(mergedPackageJson, null, 2));
|
||||
log('success', 'Updated package.json with required fields');
|
||||
} catch (error) {
|
||||
log('error', `Failed to merge package.json: ${error.message}`);
|
||||
// Create a backup before potentially modifying
|
||||
const backupPath = `${packageJsonPath}.backup-${Date.now()}`;
|
||||
fs.copyFileSync(packageJsonPath, backupPath);
|
||||
log('info', `Created backup of existing package.json at ${backupPath}`);
|
||||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
||||
log('warn', 'Created new package.json (backup of original file was created)');
|
||||
}
|
||||
} else {
|
||||
// If package.json doesn't exist, create it
|
||||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
||||
log('success', 'Created package.json');
|
||||
}
|
||||
|
||||
// Setup MCP configuration for integration with Cursor
|
||||
setupMCPConfiguration(targetDir);
|
||||
setupMCPConfiguration(targetDir, packageJson.name);
|
||||
|
||||
// Copy template files with replacements
|
||||
const replacements = {
|
||||
projectName,
|
||||
projectDescription,
|
||||
projectVersion,
|
||||
authorName,
|
||||
year: new Date().getFullYear()
|
||||
};
|
||||
|
||||
// Copy .env.example
|
||||
copyTemplateFile(
|
||||
'env.example',
|
||||
path.join(targetDir, '.env.example'),
|
||||
replacements
|
||||
);
|
||||
copyTemplateFile('env.example', path.join(targetDir, '.env.example'), replacements);
|
||||
|
||||
// Copy .gitignore
|
||||
copyTemplateFile('gitignore', path.join(targetDir, '.gitignore'));
|
||||
|
||||
// Copy dev_workflow.mdc
|
||||
copyTemplateFile(
|
||||
'dev_workflow.mdc',
|
||||
path.join(targetDir, '.cursor', 'rules', 'dev_workflow.mdc')
|
||||
);
|
||||
copyTemplateFile('dev_workflow.mdc', path.join(targetDir, '.cursor', 'rules', 'dev_workflow.mdc'));
|
||||
|
||||
// Copy taskmaster.mdc
|
||||
copyTemplateFile(
|
||||
'taskmaster.mdc',
|
||||
path.join(targetDir, '.cursor', 'rules', 'taskmaster.mdc')
|
||||
);
|
||||
copyTemplateFile('taskmaster.mdc', path.join(targetDir, '.cursor', 'rules', 'taskmaster.mdc'));
|
||||
|
||||
// Copy cursor_rules.mdc
|
||||
copyTemplateFile(
|
||||
'cursor_rules.mdc',
|
||||
path.join(targetDir, '.cursor', 'rules', 'cursor_rules.mdc')
|
||||
);
|
||||
copyTemplateFile('cursor_rules.mdc', path.join(targetDir, '.cursor', 'rules', 'cursor_rules.mdc'));
|
||||
|
||||
// Copy self_improve.mdc
|
||||
copyTemplateFile(
|
||||
'self_improve.mdc',
|
||||
path.join(targetDir, '.cursor', 'rules', 'self_improve.mdc')
|
||||
);
|
||||
copyTemplateFile('self_improve.mdc', path.join(targetDir, '.cursor', 'rules', 'self_improve.mdc'));
|
||||
|
||||
// Copy .windsurfrules
|
||||
copyTemplateFile('windsurfrules', path.join(targetDir, '.windsurfrules'));
|
||||
|
||||
// Copy scripts/dev.js
|
||||
copyTemplateFile('dev.js', path.join(targetDir, 'scripts', 'dev.js'));
|
||||
|
||||
// Copy scripts/README.md
|
||||
copyTemplateFile('scripts_README.md', path.join(targetDir, 'scripts', 'README.md'));
|
||||
|
||||
// Copy example_prd.txt
|
||||
copyTemplateFile(
|
||||
'example_prd.txt',
|
||||
path.join(targetDir, 'scripts', 'example_prd.txt')
|
||||
);
|
||||
copyTemplateFile('example_prd.txt', path.join(targetDir, 'scripts', 'example_prd.txt'));
|
||||
|
||||
// Create main README.md
|
||||
copyTemplateFile(
|
||||
'README-task-master.md',
|
||||
path.join(targetDir, 'README-task-master.md'),
|
||||
replacements
|
||||
);
|
||||
copyTemplateFile('README-task-master.md', path.join(targetDir, 'README.md'), replacements);
|
||||
|
||||
// Add shell aliases if requested
|
||||
if (addAliases) {
|
||||
addShellAliases();
|
||||
// Initialize git repository if git is available
|
||||
try {
|
||||
if (!fs.existsSync(path.join(targetDir, '.git'))) {
|
||||
log('info', 'Initializing git repository...');
|
||||
execSync('git init', { stdio: 'ignore' });
|
||||
log('success', 'Git repository initialized');
|
||||
}
|
||||
} catch (error) {
|
||||
log('warn', 'Git not available, skipping repository initialization');
|
||||
}
|
||||
|
||||
// Run npm install automatically
|
||||
console.log(boxen(chalk.cyan('Installing dependencies...'), {
|
||||
padding: 0.5,
|
||||
margin: 0.5,
|
||||
borderStyle: 'round',
|
||||
borderColor: 'blue'
|
||||
}));
|
||||
|
||||
try {
|
||||
if (!skipInstall) {
|
||||
execSync('npm install', { stdio: 'inherit', cwd: targetDir });
|
||||
log('success', 'Dependencies installed successfully!');
|
||||
} else {
|
||||
log('info', 'Dependencies installation skipped');
|
||||
}
|
||||
} catch (error) {
|
||||
log('error', 'Failed to install dependencies:', error.message);
|
||||
log('error', 'Please run npm install manually');
|
||||
}
|
||||
|
||||
// Display success message
|
||||
if (!isSilentMode()) {
|
||||
console.log(
|
||||
boxen(
|
||||
warmGradient.multiline(
|
||||
figlet.textSync('Success!', { font: 'Standard' })
|
||||
) +
|
||||
'\n' +
|
||||
chalk.green('Project initialized successfully!'),
|
||||
console.log(boxen(
|
||||
warmGradient.multiline(figlet.textSync('Success!', { font: 'Standard' })) +
|
||||
'\n' + chalk.green('Project initialized successfully!'),
|
||||
{
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
borderStyle: 'double',
|
||||
borderColor: 'green'
|
||||
}
|
||||
)
|
||||
);
|
||||
));
|
||||
|
||||
// Add shell aliases if requested
|
||||
if (addAliases) {
|
||||
addShellAliases();
|
||||
}
|
||||
|
||||
// Display next steps in a nice box
|
||||
if (!isSilentMode()) {
|
||||
console.log(
|
||||
boxen(
|
||||
chalk.cyan.bold('Things you can now do:') +
|
||||
'\n\n' +
|
||||
chalk.white('1. ') +
|
||||
chalk.yellow(
|
||||
'Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('2. ') +
|
||||
chalk.yellow(
|
||||
'Discuss your idea with AI, and once ready ask for a PRD using the example_prd.txt file, and save what you get to scripts/PRD.txt'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('3. ') +
|
||||
chalk.yellow(
|
||||
'Ask Cursor Agent to parse your PRD.txt and generate tasks'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white(' └─ ') +
|
||||
chalk.dim('You can also run ') +
|
||||
chalk.cyan('task-master parse-prd <your-prd-file.txt>') +
|
||||
'\n' +
|
||||
chalk.white('4. ') +
|
||||
chalk.yellow('Ask Cursor to analyze the complexity of your tasks') +
|
||||
'\n' +
|
||||
chalk.white('5. ') +
|
||||
chalk.yellow(
|
||||
'Ask Cursor which task is next to determine where to start'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('6. ') +
|
||||
chalk.yellow(
|
||||
'Ask Cursor to expand any complex tasks that are too large or complex.'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('7. ') +
|
||||
chalk.yellow(
|
||||
'Ask Cursor to set the status of a task, or multiple tasks. Use the task id from the task lists.'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('8. ') +
|
||||
chalk.yellow(
|
||||
'Ask Cursor to update all tasks from a specific task id based on new learnings or pivots in your project.'
|
||||
) +
|
||||
'\n' +
|
||||
chalk.white('9. ') +
|
||||
chalk.green.bold('Ship it!') +
|
||||
'\n\n' +
|
||||
chalk.dim(
|
||||
'* Review the README.md file to learn how to use other commands via Cursor Agent.'
|
||||
),
|
||||
console.log(boxen(
|
||||
chalk.cyan.bold('Things you can now do:') + '\n\n' +
|
||||
chalk.white('1. ') + chalk.yellow('Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY') + '\n' +
|
||||
chalk.white('2. ') + chalk.yellow('Discuss your idea with AI, and once ready ask for a PRD using the example_prd.txt file, and save what you get to scripts/PRD.txt') + '\n' +
|
||||
chalk.white('3. ') + chalk.yellow('Ask Cursor Agent to parse your PRD.txt and generate tasks') + '\n' +
|
||||
chalk.white(' └─ ') + chalk.dim('You can also run ') + chalk.cyan('task-master parse-prd <your-prd-file.txt>') + '\n' +
|
||||
chalk.white('4. ') + chalk.yellow('Ask Cursor to analyze the complexity of your tasks') + '\n' +
|
||||
chalk.white('5. ') + chalk.yellow('Ask Cursor which task is next to determine where to start') + '\n' +
|
||||
chalk.white('6. ') + chalk.yellow('Ask Cursor to expand any complex tasks that are too large or complex.') + '\n' +
|
||||
chalk.white('7. ') + chalk.yellow('Ask Cursor to set the status of a task, or multiple tasks. Use the task id from the task lists.') + '\n' +
|
||||
chalk.white('8. ') + chalk.yellow('Ask Cursor to update all tasks from a specific task id based on new learnings or pivots in your project.') + '\n' +
|
||||
chalk.white('9. ') + chalk.green.bold('Ship it!') + '\n\n' +
|
||||
chalk.dim('* Review the README.md file to learn how to use other commands via Cursor Agent.'),
|
||||
{
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
@@ -595,13 +691,11 @@ function createProjectStructure(addAliases) {
|
||||
title: 'Getting Started',
|
||||
titleAlignment: 'center'
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
// Function to setup MCP configuration for Cursor integration
|
||||
function setupMCPConfiguration(targetDir) {
|
||||
function setupMCPConfiguration(targetDir, projectName) {
|
||||
const mcpDirPath = path.join(targetDir, '.cursor');
|
||||
const mcpJsonPath = path.join(mcpDirPath, 'mcp.json');
|
||||
|
||||
@@ -612,28 +706,28 @@ function setupMCPConfiguration(targetDir) {
|
||||
|
||||
// New MCP config to be added - references the installed package
|
||||
const newMCPServer = {
|
||||
'task-master-ai': {
|
||||
command: 'npx',
|
||||
args: ['-y', 'task-master-mcp'],
|
||||
env: {
|
||||
ANTHROPIC_API_KEY: 'YOUR_ANTHROPIC_API_KEY',
|
||||
PERPLEXITY_API_KEY: 'YOUR_PERPLEXITY_API_KEY',
|
||||
MODEL: 'claude-3-7-sonnet-20250219',
|
||||
PERPLEXITY_MODEL: 'sonar-pro',
|
||||
MAX_TOKENS: '64000',
|
||||
TEMPERATURE: '0.2',
|
||||
DEFAULT_SUBTASKS: '5',
|
||||
DEFAULT_PRIORITY: 'medium'
|
||||
"task-master-ai": {
|
||||
"command": "npx",
|
||||
"args": [
|
||||
"-y",
|
||||
"task-master-mcp-server"
|
||||
],
|
||||
"env": {
|
||||
"ANTHROPIC_API_KEY": "%ANTHROPIC_API_KEY%",
|
||||
"PERPLEXITY_API_KEY": "%PERPLEXITY_API_KEY%",
|
||||
"MODEL": "claude-3-7-sonnet-20250219",
|
||||
"PERPLEXITY_MODEL": "sonar-pro",
|
||||
"MAX_TOKENS": 64000,
|
||||
"TEMPERATURE": 0.3,
|
||||
"DEFAULT_SUBTASKS": 5,
|
||||
"DEFAULT_PRIORITY": "medium"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Check if mcp.json already exists
|
||||
if (fs.existsSync(mcpJsonPath)) {
|
||||
log(
|
||||
'info',
|
||||
'MCP configuration file already exists, checking for existing task-master-mcp...'
|
||||
);
|
||||
log('info', 'MCP configuration file already exists, updating...');
|
||||
try {
|
||||
// Read existing config
|
||||
const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8'));
|
||||
@@ -643,36 +737,19 @@ function setupMCPConfiguration(targetDir) {
|
||||
mcpConfig.mcpServers = {};
|
||||
}
|
||||
|
||||
// Check if any existing server configuration already has task-master-mcp in its args
|
||||
const hasMCPString = Object.values(mcpConfig.mcpServers).some(
|
||||
(server) =>
|
||||
server.args &&
|
||||
server.args.some(
|
||||
(arg) => typeof arg === 'string' && arg.includes('task-master-mcp')
|
||||
)
|
||||
);
|
||||
|
||||
if (hasMCPString) {
|
||||
log(
|
||||
'info',
|
||||
'Found existing task-master-mcp configuration in mcp.json, leaving untouched'
|
||||
);
|
||||
return; // Exit early, don't modify the existing configuration
|
||||
}
|
||||
|
||||
// Add the task-master-ai server if it doesn't exist
|
||||
if (!mcpConfig.mcpServers['task-master-ai']) {
|
||||
mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];
|
||||
log(
|
||||
'info',
|
||||
'Added task-master-ai server to existing MCP configuration'
|
||||
);
|
||||
if (!mcpConfig.mcpServers["task-master-ai"]) {
|
||||
mcpConfig.mcpServers["task-master-ai"] = newMCPServer["task-master-ai"];
|
||||
log('info', 'Added task-master-ai server to existing MCP configuration');
|
||||
} else {
|
||||
log('info', 'task-master-ai server already configured in mcp.json');
|
||||
}
|
||||
|
||||
// Write the updated configuration
|
||||
fs.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 4));
|
||||
fs.writeFileSync(
|
||||
mcpJsonPath,
|
||||
JSON.stringify(mcpConfig, null, 4)
|
||||
);
|
||||
log('success', 'Updated MCP configuration file');
|
||||
} catch (error) {
|
||||
log('error', `Failed to update MCP configuration: ${error.message}`);
|
||||
@@ -685,19 +762,16 @@ function setupMCPConfiguration(targetDir) {
|
||||
|
||||
// Create new configuration
|
||||
const newMCPConfig = {
|
||||
mcpServers: newMCPServer
|
||||
"mcpServers": newMCPServer
|
||||
};
|
||||
|
||||
fs.writeFileSync(mcpJsonPath, JSON.stringify(newMCPConfig, null, 4));
|
||||
log(
|
||||
'warn',
|
||||
'Created new MCP configuration file (backup of original file was created if it existed)'
|
||||
);
|
||||
log('warn', 'Created new MCP configuration file (backup of original file was created if it existed)');
|
||||
}
|
||||
} else {
|
||||
// If mcp.json doesn't exist, create it
|
||||
const newMCPConfig = {
|
||||
mcpServers: newMCPServer
|
||||
"mcpServers": newMCPServer
|
||||
};
|
||||
|
||||
fs.writeFileSync(mcpJsonPath, JSON.stringify(newMCPConfig, null, 4));
|
||||
@@ -708,5 +782,53 @@ function setupMCPConfiguration(targetDir) {
|
||||
log('info', 'MCP server will use the installed task-master-ai package');
|
||||
}
|
||||
|
||||
// Ensure necessary functions are exported
|
||||
export { initializeProject, log }; // Only export what's needed by commands.js
|
||||
// Run the initialization if this script is executed directly
|
||||
// The original check doesn't work with npx and global commands
|
||||
// if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
// Instead, we'll always run the initialization if this file is the main module
|
||||
console.log('Checking if script should run initialization...');
|
||||
console.log('import.meta.url:', import.meta.url);
|
||||
console.log('process.argv:', process.argv);
|
||||
|
||||
// Always run initialization when this file is loaded directly
|
||||
// This works with both direct node execution and npx/global commands
|
||||
(async function main() {
|
||||
try {
|
||||
console.log('Starting initialization...');
|
||||
|
||||
// Check if we should use the CLI options or prompt for input
|
||||
if (options.yes || (options.name && options.description)) {
|
||||
// When using --yes flag or providing name and description, use CLI options
|
||||
await initializeProject({
|
||||
projectName: options.name || 'task-master-project',
|
||||
projectDescription: options.description || 'A task management system for AI-driven development',
|
||||
projectVersion: options.version || '1.0.0',
|
||||
authorName: options.author || '',
|
||||
dryRun: options.dryRun || false,
|
||||
skipInstall: options.skipInstall || false,
|
||||
addAliases: options.aliases || false
|
||||
});
|
||||
} else {
|
||||
// Otherwise, prompt for input normally
|
||||
await initializeProject({
|
||||
dryRun: options.dryRun || false,
|
||||
skipInstall: options.skipInstall || false
|
||||
});
|
||||
}
|
||||
|
||||
// Process should exit naturally after completion
|
||||
console.log('Initialization completed, exiting...');
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize project:', error);
|
||||
log('error', 'Failed to initialize project:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
||||
// Export functions for programmatic use
|
||||
export {
|
||||
initializeProject,
|
||||
createProjectStructure,
|
||||
log
|
||||
};
|
||||
@@ -34,13 +34,11 @@ let perplexity = null;
|
||||
function getPerplexityClient() {
|
||||
if (!perplexity) {
|
||||
if (!process.env.PERPLEXITY_API_KEY) {
|
||||
throw new Error(
|
||||
'PERPLEXITY_API_KEY environment variable is missing. Set it to use research-backed features.'
|
||||
);
|
||||
throw new Error("PERPLEXITY_API_KEY environment variable is missing. Set it to use research-backed features.");
|
||||
}
|
||||
perplexity = new OpenAI({
|
||||
apiKey: process.env.PERPLEXITY_API_KEY,
|
||||
baseURL: 'https://api.perplexity.ai'
|
||||
baseURL: 'https://api.perplexity.ai',
|
||||
});
|
||||
}
|
||||
return perplexity;
|
||||
@@ -87,18 +85,13 @@ function getAvailableAIModel(options = {}) {
|
||||
// Last resort: Use Claude even if overloaded (might fail)
|
||||
if (process.env.ANTHROPIC_API_KEY) {
|
||||
if (claudeOverloaded) {
|
||||
log(
|
||||
'warn',
|
||||
'Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.'
|
||||
);
|
||||
log('warn', 'Claude is overloaded but no alternatives are available. Proceeding with Claude anyway.');
|
||||
}
|
||||
return { type: 'claude', client: anthropic };
|
||||
}
|
||||
|
||||
// No models available
|
||||
throw new Error(
|
||||
'No AI models available. Please set ANTHROPIC_API_KEY and/or PERPLEXITY_API_KEY.'
|
||||
);
|
||||
throw new Error('No AI models available. Please set ANTHROPIC_API_KEY and/or PERPLEXITY_API_KEY.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,34 +144,15 @@ function handleClaudeError(error) {
|
||||
* @param {Object} modelConfig - Model configuration (optional)
|
||||
* @returns {Object} Claude's response
|
||||
*/
|
||||
async function callClaude(
|
||||
prdContent,
|
||||
prdPath,
|
||||
numTasks,
|
||||
retryCount = 0,
|
||||
{ reportProgress, mcpLog, session } = {},
|
||||
aiClient = null,
|
||||
modelConfig = null
|
||||
) {
|
||||
async function callClaude(prdContent, prdPath, numTasks, retryCount = 0, { reportProgress, mcpLog, session } = {}, aiClient = null, modelConfig = null) {
|
||||
try {
|
||||
log('info', 'Calling Claude...');
|
||||
|
||||
// Build the system prompt
|
||||
const systemPrompt = `You are an AI assistant tasked with breaking down a Product Requirements Document (PRD) into a set of sequential development tasks. Your goal is to create exactly <num_tasks>${numTasks}</num_tasks> well-structured, actionable development tasks based on the PRD provided.
|
||||
|
||||
First, carefully read and analyze the attached PRD
|
||||
|
||||
Before creating the task list, work through the following steps inside <prd_breakdown> tags in your thinking block:
|
||||
|
||||
1. List the key components of the PRD
|
||||
2. Identify the main features and functionalities described
|
||||
3. Note any specific technical requirements or constraints mentioned
|
||||
4. Outline a high-level sequence of tasks that would be needed to implement the PRD
|
||||
|
||||
Consider dependencies, maintainability, and the fact that you don't have access to any existing codebase. Balance between providing detailed task descriptions and maintaining a high-level perspective.
|
||||
|
||||
After your breakdown, create a JSON object containing an array of tasks and a metadata object. Each task should follow this structure:
|
||||
const systemPrompt = `You are an AI assistant helping to break down a Product Requirements Document (PRD) into a set of sequential development tasks.
|
||||
Your goal is to create ${numTasks} well-structured, actionable development tasks based on the PRD provided.
|
||||
|
||||
Each task should follow this JSON structure:
|
||||
{
|
||||
"id": number,
|
||||
"title": string,
|
||||
@@ -190,46 +164,39 @@ After your breakdown, create a JSON object containing an array of tasks and a me
|
||||
"testStrategy": string (validation approach)
|
||||
}
|
||||
|
||||
Guidelines for creating tasks:
|
||||
1. Number tasks from 1 to <num_tasks>${numTasks}</num_tasks>.
|
||||
2. Make each task atomic and focused on a single responsibility.
|
||||
3. Order tasks logically, considering dependencies and implementation sequence.
|
||||
4. Start with setup and core functionality, then move to advanced features.
|
||||
5. Provide a clear validation/testing approach for each task.
|
||||
6. Set appropriate dependency IDs (tasks can only depend on lower-numbered tasks).
|
||||
7. Assign priority based on criticality and dependency order.
|
||||
8. Include detailed implementation guidance in the "details" field.
|
||||
9. Strictly adhere to any specific requirements for libraries, database schemas, frameworks, tech stacks, or other implementation details mentioned in the PRD.
|
||||
10. Fill in gaps left by the PRD while preserving all explicit requirements.
|
||||
11. Provide the most direct path to implementation, avoiding over-engineering.
|
||||
|
||||
The final output should be valid JSON with this structure:
|
||||
Guidelines:
|
||||
1. Create exactly ${numTasks} tasks, numbered from 1 to ${numTasks}
|
||||
2. Each task should be atomic and focused on a single responsibility
|
||||
3. Order tasks logically - consider dependencies and implementation sequence
|
||||
4. Early tasks should focus on setup, core functionality first, then advanced features
|
||||
5. Include clear validation/testing approach for each task
|
||||
6. Set appropriate dependency IDs (a task can only depend on tasks with lower IDs)
|
||||
7. Assign priority (high/medium/low) based on criticality and dependency order
|
||||
8. Include detailed implementation guidance in the "details" field
|
||||
9. If the PRD contains specific requirements for libraries, database schemas, frameworks, tech stacks, or any other implementation details, STRICTLY ADHERE to these requirements in your task breakdown and do not discard them under any circumstance
|
||||
10. Focus on filling in any gaps left by the PRD or areas that aren't fully specified, while preserving all explicit requirements
|
||||
11. Always aim to provide the most direct path to implementation, avoiding over-engineering or roundabout approaches
|
||||
|
||||
Expected output format:
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Example Task Title",
|
||||
"description": "Brief description of the task",
|
||||
"status": "pending",
|
||||
"dependencies": [0],
|
||||
"priority": "high",
|
||||
"details": "Detailed implementation guidance",
|
||||
"testStrategy": "Approach for validating this task"
|
||||
"title": "Setup Project Repository",
|
||||
"description": "...",
|
||||
...
|
||||
},
|
||||
// ... more tasks ...
|
||||
...
|
||||
],
|
||||
"metadata": {
|
||||
"projectName": "PRD Implementation",
|
||||
"totalTasks": <num_tasks>${numTasks}</num_tasks>,
|
||||
"sourceFile": "<prd_path>${prdPath}</prd_path>",
|
||||
"totalTasks": ${numTasks},
|
||||
"sourceFile": "${prdPath}",
|
||||
"generatedAt": "YYYY-MM-DD"
|
||||
}
|
||||
}
|
||||
|
||||
Remember to provide comprehensive task details that are LLM-friendly, consider dependencies and maintainability carefully, and keep in mind that you don't have the existing codebase as context. Aim for a balance between detailed guidance and high-level planning.
|
||||
|
||||
Your response should be valid JSON only, with no additional explanation or comments. Do not duplicate or rehash any of the work you did in the prd_breakdown section in your final output.`;
|
||||
Important: Your response must be valid JSON only, with no additional explanation or comments.`;
|
||||
|
||||
// Use streaming request to handle large responses and show progress
|
||||
return await handleStreamingRequest(
|
||||
@@ -248,28 +215,16 @@ Your response should be valid JSON only, with no additional explanation or comme
|
||||
log('error', userMessage);
|
||||
|
||||
// Retry logic for certain errors
|
||||
if (
|
||||
retryCount < 2 &&
|
||||
(error.error?.type === 'overloaded_error' ||
|
||||
if (retryCount < 2 && (
|
||||
error.error?.type === 'overloaded_error' ||
|
||||
error.error?.type === 'rate_limit_error' ||
|
||||
error.message?.toLowerCase().includes('timeout') ||
|
||||
error.message?.toLowerCase().includes('network'))
|
||||
) {
|
||||
error.message?.toLowerCase().includes('network')
|
||||
)) {
|
||||
const waitTime = (retryCount + 1) * 5000; // 5s, then 10s
|
||||
log(
|
||||
'info',
|
||||
`Waiting ${waitTime / 1000} seconds before retry ${retryCount + 1}/2...`
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
||||
return await callClaude(
|
||||
prdContent,
|
||||
prdPath,
|
||||
numTasks,
|
||||
retryCount + 1,
|
||||
{ reportProgress, mcpLog, session },
|
||||
aiClient,
|
||||
modelConfig
|
||||
);
|
||||
log('info', `Waiting ${waitTime/1000} seconds before retry ${retryCount + 1}/2...`);
|
||||
await new Promise(resolve => setTimeout(resolve, waitTime));
|
||||
return await callClaude(prdContent, prdPath, numTasks, retryCount + 1, { reportProgress, mcpLog, session }, aiClient, modelConfig);
|
||||
} else {
|
||||
console.error(chalk.red(userMessage));
|
||||
if (CONFIG.debug) {
|
||||
@@ -295,16 +250,7 @@ Your response should be valid JSON only, with no additional explanation or comme
|
||||
* @param {Object} modelConfig - Model configuration (optional)
|
||||
* @returns {Object} Claude's response
|
||||
*/
|
||||
async function handleStreamingRequest(
|
||||
prdContent,
|
||||
prdPath,
|
||||
numTasks,
|
||||
maxTokens,
|
||||
systemPrompt,
|
||||
{ reportProgress, mcpLog, session } = {},
|
||||
aiClient = null,
|
||||
modelConfig = null
|
||||
) {
|
||||
async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens, systemPrompt, { reportProgress, mcpLog, session } = {}, aiClient = null, modelConfig = null) {
|
||||
// Determine output format based on mcpLog presence
|
||||
const outputFormat = mcpLog ? 'json' : 'text';
|
||||
|
||||
@@ -324,23 +270,16 @@ async function handleStreamingRequest(
|
||||
loadingIndicator = startLoadingIndicator('Generating tasks from PRD...');
|
||||
}
|
||||
|
||||
if (reportProgress) {
|
||||
await reportProgress({ progress: 0 });
|
||||
}
|
||||
if (reportProgress) { await reportProgress({ progress: 0 }); }
|
||||
let responseText = '';
|
||||
let streamingInterval = null;
|
||||
|
||||
try {
|
||||
// Use streaming for handling large responses
|
||||
const stream = await (aiClient || anthropic).messages.create({
|
||||
model:
|
||||
modelConfig?.model || session?.env?.ANTHROPIC_MODEL || CONFIG.model,
|
||||
max_tokens:
|
||||
modelConfig?.maxTokens || session?.env?.MAX_TOKENS || maxTokens,
|
||||
temperature:
|
||||
modelConfig?.temperature ||
|
||||
session?.env?.TEMPERATURE ||
|
||||
CONFIG.temperature,
|
||||
model: modelConfig?.model || session?.env?.ANTHROPIC_MODEL || CONFIG.model,
|
||||
max_tokens: modelConfig?.maxTokens || session?.env?.MAX_TOKENS || maxTokens,
|
||||
temperature: modelConfig?.temperature || session?.env?.TEMPERATURE || CONFIG.temperature,
|
||||
system: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
@@ -357,9 +296,7 @@ async function handleStreamingRequest(
|
||||
const readline = await import('readline');
|
||||
streamingInterval = setInterval(() => {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Receiving streaming response from Claude${'.'.repeat(dotCount)}`
|
||||
);
|
||||
process.stdout.write(`Receiving streaming response from Claude${'.'.repeat(dotCount)}`);
|
||||
dotCount = (dotCount + 1) % 4;
|
||||
}, 500);
|
||||
}
|
||||
@@ -370,12 +307,10 @@ async function handleStreamingRequest(
|
||||
responseText += chunk.delta.text;
|
||||
}
|
||||
if (reportProgress) {
|
||||
await reportProgress({
|
||||
progress: (responseText.length / maxTokens) * 100
|
||||
});
|
||||
await reportProgress({ progress: (responseText.length / maxTokens) * 100 });
|
||||
}
|
||||
if (mcpLog) {
|
||||
mcpLog.info(`Progress: ${(responseText.length / maxTokens) * 100}%`);
|
||||
mcpLog.info(`Progress: ${responseText.length / maxTokens * 100}%`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,20 +321,10 @@ async function handleStreamingRequest(
|
||||
stopLoadingIndicator(loadingIndicator);
|
||||
}
|
||||
|
||||
report(
|
||||
`Completed streaming response from ${aiClient ? 'provided' : 'default'} AI client!`,
|
||||
'info'
|
||||
);
|
||||
report(`Completed streaming response from ${aiClient ? 'provided' : 'default'} AI client!`, 'info');
|
||||
|
||||
// Pass options to processClaudeResponse
|
||||
return processClaudeResponse(
|
||||
responseText,
|
||||
numTasks,
|
||||
0,
|
||||
prdContent,
|
||||
prdPath,
|
||||
{ reportProgress, mcpLog, session }
|
||||
);
|
||||
return processClaudeResponse(responseText, numTasks, 0, prdContent, prdPath, { reportProgress, mcpLog, session });
|
||||
} catch (error) {
|
||||
if (streamingInterval) clearInterval(streamingInterval);
|
||||
|
||||
@@ -435,14 +360,7 @@ async function handleStreamingRequest(
|
||||
* @param {Object} options - Options object containing mcpLog etc.
|
||||
* @returns {Object} Processed response
|
||||
*/
|
||||
function processClaudeResponse(
|
||||
textContent,
|
||||
numTasks,
|
||||
retryCount,
|
||||
prdContent,
|
||||
prdPath,
|
||||
options = {}
|
||||
) {
|
||||
function processClaudeResponse(textContent, numTasks, retryCount, prdContent, prdPath, options = {}) {
|
||||
const { mcpLog } = options;
|
||||
|
||||
// Determine output format based on mcpLog presence
|
||||
@@ -477,16 +395,13 @@ function processClaudeResponse(
|
||||
|
||||
// Ensure we have the correct number of tasks
|
||||
if (parsedData.tasks.length !== numTasks) {
|
||||
report(
|
||||
`Expected ${numTasks} tasks, but received ${parsedData.tasks.length}`,
|
||||
'warn'
|
||||
);
|
||||
report(`Expected ${numTasks} tasks, but received ${parsedData.tasks.length}`, 'warn');
|
||||
}
|
||||
|
||||
// Add metadata if missing
|
||||
if (!parsedData.metadata) {
|
||||
parsedData.metadata = {
|
||||
projectName: 'PRD Implementation',
|
||||
projectName: "PRD Implementation",
|
||||
totalTasks: parsedData.tasks.length,
|
||||
sourceFile: prdPath,
|
||||
generatedAt: new Date().toISOString().split('T')[0]
|
||||
@@ -503,24 +418,11 @@ function processClaudeResponse(
|
||||
|
||||
// Try again with Claude for a cleaner response
|
||||
if (retryCount === 1) {
|
||||
report('Calling Claude again for a cleaner response...', 'info');
|
||||
return callClaude(
|
||||
prdContent,
|
||||
prdPath,
|
||||
numTasks,
|
||||
retryCount + 1,
|
||||
options
|
||||
);
|
||||
report("Calling Claude again for a cleaner response...", 'info');
|
||||
return callClaude(prdContent, prdPath, numTasks, retryCount + 1, options);
|
||||
}
|
||||
|
||||
return processClaudeResponse(
|
||||
textContent,
|
||||
numTasks,
|
||||
retryCount + 1,
|
||||
prdContent,
|
||||
prdPath,
|
||||
options
|
||||
);
|
||||
return processClaudeResponse(textContent, numTasks, retryCount + 1, prdContent, prdPath, options);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -539,22 +441,11 @@ function processClaudeResponse(
|
||||
* - session: Session object from MCP server (optional)
|
||||
* @returns {Array} Generated subtasks
|
||||
*/
|
||||
async function generateSubtasks(
|
||||
task,
|
||||
numSubtasks,
|
||||
nextSubtaskId,
|
||||
additionalContext = '',
|
||||
{ reportProgress, mcpLog, session } = {}
|
||||
) {
|
||||
async function generateSubtasks(task, numSubtasks, nextSubtaskId, additionalContext = '', { reportProgress, mcpLog, session } = {}) {
|
||||
try {
|
||||
log(
|
||||
'info',
|
||||
`Generating ${numSubtasks} subtasks for task ${task.id}: ${task.title}`
|
||||
);
|
||||
log('info', `Generating ${numSubtasks} subtasks for task ${task.id}: ${task.title}`);
|
||||
|
||||
const loadingIndicator = startLoadingIndicator(
|
||||
`Generating subtasks for task ${task.id}...`
|
||||
);
|
||||
const loadingIndicator = startLoadingIndicator(`Generating subtasks for task ${task.id}...`);
|
||||
let streamingInterval = null;
|
||||
let responseText = '';
|
||||
|
||||
@@ -577,9 +468,8 @@ For each subtask, provide:
|
||||
|
||||
Each subtask should be implementable in a focused coding session.`;
|
||||
|
||||
const contextPrompt = additionalContext
|
||||
? `\n\nAdditional context to consider: ${additionalContext}`
|
||||
: '';
|
||||
const contextPrompt = additionalContext ?
|
||||
`\n\nAdditional context to consider: ${additionalContext}` : '';
|
||||
|
||||
const userPrompt = `Please break down this task into ${numSubtasks} specific, actionable subtasks:
|
||||
|
||||
@@ -609,9 +499,7 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
const readline = await import('readline');
|
||||
streamingInterval = setInterval(() => {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Generating subtasks for task ${task.id}${'.'.repeat(dotCount)}`
|
||||
);
|
||||
process.stdout.write(`Generating subtasks for task ${task.id}${'.'.repeat(dotCount)}`);
|
||||
dotCount = (dotCount + 1) % 4;
|
||||
}, 500);
|
||||
|
||||
@@ -638,14 +526,10 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
responseText += chunk.delta.text;
|
||||
}
|
||||
if (reportProgress) {
|
||||
await reportProgress({
|
||||
progress: (responseText.length / CONFIG.maxTokens) * 100
|
||||
});
|
||||
await reportProgress({ progress: (responseText.length / CONFIG.maxTokens) * 100 });
|
||||
}
|
||||
if (mcpLog) {
|
||||
mcpLog.info(
|
||||
`Progress: ${(responseText.length / CONFIG.maxTokens) * 100}%`
|
||||
);
|
||||
mcpLog.info(`Progress: ${responseText.length / CONFIG.maxTokens * 100}%`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,12 +538,7 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
|
||||
log('info', `Completed generating subtasks for task ${task.id}`);
|
||||
|
||||
return parseSubtasksFromText(
|
||||
responseText,
|
||||
nextSubtaskId,
|
||||
numSubtasks,
|
||||
task.id
|
||||
);
|
||||
return parseSubtasksFromText(responseText, nextSubtaskId, numSubtasks, task.id);
|
||||
} catch (error) {
|
||||
if (streamingInterval) clearInterval(streamingInterval);
|
||||
stopLoadingIndicator(loadingIndicator);
|
||||
@@ -684,38 +563,26 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
* - session: Session object from MCP server (optional)
|
||||
* @returns {Array} Generated subtasks
|
||||
*/
|
||||
async function generateSubtasksWithPerplexity(
|
||||
task,
|
||||
numSubtasks = 3,
|
||||
nextSubtaskId = 1,
|
||||
additionalContext = '',
|
||||
{ reportProgress, mcpLog, silentMode, session } = {}
|
||||
) {
|
||||
async function generateSubtasksWithPerplexity(task, numSubtasks = 3, nextSubtaskId = 1, additionalContext = '', { reportProgress, mcpLog, silentMode, session } = {}) {
|
||||
// Check both global silentMode and the passed parameter
|
||||
const isSilent =
|
||||
silentMode || (typeof silentMode === 'undefined' && isSilentMode());
|
||||
const isSilent = silentMode || (typeof silentMode === 'undefined' && isSilentMode());
|
||||
|
||||
// Use mcpLog if provided, otherwise use regular log if not silent
|
||||
const logFn = mcpLog
|
||||
? (level, ...args) => mcpLog[level](...args)
|
||||
: (level, ...args) => !isSilent && log(level, ...args);
|
||||
const logFn = mcpLog ?
|
||||
(level, ...args) => mcpLog[level](...args) :
|
||||
(level, ...args) => !isSilent && log(level, ...args);
|
||||
|
||||
try {
|
||||
// First, perform research to get context
|
||||
logFn('info', `Researching context for task ${task.id}: ${task.title}`);
|
||||
const perplexityClient = getPerplexityClient();
|
||||
|
||||
const PERPLEXITY_MODEL =
|
||||
process.env.PERPLEXITY_MODEL ||
|
||||
session?.env?.PERPLEXITY_MODEL ||
|
||||
'sonar-pro';
|
||||
const PERPLEXITY_MODEL = process.env.PERPLEXITY_MODEL || session?.env?.PERPLEXITY_MODEL || 'sonar-pro';
|
||||
|
||||
// Only create loading indicators if not in silent mode
|
||||
let researchLoadingIndicator = null;
|
||||
if (!isSilent) {
|
||||
researchLoadingIndicator = startLoadingIndicator(
|
||||
'Researching best practices with Perplexity AI...'
|
||||
);
|
||||
researchLoadingIndicator = startLoadingIndicator('Researching best practices with Perplexity AI...');
|
||||
}
|
||||
|
||||
// Formulate research query based on task
|
||||
@@ -726,12 +593,10 @@ Include concrete code examples and technical considerations where relevant.`;
|
||||
// Query Perplexity for research
|
||||
const researchResponse = await perplexityClient.chat.completions.create({
|
||||
model: PERPLEXITY_MODEL,
|
||||
messages: [
|
||||
{
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: researchQuery
|
||||
}
|
||||
],
|
||||
}],
|
||||
temperature: 0.1 // Lower temperature for more factual responses
|
||||
});
|
||||
|
||||
@@ -742,10 +607,7 @@ Include concrete code examples and technical considerations where relevant.`;
|
||||
stopLoadingIndicator(researchLoadingIndicator);
|
||||
}
|
||||
|
||||
logFn(
|
||||
'info',
|
||||
'Research completed, now generating subtasks with additional context'
|
||||
);
|
||||
logFn('info', 'Research completed, now generating subtasks with additional context');
|
||||
|
||||
// Use the research result as additional context for Claude to generate subtasks
|
||||
const combinedContext = `
|
||||
@@ -753,15 +615,13 @@ RESEARCH FINDINGS:
|
||||
${researchResult}
|
||||
|
||||
ADDITIONAL CONTEXT PROVIDED BY USER:
|
||||
${additionalContext || 'No additional context provided.'}
|
||||
${additionalContext || "No additional context provided."}
|
||||
`;
|
||||
|
||||
// Now generate subtasks with Claude
|
||||
let loadingIndicator = null;
|
||||
if (!isSilent) {
|
||||
loadingIndicator = startLoadingIndicator(
|
||||
`Generating research-backed subtasks for task ${task.id}...`
|
||||
);
|
||||
loadingIndicator = startLoadingIndicator(`Generating research-backed subtasks for task ${task.id}...`);
|
||||
}
|
||||
|
||||
let streamingInterval = null;
|
||||
@@ -820,9 +680,7 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
const readline = await import('readline');
|
||||
streamingInterval = setInterval(() => {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Generating research-backed subtasks for task ${task.id}${'.'.repeat(dotCount)}`
|
||||
);
|
||||
process.stdout.write(`Generating research-backed subtasks for task ${task.id}${'.'.repeat(dotCount)}`);
|
||||
dotCount = (dotCount + 1) % 4;
|
||||
}, 500);
|
||||
}
|
||||
@@ -852,17 +710,9 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
loadingIndicator = null;
|
||||
}
|
||||
|
||||
logFn(
|
||||
'info',
|
||||
`Completed generating research-backed subtasks for task ${task.id}`
|
||||
);
|
||||
logFn('info', `Completed generating research-backed subtasks for task ${task.id}`);
|
||||
|
||||
return parseSubtasksFromText(
|
||||
responseText,
|
||||
nextSubtaskId,
|
||||
numSubtasks,
|
||||
task.id
|
||||
);
|
||||
return parseSubtasksFromText(responseText, nextSubtaskId, numSubtasks, task.id);
|
||||
} catch (error) {
|
||||
// Clean up on error
|
||||
if (streamingInterval) {
|
||||
@@ -876,10 +726,7 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
logFn(
|
||||
'error',
|
||||
`Error generating research-backed subtasks: ${error.message}`
|
||||
);
|
||||
logFn('error', `Error generating research-backed subtasks: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -891,68 +738,42 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
||||
* @param {number} expectedCount - Expected number of subtasks
|
||||
* @param {number} parentTaskId - Parent task ID
|
||||
* @returns {Array} Parsed subtasks
|
||||
* @throws {Error} If parsing fails or JSON is invalid
|
||||
*/
|
||||
function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
||||
// Set default values for optional parameters
|
||||
startId = startId || 1;
|
||||
expectedCount = expectedCount || 2; // Default to 2 subtasks if not specified
|
||||
|
||||
// Handle empty text case
|
||||
if (!text || text.trim() === '') {
|
||||
throw new Error('Empty text provided, cannot parse subtasks');
|
||||
}
|
||||
|
||||
try {
|
||||
// Locate JSON array in the text
|
||||
const jsonStartIndex = text.indexOf('[');
|
||||
const jsonEndIndex = text.lastIndexOf(']');
|
||||
|
||||
// If no valid JSON array found, throw error
|
||||
if (
|
||||
jsonStartIndex === -1 ||
|
||||
jsonEndIndex === -1 ||
|
||||
jsonEndIndex < jsonStartIndex
|
||||
) {
|
||||
throw new Error('Could not locate valid JSON array in the response');
|
||||
if (jsonStartIndex === -1 || jsonEndIndex === -1 || jsonEndIndex < jsonStartIndex) {
|
||||
throw new Error("Could not locate valid JSON array in the response");
|
||||
}
|
||||
|
||||
// Extract and parse the JSON
|
||||
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
|
||||
let subtasks;
|
||||
let subtasks = JSON.parse(jsonText);
|
||||
|
||||
try {
|
||||
subtasks = JSON.parse(jsonText);
|
||||
} catch (parseError) {
|
||||
throw new Error(`Failed to parse JSON: ${parseError.message}`);
|
||||
}
|
||||
|
||||
// Validate array
|
||||
// Validate
|
||||
if (!Array.isArray(subtasks)) {
|
||||
throw new Error('Parsed content is not an array');
|
||||
throw new Error("Parsed content is not an array");
|
||||
}
|
||||
|
||||
// Log warning if count doesn't match expected
|
||||
if (expectedCount && subtasks.length !== expectedCount) {
|
||||
log(
|
||||
'warn',
|
||||
`Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`
|
||||
);
|
||||
if (subtasks.length !== expectedCount) {
|
||||
log('warn', `Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`);
|
||||
}
|
||||
|
||||
// Normalize subtask IDs if they don't match
|
||||
subtasks = subtasks.map((subtask, index) => {
|
||||
// Assign the correct ID if it doesn't match
|
||||
if (!subtask.id || subtask.id !== startId + index) {
|
||||
log(
|
||||
'warn',
|
||||
`Correcting subtask ID from ${subtask.id || 'undefined'} to ${startId + index}`
|
||||
);
|
||||
if (subtask.id !== startId + index) {
|
||||
log('warn', `Correcting subtask ID from ${subtask.id} to ${startId + index}`);
|
||||
subtask.id = startId + index;
|
||||
}
|
||||
|
||||
// Convert dependencies to numbers if they are strings
|
||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
||||
subtask.dependencies = subtask.dependencies.map((dep) => {
|
||||
subtask.dependencies = subtask.dependencies.map(dep => {
|
||||
return typeof dep === 'string' ? parseInt(dep, 10) : dep;
|
||||
});
|
||||
} else {
|
||||
@@ -962,15 +783,35 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
||||
// Ensure status is 'pending'
|
||||
subtask.status = 'pending';
|
||||
|
||||
// Add parentTaskId if provided
|
||||
if (parentTaskId) {
|
||||
// Add parentTaskId
|
||||
subtask.parentTaskId = parentTaskId;
|
||||
}
|
||||
|
||||
return subtask;
|
||||
});
|
||||
|
||||
return subtasks;
|
||||
} catch (error) {
|
||||
log('error', `Error parsing subtasks: ${error.message}`);
|
||||
|
||||
// Create a fallback array of empty subtasks if parsing fails
|
||||
log('warn', 'Creating fallback subtasks');
|
||||
|
||||
const fallbackSubtasks = [];
|
||||
|
||||
for (let i = 0; i < expectedCount; i++) {
|
||||
fallbackSubtasks.push({
|
||||
id: startId + i,
|
||||
title: `Subtask ${startId + i}`,
|
||||
description: "Auto-generated fallback subtask",
|
||||
dependencies: [],
|
||||
details: "This is a fallback subtask created because parsing failed. Please update with real details.",
|
||||
status: 'pending',
|
||||
parentTaskId: parentTaskId
|
||||
});
|
||||
}
|
||||
|
||||
return fallbackSubtasks;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -981,18 +822,14 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
||||
function generateComplexityAnalysisPrompt(tasksData) {
|
||||
return `Analyze the complexity of the following tasks and provide recommendations for subtask breakdown:
|
||||
|
||||
${tasksData.tasks
|
||||
.map(
|
||||
(task) => `
|
||||
${tasksData.tasks.map(task => `
|
||||
Task ID: ${task.id}
|
||||
Title: ${task.title}
|
||||
Description: ${task.description}
|
||||
Details: ${task.details}
|
||||
Dependencies: ${JSON.stringify(task.dependencies || [])}
|
||||
Priority: ${task.priority || 'medium'}
|
||||
`
|
||||
)
|
||||
.join('\n---\n')}
|
||||
`).join('\n---\n')}
|
||||
|
||||
Analyze each task and return a JSON array with the following structure for each task:
|
||||
[
|
||||
@@ -1029,28 +866,20 @@ IMPORTANT: Make sure to include an analysis for EVERY task listed above, with th
|
||||
* @param {boolean} [cliMode=false] - Whether to show CLI-specific output like spinners
|
||||
* @returns {Promise<string>} The accumulated response text
|
||||
*/
|
||||
async function _handleAnthropicStream(
|
||||
client,
|
||||
params,
|
||||
{ reportProgress, mcpLog, silentMode } = {},
|
||||
cliMode = false
|
||||
) {
|
||||
async function _handleAnthropicStream(client, params, { reportProgress, mcpLog, silentMode } = {}, cliMode = false) {
|
||||
// Only set up loading indicator in CLI mode and not in silent mode
|
||||
let loadingIndicator = null;
|
||||
let streamingInterval = null;
|
||||
let responseText = '';
|
||||
|
||||
// Check both the passed parameter and global silent mode using isSilentMode()
|
||||
const isSilent =
|
||||
silentMode || (typeof silentMode === 'undefined' && isSilentMode());
|
||||
const isSilent = silentMode || (typeof silentMode === 'undefined' && isSilentMode());
|
||||
|
||||
// Only show CLI indicators if in cliMode AND not in silent mode
|
||||
const showCLIOutput = cliMode && !isSilent;
|
||||
|
||||
if (showCLIOutput) {
|
||||
loadingIndicator = startLoadingIndicator(
|
||||
'Processing request with Claude AI...'
|
||||
);
|
||||
loadingIndicator = startLoadingIndicator('Processing request with Claude AI...');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -1059,11 +888,7 @@ async function _handleAnthropicStream(
|
||||
throw new Error('Anthropic client is required');
|
||||
}
|
||||
|
||||
if (
|
||||
!params.messages ||
|
||||
!Array.isArray(params.messages) ||
|
||||
params.messages.length === 0
|
||||
) {
|
||||
if (!params.messages || !Array.isArray(params.messages) || params.messages.length === 0) {
|
||||
throw new Error('At least one message is required');
|
||||
}
|
||||
|
||||
@@ -1082,9 +907,7 @@ async function _handleAnthropicStream(
|
||||
const readline = await import('readline');
|
||||
streamingInterval = setInterval(() => {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Receiving streaming response from Claude${'.'.repeat(dotCount)}`
|
||||
);
|
||||
process.stdout.write(`Receiving streaming response from Claude${'.'.repeat(dotCount)}`);
|
||||
dotCount = (dotCount + 1) % 4;
|
||||
}, 500);
|
||||
}
|
||||
@@ -1110,10 +933,7 @@ async function _handleAnthropicStream(
|
||||
|
||||
// Report progress - use only mcpLog in MCP context and avoid direct reportProgress calls
|
||||
const maxTokens = params.max_tokens || CONFIG.maxTokens;
|
||||
const progressPercent = Math.min(
|
||||
100,
|
||||
(responseText.length / maxTokens) * 100
|
||||
);
|
||||
const progressPercent = Math.min(100, (responseText.length / maxTokens) * 100);
|
||||
|
||||
// Only use reportProgress in CLI mode, not from MCP context, and not in silent mode
|
||||
if (reportProgress && !mcpLog && !isSilent) {
|
||||
@@ -1125,9 +945,7 @@ async function _handleAnthropicStream(
|
||||
|
||||
// Log progress if logger is provided (MCP mode)
|
||||
if (mcpLog) {
|
||||
mcpLog.info(
|
||||
`Progress: ${progressPercent}% (${responseText.length} chars generated)`
|
||||
);
|
||||
mcpLog.info(`Progress: ${progressPercent}% (${responseText.length} chars generated)`);
|
||||
}
|
||||
} catch (iterError) {
|
||||
// Handle iteration errors
|
||||
@@ -1138,10 +956,7 @@ async function _handleAnthropicStream(
|
||||
}
|
||||
|
||||
// If it's a "stream finished" error, just break the loop
|
||||
if (
|
||||
iterError.message?.includes('finished') ||
|
||||
iterError.message?.includes('closed')
|
||||
) {
|
||||
if (iterError.message?.includes('finished') || iterError.message?.includes('closed')) {
|
||||
streamDone = true;
|
||||
} else {
|
||||
// For other errors, rethrow
|
||||
@@ -1163,9 +978,9 @@ async function _handleAnthropicStream(
|
||||
|
||||
// Log completion
|
||||
if (mcpLog) {
|
||||
mcpLog.info('Completed streaming response from Claude API!');
|
||||
mcpLog.info("Completed streaming response from Claude API!");
|
||||
} else if (!isSilent) {
|
||||
log('info', 'Completed streaming response from Claude API!');
|
||||
log('info', "Completed streaming response from Claude API!");
|
||||
}
|
||||
|
||||
return responseText;
|
||||
@@ -1209,12 +1024,8 @@ function parseTaskJsonResponse(responseText) {
|
||||
const jsonStartIndex = jsonContent.indexOf('{');
|
||||
const jsonEndIndex = jsonContent.lastIndexOf('}');
|
||||
|
||||
if (
|
||||
jsonStartIndex === -1 ||
|
||||
jsonEndIndex === -1 ||
|
||||
jsonEndIndex < jsonStartIndex
|
||||
) {
|
||||
throw new Error('Could not locate valid JSON object in the response');
|
||||
if (jsonStartIndex === -1 || jsonEndIndex === -1 || jsonEndIndex < jsonStartIndex) {
|
||||
throw new Error("Could not locate valid JSON object in the response");
|
||||
}
|
||||
|
||||
// Extract and parse the JSON
|
||||
@@ -1223,17 +1034,13 @@ function parseTaskJsonResponse(responseText) {
|
||||
|
||||
// Validate required fields
|
||||
if (!taskData.title || !taskData.description) {
|
||||
throw new Error(
|
||||
'Missing required fields in the generated task (title or description)'
|
||||
);
|
||||
throw new Error("Missing required fields in the generated task (title or description)");
|
||||
}
|
||||
|
||||
return taskData;
|
||||
} catch (error) {
|
||||
if (error.name === 'SyntaxError') {
|
||||
throw new Error(
|
||||
`Failed to parse JSON: ${error.message} (Response content may be malformed)`
|
||||
);
|
||||
throw new Error(`Failed to parse JSON: ${error.message} (Response content may be malformed)`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@@ -1249,8 +1056,7 @@ function parseTaskJsonResponse(responseText) {
|
||||
*/
|
||||
function _buildAddTaskPrompt(prompt, contextTasks, { newTaskId } = {}) {
|
||||
// Create the system prompt for Claude
|
||||
const systemPrompt =
|
||||
"You are a helpful assistant that creates well-structured tasks for a software development project. Generate a single new task based on the user's description.";
|
||||
const systemPrompt = "You are a helpful assistant that creates well-structured tasks for a software development project. Generate a single new task based on the user's description.";
|
||||
|
||||
const taskStructure = `
|
||||
{
|
||||
@@ -1288,13 +1094,10 @@ function getAnthropicClient(session) {
|
||||
}
|
||||
|
||||
// Initialize a new client with API key from session or environment
|
||||
const apiKey =
|
||||
session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
||||
const apiKey = session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.'
|
||||
);
|
||||
throw new Error("ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.");
|
||||
}
|
||||
|
||||
return new Anthropic({
|
||||
@@ -1315,22 +1118,14 @@ function getAnthropicClient(session) {
|
||||
* @param {Object} options.session - Session object from MCP server
|
||||
* @returns {Object} - The generated task description
|
||||
*/
|
||||
async function generateTaskDescriptionWithPerplexity(
|
||||
prompt,
|
||||
{ reportProgress, mcpLog, session } = {}
|
||||
) {
|
||||
async function generateTaskDescriptionWithPerplexity(prompt, { reportProgress, mcpLog, session } = {}) {
|
||||
try {
|
||||
// First, perform research to get context
|
||||
log('info', `Researching context for task prompt: "${prompt}"`);
|
||||
const perplexityClient = getPerplexityClient();
|
||||
|
||||
const PERPLEXITY_MODEL =
|
||||
process.env.PERPLEXITY_MODEL ||
|
||||
session?.env?.PERPLEXITY_MODEL ||
|
||||
'sonar-pro';
|
||||
const researchLoadingIndicator = startLoadingIndicator(
|
||||
'Researching best practices with Perplexity AI...'
|
||||
);
|
||||
const PERPLEXITY_MODEL = process.env.PERPLEXITY_MODEL || session?.env?.PERPLEXITY_MODEL || 'sonar-pro';
|
||||
const researchLoadingIndicator = startLoadingIndicator('Researching best practices with Perplexity AI...');
|
||||
|
||||
// Formulate research query based on task prompt
|
||||
const researchQuery = `I need to implement: "${prompt}".
|
||||
@@ -1340,12 +1135,10 @@ Include concrete code examples and technical considerations where relevant.`;
|
||||
// Query Perplexity for research
|
||||
const researchResponse = await perplexityClient.chat.completions.create({
|
||||
model: PERPLEXITY_MODEL,
|
||||
messages: [
|
||||
{
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: researchQuery
|
||||
}
|
||||
],
|
||||
}],
|
||||
temperature: 0.1 // Lower temperature for more factual responses
|
||||
});
|
||||
|
||||
@@ -1355,9 +1148,7 @@ Include concrete code examples and technical considerations where relevant.`;
|
||||
log('info', 'Research completed, now generating detailed task description');
|
||||
|
||||
// Now generate task description with Claude
|
||||
const loadingIndicator = startLoadingIndicator(
|
||||
`Generating research-backed task description...`
|
||||
);
|
||||
const loadingIndicator = startLoadingIndicator(`Generating research-backed task description...`);
|
||||
let streamingInterval = null;
|
||||
let responseText = '';
|
||||
|
||||
@@ -1394,9 +1185,7 @@ Return a JSON object with the following structure:
|
||||
const readline = await import('readline');
|
||||
streamingInterval = setInterval(() => {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Generating research-backed task description${'.'.repeat(dotCount)}`
|
||||
);
|
||||
process.stdout.write(`Generating research-backed task description${'.'.repeat(dotCount)}`);
|
||||
dotCount = (dotCount + 1) % 4;
|
||||
}, 500);
|
||||
|
||||
@@ -1421,14 +1210,10 @@ Return a JSON object with the following structure:
|
||||
responseText += chunk.delta.text;
|
||||
}
|
||||
if (reportProgress) {
|
||||
await reportProgress({
|
||||
progress: (responseText.length / CONFIG.maxTokens) * 100
|
||||
});
|
||||
await reportProgress({ progress: (responseText.length / CONFIG.maxTokens) * 100 });
|
||||
}
|
||||
if (mcpLog) {
|
||||
mcpLog.info(
|
||||
`Progress: ${(responseText.length / CONFIG.maxTokens) * 100}%`
|
||||
);
|
||||
mcpLog.info(`Progress: ${responseText.length / CONFIG.maxTokens * 100}%`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1444,10 +1229,7 @@ Return a JSON object with the following structure:
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
log(
|
||||
'error',
|
||||
`Error generating research-backed task description: ${error.message}`
|
||||
);
|
||||
log('error', `Error generating research-backed task description: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -1460,15 +1242,10 @@ Return a JSON object with the following structure:
|
||||
*/
|
||||
function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
||||
// If we have a session with ANTHROPIC_API_KEY in env, use that
|
||||
const apiKey =
|
||||
session?.env?.ANTHROPIC_API_KEY ||
|
||||
process.env.ANTHROPIC_API_KEY ||
|
||||
customEnv?.ANTHROPIC_API_KEY;
|
||||
const apiKey = session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY || customEnv?.ANTHROPIC_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.'
|
||||
);
|
||||
throw new Error("ANTHROPIC_API_KEY environment variable is missing. Set it to use AI features.");
|
||||
}
|
||||
|
||||
return new Anthropic({
|
||||
@@ -1487,18 +1264,9 @@ function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
||||
* @param {Object} options - Options containing reportProgress, mcpLog, silentMode, and session
|
||||
* @returns {string} - Response text
|
||||
*/
|
||||
async function sendChatWithContext(
|
||||
client,
|
||||
params,
|
||||
{ reportProgress, mcpLog, silentMode, session } = {}
|
||||
) {
|
||||
async function sendChatWithContext(client, params, { reportProgress, mcpLog, silentMode, session } = {}) {
|
||||
// Use the streaming helper to get the response
|
||||
return await _handleAnthropicStream(
|
||||
client,
|
||||
params,
|
||||
{ reportProgress, mcpLog, silentMode },
|
||||
false
|
||||
);
|
||||
return await _handleAnthropicStream(client, params, { reportProgress, mcpLog, silentMode }, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
32
scripts/modules/task-manager.js (lines 3036-3084)
Normal file
32
scripts/modules/task-manager.js (lines 3036-3084)
Normal file
@@ -0,0 +1,32 @@
|
||||
async function updateSubtaskById(tasksPath, subtaskId, prompt, useResearch = false) {
|
||||
let loadingIndicator = null;
|
||||
try {
|
||||
log('info', `Updating subtask ${subtaskId} with prompt: "${prompt}"`);
|
||||
|
||||
// Validate subtask ID format
|
||||
if (!subtaskId || typeof subtaskId !== 'string' || !subtaskId.includes('.')) {
|
||||
throw new Error(`Invalid subtask ID format: ${subtaskId}. Subtask ID must be in format "parentId.subtaskId"`);
|
||||
}
|
||||
|
||||
// Validate prompt
|
||||
if (!prompt || typeof prompt !== 'string' || prompt.trim() === '') {
|
||||
throw new Error('Prompt cannot be empty. Please provide context for the subtask update.');
|
||||
}
|
||||
|
||||
// Prepare for fallback handling
|
||||
let claudeOverloaded = false;
|
||||
|
||||
// Validate tasks file exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
throw new Error(`Tasks file not found at path: ${tasksPath}`);
|
||||
}
|
||||
|
||||
// Read the tasks file
|
||||
const data = readJSON(tasksPath);
|
||||
// ... rest of the function
|
||||
} catch (error) {
|
||||
// Handle errors
|
||||
console.error(`Error updating subtask: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user