Skip to content

Refactor: Modularize Task Master CLI into Modules Directory#4

Merged
eyaltoledano merged 2 commits intomainfrom
refactor
Mar 24, 2025
Merged

Refactor: Modularize Task Master CLI into Modules Directory#4
eyaltoledano merged 2 commits intomainfrom
refactor

Conversation

@eyaltoledano
Copy link
Owner

Refactor: Modularize Task Master CLI into Modules Directory

Simplified the Task Master CLI by organizing code into modules within the scripts/modules/ directory.

Why:

  • Better Organization: Code is now grouped by function (AI, commands, dependencies, tasks, UI, utilities).
  • Easier to Maintain: Smaller modules are simpler to update and fix.
  • Scalable: New features can be added more easily in a structured way.

What Changed:

  • Moved code from single scripts/dev.js file into these new modules:
    • ai-services.js: AI interactions (Claude, Perplexity)
    • commands.js: CLI command definitions (Commander.js)
    • dependency-manager.js: Task dependency handling
    • task-manager.js: Core task operations (create, list, update, etc.)
    • ui.js: User interface elements (display, formatting)
    • utils.js: Utility functions and configuration
    • index.js: Exports all modules
  • Replaced direct use of scripts/dev.js with the global task-master command (see dev_workflow.mdc).
  • Updated documentation (dev_workflow.mdc) to reflect the new task-master command.

Benefits:

Code is now cleaner, easier to work with, and ready for future growth.

Use the task-master command (or npx task-master) to run the CLI. See dev_workflow.mdc for command details.

Simplified the Task Master CLI by organizing code into modules within the  directory.

**Why:**

- **Better Organization:** Code is now grouped by function (AI, commands, dependencies, tasks, UI, utilities).
- **Easier to Maintain:**  Smaller modules are simpler to update and fix.
- **Scalable:**  New features can be added more easily in a structured way.

**What Changed:**

- Moved code from single   _____         _      __  __           _
 |_   _|_ _ ___| | __ |  \/  | __ _ ___| |_ ___ _ __
   | |/ _` / __| |/ / | |\/| |/ _` / __| __/ _ \ '__|
   | | (_| \__ \   <  | |  | | (_| \__ \ ||  __/ |
   |_|\__,_|___/_|\_\ |_|  |_|\__,_|___/\__\___|_|

by https://x.com/eyaltoledano
╭────────────────────────────────────────────╮
│                                            │
│   Version: 0.9.16   Project: Task Master   │
│                                            │
╰────────────────────────────────────────────╯

╭─────────────────────╮
│                     │
│   Task Master CLI   │
│                     │
╰─────────────────────╯

╭───────────────────╮
│  Task Generation  │
╰───────────────────╯
    parse-prd                 --input=<file.txt> [--tasks=10]          Generate tasks from a PRD document
    generate                                                           Create individual task files from tasks…

╭───────────────────╮
│  Task Management  │
╰───────────────────╯
    list                      [--status=<status>] [--with-subtas…      List all tasks with their status
    set-status                --id=<id> --status=<status>              Update task status (done, pending, etc.)
    update                    --from=<id> --prompt="<context>"         Update tasks based on new requirements
    add-task                  --prompt="<text>" [--dependencies=…      Add a new task using AI
    add-dependency            --id=<id> --depends-on=<id>              Add a dependency to a task
    remove-dependency         --id=<id> --depends-on=<id>              Remove a dependency from a task

╭──────────────────────────╮
│  Task Analysis & Detail  │
╰──────────────────────────╯
    analyze-complexity        [--research] [--threshold=5]             Analyze tasks and generate expansion re…
    complexity-report         [--file=<path>]                          Display the complexity analysis report
    expand                    --id=<id> [--num=5] [--research] […      Break down tasks into detailed subtasks
    expand --all              [--force] [--research]                   Expand all pending tasks with subtasks
    clear-subtasks            --id=<id>                                Remove subtasks from specified tasks

╭─────────────────────────────╮
│  Task Navigation & Viewing  │
╰─────────────────────────────╯
    next                                                               Show the next task to work on based on …
    show                      <id>                                     Display detailed information about a sp…

╭─────────────────────────╮
│  Dependency Management  │
╰─────────────────────────╯
    validate-dependenci…                                               Identify invalid dependencies without f…
    fix-dependencies                                                   Fix invalid dependencies automatically

╭─────────────────────────╮
│  Environment Variables  │
╰─────────────────────────╯
    ANTHROPIC_API_KEY              Your Anthropic API key                             Required
    MODEL                          Claude model to use                                Default: claude-3-7-sonn…
    MAX_TOKENS                     Maximum tokens for responses                       Default: 4000
    TEMPERATURE                    Temperature for model responses                    Default: 0.7
    PERPLEXITY_API_KEY             Perplexity API key for research                    Optional
    PERPLEXITY_MODEL               Perplexity model to use                            Default: sonar-small-onl…
    DEBUG                          Enable debug logging                               Default: false
    LOG_LEVEL                      Console output level (debug,info,warn,error)       Default: info
    DEFAULT_SUBTASKS               Default number of subtasks to generate             Default: 3
    DEFAULT_PRIORITY               Default task priority                              Default: medium
    PROJECT_NAME                   Project name displayed in UI                       Default: Task Master       file into these new modules:
    - : AI interactions (Claude, Perplexity)
    - :  CLI command definitions (Commander.js)
    - : Task dependency handling
    - : Core task operations (create, list, update, etc.)
    - : User interface elements (display, formatting)
    - : Utility functions and configuration
    - :  Exports all modules
- Replaced direct use of   _____         _      __  __           _
 |_   _|_ _ ___| | __ |  \/  | __ _ ___| |_ ___ _ __
   | |/ _` / __| |/ / | |\/| |/ _` / __| __/ _ \ '__|
   | | (_| \__ \   <  | |  | | (_| \__ \ ||  __/ |
   |_|\__,_|___/_|\_\ |_|  |_|\__,_|___/\__\___|_|

by https://x.com/eyaltoledano
╭────────────────────────────────────────────╮
│                                            │
│   Version: 0.9.16   Project: Task Master   │
│                                            │
╰────────────────────────────────────────────╯

╭─────────────────────╮
│                     │
│   Task Master CLI   │
│                     │
╰─────────────────────╯

╭───────────────────╮
│  Task Generation  │
╰───────────────────╯
    parse-prd                 --input=<file.txt> [--tasks=10]          Generate tasks from a PRD document
    generate                                                           Create individual task files from tasks…

╭───────────────────╮
│  Task Management  │
╰───────────────────╯
    list                      [--status=<status>] [--with-subtas…      List all tasks with their status
    set-status                --id=<id> --status=<status>              Update task status (done, pending, etc.)
    update                    --from=<id> --prompt="<context>"         Update tasks based on new requirements
    add-task                  --prompt="<text>" [--dependencies=…      Add a new task using AI
    add-dependency            --id=<id> --depends-on=<id>              Add a dependency to a task
    remove-dependency         --id=<id> --depends-on=<id>              Remove a dependency from a task

╭──────────────────────────╮
│  Task Analysis & Detail  │
╰──────────────────────────╯
    analyze-complexity        [--research] [--threshold=5]             Analyze tasks and generate expansion re…
    complexity-report         [--file=<path>]                          Display the complexity analysis report
    expand                    --id=<id> [--num=5] [--research] […      Break down tasks into detailed subtasks
    expand --all              [--force] [--research]                   Expand all pending tasks with subtasks
    clear-subtasks            --id=<id>                                Remove subtasks from specified tasks

╭─────────────────────────────╮
│  Task Navigation & Viewing  │
╰─────────────────────────────╯
    next                                                               Show the next task to work on based on …
    show                      <id>                                     Display detailed information about a sp…

╭─────────────────────────╮
│  Dependency Management  │
╰─────────────────────────╯
    validate-dependenci…                                               Identify invalid dependencies without f…
    fix-dependencies                                                   Fix invalid dependencies automatically

╭─────────────────────────╮
│  Environment Variables  │
╰─────────────────────────╯
    ANTHROPIC_API_KEY              Your Anthropic API key                             Required
    MODEL                          Claude model to use                                Default: claude-3-7-sonn…
    MAX_TOKENS                     Maximum tokens for responses                       Default: 4000
    TEMPERATURE                    Temperature for model responses                    Default: 0.7
    PERPLEXITY_API_KEY             Perplexity API key for research                    Optional
    PERPLEXITY_MODEL               Perplexity model to use                            Default: sonar-small-onl…
    DEBUG                          Enable debug logging                               Default: false
    LOG_LEVEL                      Console output level (debug,info,warn,error)       Default: info
    DEFAULT_SUBTASKS               Default number of subtasks to generate             Default: 3
    DEFAULT_PRIORITY               Default task priority                              Default: medium
    PROJECT_NAME                   Project name displayed in UI                       Default: Task Master       with the global  command (see ).
- Updated documentation () to reflect the new  command.

**Benefits:**

Code is now cleaner, easier to work with, and ready for future growth.

Use the  command (or ) to run the CLI.  See  for command details.
@eyaltoledano eyaltoledano self-assigned this Mar 24, 2025
Copy link
Collaborator

@Crunchyman-ralph Crunchyman-ralph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably move these rules somewhere else, so that we can be compatible with other platforms, not just cursor.

We can do that after we implement MCP.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can prob create the right rules based on the user's selections. we can do that with a command too. right now it get added via the npm package only

@Crunchyman-ralph
Copy link
Collaborator

@eyaltoledano I'm going to let you merge this, but I'm about to push something on MCP, going to probably base myself off this branch, or else things will get too messy. Please merge as quick as possible

@eyaltoledano
Copy link
Owner Author

Holding this just a little longer while I get some integration tests defined for the modules
I'm not 1000% sure everything still works and ideally dont wanan push something broken

…ntegration, 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.
@eyaltoledano
Copy link
Owner Author

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 adding and improving testing, new 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 package.json including test, test:watch, and test:coverage for streamlined testing workflows.
  • Integrated necessary devDependencies for testing, such as @types/jest, jest, jest-environment-node, mock-fs, and supertest, to support unit, integration, and end-to-end testing.

Dependency Updates:

  • Updated package-lock.json and package.json to reflect the latest dependency versions, ensuring project stability and access to the newest features and security patches.
  • Upgraded task-master-ai to version 0.9.16 and openai to 4.89.0.
  • Added node_modules/@ampproject/remapping dependency (version 2.3.0) and updated @babel 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 PERPLEXITY_API_KEY environment variable is available.
  • Modified the updateTasks function to accept a useResearch parameter, allowing dynamic selection between Perplexity AI and Claude AI for task updates based on API key availability and user preference.
  • Enhanced updateTasks 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 isCircularDependency function to utilize task IDs instead of dependency IDs, ensuring consistency and clarity in dependency management.
  • Implemented a new validateTaskDependencies function to rigorously check for both circular dependencies and self-dependencies within tasks, improving task relationship integrity.
  • Enhanced UI elements in ui.js:
    • Refactored getStatusWithColor to incorporate icons for different task statuses and utilize a statusConfig object for color mapping, improving visual representation of task status.
    • Updated getComplexityWithColor 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 tasks.json 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.

Gonna merge this and start working on the MCP server

@eyaltoledano eyaltoledano merged commit a111fa4 into main Mar 24, 2025
@eyaltoledano eyaltoledano deleted the refactor branch March 24, 2025 17:34
ProdByBuddha pushed a commit to ProdByBuddha/claude-task-master that referenced this pull request Apr 9, 2025
Refactor: Modularize Task Master CLI into Modules Directory
feat: Enhance Task Master CLI with Testing Framework, Perplexity AI Integration, and Refactored Core Logic
jonathanpberger added a commit to discoveryworks/finesse that referenced this pull request May 22, 2025
- Add comprehensive incept.js implementation with AI integration
- Generate structured INCEPTION.md with Goals, Risks, and Users
- Handle both file input and stdin for prompt content
- Parse AI JSON responses with proper error handling
- Create formatted markdown with frontmatter
- Fixed AI service response structure handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
wbisschoff13 referenced this pull request in wbisschoff13/claude-task-master Jan 7, 2026
Task: TM-004 - Add --skip CLI option with Commander.js

Notes:
- Task implementation completed in commits 85a6066, 3cef35f, and 41b319a
- Updates task status from "pending" to "done"
- Increments completedCount from 3 to 4
- Includes .taskmaster/tasks.json with task status update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants