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.
163 lines
5.0 KiB
Plaintext
163 lines
5.0 KiB
Plaintext
---
|
|
description: Guidelines for implementing CLI commands using Commander.js
|
|
globs: scripts/modules/commands.js
|
|
alwaysApply: false
|
|
---
|
|
|
|
# Command-Line Interface Implementation Guidelines
|
|
|
|
## Command Structure Standards
|
|
|
|
- **Basic Command Template**:
|
|
```javascript
|
|
// ✅ DO: Follow this structure for all commands
|
|
programInstance
|
|
.command('command-name')
|
|
.description('Clear, concise description of what the command does')
|
|
.option('-s, --short-option <value>', 'Option description', 'default value')
|
|
.option('--long-option <value>', 'Option description')
|
|
.action(async (options) => {
|
|
// Command implementation
|
|
});
|
|
```
|
|
|
|
- **Command Handler Organization**:
|
|
- ✅ DO: Keep action handlers concise and focused
|
|
- ✅ DO: Extract core functionality to appropriate modules
|
|
- ✅ DO: Include validation for required parameters
|
|
- ❌ DON'T: Implement business logic in command handlers
|
|
|
|
## Option Naming Conventions
|
|
|
|
- **Command Names**:
|
|
- ✅ DO: Use kebab-case for command names (`analyze-complexity`)
|
|
- ❌ DON'T: Use camelCase for command names (`analyzeComplexity`)
|
|
- ✅ DO: Use descriptive, action-oriented names
|
|
|
|
- **Option Names**:
|
|
- ✅ DO: Use camelCase for long-form option names (`--outputFormat`)
|
|
- ✅ DO: Provide single-letter shortcuts when appropriate (`-f, --file`)
|
|
- ✅ DO: Use consistent option names across similar commands
|
|
- ❌ DON'T: Use different names for the same concept (`--file` in one command, `--path` in another)
|
|
|
|
```javascript
|
|
// ✅ DO: Use consistent option naming
|
|
.option('-f, --file <path>', 'Path to the tasks file', 'tasks/tasks.json')
|
|
.option('-o, --output <dir>', 'Output directory', 'tasks')
|
|
|
|
// ❌ DON'T: Use inconsistent naming
|
|
.option('-f, --file <path>', 'Path to the tasks file')
|
|
.option('-p, --path <dir>', 'Output directory') // Should be --output
|
|
```
|
|
|
|
## Input Validation
|
|
|
|
- **Required Parameters**:
|
|
- ✅ DO: Check that required parameters are provided
|
|
- ✅ DO: Provide clear error messages when parameters are missing
|
|
- ✅ DO: Use early returns with process.exit(1) for validation failures
|
|
|
|
```javascript
|
|
// ✅ DO: Validate required parameters early
|
|
if (!prompt) {
|
|
console.error(chalk.red('Error: --prompt parameter is required. Please provide a task description.'));
|
|
process.exit(1);
|
|
}
|
|
```
|
|
|
|
- **Parameter Type Conversion**:
|
|
- ✅ DO: Convert string inputs to appropriate types (numbers, booleans)
|
|
- ✅ DO: Handle conversion errors gracefully
|
|
|
|
```javascript
|
|
// ✅ DO: Parse numeric parameters properly
|
|
const fromId = parseInt(options.from, 10);
|
|
if (isNaN(fromId)) {
|
|
console.error(chalk.red('Error: --from must be a valid number'));
|
|
process.exit(1);
|
|
}
|
|
```
|
|
|
|
## User Feedback
|
|
|
|
- **Operation Status**:
|
|
- ✅ DO: Provide clear feedback about the operation being performed
|
|
- ✅ DO: Display success or error messages after completion
|
|
- ✅ DO: Use colored output to distinguish between different message types
|
|
|
|
```javascript
|
|
// ✅ DO: Show operation status
|
|
console.log(chalk.blue(`Parsing PRD file: ${file}`));
|
|
console.log(chalk.blue(`Generating ${numTasks} tasks...`));
|
|
|
|
try {
|
|
await parsePRD(file, outputPath, numTasks);
|
|
console.log(chalk.green('Successfully generated tasks from PRD'));
|
|
} catch (error) {
|
|
console.error(chalk.red(`Error: ${error.message}`));
|
|
process.exit(1);
|
|
}
|
|
```
|
|
|
|
## Command Registration
|
|
|
|
- **Command Grouping**:
|
|
- ✅ DO: Group related commands together in the code
|
|
- ✅ DO: Add related commands in a logical order
|
|
- ✅ DO: Use comments to delineate command groups
|
|
|
|
- **Command Export**:
|
|
- ✅ DO: Export the registerCommands function
|
|
- ✅ DO: Keep the CLI setup code clean and maintainable
|
|
|
|
```javascript
|
|
// ✅ DO: Follow this export pattern
|
|
export {
|
|
registerCommands,
|
|
setupCLI,
|
|
runCLI
|
|
};
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
- **Exception Management**:
|
|
- ✅ DO: Wrap async operations in try/catch blocks
|
|
- ✅ DO: Display user-friendly error messages
|
|
- ✅ DO: Include detailed error information in debug mode
|
|
|
|
```javascript
|
|
// ✅ DO: Handle errors properly
|
|
try {
|
|
// Command implementation
|
|
} catch (error) {
|
|
console.error(chalk.red(`Error: ${error.message}`));
|
|
|
|
if (CONFIG.debug) {
|
|
console.error(error);
|
|
}
|
|
|
|
process.exit(1);
|
|
}
|
|
```
|
|
|
|
## Integration with Other Modules
|
|
|
|
- **Import Organization**:
|
|
- ✅ DO: Group imports by module/functionality
|
|
- ✅ DO: Import only what's needed, not entire modules
|
|
- ❌ DON'T: Create circular dependencies
|
|
|
|
```javascript
|
|
// ✅ DO: Organize imports by module
|
|
import { program } from 'commander';
|
|
import path from 'path';
|
|
import chalk from 'chalk';
|
|
|
|
import { CONFIG, log, readJSON } from './utils.js';
|
|
import { displayBanner, displayHelp } from './ui.js';
|
|
import { parsePRD, listTasks } from './task-manager.js';
|
|
import { addDependency } from './dependency-manager.js';
|
|
```
|
|
|
|
Refer to [`commands.js`](mdc:scripts/modules/commands.js) for implementation examples and [`new_features.mdc`](mdc:.cursor/rules/new_features.mdc) for integration guidelines. |