feat: Enhance Task Master CLI with Testing Framework, Perplexity AI Integration, and Refactored Core Logic

This commit introduces significant enhancements and refactoring to the Task Master CLI, focusing on improved testing, integration with Perplexity AI for research-backed task updates, and core logic refactoring for better maintainability and functionality.

**Testing Infrastructure Setup:**
- Implemented Jest as the primary testing framework, setting up a comprehensive testing environment.
- Added new test scripts to  including , , and  for streamlined testing workflows.
- Integrated necessary devDependencies for testing, such as , , , , and , to support unit, integration, and end-to-end testing.

**Dependency Updates:**
- Updated  and  to reflect the latest dependency versions, ensuring project stability and access to the newest features and security patches.
- Upgraded  to version 0.9.16 and usage: openai [-h] [-v] [-b API_BASE] [-k API_KEY] [-p PROXY [PROXY ...]]
              [-o ORGANIZATION] [-t {openai,azure}]
              [--api-version API_VERSION] [--azure-endpoint AZURE_ENDPOINT]
              [--azure-ad-token AZURE_AD_TOKEN] [-V]
              {api,tools,migrate,grit} ...

positional arguments:
  {api,tools,migrate,grit}
    api                 Direct API calls
    tools               Client side tools for convenience

options:
  -h, --help            show this help message and exit
  -v, --verbose         Set verbosity.
  -b, --api-base API_BASE
                        What API base url to use.
  -k, --api-key API_KEY
                        What API key to use.
  -p, --proxy PROXY [PROXY ...]
                        What proxy to use.
  -o, --organization ORGANIZATION
                        Which organization to run as (will use your default
                        organization if not specified)
  -t, --api-type {openai,azure}
                        The backend API to call, must be `openai` or `azure`
  --api-version API_VERSION
                        The Azure API version, e.g.
                        'https://learn.microsoft.com/en-us/azure/ai-
                        services/openai/reference#rest-api-versioning'
  --azure-endpoint AZURE_ENDPOINT
                        The Azure endpoint, e.g.
                        'https://endpoint.openai.azure.com'
  --azure-ad-token AZURE_AD_TOKEN
                        A token from Azure Active Directory,
                        https://www.microsoft.com/en-
                        us/security/business/identity-access/microsoft-entra-
                        id
  -V, --version         show program's version number and exit to 4.89.0.
- Added  dependency (version 2.3.0) and updated  related dependencies to their latest versions.

**Perplexity AI Integration for Research-Backed Updates:**
- Introduced an option to leverage Perplexity AI for task updates, enabling research-backed enhancements to task details.
- Implemented logic to initialize a Perplexity AI client if the  environment variable is available.
- Modified the  function to accept a  parameter, allowing dynamic selection between Perplexity AI and Claude AI for task updates based on API key availability and user preference.
- Enhanced  to handle responses from Perplexity AI and update tasks accordingly, including improved error handling and logging for robust operation.

**Core Logic Refactoring and Improvements:**
- Refactored the  function to utilize task IDs instead of dependency IDs, ensuring consistency and clarity in dependency management.
- Implemented a new  function to rigorously check for both circular dependencies and self-dependencies within tasks, improving task relationship integrity.
- Enhanced UI elements in :
    - Refactored  to incorporate icons for different task statuses and utilize a  object for color mapping, improving visual representation of task status.
    - Updated  to display colored complexity scores with emojis, providing a more intuitive and visually appealing representation of task complexity.
- Refactored the task data structure creation and validation process:
    - Updated the JSON Schema for  to reflect a more streamlined and efficient task structure.
    - Implemented Task Model Classes for better data modeling and type safety.
    - Improved File System Operations for task data management.
    - Developed robust Validation Functions and an Error Handling System to ensure data integrity and application stability.

**Testing Guidelines Implementation:**
- Implemented guidelines for writing testable code when developing new features, promoting a test-driven development approach.
- Added testing requirements and best practices for unit, integration, and edge case testing to ensure comprehensive test coverage.
- Updated the development workflow to mandate writing tests before proceeding with configuration and documentation updates, reinforcing the importance of testing throughout the development lifecycle.

This commit collectively enhances the Task Master CLI's reliability, functionality, and developer experience through improved testing practices, AI-powered research capabilities, and a more robust and maintainable codebase.
This commit is contained in:
Eyal Toledano
2025-03-24 13:28:08 -04:00
parent 204e318190
commit 0eec95323c
26 changed files with 6496 additions and 773 deletions

View File

@@ -14,35 +14,3 @@ Create the foundational data structure including:
# Test Strategy:
Verify that the tasks.json structure can be created, read, and validated. Test with sample data to ensure all fields are properly handled and that validation correctly identifies invalid structures.
# Subtasks:
## 1. Design JSON Schema for tasks.json [done]
### Dependencies: None
### Description: Create a formal JSON Schema definition that validates the structure of the tasks.json file. The schema should enforce the data model specified in the PRD, including the Task Model and Tasks Collection Model with all required fields (id, title, description, status, dependencies, priority, details, testStrategy, subtasks). Include type validation, required fields, and constraints on enumerated values (like status and priority options).
### Details:
## 2. Implement Task Model Classes [done]
### Dependencies: 1 (done)
### Description: Create JavaScript classes that represent the Task and Tasks Collection models. Implement constructor methods that validate input data, getter/setter methods for properties, and utility methods for common operations (like adding subtasks, changing status, etc.). These classes will serve as the programmatic interface to the task data structure.
### Details:
## 3. Create File System Operations for tasks.json [done]
### Dependencies: 1 (done), 2 (done)
### Description: Implement functions to read from and write to the tasks.json file. These functions should handle file system operations asynchronously, manage file locking to prevent corruption during concurrent operations, and ensure atomic writes (using temporary files and rename operations). Include initialization logic to create a default tasks.json file if one doesn't exist.
### Details:
## 4. Implement Validation Functions [done]
### Dependencies: 1 (done), 2 (done)
### Description: Create a comprehensive set of validation functions that can verify the integrity of the task data structure. These should include validation of individual tasks, validation of the entire tasks collection, dependency cycle detection, and validation of relationships between tasks. These functions will be used both when loading data and before saving to ensure data integrity.
### Details:
## 5. Implement Error Handling System [done]
### Dependencies: 1 (done), 3 (done), 4 (done)
### Description: Create a robust error handling system for file operations and data validation. Implement custom error classes for different types of errors (file not found, permission denied, invalid data, etc.), error logging functionality, and recovery mechanisms where appropriate. This system should provide clear, actionable error messages to users while maintaining system stability.
### Details:

View File

@@ -14,35 +14,3 @@ Implement the CLI foundation including:
# Test Strategy:
Test each command with various parameters to ensure proper parsing. Verify help documentation is comprehensive and accurate. Test logging at different verbosity levels.
# Subtasks:
## 1. Set up Commander.js Framework [done]
### Dependencies: None
### Description: Initialize and configure Commander.js as the command-line parsing framework. Create the main CLI entry point file that will serve as the application's command-line interface. Set up the basic command structure with program name, version, and description from package.json. Implement the core program flow including command registration pattern and error handling.
### Details:
## 2. Implement Global Options Handling [done]
### Dependencies: 1 (done)
### Description: Add support for all required global options including --help, --version, --file, --quiet, --debug, and --json. Implement the logic to process these options and modify program behavior accordingly. Create a configuration object that stores these settings and can be accessed by all commands. Ensure options can be combined and have appropriate precedence rules.
### Details:
## 3. Create Command Help Documentation System [done]
### Dependencies: 1 (done), 2 (done)
### Description: Develop a comprehensive help documentation system that provides clear usage instructions for all commands and options. Implement both command-specific help and general program help. Ensure help text is well-formatted, consistent, and includes examples. Create a centralized system for managing help text to ensure consistency across the application.
### Details:
## 4. Implement Colorized Console Output [done]
### Dependencies: 1 (done)
### Description: Create a utility module for colorized console output to improve readability and user experience. Implement different color schemes for various message types (info, warning, error, success). Add support for text styling (bold, underline, etc.) and ensure colors are used consistently throughout the application. Make sure colors can be disabled in environments that don't support them.
### Details:
## 5. Develop Configurable Logging System [done]
### Dependencies: 1 (done), 2 (done), 4 (done)
### Description: Create a logging system with configurable verbosity levels that integrates with the CLI. Implement different logging levels (error, warn, info, debug, trace) and ensure log output respects the verbosity settings specified by global options. Add support for log output redirection to files. Ensure logs include appropriate timestamps and context information.
### Details:

View File

@@ -1,6 +1,6 @@
# Task ID: 22
# Title: Create Comprehensive Test Suite for Task Master CLI
# Status: pending
# Status: in-progress
# Dependencies: ✅ 21 (done)
# Priority: high
# Description: Develop a complete testing infrastructure for the Task Master CLI that includes unit, integration, and end-to-end tests to verify all core functionality and error handling.
@@ -57,20 +57,20 @@ Verification will involve:
The task will be considered complete when all tests pass consistently, coverage meets targets, and the test suite can detect intentionally introduced bugs.
# Subtasks:
## 1. Set Up Jest Testing Environment [pending]
## 1. Set Up Jest Testing Environment [done]
### Dependencies: None
### Description: Configure Jest for the project, including setting up the jest.config.js file, adding necessary dependencies, and creating the initial test directory structure. Implement proper mocking for Claude API interactions, file system operations, and user input/output. Set up test coverage reporting and configure it to run in the CI pipeline.
### Details:
## 2. Implement Unit Tests for Core Components [pending]
### Dependencies: 1 (pending)
### Dependencies: 1 (done)
### Description: Create a comprehensive set of unit tests for all utility functions, core logic components, and individual modules of the Task Master CLI. This includes tests for task creation, parsing, manipulation, data storage, retrieval, and formatting functions. Ensure all edge cases and error scenarios are covered.
### Details:
## 3. Develop Integration and End-to-End Tests [pending]
### Dependencies: 1 (pending), 2 (pending)
### Dependencies: 1 (done), 2 (pending)
### Description: Create integration tests that verify the correct interaction between different components of the CLI, including command execution, option parsing, and data flow. Implement end-to-end tests that simulate complete user workflows, such as creating a task, expanding it, and updating its status. Include tests for error scenarios, recovery processes, and handling large numbers of tasks.
### Details:

View File

@@ -1,7 +1,7 @@
# Task ID: 23
# Title: Implement MCP (Model Context Protocol) Server Functionality for Task Master
# Status: pending
# Dependencies: ⏱️ 22 (pending)
# Dependencies: ⏱️ 22 (in-progress)
# Priority: medium
# Description: Extend Task Master to function as an MCP server, allowing it to provide context management services to other applications following the Model Context Protocol specification.
# Details:

View File

@@ -1,7 +1,7 @@
# Task ID: 24
# Title: Implement AI-Powered Test Generation Command
# Status: pending
# Dependencies: ⏱️ 22 (pending)
# Dependencies: ⏱️ 22 (in-progress)
# Priority: high
# Description: Create a new 'generate-test' command that leverages AI to automatically produce Jest test files for tasks based on their descriptions and subtasks.
# Details:

View File

@@ -17,60 +17,7 @@
"priority": "high",
"details": "Create the foundational data structure including:\n- JSON schema for tasks.json\n- Task model with all required fields (id, title, description, status, dependencies, priority, details, testStrategy, subtasks)\n- Validation functions for the task model\n- Basic file system operations for reading/writing tasks.json\n- Error handling for file operations",
"testStrategy": "Verify that the tasks.json structure can be created, read, and validated. Test with sample data to ensure all fields are properly handled and that validation correctly identifies invalid structures.",
"subtasks": [
{
"id": 1,
"title": "Design JSON Schema for tasks.json",
"description": "Create a formal JSON Schema definition that validates the structure of the tasks.json file. The schema should enforce the data model specified in the PRD, including the Task Model and Tasks Collection Model with all required fields (id, title, description, status, dependencies, priority, details, testStrategy, subtasks). Include type validation, required fields, and constraints on enumerated values (like status and priority options).",
"status": "done",
"dependencies": [],
"acceptanceCriteria": "- JSON Schema file is created with proper validation for all fields in the Task and Tasks Collection models\n- Schema validates that task IDs are unique integers\n- Schema enforces valid status values (\"pending\", \"done\", \"deferred\")\n- Schema enforces valid priority values (\"high\", \"medium\", \"low\")\n- Schema validates the nested structure of subtasks\n- Schema includes validation for the meta object with projectName, version, timestamps, etc."
},
{
"id": 2,
"title": "Implement Task Model Classes",
"description": "Create JavaScript classes that represent the Task and Tasks Collection models. Implement constructor methods that validate input data, getter/setter methods for properties, and utility methods for common operations (like adding subtasks, changing status, etc.). These classes will serve as the programmatic interface to the task data structure.",
"status": "done",
"dependencies": [
1
],
"acceptanceCriteria": "- Task class with all required properties from the PRD\n- TasksCollection class that manages an array of Task objects\n- Methods for creating, retrieving, updating tasks\n- Methods for managing subtasks within a task\n- Input validation in constructors and setters\n- Proper TypeScript/JSDoc type definitions for all classes and methods"
},
{
"id": 3,
"title": "Create File System Operations for tasks.json",
"description": "Implement functions to read from and write to the tasks.json file. These functions should handle file system operations asynchronously, manage file locking to prevent corruption during concurrent operations, and ensure atomic writes (using temporary files and rename operations). Include initialization logic to create a default tasks.json file if one doesn't exist.",
"status": "done",
"dependencies": [
1,
2
],
"acceptanceCriteria": "- Asynchronous read function that parses tasks.json into model objects\n- Asynchronous write function that serializes model objects to tasks.json\n- File locking mechanism to prevent concurrent write operations\n- Atomic write operations to prevent file corruption\n- Initialization function that creates default tasks.json if not present\n- Functions properly handle relative and absolute paths"
},
{
"id": 4,
"title": "Implement Validation Functions",
"description": "Create a comprehensive set of validation functions that can verify the integrity of the task data structure. These should include validation of individual tasks, validation of the entire tasks collection, dependency cycle detection, and validation of relationships between tasks. These functions will be used both when loading data and before saving to ensure data integrity.",
"status": "done",
"dependencies": [
1,
2
],
"acceptanceCriteria": "- Functions to validate individual task objects against schema\n- Function to validate entire tasks collection\n- Dependency cycle detection algorithm\n- Validation of parent-child relationships in subtasks\n- Validation of task ID uniqueness\n- Functions return detailed error messages for invalid data\n- Unit tests covering various validation scenarios"
},
{
"id": 5,
"title": "Implement Error Handling System",
"description": "Create a robust error handling system for file operations and data validation. Implement custom error classes for different types of errors (file not found, permission denied, invalid data, etc.), error logging functionality, and recovery mechanisms where appropriate. This system should provide clear, actionable error messages to users while maintaining system stability.",
"status": "done",
"dependencies": [
1,
3,
4
],
"acceptanceCriteria": "- Custom error classes for different error types (FileError, ValidationError, etc.)\n- Consistent error format with error code, message, and details\n- Error logging functionality with configurable verbosity\n- Recovery mechanisms for common error scenarios\n- Graceful degradation when non-critical errors occur\n- User-friendly error messages that suggest solutions\n- Unit tests for error handling in various scenarios"
}
]
"subtasks": []
},
{
"id": 2,
@@ -83,59 +30,7 @@
"priority": "high",
"details": "Implement the CLI foundation including:\n- Set up Commander.js for command parsing\n- Create help documentation for all commands\n- Implement colorized console output for better readability\n- Add logging system with configurable levels\n- Handle global options (--help, --version, --file, --quiet, --debug, --json)",
"testStrategy": "Test each command with various parameters to ensure proper parsing. Verify help documentation is comprehensive and accurate. Test logging at different verbosity levels.",
"subtasks": [
{
"id": 1,
"title": "Set up Commander.js Framework",
"description": "Initialize and configure Commander.js as the command-line parsing framework. Create the main CLI entry point file that will serve as the application's command-line interface. Set up the basic command structure with program name, version, and description from package.json. Implement the core program flow including command registration pattern and error handling.",
"status": "done",
"dependencies": [],
"acceptanceCriteria": "- Commander.js is properly installed and configured in the project\n- CLI entry point file is created with proper Node.js shebang and permissions\n- Program metadata (name, version, description) is correctly loaded from package.json\n- Basic command registration pattern is established\n- Global error handling is implemented to catch and display unhandled exceptions"
},
{
"id": 2,
"title": "Implement Global Options Handling",
"description": "Add support for all required global options including --help, --version, --file, --quiet, --debug, and --json. Implement the logic to process these options and modify program behavior accordingly. Create a configuration object that stores these settings and can be accessed by all commands. Ensure options can be combined and have appropriate precedence rules.",
"status": "done",
"dependencies": [
1
],
"acceptanceCriteria": "- All specified global options (--help, --version, --file, --quiet, --debug, --json) are implemented\n- Options correctly modify program behavior when specified\n- Alternative tasks.json file can be specified with --file option\n- Output verbosity is controlled by --quiet and --debug flags\n- JSON output format is supported with the --json flag\n- Help text is displayed when --help is specified\n- Version information is displayed when --version is specified"
},
{
"id": 3,
"title": "Create Command Help Documentation System",
"description": "Develop a comprehensive help documentation system that provides clear usage instructions for all commands and options. Implement both command-specific help and general program help. Ensure help text is well-formatted, consistent, and includes examples. Create a centralized system for managing help text to ensure consistency across the application.",
"status": "done",
"dependencies": [
1,
2
],
"acceptanceCriteria": "- General program help shows all available commands and global options\n- Command-specific help shows detailed usage information for each command\n- Help text includes clear examples of command usage\n- Help formatting is consistent and readable across all commands\n- Help system handles both explicit help requests (--help) and invalid command syntax"
},
{
"id": 4,
"title": "Implement Colorized Console Output",
"description": "Create a utility module for colorized console output to improve readability and user experience. Implement different color schemes for various message types (info, warning, error, success). Add support for text styling (bold, underline, etc.) and ensure colors are used consistently throughout the application. Make sure colors can be disabled in environments that don't support them.",
"status": "done",
"dependencies": [
1
],
"acceptanceCriteria": "- Utility module provides consistent API for colorized output\n- Different message types (info, warning, error, success) use appropriate colors\n- Text styling options (bold, underline, etc.) are available\n- Colors are disabled automatically in environments that don't support them\n- Color usage is consistent across the application\n- Output remains readable when colors are disabled"
},
{
"id": 5,
"title": "Develop Configurable Logging System",
"description": "Create a logging system with configurable verbosity levels that integrates with the CLI. Implement different logging levels (error, warn, info, debug, trace) and ensure log output respects the verbosity settings specified by global options. Add support for log output redirection to files. Ensure logs include appropriate timestamps and context information.",
"status": "done",
"dependencies": [
1,
2,
4
],
"acceptanceCriteria": "- Logging system supports multiple verbosity levels (error, warn, info, debug, trace)\n- Log output respects verbosity settings from global options (--quiet, --debug)\n- Logs include timestamps and appropriate context information\n- Log messages use consistent formatting and appropriate colors\n- Logging can be redirected to files when needed\n- Debug logs provide detailed information useful for troubleshooting\n- Logging system has minimal performance impact when not in use\n\nEach of these subtasks directly addresses a component of the CLI foundation as specified in the task description, and together they provide a complete implementation of the required functionality. The subtasks are ordered in a logical sequence that respects their dependencies."
}
]
"subtasks": []
},
{
"id": 3,
@@ -1474,7 +1369,7 @@
"id": 22,
"title": "Create Comprehensive Test Suite for Task Master CLI",
"description": "Develop a complete testing infrastructure for the Task Master CLI that includes unit, integration, and end-to-end tests to verify all core functionality and error handling.",
"status": "pending",
"status": "in-progress",
"dependencies": [
21
],
@@ -1486,7 +1381,7 @@
"id": 1,
"title": "Set Up Jest Testing Environment",
"description": "Configure Jest for the project, including setting up the jest.config.js file, adding necessary dependencies, and creating the initial test directory structure. Implement proper mocking for Claude API interactions, file system operations, and user input/output. Set up test coverage reporting and configure it to run in the CI pipeline.",
"status": "pending",
"status": "done",
"dependencies": [],
"acceptanceCriteria": "- jest.config.js is properly configured for the project"
},